Mission event file for Imperial Guard final mission
Guider
/
Mission event file for Imperial Guard final mission
Uppdaterad 3 years ago av 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", 0)
Player_DoNotPrecache(g_Player1, _t_MSO5I_Player1)

g_Player2 = Setup_Player(1, "$690087", "ork_race", 1)
Misc_PlayerTeamColor(g_Player2,"default_4")
Player_DoNotPrecache(g_Player2, _t_MSO5I_Player2)

g_Player3 = Setup_Player(2, "$690088", "chaos_marine_race", 1)
Misc_PlayerTeamColor(g_Player3,"default_6")
Player_DoNotPrecache(g_Player3, _t_MSO5I_Player3)

g_Player4 = Setup_Player(3, "$840016", "npc_race", 2) -- Necrons
Player_DoNotPrecache(g_Player4, _t_MSO5I_Player4)

g_Player5 = Setup_Player(4, "$690082", "guard_race", 0) -- To be rescued
Player_DoNotPrecache(g_Player5, _t_MSO5I_Player5)

g_Player6 = Setup_Player(5, "$840020", "guard_race", TEAM_NEUTRAL)
Player_DoNotPrecache(g_Player6, _t_MSO5I_Player6)

g_Player7 = Setup_Player(6, "$690085", "space_marine_race", 0)
Misc_PlayerTeamColor(g_Player7,"default_1")
Player_DoNotPrecache(g_Player7, _t_MSO5I_Player7)

Misc_ForceAutoSwitchTeamColor (g_Player1, true) 	
Misc_ForceAutoSwitchTeamColor (g_Player5, true) 	
Misc_ForceAutoSwitchTeamColor (g_Player7, true) 	

--[[ DEFINE VARIABLES AND TABLES - define any preset values here for later use]]
g_firstrun = true
g_generator_built_count = 0
g_necrons_appeared = false	
g_baneblade_owned_by_player = false

--[[
g_monolith1_flag = false
g_monolith2_flag = false
g_monolith3_flag = false
g_monolith4_flag = false
g_monolith5_flag = false
g_monolith6_flag = false
g_chaos_attack1_stop1_flag = false
g_chaos_attack2_stop1_flag = false]]

t_GeneratorTracker = {false, false, false, false, false, false}
g_necron_attack_escalation = false
t_sgroup_titan_heavy_weapon = {}
t_sgroupnecronbattlegroup = {}
t_sgroup_necron_attackers ={}
t_sgroup_necron_monolith = {}
--t_IG_unit_count_for_area = {0, 0, 0, 0, 0, 0}
t_imperial_generators = {"guard_thermo_plasma"}

--g_ultramarines_army_kickoff_iter = 1
--g_ultramarines_deployed = false
g_baneblade_base_destroyed = false

g_first_generator_online = false
g_second_generator_online = false
g_third_generator_online = false

g_base_survived = false
g_jumped = false

--g_troop_stop1 = false
--g_troop_stop2 = false

g_initial_attack_destination = 0
g_six_generators_built = false

-- g_chaos_counter_army_counter = 1 g_interference_wave = 1 g_titan_sub_objectives_completed = 0 g_end_ultra_count = 1

g_orks_activated = false
g_chaos_activated = false

g_sturnnreturn = false
g_varnusreturn = false
 
g_titan_pieces_powered_up = false
g_titan_weapons_powered_up = false

g_monoliths_destroyed = 0

t_drop_pod_position = {}

t_counter_attack_armies = { areanumber = {{count = 0}, {count = 0}, {count = 0}, {count = 0}, {count = 0}, {count = 0}}, sgroup = {"sg_chaos_counter1", "sg_chaos_counter2", "sg_chaos_counter3", "sg_ork_counter1", "sg_ork_counter2", "sg_ork_counter3"}, sourcearea = {"mkr_chaos_origin1", "mkr_chaos_origin2", "mkr_chaos_origin2", "mkr_ork_origin2", "mkr_ork_origin1", "mkr_ork_origin1"}, targetarea = {"mkr_unit_count_area1", "mkr_unit_count_area2", "mkr_unit_count_area3", "mkr_unit_count_area4", "mkr_unit_count_area5", "mkr_unit_count_area6"}, targetarea_destination = {"mkr_imperial_guard_base", "mkr_imperial_guard_base", "mkr_imperial_guard_base", "mkr_imperial_guard_base", "mkr_imperial_guard_base", "mkr_imperial_guard_base" }, squadsize = { {1, 2, 3}, {1, 2, 3}, {1, 2, 3}, {1, 2, 3}, {1, 2, 3}, {1, 2, 3} } }

t_interference_armies = { areanumber = {{count = 0}, {count = 0}, {count = 0}, {count = 0}, {count = 0}, {count = 0}}, sgroup = {"sg_chaos_interference1", "sg_chaos_interference2", "sg_chaos_interference3", "sg_ork_interference1", "sg_ork_interference2", "sg_ork_interference3"}, sourcearea = {"mkr_chaos_interference_origin1", "mkr_chaos_interference_origin2", "mkr_chaos_interference_origin2", "mkr_ork_interference_origin2", "mkr_ork_interference_origin1", "mkr_ork_interference_origin1"}, targetarea = {"mkr_unit_count_area1", "mkr_unit_count_area2", "mkr_unit_count_area3", "mkr_unit_count_area4", "mkr_unit_count_area5", "mkr_unit_count_area6"}, targetarea_destination = {"mkr_unit_count_area1", "mkr_unit_count_area2", "mkr_unit_count_area3", "mkr_unit_count_area4", "mkr_unit_count_area5", "mkr_unit_count_area6"}, squadsize = { {2, 3, 4}, {2, 3, 4}, {2, 3, 4}, {2, 3, 4}, {2, 3, 4}, {2, 3, 4} } }

t_idle_attack_armies = { areanumber = {{count = 0}, {count = 0}, {count = 0}, {count = 0}, {count = 0}, {count = 0}}, sgroup = {"sg_chaos_idle_attack1", "sg_chaos_idle_attack2", "sg_chaos_idle_attack3", "sg_ork_idle_attack1", "sg_ork_idle_attack2", "sg_ork_idle_attack3"}, sourcearea = {"mkr_chaos_origin1", "mkr_chaos_origin2", "mkr_chaos_origin2", "mkr_ork_origin2", "mkr_ork_origin1", "mkr_ork_origin1"}, targetarea = {"mkr_imperial_guard_base", "mkr_imperial_guard_base", "mkr_imperial_guard_base", "mkr_imperial_guard_base", "mkr_imperial_guard_base", "mkr_imperial_guard_base" }, -- {"mkr_unit_count_area1", "mkr_unit_count_area2", "mkr_unit_count_area3", "mkr_unit_count_area4", "mkr_unit_count_area5", "mkr_unit_count_area6"}, targetarea_destination = {"mkr_imperial_guard_base", "mkr_imperial_guard_base", "mkr_imperial_guard_base", "mkr_imperial_guard_base", "mkr_imperial_guard_base", "mkr_imperial_guard_base" }, squadsize = { {1, 2, 3}, {1, 2, 3}, {1, 2, 3}, {1, 2, 3}, {1, 2, 3}, {1, 2, 3} } }

t_monolith_track = {false, false, false, false, false}

end

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

end

function OnLoad() if g_titan_pieces_powered_up == true then

	Anim_PlayEGroupAnim(EGroup_FromName("eg_titan_right_leg_lower"), "o_idle")
	Anim_PlayEGroupAnim(EGroup_FromName("eg_titan_right_leg_upper"), "o_idle")
	Anim_PlayEGroupAnim(EGroup_FromName("eg_titan_left_leg_lower"), "o_idle")
	Anim_PlayEGroupAnim(EGroup_FromName("eg_titan_left_leg_upper"), "o_idle")
	Anim_PlayEGroupAnim(EGroup_FromName("eg_titan_torso"), "o_idle")
	Anim_PlayEGroupAnim(EGroup_FromName("eg_titan_skull"), "o_powerup")
	Anim_PlayEGroupAnim(EGroup_FromName("eg_titan_chest"), "o_powerup")
	
end

if g_titan_weapons_powered_up == true then

	Anim_PlayEGroupAnim(EGroup_FromName("eg_titan_left_arm"), "o_idle")
	Anim_PlayEGroupAnim(EGroup_FromName("eg_titan_right_arm"), "o_idle")
	Anim_PlayEGroupAnim(EGroup_FromName("eg_titan_skull"), "o_idle")
	Anim_PlayEGroupAnim(EGroup_FromName("eg_titan_chest"), "o_idle")
	
end

Misc_ForceAutoSwitchTeamColor (g_Player1, true) 	
Misc_ForceAutoSwitchTeamColor (g_Player5, true) 	
Misc_ForceAutoSwitchTeamColor (g_Player7, true) 
	

end

Scar_AddLoad(OnLoad)

function CheatClosing()

Rule_RemoveAll()
Util_StartNIS(EVENTS.NIS_Closing)

end


--[[ ON INITIALIZATION ]]

function OnInit()

--[[ RESEARCH LEVEL - sets the research level of the mission, locks researches, squads, and buildings for the appropriate mission number DOW specific! ]]
Rule_SetResearchLevel( 4 )

--[[ NIS PRESETS - turn off event cues, set the viewable space to black (faded out) and preset letterboxing ]]
EventCue_Enable(false)
Fade_Start( 0, false )	
W40k_Letterbox( true, 0 )	

--[[ 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 ]]
Util_StartNIS( EVENTS.NIS_Opening ) 	
Sound_PlayStinger("stinger_mso5i_thetitan") -- theme at the beginning
--Rule_AddOneShot(Rule_IE_OpeningSpeech, 0)  -- may be needed later

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

--[[ Define the OBJECTIVES ]]

Objective_Titan = {title_id = 841030, short_desc_id = 841032, help_tip_id = 841034}
Objective_Build_Six_Generators = {title_id = 841000, short_desc_id = 841002, help_tip_id = 841004}
Objective_Secure_Generator_Construction_Sites = {title_id = 841024, short_desc_id = 841026, help_tip_id = 841028}
Objective_Defeat_Necrons = {title_id = 841006, short_desc_id = 841008, help_tip_id = 841010}
Objective_Rescue_Baneblade = {title_id = 841012, short_desc_id = 841014, help_tip_id = 841016}
Objective_Base_Survive = {title_id = 841018, short_desc_id = 841020, help_tip_id = 841022}

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 )

--[[ DoW Specific!! Restrict_SpaceMarines( g_Player1, resLevel ) Unrestrict_ResearchWithAlerts( g_Player1, "marine_requisition_research_2", "none", "none" ) Unrestrict_ResearchWithAlerts( g_Player1, "marine_power_research_2", "none", "none" ) ]]

end


--[[ MUSIC ]]

function Rule_SetupMusicPlaylist()

t_ambient = {"Snowy_wind_2" }
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
	

	--[[ set resources ]]
	Player_SetResource(g_Player1, RT_Requisition, 1500)
	Player_SetResource(g_Player1, RT_Power, 500)
	
	--[[Kick off Armies]]
	Rule_Player_Army_Kickoff() -- Starts player's army
	Rule_Ultramarines_Army_Kickoff()
	
	Rule_AddOneShot(Rule_Chaos_Army_Kickoff, 1)
	Rule_AddOneShot(Rule_Ork_Army_Kickoff, 1)
	
	Rule_AddInterval(Rule_Sturnn_Track, 0)
	Rule_AddInterval(Rule_Varnus_Track, 3)
	
	--[[ DIFFICULTY LEVEL - gets the difficulty level from the UI and passes it into the function]]
	Rule_SetDifficultyLevel( Difficulty_Get() )
	
	--[[ Get the AI doing whatever after the NIS is over ]]
	Rule_StartAI()
	
	g_firstrun = false
	
	
elseif Event_IsAnyRunning() == false then		
	
	
	--[[ Set up a Win Check ]]
	Rule_AddInterval(Rule_EndGameWin, 1)
	
	--[[ Set up a Lose Check ]]
	Rule_AddInterval(Rule_EndGameLose, 1)
	
	--[[objectives]]
	Rule_AddInterval(Rule__Objective_Titan, 1)
	
	Rule_AddInterval(Rule_Baneblade_Secondary_Mission_Objective_Kickoff, 1)
	--Rule_AddInterval(Rule_BaneBladeRescueControl, 1) -- starts check for baneblade rescues
	
	--[[action on map]]
	Rule_AddOneShot(Rule_Enemy_Army_Activity_Kickoff, 15) -- kicks off army in 15 seconds
	Rule_AddOneShot(Rule_Ping_Kickoff, 0) -- starts initial Intel Pings on the map
	Rule_AddIntervalDelay(Rule_Generator_Counter, 2, 3)  -- counts how many generators are present
	Rule_AddIntervalDelay(Rule_Generator_Counter_Options, 2, 4)
	Rule_AddOneShot(Rule_IE_OpeningSpeech, 4)
	Rule_AddOneShot(Rule_IE_Give_First_Objective, 6)
	
	--[[autosave]]
	Rule_Add(Rule_Autosave_MissionStart) -- Autosaves mission start
	
	--[[ Clean up ]]
	Rule_Remove(Rule_GameStart)
	
end

end


--[[ DIFFICULTY ]]

function Rule_SetDifficultyLevel( difficultyLevel )

