Mission event file for Tau Stronghold mission
Руководства
/
Mission event file for Tau Stronghold mission
Обновлено 4 years ago от Merric

-- IMPORTS -- import("ScarUtil.scar") : has most of the scar function -- import("WXPScarUtil.scar") : more scar functions from DC and/or WA (I honestly not sure)

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


-- ONGAMESETUP -- OnGameSetup() : Mandatory Function that sets up the mission & sets up the players that are in the mission (Including AI Players). -- This function is run first and starts the entire mission and than starts OnInit( ) -- Also has list of the Global varibles defined in it ( g_ ) -- OnGameRestore() : Mandatory Function called after loading a saved game. -- This function is used to redefine the player slots after loading a saved game

function OnGameSetup() -- Global varibles

-- Place to store the player Race, so I dont have to keep calling the functions to get them
	-- chaos_marine_race, dark_eldar_race, eldar_race, guard_race, necron_race, ork_race, space_marine_race, sisters_race, tau_race
g_raceName = "default_race"

-- What Intel Events race is using
g_intelEvent_raceId = 0 

-- Place to store the player Faction (Example: "Blood Ravens")
g_factionName = "default_factionName"

-- Place to store the Color Scheme being used for player race (Example: "default_1")
g_colorScheme = "default_colorScheme"

-- Place to stores the Type of HQ based on each players race (Example: "chaos_hq")
g_HQ_blueprint = " "

-- Place to stores the Type of Builder used based on each players race (Example: "chaos_squad_slave")
g_Builder_blueprint = " "

-- Tier to determine difficulty level of mission based on stronghold strength
	-- 1 = low, 2 = medium, 3 = high
g_strongholdStrengthTier	=	0	

-- Forward Base Code:
	-- generator markers start at 0
	g_bonus_gen_counter = 0
	-- turrer markers start at 6
	g_bonus_turret_counter = 6

-- Handles Highlightlighting of Objectives
g_PrimaryObjectives 		= -1
g_SecondaryObjectives 	= -1

-- ------------------------------------------BALANCE VARIBLES----------------------------------

	--------------------- Laser Timers  ---------------------------------------------
	
	-- Time it takes for laser to warm up from player discovered until first shot (Hidden Timer)
	g_laserGunWarmupCounterMax = 120
	
	-- Time between shots of the laser (Timer is shown on screen)
	g_laserGunCounterMax = 90
	
	-- Time between player shots of the laser (Timer is shown on screen)
	g_laserGunCounterMax_Player = 90
	
	-- Who actually owns the laser gun 
	g_PlayerOwnsLaserGun = false
	
	-- Stores the Target Position of the Laser Gun
	g_laserTarget_pos = 0

	--------------------- Beacon Timers  --------------------------------------------
	-- Time until the Fleet Arrives (Timer is shown on screen)
	g_beaconCounterMax	=	1800
	g_beaconCounter		=	0
	
	-- At what timer do we play warning IE
	g_fleetWarning	=	300
	
	-- How Much Time is added per Tower Destruction
	g_beaconIncrease_PerTower = 600
	
	-- Track Destruction of the Beacons
	g_beaconDestroyed_One = false
	g_beaconDestroyed_Two = false	
	
	-- Track Arrival of the Tau Fleet
	g_fleet_arrived = false
	
	--------------------- Last Stand Timers -----------------------------------------
	
	-- Time between Air Caste Shots
	g_lastStand_time	=	5
	
	-- Number of Air Caste Targets placed in editor
	g_number_lastStandTargets	=	7
	
	-- Maximum number of times the air caste can fire
	g_lastStand_maxShots	=	10
	
	-- What was last target fired at (so doesn't fire at same one)
	g_lastStand_lastTarget	=	1
	
	--------------------- Resources -------------------------------------------------
	-- Amount of Initial Resource to give each of the AI Players
	g_amountRequisitionToGiveAI = 10000
	g_amountPowerToGiveAI = 5000
	
	-- Amount of Extra Resources to Give Player when they build Moon Base (Non Necron Races)
	g_amountRequisitionToGivePlayer = 2000
	g_amountPowerToGivePlayer = 500
	
	-- Amount of Extra Resource to Give to Necron Player when they build Moon Base (Since Race doesnt use Req)
	g_amountPowerToGiveNecron = 2000
	
	--------------------- Base Troop Production ---------------------------------------
	
	--Time to Wait Until Scouts Dispatched IE from when player is given base (this delay should give player time to start base)
		-- Note: Scouts still have to be produced & walk to base after this timer
	g_scoutDispatchDelay	= 30
	
	-- Time between scout spawns
	g_spawnScoutTimer = 30
	
	-- Number of "Failed" Scout Squads sent before base is alerted 
		-- Subtracts one everytime a pathfinder scout squad is produced to find enemy base
		-- at 0 tau are alerted about player location due to scout failure.
	g_SquadsUntilWarned		=	7
	
	-- How many squads must a player attack a base with to play IEs or activate Bases Early
	g_num_PlayerUnits_ActivateBase = 2
	
	-- Interval for Base to produce units if it has a few squad that it can produce (& tells them to do stuff -- patrol, attack, etc)
	
	-- DEFENSE BASE: Firewarriors, Kroot, & Vespids (Base Plyer Destroys to Build their own)
	g_productionTimer_defenseBase_barracks		=	60
	g_productionTimer_defenseBase_krootNest	=	65
	g_productionTimer_defenseBase_hq				=	70
	
	-- First Group:
	-- KROOTCENTER BASE: Attacking Kroot Carnivores & Vespids
	g_productionTimer_krootCenterBase = 270 --300
	-- SOUTH BASE: Attacking Fire Warriors & Drone Harbringer / Skyray
	g_productionTimer_southBase = 270 --300
	-- WEST BASE: Patroling Pathfinders & Attacking Firewarriors
	g_productionTimer_westBase = 270 --300
	
	-- Second Group:
	-- EAST BASE: Attacking Pathfinders, Broadsides & Air Units (Barracuda)
	g_productionTimer_eastBase = 480
	-- RELIC BASE: Crisis Suits, Stealth Suits, & Attacking Drone Harbringers
	g_productionTimer_relicBase = 480 --600
	
	-- Third Group:
	-- NORTHWEST BASE: Attacking KrootHound & Krootox
	g_productionTimer_northWestBase = 300
	
	-- Forth Group:
	-- MAIN BASE: Attacking Firewarriors, Pathfinders, Greater Knarloc, Kroot Shaper, Hammerhead, Drone Harbringer & StealthSuit
	g_productionTimer_mainBase = 360	--300
	
	-- Patrols:
	-- LASERGUN BASE: Patroling Pathfinders & Defending Broadsides
		-- NOTE: The patroling Pathfinder are basically an attack on west exit to player base
	g_productionTimer_laserGunBase					= 270 --300
	-- NORTHEAST BASE: Patrolling Kroot Carninvores & Krootox
	g_productionTimer_northEastBase					= 240 --300
	-- NORTHWEST BASE: Patroling Vespids
	g_productionTimer_northWestBase_patrol		= 240 --300
	
	-- Time until Bases Upgrade Units, Get Better Research, & Begin Attacks
		-- 3 sec difference is so production can maybe occur on the next second
	g_time_Tier_Zero = 267			-- 4:27
	g_time_Tier_One = 597			-- 10 min
	g_time_Tier_Two = 1157			-- 20 min
	g_time_Tier_Three = 1457		-- 25 min
	g_time_Tier_Four = 2357		-- 40 min
-- ------------------------------------------END BALANCE VARIBLES------------------------------

-- Tracks if a Base has activated & thus can produce troops
g_base_activated_East					=	false
g_base_activated_KrootCenter		=	false
g_base_activated_Main					=	false
g_base_activated_NorthWest			=	false
g_base_activated_Relic					=	false
g_base_activated_South				=	false
g_base_activated_South_Vehicle	=	false
g_base_activated_West					=	false

-- Controls Upgrades & Leaders
g_fireWarrior_leader 				= false
g_fireWarrior_shieldDrone 		= false
g_stealthTeam_leader 			= false
g_stealthTeam_fusionBlaster 	= false

-- What Percentage of the Squad do troops reinforce up to...
g_reinforce_percent	=	0.60

-- Can Squads Retreat?
g_retreating_enabled =	true

-- Can Squad Capture?
g_canCaptureStrat	=	false
g_canCaptureRelic	=	true
g_canCaptureCrit	=	true

-- Check for Basic Strategic Point, Relic, Critical Point
g_blueprintRelic			= Util_MakeBlueprintTable("relic_struct")
g_blueprintCritPoint	= Util_MakeBlueprintTable("strategic_objective_struct")
g_blueprintStratPoint	= Util_MakeBlueprintTable("strategic_point_flag")

-- Squad AI Stuff:
g_squad_attacking				=	0
g_squad_retreating			=	1		-- also covers normal moving (non-attack move)
g_squad_reinforcing			=	2
g_squad_loading					=	3
g_squad_usingSkill				=	4
g_squad_produced				=	5

-- g_squad_jump_prep = 6 -- g_squad_jump_ready = 7 -- g_squad_jump_attack = 8 -- g_squad_jump_checkjump = 9 g_squad_patrolling = 10 g_squad_entrenched = 11

-- Squad Skills
g_skill_firewarriors				=	1
g_skill_pathfinders				=	2
g_skill_broadsides				=	3
g_skill_barracuda				=	4
g_skill_crisis						=	5
g_skill_harbinger					=	6
g_skill_devilfish					=	7
g_skill_skyray						=	8
g_skill_stealth						=	9
g_skill_vespid						=	10
g_skill_krootcarnivore			=	11

-- East Base : Note -- Only Using 1 & 2
	-- Pathfinders(1,3) & Broadside (2,4)
g_eastBase_troops_status					=	{0,0,0,0}
g_eastBase_barracuda_status			=	{0,0,0,0}

-- Kroot Center Base	
sg_krootCenterBase_carnivore_status	= {0,0}

-- Patroling Pathfinders from Laser Gun Base
sg_laserGunBase_patrol_status			=	{0,0}

-- MainBase: Firewarriors, Pathfinders, Greater Knarloc, Kroot Shaper, Hammerhead, Drone Harbringer, StealthSuit
g_mainBase_troops_status				=	{0,0}
g_mainBase_kroot_status					=	{0,0}
g_mainBase_vehicle_status				=	{0,0}
g_mainBase_stealthSuit_status			= {0}

-- Patroling Carnivore(1,3) & Krootox (2,4)
sg_northEastBase_patrol_status		=	{0,0,0,0}

-- Hounds (1,3) & Krootox (2,4)
sg_northWestBase_troops_status		=	{0,0,0,0}

-- Patroling Vespids
sg_northWestBase_patrol_status		=	{0,0,0,0}

-- Crisis Suits (4) : I am only using 2 of these
sg_relicBase_crisis_status					=	{0,0,0,0}

-- Stealth Suit
sg_relicBase_stealthSuit_status			= {0}

-- Drone Harbringers
sg_relicBase_vehicle_status				=	{0,0}

-- Fire Warriors
sg_southBase_troops_status				= {0,0}

-- Drone Harbinger(1) & Skyray (2)
sg_southBase_vehicles_status			= {0,0}

-- Tau Fleet
sg_fleet_hammerhead_status			= {g_squad_produced,g_squad_produced}
sg_fleet_droneHarbinger_status		= {g_squad_produced}
sg_fleet_fireWarrior_status				= {g_squad_produced,g_squad_produced}
sg_fleet_greaterKnarloc_status			= {g_squad_produced}
sg_fleet_krootox_status						= {g_squad_produced,g_squad_produced}

-- Fire warrior
sg_westBase_troops_status				= {0,0}

-- pathfinders
sg_westBase_patrol_status				=	{0,0}

-- stealth
sg_westBase_stealthSuit_status		=	{0}

-- Drone Burrowing & Ambush
g_drone_burrowing_array				=	{	0, 0, 0, 0, 0, 0,
																0, 0, 0, 0, 0, 0,
																0, 0, 0, 0, 0, 0,
																0, 0, 0, 0, 0, 0}

---------------------------------------------RACE BASED INTEL EVENT ARRAYS---------------------
-- Initial_Beachhead (Race Based) : Player Destroys the first small base -- Here is your HQ & Builders
g_ie_Initial_Beachhead_Array = {
							EVENTS.IE_Initial_Beachhead_Chaos,
							EVENTS.IE_Initial_Beachhead_DarkEldar, 
							EVENTS.IE_Initial_Beachhead_Eldar ,
							EVENTS.IE_Initial_Beachhead_Guard,
							EVENTS.IE_Initial_Beachhead_Necron,
							EVENTS.IE_Initial_Beachhead_Ork,
							EVENTS.IE_Initial_Beachhead_Sisters,
							EVENTS.IE_Initial_Beachhead_Space,
							EVENTS.IE_Initial_Beachhead_Tau } -- should not be possible to get since Tau Mission

-- FirstBase_Destroyed (Race Based) : Player Destroys the first small base -- Here is your HQ & Builders
g_ie_FirstBase_Destroyed_Array = {
							EVENTS.IE_FirstBase_Destroyed_Chaos,
							EVENTS.IE_FirstBase_Destroyed_DarkEldar, 
							EVENTS.IE_FirstBase_Destroyed_Eldar ,
							EVENTS.IE_FirstBase_Destroyed_Guard,
							EVENTS.IE_FirstBase_Destroyed_Necron,
							EVENTS.IE_FirstBase_Destroyed_Ork,
							EVENTS.IE_FirstBase_Destroyed_Sisters,
							EVENTS.IE_FirstBase_Destroyed_Space,
							EVENTS.IE_FirstBase_Destroyed_Tau } -- should not be possible to get since Tau Mission

-----------------------------------------END RACE BASED INTEL EVENT ARRAYS---------------------

-- Util_StartIntel(EVENTS.IE_PlayerAttacksFirst)
-- Util_StartIntel(EVENTS.IE_LaserCharging)
-- Util_StartIntel(EVENTS.IE_PlayerCapturedLaser)

-- Get the player race & store for later access
g_raceName = MetaMap_GetPlayerNRaceName(0)

-- Create the Human Player
g_Player1 = Setup_Player(0, g_factionName, g_raceName, 0)

-- Sets up HQ, Builder, Faction Name, Color Scheme, Exception Lists, etc...
Rule_Player_Race_Dependant_Stuff()

-- NOW THAT HUMAN IS SET UP, NEED TO SET UP THE AI PLAYERS AND TEAMS

-- Tau AI Players 	
g_Player2 = Setup_Player (1, "$3950224", "tau_race", 1)	
g_Player4 = Setup_Player (3, "$3950224", "tau_race", 1)	

-- Set Tau Color Scheme
Misc_PlayerTeamColor(g_Player2, "default_4")
Misc_PlayerTeamColor(g_Player4, "default_4")

end

-- Used to redefine some varibles after loading a save game -- Restores IE Arrays function OnGameRestore() ---------------------------------------------RACE BASED INTEL EVENT ARRAYS---------------------

-- Initial_Beachhead (Race Based) : Player Destroys the first small base -- Here is your HQ & Builders
g_ie_Initial_Beachhead_Array = {
							EVENTS.IE_Initial_Beachhead_Chaos,
							EVENTS.IE_Initial_Beachhead_DarkEldar, 
							EVENTS.IE_Initial_Beachhead_Eldar ,
							EVENTS.IE_Initial_Beachhead_Guard,
							EVENTS.IE_Initial_Beachhead_Necron,
							EVENTS.IE_Initial_Beachhead_Ork,
							EVENTS.IE_Initial_Beachhead_Sisters,
							EVENTS.IE_Initial_Beachhead_Space,
							EVENTS.IE_Initial_Beachhead_Tau } -- should not be possible to get since Tau Mission

-- FirstBase_Destroyed (Race Based) : Player Destroys the first small base -- Here is your HQ & Builders
g_ie_FirstBase_Destroyed_Array = {
							EVENTS.IE_FirstBase_Destroyed_Chaos,
							EVENTS.IE_FirstBase_Destroyed_DarkEldar, 
							EVENTS.IE_FirstBase_Destroyed_Eldar ,
							EVENTS.IE_FirstBase_Destroyed_Guard,
							EVENTS.IE_FirstBase_Destroyed_Necron,
							EVENTS.IE_FirstBase_Destroyed_Ork,
							EVENTS.IE_FirstBase_Destroyed_Sisters,
							EVENTS.IE_FirstBase_Destroyed_Space,
							EVENTS.IE_FirstBase_Destroyed_Tau } -- should not be possible to get since Tau Mission

-----------------------------------------END RACE BASED INTEL EVENT ARRAYS---------------------

end

-- END OF " GAME SETUP & RESTORE " RULES


-- INITALIZATION -- OnInit() : Mandatory Function that sets up the mission : Called after OnGameSetup() -- Scar_AddInit(OnInit) : Mandatory Function that registers OnInit function with scar.

function OnInit() -- Set up stuff based on the difficulty level of the stronghold Rule_Stronghold_Difficulty_Strength_Stuff()

--Function Used to set the pregame state of the AI (basically disables all the AI)
Rule_PresetAI()

-- Function used to create all the Tau Buildings on the Map (including the laser gun)
Rule_Create_All_Tau_Buildings( )

-- OPENING NIS STUFF GOES HERE:
WXP_OpeningNISPreset( )
Util_StartNIS( EVENTS.NIS_Opening )

-- Rule_GameStart : Function used to Start the Actual Mission : Function Is Defined Below
Rule_Add( Rule_GameStart )	

end

-- This registers your init function with scar. Scar_AddInit(OnInit)

-- END OF ALL "INITALIZATION" RULES


-- EXTRA INITIAL SETUP -- Rule_SetupMusicPlaylist() : Used to Setup the music & ambient soundtracks -- Rule_SetDifficultyLevel( difficultyLevel ) : Used to set up AI difficulty levels & is added in OnInit( ) -- Rule_SetResearchLevel() : Disable, Enable, and grant research items (CURRRENTLY DOES NOTHING) -- Rule_Player_Race_Dependant_Stuff(): Handles setting everything in scenario that changes based on the player race -- Rule_Create_All_Player_InitialUnits(): Creates all the Players Initial Units on the Map (including Honor Guard) -- Rule_PresetAI() : Used to Disable AI before Initial NIS starts : Called from OnInit( )

-- Used to Setup the music & ambient soundtracks & is added in OnInit( ) function Rule_SetupMusicPlaylist() -- MUSIC TRACKS

-- clear the music playlist
Sound_PlaylistClear( PC_Music )

--Silvey Polish 10/18/07:  Made it flow a little better (plus, Tau_perc_winds does not exist ;) )
-- Add tracks to the playlist
Sound_PlaylistAddTrack( PC_Music, "MU_IG_STR_Tau_perc_str" )
Sound_PlaylistAddTrack( PC_Music, "MU_IG_STR_Tau" )
Sound_PlaylistAddTrack( PC_Music, "MU_IG_STR_Tau_perc" )
Sound_PlaylistAddTrack( PC_Music, "MU_IG_STR_Tau_perc_brass" )
-- Mark these tracks to play in order or random (True is in order) 
Sound_PlaylistSetorder( PC_Music, true )
-- add silence between tracks in seconds (Randomly chooses time between the two numbers)
Sound_PlaylistSetSilence( PC_Music, 5, 10 )

--Silvey Polish 10/10/07:  I had to add this to get the music to play after moving this function after the opening NIS.	
Sound_SetVolumeModifierMusic(1.0)
Sound_PlaylistStart(PC_Music)

-- AMBIENT TRACKS

-- clear the ambient playlist
Sound_PlaylistClear( PC_Ambient )
--add tracks to the playlist
Sound_PlaylistAddTrack( PC_Ambient, "Ambience_Wasteland" )
Sound_PlaylistAddTrack( PC_Ambient, "Ambience_Wasteland" )
-- Mark these tracks to play in order or random (True is in order) 
Sound_PlaylistSetorder( PC_Ambient, true )
-- add silence between tracks in seconds (Randomly chooses time between the two numbers)
Sound_PlaylistSetSilence( PC_Ambient, 5, 10 )

end

-- Used to Set up stuff based on the difficulty level of the stronghold (10-17) : Called from OnInit() function Rule_Stronghold_Difficulty_Strength_Stuff() -- Get the strength of the stronghold from the MetaMap local strongholdStrength = MetaMap_GetTerritoryMilitaryStrength(MetaMap_GetDefendingTerritoryIndex())

-- Set the difficulty tier based on stronghold strength: (10,11,12)
if strongholdStrength <= 12
then
	g_strongholdStrengthTier = 1

-- Set the difficulty tier based on stronghold strength: (13,14,15)
elseif strongholdStrength <= 15
then
	g_strongholdStrengthTier = 2

-- Set the difficulty tier based on stronghold strength: (16,17)
else
	g_strongholdStrengthTier = 3		
end

end

-- Used to Disable AI Players (Done Before Initial NIS) : Called from OnInit( ) function Rule_PresetAI() Cpu_Enable(g_Player2, false) Cpu_Enable(g_Player4, false) end

-- END OF ALL "EXTRA INITIAL SETUP" RULES


-- INITIAL PLAYER SETUP RULES -- Rule_Player_Race_Dependant_Stuff() : Handles setting everything in scenario that changes based on the player race : Called from OnInit() -- Rule_Create_All_Player_Initial_Units() : Creates all the Players Initial Units on the Map (including Honor Guard) -- Rule_Create_All_Player_Initial_Buildings() : Creates all the Players Initial Buildings on the Map ( & give resources)

-- Handles setting everything in scenario that changes based on the player race : Called from OnInit( ) function Rule_Player_Race_Dependant_Stuff() if g_raceName == "chaos_marine_race" then -- What Intel Events race is using g_intelEvent_raceId = 1

	-- Faction name that Race is using
	g_factionName = "$3950214"
	
	-- Color Scheme that Race is using
	g_colorScheme = "default_0"
	
	-- HQ that Race uses
	g_HQ_blueprint = "chaos_hq"
	
	-- Builder that Race uses
	g_Builder_blueprint = "chaos_squad_slave"
	
	-- Starting Troops for the Mission
	g_starting_blueprint_1 = "chaos_squad_cultist_sp_dxp3_prisoner"
	g_starting_blueprint_2 = "chaos_marine_squad_sp_dxp3_prisoner"
	g_starting_blueprint_3 = "chaos_squad_cultist_sp_dxp3_prisoner"
	g_starting_blueprint_4 = "chaos_marine_squad_sp_dxp3_prisoner"
	
	-- used for forward base ability
	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"
	
	-- Used for Defeat Checks
	t_building_exceptions = {
		"chaos_thermo_plasma_generator",
		"chaos_plasma_generator",
		"chaos_turret_bolter",
		"chaos_mine_field",
		"chaos_listening_post"}
	
	-- Used for Defeat Checks
	t_unit_exceptions = {}
	
elseif g_raceName == "dark_eldar_race"
then
	-- What Intel Events race is using
	g_intelEvent_raceId = 2
	
	-- Faction name that Race is using
	g_factionName = "$3950220"
	
	-- Color Scheme that Race is using
	g_colorScheme = "default_1"

	-- HQ that Race uses
	g_HQ_blueprint = "dark_eldar_hq"
	--_sp_dxp3_player
	
	-- Builder that Race uses
	g_Builder_blueprint = "dark_eldar_squad_slave"
	
	-- Starting Troops for the Mission
	g_starting_blueprint_1 = "dark_eldar_squad_warrior_sp_dxp3_prisoner"
	g_starting_blueprint_2 = "dark_eldar_squad_haemonculus_sp_dxp3_prisoner"
	g_starting_blueprint_3 = "dark_eldar_squad_wych_sp_dxp3_prisoner"
	g_starting_blueprint_4 = "dark_eldar_squad_warrior_sp_dxp3_prisoner"
	
	-- used for forward base ability
	g_bonus_generator	= "dark_eldar_plasma_generator"
	g_bonus_turret			= "dark_eldar_slave_caravel"
	g_bonus_barracks		= "dark_eldar_hall_of_blood"
	g_bonus_barracks2		= "dark_eldar_skimmer_shop"
	g_bonus_research		= "dark_eldar_haemonculus_laboratory"
	
	-- Used for Defeat Checks
	t_building_exceptions = {
		"dark_eldar_plasma_generator",
		"dark_eldar_thermo_plasma",
		"dark_eldar_slave_caravel",
		"dark_eldar_listening_post"}
	
	-- Used for Defeat Checks
	t_unit_exceptions = {}

-- Should not be possible to be this race on this map
elseif g_raceName == "eldar_race"
then
	-- What Intel Events race is using (not actually used)
	g_intelEvent_raceId = 3 
	
	-- Faction name that Race is using
	g_factionName = "$3950217"
	
	-- Color Scheme that Race is using
	g_colorScheme = "default_5"

	-- HQ that Race uses
	g_HQ_blueprint = "eldar_hq"
	
	-- Builder that Race uses
	g_Builder_blueprint = "eldar_squad_bonesinger"
	
	-- Starting Troops for the Mission
	g_starting_blueprint_1 = "eldar_guardian_squad_sp_dxp3_prisoner"
	g_starting_blueprint_2 = "eldar_squad_banshees_sp_dxp3_prisoner"
	g_starting_blueprint_3 = "eldar_guardian_squad_sp_dxp3_prisoner"
	g_starting_blueprint_4 = "eldar_squad_banshees_sp_dxp3_prisoner"
	
	-- used for forward base ability
	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"
	
	-- Used for Defeat Checks
	t_building_exceptions = {
		"eldar_advanced_warp_generator",
		"eldar_warp_generator",
		"eldar_support_platform_scatterlaser",
		"eldar_mine_field",
		"eldar_listening_post"}
		
	-- Used for Defeat Checks
	t_unit_exceptions = {}

elseif g_raceName == "guard_race"
then
	-- What Intel Events race is using
	g_intelEvent_raceId = 4
	
	-- Faction name that Race is using
	g_factionName = "$3950219"
	
	-- Color Scheme that Race is using
	g_colorScheme = "default_4"

	-- HQ that Race uses
	g_HQ_blueprint = "guard_hq"
	
	-- Builder that Race uses
	g_Builder_blueprint = "guard_squad_enginseer"
	
	-- Starting Troops for the Mission
	g_starting_blueprint_1 = "guard_squad_guardsmen_sp_dxp3_prisoner"
	g_starting_blueprint_2 = "guard_squad_guardsmen_sp_dxp3_prisoner"
	g_starting_blueprint_3 = "guard_squad_guardsmen_sp_dxp3_prisoner"
	g_starting_blueprint_4 = "guard_squad_ogryns_sp_dxp3_prisoner"
	
	-- used for forward base ability
	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"
	
	-- Used for Defeat Checks
	t_building_exceptions = {
		"guard_thermo_plasma",
		"guard_plasma_generator",
		"guard_turret_heavy_bolter",
		"guard_mines",
		"guard_listening_post"}
		
	-- Used for Defeat Checks
	t_unit_exceptions = {}

elseif g_raceName == "necron_race"
then
	-- What Intel Events race is using
	g_intelEvent_raceId = 5
	
	-- Faction name that Race is using
	g_factionName = "$3950223"
	
	-- Color Scheme that Race is using
	g_colorScheme = "default_0"
	
	-- HQ that Race uses
	g_HQ_blueprint = "monolith"
	
	-- Builder that Race uses
	g_Builder_blueprint = "necron_builder_scarab_squad"
	
	-- Starting Troops for the Mission
	g_starting_blueprint_1 = "necron_basic_warrior_squad_sp_dxp3_prisoner"
	g_starting_blueprint_2 = "necron_basic_warrior_squad_sp_dxp3_prisoner"
	g_starting_blueprint_3 = "necron_wraith_squad_sp_dxp3_prisoner"
	g_starting_blueprint_4 = "necron_wraith_squad_sp_dxp3_prisoner"
	
	-- used for forward base ability
	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"
	
	-- Used for Defeat Checks
	t_building_exceptions = {
		"necron_thermoplasma_generator",
		"necron_plasma_generator",
		"necron_turret",
		"necron_listening_post"}

	-- Used for Defeat Checks
	t_unit_exceptions = {}
	
elseif g_raceName == "ork_race"
then
	-- What Intel Events race is using
	g_intelEvent_raceId = 6
	
	-- Faction name that Race is using
	g_factionName = "$3950215"
	
	-- Color Scheme that Race is using
	g_colorScheme = "default_3"

	-- HQ that Race uses
	g_HQ_blueprint = "ork_hq"
	
	-- Builder that Race uses
	g_Builder_blueprint = "ork_squad_grot"
	
	-- Starting Troops for the Mission
	g_starting_blueprint_1 = "ork_squad_shoota_boy_sp_dxp3_prisoner"
	g_starting_blueprint_2 = "ork_squad_slugga_sp_dxp3_prisoner"
	g_starting_blueprint_3 = "ork_squad_shoota_boy_sp_dxp3_prisoner"
	g_starting_blueprint_4 = "ork_squad_slugga_sp_dxp3_prisoner"
	
	-- used for forward base ability
	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"
	
	-- Used for Defeat Checks
	t_building_exceptions = {
		"ork_bigger_generator",
		"ork_generator",
		"ork_waagh_banner",
		"ork_mine_field",
		"ork_listening_post"}

	-- Used for Defeat Checks
	t_unit_exceptions = {}		

elseif g_raceName == "sisters_race"
then
	-- What Intel Events race is using
	g_intelEvent_raceId = 7
	
	-- Faction name that Race is using
	g_factionName = "$3900048"
	
	-- Color Scheme that Race is using
	g_colorScheme = "default_2"

	-- HQ that Race uses
	g_HQ_blueprint = "sisters_hq"

	-- Builder that Race uses
	g_Builder_blueprint = "sisters_squad_servitor"
	
	-- Starting Troops for the Mission
	g_starting_blueprint_1 = "sisters_squad_battle_sister_sp_dxp3_prisoner"
	g_starting_blueprint_2 = "sisters_squad_battle_sister_sp_dxp3_prisoner"
	g_starting_blueprint_3 = "sisters_squad_missionary_sp_dxp3_prisoner"
	g_starting_blueprint_4 = "sisters_squad_battle_sister_sp_dxp3_prisoner"
	
	-- used for forward base ability
	g_bonus_generator	= "sisters_plasma_generator"
	g_bonus_turret			= "sisters_turret_flamer"
	g_bonus_barracks		= "sisters_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		= "sisters_sanctuary"
	
	-- Used for Defeat Checks
	t_building_exceptions = {
		"sisters_plasma_generator",
		"sisters_thermo_plasma",
		"sisters_turret_flamer",
		"sisters_mines",
		"sisters_listening_post"}

	-- Used for Defeat Checks
	t_unit_exceptions = {}

elseif g_raceName == "space_marine_race"
then
	-- What Intel Events race is using
	g_intelEvent_raceId = 8
	
	-- Faction name that Race is using
	g_factionName = "$3950213"
	
	-- Color Scheme that Race is using
	g_colorScheme = "default_0"

	-- HQ that Race uses
	g_HQ_blueprint = "space_marine_hq"
	
	-- Builder that Race uses
	g_Builder_blueprint = "space_marine_squad_servitor"
	
	-- Starting Troops for the Mission
	g_starting_blueprint_1 = "space_marine_squad_scout_sp_dxp3_prisoner"
	g_starting_blueprint_2 = "space_marine_squad_sp_dxp3_prisoner"
	g_starting_blueprint_3 = "space_marine_squad_scout_sp_dxp3_prisoner"
	g_starting_blueprint_4 = "space_marine_squad_sp_dxp3_prisoner"
	
	-- used for forward base ability
	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"
	
	-- Used for Defeat Checks
	t_building_exceptions = {
		"space_marine_thermo_generator",
		"space_marine_generator",
		"space_marine_turret_bolter",
		"space_marine_mine_field",
		"space_marine_listening_post"}
		
	-- Used for Defeat Checks
	t_unit_exceptions = {}
	
