import("ScarUtil.scar")

function OnGameSetup()

	g_CheckAnnihilate = false
	player1 = World_GetPlayerAt(1)
	player2 = World_GetPlayerAt(2)
	player3 = World_GetPlayerAt(3)
	player4 = World_GetPlayerAt(4)

end

--Code and Map by $ TEXAS $
function OnInit()

LOCSTRINGS = 
	{	
		TITLE = "Desert Hill",
		OBJECTIVE = "Hold the hill",
		OBJECTIVE2 = "Hold bridge for Armor reinforcements",
		OBJECTIVE3 = "Allied infantry will air drop in",		
		REINFORCEMENTS = "Reinforcements have arrived",	
		PARA = "Para Reinforcements have arrived",
		KT = "Axis has sent in a King Tiger",
	}
	for key, value in pairs(LOCSTRINGS) do LOCSTRINGS[key] = Util_CreateLocString(value) end


SOUNDS =
{
BACKGROUND = "ambiences/ambiences_streamed/m01_ambience_ridge",
}
for key, value in pairs(SOUNDS) do Sound_PreCacheSound(value) end
Sound_PlayStreamed(SOUNDS.BACKGROUND)
Util_PlayMusic("SOUND/Music/sp/m14/m14_ob1_killace", 0, 0)
status_intro = 1
timer = 1
Gamestyle = 1
gametype()
startAttack()
Axis_Basicinf = {SBP.AXIS.GRENADIER, SBP.AXIS.VOLKSGRENADIER}
Axis_SupportVehicles = {SBP.AXIS.PAK_38, SBP.AXIS.HALFTRACK, SBP.AXIS.HALFTRACK_FLAME, SBP.AXIS.HALFTRACK_STUKA, SBP.AXIS.MOTORCYCLE, SBP.AXIS.PUMA, SBP.AXIS.PUMA, SBP.AXIS.PUMA, SBP.AXIS.PUMA, SBP.AXIS.NEBELWERFER}
Axis_Supportinf = {SBP.AXIS.KNIGHTSCROSS, SBP.AXIS.OFFICER, SBP.AXIS.SNIPER, SBP.AXIS.SNIPER, SBP.AXIS.HEAVYMG, SBP.AXIS.HEAVYMG, SBP.AXIS.STORMTROOPER, SBP.AXIS.STORMTROOPER, SBP.AXIS.STORMTROOPER}
Axis_Armor = {SBP.AXIS.PANZER, SBP.AXIS.PANZER, SBP.AXIS.PANZER, SBP.AXIS.OSTWIND, SBP.AXIS.STUG, SBP.AXIS.PANTHER, SBP.AXIS.STUG, SBP.AXIS.STUG, SBP.AXIS.TIGER}
Axis_KT = {SBP.AXIS.KING_TIGER}

PE_Basicinf = {SBP.ELITE.PANZERGRENADIER, SBP.ELITE.ASSAULTGRENADIER}
PE_SupportVehicles = {SBP.ELITE.HALFTRACK_SNIPER, SBP.ELITE.HALFTRACK_MORTAR, SBP.ELITE.HALFTRACK_250, SBP.ELITE.ARMOURCAR_223, SBP.ELITE.ARMOURCAR_222, SBP.ELITE.ARMOURCAR_221}
PE_Supportinf = {SBP.ELITE.TANKBUSTERS, SBP.ELITE.FALLSCHIRMJAGER, SBP.ELITE.LUFTWAFFE, SBP.ELITE.TANKBUSTERS, SBP.ELITE.FALLSCHIRMJAGER, SBP.ELITE.HEAVYMG, SBP.ELITE.HEAVYMG}
PE_Armor = {SBP.ELITE.MARDER, SBP.ELITE.PANTHER, SBP.ELITE.WIRBLEWIND, SBP.ELITE.MARDER, SBP.ELITE.HETZER, SBP.ELITE.PANZER_SUPPORT, SBP.ELITE.PANZER_SUPPORT}
PE_JP = {SBP.ELITE.JAGDPANTHER}

American_Armor = {SBP.ALLIES.SHERMAN, SBP.ALLIES.SHERMAN, SBP.ALLIES.SHERMAN, SBP.ALLIES.CROCODILE, SBP.ALLIES.CROCODILE, SBP.ALLIES.PERSHING, SBP.ALLIES.CALLIOPE, SBP.ALLIES.M10, SBP.ALLIES.M10}
British_Armor = {SBP.CW.CHURCHILL_AVRE, SBP.CW.CHURCHILL_CROC, SBP.CW.CHURCHILL, SBP.CW.CROMWELL, SBP.CW.CROMWELL, SBP.CW.CROMWELL, SBP.CW.CROMWELL, SBP.CW.COMMAND_CROMWELL, SBP.CW.STUART, SBP.CW.STUART, SBP.CW.STUART, SBP.CW.FIREFLY, SBP.CW.FIREFLY}
American_Support = {SBP.ALLIES.JEEP, SBP.ALLIES.AT_57MM, SBP.ALLIES.GREYHOUND, SBP.ALLIES.GREYHOUND, SBP.ALLIES.SNIPER, SBP.ALLIES.HEAVYMG, SBP.ALLIES.RANGER, SBP.ALLIES.ENGINEER}
British_Support = {SBP.CW.BREN_CARRIER, SBP.CW.TETRARCH, SBP.CW.COMMANDOS_JEEP, SBP.CW.COMMANDOS_SNIPER, SBP.CW.COMMANDOS_MG, SBP.CW.COMMANDOS_SNIPER, SBP.CW.LIEUTENANT, SBP.CW.SAPPER}

