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

function pick()
local Numunits = GetNUnitsInScriptGroup(890, 0); 
if (Numunits <= 0 ) then
		Loose();
		DisplayTrace ("Twój generał dowodzący wojskami frontowymi został zabity", 2000); 
		Suicide();
	end;
end;

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

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

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

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

function zdaus() 
        ChangePlayer(444, 2);
	DisplayTrace ("Niemcy się poddali!", 2000); 
        Suicide();
end;

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


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


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


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


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


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

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

function Reinf1()
        if (GetNUnitsInArea(0, "village1") > 0) then
		LandReinforcement(1);
            LandReinforcement(2);
		 LandReinforcement(3);
		LandReinforcement(4);
		RunScript( "attack1", 30000);
		RunScript( "attack2", 50000);
           Suicide();
      end;
end;

function attack1()
local A_Swarm = 3; 
            Cmd(3,20,6604, 2520);
		Cmd(3,40,5881, 2093);
            Suicide();
 
end;

function attack2()
local A_Swarm = 3; 
            Cmd(3,30,2995, 816);
            Suicide();
 
end;

function Reinf2()
        if (GetNUnitsInArea(0, "village3") > 0) then
		LandReinforcement(5);
		RunScript( "Reinf3", 2000);
           Suicide();
      end;
end;

function Reinf3()
		LandReinforcement(6);
		RunScript( "attack3", 30000);
           Suicide();
end;

function attack3()
local A_Swarm = 3; 
            Cmd(3,60,2995, 816);
            Suicide();
 
end;

function Reinf4()
        if (GetNUnitsInArea(0, "village2") > 0) then
		LandReinforcement(7);
           Suicide();
      end;
end;

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

function Reinf6()
		if (GetNUnitsInArea(0, "great") > 0) then
		LandReinforcement(25);
		RunScript( "Fit1", 2000);
           Suicide();
      end;
end;

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

function Reinf7()
		if (GetNUnitsInArea(0, "city") > 0) then
		LandReinforcement(26);
		LandReinforcement(8);
		RunScript( "Fit2", 2000);
           Suicide();
      end;
end;

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

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

function Init()
	RunScript( "Objective0", 2000);
        RunScript( "Objective1", 2000);
        RunScript( "Objective2", 2000);
        RunScript( "Objective3", 2000);
	RunScript( "RevealObjective0", 2000);
               RunScript( "RevealObjective1", 5000);
	RunScript( "RevealObjective2", 9000);
               RunScript( "RevealObjective3", 15000);
        RunScript("TobeDefeated", 5000);
	RunScript( "ToWin", 4000);
	RunScript( "pick", 2000);
	RunScript( "Reinf1", 2000);
	RunScript( "Reinf2", 2000);
	RunScript( "Reinf4", 2000);
	RunScript( "Reinf6", 2000);
	RunScript( "Reinf7", 2000);
end;