-- NOT NEEDED SINCE IS TAU LEVEL
elseif g_raceName == "tau_race"
then
	-- What Intel Events race is using
	g_intelEvent_raceId = 9
	
	-- Faction name that Race is using
	g_factionName = "$3950224"
	
	-- Color Scheme that Race is using
	g_colorScheme = "default_4"

	-- HQ that Race uses
	g_HQ_blueprint = "tau_hq"
	
	-- Builder that Race uses
	g_Builder_blueprint = "tau_builder_squad"
	
	-- Starting Troops for the Mission
	g_starting_blueprint_1 = "tau_kroot_alpha_squad_sp_dxp3_prisoner"
	g_starting_blueprint_2 = "tau_kroot_alpha_squad_sp_dxp3_prisoner"
	g_starting_blueprint_3 = "tau_honor_guard_fire_warrior_squad_sp_dxp3_prisoner"
	g_starting_blueprint_4 = "tau_honor_guard_fire_warrior_squad_sp_dxp3_prisoner"
	
	-- used for forward base ability
	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 algorithm 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"
	
	-- Used for Defeat Checks
	t_building_exceptions = {
		"tau_thermoplasma_generator",
		"tau_plasma_generator",
		"tau_listening_post"}
		
	-- Used for Defeat Checks
	t_unit_exceptions = {}	
end

-- Set the Faction Name of the player
Setup_SetPlayerName(g_Player1, g_factionName)

-- Set the Color Schemes Here 
Misc_PlayerTeamColor(g_Player1, g_colorScheme)

end

-- Function used to creates all the Players Initial Units on the Map (including Honor Guard & Wargear) function Rule_Create_All_Player_InitialUnits() -- Clear the Honor Guard List t_honorGuardUnits = {}

--Set up the Unlocked wargear upgrades
MetaMap_UpdatePlayerWargear(g_Player1)

--Set up the List of the Honor Guard units
MetaMap_GetRaceStartingSquadsList(g_raceName, t_honorGuardUnits)

-- Create the Honor Guard Units on the Map
for j = 1,  table.getn(t_honorGuardUnits) do
	Util_CreateSquadsAtMarker(g_Player1, "sg_honorGuard", t_honorGuardUnits[j], "mkr_honorGuard_Location", 1)
end

-- Create the starting troop squads & Add Leaders
Util_CreateSquadsAtMarkerEx(g_Player1,  "sg_startingTroops_1", g_starting_blueprint_1, "mkr_startingTroops_1", 1, 20)
SGroup_AddLeaders("sg_startingTroops_1")

Util_CreateSquadsAtMarkerEx(g_Player1,  "sg_startingTroops_2", g_starting_blueprint_2, "mkr_startingTroops_2", 1, 20)
SGroup_AddLeaders("sg_startingTroops_2")

end

-- Creates all the Players Initial Buildings on the Map ( & give resources) -- Actually just gives resources since the buildings are created after the tau base is destroyed function Rule_Create_All_Player_Initial_Buildings( ) -- Sets the Initial Player Resources (RT_Requisition, RT_Power, RT_Pop(Orks Only)) if g_raceName == "necron_race" then -- If Necron, Only Give Power Player_SetResource(g_Player1, RT_Power, g_amountPowerToGiveNecron) else -- Otherwise give both Player_SetResource(g_Player1, RT_Requisition, g_amountRequisitionToGivePlayer) Player_SetResource(g_Player1, RT_Power, g_amountPowerToGivePlayer) end end

-- END OF ALL "INITIAL PLAYER SETUP" RULES


-- CREATE AI BUILDINGS RULES -- Rule_Create_All_Tau_Buildings() : Create all AI Bases & give them initial resources & strategic points : Called from OnInit( ) -- Rule_Create_DefenseBase_Buildings() : Create Buildings for Defense Base & the Comm Tower (one you destroy to build yours) -- Rule_Create_KrootCenterBase_Buildings( ) : Create Buildings for Small Kroot Base in Center of Map -- Rule_Create_KrootEastBase_Buildings( ) : Create Buildings for Small Kroot Base on East Side of Map -- Rule_Create_KrootWestBase_Buildings( ) : Create Buildings for Small Kroot Base on West Side of Map -- Rule_Create_LaserGunBase_Buildings( ) : Create Buildings for Laser Gun Base in Center of Map -- Rule_Create_Laser_Gun( ) : Create Actual Laser gun that the Tau starts with (Also sets the critical point associated with it) -- Rule_Create_MainTauStronghold_Buildings( ) : Create Buildings for Main Tau Base (one with final objective) -- Rule_Create_SouthBase_Buildings( ) : Create Buildings for Small Tau Base on South Side of Map -- Rule_Setup_AI_StrategicPoints( ) : Setup the Strategic Points, Critical Points, & Relics to AI Control (DOES NOT SET THE LASER GUN CRITICAL POINT)

-- Create all AI Bases & give them initial resources & strategic points : Called from OnInit( ) function Rule_Create_All_Tau_Buildings() -- Create Buildings for Defense Base & the Comm Tower (one you destroy to build yours) Rule_Create_DefenseBase_Buildings( )

-- Create Buildings for Small Kroot Base on East Side of Map
Rule_Create_EastBase_Buildings( )

-- Create Buildings for Small Kroot Base in Center of Map	
Rule_Create_KrootCenterBase_Buildings( )

-- Create Buildings & Laser for Laser Gun Base
Rule_Create_LaserGunBase_Buildings( )

-- Create Buildings for Main Tau Base (one with final objective)
Rule_Create_MainTauStronghold_Buildings( )

-- Create Buildings for Base on NorthEast Side of Map
Rule_Create_NorthEastBase_Buildings( )

-- Create Buildings for Base on NorthWest Side of Map
Rule_Create_NorthWestBase_Buildings( )

-- Create Buildings for the Base by the Relic in Center of Map
Rule_Create_RelicBase_Buildings()

-- Create Buildings for Base on South Side of Map
Rule_Create_SouthBase_Buildings( )

-- Create Buildings for Base on West Side of Map
Rule_Create_WestBase_Buildings( )

-- Setup the Strategic Points, Critical Points,  & Relics to AI Control (DOES NOT SET THE LASER GUN CRITICAL POINT)
Rule_Setup_AI_StrategicPoints( )

-- Set AI Starting Resources
Player_SetAllResources(g_Player2, g_amountRequisitionToGiveAI, g_amountPowerToGiveAI, 0)
Player_SetAllResources(g_Player4, g_amountRequisitionToGiveAI, g_amountPowerToGiveAI, 0)

end

-- Create Buildings for Defense Base (one you destroy to build yours) -- Contains: HQ(1), Barracks(1), Kroot Nest(1), Power(2) -- Using Special HP Versions of the HQ, Barracks & Kroot Nest function Rule_Create_DefenseBase_Buildings() -- used to track when all buildings in the base are destroyed (PRIMARY OBJECTIVE) EGroup_Create("eg_defenseBase_Buildings_Objective")

-- Create the Cadre HQ
for i = 1, 1 do
	Entity_CreateBuildingMarker(g_Player2,"eg_defenseBase_HQ"..i, "tau_hq_sp_dxp3","mkr_defenseBase_HQ"..i, 1)
	EGroup_AddGroup("eg_defenseBase_Buildings_Objective", "eg_defenseBase_HQ"..i)
end

-- Create the Normal Tau Barracks
for i = 1, 1 do
	Entity_CreateBuildingMarker(g_Player2,"eg_defenseBase_Barracks"..i, "tau_barracks_sp_dxp3","mkr_defenseBase_Barracks"..i, 1)
	EGroup_AddGroup("eg_defenseBase_Buildings_Objective", "eg_defenseBase_Barracks"..i)
end

-- Create the Kroot Barracks
for i = 1, 1 do
	Entity_CreateBuildingMarker(g_Player2,"eg_defenseBase_KrootNest"..i, "tau_kroot_nest_sp_dxp3","mkr_defenseBase_KrootNest"..i, 1)
	EGroup_AddGroup("eg_defenseBase_Buildings_Objective", "eg_defenseBase_KrootNest"..i)
end

-- Create the Power Generators
for i = 1, 2 do
	Entity_CreateBuildingMarker(g_Player2,"eg_defenseBase_Power"..i, "tau_plasma_generator","mkr_defenseBase_Power"..i, 1)
	EGroup_AddGroup("eg_defenseBase_Buildings_Objective", "eg_defenseBase_Power"..i)
end

end

-- Create Buildings for Small Kroot Base in Center of Map -- Contains: HQ(1), Kroot Nest(2), Power(2), PathToEnlightment(1), Kauyon(1) function Rule_Create_KrootCenterBase_Buildings( ) -- Create the Cadre HQ for i = 1, 1 do Entity_CreateBuildingMarker(g_Player2,"eg_krootCenterBase_HQ"..i, "tau_hq","mkr_krootCenterBase_HQ"..i, 1) end

-- Create the Kroot Barracks
for i = 1, 2 do
	Entity_CreateBuildingMarker(g_Player2,"eg_krootCenterBase_KrootNest"..i, "tau_kroot_nest","mkr_krootCenterBase_KrootNest"..i, 1)
end

-- Create the Kauyon Command Post ( Krootox)
for i = 1, 1 do
	Entity_CreateBuildingMarker(g_Player2,"eg_krootCenterBase_KauyonShrine"..i, "tau_shrine_of_kauyon","mkr_krootCenterBase_KauyonShrine"..i, 1)
end

-- Create the Power Generators
for i = 1, 2 do
	Entity_CreateBuildingMarker(g_Player2,"eg_krootCenterBase_Power"..i, "tau_plasma_generator","mkr_krootCenterBase_Power"..i, 1)
end

end

-- Create Buildings for Small Kroot Base on East Side of Map -- Barracks(2), Vehicle(2), Montka(1), Power(4) function Rule_Create_EastBase_Buildings( ) -- Create the Barracks for i = 1, 2 do Entity_CreateBuildingMarker(g_Player2,"eg_eastBase_Barracks"..i, "tau_barracks","mkr_eastBase_Barracks"..i, 1) end

-- Create the Mont'Ka Command Post
for i = 1, 1 do
	Entity_CreateBuildingMarker(g_Player2,"eg_eastBase_MontkaShrine"..i, "tau_shrine_of_montka","mkr_eastBase_MontkaShrine"..i, 1)
end

-- Create the Vehicle Beacon
for i = 1, 2 do
	Entity_CreateBuildingMarker(g_Player2,"eg_eastBase_VehicleBuilding"..i, "tau_vehicle_building","mkr_eastBase_VehicleBuilding"..i, 1)
end

-- Create the Normal Power Generators
for i = 1, 4 do
	Entity_CreateBuildingMarker(g_Player2,"eg_eastBase_Power"..i, "tau_plasma_generator","mkr_eastBase_Power"..i, 1)
end

-- Create the Idle Orcas in the Base
for i = 1,4 do
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_eastBase_Orca"..i, "tau_orca_dropship_sp_dxp3", "mkr_eastBase_orcaSpawn"..i, 1, 1)
end

end

-- Create Buildings for Kroot Base in North East -- Kroot Nest(2), Kauyon(1) function Rule_Create_NorthEastBase_Buildings( ) -- Create the Kroot Barracks for i = 1, 2 do Entity_CreateBuildingMarker(g_Player2,"eg_northEastBase_KrootNest"..i, "tau_kroot_nest","mkr_northEastBase_KrootNest"..i, 1) end

-- Create the Kauyon Command Post ( Krootox)
for i = 1, 1 do
	Entity_CreateBuildingMarker(g_Player2,"eg_northEastBase_KauyonShrine"..i, "tau_shrine_of_kauyon","mkr_northEastBase_KauyonShrine"..i, 1)
end

end

-- Create Buildings for Kroot Base in North West -- HQ(1), Kroot Nest(2), Kauyon(1) function Rule_Create_NorthWestBase_Buildings( ) -- Create the Cadre HQ for i = 1, 1 do Entity_CreateBuildingMarker(g_Player2,"eg_northWestBase_HQ"..i, "tau_hq","mkr_northWestBase_HQ"..i, 1) end

-- Create the Kroot Barracks
for i = 1, 2 do
	Entity_CreateBuildingMarker(g_Player2,"eg_northWestBase_KrootNest"..i, "tau_kroot_nest","mkr_northWestBase_KrootNest"..i, 1)
end

-- Create the Kauyon Command Post ( Krootox)
for i = 1, 1 do
	Entity_CreateBuildingMarker(g_Player2,"eg_northWestBase_KauyonShrine"..i, "tau_shrine_of_kauyon","mkr_northWestBase_KauyonShrine"..i, 1)
end

end

-- Create Buildings for Small Base on West Side of Map -- HQ(1), Barracks(2), Montka (1), Power(4) function Rule_Create_WestBase_Buildings( ) -- Create the Cadre HQ for i = 1, 1 do Entity_CreateBuildingMarker(g_Player2,"eg_westBase_HQ"..i, "tau_hq","mkr_westBase_HQ"..i, 1) end

-- Create the Barracks
for i = 1, 2 do
	Entity_CreateBuildingMarker(g_Player2,"eg_westBase_Barracks"..i, "tau_barracks","mkr_westBase_Barracks"..i, 1)
end

-- Create the Mont'Ka Command Post
for i = 1, 1 do
	Entity_CreateBuildingMarker(g_Player2,"eg_westBase_MontkaShrine"..i, "tau_shrine_of_montka","mkr_westBase_MontkaShrine"..i, 1)
end

-- Create the Normal Power Generators
for i = 1, 4 do
	Entity_CreateBuildingMarker(g_Player2,"eg_westBase_Power"..i, "tau_plasma_generator","mkr_westBase_Power"..i, 1)
end

end

-- Create Buildings & Laser for Laser Gun Base -- Barracks(2), Power(4), Laser(1) function Rule_Create_LaserGunBase_Buildings( ) -- Create the Tau Barracks for i = 1, 2 do Entity_CreateBuildingMarker(g_Player2,"eg_laserGunBase_Barracks"..i, "tau_barracks","mkr_laserGunBase_Barracks"..i, 1) end

-- Create the Power Generators
for i = 1, 4 do
	Entity_CreateBuildingMarker(g_Player2,"eg_laserGunBase_Power"..i, "tau_plasma_generator","mkr_laserGunBase_Power"..i, 1)
end

-- Make sure that the computer owns the laser gun
g_PlayerOwnsLaserGun = false

-- Create the Actual Laser Gun
Entity_CreateBuildingMarker(g_Player2,"eg_laserGun_Weapon", "tau_lasergun","mkr_laserGun_Location", 1)

-- Add a button to the gun so player can fire it
Rule_Laser_Button_Setup()

-- Make it so the Laser Gun can't be destroyed
EGroup_SetHealthInvulnerable("eg_laserGun_Weapon", true)

end

-- Create Buildings for Main Tau Base (one with final objective) -- HQ(1), Barracks(2), Kroot Nest(2), Path to Enlightment(2), Power(10), Purpose(1), Vehicle(2), Kauyon(2), Beacons function Rule_Create_MainTauStronghold_Buildings( ) -- Used to track when Coalition Center is destroyed, for showing of the final Ethereal (OBJECTIVE) EGroup_Create("eg_mainStronghold_EtherealBuilding_Objective")

-- used to track when all guidance beacons are destroyed
EGroup_Create("eg_All_Beacons_Objective")

--Create the Comm Towers in the Base -- Side Objective
for i=1,3 do
	Entity_CreateBuildingMarker(g_Player2,"eg_commTower_"..i, "tau_guidancebeacon_01","mkr_commTower_"..i, 1)
	EGroup_AddGroup("eg_All_Beacons_Objective", "eg_commTower_"..i)
end

-- Create the Cadre HQ
for i = 1, 1 do
	Entity_CreateBuildingMarker(g_Player2,"eg_mainStronghold_HQ"..i, "tau_hq","mkr_mainStronghold_HQ"..i, 1)
end

-- Create the Normal Tau Barracks
for i = 1, 2 do
	Entity_CreateBuildingMarker(g_Player2,"eg_mainStronghold_Barracks"..i, "tau_barracks","mkr_mainStronghold_Barracks"..i, 1)
end

-- Create the Kroot Barracks
for i = 1, 2 do
	Entity_CreateBuildingMarker(g_Player2,"eg_mainStronghold_KrootNest"..i, "tau_kroot_nest","mkr_mainStronghold_KrootNest"..i, 1)
end

-- Create the Path to Enlightment (Upgrade Building)
for i = 1, 2 do
	Entity_CreateBuildingMarker(g_Player2,"eg_mainStronghold_PathToEnlightment"..i, "tau_research_building","mkr_mainStronghold_PathToEnlightment"..i, 1)
end

-- Create the Vehicle Beacon
for i = 1, 2 do
	Entity_CreateBuildingMarker(g_Player2,"eg_mainStronghold_VehicleBuilding"..i, "tau_vehicle_building","mkr_mainStronghold_VehicleBuilding"..i, 1)
end

-- Create the Kauyon Command Post ( Krootox)
for i = 1, 2 do
	Entity_CreateBuildingMarker(g_Player2,"eg_mainStronghold_KauyonShrine"..i, "tau_shrine_of_kauyon","mkr_mainStronghold_KauyonShrine"..i, 1)
end

-- Create the Coalition Center (Ethereal Building / Greater Knarloc) -- Should only be one of these
-- DESTROYING this is also the PRIMARY OBJECTIVE of the MISSION
for i = 1, 1 do
	Entity_CreateBuildingMarker(g_Player2,"eg_mainStronghold_PurposeShrine"..i, "tau_shrine_of_purpose_sp_dxp3","mkr_mainStronghold_PurposeShrine"..i, 1)
	EGroup_AddGroup("eg_mainStronghold_EtherealBuilding_Objective", "eg_mainStronghold_PurposeShrine"..i)
end

-- Create the Normal Power Generators in the Main Base
for i = 1, 10 do
	Entity_CreateBuildingMarker(g_Player2,"eg_mainStronghold_Power"..i, "tau_plasma_generator","mkr_mainStronghold_Power"..i, 1)
end

end

-- Create Buildings for Relic Base in Center of Map -- HQ(1), Barracks(2), Vehicle Beacon(1) function Rule_Create_RelicBase_Buildings( ) -- Create the Cadre HQ for i = 1, 1 do Entity_CreateBuildingMarker(g_Player2,"eg_relicBase_HQ"..i, "tau_hq","mkr_relicBase_HQ"..i, 1) end

-- Create the Normal Tau Barracks
for i = 1, 2 do
	Entity_CreateBuildingMarker(g_Player2,"eg_relicBase_Barracks"..i, "tau_barracks","mkr_relicBase_Barracks"..i, 1)
end

-- Create the Vehicle Beacon
for i = 1, 1 do
	Entity_CreateBuildingMarker(g_Player2,"eg_relicBase_VehicleBuilding"..i, "tau_vehicle_building","mkr_relicBase_VehicleBuilding"..i, 1)
end

end

-- Create Buildings for South Tau Base -- Barracks(1), VehicleBay(1), Montka(1), Power(4) function Rule_Create_SouthBase_Buildings( ) -- Create the Normal Tau Barracks for i = 1, 1 do Entity_CreateBuildingMarker(g_Player2,"eg_southBase_Barracks"..i, "tau_barracks","mkr_southBase_Barracks"..i, 1) end

-- Create the Vehicle Beacon
for i = 1, 1 do
	Entity_CreateBuildingMarker(g_Player2,"eg_southBase_VehicleBuilding"..i, "tau_vehicle_building","mkr_southBase_VehicleBuilding"..i, 1)
end

-- Create the Mont'Ka Command Post
for i = 1, 1 do
	Entity_CreateBuildingMarker(g_Player2,"eg_southBase_MontkaShrine"..i, "tau_shrine_of_montka","mkr_southBase_MontkaShrine"..i, 1)
end

-- Create the Normal Power Generators in the Main Base
for i = 1, 4 do
	Entity_CreateBuildingMarker(g_Player2,"eg_southBase_Power"..i, "tau_plasma_generator","mkr_southBase_Power"..i, 1)
end

end

-- Setup the Strategic Points, Critical Points, & Relics to AI Control -- All EGroups are set in the editor function Rule_Setup_AI_StrategicPoints( ) ------------------------------------------------------------------------------------------------------------------------------------------------- -- Strategic Point Ownership & Upgrades to Listening Posts ------------------------------------------------------------------------------------------------------------------------------------------------- -- Strategic Points by the Defensive Base for i=1, 2 do EGroup_SetPlayerOwner("eg_defenseBase_stratPoint"..i, g_Player2) Entity_CreateBuildingPosition(g_Player2, "eg_defenseBase_listeningPost"..i, "tau_listening_post", EGroup_GetPosition("eg_defenseBase_stratPoint"..i), 1) end

-- Strategic Point by the East Base
EGroup_SetPlayerOwner("eg_eastBase_stratPoint1", g_Player2)
Entity_CreateBuildingPosition(g_Player2, "eg_eastBase_listeningPost1", "tau_listening_post", EGroup_GetPosition("eg_eastBase_stratPoint1"), 1)
EGroup_ForceAddOn("eg_eastBase_listeningPost1", "addon_tau_list_post_1" )

-- Strategic Point by the KrootCenter Base
EGroup_SetPlayerOwner("eg_krootCenterBase_stratPoint1", g_Player2)
Entity_CreateBuildingPosition(g_Player2, "eg_krootCenterBase_listeningPost1", "tau_listening_post", EGroup_GetPosition("eg_krootCenterBase_stratPoint1"), 1)
EGroup_ForceAddOn("eg_krootCenterBase_listeningPost1", "addon_tau_list_post_1" )

-- Strategic Points by the Main Tau Stronghold to the Main Tau Player: g_Player2
for i=1, 2 do
	EGroup_SetPlayerOwner("eg_mainStronghold_stratPoint"..i, g_Player2)
	Entity_CreateBuildingPosition(g_Player2, "eg_mainStronghold_listeningPost"..i, "tau_listening_post", EGroup_GetPosition("eg_mainStronghold_stratPoint"..i), 1)
	EGroup_ForceAddOn("eg_mainStronghold_listeningPost"..i, "addon_tau_list_post_1" )
end

-- Strategic Point by the NorthEast Base
EGroup_SetPlayerOwner("eg_northEastBase_stratPoint1", g_Player2)
Entity_CreateBuildingPosition(g_Player2, "eg_northEastBase_listeningPost1", "tau_listening_post", EGroup_GetPosition("eg_northEastBase_stratPoint1"), 1)
EGroup_ForceAddOn("eg_northEastBase_listeningPost1", "addon_tau_list_post_1" )

-- Strategic Point by the NorthWest Base
EGroup_SetPlayerOwner("eg_northWestBase_stratPoint1", g_Player2)
Entity_CreateBuildingPosition(g_Player2, "eg_northWestBase_listeningPost1", "tau_listening_post", EGroup_GetPosition("eg_northWestBase_stratPoint1"), 1)
EGroup_ForceAddOn("eg_northWestBase_listeningPost1", "addon_tau_list_post_1" )

-- Strategic Point by the South Base
EGroup_SetPlayerOwner("eg_southBase_stratPoint1", g_Player2)
Entity_CreateBuildingPosition(g_Player2, "eg_southBase_listeningPost1", "tau_listening_post", EGroup_GetPosition("eg_southBase_stratPoint1"), 1)
EGroup_ForceAddOn("eg_southBase_listeningPost1", "addon_tau_list_post_1" )

-- Strategic Point by the West Base
EGroup_SetPlayerOwner("eg_westBase_stratPoint1", g_Player2)
Entity_CreateBuildingPosition(g_Player2, "eg_westBase_listeningPost1", "tau_listening_post", EGroup_GetPosition("eg_westBase_stratPoint1"), 1)
EGroup_ForceAddOn("eg_westBase_listeningPost1", "addon_tau_list_post_1" )

-- Strategic Points by the Laser Gun 
EGroup_SetPlayerOwner("eg_laserGun_stratPoint1", g_Player2)
Entity_CreateBuildingPosition(g_Player2, "eg_laserGun_listeningPost1", "tau_listening_post", EGroup_GetPosition("eg_laserGun_stratPoint1"), 1)
EGroup_ForceAddOn("eg_laserGun_listeningPost1", "addon_tau_list_post_1" )

-------------------------------------------------------------------------------------------------------------------------------------------------
-- Critical Point Ownership
-------------------------------------------------------------------------------------------------------------------------------------------------
-- Set the Critical location connected to the laser gun
EGroup_SetPlayerOwner("eg_laserGun_critPoint", g_Player2)

-- Critical Point by the West Base
EGroup_SetPlayerOwner("eg_westBase_critPoint", g_Player2)

-------------------------------------------------------------------------------------------------------------------------------------------------
-- Relic Ownership  & Upgrades to Listening Posts (Also Upgrade them to Level 2)
-------------------------------------------------------------------------------------------------------------------------------------------------
-- Relic by RelicBase (Center of Map) :
EGroup_SetPlayerOwner("eg_relicBase_relic1", g_Player2)

-- Entity_CreateBuildingPosition(g_Player2, "eg_relicBase_listeningPostRelic1", "tau_listening_post", EGroup_GetPosition("eg_relicBase_relic1"), 1) -- EGroup_ForceAddOn("eg_relicBase_listeningPostRelic1", "addon_tau_list_post_2" )

-- Relic by the Main Tau Stronghold :
EGroup_SetPlayerOwner("eg_mainStronghold_relic1", g_Player2)
Entity_CreateBuildingPosition(g_Player2, "eg_mainStronghold_listeningPostRelic1", "tau_listening_post", EGroup_GetPosition("eg_mainStronghold_relic1"), 1)
EGroup_ForceAddOn("eg_mainStronghold_listeningPostRelic1", "addon_tau_list_post_2" )

end


-- END OF ALL " CREATE AI BUILDINGS " RULES

-- Create all of the initial units in the AI Bases : Called from OnInit function Rule_Create_All_Tau_InitialUnits( ) -- Create the Units for the Initial Defense Area before the Defense Base Rule_Create_DefenseBase_InitialUnits( )

-- Create the Defense Units around rest of bases (entrench broadsides, burrow drones)
Rule_Create_Initial_BaseDefenses()

end

-- Create Units for the Defense Base function Rule_Create_DefenseBase_InitialUnits() -- Create & Entrench the Braodsides in the Initial Area for i=1,1 do Util_CreateSquadsAtMarker(g_Player2, "sg_DefenseBase_broadSide"..i, "tau_broadside_battlesuit_squad", "mkr_defenseBase_broadSide_entrench"..i, 1) Command_Squad( g_Player2, "sg_DefenseBase_broadSide"..i, SCMD_Entrench ) end

-- Create the Firewarriors in the Initial Area
for i=1,3	do
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_DefenseBase_Initial_fireWarrior"..i, "tau_fire_warrior_squad", "mkr_defenseBase_fireWarrior_Spawn"..i, 1, 6)
end

-- Create the Pathfinders in the Initial Area
for i=1,g_strongholdStrengthTier	do
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_DefenseBase_Initial_pathFinder"..i, "tau_pathfinder_squad", "mkr_defenseBase_pathFinder_Spawn"..i, 1, 5)
end

end

-- Create the Initial Entrench Broadsides & Burrowed Drones function Rule_Create_Initial_BaseDefenses() -- Create the Broadsides for rest of bases for i=1,20 do Util_CreateSquadsAtMarker(g_Player2, "sg_initial_broadSide"..i, "tau_broadside_battlesuit_squad", "mkr_initial_broadside_entrench"..i, 1) Command_Squad( g_Player2, "sg_initial_broadSide"..i, SCMD_Entrench ) end

-- create & burrow the drones
for i=1,24 do
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_initial_drone"..i, "tau_drone_squad", "mkr_initial_drone_burrow"..i, 1,5)
	Command_Squad( g_Player2, "sg_initial_drone"..i, SCMD_BurrowToggle )
	g_drone_burrowing_array[i] = false
end

-- LASERGUNBASE: Create & Entrench Broadsides (these are replaced by base when they die)
for i = 1,3 do
	Util_CreateSquadsAtMarker(g_Player2, "sg_laserGunBase_broadside"..i, "tau_broadside_battlesuit_squad", "mkr_laserGunBase_broadside"..i, 1)
	Command_Squad(g_Player2, "sg_laserGunBase_broadside"..i, SCMD_Entrench)
end

end

-- Cause the Drone Squads that are burrowed around the map to pop out & attack when player gets near them function Rule_Drone_Burrow_Ambushing() local droneStillBurrowed = false

-- Loop through all drone squads
for i=1,24 do
	-- If Still Burrowed (& has members left)
	if g_drone_burrowing_array[i] == false and
		SGroup_Count("sg_initial_drone"..i) > 0
	then
		-- A Drone is still Burrowed... (So dont remove rule)
		droneStillBurrowed = true
		
		-- Check Prox to Marker where drone is ambushed
		if	Player_AreSquadsNearMarker(g_Player1, "mkr_initial_drone_burrow"..i)
		then
			-- Unburrow & Attack
			Command_Squad( g_Player2, "sg_initial_drone"..i, SCMD_BurrowToggle )
			g_drone_burrowing_array[i] = true
		end
	end
end

-- if still false, then no drone are left burrowed
if droneStillBurrowed == false
then
	Rule_Remove(Rule_Drone_Burrow_Ambushing)
end	

end

-- GAME START -- Rule_GameStart( ) : Starts the actual mission : Called from OnInit -- Optional: this all could be done in OnInit( ) but this makes it easier to read and is clearer -- Sets up objective, win/lose conditions, tracks characters, etc... -- Rule_StartAI() : Used to Enable the AI after the NIS Finishes : Called from GameStart( )

function Rule_GameStart() if not Event_IsAnyRunning() then -- Silvey Polish 10/18/07: Dave, I moved the music setup after the opening NIS so I have a little more room to breathe. -- Function Used to Setup the Sound and Music : Function Is Defined Below Rule_SetupMusicPlaylist()

	-- Function used to create all the Player Initial Units on the Map (including Honor Guard)
	Rule_Create_All_Player_InitialUnits( )
	
	-- Function used to give the Player Req & Power (Actual Buildings come later)
	Rule_Create_All_Player_Initial_Buildings()
	
	-- Function used to create all the Tau Initial Units on the Map : Function Is Defined Below
	Rule_Create_All_Tau_InitialUnits( )
	
	-- Rule_Objective_Define(): Sets up the Objective Lua Tables, but doesn't actually assign them
	Rule_Objective_Define()
	
	-- Show and Control the Game Timer
	Rule_UI_Game_Timer()
	
	-- Assign the First Two Primary Mission Objectives (waits 2 seconds before Assigning and than checks every 2 seconds) : Functions are defined below
	Rule_AddInterval(Rule_DestroyCoalitionCenter_Objective, 1)
	
	-- Checks if the player has captured the laser gun (critical point by the gun) : Added Here in Case Player Captures the Gun Early
	Rule_AddInterval(Rule_Check_Player_Control_Laser, 1)
	
	-- Set up the check for DEFEAT : Function is Defined Below
	Rule_AddInterval(Rule_EndGame_Defeat, 1)

	-- Check if player has entered 1st region by defenseBase: Begin production & send out patrols to meet the player
	Rule_AddInterval(Rule_Enable_DefenseBase, 1)
	
	-- Checks for Attack on the Laser Gun Base : Controls IE
	Rule_AddInterval(Rule_Check_LaserGunBase_Attack, 5)
	
	-- Checks for Ambushing Burrowed Drones
	Rule_AddInterval(Rule_Drone_Burrow_Ambushing, 5)
	
	-- Checks for Coalition Center Damage & Air Caste Attack
	Rule_AddInterval(Rule_LastStand, 1)
	
	-- Create the SGroups & Sync attacks
	Rule_Create_And_Sync_Attacks()
	
	-- Creates all the troops that wander around the bases to create feeling of life (& to provide small defense forces)
	Rule_Create_Wandering_Troops()
	
	--Causes a few units in each base to wander around it -- giving it the feeling of some life
	Rule_AddInterval(Rule_RandomMovement_Base,15)
	
	-- Restrict the Player From Building Bases
		-- Unrestricted once the real base is dropped in
	if g_HQ_blueprint ~= 0 then
		Player_RestrictBuilding( g_Player1, g_HQ_blueprint )
	end
	if g_bonus_generator ~= 0 then
		Player_RestrictBuilding( g_Player1, g_bonus_generator )
	end
	if g_bonus_turret ~= 0 then
		Player_RestrictBuilding( g_Player1, g_bonus_turret )
	end
	if g_bonus_barracks ~= 0 then
		Player_RestrictBuilding( g_Player1, g_bonus_barracks )
	end
	if g_bonus_barracks2 ~= 0 then
		Player_RestrictBuilding( g_Player1, g_bonus_barracks2 )
	end
	if g_bonus_research ~= 0 then
		Player_RestrictBuilding( g_Player1, g_bonus_research )
	end
	
	-- Remove this rule so that it never runs again 
	Rule_Remove(Rule_GameStart) 