Rule_AddInterval(Game_OverLose, 1)
Rule_AddInterval(timer1, 1)

Rule_AddInterval(Modivation, 10)

Rule_AddInterval(tankreinf, 600)
Rule_AddInterval(Airdrop, 480)

Rule_AddInterval(BasicInf, 120)
Rule_AddInterval(support_inf, 200)

Rule_AddInterval(support_Vehicle, 300)
Rule_AddInterval(TANKS, 540)
Rule_AddInterval(resource, 60)


end

Scar_AddInit(OnInit)

function timer1()
if timer == 5 then
Util_GlobalMessage(LOCSTRINGS.TITLE, 3)
elseif timer == 10 then
Util_GlobalMessage(LOCSTRINGS.OBJECTIVE, 7)
elseif timer == 18 then
Util_GlobalMessage(LOCSTRINGS.OBJECTIVE2, 7)
elseif timer == 25 then
Util_GlobalMessage(LOCSTRINGS.OBJECTIVE3, 7)
elseif timer == 480 then
AlliedReinfOne()
elseif timer == 960 then
AlliedReinfTwo()
elseif timer == 1440 then
AlliedReinfThree()
elseif timer == 1920 then
AlliedReinfFour()
elseif timer == 2000 then
Finalassult()
elseif timer == 2400 then
Game_OverWin()
Rule_RemoveMe()
end

timer = timer + 1

end

function gametype()

	if Player_GetID(Game_GetLocalPlayer()) == Player_GetID(player3) or Player_GetID(Game_GetLocalPlayer()) == Player_GetID(player4) then 
	Gamestyle = 2
	else
	Gamestyle = 1
	end
end


function startAttack()

	Cmd_AttackMoveThenCapture(sg_Axis, eg_HILL, 15)
	Cmd_AttackMoveThenCapture(sg_PE, eg_HILL, 15)

	EGroup_SetInvulnerable(eg_indestructable, true)

	Player_SetAbilityAvailability(player1, ABILITY.CW.HQ_REINFORCE, ITEM_LOCKED)
	Player_SetAbilityAvailability(player2, ABILITY.CW.HQ_REINFORCE, ITEM_LOCKED)

	Player_SetAbilityAvailability(player1, ABILITY.ALLIES.STICKY_BOMB, ITEM_UNLOCKED)
	Player_SetAbilityAvailability(player1, ABILITY.ALLIES.GRENADE, ITEM_UNLOCKED)
	Player_SetAbilityAvailability(player1, ABILITY.ALLIES.BAR_SUPPRESSION, ITEM_UNLOCKED)

	Player_SetMaxPopulation(player1, CT_Personnel, 200)
	Player_SetMaxPopulation(player2, CT_Personnel, 200)
	Player_SetMaxPopulation(player3, CT_Personnel, 200)
	Player_SetMaxPopulation(player4, CT_Personnel, 200)

	Timer_Start("Timer", 40*60)
end

function resource()
	
	Player_AddResource(player1, RT_Manpower, 50)
	Player_AddResource(player1, RT_Munition, 75)
	Player_AddResource(player1, RT_Fuel, 20)

	Player_AddResource(player2, RT_Manpower, 50)
	Player_AddResource(player2, RT_Munition, 75)
	Player_AddResource(player2, RT_Fuel, 20)

	Player_AddResource(player3, RT_Manpower, 0)
	Player_AddResource(player3, RT_Munition, 100)
	Player_AddResource(player3, RT_Fuel, 20)

	Player_AddResource(player4, RT_Manpower, 0)
	Player_AddResource(player4, RT_Munition, 100)
	Player_AddResource(player4, RT_Fuel, 20)
end

function Modivation()  --for coward AI
	local targetpos = marker77

	Cmd_AttackMove(sg_Axis, Util_GetPosition(targetpos), 15)
	Cmd_AttackMoveThenCapture(sg_Attackers, eg_HILL, 15)	
	Cmd_AttackMoveThenCapture(sg_BridgeAssult, eg_Bridge, 15)
	
end

function tankreinf()
	if EGroup_IsCapturedByPlayer(eg_Bridge, player1, ANY) or EGroup_IsCapturedByPlayer(eg_Bridge, player2, ANY) then
	Span_Tank_Al()
	Span_Tank_CW()	
	end
end

function Span_Tank_Al()
	local spawnpos = marker1
	local targetpos = marker2
		
	local NumTanks = World_GetRand(0, 1)
	if NumTanks == 0 then
	Util_CreateSquads(player1, sg_defenders, American_Armor[World_GetRand(1, table.getn(American_Armor))], spawnpos, nil, 1) 