--Difficulty_SetForAll( difficultyLevel )
Difficulty_SetForPlayer( g_Player2, difficultyLevel )
Difficulty_SetForPlayer( g_Player3, difficultyLevel )
Difficulty_SetForPlayer( g_Player4, difficultyLevel )
Difficulty_SetForPlayer( g_Player5, difficultyLevel )

-- 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

end


--[[ AI ]]

function Rule_StartAI()

Cpu_EnableAll(false)	

end


--[[ CORE GAME ]]


--[[ PLAYER ARMY ]]

function Rule_Player_Army_Kickoff()

EGroup_ForceAddOn("eg_guard_hq", "addon_guard_hq_1") --forces an addon to the guard HQ

Player_RestrictSquad(g_Player1, "guard_squad_command_squad") -- restricts squad so that the leader unit can't be duplicated
Player_RestrictSquad(g_Player1, "guard_squad_baneblade")
Player_RestrictBuilding(g_Player1, "guard_mars_pattern")
Player_UnRestrictSquad(g_Player1, "guard_squad_ogryns")
Player_UnRestrictSquad(g_Player1, "guard_squad_sentinel")
Player_GrantResearch(g_Player1, "marine_accuracy_upgrade_research")
Player_GrantResearch(g_Player1, "marine_health_upgrade_research")
EGroup_ForceAddOn( "eg_player_mech_production", "addon_guard_sentinel_depot")

--[[enginseer creation and stats]]
Util_CreateSquadsAtMarker(g_Player1, "sg_base_enginseer1", "guard_squad_enginseer", "mkr_imperial_guard_base", 1)
Util_CreateSquadsAtMarker(g_Player1, "sg_base_enginseer2", "guard_squad_enginseer", "mkr_imperial_guard_base", 1)

local mod_enginseer_armourincrease = Modifier_Create(MAT_EntityType, "armour_modifier", MUT_Multiplication, false, 2, "guard_squad_enginseer")
g_mod_enginseer_armourincrease = Modifier_ApplyToPlayer( mod_enginseer_armourincrease, g_Player1)
local mod_enginseer_healthincrease = Modifier_Create(MAT_EntityType, "health_maximum_modifier", MUT_Multiplication, false, 4, "guard_squad_enginseer")
g_mod_enginseer_healthincrease = Modifier_ApplyToPlayer( mod_enginseer_healthincrease, g_Player1)	

--Creates squad to be rescued with baneblade
sgroup_lost1 = Util_CreateSquadsAtMarkerEx(g_Player5, "sg_need_rescue1", "guard_squad_guardsmen", "mkr_baneblade_rescue", 2, 12)
	for i = 1, SGroup_Count(sgroup_lost1) do
		Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(sgroup_lost1, i), "guard_grenade_launcher_guardsmen", 3)
		Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(sgroup_lost1, i), "guard_plasma_gun_guardsmen", 2)
	end
SGroup_AddLeaders("sg_need_rescue1")
Cmd_SetStance( "sg_need_rescue1", STANCE_StandGround)

--baneblade escorts
Util_CreateSquadsAtMarker(g_Player5, "sg_russ_rescue1", "guard_squad_lemanruss", "mkr_outside_tank1", 1)
Util_CreateSquadsAtMarker(g_Player5, "sg_russ_rescue2", "guard_squad_lemanruss", "mkr_outside_tank2", 1)

Entity_SetHealth(EGroup_GetSpawnedEntityAt(EGroup_FromName("eg_baneblade_building"), 1), 0.5)

--[[varnus creation and stats]]
Util_CreateSquadsAtMarker(g_Player7, "sg_varnus", "space_marine_squad_chaplain", "mkr_ultramarines_spawn", 1)	
SGroup_SetPlayerOwner("sg_varnus", g_Player1)

local mod_varnushealthincrease = Modifier_Create(MAT_EntityType, "health_maximum_modifier", MUT_Multiplication, false, 4, "space_marine_squad_chaplain")
g_mod_varnushealthincrease = Modifier_ApplyToPlayer( mod_varnushealthincrease, g_Player1)	

Util_CreateSquadsAtMarker(g_Player1, "sg_sentinels", "guard_squad_sentinel", "mkr_heavy_squad", 1)

end

--[[ Tracks Sturnn ]] function Rule_Sturnn_Track()

--[[ check to see if the group is empty AND if the boolean has been returned to false - this prevents duplicate rule adds ]]
if g_sturnnreturn ~= true and SGroup_Exists("sg_sturnn") and SGroup_IsEmpty("sg_sturnn") then
	
	--[[ prevents duplicate rule adds ]]
	g_sturnnreturn = true
	
	--[[ 6 second delay, keeps it from being instantaneous ]]
	Rule_AddOneShot(Rule_Sturnn_Return, 6)
	
end

end

function Rule_Sturnn_Return()

--[[ recreate the unit ]]
g_sturnn_sgroupID = Util_CreateSquadsAtMarker(g_Player1, "sg_sturnn", "guard_squad_command_squad", "mkr_imperial_guard_base", 1)	

--[[ play the fx ]]
World_FXEventSquad("data:Art/Events/Unit_Upgrade_Morale_FX/Reinforce_Trooper", SGroup_FromName("sg_sturnn"))

--[[ reset the flag ]]
g_sturnnreturn = false

--[[ if no messages have played recently, play the Intel Event - this keeps messages from flooding the player ]]
if Event_TimeSinceLast() > 10 then
	
	local l_random_line_spoken = World_GetRand(1, 2)
	
	if l_random_line_spoken == 1 then
		Rule_AddOneShot(Rule_IE_Sturnn_Returns, 0)
	elseif l_random_line_spoken == 2 then
		Rule_AddOneShot(Rule_IE_Sturnn_Returns2, 0)
	end
	
end
EventCue_DoEvent( "recruit_commander", "/Races/Shared/Upgrade_weapon", "$42890", "$42892" )

end

--[[ Tracks Varnus ]] function Rule_Varnus_Track()

local blueprinttable = Util_MakeBlueprintTable("space_marine_squad_chaplain")

--[[ check to see if the group is empty AND if the boolean has been returned to false - this prevents duplicate rule adds ]]
if g_varnusreturn ~= true and SGroup_Exists("sg_varnus") 
and (SGroup_IsEmpty("sg_varnus") or SGroup_ContainsBlueprints( "sg_varnus", blueprinttable, false) == false) then
	
	--[[ prevents duplicate rule adds ]]
	g_varnusreturn = true
	
	--[[ 6 second delay, keeps it from being instantaneous ]]
	Rule_AddOneShot(Rule_Varnus_Return, 6)
	
end

end

function Rule_Varnus_Return()

--[[ recreate the unit ]]
g_varnus_sgroupID = Util_CreateSquadsAtMarker(g_Player1, "sg_varnus", "space_marine_squad_chaplain", "mkr_ultramarines_spawn", 1)	

--[[ play the fx ]]
World_FXEventSquad("data:Art/Events/Unit_Upgrade_Morale_FX/Reinforce_Trooper", SGroup_FromName("sg_varnus"))

--[[ reset the flag ]]
g_varnusreturn = false

--[[ if no messages have played recently, play the Intel Event - this keeps messages from flooding the player ]]
if Event_TimeSinceLast() > 10 then
	local l_random_line_spoken = World_GetRand(1, 2)
	
	if l_random_line_spoken == 1 then
		Rule_AddOneShot(Rule_IE_Varnus_Returns, 0)
	elseif l_random_line_spoken == 2 then
		Rule_AddOneShot(Rule_IE_Varnus_Returns2, 0)
	end
	
end
EventCue_DoEvent( "recruit_commander", "/Races/Shared/Upgrade_weapon", "$42890", "$42892" )

end

function Rule_Ultramarines_Army_Kickoff() -- Berger's cool function, modified

t_ultramarines_army = {
	sgroup_name = {"sg_space_marine_defense1", "sg_space_marine_defense2"},  
	blueprint = {"space_marine_squad_tactical", "space_marine_squad_assault"},
	squad_num = {1, 1}, 
	squad_size = {8, 8}, 
	
}

for i = 1, table.getn(t_ultramarines_army.sgroup_name) do
	Util_CreateSquadsAtMarkerEx(g_Player7, t_ultramarines_army.sgroup_name[i], t_ultramarines_army.blueprint[i], "mkr_ultramarines_spawn", t_ultramarines_army.squad_num[i], t_ultramarines_army.squad_size[i])
	SGroup_AddLeaders(t_ultramarines_army.sgroup_name[i])
	SGroup_SetPlayerOwner(t_ultramarines_army.sgroup_name[i], g_Player1)
end

local mod_ultramarine_assault_armourincrease = Modifier_Create(MAT_EntityType, "armour_modifier", MUT_Multiplication, false, 2.5, "space_marine_squad_assault")
g_mod_ultramarine_assault_armourincrease = Modifier_ApplyToPlayer( mod_ultramarine_assault_armourincrease, g_Player1)
local mod_ultramarine_assault_healthincrease = Modifier_Create(MAT_EntityType, "health_maximum_modifier", MUT_Multiplication, false, 2, "space_marine_squad_assault")
g_mod_ultramarine_assault_healthincrease = Modifier_ApplyToPlayer( mod_ultramarine_assault_healthincrease, g_Player1)	

local mod_ultramarine_tactical_armourincrease = Modifier_Create(MAT_EntityType, "armour_modifier", MUT_Multiplication, false, 2.5, "space_marine_squad_tactical")
g_mod_ultramarine_tactical_armourincrease = Modifier_ApplyToPlayer( mod_ultramarine_tactical_armourincrease, g_Player1)
local mod_ultramarine_tactical_healthincrease = Modifier_Create(MAT_EntityType, "health_maximum_modifier", MUT_Multiplication, false, 2, "space_marine_squad_tactical")
g_mod_ultramarine_tactical_healthincrease = Modifier_ApplyToPlayer( mod_ultramarine_tactical_healthincrease, g_Player1)	

end

function Rule_End_Ultramarines_Army_Kickoff() -- kicks off ultramarine units if g_end_ultra_count <= 4 then t_drop_pod_position[g_end_ultra_count] = Marker_GetPosition(Marker_FromName("mkr_drop_pod"..g_end_ultra_count, "basic_marker")) Util_CreateSquadsAndDropPodIn(g_Player7, "sg_end_pod_group"..g_end_ultra_count, "space_marine_squad_tactical", t_drop_pod_position[g_end_ultra_count], 1, 0 ) g_end_ultra_count = g_end_ultra_count + 1 elseif g_end_ultra_count >= 5 then Rule_Remove(Rule_End_Ultramarines_Army_Kickoff) end end

--[[Chaos Army Creation]] function Rule_Chaos_Army_Kickoff() -- Creates Chaos forces to attack the titan -- NOTE TO SELF : USE FOR LOOP

Player_GrantResearch(g_Player3, "chaos_frag_grenade_research")
Player_GrantResearch(g_Player3, "chaos_accuracy_upgrade_research")
Player_GrantResearch(g_Player3, "chaos_sorcerer_research_1")
Player_GrantResearch(g_Player3, "chaos_health_upgrade_research")


Util_CreateSquadsAtMarkerEx(g_Player3, "sg_chaos_outpost_defender1", "chaos_marine_squad", "mkr_chaos_outpost1", 2, 12)
Util_CreateSquadsAtMarker(g_Player3, "sg_chaos_outpost_defender2", "chaos_squad_sp_champion", "mkr_chaos_outpost1", 1)

Util_CreateSquadsAtMarkerEx(g_Player3, "sg_chaos_origin1_defender1", "chaos_squad_obliterator", "mkr_chaos_origin1", 3, 4)
Util_CreateSquadsAtMarker(g_Player3, "sg_chaos_origin1_defender2", "chaos_squad_predator", "mkr_chaos_origin1", 3)
Util_CreateSquadsAtMarker(g_Player3, "sg_chaos_origin1_defender3", "chaos_squad_sorcerer", "mkr_chaos_origin1", 1)

Util_CreateSquadsAtMarkerEx(g_Player3, "sg_chaos_origin2_defender1", "chaos_squad_obliterator", "mkr_chaos_origin2", 3, 4)
Util_CreateSquadsAtMarker(g_Player3, "sg_chaos_origin2_defender2", "chaos_squad_predator", "mkr_chaos_origin2", 3)
Util_CreateSquadsAtMarker(g_Player3, "sg_chaos_origin2_defender3", "chaos_squad_sorcerer", "mkr_chaos_origin2", 1)

end

--[[tracks units from Chaos outposts. If they are dead they will be regenerated]] function Rule_Chaos_Outpost_Track() if EGroup_Exists("eg_chaos_outpost_production1") and EGroup_IsEmpty("eg_chaos_outpost_production1") == false then if SGroup_Exists("sg_chaos_outpost_defender1") and SGroup_IsEmpty("sg_chaos_outpost_defender1") and EGroup_Exists("eg_chaos_outpost_production1") and EGroup_IsEmpty("eg_chaos_outpost_production1") == false then Util_CreateSquadsAtMarkerEx(g_Player3, "sg_chaos_outpost_defender1", "chaos_marine_squad", "mkr_chaos_outpost1", 1, 12) end elseif EGroup_Exists("eg_chaos_outpost_production1") and EGroup_IsEmpty("eg_chaos_outpost_production1") == false then Rule_Remove(Rule_Chaos_Outpost_Track) end end