end

end

-- Initially sets up the timer that shows the total elapsed time function Rule_UI_Game_Timer() g_UI_gameTimer = 0 WinWarning_Add( "ui_gameTime", World_GetPlayerAt(0), "", "", "" ) Rule_AddInterval(Rule_UI_Game_Timer_Tick, 1) end

-- Updates & Shows the game timer every second function Rule_UI_Game_Timer_Tick() g_UI_gameTimer = g_UI_gameTimer+1 WinWarning_SetText( "ui_gameTime", Loc_FormatText1( 60445, Loc_FormatTime( 60409, g_UI_gameTimer ) ) ) end


-- END OF ALL "GAME START" RULES


-- OBJECTIVES -- INTIAL DEFINE: -- Rule_Objective_Define(): Sets up the actual Objective Lua Tables -- Doesn't actually assign the objectives -- Just sets up the tables for them

-- ASSIGNING AND CHECKING:
	-- Rule_DestroyCoalitionCenter_Objective() : Primary Objective
		-- Checks if the Ethereal Building Has been destroyed
		-- Completion calls: Rule_EtherealBuilding_HasBeenDestroyed( )
	-- Rule_BreachDefenses_Objective() : Primary Ojective
		-- Checks if buildings that make up Defense Base are destroyed
		-- Completing gives player Moon Base
	-- Rule_CaptureLaserGun_Objective : Secondary Objective
		-- NOT CURRENTLY USED
		-- Checks if the Laser Gun has been captured by Player
	-- Rule_ReCaptureLaserGun_Objective()
		-- Checks if the Laser Gun has been captured / recaptured by Player

-- Sets up the actual Objective Lua Tables & is called from OnInit( ) function Rule_Objective_Define() -- Primary Objective : Assigned at Intro (Completion equals VICTORY of SCENARIO) Objective_DestroyCoalitionCenter = { title_id = 3950196, short_desc_id = 3950197, help_tip_id = 3950197}

-- Primary Ojective : Assigned at Intro (Completed once player is by heavy defences and has cleared area for base)
Objective_BreachDefenses = { title_id = 3950198, short_desc_id = 3950199, help_tip_id = 3950199}

-- Secondary Objective: Assigned once Gun starts firing at player (Completed once Laser Gun in under player control)
Objective_CaptureLaserGun = { title_id = 3950204, short_desc_id = 3950205, help_tip_id = 3950205}

-- Secondary Objective: Assigned if Tau regain control of of Gun after player has captured it (Completed once Laser Gun in back under player control)
Objective_ReCaptureLaserGun = { title_id = 3950204, short_desc_id = 3950205, help_tip_id = 3950205}

-- Secondary Objective: Assigned once Player Base is Established (or is it begining of mission) (Completed once All Beacons are Destroyed -- Failed if timer expires)
Objective_DestroyBeacons	=	{ title_id = 3950200, short_desc_id = 3950201, help_tip_id = 3950201}

end

-- Assigns & Checks for Primary Ojective : (Destroy the Ethereal Building) function Rule_DestroyCoalitionCenter_Objective() if Event_IsAnyRunning() == false and Objective_Exists(Objective_DestroyCoalitionCenter.title_id) == false then -- Play Initial IE: Util_StartIntel(g_ie_Initial_Beachhead_Array[g_intelEvent_raceId])

	-- Create ( & Assign)  the objective as a primary one
	Util_ObjectiveCreate(Objective_DestroyCoalitionCenter, true)
	g_PrimaryObjectives = g_PrimaryObjectives + 1
	
	-- Ping the Location of the Building in the Objective Screen
	Objective_PingMarker(Objective_DestroyCoalitionCenter.title_id, "mkr_mainStronghold_PurposeShrine1", true, default)
	
	-- Ping the location of the Building in the Main Game screen & breifly reveal Fog of War around location
	Ping_Marker("mkr_mainStronghold_PurposeShrine1",false,"default")
	FOW_RevealMarker("mkr_mainStronghold_PurposeShrine1", 20)
	
	-- Assign Breach Defenses Objective
	Rule_AddInterval(Rule_BreachDefenses_Objective, 1)

-- Else Check if the CoalitionCenter in Main Stronghold has been destroyed
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_DestroyCoalitionCenter.title_id) == true and
	EGroup_Count( EGroup_FromName("eg_mainStronghold_EtherealBuilding_Objective")) == 0
then	
	-- Complete the Objective and Remove the Rule
	Util_ObjectiveComplete(Objective_DestroyCoalitionCenter.title_id)
	Rule_Remove( Rule_DestroyCoalitionCenter_Objective )
	
	-- Add the Victory & Remove the Defeat Rule since Player Won (in case defeat occurs in delay time)
	Rule_AddOneShot(Rule_EndGame_Victory,10)
	Rule_Remove(Rule_EndGame_Defeat)
end

end

-- Assigns & Checks for Primary Ojective : (Breach Initial Tau defences and clear area) function Rule_BreachDefenses_Objective() -- First check if Objective exists and add if not... if Event_IsAnyRunning() == false and Objective_Exists(Objective_BreachDefenses.title_id) == false then -- Create (Assign) the objective as a primary one Util_ObjectiveCreate(Objective_BreachDefenses, true)

	-- Reveal the Fog of War Around the Base (reveal until objective complete)
	FOW_RevealMarker("mkr_Ai_FoundPlayerBase",10)
	
	-- Ping the Location of the Building in the Objective Screen
	Objective_PingMarker(Objective_BreachDefenses.title_id, "mkr_Ai_FoundPlayerBase", true, default)
	
	-- Update & Set the Primary Objective To this one when objective screen shows
	g_PrimaryObjectives = g_PrimaryObjectives + 1
	Objective_SetDefaultPrimary(g_PrimaryObjectives)
	
	-- Show the Objective Screen		
	Objective_ShowScreen()

-- check if all buildings that make up the Initial Tau Defenses are Destroyed
elseif Event_IsAnyRunning() == false and
	EGroup_Count( EGroup_FromName("eg_defenseBase_Buildings_Objective")) == 0
then
	-- Complete the Objective and Remove the Rule
	Util_ObjectiveComplete( Objective_BreachDefenses.title_id )
	Rule_Remove( Rule_BreachDefenses_Objective )
	
	-- Now that defense are breached -- give the player their bases 
	Rule_AddOneShot( Rule_BuildMoonBase, 0)
end

end

-- Assigns & Check for Secondary Objective : (Capture the Laser Gun) & is added in Rule_Aim_And_Fire_Laser_Gun_FirstTime() -- NOT USED!! function Rule_CaptureLaserGun_Objective( ) -- First check if Objective exists and add if not... if Event_IsAnyRunning() == false and Objective_Exists(Objective_CaptureLaserGun.title_id) == false then -- Create (Assign) the objective as a secondary one Util_ObjectiveCreate(Objective_CaptureLaserGun, false) Objective_PingMarker(Objective_CaptureLaserGun.title_id, "mkr_laserGun_Location", true, attack)

	-- Set up a ping on the ingame screen
	Ping_Marker("mkr_laserGun_Location", false, "default")
	
	-- Set Amount of time between laser guns shots
	g_laserGunCounter = g_laserGunCounterMax
	
	-- Show the timer on the screen
	UI_ShowCountDXP("LaserGunUi", g_Player1, 3950228, g_laserGunCounter )
	
	-- Checks if the player has captured the laser gun (critical point by the gun)
	Rule_AddInterval(Rule_Check_Player_Control_Laser, 1)
	
	-- Show the Objective Screen 
	Objective_ShowScreen()

-- if the player captures the laser gun
elseif	Event_IsAnyRunning() == false and
		Objective_Exists(Objective_CaptureLaserGun.title_id) == true and
		g_PlayerOwnsLaserGun == true
then	
	-- Complete the Objective and Remove the Rule
	Util_ObjectiveComplete(Objective_CaptureLaserGun.title_id)
	Rule_Remove(Rule_CaptureLaserGun_Objective)
	
	-- Hide UI Timer
	UI_HideCount("LaserGunUi")
end

-- Reveal Fog of War for the Objective (reveals until objective complete)
FOW_RevealMarker("mkr_laserGun_Location", 5)

end

-- Assigns & Checks for Secondary Objective : (Recapture the Laser Gun) & is added in Rule_Aim_And_Fire_Laser_Gun_FirstTime() function Rule_ReCaptureLaserGun_Objective() -- First check if Objective exists and add if not... if Event_IsAnyRunning() == false and Objective_Exists(Objective_ReCaptureLaserGun.title_id) == false then -- Create (Assign) the objective as a secondary one Util_ObjectiveCreate(Objective_ReCaptureLaserGun, false) Objective_PingMarker(Objective_ReCaptureLaserGun.title_id, "mkr_laserGun_Location", true, attack)

	-- Set up a ping on the ingame screen
	Ping_Marker("mkr_laserGun_Location", false, "default")
	
	-- Reveal Fog of War for the Objective
	FOW_RevealMarker("mkr_laserGun_Location", 10)
	
	-- if Tau Still Owns the Gun, Show Timer Till Next Shot
	if g_PlayerOwnsLaserGun == false
	then
		-- Set Amount of time between laser guns shots
		g_laserGunCounter = g_laserGunCounterMax
		
		-- Show the timer on the screen
		UI_ShowCountDXP("LaserGunUi", g_Player1, 3950228, g_laserGunCounter )
		
		-- Show the Objective Screen 
		Objective_ShowScreen()
	end

-- Check if Exsists, is completed, and yet player doesn't own gun
	-- Used for resetting this after completed the first time
elseif Event_IsAnyRunning() == false and 
		Objective_Exists(Objective_ReCaptureLaserGun.title_id) == true and
		g_PlayerOwnsLaserGun == false and
		Objective_GetState(Objective_ReCaptureLaserGun.title_id) == OS_Complete
then
	-- Re-ping the locatopn and set objective back to failed (can't set to incomplete for some reason)
	Objective_PingMarker(Objective_ReCaptureLaserGun.title_id, "mkr_laserGun_Location", true, attack)
	Objective_SetState(Objective_ReCaptureLaserGun.title_id, OS_Failed)

-- if the player captures the laser gun
elseif Event_IsAnyRunning() == false and
		g_PlayerOwnsLaserGun == true
then	
	-- Create & Jump in the Cris Suits from Relic Base:
	Rule_AddOneShot(Rule_RelicBase_LaserCapture, 5)
	
	-- Complete the Objective and Remove the Rule
	Objective_SetState(Objective_ReCaptureLaserGun.title_id, OS_Complete)
	Rule_Remove(Rule_ReCaptureLaserGun_Objective)
end

end

-- Assigns & Check for Secondary Objective : (Destroy Three Guidance Beacons) function Rule_DestroyBeacons_Objective() -- ASSIGN: Confirm the Objective doesn't exist if Event_IsAnyRunning() == false and Objective_Exists(Objective_DestroyBeacons.title_id) == false then -- Create (Assign) the objective as a secondary one Objective_Add(Objective_DestroyBeacons, false)

	--Associate a Ping with the Objective on the Objective Screen (Ping the 2 Generator Locations)
	g_BeaconOnePing_Objective = Objective_PingMarker(Objective_DestroyBeacons.title_id, "mkr_commTower_1", true, attack)
	g_BeaconTwoPing_Objective = Objective_PingMarker(Objective_DestroyBeacons.title_id, "mkr_commTower_2", true, attack)
	g_BeaconThreePing_Objective = Objective_PingMarker(Objective_DestroyBeacons.title_id, "mkr_commTower_3", true, attack)
	
	-- Reveal Fog Briefly around each Beacon
	FOW_RevealMarker("mkr_commTower_1", 20)
	FOW_RevealMarker("mkr_commTower_2", 20)
	FOW_RevealMarker("mkr_commTower_3", 20)
	
	-- Set Amount of time until Fleet Arrives
	g_beaconCounter = g_beaconCounterMax
	
	-- Show the Fleet Timer on the screen (Show in Hr:Min:Sec)
	WinWarning_Add( "BeaconUi", World_GetPlayerAt(0), "", "", "" )
	
	-- Controls the On Screen Counter For the Beacon Warning
	Rule_AddInterval(Rule_Beacon_Warning, 1)
	
	-- Set the Hidden Timer up for Laser Gun Warm up
	g_laserGunWarmupCounter = g_laserGunWarmupCounterMax
	
	-- Start the Hidden Timer until first laser shot fires
	Rule_AddInterval(Rule_Hidden_Laser_Gun_Warm_Up,1)
	
	-- Show the Objective Screen 
	Objective_ShowScreen()

-- FAIL: The Fleet has Arrived
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_DestroyBeacons.title_id) == true and
	g_fleet_arrived == true
then
	-- Fail the Objective & Remove the Rule
	Objective_SetState(Objective_DestroyBeacons.title_id, OS_Failed)
	Rule_Remove(Rule_DestroyBeacons_Objective)

-- COMPLETE: The objective exists & All of the Beacons are destroyed
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_DestroyBeacons.title_id) == true and
	EGroup_Count("eg_All_Beacons_Objective") == 0
then
	-- Play IE
	Util_StartIntel(EVENTS.IE_Beacon_Destroyed_Three)
	g_AllBeaconsDestroyed = true
	
	-- Remove Rules Associated With Beacons
	Rule_Remove(Rule_Beacon_Warning)
	
	-- Hide UI Timer
	UI_HideCount("BeaconUi")
	
	-- Activate Main Base: (If Not Already Active)
	g_base_activated_Main	=	true
	
	-- Complete the Objective and Remove the Rule
	Util_ObjectiveComplete(Objective_DestroyBeacons.title_id)
	Rule_Remove(Rule_DestroyBeacons_Objective)

-- UPDATE: The objectives exists & First Beacon is destroyed
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_DestroyBeacons.title_id) == true and
	EGroup_Count("eg_All_Beacons_Objective") == 2 and
	g_beaconDestroyed_One == false
then
	g_beaconDestroyed_One = true
	
	--Play IE:
	Util_StartIntel(EVENTS.IE_Beacon_Destroyed_One)
	
	-- Add Time to the Timer
	g_beaconCounter = g_beaconCounter + g_beaconIncrease_PerTower

-- UPDATE: The objectives exists & Two of the Beacons are destroyed
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_DestroyBeacons.title_id) == true and
	EGroup_Count("eg_All_Beacons_Objective") == 1 and
	g_beaconDestroyed_Two == false
then
	g_beaconDestroyed_Two = true
	
	-- Play IE:
	Util_StartIntel(EVENTS.IE_Beacon_Destroyed_Two)
	
	-- Add Time to the Timer
	g_beaconCounter = g_beaconCounter + g_beaconIncrease_PerTower
end

-- Remove the Pings for any generators that are destroyed
if EGroup_Count("eg_commTower_1") == 0		
then
	Objective_PingRemove(Objective_DestroyBeacons.title_id, g_BeaconOnePing_Objective)
end

if EGroup_Count("eg_commTower_2") == 0
then
	Objective_PingRemove(Objective_DestroyBeacons.title_id, g_BeaconTwoPing_Objective)
end

if EGroup_Count("eg_commTower_3") == 0
then
	Objective_PingRemove(Objective_DestroyBeacons.title_id, g_BeaconThreePing_Objective)
end	

end


-- END OF ALL " OBJECTIVES " RULES

function Rule_Tech_And_Activate_Tier_Zero() -- Add Leaders to the Firewarriors & Stealth Teams g_fireWarrior_leader = true g_stealthTeam_leader = true

-- Activate Bases
g_base_activated_South = true

-- What Percentage of the Squad do troops reinforce up to...
g_reinforce_percent = 0.70

end

function Rule_Tech_And_Activate_Tier_One() -- Enable the Capturing of Strategic Points (was already Capturing Criticals & Relics) g_canCaptureStrat = true

-- What Percentage of the Squad do troops reinforce up to...
g_reinforce_percent = 0.80

-- Activate Vehicles from South Base
g_base_activated_South_Vehicle = true

-- Activate Fire Warriors from West Base
g_base_activated_West = true

-- Increase Stealth Suit Damage	
Player_GrantResearch(g_Player2, "tau_stealth_suit_damage_research")

-- Damage & Range of Fire Warriors & Stealth Suits
Player_GrantResearch(g_Player2, "tau_improved_power_source_research")

end

function Rule_Tech_And_Activate_Tier_Two() -- Enable Bases g_base_activated_East = true g_base_activated_Relic = true

-- Disable Retreating for Squads
g_retreating_enabled =	false

-- Add Shields to Firewarriors & Allow Anti-Vehicle Upgrades on Stealth Suits
g_fireWarrior_shieldDrone 		= true
g_stealthTeam_fusionBlaster 	= true

-- What Percentage of the Squad do troops reinforce up to...
g_reinforce_percent = 0.90

-- Enable Kroot to Leap into Combat
Player_GrantResearch(g_Player2, "tau_feral_leap_research")

-- SkyRay Missile Attack
Player_GrantResearch(g_Player2, "tau_missile_barrage_research")

-- Stealth Suit Accuracy while Moving
Player_GrantResearch(g_Player2, "tau_target_lock")	

end

function Rule_Tech_And_Activate_Tier_Three() -- Enable Bases g_base_activated_NorthWest = true

-- What Percentage of the Squad do troops reinforce up to...
g_reinforce_percent = 0.99

-- Infantry Health
Player_GrantResearch(g_Player2, "tau_improved_metallurgy")

-- Range of Fire Warrior & Stealth Suits
Player_GrantResearch(g_Player2, "tau_targeting_optics")	

end

function Rule_Tech_And_Activate_Tier_Four() -- Enable Main Bases g_base_activated_Main = true end


-- SQUAD AI & TACTICS -- Rule_Squad_Tactics_Helper() : Helper Function that passes squads to the real tactics function & chooses skills for the squad -- Added as an Interval Rule from Rule_Create_And_Sync_Attacks() -- Rule_Squad_Tactics(squad, squad_status, skill_id) : Decides if a squad should Attack, Use Skills, Reinforce, Retreat, or wait since still loading into a transport -- Rule_Squad_Skill(squad, skillID) : Squad tries to use a variety of skills against Player Squads based on skillID passed in

-- Helper Function that passes squads to the real tactics function & chooses skills for the squad -- EastBase, KrootBase, LaserGun Patrols, NorthEast, & NorthWest function Rule_Squad_Tactics_Helper_One() -- Get all the world owned strategic points EGroup_Clear("eg_world_points") World_GetStrategicPoints("eg_world_points")

-- East Base Pathfinders & Broadside:
g_eastBase_troops_status[1] = Rule_Squad_Tactics("sg_eastBase_troops1", g_eastBase_troops_status[1], g_skill_pathfinders)
g_eastBase_troops_status[2] = Rule_Squad_Tactics("sg_eastBase_troops2", g_eastBase_troops_status[2], g_skill_broadsides)

-- Kroot Center Base
sg_krootCenterBase_carnivore_status[1] = Rule_Squad_Tactics("sg_krootCenterBase_troops1", sg_krootCenterBase_carnivore_status[1], g_skill_krootcarnivore)
sg_krootCenterBase_carnivore_status[2] = Rule_Squad_Tactics("sg_krootCenterBase_troops2", sg_krootCenterBase_carnivore_status[2], g_skill_krootcarnivore)

-- Patroling Pathfinders from Laser Gun Base
sg_laserGunBase_patrol_status[1] = Rule_Squad_Tactics("sg_laserGunBase_patrol1", sg_laserGunBase_patrol_status[1], g_skill_pathfinders)
sg_laserGunBase_patrol_status[2] = Rule_Squad_Tactics("sg_laserGunBase_patrol2", sg_laserGunBase_patrol_status[2], g_skill_pathfinders)

for i =1,4 do
	-- Barracuda
	g_eastBase_barracuda_status[i] = Rule_Squad_Tactics("sg_eastBase_barracuda"..i, g_eastBase_barracuda_status[i], g_skill_barracuda)
	
	-- Patroling Carnivore(1,3) & Krootox (2,4)
	sg_northEastBase_patrol_status[i] = Rule_Squad_Tactics("sg_northEastBase_patrol"..i, sg_northEastBase_patrol_status[i], 0)
	
	-- Hounds (1,3) & Krootox (2,4)
	sg_northWestBase_troops_status[i] = Rule_Squad_Tactics("sg_northWestBase_troops"..i, sg_northWestBase_troops_status[i], 0)
	
	-- Patroling Vespids
	sg_northWestBase_patrol_status[i] = Rule_Squad_Tactics("sg_northWestBase_patrol"..i, sg_northWestBase_patrol_status[i], g_skill_vespid)
end

-- Add the Next Tactics Function
Rule_AddOneShot(Rule_Squad_Tactics_Helper_Two, 3)

end

-- Helper Function that passes squads to the real tactics function & chooses skills for the squad -- Main Base & Relic Base function Rule_Squad_Tactics_Helper_Two() -- Get all the world owned strategic points EGroup_Clear("eg_world_points") World_GetStrategicPoints("eg_world_points")

-- Don't Bother with AI Tactics until the Base Activates
if g_base_activated_Main ==	true
then
	-- Main Base:
	g_mainBase_troops_status[1] = Rule_Squad_Tactics("sg_mainStronghold_troops1", g_mainBase_troops_status[1], g_skill_firewarriors)
	g_mainBase_troops_status[2] = Rule_Squad_Tactics("sg_mainStronghold_troops2", g_mainBase_troops_status[2], g_skill_pathfinders)

	g_mainBase_kroot_status[1] = Rule_Squad_Tactics("sg_mainStronghold_kroot1", g_mainBase_kroot_status[1], 0)
	g_mainBase_kroot_status[2] = Rule_Squad_Tactics("sg_mainStronghold_kroot2", g_mainBase_kroot_status[2], 0)

	g_mainBase_vehicle_status[1] = Rule_Squad_Tactics("sg_mainStronghold_vehicle1", g_mainBase_vehicle_status[1], 0)
	g_mainBase_vehicle_status[2] = Rule_Squad_Tactics("sg_mainStronghold_vehicle2", g_mainBase_vehicle_status[2], g_skill_harbinger)

	g_mainBase_stealthSuit_status[1] = Rule_Squad_Tactics("sg_mainStronghold_stealth", g_mainBase_stealthSuit_status[1], g_skill_stealth)
end

-- Crisis Suits
sg_relicBase_crisis_status[1] = Rule_Squad_Tactics("sg_relicBase_crisis1", sg_relicBase_crisis_status[1], g_skill_crisis)
sg_relicBase_crisis_status[2] = Rule_Squad_Tactics("sg_relicBase_crisis2", sg_relicBase_crisis_status[2], g_skill_crisis)

-- Drone Harbringers
sg_relicBase_vehicle_status[1] = Rule_Squad_Tactics("sg_relicBase_vehicle1", sg_relicBase_vehicle_status[1], g_skill_harbinger)

-- Stealth Suits
sg_relicBase_stealthSuit_status[1] = Rule_Squad_Tactics("sg_relicBase_stealthSuit1", sg_relicBase_stealthSuit_status[1], g_skill_stealth)

-- Add the Next Tactics Function
Rule_AddOneShot(Rule_Squad_Tactics_Helper_Three, 3)

end

-- Helper Function that passes squads to the real tactics function & chooses skills for the squad -- South Base, West Base, & Fleet function Rule_Squad_Tactics_Helper_Three() -- Get all the world owned strategic points EGroup_Clear("eg_world_points") World_GetStrategicPoints("eg_world_points")

-- Stealth Suits
sg_westBase_stealthSuit_status[1] = Rule_Squad_Tactics("sg_westBase_stealthSuit1", sg_westBase_stealthSuit_status[1], g_skill_stealth)

-- Fire Warriors
sg_southBase_troops_status[1] = Rule_Squad_Tactics("sg_southBase_troops1", sg_southBase_troops_status[1], g_skill_firewarriors)

-- Drone Harbinger(1) & Skyray (2)
sg_southBase_vehicles_status[1] = Rule_Squad_Tactics("sg_southBase_vehicles1", sg_southBase_vehicles_status[1], g_skill_harbinger)
sg_southBase_vehicles_status[2] = Rule_Squad_Tactics("sg_southBase_vehicles2", sg_southBase_vehicles_status[2], g_skill_skyray)

-- Fire warrior
sg_westBase_troops_status[1] = Rule_Squad_Tactics("sg_westBase_troops1", sg_westBase_troops_status[1], g_skill_firewarriors)
sg_westBase_troops_status[2] = Rule_Squad_Tactics("sg_westBase_troops2", sg_westBase_troops_status[2], g_skill_firewarriors)

-- pathfinders
sg_westBase_patrol_status[1] = Rule_Squad_Tactics("sg_westBase_patrol1", sg_westBase_patrol_status[1], g_skill_pathfinders)
sg_westBase_patrol_status[2] = Rule_Squad_Tactics("sg_westBase_patrol2", sg_westBase_patrol_status[2], g_skill_pathfinders)

-- Control the Fleet Troops once they Arrive
if g_fleet_arrived == true
then
	sg_fleet_hammerhead_status[1] = Rule_Squad_Tactics("sg_fleet_hammerhead1", sg_fleet_hammerhead_status[1], 0)
	sg_fleet_hammerhead_status[2] = Rule_Squad_Tactics("sg_fleet_hammerhead2", sg_fleet_hammerhead_status[2], 0)
	sg_fleet_droneHarbinger_status[1] = Rule_Squad_Tactics("sg_fleet_droneHarbinger1", sg_fleet_droneHarbinger_status[1], g_skill_harbinger)
	sg_fleet_fireWarrior_status[1] = Rule_Squad_Tactics("sg_fleet_firewarrior1", sg_fleet_fireWarrior_status[1], g_skill_firewarriors)
	sg_fleet_fireWarrior_status[2] = Rule_Squad_Tactics("sg_fleet_firewarrior2", sg_fleet_fireWarrior_status[1], g_skill_firewarriors)
	
	sg_fleet_greaterKnarloc_status[1] = Rule_Squad_Tactics("sg_fleet_greaterKnarloc", sg_fleet_greaterKnarloc_status[1], 0)
	sg_fleet_krootox_status[1] = Rule_Squad_Tactics("sg_fleet_krootox1", sg_fleet_krootox_status[1], 0)
	sg_fleet_krootox_status[2] = Rule_Squad_Tactics("sg_fleet_krootox2", sg_fleet_krootox_status[2], 0)	
end

-- Add the Next Tactics Function
Rule_AddOneShot(Rule_Squad_Tactics_Helper_One, 3)	

end

-- Decides if a squad should Attack, Use Skills, Reinforce, Retreat, or wait since still loading into a transport function Rule_Squad_Tactics(squad, squad_status, skill_id) -- ForEach Function: Check if a Player Owned Strategic Point, Relic or Crit Point is In Range of Squad for Capturing & Sets Attack Location to that point function Rule_Detect_Proximity_CapturePoints_Location(egroupid, itemindex, entityID) EGroup_Clear("building_target") EGroup_Add("building_target", EGroup_GetSpawnedEntityAt(egroupid,itemindex))

	-- If Squad is in proximity of a Non-Tau Owned Relic w/ No LP on it 
	if g_canCaptureRelic == true and
		Prox_SquadsInProximityOfEntities(squad, "building_target", range, true) and
		EGroup_ContainsBlueprints("building_target", g_blueprintRelic, false) == true
	then
		-- Try to Capture the Relic Point
		g_attack_target = EGroup_GetPosition("building_target")
		return true
		
	-- If Squad is in proximity of a Non-Tau Owned Critical Point 
	elseif g_canCaptureCrit == true and
		Prox_SquadsInProximityOfEntities(squad, "building_target", range, true) and
		EGroup_ContainsBlueprints("building_target", g_blueprintCritPoint, false) == true
	then
		-- Try to Capture the Critical Point
		g_attack_target = EGroup_GetPosition("building_target")
		return true
		
	-- If Squad is in proximity of a Non-Tau Owned Strategic Point w/ No LP on it 
	elseif g_canCaptureStrat == true and
		Prox_SquadsInProximityOfEntities(squad, "building_target", range, true) and
		EGroup_ContainsBlueprints("building_target", g_blueprintStratPoint, false) == true
	then
		-- Try to Capture the Strategic Point
		g_attack_target = EGroup_GetPosition("building_target")
		return true
	end	
end

-- Make Sure Squad has members (otherwise function is useless so just return to save time)
if SGroup_CountSpawned(squad) <= 0
then
	return squad_status
end

-- if currently in Attack Mode... (and not a broadside)
if squad_status == g_squad_attacking and
	skill_id ~= g_skill_broadsides
then
	-- If not a vehicle, then check for Reinforce (based on squad size being less then X %)
	if SGroup_IsVehicle(squad) == false and
		Squad_GetMax(SGroup_GetSpawnedSquadAt(squad,1)) > Squad_Count(SGroup_GetSpawnedSquadAt(squad,1)) and
		SGroup_GetAvgLoadout(squad) < g_reinforce_percent
	then
		-- Reinforce
		Command_Squad(g_Player2, squad, SCMD_ReinforceTrooper)
		squad_status = g_squad_reinforcing

	-- Check for & Attempt to use Skills
	elseif skill_id > 0 and Rule_Squad_Skill(squad, skill_id) == true
	then
		-- Skill Fired
		squad_status = g_squad_usingSkill
	
	-- Check for Retreat (based on morale broken)
	elseif g_retreating_enabled == true and 
		SGroup_IsMoraleBroken(squad,true) and
		World_GetRand(0,10) > 6
	then
		-- Give Location To Retreat To
		Command_SquadPos(g_Player2, squad, SCMD_Move, g_retreat_target)
		squad_status = g_squad_retreating
	
	-- Just Choose "Attack Target" & Attack Move if none of the above
	else
		-- Get the default Attack Targets For the AI Troops
		g_attack_target = Marker_GetPosition(Marker_FromName("mkr_player_mainBase_HQ1", "basic_marker"))
		
		-- Set Range for Target Tracking for Strategic Points:
		range = 150
		
		-- Override Attack Target for Locations of any Player Owned Relic, Critical or Strategic Points:
		if EGroup_ForEach(Player_GetEntities(g_Player1), Rule_Detect_Proximity_CapturePoints_Location)
		then
			-- Do Nothing... ForEach functions already did it
		
		-- Override Attack Target for Locations of any World Owned Relic, Critical or Strategic Points:
		elseif EGroup_Count("eg_world_points") > 0 and
			EGroup_ForEach("eg_world_points", Rule_Detect_Proximity_CapturePoints_Location)
		then
			-- Do Nothing... ForEach functions already did it
		end
		
		-- Attack Move to the Chosen Attack Target (Either default or the location of the strategic pt)
		Cmd_AttackMovePos(squad,g_attack_target)
	end

