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

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

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 -- NOT FILLED IN BY RELIC?

function OnGameSetup() -- Global varibles

-- Used to Track if the player is loading a save game
g_restoring = false	

-- 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 Race based intel event to use
g_intelEvent_raceId = 0

-- Place to store the player Faction (Example: "Blood Ravens")
-- So I dont have to keep calling the functions to get them
g_factionName = "default_factionName"

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

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

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

-- Place to stores the Type of Barracks Like Building used based on each players race (Example: "chaos_sacrificial_circle")
g_Barracks_blueprint = " "

-- Place to stores the Type of Upgrade Like Building used based on each players race (Example: "chaos_armoury")
g_Upgrade_blueprint = " " 

-- Place to stores the Type of Power Plant used based on each players race (Example: "chaos_plasma_generator")
g_Power_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	

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

-- how many player units required to attack a base at once to activate it / cloak it
g_num_PlayerUnits_ActivateBase	=	2

-- Unit Types
g_unit_Banshee			= 1
g_unit_DarkReaper		= 2
g_unit_FireDragon		= 3
g_unit_Guardian			= 4
g_unit_Rangers			= 5

-- Used to check if a Base is already cloaked
g_base_cloaked_Center	=	false
g_base_cloaked_Main		=	false
g_base_cloaked_North	=	false
g_base_cloaked_South	=	false

-- Used to check if a Base is Already Active
g_base_activated_Center 					=	false
g_base_activated_Center_Vyper 		=	false
g_base_activated_Main						=	false
g_base_activated_North						=	false
g_base_activated_North_NightWing	=	false
g_base_activated_South					=	false
g_base_activated_West						=	false
g_webway_supportPortal_activated	=	false

-- Stores the Current Alert Status (Tech Level)
g_currentAlertStatus = -1

-- So Avatar only attacks the player base the first time
g_firstAvatar_attack = true

-- Number of Each Type of Webway Squad to use
	-- Ramps up to 2 when center base is killed
g_webway_numSquads	=	1

-- Maximum Number of Total Squads to Produce from Webway in a cycle
g_webway_numSquads_perCycle = 2

-- Tracks if a webway gate has gone active (& and thus can produce troops)
g_webway_activated		=	{false, false, false, false, false, false, false, false, false, false,
												false, false, false, false, false, false, false, false, false, false}

-- Type of Unit each webway will produce
g_webway_unit				=	{ g_unit_FireDragon, g_unit_Banshee, g_unit_Guardian, g_unit_Guardian, g_unit_DarkReaper,
												g_unit_Guardian, g_unit_Banshee, g_unit_DarkReaper, g_unit_Guardian, g_unit_DarkReaper,
												g_unit_FireDragon, g_unit_Banshee, g_unit_DarkReaper, g_unit_DarkReaper, g_unit_FireDragon,
												g_unit_Banshee, g_unit_Banshee, g_unit_FireDragon, g_unit_FireDragon, g_unit_FireDragon}

-- 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_idle						=	10

-- Squad Skills
g_skill_firedragon								=	1
g_skill_guardians								=	2
g_skill_banshees									=	3
g_skill_farseer										=	4
g_skill_harlequin									=	5
g_skill_wraithLord								=	6
g_skill_builder										=	7
g_skill_southBase_warpspider_jump	=	8
g_skill_centerBase_vehicle_jump		=	9
g_skill_darkreaper								=	10

-- Can Squad Capture?
g_canCaptureStrat	=	false
g_canCaptureRelic	=	true
g_canCaptureCrit	=	false	-- there are none on map

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

-- Pre Center Base Destroyed:
g_centerBase_darkreaper_status			=	{0}
g_centerBase_guardian_status				=	{0}
g_northBase_darkreaper_status			=	{0,0}	-- Currently set to only 1 squad for balance
g_southBase_guardian_status				=	{0}
g_southBase_warpspider_status			=	{0}

g_centerBase_vyper_status					=	{0}
g_northBase_nightwing_status				=	{0,0}
g_northBase_falconGravTank_status		=	{0,0}

-- Post Center Base Destroyed:
g_mainBase_avatar_status					=	{0}
g_mainBase_fireDragon_status				=	{0}
g_mainBase_banshee_status					=	{0}
g_mainBase_darkreapers_status			=	{0}
g_mainBase_firePrism_status					=	{0,0}
g_mainBase_wraithLord_status				=	{0,0}

g_westBase_banshee_status					=	{0}
g_westBase_wraithLord_status				=	{0}

-- Webway Gates: Based on Alert Levels & Center Base Destroyed
g_webway_banshees_status					=	{0,0}
g_webway_darkreaper_status				=	{0,0}
g_webway_firedragon_status				=	{0,0}
g_webway_guardian_status					=	{0,0}
g_webway_ranger_status						=	{0,0}
g_webway_supportPortalTank_status	=	{0}

-- So Game knows when all the Eldar HQs are destroyed (Mission Complete)
g_AllEldarHQDestroyed 						= false

-- Track when the Elite Nightwing squad is destroyed
g_EliteAirSquad_Destroyed					=	false

-- For Objective Tracking of North / South Production
g_northBase_FirstNightwing_Produced	=	false
g_southBase_FirstTroops_Produced		=	false

------------------------------------------BALANCE VARIBLES----------------------------------
	
	--------------------- Starting Resources ----------------------------------------
	
	-- Amount of Initial Resource to give each of the AI Players
		-- Does Nothing For this Scenario
	g_amountRequisitionToGiveAI = 10000
	g_amountPowerToGiveAI = 5000
	
	-- Amount of Extra Resources to Give Player (Non Necron Races)
	g_amountRequisitionToGivePlayer = 1500
	g_amountPowerToGivePlayer = 500
	
	-- Amount of Extra Power Resource to Give to Necron Player
	g_amountPowerToGiveNecron = 1500
	
	--------------------- Ai Troop Production ---------------------------------------
	-- Time a base takes to produce units once it goes active
		-- Speed Up the productions since this way someone is in the base when attacked
		-- Should not affect the attack waves
	g_timer_centerBase			=	270
	g_timer_mainBase				=	360
	g_timer_northBase				=	270
	g_timer_southBase				=	270
	g_timer_westBase				=	240
	g_timer_webway					=	240
	g_timer_initialWebway		=	60
	
	-- Time From Center Base TP Until Upgrade to Alert One (10 minutes)
	g_time_until_alertOne			=	597
	-- Time From Center Base TP Until Upgrade to Alert Two (20 minutes)
	g_time_until_alertTwo			=	1197
	-- Time From Center Base TP Until Upgrade to Alert Three (35 minutes)
	g_time_until_alertThree		=	2057
	
	--What Percentage of the Squad do troops reinforce up to...
	g_reinforce_percent	=	0.60
	
	-- Number of Elite Nightwings in the squad
	g_number_EliteNightwings	=	7
	
---------------------------------------------END BALANCE VARIBLES------------------------------

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

--	Initial (Race Based) :  Attack the small Eldar base to our south
g_ie_Initial_Array = {
							EVENTS.IE_Initial_Chaos,
							EVENTS.IE_Initial_DarkEldar,
							EVENTS.IE_Initial_Eldar, -- should not be possible to get
							EVENTS.IE_Initial_Guard,
							EVENTS.IE_Initial_Necron,
							EVENTS.IE_Initial_Ork,
							EVENTS.IE_Initial_Sisters,
							EVENTS.IE_Initial_Space,
							EVENTS.IE_Initial_Tau}

--	GivePlayerBase (Race Based) :  Players HQ & Builders have arrived
g_ie_GivePlayerBase_Array = {
							EVENTS.IE_GivePlayerBase_Chaos,
							EVENTS.IE_GivePlayerBase_DarkEldar,
							EVENTS.IE_GivePlayerBase_Eldar, -- should not be possible to get
							EVENTS.IE_GivePlayerBase_Guard,
							EVENTS.IE_GivePlayerBase_Necron,
							EVENTS.IE_GivePlayerBase_Ork,
							EVENTS.IE_GivePlayerBase_Sisters,
							EVENTS.IE_GivePlayerBase_Space,
							EVENTS.IE_GivePlayerBase_Tau}

--	PostTeleport_CenterBase (Race Based) :  Center base has finished teleporting to the new location
g_ie_PostTeleport_CenterBase_Array = {
							EVENTS.IE_PostTeleport_CenterBase_Chaos,
							EVENTS.IE_PostTeleport_CenterBase_DarkEldar,
							EVENTS.IE_PostTeleport_CenterBase_Eldar, -- should not be possible to get
							EVENTS.IE_PostTeleport_CenterBase_Guard,
							EVENTS.IE_PostTeleport_CenterBase_Necron,
							EVENTS.IE_PostTeleport_CenterBase_Ork,
							EVENTS.IE_PostTeleport_CenterBase_Sisters,
							EVENTS.IE_PostTeleport_CenterBase_Space,
							EVENTS.IE_PostTeleport_CenterBase_Tau}								

--	Reveal_MainBase (Race Based) :  Center base has been destroyed -- Reveal the Main Base
g_ie_Reveal_MainBase_Array = {
							EVENTS.IE_Reveal_MainBase_Chaos,
							EVENTS.IE_Reveal_MainBase_DarkEldar,
							EVENTS.IE_Reveal_MainBase_Eldar, -- should not be possible to get
							EVENTS.IE_Reveal_MainBase_Guard,
							EVENTS.IE_Reveal_MainBase_Necron,
							EVENTS.IE_Reveal_MainBase_Ork,
							EVENTS.IE_Reveal_MainBase_Sisters,
							EVENTS.IE_Reveal_MainBase_Space,
							EVENTS.IE_Reveal_MainBase_Tau}		

--	Detect_Energy_Sources (Race Based) :  Detect Locations of the Generators
g_ie_Detect_Energy_Sources_Array = {
							EVENTS.IE_Detect_Energy_Sources_Chaos,
							EVENTS.IE_Detect_Energy_Sources_DarkEldar,
							EVENTS.IE_Detect_Energy_Sources_Eldar, -- should not be possible to get
							EVENTS.IE_Detect_Energy_Sources_Guard,
							EVENTS.IE_Detect_Energy_Sources_Necron,
							EVENTS.IE_Detect_Energy_Sources_Ork,
							EVENTS.IE_Detect_Energy_Sources_Sisters,
							EVENTS.IE_Detect_Energy_Sources_Space,
							EVENTS.IE_Detect_Energy_Sources_Tau}

--	Turrents_Found (Race Based) :  Found the Super Turrets
g_ie_Turrents_Found_Array = {
							EVENTS.IE_Turrents_Found_Chaos,
							EVENTS.IE_Turrents_Found_DarkEldar,
							EVENTS.IE_Turrents_Found_Eldar, -- should not be possible to get
							EVENTS.IE_Turrents_Found_Guard,
							EVENTS.IE_Turrents_Found_Necron,
							EVENTS.IE_Turrents_Found_Ork,
							EVENTS.IE_Turrents_Found_Sisters,
							EVENTS.IE_Turrents_Found_Space,
							EVENTS.IE_Turrents_Found_Tau}		

--	Taunt_One-Four : Four Taunts by Eldar Farseer that occur during level 
g_ie_Taunt_Array = {
							EVENTS.IE_Taunt_One,
							EVENTS.IE_Taunt_Two,
							EVENTS.IE_Taunt_Three,
							EVENTS.IE_Taunt_Four}		

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

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

-- Eldar AI Players: $3950217 = "Craftwolrd Ulthwe"
g_Player2 = Setup_Player (1, "$3950217", "eldar_race", 1)
g_Player3 = Setup_Player (2, "$3950217", "eldar_race", 1)
g_Player4 = Setup_Player (3, "$3950217", "eldar_race", 1)
g_Player5 = Setup_Player (4, "$3950217", "eldar_race", 1)

-- Set Eldar Color Scheme
Misc_PlayerTeamColor(g_Player2, "default_5")
Misc_PlayerTeamColor(g_Player3, "default_5")
Misc_PlayerTeamColor(g_Player4, "default_5")
Misc_PlayerTeamColor(g_Player5, "default_5")

end

-- Used to redefine some varibles after loading a save game -- Restores IE Arrays function OnGameRestore() -- So game knows to run Rule_RestoreSupport() since the player has reloaded a save game g_restoring = true

---------------------------------------------RACE BASED INTEL EVENT ARRAYS---------------------
--	Initial (Race Based) :  Attack the small Eldar base to our south
g_ie_Initial_Array = {
							EVENTS.IE_Initial_Chaos,
							EVENTS.IE_Initial_DarkEldar,
							EVENTS.IE_Initial_Eldar, -- should not be possible to get
							EVENTS.IE_Initial_Guard,
							EVENTS.IE_Initial_Necron,
							EVENTS.IE_Initial_Ork,
							EVENTS.IE_Initial_Sisters,
							EVENTS.IE_Initial_Space,
							EVENTS.IE_Initial_Tau}

--	GivePlayerBase (Race Based) :  Players HQ & Builders have arrived
g_ie_GivePlayerBase_Array = {
							EVENTS.IE_GivePlayerBase_Chaos,
							EVENTS.IE_GivePlayerBase_DarkEldar,
							EVENTS.IE_GivePlayerBase_Eldar, -- should not be possible to get
							EVENTS.IE_GivePlayerBase_Guard,
							EVENTS.IE_GivePlayerBase_Necron,
							EVENTS.IE_GivePlayerBase_Ork,
							EVENTS.IE_GivePlayerBase_Sisters,
							EVENTS.IE_GivePlayerBase_Space,
							EVENTS.IE_GivePlayerBase_Tau}

--	PostTeleport_CenterBase (Race Based) :  Center base has finished teleporting to the new location
g_ie_PostTeleport_CenterBase_Array = {
							EVENTS.IE_PostTeleport_CenterBase_Chaos,
							EVENTS.IE_PostTeleport_CenterBase_DarkEldar,
							EVENTS.IE_PostTeleport_CenterBase_Eldar, -- should not be possible to get
							EVENTS.IE_PostTeleport_CenterBase_Guard,
							EVENTS.IE_PostTeleport_CenterBase_Necron,
							EVENTS.IE_PostTeleport_CenterBase_Ork,
							EVENTS.IE_PostTeleport_CenterBase_Sisters,
							EVENTS.IE_PostTeleport_CenterBase_Space,
							EVENTS.IE_PostTeleport_CenterBase_Tau}								

--	Reveal_MainBase (Race Based) :  Center base has been destroyed -- Reveal the Main Base
g_ie_Reveal_MainBase_Array = {
							EVENTS.IE_Reveal_MainBase_Chaos,
							EVENTS.IE_Reveal_MainBase_DarkEldar,
							EVENTS.IE_Reveal_MainBase_Eldar, -- should not be possible to get
							EVENTS.IE_Reveal_MainBase_Guard,
							EVENTS.IE_Reveal_MainBase_Necron,
							EVENTS.IE_Reveal_MainBase_Ork,
							EVENTS.IE_Reveal_MainBase_Sisters,
							EVENTS.IE_Reveal_MainBase_Space,
							EVENTS.IE_Reveal_MainBase_Tau}		

--	Detect_Energy_Sources (Race Based) :  Detect Locations of the Generators
g_ie_Detect_Energy_Sources_Array = {
							EVENTS.IE_Detect_Energy_Sources_Chaos,
							EVENTS.IE_Detect_Energy_Sources_DarkEldar,
							EVENTS.IE_Detect_Energy_Sources_Eldar, -- should not be possible to get
							EVENTS.IE_Detect_Energy_Sources_Guard,
							EVENTS.IE_Detect_Energy_Sources_Necron,
							EVENTS.IE_Detect_Energy_Sources_Ork,
							EVENTS.IE_Detect_Energy_Sources_Sisters,
							EVENTS.IE_Detect_Energy_Sources_Space,
							EVENTS.IE_Detect_Energy_Sources_Tau}

--	Turrents_Found (Race Based) :  Found the Super Turrets
g_ie_Turrents_Found_Array = {
							EVENTS.IE_Turrents_Found_Chaos,
							EVENTS.IE_Turrents_Found_DarkEldar,
							EVENTS.IE_Turrents_Found_Eldar, -- should not be possible to get
							EVENTS.IE_Turrents_Found_Guard,
							EVENTS.IE_Turrents_Found_Necron,
							EVENTS.IE_Turrents_Found_Ork,
							EVENTS.IE_Turrents_Found_Sisters,
							EVENTS.IE_Turrents_Found_Space,
							EVENTS.IE_Turrents_Found_Tau}		

--	Taunt_One-Four : Four Taunts by Eldar Farseer that occur during level 
g_ie_Taunt_Array = {
							EVENTS.IE_Taunt_One,
							EVENTS.IE_Taunt_Two,
							EVENTS.IE_Taunt_Three,
							EVENTS.IE_Taunt_Four}		

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

end

-- Restore some stuff in case a player saves & loads a game function Rule_RestoreSupport() if g_restoring == true then -- Reveal the Fog of War around the Center, East, & West Bases so the building appear on minimap again if g_currentAlertStatus >= 0 then FOW_RevealMarker("mkr_northBase_underAttack", 1) FOW_RevealMarker("mkr_centerBase_underAttack", 1) FOW_RevealMarker("mkr_southBase_underAttack", 1) end end

g_restoring = false	

end


-- END OF " GAME SETUP & RESTORE " RULES


-- INITALIZATION -- OnInit() : Mandatory Function that sets up the mission -- Called after OnGameSetup() : Not Sure if possible for something to come between the two of them -- Used for pregame functions, things that should happen before the player officially enters the world --Despawn Reserve Units, Set Groups and Start commands for persistent behaviors. -- 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 Ai Controlled Buildings on the Map
Rule_Create_All_Ai_Initial_Buildings( )

-- Sets up & Plays the Opening NIS:
WXP_OpeningNISPreset( )
Util_StartNIS( EVENTS.NIS_Opening )

-- Rule_GameStart : Function used to Start the Actual Mission
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 : Called from OnInit() -- Rule_SetDifficultyLevel( difficultyLevel ) : Used to set up AI difficulty levels : Called from OnInit() -- Rule_Stronghold_Difficulty_Strength_Stuff() : Used to Set up stuff based on the difficulty level of the stronghold (10-17) : Called from OnInit() -- Rule_PresetAI() : Used to Disable AI Players (Done Before Initial NIS) : Called from OnInit( )

-- Used to Setup the music & ambient soundtracks : Called from OnInit() function Rule_SetupMusicPlaylist() -- MUSIC TRACKS