function Rule_IG_Count_At_Area() -- for interference armies, so that the interference army function leads an attack into the outside of the IG base. for i = 1, 6 do --checks to see if a counter attack group is empty. Only if it is empty will a proximity check be made, hopefully making this function less expensive

	if SGroup_Exists(t_interference_armies.sgroup[i]) == false or SGroup_IsEmpty(t_interference_armies.sgroup[i]) then
		Player_GetAllSquadsNearMarker(g_Player1, "sg_unit_count_for_area_for_interference"..i, t_interference_armies.targetarea[i])
		t_interference_armies.areanumber[i].count = SGroup_Count(SGroup_FromName("sg_unit_count_for_area_for_interference"..i))
		SGroup_Clear("sg_unit_count_for_area_for_interference"..i)
		--print("interference area "..i.." : ")
		--print(t_interference_armies.areanumber[i].count)
	end

end

end

function Rule_IG_Count_At_Area2() -- for counting enemy units at target area, but calling the counter attack function that leads an attack into the IG base. for i = 1, 6 do --checks to see if a counter attack group is empty. Only if it is empty will a proximity check be made, hopefully making this function less expensive

	if SGroup_Exists(t_counter_attack_armies.sgroup[i]) == false or SGroup_IsEmpty(t_counter_attack_armies.sgroup[i]) then
		Player_GetAllSquadsNearMarker(g_Player1, "sg_unit_count_for_area"..i, t_counter_attack_armies.targetarea[i])
		t_counter_attack_armies.areanumber[i].count = SGroup_Count(SGroup_FromName("sg_unit_count_for_area"..i))
		SGroup_Clear("sg_unit_count_for_area"..i)
		--print("counter area"..i.." : ")
		--print(t_counter_attack_armies.areanumber[i].count)
	end
	
end

end

function Rule_IG_Count_At_Area3() -- for counting IG units in the imperial guard base area so that the idle attack army can be adjusted to the player's army size and directed to the IG base. for i = 1, 6 do --checks to see if a counter attack group is empty. Only if it is empty will a proximity check be made, hopefully making this function less expensive

	if SGroup_Exists(t_idle_attack_armies.sgroup[i]) == false or SGroup_IsEmpty(t_idle_attack_armies.sgroup[i]) then
		Player_GetAllSquadsNearMarker(g_Player1, "sg_unit_count_for_ig_area"..i, t_idle_attack_armies.targetarea[i])
		t_idle_attack_armies.areanumber[i].count = SGroup_Count(SGroup_FromName("sg_unit_count_for_ig_area"..i))
		SGroup_Clear("sg_unit_count_for_ig_area"..i)
		--print("idle area"..i.." : ")
		--print(t_idle_attack_armies.areanumber[i].count)
	end

end

end

function Rule_Create_Chaos_Interference_Armies()

for i = 1, 3 do
	
	local dif = 1
	
	--if EGroup_IsCapturedByPlayer( "eg_capture_"..i, g_Player1, true)  then --and g_initial_attack_started == false
	if g_interference_wave == 1 then 
		
		if t_interference_armies.areanumber[i].count > 0 then
			
			if SGroup_Exists(t_interference_armies.sgroup[i]) == false or SGroup_IsEmpty(t_interference_armies.sgroup[i]) then
				
				--SGroup_CreateIfNotFound(t_interference_armies.sgroup[i])
				
				local blueprint_list = {"chaos_squad_raptor", "chaos_marine_squad"}
				
					--[[here we set 'dif' to use one of the squadsize parameters
					if t_interference_armies.areanumber[i].count >= 1 and t_interference_armies.areanumber[i].count <= 4 then
						--dif = 1
				else]]if t_interference_armies.areanumber[i].count >= 4 and t_interference_armies.areanumber[i].count <= 6 then
					dif = 2
					blueprint_list = {"chaos_squad_raptor", "chaos_marine_squad", "chaos_squad_horror"}
				elseif t_interference_armies.areanumber[i].count >= 7  then --and t_interference_armies.areanumber[i].count <= 8
					dif = 3
					blueprint_list = {"chaos_squad_raptor", "chaos_marine_squad", "chaos_squad_horror"}
				end
				
				--print("i = "..i.." and dif = "..dif)
				--print(t_interference_armies.squadsize[i][dif])
				
				for n = 1, t_interference_armies.squadsize[i][dif] do
					
					-- rand1 to be used with the blue print table	
					local rand1 = World_GetRand(1, table.getn(blueprint_list))
					-- rand2 is to be used for the squad sizes
					local rand2 = World_GetRand(6, 10)
					
					Util_CreateSquadsAtMarkerEx(g_Player3, t_interference_armies.sgroup[i], blueprint_list[rand1], t_interference_armies.sourcearea[i], 1, rand2)
					Cmd_AttackMoveMarker(t_interference_armies.sgroup[i], t_interference_armies.targetarea_destination[i])
						
						
				end
				
				--print("wave 1")
				g_interference_wave = g_interference_wave + 1
				Rule_Remove(Rule_Create_Ork_Interference_Armies)
				Rule_AddIntervalDelay(Rule_Create_Chaos_Interference_Armies_2nd_Wave, 100, 1)
				
				g_chaos_activated = true
				g_initial_attack_destination = i
				
				
				Rule_Remove(Rule_Create_Chaos_Interference_Armies)
				break
				
			end
			
		end
		
	end
	
end

end

function Rule_Create_Chaos_Interference_Armies_2nd_Wave()

local dif = 1

--if EGroup_IsCapturedByPlayer( "eg_capture_"..i, g_Player1, true)  then --and g_initial_attack_started == false
if g_interference_wave == 2 then 
	
	--print("chaos interference area count : ")
	--print(t_interference_armies.areanumber[g_initial_attack_destination].count)
	
	if t_interference_armies.areanumber[g_initial_attack_destination].count > 0  then
		
		--g_initial_attack_destination = t_interference_armies.targetarea[i]
		
		
		if SGroup_Exists(t_interference_armies.sgroup[g_initial_attack_destination]) == false or SGroup_IsEmpty(t_interference_armies.sgroup[g_initial_attack_destination]) then
			
			--print("making squads")
			--SGroup_CreateIfNotFound(t_interference_armies.sgroup[i])
			local blueprint_list = {"chaos_squad_raptor", "chaos_marine_squad"}
			
			--[[here we set 'dif' to use one of the squadsize parameters
			if t_interference_armies.areanumber[i].count >= 1 and t_interference_armies.areanumber[i].count <= 4 then
			--dif = 1
			else]]
			if t_interference_armies.areanumber[g_initial_attack_destination].count >= 4 and t_interference_armies.areanumber[g_initial_attack_destination].count <= 6 then
				dif = 2
				blueprint_list = {"chaos_squad_raptor", "chaos_marine_squad", "chaos_squad_horror"}
			elseif t_interference_armies.areanumber[g_initial_attack_destination].count >= 7  then --and t_interference_armies.areanumber[i].count <= 8
				dif = 3
				blueprint_list = {"chaos_squad_raptor", "chaos_marine_squad", "chaos_squad_horror"}
			end
			
			--print("i = "..i.." and dif = "..dif)
			--print(t_interference_armies.squadsize[g_initial_attack_destination][dif])
				
			for n = 1, t_interference_armies.squadsize[g_initial_attack_destination][dif] do
				
				-- rand1 to be used with the blue print table	
				local rand1 = World_GetRand(1, table.getn(blueprint_list))
				-- rand2 is to be used for the squad sizes
				local rand2 = World_GetRand(8, 12)
						
				Util_CreateSquadsAtMarkerEx(g_Player3, t_interference_armies.sgroup[g_initial_attack_destination], blueprint_list[rand1], t_interference_armies.sourcearea[g_initial_attack_destination], 1, rand2)
				Cmd_AttackMoveMarker(t_interference_armies.sgroup[g_initial_attack_destination], t_interference_armies.targetarea_destination[g_initial_attack_destination])
				
			end
			
			--print("wave 2")
			g_interference_wave = g_interference_wave + 1
			Rule_AddIntervalDelay(Rule_Create_Chaos_Interference_Armies_3rd_Wave, 100, 1 )
			Rule_Remove(Rule_Create_Chaos_Interference_Armies_2nd_Wave)
			
		end
		
	end
	
end

end

function Rule_Create_Chaos_Interference_Armies_3rd_Wave()

local dif = 1

--if EGroup_IsCapturedByPlayer( "eg_capture_"..i, g_Player1, true)  then --and g_initial_attack_started == false
if g_interference_wave == 3 then 
	
	if t_interference_armies.areanumber[g_initial_attack_destination].count > 0  then
		
		--g_initial_attack_destination = t_interference_armies.targetarea[i]
		
		if SGroup_Exists(t_interference_armies.sgroup[g_initial_attack_destination]) == false or SGroup_IsEmpty(t_interference_armies.sgroup[g_initial_attack_destination]) then
			
			--SGroup_CreateIfNotFound(t_interference_armies.sgroup[i])
				
			local blueprint_list = {"chaos_squad_raptor", "chaos_marine_squad"}
				
			--[[here we set 'dif' to use one of the squadsize parameters
			if t_interference_armies.areanumber[i].count >= 1 and t_interference_armies.areanumber[i].count <= 4 then
			--dif = 1
			else]]
			
			if t_interference_armies.areanumber[g_initial_attack_destination].count >= 4 and t_interference_armies.areanumber[g_initial_attack_destination].count <= 6 then
				dif = 2
				blueprint_list = {"chaos_squad_raptor", "chaos_marine_squad", "chaos_squad_horror"}
			elseif t_interference_armies.areanumber[g_initial_attack_destination].count >= 7  then --and t_interference_armies.areanumber[i].count <= 8
				dif = 3
				blueprint_list = {"chaos_squad_raptor", "chaos_marine_squad", "chaos_squad_horror"}
			end
			
			--print("i = "..i.." and dif = "..dif)
			--print(t_interference_armies.squadsize[g_initial_attack_destination][dif])
				
			for n = 1, t_interference_armies.squadsize[g_initial_attack_destination][dif] do
				
				-- rand1 to be used with the blue print table	
				local rand1 = World_GetRand(1, table.getn(blueprint_list))
				-- rand2 is to be used for the squad sizes
				local rand2 = World_GetRand(8, 12)
				
				
				Util_CreateSquadsAtMarkerEx(g_Player3, t_interference_armies.sgroup[g_initial_attack_destination], blueprint_list[rand1], t_interference_armies.sourcearea[g_initial_attack_destination], 1, rand2)
				Cmd_AttackMoveMarker(t_interference_armies.sgroup[g_initial_attack_destination], t_interference_armies.targetarea_destination[g_initial_attack_destination])
				
			end
			
			--print("wave 3")
			g_interference_wave = g_interference_wave + 1
			--Rule_AddIntervalDelay(Rule_Chaos_Interference_Armies_3rd_Wave, 30, 100)
				
			Rule_Check_AddInterval(Rule_IG_Count_At_Area2, 10)
			Rule_AddIntervalDelay(Rule_Create_Chaos_Counter_Attack_Armies, 100, 2)
			Rule_AddIntervalDelay(Rule_Create_Ork_Counter_Attack_Armies, 100, 1)
			
			Rule_Remove(Rule_Create_Chaos_Interference_Armies_3rd_Wave)
			Rule_Check_Remove(Rule_IG_Count_At_Area)
		end
			
	end
	
end

end

function Rule_Create_Chaos_Counter_Attack_Armies()

local l_random_chaos_counter_attack_area = World_GetRand(1, 3)

--for i = 1, 3 do
	
	-- this will be used to make a call to the squadsize parameter
	local dif = 1
	
	
	if t_counter_attack_armies.areanumber[l_random_chaos_counter_attack_area].count >= 0 then -- and t_interference_armies.areanumber[l_random_chaos_counter_attack_area].count < 5
		
		if SGroup_Exists(t_counter_attack_armies.sgroup[l_random_chaos_counter_attack_area]) == false or SGroup_IsEmpty(t_counter_attack_armies.sgroup[l_random_chaos_counter_attack_area]) then
			
			--SGroup_CreateIfNotFound(t_counter_attack_armies.sgroup[l_random_chaos_counter_attack_area])
			
			local blueprint_list = {"chaos_squad_khorne_berserker", "chaos_marine_squad", "chaos_squad_horror"}
			
			--[[here we set 'dif' to use one of the squadsize parameters
			if t_counter_attack_armies.areanumber[l_random_chaos_counter_attack_area].count >= 1 and t_counter_attack_armies.areanumber[l_random_chaos_counter_attack_area].count <= 4 then
				--dif = 1
			else]]
			if t_counter_attack_armies.areanumber[l_random_chaos_counter_attack_area].count >= 3 and t_counter_attack_armies.areanumber[l_random_chaos_counter_attack_area].count <= 6 then
				dif = 2
				blueprint_list = {"chaos_squad_raptor", "chaos_marine_squad", "chaos_squad_horror", "chaos_squad_khorne_berserker"}
			elseif t_counter_attack_armies.areanumber[l_random_chaos_counter_attack_area].count >= 7  then --and t_counter_attack_armies.areanumber[l_random_chaos_counter_attack_area].count <= 8
				dif = 3
				blueprint_list = {"chaos_squad_raptor", "chaos_marine_squad", "chaos_squad_horror", "chaos_squad_khorne_berserker"}
			end
			
			--print("chaos counter armies ")
			--print("i = "..i.." and dif = "..dif)
			--print(t_counter_attack_armies.squadsize[l_random_chaos_counter_attack_area][dif])
			
			for n = 1, t_counter_attack_armies.squadsize[l_random_chaos_counter_attack_area][dif] do
				
				-- rand1 to be used with the blue print table	
				local rand1 = World_GetRand(1, table.getn(blueprint_list))
				-- rand2 is to be used for the squad sizes
				local rand2 = World_GetRand(6, 12)
				
				
				Util_CreateSquadsAtMarkerEx(g_Player3, t_counter_attack_armies.sgroup[l_random_chaos_counter_attack_area], blueprint_list[rand1], t_counter_attack_armies.sourcearea[l_random_chaos_counter_attack_area], 1, rand2)
				Cmd_AttackMoveMarker(t_counter_attack_armies.sgroup[l_random_chaos_counter_attack_area], t_counter_attack_armies.targetarea_destination[l_random_chaos_counter_attack_area])
				
				--Cmd_Capture(t_interference_armies.sgroup[1], "eg_capture_"..i)
			end
			
			--break
			
		end
		
	end
	
