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


function Objective0()
         if (GetNUnitsInScriptGroup(111, 1) <= 1) then
		SetIGlobalVar( "temp.nuayon.objective.0", 1);
		ObjectiveChanged(0, 1);
		RunScript( "RevealObjective1", 2000);
		RunScript( "RevealObjective2", 2000);
		RunScript( "Reinf1", 2000);
		RunScript( "Reinf4", 2000);
		RunScript( "Reinf6", 2000);
		Suicide();
	end;
end;


function Objective1()
         if (GetNUnitsInScriptGroup(222, 1) <= 1) then
		SetIGlobalVar( "temp.nuayon.objective.1", 1);
		ObjectiveChanged(1, 1);
		Suicide();
	end;
end;


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

function last()
          if ( (GetIGlobalVar("temp.nuayon.objective.0", 0) * GetIGlobalVar("temp.nuayon.objective.1", 0) * GetIGlobalVar("temp.nuayon.objective.2", 0)) == 1) then
		RunScript( "Objective3", 2000);
		RunScript( "RevealObjective3", 2000);
		RunScript( "Reinf7", 2000);
		RunScript( "Reinf8", 2000);
		Suicide();
	end;
end;

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

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


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


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


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


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


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

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

function Reinf2() 
       if (GetNUnitsInArea(0, "bridhe2") > 0) then
	LandReinforcement(2);  
        Suicide();
    end;
end;

function Reinf3() 
       if (GetNUnitsInArea(0, "battle1") > 0) then
	LandReinforcement(1);
        RunScript("ReinfCmds", 40000);  
        Suicide();
    end;
end;

function ReinfCmds()
local A_Swarm = 3; 
            Cmd(3,10,7534, 7248);
            Suicide();
 
end;

function Reinf4() 
	LandReinforcement(30); 
        Suicide();
end;

function Reinf5() 
       if (GetNUnitsInArea(0, "battle2") > 0) then
	LandReinforcement(4);
        Suicide();
    end;
end;

function Fit1()
	AddIronMan(252);
	Suicide();
end;

function Fit2()
	AddIronMan(256);
	Suicide();
end;

function Reinf6() 
	LandReinforcement(200); 
        Suicide();
end;

function Reinf7() 
	LandReinforcement(100); 
        Suicide();
end;

function Reinf8() 
	LandReinforcement(400); 
        Suicide();
end;

function Reinf9() 
       if (GetNUnitsInArea(0, "city") > 0) then
	LandReinforcement(5);
	LandReinforcement(25);
        Suicide();
    end;
end;

function Reinf10() 
	LandReinforcement(600); 
        Suicide();
end;

function Init()
	RunScript( "Objective0", 2000);
        RunScript( "Objective1", 2000);
        RunScript( "Objective2", 2000);
        RunScript( "Objective3", 2000);
	RunScript( "Objective4", 2000);
	RunScript( "RevealObjective0", 2000);
        RunScript("TobeDefeated", 5000);
	RunScript( "Reinf2", 2000);
	RunScript( "Reinf3", 2000);
	RunScript( "Reinf5", 2000);
	RunScript( "Reinf9", 2000);
	RunScript( "Reinf10", 2000);
	RunScript( "last", 2000);
	RunScript( "Fit1", 2000);
	RunScript( "Fit2", 2000);
	RunScript( "ToWin", 4000);
end;
