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


function Objective0()
	if (GetNUnitsInScriptGroup(5, 1) <= 3)then
		SetIGlobalVar( "temp.mort_omm.objective.0", 1);
		ObjectiveChanged(0, 1);
                  RunScript( "RevealObjective1", 2000);
        	RunScript( "RevealObjective2", 3000);
                  RunScript( "RevealObjective3", 4000);
		RunScript( "RevealObjective4", 5000);
		RunScript( "zero", 2000);
		RunScript( "Reinf15", 2000);
		Suicide();
	end;
end;


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


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


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

function Objective4()
         if (GetNUnitsInScriptGroup(111, 1) <= 1) then
		SetIGlobalVar( "temp.mort_omm.objective.4", 1);
		ObjectiveChanged(4, 1);
		Suicide();
	end;
end;

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


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


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


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


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


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

function RevealObjective4()
	if ( GetIGlobalVar("temp.mort_omm.objective.4", 0) == 0) then
		ObjectiveChanged(4, 0);
	end;
	Suicide();
end;

function Reinf1() 
       if (GetNUnitsInArea(0, "battle1") > 0) then
        RunScript("Reinforcement1", 1000);
        Suicide();
    end;
end;

function Reinforcement1()
        LandReinforcement(10);
        Suicide();
end;

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

function Reinf3() 
       if (GetNUnitsInArea(0, "battle3") > 0) then
        LandReinforcement(30);
        Suicide();
    end;
end;

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

function zero() 
       if (GetNUnitsInArea(0, "attack") > 0) then
	LandReinforcement(50);
        RunScript("ReinfCmds", 70000);  
        Suicide();
    end;
end;

function ReinfCmds()
local A_Swarm = 3; 
            Cmd(3,5,6218, 8906);
            Cmd(3,5,6220, 8908);
            Suicide();
 
end;

function Reinf6() 
       if (GetNUnitsInArea(0, "battle5") > 0) then
	LandReinforcement(60);
        RunScript("ReinfCmds1", 1000);  
        Suicide();
    end;
end;

function ReinfCmds1()
local A_Swarm = 3; 
            Cmd(3,6,7458, 2968);
            Suicide();
 
end;

function Reinf7() 
       if (GetNUnitsInArea(0, "battle5") > 0) then
	LandReinforcement(70);
        RunScript("ReinfCmds2", 1000);  
        Suicide();
    end;
end;

function ReinfCmds2()
local A_Swarm = 3; 
            Cmd(3,7,8096, 4088);
            Suicide();
 
end;

function Reinf8() 
       if (GetNUnitsInArea(0, "battle1") > 0) then
	LandReinforcement(80);
        RunScript("ReinfCmds3", 1000);  
        Suicide();
    end;
end;

function ReinfCmds3()
local A_Swarm = 3; 
            Cmd(3,8,5809, 5701);
            Suicide();
 
end;

function Reinf9() 
       if (GetNUnitsInArea(0, "battle6") > 0) then
	LandReinforcement(90);
	RunScript( "Reinf14", 2000); 
        Suicide();
    end;
end;

function Reinf10() 
       if (GetNUnitsInArea(0, "battle7") > 0) then
	LandReinforcement(100);
        RunScript("ReinfCmds4", 1000);  
        Suicide();
    end;
end;

function ReinfCmds4()
local A_Swarm = 3; 
            Cmd(3,10,8388, 3012);
            Suicide();
 
end;

function Reinf11() 
       if (GetNUnitsInArea(0, "battle8") > 0) then
	LandReinforcement(110); 
        Suicide();
    end;
end;

function Reinf12() 
	LandReinforcement(120); 
        Suicide();
end;

function Reinf13() 
       if (GetNUnitsInArea(0, "attle9") > 0) then
	LandReinforcement(130);
	RunScript( "Fit2", 2000); 
        Suicide();
    end;
end;

function Reinf14() 
	LandReinforcement(140);
	RunScript( "Fit3", 2000); 
        Suicide();
end;

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

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

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

function Reinf15() 
	LandReinforcement(150); 
        Suicide();
end;

function Init()
	RunScript( "Objective0", 2000);
        RunScript( "Objective1", 2000);
        RunScript( "Objective2", 2000);
        RunScript( "Objective3", 2000);
	RunScript( "Objective4", 2000);
	RunScript( "RevealObjective0", 2000);
	RunScript( "Reinf1", 2000);
	RunScript( "Reinf2", 2000);
	RunScript( "Reinf3", 2000);
	RunScript( "Reinf4", 2000);
	RunScript( "Reinf6", 2000);
	RunScript( "Reinf7", 2000);
	RunScript( "Reinf8", 2000);
	RunScript( "Reinf9", 2000);
	RunScript( "Reinf10", 2000);
	RunScript( "Reinf11", 2000);
	RunScript( "Reinf13", 2000);
	RunScript( "zero", 2000);
	RunScript( "Fit", 2000);
        RunScript("TobeDefeated", 5000);
	RunScript( "ToWin", 4000);
end;