--end

if g_necrons_appeared == true then
	Rule_Remove(Rule_Create_Chaos_Counter_Attack_Armies)
	Rule_Check_Remove(Rule_IG_Count_At_Area2)
end

end


--Chaos Idle Attacks -- For when the player sits at his/her base and idles for a long time

--[[ function Rule_Create_Chaos_Idle_Attack_Armies_Kickoff() if g_idle_attack == false then Rule_AddOneShot(Rule_Create_Chaos_Idle_Attack_Armies_Random_Start_Generator, 1) g_idle_attack = true Rule_Remove(Rule_Create_Chaos_Idle_Attack_Armies_Kickoff) end end]]

function Rule_Create_Chaos_Idle_Attack_Armies_Random_Start_Generator() -- generates the Ork attacks that will occur if the player sits at their base and does nothing.

if g_chaos_activated == false then
	
	g_initial_attack_destination = World_GetRand(1, 3)
	
	local l_start_time = World_GetRand(10, 30)
	
	Rule_Check_AddInterval(Rule_IG_Count_At_Area3, 10, l_start_time)
	Rule_AddIntervalDelay(Rule_Create_Chaos_Idle_Attack_Armies, 45, l_start_time + 1)
elseif g_chaos_activated == true then
	Rule_Remove(Rule_Create_Chaos_Idle_Attack_Armies_Random_Start_Generator)
end

end

function Rule_Create_Chaos_Idle_Attack_Armies()

-- this will be used to make a call to the squadsize parameter
local dif = 1

if SGroup_Exists(t_idle_attack_armies.sgroup[g_initial_attack_destination]) == false or SGroup_IsEmpty(t_idle_attack_armies.sgroup[g_initial_attack_destination]) then
	
	--SGroup_CreateIfNotFound(t_idle_attack_armies.sgroup[i])
	local blueprint_list = {"chaos_squad_raptor", "chaos_marine_squad"}
	--[[here we set 'dif' to use one of the squadsize parameters
	if t_idle_attack_armies.areanumber[i].count >= 1 and t_idle_attack_armies.areanumber[i].count <= 4 then
	--dif = 1
	else]]
	
	if t_idle_attack_armies.areanumber[g_initial_attack_destination].count >= 4 and t_idle_attack_armies.areanumber[g_initial_attack_destination].count <= 6 then
		dif = 2
		blueprint_list = {"chaos_squad_raptor", "chaos_marine_squad", "chaos_squad_horror"} -- "chaos_squad_khorne_berserker"
	elseif t_idle_attack_armies.areanumber[g_initial_attack_destination].count >= 7  then --and t_idle_attack_armies.areanumber[i].count <= 8
		dif = 3
		blueprint_list = {"chaos_squad_raptor", "chaos_marine_squad", "chaos_squad_horror"} -- "chaos_squad_khorne_berserker"
	end
	
	--print("i = "..i.." and dif = "..dif)
	--print(t_idle_attack_armies.squadsize[g_initial_attack_destination][dif])
	
	for n = 1, t_idle_attack_armies.squadsize[g_initial_attack_destination][dif] do
		-- rand1 to be used with the blue print table	
		local rand1 = World_GetRand(1, table.getn(blueprint_list))
		-- rand2 is to be used for the squad sizes
		local rand2 = World_GetRand(6, 10)
		Util_CreateSquadsAtMarkerEx(g_Player2, t_idle_attack_armies.sgroup[g_initial_attack_destination], blueprint_list[rand1], t_idle_attack_armies.sourcearea[g_initial_attack_destination], 1, rand2)
		Cmd_AttackMoveMarker(t_idle_attack_armies.sgroup[g_initial_attack_destination], t_idle_attack_armies.targetarea_destination[g_initial_attack_destination])
	end
	
	Rule_AddOneShot(Rule_Create_Chaos_Idle_Attack_Armies_Random_Start_Generator, 1)
	--print(g_chaos_activated)
	Rule_Remove(Rule_Create_Chaos_Idle_Attack_Armies)
	Rule_Check_Remove(Rule_IG_Count_At_Area3)
end

end


