Mission event file for Tau Stronghold mission
Guides
/
Mission event file for Tau Stronghold mission
Updated 3 years ago by Merric

--[[ IMPORTS ]]

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


--[[ TO DO ]]

-- IN THE MISSION BRIEFING, HINT TO THE PLAYER THAT THEY WILL NEED TO USE SKULL PROBES/DETECTION UNITS EQUIVALENT FOR THEIR RACE. They were not used much in the previous games, and the stealth suits are abundant here. -- if random attack guys suffer certain casualties, they will retreat, hoping to lure the player back so that they can ambush them or hit them with reinforcements


--[[ GAME SETUP ]]

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

--[[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) 
	--Misc_PlayerTeamColor(g_Player1, g_team_color)

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) 
	--Misc_PlayerTeamColor(g_Player1, g_team_color)
	
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



--g_Player1 = Setup_Player(0, factionname, MetaMap_GetPlayerRaceName(), 0) 

-- Misc_PlayerTeamColor(g_Player1, g_team_color)

--g_Player1 = Setup_Player(0, "Player Faction", "space_marine_race", 1) -- SM for now   2803000 player race number?


g_Player2 = Setup_Player(1, "Tau", "tau_race", 1) -- Tau opposition
	--Misc_PlayerTeamColor(g_Player2, "default_1")

--[[ DEFINE VARIABLES AND TABLES - define any preset values here for later use]]

g_firstrun = true

--[[determines if the game should regenerate patrol 1/patrol 2 or not]] 
g_patrol1_generator_destroyed = false
g_patrol2_generator_destroyed = false

--[[this value denotes the first waypoint for Tau Patrol 1/Patrol 2]]
g_patrol1 = 1
g_patrol2 = 1
g_ether_patrol = 1

--[[generates a list of waypoints for Tau Patrol 1]]
t_tau_patrol1_waypoints = {"mkr_patrol1_waypoint1", "mkr_patrol1_waypoint2", "mkr_patrol1_waypoint3", "mkr_patrol1_waypoint4", "mkr_patrol1_waypoint5"}
g_patrol1_waypoints = table.getn(t_tau_patrol1_waypoints)

--[[generates a list of waypoints for Tau Patrol 2]]
t_tau_patrol2_waypoints = {"mkr_patrol2_waypoint1", "mkr_patrol2_waypoint2", "mkr_patrol2_waypoint3", "mkr_patrol2_waypoint4", "mkr_patrol2_waypoint5", "mkr_patrol2_waypoint6"}
g_patrol2_waypoints = table.getn(t_tau_patrol2_waypoints)

--[[generates a list of waypoints for Ethereal Patrol]]
t_tau_ether_patrol_waypoints = {"mkr_ether_patrol1", "mkr_ether_patrol2", "mkr_ether_patrol3", "mkr_ether_patrol4", "mkr_ether_patrol5", "mkr_ether_patrol6"}
g_ether_patrol_waypoints = table.getn(t_tau_ether_patrol_waypoints)


--[[generates a list and a count of spawn points for the tau stealth suits]]
t_tau_stealth_spawns = {"mkr_tau_stealth_spawn1", "mkr_tau_stealth_spawn2", "mkr_tau_stealth_spawn3", "mkr_tau_stealth_spawn4", "mkr_tau_stealth_spawn5", 
										  "mkr_tau_stealth_spawn6", "mkr_tau_stealth_spawn7", "mkr_tau_stealth_spawn8", "mkr_tau_stealth_spawn9", "mkr_tau_stealth_spawn10",
										  "mkr_tau_stealth_spawn11", "mkr_tau_stealth_spawn12", "mkr_tau_stealth_spawn13", "mkr_tau_stealth_spawn14", "mkr_tau_stealth_spawn15",
										  "mkr_tau_stealth_spawn16", "mkr_tau_stealth_spawn17", "mkr_tau_stealth_spawn18", "mkr_tau_stealth_spawn19", "mkr_tau_stealth_spawn20",
										  "mkr_tau_stealth_spawn21", "mkr_tau_stealth_spawn22", "mkr_tau_stealth_spawn23", "mkr_tau_stealth_spawn24", "mkr_tau_stealth_spawn25",
										  "mkr_tau_stealth_spawn26", "mkr_tau_stealth_spawn27", "mkr_tau_stealth_spawn28", "mkr_tau_stealth_spawn29", "mkr_tau_stealth_spawn30",
										  "mkr_tau_stealth_spawn31", "mkr_tau_stealth_spawn32", "mkr_tau_stealth_spawn33", "mkr_tau_stealth_spawn34", "mkr_tau_stealth_spawn35"}

g_tau_stealth_spawn_count = table.getn(t_tau_stealth_spawns)

--[[generates a list and a count of spawn points for the tau crisis suits]]
t_tau_crisis_spawns = {"mkr_tau_crisis_spawn1", "mkr_tau_crisis_spawn2", "mkr_tau_crisis_spawn3", "mkr_tau_crisis_spawn4", "mkr_tau_crisis_spawn5", 
										  "mkr_tau_crisis_spawn6", "mkr_tau_crisis_spawn7", "mkr_tau_crisis_spawn8", "mkr_tau_crisis_spawn9", "mkr_tau_crisis_spawn10",}
g_tau_crisis_spawn_count = table.getn(t_tau_crisis_spawns)			

--[[flag that tells the game that a group of the player's army has been grouped into an SGroup that will trigger an ambush]] 
g_player_pursuer_activated = false

--[[random tau attack composition]]
t_attack_vector_composition = {"tau_kroot_carnivore_squad", "tau_fire_warrior_squad", "tau_fire_warrior_squad"}

--[[allows random attack to occur]]
g_random_attack_on = false

--[[attack waves number set]]
g_waves = 0


--[[table that contains information about the bases that the player can potentially occupy, and their capture status]]
t_bases_of_operation = {
				
					areaname = {"mkr_tau_outpost1_area", "mkr_tau_outpost2_area", "mkr_tau_outpost3_area", "mkr_tau_outpost4_area","mkr_tau_outpost5_area", "mkr_tau_outpost6_area","mkr_start"},-- originally 4 areas
					
					spawnspot = {"mkr_tau_outpost1_counter_spawn", "mkr_tau_outpost2_counter_spawn", "mkr_tau_outpost3_counter_spawn", "mkr_tau_outpost4_counter_spawn", "mkr_tau_outpost5_counter_spawn", "mkr_tau_outpost6_counter_spawn", "mkr_start"},
					
					flags = {"eg_flag1", "eg_flag2", "eg_flag3", "eg_flag4", "eg_flag5", "eg_flag6", "eg_flag7"},
					
					areacapturedbyplayer = {false--[[outpost1]], false--[[outpost2]], false--[[outpost3]], false--[[outpost4]], false--[[outpost5]], false--[[outpost6]], false--[[main area]]},
					
					constructionbuildings= {"eg_tau_construction1", "eg_tau_construction2", "eg_tau_construction3", "eg_tau_construction4", "eg_tau_construction5", "eg_tau_construction6", "eg_tau_does_not_exist"},
					
					vehicles = {"mkr_outpost1_vehicle_spawn", "mkr_outpost2_vehicle_spawn", "mkr_outpost3_vehicle_spawn", "mkr_outpost4_vehicle_spawn", "mkr_outpost5_vehicle_spawn", "mkr_outpost6_vehicle_spawn", "mkr_start"},
					
					flag_names = {"mkr_tau_outpost1_area", "mkr_tau_outpost2_area", "mkr_tau_outpost3_area", "mkr_tau_outpost4_area","mkr_tau_outpost5_area", "mkr_tau_outpost6_area", "mkr_start"},-- originally 4 areas
					
					capture_status = {2, 2, 2, 2, 2, 2, 1}, -- 1 = player 1, 2 = player 2, etc.

}	

--[[table that contains information about the counterattack squads sent at the player]]
t_tau_counterattack_data = {
			
			plaza_composition1 = {"tau_fire_warrior_squad", "tau_crisis_suit_squad", "tau_stealth_team_squad"},
			plaza_composition2 = {"tau_kroot_carnivore_squad", "tau_kroot_carnivore_squad", "tau_kroot_hound_squad"}, -- no more tau_eviscerator
			
			
			easy_composition = {"tau_fire_warrior_squad", "tau_kroot_carnivore_squad"}, --, "tau_eviscerator_squad", "tau_stealth_team_squad"
			
			composition = {"tau_fire_warrior_squad", "tau_fire_warrior_squad", "tau_kroot_carnivore_squad", "tau_crisis_suit_squad","tau_kroot_hound_squad"}, 
			
			composition2 = {"tau_fire_warrior_squad", "tau_fire_warrior_squad", "tau_crisis_suit_squad", "tau_stealth_team_squad","tau_kroot_carnivore_squad"}, -- not stealth team, so firewarrior twice to make it more probable.  This is for when Kroot production is gone.
			
			composition3 = {"tau_kroot_carnivore_squad", "tau_kroot_carnivore_squad", "tau_fire_warrior_squad", "tau_kroot_hound_squad", "tau_kroot_hound_squad"}, -- squads duplicated to make it so that they have a higher chance of being used
			
			--composition3 = {"tau_fire_warrior_squad"},
			
			composition4 = {"tau_fire_warrior_squad", "tau_vespid_auxillary_squad", "tau_energy_auxillary_squad"},
			
			composition5 = {"tau_fire_warrior_squad", "tau_kroot_carnivore_squad"},
			
			composition6 = {"tau_kroot_carnivore_squad", "tau_fire_warrior_squad"},
			
			composition7 = {"tau_fire_warrior_squad", "tau_stealth_team_squad", "tau_kroot_carnivore_squad", "tau_kroot_hound_squad"},
			
			citadel_composition = {"tau_fire_warrior_squad", "tau_pathfinder_squad"},
			
			names = {"sg_tau_counterattack1", "sg_tau_counterattack2", "sg_tau_counterattack3", "sg_tau_counterattack4", "sg_tau_counterattack5", "sg_tau_counterattack6", "sg_tau_counterattack7"},
			
			major_names = {"sg_tau_counterattack1", "sg_tau_counterattack2", "sg_tau_counterattack3", "sg_tau_counterattack4","sg_tau_counterattack5", "sg_tau_counterattack6","sg_tau_counterattack7"},
			
			minor_names = {"sg_tau_minor_counterattack1", "sg_tau_minor_counterattack2", "sg_tau_minor_counterattack3", "sg_tau_minor_counterattack4", "sg_tau_minor_counterattack5", "sg_tau_minor_counterattack6", "sg_tau_minor_counterattack7"},
			
			
			playersquadcount = {0, 0, 0, 0, 0, 0, 0},
			squadsize = {
						{3, 4, 5}, -- 3, 3, 4
						{3, 4, 5}, 
						{3, 4, 5}, 
						{3, 4, 5},
						{3, 4, 5},
						{3, 4, 5},
						{3, 4, 5}
}}


-- keeps track of the names of captured flags for the various Tau outposts
t_tau_capture_flags = {"eg_capture_flag1", "eg_capture_flag2", "eg_capture_flag3", "eg_capture_flag4", "eg_capture_flag5"}
t_tau_capture_flags_markers = {"mkr_tau_capture_ping1", "mkr_tau_capture_ping2", "mkr_tau_capture_ping3", "mkr_tau_capture_ping4", "mkr_tau_capture_ping5"}

--flag capture status
t_flag_captured = {false, false, false, false, false} -- unity plaza flag is different

t_tau_listening_posts = {"eg_tau_listening_post1", "eg_tau_listening_post2", "eg_tau_listening_post3", "eg_tau_listening_post4", "eg_tau_listening_post5", 
										"eg_tau_listening_post6", "eg_tau_listening_post7", "eg_tau_listening_post8"}

--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_target_flag = ""

g_target2 = ""
g_target2_flag = ""

g_citadel_random_squads = 1

g_bases_captured = 0

g_citadel_counterattack_sent = false

g_citadel_last_stand = false

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

g_kauyon_destroyed = false

g_montka_destroyed = false

g_composition_type = t_tau_counterattack_data.easy_composition
--g_composition_type = t_tau_counterattack_data.composition

g_counterattack_unit_composition = t_tau_counterattack_data.easy_composition

g_stop_counterattacks = false

g_vehicle_type = 0 -- 0 = Hammerhead and Knarlocs, 1 = neither, 2 = Hammerheads only, 3 = knarloc

g_honour_guard5_jumped = false

g_honour_guard6_jumped = false

g_honour_guard12_jumped = false

g_honour_guard13_jumped = false

g_protect_ethereal_speech = false

g_Timer = 0

g_plaza_captured = false

g_comm_tower_time = 0

g_comm_tower_initial = true

g_button_on = true

g_detector_planted = false

g_detector_count = 0

g_button_pressed_first_time = true

g_player_race_type = ""

t_player_captured_major_flags = {"eg_flag7"}
t_player_captured_minor_flags = {}
t_player_captured_major_names = {"mkr_start"}
t_player_captured_minor_names = {}
t_tau_captured_major_flags = {"eg_flag1", "eg_flag2", "eg_flag3", "eg_flag4", "eg_flag5", "eg_flag6"}
--t_tau_captured_major_names = {"mkr_tau_outpost1_area", "mkr_tau_outpost2_area", "mkr_tau_outpost3_area", "mkr_tau_outpost4_area", "mkr_tau_outpost5_area", "mkr_tau_outpost6_area"}
t_tau_captured_major_names = {"mkr_tau_outpost1_counter_spawn", "mkr_tau_outpost2_counter_spawn", "mkr_tau_outpost3_counter_spawn", "mkr_tau_outpost4_counter_spawn", "mkr_tau_outpost5_counter_spawn", "mkr_tau_outpost6_counter_spawn"}
--t_tau_captured_minor_flags = {"eg_minor_flag1", "eg_minor_flag2", "eg_minor_flag3", "eg_minor_flag4", "eg_minor_flag5"}
--t_tau_captured_minor_names = {"mkr_outpost1", "mkr_outpost2", "mkr_outpost3", "mkr_outpost4", "mkr_outpost5"}
t_non_tau_captured_major_flags = {}
t_non_tau_captured_major_names = {}
t_non_tau_captured_minor_flags = {}
t_non_tau_captured_minor_names = {}
t_tau_captured_vehicle_names = {"mkr_outpost1_vehicle_spawn", "mkr_outpost2_vehicle_spawn", "mkr_outpost3_vehicle_spawn", "mkr_outpost4_vehicle_spawn", "mkr_outpost5_vehicle_spawn", "mkr_outpost6_vehicle_spawn"}
t_player_captured_vehicle_names = {"mkr_start"}	
-- need to check for if marker exists

t_ethereal_blueprint =  Util_MakeBlueprintTable( "tau_ethereal_squad_stronghold_sp")

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_time_elapsed = 0

--g_counterattack_unit_composition = t_tau_counterattack_data.composition

g_stop_vehicles = false

g_tower_animation_played = false

g_patrol1_ready = true

g_patrol2_ready = true

g_spawn_patrol1_iter = 1

g_spawn_patrol2_iter = 1

g_comm_tower_count = 0


g_citadel_delay_counter = 0

g_citadel_delay_counter_flag = true

g_player_unit_count = 0

g_initial_delay_counter = 0

g_mid_nis_played = 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)))


-- 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 = 10
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_large_TBASE + math.floor((g_difficulty - g_DBASE) * ((g_time_TMAX - g_time_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()

--set the music	
t_tau_stronghold_music = {"MU_IG_STR_Tau", "MU_IG_RAC_Tau", "MU_IG_STR_Tau_perc", "MU_IG_STR_Tau_perc_str", "MU_IG_STR_Tau_perc_brass"}
--t_tau_stronghold_music = {"music_ms03"}

-- Sound_PlaylistClear(PC_Music) Playlist_Manager( PC_Music, t_tau_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, 2500, 750)
	--Player_SetAllResources(g_Player1, 1000, 100)
	
	--[[ 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 Tau Army]]	
	--Rule_AddOneShot(Rule_Player_Army_Kickoff, 0)		
	Rule_AddOneShot(Rule_Create_Player_Buildings_And_Squads, 1)
	Rule_AddOneShot(Rule_Tau_Army_Kickoff, 0)		
	--Rule_AddOneShot(Rule_Tau_Patrol1_Kickoff, 0)
	--Rule_AddOneShot(Rule_Tau_Patrol2_Kickoff, 0)
	
	Rule_AddInterval(Rule_Tau_Patrol1_Kickoff, 1) -- interval is 1 second to quickly spawn the initial units
	Rule_AddInterval(Rule_Tau_Patrol2_Kickoff, 1) -- interval is 1 second to quickly spawn the initial units
	
	
	Rule_AddIntervalDelay(Rule_Tau_Patrol1, 15, 10)
	Rule_AddIntervalDelay(Rule_Tau_Patrol2, 15, 11)
	Rule_AddIntervalDelay(Rule_Ether_Patrol, 2, 13)
	
	Rule_AddIntervalDelay(Rule_Ambush_Control1, 1, 2)
	Rule_AddIntervalDelay(Rule_Ambush_Control2, 1, 3)
	Rule_AddIntervalDelay(Rule_Ambush_Control3, 1, 4)
	Rule_AddIntervalDelay(Rule_Ambush_Control4, 1, 5)
	
	--timer for testing
	Rule_AddOneShot(Rule_Add_Timer, 1) 
	
	Rule_AddOneShot(Rule_Add_Seconds, 1)]]
	
	g_firstrun = false
	

	
elseif Event_IsAnyRunning() == false then		
	
	
	--Rule_AddIntervalDelay(Rule_Random_Speech_KickOff, 1, 1)
	--Rule_AddIntervalDelay(Rule_Random_Speech_Activation, 1, 1)
	
	Rule_AddIntervalDelay(Rule_Count_Player_Units, 1, 1)
	Rule_AddIntervalDelay(Rule_Ownership_Check, 1, 1)
	
	
	Rule_AddIntervalDelay(Rule_Play_Race_Specific_Opening_Text, 1, 10) -- Rule_AddOneShot(Rule_IE_Build_Detectors, 10)
	
	
	Rule_AddInterval(Rule_Ethereal_Protection, 2)
	
	-- should give the player enough time to build up a little defense
	Rule_AddIntervalDelay(Rule_Counterattack_Activation, 10, 120)
	Rule_AddIntervalDelay(Rule_Citadel_Threshold, 10, 101)
	--Rule_AddOneShot(Rule_Initial_Attack, 30)
	
	--Rule_AddIntervalDelay(Rule_Citadel_Counterattack_Activation, 10, 100)
	
	--Rule_AddIntervalDelay(Rule_Create_Tau_Counterattack_Armies, 10, 2)

	--Rule_AddInterval(Rule_Outer_Bases_Taken_Over_Autosave_Check, 1)
	
	
	--Rule_AddInterval(Rule_Secondary_Objective_Tracker, 1)
	Rule_AddInterval(Rule_Early_Composition_Set, 1)
	Rule_AddInterval(Rule_Composition_And_Secondary_Objective_Tracker, 1)
	
	--[[ Set up a Win Check ]]
	Rule_AddInterval(Rule_EndGameWin, 5)
	
	--[[ Set up a Lose Check ]]
	Rule_AddInterval(Rule_EndGameLose, 5)
	
	
	--[[ Assigning objectives]]
	
	
	Rule_AddIntervalDelay(Rule_Objective_Kill_Ethereal, 1, 4)
	--Rule_AddIntervalDelay(Rule_Objective_Capture_Defense_Stations, 1, 10)
	
	--Rule_AddInterval(Rule_Unity_Plaza_Objective_Start, 1)
	Rule_AddInterval(Rule_Comm_Tower_Objective_Start, 1)
	
	Rule_AddInterval(Rule_Plaza_Captured_Detect, 1)
	
	--Shrine destruction objectives and text
			
	
	Rule_AddOneShot(Rule_IE_Shrine_Objective_Given, 90)
	
	
	Rule_AddIntervalDelay(Rule_Objective_Destroy_Kauyon_Shrine, 1, 100)
	--Rule_AddIntervalDelay(Rule_Objective_Destroy_Montka_Shrine, 1, 101)
	
	--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)