--	Cmd_Move(sg_defenders, Util_GetPosition(targetpos), 15)
	elseif NumTanks == 1 then
	Util_CreateSquads(player1, sg_defenders, American_Armor[World_GetRand(1, table.getn(American_Armor))], spawnpos, nil, 1)
	Util_CreateSquads(player1, sg_defenders, American_Armor[World_GetRand(1, table.getn(American_Armor))], spawnpos, nil, 1) 
--	Cmd_Move(sg_defenders, Util_GetPosition(targetpos), 15)
	end	
	 
	if Player_GetID(Game_GetLocalPlayer()) == Player_GetID(player1) then		
		EventCue_Create(CUE.NORMAL, LOCSTRINGS.REINFORCEMENTS, LOCSTRINGS.REINFORCEMENTS)
		UI_CreateMinimapBlip(spawnpos, 20, BT_GeneralPing)
	end	
end
function Span_Tank_CW()
	local spawnpos = marker1
	local targetpos = marker2
		
	local NumTanks = World_GetRand(0, 1)
	if NumTanks == 0 then
	Util_CreateSquads(player2, sg_defenders, British_Armor[World_GetRand(1, table.getn(British_Armor))], spawnpos, nil, 1) 
--	Cmd_Move(sg_defenders, Util_GetPosition(targetpos), 15)
	elseif NumTanks == 1 then
	Util_CreateSquads(player2, sg_defenders, British_Armor[World_GetRand(1, table.getn(British_Armor))], spawnpos, nil, 1)
	Util_CreateSquads(player2, sg_defenders, British_Armor[World_GetRand(1, table.getn(British_Armor))], spawnpos, nil, 1) 
--	Cmd_Move(sg_defenders, Util_GetPosition(targetpos), 15)
	end	
	 
	if Player_GetID(Game_GetLocalPlayer()) == Player_GetID(player2) then		
		EventCue_Create(CUE.NORMAL, LOCSTRINGS.REINFORCEMENTS, LOCSTRINGS.REINFORCEMENTS)
		UI_CreateMinimapBlip(spawnpos, 20, BT_GeneralPing)
	end	
end

function Airdrop()

	local spawnpos = marker3
	local targetpos = marker2

	
	spawnpos = Util_GetPosition(Marker_FromName("marker"..World_GetRand(3,24), "cyan_marker"))
	Util_Paradrop(player1, sg_defenders, SBP.ALLIES.PARATROOPER, spawnpos, 1)
	spawnpos = Util_GetPosition(Marker_FromName("marker"..World_GetRand(3,24), "cyan_marker"))
	Util_Paradrop(player1, sg_defenders, SBP.ALLIES.PARATROOPER, spawnpos, 1)
	spawnpos = Util_GetPosition(Marker_FromName("marker"..World_GetRand(3,24), "cyan_marker"))
	Util_Paradrop(player1, sg_defenders, SBP.ALLIES.PARATROOPER, spawnpos, 1)
	spawnpos = Util_GetPosition(Marker_FromName("marker"..World_GetRand(3,24), "cyan_marker"))
	Util_Paradrop(player1, sg_defenders, SBP.ALLIES.PARATROOPER, spawnpos, 1)
	spawnpos = Util_GetPosition(Marker_FromName("marker"..World_GetRand(3,24), "cyan_marker"))
	Util_Paradrop(player1, sg_defenders, SBP.ALLIES.PARATROOPER, spawnpos, 1)
	spawnpos = Util_GetPosition(Marker_FromName("marker"..World_GetRand(3,24), "cyan_marker"))
	Util_Paradrop(player1, sg_defenders, SBP.ALLIES.PARATROOPER, spawnpos, 1)

	spawnpos = Util_GetPosition(Marker_FromName("marker"..World_GetRand(3,24), "cyan_marker"))
	Util_Paradrop(player2, sg_defenders, SBP.CW.COMMANDOS_PARATROOPER_SP, spawnpos, 1)
	spawnpos = Util_GetPosition(Marker_FromName("marker"..World_GetRand(3,24), "cyan_marker"))
	Util_Paradrop(player2, sg_defenders, SBP.CW.COMMANDOS_PARATROOPER_SP, spawnpos, 1)
	spawnpos = Util_GetPosition(Marker_FromName("marker"..World_GetRand(3,24), "cyan_marker"))
	Util_Paradrop(player2, sg_defenders, SBP.CW.COMMANDOS_PARATROOPER_SP, spawnpos, 1)
	spawnpos = Util_GetPosition(Marker_FromName("marker"..World_GetRand(3,24), "cyan_marker"))
	Util_Paradrop(player2, sg_defenders, SBP.CW.COMMANDOS_PARATROOPER_SP, spawnpos, 1)
	spawnpos = Util_GetPosition(Marker_FromName("marker"..World_GetRand(3,24), "cyan_marker"))
	Util_Paradrop(player2, sg_defenders, SBP.CW.COMMANDOS_PARATROOPER_SP, spawnpos, 1)
	spawnpos = Util_GetPosition(Marker_FromName("marker"..World_GetRand(3,24), "cyan_marker"))
	Util_Paradrop(player2, sg_defenders, SBP.CW.COMMANDOS_PARATROOPER_SP, spawnpos, 1)

