function Objective0()
  if ( GetIGlobalVar("temp.riga.objective.0", 0) == 0) then     
	ObjectiveChanged(0, 0);

	EnableAviation (0, 0);
	EnableAviation (0, 1);
	DisableAviation (0, 3);
	DisableAviation (0, 2);
	DisableAviation (0, 4);

	EnableAviation (1, 0);
	EnableAviation (1, 1);
	EnableAviation (1, 4);
	DisableAviation (1, 2);
	DisableAviation (1, 3);

	Suicide();
  end;	
end;

---------------------------------------------------------------------------------

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

---------------------------------------------------------------------------------

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


---------------------------------------------------------------------------------
function Objective3()
  if ( GetIGlobalVar("temp.riga.objective.3", 0) == 0) then     
	ObjectiveChanged(3, 0);
	Suicide();
  end;	
end;

--------------------------------------------------------------------------------

function z_0()
	if ((GetNUnitsInScriptGroup(2) + GetNUnitsInScriptGroup(3)+ GetNUnitsInScriptGroup(4)) <= 0) then
	SetIGlobalVar("temp.riga.objective.0", 1);
	ObjectiveChanged(0, 1);
	RunScript("Objective1", 2000);
	LandReinforcement(50);
	Suicide();
	end;
end;

---------------------------------------------------------------------------------

function z_1()
	if (GetNUnitsInArea(1, "z1") < 2) then
	SetIGlobalVar("temp.riga.objective.1", 1);
	ObjectiveChanged(1, 1);
	RunScript("Objective2", 2000);
	LandReinforcement(55);
	Suicide();
	end;
end;

---------------------------------------------------------------------------------

function z_2()
	if (GetNUnitsInArea(1, "z2") < 1) then
	SetIGlobalVar("temp.riga.objective.2", 1);
	ObjectiveChanged(2, 1);
	RunScript("Objective3", 2000);
	LandReinforcement(60);
	Suicide();
	end;
end;

---------------------------------------------------------------------------------

function z_3()
zone1 = GetNUnitsInArea(1, "z3_0")
zone2 = GetNUnitsInArea(1, "z3_1")

	if ( zone1 + zone2 < 1) then
	SetIGlobalVar("temp.riga.objective.3", 1);
	ObjectiveChanged(3, 1);
	RunScript("Objective3", 2000);
	Suicide();
	end;
end;

---------------------------------------------------------------------------------

function p2()
     		p0x, p0y, radius = GetScriptAreaParams ("p0");

	if (GetNUnitsInArea (1, "p2") <= 0) then
	LandReinforcement(30);
	Cmd (0,31,p0x,p0y);
	Suicide();
     	end;			
		
end;

---------------------------------------------------------------------------------

function p4()
     		p4x, p4y, radius = GetScriptAreaParams ("p4");

	if (GetNUnitsInArea (0, "p0") >= 1) then
	Cmd (0,56,p4x,p4y);
	Suicide();
     	end;			
		
end;

---------------------------------------------------------------------------------

function ToWin()
	if ((GetIGlobalVar("temp.riga.objective.0", 0) 
	* GetIGlobalVar("temp.riga.objective.1", 0) 
	* GetIGlobalVar("temp.riga.objective.2", 0) 
	* GetIGlobalVar("temp.riga.objective.3", 0)) == 1) then
		Win(0);
		Suicide();
	end;
end;

---------------------------------------------------------------------------------

function gamover_Loose1()
	if ( GetNUnitsInParty (0) < 1) then
	RunScript("gamover_Loose0", 5000);
	Suicide();
	end;
end;

---------------------------------------------------------------------------------

function gamover_Loose0()
        Loose();
        Suicide();
end;

---------------------------------------------------------------------------------

function Land100()

		GiveCommand(3,2,x100,y100);
		GiveCommand(3,3,x100,y100);

Group2 = GetNUnitsInScriptGroup(2)
Group3 = GetNUnitsInScriptGroup(3)
Group4 = GetNUnitsInScriptGroup(4)

		--DisplayTrace ("Group2= %g Group3= %g Group4= %g", Group2, Group3, Group4);
		--DisplayTrace ("x= %g y= %g", x100, y100);

		if (Group2 + Group3  < 4) then
	
		GiveCommand(3,4,x100,y100);

		end;



			if ( GetNUnitsInArea(0, "x1") > 0) then
                                              x100, y100 = GetScriptAreaParams ("x1");

			end;


			if ( GetNUnitsInArea(0, "x9") > 0) then
                                              x100, y100 = GetScriptAreaParams ("x9");

			end;

			if ( GetNUnitsInArea(0, "x2") > 0) then
                                              x100, y100 = GetScriptAreaParams ("x2");

			end;

			if ( GetNUnitsInArea(0, "x3") > 0) then
                                              x100, y100 = GetScriptAreaParams ("x3");

			end;

			if ( GetNUnitsInArea(0, "x4") > 0) then
                                              x100, y100 = GetScriptAreaParams ("x4");

			end;

			if ( GetNUnitsInArea(0, "x5") > 0) then
                                              x100, y100 = GetScriptAreaParams ("x5");

			end;

			if ( GetNUnitsInArea(0, "x6") > 0) then
                                              x100, y100 = GetScriptAreaParams ("x6");

			end;


			if ( GetNUnitsInArea(0, "x7") > 0) then
                                              x100, y100 = GetScriptAreaParams ("x7");

			end;

			if ( GetNUnitsInArea(0, "x8") > 0) then
                                              x100, y100 = GetScriptAreaParams ("x8");

			end;

			if ( GetNUnitsInArea(0, "x10") > 0) then
                                              x100, y100 = GetScriptAreaParams ("x10");

			end;
			if ( GetNUnitsInArea(0, "x0") > 0) then
                                              x100, y100 = GetScriptAreaParams ("x0");

			end;


