Mission event file for Dark Eldar Stronghold mission
Przewodniki
/
Mission event file for Dark Eldar Stronghold mission
Zaktualizowany 4 years ago przez Merric

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

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

--addon_dark_eldar_list_post_dark_lance


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

function OnGameSetup() -- Global varibles

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

-- What Race based intel event to use
g_intelEvent_raceId = 0

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

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

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

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

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

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

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

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

	--------------------- Starting Resources ----------------------------------------
	-- Amount of Initial Resource to give each of the AI Players
	g_amountRequisitionToGiveAI = 15000
	g_amountPowerToGiveAI = 10000

	-- Initial Amount of Extra Resources to Give Player (Non Necron Races)
	g_amountRequisitionToGivePlayer = 500
	g_amountPowerToGivePlayer = 500

	-- Initial Amount of Extra Power Resource to Give to Necron Player
	g_amountPowerToGiveNecron = 500
	
	-- How Much Resources to Give the Player for each cage they save
	g_amountRequisitionToGivePlayer_PerCage = 300
	g_amountPowerToGivePlayer_PerCage = 100
	
	-- How Much Resources to Give the Necron Player for each cage they save
	g_amountPowerToGiveNecron_PerCage = 300

	-- Time a base takes to produce units once it goes active
		-- Once a unit produces, it will attack
	
	-- Initial Areas:
	g_timer_centerBase			=	60
	g_timer_prisonerCage			=	30
	
	-- First Tier Activation:
	g_timer_eastBase				=	180
	g_timer_westBase				=	180
	g_timer_vectBase				=	180
	
	-- Second Tier Activation
	g_timer_mainBase				=	540
	g_timer_southEastBase		=	360
	
	-- Third Tier Activation:
	g_timer_northBase				=	540
	g_timer_northWestBase		=	540	
	g_timer_southWestBase		=	360
	
	-- Time between Vect Attacks (Will Only Attack if 100% Health, Else Wait till next time)
	g_timer_vectAttack				=	540
	
	-- What Percent of His life does Vect Retreat at (subtracts 0.10 before begininng checks)
	g_vect_retreat_damage		=	1.05
	
	--Time From Player Construction of HQ until Enemy Techs to Next Tier
	g_time_Tier_Two =	600
	g_time_Tier_Three = 1200
	
	g_units_produced = 0
	
---------------------------------------------END BALANCE VARIBLES------------------------------

-- Tracks if a Base has activated & thus can produce troops
g_base_activated_Center			=	false
g_base_activated_East				=	false
g_base_activated_Main				=	false
g_base_activated_North				=	false
g_base_activated_NorthWest		=	false
g_base_activated_SouthEast		=	false
g_base_activated_SouthWest	=	false
g_base_activated_West				=	false
g_base_activated_Vect				=	false

-- Can the Dark Eldar Use Soul Power yet
g_soulPower_enabled_Corrosion				=	false
g_soulPower_enabled_SoulStorm				=	false
g_soulPower_enabled_ScreamofDammed	=	false
g_soulPower_enabled_PiercingVision			=	false

g_patrol_activated_Center			=	true
g_patrol_activated_North			=	true
g_patrol_activated_SouthWest	=	false

g_skimmerShop10_activated		=	false
g_hallOfBlood10_activated			=	false
g_hallOfBlood14_activated			=	false
g_hallOfBlood15_activated			=	false

-- Which Troops are Active to Support Vect
g_vectSupport_warpBeast			=	false
g_vectSupport_ravager				=	false

-- Tracks if a Prisoner Cage Base has been activated (or a scripted attack has fired)
g_firstTroops_sent = false
g_prisonerCage3_activated = false
g_prisonerCage4_activated = false
g_prisonerCage6_activated = false
g_prisonerCage10_activated = false

-- Counts have many prisoners have been freed
g_prisonerCage_numFreed = 0

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

-- Can Squads Retreat?
g_retreating_enabled =	true

-- How many Incubi can the Archon Have (used to track the researches
g_number_incubi	=	2

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

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

-- Squad AI Stuff:
g_squad_attacking				=	0
g_squad_retreating			=	1		-- also covers normal moving (non-attack move)
g_squad_reinforcing			=	2
g_squad_loading					=	3
g_squad_usingSkill				=	4
g_squad_produced				=	5
g_squad_jump_prep			=	6
g_squad_jump_ready			=	7
g_squad_jump_attack			=	8
g_squad_jump_checkjump	=	9
g_squad_patrolling				=	10

-- Squad Skills
	-- hellions & scourge are only used as jump troops (& thus skills used differently)
g_skill_warriors					=	1
g_skill_warpbeasts				=	2
g_skill_haemonculus			=	3
g_skill_raven						=	4
g_skill_wych						=	5
g_skill_talos						=	6
g_skill_archon						=	7
g_skill_slave						=	8
g_skill_raider						=	9
g_skill_raven_airDefense	=	10
g_skill_mandrakes				=	11

-- Jumping Skills
g_skill_eastBase_hellion_jump				=	12
g_skill_westBase_scourge_jump			=	13
g_skill_southEastBase_scourge_jump	=	14

-- Troops
	-- Cage Defense Troops
g_cageDefense_warrior_status					=	{0,0}
g_cageDefense_scourge_status					=	{0}
g_cageDefense_reaver_status					=	{0}

-- Center Base
g_centerBase_reaver_status						=	{0}
g_centerBase_mandrake_status				=	{0}
g_centerBase_scourge_status					=	{0}

-- East Base
g_eastBase_hellions_status						=	{0}
g_eastBase_warrior_status						=	{0}
g_eastBase_mandrake_status					=	{0}

-- Main Base
g_mainBase_raider_status							=	{0,0}
g_mainBase_ravager_status						=	{0,0}
g_mainBase_warrior_status						=	{0,0}

-- North Base
g_northBase_talos_status							=	{0,0}
g_northBase_raven_status							=	{0,0}

-- North West Base
g_northWestBase_haemonculus_status		=	{0}
g_northWestBase_wych_status					=	{0}

-- Patrol Squads:
g_centerBase_hellions_patrol_status				=	{0}
g_northBase_warpBeast_patrol_status			=	{0}
g_northBase_mandrake_patrol_status			=	{0}
g_southWestBase_warpbeast_patrol_status	=	{0}

-- Slave Squads for Random Repairing & Soul Harvesting
g_slave_status												=	{0,0,0,0}

-- South East Base
g_southEastBase_scourge_status			=	{0}
g_southEastBase_mandrakes_status		=	{0}

-- South West Base
g_southWestBase_wych_status					=	{0}
g_southWestBase_haemonculus_status	=	{0}
g_southWestBase_raven_status				=	{0}
g_southWestBase_reaver_status				=	{0,0}
g_southWestBase_talos_status					=	{0}

-- Vect Support
g_vectSupport_warrior_status				=	{0}
g_vectSupport_warpBeast_status			=	{0}
g_vectSupport_reaver_status					=	{0}
g_vectSupport_ravager_status				=	{0}

-- West Base
g_westBase_scourge_status					=	{0}
g_westBase_warrior_status					=	{0}
g_westBase_reaver_status					=	{0,0}

-- Vect Base:
g_vectBase_archon_status						=	{0}
g_vectBase_raven_status						=	{0,0}

---------------------------------------------RACE BASED INTEL EVENT ARRAYS---------------------
-- Track if IEs have played:
g_ie_FirstCage_Played = false
g_ie_FreeMostTroops_Played = false
g_ie_baseRevealed = false

-- Soul Cage Destroyed IEs:
g_ie_SoulCage_Destroyed	= {false,false,false,false}

-- Race Based IE Array for Initial : Our troops are caged -- Free them
g_ie_Initial_Array = {
							EVENTS.IE_Initial_Chaos,
							EVENTS.IE_Initial_DarkEldar, -- should not be possible to get
							EVENTS.IE_Initial_Eldar,
							EVENTS.IE_Initial_Guard,
							EVENTS.IE_Initial_Necron,
							EVENTS.IE_Initial_Ork,
							EVENTS.IE_Initial_Sisters,
							EVENTS.IE_Initial_Space,
							EVENTS.IE_Initial_Tau}

-- Race Based IE Array for FirstCage : Player frees first cage of troops
g_ie_FirstCage_Array = {
							EVENTS.IE_FirstCage_Chaos,
							EVENTS.IE_FirstCage_DarkEldar, -- should not be possible to get
							EVENTS.IE_FirstCage_Eldar,
							EVENTS.IE_FirstCage_Guard,
							EVENTS.IE_FirstCage_Necron,
							EVENTS.IE_FirstCage_Ork,
							EVENTS.IE_FirstCage_Sisters,
							EVENTS.IE_FirstCage_Space,
							EVENTS.IE_FirstCage_Tau}

-- Race Based IE Array for EarlyDarkEldarCharge : Dark Eldar have spotted & are attacking us
g_ie_EarlyDarkEldarCharge_Array = {
							EVENTS.IE_EarlyDarkEldarCharge_Chaos,
							EVENTS.IE_EarlyDarkEldarCharge_DarkEldar, -- should not be possible to get
							EVENTS.IE_EarlyDarkEldarCharge_Eldar,
							EVENTS.IE_EarlyDarkEldarCharge_Guard,
							EVENTS.IE_EarlyDarkEldarCharge_Necron,
							EVENTS.IE_EarlyDarkEldarCharge_Ork,
							EVENTS.IE_EarlyDarkEldarCharge_Sisters,
							EVENTS.IE_EarlyDarkEldarCharge_Space,
							EVENTS.IE_EarlyDarkEldarCharge_Tau}


-- Race Based IE Array for ShowTwoBases : Tell Player to avoid attacking the two large bases
g_ie_ShowTwoBases_Array = {
							EVENTS.IE_ShowTwoBases_Chaos,
							EVENTS.IE_ShowTwoBases_DarkEldar, -- should not be possible to get
							EVENTS.IE_ShowTwoBases_Eldar,
							EVENTS.IE_ShowTwoBases_Guard,
							EVENTS.IE_ShowTwoBases_Necron,
							EVENTS.IE_ShowTwoBases_Ork,
							EVENTS.IE_ShowTwoBases_Sisters,
							EVENTS.IE_ShowTwoBases_Space,
							EVENTS.IE_ShowTwoBases_Tau}

-- Race Based IE Array for FreeMostTroops : Most of our troops are freed
g_ie_FreeMostTroops_Array = {
							EVENTS.IE_FreeMostTroops_Chaos,
							EVENTS.IE_FreeMostTroops_DarkEldar, -- should not be possible to get
							EVENTS.IE_FreeMostTroops_Eldar,
							EVENTS.IE_FreeMostTroops_Guard,
							EVENTS.IE_FreeMostTroops_Necron,
							EVENTS.IE_FreeMostTroops_Ork,
							EVENTS.IE_FreeMostTroops_Sisters,
							EVENTS.IE_FreeMostTroops_Space,
							EVENTS.IE_FreeMostTroops_Tau}

-- Race Based IE Array for FreeBuilders : Builders Freed -- Tell Player to Build HQ
g_ie_FreeBuilders_Array = {
							EVENTS.IE_FreeBuilders_Chaos,
							EVENTS.IE_FreeBuilders_DarkEldar, -- should not be possible to get
							EVENTS.IE_FreeBuilders_Eldar,
							EVENTS.IE_FreeBuilders_Guard,
							EVENTS.IE_FreeBuilders_Necron,
							EVENTS.IE_FreeBuilders_Ork,
							EVENTS.IE_FreeBuilders_Sisters,
							EVENTS.IE_FreeBuilders_Space,
							EVENTS.IE_FreeBuilders_Tau}	

-- 3 Random Lines for when piercing vision power is used
g_ie_DetectCloakTaunt_Array = {
							EVENTS.IE_DetectCloakTaunt_One,
							EVENTS.IE_DetectCloakTaunt_Two,
							EVENTS.IE_DetectCloakTaunt_Three}

-- 3 Random Lines for when non-piercing vision soul power is used
g_ie_PowerUseTaunt_Array = {
							EVENTS.IE_PowerUseTaunt_One,
							EVENTS.IE_PowerUseTaunt_Two,
							EVENTS.IE_PowerUseTaunt_Three}

-- Race Based IE Array for VectFirstAttack : First Time Vect Attacks Player -- Vect Taunts, Player Responds
g_ie_VectFirstAttack_Array = {
							EVENTS.IE_VectFirstAttack_Chaos,
							EVENTS.IE_VectFirstAttack_DarkEldar, -- should not be possible to get
							EVENTS.IE_VectFirstAttack_Eldar,
							EVENTS.IE_VectFirstAttack_Guard,
							EVENTS.IE_VectFirstAttack_Necron,
							EVENTS.IE_VectFirstAttack_Ork,
							EVENTS.IE_VectFirstAttack_Sisters,
							EVENTS.IE_VectFirstAttack_Space,
							EVENTS.IE_VectFirstAttack_Tau}

-- 3 Random Lines for when Vect Attacks Player
g_ie_VectRandomAttack_Array = {
							EVENTS.IE_VectRandomAttack_One,
							EVENTS.IE_VectRandomAttack_Two,
							EVENTS.IE_VectRandomAttack_Three}

-- 4 Random Lines for when Vect Retreats
g_ie_VectRandomFlee_Array = {
							EVENTS.IE_VectRandomFlee_One,
							EVENTS.IE_VectRandomFlee_Two,
							EVENTS.IE_VectRandomFlee_Three,
							EVENTS.IE_VectRandomFlee_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, 1)

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

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

-- Dark Eldar AI Players
g_Player2 = Setup_Player (1, "$3950220", "dark_eldar_race", 2)	
g_Player3 = Setup_Player (2, "$3950220", "dark_eldar_race", 2)
g_Player4 = Setup_Player (3, "$3950220", "dark_eldar_race", 2)

-- Set Dark Eldar Color Scheme
Misc_PlayerTeamColor(g_Player2, "default_1")
Misc_PlayerTeamColor(g_Player3, "default_1")
Misc_PlayerTeamColor(g_Player4, "default_1")

end

-- Used to redefine some varibles after loading a save game function OnGameRestore() ---------------------------------------------RACE BASED INTEL EVENT ARRAYS--------------------- -- Race Based IE Array for Initial : Our troops are caged -- Free them g_ie_Initial_Array = { EVENTS.IE_Initial_Chaos, EVENTS.IE_Initial_DarkEldar, -- should not be possible to get EVENTS.IE_Initial_Eldar, EVENTS.IE_Initial_Guard, EVENTS.IE_Initial_Necron, EVENTS.IE_Initial_Ork, EVENTS.IE_Initial_Sisters, EVENTS.IE_Initial_Space, EVENTS.IE_Initial_Tau}

-- Race Based IE Array for FirstCage : Player frees first cage of troops
g_ie_FirstCage_Array = {
							EVENTS.IE_FirstCage_Chaos,
							EVENTS.IE_FirstCage_DarkEldar, -- should not be possible to get
							EVENTS.IE_FirstCage_Eldar,
							EVENTS.IE_FirstCage_Guard,
							EVENTS.IE_FirstCage_Necron,
							EVENTS.IE_FirstCage_Ork,
							EVENTS.IE_FirstCage_Sisters,
							EVENTS.IE_FirstCage_Space,
							EVENTS.IE_FirstCage_Tau}

-- Race Based IE Array for EarlyDarkEldarCharge : Dark Eldar have spotted & are attacking us
g_ie_EarlyDarkEldarCharge_Array = {
							EVENTS.IE_EarlyDarkEldarCharge_Chaos,
							EVENTS.IE_EarlyDarkEldarCharge_DarkEldar, -- should not be possible to get
							EVENTS.IE_EarlyDarkEldarCharge_Eldar,
							EVENTS.IE_EarlyDarkEldarCharge_Guard,
							EVENTS.IE_EarlyDarkEldarCharge_Necron,
							EVENTS.IE_EarlyDarkEldarCharge_Ork,
							EVENTS.IE_EarlyDarkEldarCharge_Sisters,
							EVENTS.IE_EarlyDarkEldarCharge_Space,
							EVENTS.IE_EarlyDarkEldarCharge_Tau}


-- Race Based IE Array for ShowTwoBases : Tell Player to avoid attacking the two large bases
g_ie_ShowTwoBases_Array = {
							EVENTS.IE_ShowTwoBases_Chaos,
							EVENTS.IE_ShowTwoBases_DarkEldar, -- should not be possible to get
							EVENTS.IE_ShowTwoBases_Eldar,
							EVENTS.IE_ShowTwoBases_Guard,
							EVENTS.IE_ShowTwoBases_Necron,
							EVENTS.IE_ShowTwoBases_Ork,
							EVENTS.IE_ShowTwoBases_Sisters,
							EVENTS.IE_ShowTwoBases_Space,
							EVENTS.IE_ShowTwoBases_Tau}

-- Race Based IE Array for FreeMostTroops : Most of our troops are freed
g_ie_FreeMostTroops_Array = {
							EVENTS.IE_FreeMostTroops_Chaos,
							EVENTS.IE_FreeMostTroops_DarkEldar, -- should not be possible to get
							EVENTS.IE_FreeMostTroops_Eldar,
							EVENTS.IE_FreeMostTroops_Guard,
							EVENTS.IE_FreeMostTroops_Necron,
							EVENTS.IE_FreeMostTroops_Ork,
							EVENTS.IE_FreeMostTroops_Sisters,
							EVENTS.IE_FreeMostTroops_Space,
							EVENTS.IE_FreeMostTroops_Tau}

-- Race Based IE Array for FreeBuilders : Builders Freed -- Tell Player to Build HQ
g_ie_FreeBuilders_Array = {
							EVENTS.IE_FreeBuilders_Chaos,
							EVENTS.IE_FreeBuilders_DarkEldar, -- should not be possible to get
							EVENTS.IE_FreeBuilders_Eldar,
							EVENTS.IE_FreeBuilders_Guard,
							EVENTS.IE_FreeBuilders_Necron,
							EVENTS.IE_FreeBuilders_Ork,
							EVENTS.IE_FreeBuilders_Sisters,
							EVENTS.IE_FreeBuilders_Space,
							EVENTS.IE_FreeBuilders_Tau}	

-- 3 Random Lines for when piercing vision power is used
g_ie_DetectCloakTaunt_Array = {
							EVENTS.IE_DetectCloakTaunt_One,
							EVENTS.IE_DetectCloakTaunt_Two,
							EVENTS.IE_DetectCloakTaunt_Three}

-- 3 Random Lines for when non-piercing vision soul power is used
g_ie_PowerUseTaunt_Array = {
							EVENTS.IE_PowerUseTaunt_One,
							EVENTS.IE_PowerUseTaunt_Two,
							EVENTS.IE_PowerUseTaunt_Three}

-- Race Based IE Array for VectFirstAttack : First Time Vect Attacks Player -- Vect Taunts, Player Responds
g_ie_VectFirstAttack_Array = {
							EVENTS.IE_VectFirstAttack_Chaos,
							EVENTS.IE_VectFirstAttack_DarkEldar, -- should not be possible to get
							EVENTS.IE_VectFirstAttack_Eldar,
							EVENTS.IE_VectFirstAttack_Guard,
							EVENTS.IE_VectFirstAttack_Necron,
							EVENTS.IE_VectFirstAttack_Ork,
							EVENTS.IE_VectFirstAttack_Sisters,
							EVENTS.IE_VectFirstAttack_Space,
							EVENTS.IE_VectFirstAttack_Tau}

-- 3 Random Lines for when Vect Attacks Player
g_ie_VectRandomAttack_Array = {
							EVENTS.IE_VectRandomAttack_One,
							EVENTS.IE_VectRandomAttack_Two,
							EVENTS.IE_VectRandomAttack_Three}

-- 4 Random Lines for when Vect Retreats
g_ie_VectRandomFlee_Array = {
							EVENTS.IE_VectRandomFlee_One,
							EVENTS.IE_VectRandomFlee_Two,
							EVENTS.IE_VectRandomFlee_Three,
							EVENTS.IE_VectRandomFlee_Four}								

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

end

-- END OF " GAME SETUP & RESTORE " RULES


-- INITALIZATION -- OnInit() : Mandatory Function that sets up the mission -- Called after OnGameSetup() : 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 -- Rule_Stronghold_Difficulty_Strength_Stuff() : Used to Set up stuff based on the difficulty level of the stronghold (10-17) -- Rule_PresetAI() : Used to Disable AI Players (Done Before Initial NIS)

-- Used to Setup the music & ambient soundtracks 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_darkeldar_perc_str" )
Sound_PlaylistAddTrack( PC_Music, "MU_IG_STR_darkeldar" )
Sound_PlaylistAddTrack( PC_Music, "MU_IG_STR_darkeldar_perc" )
Sound_PlaylistAddTrack( PC_Music, "MU_IG_STR_darkeldar_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 11/06/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_ChaosCorruption1" )
Sound_PlaylistAddTrack( PC_Ambient, "Ambience_ChaosCorruption2" )
-- 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) function Rule_Stronghold_Difficulty_Strength_Stuff() -- Get the strength of the stronghold from the MetaMap g_strongholdStrength = MetaMap_GetTerritoryMilitaryStrength(MetaMap_GetDefendingTerritoryIndex())

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

-- Set the difficulty tier based on stronghold strength: (13,14,15)
elseif g_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 function Rule_PresetAI() Cpu_Enable(g_Player2, false) Cpu_Enable(g_Player3, false) Cpu_Enable(g_Player4, false) end

-- END OF ALL "EXTRA INITIAL SETUP" RULES


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

-- Handles setting everything in scenario that changes based on the player race 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"
	
	-- Air Unit for the Race:
	g_AirUnit_blueprint = "chaos_squad_hell_talon"
	
	-- What drops out of the prisoner cages when they are freed (7-9 are builders)
	g_prisoner_blueprint_1 = "chaos_squad_horror_sp_dxp3_prisoner"
	g_prisoner_blueprint_2 = "chaos_squad_cultist_sp_dxp3_prisoner"
	g_prisoner_blueprint_3 = "chaos_squad_horror_sp_dxp3_prisoner"
	g_prisoner_blueprint_4 = "chaos_squad_cultist_sp_dxp3_prisoner"
	g_prisoner_blueprint_5 = "chaos_squad_khorne_berserker_sp_dxp3_prisoner"
	g_prisoner_blueprint_6 = "chaos_marine_squad_sp_dxp3_prisoner"
	
	-- used for forward base ability
	g_bonus_generator	= "chaos_plasma_generator"
	g_bonus_turret			= "chaos_turret_bolter"
	g_bonus_barracks		= "chaos_temple"
	g_bonus_barracks2		= 0 --value on used for tau kroot nest, dummy value for all other races, like the Tau turret.
	g_bonus_research		= "chaos_armoury"
	
	-- Used for Defeat Checks
	t_building_exceptions = {
		"chaos_thermo_plasma_generator",
		"chaos_plasma_generator",
		"chaos_turret_bolter",
		"chaos_mine_field",
		"chaos_listening_post"}
	
	-- Used for Defeat Checks
	t_unit_exceptions = {}

-- Should not be possible to be this race on this map
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"
	
	-- Air Unit for the Race:
	g_AirUnit_blueprint = "dark_eldar_squad_raven"
	
	-- NOT NEEDED SINCE IS DARK ELDAR LEVEL
	-- What drops out of the prisoner cages when they are freed (7-9 are builders)
	g_prisoner_blueprint_1 = " "
	g_prisoner_blueprint_2 = " "
	g_prisoner_blueprint_3 = " "
	g_prisoner_blueprint_4 = " "
	g_prisoner_blueprint_5 = " "
	g_prisoner_blueprint_6 = " "
	
	-- NOT NEEDED SINCE IS DARK ELDAR LEVEL
	-- 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		= 0 -- Dark Eldar Research is their second tier, so makes no sense
	
	-- 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 = {}