-- clear the music playlist
Sound_PlaylistClear( PC_Music )
-- Add tracks to the playlist	
Sound_PlaylistAddTrack( PC_Music, "MU_IG_STR_eldar_perc_str" )
Sound_PlaylistAddTrack( PC_Music, "MU_IG_STR_eldar" )
Sound_PlaylistAddTrack( PC_Music, "MU_IG_STR_eldar_perc" )
Sound_PlaylistAddTrack( PC_Music, "MU_IG_STR_eldar_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/21/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) 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) : Called from OnInit() -- Rule_Create_All_Player_Initial_Buildings() : Creates all the Players Initial Buildings on the Map ( & give resources) : Called from OnInit()

-- 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_marine_squad"
	g_starting_blueprint_2 = "chaos_squad_cultist"
	g_starting_blueprint_3 = "chaos_squad_cultist"
	
	-- 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"
	
	-- Builder that Race uses
	g_Builder_blueprint = "dark_eldar_squad_slave"
	
	-- Starting Troops for the Mission
	g_starting_blueprint_1 = "dark_eldar_squad_warrior"
	g_starting_blueprint_2 = "dark_eldar_squad_warrior"
	g_starting_blueprint_3 = "dark_eldar_squad_warrior"
	
	-- 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_squad_banshees"
	g_starting_blueprint_2 = "eldar_guardian_squad"
	g_starting_blueprint_3 = "eldar_guardian_squad"
	
	-- 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"
	g_starting_blueprint_2 = "guard_squad_guardsmen"
	g_starting_blueprint_3 = "guard_squad_guardsmen"
	
	-- 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"
	g_starting_blueprint_2 = "necron_basic_warrior_squad"
	g_starting_blueprint_3 = "necron_wraith_squad"
	
	-- 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_slugga"
	g_starting_blueprint_2 = "ork_squad_shoota_boy"
	g_starting_blueprint_3 = "ork_squad_shoota_boy"
	
	-- 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"
	g_starting_blueprint_2 = "sisters_squad_missionary"
	g_starting_blueprint_3 = "sisters_squad_missionary"
	
	-- 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"
	g_starting_blueprint_2 = "space_marine_squad_tactical"
	g_starting_blueprint_3 = "space_marine_squad_tactical"
	
	-- 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_carnivore_squad"
	g_starting_blueprint_2 = "tau_fire_warrior_squad"
	g_starting_blueprint_3 = "tau_fire_warrior_squad"
	
	-- 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

-- Creates all the Players Initial Units on the Map (including Honor Guard) : Called from OnInit() function Rule_Create_All_Player_Initial_Units() -- 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 Initial Troops
Util_CreateSquadsAtMarkerEx(g_Player1, "sg_player_troops1", g_starting_blueprint_1, "mkr_player_mainBase_troops", 1,20)
Util_CreateSquadsAtMarkerEx(g_Player1, "sg_player_troops2", g_starting_blueprint_2, "mkr_player_mainBase_troops", 1,20)

-- Add Leaders if Squad has One
SGroup_AddLeaders("sg_player_troops1")
SGroup_AddLeaders("sg_player_troops2")

end

-- Creates all the Players Initial Buildings on the Map ( & give resources) : Called from OnInit() -- Actually just gives resources since the buildings are created after the eldar base teleports out 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

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

-- 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_HQ")

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


-- END OF ALL "INITIAL PLAYER SETUP" RULES


-- CREATE AI BUILDINGS RULES -- Rule_Create_All_Ai_Initial_Buildings() : Create all AI Bases & give them initial resources & strategic points : Called from OnInit( ) -- Rule_Setup_AI_StrategicPoints( ) : Setup the Strategic Points, Critical Points, & Relics to AI Control

-- Create all AI Bases & give them initial resources & strategic points : Called from OnInit( ) function Rule_Create_All_Ai_Initial_Buildings() -- Grant the Research for the Webway Gates to Cloak, Heal, & Allow Buildings to Relocate Player_GrantResearch(g_Player2, "eldar_shroud_ability_research") Player_GrantResearch(g_Player2, "eldar_webway_gate_relocation_research") Player_GrantResearch(g_Player2, "eldar_webway_gate_healing_research")

-- Tiering research (Dont think this actually has an effect on the units or anything)
	-- Needed for the Aspect Stones
Player_GrantResearch(g_Player2, "eldar_tier2_research")
Player_GrantResearch(g_Player2, "eldar_annihilate_the_enemy")

-- Create Buildings for Center Base
	-- One that teleports out once attacked
Rule_Create_CenterBase_Buildings()

-- Create & cloaks all the Webway Gates & Buildings around the map
Rule_Create_Cloaked_Buildings()

-- Create all the Hologram Rocks that are controlled by the Hologram Generators
Rule_Create_Holo_Rocks()

-- Create the North & South Bases
Rule_Create_NorthBase_Buildings()
Rule_Create_SouthBase_Buildings()

-- Create the Super Turrets
Rule_Create_Super_Turrets()

-- Setup the Strategic Points, Critical Points,  & Relics to AI Control
Rule_Setup_AI_StrategicPoints( )

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

end

-- Create all the Hologram Rocks that are controlled by the Hologram Generators function Rule_Create_Holo_Rocks() -- Main Base Cover: -- One on each of the Webway Gates for i =1,5 do User_CreateBuilding(g_Player2,"eg_hologramRocks_MainBase", "eldar_hologram_rocks_dxp3","mkr_mainBase_webwayGate"..i, 1) end

-- West Base Cover:
	-- One on each of the Webway Gates
for i =1,3 do
	User_CreateBuilding(g_Player2,"eg_hologramRocks_WestBase", "eldar_hologram_rocks_dxp3","mkr_westBase_webwayGate"..i, 1)
end

-- Create the Rocks that cover up the cloaked webway gates
for i = 12, 20 do
	User_CreateBuilding(g_Player2,"eg_cloaked_webwayGateRock"..i, "eldar_hologram_rocks_dxp3","mkr_cloaked_webwayGate"..i, 1)
end

-- Create the Rock that covers up the Support Portal (Vehicle bays)
for i = 1, 1 do
	User_CreateBuilding(g_Player2,"eg_cloaked_supportPortalRock"..i, "eldar_hologram_rocks_dxp3","mkr_cloaked_supportPortal"..i, 1)
end

-- Create the Rocks that Cover up the 4 Hologram Generators:
for i =1,4 do
	User_CreateBuilding(g_Player2,"eg_hologram_generator_Rock"..i, "eldar_hologram_rocks_dxp3","mkr_hologram_generator"..i, 1)
end

end

-- Create Buildings for the Center Base (the one that starts in middle & Teleports Out) function Rule_Create_CenterBase_Buildings() -- Create the HQ: Webway Assembly -- Located in Starting Location User_CreateBuilding(g_Player2,"eg_centerBase_HQ", "eldar_hq_sp_dxp3","mkr_centerBase_HQ1", 1)

-- Create the Aspect Portal (Barracks)
	-- Located in Starting Location
User_CreateBuilding(g_Player2,"eg_centerBase_aspectPortal", "eldar_aspect_portal_sp_dxp3","mkr_centerBase_aspectPortal1", 1)
EGroup_ForceAddOn("eg_centerBase_aspectPortal", "eldar_aspect_stone_dark_reapers" )

-- Create the Support Portals (Vehicle bays)
	-- Located in Starting Location
User_CreateBuilding(g_Player2,"eg_centerBase_supportPortal", "eldar_support_portal_sp_dxp3","mkr_centerBase_supportPortal1", 1)
EGroup_ForceAddOn("eg_centerBase_supportPortal", "eldar_aspect_stone_vyper" )

-- Create all the ScatterLaser Turrets (& Upgrade to Anti-Vehicle)
	-- Located in Starting Location
for i = 1,4  do
	User_CreateBuilding(g_Player2,"eg_centerBase_supportPlatform"..i, "eldar_support_platform_scatterlaser_sp_dxp3","mkr_centerBase_supportPlatform"..i, 1)

-- EGroup_ForceAddOn("eg_centerBase_supportPlatform"..i, "eldar_support_platform_addon") end

-- Create the Warp Generators (Power Plants)
	-- Located in Starting Location
for i = 1, 4 do
	User_CreateBuilding(g_Player2,"eg_centerBase_warpGenerator"..i, "eldar_warp_generator_sp_dxp3","mkr_centerBase_warpGenerator"..i, 1)
end

-- Create the Webway Gates
	-- 1-2 in starting location, 3-4 in the teleport location
for i = 1, 4 do
	User_CreateBuilding(g_Player2,"eg_centerBase_webwayGate"..i, "eldar_webway_gate","mkr_centerBase_webwayGate"..i, 1)
end

end

-- Create & cloaks all the Webway Gates & Buildings around the map function Rule_Create_Cloaked_Buildings() -- Set up all the Groups for the Cloaked Webway Gates (since not all gates are actually created at start) for i = 1,20 do EGroup_Create("eg_cloaked_webwayGate"..i) EGroup_SetPlayerOwner("eg_cloaked_webwayGate"..i, g_Player2) end

-- Create & cloak (shroud)  all the webway gates
	-- 12- 20 start as rocks & appear later in game
for i = 1, 11 do
	User_CreateBuilding(g_Player2,"eg_cloaked_webwayGate"..i, "eldar_webway_gate","mkr_cloaked_webwayGate"..i, 1)

-- EGroup_Shroud("eg_cloaked_webwayGate"..i,true) end

-- Create all the ScatterLaser Turrets by the random cloaked webway gates (& Upgrade to Anti-Vehicle)
for i = 1,15  do
	User_CreateBuilding(g_Player2,"eg_cloaked_supportPlatform"..i, "eldar_support_platform_scatterlaser","mkr_cloaked_supportPlatform"..i, 1)
	EGroup_ForceAddOn("eg_cloaked_supportPlatform"..i, "eldar_support_platform_addon")
end

end

-- Create Buildings for Main Base function Rule_Create_MainBase_Buildings() -- Create the HQ: Webway Assembly (used for objective) --One that teleports to the Real Base User_CreateBuilding(g_Player2,"eg_HQinMainBase_Objective", "eldar_hq_sp_dxp3","mkr_mainBase_HQ1", 1)

-- Create the Webway Gates
for i = 1, 5 do
	User_CreateBuilding(g_Player2,"eg_mainBase_webwayGate"..i, "eldar_webway_gate","mkr_mainBase_webwayGate"..i, 1)
end

-- Create the Aspect Portals (Barracks)
for i = 1, 2 do
	User_CreateBuilding(g_Player2,"eg_mainBase_aspectPortal"..i, "eldar_aspect_portal","mkr_mainBase_aspectPortal"..i, 1)
	EGroup_ForceAddOn("eg_mainBase_aspectPortal"..i, "eldar_aspect_stone_banshees" )
	EGroup_ForceAddOn("eg_mainBase_aspectPortal"..i, "eldar_aspect_stone_dark_reapers" )
	EGroup_ForceAddOn("eg_mainBase_aspectPortal"..i, "eldar_aspect_stone_fire_dragon" )
end

-- Create the Soul Shrines
	-- number 1 teleports here from Fake Base
for i = 1, 3 do
	User_CreateBuilding(g_Player2,"eg_mainBase_soulShrine"..i, "eldar_soul_shrine","mkr_mainBase_soulShrine"..i, 1)
end

-- Create the Support Portals (Vehicle bays)
for i = 1, 2 do
	User_CreateBuilding(g_Player2,"eg_mainBase_supportPortal"..i, "eldar_support_portal","mkr_mainBase_supportPortal"..i, 1)
	EGroup_ForceAddOn("eg_mainBase_supportPortal"..i, "eldar_aspect_stone_wraithlord" )
	EGroup_ForceAddOn("eg_mainBase_supportPortal"..i, "eldar_aspect_stone_prism" )
end

-- Create all the ScatterLaser Turrets (& Upgrade to Anti-Vehicle)
for i = 1,8  do
	User_CreateBuilding(g_Player2,"eg_mainBase_supportPlatform"..i, "eldar_support_platform_scatterlaser","mkr_mainBase_supportPlatform"..i, 1)
	EGroup_ForceAddOn("eg_mainBase_supportPlatform"..i, "eldar_support_platform_addon")
end

end

-- Create Buildings for North Base function Rule_Create_NorthBase_Buildings() -- Create the Soul Shrines for i = 1, 1 do User_CreateBuilding(g_Player2,"eg_northBase_soulShrine"..i, "eldar_soul_shrine","mkr_northBase_soulShrine"..i, 1) end

-- Create the Support Portals (Vehicle bays)
for i = 1, 2 do
	User_CreateBuilding(g_Player2,"eg_northBase_supportPortal"..i, "eldar_support_portal","mkr_northBase_supportPortal"..i, 1)
	EGroup_ForceAddOn("eg_northBase_supportPortal"..i, "eldar_aspect_stone_nightwing" )
end

-- Create the Warp Generator Gates
for i = 1, 4 do
	User_CreateBuilding(g_Player2,"eg_northBase_warpGenerator"..i, "eldar_warp_generator","mkr_northBase_warpGenerator"..i, 1)
end

-- Create (& Shroud)  the Webway Gates
for i = 1, 4 do
	User_CreateBuilding(g_Player2,"eg_northBase_webwayGate"..i, "eldar_webway_gate","mkr_northBase_webwayGate"..i, 1)

-- EGroup_Shroud("eg_northBase_webwayGate"..i,true) end

-- Create all the ScatterLaser Turrets (& Upgrade to Anti-Vehicle)
for i = 1,4 do
	User_CreateBuilding(g_Player2,"eg_northBase_supportPlatform"..i, "eldar_support_platform_scatterlaser","mkr_northBase_supportPlatform"..i, 1)

-- EGroup_ForceAddOn("eg_northBase_supportPlatform"..i, "eldar_support_platform_addon") end end

-- Create Buildings for South Base function Rule_Create_SouthBase_Buildings() -- Create the HQ: Webway Assembly User_CreateBuilding(g_Player2,"eg_southBase_HQ", "eldar_hq","mkr_southBase_HQ1", 1)

-- Create the Aspect Portals (Barracks)
for i = 1, 2 do
	User_CreateBuilding(g_Player2,"eg_southBase_aspectPortal"..i, "eldar_aspect_portal","mkr_southBase_aspectPortal"..i, 1)
	EGroup_ForceAddOn("eg_southBase_aspectPortal"..i, "eldar_aspect_stone_warp_spider" )
end

-- Create the Soul Shrines
for i = 1, 1 do
	User_CreateBuilding(g_Player2,"eg_southBase_soulShrine"..i, "eldar_soul_shrine","mkr_southBase_soulShrine"..i, 1)
end

-- Create all the ScatterLaser Turrets
for i = 1,4  do
	User_CreateBuilding(g_Player2,"eg_southBase_supportPlatform"..i, "eldar_support_platform_scatterlaser","mkr_southBase_supportPlatform"..i, 1)
end

-- Create (& Shroud) the Webway Gates
for i = 1, 4 do
	User_CreateBuilding(g_Player2,"eg_southBase_webwayGate"..i, "eldar_webway_gate","mkr_southBase_webwayGate"..i, 1)

-- EGroup_Shroud("eg_southBase_webwayGate"..i,true) end end

-- Create the Array of Super Turrets function Rule_Create_Super_Turrets() -- Create EGroup to Track Generators EGroup_Create("eg_super_turret_Objective")

-- Create the Array of Super Turrets
for i =1,20 do
	-- Create all the Egroups of Super Turrets (So Can track damage)
	User_CreateBuilding(g_Player2, "eg_super_turret_"..i, "eldar_support_platform_uberturret_sp_dxp3", "mkr_super_turret_"..i, 1)
	
	-- Add all the Supper Turrets to the same EGroup
	EGroup_AddGroup("eg_super_turret_Objective", "eg_super_turret_"..i)
end

end

-- Create Buildings for West Base function Rule_Create_WestBase_Buildings() -- Create the Webway Gates for i = 1, 3 do User_CreateBuilding(g_Player2,"eg_westBase_webwayGate"..i, "eldar_webway_gate","mkr_westBase_webwayGate"..i, 1) end

-- Create the Aspect Portals (Barracks)
for i = 1, 1 do
	User_CreateBuilding(g_Player2,"eg_westBase_aspectPortal"..i, "eldar_aspect_portal","mkr_westBase_aspectPortal"..i, 1)
	EGroup_ForceAddOn("eg_westBase_aspectPortal"..i, "eldar_aspect_stone_banshees" )
end

-- Create the Support Portals (Vehicle bays)
for i = 1, 1 do
	User_CreateBuilding(g_Player2,"eg_westBase_supportPortal"..i, "eldar_support_portal","mkr_westBase_supportPortal"..i, 1)
	EGroup_ForceAddOn("eg_westBase_supportPortal"..i, "eldar_aspect_stone_wraithlord" )
end

-- Create the Warp Generators
for i = 1, 6 do
	User_CreateBuilding(g_Player2,"eg_westBase_warpGenerator"..i, "eldar_warp_generator","mkr_westBase_warpGenerator"..i, 1)
end

-- Create all the ScatterLaser Turrets (& Upgrade to Anti-Vehicle)
for i = 5,8  do
	User_CreateBuilding(g_Player2,"eg_westBase_supportPlatform"..i, "eldar_support_platform_scatterlaser","mkr_westBase_supportPlatform"..i, 1)
	EGroup_ForceAddOn("eg_westBase_supportPlatform"..i, "eldar_support_platform_addon")
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 ------------------------------------------------------------------------------------------------------------------------------------------------- -- The two by the starting location base for i=1, 2 do EGroup_SetPlayerOwner("eg_stratPoint"..i, g_Player2) end

-- Strategic Points to g_Player2
	-- Upgrade to Tier 2
for i=3, 8 do
	EGroup_SetPlayerOwner("eg_stratPoint"..i, g_Player2)
	Entity_CreateBuildingPosition(g_Player2, "eg_listeningPost"..i, "eldar_listening_post", EGroup_GetPosition("eg_stratPoint"..i), 1)
	EGroup_ForceAddOn("eg_listeningPost"..i, "eldar_list_post_addon_2" )
end

-------------------------------------------------------------------------------------------------------------------------------------------------
-- Relic Ownership  & Upgrades to Listening Posts Level 2
-------------------------------------------------------------------------------------------------------------------------------------------------
-- Relic by the West Base to g_Player2
for i=1, 1 do
	EGroup_SetPlayerOwner("eg_relic"..i, g_Player2)
	Entity_CreateBuildingPosition(g_Player2, "eg_listeningPostRelic"..i, "eldar_listening_post", EGroup_GetPosition("eg_relic"..i), 1)
	EGroup_ForceAddOn("eg_listeningPostRelic"..i, "eldar_list_post_addon_2" )
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

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


-- END OF ALL " CREATE AI BUILDINGS " RULES

-- Abilities:
-- Farseer:	eldar_eldritchstorm, eldar_guide, eldar_mind_war, eldar_psychic_storm
-- Builder:	eldar_wraithtomb

-- eldar_hologram_generator_infiltrate_sp_dxp3

-- 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( ) -- Rule_UI_Game_Timer() : Initially sets up the timer that shows the total elapsed time -- Rule_UI_Game_Timer_Tick(): Updates & Shows the game timer every second

-- Starts the actual mission : Called from OnInit function Rule_GameStart() if not Event_IsAnyRunning() then -- Silvey Polish 10/21/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()

	--Shroud the Webway Gates -- so they appeared during the intro NIS
	Rule_Initial_Base_Cloak()
	
	-- Function used to create all the Player Initial Units on the Map (including Honor Guard)
	Rule_Create_All_Player_Initial_Units( )
	
	-- Function used to create all the Player Initial Buildings on the Map
	Rule_Create_All_Player_Initial_Buildings( )
	
	-- 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()
	
	-- Handles the restoring of save games)
	Rule_AddInterval(Rule_RestoreSupport, 3)
	
	-- Assign the First Objectives
	Rule_AddInterval(Rule_DestroyEldarHQ_Objective, 1)
	
	-- Set up the check for DEFEAT : Function is Defined Below
	Rule_AddInterval(Rule_EndGame_Defeat_Early, 1)
	
	-- Create all the SGroups for attacks & add Tactics Rules
	Rule_Create_Attacks()
	
	--For When Player Gets Near the CenterBase -- Play IE & Produce First Troops
	Rule_AddInterval(Rule_PreTeleport_CenterBase,1)
	
	-- Make Initial Base Buildings Invulnurable (so cant be destroyed pre-teleport): 
	--EGroup_SetHealthInvulnerable("eg_centerBase_HQ", true)
	--EGroup_SetHealthInvulnerable("eg_centerBase_aspectPortal", true)
	--EGroup_SetHealthInvulnerable("eg_centerBase_supportPortal", true)
	
	names = {"eldar_hq_sp_dxp3","eldar_aspect_portal_sp_dxp3","eldar_support_portal_sp_dxp3"}
	
	g_modifier_invulnurable1 = Modifier_Create(MAT_EntityType,"enable_health_damage",MUT_Enable, false, -1, names[1])
	g_modifier_invulnurable2 = Modifier_Create(MAT_EntityType,"enable_health_damage",MUT_Enable, false, -1, names[2])
	g_modifier_invulnurable3 = Modifier_Create(MAT_EntityType,"enable_health_damage",MUT_Enable, false, -1, names[3])
	

-- g_modifier_killable = Modifier_Create(MAT_EntityType,"enable_health_damage",MUT_Enable, false, 1, names[1]) -- g_modifier_killable = Modifier_Create(MAT_EntityType,"enable_health_damage",MUT_Enable, false, 1, names[2]) -- g_modifier_killable = Modifier_Create(MAT_EntityType,"enable_health_damage",MUT_Enable, false, 1, names[3])

	Modifier_ApplyToEntity( g_modifier_invulnurable1, EGroup_GetSpawnedEntityAt("eg_centerBase_HQ",1))
	Modifier_ApplyToEntity( g_modifier_invulnurable2, EGroup_GetSpawnedEntityAt("eg_centerBase_aspectPortal",1))
	Modifier_ApplyToEntity( g_modifier_invulnurable3, EGroup_GetSpawnedEntityAt("eg_centerBase_supportPortal",1))
	
	-- Check for the player destroying the CenterBase (so we know when to warp out the Base & spring the trap)
	Rule_Add(Rule_Check_For_Center_Base_Damage)
	
	-- Checks for & Activates Bases if the Player attacks them before they activated (basically if the player skips the first base for some reason
	Rule_AddInterval(Rule_Check_EarlyPlayer_Attack_North_Base,1)
	Rule_AddInterval(Rule_Check_EarlyPlayer_Attack_Center_Base,1)
	Rule_AddInterval(Rule_Check_EarlyPlayer_Attack_South_Base,1)
	
	-- Restrict the Player From Building Bases
	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 : Called from OnInit() -- Doesn't actually assign the objectives -- Just sets up the tables for them

-- ASSIGNING AND CHECKING:
	-- PRIMARY:
	
	-- Rule_DestroyEldarHQ_Objective()
		-- Rule_DestroyRelocatedEldarHQ_Objective()
		-- Rule_DestroyRealEldarHQ_Objective()
	
	-- Rule_FindRealEldarBase_Objective()	
		-- Rule_FindEldarGenerators_Objective()
		-- Rule_DestroyEldarGenerators_Objective()
	
	-- SECONDARY:
	
	-- Rule_DestroyNorthBase_Objective()
		-- Rule_StopNorthBaseProduction_Objective()
		-- Rule_Objective_Assign_NorthBase_Production()
	
	-- Rule_DestroySouthBase_Objective()
		-- Rule_StopSouthBaseProduction_Objective()
		-- Rule_Objective_Assign_SouthBase_Production()
	
	-- Rule_DisableSuperTurrets_Objective()
		-- Rule_Track_Super_Turret_Damage()

-- Sets up the actual Objective Lua Tables : Called from OnInit() function Rule_Objective_Define() -- Primary Objective : Assigned at Intro Objective_DestroyEldarHQ = { title_id = 3950000, short_desc_id = 3950001, help_tip_id = 3950001}

-- Sub-PrimaryObjective: Assigned once Eldar relocate (teleport) the centerBase HQ
Objective_DestroyRelocatedEldarHQ = { title_id = 3950002, short_desc_id = 3950003, help_tip_id = 3950003}

-- Sub-Primary Ojective : Assigned once centerBase is destroyed & real base is revealed
Objective_DestroyRealEldarHQ = { title_id = 3950004, short_desc_id = 3950005, help_tip_id = 3950005}

-- Primary Ojective : Assigned a little after centerBase is destroyed & real base is revealed
Objective_FindRealEldarBase = { title_id = 3950008, short_desc_id = 3950009, help_tip_id = 3950009}

-- Sub-Primary Ojective : Assigned a little after centerBase is destroyed & real base is revealed
Objective_FindEldarGenerators = { title_id = 3950012, short_desc_id = 3950013, help_tip_id = 3950013}

-- Sub-Primary Ojective : Assigned once a generator is decloaked
Objective_DestroyEldarGenerators = { title_id = 3950010, short_desc_id = 3950011, help_tip_id = 3950011}

-- Secondary Objective: Assigned once Eldar relocate (teleport) the centerBase HQ
Objective_DestroyNorthBase = { title_id = 3950014, short_desc_id = 3950015, help_tip_id = 3950015}

-- Sub-Secondary Objective: Assigned once first Nightwing is killed
Objective_StopNorthBaseProduction = { title_id = 3950016, short_desc_id = 3950017, help_tip_id = 3950017}

-- Secondary Objective: Assigned once Eldar relocate (teleport) the centerBase HQ
Objective_DestroySouthBase = { title_id = 3950018, short_desc_id = 3950019, help_tip_id = 3950019}

-- Sub-Secondary Objective: Assigned once first WarpSpider / Ranger is killed
Objective_StopSouthBaseProduction = { title_id = 3950020, short_desc_id = 3950021, help_tip_id = 3950021}

-- Secondary Objective: Assigned once player finds a super turrent
Objective_DisableSuperTurrets = { title_id = 3950006, short_desc_id = 3950007, help_tip_id = 3950007}

end

-- Assigns & Checks for Primary Objective: (Destroy the Eldar HQ) & is added in OnGameStart() function Rule_DestroyEldarHQ_Objective() -- First check if Objective exists and add if not... if Event_IsAnyRunning() == false and Objective_Exists(Objective_DestroyEldarHQ.title_id) == false then -- Play Initial Race Based IE Event Util_StartIntel(g_ie_Initial_Array[g_intelEvent_raceId])

	-- Create ( & Assign)  the objective as a primary one
	Util_ObjectiveCreate(Objective_DestroyEldarHQ, true)
	
	-- Update & Set the Primary Objective To this one when objective screen shows
	g_PrimaryObjectives = g_PrimaryObjectives + 1
	Objective_SetDefaultPrimary(g_PrimaryObjectives)
	
	-- Setup Ping On Objective Screen (Ping the Location of the Center Base HQ)
		-- Objective Ping will update throughout the mission
	g_EldarHQPing_Objective = Objective_PingMarker(Objective_DestroyEldarHQ.title_id, "mkr_centerBase_HQ1", true, attack)
	
	-- Set up a one time ping on the ingame screen
	Ping_Marker("mkr_centerBase_HQ1", false, "default")
	
	-- Reveal the Fog of War Around the HQ
	FOW_RevealMarker("mkr_centerBase_HQ1", 60)		

-- Else Check if all the Objective Eldar HQs are destroyed
elseif Event_IsAnyRunning() == false and
		g_AllEldarHQDestroyed == true
then	
	-- Complete the Objective and Remove the Rule
	Util_ObjectiveComplete(Objective_DestroyEldarHQ.title_id)
	Rule_Remove( Rule_DestroyEldarHQ_Objective )
	
	-- Call the Victory Rule after a short delay
	Rule_AddOneShot(Rule_EndGame_Victory, 5)		
end

end

-- Assigns & Check for Sub-Primary Objective : (Destroy the Relocated Eldar Center Base HQ) function Rule_DestroyRelocatedEldarHQ_Objective() -- Confirm the Primary Objective Exists and then check if the Sub-Objective exists and add sub if not... if Event_IsAnyRunning() == false and Objective_Exists(Objective_DestroyEldarHQ.title_id) == true and Objective_Exists(Objective_DestroyRelocatedEldarHQ.title_id) == false then -- Create (Assign) the objective as a sub-primary one Objective_SubAdd(Objective_DestroyRelocatedEldarHQ, Objective_DestroyEldarHQ.title_id)

	-- Update & Set the Primary Objective To this one when objective screen shows
	g_PrimaryObjectives = g_PrimaryObjectives + 1
	Objective_SetDefaultPrimary(g_PrimaryObjectives)
	
	--Associate a Ping with the Objective on the Objective Screen
	Objective_PingMarker(Objective_DestroyRelocatedEldarHQ.title_id, "mkr_tp_centerBase_HQ1", true, attack)
	
	-- Set up a ping on the ingame screen
	Ping_Marker("mkr_tp_centerBase_HQ1", false, "default")
	
	-- Change the Primary Objective Ping to Point to this HQ (Stop the Old & Assign the New)
	Objective_PingRemove(Objective_DestroyEldarHQ.title_id, g_EldarHQPing_Objective)
	g_EldarHQPing_Objective = Objective_PingMarker(Objective_DestroyEldarHQ.title_id, "mkr_tp_centerBase_HQ1", true, attack)
	
	-- Reveal the Fog of War around the HQ
	FOW_RevealMarker("mkr_centerBase_underAttack", 15)
	
	-- Show the Objective Screen 
	Objective_ShowScreen()

-- if the objective exists and the HQ is destroyed
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_DestroyEldarHQ.title_id) == true and
	Objective_Exists(Objective_DestroyRelocatedEldarHQ.title_id) == true and	
	EGroup_Count( EGroup_FromName("eg_centerBase_HQ")) == 0
