Mission event file for Order mission 4
Gidsen
/
Mission event file for Order mission 4
Geüpdatet 4 years ago door Merric

--[[ IMPORTS ]]

import("ScarUtil.scar") import("WXPScarUtil.scar")


--[[ GAME SETUP ]]

--[[ the OnGameSetup() function is mandatory! ]] function OnGameSetup()

g_Player1 = Setup_Player(0, "$690080", "guard_race", 1)
Player_DoNotPrecache(g_Player1, _t_MSO4_Player1)

g_Player2 = Setup_Player(1, "$690083", "eldar_race", 1)
Misc_PlayerTeamColor(g_Player2,"default_5")
Player_DoNotPrecache(g_Player2, _t_MSO4_Player2)

g_Player3 = Setup_Player(2, "$690085", "space_marine_race", 1)
Misc_PlayerTeamColor(g_Player3,"default_1")
Player_DoNotPrecache(g_Player3, _t_MSO4_Player3)

g_Player4 = Setup_Player(3, "$690082", "guard_race", 1)
Player_DoNotPrecache(g_Player4, _t_MSO4_Player4)

g_Player5 = Setup_Player(4, "$690087", "ork_race", 3)
Misc_PlayerTeamColor(g_Player5,"default_4")
Player_DoNotPrecache(g_Player5, _t_MSO4_Player5)

g_Player6 = Setup_Player(5, "$690088", "chaos_marine_race", 3)
Misc_PlayerTeamColor(g_Player6,"default_6")
Player_DoNotPrecache(g_Player6, _t_MSO4_Player6)

g_Player7 = Setup_Player(6, "$690082", "guard_race", TEAM_NEUTRAL)
Player_DoNotPrecache(g_Player7, _t_MSO4_Player7)

g_Player8 = Setup_Player(7, "$690088", "chaos_marine_race", 3)
Misc_PlayerTeamColor(g_Player8,"default_6")
Player_DoNotPrecache(g_Player8, _t_MSO4_Player8)

--[[ DEFINE VARIABLES AND TABLES - define any preset values here for later use]]
g_firstrun = true
--[[ define the "enemy" who will win if the player 'loses' ]]
g_enemy = g_Player6
g_time = 0
g_reinforceblackout = 0
g_gencountdown = 0
t_chaostargets = { 14, 13, 15, 12, 9, 8, 10, 11 }
t_orktargets = { 1, 2, 3, 4, 5, 7, 6 }

--[[ tuneables ]]
g_landraider_speed = .2 -- default 0.2
g_reinforceblackout_delay = 6
g_callconvoydist = 80

--[[ guard ]]
g_guarddif1 = 1 -- number of iterations of Bunker defense
g_guarddif2 = 1 -- chaos skirmish side
g_guarddif3 = 2 -- ork skirmish side


--[[disorder ]]
g_horrornum = 1

g_chaos_baseattack_dif = 1
g_chaos_baseattack_squaddif = 1

g_ork_baseattack_dif = 1
g_ork_baseattack_squaddif = 1

g_orkwebway_dif = 1

end

--[[ the OnGameRestore() function is mandatory!, this will only get called after loading a game ]] function OnGameRestore()

--[[ nothing at the moment ]]

end

--[[ the OnLoad() function acts like the OnInit() but for saved games only ]] function OnLoad()

if g_gatesopen then
	Anim_PlayEGroupAnim(EGroup_FromName("eg_gatefinal"), "die")
end

end

Scar_AddLoad(OnLoad)


--[[ ON INITIALIZATION ]]

function OnInit()

--[[ RESEARCH LEVEL ]]
-- sets the research level of the mission, locks researches, squads, and buildings
Rule_SetResearchLevel( 4 )

--[[ NIS PRESETS ]]
-- turn off event cues, set the viewable space to black (faded out) and preset letterboxing 
WXP_OpeningNISPreset()

--[[ START THE MUSIC ]]
-- call the function to load the jukebox with tunes
Rule_SetupMusicPlaylist()

--[[ SET AI ]]
-- call the function to set the pregame state of the AI 
Rule_PresetAI()		

--[[ START NIS ]]
-- calls the NIS function located in the MissionName.nis file 
g_sg_disorderID = SGroup_CreateIfNotFound("sg_disorder")
Util_StartNIS( EVENTS.NIS_Opening ) 	

--[[ GET THE START PLAY MISSION READY TO ROLL ]]
Rule_Add( Rule_GameStart )	

end

--[[ the Scar_AddInit(OnInit) function is mandatory! This registers your init function with scar. ]] Scar_AddInit(OnInit)


--[[ GAME RESTRICTIONS ]]

--[[ Disables, enables, and grants research items ]] function Rule_SetResearchLevel( resLevel )

--[[ Player 1 - Guard ]]
local table1 = {
	"guard_hq", 
	"guard_infantry", 
	"guard_mars_pattern", 
	"guard_mechanized", 
	"guard_tactica", 
	"guard_turret_heavy_bolter", 
}
Player_RestrictBuildingList(g_Player1, table1)
Player_RestrictSquad(g_Player1, "guard_squad_command_squad")

Player_SetSquadCap(g_Player1, 16)
Player_SetSupportCap(g_Player1, 12)

--[[ Player 2 - Eldar ]]
Player_RestrictSquad(g_Player2, "eldar_squad_avatar")
Player_RestrictSquad(g_Player2, "eldar_squad_farseer")
Player_RestrictBuilding(g_Player2, "eldar_hq")

--[[ WXP Specific ]]
WXP_Restrict( resLevel )

g_zone1ID = W40k_NoBuildZonePosition( Util_ScarPos(-16, 211), Util_ScarPos(5, 254) )
g_zone2ID = W40k_NoBuildZonePosition( Util_ScarPos(-16, 198), Util_ScarPos(-2, 210) )
g_zone3ID = W40k_NoBuildZonePosition( Util_ScarPos(-12, 188), Util_ScarPos(0, 195) )

end


--[[ MUSIC ]]

function Rule_SetupMusicPlaylist()

t_ambient = {"Rain_thunder_amb"  }
Playlist_Manager( PC_Ambient, t_ambient, true , true , {5, 10})

end


--[[ PRESET AI ]]

function Rule_PresetAI()

Cpu_EnableAll(false)	

end


--[[ START PLAY ]]

--[[ NOW TO KICK OFF THE ACTUAL MISSION ONCE THE OPENING NIS IS DONE ]]

function Rule_GameStart()

if g_firstrun then
	
	--[[ share fow ]]
	
	--[[ SET RESOURCES ]]
	Player_SetAllResources(g_Player1, 5000, 1000)
	Player_SetAllResources(g_Player2, 20000, 5000)
	
	--[[ PREACTION ]]
	-- Use this space to add core mission functions that should be in place during the opening NIS
	Rule_AddOneShot(Rule_TitanCrew_KickOff, 0)
	Rule_AddOneShot(Rule_Guard_KickOff, 0)
	Rule_AddOneShot(Rule_WorldTriggers_Kickoff, 0)
	Rule_AddOneShot(Rule_Eldar_Kickoff, 0)
	
	Rule_AddOneShot(Rule_Disorder_Kickoff, 0)
	Rule_AddOneShot(Rule_IG_Kickoff, 0)
	
	--[[ DIFFICULTY LEVEL ]]
	-- gets the difficulty level from the UI and passes it into the function
	Rule_SetDifficultyLevel( Difficulty_Get() )
	
	g_firstrun = false
	
elseif Event_IsAnyRunning() == false then		
	Rule_AddInterval(Rule_Timer, 1)
	
	--[[ Get the AI doing whatever after the NIS is over ]]
	Rule_StartAI()
	
	--[[ FOW ]]
	World_EnablePlayerToPlayerFOW(g_Player2, g_Player1, false)
	World_EnablePlayerToPlayerFOW(g_Player2, g_Player3, false)
	World_EnablePlayerToPlayerFOW(g_Player1, g_Player3, false)
	World_EnablePlayerToPlayerFOW(g_Player1, g_Player4, true)
	World_EnablePlayerToPlayerFOW(g_Player2, g_Player4, true)
	
	--[[ WIN CHECK ]]
	Rule_AddInterval(Rule_EndGameWin, 1)
	
	--[[ LOSE CHECK ]]
	Rule_AddInterval(Rule_EndGameLose, 1)
	Rule_AddInterval(Rule_EndGameLose_Guard, 1)
	Rule_AddInterval(Rule_EndGameLose_Eldar, 1)
	
	--[[ ASSIGN OBJECTIVES ]]
	Rule_AddInterval(Rule_Objective_SwitchSides, 1)
	Rule_AddIntervalDelay(Rule_Objective_TitanCrew, 1, 2)
	Rule_AddIntervalDelay(Rule_Guard_ConvoyNeedsToMove, 1, 10)
	
	--[[ AUTOSAVE AFTER NIS ]]
	Rule_AddOneShot(Rule_ScarButton_Create, 2)
	Rule_AddIntervalDelay(Rule_Autosave_MissionStart, 1, 3)
	
	--[[ GENERATE ACTION ]]
	-- Use this space to add all core mission functions
	
	--[[ Clean up ]]
	Rule_Remove(Rule_GameStart)
	
end

end


--[[ DIFFICULTY ]]

function Rule_SetDifficultyLevel( difficultyLevel )

--[[ STATIC MODIFIERS ]]
-- Use this space to set any Static Modifiers. Modifiers that will not change with the difficulty setting.

Difficulty_SetForPlayer( g_Player8, difficultyLevel )
Difficulty_SetForPlayer( g_Player5, difficultyLevel )
Difficulty_SetForPlayer( g_Player6, difficultyLevel )

--[[ DIFFICULTY GENERAL RULES ]]
--[[ Types of things that can me done	include: 
a) adding resource values
b) changing variables for the number of starting units a player recieves 
b) or even activating new objectives (although we refrained from this in DoW as the increased testing requirements it dictates)
]]	
-- easy
if difficultyLevel == DIFFICULTY_EASY then
	
	--Cpu_SetDifficulty( g_Player2, AD_Standard )
	
-- medium
elseif difficultyLevel == DIFFICULTY_NORMAL then
	
-- hard
elseif difficultyLevel == DIFFICULTY_HARD then
	
end

--[[ toughen up Guard Barracks 
local mod_barrackarmour = Modifier_Create(MAT_EntityType, "armour_modifier", MUT_Multiplication, false, 1.2, "guard_infantry")
Modifier_ApplyToPlayer( mod_barrackarmour, g_Player4)]]
local mod_barrackhealth = Modifier_Create(MAT_EntityType, "health_maximum_modifier", MUT_Multiplication, false, 2, "guard_infantry")
Modifier_ApplyToPlayer( mod_barrackhealth, g_Player4)

local mod_turretarmour = Modifier_Create(MAT_EntityType, "armour_modifier", MUT_Multiplication, false, 1.2, "guard_turret_heavy_bolter")
Modifier_ApplyToPlayer( mod_turretarmour, g_Player4)
local mod_turrethealth = Modifier_Create(MAT_EntityType, "health_maximum_modifier", MUT_Multiplication, false, 2, "guard_turret_heavy_bolter")
Modifier_ApplyToPlayer( mod_turrethealth, g_Player4)

--[[ marines ]]
local mod_tacarmour = Modifier_Create(MAT_EntityType, "armour_modifier", MUT_Multiplication, false, 1, "space_marine_tactical_bolter")
Modifier_ApplyToPlayer( mod_tacarmour, g_Player3)
local mod_tachealth = Modifier_Create(MAT_EntityType, "health_maximum_modifier", MUT_Multiplication, false, 1.2, "space_marine_tactical_bolter")
Modifier_ApplyToPlayer( mod_tachealth, g_Player3)

local mod_chaparmour = Modifier_Create(MAT_EntityType, "armour_modifier", MUT_Multiplication, false, 1, "chaplain")
Modifier_ApplyToPlayer( mod_chaparmour, g_Player3)
local mod_chaphealth = Modifier_Create(MAT_EntityType, "health_maximum_modifier", MUT_Multiplication, false, 2, "chaplain")
Modifier_ApplyToPlayer( mod_chaphealth, g_Player3)

local mod_termarmour = Modifier_Create(MAT_EntityType, "armour_modifier", MUT_Multiplication, false, 1, "terminator_assault")
Modifier_ApplyToPlayer( mod_termarmour, g_Player3)
local mod_termhealth = Modifier_Create(MAT_EntityType, "health_maximum_modifier", MUT_Multiplication, false, 2, "terminator_assault")
Modifier_ApplyToPlayer( mod_termhealth, g_Player3)

local mod_termassarmour = Modifier_Create(MAT_EntityType, "armour_modifier", MUT_Multiplication, false, 1, "terminator")
Modifier_ApplyToPlayer( mod_termassarmour, g_Player3)
local mod_termasshealth = Modifier_Create(MAT_EntityType, "health_maximum_modifier", MUT_Multiplication, false, 2, "terminator")
Modifier_ApplyToPlayer( mod_termasshealth, g_Player3)

--[[ player guard ]]
local mod_genhealth = Modifier_Create(MAT_EntityType, "health_maximum_modifier", MUT_Multiplication, false, 4, "guard_leaders_captain")
Modifier_ApplyToPlayer( mod_genhealth, g_Player1)

--[[ player eldar ]]
local mod_farhealth = Modifier_Create(MAT_EntityType, "health_maximum_modifier", MUT_Multiplication, false, 4, "eldar_farseer")
Modifier_ApplyToPlayer( mod_farhealth, g_Player2)

end


--[[ AI ]]

function Rule_StartAI()

-- Cpu_EnableAll(false)

end


--[[ CORE GAME ]]

function Rule_Timer() g_time = g_time+1 end

function Rule_FOW_Reset() FOW_Reset() end

--[[ SWITCH BUTTON ]]

function Rule_ScarButton_Create()

--[[ CREATE THE SWITCH BUTTON ]]
g_btnID = Button_Add("btn_ScarUI", true, true, false)

Button_SetTextures(g_btnID, "Scar_buttons/switchto_Eldar", "Scar_buttons/switchto_Eldar", "Scar_buttons/switchto_Eldar")
Button_SetTooltip(g_btnID, "$830050", "$830051")

g_enable = 1
g_visible = 1
g_playerSwitch = "g_Player1" 

Rule_AddInterval(Rule_SwitchControl, 1)

end

function Rule_SGroupAbilityButton_ManageVisible() --[[ CREATE THE REINFORCING BUTTONs ]] -- Guardsmen local textable = {"Scar_buttons/order_guardsmen", "Scar_buttons/order_guardsmen", "Scar_buttons/order_guardsmen"} local tiptable = { "$830054", "$830055"} g_infbtnID = Util_AbilityButton_Create(textable, tiptable, true)

-- Sentinel
local textable = {"Scar_buttons/order_sentinel", "Scar_buttons/order_sentinel", "Scar_buttons/order_sentinel"}
local tiptable = { "$830056", "$830057"}	
g_sentbtnID = Util_AbilityButton_Create(textable, tiptable, true)

-- Tech Priest
local textable = {"Scar_buttons/order_techpriest", "Scar_buttons/order_techpriest", "Scar_buttons/order_techpriest"}
local tiptable = { "$830058", "$830059"}	
g_engbtnID = Util_AbilityButton_Create(textable, tiptable, true)

t_reinforce = {
	buttons = {g_infbtnID, g_sentbtnID, g_engbtnID},
	name = {"escort1", "escort7", "builder1"},
	blue = {"guard_squad_guardsmen", "guard_squad_sentinel", "guard_squad_enginseer"},
}

Util_SGroupAbilityButton_Add2Manager(g_conbtnID, "sg_guardleader")
Util_SGroupAbilityButton_Add2Manager(g_infbtnID, "sg_guarddropship")
Util_SGroupAbilityButton_Add2Manager(g_sentbtnID, "sg_guarddropship")
Util_SGroupAbilityButton_Add2Manager(g_engbtnID, "sg_guarddropship")

end

function Rule_SwitchControl()

if Button_GetPressed(g_btnID) then
	if g_playerSwitch ~= "g_Player1" then
		g_obj_switchsides = true
		
		--[[ THE SWITCH ]]
		Util_StartNIS(EVENTS.NIS_SwitchGuard)
		
		Button_SetTextures(g_btnID, "Scar_buttons/switchto_Eldar", "Scar_buttons/switchto_Eldar", "Scar_buttons/switchto_Eldar")
		
	elseif g_playerSwitch ~= "g_Player2" then
		g_obj_switchsides = true
		
		--[[ THE SWITCH ]]
		Util_StartNIS(EVENTS.NIS_SwitchEldar)
		
		Button_SetTextures(g_btnID, "Scar_buttons/switchto_IG", "Scar_buttons/switchto_IG", "Scar_buttons/switchto_IG")
		
	end
end

if g_eldardead and g_guarddead ~= true then
	if g_playerSwitch ~= "g_Player1" then
		
		g_obj_switchsides = true
		--[[ THE SWITCH ]]
		Util_StartNIS(EVENTS.NIS_SwitchGuard)
		
	end
	Button_Remove(g_btnID)
	
	Rule_AddIntervalDelay(Rule_Autosave_EldarEliminated, 1, 3)
	
	Rule_Remove(Rule_SwitchControl)
	
elseif g_guarddead and g_eldardead ~= true then
	if g_playerSwitch ~= "g_Player2" then
		
		g_obj_switchsides = true
		--[[ THE SWITCH ]]
		Util_StartNIS(EVENTS.NIS_SwitchEldar)
		
	end
	Button_Remove(g_btnID)
	
	Rule_AddIntervalDelay(Rule_Autosave_GuardEliminated, 1, 3)
	
	Rule_Remove(Rule_SwitchControl)
	
end	

end

--[[ SWITCH MARKER FUNCTIONS ]]

--[[ The point of the following set of special, mission specific, util functions is to allow only the active player slot's Pings and Beacons to be visible at any point during play.

Since the player has the ability to switch back and forth on their own and Pings and Beacons are often created throughout the whole mission it became very confusing for them ALL to be visible at the same time.

This set of Add, Switch, and Remove functions is aimed at resolving this issue -deg ]]

--[[ MARKER ADD FUNCTION ]] function MSO4_SwitchPings_Add(playerid, beacon, ping, location)

if _switch == nil then
	_switch = {}
end

local count = table.getn(_switch)
local i = count+1
local pos = {x = 0, y = 0, z = 0}
if type(location) == "string" and Marker_Exists(location, "basic_marker") then
	pos = Marker_GetPosition(Marker_FromName(location, "basic_marker"))
else
	pos = location
end

local player = 0
if playerid == g_Player1 then
	player = "g_Player1"
elseif playerid == g_Player2 then
	player = "g_Player2"
end

local template = {id = player, loc = pos, be = beacon, beid = 0, ping = ping}
table.insert(_switch, i , template)

if _switch[i].be ~= nil then
	_switch[i].beid = Util_CreateBeaconPosition_Blue(_switch[i].loc)
end

if _switch[i].ping ~= nil then
	Util_Ping_LoopingPos(_switch[i].ping, _switch[i].loc)
end

end

--[[ MARKER SWITCH FUNCTION ]] function MSO4_SwitchPings_Switch(playerid)

local count = 0

if _switch ~= nil then
	count = table.getn(_switch)
end

local player = 0
if playerid == g_Player1 then
	player = "g_Player1"
elseif playerid == g_Player2 then
	player = "g_Player2"
end

if count > 0 then
	
	for i = 1, count do
		
		if _switch[i].id ~= player then
			
			if _switch[i].be ~= nil then
				Util_RemoveBeaconMarker(_switch[i].beid)
			end
			
			if _switch[i].ping ~= nil then
				Util_Ping_Stop(_switch[i].ping)
			end
			
		elseif _switch[i].id == player then
			
			if _switch[i].be ~= nil then
				_switch[i].beid = Util_CreateBeaconPosition_Blue(_switch[i].loc)
			end
			
			if _switch[i].ping ~= nil then
				Util_Ping_LoopingPos(_switch[i].ping, _switch[i].loc)
			end
			
		else
		end
		
	end
	
end

end

--[[ MARKER REMOVAL FUNCTIONS ]]

--[[ Remove Ping ]] function MSO4_SwitchPings_RemovePing(ping)

local count = table.getn(_switch)
if count > 0 then
	
	for i = count, 1, -1 do
		
		if _switch[i].ping == ping then
			
			Util_Ping_Stop(ping)
			table.remove(_switch, i)
			
			break
		end
		
	end
	
end

end

--[[ Remove Beacon ]] function MSO4_SwitchPings_RemoveBeacon(beacon)

local count = table.getn(_switch)
if count > 0 then
	
	for i = count, 1, -1 do
		
		if _switch[i].be == beacon then
			
			Util_RemoveBeaconMarker(_switch[i].beid)
			table.remove(_switch, i)
			
			break
		end
		
	end
	
end

end

--[[ Remove Beacon AND Ping ]] function MSO4_SwitchPings_RemoveBoth(beacon, ping)

local count = table.getn(_switch)
if count > 0 then
	
	for i = count, 1, -1 do
		
		if _switch[i].be == beacon then
			
			Util_RemoveBeaconMarker(_switch[i].beid)
			Util_Ping_Stop(ping)
			table.remove(_switch, i)
			
			break
		end
		
	end
	
end

end

--[[ GUARD - PLAYER ]]

-- the following is the creation of the Player's Guard Army function Rule_Guard_KickOff()

Rule_AddOneShot(Rule_Guard_Dropship_CreateButtons, 0)
g_deploytally = 0
g_gencountdown = 0
g_genrespawn = "mkr_guardstart"

Rule_AddOneShot(Rule_Guard_Create, 0)

--[[ create the outpost ]]
Entity_CreateBuildingMarker(g_Player8, "eg_guard_1stchaos_brrks", "chaos_temple", "mkr_firstchaosbase", 1)
	EGroup_AddGroup(EGroup_CreateIfNotFound("eg_guard_1stchaosbase"), EGroup_FromName("eg_guard_1stchaos_brrks"))
for i = 1, 4 do
	Entity_CreateBuildingMarker(g_Player8, "eg_guard_1stchaos_turret"..i, "chaos_turret_bolter", "mkr_firstchaos"..i, 1)
		EGroup_AddGroup(EGroup_CreateIfNotFound("eg_guard_1stchaos"), EGroup_FromName("eg_guard_1stchaos_turret"..i))
end

end

function Rule_Guard_Dropship_Replace()

Util_CreateSquadsAtMarkerEx(g_Player1, "sg_guarddropship", "npc_valkyrie", "mkr_guard_dropship1", 1, 1)
Anim_PlaySGroupAnim(SGroup_FromName("sg_guarddropship"), "sp_land")

Rule_AddOneShot(Rule_Guard_Dropship_Touchdown, 8)

end

function Rule_Guard_Dropship_Touchdown()

g_dropship_replacing = false
g_dropship_landed = true

end

--[[ INITIAL GUARD SUPPORT ]] -- giving the Guard a good foundation function Rule_Guard_Dropship_CreateButtons()

