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


function Objective0()
	 if (GetNUnitsInScriptGroup(444, 1) <= 1) then
		SetIGlobalVar( "temp.river_ena.objective.0", 1);
		ObjectiveChanged(0, 1);                   
--		RunScript( "attack", 2000);
		RunScript( "back1", 2000);
		RunScript( "back2", 2000);
		Suicide();
	end;
end;


function Objective1()
         if (GetNUnitsInScriptGroup(111, 1) <= 1) then
		SetIGlobalVar( "temp.river_ena.objective.1", 1);
		ObjectiveChanged(1, 1);
                                    RunScript( "Reinf7", 8000);
		Suicide();
	end;
end;


function Objective2()
         if (GetNUnitsInScriptGroup(222, 1) <= 1) then
		SetIGlobalVar( "temp.river_ena.objective.2", 1);
		ObjectiveChanged(2, 1);
		RunScript( "Reinf8", 4000); 
		Suicide();
	end;
end;


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


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


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


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


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


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


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


function Fit()
	AddIronMan(121);
	Suicide();
end;

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

function attack() 
       if (GetNUnitsInArea(0, "start") > 0) then
        RunScript("ReinfCmds", 40000);  
        Suicide();
    end;
end;

function ReinfCmds()
local A_Swarm = 3; 
            Cmd(3,444,786, 7770);
            Suicide();
 
end;

function Reinf1() 
       if (GetNUnitsInArea(0, "battle1") > 0) then
	LandReinforcement(1);  
        Suicide();
    end;
end;

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

function Reinf3() 
       if (GetNUnitsInArea(0, "dattle3") > 0) then
	LandReinforcement(3);  
        Suicide();
    end;
end;

function Reinf4() 
       if (GetNUnitsInArea(0, "battle4") > 0) then
	LandReinforcement(4);  
        Suicide();
    end;
end;

function Reinf5() 
       if (GetNUnitsInArea(0, "battle5") > 0) then
	LandReinforcement(5);  
        Suicide();
    end;
end;

function Reinf6() 
       if (GetNUnitsInArea(0, "aga1") > 0) then
	LandReinforcement(6);  
        Suicide();
    end;
end;

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

function back1() 
        RunScript("ReinfCmds2", 90000);  
        Suicide();
end;

function ReinfCmds2()
local A_Swarm = 3; 
            Cmd(3,344,920, 3908);
            Suicide();
 
end;

function back2() 
        RunScript("ReinfCmds3", 90000);  
        Suicide();
end;

function ReinfCmds3()
local A_Swarm = 3; 
            Cmd(3,343,4911, 876);
            Suicide();
 
end;

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

function Fit3()
	AddIronMan(253);
	Suicide();
end;

function Init()
	RunScript( "Objective0", 2000);
        RunScript( "Objective1", 2000);
        RunScript( "Objective2", 2000);
        RunScript( "Objective3", 2000);
	RunScript( "RevealObjective0", 2000);
                  RunScript( "RevealObjective1", 2000);
	RunScript( "RevealObjective2", 2000);
	RunScript( "RevealObjective3", 2000);
	RunScript( "Reinf1", 2000);
	RunScript( "Reinf2", 2000);
--	RunScript( "Reinf3", 2000);
	RunScript( "Reinf4", 2000);
	RunScript( "Reinf5", 2000);
	RunScript( "Reinf6", 2000);
	RunScript( "Fit", 2000);
	RunScript( "Fit2", 2000);
	RunScript( "Fit3", 2000);
        RunScript("TobeDefeated", 5000);
	RunScript( "ToWin", 4000);
end;