then
	-- Complete the Objective and Remove the Rule
	Util_ObjectiveComplete(Objective_DestroyRelocatedEldarHQ.title_id)
	Rule_Remove(Rule_DestroyRelocatedEldarHQ_Objective)
	
	-- Stop the Ping From the Primary Objective
	Objective_PingRemove(Objective_DestroyEldarHQ.title_id, g_EldarHQPing_Objective)
	
	-- Reveal the MainBase, Activate the WestBase, Etc...
	Rule_CenterBase_Destroyed()
end

end

-- Assigns & Check for Sub-Primary Objective : (Destroy the Real Eldar HQ) function Rule_DestroyRealEldarHQ_Objective() -- Confirm the Primary Objective Exists and then check if the Sub-Objective exists and add sub if not... if Event_IsAnyRunning() == false and Objective_Exists(Objective_DestroyEldarHQ.title_id) == true and Objective_Exists(Objective_DestroyRealEldarHQ.title_id) == false then -- Create (Assign) the objective as a sub-primary one Objective_SubAdd(Objective_DestroyRealEldarHQ, Objective_DestroyEldarHQ.title_id)

	-- Update & Set the Primary Objective To this one when objective screen shows
	g_PrimaryObjectives = g_PrimaryObjectives + 1
	Objective_SetDefaultPrimary(g_PrimaryObjectives)
	
	-- Play IE
	Util_StartIntel(g_ie_Reveal_MainBase_Array[g_intelEvent_raceId])
	
	--Associate a Ping with the Objective on the Objective Screen
	g_EldarRealHQPing_Objective = Objective_PingMarker(Objective_DestroyRealEldarHQ.title_id, "mkr_mainBase_HQ1", true, attack)
	
	-- Set up a ping on the ingame screen
	Ping_Marker("mkr_mainBase_HQ1", false, "default")
	
	-- Change the Primary Objective Ping to Point to this HQ
	g_EldarHQPing_Objective = Objective_PingMarker(Objective_DestroyEldarHQ.title_id, "mkr_mainBase_HQ1", true, attack)
	
	-- Reveal the Fog of War around the HQ
	FOW_RevealMarker("mkr_mainBase_webwayGate5", 60)
	
	-- Assign Primary Objective: Find A Way to Eldar Base
	Rule_AddInterval(Rule_FindRealEldarBase_Objective,1)

-- if the objective exists and the HQ is destroyed
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_DestroyEldarHQ.title_id) == true and
	Objective_Exists(Objective_DestroyRealEldarHQ.title_id) == true and	
	EGroup_Count( EGroup_FromName("eg_HQinMainBase_Objective")) == 0
then
	-- Complete the Objective and Remove the Rule
	Util_ObjectiveComplete(Objective_DestroyRealEldarHQ.title_id)
	Rule_Remove(Rule_DestroyRealEldarHQ_Objective)
	
	-- All HQs Are Destroyed -- So Primary Objective: DestroyEldarHQ will complete
	g_AllEldarHQDestroyed = true		
end

end

-- Assigns & Checks for Primary Objective: (Find a Way past all HoloRocks to Real Eldar Base) function Rule_FindRealEldarBase_Objective() -- First check if Objective exists and add if not... if Event_IsAnyRunning() == false and Objective_Exists(Objective_FindRealEldarBase.title_id) == false then -- Create ( & Assign) the objective as a primary one Util_ObjectiveCreate(Objective_FindRealEldarBase, true)

	-- Update & Set the Primary Objective To this one when objective screen shows
	g_PrimaryObjectives = g_PrimaryObjectives + 1
	Objective_SetDefaultPrimary(g_PrimaryObjectives)
	
	-- So know when objective is complete
	g_AllHoloRocksDestroyed = false
	
	-- Objective Screen Pings of the Locations of the Rocks
	g_holoRockGroup1Ping_Objective = Objective_PingMarker(Objective_FindRealEldarBase.title_id, "mkr_FOW_holoRocksGroup1", true, attack)
	g_holoRockGroup2Ping_Objective = Objective_PingMarker(Objective_FindRealEldarBase.title_id, "mkr_FOW_holoRocksGroup2", true, attack)
	g_holoRockGroup3Ping_Objective = Objective_PingMarker(Objective_FindRealEldarBase.title_id, "mkr_FOW_holoRocksGroup3", true, attack)
	
	-- Set up a one time ping on the ingame screen
	Ping_Marker("mkr_FOW_holoRocksGroup1", false, "default")
	Ping_Marker("mkr_FOW_holoRocksGroup2", false, "default")
	Ping_Marker("mkr_FOW_holoRocksGroup3", false, "default")
	
	-- Reveal the Fog of War Around the Rock Walls
	FOW_RevealMarker("mkr_FOW_holoRocksGroup1", 20)
	FOW_RevealMarker("mkr_FOW_holoRocksGroup2", 20)
	FOW_RevealMarker("mkr_FOW_holoRocksGroup3", 20)
	
	-- Assign Sub-Primary: FindEldarGenerators (Create & Ping Generators)
	Rule_AddIntervalDelay(Rule_FindEldarGenerators_Objective,1,15)
	
	-- Show the Objective Screen 
	Objective_ShowScreen()

-- Else Check if all the Objective Rocks are destroyed
elseif Event_IsAnyRunning() == false and
	g_AllHoloRocksDestroyed == true
	then	
	-- Complete the Objective and Remove the Rule
	Util_ObjectiveComplete(Objective_FindRealEldarBase.title_id)
	Rule_Remove( Rule_FindRealEldarBase_Objective )
end

end

-- Assigns & Check for Sub-Primary Objective : (Find HoloRock generators) function Rule_FindEldarGenerators_Objective() -- ASSIGN: Confirm the Primary Objective Exists & the Sub-Objective doesn't exist... if Event_IsAnyRunning() == false and Objective_Exists(Objective_FindRealEldarBase.title_id) == true and Objective_Exists(Objective_FindEldarGenerators.title_id) == false then -- Create (Assign) the objective as a sub-primary one Objective_SubAdd(Objective_FindEldarGenerators, Objective_FindRealEldarBase.title_id)

	-- Update & Set the Primary Objective To this one when objective screen shows
	g_PrimaryObjectives = g_PrimaryObjectives + 1
	Objective_SetDefaultPrimary(g_PrimaryObjectives)
	
	-- Play IE
	Util_StartIntel(g_ie_Detect_Energy_Sources_Array[g_intelEvent_raceId])
	
	-- So know when the generators are all destoyed
	g_generatorDestroyed_One	=	false
	g_generatorDestroyed_Two	=	false
	g_generatorDestroyed_Three	=	false
	
	-- Remove the HoloRocks that are covering up the generators...
	EGroup_DeSpawn("eg_hologram_generator_Rock1")
	EGroup_DeSpawn("eg_hologram_generator_Rock2")
	EGroup_DeSpawn("eg_hologram_generator_Rock3")
	
	-- Then Create the Hologram Generators
	User_CreateBuilding(g_Player2,"eg_hologram_generator_One_Objective", "eldar_hologram_generator_dxp3","mkr_hologram_generator1", 1)
	User_CreateBuilding(g_Player2,"eg_hologram_generator_Two_Objective", "eldar_hologram_generator_dxp3","mkr_hologram_generator2", 1)
	User_CreateBuilding(g_Player2,"eg_hologram_generator_Three_Objective", "eldar_hologram_generator_dxp3","mkr_hologram_generator3", 1)
	
	-- Create EGroup to Track Generators
	EGroup_Create("eg_hologram_generator_Objective")
	
	-- Add all the Holorock generators to the same EGroup
	EGroup_AddGroup("eg_hologram_generator_Objective", "eg_hologram_generator_One_Objective")
	EGroup_AddGroup("eg_hologram_generator_Objective", "eg_hologram_generator_Two_Objective")
	EGroup_AddGroup("eg_hologram_generator_Objective", "eg_hologram_generator_Three_Objective")
	
	--Associate a Ping with the Objective on the Objective Screen (Ping the 2 Generator Locations)
	g_GeneratorOnePing_Objective = Objective_PingMarker(Objective_FindEldarGenerators.title_id, "mkr_hologram_generator1", true, attack)
	g_GeneratorTwoPing_Objective = Objective_PingMarker(Objective_FindEldarGenerators.title_id, "mkr_hologram_generator2", true, attack)
	g_GeneratorThreePing_Objective = Objective_PingMarker(Objective_FindEldarGenerators.title_id, "mkr_hologram_generator3", true, attack)
	
	-- In game Ping (Ping the 3 Generator Locations)
	Ping_Marker("mkr_hologram_generator1", false, "default")
	Ping_Marker("mkr_hologram_generator2", false, "default")
	Ping_Marker("mkr_hologram_generator3", false, "default")		

-- COMPLETE: The objective exists & a Generators has been damaged
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_FindRealEldarBase.title_id) == true and
	Objective_Exists(Objective_FindEldarGenerators.title_id) == true and
	EGroup_GetAvgHealth("eg_hologram_generator_Objective") < 1.0
then
	-- Complete the Objective and Remove the Rule
	Util_ObjectiveComplete(Objective_FindEldarGenerators.title_id)
	Rule_Remove(Rule_FindEldarGenerators_Objective)
	
	--Add the Other Objective, Since now discovered generators
	Rule_AddInterval(Rule_DestroyEldarGenerators_Objective, 1)
end

end

-- Assigns & Check for Sub-Primary Objective : (Destroy HoloRock generators) & is added function Rule_DestroyEldarGenerators_Objective() -- ASSIGN: Confirm the Primary Objective Exists & the Sub-Objective doesn't exist... if Event_IsAnyRunning() == false and Objective_Exists(Objective_FindRealEldarBase.title_id) == true and Objective_Exists(Objective_DestroyEldarGenerators.title_id) == false then -- Create (Assign) the objective as a sub-primary one Objective_SubAdd(Objective_DestroyEldarGenerators, Objective_FindRealEldarBase.title_id)

	-- Update & Set the Primary Objective To this one when objective screen shows
	g_PrimaryObjectives = g_PrimaryObjectives + 1
	Objective_SetDefaultPrimary(g_PrimaryObjectives)
	
	--Associate a Ping with the Objective on the Objective Screen (Ping the 2 Generator Locations)
	g_GeneratorOnePing_Objective = Objective_PingMarker(Objective_DestroyEldarGenerators.title_id, "mkr_hologram_generator1", true, attack)
	g_GeneratorTwoPing_Objective = Objective_PingMarker(Objective_DestroyEldarGenerators.title_id, "mkr_hologram_generator2", true, attack)
	g_GeneratorThreePing_Objective = Objective_PingMarker(Objective_DestroyEldarGenerators.title_id, "mkr_hologram_generator3", true, attack)
	
	-- Show the Objective Screen 
	Objective_ShowScreen()

-- COMPLETE: The objective exists & All of the Generators  are destroyed
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_FindRealEldarBase.title_id) == true and
	Objective_Exists(Objective_DestroyEldarGenerators.title_id) == true and
	EGroup_Count("eg_hologram_generator_Objective") == 0
then
	-- Play IE
	Util_StartIntel(EVENTS.IE_All_Barriers_Destroyed)
	g_AllHoloRocksDestroyed = true
	
	-- Complete the Objective and Remove the Rule
	Util_ObjectiveComplete(Objective_DestroyEldarGenerators.title_id)
	Rule_Remove(Rule_DestroyEldarGenerators_Objective)
	
	-- Reveal the FOG of War so can see the Rocks are destroyed
	FOW_RevealMarker("mkr_FOW_holoRocksGroup3", 10)
	EGroup_DeSpawn("eg_hologramRocks_GroupThree")
	Ping_Marker("mkr_FOW_holoRocksGroup3", false, "default")
	
	--Activate Main Base
	g_base_activated_Main	=	true
	
	-- Turn off the Main Base Cloak & Remove the Rule
	for i = 1, 5 do
		if EGroup_Count("eg_mainBase_webwayGate"..i) == 1
		then
			EGroup_Shroud("eg_mainBase_webwayGate"..i, false)
		end
	end
	
	-- Main Base Will No Longer Cloak
	Rule_Remove(Rule_Cloak_Main_Base)

-- UPDATE: The objectives exists & First Generator is destroyed
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_FindRealEldarBase.title_id) == true and
	Objective_Exists(Objective_DestroyEldarGenerators.title_id) == true and	
	EGroup_Count("eg_hologram_generator_Objective") == 2 and
	g_generatorDestroyed_One == false
then
	g_generatorDestroyed_One = true
	
	--Play IE:
	Util_StartIntel(EVENTS.IE_First_Barrier_Destroyed)
	
	-- Remove the Objective Screen Ping Associated with Holo Rocks 1
	Objective_PingRemove(Objective_FindRealEldarBase.title_id, g_holoRockGroup1Ping_Objective)
	
	-- Reveal the FOG of War so can see the Rocks are destroyed
	FOW_RevealMarker("mkr_FOW_holoRocksGroup1", 10)
	EGroup_DeSpawn("eg_hologramRocks_GroupOne")
	EGroup_DestroyAllEntities("eg_hologramRocks_GroupOne")
	EGroup_Destroy("eg_hologramRocks_GroupOne")
	Ping_Marker("mkr_FOW_holoRocksGroup1", false, "default")
	
	-- Activate Webway Gates by the First Holowall
	g_webway_activated[5]	= true
	g_webway_activated[6]	= true
	g_webway_activated[7]	= true
	
	for i = 15,16 do
		-- Remove the Holorocks that were covering up the webway gates
		EGroup_DeSpawn("eg_cloaked_webwayGateRock"..i)
		
		-- Spawn in, Cloak, & Activate the Webway Gates by the Generators
		User_CreateBuilding(g_Player2,"eg_cloaked_webwayGate"..i, "eldar_webway_gate","mkr_cloaked_webwayGate"..i, 1)
		EGroup_Shroud("eg_cloaked_webwayGate"..i,true)
		g_webway_activated[i] = true
	end

-- UPDATE: The objectives exists & Two of the Generators are destroyed
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_FindRealEldarBase.title_id) == true and
	Objective_Exists(Objective_DestroyEldarGenerators.title_id) == true and	
	EGroup_Count("eg_hologram_generator_Objective") == 1 and
	g_generatorDestroyed_Two == false
then
	g_generatorDestroyed_Two = true
	
	-- Play IE:
	Util_StartIntel(EVENTS.IE_Second_Barrier_Destroyed)
	
	-- Remove the Objective Screen Ping Associated with Holo Rocks 2
	Objective_PingRemove(Objective_FindRealEldarBase.title_id, g_holoRockGroup2Ping_Objective )
	
	-- Reveal the FOG of War so can see the Rocks are destroyed
	FOW_RevealMarker("mkr_FOW_holoRocksGroup2", 10)
	EGroup_DeSpawn("eg_hologramRocks_GroupTwo")
	Ping_Marker("mkr_FOW_holoRocksGroup2", false, "default")
	
	-- Activate Webway Gate & West Base
	g_webway_activated[8]	= true
	g_base_activated_West	=	true
	
	-- Activate Remaining Webway Gates (Ones South of Player Base)
	for i = 17,20 do
		-- Remove the Holorocks that were covering up the webway gates
		EGroup_DeSpawn("eg_cloaked_webwayGateRock"..i)
		
		-- Spawn in, Cloak, & Activate the Webway Gates by the Generators
		User_CreateBuilding(g_Player2,"eg_cloaked_webwayGate"..i, "eldar_webway_gate","mkr_cloaked_webwayGate"..i, 1)
		EGroup_Shroud("eg_cloaked_webwayGate"..i,true)
		g_webway_activated[i] = true
	end
	
	-- Remove the Holorock around the Support Portal & Create the Support Portal  south of player base
	EGroup_DeSpawn("eg_cloaked_supportPortalRock1")
	User_CreateBuilding(g_Player2,"eg_cloaked_supportPortal1", "eldar_support_portal","mkr_cloaked_supportPortal1", 1)
	g_webway_supportPortal_activated = true		
end

-- Remove the Pings for any generators that are destroyed
if EGroup_Count("eg_hologram_generator_One_Objective") == 0
then
	Objective_PingRemove(Objective_DestroyEldarGenerators.title_id, g_GeneratorOnePing_Objective)
end
if EGroup_Count("eg_hologram_generator_Two_Objective") == 0
then
	Objective_PingRemove(Objective_DestroyEldarGenerators.title_id, g_GeneratorTwoPing_Objective)
end
if EGroup_Count("eg_hologram_generator_Three_Objective") == 0
then
	Objective_PingRemove(Objective_DestroyEldarGenerators.title_id, g_GeneratorThreePing_Objective)
end	

end

-- Assigns & Checks for Secondary Objective : (Destroy North Base -- Called EAST BASE in game) function Rule_DestroyNorthBase_Objective() -- ASSIGN: The Objective doesn't exist... if Event_IsAnyRunning() == false and Objective_Exists(Objective_DestroyNorthBase.title_id) == false then -- Create (Assign) the objective as a secondary one Util_ObjectiveCreate(Objective_DestroyNorthBase, false)

	--Associate a Ping with the Objective on the Objective Screen (Ping the Base)
	Objective_PingMarker(Objective_DestroyNorthBase.title_id, "mkr_northBase_underAttack", true, attack)
	
	-- In game Ping (Ping the Base)
	Ping_Marker("mkr_northBase_underAttack", false, "default")
	
	-- Reveal & Decloak North Base 
	FOW_RevealMarker("mkr_northBase_underAttack", 15)
	
	-- Uncloak the Webway Gates at the NorthBase Location
	for i = 1, 4 do
		if EGroup_Count("eg_northBase_webwayGate"..i) == 1
		then
			EGroup_Shroud("eg_northBase_webwayGate"..i,false)
		end
	end
	
	-- Assign South Objective (which shows the objective screen)
	Rule_AddInterval(Rule_DestroySouthBase_Objective,1)

-- COMPLETE: Both the objective & sub-objective exists & the sub-obj has been completed (both Support Portals are destroyed)
elseif Event_IsAnyRunning() == false and 
		Objective_Exists(Objective_DestroyNorthBase.title_id) == true and
		Objective_Exists(Objective_StopNorthBaseProduction.title_id) == true and
		Objective_GetState(Objective_StopNorthBaseProduction.title_id) == OS_Complete
	then
		-- Play IE Based on if the Elite Air Squadron has been killed already
		if g_EliteAirSquad_Destroyed == true
		then
			Util_StartIntel(EVENTS.IE_Eldar_AirfieldDestroyed_without_Squadron )
		else
			Util_StartIntel(EVENTS.IE_Eldar_AirfieldDestroyed_with_Squadron )
		end
		
		-- Complete the Objective and Remove the Rule
		Util_ObjectiveComplete(Objective_DestroyNorthBase.title_id)
		Rule_Remove(Rule_DestroyNorthBase_Objective)