elseif g_raceName == "eldar_race"
then
	-- What Intel Events race is using
	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"
	
	-- Air Unit for the Race:
	g_AirUnit_blueprint = "eldar_squad_nightwing"
	
	-- What drops out of the prisoner cages when they are freed (7-9 are builders)
	g_prisoner_blueprint_1 = "eldar_squad_dark_reapers_sp_dxp3_prisoner"
	g_prisoner_blueprint_2 = "eldar_guardian_squad_sp_dxp3_prisoner"
	g_prisoner_blueprint_3 = "eldar_squad_fire_dragon_sp_dxp3_prisoner"
	g_prisoner_blueprint_4 = "eldar_squad_dark_reapers_sp_dxp3_prisoner"
	g_prisoner_blueprint_5 = "eldar_harlequin_squad_sp_dxp3_prisoner"
	g_prisoner_blueprint_6 = "eldar_squad_banshees_sp_dxp3_prisoner"
	
	-- used for forward base ability
	g_bonus_generator	= "eldar_warp_generator"
	g_bonus_turret			= "eldar_support_platform_scatterlaser"
	g_bonus_barracks		= "eldar_aspect_portal"
	g_bonus_barracks2		= 0 --value on used for tau kroot nest, dummy value for all other races, like the Tau turret.
	g_bonus_research		= "eldar_soul_shrine"
	
	-- Used for Defeat Checks
	t_building_exceptions = {
		"eldar_advanced_warp_generator",
		"eldar_warp_generator",
		"eldar_support_platform_scatterlaser",
		"eldar_mine_field",
		"eldar_listening_post"}
	
	-- Used for Defeat Checks
	t_unit_exceptions = {}

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

	-- HQ that Race uses
	g_HQ_blueprint = "guard_hq"
	
	-- Builder that Race uses
	g_Builder_blueprint = "guard_squad_enginseer"
	
	-- Air Unit for the Race:
	g_AirUnit_blueprint = "guard_squad_marauder"
	
	-- What drops out of the prisoner cages when they are freed (7-9 are builders)
	g_prisoner_blueprint_1 = "guard_squad_kasrkin_sp_dxp3_prisoner"
	g_prisoner_blueprint_2 = "guard_squad_guardsmen_sp_dxp3_prisoner"
	g_prisoner_blueprint_3 = "guard_squad_priest_sp_dxp3_prisoner"
	g_prisoner_blueprint_4 = "guard_squad_guardsmen_sp_dxp3_prisoner"
	g_prisoner_blueprint_5 = "guard_squad_ogryns_sp_dxp3_prisoner"
	g_prisoner_blueprint_6 = "guard_squad_guardsmen_sp_dxp3_prisoner"
	
	-- used for forward base ability
	g_bonus_generator	= "guard_plasma_generator"
	g_bonus_turret			= "guard_turret_heavy_bolter"
	g_bonus_barracks		= "guard_infantry"
	g_bonus_barracks2		= 0 --value on used for tau kroot nest, dummy value for all other races, like the Tau turret.
	g_bonus_research		= "guard_tactica"
	
	-- Used for Defeat Checks
	t_building_exceptions = {
		"guard_thermo_plasma",
		"guard_plasma_generator",
		"guard_turret_heavy_bolter",
		"guard_mines",
		"guard_listening_post"}
	
	-- Used for Defeat Checks
	t_unit_exceptions = {}

elseif g_raceName == "necron_race"
then
	-- What Intel Events race is using
	g_intelEvent_raceId = 5
	
	-- Faction name that Race is using
	g_factionName = "$3950223"
	
	-- Color Scheme that Race is using
	g_colorScheme = "default_0"
	
	-- HQ that Race uses
	g_HQ_blueprint = "monolith"
	
	-- Builder that Race uses
	g_Builder_blueprint = "necron_builder_scarab_squad"
	
	-- Air Unit for the Race:
	g_AirUnit_blueprint = "necron_scarab_squad"
	
	-- What drops out of the prisoner cages when they are freed (7-9 are builders)
	g_prisoner_blueprint_1 = "necron_immortal_squad_sp_dxp3_prisoner"
	g_prisoner_blueprint_2 = "necron_basic_warrior_squad_sp_dxp3_prisoner"
	g_prisoner_blueprint_3 = "necron_pariah_squad_sp_dxp3_prisoner"
	g_prisoner_blueprint_4 = "necron_basic_warrior_squad_sp_dxp3_prisoner"
	g_prisoner_blueprint_5 = "necron_wraith_squad_sp_dxp3_prisoner"
	g_prisoner_blueprint_6 = "necron_basic_warrior_squad_sp_dxp3_prisoner"
	
	-- used for forward base ability
	g_bonus_generator	= "necron_plasma_generator"
	g_bonus_turret			= "necron_turret"
	g_bonus_barracks		= "necron_summoning_core"
	g_bonus_barracks2		= 0 --value on used for tau kroot nest, dummy value for all other races, like the Tau turret.
	g_bonus_research		= "necron_forbidden_archive"
	
	-- Used for Defeat Checks
	t_building_exceptions = {
		"necron_thermoplasma_generator",
		"necron_plasma_generator",
		"necron_turret",
		"necron_listening_post"}
	
	-- Used for Defeat Checks
	t_unit_exceptions = {}

elseif g_raceName == "ork_race"
then
	-- What Intel Events race is using
	g_intelEvent_raceId = 6
	
	-- Faction name that Race is using
	g_factionName = "$3950215"
	
	-- Color Scheme that Race is using
	g_colorScheme = "default_3"
	
	-- HQ that Race uses
	g_HQ_blueprint = "ork_hq"
	
	-- Builder that Race uses
	g_Builder_blueprint = "ork_squad_grot"
	
	-- Air Unit for the Race:
	g_AirUnit_blueprint = "ork_squad_fighta_bomba"
	
	-- What drops out of the prisoner cages when they are freed (7-9 are builders)
	g_prisoner_blueprint_1 = "ork_squad_tankbusta_sp_dxp3_prisoner"
	g_prisoner_blueprint_2 = "ork_squad_shoota_boy_sp_dxp3_prisoner"
	g_prisoner_blueprint_3 = "ork_squad_nob_sp_dxp3_prisoner"
	g_prisoner_blueprint_4 = "ork_squad_slugga_sp_dxp3_prisoner"
	g_prisoner_blueprint_5 = "ork_squad_tankbusta_sp_dxp3_prisoner"
	g_prisoner_blueprint_6 = "ork_squad_slugga_sp_dxp3_prisoner"
	
	-- used for forward base ability
	g_bonus_generator	= "ork_generator"
	g_bonus_turret			= "ork_waagh_banner"
	g_bonus_barracks		= "ork_boy_hut"
	g_bonus_barracks2		= 0 --value on used for tau kroot nest, dummy value for all other races, like the Tau turret.
	g_bonus_research		= "ork_pile_o_guns"
	
	-- Used for Defeat Checks
	t_building_exceptions = {
		"ork_bigger_generator",
		"ork_generator",
		"ork_waagh_banner",
		"ork_mine_field",
		"ork_listening_post"}
	
	-- Used for Defeat Checks
	t_unit_exceptions = {}	

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

	-- HQ that Race uses
	g_HQ_blueprint = "sisters_hq"

	-- Builder that Race uses
	g_Builder_blueprint = "sisters_squad_servitor"
	
	-- Air Unit for the Race:
	g_AirUnit_blueprint = "sisters_squad_lightning"
	
	-- What drops out of the prisoner cages when they are freed (7-9 are builders)
	g_prisoner_blueprint_1 = "sisters_squad_battle_sister_sp_dxp3_prisoner"
	g_prisoner_blueprint_2 = "sisters_squad_missionary_sp_dxp3_prisoner"
	g_prisoner_blueprint_3 = "sisters_squad_celestian_sp_dxp3_prisoner"
	g_prisoner_blueprint_4 = "sisters_squad_missionary_sp_dxp3_prisoner"
	g_prisoner_blueprint_5 = "sisters_squad_repentia_sp_dxp3_prisoner"
	g_prisoner_blueprint_6 = "sisters_squad_battle_sister_sp_dxp3_prisoner"
	
	-- used for forward base ability
	g_bonus_generator	= "sisters_plasma_generator"
	g_bonus_turret			= "sisters_turret_flamer"
	g_bonus_barracks		= "sisters_infantry"
	g_bonus_barracks2		= 0 --value on used for tau kroot nest, dummy value for all other races, like the Tau turret.
	g_bonus_research		= "sisters_sanctuary"
	
	-- Used for Defeat Checks
	t_building_exceptions = {
		"sisters_plasma_generator",
		"sisters_thermo_plasma",
		"sisters_turret_flamer",
		"sisters_mines",
		"sisters_listening_post"}

	-- Used for Defeat Checks
	t_unit_exceptions = {}

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

	-- HQ that Race uses
	g_HQ_blueprint = "space_marine_hq"
	
	-- Builder that Race uses
	g_Builder_blueprint = "space_marine_squad_servitor"
	
	-- Air Unit for the Race:
	g_AirUnit_blueprint = "space_marine_squad_tempest"
	
	-- What drops out of the prisoner cages when they are freed (7-9 are builders)
	g_prisoner_blueprint_1 = "space_marine_squad_sp_dxp3_prisoner"
	g_prisoner_blueprint_2 = "space_marine_squad_scout_sp_dxp3_prisoner"
	g_prisoner_blueprint_3 = "space_marine_squad_grey_knights_sp_dxp3_prisoner"
	g_prisoner_blueprint_4 = "space_marine_squad_scout_sp_dxp3_prisoner"
	g_prisoner_blueprint_5 = "space_marine_squad_terminator_veteran_sp_dxp3_prisoner"
	g_prisoner_blueprint_6 = "space_marine_squad_sp_dxp3_prisoner"

	-- used for forward base ability
	g_bonus_generator	= "space_marine_generator"
	g_bonus_turret			= "space_marine_turret_bolter"
	g_bonus_barracks		= "space_marine_barracks"
	g_bonus_barracks2		= 0 --value on used for tau kroot nest, dummy value for all other races, like the Tau turret.
	g_bonus_research		= "space_marine_armoury"
	
	-- Used for Defeat Checks
	t_building_exceptions = {
		"space_marine_thermo_generator",
		"space_marine_generator",
		"space_marine_turret_bolter",
		"space_marine_mine_field",
		"space_marine_listening_post"}
		
	-- Used for Defeat Checks
	t_unit_exceptions = {}
	
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"
	
	-- Air Unit for the Race:
	g_AirUnit_blueprint = "tau_barracuda_squad"
	
	-- What drops out of the prisoner cages when they are freed (7-9 are builders)
	g_prisoner_blueprint_1 = "tau_kroot_alpha_squad_sp_dxp3_prisoner"
	g_prisoner_blueprint_2 = "tau_honor_guard_fire_warrior_squad_sp_dxp3_prisoner"
	g_prisoner_blueprint_3 = "tau_kroot_hound_squad_sp_dxp3_prisoner"
	g_prisoner_blueprint_4 = "tau_honor_guard_fire_warrior_squad_sp_dxp3_prisoner"
	g_prisoner_blueprint_5 = "tau_kroot_shaper_squad_sp_dxp3_prisoner"
	g_prisoner_blueprint_6 = "tau_honor_guard_fire_warrior_squad_sp_dxp3_prisoner"

	-- used for forward base ability
	g_bonus_generator	= "tau_plasma_generator"
	g_bonus_turret			= 0  --tau have no turrets, so zero is simply a filler value to establish the variable instead of writting cutom checks for tau later.  0 will never be a value fed in by code, so it simply allows the algorithm to function in a standadrd manner for all races.
	g_bonus_barracks		= "tau_barracks"
	g_bonus_barracks2		= "tau_kroot_nest"
	g_bonus_research		= "tau_research_building"
	
	-- Used for Defeat Checks
	t_building_exceptions = {
		"tau_thermoplasma_generator",
		"tau_plasma_generator",
		"tau_listening_post"}
	
	-- Used for Defeat Checks
	t_unit_exceptions = {}
end

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

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

end

-- Creates all the Players Initial Units on the Map (including Honor Guard) ( & give resources) 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_troops", g_prisoner_blueprint_2, "mkr_initial_troops", 1,20)
SGroup_AddLeaders("sg_player_troops")

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

-- Give the Orks Some Population
if g_raceName == "ork_race"
then
	Player_AddResource(g_Player1, RT_Pop, 10)
end

end

-- Forward Base Special Ability that the Sisters start with function ForwardBases() -- Add in any bonus buildings made availible if the player has purchased them via owning Hyperion peaks province t_blueprintEntitybonus = {}

MetaMap_GetAttackingRaceStartingEntitiesList(t_blueprintEntitybonus)

for j=1,table.getn(t_blueprintEntitybonus) do
	if t_blueprintEntitybonus[j] == g_bonus_generator
	then
		User_CreateBuilding(g_Player1, "eg_Bonus"..j, t_blueprintEntitybonus[j], "MM_Reinforcement"..g_bonus_gen_counter, 0)
		
		--increase by one, the next generator will then spawn at the correct marker after this one
		g_bonus_gen_counter = g_bonus_gen_counter + 1
	
	elseif t_blueprintEntitybonus[j] == g_bonus_turret
	then
		User_CreateBuilding(g_Player1, "eg_Bonus"..j, t_blueprintEntitybonus[j], "MM_Reinforcement"..g_bonus_turret_counter, 0)
		
		--increase by one, the next turret will then spawn at the correct marker after this one
		g_bonus_turret_counter = g_bonus_turret_counter + 1
	
	elseif t_blueprintEntitybonus[j] == g_bonus_barracks
	then
		User_CreateBuilding(g_Player1, "eg_Bonus"..j, t_blueprintEntitybonus[j], "MM_Reinforcement10", 0)
	
	elseif t_blueprintEntitybonus[j] == g_bonus_research
	then
		User_CreateBuilding(g_Player1, "eg_Bonus"..j, t_blueprintEntitybonus[j], "MM_Reinforcement11", 0)
	
	elseif t_blueprintEntitybonus[j] == g_bonus_barracks2
	then
		User_CreateBuilding(g_Player1, "eg_Bonus"..j, t_blueprintEntitybonus[j], "MM_Reinforcement13", 0)
	end
end

end

-- Code to Always Builds the building (prevents crashes & makes sure the buildings spawned) function User_CreateBuilding(p_PlayerID, p_EGroupID, p_Blueprint, p_MarkerName, complete)

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

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

-- Entity_Spawn(l_EntityID)

-- I added this part so it can build at a percentage

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

-- Complete the Forward bases 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: Player Builds own HQ in mission

-- EGroup_SetConstructionComplete("eg_player_mainBase_HQ1")

-- Forward Bases:
for j=1,table.getn(t_blueprintEntitybonus) do
	if t_blueprintEntitybonus[j] == g_bonus_generator
	then
		EGroup_SetConstructionComplete("eg_Bonus"..j)
	
		--increase by one, the next generator will then spawn at the correct marker after this one
		g_bonus_gen_counter = g_bonus_gen_counter + 1
	
	elseif t_blueprintEntitybonus[j] == g_bonus_turret
	then
		EGroup_SetConstructionComplete("eg_Bonus"..j)
	
		--increase by one, the next turret will then spawn at the correct marker after this one
		g_bonus_turret_counter = g_bonus_turret_counter + 1
	
	elseif t_blueprintEntitybonus[j] == g_bonus_barracks
	then
		EGroup_SetConstructionComplete("eg_Bonus"..j)
	
	elseif t_blueprintEntitybonus[j] == g_bonus_research
	then
		EGroup_SetConstructionComplete("eg_Bonus"..j)
	
	elseif t_blueprintEntitybonus[j] == g_bonus_barracks2
	then
		EGroup_SetConstructionComplete("eg_Bonus"..j)
	end
end

end

-- 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_Create_CenterBase_Buildings() : Create Buildings for Center Base (also creates the HQs for the Mega Basilisk Spotter Objective)

-- Create all AI Bases & give them strategic points : Called from OnInit( ) function Rule_Create_All_Ai_Initial_Buildings() -- Create all the AI Buildings Rule_Create_DarkEldar_Buildings()

-- 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)
Player_SetAllResources(g_Player3, g_amountRequisitionToGiveAI, g_amountPowerToGiveAI, 0)
Player_SetAllResources(g_Player4, g_amountRequisitionToGiveAI, g_amountPowerToGiveAI, 0)

-- Give Some Starting Soul Resources to AI
Player_AddResource(g_Player2, RT_Souls, 10000)
Player_AddResource(g_Player3, RT_Souls, 10000)
Player_AddResource(g_Player4, RT_Souls, 10000)

end

-- Create All the Dark Eldar Buildings on the Map function Rule_Create_DarkEldar_Buildings() -- Used for Soul Cage Objectives EGroup_Create("eg_soulCage_Objective")

-- Create the haemonculus laboratory: 
for i = 1,3  do
	Entity_CreateBuildingMarker(g_Player2,"eg_haemonculusLab_"..i, "dark_eldar_haemonculus_laboratory","mkr_haemonculusLab_"..i, 1)
end

-- Create the Barracks: Hall of Blood 
for i = 1,15  do
	Entity_CreateBuildingMarker(g_Player2,"eg_hallOfBlood_"..i, "dark_eldar_hall_of_blood","mkr_hallOfBlood_"..i, 1)
end

-- Create the HQ: 
for i = 1,8  do
	Entity_CreateBuildingMarker(g_Player2,"eg_hq_"..i, "dark_eldar_hq","mkr_hq_"..i, 1)
end

-- Upgrade the HQ to the top tier (for soul powers)
EGroup_ForceAddOn("eg_hq_1", "addon_dark_eldar_hq_1" )
EGroup_ForceAddOn("eg_hq_1", "addon_dark_eldar_hq_2" )

-- Create the Plasma Generators: 
for i = 1,18  do
	Entity_CreateBuildingMarker(g_Player2,"eg_power_"..i, "dark_eldar_plasma_generator","mkr_power_"..i, 1)
end

-- Create the Real Prisoner Cages: 
for i = 1,10  do
	Entity_CreateBuildingMarker(g_Player2,"eg_prisonerCage_"..i, "dark_eldar_prisoner_cage_sp_dxp3","mkr_prisonerCage_"..i, 1)
end

-- Create some Fake Prisoner Caged (Addon Removes the Smoke Effect)
for i = 1,9  do
	Entity_CreateBuildingMarker(g_Player2,"eg_prisonerCage_fake_"..i, "dark_eldar_prisoner_cage_sp_dxp3","mkr_prisonerCage_fake_"..i, 1)
	EGroup_ForceAddOn("eg_prisonerCage_fake_"..i, "addon_dark_eldar_cage_empty")
end

-- Create the Vehicle Bay: Skimmer Shop (Dark Foundry) 
for i = 1,11  do
	Entity_CreateBuildingMarker(g_Player2,"eg_skimmerShop_"..i, "dark_eldar_skimmer_shop","mkr_skimmerShop_"..i, 1)
end

-- Create the Slave Caravels:	
-- Ones that create slaves
for i = 1,8  do
	Entity_CreateBuildingMarker(g_Player2,"eg_slaveCaravel_"..i, "dark_eldar_slave_caravel","mkr_slaveCaravel_"..i, 1)
	EGroup_ForceAddOn("eg_slaveCaravel_"..i, "addon_dark_eldar_slave_graveyard")
end

-- Ones that send out shock ability
for i = 9,20  do
	Entity_CreateBuildingMarker(g_Player2,"eg_slaveCaravel_"..i, "dark_eldar_slave_caravel","mkr_slaveCaravel_"..i, 1)
	EGroup_ForceAddOn("eg_slaveCaravel_"..i, "addon_dark_eldar_gruesome_display")
end	

-- Create the Soul Cages: (Used for objectives)
	-- 1 & 2 have been removed
for i = 3,6  do
	Entity_CreateBuildingMarker(g_Player2,"eg_soulCage_"..i, "dark_eldar_soul_cage_sp_dxp3","mkr_soulCage_"..i, 1)
	EGroup_AddGroup("eg_soulCage_Objective", "eg_soulCage_"..i)
end

-- Create the Wych Cult Arena: 
for i = 1,1  do
	Entity_CreateBuildingMarker(g_Player2,"eg_wychCultArena_"..i, "dark_eldar_wych_cult_arena","mkr_wychCultArena_"..i, 1)
end

end

-- Setup the Strategic Points, Critical Points, & Relics to AI Control -- All EGroups are set in the editor function Rule_Setup_AI_StrategicPoints( ) ------------------------------------------------------------------------------------------------------------------------------------------------- -- Strategic Point Ownership & Upgrades to Listening Posts ------------------------------------------------------------------------------------------------------------------------------------------------- -- The three by the location where player bulds base -- Upgrade to tier 1 for i=15, 17 do EGroup_SetPlayerOwner("eg_stratPoint"..i, g_Player2) Entity_CreateBuildingPosition(g_Player2, "eg_listeningPost"..i, "dark_eldar_listening_post", EGroup_GetPosition("eg_stratPoint"..i), 1) EGroup_ForceAddOn("eg_listeningPost"..i, "addon_dark_eldar_list_post_1" ) end

-- Strategic Points to g_Player2
	-- Upgrade to Tier 2 & Dark Lance Upgrades
for i=1, 14 do
	EGroup_SetPlayerOwner("eg_stratPoint"..i, g_Player2)
	Entity_CreateBuildingPosition(g_Player2, "eg_listeningPost"..i, "dark_eldar_listening_post", EGroup_GetPosition("eg_stratPoint"..i), 1)
	EGroup_ForceAddOn("eg_listeningPost"..i, "addon_dark_eldar_list_post_2" )
	EGroup_ForceAddOn("eg_listeningPost"..i, "addon_dark_eldar_list_post_dark_lance")		
end
-------------------------------------------------------------------------------------------------------------------------------------------------
-- Relic Ownership  & Upgrades to Listening Posts Level 2
-------------------------------------------------------------------------------------------------------------------------------------------------
-- Relic by the Main Base to g_Player2
	-- Tier 2 & Dark Lance Upgrades
for i=1, 1 do
	EGroup_SetPlayerOwner("eg_relic"..i, g_Player2)
	Entity_CreateBuildingPosition(g_Player2, "eg_listeningPostRelic"..i, "dark_eldar_listening_post", EGroup_GetPosition("eg_relic"..i), 1)
	EGroup_ForceAddOn("eg_listeningPostRelic"..i, "addon_dark_eldar_list_post_2" )
	EGroup_ForceAddOn("eg_listeningPostRelic"..i, "addon_dark_eldar_list_post_dark_lance")	
end

-- Relic by the Side Bases to g_Player2
	-- No LP so Player knows where they are
for i=2, 3 do
	EGroup_SetPlayerOwner("eg_relic"..i, g_Player2)
end

end


-- END OF ALL " CREATE AI BUILDINGS " RULES


-- CREATE AI INITIAL UNIT RULES -- Rule_Create_All_Ai_Initial_Units() : Create all AI Initial Units : Called from OnInit( )

-- Create all AI Initial Units : Called from OnInit( ) function Rule_Create_All_Ai_Initial_Units() -- Spawn in Vect for the Objective Util_CreateSquadsAtMarker(g_Player4, "sg_Vect_Objective", "dark_eldar_squad_dais_of_destruction_sp_dxp3", "mkr_vect_objective", 1)

-- Produce some basic troops by the First Prisoner Cage (Cage 10) (1 squad + 1 for each difficult tier)
Rule_Produce_Mandrake_Full("sg_prisonerCage_firstTroops", "eg_hallOfBlood_10", "mkr_prisonerCage_10")
for i= 1, g_strongholdStrengthTier do
	Rule_Produce_Mandrake_Full("sg_prisonerCage_firstTroops", "eg_hallOfBlood_10", "mkr_prisonerCage_10")
end

-- Produce the First Attack Squad of Troops (The group that attacks right past the first cage) (2 warrior + 1 mandrake per tier)
Rule_Produce_Warrior_Full("sg_firstTroops", "eg_hallOfBlood_10", "mkr_spawnFirstTroops_1")
Rule_Produce_Warrior_Full("sg_firstTroops", "eg_hallOfBlood_10", "mkr_spawnFirstTroops_3")
for i = 1, g_strongholdStrengthTier do
	Rule_Produce_Mandrake_Full("sg_firstTroops", "eg_hallOfBlood_10", "mkr_spawnFirstTroops_2")
end

-- Produce the Squad of Warriors from Hall of Blood 10
Rule_Produce_Warrior_Full("sg_hallOfBlood10_firstTroops", "eg_hallOfBlood_10", "mkr_hallOfBlood_10")

-- Produce the Squad of Warriors from Hall of Blood 14
Rule_Produce_Warrior_Full("sg_hallOfBlood14_firstTroops", "eg_hallOfBlood_14", "mkr_hallOfBlood_14")