--[[ Types of things that can be 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)	

--[[
Cpu_Enable(g_Player2, true)	

Cpu_EnableComponent(g_Player2, false, CT_Resourcing)
Cpu_EnableComponent(g_Player2, false, CT_BuildBuildings)
Cpu_EnableComponent(g_Player2, false, CT_BuildUnits)
Cpu_EnableComponent(g_Player2, false, CT_BuildResearch)
Cpu_EnableComponent(g_Player2, false, CT_BuildAddOns)
Cpu_EnableComponent(g_Player2, true, CT_Tactics)]]

end


--[[ CORE GAME ]]


--[[ PLAYER ARMY ]]

function Rule_Create_Player_Buildings_And_Squads()

MetaMap_UpdatePlayerWargear(g_Player1)

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
	--[[
	for i = 1, table.getn(t_Player_Units.chaos_unit_name) do
		Util_CreateSquadsAtMarkerEx(g_Player1, t_Player_Units.chaos_unit_name[i], t_Player_Units.chaos_unit_type[i], t_Player_Units.chaos_unit_spawn[i], t_Player_Units.chaos_unit_squad_numbers[i], t_Player_Units.chaos_unit_population[i])
	end]]
	
	g_Leader_Type = "chaos_squad_lord"
	g_Leader_Bonus_Type = "chaos_squad_lord_advance_sp"
	
	g_player_race_type = "chaos_marine_race"
	
	t_building_exceptions = {
	"chaos_thermo_plasma_generator",
	"chaos_plasma_generator",
	"chaos_turret_bolter",
	"chaos_mine_field"}
	
	t_unit_exceptions = {}
	
	
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
	--[[
	for i = 1, table.getn(t_Player_Units.eldar_unit_name) do
		Util_CreateSquadsAtMarkerEx(g_Player1, t_Player_Units.eldar_unit_name[i], t_Player_Units.eldar_unit_type[i], t_Player_Units.eldar_unit_spawn[i], t_Player_Units.eldar_unit_squad_numbers[i], t_Player_Units.eldar_unit_population[i])
	end]]
	
	g_Leader_Type = "eldar_squad_farseer"
	g_Leader_Bonus_Type = "eldar_squad_farseer_advance_sp"
			
	g_player_race_type = "eldar_race"
	
	--win/loss
	t_building_exceptions = {
	"eldar_advanced_warp_generator",
	"eldar_warp_generator",
	"eldar_support_platform_scatterlaser",
	"eldar_mine_field"}
	
	t_unit_exceptions = {}
	
	
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
	--[[
	for i = 1, table.getn(t_Player_Units.guard_unit_name) do
		Util_CreateSquadsAtMarkerEx(g_Player1, t_Player_Units.guard_unit_name[i], t_Player_Units.guard_unit_type[i], t_Player_Units.guard_unit_spawn[i], t_Player_Units.guard_unit_squad_numbers[i], t_Player_Units.guard_unit_population[i])
	end]]
	
	g_Leader_Type = "guard_squad_command_squad"
	g_Leader_Bonus_Type = "guard_squad_command_squad_advance_sp"
	
	
	g_player_race_type = "guard_race"
	
	--win/loss
	t_building_exceptions = {
	"guard_thermo_plasma",
	"guard_plasma_generator",
	"guard_turret_heavy_bolter",
	"guard_mines"}
	
	t_unit_exceptions = {}
	
	
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
	--[[
	for i = 1, table.getn(t_Player_Units.ork_unit_name) do
		Util_CreateSquadsAtMarkerEx(g_Player1, t_Player_Units.ork_unit_name[i], t_Player_Units.ork_unit_type[i], t_Player_Units.ork_unit_spawn[i], t_Player_Units.ork_unit_squad_numbers[i], t_Player_Units.ork_unit_population[i])
	end]]
	
	
	g_Leader_Type = "ork_squad_warboss"
	g_Leader_Bonus_Type = "ork_squad_warboss_advance_sp"
	
	g_player_race_type = "ork_race"
	
	--win/loss
	t_building_exceptions = {
	"ork_bigger_generator",
	"ork_generator",
	"ork_waagh_banner",
	"ork_mine_field"}
	
	t_unit_exceptions = {}
	
		
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
	--[[
	for i = 1, table.getn(t_Player_Units.marines_unit_name) do
		Util_CreateSquadsAtMarkerEx(g_Player1, t_Player_Units.marines_unit_name[i], t_Player_Units.marines_unit_type[i], t_Player_Units.marines_unit_spawn[i], t_Player_Units.marines_unit_squad_numbers[i], t_Player_Units.marines_unit_population[i])
	end]]
	
	g_Leader_Type = "space_marine_squad_force_commander"
	g_Leader_Bonus_Type = "space_marine_squad_force_commander_advance_sp"
	
	g_player_race_type = "space_marine_race"
	
	--win/loss
	t_building_exceptions = {
	"space_marine_thermo_generator",
	"space_marine_generator",
	"space_marine_turret_bolter",
	"space_marine_mine_field"}
	
	t_unit_exceptions = {}
	
	
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
	--[[
	for i = 1, table.getn(t_Player_Units.tau_unit_name) do
		Util_CreateSquadsAtMarkerEx(g_Player1, t_Player_Units.tau_unit_name[i], t_Player_Units.tau_unit_type[i], t_Player_Units.tau_unit_spawn[i], t_Player_Units.tau_unit_squad_numbers[i], t_Player_Units.tau_unit_population[i])
	end]]
	
	g_Leader_Type = "tau_commander_squad"
	g_Leader_Bonus_Type = "tau_commander_squad_advance_sp"
	
	g_player_race_type = "tau_race"
	
	--win/loss
	t_building_exceptions = {
	"tau_thermoplasma_generator",
	"tau_plasma_generator",}
	
	t_unit_exceptions = {}
	
	
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
	
	--[[
	for i = 1, table.getn(t_Player_Units.necron_unit_name) do
		Util_CreateSquadsAtMarkerEx(g_Player1, t_Player_Units.necron_unit_name[i], t_Player_Units.necron_unit_type[i], t_Player_Units.necron_unit_spawn[i], t_Player_Units.necron_unit_squad_numbers[i], t_Player_Units.necron_unit_population[i])
	end]]
	
	g_Leader_Type = "necron_lord_squad"		
	g_Leader_Bonus_Type = "necron_lord_squad_advance_sp"		
	
	g_player_race_type = "necron_race"
	
	--win/loss
	t_building_exceptions = {
	"necron_thermoplasma_generator",
	"necron_plasma_generator",
	"necron_turret",}
	
	t_unit_exceptions = {}
	
	
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

t_blueprintleader = Util_MakeBlueprintTable(g_Leader_Type)
t_advanced_blueprintleader = Util_MakeBlueprintTable(g_Leader_Bonus_Type)





--Rule_AddOneShot(Rule_Create_Enemy_Bonus_Squads, 1)

Rule_Remove(Rule_Create_Player_Buildings_And_Squads)

--[[ --for testing purposes]] --Util_CreateSquadsAtMarkerEx(g_Player1, "sg_initial_force4", "space_marine_squad_land_raider", "mkr_start", 12, 2) --Util_CreateSquadsAtMarkerEx(g_Player1, "sg_initial_force4", "space_marine_squad_land_raider", "mkr_tau_outpost1_area", 12, 2) --Util_CreateSquadsAtMarkerEx(g_Player1, "sg_initial_transport", "space_marine_squad_rhino", "mkr_tau_outpost1_area", 1, 1)

end

--[[ function Rule_Player_Army_Kickoff() -- for testing purposes

Util_CreateSquadsAtMarkerEx(g_Player1, "sg_initial_force1", "space_marine_squad_tactical", "mkr_player_spawn1", 1, 8)
Util_CreateSquadsAtMarkerEx(g_Player1, "sg_initial_force2", "space_marine_squad_scout", "mkr_player_spawn2", 1, 4)
Util_CreateSquadsAtMarkerEx(g_Player1, "sg_initial_force3", "space_marine_squad_tactical", "mkr_player_spawn3", 1, 8)
--SGroup_AddLeaders("sg_initial_force")
--Util_CreateSquadsAtMarkerEx(g_Player1, "sg_initial_force4", "space_marine_squad_land_raider", "mkr_start", 10, 2)

Util_CreateSquadsAtMarkerEx(g_Player1, "sg_initial_builders", "space_marine_squad_servitor", "mkr_player_builder_spawn", 2, 1)
Util_CreateSquadsAtMarkerEx(g_Player1, "sg_initial_transport", "space_marine_squad_rhino", "mkr_player_vehicle_spawn", 1, 1)
Util_CreateSquadsAtMarkerEx(g_Player1, "sg_initial_tank", "space_marine_squad_predator", "mkr_player_vehicle_spawn", 2, 1)

end]]

--[[Kicks off the Tau opposition]] function Rule_Tau_Army_Kickoff()

--- MAKES COMM TOWER DEACTIVATED AT THE BEGINNING!
Anim_PlayEGroupAnim(EGroup_FromName("eg_comm_tower"), "sp_de_activation")
EGroup_SetPlayerOwner("eg_comm_tower", g_Player2)

--Player_GrantResearch( g_Player2, "tau_improved_metallurgy")

-- generates stealth suit units at each of the spawns set aside for stealth suit units

Player_GrantResearch(g_Player2, "tau_stealth_suit_damage_research")
Player_GrantResearch(g_Player2, "tau_improved_power_source_research")
--Player_GrantResearch(g_Player2, "tau_targeting_optics")
Player_GrantResearch(g_Player2, "tau_target_lock")
Player_GrantResearch(g_Player2, "tau_teachings_of_montka_research")
Player_GrantResearch(g_Player2, "tau_teachings_of_kauyon_research")
--Player_GrantResearch(g_Player2, "tau_missile_barrage_research")


for i = 1, g_tau_stealth_spawn_count do
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_stealth_defender"..i, "tau_stealth_team_squad", t_tau_stealth_spawns[i], 1,	g_small_deployment_size)
	SGroup_AddLeaders("sg_tau_stealth_defender"..i)
	--FOW_TagSGroup(g_Player1, SGroup_FromName("sg_tau_stealth_defender"..i))
	--Util_CreateSquadsAtMarkerEx(g_Player1, "sg_player1_detector"..i, "npc_infiltration_spotter", t_tau_stealth_spawns[i], 1, 1)
end

--test
--Entity_CreateBuildingMarker(g_Player1, "eg_detector", "npc_infiltration_spotter", "mkr_test_spawn", 1)

-- generates crisis suit units at each of the spawns set aside for crisis units for i = 1, g_tau_crisis_spawn_count do Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_crisis_defender"..i, "tau_crisis_suit_squad_stronghold_sp", t_tau_crisis_spawns[i], 1, 1)

	--for n = 1, SGroup_Count(SGroup_FromName("sg_tau_crisis_defender"..i)) do
		Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_tau_crisis_defender"..i), 1), "tau_missile_pod_crisis_suit", 1)
		--Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_tau_crisis_defender"..i), 1), "tau_fusion_blaster_crisis_suit", 1)
	--end
	
	SGroup_AddLeaders("sg_tau_crisis_defender"..i)
	
end

--generates ethereal Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_commander", "tau_commander_squad_advance_sp", "mkr_tau_commander_spawn", 1,1) --Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_tau_commander"), 1),"tau_commander_jetpack", 1) Player_GrantResearch(g_Player2, "tau_wargear_upgrade_07_jetpack_research")

--[[
for i = 1, SGroup_Count(SGroup_FromName("sg_tau_commander")) do
	Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_tau_commander"), i), "tau_fusion_blaster_commander", 1)
	Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_tau_commander"), i), "tau_missile_launcher_commander", 1)
	Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_tau_commander"), i), "tau_flamer_commander", 1)
end]]


Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_ethereal", "tau_ethereal_squad_stronghold_sp", "mkr_tau_ethereal_spawn", 1,1)
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_ethereal_retinue", "tau_honor_guard_fire_warrior_squad_stronghold_sp", "mkr_tau_ethereal_spawn", 1, g_med_deployment_size)
Cmd_AttachSquads("sg_tau_ethereal_retinue", "sg_tau_ethereal" )
SGroup_AddGroup(SGroup_FromName("sg_tau_ethereal"), SGroup_FromName("sg_tau_ethereal_retinue"))

--generates ethereal bodyguards Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_honour_guard1a", "tau_honor_guard_fire_warrior_squad_stronghold_sp", "mkr_honour1", 1, g_body_deployment_size) SGroup_AddLeaders("sg_tau_honour_guard1a")

Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_honour_guard1b", "tau_honor_guard_fire_warrior_squad_stronghold_sp", "mkr_honour2", 1, g_body_deployment_size)
SGroup_AddLeaders("sg_tau_honour_guard1b")


Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_honour_guard2", "tau_fire_warrior_squad", "mkr_bodyguard_start_area3", 1, g_body_deployment_size)
SGroup_AddLeaders("sg_tau_honour_guard2")

Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_honour_guard3", "tau_fire_warrior_squad", "mkr_bodyguard_start_area2", 1, g_body_deployment_size)
SGroup_AddLeaders("sg_tau_honour_guard3")

Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_honour_guard4", "tau_honor_guard_crisis_suit_squad_advance_sp", "mkr_bodyguard_start_area", g_small_deployment_size, 1)
--Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_tau_honour_guard4"), 1), "tau_fusion_blaster_crisis_suit", 1)


Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_honour_guard5", "tau_honor_guard_crisis_suit_squad_advance_sp", "mkr_bodyguard_crisis1", g_small_deployment_size, 1)
--Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_tau_honour_guard5"), 1), "tau_fusion_blaster_crisis_suit", 1)

Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_honour_guard6", "tau_honor_guard_crisis_suit_squad_advance_sp", "mkr_bodyguard_crisis2", g_small_deployment_size, 1)
--Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_tau_honour_guard6"), 1), "tau_fusion_blaster_crisis_suit", 1)


Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_honour_guard7", "tau_vespid_auxiliary_squad", "mkr_bodyguard_spawn1", 2, g_med_deployment_size)
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_honour_guard8", "tau_honor_guard_stealth_suit_squad_advance_sp", "mkr_honour_stealth_spawn1", 1, g_med_deployment_size)
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_honour_guard9", "tau_honor_guard_stealth_suit_squad_advance_sp", "mkr_honour_stealth_spawn2", 1, g_med_deployment_size)
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_honour_guard10", "tau_honor_guard_stealth_suit_squad_advance_sp", "mkr_honour_stealth_spawn3", 1, g_med_deployment_size)
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_honour_guard11", "tau_honor_guard_stealth_suit_squad_advance_sp", "mkr_bodyguard_spawn1", 1, g_med_deployment_size)

Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_honour_guard12", "tau_honor_guard_crisis_suit_squad_advance_sp", "mkr_bodyguard_crisis3", g_small_deployment_size, 1)
--Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_tau_honour_guard12"), 1), "tau_fusion_blaster_crisis_suit", 2)
Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_tau_honour_guard12"), 1), "tau_flamer_crisis_suit", 1)

Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_honour_guard13", "tau_honor_guard_crisis_suit_squad_advance_sp", "mkr_bodyguard_crisis4", g_small_deployment_size, 1)
--Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_tau_honour_guard13"), 1), "tau_fusion_blaster_crisis_suit", 1)
Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_tau_honour_guard13"), 1), "tau_flamer_crisis_suit", 1)

Util_CreateSquadsAtMarker(g_Player2, "sg_tau_honour_vehicle1", "tau_hammerhead_gunship_squad", "mkr_bodyguard_vehicles1", 1)
Util_CreateSquadsAtMarker(g_Player2, "sg_tau_honour_vehicle2", "tau_hammerhead_gunship_squad", "mkr_bodyguard_vehicles2", 1)
Util_CreateSquadsAtMarker(g_Player2, "sg_tau_honour_vehicle3", "tau_hammerhead_gunship_squad", "mkr_bodyguard_vehicles3", 1)
Util_CreateSquadsAtMarker(g_Player2, "sg_tau_honour_vehicle4", "tau_hammerhead_gunship_squad", "mkr_bodyguard_vehicles4", 1)
Util_CreateSquadsAtMarker(g_Player2, "sg_tau_honour_vehicle5", "tau_skyray_squad", "mkr_bodyguard_vehicles5", 1)
Util_CreateSquadsAtMarker(g_Player2, "sg_tau_honour_vehicle6", "tau_skyray_squad", "mkr_bodyguard_vehicles6", 1)

Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_broadside_guard1", "tau_broadside_battlesuit_squad", "mkr_citadel_broadside_spawn1", 1, g_small_deployment_size)
Cmd_SquadEntrench("sg_tau_broadside_guard1")
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_broadside_guard2", "tau_broadside_battlesuit_squad", "mkr_citadel_broadside_spawn2", 1, g_small_deployment_size)
Cmd_SquadEntrench("sg_tau_broadside_guard2")

