local time_CPU = 1; 
local error_obj = false;
local error_CPU = false;
local count_CPU = 0;
local idCPUObject = 0;
dropped_obj = 0;
replay=false
function SetCursors()
end;

function TimerFinish()
        CollapseObj(idCPUObject);
        for k, l in pairs(CPU_objects) do
          if l == idCPUObject then 
            CPU_objects[k]=nil    
            setcolor(tonumber(k)+1000, 0, 0, 0, 0.5, 0.5);
            collaps_starting=true
            count_CPU = count_CPU + 1;
            if count_CPU < 15 then
                CPU_Random();
            return;end;
          end;    
        end;
end;

function LevelComplete()
  if not flags.comics12 then
    flags.comics12 = true;
    jumpfromanw=true
    flags.is_comics=true    
    jump("another_world","comics12",21,50); 
  return; end;

return; end;

function CPU_Random()
  have_to_CPU_Random=true
  WriteToConsole("In CPU_Random flags.blockrender = "..tostring(flags.blockrender).."\n")
  if not flags.blockrender then
  error_CPU = false;
  obj_is_find=false
  if not error_CPU then
    idCPUObject = GetRandomObject();
    --WriteToConsole("idCPUObject ="..idCPUObject)
    for i, v in pairs(CPU_objects) do
      if  v == idCPUObject then
        have_to_CPU_Random=false
        xCur,yCur = GetObjectPosition(100);
        xObj,yObj = GetObjectPosition(idCPUObject);
        flyCursor = {"InstantiationOfLine", 2, xCur, yCur, xObj+10, yObj+10, 5, false};
        StartTravel(100,1,nil,nil,flyCursor);
        timer_starting=true;
        --StartTimer(8887,5,"TimerFinish");
        obj_is_find=true
      return; end;
    end;
    end;

  if not obj_is_find then
    CPU_Random()
  end;
    end;
return; end;

function SelectRandom()
  error_obj = false;
  objA_is_find=false
  while not error_obj do
    idObject = GetRandomObject();
    for i, v in pairs(ActObj) do
      if v == idObject then
        error_obj = true;
        selectrandomobjectus(1.5,idObject);
        objA_is_find=true
      return; end;
    end;
  end;
  if not objA_is_find then
  SelectRandom();
  end;
return;end;

function ActionsJump ()
    
end;

function gameinput (sender,obj_id,attachedID)
CursorTreatment(obj_id,sender,attachedID);
  if sender==41 then
    TimerFinish()
  end;
  if sender == 1 then  
    for i, v in pairs(ActObj) do
      if obj_id == v then
        -- dropped_obj = dropped_obj + 1;
        ActObj[i]=nil
        playeffect("collaps")
        CollapseObj(obj_id);
    --    flags.blockrender=true
        collaps0_starting=true
      end;
    end;
  return ;end;
 
 
 
  if sender == 100 then      
    playeffect("fon_dark",true);
    BlockCursor(false)
    if not flags.comics11 and flags.is_jumping then
        flags.is_jumping=false
        add_free_leaf("Root","comics11",20,50);
        set_satelite_leaf("another_world");
        DoFile(20,50)
    return; end; 
  if rebattle then
    rebattle=false
    Block_Show_Cur(true);
    ----восстановление объектов для повтора битвы
    DarkScreen1(true);
    ShowMenu(false);
    for i, v in pairs (obj) do
      for k, l in pairs (object_name) do
        if obj[i].name == l then
          obj[i].is_collapsed = false;
        end;
      end;
    end;
    count_CPU=0;
    dropped_obj=0;
    StartTimer(1536,1);
    return;end;
  return; end;
 
  if sender == 12 then
    --    flags.blockrender=false
    her_objects=0;    
    if collaps_starting then
    collaps_starting=false

    count_CPU1=false;
    for k, l in pairs(CPU_objects) do
       if CPU_objects[k]~=nil then count_CPU1=true end;
    end;        
    if not count_CPU1 then --она закончила
        StartTimer(656565,1)
    return; end;
    return;end;
    if collaps0_starting then
    collaps0_starting=false
    count_Act1=false;
    for k, l in pairs(ActObj) do
       if ActObj[k]~=nil then count_Act1=true end;
    end;        
    if not count_Act1 then --она закончила
      if not flags.comics12 then
        flags.comics12 = true;
        jumpfromanw=true
        flags.is_comics = true;
        flags.is_hidden_loc=false
    --    flags.blockrender=true;
         jump("another_world","comics12",21,50); 
      return; end;
    return; end;
    return; end;
  return; end;
  
  if sender == 28 then
    if obj_id == 1 then
      Block_Show_Cur(false);
      y = 5;
      x = 272;
      fuck = 0;
      for i, v in pairs(CPU_objects) do
        addtexttogame(tonumber(i)+1000,x,y,tostring(i)); 
        setcolor(tonumber(i)+1000,0,0,0,1,1);
        speciale_action(4,tonumber(i)+1000);
        fuck = fuck + 1;
        y = y + 24;
        if fuck == 3 then
          y = 5;
            x = x + 116;
            fuck = 0;
            if x == 852 then
              StartTimer(888666, 0.5);
            return; end;
        end;
      end;
    return; end;
  return; end;
  
  if sender==36 then
    if obj_id == 1536 then
      delete_tree_leaf("Root", "another_world");
      add_tree_leaf("Root", "another_world", 21, 0);
      dofile("./data/21/0/res.lua");
      dofile("./data/21/0/level.lua");
      ShowMenu(true);
      DarkScreen1(false);
    SetAlfa(9777778,1,0,0.5)          
      Block_Show_Cur(false);
    return; end;
    if obj_id == 888666 then
      flags.blockrender=false
      flags.GlobalHint =false
      CPU_Random();
      
    return; end;
    if obj_id==656565 then
        add_free_leaf("Root","comics13",21,51);
        set_satelite_leaf("another_world");
        DoFile(21,51)
    return;end;
    if obj_id == 8885 then
      MoveObjectY(1,-215,0,1);
      speciale_action(4,1)
    return; end;
    if obj_id == 88811 then
      Block_Show_Cur(false);
      CreatePlashechka(900000,"595")
    --  CreateWindow1(100,100,"595",nil,nil,200,200,nil,nil,nil);
    return; end;
    if obj_id == 88812 then
      Block_Show_Cur(false);
      CreatePlashechka(900000,"596")
    --  CreateWindow1(100,100,"596",nil,nil,200,200,nil,nil,nil);
    return; end;

  return; end;
  
  if sender == 26 then
    
  return; end;
end
function SheetSwitched(nCount)
end;