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

function ToLoose1()
if ( GetNUnitsInParty (0) <= 0) then
Loose(0);
DisplayTrace ("Unbelievable! The enemy has beaten you.");
Suicide();
end;
end;

function ToLoose2()
if (( GetNUnitsInArea (1, "looser1") > 0) or ( GetNUnitsInArea (1, "looser2") > 0) or ( GetNUnitsInArea (1, "looser3") > 0) or ( GetNUnitsInArea (1, "looser4") > 0)) then
Loose(0);
DisplayTrace ("The Russians have cut off the withdrawal path of");
DisplayTrace ("the 1st Armored Army.");
Suicide();
end;
end;

function Start()
SetIGlobalVar("ukol.0", 0);
SetIGlobalVar("ukol.1", 0);
SetIGlobalVar("ukol.2", 0);
SetIGlobalVar("ukol.3", 0);
SetIGlobalVar("ukol.4", 0);
SetIGlobalVar("konvoj1a", 0);
SetIGlobalVar("konvoj1b", 0);
SetIGlobalVar("konvoj1c", 0);
SetIGlobalVar("konvoj1d", 0);
SetIGlobalVar("konvoj2a", 0);
SetIGlobalVar("konvoj2b", 0);
SetIGlobalVar("konvoj2c", 0);
SetIGlobalVar("konvoj2d", 0);
SetIGlobalVar("konvoj2e", 0);
SetIGlobalVar("konvoj3a", 0);
SetIGlobalVar("konvoj3b", 0);
SetIGlobalVar("konvoj3c", 0);
SetIGlobalVar("konvoj3d", 0);
Suicide();
end;

function check_reinf()
if ( GetNUnitsInArea (1, "cutoff") >= 1) then
KillScript ("posily1");
KillScript ("posily2");
ObjectiveChanged(0, 2);
DisplayTrace ("Headquarters is unable to send you more units now.");
Suicide();
end;
end;

function check_arty_n()
if ( GetNUnitsInScriptGroup (151, 1) <= 1) then
RunScript( "arty_n" , 3000);
Suicide();
end;
end;

function check_arty_s()
if ( GetNUnitsInScriptGroup (152, 1) <= 0) then
RunScript( "arty_s" , 3000);
Suicide();
end;
end;

function arty_n()
LandReinforcement(153);
Suicide();
end;

function arty_s()
LandReinforcement(154);
Suicide();
end;

function RevealObjective0()
if ( GetIGlobalVar("ukol.0", 0) == 0) then
        ObjectiveChanged(0, 0);
        Suicide();
	else Suicide();
	end;
end;

function Objective0()
if ( GetNUnitsInArea (1, "cutoff") <= 0) then
	ObjectiveChanged(0, 1);
	Suicide();
	else Suicide();
	end;
end;

function RevealObjective1()
if ( GetIGlobalVar("ukol.1", 0) == 0) then
        ObjectiveChanged(1, 0);
        Suicide();
	else Suicide();
	end;
end;

function Objective1()
if ((GetIGlobalVar("ukol.2", 1) * GetIGlobalVar("ukol.3", 1) * GetIGlobalVar("ukol.4", 1)) == 1) then
SetIGlobalVar("ukol.1", 1);
ObjectiveChanged(1, 1);
RunScript( "Objective0" , 4000);
RunScript( "ToWin" , 8000);
Suicide();
end;
end;

function RevealObjective2()
if ( GetIGlobalVar("ukol.2", 0) == 0) then
        ObjectiveChanged(2, 0);
        Suicide();
	else Suicide();
	end;
end;

function Objective2()
if ((GetIGlobalVar("konvoj1a", 1) * GetIGlobalVar("konvoj1b", 1) * GetIGlobalVar("konvoj1c", 1) * GetIGlobalVar("konvoj1d", 1)) == 1) then
SetIGlobalVar("ukol.2", 1);
ObjectiveChanged(2, 1);
Suicide();
end;
end;

function RevealObjective3()
if ( GetIGlobalVar("ukol.3", 0) == 0) then
        ObjectiveChanged(3, 0);
        Suicide();
	else Suicide();
	end;
end;

function Objective3()
if ((GetIGlobalVar("konvoj2a", 1) * GetIGlobalVar("konvoj2b", 1) * GetIGlobalVar("konvoj2c", 1) * GetIGlobalVar("konvoj2d", 1) * GetIGlobalVar("konvoj2e", 1)) == 1) then
SetIGlobalVar("ukol.3", 1);
ObjectiveChanged(3, 1);
Suicide();
end;
end;

function RevealObjective4()
if ( GetIGlobalVar("ukol.4", 0) == 0) then
        ObjectiveChanged(4, 0);
        Suicide();
	else Suicide();
	end;
end;