--generates the tau bait units Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_bait1", "tau_fire_warrior_squad", "mkr_bait1_start", 1, g_med_deployment_size) SGroup_AddLeaders("sg_tau_bait1") Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_bait2", "tau_fire_warrior_squad", "mkr_bait2_start", 1, g_med_deployment_size) SGroup_AddLeaders("sg_tau_bait2")

--generates an ambush near east bridge Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_ambush2_kroot1", "tau_kroot_carnivore_squad", "mkr_kroot_ambush_spawn1", 1,g_med_deployment_size) Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_ambush2_kroot2", "tau_kroot_hound_squad", "mkr_kroot_ambush_spawn1", 2, g_med_deployment_size) Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_ambush2_kroot3", "tau_kroot_carnivore_squad", "mkr_kroot_ambush_spawn2", 1,g_med_deployment_size) Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_ambush2_kroot4", "tau_kroot_hound_squad", "mkr_kroot_ambush_spawn2", 2, g_med_deployment_size) Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_ambush2_vehicle1", "tau_skyray_squad", "mkr_ambush2_vehicle1", 1, 1) Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_ambush2_vehicle2", "tau_skyray_squad", "mkr_ambush2_vehicle2", 1, 1)

SGroup_CreateIfNotFound("sg_tau_ambush2")
SGroup_CreateIfNotFound("sg_tau_ambush2_vehicles")

for n = 1, 4 do
	SGroup_AddGroup(SGroup_FromName("sg_tau_ambush2"), SGroup_FromName("sg_tau_ambush2_kroot"..n))
end

SGroup_AddGroup(SGroup_FromName("sg_tau_ambush2_vehicles"), SGroup_FromName("sg_tau_ambush2_vehicle1"))
SGroup_AddGroup(SGroup_FromName("sg_tau_ambush2_vehicles"), SGroup_FromName("sg_tau_ambush2_vehicle2"))

--generates tau relic defenders

Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_relic_defender1", "tau_fire_warrior_squad", "mkr_relic_defender1", 2, g_med_deployment_size)
SGroup_AddLeaders("sg_tau_relic_defender1")
--SGroup_AddLeadersAtIndex("sg_tau_relic_defender1", 2)

Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_relic_defender2", "tau_fire_warrior_squad", "mkr_relic_defender2", 2, g_med_deployment_size)
SGroup_AddLeaders("sg_tau_relic_defender2")

Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_relic_defender3", "tau_broadside_battlesuit_squad", "mkr_relic_defender3", 1, g_small_deployment_size)
SGroup_AddLeaders("sg_tau_relic_defender3")
Cmd_SquadEntrench("sg_tau_relic_defender3")

Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_relic_defender4", "tau_broadside_battlesuit_squad", "mkr_relic_defender4", 1, g_small_deployment_size)
SGroup_AddLeaders("sg_tau_relic_defender4")
Cmd_SquadEntrench("sg_tau_relic_defender4")

--generates tau knarloc Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_knarloc1", "tau_greater_knarloc_squad", "mkr_knarloc_spawn1", 1, 1) Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_knarloc1_keepers", "tau_kroot_carnivore_squad", "mkr_knarloc_spawn1", 2, g_med_deployment_size) Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_knarloc2", "tau_greater_knarloc_squad", "mkr_knarloc_spawn2", 1, 1) Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_knarloc2_keepers", "tau_kroot_carnivore_squad", "mkr_knarloc_spawn2", 2, g_med_deployment_size)

--generates tau citadel defenders Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_citadel_defender1", "tau_fire_warrior_squad", "mkr_citadel_fire_warrior1", 1, g_med_deployment_size) SGroup_AddLeaders("sg_tau_citadel_defender1") Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_citadel_defender2", "tau_fire_warrior_squad", "mkr_citadel_fire_warrior2", 1, g_med_deployment_size) SGroup_AddLeaders("sg_tau_citadel_defender2")

Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_kroot_citadel_defender1", "tau_kroot_alpha_squad_advance_sp", "mkr_kroot_alpha1", 1, g_med_deployment_size)
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_kroot_citadel_defender2", "tau_kroot_alpha_squad_advance_sp", "mkr_kroot_alpha2", 1, g_med_deployment_size)

Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_citadel_skyray1", "tau_skyray_squad", "mkr_tau_citadel_skyray_spawn1", 1, 1)
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_citadel_skyray2", "tau_skyray_squad", "mkr_tau_citadel_skyray_spawn2", 1, 1)

for x = 1,4 do
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_citadel_hammerhead"..x, "tau_hammerhead_gunship_squad", "mkr_tau_citadel_hammerhead_spawn"..x, 1, 1)
end

--generates tau outpost defenders

for i = 1, 6 do
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_outpost"..i.."_defender1", "tau_fire_warrior_squad", "mkr_outpost"..i.."_guards", 2, g_med_deployment_size) --"mkr_tau_outpost"..i.."_area"
	
	--SGroup_AddLeaders("sg_tau_outpost"..i.."_defender1")
	
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_outpost"..i.."_defender2", "tau_kroot_carnivore_squad", "mkr_outpost"..i.."_kroot", 2, g_large_deployment_size) -- "mkr_tau_outpost"..i.."_area"
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_outpost"..i.."_vehicle1", "tau_skyray_squad", "mkr_tau_outpost"..i.."_skyray1", 1, 1)
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_outpost"..i.."_vehicle2", "tau_hammerhead_gunship_squad", "mkr_tau_outpost"..i.."_hammerhead1", 1, 1)
end


Rule_AddIntervalDelay(Rule_Tau_Base_Defender1_Movement, 45, 40)
Rule_AddIntervalDelay(Rule_Tau_Base_Defender2_Movement, 45, 50)

--generates kroot for a kroot ambush Util_CreateSquadsAtMarkerEx(g_Player2, "sg_kroot_ambush1", "tau_kroot_carnivore_squad", "mkr_kroot_ambush_spawn", 1, g_large_deployment_size) Util_CreateSquadsAtMarkerEx(g_Player2, "sg_kroot_ambush2", "tau_kroot_hound_squad", "mkr_kroot_ambush_spawn", 1, g_med_deployment_size)

for i = 1, table.getn(t_tau_listening_posts) do	
	EGroup_ForceAddOn("eg_tau_listening_post"..i, "addon_tau_list_post_2")
end


t_pathfinder_spawns = {"mkr_pathfinder_spawn1", "mkr_pathfinder_spawn2", "mkr_pathfinder_spawn3", "mkr_pathfinder_spawn4", "mkr_pathfinder_spawn5", "mkr_pathfinder_spawn6", "mkr_pathfinder_spawn7", "mkr_pathfinder_spawn8",
	"mkr_pathfinder_spawn9", "mkr_pathfinder_spawn10", "mkr_pathfinder_spawn11", "mkr_pathfinder_spawn12", "mkr_pathfinder_spawn13", "mkr_pathfinder_spawn14", "mkr_pathfinder_spawn15"}

for i = 1, table.getn(t_pathfinder_spawns) do
	
	if Marker_Exists(t_pathfinder_spawns[i], "basic_marker") then
		
		Util_CreateSquadsAtMarkerEx(g_Player2, "sg_pathfinder"..i, "tau_pathfinder_squad", "mkr_pathfinder_spawn"..i, 1, 4)
		Cmd_SetStance("sg_pathfinder"..i, STANCE_StandGround)
		
	end
	
end

t_extra_pathfinder_spawns = {"mkr_extra_pathfinders1", "mkr_extra_pathfinders2", "mkr_extra_pathfinders3", "mkr_extra_pathfinders4"}

for i = 1, table.getn(t_extra_pathfinder_spawns) do
	
	if Marker_Exists(t_extra_pathfinder_spawns[i], "basic_marker") then
		
		Util_CreateSquadsAtMarkerEx(g_Player2, "sg_extra_pathfinder"..i, "tau_pathfinder_squad", "mkr_extra_pathfinders"..i, 1, g_small_deployment_size)
		Cmd_SetStance("sg_extra_pathfinder"..i, STANCE_StandGround)
		
	end
	
end

Util_CreateSquadsAtMarker(g_Player2, "sg_montka_extra_vehicle1", "tau_skyray_squad", "mkr_montka_extra_vehicle1", 1)
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_montka_extra_pathfinder", "tau_pathfinder_squad", "mkr_montka_extra_pathfinders", 1, 4)
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_montka_extra_broadside", "tau_broadside_battlesuit_squad", "mkr_extra_broadsides1", 1, g_small_deployment_size)
Cmd_SquadEntrench("sg_montka_extra_broadside")

Util_CreateSquadsAtMarker(g_Player2, "sg_kauyon_extra_vehicle1", "tau_skyray_squad", "mkr_kauyon_extra_vehicle1", 1)
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_kauyon_extra_pathfinder", "tau_pathfinder_squad", "mkr_kauyon_extra_pathfinders", 1, 4)
--Util_CreateSquadsAtMarkerEx(g_Player2, "sg_kauyon_extra_broadside", "tau_broadside_battlesuit_squad", "mkr_extra_broadsides1", 1, g_small_deployment_size)

--generates burrowed drones
t_drone_spawns = {"mkr_drone_spawn1", "mkr_drone_spawn2", "mkr_drone_spawn3", "mkr_drone_spawn4", "mkr_drone_spawn5", "mkr_drone_spawn6", "mkr_drone_spawn7", "mkr_drone_spawn8"}


for p = 1, table.getn(t_drone_spawns) do

	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_drones"..p, "tau_drone_squad", "mkr_drone_trap"..p, 1, 2)
	
	--Cmd_SetStance("sg_drones"..p, STANCE_CeaseFire)
	Command_Squad(g_Player2, SGroup_FromName("sg_drones"..p), SCMD_BurrowToggle)	

end

--Cmd_SetStance("sg_drones5", STANCE_CeaseFire)
Cmd_SetStance("sg_drones6", STANCE_CeaseFire)

--[[
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_assault1", "tau_pathfinder_squad", "mkr_initial_assault_spawn1", 3, 4)
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_assault2", "tau_fire_warrior_squad", "mkr_initial_assault_spawn2", 2, 5)
SGroup_AddLeaders("sg_assault2")]]
--Util_CreateSquadsAtMarker(g_Player2, "sg_assault3", "tau_drone_harbinger_squad", "mkr_initial_assault_spawn3", 1)
--Util_CreateSquadsAtMarkerEx(g_Player2, "sg_assault4", "tau_drone_squad", "mkr_initial_assault_spawn4", 1, 2)

--Cmd_JumpToMarker("sg_assault1", "mkr_jump_attack1")
--Cmd_JumpToMarker("sg_assault2", "mkr_jump_attack2")


Rule_AddOneShot(Rule_Initial_Ambush_Spawner, 1)


--GRANTS CPU FERAL LEAP
Player_GrantResearch(g_Player2, "tau_feral_leap_research")

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]] 4, --[[Strength11]] 4, --[[Strength12]] 5, --[[Strength13]] 5, --[[Strength14]] 5, --[[Strength15]] 5},
	
	ambush_types = {"tau_fire_warrior_squad", "tau_kroot_carnivore_squad"}, -- "ork_squad_stormboy"
	
	ambush_number_of_vehicles = {--[[Strength10]] 1, --[[Strength11]] 2, --[[Strength12]] 2, --[[Strength13]] 2, --[[Strength14]] 2, --[[Strength15]] 3}, -- 1, 1, 2, 2, 3, 3
	
	ambush_vehicle_types = {"tau_drone_harbinger_squad", "tau_skyray_squad"}, 
	
	ambush_detector = {"tau_pathfinder_squad"},
	
	ambush_detector_number = {--[[Strength10]] 5, --[[Strength11]] 5, --[[Strength12]] 5, --[[Strength13]] 5, --[[Strength14]] 5, --[[Strength15]] 5},
	
	
	}

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", 2, t_ambush_components.ambush_detector_number[g_defender_str_adjusted] )
SGroup_AddGroup(SGroup_FromName("sg_initial_ambush"), SGroup_FromName("sg_initial_detector"))

Rule_AddOneShot(Rule_Initial_Ambush_Activation, 30)



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


--custom for Tau Stronghold Only
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_initial_anti_vehicle", "tau_crisis_suit_squad", "mkr_ambush2spawn", 1, 1 )
Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_initial_anti_vehicle"), 1), "tau_missile_pod_crisis_suit", 1)
SGroup_AddGroup(SGroup_FromName("sg_initial_ambush"), SGroup_FromName("sg_initial_anti_vehicle"))