-- Produce the Squad of Warriors from Hall of Blood 15
Rule_Produce_Warrior_Full("sg_hallOfBlood15_firstTroops", "eg_hallOfBlood_15", "mkr_hallOfBlood_15")

-- Produce the First Reavers from SKimmer10
Rule_Produce_Reaver("sg_skimmer10_firstTroops", "eg_skimmerShop_10", "mkr_skimmerShop_10")
Rule_Produce_Reaver("sg_skimmer10_firstTroops", "eg_skimmerShop_10", "mkr_skimmerShop_10")

-- Produce Some Slaves For Repairing & Soul Harvesting
Rule_Produce_Slave("sg_slave_1", "eg_hq_1", "mkr_hq_1")
Rule_Produce_Slave("sg_slave_2", "eg_hq_1", "mkr_hq_1")
Rule_Produce_Slave("sg_slave_3", "eg_slaveCaravel_5", "mkr_slaveCaravel_5")
Rule_Produce_Slave("sg_slave_4", "eg_slaveCaravel_6", "mkr_slaveCaravel_6")	

-- Produce Some Loaded Raiders For Jumping In
	-- Create at Hall of Blood 7 & Skimmer Shop 7 & Jump in once the player nears the markers
for i=1,4 do
	Rule_Produce_Warrior_Full("sg_prisoner_raider_jump_troops"..i, "eg_hallOfBlood_7", "mkr_hallOfBlood_7")
	Rule_Produce_Raider("sg_prisoner_raider_jump_"..i, "eg_skimmerShop_7", "mkr_skimmerShop_7")
	Cmd_EnterTransport("sg_prisoner_raider_jump_troops"..i, "sg_prisoner_raider_jump_"..i)
end

-- Create the Sourge Jump Troops (w/ Dark Lance) used to jump in throughout the intro areas
	-- Create by Center Base & Jump in once the player nears the markers
for i = 1,6 do
	Rule_Produce_Scourge_FullDarkLance("sg_prisoner_scourge_jump_"..i, "eg_hq_4", "mkr_hq_4")
end

-- Create the Helion Jump Troops used to jump in throughout the intro areas
	-- Create at Hall of Blood 6 & Jump in once the player nears the markers
for i = 1,3 do
	Rule_Produce_Hellion("sg_prisoner_hellion_jump_"..i, "eg_hallOfBlood_6", "mkr_hallOfBlood_6")
end

-- Create the Wychs By Prisoner Cage 6
for i = 1,2 do
	Rule_Produce_Wych("sg_prisoner_wych_"..i, "eg_hallOfBlood_12", "mkr_prisoner_wych_"..i)
end

-- Create the Warriors By Prisoner Cage 6
for i = 1,2 do
	Rule_Produce_Warrior_Full("sg_prisoner_warrior_"..i, "eg_prisonerCage_6", "mkr_prisoner_troop_"..i)
end

-- Create Initial Defense Troops by the Bases
Rule_Create_Ai_Initial_Units_Center_Base()
Rule_Create_Ai_Initial_Units_East_Base()
Rule_Create_Ai_Initial_Units_Main_Base()
Rule_Create_Ai_Initial_Units_North_Base()
Rule_Create_Ai_Initial_Units_NorthWest_Base()
Rule_Create_Ai_Initial_Units_SouthEast_Base()
Rule_Create_Ai_Initial_Units_SouthWest_Base()
Rule_Create_Ai_Initial_Units_West_Base()

end

--Produce Some Troops for Initial Center Base Defense: function Rule_Create_Ai_Initial_Units_Center_Base() -- Two Slave Squads at HQ Rule_Produce_Slave("sg_center_defense_slave1", "eg_hq_4", "mkr_hq_4") Rule_Produce_Slave("sg_center_defense_slave2", "eg_hq_4", "mkr_hq_4")

-- Two Warrior Squads at HQ
Rule_Produce_Warrior_Full("sg_center_defense_warrior1", "eg_hq_4", "mkr_hq_4")
Rule_Produce_Warrior_Full("sg_center_defense_warrior2", "eg_hq_4", "mkr_hq_4")

-- Two Reavers at HQ
Rule_Produce_Reaver("sg_center_defense_reaver1", "eg_hq_4", "mkr_hq_4")
Rule_Produce_Reaver("sg_center_defense_reaver2", "eg_hq_4", "mkr_hq_4")

end

--Produce Some Troops for Initial East Base Defense: function Rule_Create_Ai_Initial_Units_East_Base() -- Four Reaver Squads at HQ Rule_Produce_Reaver("sg_east_defense_reaver1", "eg_hq_5", "mkr_hq_5") Rule_Produce_Reaver("sg_east_defense_reaver2", "eg_hq_5", "mkr_hq_5") Rule_Produce_Reaver("sg_east_defense_reaver3", "eg_hq_5", "mkr_hq_5") Rule_Produce_Reaver("sg_east_defense_reaver4", "eg_hq_5", "mkr_hq_5")

--Warrior Squads at HQ
for i = 1, g_strongholdStrengthTier do
	Rule_Produce_Warrior_Full("sg_east_defense_warrior"..i, "eg_hq_5", "mkr_hq_5")	
end

end

--Produce Some Troops for Initial Main Base Defense: function Rule_Create_Ai_Initial_Units_Main_Base() -- Produce Two Mandrakes at HQ Rule_Produce_Mandrake_Full("sg_main_defense_mandrakes1", "eg_hq_1", "mkr_hq_1") Rule_Produce_Mandrake_Full("sg_main_defense_mandrakes2", "eg_hq_1", "mkr_hq_1")

--Warrior Squads at HQ
for i = 1, g_strongholdStrengthTier do
	Rule_Produce_Warrior_Full("sg_main_defense_warrior"..i, "eg_hq_1", "mkr_hq_1")	
end

--ProduceTwo Ravagers
Rule_Produce_Ravager_FullyUpgraded("sg_main_defense_ravager1", "eg_hq_1", "mkr_hq_1")
Rule_Produce_Ravager_FullyUpgraded("sg_main_defense_ravager2", "eg_hq_1", "mkr_hq_1")

-- Produce a Talos
Rule_Produce_Talos("sg_main_defense_talos", "eg_hq_1", "mkr_hq_1")

-- Produce Two Ravens
Rule_Produce_Raven("sg_main_defense_raven1", "eg_hq_1", "mkr_hq_1")
Rule_Produce_Raven("sg_main_defense_raven2", "eg_hq_1", "mkr_hq_1")	

end

--Produce Some Troops for Initial North Base Defense: function Rule_Create_Ai_Initial_Units_North_Base() -- Two Warrior Squads at Soul Cage Rule_Produce_Warrior_Full("sg_north_defense_warrior1", "eg_soulCage_5", "mkr_soulCage_5") Rule_Produce_Warrior_Full("sg_north_defense_warrior2", "eg_soulCage_5", "mkr_soulCage_5")

-- Two Scourge Squads at Soul Cage
Rule_Produce_Scourge_FullDarkLance("sg_north_defense_scourge1", "eg_soulCage_5", "mkr_soulCage_5")
Rule_Produce_Scourge_FullDarkLance("sg_north_defense_scourge2", "eg_soulCage_5", "mkr_soulCage_5")

end

--Produce Some Troops for Initial North West Base Defense: function Rule_Create_Ai_Initial_Units_NorthWest_Base() -- Two Reavers at HQ 3 Rule_Produce_Reaver("sg_northWest_defense_reaver1", "eg_hq_3", "mkr_hq_3") Rule_Produce_Reaver("sg_northWest_defense_reaver2", "eg_hq_3", "mkr_hq_3") end

--Produce Some Troops for Initial South East Base Defense: function Rule_Create_Ai_Initial_Units_SouthEast_Base() -- Two Scourge Squads at Hall of Blood 11 Rule_Produce_Scourge_FullDarkLance("sg_southEast_defense_scourge1", "eg_hallOfBlood_11", "mkr_hallOfBlood_11") Rule_Produce_Scourge_FullDarkLance("sg_southEast_defense_scourge2", "eg_hallOfBlood_11", "mkr_hallOfBlood_11")

-- 1 Talos & 1 Mandrakes at HQ7
Rule_Produce_Talos("sg_southEast_defense_talos", "eg_hq_7", "mkr_hq_7")
Rule_Produce_Mandrake_Full("sg_southEast_defense_mandrakes", "eg_hq_7", "mkr_hq_7")

-- 2 Ravagers at Power Plants 17 & 18
Rule_Produce_Ravager_FullyUpgraded("sg_southEast_defense_ravager1", "eg_power_17", "mkr_power_17")
Rule_Produce_Ravager_FullyUpgraded("sg_southEast_defense_ravager2", "eg_power_18", "mkr_power_18")

end

--Produce Some Troops for Initial South West Base Defense: function Rule_Create_Ai_Initial_Units_SouthWest_Base() -- One Wych Squad by Hall of Blood 12 Rule_Produce_Wych("sg_southWest_defense_wych", "eg_hallOfBlood_12", "mkr_hallOfBlood_12")

-- One Warp Beast Squad by Hall of Blood 13
Rule_Produce_WarpBeast("sg_southWest_defense_warpBeast", "eg_hallOfBlood_13", "mkr_hallOfBlood_13")

-- One Talos by Skimmer Shop 9
Rule_Produce_Talos("sg_southWest_defense_talos", "eg_skimmerShop_9", "mkr_skimmerShop_9")

-- One Mandrakes by Haemonculus Lab
Rule_Produce_Mandrake_Full("sg_southWest_defense_mandrakes", "eg_haemonculusLab_3", "mkr_haemonculusLab_3")

-- One Haemonculus by Haemonculus Lab
Rule_Produce_Haemonculus("sg_southWest_defense_haemonculus", "eg_haemonculusLab_3", "mkr_haemonculusLab_3")

-- Two Ravagers by HQ6
Rule_Produce_Ravager_FullyUpgraded("sg_southWest_defense_ravager1", "eg_hq_6", "mkr_hq_6")
Rule_Produce_Ravager_FullyUpgraded("sg_southWest_defense_ravager2", "eg_hq_6", "mkr_hq_6")

end

--Produce Some Troops for Initial West Base Defense: function Rule_Create_Ai_Initial_Units_West_Base() -- 1 Talos & 1 Mandrakes at Skimmer Shop 7 Rule_Produce_Talos("sg_west_defense_talos", "eg_skimmerShop_7", "mkr_skimmerShop_7") Rule_Produce_Mandrake_Full("sg_west_defense_mandrakes1", "eg_skimmerShop_7", "mkr_skimmerShop_7") Rule_Produce_Mandrake_Full("sg_west_defense_mandrakes2", "eg_skimmerShop_7", "mkr_skimmerShop_7") end


-- END OF ALL " CREATE AI INITIAL UNIT " RULES


-- 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_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 11/06/07: Dave, I moved the music setup after the opening NIS so I have a little more room to breathe. -- Function Used to Setup the Sound and Music : Function Is Defined Below Rule_SetupMusicPlaylist()

	-- Function used to create all the Initial Ai Units on the Map
	Rule_Create_All_Ai_Initial_Units( )
	
	-- Function used to give resources & create all the Player Initial Units on the Map (including Honor Guard) 
	Rule_Create_All_Player_Initial_Units( )
	
	-- Rule_Objective_Define(): Sets up the Objective Lua Tables, but doesn't actually assign them
	Rule_Objective_Define()
	
	-- Show and Control the Game Timer
	Rule_UI_Game_Timer()
	
	-- Assign & Check for Primary Objective: Establish Base of Operations (Also Assigns Prisoner Cage Objective) 
	Rule_AddInterval(Rule_EstablishBaseOfOperation_Objective,1)
	
	-- Set up the check for DEFEAT (Loss of Units / Buildings)
	Rule_AddInterval(Rule_EndGame_Defeat, 5)
	
	-- Makes Sure all base attacks are synced up
	Rule_AddOneShot(Rule_Create_And_Sync_Attacks, 0)
	
	-- 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:

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

-- PrimaryObjective: Assigned at Intro
Objective_EstablishBaseOfOperation = { title_id = 3950079, short_desc_id = 3950080, help_tip_id = 3950080}

-- Sub-Primary Ojective : Assigned briefly after start
Objective_FreeBuilders = { title_id = 3950081, short_desc_id = 3950082, help_tip_id = 3950082}

-- Sub-Primary Objective:  Assigned once builders are freed
Objective_BuildHQ = { title_id = 3950083, short_desc_id = 3950084, help_tip_id = 3950084}

-- Secondary Objective: Assigned briefly after start
Objective_FreeTroops = { title_id = 3950085, short_desc_id = 3950086, help_tip_id = 3950086}

-- Secondary Objective: Assigned after hq is built
Objective_DestroySoulCages = { title_id = 3950087, short_desc_id = 3950088, help_tip_id = 3950088}

-- Sub-Secondary Objective for all the Soul Cages
Objective_DestroyCage_SoulStorm = { title_id = 3950266, short_desc_id = 3950267, help_tip_id = 3950267}
Objective_DestroyCage_ScreamOfDammed = { title_id = 3950091, short_desc_id = 3950092, help_tip_id = 3950092}
Objective_DestroyCage_Corrosion = { title_id = 3950093, short_desc_id = 3950094, help_tip_id = 3950094}
Objective_DestroyCage_PiercingVision = { title_id = 3950258, short_desc_id = 3950259, help_tip_id = 3950259}

end

-- Assigns & Checks for Primary Objective: Kill Vect function Rule_KillVect_Objective() -- First check if Objective exists and add if not... if Event_IsAnyRunning() == false and Objective_Exists(Objective_KillVect.title_id) == false then -- Create ( & Assign) the objective as a primary one Util_ObjectiveCreate(Objective_KillVect, true)

	-- Update & Set the Primary Objective To this one when objective screen shows
	g_PrimaryObjectives = g_PrimaryObjectives + 1
	Objective_SetDefaultPrimary(g_PrimaryObjectives)
	
	--Initial Ping of Vect Location
	g_vect_ping = Objective_PingPosition(Objective_KillVect.title_id, SGroup_GetPosition("sg_Vect_Objective"), true, attack)
	
	-- Assign the Secondary Objective to Destroy All the Soul Cages
	Rule_AddInterval(Rule_DestroySoulCages_Objective,1)

-- Else Check if Vect is Dead are destroyed
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_KillVect.title_id) == true and
	SGroup_Count("sg_Vect_Objective") == 0
then	
	-- Complete the Objective and Remove the Rule
	Util_ObjectiveComplete(Objective_KillVect.title_id)
	Rule_Remove( Rule_KillVect_Objective )
	
	--Remove Ping
	Objective_PingRemove(Objective_KillVect.title_id, g_vect_ping)
	
	-- Victory Goes Here (5 sec delay is so it doesn't happen instantly)
	Rule_AddOneShot(Rule_EndGame_Actual_Victory, 5)

-- Else Ping Vect is still alive
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_KillVect.title_id) == true and
	SGroup_Count("sg_Vect_Objective") == 1
then
	--Remove Old Ping...
	Objective_PingRemove(Objective_KillVect.title_id, g_vect_ping)
	
	-- ...Update with new Ping Location of Vect on the Objective Screen
	g_vect_ping = Objective_PingPosition(Objective_KillVect.title_id, SGroup_GetPosition("sg_Vect_Objective"), true, attack)
end

end

-- Assigns & Check for Sub-Primary Objective : Establish your Base function Rule_EstablishBaseOfOperation_Objective() -- First check if Objective exists and add if not... if Event_IsAnyRunning() == false and Objective_Exists(Objective_EstablishBaseOfOperation.title_id) == false then -- Create ( & Assign) the objective as a primary one Util_ObjectiveCreate(Objective_EstablishBaseOfOperation, true) g_PrimaryObjectives = g_PrimaryObjectives + 1

	-- Play Initial IE: Our troops are caged -- Free them
	Util_StartIntel(g_ie_Initial_Array[g_intelEvent_raceId])
	
	-- Track when the player builds their hq (& thus all sub-objectives completed)
	g_player_hq_created = false
	
	-- Assign & Check for the Sub-Objective: Free Builders
	Rule_AddInterval(Rule_FreeBuilders_Objective,1)

-- if objective exists & the sub-objectives are completed (if the player has built HQ)
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_EstablishBaseOfOperation.title_id) == true and
	g_player_hq_created == true
then
	-- Play IE for Player HQ Completion
	Util_StartIntel(EVENTS.IE_PlayerHQ_Built)
	
	--Handles the Delayed Teching & Activation of Enemy Bases & research
	Rule_AddOneShot(Rule_Tech_And_Activate_Tier_One,1)
	Rule_AddOneShot(Rule_Tech_And_Activate_Tier_Two, g_time_Tier_Two)
	Rule_AddOneShot(Rule_Tech_And_Activate_Tier_Three, g_time_Tier_Three)
	
	-- Assign & Check for Primary Objective: Kill Vect (Also Assign Objective with Soul Cages)
	Rule_AddInterval(Rule_KillVect_Objective,1)
	
	-- Complete the Objective and Remove the Rule
	Util_ObjectiveComplete(Objective_EstablishBaseOfOperation.title_id)
	Rule_Remove(Rule_EstablishBaseOfOperation_Objective)
end

end

-- Assigns & Check for Sub-Primary Objective : Free your builders function Rule_FreeBuilders_Objective() -- Confirm the Primary Objective Exists & check if the Sub-Objective exists & add sub if not... if Event_IsAnyRunning() == false and Objective_Exists(Objective_EstablishBaseOfOperation.title_id) == true and Objective_GetState(Objective_EstablishBaseOfOperation.title_id) ~= OS_Complete and Objective_Exists(Objective_FreeBuilders.title_id) == false then -- Create (Assign) the objective as a sub-primary one Objective_SubAdd(Objective_FreeBuilders, Objective_EstablishBaseOfOperation.title_id)

	--Associate a Ping with the Objective on the Objective Screen (updates when each cage is destroyed)
	g_PrisonerCage_7_Ping_Objective = Objective_PingMarker(Objective_FreeBuilders.title_id, "mkr_prisonerCage_7", true, attack)
	g_PrisonerCage_8_Ping_Objective = Objective_PingMarker(Objective_FreeBuilders.title_id, "mkr_prisonerCage_8", true, attack)
	g_PrisonerCage_9_Ping_Objective = Objective_PingMarker(Objective_FreeBuilders.title_id, "mkr_prisonerCage_9", true, attack)

	-- Set up a ping on the ingame screen:
	Ping_Marker("mkr_prisonerCage_7", false, "default")
	Ping_Marker("mkr_prisonerCage_8", false, "default")
	Ping_Marker("mkr_prisonerCage_9", false, "default")
	
	-- Track when first builder is free so know to assign: Build HQ Objective
	g_buildHQ_assigned = false
	
	-- Update & Set the Primary Objective To this one when objective screen shows
	g_PrimaryObjectives = g_PrimaryObjectives + 1
	Objective_SetDefaultPrimary(g_PrimaryObjectives)
	
	-- Assign & Check for the Secondary Objective: Free Troops
	Rule_AddInterval(Rule_FreeTroops_Objective,1)

-- if the objective exists & all the builders are freed
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_FreeBuilders.title_id) == true and
	EGroup_Count("eg_prisonerCage_7") == 0 and
	EGroup_Count("eg_prisonerCage_8") == 0 and
	EGroup_Count("eg_prisonerCage_9") == 0
then

	-- Give the Player Resources (RT_Requisition, RT_Power) for Freeing All Builders (So Have Enough to Build HQ)
	if g_raceName == "necron_race"
	then
		-- If Necron, Only Give Power
		Player_AddResource(g_Player1, RT_Power, g_amountPowerToGiveNecron)
	else
		-- Otherwise give both
		Player_AddResource(g_Player1, RT_Requisition, g_amountRequisitionToGivePlayer)
		Player_AddResource(g_Player1, RT_Power, g_amountPowerToGivePlayer)
	end
	
	-- Complete the Objective & Remove the Rule
	Util_ObjectiveComplete(Objective_FreeBuilders.title_id)
	Rule_Remove(Rule_FreeBuilders_Objective)
end

-- Remove Objective Ping when the prisoner cage 7 is destroyed:
if EGroup_Count("eg_prisonerCage_7") == 0 and
	Objective_Exists(Objective_FreeBuilders.title_id) == true
then
	Objective_PingRemove(Objective_FreeBuilders.title_id, g_PrisonerCage_7_Ping_Objective)
		
	if g_buildHQ_assigned == false
	then
		g_buildHQ_assigned = true
		
		-- Check if Builders are killed before HQ is Built
		Rule_AddInterval(Rule_EndGame_Defeat_Builders,1)
		
		-- Assign Build HQ Objective here
		Rule_AddInterval(Rule_BuildHQ_Objective,1)
	end
end

-- Remove Objective Ping when the prisoner cage 8 is destroyed:
if EGroup_Count("eg_prisonerCage_8") == 0 and
	Objective_Exists(Objective_FreeBuilders.title_id) == true
then
	Objective_PingRemove(Objective_FreeBuilders.title_id, g_PrisonerCage_8_Ping_Objective)
	
	if g_buildHQ_assigned == false
	then
		g_buildHQ_assigned = true
		
		-- Check if Builders are killed before HQ is Built
		Rule_AddInterval(Rule_EndGame_Defeat_Builders,1)
		
		-- Assign Build HQ Objective here
		Rule_AddInterval(Rule_BuildHQ_Objective,1)
	end
end

-- Remove Objective Ping when the prisoner cage 9 is destroyed:
if EGroup_Count("eg_prisonerCage_9") == 0 and
	Objective_Exists(Objective_FreeBuilders.title_id) == true
then
	Objective_PingRemove(Objective_FreeBuilders.title_id, g_PrisonerCage_9_Ping_Objective)
	
	if g_buildHQ_assigned == false
	then
		g_buildHQ_assigned = true
		
		-- Check if Builders are killed before HQ is Built
		Rule_AddInterval(Rule_EndGame_Defeat_Builders,1)
		
		-- Assign Build HQ Objective here
		Rule_AddInterval(Rule_BuildHQ_Objective,1)
	end		
end

end

-- Assigns & Check for Sub-Primary Objective : Build Your HQ function Rule_BuildHQ_Objective() -- Confirm the Primary Objective Exists & check if the Sub-Objective exists & add sub if not... if Event_IsAnyRunning() == false and Objective_Exists(Objective_EstablishBaseOfOperation.title_id) == true and Objective_GetState(Objective_EstablishBaseOfOperation.title_id) ~= OS_Complete and Objective_Exists(Objective_BuildHQ.title_id) == false then -- Create (Assign) the objective as a sub-primary one Objective_SubAdd(Objective_BuildHQ, Objective_EstablishBaseOfOperation.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_FreeBuilders_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

-- if the objective exists & all the player HQ is built
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_BuildHQ.title_id) == true and
	g_playerHQ_built == true
then
	-- Remove the Defeat rule that checks for builder death, since HQ is completed now
	Rule_Remove(Rule_EndGame_Defeat_Builders)
	
	-- Complete the Objective & Remove the Rule
	Util_ObjectiveComplete(Objective_BuildHQ.title_id)
	Rule_Remove(Rule_BuildHQ_Objective)
	
	-- Remove the FOW Vision between Patrols & Player1
	World_EnablePlayerToPlayerFOW(g_Player1, g_Player3, true)
	
	-- Stop the FOG Reveal around the two large bases in the prisoner area
	Rule_Remove(Rule_RevealBaseWarning)
	
	-- so game know Player has built there HQ & where it is ( so main objective completes)
	g_player_hq_created = true
end

--Does Player Have HQ?
if EGroup_ContainsBlueprints(Player_GetEntities(g_Player1), Util_MakeBlueprintTable(g_HQ_blueprint), true) == true and
	Objective_Exists(Objective_BuildHQ.title_id) == true and
	g_player_hq_created == false