-- if currently in retreat mode
elseif squad_status == g_squad_retreating
then
	-- Check for Reinforce (based on squad size being less then X %)
	if Squad_GetMax(SGroup_GetSpawnedSquadAt(squad,1)) > Squad_Count(SGroup_GetSpawnedSquadAt(squad,1)) and
		SGroup_GetAvgLoadout(squad) < g_reinforce_percent
	then
		Command_Squad(g_Player2, squad, SCMD_ReinforceTrooper)
		squad_status = g_squad_retreating
	
	-- else set to attack mode if the morale is restored
	elseif SGroup_IsMoraleBroken(squad,true) == false
	then
		squad_status = g_squad_attacking
	end

-- Buy Transports another cycle or two to finish loading, before they attack (loading->produced->attacking)
elseif squad_status == g_squad_loading
then
	squad_status = g_squad_produced

-- Handles Broadside Entrenching
elseif skill_id == g_skill_broadsides
then
	-- If Currently Entrenched & No one in the area...
	if squad_status == g_squad_entrenched and
		Rule_Squad_Skill(squad, skill_id) == false
	then
		-- Un-Entrench:
		Command_Squad(g_Player2, squad, SCMD_Entrench)
		squad_status = g_squad_attacking
	
	-- If Entrenched & Enemies Still in the area...
	elseif squad_status == g_squad_entrenched and 
		Rule_Squad_Skill(squad, skill_id) == true
	then
		--Do Nothing (stay entrenched)
		squad_status = g_squad_entrenched
	
	-- Not Entrenched, so Check for enemies in the area
	elseif squad_status ~= g_squad_entrenched and 
		Rule_Squad_Skill(squad, skill_id) == true
	then
		-- Entrench:
		Command_Squad(g_Player2, squad, SCMD_Entrench)
		squad_status = g_squad_entrenched
	
	-- No one in area, so attack move away
	else
		squad_status = g_squad_attacking
		Cmd_AttackMovePos(squad,g_attack_target)
	end

-- Handles Patrolling Squads: Try & Use Skill, Otherwise do nothing -- Patrol Functions Handle Movement & Reinforcing
elseif squad_status == g_squad_patrolling
then	
	if skill_id > 0 and Rule_Squad_Skill(squad, skill_id) == true
	then
		-- Do Nothing (Just cast the skill)
		squad_status = g_squad_patrolling
	end
	
	-- Leave in Patrol State
	squad_status = g_squad_patrolling

-- Set Back to Attack Mode since everything else is done
	-- Includes g_squad_status == g_squad_reinforcing & g_squad_usingSkill
else
	squad_status = g_squad_attacking
end

-- return the new squad status
return squad_status	

end

-- Squad tries to use a variety of skills against Player Squads based on skillID passed in
function Rule_Squad_Skill(squad, skillID) -- ForEach Function: Checks if a Enemy Squad (Non-Vehicle) is In Range of Your Squad for Skill Targeting function Rule_Detect_Proximity(sgroupid, itemindex, squadID) SGroup_Clear("skill_target") SGroup_Add("skill_target", SGroup_GetSpawnedSquadAt(sgroupid,itemindex))

	if SGroup_IsVehicle("skill_target") == false and
		Prox_SquadsInProximityOfSquads(squad, "skill_target", range, true) and
		Prox_SquadsInProximityOfSquads(squad, "skill_target", rangeMin, true) == false
	then
		return true
	end
end

-- ForEach Function: Check if a Enemy Vehicle is In Range of Your Squad for Skill Targeting
function Rule_Detect_Proximity_Vehicles(sgroupid, itemindex, squadID)
	SGroup_Clear("skill_target")
	SGroup_Add("skill_target", SGroup_GetSpawnedSquadAt(sgroupid,itemindex))

	if SGroup_IsVehicle("skill_target") and
		Prox_SquadsInProximityOfSquads(squad, "skill_target", range, true) and
		Prox_SquadsInProximityOfSquads(squad, "skill_target", rangeMin, true) == false
	then
		return true
	end
end

-- ForEach Function: Check if a Enemy Building is In Range of Your Squad for Skill Targeting
function Rule_Detect_Proximity_Buildings(egroupid, itemindex, entityID)
	EGroup_Clear("building_target")
	EGroup_Add("building_target", EGroup_GetSpawnedEntityAt(egroupid,itemindex))
	
	-- Avoid Basic Strategic Point, Relic, Critical Point (also avoid the laser gun & cannibalism parts)
	local blueprintTable = Util_MakeBlueprintTable("relic_struct", "strategic_point_flag", "strategic_objective_struct", "tau_lasergun", "cannibalism_Parts")
	
	if Prox_SquadsInProximityOfEntities(squad, "building_target", range, true) and
		EGroup_ContainsBlueprints("building_target", blueprintTable, false) == false
	then
		return true
	end	
end

-- ForEach Function: Check if a Player Owned Strategic Point, Relic or Crit Point is In Range of Squad for Capturing
function Rule_Detect_Proximity_CapturePoints(egroupid, itemindex, entityID)
	EGroup_Clear("building_target")
	EGroup_Add("building_target", EGroup_GetSpawnedEntityAt(egroupid,itemindex))
	
	-- If Squad is in proximity of a Non-Tau Owned Relic w/ No LP on it 
	if g_canCaptureRelic == true and
		Prox_SquadsInProximityOfEntities(squad, "building_target", range, true) and
		EGroup_ContainsBlueprints("building_target", g_blueprintRelic, false) == true and
		EGroup_HasStrategicPointWithStructure("building_target") == false
	then
		-- Try to Capture the Relic Point
		Cmd_Capture(squad, "building_target")
		return true
	
	-- If Squad is in proximity of a Non-Tau Owned Critical Point 
	elseif g_canCaptureCrit == true and
		Prox_SquadsInProximityOfEntities(squad, "building_target", range, true) and
		EGroup_ContainsBlueprints("building_target", g_blueprintCritPoint, false) == true
	then
		-- Try to Capture the Critical Point
		Cmd_Capture(squad, "building_target")
		return true	
	
	-- If Squad is in proximity of a Non-Tau Owned Strategic Point w/ No LP on it 
	elseif g_canCaptureStrat == true and
		Prox_SquadsInProximityOfEntities(squad, "building_target", range, true) and
		EGroup_ContainsBlueprints("building_target", g_blueprintStratPoint, false) == true and
		EGroup_HasStrategicPointWithStructure("building_target") == false
	then
		-- Try to Capture the Strategic Point
		Cmd_Capture(squad, "building_target")
		return true			
	end	
end

-- g_skill_crisis (jump, missle (v), flamer(infantry) -- g_skill_devilfish (transport)

rangeMin = 0

-- vespid ( destabilization, sonic pulse)
if skillID == g_skill_vespid
then
	range = 35
	
	-- Use Sonic Pulse on nearby Infantry
	if 	SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity) and
		SGroup_Count("skill_target") > 0 and
		Cmd_CastAbilitySGroup(squad, "tau_sonic_pulse", "skill_target")
	then
		return true
	
	-- Use Sonic Pulse on nearby Vehicles
	elseif SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity_Vehicles) and
		SGroup_Count("skill_target") > 0 and
		Cmd_CastAbilitySGroup(squad, "tau_sonic_pulse", "skill_target")
	then
		return true
		
	-- Use Destabilization on nearby Buildings
	elseif EGroup_ForEach(Player_GetEntities(g_Player1), Rule_Detect_Proximity_Buildings) and
		EGroup_Count("building_target") > 0 and
		Cmd_CastAbilitySGroupE(squad, "tau_devour", "building_target")
	then
		return true
	
	-- If Morale Not Broken -- Prioritize Infantry for attacks:
	elseif SGroup_IsMoraleBroken(squad,true) == false and
		SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity) and
		SGroup_Count("skill_target") > 0
	then
		Cmd_AttackSGroup(squad, "skill_target")
		return true
	end

-- Stealth Suits (Vehicles, emp grenades)
elseif skillID == g_skill_stealth
then
	range = 35
	
	-- Emp Grenades on Enemy Vehicles (Needs: Shas' Vre Leader)
	if SGroup_HasLeader(squad, true) and
		SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity_Vehicles) and
		SGroup_Count("skill_target") > 0 and
		Cmd_CastAbilitySGroup(squad, "tau_emp_grenade", "skill_target")
	then
		return true
	
	-- If Morale Not Broken -- Prioritize Vehicles for attacks:
	elseif SGroup_IsMoraleBroken(squad,true) == false and
		SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity_Vehicles) and
		SGroup_Count("skill_target") > 0
	then
		Cmd_AttackSGroup(squad, "skill_target")
		return false
	end
	
	-- If Morale Not Broken -- Try & Capture Player LPs
	if SGroup_IsMoraleBroken(squad,true) == false and
		EGroup_ForEach(Player_GetEntities(g_Player1), Rule_Detect_Proximity_CapturePoints) and
		EGroup_Count("building_target") > 0
	then
		return true
	
	-- If Morale Not Broken -- Try & Capture World Owned LPs
	elseif SGroup_IsMoraleBroken(squad,true) == false and
		EGroup_Count("eg_world_points") > 0 and
		EGroup_ForEach("eg_world_points", Rule_Detect_Proximity_CapturePoints)
	then
		return true
	end

-- Skyray (missile barage)
elseif skillID == g_skill_skyray
then
	range = 60
	rangeMin = 35
	
	-- Use Missile on nearby Infantry
	if 	SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity) and
		SGroup_Count("skill_target") > 0 and
		Cmd_CastAbilitySGroup(squad, "tau_skyray_missile_barrage", "skill_target")
	then
		return true
	
	-- Use Missile on nearby Vehicles
	elseif SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity_Vehicles) and
		SGroup_Count("skill_target") > 0 and
		Cmd_CastAbilitySGroup(squad, "tau_skyray_missile_barrage", "skill_target")
	then
		return true
	end
	
	range = 35
	rangeMin = 0
	
	-- Prioritize Infantry for attacks:
	if SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity) and
		SGroup_Count("skill_target") > 0
	then
		Cmd_AttackSGroup(squad, "skill_target")
		return true
	end

-- Harbinger (Produce Drones & Attack with them)
elseif skillID == g_skill_harbinger	
then
	range = 70
	
	-- Prioritize Infantry for attacks:
	if SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity) and
		SGroup_Count("skill_target") > 0
	then
		-- Produce a Drone next to the harbriger
		Util_CreateSquadsAtPosition(g_Player2, "sg_drones", "tau_harbinger_drones_squad", SGroup_GetPosition(SGroup_FromName(squad)), 1)
		
		-- stop the harbinger & tell the drones to attack the target
		Cmd_StopSquads(squad)
		Cmd_AttackSGroup("sg_drones", "skill_target")
		return true
	
	-- Prioritize Vehicles
	elseif SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity_Vehicles) and
		SGroup_Count("skill_target") > 0
	then
		-- Produce a Drone next to the harbriger
		Util_CreateSquadsAtPosition(g_Player2, "sg_drones", "tau_harbinger_drones_squad", SGroup_GetPosition(SGroup_FromName(squad)), 1)
		
		-- stop the harbinger & tell the drones to attack the target
		Cmd_StopSquads(squad)
		Cmd_AttackSGroup("sg_drones", "skill_target")
		return true
	
	-- Prioritize Buildings
	elseif EGroup_ForEach(Player_GetEntities(g_Player1), Rule_Detect_Proximity_Buildings) and
		EGroup_Count("building_target") > 0
	then
		-- Produce a Drone next to the harbriger
		Util_CreateSquadsAtPosition(g_Player2, "sg_drones", "tau_harbinger_drones_squad", SGroup_GetPosition(SGroup_FromName(squad)), 1)
		
		-- stop the harbinger & tell the drones to attack the target
		Cmd_StopSquads(squad)
		Cmd_AttackEGroup("sg_drones", "building_target")
		return true
	end	

-- Barracuda (Air Unit) -- Prioritize Vehicle & Buildings
elseif skillID == g_skill_barracuda
then
	range = 50
	
	-- Prioritize Vehicles
	if SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity_Vehicles) and
		SGroup_Count("skill_target") > 0
	then
		Cmd_AttackSGroup(squad, "skill_target")
		return true
	
	-- Prioritize Buildings
	elseif EGroup_ForEach(Player_GetEntities(g_Player1), Rule_Detect_Proximity_Buildings) and
		EGroup_Count("building_target") > 0
	then
		Cmd_AttackEGroup(squad, "building_target")
		return true
	end	

-- Broadsides (entrench)
elseif skillID == g_skill_broadsides
then
	range = 35
	
	-- Return true to Entrench since nearby Vehicles
	if SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity_Vehicles) and
		SGroup_Count("skill_target") > 0
	then
		return true
	
	-- Return true to Entrench since nearby Infantry
	elseif 	SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity) and
		SGroup_Count("skill_target") > 0
	then
		return true
	
	-- Return False since no one in the area
	else
		return false
	end

-- Pathfinders (mark squad)
elseif skillID == g_skill_pathfinders
then
	range = 35
	
	-- Use Mark Squad on nearby Vehicles
	if SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity_Vehicles) and
		SGroup_Count("skill_target") > 0 and
		Cmd_CastAbilitySGroup(squad, "tau_mark_squad", "skill_target")
	then
		return true
	
	-- Use Mark Squad on nearby Infantry
	elseif 	SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity) and
		SGroup_Count("skill_target") > 0 and
		Cmd_CastAbilitySGroup(squad, "tau_mark_squad", "skill_target")
	then
		return true
	end
	
	-- If Morale Not Broken -- Prioritize Infantry for attacks:
	if SGroup_IsMoraleBroken(squad,true) == false and
		SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity) and
		SGroup_Count("skill_target") > 0
	then
		Cmd_AttackSGroup(squad, "skill_target")
		return true
	
	-- If Morale Not Broken -- Try & Capture Unowned LPs
	elseif SGroup_IsMoraleBroken(squad,true) == false and
		EGroup_ForEach(Player_GetEntities(g_Player1), Rule_Detect_Proximity_CapturePoints) and
		EGroup_Count("building_target") > 0
	then
		return true
	
	-- If Morale Not Broken -- Try & Capture World Owned LPs
	elseif SGroup_IsMoraleBroken(squad,true) == false and
		EGroup_Count("eg_world_points") > 0 and
		EGroup_ForEach("eg_world_points", Rule_Detect_Proximity_CapturePoints)
	then
		return true
	end

-- Kroot Carnivores: Capturing Points
elseif skillID == g_skill_krootcarnivore
then
	-- Set Range for Capturing
	range = 35
	
	-- If Morale Not Broken -- Prioritize Infantry for Attack
	if SGroup_IsMoraleBroken(squad,true) == false and
		SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity) and
		SGroup_Count("skill_target") > 0
	then
		Cmd_AttackSGroup(squad, "skill_target")
		return true
	
	-- If Morale Not Broken -- Try & Capture Unowned LPs
	elseif SGroup_IsMoraleBroken(squad,true) == false and
		EGroup_ForEach(Player_GetEntities(g_Player1), Rule_Detect_Proximity_CapturePoints) and
		EGroup_Count("building_target") > 0
	then
		return true
	
	-- If Morale Not Broken -- Try & Capture World Owned LPs
	elseif SGroup_IsMoraleBroken(squad,true) == false and
		EGroup_Count("eg_world_points") > 0 and
		EGroup_ForEach("eg_world_points", Rule_Detect_Proximity_CapturePoints)
	then
		return true
	end

-- Firewarriors Grenades & Energy Shields
elseif skillID == g_skill_firewarriors
then
	-- Set Range for Capturing
	range = 35
	
	-- Try & Capture Unowned LPs
	if EGroup_ForEach(Player_GetEntities(g_Player1), Rule_Detect_Proximity_CapturePoints) and
		EGroup_Count("building_target") > 0
	then
		return true
	end
	
	-- Try & Capture World Owned LPs
	if EGroup_Count("eg_world_points") > 0 and
		EGroup_ForEach("eg_world_points", Rule_Detect_Proximity_CapturePoints)
	then
		return true
	end
	
	-- Grenades on Enemy Infantry Squads (Needs: Shas' Ui Leader)
	if SGroup_HasLeader(squad, true) and
		SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity) and
		SGroup_Count("skill_target") > 0 and
		Cmd_CastAbilitySGroup(squad, "tau_photon_grenade", "skill_target")
	then
		return true
	
	-- Cast Energy Shield if Under Attack (Needs: Shield Drone)
	elseif SGroup_HasLeader(squad, true) and
		SGroup_IsUnderAttack(squad, true) and
		SGroup_Count("skill_target") > 0 and
		Cmd_CastAbilitySelf(squad, "tau_personal_shield")
	then
		return true
	
	-- Prioritize Infantry for attacks:
	elseif SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity) and
		SGroup_Count("skill_target") > 0
	then
		Cmd_AttackSGroup(squad, "skill_target")
		return false
	end
end

end


-- END OF ALL " SQUAD AI & TACTICS " RULES

-- Launchs the first Major Tau Attack here & Enable First Tau Bases -- Also start the hidden timer for laser gun function Rule_Launch_First_Major_Attack() -- Play IE: Util_StartIntel(EVENTS.IE_BeaconObjective)

-- Add Destroy Beacons Objective Here (also starts the hidden laser timers)
Rule_AddInterval(Rule_DestroyBeacons_Objective, 1)

-- Activate KrootCenter Base & Launch First Attack From it
g_base_activated_KrootCenter = true
Rule_AddOneShot(Rule_First_Production_KrootCenterBase, 5)

-- EAST BASE: Attacking Pathfinders, Broadsides & Air Units (Barracuda)
Rule_AddInterval(Rule_Production_EastBase, g_productionTimer_eastBase)

-- KROOTCENTER BASE: Attacking Kroot Carnivores & Vespids
Rule_AddInterval(Rule_Production_KrootCenterBase, g_productionTimer_krootCenterBase)

-- MAIN BASE:
Rule_AddInterval(Rule_Production_MainBase, g_productionTimer_mainBase)

-- NORTHWEST BASE: Attacking KrootHound & Krootox
Rule_AddInterval(Rule_Production_NorthWestBase, g_productionTimer_northWestBase)	

-- RELIC BASE: Crisis Suits, Stealth Suits, & Attacking Drone Harbringers
Rule_AddInterval(Rule_Production_RelicBase, g_productionTimer_relicBase)

-- SOUTH BASE: Attacking Fire Warriors & Drone Harbringer / Skyray
Rule_AddInterval(Rule_Production_SouthBase, g_productionTimer_southBase)

-- WEST BASE: Patroling Pathfinders & Attacking Firewarriors
Rule_AddInterval(Rule_Production_WestBase,g_productionTimer_westBase)

--Handles the Delayed Teching & Activation of Enemy Bases & research
Rule_AddOneShot(Rule_Tech_And_Activate_Tier_Zero, g_time_Tier_Zero)
Rule_AddOneShot(Rule_Tech_And_Activate_Tier_One, g_time_Tier_One)
Rule_AddOneShot(Rule_Tech_And_Activate_Tier_Two, g_time_Tier_Two)
Rule_AddOneShot(Rule_Tech_And_Activate_Tier_Three, g_time_Tier_Three)
Rule_AddOneShot(Rule_Tech_And_Activate_Tier_Four, g_time_Tier_Four)

end


-- BASE PRODUCTION -- Rule_Create_And_Sync_Attacks() : Creates the SGroups Used & Adds all the attack Rules at the same time to sync them

-- DEFENSE BASE
	-- Rule_Enable_DefenseBase() : Gives the Base some units for an initial defense & enables Unit Production
	-- Rule_Production_DefenseBase_Barracks() : Produces Firewarriors from the Barracks
	-- Rule_Production_DefenseBase_KrootNest() : Produces Kroot Carnivores from the Kroot Nest
	-- Rule_Production_DefenseBase_HQ() : Produces Vespids from the HQ

-- EAST BASE
	-- Rule_Production_EastBase() : Produce Pathfinder & Broadsides from Barracks & Barracudas (Air Unit) From Vehicle Bays

-- KROOT CENTER BASE
	-- Rule_First_Production_KrootCenterBase() : Produces the first wave of Kroot Carnivores from Kroot Nest & Vespids from HQ
	-- Rule_Production_KrootCenterBase() : Produces Kroot Carnivores from Kroot Nest & Vespids from HQ
	-- Rule_KrootCenterBase_VespidJump() : Check for & then cause the Vespids to jump to a random building in the Players Starting Area
	-- Rule_KrootCenterBase_VespidSkill() : Use the Vespid Destabalization Skill on the Target Building (Building Takes Double Damage)
	-- Rule_KrootCenterBase_VespidAttack() : Order the Vespids to attack the building after using the skill on it

-- LASER GUN BASE
	-- Rule_Check_LaserGunBase_Attack() : Check if Player is Attacking the Laser Gun & Play IE
	-- Rule_Production_LaserGunBase() : Produce Patroling Pathfinders & Defending Broadsides
	-- Rule_PatrolOne_LaserGunBase() : Controls the Counter-Clockwise Patroling Pathfinders
	-- Rule_PatrolTwo_LaserGunBase() : Controls the Clockwise Patroling Pathfinders

-- MAIN BASE
	-- Rule_Production_MainBase() : Produce Attacking Firewarriors, Pathfinders, Greater Knarloc, Kroot Shaper, Hammerhead, Drone Harbringer, StealthSuit

-- NORTH EAST BASE
	-- Rule_Production_NorthEastBase() : Produce Patroling Kroot Squads: Kroot Carnivore & Krootox
	-- Rule_PatrolOne_NorthEastBase() : Controls the Counter-Clockwise Patroling Kroot
	-- Rule_PatrolTwo_NorthEastBase() : Controls the Clockwise Patroling Kroot

-- NORTH WEST BASE
	-- Rule_Production_NorthWestBase() : Produce Attacking KrootHound & Krootox Squads
	-- Rule_Production_NorthWestBase_Patrol() : Produce Patroling Vespids
	-- Rule_PatrolOne_NorthWestBase() : Controls the Counter-Clockwise Patroling Vespid
	-- Rule_PatrolTwo_NorthWestBase() : Controls the Clockwise Patroling Vespid

-- RELIC BASE
	-- Rule_Production_RelicBase() : Produce Crisis Suits, Stealth Suits, & Attacking Drone Harbringers

-- SOUTH BASE
	-- Rule_Production_SouthBase() : Produce Firewarrior, DroneHarbringer, & Skyray

-- WEST BASE
	-- Rule_Production_WestBase() : Produce Patroling Pathfinders & Attacking Firewarriors, Stealth Suits
	-- Rule_PatrolOne_WestBase() : Controls the Clockwise Patroling Pathfinders
	-- Rule_PatrolTwo_WestBase() : Controls the Couter-Clockwise Patroling Pathfinders

-- Create all the SGroups used in the mission & sync the attack waves function Rule_Create_And_Sync_Attacks() -- SGroup & EGroups used for targeting of skills SGroup_Create("skill_target") EGroup_Create("building_target")

--Egroup for all of the Strategic Points the World Owns
EGroup_Create("eg_world_points")

-- Used to Store All the player units for Laser Gun Targeting
SGroup_Create("sg_players_units")

-- Used to Track & Attack Player Buildings
EGroup_Create("eg_players_buildings_startingArea")
EGroup_Create("eg_vespidTarget")

-- Set up the Retreat target for Squads 
g_retreat_target = Marker_GetPosition(Marker_FromName("mkr_main_stagingGround", "basic_marker"))	

-- Vespid & Stealth Suit jump ability
Player_GrantResearch(g_Player2, "tau_anti_grav_research")

-- Create the DefenseBase Troops
for i = 1,3 do
	SGroup_Create("sg_defenseBase_troops"..i)
	SGroup_Create("sg_defenseBase_pathfinders"..i)
end

-- Create the EastBase Troops
for i = 1,2 do
	SGroup_Create("sg_eastBase_troops"..i)
end

-- Create the Air Units from East Base
for i = 1,4 do
	SGroup_Create("sg_eastBase_barracuda"..i)
end	

-- Create the KrootCenterBase Troops
for i = 1,2 do
	SGroup_Create("sg_krootCenterBase_troops"..i)
end

--KrootCenterBase Vespids
SGroup_Create("sg_krootCenterBase_vespids1")

-- LaserGunBase Patrol Squads
SGroup_Create("sg_laserGunBase_patrol1")
SGroup_Create("sg_laserGunBase_patrol2")

-- Create the Main Base Squads
SGroup_Create("sg_mainStronghold_troops1")
SGroup_Create("sg_mainStronghold_troops2")
SGroup_Create("sg_mainStronghold_kroot1")
SGroup_Create("sg_mainStronghold_kroot2")
SGroup_Create("sg_mainStronghold_vehicle1")
SGroup_Create("sg_mainStronghold_vehicle2")
SGroup_Create("sg_mainStronghold_stealth")

-- Create the NorthEast Patrol Squads
for i = 1,4 do
	SGroup_Create("sg_northEastBase_patrol"..i)
end

-- Create the NorthWest Troops Squads
for i = 1,4 do
	SGroup_Create("sg_northWestBase_troops"..i)
end

-- Create the NorthWest Patrol Squads
for i = 1,4 do
	SGroup_Create("sg_northWestBase_patrol"..i)
end

-- Create the RelicBase Crisis Suits
for i = 1,2 do
	SGroup_Create("sg_relicBase_crisis"..i)
end

-- RelicBase: Crisis Suits to Jump in once player captures Laser 
SGroup_Create("sg_laserAttack_Crisis1")
SGroup_Create("sg_laserAttack_Crisis2")

-- RelicBase Stealth Suits
SGroup_Create("sg_relicBase_stealthSuit1")

-- RelicBase Vehicle Squad
SGroup_Create("sg_relicBase_vehicle1")

-- SGroup_Create("sg_relicBase_vehicle2")

-- Create the SouthBase Troops
for i = 1,1 do
	SGroup_Create("sg_southBase_troops"..i)
end

-- Create the SouthBase Vehicles
for i = 1,2 do
	SGroup_Create("sg_southBase_vehicles"..i)
end

-- Create the WestBase Troops
for i = 1,2 do
	SGroup_Create("sg_westBase_troops"..i)
end

-- West Base Patrol Squads
SGroup_Create("sg_westBase_patrol1")
SGroup_Create("sg_westBase_patrol2")

-- West Base Stealth Suits
SGroup_Create("sg_westBase_stealthSuit1")

-- Skills, Reinforcing, Attacking, etc...
Rule_AddOneShot(Rule_Squad_Tactics_Helper_One, 3)	

-- LASERGUN BASE: Patroling Pathfinders & Defending Broadsides
Rule_AddInterval(Rule_Production_LaserGunBase, g_productionTimer_laserGunBase)

-- NORTHEAST BASE: Patrolling Kroot Carninvores & Krootox
Rule_AddInterval(Rule_Production_NorthEastBase, g_productionTimer_northEastBase)

-- NORTHWEST BASE: Patroling Vespids
Rule_AddInterval(Rule_Production_NorthWestBase_Patrol, g_productionTimer_northWestBase_patrol)	

-- Controls KrootCenterBase Vespid Jumping & Building Attacking
Rule_AddInterval(Rule_KrootCenterBase_VespidSkill,1)
Rule_AddInterval(Rule_KrootCenterBase_VespidJump,1)

-- Handles the Patroling Pathfinders from the Lasergun Base
Rule_AddInterval(Rule_PatrolOne_LaserGunBase,5)
Rule_AddInterval(Rule_PatrolTwo_LaserGunBase,5)

-- Handles the Patroling Pathfinders from the NorthEast Base
Rule_AddInterval(Rule_PatrolOne_NorthEastBase,5)
Rule_AddInterval(Rule_PatrolTwo_NorthEastBase,5)

-- Handles the Patroling Vespids from the NorthWest Base
Rule_AddInterval(Rule_PatrolOne_NorthWestBase,5)
Rule_AddInterval(Rule_PatrolTwo_NorthWestBase,5)

-- Handles the Patroling Pathfinders from the West Base
Rule_AddInterval(Rule_PatrolOne_WestBase,5)
Rule_AddInterval(Rule_PatrolTwo_WestBase,5)

end


-- "DEFENSE BASE" RULES

-- Gives the Base some units for an initial defense & enables Unit Production function Rule_Enable_DefenseBase() -- Check if the player has entered the area... if Player_AreSquadsNearMarker(g_Player1, "mkr_defenseBase_EnableBaseAI") then -- Play IE: Util_StartIntel(EVENTS.IE_DefendFirstBase)

	-- Produce some Initial Fire Warriors & Pathfinders and Order to Attack the Player (1-3)
	for i = 1, g_strongholdStrengthTier do
		Rule_Produce_Firewarrior(g_Player2, "sg_defenseBase_troops"..i, "eg_defenseBase_Barracks1", "mkr_defenseBase_Barracks1")
		Rule_Produce_Pathfinder(g_Player2, "sg_defenseBase_pathfinders"..i, "eg_defenseBase_Barracks1", "mkr_defenseBase_Barracks1")
		
		Cmd_AttackMoveMarker("sg_defenseBase_troops"..i, "mkr_Ai_Patrol_InitialArea")
		Cmd_AttackMoveMarker("sg_defenseBase_pathfinders"..i, "mkr_Ai_Patrol_InitialArea")			
	end
	
	-- Produce Firewarriors, Kroot Carnivores, Vespids from DefenseBase Buildings
	Rule_AddInterval(Rule_Production_DefenseBase_Barracks, g_productionTimer_defenseBase_barracks)
	Rule_AddInterval(Rule_Production_DefenseBase_KrootNest, g_productionTimer_defenseBase_krootNest)
	Rule_AddInterval(Rule_Production_DefenseBase_HQ, g_productionTimer_defenseBase_hq)
	
	-- Remove this Rule since it has done its job
	Rule_Remove(Rule_Enable_DefenseBase)
end

end

-- Produces Firewarriors from the Barracks function Rule_Production_DefenseBase_Barracks() local defenseBase_troopsProduced = false

-- if the Barracks still exists
if EGroup_Count("eg_defenseBase_Barracks1") == 1 and
	EGroup_GetAvgHealth("eg_defenseBase_Barracks1") > 0
then
	-- Loop through all the possible defenseBase_troop Squads
	for i =1,2	do
		-- If the SGroup is Not Currently Used...
		if defenseBase_troopsProduced == false and
			SGroup_Count("sg_defenseBase_troops"..i) == 0
		then
			-- Try to Produce Fire Warriors
			if Rule_Produce_Firewarrior(g_Player2, "sg_defenseBase_troops"..i, "eg_defenseBase_Barracks1", "mkr_defenseBase_Barracks1") == true
			then
				defenseBase_troopsProduced = true
				
				Cmd_AttackMoveMarker("sg_defenseBase_troops"..i, "mkr_Ai_Patrol_InitialArea")	
			end
		end
	end

-- Else Remove the Rule
else
	Rule_Remove(Rule_Production_DefenseBase_Barracks)
end

end