end --[[

function Rule_Create_Enemy_Bonus_Squads()

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

for t = 1,  table.getn(t_cpu_blueprintbonus) do
		
	u = math.mod(t - 1, 6) + 1
	
	Util_CreateSquadsAtMarker(g_Player2, "sg_cpu_bonus"..t, t_cpu_blueprintbonus[t], "mkr_cpu_bonus"..u, 1)
	
	
end

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

--[[generates patrol unit 1 -- will make this function generate random patrol composition at a later date]] function Rule_Tau_Patrol1_Kickoff()

if g_spawn_patrol1_iter < 4 then
	
	if ((EGroup_Exists("eg_patrol1_generator")) and (EGroup_IsEmpty("eg_patrol1_generator") == false)) then
		
		if g_spawn_patrol1_iter == 1 then
			
			Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_patrol1", "tau_fire_warrior_squad", "mkr_patrol1_spawn", 1, 8)
			SGroup_AddLeaders("sg_tau_patrol1")
			SGroup_AddLeadersAtIndex("sg_tau_patrol1", 2)
			
		elseif g_spawn_patrol1_iter == 2 then
			
			Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_patrol1b", "tau_pathfinder_squad", "mkr_patrol1_spawn", 1, 4)
			SGroup_AddGroup(SGroup_FromName("sg_tau_patrol1"), SGroup_FromName("sg_tau_patrol1b"))
			
		elseif g_spawn_patrol1_iter == 3 then			
			
			Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_patrol1c", "tau_pathfinder_squad", "mkr_patrol1_spawn", 1, 4)
			SGroup_AddGroup(SGroup_FromName("sg_tau_patrol1"), SGroup_FromName("sg_tau_patrol1c"))		
			
		end
		
	elseif (EGroup_Exists("eg_patrol1_generator") and (EGroup_IsEmpty("eg_patrol1_generator"))) then
		
		g_patrol1_generator_destroyed = true
		
		Rule_Remove(Rule_Tau_Patrol1_Kickoff)
		
	end
	
end


if g_spawn_patrol1_iter >= 4 then
	
	g_patrol1_ready = true
	
	g_spawn_patrol1_iter = 1
	
	Rule_Remove(Rule_Tau_Patrol1_Kickoff)
	
elseif g_spawn_patrol1_iter <= 3 then
	
	g_spawn_patrol1_iter = g_spawn_patrol1_iter + 1
	
end

end

--[[generates patrol unit 2 -- will make this function generate random patrol composition at a later date]] function Rule_Tau_Patrol2_Kickoff()

if g_spawn_patrol2_iter < 4 then
	
	if ((EGroup_Exists("eg_patrol2_generator")) and (EGroup_IsEmpty("eg_patrol2_generator") == false)) then
		
		if g_spawn_patrol2_iter == 1 then
			
			Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_patrol2", "tau_kroot_carnivore_squad", "mkr_patrol2_spawn", 1, g_large_deployment_size)
			SGroup_AddLeaders("sg_tau_patrol2")
			
		elseif g_spawn_patrol2_iter == 2 then
			
			Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_patrol2b", "tau_pathfinder_squad", "mkr_patrol2_spawn", 1, 4)
			SGroup_AddGroup(SGroup_FromName("sg_tau_patrol2"), SGroup_FromName("sg_tau_patrol2b"))
			
		elseif g_spawn_patrol2_iter == 3 then
			
			Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_patrol2c", "tau_pathfinder_squad", "mkr_patrol2_pathfinder_spawn", 1, 4)
			SGroup_AddGroup(SGroup_FromName("sg_tau_patrol2"), SGroup_FromName("sg_tau_patrol2c"))		
			
		end
		
	elseif (EGroup_Exists("eg_patrol2_generator") and (EGroup_IsEmpty("eg_patrol2_generator"))) then
		
		g_patrol2_generator_destroyed = true
		
		Rule_Remove(Rule_Tau_Patrol2_Kickoff)
		
	end
	
end


if g_spawn_patrol2_iter >= 4 then
	
	g_patrol2_ready = true
	
	g_spawn_patrol2_iter = 1
	
	Rule_Remove(Rule_Tau_Patrol2_Kickoff)
	
elseif g_spawn_patrol2_iter <= 3 then
	
	g_spawn_patrol2_iter = g_spawn_patrol2_iter + 1
	
end

end

--[[ --[[generates patrol unit 2 -- will make this function generate random patrol composition at a later date]] function Rule_Tau_Patrol2_Kickoff()

if ((EGroup_Exists("eg_patrol2_generator")) and (EGroup_IsEmpty("eg_patrol2_generator") == false)) then
	
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_patrol2", "tau_kroot_carnivore_squad", "mkr_patrol2_spawn", 1, 8)
	SGroup_AddLeaders("sg_tau_patrol2")
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_patrol2b", "tau_pathfinder_squad", "mkr_patrol1_spawn", 2, 4)
	SGroup_AddGroup(SGroup_FromName("sg_tau_patrol2"), SGroup_FromName("sg_tau_patrol2b"))

elseif (EGroup_Exists("eg_patrol2_generator") and (EGroup_IsEmpty("eg_patrol2_generator"))) then
	
	g_patrol2_generator_destroyed = 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_Marines_Mission_Start, 1)
	
	Rule_Remove(Rule_Play_Race_Specific_Opening_Text)
	
elseif g_player_race_type == "ork_race" then
	
	Rule_AddOneShot(Rule_IE_Orks_Mission_Start, 1)
	
	Rule_Remove(Rule_Play_Race_Specific_Opening_Text)
	
elseif g_player_race_type == "necron_race" then
	
	Rule_AddOneShot(Rule_IE_Necrons_Mission_Start, 1)
	
	Rule_Remove(Rule_Play_Race_Specific_Opening_Text)
	
end

end

-- what happens when player approaches the Ethereal's Base function Rule_Ethereal_Sighted_Base()

--if Player_AreSquadsNearMarker(g_Player1, "mkr_bodyguard_trigger1") then
	
	
	if g_player_race_type == "chaos_marine_race" then
		
		Rule_AddOneShot(Rule_IE_Ethereal_Sighted_Chaos, 1)
		
		Rule_Remove(Rule_Ethereal_Sighted_Base)
		
	elseif g_player_race_type == "eldar_race" then
		
		Rule_AddOneShot(Rule_IE_Ethereal_Sighted_Eldar, 1)
		
		Rule_Remove(Rule_Ethereal_Sighted_Base)
		
	elseif g_player_race_type == "guard_race" then
		
		Rule_AddOneShot(Rule_IE_Ethereal_Sighted_IG, 1)
		
		Rule_Remove(Rule_Ethereal_Sighted_Base)
		
	elseif g_player_race_type == "space_marine_race" then
		
		Rule_AddOneShot(Rule_IE_Ethereal_Sighted_Space_Marines, 1)
		
		Rule_Remove(Rule_Ethereal_Sighted_Base)
		
	elseif g_player_race_type == "ork_race" then
		
		Rule_AddOneShot(Rule_IE_Ethereal_Sighted_Orks, 1)
		
		Rule_Remove(Rule_Ethereal_Sighted_Base)
		
	elseif g_player_race_type == "necron_race" then
		
		Rule_AddOneShot(Rule_IE_Ethereal_Sighted_Necrons, 1)
		
		Rule_Remove(Rule_Ethereal_Sighted_Base)
		
	end
	
	
	--Rule_Remove(Rule_Ethereal_Sighted_Base)
	
--end

end

-- what happens when player approaches the Com Tower function Rule_Race_Specific_Com_Tower_Speech()

--if Player_AreSquadsNearMarker(g_Player1, "mkr_bodyguard_trigger1") then
	
	
	if g_player_race_type == "chaos_marine_race" then
		
		Rule_AddOneShot(Rule_IE_Com_Tower_Objective_Activation_Chaos, 1)
		
		Rule_Remove(Rule_Race_Specific_Com_Tower_Speech)
		
	elseif g_player_race_type == "eldar_race" then
		
		Rule_AddOneShot(Rule_IE_Com_Tower_Objective_Activation_Eldar, 1)
		
		Rule_Remove(Rule_Race_Specific_Com_Tower_Speech)
		
	elseif g_player_race_type == "guard_race" then
		
		Rule_AddOneShot(Rule_IE_Com_Tower_Objective_Activation_IG, 1)
		
		Rule_Remove(Rule_Race_Specific_Com_Tower_Speech)
		
	elseif g_player_race_type == "space_marine_race" then
		
		Rule_AddOneShot(Rule_IE_Com_Tower_Objective_Activation_Space_Marines, 1)
		
		Rule_Remove(Rule_Race_Specific_Com_Tower_Speech)
		
	elseif g_player_race_type == "ork_race" then
		
		Rule_AddOneShot(Rule_IE_Com_Tower_Objective_Activation_Orks, 1)
		
		Rule_Remove(Rule_Race_Specific_Com_Tower_Speech)
		
	elseif g_player_race_type == "necron_race" then
		
		Rule_AddOneShot(Rule_IE_Com_Tower_Objective_Activation_Necrons, 1)
		
		Rule_Remove(Rule_Race_Specific_Com_Tower_Speech)
		
	end
	
	
	--Rule_Remove(Rule_Ethereal_Sighted_Base)
	
--end

end

--Tau patrol1 sgroup routine. --Detects to see if the sgroup exists and if it is empty. If it is alive and well, it will start to move along its waypoints.
--This routine counts the number of waypoints entered into the table t_tau_patrol1_waypoints and uses that as the basis for the for loop used in this function. --Only when the patrol's units gets close enough to the waypoint does the counter for the for loop go up by 1, which means that the patrol will move onto the next waypoint in sequence --The patrol loop will stop when g_patrol1_generator_destroyed is true. This flag will be kicked off when sg_tau_patrol1's "generator building" is destroyed. function Rule_Tau_Patrol1()

if SGroup_Exists("sg_tau_patrol1") and SGroup_IsEmpty("sg_tau_patrol1") ~= true then
	
	if g_patrol1_ready == true then
	
		if SGroup_IsUnderAttackByPlayer("sg_tau_patrol1", false, g_Player1) ~= true then
			
			for i = 1, g_patrol1_waypoints do
				
				if (g_patrol1 == i) and (g_patrol1 <= g_patrol1_waypoints)then
					
					Cmd_AttackMoveMarker("sg_tau_patrol1", "mkr_patrol1_waypoint"..i)
					
					if Prox_AnySquadNearMarker("sg_tau_patrol1", "mkr_patrol1_waypoint"..i) == true then
						
						g_patrol1 = i + 1
						
						
					end
					
				elseif g_patrol1 >= (g_patrol1_waypoints + 1)  then
					
					g_patrol1 = 1
					
				end
				
			end
			
		end
		
	end
	
elseif SGroup_Count(SGroup_FromName("sg_tau_patrol1")) == 0 and (g_patrol1_generator_destroyed == false) then
	
	--Rule_Check_AddOneShot(Rule_Tau_Patrol1_Kickoff, 5)
	Rule_Check_AddInterval(Rule_Tau_Patrol1_Kickoff, 30)
	
	g_patrol1_ready = false
	
elseif SGroup_Count(SGroup_FromName("sg_tau_patrol1")) == 0 and  (g_patrol1_generator_destroyed == true) then
	
	Rule_Remove(Rule_Tau_Patrol1);
	
	g_patrol1_ready = false
	
end

end

--[[What happens when tau patrol1 is under attack (currently unused)]] --I'm going to modify this so that when the patrol is attacked, it will attempt to lure the player back towards its origin point. Once the player steps within a certain area (and with enough troops) the Tau will dramatically jump in a few crisis suits to snipe the player. function Rule_Tau_Patrol1_Attacked()

if SGroup_Exists("sg_tau_patrol1") and SGroup_IsEmpty("sg_tau_patrol1") ~= true then
	
	if SGroup_IsUnderAttackByPlayer("sg_tau_patrol1", false, g_Player1) then
		
		Cmd_SetStance("sg_tau_patrol1", STANCE_Attack ) 
		g_all_current_player1_squads = Player_GetSquads(g_Player1)
		Cmd_AttackSGroup("sg_tau_patrol1", SGroup_GetName(g_all_current_player1_squads))
		
	end
	
elseif SGroup_Count(SGroup_FromName("sg_tau_patrol1")) == 0 then
	Rule_Remove(Rule_Tau_Patrol1_Attacked);
end

end

function Rule_Tau_Patrol2()

if SGroup_Exists("sg_tau_patrol2") and SGroup_IsEmpty("sg_tau_patrol2") ~= true then
	
	if g_patrol2_ready == true then
	
		if SGroup_IsUnderAttackByPlayer("sg_tau_patrol2", false, g_Player1) ~= true then
			
			for i = 1, g_patrol2_waypoints do
				
				if (g_patrol2 == i) and (g_patrol2 <= g_patrol2_waypoints)then
					
					Cmd_AttackMoveMarker("sg_tau_patrol2", "mkr_patrol2_waypoint"..i)
					
					if Prox_AnySquadNearMarker("sg_tau_patrol2", "mkr_patrol2_waypoint"..i) == true then
						
						g_patrol2 = i + 1
						
						
					end
					
				elseif g_patrol2 >= (g_patrol2_waypoints + 1)  then
					
					g_patrol2 = 1
					
				end
				
			end
			
		end
		
	end
	
elseif SGroup_Count(SGroup_FromName("sg_tau_patrol2")) == 0 and (g_patrol2_generator_destroyed == false) then
	
	--Rule_Check_AddOneShot(Rule_Tau_Patrol2_Kickoff, 5)
	Rule_Check_AddInterval(Rule_Tau_Patrol2_Kickoff, 30)
	
	g_patrol2_ready = false
	
elseif SGroup_Count(SGroup_FromName("sg_tau_patrol2")) == 0 and  (g_patrol2_generator_destroyed == true) then
	
	Rule_Remove(Rule_Tau_Patrol2);
	
	g_patrol2_ready = false
	
end

end

--[[ function Rule_Tau_Patrol2() -- same functionality as Tau Patrol 1 if SGroup_Exists("sg_tau_patrol2") and SGroup_IsEmpty("sg_tau_patrol2") ~= true then

	if SGroup_IsUnderAttackByPlayer("sg_tau_patrol2", false, g_Player1) ~= true then
		
		for i = 1, g_patrol2_waypoints do
			
			if (g_patrol2 == i) and (g_patrol2 <= g_patrol2_waypoints)then
				
				Cmd_AttackMoveMarker("sg_tau_patrol2", "mkr_patrol2_waypoint"..i)
				
				if Prox_AnySquadNearMarker("sg_tau_patrol2", "mkr_patrol2_waypoint"..i) == true then
					
					g_patrol2 = i + 1
					
					
				end
				
			elseif g_patrol2 >= (g_patrol2_waypoints + 1)  then
				
				g_patrol2 = 1
				
			end
			
		end
		
	end
	
elseif SGroup_Count(SGroup_FromName("sg_tau_patrol2")) == 0 then
	
	Rule_Check_AddOneShot(Rule_Tau_Patrol2_Kickoff, 5)
		
elseif SGroup_Count(SGroup_FromName("sg_tau_patrol2")) == 0 and  (g_patrol2_generator_destroyed == true) then
	
	Rule_Remove(Rule_Tau_Patrol2);
	
end

end]]

--[[what happens when tau patrol2 is under attack (currently unused)]] function Rule_Tau_Patrol2_Attacked() --I'm going to modify this so that when the patrol is attacked, it will attempt to lure the player back towards its origin point. Once the player steps within a certain area (and with enough troops) the Tau will dramatically jump in a few crisis suits to snipe the player. if SGroup_Exists("sg_tau_patrol2") and SGroup_IsEmpty("sg_tau_patrol2") ~= true then

	if SGroup_IsUnderAttackByPlayer("sg_tau_patrol2", false, g_Player1) then
		
		Cmd_SetStance("sg_tau_patrol2", STANCE_Attack ) 
		g_all_current_player1_squads = Player_GetSquads(g_Player1)
		Cmd_AttackSGroup("sg_tau_patrol2", SGroup_GetName(g_all_current_player1_squads))
		
	end
	
elseif SGroup_Count(SGroup_FromName("sg_tau_patrol2")) == 0 then
	Rule_Remove(Rule_Tau_Patrol2_Attacked);
end

end

--[[Tau Ethereal patrol routine]] function Rule_Ether_Patrol() --Moves the Ethereal around its patrol routine. If the Ethereal isn't under attack, the game will tell it to move to the next waypoint in sequence. A counter is used to keep --track of whether or not the Ethereal has reached the next waypoint. Once it has reached the last waypoint, the counter will reset and the Ethereal will be sent back to --the first waypoint. if SGroup_Exists("sg_tau_ethereal") and SGroup_IsEmpty("sg_tau_ethereal") ~= true then

	if Player_AreSquadsNearMarker(g_Player1, "mkr_tau_hq_area") == false then
		
		if SGroup_IsUnderAttackByPlayer("sg_tau_ethereal", false, g_Player1) ~= true then
			
			for i = 1, g_ether_patrol_waypoints do
				
				if (g_ether_patrol == i) and (g_patrol2 <= g_ether_patrol_waypoints) then
					
					Cmd_AttackMoveMarker("sg_tau_ethereal", "mkr_ether_patrol"..i)
					Cmd_SetStance("sg_tau_ethereal", STANCE_StandGround)
					--might want to try all squadsnearmarker
					if Prox_AnySquadNearMarker("sg_tau_ethereal", "mkr_ether_patrol"..i) == true then
						
						g_ether_patrol = i + 1
						
					end
					
				elseif g_ether_patrol >= (g_ether_patrol_waypoints + 1)  then
					
					g_ether_patrol = 1
					
				end
				
			end
			
		elseif SGroup_IsUnderAttackByPlayer("sg_tau_ethereal", false, g_Player1) == true then
			
			if g_protect_ethereal_speech == false then
				
				--Rule_AddOneShot(Rule_IE_Protect_Ethereal, 1)
				
				Rule_AddOneShot(Rule_Ethereal_Sighted_Base, 1)
				
				
				g_protect_ethereal_speech = true
				
			end
			
		end
			
		
	elseif Player_AreSquadsNearMarker(g_Player1, "mkr_tau_hq_area") == true then
		
		if g_protect_ethereal_speech == false then
			
			--Rule_AddOneShot(Rule_IE_Protect_Ethereal, 1)
			
			Rule_AddOneShot(Rule_Ethereal_Sighted_Base, 1)
			
			g_protect_ethereal_speech = true
			
		end
		Cmd_SetStance("sg_tau_ethereal", STANCE_StandGround)
		Cmd_MoveToMarker("sg_tau_ethereal", "mkr_ethereal_retreat")
		
	end
	
	
	
elseif SGroup_Count(SGroup_FromName("sg_tau_ethereal")) == 0 then
	
	Rule_Remove(Rule_Ether_Patrol);
	
end

end

--[[ --[[what happens when the Ethereal is under attack (currently unused)]] function Rule_Ether_Patrol_Attacked() --I'm going to modify this so that when the patrol is attacked, it will attempt to lure the player back towards its origin point. Once the player steps within a certain area (and with enough troops) the Tau will dramatically jump in a few crisis suits to snipe the player. if SGroup_Exists("sg_tau_ethereal") and SGroup_IsEmpty("sg_tau_ethereal") ~= true then

	if SGroup_IsUnderAttackByPlayer("sg_tau_ethereal", false, g_Player1) then
		
		Cmd_SetStance("sg_tau_ethereal", STANCE_Attack ) 
		
		
		Rule_AddOneShot(Rule_Ethereal_Sighted_Base, 1)
		
		g_all_current_player1_squads = Player_GetSquads(g_Player1)
		Cmd_AttackSGroup("sg_tau_ethereal", SGroup_GetName(g_all_current_player1_squads))
		
	end
	
elseif SGroup_Count(SGroup_FromName("sg_tau_ethereal")) == 0 then
	Rule_Remove(Rule_Ether_Patrol_Attacked);
end

end]]

-- function here that controls crisis suits jumping in to ambush player -- function here that controls Skyray and Hammerheads coming in to ambush player -- function here that controls Stealth Suit snipers perched on the tops of buildings. These guys will mark key player units such as anti-stealth units. Then they will target commanders or heavy vehicles. --when the player moves within range, the crisis suits and vehicles will target these anti-stealth units first, then commanders and vehicles -- function here that controls the behaviour of the defenders of the base at the relic in the center of the city area. This area will be heavily defended -- function here that controls in general the behaviour of units -- fire warrior "recon" elements will keep nipping at the fringe of the player's sensor radius, and keep moving in the general direction of either of the key Tau patrol firebases. --function here that controls 2 Tau attack forces, to lure the player away from their base, or to wear down the base's defences so that the player can't turtle. --if the main base is taken out, but the player has outposts, keep track of where the player outposts are and then send enemy attacks to them too, once the main base gets destroyed.


--AMBUSH CONTROL 1

--[[function here that controls the "bait" units]] function Rule_Ambush_Control1()

if SGroup_Exists("sg_tau_bait1") and (SGroup_IsEmpty("sg_tau_bait1") == false) then
	
	--creates an SGroup out of the player's units so that if any of the player's units sees the bait, the bait will try to move out of the way to lure them towards the kill zone
	SGroup_CreateIfNotFound("sg_player_pursuer_unit")
	Player_AddSquadsToSGroup(g_Player1, "sg_player_pursuer_unit")
	
	if SGroup_CanSeeSGroup("sg_player_pursuer_unit", "sg_tau_bait1", false) then
		
		Cmd_ReinforceTrooper("sg_tau_bait1", 6)
		Cmd_MoveToMarker("sg_tau_bait1", "mkr_bait1_destination")
		
	elseif SGroup_CanSeeSGroup("sg_player_pursuer_unit", "sg_tau_bait1", false) == false then
		
		Cmd_ReinforceTrooper("sg_tau_bait1", 6)
		Cmd_StopSquads("sg_tau_bait1")
		
	end
	
	
	--grabs all player's units that are in a certain area when the bait reaches its destination and then attacks them with the pre-positioned units,
	if Prox_AnySquadNearMarker("sg_tau_bait1", "mkr_bait1_destination") == true then
		
		Player_GetAllSquadsNearMarker( g_Player1, "sg_player_lured_unit1", "mkr_create_lured_enemy_sgroup1" )
		
		if Prox_AnySquadNearMarker( "sg_player_lured_unit1", "mkr_create_lured_enemy_sgroup1" ) == true then
			
			if SGroup_Count("sg_player_lured_unit1") >= 4 then
				--checks to see if it's just a small force, which would be easily taken care of.  if it's a larger force the cavalry is called in....
				
				Rule_Check_AddOneShot(Rule_Get_Player_Lured_Unit1, 0)	
				
				Rule_Remove(Rule_Ambush_Control1)
				
			end 
			
		end
		
	end
	
elseif SGroup_Exists("sg_tau_bait1") and (SGroup_IsEmpty("sg_tau_bait1") == true) then -- if the bait is killed....
	
	-- this is used if the bait is destroyed before it gets to its destination
	
	SGroup_CreateIfNotFound("sg_player_pursuer_unit")
	Player_AddSquadsToSGroup(g_Player1, "sg_player_pursuer_unit")
	
	--grabs all player's units within a certain area and makes them a target
	Player_GetAllSquadsNearMarker( g_Player1, "sg_player_lured_unit1", "mkr_create_lured_enemy_sgroup1" )
	
	if Prox_AnySquadNearMarker( "sg_player_lured_unit1", "mkr_create_lured_enemy_sgroup1" ) then
		
		if SGroup_Count("sg_player_lured_unit1") >= 3 then
			--checks to see if it's just a small force, which would be easily taken care of.  if it's a larger force the cavalry is called in....
			
			if ((SGroup_Exists("sg_tau_knarloc1") and (SGroup_IsEmpty("sg_tau_knarloc1") == false)) and
				(SGroup_Exists("sg_tau_knarloc1_keepers") and (SGroup_IsEmpty("sg_tau_knarloc1_keepers") == false))) then
				
				Cmd_AttackMoveMarker("sg_tau_knarloc1", "mkr_create_lured_enemy_sgroup1")
				Cmd_AttackMoveMarker("sg_tau_knarloc1_keepers", "mkr_create_lured_enemy_sgroup1")
				
				Rule_AddOneShot(Rule_IE_Ambush2, 1)
				
				
				Rule_Remove(Rule_Ambush_Control1)
				
			end
			
		end
		
	end
	
end

end

function Rule_Get_Player_Lured_Unit1() --[[makes units attack the player's army]]

if ((SGroup_Exists("sg_tau_knarloc1") and (SGroup_IsEmpty("sg_tau_knarloc1") == false)) and 
	(SGroup_Exists("sg_tau_knarloc1_keepers") and (SGroup_IsEmpty("sg_tau_knarloc1_keepers") == false))) and (SGroup_IsEmpty("sg_tau_bait1") == false) then
	
	Cmd_AttackSGroup("sg_tau_knarloc1", "sg_player_lured_unit1")
	Cmd_AttackSGroup("sg_tau_knarloc1_keepers", "sg_player_lured_unit1")

	Rule_AddOneShot(Rule_IE_Ambush2, 1)

	
	if SGroup_Exists("sg_tau_crisis_defender10") and (SGroup_IsEmpty("sg_tau_crisis_defender10") == false) then
		
		Cmd_JumpToMarker("sg_tau_crisis_defender10", "mkr_create_lured_enemy_sgroup1")
		
	end
	
end

end


--AMBUSH CONTROL 2

--[[function here that controls the "bait" units]] function Rule_Ambush_Control2()

if SGroup_Exists("sg_tau_bait2") and (SGroup_IsEmpty("sg_tau_bait2") == false) then
	
	--creates an SGroup out of the player's units so that if any of the player's units sees the bait, the bait will try to move out of the way to lure them towards the kill zone
	SGroup_CreateIfNotFound("sg_player_pursuer_unit")
	Player_AddSquadsToSGroup(g_Player1, "sg_player_pursuer_unit")
	
	if SGroup_CanSeeSGroup("sg_player_pursuer_unit", "sg_tau_bait2", false) then
		
		Cmd_ReinforceTrooper("sg_tau_bait2", 6)
		Cmd_MoveToMarker("sg_tau_bait2", "mkr_bait2_destination")
		
	elseif SGroup_CanSeeSGroup("sg_player_pursuer_unit", "sg_tau_bait2", false) == false then
		
		Cmd_ReinforceTrooper("sg_tau_bait2", 6)
		Cmd_StopSquads("sg_tau_bait2")
		
	end
	
	--grabs all player's units that are in a certain area when the bait reaches its destination and then attacks them with the pre-positioned units,
	if Prox_AnySquadNearMarker("sg_tau_bait2", "mkr_bait2_destination") == true then
		
		Player_GetAllSquadsNearMarker( g_Player1, "sg_player_lured_unit2", "mkr_create_lured_enemy_sgroup2" )
		
		if Prox_AnySquadNearMarker( "sg_player_lured_unit2", "mkr_create_lured_enemy_sgroup2" ) == true then
			
			if SGroup_Count("sg_player_lured_unit2") >= 4 then
				--checks to see if it's just a small force, which would be easily taken care of.  if it's a larger force the cavalry is called in....
				
				Rule_Check_AddOneShot(Rule_Get_Player_Lured_Unit2, 0)	
				
				Rule_Remove(Rule_Ambush_Control2)
				
			end 
			
		end
		
	end
	
elseif SGroup_Exists("sg_tau_bait2") and (SGroup_IsEmpty("sg_tau_bait2") == true) then -- if the bait is killed....
	
	-- this is used if the bait is destroyed before it gets to its destination
	
	SGroup_CreateIfNotFound("sg_player_pursuer_unit")
	Player_AddSquadsToSGroup(g_Player1, "sg_player_pursuer_unit")
	
	--grabs all player's units within a certain area and makes them a target
	Player_GetAllSquadsNearMarker( g_Player1, "sg_player_lured_unit2", "mkr_create_lured_enemy_sgroup2" )
	
	if Prox_AnySquadNearMarker( "sg_player_lured_unit2", "mkr_create_lured_enemy_sgroup2" ) then
		
		if SGroup_Count("sg_player_lured_unit2") >= 3 then
			--checks to see if it's just a small force, which would be easily taken care of.  if it's a larger force the cavalry is called in....
			
			if ((SGroup_Exists("sg_tau_ambush2") and (SGroup_IsEmpty("sg_tau_ambush2") == false)) and
				(SGroup_Exists("sg_tau_ambush2_vehicles") and (SGroup_IsEmpty("sg_tau_ambush2_vehicles") == false))) then
				
				Cmd_AttackMoveMarker("sg_tau_ambush2", "mkr_create_lured_enemy_sgroup2")
				Cmd_AttackMoveMarker("sg_tau_ambush2_vehicles", "mkr_create_lured_enemy_sgroup2")
				
				Rule_AddOneShot(Rule_IE_Ambush1, 1) -- 1 is actually the Kroot Hounds
				
				Rule_Remove(Rule_Ambush_Control2)
				
			end
			
		end
		
	end
	
end

end

function Rule_Get_Player_Lured_Unit2()

if ((SGroup_Exists("sg_tau_ambush2") and (SGroup_IsEmpty("sg_tau_ambush2") == false)) and 
	(SGroup_Exists("sg_tau_ambush2_vehicles") and (SGroup_IsEmpty("sg_tau_ambush2_vehicles") == false))) and (SGroup_IsEmpty("sg_tau_bait2") == false) then
	
	Cmd_AttackSGroup("sg_tau_ambush2", "sg_player_lured_unit2")
	Cmd_AttackSGroup("sg_tau_ambush2_vehicles", "sg_player_lured_unit2")
	
	Rule_AddOneShot(Rule_IE_Ambush1, 1) -- 1 is actually the Kroot Hounds
	
end
	

end


--Ambush Control 3

-- this functions controls what happens in the 3rd ambush near the western side of the map. When the player reaches this "sniper alley", units will appear and attack the player from -- both ends, trapping him/her. function Rule_Ambush_Control3()

if Player_AreSquadsNearMarker(g_Player1, "mkr_ambush_activation_trigger1") then
	
	Player_GetAllSquadsNearMarker(g_Player1, "sg_ambushed_by_knarloc2", "mkr_ambush_activation_trigger1")
	
	if SGroup_Count(SGroup_FromName("sg_ambushed_by_knarloc2")) >= 3 then
		
		if SGroup_Exists("sg_drones6") and (SGroup_IsEmpty("sg_drones6") == false) then
			Cmd_SetStance("sg_drones6", STANCE_StandGround)
			Command_Squad(g_Player2, SGroup_FromName("sg_drones6"), SCMD_BurrowToggle)	
		end
		
		if SGroup_Exists("sg_tau_knarloc2") and (SGroup_IsEmpty("sg_tau_knarloc2") == false) then
			Cmd_AttackMoveMarker("sg_tau_knarloc2", "mkr_knarloc_spawn2_waypoint1")
		end
		
		if SGroup_Exists("sg_tau_knarloc2_keepers") and SGroup_IsEmpty("sg_tau_knarloc2_keepers") == false then
			Cmd_AttackMoveMarker("sg_tau_knarloc2_keepers", "mkr_knarloc_spawn2_waypoint1")
		end
		
		if SGroup_Exists("sg_tau_ambush3_behind") == false or SGroup_IsEmpty("sg_tau_ambush3_behind") then
			Util_CreateSquadsAtMarkerEx(g_Player2, "sg_tau_ambush3_behind", "tau_crisis_suit_squad_stronghold_sp", "mkr_ambush_dropin1_spawn", 2, 10)
			--Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_tau_ambush3_behind"), 1), "tau_fusion_blaster_crisis_suit", 2)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_tau_ambush3_behind"), 1), "tau_flamer_crisis_suit", 1)
			
			Cmd_JumpToMarker("sg_tau_ambush3_behind", "mkr_ambush_dropin1_waypoint1")
			--Cmd_AttackMoveMarker("sg_tau_ambush3_behind", "mkr_ambush_dropin1_waypoint1")
		end
		
		Rule_AddOneShot(Rule_IE_Ambush3, 1)
		
		Rule_Remove(Rule_Ambush_Control3)
	
	end
	
end

end


--Ambush Control 4

--kroot ambush from abandoned building

function Rule_Ambush_Control4()

if Player_AreSquadsNearMarker(g_Player1, "mkr_ambush_activation_trigger3") then
	
	Player_GetAllSquadsNearMarker(g_Player1, "sg_ambushed_by_kroot", "mkr_kroot_ambush_grab_player_units")
	
	if SGroup_Count(SGroup_FromName("sg_ambushed_by_kroot")) >= 3 then
		
		if SGroup_Exists("sg_kroot_ambush1") and (SGroup_IsEmpty("sg_kroot_ambush1") == false) then
			Cmd_AttackSGroup("sg_kroot_ambush1", "sg_ambushed_by_kroot")
		end
		
		if SGroup_Exists("sg_kroot_ambush2") and (SGroup_IsEmpty("sg_kroot_ambush2") == false) then
			Cmd_AttackSGroup("sg_kroot_ambush2", "sg_ambushed_by_kroot")
		end
		
		Rule_Remove(Rule_Ambush_Control4)
		
	end
	
end

end

function Rule_Initial_Attack()

--Cmd_AttackMoveMarker("sg_assault1", "mkr_initial_assault_destination1")
--Cmd_AttackMoveMarker("sg_assault2", "mkr_initial_assault_destination2")
--Cmd_AttackMoveMarker("sg_assault3", "mkr_initial_assault_destination3")
--Cmd_AttackMoveMarker("sg_assault4", "mkr_initial_assault_destination4")		
--Rule_AddInterval(Rule_Initial_Attack_Delay, 1)

end

--[[ function Rule_Initial_Attack_Delay()

if g_initial_delay_counter <= 10 then

	g_initial_delay_counter = g_initial_delay_counter + 1

elseif g_initial_delay_counter >= 11 then
--Cmd_AttackMoveMarker("sg_assault1", "mkr_initial_assault_destination1")
--Cmd_AttackMoveMarker("sg_assault2", "mkr_initial_assault_destination2")
Cmd_AttackMoveMarker("sg_assault3", "mkr_initial_assault_destination3")
--Cmd_AttackMoveMarker("sg_assault4", "mkr_initial_assault_destination4")		
	Rule_Remove(Rule_Initial_Attack_Delay)
end

end]]

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

for i = 1, 7 do	--number designation
	
	Player_GetAllSquadsNearMarker(g_Player1, "sg_unit_count_for_areas"..i, t_bases_of_operation.areaname[i])
	t_tau_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() -- controls how the counterattack is triggered. if the counterattack flag is false, it will start the army generation function. if it's already sent, then it keeps looping -- until the counterattack is destroyed, after which the flag will be set to false and the counterattack will be activated again if g_counterattack_sent == false then

	Rule_Check_AddInterval(Rule_Create_Tau_Counterattack_Armies, 1) -- 10 seconds for test --check_AddOneShot
	--print("create tau 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_Count_Player_Buildings() -- not used yet, will add soon

for i = 1, 6 do

	Player_GetAllEntitiesNearMarker(g_Player1, "eg_player_buildings_at_outpost"..i, "mkr_tau_outpost"..i.."area")
	
	t_area_building_count[i] = EGroup_Count(EGroup_FromName("eg_player_buildings_at_outpost"..i))
	
end

end]]

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

if g_counterattack_sent == true then
	
	if SGroup_Exists("sg_counterattack_force") and (SGroup_IsEmpty("sg_counterattack_force") == false) and 
	SGroup_CheckActiveCommand("sg_counterattack_force", 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_counterattack_force", g_target) then
			
			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)
				
				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")
						
					--end
					
				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, 7)
				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 t_bases_of_operation.areacapturedbyplayer[l_random_area_to_attack] == true 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")
					
					end
					
					
					
				end
				
			end
			
		elseif Prox_AllSquadsNearMarker("sg_counterattack_force", g_target) == false then
			
			Cmd_Capture("sg_counterattack_force", g_target_flag)
			
			if EGroup_IsCapturedByPlayer(g_target_flag, g_Player1, false) == true or Entity_GetWorldOwner(EGroup_GetSpawnedEntityAt(g_target_flag, 1)) == true then	
				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
		
		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")
			
		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