function Objective4()
if ((GetIGlobalVar("konvoj3a", 1) * GetIGlobalVar("konvoj3b", 1) * GetIGlobalVar("konvoj3c", 1) * GetIGlobalVar("konvoj3d", 1)) == 1) then
SetIGlobalVar("ukol.4", 1);
ObjectiveChanged(4, 1);
Suicide();
end;
end;

function protiutok1()
LandReinforcement(101);
RunScript( "protiutok2", 180000);
Suicide();
end;

function protiutok2()
LandReinforcement(102);
RunScript( "protiutok3", 200000);
Suicide();
end;

function protiutok3()
LandReinforcement(103);
GiveCommand (36, 5000, 1, 3644, 8560);
RunScript( "konvoj1", 60000);
RunScript( "posily1", 180000);
Suicide();
end;

function posily1()
LandReinforcement(1);
RunScript( "protiutok4", 100000);
Suicide();
end;

function protiutok4()
LandReinforcement(104);
GiveCommand (36, 5000, 1, 5576, 1016);
RunScript( "protiutok5", 200000);
RunScript( "konvoj2", 240000);
Suicide();
end;

function protiutok5()
LandReinforcement(105);
RunScript( "protiutok6", 180000);
Suicide();
end;

function protiutok6()
LandReinforcement(106);
RunScript( "posily2", 60000);
Suicide();
end;

function posily2()
LandReinforcement(2);
RunScript( "protiutok7", 150000);
Suicide();
end;

function protiutok7()
LandReinforcement(107);
GiveCommand (36, 5000, 1, 4606, 6646);
RunScript( "protiutok8", 240000);
Suicide();
end;

function protiutok8()
LandReinforcement(108);
RunScript( "protiutok9", 240000);
Suicide();
end;

function protiutok9()
LandReinforcement(109);
RunScript( "konvoj3", 120000);
Suicide();
end;

function konvoj1()
LandReinforcement(21);
GiveCommand(0, 21, 2196, 1667);
GiveQCommand(0, 21, 2190, 6054);
GiveQCommand(0, 21, 53, 6060);
RunScript( "konvoj1b", 6000);
RunScript( "konvoj1_end", 1000);
RunScript( "RevealObjective2" , 1000);
Suicide();
end;

function konvoj1b()
LandReinforcement(22);
GiveCommand(0, 22, 2196, 1667);
GiveQCommand(0, 22, 2190, 6054);
GiveQCommand(0, 22, 53, 6060);
RunScript( "konvoj1c", 6000);
RunScript( "konvoj1b_end", 1000);
Suicide();
end;

function konvoj1c()
LandReinforcement(23);
GiveCommand(0, 23, 2196, 1667);
GiveQCommand(0, 23, 2190, 6054);
GiveQCommand(0, 23, 53, 6060);
RunScript( "konvoj1d", 6000);
RunScript( "konvoj1c_end", 1000);
Suicide();
end;

function konvoj1d()
LandReinforcement(24);
GiveCommand(0, 24, 2196, 1667);
GiveQCommand(0, 24, 2190, 6054);
GiveQCommand(0, 24, 53, 6060);
RunScript( "konvoj1d_end", 1000);
Suicide();
end;

function konvoj1_end()
if ( GetNScriptUnitsInArea (21, "exit") >= 1) then
DeleteReinforcement (21);
SetIGlobalVar("konvoj1a", 1);
Suicide();
end;
end;

function konvoj1b_end()
if ( GetNScriptUnitsInArea (22, "exit") >= 1) then
DeleteReinforcement (22);
SetIGlobalVar("konvoj1b", 1);
Suicide();
end;
end;

function konvoj1c_end()
if ( GetNScriptUnitsInArea (23, "exit") >= 1) then
DeleteReinforcement (23);
SetIGlobalVar("konvoj1c", 1);
Suicide();
end;
end;

function konvoj1d_end()
if ( GetNScriptUnitsInArea (24, "exit") >= 1) then
DeleteReinforcement (24);
SetIGlobalVar("konvoj1d", 1);
Suicide();
end;
end;

function konvoj2()
LandReinforcement(31);
GiveCommand(0, 31, 2196, 1667);
GiveQCommand(0, 31, 2190, 6054);
GiveQCommand(0, 31, 53, 6060);
RunScript( "konvoj2b", 6000);
RunScript( "konvoj2_end", 1000);
RunScript( "RevealObjective3" , 1000);
Suicide();
end;

function konvoj2b()
LandReinforcement(32);
GiveCommand(0, 32, 2196, 1667);
GiveQCommand(0, 32, 2190, 6054);
GiveQCommand(0, 32, 53, 6060);
RunScript( "konvoj2c", 6000);
RunScript( "konvoj2b_end", 1000);
Suicide();
end;

