function SelectRandom()

  if flags.ShowTutorial and not flags.tumba then
     selectrandomobject1(1.5,20);
  return;end;

     if not flags.cod then
       if not flags.shkafM then
        selectrandomobject1(1.5,22);
        else
        selectrandomobject1(1.5,21);
        end;
     return;end;
     if not flags.medalyon and (obj.nog~=nil and obj.nog.is_stored )then
        selectrandomobject1(1.5,99);

     return;end;       
     if not flags.medalyon and flags.posM then
        selectrandomobject1(1.5,9);
        return;end;    
     if not flags.tumba then
        selectrandomobject1(1.5,20);
     return;end;                   
     if (flags.taburka_razbit and not flags.hidden)  then
        selectrandomobject1(1.5,16);
     return;end;  
     not_hint=true	 
	 CreatePlashechka(900000,"10005")
    -- selectrandomobject1(1.5,28);
return;end;

function tut()
  if flags.ShowTutorial then
  nexttutorial=true
  WaitRender()
  end;
end;

function ActionsJump ()
end;

function SetCursors()
    ItemsCur={}
    PointingItems={}
    Set_Anim_Cur(28,14);
    Set_Anim_Cur(216,2);
    if not flags.tumba then
      Set_Anim_Cur(20,2);
    end;    
    if not flags.cod then
      if not  flags.shkafM then
        Set_Anim_Cur(22,2)
      else    
        Set_Anim_Cur(21,2);
      end;
    end;    
    if (flags.taburka_razbit and not flags.hidden)  then
      Set_Anim_Cur(16,2);    
    end;
    if not flags.medalyon then
        Set_Anim_Cur(99,2);    
    end;
end;

function SetParticles()
        AddParticleToObject(216,"diplom",578 ,168);
        MoveEmiter("diplom",578 ,168);
        StartEmiter("diplom");
    if flags.is_spirit then
        forduh={
        0,0,
        0,1,
        1,1,
        1,0
        }
        CreatePolygon(987,4,"forduh");
        AddParticleToObject(987,"duh",512 ,384);
        MoveEmiter("duh",512 ,384);
        StartEmiter("duh");
    end;
    if (flags.taburka_razbit and not flags.hidden) then
          AddParticleToObject(16,"stol",388 ,400);
          MoveEmiter("stol",388 ,400);
          StartEmiter("stol");
    end;
    if not flags.tumba then
      AddParticleToObject(20,"one2",700,325);
      MoveEmiter("one2",700,325);
      StartEmiter("one2");  
    end;
    if not flags.medalyon then
     if not flags.medalyon and flags.posM then
          AddParticleToObject(9,"posilka",757,475);
          MoveEmiter("posilka",757,475);
          StartEmiter("posilka");  
      else        
      AddParticleToObject(99,"posilka",757,475);
      MoveEmiter("posilka",757,475);
      StartEmiter("posilka");          
      end;
    end;
    if not flags.cod and not flags.shkafM then
        ActivateObject(22,true);
        AddParticleToObject(22,"one1",115,208);
        MoveEmiter("one1",115,208);
        StartEmiter("one1");
      end;    
    if not flags.cod and flags.shkafM then
        ActivateObject(21,true);
        AddParticleToObject(21,"one1",115,208);
        MoveEmiter("one1",115,208);
        StartEmiter("one1");
      end;    
end;


function gameinput (sender,obj_id,attachedID)    
  WriteToConsole("sender = "..sender.." obj_id= "..tostring(obj_id).."\n")
  if not windowtutorial and not tutorialprocessing then
    CursorTreatment(obj_id,sender,attachedID);
  end;
      if sender==33 then    
      Block_Show_Cur(false);
      if obj_id==1000 then
        change_light=true
        WaitRender()
      end;
      if ztm == 1 then
        WaitRender();
      return; end;
    return;end;
  
  if sender==26 then 
    if obj_id==900090 then
    InvitationTutorial()
    flags.mes_tutorial=1;
  return;end;
  if obj_id==900100 then
  if flags.ShowTutorial then
    nexttutorial=true
    WaitRender()
  end
  return;end;
  return;end;

  if sender == 36 then
    -- if obj_id==4785 then
        -- Block_Show_Cur(false);
        -- Set_Sat("tutor",0,12,"kabinet")    
    -- return;end;

    -- if obj_id==787878 then
        -- AddParticleToObject(obj.pisom.id,"fakel1",454,597);
        -- MoveEmiter("fakel1",454,597);
        -- StartEmiter("fakel1");    
    -- return;end;
  return; end;
  
  -- if sender==154 then
    -- if flags.ShowTutorial then
    -- nexttutorial=true

    -- WaitRender()
	-- tutorialprocessing=false
    -- end;
  -- end;
  
  if sender == 1 and not windowtutorial then
    g_attachedID = attachedID;     
  
  -- if flags.waitforpas then
  
