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

function Kill()
local Numunits = GetNUnitsInScriptGroup(99, 0); 
if (Numunits <= 0 ) then
		DisplayTrace ("Twój posłaniec został zabity.", 2000);
		Loose();
		Suicide();
	end;
end;

function Objective0()
	if (GetNUnitsInArea(0, "mission1") > 0) then
		SetIGlobalVar( "temp.somme.objective.0", 1);
		ObjectiveChanged(0, 1);
		RunScript( "RevealObjective1", 2000);
		RunScript( "RevealObjective2", 4000);
		RunScript( "RevealObjective3", 6000);
                                    RunScript( "RevealObjective5", 8000);
		RunScript( "good", 2000);
                                RunScript( "nogood", 2000);
		DisplayTrace ("Alianci zostali powiadomieni o połączonej ofensywie na tym odcinku frontu.", 2000);
		Suicide();
	end;
end;

function good() 
        ChangePlayer(88, 0);
	 ChangePlayer(77, 0);
	KillScript( "Kill", 2000);
	RunScript("TobeDefeated", 4000);
        Suicide();
end;

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

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

function Objective3()
         if (GetNUnitsInArea(0, "tank") > 0) then
		SetIGlobalVar( "temp.somme.objective.3", 1);
		ObjectiveChanged(3, 1);
		RunScript( "good1", 2000);
		Suicide();
	end;
end;

function good1() 
        ChangePlayer(789, 0);
	DisplayTrace ("Twoje wojska zdobyły niemiecki czołg.", 2000);
        Suicide();
end;

function nogood() 
          if (GetNUnitsInScriptGroup(789) <= 0) then
	SetIGlobalVar( "temp.somme.objective.3", 2);
		ObjectiveChanged(3, 2);
		Suicide();
	end;
end;

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

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

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


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


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


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


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


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

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

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

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

function Reinf1()
        if (GetNUnitsInArea(0, "village1") > 0) then
            LandReinforcement(25);
		RunScript( "massive1", 30000);
		RunScript( "Fit1", 4000);
           Suicide();
      end;
end;

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

function massive1()
		LandReinforcement(1);
		RunScript( "attack1", 2000);
           Suicide();
end;

function attack1()
local A_Swarm = 3; 
            Cmd(3,10,5629, 2832);
            Suicide();
 
end;

function Reinf2()
        if (GetNUnitsInArea(0, "village2") > 0) then
            LandReinforcement(26);
		RunScript( "Fit2", 4000);
           Suicide();
      end;
end;

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

function Reinf3()
        if (GetNUnitsInArea(0, "village3") > 0) then
            LandReinforcement(27);
		LandReinforcement(4);
		RunScript( "Fit3", 4000);
           Suicide();
      end;
end;

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

function Reinf4() 
	LandReinforcement(20); 
        Suicide();
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( "ToWin", 4000);
	RunScript( "Kill", 2000);
	RunScript( "last", 3000);
	RunScript( "Reinf1", 4000);
	RunScript( "Reinf2", 4000);
	RunScript( "Reinf3", 4000);
end;
