Mission event file for Ork Stronghold mission
Guides
/
Mission event file for Ork Stronghold mission
Updated 4 years ago by Merric

--[[ IMPORTS ]]

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


--[[ TO DO ]]


--[[ GAME SETUP ]]

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

g_player_race_type = MetaMap_GetPlayerRaceName()

--[[defining the name of the player's faction]]
if MetaMap_GetPlayerRaceName() == "chaos_marine_race" then
	
	factionname = "$690014"
	g_team_color = "default_1"
	g_Player1 = Setup_Player(0, factionname, MetaMap_GetPlayerRaceName(), 0) 
	Misc_PlayerTeamColor(g_Player1, g_team_color)
	
elseif MetaMap_GetPlayerRaceName() == "eldar_race" then

	factionname = "$690012"
	g_team_color = "default_5"
	g_Player1 = Setup_Player(0, factionname, MetaMap_GetPlayerRaceName(), 0) 
	Misc_PlayerTeamColor(g_Player1, g_team_color)
	
elseif MetaMap_GetPlayerRaceName() == "guard_race" then

	factionname = "$690011"
	g_team_color = "liberators"
	g_Player1 = Setup_Player(0, factionname, MetaMap_GetPlayerRaceName(), 0) 

elseif MetaMap_GetPlayerRaceName() == "ork_race" then

	factionname = "$690013"
	g_team_color = "default_4"
	g_Player1 = Setup_Player(0, factionname, MetaMap_GetPlayerRaceName(), 0) 
	
	Misc_PlayerTeamColor(g_Player1, g_team_color)
	
elseif MetaMap_GetPlayerRaceName() == "space_marine_race" then

	factionname = "$690010"
	g_team_color = "default_0"
	g_Player1 = Setup_Player(0, factionname, MetaMap_GetPlayerRaceName(), 0) 
	
elseif MetaMap_GetPlayerRaceName() == "tau_race" then
	
	factionname = "$690015"
	g_team_color = "default_1"
	g_Player1 = Setup_Player(0, factionname, MetaMap_GetPlayerRaceName(), 0) 
	
	
elseif MetaMap_GetPlayerRaceName() == "necron_race" then

	factionname = "$690016"
	g_team_color = "default_1"
	g_Player1 = Setup_Player(0, factionname, MetaMap_GetPlayerRaceName(), 0) 

end

--[[defining player faction names, teams and colours]]
--g_Player1 = Setup_Player(0, factionname, MetaMap_GetPlayerRaceName(), 1) 
	
g_Player2 = Setup_Player(1, "$2703010", "ork_race", 2) 
Misc_PlayerTeamColor(g_Player2,"default_4")

g_Player3 = Setup_Player(2, "$2703020", "ork_race", 3) 
Misc_PlayerTeamColor(g_Player3,"default_3")

g_Player4 = Setup_Player(3, "$2703030", "ork_race", 4) 
Misc_PlayerTeamColor(g_Player4,"default_2")

g_Player5 = Setup_Player(4, "$2703040", "ork_race", 5) 
Misc_PlayerTeamColor(g_Player5,"default_1")

g_Player6 = Setup_Player(5, "$2703050", "ork_race", 6) 
Misc_PlayerTeamColor(g_Player6,"default_5")

g_Player7 = Setup_Player(6, "$2703060", "ork_race", 7) 
Misc_PlayerTeamColor(g_Player7,"default_6")

g_Player8 = Setup_Player(7, "$2703070", "ork_race", 8)
Misc_PlayerTeamColor(g_Player8,"default_4")

-- forces the team colours to automatically switch when the team itself switches sides
Misc_ForceAutoSwitchTeamColor (g_Player1, true) 	
Misc_ForceAutoSwitchTeamColor (g_Player2, true) 
Misc_ForceAutoSwitchTeamColor (g_Player3, true) 
Misc_ForceAutoSwitchTeamColor (g_Player4, true) 
Misc_ForceAutoSwitchTeamColor (g_Player5, true) 
Misc_ForceAutoSwitchTeamColor (g_Player6, true) 
Misc_ForceAutoSwitchTeamColor (g_Player7, true) 
Misc_ForceAutoSwitchTeamColor (g_Player8, false) 


--[[generates a list of waypoints for Ork Vehicle Patrol]]
t_ork_racer_patrol_waypoints = {"mkr_track_waypoint1", "mkr_track_waypoint2", "mkr_track_waypoint3", "mkr_track_waypoint4", "mkr_track_waypoint5", 
													  "mkr_track_waypoint6", "mkr_track_waypoint7", "mkr_track_waypoint8", "mkr_track_waypoint9", "mkr_track_waypoint10",
													  "mkr_track_waypoint11", "mkr_track_waypoint12", "mkr_track_waypoint13", "mkr_track_waypoint14", "mkr_track_waypoint15", 
													  "mkr_track_waypoint16"}
g_ork_racer_waypoints = table.getn(t_ork_racer_patrol_waypoints)

--[[ each numerical entry indicates what waypoint the specified patrol is currently located in]]
t_ork_racer_patrol_table = {
1 --[[patrol 1]], 1 --[[patrol 2]], 1 --[[patrol 3]], 1 --[[patrol 4]]}

--[[counts how many racers are in the racer patrol table]]
--g_ork_racer_population = table.getn(t_ork_racer_patrol_table)
-- SEE DIFFICULTY ADJUSTED VARIABLES


t_banner_table = {"eg_headcrushaz_banner", "eg_rokkitrangaz_banner", "eg_burnaboyz_banner", "eg_kwikmekz_banner", "eg_footstompaz_banner"}
g_banner_table_count = table.getn(t_banner_table)
t_banner_status = {true, true, true, true, true}

--[[table that keeps track of all the CPU players and spawn points for each.  also contrains a list that indicates which team each faction belongs to when they split off]]
t_cpu_player_table = {
	cpu_player_name = {g_Player3, g_Player4, g_Player5, g_Player6, g_Player7},
	cpu_rebel_spawn = {"mkr_rebel_spawn1", "mkr_rebel_spawn2", "mkr_rebel_spawn3", "mkr_rebel_spawn4", "mkr_rebel_spawn5"},
	cpu_team_list = {3 --[[headcrushaz]], 4 --[[rokkitrangaz]], 5 --[[burnaboyz]], 6 --[[kwikmekz]], 7 --[[footstompaz]]}}


--[[table that contains the name of markers where each base is located]]
t_clan_base_list = {"mkr_headcrushaz_base", "mkr_rokkitrangaz_base", "mkr_burnaboyz_base", "mkr_kwikmekz_base", "mkr_footstompaz_base"}

--[[table that contains the name of the banners]]
t_clan_banner_list = {"mkr_headcrushaz_banner", "mkr_rokkitrangaz_banner", "mkr_burnaboyz_banner", "mkr_kwikmekz_banner", "mkr_footstompaz_banner"}

-- table that keeps track of whether or not an ork worshipper is under attack
g_ork_worshippers_under_attack = false --{false, false, false, false, false}

--[[keeps track of the faction's rebellion status]]
t_ork_rebellion_status = {false --[[headcrushaz]], false --[[rokkitrangaz]], false --[[burnaboyz]], false --[[kwikmekz]], false --[[footstompaz]], true --[[player.. will always be treated as revolt for another function]]}


--[[Counterattack Data]] --[[capture/counterattack variables]] --[[table that contains information about the bases that the player can potentially occupy, and their capture status]] t_bases_of_operation = { areaname = {"mkr_headcrushaz_base", "mkr_rokkitrangaz_base", "mkr_burnaboyz_base", "mkr_kwikmekz_base", "mkr_footstompaz_base", "mkr_start"}, spawnspot = {"mkr_headcrushaz_counterattack_spawn", "mkr_rokkitrangaz_counterattack_spawn", "mkr_burnaboyz_counterattack_spawn", "mkr_kwikmekz_counterattack_spawn", "mkr_footstompaz_counterattack_spawn", "mkr_start"}, flags = {"eg_flag1", "eg_flag2", "eg_flag3", "eg_flag4", "eg_flag5", "eg_flag6"}, flag_names = {"mkr_headcrushaz_base", "mkr_rokkitrangaz_base", "mkr_burnaboyz_base", "mkr_kwikmekz_base", "mkr_footstompaz_base", "mkr_start"}, minor_flags ={"eg_minor_flag1", "eg_minor_flag2", "eg_minor_flag3", "eg_minor_flag4", "eg_minor_flag5"}, areacapturedbyplayer = {false--[[headcrushaz]], false--[[rokkitrangaz]], false--[[burnaboyz]], false --[[kwikmekz]], false --[[footstompaz]], false--[[main area]]}, minor_area_not_gorgutz = {false, false, false, false, false}, capture_status = {2, 2, 2, 2, 2, 1}, -- 1 = player 1, 2 = player 2, etc. constructionbuildings= {"eg_construction1", "eg_construction2", "eg_construction3", "eg_construction4", "eg_construction5"}, vehicles = {"mkr_headcrushaz_vehicle_spawn", "mkr_rokkitrangaz_vehicle_spawn", "mkr_burnaboyz_vehicle_spawn", "mkr_kwikmekz_vehicle_spawn", "mkr_footstompaz_vehicle_spawn", "mkr_start"}} -- no marker start

--[[table that contains information about the counterattack squads sent at the player]]
t_ork_counterattack_data = {
	citadel_composition = {"ork_squad_slugga", "ork_squad_nob"},
	composition = {"ork_squad_shoota_boy", "ork_squad_slugga", "ork_squad_stormboy"},
	composition2 = {"ork_squad_nob", "ork_squad_nob", "ork_squad_shoota_boy", "ork_squad_stormboy"},
	composition3 = {"ork_flash_gitz_squad", "ork_squad_armored_nob", "ork_squad_nob", "ork_squad_stormboy", "ork_squad_tankbusta"}, -- advanced elite nobs instead of regular nobs
	major_names = {"sg_ork_counterattack1", "sg_ork_counterattack2", "sg_ork_counterattack3", "sg_ork_counterattack4","sg_ork_counterattack5", "sg_ork_counterattack6"},
	minor_names = {"sg_ork_minor_counterattack1", "sg_ork_minor_counterattack2", "sg_ork_minor_counterattack3", "sg_ork_minor_counterattack4", "sg_ork_minor_counterattack5"},
	playersquadcount = {0, 0, 0, 0, 0, 0},
	squadsize = {
	{3, 4, 5}, 
	{3, 4, 5}, 
	{3, 4, 5}, 
	{3, 4, 5},
	{3, 4, 5},
	{3, 4, 5}}}
	

--[[Interceptors]]

--[[table that keeps track of the units that are assigned as "interceptors" in each base]]
t_ork_interceptors = {
	
	base_name = {
	"mkr_headcrushaz_base", "mkr_rokkitrangaz_base", "mkr_burnaboyz_base", "mkr_kwikmekz_base", "mkr_footstompaz_base"},
	
	interceptor_units = {
		{"sg_headcrushaz1", "sg_headcrushaz2", "sg_headcrushaz5"},
		{"sg_rokkitrangaz1", "sg_rokkitrangaz2", "sg_rokkitrangaz5"},
		{"sg_burnaboyz1", "sg_burnaboyz2", "sg_burnaboyz5"},
		{"sg_kwikmekz1", "sg_kwikmekz2", "sg_kwikmekz5"},
		{"sg_footstompaz1", "sg_footstompaz2", "sg_footstompaz5"}},
		
	interceptor_status = {
	{true, true, true},
	{true, true, true},
	{true, true, true},
	{true, true, true},
	{true, true, true}}
}


g_interceptors_dead = 0

g_headcrushaz_interceptors_dead = 0
g_rokkitrangaz_interceptors_dead = 0
g_burnaboyz_interceptors_dead = 0
g_kwikmekz_interceptors_dead = 0
g_footstompaz_interceptors_dead = 0

--[[List of sgroups and egroups that can cause morale loss.  Index 1 = headcrushaz, 2 = rokkitrangaz, 3 = burnaboyz, 4 = kwikmekz, 5 = footstompaz]]
t_morale_droppers = {
	name = {"eg_headcrushaz_banner", "eg_rokkitrangaz_banner", "eg_burnaboyz_banner", "eg_kwikmekz_banner", "sg_squiggoth_trainer"},
	status = {false, false, false, false, false},
	target = {"sg_clan_orks1", "sg_clan_orks2", "sg_clan_orks3", "sg_clan_orks4", "sg_clan_orks5"}
	}


--[[number of areas occupied by the player.  This will change over time as more areas are occupied by the player.  If we have time we could try to make it so the CPU attempts to recapture
--if we have more time, we can make it so that the higher the number of occupied areas, the more vehicles or heavy units the computer will send.]]
g_occupied_areas = 1

--[[flag that indicates if a counterattack is under way]]
g_counterattack_sent = false

g_target = ""
g_target2 = ""

--[[counts the flags captured for ping purposes]]
g_flag_capture_counter = 0


--[[list of listening posts to be upgraded]]
t_ork_listening_posts = {"eg_ork_major_listening_post1", "eg_ork_major_listening_post2", "eg_ork_major_listening_post3", "eg_ork_major_listening_post4", "eg_ork_major_listening_post5"}


--[[Ork Worshipper variables]]

--table that contains the states for various Ork worshippers
t_group_is_ready = {false, false, false, false, false}

--how many ork worshippers are in position
g_ready_count = 0

--flag to show whether or not the ork worshippers are ready as a whole to return to their spots and resume their worshipping animation
g_return_on = false

g_worship_wait_count = 0

g_anim_wait_count = 0

--[[flag to tell the game the state of the ork worshippers]]
g_stop_animation = false


--[[more counter attack variables]]

g_counterattack_unit_composition = t_ork_counterattack_data.composition

g_bases_captured = 0

g_citadel_counterattack_sent = false

g_citadel_random_squads = 1

g_reinforcement_wait = 0 

g_vehicle_reinforcement_wait = 0 

g_dead_units = 0

t_group_is_dead = {false, false, false, false, false}

g_broken_number = 0


-- 	the following are defined here so that the base defender creation function is created once, and only once.  Their creation is caused by either the CPU or the player 
--	moving into the area.
g_headcrushaz_defense_created = false
g_rokkitrangaz_defense_created = false
g_burnaboyz_defense_created = false
g_kwikmekz_defense_created = false
g_footstompaz_defense_created = false

--g_player_race_type = ""

t_player_captured_major_flags = {"eg_flag6"}
t_player_captured_minor_flags = {}
t_player_captured_major_names = {"mkr_start"}
t_player_captured_minor_names = {}
t_gorgutz_captured_major_flags = {"eg_flag1", "eg_flag2", "eg_flag3", "eg_flag4", "eg_flag5"}
t_gorgutz_captured_major_names = {"mkr_headcrushaz_base", "mkr_rokkitrangaz_base", "mkr_burnaboyz_base", "mkr_kwikmekz_base", "mkr_footstompaz_base"}
t_gorgutz_captured_minor_flags = {"eg_minor_flag1", "eg_minor_flag2", "eg_minor_flag3", "eg_minor_flag4", "eg_minor_flag5"}
t_gorgutz_captured_minor_names = {"mkr_outpost1", "mkr_outpost2", "mkr_outpost3", "mkr_outpost4", "mkr_outpost5"}
t_non_gorgutz_captured_major_flags = {}
t_non_gorgutz_captured_major_names = {}
t_non_gorgutz_captured_minor_flags = {}
t_non_gorgutz_captured_minor_names = {}
t_gorgutz_captured_vehicle_names = {"mkr_headcrushaz_vehicle_spawn", "mkr_rokkitrangaz_vehicle_spawn", "mkr_burnaboyz_vehicle_spawn", "mkr_kwikmekz_vehicle_spawn", "mkr_footstompaz_vehicle_spawn"}
t_player_captured_vehicle_names = {"mkr_start"}	


g_deployed_count = 0

g_stop_loop1 = false
g_stop_loop2 = false
g_stop_loop3 = false
g_stop_loop4 = false

g_spawn_vehicle_composition1_iter = 1
g_spawn_vehicle_composition2_iter = 1
g_spawn_vehicle_composition3_iter = 1
g_spawn_vehicle_composition4_iter = 1

g_previous_line_used = 0

g_waves = 1 -- the wave number is expressed here

t_ork_base_defender_table = {{"sg_headcrushaz1", "sg_headcrushaz2", "sg_headcrushaz3", "sg_headcrushaz4", "sg_headcrushaz5"},
											   {"sg_rokkitrangaz1", "sg_rokkitrangaz2", "sg_rokkitrangaz3", "sg_rokkitrangaz4", "sg_rokkitrangaz5"},
											   {"sg_burnaboyz1", "sg_burnaboyz2", "sg_burnaboyz3", "sg_burnaboyz4", "sg_burnaboyz5"},
											   {"sg_kwikmekz1", "sg_kwikmekz2", "sg_kwikmekz3", "sg_kwikmekz4", "sg_kwikmekz5"},
											   {"sg_footstompaz1", "sg_footstompaz2", "sg_footstompaz3", "sg_footstompaz4", "sg_footstompaz5"}}

t_odd = {true, false, true, false, true, false, true, false, true, false}

g_firstrun = true

g_player_win = false

g_build_yes = false

g_mid_nis_played = false

--[[initializes variable used to keep track of how many minutes played]]
g_Timer = 0
	
--[[counter for the time that's elapsed in terms of seconds]]
g_time_elapsed = 0


--[[external patrol path initializations]]
g_external_patrol1_move = 0
g_external_patrol2_move = 0

g_citadel_delay_counter = 0

g_citadel_delay_counter_flag = true

g_player_unit_count = 0

g_cpu_group_sent = false

--gets difficulty of the map
g_defender_strength = MetaMap_GetTerritoryMilitaryStrength(MetaMap_GetDefendingTerritoryIndex())

--strength variables used for difficulty tuning.  Tied in with g_defender_strength
g_DBASE = 10
g_DMAX = 15


--tuning variable
g_difficulty = g_defender_strength


--bodyguard size tuning
g_body_TBASE = 2
g_body_TMAX = 6
g_body_deployment_size = g_body_TBASE + math.floor((g_difficulty - g_DBASE) * ((g_body_TMAX - g_body_TBASE)/ (g_DMAX - g_DBASE)))

--outpost defense size tuning
g_outpost_TBASE = 4
g_outpost_TMAX = 8
g_outpost_deployment_size = g_outpost_TBASE + math.floor((g_difficulty - g_DBASE) * ((g_outpost_TMAX - g_outpost_TBASE)/ (g_DMAX - g_DBASE)))

--clan sub-base size tuning
g_clan_TBASE = 5
g_clan_TMAX = 8
g_clan_deployment_size = g_clan_TBASE + math.floor((g_difficulty - g_DBASE) * ((g_clan_TMAX - g_clan_TBASE)/ (g_DMAX - g_DBASE)))

-- small sized squad tuning
g_small_TBASE = 2
g_small_TMAX = 4
g_small_deployment_size = g_small_TBASE + math.floor((g_difficulty - g_DBASE) * ((g_small_TMAX - g_small_TBASE)/ (g_DMAX - g_DBASE)))

-- medium sized squad tuning
g_med_TBASE = 4
g_med_TMAX = 6
g_med_deployment_size = g_med_TBASE + math.floor((g_difficulty - g_DBASE) * ((g_med_TMAX - g_med_TBASE)/ (g_DMAX - g_DBASE)))

-- large sized squad tuning
g_large_TBASE = 6
g_large_TMAX = 12
g_large_deployment_size = g_large_TBASE + math.floor((g_difficulty - g_DBASE) * ((g_large_TMAX - g_large_TBASE)/ (g_DMAX - g_DBASE)))

--time frequency variable for citadel raider counterattacks
g_time_TBASE = 0
g_time_TMAX = 80
g_adjusted_frequency = g_time_TBASE + math.floor((g_difficulty - g_DBASE) * ((g_time_TMAX - g_time_TBASE)/ (g_DMAX - g_DBASE)))


-- controls # of racers
g_racer_TBASE = 2
g_racer_TMAX = 4
g_ork_racer_population = g_racer_TBASE + math.floor((g_difficulty - g_DBASE) * ((g_racer_TMAX - g_racer_TBASE)/ (g_DMAX - g_DBASE)))


end

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

function OnLoad()

FOW_Reset()

end

Scar_AddLoad(OnLoad)


--[[ 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_Start_Music()

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

--Rule_AddOneShot(Rule_IE_OpeningSpeech, 0)

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

--[[ Define the OBJECTIVES ]]

-- Objective_TakeOverClanHeadCrushazBase = {title_id = 871000, short_desc_id = 871002, help_tip_id = 871004}

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


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_Start_Music()

t_ork_stronghold_music = {"MU_IG_STR_Ork", "MU_IG_STR_Ork_perc", "MU_IG_STR_Ork_perc_str", "MU_IG_STR_Ork_perc_brass", "music_msd5o", "music_msd1" }
--set the music	
--t_tau_stronghold_music = {"music_ms03"}

-- Sound_PlaylistClear(PC_Music) Playlist_Manager( PC_Music, t_ork_stronghold_music, true, true , {2, 4})

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_SetAllResources(g_Player1, 1000, 100) -- 2000-750
	Player_SetAllResources(g_Player2, 2000, 750) -- we can disable 2-8 if needed
	Player_SetAllResources(g_Player3, 2000, 750)
	Player_SetAllResources(g_Player4, 2000, 750)
	Player_SetAllResources(g_Player5, 2000, 750)
	Player_SetAllResources(g_Player6, 2000, 750)
	Player_SetAllResources(g_Player7, 2000, 750)
	Player_SetAllResources(g_Player8, 2000, 750)
	
	Player_GrantResearch(g_Player2, "ork_research_tank_busta_infiltrate")
	Player_GrantResearch(g_Player2, "ork_research_tank_busta_infiltrate")
	Player_GrantResearch(g_Player2, "ork_research_tank_busta_infiltrate")
	Player_GrantResearch(g_Player2, "ork_research_tank_busta_infiltrate")
	Player_GrantResearch(g_Player2, "ork_research_tank_busta_infiltrate")
	Player_GrantResearch(g_Player2, "ork_research_tank_busta_infiltrate")
	Player_GrantResearch(g_Player2, "ork_research_tank_busta_infiltrate")
	
	
	--[[ 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()
	
	--[[
	--[[Starts Player Army and Ork Army]]
	Rule_AddOneShot(Rule_Create_Player_Buildings_And_Squads, 1)
	Rule_AddOneShot(Rule_Ork_Army_Kickoff, 1)		
	Rule_AddOneShot(Rule_Ork_Vehicle_Kickoff, 2)
	Rule_AddOneShot(Rule_Play_Race_Specific_Opening_Text, 2)
	Rule_AddInterval(Rule_Approach_Gorgutz_Base, 1)
	Rule_AddInterval(Rule_Worshipper_Control, 15) --1
	Rule_AddInterval(Rule_Squiggoths_Gone_Wild, 1)
	Rule_AddInterval(Rule_Composition_Changer, 1)
	
	--starts player count function
	Rule_AddIntervalDelay(Rule_Count_Player_Units, 1, 1)
	
	--starts function that keeps track of who owns the capture points
	Rule_AddIntervalDelay(Rule_Ownership_Check, 1, 1)
	
	--timer for testing
	Rule_AddOneShot(Rule_Add_Timer, 1) 
	Rule_AddOneShot(Rule_Add_Seconds, 1)
	
	-- should give the player enough time to build up a little defense
	Rule_AddIntervalDelay(Rule_Counterattack_Activation, 10, 100)
	Rule_AddIntervalDelay(Rule_Counterattack_Idle_Fixing, 10, 122)
	Rule_AddIntervalDelay(Rule_Citadel_Threshold, 10, 101)
	Rule_AddIntervalDelay(Rule_Outpost_Raiders,  10, 180)
	
	--squiggoth rampage trigger
	Rule_AddIntervalDelay(Rule_Initial_Rampage_Trigger, 2, 20) -- Squiggoth_Rampage_Trigger
	
	
	Rule_AddIntervalDelay(Rule_Relic_Takeover_Mechanic, 2, 15)
	
	--initiates interception
	--Rule_AddIntervalDelay(Rule_Ork_Interception, 3, 16)
	
	
	--initiates morale loss mechanic
	Rule_AddIntervalDelay(Rule_Morale_Loss, 2, 21)
	Rule_AddIntervalDelay(Rule_Gorgutz_Reinforcements, 1, 30)
	Rule_AddIntervalDelay(Rule_Gorgutz_Vehicle_Reinforcements, 1, 31)
	

]]

	g_firstrun = false
	
	
elseif Event_IsAnyRunning() == false then		
	
	--Rule_AddOneShot(TeamSwitchTest, 60)
	
	--[[ Set up a Win Check ]]
	Rule_AddIntervalDelay(Rule_EndGameWin, 1, 10)
	
	--[[ Set up a Lose Check ]]
	Rule_AddIntervalDelay(Rule_EndGameLose, 1, 10)
	
	--[[ Assigning objectives]]
	Rule_AddIntervalDelay(Rule_Objective_Kill_Gorgutz, 1, 10)
	
	-- The following sets it up so that the triggers for the objectives are activated
	Rule_AddIntervalDelay(Rule_Initiate_Kill_Headcrushaz_Banner, 1, 11)
	Rule_AddIntervalDelay(Rule_Initiate_Kill_Rokkitrangaz_Banner, 1, 12)
	Rule_AddIntervalDelay(Rule_Initiate_Kill_Burnaboyz_Banner, 1, 13)
	Rule_AddIntervalDelay(Rule_Initiate_Kill_Kwikmekz_Banner, 1, 14)
	Rule_AddIntervalDelay(Rule_Initiate_Kill_Footstompaz_Banner, 1, 15)
	
	--Rule_AddIntervalDelay(Rule_Headcrushaz_Defense_Against_Rebels_Creation, 2, 16)
	--Rule_AddIntervalDelay(Rule_Rokkitrangaz_Defense_Against_Rebels_Creation, 2, 17)
	--Rule_AddIntervalDelay(Rule_Burnaboyz_Defense_Against_Rebels_Creation, 2, 18)
	--Rule_AddIntervalDelay(Rule_Kwikmekz_Defense_Against_Rebels_Creation, 2, 19)
	--Rule_AddIntervalDelay(Rule_Footstompaz_Defense_Against_Rebels_Creation, 2, 20)
	

	--Rule_AddOneShot(Rule_Add_Kill_Clan_Bosses_Objective, 15)
	Rule_AddOneShot(Rule_Add_Kill_Clan_Banners_Objective, 15)		
	
	--start music
	--Rule_AddOneShot(Rule_Start_Music, 0)
	
	--[[ Clean up ]]
	Rule_Remove(Rule_GameStart)
	
end

end


--[[ DIFFICULTY ]]

function Rule_SetDifficultyLevel( difficultyLevel )

--Difficulty_SetForPlayer(g_Player1, difficultyLevel)
--Difficulty_SetForPlayer(g_Player2, difficultyLevel)
--Difficulty_SetForPlayer(g_Player3, difficultyLevel)
--Difficulty_SetForPlayer(g_Player4, difficultyLevel)
--Difficulty_SetForPlayer(g_Player5, difficultyLevel)
--Difficulty_SetForPlayer(g_Player6, difficultyLevel)
--Difficulty_SetForPlayer(g_Player7, difficultyLevel)
--Difficulty_SetForPlayer(g_Player8, difficultyLevel)

--

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

--]]

end


--[[ AI ]]

function Rule_StartAI()

Cpu_EnableAll(false)	

end


--[[ CORE GAME ]]


--[[ PLAYER ARMY ]]

function Rule_Create_Player_Buildings_And_Squads()

MetaMap_UpdatePlayerWargear(g_Player1)


--no build zone for exploitable area -- Ork Stronghold Only
W40k_NoBuildZoneMarker( "mkr_nobuild1", "mkr_nobuild2" )
W40k_NoBuildZoneMarker( "mkr_nobuild3", "mkr_nobuild4" )
W40k_NoBuildZoneMarker( "mkr_nobuild5", "mkr_nobuild6" )
W40k_NoBuildZoneMarker( "mkr_nobuild7", "mkr_nobuild8" )
W40k_NoBuildZoneMarker( "mkr_nobuild9", "mkr_nobuild10" )
W40k_NoBuildZoneMarker( "mkr_nobuild11", "mkr_nobuild12" )
W40k_NoBuildZoneMarker( "mkr_nobuild13", "mkr_nobuild14" )
W40k_NoBuildZoneMarker( "mkr_nobuild15", "mkr_nobuild16" )
W40k_NoBuildZoneMarker( "mkr_nobuild17", "mkr_nobuild18" )

t_Player_Buildings ={

chaos_name = {"eg_Player_HQ"},
chaos_building_blueprint = {"chaos_hq"},
chaos_marker_spawn = {"mkr_Player_HQ"},

eldar_name = {"eg_Player_HQ"},
eldar_building_blueprint = {"eldar_hq"},
eldar_marker_spawn ={"mkr_Player_HQ"}, 

guard_name = {"eg_Player_HQ"},
guard_building_blueprint = {"guard_hq"}, 
guard_marker_spawn ={"mkr_Player_HQ"},

ork_name = {"eg_Player_HQ"},
ork_building_blueprint = {"ork_hq"},
ork_marker_spawn ={"mkr_Player_HQ"},

marines_name = {"eg_Player_HQ"},
marines_building_blueprint = {"space_marine_hq"},
marines_marker_spawn ={"mkr_Player_HQ"},

tau_name = {"eg_Player_HQ"},
tau_building_blueprint = {"tau_hq"},
tau_marker_spawn= {"mkr_Player_HQ"},

necron_name ={"eg_Player_HQ"},
necron_building_blueprint = {"monolith"},
necron_marker_spawn = {"mkr_Player_HQ"},

}

t_Player_Builder_Units = {

chaos_buildername = {"sg_Player_Builder"},
chaos_builder_blueprint = {"chaos_squad_slave"},
chaos_buildermarker_spawn = {"mkr_Player_Builder"},

eldar_buildername = {"sg_Player_Builder"},
eldar_builder_blueprint = {"eldar_squad_bonesinger"},
eldar_buildermarker_spawn ={"mkr_Player_Builder"}, 

guard_buildername = {"sg_Player_Builder"},
guard_builder_blueprint = {"guard_squad_enginseer"}, 
guard_buildermarker_spawn ={"mkr_Player_Builder"},

ork_buildername = {"sg_Player_Builder"},
ork_builder_blueprint = {"ork_squad_grot"},
ork_buildermarker_spawn ={"mkr_Player_Builder"},

marines_buildername = {"sg_Player_Builder"},
marines_builder_blueprint = {"space_marine_squad_servitor"},
marines_buildermarker_spawn ={"mkr_Player_Builder"},

tau_buildername = {"sg_Player_Builder"},
tau_builder_blueprint = {"tau_builder_squad"},
tau_buildermarker_spawn= {"mkr_Player_Builder"},

necron_buildername ={"sg_Player_Builder"},
necron_builder_blueprint = {"necron_builder_scarab_squad"},
necron_buildermarker_spawn = {"mkr_Player_Builder"},
}


if MetaMap_GetPlayerRaceName() == "chaos_marine_race" then

	for i = 1, table.getn(t_Player_Buildings.chaos_name) do
		
		Entity_CreateBuildingMarker(g_Player1, t_Player_Buildings.chaos_name[i], t_Player_Buildings.chaos_building_blueprint[i], t_Player_Buildings.chaos_marker_spawn[i], 1)
		Util_CreateSquadsAtMarkerEx(g_Player1, t_Player_Builder_Units.chaos_buildername[i], t_Player_Builder_Units.chaos_builder_blueprint[i], t_Player_Builder_Units.chaos_buildermarker_spawn[i], 1, 1)
		
		
	end

elseif MetaMap_GetPlayerRaceName() == "eldar_race" then

	for i = 1, table.getn(t_Player_Buildings.eldar_name) do
	
		Entity_CreateBuildingMarker(g_Player1, t_Player_Buildings.eldar_name[i], t_Player_Buildings.eldar_building_blueprint[i], t_Player_Buildings.eldar_marker_spawn[i], 1)
		Util_CreateSquadsAtMarkerEx(g_Player1, t_Player_Builder_Units.eldar_buildername[i], t_Player_Builder_Units.eldar_builder_blueprint[i], t_Player_Builder_Units.eldar_buildermarker_spawn[i], 1, 1)
	
	end

elseif MetaMap_GetPlayerRaceName() == "guard_race" then

	for i = 1, table.getn(t_Player_Buildings.guard_name) do
	
		Entity_CreateBuildingMarker(g_Player1, t_Player_Buildings.guard_name[i], t_Player_Buildings.guard_building_blueprint[i], t_Player_Buildings.guard_marker_spawn[i], 1)
		Util_CreateSquadsAtMarkerEx(g_Player1, t_Player_Builder_Units.guard_buildername[i], t_Player_Builder_Units.guard_builder_blueprint[i], t_Player_Builder_Units.guard_buildermarker_spawn[i], 1, 1)
		
	
	end

elseif MetaMap_GetPlayerRaceName() == "ork_race" then

	for i = 1, table.getn(t_Player_Buildings.ork_name) do
		
		Entity_CreateBuildingMarker(g_Player1, t_Player_Buildings.ork_name[i], t_Player_Buildings.ork_building_blueprint[i], t_Player_Buildings.ork_marker_spawn[i], 1)
		Util_CreateSquadsAtMarkerEx(g_Player1, t_Player_Builder_Units.ork_buildername[i], t_Player_Builder_Units.ork_builder_blueprint[i], t_Player_Builder_Units.ork_buildermarker_spawn[i], 1, 1)
		
		
	end

elseif MetaMap_GetPlayerRaceName() == "space_marine_race" then

	for i = 1, table.getn(t_Player_Buildings.marines_name) do
		
		Entity_CreateBuildingMarker(g_Player1, t_Player_Buildings.marines_name[i], t_Player_Buildings.marines_building_blueprint[i], t_Player_Buildings.marines_marker_spawn[i], 1)
		Util_CreateSquadsAtMarkerEx(g_Player1, t_Player_Builder_Units.marines_buildername[i], t_Player_Builder_Units.marines_builder_blueprint[i], t_Player_Builder_Units.marines_buildermarker_spawn[i], 1, 1)
		
		
	end
	
elseif MetaMap_GetPlayerRaceName() == "tau_race" then
	
	for i = 1, table.getn(t_Player_Buildings.tau_name) do
		
		Entity_CreateBuildingMarker(g_Player1, t_Player_Buildings.tau_name[i], t_Player_Buildings.tau_building_blueprint[i], t_Player_Buildings.tau_marker_spawn[i], 1)
		Util_CreateSquadsAtMarkerEx(g_Player1, t_Player_Builder_Units.tau_buildername[i], t_Player_Builder_Units.tau_builder_blueprint[i], t_Player_Builder_Units.tau_buildermarker_spawn[i], 1, 1)
		
	end
	
elseif MetaMap_GetPlayerRaceName() == "necron_race" then
	
	for i = 1, table.getn(t_Player_Buildings.necron_name) do
		
		Entity_CreateBuildingMarker(g_Player1, t_Player_Buildings.tau_name[i], t_Player_Buildings.necron_building_blueprint[i], t_Player_Buildings.necron_marker_spawn[i], 1)
		Util_CreateSquadsAtMarkerEx(g_Player1, t_Player_Builder_Units.necron_buildername[i], t_Player_Builder_Units.necron_builder_blueprint[i], t_Player_Builder_Units.necron_buildermarker_spawn[i], 1, 1)
		
	end
	
end

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

--Creation of bonus buildings
--establish variables to be used to incrementally create turrets and generators by concantenating the variables onto the markers as needed

-- generator markers start at 0
g_bonus_gen_counter = 0
-- turrer markers start at 6
g_bonus_turret_counter = 6

--determine race specific blueprints to be looked for when creating forward base

if MetaMap_GetPlayerRaceName() == "chaos_marine_race" then

    g_bonus_generator = "chaos_plasma_generator"
    g_bonus_turret = "chaos_turret_bolter"
    g_bonus_barracks = "chaos_temple"
    g_bonus_barracks2 = 0 --value on used for tau kroot nest, dummy value for all other races, like the Tau turret.
    g_bonus_research = "chaos_armoury"
	
elseif MetaMap_GetPlayerRaceName() == "eldar_race" then
	
	g_bonus_generator = "eldar_warp_generator"
    g_bonus_turret = "eldar_support_platform_scatterlaser"
    g_bonus_barracks = "eldar_aspect_portal"
    g_bonus_barracks2 = 0 --value on used for tau kroot nest, dummy value for all other races, like the Tau turret.
    g_bonus_research = "eldar_soul_shrine"
	
elseif MetaMap_GetPlayerRaceName() == "guard_race" then
	
    g_bonus_generator = "guard_plasma_generator"
	g_bonus_turret = "guard_turret_heavy_bolter"
	g_bonus_barracks = "guard_infantry"
	g_bonus_barracks2 = 0 --value on used for tau kroot nest, dummy value for all other races, like the Tau turret.
	g_bonus_research = "guard_tactica"
	
elseif MetaMap_GetPlayerRaceName() == "ork_race" then
	
    g_bonus_generator = "ork_generator"
	g_bonus_turret = "ork_waagh_banner"
	g_bonus_barracks = "ork_boy_hut"
	g_bonus_barracks2 = 0 --value on used for tau kroot nest, dummy value for all other races, like the Tau turret.
	g_bonus_research = "ork_pile_o_guns"
	
elseif MetaMap_GetPlayerRaceName() == "space_marine_race" then
	
	g_bonus_generator = "space_marine_generator"
	g_bonus_turret = "space_marine_turret_bolter"
	g_bonus_barracks = "space_marine_barracks"
	g_bonus_barracks2 = 0 --value on used for tau kroot nest, dummy value for all other races, like the Tau turret.
	g_bonus_research = "space_marine_armoury"
	
elseif MetaMap_GetPlayerRaceName() == "tau_race" then
	
	g_bonus_generator = "tau_plasma_generator"
	g_bonus_turret = 0  --tau have no turrets, so zero is simply a filler value to establish the variable instead of writting cutom checks for tau later.  0 will never be a value fed in by code, so it simply allows the algorithym to function in a standadrd manner for all races.
	g_bonus_barracks = "tau_barracks"
	g_bonus_barracks2 = "tau_kroot_nest"
	g_bonus_research = "tau_research_building"
	
elseif MetaMap_GetPlayerRaceName() == "necron_race" then
	
	g_bonus_generator = "necron_plasma_generator"
	g_bonus_turret = "necron_turret"
	g_bonus_barracks = "necron_summoning_core"
	g_bonus_barracks2 = 0 --value on used for tau kroot nest, dummy value for all other races, like the Tau turret.
	g_bonus_research = "necron_forbidden_archive"
	
end

--Add in any bonus buildings made availible if the player has purchased them via owning Hyperion peaks province

t_blueprintEntitybonus = {}
MetaMap_GetAttackingRaceStartingEntitiesList(t_blueprintEntitybonus)

for j = 1,table.getn(t_blueprintEntitybonus) do
	
	if t_blueprintEntitybonus[j] == g_bonus_generator then
		
		Entity_CreateBuildingMarker(g_Player1, "eg_Bonus"..j, t_blueprintEntitybonus[j], "MM_Reinforcement"..g_bonus_gen_counter, 1)
		--increase by one, the next generator will then spawn at the correct marker after this one
		g_bonus_gen_counter = g_bonus_gen_counter + 1
		
	elseif t_blueprintEntitybonus[j] == g_bonus_turret then
		
		Entity_CreateBuildingMarker(g_Player1, "eg_Bonus"..j, t_blueprintEntitybonus[j], "MM_Reinforcement"..g_bonus_turret_counter, 1)
		--increase by one, the next turret will then spawn at the correct marker after this one
		g_bonus_turret_counter = g_bonus_turret_counter + 1
		
	elseif t_blueprintEntitybonus[j] == g_bonus_barracks then
		
		--fixed marker spawn based on Phil's table.  Only one barracks is spawned, always at marker 10
		--Necron intentionally spawn a summoning core in place of a barracks due to the monolith doubling as their barracks.
		Entity_CreateBuildingMarker(g_Player1, "eg_Bonus"..j, t_blueprintEntitybonus[j], "MM_Reinforcement10", 1)
		
	elseif t_blueprintEntitybonus[j] == g_bonus_research then
		
		--fixed marker spawn based on Phil's table.  Only one research building is spawned, always at marker 11
		Entity_CreateBuildingMarker(g_Player1, "eg_Bonus"..j, t_blueprintEntitybonus[j], "MM_Reinforcement11", 1)
		
	elseif t_blueprintEntitybonus[j] == g_bonus_barracks2 then
		
		--This will only be used to spawn the kroot nest when the player is Tau, otherwise it will be passed over due to g_bonus_barracks2 being a dummy value.
		--fixed marker spawn based on Phil's table.  Only one kroot nest is spawned, always at marker 13
		Entity_CreateBuildingMarker(g_Player1, "eg_Bonus"..j, t_blueprintEntitybonus[j], "MM_Reinforcement13", 1)
		
	end
	
end

	--setting up the bonus units for the player
t_blueprintbonus = {}
MetaMap_GetRaceStartingSquadsList(MetaMap_GetPlayerRaceName(), t_blueprintbonus)

for j = 1,  table.getn(t_blueprintbonus) do
	
	k = math.mod(j - 1, 6) + 1
	
	Util_CreateSquadsAtMarker(g_Player1, "sg_Bonus"..j, t_blueprintbonus[j], "mkr_Bonus"..k, 1)
	
	
end


--Rule_AddOneShot(Rule_Create_Enemy_Bonus_Squads, 1)

Rule_Remove(Rule_Create_Player_Buildings_And_Squads)

end

--[[ function Rule_Create_Enemy_Bonus_Squads()

--setting up the bonus units for the player
t_cpu_blueprintbonus = {}
MetaMap_GetRaceStartingSquadsList("ork_race", t_cpu_blueprintbonus)

g_blueprint_bonus_population = table.getn(t_cpu_blueprintbonus)

for t = 1, g_blueprint_bonus_population  do
	
	u = math.mod(t - 1, 6) + 1
	
	if (t_cpu_blueprintbonus[t] == "ork_squad_warboss_advance_sp") or (t_cpu_blueprintbonus[t] == "ork_squad_warboss_stronghold_sp") then -- exception just for Ork Stronghold
	
		Util_CreateSquadsAtMarker(g_Player2, "sg_cpu_bonus"..t, "ork_squad_mek_boy_advance_sp", "mkr_cpu_bonus"..u, 1)
	
	else
	
		Util_CreateSquadsAtMarker(g_Player2, "sg_cpu_bonus"..t, t_cpu_blueprintbonus[t], "mkr_cpu_bonus"..u, 1)
	end
	
end

end]]


function Rule_Ork_Army_Kickoff()

--test --[[ Util_CreateSquadsAtMarkerEx(g_Player1, "test1", "guard_squad_baneblade", "mkr_rokkitrangaz_base", 12, 1) Util_CreateSquadsAtMarkerEx(g_Player1, "test2", "guard_squad_psyker", "mkr_rokkitrangaz_base", 12, 1) Util_CreateSquadsAtMarkerEx(g_Player1, "test3", "guard_squad_baneblade", "mkr_burnaboyz_base", 12, 1) Util_CreateSquadsAtMarkerEx(g_Player1, "test4", "guard_squad_baneblade", "mkr_start", 12, 1)]]

--generic Gorgutz Orks at outposts

for i = 1, 5 do
	SGroup_CreateIfNotFound("sg_outpost"..i.."_orks")
	
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_ork_outpost"..i.."defender1", "ork_squad_slugga", "mkr_outpost"..i, 1, g_outpost_deployment_size)
	SGroup_AddLeaders("sg_ork_outpost"..i.."defender1")
	SGroup_AddGroup(SGroup_FromName("sg_outpost"..i.."_orks"), SGroup_FromName("sg_ork_outpost"..i.."defender1"))
			
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_ork_outpost"..i.."defender2", "ork_squad_shoota_boy", "mkr_outpost"..i, 1, g_outpost_deployment_size)
	SGroup_AddLeaders("sg_ork_outpost"..i.."defender2")
	SGroup_AddGroup(SGroup_FromName("sg_outpost"..i.."_orks"), SGroup_FromName("sg_ork_outpost"..i.."defender2"))
	
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_ork_outpost"..i.."defender3", "ork_squad_nob", "mkr_outpost"..i, 1, g_outpost_deployment_size)
	SGroup_AddLeaders("sg_ork_outpost"..i.."defender2")
	SGroup_AddGroup(SGroup_FromName("sg_outpost"..i.."_orks"), SGroup_FromName("sg_ork_outpost"..i.."defender3"))
	
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_ork_outpost"..i.."defender4", "ork_squad_grot", "mkr_outpost"..i, 1, g_outpost_deployment_size)
	SGroup_AddLeaders("sg_ork_outpost"..i.."defender2")
	SGroup_AddGroup(SGroup_FromName("sg_outpost"..i.."_orks"), SGroup_FromName("sg_ork_outpost"..i.."defender4"))
	
end


Rule_AddIntervalDelay(Rule_Defender1_Movement, 45, 60)
Rule_AddIntervalDelay(Rule_Defender2_Movement, 45, 70)
Rule_AddIntervalDelay(Rule_Defender3_Movement, 45, 80)
Rule_AddIntervalDelay(Rule_Defender4_Movement, 45, 90)
Rule_AddIntervalDelay(Rule_Defender5_Movement, 45, 100)


SGroup_CreateIfNotFound("sg_clan_bosses")
SGroup_CreateIfNotFound("sg_worshipping_orks")

--headcrushaz defense

SGroup_CreateIfNotFound("sg_clan_orks1")
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_worshippers1", "ork_squad_nob", "mkr_ork_worship1", 1, g_large_deployment_size)
SGroup_AddGroup(SGroup_FromName("sg_worshipping_orks"), SGroup_FromName("sg_worshippers1"))
SGroup_AddGroup(SGroup_FromName("sg_clan_orks1"), SGroup_FromName("sg_worshippers1"))
Anim_PlaySGroupAnim(SGroup_FromName("sg_worshippers1"), "capture_strategic_point" )	
Cmd_SetStance("sg_worshippers1", STANCE_CeaseFire)

--rokkitrangaz defense

SGroup_CreateIfNotFound("sg_clan_orks2")
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_worshippers2", "ork_squad_nob", "mkr_ork_worship2", 1, g_large_deployment_size)
SGroup_AddGroup(SGroup_FromName("sg_worshipping_orks"), SGroup_FromName("sg_worshippers2"))
SGroup_AddGroup(SGroup_FromName("sg_clan_orks2"), SGroup_FromName("sg_worshippers2"))
Anim_PlaySGroupAnim(SGroup_FromName("sg_worshippers2"), "capture_strategic_point" )	
Cmd_SetStance("sg_worshippers2", STANCE_CeaseFire)

--burnaboyz defense

SGroup_CreateIfNotFound("sg_clan_orks3")
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_worshippers3", "ork_squad_nob", "mkr_ork_worship3", 1, g_large_deployment_size)
SGroup_AddGroup(SGroup_FromName("sg_worshipping_orks"), SGroup_FromName("sg_worshippers3"))
SGroup_AddGroup(SGroup_FromName("sg_clan_orks3"), SGroup_FromName("sg_worshippers3"))
Anim_PlaySGroupAnim(SGroup_FromName("sg_worshippers3"), "capture_strategic_point" )	
Cmd_SetStance("sg_worshippers3", STANCE_CeaseFire)

--kwikmekz defense

SGroup_CreateIfNotFound("sg_clan_orks4")
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_worshippers4", "ork_squad_nob", "mkr_ork_worship4", 1, g_large_deployment_size)
SGroup_AddGroup(SGroup_FromName("sg_worshipping_orks"), SGroup_FromName("sg_worshippers4"))
SGroup_AddGroup(SGroup_FromName("sg_clan_orks4"), SGroup_FromName("sg_worshippers4"))	

Anim_PlaySGroupAnim(SGroup_FromName("sg_worshippers4"), "capture_strategic_point" )	
Cmd_SetStance("sg_worshippers4", STANCE_CeaseFire)

--footstompaz defense -- includes squiggoth and trainer

SGroup_CreateIfNotFound("sg_clan_orks5")
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_worshippers5", "ork_squad_nob", "mkr_ork_worship5", 1, g_large_deployment_size)
SGroup_AddGroup(SGroup_FromName("sg_worshipping_orks"), SGroup_FromName("sg_worshippers5"))
SGroup_AddGroup(SGroup_FromName("sg_clan_orks5"), SGroup_FromName("sg_worshippers5"))	
Anim_PlaySGroupAnim(SGroup_FromName("sg_worshippers5"), "capture_strategic_point" )	
Cmd_SetStance("sg_worshippers5", STANCE_CeaseFire)

Util_CreateSquadsAtMarker(g_Player2, "sg_squiggoth1", "ork_squad_squiggoth_sp_long_rampage", "mkr_squiggoth_spawn", 1)
--Util_CreateSquadsAtMarker(g_Player7, "sg_squiggoth2", "ork_squad_squiggoth", "mkr_squiggoth_spawn", 1)

SGroup_CreateIfNotFound("sg_squiggoths")
SGroup_AddGroup(SGroup_FromName("sg_squiggoths"), SGroup_FromName("sg_squiggoth1"))
SGroup_FaceMarker( "sg_squiggoth1", "mkr_squiggoth_charge_trigger" )

SGroup_AddGroup(SGroup_FromName("sg_clan_orks5"), SGroup_FromName("sg_squiggoths"))	
--SGroup_AddGroup(SGroup_FromName("sg_squiggoths"), SGroup_FromName("sg_squiggoth2"))

Util_CreateSquadsAtMarker(g_Player2, "sg_squiggoth_trainer", "ork_squad_bad_dok_sp_trainer", "mkr_squiggoth_trainer_spawn", 1)

--gorgutz defense -- information about the infantry defending gorgutz' base t_gorgutz_defender_info = { name = {"sg_gorgutz_defense1", "sg_gorgutz_defense2", "sg_gorgutz_defense3", "sg_gorgutz_defense4", "sg_gorgutz_defense5", "sg_gorgutz_outer_guard"}, defender_type = {"ork_squad_slugga_advance_sp", "ork_squad_shoota_boy_advance_sp", "ork_squad_nob_advance_sp", "ork_squad_armored_nob", "ork_squad_nob_advance_sp", "ork_squad_armored_nob"}, spawn_location = {"mkr_gorgutz_defense_spawn1", "mkr_gorgutz_defense_spawn2", "mkr_gorgutz_defense_spawn3", "mkr_gorgutz_defense_spawn4", "mkr_gorgutz_defense_spawn5", "mkr_gorgutz_outer_guard_spawn"}, respawn_location = {"mkr_reinforcement_spawner1", "mkr_reinforcement_spawner2", "mkr_reinforcement_spawner3", "mkr_reinforcement_spawner4", "mkr_reinforcement_spawner5", "mkr_reinforcement_spawner6"}, spawn_squad_number = {1, 1, 1, 1, 1, 1}, spawn_squad_population = {g_large_deployment_size, g_large_deployment_size, g_large_deployment_size, g_small_deployment_size, g_clan_deployment_size, g_small_deployment_size}} --12, 12, 12, 4, 12, 4

SGroup_CreateIfNotFound("sg_gorgutz_defense_orks")

for i = 1, table.getn(t_gorgutz_defender_info.name) do
	Util_CreateSquadsAtMarkerEx(g_Player2, t_gorgutz_defender_info.name[i], t_gorgutz_defender_info.defender_type[i], t_gorgutz_defender_info.spawn_location[i], 
	t_gorgutz_defender_info.spawn_squad_number[i], t_gorgutz_defender_info.spawn_squad_population[i])
	SGroup_AddLeaders(t_gorgutz_defender_info.name[i])
	SGroup_AddGroup(SGroup_FromName("sg_gorgutz_defense_orks"),  t_gorgutz_defender_info.name[i])
end

--rebels in Gorgutz' base
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_gorgutz_surprise_rebels", "ork_squad_nob_advance_sp", "mkr_gorgutz_rebel_spawn", 2, g_large_deployment_size)
Util_CreateSquadsAtMarker(g_Player2, "sg_gorgutz", "ork_squad_warboss_stronghold_sp", "mkr_gorgutz_spawn", 1)

--Util_CreateSquadsAtMarkerEx(g_Player2, "sg_gorgutz_outer_guard", "ork_squad_armored_nob", "mkr_gorgutz_outer_guard_spawn", 2, 8)

for i = 1, table.getn(t_ork_listening_posts) do	
	EGroup_ForceAddOn("eg_ork_major_listening_post"..i, "ork_gork_totem_addon_2")
end

EGroup_ForceAddOn("eg_relic_listening_post", "ork_gork_totem_addon_2")

--Util_CreateSquadsAtMarkerEx(g_Player2, "sg_gorgutz_defense5", "ork_squad_slugga", "mkr_gorgutz_base", 1, 8)

-- information about the vehicles defending gorgutz' base t_gorgutz_vehicle_defender_info = { name = {"sg_gorgutz_tanks1", "sg_gorgutz_tanks2" --[[,"sg_gorgutz_tanks3", "sg_gorgutz_tanks4"]] --[[, "sg_gorgutz_tanks5"]]}, defender_type = {"ork_squad_looted_tank_sp", "ork_squad_looted_tank_sp" --[[, "ork_squad_looted_tank_sp", "ork_squad_looted_tank_sp"]] --[[, "ork_squad_looted_tank_sp"]]}, spawn_location = {"mkr_gorgutz_looted_tank1", "mkr_gorgutz_looted_tank2" --[[,"mkr_gorgutz_looted_tank3", "mkr_gorgutz_looted_tank4"]] --[[, "mkr_gorgutz_looted_tank5"]]}, spawn_squad_number = {1, 1, --[[1, 1]] --[[, 1]]}, spawn_squad_population = {1, 1,--[[ 1, 1]] --[[, 1]]}}

for i = 1, table.getn(t_gorgutz_vehicle_defender_info.name) do
	Util_CreateSquadsAtMarkerEx(g_Player2, t_gorgutz_vehicle_defender_info.name[i], t_gorgutz_vehicle_defender_info.defender_type[i], t_gorgutz_vehicle_defender_info.spawn_location[i], 
		t_gorgutz_vehicle_defender_info.spawn_squad_number[i], t_gorgutz_vehicle_defender_info.spawn_squad_population[i])
	SGroup_AddLeaders(t_gorgutz_vehicle_defender_info.name[i])
	SGroup_AddGroup(SGroup_FromName("sg_gorgutz_defense_orks"),  t_gorgutz_vehicle_defender_info.name[i])
end

--rebel tank spawn
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_rebel_tank", "ork_squad_looted_tank_sp", "mkr_rebel_tank_spawn", 1, 1)


--external patrol spawns
SGroup_CreateIfNotFound("sg_external_patrol1")
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_external_patrol1_slugga", "ork_squad_slugga", "mkr_main_patrol1_path1", 1, 6)
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_external_patrol1_armor", "ork_squad_armored_nob", "mkr_main_patrol1_path1", 1, 1)	
SGroup_AddGroup(SGroup_FromName("sg_external_patrol1"),  SGroup_FromName("sg_external_patrol1_slugga"))
SGroup_AddGroup(SGroup_FromName("sg_external_patrol1"),  SGroup_FromName("sg_external_patrol1_armor"))

SGroup_CreateIfNotFound("sg_external_patrol2")
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_external_patrol2_slugga", "ork_squad_slugga", "mkr_main_patrol2_path1", 1, 6)
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_external_patrol2_armor", "ork_squad_armored_nob", "mkr_main_patrol2_path1", 1, 1)	
SGroup_AddGroup(SGroup_FromName("sg_external_patrol2"),  SGroup_FromName("sg_external_patrol2_slugga"))
SGroup_AddGroup(SGroup_FromName("sg_external_patrol2"),  SGroup_FromName("sg_external_patrol2_armor"))

--[[
-- initial ambush spawn
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_initial_ambush1", "ork_squad_stormboy", "mkr_ambush1", 1, 10)
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_initial_ambush2", "ork_squad_stormboy", "mkr_ambush2", 1, 10)
Util_CreateSquadsAtMarker(g_Player2, "sg_initial_ambush3", "ork_squad_wartrak", "mkr_ambush3", 1)

-- Util_CreateSquadsAtMarkerEx(g_Player2, "sg_initial_ambush4", "ork_squad_armored_nob", "mkr_ambush4", 1,4) ]]

--Rule_AddOneShot(Rule_Stormboy_Kickoff, 20)
--Rule_AddOneShot(Rule_Initial_Vehicle_Kickoff, 30)

Rule_AddInterval(Rule_External_Patrol1, 20)
Rule_AddInterval(Rule_External_Patrol2, 20)

--Prevents the squiggoth from being generated except when specifically done
Player_RestrictSquad( g_Player2, "ork_squad_squiggoth")
Player_RestrictSquad( g_Player3, "ork_squad_squiggoth")
Player_RestrictSquad( g_Player4, "ork_squad_squiggoth")
Player_RestrictSquad( g_Player5, "ork_squad_squiggoth")
Player_RestrictSquad( g_Player6, "ork_squad_squiggoth")
Player_RestrictSquad( g_Player7, "ork_squad_squiggoth")
Player_RestrictSquad( g_Player8, "ork_squad_squiggoth")

Rule_AddOneShot(Rule_Initial_Ambush_Spawner, 1)

end



function Rule_Initial_Ambush_Spawner()

t_ambush_components = {
	
	ambush_number_of_squads = {--[[Strength10]] 1, --[[Strength11]] 2, --[[Strength12]] 3, --[[Strength13]] 4, --[[Strength14]] 5, --[[Strength15]] 6}, --3, 3, 4, 5, 6, 7
	
	ambush_number_of_units = {--[[Strength10]] 8, --[[Strength11]] 8, --[[Strength12]] 8, --[[Strength13]] 8, --[[Strength14]] 8, --[[Strength15]] 8},
	
	ambush_types = {"ork_squad_slugga", "ork_squad_shoota_boy", "ork_squad_nob"}, -- "ork_squad_stormboy"
	
	ambush_number_of_vehicles = {--[[Strength10]] 0, --[[Strength11]] 1, --[[Strength12]] 1, --[[Strength13]] 2, --[[Strength14]] 3, --[[Strength15]] 3}, -- 1, 1, 2, 2, 3, 3
	
	ambush_vehicle_types = {"ork_squad_wartrak", "ork_squad_trukk"}, -- took out killa kan for balance
	
	ambush_detector = {"ork_squad_armored_nob"},
	
	ambush_detector_number = {--[[Strength10]] 0, --[[Strength11]] 0, --[[Strength12]] 1, --[[Strength13]] 1, --[[Strength14]] 2, --[[Strength15]] 2},
	
	--only for Ork Stronghold
	ambush_ork_jumper_number = {--[[Strength10]] 1, --[[Strength11]] 1, --[[Strength12]] 2, --[[Strength13]] 2, --[[Strength14]] 3, --[[Strength15]] 4}
	
	}

g_defender_str = MetaMap_GetTerritoryMilitaryStrength(MetaMap_GetDefendingTerritoryIndex())	
g_defender_str_adjusted = g_defender_str - 9 --adjusted for table

for r = 1, t_ambush_components.ambush_number_of_squads[g_defender_str_adjusted] do
	
	if r <= 4 then
			
			p = r
	else
	
		p = r - 4
	
	end
	
	local l_random_ambush_type = World_GetRand(1, table.getn(t_ambush_components.ambush_types))	
	
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_initial_ambush", t_ambush_components.ambush_types[l_random_ambush_type], "mkr_ambush"..p.."spawn", 
	1, t_ambush_components.ambush_number_of_units[g_defender_str_adjusted])
	
	
end

for r = 1, t_ambush_components.ambush_number_of_vehicles[g_defender_str_adjusted] do

	
	if r <= 2 then
			
			p = r
	else
	
		p = r - 2
	
	end
	
	local l_random_vehicle_ambush_type = World_GetRand(1, table.getn(t_ambush_components.ambush_vehicle_types))	
	
	Util_CreateSquadsAtMarker(g_Player2, "sg_initial_vehicle_ambush", t_ambush_components.ambush_vehicle_types[l_random_vehicle_ambush_type], "mkr_ambush"..p.."_vehicle", 
	1, 1)
	SGroup_AddGroup(SGroup_FromName("sg_initial_ambush"), SGroup_FromName("sg_initial_vehicle_ambush"))	
end

--creates detectors
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_initial_detector", t_ambush_components.ambush_detector[1], "mkr_ambush1spawn", 1, t_ambush_components.ambush_detector_number[g_defender_str_adjusted] )
SGroup_AddGroup(SGroup_FromName("sg_initial_ambush"), SGroup_FromName("sg_initial_detector"))





--custom for Ork Stronghold Only
if g_defender_str >= 13 then 
	Util_CreateSquadsAtMarker(g_Player2, "sg_initial_vehicle_ambush", "ork_squad_killa_kan", "mkr_ambush1_vehicle", 1, 1)
	SGroup_AddGroup(SGroup_FromName("sg_initial_ambush"), SGroup_FromName("sg_initial_vehicle_ambush"))
end


--custom for Ork Stronghold Only
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_initial_anti_vehicle", "ork_squad_tankbusta", "mkr_ambush2spawn", 1, 8 )
SGroup_AddGroup(SGroup_FromName("sg_initial_ambush"), SGroup_FromName("sg_initial_anti_vehicle"))


--the following is custom for Ork Stronghold only
for r = 1,  t_ambush_components.ambush_ork_jumper_number[g_defender_str_adjusted] do
	
	if r <= 2 then
		
		p = r
		
	else
		
		p = r - 2
		
	end
	
	
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_initial_jumper"..p, "ork_squad_stormboy", "mkr_jump_ambush"..p, 1, 1)	
	SGroup_AddGroup(SGroup_CreateIfNotFound("sg_jumpers"), SGroup_FromName("sg_initial_jumper"..p))	
	
end

--custom for ork stronghold
Rule_AddOneShot(Rule_Initial_Jump_Activation, 40)




-- REQUIRED
Rule_AddOneShot(Rule_Initial_Ambush_Activation, 30)

end

function Rule_Initial_Ambush_Activation()

Cmd_SetStance("sg_initial_ambush", STANCE_Attack)
Cmd_AttackMoveMarker("sg_initial_ambush", "mkr_Player_HQ")


Rule_AddIntervalDelay(Rule_Initial_Ambush_Idle_Fix, 3, 5)

end

function Rule_Initial_Ambush_Idle_Fix()

if SGroup_Exists("sg_initial_ambush") and (SGroup_IsEmpty("sg_initial_ambush") == false) then
	
	if SGroup_CheckActiveCommand("sg_initial_ambush", SQUADSTATEID_Idle, false) then
		Cmd_AttackMoveMarker("sg_initial_ambush", "mkr_Player_HQ")
	end
	
elseif ((SGroup_Exists("sg_initial_ambush") == false) or (SGroup_IsEmpty("sg_initial_ambush") == true)) then
	
	Rule_Remove(Rule_Initial_Ambush_Idle_Fix)
	
end

end

--custom for orks function Rule_Initial_Jump_Activation()

if SGroup_Exists("sg_initial_jumper1") and (SGroup_IsEmpty("sg_initial_jumper1") == false) then
	
	Cmd_SetStance("sg_initial_jumper1", STANCE_Attack)
	Cmd_JumpToMarker("sg_initial_jumper1", "mkr_ambush_jump1")
	
end

if SGroup_Exists("sg_initial_jumper2") and (SGroup_IsEmpty("sg_initial_jumper2") == false) then
	
	Cmd_SetStance("sg_initial_jumper2", STANCE_Attack)
	Cmd_JumpToMarker("sg_initial_jumper2", "mkr_ambush_jump2")
	
end

Rule_AddIntervalDelay(Rule_Initial_Jump_Ambush_Idle_Fix, 3, 5)

end

--custom for orks function Rule_Initial_Jump_Ambush_Idle_Fix()

if SGroup_Exists("sg_jumpers") and (SGroup_IsEmpty("sg_jumpers") == false) then
	
	if SGroup_CheckActiveCommand("sg_jumpers", SQUADSTATEID_Idle, false) then
		Cmd_AttackMoveMarker("sg_jumpers", "mkr_Player_HQ")
	end
	
elseif ((SGroup_Exists("sg_jumpers") == false) or (SGroup_IsEmpty("sg_jumpers") == true)) then

	Rule_Remove(Rule_Initial_Jump_Ambush_Idle_Fix)

end

end


--[[ function Rule_Stormboy_Kickoff()

Cmd_JumpToMarker("sg_initial_ambush1", "mkr_ambush1_jump")
Cmd_JumpToMarker("sg_initial_ambush2", "mkr_ambush2_jump")

end

function Rule_Initial_Vehicle_Kickoff()

Cmd_AttackMoveMarker("sg_initial_ambush3", "mkr_Player_HQ")
--Cmd_AttackMoveMarker("sg_initial_ambush4", "mkr_Player_HQ")

end

]] --[[BASE DEFENDER CREATION]] -- These rules govern what happens when a base's defenses are activated via the Rule_Initiate_<name of clan> functions

function Rule_Ork_Headcrushaz_Creation()

if g_headcrushaz_defense_created == false then
--	SGroup_CreateIfNotFound("sg_clan_orks1")
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_headcrushaz1", "ork_squad_slugga", "mkr_headcrushaz_boyz_spawn", 1, g_large_deployment_size)
	SGroup_AddLeaders("sg_headcrushaz1")
	SGroup_AddGroup(SGroup_FromName("sg_clan_orks1"), SGroup_FromName("sg_headcrushaz1"))
	
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_headcrushaz2", "ork_squad_shoota_boy", "mkr_headcrushaz_boyz_spawn", 1, g_large_deployment_size)
	SGroup_AddLeaders("sg_headcrushaz2")	
	
	for i = 1, SGroup_Count(SGroup_FromName("sg_headcrushaz2")) do
		Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_headcrushaz2"), i), "ork_big_shoota_shoota", 5)
	end
		
	SGroup_AddGroup(SGroup_FromName("sg_clan_orks1"), SGroup_FromName("sg_headcrushaz2"))
	
	
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_headcrushaz3", "ork_squad_nob", "mkr_headcrushaz_boyz_spawn", 1, g_large_deployment_size)
	SGroup_AddLeaders("sg_headcrushaz3")
	SGroup_AddGroup(SGroup_FromName("sg_clan_orks1"), SGroup_FromName("sg_headcrushaz3"))
	
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_headcrushaz4", "ork_squad_grot", "mkr_headcrushaz_boyz_spawn", 1, g_large_deployment_size)
	SGroup_AddGroup(SGroup_FromName("sg_clan_orks1"), SGroup_FromName("sg_headcrushaz4"))
	
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_headcrushaz5", "ork_squad_slugga", "mkr_headcrushaz_boyz_spawn", 1, g_large_deployment_size)
	SGroup_AddGroup(SGroup_FromName("sg_clan_orks1"), SGroup_FromName("sg_headcrushaz5"))
	
	
	
	Util_CreateSquadsAtMarker(g_Player2, "sg_headcrushaz_boss", "ork_squad_mek_boy_advance_sp", "mkr_headcrushaz_boss", 1)
	SGroup_AddGroup(SGroup_FromName("sg_clan_bosses"), SGroup_FromName("sg_headcrushaz_boss"))
	SGroup_AddGroup(SGroup_FromName("sg_clan_orks1"), SGroup_FromName("sg_headcrushaz_boss"))

	
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_loyalists1", "ork_squad_nob_advance_sp", "mkr_loyalists_at_headcrushaz", 2, g_clan_deployment_size)
	SGroup_AddLeaders("sg_loyalists1")
	
	Rule_AddInterval(Rule_Ork_Headcrushaz_Interception, 2)
	
	Rule_AddInterval(Rule_Ork_Base1_Movement, 45)
	
	g_headcrushaz_defense_created = true
end

end

function Rule_Ork_Rokkitrangaz_Creation()

if g_rokkitrangaz_defense_created == false then

--	SGroup_CreateIfNotFound("sg_clan_orks2")
	
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_rokkitrangaz1", "ork_squad_tankbusta", "mkr_rokkitrangaz_boyz_spawn", 2, g_med_deployment_size)
	SGroup_AddLeaders("sg_rokkitrangaz1")
	for i = 1, SGroup_Count(SGroup_FromName("sg_rokkitrangaz1")) do
		Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_rokkitrangaz1"), i), "ork_rokkit_launcha_tankbusta", 4)
	end
	SGroup_AddGroup(SGroup_FromName("sg_clan_orks2"), SGroup_FromName("sg_rokkitrangaz1"))
	
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_rokkitrangaz2", "ork_squad_tankbusta", "mkr_rokkitrangaz_boyz_spawn", 2, g_med_deployment_size)
	SGroup_AddLeaders("sg_rokkitrangaz2")	
	for i = 1, SGroup_Count(SGroup_FromName("sg_rokkitrangaz2")) do
		Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_rokkitrangaz2"), i), "ork_rokkit_launcha_tankbusta", 4)
	end
	SGroup_AddGroup(SGroup_FromName("sg_clan_orks2"), SGroup_FromName("sg_rokkitrangaz2"))
	
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_rokkitrangaz3", "ork_squad_nob", "mkr_rokkitrangaz_boyz_spawn", 1, g_large_deployment_size)
	SGroup_AddLeaders("sg_rokkitrangaz3")
	SGroup_AddGroup(SGroup_FromName("sg_clan_orks2"), SGroup_FromName("sg_rokkitrangaz3"))
	
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_rokkitrangaz4", "ork_squad_grot", "mkr_rokkitrangaz_boyz_spawn", 1, g_large_deployment_size)
	SGroup_AddGroup(SGroup_FromName("sg_clan_orks2"), SGroup_FromName("sg_rokkitrangaz4"))
	
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_rokkitrangaz5", "ork_squad_slugga", "mkr_rokkitrangaz_boyz_spawn", 1, g_large_deployment_size)
	SGroup_AddGroup(SGroup_FromName("sg_clan_orks2"), SGroup_FromName("sg_rokkitrangaz5"))
	
	
	Util_CreateSquadsAtMarker(g_Player2, "sg_rokkitrangaz_boss", "ork_squad_mek_boy_advance_sp", "mkr_rokkitrangaz_boss", 1)
	SGroup_AddGroup(SGroup_FromName("sg_clan_bosses"), SGroup_FromName("sg_rokkitrangaz_boss"))
	SGroup_AddGroup(SGroup_FromName("sg_clan_orks2"), SGroup_FromName("sg_rokkitrangaz_boss"))
	
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_loyalists2", "ork_squad_nob_advance_sp", "mkr_loyalists_at_rokkitrangaz", 2, g_clan_deployment_size)
	SGroup_AddLeaders("sg_loyalists2")
	
	Rule_AddInterval(Rule_Ork_Rokkitrangaz_Interception, 2)
	
	Rule_AddInterval(Rule_Ork_Base2_Movement, 45)
	
	g_rokkitrangaz_defense_created = true
	
end

end

function Rule_Ork_Burnaboyz_Creation()

if g_burnaboyz_defense_created == false then

-- SGroup_CreateIfNotFound("sg_clan_orks3")

Util_CreateSquadsAtMarkerEx(g_Player2, "sg_burnaboyz1", "ork_squad_slugga", "mkr_burnaboyz_boyz_spawn", 1, g_large_deployment_size)
SGroup_AddLeaders("sg_burnaboyz1")
for i = 1, SGroup_Count(SGroup_FromName("sg_burnaboyz1")) do
	Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_burnaboyz1"), i), "ork_burna_slugga", g_med_deployment_size)
end
SGroup_AddGroup(SGroup_FromName("sg_clan_orks3"), SGroup_FromName("sg_burnaboyz1"))	

Util_CreateSquadsAtMarkerEx(g_Player2, "sg_burnaboyz2", "ork_squad_slugga", "mkr_burnaboyz_boyz_spawn", 1, g_large_deployment_size)
SGroup_AddLeaders("sg_burnaboyz2")	
for i = 1, SGroup_Count(SGroup_FromName("sg_burnaboyz2")) do
	Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_burnaboyz2"), i), "ork_burna_slugga", g_med_deployment_size)
end
SGroup_AddGroup(SGroup_FromName("sg_clan_orks3"), SGroup_FromName("sg_burnaboyz2"))

Util_CreateSquadsAtMarkerEx(g_Player2, "sg_burnaboyz3", "ork_squad_nob", "mkr_burnaboyz_boyz_spawn", 1, g_large_deployment_size)
SGroup_AddLeaders("sg_burnaboyz3")
SGroup_AddGroup(SGroup_FromName("sg_clan_orks3"), SGroup_FromName("sg_burnaboyz3"))

Util_CreateSquadsAtMarkerEx(g_Player2, "sg_burnaboyz4", "ork_squad_grot", "mkr_burnaboyz_boyz_spawn", 1, g_large_deployment_size)
SGroup_AddGroup(SGroup_FromName("sg_clan_orks3"), SGroup_FromName("sg_burnaboyz4"))

Util_CreateSquadsAtMarkerEx(g_Player2, "sg_burnaboyz5", "ork_squad_slugga", "mkr_burnaboyz_boyz_spawn", 1, g_large_deployment_size)
SGroup_AddGroup(SGroup_FromName("sg_clan_orks3"), SGroup_FromName("sg_burnaboyz5"))


Util_CreateSquadsAtMarker(g_Player2, "sg_burnaboyz_boss", "ork_squad_mek_boy_advance_sp", "mkr_burnaboyz_boss", 1)
SGroup_AddGroup(SGroup_FromName("sg_clan_bosses"), SGroup_FromName("sg_burnaboyz_boss"))
SGroup_AddGroup(SGroup_FromName("sg_clan_orks3"), SGroup_FromName("sg_burnaboyz_boss"))

	
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_loyalists3", "ork_squad_nob_advance_sp", "mkr_loyalists_at_burnaboyz", 2, g_clan_deployment_size)
SGroup_AddLeaders("sg_loyalists3")


Rule_AddInterval(Rule_Ork_Burnaboyz_Interception, 2)

Rule_AddInterval(Rule_Ork_Base3_Movement, 45)

g_burnaboyz_defense_created = true

end

end

function Rule_Ork_Kwikmekz_Creation()

if g_kwikmekz_defense_created == false then
--	SGroup_CreateIfNotFound("sg_clan_orks4")
	
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_kwikmekz1", "ork_squad_slugga", "mkr_kwikmekz_boyz_spawn", 1, g_large_deployment_size)
	SGroup_AddLeaders("sg_kwikmekz1")
	SGroup_AddGroup(SGroup_FromName("sg_clan_orks4"), SGroup_FromName("sg_kwikmekz1"))	
	
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_kwikmekz2", "ork_squad_shoota_boy", "mkr_kwikmekz_boyz_spawn", 1, g_large_deployment_size)
	SGroup_AddLeaders("sg_kwikmekz2")	
	SGroup_AddGroup(SGroup_FromName("sg_clan_orks4"), SGroup_FromName("sg_kwikmekz2"))	
	
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_kwikmekz4", "ork_squad_grot", "mkr_kwikmekz_grot_spawn", 1, g_large_deployment_size)
	SGroup_AddGroup(SGroup_FromName("sg_clan_orks4"), SGroup_FromName("sg_kwikmekz4"))
	
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_kwikmekz5", "ork_squad_slugga", "mkr_kwikmekz_boyz_spawn", 1, g_large_deployment_size)
	SGroup_AddGroup(SGroup_FromName("sg_clan_orks4"), SGroup_FromName("sg_kwikmekz5"))
	
	
	Util_CreateSquadsAtMarker(g_Player2, "sg_kwikmekz_boss", "ork_squad_mek_boy_advance_sp", "mkr_kwikmekz_boss", 1)
	SGroup_AddGroup(SGroup_FromName("sg_clan_bosses"), SGroup_FromName("sg_kwikmekz_boss"))
	SGroup_AddGroup(SGroup_FromName("sg_clan_orks4"), SGroup_FromName("sg_kwikmekz_boss"))	
	
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_loyalists4", "ork_squad_nob_advance_sp", "mkr_loyalists_at_kwikmekz", 2, g_clan_deployment_size)
	SGroup_AddLeaders("sg_loyalists4")
		
	for i = 1, 1 do
		Util_CreateSquadsAtMarkerEx(g_Player2, "sg_kwikmekz_tanks"..i, "ork_squad_looted_tank", "mkr_kwikmekz_tank_spawn"..i, 1, 1)
		SGroup_AddGroup(SGroup_FromName("sg_clan_orks4"), SGroup_FromName("sg_kwikmekz_tanks"..i))	
	end
	
	for i = 1, 2 do
		Util_CreateSquadsAtMarkerEx(g_Player2, "sg_kwikmekz_kans"..i, "ork_squad_killa_kan", "mkr_kwikmekz_kans", 1, 1)
		SGroup_AddGroup(SGroup_FromName("sg_clan_orks4"), SGroup_FromName("sg_kwikmekz_kans"..i))	
	end

	Rule_AddInterval(Rule_Ork_Kwikmekz_Interception, 2)
	
	Rule_AddInterval(Rule_Ork_Base4_Movement, 45)
	
	g_kwikmekz_defense_created = true

end

end

function Rule_Ork_Footstompaz_Creation() if g_footstompaz_defense_created == false then -- SGroup_CreateIfNotFound("sg_clan_orks5")

	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_footstompaz1", "ork_squad_slugga", "mkr_footstompaz_boyz_spawn", 1, g_large_deployment_size)
	SGroup_AddLeaders("sg_footstompaz1")
	SGroup_AddGroup(SGroup_FromName("sg_clan_orks5"), SGroup_FromName("sg_footstompaz1"))	
	
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_footstompaz2", "ork_squad_shoota_boy", "mkr_footstompaz_boyz_spawn", 1, g_large_deployment_size)
	SGroup_AddLeaders("sg_footstompaz2")	
	for i = 1, SGroup_Count(SGroup_FromName("sg_footstompaz2")) do
		Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_footstompaz2"), i), "ork_big_shoota_shoota", 5)
	end
	SGroup_AddGroup(SGroup_FromName("sg_clan_orks5"), SGroup_FromName("sg_footstompaz2"))	
	
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_footstompaz5", "ork_squad_slugga", "mkr_footstompaz_boyz_spawn", 1, g_large_deployment_size)
	SGroup_AddGroup(SGroup_FromName("sg_clan_orks5"), SGroup_FromName("sg_footstompaz5"))
	
	
	Util_CreateSquadsAtMarker(g_Player2, "sg_footstompaz_boss", "ork_squad_mek_boy_advance_sp", "mkr_footstompaz_boss", 1)
	SGroup_AddGroup(SGroup_FromName("sg_clan_bosses"), SGroup_FromName("sg_footstompaz_boss"))
	SGroup_AddGroup(SGroup_FromName("sg_clan_orks5"), SGroup_FromName("sg_footstompaz_boss"))	

	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_loyalists5", "ork_squad_nob_advance_sp", "mkr_loyalists_at_footstompaz", 2, g_clan_deployment_size)
	SGroup_AddLeaders("sg_loyalists5")
	
	Rule_AddInterval(Rule_Ork_Footstompaz_Interception, 2)
	
	Rule_AddInterval(Rule_Ork_Base5_Movement, 45)
	
	g_footstompaz_defense_created = true
	
	
	
end	

end


--[[Gameplay Starts]]

--[[Mission Start Text (Race Specific)]]

function Rule_Play_Race_Specific_Opening_Text()

if g_player_race_type == "chaos_marine_race" then
	
	Rule_AddOneShot(Rule_IE_Chaos_Mission_Start, 1)
	
	Rule_Remove(Rule_Play_Race_Specific_Opening_Text)
	
elseif g_player_race_type == "eldar_race" then
	
	Rule_AddOneShot(Rule_IE_Eldar_Mission_Start, 1)
	
	Rule_Remove(Rule_Play_Race_Specific_Opening_Text)
	
elseif g_player_race_type == "guard_race" then
	
	Rule_AddOneShot(Rule_IE_IG_Mission_Start, 1)
	
	Rule_Remove(Rule_Play_Race_Specific_Opening_Text)
	
elseif g_player_race_type == "space_marine_race" then
	
	Rule_AddOneShot(Rule_IE_Space_Marine_Mission_Start, 1)
	
	Rule_Remove(Rule_Play_Race_Specific_Opening_Text)
	
elseif g_player_race_type == "tau_race" then
	
	Rule_AddOneShot(Rule_IE_Tau_Mission_Start, 1)
	
	Rule_Remove(Rule_Play_Race_Specific_Opening_Text)
	
elseif g_player_race_type == "necron_race" then
	
	Rule_AddOneShot(Rule_IE_Necron_Mission_Start, 1)
	
	Rule_Remove(Rule_Play_Race_Specific_Opening_Text)
	
end

end

-- what happens when player approaches Gorgutz' base function Rule_Approach_Gorgutz_Base()

if Player_AreSquadsNearMarker(g_Player1, "mkr_gorgutz_base") then
	
	
	if g_player_race_type == "chaos_marine_race" then
		
		Rule_AddOneShot(Rule_IE_Chaos_Approach_Gorgutz, 1)
		
		Rule_Remove(Rule_Approach_Gorgutz_Base)
		
	elseif g_player_race_type == "eldar_race" then
		
		Rule_AddOneShot(Rule_IE_Eldar_Approach_Gorgutz, 1)
		
		Rule_Remove(Rule_Approach_Gorgutz_Base)
		
	elseif g_player_race_type == "guard_race" then
		
		Rule_AddOneShot(Rule_IE_IG_Approach_Gorgutz, 1)
		
		Rule_Remove(Rule_Approach_Gorgutz_Base)
		
	elseif g_player_race_type == "space_marine_race" then
		
		Rule_AddOneShot(Rule_IE_Space_Marine_Approach_Gorgutz, 1)
		
		Rule_Remove(Rule_Approach_Gorgutz_Base)
		
	elseif g_player_race_type == "tau_race" then
		
		Rule_AddOneShot(Rule_IE_Tau_Approach_Gorgutz, 1)
		
		Rule_Remove(Rule_Approach_Gorgutz_Base)
		
	elseif g_player_race_type == "necron_race" then
		
		Rule_AddOneShot(Rule_IE_Necron_Approach_Gorgutz, 1)
		
		Rule_Remove(Rule_Approach_Gorgutz_Base)
		
	end
	
	
	Rule_Remove(Rule_Approach_Gorgutz_Base)
	
end

end


--[[INTERCEPTION]] --These rules govern how the Orks will send out interception units against the player whenever the player strays close to a base function Rule_Ork_Headcrushaz_Interception()

if g_headcrushaz_interceptors_dead >= table.getn(t_ork_interceptors.interceptor_units[1]) then -- 2
	
	Rule_Remove(Rule_Ork_Headcrushaz_Interception) -- removes rule when all interceptor units are dead
	
elseif g_headcrushaz_interceptors_dead <= (table.getn(t_ork_interceptors.interceptor_units[1]) - 1) then
	
	--for i = 1, 5 do
		
		if Player_AreSquadsNearMarker(g_Player1, t_clan_base_list[1]) then
			
			Player_GetAllSquadsNearMarker(g_Player1, "sg_to_be_intercepted_by_headcrushaz", t_clan_base_list[1])
			
			for n = 1, table.getn(t_ork_interceptors.interceptor_units[1]) do
				
				if SGroup_Exists(t_ork_interceptors.interceptor_units[1][n]) and SGroup_IsEmpty(t_ork_interceptors.interceptor_units[1][n]) == false then
					
					Cmd_AttackSGroup(t_ork_interceptors.interceptor_units[1][n], "sg_to_be_intercepted_by_headcrushaz")
					
				elseif (SGroup_Exists(t_ork_interceptors.interceptor_units[1][n]) and SGroup_IsEmpty(t_ork_interceptors.interceptor_units[1][n]) == true) and 
					t_ork_interceptors.interceptor_status[1][n] == true then
					
					t_ork_interceptors.interceptor_status[1][n] = false
					g_headcrushaz_interceptors_dead = g_headcrushaz_interceptors_dead + 1
					
				end
				
			end
			
		end
		
	--end
	
end

end

function Rule_Ork_Rokkitrangaz_Interception()

if g_rokkitrangaz_interceptors_dead >= table.getn(t_ork_interceptors.interceptor_units[2])  then
	
	Rule_Remove(Rule_Ork_Rokkitrangaz_Interception) -- removes rule when all interceptor units are dead
	
elseif g_rokkitrangaz_interceptors_dead <= (table.getn(t_ork_interceptors.interceptor_units[2]) - 1) then
	
	--for i = 1, 5 do
		
		if Player_AreSquadsNearMarker(g_Player1, t_clan_base_list[2]) then
			
			Player_GetAllSquadsNearMarker(g_Player1, "sg_to_be_intercepted_by_rokkitrangaz", t_clan_base_list[2])
			
			for n = 1, table.getn(t_ork_interceptors.interceptor_units[2]) do
				
				if SGroup_Exists(t_ork_interceptors.interceptor_units[2][n]) and SGroup_IsEmpty(t_ork_interceptors.interceptor_units[2][n]) == false then
					
					Cmd_AttackSGroup(t_ork_interceptors.interceptor_units[2][n], "sg_to_be_intercepted_by_rokkitrangaz")
					
				elseif (SGroup_Exists(t_ork_interceptors.interceptor_units[2][n]) and SGroup_IsEmpty(t_ork_interceptors.interceptor_units[2][n]) == true) and 
					t_ork_interceptors.interceptor_status[2][n] == true then
					
					t_ork_interceptors.interceptor_status[2][n] = false
					g_rokkitrangaz_interceptors_dead = g_rokkitrangaz_interceptors_dead + 1
					
				end
				
			end
			
		end
		
	--end
	
end

end

function Rule_Ork_Burnaboyz_Interception()

if g_burnaboyz_interceptors_dead >= table.getn(t_ork_interceptors.interceptor_units[3])  then
	
	Rule_Remove(Rule_Ork_Burnaboyz_Interception) -- removes rule when all interceptor units are dead
	
elseif g_burnaboyz_interceptors_dead <= (table.getn(t_ork_interceptors.interceptor_units[3]) -1) then
	
	--for i = 1, 5 do
		
		if Player_AreSquadsNearMarker(g_Player1, t_clan_base_list[3]) then
			
			Player_GetAllSquadsNearMarker(g_Player1, "sg_to_be_intercepted_by_burnaboyz", t_clan_base_list[3])
			
			for n = 1, table.getn(t_ork_interceptors.interceptor_units[3]) do
				
				if SGroup_Exists(t_ork_interceptors.interceptor_units[3][n]) and SGroup_IsEmpty(t_ork_interceptors.interceptor_units[3][n]) == false then
					
					Cmd_AttackSGroup(t_ork_interceptors.interceptor_units[3][n], "sg_to_be_intercepted_by_burnaboyz")
					
				elseif (SGroup_Exists(t_ork_interceptors.interceptor_units[3][n]) and SGroup_IsEmpty(t_ork_interceptors.interceptor_units[3][n]) == true) and 
					t_ork_interceptors.interceptor_status[3][n] == true then
					
					t_ork_interceptors.interceptor_status[3][n] = false
					g_burnaboyz_interceptors_dead = g_burnaboyz_interceptors_dead + 1
					
				end
				
			end
			
		end
		
	--end
	
end

end

function Rule_Ork_Kwikmekz_Interception()

if g_kwikmekz_interceptors_dead >= table.getn(t_ork_interceptors.interceptor_units[4])  then
	
	Rule_Remove(Rule_Ork_Kwikmekz_Interception) -- removes rule when all interceptor units are dead
	
elseif g_kwikmekz_interceptors_dead <= (table.getn(t_ork_interceptors.interceptor_units[4]) -1)  then
	
	--for i = 1, 5 do
		
		if Player_AreSquadsNearMarker(g_Player1, t_clan_base_list[4]) then
			
			Player_GetAllSquadsNearMarker(g_Player1, "sg_to_be_intercepted_by_kwikmekz", t_clan_base_list[4])
			
			for n = 1, table.getn(t_ork_interceptors.interceptor_units[4]) do
				
				if SGroup_Exists(t_ork_interceptors.interceptor_units[4][n]) and SGroup_IsEmpty(t_ork_interceptors.interceptor_units[4][n]) == false then
					
					Cmd_AttackSGroup(t_ork_interceptors.interceptor_units[4][n], "sg_to_be_intercepted_by_kwikmekz")
					
				elseif (SGroup_Exists(t_ork_interceptors.interceptor_units[4][n]) and SGroup_IsEmpty(t_ork_interceptors.interceptor_units[4][n]) == true) and 
					t_ork_interceptors.interceptor_status[4][n] == true then
					
					t_ork_interceptors.interceptor_status[4][n] = false
					g_kwikmekz_interceptors_dead = g_kwikmekz_interceptors_dead + 1
					
				end
				
			end
			
		end
		
	--end
	
end

end

function Rule_Ork_Footstompaz_Interception()

if g_footstompaz_interceptors_dead >= table.getn(t_ork_interceptors.interceptor_units[5])  then
	
	Rule_Remove(Rule_Ork_Footstompaz_Interception) -- removes rule when all interceptor units are dead
	
elseif g_footstompaz_interceptors_dead <= (table.getn(t_ork_interceptors.interceptor_units[5]) -1)  then
	
	--for i = 1, 5 do
		
		if Player_AreSquadsNearMarker(g_Player1, t_clan_base_list[5]) then
			
			Player_GetAllSquadsNearMarker(g_Player1, "sg_to_be_intercepted_by_footstompaz", t_clan_base_list[5])
			
			for n = 1, table.getn(t_ork_interceptors.interceptor_units[5]) do
				
				if SGroup_Exists(t_ork_interceptors.interceptor_units[5][n]) and SGroup_IsEmpty(t_ork_interceptors.interceptor_units[5][n]) == false then
					
					Cmd_AttackSGroup(t_ork_interceptors.interceptor_units[5][n], "sg_to_be_intercepted_by_footstompaz")
					
				elseif (SGroup_Exists(t_ork_interceptors.interceptor_units[5][n]) and SGroup_IsEmpty(t_ork_interceptors.interceptor_units[5][n]) == true) and 
					t_ork_interceptors.interceptor_status[5][n] == true then
					
					t_ork_interceptors.interceptor_status[5][n] = false
					g_footstompaz_interceptors_dead = g_footstompaz_interceptors_dead + 1
					
				end
				
			end
			
		end
		
	--end
	
end

end


--checks to see if certain assets exist. If they don't the associated Orks will lose morale function Rule_Morale_Loss()

for i = 1,4 do 
	
	if EGroup_Exists(t_morale_droppers.name[i]) and EGroup_IsEmpty(t_morale_droppers.name[i]) and t_morale_droppers.status[i] == false then
		
		t_morale_droppers.status[i] = true
		SGroup_SetAvgMorale(t_morale_droppers.target[i], 0.0)
		g_broken_number = g_broken_number + 1
		
	end
	
end

if SGroup_Exists(t_morale_droppers.name[5]) and SGroup_IsEmpty(t_morale_droppers.name[5]) and t_morale_droppers.status[5] == false then
	
	t_morale_droppers.status[5] = true
	SGroup_SetAvgMorale(t_morale_droppers.target[5], 0.0)
	g_broken_number = g_broken_number + 1
	
end

if g_broken_number >= 5 then
	Rule_Remove(Rule_Morale_Loss)
end

end



--bunch of vehicles for the track function Rule_Ork_Vehicle_Kickoff()

SGroup_CreateIfNotFound("sg_ork_racers")

--g_ork_racer_population is determined by the stronghold difficulty variables

for i = 1, g_ork_racer_population do
	
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_ork_racer_patrol"..i, "ork_squad_wartrak", "mkr_track_spawn", 1, 1)
	SGroup_AddGroup(SGroup_FromName("sg_ork_racers"), SGroup_FromName("sg_ork_racer_patrol"..i))
	
end

Rule_AddIntervalDelay(Rule_Ork_Racer_Patrol, 2, 1)	

end

-- controls the ork vehicles on the dirt track function Rule_Ork_Racer_Patrol()

for i = 1, g_ork_racer_population do
	
	if SGroup_Exists("sg_ork_racer_patrol"..i) and SGroup_IsEmpty("sg_ork_racer_patrol"..i) == false then
		
		if SGroup_IsUnderAttackByPlayer("sg_ork_racer_patrol"..i, false, g_Player1) == false then
			
			for n = 1, g_ork_racer_waypoints do
				
				if (t_ork_racer_patrol_table[i] == n) and (t_ork_racer_patrol_table[i] <= g_ork_racer_waypoints)then
					
					Cmd_AttackMoveMarker("sg_ork_racer_patrol"..i, "mkr_track_waypoint"..n)
					
					if SGroup_CheckActiveCommand("sg_ork_racer_patrol"..i, SQUADSTATEID_Idle, false) then
						--if the vehicle unit in question is idle, then the game will force it to attack move towards the next waypoint
						Cmd_AttackMoveMarker("sg_ork_racer_patrol"..i, "mkr_track_waypoint"..n)
						--print("idleness fixed for vehicles")
					end
					
					if Prox_AnySquadNearMarker("sg_ork_racer_patrol"..i, "mkr_track_waypoint"..n) == true then
						
						t_ork_racer_patrol_table[i] = n + 1
						
					end
					
				elseif t_ork_racer_patrol_table[i] >= (g_ork_racer_waypoints + 1)  then
					
					t_ork_racer_patrol_table[i] = 1
					
				end
				
			end
			
		end
		
	elseif SGroup_Count(SGroup_FromName("sg_ork_racers")) == 0 then
		
		Rule_Remove(Rule_Ork_Racer_Patrol);
		
	end

end

end

--[[ function TeamSwitchTest()

SGroup_SetPlayerOwner("sg_headcrushaz1", g_Player3)

end]]

-- Banners are now what the game uses to see if a faction goes crazy. If a banner gets destroyed, the faction switches sides. function Rule_Banner_Tracker()

for i = 1, g_banner_table_count do
	
	if t_banner_status[i] == true then
		
		if EGroup_Exists(t_banner_table[i]) and EGroup_IsEmpty(t_banner_table[i]) == true then
			
			t_banner_status[i] = false
			
			--if the clan buildings exist, then switch over the clan buildings
			if EGroup_Exists("eg_clan_buildings"..i) and EGroup_IsEmpty("eg_clan_buildings"..i) == false then
				EGroup_SetPlayerOwner("eg_clan_buildings"..i, t_cpu_player_table.cpu_player_name[i])
			end
			
			--if there are any orks alive, switch over some of the survivors
			if SGroup_Exists("sg_clan_orks"..i) and SGroup_IsEmpty("sg_clan_orks"..i) == false then
				
				for j = 1, table.getn(t_ork_base_defender_table[i]) do
                    
					if SGroup_Exists(t_ork_base_defender_table[i][j]) and SGroup_IsEmpty(t_ork_base_defender_table[i][j]) == false then
                          
						if Squad_GetActiveCommand(SGroup_GetSpawnedSquadAt(SGroup_FromName(t_ork_base_defender_table[i][j]), 1)) == SQUADSTATEID_Combat then
                            
							SGroup_SetPlayerOwner(t_ork_base_defender_table[i][j], t_cpu_player_table.cpu_player_name[i])
							SGroup_AddGroup(SGroup_CreateIfNotFound("sg_Rebel_Scum"..i), SGroup_FromName(t_ork_base_defender_table[i][j]))
							World_FXEventSquad("data:Art/Events/Unit_Upgrade_Morale_FX/Reinforce_Trooper", SGroup_FromName(t_ork_base_defender_table[i][j]))
							Cmd_StopSquads(t_ork_base_defender_table[i][j])
                            
						elseif t_odd[j] == false then
                            
							SGroup_SetPlayerOwner(t_ork_base_defender_table[i][j], t_cpu_player_table.cpu_player_name[i])
							SGroup_AddGroup(SGroup_CreateIfNotFound("sg_Rebel_Scum"..i), SGroup_FromName(t_ork_base_defender_table[i][j]))
							World_FXEventSquad("data:Art/Events/Unit_Upgrade_Morale_FX/Reinforce_Trooper", SGroup_FromName(t_ork_base_defender_table[i][j]))
                            
						elseif t_odd[j] == true then
                            
							SGroup_AddGroup(SGroup_CreateIfNotFound("sg_Imperials"..i), SGroup_FromName(t_ork_base_defender_table[i][j]))
                            
						end
						
					end
                    
				end
                
				if (SGroup_Exists("sg_Rebel_Scum"..i) and SGroup_IsEmpty("sg_Rebel_Scum"..i) == false) and
					(SGroup_Exists("sg_Imperials"..i) and SGroup_IsEmpty("sg_Imperials"..i) == false)	then 
					
					Cmd_AttackSGroup("sg_Rebel_Scum"..i, "sg_Imperials"..i)
					Cmd_AttackSGroup("sg_Imperials"..i, "sg_Rebel_Scum"..i)
					
				end
                
			end
            
			FOW_RevealMarker(t_ork_interceptors.base_name[i], 30)
            
			--switches the outpost teams
			for n = 1, 4 do
                
				if SGroup_Exists("sg_ork_outpost"..i.."defender"..n) and SGroup_IsEmpty("sg_ork_outpost"..i.."defender"..n) == false then
					SGroup_SetPlayerOwner("sg_ork_outpost"..i.."defender"..n, t_cpu_player_table.cpu_player_name[i])
				end
                
				if EGroup_Exists("eg_outpost"..i) and EGroup_IsEmpty("eg_outpost"..i) == false then
					EGroup_SetPlayerOwner("eg_outpost"..i, t_cpu_player_table.cpu_player_name[i])
				end
                
			end
            
			FOW_RevealMarker("mkr_show_relic_area", 10)
             
			--Player_SetTeam(t_cpu_player_table.cpu_player_name[i], t_cpu_player_table.cpu_team_list[i])            
			Cpu_Enable(t_cpu_player_table.cpu_player_name[i], true )
			Cpu_ForceAttack(t_cpu_player_table.cpu_player_name[i], g_Player2) -- forces attack on Gorgutz
            Cpu_EnableComponent(t_cpu_player_table.cpu_player_name[i], false, CT_Resourcing) -- disables the AI so that it doesn't capture points and mess up the capture point tracking.
			
			t_ork_rebellion_status[i] = true
			
            --Rule_AddOneShot(t_rebel_notification[i], 2)
			
			
			--determines dialogue spoken
			if i == 1 then
				
				Rule_AddOneShot(Rule_IE_Headcrushaz_Rebellion,0)
				
				g_nis_rebels = 1
				
				if g_mid_nis_played == false then
					Util_StartNIS( EVENTS.NIS_Mid ) 	
					g_mid_nis_played = true
				end
				
			elseif i == 2 then
				
				Rule_AddOneShot(Rule_IE_Rokkitrangaz_Rebellion,0)
				
				g_nis_rebels = 2
				
				if g_mid_nis_played == false then
					Util_StartNIS( EVENTS.NIS_Mid ) 	
					g_mid_nis_played = true
				end
				
			elseif i == 3 then
				
				Rule_AddOneShot(Rule_IE_Burnaboyz_Rebellion,0)
				
				g_nis_rebels = 3
				
				if g_mid_nis_played == false then
					Util_StartNIS( EVENTS.NIS_Mid ) 	
					g_mid_nis_played = true
				end
				
			elseif i == 4 then
				
				Rule_AddOneShot(Rule_IE_Kwikmekz_Rebellion,0)
				
				g_nis_rebels = 4
				
				if g_mid_nis_played == false then
					Util_StartNIS( EVENTS.NIS_Mid ) 	
					g_mid_nis_played = true
				end
				
			elseif i == 5 then
				
				Rule_AddOneShot(Rule_IE_Footstompaz_Rebellion, 0)
				
				g_nis_rebels = 5
				
				if g_mid_nis_played == false then
					Util_StartNIS( EVENTS.NIS_Mid ) 	
					g_mid_nis_played = true
				end
				
			end
			
			
			if EGroup_Exists(t_bases_of_operation.constructionbuildings[i]) and EGroup_IsEmpty(t_bases_of_operation.constructionbuildings[i]) == false then
				
				Util_CreateSquadsAtMarkerEx(t_cpu_player_table.cpu_player_name[i], "sg_rebel"..i, "ork_squad_slugga", t_cpu_player_table.cpu_rebel_spawn[i], 1, 12)
				SGroup_AddLeaders("sg_rebel"..i)           
				
				Cmd_AttackMoveMarker("sg_rebel"..i, "mkr_gorgutz_outer_guard_spawn")
				
			end
			
		end
		
	end
	
end

end

-- stops the ping by Gorgutz function Rule_Gorgutz_Ping_Stop() Util_Ping_Stop("ping_gorgutz") end

-- this function controls if the worshipping orks in the middle stop what they're doing once they are under attack. If they are under attack, then the capture animation is stopped -- if by any chance the attacks stop and nothing happens, then 5 seconds later the game will call the worshipper return function function Rule_Worshipper_Control()

if SGroup_Exists("sg_worshipping_orks") and SGroup_IsEmpty("sg_worshipping_orks") == false then
	

-- for i = 1, 5 do

--		if SGroup_Exists("sg_worshippers"..i) and SGroup_IsEmpty("sg_worshippers"..i) == false then
			if Prox_PlayerSquadsInProximityOfSquads( g_Player1, "sg_worshipping_orks", 50, false)  or 
			(SGroup_IsUnderAttack("sg_worshipping_orks", false) == true and g_ork_worshippers_under_attack == false) then
			--if (SGroup_IsUnderAttack("sg_worshipping_orks", false) == true and g_ork_worshippers_under_attack == false)  then
				
				if g_stop_animation == false then
					
					Anim_StopSGroupAnim( SGroup_FromName("sg_worshipping_orks"), "capture_strategic_point") -- "sg_worshipping_orks"
					
					g_stop_animation = true
					
					Cmd_SetStance("sg_worshipping_orks", STANCE_Attack)
					
					print("animation stopped")
					
				end
					
				g_ork_worshippers_under_attack = true
				
				
				for n = 1, 5 do
					t_group_is_ready[n] = false
				end
				
				print("ready all false")
				
			elseif (SGroup_IsUnderAttack("sg_worshipping_orks", true) == false and g_ork_worshippers_under_attack == true) then
				
				
				if g_worship_wait_count <= 4 then
					
					g_worship_wait_count = g_worship_wait_count + 1
					
					print("worshipping wait counting: "..g_worship_wait_count)
					
				end
				
				
			end
			
		--end
		
	--end
	
	if g_worship_wait_count >= 5 and g_stop_animation == true then
	
		g_ork_worshippers_under_attack = false
		
		g_worship_wait_count = 0
		
		g_return_on = true
		print("return on is true, and adding worshipper return")
		Rule_Check_AddInterval(Rule_Worshipper_Return, 1)
		Rule_Remove(Rule_Worshipper_Control)
		
	end
	
	
	
	
end

end

function Rule_Worshipper_Return() --governs the behaviour of the worshippers when they are not under attack (as determined by Rule_Worshipper_Control) -- basically, it moves the orks to their markers, and then once they are all in place, then they all start doing their worshipping animation at once. --the actual animation call is done in Rule_Start_Animation

if g_return_on == true then -- only activates if g_return_on is on
	
	--if SGroup_Exists("sg_worshipping_orks") and SGroup_IsEmpty("sg_worshipping_orks") == false then
		
		for i = 1, 5 do
			
			if SGroup_Exists("sg_worshippers"..i) and SGroup_IsEmpty("sg_worshippers"..i) == false and t_group_is_ready[i] == false then
				
				Cmd_AttackMoveMarker("sg_worshippers"..i, "mkr_ork_worship"..i)
				
				if Prox_AnySquadNearMarker("sg_worshippers"..i, "mkr_ork_worship"..i) and t_group_is_ready[i] == false and SGroup_CheckActiveCommand("sg_worshippers"..i , SQUADSTATEID_Idle, true) then
					
					print("tgroup "..i.." is ready")
					
					t_group_is_ready[i] = true
					
					Cmd_SetStance("sg_worshippers"..i, STANCE_Hold)
					
					g_ready_count = g_ready_count + 1
					
					print("ready count = "..g_ready_count)
					
				end
				
			--[[	
			elseif SGroup_Exists("sg_worshippers"..i) and SGroup_IsEmpty("sg_worshippers"..i) == true and t_group_is_dead[i] == false then
			
				t_group_is_dead[i] = true
				
				g_dead_units = g_dead_units + 1
				
				print("dead units = "..g_dead_units)
		
				print(SGroup_Count("sg_worshipping_orks") - g_dead_units)]]

		
			end
			
			
		end
		-- need to account for dead units!!!!!!!
		if g_ready_count == (SGroup_Count("sg_worshipping_orks") --[[- g_dead_units]]) then
		
		
			--Rule_Check_AddInterval(Rule_Start_Animation, 1)
			print("ready count is same as total group minus dead units!")
			g_return_on = false
			g_ready_count = 0
			
		end
		
	--end
elseif g_return_on == false then
	print("return on = false, so starting rule start animation and removing rule worshipper return")
	
	Rule_Check_AddInterval(Rule_Start_Animation, 1)

	Rule_Remove(Rule_Worshipper_Return)
end

	

end

--Makes the game wait 5 seconds before the animation is called, to allow the Orks to "settle down" before commencing the capture point animation to minimize sliding around function Rule_Start_Animation()

if g_stop_animation == true then
	
	if g_anim_wait_count <= 4 then
		
		g_anim_wait_count = g_anim_wait_count + 1
		
	elseif g_anim_wait_count >= 5 then
		
		g_anim_wait_count = 0
		Anim_PlaySGroupAnim(SGroup_FromName("sg_worshipping_orks"), "capture_strategic_point" )	
		print("animation started")
		
		Cmd_SetStance("sg_worshipping_orks", STANCE_CeaseFire)
		
		g_stop_animation = false
		
		Rule_Check_AddInterval(Rule_Worshipper_Control, 1)
		Rule_Remove(Rule_Start_Animation)
		
	end
	
end

end

function Rule_Squiggoths_Gone_Wild() -- this function checks to see if the squiggoth trainer is dead. if so, then the squiggoth/squiggoths will go wild

if SGroup_Exists("sg_squiggoth_trainer") and SGroup_IsEmpty("sg_squiggoth_trainer") == true then

	if SGroup_Exists("sg_squiggoths") and SGroup_IsEmpty("sg_squiggoths") == false then
		SGroup_SetPlayerOwner( "sg_squiggoths", g_Player8 )
		Cpu_Enable(g_Player8, true )
		Rule_Remove(Rule_Squiggoths_Gone_Wild)
	end
end

end

function Rule_Defender1_Movement()

for i = 1, 5 do

	if SGroup_Exists("sg_ork_outpost"..i.."defender1") and SGroup_IsEmpty("sg_ork_outpost"..i.."defender1") == false then
		
		Util_AttackMoveMarkerRandomRadius("sg_ork_outpost"..i.."defender1", "mkr_outpost"..i.."_wandering")
		
	else
		
		--Rule_Remove(Rule_Defender1_Movement)
		
	end

end

end

function Rule_Defender2_Movement()

for i = 1, 5 do
	
	if SGroup_Exists("sg_ork_outpost"..i.."defender2") and SGroup_IsEmpty("sg_ork_outpost"..i.."defender2") == false then
		
		Util_AttackMoveMarkerRandomRadius("sg_ork_outpost"..i.."defender2", "mkr_outpost"..i.."_wandering")
		
	else
		
		--Rule_Remove(Rule_Defender2_Movement)
		
	end
	
end

end

function Rule_Defender3_Movement()

for i = 1, 5 do
	
	if SGroup_Exists("sg_ork_outpost"..i.."defender3") and SGroup_IsEmpty("sg_ork_outpost"..i.."defender3") == false then
		
		Util_AttackMoveMarkerRandomRadius("sg_ork_outpost"..i.."defender3", "mkr_outpost"..i.."_wandering")
		
	else
		
		--Rule_Remove(Rule_Defender3_Movement)
		
	end
	
end

end

function Rule_Defender4_Movement()

for i = 1, 5 do
	
	if SGroup_Exists("sg_ork_outpost"..i.."defender4") and SGroup_IsEmpty("sg_ork_outpost"..i.."defender4") == false then
		
		Util_AttackMoveMarkerRandomRadius("sg_ork_outpost"..i.."defender4", "mkr_outpost"..i.."_wandering")
		
	else
		
		--Rule_Remove(Rule_Defender4_Movement)
		
	end
	
end

end

function Rule_Defender5_Movement() for i = 1,5 do

	if SGroup_Exists("sg_ork_outpost"..i.."defender5") and SGroup_IsEmpty("sg_ork_outpost"..i.."defender5") == false then
		
		Util_AttackMoveMarkerRandomRadius("sg_ork_outpost"..i.."defender5", "mkr_outpost"..i.."_wandering")
		
	else
		
		--Rule_Remove(Rule_Defender5_Movement)
		
	end
	
end

end

function Rule_Ork_Base1_Movement()

for i = 4,5 do

	if SGroup_Exists("sg_headcrushaz"..i) and SGroup_IsEmpty("sg_headcrushaz"..i) == false and (SGroup_IsUnderAttack("sg_headcrushaz"..i, false) == false) then
		
		Util_AttackMoveMarkerRandomRadius("sg_headcrushaz"..i, "mkr_headcrushaz_wandering")
		
	else
		
		--Rule_Remove(Rule_Defender5_Movement)
		
	end
	
end

end

function Rule_Ork_Base2_Movement()

for i = 4,5 do

	if SGroup_Exists("sg_rokkitrangaz"..i) and SGroup_IsEmpty("sg_rokkitrangaz"..i) == false and (SGroup_IsUnderAttack("sg_rokkitrangaz"..i, false) == false) then
		
		Util_AttackMoveMarkerRandomRadius("sg_rokkitrangaz"..i, "mkr_rokkitrangaz_wandering")
		
	else
		
		--Rule_Remove(Rule_Defender5_Movement)
		
	end
	
end

end

function Rule_Ork_Base3_Movement()

for i = 4,5 do

	if SGroup_Exists("sg_burnaboyz"..i) and SGroup_IsEmpty("sg_burnaboyz"..i) == false and (SGroup_IsUnderAttack("sg_burnaboyz"..i, false) == false) then
		
		Util_AttackMoveMarkerRandomRadius("sg_burnaboyz"..i, "mkr_burnaboyz_wandering")
		
	else
		
		--Rule_Remove(Rule_Defender5_Movement)
		
	end
	
end

end

function Rule_Ork_Base4_Movement()

for i = 4,5 do

	if SGroup_Exists("sg_kwikmekz"..i) and SGroup_IsEmpty("sg_kwikmekz"..i) == false and (SGroup_IsUnderAttack("sg_kwikmekz"..i, false) == false) then
		
		Util_AttackMoveMarkerRandomRadius("sg_kwikmekz"..i, "mkr_kwikmekz_wandering")
		
	else
		
		--Rule_Remove(Rule_Defender5_Movement)
		
	end
	
end

end

function Rule_Ork_Base5_Movement()

for i = 4,5 do

	if SGroup_Exists("sg_footstompaz"..i) and SGroup_IsEmpty("sg_footstompaz"..i) == false and (SGroup_IsUnderAttack("sg_footstompaz"..i, false) == false) then
		
		Util_AttackMoveMarkerRandomRadius("sg_footstompaz"..i, "mkr_footstompaz_wandering")
		
	else
		
		--Rule_Remove(Rule_Defender5_Movement)
		
	end
	
end

end

-- patrol function for an external patrol so that the player will periodically encounter other orks that aren't in their base function Rule_External_Patrol1()

if SGroup_Exists("sg_external_patrol1") and SGroup_IsEmpty("sg_external_patrol1") == false then
	
	if g_external_patrol1_move == 0 and Prox_AllSquadsNearMarker("sg_external_patrol1", "mkr_main_patrol1_path1")  then
		
		Cmd_AttackMoveMarker("sg_external_patrol1", "mkr_main_patrol1_path2")
		g_external_patrol1_move = g_external_patrol1_move +1
		
	elseif g_external_patrol1_move == 1 and  Prox_AllSquadsNearMarker("sg_external_patrol1", "mkr_main_patrol1_path2")  then
		
		Cmd_AttackMoveMarker("sg_external_patrol1", "mkr_main_patrol1_path3")
		g_external_patrol1_move = g_external_patrol1_move +1
		
	elseif g_external_patrol1_move == 2 and  Prox_AllSquadsNearMarker("sg_external_patrol1", "mkr_main_patrol1_path3")  then
		
		Cmd_AttackMoveMarker("sg_external_patrol1", "mkr_main_patrol1_path4")
		g_external_patrol1_move = g_external_patrol1_move +1
		
	elseif g_external_patrol1_move == 3 and  Prox_AllSquadsNearMarker("sg_external_patrol1", "mkr_main_patrol1_path4")  then
		
		Cmd_AttackMoveMarker("sg_external_patrol1", "mkr_main_patrol1_path5")
		g_external_patrol1_move = g_external_patrol1_move +1
		
	elseif g_external_patrol1_move == 4 and  Prox_AllSquadsNearMarker("sg_external_patrol1", "mkr_main_patrol1_path5")  then
		
		Cmd_AttackMoveMarker("sg_external_patrol1", "mkr_main_patrol1_path6")
		g_external_patrol1_move = g_external_patrol1_move +1
		
	elseif g_external_patrol1_move == 5 and  Prox_AllSquadsNearMarker("sg_external_patrol1", "mkr_main_patrol1_path6")  then
		
		Cmd_AttackMoveMarker("sg_external_patrol1", "mkr_main_patrol1_path7")
		g_external_patrol1_move = g_external_patrol1_move +1
		
	elseif g_external_patrol1_move == 6 and  Prox_AllSquadsNearMarker("sg_external_patrol1", "mkr_main_patrol1_path7")  then
		
		Cmd_AttackMoveMarker("sg_external_patrol1", "mkr_main_patrol1_path1")
		g_external_patrol1_move = 0
		
	end
	
elseif SGroup_Exists("sg_external_patrol1") == false or SGroup_IsEmpty("sg_external_patrol1") == true then
	
	Rule_Remove(Rule_External_Patrol1)
	
	Rule_AddInterval(Rule_Create_External1, 10)
	
end

end

-- patrol function for an external patrol so that the player will periodically encounter other orks that aren't in their base function Rule_External_Patrol2()

if SGroup_Exists("sg_external_patrol2") and SGroup_IsEmpty("sg_external_patrol2") == false then
	
	if g_external_patrol2_move == 0 and Prox_AllSquadsNearMarker("sg_external_patrol2", "mkr_main_patrol2_path1")  then
		
		Cmd_AttackMoveMarker("sg_external_patrol2", "mkr_main_patrol2_path2")
		g_external_patrol2_move = g_external_patrol2_move +1
		
	elseif g_external_patrol2_move == 1 and  Prox_AllSquadsNearMarker("sg_external_patrol2", "mkr_main_patrol2_path2")  then
		
		Cmd_AttackMoveMarker("sg_external_patrol2", "mkr_main_patrol2_path3")
		g_external_patrol2_move = g_external_patrol2_move +1
		
	elseif g_external_patrol2_move == 2 and  Prox_AllSquadsNearMarker("sg_external_patrol2", "mkr_main_patrol2_path3")  then
		
		Cmd_AttackMoveMarker("sg_external_patrol2", "mkr_main_patrol2_path4")
		g_external_patrol2_move = g_external_patrol2_move +1
		
	elseif g_external_patrol2_move == 3 and  Prox_AllSquadsNearMarker("sg_external_patrol2", "mkr_main_patrol2_path4")  then
		
		Cmd_AttackMoveMarker("sg_external_patrol2", "mkr_main_patrol2_path5")
		g_external_patrol2_move = g_external_patrol2_move +1
		
	elseif g_external_patrol2_move == 4 and  Prox_AllSquadsNearMarker("sg_external_patrol2", "mkr_main_patrol2_path5")  then
		
		Cmd_AttackMoveMarker("sg_external_patrol2", "mkr_main_patrol2_path6")
		g_external_patrol2_move = g_external_patrol2_move +1
		
	elseif g_external_patrol2_move == 5 and  Prox_AllSquadsNearMarker("sg_external_patrol2", "mkr_main_patrol2_path6")  then
		
		Cmd_AttackMoveMarker("sg_external_patrol2", "mkr_main_patrol2_path7")
		g_external_patrol2_move = g_external_patrol2_move +1
		
	elseif g_external_patrol2_move == 6 and  Prox_AllSquadsNearMarker("sg_external_patrol2", "mkr_main_patrol2_path7")  then
		
		Cmd_AttackMoveMarker("sg_external_patrol2", "mkr_main_patrol2_path1")
		g_external_patrol2_move = 0
		
	end
	
elseif SGroup_Exists("sg_external_patrol2") == false or SGroup_IsEmpty("sg_external_patrol2") == true then
	
	Rule_Remove(Rule_External_Patrol2)
	
	Rule_AddInterval(Rule_Create_External2, 10)
	
end

end

-- function for propagating the external patrols if they don't exist or are destroyed. checks to see if either of the designated origins exist. if one doesn't exist then the spawning occurs at the other one function Rule_Create_External1()

if SGroup_Exists("sg_external_patrol1") == false or SGroup_IsEmpty("sg_external_patrol1") == true then

	if EGroup_Exists("eg_external_patrol_construction1") and EGroup_IsEmpty("eg_external_patrol_construction1") == false then
	
		SGroup_CreateIfNotFound("sg_external_patrol1")
		Util_CreateSquadsAtMarkerEx(g_Player2, "sg_external_patrol1_slugga", "ork_squad_slugga", "mkr_external1_spawn1", 1, 6)
		Util_CreateSquadsAtMarkerEx(g_Player2, "sg_external_patrol1_armor", "ork_squad_armored_nob", "mkr_external1_spawn1", 1, 1)	
		SGroup_AddGroup(SGroup_FromName("sg_external_patrol1"),  SGroup_FromName("sg_external_patrol1_slugga"))
		SGroup_AddGroup(SGroup_FromName("sg_external_patrol1"),  SGroup_FromName("sg_external_patrol1_armor"))
		
		Cmd_AttackMoveMarker("sg_external_patrol1", "mkr_main_patrol1_path1")
		
		
		Rule_Remove(Rule_Create_External1)
		Rule_AddInterval(Rule_External_Patrol1, 20)

	
	elseif EGroup_Exists("eg_external_patrol_construction2") and EGroup_IsEmpty("eg_external_patrol_construction2") == false then
	
		SGroup_CreateIfNotFound("sg_external_patrol1")
		Util_CreateSquadsAtMarkerEx(g_Player2, "sg_external_patrol1_slugga", "ork_squad_slugga", "mkr_external1_spawn2", 1, 6)
		Util_CreateSquadsAtMarkerEx(g_Player2, "sg_external_patrol1_armor", "ork_squad_armored_nob", "mkr_external1_spawn2", 1, 1)	
		SGroup_AddGroup(SGroup_FromName("sg_external_patrol1"),  SGroup_FromName("sg_external_patrol1_slugga"))
		SGroup_AddGroup(SGroup_FromName("sg_external_patrol1"),  SGroup_FromName("sg_external_patrol1_armor"))
	
		Cmd_AttackMoveMarker("sg_external_patrol1", "mkr_main_patrol1_path4")
		
		g_external_patrol2_move = 3
	
		Rule_Remove(Rule_Create_External1)
		Rule_AddInterval(Rule_External_Patrol1, 20)
	
	
	elseif (EGroup_Exists("eg_external_patrol_construction1") == false or EGroup_IsEmpty("eg_external_patrol_construction1") == true) and
		(EGroup_Exists("eg_external_patrol_construction2") == false or EGroup_IsEmpty("eg_external_patrol_construction2") == true) then
		
		Rule_Remove(Rule_Create_External1)
		
	end
	
end

end

-- function for propagating the external patrols if they don't exist or are destroyed. checks to see if either of the designated origins exist. if one doesn't exist then the spawning occurs at the other one function Rule_Create_External2()

if SGroup_Exists("sg_external_patrol2") == false or SGroup_IsEmpty("sg_external_patrol2") == true then

	if EGroup_Exists("eg_external_patrol_construction3") and EGroup_IsEmpty("eg_external_patrol_construction3") == false then
	
		SGroup_CreateIfNotFound("sg_external_patrol2")
		Util_CreateSquadsAtMarkerEx(g_Player2, "sg_external_patrol2_slugga", "ork_squad_slugga", "mkr_external2_spawn1", 1, 6)
		Util_CreateSquadsAtMarkerEx(g_Player2, "sg_external_patrol2_armor", "ork_squad_armored_nob", "mkr_external2_spawn1", 1, 1)	
		SGroup_AddGroup(SGroup_FromName("sg_external_patrol2"),  SGroup_FromName("sg_external_patrol2_slugga"))
		SGroup_AddGroup(SGroup_FromName("sg_external_patrol2"),  SGroup_FromName("sg_external_patrol2_armor"))
		
		
		Cmd_AttackMoveMarker("sg_external_patrol1", "mkr_main_patrol2_path1")
		
		Rule_Remove(Rule_Create_External2)
		Rule_AddInterval(Rule_External_Patrol2, 20)
	
	
	elseif EGroup_Exists("eg_external_patrol_construction4") and EGroup_IsEmpty("eg_external_patrol_construction4") == false then
	
		SGroup_CreateIfNotFound("sg_external_patrol2")
		Util_CreateSquadsAtMarkerEx(g_Player2, "sg_external_patrol2_slugga", "ork_squad_slugga", "mkr_external2_spawn2", 1, 6)
		Util_CreateSquadsAtMarkerEx(g_Player2, "sg_external_patrol2_armor", "ork_squad_armored_nob", "mkr_external2_spawn2", 1, 1)	
		SGroup_AddGroup(SGroup_FromName("sg_external_patrol2"),  SGroup_FromName("sg_external_patrol2_slugga"))
		SGroup_AddGroup(SGroup_FromName("sg_external_patrol2"),  SGroup_FromName("sg_external_patrol2_armor"))
	
		Cmd_AttackMoveMarker("sg_external_patrol1", "mkr_main_patrol2_path4")
		g_external_patrol2_move = 3
	
		Rule_Remove(Rule_Create_External2)
		Rule_AddInterval(Rule_External_Patrol2, 20)
	
	
	elseif (EGroup_Exists("eg_external_patrol_construction3") == false or EGroup_IsEmpty("eg_external_patrol_construction3") == true) and
		(EGroup_Exists("eg_external_patrol_construction4") == false or EGroup_IsEmpty("eg_external_patrol_construction4") == true) then
		
		Rule_Remove(Rule_Create_External2)
		
	end
	
end

end

--[[ function Rule_Rent_A_Cop1()

if SGroup_Exists("sg_outpost_patrol1") and SGroup_IsEmpty("sg_outpost_patrol1") == false then
	
	if g_outpost1_patrol_move == 0 and Prox_AllSquadsNearMarker("sg_outpost_patrol1", "mkr_PatrolA1")  then
	
		Cmd_AttackMoveMarker("sg_outpost_patrol1", "mkr_PatrolA2")
		g_outpost1_patrol_move = g_outpost1_patrol_move +1
	
	elseif g_outpost1_patrol_move == 1 and  Prox_AllSquadsNearMarker("sg_outpost_patrol1", "mkr_PatrolA2")  then
	
		Cmd_AttackMoveMarker("sg_outpost_patrol1", "mkr_PatrolA3")
		g_outpost1_patrol_move = g_outpost1_patrol_move +1
		
	elseif g_outpost1_patrol_move == 6 and  Prox_AllSquadsNearMarker("sg_outpost_patrol1", "mkr_PatrolA7")  then
	
		Cmd_AttackMoveMarker("sg_outpost_patrol1", "mkr_PatrolA1")
		g_outpost1_patrol_move = 0

	end

else
	
	Rule_Remove(Rule_Rent_A_Cop1)

end

end

function Rule_Rent_A_Cop2()

if SGroup_Exists("sg_outpost_patrol2") and SGroup_IsEmpty("sg_outpost_patrol2") == false then
	
	if g_outpost2_patrol_move == 0 and Prox_AllSquadsNearMarker("sg_outpost_patrol2", "mkr_PatrolA1")  then
	
		Cmd_AttackMoveMarker("sg_outpost_patrol2", "mkr_PatrolA2")
		g_outpost2_patrol_move = g_outpost2_patrol_move +1
	
	elseif g_outpost2_patrol_move == 1 and  Prox_AllSquadsNearMarker("sg_outpost_patrol2", "mkr_PatrolA2")  then
	
		Cmd_AttackMoveMarker("sg_outpost_patrol2", "mkr_PatrolA3")
		g_outpost2_patrol_move = g_outpost2_patrol_move +1
		
	elseif g_outpost2_patrol_move == 6 and  Prox_AllSquadsNearMarker("sg_outpost_patrol2", "mkr_PatrolA7")  then
	
		Cmd_AttackMoveMarker("sg_outpost_patrol2", "mkr_PatrolA1")
		g_outpost2_patrol_move = 0

	end

else
	
	Rule_Remove(Rule_Rent_A_Cop2)

end

end

function Rule_Rent_A_Cop3()

if SGroup_Exists("sg_outpost_patrol3") and SGroup_IsEmpty("sg_outpost_patrol3") == false then
	
	if g_outpost3_patrol_move == 0 and Prox_AllSquadsNearMarker("sg_outpost_patrol3", "mkr_PatrolA1")  then
	
		Cmd_AttackMoveMarker("sg_outpost_patrol3", "mkr_PatrolA2")
		g_outpost3_patrol_move = g_outpost3_patrol_move +1
	
	elseif g_outpost3_patrol_move == 1 and  Prox_AllSquadsNearMarker("sg_outpost_patrol3", "mkr_PatrolA2")  then
	
		Cmd_AttackMoveMarker("sg_outpost_patrol3", "mkr_PatrolA3")
		g_outpost3_patrol_move = g_outpost3_patrol_move +1
		
	elseif g_outpost3_patrol_move == 6 and  Prox_AllSquadsNearMarker("sg_outpost_patrol3", "mkr_PatrolA7")  then
	
		Cmd_AttackMoveMarker("sg_outpost_patrol3", "mkr_PatrolA1")
		g_outpost3_patrol_move = 0

	end

else
	
	Rule_Remove(Rule_Rent_A_Cop3)

end

end

function Rule_Rent_A_Cop4()

if SGroup_Exists("sg_outpost_patrol4") and SGroup_IsEmpty("sg_outpost_patrol4") == false then
	
	if g_outpost4_patrol_move == 0 and Prox_AllSquadsNearMarker("sg_outpost_patrol4", "mkr_PatrolA1")  then
	
		Cmd_AttackMoveMarker("sg_outpost_patrol4", "mkr_PatrolA2")
		g_outpost4_patrol_move = g_outpost4_patrol_move +1
	
	elseif g_outpost4_patrol_move == 1 and  Prox_AllSquadsNearMarker("sg_outpost_patrol4", "mkr_PatrolA2")  then
	
		Cmd_AttackMoveMarker("sg_outpost_patrol4", "mkr_PatrolA3")
		g_outpost4_patrol_move = g_outpost4_patrol_move +1
		
	elseif g_outpost4_patrol_move == 6 and  Prox_AllSquadsNearMarker("sg_outpost_patrol4", "mkr_PatrolA7")  then
	
		Cmd_AttackMoveMarker("sg_outpost_patrol4", "mkr_PatrolA1")
		g_outpost4_patrol_move = 0

	end

else
	
	Rule_Remove(Rule_Rent_A_Cop4)

end

end

function Rule_Rent_A_Cop5()

if SGroup_Exists("sg_outpost_patrol5") and SGroup_IsEmpty("sg_outpost_patrol5") == false then
	
	if g_outpost5_patrol_move == 0 and Prox_AllSquadsNearMarker("sg_outpost_patrol5", "mkr_PatrolA1")  then
	
		Cmd_AttackMoveMarker("sg_outpost_patrol5", "mkr_PatrolA2")
		g_outpost5_patrol_move = g_outpost5_patrol_move +1
	
	elseif g_outpost5_patrol_move == 1 and  Prox_AllSquadsNearMarker("sg_outpost_patrol5", "mkr_PatrolA2")  then
	
		Cmd_AttackMoveMarker("sg_outpost_patrol5", "mkr_PatrolA3")
		g_outpost5_patrol_move = g_outpost5_patrol_move +1
		
	elseif g_outpost5_patrol_move == 6 and  Prox_AllSquadsNearMarker("sg_outpost_patrol5", "mkr_PatrolA7")  then
	
		Cmd_AttackMoveMarker("sg_outpost_patrol5", "mkr_PatrolA1")
		g_outpost5_patrol_move = 0

	end

else
	
	Rule_Remove(Rule_Rent_A_Cop5)

end

end ]]


--[[Random Attacks]]

--[[counts number of units a player has at 6 positions]] function Rule_Count_Player_Units()

for i = 1, 6 do	--number designation
	
	Player_GetAllSquadsNearMarker(g_Player1, "sg_unit_count_for_areas"..i, t_bases_of_operation.areaname[i])
	t_ork_counterattack_data.playersquadcount[i] = SGroup_Count(SGroup_FromName("sg_unit_count_for_areas"..i))
	SGroup_Clear("sg_unit_count_for_areas"..i)
	
end

end

--[[activates the counterattack]] function Rule_Counterattack_Activation()

if g_counterattack_sent == false then
	
	Rule_Check_AddInterval(Rule_Create_Ork_Counterattack_Armies, 1) -- 10 seconds for test --check_AddOneShot
	--print("create ork counterattack armies will be activated in 1 seconds")
	Rule_Check_Remove(Rule_Counterattack_Activation)
	
elseif g_counterattack_sent == true then
	
	--print("g_counterattack_sent is true")
	
	if SGroup_Exists("sg_counterattack_force") and SGroup_IsEmpty("sg_counterattack_force") then
		
		--print("enemies are dead!")
		g_counterattack_sent = false
		
	end
	
		
end

end

function Rule_Create_Ork_Counterattack_Armies() -- choose a player occupied area to attack -- called every second, in case the area where the attacks are originating from is already occupied by the player so that the game can quickly move on to the next area to send enemies from.

local l_random_ork_counterattack_source = World_GetRand(1, table.getn(t_bases_of_operation.flags))
local l_random_area_to_attack = World_GetRand(1, table.getn(t_bases_of_operation.flags)) -- check to see size of flag list

print("source: "..l_random_ork_counterattack_source)
print("destination: "..l_random_area_to_attack)


print("source owner status: "..t_bases_of_operation.capture_status[l_random_ork_counterattack_source])
print("destination owner status: "..t_bases_of_operation.capture_status[l_random_area_to_attack])

-- if the capture_status indicates that the owner is player 1 and the owner of the originating base of this attack is player2
if t_bases_of_operation.capture_status[l_random_area_to_attack] <= 1 and t_bases_of_operation.capture_status[l_random_ork_counterattack_source] >= 2 then 
	
	print("start production?")
	
	if t_bases_of_operation.flags[l_random_ork_counterattack_source] == "eg_flag1" and (EGroup_Exists("eg_construction1") and (EGroup_IsEmpty("eg_construction1") == false)) then
		
		g_build_yes = true
		g_construction_zone = "eg_construction1"
		g_vehicle_construction_zone = "eg_vehicle_construction1"
		
	elseif t_bases_of_operation.flags[l_random_ork_counterattack_source] == "eg_flag2" and (EGroup_Exists("eg_construction2") and (EGroup_IsEmpty("eg_construction2") == false)) then
		
		g_build_yes = true
		g_construction_zone = "eg_construction2"
		g_vehicle_construction_zone = "eg_vehicle_construction2"
		
	elseif t_bases_of_operation.flags[l_random_ork_counterattack_source] == "eg_flag3" and (EGroup_Exists("eg_construction3") and (EGroup_IsEmpty("eg_construction3") == false)) then
		
		g_build_yes = true
		g_construction_zone = "eg_construction3"
		g_vehicle_construction_zone = "eg_vehicle_construction3"
		
	elseif t_bases_of_operation.flags[l_random_ork_counterattack_source] == "eg_flag4" and (EGroup_Exists("eg_construction4") and (EGroup_IsEmpty("eg_construction4") == false)) then
		
		g_build_yes = true
		g_construction_zone = "eg_construction4"
		g_vehicle_construction_zone = "eg_vehicle_construction4"	
		
	elseif t_bases_of_operation.flags[l_random_ork_counterattack_source] == "eg_flag5" and (EGroup_Exists("eg_construction5") and (EGroup_IsEmpty("eg_construction5") == false)) then
		
		g_build_yes = true
		g_construction_zone = "eg_construction5"
		g_vehicle_construction_zone = "eg_vehicle_construction5"
		
	elseif t_bases_of_operation.flags[l_random_ork_counterattack_source] == "eg_flag6" and (EGroup_Exists("eg_construction6") and (EGroup_IsEmpty("eg_construction6") == false)) then
		
		g_build_yes = true
		g_construction_zone = "eg_does_not_exist"
		g_vehicle_construction_zone = "eg_vehicle_construction_does_not_exist"
		
	end
	
	--print("construction zone: "..g_construction_zone)
	
	if g_build_yes == true then 
		
		zone_count = EGroup_Count(EGroup_FromName(g_construction_zone))
		
		print("zone count = "..zone_count)
		
		print("construction buildings exist")
		
		
		local l_squadsize_index = 1
		
		
		
		local CountBuilderSquad = function( _sgroupid, _itemindex, _squadid )
			
			print(Squad_GetBlueprintName(_squadid))
			
			if Squad_GetBlueprintName(_squadid) == "chaos_squad_slave" then
				SGroup_Remove( _sgroupid, _squadid )
			elseif Squad_GetBlueprintName(_squadid) == "space_marine_squad_servitor" then
				SGroup_Remove( _sgroupid, _squadid )
			elseif Squad_GetBlueprintName(_squadid) == "eldar_squad_bonesinger" then
				SGroup_Remove( _sgroupid, _squadid )
			elseif Squad_GetBlueprintName(_squadid) == "guard_squad_enginseer" then
				SGroup_Remove( _sgroupid, _squadid )
			elseif Squad_GetBlueprintName(_squadid) == "necron_builder_scarab_squad" then
				SGroup_Remove( _sgroupid, _squadid )
			elseif Squad_GetBlueprintName(_squadid) == "tau_builder_squad" then
				SGroup_Remove( _sgroupid, _squadid )
				print("test!!!!")
			else	
				--SGroup_Remove( _sgroupid, _squadid )
			end
			
			return true
		end
		
		Player_GetAllSquadsNearMarker(g_Player1, "sg_unit_count_for_player", t_bases_of_operation.areaname[l_random_area_to_attack])
		
		SGroup_ForEachAllOrAnyEx(SGroup_FromName("sg_unit_count_for_player"), true, CountBuilderSquad, true, false )
		
		g_player_unit_count = SGroup_Count(SGroup_FromName("sg_unit_count_for_player"))
		

--[[ --Player_GetAllSquadsNearMarker(g_Player1, "sg_unit_count_for_player", t_bases_of_operation.areaname[l_random_area_to_attack])

		--g_player_unit_count = SGroup_Count("sg_unit_count_for_player")]]
		
		
		if g_player_unit_count >= 0 then -- if t_ork_counterattack_data.playersquadcount[l_random_area_to_attack] >= 0 then
			
			print("number of player units in attack area: "..g_player_unit_count)
			
			
			if (SGroup_Exists("sg_counterattack_force") == false or SGroup_IsEmpty("sg_counterattack_force")) --if (SGroup_Exists(t_ork_counterattack_data.major_names[l_random_ork_counterattack_source]) == false or SGroup_IsEmpty(t_ork_counterattack_data.major_names[l_random_ork_counterattack_source]))
				or SGroup_Exists("sg_counterattack_vehicle_force") == false or SGroup_IsEmpty("sg_counterattack_vehicle_force")	then
			--checks to see if the attacking squads exist or are empty	
			
			--if t_ork_counterattack_data.playersquadcount[l_random_area_to_attack] >= 9 and t_ork_counterattack_data.playersquadcount[l_random_area_to_attack] <= 13  then --and (g_Timer >= 600 and g_Timer <= 1199)
				if g_player_unit_count >= 7 and g_player_unit_count <= 10  and g_waves >= 3 then --and (g_Timer >= 600 and g_Timer <= 1199)
					--if the player has 5-6 squads then the game will attack with the number associated with the index inside t_tau_counterattack_data.squadsize
					print("size2")
					l_squadsize_index = 2
			
					--	elseif 	t_ork_counterattack_data.playersquadcount[l_random_area_to_attack] >= 14  then --and g_Timer >= 1200
				elseif 	g_player_unit_count >= 11  and g_waves >=3 then --and g_Timer >= 1200
					--if the player has 7-8 squads then the game will attack with the number associated with the index inside t_tau_counterattack_data.squadsize
					print("size3")
					l_squadsize_index = 3
				end
				--9 --> 12 -->13
				
				final_random_ork_counterattack_source = l_random_ork_counterattack_source
				final_random_area_to_attack = l_random_area_to_attack
				final_squadsize_index = l_squadsize_index
				
				locked_source = t_bases_of_operation.flags[final_random_ork_counterattack_source]
				locked_source2 = t_bases_of_operation.spawnspot[final_random_ork_counterattack_source]
				locked_source3 = t_bases_of_operation.vehicles[final_random_ork_counterattack_source]
				locked_attack =  t_bases_of_operation.areaname[final_random_area_to_attack]
				locked_flag =  t_bases_of_operation.flags[final_random_area_to_attack]
				
				print("l_squadsize_index = "..l_squadsize_index)
				
				if l_squadsize_index >= 2 then
					Rule_Check_AddInterval(Rule_Vehicle_Spawner, 5)
					print("test")
				end
				
				Rule_Check_AddInterval(Rule_Counterattack_Spawner, 10)
				
				
				Rule_AddIntervalDelay(Rule_Counterattack_Activation, 1, 180) --120 --150
				
				--Rule_Check_AddInterval(Rule_Counterattack_Idle_Fixing, 1)
				
				Rule_Remove(Rule_Create_Ork_Counterattack_Armies)
				
				
				g_build_yes = false
				
				--print("counterattack activation enabled at interval of 1 second")
				
				--Rule_Check_AddInterval(Rule_Counterattack_Proximity, 10)
				
			end
			
		end
	--elseif EGroup_Exists(t_bases_of_operation.constructionbuildings[l_random_ork_counterattack_source]) and (EGroup_IsEmpty(t_bases_of_operation.constructionbuildings[l_random_ork_counterattack_source]) == true) then 	
	elseif g_build_yes == false then 
		
		print("construction building does not exist")
		
	end	
	
--elseif t_bases_of_operation.capture_status[l_random_ork_counterattack_source] == 2 then 

end

end

function Rule_Ownership_Check()

for i = 1, table.getn(t_bases_of_operation.flags) do
	
	--print("inside ownership function")
	
	if EGroup_Exists(t_bases_of_operation.flags[i]) then
			
			--print("flag exists")
			
			if EGroup_IsCapturedByPlayer(t_bases_of_operation.flags[i] , g_Player1, false ) then
				
				--print("flag captured")
				t_bases_of_operation.capture_status[i] = 1
				
				
				if t_bases_of_operation.areacapturedbyplayer[i] == false then
					
					t_bases_of_operation.areacapturedbyplayer[i] = true
					
					g_bases_captured = g_bases_captured + 1
					
				end
				
				
				
				
			elseif EGroup_IsCapturedByPlayer(t_bases_of_operation.flags[i] , g_Player2, false ) then
				
				t_bases_of_operation.capture_status[i] = 2
				
				if t_bases_of_operation.areacapturedbyplayer[i] == true then
					
					t_bases_of_operation.areacapturedbyplayer[i] = false
					
					
					if g_bases_captured >= 1 then 
					
						g_bases_captured = g_bases_captured - 1
					
					elseif g_bases_captured <= 0 then
					
						g_bases_captured = 0
					
					end
					
				end
				
				
				
				
			elseif EGroup_IsCapturedByPlayer(t_bases_of_operation.flags[i] , g_Player3, false ) then
				
				t_bases_of_operation.capture_status[i] = 3
				
				
				if t_bases_of_operation.areacapturedbyplayer[i] == true then
					
					t_bases_of_operation.areacapturedbyplayer[i] = false
					
					
					if g_bases_captured >= 1 then 
					
						g_bases_captured = g_bases_captured - 1
					
					elseif g_bases_captured <= 0 then
					
						g_bases_captured = 0
					
					end
					
				end
				
			elseif EGroup_IsCapturedByPlayer(t_bases_of_operation.flags[i] , g_Player4, false ) then
				
				t_bases_of_operation.capture_status[i] = 4
				
				
				if t_bases_of_operation.areacapturedbyplayer[i] == true then
					
					t_bases_of_operation.areacapturedbyplayer[i] = false
					
					
					if g_bases_captured >= 1 then 
					
						g_bases_captured = g_bases_captured - 1
					
					elseif g_bases_captured <= 0 then
					
						g_bases_captured = 0
					
					end
					
				end
				
			elseif EGroup_IsCapturedByPlayer(t_bases_of_operation.flags[i] , g_Player5, false ) then
				
				t_bases_of_operation.capture_status[i] = 5
				
				if t_bases_of_operation.areacapturedbyplayer[i] == true then
					
					t_bases_of_operation.areacapturedbyplayer[i] = false
					
					
					if g_bases_captured >= 1 then 
					
						g_bases_captured = g_bases_captured - 1
					
					elseif g_bases_captured <= 0 then
					
						g_bases_captured = 0
					
					end
					
				end
				
			elseif EGroup_IsCapturedByPlayer(t_bases_of_operation.flags[i] , g_Player6, false ) then
				
				t_bases_of_operation.capture_status[i] = 6
				
				if t_bases_of_operation.areacapturedbyplayer[i] == true then
					
					t_bases_of_operation.areacapturedbyplayer[i] = false
					
					
					if g_bases_captured >= 1 then 
					
						g_bases_captured = g_bases_captured - 1
					
					elseif g_bases_captured <= 0 then
					
						g_bases_captured = 0
					
					end
					
				end
				
			elseif EGroup_IsCapturedByPlayer(t_bases_of_operation.flags[i] , g_Player7, false ) then
				
				t_bases_of_operation.capture_status[i] = 7
				
				if t_bases_of_operation.areacapturedbyplayer[i] == true then
					
					t_bases_of_operation.areacapturedbyplayer[i] = false
					
					
					if g_bases_captured >= 1 then 
					
						g_bases_captured = g_bases_captured - 1
					
					elseif g_bases_captured <= 0 then
					
						g_bases_captured = 0
					
					end
					
				end
				
			elseif EGroup_IsCapturedByPlayer(t_bases_of_operation.flags[i] , g_Player8, false ) then
				
				t_bases_of_operation.capture_status[i] = 8
				
				if t_bases_of_operation.areacapturedbyplayer[i] == true then
					
					t_bases_of_operation.areacapturedbyplayer[i] = false
					
					
					if g_bases_captured >= 1 then 
					
						g_bases_captured = g_bases_captured - 1
					
					elseif g_bases_captured <= 0 then
					
						g_bases_captured = 0
					
					end
					
				end
				
			end
	end
	
end

end

function Rule_Counterattack_Spawner() -- rand1 to be used with the blue print table local rand1 = World_GetRand(1, table.getn(g_counterattack_unit_composition))

-- rand2 is to be used for the squad sizes
local rand2 = World_GetRand(6, g_large_deployment_size)



if EGroup_IsCapturedByPlayer(locked_source, g_Player2, false) then


	if EGroup_Exists(g_construction_zone) and EGroup_IsEmpty(g_construction_zone) == false then
		
		
		print(g_counterattack_unit_composition[rand1])
		print("random1 = "..rand1)
		
		Util_CreateSquadsAtMarkerEx(g_Player2, ("sg_counterattack_group"..g_deployed_count), g_counterattack_unit_composition[rand1], 
			locked_source2, 1, rand2) 
		
		
		--print("marker source: "..t_gorgutz_captured_major_names[final_random_ork_counterattack_source])
		print("marker source: "..locked_source2)
		
		SGroup_AddLeaders("sg_counterattack_group"..g_deployed_count)
		--SGroup_AddLeaders(t_ork_counterattack_data.major_names[final_random_area_to_attack])
		
		SGroup_CreateIfNotFound("sg_counterattack_force")
		SGroup_AddGroup(SGroup_FromName("sg_counterattack_force"), SGroup_FromName("sg_counterattack_group"..g_deployed_count))
		--SGroup_AddGroup(SGroup_FromName("sg_counterattack_force"), SGroup_FromName(t_ork_counterattack_data.major_names[final_random_area_to_attack]))
		
		g_deployed_count = g_deployed_count + 1
		
		
		if g_deployed_count == t_ork_counterattack_data.squadsize[final_random_area_to_attack][final_squadsize_index] then
			
			
			if g_waves >= 4 then --  chance of adding a stealth detector after wave 5
				
				l_random_stealth_detect = World_GetRand(1, 2)
				
				if l_random_stealth_detect == 1 then
					
					Util_CreateSquadsAtMarkerEx(g_Player2, "sg_counterattack_mek_boy", "ork_squad_mek_boy", locked_source2, 1, 1)  -- regularm mek boy to boost anti-stealth capabilities
					SGroup_AddGroup(SGroup_FromName("sg_counterattack_force"), SGroup_FromName("sg_counterattack_mek_boy"))
					
				end
				
				if l_random_stealth_detect == 2 then
					
					Util_CreateSquadsAtMarkerEx(g_Player2, "sg_counterattack_armored_nob", "ork_squad_armored_nob", locked_source2, 1, 1)  -- regularm mek boy to boost anti-stealth capabilities
					SGroup_AddGroup(SGroup_FromName("sg_counterattack_force"), SGroup_FromName("sg_counterattack_armored_nob"))
					
				end
				
				
			end
			
			--[[
			----******** Adds enemy AI blueprint units to attack after a certain wave
			
			if g_waves >= 5 and g_cpu_group_sent == false then 
			
				for f = 1, g_blueprint_bonus_population do
					
					if SGroup_Exists("sg_cpu_bonus"..f) and (SGroup_IsEmpty("sg_cpu_bonus"..f) == false) then
						
						SGroup_AddGroup(SGroup_FromName("sg_counterattack_force"), SGroup_FromName("sg_cpu_bonus"..f))
						
						g_cpu_group_sent = true
						
					end	
					
				end				
				
			end]]
			
			Cmd_AttackMoveMarker("sg_counterattack_force", locked_attack)-- t_bases_of_operation.areaname --t_player_captured_major_names[final_random_area_to_attack]
			
			g_counterattack_sent = true
			
			g_deployed_count = 0
			
			Rule_Check_AddInterval(Rule_Random_Speech_Activation, 2)
			
			if g_waves <= 5 then -- stops count of waves once it reaches a number greater than 3 (i.e. 4)
				g_waves = g_waves + 1
			end
			
			Rule_Check_AddInterval(Rule_Counterattack_Idle_Fixing, 10)
			
			Rule_Remove(Rule_Counterattack_Spawner)
			
		end
		
	end
		
	g_target = locked_attack-- t_bases_of_operation.areaname[final_random_area_to_attack]
	g_target_flag = locked_flag --t_bases_of_operation.flags[final_random_area_to_attack]
	
elseif EGroup_IsCapturedByPlayer(locked_source, g_Player2, false) == false then

	Rule_Remove(Rule_Counterattack_Spawner)

end

end

function Rule_Vehicle_Spawner() print("vehicle spawner called")

if EGroup_IsCapturedByPlayer(locked_source, g_Player2, false) then
	
	print("egroup owned by Gorgutz")
	
	if EGroup_Exists(g_vehicle_construction_zone) and (EGroup_IsEmpty(g_vehicle_construction_zone) == false) then
		
		print(g_vehicle_construction_zone.." exists!")
		
		print(final_squadsize_index.." is the final squadsize index")
		
		if final_squadsize_index == 2 then
			
			print("vehicle squadsize index 2")
			
			if g_time_elapsed >= 400 then
				
				print("size 2 time => 400")
				
				Rule_AddInterval(Rule_Spawn_Vehicle_Composition1, 5)
				
				Rule_Remove(Rule_Vehicle_Spawner)
				
			elseif g_time_elapsed <= 399 then
				
				print("size 2 time < 400")
				
				Rule_AddInterval(Rule_Spawn_Vehicle_Composition2, 5)
				
				Rule_Remove(Rule_Vehicle_Spawner)
				
			end
			
		elseif final_squadsize_index == 3 then
			
			print("vehicle squadsize index 3")
			
			if g_time_elapsed >= 1800 then
				
				print("size 3 time > 1800")
				
				Rule_AddInterval(Rule_Spawn_Vehicle_Composition3, 5)
				
				Rule_Remove(Rule_Vehicle_Spawner)
				
			elseif g_time_elapsed <= 1799 then
				
				print("size 3 time < 1800")
				
				Rule_AddInterval(Rule_Spawn_Vehicle_Composition4, 5)
				
				Rule_Remove(Rule_Vehicle_Spawner)
				
			end
			
		end
		
	end
	
elseif EGroup_IsCapturedByPlayer(locked_source, g_Player2, false) == false then	

	Rule_Remove(Rule_Vehicle_Spawner)
	
	print("rule removed - egroup not captured by cpu")

end
	

end

function Rule_Spawn_Vehicle_Composition1()

if EGroup_IsCapturedByPlayer(locked_source, g_Player2, false) then
	
	
	t_vehicle_composition1_table ={
	name = {"sg_counter_vehicle1", "sg_counter_vehicle2" --[[, "sg_counter_vehicle3"]]},
	vehicle_type = {"ork_squad_wartrak", "ork_squad_killa_kan"--[[, "ork_squad_wartrak"]]} }
	
	local i = g_spawn_vehicle_composition1_iter
	
	print("inside vehicle comp 1")
	
	--if EGroup_Exists("eg_vehicle_construction"..final_random_ork_counterattack_source) == true and EGroup_IsEmpty("eg_vehicle_construction"..final_random_ork_counterattack_source) == false then 
	if EGroup_Exists(g_vehicle_construction_zone) == true and (EGroup_IsEmpty(g_vehicle_construction_zone) == false) then 	
		
		Util_CreateSquadsAtMarkerEx(g_Player2, t_vehicle_composition1_table.name[i], t_vehicle_composition1_table.vehicle_type[i], 
			locked_source3, 1, 1) -- locked source 2
		SGroup_CreateIfNotFound("sg_counterattack_vehicle_force")
		SGroup_AddGroup(SGroup_FromName("sg_counterattack_vehicle_force"), SGroup_FromName(t_vehicle_composition1_table.name[i]))
		
		print("spawned vehicles 1")
		
	end
	
	g_spawn_vehicle_composition1_iter = g_spawn_vehicle_composition1_iter + 1
	
	if g_spawn_vehicle_composition1_iter >= 3 then
	
		if SGroup_Exists("sg_counterattack_vehicle_force") and (SGroup_IsEmpty("sg_counterattack_vehicle_force") == false) then
			
			--Cmd_AttackMoveMarker("sg_counterattack_vehicle_force", t_bases_of_operation.areaname[final_random_area_to_attack])
			Cmd_AttackMoveMarker("sg_counterattack_vehicle_force", locked_attack)
			print("spawned vehicles sent")
			
		end
		
		Rule_Remove(Rule_Spawn_Vehicle_Composition1)
		
		g_spawn_vehicle_composition1_iter = 1
		
	end
	
elseif EGroup_IsCapturedByPlayer(locked_source, g_Player2, false) == false then
	
	Rule_Remove(Rule_Spawn_Vehicle_Composition1)
	
	print("onoz can't spawn!")
	
end

end

function Rule_Spawn_Vehicle_Composition2()

if EGroup_IsCapturedByPlayer(locked_source, g_Player2, false) then	

	t_vehicle_composition2_table ={
	name = {"sg_counter_vehicle1", "sg_counter_vehicle2"},
	vehicle_type = {"ork_squad_wartrak", "ork_squad_trukk"} }
	
	local i = g_spawn_vehicle_composition2_iter
	
	print("inside vehicle comp 2")
	
	if EGroup_Exists(g_vehicle_construction_zone) == true and (EGroup_IsEmpty(g_vehicle_construction_zone) == false) then 	
		
		Util_CreateSquadsAtMarkerEx(g_Player2, t_vehicle_composition2_table.name[i], t_vehicle_composition2_table.vehicle_type[i], 
			locked_source3, 1, 1) --locked_source2
		SGroup_CreateIfNotFound("sg_counterattack_vehicle_force")
		SGroup_AddGroup(SGroup_FromName("sg_counterattack_vehicle_force"), SGroup_FromName(t_vehicle_composition2_table.name[i]))
		
		print("spawned vehicles 2")
		
	end
	
	g_spawn_vehicle_composition2_iter = g_spawn_vehicle_composition2_iter + 1
	
	if g_spawn_vehicle_composition2_iter >= 3 then
	
		if SGroup_Exists("sg_counterattack_vehicle_force") and (SGroup_IsEmpty("sg_counterattack_vehicle_force") == false) then
			
			--Cmd_AttackMoveMarker("sg_counterattack_vehicle_force", t_bases_of_operation.areaname[final_random_area_to_attack])
			Cmd_AttackMoveMarker("sg_counterattack_vehicle_force", locked_attack)
			
			print("spawned vehicles sent")
			
		end
		
		Rule_Remove(Rule_Spawn_Vehicle_Composition2)
		
		g_spawn_vehicle_composition2_iter = 1
		
	end
	
elseif EGroup_IsCapturedByPlayer(locked_source, g_Player2, false) == false then
	
	Rule_Remove(Rule_Spawn_Vehicle_Composition2)
	
	print("onoz can't spawn!")
	
end

end

function Rule_Spawn_Vehicle_Composition3()

if EGroup_IsCapturedByPlayer(locked_source, g_Player2, false) then
	
	t_vehicle_composition3_table ={
	name = {"sg_counter_vehicle1", "sg_counter_vehicle2", "sg_counter_vehicle3"},
	vehicle_type = {"ork_squad_wartrak", "ork_squad_looted_tank", "ork_squad_killa_kan"} }
	
	local i = g_spawn_vehicle_composition3_iter
	
	print("inside vehicle comp 3")
	
	if EGroup_Exists(g_vehicle_construction_zone) == true and (EGroup_IsEmpty(g_vehicle_construction_zone) == false) then 	
		
		Util_CreateSquadsAtMarkerEx(g_Player2, t_vehicle_composition3_table.name[i], t_vehicle_composition3_table.vehicle_type[i], 
			locked_source3, 1, 1) --t_gorgutz_captured_major_names[final_random_ork_counterattack_source] -- locked_source2
		
		SGroup_CreateIfNotFound("sg_counterattack_vehicle_force")
		SGroup_AddGroup(SGroup_FromName("sg_counterattack_vehicle_force"), SGroup_FromName(t_vehicle_composition3_table.name[i]))
		
		print("spawned vehicles 3")
		
	end
	
	g_spawn_vehicle_composition3_iter = g_spawn_vehicle_composition3_iter + 1
	
	if g_spawn_vehicle_composition3_iter >= 4 then
		
		if SGroup_Exists("sg_counterattack_vehicle_force") and (SGroup_IsEmpty("sg_counterattack_vehicle_force") == false) then
			
			--Cmd_AttackMoveMarker("sg_counterattack_vehicle_force", t_bases_of_operation.areaname[final_random_area_to_attack])
			Cmd_AttackMoveMarker("sg_counterattack_vehicle_force", locked_attack)
			
			print("spawned vehicles sent")
			
		end
		
		Rule_Remove(Rule_Spawn_Vehicle_Composition3)
		
		g_spawn_vehicle_composition3_iter = 1
		
	end
	
elseif EGroup_IsCapturedByPlayer(locked_source, g_Player2, false) == false then
	
	Rule_Remove(Rule_Spawn_Vehicle_Composition3)
	
	print("onoz can't spawn!")
	
end

end

function Rule_Spawn_Vehicle_Composition4()

if EGroup_IsCapturedByPlayer(locked_source, g_Player2, false) then
	
	t_vehicle_composition4_table ={
	name = {"sg_counter_vehicle1", "sg_counter_vehicle2"},
	vehicle_type = {"ork_squad_wartrak", "ork_squad_killa_kan"} }
	
	local i = g_spawn_vehicle_composition4_iter
	
	print("inside vehicle comp 4")
	
	if EGroup_Exists(g_vehicle_construction_zone) == true and (EGroup_IsEmpty(g_vehicle_construction_zone) == false) then 	
		
		Util_CreateSquadsAtMarkerEx(g_Player2, t_vehicle_composition4_table.name[i], t_vehicle_composition4_table.vehicle_type[i], 
			locked_source3, 1, 1) --locked_source2
		--[[
		Util_CreateSquadsAtMarkerEx(g_Player2, t_vehicle_composition4_table.name[i], t_vehicle_composition4_table.vehicle_type[i], 
			t_gorgutz_captured_major_names[final_random_ork_counterattack_source], 1, 1)]]
		
		
		SGroup_CreateIfNotFound("sg_counterattack_vehicle_force")
		SGroup_AddGroup(SGroup_FromName("sg_counterattack_vehicle_force"), SGroup_FromName(t_vehicle_composition4_table.name[i]))
		
		print("spawned vehicles 4")
		
	end
	
	g_spawn_vehicle_composition4_iter = g_spawn_vehicle_composition4_iter + 1
	
	if g_spawn_vehicle_composition4_iter >= 3 then
	
		if SGroup_Exists("sg_counterattack_vehicle_force") and (SGroup_IsEmpty("sg_counterattack_vehicle_force") == false) then
			
			--Cmd_AttackMoveMarker("sg_counterattack_vehicle_force", t_bases_of_operation.areaname[final_random_area_to_attack])
			Cmd_AttackMoveMarker("sg_counterattack_vehicle_force", locked_attack)
			
			print("spawned vehicles sent")
			
		end
		
		Rule_Remove(Rule_Spawn_Vehicle_Composition4)
		
		g_spawn_vehicle_composition4_iter = 1
		
	end
	
elseif EGroup_IsCapturedByPlayer(locked_source, g_Player2, false) == false then
	
	Rule_Remove(Rule_Spawn_Vehicle_Composition4)
	
	print("onoz can't spawn!")
	
end

end

function Rule_Counterattack_Idle_Fixing() -- makes sure that the counterattack units are not idle

print("counterattack on")

if SGroup_Exists("sg_counterattack_force") and (SGroup_IsEmpty("sg_counterattack_force") == false) and 
SGroup_CheckActiveCommand("sg_counterattack_force", SQUADSTATEID_Idle, true) then
	
	
	print("counter attack force exists and not empty, and is idle")
	
	--if these units are idle, and near the marker, then a check will be made to see if the flag they're around is captured by the player or not.
	if Prox_AllSquadsNearMarker("sg_counterattack_force", g_target) then
		
		print("counterattack close")
		
		if EGroup_IsCapturedByPlayer(g_target_flag, g_Player1, false) == true or Entity_GetWorldOwner(EGroup_GetSpawnedEntityAt(g_target_flag, 1)) == true then
			
			Cmd_Capture("sg_counterattack_force", g_target_flag)
			print("capture command added")
			
			if SGroup_Exists("sg_counterattack_vehicle_force") and SGroup_IsEmpty("sg_counterattack_vehicle_force") == false then
				
				--if SGroup_CheckActiveCommand("sg_counterattack_vehicle_force", SQUADSTATEID_Idle, false) then
					--if the vehicle unit in question is idle, then the game will force it to attack towards the specified attack point
					
					Cmd_AttackMoveMarker("sg_counterattack_vehicle_force", g_target)
					print("idleness fixed for vehicles first loop")
					
				--end
				
			end
			
		elseif EGroup_IsCapturedByPlayer(g_target_flag, g_Player2, false) == true then
			
			print("flag already captured by gorgutz")
			
			--if the flag is captured already, then they'll attack a random area, which is stored so that a check can be made again (as previously done in this function)
			
			l_random_area_to_attack = World_GetRand(1, table.getn(t_bases_of_operation.areaname))
			
			--print("random area to attack is: "..l_random_area_to_attack)
			
			if t_bases_of_operation.capture_status[l_random_area_to_attack] == 1 then -- if the selected area is captured by player 1
				
				Cmd_AttackMoveMarker("sg_counterattack_force", t_bases_of_operation.areaname[l_random_area_to_attack])
				
				g_target = t_bases_of_operation.areaname[l_random_area_to_attack]
				
				g_target_flag = t_bases_of_operation.flags[l_random_area_to_attack]
				
				
				if SGroup_Exists("sg_counterattack_vehicle_force") and SGroup_IsEmpty("sg_counterattack_vehicle_force") == false then
					
					Cmd_AttackMoveMarker("sg_counterattack_vehicle_force", g_target)
					print("vehicles redirected area captured by player, going to new area")
					
				end
				
			end
			
		end
		
	elseif Prox_AllSquadsNearMarker("sg_counterattack_force", g_target) == false then
		
		print("far from target")
		
		if EGroup_IsCapturedByPlayer(g_target_flag, g_Player1, false) == true or Entity_GetWorldOwner(EGroup_GetSpawnedEntityAt(g_target_flag, 1)) == true then
			
			print("counterattack force not close to flag, re-issueing capture")
			print("target flag: "..g_target_flag)
			Cmd_Capture("sg_counterattack_force", g_target_flag)
			
			if SGroup_Exists("sg_counterattack_vehicle_force") and SGroup_IsEmpty("sg_counterattack_vehicle_force") == false then
				
				Cmd_AttackMoveMarker("sg_counterattack_vehicle_force", g_target)
				print("vehicles redirected")
				
			end
			
		elseif EGroup_IsCapturedByPlayer(g_target_flag, g_Player2, false) == true then
			
			--if the flag is captured already, then they'll attack a random area, which is stored so that a check can be made again (as previously done in this function)
			
			l_random_area_to_attack = World_GetRand(1, table.getn(t_bases_of_operation.areaname))
			
			--print("random area to attack is: "..l_random_area_to_attack)
			
			if t_bases_of_operation.capture_status[l_random_area_to_attack] == 1 then
				
				Cmd_AttackMoveMarker("sg_counterattack_force", t_bases_of_operation.areaname[l_random_area_to_attack])
				
					
				
				g_target = t_bases_of_operation.areaname[l_random_area_to_attack]
				
				g_target_flag = t_bases_of_operation.flags[l_random_area_to_attack]
				
				
				if SGroup_Exists("sg_counterattack_vehicle_force") and SGroup_IsEmpty("sg_counterattack_vehicle_force") == false then
					
					Cmd_AttackMoveMarker("sg_counterattack_vehicle_force", g_target)
					print("vehicles redirected area captured by player, going to new area")
					
				end
				
				
				
			end
			
		end
		
		
		
	end
	
elseif SGroup_Exists("sg_counterattack_force") == false or (SGroup_IsEmpty("sg_counterattack_force") == true) then
	
	print("sg_counterattack doesn't exist, moving vehicles if they exist")
	
	if SGroup_Exists("sg_counterattack_vehicle_force") and SGroup_IsEmpty("sg_counterattack_vehicle_force") == false 
		and SGroup_CheckActiveCommand("sg_counterattack_vehicle_force", SQUADSTATEID_Idle, true) then
		
		Cmd_AttackMoveMarker("sg_counterattack_vehicle_force", g_target)
		print("vehicles redirected, other units dead")
		
		--Rule_Remove(Rule_Counterattack_Idle_Fixing)
		
	elseif SGroup_Exists("sg_counterattack_vehicle_force") == false or SGroup_IsEmpty("sg_counterattack_vehicle_force") == true then
		
		Rule_Remove(Rule_Counterattack_Idle_Fixing)
		
	end
	
end

end

-- after 15 minutes, the computer will start using composition2. after 30 minutes, the computer will start using composition 3. Also, the number of attacking units increase by 1 function Rule_Composition_Changer()

if g_Timer >= 900 and g_Timer <= 1799 then
	
	g_counterattack_unit_composition = t_ork_counterattack_data.composition2
	
	
	Rule_AddOneShot(Rule_IE_Counterattack_Escalation1, 1)
	
elseif g_Timer >= 1800 then
	
	g_counterattack_unit_composition = t_ork_counterattack_data.composition3
	
	
	--the following increases the number of sgroups sent for the counterattacks by 1
	for i = 1, table.getn(t_ork_counterattack_data.squadsize) do
		
		--counterattacks
		for z = 1, 3 do
			t_ork_counterattack_data.squadsize[i][z] = t_ork_counterattack_data.squadsize[i][z] + 1
		end
		
		
	end
	
	Rule_AddOneShot(Rule_IE_Counterattack_Escalation2, 1)
	
	Rule_Remove(Rule_Composition_Changer)
	
end

end

function Rule_Citadel_Threshold() -- activates the attacks from the central, main base after 2 bases are captured/destroyed

--test --g_bases_captured = 3

if g_bases_captured >= 4 then 
	
	--Rule_AddOneShot(Rule_IE_Citadel_Attacks, 0)
	
	Rule_AddIntervalDelay(Rule_Citadel_Counterattack_Activation, 10, 21)	
	
	Rule_Remove(Rule_Citadel_Threshold)

end

end

-- same operation principle as the main counterattack activation function function Rule_Citadel_Counterattack_Activation()

if g_citadel_counterattack_sent == false and g_citadel_delay_counter_flag == true then
	
	
	g_citadel_delay_counter_flag = false
	
	Rule_Check_AddInterval(Rule_Create_Citadel_Raiders, 1) 
	--print("create tau citadel counterattack armies will be activated in 1 seconds")
	
	Rule_Check_Remove(Rule_Citadel_Counterattack_Activation)
	
elseif g_citadel_counterattack_sent == true then
	
	--print("g_citadel_counterattack_sent is true")
	
	if SGroup_Exists("sg_citadel_raiders") and SGroup_IsEmpty("sg_citadel_raiders") then
		
		--print("enemies are dead!")
		g_citadel_counterattack_sent = false
		
		Rule_Check_AddInterval(Rule_Citadel_Delay_Counter,1)
		
	end
	
end

end

function Rule_Citadel_Delay_Counter()

if g_citadel_delay_counter <= 179 then
	g_citadel_delay_counter = g_citadel_delay_counter + 1
	
elseif g_citadel_delay_counter >=180 then
	
	g_citadel_delay_counter = 0
	
	g_citadel_delay_counter_flag = true
	
	Rule_Remove(Rule_Citadel_Delay_Counter)
	
end

end

-- makes sure that the counterattack units are not idle function Rule_Citadel_Counterattack_Idle_Fixing()

if SGroup_Exists("sg_citadel_raiders") and (SGroup_IsEmpty("sg_citadel_raiders") == false) and 
SGroup_CheckActiveCommand("sg_citadel_raiders", SQUADSTATEID_Idle, true) then
	
	--if these units are idle, and near the marker, then a check will be made to see if the flag they're around is captured by the player or not.
	if Prox_AllSquadsNearMarker("sg_citadel_raiders", g_target2) then
		
		if EGroup_IsCapturedByPlayer(g_target2_flag, g_Player1, false) == true or Entity_GetWorldOwner(EGroup_GetSpawnedEntityAt(g_target2_flag, 1)) == true then -- EGroup_GetSpawnedEntityAt(g_target2_flag, 1) used to be g_target_flag?
			
			Cmd_Capture("sg_citadel_raiders", g_target2_flag)
			
		elseif EGroup_IsCapturedByPlayer(g_target2_flag, g_Player2, false) == true then
			--if the flag is captured already, then they'll attack a random area, which is stored so that a check can be made again (as previously done in this function)
			
			local l_random_area_to_attack = World_GetRand(1, 7)
			
			--print("random area to attack is: "..l_random_area_to_attack)
			
			if t_bases_of_operation.capture_status[l_random_area_to_attack] == 1 then
				
				Cmd_AttackMoveMarker("sg_citadel_raiders", t_bases_of_operation.areaname[l_random_area_to_attack])
				
				g_target2 = t_bases_of_operation.areaname[l_random_area_to_attack]
				
				g_target2_flag = t_bases_of_operation.flags[l_random_area_to_attack]
				
			end
			
		end
		
	elseif Prox_AllSquadsNearMarker("sg_citadel_raiders", g_target2) == false then
		
		Cmd_Capture("sg_citadel_raiders", g_target2_flag) -- g_target1? sg_counterattack_force?
		
		
		if EGroup_IsCapturedByPlayer(g_target2_flag, g_Player2, false) == true then
				--if the flag is captured already, then they'll attack a random area, which is stored so that a check can be made again (as previously done in this function)
				
				l_random_area_to_attack = World_GetRand(1, table.getn(t_bases_of_operation.areaname))
				
				--print("random area to attack is: "..l_random_area_to_attack)
				
				if t_bases_of_operation.capture_status[l_random_area_to_attack] == 1 then
					
					Cmd_AttackMoveMarker("sg_counterattack_force", t_bases_of_operation.areaname[l_random_area_to_attack])
					
						
					
					g_target2 = t_bases_of_operation.areaname[l_random_area_to_attack]
					
					g_target2_flag = t_bases_of_operation.flags[l_random_area_to_attack]
					
					
					if SGroup_Exists("sg_counterattack_vehicle_force") and SGroup_IsEmpty("sg_counterattack_vehicle_force") == false then
						
						Cmd_AttackMoveMarker("sg_counterattack_vehicle_force", g_target2)
						print("vehicles redirected area captured by player, going to new area")
						
					end
					
				end
				
		end
		
		
		
	end
	
elseif SGroup_Exists("sg_citadel_raiders") and (SGroup_IsEmpty("sg_citadel_raiders") == true) then
	
	Rule_Remove(Rule_Citadel_Counterattack_Idle_Fixing)
	
end

end

-- this function is for the actual production of the raiders originating from the Citadel function Rule_Create_Citadel_Raiders()

--if g_citadel_last_stand == false then
	
	if SGroup_Exists("sg_citadel_raiders") == false or SGroup_IsEmpty("sg_citadel_raiders") then
	
		local l_random_area_to_attack = World_GetRand(1, table.getn(t_bases_of_operation.flags))
		
		if EGroup_IsCapturedByPlayer(t_bases_of_operation.flags[l_random_area_to_attack] , g_Player2, false ) == false then --t_bases_of_operation.areacapturedbyplayer[l_random_area_to_attack]
			
			--if g_citadel_last_stand == false then -- when the relic gets taken over
			
				-- depending on the number of bases captured, there will be different numbers of units sent out from the citadel in response.
				if g_bases_captured >= 4 and g_bases_captured <= 5 then
					
					local l_random_number_of_squads = World_GetRand(1, 1)	
					g_citadel_random_squads = l_random_number_of_squads
					
				elseif g_bases_captured >= 6 and g_bases_captured <= 7 then
					
					local l_random_number_of_squads = World_GetRand(2, 2)	
					g_citadel_random_squads = l_random_number_of_squads
					
				end
				
--			elseif g_citadel_last_stand == true then -- when the shrines are gone
				--[[	
				local l_random_number_of_squads = World_GetRand(5, 6)	
				g_citadel_random_squads = l_random_number_of_squads
					
			end]]
			
			
			
			for n = 1, g_citadel_random_squads do		
				
				if EGroup_Exists("eg_citadel_construction") and (EGroup_IsEmpty("eg_citadel_construction") == false) then 
					
					-- rand1 to be used with the blue print table
					local rand1 = World_GetRand(1, table.getn(t_ork_counterattack_data.citadel_composition)) --t_tau_counterattack_data.composition
					-- rand2 is to be used for the squad sizes
					local rand2 = World_GetRand(8, 15)
					
					Util_CreateSquadsAtMarkerEx(g_Player2, "sg_citadel_raider"..n, t_ork_counterattack_data.citadel_composition[rand1], 
						"mkr_citadel_raider_spawn", 1, rand2)
					SGroup_AddLeaders("sg_citadel_raider"..n)
					SGroup_CreateIfNotFound("sg_citadel_raiders")
					SGroup_AddGroup(SGroup_FromName("sg_citadel_raiders"), SGroup_FromName("sg_citadel_raider"..n))
					
					Cmd_AttackMoveMarker("sg_citadel_raider"..n, t_bases_of_operation.areaname[l_random_area_to_attack])
					
					--print("citadel squads constructed!")
					
				end
				
			end
			
			g_citadel_counterattack_sent = true
			
			g_target2 = t_bases_of_operation.areaname[l_random_area_to_attack]
			
			g_target2_flag = t_bases_of_operation.flags[l_random_area_to_attack]
			
			
			Rule_AddIntervalDelay(Rule_Citadel_Counterattack_Activation, 1, (230 - g_adjusted_frequency)) -- 120
			
			Rule_Check_AddInterval(Rule_Citadel_Counterattack_Idle_Fixing, 1)
			
			Rule_Remove(Rule_Create_Citadel_Raiders)
			
		end
		
		
		if EGroup_Exists("eg_citadel_construction") and EGroup_IsEmpty("eg_citadel_construction") then
			Rule_Remove(Rule_Create_Citadel_Raiders) -- removes the citadel creation function from memory if there are no more construction buildings for it
		end
		
	end	
	
--elseif g_citadel_last_stand == true then
	
	
--end

end

function Rule_Outpost_Raiders()

if SGroup_Exists("sg_outpost_raiders") == false or SGroup_IsEmpty("sg_outpost_raiders") == true then

	--g_outpost_raider_origin = World_GetRand(1, NUMBER HERE)
	g_outpost_raider_destination = World_GetRand(1, table.getn(t_bases_of_operation.minor_flags))
	
	g_area_to_capture = t_bases_of_operation.minor_flags[g_outpost_raider_destination]
	
	if EGroup_Exists(g_area_to_capture  ) then 

		
		if EGroup_IsCapturedByPlayer(g_area_to_capture, g_Player2, false) == false then
			
			if EGroup_Exists("eg_citadel_construction") and EGroup_IsEmpty("eg_citadel_construction") == false then
				
				Rule_Check_AddOneShot(Rule_Outpost_Raiders_Spawn, 2)
				
				Rule_Remove(Rule_Outpost_Raiders)
				
				
				
			end
			
			
		end
	end

end

end

function Rule_Outpost_Raiders_Spawn()

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

	t_raider_composition = {"ork_squad_shoota_boy", "ork_squad_slugga", "ork_squad_stormboy"}
	
	local l_random_raider_type = World_GetRand(1, table.getn(t_raider_composition))

	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_outpost_raiders", t_raider_composition[l_random_raider_type], "mkr_citadel_raider_spawn", 1, g_clan_deployment_size) --8
	--Util_CreateSquadsAtMarkerEx(g_Player2, "sg_outpost_raiders_escort", t_raider_composition[l_random_raider_type], "mkr_citadel_raider_spawn", 1, 8)

	Cmd_Capture("sg_outpost_raiders", g_area_to_capture )
	--Cmd_MoveToEGroup("sg_outpost_raiders_escort", g_area_to_capture)
	
	Rule_Remove(Rule_Outpost_Raiders_Spawn)
	--Rule_AddIntervalDelay(Rule_Outpost_Raiders, 10, 120)
	Rule_AddIntervalDelay(Rule_Outpost_Raiders_Idle, 10, 10)

elseif EGroup_Exists("eg_citadel_construction") and EGroup_IsEmpty("eg_citadel_construction") == true then

	Rule_Remove(Rule_Outpost_Raiders_Spawn)
	
end

end

function Rule_Outpost_Raiders_Idle()

if SGroup_Exists("sg_outpost_raiders") and (SGroup_IsEmpty("sg_outpost_raiders") == false) then
	
	if SGroup_CheckActiveCommand("sg_outpost_raiders", SQUADSTATEID_Idle, true) then
		
		if EGroup_IsCapturedByPlayer(g_area_to_capture, g_Player2, false) == false then
			
			Cmd_Capture("sg_outpost_raiders", g_area_to_capture )
			
		elseif EGroup_IsCapturedByPlayer(g_area_to_capture, g_Player2, false) == true then
			
			g_outpost_raider_destination = World_GetRand(1, table.getn(t_bases_of_operation.minor_flags))
			
			Cmd_Capture("sg_outpost_raiders", g_area_to_capture)
			
		end
		
	end
	
	
elseif (SGroup_Exists("sg_outpost_raiders") == false) or (SGroup_IsEmpty("sg_outpost_raiders") == true) then
	
	Rule_AddIntervalDelay(Rule_Outpost_Raiders, 10, (230 - g_adjusted_frequency))  --180
	
	Rule_Remove(Rule_Outpost_Raiders_Idle)
	
end

end


-- function for reinforcing Gorgutz' main base function Rule_Gorgutz_Reinforcements()

for i = 1, table.getn(t_gorgutz_defender_info.name) do
	
	if EGroup_Exists("eg_infantry_reinforcement_building"..i) and EGroup_IsEmpty("eg_infantry_reinforcement_building"..i) == false then
	
		if SGroup_Exists(t_gorgutz_defender_info.name[i]) and SGroup_IsEmpty(t_gorgutz_defender_info.name[i]) == true then
			
			if g_reinforcement_wait >= 60 then
				
				--if EGroup_Exists("eg_infantry_reinforcement_building"..i) and EGroup_IsEmpty("eg_infantry_reinforcement_building"..i) == false then
				
					Util_CreateSquadsAtMarkerEx(g_Player2, t_gorgutz_defender_info.name[i], t_gorgutz_defender_info.defender_type[i], t_gorgutz_defender_info.respawn_location[i],  --t_gorgutz_defender_info.spawn_location[i]
					t_gorgutz_defender_info.spawn_squad_number[i], t_gorgutz_defender_info.spawn_squad_population[i])
					SGroup_AddLeaders(t_gorgutz_defender_info.name[i])
					
					Cmd_AttackMoveMarker(t_gorgutz_defender_info.name[i], t_gorgutz_defender_info.spawn_location[i])
					
					g_reinforcement_wait = 0
					break
				--[[
				elseif EGroup_Exists("eg_infantry_reinforcement_building") and EGroup_IsEmpty("eg_infantry_reinforcement_building") == true then
					
					Rule_Remove(Rule_Gorgutz_Reinforcements)]]
					
				--end
				
			elseif g_reinforcement_wait < 60 then
				
				g_reinforcement_wait = g_reinforcement_wait + 1
				
				break
				
			end
			
		end
		
	elseif EGroup_Exists("eg_infantry_reinforcement_building") and EGroup_IsEmpty("eg_infantry_reinforcement_building") == true then
		
		Rule_Remove(Rule_Gorgutz_Reinforcements)
		
	end
	
end

--g_reinforcement_wait = g_reinforcement_wait + 1

end

-- function for reinforcing Gorgutz's vehicles in his main base function Rule_Gorgutz_Vehicle_Reinforcements()

for i = 1, table.getn(t_gorgutz_vehicle_defender_info.name) do
	
	if SGroup_Exists(t_gorgutz_vehicle_defender_info.name[i]) and SGroup_IsEmpty(t_gorgutz_vehicle_defender_info.name[i]) == true then
		
		if g_vehicle_reinforcement_wait >= 300 then
			if EGroup_Exists("eg_vehicle_reinforcement_building") and EGroup_IsEmpty("eg_vehicle_reinforcement_building") == false then
				
				Util_CreateSquadsAtMarkerEx(g_Player2, t_gorgutz_vehicle_defender_info.name[i], t_gorgutz_vehicle_defender_info.defender_type[i], "mkr_looted_tank_spawner", --t_gorgutz_vehicle_defender_info.spawn_location[i]
				t_gorgutz_vehicle_defender_info.spawn_squad_number[i], t_gorgutz_vehicle_defender_info.spawn_squad_population[i])
				--SGroup_AddLeaders(t_gorgutz_vehicle_defender_info.name[i])
				
				Cmd_AttackMoveMarker(t_gorgutz_vehicle_defender_info.name[i], t_gorgutz_vehicle_defender_info.spawn_location[i])
				
				g_vehicle_reinforcement_wait = 0
				break
				
			elseif EGroup_Exists("eg_vehicle_reinforcement_building") and EGroup_IsEmpty("eg_vehicle_reinforcement_building") == true then
				
				Rule_Remove(Rule_Gorgutz_Vehicle_Reinforcements)
				
			end
			
		elseif g_vehicle_reinforcement_wait < 300 then
			
			g_vehicle_reinforcement_wait = g_vehicle_reinforcement_wait + 1
			break
			
		end
		
	end
	
end

-- g_vehicle_reinforcement_wait = g_vehicle_reinforcement_wait + 1

end

function Rule_Initial_Rampage_Trigger() -- when the player moves towards a certain marker, the squiggoth will attempt to rampage the player. -- once this is done, another function is called that makes it so that every so often the squiggoth would target any squad close by and attack that with an additional rampage

if SGroup_Exists("sg_squiggoth1") and SGroup_IsEmpty("sg_squiggoth1") == false then
	if Player_AreSquadsNearMarker(g_Player1, "mkr_squiggoth_charge_trigger") then
		
		Player_GetAllSquadsNearMarker( g_Player1, "sg_squiggoth_bait", "mkr_squiggoth_charge_trigger" )
		Cmd_RampagePos("sg_squiggoth1", SGroup_GetPosition("sg_squiggoth_bait"))
		
		Rule_AddOneShot(Rule_IE_Squiggoth_Rampage, 1)
		
		Rule_AddIntervalDelay(Rule_Squiggoth_Rampage_Trigger, 1, 15)
		Rule_Remove(Rule_Initial_Rampage_Trigger)
	end
end

end

function Rule_Squiggoth_Rampage_Trigger() -- this function is such that any of the squads within a radius of 40 around the squiggoth will become fair game for the squiggoth's rampage.

--if Prox_PlayerSquadsInProximityOfSquads(g_Player1, "sg_squiggoth1", 20, false) then

--Prox_PlayerSquadsInProximityOfPlayerSquads(g_Player1, g_Player2, 20, false) --if Player_AreSquadsNearMarker(g_Player1, "mkr_squiggoth_charge_trigger") then

	if SGroup_Exists("sg_squiggoth1") and SGroup_IsEmpty("sg_squiggoth1") == false then
		
		if Prox_PlayerSquadsInProximityOfSquads(g_Player1, "sg_squiggoth1", 40, false) then
			
			Player_GetAllSquadsNearPos(g_Player1, "sg_squiggoth_bait", SGroup_GetPosition(SGroup_FromName("sg_squiggoth1")), 40)				
			--Player_GetAllSquadsNearMarker( g_Player1, "sg_squiggoth_bait", "mkr_squiggoth_charge_trigger" )
			Cmd_RampagePos("sg_squiggoth1", SGroup_GetPosition("sg_squiggoth_bait"))
			Rule_Remove(Rule_Squiggoth_Rampage_Trigger)
			Rule_AddOneShot(Rule_Squiggoth_Rampage_Activation, 1)
		end
	elseif SGroup_Exists("sg_squiggoth1") and SGroup_IsEmpty("sg_squiggoth1") == true then
		
		Rule_Remove(Rule_Squiggoth_Rampage_Trigger)
		
	end

end

function Rule_Squiggoth_Rampage_Activation() -- switch function to cause the function to repeat itself every second, after 15 seconds of delay

Rule_AddIntervalDelay(Rule_Squiggoth_Rampage_Trigger, 1, 15)
Rule_Remove(Rule_Squiggoth_Rampage_Activation)

end

--[[Relic Takeover Mechanic]]

function Rule_Relic_Takeover_Mechanic()

--When the relic is taken over by player 1, certain numbers of Gorgutz' troops go wild if EGroup_IsCapturedByPlayer("eg_relic_flag" , g_Player1, false ) then

	Rule_AddInterval(Rule_Gorgutz_Base_Untag, 1)
	
	FOW_TagSGroup(g_Player1, SGroup_FromName("sg_gorgutz_defense_orks"))
		
	if SGroup_Exists("sg_gorgutz_surprise_rebels") and (SGroup_IsEmpty("sg_gorgutz_surprise_rebels") == false) then
		
		SGroup_SetPlayerOwner("sg_gorgutz_surprise_rebels", g_Player8)
		
	end
	
	if SGroup_Exists("sg_rebel_tank") and (SGroup_IsEmpty("sg_rebel_tank") == false) then
		
		SGroup_SetPlayerOwner("sg_rebel_tank", g_Player8)
		
	end
	
	Rule_AddOneShot(Rule_IE_Relic_Captured, 1)
	
	Rule_Remove(Rule_Relic_Takeover_Mechanic)
	
end

end

function Rule_Gorgutz_Base_Untag() --if rebels are dead, then call the untagging function after 7 seconds so Orks finish their death animations, etc. instead of cutting straight to black

if (SGroup_Exists("sg_gorgutz_surprise_rebels") and (SGroup_IsEmpty("sg_gorgutz_surprise_rebels") == true)) and
		(SGroup_Exists("sg_rebel_tank") and (SGroup_IsEmpty("sg_rebel_tank") == true)) then
	
	Rule_AddOneShot(Rule_Untagging_FOW, 7)
	
	Rule_Remove(Rule_Gorgutz_Base_Untag)
end

end

--untags FOW from Gorgutz' base defenders function Rule_Untagging_FOW()

FOW_UnTagSGroup(g_Player1, SGroup_FromName("sg_gorgutz_defense_orks"))

end


--[[

--[[Timer functions to display minutes played on screen]] function Rule_Add_Timer()

	UI_ShowCount("Timer", g_Player1, 2740000, g_Timer )
	Rule_AddInterval(Rule_Increment_Timer, 60)

end

function Rule_Increment_Timer()

g_Timer = g_Timer +1
UI_ShowCountUpdate("Timer", g_Timer)

end]]

-- kicks of function that ticks away number of seconds function Rule_Add_Seconds()

Rule_AddInterval(Rule_Increment_Seconds, 1)

end

function Rule_Increment_Seconds() g_time_elapsed = g_time_elapsed + 1 end

--[[ function Rule_Kill_Clan_Bosses_Ping_Stop() for i = 1, 5 do Util_Ping_Stop("ping_clan_boss"..i) end end]]

function Rule_Kill_Headcrushaz_Banner_Ping_Stop()

Util_Ping_Stop("ping_clan_banner1")

end

function Rule_Kill_Rokkitrangaz_Banner_Ping_Stop()

Util_Ping_Stop("ping_clan_banner2")

end

function Rule_Kill_Burnaboyz_Banner_Ping_Stop()

Util_Ping_Stop("ping_clan_banner3")

end

function Rule_Kill_Kwikmekz_Banner_Ping_Stop()

Util_Ping_Stop("ping_clan_banner4")

end

function Rule_Kill_Footstompaz_Banner_Ping_Stop()

Util_Ping_Stop("ping_clan_banner5")

end

-- yes, long name but easier to determine the purpose of this function since it will use the same creation functions as the Rule_Initiate... series -- because there is no guarantee that a rebel faction will enter the base area, a check is added so that the function is disabled if the player already reached -- the base already (since the defenders would have been generated already) function Rule_Headcrushaz_Defense_Against_Rebels_Creation() if g_headcrushaz_defense_created == false then if Player_AreSquadsNearMarker(g_Player3, "mkr_headcrushaz_creation_threshold") then Rule_AddOneShot(Rule_Ork_Headcrushaz_Creation, 1) Rule_Remove(Rule_Headcrushaz_Defense_Against_Rebels_Creation) elseif Player_AreSquadsNearMarker(g_Player4, "mkr_headcrushaz_creation_threshold") then Rule_AddOneShot(Rule_Ork_Headcrushaz_Creation, 1) Rule_Remove(Rule_Headcrushaz_Defense_Against_Rebels_Creation) elseif Player_AreSquadsNearMarker(g_Player5, "mkr_headcrushaz_creation_threshold") then Rule_AddOneShot(Rule_Ork_Headcrushaz_Creation, 1) Rule_Remove(Rule_Headcrushaz_Defense_Against_Rebels_Creation) elseif Player_AreSquadsNearMarker(g_Player6, "mkr_headcrushaz_creation_threshold") then Rule_AddOneShot(Rule_Ork_Headcrushaz_Creation, 1) Rule_Remove(Rule_Headcrushaz_Defense_Against_Rebels_Creation) elseif Player_AreSquadsNearMarker(g_Player7, "mkr_headcrushaz_creation_threshold") then Rule_AddOneShot(Rule_Ork_Headcrushaz_Creation, 1) Rule_Remove(Rule_Headcrushaz_Defense_Against_Rebels_Creation) end end end

function Rule_Rokkitrangaz_Defense_Against_Rebels_Creation() if g_rokkitrangaz_defense_created == false then if Player_AreSquadsNearMarker(g_Player3, "mkr_rokkitrangaz_creation_threshold") then Rule_AddOneShot(Rule_Ork_Rokkitrangaz_Creation, 1) Rule_Remove(Rule_Rokkitrangaz_Defense_Against_Rebels_Creation)

	elseif Player_AreSquadsNearMarker(g_Player4, "mkr_rokkitrangaz_creation_threshold") then
		Rule_AddOneShot(Rule_Ork_Rokkitrangaz_Creation, 1)
		Rule_Remove(Rule_Rokkitrangaz_Defense_Against_Rebels_Creation)
		
	elseif Player_AreSquadsNearMarker(g_Player5, "mkr_rokkitrangaz_creation_threshold") then
		Rule_AddOneShot(Rule_Ork_Rokkitrangaz_Creation, 1)
		Rule_Remove(Rule_Rokkitrangaz_Defense_Against_Rebels_Creation)
		
	elseif Player_AreSquadsNearMarker(g_Player6, "mkr_rokkitrangaz_creation_threshold") then
		Rule_AddOneShot(Rule_Ork_Rokkitrangaz_Creation, 1)
		Rule_Remove(Rule_Rokkitrangaz_Defense_Against_Rebels_Creation)
		
	elseif Player_AreSquadsNearMarker(g_Player7, "mkr_rokkitrangaz_creation_threshold") then
		Rule_AddOneShot(Rule_Ork_Rokkitrangaz_Creation, 1)
		Rule_Remove(Rule_Rokkitrangaz_Defense_Against_Rebels_Creation)
		
	end
end

end

function Rule_Burnaboyz_Defense_Against_Rebels_Creation() if g_burnaboyz_defense_created == false then if Player_AreSquadsNearMarker(g_Player3, "mkr_burnaboyz_creation_threshold") then Rule_AddOneShot(Rule_Ork_Burnaboyz_Creation, 1) Rule_Remove(Rule_Burnaboyz_Defense_Against_Rebels_Creation) elseif Player_AreSquadsNearMarker(g_Player4, "mkr_burnaboyz_creation_threshold") then Rule_AddOneShot(Rule_Ork_Burnaboyz_Creation, 1) Rule_Remove(Rule_Burnaboyz_Defense_Against_Rebels_Creation) elseif Player_AreSquadsNearMarker(g_Player5, "mkr_burnaboyz_creation_threshold") then Rule_AddOneShot(Rule_Ork_Burnaboyz_Creation, 1) Rule_Remove(Rule_Burnaboyz_Defense_Against_Rebels_Creation) elseif Player_AreSquadsNearMarker(g_Player6, "mkr_burnaboyz_creation_threshold") then Rule_AddOneShot(Rule_Ork_Burnaboyz_Creation, 1) Rule_Remove(Rule_Burnaboyz_Defense_Against_Rebels_Creation) elseif Player_AreSquadsNearMarker(g_Player7, "mkr_burnaboyz_creation_threshold") then Rule_AddOneShot(Rule_Ork_Burnaboyz_Creation, 1) Rule_Remove(Rule_Burnaboyz_Defense_Against_Rebels_Creation) end

end

end

function Rule_Kwikmekz_Defense_Against_Rebels_Creation() if g_kwikmekz_defense_created == false then if Player_AreSquadsNearMarker(g_Player3, "mkr_kwikmekz_creation_threshold") then Rule_AddOneShot(Rule_Ork_Kwikmekz_Creation, 1) Rule_Remove(Rule_Kwikmekz_Defense_Against_Rebels_Creation) elseif Player_AreSquadsNearMarker(g_Player4, "mkr_kwikmekz_creation_threshold") then Rule_AddOneShot(Rule_Ork_Kwikmekz_Creation, 1) Rule_Remove(Rule_Kwikmekz_Defense_Against_Rebels_Creation) elseif Player_AreSquadsNearMarker(g_Player5, "mkr_kwikmekz_creation_threshold") then Rule_AddOneShot(Rule_Ork_Kwikmekz_Creation, 1) Rule_Remove(Rule_Kwikmekz_Defense_Against_Rebels_Creation) elseif Player_AreSquadsNearMarker(g_Player6, "mkr_kwikmekz_creation_threshold") then Rule_AddOneShot(Rule_Ork_Kwikmekz_Creation, 1) Rule_Remove(Rule_Kwikmekz_Defense_Against_Rebels_Creation) elseif Player_AreSquadsNearMarker(g_Player7, "mkr_kwikmekz_creation_threshold") then Rule_AddOneShot(Rule_Ork_Kwikmekz_Creation, 1) Rule_Remove(Rule_Kwikmekz_Defense_Against_Rebels_Creation) end end end

function Rule_Footstompaz_Defense_Against_Rebels_Creation() if g_kwikmekz_defense_created == false then if Player_AreSquadsNearMarker(g_Player3, "mkr_footstompaz_creation_threshold") then Rule_AddOneShot(Rule_Ork_Footstompaz_Creation, 1) Rule_Remove(Rule_Footstompaz_Defense_Against_Rebels_Creation)

	elseif Player_AreSquadsNearMarker(g_Player4, "mkr_footstompaz_creation_threshold") then
		Rule_AddOneShot(Rule_Ork_Footstompaz_Creation, 1)
		Rule_Remove(Rule_Footstompaz_Defense_Against_Rebels_Creation)
		
	elseif Player_AreSquadsNearMarker(g_Player5, "mkr_footstompaz_creation_threshold") then
		Rule_AddOneShot(Rule_Ork_Footstompaz_Creation, 1)
		Rule_Remove(Rule_Footstompaz_Defense_Against_Rebels_Creation)
		
	elseif Player_AreSquadsNearMarker(g_Player6, "mkr_footstompaz_creation_threshold") then
		Rule_AddOneShot(Rule_Ork_Footstompaz_Creation, 1)
		Rule_Remove(Rule_Footstompaz_Defense_Against_Rebels_Creation)
		
	elseif Player_AreSquadsNearMarker(g_Player7, "mkr_footstompaz_creation_threshold") then
		Rule_AddOneShot(Rule_Ork_Footstompaz_Creation, 1)
		Rule_Remove(Rule_Footstompaz_Defense_Against_Rebels_Creation)
		
	end
	
end

end

--[[random speech]]

function Rule_Random_Speech_Activation()

if SGroup_Exists("sg_counterattack_force") and SGroup_IsEmpty("sg_counterattack_force") == false then

	if SGroup_IsUnderAttackByPlayer("sg_counterattack_force", false, g_Player1) then
	
		Rule_AddOneShot(Rule_Play_Random_Speech, 0)
		
		Rule_Remove(Rule_Random_Speech_Activation)
		
	end
	

end

end

function Rule_Play_Random_Speech()

t_random_line_used_table = {rule = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}

--[[
t_random_line_used_table = {rule = {Rule_IE_Generic_Gorgutz1, Rule_IE_Generic_Gorgutz2, Rule_IE_Generic_Gorgutz3, Rule_IE_Generic_Gorgutz4, Rule_IE_Generic_Gorgutz5, 
															Rule_IE_Generic_Gorgutz6, Rule_IE_Generic_Gorgutz7, Rule_IE_Generic_Gorgutz8, Rule_IE_Generic_Gorgutz9, Rule_IE_Generic_Gorgutz10}}]]



local l_random_line = World_GetRand(1, table.getn(t_random_line_used_table.rule))


if g_previous_line_used ~= l_random_line then
	
	--Rule_AddOneShot(t_random_line_used_table.rule[l_random_line], 1)
	
	if l_random_line == 1 then
		
		Rule_AddOneShot(Rule_IE_Generic_Gorgutz1, 0)
		g_previous_line_used = l_random_line
		
	elseif l_random_line == 2 then
		
		Rule_AddOneShot(Rule_IE_Generic_Gorgutz2, 0)
		g_previous_line_used = l_random_line
		
	elseif l_random_line == 3 then
		
		Rule_AddOneShot(Rule_IE_Generic_Gorgutz3, 0)
		g_previous_line_used = l_random_line
		
	elseif l_random_line == 4 then
		
		Rule_AddOneShot(Rule_IE_Generic_Gorgutz4, 0)
		g_previous_line_used = l_random_line
		
	elseif l_random_line == 5 then
		
		Rule_AddOneShot(Rule_IE_Generic_Gorgutz5, 0)
		g_previous_line_used = l_random_line
		
	elseif l_random_line == 6 then
		
		Rule_AddOneShot(Rule_IE_Generic_Gorgutz6, 0)
		g_previous_line_used = l_random_line
		
	elseif l_random_line == 7 then
		
		Rule_AddOneShot(Rule_IE_Generic_Gorgutz7, 0)
		g_previous_line_used = l_random_line
		
	elseif l_random_line == 8 then
		
		Rule_AddOneShot(Rule_IE_Generic_Gorgutz8, 0)
		g_previous_line_used = l_random_line
		
	elseif l_random_line == 9 then
		
		Rule_AddOneShot(Rule_IE_Generic_Gorgutz9, 0)
		g_previous_line_used = l_random_line
		
	elseif l_random_line == 10 then
		
		Rule_AddOneShot(Rule_IE_Generic_Gorgutz10, 0)
		g_previous_line_used = l_random_line
		
	end
	
end

end


--[[ Objectives]]

function Rule_Add_Kill_Clan_Banners_Objective()

Rule_AddInterval(Rule_Banner_Tracker, 1)
--Rule_AddIntervalDelay(Rule_Objective_Kill_Clan_Banneres, 1,10)	

end

-- The following several functions kick off the creation functions, and then the objectives afterwards function Rule_Initiate_Kill_Headcrushaz_Banner()

if Player_AreSquadsNearMarker(g_Player1, "mkr_headcrushaz_creation_threshold") then --mkr_headcrushaz_base
	
	Rule_AddOneShot(Rule_Ork_Headcrushaz_Creation, 1)
	Rule_AddOneShot(Rule_Reveal_Headcrushaz_Banner, 2)
	
	Rule_AddIntervalDelay(Rule_Objective_Kill_Headcrushaz_Banner, 1, 2)
	

	
	Rule_Remove(Rule_Initiate_Kill_Headcrushaz_Banner)
	
end

end

function Rule_Reveal_Headcrushaz_Banner() -- reveals this boss' FOW to player

if EGroup_Exists("eg_headcrushaz_banner") and EGroup_IsEmpty("eg_headcrushaz_banner") == false then
	
	print("headcrushaz boss highlighted")
	FOW_TagEGroup(g_Player1, EGroup_FromName("eg_headcrushaz_banner"))
	FOW_RevealEGroup(EGroup_FromName("eg_headcrushaz_banner"), 30)
	
end

end

function Rule_Initiate_Kill_Rokkitrangaz_Banner()

if Player_AreSquadsNearMarker(g_Player1, "mkr_rokkitrangaz_creation_threshold") then --mkr_rokkitrangaz_base
	
	Rule_AddOneShot(Rule_Ork_Rokkitrangaz_Creation, 1)
	Rule_AddOneShot(Rule_Reveal_Rokkitrangaz_Banner, 2)
	
	Rule_AddIntervalDelay(Rule_Objective_Kill_Rokkitrangaz_Banner, 1, 2)
	
	
	Rule_Remove(Rule_Initiate_Kill_Rokkitrangaz_Banner)
	
end

end

function Rule_Reveal_Rokkitrangaz_Banner() -- reveals this boss' FOW to player

if EGroup_Exists("eg_rokkitrangaz_banner") and EGroup_IsEmpty("eg_rokkitrangaz_banner") == false then
	
	print("rokkitrangaz boss highlighted")
	FOW_TagEGroup(g_Player1, EGroup_FromName("eg_rokkitrangaz_banner"))
	
end

end

function Rule_Initiate_Kill_Burnaboyz_Banner() if Player_AreSquadsNearMarker(g_Player1, "mkr_burnaboyz_creation_threshold") then -- mkr_burnaboyz_base

	Rule_AddOneShot(Rule_Ork_Burnaboyz_Creation, 1)
	Rule_AddOneShot(Rule_Reveal_Burnaboyz_Banner, 2)
	
	Rule_AddIntervalDelay(Rule_Objective_Kill_Burnaboyz_Banner, 1, 2)
	
	
	
	Rule_Remove(Rule_Initiate_Kill_Burnaboyz_Banner)
	
end

end

function Rule_Reveal_Burnaboyz_Banner() -- reveals this boss' FOW to player

if EGroup_Exists("eg_burnaboyz_banner") and EGroup_IsEmpty("eg_burnaboyz_banner") == false then
	
	print("burnaboyz boss highlighted")
	FOW_TagEGroup(g_Player1, EGroup_FromName("eg_burnaboyz_banner"))
	
end

end

function Rule_Initiate_Kill_Kwikmekz_Banner()

if Player_AreSquadsNearMarker(g_Player1, "mkr_kwikmekz_creation_threshold") then -- mkr_kwikmekz_base
	
	Rule_AddOneShot(Rule_Ork_Kwikmekz_Creation, 1)
	Rule_AddOneShot(Rule_Reveal_Kwikmekz_Banner, 2)
	
	Rule_AddIntervalDelay(Rule_Objective_Kill_Kwikmekz_Banner, 1, 2)
	
	
	
	Rule_Remove(Rule_Initiate_Kill_Kwikmekz_Banner)
	
end

end

function Rule_Reveal_Kwikmekz_Banner() -- reveals this boss' FOW to player

if EGroup_Exists("eg_kwikmekz_banner") and EGroup_IsEmpty("eg_kwikmekz_banner") == false then
	
	print("kwikmekz boss highlighted")
	FOW_TagEGroup(g_Player1, EGroup_FromName("eg_kwikmekz_banner"))
	
end

end

function Rule_Initiate_Kill_Footstompaz_Banner() if Player_AreSquadsNearMarker(g_Player1, "mkr_footstompaz_creation_threshold") then --mkr_footstomapaz_base

	Rule_AddOneShot(Rule_Ork_Footstompaz_Creation, 1)
	Rule_AddOneShot(Rule_Reveal_Footstompaz_Banner, 2)
	
	Rule_AddIntervalDelay(Rule_Objective_Kill_Footstompaz_Banner, 1, 2)
	
	
	
	Rule_Remove(Rule_Initiate_Kill_Footstompaz_Banner)
	
end

end

function Rule_Reveal_Footstompaz_Banner() -- reveals this boss' FOW to player

if EGroup_Exists("eg_footstompaz_banner") and EGroup_IsEmpty("eg_footstompaz_banner") == false then
	
	print("footstompaz boss highlighted")
	FOW_TagEGroup(g_Player1, EGroup_FromName("eg_footstompaz_banner"))
	
end

end


function Rule_Objective_Kill_Gorgutz()

Objective_Kill_Gorgutz = { title_id = 2720000, short_desc_id = 2720002, help_tip_id = 2720000 }

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Kill_Gorgutz.title_id) == false then
	
	Util_WXP_ObjectiveCreate( Objective_Kill_Gorgutz, true, g_Player1 )
	
	Objective_ShowScreen()
	Flash_OtherButton("dlg_objectives", 0, false, true)
	
	Util_Ping_LoopingMkr( "ping_gorgutz", "mkr_gorgutz_spawn" )
	
	FOW_RevealMarker( "mkr_gorgutz_spawn", 10 )
	
	t_obj_kill_gorgutz_ping = Objective_PingMarker(Objective_Kill_Gorgutz.title_id, "mkr_gorgutz_spawn", true, "default")
	
	Rule_AddOneShot(Rule_Gorgutz_Ping_Stop, 10)
	
elseif Event_IsAnyRunning() == false and g_player_win == true then
	
	Util_ObjectiveComplete(Objective_Kill_Gorgutz.title_id)
	
	Util_Ping_Stop("ping_gorgutz")
	
	Objective_PingRemove(Objective_Kill_Gorgutz.title_id, t_obj_kill_gorgutz_ping)
	
	Rule_Remove(Rule_Objective_Kill_Gorgutz)
	
	--[[game is won]]
	Util_StartNIS( EVENTS.NIS_Closing )
	
end

end

--[[This secondary objective is for killing the leader of the Headcrushaz on the map]] function Rule_Objective_Kill_Headcrushaz_Banner()

Objective_Kill_Headcrushaz_Banner = { title_id = 2721006, short_desc_id = 2721008, help_tip_id = 2721006 }

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Kill_Headcrushaz_Banner.title_id) == false then
	
	Util_WXP_ObjectiveCreate( Objective_Kill_Headcrushaz_Banner, false, g_Player1 )
	
	Objective_ShowScreen()
	Flash_OtherButton("dlg_objectives", 0, false, true)
	
	--these pings may be added/required at a later date
	
	
	Util_Ping_LoopingMkr( "ping_clan_banner1", t_clan_banner_list[1] )
	
	
	--t_obj_clan_boss_ping = {}
	
	
	g_obj_clan_banner_ping1 = Objective_PingMarker(Objective_Kill_Headcrushaz_Banner.title_id, t_clan_banner_list[1], true, "default")
	
	
	--Rule_AddInterval(Rule_Boss_Tracker, 1) -- kicks off boss tracker
	
	Rule_AddOneShot(Rule_IE_Near_Headcrushaz_Base, 1)
	
	Rule_AddOneShot(Rule_Kill_Headcrushaz_Banner_Ping_Stop, 20)
	
elseif Event_IsAnyRunning() == false and EGroup_IsEmpty("eg_headcrushaz_banner") then
	
	Util_ObjectiveComplete(Objective_Kill_Headcrushaz_Banner.title_id)
	
	--these pings may be added/required at a later date
	
	Util_Ping_Stop("ping_clan_banner1")
	
	Objective_PingRemove(Objective_Kill_Headcrushaz_Banner.title_id, g_obj_clan_banner_ping1)
	
	Rule_Remove(Rule_Objective_Kill_Headcrushaz_Banner)
	
end

end

--[[This secondary objective is for killing the leader of the Rokkitrangaz on the map]] function Rule_Objective_Kill_Rokkitrangaz_Banner()

Objective_Kill_Rokkitrangaz_Banner = { title_id = 2721012, short_desc_id = 2721014, help_tip_id = 2721012 }

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Kill_Rokkitrangaz_Banner.title_id) == false then
	
	Util_WXP_ObjectiveCreate( Objective_Kill_Rokkitrangaz_Banner, false, g_Player1 )
	
	Objective_ShowScreen()
	Flash_OtherButton("dlg_objectives", 0, false, true)
	
	--these pings may be added/required at a later date
	
	
	Util_Ping_LoopingMkr( "ping_clan_banner2", t_clan_banner_list[2] )
	
	
	--t_obj_clan_boss_ping = {}
	
	
	g_obj_clan_banner_ping2 = Objective_PingMarker(Objective_Kill_Rokkitrangaz_Banner.title_id, t_clan_banner_list[2], true, "default")
	
	
	--Rule_AddInterval(Rule_Boss_Tracker, 1) -- kicks off boss tracker
	
	Rule_AddOneShot(Rule_IE_Near_Rokkitrangaz_Base, 1)
	Rule_AddOneShot(Rule_Kill_Rokkitrangaz_Banner_Ping_Stop, 20)
	
elseif Event_IsAnyRunning() == false and EGroup_IsEmpty("eg_rokkitrangaz_banner") then
	
	Util_ObjectiveComplete(Objective_Kill_Rokkitrangaz_Banner.title_id)
	
	--these pings may be added/required at a later date
	
	Util_Ping_Stop("ping_clan_banner2")
	
	Objective_PingRemove(Objective_Kill_Rokkitrangaz_Banner.title_id, g_obj_clan_banner_ping2)
	
	Rule_Remove(Rule_Objective_Kill_Rokkitrangaz_Banner)
	
end

end

--[[This secondary objective is for killing the leader of the Burnaboyz on the map]] function Rule_Objective_Kill_Burnaboyz_Banner()

Objective_Kill_Burnaboyz_Banner = { title_id = 2721018, short_desc_id = 2721020, help_tip_id = 2721018 }

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Kill_Burnaboyz_Banner.title_id) == false then
	
	Util_WXP_ObjectiveCreate( Objective_Kill_Burnaboyz_Banner, false, g_Player1 )
	
	Objective_ShowScreen()
	Flash_OtherButton("dlg_objectives", 0, false, true)
	
	--these pings may be added/required at a later date
	
	
	
	
	Util_Ping_LoopingMkr( "ping_clan_banner3", t_clan_banner_list[3] )
	
	
	--t_obj_clan_boss_ping = {}
	
	
	g_obj_clan_banner_ping3 = Objective_PingMarker(Objective_Kill_Burnaboyz_Banner.title_id, t_clan_banner_list[3], true, "default")
	
	
	--Rule_AddInterval(Rule_Boss_Tracker, 1) -- kicks off boss tracker
	Rule_AddOneShot(Rule_IE_Near_Burnaboyz_Base, 1)
	Rule_AddOneShot(Rule_Kill_Burnaboyz_Banner_Ping_Stop, 20)
	
elseif Event_IsAnyRunning() == false and EGroup_IsEmpty("eg_burnaboyz_banner") then
	
	Util_ObjectiveComplete(Objective_Kill_Burnaboyz_Banner.title_id)
	
	--these pings may be added/required at a later date
	
	Util_Ping_Stop("ping_clan_banner3")
	
	Objective_PingRemove(Objective_Kill_Burnaboyz_Banner.title_id, g_obj_clan_banner_ping3)
	
	Rule_Remove(Rule_Objective_Kill_Burnaboyz_Banner)
	
end

end

--[[This secondary objective is for killing the leader of the Kwikmekz on the map]] function Rule_Objective_Kill_Kwikmekz_Banner()

Objective_Kill_Kwikmekz_Banner = { title_id = 2721024, short_desc_id = 2721026, help_tip_id = 2721024 }

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Kill_Kwikmekz_Banner.title_id) == false then
	
	Util_WXP_ObjectiveCreate( Objective_Kill_Kwikmekz_Banner, false, g_Player1 )
	
	Objective_ShowScreen()
	Flash_OtherButton("dlg_objectives", 0, false, true)
	
	--these pings may be added/required at a later date
	
	
	Util_Ping_LoopingMkr( "ping_clan_banner4", t_clan_banner_list[4] )
	
	
	--t_obj_clan_boss_ping = {}
	
	
	g_obj_clan_banner_ping4 = Objective_PingMarker(Objective_Kill_Kwikmekz_Banner.title_id, t_clan_banner_list[4], true, "default")
	
	
	--Rule_AddInterval(Rule_Boss_Tracker, 1) -- kicks off boss tracker
	Rule_AddOneShot(Rule_IE_Near_Kwikmekz_Base, 1)
	Rule_AddOneShot(Rule_Kill_Kwikmekz_Banner_Ping_Stop, 20)
	
elseif Event_IsAnyRunning() == false and EGroup_IsEmpty("eg_kwikmekz_banner") then
	
	Util_ObjectiveComplete(Objective_Kill_Kwikmekz_Banner.title_id)
	
	--these pings may be added/required at a later date
	
	Util_Ping_Stop("ping_clan_banner4")
	
	Objective_PingRemove(Objective_Kill_Kwikmekz_Banner.title_id, g_obj_clan_banner_ping4)
	
	Rule_Remove(Rule_Objective_Kill_Kwikmekz_Banner)
	
end

end

--[[This secondary objective is for killing the leader of the Footstompaz on the map]] function Rule_Objective_Kill_Footstompaz_Banner()

Objective_Kill_Footstompaz_Banner = { title_id = 2721030, short_desc_id = 2721032, help_tip_id = 2721030 }

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Kill_Footstompaz_Banner.title_id) == false then
	
	Util_WXP_ObjectiveCreate( Objective_Kill_Footstompaz_Banner, false, g_Player1 )
	
	Objective_ShowScreen()	
	Flash_OtherButton("dlg_objectives", 0, false, true)
	
	--these pings may be added/required at a later date
	
	
	Util_Ping_LoopingMkr( "ping_clan_banner5", t_clan_banner_list[5] )
	
	
	--t_obj_clan_boss_ping = {}
	
	
	g_obj_clan_banner_ping5 = Objective_PingMarker(Objective_Kill_Footstompaz_Banner.title_id, t_clan_banner_list[5], true, "default")
	
	
	--Rule_AddInterval(Rule_Boss_Tracker, 1) -- kicks off boss tracker
	
	Rule_AddOneShot(Rule_IE_Near_Footstompaz_Base, 1)
	Rule_AddOneShot(Rule_Kill_Footstompaz_Banner_Ping_Stop, 20)
	
elseif Event_IsAnyRunning() == false and EGroup_IsEmpty("eg_footstompaz_banner") then
	
	Util_ObjectiveComplete(Objective_Kill_Footstompaz_Banner.title_id)
	
	--these pings may be added/required at a later date
	
	Util_Ping_Stop("ping_clan_banner5")
	
	Objective_PingRemove(Objective_Kill_Footstompaz_Banner.title_id, g_obj_clan_banner_ping5)
	
	Rule_Remove(Rule_Objective_Kill_Footstompaz_Banner)
	
end

end


--[[ GAME OVER - Player Wins ]]

function Rule_EndGameWin() -- Player wins when Gorgutz is dead. if (SGroup_Exists("sg_gorgutz") and SGroup_IsEmpty("sg_gorgutz")) == true then

	g_player_win = true
	
	Rule_Remove(Rule_EndGameWin)
	Rule_Remove(Rule_EndGameLose)
	
end

end

--[[ function Rule_EndGameWin() -- Player wins when Gorgutz is dead. if Objective_Kill_Gorgutz ~= nil and Objective_Exists(Objective_Kill_Gorgutz.title_id) and Objective_GetState(Objective_Kill_Gorgutz.title_id) == OS_Complete then Rule_RemoveAll() World_SetTeamWin(g_Player1,"") Rule_AddIntervalEx(Rule_GameOver, 5, 1) 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 = 
{
	"chaos_listening_post",
	"chaos_turret_bolter",
	
	"eldar_listening_post",
	"eldar_support_platform_scatterlaser",
	"eldar_webway_gate",
	
	"guard_listening_post",
	"guard_turret_heavy_bolter",
	
	"necron_listening_post",
	"necron_turret",
	
	"ork_gork_totem",
	"ork_waagh_banner",
	
	"tau_listening_post",
	
	"space_marine_listening_post",
	"space_marine_turret_bolter"
}

g_unit_exceptions = 
{
	--"ork_squad_warboss"
}

--[[ Lose because of Annihilation ]]	
	if( Player_HasBuildingsExcept(g_Player1, g_building_exceptions) == false ) then
		if( Player_HasSquadsExcept(g_Player1, g_unit_exceptions ) == false ) 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


--INTEL EVENTS

function Rule_IE_Gorgutz_Gloat()

Util_StartIntel(EVENTS.IE_Gorgutz_Gloat)

end


--Final? text as follows. Will take away brackets when needed

function Rule_IE_Generic_Gorgutz1()

Util_StartIntel(EVENTS.IE_Generic_Gorgutz1)

end

function Rule_IE_Generic_Gorgutz2()

Util_StartIntel(EVENTS.IE_Generic_Gorgutz2)

end

function Rule_IE_Generic_Gorgutz3()

Util_StartIntel(EVENTS.IE_Generic_Gorgutz3)

end

function Rule_IE_Generic_Gorgutz4()

Util_StartIntel(EVENTS.IE_Generic_Gorgutz4)

end

function Rule_IE_Generic_Gorgutz5()

Util_StartIntel(EVENTS.IE_Generic_Gorgutz5)

end

function Rule_IE_Generic_Gorgutz6()

Util_StartIntel(EVENTS.IE_Generic_Gorgutz6)

end

function Rule_IE_Generic_Gorgutz7()

Util_StartIntel(EVENTS.IE_Generic_Gorgutz7)

end

function Rule_IE_Generic_Gorgutz8()

Util_StartIntel(EVENTS.IE_Generic_Gorgutz8)

end

function Rule_IE_Generic_Gorgutz9()

Util_StartIntel(EVENTS.IE_Generic_Gorgutz9)

end

function Rule_IE_Generic_Gorgutz10()

Util_StartIntel(EVENTS.IE_Generic_Gorgutz10)

end

function Rule_IE_Near_Headcrushaz_Base()

Util_StartIntel(EVENTS.IE_Near_Headcrushaz_Base)

end

function Rule_IE_Near_Footstompaz_Base()

Util_StartIntel(EVENTS.IE_Near_Footstompaz_Base)

end

function Rule_IE_Near_Burnaboyz_Base()

Util_StartIntel(EVENTS.IE_Near_Burnaboyz_Base)

end

function Rule_IE_Near_Rokkitrangaz_Base()

Util_StartIntel(EVENTS.IE_Near_Rokkitrangaz_Base)

end

function Rule_IE_Near_Kwikmekz_Base()

Util_StartIntel(EVENTS.IE_Near_Kwikmekz_Base)

end

function Rule_IE_Relic_Captured()

Util_StartIntel(EVENTS.IE_Relic_Captured)

end

function Rule_IE_Squiggoth_Rampage()

Util_StartIntel(EVENTS.IE_Squiggoth_Rampage)

end

function Rule_IE_Headcrushaz_Rebellion()

Util_StartIntel(EVENTS.IE_Headcrushaz_Rebellion)

end

function Rule_IE_Footstompaz_Rebellion()

Util_StartIntel(EVENTS.IE_Footstompaz_Rebellion)

end

function Rule_IE_Kwikmekz_Rebellion()

Util_StartIntel(EVENTS.IE_Kwikmekz_Rebellion)

end

function Rule_IE_Rokkitrangaz_Rebellion()

Util_StartIntel(EVENTS.IE_Rokkitrangaz_Rebellion)

end

function Rule_IE_Burnaboyz_Rebellion()

Util_StartIntel(EVENTS.IE_Burnaboyz_Rebellion)

end

function Rule_IE_Counterattack_Escalation1()

Util_StartIntel(EVENTS.IE_Counterattack_Escalation1)

end

function Rule_IE_Counterattack_Escalation2()

Util_StartIntel(EVENTS.IE_Counterattack_Escalation2)

end

function Rule_IE_Chaos_Mission_Start()

Util_StartIntel(EVENTS.IE_Chaos_Mission_Start)

end

function Rule_IE_Chaos_Approach_Gorgutz()

Util_StartIntel(EVENTS.IE_Chaos_Approach_Gorgutz)

end

function Rule_IE_Eldar_Mission_Start()

Util_StartIntel(EVENTS.IE_Eldar_Mission_Start)

end

function Rule_IE_Eldar_Approach_Gorgutz()

Util_StartIntel(EVENTS.IE_Eldar_Approach_Gorgutz)

end

function Rule_IE_IG_Mission_Start()

Util_StartIntel(EVENTS.IE_IG_Mission_Start)

end

function Rule_IE_IG_Approach_Gorgutz()

Util_StartIntel(EVENTS.IE_IG_Approach_Gorgutz)

end

function Rule_IE_Necron_Mission_Start()

Util_StartIntel(EVENTS.IE_Necron_Mission_Start)

end

function Rule_IE_Necron_Approach_Gorgutz()

Util_StartIntel(EVENTS.IE_Necron_Approach_Gorgutz)

end

function Rule_IE_Space_Marine_Mission_Start()

Util_StartIntel(EVENTS.IE_Space_Marine_Mission_Start)

end

function Rule_IE_Space_Marine_Approach_Gorgutz()

Util_StartIntel(EVENTS.IE_Space_Marine_Approach_Gorgutz)

end

function Rule_IE_Tau_Mission_Start()

Util_StartIntel(EVENTS.IE_Tau_Mission_Start)

end

function Rule_IE_Tau_Approach_Gorgutz()

Util_StartIntel(EVENTS.IE_Tau_Approach_Gorgutz)

end