end

function BasicInf()
	local spawnpos = marker1
	local targetpos = marker2
		
	spawnpos = Util_GetPosition(Marker_FromName("marker"..World_GetRand(25,47), "red_marker"))

	local NumTanks = World_GetRand(0, 3)
	if NumTanks == 0 then
	Util_CreateSquads(player3, sg_Attackers, Axis_Basicinf[World_GetRand(1, table.getn(Axis_Basicinf))], spawnpos, nil, 1) 
	Cmd_AttackMoveThenCapture(sg_Attackers, eg_HILL, 15)
	elseif NumTanks == 1 then
	Util_CreateSquads(player3, sg_Attackers, Axis_Basicinf[World_GetRand(1, table.getn(Axis_Basicinf))], spawnpos, nil, 1)
	Util_CreateSquads(player3, sg_Attackers, Axis_Basicinf[World_GetRand(1, table.getn(Axis_Basicinf))], spawnpos, nil, 1) 
	Cmd_AttackMoveThenCapture(sg_Attackers, eg_HILL, 15)
	elseif NumTanks == 2 then
	Util_CreateSquads(player3, sg_Attackers, Axis_Basicinf[World_GetRand(1, table.getn(Axis_Basicinf))], spawnpos, nil, 1)
	Util_CreateSquads(player3, sg_Attackers, Axis_Basicinf[World_GetRand(1, table.getn(Axis_Basicinf))], spawnpos, nil, 1) 
	Util_CreateSquads(player3, sg_Attackers, Axis_Basicinf[World_GetRand(1, table.getn(Axis_Basicinf))], spawnpos, nil, 1) 
	Cmd_AttackMoveThenCapture(sg_Attackers, eg_HILL, 15)
	elseif NumTanks == 3 then
	Util_CreateSquads(player3, sg_Attackers, Axis_Basicinf[World_GetRand(1, table.getn(Axis_Basicinf))], spawnpos, nil, 1)
	Util_CreateSquads(player3, sg_Attackers, Axis_Basicinf[World_GetRand(1, table.getn(Axis_Basicinf))], spawnpos, nil, 1) 
	Util_CreateSquads(player3, sg_Attackers, Axis_Basicinf[World_GetRand(1, table.getn(Axis_Basicinf))], spawnpos, nil, 1)
	Util_CreateSquads(player3, sg_Attackers, Axis_Basicinf[World_GetRand(1, table.getn(Axis_Basicinf))], spawnpos, nil, 1) 
	Cmd_AttackMoveThenCapture(sg_Attackers, eg_HILL, 15)	
	end	
		
	spawnpos = Util_GetPosition(Marker_FromName("marker"..World_GetRand(25,47), "red_marker"))

	local NumTanks = World_GetRand(0, 3)
	if NumTanks == 0 then
	Util_CreateSquads(player4, sg_Attackers, PE_Basicinf[World_GetRand(1, table.getn(PE_Basicinf))], spawnpos, nil, 1) 
	Cmd_AttackMoveThenCapture(sg_Attackers, eg_HILL, 15)
	elseif NumTanks == 1 then
	Util_CreateSquads(player4, sg_Attackers, PE_Basicinf[World_GetRand(1, table.getn(PE_Basicinf))], spawnpos, nil, 1)
	Util_CreateSquads(player4, sg_Attackers, PE_Basicinf[World_GetRand(1, table.getn(PE_Basicinf))], spawnpos, nil, 1) 
	Cmd_AttackMoveThenCapture(sg_Attackers, eg_HILL, 15)
	elseif NumTanks == 2 then
	Util_CreateSquads(player4, sg_Attackers, PE_Basicinf[World_GetRand(1, table.getn(PE_Basicinf))], spawnpos, nil, 1)
	Util_CreateSquads(player4, sg_Attackers, PE_Basicinf[World_GetRand(1, table.getn(PE_Basicinf))], spawnpos, nil, 1) 
	Util_CreateSquads(player4, sg_Attackers, PE_Basicinf[World_GetRand(1, table.getn(PE_Basicinf))], spawnpos, nil, 1) 
	Cmd_AttackMoveThenCapture(sg_Attackers, eg_HILL, 15)
	elseif NumTanks == 3 then
	Util_CreateSquads(player4, sg_Attackers, PE_Basicinf[World_GetRand(1, table.getn(PE_Basicinf))], spawnpos, nil, 1)
	Util_CreateSquads(player4, sg_Attackers, PE_Basicinf[World_GetRand(1, table.getn(PE_Basicinf))], spawnpos, nil, 1) 
	Util_CreateSquads(player4, sg_Attackers, PE_Basicinf[World_GetRand(1, table.getn(PE_Basicinf))], spawnpos, nil, 1)
	Util_CreateSquads(player4, sg_Attackers, PE_Basicinf[World_GetRand(1, table.getn(PE_Basicinf))], spawnpos, nil, 1) 
	Cmd_AttackMoveThenCapture(sg_Attackers, eg_HILL, 15)	
	end

	spawnpos = marker1

	Util_CreateSquads(player3, sg_BridgeAssult, Axis_Basicinf[World_GetRand(1, table.getn(Axis_Basicinf))], spawnpos, nil, 1) 
	Util_CreateSquads(player4, sg_BridgeAssult, PE_Basicinf[World_GetRand(1, table.getn(PE_Basicinf))], spawnpos, nil, 1) 
	Cmd_AttackMoveThenCapture(sg_BridgeAssult, eg_Bridge, 15)