-- Produces Kroot Carnivores from the Kroot Nest function Rule_Production_DefenseBase_KrootNest() local defenseBase_troopsProduced = false

-- If the Kroot Barracks still exists
if EGroup_Count("eg_defenseBase_KrootNest1") == 1 and
	EGroup_GetAvgHealth("eg_defenseBase_KrootNest1") > 0
then
	-- Loop through all the possible defenseBase_troop Squads
	for i =1,2	do
		-- If the SGroup is Not Currently Used...
		if defenseBase_troopsProduced == false and
			SGroup_Count("sg_defenseBase_troops"..i) == 0
		then
			-- Try to Produce Kroot Carnivores
			if Rule_Produce_KrootCarnivore(g_Player2, "sg_defenseBase_troops"..i, "eg_defenseBase_KrootNest1", "mkr_defenseBase_KrootNest1") == true
			then
				defenseBase_troopsProduced = true
				
				Cmd_AttackMoveMarker("sg_defenseBase_troops"..i, "mkr_Ai_Patrol_InitialArea")	
			end
		end
	end

else
	Rule_Remove(Rule_Production_DefenseBase_KrootNest)
end

end

-- Produces Vespids from the HQ function Rule_Production_DefenseBase_HQ() local defenseBase_troopsProduced = false

-- if the HQ still exists
if EGroup_Count("eg_defenseBase_HQ1") == 1 and
	EGroup_GetAvgHealth("eg_defenseBase_HQ1") > 0
then
	-- Loop through all the possible defenseBase_troop Squads
	for i =1,2	do
		-- If the SGroup is Not Currently Used...
		if defenseBase_troopsProduced == false and
			SGroup_Count("sg_defenseBase_troops"..i) == 0
		then
			-- Try to Produce Fire Warriors
			if Rule_Produce_Vespid(g_Player2, "sg_defenseBase_troops"..i, "eg_defenseBase_HQ1", "mkr_defenseBase_HQ1") == true
			then
				defenseBase_troopsProduced = true
				
				Cmd_AttackMoveMarker("sg_defenseBase_troops"..i, "mkr_Ai_Patrol_InitialArea")					
			end
		end
	end

-- else remove the rule since HQ is Destroyed
else
	Rule_Remove(Rule_Production_DefenseBase_HQ)
end

end


-- "EAST BASE" RULES

-- Produce Pathfinder & Broadsides from Barracks & Barracudas (Air Unit) From Vehicle Bays function Rule_Production_EastBase() --Loop through all Barracks & if still exists... for j =1,2 do local eastBase_troopsProduced = false

	if g_base_activated_East == true and
		EGroup_Count("eg_eastBase_Barracks"..j) == 1
	then
		-- Loop through all troop squads
		for i =1,2	do
			-- If the SGroup is Not Currently Used...
			if eastBase_troopsProduced == false and
				SGroup_Count("sg_eastBase_troops"..i) == 0
			then
				-- Try to Produce Pathfinders Squad (1&3) 
				if  i == 1 and						
					Rule_Produce_Pathfinder(g_Player2, "sg_eastBase_troops"..i, "eg_eastBase_Barracks"..j, "mkr_eastBase_Barracks"..j) == true
				then
					eastBase_troopsProduced = true
					g_eastBase_troops_status[i] = g_squad_produced
				
				-- Try to Produce a Broadside (2 & 4)
				elseif  i == 2 and
					Rule_Produce_Broadside(g_Player2, "sg_eastBase_troops"..i, "eg_eastBase_Barracks"..j, "mkr_eastBase_Barracks"..j) == true
				then
					eastBase_troopsProduced = true
					g_eastBase_troops_status[i] = g_squad_produced
				end
			end
		end
	end
	
	eastBase_troopsProduced = false
	
	-- Vehicle Bay: Barracuda (Air Unit)
	if g_base_activated_East == true and
		EGroup_Count("eg_eastBase_VehicleBuilding"..j) == 1
	then
		-- Loop through all troop squads
		for i =1,2	do
			-- If the SGroup is Not Currently Used...
			if eastBase_troopsProduced == false and
				SGroup_Count("sg_eastBase_barracuda"..i) == 0
			then
				-- Try to Produce Air Units Squad 
				if Rule_Produce_Barracuda(g_Player2, "sg_eastBase_barracuda"..i, "eg_eastBase_VehicleBuilding"..j, "mkr_eastBase_VehicleBuilding"..j) == true
				then
					eastBase_troopsProduced = true
					g_eastBase_barracuda_status[i] = g_squad_produced
				end
			end
		end
	end		
end

-- All Baracks are destroyed...Remove Rules since Base is dead
if EGroup_Count("eg_eastBase_Barracks1") == 0 and
	EGroup_Count("eg_eastBase_Barracks2") == 0 and
	EGroup_Count("eg_eastBase_VehicleBuilding1") == 0 and
	EGroup_Count("eg_eastBase_VehicleBuilding2") == 0
then
	Rule_Remove(Rule_Production_NorthEastBase)
end

end


-- "KROOT CENTER BASE" RULES

-- Produces the first wave of Kroot Carnivores from Kroot Nest & Vespids from HQ function Rule_First_Production_KrootCenterBase() --Loop through all Kroot Nests & if still exists... for j =1,2 do local krootCenter_troopsProduced = false

	if g_base_activated_KrootCenter == true and
		EGroup_Count("eg_krootCenterBase_KrootNest"..j) == 1
	then
		-- Loop through all the possible krootCenter_troop Squads
		for i =1,2	do
			-- If the SGroup is Not Currently Used...
			if krootCenter_troopsProduced == false and
				SGroup_Count("sg_krootCenterBase_troops"..i) == 0
			then
				-- Try to Produce Kroot Carnivores
				if Rule_Produce_KrootCarnivore(g_Player2, "sg_krootCenterBase_troops"..i, "eg_krootCenterBase_KrootNest"..j, "mkr_krootCenterBase_KrootNest"..j) == true
				then
					krootCenter_troopsProduced = true
					sg_krootCenterBase_carnivore_status[i] = g_squad_produced	
				end
			end
		end
	end
end

if g_base_activated_KrootCenter == true and
	SGroup_Count("sg_krootCenterBase_vespids1") == 0
then
	-- Try to Produce a New Vespid if HQ is Still Alive
	if Rule_Produce_Vespid(g_Player2, "sg_krootCenterBase_vespids1", "eg_krootCenterBase_HQ1", "mkr_krootCenterBase_HQ1") == true
	then
		-- Order the Vespid Squad to Jump Zone
		Cmd_AttackMoveMarker("sg_krootCenterBase_vespids1", "mkr_Ai_VespidJumpZone")
		
		-- In case last group was killed before the skill gets off...
		g_krootCenterBase_UsedSkill = false
		EGroup_Clear("eg_vespidTarget")	
	end
end

end

-- Produces Kroot Carnivores from Kroot Nest & Vespids from HQ function Rule_Production_KrootCenterBase() --Loop through all Kroot Nests & if still exists... for j =1,2 do local krootCenter_troopsProduced = false

	if g_base_activated_KrootCenter == true and
		EGroup_Count("eg_krootCenterBase_KrootNest"..j) == 1
	then
		-- Loop through all the possible krootCenter_troop Squads
		for i =1,2	do
			-- If the SGroup is Not Currently Used...
			if krootCenter_troopsProduced == false and
				SGroup_Count("sg_krootCenterBase_troops"..i) == 0
			then
				-- Try to Produce Kroot Carnivores
				if Rule_Produce_KrootCarnivore(g_Player2, "sg_krootCenterBase_troops"..i, "eg_krootCenterBase_KrootNest"..j, "mkr_krootCenterBase_KrootNest"..j) == true
				then
					krootCenter_troopsProduced = true
					sg_krootCenterBase_carnivore_status[i] = g_squad_produced	
				end
			end
		end
	end
end

if g_base_activated_KrootCenter == true and
	SGroup_Count("sg_krootCenterBase_vespids1") == 0
then
	-- Try to Produce a New Vespid if HQ is Still Alive
	if Rule_Produce_Vespid(g_Player2, "sg_krootCenterBase_vespids1", "eg_krootCenterBase_HQ1", "mkr_krootCenterBase_HQ1") == true
	then
		-- Order the Vespid Squad to Jump Zone
		Cmd_AttackMoveMarker("sg_krootCenterBase_vespids1", "mkr_Ai_VespidJumpZone")
		
		-- In case last group was killed before the skill gets off...
		g_krootCenterBase_UsedSkill = false
		EGroup_Clear("eg_vespidTarget")	
	end
end

-- All Kroot Nests & HQ are destroyed...Remove Rules since Base is dead
if EGroup_Count("eg_krootCenterBase_KrootNest1") == 0 and
	EGroup_Count("eg_krootCenterBase_KrootNest2") == 0 and
	EGroup_Count("eg_krootCenterBase_HQ1") == 0
then
	-- Make Sure the T1 Bases are active (in case of fast player attack)
	g_base_activated_South = true
	
	Rule_Remove(Rule_Production_KrootCenterBase)
end

end

-- Check for & then cause the Vespids to jump to a random building in the Players Starting Area function Rule_KrootCenterBase_VespidJump() if SGroup_Exists("sg_krootCenterBase_vespids1") and Prox_AllSquadsNearMarker("sg_krootCenterBase_vespids1", "mkr_Ai_VespidJumpZone") == true and EGroup_Count("eg_vespidTarget") == 0 then -- Get All Player Buildings in Opening Area EGroup_Clear("eg_players_buildings_startingArea") Player_GetAllEntitiesNearMarker( g_Player1, "eg_players_buildings_startingArea", "mkr_player_baseArea" )

	eCount = EGroup_Count("eg_players_buildings_startingArea")
	
	if eCount >= 1
	then
		-- Get Location of Building
		eNumber = World_GetRand(1, eCount)
		vespid_pos = Entity_GetPosition(EGroup_GetSpawnedEntityAt(EGroup_FromName("eg_players_buildings_startingArea"), eNumber))
		Cmd_JumpToPos("sg_krootCenterBase_vespids1", vespid_pos)
		
		-- Get the Actual Building so can target with skills
		EGroup_Add("eg_vespidTarget", EGroup_GetSpawnedEntityAt(EGroup_FromName("eg_players_buildings_startingArea"), eNumber))
	end
end

end

-- Use the Vespid Destabalization Skill on the Target Building (Building Takes Double Damage) function Rule_KrootCenterBase_VespidSkill() if SGroup_Exists("sg_krootCenterBase_vespids1") and EGroup_Count("eg_vespidTarget") == 1 and Prox_AllSquadsNearMarker("sg_krootCenterBase_vespids1", "mkr_player_baseArea") == true and g_krootCenterBase_UsedSkill == false then Cmd_CastAbilitySGroupE("sg_krootCenterBase_vespids1", "tau_devour", "eg_vespidTarget") Rule_AddOneShot(Rule_KrootCenterBase_VespidAttack,3) g_krootCenterBase_UsedSkill = true end end

-- Order the Vespids to attack the building after using the skill on it function Rule_KrootCenterBase_VespidAttack() Cmd_AttackEGroup("sg_krootCenterBase_vespids1", "eg_vespidTarget") g_krootCenterBase_UsedSkill = false EGroup_Clear("eg_vespidTarget") end


-- "LASER GUN BASE" RULES

-- Check if Player is Attacking the Laser Gun & Play IE function Rule_Check_LaserGunBase_Attack() if Player_AreSquadsNearMarker(g_Player1, "mkr_laserGun_Location") then -- Count How many play units are at that marker Player_GetAllSquadsNearMarker(g_Player1, "sg_NearMarker", "mkr_laserGun_Location") local unitCount = SGroup_Count("sg_NearMarker")

	--is it enough units to activate a base?
	if unitCount >= g_num_PlayerUnits_ActivateBase
	then
		-- Play IE:
		Util_StartIntel(EVENTS.IE_PlayerNearsBigGun)
		
		-- Remove the Rule:
		Rule_Remove(Rule_Check_LaserGunBase_Attack)
	end
end

end

-- Produce Patroling Pathfinders & Defending Broadsides function Rule_Production_LaserGunBase() --Loop through all Barracks & if still exists... for j =1,2 do local laserGunBase_troopsProduced = false

	if EGroup_Count("eg_laserGunBase_Barracks"..j) == 1
	then
		-- Loop through all the possible laserGunBase_patrol Squads
		for i =1,2	do
			-- If the SGroup is Not Currently Used...
			if laserGunBase_troopsProduced == false and
				SGroup_Count("sg_laserGunBase_patrol"..i) == 0
			then
				-- Try to Produce Pathfinders
				if Rule_Produce_Pathfinder(g_Player2, "sg_laserGunBase_patrol"..i, "eg_laserGunBase_Barracks"..j, "mkr_laserGunBase_Barracks"..j) == true
				then
					laserGunBase_troopsProduced = true
					sg_laserGunBase_patrol_status[i] = g_squad_patrolling
					
					-- Order Patrol Squad to First Patrol Point
					Cmd_AttackMoveMarker("sg_laserGunBase_patrol"..i, "mkr_laserGunBase_Patrol5")
				end
			end
		end
		
		-- If didn't produce a patrol squad -- check if need to replace a broadside
		for i =1,3	do
			-- If the SGroup is Not Currently Used...
			if laserGunBase_troopsProduced == false and
				SGroup_Count("sg_laserGunBase_broadside"..i) == 0
			then
				-- Try to Produce Broadside
				if Rule_Produce_Broadside(g_Player2, "sg_laserGunBase_broadside"..i, "eg_laserGunBase_Barracks"..j, "mkr_laserGunBase_Barracks"..j) == true
				then
					laserGunBase_troopsProduced = true
					
					-- Order Broadside to Entrench Location
					Cmd_AttackMoveMarker("sg_laserGunBase_broadside"..i, "mkr_laserGunBase_broadside"..i)
				end
			end
		end			
	end
end

-- All Barracks are destroyed...Remove Rules since Base is dead
if EGroup_Count("eg_laserGunBase_Barracks1") == 0 and
	EGroup_Count("eg_laserGunBase_Barracks2") == 0
then
	-- Make Sure the T1 Bases are active (in case of fast player attack)
	g_base_activated_South = true
	
	-- Also Activate the Vehicles from South Base
	g_base_activated_South_Vehicle = true
	
	-- Remove the Production Rule & The Rule for Laser Gun IE (in case base was killed without triggering)
	Rule_Remove(Rule_Production_LaserGunBase)
	Rule_Remove(Rule_Check_LaserGunBase_Attack)
end

end

-- Controls the Counter-Clockwise Patroling Pathfinders function Rule_PatrolOne_LaserGunBase() -- If the Squad is Killed if SGroup_Exists("sg_laserGunBase_patrol1") and SGroup_Count("sg_laserGunBase_patrol1") == 0 then -- Unit is Dead, Do Nothing, since production is handled differently

-- Check if the Squad arrived at the Patrol Location 1
elseif SGroup_Exists("sg_laserGunBase_patrol1") and
	Prox_AllSquadsNearMarker("sg_laserGunBase_patrol1", "mkr_laserGunBase_Patrol1")
then
	-- Reinforce BackUp before continuing patrol
	if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_laserGunBase_patrol1",1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_laserGunBase_patrol1",1)) and
		SGroup_GetAvgLoadout("sg_laserGunBase_patrol1") < 0.75
	then
		-- Reinforce
		Command_Squad(g_Player2, "sg_laserGunBase_patrol1", SCMD_ReinforceTrooper)
	else
		-- Task to Next Patrol Point
		Cmd_AttackMoveMarker("sg_laserGunBase_patrol1", "mkr_laserGunBase_Patrol2")
	end

-- Check if the Squad arrived at the Patrol Location 2
elseif SGroup_Exists("sg_laserGunBase_patrol1") and
	Prox_AllSquadsNearMarker("sg_laserGunBase_patrol1", "mkr_laserGunBase_Patrol2")
then
	-- Reinforce BackUp before continuing patrol
	if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_laserGunBase_patrol1",1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_laserGunBase_patrol1",1)) and
		SGroup_GetAvgLoadout("sg_laserGunBase_patrol1") < 0.75
	then
		-- Reinforce
		Command_Squad(g_Player2, "sg_laserGunBase_patrol1", SCMD_ReinforceTrooper)
	else
		-- Task to Next Patrol Point
		Cmd_AttackMoveMarker("sg_laserGunBase_patrol1", "mkr_laserGunBase_Patrol3")
	end

-- Check if the Squad arrived at the Patrol Location 3
elseif SGroup_Exists("sg_laserGunBase_patrol1") and
	Prox_AllSquadsNearMarker("sg_laserGunBase_patrol1", "mkr_laserGunBase_Patrol3")
then
	-- Reinforce BackUp before continuing patrol
	if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_laserGunBase_patrol1",1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_laserGunBase_patrol1",1)) and
		SGroup_GetAvgLoadout("sg_laserGunBase_patrol1") < 0.75
	then
		-- Reinforce
		Command_Squad(g_Player2, "sg_laserGunBase_patrol1", SCMD_ReinforceTrooper)
	else
		-- Task to Next Patrol Point
		Cmd_AttackMoveMarker("sg_laserGunBase_patrol1", "mkr_laserGunBase_Patrol4")
	end

-- Check if the Squad arrived at the Patrol Location 4
elseif SGroup_Exists("sg_laserGunBase_patrol1") and
	Prox_AllSquadsNearMarker("sg_laserGunBase_patrol1", "mkr_laserGunBase_Patrol4")
then
	-- Reinforce BackUp before continuing patrol
	if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_laserGunBase_patrol1",1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_laserGunBase_patrol1",1)) and
		SGroup_GetAvgLoadout("sg_laserGunBase_patrol1") < 0.75
	then
		-- Reinforce
		Command_Squad(g_Player2, "sg_laserGunBase_patrol1", SCMD_ReinforceTrooper)
	else
		-- Task to Next Patrol Point
		Cmd_AttackMoveMarker("sg_laserGunBase_patrol1", "mkr_laserGunBase_Patrol5")
	end

-- Check if the Squad arrived at the Patrol Location 5
elseif SGroup_Exists("sg_laserGunBase_patrol1") and
	Prox_AllSquadsNearMarker("sg_laserGunBase_patrol1", "mkr_laserGunBase_Patrol5")
then
	-- Reinforce BackUp before continuing patrol
	if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_laserGunBase_patrol1",1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_laserGunBase_patrol1",1)) and
		SGroup_GetAvgLoadout("sg_laserGunBase_patrol1") < 0.75
	then
		-- Reinforce
		Command_Squad(g_Player2, "sg_laserGunBase_patrol1", SCMD_ReinforceTrooper)
	else
		-- Task to Next Patrol Point
		Cmd_AttackMoveMarker("sg_laserGunBase_patrol1", "mkr_laserGunBase_Patrol1")
	end	
end

end

-- Controls the Clockwise Patroling Pathfinders function Rule_PatrolTwo_LaserGunBase() -- If the Squad is Killed if SGroup_Exists("sg_laserGunBase_patrol2") and SGroup_Count("sg_laserGunBase_patrol2") == 0 then -- Unit is Dead, Do Nothing, since production is handled differently

-- Check if the Squad arrived at the Patrol Location 5
elseif SGroup_Exists("sg_laserGunBase_patrol2") and
	Prox_AllSquadsNearMarker("sg_laserGunBase_patrol2", "mkr_laserGunBase_Patrol5")
then
	-- Reinforce BackUp before continuing patrol
	if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_laserGunBase_patrol2",1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_laserGunBase_patrol2",1)) and
		SGroup_GetAvgLoadout("sg_laserGunBase_patrol2") < 0.75
	then
		-- Reinforce
		Command_Squad(g_Player2, "sg_laserGunBase_patrol2", SCMD_ReinforceTrooper)
	else
		-- Task to Next Patrol Point
		Cmd_AttackMoveMarker("sg_laserGunBase_patrol2", "mkr_laserGunBase_Patrol4")
	end

-- Check if the Squad arrived at the Patrol Location 4
elseif SGroup_Exists("sg_laserGunBase_patrol2") and
	Prox_AllSquadsNearMarker("sg_laserGunBase_patrol2", "mkr_laserGunBase_Patrol4")
then
	-- Reinforce BackUp before continuing patrol
	if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_laserGunBase_patrol2",1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_laserGunBase_patrol2",1)) and
		SGroup_GetAvgLoadout("sg_laserGunBase_patrol2") < 0.75
	then
		-- Reinforce
		Command_Squad(g_Player2, "sg_laserGunBase_patrol2", SCMD_ReinforceTrooper)
	else
		-- Task to Next Patrol Point
		Cmd_AttackMoveMarker("sg_laserGunBase_patrol2", "mkr_laserGunBase_Patrol3")
	end

-- Check if the Squad arrived at the Patrol Location 3
elseif SGroup_Exists("sg_laserGunBase_patrol2") and
	Prox_AllSquadsNearMarker("sg_laserGunBase_patrol2", "mkr_laserGunBase_Patrol3")
then
	-- Reinforce BackUp before continuing patrol
	if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_laserGunBase_patrol2",1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_laserGunBase_patrol2",1)) and
		SGroup_GetAvgLoadout("sg_laserGunBase_patrol2") < 0.75
	then
		-- Reinforce
		Command_Squad(g_Player2, "sg_laserGunBase_patrol2", SCMD_ReinforceTrooper)
	else
		-- Task to Next Patrol Point
		Cmd_AttackMoveMarker("sg_laserGunBase_patrol2", "mkr_laserGunBase_Patrol2")
	end

-- Check if the Squad arrived at the Patrol Location 2
elseif SGroup_Exists("sg_laserGunBase_patrol2") and
	Prox_AllSquadsNearMarker("sg_laserGunBase_patrol2", "mkr_laserGunBase_Patrol2")
then
	-- Reinforce BackUp before continuing patrol
	if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_laserGunBase_patrol2",1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_laserGunBase_patrol2",1)) and
		SGroup_GetAvgLoadout("sg_laserGunBase_patrol2") < 0.75
	then
		-- Reinforce
		Command_Squad(g_Player2, "sg_laserGunBase_patrol2", SCMD_ReinforceTrooper)
	else
		-- Task to Next Patrol Point
		Cmd_AttackMoveMarker("sg_laserGunBase_patrol2", "mkr_laserGunBase_Patrol1")
	end

-- Check if the Squad arrived at the Patrol Location 1
elseif SGroup_Exists("sg_laserGunBase_patrol2") and
	Prox_AllSquadsNearMarker("sg_laserGunBase_patrol2", "mkr_laserGunBase_Patrol1")
then
	-- Reinforce BackUp before continuing patrol
	if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_laserGunBase_patrol2",1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_laserGunBase_patrol2",1)) and
		SGroup_GetAvgLoadout("sg_laserGunBase_patrol2") < 0.75
	then
		-- Reinforce
		Command_Squad(g_Player2, "sg_laserGunBase_patrol2", SCMD_ReinforceTrooper)
	else
		-- Task to Next Patrol Point
		Cmd_AttackMoveMarker("sg_laserGunBase_patrol2", "mkr_laserGunBase_Patrol5")
	end	
end

end

-- "MAIN BASE" RULES

-- Produce Attacking Firewarriors, Pathfinders, Greater Knarloc, Kroot Shaper, Hammerhead, Drone Harbringer, StealthSuit function Rule_Production_MainBase() --Loop through all Barracks, Kroot Nests, & Vehicle Bays for j =1,2 do local mainBase_troopsProduced = false

	if g_base_activated_Main == true and
		EGroup_Count("eg_mainStronghold_Barracks"..j) == 1
	then
		-- Loop through all troop squads
		for i =1,2	do
			-- If the SGroup is Not Currently Used...
			if mainBase_troopsProduced == false and
				SGroup_Count("sg_mainStronghold_troops"..i) == 0
			then
				-- Try to Produce Pathfinders 
				if  i == 2 and						
					Rule_Produce_Pathfinder(g_Player2, "sg_mainStronghold_troops"..i, "eg_mainStronghold_Barracks"..j, "mkr_mainStronghold_Barracks"..j) == true
				then
					mainBase_troopsProduced = true
					g_mainBase_troops_status[i] = g_squad_produced
				
				-- Try to Produce a Firewarrior
				elseif  i == 1 and
					Rule_Produce_Firewarrior(g_Player2, "sg_mainStronghold_troops"..i, "eg_mainStronghold_Barracks"..j, "mkr_mainStronghold_Barracks"..j) == true
				then
					mainBase_troopsProduced = true
					g_mainBase_troops_status[i] = g_squad_produced
				end
			end
		end
	end
	
	mainBase_troopsProduced = false
	
	if g_base_activated_Main == true and
		EGroup_Count("eg_mainStronghold_KrootNest"..j) == 1
	then
		-- Loop through all troop squads
		for i =1,2	do
			-- If the SGroup is Not Currently Used...
			if mainBase_troopsProduced == false and
				SGroup_Count("sg_mainStronghold_kroot"..i) == 0
			then
				-- Try to Produce Greater Knarloc 
				if  i == 1 and						
					Rule_Produce_GreaterKnarloc(g_Player2, "sg_mainStronghold_kroot"..i, "eg_mainStronghold_KrootNest"..j, "mkr_mainStronghold_KrootNest"..j) == true
				then
					mainBase_troopsProduced = true
					g_mainBase_kroot_status[i] = g_squad_produced
				
				-- Try to Produce a Kroot Shaper
				elseif  i == 2 and
					Rule_Produce_KrootShaper(g_Player2, "sg_mainStronghold_kroot"..i, "eg_mainStronghold_KrootNest"..j, "mkr_mainStronghold_KrootNest"..j) == true
				then
					mainBase_troopsProduced = true
					g_mainBase_kroot_status[i] = g_squad_produced
				end
			end
		end
	end
	
	mainBase_troopsProduced = false
	
	if g_base_activated_Main == true and
		EGroup_Count("eg_mainStronghold_VehicleBuilding"..j) == 1
	then
		-- Loop through all troop squads
		for i =1,2	do
			-- If the SGroup is Not Currently Used...
			if mainBase_troopsProduced == false and
				SGroup_Count("sg_mainStronghold_vehicle"..i) == 0
			then
				-- Try to Produce Hammerhead
				if  i == 1 and						
					Rule_Produce_Hammerhead(g_Player2, "sg_mainStronghold_vehicle"..i, "eg_mainStronghold_VehicleBuilding"..j, "mkr_mainStronghold_VehicleBuilding"..j) == true
				then
					mainBase_troopsProduced = true
					g_mainBase_vehicle_status[i] = g_squad_produced
				
				-- Try to Produce Drone Harbringer
				elseif  i == 2 and
					Rule_Produce_DroneHarbinger(g_Player2, "sg_mainStronghold_vehicle"..i, "eg_mainStronghold_VehicleBuilding"..j, "mkr_mainStronghold_VehicleBuilding"..j) == true
				then
					mainBase_troopsProduced = true
					g_mainBase_vehicle_status[i] = g_squad_produced
				end
			end
		end
	end
end

-- Try to Produce Stealth Suit from HQ if none on battle field
if g_base_activated_Main == true and
	SGroup_Count("sg_mainStronghold_stealth") == 0
then
	if Rule_Produce_StealthTeam(g_Player2, "sg_mainStronghold_stealth", "eg_mainStronghold_HQ1", "mkr_mainStronghold_HQ1") == true
	then
		g_mainBase_stealthSuit_status[1] = g_squad_produced
	end
end

-- All Baracks are destroyed...Remove Rules since Base is dead
if EGroup_Count("eg_mainStronghold_Barracks1") == 0 and
	EGroup_Count("eg_mainStronghold_Barracks2") == 0 and
	EGroup_Count("eg_mainStronghold_KrootNest1") == 0 and
	EGroup_Count("eg_mainStronghold_KrootNest2") == 0 and
	EGroup_Count("eg_mainStronghold_VehicleBuilding1") == 0 and
	EGroup_Count("eg_mainStronghold_VehicleBuilding2") == 0 and
	EGroup_Count("eg_mainStronghold_HQ1") == 0
then
	Rule_Remove(Rule_Production_MainBase)
end

end

-- "NORTH EAST BASE" RULES

-- Produce Patroling Kroot Squads: Kroot Carnivore & Krootox function Rule_Production_NorthEastBase() --Loop through all Barracks & if still exists... for j =1,2 do local northEastBase_troopsProduced = false

	if EGroup_Count("eg_northEastBase_KrootNest"..j) == 1
	then
		-- Loop through all kroot patrol Squads
		for i =1,4	do
			-- If the SGroup is Not Currently Used...
			if northEastBase_troopsProduced == false and
				SGroup_Count("sg_northEastBase_patrol"..i) == 0
			then
				-- Try to Produce Kroot Squad (Patrols 1&3) 
				if  (i == 1 or i == 3) and						
					Rule_Produce_KrootCarnivore(g_Player2, "sg_northEastBase_patrol"..i, "eg_northEastBase_KrootNest"..j, "mkr_northEastBase_KrootNest"..j) == true
				then
					northEastBase_troopsProduced = true
					sg_northEastBase_patrol_status[i] = g_squad_patrolling
					
					-- Order Patrol Squad to First Patrol Point
					Cmd_AttackMoveMarker("sg_northEastBase_patrol"..i, "mkr_northEastBase_Patrol1")
				
				-- Try to Produce a Krootox (Patrols 2 & 4)
				elseif  (i == 2 or i == 4) and
					Rule_Produce_Krootox(g_Player2, "sg_northEastBase_patrol"..i, "eg_northEastBase_KrootNest"..j, "mkr_northEastBase_KrootNest"..j) == true
				then
					northEastBase_troopsProduced = true
					sg_northEastBase_patrol_status[i] = g_squad_patrolling
					
					-- Order Patrol Squad to First Patrol Point
					Cmd_AttackMoveMarker("sg_northEastBase_patrol"..i, "mkr_northEastBase_Patrol1")
				end
			end
		end
	end
end

-- All KrootNests are destroyed...Remove Rules since Base is dead
if EGroup_Count("eg_northEastBase_KrootNest1") == 0 and
	EGroup_Count("eg_northEastBase_KrootNest2") == 0
then
	Rule_Remove(Rule_Production_NorthEastBase)
end

end