then
	-- Create EGroup with Player HQ
	EGroup_CreateFromEGroup("eg_player_HQ", EGroup_GetName(Player_GetEntities(g_Player1)), g_HQ_blueprint)
	
	-- Is the Player hq Completed (Greater than 97%)?
	-- using Greater than 97% in case it gets damaged during the building process
	--if EGroup_GetAvgHealth("eg_player_HQ") > 0.97
	--then
	
	-- if HQ Egroup Exists, Has at least 1 member, & the HQ is completed
	if EGroup_Exists("eg_player_HQ") and	EGroup_CountSpawned(EGroup_FromName("eg_player_HQ")) >= 1 and
		Entity_GetBuildingProgress(EGroup_GetSpawnedEntityAt(EGroup_FromName("eg_player_HQ"),1)) == 1
	then
		g_playerHQ_position = EGroup_GetPosition("eg_player_HQ")
		g_attack_target = EGroup_GetPosition("eg_player_HQ")
		g_playerHQ_built = true
		
		-- Bring in Any Building purchased using the forward bases special power
		ForwardBases()
		
		-- Complete the Forward Base Building
		Rule_AddOneShot(Rule_Complete_Player_Buildings,5)			
	end
end

end

-- Assigns & Check for Secondary Objective : Free your troops function Rule_FreeTroops_Objective() -- First check if Objective exists and add if not... if Event_IsAnyRunning() == false and Objective_Exists(Objective_FreeTroops.title_id) == false then -- Create( & Assign) the objective as a secondary one Util_ObjectiveCreate(Objective_FreeTroops, false)

	--Associate a Ping with the Objective on the Objective Screen (updates when each cage is destroyed)
	g_PrisonerCage_1_Ping_Objective = Objective_PingMarker(Objective_FreeTroops.title_id, "mkr_prisonerCage_1", true, attack)
	g_PrisonerCage_2_Ping_Objective = Objective_PingMarker(Objective_FreeTroops.title_id, "mkr_prisonerCage_2", true, attack)
	g_PrisonerCage_3_Ping_Objective = Objective_PingMarker(Objective_FreeTroops.title_id, "mkr_prisonerCage_3", true, attack)
	g_PrisonerCage_4_Ping_Objective = Objective_PingMarker(Objective_FreeTroops.title_id, "mkr_prisonerCage_4", true, attack)
	g_PrisonerCage_5_Ping_Objective = Objective_PingMarker(Objective_FreeTroops.title_id, "mkr_prisonerCage_5", true, attack)
	g_PrisonerCage_6_Ping_Objective = Objective_PingMarker(Objective_FreeTroops.title_id, "mkr_prisonerCage_6", true, attack)
	g_PrisonerCage_10_Ping_Objective = Objective_PingMarker(Objective_FreeTroops.title_id, "mkr_prisonerCage_10", true, attack)
	
	-- Set up a ping on the ingame screen for all the prisoner cages:
	for i=1,6 do
		Ping_Marker("mkr_prisonerCage_"..i, false, "default")
	end
	
	Ping_Marker("mkr_prisonerCage_10", false, "default")
	
	--Show the Objective Screen
	Objective_ShowScreen()

-- if the objective exists & all the troops are freed
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_FreeTroops.title_id) == true and
	EGroup_Count("eg_prisonerCage_1") == 0 and
	EGroup_Count("eg_prisonerCage_2") == 0 and
	EGroup_Count("eg_prisonerCage_3") == 0 and
	EGroup_Count("eg_prisonerCage_4") == 0 and
	EGroup_Count("eg_prisonerCage_5") == 0 and
	EGroup_Count("eg_prisonerCage_6") == 0 and
	EGroup_Count("eg_prisonerCage_10") == 0
then
	-- Complete the Objective & Remove the Rule
	Util_ObjectiveComplete(Objective_FreeTroops.title_id)
	Rule_Remove(Rule_FreeTroops_Objective)
end

-- Remove Objective Ping when the prisoner cage 1 is destroyed:
if EGroup_Count("eg_prisonerCage_1") == 0 and
	Objective_Exists(Objective_FreeTroops.title_id) == true
then
	Objective_PingRemove(Objective_FreeTroops.title_id, g_PrisonerCage_1_Ping_Objective)
end
-- Remove Objective Ping when the prisoner cage 2 is destroyed:
if EGroup_Count("eg_prisonerCage_2") == 0 and
	Objective_Exists(Objective_FreeTroops.title_id) == true
then
	Objective_PingRemove(Objective_FreeTroops.title_id, g_PrisonerCage_2_Ping_Objective)
end
-- Remove Objective Ping when the prisoner cage 3 is destroyed:
if EGroup_Count("eg_prisonerCage_3") == 0 and
	Objective_Exists(Objective_FreeTroops.title_id) == true
then
	Objective_PingRemove(Objective_FreeTroops.title_id, g_PrisonerCage_3_Ping_Objective)
end
-- Remove Objective Ping when the prisoner cage 4 is destroyed:
if EGroup_Count("eg_prisonerCage_4") == 0 and
	Objective_Exists(Objective_FreeTroops.title_id) == true
then
	Objective_PingRemove(Objective_FreeTroops.title_id, g_PrisonerCage_4_Ping_Objective)
end
-- Remove Objective Ping when the prisoner cage 5 is destroyed:
if EGroup_Count("eg_prisonerCage_5") == 0 and
	Objective_Exists(Objective_FreeTroops.title_id) == true
then
	Objective_PingRemove(Objective_FreeTroops.title_id, g_PrisonerCage_5_Ping_Objective)
end
-- Remove Objective Ping when the prisoner cage 6 is destroyed:
if EGroup_Count("eg_prisonerCage_6") == 0 and
	Objective_Exists(Objective_FreeTroops.title_id) == true
then
	Objective_PingRemove(Objective_FreeTroops.title_id, g_PrisonerCage_6_Ping_Objective)
end
-- Remove Objective Ping when the prisoner cage 10 is destroyed:
if EGroup_Count("eg_prisonerCage_10") == 0 and
	Objective_Exists(Objective_FreeTroops.title_id) == true
then
	Objective_PingRemove(Objective_FreeTroops.title_id, g_PrisonerCage_10_Ping_Objective)
end

end

-- Assigns & Check for Secondary Objective : Destroy All Soul Cages function Rule_DestroySoulCages_Objective() -- First check if Objective exists and add if not... if Event_IsAnyRunning() == false and Objective_Exists(Objective_DestroySoulCages.title_id) == false then -- Create( & Assign) the objective as a secondary one Util_ObjectiveCreate(Objective_DestroySoulCages, false)

	-- Add Sub-Objectives to Destroy Soul Cages
	Rule_AddInterval(Rule_DestroyCage_Corrosion_Objective,1)

-- if the objective exists & all the soul cages are destroyed
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_DestroySoulCages.title_id) == true and
	EGroup_Count("eg_soulCage_Objective") == 0
then
	-- Play Initial IE: All Soul Cages Are Destroyed
	Util_StartIntel(EVENTS.IE_SoulCage_NoneLeft)
	
	-- Complete the Objective & Remove the Rule
	Util_ObjectiveComplete(Objective_DestroySoulCages.title_id)
	Rule_Remove(Rule_DestroySoulCages_Objective)

-- if the objective exists & first soul cage is destroyed
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_DestroySoulCages.title_id) == true and
	EGroup_Count("eg_soulCage_Objective") == 3 and
	g_ie_SoulCage_Destroyed[1] == false
then
	-- Play IE: First Soul Cages is Destroyed
	Util_StartIntel(EVENTS.IE_SoulCage_First_Destroyed)
	
	-- So IE Doesn't Play Again
	g_ie_SoulCage_Destroyed[1] = true

-- if the objective exists & two soul cages are destroyed
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_DestroySoulCages.title_id) == true and
	EGroup_Count("eg_soulCage_Objective") == 2 and
	g_ie_SoulCage_Destroyed[2] == false
then
	-- NO IE FOR WHEN SECOND CAGE IS DESTROYED
	
	-- So IE Doesn't Play Again
	g_ie_SoulCage_Destroyed[2] = true	
	
-- if the objective exists & three soul cages are destroyed
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_DestroySoulCages.title_id) == true and
	EGroup_Count("eg_soulCage_Objective") == 1 and
	g_ie_SoulCage_Destroyed[3] == false
then
	-- Play IE: Third Soul Cages is Destroyed (Only One Left)
	Util_StartIntel(EVENTS.IE_SoulCage_OneLeft)
	
	-- So IE Doesn't Play Again
	g_ie_SoulCage_Destroyed[3] = true
end

end

-- Assigns & Check for Sub-Secondary Objective : Destroy Soul Cage: Corrosion function Rule_DestroyCage_Corrosion_Objective() -- Confirm the Primary Objective Exists & check if the Sub-Objective exists & add sub if not... if Event_IsAnyRunning() == false and Objective_Exists(Objective_DestroySoulCages.title_id) == true and Objective_GetState(Objective_DestroySoulCages.title_id) ~= OS_Complete and Objective_Exists(Objective_DestroyCage_Corrosion.title_id) == false then -- Create (Assign) the objective as a sub-secondary one Objective_SubAdd(Objective_DestroyCage_Corrosion, Objective_DestroySoulCages.title_id)

	-- Enable the use of the Corrosion Skill
	Rule_AddInterval(Rule_SoulPower_Corrosion, 30)
	
	--Associate a Ping with the Objective on the Objective Screen
	g_SoulCage_Corrosion_Ping_Objective = Objective_PingMarker(Objective_DestroyCage_Corrosion.title_id, "mkr_soulCage_4", true, attack)
	
	-- Set up a ping on the ingame screen & reveal FOW for 10 sec:
	Ping_Marker("mkr_soulCage_4", false, "default")
	FOW_RevealMarker("mkr_soulCage_4", 10)
	
	-- Add Next Sub-Objective
	Rule_AddInterval(Rule_DestroyCage_SoulStorm_Objective,1)

-- if the objective exists & the soul cage is destroyed
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_DestroyCage_Corrosion.title_id) == true and
	EGroup_Count("eg_soulCage_4") == 0
then
	-- Complete the Objective & Remove the Rule
	Util_ObjectiveComplete(Objective_DestroyCage_Corrosion.title_id)
	Rule_Remove(Rule_DestroyCage_Corrosion_Objective)
	
	-- Stop the Use of the Corrosion Skill
	Rule_Remove(Rule_SoulPower_Corrosion)
end	

end

-- Assigns & Check for Sub-Secondary Objective : Destroy Soul Cage: SoulStorm function Rule_DestroyCage_SoulStorm_Objective() -- Confirm the Primary Objective Exists & check if the Sub-Objective exists & add sub if not... if Event_IsAnyRunning() == false and Objective_Exists(Objective_DestroySoulCages.title_id) == true and Objective_GetState(Objective_DestroySoulCages.title_id) ~= OS_Complete and Objective_Exists(Objective_DestroyCage_SoulStorm.title_id) == false then -- Create (Assign) the objective as a sub-secondary one Objective_SubAdd(Objective_DestroyCage_SoulStorm, Objective_DestroySoulCages.title_id)

	-- Enable Soul Storm skill
	Rule_AddInterval(Rule_SoulPower_SoulStorm, 45)
	
	--Associate a Ping with the Objective on the Objective Screen
	g_SoulCage_RendSoul_Ping_Objective = Objective_PingMarker(Objective_DestroyCage_SoulStorm.title_id, "mkr_soulCage_5", true, attack)
	
	-- Set up a ping on the ingame screen & reveal FOW for 10 sec:
	Ping_Marker("mkr_soulCage_5", false, "default")
	FOW_RevealMarker("mkr_soulCage_5", 10)
	
	-- Add Next Sub-Objective
	Rule_AddInterval(Rule_DestroyCage_ScreamOfDammed_Objective,1)

-- if the objective exists & all the soul cage is destroyed
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_DestroyCage_SoulStorm.title_id) == true and
	EGroup_Count("eg_soulCage_5") == 0
then
	-- Complete the Objective & Remove the Rule
	Util_ObjectiveComplete(Objective_DestroyCage_SoulStorm.title_id)
	Rule_Remove(Rule_DestroyCage_SoulStorm_Objective)
	
	-- Stop the Use of the Soul Storm Skill
	Rule_Remove(Rule_SoulPower_SoulStorm)
end	

end

-- Assigns & Check for Sub-Secondary Objective : Destroy Soul Cage: ScreamOfDammed function Rule_DestroyCage_ScreamOfDammed_Objective() -- Confirm the Primary Objective Exists & check if the Sub-Objective exists & add sub if not... if Event_IsAnyRunning() == false and Objective_Exists(Objective_DestroySoulCages.title_id) == true and Objective_GetState(Objective_DestroySoulCages.title_id) ~= OS_Complete and Objective_Exists(Objective_DestroyCage_ScreamOfDammed.title_id) == false then -- Create (Assign) the objective as a sub-secondary one Objective_SubAdd(Objective_DestroyCage_ScreamOfDammed, Objective_DestroySoulCages.title_id)

	-- Enable Scream of the Dammed
	Rule_AddInterval(Rule_SoulPower_ScreamOfDammed, 45)
	
	--Associate a Ping with the Objective on the Objective Screen
	g_SoulCage_Sadisim_Ping_Objective = Objective_PingMarker(Objective_DestroyCage_ScreamOfDammed.title_id, "mkr_soulCage_6", true, attack)
	
	-- Set up a ping on the ingame screen & reveal FOW for 10 sec:
	Ping_Marker("mkr_soulCage_6", false, "default")
	FOW_RevealMarker("mkr_soulCage_6", 10)
	
	-- Add Next Sub-Objective
	Rule_AddInterval(Rule_DestroyCage_PiercingVision_Objective,1)

-- if the objective exists & all the soul cage is destroyed
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_DestroyCage_ScreamOfDammed.title_id) == true and
	EGroup_Count("eg_soulCage_6") == 0
then
	-- Complete the Objective & Remove the Rule
	Util_ObjectiveComplete(Objective_DestroyCage_ScreamOfDammed.title_id)
	Rule_Remove(Rule_DestroyCage_ScreamOfDammed_Objective)
	
	-- Stop the Use of the Scream of the Dammed Skill
	Rule_Remove(Rule_SoulPower_ScreamOfDammed)
end	

end

-- Assigns & Check for Sub-Secondary Objective : Destroy Soul Cage: Piercing Vision function Rule_DestroyCage_PiercingVision_Objective() -- Confirm the Primary Objective Exists & check if the Sub-Objective exists & add sub if not... if Event_IsAnyRunning() == false and Objective_Exists(Objective_DestroySoulCages.title_id) == true and Objective_GetState(Objective_DestroySoulCages.title_id) ~= OS_Complete and Objective_Exists(Objective_DestroyCage_PiercingVision.title_id) == false then -- Create (Assign) the objective as a sub-secondary one Objective_SubAdd(Objective_DestroyCage_PiercingVision, Objective_DestroySoulCages.title_id)

	-- Enable Piercing Vision
	Rule_AddInterval(Rule_SoulPower_PiercingVision,10)
	
	-- Plays IE & Actually Allows the soul powers to start being casted
	Rule_AddOneShot(Rule_Start_Using_Soul_Powers, 30)
	
	--Associate a Ping with the Objective on the Objective Screen
	g_SoulCage_PiercingVision_Ping_Objective = Objective_PingMarker(Objective_DestroyCage_PiercingVision.title_id, "mkr_soulCage_3", true, attack)
	
	-- Set up a ping on the ingame screen & reveal FOW for 10 sec:
	Ping_Marker("mkr_soulCage_3", false, "default")
	FOW_RevealMarker("mkr_soulCage_3", 10)
	
	-- Show Objective Screen
	Objective_ShowScreen()

-- if the objective exists & all the soul cage is destroyed
elseif Event_IsAnyRunning() == false and
	Objective_Exists(Objective_DestroyCage_PiercingVision.title_id) == true and
	EGroup_Count("eg_soulCage_3") == 0
then
	-- Complete the Objective & Remove the Rule
	Util_ObjectiveComplete(Objective_DestroyCage_PiercingVision.title_id)
	Rule_Remove(Rule_DestroyCage_PiercingVision_Objective)
	
	-- Stop the Use of the Piercing Vision Skill
	Rule_Remove(Rule_SoulPower_PiercingVision)
end	

end


-- END OF ALL " OBJECTIVES " RULES

-- Plays IE & Actually Allows the soul powers to start being casted function Rule_Start_Using_Soul_Powers() --Play IE: First Time using a soul power Util_StartIntel(EVENTS.IE_UseSoulCages)

-- Enable the Soul Powers to now be used
g_soulPower_enabled_Corrosion = true
g_soulPower_enabled_PiercingVision = true
g_soulPower_enabled_ScreamofDammed = true

end

--Handles the Delayed Tech-ing & Activation of Enemy Bases & granting of research function Rule_Tech_And_Activate_Tier_One() -- Change Target Location for when a squad is told to retreat (Retreat Toward Main Base HQ) g_retreat_target = Marker_GetPosition(Marker_FromName("mkr_hq_1", "basic_marker"))

-- Rule For Vect Attacks to Start
Rule_AddInterval(Rule_VectAttack, g_timer_vectAttack)

-- Sync Production Rules for After Player Builds HQ
Rule_AddInterval(Rule_Production_East_Base, g_timer_eastBase)
Rule_AddInterval(Rule_Production_Main_Base, g_timer_mainBase)
Rule_AddInterval(Rule_Production_North_Base, g_timer_northBase)
Rule_AddInterval(Rule_Production_NorthWest_Base, g_timer_northWestBase)
Rule_AddInterval(Rule_Production_West_Base, g_timer_westBase)
Rule_AddInterval(Rule_Production_VectBase, g_timer_vectBase)

-- Activate East Base: Warrior, Mandrakes & Jumping Hellions
g_base_activated_East = true

-- Activate West Base: Warriors, Jumping Scourge & Reavers
g_base_activated_West = true

-- Activate North Base Patrols: Patrolling Mandrakes & Patrolling Warp Beasts
g_patrol_activated_North = true

--Archon & Raven Air Defense : Activated here since these raven only attack Air Units & hopefully the early activation will help with letting them get both ravens up before attacking
g_base_activated_Vect = true

end

--Handles the Delayed Tech-ing & Activation of Enemy Bases & granting of research function Rule_Tech_And_Activate_Tier_Two() --Taunt Player (Since Tiered Up) Util_StartIntel(EVENTS.IE_Taunt_One)

-- Jumping Raiders & Troops from Main Base
g_base_activated_Main = true	

-- Jumping Scourge & Mandrakes
g_base_activated_SouthEast = true

-- Main Base Warp beasts for Vect:
g_vectSupport_warpBeast	=	true

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

-- Change Amount of Time between Vect Attacks
g_timer_vectAttack = 360

-- Grant Mandrake Cloaking
Player_GrantResearch(g_Player2, "dark_eldar_infiltration_mandrake_research")
Player_GrantResearch(g_Player3, "dark_eldar_infiltration_mandrake_research")

-- Increase Mandrake Damage
Player_GrantResearch(g_Player2, "dark_eldar_upgrade_mandrake_melee")
Player_GrantResearch(g_Player3, "dark_eldar_upgrade_mandrake_melee")

-- Increase Vechicle Armor
Player_GrantResearch(g_Player2, "dark_eldar_upgrade_vehicle_armor")
Player_GrantResearch(g_Player3, "dark_eldar_upgrade_vehicle_armor")
Player_GrantResearch(g_Player4, "dark_eldar_upgrade_vehicle_armor")

-- Add DOT to Melee Attacks
Player_GrantResearch(g_Player2, "dark_eldar_poisoned_blades_research")
Player_GrantResearch(g_Player3, "dark_eldar_poisoned_blades_research")

-- Increase Weapon Accuracy
Player_GrantResearch(g_Player2, "dark_eldar_upgrade_soulseeker_ammunition")
Player_GrantResearch(g_Player3, "dark_eldar_upgrade_soulseeker_ammunition")

-- Upgrade Reaver Damage
Player_GrantResearch(g_Player2, "dark_eldar_reaver_targeting_research")
Player_GrantResearch(g_Player3, "dark_eldar_reaver_targeting_research")

-- Stinger for Haemonculus
Player_GrantResearch(g_Player2, "dark_eldar_stinger_research")
Player_GrantResearch(g_Player3, "dark_eldar_stinger_research")

-- Soul Destruction for Haemonculus
Player_GrantResearch(g_Player2, "dark_eldar_soul_destruction_research")
Player_GrantResearch(g_Player3, "dark_eldar_soul_destruction_research")

-- Increase Commander & Leader Health
Player_GrantResearch(g_Player2, "dark_eldar_upgrade_commander_health")
Player_GrantResearch(g_Player3, "dark_eldar_upgrade_commander_health")

-- Increase Melee Damage for Leaders :Power Blades
Player_GrantResearch(g_Player2, "dark_eldar_upgrade_power_scythe")
Player_GrantResearch(g_Player3, "dark_eldar_upgrade_power_scythe")

-- Increase Ranged Damage for Leaders : Splinter Cannons
Player_GrantResearch(g_Player2, "dark_eldar_upgrade_power_scythe")
Player_GrantResearch(g_Player3, "dark_eldar_upgrade_power_scythe")

-- Increase Power (Probably useless for the scenario)
Player_GrantResearch(g_Player2, "dark_eldar_upgrade_power_1")
Player_GrantResearch(g_Player3, "dark_eldar_upgrade_power_1")

-- Increase Req (Probably useless for the scenario)
Player_GrantResearch(g_Player2, "dark_eldar_upgrade_requisition_1")
Player_GrantResearch(g_Player3, "dark_eldar_upgrade_requisition_1")

-- Give Archon the Crucible of Malediction Skill
Player_GrantResearch(g_Player2, "dark_eldar_crucible_of_malediction_research")

-- Increase size of Archon Squad -- Add More Retinue
Player_GrantResearch(g_Player2, "dark_eldar_upgrade_retinue_size_1")
g_number_incubi	=	3

end

--Handles the Delayed Tech-ing & Activation of Enemy Bases & granting of research function Rule_Tech_And_Activate_Tier_Three() --Taunt Player (Since Tiered Up) Util_StartIntel(EVENTS.IE_Taunt_Two)

--Stop the Capturing of Strategic Points & Relics
g_canCaptureStrat	=	false
g_canCaptureRelic	=	false

-- North Base: Talos & Ravens
g_base_activated_North = true	

-- NorthWest Base: Haemonculus & Wychs
g_base_activated_NorthWest = true

-- SouthWest Base: Wych, Haemonculus, Talos & Raven
g_base_activated_SouthWest = true

-- Main Base Ravagers for Vect:
g_vectSupport_ravager = true

-- Enable the Soul Power
g_soulPower_enabled_SoulStorm = true

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

-- Change Amount of Time between Vect Attacks
g_timer_vectAttack = 240

-- Increase size of Archon Squad -- Add More Retinue
Player_GrantResearch(g_Player2, "dark_eldar_upgrade_retinue_size_2")
g_number_incubi	=	4

-- Further Increase Vechicle Armor
Player_GrantResearch(g_Player2, "dark_eldar_upgrade_vehicle_armor_2")
Player_GrantResearch(g_Player3, "dark_eldar_upgrade_vehicle_armor_2")
Player_GrantResearch(g_Player4, "dark_eldar_upgrade_vehicle_armor_2")

-- Increase Commander & Leader Health
Player_GrantResearch(g_Player2, "dark_eldar_upgrade_commander_health_2")
Player_GrantResearch(g_Player3, "dark_eldar_upgrade_commander_health_2")

-- 2nd Increase Melee Damage for Leaders
Player_GrantResearch(g_Player2, "dark_eldar_upgrade_agonizer")
Player_GrantResearch(g_Player3, "dark_eldar_upgrade_agonizer")

-- Grant Talos Wildfire Skill
Player_GrantResearch(g_Player2, "dark_eldar_wildfire_research")
Player_GrantResearch(g_Player3, "dark_eldar_wildfire_research")

-- Increase Soul Harvesting (Probably useless for the scenario)
Player_GrantResearch(g_Player2, "dark_eldar_soulharvest_research")
Player_GrantResearch(g_Player3, "dark_eldar_soulharvest_research")

-- Increase Power (Probably useless for the scenario)
Player_GrantResearch(g_Player2, "dark_eldar_upgrade_power_2")
Player_GrantResearch(g_Player3, "dark_eldar_upgrade_power_2")

-- Increase Req (Probably useless for the scenario)
Player_GrantResearch(g_Player2, "dark_eldar_upgrade_requisition_2")
Player_GrantResearch(g_Player3, "dark_eldar_upgrade_requisition_2")

end


