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


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

function Objective1()
         if (GetNUnitsInArea(0, "mission1") > 5) then
		SetIGlobalVar( "temp.battle_of_messin.objective.1", 1);
		ObjectiveChanged(1, 1);
		RunScript( "RevealObjective2", 2000);
		RunScript( "attack1", 60000);
		RunScript( "proval", 2000);
		Suicide();
	end;
end;

function attack1()
local A_Swarm = 3; 
            Cmd(3,222,9225, 558);
            Cmd(3,222,9225, 558);
            Suicide();
 
end;

function proval()
         if (GetNUnitsInArea(1, "sklad") > 3) then
		DisplayTrace ("Wojska niemieckie zajęły składy amunicji.", 2000);
		Loose();
		Suicide();
	end;
end;

function Objective2()
         if (GetNUnitsInScriptGroup(222, 1) <= 3) then
		SetIGlobalVar( "temp.battle_of_messin.objective.2", 1);
		ObjectiveChanged(2, 1);
		RunScript( "RevealObjective4", 2000);
		RunScript( "attack2", 30000);
		RunScript( "go1", 3000);
		Suicide();
	end;
end;

function attack2()
local A_Swarm = 3; 
            Cmd(3,333,3194, 1662);
            Cmd(3,333,3194, 1662);
            Suicide();
 
end;

function go1()
        if (GetNUnitsInArea(1, "take") > 0) then
            RunScript( "razvedka", 2000);
		DisplayTrace ("Wywiad donosi o zgrupowaniu wroga zbliżającym się do twoich pozycji.", 2000);	
           Suicide();
      end;
end;

function razvedka() 
        ChangePlayer(78, 0);
	RunScript( "RevealObjective3", 2000);
        Suicide();
end;

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

function Objective4()
         if (GetNUnitsInScriptGroup(444, 1) <= 1) then
		SetIGlobalVar( "temp.battle_of_messin.objective.4", 1);
		ObjectiveChanged(4, 1);
		RunScript( "RevealObjective5", 2000);
		RunScript( "Reinf2", 4000);
		RunScript( "Reinf3", 4000);
		Suicide();
	end;
end;

function Objective5()
	if (GetNUnitsInScriptGroup(555, 1) <= 1) then
		SetIGlobalVar( "temp.battle_of_messin.objective.5", 1);
		ObjectiveChanged(5, 1);
		Suicide();
	end;
end;

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


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


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


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


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


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

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

function RevealObjective5()
	if ( GetIGlobalVar("temp.battle_of_messin.objective.5", 0) == 0) then
		ObjectiveChanged(5, 0);
	end;
	Suicide();
end;

function last()
          if ( (GetIGlobalVar("temp.battle_of_messin.objective.0", 0) * GetIGlobalVar("temp.battle_of_messin.objective.1", 0) * GetIGlobalVar("temp.battle_of_messin.objective.2", 0) * GetIGlobalVar("temp.battle_of_messin.objective.3", 0)) == 1) then
		RunScript( "RevealObjective4", 2000);
		Suicide();
	end;
end;

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

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

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

function Reinf4()
        if (GetNUnitsInArea(0, "attack4") > 0) then
            LandReinforcement(2);
           Suicide();
      end;
end;

function Reinf5()
        if (GetNUnitsInArea(0, "attack5") > 0) then
            LandReinforcement(3);
           Suicide();
      end;
end;

function Reinf6()
        if (GetNUnitsInArea(0, "oborona1") > 0) then
            LandReinforcement(25);
		LandReinforcement(3);
		RunScript( "Fit1", 4000);
           Suicide();
      end;
end;

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

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

function Reinf7()
        if (GetNUnitsInArea(0, "oborona2") > 0) then
            LandReinforcement(26);
		LandReinforcement(4);
		RunScript( "Fit2", 4000);
           Suicide();
      end;
end;

function Init()
	RunScript( "Objective0", 2000);
        RunScript( "Objective1", 2000);
        RunScript( "Objective2", 2000);
        RunScript( "Objective3", 2000);
	RunScript( "Objective4", 2000);
	RunScript( "Objective5", 2000);
	RunScript( "RevealObjective0", 2000);
        RunScript("TobeDefeated", 5000);
	RunScript( "ToWin", 4000);
	RunScript( "Reinf1", 4000);
	RunScript( "Reinf4", 4000)
	RunScript( "Reinf5", 4000)
	RunScript( "Reinf6", 4000)
end;