--   return;end;
	if not tutorialprocessing then
      if  obj_id==216 then
          s_obj=attachedID               
          RemObjFromMouse()
          Set_Sat("diploms",0,5,"kabinet")      
      end;
      if  obj_id==99 then
          s_obj=attachedID               
          RemObjFromMouse()
          Set_Sat("posilka",0,4,"kabinet")
      end;
      
      if obj_id == 16 then 
        if flags.taburka_razbit and not flags.hidden then
            flags.is_hidden_loc = true;
            RemObjFromMouse()  
            jump("kabinet","stol",0,1);            
        return; end;
       return; end;
      
      if obj_id == 28 then    
          CloseParticleByName("kabinet")
          playeffect("step_room")
          RemObjFromMouse()           
          jump("kabinet","holl",1,0);
      return; end; 
      
      if obj_id == 22 or obj_id==21 then        
        s_obj=attachedID        
        RemObjFromMouse()    
        Set_Sat("shkaf",0,3,"kabinet")    
      return; end;
      
      if obj_id == 20 or obj_id == 19 or obj_id == 18 then    
          s_obj=attachedID                 
          RemObjFromMouse()          
          Set_Sat("tumba",0,2,"kabinet")
      return; end;
    return;end;
  return; end;

  if sender == 100 then
  --  Block_Show_Cur(false)
  if not is_tutorial and not tutorialprocessing and not satelliteopen  then
    SetCursors();
  end;
    SetParticles()
    playeffect("fon_room",true);
    if startgame then
    startgame=false
    CreatePlashechka(900090,"5000")
  end;
  if nexttutorial and flags.ShowTutorial then
	
    is_tutorial=false
	
    if flags.mes_tutorial==1 then
	tutorialprocessing=true
       CreateTutorial("3056",260,170,0) --,99
      -- flags.waitforpas=true;
       nexttutorial=false
       flags.mes_tutorial=2;       
    return;end;  
    if flags.mes_tutorial==3 then
	tutorialprocessing=true
       CreateTutorial("3059",362,282,0)
       nexttutorial=false
       flags.mes_tutorial=4;       
    return;end;      
    if flags.mes_tutorial==4 then
	tutorialprocessing=true
       CreateTutorial("3058",380,300,2)
       nexttutorial=false
       flags.mes_tutorial=5;       
    return;end;      
    if flags.mes_tutorial==5 and flags.medalyon then
	tutorialprocessing=true
      CreateTutorial("3061",348,348,1)  
      ShowSheet("gr","move",5000,true);
       nexttutorial=false
       flags.mes_tutorial=6;      
    return;end;
  end;
    -- if flags.to_run_com5 then
        -- flags.to_run_com5=false;
        -- ShowMenu(false)
        -- flags.is_comics=true    
        -- jump("kabinet","comics5",2,50)
    -- end;
    
    if flags.hint_cur then
        Block_Show_Cur(true)
        flags.hint_cur=false;
        ShowMenu(true);
        StartTimer(4785,1)
        DeleteResources("./data/0/global_res.lua","comics");
        delete_tree_leaf("Root","comics");
     end;     
    if fromMed then
        fromMed=false
        CreatePlashechka(900100,"23")
    end;
    if flags.is_hidden_finish then
       flags.is_hidden_finish=false
       StopEmiter("stol");
       Set_Anim_Cur(16,3);    
    end;
    if change_light then      
          if not light_blik and change_light then
            change_light =false;
            light_blik=true;
            SetAlfa(1000,0.5,1,5);                    
          end;
          if light_blik and change_light then
            change_light =false;
            light_blik=false;    
            SetAlfa(1000,1,0.5,5);              
          end;          
    end;

  return; end;
end

function SheetSwitched(nCount)
end;