--[[generates the chaos forces dedicated to destroying the player's generators]] function Rule_Chaos_Generator_Raiders()

if EGroup_Exists("eg_chaos_production1") and EGroup_IsEmpty("eg_chaos_production1") == false then 
	for i = 1, 1 do
		if SGroup_Exists("sg_chaos_generator_raider_squad"..i) == false or SGroup_IsEmpty("sg_chaos_generator_raider_squad"..i) then
			if EGroup_Exists("eg_generators"..i) and EGroup_IsEmpty("eg_generators"..i) == false then
				if Entity_GetBuildingProgress(EGroup_GetSpawnedEntityAt(EGroup_FromName("eg_generators"..i), 1)) == 1.0 then
				
					Util_CreateSquadsAtMarkerEx(g_Player3, "sg_chaos_generator_raider_squad"..i, "chaos_squad_raptor", "mkr_chaos_origin"..i, 1, 8)
					Cmd_AttackEGroup("sg_chaos_generator_raider_squad"..i, "eg_generators"..i)
				
				end
			end
		end
	end
end

if EGroup_Exists("eg_chaos_production2") and EGroup_IsEmpty("eg_chaos_production2") == false then 
	for i = 2, 3 do
		if SGroup_Exists("sg_chaos_generator_raider_squad"..i) == false or SGroup_IsEmpty("sg_chaos_generator_raider_squad"..i) then
			if EGroup_Exists("eg_generators"..i) and EGroup_IsEmpty("eg_generators"..i) == false then
				if Entity_GetBuildingProgress(EGroup_GetSpawnedEntityAt(EGroup_FromName("eg_generators"..i), 1)) == 1.0 then
				
					Util_CreateSquadsAtMarkerEx(g_Player3, "sg_chaos_generator_raider_squad"..i, "chaos_squad_raptor", "mkr_chaos_origin"..i, 1, 8)
					Cmd_AttackEGroup("sg_chaos_generator_raider_squad"..i, "eg_generators"..i)
				
				end
			end
		end
	end
end

end

--[[kicks off the raptor squads attacking the main base]] function Rule_Chaos_Jump_Attack_Launch()

if g_generator_built_count == 2 then
	
	Util_CreateSquadsAtMarkerEx(g_Player3, "sg_chaos_jumpers", "chaos_squad_raptor", "mkr_chaos_raptors", 1, 12)
	SGroup_SetMoraleInvulnerable( "sg_chaos_jumpers", true)
	
	Cmd_JumpToMarker("sg_chaos_jumpers", "mkr_chaos_jump")
	g_jumped = true
	Rule_AddInterval(Rule_Chaos_Jump_Attack, 45)
	Rule_Remove(Rule_Chaos_Jump_Attack_Launch)
	
end

end

function Rule_Chaos_Jump_Attack()

if SGroup_Exists("sg_chaos_jumpers") == false and SGroup_IsEmpty("sg_chaos_jumpers") == true and g_jumped == false then -- and g_necrons_appeared == false 
	
	Util_CreateSquadsAtMarkerEx(g_Player3, "sg_chaos_jumpers", "chaos_squad_raptor", "mkr_chaos_raptors", 1, 12)
	SGroup_SetMoraleInvulnerable( "sg_chaos_jumpers", true)
	
	Cmd_JumpToMarker("sg_chaos_jumpers", "mkr_chaos_jump")
	g_jumped = true
	Rule_AddOneShot(Rule_Chaos_Jump_Attack2, 8)
	
elseif SGroup_Exists("sg_chaos_jumpers") and SGroup_IsEmpty("sg_chaos_jumpers") == false and g_jumped == true then
	
	Rule_AddOneShot(Rule_Chaos_Jump_Attack2, 8)
	
end

end

function Rule_Chaos_Jump_Attack2()

if SGroup_Exists("sg_chaos_jumpers") and SGroup_IsEmpty("sg_chaos_jumpers") == false then --and g_necrons_appeared == false -- (Prox_AnySquadNearMarker("sg_chaos_jumpers", "mkr_chaos_jump") == true)
	
	Cmd_SetStance("sg_chaos_jumpers", STANCE_Burn)
	
	if SGroup_CheckActiveCommand("sg_chaos_jumpers", SQUADSTATEID_Idle, true) then
		Cmd_AttackMoveMarker("sg_chaos_jumpers", "mkr_imperial_guard_base")
	end
	
	g_jumped = false 
	
elseif g_necrons_appeared == true then
	
	Rule_Remove(Rule_Chaos_Jump_Attack)
	
end

if g_necrons_appeared == true then 
	
	Rule_Remove(Rule_Chaos_Jump_Attack)
	
end

end

--[[Ork Army Creation]] function Rule_Ork_Army_Kickoff() -- Creates orks to attack the titan -- NOTE TO SELF: USE FOR LOOP

Player_GrantResearch(g_Player2, "ork_research_eavy_armor_boyz")
Player_GrantResearch(g_Player2, "ork_research_stikk_bombs")
Player_GrantResearch(g_Player2, "ork_research_moredakka")
Player_GrantResearch(g_Player2, "ork_research_morechoppy")
Player_GrantResearch(g_Player2, "ork_research_tougherorks")	

--[[	
sgroup_ork_attackers5 = Util_CreateSquadsAtMarkerEx(g_Player2, "sg_ork_attackers5", "ork_squad_slugga", "mkr_ork_tank_raid", 1, 6)
SGroup_AddLeaders("sg_ork_attackers5")

Cmd_AttackMoveMarker("sg_ork_attackers5", "mkr_baneblade_rescue") -- ork raiders
SGroup_SetMoraleInvulnerable( "sg_ork_attackers5", true)]]

Util_CreateSquadsAtMarkerEx(g_Player2, "sg_ork_outpost_defender1", "ork_squad_shoota_boy", "mkr_ork_outpost1", 2, 12)
Util_CreateSquadsAtMarker(g_Player2, "sg_ork_outpost_defender2", "ork_squad_armored_nob", "mkr_ork_outpost1", 1)

Util_CreateSquadsAtMarkerEx(g_Player2, "sg_ork_origin1_defender1", "ork_squad_shoota_boy", "mkr_ork_origin1", 3, 6)
Util_CreateSquadsAtMarker(g_Player2, "sg_ork_origin1_defender2", "ork_squad_looted_tank", "mkr_ork_origin1", 2)
Util_CreateSquadsAtMarker(g_Player2, "sg_ork_origin1_defender2", "ork_squad_armored_nob", "mkr_ork_origin1", 1)

Util_CreateSquadsAtMarkerEx(g_Player2, "sg_ork_origin2_defender1", "ork_squad_shoota_boy", "mkr_ork_origin2", 3, 6)
Util_CreateSquadsAtMarker(g_Player2, "sg_ork_origin2_defender2", "ork_squad_looted_tank", "mkr_ork_origin2", 2)
Util_CreateSquadsAtMarker(g_Player2, "sg_ork_origin2_defender2", "ork_squad_armored_nob", "mkr_ork_origin2", 1)

end

function Rule_Ork_Outpost_Track() if EGroup_Exists("eg_ork_outpost_production1") and EGroup_IsEmpty("eg_ork_outpost_production1") == false then if SGroup_Exists("sg_ork_outpost_defender1") and SGroup_IsEmpty("sg_ork_outpost_defender1") and EGroup_Exists("eg_ork_outpost_production1") and EGroup_IsEmpty("eg_ork_outpost_production1") == false then Util_CreateSquadsAtMarkerEx(g_Player3, "sg_ork_outpost_defender1", "ork_squad_slugga", "mkr_ork_outpost1", 2, 12) end elseif EGroup_Exists("eg_ork_outpost_production1") and EGroup_IsEmpty("eg_ork_outpost_production1") == true then Rule_Remove(Rule_Ork_Outpost_Track) end end

function Rule_Create_Ork_Interference_Armies()

for i = 4, 6 do
	
	-- this will be used to make a call to the squadsize parameter
	local dif = 1
	
	--if EGroup_IsCapturedByPlayer( "eg_capture_"..i, g_Player1, true)  then --and g_initial_attack_started == false
	if g_interference_wave == 1 then 
		
		if t_interference_armies.areanumber[i].count > 0 then
			
			if SGroup_Exists(t_interference_armies.sgroup[i]) == false or SGroup_IsEmpty(t_interference_armies.sgroup[i]) then
				
				--SGroup_CreateIfNotFound(t_interference_armies.sgroup[i])
				
				local blueprint_list = {"ork_squad_slugga", "ork_squad_shoota_boy"}
					
					--[[here we set 'dif' to use one of the squadsize parameters
					if t_interference_armies.areanumber[i].count >= 1 and t_interference_armies.areanumber[i].count <= 4 then
						--dif = 1
					else]]
					if t_interference_armies.areanumber[i].count >= 4 and t_interference_armies.areanumber[i].count <= 6 then
						dif = 2
						blueprint_list = {"ork_squad_slugga", "ork_squad_shoota_boy", "ork_squad_nob", "ork_squad_stormboy"}
					elseif t_interference_armies.areanumber[i].count >= 7  then --and t_interference_armies.areanumber[i].count <= 8
						dif = 3
						blueprint_list = {"ork_squad_slugga", "ork_squad_shoota_boy", "ork_squad_nob", "ork_squad_stormboy"}
					end
					--print("i = "..i.." and dif = "..dif)
					--print(t_interference_armies.squadsize[i][dif])
					
					for n = 1, t_interference_armies.squadsize[i][dif] do
						
						-- rand1 to be used with the blue print table	
						local rand1 = World_GetRand(1, table.getn(blueprint_list))
						-- rand2 is to be used for the squad sizes
						local rand2 = World_GetRand(6, 10)
						
						
						Util_CreateSquadsAtMarkerEx(g_Player2, t_interference_armies.sgroup[i], blueprint_list[rand1], t_interference_armies.sourcearea[i], 1, rand2)
						Cmd_AttackMoveMarker(t_interference_armies.sgroup[i], t_interference_armies.targetarea_destination[i])
						
						
					end
					
				--print("wave 1")
				g_interference_wave = g_interference_wave + 1
				Rule_Remove(Rule_Create_Chaos_Interference_Armies)
				Rule_AddIntervalDelay(Rule_Create_Ork_Interference_Armies_2nd_Wave, 100, 1)
				
				g_orks_activated = true
				g_initial_attack_destination = i
				
				Rule_Remove(Rule_Create_Ork_Interference_Armies)
				break
			end
			
		end
		
		
	end
	
end

end

function Rule_Create_Ork_Interference_Armies_2nd_Wave()

local dif = 1

--if EGroup_IsCapturedByPlayer( "eg_capture_"..i, g_Player1, true)  then --and g_initial_attack_started == false
if g_interference_wave == 2 then 
	
	--print(t_interference_armies.areanumber[g_initial_attack_destination].count)
	
	if t_interference_armies.areanumber[g_initial_attack_destination].count > 0  then
		
		--print("count is greater than zero")
			--g_initial_attack_destination = t_interference_armies.targetarea[i]
			
		if SGroup_Exists(t_interference_armies.sgroup[g_initial_attack_destination]) == false or SGroup_IsEmpty(t_interference_armies.sgroup[g_initial_attack_destination]) then
			
			--print("making squads")
			--SGroup_CreateIfNotFound(t_interference_armies.sgroup[i])
			
			local blueprint_list = {"ork_squad_slugga", "ork_squad_shoota_boy"}
			
			--[[here we set 'dif' to use one of the squadsize parameters
			if t_interference_armies.areanumber[i].count >= 1 and t_interference_armies.areanumber[i].count <= 4 then
				--dif = 1
			else]]if t_interference_armies.areanumber[g_initial_attack_destination].count >= 4 and t_interference_armies.areanumber[g_initial_attack_destination].count <= 6 then
				dif = 2
				blueprint_list = {"ork_squad_slugga", "ork_squad_shoota_boy", "ork_squad_nob", "ork_squad_stormboy"}
			elseif t_interference_armies.areanumber[g_initial_attack_destination].count >= 7  then --and t_interference_armies.areanumber[i].count <= 8
				dif = 3
				blueprint_list = {"ork_squad_slugga", "ork_squad_shoota_boy", "ork_squad_nob", "ork_squad_stormboy"}
			end
			
			--print(t_interference_armies.squadsize[g_initial_attack_destination][dif])
				
			for n = 1, t_interference_armies.squadsize[g_initial_attack_destination][dif] do
				
				-- rand1 to be used with the blue print table	
				local rand1 = World_GetRand(1, table.getn(blueprint_list))
				-- rand2 is to be used for the squad sizes
				local rand2 = World_GetRand(8, 12)
						
				--print(t_interference_armies.sourcearea[i])
				Util_CreateSquadsAtMarkerEx(g_Player2, t_interference_armies.sgroup[g_initial_attack_destination], blueprint_list[rand1], t_interference_armies.sourcearea[g_initial_attack_destination], 1, rand2)
				Cmd_AttackMoveMarker(t_interference_armies.sgroup[g_initial_attack_destination], t_interference_armies.targetarea_destination[g_initial_attack_destination])
				
			end
				
			--break
			--print("wave 2")
			g_interference_wave = g_interference_wave + 1
			Rule_AddIntervalDelay(Rule_Create_Ork_Interference_Armies_3rd_Wave, 100, 1)
			Rule_Remove(Rule_Create_Ork_Interference_Armies_2nd_Wave)
			
		end
		
	end
	
end

end

function Rule_Create_Ork_Interference_Armies_3rd_Wave()

local dif = 1
--if EGroup_IsCapturedByPlayer( "eg_capture_"..i, g_Player1, true)  then --and g_initial_attack_started == false

if g_interference_wave == 3 then 
	
	if t_interference_armies.areanumber[g_initial_attack_destination].count > 0  then
		
		--g_initial_attack_destination = t_interference_armies.targetarea[i]
		if SGroup_Exists(t_interference_armies.sgroup[g_initial_attack_destination]) == false or SGroup_IsEmpty(t_interference_armies.sgroup[g_initial_attack_destination]) then
				
			--SGroup_CreateIfNotFound(t_interference_armies.sgroup[i])
				
			local blueprint_list = {"ork_squad_slugga", "ork_squad_shoota_boy"}
				
			--[[here we set 'dif' to use one of the squadsize parameters
			if t_interference_armies.areanumber[i].count >= 1 and t_interference_armies.areanumber[i].count <= 4 then
			--dif = 1
			else]]if t_interference_armies.areanumber[g_initial_attack_destination].count >= 4 and t_interference_armies.areanumber[g_initial_attack_destination].count <= 6 then
				dif = 2
				blueprint_list = {"ork_squad_slugga", "ork_squad_shoota_boy", "ork_squad_nob", "ork_squad_stormboy"}
			elseif t_interference_armies.areanumber[g_initial_attack_destination].count >= 7  then --and t_interference_armies.areanumber[i].count <= 8
				
				dif = 3
				blueprint_list = {"ork_squad_slugga", "ork_squad_shoota_boy", "ork_squad_nob", "ork_squad_stormboy"}
			end
			
			--print("i = "..i.." and dif = "..dif)
			--print(t_interference_armies.squadsize[g_initial_attack_destination][dif])
			
			for n = 1, t_interference_armies.squadsize[g_initial_attack_destination][dif] do
				-- rand1 to be used with the blue print table	
				local rand1 = World_GetRand(1, table.getn(blueprint_list))
				-- rand2 is to be used for the squad sizes
				local rand2 = World_GetRand(10, 12)
				
				Util_CreateSquadsAtMarkerEx(g_Player2, t_interference_armies.sgroup[g_initial_attack_destination], blueprint_list[rand1], t_interference_armies.sourcearea[g_initial_attack_destination], 1, rand2)
				Cmd_AttackMoveMarker(t_interference_armies.sgroup[g_initial_attack_destination], t_interference_armies.targetarea_destination[g_initial_attack_destination])
				
			end
				
			--break
			--print("wave 3")
			g_interference_wave = g_interference_wave + 1
			
			Rule_Check_AddInterval(Rule_IG_Count_At_Area2, 10)
			Rule_AddIntervalDelay(Rule_Create_Chaos_Counter_Attack_Armies, 100, 2)
			Rule_AddIntervalDelay(Rule_Create_Ork_Counter_Attack_Armies, 100, 1)
			
			Rule_Remove(Rule_Create_Ork_Interference_Armies_3rd_Wave)
			Rule_Check_Remove(Rule_IG_Count_At_Area) -- removes the counter function that isn't needed anymore
			
		end
			
	end
	
end

end

function Rule_Create_Ork_Counter_Attack_Armies()

local l_random_ork_counter_attack_area = World_GetRand(4, 6)

--for i = 4, 6 do
	
-- this will be used to make a call to the squadsize parameter
	local dif = 1
	
	if t_counter_attack_armies.areanumber[l_random_ork_counter_attack_area].count >= 0 then --and t_interference_armies.areanumber[l_random_ork_counter_attack_area].count < 5
		
		if SGroup_Exists(t_counter_attack_armies.sgroup[l_random_ork_counter_attack_area]) == false or SGroup_IsEmpty(t_counter_attack_armies.sgroup[l_random_ork_counter_attack_area]) then
			
			local blueprint_list = {"ork_squad_slugga", "ork_squad_shoota_boy"}
			
			--[[ here we set 'dif' to use one of the squadsize parameters
			if t_counter_attack_armies.areanumber[l_random_ork_counter_attack_area].count >= 1 and t_counter_attack_armies.areanumber[l_random_ork_counter_attack_area].count <= 4 then
				dif = 1
			else]]
			
			if t_counter_attack_armies.areanumber[l_random_ork_counter_attack_area].count >= 3 and t_counter_attack_armies.areanumber[l_random_ork_counter_attack_area].count <= 6 then
				dif = 2
				blueprint_list = {"ork_squad_slugga", "ork_squad_shoota_boy", "ork_squad_nob", "ork_squad_stormboy"}
			elseif t_counter_attack_armies.areanumber[l_random_ork_counter_attack_area].count >= 7 then --and t_counter_attack_armies.areanumber[l_random_ork_counter_attack_area].count <= 8
				dif = 3
				blueprint_list = {"ork_squad_slugga", "ork_squad_shoota_boy", "ork_squad_nob", "ork_squad_stormboy"}
			end
			
			--print("orks counter")
			--print("i = "..i.." and dif = "..dif)
			--print(t_counter_attack_armies.squadsize[l_random_ork_counter_attack_area][dif])
			
			
			for n = 1, t_counter_attack_armies.squadsize[l_random_ork_counter_attack_area][dif] do
				
				-- rand1 to be used with the blue print table
				local rand1 = World_GetRand(1, table.getn(blueprint_list))
				-- rand2 is to be used for the squad sizes
				local rand2 = World_GetRand(6, 15)
				
				Util_CreateSquadsAtMarkerEx(g_Player2, t_counter_attack_armies.sgroup[l_random_ork_counter_attack_area], blueprint_list[rand1], t_counter_attack_armies.sourcearea[l_random_ork_counter_attack_area], 1, rand2)
				Cmd_AttackMoveMarker(t_counter_attack_armies.sgroup[l_random_ork_counter_attack_area], t_counter_attack_armies.targetarea_destination[l_random_ork_counter_attack_area])
				
			end
			
			--break
			
		end
		
	end
	
--end

if g_necrons_appeared == true then
	Rule_Remove(Rule_Create_Ork_Counter_Attack_Armies)
	Rule_Check_Remove(Rule_IG_Count_At_Area2)
end

end

--[[generates ork forces dedicated to destroying the player's generators]] function Rule_Ork_Generator_Raiders() if EGroup_Exists("eg_ork_production1") and EGroup_IsEmpty("eg_ork_production1") == false then for i = 4, 4 do if SGroup_Exists("sg_ork_generator_raider_squad"..i) == false or SGroup_IsEmpty("sg_ork_generator_raider_squad"..i) then if EGroup_Exists("eg_generators"..i) and EGroup_IsEmpty("eg_generators"..i) == false then if Entity_GetBuildingProgress(EGroup_GetSpawnedEntityAt(EGroup_FromName("eg_generators"..i), 1)) == 1.0 then

					Util_CreateSquadsAtMarkerEx(g_Player3, "sg_ork_generator_raider_squad"..i, "ork_squad_stormboy", "mkr_ork_origin"..i, 1, 6)
					Cmd_AttackEGroup("sg_ork_generator_raider_squad"..i, "eg_generators"..i)
				
				end
			end
		end
	end
end

if EGroup_Exists("eg_ork_production2") and EGroup_IsEmpty("eg_ork_production2") == false then
	for i = 5, 6 do
		if SGroup_Exists("sg_ork_generator_raider_squad"..i) == false or SGroup_IsEmpty("sg_ork_generator_raider_squad"..i) then
			if EGroup_Exists("eg_generators"..i) and EGroup_IsEmpty("eg_generators"..i) == false then
				if Entity_GetBuildingProgress(EGroup_GetSpawnedEntityAt(EGroup_FromName("eg_generators"..i), 1)) == 1.0 then
				
					Util_CreateSquadsAtMarkerEx(g_Player3, "sg_ork_generator_raider_squad"..i, "ork_squad_stormboy", "mkr_ork_origin"..i, 1, 6)
					Cmd_AttackEGroup("sg_ork_generator_raider_squad"..i, "eg_generators"..i)
				
				end
			end
		end
	end
end

end


--Ork Idle Attacks -- For when the player sits at his/her base and idles for a long time

--[[ function Rule_Create_Ork_Idle_Attack_Armies_Kickoff() if g_idle_attack == false then Rule_AddOneShot(Rule_Create_Ork_Idle_Attack_Armies_Random_Start_Generator, 1) g_idle_attack = true Rule_Remove(Rule_Create_Ork_Idle_Attack_Armies_Kickoff) end end]]

function Rule_Create_Ork_Idle_Attack_Armies_Random_Start_Generator() -- generates the Ork attacks that will occur if the player sits at their base and does nothing. if g_orks_activated == false then

	g_initial_attack_destination = World_GetRand(4, 6)

	local l_start_time = World_GetRand(10, 30)
	
	Rule_Check_AddInterval(Rule_IG_Count_At_Area3, 10, l_start_time)
	Rule_AddIntervalDelay(Rule_Create_Ork_Idle_Attack_Armies, 45, l_start_time + 1)
elseif g_orks_activated == true then
	Rule_Remove(Rule_Create_Ork_Idle_Attack_Armies_Random_Start_Generator)
end

end

function Rule_Create_Ork_Idle_Attack_Armies() -- Thank you, Mr. Degnan

-- this will be used to make a call to the squadsize parameter
local dif = 1

if SGroup_Exists(t_idle_attack_armies.sgroup[g_initial_attack_destination]) == false or SGroup_IsEmpty(t_idle_attack_armies.sgroup[g_initial_attack_destination]) then
	
	--SGroup_CreateIfNotFound(t_idle_attack_armies.sgroup[i])
	
	local blueprint_list = {"ork_squad_slugga", "ork_squad_shoota_boy"}
	
	--[[here we set 'dif' to use one of the squadsize parameters
	if t_idle_attack_armies.areanumber[i].count >= 1 and t_idle_attack_armies.areanumber[i].count <= 4 then
	--dif = 1
	else]]
	
	if t_idle_attack_armies.areanumber[g_initial_attack_destination].count >= 4 and t_idle_attack_armies.areanumber[g_initial_attack_destination].count <= 6 then
		dif = 2
		blueprint_list = {"ork_squad_slugga", "ork_squad_shoota_boy", "ork_squad_stormboy"} -- "ork_squad_nob"
	elseif t_idle_attack_armies.areanumber[g_initial_attack_destination].count >= 7  then --and t_idle_attack_armies.areanumber[i].count <= 8
		dif = 3
		blueprint_list = {"ork_squad_slugga", "ork_squad_shoota_boy", "ork_squad_stormboy"} -- "ork_squad_nob"
	end
	
	--print("i = "..i.." and dif = "..dif)
	--print(t_idle_attack_armies.squadsize[g_initial_attack_destination][dif])
	
	for n = 1, t_idle_attack_armies.squadsize[g_initial_attack_destination][dif] do
		
		-- rand1 to be used with the blue print table	
		local rand1 = World_GetRand(1, table.getn(blueprint_list))
		-- rand2 is to be used for the squad sizes
		local rand2 = World_GetRand(6, 10)
		Util_CreateSquadsAtMarkerEx(g_Player2, t_idle_attack_armies.sgroup[g_initial_attack_destination], blueprint_list[rand1], t_idle_attack_armies.sourcearea[g_initial_attack_destination], 1, rand2)
		Cmd_AttackMoveMarker(t_idle_attack_armies.sgroup[g_initial_attack_destination], t_idle_attack_armies.targetarea_destination[g_initial_attack_destination])
		
		
	end
	
	--break
	--	print("wave 1")
	--g_interference_wave = g_interference_wave + 1
	--Rule_Remove(Rule_Create_Chaos_Interference_Armies)
	--Rule_AddIntervalDelay(Rule_Create_Ork_Interference_Armies_2nd_Wave, 45, 1)
				
	--g_idle_attack = true
	Rule_AddOneShot(Rule_Create_Ork_Idle_Attack_Armies_Random_Start_Generator, 1)
	--print(g_orks_activated)
	Rule_Remove(Rule_Create_Ork_Idle_Attack_Armies)
	Rule_Check_Remove(Rule_IG_Count_At_Area3)
	
end

end


--[[governs the generation of enemy armies]] function Rule_Enemy_Army_Activity_Kickoff()

Rule_AddIntervalDelay(Rule_IG_Count_At_Area, 10, 1)

local l_ork_or_chaos = World_GetRand(1, 2) -- makes the game choose a random number.  1  = chaos and 2 = orks

if l_ork_or_chaos == 1 then -- if the game chose 1, then use Chaos idle attacks 
	Rule_AddOneShot(Rule_Create_Chaos_Idle_Attack_Armies_Random_Start_Generator, 60) -- A gentle reminder to the player if they are turtling in the center of the base
elseif l_ork_or_chaos == 2 then -- if the game chose 2, then use Ork idle attacks
	Rule_AddOneShot(Rule_Create_Ork_Idle_Attack_Armies_Random_Start_Generator, 60) -- A gentle reminder to the player if they are turtling in the center of the base
end

Rule_AddIntervalDelay(Rule_Create_Chaos_Interference_Armies, 100, 1) 
Rule_AddIntervalDelay(Rule_Create_Ork_Interference_Armies, 100, 1)
Rule_AddIntervalDelay(Rule_Chaos_Generator_Raiders, 30, 2)
Rule_AddIntervalDelay(Rule_Ork_Generator_Raiders, 30, 2)
Rule_AddIntervalDelay(Rule_Chaos_Outpost_Track, 20, 3)
Rule_AddIntervalDelay(Rule_Chaos_Jump_Attack_Launch, 5, 3)

end

--[[Necron Army Creation]] function Rule_Necron_Army_Kickoff() for i = 2,6 do t_sgroupnecronbattlegroup[i] = SGroup_CreateIfNotFound("sg_necron_battlegroup"..i) t_sgroup_necron_attackers[i] = Util_CreateSquadsAtMarkerEx(g_Player4, "sg_necron_attackers"..i, "npc_necron_warrior", "mkr_necron_origin"..i, 2, 12) t_sgroup_necron_monolith[i] = Util_CreateSquadsAtMarker(g_Player4, "sg_necron_monolith"..i, "npc_necron_monolith", "mkr_necron_origin"..i, 1, 1) --FOW_RevealSGroup(t_sgroup_necron_monolith[i], 10 ) Cmd_AttackMoveMarker("sg_necron_attackers"..i, "mkr_monolith_destination"..i.."a") Cmd_AttackMoveMarker("sg_necron_monolith"..i, "mkr_monolith_destination"..i.."a") Util_Ping_LoopingMkr("ping_monolith"..i, "mkr_necron_origin"..i) SGroup_AddGroup(t_sgroupnecronbattlegroup[i], t_sgroup_necron_attackers[i]) SGroup_AddGroup(t_sgroupnecronbattlegroup[i], t_sgroup_necron_monolith[i]) --FOW_RevealSGroup("sg_necron_monolith"..i, 30 ) --FOW_RevealSGroup("sg_necron_monolith1", 30 )

	FOW_TagSGroup(g_Player1, SGroup_FromName("sg_necron_monolith"..i ))
end

Rule_Check_AddInterval(Rule_Necron_Army_Track, 1) -- tracks the rest of the necron army
Rule_Check_AddInterval(Rule_Necron_Monolith_Track, 1) -- tracks monoliths
Rule_Check_AddInterval(Rule_Necron_Focus, 5) -- keeps necrons focused 

Rule_AddOneShot(Rule_Monolith_Ping_Remove, 30)
--Rule_AddInterval(Rule_Necron_Monolith_Reveal, 10)

end --[[ function Rule_Necron_Monolith_Reveal() for i = 1, 6 do if SGroup_Exists("sg_necron_monolith"..i) and SGroup_IsEmpty("sg_necron_monolith"..i) == false then FOW_Reset() FOW_RevealSGroup("sg_necron_monolith"..i, 10 ) end end end]]

function Rule_Monolith_Ping_Remove() for i = 1, 6 do Util_Ping_Stop("ping_monolith"..i) -- ping_monolith1 was defined in NIS! end end

--[[generates necrons when their sgroups are dead]] function Rule_Necron_Army_Track() for i = 1, 6 do if g_necron_attack_escalation == false and (SGroup_IsEmpty("sg_necron_attackers"..i) and SGroup_IsEmpty("sg_necron_monolith"..i) == false) then -- will only regenerate when monoliths are alive t_sgroup_necron_attackers[i] = Util_CreateSquadsAtPositionEx(g_Player4, "sg_necron_attackers"..i, "npc_necron_warrior", SGroup_GetPosition(t_sgroup_necron_monolith[i]), 2, 12) Cmd_AttackMoveMarker("sg_necron_attackers"..i, "mkr_imperial_guard_base") elseif g_necron_attack_escalation == true and (SGroup_IsEmpty("sg_necron_attackers"..i) and SGroup_IsEmpty("sg_necron_monolith"..i) == false) then t_sgroup_necron_attackers[i] = Util_CreateSquadsAtPositionEx(g_Player4, "sg_necron_attackers"..i, "npc_necron_warrior", SGroup_GetPosition(t_sgroup_necron_monolith[i]), 2, 12) Cmd_AttackMoveMarker("sg_necron_attackers"..i, "mkr_imperial_guard_base") end end

end

--[[focuses Necrons on their destinations determined by marker]] function Rule_Necron_Focus()

if g_necron_attack_escalation == false then
	
	for i = 1, 6 do
		if SGroup_Exists("sg_necron_attackers"..i) and SGroup_IsEmpty("sg_necron_attackers"..i) == false then
			if SGroup_CheckActiveCommand("sg_necron_attackers"..i, SQUADSTATEID_Idle, false) then
				Cmd_AttackMoveMarker("sg_necron_attackers"..i, "mkr_imperial_guard_base")
			end
		end
		
		if SGroup_Exists("sg_necron_monolith"..i) and SGroup_IsEmpty("sg_necron_monolith"..i) == false then
			if SGroup_CheckActiveCommand("sg_necron_monolith"..i, SQUADSTATEID_Idle, false) then
				Cmd_AttackMoveMarker("sg_necron_monolith"..i, "mkr_monolith_destination"..i.."a")
			end
		end
		
		
	end
	
elseif g_necron_attack_escalation == true then
	
	for i = 1, 6 do
		if SGroup_Exists("sg_necron_attackers"..i) and SGroup_IsEmpty("sg_necron_attackers"..i) == false then
			if SGroup_CheckActiveCommand("sg_necron_attackers"..i, SQUADSTATEID_Idle, false) then
				Cmd_AttackMoveMarker("sg_necron_attackers"..i, "mkr_imperial_guard_base")
			end
		end
		
		if SGroup_Exists("sg_necron_monolith"..i) and SGroup_IsEmpty("sg_necron_monolith"..i) == false then
			if SGroup_CheckActiveCommand("sg_necron_monolith"..i, SQUADSTATEID_Idle, false) then
				Cmd_AttackMoveMarker("sg_necron_monolith"..i, "mkr_monolith_destination"..i.."b")
			end
		end
		
	end
	
end

end

--[[Tells the game which random intel event to display when a Monolith gets destroyed]] function Rule_Necron_Monolith_Track()

for i = 1, 6 do
	if (SGroup_Exists("sg_necron_monolith"..i) and SGroup_IsEmpty("sg_necron_monolith"..i)) and (t_monolith_track[i] == false) then
		t_monolith_track[i] = true
		Sound_PlayStinger("stinger_newigunit")
		g_monoliths_destroyed = g_monoliths_destroyed + 1
		
		local l_random_line_spoken = World_GetRand(1, 4)
		
		if l_random_line_spoken == 1 then
			Rule_AddOneShot(Rule_IE_Monolith_Destroyed1, 0)
		elseif l_random_line_spoken == 2 then
			Rule_AddOneShot(Rule_IE_Monolith_Destroyed2, 0)
		elseif l_random_line_spoken == 3 then
			Rule_AddOneShot(Rule_IE_Monolith_Destroyed3, 0)
		elseif l_random_line_spoken == 4 then
			Rule_AddOneShot(Rule_IE_Monolith_Destroyed4, 0)
		end
		
	end
	if g_monoliths_destroyed >= 6 then
		Rule_Remove(Rule_Necron_Monolith_Track)
	end
end

end

--[[Meeting up with beleaguered forces]]

--[[Rescue Baneblade Secondary Mission Objective Kickoff]] function Rule_Baneblade_Secondary_Mission_Objective_Kickoff() Player_GetAllSquadsNearMarker(g_Player1 , "sg_near_baneblade", "mkr_baneblade_rescue")

if Prox_AnySquadNearMarker("sg_near_baneblade", "mkr_baneblade_secondary_mission_objective_kickoff_radius") or g_generator_built_count >= 2 then
	--Player_SetTeam( g_Player5, 0)
	Rule_AddOneShot(Rule_IE_Give_Secondary_Objective, 1)
	Rule_AddInterval(Rule__Objective_Rescue_Baneblade, 1)
	Rule_AddInterval(Rule_BaneBladeRescueControl, 1)
	Rule_AddOneShot(Rule_Ork_Tank_Raid_Kickoff, 2)
	Rule_Remove(Rule_Baneblade_Secondary_Mission_Objective_Kickoff)
	
end

end

function Rule_Ork_Tank_Raid_Kickoff() -- sets up Ork attack on the Baneblade

sgroup_ork_attackers5 = Util_CreateSquadsAtMarkerEx(g_Player2, "sg_ork_attackers5", "ork_squad_slugga", "mkr_ork_tank_raid", 1, 6)
SGroup_AddLeaders("sg_ork_attackers5")
Cmd_AttackMoveMarker("sg_ork_attackers5", "mkr_baneblade_rescue") -- ork raiders
SGroup_SetMoraleInvulnerable( "sg_ork_attackers5", true)
Rule_AddInterval(Rule_Ork_Tank_Raid_Track, 30)

end

function Rule_Ork_Tank_Raid_Track() -- tracks the Orks attacking the baneblade. If they are destroyed, new orks will spawn to replace them.

if EGroup_Exists("eg_ork_tank_raid_production") and EGroup_IsEmpty("eg_ork_tank_raid_production") == false then

	if SGroup_IsEmpty("sg_ork_attackers5") and (g_baneblade_owned_by_player == false) and g_necrons_appeared == false then
		sgroup_ork_attackers5 = Util_CreateSquadsAtMarkerEx(g_Player2, "sg_ork_attackers5", "ork_squad_slugga", "mkr_ork_tank_raid", 3, 12)
		SGroup_SetMoraleInvulnerable( "sg_ork_attackers5", true)
		SGroup_AddLeaders("sg_ork_attackers5")
		Cmd_AttackMoveMarker("sg_ork_attackers5", "mkr_baneblade_rescue")
		if SGroup_Exists("sg_need_rescue1") and SGroup_IsEmpty("sg_need_rescue1") == false then
			Cmd_AttackSGroup("sg_ork_attackers5", "sg_need_rescue1")
		elseif SGroup_Exists("sg_need_rescue1") and SGroup_IsEmpty("sg_need_rescue1") == true then
			Cmd_AttackEGroup("sg_ork_attackers5", "eg_outside_infantry")
		end
	
	elseif (g_necrons_appeared == true) and (g_baneblade_owned_by_player == true) then
		Rule_Remove(Rule_Ork_Tank_Raid_Track)
	end

	if SGroup_Exists("sg_ork_attackers5") and SGroup_IsEmpty("sg_ork_attackers5") == false then
		if SGroup_CheckActiveCommand("sg_ork_attackers5", SQUADSTATEID_Idle, true) then
			if SGroup_Exists("sg_need_rescue1") and SGroup_IsEmpty("sg_need_rescue1") == false then
				Cmd_AttackSGroup("sg_ork_attackers5", "sg_need_rescue1")
			elseif SGroup_Exists("sg_need_rescue1") and SGroup_IsEmpty("sg_need_rescue1") == true then
				Cmd_AttackEGroup("sg_ork_attackers5", "eg_outside_infantry")
			end
		end
	end

elseif EGroup_Exists("eg_ork_tank_raid_production") and EGroup_IsEmpty("eg_ork_tank_raid_production") == true then
	Rule_Remove(Rule_Ork_Tank_Raid_Track)
end

end

--[[Rescue Baneblade Check and Take Over Functions]] function Rule_BaneBladeRescueControl()

--local pos = Marker_GetPosition(Marker_FromName("mkr_baneblade_rescue", "basic_marker"))
Player_GetAllSquadsNearMarker(g_Player1 , "sg_near_baneblade", "mkr_baneblade_rescue")

if Prox_AnySquadNearMarker("sg_near_baneblade", "mkr_baneblade_rescue") then
	if EGroup_Exists("eg_baneblade_building") and EGroup_IsEmpty("eg_baneblade_building") == false then
		EGroup_SetPlayerOwner("eg_baneblade_building", g_Player1)
	end
	if EGroup_Exists("eg_outside_infantry") and EGroup_IsEmpty("eg_outside_infantry") == false then
		EGroup_SetPlayerOwner("eg_outside_infantry", g_Player1)
	end
	if SGroup_Exists("sg_need_rescue1") and SGroup_IsEmpty("sg_need_rescue1") == false then
		SGroup_SetPlayerOwner("sg_need_rescue1", g_Player1)
	end
	if SGroup_Exists("sg_russ_rescue1") and SGroup_IsEmpty("sg_russ_rescue1") == false then
		SGroup_SetPlayerOwner("sg_russ_rescue1", g_Player1)
	end
	if SGroup_Exists("sg_russ_rescue2") and SGroup_IsEmpty("sg_russ_rescue2") == false then
		SGroup_SetPlayerOwner("sg_russ_rescue2", g_Player1)
	end

	Rule_AddInterval(Rule_BaneBladeRepairControl, 1)
	Rule_AddOneShot(Rule_IE_Baneblade_Men_Rescued, 0)
	Rule_Remove(Rule_BaneBladeRescueControl)
end
SGroup_Destroy(SGroup_FromName("sg_near_baneblade"))

end

function Rule_BaneBladeRepairControl() -- controls what happens when the baneblade building gets repaired. Basically everything in its local area gets switched over ot player 1

if EGroup_GetAvgHealth("eg_baneblade_building") == 1.0 then
	
	Util_CreateSquadsAtMarker(g_Player1, "sg_baneblade1", "guard_squad_baneblade", "mkr_baneblade_spawn", 1)
	g_baneblade_owned_by_player = true
	Player_UnRestrictSquad(g_Player1, "guard_squad_baneblade") 
	Player_UnRestrictBuilding(g_Player1, "guard_mars_pattern")
	Rule_Remove(Rule_BaneBladeRepairControl)
	
end

if EGroup_GetAvgHealth("eg_baneblade_building") == 0.0 then
	
	g_baneblade_base_destroyed = true
	Util_Ping_Stop("ping_banebladelocation")
	Rule_Remove(Rule_BaneBladeRepairControl)
	
end

end


--[[Generator counting stuff]]

function Rule_Generator_Counter_Display() -- displays how many generators are built UI_ShowCount("cnt_generator_number", g_Player1, 840300, 0) end

--[[calls Rule_Generator_Counter_Options to see what to do next]] function Rule_Generator_Counter()

g_generator_egroupID = (EGroup_CreateIfNotFound("eg_generators"))

for i = 1, 6 do
	
	Player_GetAllEntitiesNearMarker( g_Player1, "eg_generators"..i, "mkr_generator"..i) -- check blueprint stuff is not working, this is placeholder
	
	if EGroup_IsEmpty("eg_generators"..i) == false then
		
		if Entity_GetBuildingProgress(EGroup_GetSpawnedEntityAt(EGroup_FromName("eg_generators"..i), 1)) == 1.0 and (t_GeneratorTracker[i] == false) then
			g_generator_built_count = g_generator_built_count + 1
			UI_ShowCountUpdate("cnt_generator_number", g_generator_built_count)
			t_GeneratorTracker[i] = true
			Util_Ping_Stop("ping_generator"..i)
			
			if Objective_Exists(Objective_Build_Six_Generators.title_id) == true then
				Objective_PingRemove(Objective_Build_Six_Generators.title_id, t_obj_generator_ping[i])
			end
			
		end
		
	end
	
	if EGroup_IsEmpty("eg_generators"..i) == true and (t_GeneratorTracker[i] == true) then
		
		g_generator_built_count = g_generator_built_count - 1
		Rule_Check_AddOneShot(Rule_Generator_Destroyed_Notify, 1)
		UI_ShowCountUpdate("cnt_generator_number", g_generator_built_count)
		t_GeneratorTracker[i] = false
		Util_Ping_LoopingMkr("ping_generator"..i, "mkr_generator"..i)
		
		if Objective_Exists(Objective_Build_Six_Generators.title_id) == true then
			t_obj_generator_ping[i] = Objective_PingMarker(Objective_Build_Six_Generators.title_id, "mkr_generator"..i, true, "default")
		end
		
	end
	
end

if EGroup_Exists("eg_generators") and EGroup_IsEmpty("eg_generators") == false then
	EGroup_Destroy(EGroup_FromName("eg_generators"))
end

end

--[[determines what happens when certain numbers of generators have been reached]] function Rule_Generator_Counter_Options()

if g_generator_built_count >= 1 and g_necrons_appeared == false and g_first_generator_online == false then
	
	Rule_Check_AddOneShot(Rule_IE_First_Generator_Online, 0)
	
	g_first_generator_online = true
	Playlist_Manager( PC_Music, {"music_mso5i_perc"}, true , true, {1, 2})
	Rule_Add(Rule_Autosave_First_Generator_Online)
end

if g_generator_built_count >= 2 and g_necrons_appeared == false and g_second_generator_online == false then
	
	g_second_generator_online = true
	Playlist_Manager( PC_Music, {"music_mso5i_perc_choir"}, true , true, {1, 2})
	
end

if g_generator_built_count >= 3 and g_necrons_appeared == false and g_third_generator_online == false then
	
	g_third_generator_online = true
	Playlist_Manager( PC_Music, {"music_mso5i_perc_choir"}, true , true, {1, 2})
	
end

if g_generator_built_count >= 4 and g_necrons_appeared == false then
	
	--print("Generators counted")
	g_necrons_appeared = true
	Util_StartNIS( EVENTS.NIS_FIRST_MOMENT ) 
	
	Rule_Check_Remove(Rule_Create_Ork_Counter_Attack_Armies)
	Rule_Check_Remove(Rule_Create_Chaos_Counter_Attack_Armies)
	FOW_RevealMarker("mkr_titan_sensor_radius", 3600)
	Rule_AddInterval(Rule__Objective_Defeat_Necrons, 1)
	Rule_Add(Rule_Autosave_Necrons)
	
end	

if (g_generator_built_count >= 5) and (g_necrons_appeared == true) and (g_necron_attack_escalation == false) then -- and (SGroup_Exists("sg_necron_monolith1")) 
		g_necron_attack_escalation = true
		for i = 1, 6 do			
			if SGroup_Exists("sg_necron_monolith"..i) and SGroup_IsEmpty("sg_necron_monolith"..i) == false then
				Cmd_AttackMoveMarker("sg_necron_monolith"..i, "mkr_monolith_destination"..i.."b")
				--Util_Ping_Stop("ping_monolith"..i)
			end
		end
		
		for i = 1, 6 do			
			if SGroup_Exists("sg_necron_attackers"..i) and SGroup_IsEmpty("sg_necron_attackers"..i) == false then
				Cmd_AttackMoveMarker("sg_necron_attackers"..i, "mkr_imperial_guard_base")
			end
		end
		
		Rule_Check_Remove(Rule_Ork_Generator_Raiders)
		Rule_Check_Remove(Rule_Chaos_Generator_Raiders)
		
		
		--print("Monoliths to first locations.")
end

end

--[[notifies the player when a generator is destroyed]] function Rule_Generator_Destroyed_Notify() if g_six_generators_built == false then if Event_IsAnyRunning() == false then Rule_Check_AddOneShot(Rule_IE_Generator_Destroyed, 0) end elseif g_six_generators_built == true then Rule_Remove(Rule_Generator_Destroyed_Notify) end end


--[[kicks off pings around generator area]]

function Rule_Ping_Kickoff()

for i = 1, 6 do
	Util_Ping_LoopingMkr("ping_generator"..i, "mkr_generator"..i)
end

end

--[[puts titan piece animations to a certain state when needed]] function Rule_Titan_Piece_Sensors_Online_Cleanup()

Anim_PlayEGroupAnim(EGroup_FromName("eg_titan_right_leg_lower"), "o_powerup")
Anim_PlayEGroupAnim(EGroup_FromName("eg_titan_right_leg_upper"), "o_powerup")
Anim_PlayEGroupAnim(EGroup_FromName("eg_titan_left_leg_lower"), "o_powerup")
Anim_PlayEGroupAnim(EGroup_FromName("eg_titan_left_leg_upper"), "o_powerup")
Anim_PlayEGroupAnim(EGroup_FromName("eg_titan_torso"), "o_powerup")
Anim_PlayEGroupAnim(EGroup_FromName("eg_titan_skull"), "o_powerup")
Anim_PlayEGroupAnim(EGroup_FromName("eg_titan_chest"), "o_powerup")

end

--[[puts titan piece animations to a certain state when needed]] function Rule_Titan_Piece_Activation_Cleanup()

Anim_PlayEGroupAnim(EGroup_FromName("eg_titan_skull"), "o_idle")
Anim_PlayEGroupAnim("eg_titan_chest", "o_idle")
Anim_PlayEGroupAnim("eg_titan_left_arm", "o_idle")
Anim_PlayEGroupAnim("eg_titan_right_arm", "o_idle")
	

end

--[[ function Rule_Generator_Ping_Stop() -- stops pings at generator for i = 1, 6 do Util_Ping_Stop("ping_generator"..i, "mkr_generator"..i) end end]]

function Rule_Six_Generators_Activated() for i = 1, 6 do if SGroup_Exists("sg_necron_monolith"..i) and SGroup_IsEmpty("sg_necron_monolith"..i) == false then Cmd_AttackMoveMarker("sg_necron_monolith"..i, "mkr_imperial_guard_base") end --SGroup_SetHealthInvulnerable("sg_necron_monolith"..i, false) end

	Sound_PlayStinger("stinger_mso5i_titanweaponline")
	--Rule_AddOneShot(Rule_Generator_Ping_Stop, 0)
	Util_StartNIS( EVENTS.NIS_MOMENT ) 	

	for i = 1, 6 do
		EGroup_SetPlayerOwner("eg_titan_heavy_weapons"..i, g_Player1)
	end
	
	Rule_Add(Rule_Autosave_Titan_Heavy_Weapons_Online)
	

end

--[[ function Rule_Moment_Shortcut() Util_StartNIS( EVENTS.NIS_MOMENT ) --g_generator_built_count = 6 --Rule_AddOneShot(Rule_Necron_Army_Kickoff, 0) --Rule_AddOneShot(Rule_Necron_Army_Track, 0) end]]

--~ function Rule_Moment_Shortcut_Necrons() --~ g_generator_built_count = 4 --~ end

--[[ function Rule_Guns_Online() g_generator_built_count = 6 end]]

--[[ function Raptors() g_generator_built_count = 2 end]]

--[[ function Rule_End_Shortcut() Util_StartNIS(EVENTS.NIS_Closing) end]]


--[[ GAME OVER - Player Wins ]]

function Rule_EndGameWin()

if (Objective_Exists(Objective_Build_Six_Generators.title_id) and Objective_GetState(Objective_Build_Six_Generators.title_id) == OS_Complete) and
(Objective_Exists(Objective_Defeat_Necrons.title_id) and Objective_GetState(Objective_Defeat_Necrons.title_id) == OS_Complete) and 
(Objective_Exists(Objective_Base_Survive.title_id) and Objective_GetState(Objective_Base_Survive.title_id) == OS_Complete) then
	Rule_RemoveAll()
	Sound_PlayStinger("stinger_mso5i_necronsdestroyed")
	Util_StartNIS(EVENTS.NIS_Closing)
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_exceptions = 
{
	"guard_mines",
	"guard_listening_post",
	"guard_turret_heavy_bolter",
	"guard_thermo_plasma",
	--"guard_infantry"
}

g_unit_exceptions = 
{
	"guard_squad_command_squad"
	--[["space_marine_squad_terminator",
	"space_marine_squad_assault",
	"space_marine_squad_tactical",
	"space_marine_squad_rhino",]]
}


--[[ Lose because of Annihilation ]] -- Mission failure if buildings are destroyed
if g_playerHasWon == false then
--if EGroup_Exists("eg_main_base") and EGroup_IsEmpty("eg_main base") == true then --if( Player_HasBuildingsExcept(g_Player1, g_building_exceptions) == false ) then
--	if( Player_HasSquadsExcept(g_Player1, g_unit_exceptions ) == false ) and SGroup_CountDeSpawned(g_sgroupID0) == 0 then
		Rule_RemoveAll()
		Fade_Start(4, false)
		World_SetTeamWin( g_Player2, "" )
		Rule_AddIntervalEx( Rule_GameOver,5,1 )
		Rule_Remove( Rule_EndGameLose )
--	end
end

end

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


--[[ OBJECTIVES ]]

function Rule__Objective_Titan() -- titan over-objective

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Titan.title_id) == false then
	
	Util_WXP_ObjectiveCreate(Objective_Titan, true)
	
	Rule_AddInterval(Rule__Objective_Build_Six_Generators, 1)
	Rule_AddInterval(Rule__Objective_Secure_Generator_Construction_Sites, 1)
	Rule_AddInterval(Rule__Objective_Base_Survive, 1)
	
elseif Event_IsAnyRunning() == false and (g_titan_sub_objectives_completed >= 3)  then -- checks to see if all 6 generators are built.  if so, the game will assume that all generator sites are secured.
	
	Util_ObjectiveComplete(Objective_Titan.title_id)
	
	Rule_Remove(Rule__Objective_Titan)
	
end

end

function Rule__Objective_Build_Six_Generators() -- generator objective

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Build_Six_Generators.title_id) == false then
	
	Util_WXP_ObjectiveSubCreate(Objective_Build_Six_Generators, 841030)
	
	t_obj_generator_ping = {}
	
	for i = 1, 6 do
		t_obj_generator_ping[i] = Objective_PingMarker(Objective_Build_Six_Generators.title_id, "mkr_generator"..i, true, "default")
	end
		
	Rule_AddOneShot(Rule_Generator_Counter_Display, 2)
	
elseif Event_IsAnyRunning() == false and (g_generator_built_count >= 6)  then -- checks to see if Chaos base is destroyed
	--Rule_AddOneShot(Rule_IE_Heavy_Weapons_Online, 0)
	Util_ObjectiveComplete(Objective_Build_Six_Generators.title_id)
	
	for i = 1, 6 do
		Objective_PingRemove(Objective_Build_Six_Generators.title_id, t_obj_generator_ping[i])
	end
		
	Rule_AddOneShot(Rule_Six_Generators_Activated, 0)
	
	UI_HideCount("cnt_generator_number")
	g_six_generators_built = true
	
	g_titan_sub_objectives_completed = g_titan_sub_objectives_completed + 1
	
	Rule_Remove(Rule__Objective_Build_Six_Generators)
	Rule_Remove(Rule_Generator_Counter)
	--Rule_Remove(Rule_Ork_Generator_Raiders)
	--Rule_Remove(Rule_Chaos_Generator_Raiders)
			
	Rule_Check_Remove(Rule_Generator_Counter)
	Rule_Check_Remove(Rule_Generator_Counter_Options)
	
end

end

function Rule__Objective_Secure_Generator_Construction_Sites() -- secure construction site objective

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Secure_Generator_Construction_Sites.title_id) == false then
	
	Util_WXP_ObjectiveCreate(Objective_Secure_Generator_Construction_Sites, false)

	t_obj_generator_site_ping = {}
	
	for i = 1, 6 do
		t_obj_generator_site_ping[i] = Objective_PingMarker(Objective_Secure_Generator_Construction_Sites.title_id, "mkr_generator"..i, true, "default")
	end
	
	
elseif Event_IsAnyRunning() == false and (g_generator_built_count == 6)  then -- checks to see if all 6 generators are built.  if so, the game will assume that all generator sites are secured.
	
	Util_ObjectiveComplete(Objective_Secure_Generator_Construction_Sites.title_id)
	
	for i = 1, 6 do
		Objective_PingRemove(Objective_Secure_Generator_Construction_Sites.title_id, t_obj_generator_site_ping[i])
	end
	
	Rule_Remove(Rule__Objective_Secure_Generator_Construction_Sites)
	
end

end

function Rule__Objective_Defeat_Necrons() -- defeat Necrons objective

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Defeat_Necrons.title_id) == false then
	
	Util_WXP_ObjectiveSubCreate(Objective_Defeat_Necrons, 841030)
	
