function Timer(ncount, Param1)
     if not StopSheet then
          AlfingSheet();
          StopSheet=false;
     return;end;
return;end;
function SheetSwitched (ncount)
     StopSheet=true;
return;end;
local n=0
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==100 then  
   if  flags.konecz then
     if flags.loc2 and flags.loc3 and flags.minicomplete3 then
      flags.loc3= false;
      flags.levelcomplete=true;
      DarkScreen(true);
      ShowMenu(false)
    return; end;
   end
return; end;
   
   if sender==26 then          
          if obj_id==123321 then
      if flags.items==13 and flags.pasp and flags.loc2 and flags.minicomplete3 then
        flags.loc3= false;
        flags.levelcomplete=true;
        DarkScreen(true);
        ShowMenu(false)  
      return; end;
    return;end;
          if obj_id==1 then
      collaps_obj(200,0,0,10,1);
      WaitRender()
      flags.konecz= true
          return;end;                    
     return;end;
   if sender==15 then  
    BlockCursor(false)
          if obj_id==332 then
      CreateWindow(150,250,"218",1,nil,250,30);
      flags.pasp= true;
          return;end;                    
     return;end;     -- return;end;
   if sender==16 then          
          if obj_id==42 then
        CreateWindow(150,250,"211",nil,nil,250,30);  
          return;end;                    
     return;end;
  if sender==35 then
  -- WriteToConsole("35")
    if obj_id==480 then
      -- WriteToConsole("480")
      StartAnimation(480,0,3)
    return;end;  
    if obj_id==550 then
      -- WriteToConsole("550")
      StartAnimation(550,0,4)
    return;end;  
    if obj_id==101010 then
      -- WriteToConsole("10")
      StartAnimation(101010,0,5)
    return;end;  
  return;end;
  if sender==12 then
  if SLevel==1.0 then return;end;  
if obj_id==115 then
      AddElement("gr",115);
      setcolor(115,0,0,0,0.5,1);
      MoveObjectToTree(115);
      flags.keys=true; 
      StopEmiter("zvezd4");
      Set_Cursor(38,3);
      playeffect("29");
 end;
 if obj_id==114 then
  AddElement("gr",114);
  SetAlfaSheet(2.5)
  MoveObjectToTree(114); 
  flags.card=true;
  CreateWindow(150,250,"195",123321,nil,250,30);
 return;end;

if obj_id==309 then
    AddElement("gr",obj_id);
    SetAlfaSheet(2.5)
    setcolor(obj_id,0,0,0,0.5,1);
    MoveObjectToTree(obj_id);
 end;