-- 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_Archon
	-- Rule_Produce_Haemonculus
	-- Rule_Produce_Hellion
	-- Rule_Produce_Mandrake
		-- Rule_Produce_Mandrake_Full
	-- Rule_Produce_Raider
	-- Rule_Produce_Ravager
		-- Rule_Produce_Ravager_FullyUpgraded
	-- Rule_Produce_Raven
	-- Rule_Produce_Reaver
	-- Rule_Produce_Scourge
		-- Rule_Produce_Scourge_FullDarkLance
	-- Rule_Produce_Slave (Fast Repairing version of Builder)
	-- Rule_Produce_Talos
	-- Rule_Produce_WarpBeast
	-- Rule_Produce_Warrior
		-- Rule_Produce_Warrior_Full
	-- Rule_Produce_Wych
	
	-- "dark_eldar_squad_dais_of_destruction" (is the objective for the level so not need

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

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

end

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

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

end

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

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

end

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

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

end

-- Produce a mandrake from Building at Marker for g_Player2 & Assign it to SGroup(squadName) if building exists function Rule_Produce_Mandrake_Full(squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a mandrake & return "true" Util_CreateSquadsAtMarkerEx(g_Player2, squadName, "dark_eldar_squad_mandrake", markerName, 1,6) return true end

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

end

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

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

end

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

	-- Random Chance of Upgrading to Anti-Infantry
	if World_GetRand(0,4) < 2
	then
		-- Upgrade to Anti Infantry Weapon Upgrades
		Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName(squadName), 1),"dark_eldar_disintegrator_ravager", 1)
		Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName(squadName), 1),"dark_eldar_disintegrator_ravager_2", 1)
		Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName(squadName), 1),"dark_eldar_disintegrator_ravager_3", 1)
	end
	
	return true
end

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

end

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

	-- Upgrade to Anti Infantry Weapon Upgrades
	Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName(squadName), 1),"dark_eldar_disintegrator_ravager", 1)
	Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName(squadName), 1),"dark_eldar_disintegrator_ravager_2", 1)
	Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName(squadName), 1),"dark_eldar_disintegrator_ravager_3", 1)
	return true
end

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

end

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

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

end

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

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

end

-- Produce a scourge from Building at Marker for g_Player2 & Assign it to SGroup(squadName) if building exists function Rule_Produce_Scourge(squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a scourge & return "true" Util_CreateSquadsAtMarkerEx(g_Player2, squadName, "dark_eldar_squad_scourge_sp_dxp3", markerName, 1,4)

	-- Give the Scourge their Dark Lance
	local darkLance = World_GetRand(0,4)
	
	Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName(squadName), 1),"dark_eldar_dark_lance_scourge", darkLance)
	return true
end

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

end

-- Produce a scourge from Building at Marker for g_Player2 & Assign it to SGroup(squadName) if building exists function Rule_Produce_Scourge_FullDarkLance(squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a scourge & return "true" Util_CreateSquadsAtMarkerEx(g_Player2, squadName, "dark_eldar_squad_scourge_sp_dxp3", markerName, 1,6)

	-- Give the Scourge their Dark Lance
	Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName(squadName), 1),"dark_eldar_dark_lance_scourge", 4)
	return true
end

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

end

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

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

end

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

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

end

-- Produce a warp beast from Building at Marker for g_Player2 & Assign it to SGroup(squadName) if building exists function Rule_Produce_WarpBeast(squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a WarpBeast, Add Leader & return "true" Util_CreateSquadsAtMarker(g_Player2, squadName, "dark_eldar_squad_warp_beast", markerName, 1) SGroup_AddLeaders(squadName) return true end

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

end

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

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

end

-- Produce a full squad of warriors from Building at Marker for g_Player2 & Assign it to SGroup(squadName) if building exists function Rule_Produce_Warrior_Full(squadName, buildingName, markerName) -- if building still exists if EGroup_Count(buildingName) == 1 then -- Create a full warrior squad with leader & return "true" Util_CreateSquadsAtMarkerEx(g_Player2, squadName, "dark_eldar_squad_warrior", markerName, 1,6) SGroup_AddLeaders(squadName) return true end

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

end

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

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

end

-- END OF ALL " UNIT PRODUCTION " 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")

-- Get Attack Target For the Enemy
g_attack_target = SGroup_GetPosition(Player_GetSquads(g_Player1))

-- Cage Defense Troops
g_cageDefense_warrior_status[1] = Rule_Squad_Tactics("sg_cageDefense_warrior1", g_cageDefense_warrior_status[1], g_skill_warriors)
g_cageDefense_warrior_status[2] = Rule_Squad_Tactics("sg_cageDefense_warrior2", g_cageDefense_warrior_status[2], g_skill_warriors)
g_cageDefense_scourge_status[1] = Rule_Squad_Tactics("sg_cageDefense_scourge", g_cageDefense_scourge_status[1], 0)
g_cageDefense_reaver_status[1] = Rule_Squad_Tactics("sg_cageDefense_reaver", g_cageDefense_reaver_status[1], 0)

-- Center Base
g_centerBase_reaver_status[1] = Rule_Squad_Tactics("sg_centerBase_reaver", g_centerBase_reaver_status[1], 0)
g_centerBase_mandrake_status[1] = Rule_Squad_Tactics("sg_centerBase_mandrake", g_centerBase_mandrake_status[1], g_skill_mandrakes)
g_centerBase_scourge_status[1] = Rule_Squad_Tactics("sg_centerBase_scourge", g_centerBase_scourge_status[1], 0)

-- East Base
g_eastBase_hellions_status[1] = Rule_Squad_Tactics("sg_eastBase_hellions", g_eastBase_hellions_status[1], g_skill_eastBase_hellion_jump)
g_eastBase_warrior_status[1] = Rule_Squad_Tactics("sg_eastBase_warrior", g_eastBase_warrior_status[1], g_skill_warriors)
g_eastBase_mandrake_status[1] = Rule_Squad_Tactics("sg_eastBase_mandrake", g_eastBase_mandrake_status[1], g_skill_mandrakes)

-- Main Base
g_mainBase_raider_status[1] = Rule_Squad_Tactics("sg_mainBase_raider1", g_mainBase_raider_status[1], g_skill_raider)
g_mainBase_raider_status[2] = Rule_Squad_Tactics("sg_mainBase_raider2", g_mainBase_raider_status[2], g_skill_raider)
g_mainBase_ravager_status[1] = Rule_Squad_Tactics("sg_mainBase_ravager1", g_mainBase_ravager_status[1], 0)
g_mainBase_ravager_status[2] = Rule_Squad_Tactics("sg_mainBase_ravager2", g_mainBase_ravager_status[2], 0)
g_mainBase_warrior_status[1] = Rule_Squad_Tactics("sg_mainBase_warrior1", g_mainBase_warrior_status[1], g_skill_warriors)
g_mainBase_warrior_status[2] = Rule_Squad_Tactics("sg_mainBase_warrior2", g_mainBase_warrior_status[2], g_skill_warriors)

-- North Base
g_northBase_talos_status[1] = Rule_Squad_Tactics("sg_northBase_talos1", g_northBase_talos_status[1], g_skill_talos)
g_northBase_talos_status[2] = Rule_Squad_Tactics("sg_northBase_talos2", g_northBase_talos_status[2], g_skill_talos)
g_northBase_raven_status[1] = Rule_Squad_Tactics("sg_northBase_raven1", g_northBase_raven_status[1], g_skill_raven)
g_northBase_raven_status	[2] = Rule_Squad_Tactics("sg_northBase_raven2", g_northBase_raven_status[2], g_skill_raven)

-- North West Base
g_northWestBase_haemonculus_status[1] = Rule_Squad_Tactics("sg_northWestBase_haemonculus", g_northWestBase_haemonculus_status[1], g_skill_haemonculus)
g_northWestBase_wych_status[1] = Rule_Squad_Tactics("sg_northWestBase_wych", g_northWestBase_wych_status[1], g_skill_wych)

-- Patrol Squads:
g_centerBase_hellions_patrol_status[1] = Rule_Squad_Tactics("sg_centerBase_hellions_patrol", g_centerBase_hellions_patrol_status[1], 0)
g_northBase_warpBeast_patrol_status[1] = Rule_Squad_Tactics("sg_northBase_warpBeast_patrol", g_northBase_warpBeast_patrol_status[1], g_skill_warpbeasts)
g_northBase_mandrake_patrol_status[1] = Rule_Squad_Tactics("sg_northBase_mandrake_patrol", g_northBase_mandrake_patrol_status[1], 0)
g_southWestBase_warpbeast_patrol_status[1] = Rule_Squad_Tactics("sg_southWestBase_warpbeast_patrol", g_southWestBase_warpbeast_patrol_status[1], g_skill_warpbeasts)

-- Slaves to Repair & Soul Harvest
g_slave_status[1] = Rule_Squad_Tactics("sg_slave_1", g_slave_status[1], g_skill_slave)
g_slave_status[2] = Rule_Squad_Tactics("sg_slave_2", g_slave_status[2], g_skill_slave)
g_slave_status[3] = Rule_Squad_Tactics("sg_slave_3", g_slave_status[3], g_skill_slave)
g_slave_status[4] = Rule_Squad_Tactics("sg_slave_4", g_slave_status[4], g_skill_slave)

-- South East Base
g_southEastBase_scourge_status[1] = Rule_Squad_Tactics("sg_southEastBase_scourge", g_southEastBase_scourge_status[1], g_skill_southEastBase_scourge_jump)
g_southEastBase_mandrakes_status[1] = Rule_Squad_Tactics("sg_southEastBase_mandrakes", g_southEastBase_mandrakes_status[1], g_skill_mandrakes)

-- South West Base
g_southWestBase_wych_status[1] = Rule_Squad_Tactics("sg_southWestBase_wych", g_southWestBase_wych_status[1], g_skill_wych)
g_southWestBase_haemonculus_status[1] = Rule_Squad_Tactics("sg_southWestBase_haemonculus", g_southWestBase_haemonculus_status[1], g_skill_haemonculus)
g_southWestBase_raven_status[1] = Rule_Squad_Tactics("sg_southWestBase_raven", g_southWestBase_raven_status[1], g_skill_raven)
g_southWestBase_reaver_status[1] = Rule_Squad_Tactics("sg_southWestBase_reaver_1", g_southWestBase_reaver_status[1], 0)
g_southWestBase_reaver_status[2] = Rule_Squad_Tactics("sg_southWestBase_reaver_2", g_southWestBase_reaver_status[2], 0)
g_southWestBase_talos_status[1] = Rule_Squad_Tactics("sg_southWestBase_talos", g_southWestBase_talos_status[1], g_skill_talos)

-- Vect Support:
g_vectSupport_warrior_status[1] = Rule_Squad_Tactics("sg_vectSupport_warrior", g_vectSupport_warrior_status[1], g_skill_warriors)
g_vectSupport_warpBeast_status[1] = Rule_Squad_Tactics("sg_vectSupport_warpBeast", g_vectSupport_warpBeast_status[1], g_skill_warpbeasts)
g_vectSupport_reaver_status[1] = Rule_Squad_Tactics("sg_vectSupport_reaver", g_vectSupport_reaver_status[1], 0)
g_vectSupport_ravager_status[1] = Rule_Squad_Tactics("sg_vectSupport_ravager", g_vectSupport_ravager_status[1], 0)

-- Vect Base : Archon & Air Defending Ravens
g_vectBase_archon_status[1] = Rule_Squad_Tactics("sg_vectBase_archon", g_vectBase_archon_status[1], g_skill_archon)
g_vectBase_raven_status[1] = Rule_Squad_Tactics("sg_vectBase_raven1", g_vectBase_raven_status[1], g_skill_raven_airDefense)
g_vectBase_raven_status[2] = Rule_Squad_Tactics("sg_vectBase_raven2", g_vectBase_raven_status[2], g_skill_raven_airDefense)

-- West Base
g_westBase_scourge_status[1] = Rule_Squad_Tactics("sg_westBase_scourge", g_westBase_scourge_status[1], g_skill_westBase_scourge_jump)
g_westBase_warrior_status[1] = Rule_Squad_Tactics("sg_westBase_warrior", g_westBase_warrior_status[1], g_skill_warriors)
g_westBase_reaver_status[1] = Rule_Squad_Tactics("sg_westBase_reaver_1", g_westBase_reaver_status[1], 0)
g_westBase_reaver_status[2] = Rule_Squad_Tactics("sg_westBase_reaver_2", g_westBase_reaver_status[2], 0)

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	

-- 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) > 5
	then
		-- Give Location To Retreat To
		Command_SquadPos(g_Player2, squad, SCMD_Move, g_retreat_target)
		squad_status = g_squad_retreating		
	
	-- Just Choose "Attack Target" & Attack Move if none of the above
	else
		-- Get the default Attack Targets For the AI Troops : Location of Player Base if it exists
		if EGroup_Exists("eg_player_HQ") and
			EGroup_Count("eg_player_HQ") > 0
		then
			g_attack_target = EGroup_GetPosition("eg_player_HQ")
		else
			g_attack_target = SGroup_GetPosition(Player_GetSquads(g_Player1))
		end
		
		-- Set Range for Target Tracking for Strategic Points:
		range = 150
		
		-- Override Attack Target for Locations of any Player Owned Relic, Critical or Strategic Points:
		if EGroup_ForEach(Player_GetEntities(g_Player1), Rule_Detect_Proximity_CapturePoints_Location)
		then
			-- Do Nothing... ForEach functions already did it
		
		-- Override Attack Target for Locations of any World Owned Relic, Critical or Strategic Points:
		elseif EGroup_Count("eg_world_points") > 0 and
			EGroup_ForEach("eg_world_points", Rule_Detect_Proximity_CapturePoints_Location)
		then
			-- Do Nothing... ForEach functions already did it
		end
		
		-- Attack Move to the Chosen Attack Target (Either default or the location of the strategic pt)
		Cmd_AttackMovePos(squad,g_attack_target)
	end

-- if currently in retreat mode
elseif squad_status == g_squad_retreating
then
	-- Check for Reinforce (based on squad size being less then X %)
	if Squad_GetMax(SGroup_GetSpawnedSquadAt(squad,1)) > Squad_Count(SGroup_GetSpawnedSquadAt(squad,1)) and
		SGroup_GetAvgLoadout(squad) < g_reinforce_percent
	then
		Command_Squad(g_Player2, squad, SCMD_ReinforceTrooper)
		squad_status = g_squad_retreating

	-- else set to attack mode if the morale is restored
	elseif SGroup_IsMoraleBroken(squad,true) == false
	then
		squad_status = g_squad_attacking
		Cmd_AttackMovePos(squad,g_attack_target)
	end

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

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

-- Prep for Squad Jumping (Reinforcing & Moving towards jump zone)
elseif squad_status == g_squad_jump_prep
then
	-- East Base Sends it hellions to Jump Location 1
	if skill_id == g_skill_eastBase_hellion_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
	
	-- West Base Sends Scourge to Jump Location 2
	elseif skill_id == g_skill_westBase_scourge_jump
	then
		-- Check if arrived 
		if Prox_AllSquadsNearMarker(squad, "mkr_AI_jumpLocation2")
		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_jumpLocation2")
		end
	
	-- South East Base Sends it Scourge to Jump Location 3
	elseif skill_id == g_skill_southEastBase_scourge_jump
	then
		-- Check if arrived 
		if Prox_AllSquadsNearMarker(squad, "mkr_AI_jumpLocation3")
		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_jumpLocation3")
		end
	end

-- Actual Squad Jumping
elseif squad_status == g_squad_jump_ready
then
	-- East Base Hellions: if morale is broken -- retreat and heal up
	if SGroup_IsMoraleBroken(squad,true) and
		skill_id == g_skill_eastBase_hellion_jump
	then
		Cmd_JumpToMarker(squad, "mkr_AI_landLocation1")
		squad_status = g_squad_jump_prep
	
	-- West Base Scourge: if morale is broken -- retreat and heal up
	elseif SGroup_IsMoraleBroken(squad,true) and
		skill_id == g_skill_westBase_scourge_jump
	then
		Cmd_JumpToMarker(squad, "mkr_AI_landLocation2")
		squad_status = g_squad_jump_prep
	
	-- South East Base Scourge: if morale is broken -- retreat and heal up
	elseif SGroup_IsMoraleBroken(squad,true) and
		skill_id == g_skill_southEastBase_scourge_jump
	then
		Cmd_JumpToMarker(squad, "mkr_AI_landLocation3")
		squad_status = g_squad_jump_prep
		
	--Other Jump to Next Location & Attack from the New Direction
	else
		jumpLoc = World_GetRand(1, 10)
		Cmd_JumpToMarker(squad, "mkr_AI_landLocation"..jumpLoc)
		squad_status = g_squad_jump_attack
	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
	-- Only jump to a new location if under attack at current location
	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)
	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)
	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
	local blueprintTable = Util_MakeBlueprintTable("relic_struct", "strategic_point_flag", "strategic_objective_struct")
	
	if Prox_SquadsInProximityOfEntities(squad, "building_target", range, true) and
		EGroup_ContainsBlueprints("building_target", blueprintTable, false) == false
	then
		return true
	end	
end

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

	if SGroup_IsVehicle("skill_target") and
		Prox_AllSquadsNearMarker("skill_target", "mkr_hq_4") == false and
		Prox_SquadsInProximityOfSquads(squad, "skill_target", range, true)
	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-DE 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-DE 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-DE 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	

-- Haemonculus Skills
if skillID == g_skill_haemonculus
then
	range = 35
	
	-- Stinger : Causes DoT on Enemy Infantry Squad
	if SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity) and
		SGroup_Count("skill_target") > 0 and
		Cmd_CastAbilitySGroup(squad, "dark_eldar_stinger", "skill_target")
	then
		return true
	
	-- Torture Amp : Slows Movement / Attack Speed on Enemy Infantry
	elseif SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity) and
		SGroup_Count("skill_target") > 0 and
		Cmd_CastAbilitySelf(squad, "dark_eldar_torture_amp")
	then
		return true
	
	-- Try & Cast Soul Destruction Ability if enemy troops in the area (SKill won't actually fire unless there are souls in the area)
	elseif SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity) and
		SGroup_Count("skill_target") > 0
	then
		Squad_SoulDestruction(SGroup_GetSpawnedSquadAt(squad,1))
		
		-- Return False, since it might not have fired off
		return false
	end

-- Warrior Terrorfex Grenades
elseif skillID == g_skill_warriors
then
	range = 35
	
	-- Terrorfex Grenades on Enemy Infantry Squads (Needs Sybarite Leader)
	if SGroup_HasLeader(squad, true) and
		SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity) and
		SGroup_Count("skill_target") > 0 and
		Cmd_CastAbilitySGroup(squad, "dark_eldar_terrorfex_grenade", "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
	
	-- If Morale Not Broken -- 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
	
	-- If Morale Not Broken -- Try & Capture World Owned LPs
	elseif SGroup_IsMoraleBroken(squad,true) == false and
		EGroup_Count("eg_world_points") > 0 and
		EGroup_ForEach("eg_world_points", Rule_Detect_Proximity_CapturePoints)
	then
		return true
	end

-- Mandrakes -- Capturing & Infantry Targeting
elseif skillID == g_skill_mandrakes
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
	
	-- If Morale Not Broken -- 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
	
	-- If Morale Not Broken -- Try & Capture World Owned LPs
	elseif SGroup_IsMoraleBroken(squad,true) == false and
		EGroup_Count("eg_world_points") > 0 and
		EGroup_ForEach("eg_world_points", Rule_Detect_Proximity_CapturePoints)
	then
		return true
	end

-- Warp Beast Tame Skill (Restores Morale)
elseif skillID == g_skill_warpbeasts
then
	-- Tame Warp Beasts (Needs Beastmaster Leader)
	if SGroup_HasLeader(squad, true) and
		SGroup_IsMoraleBroken(squad,true) and
		Cmd_CastAbilitySelf(squad, "dark_eldar_tame_warp_beasts")
	then
		return true
	
	-- Give Back Leader if has been killed
	elseif SGroup_HasLeader(squad, true) == false
	then
		Command_Squad(g_Player2, squad, SCMD_ReinforceLeader)
		--SGroup_AddLeaders(squad)
		return true
	end

-- Wych Skill
elseif skillID == g_skill_wych
then
	-- Combat Drugs : Increase Movement / Attack Speed (Needs Wych Succubus Leader)
	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, "dark_eldar_combat_drugs")
	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
	
	-- If Morale Not Broken -- 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
	
	-- If Morale Not Broken -- Try & Capture World Owned LPs
	elseif SGroup_IsMoraleBroken(squad,true) == false and
		EGroup_Count("eg_world_points") > 0 and
		EGroup_ForEach("eg_world_points", Rule_Detect_Proximity_CapturePoints)
	then
		return true
	end

-- Talos : Wildfire -- Fires Attack in different direction  
elseif skillID == g_skill_talos
then
	range = 15
	
	-- Use Wildfire since nearby Infantry
	if 	SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity) and
		SGroup_Count("skill_target") > 0 and
		Cmd_CastAbilitySelf(squad, "dark_eldar_wildfire")
	then
		return true
	
	-- Use Wildfire since nearby Vehicles
	elseif SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity_Vehicles) and
		SGroup_Count("skill_target") > 0 and
		Cmd_CastAbilitySelf(squad, "dark_eldar_wildfire")
	then
		return true
	
	-- Use Wildfire since nearby Buildings
	elseif EGroup_ForEach(Player_GetEntities(g_Player1), Rule_Detect_Proximity_Buildings) and
		EGroup_Count("building_target") > 0 and
		Cmd_CastAbilitySelf(squad, "dark_eldar_wildfire")
	then
		return true
	
	-- Prioritize Infantry for attacks:
	elseif SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity) and
		SGroup_Count("skill_target") > 0
	then
		Cmd_AttackSGroup(squad, "skill_target")
		return true
	end

-- Raider : Jump on Top of Enemy Troops
elseif skillID == g_skill_raider
then
	
	range = 100
	
	-- Find an Enemy Infantry Squad in Range...
	if SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity) and
		SGroup_Count("skill_target") > 0
	then
		-- Jump in Raider on top of the infantry squad
		raiderattack_pos = Squad_GetPosition(SGroup_GetSpawnedSquadAt(SGroup_FromName("skill_target"), 1))
		Cmd_JumpToPos(squad, raiderattack_pos)
		return true
	end

-- Tortured Slave : Repair Vehciles
elseif skillID == g_skill_slave
then
	range = 50
	
	-- Find an Friendly Vehicle Squad in Range...
	if SGroup_ForEach(Player_GetSquads(g_Player2), Rule_Detect_Proximity_Vehicles) and
		SGroup_Count("skill_target") > 0 and
		SGroup_GetAvgHealth("skill_target") < 1			
	then
		-- Order Slave to Repair
		Command_SquadSquad(g_Player2, squad, SCMD_Repair, "skill_target")
		return true
	
	-- No One to repair so try soul harvesting
	else
		Squad_SoulHarvest(SGroup_GetSpawnedSquadAt(squad,1))
		return true
	end

-- Raven (Air Unit): Short Circuit Ability (Disables Vehicles / Buildings)
elseif skillID == g_skill_raven
then
	range = 35
	
	-- Use Short Circuit on Vehicles
	if SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity_Vehicles) and
		SGroup_Count("skill_target") > 0 and
		Cmd_CastAbilitySGroup(squad, "dark_eldar_short_circuit", "skill_target")
	then
		return true
	
	-- Use Short Circuit on Buildings (useless on most of them -- but maybe will get lucky & hit turret or building w/ guns)
	elseif EGroup_ForEach(Player_GetEntities(g_Player1), Rule_Detect_Proximity_Buildings) and
		EGroup_Count("building_target") > 0 and
		Cmd_CastAbilitySGroupE(squad, "dark_eldar_short_circuit", "building_target")
	then
		return true
	end