elseif Event_IsAnyRunning() == false and (SGroup_IsEmpty("sg_necron_monolith1") == true) and (SGroup_IsEmpty("sg_necron_monolith2") == true) and (SGroup_IsEmpty("sg_necron_monolith3") == true) 
and (SGroup_IsEmpty("sg_necron_monolith4") == true) and (SGroup_IsEmpty("sg_necron_monolith5") == true) and (SGroup_IsEmpty("sg_necron_monolith6") == true)
and (g_necrons_appeared == true) then -- checks to see if Chaos base is destroyed
	
	Util_ObjectiveComplete(Objective_Defeat_Necrons.title_id)
	
	g_titan_sub_objectives_completed = g_titan_sub_objectives_completed + 1
	g_base_survived = true 
	
	Rule_Remove(Rule__Objective_Defeat_Necrons)
	
end

end

function Rule__Objective_Rescue_Baneblade() -- rescue baneblade objective

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Rescue_Baneblade.title_id) == false then
	
	Util_WXP_ObjectiveCreate(Objective_Rescue_Baneblade, false)
	
	Util_Ping_LoopingMkr("ping_banebladelocation", "mkr_mars_facility")
	
	g_baneblade_ping = Objective_PingMarker(Objective_Rescue_Baneblade.title_id, "mkr_baneblade_rescue", true, "default")
	