-- Controls the Counter-Clockwise Patroling Kroot function Rule_PatrolOne_NorthEastBase() for i = 1,2 do -- If the Squad is Killed if SGroup_Exists("sg_northEastBase_patrol"..i) and SGroup_Count("sg_northEastBase_patrol"..i) == 0 then -- Unit is Dead, Do Nothing, since production is handled differently

	-- Check if the Squad arrived at the Patrol Location 1
	elseif SGroup_Exists("sg_northEastBase_patrol"..i) and
		Prox_AllSquadsNearMarker("sg_northEastBase_patrol"..i, "mkr_northEastBase_Patrol1")
	then
		-- Reinforce BackUp before continuing patrol
		if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_northEastBase_patrol"..i,1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_northEastBase_patrol"..i,1)) and
			SGroup_GetAvgLoadout("sg_northEastBase_patrol"..i) < 0.75
		then
			-- Reinforce
			Command_Squad(g_Player2, "sg_northEastBase_patrol"..i, SCMD_ReinforceTrooper)
		else
			-- Task to Next Patrol Point
			Cmd_AttackMoveMarker("sg_northEastBase_patrol"..i, "mkr_northEastBase_Patrol2")
		end

	-- Check if the Squad arrived at the Patrol Location 2
	elseif SGroup_Exists("sg_northEastBase_patrol"..i) and
		Prox_AllSquadsNearMarker("sg_northEastBase_patrol"..i, "mkr_northEastBase_Patrol2")
	then
		-- Reinforce BackUp before continuing patrol
		if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_northEastBase_patrol"..i,1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_northEastBase_patrol"..i,1)) and
			SGroup_GetAvgLoadout("sg_northEastBase_patrol"..i) < 0.75
		then
			-- Reinforce
			Command_Squad(g_Player2, "sg_northEastBase_patrol"..i, SCMD_ReinforceTrooper)
		else
			-- Task to Next Patrol Point
			Cmd_AttackMoveMarker("sg_northEastBase_patrol"..i, "mkr_northEastBase_Patrol3")
		end

	-- Check if the Squad arrived at the Patrol Location 3
	elseif SGroup_Exists("sg_northEastBase_patrol"..i) and
		Prox_AllSquadsNearMarker("sg_northEastBase_patrol"..i, "mkr_northEastBase_Patrol3")
	then
		-- Reinforce BackUp before continuing patrol
		if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_northEastBase_patrol"..i,1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_northEastBase_patrol"..i,1)) and
			SGroup_GetAvgLoadout("sg_northEastBase_patrol"..i) < 0.75
		then
			-- Reinforce
			Command_Squad(g_Player2, "sg_northEastBase_patrol"..i, SCMD_ReinforceTrooper)
		else
			-- Task to Next Patrol Point
			Cmd_AttackMoveMarker("sg_northEastBase_patrol"..i, "mkr_northEastBase_Patrol4")
		end

	-- Check if the Squad arrived at the Patrol Location 4
	elseif SGroup_Exists("sg_northEastBase_patrol"..i) and
		Prox_AllSquadsNearMarker("sg_northEastBase_patrol"..i, "mkr_northEastBase_Patrol4")
	then
		-- Reinforce BackUp before continuing patrol
		if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_northEastBase_patrol"..i,1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_northEastBase_patrol"..i,1)) and
			SGroup_GetAvgLoadout("sg_northEastBase_patrol"..i) < 0.75
		then
			-- Reinforce
			Command_Squad(g_Player2, "sg_northEastBase_patrol"..i, SCMD_ReinforceTrooper)
		else
			-- Task to Next Patrol Point
			Cmd_AttackMoveMarker("sg_northEastBase_patrol"..i, "mkr_northEastBase_Patrol1")
		end
	end
end

end

-- Controls the Clockwise Patroling Kroot function Rule_PatrolTwo_NorthEastBase() for i =3,4 do -- If the Squad is Killed if SGroup_Exists("sg_northEastBase_patrol"..i) and SGroup_Count("sg_northEastBase_patrol"..i) == 0 then -- Unit is Dead, Do Nothing, since production is handled differently

	-- Check if the Squad arrived at the Patrol Location 4
	elseif SGroup_Exists("sg_northEastBase_patrol"..i) and
		Prox_AllSquadsNearMarker("sg_northEastBase_patrol"..i, "mkr_northEastBase_Patrol4")
	then
		-- Reinforce BackUp before continuing patrol
		if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_northEastBase_patrol"..i,1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_northEastBase_patrol"..i,1)) and
			SGroup_GetAvgLoadout("sg_northEastBase_patrol"..i) < 0.75
		then
			-- Reinforce
			Command_Squad(g_Player2, "sg_northEastBase_patrol"..i, SCMD_ReinforceTrooper)
		else
			-- Task to Next Patrol Point
			Cmd_AttackMoveMarker("sg_northEastBase_patrol"..i, "mkr_northEastBase_Patrol3")
		end

	-- Check if the Squad arrived at the Patrol Location 3
	elseif SGroup_Exists("sg_northEastBase_patrol"..i) and
		Prox_AllSquadsNearMarker("sg_northEastBase_patrol"..i, "mkr_northEastBase_Patrol3")
	then
		-- Reinforce BackUp before continuing patrol
		if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_northEastBase_patrol"..i,1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_northEastBase_patrol"..i,1)) and
			SGroup_GetAvgLoadout("sg_northEastBase_patrol"..i) < 0.75
		then
			-- Reinforce
			Command_Squad(g_Player2, "sg_northEastBase_patrol"..i, SCMD_ReinforceTrooper)
		else
			-- Task to Next Patrol Point
			Cmd_AttackMoveMarker("sg_northEastBase_patrol"..i, "mkr_northEastBase_Patrol2")
		end

	-- Check if the Squad arrived at the Patrol Location 2
	elseif SGroup_Exists("sg_northEastBase_patrol"..i) and
		Prox_AllSquadsNearMarker("sg_northEastBase_patrol"..i, "mkr_northEastBase_Patrol2")
	then
		-- Reinforce BackUp before continuing patrol
		if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_northEastBase_patrol"..i,1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_northEastBase_patrol"..i,1)) and
			SGroup_GetAvgLoadout("sg_northEastBase_patrol"..i) < 0.75
		then
			-- Reinforce
			Command_Squad(g_Player2, "sg_northEastBase_patrol"..i, SCMD_ReinforceTrooper)
		else
			-- Task to Next Patrol Point
			Cmd_AttackMoveMarker("sg_northEastBase_patrol"..i, "mkr_northEastBase_Patrol1")
		end

	-- Check if the Squad arrived at the Patrol Location 1
	elseif SGroup_Exists("sg_northEastBase_patrol"..i) and
		Prox_AllSquadsNearMarker("sg_northEastBase_patrol"..i, "mkr_northEastBase_Patrol1")
	then
		-- Reinforce BackUp before continuing patrol
		if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_northEastBase_patrol"..i,1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_northEastBase_patrol"..i,1)) and
			SGroup_GetAvgLoadout("sg_northEastBase_patrol"..i) < 0.75
		then
			-- Reinforce
			Command_Squad(g_Player2, "sg_northEastBase_patrol"..i, SCMD_ReinforceTrooper)
		else
			-- Task to Next Patrol Point
			Cmd_AttackMoveMarker("sg_northEastBase_patrol"..i, "mkr_northEastBase_Patrol4")
		end		
	end
end

end


-- "NORTH WEST BASE" RULES

-- Produce Attacking KrootHound & Krootox Squads function Rule_Production_NorthWestBase() --Loop through all Barracks & if still exists... for j =1,2 do local northWestBase_troopsProduced = false

	if g_base_activated_NorthWest	 == true and
		EGroup_Count("eg_northWestBase_KrootNest"..j) == 1
	then
		-- Loop through all Kroot Squads
		for i =1,2	do
			-- If the SGroup is Not Currently Used...
			if northWestBase_troopsProduced == false and
				SGroup_Count("sg_northWestBase_troops"..i) == 0
			then
				-- Try to Produce KrootHound (Patrols 1&3) 
				if  (i == 1 or i == 3) and						
					Rule_Produce_KrootHound(g_Player2, "sg_northWestBase_troops"..i, "eg_northWestBase_KrootNest"..j, "mkr_northWestBase_KrootNest"..j) == true
				then
					northWestBase_troopsProduced = true
					sg_northWestBase_troops_status[i] = g_squad_produced
				
				-- Try to Produce a Krootox (Patrols 2 & 4)
				elseif  (i == 2 or i == 4) and
					Rule_Produce_Krootox(g_Player2, "sg_northWestBase_troops"..i, "eg_northWestBase_KrootNest"..j, "mkr_northWestBase_KrootNest"..j) == true
				then
					northWestBase_troopsProduced = true
					sg_northWestBase_troops_status[i] = g_squad_produced
				end
			end
		end
	end
end

-- All KrootNests are destroyed...Remove Rules since Base is dead
if EGroup_Count("eg_northWestBase_KrootNest1") == 0 and
	EGroup_Count("eg_northWestBase_KrootNest2") == 0
then
	Rule_Remove(Rule_Production_NorthWestBase)
end

end

-- Produce Patroling Vespids function Rule_Production_NorthWestBase_Patrol() local northWestBase_troopsProduced = false

-- If Hq still Exists (Patrols start before rest of base is activated)
if EGroup_Count("eg_northWestBase_HQ1") == 1
then
	-- Loop through all Patrol Squads
	for i =1,4	do
		-- If the SGroup is Not Currently Used...
		if northWestBase_troopsProduced == false and
			SGroup_Count("sg_northWestBase_patrol"..i) == 0
		then
			-- Try to Produce Patrol Vespid 
			if  Rule_Produce_Vespid(g_Player2, "sg_northWestBase_patrol"..i, "eg_northWestBase_HQ1", "mkr_northWestBase_HQ1") == true
			then
				northWestBase_troopsProduced = true
				sg_northWestBase_patrol_status[i] = g_squad_patrolling
				
				-- Order Troops to Patrol Point
				Cmd_AttackMoveMarker("sg_northWestBase_patrol"..i, "mkr_northWestBase_Patrol1")
			end
		end
	end
end

-- HQ is destroyed...Remove Rules since Base is dead
if EGroup_Count("eg_northWestBase_HQ1") == 0
then
	Rule_Remove(Rule_Production_NorthWestBase_Patrol)
end

end

-- Controls the Counter-Clockwise Patroling Vespid function Rule_PatrolOne_NorthWestBase() for i = 1,2 do -- If the Squad is Killed if SGroup_Exists("sg_northWestBase_patrol"..i) and SGroup_Count("sg_northWestBase_patrol"..i) == 0 then -- Unit is Dead, Do Nothing, since production is handled differently

	-- Check if the Squad arrived at the Patrol Location 1
	elseif SGroup_Exists("sg_northWestBase_patrol"..i) and
		Prox_AllSquadsNearMarker("sg_northWestBase_patrol"..i, "mkr_northWestBase_Patrol1")
	then
		-- Reinforce BackUp before continuing patrol
		if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_northWestBase_patrol"..i,1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_northWestBase_patrol"..i,1)) and
			SGroup_GetAvgLoadout("sg_northWestBase_patrol"..i) < 0.75
		then
			-- Reinforce
			Command_Squad(g_Player2, "sg_northWestBase_patrol"..i, SCMD_ReinforceTrooper)
		else
			-- Task to Next Patrol Point
			Cmd_AttackMoveMarker("sg_northWestBase_patrol"..i, "mkr_northWestBase_Patrol2")
		end
	
	-- Check if the Squad arrived at the Patrol Location 2
	elseif SGroup_Exists("sg_northWestBase_patrol"..i) and
		Prox_AllSquadsNearMarker("sg_northWestBase_patrol"..i, "mkr_northWestBase_Patrol2")
	then
		-- Reinforce BackUp before continuing patrol
		if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_northWestBase_patrol"..i,1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_northWestBase_patrol"..i,1)) and
			SGroup_GetAvgLoadout("sg_northWestBase_patrol"..i) < 0.75
		then
			-- Reinforce
			Command_Squad(g_Player2, "sg_northWestBase_patrol"..i, SCMD_ReinforceTrooper)
		else
			-- Task (JUMP) to Next Patrol Point
			Cmd_JumpToMarker("sg_northWestBase_patrol"..i, "mkr_northWestBase_Patrol3")
		end
	
	-- Check if the Squad arrived at the Patrol Location 3
	elseif SGroup_Exists("sg_northWestBase_patrol"..i) and
		Prox_AllSquadsNearMarker("sg_northWestBase_patrol"..i, "mkr_northWestBase_Patrol3")
	then
		-- Reinforce BackUp before continuing patrol
		if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_northWestBase_patrol"..i,1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_northWestBase_patrol"..i,1)) and
			SGroup_GetAvgLoadout("sg_northWestBase_patrol"..i) < 0.75
		then
			-- Reinforce
			Command_Squad(g_Player2, "sg_northWestBase_patrol"..i, SCMD_ReinforceTrooper)
		else
			-- Task to Next Patrol Point
			Cmd_AttackMoveMarker("sg_northWestBase_patrol"..i, "mkr_northWestBase_Patrol4")
		end
	
	-- Check if the Squad arrived at the Patrol Location 4
	elseif SGroup_Exists("sg_northWestBase_patrol"..i) and
		Prox_AllSquadsNearMarker("sg_northWestBase_patrol"..i, "mkr_northWestBase_Patrol4")
	then
		-- Reinforce BackUp before continuing patrol
		if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_northWestBase_patrol"..i,1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_northWestBase_patrol"..i,1)) and
			SGroup_GetAvgLoadout("sg_northWestBase_patrol"..i) < 0.75
		then
			-- Reinforce
			Command_Squad(g_Player2, "sg_northWestBase_patrol"..i, SCMD_ReinforceTrooper)
		else
			-- Task to Next Patrol Point
			Cmd_AttackMoveMarker("sg_northWestBase_patrol"..i, "mkr_northWestBase_Patrol5")
		end
	
	-- Check if the Squad arrived at the Patrol Location 5
	elseif SGroup_Exists("sg_northWestBase_patrol"..i) and
		Prox_AllSquadsNearMarker("sg_northWestBase_patrol"..i, "mkr_northWestBase_Patrol5")
	then
		-- Reinforce BackUp before continuing patrol
		if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_northWestBase_patrol"..i,1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_northWestBase_patrol"..i,1)) and
			SGroup_GetAvgLoadout("sg_northWestBase_patrol"..i) < 0.75
		then
			-- Reinforce
			Command_Squad(g_Player2, "sg_northWestBase_patrol"..i, SCMD_ReinforceTrooper)
		else
			-- Task to Next Patrol Point
			Cmd_AttackMoveMarker("sg_northWestBase_patrol"..i, "mkr_northWestBase_Patrol6")
		end			
	
	-- Check if the Squad arrived at the Patrol Location 6
	elseif SGroup_Exists("sg_northWestBase_patrol"..i) and
		Prox_AllSquadsNearMarker("sg_northWestBase_patrol"..i, "mkr_northWestBase_Patrol6")
	then
		-- Reinforce BackUp before continuing patrol
		if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_northWestBase_patrol"..i,1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_northWestBase_patrol"..i,1)) and
			SGroup_GetAvgLoadout("sg_northWestBase_patrol"..i) < 0.75
		then
			-- Reinforce
			Command_Squad(g_Player2, "sg_northWestBase_patrol"..i, SCMD_ReinforceTrooper)
		else
			-- Task (JUMP) to Next Patrol Point
			Cmd_JumpToMarker("sg_northWestBase_patrol"..i, "mkr_northWestBase_Patrol1")
		end			
	end
end

end

-- Controls the Clockwise Patroling Vespid function Rule_PatrolTwo_NorthWestBase() for i = 3,4 do -- If the Squad is Killed if SGroup_Exists("sg_northWestBase_patrol"..i) and SGroup_Count("sg_northWestBase_patrol"..i) == 0 then -- Unit is Dead, Do Nothing, since production is handled differently

	-- Check if the Squad arrived at the Patrol Location 1
	elseif SGroup_Exists("sg_northWestBase_patrol"..i) and
		Prox_AllSquadsNearMarker("sg_northWestBase_patrol"..i, "mkr_northWestBase_Patrol1")
	then
		-- Reinforce BackUp before continuing patrol
		if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_northWestBase_patrol"..i,1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_northWestBase_patrol"..i,1)) and
			SGroup_GetAvgLoadout("sg_northWestBase_patrol"..i) < 0.75
		then
			-- Reinforce
			Command_Squad(g_Player2, "sg_northWestBase_patrol"..i, SCMD_ReinforceTrooper)
		else
			-- Task (JUMP) to Next Patrol Point
			Cmd_JumpToMarker("sg_northWestBase_patrol"..i, "mkr_northWestBase_Patrol6")
		end
		
	-- Check if the Squad arrived at the Patrol Location 6
	elseif SGroup_Exists("sg_northWestBase_patrol"..i) and
		Prox_AllSquadsNearMarker("sg_northWestBase_patrol"..i, "mkr_northWestBase_Patrol6")
	then
		-- Reinforce BackUp before continuing patrol
		if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_northWestBase_patrol"..i,1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_northWestBase_patrol"..i,1)) and
			SGroup_GetAvgLoadout("sg_northWestBase_patrol"..i) < 0.75
		then
			-- Reinforce
			Command_Squad(g_Player2, "sg_northWestBase_patrol"..i, SCMD_ReinforceTrooper)
		else
			-- Task to Next Patrol Point
			Cmd_AttackMoveMarker("sg_northWestBase_patrol"..i, "mkr_northWestBase_Patrol5")
		end
		
	-- Check if the Squad arrived at the Patrol Location 5
	elseif SGroup_Exists("sg_northWestBase_patrol"..i) and
		Prox_AllSquadsNearMarker("sg_northWestBase_patrol"..i, "mkr_northWestBase_Patrol5")
	then
		-- Reinforce BackUp before continuing patrol
		if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_northWestBase_patrol"..i,1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_northWestBase_patrol"..i,1)) and
			SGroup_GetAvgLoadout("sg_northWestBase_patrol"..i) < 0.75
		then
			-- Reinforce
			Command_Squad(g_Player2, "sg_northWestBase_patrol"..i, SCMD_ReinforceTrooper)
		else
			-- Task to Next Patrol Point
			Cmd_AttackMoveMarker("sg_northWestBase_patrol"..i, "mkr_northWestBase_Patrol4")
		end
		
	-- Check if the Squad arrived at the Patrol Location 4
	elseif SGroup_Exists("sg_northWestBase_patrol"..i) and
		Prox_AllSquadsNearMarker("sg_northWestBase_patrol"..i, "mkr_northWestBase_Patrol4")
	then
		-- Reinforce BackUp before continuing patrol
		if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_northWestBase_patrol"..i,1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_northWestBase_patrol"..i,1)) and
			SGroup_GetAvgLoadout("sg_northWestBase_patrol"..i) < 0.75
		then
			-- Reinforce
			Command_Squad(g_Player2, "sg_northWestBase_patrol"..i, SCMD_ReinforceTrooper)
		else
			-- Task to Next Patrol Point
			Cmd_AttackMoveMarker("sg_northWestBase_patrol"..i, "mkr_northWestBase_Patrol3")
		end
	
	-- Check if the Squad arrived at the Patrol Location 3
	elseif SGroup_Exists("sg_northWestBase_patrol"..i) and
		Prox_AllSquadsNearMarker("sg_northWestBase_patrol"..i, "mkr_northWestBase_Patrol3")
	then
		-- Reinforce BackUp before continuing patrol
		if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_northWestBase_patrol"..i,1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_northWestBase_patrol"..i,1)) and
			SGroup_GetAvgLoadout("sg_northWestBase_patrol"..i) < 0.75
		then
			-- Reinforce
			Command_Squad(g_Player2, "sg_northWestBase_patrol"..i, SCMD_ReinforceTrooper)
		else
			-- Task (JUMP) to Next Patrol Point
			Cmd_JumpToMarker("sg_northWestBase_patrol"..i, "mkr_northWestBase_Patrol2")
		end
	
	-- Check if the Squad arrived at the Patrol Location 2
	elseif SGroup_Exists("sg_northWestBase_patrol"..i) and
		Prox_AllSquadsNearMarker("sg_northWestBase_patrol"..i, "mkr_northWestBase_Patrol2")
	then
		-- Reinforce BackUp before continuing patrol
		if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_northWestBase_patrol"..i,1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_northWestBase_patrol"..i,1)) and
			SGroup_GetAvgLoadout("sg_northWestBase_patrol"..i) < 0.75
		then
			-- Reinforce
			Command_Squad(g_Player2, "sg_northWestBase_patrol"..i, SCMD_ReinforceTrooper)
		else
			-- Task to Next Patrol Point
			Cmd_AttackMoveMarker("sg_northWestBase_patrol"..i, "mkr_northWestBase_Patrol1")
		end
	end
end

end


-- "RELIC BASE" RULES

-- Produce Crisis Suits, Stealth Suits, & Attacking Drone Harbringers function Rule_Production_RelicBase() --Loop through Barracks & if still exists... for j =1,2 do local relicBase_troopsProduced = false

	if g_base_activated_Relic == true and
		EGroup_Count("eg_relicBase_Barracks"..j) == 1
	then
		-- Loop through all the possible sg_relicBase_crisis squads
		for i =1,2	do
			-- If the SGroup is Not Currently Used...
			if relicBase_troopsProduced == false and
				SGroup_Count("sg_relicBase_crisis"..i) == 0
			then
				-- Try to Produce Crisis Suit
				if Rule_Produce_CrisisSuit(g_Player2, "sg_relicBase_crisis"..i, "eg_relicBase_Barracks"..j, "mkr_relicBase_Barracks"..j) == true
				then
					relicBase_troopsProduced = true
					sg_relicBase_crisis_status[i] = g_squad_produced
				end
			end
		end
	end
end

if g_base_activated_Relic == true and
	SGroup_Count("sg_relicBase_stealthSuit1") == 0
then
	-- Try to Produce a New Stealth Suit if HQ is Still Alive
	if Rule_Produce_StealthTeam(g_Player2, "sg_relicBase_stealthSuit1", "eg_relicBase_HQ1", "mkr_relicBase_HQ1") == true
	then
		sg_relicBase_stealthSuit_status[1] = g_squad_produced
	end
end

relicBase_troopsProduced = false

-- Vehicle Beacon
if g_base_activated_Relic == true and
	EGroup_Count("eg_relicBase_VehicleBuilding1") == 1
then
	-- Loop through all the possible sg_relicBase_vehicles
	for i =1,1	do
		-- If the SGroup is Not Currently Used...
		if relicBase_troopsProduced == false and
			SGroup_Count("sg_relicBase_vehicle"..i) == 0
		then
			-- Try to Produce Drone Harbinger
			if Rule_Produce_DroneHarbinger(g_Player2, "sg_relicBase_vehicle"..i, "eg_relicBase_VehicleBuilding1", "mkr_relicBase_VehicleBuilding1") == true
			then
				relicBase_troopsProduced = true
				sg_relicBase_vehicle_status[i] = g_squad_produced
			end
		end
	end
end

-- All Barracks, Vehicle Beacon & HQ are destroyed...Remove Rules since Base is dead
if EGroup_Count("eg_relicBase_Barracks1") == 0 and
	EGroup_Count("eg_relicBase_Barracks2") == 0 and
	EGroup_Count("eg_relicBase_VehicleBuilding1") == 0 and
	EGroup_Count("eg_relicBase_HQ1") == 0
then
	Rule_Remove(Rule_Production_RelicBase)
end

end

-- Produces the Crisis Suits to Jump in & Attack the LaserGun once the player captures it -- Called as a OneShot once the player captures the laser function Rule_RelicBase_LaserCapture() --Loop through Barracks & if still exists... for j =1,2 do local relicBase_troopsProduced = false

	if EGroup_Count("eg_relicBase_Barracks"..j) == 1
	then
		-- Loop through all the possible "sg_laserAttack_Crisis" squads
		for i =1,2	do
			-- If the SGroup is Not Currently Used...
			if relicBase_troopsProduced == false and
				SGroup_Count("sg_laserAttack_Crisis"..i) == 0
			then
				-- Try to Produce Crisis Suit
				if Rule_Produce_CrisisSuit(g_Player2, "sg_laserAttack_Crisis"..i, "eg_relicBase_Barracks"..j, "mkr_relicBase_Barracks"..j) == true
				then
					relicBase_troopsProduced = true
					
					-- Jump in to attack the gun:
					Cmd_JumpToMarker("sg_laserAttack_Crisis"..i, "mkr_Ai_Crisis_LaserJump"..i)
				end
			end
		end
	end
end

end


-- "SOUTH BASE" RULES

-- Produce Firewarrior, DroneHarbringer, & Skyray function Rule_Production_SouthBase() local southBase_troopsProduced = false

-- Produce Troops from Barracks if Free SGroup
for i =1,1	do
	-- If the SGroup is Not Currently Used...
	if g_base_activated_South == true and
		southBase_troopsProduced == false and
		SGroup_Count("sg_southBase_troops"..i) == 0
	then
		-- Try to Produce Firewarriors
		if Rule_Produce_Firewarrior(g_Player2, "sg_southBase_troops"..i, "eg_southBase_Barracks1", "mkr_southBase_Barracks1") == true
		then
			southBase_troopsProduced = true
			sg_southBase_troops_status[i] = g_squad_produced
		end
	end
end

-- Produce a Drone Harbinger if none exist
if g_base_activated_South_Vehicle and
	SGroup_Count("sg_southBase_vehicles1") == 0
then
	-- Try to Produce Drone Harbinger
	if Rule_Produce_DroneHarbinger(g_Player2, "sg_southBase_vehicles1", "eg_southBase_VehicleBuilding1", "mkr_southBase_VehicleBuilding1") == true
	then
		sg_southBase_vehicles_status[1] = g_squad_produced
	end

-- Produce a Skyray if none exist
elseif g_base_activated_South_Vehicle == true and
	SGroup_Count("sg_southBase_vehicles2") == 0
then
	-- Try to Produce Skyray
	if Rule_Produce_Skyray(g_Player2, "sg_southBase_vehicles2", "eg_southBase_VehicleBuilding1", "mkr_southBase_VehicleBuilding1") == true
	then
		sg_southBase_vehicles_status[2] = g_squad_produced
	end
end

-- Barracks & Vehicle Bay are destroyed...Remove Rules since Base is dead
if EGroup_Count("eg_southBase_Barracks1") == 0 and
	EGroup_Count("eg_southBase_VehicleBuilding1") == 0
then
	Rule_Remove(Rule_Production_SouthBase)
end

end


-- "WEST BASE" RULES

-- Produce Patroling Pathfinders & Attacking Firewarriors, Stealth Suits function Rule_Production_WestBase() --Loop through all Barracks & if still exists... for j =1,2 do local westBase_troopsProduced = false

	if EGroup_Count("eg_westBase_Barracks"..j) == 1
	then
		-- If base is activated, try to produce troop squads
		for i =1,1	do
			-- If the SGroup is Not Currently Used...
			if g_base_activated_West == true and
				westBase_troopsProduced == false and
				SGroup_Count("sg_westBase_troops"..i) == 0
			then
				-- Try to Produce Firewarriors
				if Rule_Produce_Firewarrior(g_Player2, "sg_westBase_troops"..i, "eg_westBase_Barracks"..j, "mkr_westBase_Barracks"..j) == true
				then
					westBase_troopsProduced = true
					sg_westBase_troops_status[i] = g_squad_produced
				end
			end
		end
	
		-- If didn't produce a troop squad -- check if need to replace a patrol squad
		for i =1,2	do
			-- If the SGroup is Not Currently Used...
			if westBase_troopsProduced == false and
				SGroup_Count("sg_westBase_patrol"..i) == 0
			then
				-- Try to Produce Pathfinders
				if Rule_Produce_Pathfinder(g_Player2, "sg_westBase_patrol"..i, "eg_westBase_Barracks"..j, "mkr_westBase_Barracks"..j) == true
				then
					westBase_troopsProduced = true
					sg_westBase_patrol_status[i] = g_squad_patrolling
					
					-- Order Patrol Squad to First Patrol Point
					Cmd_AttackMoveMarker("sg_westBase_patrol"..i, "mkr_westBase_Patrol1")
				end
			end
		end
	end
end

-- Try to Produce Stealth Suit from HQ if none on battle field
if g_base_activated_West == true and
	SGroup_Count("sg_westBase_stealthSuit1") == 0
then
	if Rule_Produce_StealthTeam(g_Player2, "sg_westBase_stealthSuit1", "eg_westBase_HQ1", "mkr_westBase_HQ1") == true
	then
		sg_westBase_stealthSuit_status[1] = g_squad_produced
	end
end

-- All Barracks & HQ are destroyed...Remove Rules since Base is dead
if EGroup_Count("eg_westBase_Barracks1") == 0 and
	EGroup_Count("eg_westBase_Barracks2") == 0 and
	EGroup_Count("eg_westBase_HQ1") == 0		
then
	Rule_Remove(Rule_Production_WestBase)
end

end

-- Controls the Clockwise Patroling Pathfinders function Rule_PatrolOne_WestBase() -- If the Squad is Killed if SGroup_Exists("sg_westBase_patrol1") and SGroup_Count("sg_westBase_patrol1") == 0 then -- Unit is Dead, Do Nothing, since production is handled differently

-- Check if the Squad arrived at the Patrol Location 1
elseif SGroup_Exists("sg_westBase_patrol1") and
	Prox_AllSquadsNearMarker("sg_westBase_patrol1", "mkr_westBase_Patrol1")
then
	-- Reinforce BackUp before continuing patrol
	if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_westBase_patrol1",1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_westBase_patrol1",1)) and
		SGroup_GetAvgLoadout("sg_westBase_patrol1") < 0.75
	then
		-- Reinforce
		Command_Squad(g_Player2, "sg_westBase_patrol1", SCMD_ReinforceTrooper)
	else
		-- Task to Next Patrol Point
		Cmd_AttackMoveMarker("sg_westBase_patrol1", "mkr_westBase_Patrol2")	
	end
	
-- Check if the Squad arrived at the Patrol Location 2
elseif SGroup_Exists("sg_westBase_patrol1") and
	Prox_AllSquadsNearMarker("sg_westBase_patrol1", "mkr_westBase_Patrol2")
then
	-- Reinforce BackUp before continuing patrol
	if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_westBase_patrol1",1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_westBase_patrol1",1)) and
		SGroup_GetAvgLoadout("sg_westBase_patrol1") < 0.75
	then
		-- Reinforce
		Command_Squad(g_Player2, "sg_westBase_patrol1", SCMD_ReinforceTrooper)
	else
		-- Task to Next Patrol Point
		Cmd_AttackMoveMarker("sg_westBase_patrol1", "mkr_westBase_Patrol3")	
	end

-- Check if the Squad arrived at the Patrol Location 3
elseif SGroup_Exists("sg_westBase_patrol1") and
	Prox_AllSquadsNearMarker("sg_westBase_patrol1", "mkr_westBase_Patrol3")
then
	-- Reinforce BackUp before continuing patrol
	if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_westBase_patrol1",1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_westBase_patrol1",1)) and
		SGroup_GetAvgLoadout("sg_westBase_patrol1") < 0.75
	then
		-- Reinforce
		Command_Squad(g_Player2, "sg_westBase_patrol1", SCMD_ReinforceTrooper)
	else
		-- Task to Next Patrol Point
		Cmd_AttackMoveMarker("sg_westBase_patrol1", "mkr_westBase_Patrol4")	
	end

-- Check if the Squad arrived at the Patrol Location 4
elseif SGroup_Exists("sg_westBase_patrol1") and
	Prox_AllSquadsNearMarker("sg_westBase_patrol1", "mkr_westBase_Patrol4")
then
	-- Reinforce BackUp before continuing patrol
	if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_westBase_patrol1",1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_westBase_patrol1",1)) and
		SGroup_GetAvgLoadout("sg_westBase_patrol1") < 0.75
	then
		-- Reinforce
		Command_Squad(g_Player2, "sg_westBase_patrol1", SCMD_ReinforceTrooper)
	else
		-- Task to Next Patrol Point
		Cmd_AttackMoveMarker("sg_westBase_patrol1", "mkr_westBase_Patrol1")	
	end	
end

end

-- Controls the Couter-Clockwise Patroling Pathfinders function Rule_PatrolTwo_WestBase() -- If the Squad is Killed if SGroup_Exists("sg_westBase_patrol2") and SGroup_Count("sg_westBase_patrol2") == 0 then -- Unit is Dead, Do Nothing, since production is handled differently

-- Check if the Squad arrived at the Patrol Location 4
elseif SGroup_Exists("sg_westBase_patrol2") and
	Prox_AllSquadsNearMarker("sg_westBase_patrol2", "mkr_westBase_Patrol4")
then
	-- Reinforce BackUp before continuing patrol
	if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_westBase_patrol2",1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_westBase_patrol2",1)) and
		SGroup_GetAvgLoadout("sg_westBase_patrol2") < 0.75
	then
		-- Reinforce
		Command_Squad(g_Player2, "sg_westBase_patrol2", SCMD_ReinforceTrooper)
	else
		-- Task to Next Patrol Point
		Cmd_AttackMoveMarker("sg_westBase_patrol2", "mkr_westBase_Patrol3")	
	end
	