g_guard_1stbase = "g_Player3"

end

function Rule_Guard_Dropship_Support() t_reinforce = { buttons = {g_infbtnID, g_sentbtnID, g_engbtnID}, name = {"_squad", "_sentinel", "_builder"}, blue = {"guard_squad_guardsmen", "guard_squad_sentinel", "guard_squad_enginseer"}, }

--[[ EMERGENCY REMOVAL IN CASE OF DEATH ]]
if SGroup_IsEmpty("sg_guarddropship") and g_dropship_replacing ~= true then
	
	g_dropship_replacing = true
	Rule_AddOneShot(Rule_Guard_Dropship_Replace, 4)
	
elseif g_dropship_landed == true then
	
	--[[ MANAGING THE ENABLED/DISABLED ]]
	if g_playerSwitch == "g_Player1" then
		for i = 1, table.getn(t_reinforce.name) do
			if Button_GetEnabled(t_reinforce.buttons[i]) == false then
				Button_SetEnabled(t_reinforce.buttons[i], true)
			end
		end
	elseif g_playerSwitch == "g_Player2" then
		for i = 1, table.getn(t_reinforce.name) do
			if Button_GetEnabled(t_reinforce.buttons[i]) == true then
				Button_SetEnabled(t_reinforce.buttons[i], false)
			end
		end
	end
	
	--[[ PROPER USEAGE OF THE BUTTONS ]] 
	if g_guard_1stbase == "g_Player3" then
		
		for i = 1, table.getn(t_reinforce.name) do
			
			if SGroup_Exists("sg_guard"..t_reinforce.name[i]) and SGroup_Count(SGroup_FromName("sg_guard"..t_reinforce.name[i])) < 3 then
				if Button_GetEnabled(t_reinforce.buttons[i]) == false then
					Button_SetEnabled(t_reinforce.buttons[i], true)
				end
			elseif SGroup_Exists("sg_guard"..t_reinforce.name[i]) and SGroup_Count(SGroup_FromName("sg_guard"..t_reinforce.name[i])) >= 3 then
				if Button_GetEnabled(t_reinforce.buttons[i]) == true then
					Button_SetEnabled(t_reinforce.buttons[i], false)
				end
			end
			
			if g_playerSwitch == "g_Player1" and Button_GetPressed(t_reinforce.buttons[i]) and Button_GetEnabled(t_reinforce.buttons[i]) == true then
				
				local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player1, "sg_guard"..t_reinforce.name[i], t_reinforce.blue[i], "mkr_guardstart", 1, 8)
				SGroup_AddGroup(SGroup_CreateIfNotFound("sg_guard"), sgroupID)
				SGroup_AddGroup(SGroup_CreateIfNotFound("sg_guardescort"), sgroupID)
			end
			
		end
		
	--[[ REMOVE WHEN THE PLAYER EARNS OWN BASE ]]
	elseif EGroup_Exists("eg_guard_1stbase") and EGroup_IsEmpty("eg_guard_1stbase") == false and g_guard_1stbase == "g_Player1" then
		
		--[[ INTEL EVENT -- ok we're done with you now ]]
		g_handover = true 
		
		for i = 1, table.getn(t_reinforce.name) do
			Util_SGroupAbilityButton_Remove(t_reinforce.buttons[i])
			Button_Remove(t_reinforce.buttons[i])
		end
		
		Rule_AddOneShot(Rule_Guard_Dropship_Despawn, 8)
		
		if SGroup_Exists("sg_guarddropship") and SGroup_IsEmpty("sg_guarddropship") == false then
			Anim_PlaySGroupAnim(SGroup_FromName("sg_guarddropship"), "sp_take_off")
		end
		
		Rule_Remove(Rule_Guard_Dropship_Support)
		
	end
	
end	

end

function Rule_Guard_Dropship_Despawn()

if SGroup_Exists("sg_guarddropship") and SGroup_IsEmpty("sg_guarddropship") == false then
	SGroup_DeSpawn("sg_guarddropship")
	SGroup_DestroyAllSquads("sg_guarddropship")
end

end

--[[ GENERAL TRACKING ]] function Rule_Guard_GeneralReplace()

local blueprinttable = Util_MakeBlueprintTable("guard_squad_command_squad")

if g_gencountdown > 1 then
	g_gencountdown = g_gencountdown-1
elseif g_gencountdown == 1 then
	g_gencountdown = 0
	local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player1, "sg_guardleader", "guard_squad_command_squad", g_genrespawn, 1, 1)
	World_FXEventSquad("data:Art/Events/Unit_Upgrade_Morale_FX/Reinforce_Trooper", sgroupID)
	SGroup_AddGroup(SGroup_CreateIfNotFound("sg_guard"), sgroupID)
	SGroup_AddGroup(SGroup_CreateIfNotFound("sg_guardescort"), sgroupID)
	
	--[[ INTEL EVENT -- I am back ]]
	if Event_TimeSinceLast() > 10 then
		Util_StartIntel(EVENTS.IE_Guard_ImBack)
	end
	EventCue_DoEvent( "recruit_commander", "/Races/Shared/Upgrade_weapon", "$42890", "$42892" )
	
elseif SGroup_Exists("sg_guardleader") and (SGroup_IsEmpty("sg_guardleader") or SGroup_ContainsBlueprints( "sg_guardleader", blueprinttable, false) == false) and g_gencountdown == 0 then
	g_gencountdown = 6
	
	--[[ INTEL EVENT - I will return ]]
	
end

end

--[[ INITIAL GUARD CREATION ]] function Rule_Guard_Create()

Rule_AddInterval(Rule_Guard_CreateChaosOutpost, 5)
Rule_AddInterval(Rule_Guard_BreachChaosCreate, 4.5)
Rule_AddInterval(Rule_Guard_FirstBase, 5)
Rule_AddOneShot(Rule_Guard_CaptureableBases, 1)

--[[ CREATE THE "CALL CONVOY" BUTTON ]]
local textable = {"Scar_buttons/call_convoy", "Scar_buttons/call_convoy", "Scar_buttons/call_convoy"}
local tiptable = { "$830052", "$830053"}	
g_conbtnID = Util_AbilityButton_Create(textable, tiptable, false)

end

--[[ create the bases that the player can capture the player will not be allowed to build anything that may jeparodize their ability to get the convoy home so to add to their base the commander will seize bases from the AI but only special ones so as not to fuck up the AI ]] function Rule_Guard_CaptureableBases()

--[[ Create the Second base - just a barracks ]]
local table1 = {"guard_infantry"}
for i = 1, table.getn(table1) do
	Entity_CreateBuildingMarker(g_Player4, "eg_guard_2base"..i, table1[i], "mkr_guard_2base"..i, 1)
	EGroup_AddGroup(EGroup_CreateIfNotFound("eg_guard_2base"), EGroup_FromName("eg_guard_2base"..i))
end
	MSO4_SwitchPings_Add(g_Player1, "g_base2beaconID", nil, "mkr_guard_2base1")

--[[ Create the Third base - a barracks and another tactica ]]
local table2 = {"guard_infantry", "guard_tactica"}
for i = 1, table.getn(table2) do
	Entity_CreateBuildingMarker(g_Player4, "eg_guard_3base"..i, table2[i], "mkr_guard_3base"..i, 1)
	EGroup_AddGroup(EGroup_CreateIfNotFound("eg_guard_3base"), EGroup_FromName("eg_guard_3base"..i))
end
	MSO4_SwitchPings_Add(g_Player1, "g_base3beaconID", nil, "mkr_guard_3base1")

--[[ Create the Fourth base - a mechshop, a barracks and a generator ]]
local table3 = {"guard_mechanized", "guard_infantry", "guard_plasma_generator"}
for i = 1, table.getn(table3) do
	Entity_CreateBuildingMarker(g_Player4, "eg_guard_4base"..i, table3[i], "mkr_guard_4base"..i, 1)
	EGroup_AddGroup(EGroup_CreateIfNotFound("eg_guard_4base"), EGroup_FromName("eg_guard_4base"..i))
end
	MSO4_SwitchPings_Add(g_Player1, "g_base4beaconID", nil, "mkr_guard_4base1")

--[[ Create the Fifth base - just a mechshop ]]
local table4 = {"guard_mechanized"}
for i = 1, table.getn(table4) do
	Entity_CreateBuildingMarker(g_Player4, "eg_guard_5base"..i, table4[i], "mkr_guard_5base"..i, 1)
	EGroup_AddGroup(EGroup_CreateIfNotFound("eg_guard_5base"), EGroup_FromName("eg_guard_5base"..i))
end
	MSO4_SwitchPings_Add(g_Player1, "g_base5beaconID", nil, "mkr_guard_5base1")

--[[ Create the Second base - just a barracks ]]
local table5 = {"guard_mars_pattern"}
for i = 1, table.getn(table5) do
	Entity_CreateBuildingMarker(g_Player4, "eg_guard_6base"..i, table5[i], "mkr_guard_6base"..i, 1)
	EGroup_AddGroup(EGroup_CreateIfNotFound("eg_guard_6base"), EGroup_FromName("eg_guard_6base"..i))
end
	MSO4_SwitchPings_Add(g_Player1, "g_base6beaconID", nil, "mkr_guard_6base1")

local pos1 = Marker_GetPosition(Marker_FromName("mkr_guard_2base1", "basic_marker"))
local pos2 = Marker_GetPosition(Marker_FromName("mkr_guard_3base1", "basic_marker"))
local pos3 = Marker_GetPosition(Marker_FromName("mkr_guard_4base1", "basic_marker"))
local pos4 = Marker_GetPosition(Marker_FromName("mkr_guard_5base1", "basic_marker"))
local pos5 = Marker_GetPosition(Marker_FromName("mkr_guard_6base1", "basic_marker"))
t_base = {
	{name = "eg_guard_2base", pos = pos1, intel = EVENTS.IE_Sturnn_TakingCommandStructure, beacon = "g_base2beaconID"},
	{name = "eg_guard_3base", pos = pos2, intel = EVENTS.IE_Sturnn_TakingCommandStructure, beacon = "g_base3beaconID"},
	{name = "eg_guard_4base", pos = pos3, intel = EVENTS.IE_Sturnn_TakingCommandStructure, beacon = "g_base4beaconID"},
	{name = "eg_guard_5base", pos = pos4, intel = EVENTS.IE_Sturnn_TakingCommandStructure, beacon = "g_base5beaconID"},
	{name = "eg_guard_6base", pos = pos5, intel = EVENTS.IE_Sturnn_TakingCommandStructure, beacon = "g_base6beaconID"},
}
g_basesrecovered = 0
Rule_AddInterval(Rule_Guard_CaptureBase_GenericCheck, 3)

end

--[[ checks the commander to see if he is near any of the created bases ]] function Rule_Guard_CaptureBase_GenericCheck() if SGroup_Exists("sg_guardleader") and SGroup_IsEmpty("sg_guardleader") == false then local pos = SGroup_GetPosition(SGroup_FromName("sg_guardleader")) for i = 5, 1, -1 do if t_base[i].name ~= nil and World_DistancePointToPoint(pos, t_base[i].pos) <= 25 then if EGroup_IsEmpty(t_base[i].name) == false then

				--[[ INTEL EVENT -- the base is ours ]]
				Util_StartIntel(EVENTS.IE_Sturnn_TakingCommandStructure)
				
				MSO4_SwitchPings_RemoveBeacon(t_base[i].beacon)
				EGroup_SetPlayerOwner(t_base[i].name, g_Player1)
				
				g_basesrecovered = g_basesrecovered+1
				
				t_base[i].name = nil
				break
			elseif EGroup_IsEmpty(t_base[i].name) then
				MSO4_SwitchPings_RemoveBeacon(t_base[i].beacon)
				t_base[i].name = nil
				g_basesrecovered = g_basesrecovered+1
			end
		end
	end
	
end

if	g_basesrecovered == 5 then
	Rule_Remove(Rule_Guard_CaptureBase_GenericCheck)
end

end

function Rule_Guard_ConvoyNeedsToMove()

--[[ if the group exists and we're the IG player ]]
if g_playerSwitch == "g_Player1" then
	
	Rule_AddOneShot(Rule_Guard_PathNotClearedInTime, 120)
	
	Rule_Remove(Rule_Guard_ConvoyNeedsToMove)
else
	
	Rule_AddOneShot(Rule_Guard_PathNotClearedInTime, 0)
	
	Rule_Remove(Rule_Guard_ConvoyNeedsToMove)
	
end

end

--[[ this is the deadman's switch that gets things going ]] function Rule_Guard_PathNotClearedInTime()

if g_convoymove ~= true and g_obj_clearpath ~= true then
	g_convoymove = true
	
	Util_StartIntel(EVENTS.IE_Convoy_CantStandStill)
	
	--[[ trigger the next objective ]]
	if Rule_Exists(Rule_Objective_EscortConvoy) == false then
		Rule_AddIntervalDelay(Rule_Objective_EscortConvoy, 1, 5)
	end
	if Rule_Exists(Rule_Objective_CallConvoy) == false then
		Rule_AddIntervalDelay(Rule_Objective_CallConvoy, 1, 7)
	end
	
	--[[ TRIGGER THE CONVOY HARASSMENT ]]
	Rule_Check_AddInterval(Rule_Disorder_HarassConvoy, 30)
	
	--[[ start the convoy rolling ]]
	Rule_AddInterval(Rule_TitanCrew_TransportMove_JunctA, 5)
	Rule_AddInterval(Rule_TitanCrew_ReachesDestination, 5)
	
	g_convoyscarlock = false
	--[[ this is the button stuff above that lets the General call the landraider over ]]
	Rule_AddInterval(Rule_ConvoyCall, 1)
	Rule_AddInterval(Rule_ConvoyLockout, 1)
	
end

end

--[[ CREATE THE FIRST OF THE GUARD SPECIFIC OBSTACLES ]]

-- here is a few things to get the guard player rolling forward --[[ make the Chaos ]] function Rule_Guard_CreateChaosOutpost()

--[[ if the turrets are gone ]]
if EGroup_Exists("eg_guard_1stchaos") and EGroup_IsEmpty("eg_guard_1stchaos") and (g_playerSwitch == "g_Player1" or g_eldarbreak == true) then
	
	--[[ this is the convoy button ]]
	if Button_Exists(g_conbtnID) and Button_GetEnabled(g_conbtnID) == false then
		Button_SetEnabled(g_conbtnID, true)
	end
	
	g_obj_clearpath = true
	Rule_Remove(Rule_Guard_CreateChaosOutpost)
	
	--[[ TRIGGER THE CONVOY HARASSMENT ]]
	Rule_Check_AddInterval(Rule_Disorder_HarassConvoy, 30)
	
	
elseif EGroup_Exists("eg_guard_1stchaos") and EGroup_IsEmpty("eg_guard_1stchaos_brrks") == false and (g_playerSwitch == "g_Player1" or g_eldarbreak == true) then
	
	
end

end

--[[ CALLING ALL CONVOYS ]] -- this function allows the guard player to command the Convoy to move to the general -- this is added when the convoy is kicked off (see down lower ) function Rule_ConvoyCall() --[[ toggle enabled ]] --disable the button if the player is not Player 1 if g_conbtnID ~= nil then

	if g_playerSwitch == "g_Player1" and Button_GetEnabled(g_conbtnID) == false then
		Button_SetEnabled(g_conbtnID, true)
	elseif g_playerSwitch == "g_Player2" and Button_GetEnabled(g_conbtnID) == true then
		Button_SetEnabled(g_conbtnID, false)
	end
	
	if Button_GetPressed(g_conbtnID) then
		if g_playerSwitch == "g_Player1" then
			
			-- if the general is there and not despawned and the transport is there too then issue the move order
			if SGroup_IsEmpty("sg_guardleader") == false 
			and SGroup_CountDeSpawned(SGroup_FromName("sg_guardleader")) == 0 
			and SGroup_IsEmpty("sg_convoytransport") == false 
			and g_convoyscarlock == false then
			
				local pos = SGroup_GetPosition(SGroup_FromName("sg_guardleader"))
				
				if World_DistanceSGroupToPoint(SGroup_FromName("sg_convoytransport"), pos, true) > g_callconvoydist then
					UIWarning_Show("$900914")
				else
					--[[ Intel Event ]]
					if Event_IsAnyRunning() == false and Event_TimeSinceLast() > 20 then
						Util_StartIntel(EVENTS.IE_Convoy_BetterPath)
					end
					
					--[[ Start the Count down 
					UI_ShowCountdown( 830070, 120)]]
					g_convoylock = 120
					g_called = true 
					g_obj_callconvoy = true
					
					if g_transporttrapped ~= true then
						local pos = SGroup_GetPosition(SGroup_FromName("sg_guardleader"))
						Cmd_MoveToPosOffset("sg_convoytransport", pos, 4, 7)
					end
				end
			end
			
		elseif g_playerSwitch == "g_Player2" then
			
		end
	end
	
	if g_guarddead then
		
		Util_SGroupAbilityButton_Remove(g_conbtnID)
		Button_Remove(g_conbtnID)
		Rule_Remove(Rule_ConvoyCall)
		
	end
	
end

end

function Rule_ConvoyLockout() if g_playerSwitch == "g_Player2" then g_convoylock = 0 g_called = false -- UI_HideCountdown() elseif g_playerSwitch == "g_Player1" then if g_convoylock > 0 then g_convoylock = g_convoylock-1 elseif g_convoylock == 0 and g_called == true then if g_obj_escortconvoy ~= true then Util_StartIntel(EVENTS.IE_Convoy_ReturnToPath) end g_called = false end end

if g_guarddead then
	
	g_convoylock = 0

-- UI_HideCountdown() Rule_Remove(Rule_ConvoyLockout)

end	

end

function Rule_Guard_BreachChaosCreate()

if EGroup_Exists("eg_guard_1stchaos_brrks") and EGroup_IsEmpty("eg_guard_1stchaos_brrks") == false then
	if SGroup_Exists("sg_guard_1stchaos") == false or SGroup_CountSpawned(SGroup_FromName("sg_guard_1stchaos")) < 3 then
		local blue = {"chaos_squad_cultist", "chaos_marine_squad", "chaos_marine_squad", "chaos_squad_cultist"}
		local rand1 = World_GetRand(1, table.getn(blue))
		local rand2 = World_GetRand(5, 8)
		local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player8, "sg_guard_1stchaos", blue[rand1], "mkr_firstchaosbase", 1, rand2)
--			Cpu_LockSGroup(g_Player6, "sg_guard_1stchaos")
		Cmd_SetStance("sg_guard_1stchaos", STANCE_StandGround)
		Cmd_AttackMoveMarker("sg_guard_1stchaos", "mkr_bigbreach")
	end
else
	Rule_Remove(Rule_Guard_BreachChaosCreate)
end

end

--[[ making the guard that the player must save ]] function Rule_Guard_FirstBase()

if EGroup_Exists("eg_guard_1stbase") == false then
	local  blue = {"guard_hq", "guard_infantry", "guard_tactica", "guard_mechanized"}
	--create the outpost
	for i = 1, 4 do
		Entity_CreateBuildingMarker(g_Player4, "eg_guard_1stbase"..i, blue[i], "mkr_guard_1stbase"..i, 1)
		EGroup_AddGroup(EGroup_CreateIfNotFound("eg_guard_1stbase"), EGroup_FromName("eg_guard_1stbase"..i))
	end
	
elseif EGroup_IsEmpty("eg_guard_1stbase") or EGroup_IsEmpty("eg_guard_1stbase1") then
	
	Rule_Remove(Rule_Guard_FirstBase)
	
	g_obj_defendbreach = false
	
elseif SGroup_Exists("sg_guard_1stchaos") and SGroup_IsEmpty("sg_guard_1stchaos") == false then
	
	if SGroup_Exists("sg_guard_1stguard") == false or SGroup_CountSpawned(SGroup_FromName("sg_guard_1stguard")) < 3 then
		local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player4, "sg_guard_1stguard", "guard_squad_guardsmen", "mkr_guard_1stbase1", 1, 12)

-- Cpu_LockSGroup(g_Player3, "sg_guard_1stguard") Cmd_SetMeleeStance("sg_guard_1stguard", MSTANCE_Assault) Cmd_AttackMoveMarker("sg_guard_1stguard", "mkr_bigbreach") end

elseif SGroup_Exists("sg_guard_1stchaos") and SGroup_IsEmpty("sg_guard_1stchaos") then
	
	--[[ INTEL EVENT - breach clear ]]
	g_obj_defendbreach = true
	
	Cmd_EnterBuilding("sg_guard_1stguard", "eg_guard_1stbase")
	
	g_bigbreachclear = true
	
	Rule_AddInterval(Rule_Guard_FirstBase_Give2Player, 1)
	
	Rule_Remove(Rule_Guard_FirstBase)
	
end

end

function Rule_Guard_FirstBase_Give2Player()

if EGroup_IsEmpty("eg_guard_1stbase") == false and EGroup_IsEmpty("eg_guard_1stbase1") == false 
and SGroup_IsInHold("sg_guard_1stguard", "eg_guard_1stbase", true) then
	
	--[[ INTEL EVENT - handing the base over ]]
	
	Rule_AddInterval(Rule_Objective_CommandBase, 1)
	
	Rule_AddInterval(Rule_Guard_FirstBase_Captured, 1)
	
	Rule_Remove(Rule_Guard_FirstBase_Give2Player)
elseif EGroup_IsEmpty("eg_guard_1stbase") or EGroup_IsEmpty("eg_guard_1stbase1")  then
	Rule_Remove(Rule_Guard_FirstBase_Give2Player)
end

end

function Rule_Guard_FirstBase_Captured()

if EGroup_IsEmpty("eg_guard_1stbase") == false and EGroup_IsEmpty("eg_guard_1stbase1") == false 
and Prox_AnySquadNearMarker("sg_guardleader", "mkr_guard_1stbase1") then
	
	--[[ INTEL EVENT -- the base is ours ]]
	Util_StartIntel(EVENTS.IE_Sturnn_TakingCommandStructure)
	
	g_obj_commandbase = true
	
	SGroup_DestroyAllSquads("sg_guard_1stguard")
	EGroup_SetPlayerOwner("eg_guard_1stbase", g_Player1)
	g_guard_1stbase = "g_Player1"
	
	Rule_Remove(Rule_Guard_FirstBase_Captured)
	
elseif EGroup_IsEmpty("eg_guard_1stbase") or EGroup_IsEmpty("eg_guard_1stbase1")  then
	Rule_Remove(Rule_Guard_FirstBase_Captured)
end

end

--[[ GUARD OPEN DOOR ]] function Rule_Guard_DefeatEndSecurity()

if EGroup_IsCapturedByPlayer("eg_ig_controlpoint", g_Player1, false) then

-- Anim_PlayEGroupAnim( "eg_gatefinal", "die" )

	g_obj_capturebuilding = true
	
	Rule_Check_Remove(Rule_EndZone_Defense)
	
	Rule_AddInterval(Rule_Guard_InFinalZone, 1)
	
	Rule_Remove(Rule_Guard_DefeatEndSecurity)
end

end

function Rule_Guard_InFinalZone()

if SGroup_IsEmpty("sg_convoytransport") == false and Prox_AnySquadNearMarker("sg_convoytransport", "mkr_convoy_destFinal") then
	
	g_obj_finalapproach = true
	
	Rule_Remove(Rule_Guard_InFinalZone)
end

end


--[[ TITAN CREW ]]


-- the following are the essentials of the Titan Crew Convoy and supporting game elements function Rule_TitanCrew_KickOff()

Rule_AddInterval(Rule_TitanCrew_GateB_State, 1)
Rule_AddInterval(Rule_TitanCrew_GateC_State, 1)

local mod_raiderspeeddecrease = Modifier_Create(MAT_EntityType, "speed_maximum_modifier", MUT_Multiplication, false, g_landraider_speed, "land_raider")
Modifier_ApplyToPlayer( mod_raiderspeeddecrease, g_Player3 )
local mod_raiderarmour = Modifier_Create(MAT_EntityType, "armour_modifier", MUT_Multiplication, false, 2, "land_raider")
Modifier_ApplyToPlayer( mod_raiderarmour, g_Player3 )

g_restart = 0
Rule_AddIntervalDelay(Rule_TitanCrew_TransportTrapped, 10, 10)

end

--[[ Simple Logic for Convoy Escort ]]

-- deg - to be readdressed later on function Rule_TitanCrew_EscortMove() if SGroup_IsEmpty("sg_convoytransport") or SGroup_IsEmpty("sg_convoyescort") then Rule_Remove(Rule_TitanCrew_EscortTrack) elseif SGroup_IsEmpty("sg_convoytransport") == false then for i = 1, 8 do if SGroup_IsEmpty("sg_convoyescort"..i) == false and SGroup_CountDeSpawned(SGroup_FromName("sg_convoyescort"..i)) == 0 then Cmd_MoveToSGroupOffset("sg_convoyescort"..i, "sg_convoytransport", i-1, 5) end end if SGroup_IsEmpty("sg_convoyleader") == false and SGroup_CountDeSpawned(SGroup_FromName("sg_convoyleader")) == 0 then Cmd_MoveToSGroupOffset("sg_convoyleader", "sg_convoytransport", 0, 5) end end end

--[[ TRACKING AND REPLACING ]]

function Rule_TitanCrew_EscortTrack() if SGroup_IsEmpty("sg_convoytransport") == false and SGroup_IsEmpty("sg_convoyescort") == false then for i = 1, 8 do if g_reinforceblackout == 0 and SGroup_IsEmpty("sg_convoyescort"..i) then

			local pos = SGroup_GetPosition(SGroup_FromName("sg_convoytransport"))
			Rule_TitanCrew_MarineReplace(i, pos)
			g_reinforceblackout = g_reinforceblackout_delay
			
		end
	end
	if g_reinforceblackout == 0 and SGroup_IsEmpty("sg_convoyleader") then
		
		local pos = SGroup_GetPosition(SGroup_FromName("sg_convoytransport"))
		Rule_TitanCrew_LeaderReplace(pos)
		g_reinforceblackout = g_reinforceblackout_delay
		
	end
end

if SGroup_IsEmpty("sg_convoyescort") then
	Rule_Remove(Rule_TitanCrew_EscortTrack)
	Util_StartIntel(EVENTS.IE_Convoy_BrothersFallen)
end

if g_reinforceblackout > 0 then
	g_reinforceblackout = g_reinforceblackout-1
end

end

function Rule_TitanCrew_MarineReplace(integer, pos)

t_reinfconvoy = { 
	--[[ type 1 ]]{ blue = "space_marine_squad_tactical", weapon = nil},
	--[[ type 2.1 ]]{ blue = "space_marine_squad_tactical", weapon = "space_marine_plasma_gun"},
	--[[ type 2.2 ]]{ blue = "space_marine_squad_tactical", weapon = "space_marine_flamer_tactical"},
	--[[ type 3 ]]{ blue = "space_marine_squad_dreadnought", weapon = nil},
	--[[ type 4 ]]{ blue = "space_marine_squad_tactical", weapon =  nil},
	--[[ type 5 ]]{ blue = "space_marine_squad_terminator", weapon = nil},
	--[[ type 6 ]]{ blue = "space_marine_squad_terminator_assault", weapon = nil},

}

local rand = World_GetRand(1, table.getn(t_reinfconvoy))
local i = integer
t_convoy.sgroupid[i] = Util_CreateSquadsAndDropPodIn(g_Player3, "sg_convoyescort"..i, t_reinfconvoy[rand].blue, pos, 1, 1)
	SGroup_AddGroup(g_sg_convoyID, t_convoy.sgroupid[i])
	SGroup_AddGroup(g_sg_convoyescortID, t_convoy.sgroupid[i])
if t_reinfconvoy[rand].weapon ~= nil then
	Squad_ForceUpgradeWeapons(SGroup_GetDeSpawnedSquadAt(t_convoy.sgroupid[i], 1), t_reinfconvoy[rand].weapon, 1)
end

end

function Rule_TitanCrew_LeaderReplace(pos)

local sgroupID = Util_CreateSquadsAndDropPodIn(g_Player3, "sg_convoyleader", "space_marine_squad_chaplain", pos, 1, 1)
SGroup_AddGroup(g_sg_convoyescortID, sgroupID)
SGroup_AddGroup(g_sg_convoyID, sgroupID)

end

--[[ Stalling the Convoy ]] function Rule_TitanCrew_TransportTrapped()

if SGroup_IsEmpty("sg_convoytransport") == false then
	
	local currenthealth = SGroup_GetTotalHealthCurrent("sg_convoytransport")
	
	-- the idea here is to 'stall' the convoy whenever it's getting 'into trouble'
	if  --[[g_restart == 0 and ]]currenthealth <= g_totalhealth*0.1 then
		
		g_transporthurt = true
		g_transporttrapped = true
		g_restart = 6
		g_convoydisabled = true
		
		if g_warningOn ~= true then
			
			--[[ INTEL EVENT - to damaged to move ]]
			if Event_IsAnyRunning() == false and Event_TimeSinceLast() > 10 and g_firstrundone then
				Util_StartIntel(EVENTS.IE_Convoy_StalledNeedAFix)
			end
			g_firstrundone = true
			Sound_PlayStinger("stinger_mso4_convoyatrisk")	
			
			Rule_ConvoyStopWarning()
			
		end
		
		if Rule_Exists(Rule_TitanCrew_TransportDeath) == false then
			Rule_AddOneShot(Rule_TitanCrew_TransportDeath, 5)
		end
		
	elseif g_restart == 0 and Prox_PlayerSquadsInProximityOfSquads(g_Player6, "sg_convoytransport", 7, false) then
		g_transporttrapped = true
		g_restart = 4
		
		--[[ INTEL EVENT - surrounded ]]
		if Event_IsAnyRunning() == false and Event_TimeSinceLast() > 20 then
			Util_StartIntel(EVENTS.IE_Convoy_UnderFire)
		end
		
		Sound_PlayStinger("stinger_mso4_convoyatrisk")	
		
		Rule_ConvoyStopWarning()
		
	elseif g_restart == 0 and Prox_PlayerSquadsInProximityOfSquads(g_Player5, "sg_convoytransport", 7, false) then
		g_transporttrapped = true
		g_restart = 4
		
		--[[ INTEL EVENT - surrounded ]]
		--Util_StartIntel(EVENTS.IE_Convoy_UnderFire2)
		Sound_PlayStinger("stinger_mso4_convoyatrisk")	
		
		Rule_ConvoyStopWarning()
		
	--[[ the convoy will no longer stop for being at 40% health ]]
	elseif  g_restart == 0 and currenthealth <= g_totalhealth*0.4 then

-- g_transporttrapped = true -- g_restart = 40 -- g_convoydisabled = true

		--[[ INTEL EVENT - taking lots of damage ]]
		if Event_IsAnyRunning() == false and Event_TimeSinceLast() > 35 and g_firstrundone then
			Util_StartIntel(EVENTS.IE_Convoy_HeavyDamage)
			Sound_PlayStinger("stinger_mso4_convoyatrisk")	
		end
		g_firstrundone = true
		

-- Rule_ConvoyStopWarning()

	elseif (currenthealth > g_totalhealth*0.41 and g_transporthurt == true ) or g_restart == 1 then
		g_transporttrapped = false
		g_transporthurt = false
		g_restart = 0
		g_convoydisabled = false
		
		--[[ INTEL EVENT - starting up again ]]
		if g_playerSwitch == "g_Player1" and Event_IsAnyRunning() == false and Event_TimeSinceLast() > 40 then
			Util_StartIntel(EVENTS.IE_Convoy_Grateful)
		end
		
		if g_warningOn == true then
			MSO4_SwitchPings_RemoveBoth("g_cnvybeaconID", "png_convoy")
			g_warningOn = false
		end
		
	end
	
	g_lasthealth = currenthealth
	
	if g_restart >= 2 then
		g_restart = g_restart-1
	end
	
elseif SGroup_IsEmpty("sg_convoytransport") then
	Rule_Remove(Rule_TitanCrew_TransportTrapped)
	if g_warningOn == true then
		MSO4_SwitchPings_RemoveBoth("g_cnvybeaconID", "png_convoy")
		g_warningOn = false
	end
end

end

function Rule_TitanCrew_TransportDeath()

g_building_exceptions2 = 
{
	"guard_listening_post",
	"guard_mines",
	"guard_tactica",
	"guard_infantry",
	"guard_mechanized",
	"guard_plasma_generator",
	"guard_thermo_plasma",
	"guard_turret_heavy_bolter",
	"guard_mars_pattern"
}

g_unit_exceptions2 = 
{
	"guard_squad_assassin",
	"guard_squad_baneblade",
	"guard_squad_basilisk",
	"guard_squad_basilisk_sp_mso2",
	"guard_squad_chimera",
	"guard_squad_chimera_sp_test",
	"guard_squad_command_squad",
	"guard_squad_commissar",
	"guard_squad_guardsmen",
	"guard_squad_hellhound",
	"guard_squad_kasrkin",
	"guard_squad_lemanruss",
	"guard_squad_ogryns",
	"guard_squad_priest",
	"guard_squad_psyker",
	"guard_squad_psyker_sp_msdc5",
	"guard_squad_sentinel",
}

if SGroup_IsEmpty("sg_convoytransport") == false and g_handover == true then
	
	if ( Player_HasBuildingsExcept(g_Player1, g_building_exceptions2) == false ) then
		if( Player_HasSquadsExcept(g_Player1, g_unit_exceptions2 ) == false ) then
			
			Util_StartNIS(EVENTS.NIS_KillConvoy)
			
		end	
	end
	
end

end

function Rule_ConvoyStopWarning()

g_warningOn = true

local pos = SGroup_GetPosition(SGroup_FromName("sg_convoytransport"))
MSO4_SwitchPings_Add(g_Player1, "g_cnvybeaconID", "png_convoy", pos)

Cmd_StopSquads("sg_convoytransport")

end

--[[ TRANSPORT MOVE SCRIPT ]]

-- deg - the following is a chain of statements that tracks the variable path of the transport across the level -- I set it up as a chain instead of a something more efficient so we could customize each stage if we wanted to. function Rule_TitanCrew_TransportMove_JunctA() if SGroup_IsEmpty("sg_convoytransport") == false and g_convoylock == 0 and g_restart == 0 then local markerpos = Marker_GetPosition(Marker_FromName("mkr_convoy_junctA", "basic_marker")) local transpos = SGroup_GetPosition(SGroup_FromName("sg_convoytransport"))

	if g_obj_escortconvoy == true then
		
		Rule_Remove(Rule_TitanCrew_TransportMove_JunctA)
		
	elseif transpos.z > markerpos.z then
		
		Cmd_MoveToMarker("sg_convoytransport", "mkr_convoy_destA1")
		Rule_AddInterval(Rule_TitanCrew_TransportMove_JunctA1, 5)
		Rule_Remove(Rule_TitanCrew_TransportMove_JunctA)
		
	else
		
		if World_DistanceSGroupToPoint(g_transsgID, markerpos, true) <= 20 then
			if --[[g_bigbreachclear]]false == true then
				Cmd_MoveToMarker("sg_convoytransport", "mkr_convoy_destA2")
				Rule_AddInterval(Rule_TitanCrew_TransportMove_JunctA2, 5)
				Rule_Remove(Rule_TitanCrew_TransportMove_JunctA)
			else
				Cmd_MoveToMarker("sg_convoytransport", "mkr_convoy_destA1")
				Rule_AddInterval(Rule_TitanCrew_TransportMove_JunctA1, 5)
				Rule_Remove(Rule_TitanCrew_TransportMove_JunctA)
			end
		else
			Cmd_MoveToMarker("sg_convoytransport", "mkr_convoy_junctA")
		end
		
	end
end

end

--[[ the transport makes it through the wall ]] function Rule_TitanCrew_TransportMove_JunctA2() if SGroup_IsEmpty("sg_convoytransport") == false and g_convoylock == 0 and g_restart == 0 then local markerpos = Marker_GetPosition(Marker_FromName("mkr_convoy_destA2", "basic_marker")) local transpos = SGroup_GetPosition(SGroup_FromName("sg_convoytransport"))

	if g_obj_escortconvoy == true then
		
		Rule_Remove(Rule_TitanCrew_TransportMove_JunctA2)
		
	elseif transpos.z > markerpos.z then
		
		Cmd_MoveToMarker("sg_convoytransport", "mkr_convoy_junctB")
		Rule_AddInterval(Rule_TitanCrew_TransportMove_JunctB, 5)
		Rule_Remove(Rule_TitanCrew_TransportMove_JunctA2)
		
	else
		
		if World_DistanceSGroupToPoint(g_transsgID, markerpos, true) <= 20 then
			Cmd_MoveToMarker("sg_convoytransport", "mkr_convoy_junctB")
			Rule_AddInterval(Rule_TitanCrew_TransportMove_JunctB, 5)
			Rule_Remove(Rule_TitanCrew_TransportMove_JunctA2)
		else
			Cmd_MoveToMarker("sg_convoytransport", "mkr_convoy_destA2")
		end
	end
end

end

--[[ the transport has to wait at the main gates ]] function Rule_TitanCrew_TransportMove_JunctA1() if SGroup_IsEmpty("sg_convoytransport") == false and g_convoylock == 0 and g_restart == 0 then local pos = Marker_GetPosition(Marker_FromName("mkr_convoy_destA1", "basic_marker")) if g_obj_escortconvoy == true then

		Rule_Remove(Rule_TitanCrew_TransportMove_JunctA1)
		
	elseif World_DistanceSGroupToPoint(g_transsgID, pos, true) <= 20 then
		
		g_convoyscarlock = true
		--[[ INTEL EVENT - sorry can't move the convoy right now ]]
		
		Util_CreateSquadsAtMarkerEx(g_Player4, "sg_gatekeeper", "guard_squad_kasrkin", "mkr_gatesteward", 1, 2)
		SGroup_AddLeaders("sg_gatekeeper")
		
		Rule_AddOneShot(Rule_IE_GateA_Announcement, 0)
		Rule_AddInterval(Rule_TitanCrew_GateA_Lower, 1)
		Rule_Remove(Rule_TitanCrew_TransportMove_JunctA1)
	else
		Cmd_MoveToMarker("sg_convoytransport", "mkr_convoy_destA1")
	end
end

end

--[[ main gates lower ]] function Rule_TitanCrew_GateA_Lower() if SGroup_IsEmpty("sg_gatekeeper") == false then if EGroup_IsCapturedByPlayer("eg_gateA_singlepoint", g_Player4, false) or EGroup_IsCapturedByPlayer("eg_gateA_singlepoint", g_Player1, false) then

		Playlist_Manager(PC_Music, {"music_mso4_perc"}, true, true, {30, 40})	
		
		--lower last gate
		Anim_PlayEGroupAnim( "eg_gateA1", "die" )
		Anim_PlayEGroupAnim( "eg_gateA1", "die" )
		
		--[[ objective complete ]]
		g_obj_opengateA = true
		
		Rule_AddOneShot(Rule_TitanCrew_GateA_Despawn, 8)
		
		Rule_Remove(Rule_TitanCrew_GateA_Lower)
		
	elseif EGroup_IsCapturedByPlayer("eg_gateA_singlepoint", g_Player4, false) == false 
	or EGroup_IsCapturedByPlayer("eg_gateA_singlepoint", g_Player1, false) == false then
		Cmd_Capture("sg_gatekeeper", "eg_gateA_singlepoint")
	end
else
	Util_CreateSquadsAtMarkerEx(g_Player4, "sg_gatekeeper", "guard_squad_kasrkin", "mkr_gatesteward", 1, 2)
	SGroup_AddLeaders("sg_gatekeeper")
end

end

--[[ first gate drops ]] function Rule_TitanCrew_GateA_Despawn() EGroup_DeSpawn( "eg_gateA1") EGroup_DeSpawn( "eg_gateA2")

g_convoyscarlock = false
if SGroup_IsEmpty("sg_convoytransport") == false and g_convoylock == 0 and g_restart == 0 then
	Cmd_MoveToMarker("sg_convoytransport", "mkr_convoy_junctB")
end
Rule_AddOneShot(Rule_IE_GateA_Open, 0)
Rule_AddInterval(Rule_TitanCrew_TransportMove_JunctB, 5)

end

--[[ Transport Reaches Junction B ]] function Rule_TitanCrew_TransportMove_JunctB() if SGroup_IsEmpty("sg_convoytransport") == false and g_convoylock == 0 and g_restart == 0 then local markerpos = Marker_GetPosition(Marker_FromName("mkr_convoy_junctB", "basic_marker")) local transpos = SGroup_GetPosition(SGroup_FromName("sg_convoytransport"))

	if g_obj_escortconvoy == true then
		
		Rule_Remove(Rule_TitanCrew_TransportMove_JunctB)
		
	elseif transpos.z > markerpos.z then
		g_step = 2
		
		Cmd_MoveToMarker("sg_convoytransport", "mkr_convoy_destB2")
		Rule_AddInterval(Rule_TitanCrew_TransportMove_JunctB2, 5)
		Rule_Remove(Rule_TitanCrew_TransportMove_JunctB)
		
	else
		
		if World_DistanceSGroupToPoint(g_transsgID, markerpos, true) <= 20 then
			g_step = 2
			if g_gateBdown == true then
				Cmd_MoveToMarker("sg_convoytransport", "mkr_convoy_destB2")
				Rule_AddInterval(Rule_TitanCrew_TransportMove_JunctB2, 5)
				Rule_Remove(Rule_TitanCrew_TransportMove_JunctB)
			else
				Cmd_MoveToMarker("sg_convoytransport", "mkr_convoy_destB1")
				Rule_AddInterval(Rule_TitanCrew_TransportMove_JunctB1, 5)
				Rule_Remove(Rule_TitanCrew_TransportMove_JunctB)
			end
		else
			Cmd_MoveToMarker("sg_convoytransport", "mkr_convoy_junctB")
		end
	end
end

end --[[ the transport goes through the second gate ]] function Rule_TitanCrew_TransportMove_JunctB2() if SGroup_IsEmpty("sg_convoytransport") == false and g_convoylock == 0 and g_restart == 0 then local markerpos = Marker_GetPosition(Marker_FromName("mkr_convoy_destB2", "basic_marker")) local transpos = SGroup_GetPosition(SGroup_FromName("sg_convoytransport"))

	if g_obj_escortconvoy == true then
		
		Rule_Remove(Rule_TitanCrew_TransportMove_JunctB2)
		
	elseif transpos.z > markerpos.z then
		
		Cmd_MoveToMarker("sg_convoytransport", "mkr_convoy_junctC")
		Rule_AddInterval(Rule_TitanCrew_TransportMove_JunctC, 5)
		Rule_Remove(Rule_TitanCrew_TransportMove_JunctB2)
		
	else
		
		if World_DistanceSGroupToPoint(g_transsgID, markerpos, true) <= 20 then
			Cmd_MoveToMarker("sg_convoytransport", "mkr_convoy_junctC")
			Rule_AddInterval(Rule_TitanCrew_TransportMove_JunctC, 5)
			Rule_Remove(Rule_TitanCrew_TransportMove_JunctB2)
		else
			Cmd_MoveToMarker("sg_convoytransport", "mkr_convoy_destB2")
		end
	end
end

end --[[ the transport has to go around the second gate ]] function Rule_TitanCrew_TransportMove_JunctB1() if SGroup_IsEmpty("sg_convoytransport") == false and g_convoylock == 0 and g_restart == 0 then local pos = Marker_GetPosition(Marker_FromName("mkr_convoy_destB1", "basic_marker")) if g_obj_escortconvoy == true then

		Rule_Remove(Rule_TitanCrew_TransportMove_JunctB1)
		
	elseif World_DistanceSGroupToPoint(g_transsgID, pos, true) <= 20 then
		Cmd_MoveToMarker("sg_convoytransport", "mkr_convoy_junctC")
		Rule_AddInterval(Rule_TitanCrew_TransportMove_JunctC, 5)
		Rule_Remove(Rule_TitanCrew_TransportMove_JunctB1)
	else
		Cmd_MoveToMarker("sg_convoytransport", "mkr_convoy_destB1")
	end
end

end

--[[ Transport Reaches Junction C ]] function Rule_TitanCrew_TransportMove_JunctC() if SGroup_IsEmpty("sg_convoytransport") == false and g_convoylock == 0 and g_restart == 0 then local markerpos = Marker_GetPosition(Marker_FromName("mkr_convoy_junctC", "basic_marker")) local transpos = SGroup_GetPosition(SGroup_FromName("sg_convoytransport"))

	if g_obj_escortconvoy == true then
		
		Rule_Remove(Rule_TitanCrew_TransportMove_JunctC)
		
	elseif transpos.z > markerpos.z then
		g_step = 3
		
		Cmd_MoveToMarker("sg_convoytransport", "mkr_convoy_destC2")
		Rule_AddInterval(Rule_TitanCrew_TransportMove_JunctC2, 5)
		Rule_Remove(Rule_TitanCrew_TransportMove_JunctC)
		
	else
		
		if World_DistanceSGroupToPoint(g_transsgID, markerpos, true) <= 20 then
			if g_gateCdown == true then
				Cmd_MoveToMarker("sg_convoytransport", "mkr_convoy_destC2")
				Rule_AddInterval(Rule_TitanCrew_TransportMove_JunctC2, 5)
				Rule_Remove(Rule_TitanCrew_TransportMove_JunctC)
			else
				Cmd_MoveToMarker("sg_convoytransport", "mkr_convoy_destC1")
				Rule_AddInterval(Rule_TitanCrew_TransportMove_JunctC1, 5)
				Rule_Remove(Rule_TitanCrew_TransportMove_JunctC)
			end
		else
			Cmd_MoveToMarker("sg_convoytransport", "mkr_convoy_junctC")
		end
	end
end

end --[[ the transport goes through the second gate ]] function Rule_TitanCrew_TransportMove_JunctC2() if SGroup_IsEmpty("sg_convoytransport") == false and g_convoylock == 0 and g_restart == 0 then local markerpos = Marker_GetPosition(Marker_FromName("mkr_convoy_destC2", "basic_marker")) local transpos = SGroup_GetPosition(SGroup_FromName("sg_convoytransport"))

	if g_obj_escortconvoy == true then
		
		Rule_Remove(Rule_TitanCrew_TransportMove_JunctC2)
		
	elseif transpos.z > markerpos.z then
		
			Cmd_MoveToMarker("sg_convoytransport", "mkr_convoy_destD")
			g_step = 4
	--		Rule_AddInterval(Rule_TitanCrew_TransportMove_JunctC, 1)
			Rule_Remove(Rule_TitanCrew_TransportMove_JunctC2)
		
	else
		
		if World_DistanceSGroupToPoint(g_transsgID, markerpos, true) <= 20 then
			Cmd_MoveToMarker("sg_convoytransport", "mkr_convoy_destD")
			g_step = 4
	--		Rule_AddInterval(Rule_TitanCrew_TransportMove_JunctC, 1)
			Rule_Remove(Rule_TitanCrew_TransportMove_JunctC2)
		else
			Cmd_MoveToMarker("sg_convoytransport", "mkr_convoy_destC2")
		end
	end
end

end --[[ the transport has to go around the second gate ]] function Rule_TitanCrew_TransportMove_JunctC1() if SGroup_IsEmpty("sg_convoytransport") == false and g_convoylock == 0 and g_restart == 0 then local pos = Marker_GetPosition(Marker_FromName("mkr_convoy_destC1", "basic_marker")) if g_obj_escortconvoy == true then

		Rule_Remove(Rule_TitanCrew_TransportMove_JunctC1)
		
	elseif World_DistanceSGroupToPoint(g_transsgID, pos, true) <= 20 then
		Cmd_MoveToMarker("sg_convoytransport", "mkr_convoy_destD")
		g_step = 4
--		Rule_AddInterval(Rule_TitanCrew_TransportMove_JunctC, 1)
		Rule_Remove(Rule_TitanCrew_TransportMove_JunctC1)
	else
		Cmd_MoveToMarker("sg_convoytransport", "mkr_convoy_destC1")
	end
end

end

function Rule_TitanCrew_ReachesDestination()

if SGroup_IsEmpty("sg_convoytransport") == false and Prox_AnySquadNearMarker("sg_convoytransport", "mkr_convoy_destD") then
	
	g_obj_escortconvoy = true
	Rule_Check_AddInterval(Rule_Guard_DefeatEndSecurity, 1)
	
	Rule_Remove(Rule_TitanCrew_ReachesDestination)
end

end

--[[ Gate B checks ]]

-- are they down? function Rule_TitanCrew_GateB_State() if EGroup_IsCapturedByPlayer("eg_gateB_points", g_Player4, false) or EGroup_IsCapturedByPlayer("eg_gateB_points", g_Player1, false) then

	--[[ placeholder ]]
	Playlist_Manager(PC_Music, {"music_mso4_perc"}, true, true, {30, 40}) 
	
	Anim_PlayEGroupAnim( "eg_gateB1", "die" )
	Anim_PlayEGroupAnim( "eg_gateB2", "die" )
	
	--[[ objective complete ]]
	g_obj_opengateB = true
	
	Rule_AddOneShot(Rule_TitanCrew_GateB_Despawn, 8)
	
	Rule_Remove(Rule_TitanCrew_GateB_State)
end

end

function Rule_TitanCrew_GateB_Despawn() EGroup_DeSpawn("eg_gateB1") EGroup_DeSpawn("eg_gateB2")

g_gateBdown = true

end

--[[ Gate C checks ]]

-- are they down? function Rule_TitanCrew_GateC_State() if EGroup_IsCapturedByPlayer("eg_gateC_points", g_Player4, false) or EGroup_IsCapturedByPlayer("eg_gateC_points", g_Player1, false) then

	--[[ placeholder ]]
	Util_Music_CreateSingleLoop( {"music_mso4"}, {"music_mso4_perc", "music_mso4_perc"}, 130 )
	
	Anim_PlayEGroupAnim( "eg_gateC1", "die" )
	Anim_PlayEGroupAnim( "eg_gateC2", "die" )
	
	--[[ objective complete ]]
	g_obj_opengateC = true
	
	Rule_AddOneShot(Rule_TitanCrew_GateC_Despawn, 8)
	
	Rule_Remove(Rule_TitanCrew_GateC_State)
end

end

function Rule_TitanCrew_GateC_Despawn() EGroup_DeSpawn("eg_gateC1") EGroup_DeSpawn("eg_gateC2")

g_gateCdown = true

end


--[[ FORCES OF DISORDER ]]


-- here we set about making the evil ones function Rule_Disorder_Kickoff()

t_orkchargetarget = {"mkr_ig_rally2", "mkr_ig_rally1"}
t_chaoschargetarget = {"mkr_ig_rally14", "mkr_ig_rally13"}

t_orkbuild = {
	"ork_boy_hut",
	"ork_generator",
	"ork_mek_shop",
	"ork_pile_o_guns",
	"ork_waagh_banner",
}

t_chaosbuild = {
	"chaos_temple",
	"chaos_sacrificial_circle",
	"chaos_armoury",
	"chaos_plasma_generator",
	"chaos_machine_pit",
}

Player_SetAllResources(g_Player5, 100000, 100000, 100)
Player_SetAllResources(g_Player6, 100000, 100000)

local restrict = {
	"chaos_squad_cap_research",
	"chaos_squad_cap_research_1",
	"chaos_squad_cap_research_2",
	"chaos_squad_cap_research_3",
	"chaos_support_cap_research_1",
	"chaos_support_cap_research_2",
	"chaos_support_cap_research_3",
}  

Player_RestrictResearchList(g_Player6, restrict)

Cpu_Enable(g_Player5, true)
Cpu_EnableComponent(g_Player5, false,   CT_Resourcing)
Cpu_EnableComponent(g_Player5, false,  CT_Attacking)
Cpu_SetDifficulty(g_Player5,  AD_Advanced)
Player_SetMaxSupportCap( g_Player5, 10 )
Player_SetSupportCap( g_Player5, 10 )
Player_SetMaxSquadCap( g_Player5, 10 )
Player_SetSquadCap( g_Player5, 10 )

Cpu_Enable(g_Player6, true)
Cpu_EnableComponent(g_Player6, false,   CT_Resourcing)
Cpu_EnableComponent(g_Player6, false,  CT_Attacking)
Cpu_SetDifficulty(g_Player6,  AD_Advanced)
Player_SetMaxSupportCap( g_Player6, 10 )
Player_SetSupportCap( g_Player6, 10 )
Player_SetMaxSquadCap( g_Player6, 10 )
Player_SetSquadCap( g_Player6, 10 )

Player_RestrictSquad(g_Player6, "chaos_squad_horror")

for j = 1, 2 do
	Entity_CreateBuildingMarker(g_Player5, "eg_ork_hq"..j, "ork_hq", "mkr_orkbase"..j, 1)
	for i = 1, 5 do
		local num = World_GetRand(2, 4)
		for y = 1, num do
			local newx = World_GetRand(-30, 30)
			local newz = World_GetRand(-30, 30)
			local pos = Marker_GetPosition(Marker_FromName("mkr_orkbase"..j, "basic_marker"))
			pos.x = pos.x + newx
			pos.z = pos.z + newz
			Entity_CreateBuildingPosition(g_Player5, "eg_chaos_base"..i, t_orkbuild[i], pos, 1)
		end
	end
end

for j = 1, 2 do	
	Entity_CreateBuildingMarker(g_Player6, "eg_chaos_hq"..j, "chaos_hq", "mkr_chaosbase"..j, 1)
	for i = 1, 5 do
		local num = World_GetRand(2, 4)
		for y = 1, num do
			local newx = World_GetRand(-30, 30)
			local newz = World_GetRand(-30, 30)
			local pos = Marker_GetPosition(Marker_FromName("mkr_chaosbase"..j, "basic_marker"))
			pos.x = pos.x + newx
			pos.z = pos.z + newz
			Entity_CreateBuildingPosition(g_Player6, "eg_chaos_base"..i, t_chaosbuild[i], pos, 1)
		end
	end
end

Rule_AddInterval(Rule_Disorder_SquadCount, 1)

end

function Rule_Disorder_SquadCount() g_orkcount = Player_GetSquadCount(g_Player5) g_chaoscount = Player_GetSquadCount(g_Player6)

if g_orksquadlock ~= true and orkcount ~= nil and orkcount > 5 then
	Cpu_EnableComponent(g_Player5, false, CT_BuildUnits)
	g_orksquadlock = true
elseif g_orksquadlock == true and orkcount ~= nil and orkcount < 4 then
	Cpu_EnableComponent(g_Player5, false, CT_BuildUnits)
	g_orksquadlock = false
end

if g_chaossquadlock ~= true and chaoscount ~= nil and chaoscount > 5 then
	Cpu_EnableComponent(g_Player6, false, CT_BuildUnits)
	g_chaossquadlock = true
elseif g_chaossquadlock == true and chaoscount ~= nil and chaoscount < 4 then
	Cpu_EnableComponent(g_Player6, false, CT_BuildUnits)
	g_chaossquadlock = false
end

end

function MS04_Generate_Chaos(playerID, sgroupname, marker, squads, infantry, vehicle) if infantry == true then local blue = { "chaos_squad_raptor", "chaos_marine_squad", "chaos_squad_khorne_berserker", "chaos_squad_cultist", "chaos_squad_obliterator", "chaos_marine_squad", "chaos_squad_raptor" } local num = {8, 9, 6, 12, 4, 6, 8} local rand1 = World_GetRand(1, table.getn(blue)) Util_CreateSquadsAtMarkerEx(playerID, sgroupname, blue[rand1], marker, squads, num[rand1]) end if vehicle == true then local blue = { "chaos_squad_defiler", "chaos_squad_predator", "chaos_squad_defiler", "chaos_squad_predator", } local num = {1, 1, 1, 1} local rand1 = World_GetRand(1, table.getn(blue)) Util_CreateSquadsAtMarker(playerID, sgroupname, blue[rand1], marker, num[rand1]) end

return SGroup_FromName(sgroupname)

end

function MS04_Generate_Orks(playerID, sgroupname, marker, squads, infantry, vehicle) if infantry == true then local blue = { "ork_squad_shoota_boy", "ork_squad_slugga", "ork_squad_stormboy", "ork_squad_slugga", "ork_squad_shoota_boy", "ork_squad_nob", "ork_squad_tankbusta" } local num = {8, 9, 6, 12, 3, 5, 8} local rand1 = World_GetRand(1, table.getn(blue)) Util_CreateSquadsAtMarkerEx(playerID, sgroupname, blue[rand1], marker, squads+1, num[rand1]) end if vehicle == true then local blue = { "ork_squad_killa_kan", "ork_squad_killa_kan", "ork_squad_looted_tank", "ork_squad_looted_tank", "ork_squad_trukk", "ork_squad_wartrak", "ork_squad_wartrak", } local num = {1, 2, 1, 1, 1, 2, 3} local rand1 = World_GetRand(1, table.getn(blue)) Util_CreateSquadsAtMarker(playerID, sgroupname, blue[rand1], marker, num[rand1]) end

return SGroup_FromName(sgroupname)

end

--[[ Create a skirmish line of Ork and Guard combatants without blowing the squad count ]] function Rule_Disorder_OrkSkirmishLine()

local count = table.getn(t_orkchargetarget)
if count > 0 then
	local rand = World_GetRand(5, 8)
	for i = 1, count do
		for y = 1, 2 do
			if SGroup_Exists("sg_ork_skirmish"..i.."_"..y) == false or SGroup_IsEmpty("sg_ork_skirmish"..i.."_"..y) then
				--[[ create group ]]
				local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player6, "sg_ork_skirmish"..i.."_"..y, "ork_squad_slugga", "mkr_ork_source1", 1, rand)
				SGroup_AddLeaders("sg_ork_skirmish"..i.."_"..y)
				SGroup_AddGroup(g_sg_disorderID, sgroupID)
				SGroup_AddGroup(SGroup_CreateIfNotFound("sg_ork_skirmish"..i), sgroupID)
				--[[ lock it ]]
				Cpu_LockSGroupAcrossPlayers("sg_ork_skirmish"..i.."_"..y)
				Cmd_SetStance("sg_ork_skirmish"..i.."_"..y, STANCE_Attack)
				--[[ send it ]]
				Cmd_AttackMoveMarker("sg_ork_skirmish"..i.."_"..y, t_orkchargetarget[i])
				break
			end
		end
	end
	for i = 1, count do
		for y = 1, g_guarddif3 do
			if SGroup_Exists("sg_ork_skirmishig"..i.."_"..y) == false or SGroup_IsEmpty("sg_ork_skirmishig"..i.."_"..y) then
				--[[ create group ]]
				local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player4, "sg_ork_skirmishig"..i.."_"..y, "guard_squad_guardsmen", "mkr_ig_base6", 1, rand)
				SGroup_AddLeaders("sg_ork_skirmishig"..i.."_"..y)
				SGroup_AddGroup(SGroup_CreateIfNotFound("sg_ork_skirmish"..i), sgroupID)
				Cmd_SetStance("sg_ork_skirmishig"..i.."_"..y, STANCE_StandGround)
				--[[ send it ]]
				Cmd_AttackMoveMarker("sg_ork_skirmishig"..i.."_"..y, t_orkchargetarget[i])
				break
			end
		end
	end
	for i = 1, count do
		if SGroup_Exists("sg_ork_skirmish"..i) and SGroup_IsEmpty("sg_ork_skirmish"..i) == false then
			--[[ attack move ]]
			Cmd_AttackMoveMarker("sg_ork_skirmish"..i, t_orkchargetarget[i])
		end
	end
end

if EGroup_Exists("eg_ig_base6") and EGroup_IsEmpty("eg_ig_base6") then
	Rule_Remove(Rule_Disorder_OrkSkirmishLine)
end

end

--[[ Create a skirmish line of Chaos and Guard combatants without blowing the squad count ]] function Rule_Disorder_ChaosSkirmishLine()

local count = table.getn(t_chaoschargetarget)
if count > 0 then
	local rand = World_GetRand(5, 8)
	for i = 1, count do
		for y = 1, 2 do
			local rand = World_GetRand(5, 8)
			if SGroup_Exists("sg_chaos_skirmish"..i.."_"..y) == false or SGroup_IsEmpty("sg_chaos_skirmish"..i.."_"..y) then
				--[[ create group ]]
				local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player6, "sg_chaos_skirmish"..i.."_"..y, "chaos_squad_cultist", "mkr_chaos_source1", 1, rand)
				SGroup_AddLeaders("sg_chaos_skirmish"..i.."_"..y)
				SGroup_AddGroup(g_sg_disorderID, sgroupID)
				SGroup_AddGroup(SGroup_CreateIfNotFound("sg_chaos_skirmish"..i), sgroupID)
				--[[ lock it ]]
				Cpu_LockSGroupAcrossPlayers("sg_chaos_skirmish"..i.."_"..y)
				Cmd_SetStance("sg_chaos_skirmish"..i.."_"..y, STANCE_Attack)
				--[[ send it ]]
				Cmd_AttackMoveMarker("sg_chaos_skirmish"..i.."_"..y, t_chaoschargetarget[i])
				break
			end
		end
	end
	for i = 1, count do
		for y = 1, g_guarddif2 do
				if SGroup_Exists("sg_chaos_skirmishig"..i.."_"..y) == false or SGroup_IsEmpty("sg_chaos_skirmishig"..i.."_"..y) then
				--[[ create group ]]
				local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player4, "sg_chaos_skirmishig"..i.."_"..y, "guard_squad_guardsmen", "mkr_ig_base11", 1, rand)
				SGroup_AddLeaders("sg_chaos_skirmishig"..i.."_"..y)
				SGroup_AddGroup(SGroup_CreateIfNotFound("sg_chaos_skirmish"..i), sgroupID)
				Cmd_SetStance("sg_chaos_skirmishig"..i.."_"..y, STANCE_StandGround)
				--[[ send it ]]
				Cmd_AttackMoveMarker("sg_chaos_skirmishig"..i.."_"..y, t_chaoschargetarget[i])
				break
			end
		end
	end
	for i = 1, count do
		if SGroup_Exists("sg_chaos_skirmish"..i) and SGroup_IsEmpty("sg_chaos_skirmish"..i) == false then
			--[[ attack move ]]
			Cmd_AttackMoveMarker("sg_chaos_skirmish"..i, t_chaoschargetarget[i])
		end
	end
end

if EGroup_Exists("eg_ig_base11") and EGroup_IsEmpty("eg_ig_base11") then
	Rule_Remove(Rule_Disorder_ChaosSkirmishLine)
end

end

function Rule_Disorder_Generate()

--[[ the is to throw some randomness into how often the reinforcments spawn ]]
local randomturn = World_GetRand(1, 5)

if randomturn > 2 then
	if g_chaoscount < 2 then
		local sgroupID = MS04_Generate_Chaos(g_Player6, "sg_disorder_chaos"..g_time, "mkr_chaos_source1", 1, true, true)
		SGroup_AddGroup(g_sg_disorderID, sgroupID)

-- Cpu_LockSGroupAcrossPlayers("sg_disorder_chaos"..g_time) Cmd_SetStance("sg_disorder_chaos"..g_time, STANCE_Attack) Cmd_AttackMoveMarker("sg_disorder_chaos"..g_time, "mkr_chaosbase1") end end

if randomturn < 4 then
	if g_orkcount < 2 then
		local sgroupID = MS04_Generate_Orks(g_Player5, "sg_disorder_ork"..g_time, "mkr_ork_source1", 1, true, true)
		SGroup_AddGroup(g_sg_disorderID, sgroupID)

-- Cpu_LockSGroupAcrossPlayers("sg_disorder_ork"..g_time) Cmd_SetStance("sg_disorder_ork"..g_time, STANCE_Attack) Cmd_AttackMoveMarker("sg_disorder_ork"..g_time, "mkr_orkbase1") end end

end

function Rule_Disorder_Chaos_BaseAttack()

local i = 0
if table.getn(t_chaostargets) == 0 then
	Rule_Remove(Rule_Disorder_Chaos_BaseAttack)
else
	i = t_chaostargets[1]
	
	if EGroup_IsEmpty("eg_ig_base"..i) == false then
		local pos = EGroup_GetPosition(EGroup_FromName("eg_ig_base"..i))
		if SGroup_Exists("sg_chaos_baseattack") == false or SGroup_IsEmpty("sg_chaos_baseattack") then
			for y = 1, g_chaos_baseattack_dif do
				local sgroupID = MS04_Generate_Chaos(g_Player6, "sg_chaos_baseattack", "mkr_chaos_source1", g_chaos_baseattack_squaddif, true, true)
				SGroup_AddGroup(g_sg_disorderID, sgroupID)
				Cpu_LockSGroupAcrossPlayers("sg_chaos_baseattack")
				Cmd_SetStance("sg_chaos_baseattack", STANCE_Attack)
				Cmd_AttackMovePos("sg_chaos_baseattack", pos)
			end
		elseif SGroup_Exists("sg_chaos_baseattack") and SGroup_IsEmpty("sg_chaos_baseattack") == false then
			Cmd_AttackMovePos("sg_chaos_baseattack", pos)
		end
		
	elseif EGroup_IsEmpty("eg_ig_base"..i) then
		table.remove(t_chaostargets, 1)
	end
	
end

end

function Rule_Disorder_Ork_BaseAttack()

local i = 0
if table.getn(t_orktargets) == 0 then
	Rule_Remove(Rule_Disorder_Ork_BaseAttack)
else
	i = t_orktargets[1]
	
	if EGroup_IsEmpty("eg_ig_base"..i) == false then
		local pos = EGroup_GetPosition(EGroup_FromName("eg_ig_base"..i))
		if SGroup_Exists("sg_ork_baseattack") == false or SGroup_IsEmpty("sg_ork_baseattack") then
			for y = 1, g_ork_baseattack_dif do
				local sgroupID = MS04_Generate_Orks(g_Player6, "sg_ork_baseattack", "mkr_ork_source1", g_ork_baseattack_squaddif, true, true)
				SGroup_AddGroup(SGroup_CreateIfNotFound("sg_disorder"), sgroupID)
				Cpu_LockSGroupAcrossPlayers("sg_ork_baseattack")
				Cmd_SetStance("sg_ork_baseattack", STANCE_Attack)
				Cmd_AttackMovePos("sg_ork_baseattack", pos)
			end
		elseif SGroup_Exists("sg_ork_baseattack") and SGroup_IsEmpty("sg_ork_baseattack") == false then
			Cmd_AttackMovePos("sg_ork_baseattack", pos)
		end
		
	elseif EGroup_IsEmpty("eg_ig_base"..i) then
		table.remove(t_orktargets, 1)
	end
	
end

end

--[[ This is a function to present the convoy with a constant threat in addition to the threat from all of ther other sources ]] function Rule_Disorder_HarassConvoy()

if g_harasslast == true then
	g_harasslast = false
else
	local rand = World_GetRand(1, 3)
	--[[ random chance to attack and will only attack if the player is in control of the landraider ]]
	if rand < 3 then
		
		--[[ SUMMON SOME HORRORS RIGHT ON TOP OF THE CONVOY ]]
		if SGroup_Exists("sg_disoder_consummon") == false or SGroup_IsEmpty("sg_disoder_consummon") and SGroup_IsEmpty("sg_convoytransport") == false then
			local rand1 = World_GetRand(g_horrornum, g_horrornum+1)
			local rand2 = World_GetRand(5, 9)
			local pos = SGroup_GetPosition(SGroup_FromName("sg_convoytransport"))
			Util_CreateHorrorsAndSummon(g_Player6, "sg_disoder_consummon", pos, rand1, rand2)
			Cpu_LockSGroupAcrossPlayers("sg_disoder_consummon")
			
		end
		
		--[[ SUMMON SOME HORRORS RIGHT ON TOP OF THE CONVOY ]]
		if g_convoylock ~= nil and g_convoylock > 10 and g_playerSwitch == "g_Player1" 
		and (SGroup_Exists("sg_disoder_gensummon") == false or SGroup_CountSpawned(SGroup_FromName("sg_disoder_gensummon")) < 3 ) 
		and SGroup_IsEmpty("sg_guardleader") == false then
			local rand1 = World_GetRand(g_horrornum, g_horrornum+1)
			local rand2 = World_GetRand(5, 9)
			local pos = SGroup_GetPosition(SGroup_FromName("sg_guardleader"))
			Util_CreateHorrorsAndSummon(g_Player8, "sg_disoder_gensummon", pos, rand1, rand2)
			Cpu_LockSGroupAcrossPlayers("sg_disoder_gensummon")
			Cmd_AttackSGroup("sg_disoder_gensummon", "sg_guardleader")
		end
		if SGroup_Exists("sg_disoder_gensummon") and SGroup_IsEmpty("sg_disoder_gensummon") == false then
			Cmd_AttackSGroup("sg_disoder_gensummon", "sg_guardleader")
		end
		
		if g_playerSwitch == "g_Player1" and (SGroup_Exists("sg_disoder_gensummon") == false or SGroup_CountSpawned(SGroup_FromName("sg_disoder_gensummon")) < 5 )  and SGroup_IsEmpty("sg_convoytransport") == false then
			local sgroupID = MS04_Generate_Orks(g_Player5, "sg_disoder_conharass", "mkr_chaos_source1", 2, true, false)
			SGroup_AddGroup(SGroup_CreateIfNotFound("sg_disorder"), sgroupID)
			local sgroupID = MS04_Generate_Chaos(g_Player6, "sg_disoder_conharass", "mkr_ork_source1", 2, true, false)
			SGroup_AddGroup(SGroup_CreateIfNotFound("sg_disorder"), sgroupID)
			Cpu_LockSGroupAcrossPlayers("sg_disoder_conharass")
--			Cpu_LockSGroup(g_Player6, "sg_guard_1stchaos")

-- Cmd_SetStance("sg_disoder_conharass", STANCE_StandGround) Cmd_AttackSGroup("sg_disoder_conharass", "sg_convoytransport") elseif g_playerSwitch ~= "g_Player1" and (SGroup_Exists("sg_disoder_gensummon") == false or SGroup_CountSpawned(SGroup_FromName("sg_disoder_gensummon")) < 5 ) and SGroup_IsEmpty("sg_convoytransport") == false then local sgroupID = MS04_Generate_Orks(g_Player5, "sg_disoder_conharass", "mkr_chaos_source1", 1, true, false) SGroup_AddGroup(SGroup_CreateIfNotFound("sg_disorder"), sgroupID) local sgroupID = MS04_Generate_Chaos(g_Player6, "sg_disoder_conharass", "mkr_ork_source1", 1, true, false) SGroup_AddGroup(SGroup_CreateIfNotFound("sg_disorder"), sgroupID) Cpu_LockSGroupAcrossPlayers("sg_disoder_conharass") -- Cpu_LockSGroup(g_Player6, "sg_guard_1stchaos") -- Cmd_SetStance("sg_disoder_conharass", STANCE_StandGround) Cmd_AttackSGroup("sg_disoder_conharass", "sg_convoytransport") end

		g_harasslast = true
		
	end
end	

end

--[[ This is a function to present the Webway Assembly with a constant threat in addition to the threat from all of ther other sources ]] function Rule_Disorder_HarassWebway()

if g_harassweblast == true then
	g_harassweblast = false
else
	local rand = World_GetRand(1, 3)
	--[[ random chance to attack and will only attack if the player is in control of the landraider ]]
	if rand < 3 and g_playerSwitch == "g_Player2" then
		
		if (SGroup_Exists("sg_disoder_webharass") == false or SGroup_IsEmpty("sg_disoder_webharass")) and EGroup_IsEmpty("eg_soulshrine") == false then
			local sgroupID = MS04_Generate_Orks(g_Player5, "sg_disoder_webharass", "mkr_chaos_source1", g_orkwebway_dif, true, true)
			SGroup_AddGroup(SGroup_CreateIfNotFound("sg_disorder"), sgroupID)
			Cpu_LockSGroupAcrossPlayers("sg_disoder_webharass")
			Cmd_SetStance("sg_disoder_webharass", STANCE_StandGround)
			Cmd_AttackEGroup("sg_disoder_webharass", "eg_soulshrine")				
		end
		
		g_harassweblast = true
		
	end
end	

end

function Rule_Disorder_Steal()

--[[ want to steal groups from each player and send them to attack breach points ]]
--[[ must double check that squads I steal are not already part of another group ]]
local sgroupID0 = SGroup_CreateIfNotFound("_sg_disorder_orks")
SGroup_Clear(sgroupID0)
--get all orks squads
SGroup_AddGroup(sgroupID0, Player_GetSquads(g_Player5))
--if the group is not empty
if SGroup_IsEmpty("_sg_disorder_orks") == false then
--get the count
	local count = SGroup_CountSpawned(sgroupID0)
--if the count is greater than 5
	if count > 5 then
	--for each of the breach points
		for i = 5, 1, -1 do
			
			local sgroupID1 = SGroup_CreateIfNotFound("_sg_disorder_orks_charge"..i)
			SGroup_Clear(sgroupID1)
			
			local squadID = SGroup_GetSpawnedSquadAt(sgroupID0, i)
			SGroup_Add(sgroupID1, squadID)
			--remove that from the top group
			SGroup_Remove(sgroupID0, squadID)
			
			--send it in an attack move to the point
			Cpu_LockSGroupAcrossPlayers("_sg_disorder_orks_charge"..i)
			Cmd_SetStance("_sg_disorder_orks_charge"..i, STANCE_Hold)
			Cmd_SetMeleeStance("_sg_disorder_orks_charge"..i, MSTANCE_Assault)
			
			if i < 5 then
				Cmd_AttackMoveMarker("_sg_disorder_orks_charge"..i, t_orkchargetarget[i])
			elseif g_obj_clearpath == true and SGroup_IsEmpty("sg_convoytransport") == false then
				Cmd_AttackSGroup("_sg_disorder_orks_charge"..i, "sg_convoytransport")
			end
		end
	end
	
end

local sgroupID0 = SGroup_CreateIfNotFound("_sg_disorder_chaos")
SGroup_Clear(sgroupID0)
--get all orks squads
SGroup_AddGroup(sgroupID0, Player_GetSquads(g_Player6))
--if the group is not empty
if SGroup_IsEmpty("_sg_disorder_chaos") == false then
--get the count
	local count = SGroup_CountSpawned(sgroupID0)
--if the count is greater than 5
	if count > 5 then
	--for each of the breach points
		for i = 5, 1, -1 do
			
			local sgroupID1 = SGroup_CreateIfNotFound("_sg_disorder_chaos_charge"..i)
			SGroup_Clear(sgroupID1)
			
			local squadID = SGroup_GetSpawnedSquadAt(sgroupID0, i)
			SGroup_Add(sgroupID1, squadID)
			--remove that from the top group
			SGroup_Remove(sgroupID0, squadID)
			
			--send it in an attack move to the point
			Cpu_LockSGroupAcrossPlayers("_sg_disorder_chaos_charge"..i)
			Cmd_SetStance("_sg_disorder_chaos_charge"..i, STANCE_Hold)
			Cmd_SetMeleeStance("_sg_disorder_chaos_charge"..i, MSTANCE_Assault)
			
			if i < 5 then
				Cmd_AttackMoveMarker("_sg_disorder_chaos_charge"..i, t_chaoschargetarget[i])
			elseif g_obj_clearpath == true and SGroup_IsEmpty("sg_convoytransport") == false then
				Cmd_AttackSGroup("_sg_disorder_chaos_charge"..i, "sg_convoytransport")
			end
		end
	end
	
end

end


--[[ TITAN DEFENSE FORCES ]]


-- here we set about making the evil ones function Rule_IG_Kickoff()

Rule_AddOneShot(Rule_IG_MakeBases, 0)

end

function Rule_IG_MakeBases()

for i = 1, 15 do
	--[[ make the barracks ]]
	local pos = Marker_GetPosition(Marker_FromName("mkr_ig_base"..i, "basic_marker"))
	Entity_CreateBuildingPosition(g_Player4, "eg_ig_base"..i, "guard_infantry", pos, 1)
	EGroup_AddGroup(EGroup_CreateIfNotFound("eg_ig_infbases"), EGroup_FromName("eg_ig_base"..i))
end

for i = 1, 6 do
	--[[ make the barracks ]]
	local pos = Marker_GetPosition(Marker_FromName("mkr_ig_mech"..i, "basic_marker"))
	Entity_CreateBuildingPosition(g_Player4, "eg_ig_mech"..i, "guard_mechanized", pos, 1)
	EGroup_AddGroup(EGroup_CreateIfNotFound("eg_ig_mech"), EGroup_CreateIfNotFound("eg_ig_mech"..i))
end

for i = 1, 4 do
	--[[ make the turrets ]]
	local pos = Marker_GetPosition(Marker_FromName("mkr_ig_endturret"..i, "basic_marker"))
	Entity_CreateBuildingPosition(g_Player4, "eg_ig_endturret"..i, "guard_turret_heavy_bolter", pos, 1)
	EGroup_AddGroup(EGroup_CreateIfNotFound("eg_ig_endturrets"), EGroup_FromName("eg_ig_endturret"..i))
end

for i = 1, 9 do
	--[[ make the generators ]]
	local pos = Marker_GetPosition(Marker_FromName("mkr_ig_gen"..i, "basic_marker"))
	Entity_CreateBuildingPosition(g_Player4, "eg_ig_gen"..i, "guard_plasma_generator", pos, 1)
	EGroup_AddGroup(EGroup_CreateIfNotFound("eg_ig_gen"), EGroup_CreateIfNotFound("eg_ig_gen"..i))
end

t_infantrybasesAll = {true, true, true, true, true, true, true, true, true, true, true, true, true, true, true}

t_infantrybases = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
t_infantry = {
	{"guard", "guard_squad_guardsmen", {true, true, true, true, true, true, true, true, true, true, true, true, true, true, true}, 3},
	{"kasrkin", "guard_squad_kasrkin", {false, false, false, true, true, true, true, true, true, true, true, false, false, false, false}, 1},
	{"ogryn", "guard_squad_ogryns", {false, false, false, false, false, true, true, false, false, true, true, false, false, false, false}, 1},
}

Rule_AddOneShot(Rule_IG_CreateTurtleInfantry, 0)

end

--[[ this puts guardsmen inside the random barracks so that the barracks then fire ]] function Rule_IG_CreateTurtleInfantry()

for i = 1, 15 do
	if EGroup_IsEmpty("eg_ig_base"..i) == false then
		if SGroup_Exists("sg_ig_baseturtle"..i) == false then
			local rand1 =World_GetRand(1, 3) 
			local rand2 = World_GetRand(5, 9)
			local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player4, "sg_ig_baseturtle"..i, "guard_squad_guardsmen", "mkr_ig_base"..i, rand1, rand2)
			Cmd_EnterBuilding("sg_ig_baseturtle"..i, "eg_ig_base"..i)
		end
	end
