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 == 100 then
  if flags.comx then
    speciale_action(2,12121,true);
    add_free_leaf("map13",12,101);
    set_satelite_leaf("avariya");
    DoFile(12,101)
    flags.comx= false;
    flags.comx1= true;
  return;end;
  return;end;
  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 SLevel==1.0 then return;end;
  if last1_id==obj_id then
      if obj_id==119 then
          AddElement("gr",119);
          SetAlfaSheet(2.5)
          setcolor(119,0,0,0,0.5,1);
          MoveObjectToTree(119);
          flags.mousein=true;
          Set_Cursor(66,3);
          flags.mouse=false;
    end;  
    if obj_id==214 then
          AddElement("gr",obj_id);
          SetAlfaSheet(2.5)
          setcolor(obj_id,0,0,0,0.5,1);
          MoveObjectToTree(obj_id);
    end;  
    if obj_id==215 then
          AddElement("gr",obj_id);
          SetAlfaSheet(2.5)
          setcolor(obj_id,0,0,0,0.5,1);
          MoveObjectToTree(obj_id);
    end;  
    if obj_id==213 then
          AddElement("gr",obj_id);
          SetAlfaSheet(2.5)
          setcolor(obj_id,0,0,0,0.5,1);
          MoveObjectToTree(obj_id);
          flags.trunk=true;
          flags.minicomplete34 = true;
    end;  
    if obj_id==121 then
          AddElement("gr",obj_id);
          SetAlfaSheet(2.5)
          setcolor(obj_id,0,0,0,0.5,1);
          MoveObjectToTree(obj_id);
          flags.flower=true;
    end;
    if flags.loc1 then    
      if flags.loc1 and flags.loc2 then
      flags.loc1= 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==35 then
    if obj_id==550 then
      StartAnimation(550,0,3)
    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(70,"bagaj",649,248);
      MoveEmiter("bagaj",649,248);
      if not flags.trunk then
        StartEmiter("bagaj");
      end;  
      AddParticleToObject(67,"miwka",28,575);
      MoveEmiter("miwka",28,575);
      if not flags.mouse then  
        StartEmiter("miwka");
      end;
      savegame(SaveLevel());
    return;end;     
    if obj_id==503 then --название levовня
        BlockCursor(false);
      if whole_darkness then
         --затемнилось
      return;end;      
      -- проявление меню вывод собщений в начале levовня ----
      ShowMenu(true);
      --CreateWindow(150,250,"224");             
      ------
    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 --кликнули левой кнопкой мыши на активный объект
      last1_id=obj_id
      if obj_id==70 then  -- авто
        if not flags.trunk then
          if attachedID == 120 then
          RemoveFromMouse(120);
            playeffect("KeyRotate");  
            Set_Cursor(59,3);
            speciale_action(2,213);
            speciale_action(2,2133)
            speciale_action(2,214);
            speciale_action(2,215);
            setcolor(215,0,0,0,1,1);
            setcolor(213,0,0,0,1,1);
            setcolor(214,0,0,0,1,1);
            speciale_action(2,55);
            set_visible_object(70,false)
            flags.trunk=true;
            StopEmiter("bagaj");
          return; end;  
          if (attachedID ~= 120) 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,"202",nil,nil,250,30);
              --playeffect("01");  
          return; end;
        return;end;        
      return;end;
      if obj_id==67 then  -- норка
              if not flags.mouse then    
          if attachedID == 214 then
            RemoveFromMouse(attachedID);
            SetAlfaSheet(2.0)
            DeleteElement("gr",attachedID);
            flags.mouse=true;
            StopEmiter("miwka");
            AddParticleToObject(66,"miw",118,595);
            MoveEmiter("miw",118,595);
            StartEmiter("miw");
            speciale_action(2,66);
            Set_Cursor(67,3);
            Set_Cursor(66,4);
          return; end;  
          if (attachedID ~= 214) 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,"203",nil,nil,250,30);
              --playeffect("01");  
          return; end;
        return; end;  
      return;end;      
        if obj_id== 119 then
          collaps_obj(119,0,0,10,0);
          playeffect("20");

        return; end;      
      if obj_id==66 then
          if flags.mouse then    
          if attachedID == 215 then
            RemoveFromMouse(attachedID);
            SetAlfaSheet(2.0)
            DeleteElement("gr",attachedID);
            speciale_action(2,119);
            set_visible_object(67,false)
            speciale_action(2,65);
            setcolor(119,0,0,0,1,1);
            Set_Cursor(66,3)
            flags.miw= true
            StopEmiter("miw");
            CreateWindow(150,250,"85",nil,nil,250,30);  
          return; end;  
          if (attachedID ~= 215) and (attachedID>-1) then
          RemoveFromMouse(attachedID);
            CreateWindow(150,250,"200",nil,nil,250,30);
              --playeffect("01");  
          return; end;
          if attachedID==-1 and not flags.miw then
            CreateWindow(150,250,"204",nil,nil,250,30);
              --playeffect("01");  
          return; end;    
        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==58 then
        if flags.firstloc1 then
          setcurentleaf("car",12,1);
          playeffect("nogi");  
          SwitchToSheet("re");
          whole_darkness=false;
          DarkScreen(true);
          SetAlfa(503,0,1,1);
          speciale_action(4,503);
          flags.firstloc1 = false;
          ShowMenu(false)
        return; end;
          setcurentleaf("car",12,1);
          playeffect("nogi");  
          savegame(SaveLevel());
        return; end;
        
        if obj_id == 214 then
          collaps_obj(obj_id,0,0,10,0);
          playeffect("20");

        return; end;  

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

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

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

        return;end;  
      
        if obj_id > 0 and obj_id < 200 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.0".." "..sender.."\n")
  if SLevel==1.0 then return;end;
  flags.loc1 = true;

  return; end;  
------------------------------------------------------------------------------------------------------------------  
  
end
function SelectRandom()
  idObject=GetRandomObject();
  if not flags.trunk then
    if idObject==119 or idObject==213 or idObject==214 or idObject==215 then
    if flags.keys then
    selectrandomobject(1.5,58);
    end;
      selectrandomobject(1.5,70);
    end;
    selectrandomobject(1.5,idObject);
  end;
  -- if not flags.minicomplete34  and idObject==213 then
    -- selectrandomobject(1.5,68);
  -- end;
  if flags.loc1  then
    selectrandomobject(1.5,58);
   end;
        if idObject==119 then
      selectrandomobject(1.5,67);
  end;
  -- if idObject==213 or 214 or 215  then
    -- selectrandomobject(1.5,70);
  -- end;
  selectrandomobject(1.5,idObject);
end;
function SelectRandomRadar(idObject)
    if idObject==213 then
      selectrandomobject(1.5,70);
  end;
      if idObject==214 then
      selectrandomobject(1.5,70);
  end;
      if idObject==215 then
      selectrandomobject(1.5,70);
  end;
      if idObject==119 then
      selectrandomobject(1.5,67);
  end;
  selectrandomobject(1.5,idObject);
end;
