function SheetSwitched (ncount)
     StopSheet=true;
return;end;
function Timer(ncount, Param1)
     if not StopSheet then
          AlfingSheet();
          StopSheet=false;
     return;end;
return;end;
function gameinput (sender,obj_id,attachedID)

  if sender == 2 then
      RemoveFromMouse(object);
    MessageProc(sender,obj_id);
  return;end;
     if sender==36 then          
          if obj_id==9999 then
               if not StopSheet then
                    AlfingSheet();
                    StopSheet=false;
               return;end;
          return;end;                    
     return;end;
    if sender==12 then
    -- messagebox("1")
      if SLevel==1.0 then return;end;
                if obj_id== 120 then
          -- messagebox("2")
          AddElement("gr",120);
          SetAlfaSheet(2.5)
          set_visible_object(42,true)    
          Set_Cursor(42,4)
          flags.crea= true
          setcolor(120,0,0,0,0.5,1);
          MoveObjectToTree(120);
          end;
        if last_id==obj_id then
        -- messagebox("3")
          if obj_id== 121 then
          CreateWindow(150,250,"399",nil,nil,250,30);
          AddElement("gr",obj_id);
          SetAlfaSheet(2.5)
          setcolor(obj_id,0,0,0,0.5,1);
          MoveObjectToTree(obj_id);
          end;  

          if flags.loc2 then    
            if flags.loc1 and flags.loc2 then
              flags.loc2= false;
              flags.levelcomplete=true;
              DarkScreen(true);
              ShowMenu(false)
            return; end;  
          CreateWindow(150,250,"199",nil,nil,250,30);  
          --playeffect("01");        
          return;end;
      
        return;end;

    return;end;
  if sender==26 then
    if obj_id==13 then
      if flags.minicomplete5 and flags.all then  
      
      flags.loc2 = true;          
        if flags.loc1 and flags.loc2 then        
          flags.levelcomplete=true;
          DarkScreen(true);
          ShowMenu(false)
        return; end;  
      CreateWindow(150,250,"199",nil,nil,250,30);
        --playeffect("01");  
      return;end;
    return; end;
  return; end;