if obj_id==301 then
  AddElement("gr",obj_id);
  SetAlfaSheet(2.5)
  setcolor(obj_id,0,0,0,0.5,1);
  MoveObjectToTree(obj_id); 
  flags.kriwka= true;
 end;
      
    if flags.items==13 and flags.pasp and flags.loc2 and flags.minicomplete3 then
        flags.loc3= false;
        flags.levelcomplete=true;
        DarkScreen(true);
        ShowMenu(false)  
  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(38,"zvezd4",608,457);
      MoveEmiter("zvezd4",608,457);
      if (not flags.otkr) then
        StartEmiter("zvezd4");
      end;


    return;end;     
    if obj_id==503 then --название уровня
        BlockCursor(false);
      if whole_darkness then
         --затемнилось
      return;end;      
      -- проявление меню вывод собщений в начале уровня ----
      ShowMenu(true);
        CreateWindow(150,250,"197",nil,nil,250,20);  
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 == 200 then
        if flags.case then
          if not flags.one then
            speciale_action(2,332,true)  
            speciale_action(4,332)  
            flags.one= true;
            Set_Cursor(200,3)
            StopEmiter("pasport");
          return; end;  
        return; end;  
                CreateWindow(150,250,"210",nil,nil,250,30);  
      return; end;
      if obj_id==52 then
        if not flags.snake then
        if attachedID==309 then         
          RemoveFromMouse(attachedID);
          SetAlfaSheet(2.0)
          DeleteElement("gr",attachedID);
          
          speciale_action(2,42,true);
          speciale_action(2,200)
          Set_Cursor(200,2)
          speciale_action(2,52,true);            
          flags.snake=true;
          AddParticleToObject(49,"zvezd3",104,534);
          MoveEmiter("zvezd3",104,534);
          if  flags.snake and not flags.case then
            StartEmiter("zvezd3");
          end;
        return;end;  
        if  (attachedID~=309) and (attachedID>-1) then 
        RemoveFromMouse(attachedID);
          CreateWindow(150,250,"200",nil,nil,250,30);
        return; end;  
        if attachedID==-1 then  
          CreateWindow(150,250,"212",nil,nil,250,30);  
        return; end;  
        return;end;        
      return;end;
      if obj_id==43 then    
        if not flags.case then
        if flags.snake then
          if attachedID==301 then         
            RemoveFromMouse(attachedID);
            SetAlfaSheet(2.0)
            DeleteElement("gr",attachedID);
            flags.case=true;
            flags.snake =false;
            speciale_action(2,41);
            setcolor(200,0,0,0,1,1);
            StopEmiter("zvezd3");
            Set_Cursor(43,3)
            Set_Cursor(52,2)
            AddParticleToObject(200,"pasport",241,420);
            MoveEmiter("pasport",241,420);
            if (not flags.minicomplete10) then
            StartEmiter("pasport");
            end;

          return;end;  
          if  (attachedID~=301) and (attachedID>-1) then 
          RemoveFromMouse(attachedID);
              CreateWindow(150,250,"200",nil,nil,250,30);
          return; end;  
          if attachedID==-1 then        
              CreateWindow(150,250,"215",nil,nil,250,30);
          return; end;    
        return; end;
        return; end;          
      return; end;
            
      if attachedID==-1  then

            if obj_id==501 then
              if flags.levelcomplete then
                delete_tree_leaf("Root","rouk_enter");-- Добавляет лист в дерево 
                delete_tree_leaf("Root","rouk_room");-- Добавляет лист в дерево 
                setnextlavel(9);
                loadlavel();  
              return;end;        
            DarkScreen(false);
            whole_darkness=false;
            SetAlfa(503,1,0,1);
          return;end;  
        if obj_id==58 then
          setcurentleaf("rouk_enter",25,1);
            playeffect("door");
          SwitchToSheet("re");
          savegame(SaveLevel());
        return; end;
        if obj_id==332 then
          speciale_action(2,332,true);
        return; end;
        if obj_id == 309 then
          collaps_obj(obj_id,0,0,10,0);
          flags.items = flags.items + 1;
          playeffect("20");
 
        return; end;  
        if obj_id == 114 then
          collaps_obj(114,0,0,10,0);
          flags.items = flags.items + 1;
          playeffect("20");

        return; end;  

        if obj_id == 301 then
          collaps_obj(obj_id,0,0,10,0);
          flags.items = flags.items + 1;
          playeffect("20");

        return; end;            
        if obj_id==38 then
        if (not flags.minicomplete3) then
          playeffect("29");
          add_free_leaf("Root","mini3",0,13);-- шкатулка
          set_satelite_leaf("rouk_room");
          DoFile(0,13)
          flags.nohints=true;
        if not flags.proideno then
          mini_create();
        return; end;
        return; end;
        return; end;
      
      if obj_id > 0 and obj_id < 200  then --кликаем на активный объект
        playeffect("20");
            collaps_obj(obj_id,0,0,10,1);
        flags.items = flags.items + 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
        if SLevel==1.0 then return;end;
    -- flags.loc3 = true;
  return; end;    
  
end
function SelectRandom()
  idObject=GetRandomObject();
  if not flags.minicomplete3 and idObject==115 then
      selectrandomobject(1.5,38);
  end;
  if not flags.pasp then
  if not flags.case then
    if not flags.kriwka then
      selectrandomobject(1.5,301);
    end;
    if not flags.snake and flags.kriwka then
      selectrandomobject(1.5,52);
    end;  

    selectrandomobject(1.5,43);
    end;
    selectrandomobject(1.5,200);
  end;
    idObject=GetRandomObject();
  if flags.loc3 then
    selectrandomobject(1.5,58);
  end;
  selectrandomobject(1.5,idObject);
end;
function SelectRandomRadar(idObject)
if not flags.pasp then
  if not flags.case then
    if not flags.kriwka then
      selectrandomobject(1.5,301);
    return;end;
    if not flags.snake and flags.kriwka then
      selectrandomobject(1.5,52);
    return;end;  

    selectrandomobject(1.5,43);
    return;end;
    selectrandomobject(1.5,200);
  return;end;
  if idObject==115 then
      selectrandomobject(1.5,38);
  return;end;
  selectrandomobject(1.5,idObject);
end;