end

end

--[[ this creates the infantry defenders ]] function Rule_IG_CreateInfantry()

for z = 1, table.getn(t_infantrybases) do
	local i = t_infantrybases[z]
	if i ~= 0 and EGroup_IsEmpty("eg_ig_base"..i) == false and EGroup_IsUnderAttack("eg_ig_base"..i, true) then
		
		for y = 1, g_guarddif1 do
			if t_infantry[y][3][i] == true and (SGroup_Exists("sg_ig_base"..t_infantry[y][1]..i) == false or SGroup_Count(SGroup_FromName("sg_ig_base"..t_infantry[y][1]..i)) < t_infantry[y][4]) then
				local rand = World_GetRand(5, 9)
				local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player4, "sg_ig_base"..t_infantry[y][1]..i, t_infantry[y][2], "mkr_ig_base"..i, 1, rand)
				SGroup_AddGroup(SGroup_CreateIfNotFound("sg_ig_infbases"), sgroupID)
				Cmd_SetStance("sg_ig_base"..t_infantry[y][1]..i, STANCE_StandGround)
				Cmd_AttackMoveMarker("sg_ig_base"..t_infantry[y][1]..i, "mkr_ig_rally"..i)
				break
			end
		end
		
	elseif i ~= 0 and EGroup_IsEmpty("eg_ig_base"..i) then
		t_infantrybases[z] = 0
	end
