function TobeDefeated()
local Numunits = GetNUnitsInScriptGroup(1000, 0) + GetNUnitsInScriptGroup(500, 0); 
if (Numunits <= 0 ) then
		Loose();
		Suicide();
	end;
end;



function Objective0()
local Numunits = GetNUnitsInScriptGroup(10) + GetNUnitsInScriptGroup(11) + GetNUnitsInScriptGroup(20) + GetNUnitsInScriptGroup(21); 
if (Numunits <= 10 ) then
		SetIGlobalVar("temp.gonelie.objective.0", 1);
                ObjectiveChanged(0, 1);
                RunScript( "RevealObjective1", 2000);
                RunScript( "Attack2", 6000);
                RunScript( "Town", 2000);
		Suicide();
	end;
end;


function Objective1()
  if (GetNUnitsInScriptGroup(1500, 0) <= 0) then
         if ( GetIGlobalVar("temp.gonelie.objective.3", 0) == 0) then  
			SetIGlobalVar("temp.gonelie.objective.1", 2);
			ObjectiveChanged(1, 2);
                        RunScript( "RevealObjective2", 2000);
                        RunScript( "RevealObjective3", 2000); 
                   end;
		   Suicide();
	 else    
  if ((GetNUnitsInScriptGroup(31, 1) < 2) and (GetNUnitsInScriptGroup(32, 1) < 6)) then
		SetIGlobalVar("temp.gonelie.objective.1", 1);
                ObjectiveChanged(1, 1);
                RunScript( "RevealObjective2", 2000);
                RunScript( "RevealObjective3", 2000);
                RunScript( "Reinf1", 2000);
                RunScript( "Avia", 30000); 
		Suicide();
	end;
     end;
end;


function Objective2()
           if (GetNUnitsInScriptGroup(50, 1) <= 0) then
		SetIGlobalVar("temp.gonelie.objective.2", 1);
                ObjectiveChanged(2, 1);
		Suicide();
	end;
end;


function Objective3()
           if (GetNUnitsInScriptGroup(60, 1) <= 0) then 
		SetIGlobalVar("temp.gonelie.objective.3", 1);
                ObjectiveChanged(3, 1);
		Suicide();
	end;
end;

	
function Attack1()
            Cmd(3,10,11110,6838);
            Cmd(3,11,11110,6838);

            Cmd(3,20,9884,2012);
            Cmd(3,21,9884,2012);
            Suicide();
end;


function Attack2()
          Cmd(3,31,10624,11166);
          Cmd(3,32,10624,11166);
          Suicide();
end; 


function Attack()
        if (GetNUnitsInArea(0, "attack") > 0) then
            LandReinforcement(1);
            RunScript( "Cmd2", 2000);   
           Suicide();
      end;
end;


function Attack3()
        if (GetNUnitsInArea(0, "attack1") > 0) then
            LandReinforcement(2);
            RunScript( "Cmd1", 2000);   
           Suicide();
      end;
end;

function Cmd1()
local A_Swarm = 3; 
            Cmd(3,99,5313,11636);         
end;
  

function Cmd2()
local A_Swarm = 3; 
             Cmd(3,88,4972,2824);        
end;


function Avianem()
         EnableAviation(1, 3);
         RunScript("EnableAvianem", 12000);
         Suicide();
end;  


function EnableAvianem()      
local A_Swarm = 3;
	EnableAviation(1, 3);
        Cmd(A_Swarm, 10000, 0, 10624,11166);
	Suicide();
end;


function DisableAvianem()
	DiableAviation(1, 2); 
	DiableAviation(1, 0);
	DiableAviation(1, 1);
	DiableAviation(1, 3); -- bombardirovshik
	DiableAviation(1, 4);
	Suicide();
end;


function Avia()
         EnableAviation(0, 0);
         EnableAviation(0, 1);
         Suicide();
end;


function DisableAvia()
	SwitchWeatherAutomatic(0);
	SwitchWeather(0);
	DiableAviation(0, 0); 
	DiableAviation(0, 1);
	DiableAviation(0, 2);
	DiableAviation(0, 3); 
	DiableAviation(0, 4);
	Suicide();
end;


function Reinf1() 
        LandReinforcement(0);
        Suicide();
end;


function Town()
           RunScript( "Avianem", 100000);    
           Suicide();
end;


function ToWin()
        if ( (GetIGlobalVar("temp.gonelie.objective.0", 0) * GetIGlobalVar("temp.gonelie.objective.2", 0) * GetIGlobalVar("temp.gonelie.objective.3", 0)) == 1) then
		RunScript( "WinWin", 4000);
		Suicide();
	end;
end;


function WinWin()
	Win(0);
	Suicide();
end;


function RevealObjective0()
        if ( GetIGlobalVar("temp.gonelie.objective.0", 0) == 0) then
	ObjectiveChanged(0, 0);
        end;
	Suicide();
end;


function RevealObjective1()
	if ( GetIGlobalVar("temp.gonelie.objective.1", 0) == 0) then
		ObjectiveChanged(1, 0);
	end;
	Suicide();
end;


function RevealObjective2()
	if ( GetIGlobalVar("temp.gonelie.objective.2", 0) == 0) then
		ObjectiveChanged(2, 0);
	end;
	Suicide();
end;


function RevealObjective3()
	if ( GetIGlobalVar("temp.gonelie.objective.3", 0) == 0) then
		ObjectiveChanged(3, 0);
	end;
	Suicide();
end;


function Init()
          RunScript( "DisableAvia", 0);
          RunScript( "DisableAvianem", 0);
	  RunScript( "Objective0", 2000);
          RunScript( "Objective1", 2000);
          RunScript( "Objective2", 6000);
          RunScript( "Objective3", 6000);
          RunScript( "RevealObjective0", 3000);
          RunScript( "Town", 3000);
          RunScript( "Attack", 3000);
          RunScript( "Attack1", 30000);
           RunScript( "ToWin", 30000);
          RunScript("TobeDefeated", 5000);
end;