end

function Rule_Create_Tau_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.

--if t_tau_captured_major_flags ~= nil and t_player_captured_major_flags ~= nil then

local l_random_tau_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_tau_counterattack_source)
print("destination: "..l_random_area_to_attack)

print("source owner status: "..t_bases_of_operation.capture_status[l_random_tau_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_tau_counterattack_source] >= 2 then 

	print("start production!")


	if t_tau_captured_major_flags[l_random_tau_counterattack_source] == "eg_flag1" and (EGroup_Exists("eg_tau_construction1") and (EGroup_IsEmpty("eg_tau_construction1") == false)) then
		
		g_build_yes = true
		g_construction_zone = "eg_tau_construction1"
		g_vehicle_construction_zone = "eg_vehicle_construction1"
		print("construction zone: "..g_construction_zone)			
		
	elseif t_tau_captured_major_flags[l_random_tau_counterattack_source] == "eg_flag2" and (EGroup_Exists("eg_tau_construction2") and (EGroup_IsEmpty("eg_tau_construction2") == false)) then
		
		g_build_yes = true
		g_construction_zone = "eg_tau_construction2"
		g_vehicle_construction_zone = "eg_vehicle_construction2"
		print("construction zone: "..g_construction_zone)
		
	elseif t_tau_captured_major_flags[l_random_tau_counterattack_source] == "eg_flag3" and (EGroup_Exists("eg_tau_construction3") and (EGroup_IsEmpty("eg_tau_construction3") == false)) then
		
		g_build_yes = true
		g_construction_zone = "eg_tau_construction3"
		g_vehicle_construction_zone = "eg_vehicle_construction3"
		print("construction zone: "..g_construction_zone)
		
	elseif t_tau_captured_major_flags[l_random_tau_counterattack_source] == "eg_flag4" and (EGroup_Exists("eg_tau_construction4") and (EGroup_IsEmpty("eg_tau_construction4") == false)) then
		
		g_build_yes = true
		g_construction_zone = "eg_tau_construction4"
		g_vehicle_construction_zone = "eg_vehicle_construction4"	
		print("construction zone: "..g_construction_zone)
		
	elseif t_tau_captured_major_flags[l_random_tau_counterattack_source] == "eg_flag5" and (EGroup_Exists("eg_tau_construction5") and (EGroup_IsEmpty("eg_tau_construction5") == false)) then
		
		g_build_yes = true
		g_construction_zone = "eg_tau_construction5"
		g_vehicle_construction_zone = "eg_vehicle_construction5"
		print("construction zone: "..g_construction_zone)
		
	elseif t_tau_captured_major_flags[l_random_tau_counterattack_source] == "eg_flag6" and (EGroup_Exists("eg_tau_construction6") and (EGroup_IsEmpty("eg_tau_construction6") == false)) then
		
		g_build_yes = true
		g_construction_zone = "eg_tau_construction6"
		g_vehicle_construction_zone = "eg_vehicle_construction6"
		print("construction zone: "..g_construction_zone)
		
	elseif t_tau_captured_major_flags[l_random_tau_counterattack_source] == "eg_flag7" and (EGroup_Exists("eg_tau_construction7") and (EGroup_IsEmpty("eg_tau_construction7") == false)) then
		
		g_build_yes = true
		g_construction_zone = "eg_tau_construction_does_not_exist"
		g_vehicle_construction_zone = "eg_vehicle_construction_does_not_exist"
		print("construction zone: "..g_construction_zone)
		
	end

	--print("construction zone: "..g_construction_zone)


	if g_build_yes == true then 
	
	--	if EGroup_Exists(t_bases_of_operation.constructionbuildings[l_random_tau_counterattack_source]) and (EGroup_IsEmpty(t_bases_of_operation.constructionbuildings[l_random_tau_counterattack_source]) == false) then 
				if (EGroup_Exists(g_construction_zone) and (EGroup_IsEmpty(g_construction_zone) == false)) 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 )
					
						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"))
					--g_player_unit_count = SGroup_Count("sg_unit_count_for_player")
					
					
					if g_player_unit_count >= 0 then -- if t_tau_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_tau_counterattack_data.major_names[l_random_tau_counterattack_source]) == false or SGroup_IsEmpty(t_tau_counterattack_data.major_names[l_random_tau_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_tau_counterattack_data.playersquadcount[l_random_area_to_attack] >= 9 and t_tau_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 >= 4 then --and (g_Timer >= 600 and g_Timer <= 1199)  -- 10 and 13
								--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_tau_counterattack_data.playersquadcount[l_random_area_to_attack] >= 14  then --and g_Timer >= 1200
							elseif 	g_player_unit_count >= 11  and g_waves >= 4 then --and g_Timer >= 1200 -- 14
								--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_tau_counterattack_source = l_random_tau_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_tau_counterattack_source]
							locked_source2 = t_bases_of_operation.spawnspot[final_random_tau_counterattack_source]
							locked_source3 = t_bases_of_operation.vehicles[final_random_tau_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]
							
							if g_waves >= 5 then
							
								--if ((locked_source2 == "mkr_tau_outpost3_area")  or  (locked_source2 == "mkr_tau_outpost4_area")) then -- kroot only
								if ((locked_source2 == "mkr_tau_outpost3_counter_spawn")  or  (locked_source2 == "mkr_tau_outpost4_counter_spawn")) then -- kroot only
										
										if g_kauyon_destroyed == true then
											--g_composition_type = t_tau_counterattack_data.composition6
											g_counterattack_unit_composition = t_tau_counterattack_data.composition6
											--print("composition 3")
											
										elseif g_kauyon_destroyed == false then
											--g_composition_type = t_tau_counterattack_data.composition3
											g_counterattack_unit_composition = t_tau_counterattack_data.composition3
											--print("composition 4")
											
										end
										
								elseif ((locked_source2 == "mkr_tau_outpost5_counter_spawn")  or  (locked_source2 == "mkr_tau_outpost1_counter_spawn"))  then -- tau only
										
										if g_montka_destroyed == true then
											--g_composition_type = t_tau_counterattack_data.composition5
											g_counterattack_unit_composition = t_tau_counterattack_data.composition5
											--print("composition 5")
											
										elseif g_montka_destroyed == false then
											--g_composition_type = t_tau_counterattack_data.composition2
											g_counterattack_unit_composition = t_tau_counterattack_data.composition2
											--print("composition 2")
											
										end
									
								elseif ((locked_source2 == "mkr_tau_outpost2_counter_spawn")  or  (locked_source2 == "mkr_tau_outpost6_counter_spawn"))  then -- this source is a mix of kroot and tau
										
										if g_montka_destroyed == true and g_kauyon_destroyed == true then
											
											--print("composition 7")
											
											--g_composition_type = t_tau_counterattack_data.composition7
											g_counterattack_unit_composition = t_tau_counterattack_data.composition5 -- 7
											
										elseif g_montka_destroyed == false and g_kauyon_destroyed == false then
											
											--g_composition_type = t_tau_counterattack_data.composition
											g_counterattack_unit_composition = t_tau_counterattack_data.composition
											
											--print("composition 0")
										elseif g_montka_destroyed == true and g_kauyon_destroyed == false then
										
											g_counterattack_unit_composition = t_tau_counterattack_data.composition3
										
										elseif g_montka_destroyed == false and g_kauyon_destroyed == true then
								
											g_counterattack_unit_composition = t_tau_counterattack_data.composition2
								
										end
										
								end
							
							end
							
							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_Tau_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_tau_counterattack_source]) and (EGroup_IsEmpty(t_bases_of_operation.constructionbuildings[l_random_tau_counterattack_source]) == true) then 	
				elseif EGroup_Exists(g_construction_zone) and (EGroup_IsEmpty(g_construction_zone) == true) then 
					
					print("construction building does not exist")
					
					--g_build_yes = false
					
				end	
	elseif g_build_yes == false then 
		print("construction building does not exist")
		
	end	
	--elseif t_tau_captured_major_flags == nil and t_player_captured_major_flags == nil then
	
		--print("nil?")
	--end
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
			--t_bases_of_operation.areacapturedbyplayer[i] = true
			
			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_Player1, 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
			
		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
		
		Util_CreateSquadsAtMarkerEx(g_Player2, ("sg_counterattack_group"..g_deployed_count), g_counterattack_unit_composition[rand1], 
			locked_source2, 1, rand2) 
		
		print("marker source: "..locked_source2)
		
		SGroup_AddLeaders("sg_counterattack_group"..g_deployed_count)
		--SGroup_AddLeaders(t_tau_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))
		
		g_deployed_count = g_deployed_count + 1
		
		
		if g_deployed_count == t_tau_counterattack_data.squadsize[final_random_area_to_attack][final_squadsize_index] then
			
			
			
			if g_waves >= 3 then --  chance of adding a stealth detector after wave 3
				
				l_random_stealth_detect = World_GetRand(1, 2)
				
				if l_random_stealth_detect == 1 then
					
					Util_CreateSquadsAtMarkerEx(g_Player2, "sg_counterattack_detector", "tau_pathfinder_squad", locked_source2, 1, 5)  -- pathfinders to boost anti-stealth capabilities
					SGroup_AddGroup(SGroup_FromName("sg_counterattack_force"), SGroup_FromName("sg_counterattack_detector"))
					
				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 <= 7 then -- stops count of waves once it reaches > 6 
				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 Tau")

	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_Check_AddInterval(Rule_Spawn_Vehicle_Composition1, 5)
				
				Rule_Remove(Rule_Vehicle_Spawner)
				
				
			elseif g_time_elapsed <= 399 then
				
				print("size 2 time < 400")
				
				Rule_Check_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_Check_AddInterval(Rule_Spawn_Vehicle_Composition3, 5)
				
				Rule_Remove(Rule_Vehicle_Spawner)
				
			elseif g_time_elapsed <= 1799 then
				
				print("size 3 time < 1800")
				
				Rule_Check_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
	
	if g_construction_zone == "eg_tau_construction1" or g_construction_zone == "eg_tau_construction5" then
		
		t_vehicle_composition1_table ={
		name = {"sg_counter_vehicle1", "sg_counter_vehicle2"},
		vehicle_type = {"tau_drone_harbinger_squad", "tau_skyray_squad"} }
		
		
	elseif g_construction_zone == "eg_tau_construction2" or g_construction_zone == "eg_tau_construction6" then
		
		t_vehicle_composition1_table ={
				name = {"sg_counter_vehicle1", "sg_counter_vehicle2"},
		vehicle_type = {"tau_drone_harbinger_squad", "tau_skyray_squad"} }
		
		
	elseif g_construction_zone == "eg_tau_construction3" or g_construction_zone == "eg_tau_construction4" then
	
		if g_kauyon_destroyed == true then
			
			t_vehicle_composition1_table ={
			name = {"sg_counter_vehicle1", "sg_counter_vehicle2"},
			vehicle_type = {"tau_skyray_squad", "tau_drone_harbinger_squad"} }
			
		elseif g_kauyon_destroyed == false then
		
			t_vehicle_composition1_table ={
			name = {"sg_counter_vehicle1", "sg_counter_vehicle2"},
			vehicle_type = {"tau_krootox_squad", "tau_krootox_squad"} }
		
		end
		
	end
		
	local i = g_spawn_vehicle_composition1_iter
	
	print("inside vehicle comp 1")
	
	if g_stop_vehicles == false then
		--if EGroup_Exists("eg_vehicle_construction"..final_random_tau_counterattack_source) == true and EGroup_IsEmpty("eg_vehicle_construction"..final_random_tau_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
	end
	--g_spawn_vehicle_composition1_iter = g_spawn_vehicle_composition1_iter + 1
	
	if g_spawn_vehicle_composition1_iter >= table.getn(t_vehicle_composition1_table.name) then --4
		
		g_stop_vehicles = true
		
		
		if g_counterattack_sent == true 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
			
			g_stop_vehicles = false
			
		end
		
	elseif g_spawn_vehicle_composition1_iter < table.getn(t_vehicle_composition1_table.name) then
		
		g_spawn_vehicle_composition1_iter = 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	
	
	if g_construction_zone == "eg_tau_construction1" or g_construction_zone == "eg_tau_construction5" then
		
		t_vehicle_composition2_table ={
		name = {"sg_counter_vehicle1"},
		vehicle_type = {"tau_drone_harbinger_squad"} }
		
	elseif g_construction_zone == "eg_tau_construction2" or g_construction_zone == "eg_tau_construction6" then
		
		t_vehicle_composition2_table ={
				name = {"sg_counter_vehicle1"},
		vehicle_type = {"tau_drone_harbinger_squad"} }
		
		
	elseif g_construction_zone == "eg_tau_construction3" or g_construction_zone == "eg_tau_construction4" then
		
		if g_kauyon_destroyed == true then
		
			t_vehicle_composition2_table ={
			name = {"sg_counter_vehicle1"},
			vehicle_type = {"tau_skyray_squad"} }
		
		elseif g_kauyon_destroyed == false then
		
			t_vehicle_composition2_table ={
			name = {"sg_counter_vehicle1"},
			vehicle_type = {"tau_krootox_squad"} }
		
		end
		
	end
	
	local i = g_spawn_vehicle_composition2_iter
	
	print("inside vehicle comp 2")
	
	if g_stop_vehicles == 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_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
	
	end
	--g_spawn_vehicle_composition2_iter = g_spawn_vehicle_composition2_iter + 1
	
	if g_spawn_vehicle_composition2_iter >=  table.getn(t_vehicle_composition2_table.name) then
		
		g_stop_vehicles = true
		
		if g_counterattack_sent == true 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
			
			g_stop_vehicles = false
			
		end
		
	elseif g_spawn_vehicle_composition2_iter < table.getn(t_vehicle_composition2_table.name) then
		
		g_spawn_vehicle_composition2_iter = 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
	
	if g_construction_zone == "eg_tau_construction1" or g_construction_zone == "eg_tau_construction5" then
		
		if g_montka_destroyed == true then
			
			t_vehicle_composition3_table ={
			name = {"sg_counter_vehicle1", "sg_counter_vehicle2", "sg_counter_vehicle3"},
			vehicle_type = {"tau_drone_harbinger_squad", "tau_drone_harbinger_squad",  "tau_drone_harbinger_squad"} }
			
		elseif g_montka_destroyed == false then
			
		t_vehicle_composition3_table ={
			name = {"sg_counter_vehicle1", "sg_counter_vehicle2", "sg_counter_vehicle3"},
			vehicle_type = {"tau_drone_harbinger_squad", "tau_hammerhead_gunship_squad", "tau_drone_harbinger_squad"} }
			
		end
		
	elseif g_construction_zone == "eg_tau_construction2" or g_construction_zone == "eg_tau_construction6" then
		
		t_vehicle_composition3_table ={
				name = {"sg_counter_vehicle1", "sg_counter_vehicle2"},
		vehicle_type = {"tau_skyray_squad", "tau_skyray_squad"} }
		
		
	elseif g_construction_zone == "eg_tau_construction3" or g_construction_zone == "eg_tau_construction4" then
		
		if g_kauyon_destroyed == true then
			
			t_vehicle_composition3_table ={
			name = {"sg_counter_vehicle1", "sg_counter_vehicle2"},
			vehicle_type = {"tau_drone_harbinger_squad", "tau_drone_harbinger_squad"} }  -- ***instead of krootox use regular vehicle
			
		elseif g_kauyon_destroyed == false then
			
			t_vehicle_composition3_table ={
			name = {"sg_counter_vehicle1", "sg_counter_vehicle2", "sg_counter_vehicle3"},
			vehicle_type = {"tau_krootox_squad", "tau_greater_knarloc_squad", "tau_krootox_squad"} }
			
		end
		
	end
	
	local i = g_spawn_vehicle_composition3_iter
	
	print("inside vehicle comp 3")
	
	
	--[[if ((g_vehicle_construction_zone == "eg_vehicle_construction3") or (g_vehicle_construction_zone == "eg_vehicle_construction4")) and
				g_kauyon_destroyed == true	then
			
			end]]
	
	
	
	if g_stop_vehicles == 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_composition3_table.name[i], t_vehicle_composition3_table.vehicle_type[i], 
				locked_source3, 1, 1) --t_tau_captured_major_names[final_random_tau_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
	
	end
	--g_spawn_vehicle_composition3_iter = g_spawn_vehicle_composition3_iter + 1
	
	if g_spawn_vehicle_composition3_iter >= table.getn(t_vehicle_composition3_table.name) then
	
		g_stop_vehicles = true
		
		if g_counterattack_sent == true 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
			
			g_stop_vehicles = false
			
		end
		
	elseif g_spawn_vehicle_composition3_iter < table.getn(t_vehicle_composition3_table.name) then
		
		g_spawn_vehicle_composition3_iter = 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

	if g_construction_zone == "eg_tau_construction1" or g_construction_zone == "eg_tau_construction5" then
	
		if g_montka_destroyed == true then
			
			t_vehicle_composition4_table ={
			name = {"sg_counter_vehicle1", "sg_counter_vehicle2"},
			vehicle_type = {"tau_skyray_squad", "tau_skyray_squad"} }
			
		elseif g_montka_destroyed == false then
		
		t_vehicle_composition4_table ={
			name = {"sg_counter_vehicle1", "sg_counter_vehicle2"},
			vehicle_type = {"tau_skyray_squad", "tau_hammerhead_gunship_squad"} }
			
		end
		
	elseif g_construction_zone == "eg_tau_construction2" or g_construction_zone == "eg_tau_construction6" then
	
		t_vehicle_composition4_table ={
				name = {"sg_counter_vehicle1", "sg_counter_vehicle2"},
		vehicle_type = {"tau_skyray_squad", "tau_skyray_squad"} }
		
	
	elseif g_construction_zone == "eg_tau_construction3" or g_construction_zone == "eg_tau_construction4" then
	
		if g_kauyon_destroyed == true then
			t_vehicle_composition4_table ={
			name = {"sg_counter_vehicle1", "sg_counter_vehicle2"},
			vehicle_type = {"tau_drone_harbinger_squad", "tau_skyray_squad"} }
		elseif g_kauyon_destroyed == false then
			t_vehicle_composition4_table ={
			name = {"sg_counter_vehicle1", "sg_counter_vehicle2"},
			vehicle_type = {"tau_krootox_squad", "tau_greater_knarloc_squad"} }
		end
		
	end
	
	local i = g_spawn_vehicle_composition4_iter
	
	print("inside vehicle comp 4")
	
	if g_stop_vehicles == 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_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_tau_captured_major_names[final_random_tau_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
	end
	
	if g_spawn_vehicle_composition4_iter >= table.getn(t_vehicle_composition4_table.name) then
		
		g_stop_vehicles = true
		
		if g_counterattack_sent == true 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
			
			g_stop_vehicles = false
			
		end
		
	elseif g_spawn_vehicle_composition4_iter < table.getn(t_vehicle_composition4_table.name) then
		
		g_spawn_vehicle_composition4_iter = 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_Early_Composition_Set() -- first 3 waves --g_waves = 4 -- test

if g_waves <= 4 then
	
	g_composition_type = t_tau_counterattack_data.easy_composition
	g_counterattack_unit_composition = t_tau_counterattack_data.easy_composition
	
	
elseif g_waves >= 5 and g_waves < 7 then

	g_composition_type = t_tau_counterattack_data.composition
	g_counterattack_unit_composition = t_tau_counterattack_data.composition

elseif g_waves >= 7 then
	
	--g_composition_type = t_tau_counterattack_data.composition
	--Rule_Check_AddInterval(Rule_Composition_And_Secondary_Objective_Tracker, 1)
	Rule_Remove(Rule_Early_Composition_Set)
	
end

end

function Rule_Composition_And_Secondary_Objective_Tracker() -- changes the type of units that will attack the player depending on the shrines being destroyed, etc.

if g_montka_destroyed == false and g_kauyon_destroyed == true then -- no kroot specials
	
	--g_composition_type = t_tau_counterattack_data.composition2
	g_vehicle_type = 2 --1
	
elseif g_montka_destroyed == true and g_kauyon_destroyed == false then -- no tau specials
	
	--g_composition_type = t_tau_counterattack_data.composition3
	g_vehicle_type = 3 -- 2
	
elseif g_montka_destroyed == true and g_kauyon_destroyed == true then --no tau or kroot uber units, but auxillaries
	
	--g_composition_type = t_tau_counterattack_data.composition4
	
	--g_stop_counterattacks = true
	g_citadel_last_stand = true
	
	g_vehicle_type = 1  --3
	
end

end

--this function makes the citadel counterattack functions kick off only after 2 bases have been captured, and then turns itself off function Rule_Citadel_Threshold()

--test --g_bases_captured = 3

if g_bases_captured >= 4 then
	
	Rule_AddOneShot(Rule_IE_Citadel_Initiates_Attacks, 0)
	
	Rule_AddIntervalDelay(Rule_Citadel_Counterattack_Activation, 10, 60)	
	
	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
			
			if g_citadel_last_stand == false then -- when the shrines are still around
			
				-- 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, 2)	
					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(1, 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(1, 2)	
				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_tau_counterattack_data.citadel_composition)) --t_tau_counterattack_data.composition
					-- rand2 is to be used for the squad sizes
					local rand2 = World_GetRand(3, g_med_deployment_size)
					
					Util_CreateSquadsAtMarkerEx(g_Player2, "sg_citadel_raider"..n, t_tau_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])
					
				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_Ethereal_Ping_Stop() Util_Ping_Stop("ping_ethereal") end