end

end

--[[ Regroup the Troops ]] function Rule_IG_InfantryRegroup()

for i = 1, 15 do
	for y = 1, 3 do
		if SGroup_Exists("sg_ig_base"..t_infantry[y][1]..i) and SGroup_IsEmpty("sg_ig_base"..t_infantry[y][1]..i) == false then
			Cmd_AttackMoveMarker("sg_ig_base"..t_infantry[y][1]..i, "mkr_ig_rally"..i)
		end
	end
end

end

function Rule_IG_InfantryReOutfit() --make a utility group local sgroupID_outfit = SGroup_CreateIfNotFound("_sg_outfit") SGroup_Clear(sgroupID_outfit) --check the outpost group local sgroupID = SGroup_CreateIfNotFound("sg_ig_infbases") local count = SGroup_CountSpawned(sgroupID) -- if the outpost group is not empty if count > 0 then for i = 1, count do -- we want a random squad out of the group local randsquad = World_GetRand(1, count) -- there is a chance this will crash local squadID = SGroup_GetSpawnedSquadAt(sgroupID, randsquad) -- add it to the group cause somethings are easier to do to a sgroup SGroup_Add(sgroupID_outfit, squadID) --check to see if there is a sergeant if SGroup_HasLeader("_sg_outfit", false) == false then SGroup_AddLeaders("_sg_outfit") SGroup_Clear(sgroupID_outfit) break end --check to see if they have any weapons if Squad_GetBlueprintName(squadID) == "guard_squad_guardsmen" and Squad_WeaponCount(squadID, "guard_grenade_launcher_guardsmen") == 0 and Squad_WeaponCount(squadID, "guard_plasma_gun_guardsmen") == 0 then local weapons = {"guard_grenade_launcher_guardsmen", "guard_plasma_gun_guardsmen", "guard_grenade_launcher_guardsmen"} local randweapon = World_GetRand(1, 2) Squad_ForceUpgradeWeapons(squadID, weapons[randweapon], randweapon) SGroup_Clear(sgroupID_outfit) break end --reinforce Cmd_ReinforceTrooper("_sg_outfit", 1) end end