-- COMPLETE: Objective Exists the support portals are destroyed before the sub-objective is assigned
elseif Event_IsAnyRunning() == false and 
		Objective_Exists(Objective_DestroyNorthBase.title_id) == true and
		Objective_Exists(Objective_StopNorthBaseProduction.title_id) == false and
		EGroup_Count("eg_northBase_supportPortal1") == 0 and
		EGroup_Count("eg_northBase_supportPortal2") == 0
	then
		-- Remove the Production Rule since base is destroyed
		Rule_Remove(Rule_Objective_Assign_NorthBase_Production)
		
		-- Play IE Based on if the Elite Air Squadron has been killed already
		if g_EliteAirSquad_Destroyed == true
		then
			Util_StartIntel(EVENTS.IE_Eldar_AirfieldDestroyed_without_Squadron )
		else
			Util_StartIntel(EVENTS.IE_Eldar_AirfieldDestroyed_with_Squadron )
		end
		
		-- Complete the Objective and Remove the Rule
		Util_ObjectiveComplete(Objective_DestroyNorthBase.title_id)
		Rule_Remove(Rule_DestroyNorthBase_Objective)
end

end

-- Assigns & Check for Sub-Secondary Objective : (Stop North Base Production) & is added function Rule_StopNorthBaseProduction_Objective() -- ASSIGN: Confirm the Secondary Objective Exists & the Sub-Objective doesn't exist... if Event_IsAnyRunning() == false and Objective_Exists(Objective_DestroyNorthBase.title_id) == true and Objective_Exists(Objective_StopNorthBaseProduction.title_id) == false then -- Create (Assign) the objective as a sub-primary one Objective_SubAdd(Objective_StopNorthBaseProduction, Objective_DestroyNorthBase.title_id)

	--Associate a Ping with the Objective on the Objective Screen (Ping the 2 Support Portals)
	g_northSupportPortalOnePing_Objective = Objective_PingMarker(Objective_StopNorthBaseProduction.title_id, "mkr_northBase_supportPortal1", true, attack)
	g_northSupportPortalTwoPing_Objective = Objective_PingMarker(Objective_StopNorthBaseProduction.title_id, "mkr_northBase_supportPortal2", true, attack)
	
	-- In game Ping (Ping the 2 Support Portals)
	Ping_Marker("mkr_northBase_supportPortal1", false, "default")
	Ping_Marker("mkr_northBase_supportPortal2", false, "default")
	
	-- Reveal the Fog of War Around the Support Portals Briefly
	FOW_RevealMarker("mkr_northBase_supportPortal1", 10)
	FOW_RevealMarker("mkr_northBase_supportPortal2", 10)
	
	-- Show the Objective Screen 
	Objective_ShowScreen()

-- COMPLETE: The objective exists & Both of the Aspect Portals  are destroyed
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_DestroyNorthBase.title_id) == true and
	Objective_Exists(Objective_StopNorthBaseProduction.title_id) == true and
	EGroup_Count("eg_northBase_supportPortal1") == 0 and
	EGroup_Count("eg_northBase_supportPortal2") == 0
then
	-- Complete the Objective and Remove the Rule
	Util_ObjectiveComplete(Objective_StopNorthBaseProduction.title_id)
	Rule_Remove(Rule_StopNorthBaseProduction_Objective)

-- UPDATE: The objectives exists & Aspect Portal One is destroyed
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_DestroyNorthBase.title_id) == true and
	Objective_Exists(Objective_StopNorthBaseProduction.title_id) == true and	
	EGroup_Count("eg_northBase_supportPortal1") == 0
then
	-- Remove the Objective Screen Ping Associated with Aspect Portal One
	Objective_PingRemove(Objective_StopNorthBaseProduction.title_id, g_northSupportPortalOnePing_Objective)

-- UPDATE: The objectives exists & Aspect Portal Two is destroyed
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_DestroyNorthBase.title_id) == true and
	Objective_Exists(Objective_StopNorthBaseProduction.title_id) == true and	
	EGroup_Count("eg_northBase_supportPortal2") == 0
then
	-- Remove the Objective Screen Ping Associated with Aspect Portal Two
	Objective_PingRemove(Objective_StopNorthBaseProduction.title_id, g_northSupportPortalTwoPing_Objective)
end

end

-- Checks for when the first Nightwing is killed & Assigns Objective function Rule_Objective_Assign_NorthBase_Production() if SGroup_Exists("sg_northBase_nightwing1") and SGroup_Count("sg_northBase_nightwing1") == 0 and g_northBase_FirstNightwing_Produced == true then -- Play IE Util_StartIntel(EVENTS.IE_Activate_NorthBase)

	Rule_AddInterval(Rule_StopNorthBaseProduction_Objective,1)
	Rule_Remove(Rule_Objective_Assign_NorthBase_Production)
end

end

-- Assigns & Checks for Secondary Objective : (Destroy South Base) & is added function Rule_DestroySouthBase_Objective() -- ASSIGN: The Objective doesn't exist... if Event_IsAnyRunning() == false and Objective_Exists(Objective_DestroySouthBase.title_id) == false then -- Create (Assign) the objective as a secondary one Util_ObjectiveCreate(Objective_DestroySouthBase, false)

	--Associate a Ping with the Objective on the Objective Screen (Ping the Base)
	Objective_PingMarker(Objective_DestroySouthBase.title_id, "mkr_southBase_underAttack", true, attack)
	
	-- In game Ping (Ping the Base)
	Ping_Marker("mkr_southBase_underAttack", false, "default")
	
	-- Reveal & Decloak South Base
	FOW_RevealMarker("mkr_southBase_underAttack", 15)
	
	-- Uncloak the Webway Gates at the SouthBase Location
	for i = 1, 4 do
		if EGroup_Count("eg_southBase_webwayGate"..i) == 1
		then
			EGroup_Shroud("eg_southBase_webwayGate"..i,false)
		end
	end
	
	-- Show the Objective Screen 
	Objective_ShowScreen()

-- COMPLETE: Both the objective & sub-objective exists & the sub-obj has been completed (both Aspect Portals are destroyed)
elseif Event_IsAnyRunning() == false and 
		Objective_Exists(Objective_DestroySouthBase.title_id) == true and
		Objective_Exists(Objective_StopSouthBaseProduction.title_id) == true and
		Objective_GetState(Objective_StopSouthBaseProduction.title_id) == OS_Complete
	then
		-- Play IE
		Util_StartIntel(EVENTS.IE_Eldar_SouthBaseDestroyed)
		
		-- Complete the Objective and Remove the Rule
		Util_ObjectiveComplete(Objective_DestroySouthBase.title_id)
		Rule_Remove(Rule_DestroySouthBase_Objective)
end

end

-- Assigns & Check for Sub-Secondary Objective : (Stop South Base Production) & is added function Rule_StopSouthBaseProduction_Objective() -- ASSIGN: Confirm the Secondary Objective Exists & the Sub-Objective doesn't exist... if Event_IsAnyRunning() == false and Objective_Exists(Objective_DestroySouthBase.title_id) == true and Objective_Exists(Objective_StopSouthBaseProduction.title_id) == false then -- Create (Assign) the objective as a sub-primary one Objective_SubAdd(Objective_StopSouthBaseProduction, Objective_DestroySouthBase.title_id)

	--Associate a Ping with the Objective on the Objective Screen (Ping the 2 Aspect Portals)
	g_southAspectPortalOnePing_Objective = Objective_PingMarker(Objective_StopSouthBaseProduction.title_id, "mkr_southBase_aspectPortal1", true, attack)
	g_southAspectPortalTwoPing_Objective = Objective_PingMarker(Objective_StopSouthBaseProduction.title_id, "mkr_southBase_aspectPortal2", true, attack)
	
	-- In game Ping (Ping the 2 Aspect Portals)
	Ping_Marker("mkr_southBase_aspectPortal1", false, "default")
	Ping_Marker("mkr_southBase_aspectPortal2", false, "default")
	
	-- Reveal the Fog of War Around the Aspect Portals Briefly
	FOW_RevealMarker("mkr_southBase_aspectPortal1", 10)
	FOW_RevealMarker("mkr_southBase_aspectPortal2", 10)
	
	-- Show the Objective Screen 
	Objective_ShowScreen()

-- COMPLETE: The objective exists & Both of the Aspect Portals  are destroyed
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_DestroySouthBase.title_id) == true and
	Objective_Exists(Objective_StopSouthBaseProduction.title_id) == true and
	EGroup_Count("eg_southBase_aspectPortal1") == 0 and
	EGroup_Count("eg_southBase_aspectPortal2") == 0
then
	-- Complete the Objective and Remove the Rule
	Util_ObjectiveComplete(Objective_StopSouthBaseProduction.title_id)
	Rule_Remove(Rule_StopSouthBaseProduction_Objective)

-- UPDATE: The objectives exists & Aspect Portal One is destroyed
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_DestroySouthBase.title_id) == true and
	Objective_Exists(Objective_StopSouthBaseProduction.title_id) == true and	
	EGroup_Count("eg_southBase_aspectPortal1") == 0
then
	-- Remove the Objective Screen Ping Associated with Aspect Portal One
	Objective_PingRemove(Objective_StopSouthBaseProduction.title_id, g_southAspectPortalOnePing_Objective)

-- UPDATE: The objectives exists & Aspect Portal Two is destroyed
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_DestroySouthBase.title_id) == true and
	Objective_Exists(Objective_StopSouthBaseProduction.title_id) == true and	
	EGroup_Count("eg_southBase_aspectPortal2") == 0
then
	-- Remove the Objective Screen Ping Associated with Aspect Portal Two
	Objective_PingRemove(Objective_StopSouthBaseProduction.title_id, g_southAspectPortalTwoPing_Objective)
end

end

-- Checks for when the first warp spiders / rangers are killed & Assigns Objective function Rule_Objective_Assign_SouthBase_Production() if SGroup_Exists("sg_southBase_rangers1") and SGroup_Count("sg_southBase_rangers1") == 0 and g_southBase_FirstTroops_Produced == true then -- Play IE Util_StartIntel(EVENTS.IE_Activate_SouthBase)

	Rule_AddInterval(Rule_StopSouthBaseProduction_Objective,3)
	Rule_Remove(Rule_Objective_Assign_SouthBase_Production)

elseif SGroup_Exists("sg_southBase_warpspider1") and
	SGroup_Count("sg_southBase_warpspider1") == 0 and
	g_southBase_FirstTroops_Produced == true
then
	-- Play IE
	Util_StartIntel(EVENTS.IE_Activate_SouthBase)
	
	Rule_AddInterval(Rule_StopSouthBaseProduction_Objective,3)
	Rule_Remove(Rule_Objective_Assign_SouthBase_Production)
end

end

-- Checks for Super Turret Activation / Disabling function Rule_DisableSuperTurrets_Objective() -- ASSIGN: Confirm the Secondary Objective Doesn't exist... if Event_IsAnyRunning() == false and Objective_Exists(Objective_DisableSuperTurrets.title_id) == false then -- Create (Assign) the objective as a secondary one Util_ObjectiveCreate(Objective_DisableSuperTurrets, false)

	--Associate a Ping with the Objective on the Objective Screen (Ping the Generator to Disable)
	g_southAspectPortalOnePing_Objective = Objective_PingMarker(Objective_DisableSuperTurrets.title_id, "mkr_hologram_generator4", true, attack)
	
	-- Remove the HoloRocks that are covering up the generator
	EGroup_DeSpawn("eg_hologram_generator_Rock4")
	
	-- Spawn in the Generator (Is a modified Thermo-Plasma Generator that can build on normal ground)
	--User_CreateBuilding(g_Player2,"eg_hologram_generator_turrets", "eldar_hologram_generator_dxp3","mkr_hologram_generator4", 1)
	User_CreateBuilding(g_Player2,"eg_hologram_generator_turrets", "eldar_advanced_warp_generator_noslag_sp_dxp3","mkr_hologram_generator4", 1)
	
	-- Show the Objective Screen 
	Objective_ShowScreen()

-- COMPLETE: The objective exists & Hologenerator controlling the turrets is destroyed
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_DisableSuperTurrets.title_id) == true and
	EGroup_Count("eg_hologram_generator_turrets") == 0
then
	-- Grant Research to Disable the Turrets
	Player_GrantResearch(g_Player2, "eldar_disable_uberturret_sp_dxp3")
	
	-- Play IE:
	Util_StartIntel(EVENTS.IE_Turrets_Disabled)
	
	-- Complete the Objective and Remove the Rule
	Util_ObjectiveComplete(Objective_DisableSuperTurrets.title_id)
	Rule_Remove(Rule_DisableSuperTurrets_Objective)

-- COMPLETE: The objective exists & All of the Turrets have been destroyed
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_DisableSuperTurrets.title_id) == true and
	EGroup_Count("eg_super_turret_Objective") == 0
then
	-- Play IE:
	Util_StartIntel(EVENTS.IE_Turrets_Disabled)
	
	-- Complete the Objective and Remove the Rule
	Util_ObjectiveComplete(Objective_DisableSuperTurrets.title_id)
	Rule_Remove(Rule_DisableSuperTurrets_Objective)
end

end

-- Checks for Super Turret Damage function Rule_Track_Super_Turret_Damage() local assign_turret_objective = false

-- Check if a turret has been damaged (life less than 90%)
for i =1,20 do
	if EGroup_GetAvgHealth("eg_super_turret_"..i) <= 0.90
	then
		assign_turret_objective = true
	end
end

-- If a turret has been damaged -- assign Objective
if assign_turret_objective == true
then
	-- Play IE:
	Util_StartIntel(g_ie_Turrents_Found_Array[g_intelEvent_raceId])
	
	-- Assign Objective & Remove Rule
	Rule_AddInterval(Rule_DisableSuperTurrets_Objective,1)
	Rule_Remove(Rule_Track_Super_Turret_Damage)		
end

end

-- Play IE the First Time Nightwings are encountered function Rule_IE_Elite_Nightwing_Contact() -- First Contact has been made with the Elite Nightwings if Event_IsAnyRunning() == false and SGroup_Exists("sg_eliteNightwings") and SGroup_GetAvgHealth("sg_eliteNightwings") ~= 1.0 then -- Play IE & Remove Rule Util_StartIntel(EVENTS.IE_Meet_Elite_Aircraft) Rule_Remove(Rule_IE_Elite_Nightwing_Contact) end end

-- Play the IE for when all elite Nightwings are destroyed function Rule_IE_Elite_Nightwing_Destroyed() -- All Elite Nightwings are destroyed if Event_IsAnyRunning() == false and SGroup_Exists("sg_eliteNightwings") and SGroup_Count("sg_eliteNightwings") == 0 then -- Play IE Util_StartIntel(EVENTS.IE_Destroyed_Elite_Aircraft )

	-- Incase you destroy them before the Air Base
	g_EliteAirSquad_Destroyed = true
	
	-- Remove Rules
	Rule_Remove(Rule_IE_Elite_Nightwing_Destroyed)
	Rule_Remove(Rule_IE_Elite_Nightwing_Contact)
end

end

-- END OF ALL " OBJECTIVES " RULES


-- INCREASE ALERT LEVELS -- Increase the Overall Alert Level -- Allows Better Research and Unit Production -- Rule_Upgrade_To_Alert_Zero() -- Rule_Upgrade_To_Alert_One() -- Rule_Upgrade_To_Alert_Two() -- Rule_Upgrade_To_Alert_Three()

-- Make Sure Alert Level Increased: Time Delay
	-- Rule_Delayed_Upgrade_To_Alert_One()
	-- Rule_Delayed_Upgrade_To_Alert_Two()
	-- Rule_Delayed_Upgrade_To_Alert_Three()

-- Activate the First Three Bases & Sync All Attacks -- Alert Level for After Teleport Out function Rule_Upgrade_To_Alert_Zero() g_currentAlertStatus = 0

-- Activate the First Couple of Bases
g_base_activated_Center = true
g_base_activated_North = true
g_base_activated_South = true

-- Play IE Here
Util_StartIntel(g_ie_PostTeleport_CenterBase_Array[g_intelEvent_raceId])

--Assign the Secondary Objectives to Destroy North Base & South Base (Called EAST & WEST in Game)
	-- North calls the Rule to Assign South
Rule_AddInterval(Rule_DestroyNorthBase_Objective,1)

-- Add Checks to Assign the Sub-Secondary Objectives
Rule_AddInterval(Rule_Objective_Assign_NorthBase_Production,1)
Rule_AddInterval(Rule_Objective_Assign_SouthBase_Production,1)

-- Set Base Cloaked Varibles to False (so they can be recloaked based on player attacks)
g_base_cloaked_Center	=	false
g_base_cloaked_North	=	false
g_base_cloaked_South	=	false

-- Checks for & Cloaks the Eldar Bases if the Player Units Attack them 
Rule_AddInterval(Rule_Cloak_Center_Base, 1)
Rule_AddInterval(Rule_Cloak_North_Base, 1)
Rule_AddInterval(Rule_Cloak_South_Base, 1)

-- Sync all Attacks & Base Production
Rule_Sync_Attacks()

-- Check for Early Attacks on the Webway Gates (Pre-Activation)
Rule_AddInterval(Rule_Check_EarlyPlayer_Attack_Webway,1)

-- Add the Delays to Alert Levels
Rule_AddOneShot(Rule_Delayed_Upgrade_To_Alert_One, g_time_until_alertOne)
Rule_AddOneShot(Rule_Delayed_Upgrade_To_Alert_Two, g_time_until_alertTwo)
Rule_AddOneShot(Rule_Delayed_Upgrade_To_Alert_Three, g_time_until_alertThree)

--Set up Target for Attacking Squads
g_attack_target = Marker_GetPosition(Marker_FromName("mkr_player_mainBase_HQ", "basic_marker"))

-- Produce Some First Attack troops from the three bases
--North Base:
Rule_Produce_DarkReapers("sg_northBase_darkreaper1", "eg_northBase_webwayGate1", "mkr_northBase_webwayGate1")
g_northBase_darkreaper_status[1] = g_squad_produced						

-- South Base:
Rule_Produce_Guardian("sg_southBase_guardian1", "eg_southBase_HQ", "mkr_southBase_HQ1")
g_southBase_guardian_status[1] = g_squad_produced

-- Center Base:
Rule_Produce_DarkReapers("sg_centerBase_darkreaper1", "eg_centerBase_aspectPortal", "mkr_tp_centerBase_aspectPortal1")
g_centerBase_darkreaper_status[1] = g_squad_produced

end

-- Increase the Overall Alert Level -- Allows Better Research and Unit Production function Rule_Upgrade_To_Alert_One() -- Play a Taunt so player knows upgrade occured Util_StartIntel(g_ie_Taunt_Array[2]) g_currentAlertStatus = 1

-- Activate the Vypers from the Center Base (May be already active via attack)
g_base_activated_Center_Vyper = true

-- Allow Rangers to Cloak
Player_GrantResearch(g_Player2, "eldar_ranger_infiltration_research")

-- Give Warlocks their abilities
Player_GrantResearch(g_Player2, "eldar_warlock_ability_research")

-- Increase Health & Accuracy
Player_GrantResearch(g_Player2, "eldar_research_infantryaccuracy_1")
Player_GrantResearch(g_Player2, "eldar_research_infantryhealth_1")

-- Increase Reinforce Percent (Larger Squad Sizes)
g_reinforce_percent	=	0.70

end

-- Increase the Overall Alert Level -- Allows Better Research and Unit Production function Rule_Upgrade_To_Alert_Two() -- Play a Taunt so player knows upgrade occured Util_StartIntel(g_ie_Taunt_Array[1]) g_currentAlertStatus = 2

-- Enable Grenades for Warp Spiders & Guardians
Player_GrantResearch(g_Player2, "eldar_haywire_bomb_research")
Player_GrantResearch(g_Player2, "eldar_plasma_grenade_research")

-- Increase Health of Guardian Warlock, Farseer & Harlequin
Player_GrantResearch(g_Player2, "eldar_research_farseerhealth_1")

-- Activate the NightWings from North Base (May be already active via attack)
g_base_activated_North_NightWing = true

-- Activate some webway gates
g_webway_activated[1]		= true
g_webway_activated[2]		= true	
g_webway_activated[3]		= true
g_webway_activated[4]		= true
g_webway_activated[11]	= true

-- Increase Reinforce Percent (Larger Squad Sizes)
g_reinforce_percent	=	0.80

end

-- Increase the Overall Alert Level -- Allows Better Research and Unit Production function Rule_Upgrade_To_Alert_Three() -- Play a Taunt so player knows upgrade occured Util_StartIntel(g_ie_Taunt_Array[3])

-- Stop the Recapture of Strat Points
g_canCaptureStrat	=	false

g_currentAlertStatus = 3

-- Increase Reinforce Percent (Larger Squad Sizes)
g_reinforce_percent	=	0.90

-- Banshee Upgrades:
Player_GrantResearch(g_Player2, "eldar_exarch_ability_research")

-- Give Vehicles Better Armor
Player_GrantResearch(g_Player2, "eldar_vehicle_ability_research")

-- Increase Health of Guardian Warlock, Farseer & Harlequin
Player_GrantResearch(g_Player2, "eldar_research_farseerhealth_2")

-- Give the Farseer Abilities
Player_GrantResearch(g_Player2, "eldar_farseer_ability_research")
Player_GrantResearch(g_Player2, "eldar_farseer_ability_research_3")

-- Increase Health & Accuracy
Player_GrantResearch(g_Player2, "eldar_research_infantryaccuracy_2")
Player_GrantResearch(g_Player2, "eldar_research_infantryhealth_2")	

end

-- Make Sure Alert Level Increased: Time Delay function Rule_Delayed_Upgrade_To_Alert_One() if g_currentAlertStatus == 0 then g_currentAlertStatus = 1 Rule_AddOneShot(Rule_Upgrade_To_Alert_One, 0) end end

-- Make Sure Alert Level Increased: Time Delay function Rule_Delayed_Upgrade_To_Alert_Two() if g_currentAlertStatus == 1 then g_currentAlertStatus = 2 Rule_AddOneShot(Rule_Upgrade_To_Alert_Two, 0) end end -- Make Sure Alert Level Increased: Time Delay function Rule_Delayed_Upgrade_To_Alert_Three() if g_currentAlertStatus == 2 then g_currentAlertStatus = 3 Rule_AddOneShot(Rule_Upgrade_To_Alert_Three, 0) end end