function Rule_Unity_Ping_Stop() Util_Ping_Stop("ping_unity_plaza_capture") end

function Rule_Montka_Ping_Stop() Util_Ping_Stop("ping_montka_shrine") end

function Rule_Kauyon_Ping_Stop() Util_Ping_Stop("ping_kauyon_shrine") end

function Rule_Comm_Ping_Stop() Util_Ping_Stop("ping_comm_tower") end

function Rule_Ethereal_Protection()

if Player_AreSquadsNearMarker(g_Player1, "mkr_bodyguard_trigger1") and g_honour_guard5_jumped == false then
	if SGroup_Exists("sg_tau_honour_guard5") and SGroup_IsEmpty("sg_tau_honour_guard5") == false then
		Cmd_JumpToMarker("sg_tau_honour_guard5", "mkr_bodyguard_jump1")
		g_honour_guard5_jumped = true
		
		Rule_AddOneShot(Rule_IE_Player_Breaches_Citadel, 0)
		
	end
	
end

if Player_AreSquadsNearMarker(g_Player1, "mkr_bodyguard_trigger2") and g_honour_guard6_jumped == false then
	if SGroup_Exists("sg_tau_honour_guard6") and SGroup_IsEmpty("sg_tau_honour_guard6") == false then
		Cmd_JumpToMarker("sg_tau_honour_guard6", "mkr_bodyguard_jump2")
		g_honour_guard6_jumped = true
		
		Rule_AddOneShot(Rule_IE_Player_Breaches_Citadel2, 0)
		
	end
end


if Player_AreSquadsNearMarker(g_Player1, "mkr_last_line_defense") and g_honour_guard12_jumped == false then
	if SGroup_Exists("sg_tau_honour_guard12") and SGroup_IsEmpty("sg_tau_honour_guard12") == false then
		Cmd_JumpToMarker("sg_tau_honour_guard12", "mkr_bodyguard_jump3")
		g_honour_guard12_jumped = true
		
		if g_honour_guard13_jumped == false then
			Rule_AddOneShot(Rule_IE_Player_Breaches_Citadel3, 0) -- temporarily disabled until we get the 3 breech texts
		end
		
	end
	
end

if Player_AreSquadsNearMarker(g_Player1, "mkr_last_line_defense") and g_honour_guard13_jumped == false then
	if SGroup_Exists("sg_tau_honour_guard13") and SGroup_IsEmpty("sg_tau_honour_guard13") == false then
		Cmd_JumpToMarker("sg_tau_honour_guard13", "mkr_bodyguard_jump4")
		g_honour_guard13_jumped = true
		
		if g_honour_guard12_jumped == false then
			Rule_AddOneShot(Rule_IE_Player_Breaches_Citadel3, 0) -- temporarily disabled until we get the 3 breech texts
		end
		
		
	end
end

if g_honour_guard5_jumped == true and g_honour_guard6_jumped == true and 
	g_honour_guard12_jumped == true and g_honour_guard13_jumped == true then
	
	Rule_Remove(Rule_Ethereal_Protection)
	
end

end

function Rule_Comm_Tower_Objective_Start() --function Rule_Unity_Plaza_Objective_Start()