end

function support_inf()
	local spawnpos = marker1
	local targetpos = marker2
		
	spawnpos = Util_GetPosition(Marker_FromName("marker"..World_GetRand(25,47), "red_marker"))

	local NumTanks = World_GetRand(0, 2)
	if NumTanks == 0 then
	Util_CreateSquads(player3, sg_Attackers, Axis_Supportinf[World_GetRand(1, table.getn(Axis_Supportinf))], spawnpos, nil, 1) 
	Cmd_AttackMoveThenCapture(sg_Attackers, eg_HILL, 15)
	elseif NumTanks == 1 then
	Util_CreateSquads(player3, sg_Attackers, Axis_Supportinf[World_GetRand(1, table.getn(Axis_Supportinf))], spawnpos, nil, 1)
	Util_CreateSquads(player3, sg_Attackers, Axis_Supportinf[World_GetRand(1, table.getn(Axis_Supportinf))], spawnpos, nil, 1) 
	Cmd_AttackMoveThenCapture(sg_Attackers, eg_HILL, 15)
	elseif NumTanks == 2 then
	Util_CreateSquads(player3, sg_Attackers, Axis_Supportinf[World_GetRand(1, table.getn(Axis_Supportinf))], spawnpos, nil, 1)
	Util_CreateSquads(player3, sg_Attackers, Axis_Supportinf[World_GetRand(1, table.getn(Axis_Supportinf))], spawnpos, nil, 1) 
	Util_CreateSquads(player3, sg_Attackers, Axis_Supportinf[World_GetRand(1, table.getn(Axis_Supportinf))], spawnpos, nil, 1) 
	Cmd_AttackMoveThenCapture(sg_Attackers, eg_HILL, 15)	
	end	
		
	spawnpos = Util_GetPosition(Marker_FromName("marker"..World_GetRand(25,47), "red_marker"))

	local NumTanks = World_GetRand(0, 2)
	if NumTanks == 0 then
	Util_CreateSquads(player4, sg_Attackers, PE_Supportinf[World_GetRand(1, table.getn(PE_Supportinf))], spawnpos, nil, 1) 
	Cmd_AttackMoveThenCapture(sg_Attackers, eg_HILL, 15)
	elseif NumTanks == 1 then
	Util_CreateSquads(player4, sg_Attackers, PE_Supportinf[World_GetRand(1, table.getn(PE_Supportinf))], spawnpos, nil, 1)
	Util_CreateSquads(player4, sg_Attackers, PE_Supportinf[World_GetRand(1, table.getn(PE_Supportinf))], spawnpos, nil, 1) 
	Cmd_AttackMoveThenCapture(sg_Attackers, eg_HILL, 15)
	elseif NumTanks == 2 then
	Util_CreateSquads(player4, sg_Attackers, PE_Supportinf[World_GetRand(1, table.getn(PE_Supportinf))], spawnpos, nil, 1)
	Util_CreateSquads(player4, sg_Attackers, PE_Supportinf[World_GetRand(1, table.getn(PE_Supportinf))], spawnpos, nil, 1) 
	Util_CreateSquads(player4, sg_Attackers, PE_Supportinf[World_GetRand(1, table.getn(PE_Supportinf))], spawnpos, nil, 1) 
	Cmd_AttackMoveThenCapture(sg_Attackers, eg_HILL, 15)	
	end

	spawnpos = marker1

	Util_CreateSquads(player4, sg_BridgeAssult, PE_Supportinf[World_GetRand(1, table.getn(PE_Supportinf))], spawnpos, nil, 1) 
	Util_CreateSquads(player3, sg_BridgeAssult, Axis_Supportinf[World_GetRand(1, table.getn(Axis_Supportinf))], spawnpos, nil, 1) 
	Cmd_AttackMoveThenCapture(sg_BridgeAssult, eg_Bridge, 15)
	
end