if SGroup_IsEmpty("sg_ig_infbases") then
	Rule_Remove(Rule_IG_InfantryReOutfit)
end

end

function MS04_Generate_Guard(playerID, sgroupname, marker, squads, infantry, vehicle) if infantry == true then local blue = { "guard_squad_ogryns", "guard_squad_kasrkin", "guard_squad_guardsmen", "guard_squad_ogryns", "guard_squad_kasrkin", "guard_squad_guardsmen", } local num = {4, 6, 5, 2, 4, 8} local rand1 = World_GetRand(1, table.getn(blue)) Util_CreateSquadsAtMarkerEx(playerID, sgroupname, blue[rand1], marker, squads, num[rand1]) end if vehicle == true then local blue = { "guard_squad_basilisk", "guard_squad_chimera", "guard_squad_hellhound", "guard_squad_basilisk", "guard_squad_sentinel", "guard_squad_sentinel", "guard_squad_hellhound", } local num = {1, 1, 1, 1, 2, 1, 2} local rand1 = World_GetRand(1, table.getn(blue)) Util_CreateSquadsAtMarker(playerID, sgroupname, blue[rand1], marker, num[rand1]) end

return SGroup_FromName(sgroupname)

end

--[[ Here we load out the vehicles ]] function Rule_IG_CreateVehicles()

t_mech = {
	egroup = {"eg_ig_mech1", "eg_ig_mech1", "eg_ig_mech2", "eg_ig_mech2", "eg_ig_mech3", "eg_ig_mech3", "eg_ig_mech4", "eg_ig_mech4", "eg_ig_mech5", "eg_ig_mech5", "eg_ig_mech6", "eg_ig_mech6"},
	marker = {"mkr_ig_mech1", "mkr_ig_mech1", "mkr_ig_mech2", "mkr_ig_mech2", "mkr_ig_mech3", "mkr_ig_mech3", "mkr_ig_mech4", "mkr_ig_mech4", "mkr_ig_mech5", "mkr_ig_mech5", "mkr_ig_mech6", "mkr_ig_mech6"},
	rally = {"mkr_ig_rally13", "mkr_ig_mech14", "mkr_ig_rally3", "mkr_ig_rally4", "mkr_ig_rally5", "mkr_ig_rally6", "mkr_ig_rally8", "mkr_ig_rally9", "mkr_ig_rally7", "mkr_eldarcontrol", "mkr_ig_rally10", "mkr_ig_rally11"},
}

for i = 1, 12 do
	if EGroup_IsEmpty(t_mech.egroup[i]) == false then
		if SGroup_Exists("sg_ig_mech"..i) == false or SGroup_IsEmpty("sg_ig_mech"..i) then
			local rand1 =World_GetRand(1, 3) 
			local rand2 = World_GetRand(5, 9)
			local sgroupID = MS04_Generate_Guard(g_Player4, "sg_ig_mech"..i, t_mech.marker[i], 1, false, true)
			Cmd_AttackMoveMarker("sg_ig_mech"..i, t_mech.rally[i])
			break
		end
	end
end

if EGroup_IsEmpty("eg_ig_mech") then
	Rule_Remove(Rule_IG_CreateVehicles)
end

end


--[[ ELDAR ]]


function Rule_Eldar_Kickoff()

Rule_AddInterval(Rule_Eldar_FirstMasterObjective, 1)
Rule_AddInterval(Rule_Eldar_DetectCross, 10)
Rule_AddInterval(Rule_EndZone_Defense, 1)
Rule_AddInterval(Rule_Eldar_AllianceBroken, 1)
Rule_AddInterval(Rule_Eldar_EGGetAll, 3)
Rule_AddInterval(Rule_Eldar_SGGetAll, 2)
Rule_AddInterval(Rule_Eldar_WebwayAssemblyThrough, 5)
Rule_AddInterval(Rule_Eldar_PlateauCreate, 1)

Player_GrantResearch(g_Player2, "eldar_webway_gate_relocation_research")

end

function Rule_Eldar_EGGetAll()

local egroupID = EGroup_CreateIfNotFound("_eg_alleldar")
EGroup_Clear(egroupID)
EGroup_AddGroup(egroupID, Player_GetEntities(g_Player2))

end

function Rule_Eldar_SGGetAll()

local sgroupID = SGroup_CreateIfNotFound("_sg_alleldar")
SGroup_Clear(sgroupID)
SGroup_AddGroup(sgroupID, Player_GetSquads(g_Player2))

end

--[[ FARSEER TRACKING ]] function Rule_Eldar_FarseerReplace()

local blueprinttable = Util_MakeBlueprintTable("eldar_squad_farseer")

if g_farseercountdown == nil then
	g_farseercountdown = 0
end

if g_farseercountdown > 1 then
	g_farseercountdown = g_farseercountdown-1
elseif g_farseercountdown == 1 and EGroup_Exists("eg_soulshrine") and EGroup_IsEmpty("eg_soulshrine") == false then
	g_farseercountdown = 0
	local pos = EGroup_GetPosition(EGroup_FromName("eg_soulshrine"))
	local sgroupID = Util_CreateSquadsAtPosition(g_Player2, "sg_eldarleader", "eldar_squad_farseer", pos, 1)
	World_FXEventSquad("data:Art/Events/Unit_Upgrade_Morale_FX/Reinforce_Trooper", sgroupID)
	SGroup_AddGroup(SGroup_CreateIfNotFound("sg_eldar"), sgroupID)
	
	--[[ INTEL EVENT -- I am back ]]
	if Event_TimeSinceLast() > 10 then
		Util_StartIntel(EVENTS.IE_Eldar_ImBack)
	end
	EventCue_DoEvent( "recruit_commander", "/Races/Shared/Upgrade_weapon", "$42890", "$42892" )
	
elseif SGroup_Exists("sg_eldarleader") and (SGroup_IsEmpty("sg_eldarleader") or SGroup_ContainsBlueprints( "sg_eldarleader", blueprinttable, false) == false) and g_farseercountdown == 0 then
	g_farseercountdown = 6
	
	--[[ INTEL EVENT - I will return ]]
	
end

end

--[[ WEBWAY ASSEMBLY TRACKING ]] function Rule_Eldar_WebwayTracker()

if g_webwaycountdown == nil then
	g_webwaycountdown = 0
end

if g_webwaycountdown > 1 then
	g_webwaycountdown = g_webwaycountdown-1
elseif g_webwaycountdown == 0 and EGroup_Exists("eg_soulshrine") and EGroup_IsEmpty("eg_soulshrine") == false and EGroup_GetAvgHealth("eg_soulshrine") < .5 then
	g_webwaycountdown = 120
	
	Sound_PlayStinger("stinger_mso4_webwayassemblyatrisk")	
	
end

if EGroup_Exists("eg_soulshrine") and EGroup_IsEmpty("eg_soulshrine") then
	Rule_Remove(Rule_Eldar_WebwayTracker)
end

end

--[[ THE PLATEAU FOR THE PLAYER TO JUMP TO ]]

function Rule_Eldar_FirstMasterObjective()

if g_obj_switchsides == true then
	
	Rule_AddIntervalDelay(Rule_Objective_WebwayAssembly, 1, 1)
	
	Rule_Remove(Rule_Eldar_FirstMasterObjective)
	
end

end

--[[ THE PLATEAU FOR THE PLAYER TO JUMP TO ]]

function Rule_Eldar_PlateauCreate()

--create the outpost
Entity_CreateBuildingMarker(g_Player4, "eg_plat_guardbase", "guard_infantry", "mkr_plat_barrack", 1)

local target = {"guard1", "guard2", "guard3", "artillery"}
local blue = {"guard_squad_guardsmen", "guard_squad_guardsmen", "guard_squad_guardsmen", "guard_squad_basilisk"}
for i = 1, table.getn(target) do
	local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player4, "sg_platguard"..i, blue[i], "mkr_plat_barrack", 1, 5)
	SGroup_AddGroup(SGroup_CreateIfNotFound("sg_platguard"), sgroupID)

-- Cpu_LockSGroup(g_Player3, "sg_platguard"..i) Cmd_SetStance("sg_platguard"..i, STANCE_StandGround) Cmd_AttackMoveMarker( "sg_platguard"..i, "mkr_plat_"..target[i]) end for i = 1, 2 do Cmd_EnterBuilding("sg_platguard"..i, "eg_plat_guardbase") end

Rule_AddInterval(Rule_Eldar_PlateauMonitor, 3)

Rule_Remove(Rule_Eldar_PlateauCreate)

end

--[[ monitoring the plateau situation ]] function Rule_Eldar_PlateauMonitor()

if Prox_AnySquadNearMarker("_sg_alleldar", "mkr_plat_trigger") and g_eldarbreak ~= true then
	g_eldarbreak = true
	
	
elseif SGroup_IsEmpty("sg_platguard") and Prox_AnyEntityNearMarker("eg_soulshrine", "mkr_plat_trigger") then
	
	--[[ INTEL EVENT -- captured the plateau ]]
	g_obj_plateau = true  
	
	Rule_AddInterval(Rule_Disorder_HarassWebway, 45)
	
	Rule_Remove(Rule_Eldar_PlateauMonitor)
end	

end

--[[ are there any eldar on the IG side? ]] function Rule_Eldar_DetectCross()

for i = 1, 2 do
	if Prox_AnySquadNearMarker("_sg_alleldar", "mkr_igterritory"..i) then
		g_eldarcross = true
		Rule_AddOneShot(Rule_Eldar_BreakAlliance_Warning, 0)
		Rule_Remove(Rule_Eldar_DetectCross)
		break
	end