if Player_AreSquadsNearMarker(g_Player1, "mkr_unity_plaza_detection") then
	
	--Rule_AddOneShot(Rule_IE_Unity_Plaza_Fortified, 1)
	--Rule_AddIntervalDelay(Rule_Objective_Capture_Unity_Plaza, 1, 2)
	--Rule_AddIntervalDelay(Rule_Objective_Use_Comm_Tower, 1, 5)
	--Rule_AddOneShot(Rule_Comm_Tower_Kickoff, 15)
	--Rule_AddOneShot(Rule_Tap_Tau_Button, 15)
	
	--Rule_AddOneShot(Rule_Button_Setup, 15)
	
	
	Rule_AddIntervalDelay(Rule_Objective_Use_Comm_Tower, 1, 1)
	
	Rule_AddOneShot(Rule_Race_Specific_Com_Tower_Speech, 2)
	
	
	
	Rule_AddInterval(Rule_Button_Kickoff, 2)
	
	
	
	Rule_Remove(Rule_Comm_Tower_Objective_Start)
	
end

end

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

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

end

function Rule_Increment_Timer()

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

end]]

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

if EGroup_IsCapturedByPlayer("eg_unity_plaza_relic", g_Player1, true) then
	
	Rule_AddIntervalDelay(Rule_Plaza_Revenge_Activation, 5, 5)
	
	Rule_Remove(Rule_Plaza_Captured_Detect)
	
	g_plaza_captured = true
	
end

end

function Rule_Plaza_Revenge_Activation() --function Rule_Plaza_Revenge_Speech()

if g_plaza_captured == true then
	
	if g_montka_destroyed == false and g_kauyon_destroyed == false then
		-- some dialogue then the game sends a force to attack, followed by a brief FOW reveal
		
		g_plaza_attack_type = 1
		
		--Rule_AddOneShot(Rule_IE_Unity_Plaza_Fallen, 1)
		Rule_AddIntervalDelay(Rule_Recapture_Plaza, 15, 5)
					
		
	elseif g_montka_destroyed == true and g_kauyon_destroyed == false then
		
		g_plaza_attack_type = 2
		
		--Rule_AddOneShot(Rule_IE_Unity_Plaza_Fallen_Montka_Destroyed, 1)
		Rule_AddIntervalDelay(Rule_Recapture_Plaza, 15, 5)
		
	elseif g_montka_destroyed == false and g_kauyon_destroyed == true then
		
		g_plaza_attack_type = 3
		
		--Rule_AddOneShot(Rule_IE_Unity_Plaza_Fallen_Kauyon_Destroyed, 1)
		Rule_AddIntervalDelay(Rule_Recapture_Plaza, 15, 5)
		
	elseif g_montka_destroyed == true and g_kauyon_destroyed == true then
		
		g_plaza_attack_type = 4
		
		--Rule_AddOneShot(Rule_IE_Unity_Plaza_Fallen_Shrines_Destroyed, 1)
		
		
	end
	
	
	Rule_Remove(Rule_Plaza_Revenge_Activation) -- removes rule from game after the speech has been played
	
end

end

function Rule_Recapture_Plaza()

if SGroup_Exists("sg_plaza_recapture") == false or SGroup_IsEmpty("sg_plaza_recapture") then
	
	local l_rand3 = World_GetRand(3, 4)
	local l_rand4 = World_GetRand(3, 4)
	
	if g_plaza_attack_type == 1 then -- neither shrine destroyed
		
		
		SGroup_CreateIfNotFound("sg_plaza_recapture")
		
		for x = 1, l_rand3 do
			
			local l_rand1 = World_GetRand(1, table.getn(t_tau_counterattack_data.plaza_composition1)) -- montka
			
			if EGroup_Exists("eg_tau_construction5") and EGroup_IsEmpty("eg_tau_construction5") == false then
				Util_CreateSquadsAtMarkerEx(g_Player2, "sg_plaza_recapture1", t_tau_counterattack_data.plaza_composition1[l_rand1], "mkr_plaza_recapture_spawn1", 1, 8)
				SGroup_AddGroup(SGroup_FromName("sg_plaza_recapture"), SGroup_FromName("sg_plaza_recapture1"))
				
				Cmd_AttackMoveMarker("sg_plaza_recapture1", "mkr_plaza_recapture_destination")
				FOW_RevealSGroup("sg_plaza_recapture1", 10)
				
				
			end
			
		end
		
		for x = 1, l_rand4 do
			
			local l_rand2 = World_GetRand(1, table.getn(t_tau_counterattack_data.plaza_composition2)) -- kauyon
			
			if EGroup_Exists("eg_tau_construction3") and EGroup_IsEmpty("eg_tau_construction3") == false then
				Util_CreateSquadsAtMarkerEx(g_Player2, "sg_plaza_recapture2", t_tau_counterattack_data.plaza_composition2[l_rand2], "mkr_plaza_recapture_spawn2", 1, 8)
				SGroup_AddGroup(SGroup_FromName("sg_plaza_recapture"), SGroup_FromName("sg_plaza_recapture2"))
				
				Cmd_AttackMoveMarker("sg_plaza_recapture2", "mkr_plaza_recapture_destination")
				FOW_RevealSGroup("sg_plaza_recapture2", 10)
				
				
			end
			
		end
		
		Rule_AddInterval(Rule_Recapture_Plaza_Idle_Fix, 5)
		
		Rule_Remove(Rule_Recapture_Plaza)
		
		
	elseif g_plaza_attack_type == 2 then -- montka destroyed
		
		SGroup_CreateIfNotFound("sg_plaza_recapture")
		
		for x = 1, l_rand4 do
			
			local l_rand2 = World_GetRand(1, table.getn(t_tau_counterattack_data.plaza_composition2)) -- kauyon generation
			
			
			if EGroup_Exists("eg_tau_construction3") and EGroup_IsEmpty("eg_tau_construction3") == false then
				
				Util_CreateSquadsAtMarkerEx(g_Player2, "sg_plaza_recapture2", t_tau_counterattack_data.plaza_composition2[l_rand2], "mkr_plaza_recapture_spawn2", 1, 8)
				SGroup_AddGroup(SGroup_FromName("sg_plaza_recapture"), SGroup_FromName("sg_plaza_recapture2"))
				
				Cmd_AttackMoveMarker("sg_plaza_recapture2", "mkr_plaza_recapture_destination")
				FOW_RevealSGroup("sg_plaza_recapture2", 10)
				
			end
		end
		
		Rule_AddInterval(Rule_Recapture_Plaza_Idle_Fix, 5)
		
		Rule_Remove(Rule_Recapture_Plaza)
		
		
	elseif g_plaza_attack_type == 3 then -- kauyon destroyed
		
		SGroup_CreateIfNotFound("sg_plaza_recapture")
		
		for x = 1, l_rand3 do
			
			local l_rand1 = World_GetRand(1, table.getn(t_tau_counterattack_data.plaza_composition1)) -- montka generation
			
			
			
			if EGroup_Exists("eg_tau_construction5") and EGroup_IsEmpty("eg_tau_construction5") == false then
				
				Util_CreateSquadsAtMarkerEx(g_Player2, "sg_plaza_recapture1", t_tau_counterattack_data.plaza_composition1[l_rand1], "mkr_plaza_recapture_spawn1", 1, 8)
				SGroup_AddGroup(SGroup_FromName("sg_plaza_recapture"), SGroup_FromName("sg_plaza_recapture1"))
				
				Cmd_AttackMoveMarker("sg_plaza_recapture1", "mkr_plaza_recapture_destination")
				FOW_RevealSGroup("sg_plaza_recapture1", 10)
				
			end
		
		end
		
		Rule_AddInterval(Rule_Recapture_Plaza_Idle_Fix, 5)
		
		Rule_Remove(Rule_Recapture_Plaza)
		
		
	elseif g_plaza_attack_type == 4 then -- both shrines destroyed
		
		Rule_Remove(Rule_Recapture_Plaza)
		
	end
	
end

end

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

if SGroup_Exists("sg_plaza_recapture") and (SGroup_IsEmpty("sg_plaza_recapture") == false) and 
SGroup_CheckActiveCommand("sg_plaza_recapture", SQUADSTATEID_Idle, true) then
	
	Cmd_Capture("sg_plaza_recapture", "eg_flag6")
	
	--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_plaza_recapture", "mkr_tau_outpost6_area") then
		
		if EGroup_IsCapturedByPlayer("eg_flag6", g_Player1, false) == true or Entity_GetWorldOwner(EGroup_GetSpawnedEntityAt(EGroup_FromName("eg_flag6"), 1)) == true then
			
			Cmd_Capture("sg_plaza_recapture", "eg_flag6")
			
		elseif EGroup_IsCapturedByPlayer("eg_flag6", 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)
			
			Cmd_SetStance("sg_plaza_recapture", STANCE_Hold)
			Rule_Remove(Rule_Recapture_Plaza_Idle_Fix)
			Rule_AddInterval(Rule_Recapture_Plaza, 120)
			--end
			
		end
		
	end
	
elseif SGroup_Exists("sg_plaza_recapture") and (SGroup_IsEmpty("sg_plaza_recapture") == true) then
	
	Rule_Remove(Rule_Recapture_Plaza_Idle_Fix)
	Rule_AddInterval(Rule_Recapture_Plaza, 120)
	
end

end


--[[Comm Tower Stuff]]


--[[ Tapping into the Tau communications grid ]]

--[[ --The first function sets up the button's stats. The current icons are temporary until I can get some real ones, if this mechanic is approved. function Rule_Tap_Tau_Button()

t_tap_tau_button = {
	button_icon = {--[[1]]"Scar_buttons/switchto_Ork", --[[2]]"Scar_buttons/switchto_Ork", --[[3]]"Scar_buttons/switchto_Ork"},
	button_description = {--[[1]]"$2830023", --[[2]]"$2830024"}, 
}

g_buttonID1 = Util_ScarButton_Create("btn_ScarUI", t_tap_tau_button.button_icon, t_tap_tau_button.button_description, true, true)

end]]


--[[Modal Button Experiment]] -- Thanks, Berger

function Rule_Button_Kickoff()

if Player_AreSquadsNearMarker(g_Player1, "mkr_comm_tower_radius") and (Player_AreSquadsNearMarker(g_Player2, "mkr_comm_tower_radius") == false) then
	
	--Rule_AddOneShot(Rule_Button_Setup, 1)
	--Rule_AddOneShot(Rule_IE_Placeholder_Comm_Tower_First_Time, 0)
	

-- Rule_AddOneShot(Rule_Race_Specific_Com_Tower_Speech, 1)

	--Rule_AddIntervalDelay(Rule_Objective_Use_Comm_Tower, 1, 5)
	
	Rule_Check_AddInterval(Rule_Comm_Tower_Animation_Control, 2)
		
	Rule_Remove(Rule_Button_Kickoff)
end

end

function Rule_Comm_Tower_Animation_Control()

if Player_AreSquadsNearMarker(g_Player1, "mkr_comm_tower_radius")  and (Player_AreSquadsNearMarker(g_Player2, "mkr_comm_tower_radius") == false) then
	
	if g_tower_animation_played == false and g_comm_tower_count == 0 then
	
		EGroup_SetPlayerOwner("eg_comm_tower", g_Player1)
	
		Anim_PlayEGroupAnim(EGroup_FromName("eg_comm_tower"), "sp_activation")
		g_tower_animation_played = true
		
		g_comm_ability_on = true
		
		--Button_SetEnabled(g_buttonID1, true)
		--Button_SetVisible(g_buttonID1, true )
		
		if g_mid_nis_played == false then
		
			Util_StartNIS( EVENTS.NIS_Mid ) 	
			
			-- will start entity detection for the entity spawned when you use the detection ability in NIS
			
			g_mid_nis_played = true
		
		end
		
		
		Rule_Check_AddInterval(Rule_Comm_Tower_Count, 1)
		
	end
	
elseif Player_AreSquadsNearMarker(g_Player1, "mkr_comm_tower_radius") == false or (Player_AreSquadsNearMarker(g_Player2, "mkr_comm_tower_radius") == true) then
	
	if g_tower_animation_played == true and g_comm_tower_count == 13 then
		
		EGroup_SetPlayerOwner("eg_comm_tower", g_Player2)
		
		Anim_PlayEGroupAnim(EGroup_FromName("eg_comm_tower"), "sp_de_activation")
		g_tower_animation_played = false
		
		g_comm_ability_on = false
		
		--Button_SetEnabled(g_buttonID1, false)
		--Button_SetVisible(g_buttonID1, false )
		
		Rule_Check_AddInterval(Rule_Comm_Tower_Count2, 1)
		
	end
	
end

end

function Rule_Comm_Tower_Count()

g_comm_tower_count = g_comm_tower_count + 1

if g_comm_tower_count >= 13 then
	
	Rule_Remove(Rule_Comm_Tower_Count)
	
	g_comm_tower_count = 13
end

end

function Rule_Comm_Tower_Count2()

g_comm_tower_count = g_comm_tower_count - 1

if g_comm_tower_count <= 0 then
	
	Rule_Remove(Rule_Comm_Tower_Count2)
	
	g_comm_tower_count = 0
	
end

end

--[[ function Rule_Button_Setup()

t_infiltration_scanner = {
	button_icon = {--[[1]]"Scar_buttons/Titan_weapon", --[[2]]"Scar_buttons/Titan_weapon", --[[3]]"Scar_buttons/Titan_weapon"},
	button_description = {--[[1]]"$2840100", --[[2]]"$2840102"}, 
}


g_buttonID1 = Util_AbilityButton_CreateModal(t_infiltration_scanner.button_icon, t_infiltration_scanner.button_description, true)



Rule_AddIntervalDelay(Rule_Leader_Check, 1,2)


Rule_AddDelay(Rule_Button_Click, 10)

end]]

--[[ function Rule_Leader_Check()

Misc_GetSelectedSquads(SGroup_CreateIfNotFound("sg_Leader_Potential"))
if SGroup_Count(SGroup_FromName("sg_Leader_Potential")) > 0 and (SGroup_ContainsBlueprints(SGroup_FromName("sg_Leader_Potential"), t_blueprintleader, false) or SGroup_ContainsBlueprints(SGroup_FromName("sg_Leader_Potential"), t_advanced_blueprintleader, false))

then
	
	SGroup_AddGroup(SGroup_CreateIfNotFound("sg_Player_Leader"), SGroup_FromName("sg_Leader_Potential"))
	SGroup_Clear("sg_Leader_Potential")
	
	if g_add_button == true then
		Util_ButtonManagerUpdateAll()
	else
		Util_SGroupAbilityButton_Add2Manager(g_buttonID1, "sg_Player_Leader")
		g_add_button = true
	end

	
end	
	
	

end]]

--[[ function Rule_Button_Click()

--if Player_AreSquadsNearMarker(g_Player1, "mkr_comm_tower_radius") and (Player_AreSquadsNearMarker(g_Player2, "mkr_comm_tower_radius") == false) then
if g_comm_ability_on == true then

	--Button_SetEnabled(g_buttonID1, true)

	if g_detector_planted == false then
	
		Button_SetEnabled(g_buttonID1, true)

	
		if Button_GetPressed(g_buttonID1) == true then
			
			
			local pos  = Button_GetPressedPosition(g_buttonID1)
			
			--print("button pressed")
			
			--if Player_CanSeePosition(g_Player1, pos ) then
				
				
				
				--[[
				potential_squadsSGroupID = Player_GetSquads(g_Player2)
				SGroup_CreateIfNotFound("sg_player2_units")
				SGroup_AddGroup(SGroup_FromName("sg_player2_units"), potential_squadsSGroupID)]]
				
				
				--SGroup_ForEachAllOrAny( potential_squadsSGroupID, true, Rule_Grab_Stealth )
				--if Player_CanSeeSGroup(g_Player1, "sg_player2_units", false) and Player_AreSquadsNearMarker(g_Player1, "mkr_comm_tower_radius") then
				
				if Player_CanSeePosition(g_Player1, pos) and Player_AreSquadsNearMarker(g_Player1, "mkr_comm_tower_radius") then
				
					--local pos = SGroup_GetPosition(SGroup_FromName("sg_stealthed")) -- gets the current position of stealth defenders
					--pos.x = pos.x + 5 
					--pos.y = pos.y - 5
					if Entity_CreateBuildingPosition(g_Player1, "eg_detector", "npc_infiltration_spotter", pos, 1) then
					
						--print("detector created")
						
						g_detector_planted = true
						
						g_detector_count = 0 
						
						Button_SetEnabled(g_buttonID1, false)
						
						if g_button_pressed_first_time == true then
						
							g_button_pressed_first_time = false
						end
						
						
						
						Rule_AddInterval(Rule_Detector_Despawn_Countdown, 1)
						Rule_Remove(Rule_Button_Click)
						
					end
					
				else	
				
					UIWarning_Show("$2840110")
				
				end
				
				
				
		end
		
	end
	
elseif g_comm_ability_on == false then

	Button_SetEnabled(g_buttonID1, false)
	
end

end ]]

--[[ function Rule_Detector_Despawn_Countdown()

if g_detector_count <= 9 then
	
	g_detector_count = g_detector_count + 1
	
elseif g_detector_count >=10 then
	
	EGroup_DeSpawn("eg_detector")
	EGroup_DestroyAllEntities("eg_detector")
	
	--print("detector despawned")
	
	--g_detector_planted = false
	g_detector_count = 0
	
	Rule_AddOneShot(Rule_Button_Reset, 10)
	Rule_Remove(Rule_Detector_Despawn_Countdown)
	
	--print("reset! wait 10 seconds")
	
end

end]] --[[ function Rule_Button_Reset() --print("detector is now false") g_detector_planted = false Rule_Add(Rule_Button_Click)

end]]

--[[ function Rule_Comm_Tower_Occupation_Check()

if Player_AreSquadsNearMarker(g_Player1, "mkr_comm_tower_radius") == false and Player_AreSquadsNearMarker(g_Player2, "mkr_comm_tower_radius") == true then
	
	Button_SetEnabled(g_buttonID1, false)
	
end

end]]

-----test

function Burrow_Test()

Util_CreateSquadsAtMarkerEx(g_Player2, "blah", "tau_drone_squad", "mkr_player_spawn3", 2, 4)
Command_Squad(g_Player2, SGroup_FromName("blah"), SCMD_BurrowToggle)