function support_Vehicle()
	local spawnpos = marker1
	local targetpos = marker77
		
	spawnpos = Util_GetPosition(Marker_FromName("marker"..World_GetRand(25,47), "red_marker"))

	local NumTanks = World_GetRand(0, 2)
	if NumTanks == 0 then
	Util_CreateSquads(player3, sg_Axis, Axis_SupportVehicles[World_GetRand(1, table.getn(Axis_SupportVehicles))], spawnpos, nil, 1) 
	Cmd_AttackMove(sg_Axis, Util_GetPosition(targetpos), 15)
	elseif NumTanks == 1 then
	Util_CreateSquads(player3, sg_Axis, Axis_SupportVehicles[World_GetRand(1, table.getn(Axis_SupportVehicles))], spawnpos, nil, 1)
	Util_CreateSquads(player3, sg_Axis, Axis_SupportVehicles[World_GetRand(1, table.getn(Axis_SupportVehicles))], spawnpos, nil, 1) 
	Cmd_AttackMove(sg_Axis, Util_GetPosition(targetpos), 15)
	elseif NumTanks == 2 then
	Util_CreateSquads(player3, sg_Axis, Axis_SupportVehicles[World_GetRand(1, table.getn(Axis_SupportVehicles))], spawnpos, nil, 1)
	Util_CreateSquads(player3, sg_Axis, Axis_SupportVehicles[World_GetRand(1, table.getn(Axis_SupportVehicles))], spawnpos, nil, 1) 
	Util_CreateSquads(player3, sg_Axis, Axis_SupportVehicles[World_GetRand(1, table.getn(Axis_SupportVehicles))], spawnpos, nil, 1) 
	Cmd_AttackMove(sg_Axis, Util_GetPosition(targetpos), 15)	
	end	
		
	spawnpos = Util_GetPosition(Marker_FromName("marker"..World_GetRand(25,47), "red_marker"))

	local NumTanks = World_GetRand(0, 2)
	if NumTanks == 0 then
	Util_CreateSquads(player4, sg_Axis, PE_SupportVehicles[World_GetRand(1, table.getn(PE_SupportVehicles))], spawnpos, nil, 1) 
	Cmd_AttackMove(sg_Axis, Util_GetPosition(targetpos), 15)
	elseif NumTanks == 1 then
	Util_CreateSquads(player4, sg_Axis, PE_SupportVehicles[World_GetRand(1, table.getn(PE_SupportVehicles))], spawnpos, nil, 1)
	Util_CreateSquads(player4, sg_Axis, PE_SupportVehicles[World_GetRand(1, table.getn(PE_SupportVehicles))], spawnpos, nil, 1) 
	Cmd_AttackMove(sg_Axis, Util_GetPosition(targetpos), 15)
	elseif NumTanks == 2 then
	Util_CreateSquads(player4, sg_Axis, PE_SupportVehicles[World_GetRand(1, table.getn(PE_SupportVehicles))], spawnpos, nil, 1)
	Util_CreateSquads(player4, sg_Axis, PE_SupportVehicles[World_GetRand(1, table.getn(PE_SupportVehicles))], spawnpos, nil, 1) 
	Util_CreateSquads(player4, sg_Axis, PE_SupportVehicles[World_GetRand(1, table.getn(PE_SupportVehicles))], spawnpos, nil, 1) 
	Cmd_AttackMove(sg_Axis, Util_GetPosition(targetpos), 15)	
	end
	
end


function TANKS()
	local spawnpos = marker1
	local targetpos = marker77
		
	spawnpos = Util_GetPosition(Marker_FromName("marker"..World_GetRand(25,47), "red_marker"))

	local NumTanks = World_GetRand(0, 2)
	if NumTanks == 0 then
	Util_CreateSquads(player3, sg_Axis, Axis_Armor[World_GetRand(1, table.getn(Axis_Armor))], spawnpos, nil, 1) 
	Cmd_AttackMove(sg_Axis, Util_GetPosition(targetpos), 15)
	elseif NumTanks == 1 then
	Util_CreateSquads(player3, sg_Axis, Axis_Armor[World_GetRand(1, table.getn(Axis_Armor))], spawnpos, nil, 1)
	Util_CreateSquads(player3, sg_Axis, Axis_Armor[World_GetRand(1, table.getn(Axis_Armor))], spawnpos, nil, 1) 
	Cmd_AttackMove(sg_Axis, Util_GetPosition(targetpos), 15)
	elseif NumTanks == 2 then
	Util_CreateSquads(player3, sg_Axis, Axis_Armor[World_GetRand(1, table.getn(Axis_Armor))], spawnpos, nil, 1)
	Util_CreateSquads(player3, sg_Axis, Axis_Armor[World_GetRand(1, table.getn(Axis_Armor))], spawnpos, nil, 1) 
	Cmd_AttackMove(sg_Axis, Util_GetPosition(targetpos), 15)	
	end	
		
	spawnpos = Util_GetPosition(Marker_FromName("marker"..World_GetRand(25,47), "red_marker"))

	local NumTanks = World_GetRand(0, 2)
	if NumTanks == 0 then
	Util_CreateSquads(player4, sg_Axis, PE_Armor[World_GetRand(1, table.getn(PE_Armor))], spawnpos, nil, 1) 
	Cmd_AttackMove(sg_Axis, Util_GetPosition(targetpos), 15)
	elseif NumTanks == 1 then
	Util_CreateSquads(player4, sg_Axis, PE_Armor[World_GetRand(1, table.getn(PE_Armor))], spawnpos, nil, 1)
	Util_CreateSquads(player4, sg_Axis, PE_Armor[World_GetRand(1, table.getn(PE_Armor))], spawnpos, nil, 1) 
	Cmd_AttackMove(sg_Axis, Util_GetPosition(targetpos), 15)	
	elseif NumTanks == 2 then
	Util_CreateSquads(player4, sg_Axis, PE_Armor[World_GetRand(1, table.getn(PE_Armor))], spawnpos, nil, 1)
	Util_CreateSquads(player4, sg_Axis, PE_Armor[World_GetRand(1, table.getn(PE_Armor))], spawnpos, nil, 1) 
	Cmd_AttackMove(sg_Axis, Util_GetPosition(targetpos), 15)
	end
	