-- END OF ALL " INCREASE ALERT LEVELS " RULES


-- 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 -- Added as an Interval Rule from Rule_Create_And_Sync_Attacks() function Rule_Squad_Tactics_Helper() -- Get all the world owned strategic points (relics & crits also) EGroup_Clear("eg_world_points") World_GetStrategicPoints("eg_world_points")

-- Handles Units for the Center Base
g_centerBase_darkreaper_status[1]	=	Rule_Squad_Tactics("sg_centerBase_darkreaper1", g_centerBase_darkreaper_status[1], g_skill_darkreaper)
g_centerBase_guardian_status[1]		=	Rule_Squad_Tactics("sg_centerBase_guardian1", g_centerBase_guardian_status[1], g_skill_guardians)
g_centerBase_vyper_status[1]			=	Rule_Squad_Tactics("sg_centerBase_vyper1", g_centerBase_vyper_status[1], g_skill_centerBase_vehicle_jump)

-- Handles Units for the Main Base
g_mainBase_avatar_status[1]			=	Rule_Squad_Tactics("sg_mainBase_avatar", g_mainBase_avatar_status[1], 0)
g_mainBase_fireDragon_status[1]		=	Rule_Squad_Tactics("sg_mainBase_fireDragon", g_mainBase_fireDragon_status[1], g_skill_firedragon)
g_mainBase_banshee_status[1]		=	Rule_Squad_Tactics("sg_mainBase_banshee", g_mainBase_banshee_status[1], g_skill_banshees)
g_mainBase_darkreapers_status[1]	=	Rule_Squad_Tactics("sg_mainBase_darkreapers", g_mainBase_darkreapers_status[1], g_skill_darkreaper)
g_mainBase_firePrism_status[1]			=	Rule_Squad_Tactics("sg_mainBase_firePrism1", g_mainBase_firePrism_status[1], 0)
g_mainBase_firePrism_status[2]			=	Rule_Squad_Tactics("sg_mainBase_firePrism2", g_mainBase_firePrism_status[2], 0)
g_mainBase_wraithLord_status[1]		=	Rule_Squad_Tactics("sg_mainBase_wraithLord1", g_mainBase_wraithLord_status[1], g_skill_wraithLord)
g_mainBase_wraithLord_status[2]		=	Rule_Squad_Tactics("sg_mainBase_wraithLord2", g_mainBase_wraithLord_status[2], g_skill_wraithLord)

-- Handles Units for the North Base
g_northBase_darkreaper_status[1]		=	Rule_Squad_Tactics("sg_northBase_darkreaper1", g_northBase_darkreaper_status[1], g_skill_darkreaper)
g_northBase_darkreaper_status[2]		=	Rule_Squad_Tactics("sg_northBase_darkreaper2", g_northBase_darkreaper_status[2], g_skill_darkreaper)
g_northBase_nightwing_status[1]			=	Rule_Squad_Tactics("sg_northBase_nightwing1", g_northBase_nightwing_status[1], 0)
g_northBase_nightwing_status[2]			=	Rule_Squad_Tactics("sg_northBase_nightwing2", g_northBase_nightwing_status[2], 0)
g_northBase_falconGravTank_status[1]	=	Rule_Squad_Tactics("sg_northBase_falconGravTank1", g_northBase_falconGravTank_status[1], 0)
g_northBase_falconGravTank_status[2]	=	Rule_Squad_Tactics("sg_northBase_falconGravTank2", g_northBase_falconGravTank_status[2], 0)

-- Handles Units for the South Base
	-- Base Also has patroling Rangers
g_southBase_guardian_status[1]		=	Rule_Squad_Tactics("sg_southBase_guardian1", g_southBase_guardian_status[1], g_skill_guardians)
g_southBase_warpspider_status[1]	=	Rule_Squad_Tactics("sg_southBase_warpspider1", g_southBase_warpspider_status[1], g_skill_southBase_warpspider_jump)

-- Handles Units for the West Base
g_westBase_banshee_status[1]		=	Rule_Squad_Tactics("sg_westBase_banshee1", g_westBase_banshee_status[1], g_skill_banshees)
g_westBase_wraithLord_status[1]		=	Rule_Squad_Tactics("sg_westBase_wraithLord1", g_westBase_wraithLord_status[1], g_skill_wraithLord)

-- Handles the WraithLord from the Southern Support Portal
g_webway_supportPortalTank_status[1]	=	Rule_Squad_Tactics("sg_webway_wraithLord", g_webway_supportPortalTank_status[1], 0)

-- Handles Units for the Cloaked Webway Gates
for i =1,2 do
	g_webway_banshees_status[i]		=	Rule_Squad_Tactics("sg_webway_banshees"..i, g_webway_banshees_status[i], g_skill_banshees)
	g_webway_darkreaper_status[i]	=	Rule_Squad_Tactics("sg_webway_darkreaper"..i, g_webway_darkreaper_status[i], g_skill_darkreaper)
	g_webway_firedragon_status[i]		=	Rule_Squad_Tactics("sg_webway_firedragon"..i, g_webway_firedragon_status[i], g_skill_firedragon)
	g_webway_guardian_status[i]		=	Rule_Squad_Tactics("sg_webway_guardian"..i, g_webway_guardian_status[i], g_skill_guardians)
	
	-- not currently used
	g_webway_ranger_status[i]			=	Rule_Squad_Tactics("sg_webway_rangers"..i, g_webway_ranger_status[i], 0)
end

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 Relic
	if g_canCaptureRelic == true and
		Prox_SquadsInProximityOfEntities(squad, "building_target", range, true) and
		EGroup_ContainsBlueprints("building_target", g_blueprintRelic, false) == true
	then
		-- Attack towards the Relic
		g_attack_target = EGroup_GetPosition("building_target")
		return true
	
	-- If Squad is in proximity of a Critical Point 
	elseif g_canCaptureCrit == true and
		Prox_SquadsInProximityOfEntities(squad, "building_target", range, true) and
		EGroup_ContainsBlueprints("building_target", g_blueprintCritPoint, false) == true
	then
		-- Attack towards the Critical Point
		g_attack_target = EGroup_GetPosition("building_target")
		return true
	
	-- If Squad is in proximity of a Strategic Point 
	elseif g_canCaptureStrat == true and
		Prox_SquadsInProximityOfEntities(squad, "building_target", range, true) and
		EGroup_ContainsBlueprints("building_target", g_blueprintStratPoint, false) == true
	then
		-- Attack towards the Strategic Point
		g_attack_target = EGroup_GetPosition("building_target")
		return true
	end	
end

-- Make Sure Squad has members (otherwise this function is useless)
if SGroup_CountSpawned(squad) <= 0
then
	return squad_status
end

-- Idle Mode : Do Nothing -- Used to Make a unit just hang around after being produced
if squad_status == g_squad_idle
then
	return squad_status
end

-- if currently in Attack Mode...
if squad_status == g_squad_attacking
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
		-- Engage Fleet of Foot if possible & Give Location To Retreat To
		Cmd_CastAbilitySelf(squad, "eldar_fleetoffoot")
		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_HQ", "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
	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
		-- Should Disengage Fleet of Foot
		Cmd_CastAbilitySelf(squad, "eldar_fleetoffoot")
		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

-- Prep for Squad Jumping (Reinforcing & Moving towards jump zone)
elseif squad_status == g_squad_jump_prep
then
	-- South Base Sends it troops to Jump Location 1
	if skill_id == g_skill_southBase_warpspider_jump
	then
		-- Check if arrived 
		if Prox_AllSquadsNearMarker(squad, "mkr_AI_jumpLocation1")
		then
			-- Check if need to reinforce
			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)
			else
				squad_status = g_squad_jump_ready
			end	
		else
			Cmd_AttackMoveMarker(squad, "mkr_AI_jumpLocation1")
		end
	
	-- Center Base Sends it troops to Jump Location 2
	elseif skill_id == g_skill_centerBase_vehicle_jump
	then
		-- Check if arrived 
		if Prox_AllSquadsNearMarker(squad, "mkr_AI_jumpLocation2")
		then
			squad_status = g_squad_jump_ready
		else
			Cmd_AttackMoveMarker(squad, "mkr_AI_jumpLocation2")
		end
	end

-- Actual Squad Jumping
elseif squad_status == g_squad_jump_ready
then
	-- Center Base is Vypers
	if skill_id == g_skill_centerBase_vehicle_jump
	then
		jumpLoc = World_GetRand(1, 3)
		Cmd_JumpToMarker(squad, "mkr_AI_landLocation"..jumpLoc)
		squad_status = g_squad_jump_attack
	
	-- South Base is Warp Spiders
	elseif skill_id == g_skill_southBase_warpspider_jump
	then
		-- IF Morale Broken, Jump Back to Launch Zone, so can heal up & try again
		if SGroup_IsMoraleBroken(squad,true)
		then
			Cmd_JumpToMarker(squad, "mkr_AI_landLocation1")
			squad_status = g_squad_jump_prep
		
		--Jump to Next Location & Attack from the New Direction
		else
			jumpLoc = World_GetRand(1, 6)
			Cmd_JumpToMarker(squad, "mkr_AI_landLocation"..jumpLoc)
			squad_status = g_squad_jump_attack
		end
	end

-- Check for Jumping
elseif squad_status == g_squad_jump_attack
then
	-- Try & use Skills, or just pick target & attack
	if skill_id > 0 and Rule_Squad_Skill(squad, skill_id) == true
	then
		squad_status = g_squad_jump_checkjump		
	else
		Cmd_AttackMovePos(squad,g_attack_target)
		squad_status = g_squad_jump_checkjump
	end

-- Check if need to jump (also controls reinforcing)
elseif squad_status == g_squad_jump_checkjump
then
	if SGroup_IsUnderAttack(squad, true)
	then
		squad_status = g_squad_jump_ready
	end
	
	-- Check if need to reinforce
	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)
	end

-- 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, & Cannibalism Parts
	local blueprintTable = Util_MakeBlueprintTable("relic_struct", "strategic_point_flag", "strategic_objective_struct", "cannibalism_Parts")
	
	if Prox_SquadsInProximityOfEntities(squad, "building_target", range, true) and 
		Prox_SquadsInProximityOfEntities(squad, "building_target", rangeMin, true) == false 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-Eldar 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, true) == 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-Eldar Owned Critical Point 
	elseif g_canCaptureCrit == true and
		Prox_SquadsInProximityOfEntities(squad, "building_target", range, true) and
		EGroup_ContainsBlueprints("building_target", g_blueprintCritPoint, true) == true
	then
		-- Try to Capture the Critical Point
		Cmd_Capture(squad, "building_target")
		return true	
	
	-- If Squad is in proximity of a Non-Eldar 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, true) == true and
		EGroup_HasStrategicPointWithStructure("building_target") == false
	then
		-- Try to Capture the Strategic Point
		Cmd_Capture(squad, "building_target")
		return true			
	end	
end	

rangeMin = 0

-- FireDragon -- Try & Make Sure Attacks the Vehicles/ Buildings if they can
if skillID == g_skill_firedragon
then
	range = 35
	
	-- Attack Nearby Vehicles if possible
	if 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 true
		
	-- Attack Nearby Buildings if possible
	elseif SGroup_IsMoraleBroken(squad,true) == false and
		EGroup_ForEach(Player_GetEntities(g_Player1), Rule_Detect_Proximity_Buildings) and
		EGroup_Count("building_target") > 0
	then
		Cmd_AttackEGroup(squad, "building_target")
		return true
	
	-- Try & Capture Player 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
	
	-- 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

-- Guardian Skills
elseif skillID == g_skill_guardians
then
	range = 35
	
	-- Entanglement on Enemy Infantry Squads (Needs Warlock)
	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, "eldar_entanglement", "skill_target")
	then
		return true
	
	-- Embolden of Self if Morale is Broken (Needs Warlock)
	elseif SGroup_HasLeader(squad, true) and
			SGroup_IsMoraleBroken(squad,true) and
			Cmd_CastAbilitySGroup(squad, "eldar_embolden", "skill_target")
	then
		return true
	
	-- Grenades on Enemy Infantry Squads
	elseif SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity) and
			SGroup_Count("skill_target") > 0 and
			Cmd_CastAbilitySGroup(squad, "eldar_plasma_grenades", "skill_target")
	then
		return true
	
	-- 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
	
	-- Try & Capture Player 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
	
	-- 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

-- Banshees War Shout -- Morale Damage to Enemy Squads
elseif skillID == g_skill_banshees
then
	range = 35
	
	-- If have leader & enemy troops in range
	if SGroup_HasLeader(squad, true) and
		SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity) and
		SGroup_Count("skill_target") > 0 and
		Cmd_CastAbilitySelf(squad, "eldar_warshout")
	then
		return true
	
	-- 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
	
	-- Try & Capture Player 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
	
	-- 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

-- Dark Reaper -- Target Infantry & Capt Points
elseif skillID == g_skill_darkreaper
then
	range = 35
	
	-- 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
	
	-- Try & Capture Player 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
	
	-- 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

-- Farseer Skills
elseif skillID == g_skill_farseer
then
	-- Farseer Skills go here
	return false

-- Harlequin Skills
elseif skillID == g_skill_harlequin
then
	-- Harlequins Kiss on Enemy Infantry Squads
	if SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity) and
		SGroup_Count("skill_target") > 0 and
		Cmd_CastAbilitySGroup(squad, "eldar_liquefy", "skill_target")
	then
		return true
	
	-- Attempt "Dance of Death" if Nearby Infantry Squads
	elseif SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity) and
		SGroup_Count("skill_target") > 0
	then
		Squad_DanceOfDeath(squad)
		return true			
	end

-- WraithLord -- Try & Make Sure Attacks the Vehicles/ Buildings if they can
elseif skillID == g_skill_wraithLord
then
	-- Attack Nearby Vehicles if possible
	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
		
	-- Attack Nearby Buildings if possible
	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

-- Builder Skills

-- elseif skillID == g_skill_builder -- then -- WraithTomb on Buildings (Stops Productions) -- if EGroup_ForEach(Player_GetEntities(g_Player1), Rule_Detect_Proximity_Buildings) and -- EGroup_Count("building_target") > 0 and -- Cmd_CastAbilitySGroupE(squad, "eldar_wraithtomb", "building_target") -- then -- return true -- end

--Warp Spiders
elseif skillID == g_skill_southBase_warpspider_jump
then
	range = 35
	
	-- Use Haywire Grenades on Vehicles
	if SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity_Vehicles) and
		SGroup_Count("skill_target") > 0 and
		Cmd_CastAbilitySGroup(squad, "eldar_haywire_bombs", "skill_target")
	then
		return true
	
	-- Use Haywire Grenades on Buildings
	elseif EGroup_ForEach(Player_GetEntities(g_Player1), Rule_Detect_Proximity_Buildings) and
		EGroup_Count("building_target") > 0 and
		Cmd_CastAbilitySGroupE(squad, "eldar_haywire_bombs", "building_target")
	then
		return true
	end		
end

end


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


-- UNIT PRODUCTION -- 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_Avatar
	-- Rule_Produce_Banshees
		-- Rule_Produce_Banshees_Full
	-- Rule_Produce_Bonesinger
	-- Rule_Produce_DarkReapers
		-- Rule_Produce_DarkReapers_Full
	-- Rule_Produce_FalconGravTank
	-- Rule_Produce_Farseer
	-- Rule_Produce_FireDragon
		-- Rule_Produce_FireDragon_Full
	-- Rule_Produce_FirePrism
	-- Rule_Produce_GravPlatform
	-- Rule_Produce_GravPlatform_Brightlance
	-- Rule_Produce_Guardian
	-- Rule_Produce_Harlequin
	-- Rule_Produce_Nightwing
		-- Rule_Produce_Nightwing_Elite
	-- Rule_Produce_Rangers
		-- Rule_Produce_Rangers_Full
	-- Rule_Produce_SeerCouncil
		-- Rule_Produce_SeerCouncil_Full
	-- Rule_Produce_Vyper
	-- Rule_Produce_WarpSpider
	-- Rule_Produce_WraithLord