-- Check if the Squad arrived at the Patrol Location 3
elseif SGroup_Exists("sg_westBase_patrol2") and
	Prox_AllSquadsNearMarker("sg_westBase_patrol2", "mkr_westBase_Patrol3")
then
	-- Reinforce BackUp before continuing patrol
	if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_westBase_patrol2",1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_westBase_patrol2",1)) and
		SGroup_GetAvgLoadout("sg_westBase_patrol2") < 0.75
	then
		-- Reinforce
		Command_Squad(g_Player2, "sg_westBase_patrol2", SCMD_ReinforceTrooper)
	else
		-- Task to Next Patrol Point
		Cmd_AttackMoveMarker("sg_westBase_patrol2", "mkr_westBase_Patrol2")	
	end

-- Check if the Squad arrived at the Patrol Location 2
elseif SGroup_Exists("sg_westBase_patrol2") and
	Prox_AllSquadsNearMarker("sg_westBase_patrol2", "mkr_westBase_Patrol2")
then
	-- Reinforce BackUp before continuing patrol
	if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_westBase_patrol2",1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_westBase_patrol2",1)) and
		SGroup_GetAvgLoadout("sg_westBase_patrol2") < 0.75
	then
		-- Reinforce
		Command_Squad(g_Player2, "sg_westBase_patrol2", SCMD_ReinforceTrooper)
	else
		-- Task to Next Patrol Point
		Cmd_AttackMoveMarker("sg_westBase_patrol2", "mkr_westBase_Patrol1")	
	end

-- Check if the Squad arrived at the Patrol Location 1
elseif SGroup_Exists("sg_westBase_patrol2") and
	Prox_AllSquadsNearMarker("sg_westBase_patrol2", "mkr_westBase_Patrol1")
then
	-- Reinforce BackUp before continuing patrol
	if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_westBase_patrol2",1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_westBase_patrol2",1)) and
		SGroup_GetAvgLoadout("sg_westBase_patrol2") < 0.75
	then
		-- Reinforce
		Command_Squad(g_Player2, "sg_westBase_patrol2", SCMD_ReinforceTrooper)
	else
		-- Task to Next Patrol Point
		Cmd_AttackMoveMarker("sg_westBase_patrol2", "mkr_westBase_Patrol4")	
	end	
end

end

-- END OF ALL "BASE" PRODUCTION RULES

-- Play IE & Setup for the Dispatching of Scouts to find Player Base function Rule_Begin_Scout_Dispatching() -- Play IE ordering the Dispatching of Scouts Util_StartIntel(EVENTS.IE_DispatchScouts)

-- So the Player can see the Scouts
--World_EnablePlayerToPlayerFOW(g_Player1, g_Player4, false)

-- Create the Sgroups used to control scoutSquads
for i =1,4 do
	SGroup_Create("sg_scoutSquad"..i)
	SGroup_SetPlayerOwner("sg_scoutSquad"..i, g_Player4)
end

-- Creates Pathfinder Scouts & Send them to find player base
Rule_AddInterval(Rule_Task_Scouts_Find_PlayerBase, g_spawnScoutTimer)

-- Check if the Scouts find the player base
Rule_AddInterval(Rule_Check_Scouts_Found_PlayerBase, 1)

end

-- Create a Group of Scouts (Pathfinders) & Send them to find player base function Rule_Task_Scouts_Find_PlayerBase() local scoutsProduced = false

-- Produce Scout squads of Pathfinders from West Base
for i =1,4	do
	-- If the SGroup is Not Currently Used...
	if scoutsProduced == false and
		SGroup_Count("sg_scoutSquad"..i) == 0
	then
		-- Try to Produce Pathfinders from West Base (actually is produced for g_Player2)
		if Rule_Produce_Pathfinder_Full(g_Player4, "sg_scoutSquad"..i, "eg_westBase_Barracks1", "mkr_westBase_Barracks1") == true
		then
			Cmd_AttackMoveMarker("sg_scoutSquad"..i, "mkr_Ai_Attack_PlayerWestSide")
			scoutsProduced = true
			
			-- Since Player Varible in Produce_Pathfinders doesn't work
			SGroup_SetPlayerOwner("sg_scoutSquad"..i, g_Player4)
			
			-- Subtract from counter until scouts report they have been unable to break player defenses
			g_SquadsUntilWarned	 = g_SquadsUntilWarned - 1
		end
	end
end

scoutsProduced = false

-- Produce Scout squads of Pathfinders from South Base
for i =1,4	do
	-- If the SGroup is Not Currently Used...
	if scoutsProduced == false and
		SGroup_Count("sg_scoutSquad"..i) == 0
	then
		-- Try to Produce Pathfinders from South Base (actually is produced for g_Player2)
		if Rule_Produce_Pathfinder_Full(g_Player4, "sg_scoutSquad"..i, "eg_southBase_Barracks1", "mkr_southBase_Barracks1") == true
		then
			Cmd_AttackMoveMarker("sg_scoutSquad"..i, "mkr_Ai_Attack_PlayerEastSide")
			scoutsProduced = true
			
			-- Since Player Varible in Produce_Pathfinders doesn't work
			SGroup_SetPlayerOwner("sg_scoutSquad"..i, g_Player4)
			
			-- Subtract from counter until scouts report they have been unable to break player defenses 
			g_SquadsUntilWarned	 = g_SquadsUntilWarned - 1				
		end
	end
end

end

-- Checks if any scouts have actually reached the player base function Rule_Check_Scouts_Found_PlayerBase( ) -- Warn them if the scouts found the player base (basically if a squad reaches it alive) if Player_AreSquadsNearMarker(g_Player4, "mkr_Ai_FoundPlayerBase") then -- Play Intel that Base was found Util_StartIntel(EVENTS.IE_ScoutsFoundPlayer)

	-- Launch major Tau Attack here
	Rule_AddOneShot(Rule_Launch_First_Major_Attack, 1)

	-- Base found:  no longer need to produce scouts or check if found
	Rule_Remove(Rule_Task_Scouts_Find_PlayerBase)
	Rule_Remove(Rule_Check_Scouts_Found_PlayerBase)

-- Warn Them based on the fact that they keep sending squads out and they are all getting killed... (tau forced to assume somethings up)
elseif g_SquadsUntilWarned <= 0
then
	-- Play Intel that Base was found
	Util_StartIntel(EVENTS.IE_ScoutsKilled)

	-- Launch major Tau Attack here
	Rule_AddOneShot(Rule_Launch_First_Major_Attack, 1)

	-- Base found:  no longer need to produce scouts or check if found
	Rule_Remove(Rule_Task_Scouts_Find_PlayerBase)
	Rule_Remove(Rule_Check_Scouts_Found_PlayerBase)
end

end

-- Checks for the Tau's Final Stand -- Call in Air Caste Attack when Coalition Center is Damaged function Rule_LastStand() -- If the Coalition Center is at less than 99% health if EGroup_Exists("eg_mainStronghold_EtherealBuilding_Objective") and EGroup_GetAvgHealth("eg_mainStronghold_EtherealBuilding_Objective") < 0.99 then -- Play IE: Util_StartIntel(EVENTS.IE_LastStand)

	-- Call in the Air Caste Attack
	Rule_AddInterval(Rule_LastStand_Attack, g_lastStand_time)
	
	-- Remove the Rule since Attack has been called in...
	Rule_Remove(Rule_LastStand)
end	

end

-- Control the Actual Air Caste Attacks of the Last Stand function Rule_LastStand_Attack() -- As long the Coalition Center Has Not Been Destroyed, Enemy is still in range (& Still have bullets) if EGroup_Exists("eg_mainStronghold_EtherealBuilding_Objective") and EGroup_Count("eg_mainStronghold_EtherealBuilding_Objective") == 1 and Player_AreSquadsNearMarker(g_Player1, "mkr_mainStronghold_PurposeShrine1") and g_lastStand_maxShots > 0 then -- Subtract One From Number of Shots left g_lastStand_maxShots = g_lastStand_maxShots -1

	-- Choose a target
	target = World_GetRand(1,g_number_lastStandTargets)
	
	-- Try to not fire at same target twice in a row
	if target ~= g_lastStand_lastTarget
	then
		-- Save Target
		g_lastStand_lastTarget = target
	else
		-- Try again to get a new target : if it comes up same again -- oh well : )
		g_lastStand_lastTarget = World_GetRand(1,g_number_lastStandTargets)
	end
	
	-- Ping the Target
	Ping_Marker("mkr_lastStand_"..g_lastStand_lastTarget, false, "default")
	
	-- & Fire the Air Caste Blast
	Command_EntityAbilityPos(g_Player2, EGroup_GetSpawnedEntityAt(EGroup_FromName("eg_mainStronghold_EtherealBuilding_Objective"), 1), "tau_death_pulse_sp_dxp3", 
		Marker_GetPosition(Marker_FromName("mkr_lastStand_"..g_lastStand_lastTarget, "basic_marker")))

-- Center Destroyed
elseif EGroup_Exists("eg_mainStronghold_EtherealBuilding_Objective") and 
	EGroup_Count("eg_mainStronghold_EtherealBuilding_Objective") == 0
then
	-- Remove the Rule, since either Coalition Center is Destroyed (Player Wins)
	Rule_Remove(Rule_LastStand_Attack)
end

end


-- LASER GUN RULES -- Rule_Hidden_Laser_Gun_Warm_Up() : Controls the Hidden Timer for the Laser Gun Warming Up to Fire -- Plays IE & Assigns secondary obj when ready to fire -- Rule_Laser_Gun_Warning() : Controls the On Screen Countdown Timer on the Laser Gun -- Rule_Aim_And_Fire_Laser_Gun( ) : Picks Random Player Unit & Fires at them

-- Controls the Hidden Timer for the Laser Gun Warming Up to Fire, and Plays IE when ready to fire function Rule_Hidden_Laser_Gun_Warm_Up( ) --counting down from g_laserGunCounterMax to 0 g_laserGunWarmupCounter = g_laserGunWarmupCounter-1

--once you hit 0 the laser gun will fire
if g_laserGunWarmupCounter == 0
then
	-- if Tau Still Owns the Gun, Play IE & Fire the Gun
	if g_PlayerOwnsLaserGun == false
	then
		-- Intel Event: First time the Tau Fire the Laser Cannon
		Util_StartIntel(EVENTS.IE_FirstLaserAttack)
		
		-- Pick you target and fire the laser (Time to end of IE)
		Rule_AddOneShot(Rule_Aim_And_Fire_Laser_Gun, 22)
	end
	
	-- Assign the Objective to Capture the Laser Gun
	Rule_AddIntervalDelay(Rule_ReCaptureLaserGun_Objective,2,30)
	
	-- Remove this rule
	Rule_Remove(Rule_Hidden_Laser_Gun_Warm_Up)
end

end

-- Controls the On Screen Countdown Timer on the Laser Gun function Rule_Laser_Gun_Warning( ) --counting down from g_laserGunCounterMax to 0 g_laserGunCounter = g_laserGunCounter -1

UI_ShowCountUpdateDxp("LaserGunUi", g_laserGunCounter, 3950228)

--once you hit 0 the laser gun will try and fire
if g_laserGunCounter == 0
then
	-- Play IE:
	Util_StartIntel(EVENTS.IE_OrbitalAttack_Announcement)
	
	-- Pick you target and fire the laser
	Rule_AddOneShot(Rule_Aim_And_Fire_Laser_Gun, 0.5)
	
	-- Remove this rule (will be readded next time ready to start laser countdown)
	Rule_Remove(Rule_Laser_Gun_Warning)
end

end

-- Choose a Random Player unit & fire the laser gun at it... function Rule_Aim_And_Fire_Laser_Gun( ) -- Find All the Player Units SGroup_Clear("sg_players_units") SGroup_AddGroup("sg_players_units", Player_GetSquads(g_Player1))

--if we got someone...
if SGroup_Count("sg_players_units") > 0
then
	-- Get Number of Active Player Squads (incase someone is garrisoned in building or something)
	numUnits = Player_GetActiveSquadCount(g_Player1)
	-- Get the Number we counted
	sCount = SGroup_Count("sg_players_units")
	
	--use the lowest
	if sCount < numUnits
	then
		numUnits = sCount
	end
	
	-- If Player Unit was found...
	if numUnits >= 1
	then
		-- Fire the laser Blast at location of random player unit (Ping & Fire)
		g_laserTarget_pos = Squad_GetPosition(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_players_units"), World_GetRand(1, numUnits)))
		Ping_Position(g_laserTarget_pos, false, "default")
		
		-- Fire the Gun after a Small Delay (so player has a chance to move the target unit out of the way)
		Rule_AddOneShot(Rule_Actual_Firing_Of_Laser_Gun,2)			
	else
		-- Fire the Laser Blast at the default target location since no player units found (Ping & Fire)
		g_laserTarget_pos = Marker_GetPosition(Marker_FromName("mkr_laserGun_default", "basic_marker"))
		Ping_Position(g_laserTarget_pos, false, "default")			
		
		-- Fire the Gun after a Small Delay (so player can see target)
		Rule_AddOneShot(Rule_Actual_Firing_Of_Laser_Gun,1)
	end

-- Fire the Laser Blast at the default target location since no player units found (Ping & Fire)
else
	g_laserTarget_pos = Marker_GetPosition(Marker_FromName("mkr_laserGun_default", "basic_marker"))
	Ping_Position(g_laserTarget_pos, false, "default")
	
	-- Fire the Gun after a Small Delay (so player can see target)
	Rule_AddOneShot(Rule_Actual_Firing_Of_Laser_Gun,1)
end

-- Restarts the timer and prepares for the next shot (Warning Delay is to give effect time to disolve out before starting recharge)
	-- Delay was changed to 1 due to Bug where both sides could own gun at same time
g_laserGunCounter = g_laserGunCounterMax
Rule_AddIntervalDelay(Rule_Laser_Gun_Warning, 1,1) -- 15)

-- Remove Rule so dont have multiple running (Since Warning will readd once it decides to fire again)
Rule_Remove(Rule_Aim_And_Fire_Laser_Gun)

end

-- Actually Fires the Laser Gun function Rule_Actual_Firing_Of_Laser_Gun() Command_EntityAbilityPos(g_Player2,EGroup_GetSpawnedEntityAt(EGroup_FromName("eg_laserGun_Weapon"), 1), "tau_lasergun_sp", g_laserTarget_pos) end

-- Checks if the player owns the laser function Rule_Check_Player_Control_Laser( ) -- Check if the player has captured the laser gun critical point if g_PlayerOwnsLaserGun == false and EGroup_IsCapturedByPlayer("eg_laserGun_critPoint", g_Player1, false) == true then -- So Game knows the player owns the Gun (will complete the objective also) g_PlayerOwnsLaserGun = true

	-- Play IE for Player has captured laserGun
	Util_StartIntel(EVENTS.IE_PlayerCapturedLaser_FirstTime)
	
	-- Enable the Ui Button
	Button_SetEnabled(g_laser_button_spawn, true)
	
	-- Checks if player if trying to fire the gun (and fires it)
	Rule_AddDelay(Rule_Laser_Button_Click,10)
	
	-- Set the Gun Building to be controlled by the player
	EGroup_SetPlayerOwner("eg_laserGun_Weapon", g_Player1)
	
	-- Add Rule to Check if the Tau takes the gun back (only adds if not already added)
	Rule_Check_AddInterval(Rule_Check_Ai_Control_Laser, 3)
	
	-- Hide the AI Fire Timer
	UI_HideCount("LaserGunUi")
	
	-- Remove the Rule Controlling When Ai Fires
	Rule_Remove(Rule_Laser_Gun_Warning)
	
	-- remove the rule since the player now owns gun
	Rule_Remove(Rule_Check_Player_Control_Laser)
end

end

-- Checks if Tau are able to recapture the laser gun back function Rule_Check_Ai_Control_Laser( ) -- Check if the player has captured the laser gun (but tau has taken back) if g_PlayerOwnsLaserGun == true and EGroup_IsCapturedByPlayer("eg_laserGun_critPoint", g_Player1, false) == false then -- Set So Player Doesn't own gun g_PlayerOwnsLaserGun = false

	-- Set the Gun Building to be controlled by the Tau Again
	EGroup_SetPlayerOwner("eg_laserGun_Weapon", g_Player2)
	
	-- Remove the Rule Check for player click and Ui Timer
	Rule_Remove(Rule_Laser_Button_Click)
	Rule_Remove(Rule_Laser_Gun_Warning_Player)
	UI_HideCount("LaserGunUi_Player")
	
	-- Disable the Firecontrol for the Laser
	Button_SetEnabled(g_laser_button_spawn, false)
	
	-- Readd the rule to check for objective complete
	Rule_Check_AddInterval(Rule_ReCaptureLaserGun_Objective, 2)
	
	-- Add Rule to Check if player has recaptured the Gun Back
	Rule_Check_AddInterval(Rule_Check_Player_Control_Laser, 3)		
end

-- If the Tau own the gun...
if EGroup_IsCapturedByPlayer("eg_laserGun_critPoint", g_Player2, false) == true
then
	-- Play IE for Tau has captured laserGun again
	Util_StartIntel(EVENTS.IE_TauCapturedLaser)
	
	-- Set Amount of time between laser guns shots
	g_laserGunCounter = g_laserGunCounterMax
	
	-- Re-Show the timer on the screen
	UI_ShowCountDXP("LaserGunUi", g_Player1, 2840000, g_laserGunCounter )
	
	-- Shows UI Countdown til laser fires, than will fire laser
	Rule_AddInterval(Rule_Laser_Gun_Warning, 1)
	
	-- remove the rule since the tau now owns gun
	Rule_Remove(Rule_Check_Ai_Control_Laser)
end

end

-- Creates the actual button on the laser that the player clicks to fire the laser function Rule_Laser_Button_Setup() t_laser_firing = { -- enabled icon, disabled icon, mouseover icon (need new icons) button_icon = {"tau_icons/lasergun_icon", "tau_icons/lasergun_icon", "tau_icons/lasergun_icon"}, -- title, description (need to localize) button_description = {"$3950241", "$3950242","$3950243", "$3950244"}, } g_laser_button_spawn = Util_AbilityButton_CreateModal(t_laser_firing.button_icon, t_laser_firing.button_description, true)

-- Make the button show up on the Building UI
Util_EGroupAbilityButton_Add2Manager(g_laser_button_spawn, "eg_laserGun_Weapon")

-- Disable the Firecontrol for the Laser
Button_SetEnabled(g_laser_button_spawn, false)

end

-- Rule that fires the laser when the player clicks the button and than clicks on screen function Rule_Laser_Button_Click() -- Player has clicked the UI Button on the laser building if Button_GetPressed(g_laser_button_spawn) == true then -- location of where player has clicked in the world local pos = Button_GetPressedPosition(g_laser_button_spawn)

	-- So can only fire into areas that you can see & not into Fog of War
	if Player_CanSeePosition(g_Player1, pos)
	then
		-- Play IE:
		Util_StartIntel(EVENTS.IE_OrbitalAttack_Announcement)
		
		-- Ping & Fire laser on the Position
		Ping_Position(pos, false, "default")
		Command_EntityAbilityPos(g_Player1, EGroup_GetSpawnedEntityAt(EGroup_FromName("eg_laserGun_Weapon"), 1), "tau_lasergun_sp", pos)
		
		-- disable the skill button while it "refreshes"
		Button_SetEnabled(g_laser_button_spawn, false)
		
		-- Reset the Timer For Player to Fire Laser Gun Again
		g_laserGunCounter_Player = g_laserGunCounterMax_Player
		UI_ShowCountDXP("LaserGunUi_Player", g_Player1, 3950228, g_laserGunCounter_Player )
		
		-- Rule that controls the actual onscreen countdown for the rule (Delay is for Laser Effect to fade out first)
			-- Delay was changed to 1 due to Bug where both sides could own gun at same time
		Rule_AddIntervalDelay(Rule_Laser_Gun_Warning_Player, 1, 1) --15)
	end
end

end