end

function AlliedReinfOne()
	local spawnpos = marker48
	local targetpos = marker2
	
	Util_CreateSquads(player1, sg_defenders, American_Support[World_GetRand(1, table.getn(American_Support))], spawnpos, nil, 1)
	Util_CreateSquads(player1, sg_defenders, American_Support[World_GetRand(1, table.getn(American_Support))], spawnpos, nil, 1) 
	Util_CreateSquads(player1, sg_defenders, American_Support[World_GetRand(1, table.getn(American_Support))], spawnpos, nil, 1)
	Util_CreateSquads(player1, sg_defenders, SBP.ALLIES.RANGER_SP_BAZOOKA, spawnpos, nil, 1) 
	Util_CreateSquads(player1, sg_defenders, SBP.ALLIES.RANGER_SP_BAZOOKA, spawnpos, nil, 1) 
--	Cmd_AttackMoveThenCapture(sg_defenders, eg_HILL, 15)		
		
	
	Util_CreateSquads(player2, sg_defenders, British_Support[World_GetRand(1, table.getn(British_Support))], spawnpos, nil, 1)
	Util_CreateSquads(player2, sg_defenders, British_Support[World_GetRand(1, table.getn(British_Support))], spawnpos, nil, 1) 
	Util_CreateSquads(player2, sg_defenders, British_Support[World_GetRand(1, table.getn(British_Support))], spawnpos, nil, 1)
	Util_CreateSquads(player2, sg_defenders, SBP.CW.COMMANDOS_PIAT, spawnpos, nil, 1) 
	Util_CreateSquads(player2, sg_defenders, SBP.CW.COMMANDOS_PIAT, spawnpos, nil, 1) 
--	Cmd_AttackMoveThenCapture(sg_defenders, eg_HILL, 15)	
	
end

function AlliedReinfTwo()
	local spawnpos = marker49
	local targetpos = marker2
	
	Util_CreateSquads(player1, sg_defenders, American_Support[World_GetRand(1, table.getn(American_Support))], spawnpos, nil, 1)
	Util_CreateSquads(player1, sg_defenders, American_Support[World_GetRand(1, table.getn(American_Support))], spawnpos, nil, 1) 
	Util_CreateSquads(player1, sg_defenders, American_Armor[World_GetRand(1, table.getn(American_Armor))], spawnpos, nil, 1)
	Util_CreateSquads(player1, sg_defenders, American_Support[World_GetRand(1, table.getn(American_Support))], spawnpos, nil, 1) 
	Util_CreateSquads(player1, sg_defenders, SBP.ALLIES.RANGER_SP_BAZOOKA, spawnpos, nil, 1) 
--	Cmd_AttackMoveThenCapture(sg_defenders, eg_HILL, 15)		
		
	
	Util_CreateSquads(player2, sg_defenders, British_Support[World_GetRand(1, table.getn(British_Support))], spawnpos, nil, 1)
	Util_CreateSquads(player2, sg_defenders, British_Support[World_GetRand(1, table.getn(British_Support))], spawnpos, nil, 1) 
	Util_CreateSquads(player2, sg_defenders, British_Support[World_GetRand(1, table.getn(British_Support))], spawnpos, nil, 1)
	Util_CreateSquads(player2, sg_defenders, British_Armor[World_GetRand(1, table.getn(British_Armor))], spawnpos, nil, 1) 
	Util_CreateSquads(player2, sg_defenders, SBP.CW.COMMANDOS_PIAT, spawnpos, nil, 1) 
--	Cmd_AttackMoveThenCapture(sg_defenders, eg_HILL, 15)	
	
end

function AlliedReinfThree()
	local spawnpos = marker50
	local targetpos = marker2
	
	Util_CreateSquads(player1, sg_defenders, American_Armor[World_GetRand(1, table.getn(American_Armor))], spawnpos, nil, 1)
	Util_CreateSquads(player1, sg_defenders, American_Armor[World_GetRand(1, table.getn(American_Armor))], spawnpos, nil, 1) 
	Util_CreateSquads(player1, sg_defenders, American_Support[World_GetRand(1, table.getn(American_Support))], spawnpos, nil, 1)
	Util_CreateSquads(player1, sg_defenders, American_Support[World_GetRand(1, table.getn(American_Support))], spawnpos, nil, 1) 
	Util_CreateSquads(player1, sg_defenders, American_Support[World_GetRand(1, table.getn(American_Support))], spawnpos, nil, 1) 
--	Cmd_AttackMoveThenCapture(sg_defenders, eg_HILL, 15)		
		
	
	Util_CreateSquads(player2, sg_defenders, British_Support[World_GetRand(1, table.getn(British_Support))], spawnpos, nil, 1)
	Util_CreateSquads(player2, sg_defenders, British_Support[World_GetRand(1, table.getn(British_Support))], spawnpos, nil, 1) 
	Util_CreateSquads(player2, sg_defenders, British_Support[World_GetRand(1, table.getn(British_Support))], spawnpos, nil, 1)
	Util_CreateSquads(player2, sg_defenders, British_Armor[World_GetRand(1, table.getn(British_Armor))], spawnpos, nil, 1) 
	Util_CreateSquads(player2, sg_defenders, British_Armor[World_GetRand(1, table.getn(British_Armor))], spawnpos, nil, 1) 