-- Produce an Avatar from Building at Marker for g_Player2 & Assign it to SGroup(squadName) if building exists function Rule_Produce_Avatar(squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create an Avatar Util_CreateSquadsAtMarker(g_Player2, squadName, "eldar_squad_avatar", markerName, 1)

	-- Avatar was Created
	return true
end

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

end

-- Produce a Banshee Squad from Building at Marker for g_Player2 & Assign it to SGroup(squadName) if building exists function Rule_Produce_Banshees(squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a squad of Banshee & give leader Util_CreateSquadsAtMarker(g_Player2, squadName, "eldar_squad_banshees", markerName, 1) SGroup_AddLeaders(squadName)

	-- Banshee Squad was Created
	return true
end

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

end

-- Produce a Full Banshee Squad from Building at Marker for g_Player2 & Assign it to SGroup(squadName) if building exists function Rule_Produce_Banshees_Full(squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a squad of Banshee & give leader Util_CreateSquadsAtMarkerEx(g_Player2, squadName, "eldar_squad_banshees", markerName, 1, 10) SGroup_AddLeaders(squadName)

	-- Banshee Squad was Created
	return true
end

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

end

-- Produce a bonesinger (builder) from Building at Marker for g_Player2 & Assign it to SGroup(squadName) if building exists function Rule_Produce_Bonesinger(squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a squad of bonesinger & return "true" Util_CreateSquadsAtMarker(g_Player2, squadName, "eldar_squad_bonesinger_sp_dxp3", markerName, 1) return true end

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

end

-- Produce a Dark Reapers Squad from Building at Marker for g_Player2 & Assign it to SGroup(squadName) if building exists function Rule_Produce_DarkReapers(squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a squad of Dark Reapers & return "true" Util_CreateSquadsAtMarker(g_Player2, squadName, "eldar_squad_dark_reapers", markerName, 1) SGroup_AddLeaders(squadName) return true end

-- Dark Reapers squad not created since building doesn't exist
return false

end

-- Produce a Dark Reapers Squad from Building at Marker for g_Player2 & Assign it to SGroup(squadName) if building exists function Rule_Produce_DarkReapers_Full(squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a squad of Dark Reapers & return "true" Util_CreateSquadsAtMarkerEx(g_Player2, squadName, "eldar_squad_dark_reapers", markerName, 1, 6) SGroup_AddLeaders(squadName) return true end

-- Dark Reapers squad not created since building doesn't exist
return false

end

-- Produce a Falcon Grav Tank from Building at Marker for g_Player2 & Assign it to SGroup(squadName) if building exists function Rule_Produce_FalconGravTank(squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a Falcon Grav Tank & return "true" Util_CreateSquadsAtMarker(g_Player2, squadName, "eldar_squad_falcon_grav_tank_sp_dxp3", markerName, 1)

	-- Add Upgrade Here
	
	return true
end

-- Falcon Grav Tank not created since building doesn't exist
return false

end

-- Produce a Farseer from Building at Marker for g_Player2 & Assign it to SGroup(squadName) if building exists function Rule_Produce_Farseer(squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a Farseer & return "true" Util_CreateSquadsAtMarker(g_Player2, squadName, "eldar_squad_farseer", markerName, 1) return true end

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

end

-- Produce a FireDragon from Building at Marker for g_Player2 & Assign it to SGroup(squadName) if building exists function Rule_Produce_FireDragon(squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a squad of Fire Dragon & return "true" Util_CreateSquadsAtMarker(g_Player2, squadName, "eldar_squad_fire_dragon", markerName, 1) SGroup_AddLeaders(squadName) return true end

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

end

-- Produce a FireDragon from Building at Marker for g_Player2 & Assign it to SGroup(squadName) if building exists function Rule_Produce_FireDragon_Full(squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a squad of Fire Dragon & return "true" Util_CreateSquadsAtMarkerEx(g_Player2, squadName, "eldar_squad_fire_dragon", markerName, 1, 6) SGroup_AddLeaders(squadName) return true end

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

end

-- Produce a FirePrism from Building at Marker for g_Player2 & Assign it to SGroup(squadName) if building exists function Rule_Produce_FirePrism(squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a FirePrism & return "true" Util_CreateSquadsAtMarker(g_Player2, squadName, "eldar_squad_fire_prism_sp_dxp3", markerName, 1) return true end

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

end

-- Produce a Grav Platform from Building at Marker for g_Player2 & Assign it to SGroup(squadName) if building exists function Rule_Produce_GravPlatform(squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a Grav Platform & return "true" Util_CreateSquadsAtMarker(g_Player2, squadName, "eldar_squad_grav_platform", markerName, 1) --SGroup_AddLeaders(squadName) return true end

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

end

-- Produce a Grav Platform (Brightlance Version) from Building at Marker for g_Player2 & Assign it to SGroup(squadName) if building exists function Rule_Produce_GravPlatform_Brightlance(squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a squad of GravPlatform_Brightlance & return "true" Util_CreateSquadsAtMarker(g_Player2, squadName, "eldar_squad_grav_platform_brightlance", markerName, 1) --SGroup_AddLeaders(squadName) return true end

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

end

-- Produce a Guardian from Building at Marker for g_Player2 & Assign it to SGroup(squadName) if building exists function Rule_Produce_Guardian(squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a squad of Guardian & return "true" Util_CreateSquadsAtMarker(g_Player2, squadName, "eldar_guardian_squad", markerName, 1) SGroup_AddLeaders(squadName) return true end

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

end

-- Produce a Guardian from Building at Marker for g_Player2 & Assign it to SGroup(squadName) if building exists function Rule_Produce_Guardian_Full(squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a squad of Guardian & return "true" Util_CreateSquadsAtMarkerEx(g_Player2, squadName, "eldar_guardian_squad", markerName, 1, 9) SGroup_AddLeaders(squadName) return true end

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

end

-- Produce a Harlequin from Building at Marker for g_Player2 & Assign it to SGroup(squadName) if building exists function Rule_Produce_Harlequin(squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a Harlequin & return "true" Util_CreateSquadsAtMarker(g_Player2, squadName, "eldar_harlequin_squad", markerName, 1) return true end

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

end

-- Produce a Nightwing from Building at Marker for g_Player2 & Assign it to SGroup(squadName) if building exists function Rule_Produce_Nightwing(squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a Nightwing & return "true" Util_CreateSquadsAtMarker(g_Player2, squadName, "eldar_squad_nightwing", markerName, 1) return true end

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

end

-- Produce a Nightwing from Building at Marker for g_Player2 & Assign it to SGroup(squadName) if building exists function Rule_Produce_Nightwing_Elite(squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a Nightwing & return "true" Util_CreateSquadsAtMarker(g_Player2, squadName, "eldar_squad_nightwing_elite_sp_dxp3", markerName, 1) return true end

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

end

-- Produce a Rangers from Building at Marker for g_Player2 & Assign it to SGroup(squadName) if building exists function Rule_Produce_Rangers(squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a squad of Rangers & return "true" Util_CreateSquadsAtMarker(g_Player2, squadName, "eldar_squad_rangers", markerName, 1) return true end

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

end

-- Produce a Rangers from Building at Marker for g_Player2 & Assign it to SGroup(squadName) if building exists function Rule_Produce_Rangers_Full(squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a squad of Rangers & return "true" Util_CreateSquadsAtMarkerEx(g_Player2, squadName, "eldar_squad_rangers", markerName, 1, 8) return true end

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

end

-- Produce a Seer Council from Building at Marker for g_Player2 & Assign it to SGroup(squadName) if building exists function Rule_Produce_SeerCouncil(squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a squad ofSeer Council & return "true" Util_CreateSquadsAtMarker(g_Player2, squadName, "eldar_squad_seer_council", markerName, 1) return true end

-- Seer Council squad not created since building doesn't exist
return false

end

-- Produce a Seer Council from Building at Marker for g_Player2 & Assign it to SGroup(squadName) if building exists function Rule_Produce_SeerCouncil_Full(squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a squad ofSeer Council & return "true" Util_CreateSquadsAtMarkerEx(g_Player2, squadName, "eldar_squad_seer_council", markerName, 1, 9) return true end

-- Seer Council squad not created since building doesn't exist
return false

end

-- Produce a Vyper from Building at Marker for g_Player2 & Assign it to SGroup(squadName) if building exists function Rule_Produce_Vyper(squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a Vyper & return "true" Util_CreateSquadsAtMarker(g_Player2, squadName, "eldar_squad_vypers_sp_dxp3", markerName, 1) return true end

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

end

-- Produce a Vyper from Building at Marker for g_Player2 & Assign it to SGroup(squadName) if building exists function Rule_Produce_WarpSpider(squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a WarpSpider & return "true" Util_CreateSquadsAtMarker(g_Player2, squadName, "eldar_squad_warp_spider_sp_dxp3", markerName, 1) SGroup_AddLeaders(squadName) return true end

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

end

-- Produce a Wraith Lord from Building at Marker for g_Player2 & Assign it to SGroup(squadName) if building exists function Rule_Produce_WraithLord(squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a WraithLord, Add Upgrade & return "true" Util_CreateSquadsAtMarker(g_Player2, squadName, "eldar_squad_wraithlord", markerName, 1) Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName(squadName), 1),"eldar_brightlance_wraithlord", 1) return true end

-- Wraith Lord not created since building doesn't exist
return false

end


-- END OF ALL " UNIT PRODUCTION " RULES


-- LEVEL FLOW -- Center Base Teleporting & Attacking with North / South Base -- Rule_PreTeleport_CenterBase() : Play IE & Produce 1st Group of Troops in the Pre-Teleport Location of Center Base -- Rule_Check_For_Center_Base_Damage() : Check for the Player Damaging the CenterBase (so we know when to warp out & spring the trap) -- Rule_SpringTrap_PartOne() : Part One: Relocate Center Base to New Location -- Rule_SpringTrap_PartTwo() : Part Two: Teleporting Finished -- Give Player Base & Assign Objective

-- Center Base Destruction : Reveal Main Base, Holorock generators etc
	-- Rule_CenterBase_Destroyed() : Center Base has been destroyed, reveal Main Base

-- Cloak all the bases -- so they appear correctly during the intro NIS function Rule_Initial_Base_Cloak() -- Shroud the Webway Gates (3-4) at the teleport location -- Will Unshroud when the Base Teleports to this location for i = 3, 4 do EGroup_Shroud("eg_centerBase_webwayGate"..i,true) end

-- Shroud  all the webway gates
	-- 12- 20 start as rocks & appear later in game
for i = 1, 11 do
	EGroup_Shroud("eg_cloaked_webwayGate"..i,true)
end

-- Shroud  the Webway Gates
for i = 1, 4 do
	EGroup_Shroud("eg_northBase_webwayGate"..i,true)
end

-- Shroud the Webway Gates
for i = 1, 4 do
	EGroup_Shroud("eg_southBase_webwayGate"..i,true)
end

end

-- Play IE & Produce 1st Group of Troops in the Pre-Teleport Location of Center Base function Rule_PreTeleport_CenterBase() -- Once Player Gets Close to CenterBase if Player_AreSquadsNearMarker(g_Player1, "mkr_centerBase_HQ1") then -- Play IE: Util_StartIntel(EVENTS.IE_Player_Nears_CenterBase)

	-- Produce First Group of Troops 
	Rule_Produce_Guardian_Full("sg_centerBase_guardian1", "eg_centerBase_HQ", "mkr_centerBase_HQ1")
	g_centerBase_guardian_status[1] = g_squad_produced
	
	-- Assign Target for the Squad
	g_attack_target = Marker_GetPosition(Marker_FromName("mkr_honorGuard_Location", "basic_marker"))
	
	Rule_Remove( Rule_PreTeleport_CenterBase)
end

end

-- Check for the Player Damaging the CenterBase (so we know when to warp out & spring the trap) function Rule_Check_For_Center_Base_Damage() -- Reveal FOW around the Base so the player can see what they need to attack FOW_RevealMarker("mkr_centerBase_HQ1", 60)

-- Spring Based on HQ Damage (less than 99% life)
if EGroup_Exists("eg_centerBase_HQ") and
	EGroup_IsUnderAttack("eg_centerBase_HQ", false) == true
	--EGroup_GetAvgHealth("eg_centerBase_HQ") <= .99
then
	-- Make Buildings Invulnurable: 
	--EGroup_SetHealthInvulnerable("eg_centerBase_HQ", true)
	--EGroup_SetHealthInvulnerable("eg_centerBase_aspectPortal", true)
	--EGroup_SetHealthInvulnerable("eg_centerBase_supportPortal", true)
	
	-- Play IE Here (Relocate the Center Base)
	Util_StartIntel(EVENTS.IE_BeginTeleport_CenterBase )
	
	-- Reveal FOW around New CenterBase Location
	FOW_RevealMarker("mkr_centerBase_underAttack", 60)
	
	-- Uncloak the Webway Gates at the New CenterBase Location
	EGroup_Shroud("eg_centerBase_webwayGate3",false)
	EGroup_Shroud("eg_centerBase_webwayGate4",false)
	
	-- Remove the Rule & Check for Warp Completion 
	Rule_AddOneShot(Rule_SpringTrap_PartOne,1)
	Rule_Remove(Rule_Check_For_Center_Base_Damage)

-- Spring Based on Aspect Portal Damage (less than 99% life)
elseif EGroup_Exists("eg_centerBase_aspectPortal") and
	EGroup_IsUnderAttack("eg_centerBase_aspectPortal", false) == true
	--EGroup_GetAvgHealth("eg_centerBase_aspectPortal") <= .99
then
	-- Make Buildings Invulnurable: 
	--EGroup_SetHealthInvulnerable("eg_centerBase_HQ", true)
	--EGroup_SetHealthInvulnerable("eg_centerBase_aspectPortal", true)
	--EGroup_SetHealthInvulnerable("eg_centerBase_supportPortal", true)
	
	-- Play IE Here (Relocate the Center Base)
	Util_StartIntel(EVENTS.IE_BeginTeleport_CenterBase )
	
	-- Reveal FOW around New CenterBase Location
	FOW_RevealMarker("mkr_centerBase_underAttack", 60)
	
	-- Uncloak the Webway Gates at the New CenterBase Location
	EGroup_Shroud("eg_centerBase_webwayGate3",false)
	EGroup_Shroud("eg_centerBase_webwayGate4",false)
	
	-- Remove the Rule & Check for Warp Completion
	Rule_AddOneShot(Rule_SpringTrap_PartOne,1)
	Rule_Remove(Rule_Check_For_Center_Base_Damage)

-- Spring Based on Support Portal Damage (less than 99% life)
elseif EGroup_Exists("eg_centerBase_supportPortal") and
	EGroup_IsUnderAttack("eg_centerBase_supportPortal", false) == true
	--EGroup_GetAvgHealth("eg_centerBase_supportPortal") <= .99
then
	-- Make Buildings Invulnurable: 
	--EGroup_SetHealthInvulnerable("eg_centerBase_HQ", true)
	--EGroup_SetHealthInvulnerable("eg_centerBase_aspectPortal", true)
	--EGroup_SetHealthInvulnerable("eg_centerBase_supportPortal", true)
	
	-- Play IE Here (Relocate the Center Base)
	Util_StartIntel(EVENTS.IE_BeginTeleport_CenterBase )
	
	-- Reveal FOW around New CenterBase Location
	FOW_RevealMarker("mkr_centerBase_underAttack", 60)
	
	-- Uncloak the Webway Gates at the New CenterBase Location
	EGroup_Shroud("eg_centerBase_webwayGate3",false)
	EGroup_Shroud("eg_centerBase_webwayGate4",false)
	
	-- Remove the Rule & Check for Warp Completion
	Rule_AddOneShot(Rule_SpringTrap_PartOne,1)
	Rule_Remove(Rule_Check_For_Center_Base_Damage)
	
-- Spring Based on First Support Platform Damage (less than 25% life)
elseif EGroup_Exists("eg_centerBase_supportPlatform4") and
	EGroup_GetAvgHealth("eg_centerBase_supportPlatform4") <= .25
then
	-- Make Buildings Invulnurable: 
	--EGroup_SetHealthInvulnerable("eg_centerBase_HQ", true)
	--EGroup_SetHealthInvulnerable("eg_centerBase_aspectPortal", true)
	--EGroup_SetHealthInvulnerable("eg_centerBase_supportPortal", true)
	
	-- Play IE Here (Relocate the Center Base)
	Util_StartIntel(EVENTS.IE_BeginTeleport_CenterBase )
	
	-- Reveal FOW around New CenterBase Location
	FOW_RevealMarker("mkr_centerBase_underAttack", 60)
	
	-- Uncloak the Webway Gates at the New CenterBase Location
	EGroup_Shroud("eg_centerBase_webwayGate3",false)
	EGroup_Shroud("eg_centerBase_webwayGate4",false)
	
	-- Remove the Rule & Check for Warp Completion
	Rule_AddOneShot(Rule_SpringTrap_PartOne,1)
	Rule_Remove(Rule_Check_For_Center_Base_Damage)
end

end

-- Part One: Relocate Center Base to New Location function Rule_SpringTrap_PartOne() -- Relocate the HQ, Aspect Portal, & Support Portal Cmd_EGroupRelocateMarker("eg_centerBase_HQ", "mkr_tp_centerBase_HQ1", 5) Cmd_EGroupRelocateMarker("eg_centerBase_aspectPortal", "mkr_tp_centerBase_aspectPortal1", 5) Cmd_EGroupRelocateMarker("eg_centerBase_supportPortal", "mkr_tp_centerBase_supportPortal1", 5)

-- Relocate Any Warp Generators & Support Platforms that Still Exist
for i = 1,4 do
	-- If Warp Generator still exists, then warp it to the new location
	if EGroup_Count("eg_centerBase_warpGenerator"..i) == 1
	then
		Cmd_EGroupRelocateMarker("eg_centerBase_warpGenerator"..i, "mkr_tp_centerBase_warpGenerator"..i, 5)
	end
	
	-- If Support Platform still exists, then warp it to the new location
	if EGroup_Count("eg_centerBase_supportPlatform"..i) == 1
	then
		Cmd_EGroupRelocateMarker("eg_centerBase_supportPlatform"..i, "mkr_tp_centerBase_supportPlatform"..i, 5)
	end
end

-- Begin Checking for Part Two of the Trap
Rule_AddInterval(Rule_SpringTrap_PartTwo,1)	

end

-- Part Two: Teleporting Finished -- Give Player Base & Assign Objective function Rule_SpringTrap_PartTwo() -- Check if the CenterBase has Finished Relocating if EGroup_IsRelocating("eg_centerBase_HQ",true) == false and EGroup_IsRelocating("eg_centerBase_aspectPortal",true) == false and EGroup_IsRelocating("eg_centerBase_supportPortal",true) == false then -- Remove the Rule Since Base has finished Relocating & Trap is firing Rule_Remove(Rule_SpringTrap_PartTwo)

	-- Make Buildings Vulnurable Again: 
	EGroup_SetHealthInvulnerable("eg_centerBase_HQ", false)
	EGroup_SetHealthInvulnerable("eg_centerBase_aspectPortal", false)
	EGroup_SetHealthInvulnerable("eg_centerBase_supportPortal", false)
	
	--Cloak the Webway Gates that are still in player base if they are still alive
	if EGroup_Count("eg_centerBase_webwayGate1") == 1 then
		EGroup_Shroud("eg_centerBase_webwayGate1", true)
	end
	if EGroup_Count("eg_centerBase_webwayGate1") == 1 then
		EGroup_Shroud("eg_centerBase_webwayGate2", true)
	end
	
	-- Play IE: Give Player their base & builders
	Util_StartIntel(g_ie_GivePlayerBase_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 player HQ (at 0% so it plays arrival animation)
	User_CreateBuilding(g_Player1,"eg_player_mainBase_HQ", g_HQ_blueprint,"mkr_player_mainBase_HQ",0)
	
	-- Give the Player all forward base buidings
	ForwardBases()
	
	-- Complete the HQ & Forward Bases (They start at 0 for so they play arrival animation)
	Rule_AddOneShot(Rule_Complete_Player_Buildings, 5)
	
	-- Swap the defeat rule -- new one doesn't care about units just buildings
	Rule_Remove(Rule_EndGame_Defeat_Early)
	Rule_AddIntervalDelay(Rule_EndGame_Defeat, 1,30)
	
	-- Order the builders to walk towards the HQ
	Cmd_MoveToMarker("sg_player_mainBase_builder", "mkr_player_mainBase_HQ")
	
	-- Assign Primary Sub-Objective to Destroy Relocated HQ
	Rule_AddIntervalDelay(Rule_DestroyRelocatedEldarHQ_Objective,1,5)
	
	-- Check for Super Turret Damage so can assign objective
	Rule_AddInterval(Rule_Track_Super_Turret_Damage,2)
	
	-- Spawn in Base Defenders for the Three Bases: Center, North, South
	Rule_Create_Defending_Troops_WaveOne()
	
	-- Reveal bases, send first attacks, assign objectives
	Rule_AddOneShot(Rule_Upgrade_To_Alert_Zero,30)
end	

end

-- Center Base has been destroyed, reveal Main Base function Rule_CenterBase_Destroyed() -- Remove the "Rocks" that are hiding the Main Base & West Base EGroup_DeSpawn("eg_hologramRocks_MainBase") EGroup_DeSpawn("eg_hologramRocks_WestBase")

-- Create the Main Base & West Base
Rule_Create_MainBase_Buildings()
Rule_Create_WestBase_Buildings()

-- Create Some Basic Defense for the Bases
Rule_Create_Defending_Troops_WaveTwo()

--Check for Early Attack & Cloaking of Main Base
Rule_AddInterval(Rule_Check_EarlyPlayer_Attack_Main_Base, 3)
Rule_AddInterval(Rule_Cloak_Main_Base,3)

-- Activate Another Batch of Webway Gates:
g_webway_activated[9]		= true
g_webway_activated[10]	= true

-- Allow two webway squads to produce at once
g_webway_numSquads	=	2

-- Assign Sub-Primary Objective: Kill Main HQ
Rule_AddInterval(Rule_DestroyRealEldarHQ_Objective,2)

for i = 12,14 do
	-- Remove the Holorocks that were covering up the webway gates
	EGroup_DeSpawn("eg_cloaked_webwayGateRock"..i)
	
	-- Spawn in, Cloak, & Activate the Webway Gates by the Generators
	User_CreateBuilding(g_Player2,"eg_cloaked_webwayGate"..i, "eldar_webway_gate","mkr_cloaked_webwayGate"..i, 1)
	EGroup_Shroud("eg_cloaked_webwayGate"..i,true)
	g_webway_activated[i] = true
end

end


-- END OF ALL " LEVEL FLOW " RULES


-- BASE ACTIVATION, PRODUCTION, & ATTACKS -- Rule_Create_Attacks() : Creates the SGroups Used by all the bases & Adds Patrol & Tactics Rules -- Rule_Sync_Attacks() : Syncs All Attacks from the Same Point in Time -- Rule_Create_Defending_Troops_WaveOne() : Create a few squads of troops to protect Center, North, & South Bases from early attacks -- Rule_Create_Defending_Troops_WaveTwo() : Create a few squads of troops to protect West & Main Bases (& Webway Gates) from early attacks

-- Center Base:
	-- Rule_Cloak_Center_Base() : Checks for & Cloaks the Base if the Player Units Attack
	-- Rule_Check_EarlyPlayer_Attack_Center_Base() : Checks if the Player Attacks the Base before Vypers have been activated
	-- Rule_Production_Center_Base() : Handles Production of Units (dark reapers, vypers, & guardians)

-- Main Base
	-- Rule_Cloak_Main_Base() : Checks for & Cloaks the Base if the Player Units Attack
	-- Rule_Check_EarlyPlayer_Attack_Main_Base() : Checks if the Player Attacks the Base before it has been activated fully
	-- Rule_Production_Main_Base() : Handles Production of Units ( Fire Prism, WraithLord, Avatar, Fire Dragon, Dark Reapers, Banshee)

-- North Base:
	-- Rule_Cloak_North_Base() : Checks for & Cloaks the Base if the Player Units Attack
	-- Rule_Check_EarlyPlayer_Attack_North_Base() : Checks if the Player Attacks the Base before it has been activated fully
	-- Rule_Production_North_Base() : Handles Production of Units (Nightwing & Dark Reapers)

-- South Base:
	-- Rule_Cloak_South_Base() : Checks for & Cloaks the Base if the Player Units Attack
	-- Rule_Check_EarlyPlayer_Attack_South_Base() : Checks if the Player Attacks the Base before it has been activated
	-- Rule_Production_South_Base() : Handles Production of Units ( Ranger Patrols, Warp Spiders, & Guardians)
	-- Rule_SouthBase_Ranger_Patrol_One() : SouthBase: Ranger Squad One Patrols from 1,2,3,4,1
	-- Rule_SouthBase_Ranger_Patrol_Two() : SouthBase: Ranger Squad Two Patrols from 4,3,5,6,2,1,4

-- West Base:
	-- Handles Production of Units (Banshees & WraithLord)

-- Cloaked Webway Gates
	-- Rule_Check_EarlyPlayer_Attack_Webway() : Activate the webway Gates Earlier if the Player decloacks them
	-- Rule_Initial_Webway_Production() : Controls the Initial Webway Gates that are in Player Base
	-- Rule_Cloaked_Webway_Production() : Handles Production of Units (banshees, dark reapers, fire dragons, guardians & rangers)

-- Creates the SGroups Used by all the bases & Adds Patrol & Tactics Rules -- Attacks are synced seperatly to delay them until the center base teleports out function Rule_Create_Attacks() -- Target Location for when a squad is told to retreat (Retreat Toward Center Base HQ) g_retreat_target = Marker_GetPosition(Marker_FromName("mkr_tp_centerBase_HQ1", "basic_marker"))

-- Default Attack Target (Changes During Mission)
g_attack_target = Marker_GetPosition(Marker_FromName("mkr_player_mainBase_HQ", "basic_marker"))

-- Grant Fleet of Foot Research
Player_GrantResearch(g_Player2, "eldar_fleet_of_foot_research")	

-- SGroup & EGroup 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")

-- Create the SGroups for the Center Base
SGroup_Create("sg_centerBase_darkreaper1")
SGroup_Create("sg_centerBase_guardian1")
SGroup_Create("sg_centerBase_vyper1")

-- Create the SGroup to Track Elite Nightwings
SGroup_Create("sg_eliteNightwings")

-- Create the SGroups for the Main Base	
SGroup_Create("sg_mainBase_avatar")
SGroup_Create("sg_mainBase_fireDragon")
SGroup_Create("sg_mainBase_banshee")
SGroup_Create("sg_mainBase_darkreapers")

SGroup_Create("sg_mainBase_firePrism1")
SGroup_Create("sg_mainBase_firePrism2")
SGroup_Create("sg_mainBase_wraithLord1")
SGroup_Create("sg_mainBase_wraithLord2")

-- Create the SGroups for the North Base
SGroup_Create("sg_northBase_falconGravTank1")
SGroup_Create("sg_northBase_falconGravTank2")
SGroup_Create("sg_northBase_nightwing1")
SGroup_Create("sg_northBase_nightwing2")
SGroup_Create("sg_northBase_darkreaper1")
SGroup_Create("sg_northBase_darkreaper2")

-- Create the SGroups for the South Base
SGroup_Create("sg_southBase_guardian1")
SGroup_Create("sg_southBase_rangers1")
SGroup_Create("sg_southBase_rangers2")
SGroup_Create("sg_southBase_warpspider1")

-- Create the SGroups for the West Base
SGroup_Create("sg_westBase_banshee1")
SGroup_Create("sg_westBase_wraithLord1")

-- Create the SGroups for the Cloaked Webway Gates
SGroup_Create("sg_webway_banshees1")
SGroup_Create("sg_webway_banshees2")	
SGroup_Create("sg_webway_darkreaper1")
SGroup_Create("sg_webway_darkreaper2")	
SGroup_Create("sg_webway_firedragon1")
SGroup_Create("sg_webway_firedragon2")	
SGroup_Create("sg_webway_guardian1")
SGroup_Create("sg_webway_guardian2")	
SGroup_Create("sg_webway_rangers1")
SGroup_Create("sg_webway_rangers2")

SGroup_Create("sg_webway_wraithLord")

-- Add the Patrol Routes for the SouthBase Rangers 
Rule_AddInterval(Rule_SouthBase_Ranger_Patrol_One, 3)
Rule_AddInterval(Rule_SouthBase_Ranger_Patrol_Two, 3)

-- SQUAD TACTICS
Rule_AddInterval(Rule_Squad_Tactics_Helper,5)

-- Provides Some Random Movement & Life to the Bases
Rule_AddInterval(Rule_RandomMovement_Base,10)

end

-- Syncs All Attacks from the Same Point in Time function Rule_Sync_Attacks() -- Sync the Production Rules for the Bases (Bases won't actually produce / attack until they activate) Rule_AddInterval(Rule_Production_Center_Base, g_timer_centerBase) Rule_AddInterval(Rule_Production_Main_Base, g_timer_mainBase) Rule_AddInterval(Rule_Production_North_Base, g_timer_northBase) Rule_AddInterval(Rule_Production_South_Base, g_timer_southBase) Rule_AddInterval(Rule_Production_West_Base, g_timer_westBase) Rule_AddInterval(Rule_Cloaked_Webway_Production, g_timer_webway) Rule_AddInterval(Rule_Initial_Webway_Production, g_timer_initialWebway) end

-- Create a few squads of troops to protect Center, North, & South Bases from early attacks function Rule_Create_Defending_Troops_WaveOne() -- Produce Some Defending WraithLords, Banshees, Grav Platforms, Grav Platform (Brightlance) & Seer Council (Cloak Detect) for Center Base Rule_Produce_WraithLord("sg_centerBase_defender1", "eg_centerBase_HQ", "mkr_tp_centerBase_HQ1") Rule_Produce_WraithLord("sg_centerBase_defender2", "eg_centerBase_HQ", "mkr_tp_centerBase_HQ1") Rule_Produce_Banshees_Full("sg_centerBase_defender3", "eg_centerBase_HQ", "mkr_tp_centerBase_HQ1") Rule_Produce_SeerCouncil_Full("sg_centerBase_defender4", "eg_centerBase_HQ", "mkr_tp_centerBase_HQ1") Rule_Produce_GravPlatform("sg_centerBase_defender5", "eg_centerBase_HQ", "mkr_tp_centerBase_HQ1") Rule_Produce_GravPlatform("sg_centerBase_defender6", "eg_centerBase_HQ", "mkr_tp_centerBase_HQ1") Rule_Produce_GravPlatform_Brightlance("sg_centerBase_defender7", "eg_centerBase_HQ", "mkr_tp_centerBase_HQ1") Rule_Produce_GravPlatform_Brightlance("sg_centerBase_defender8", "eg_centerBase_HQ", "mkr_tp_centerBase_HQ1")

-- Produce Some Defending WraithLords, Banshees, & Seer Council (Cloak Detect) for North Base
Rule_Produce_WraithLord("sg_northBase_defender1", "eg_centerBase_HQ", "mkr_northBase_soulShrine1")
Rule_Produce_WraithLord("sg_northBase_defender2", "eg_centerBase_HQ", "mkr_northBase_soulShrine1")
Rule_Produce_Banshees_Full("sg_northBase_defender3", "eg_centerBase_HQ", "mkr_northBase_soulShrine1")
Rule_Produce_SeerCouncil_Full("sg_northBase_defender4", "eg_centerBase_HQ", "mkr_northBase_soulShrine1")
Rule_Produce_Nightwing("sg_northBase_defender5", "eg_centerBase_HQ", "mkr_northBase_soulShrine1")
Rule_Produce_Nightwing("sg_northBase_defender6", "eg_centerBase_HQ", "mkr_northBase_soulShrine1")

-- Produce Some defending WraithLords, Banshees, & Seer Council (Cloak Detect) for South Base
Rule_Produce_WraithLord("sg_southBase_defender1", "eg_centerBase_HQ", "mkr_southBase_HQ1")
Rule_Produce_WraithLord("sg_southBase_defender2", "eg_centerBase_HQ", "mkr_southBase_HQ1")
Rule_Produce_Banshees_Full("sg_southBase_defender3", "eg_centerBase_HQ", "mkr_southBase_HQ1")
Rule_Produce_SeerCouncil_Full("sg_southBase_defender4", "eg_centerBase_HQ", "mkr_southBase_HQ1")

end

-- Create a few squads of troops to protect West & Main Bases (& Webway Gates) from early attacks function Rule_Create_Defending_Troops_WaveTwo() -- Create the Elite Night Wing Squadron for i =1,g_number_EliteNightwings do Rule_Produce_Nightwing_Elite("sg_elite_nightwing"..i, "eg_HQinMainBase_Objective", "mkr_mainBase_webwayGate5") SGroup_AddGroup("sg_eliteNightwings", "sg_elite_nightwing"..i) end

-- Add the rules to track for elite nightwing contact & destruction
Rule_AddInterval(Rule_IE_Elite_Nightwing_Contact, 1)
Rule_AddInterval(Rule_IE_Elite_Nightwing_Destroyed, 1)

-- Produce Some Defending WraithLords, Rangers, & Fire Prism for Main Base
Rule_Produce_WraithLord("sg_mainBase_defender1", "eg_HQinMainBase_Objective", "mkr_mainBase_webwayGate5")
Rule_Produce_WraithLord("sg_mainBase_defender2", "eg_HQinMainBase_Objective", "mkr_mainBase_webwayGate5")
Rule_Produce_Rangers_Full("sg_mainBase_defender3", "eg_HQinMainBase_Objective", "mkr_mainBase_webwayGate5")
Rule_Produce_Rangers_Full("sg_mainBase_defender4", "eg_HQinMainBase_Objective", "mkr_mainBase_webwayGate5")
Rule_Produce_FirePrism("sg_mainBase_defender5", "eg_HQinMainBase_Objective", "mkr_mainBase_webwayGate5")
Rule_Produce_GravPlatform("sg_mainBase_defender6", "eg_HQinMainBase_Objective", "mkr_mainBase_webwayGate5")
Rule_Produce_GravPlatform("sg_mainBase_defender7", "eg_HQinMainBase_Objective", "mkr_mainBase_webwayGate5")
Rule_Produce_GravPlatform_Brightlance("sg_mainBase_defender8", "eg_HQinMainBase_Objective", "mkr_mainBase_webwayGate5")
Rule_Produce_GravPlatform_Brightlance("sg_mainBase_defender9", "eg_HQinMainBase_Objective", "mkr_mainBase_webwayGate5")

-- Produce Some Defending WraithLords, Fire Prism, & Seer Council (Cloak Detect) for West Base
Rule_Produce_WraithLord("sg_westBase_defender1", "eg_HQinMainBase_Objective", "mkr_westBase_supportPortal1")
Rule_Produce_WraithLord("sg_westBase_defender2", "eg_HQinMainBase_Objective", "mkr_westBase_supportPortal1")
Rule_Produce_FirePrism("sg_westBase_defender3", "eg_HQinMainBase_Objective", "mkr_westBase_supportPortal1")
Rule_Produce_SeerCouncil_Full("sg_westBase_defender4", "eg_HQinMainBase_Objective", "mkr_westBase_supportPortal1")

end

-- Center Base

-- Checks for & Cloaks the Base if the Player Units Attack function Rule_Cloak_Center_Base() --is the base already cloaked? if g_base_cloaked_Center == false then -- if not...Check if the Player is attacking the base if Player_AreSquadsNearMarker(g_Player1, "mkr_centerBase_underAttack") then -- Count How many play units are at that marker Player_GetAllSquadsNearMarker(g_Player1, "sg_NearMarker", "mkr_centerBase_underAttack") local unitCount = SGroup_Count("sg_NearMarker") SGroup_Clear("sg_NearMarker")

		--is it enough units to cloak a base?
		if unitCount >= g_num_PlayerUnits_ActivateBase
		then
				-- if a webway gate exists in the base, enable its cloak
				for i = 3, 4 do
					if EGroup_Count("eg_centerBase_webwayGate"..i) == 1
					then
						EGroup_Shroud("eg_centerBase_webwayGate"..i,true)
					end
				end
				-- Base is now cloaked
				g_base_cloaked_Center = true
		end
	end

-- Remove the Rule since the base is already cloaked
else
	Rule_Remove(Rule_Cloak_Center_Base)
end

end

-- Checks if the Player Attacks the Base before Vypers have been activated function Rule_Check_EarlyPlayer_Attack_Center_Base() -- Checks if the Base is already activated if g_base_activated_Center_Vyper == false then -- if not...Check if the Player is attacking the base if Player_AreSquadsNearMarker(g_Player1, "mkr_centerBase_underAttack") then -- Count How many play units are at that marker Player_GetAllSquadsNearMarker(g_Player1, "sg_NearMarker", "mkr_centerBase_underAttack") local unitCount = SGroup_Count("sg_NearMarker") SGroup_Clear("sg_NearMarker")

		--is it enough units to activate a base?
		if unitCount >= g_num_PlayerUnits_ActivateBase
		then
			-- Activate the Center Base Instantly
			g_base_activated_Center_Vyper = true
			g_base_activated_Center = true
		end
	end

-- Remove the Rule since the base is already activated
else
	Rule_Remove(Rule_Check_EarlyPlayer_Attack_Center_Base)
end

end

-- Handles Production of Units (dark reapers, vypers, & guardians) function Rule_Production_Center_Base() local centerBase_troopsProduced = false local centerBase_vehicleProduced = false

-- Loop through all the possible centerBase_darkReaper Squads
for i =1,1	do
	-- If the SGroup is Not Currently Used...
	if g_base_activated_Center == true and 
		centerBase_troopsProduced == false and
		SGroup_Count("sg_centerBase_darkreaper"..i) == 0
	then
		-- Try to Produce a Dark Reapers squad from the Aspect Portal
		if Rule_Produce_DarkReapers("sg_centerBase_darkreaper"..i, "eg_centerBase_aspectPortal", "mkr_tp_centerBase_aspectPortal1") == true
		then
			centerBase_troopsProduced = true
			
			-- Reset Status (in case died while retreating etc...)
			g_centerBase_darkreaper_status[i] = g_squad_produced
		end
	end
end

centerBase_troopsProduced = false

-- Loop through all the possible centerBase_guardian Squads
for i =1,1	do
	-- If the SGroup is Not Currently Used...
	if g_base_activated_Center == true and 
		centerBase_troopsProduced == false and
		SGroup_Count("sg_centerBase_guardian"..i) == 0
	then
		-- Try to Produce a Guardian squad from the HQ
		if Rule_Produce_Guardian("sg_centerBase_guardian"..i, "eg_centerBase_HQ", "mkr_tp_centerBase_HQ1") == true
		then
			centerBase_troopsProduced = true
			
			-- Reset Status (in case died while retreating etc...)
			g_centerBase_guardian_status[i] = g_squad_produced
		end
	end
end

-- Loop through all the possible centerBase_vypers Squads
for i =1,1	do
	-- If the SGroup is not currently used...
	if g_base_activated_Center_Vyper == true and
		centerBase_vehicleProduced == false and
		SGroup_Count("sg_centerBase_vyper"..i) == 0
	then
		-- Try to Produce a Vyper from the Support Portal
		if Rule_Produce_Vyper("sg_centerBase_vyper"..i, "eg_centerBase_supportPortal", "mkr_tp_centerBase_supportPortal1") == true
		then
			centerBase_vehicleProduced = true
			
			-- Reset Status for Jumping
			g_centerBase_vyper_status[i] = g_squad_jump_prep
		end
	end
end

--if all production buildings are destroyed, remove rules since base is gone
if 	g_base_activated_Center == true and
	EGroup_Count("eg_centerBase_aspectPortal") == 0 and
	EGroup_Count("eg_centerBase_supportPortal") == 0 and
	EGroup_Count("eg_centerBase_HQ") == 0
then
	Rule_Remove(Rule_Production_Center_Base)
end

end

-- Main Base

-- Checks for & Cloaks the Base if the Player Units Attack function Rule_Cloak_Main_Base() --is the base already cloaked? if g_base_cloaked_Main == false then -- if not...Check if the Player is attacking the base if Player_AreSquadsNearMarker(g_Player1, "mkr_mainBase_webwayGate5") then -- Count How many play units are at that marker Player_GetAllSquadsNearMarker(g_Player1, "sg_NearMarker", "mkr_mainBase_webwayGate5") local unitCount = SGroup_Count("sg_NearMarker") SGroup_Clear("sg_NearMarker")

		--is it enough units to cloak a base?
		if unitCount >= g_num_PlayerUnits_ActivateBase
		then
			-- if a webway gate exists in the base, enable its cloak
			for i = 1, 5 do
				if EGroup_Count("eg_mainBase_webwayGate"..i) == 1
				then
					EGroup_Shroud("eg_mainBase_webwayGate"..i,true)
				end
			end
			-- Base is now cloaked
			g_base_cloaked_Main = true
		end
	end

-- Remove the Rule since the base is already cloaked
else
	Rule_Remove(Rule_Cloak_Main_Base)
end

end

-- Checks if the Player Attacks the Base before it has been activated fully function Rule_Check_EarlyPlayer_Attack_Main_Base() -- Checks if the Base is already activated if g_base_activated_Main == false then -- if not...Check if the Player is attacking the base if Player_AreSquadsNearMarker(g_Player1, "mkr_mainBase_webwayGate5") then -- Count How many play units are at that marker Player_GetAllSquadsNearMarker(g_Player1, "sg_NearMarker", "mkr_mainBase_webwayGate5") local unitCount = SGroup_Count("sg_NearMarker") SGroup_Clear("sg_NearMarker")

		--is it enough units to activate a base?
		if unitCount >= g_num_PlayerUnits_ActivateBase
		then
			-- Activate the Main Base Instantly
			g_base_activated_Main = true
		end
	end

-- Remove the Rule since the base is already activated
else
	Rule_Remove(Rule_Check_EarlyPlayer_Attack_Main_Base)
end

end

-- Handles Production of Units ( Fire Prism, WraithLord, Avatar, Fire Dragon, Dark Reapers, Banshee) function Rule_Production_Main_Base() -- Loop through all the Aspect Portals for i = 1,2 do -- if the Aspect Portal still exists & base activated if g_base_activated_Main == true and EGroup_Count("eg_mainBase_aspectPortal"..i) == 1 then -- Avatar if SGroup_Count("sg_mainBase_avatar") == 0 and Rule_Produce_Avatar("sg_mainBase_avatar", "eg_mainBase_aspectPortal"..i, "mkr_mainBase_aspectPortal"..i)

		then
			-- Only Attack the Player Base the First Time & Every Other Time
			if g_firstAvatar_attack == true
			then
				-- Reset Status (in case died while retreating etc...)
				g_mainBase_avatar_status[1] = g_squad_produced
				g_firstAvatar_attack = false
			
			else
				-- Just hang around & do nothing
				g_mainBase_avatar_status[1] = g_squad_idle
				g_firstAvatar_attack = true
			end
		
		-- Fire Dragons
		elseif SGroup_Count("sg_mainBase_fireDragon") == 0 and
			Rule_Produce_FireDragon("sg_mainBase_fireDragon", "eg_mainBase_aspectPortal"..i, "mkr_mainBase_aspectPortal"..i)
		then
			-- Reset Status (in case died while retreating etc...)
			g_mainBase_fireDragon_status[1] = g_squad_produced
		
		-- Banshee
		elseif SGroup_Count("sg_mainBase_banshee") == 0 and
			Rule_Produce_Banshees("sg_mainBase_banshee", "eg_mainBase_aspectPortal"..i, "mkr_mainBase_aspectPortal"..i)
		then
			-- Reset Status (in case died while retreating etc...)
			g_mainBase_banshee_status[1] = g_squad_produced
		
		-- Dark Reaper
		elseif SGroup_Count("sg_mainBase_darkreapers") == 0 and
			Rule_Produce_DarkReapers("sg_mainBase_darkreapers", "eg_mainBase_aspectPortal"..i, "mkr_mainBase_aspectPortal"..i)
		then
			-- Reset Status (in case died while retreating etc...)
			g_mainBase_darkreapers_status[1] = g_squad_produced
		end
	end
end

-- Harlequin from HQ

-- Loop through all the Support Portals
for i = 1,2 do
	-- if the Support Portal still exists & base activated
	if g_base_activated_Main == true and
		EGroup_Count("eg_mainBase_supportPortal"..i) == 1
	then
		-- Fire Prism Tank
		if SGroup_Count("sg_mainBase_firePrism1") == 0 and
			Rule_Produce_FirePrism("sg_mainBase_firePrism1", "eg_mainBase_supportPortal"..i, "mkr_mainBase_supportPortal"..i)
		then
			-- Reset Status (in case died while retreating etc...)
			g_mainBase_firePrism_status[1] = g_squad_produced
		
		-- WraithLord
		elseif SGroup_Count("sg_mainBase_wraithLord1") == 0 and
			Rule_Produce_WraithLord("sg_mainBase_wraithLord1", "eg_mainBase_supportPortal"..i, "mkr_mainBase_supportPortal"..i)
		then
			-- Reset Status (in case died while retreating etc...)
			g_mainBase_wraithLord_status[1] = g_squad_produced
		
		-- Fire Prism Tank 
		elseif SGroup_Count("sg_mainBase_firePrism2") == 0 and
			Rule_Produce_FirePrism("sg_mainBase_firePrism2", "eg_mainBase_supportPortal"..i, "mkr_mainBase_supportPortal"..i)
		then
			-- Reset Status (in case died while retreating etc...)
			g_mainBase_firePrism_status[2] = g_squad_produced
		
		-- WraithLord
		elseif SGroup_Count("sg_mainBase_wraithLord2") == 0 and
			Rule_Produce_WraithLord("sg_mainBase_wraithLord2", "eg_mainBase_supportPortal"..i, "mkr_mainBase_supportPortal"..i)
		then
			-- Reset Status (in case died while retreating etc...)
			g_mainBase_wraithLord_status[2] = g_squad_produced
		end
	end
end

--if aspect portals, support portals & hqs are destroyed, remove rules since base is gone
if 	g_base_activated_Main == true and
	EGroup_Count("eg_southBase_aspectPortal1") == 0 and
	EGroup_Count("eg_southBase_aspectPortal1") == 0 and
	EGroup_Count("eg_mainBase_supportPortal2") == 0 and
	EGroup_Count("eg_mainBase_supportPortal2") == 0 and
	EGroup_Count("eg_southBase_HQ") == 0
then
	Rule_Remove(Rule_Production_Main_Base)
end

end

-- North Base

-- Checks for & Cloaks the Base if the Player Units Attack function Rule_Cloak_North_Base() --is the base already cloaked? if g_base_cloaked_North == false then -- if not...Check if the Player is attacking the base if Player_AreSquadsNearMarker(g_Player1, "mkr_northBase_underAttack") then -- Count How many play units are at that marker Player_GetAllSquadsNearMarker(g_Player1, "sg_NearMarker", "mkr_northBase_underAttack") local unitCount = SGroup_Count("sg_NearMarker") SGroup_Clear("sg_NearMarker")

		--is it enough units to cloak a base?
		if unitCount >= g_num_PlayerUnits_ActivateBase
		then
				-- if a webway gate exists in the base, enable its cloak
				for i = 1, 4 do
					if EGroup_Count("eg_northBase_webwayGate"..i) == 1
					then
						EGroup_Shroud("eg_northBase_webwayGate"..i,true)
					end
				end
				-- Base is now cloaked
				g_base_cloaked_North = true
		end
	end

-- Remove the Rule since the base is already cloaked
else
	Rule_Remove(Rule_Cloak_North_Base)
end

end

-- Checks if the Player Attacks the Base before it has been activated fully function Rule_Check_EarlyPlayer_Attack_North_Base() -- Checks if the Base is already activated if g_base_activated_North_NightWing == false then -- if not...Check if the Player is attacking the base if Player_AreSquadsNearMarker(g_Player1, "mkr_northBase_underAttack") then -- Count How many play units are at that marker Player_GetAllSquadsNearMarker(g_Player1, "sg_NearMarker", "mkr_northBase_underAttack") local unitCount = SGroup_Count("sg_NearMarker") SGroup_Clear("sg_NearMarker")

		--is it enough units to activate a base?
		if unitCount >= g_num_PlayerUnits_ActivateBase
		then
			-- Activate the North Base Instantly (Both Land & Air)
			g_base_activated_North = true
			g_base_activated_North_NightWing = true
		end
	end

-- Remove the Rule since the base is already activated
else
	Rule_Remove(Rule_Check_EarlyPlayer_Attack_North_Base)
end

end

-- Handles Production of Units (Nightwing & Dark Reapers) function Rule_Production_North_Base() -- Loop through all the Support Portals for j = 1,2 do local northBase_nightwingProduced = false

	-- if the support portal still exists & base activated
	if g_base_activated_North_NightWing == true and
		EGroup_Count("eg_northBase_supportPortal"..j) == 1
	then
		-- Loop through all the possible sg_northBase_nightwing Squads
		for i =1,2	do
			-- If the SGroup is not currently used...
			if northBase_nightwingProduced == false and
				SGroup_Count("sg_northBase_nightwing"..i) == 0
			then
				-- Try to Produce a Nightwing from the Support Portal
				if Rule_Produce_Nightwing("sg_northBase_nightwing"..i, "eg_northBase_supportPortal"..j, "mkr_northBase_supportPortal"..j) == true
				then
					-- For Objective Assigning
					g_northBase_FirstNightwing_Produced = true
					
					northBase_nightwingProduced = true
					
					-- Reset Status (in case died while retreating etc...)
					g_northBase_nightwing_status[i] = g_squad_produced						
				end
			end
		end
	
	-- If Base is Activated, but not yet NightWing Activated -- Produce Falcon Grav Tanks
	elseif g_base_activated_North_NightWing ==false and
		g_base_activated_Center_Vyper == true and
		g_base_activated_North == true and
		EGroup_Count("eg_northBase_supportPortal"..j) == 1
	then
		-- Loop through all the possible sg_northBase_falconGravTank Squads
		for i =1,2	do
			-- If the SGroup is not currently used...
			if northBase_nightwingProduced == false and
				SGroup_Count("sg_northBase_falconGravTank"..i) == 0
			then
				-- Try to Produce a Falcon Grav Tank from teh Support Portal
				if Rule_Produce_FalconGravTank("sg_northBase_falconGravTank"..i, "eg_northBase_supportPortal"..j, "mkr_northBase_supportPortal"..j) == true
				then
					northBase_nightwingProduced = true
					
					-- Reset Status (in case died while retreating etc...)
					g_northBase_falconGravTank_status[i] = g_squad_produced						
				end
			end
		end
	end
end

--loop through the webway gates
for j = 1,4 do
	local northBase_darkreaperProduced = false
	
	-- if the webway gate still exists & base activated
	if g_base_activated_North == true and
		EGroup_Count("eg_northBase_webwayGate"..j) == 1
	then
		-- Loop through all the possible sg_northBase_darkreaper Squads
			-- Changed to only one squad for balance reasons
		for i =1,1	do
			-- If the SGroup is not currently used...
			if northBase_darkreaperProduced == false and
				SGroup_Count("sg_northBase_darkreaper"..i) == 0
			then
				-- Try to Produce a dark reaper from the webway gate
				if Rule_Produce_DarkReapers("sg_northBase_darkreaper"..i, "eg_northBase_webwayGate"..j, "mkr_northBase_webwayGate"..j) == true
				then
					northBase_darkreaperProduced = true
					
					-- Reset Status (in case died while retreating etc...)
					g_northBase_darkreaper_status[i] = g_squad_produced						
				end
			end
		end
	end
end

--if all support portals & webway gates are destroyed, remove rules since base is gone
if 	g_base_activated_North == true and
	EGroup_Count("eg_northBase_supportPortal1") == 0 and
	EGroup_Count("eg_northBase_supportPortal2") == 0 and
	EGroup_Count("eg_northBase_webwayGate1") == 0 and
	EGroup_Count("eg_northBase_webwayGate2") == 0 and
	EGroup_Count("eg_northBase_webwayGate3") == 0 and
	EGroup_Count("eg_northBase_webwayGate4") == 0
then
	Rule_Remove(Rule_Production_North_Base)
end

end

-- South Base

-- Checks for & Cloaks the Base if the Player Units Attack function Rule_Cloak_South_Base() --is the base already cloaked? if g_base_cloaked_South == false then -- if not...Check if the Player is attacking the base if Player_AreSquadsNearMarker(g_Player1, "mkr_southBase_underAttack") then -- Count How many play units are at that marker Player_GetAllSquadsNearMarker(g_Player1, "sg_NearMarker", "mkr_southBase_underAttack") local unitCount = SGroup_Count("sg_NearMarker") SGroup_Clear("sg_NearMarker")

		--is it enough units to cloak a base?
		if unitCount >= g_num_PlayerUnits_ActivateBase
		then
				-- if a webway gate exists in the base, enable its cloak
				for i = 1, 4 do
					if EGroup_Count("eg_southBase_webwayGate"..i) == 1
					then
						EGroup_Shroud("eg_southBase_webwayGate"..i,true)
					end
				end
				-- Base is now cloaked
				g_base_cloaked_South = true
		end
	end

-- Remove the Rule since the base is already cloaked
else
	Rule_Remove(Rule_Cloak_South_Base)
end

end

-- Checks if the Player Attacks the Base before it has been activated function Rule_Check_EarlyPlayer_Attack_South_Base() -- Checks if the Base is already activated if g_base_activated_South == false then -- if not...Check if the Player is attacking the base if Player_AreSquadsNearMarker(g_Player1, "mkr_southBase_underAttack") then -- Count How many play units are at that marker Player_GetAllSquadsNearMarker(g_Player1, "sg_NearMarker", "mkr_southBase_underAttack") local unitCount = SGroup_Count("sg_NearMarker") SGroup_Clear("sg_NearMarker")

		--is it enough units to activate a base?
		if unitCount >= g_num_PlayerUnits_ActivateBase
		then
			-- Activate the North Base Instantly
			g_base_activated_South = true
		end
	end

-- Remove the Rule since the base is already activated
else
	Rule_Remove(Rule_Check_EarlyPlayer_Attack_South_Base)
end

end

-- Handles Production of Units ( Ranger Patrols, Warp Spiders, & Guardians) function Rule_Production_South_Base() -- Loop through all the Aspect Portals for j = 1,2 do -- if the Aspect Portal still exists & base activated if g_base_activated_South == true and EGroup_Count("eg_southBase_aspectPortal"..j) == 1 then -- First Patroling Ranger Squad doesn't exist if SGroup_Count("sg_southBase_rangers1") == 0 and Rule_Produce_Rangers("sg_southBase_rangers1", "eg_southBase_aspectPortal"..j, "mkr_southBase_aspectPortal"..j) then -- For Objective Assigning g_southBase_FirstTroops_Produced = true

			-- Task to First Patrol Point
			Cmd_AttackMoveMarker("sg_southBase_rangers1", "mkr_AI_RangerPatrol4")
		
		-- Warp Spider Squad doesn't exist
		elseif SGroup_Count("sg_southBase_warpspider1") == 0 and
			Rule_Produce_WarpSpider("sg_southBase_warpspider1", "eg_southBase_aspectPortal"..j, "mkr_southBase_aspectPortal"..j)
		then
			-- For Objective Assigning
			g_southBase_FirstTroops_Produced = true
			
			-- Reset Status for Jumping
			g_southBase_warpspider_status[1] = g_squad_jump_prep
		
		-- Second Patroling Ranger Squad doesn't exist
		elseif SGroup_Count("sg_southBase_rangers2") == 0 and
			Rule_Produce_Rangers("sg_southBase_rangers2", "eg_southBase_aspectPortal"..j, "mkr_southBase_aspectPortal"..j)
		then
			-- Task to First Patrol Point
			Cmd_AttackMoveMarker("sg_southBase_rangers2", "mkr_AI_RangerPatrol4")
		end
	end
end	

-- Actually is only needed if "i  > 1 "
local southBase_troopsProduced = false

-- Loop through all the possible southBase_guardian Squads
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_guardian"..i) == 0
	then
		-- Try to Produce a Guardian squad from the HQ
		if Rule_Produce_Guardian("sg_southBase_guardian"..i, "eg_southBase_HQ", "mkr_southBase_HQ1") == true
		then
			southBase_troopsProduced = true
			
			-- Reset Status (in case died while retreating etc...)
			g_southBase_guardian_status[i] = g_squad_produced
		end
	end
end

--if aspect portals & hqs are destroyed, remove rules since base is gone
if 	g_base_activated_South == true and
	EGroup_Count("eg_southBase_aspectPortal1") == 0 and
	EGroup_Count("eg_southBase_aspectPortal2") == 0 and
	EGroup_Count("eg_southBase_HQ") == 0
then
	Rule_Remove(Rule_Production_South_Base)
end

end

-- SouthBase: Ranger Squad One Patrols from 1,2,3,4,1 function Rule_SouthBase_Ranger_Patrol_One() -- Check if the Rangers arrived at the Patrol Location 1 if SGroup_Exists("sg_southBase_rangers1") and Prox_AllSquadsNearMarker("sg_southBase_rangers1", "mkr_AI_RangerPatrol1") then -- Task to Next Patrol Point Cmd_AttackMoveMarker("sg_southBase_rangers1", "mkr_AI_RangerPatrol2")

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

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

end

-- SouthBase: Ranger Squad Two Patrols from 4,3,5,6,2,1,4 -- Note: Player Base is at 6 so basically this is an attack function Rule_SouthBase_Ranger_Patrol_Two() -- Check if the Rangers arrived at the Patrol Location 4 if SGroup_Exists("sg_southBase_rangers2") and Prox_AllSquadsNearMarker("sg_southBase_rangers2", "mkr_AI_RangerPatrol4") then -- Reinforce BackUp before continuing patrol if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_southBase_rangers2",1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_southBase_rangers2",1)) and SGroup_GetAvgLoadout("sg_southBase_rangers2") < 0.75 then -- Reinforce Command_Squad(g_Player2, "sg_southBase_rangers2", SCMD_ReinforceTrooper) else -- Task to Next Patrol Point Cmd_AttackMoveMarker("sg_southBase_rangers2", "mkr_AI_RangerPatrol3") end

-- Check if the Rangers arrived at the Patrol Location 3
elseif SGroup_Exists("sg_southBase_rangers2") and
	Prox_AllSquadsNearMarker("sg_southBase_rangers2", "mkr_AI_RangerPatrol3")
then
	-- Task to Next Patrol Point
	Cmd_AttackMoveMarker("sg_southBase_rangers2", "mkr_AI_RangerPatrol5")

	-- Check if the Rangers arrived at the Patrol Location 5
elseif SGroup_Exists("sg_southBase_rangers2") and
	Prox_AllSquadsNearMarker("sg_southBase_rangers2", "mkr_AI_RangerPatrol5")
then
	-- Task to Next Patrol Point
	Cmd_AttackMoveMarker("sg_southBase_rangers2", "mkr_AI_RangerPatrol6")	
	
	-- Check if the Rangers arrived at the Patrol Location 6
elseif SGroup_Exists("sg_southBase_rangers2") and
	Prox_AllSquadsNearMarker("sg_southBase_rangers2", "mkr_AI_RangerPatrol6")
then
	-- Reinforce BackUp before continuing patrol (since this is middle of player base & should lose units here)
	if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_southBase_rangers2",1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_southBase_rangers2",1)) and
		SGroup_GetAvgLoadout("sg_southBase_rangers2") < 0.75
	then
		-- Reinforce
		Command_Squad(g_Player2, "sg_southBase_rangers2", SCMD_ReinforceTrooper)
	else
		-- Task to Next Patrol Point
		Cmd_AttackMoveMarker("sg_southBase_rangers2", "mkr_AI_RangerPatrol2")
	end

-- Check if the Rangers arrived at the Patrol Location 2
elseif SGroup_Exists("sg_southBase_rangers2") and
	Prox_AllSquadsNearMarker("sg_southBase_rangers2", "mkr_AI_RangerPatrol2")
then
	-- Task to Next Patrol Point
	Cmd_AttackMoveMarker("sg_southBase_rangers2", "mkr_AI_RangerPatrol1")	
	
	-- Check if the Rangers arrived at the Patrol Location 1
elseif SGroup_Exists("sg_southBase_rangers2") and
	Prox_AllSquadsNearMarker("sg_southBase_rangers2", "mkr_AI_RangerPatrol1")
then
	-- Task to Next Patrol Point
	Cmd_AttackMoveMarker("sg_southBase_rangers2", "mkr_AI_RangerPatrol4")
end

end


-- West Base

-- Handles Production of Units (Banshees & WraithLord) function Rule_Production_West_Base() local westBase_troopsProduced = false local westBase_vehicleProduced = false

-- Loop through all the possible westBase_banshees 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_banshee"..i) == 0
	then
		-- Try to Produce a Banshee squad from the Aspect Portal
		if Rule_Produce_Banshees("sg_westBase_banshee"..i, "eg_westBase_aspectPortal1", "mkr_westBase_aspectPortal1") == true
		then
			westBase_troopsProduced = true
			
			-- Reset Status (in case died while retreating etc...)
			g_westBase_banshee_status[i] = g_squad_produced
		end
	end
end

-- Loop through all the possible westBase_wraithLord Squads
for i =1,1	do
	-- If the SGroup is not currently used...
	if g_base_activated_West == true and
		westBase_vehicleProduced == false and
		SGroup_Count("sg_westBase_wraithLord"..i) == 0
	then
		-- Try to Produce a WraithLord from the Support Portal
		if Rule_Produce_WraithLord("sg_westBase_wraithLord"..i, "eg_westBase_supportPortal1", "mkr_westBase_supportPortal1") == true
		then
			westBase_vehicleProduced = true
			
			-- Reset Status (in case died while retreating etc...)
			g_westBase_wraithLord_status[i] = g_squad_produced
		end
	end
end

--if all production buildings are destroyed, remove rules since base is gone
if 	g_base_activated_West == true and
	EGroup_Count("eg_westBase_aspectPortal1") == 0 and
	EGroup_Count("eg_westBase_supportPortal1") == 0
then
	Rule_Remove(Rule_Production_West_Base)
end

end

-- Cloaked Webway Gates

-- Activate the webway Gates Earlier if the Player decloacks them function Rule_Check_EarlyPlayer_Attack_Webway() -- If a webway gate is decloaked (player discovered) then activate it early for i =1,4 do if g_webway_activated[i] == false and EGroup_IsShrouded("eg_cloaked_webwayGate"..i, true) == false then g_webway_activated[i] = true end end

-- 5-8 are behind holorocks so no need to early activate them

-- If a webway gate is decloaked (player discovered) then activate it early
for i =9,11 do
	if g_webway_activated[i] == false and
		EGroup_IsShrouded("eg_cloaked_webwayGate"..i, true) == false
	then
		g_webway_activated[i] = true
	end		
end

end

-- Controls the Initial Webway Gates that are in Player Base function Rule_Initial_Webway_Production() for i =1,2 do -- Produce a Guardian Squad from Webway Gates if SGroup_Count("sg_webway_guardian"..i) == 0 then Rule_Produce_Guardian("sg_webway_guardian"..i, "eg_centerBase_webwayGate"..i, "mkr_centerBase_webwayGate"..i) g_webway_guardian_status[i] = g_squad_produced end end

-- remove the rule once both webway gates are destroyed
if EGroup_Count("eg_centerBase_webwayGate1") == 0 and
	EGroup_Count("eg_centerBase_webwayGate2") == 0
then
	Rule_Remove(Rule_Initial_Webway_Production)
end

end

-- Handles Production of Units (banshees, dark reapers, fire dragons, guardians & rangers) function Rule_Cloaked_Webway_Production() -- So doesn't produce two squads from the same webway gate per cycle local webway_produced = {0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0}

for i = 1,20 do
	-- track if a webway has produced this cycle
	webway_produced[i] = false
end

-- Set Maximum Number of Possible Squads to Produce in a cycle
local max_number_produced = g_webway_numSquads_perCycle

-- Loop through all webway gates
for i =20,1,-1 do
	-- Loop the Different Unit SGroups
	for j =1,g_webway_numSquads do
		-- If Activated, Still Exists, & Not Produced this cycle 
		if g_webway_activated[i] == true and
			EGroup_Count("eg_cloaked_webwayGate"..i) == 1 and
			webway_produced[i] == false and
			max_number_produced > 0
		then
			-- Uncloak the Active Ones
			EGroup_Shroud("eg_cloaked_webwayGate"..i,false)
			
			-- If Webway produces banshees & have an empty Banshee Squad
			if g_webway_unit[i] == g_unit_Banshee and
				SGroup_Count("sg_webway_banshees"..j) == 0 and
				Rule_Produce_Banshees("sg_webway_banshees"..j, "eg_cloaked_webwayGate"..i, "mkr_cloaked_webwayGate"..i)
			then
				-- Produce Banshee & Set Status
				g_webway_banshees_status[j]	= g_squad_produced
				webway_produced[i] = true
				
				-- Subtract One from total produced
				max_number_produced = max_number_produced - 1
			
			-- If Webway produces Dark Reaper & have an empty Dark Reaper Squad
			elseif g_webway_unit[i] == g_unit_DarkReaper and
				SGroup_Count("sg_webway_darkreaper"..j) == 0 and
				Rule_Produce_DarkReapers("sg_webway_darkreaper"..j, "eg_cloaked_webwayGate"..i, "mkr_cloaked_webwayGate"..i)
			then
				-- Produce Dark Reaper & Set Status
				g_webway_darkreaper_status[j] = g_squad_produced
				webway_produced[i] = true
				
				-- Subtract One from total produced
				max_number_produced = max_number_produced - 1
			
			-- If Webway produces Fire Dragon & have an empty Fire Dragon Squad
			elseif g_webway_unit[i] == g_unit_FireDragon and
				SGroup_Count("sg_webway_firedragon"..j) == 0 and
				Rule_Produce_FireDragon("sg_webway_firedragon"..j, "eg_cloaked_webwayGate"..i, "mkr_cloaked_webwayGate"..i)
			then
				-- Produce Fire Dragon & Set Status
				g_webway_firedragon_status[j] = g_squad_produced
				webway_produced[i] = true
				
				-- Subtract One from total produced
				max_number_produced = max_number_produced - 1
				
			-- If Webway produces Guardian & have an empty Guardian Squad
			elseif g_webway_unit[i] == g_unit_Guardian and
				SGroup_Count("sg_webway_guardian"..j) == 0 and
				Rule_Produce_Guardian("sg_webway_guardian"..j, "eg_cloaked_webwayGate"..i, "mkr_cloaked_webwayGate"..i)
			then
				-- Produce Guardian & Set Status
				g_webway_guardian_status[j] = g_squad_produced
				webway_produced[i] = true
				
				-- Subtract One from total produced
				max_number_produced = max_number_produced - 1
				
			-- If Webway produces Rangers & have an empty Ranger Squad
			elseif g_webway_unit[i] == g_unit_Rangers and
				SGroup_Count("sg_webway_rangers"..j) == 0 and
				Rule_Produce_Rangers("sg_webway_rangers"..j, "eg_cloaked_webwayGate"..i, "mkr_cloaked_webwayGate"..i)
			then
				-- Produce Ranger & Set Status
				g_webway_ranger_status[j] = g_squad_produced
				webway_produced[i] = true
				
				-- Subtract One from total produced
				max_number_produced = max_number_produced - 1
			end
		end
	end
end

-- Send in WraithLord From Support Portal to the South of Player Base
if g_webway_supportPortal_activated == true and
	SGroup_Count("sg_webway_wraithLord") == 0 and
	Rule_Produce_WraithLord("sg_webway_wraithLord", "eg_cloaked_supportPortal1", "mkr_cloaked_supportPortal1")		
then
	g_webway_supportPortalTank_status[1] = g_squad_produced
end	

end

-- END OF ALL " BASE ACTIVATION, PRODUCTION, & ATTACKS " RULES


-- RANDOM MOVEMENT RULES -- 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 -- Rule_RandomMovement_Base() -- Causes a few units in each base to wander around it -- giving it the feeling of some life

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

-- Causes a few units in each base to wander around it -- giving it the feeling of some life function Rule_RandomMovement_Base() -- Center Base: Rule_RandomMovement_Support("sg_centerBase_defender1", "mkr_centerBase_underAttack") Rule_RandomMovement_Support("sg_centerBase_defender2", "mkr_centerBase_underAttack") Rule_RandomMovement_Support("sg_centerBase_defender3", "mkr_centerBase_underAttack") Rule_RandomMovement_Support("sg_centerBase_defender4", "mkr_centerBase_underAttack") Rule_RandomMovement_Support("sg_centerBase_defender5", "mkr_centerBase_underAttack") Rule_RandomMovement_Support("sg_centerBase_defender6", "mkr_centerBase_underAttack") Rule_RandomMovement_Support("sg_centerBase_defender7", "mkr_centerBase_underAttack") Rule_RandomMovement_Support("sg_centerBase_defender8", "mkr_centerBase_underAttack")

-- Elite Nightwing squads:
for i =1,g_number_EliteNightwings do
	Rule_RandomMovement_Support("sg_elite_nightwing"..i, "mkr_mainBase_webwayGate5")
end

-- Main Base:
Rule_RandomMovement_Support("sg_mainBase_defender1", "mkr_mainBase_webwayGate5")
Rule_RandomMovement_Support("sg_mainBase_defender2", "mkr_mainBase_webwayGate5")
Rule_RandomMovement_Support("sg_mainBase_defender3", "mkr_mainBase_webwayGate5")
Rule_RandomMovement_Support("sg_mainBase_defender4", "mkr_mainBase_webwayGate5")
Rule_RandomMovement_Support("sg_mainBase_defender5", "mkr_mainBase_webwayGate5")
Rule_RandomMovement_Support("sg_mainBase_defender6", "mkr_mainBase_webwayGate5")
Rule_RandomMovement_Support("sg_mainBase_defender7", "mkr_mainBase_webwayGate5")
Rule_RandomMovement_Support("sg_mainBase_defender8", "mkr_mainBase_webwayGate5")
Rule_RandomMovement_Support("sg_mainBase_defender9", "mkr_mainBase_webwayGate5")

-- North Base:
Rule_RandomMovement_Support("sg_northBase_defender1", "mkr_northBase_underAttack")
Rule_RandomMovement_Support("sg_northBase_defender2", "mkr_northBase_underAttack")
Rule_RandomMovement_Support("sg_northBase_defender3", "mkr_northBase_underAttack")
Rule_RandomMovement_Support("sg_northBase_defender4", "mkr_northBase_underAttack")
Rule_RandomMovement_Support("sg_northBase_defender5", "mkr_northBase_underAttack")
Rule_RandomMovement_Support("sg_northBase_defender6", "mkr_northBase_underAttack")

-- South Base:
Rule_RandomMovement_Support("sg_southBase_defender1", "mkr_southBase_underAttack")
Rule_RandomMovement_Support("sg_southBase_defender2", "mkr_southBase_underAttack")
Rule_RandomMovement_Support("sg_southBase_defender3", "mkr_southBase_underAttack")
Rule_RandomMovement_Support("sg_southBase_defender4", "mkr_southBase_underAttack")

-- West Base
Rule_RandomMovement_Support("sg_westBase_defender1", "mkr_westBase_supportPortal1")
Rule_RandomMovement_Support("sg_westBase_defender2", "mkr_westBase_supportPortal1")
Rule_RandomMovement_Support("sg_westBase_defender3", "mkr_westBase_supportPortal1")
Rule_RandomMovement_Support("sg_westBase_defender4", "mkr_westBase_supportPortal1")

end

-- END OF ALL " RANDOM MOVEMENT " RULES


-- VICTORY / DEFEAT RULES -- Rule_EndGame_Victory() : Wins the Mission & Plays the Final NIS -- Rule_EndGame_Defeat() : Checks if mission has been lost (Player Killed) -- Rule_GameOver() : Sets Game Over

-- Wins the Mission & Plays the Final NIS : Added as a OneShot in Rule_DestroyEldarHQ_Objective() once the objective is completed 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_Outro)	

Rule_AddInterval(Rule_GameOver, 1)

end

-- Rule for Losing the Game : Version for Losing before the player has a base function Rule_EndGame_Defeat_Early() --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_Player2, "" ) Rule_AddInterval(Rule_GameOver, 1) Rule_Remove(Rule_EndGame_Defeat) end end

-- Rule for Losing the Game : Version for losing after player has a base function Rule_EndGame_Defeat() --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 then Rule_RemoveAll() Fade_Start(4, false) World_SetTeamWin(g_Player2, "" ) 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