function Timer(ncount, Param1)
     if not StopSheet then
          AlfingSheet();
          StopSheet=false;
     return;end;
return;end;

function SheetSwitched (ncount)
     StopSheet=true;
return;end;
function gameinput (sender,obj_id,attachedID)

  if sender == 100 then
  if flags.comx then
    speciale_action(2,12121,true);
    add_free_leaf("map9",8,101);
    set_satelite_leaf("garaj");
    DoFile(8,101)
    flags.comx= false;
    flags.comx1= true;
  return;end;
    if flags.bolt2 and flags.bolt1 and flags.bolt2 and flags.bolt3 and flags.bolt4 and flags.bolt5 then
      DeleteElement("gr",100);
      DeleteElement("gr",111);
      DeleteElement("gr",112);
      DeleteElement("gr",113);
      DeleteElement("gr",114);
      collaps_obj(172,0,0,10,0);
      playeffect("20");

      end;
  return;end;
-- messageboxi(sender);
  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          
          if obj_id==174 then
      
    setcolor(174,0,0,0,0.5,1);
      AddElement("gr",174);
      MoveObjectToTree(174); 
      zapic= true;
      end;
      if obj_id==167 then
      AddElement("gr",167);
      StopEmiter("Svet2");
      setcolor(167,0,0,0,0.5,1);
      MoveObjectToTree(167);  
      end;
            if obj_id==172 then
      AddElement("gr",172);
      setcolor(172,0,0,0,0.5,1);
      MoveObjectToTree(172);           
      flags.bolt2= false
         end; 
      if obj_id==100 then
        AddElement("gr",obj_id);
        SetAlfaSheet(2.5)
        setcolor(obj_id,0,0,0,0.5,1);
        MoveObjectToTree(obj_id); 
        flags.bolt1=true;
        WaitRender()
          end; 
      if obj_id==111 then
        AddElement("gr",obj_id);
        SetAlfaSheet(2.5)
        setcolor(obj_id,0,0,0,0.5,1);
        MoveObjectToTree(obj_id); 
        flags.bolt2=true;
        WaitRender()
          end;    
      if obj_id==112 then
        AddElement("gr",obj_id);
        SetAlfaSheet(2.5)
        setcolor(obj_id,0,0,0,0.5,1);
        MoveObjectToTree(obj_id); 
        flags.bolt3=true;
        WaitRender()
         end; 
      if obj_id==113 then
        AddElement("gr",obj_id);
        SetAlfaSheet(2.5)
        setcolor(obj_id,0,0,0,0.5,1);
        MoveObjectToTree(obj_id); 
        flags.bolt4=true;
        WaitRender()
          end;  
      if obj_id==114 then
        AddElement("gr",obj_id);
        SetAlfaSheet(2.5)
        setcolor(obj_id,0,0,0,0.5,1);
        MoveObjectToTree(obj_id); 
        flags.bolt5=true;
        WaitRender()
         end
      if obj_id==126 then
        AddElement("gr",obj_id);
        SetAlfaSheet(2.5)
        setcolor(obj_id,0,0,0,0.5,1);
        MoveObjectToTree(obj_id); 
          end
       if obj_id==127 then
        AddElement("gr",obj_id);
        SetAlfaSheet(2.5)
        setcolor(obj_id,0,0,0,0.5,1);
        MoveObjectToTree(obj_id); 
         end;   
      if flags.loc1 and flags.minicomplete24 then
        flags.levelcomplete=true;
        DarkScreen(true);
        ShowMenu(false)
      return; end;  

     
                 
     return;end; 
  if sender==35 then
    if obj_id==505 then
      StartAnimation(505,0,5)
    return;end;    
    if obj_id==280 then
      StartAnimation(280,0,4)
    return;end;  
    if obj_id==341 then
      StartAnimation(341,0,4)
    return;end;  
  return;end;
  if sender==26 then
    if obj_id==10 then
      speciale_action(2,680,true);
      speciale_action(4,680);
      playeffect("paper");
    if flags.minicomplete30 and not flags.minicomplete24 then
      set_visible_object(63,false)

  end
    return; end;  
    if obj_id==5 then
      collaps_obj(174,0,0,10,0);

    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(57,"koleco",544,463);
      MoveEmiter("koleco",544,463);
      if not flags.auto then  
        StartEmiter("koleco");
      end;
      AddParticleToObject(36,"korobka",977,594);
      MoveEmiter("korobka",977,594);
      if not flags.first then
        StartEmiter("korobka");
      end;
    return;end;     
    if obj_id==503 then --название уровня
        BlockCursor(false);
      if whole_darkness then
         --затемнилось
      return;end;      
      -- проявление меню вывод собщений в начале уровня ----
      ShowMenu(true);
      CreateWindow(150,250,"198",nil,nil,250,30);   
  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 --кликнули левой кнопкой мыши на активный объект

      if obj_id==57 then -- обрабатываем объект диск для колеса      
        if not flags.wheel then  
           if attachedID==127 then
          RemoveFromMouse(attachedID);
          SetAlfaSheet(2.0)
          collaps_obj(127,0,0,10,0);
          playeffect("20");
          DeleteElement("gr",attachedID);
          flags.wheel=true;
          
          Set_Cursor(57,3);
          speciale_action(2,58);

          Set_Cursor(58,2);
           return; end;
          if  (attachedID~=127) and (attachedID>-1) then 
          RemoveFromMouse(attachedID);
          CreateWindow(150,250,"200",nil,nil,250,30); 
          return; end;
          if  attachedID<=-1 then 
          CreateWindow(150,250,"203",nil,nil,250,30); 
        return; end;
        return; end;
      return; end;  
      if obj_id==58 then -- обрабатываем объект диск для колеса        
          if not flags.auto then
        if flags.wheel then
          if attachedID==172 then
          RemoveFromMouse(attachedID);
          SetAlfaSheet(2.0)
          collaps_obj(172,0,0,10,0);
          playeffect("20");
          DeleteElement("gr",attachedID);
          flags.wheel=false;
          flags.bolt=true;        
            return; end;
          if  (attachedID~=172) and (attachedID>-1) then 
          RemoveFromMouse(attachedID);
          CreateWindow(150,250,"200",nil,nil,250,30); 
          return; end;
          if  attachedID<=-1 then 
          CreateWindow(150,250,"204",nil,nil,250,30); 
          return; end;        
        return;end;  
        if flags.bolt then        
          if attachedID==126 then
            RemoveFromMouse(attachedID);
            SetAlfaSheet(2.0)
            collaps_obj(126,0,0,10,0);
            playeffect("20");
            DeleteElement("gr",attachedID);
            flags.bolt=false;
            flags.auto=true;
            Set_Cursor(57,2);
            StopEmiter("koleco");
            AddParticleToObject(59,"mawina",590,583);
            MoveEmiter("mawina",723,515);
            if not flags.minicomplete30 then
              StartEmiter("mawina");
            end;            
            CreateWindow(150,250,"216",nil,nil,250,30); 
            Set_Cursor(58,3);
            speciale_action(2,58)
            speciale_action(2,57)
            speciale_action(2,59)
            Set_Cursor(59,2);
            return; end;
          if  (attachedID~=126) and (attachedID>-1) then 
          RemoveFromMouse(attachedID);
          CreateWindow(150,250,"200",nil,nil,250,30); 
          return; end;
          if  attachedID<=-1 then 
          CreateWindow(150,250,"204",nil,nil,250,30); 
          return; end;            
        return;end;  
      return; end;        
      return;end;    
      
      if obj_id==501 then
        if flags.levelcomplete then
      --if attachedID==-1 then
        delete_tree_leaf("Root","garaj");-- Добавляет лист в дерево 
        setnextlavel(25);
        loadlavel();    
      --return; end;
        return;end;        
            DarkScreen(false);
            whole_darkness=false;
          SetAlfa(503,1,0,1);
      return;end;  

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


      return;end;
    
      if obj_id==111 then
        collaps_obj(obj_id,0,0,10,0);
        playeffect("20");


      return;end;

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


      return;end;

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

      return;end;

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


      return;end;

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

      return; end;
    if obj_id==680 then
      speciale_action(2,680,true);
    if flags.minicomplete30 and not flags.minicomplete24 then
      set_visible_object(63,true)
    end;    
    return; end;
      
      if obj_id==127 then 
        collaps_obj(obj_id,0,0,10,0);
        playeffect("20");

      return; end;  

      if obj_id==36 then 
      if not flags.first then
        CreateWindow(150,250,"201",10,nil,250,18); 
        flags.first=true;
        Set_Cursor(36,3)
        StopEmiter("korobka");
      --  --collaps_obj(obj_id,0,0,10,1);    
      return; end;      
      return; end;      
      if obj_id==63 then
      RemoveFromMouse(attachedID);
      if flags.auto and (not flags.minicomplete24) then -- мини-игра ханойская башня
        playeffect("29");
        add_free_leaf("Root","mini24",0,34);
        set_satelite_leaf("garaj");
        DoFile(0,34)
        mini_create();
        flags.nohints=true;
      return; end;  
        return; end;  

      if obj_id==59 then 
          if flags.auto and (not flags.minicomplete30) then --мини-игра выпустить авто
          playeffect("29");
          add_free_leaf("Root","mini30",0,40);
          set_satelite_leaf("garaj");
          DoFile(0,40)
          mini_create(); 
          flags.nohints=true;
        return; end;
        
        CreateWindow(150,250,"205",nil,nil,250,30); 
      return; end;      
            
      
      if obj_id > 0 and obj_id < 200  then --кликаем на активный объект
        playeffect("20");
            collaps_obj(obj_id,0,0,10,1);
          return 0; 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, lev.8.0".." "..sender.."\n")
    flags.loc1 = true;
    if zapic then
      flags.levelcomplete=true;
      DarkScreen(true);
      ShowMenu(false)
    return; end;
  return; end;
  if sender==15 then
    if obj_id==680 then
      CreateWindow(150,250,"262",5,nil,250,30);

    return; end;
  return; end;    
end;
function SelectRandom()

  idObject=GetRandomObject();
    if idObject==167 then
      if not flags.minicomplete30  then
        if not flags.auto  then
          selectrandomobject(1.5,57);
        return; end;
      selectrandomobject(1.5,59);
      return; end;
    selectrandomobject(1.5,63);
    return; end;
if idObject==174 then
selectrandomobject(1.5,36);
return; end;
  selectrandomobject(1.5,idObject);
end;
function SelectRandomRadar(idObject)

    if idObject==167 then
      if not flags.minicomplete30  then
        if not flags.auto  then
          selectrandomobject(1.5,57);
        return; end;
      selectrandomobject(1.5,59);
      return; end;
      selectrandomobject(1.5,63);
  return;end;
    -- if idObject==74 then
      -- selectrandomobject(1.5,63);
  -- return;end;
  if idObject==174 then
selectrandomobject(1.5,36);
return; end;
  selectrandomobject(1.5,idObject);
end;