--	Cmd_AttackMoveThenCapture(sg_defenders, eg_HILL, 15)	
	
end

function AlliedReinfFour()
	local spawnpos = marker51
	local targetpos = marker2
	
	Util_CreateSquads(player1, sg_defenders, American_Armor[World_GetRand(1, table.getn(American_Armor))], spawnpos, nil, 1)
	Util_CreateSquads(player1, sg_defenders, American_Armor[World_GetRand(1, table.getn(American_Armor))], spawnpos, nil, 1) 
	Util_CreateSquads(player1, sg_defenders, American_Armor[World_GetRand(1, table.getn(American_Armor))], spawnpos, nil, 1)
	Util_CreateSquads(player1, sg_defenders, American_Support[World_GetRand(1, table.getn(American_Support))], spawnpos, nil, 1) 
	Util_CreateSquads(player1, sg_defenders, American_Support[World_GetRand(1, table.getn(American_Support))], spawnpos, nil, 1) 
	Util_CreateSquads(player1, sg_defenders, SBP.ALLIES.PERSHING, spawnpos, nil, 1)
	Util_CreateSquads(player1, sg_defenders, SBP.ALLIES.PERSHING, spawnpos, nil, 1) 
--	Cmd_AttackMoveThenCapture(sg_defenders, eg_HILL, 15)		
		
	
	Util_CreateSquads(player2, sg_defenders, British_Support[World_GetRand(1, table.getn(British_Support))], spawnpos, nil, 1)
	Util_CreateSquads(player2, sg_defenders, British_Support[World_GetRand(1, table.getn(British_Support))], spawnpos, nil, 1) 
	Util_CreateSquads(player2, sg_defenders, British_Armor[World_GetRand(1, table.getn(British_Armor))], spawnpos, nil, 1)
	Util_CreateSquads(player2, sg_defenders, British_Armor[World_GetRand(1, table.getn(British_Armor))], spawnpos, nil, 1) 
	Util_CreateSquads(player2, sg_defenders, British_Armor[World_GetRand(1, table.getn(British_Armor))], spawnpos, nil, 1) 
	Util_CreateSquads(player2, sg_defenders, SBP.CW.CHURCHILL_CROC, spawnpos, nil, 1)
	Util_CreateSquads(player2, sg_defenders, SBP.CW.CHURCHILL_AVRE, spawnpos, nil, 1) 
--	Cmd_AttackMoveThenCapture(sg_defenders, eg_HILL, 15)	
	
end
function Finalassult()
	local spawnpos = marker1
	local targetpos = marker77
		
	spawnpos = Util_GetPosition(Marker_FromName("marker"..World_GetRand(25,47), "red_marker"))
	
	Util_CreateSquads(player3, sg_Axis, Axis_KT[World_GetRand(1, table.getn(Axis_KT))], spawnpos, nil, 1) 
	Cmd_AttackMove(sg_Axis, Util_GetPosition(targetpos), 15)
		
	spawnpos = Util_GetPosition(Marker_FromName("marker"..World_GetRand(25,47), "red_marker"))

	Util_CreateSquads(player4, sg_Axis, PE_JP[World_GetRand(1, table.getn(PE_JP))], spawnpos, nil, 1)
	Util_CreateSquads(player4, sg_Axis, PE_JP[World_GetRand(1, table.getn(PE_JP))], spawnpos, nil, 1) 
	Cmd_AttackMove(sg_Axis, Util_GetPosition(targetpos), 15)

	Util_GlobalMessage(LOCSTRINGS.KT, 3)

end




function Game_OverLose()
	local pointless = 5

	Timer_DisplayOnScreen("Timer")
	if EGroup_IsCapturedByPlayer(eg_HILL, player3, ANY) or EGroup_IsCapturedByPlayer(eg_HILL, player4, ANY) then
	if Gamestyle == 2 then
		Game_EndSP(true, nil, true)
	else
		Game_EndSP(false, nil, true)
	end
	end


	if Player_OwnsSGroup(player1, sg_defenders, ANY) then
		pointless = 2
	elseif Player_OwnsSGroup(player2, sg_defenders, ANY) then
		pointless = 2
	elseif Gamestyle == 2 then
		Game_EndSP(true, nil, true)
	else
		Game_EndSP(false, nil, true)
	end 
	
end

function Game_OverWin()
	if Gamestyle == 1 then
		Game_EndSP(true, nil, true)
	else
		Game_EndSP(false, nil, true)
	end
end















function Util_CreateLocString(text)
	local tmpstr = LOC(text)
	tmpstr[1] = text
	return tmpstr
end

function Util_GlobalMessage(title, displaytime)
	local _ShowMsg = function()
		CTRL.Game_TextTitleFade(title, 0, displaytime, 2, "")
		CTRL.WAIT()
	end

	Util_StartIntel(_ShowMsg)
end