function konvoj2c()
LandReinforcement(33);
GiveCommand(0, 33, 2196, 1667);
GiveQCommand(0, 33, 2190, 6054);
GiveQCommand(0, 33, 53, 6060);
RunScript( "konvoj2d", 6000);
RunScript( "konvoj2c_end", 1000);
Suicide();
end;

function konvoj2d()
LandReinforcement(34);
GiveCommand(0, 34, 2196, 1667);
GiveQCommand(0, 34, 2190, 6054);
GiveQCommand(0, 34, 53, 6060);
RunScript( "konvoj2e", 6000);
RunScript( "konvoj2d_end", 1000);
Suicide();
end;

function konvoj2e()
LandReinforcement(35);
GiveCommand(0, 35, 2196, 1667);
GiveQCommand(0, 35, 2190, 6054);
GiveQCommand(0, 35, 53, 6060);
RunScript( "konvoj2e_end", 1000);
Suicide();
end;

function konvoj2_end()
if ( GetNScriptUnitsInArea (31, "exit") >= 1) then
DeleteReinforcement (31);
SetIGlobalVar("konvoj2a", 1);
Suicide();
end;
end;

function konvoj2b_end()
if ( GetNScriptUnitsInArea (32, "exit") >= 1) then
DeleteReinforcement (32);
SetIGlobalVar("konvoj2b", 1);
Suicide();
end;
end;

function konvoj2c_end()
if ( GetNScriptUnitsInArea (33, "exit") >= 1) then
DeleteReinforcement (33);
SetIGlobalVar("konvoj2c", 1);
Suicide();
end;
end;

function konvoj2d_end()
if ( GetNScriptUnitsInArea (34, "exit") >= 1) then
DeleteReinforcement (34);
SetIGlobalVar("konvoj2d", 1);
Suicide();
end;
end;

function konvoj2e_end()
if ( GetNScriptUnitsInArea (35, "exit") >= 1) then
DeleteReinforcement (35);
SetIGlobalVar("konvoj2e", 1);
Suicide();
end;
end;

function konvoj3()
LandReinforcement(41);
GiveCommand(0, 41, 2196, 1667);
GiveQCommand(0, 41, 2190, 6054);
GiveQCommand(0, 41, 53, 6060);
RunScript( "konvoj3b", 6000);
RunScript( "konvoj3_end", 1000);
RunScript( "RevealObjective4" , 1000);
Suicide();
end;

function konvoj3b()
LandReinforcement(42);
GiveCommand(0, 42, 2196, 1667);
GiveQCommand(0, 42, 2190, 6054);
GiveQCommand(0, 42, 53, 6060);
RunScript( "konvoj3c", 6000);
RunScript( "konvoj3b_end", 1000);
Suicide();
end;

function konvoj3c()
LandReinforcement(43);
GiveCommand(0, 43, 2196, 1667);
GiveQCommand(0, 43, 2190, 6054);
GiveQCommand(0, 43, 53, 6060);
RunScript( "konvoj3d", 6000);
RunScript( "konvoj3c_end", 1000);
Suicide();
end;

function konvoj3d()
LandReinforcement(44);
GiveCommand(0, 44, 2196, 1667);
GiveQCommand(0, 44, 2190, 6054);
GiveQCommand(0, 44, 53, 6060);
RunScript( "konvoj3d_end", 1000);
Suicide();
end;

function konvoj3_end()
if ( GetNScriptUnitsInArea (41, "exit") >= 1) then
DeleteReinforcement (41);
SetIGlobalVar("konvoj3a", 1);
Suicide();
end;
end;

function konvoj3b_end()
if ( GetNScriptUnitsInArea (42, "exit") >= 1) then
DeleteReinforcement (42);
SetIGlobalVar("konvoj3b", 1);
Suicide();
end;
end;

function konvoj3c_end()
if ( GetNScriptUnitsInArea (43, "exit") >= 1) then
DeleteReinforcement (43);
SetIGlobalVar("konvoj3c", 1);
Suicide();
end;
end;

function konvoj3d_end()
if ( GetNScriptUnitsInArea (44, "exit") >= 1) then
DeleteReinforcement (44);
SetIGlobalVar("konvoj3d", 1);
Suicide();
end;
end;

function Init()
RunScript( "Start" , 1000);
RunScript( "ToLoose1" , 5000);
RunScript( "ToLoose2" , 5000);
RunScript( "check_reinf" , 2000);
RunScript( "check_arty_n" , 17000);
RunScript( "check_arty_s" , 17000);
RunScript( "RevealObjective0" , 3000);
RunScript( "RevealObjective1" , 6000);
RunScript( "Objective1" , 5000);
RunScript( "Objective2" , 5000);
RunScript( "Objective3" , 5000);
RunScript( "Objective4" , 5000);
RunScript( "protiutok1", 150000);
end;