if sender==33 then
    BlockCursor(false);
    if obj_id==501 then -- тёмная плашка
      BlockCursor(false);
      if whole_darkness then
         if flags.levelcomplete then
          SetAlfa(500,0,1,1);
          speciale_action(4,500);
          BlockCursor(true);

        return;end;      
         --затемнилось
      return;end;
      whole_darkness=false;
         -- растемнилось
      AddParticleToObject(39,"barda4",810,483);
      MoveEmiter("barda4",810,483);
      if (not flags.minicomplete5) then
        StartEmiter("barda4");
      end;
      AddParticleToObject(41,"pereda4a",523,623);
      MoveEmiter("pereda4a",523,623);
      if not flags.transmission then
        StartEmiter("pereda4a");
      end;  

    return;end;     
    if obj_id==503 then --название levовня
        BlockCursor(false);
      if whole_darkness then
         --затемнилось
      return;end;      
      -- проявление меню вывод собщений в начале levовня ----
      ShowMenu(true);
      --CreateWindow(150,250,"224");             
      ------
      savegame(SaveLevel());
    return;end;
  return;end;
    if pause_state then
    if sender==1 or sender==6 or sender==14 then
      pause_state=false;
      --set_visible_object(11111,false);
    end;  
  return;end;
  if sender == 1 then --кликнули левой кнопкой мыши на активный объект
  last_id=obj_id
      if obj_id==41 then  -- для рычага
      if not flags.transmission then
      if attachedID == 213 then
          RemoveFromMouse(attachedID);
          SetAlfaSheet(2.0)
          DeleteElement("gr",attachedID);
          Set_Cursor(41,3);
          Set_Cursor(28,2)
          flags.transmission = true;
          CreateWindow(150,250,"205",nil,nil,250,30);
            --playeffect("01");  
          speciale_action(2,28);
        return; end;  
        if (attachedID ~= 213) and (attachedID>-1) then
        RemoveFromMouse(attachedID);
                    CreateWindow(150,250,"200",nil,nil,250,30);
            --playeffect("01");  
        return; end;
        if attachedID==-1 then
                    CreateWindow(150,250,"206",nil,nil,250,30);
            --playeffect("01");  
        return; end;      
      return;end;
      return;end;
      

      if obj_id==42 then  -- для ключей
      if not flags.keys then
      if flags.transmission then
        if attachedID == 120 or attachedID == 161 then
          RemoveFromMouse(attachedID);
          SetAlfaSheet(2.0)
          DeleteElement("gr",attachedID);
          Set_Cursor(5,3);
          flags.crea= false
          set_visible_object(42,false)
          flags.keys = true;
          speciale_action(2,35);
          Set_Cursor(42,3)
          Set_Cursor(35,4);
          CreateWindow(150,250,"207",nil,nil,250,30);
            --playeffect("01");  
        return; end;  
        if (attachedID ~= 120) and (attachedID ~= 161) and (attachedID>-1) then
        RemoveFromMouse(attachedID);
          CreateWindow(150,250,"200",nil,nil,250,30);
            --playeffect("01");  
        return; end;
        if attachedID==-1 then
          CreateWindow(150,250,"206",nil,nil,250,30);
            --playeffect("01");  
        return; end;      
      return;end;  
      RemoveFromMouse(attachedID);
      CreateWindow(150,250,"211",nil,nil,250,30);
        --playeffect("01");  
      return;end;          
      return;end;
      if attachedID==-1 then
      if obj_id==501 then
  --        if whole_darkness then
        if flags.levelcomplete then
          LoadNextLevel()
        return;end;        
            DarkScreen(false);
            whole_darkness=false;
          SetAlfa(503,1,0,1);
    --    return;end;
      return;end;    
        if obj_id==43 then
          setcurentleaf("avariya",12,0);
          playeffect("nogi");  
          SwitchToSheet("re");
          savegame(SaveLevel());
        return; end;
        if obj_id == 35 then
          if flags.transmission then
            speciale_action(2,36);
                        speciale_action(2,35);
            speciale_action(2,27);
            flags.neitralka= true;
            CreateWindow(150,250,"84",nil,nil,250,30);
            StopEmiter("klu4i");
          return;end;
          collaps_obj(120,0,0,10,0);
          
          playeffect("20");
          speciale_action(2,35)
          --Set_Cursor(5,2);
          flags.keys=false;
          AddParticleToObject(42,"klu4i",286,374);
          MoveEmiter("klu4i",286,374);
          if  not flags.keys then
          StartEmiter("klu4i");
          end;
        return; end;  

        if obj_id == 121 then
          collaps_obj(obj_id,0,0,10,0);
          playeffect("20");  

        return; end;  
        if obj_id == 300 then
          CreateWindow(150,250,"398",nil,nil,250,30);
          collaps_obj(300,0,0,10,1);
          StopEmiter("barda4");
          setcolor(300,0,0,0,0.5,1);
        return; end;  
        if obj_id==39 then
        if (not flags.minicomplete5) then
            speciale_action(2,39);    
          speciale_action(2,300); 
            speciale_action(2,16)
            speciale_action(2,10)
          setcolor(10,0,0,0,1,1);
          setcolor(300,0,0,0,1,1);
          Set_Cursor(39,3);
          flags.key9=true;
          flags.minicomplete5= true;
        return; end;      
        return; end;

        
        if obj_id==28 then  -- номер
        if flags.neitralka and flags.transmission then
        flags.last=true;  
           CreateWindow(150,250,"208",13,nil,250,30);  
             --playeffect("01");  
           Set_Cursor(27,3);
  
        return;end;  
        CreateWindow(150,250,"210",nil,nil,250,30);
          --playeffect("01");  
        return;end;  
      
        if obj_id > 0 and obj_id < 57 and attachedID == -1 then --кликаем на активный объект
          playeffect("20");
          collaps_obj(obj_id,0,0,10,1);
        return 0; end
      
      return; end;  
  return; end;
  
  if sender==14 then
    if obj_id>0 then
    StopSheet=true;
    object=obj_id
      addObjectToMouse(obj_id);
    return; end;
  return; end;  
-----------------------------------------------На сцене отработали все объекты-------------------------
  if sender==4 then
  -- WriteToConsole("sender = 4, lev12.1".." "..sender.."\n")
  if SLevel==1.0 then return;end;
  flags.all=true;
  if flags.last then
    flags.loc2 = true;
  return; end;  
  return; end;  
------------------------------------------------------------------------------------------------------------------  
  
end
function SelectRandom()
  idObject=GetRandomObject();
  if idObject==300 or idObject==10 then
  if not flags.minicomplete5 then
    selectrandomobject(1.5,39);
  return; end;
  selectrandomobject(1.5,idObject);
  return; end;
  if idObject==120 then
    selectrandomobject(1.5,35);
  return;end;
  if flags.all  then
    if (not flags.minicomplete34) then
      selectrandomobject(1.5,43);
    return; end;
    if flags.transmission then
      if flags.keys then
        if not flags.neitralka then
        selectrandomobject(1.5,35);
        end;
        selectrandomobject(1.5,41);
      return;end;
      selectrandomobject(1.5,42);
    return;end;
  selectrandomobject(1.5,41);
  return; end;
  selectrandomobject(1.5,idObject);
end;
function SelectRandomRadar(idObject)
  if idObject==120 then
    selectrandomobject(1.5,35);
  return;end;
  if idObject==10 then
    if not flags.minicomplete5 then 
      selectrandomobject(1.5,39);
    return;end;
  selectrandomobject(1.5,idObject);
  return;end;
  if idObject==300 then
    selectrandomobject(1.5,39);
  return;end;
  selectrandomobject(1.5,idObject);
end;