-- Raven (Air Unit Defense): Short Circuit Ability & Air Unit Targetting Only
elseif skillID == g_skill_raven_airDefense
then
	range = 1000
	
	-- Get all the Player Air Units
	SGroup_Clear("sg_playerAirUnits")	
	Util_GetSquadsByBP(SGroup_GetName(Player_GetSquads(g_Player1)), "sg_playerAirUnits", g_AirUnit_blueprint)
	
	-- If You Found an Player Air Unit outside of the players base
	if SGroup_Count("sg_playerAirUnits") > 0 and
		SGroup_ForEach("sg_playerAirUnits", Rule_Detect_Proximity_Vehicles_NotByPlayerBase) and
		SGroup_Count("skill_target") > 0
	then
		-- Try to Cast Short Circuit on the Air Unit & Attack it if can't cast skill
		if Cmd_CastAbilitySGroup(squad, "dark_eldar_short_circuit", "skill_target") == false
		then		
			-- target it
			Cmd_AttackSGroup(squad, "skill_target")
			return true
		end
	
	-- Else Return to Your own Base
	else
		Cmd_MoveToMarker(squad, "mkr_skimmerShop_11")
		return true
	end
	
	--Always return true, otherwise unit will attack normal units
	return true

-- Archon Commander
elseif skillID == g_skill_archon
then
	local blueprintTable = Util_MakeBlueprintTable("dark_eldar_squad_archon")
	range = 40
	
	-- Crucible on Enemy Infantry Squads (Squad needs Archon)
	if SGroup_ContainsBlueprints(squad, blueprintTable, true) and
		SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity) and
		SGroup_Count("skill_target") > 0 and
		Cmd_CastAbilitySGroup(squad, "dark_eldar_crucible", "skill_target")
	then
		return true
	
	-- Animus Vitae on Enemy Infantry Squads (Squad needs Archon)
	elseif SGroup_ContainsBlueprints(squad, blueprintTable, true) and
		SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity) and
		SGroup_Count("skill_target") > 0 and
		Cmd_CastAbilitySGroup(squad, "dark_eldar_animus_vitae", "skill_target")
	then
		return true
	
	-- Add the Incubi -- Squad Contains the Archon & still has room to reinforce incubi
	elseif SGroup_ContainsBlueprints(squad, blueprintTable, true) and

-- Squad_GetMax(SGroup_GetSpawnedSquadAt(squad,1)) > Squad_Count(SGroup_GetSpawnedSquadAt(squad,1)) and SGroup_CountLeaders(squad) < g_number_incubi then Cmd_ReinforceLeader(squad,1) return true

	-- Else Target Nearby Infantry
	elseif SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Detect_Proximity) and
		SGroup_Count("skill_target") > 0
	then
		Cmd_AttackSGroup(squad, "skill_target")
		return true
	end
end

end


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


-- LEVEL FLOW -- Rule_PrisonerCage_FreeCage : Check For Destroyed Cages so know to free the prisoner from it (& Give Resources) -- Rule_PrisonerCage_BaseActivation : Controls Attacks as the player nears the prisoner cages & small bases -- Rule_RevealBaseWarning() : Warn the Player about the South East & West Bases & Reveal Fog of War on them -- Rule_SlaveCaravel_Attack : Slave Caravels use their Soul Shock Skill

-- Check For Destroyed Cages so know to free the prisoner from it (& Give Resources) function Rule_PrisonerCage_FreeCage() -- Loop Through All The Prisoner Cages for i =1,10 do -- If Cage is Destroyed (& Yet to Free this prisoner) if EGroup_Count("eg_prisonerCage_"..i) == 0 and g_array_prisonerCage_freed[i] == false then -- Free the Prisoner & give leader if possible Util_CreateSquadsAtMarkerEx(g_Player1, "sg_player_freePrisoner"..i,g_array_prisonerCage_prisoner[i], "mkr_prisonerCage_"..i, 1,20) SGroup_AddLeaders("sg_player_freePrisoner"..i) g_array_prisonerCage_freed[i] = true

		-- Give the Player Resources (RT_Requisition, RT_Power) for Freeing Prisoner
		if g_raceName == "necron_race"
		then
			-- If Necron, Only Give Power
			Player_AddResource(g_Player1, RT_Power, g_amountPowerToGiveNecron_PerCage)
		else
			-- Otherwise give both
			Player_AddResource(g_Player1, RT_Requisition, g_amountRequisitionToGivePlayer_PerCage)
			Player_AddResource(g_Player1, RT_Power, g_amountPowerToGivePlayer_PerCage)
		end
		
		-- Give the Orks Some Population
		if g_raceName == "ork_race"
		then
			Player_AddResource(g_Player1, RT_Pop, 10)
		end
		
		-- Increment the Number of Prisoners Freed
		g_prisonerCage_numFreed  = g_prisonerCage_numFreed  + 1
	end
	
	-- if the cage is still alive, reveal fog of war around it
	if EGroup_Count("eg_prisonerCage_"..i) == 1
	then
		FOW_RevealMarker("mkr_prisonerCage_"..i, 10)
	end
end

-- First Prisoner Freed...Play IE
if g_prisonerCage_numFreed == 1 and
	g_ie_FirstCage_Played == false
then
	g_ie_FirstCage_Played = true
	
	-- Play IE for first cage freed
	Util_StartIntel(g_ie_FirstCage_Array[g_intelEvent_raceId])
end

-- Most of the Prisoners Freed...Play IE to Attack Base
if g_prisonerCage_numFreed == 5 and
	g_ie_FreeMostTroops_Played == false
then
	g_ie_FreeMostTroops_Played = true
	
	-- Play IE for most troops freed
	Util_StartIntel(g_ie_FreeMostTroops_Array[g_intelEvent_raceId])
end
	
-- If ALL Prisoners have been freed...Remove the Rule
if g_prisonerCage_numFreed >= 10
then
	Rule_Remove(Rule_PrisonerCage_FreeCage)
end

end

-- Check for Activation of Base function Rule_PrisonerCage_BaseActivation() -- Get the rough position of the Players Troops (somewhere for the units to attack move to) g_attack_target = SGroup_GetPosition(Player_GetSquads(g_Player1))

-- If the Player is nearing Prisoner Cage 10 (First Cage)
if g_prisonerCage10_activated == false and
	Player_AreSquadsNearMarker(g_Player1, "mkr_activate_prisonerCage_10")
then
	-- Activate the Cage (Troops Sent)
	g_prisonerCage10_activated = true

	-- order the initial troops to attack player
	if SGroup_Count("sg_prisonerCage_firstTroops") > 0
	then
		Cmd_AttackMovePos("sg_prisonerCage_firstTroops", g_attack_target)
	end
end

-- If the Player is nearing First group of defence troops (Right Past First Cage)
if g_firstTroops_sent == false and
	Player_AreSquadsNearMarker(g_Player1, "mkr_sendFirstTroops")
then
	-- First Defense Troops Sent
	g_firstTroops_sent = true
	
	-- Play IE for Dark Eldar Attack
	Util_StartIntel(g_ie_EarlyDarkEldarCharge_Array[g_intelEvent_raceId])

	-- order the initial troops to attack player
	if SGroup_Count("sg_firstTroops") > 0
	then
		Cmd_AttackMovePos("sg_firstTroops", g_attack_target)
	end
end

-- If the Player is nearing Prisoner Cage 1/2
if g_hallOfBlood14_activated == false and
	Player_AreSquadsNearMarker(g_Player1, "mkr_activate_hallOfBlood14")
then
	-- Activate Hall of Blood by Prisoner Cage 1/2
	g_hallOfBlood14_activated = true

	-- order the initial troops to attack player
	if SGroup_Count("sg_hallOfBlood14_firstTroops") > 0
	then
		Cmd_AttackMovePos("sg_hallOfBlood14_firstTroops", g_attack_target)
	end
	
	-- Jump in Scourge Troops
	if SGroup_Count("sg_prisoner_scourge_jump_1") > 0 and
		SGroup_Count("sg_prisoner_scourge_jump_2") > 0
	then
		Cmd_JumpToMarker("sg_prisoner_scourge_jump_1","mkr_prisoner_scourge_jump_1")		
		Cmd_JumpToMarker("sg_prisoner_scourge_jump_2","mkr_prisoner_scourge_jump_2")
	end
end

-- If the Player is heading towards Prisoner Cage 3
if g_hallOfBlood15_activated  == false and
	Player_AreSquadsNearMarker(g_Player1, "mkr_activate_hallOfBlood15")
then
	-- Activate Hall of Blood & Skimmer Shop by Prisoner Cage 3
	g_hallOfBlood15_activated  = true
	g_skimmerShop10_activated = true
	
	-- order the initial troops to attack player
	if SGroup_Count("sg_hallOfBlood15_firstTroops") > 0
	then
		Cmd_AttackMovePos("sg_hallOfBlood15_firstTroops", g_attack_target)
	end
	if SGroup_Count("sg_skimmer10_firstTroops") > 0
	then
		Cmd_AttackMovePos("sg_skimmer10_firstTroops", g_attack_target)
	end
end

-- If the Player is nearing Prisoner Cage 3
if g_prisonerCage3_activated  == false and
	Player_AreSquadsNearMarker(g_Player1, "mkr_prisonerCage_3")
then
	-- Activate the Cage (Troops jumped In)
	g_prisonerCage3_activated = true
	
	-- Jump in Scourge Squads
	if SGroup_Count("sg_prisoner_scourge_jump_3") > 0 and
		SGroup_Count("sg_prisoner_scourge_jump_4") > 0
	then
		Cmd_JumpToMarker("sg_prisoner_scourge_jump_3","mkr_prisoner_scourge_jump_3")
		Cmd_JumpToMarker("sg_prisoner_scourge_jump_4","mkr_prisoner_scourge_jump_4")
	end
end

-- If the Player is nearing Raider Ambush Location (Right Past Prisoner Cage 3)
if g_patrol_activated_SouthWest == false and
	Player_AreSquadsNearMarker(g_Player1, "mkr_activate_hallOfBlood13")
then
	-- Activate Patrol from SouthWest Base
	g_patrol_activated_SouthWest  = true
	
	-- Play IE for First Raider Attack
	Util_StartIntel(EVENTS.IE_FirstRaiderAttack)
	
	-- Jump in the Scourge Squads
	if SGroup_Count("sg_prisoner_scourge_jump_5") > 0 and
		SGroup_Count("sg_prisoner_scourge_jump_6") > 0
	then
		Cmd_JumpToMarker("sg_prisoner_scourge_jump_5","mkr_prisoner_scourge_jump_5")
		Cmd_JumpToMarker("sg_prisoner_scourge_jump_6","mkr_prisoner_scourge_jump_6")
	end
	
	-- Jump in the Raiders w/ Troops
	if SGroup_Count("sg_prisoner_raider_jump_1") > 0 and
		SGroup_Count("sg_prisoner_raider_jump_2") > 0
	then
		Cmd_JumpToMarker("sg_prisoner_raider_jump_1","mkr_prisoner_raider_jump_1")
		Cmd_JumpToMarker("sg_prisoner_raider_jump_2","mkr_prisoner_raider_jump_2")
	end
end

-- If the player has just past the First Raider Ambush
if g_ie_baseRevealed == false and
	Player_AreSquadsNearMarker(g_Player1, "mkr_revealBase_warning")
then
	-- Play IE for Dark Eldar Attack
	Util_StartIntel(g_ie_ShowTwoBases_Array[g_intelEvent_raceId])
	
	-- Enable FOW Vision between Patrols & Player1
	World_EnablePlayerToPlayerFOW(g_Player1, g_Player3, false)
	
	-- Ping the Base Locations
	Ping_Marker("mkr_activate_southEast_base",false,attack)
	Ping_Marker("mkr_activate_southWest_base",false,attack)
	
	-- Warn the Player about the South East & West Bases & Reveal Fog of War on them
	Rule_AddInterval(Rule_RevealBaseWarning,5)
	g_ie_baseRevealed = true
end

-- If the Player is nearing Prisoner Cage 4
if g_prisonerCage4_activated == false and
	Player_AreSquadsNearMarker(g_Player1, "mkr_activate_prisonerCage4")
then
	-- Activate the Cage (Troops jumped In)
	g_prisonerCage4_activated = true
	
	-- Jump in the Hellions
	for i =1,3	do
		if SGroup_Count("sg_prisoner_hellion_jump_"..i) > 0
		then
			Cmd_JumpToMarker("sg_prisoner_hellion_jump_"..i,"mkr_prisoner_hellion_jump_"..i)
		end
	end
	
	-- Jump in the Raiders w/ Warriors
	if SGroup_Count("sg_prisoner_raider_jump_3") > 0
	then
		Cmd_JumpToMarker("sg_prisoner_raider_jump_3","mkr_prisoner_raider_jump_3")
	end
	
	if SGroup_Count("sg_prisoner_raider_jump_4") > 0
	then
		Cmd_JumpToMarker("sg_prisoner_raider_jump_4","mkr_prisoner_raider_jump_4")
	end
end

-- If the Player is nearing Prisoner Cage 5
if g_hallOfBlood10_activated  == false and
	Player_AreSquadsNearMarker(g_Player1, "mkr_activate_hallOfBlood10") and
	SGroup_Count("sg_hallOfBlood10_firstTroops") >0
then
	-- Activate Hall of Blood by Prisoner Cage 5
	g_hallOfBlood10_activated = true
	
	-- order the initial troops to attack player
	Cmd_AttackMovePos("sg_hallOfBlood10_firstTroops", g_attack_target)
end

-- If the Player is nearing Prisoner Cage 6
if g_prisonerCage6_activated == false and
	Player_AreSquadsNearMarker(g_Player1, "mkr_activate_prisonerCage6")
then
	g_prisonerCage6_activated = true
	
	-- Cast Combat Drugs on the Warriors... while Warriors attack
	if SGroup_Count("sg_prisoner_wych_1") > 0 and
		SGroup_Count("sg_prisoner_warrior_1") > 0
	then
		Cmd_CastAbilitySGroup("sg_prisoner_wych_1", "dark_eldar_combat_drugs", "sg_prisoner_warrior_1")
		Cmd_AttackMovePos("sg_prisoner_warrior_1", g_attack_target)
	end
	
	if SGroup_Count("sg_prisoner_wych_2") > 0 and
		SGroup_Count("sg_prisoner_warrior_2") > 0
	then
		Cmd_CastAbilitySGroup("sg_prisoner_wych_2", "dark_eldar_combat_drugs", "sg_prisoner_warrior_2")
		Cmd_AttackMovePos("sg_prisoner_warrior_2", g_attack_target)
	end
end

-- If the Player is nearing Center Base from the West Side
if g_base_activated_Center  == false and
	Player_AreSquadsNearMarker(g_Player1, "mkr_activate_centerBase_West")
then
	-- Activate Center Base by Prisoner Cage 7-9
	g_base_activated_Center = true		
end

-- If the Player is nearing Center Base from the East Side
if g_base_activated_Center  == false and
	Player_AreSquadsNearMarker(g_Player1, "mkr_activate_centerBase_East")
then
	-- Activate Center Base by Prisoner Cage 7-9
	g_base_activated_Center = true		
end

-- Remove the Rule once all the bases have been activated...
if g_firstTroops_sent == true and
	g_prisonerCage3_activated == true and
	g_prisonerCage4_activated == true and
	g_prisonerCage6_activated == true and
	g_prisonerCage10_activated == true and
	g_hallOfBlood10_activated  == true and
	g_hallOfBlood14_activated == true and
	g_hallOfBlood15_activated == true and
	g_base_activated_Center == true and
	g_ie_baseRevealed == true
then
	Rule_Remove(Rule_PrisonerCage_BaseActivation)
end

end

-- Warn the Player about the South East & West Bases & Reveal Fog of War on them function Rule_RevealBaseWarning() -- Reveal the southEast & West Bases FOW_RevealMarker("mkr_activate_southEast_base", 10) FOW_RevealMarker("mkr_activate_southWest_base", 10) end

-- Slave Caravels use their Soul Shock Skill function Rule_SlaveCaravel_Attack() for i = 9,20 do -- Check if player is in range & slave caravel is still alive if EGroup_Count("eg_slaveCaravel_"..i) == 1 and Player_AreSquadsNearMarker(g_Player1, "mkr_slaveCaravel_"..i) then -- Attempt to Fire Skill : Skill wont fire if not recharged Command_EntityAbilitySelf(g_Player2,EGroup_GetSpawnedEntityAt(EGroup_FromName("eg_slaveCaravel_"..i), 1), "dark_eldar_soul_shock") end end

-- If All Slave Caravels are destroyed -- Remove Rule
if EGroup_Count("eg_slaveCaravel_9") == 0 and
	EGroup_Count("eg_slaveCaravel_10") == 0 and
	EGroup_Count("eg_slaveCaravel_11") == 0 and
	EGroup_Count("eg_slaveCaravel_12") == 0 and
	EGroup_Count("eg_slaveCaravel_13") == 0 and
	EGroup_Count("eg_slaveCaravel_14") == 0 and
	EGroup_Count("eg_slaveCaravel_15") == 0 and
	EGroup_Count("eg_slaveCaravel_16") == 0 and
	EGroup_Count("eg_slaveCaravel_17") == 0 and
	EGroup_Count("eg_slaveCaravel_18") == 0 and
	EGroup_Count("eg_slaveCaravel_19") == 0 and
	EGroup_Count("eg_slaveCaravel_20") == 0
then
	Rule_Remove(Rule_SlaveCaravel_Attack)
end

end

-- Control Vect Attacks if ready for them function Rule_VectAttack() --if vect is at full life (or if both Repair HQs are Destroyed) if SGroup_Count("sg_Vect_Objective") > 0 and (SGroup_GetAvgHealth("sg_Vect_Objective") == 1.0 or (EGroup_Count("eg_hq_1") == 0 and EGroup_Count("eg_hq_8") == 0)) then -- Share FOW Vision with Vect World_EnablePlayerToPlayerFOW(g_Player1, g_Player4, false)

	-- PRODUCE SUPPORT SQUADS AND ORDER ATTACK
	-- Produce Some Support Warriors : If the Warrior SGroup is Empty & wap beasts not yet activated
	if SGroup_Count("sg_vectSupport_warrior") == 0 and
		g_vectSupport_warpBeast == false and
		Rule_Produce_Warrior("sg_vectSupport_warrior", "eg_hallOfBlood_3", "mkr_hallOfBlood_3")
	then
		-- Reset Status (in case died while retreating etc...)
		g_vectSupport_warrior_status[1] = g_squad_produced
	
	-- Produce Some Support Warp Beasts : If the Warp Beasts SGroup is Empty
	elseif g_vectSupport_warpBeast == true and
		SGroup_Count("sg_vectSupport_warpBeast") == 0 and
		Rule_Produce_WarpBeast("sg_vectSupport_warpBeast", "eg_hallOfBlood_3", "mkr_hallOfBlood_3")			
	then
		-- Reset Status (in case died while retreating etc...)
		g_vectSupport_warpBeast_status[1] = g_squad_produced
	end
	
	-- Produce Some Support Reavers : If the Reaver SGroup is Empty & ravagers not yet activated
	if SGroup_Count("sg_vectSupport_reaver") == 0 and
		Rule_Produce_Reaver("sg_vectSupport_reaver", "eg_skimmerShop_3", "mkr_skimmerShop_3") and
		g_vectSupport_ravager == false
	then
		-- Reset Status (in case died while retreating etc...)
		g_vectSupport_reaver_status[1] = g_squad_produced
	
	-- Produce Some Support Ravagers : If the Ravager SGroup is Empty
	elseif g_vectSupport_ravager == true and
		SGroup_Count("sg_vectSupport_ravager") == 0 and
		Rule_Produce_Ravager_FullyUpgraded("sg_vectSupport_ravager", "eg_skimmerShop_3", "mkr_skimmerShop_3")
	then
		-- Reset Status (in case died while retreating etc...)
		g_vectSupport_ravager_status[1] = g_squad_produced		
	end
	
	--Order Vect to attack the player
	Cmd_AttackMovePos("sg_Vect_Objective", g_attack_target)
	
	-- Pick Vects Attack Taunt & Play IE
	attack_Taunt = World_GetRand(1,3)
	Util_StartIntel(g_ie_VectRandomAttack_Array[attack_Taunt])
	
	-- Subtract 10% from his retreat damage number (EX: 99% to 89%)
	g_vect_retreat_damage = g_vect_retreat_damage - 0.10
	
	-- So Retreat Damage is Always over 50%
	if g_vect_retreat_damage < 0.5
	then
		g_vect_retreat_damage = 0.5
	end
	
	-- Confirm Rule was removed in time
	Rule_Remove(Rule_VectAttack)
	
	-- Add rule to check if Vect has been hurt
	Rule_AddInterval(Rule_Check_For_Vect_Damage,5)
	
-- Vect is Still Wounded...
else	
	--Taunt Player (Since Not Attacking)
	Util_StartIntel(EVENTS.IE_Taunt_Four)
	
	-- make sure he is in his marker area for next attack
	Cmd_MoveToMarker("sg_Vect_Objective", "mkr_vect_objective")
	
	-- task some slaves to fix him (slaves from main base)
	if SGroup_Count("sg_vectRepair") > 0
	then
		Command_SquadSquad(g_Player4, "sg_vectRepair", SCMD_Repair, "sg_Vect_Objective")
	end
	
	-- task some slaves to fix him (slaves from hq next to vect)
	if SGroup_Count("sg_vectRepair_2") > 0
	then
		Command_SquadSquad(g_Player4, "sg_vectRepair_2", SCMD_Repair, "sg_Vect_Objective")
	end
	
	-- Replace Slaves from Main Base HQ
	if SGroup_Count("sg_vectRepair") == 0 and
		EGroup_Count("eg_hq_1") == 1
	then
		Util_CreateSquadsAtMarker(g_Player4, "sg_vectRepair", "dark_eldar_squad_slave", "mkr_hq_1", 1)
		Command_SquadSquad(g_Player4, "sg_vectRepair", SCMD_Repair, "sg_Vect_Objective")
	end
	
	-- Replace Slaves from Backup Repair HQ
	if SGroup_Count("sg_vectRepair_2") == 0 and
		EGroup_Count("eg_hq_8") == 1
	then
		Util_CreateSquadsAtMarker(g_Player4, "sg_vectRepair_2", "dark_eldar_squad_slave", "mkr_hq_8", 1)
		Command_SquadSquad(g_Player4, "sg_vectRepair_2", SCMD_Repair, "sg_Vect_Objective")
	end
end

end

--Check if Vect is Damaged enough -- retreat if so function Rule_Check_For_Vect_Damage() local vect_health = SGroup_GetAvgHealth("sg_Vect_Objective")

-- If hurt enough to retreat
if vect_health <= g_vect_retreat_damage
then
	-- Pick Vects Attack Taunt & Play IE
	retreat_Taunt = World_GetRand(1,4)
	Util_StartIntel(g_ie_VectRandomFlee_Array[retreat_Taunt])
	
	-- Stop Sharing FOW Vision with Vect
	World_EnablePlayerToPlayerFOW(g_Player1, g_Player4, true)
	
	-- Use Skill To Cover Escape & retreat
	Cmd_CastAbilitySelf("sg_Vect_Objective", "dark_eldar_darklance_sweep")
	Cmd_MoveToMarker("sg_Vect_Objective", "mkr_vect_objective")
	
	-- task some slaves to fix him (slaves from main hq)
	if SGroup_Count("sg_vectRepair") > 0
	then
		Command_SquadSquad(g_Player4, "sg_vectRepair", SCMD_Repair, "sg_Vect_Objective")
	end
	
	-- task some slaves to fix him (slaves from hq next to vect)
	if SGroup_Count("sg_vectRepair_2") > 0
	then
		Command_SquadSquad(g_Player4, "sg_vectRepair_2", SCMD_Repair, "sg_Vect_Objective")
	end
	
	if SGroup_Count("sg_vectRepair") == 0 and
		EGroup_Count("eg_hq_1") == 1
	then
		Util_CreateSquadsAtMarker(g_Player4, "sg_vectRepair", "dark_eldar_squad_slave", "mkr_hq_1", 1)
		Command_SquadSquad(g_Player4, "sg_vectRepair", SCMD_Repair, "sg_Vect_Objective")
	end
	
	-- Replace Slaves from Backup Repair HQ
	if SGroup_Count("sg_vectRepair_2") == 0 and
		EGroup_Count("eg_hq_8") == 1
	then
		Util_CreateSquadsAtMarker(g_Player4, "sg_vectRepair_2", "dark_eldar_squad_slave", "mkr_hq_8", 1)
		Command_SquadSquad(g_Player4, "sg_vectRepair_2", SCMD_Repair, "sg_Vect_Objective")
	end
	
	--Prepare for Next Attack Attempt (Time Changes based on tech tiers)
	Rule_AddInterval(Rule_VectAttack, g_timer_vectAttack)
	Rule_Remove(Rule_Check_For_Vect_Damage)