end

end

--[[ this function is here because I am assuming I will want a large chunk of stuff to happen when the Eldar first cross the line. - deg ]] function Rule_Eldar_BreakAlliance_Warning()

--[[ give the player 2 minutes to get their shit outa there before starting the check again
this is to ease the burden, ie. turning off the checker when we're not using it ]]
Util_StartIntel(EVENTS.IE_EldarSwitch_Warning)

g_alliancebreak = 0
Rule_AddInterval(Rule_Eldar_BreakAlliance, 2)

end

function Rule_Eldar_BreakAlliance() if g_alliancebreak < 60 then

	if g_eldarbreak == true then
		Rule_Remove(Rule_Eldar_BreakAlliance)
	end
	
	g_alliancebreak = g_alliancebreak+1
else
	local egroupID = EGroup_CreateIfNotFound("_eg_alleldar")
	EGroup_Clear(egroupID)
	EGroup_AddGroup(egroupID, Player_GetEntities(g_Player2))
	for i = 1, 2 do
		if Prox_AnyEntityNearMarker("_eg_alleldar", "mkr_igterritory"..i) then
			g_eldarbreak = true
			Rule_Remove(Rule_Eldar_BreakAlliance)
			break
		end
	end
end

end

function Rule_Eldar_AllianceBroken()

if g_eldarbreak == true then
	Util_StartIntel(EVENTS.IE_EldarSwitch_Break)
	
	Player_SetTeam(g_Player2, 2)
	
	World_EnablePlayerToPlayerFOW(g_Player2, g_Player3, false)
	
	Rule_Remove(Rule_Eldar_AllianceBroken)
end

end

--[[ ELDAR SAFE TO ENTER ]] function Rule_Eldar_DefeatEndSecurity()

if EGroup_IsEmpty("eg_ig_generators") then
	
	Rule_AddOneShot(Rule_Eldar_EndBypass, 0)
	
	if EGroup_IsEmpty("eg_ig_endturrets") == false then
		EGroup_SetPlayerOwner("eg_ig_endturrets", g_Player7)
	end
	
	if g_gateopened ~= true then
		Util_StartNIS(EVENTS.NIS_GateOpens)
		g_gateopened = true
	end
	
	g_obj_eldardefenses = true
	
	Rule_Check_Remove(Rule_EndZone_Defense)
	
	Rule_Remove(Rule_Eldar_DefeatEndSecurity)
end

end

--[[ ELDAR SAFE TO ENTER ]] function Rule_Eldar_WebwayAssemblyThrough()

if EGroup_IsEmpty("eg_soulshrine") == false and Prox_AnyEntityNearMarker("eg_soulshrine", "mkr_convoy_destFinal") then
	
	g_obj_eldardinside = true
	
	Rule_Remove(Rule_Eldar_WebwayAssemblyThrough)
end

end


--[[ WORLD TRIGGERS ]]


-- the following are various world events function Rule_WorldTriggers_Kickoff()

Rule_AddInterval(Rule_Breach_Advancement, 5)

end

--[[ ADVANCING THE BREACH ]] function Rule_Breach_Advancement()

if g_step == 2 then
	--[[ disorder ]]
	t_orkchargetarget = {"mkr_ig_rally3", "mkr_ig_rally4"}
	t_chaoschargetarget = {"mkr_ig_rally15", "mkr_ig_rally8" }
	
	g_horrornum = 2
	
	g_chaos_baseattack_dif = 1
	g_chaos_baseattack_squaddif = 2
	
	g_ork_baseattack_dif = 1
	g_ork_baseattack_squaddif = 2
	
	g_orkwebway_dif = 1
	
	
	g_step = 0
	
elseif g_step == 3 then
	--[[ disorder ]]
	t_orkchargetarget = {"mkr_ig_rally6", "mkr_ig_rally7"}
	t_chaoschargetarget = {"mkr_ig_rally10", "mkr_ig_rally11" }
	
	g_horrornum = 2
	
	g_chaos_baseattack_dif = 2
	g_chaos_baseattack_squaddif = 2
	
	g_ork_baseattack_dif = 2
	g_ork_baseattack_squaddif = 2
	
	g_orkwebway_dif = 2
	
	Rule_AddIntervalDelay(Rule_Autosave_ConvoyHalfway, 1, 3)
	
	g_step = 0
	
elseif g_step == 4 then
	--[[ disorder 
	t_orkchargetarget = {"mkr_ig_rally", "mkr_ig_rally"}
	t_chaoschargetarget = {"mkr_ig_rally", "mkr_ig_rally" }
	]]
	
	g_horrornum = 3
	
	g_chaos_baseattack_dif = 2
	g_chaos_baseattack_squaddif = 3
	
	g_ork_baseattack_dif = 2
	g_ork_baseattack_squaddif = 3
	
	g_orkwebway_dif = 3
	
	Rule_AddIntervalDelay(Rule_Autosave_ConvoyAlmostThere, 1, 3)
	
	g_step = 0
end

end

--[[ ENTER THE END AREA TOO EARLY ]] function Rule_EndZone_Defense()

local sgroupID = SGroup_CreateIfNotFound("_sg_endzone")
SGroup_Clear(sgroupID)
--[[ do player 1 first - the Imperial Guard ]]
Player_GetAllSquadsNearMarker(g_Player1, "_sg_endzone", "mkr_convoy_destFinal")
Player_GetAllSquadsNearMarker(g_Player3, "_sg_endzone", "mkr_convoy_destFinal")
Player_GetAllSquadsNearMarker(g_Player4, "_sg_endzone", "mkr_convoy_destFinal")
Player_GetAllSquadsNearMarker(g_Player5, "_sg_endzone", "mkr_convoy_destFinal")
Player_GetAllSquadsNearMarker(g_Player6, "_sg_endzone", "mkr_convoy_destFinal")
if SGroup_IsEmpty("_sg_endzone") == false then
	SGroup_SelfDestroy("_sg_endzone", true)
end
SGroup_Clear("_sg_endzone")

local egroupID = EGroup_CreateIfNotFound("_eg_endzone")
EGroup_Clear(egroupID)
--[[ do player 1 first - the Imperial Guard ]]
Player_GetAllEntitiesNearMarker(g_Player1, "_eg_endzone", "mkr_convoy_destFinal")
Player_GetAllEntitiesNearMarker(g_Player2, "_eg_endzone", "mkr_convoy_destFinal")
if EGroup_IsEmpty("_eg_endzone") == false then
	EGroup_SelfDestroy("_eg_endzone", true)
end

--[[ do player 2 - the Eldar - and if they are here and the are not broken yet, now they are! ]]
Player_GetAllSquadsNearMarker(g_Player2, "_sg_endzone", "mkr_convoy_destFinal")
if SGroup_IsEmpty("_sg_endzone") == false then
	SGroup_SelfDestroy("_sg_endzone", true)
	
	if g_endzonefirst ~= false then
		g_eldarcross = true
		g_eldarbreak = true
		Rule_AddOneShot(Rule_IE_EldarSwitch_EndWarning, 0)
		
		Rule_Check_Remove(Rule_Eldar_DetectCross)
		Rule_Check_Remove(Rule_Eldar_BreakAlliance)
		g_endzonefirst = false
	end
end

end


--[[ GAME OVER - Player Wins ]]

function Rule_EndGameWin() --[[ don't know if the player should be required to be playing as the winning side at that moment to actually win - deg ]] if g_playerHasWon then if g_obj_titancrew == true --[[and g_playerSwitch == "g_Player1"]] then Rule_RemoveAll() Util_StartNIS(EVENTS.NIS_Closing_Guard) elseif g_obj_relocate == true --[[and g_playerSwitch == "g_Player2"]] then Rule_RemoveAll() Util_StartNIS(EVENTS.NIS_Closing_Eldar) else end end

end

--[[ USED IN THE NIS ]] function Rule_NISCE_GuardRegen()

local source = {"mkr_NISCE_source1", "mkr_NISCE_source1", "mkr_NISCE_source2", "mkr_NISCE_source2"}
local target = {"mkr_NISCE_rally1", "mkr_NISCE_rally2", "mkr_NISCE_rally3", "mkr_NISCE_rally4"}

for i = 1, 4 do
	if SGroup_IsEmpty("sg_NISCEguard"..i) then
		local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player1, "sg_NISCEguard"..i, "guard_squad_guardsmen", source[i], 1, 8)
		SGroup_AddLeaders("sg_NISCEguard"..i)
		Cmd_MoveToMarker("sg_NISCEguard"..i, target[i])
	end
end

end

--[[ USED IN THE NIS ]] function Rule_NISCI_EldarRegen()

local source = {"mkr_NISCE_source1", "mkr_NISCE_source1", "mkr_NISCE_source2", "mkr_NISCE_source2"}
local target = {"mkr_NISCE_rally1", "mkr_NISCE_rally2", "mkr_NISCE_rally3", "mkr_NISCE_rally4"}

for i = 1, 4 do
	if SGroup_IsEmpty("sg_NISCIeldar"..i) then
		local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player1, "sg_NISCIeldar"..i, "eldar_guardian_squad", source[i], 1, 8)
		SGroup_AddLeaders("sg_NISCIeldar"..i)
		Cmd_MoveToMarker("sg_NISCIeldar"..i, target[i])
	end
end

end

--[[ USED IN THE NIS ]]

function Rule_NISCE_Disorder_Generate()

if Player_GetSquadCount(g_Player6) < 3 then
	local sgroupID = MS04_Generate_Chaos(g_Player6, "sg_disorder_chaos", "mkr_NISC_disorder", 1, true, false)
	Cmd_AttackMoveMarker("sg_disorder_chaos", "mkr_NISCE_rally3")
end

if Player_GetSquadCount(g_Player5) < 3 then
	local sgroupID = MS04_Generate_Orks(g_Player5, "sg_disorder_ork", "mkr_NISC_disorder", 1, true, false)
	Cmd_AttackMoveMarker("sg_disorder_ork", "mkr_NISCE_rally3")
end

end

function Rule_NISCI_Disorder_Generate()

if Player_GetSquadCount(g_Player6) < 3 then
	local sgroupID = MS04_Generate_Chaos(g_Player6, "sg_disorder_chaos", "mkr_NISC_disorder", 1, true, false)
	Cmd_AttackMoveMarker("sg_disorder_chaos", "mkr_NISCE_rally3")
end

if Player_GetSquadCount(g_Player5) < 3 then
	local sgroupID = MS04_Generate_Orks(g_Player5, "sg_disorder_ork", "mkr_NISC_disorder", 1, true, false)
	Cmd_AttackMoveMarker("sg_disorder_ork", "mkr_NISCE_rally3")
end

end


--[[ GAME OVER - Player Loses ]]

--[[ The Player Loses condition will be mission specific this version of the function detects if the player has lost their base and has no servitors left ]]

function Rule_EndGameLose()

g_building_exceptions1 = 
{
	"guard_listening_post",
	"guard_mines",
	"guard_tactica",
	"guard_mechanized",
	"guard_plasma_generator",
	"guard_thermo_plasma",
	"guard_turret_heavy_bolter",
	"guard_mars_pattern"
}


g_unit_exceptions1 = 
{
	"guard_squad_assassin",
	"guard_squad_baneblade",
	"guard_squad_basilisk",
	"guard_squad_basilisk_sp_mso2",
	"guard_squad_chimera",
	"guard_squad_chimera_sp_test",
	"guard_squad_command_squad",
	"guard_squad_commissar",
	"guard_squad_enginseer",
	"guard_squad_hellhound",
	"guard_squad_lemanruss",
	"guard_squad_priest",
	"guard_squad_psyker",
	"guard_squad_psyker_sp_msdc5",
	"guard_squad_sentinel",
	"guard_squad_enginseer_sp_transportable",
}
g_building_exceptions2 = 
{
	"guard_listening_post",
	"guard_mines",
	"guard_tactica",
	"guard_infantry",
	"guard_mechanized",
	"guard_plasma_generator",
	"guard_thermo_plasma",
	"guard_turret_heavy_bolter",
	"guard_mars_pattern"
}


g_unit_exceptions2 = 
{
	"guard_squad_assassin",
	"guard_squad_baneblade",
	"guard_squad_basilisk",
	"guard_squad_basilisk_sp_mso2",
	"guard_squad_chimera",
	"guard_squad_chimera_sp_test",
	"guard_squad_command_squad",
	"guard_squad_commissar",
	"guard_squad_guardsmen",
	"guard_squad_hellhound",
	"guard_squad_kasrkin",
	"guard_squad_lemanruss",
	"guard_squad_ogryns",
	"guard_squad_priest",
	"guard_squad_psyker",
	"guard_squad_psyker_sp_msdc5",
	"guard_squad_sentinel",
}

--[[ Lose because of Annihilation ]]
if g_handover == true then
	
	if g_psykicgateopen ~= true then
		if ( Player_HasBuildingsExcept(g_Player1, g_building_exceptions1) == false ) then
			if( Player_HasSquadsExcept(g_Player1, g_unit_exceptions1 ) == false ) then
				
				g_guarddead = true
				if g_eldardead == true then
					Rule_RemoveAll()
					
					Rule_AddOneShot(Rule_LastStanding_Guard_WeLost2, 0)
					
				elseif g_playerSwitch ~= "g_Player2" then
					
					--[[ Guard Cleanup ]]
					Rule_Check_Remove(Rule_EndGameLose_Guard)
					
					Rule_AddOneShot(Rule_IE_Loser_Guard2, .5)
					Rule_AddOneShot(Rule_Guard_WeLost_Cleanup, 1)
					
				end
				Rule_Remove( Rule_EndGameLose )
				
			end
		end
	end

--[[ if g_convoydisabled == true then if ( Player_HasBuildingsExcept(g_Player1, g_building_exceptions2) == false ) then if( Player_HasSquadsExcept(g_Player1, g_unit_exceptions2 ) == false ) then

				g_guarddead = true
				if g_eldardead == true then
					Rule_RemoveAll()
					
					Rule_AddOneShot(Rule_LastStanding_Guard_WeLost2, 0)
					
				elseif g_playerSwitch ~= "g_Player2" then
					
					--[[ Guard Cleanup ]]
					Rule_Check_Remove(Rule_EndGameLose_Guard)
					
					Rule_AddOneShot(Rule_IE_Loser_Guard2, .5)
					Rule_AddOneShot(Rule_Guard_WeLost_Cleanup, 1)
					
				end
				Rule_Remove( Rule_EndGameLose )
				
			end
		end
	end
]]	
end

--[[ Lose because of the Objectives Failed 
if g_playerHasWon == false then
	Rule_RemoveAll()
	Fade_Start(4, false)
	World_SetTeamWin( g_enemy, "" )
	Rule_AddIntervalEx( Rule_GameOver,5,1 )
	Rule_Remove( Rule_EndGameLose )
end
]]

end

function Rule_EndGameLose_Guard()

--[[ Lose because of the Objectives Failed ]]
if g_playerHasWon ~= true and SGroup_IsEmpty("sg_convoytransport") then
	g_guarddead = true
	if g_eldardead == true then
		Rule_RemoveAll()
		
		Rule_AddOneShot(Rule_LastStanding_Guard_WeLost, 0)
		
	elseif g_playerSwitch ~= "g_Player2" then
		
		--[[ Guard Cleanup ]]
		
		Rule_AddOneShot(Rule_IE_Loser_Guard, .5)
		Rule_AddOneShot(Rule_Guard_WeLost_Cleanup, 1)
		
	end
	Rule_Remove( Rule_EndGameLose_Guard )
end

end

function Rule_Guard_WeLost_Cleanup()

local sgroupID = SGroup_CreateIfNotFound("sg_guardloose")
SGroup_AddGroup(sgroupID, Player_GetSquads( g_Player1 ))
Cmd_MoveToMarker("sg_guardloose", "mkr_NISCE_rally1")

end

function Rule_LastStanding_Guard_WeLost()

Util_StartIntel(EVENTS.IE_LastStanding_GuardLost)
Fade_Start(4, false)

end

function Rule_LastStanding_Guard_WeLost2()

Util_StartIntel(EVENTS.IE_LastStanding_GuardLost2)
Fade_Start(4, false)

end

function Rule_EndGameLose_Eldar()

--[[ Lose because of the Objectives Failed ]]
if g_playerHasWon ~= true and EGroup_IsEmpty("eg_soulshrine") then
	g_eldardead = true 
	if g_guarddead == true then
		Rule_RemoveAll()
		
		Rule_AddOneShot(Rule_LastStanding_Eldar_WeLost, 0)
		
	elseif g_playerSwitch ~= "g_Player1" then
		
		--[[ Eldar Cleanup ]]
		
		Rule_AddOneShot(Rule_IE_Loser_Eldar, .5)
		Rule_AddOneShot(Rule_Eldar_WeLost_Cleanup, 1)
		
	end
	Rule_Remove( Rule_EndGameLose_Eldar )
end

end

function Rule_Eldar_WeLost_Cleanup()

local sgroupID = SGroup_CreateIfNotFound("sg_eldarloose")
SGroup_AddGroup(sgroupID, Player_GetSquads( g_Player2 ))
World_FXEventSquad("data:Art/Events/Unit_Upgrade_Morale_FX/Reinforce_Trooper", sgroupID)
SGroup_DeSpawn("sg_eldarloose")

Rule_AddOneShot(Rule_Eldar_WeLost_Kill, 1)

end

function Rule_Eldar_WeLost_Kill()

SGroup_DestroyAllSquads("sg_eldarloose")

end

function Rule_LastStanding_Eldar_WeLost()

Util_StartIntel(EVENTS.IE_LastStanding_EldarLost)
Fade_Start(4, false)

end

--[[ call this with an interval to ensure the mission ends ]] function Rule_GameOver() World_SetGameOver() end


--[[ OBJECTIVES ]]

--[[ IMPERIAL OBJECTIVES Rule_Objective_SwitchSides g_obj_switchsides Rule_Objective_TitanCrew g_obj_titancrew Rule_Objective_ClearPath g_obj_clearpath Rule_Objective_DefendBreach g_obj_defendbreach Rule_Objective_CommandBase g_obj_commandbase Rule_Objective_CaptureBuilding g_obj_capturebuilding Rule_Objective_FinalApproach g_obj_finalapproach ]]

--[[ SECONDARY OBJECTIVE - Switch Sides ]] function Rule_Objective_SwitchSides()

Objective_SwitchSides = { title_id = 831014, short_desc_id = 831015, help_tip_id = 000000 }

if Event_IsAnyRunning() == false and Objective_Exists(Objective_SwitchSides.title_id) == false then
	
	Util_WXP_ObjectiveCreate(Objective_SwitchSides, true)
	
elseif Event_IsAnyRunning() == false and g_obj_switchsides == true  then
	
	Util_ObjectiveComplete(Objective_SwitchSides.title_id)
	
	Rule_Remove(Rule_Objective_SwitchSides)
	
elseif Event_IsAnyRunning() == false and g_obj_switchsides == false then
	
	Util_ObjectiveFail(Objective_SwitchSides.title_id)
	
	Rule_Remove(Rule_Objective_SwitchSides)
	
end

end

--[[ MASTER OBJECTIVE - Deliver the Titan Crew ]] function Rule_Objective_TitanCrew()

Objective_TitanCrew = { title_id = 831000, short_desc_id = 831001, help_tip_id = 000000 }

if Event_IsAnyRunning() == false and Objective_Exists(Objective_TitanCrew.title_id) == false then
	
	Util_WXP_ObjectiveCreate(Objective_TitanCrew, true, g_Player1)
	
	Rule_AddIntervalDelay(Rule_Objective_ClearPath, 1, 10)
	
elseif Event_IsAnyRunning() == false and g_obj_titancrew == true  then
	
	Util_ObjectiveComplete(Objective_TitanCrew.title_id)
	
	--[[ IF THIS IS THE FINAL WIN CONDITION - uncomment out the following ]]
	g_playerHasWon = true
	
	Rule_Remove(Rule_Objective_TitanCrew)
	
elseif Event_IsAnyRunning() == false and g_obj_titancrew == false then
	
	Util_ObjectiveFail(Objective_TitanCrew.title_id)
	
	--[[ IF THIS IS THE FINAL WIN CONDITION - uncomment out the following ]]
	g_playerHasWon = false
	
	Rule_Remove(Rule_Objective_TitanCrew)
	
end

if g_guarddead == true then
	if Objective_TitanCrew ~= nil and Objective_Exists(Objective_TitanCrew.title_id) and Objective_GetState(Objective_TitanCrew.title_id) == OS_Incomplete then
		Util_ObjectiveFail(Objective_TitanCrew.title_id)
		Rule_Remove(Rule_Objective_TitanCrew)
	else
		Rule_Remove(Rule_Objective_TitanCrew)
	end
end

end

--[[ SUB OBJECTIVE - Clear the Path ]] function Rule_Objective_ClearPath()

if g_playerSwitch == "g_Player1" then
	
	Objective_ClearPath = { title_id = 831002, short_desc_id = 831003, help_tip_id = 000000 }
	
	if Event_IsAnyRunning() == false and Objective_Exists(Objective_ClearPath.title_id) == false then
		
		--[[ INTEL EVENT -- kill that first ]]
		Util_StartIntel(EVENTS.IE_Sturnn_ClearPath)
		Util_WXP_ObjectiveCreate(Objective_ClearPath, false, g_Player1)
		
		MSO4_SwitchPings_Add(g_Player1, "g_1stchaosbeaconID", "png_1stchaos", "mkr_firstchaos_ping")
		FOW_RevealMarker("mkr_firstchaos_ping", 20)
		g_objclearping = Objective_PingMarker(Objective_ClearPath.title_id, "mkr_firstchaos_ping", true, "attack")
		
		World_EnablePlayerToPlayerFOW(g_Player8, g_Player1, false)
		
	elseif Event_IsAnyRunning() == false and g_obj_clearpath == true  then
		
		Util_ObjectiveComplete(Objective_ClearPath.title_id)
		Objective_PingRemove(Objective_ClearPath.title_id, g_objclearping)
		
		World_EnablePlayerToPlayerFOW(g_Player8, g_Player1, true)
		
		if g_playerSwitch == "g_Player1" then
			--[[ INTEL EVENT - safe to move out ]]
			Util_StartIntel(EVENTS.IE_Sturnn_OurDuty)
		end
		
		MSO4_SwitchPings_RemoveBoth("g_1stchaosbeaconID", "png_1stchaos")
		
		if g_convoymove ~= true then
			
			--[[ trigger the next objective ]]
			if Rule_Exists(Rule_Objective_EscortConvoy) == false then
				Rule_AddIntervalDelay(Rule_Objective_EscortConvoy, 1, 5)
			end
			if Rule_Exists(Rule_Objective_CallConvoy) == false then
				Rule_AddIntervalDelay(Rule_Objective_CallConvoy, 1, 7)
			end
			
			--[[ start the convoy rolling ]]
			Rule_Check_AddInterval(Rule_TitanCrew_TransportMove_JunctA, 5, 10)
			Rule_Check_AddInterval(Rule_TitanCrew_ReachesDestination, 5, 10)
			
			--[[ this is the button stuff above that lets the General call the landraider over ]]
			g_convoyscarlock = false
			Rule_Check_AddInterval(Rule_ConvoyCall, 1)
			Rule_Check_AddInterval(Rule_ConvoyLockout, 1)
		end
		

-- Rule_AddIntervalDelay(Rule_Autosave_PathClear, 1, 3)

		Rule_Remove(Rule_Objective_ClearPath)
		
	elseif Event_IsAnyRunning() == false and g_obj_clearpath == false then
		
		Util_ObjectiveFail(Objective_ClearPath.title_id)
		Objective_PingRemove(Objective_ClearPath.title_id, g_objclearping)
		
		--[[ IF THIS IS THE FINAL WIN CONDITION - uncomment out the following
		g_playerHasWon = false
		]]
		
		Rule_Remove(Rule_Objective_ClearPath)
		
	end
	
end

if g_guarddead == true then
	if Objective_ClearPath ~= nil and Objective_Exists(Objective_ClearPath.title_id) and Objective_GetState(Objective_ClearPath.title_id) == OS_Incomplete then
		Util_ObjectiveFail(Objective_ClearPath.title_id)
		Objective_PingRemove(Objective_ClearPath.title_id, g_objclearping)
		Rule_Remove(Rule_Objective_ClearPath)
	else
		Rule_Remove(Rule_Objective_ClearPath)
	end
end

end

--[[ SUB OBJECTIVE - Escort Convoy to the Gate ]] function Rule_Objective_EscortConvoy()

if g_playerSwitch == "g_Player1" then
	
	Objective_EscortConvoy = { title_id = 831012, short_desc_id = 831013, help_tip_id = 000000 }
	
	if Event_IsAnyRunning() == false and Objective_Exists(Objective_EscortConvoy.title_id) == false then
		
		Util_WXP_ObjectiveSubCreate(Objective_EscortConvoy, Objective_TitanCrew.title_id)
		
		MSO4_SwitchPings_Add(g_Player1, "g_gatebeaconID", "png_gate", "mkr_convoy_destD")
		FOW_RevealMarker("mkr_convoy_destD", 10)
		g_objgateping = Objective_PingMarker(Objective_EscortConvoy.title_id, "mkr_convoy_destD", true, "default")
		
		--[[ add other objectives ]]
		Rule_AddIntervalDelay(Rule_Objective_OpenGates, 1, 30)
		if EGroup_Exists("eg_guard_1stchaos_brrks") and EGroup_IsEmpty("eg_guard_1stchaos_brrks") == false then
			Rule_AddIntervalDelay(Rule_Objective_DefendBreach, 1, 20)
		end
		
	elseif Event_IsAnyRunning() == false and g_obj_escortconvoy == true  then
		
		Util_ObjectiveComplete(Objective_EscortConvoy.title_id)
		Objective_PingRemove(Objective_EscortConvoy.title_id, g_objgateping)
		MSO4_SwitchPings_RemoveBoth("g_gatebeaconID", "png_gate")
		
		--[[ clean up the Gate Objectives ]]
		if Objective_OpenGateA ~= nil then
			g_obj_opengateA = false
		end
		if Objective_OpenGateB ~= nil then
			g_obj_opengateB = false
		end
		if Objective_OpenGateC ~= nil then
			g_obj_opengateC = false
		end
		
		--[[ rush the convoy ]]
		local sgroupID = SGroup_CreateIfNotFound("sg_rush_the_endzone")
		SGroup_AddGroup(sgroupID, Player_GetSquads( g_Player5 ))
		SGroup_AddGroup(sgroupID, Player_GetSquads( g_Player6 ))
		Cpu_LockSGroupAcrossPlayers("sg_rush_the_endzone")
		Cmd_SetStance("sg_rush_the_endzone", STANCE_Attack)
		Cmd_MoveToMarker("sg_rush_the_endzone", "mkr_convoy_destD")
		
		--[[ trigger the next objective ]]
		Rule_AddIntervalDelay(Rule_Objective_CaptureBuilding, 1, 5)
		
		Rule_Remove(Rule_Objective_EscortConvoy)
		
	elseif Event_IsAnyRunning() == false and g_obj_escortconvoy == false then
		
		Util_ObjectiveFail(Objective_EscortConvoy.title_id)
		Objective_PingRemove(Objective_EscortConvoy.title_id, g_objgateping)
		MSO4_SwitchPings_RemoveBoth("g_gatebeaconID", "png_gate")
		
		--[[ IF THIS IS THE FINAL WIN CONDITION - uncomment out the following
		g_playerHasWon = false
		]]
		
		Rule_Remove(Rule_Objective_EscortConvoy)
		
	end
	
end

if g_guarddead == true then
	if Objective_EscortConvoy ~= nil and Objective_Exists(Objective_EscortConvoy.title_id) and Objective_GetState(Objective_EscortConvoy.title_id) == OS_Incomplete then
		Util_ObjectiveFail(Objective_EscortConvoy.title_id)
		Objective_PingRemove(Objective_EscortConvoy.title_id, g_objgateping)
		MSO4_SwitchPings_RemoveBoth("g_gatebeaconID", "png_gate")
		Rule_Remove(Rule_Objective_EscortConvoy)
	else
		Rule_Remove(Rule_Objective_EscortConvoy)
	end
end

end

--[[ SUB OBJECTIVE - Capture the Control Building ]] function Rule_Objective_CaptureBuilding()

Objective_CaptureBuilding = { title_id = 831008, short_desc_id = 831009, help_tip_id = 000000 }

if Event_IsAnyRunning() == false and Objective_Exists(Objective_CaptureBuilding.title_id) == false then
	
	Util_WXP_ObjectiveSubCreate(Objective_CaptureBuilding, Objective_TitanCrew.title_id)
	MSO4_SwitchPings_Add(g_Player1, "g_controlbeaconID", "png_control", "mkr_guardcontrol")
	FOW_RevealMarker("mkr_guardcontrol", 20)
	g_objbaseping = Objective_PingMarker(Objective_CaptureBuilding.title_id, "mkr_guardcontrol", true, "default")
	
elseif Event_IsAnyRunning() == false and g_obj_capturebuilding == true  then
	
	g_genrespawn = "mkr_guardcontrol"
	
	Util_ObjectiveComplete(Objective_CaptureBuilding.title_id)
	Objective_PingRemove(Objective_CaptureBuilding.title_id, g_objbaseping)
	
	MSO4_SwitchPings_RemoveBoth("g_controlbeaconID", "png_control")
	
	if g_gateopened ~= true then
		Util_StartNIS(EVENTS.NIS_GateOpens)
		g_gateopened = true
	end
	
	Rule_AddIntervalDelay(Rule_Autosave_GuardUnlockGate, 1, 3)
	
	--[[ Trigger the next objective ]]
	Rule_AddIntervalDelay(Rule_Objective_FinalApproach, 1, 10)
	
	Rule_Remove(Rule_Objective_CaptureBuilding)
	
elseif Event_IsAnyRunning() == false and g_obj_capturebuilding == false then
	
	Util_ObjectiveFail(Objective_CaptureBuilding.title_id)
	Objective_PingRemove(Objective_CaptureBuilding.title_id, g_objbaseping)
	MSO4_SwitchPings_RemoveBoth("g_controlbeaconID", "png_control")
	
	--[[ IF THIS IS THE FINAL WIN CONDITION - uncomment out the following ]]
	g_playerHasWon = false
	
	Rule_Remove(Rule_Objective_CaptureBuilding)
	
end

if g_guarddead == true then
	if Objective_CaptureBuilding ~= nil and Objective_Exists(Objective_CaptureBuilding.title_id) and Objective_GetState(Objective_CaptureBuilding.title_id) == OS_Incomplete then
		Util_ObjectiveFail(Objective_CaptureBuilding.title_id)
		Objective_PingRemove(Objective_CaptureBuilding.title_id, g_objbaseping)
		MSO4_SwitchPings_RemoveBoth("g_controlbeaconID", "png_control")
		Rule_Remove(Rule_Objective_CaptureBuilding)
	else
		Rule_Remove(Rule_Objective_CaptureBuilding)
	end
end

end

--[[ SUB OBJECTIVE - Defend the final approach ]] function Rule_Objective_FinalApproach()

Objective_FinalApproach = { title_id = 831010, short_desc_id = 831011, help_tip_id = 000000 }

if Event_IsAnyRunning() == false and Objective_Exists(Objective_FinalApproach.title_id) == false then
	
	Util_WXP_ObjectiveSubCreate(Objective_FinalApproach, Objective_TitanCrew.title_id)
	MSO4_SwitchPings_Add(g_Player1, "g_finalbeacon_guardID", "png_final", "mkr_convoy_destFinal")
	FOW_RevealMarker("mkr_convoy_destFinal", 20)
	g_objfinalping = Objective_PingMarker(Objective_FinalApproach.title_id, "mkr_convoy_destFinal", true, "default")
	
elseif Event_IsAnyRunning() == false and g_obj_finalapproach == true  then
	
	Util_ObjectiveComplete(Objective_FinalApproach.title_id)
	MSO4_SwitchPings_RemoveBoth("g_finalbeacon_guardID", "png_final")
	Objective_PingRemove(Objective_FinalApproach.title_id, g_objfinalping)
	
	--[[ TRIGGER THE MASTER OBJECTIVE TO BE COMPLETE ]]
	g_obj_titancrew = true
	
	Rule_Remove(Rule_Objective_FinalApproach)
	
elseif Event_IsAnyRunning() == false and g_obj_finalapproach == false then
	
	Util_ObjectiveFail(Objective_FinalApproach.title_id)
	MSO4_SwitchPings_RemoveBoth("g_finalbeacon_guardID", "png_final")
	Objective_PingRemove(Objective_FinalApproach.title_id, g_objfinalping)
	
	--[[ IF THIS IS THE FINAL WIN CONDITION - uncomment out the following]]
	g_playerHasWon = false
	
	Rule_Remove(Rule_Objective_FinalApproach)
	
end

if g_guarddead == true then
	if Objective_FinalApproach ~= nil and Objective_Exists(Objective_FinalApproach.title_id) and Objective_GetState(Objective_FinalApproach.title_id) == OS_Incomplete then
		Util_ObjectiveFail(Objective_FinalApproach.title_id)
		MSO4_SwitchPings_RemoveBoth("g_finalbeacon_guardID", "png_final")
		Objective_PingRemove(Objective_FinalApproach.title_id, g_objfinalping)
		Rule_Remove(Rule_Objective_FinalApproach)
	else
		Rule_Remove(Rule_Objective_FinalApproach)
	end
end

end

--[[ SECONDARY MASTER OBJECTIVE - Open the Gates ]] function Rule_Objective_OpenGates()

if g_playerSwitch == "g_Player1" then
	
	Objective_OpenGates = { title_id = 831018, short_desc_id = 831019, help_tip_id = 000000 }
	
	if Event_IsAnyRunning() == false and Objective_Exists(Objective_OpenGates.title_id) == false then
		
		g_allgatesopen = 0
		
		Util_WXP_ObjectiveCreate(Objective_OpenGates, false, g_Player1)
		
		Rule_AddIntervalDelay(Rule_Objective_OpenGateA, 1, 1)
		Rule_AddInterval(Rule_ObjectiveOpenGatesCounter, 1)
		
	elseif Event_IsAnyRunning() == false and g_obj_opengates == true  then
		
		Util_ObjectiveComplete(Objective_OpenGates.title_id)
		
		Rule_Remove(Rule_Objective_OpenGates)
		
	elseif Event_IsAnyRunning() == false and (g_obj_opengates == false or g_obj_opengateA == false or g_obj_opengateB == false or g_obj_opengateC == false )then
		
		Util_ObjectiveFail(Objective_OpenGates.title_id)
		Rule_Remove(Rule_Objective_OpenGates)
		
	end
	
end

if g_guarddead == true then
	if Objective_OpenGates ~= nil and Objective_Exists(Objective_OpenGates.title_id) and Objective_GetState(Objective_OpenGates.title_id) == OS_Incomplete then
		Util_ObjectiveFail(Objective_OpenGates.title_id)
		Rule_Remove(Rule_Objective_OpenGates)
	else
		Rule_Remove(Rule_Objective_OpenGates)
	end
end

end

function Rule_ObjectiveOpenGatesCounter()

if g_allgatesopen == 3 then
	g_obj_opengates = true
	Rule_Remove(Rule_ObjectiveOpenGatesCounter)
end

end

--[[ SECONDARY SUB OBJECTIVE - Open Gate A ]] function Rule_Objective_OpenGateA()

if g_playerSwitch == "g_Player1" then
	
	Objective_OpenGateA = { title_id = 831020, short_desc_id = 831021, help_tip_id = 000000 }
	
	if Event_IsAnyRunning() == false and Objective_Exists(Objective_OpenGateA.title_id) == false then
		
		Util_WXP_ObjectiveSubCreate(Objective_OpenGateA, Objective_OpenGates.title_id)
		
		MSO4_SwitchPings_Add(g_Player1, "g_gateAbeaconID", "png_gateA", "mkr_gateA")
		FOW_RevealMarker("mkr_gateA", 20)
		g_objgateAping = Objective_PingMarker(Objective_OpenGateA.title_id, "mkr_gateA", true, "default")
		
	elseif Event_IsAnyRunning() == false and g_obj_opengateA == true  then
		
		g_allgatesopen = g_allgatesopen+1
		
		Util_ObjectiveComplete(Objective_OpenGateA.title_id)
		MSO4_SwitchPings_RemoveBoth("g_gateAbeaconID", "png_gateA")
		Objective_PingRemove(Objective_OpenGateA.title_id, g_objgateAping)
		
		Rule_AddIntervalDelay(Rule_Objective_OpenGateB, 1, 5)
		
		Rule_Remove(Rule_Objective_OpenGateA)
		
	elseif Event_IsAnyRunning() == false and g_obj_opengateA == false then
		
		Util_ObjectiveFail(Objective_OpenGateA.title_id)
		MSO4_SwitchPings_RemoveBoth("g_gateAbeaconID", "png_gateA")
		Objective_PingRemove(Objective_OpenGateA.title_id, g_objgateAping)
		Rule_Remove(Rule_Objective_OpenGateA)
		
	end
	
end

if g_guarddead == true then
	if Objective_OpenGateA ~= nil and Objective_Exists(Objective_OpenGateA.title_id) and Objective_GetState(Objective_OpenGateA.title_id) == OS_Incomplete then
		Util_ObjectiveFail(Objective_OpenGateA.title_id)
		MSO4_SwitchPings_RemoveBoth("g_gateAbeaconID", "png_gateA")
		Objective_PingRemove(Objective_OpenGateA.title_id, g_objgateAping)
		Rule_Remove(Rule_Objective_OpenGateA)
	else
		Rule_Remove(Rule_Objective_OpenGateA)
	end
end

end

--[[ SECONDARY SUB OBJECTIVE - Open Gate B ]] function Rule_Objective_OpenGateB()

if g_playerSwitch == "g_Player1" then
	
	Objective_OpenGateB = { title_id = 831022, short_desc_id = 831023, help_tip_id = 000000 }
	
	if Event_IsAnyRunning() == false and Objective_Exists(Objective_OpenGateB.title_id) == false then
		
		Util_WXP_ObjectiveSubCreate(Objective_OpenGateB, Objective_OpenGates.title_id)
		
		MSO4_SwitchPings_Add(g_Player1, "g_gateBbeaconID", "png_gateB", "mkr_gateB")
		FOW_RevealMarker("mkr_gateB", 20)
		g_objgateBping = Objective_PingMarker(Objective_OpenGateB.title_id, "mkr_gateB", true, "default")
		
	elseif Event_IsAnyRunning() == false and g_obj_opengateB == true  then
		
		g_allgatesopen = g_allgatesopen+1
		
		Util_ObjectiveComplete(Objective_OpenGateB.title_id)
		MSO4_SwitchPings_RemoveBoth("g_gateBbeaconID", "png_gateB")
		Objective_PingRemove(Objective_OpenGateB.title_id, g_objgateBping)
		
		Rule_AddIntervalDelay(Rule_Objective_OpenGateC, 1, 5)
		
		Rule_Remove(Rule_Objective_OpenGateB)
		
	elseif Event_IsAnyRunning() == false and g_obj_opengateB == false then
		
		Util_ObjectiveFail(Objective_OpenGateB.title_id)
		MSO4_SwitchPings_RemoveBoth("g_gateBbeaconID", "png_gateB")
		Objective_PingRemove(Objective_OpenGateB.title_id, g_objgateBping)
		Rule_Remove(Rule_Objective_OpenGateB)
		
	end
	
end

if g_guarddead == true then
	if Objective_OpenGateB ~= nil and Objective_Exists(Objective_OpenGateB.title_id) and Objective_GetState(Objective_OpenGateB.title_id) == OS_Incomplete then
		Util_ObjectiveFail(Objective_OpenGateB.title_id)
		MSO4_SwitchPings_RemoveBoth("g_gateBbeaconID", "png_gateB")
		Objective_PingRemove(Objective_OpenGateB.title_id, g_objgateBping)
		Rule_Remove(Rule_Objective_OpenGateB)
	else
		Rule_Remove(Rule_Objective_OpenGateB)
	end
end

end

--[[ SECONDARY SUB OBJECTIVE - Open Gate C ]] function Rule_Objective_OpenGateC()

if g_playerSwitch == "g_Player1" then
	
	Objective_OpenGateC = { title_id = 831024, short_desc_id = 831025, help_tip_id = 000000 }
	
	if Event_IsAnyRunning() == false and Objective_Exists(Objective_OpenGateC.title_id) == false then
		
		Util_WXP_ObjectiveSubCreate(Objective_OpenGateC, Objective_OpenGates.title_id)
		
		MSO4_SwitchPings_Add(g_Player1, "g_gateCbeaconID", "png_gateC", "mkr_gateC")
		FOW_RevealMarker("mkr_gateC", 20)
		g_objgateCping = Objective_PingMarker(Objective_OpenGateC.title_id, "mkr_gateC", true, "default")
		
	elseif Event_IsAnyRunning() == false and g_obj_opengateC == true  then
		
		g_allgatesopen = g_allgatesopen+1
		
		Util_ObjectiveComplete(Objective_OpenGateC.title_id)
		MSO4_SwitchPings_RemoveBoth("g_gateCbeaconID", "png_gateC")
		Objective_PingRemove(Objective_OpenGateC.title_id, g_objgateCping)
		
		Rule_Remove(Rule_Objective_OpenGateC)
		
	elseif Event_IsAnyRunning() == false and g_obj_opengateC == false then
		
		Util_ObjectiveFail(Objective_OpenGateC.title_id)
		MSO4_SwitchPings_RemoveBoth("g_gateCbeaconID", "png_gateC")
		Rule_Remove(Rule_Objective_OpenGateC)
		Objective_PingRemove(Objective_OpenGateC.title_id, g_objgateCping)
		
	end
	
end

if g_guarddead == true then
	if Objective_OpenGateC ~= nil and Objective_Exists(Objective_OpenGateC.title_id) and Objective_GetState(Objective_OpenGateC.title_id) == OS_Incomplete then
		Util_ObjectiveFail(Objective_OpenGateC.title_id)
		MSO4_SwitchPings_RemoveBoth("g_gateCbeaconID", "png_gateC")
		Objective_PingRemove(Objective_OpenGateC.title_id, g_objgateCping)
		Rule_Remove(Rule_Objective_OpenGateC)
	else
		Rule_Remove(Rule_Objective_OpenGateC)
	end
end

end

--[[ SECONDARY OBJECTIVE - Defend the Breach ]] function Rule_Objective_DefendBreach()

if g_playerSwitch == "g_Player1" then
	
	Objective_DefendBreach = { title_id = 831004, short_desc_id = 831005, help_tip_id = 000000 }
	
	if Event_IsAnyRunning() == false and Objective_Exists(Objective_DefendBreach.title_id) == false then
		
		--[[ INTEL EVENT - chaos broken through ]]
		Util_StartIntel(EVENTS.IE_Sturnn_ChaosBrokenDefense)
		
		Util_WXP_ObjectiveCreate(Objective_DefendBreach, false, g_Player1)
		
		MSO4_SwitchPings_Add(g_Player1, "g_1stbreachbeaconID", "png_1stbreach", "mkr_bigbreach")
		FOW_RevealMarker("mkr_bigbreach", 20)
		g_objbreachping = Objective_PingMarker(Objective_DefendBreach.title_id, "mkr_bigbreach", true, "default")
		
	elseif Event_IsAnyRunning() == false and g_obj_defendbreach == true  then
		
		Util_ObjectiveComplete(Objective_DefendBreach.title_id)
		
		MSO4_SwitchPings_RemoveBoth("g_1stbreachbeaconID", "png_1stbreach")
		Objective_PingRemove(Objective_DefendBreach.title_id, g_objbreachping)
		
		Rule_Remove(Rule_Objective_DefendBreach)
		
	elseif Event_IsAnyRunning() == false and g_obj_defendbreach == false then
		
		Util_ObjectiveFail(Objective_DefendBreach.title_id)
		
		MSO4_SwitchPings_RemoveBoth("g_1stbreachbeaconID", "png_1stbreach")
		Objective_PingRemove(Objective_DefendBreach.title_id, g_objbreachping)
		
		Rule_Remove(Rule_Objective_DefendBreach)
		
	end
	
end

if g_guarddead == true then
	if Objective_DefendBreach ~= nil and Objective_Exists(Objective_DefendBreach.title_id) and Objective_GetState(Objective_DefendBreach.title_id) == OS_Incomplete then
		Util_ObjectiveFail(Objective_DefendBreach.title_id)
		Objective_PingRemove(Objective_DefendBreach.title_id, g_objbreachping)
		Rule_Remove(Rule_Objective_DefendBreach)
	else
		Rule_Remove(Rule_Objective_DefendBreach)
	end
end

end

--[[ SECONDARY OBJECTIVE - Take Command of the Base ]] function Rule_Objective_CommandBase()

if g_playerSwitch == "g_Player1" then
	
	Objective_CommandBase = { title_id = 831006, short_desc_id = 831007, help_tip_id = 000000 }
	
	if Event_IsAnyRunning() == false and Objective_Exists(Objective_CommandBase.title_id) == false then
		
		Util_WXP_ObjectiveCreate(Objective_CommandBase, false, g_Player1)
		
		MSO4_SwitchPings_Add(g_Player1, "g_1stbasebeaconID", "png_1stbase", "mkr_guard_1stbase1")
		FOW_RevealMarker("mkr_guard_1stbase1", 20)
		g_objbaseping = Objective_PingMarker(Objective_CommandBase.title_id, "mkr_guard_1stbase1", true, "default")
		
	elseif Event_IsAnyRunning() == false and g_obj_commandbase == true  then
		
		g_genrespawn = "mkr_guard_1stbase1"
		
		Util_ObjectiveComplete(Objective_CommandBase.title_id)
		
		MSO4_SwitchPings_RemoveBoth("g_1stbasebeaconID", "png_1stbase")
		Objective_PingRemove(Objective_CommandBase.title_id, g_objbaseping)
		
		Rule_AddIntervalDelay(Rule_Autosave_ReclaimBase, 1, 3)
		
		Rule_Remove(Rule_Objective_CommandBase)
		
	elseif Event_IsAnyRunning() == false and g_obj_commandbase == false then
		
		Util_ObjectiveFail(Objective_CommandBase.title_id)
		
		MSO4_SwitchPings_RemoveBoth("g_1stbasebeaconID", "png_1stbase")
		Objective_PingRemove(Objective_CommandBase.title_id, g_objbaseping)
		
		Rule_Remove(Rule_Objective_CommandBase)
		
	end
	
end

if g_guarddead == true then
	if Objective_CommandBase ~= nil and Objective_Exists(Objective_CommandBase.title_id) and Objective_GetState(Objective_CommandBase.title_id) == OS_Incomplete then
		Util_ObjectiveFail(Objective_CommandBase.title_id)
		MSO4_SwitchPings_RemoveBoth("g_1stbasebeaconID", "png_1stbase")
		Objective_PingRemove(Objective_CommandBase.title_id, g_objbaseping)
		Rule_Remove(Rule_Objective_CommandBase)
	else
		Rule_Remove(Rule_Objective_CommandBase)
	end
end

end

--[[ SECONDARY OBJECTIVE - Call the Convoy ]] function Rule_Objective_CallConvoy()

if g_playerSwitch == "g_Player1" then
	
	Objective_CallConvoy = { title_id = 831016, short_desc_id = 831017, help_tip_id = 000000 }
	
	if Event_IsAnyRunning() == false and Objective_Exists(Objective_CallConvoy.title_id) == false then
		
		Util_WXP_ObjectiveCreate(Objective_CallConvoy, false, g_Player1)
		
	elseif Event_IsAnyRunning() == false and g_obj_callconvoy == true  then
		
		Util_ObjectiveComplete(Objective_CallConvoy.title_id)
		Rule_Remove(Rule_Objective_CallConvoy)
		
	elseif Event_IsAnyRunning() == false and g_obj_callconvoy == false then
		
		Util_ObjectiveFail(Objective_CallConvoy.title_id)
		Rule_Remove(Rule_Objective_CallConvoy)
		
	end
	
end

if g_guarddead == true then
	if Objective_CallConvoy ~= nil and Objective_Exists(Objective_CallConvoy.title_id) and Objective_GetState(Objective_CallConvoy.title_id) == OS_Incomplete then
		Util_ObjectiveFail(Objective_CallConvoy.title_id)
		Rule_Remove(Rule_Objective_CallConvoy)
	else
		Rule_Remove(Rule_Objective_CallConvoy)
	end
end

end

--[[ Eldar Objectives ]]

--[[ MASTER OBJECTIVE - Eldar Relocate Soul Stone ]] function Rule_Objective_WebwayAssembly()

Objective_WebwayAssembly = { title_id = 831110, short_desc_id = 831111, help_tip_id = 000000 }

if Event_IsAnyRunning() == false and Objective_Exists(Objective_WebwayAssembly.title_id) == false then
	
	Util_WXP_ObjectiveCreate(Objective_WebwayAssembly, true, g_Player2)
	Util_StartIntel(EVENTS.IE_Eldar_RelocateAssembly)
	
	Rule_AddIntervalDelay(Rule_Objective_ScoutEntrance, 1, 2)
	
elseif Event_IsAnyRunning() == false and g_obj_relocate == true  then
	
	Util_ObjectiveComplete(Objective_WebwayAssembly.title_id)
	Rule_AddOneShot(Rule_IE_Objective_WebwayAssemblyComplete, 0)
	
	MSO4_SwitchPings_RemoveBoth("g_finalbeacon_eldarID", "png_final")
	
	--[[ IF THIS IS THE FINAL WIN CONDITION - uncomment out the following]]
	g_playerHasWon = true
	
	Rule_Remove(Rule_Objective_WebwayAssembly)
	
elseif Event_IsAnyRunning() == false and g_obj_relocate == false then
	
	Util_ObjectiveFail(Objective_WebwayAssembly.title_id)
	Rule_AddOneShot(Rule_IE_Objective_WebwayAssemblyFailed, 0)
	
	MSO4_SwitchPings_RemoveBoth("g_finalbeacon_eldarID", "png_final")
	
	--[[ IF THIS IS THE FINAL WIN CONDITION - uncomment out the following]]
	g_playerHasWon = false
	
	Rule_Remove(Rule_Objective_WebwayAssembly)
	
end

if g_eldardead == true then
	if Objective_WebwayAssembly ~= nil and Objective_Exists(Objective_WebwayAssembly.title_id) and Objective_GetState(Objective_WebwayAssembly.title_id) == OS_Incomplete then
		Util_ObjectiveFail(Objective_WebwayAssembly.title_id)
		Rule_AddOneShot(Rule_IE_Objective_WebwayAssemblyFailed, 0)
		MSO4_SwitchPings_RemoveBoth("g_finalbeacon_eldarID", "png_final")
		Rule_Remove(Rule_Objective_WebwayAssembly)
	else
		Rule_Remove(Rule_Objective_WebwayAssembly)
	end
end

end

--[[ SUB OBJECTIVE - Scout Entrance ]] function Rule_Objective_ScoutEntrance()

if g_playerSwitch == "g_Player2" then
	
	Objective_ScoutEntrance = { title_id = 831121, short_desc_id = 831122, help_tip_id = 000000 }
	
	if Event_IsAnyRunning() == false and Objective_Exists(Objective_ScoutEntrance.title_id) == false then
		
		Util_WXP_ObjectiveSubCreate(Objective_ScoutEntrance, Objective_WebwayAssembly.title_id)
		Util_StartIntel(EVENTS.IE_Eldar_ScoutFirst)
		
		MSO4_SwitchPings_Add(g_Player2, "g_scoutbeaconID", "png_scout", "mkr_convoy_destD")
		FOW_RevealMarker("mkr_convoy_destD", 20)
		g_objscoutping = Objective_PingMarker(Objective_ScoutEntrance.title_id, "mkr_convoy_destD", true, "default")
		
		Rule_AddInterval(Rule_Objective_ScoutEntrance_Check, 3)
		
		--[[ add objective ]]
		Rule_AddIntervalDelay(Rule_Objective_TakePlateau, 1, 30)
		
	elseif Event_IsAnyRunning() == false and g_obj_scoutgate == true  then
		
		Util_ObjectiveComplete(Objective_ScoutEntrance.title_id)
		
		--[[ does this turn the guard against the eldar? ]]
		g_eldarbreak = true
		
		MSO4_SwitchPings_RemoveBoth("g_scoutbeaconID", "png_scout")
		Objective_PingRemove(Objective_ScoutEntrance.title_id, g_objscoutping)
		
		Rule_AddIntervalDelay(Rule_Objective_DestroyDefenses, 1, 2)
		
		Rule_Remove(Rule_Objective_ScoutEntrance)
		
	elseif Event_IsAnyRunning() == false and g_obj_scoutgate == false then
		
		Util_ObjectiveFail(Objective_ScoutEntrance.title_id)
		Objective_PingRemove(Objective_ScoutEntrance.title_id, g_objscoutping)
		MSO4_SwitchPings_RemoveBoth("g_scoutbeaconID", "png_scout")
		
		Rule_Remove(Rule_Objective_ScoutEntrance)
		
	end
	
end

if g_eldardead == true then
	if Objective_ScoutEntrance ~= nil and Objective_Exists(Objective_ScoutEntrance.title_id) and Objective_GetState(Objective_ScoutEntrance.title_id) == OS_Incomplete then
		Util_ObjectiveFail(Objective_ScoutEntrance.title_id)
		Objective_PingRemove(Objective_ScoutEntrance.title_id, g_objscoutping)
		MSO4_SwitchPings_RemoveBoth("g_scoutbeaconID", "png_scout")
		Rule_Remove(Rule_Objective_ScoutEntrance)
	else
		Rule_Remove(Rule_Objective_ScoutEntrance)
	end
end

end

function Rule_Objective_ScoutEntrance_Check()

if Prox_AnySquadNearMarker("_sg_alleldar", "mkr_convoy_destD") then
	g_obj_scoutgate = true
	Rule_Remove(Rule_Objective_ScoutEntrance_Check)
end

end

--[[ SUB OBJECTIVE - Destroy Defenses ]] function Rule_Objective_DestroyDefenses()

if g_playerSwitch == "g_Player2" then
	
	Objective_DestroyDefenses = { title_id = 831117, short_desc_id = 831118, help_tip_id = 000000 }
	
	if Event_IsAnyRunning() == false and Objective_Exists(Objective_DestroyDefenses.title_id) == false then
		
		Util_WXP_ObjectiveSubCreate(Objective_DestroyDefenses, Objective_WebwayAssembly.title_id)
		Util_StartIntel(EVENTS.IE_Eldar_CaptureMechanics)
		
		MSO4_SwitchPings_Add(g_Player2, "g_genbeaconID", "png_defenses", "mkr_eldarcontrol")
		FOW_RevealMarker("mkr_eldarcontrol", 20)
		g_objdefping = Objective_PingMarker(Objective_DestroyDefenses.title_id, "mkr_eldarcontrol", true, "attack")
		
		Rule_AddInterval(Rule_Eldar_DefeatEndSecurity, 1)
		
	elseif Event_IsAnyRunning() == false and g_obj_eldardefenses == true  then
		
		Util_ObjectiveComplete(Objective_DestroyDefenses.title_id)
		
		MSO4_SwitchPings_RemoveBoth("g_genbeaconID", "png_defenses")
		Objective_PingRemove(Objective_DestroyDefenses.title_id, g_objdefping)
		
		Rule_AddIntervalDelay(Rule_Objective_RelocateInside, 1, 2)
		Rule_AddIntervalDelay(Rule_Autosave_EldarUnlockGate, 1, 3)
		
		Rule_Remove(Rule_Objective_DestroyDefenses)
		
	elseif Event_IsAnyRunning() == false and g_obj_eldardefenses == false then
		
		Util_ObjectiveFail(Objective_DestroyDefenses.title_id)
		MSO4_SwitchPings_RemoveBoth("g_genbeaconID", "png_defenses")
		Objective_PingRemove(Objective_DestroyDefenses.title_id, g_objdefping)
		
		Rule_Remove(Rule_Objective_DestroyDefenses)
		
	end
	
end

if g_eldardead == true then
	if Objective_DestroyDefenses ~= nil and Objective_Exists(Objective_DestroyDefenses.title_id) and Objective_GetState(Objective_DestroyDefenses.title_id) == OS_Incomplete then
		Util_ObjectiveFail(Objective_DestroyDefenses.title_id)
		MSO4_SwitchPings_RemoveBoth("g_genbeaconID", "png_defenses")
		Objective_PingRemove(Objective_DestroyDefenses.title_id, g_objdefping)
		Rule_Remove(Rule_Objective_DestroyDefenses)
	else
		Rule_Remove(Rule_Objective_DestroyDefenses)
	end
end

end

--[[ SUB OBJECTIVE - Relocate Inside ]] function Rule_Objective_RelocateInside()

if g_playerSwitch == "g_Player2" then
	
	Objective_RelocateInside = { title_id = 831113, short_desc_id = 831114, help_tip_id = 000000 }
	
	if Event_IsAnyRunning() == false and Objective_Exists(Objective_RelocateInside.title_id) == false then
		
		Util_WXP_ObjectiveSubCreate(Objective_RelocateInside, Objective_WebwayAssembly.title_id)
		Util_StartIntel(EVENTS.IE_Eldar_GateisOurs)
		
		MSO4_SwitchPings_Add(g_Player2, "g_finalbeacon_eldarID", "png_final", "mkr_convoy_destFinal")
		FOW_RevealMarker("mkr_convoy_destFinal", 20)
		g_objrelping = Objective_PingMarker(Objective_RelocateInside.title_id, "mkr_convoy_destFinal", true, "default")
		
	elseif Event_IsAnyRunning() == false and g_obj_eldardinside == true  then
		
		Util_ObjectiveComplete(Objective_RelocateInside.title_id)
		g_obj_relocate = true
		
		MSO4_SwitchPings_RemoveBoth("g_finalbeacon_eldarID", "png_final")
		Objective_PingRemove(Objective_RelocateInside.title_id, g_objrelping)
		
		Rule_Remove(Rule_Objective_RelocateInside)
		
	elseif Event_IsAnyRunning() == false and g_obj_eldardinside == false then
		
		Util_ObjectiveFail(Objective_RelocateInside.title_id)
		MSO4_SwitchPings_RemoveBoth("g_finalbeacon_eldarID", "png_final")
		Objective_PingRemove(Objective_RelocateInside.title_id, g_objrelping)
		
		Rule_Remove(Rule_Objective_RelocateInside)
		
	end
	
end

if g_eldardead == true then
	if Objective_RelocateInside ~= nil and Objective_Exists(Objective_RelocateInside.title_id) and Objective_GetState(Objective_RelocateInside.title_id) == OS_Incomplete then
		Util_ObjectiveFail(Objective_RelocateInside.title_id)
		MSO4_SwitchPings_RemoveBoth("g_finalbeacon_eldarID", "png_final")
		Objective_PingRemove(Objective_RelocateInside.title_id, g_objrelping)
		Rule_Remove(Rule_Objective_RelocateInside)
	else
		Rule_Remove(Rule_Objective_RelocateInside)
	end
end

end

--[[ SECONDARY OBJECTIVE - Take the Plateau ]] function Rule_Objective_TakePlateau()

if g_playerSwitch == "g_Player2" then
	
	Objective_TakePlateau = { title_id = 831115, short_desc_id = 831116, help_tip_id = 000000 }
	
	if Event_IsAnyRunning() == false and Objective_Exists(Objective_TakePlateau.title_id) == false then
		
		Util_WXP_ObjectiveCreate(Objective_TakePlateau, false, g_Player2)
		Util_StartIntel(EVENTS.IE_Eldar_PerfectSpot)
		MSO4_SwitchPings_Add(g_Player2, "g_plateaubeaconID", "png_plateau", "mkr_plat_trigger")
		FOW_RevealMarker("mkr_plat_trigger", 20)
		g_objplatping = Objective_PingMarker(Objective_TakePlateau.title_id, "mkr_plat_trigger", true, "default")
		
	elseif Event_IsAnyRunning() == false and g_obj_plateau == true  then
		
		Util_ObjectiveComplete(Objective_TakePlateau.title_id)
		
		Rule_AddIntervalDelay(Rule_Objective_TakePoint, 1, 2)
		Rule_AddIntervalDelay(Rule_Autosave_PlateauClear, 1, 5)
		
		MSO4_SwitchPings_RemoveBoth("g_plateaubeaconID", "png_plateau")
		Objective_PingRemove(Objective_TakePlateau.title_id, g_objplatping)
		
		Rule_Remove(Rule_Objective_TakePlateau)
		
	elseif Event_IsAnyRunning() == false and g_obj_plateau == false then
		
		Util_ObjectiveFail(Objective_TakePlateau.title_id)
		MSO4_SwitchPings_RemoveBoth("g_plateaubeaconID", "png_plateau")
		Objective_PingRemove(Objective_TakePlateau.title_id, g_objplatping)
		Rule_Remove(Rule_Objective_TakePlateau)
		
	end
	
end

if g_eldardead == true then
	if Objective_TakePlateau ~= nil and Objective_Exists(Objective_TakePlateau.title_id) and Objective_GetState(Objective_TakePlateau.title_id) == OS_Incomplete then
		Util_ObjectiveFail(Objective_TakePlateau.title_id)
		MSO4_SwitchPings_RemoveBoth("g_plateaubeaconID", "png_plateau")
		Objective_PingRemove(Objective_TakePlateau.title_id, g_objplatping)
		Rule_Remove(Rule_Objective_TakePlateau)
	else
		Rule_Remove(Rule_Objective_TakePlateau)
	end
end

end

--[[ SECONDARY OBJECTIVE - Take the Point ]] function Rule_Objective_TakePoint()

if g_playerSwitch == "g_Player2" then
	
	Objective_TakePoint = { title_id = 831119, short_desc_id = 831120, help_tip_id = 000000 }
	
	if Event_IsAnyRunning() == false and Objective_Exists(Objective_TakePoint.title_id) == false then
		
		Util_WXP_ObjectiveCreate(Objective_TakePoint, false, g_Player2)
		MSO4_SwitchPings_Add(g_Player2, "g_pointbeaconID", "png_point", "mkr_eldar_relocate2")
		FOW_RevealMarker("mkr_eldar_relocate2", 20)
		g_objpointping = Objective_PingMarker(Objective_TakePoint.title_id, "mkr_eldar_relocate2", true, "default")
		
		Rule_AddInterval(Rule_Objective_TakePoint_Check, 3)
		
	elseif Event_IsAnyRunning() == false and g_obj_takepoint == true  then
		
		Util_ObjectiveComplete(Objective_TakePoint.title_id)
		MSO4_SwitchPings_RemoveBoth("g_pointbeaconID", "png_point")
		Objective_PingRemove(Objective_TakePoint.title_id, g_objpointping)
		
		Rule_Remove(Rule_Objective_TakePoint)
		
	elseif Event_IsAnyRunning() == false and g_obj_takepoint == false then
		
		Util_ObjectiveFail(Objective_TakePoint.title_id)
		Objective_PingRemove(Objective_TakePoint.title_id, g_objpointping)
		
		Rule_Remove(Rule_Objective_TakePoint)
		
	end
	
end

if g_eldardead == true then
	if Objective_TakePoint ~= nil and Objective_Exists(Objective_TakePoint.title_id) and Objective_GetState(Objective_TakePoint.title_id) == OS_Incomplete then
		Util_ObjectiveFail(Objective_TakePoint.title_id)
		Objective_PingRemove(Objective_TakePoint.title_id, g_objpointping)
		Rule_Remove(Rule_Objective_TakePoint)
	else
		Rule_Remove(Rule_Objective_TakePoint)
	end
end

end

function Rule_Objective_TakePoint_Check()

if Prox_AnyEntityNearMarker("_eg_alleldar", "mkr_eldar_relocate2") then
	g_obj_takepoint = true
	Rule_Remove(Rule_Objective_TakePoint_Check)
end

end


--[[ AUTOSAVES ]]

-- Rule_AddIntervalDelay(Rule_Autosave_MissionStart, 1, 3)

function Rule_Autosave_MissionStart()

if not Event_IsAnyRunning() then
	Util_Autosave( "$830200" )
	Rule_Remove(Rule_Autosave_MissionStart)
end

end

function Rule_Autosave_PlateauClear() if not Event_IsAnyRunning() then Util_Autosave( "$830201" ) Rule_Remove(Rule_Autosave_PlateauClear) end end

function Rule_Autosave_PathClear() if not Event_IsAnyRunning() then Util_Autosave( "$830202" ) Rule_Remove(Rule_Autosave_PathClear) end end

function Rule_Autosave_ReclaimBase() if not Event_IsAnyRunning() then Util_Autosave( "$830203" ) Rule_Remove(Rule_Autosave_ReclaimBase) end end

function Rule_Autosave_GuardEliminated() if not Event_IsAnyRunning() then Util_Autosave( "$830204" ) Rule_Remove(Rule_Autosave_GuardEliminated) end end

function Rule_Autosave_EldarEliminated() if not Event_IsAnyRunning() then Util_Autosave( "$830205" ) Rule_Remove(Rule_Autosave_EldarEliminated) end end

function Rule_Autosave_GuardUnlockGate() if not Event_IsAnyRunning() then Util_Autosave( "$830206" ) Rule_Remove(Rule_Autosave_GuardUnlockGate) end end

function Rule_Autosave_EldarUnlockGate() if not Event_IsAnyRunning() then Util_Autosave( "$830207" ) Rule_Remove(Rule_Autosave_EldarUnlockGate) end end

function Rule_Autosave_ConvoyHalfway() if not Event_IsAnyRunning() then Util_Autosave( "$830208" ) Rule_Remove(Rule_Autosave_ConvoyHalfway) end end

function Rule_Autosave_ConvoyAlmostThere() if not Event_IsAnyRunning() then Util_Autosave( "$830209" ) Rule_Remove(Rule_Autosave_ConvoyAlmostThere) end end


--[[ INTEL EVENTS ]]

--[[ LOSERS ]] function Rule_IE_Loser_Eldar() Util_StartIntel(EVENTS.IE_Loser_Eldar) end

function Rule_IE_Loser_Guard() Util_StartIntel(EVENTS.IE_Loser_Guard) end

function Rule_IE_Loser_Guard2() Util_StartIntel(EVENTS.IE_Loser_Guard2) end

--[[ Intel Event 1 ]] function Rule_IE_GateA_Announcement() Util_StartIntel(EVENTS.IE_GateA_Announcement) end

function Rule_IE_GateA_Open() Util_StartIntel(EVENTS.IE_GateA_Open) end

function Rule_IE_EldarSwitch_EndWarning() Util_StartIntel(EVENTS.IE_EldarSwitch_EndWarning) end

function Rule_Eldar_EndBypass() Util_StartIntel(EVENTS.IE_Eldar_EndBypass) end

--[[ guard ]] function Rule_Guard_EndBypass() Util_StartIntel(EVENTS.IE_Guard_EndBypass) end

--[[ Objectives ]]

function Rule_IE_Objective_WebwayAssemblyComplete()

-- Util_StartIntel(EVENTS.IE_Objective_WebwayAssemblyComplete)

end

--[[ Intel Event 1 ]] function Rule_IE_Objective_WebwayAssemblyFailed()

-- Util_StartIntel(EVENTS.IE_Objective_WebwayAssemblyFailed)

end




--[[ CHEATS ]]

--~ function CheatClosingE()

--~ Rule_RemoveAll() --~ Util_StartNIS(EVENTS.NIS_Closing_Eldar)

--~ end

--~ function CheatClosingI()

--~ Rule_RemoveAll() --~ Util_StartNIS(EVENTS.NIS_Closing_Guard)

--~ end

--~ function CheatKillTransport()

--~ if SGroup_Exists("sg_convoytransport") and SGroup_IsEmpty("sg_convoytransport") == false then --~ SGroup_SelfDestroy("sg_convoytransport", false) --~ end --~ --~ end

--~ function CheatKillConvoy()

--~ if SGroup_Exists("sg_convoyescort") and SGroup_IsEmpty("sg_convoyescort") == false then --~ SGroup_SelfDestroy("sg_convoyescort", false) --~ end

--~ end




Game statistieken
Volgers
12
Runs
62
Spelers
7
Recente runs
Niveau: Trophies (Disorder 5 / Orks)
Niveau: Blood for the Blood God! (Disorder 3)
Niveau: Titan of the Emperor (Order 5 / Imperial guard)
Moderators