elseif Event_IsAnyRunning() == false and (g_baneblade_owned_by_player == true) then
	
	Rule_AddOneShot(Rule_IE_Baneblade_Rescued, 0)
	Util_ObjectiveComplete(Objective_Rescue_Baneblade.title_id)
	
	Objective_PingRemove(Objective_Rescue_Baneblade.title_id, g_baneblade_ping)
	Util_Ping_Stop("ping_banebladelocation")
	
	Rule_Remove(Rule__Objective_Rescue_Baneblade)

elseif Event_IsAnyRunning() == false and g_baneblade_base_destroyed == true then
	
	Util_ObjectiveFail(Objective_Rescue_Baneblade.title_id)
	
	Objective_PingRemove(Objective_Rescue_Baneblade.title_id, g_baneblade_ping)
	
	Util_Ping_Stop("ping_banebladelocation")
	
	--[[ IF THIS IS A FAILURE/LOSE CONDITION - uncomment out the following
	g_playerHasWon = false
	]]
	
	Rule_Remove(Rule__Objective_Rescue_Baneblade)
	
end

end

function Rule__Objective_Base_Survive()

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Base_Survive.title_id) == false then
	
	Util_WXP_ObjectiveSubCreate(Objective_Base_Survive, 841030)
	
	g_hq_ping = Objective_PingMarker(Objective_Base_Survive.title_id, "mkr_imperial_guard_base", true, "default")
	