end

end

-- ForEach Function: Checks if a Enemy Squad is under attack for soul powers function Rule_Check_Attack(sgroupid, itemindex, squadID) SGroup_Clear("skill_target") SGroup_Add("skill_target", SGroup_GetSpawnedSquadAt(sgroupid,itemindex))

if SGroup_IsVehicle("skill_target") == false and
	SGroup_IsUnderAttack("skill_target",true)
then
	return true
end

end

-- ForEach Function: Check if a Enemy Vehicle is under attack for soul powers function Rule_Check_Attack_Vehicles(sgroupid, itemindex, squadID) SGroup_Clear("skill_target") SGroup_Add("skill_target", SGroup_GetSpawnedSquadAt(sgroupid,itemindex))

if SGroup_IsVehicle("skill_target") and
	SGroup_IsUnderAttack("skill_target",true)
then
	return true
end

end

-- ForEach Function: Check if a Enemy Building is under attack for soul powers function Rule_Check_Attack_Buildings(egroupid, itemindex, entityID) EGroup_Clear("building_target") EGroup_Add("building_target", EGroup_GetSpawnedEntityAt(egroupid,itemindex))

-- Avoid Basic Strategic Point, Relic, Critical Point
local blueprintTable = Util_MakeBlueprintTable("relic_struct", "strategic_point_flag", "strategic_objective_struct")

if EGroup_IsUnderAttack("building_target",true) and
	EGroup_ContainsBlueprints("building_target", blueprintTable, false) == false
then
	return true
end	

end

-- ForEach Function: Check if a Enemy Building is under attack for soul powers function Rule_Check_SkillUsage(sgroupid, itemindex, squadID) SGroup_Clear("skill_target") SGroup_Add("skill_target", SGroup_GetSpawnedSquadAt(sgroupid,itemindex))

-- Avoid Basic Strategic Point, Relic, Critical Point
local blueprintTable = Util_MakeBlueprintTable("relic_struct", "strategic_point_flag", "strategic_objective_struct")

if SGroup_IsUnderAttack("skill_target",true) and
	SGroup_ContainsBlueprints("skill_target", blueprintTable, false) == true
then
	return true
end	

end

-- Soul Powers

-- Soul Power: Corrosion -- Fires it at Player Squads/Vehicles that are in combat function Rule_SoulPower_Corrosion() -- Check if Player Vehicle is in combat, & fire corrosion at them if g_soulPower_enabled_Corrosion == true and SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Check_Attack_Vehicles) and SGroup_Count("skill_target") > 0 and EGroup_Count("eg_hq_1") > 0 and Cmd_CastAbilityEGroupS("eg_hq_1", "dark_eldar_corrosive_cloud", "skill_target") then -- Random Chance to Play Taunt IE if World_GetRand(0,2) < 1 then -- Play IE if Piercing Vision is used power_Taunt = World_GetRand(1,3) Util_StartIntel(g_ie_PowerUseTaunt_Array[power_Taunt]) end

-- Check if Player Units (Non-Vehicle) is in combat, & fire corrosion at them
elseif g_soulPower_enabled_Corrosion == true and
	SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Check_Attack) and
	SGroup_Count("skill_target") > 0 and
	EGroup_Count("eg_hq_1") > 0 and
	Cmd_CastAbilityEGroupS("eg_hq_1", "dark_eldar_corrosive_cloud", "skill_target")
then
	-- Random Chance to Play Taunt IE
	if World_GetRand(0,2) < 1
	then
		-- Play IE if Piercing Vision is used
		power_Taunt = World_GetRand(1,3)
		Util_StartIntel(g_ie_PowerUseTaunt_Array[power_Taunt])
	end
end

end

-- Soul Power: SoulStorm -- Fires it at Eneny Squads in combat function Rule_SoulPower_SoulStorm() -- Check if Player Vehicle is in combat, & fire SoulStorm at them if g_soulPower_enabled_SoulStorm == true and SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Check_Attack_Vehicles) and SGroup_Count("skill_target") > 0 and EGroup_Count("eg_hq_1") > 0 and Cmd_CastAbilityEGroupS("eg_hq_1", "dark_eldar_soulstorm", "skill_target") then -- Random Chance to Play Taunt IE if World_GetRand(0,2) < 1 then -- Play IE if Piercing Vision is used power_Taunt = World_GetRand(1,3) Util_StartIntel(g_ie_PowerUseTaunt_Array[power_Taunt]) end

-- Check if Player Units (Non-Vehicle) is in combat, & fire SoulStorm at them
elseif g_soulPower_enabled_SoulStorm == true and
	SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Check_Attack) and
	SGroup_Count("skill_target") > 0 and
	EGroup_Count("eg_hq_1") > 0 and
	Cmd_CastAbilityEGroupS("eg_hq_1", "dark_eldar_soulstorm", "skill_target")
then
	-- Random Chance to Play Taunt IE
	if World_GetRand(0,2) < 1
	then
		-- Play IE if Piercing Vision is used
		power_Taunt = World_GetRand(1,3)
		Util_StartIntel(g_ie_PowerUseTaunt_Array[power_Taunt])
	end
end

end

-- Soul Power: Scream of the Dammed -- Fires it if Player Squads is in combat function Rule_SoulPower_ScreamOfDammed() -- Check if Player Squad is in combat, & fire Scream of the Dammed if g_soulPower_enabled_ScreamofDammed == true and SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Check_Attack) and SGroup_Count("skill_target") > 0 and EGroup_Count("eg_hq_1") > 0 and Command_EntityAbilitySelf(g_Player2,EGroup_GetSpawnedEntityAt(EGroup_FromName("eg_hq_1"), 1), "dark_eldar_screams_of_the_damned") then -- Random Chance to Play Taunt IE if World_GetRand(0,2) < 1 then -- Play IE if Piercing Vision is used power_Taunt = World_GetRand(1,3) Util_StartIntel(g_ie_PowerUseTaunt_Array[power_Taunt]) end end end

-- Soul Power: Piercing Vision -- Fires it on Enemy Squad in Proximity of Infiltrated player Units function Rule_SoulPower_PiercingVision() -- ForEach Function: Checks if a Enemy Squad is In Range of Player Infiltrated Squad for Skill Targeting function Rule_Detect_Proximity_Infiltrated(sgroupid_ai, itemindex_ai, squadID_ai) SGroup_Clear("squad_ai") SGroup_Add("squad_ai", SGroup_GetSpawnedSquadAt(sgroupid_ai,itemindex_ai))

	-- If Dark Eldar Unit is in Proximity to cloaked squad & HQs exists -- try to cast piercing vision
	if Prox_SquadsInProximityOfSquads("squad_player", "squad_ai", range, true) and
		EGroup_Count("eg_hq_1") > 0 and
		Cmd_CastAbilityEGroupS("eg_hq_1", "dark_eldar_piercing_vision", "squad_ai")
	then
		-- Play IE if Piercing Vision is used
		cloak_Taunt = World_GetRand(1,3)
		Util_StartIntel(g_ie_DetectCloakTaunt_Array[cloak_Taunt])
		return true
	end
end

-- ForEach Function: Checks if Player Squad is Infiltrated & if eneny squad in range
function Rule_Check_Player_Infiltrated(sgroupid_player, itemindex_player, squadID_player)
	-- Check if the Squad is Infiltrated
	if Squad_IsInfiltrated(squadID_player)
	then
		SGroup_Clear("squad_player")
		SGroup_Add("squad_player",squadID_player)

		if SGroup_ForEach(Player_GetSquads(g_Player2), Rule_Detect_Proximity_Infiltrated)
		then
			return true
		end
	end
end

range = 45

-- Check if AI Squad is in range of an infiltrated player squad, and cast piercing vision on the AI Squad
if g_soulPower_enabled_PiercingVision == true
then
	SGroup_ForEach(Player_GetSquads(g_Player1), Rule_Check_Player_Infiltrated)
end

end


-- END OF ALL " LEVEL FLOW " RULES


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

-- Creates the SGroups Used & Adds all the attack Rules at the same time to sync them function Rule_Create_And_Sync_Attacks() -- Checks if a prisoner has been freed from their cage yet g_array_prisonerCage_freed = { false, --1 false, --2 false, --3 false, --4 false, --5 false, --6 false, --7 false, --8 false, --9 false, --10 }

-- What Prisoner to free from what cage
g_array_prisonerCage_prisoner = {
	g_prisoner_blueprint_1, --1
	g_prisoner_blueprint_2, --2
	g_prisoner_blueprint_3, --3
	g_prisoner_blueprint_4, --4
	g_prisoner_blueprint_5, --5
	g_prisoner_blueprint_6, --6
	g_Builder_blueprint, --7
	g_Builder_blueprint, --8
	g_Builder_blueprint, --9
	g_prisoner_blueprint_6, --10
}
-- Target Location for when a squad is told to retreat (Retreat Toward Center Base HQ)
g_retreat_target = Marker_GetPosition(Marker_FromName("mkr_hq_4", "basic_marker"))

-- Default Attack Target
g_attack_target = SGroup_GetPosition(Player_GetSquads(g_Player1))

-- SGroup & EGroups used for targeting of skills
SGroup_Create("skill_target")
EGroup_Create("building_target")

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

-- Used for Air Unit Targeting
SGroup_Create("sg_playerAirUnits")

--Used for Soul Power Targeting
SGroup_Create("squad_player")
SGroup_Create("squad_ai")

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

-- Create the SGroups used by the Bases to Attack & Patrol with

-- Cage Defense Troops
SGroup_Create("sg_cageDefense_warrior1")
SGroup_Create("sg_cageDefense_warrior2")
SGroup_Create("sg_cageDefense_scourge")
SGroup_Create("sg_cageDefense_reaver")

-- Center Base
SGroup_Create("sg_centerBase_hellions_patrol")
SGroup_Create("sg_centerBase_reaver")
SGroup_Create("sg_centerBase_mandrake")
SGroup_Create("sg_centerBase_scourge")

-- East Base
SGroup_Create("sg_eastBase_hellions")
SGroup_Create("sg_eastBase_warrior")
SGroup_Create("sg_eastBase_mandrake")

-- Main Base
for i = 1,2 do
	SGroup_Create("sg_mainBase_raider"..i)
	SGroup_Create("sg_mainBase_ravager"..i)
	SGroup_Create("sg_mainBase_warrior"..i)
end

-- North Base
SGroup_Create("sg_northBase_warpBeast_patrol")
SGroup_Create("sg_northBase_mandrake_patrol")
for i = 1,2 do
	SGroup_Create("sg_northBase_talos"..i)
	SGroup_Create("sg_northBase_raven"..i)
end

-- North West Base
SGroup_Create("sg_northWestBase_haemonculus")
SGroup_Create("sg_northWestBase_wych")

-- South East Base
SGroup_Create("sg_southEastBase_scourge")
SGroup_Create("sg_southEastBase_mandrakes")

-- South West Base
SGroup_Create("sg_southWestBase_warpbeast_patrol")
SGroup_Create("sg_southWestBase_wych")
SGroup_Create("sg_southWestBase_haemonculus")
SGroup_Create("sg_southWestBase_raven")
SGroup_Create("sg_southWestBase_reaver_1")
SGroup_Create("sg_southWestBase_reaver_2")
SGroup_Create("sg_southWestBase_talos")

-- Vect Support	
SGroup_Create("sg_vectSupport_warrior")
SGroup_Create("sg_vectSupport_warpBeast")
SGroup_Create("sg_vectSupport_reaver")
SGroup_Create("sg_vectSupport_ravager")

-- Group for Repairing Vect
SGroup_Create("sg_vectRepair")
SGroup_Create("sg_vectRepair_2")

-- West Base
SGroup_Create("sg_westBase_scourge")
SGroup_Create("sg_westBase_warrior")
SGroup_Create("sg_westBase_reaver_1")
SGroup_Create("sg_westBase_reaver_2")

-- Vect Base
SGroup_Create("sg_vectBase_archon")
SGroup_Create("sg_vectBase_raven1")
SGroup_Create("sg_vectBase_raven2")

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

-- Check for Base Activation by the Prisoner Cages
Rule_AddInterval(Rule_PrisonerCage_BaseActivation, 1)

-- Check For Destroyed Cages to free prisoners & give resources
Rule_AddInterval(Rule_PrisonerCage_FreeCage,1)

-- Allow Slave Caravals to check for & use soul shock ability
Rule_AddInterval(Rule_SlaveCaravel_Attack,3)

-- Sync Production of Center Base & The Prisoner Cage Defenses	
Rule_AddInterval(Rule_Production_Center_Base, g_timer_centerBase)
Rule_AddInterval(Rule_Production_PrisonerCage, g_timer_prisonerCage)
Rule_AddInterval(Rule_Production_SouthEast_Base, g_timer_southEastBase)
Rule_AddInterval(Rule_Production_SouthWest_Base, g_timer_southWestBase)

-- Patrols
Rule_AddInterval(Rule_Patrol_Center, 5)
Rule_AddInterval(Rule_Patrol_North, 5)
Rule_AddInterval(Rule_Patrol_North_Reverse, 5)
Rule_AddInterval(Rule_Patrol_SouthWest, 5)

-- Squad Tactics : Reinforcing, Skills, Attacking, Jumping, etc..
Rule_AddInterval(Rule_Squad_Tactics_Helper,5)

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

end

-- Produce Scourge, Reaver, Mandrakes, & Patrolling Hellions function Rule_Production_Center_Base() -- If the Scourge SGroup is Empty (& Base Activated) if g_base_activated_Center == true and SGroup_Count("sg_centerBase_scourge") == 0 and Rule_Produce_Scourge("sg_centerBase_scourge", "eg_hallOfBlood_8", "mkr_hallOfBlood_8") then -- Reset Status (in case died while retreating etc...) g_centerBase_scourge_status[1] = g_squad_produced end

-- If the Reaver SGroup is Empty (& Base Activated)
if g_base_activated_Center == true and
	SGroup_Count("sg_centerBase_reaver") == 0 and
	Rule_Produce_Reaver("sg_centerBase_reaver", "eg_skimmerShop_6", "mkr_skimmerShop_6")
then
	-- Reset Status (in case died while retreating etc...)
	g_centerBase_reaver_status[1] = g_squad_produced
end

-- If the Patroling Hellion SGroup is Empty (& Patrol Activated)
if g_patrol_activated_Center == true and
	SGroup_Count("sg_centerBase_hellions_patrol") == 0 and
	Rule_Produce_Hellion("sg_centerBase_hellions_patrol", "eg_skimmerShop_6", "mkr_skimmerShop_6")
then
	-- Set SGroup Owner to Player3 so can share FOW Vision
	SGroup_SetPlayerOwner("sg_centerBase_hellions_patrol", g_Player3)
	
	-- Task to First Patrol Point
	Cmd_AttackMoveMarker("sg_centerBase_hellions_patrol", "mkr_Patrol_Center_1")		
	g_centerBase_hellions_patrol_status[1]	=	g_squad_patrolling
end

-- If the Mandrake SGroup is Empty (& Base Activated)
if g_base_activated_Center == true and
	SGroup_Count("sg_centerBase_mandrake") == 0 and
	Rule_Produce_Mandrake("sg_centerBase_mandrake", "eg_hq_4", "mkr_hq_4")
then
	-- Reset Status (in case died while retreating etc...)
	g_centerBase_mandrake_status[1] = g_squad_produced
end

--if hall of blood, dark foundry & hqs are destroyed, remove rules since base is gone
if 	EGroup_Count("eg_skimmerShop_6") == 0 and
	EGroup_Count("eg_hq_4") == 0 and
	EGroup_Count("eg_hallOfBlood_8") == 0
then
	Rule_Remove(Rule_Production_Center_Base)
end

end

-- Produce Warriors & Raiders from the Main Base once activated function Rule_Production_Main_Base() -- Loop through all the Warriors, Raiders, Dark Foundry, & Hall of Bloods in Main Base for i =1,2 do -- Reset Production Values to False local mainBase_troopsProduced = false local mainBase_raiderProduced = false

	-- If the Warrior SGroup is Empty (& Base Activated)...
	if g_base_activated_Main == true and
		SGroup_Count("sg_mainBase_warrior"..i) == 0 and
		Rule_Produce_Warrior_Full("sg_mainBase_warrior"..i, "eg_hallOfBlood_"..i, "mkr_hallOfBlood_"..i) == true
	then
		mainBase_troopsProduced = true
		
		-- Reset Status (in case died while retreating etc...)
		g_mainBase_warrior_status[i] = g_squad_produced
	end
	
	-- If the Raider SGroup is Empty (& Base Activated)...
	if g_base_activated_Main == true and
		SGroup_Count("sg_mainBase_raider"..i) == 0 and
		Rule_Produce_Raider("sg_mainBase_raider"..i, "eg_skimmerShop_"..i, "mkr_skimmerShop_"..i) == true
	then
		mainBase_raiderProduced = true
		
		-- Reset Status (in case died while retreating etc...)
		g_mainBase_raider_status[i] = g_squad_produced			
	end
	
	-- if both troops & transport exist...
	if mainBase_troopsProduced == true and
		mainBase_raiderProduced == true
	then
		-- load the warriors into the raider (& set status to loading to buy time before sending in)
		Cmd_EnterTransport("sg_mainBase_warrior"..i, "sg_mainBase_raider"..i)
		g_mainBase_raider_status[i] = g_squad_loading	
		g_mainBase_warrior_status[i] = g_squad_loading	
	end
end

-- If the Slave SGroup is Empty (& Base Activated)
if g_base_activated_Main == true and
	SGroup_Count("sg_slave_1") == 0 and
	Rule_Produce_Slave("sg_slave_1", "eg_hq_1", "mkr_hq_1")
then
	-- Reset Status (in case died while retreating etc...)
	g_slave_status[1] = g_squad_produced

elseif g_base_activated_Main == true and
	SGroup_Count("sg_slave_2") == 0 and
	Rule_Produce_Slave("sg_slave_2", "eg_hq_1", "mkr_hq_1")
then
	-- Reset Status (in case died while retreating etc...)
	g_slave_status[2] = g_squad_produced
end	

if 	EGroup_Count("eg_skimmerShop_1") == 0 and
	EGroup_Count("eg_skimmerShop_2") == 0 and
	EGroup_Count("eg_hallOfBlood_1") == 0 and
	EGroup_Count("eg_hallOfBlood_2") == 0 and
	EGroup_Count("eg_hq_1") == 0
then
	Rule_Remove(Rule_Production_Main_Base)
end

end

-- Produce Troops from the East Base once activated function Rule_Production_East_Base() -- If the Hellion SGroup is Empty (& Base Activated) if g_base_activated_East == true and SGroup_Count("sg_eastBase_hellions") == 0 and Rule_Produce_Hellion("sg_eastBase_hellions", "eg_skimmerShop_8", "mkr_skimmerShop_8") then -- Reset Status for Jumping g_eastBase_hellions_status[1] = g_squad_jump_prep end

-- If the Mandrake SGroup is Empty (& Base Activated)
if g_base_activated_East == true and
	SGroup_Count("sg_eastBase_mandrake") == 0 and
	Rule_Produce_Mandrake("sg_eastBase_mandrake", "eg_hq_5", "mkr_hq_5")
then
	-- Reset Status (in case died while retreating etc...)
	g_eastBase_mandrake_status[1] = g_squad_produced
end	

-- If the Warrior SGroup is Empty (& Base Activated)
if g_base_activated_East == true and
	SGroup_Count("sg_eastBase_warrior") == 0 and
	Rule_Produce_Warrior("sg_eastBase_warrior", "eg_hallOfBlood_4", "mkr_hallOfBlood_4")
then
	-- Reset Status (in case died while retreating etc...)
	g_eastBase_warrior_status[1] = g_squad_produced
end	

--if hall of blood, dark foundry & hqs are destroyed, remove rules since base is gone
if 	EGroup_Count("eg_hallOfBlood_4") == 0 and
	EGroup_Count("eg_hq_5") == 0 and
	EGroup_Count("eg_skimmerShop_8") == 0
then
	Rule_Remove(Rule_Production_East_Base)
end

end -- Produce Patroling Warp beasts, Patroling Mandrakes, Ravens & Talos function Rule_Production_North_Base() -- Hall of Blood 5:

-- If the Warp Beast Patrol SGroup is Empty (& Base Activated)
if g_patrol_activated_North == true and
	SGroup_Count("sg_northBase_warpBeast_patrol") == 0 and
	Rule_Produce_WarpBeast("sg_northBase_warpBeast_patrol", "eg_hallOfBlood_5", "mkr_hallOfBlood_5")
then
	-- Task to First Patrol Point
	Cmd_AttackMoveMarker("sg_northBase_warpBeast_patrol", "mkr_Patrol_North_1")
	g_northBase_warpBeast_patrol_status[1]	=	g_squad_patrolling
end

-- HQ 2:

-- If the Mandrake Patrol SGroup is Empty (& Base Activated)
if g_patrol_activated_North == true and
	SGroup_Count("sg_northBase_mandrake_patrol") == 0 and
	Rule_Produce_Mandrake("sg_northBase_mandrake_patrol", "eg_hq_2", "mkr_hq_2")
then
	-- Task to First Patrol Point
	Cmd_AttackMoveMarker("sg_northBase_mandrake_patrol", "mkr_Patrol_North_1")
	g_northBase_mandrake_patrol_status[1]	=	g_squad_patrolling
end	

-- Dark Foundry 4:

-- If the Raven SGroup is Empty (& Base Activated)
if g_base_activated_North == true and
	SGroup_Count("sg_northBase_raven1") == 0 and
	Rule_Produce_Raven("sg_northBase_raven1", "eg_skimmerShop_4", "mkr_skimmerShop_4")
then
	-- Reset Status (in case died while retreating etc...)
	g_northBase_raven_status[1] = g_squad_produced

-- Else if the Talos SGroup is Empty (& Base Activated)
elseif g_base_activated_North == true and
	SGroup_Count("sg_northBase_talos1") == 0 and
	Rule_Produce_Talos("sg_northBase_talos1", "eg_skimmerShop_4", "mkr_skimmerShop_4")
then
	-- Reset Status (in case died while retreating etc...)
	g_northBase_talos_status[1] = g_squad_produced
end

-- Dark Foundry 5:

-- If the Raven SGroup is Empty (& Base Activated)
if g_base_activated_North == true and
	SGroup_Count("sg_northBase_raven2") == 0 and
	Rule_Produce_Raven("sg_northBase_raven2", "eg_skimmerShop_5", "mkr_skimmerShop_5")
then
	-- Reset Status (in case died while retreating etc...)
	g_northBase_raven_status[2] = g_squad_produced

-- Else if the Talos SGroup is Empty (& Base Activated)
elseif g_base_activated_North == true and
	SGroup_Count("sg_northBase_talos2") == 0 and
	Rule_Produce_Talos("sg_northBase_talos2", "eg_skimmerShop_5", "mkr_skimmerShop_5")
then
	-- Reset Status (in case died while retreating etc...)
	g_northBase_talos_status[2] = g_squad_produced
end

--if hall of blood, dark foundry & hqs are destroyed, remove rules since base is gone
if 	EGroup_Count("eg_hallOfBlood_5") == 0 and
	EGroup_Count("eg_hq_2") == 0 and
	EGroup_Count("eg_skimmerShop_4") == 0 and
	EGroup_Count("eg_skimmerShop_5") == 0
then
	Rule_Remove(Rule_Production_North_Base)
end	

end

-- Produce Troops from the NorthWest Base once activated function Rule_Production_NorthWest_Base() -- If the Haemonculus SGroup is Empty (& Base Activated) if g_base_activated_NorthWest == true and SGroup_Count("sg_northWestBase_haemonculus") == 0 and Rule_Produce_Haemonculus("sg_northWestBase_haemonculus", "eg_hq_3", "mkr_hq_3") then -- Produce a Squad of Warriors & Attach Haemonculus if Rule_Produce_Warrior_Full("sg_northWestBase_haemonculus_support", "eg_hallOfBlood_9", "mkr_hallOfBlood_9") then Cmd_AttachSquads("sg_northWestBase_haemonculus_support", "sg_northWestBase_haemonculus") end

	-- Reset Status (in case died while retreating etc...)
	g_northWestBase_haemonculus_status[1] = g_squad_produced