end;

---------------------------------------------------------------------------------

function Land200()

		GiveCommand(3,33,x200,y200);




			if ( GetNUnitsInArea(0, "d1") > 0) then
                                              x200, y200 = GetScriptAreaParams ("d1");

			end;


			if ( GetNUnitsInArea(0, "d9") > 0) then
                                              x200, y200 = GetScriptAreaParams ("d9");

			end;

			if ( GetNUnitsInArea(0, "d2") > 0) then
                                              x200, y200 = GetScriptAreaParams ("d2");

			end;

			if ( GetNUnitsInArea(0, "d3") > 0) then
                                              x200, y200 = GetScriptAreaParams ("d3");

			end;

			if ( GetNUnitsInArea(0, "d4") > 0) then
                                              x200, y200 = GetScriptAreaParams ("d4");

			end;

			if ( GetNUnitsInArea(0, "d5") > 0) then
                                              x200, y200 = GetScriptAreaParams ("d5");

			end;

			if ( GetNUnitsInArea(0, "d6") > 0) then
                                              x200, y200 = GetScriptAreaParams ("d6");

			end;


			if ( GetNUnitsInArea(0, "d7") > 0) then
                                              x200, y200 = GetScriptAreaParams ("d7");

			end;

			if ( GetNUnitsInArea(0, "d8") > 0) then
                                              x200, y200 = GetScriptAreaParams ("d8");

			end;

			if ( GetNUnitsInArea(0, "d10") > 0) then
                                              x200, y200 = GetScriptAreaParams ("d10");

			end;
			if ( GetNUnitsInArea(0, "d0") > 0) then
                                              x200, y200 = GetScriptAreaParams ("d0");

			end;

			if ( GetNUnitsInArea(0, "d11") > 0) then
                                              x200, y200 = GetScriptAreaParams ("d11");

			end;

			if ( GetNUnitsInArea(0, "d12") > 0) then
                                              x200, y200 = GetScriptAreaParams ("d12");

			end;

			if ( GetNUnitsInArea(0, "d14") > 0) then
                                              x200, y200 = GetScriptAreaParams ("d14");

			end;

			if ( GetNUnitsInArea(0, "d13") > 0) then
                                              x200, y200 = GetScriptAreaParams ("d13");

			end;
			if ( GetNUnitsInArea(0, "d15") > 0) then
                                              x200, y200 = GetScriptAreaParams ("d15");

			end;

end;

---------------------------------------------------------------------------------

function Land300()

		GiveCommand(3,44,x300,y300);




			if ( GetNUnitsInArea(0, "f1") > 0) then
                                              x300, y300 = GetScriptAreaParams ("f1");

			end;


			if ( GetNUnitsInArea(0, "f9") > 0) then
                                              x300, y300 = GetScriptAreaParams ("f9");

			end;

			if ( GetNUnitsInArea(0, "f2") > 0) then
                                              x300, y300 = GetScriptAreaParams ("f2");

			end;

			if ( GetNUnitsInArea(0, "f3") > 0) then
                                              x300, y300 = GetScriptAreaParams ("f3");

			end;

			if ( GetNUnitsInArea(0, "f4") > 0) then
                                              x300, y300 = GetScriptAreaParams ("f4");

			end;

			if ( GetNUnitsInArea(0, "f5") > 0) then
                                              x300, y300 = GetScriptAreaParams ("f5");

			end;

			if ( GetNUnitsInArea(0, "f6") > 0) then
                                              x300, y300 = GetScriptAreaParams ("f6");

			end;


			if ( GetNUnitsInArea(0, "f7") > 0) then
                                              x300, y300 = GetScriptAreaParams ("f7");

			end;

			if ( GetNUnitsInArea(0, "f8") > 0) then
                                              x300, y300 = GetScriptAreaParams ("f8");

			end;

			if ( GetNUnitsInArea(0, "f10") > 0) then
                                              x300, y300 = GetScriptAreaParams ("f10");

			end;
			if ( GetNUnitsInArea(0, "f0") > 0) then
                                              x300, y300 = GetScriptAreaParams ("f0");

			end;

			if ( GetNUnitsInArea(0, "f11") > 0) then
                                              x300, y300 = GetScriptAreaParams ("f11");

			end;

			if ( GetNUnitsInArea(0, "f12") > 0) then
                                              x300, y300 = GetScriptAreaParams ("f12");

			end;

			if ( GetNUnitsInArea(0, "f14") > 0) then
                                              x300, y300 = GetScriptAreaParams ("f14");

			end;

			if ( GetNUnitsInArea(0, "f13") > 0) then
                                              x300, y300 = GetScriptAreaParams ("f13");

			end;
			if ( GetNUnitsInArea(0, "f15") > 0) then
                                              x300, y300 = GetScriptAreaParams ("f15");

			end;

end;

-----------------------------------------------------------------------------------

function Init()
	RunScript("Objective0", 2000);
	RunScript("z_0", 2000);
	RunScript("z_1", 2000);
	RunScript("z_2", 2000);
	RunScript("z_3", 2000);
	RunScript("p2", 2000);
	RunScript("d1", 2000);
	RunScript("Land100", 5000);
	RunScript("Land200", 5000);
	RunScript("Land300", 5000);
	RunScript("p4", 2000);
	RunScript("ToWin", 2000);
	RunScript("gamover_Loose1", 2000);
end;