end



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 = {Rule_IE_Generic_Taunt1_Commander, Rule_IE_Generic_Taunt2_Commander, Rule_IE_Generic_Taunt3_Commander, 
															Rule_IE_Generic_Taunt1_Ethereal, Rule_IE_Generic_Taunt2_Ethereal, Rule_IE_Generic_Taunt3_Ethereal}}


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)

	g_previous_line_used = l_random_line
	
end

end


--[[random movement at bases]]

function Rule_Tau_Base_Defender1_Movement()

for i = 1,6 do
	
	if SGroup_Exists("sg_tau_outpost"..i.."_defender1") and SGroup_IsEmpty("sg_tau_outpost"..i.."_defender1") == false and (SGroup_IsUnderAttack("sg_tau_outpost"..i.."_defender1", false) == false) then
		
		Util_AttackMoveMarkerRandomRadius("sg_tau_outpost"..i.."_defender1", "mkr_outpost"..i.."_wandering")
		
	else --if SGroup_Exists("sg_tau_outpost"..i.."_defender1") == false or SGroup_IsEmpty("sg_tau_outpost"..i.."_defender1") == true  then
		
		--Rule_Remove(Rule_Tau_Base_Defender1_Movement)
		
	end
	
end

end

function Rule_Tau_Base_Defender2_Movement()

for i = 1,6 do
	
	if SGroup_Exists("sg_tau_outpost"..i.."_defender2") and SGroup_IsEmpty("sg_tau_outpost"..i.."_defender2") == false and (SGroup_IsUnderAttack("sg_tau_outpost"..i.."_defender2", false) == false) then
		
		Util_AttackMoveMarkerRandomRadius("sg_tau_outpost"..i.."_defender2", "mkr_outpost"..i.."_wandering")
		
	else --if SGroup_Exists("sg_tau_outpost"..i.."_defender2") == false or SGroup_IsEmpty("sg_tau_outpost"..i.."_defender2") == true  then
		
		--Rule_Remove(Rule_Tau_Base_Defender2_Movement)
		
	end
	
end

end

function Rule_Detect_Comm_Entity()

if Player_GetBlueprintCount(g_Player1, "guard_detection_field_sp") >= 1 then
	
	if g_button_pressed_first_time == true then
		
		g_button_pressed_first_time = false
		
	end
	
	Rule_Remove(Rule_Detect_Comm_Entity)
	
end

end


--[[ Objective Kill Ethereal ]]

--This primary objective is to kill the Ethereal function Rule_Objective_Kill_Ethereal()

Objective_Kill_Ethereal = { title_id = 2820000, short_desc_id = 2820002, help_tip_id = 2820000 }

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Kill_Ethereal.title_id) == false then
	
	Util_WXP_ObjectiveCreate( Objective_Kill_Ethereal, true, g_Player1 )
	
	--sets pings
	Util_Ping_LoopingMkr( "ping_ethereal", "mkr_tau_ethereal_spawn" )
	
	FOW_RevealMarker( "mkr_tau_ethereal_spawn", 10 )
	
	Rule_AddOneShot(Rule_Ethereal_Ping_Stop, 10)
	
	t_obj_kill_ethereal_ping = Objective_PingMarker(Objective_Kill_Ethereal.title_id, "mkr_tau_ethereal_spawn", true, "default")
	
	Objective_ShowScreen()	
	Flash_OtherButton("dlg_objectives", 0, false, true)
	
elseif Event_IsAnyRunning() == false and g_player_win == true then
	
	Util_ObjectiveComplete(Objective_Kill_Ethereal.title_id)
	
	--Util_Ping_Stop("ping_ethereal")
	
	Objective_PingRemove(Objective_Kill_Ethereal.title_id, t_obj_kill_ethereal_ping)
	
	--Rule_AddOneShot(Rule_IE_Tau_Retreat, 0)
	
	
	Rule_Remove(Rule_Objective_Kill_Ethereal)
	
	Util_StartNIS( EVENTS.NIS_Closing )
	
end

end

--[[This secondary objective is for the use of the Comm Tower to detect enemy units]] function Rule_Objective_Use_Comm_Tower()

Objective_Use_Comm_Tower = { title_id = 2826000, short_desc_id = 2826002, help_tip_id = 2826000 }

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Use_Comm_Tower.title_id) == false then
	
	Util_WXP_ObjectiveCreate( Objective_Use_Comm_Tower, false, g_Player1 )
	
	Util_Ping_LoopingMkr("ping_comm_tower", "mkr_comm_tower_radius")
	
	Rule_AddOneShot(Rule_Comm_Ping_Stop, 10)
	
	t_obj_tau_comm_ping = Objective_PingMarker(Objective_Use_Comm_Tower.title_id, "mkr_comm_tower_radius", true, "default")
	
	Objective_ShowScreen()	
	Flash_OtherButton("dlg_objectives", 0, false, true)
	
elseif Event_IsAnyRunning() == false and g_button_pressed_first_time == false then
	
	Util_ObjectiveComplete(Objective_Use_Comm_Tower.title_id)
	
	Objective_PingRemove(Objective_Use_Comm_Tower.title_id, t_obj_tau_comm_ping)
	
	--Util_Ping_Stop("ping_unity_plaza_capture")
		
	--Rule_AddOneShot(Rule_IE_Comm_Tower_Captured, 1)
	
	--CALL MID NIS HERE!!!!!!!!!!!
		
	Rule_Remove(Rule_Objective_Use_Comm_Tower)
	
end

end

--[[This secondary objective is for the destruction of the Kauyon Shrine in the Kroot quarter]] function Rule_Objective_Destroy_Kauyon_Shrine()

Objective_Destroy_Kauyon_Shrine = { title_id = 2823000, short_desc_id = 2823002, help_tip_id = 2823000 }

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Destroy_Kauyon_Shrine.title_id) == false then
	
	Util_WXP_ObjectiveCreate( Objective_Destroy_Kauyon_Shrine, false, g_Player1 )
	
	Util_Ping_LoopingMkr("ping_kauyon_shrine", "mkr_kauyon_shrine")
	
	Rule_AddOneShot(Rule_Kauyon_Ping_Stop, 10)
	
	t_obj_tau_destroy_kroot_ping = Objective_PingMarker(Objective_Destroy_Kauyon_Shrine.title_id, "mkr_kauyon_shrine", true, "default")
	
	Rule_AddIntervalDelay(Rule_Objective_Destroy_Montka_Shrine, 1, 1)
	
elseif Event_IsAnyRunning() == false and (EGroup_Exists("eg_kauyon_shrine") and EGroup_IsEmpty("eg_kauyon_shrine")) then
	
	Util_ObjectiveComplete(Objective_Destroy_Kauyon_Shrine.title_id)
	
	Objective_PingRemove(Objective_Destroy_Kauyon_Shrine.title_id, t_obj_tau_destroy_kroot_ping)
	
	--Util_Ping_Stop("ping_kauyon_shrine")
	
	g_kauyon_destroyed = true
	
	Rule_AddOneShot(Rule_IE_Kauyon_Objective_Destroyed, 0)
	
	Rule_Remove(Rule_Objective_Destroy_Kauyon_Shrine)
	
end

end

--[[This secondary objective is for the destruction of the Montka Shrine]] function Rule_Objective_Destroy_Montka_Shrine()

Objective_Destroy_Montka_Shrine = { title_id = 2824000, short_desc_id = 2824002, help_tip_id = 2824000 }

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Destroy_Montka_Shrine.title_id) == false then
	
	Util_WXP_ObjectiveCreate( Objective_Destroy_Montka_Shrine, false, g_Player1 )
	
	Util_Ping_LoopingMkr("ping_montka_shrine", "mkr_montka_shrine")
	
	Rule_AddOneShot(Rule_Montka_Ping_Stop, 10)
	
	t_obj_tau_destroy_montka_ping = Objective_PingMarker(Objective_Destroy_Montka_Shrine.title_id, "mkr_montka_shrine", true, "default")
	
	Objective_ShowScreen()	
	Flash_OtherButton("dlg_objectives", 0, false, true)
	
elseif Event_IsAnyRunning() == false and EGroup_Exists("eg_montka_shrine") and EGroup_IsEmpty("eg_montka_shrine") then
	
	Util_ObjectiveComplete(Objective_Destroy_Montka_Shrine.title_id)
	
	Objective_PingRemove(Objective_Destroy_Montka_Shrine.title_id, t_obj_tau_destroy_montka_ping)
	
	--Util_Ping_Stop("ping_montka_shrine")
	
	g_montka_destroyed = true
	
	Rule_AddOneShot(Rule_IE_Montka_Objective_Destroyed, 0)
	
	Rule_Remove(Rule_Objective_Destroy_Montka_Shrine)
	
end

end --[[ function Rule_Objective_Build_Detector_Unit()

Objective_Build_Detector_Unit = { title_id = 2824000, short_desc_id = 2824002, help_tip_id = 2824000 }

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Build_Detector_Unit.title_id) == false then
	
	Util_WXP_ObjectiveCreate( Objective_Build_Detector_Unit, false, g_Player1 )
	
	
elseif Event_IsAnyRunning() == false and Player_GetBlueprintCount( g_Player1, "space_marine_squad_rhino" ) >= 1 then
	
	Util_ObjectiveComplete(Objective_Build_Detector_Unit.title_id)
	
	
	Rule_Remove(Rule_Objective_Build_Detector_Unit)
	
end

end]]


--[[ GAME OVER - Player Wins ]]

function Rule_EndGameWin() -- Player wins when Ethereal is dead. --[[ --g_playerHasWon if Objective_Duel_Crull ~= nil and Objective_Exists(Objective_Duel_Crull.title_id) and Objective_GetState(Objective_Duel_Crull.title_id) == OS_Complete then Rule_RemoveAll() Util_StartNIS(EVENTS.NIS_Closing) end]] --[[ if Objective_Kill_Ethereal ~= nil and Objective_Exists(Objective_Kill_Ethereal.title_id) and Objective_GetState(Objective_Kill_Ethereal.title_id) == OS_Complete then Rule_RemoveAll() World_SetTeamWin(g_Player1,"") Rule_AddIntervalEx(Rule_GameOver, 5, 1) end]] if (SGroup_Exists("sg_tau_ethereal") and ( (SGroup_IsEmpty("sg_tau_ethereal")) == true)) or (SGroup_ContainsBlueprints(SGroup_FromName("sg_tau_ethereal"), t_ethereal_blueprint, false) == false) then

--if (SGroup_Exists("sg_tau_ethereal") and (SGroup_IsEmpty("sg_tau_ethereal") == true)) or (Player_GetBlueprintCount( g_Player2, "tau_ethereal_squad_stronghold_sp" ) <= 0) then
	
	g_player_win = true
	
	Rule_Remove(Rule_EndGameWin)
	Rule_Remove(Rule_EndGameLose)
	
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() --[[ t_building_exceptions = { --"tau_listening_post" "eldar_webway_gate", "space_marine_listening_post", "space_marine_turret_bolter" }

g_unit_exceptions = 
{
	--"ork_squad_warboss"
}
]]
--[[ Lose because of Annihilation ]]	
	if( Player_HasBuildingsExcept(g_Player1, t_building_exceptions) == false ) then
		if( Player_HasSquadsExcept(g_Player1, t_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_Build_Detectors()

Util_StartIntel(EVENTS.IE_Build_Detectors)

end]]

--[[ function Rule_IE_Kauyon_Destroyed()

Util_StartIntel(EVENTS.IE_Kauyon_Destroyed)

end

function Rule_IE_Montka_Destroyed()

Util_StartIntel(EVENTS.IE_Montka_Destroyed)

end

function Rule_IE_Unity_Plaza_Fortified()

Util_StartIntel(EVENTS.IE_Unity_Plaza_Fortified)

end]] --[[ function Rule_IE_Protect_Ethereal()

Util_StartIntel(EVENTS.IE_Protect_Ethereal)

end]] --[[ function Rule_IE_Tau_Retreat()

Util_StartIntel(EVENTS.IE_Tau_Retreat)

end]]

--[[ function Rule_IE_Citadel_Attacks()

Util_StartIntel(EVENTS.IE_Citadel_Attacks)

end]] --[[ function Rule_IE_Unity_Plaza_Fallen()

Util_StartIntel(EVENTS.IE_Unity_Plaza_Fallen)

end

function Rule_IE_Unity_Plaza_Fallen_Kauyon_Destroyed()

Util_StartIntel(EVENTS.IE_Unity_Plaza_Fallen_Kauyon_Destroyed)

end

function Rule_IE_Unity_Plaza_Fallen_Montka_Destroyed()

Util_StartIntel(EVENTS.IE_Unity_Plaza_Fallen_Montka_Destroyed)

end

function Rule_IE_Unity_Plaza_Fallen_Shrines_Destroyed()

Util_StartIntel(EVENTS.IE_Unity_Plaza_Fallen_Shrines_Destroyed)

end]] --[[ function Rule_IE_Placeholder_Comm_Tower_First_Time()

Util_StartIntel(EVENTS.IE_Placeholder_Comm_Tower_First_Time)

end]]


--stubs to be used later

function Rule_IE_Shrine_Objective_Given()

Util_StartIntel(EVENTS.IE_Shrine_Objective_Given)

end

function Rule_IE_Montka_Objective_Destroyed()

Util_StartIntel(EVENTS.IE_Montka_Objective_Destroyed)

end

function Rule_IE_Kauyon_Objective_Destroyed()

Util_StartIntel(EVENTS.IE_Kauyon_Objective_Destroyed)

end --[[ function Rule_IE_Tau_First_Encounter()

Util_StartIntel(EVENTS.IE_Tau_First_Encounter)

end ]] function Rule_IE_Com_Tower_Objective_Activation()

Util_StartIntel(EVENTS.IE_Com_Tower_Objective_Activation)

end

function Rule_IE_Com_Tower_Objective_Activation_Chaos()

Util_StartIntel(EVENTS.IE_Com_Tower_Objective_Activation_Chaos)

end

function Rule_IE_Com_Tower_Objective_Activation_Eldar()

Util_StartIntel(EVENTS.IE_Com_Tower_Objective_Activation_Eldar)

end

function Rule_IE_Com_Tower_Objective_Activation_IG()

Util_StartIntel(EVENTS.IE_Com_Tower_Objective_Activation_IG)

end

function Rule_IE_Com_Tower_Objective_Activation_Orks()

Util_StartIntel(EVENTS.IE_Com_Tower_Objective_Activation_Orks)

end

function Rule_IE_Com_Tower_Objective_Activation_Necrons()

Util_StartIntel(EVENTS.IE_Com_Tower_Objective_Activation_Necrons)

end

function Rule_IE_Com_Tower_Objective_Activation_Space_Marines()

Util_StartIntel(EVENTS.IE_Com_Tower_Objective_Activation_Space_Marines)

end

function Rule_IE_Citadel_Initiates_Attacks()

Util_StartIntel(EVENTS.IE_Citadel_Initiates_Attacks)

end

--[[ function Rule_IE_Com_Tower_Captured() -- likely will be Mid NIS

Util_StartIntel(EVENTS.IE_Com_Tower_Captured)

end]]

function Rule_IE_Player_Breaches_Citadel()

Util_StartIntel(EVENTS.IE_Player_Breaches_Citadel)

end

function Rule_IE_Player_Breaches_Citadel2()

Util_StartIntel(EVENTS.IE_Player_Breaches_Citadel2)

end

function Rule_IE_Player_Breaches_Citadel3()

Util_StartIntel(EVENTS.IE_Player_Breaches_Citadel3)

end

function Rule_IE_Ethereal_Sighted_Chaos()

Util_StartIntel(EVENTS.IE_Ethereal_Sighted_Chaos)

end

function Rule_IE_Ethereal_Sighted_Eldar()

Util_StartIntel(EVENTS.IE_Ethereal_Sighted_Eldar)

end

function Rule_IE_Ethereal_Sighted_IG()

Util_StartIntel(EVENTS.IE_Ethereal_Sighted_IG)

end

function Rule_IE_Ethereal_Sighted_Orks()

Util_StartIntel(EVENTS.IE_Ethereal_Sighted_Orks)

end

function Rule_IE_Ethereal_Sighted_Necrons()

Util_StartIntel(EVENTS.IE_Ethereal_Sighted_Necrons)

end

function Rule_IE_Ethereal_Sighted_Space_Marines()

Util_StartIntel(EVENTS.IE_Ethereal_Sighted_Space_Marines)

end

function Rule_IE_Ambush1()

Util_StartIntel(EVENTS.IE_Ambush1)

end

function Rule_IE_Ambush2()

Util_StartIntel(EVENTS.IE_Ambush2)

end

function Rule_IE_Ambush3()

Util_StartIntel(EVENTS.IE_Ambush3)

end

--[[ function Rule_IE_Ambush4()

Util_StartIntel(EVENTS.IE_Ambush4)

end]]

function Rule_IE_Chaos_Mission_Start()

Util_StartIntel(EVENTS.IE_Chaos_Mission_Start)

end

function Rule_IE_Eldar_Mission_Start()

Util_StartIntel(EVENTS.IE_Eldar_Mission_Start)

end

function Rule_IE_IG_Mission_Start()

Util_StartIntel(EVENTS.IE_IG_Mission_Start)

end

function Rule_IE_Orks_Mission_Start()

Util_StartIntel(EVENTS.IE_Orks_Mission_Start)

end

function Rule_IE_Necrons_Mission_Start()

Util_StartIntel(EVENTS.IE_Necrons_Mission_Start)

end

function Rule_IE_Space_Marines_Mission_Start()

Util_StartIntel(EVENTS.IE_Space_Marines_Mission_Start)

end

function Rule_IE_Generic_Taunt1_Commander()

Util_StartIntel(EVENTS.IE_Generic_Taunt1_Commander)

end

function Rule_IE_Generic_Taunt2_Commander()

Util_StartIntel(EVENTS.IE_Generic_Taunt2_Commander)

end

function Rule_IE_Generic_Taunt3_Commander()

Util_StartIntel(EVENTS.IE_Generic_Taunt3_Commander)

end

function Rule_IE_Generic_Taunt1_Ethereal()

Util_StartIntel(EVENTS.IE_Generic_Taunt1_Ethereal)

end

function Rule_IE_Generic_Taunt2_Ethereal()

Util_StartIntel(EVENTS.IE_Generic_Taunt2_Ethereal)

end

function Rule_IE_Generic_Taunt3_Ethereal()

Util_StartIntel(EVENTS.IE_Generic_Taunt3_Ethereal)

end