end

-- If the Wych SGroup is Empty (& Base Activated)
if g_base_activated_NorthWest == true and
	SGroup_Count("sg_northWestBase_wych") == 0 and
	Rule_Produce_Wych("sg_northWestBase_wych", "eg_hallOfBlood_9", "mkr_hallOfBlood_9")
then
	-- Reset Status (in case died while retreating etc...)
	g_northWestBase_wych_status[1] = g_squad_produced
end

-- All Production Buildings destroyed -- Remove Rule
if EGroup_Count("eg_hallOfBlood_9") == 0 and
	EGroup_Count("eg_hq_3") == 0
then
	Rule_Remove(Rule_Production_NorthWest_Base)
end

end

-- Produce Warriors, Reavers, & Scourge to Defend Prisoner Cages function Rule_Production_PrisonerCage() -- Hall of Blood 14 by Prisoner Cage 1 & 2

-- If the Warrior SGroup is Empty (& Hall of Blood 14 Activated)
if g_hallOfBlood14_activated == true and
	SGroup_Count("sg_cageDefense_warrior1") == 0 and
	Rule_Produce_Warrior("sg_cageDefense_warrior1", "eg_hallOfBlood_14", "mkr_hallOfBlood_14")
then
	-- Reset Status (in case died while retreating etc...)
	g_cageDefense_warrior_status[1] = g_squad_produced
end	

-- Hall of Blood 15 by Prisoner Cage 3

-- If the Warrior SGroup is Empty (& Hall of Blood 15 Activated)
if g_hallOfBlood15_activated == true and
	SGroup_Count("sg_cageDefense_warrior2") == 0 and
	Rule_Produce_Warrior("sg_cageDefense_warrior2", "eg_hallOfBlood_15", "mkr_hallOfBlood_15")
then
	-- Reset Status (in case died while retreating etc...)
	g_cageDefense_warrior_status[2] = g_squad_produced
end	

-- Skimmer Shop 10 by Prisoner Cage 3

-- If the Warrior SGroup is Empty (& Skimmer Shop 10 Activated)
if g_skimmerShop10_activated  == true and
	SGroup_Count("sg_cageDefense_reaver") == 0 and
	Rule_Produce_Reaver("sg_cageDefense_reaver", "eg_skimmerShop_10", "mkr_skimmerShop_10")
then
	-- Reset Status (in case died while retreating etc...)
	g_cageDefense_reaver_status[1] = g_squad_produced
end

-- Hall of Blood 10 by Prisoner Cage 5

-- If the Scourge SGroup is Empty (& Hall of Blood 10 Activated)
if g_hallOfBlood10_activated == true and
	SGroup_Count("sg_cageDefense_scourge") == 0 and
	Rule_Produce_Scourge("sg_cageDefense_scourge", "eg_hallOfBlood_10", "mkr_hallOfBlood_10")
then
	-- Reset Status (in case died while retreating etc...)
	g_cageDefense_scourge_status[1] = g_squad_produced
end

--if Hall of Bloods & Dark Foundry are destroyed, remove rules since base is gone
if 	EGroup_Count("eg_hallOfBlood_14") == 0 and
	EGroup_Count("eg_hallOfBlood_15") == 0 and
	EGroup_Count("eg_hallOfBlood_10") == 0 and
	EGroup_Count("eg_skimmerShop_10") == 0
then
	Rule_Remove(Rule_Production_PrisonerCage)
end

end

-- Produces Jumping Scourge & Mandrakes -- (PreActive: Scourge & Mandrakes) function Rule_Production_SouthEast_Base() -- BASE ACTIVE:

-- If the Mandrake SGroup is Empty (& Base Activated)
if g_base_activated_SouthEast == true and
	SGroup_Count("sg_southEastBase_mandrakes") == 0 and
	Rule_Produce_Mandrake("sg_southEastBase_mandrakes", "eg_hq_7", "mkr_hq_7")
then
	-- Reset Status (in case died while retreating etc...)
	g_southEastBase_mandrakes_status[1] = g_squad_produced
end

-- If the Scourge SGroup is Empty (& Hall of Blood 10 Activated)
if g_base_activated_SouthEast == true and
	SGroup_Count("sg_southEastBase_scourge") == 0 and
	Rule_Produce_Scourge("sg_southEastBase_scourge", "eg_hallOfBlood_11", "mkr_hallOfBlood_11")
then
	-- Reset Status (in case died while retreating etc...)
	g_southEastBase_scourge_status[1] = g_squad_produced
end

-- BASE NOT YET ACTIVE:

if g_base_activated_SouthEast == false and
	Player_AreSquadsNearMarker(g_Player1, "mkr_activate_southEast_base")
then
	-- If the Mandrake SGroup is Empty
	if SGroup_Count("sg_southEastBase_mandrakes") == 0 and
		Rule_Produce_Mandrake("sg_southEastBase_mandrakes", "eg_hq_7", "mkr_hq_7")
	then
		-- Reset Status (in case died while retreating etc...)
		g_southEastBase_mandrakes_status[1] = g_squad_produced
	end

	-- If the Scourge SGroup is Empty
	if SGroup_Count("sg_southEastBase_scourge") == 0 and
		Rule_Produce_Scourge("sg_southEastBase_scourge", "eg_hallOfBlood_11", "mkr_hallOfBlood_11")
	then
		-- Reset Status (in case died while retreating etc...)
		g_southEastBase_scourge_status[1] = g_squad_produced
	end
end

-- BASE DESTROYED

--if Hall of Bloods & HQ are destroyed, remove rules since base is gone
if 	EGroup_Count("eg_hallOfBlood_11") == 0 and
	EGroup_Count("eg_hq_7") == 0
then
	Rule_Remove(Rule_Production_PrisonerCage)
end

end

-- Produces Wych, Patroling WarpBeast, Haemonculus, Talos & Raven -- (PreActive: Wych & Reaver) function Rule_Production_SouthWest_Base() -- BASE ACTIVE:

-- Hall of Blood 12

-- If the Wych SGroup is Empty (& Base Activated)
if g_base_activated_SouthWest == true and
	SGroup_Count("sg_southWestBase_wych") == 0 and
	Rule_Produce_Wych("sg_southWestBase_wych", "eg_hallOfBlood_12", "mkr_hallOfBlood_12")
then
	-- Reset Status (in case died while retreating etc...)
	g_southWestBase_wych_status[1] = g_squad_produced
end

-- Hall of Blood 13:

-- If the Warp Beast Patrol SGroup is Empty (& Base Activated)
if g_patrol_activated_SouthWest == true and
	SGroup_Count("sg_southWestBase_warpbeast_patrol") == 0 and
	Rule_Produce_WarpBeast("sg_southWestBase_warpbeast_patrol", "eg_hallOfBlood_13", "mkr_hallOfBlood_13")
then
	-- Set SGroup Owner to Player3 so can share FOW Vision
	SGroup_SetPlayerOwner("sg_southWestBase_warpbeast_patrol", g_Player3)
	
	-- Task to First Patrol Point
	Cmd_AttackMoveMarker("sg_southWestBase_warpbeast_patrol", "mkr_Patrol_SouthWest_1")
	g_southWestBase_warpbeast_patrol_status[1]	=	g_squad_patrolling
end

-- HQ 6:

-- If the Haemonculus SGroup is Empty (& Base Activated)
if g_base_activated_SouthWest == true and
	SGroup_Count("sg_southWestBase_haemonculus") == 0 and
	Rule_Produce_Mandrake("sg_southWestBase_haemonculus", "eg_hq_6", "mkr_hq_6")
then
	-- Reset Status (in case died while retreating etc...)
	g_southWestBase_haemonculus_status[1] = g_squad_produced
end

-- Dark Foundry 9:

-- If the Raven SGroup is Empty (& Base Activated)
if g_base_activated_SouthWest == true and
	SGroup_Count("sg_southWestBase_raven") == 0 and
	Rule_Produce_Raven("sg_southWestBase_raven", "eg_skimmerShop_9", "mkr_skimmerShop_9")
then
	-- Reset Status (in case died while retreating etc...)
	g_southWestBase_raven_status[1] = g_squad_produced

-- Else If the Talos SGroup is Empty (& Base Activated)
elseif g_base_activated_SouthWest == true and
	SGroup_Count("sg_southWestBase_talos") == 0 and
	Rule_Produce_Talos("sg_southWestBase_talos", "eg_skimmerShop_9", "mkr_skimmerShop_9")
then
	-- Reset Status (in case died while retreating etc...)
	g_southWestBase_talos_status[1] = g_squad_produced
end

-- BASE NOT YET ACTIVE:

if g_base_activated_SouthWest == false and
	Player_AreSquadsNearMarker(g_Player1, "mkr_activate_southWest_base")
then
	-- If the Wych SGroup is Empty
	if SGroup_Count("sg_southWestBase_wych") == 0 and
		Rule_Produce_Wych("sg_southWestBase_wych", "eg_hallOfBlood_12", "mkr_hallOfBlood_12")
	then
		-- Reset Status (in case died while retreating etc...)
		g_southWestBase_wych_status[1] = g_squad_produced
	end

	-- If the Reaver SGroup is Empty
	if SGroup_Count("sg_southWestBase_reaver_1") == 0 and
		Rule_Produce_Reaver("sg_southWestBase_reaver_1", "eg_skimmerShop_9", "mkr_skimmerShop_9")
	then
		-- Reset Status (in case died while retreating etc...)
		g_southWestBase_reaver_status[1] = g_squad_produced
	end
	
	-- If the Reaver SGroup is Empty
	if SGroup_Count("sg_southWestBase_reaver_2") == 0 and
		Rule_Produce_Reaver("sg_southWestBase_reaver_2", "eg_skimmerShop_9", "mkr_skimmerShop_9")
	then
		-- Reset Status (in case died while retreating etc...)
		g_southWestBase_reaver_status[2] = g_squad_produced
	end
end

-- BASE DESTROYED

-- All Production Buildings destroyed -- Remove Rule
if EGroup_Count("eg_hallOfBlood_12") == 0 and
	EGroup_Count("eg_hallOfBlood_13") == 0 and
	EGroup_Count("eg_hq_6") == 0 and
	EGroup_Count("eg_skimmerShop_9") == 0
then
	Rule_Remove(Rule_Production_SouthWest_Base)
end	

end

-- Produce Warriors, Jumping Scourge & Reavers function Rule_Production_West_Base() -- If the Scourge SGroup is Empty (& Base Activated) if g_base_activated_West == true and SGroup_Count("sg_westBase_scourge") == 0 and Rule_Produce_Scourge("sg_westBase_scourge", "eg_hallOfBlood_6", "mkr_hallOfBlood_6") then -- Reset Status for Jumping g_westBase_scourge_status[1] = g_squad_jump_prep end

-- If the Warrior SGroup is Empty (& Base Activated)
if g_base_activated_West == true and
	SGroup_Count("sg_westBase_warrior") == 0 and
	Rule_Produce_Warrior("sg_westBase_warrior", "eg_hallOfBlood_7", "mkr_hallOfBlood_7")
then
	-- Reset Status (in case died while retreating etc...)
	g_westBase_warrior_status[1] = g_squad_produced
end

-- If the Reaver SGroup is Empty (& Base Activated)
if g_base_activated_West == true and
	SGroup_Count("sg_westBase_reaver_1") == 0 and
	Rule_Produce_Reaver("sg_westBase_reaver_1", "eg_skimmerShop_7", "mkr_skimmerShop_7")
then
	-- Reset Status (in case died while retreating etc...)
	g_westBase_reaver_status[1] = g_squad_produced
end

-- If the Reaver SGroup is Empty (& Base Activated)
if g_base_activated_West == true and
	SGroup_Count("sg_westBase_reaver_2") == 0 and
	Rule_Produce_Reaver("sg_westBase_reaver_2", "eg_skimmerShop_7", "mkr_skimmerShop_7")
then
	-- Reset Status (in case died while retreating etc...)
	g_westBase_reaver_status[2] = g_squad_produced
end

--if hall of bloods & Dark Foundry are destroyed, remove rules since base is gone
if 	EGroup_Count("eg_hallOfBlood_6") == 0 and
	EGroup_Count("eg_hallOfBlood_7") == 0 and
	EGroup_Count("eg_skimmerShop_7") == 0
then
	Rule_Remove(Rule_Production_West_Base)
end

end

-- Handles the Hellions that Patrol the Prisoner Cage Area function Rule_Patrol_Center() -- Check if the Squad arrived at the Patrol Location 1 if SGroup_Exists("sg_centerBase_hellions_patrol") and Prox_AllSquadsNearMarker("sg_centerBase_hellions_patrol", "mkr_Patrol_Center_1") then -- Reinforce BackUp before continuing patrol if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_centerBase_hellions_patrol",1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_centerBase_hellions_patrol",1)) and SGroup_GetAvgLoadout("sg_centerBase_hellions_patrol") < 0.75 then -- Reinforce Command_Squad(g_Player2, "sg_centerBase_hellions_patrol", SCMD_ReinforceTrooper) else -- Task to Next Patrol Point Cmd_AttackMoveMarker("sg_centerBase_hellions_patrol", "mkr_Patrol_Center_2") end

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

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

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

--- Production Building & Patrol Squad are destroyed
if EGroup_Count("eg_skimmerShop_6") == 0 and
	SGroup_Count("sg_centerBase_hellions_patrol") == 0
then
	Rule_Remove(Rule_Patrol_Center)
end	

end

-- Handles the Warp Beasts that Patrol the Northern Area & by the Soul Cages function Rule_Patrol_North() -- Check if the Squad arrived at the Patrol Location 1 if SGroup_Exists("sg_northBase_warpBeast_patrol") and Prox_AllSquadsNearMarker("sg_northBase_warpBeast_patrol", "mkr_Patrol_North_1") then -- Reinforce BackUp before continuing patrol if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_northBase_warpBeast_patrol",1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_northBase_warpBeast_patrol",1)) and SGroup_GetAvgLoadout("sg_northBase_warpBeast_patrol") < 0.75 then -- Reinforce Command_Squad(g_Player2, "sg_northBase_warpBeast_patrol", SCMD_ReinforceTrooper) else -- Task to Next Patrol Point Cmd_AttackMoveMarker("sg_northBase_warpBeast_patrol", "mkr_Patrol_North_2") end

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

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

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

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

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

--- Production Building & Patrol Squad are destroyed
if EGroup_Count("eg_hallOfBlood_5") == 0 and
	SGroup_Count("sg_northBase_warpBeast_patrol") == 0
then
	Rule_Remove(Rule_Patrol_North)
end

end

-- Handles the Mandrakes that Patrol the Northern Area & by the Soul Cages function Rule_Patrol_North_Reverse() -- Check if the Squad arrived at the Patrol Location 1 if SGroup_Exists("sg_northBase_mandrake_patrol") and Prox_AllSquadsNearMarker("sg_northBase_mandrake_patrol", "mkr_Patrol_North_1") then -- Reinforce BackUp before continuing patrol if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_northBase_mandrake_patrol",1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_northBase_mandrake_patrol",1)) and SGroup_GetAvgLoadout("sg_northBase_mandrake_patrol") < 0.75 then -- Reinforce Command_Squad(g_Player2, "sg_northBase_mandrake_patrol", SCMD_ReinforceTrooper) else -- Task to Next Patrol Point Cmd_AttackMoveMarker("sg_northBase_mandrake_patrol", "mkr_Patrol_North_6") end

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

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

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

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

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

--- Production Building & Patrol Squad are destroyed
if EGroup_Count("eg_hq_2") == 0 and
	SGroup_Count("sg_northBase_mandrake_patrol") == 0
then
	Rule_Remove(Rule_Patrol_North_Reverse)
end

end

-- Handles the WarpBeasts that Patrol the Prisoner Cage Area function Rule_Patrol_SouthWest() -- Check if the Squad arrived at the Patrol Location 1 if SGroup_Exists("sg_southWestBase_warpbeast_patrol") and Prox_AllSquadsNearMarker("sg_southWestBase_warpbeast_patrol", "mkr_Patrol_SouthWest_1") then -- Reinforce BackUp before continuing patrol if Squad_GetMax(SGroup_GetSpawnedSquadAt("sg_southWestBase_warpbeast_patrol",1)) > Squad_Count(SGroup_GetSpawnedSquadAt("sg_southWestBase_warpbeast_patrol",1)) and SGroup_GetAvgLoadout("sg_southWestBase_warpbeast_patrol") < 0.75 then -- Reinforce Command_Squad(g_Player2, "sg_southWestBase_warpbeast_patrol", SCMD_ReinforceTrooper) else -- Task to Next Patrol Point Cmd_AttackMoveMarker("sg_southWestBase_warpbeast_patrol", "mkr_Patrol_SouthWest_2") end

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

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

--- Production Building & Patrol Squad are destroyed
if EGroup_Count("eg_hallOfBlood_13") == 0 and
	SGroup_Count("sg_southWestBase_warpbeast_patrol") == 0
then
	Rule_Remove(Rule_Patrol_SouthWest)
end	

end

-- Produces the Archon & Ravens from the base where Vect Hangs Out function Rule_Production_VectBase() -- Produce the Archon if g_base_activated_Vect == true and SGroup_Count("sg_vectBase_archon") == 0 and Rule_Produce_Archon("sg_vectBase_archon", "eg_hq_8", "mkr_hq_8") then -- Reset Status (in case died while retreating etc...) g_vectBase_archon_status[1] = g_squad_produced end

-- Produce some Ravens for Air Unit Targeting
if g_base_activated_Vect == true and
	SGroup_Count("sg_vectBase_raven1") == 0 and
	Rule_Produce_Raven("sg_vectBase_raven1", "eg_skimmerShop_11", "mkr_skimmerShop_11")
then
	-- Reset Status (in case died while retreating etc...)
	g_vectBase_raven_status[1] = g_squad_produced

elseif g_base_activated_Vect == true and
	SGroup_Count("sg_vectBase_raven2") == 0 and
	Rule_Produce_Raven("sg_vectBase_raven2", "eg_skimmerShop_11", "mkr_skimmerShop_11")
then
	-- Reset Status (in case died while retreating etc...)
	g_vectBase_raven_status[2] = g_squad_produced
end

-- Base is destroyed, remove the rule	
if EGroup_Count("eg_hq_8") == 0 and
	EGroup_Count("eg_skimmerShop_11") == 0
then
	Rule_Remove(Rule_Production_VectBase)
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_Builder("sg_center_defense_slave1", "mkr_hq_4") Rule_RandomMovement_Support_Builder("sg_center_defense_slave2", "mkr_hq_4") Rule_RandomMovement_Support("sg_center_defense_warrior1", "mkr_hq_4") Rule_RandomMovement_Support("sg_center_defense_warrior2", "mkr_hq_4") Rule_RandomMovement_Support("sg_center_defense_reaver1", "mkr_hq_4") Rule_RandomMovement_Support("sg_center_defense_reaver2", "mkr_hq_4")

-- East Base:
Rule_RandomMovement_Support("sg_east_defense_reaver1", "mkr_hq_5")
Rule_RandomMovement_Support("sg_east_defense_reaver2", "mkr_hq_5")
Rule_RandomMovement_Support("sg_east_defense_reaver3", "mkr_hq_5")
Rule_RandomMovement_Support("sg_east_defense_reaver4", "mkr_hq_5")
for i =1, g_strongholdStrengthTier do
	Rule_RandomMovement_Support("sg_east_defense_warrior"..i, "mkr_hq_5")
end

-- Main Base:
Rule_RandomMovement_Support("sg_main_defense_mandrakes1", "mkr_hq_1")
Rule_RandomMovement_Support("sg_main_defense_mandrakes2", "mkr_hq_1")
Rule_RandomMovement_Support("sg_main_defense_ravager1", "mkr_hq_1")
Rule_RandomMovement_Support("sg_main_defense_ravager2", "mkr_hq_1")
Rule_RandomMovement_Support("sg_main_defense_talos", "mkr_hq_1")
Rule_RandomMovement_Support("sg_main_defense_raven1", "mkr_hq_1")
Rule_RandomMovement_Support("sg_main_defense_raven2", "mkr_hq_1")
for i =1, g_strongholdStrengthTier do
	Rule_RandomMovement_Support("sg_main_defense_warrior"..i, "mkr_hq_1")
end

-- North Base:
Rule_RandomMovement_Support("sg_north_defense_warrior1", "mkr_soulCage_5")
Rule_RandomMovement_Support("sg_north_defense_warrior2", "mkr_soulCage_5")
Rule_RandomMovement_Support("sg_north_defense_scourge1", "mkr_soulCage_5")
Rule_RandomMovement_Support("sg_north_defense_scourge2", "mkr_soulCage_5")

-- North West Base:
Rule_RandomMovement_Support("sg_northWest_defense_reaver1", "mkr_hq_3")
Rule_RandomMovement_Support("sg_northWest_defense_reaver2", "mkr_hq_3")

-- SouthEast Base:
Rule_RandomMovement_Support("sg_southEast_defense_scourge1", "mkr_hallOfBlood_11")
Rule_RandomMovement_Support("sg_southEast_defense_scourge2", "mkr_hallOfBlood_11")
Rule_RandomMovement_Support("sg_southEast_defense_talos", "mkr_hq_7")
Rule_RandomMovement_Support("sg_southEast_defense_ravager1", "mkr_power_17")
Rule_RandomMovement_Support("sg_southEast_defense_ravager2", "mkr_power_18")

-- SouthWest Base:
Rule_RandomMovement_Support("sg_southWest_defense_wych", "mkr_hallOfBlood_12")
Rule_RandomMovement_Support("sg_southWest_defense_warpBeast", "mkr_hallOfBlood_13")
Rule_RandomMovement_Support("sg_southWest_defense_haemonculus", "mkr_haemonculusLab_3")
Rule_RandomMovement_Support("sg_southWest_defense_talos", "mkr_skimmerShop_9")
Rule_RandomMovement_Support("sg_southWest_defense_ravager1", "mkr_hq_6")
Rule_RandomMovement_Support("sg_southWest_defense_ravager2", "mkr_hq_6")

-- West Base
Rule_RandomMovement_Support("sg_west_defense_talos", "mkr_skimmerShop_7")
Rule_RandomMovement_Support("sg_west_defense_mandrakes1", "mkr_skimmerShop_7")
Rule_RandomMovement_Support("sg_west_defense_mandrakes2", "mkr_skimmerShop_7")

end


-- END OF ALL " RANDOM MOVEMENT " RULES


-- VICTORY / DEFEAT RULES -- Rule_EndGame_Actual_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 -- Called once Vect is Killed function Rule_EndGame_Actual_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_Victory)	

Rule_AddInterval(Rule_GameOver, 1)

end

-- Rule for Losing the Game function Rule_EndGame_Defeat() -- define the "enemy" who will win when the player 'loses' g_enemy = g_Player2

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

end

-- Rule for Losing the Game : Version for if builders are lost before HQ is completed function Rule_EndGame_Defeat_Builders() -- define the "enemy" who will win when the player 'loses' g_enemy = g_Player2

--Lose because of Player Builder Annihilation (Make sure IE is not playing when check is made)	
if Event_IsAnyRunning() == false and
	SGroup_Exists("sg_player_freePrisoner7") and
	SGroup_Exists("sg_player_freePrisoner8") and
	SGroup_Exists("sg_player_freePrisoner9") and
	SGroup_Count("sg_player_freePrisoner7") == 0 and
	SGroup_Count("sg_player_freePrisoner8") == 0 and
	SGroup_Count("sg_player_freePrisoner9") == 0
then
	Rule_RemoveAll()
	Fade_Start(4, false)
	World_SetTeamWin( g_enemy, "" )
	Rule_AddInterval(Rule_GameOver,1)
	Rule_Remove( Rule_EndGame_Defeat_Builders )
end

end

-- Actually sets the Game Over function Rule_GameOver() if Event_IsAnyRunning() == false then World_SetGameOver() end end

-- END OF ALL " VICTORY / DEFEAT " RULES

Statystyki gry
Obserwujący
24
Przebiegi
69
Gracze
5
Najnowsze wątki
Opublikowano 2 years ago
1 odpowiedź