elseif Event_IsAnyRunning() == false and g_base_survived == true then
	
	Util_ObjectiveComplete(Objective_Base_Survive.title_id)
	
	Objective_PingRemove(Objective_Base_Survive.title_id, g_hq_ping)
	
	g_titan_sub_objectives_completed = g_titan_sub_objectives_completed + 1
	
	Rule_Remove(Rule__Objective_Base_Survive)
	
elseif Event_IsAnyRunning() == false and (EGroup_Exists("eg_main_base") and EGroup_IsEmpty("eg_main_base") == true) then
	
	g_playerHasWon = false
	
end	

end


--[[ AUTOSAVES ]]

function Rule_Autosave_MissionStart()

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

end

function Rule_Autosave_First_Generator_Online()

if not Event_IsAnyRunning() then
	Util_Autosave( "$840202" )
	Rule_Remove(Rule_Autosave_First_Generator_Online)
end

end

function Rule_Autosave_Necrons()

if not Event_IsAnyRunning() then
	Util_Autosave( "$840204" )
	Rule_Remove(Rule_Autosave_Necrons)
end

end

function Rule_Autosave_Titan_Heavy_Weapons_Online()

if not Event_IsAnyRunning() then
	Util_Autosave( "$840206" )
	Rule_Remove(Rule_Autosave_Titan_Heavy_Weapons_Online)
end

end


--[[ INTEL EVENTS ]]

--[[ Intel Event 1 ]] function Rule_IE_OpeningSpeech() -- Disabled for now --Util_StartIntel(EVENTS.IE_OpeningSpeech)

end

function Rule_IE_Give_First_Objective()

Util_StartIntel(EVENTS.IE_Give_First_Objective)

end

function Rule_IE_Give_Secondary_Objective()

Util_StartIntel(EVENTS.IE_Give_Secondary_Objective)

end

--[[ function Rule_IE_Necrons_Appear()

Util_StartIntel(EVENTS.IE_Necrons_Appear)

end]]

function Rule_IE_First_Generator_Online()

Util_StartIntel(EVENTS.IE_First_Generator_Online)

end

function Rule_IE_Generator_Destroyed()

Util_StartIntel(EVENTS.IE_Generator_Destroyed)

end

--[[ function Rule_IE_Heavy_Weapons_Online()

Util_StartIntel(EVENTS.IE_Heavy_Weapons_Online)

end]]

function Rule_IE_Baneblade_Rescued()

Util_StartIntel(EVENTS.IE_Baneblade_Rescued)

end

function Rule_IE_Sturnn_Returns()

Util_StartIntel(EVENTS.IE_Sturnn_Returns)

end

function Rule_IE_Sturnn_Returns2()

Util_StartIntel(EVENTS.IE_Sturnn_Returns2)

end

function Rule_IE_Varnus_Returns()

Util_StartIntel(EVENTS.IE_Varnus_Returns)

end

function Rule_IE_Varnus_Returns2()

Util_StartIntel(EVENTS.IE_Varnus_Returns2)

end

function Rule_IE_Baneblade_Men_Rescued()

Util_StartIntel(EVENTS.IE_Baneblade_Men_Rescued)

end

function Rule_IE_Monolith_Destroyed1()

Util_StartIntel(EVENTS.IE_Monolith_Destroyed1)

end

function Rule_IE_Monolith_Destroyed2()

Util_StartIntel(EVENTS.IE_Monolith_Destroyed2)

end

function Rule_IE_Monolith_Destroyed3()

Util_StartIntel(EVENTS.IE_Monolith_Destroyed3)

end

function Rule_IE_Monolith_Destroyed4()

Util_StartIntel(EVENTS.IE_Monolith_Destroyed4)

end




Spelstatistik
Följare
12
Körningar
58
Spelare
7
Senaste omgångarna
Nivå: Titan of the Emperor (Order 5 / Imperial guard)
Nivå: Hunter! (Disorder 2)
Nivå: Trophies (Disorder 5 / Orks)
Nivå: Keep Your Enemies Closer (Disorder 4)
Nivå: Blood for the Blood God! (Disorder 3)
Moderatorer