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

function Objective0()
	if (GetNUnitsInScriptGroup(1, 1) <= 0) then
		SetIGlobalVar( "temp.verden.objective.0", 1);
		ObjectiveChanged(0, 1);
                RunScript( "RevealObjective1", 3000);
                RunScript("Attack1", 10000);
                RunScript( "Objective1", 30000); 
                RunScript("Reinf1", 30000);
                KillScript( "Attack3", 3000);
		Suicide();
	end;
end;

function Objective1()
if ((GetNUnitsInScriptGroup(2, 1) <= 1) and (GetNUnitsInScriptGroup(4, 1) <= 1)) then 
		SetIGlobalVar( "temp.verden.objective.1", 1);  
		ObjectiveChanged(1, 1);
                RunScript( "RevealObjective2", 3000);
                RunScript( "RevealObjective3", 5000);
                RunScript("Aviafr", 50000);
                RunScript("Reinf2", 10000)	
		Suicide();
	end;
end;


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


function Objective3()
	if ((GetNUnitsInScriptGroup(35, 1) <= 2) and (GetNUnitsInScriptGroup(36, 1) <= 2)) then 
		SetIGlobalVar( "temp.verden.objective.3", 1);
		ObjectiveChanged(3, 1);
		Suicide();
	end;
end;

-------------Reinf----------------
function Reinf1() 
        LandReinforcement(0);
        RunScript("Reinf1Cmds", 5000);    
        Suicide();
end;


function Reinf1Cmds()
        Cmd(3,500,8057,11029);
        Cmd(3,501,8062,11451);
        Cmd(3,503,8062,11451);
        Cmd(3,502,7515,8643);
        Suicide();
end;

---------Attack--------------
function Attack1()
            LandReinforcement(2);
            RunScript("Reinf5Cmds", 10000);  
           Suicide();
end;


function Reinf5Cmds()
            Cmd(3,2,6747,11251);
            Cmd(3,3,6747,11251);
     
            Cmd(3,4,7110,11202);
            Cmd(3,5,7110,11202);
        Suicide();
end;


-----------Attack1----------------------
function Attack2()
        if (GetNUnitsInArea(0, "Attack") > 0) then   
             Cmd(3,15, 7796, 1956);
             Suicide();
      end;
end;
-----------Attack2----------------------
function Attack3()
        if (GetNUnitsInArea(0, "Attack1") > 0) then 
             LandReinforcement(3);
             RunScript("AttackCmds", 5000);  
             Suicide();
      end;
end;
-------------------------------------

function AttackCmds()
          Cmd(3,25, 9087, 7763);
        Suicide();
end;

------------Reinf2-----------------
function Reinf2() 
        LandReinforcement(1);
        RunScript("Reinf2Cmds", 5000);    
        Suicide();
end;


function Reinf2Cmds()
        Cmd(3,700,1795,4563);
        Cmd(3,701,1795,4563);
        Cmd(3,702,1795,4563);
        Cmd(3,703,3960,4440);
        Suicide();
end;
----------Aviation------------------
function Aviafr()
         EnableAviation(1, 3);
         Suicide();
end;

function DisableAviafr()
        SwitchWeatherAutomatic(0);
	SwitchWeather(0);
	DiableAviation(1, 2); 
	DiableAviation(1, 0);
	DiableAviation(1, 1);
	DiableAviation(1, 3); -- bombardirovshik
	DiableAviation(1, 4); 
	Suicide();
end;
------------------------------------------

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

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

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

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

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

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


function Init()
        RunScript( "DisableAviafr", 0);
	RunScript( "Objective0", 2000);
--	RunScript( "Objective1", 2000);
        RunScript( "Objective2", 2000);
        RunScript( "Objective3", 2000);
	RunScript( "RevealObjective0", 2000);
        RunScript("Attack2", 3000);
        RunScript("Attack3", 3000);
        RunScript("TobeDefeated", 5000);
	RunScript( "ToWin", 4000);
end;