-- Controls the On screen timer until the laser is refreshed (so player knows when can fire again function Rule_Laser_Gun_Warning_Player() --counting down from g_laserGunCounterMax to 0 g_laserGunCounter_Player = g_laserGunCounter_Player -1

--2840000 is the localized string that appears on screen
UI_ShowCountUpdateDxp("LaserGunUi_Player", g_laserGunCounter_Player, 3950228)
	
--once you hit 0 the laser gun will be ready to fire again
if g_laserGunCounter_Player == 0
then
	-- reenable the skill button  on the laser so player can choose to fire again
	Button_SetEnabled(g_laser_button_spawn, true)
	
	-- Remove this rule (will be readded next time ready to start laser countdown)
	Rule_Remove(Rule_Laser_Gun_Warning_Player)
end

end


-- END OF ALL " LASER GUN " RULES


-- " BEACON & FLEET " RULES

-- Controls the On screen timer until the Tau Fleet Arrives function Rule_Beacon_Warning() --counting down from g_laserGunCounterMax to 0 g_beaconCounter = g_beaconCounter -1

-- Show the Fleet Timer on the screen (Show in Hr:Min:Sec)

-- UI_ShowCountUpdateDxp("BeaconUi", g_beaconCounter, 3950206) WinWarning_SetText( "BeaconUi", Loc_FormatText1( 3950206, Loc_FormatTime(60409, g_beaconCounter)))

-- Warn the Player the Fleet is Going to arrive Soon
if g_beaconCounter == g_fleetWarning
then
	-- PLay IE: Note this IE could occur Multiple times based on beacon destruction
	Util_StartIntel(EVENTS.IE_Fleet_Soon)
end
	
--once you hit 0 the laser gun will be ready to fire again
if g_beaconCounter == 0
then
	-- Fleet Needs to Arrive Here
	Rule_AddOneShot(Rule_Fleet_Arrival, 1)		
	
	-- Remove this rule
	Rule_Remove(Rule_Beacon_Warning)
end

end

-- Bring in the Fleet function Rule_Fleet_Arrival() Rule_Fleet_CheckDrop() end

function Rule_Fleet_CheckDrop() -- Call in Orca Ships Util_CreateSquadsAtMarkerEx(g_Player2, "sg_fleet_drop_1", "tau_orca_dropship_sp_dxp3", "mkr_mainStronghold_orcaSpawn1", 1, 1) Anim_PlaySGroupAnim(SGroup_FromName("sg_fleet_drop_1"), "sp_land")

Util_CreateSquadsAtMarkerEx(g_Player2, "sg_fleet_drop_2", "tau_orca_dropship_sp_dxp3", "mkr_mainStronghold_orcaSpawn2", 1, 1)
Anim_PlaySGroupAnim(SGroup_FromName("sg_fleet_drop_2"), "sp_land")

Rule_AddOneShot(Rule_Fleet_SpawnFleet, 10)
Rule_Remove(Rule_Fleet_CheckDrop)

end

function Rule_Fleet_SpawnFleet() -- PLay IE Util_StartIntel(EVENTS.IE_Fleet_Arrived) g_fleet_arrived = true

-- Produce some troops from the Orca
Rule_Produce_Hammerhead(g_Player2, "sg_fleet_hammerhead1", "eg_mainStronghold_EtherealBuilding_Objective", "mkr_mainStronghold_orcaSpawn1")
Rule_Produce_Hammerhead(g_Player2, "sg_fleet_hammerhead2", "eg_mainStronghold_EtherealBuilding_Objective", "mkr_mainStronghold_orcaSpawn1")
Rule_Produce_DroneHarbinger(g_Player2, "sg_fleet_droneHarbinger1", "eg_mainStronghold_EtherealBuilding_Objective", "mkr_mainStronghold_orcaSpawn1")
Rule_Produce_Firewarrior_Full(g_Player2, "sg_fleet_firewarrior1", "eg_mainStronghold_EtherealBuilding_Objective", "mkr_mainStronghold_orcaSpawn1")
Rule_Produce_Firewarrior_Full(g_Player2, "sg_fleet_firewarrior2", "eg_mainStronghold_EtherealBuilding_Objective", "mkr_mainStronghold_orcaSpawn1")

Rule_Produce_GreaterKnarloc(g_Player2, "sg_fleet_greaterKnarloc", "eg_mainStronghold_EtherealBuilding_Objective", "mkr_mainStronghold_orcaSpawn2")
Rule_Produce_Krootox(g_Player2, "sg_fleet_krootox1", "eg_mainStronghold_EtherealBuilding_Objective", "mkr_mainStronghold_orcaSpawn2")
Rule_Produce_Krootox(g_Player2, "sg_fleet_krootox2", "eg_mainStronghold_EtherealBuilding_Objective", "mkr_mainStronghold_orcaSpawn2")

-- Take Off
Anim_PlaySGroupAnim(SGroup_FromName("sg_fleet_drop_1"), "sp_take_off")
Anim_PlaySGroupAnim(SGroup_FromName("sg_fleet_drop_2"), "sp_take_off")
Rule_AddOneShot(Rule_Fleet_Despawn,10)

end

function Rule_Fleet_Despawn() SGroup_DeSpawn("sg_fleet_drop_1") SGroup_Destroy("sg_fleet_drop_1")

SGroup_DeSpawn("sg_fleet_drop_2")
SGroup_Destroy("sg_fleet_drop_2")

end


-- END OF ALL "BEACON & FLEET " RULES


-- " UNIT PRODUCTION " RULES -- Rule_Produce_XXX (squadName, buildingName, markerName) -- Produces (& Upgrades) XXX from Building at Marker for g_Player2 & Assign it to SGroup(squadName) if building exists -- Return True if XXX is Created, & False if the Building is Destroyed

-- Unit Types:
	-- Rule_Produce_Builder
	-- Rule_Produce_Firewarrior
		-- Rule_Produce_Firewarrior_Full
	-- Rule_Produce_Pathfinder
		-- Rule_Produce_Pathfinder_Full
	-- Rule_Produce_StealthTeam
	-- Rule_Produce_Vespid
	-- Rule_Produce_KrootCarnivore
	-- Rule_Produce_KrootHound
	-- Rule_Produce_KrootShaper
	-- Rule_Produce_Krootox
	-- Rule_Produce_GreaterKnarloc
	-- Rule_Produce_Broadside
	-- Rule_Produce_Barracuda
	-- Rule_Produce_DroneHarbinger
	-- Rule_Produce_Hammerhead
	-- Rule_Produce_Skyray
	-- Rule_Produce_CrisisSuit

-- Produce a Builder (Earth Caste) from Building at Marker for g_Player(playerNumber) and assign it to SGroup(squadName) function Rule_Produce_Builder(playerNunber, squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a builder Util_CreateSquadsAtMarker(g_Player2, squadName, "tau_builder_squad", markerName, 1)

	-- Builder was Created
	return true
end

-- Builder not created since building doesn't exist
return false

end

-- Produce (& Give Leaders) a Firewarrior Squad from Building at Marker for g_Player(playerNumber) and assign it to SGroup(squadName) function Rule_Produce_Firewarrior(playerNunber, squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- get size of firewarrior squad local loadout = World_GetRand(3,6)

	-- Create a squad of fire warriors
	Util_CreateSquadsAtMarkerEx(g_Player2, squadName, "tau_fire_warrior_squad", markerName, 1, loadout)
	
	-- Give squad the leader (Shas'ui -- Enables Grenades)
	if g_fireWarrior_leader == true
	then
		SGroup_AddLeaders(squadName)
	end
	
	-- Give Squad Shield Drone Here is Enabled
	if g_fireWarrior_shieldDrone == true
	then
		SGroup_AddLeadersAtIndex(squadName,2)
	end
	
	-- Firewarrior Squad was Created
	return true
end

-- Fire Warrior squad not created since building doesn't exist
return false

end

-- Produce (& Give Leaders) a Full Firewarrior Squad from Building at Marker for g_Player(playerNumber) and assign it to SGroup(squadName) function Rule_Produce_Firewarrior_Full(playerNunber, squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a squad of fire warriors Util_CreateSquadsAtMarkerEx(g_Player2, squadName, "tau_fire_warrior_squad", markerName, 1, 6)

	-- Give squad the leader (Shas'ui -- Enables Grenades)
	SGroup_AddLeaders(squadName)

	-- Give Squad Shield Drone Here is Enabled
	SGroup_AddLeadersAtIndex(squadName,2)
	
	-- Firewarrior Squad was Created
	return true
end

-- Fire Warrior squad not created since building doesn't exist
return false

end

-- Produce a Pathfinder Squad from Building at Marker for g_Player(playerNumber) and assign it to SGroup(squadName) function Rule_Produce_Pathfinder(playerNunber, squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- get size of pathfinder squad local loadout = World_GetRand(2,5)

	-- Create a squad of pathfinders
	Util_CreateSquadsAtMarkerEx(g_Player2, squadName, "tau_pathfinder_squad", markerName, 1, loadout)
	
	-- Path Finder Squad was Created
	return true
end

-- Path Finder squad not created since building doesn't exist
return false

end

-- Produce a Full Pathfinder Squad from Building at Marker for g_Player(playerNumber) and assign it to SGroup(squadName) function Rule_Produce_Pathfinder_Full(playerNunber, squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a full squad of pathfinders Util_CreateSquadsAtMarkerEx(g_Player2, squadName, "tau_pathfinder_squad", markerName, 1, 5)

	-- Path Finder Squad was Created
	return true
end

-- Path Finder squad not created since building doesn't exist
return false

end

-- Produce a Stealth Team Squad from Building at Marker for g_Player(playerNumber) and assign it to SGroup(squadName) function Rule_Produce_StealthTeam(playerNunber, squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- get size of stealth team local loadout = World_GetRand(1,3)

	-- Create Stealth Team
	Util_CreateSquadsAtMarkerEx(g_Player2, squadName, "tau_stealth_team_squad", markerName, 1, loadout)
	
	-- Give squad the leader (Shas'vre -- Enables Emp Grenades)
	if g_stealthTeam_leader == true
	then
		SGroup_AddLeaders(squadName)
	end
	
	-- Give squad Fusion Blasters (Anti-Vehicle) if enabled
	if g_stealthTeam_fusionBlaster == true
	then
		Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName(squadName), 1),"tau_fusion_blaster_stealth_suit", loadout)
	end
	
	-- Stealth Team was Created
	return true
end

-- Stealth Team not created since building doesn't exist
return false

end

-- Produce a Vespid Squad from Building at Marker for g_Player(playerNumber) and assign it to SGroup(squadName) function Rule_Produce_Vespid(playerNunber, squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- get size of Vespid squad local loadout = World_GetRand(3,5)

	-- Create Vespid (Special Vespid with Infinate Jump Range for Scar) & give leader
	Util_CreateSquadsAtMarkerEx(g_Player2, squadName, "tau_vespid_auxiliary_squad_sp_dxp3", markerName, 1, loadout)
	SGroup_AddLeaders(squadName)
	
	-- Vespid was Created
	return true
end

-- Vespid not created since building doesn't exist
return false

end

-- Produce a Kroot Carnivore Squad from Building at Marker for g_Player(playerNumber) and assign it to SGroup(squadName) function Rule_Produce_KrootCarnivore(playerNunber, squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- get size of Kroot Carnivore squad local loadout = World_GetRand(4,10)

	-- Create a squad of Kroot Carnivore
	Util_CreateSquadsAtMarkerEx(g_Player2, squadName, "tau_kroot_carnivore_squad", markerName, 1, loadout)
	
	-- KrootCarnivore Squad was Created
	return true
end

-- Kroot Carnivore squad not created since building doesn't exist
return false

end

-- Produce a Kroot Houd Squad from Building at Marker for g_Player(playerNumber) and assign it to SGroup(squadName) function Rule_Produce_KrootHound(playerNunber, squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- get size of Kroot Hound squad local loadout = World_GetRand(4,8)

	-- Create a squad of Kroot Hound
	Util_CreateSquadsAtMarkerEx(g_Player2, squadName, "tau_kroot_hound_squad", markerName, 1, loadout)
	
	-- Kroot Hounds were Created
	return true
end

-- Kroot Hounds not created since building doesn't exist
return false

end

-- Produce a Kroot Shaper from Building at Marker for g_Player(playerNumber) and assign it to SGroup(squadName) function Rule_Produce_KrootShaper(playerNunber, squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a Kroot Shaper Util_CreateSquadsAtMarker(g_Player2, squadName, "tau_kroot_shaper_squad", markerName, 1)

	-- Kroot Shaper was Created
	return true
end

-- Kroot Shaper not created since building doesn't exist
return false

end

-- Produce a Krootox from Building at Marker for g_Player(playerNumber) and assign it to SGroup(squadName) function Rule_Produce_Krootox(playerNunber, squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a Krootox Util_CreateSquadsAtMarker(g_Player2, squadName, "tau_krootox_squad", markerName, 1)

	-- Krootox was Created
	return true
end

-- Krootox not created since building doesn't exist
return false

end

-- Produce a GreaterKnarloc from Building at Marker for g_Player(playerNumber) and assign it to SGroup(squadName) function Rule_Produce_GreaterKnarloc(playerNunber, squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a GreaterKnarloc Util_CreateSquadsAtMarker(g_Player2, squadName, "tau_greater_knarloc_squad", markerName, 1)

	-- GreaterKnarloc was Created
	return true
end

-- GreaterKnarloc not created since building doesn't exist
return false

end

-- Produce a Broadside from Building at Marker for g_Player(playerNumber) and assign it to SGroup(squadName) function Rule_Produce_Broadside(playerNunber, squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a Broadside Util_CreateSquadsAtMarker(g_Player2, squadName, "tau_broadside_battlesuit_squad", markerName, 1)

	-- Broadside was created
	return true
end

-- Broadside not created since building doesn't exist
return false

end

-- Produce a Barracuda from Building at Marker for g_Player(playerNumber) and assign it to SGroup(squadName) function Rule_Produce_Barracuda(playerNunber, squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a Barracuda Util_CreateSquadsAtMarker(g_Player2, squadName, "tau_barracuda_squad", markerName, 1)

	-- Barracuda was created
	return true
end

-- Barracuda not created since building doesn't exist
return false

end

-- Produce a Drone Harbinger from Building at Marker for g_Player(playerNumber) and assign it to SGroup(squadName) function Rule_Produce_DroneHarbinger(playerNunber, squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a Drone Harbinger Util_CreateSquadsAtMarker(g_Player2, squadName, "tau_drone_harbinger_squad", markerName, 1)

	-- Drone Harbinger was created
	return true
end

-- Drone Harbinger not created since building doesn't exist
return false

end

-- Produce a Hammerhead from Building at Marker for g_Player(playerNumber) and assign it to SGroup(squadName) function Rule_Produce_Hammerhead(playerNunber, squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a Hammerhead Util_CreateSquadsAtMarker(g_Player2, squadName, "tau_hammerhead_gunship_squad", markerName, 1)

	-- Hammerhead was created
	return true
end

-- Hammerhead not created since building doesn't exist
return false

end

-- Produce a Skyray from Building at Marker for g_Player(playerNumber) and assign it to SGroup(squadName) function Rule_Produce_Skyray(playerNunber, squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a Skyray Util_CreateSquadsAtMarker(g_Player2, squadName, "tau_skyray_squad", markerName, 1)

	-- Skyray was created
	return true
end

-- Skyray not created since building doesn't exist
return false

end

-- Produce a CrisisSuit from Building at Marker for g_Player(playerNumber) and assign it to SGroup(squadName) function Rule_Produce_CrisisSuit(playerNunber, squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a CrisisSuit Util_CreateSquadsAtMarker(g_Player2, squadName, "tau_crisis_suit_squad_sp_dxp3", markerName, 1)

	-- Randomly Pick Weapon Upgrade Type: Missile Pod Or Flamer
	if World_GetRand(0,1) == 0
	then
		Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName(squadName), 1),"tau_missile_pod_crisis_suit", 1)
	else
		Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName(squadName), 1),"tau_flamer_crisis_suit", 1)
	end		
	-- CrisisSuit was created
	return true
end

-- CrisisSuit not created since building doesn't exist
return false

end


-- END OF ALL " UNIT PRODUCTION " RULES


-- RANDOM MOVEMENT RULES -- Rule_Create_Wandering_Troops() : Creates all the troops that wander around the bases to create feeling of life (& to provide small defense forces) -- Rule_RandomMovement_Base() : Causes a few units in each base to wander around it -- giving it the feeling of some life -- Rule_RandomMovement_Support(squadName, markerName) : Makes sure the squad Exists & has units, before telling the squad to randomly move to a location inside marker -- Rule_RandomMovement_Support_Builder(squadName, markerName) :Causes Units to Move (Instead of Attack Move) to random location inside marker

-- Creates all the troops that wander around the bases to create feeling of life (& to provide small defense forces) function Rule_Create_Wandering_Troops() -- DEFENSE BASE: Create Builders & Firewarriors Rule_Produce_Builder(g_Player2, "sg_defenseBase_wanderBuilder1", "eg_defenseBase_HQ1", "mkr_defenseBase_HQ1") Rule_Produce_Builder(g_Player2, "sg_defenseBase_wanderBuilder2", "eg_defenseBase_HQ1", "mkr_defenseBase_HQ1") Rule_Produce_Builder(g_Player2, "sg_defenseBase_wanderBuilder3", "eg_defenseBase_HQ1", "mkr_defenseBase_HQ1")

for i = 1, g_strongholdStrengthTier do
	Rule_Produce_Firewarrior(g_Player2, "sg_defenseBase_wanderFire"..i, "eg_defenseBase_HQ1", "mkr_defenseBase_HQ1")
	Rule_Produce_Pathfinder(g_Player2, "sg_defenseBase_wanderPath"..i, "eg_defenseBase_HQ1", "mkr_defenseBase_HQ1")
end	

--EASTBASE: Create Hammerhead, Pathfinder, Barracuda & Builders
Rule_Produce_Hammerhead(g_Player2, "sg_eastBase_wander1", "eg_commTower_2", "mkr_commTower_2")
Rule_Produce_Pathfinder(g_Player2, "sg_eastBase_wander2", "eg_commTower_2", "mkr_commTower_2")
Rule_Produce_Builder(g_Player2, "sg_eastBase_wander3", "eg_commTower_2", "mkr_commTower_2")
Rule_Produce_Builder(g_Player2, "sg_eastBase_wander4", "eg_commTower_2", "mkr_commTower_2")
Rule_Produce_Barracuda(g_Player2, "sg_eastBase_wander5", "eg_commTower_2", "mkr_commTower_2")
Rule_Produce_Barracuda(g_Player2, "sg_eastBase_wander6", "eg_commTower_2", "mkr_commTower_2")
Rule_Produce_CrisisSuit(g_Player2, "sg_eastBase_wander7", "eg_commTower_2", "mkr_commTower_2")
Rule_Produce_CrisisSuit(g_Player2, "sg_eastBase_wander8", "eg_commTower_2", "mkr_commTower_2")

-- KROOTCENTERBASE: Create the Kroot Hound & Shaper squad
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_krootCenterBase_wander1", "tau_kroot_hound_squad", "mkr_krootCenterBase_KauyonShrine1", 1, 4)
Util_CreateSquadsAtMarker(g_Player2, "sg_krootCenterBase_shaper", "tau_kroot_shaper_squad", "mkr_krootCenterBase_KauyonShrine1", 1)
Cmd_AttachSquads("sg_krootCenterBase_wander1", "sg_krootCenterBase_shaper")

-- KROOTCENTERBASE: Create squads of kroot carnivores
for i=1,2 do
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_krootCenterBase_wander"..i, "tau_kroot_carnivore_squad", "mkr_krootCenterBase_troops_"..i, 1, 6)
end

-- LASERGUNBASE: Create Builders & Pathfinders
Rule_Produce_Builder(g_Player2, "sg_laserGunBase_wander1", "eg_laserGunBase_Barracks2", "mkr_laserGunBase_Barracks2")
Rule_Produce_Builder(g_Player2, "sg_laserGunBase_wander2", "eg_laserGunBase_Barracks2", "mkr_laserGunBase_Barracks2")
Rule_Produce_Pathfinder_Full(g_Player2, "sg_laserGunBase_wander3", "eg_laserGunBase_Barracks2", "mkr_laserGunBase_Barracks2")
Rule_Produce_Pathfinder_Full(g_Player2, "sg_laserGunBase_wander4", "eg_laserGunBase_Barracks2", "mkr_laserGunBase_Barracks2")

-- MAINBASE: Create Builders, Pathfinders, Firewarriors, Barracudas, & Crisis Suits
Rule_Produce_Builder(g_Player2, "sg_mainBase_wander1", "eg_mainStronghold_HQ1", "mkr_mainStronghold_HQ1")
Rule_Produce_Builder(g_Player2, "sg_mainGunBase_wander2", "eg_mainStronghold_HQ1", "mkr_mainStronghold_HQ1")
Rule_Produce_Builder(g_Player2, "sg_mainBase_wander3", "eg_mainStronghold_HQ1", "mkr_mainStronghold_HQ1")
Rule_Produce_Pathfinder_Full(g_Player2, "sg_mainBase_wander4", "eg_mainStronghold_HQ1", "mkr_mainStronghold_HQ1")
Rule_Produce_Pathfinder_Full(g_Player2, "sg_mainBase_wander5", "eg_mainStronghold_HQ1", "mkr_mainStronghold_HQ1")
Rule_Produce_Firewarrior_Full(g_Player2, "sg_mainBase_wander6", "eg_mainStronghold_HQ1", "mkr_mainStronghold_HQ1")
Rule_Produce_Firewarrior_Full(g_Player2, "sg_mainBase_wander7", "eg_mainStronghold_HQ1", "mkr_mainStronghold_HQ1")
Rule_Produce_Barracuda(g_Player2, "sg_mainBase_wander8", "eg_mainStronghold_HQ1", "mkr_mainStronghold_HQ1")
Rule_Produce_Barracuda(g_Player2, "sg_mainBase_wander9", "eg_mainStronghold_HQ1", "mkr_mainStronghold_HQ1")
Rule_Produce_CrisisSuit(g_Player2, "sg_mainBase_wander10", "eg_mainStronghold_HQ1", "mkr_mainStronghold_HQ1")
Rule_Produce_CrisisSuit(g_Player2, "sg_mainBase_wander11", "eg_mainStronghold_HQ1", "mkr_mainStronghold_HQ1")

-- NORTHEAST BASE: Greater Knarloc & Hound w/ Shaper
Rule_Produce_GreaterKnarloc(g_Player2, "sg_northEastBase_wander1", "eg_northEastBase_KauyonShrine1", "mkr_northEastBase_KauyonShrine1")
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_northEastBase_wander2", "tau_kroot_hound_squad", "mkr_northEastBase_KauyonShrine1", 1, 4)
Util_CreateSquadsAtMarker(g_Player2, "sg_northEastBase_shaper", "tau_kroot_shaper_squad", "mkr_northEastBase_KauyonShrine1", 1)
Cmd_AttachSquads("sg_northEastBase_wander2", "sg_northEastBase_shaper")

-- NORTHWEST BASE: Greater Knarloc & Hound w/ Shaper
Rule_Produce_GreaterKnarloc(g_Player2, "sg_northWestBase_wander1", "eg_northWestBase_KauyonShrine1", "mkr_northWestBase_KauyonShrine1")
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_northWestBase_wander2", "tau_kroot_hound_squad", "mkr_northWestBase_KauyonShrine1", 1, 4)
Util_CreateSquadsAtMarker(g_Player2, "sg_northWestBase_shaper", "tau_kroot_shaper_squad", "mkr_northWestBase_KauyonShrine1", 1)
Cmd_AttachSquads("sg_northWestBase_wander2", "sg_northWestBase_shaper")

-- RELICBASE: Hammerheads, Pathfinders, Barracudas, Builders
Rule_Produce_Hammerhead(g_Player2, "sg_relicBase_wander1", "eg_relicBase_HQ1", "mkr_relicBase_HQ1")
Rule_Produce_Hammerhead(g_Player2, "sg_relicBase_wander2", "eg_relicBase_HQ1", "mkr_relicBase_HQ1")
Rule_Produce_Pathfinder_Full(g_Player2, "sg_relicBase_wander3", "eg_relicBase_HQ1", "mkr_relicBase_HQ1") 
Rule_Produce_Builder(g_Player2, "sg_relicBase_wander4", "eg_relicBase_HQ1", "mkr_relicBase_HQ1")
Rule_Produce_Builder(g_Player2, "sg_relicBase_wander5", "eg_relicBase_HQ1", "mkr_relicBase_HQ1")
Rule_Produce_Barracuda(g_Player2, "sg_relicBase_wander6", "eg_relicBase_HQ1", "mkr_relicBase_HQ1")
Rule_Produce_Barracuda(g_Player2, "sg_relicBase_wander7", "eg_relicBase_HQ1", "mkr_relicBase_HQ1")

-- SOUTHBASE: Create Barracuda, Pathfinders & Firewarriors
Rule_Produce_Pathfinder_Full(g_Player2, "sg_southBase_wander1", "eg_commTower_1", "mkr_commTower_1") 
Rule_Produce_Firewarrior_Full(g_Player2, "sg_southBase_wander2", "eg_commTower_1", "mkr_commTower_1")
Rule_Produce_Firewarrior_Full(g_Player2, "sg_southBase_wander3", "eg_commTower_1", "mkr_commTower_1")
Rule_Produce_Builder(g_Player2, "sg_southBase_wander4", "eg_commTower_1", "mkr_commTower_1")
Rule_Produce_Builder(g_Player2, "sg_southBase_wander5", "eg_commTower_1", "mkr_commTower_1")
Rule_Produce_Barracuda(g_Player2, "sg_southBase_wander6", "eg_commTower_1", "mkr_commTower_1")
Rule_Produce_Barracuda(g_Player2, "sg_southBase_wander7", "eg_commTower_1", "mkr_commTower_1")

-- WESTBASE: Create Builders, Pathfinders, & Barracuda
Rule_Produce_Pathfinder_Full(g_Player2, "sg_westBase_wander1", "eg_westBase_HQ1", "mkr_westBase_HQ1") 
Rule_Produce_Builder(g_Player2, "sg_westBase_wander2", "eg_westBase_HQ1", "mkr_westBase_HQ1")
Rule_Produce_Builder(g_Player2, "sg_westBase_wander3", "eg_westBase_HQ1", "mkr_westBase_HQ1")
Rule_Produce_Barracuda(g_Player2, "sg_westBase_wander4", "eg_westBase_HQ1", "mkr_westBase_HQ1") 

end

-- Causes a few units in each base to wander around it -- giving it the feeling of some life function Rule_RandomMovement_Base() -- DEFENSE BASE: Create Builders, Firewarriors, & PathFinders Rule_RandomMovement_Support_Builder(g_Player2, "sg_defenseBase_wanderBuilder1", "mkr_Ai_FoundPlayerBase") Rule_RandomMovement_Support_Builder(g_Player2, "sg_defenseBase_wanderBuilder2", "mkr_Ai_FoundPlayerBase") Rule_RandomMovement_Support_Builder(g_Player2, "sg_defenseBase_wanderBuilder3", "mkr_Ai_FoundPlayerBase")

for i = 1, g_strongholdStrengthTier do
	Rule_RandomMovement_Support("sg_defenseBase_wanderFire"..i, "mkr_Ai_FoundPlayerBase")
	Rule_RandomMovement_Support("sg_defenseBase_wanderPath"..i, "mkr_Ai_FoundPlayerBase")
end

-- EAST BASE: Hammerhead, Pathfinders, Barracuda, Crisis Suits & Builders
Rule_RandomMovement_Support("sg_eastBase_wander1", "mkr_eastBase_wandering")
Rule_RandomMovement_Support("sg_eastBase_wander2", "mkr_eastBase_wandering")
Rule_RandomMovement_Support_Builder(g_Player2, "sg_eastBase_wander3", "mkr_eastBase_builder_wander")
Rule_RandomMovement_Support_Builder(g_Player2, "sg_eastBase_wander4", "mkr_eastBase_builder_wander")
Rule_RandomMovement_Support("sg_eastBase_wander5", "mkr_eastBase_wandering")
Rule_RandomMovement_Support("sg_eastBase_wander6", "mkr_eastBase_wandering")
Rule_RandomMovement_Support("sg_eastBase_wander7", "mkr_eastBase_wandering")
Rule_RandomMovement_Support("sg_eastBase_wander8", "mkr_eastBase_wandering")

-- KROOTCENTER BASE: Hounds, Carnivores & Snapers
Rule_RandomMovement_Support("sg_krootCenterBase_wander1", "mkr_krootCenterBase_wandering")
Rule_RandomMovement_Support("sg_krootCenterBase_wander2", "mkr_krootCenterBase_wandering")
Rule_RandomMovement_Support("sg_krootCenterBase_wander3", "mkr_krootCenterBase_wandering")

-- LASERGUN BASE:  Builders & Pathfinders
Rule_RandomMovement_Support_Builder(g_Player2, "sg_laserGunBase_wander1", "mkr_laserGunBase_builder_wander")
Rule_RandomMovement_Support_Builder(g_Player2, "sg_laserGunBase_wander2", "mkr_laserGunBase_builder_wander")
Rule_RandomMovement_Support("sg_laserGunBase_wander3", "mkr_laserGunBase_builder_wander")
Rule_RandomMovement_Support("sg_laserGunBase_wander4", "mkr_laserGunBase_builder_wander")

-- MAIN BASE: Builders, Pathfinders, Barracudas, Crisis Suits & Firewarriors
Rule_RandomMovement_Support_Builder(g_Player2, "sg_mainBase_wander1", "mkr_mainStronghold_HQ1")
Rule_RandomMovement_Support_Builder(g_Player2, "sg_mainBase_wander2", "mkr_mainStronghold_HQ1")
Rule_RandomMovement_Support_Builder(g_Player2, "sg_mainBase_wander3", "mkr_mainStronghold_HQ1")
Rule_RandomMovement_Support_Builder(g_Player2, "sg_mainBase_wander4", "mkr_mainStronghold_HQ1")
Rule_RandomMovement_Support("sg_mainBase_wander5", "mkr_mainStronghold_HQ1")
Rule_RandomMovement_Support("sg_mainBase_wander6", "mkr_mainStronghold_HQ1")
Rule_RandomMovement_Support("sg_mainBase_wander7", "mkr_mainStronghold_HQ1")
Rule_RandomMovement_Support("sg_mainBase_wander8", "mkr_mainStronghold_HQ1")
Rule_RandomMovement_Support("sg_mainBase_wander9", "mkr_mainStronghold_HQ1")
Rule_RandomMovement_Support("sg_mainBase_wander10", "mkr_mainStronghold_HQ1")
Rule_RandomMovement_Support("sg_mainBase_wander11", "mkr_mainStronghold_HQ1")

-- NORTHEAST BASE: Greater Knarloc & Hounds w/ Shaper
Rule_RandomMovement_Support("sg_northEastBase_wander1", "mkr_northEastBase_wandering")
Rule_RandomMovement_Support("sg_northEastBase_wander2", "mkr_northEastBase_wandering")

-- NORTHWEST BASE: Greater Knarloc & Hounds w/ Shaper
Rule_RandomMovement_Support("sg_northWestBase_wander1", "mkr_northWestBase_wandering")
Rule_RandomMovement_Support("sg_northWestBase_wander2", "mkr_northWestBase_wandering")

-- RELIC BASE: Hammerhead, Pathfinders, Barracudas & Builders
Rule_RandomMovement_Support("sg_relicBase_wander1", "mkr_relic_wandering")
Rule_RandomMovement_Support("sg_relicBase_wander2", "mkr_relic_wandering")	
Rule_RandomMovement_Support("sg_relicBase_wander3", "mkr_relicBase_wandering")
Rule_RandomMovement_Support_Builder(g_Player2, "sg_relicBase_wander4", "mkr_relicBase_wandering")
Rule_RandomMovement_Support_Builder(g_Player2, "sg_relicBase_wander5", "mkr_relicBase_wandering")
Rule_RandomMovement_Support("sg_relicBase_wander6", "mkr_relicBase_wandering")
Rule_RandomMovement_Support("sg_relicBase_wander7", "mkr_relicBase_wandering")

-- SOUTH BASE: Troops (Pathfinders, Firewarriors & Barracuda) & Builder
Rule_RandomMovement_Support("sg_southBase_wander1", "mkr_southBase_wandering")
Rule_RandomMovement_Support("sg_southBase_wander2", "mkr_southBase_wandering")
Rule_RandomMovement_Support("sg_southBase_wander3", "mkr_southBase_wandering")
Rule_RandomMovement_Support_Builder(g_Player2, "sg_southBase_wander4", "mkr_southBase_builder_wander")
Rule_RandomMovement_Support_Builder(g_Player2, "sg_southBase_wander5", "mkr_southBase_builder_wander")
Rule_RandomMovement_Support("sg_southBase_wander6", "mkr_southBase_wandering")
Rule_RandomMovement_Support("sg_southBase_wander7", "mkr_southBase_wandering")

--WEST BASE: Troops (Pathfinders, Barracudas) & Builder
Rule_RandomMovement_Support("sg_westBase_wander1", "mkr_westBase_wandering")
Rule_RandomMovement_Support_Builder(g_Player2, "sg_westBase_wander2", "mkr_westBase_builder_wander")
Rule_RandomMovement_Support_Builder(g_Player2, "sg_westBase_wander3", "mkr_westBase_builder_wander")
Rule_RandomMovement_Support("sg_westBase_wander4", "mkr_westBase_wandering")

end

-- Makes sure the squad Exists & has units, before telling the squad to randomly move to a location inside marker function Rule_RandomMovement_Support(squadName, markerName ) if SGroup_Exists(squadName) and SGroup_Count(squadName) > 0 then Util_AttackMoveMarkerRandomRadius(squadName, markerName) end end

-- Causes Units to Move (Instead of Attack Move) to random location inside marker function Rule_RandomMovement_Support_Builder(playerName, squadName, markerName ) if SGroup_Exists(squadName) and SGroup_Count(squadName) > 0 then local pos = Marker_GetPosition( Marker_FromName( markerName, "basic_marker" ) ) local prox = Marker_GetProximity( Marker_FromName( markerName, "basic_marker" ) )

	local xrand = World_GetRand( -prox, prox ) 
	local zrand = World_GetRand( -prox, prox ) 

	local movePos = World_Pos( xrand + pos.x, pos.y, zrand + pos.z )

	Command_SquadPos(g_Player2, squadName, SCMD_Move, movePos)
end

end

-- END OF ALL " RANDOM MOVEMENT " RULES

-- Create the Player Base after the initial line of defenses have been breached function Rule_BuildMoonBase() -- Intel Event: FirstBase_Destroyed (Race Based) : Player Destroys the first small base -- Here is your HQ & Builders Util_StartIntel(g_ie_FirstBase_Destroyed_Array[g_intelEvent_raceId])

-- Un-Restrict the Player From Building Bases
if g_HQ_blueprint ~= 0 then
	Player_UnRestrictBuilding( g_Player1, g_HQ_blueprint )
end
if g_bonus_generator ~= 0 then
	Player_UnRestrictBuilding( g_Player1, g_bonus_generator )
end
if g_bonus_turret ~= 0 then
	Player_UnRestrictBuilding( g_Player1, g_bonus_turret )
end
if g_bonus_barracks ~= 0 then
	Player_UnRestrictBuilding( g_Player1, g_bonus_barracks )
end
if g_bonus_barracks2 ~= 0 then
	Player_UnRestrictBuilding( g_Player1, g_bonus_barracks2 )
end
if g_bonus_research ~= 0 then
	Player_UnRestrictBuilding( g_Player1, g_bonus_research )
end

-- Create Player Builders (3)
Util_CreateSquadsAtMarker(g_Player1 , "sg_player_mainBase_builder", g_Builder_blueprint, "mkr_player_mainBase_builder", 3)

-- Create the EGroups for the player buildings
EGroup_Create("eg_player_mainBase_HQ1")

-- Varible to track failures of building attempts
g_attempt_build_hq = 0

-- Try to bring in the HQ (also controls the building auto-complete delay)
Rule_AddInterval(Rule_Build_Player_HQ,2)

-- Handle the Forward Base Special Ability
ForwardBases()

-- Add extra resources to players current amounts
if g_raceName == "necron_race"
then
	-- If Necron, Only Give Power
	Player_AddResource(g_Player1, RT_Power, g_amountPowerToGiveNecron)
else
	-- Otherwise give both
	Player_AddResource(g_Player1, RT_Requisition, g_amountRequisitionToGivePlayer)
	Player_AddResource(g_Player1, RT_Power, g_amountPowerToGivePlayer)
end

-- Dispatch Scouts to find the Player Base
Rule_AddOneShot(Rule_Begin_Scout_Dispatching, g_scoutDispatchDelay)

end

-- Create the actual player base buildings -- this should actually work first try with Force Build Code, function was just left over function Rule_Build_Player_HQ() -- If you succeed last time in creating the building (or have tried and failed multiple times, then remove the rule if EGroup_Count("eg_player_mainBase_HQ1") == 1 or g_attempt_build_hq == 5 then -- Order the builders to walk towards the HQ since should be built now Cmd_MoveToMarker("sg_player_mainBase_builder", "mkr_player_mainBase_HQ1") Rule_Remove(Rule_Build_Player_HQ)

	-- Complete the HQ & Forward Base Building
	Rule_AddOneShot(Rule_Complete_Player_Buildings,5)

-- Try and Create the Building 
else
	User_CreateBuilding(g_Player1,"eg_player_mainBase_HQ1", g_HQ_blueprint,"mkr_player_mainBase_HQ1", 0)
	g_attempt_build_hq = g_attempt_build_hq + 1
end

end

-- Forward Base Special Ability that the Sisters start with function ForwardBases() --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
		User_CreateBuilding(g_Player1, "eg_Bonus"..j, t_blueprintEntitybonus[j], "MM_Reinforcement"..g_bonus_gen_counter, 0)

		--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
		User_CreateBuilding(g_Player1, "eg_Bonus"..j, t_blueprintEntitybonus[j], "MM_Reinforcement"..g_bonus_turret_counter, 0)

		--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
		User_CreateBuilding(g_Player1, "eg_Bonus"..j, t_blueprintEntitybonus[j], "MM_Reinforcement10", 0)

	elseif t_blueprintEntitybonus[j] == g_bonus_research
	then
		User_CreateBuilding(g_Player1, "eg_Bonus"..j, t_blueprintEntitybonus[j], "MM_Reinforcement11", 0)
	
	elseif t_blueprintEntitybonus[j] == g_bonus_barracks2
	then
		User_CreateBuilding(g_Player1, "eg_Bonus"..j, t_blueprintEntitybonus[j], "MM_Reinforcement13", 0)
	end
end

end

-- Code to Always Builds the building (prevents crashes & makes sure the buildings spawned) function User_CreateBuilding(p_PlayerID, p_EGroupID, p_Blueprint, p_MarkerName, complete) -- This will force the building to spawn at a position (Ignores Units in the way) -- This could have been placed where User_CreateBuilding() was but this new tech function was added later since old Silvey Methods Didn't work well with percentage buildings Entity_CreateBuildingPositionForce(p_PlayerID, p_EGroupID, p_Blueprint, Marker_GetPosition(Marker_FromName(p_MarkerName, "basic_marker" )), complete)

-- l_EntityID = Entity_Create(p_Blueprint, p_PlayerID, Marker_GetPosition(Marker_FromName(p_MarkerName, "basic_marker" ))) -- EGroup_Add(EGroup_CreateIfNotFound(p_EGroupID), l_EntityID) -- Entity_Spawn(l_EntityID)

-- I added this part so it can build at a percentage of 0
	-- Honestly Could just move the complete varible to the SetProgress...

-- if complete == 0 -- then -- Entity_SetBuildingProgress( l_EntityID, 0 ) -- end end

-- Complete the Forward bases & HQ after they are dropped in... function Rule_Complete_Player_Buildings() -- Reset the Forward Base Code: -- generator markers start at 0 g_bonus_gen_counter = 0 -- turrer markers start at 6 g_bonus_turret_counter = 6

-- Player HQ:
EGroup_SetConstructionComplete("eg_player_mainBase_HQ1")

-- Forward Bases:
for j=1,table.getn(t_blueprintEntitybonus) do
	if t_blueprintEntitybonus[j] == g_bonus_generator
	then
		EGroup_SetConstructionComplete("eg_Bonus"..j)
	
		--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
		EGroup_SetConstructionComplete("eg_Bonus"..j)
	
		--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
		EGroup_SetConstructionComplete("eg_Bonus"..j)
	
	elseif t_blueprintEntitybonus[j] == g_bonus_research
	then
		EGroup_SetConstructionComplete("eg_Bonus"..j)
	
	elseif t_blueprintEntitybonus[j] == g_bonus_barracks2
	then
		EGroup_SetConstructionComplete("eg_Bonus"..j)
	end
end

end


-- VICTORY / DEFEAT RULES -- Rule_EndGame_Victory() : Wins the Mission and Plays Final NIS -- Added in Rule_KillTauEtherealInStronghold_Objective( ) when the ethereal is killed -- Rule_EndGame_Defeat() : Checks if mission has been lost (Player Killed) -- Added in Rule_GameStart( ) or Rule_Stop_DropPod_Troops( ) -- Rule_GameOver() : Sets Game Over

-- Wins the Mission and Plays Final NIS : Added in Rule_KillTauEtherealInStronghold_Objective( ) when the ethereal is killed function Rule_EndGame_Victory() -- Kills all rules (Basically cleans up any extra rules that were running and prepares for scenario complete) Rule_RemoveAll()

-- NIS: Play the mission complete scripted scene
WXP_OpeningNISPreset( )
Util_StartNIS(EVENTS.NIS_Closing)	

Rule_AddInterval(Rule_GameOver, 1)

end

-- Rule for Losing the Game : Rule Checks Every 10 secs & is Added in Rule_GameStart( ) function Rule_EndGame_Defeat() -- define the "enemy" who will win when the player 'loses' g_enemy = g_Player2

--Lose because of Player Annihilation (Make sure IE is not playing when check is made)	
if Event_IsAnyRunning() == false and
	Player_HasBuildingsExcept(g_Player1, t_building_exceptions) == false and
	Player_HasSquadsExcept(g_Player1, t_unit_exceptions) == false
then
	Rule_RemoveAll()
	Fade_Start(4, false)
	World_SetTeamWin( g_enemy, "" )
	Rule_AddInterval(Rule_GameOver,1 )
	Rule_Remove( Rule_EndGame_Defeat )
end

end

-- Actually sets the Game Over & is added from Rule_EndGame_Victory( ) or Rule_EndGame_Defeat( ) function Rule_GameOver() if Event_IsAnyRunning() == false then World_SetGameOver() end end


-- END OF ALL " VICTORY / DEFEAT " RULES

Статистика игры
Подписчики
24
Времена
69
Игроки
5
Последние темы
Опубликовано 2 years ago
1 ответ
Модераторы