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

function Objective0()
	if ( GetNUnitsInScriptGroup(2500) > 2) then
		SetIGlobalVar( "temp.balkani_fronte.objective.0", 1);
		ObjectiveChanged(0, 1);
		RunScript( "RevealObjective3", 3000);
                RunScript( "RevealObjective1", 3000);
		Suicide();
	end;
end;

function Objective1()
	if (GetNUnitsInScriptGroup(1, 1) < 2) then
		SetIGlobalVar( "temp.balkani_fronte.objective.1", 1);
		ObjectiveChanged(1, 1);
                RunScript( "RevealObjective2", 4000);
                RunScript( "RevealObjective5", 7000);
                 RunScript( "Reinf1", 5000); 
                RunScript("Attack", 3000);
                DisplayTrace( "Brytyjski posłaniec został wysłany do wioski Niche z wieściami o ataku na Skople.");
--                RunScript("Avia", 300000);	
		Suicide();
	end; 
end;

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


function Objective3()
	if (GetNUnitsInScriptGroup(999, 0) <= 0) then
         if ( GetIGlobalVar("temp.balkani_fronte.objective.3", 0) == 0) then  
			SetIGlobalVar("temp.balkani_fronte.objective.3", 2);
			ObjectiveChanged(3, 2);
                         RunScript("Reinf",3000);
                         RunScript("RevealObjective4",10000);
                         RunScript( "Objective4", 30000);
                   end;
		   Suicide();
	 else   
	if ( GetNUnitsInScriptGroup(66, 1) <= 0) then
		SetIGlobalVar( "temp.balkani_fronte.objective.3", 1);
		ObjectiveChanged(3, 1);
                Suicide();
        end;
        end; 
end;
       

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

function Objective5()
	if ((GetNUnitsInScriptGroup(15, 1) < 2) and (GetNUnitsInArea(0, "durres") > 0)) then
		SetIGlobalVar( "temp.balkani_fronte.objective.5", 1);
		ObjectiveChanged(5, 1);
		Suicide();
	end;
end;
 

function Damage()
        if (GetNUnitsInArea(0, "bridge") > 0) then
           DamageObject(2000, 0);      
           Suicide();
     end;
end;

function Reinf() 
         LandReinforcement(0);
         Cmd(3,40, 3758, 8906);
         Cmd(3,41, 3758, 8906);     
	Suicide();	
end;

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


function Attack() 
         Cmd(3,77, 2535, 3711);   
	Suicide();
end;


function Avia()
         EnableAviation(0, 3);
         Suicide();
end;


function DisableAvia()
	SwitchWeatherAutomatic(0);
	SwitchWeather(0);
	DiableAviation(0, 0); 
	DiableAviation(0, 1);
	DiableAviation(0, 2);
	DiableAviation(0, 3); -- bombardirovshik
	DiableAviation(0, 4);
	Suicide();
end;

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

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

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

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

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

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


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


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

function Init()
        RunScript("Damage", 1000); 
	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("DisableAvia", 0);
	RunScript( "ToWin", 4000);
end;
