function TobeDefeated()
local Numunits = GetNUnitsInScriptGroup(100, 0) + GetNUnitsInScriptGroup(1001, 0) + GetNUnitsInScriptGroup(1100, 0); 
if (Numunits <= 0 ) then
		Loose();
		Suicide();
	end;
end;

function Objective0()
	if ( GetNUnitsInScriptGroup(1, 1) <= 0) then
		SetIGlobalVar( "temp.liez.objective.0", 1);
		ObjectiveChanged(0, 1);
		RunScript( "RevealObjective1", 3000);
                RunScript("Reinf2", 3000);
		Suicide();
	end;
end;

function Objective1()
	if ((GetNUnitsInScriptGroup(6, 1) < 2) and (GetNUnitsInArea(0, "sklad") > 0)) then
		SetIGlobalVar( "temp.liez.objective.1", 1);
		ObjectiveChanged(1, 1);
                RunScript( "RevealObjective2", 5000);
                RunScript( "RevealObjective3", 10000);	
		Suicide();
	end;
end;

function Objective2()
	if (GetNUnitsInScriptGroup(3, 1) < 3) then
		SetIGlobalVar( "temp.liez.objective.2", 1);
		ObjectiveChanged(2, 1);
                RunScript("Reinf1", 3000);
                RunScript( "RevealObjective4", 6000);
                RunScript("TobeDefeated", 12000);
		Suicide();
	end;
end;


function Objective3()
	if (GetNUnitsInArea(0, "Castle") > 0) then
                SetIGlobalVar( "temp.liez.objective.3", 1);
		ObjectiveChanged(3, 1);
		Suicide();
	end;
end;


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


function DamageBridge()
local num = GetNUnitsInArea(0, "Bridge");
	if (num > 0) then
           DamageObject(2000, 0);
           Suicide();
	end;
end;

function DamageBridge1()
local num = GetNUnitsInArea(0, "Bridge1");
	if (num > 0) then
           DamageObject(2001, 0);
           Suicide();
	end;
end;

function Attack()
local A_Swarm = 3;
        if (GetNUnitsInArea(0, "Reinf1") > 0) then 
            Cmd(3,50,4772,1752);
           Suicide();
      end;
end;


function Reinf1() 
        LandReinforcement(0);
        Suicide();
end;


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


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

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

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

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

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

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

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


function Init()
        RunScript("DamageBridge", 1000);
        RunScript("DamageBridge1", 1000);  
        RunScript( "Objective0", 2000);
        RunScript( "Objective1", 2000);
        RunScript( "Objective2", 2000);
        RunScript( "Objective3", 4000);
       RunScript( "Objective4", 5000);
        RunScript( "RevealObjective0", 2000);
        RunScript("Attack", 4000);
	RunScript( "ToWin", 4000);
end;
