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

--[[ IMPORTS ]]

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


--[[ GAME SETUP ]]

--[[global variables]]

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

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

	factionname = "$690011"
	colorscheme = "default_8"

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

elseif MetaMap_GetPlayerRaceName() == "ork_race" then

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

	factionname = "$690010"
	colorscheme = "default_0"
	
	g_Player1 = Setup_Player(0, factionname, MetaMap_GetPlayerRaceName(), 1)
	
elseif MetaMap_GetPlayerRaceName() == "tau_race" then
	
	factionname = "$690015"
	colorscheme = "default_0"
	
	g_Player1 = Setup_Player(0, factionname, MetaMap_GetPlayerRaceName(), 1)
	
elseif MetaMap_GetPlayerRaceName() == "eldar_race" then

	factionname = "$690012"
	colorscheme = "default_5"

	g_Player1 = Setup_Player(0, factionname, MetaMap_GetPlayerRaceName(), 1)
	Misc_PlayerTeamColor(g_Player1, colorscheme)
	
end

g_Player2 = Setup_Player(1, "$690016", "necron_race", 2)
g_Player3 = Setup_Player(2, "$690016", "necron_race", 2)
g_Player4 = Setup_Player(3, "$690016", "necron_race", 2)
g_Player5 = Setup_Player(4, "$690016", "necron_race", 2)
g_Player6 = Setup_Player(5, "$690016", "necron_race", 2)
g_Player7 = Setup_Player(6, factionname, MetaMap_GetPlayerRaceName(), 1)
g_Player8 = Setup_Player(7, factionname, MetaMap_GetPlayerRaceName(), TEAM_NEUTRAL)



Misc_ForceAutoSwitchTeamColor(g_Player1, true)
Misc_ForceAutoSwitchTeamColor(g_Player2, true)
Misc_ForceAutoSwitchTeamColor(g_Player3, true)
Misc_ForceAutoSwitchTeamColor(g_Player4, true)
Misc_ForceAutoSwitchTeamColor(g_Player5, true)
Misc_ForceAutoSwitchTeamColor(g_Player6, true)
Misc_ForceAutoSwitchTeamColor(g_Player7, true)
Misc_ForceAutoSwitchTeamColor(g_Player8, true)

--[[ DEFINE VARIABLES AND TABLES - define any preset values here for later use]] g_firstrun = true g_Win = false g_Relic = false g_Target = 1 g_Escape = false g_Timer = 0 g_EscapeTimer = 8 g_MonolithFailed = false g_BeaconEncountered = false g_TunnelEncountered = false g_Timer1 = false g_Timer2 = false g_Researched = false

--difficulty variable
g_Difficulty = 0

g_AssassinSpawn1 = "mkr_S_Spawn7"
g_AssassinSpawn2 = "mkr_S_Tunnel14"
g_SaboteurSpawn1 = "mkr_S_Spawn7"
g_SaboteurSpawn2 = "mkr_S_Tunnel4"

g_HQ_Type = nil
g_Leader_Type = nil
g_Turret_Type = nil

g_Beacon1Found = false
g_Beacon2Found = false
g_Beacon3Found = false
g_Beacon4Found = false
g_MonolithsFound = false

g_Beacon1Dead = false
g_Beacon2Dead = false
g_Beacon3Dead = false
g_Beacon4Dead = false
g_MonolithsDead = false

--difficulty variable
g_Difficulty = 0
g_DBase = 10
g_DMax = 15
g_SmallSquadMin = 3
g_SmallSquadMax = 5
g_MediumSquadMin = 4
g_MediumSquadMax = 9
g_LargeSquadMin = 7
g_LargeSquadMax = 15

g_Penalties = false

--Objectives:
Objective_Bomb = {title_id = 2670000, short_desc_id = 2670001, help_tip_id = 2670000}
Objective_Survive = {title_id = 2670100, short_desc_id = 2670101, help_tip_id = 2670100}
Objective_Escape = {title_id = 2670200, short_desc_id = 2670201, help_tip_id = 2670200}
Objective_Monoliths = {title_id = 2670300, short_desc_id = 2670301, help_tip_id = 2670300}
Objective_Beacons = {title_id = 2670400, short_desc_id = 2670401, help_tip_id = 2670400}
Objective_Ressurection = {title_id = 2670500, short_desc_id = 2670501, help_tip_id = 2670500}
Objective_Darkness = {title_id = 2670600, short_desc_id = 2670601, help_tip_id = 2670600}
Objective_Chronometron = {title_id = 2670700, short_desc_id = 2670701, help_tip_id = 2670700}
Objective_Possession = {title_id = 2670800, short_desc_id = 2670801, help_tip_id = 2670800}

--[[ define the "enemy" who will win if the player 'loses' ]] g_enemy = g_Player2

--[[Win condition Objective]]

end


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

function OnGameRestore()

end


--[[ ON INITIALIZATION ]]

function OnInit()

--[[ RESEARCH LEVEL - sets the research level of the mission, locks researches, squads, and buildings for the appropriate mission number DOW specific!
 sets the research level of the mission, locks researches, squads, and buildings]]
Rule_SetResearchLevel( 4 )
	
	
--[[ NIS PRESETS - turn off event cues, set the viewable space to black (faded out) and preset letterboxing 
turn off event cues, set the viewable space to black (faded out) and preset letterboxing ]]
WXP_OpeningNISPreset()		
	
--[[ START THE MUSIC ]]
-- call the function to load the jukebox with tunes]]
Rule_SetupMusicPlaylist()	

--[[ SET AI - call the function to set the pregame state of the AI 
call the function to set the pregame state of the AI ]]
Rule_PresetAI()		
	
--[[ START NIS - calls the NIS function located in the MissionName.nis file 
calls the NIS function located in the MissionName.nis file ]]	
Util_StartNIS( EVENTS.NIS_Opening ) 
	

end

--[[ the Scar_AddInit(OnInit) function is mandatory! This registers your init function with scar. ]] Scar_AddInit(OnInit)


--[[ GAME RESTRICTIONS ]]

--[[ Disables, enables, and grants research items ]]

function Rule_SetResearchLevel( resLevel )

--[[ WXP Specific ]]
WXP_Restrict( resLevel )

end


--[[ MUSIC ]]

function Rule_SetupMusicPlaylist()

--t_music = {"MU_IG_STR_Eldar", "MU_IG_STR_Eldar_perc", "MU_IG_STR_Eldar_perc_brass", "MU_IG_STR_Eldar_perc_str"}

--Playlist_Manager( PC_Music, t_music, true, true , {20, 40})


--ambient sound
--t_ambient_sound = {"Snowy_wind_1"}


--Playlist_Manager( PC_Ambient, t_ambient_sound, true, true , {2, 4})


--music
t_music = {"MU_IG_THEME_Nightbringer", "MU_IG_STR_Necron", "MU_IG_STR_Necron_perc", "MU_IG_STR_Necron_perc_brass", "MU_IG_STR_Necron_perc_str"}

Playlist_Manager( PC_Music, t_music, true, true , {20, 40})


--ambient sound
t_ambient_sound = {"AM_IG_STR_Necron"}


Playlist_Manager( PC_Ambient, t_ambient_sound, true, true , {2, 4})

end


--[[ PRESET AI ]]

function Rule_PresetAI() --Cpu_EnableAll(true) Cpu_Enable(g_Player2, true) Cpu_Enable(g_Player3, false) Cpu_Enable(g_Player4, false) Cpu_Enable(g_Player5, false) Cpu_Enable(g_Player6, false) Cpu_Enable(g_Player7, false) Cpu_Enable(g_Player8, false) end


--[[ START PLAY ]]

--[[ NOW TO KICK OFF THE ACTUAL MISSION ONCE THE OPENING NIS IS DONE ]]

function Rule_GameStart()

if g_firstrun then
	
	g_Difficulty = MetaMap_GetTerritoryMilitaryStrength(MetaMap_GetDefendingTerritoryIndex())
	g_SmallSquadSize = g_SmallSquadMin + math.floor ((g_Difficulty - g_DBase) * ((g_SmallSquadMax - g_SmallSquadMin) / (g_DMax - g_DBase)))
	g_MediumSquadSize = g_MediumSquadMin + math.floor ((g_Difficulty - g_DBase) * ((g_MediumSquadMax - g_MediumSquadMin) / (g_DMax - g_DBase)))
	g_LargeSquadSize = g_LargeSquadMin + math.floor ((g_Difficulty - g_DBase) * ((g_LargeSquadMax - g_LargeSquadMin) / (g_DMax - g_DBase)))

	
	--[[ set resources ]]
	Player_SetAllResources(g_Player1, 1000, 100, 14)
	Player_SetAllResources(g_Player2, 0, 1000, 60)
	Player_SetMaxSquadCap(g_Player2, 99)
	Player_SetMaxSupportCap(g_Player2, 60)
	Player_SetAllResources(g_Player3, 0, 1000, 20)
	Player_SetAllResources(g_Player4, 0, 1000, 20)
	Player_SetAllResources(g_Player5, 0, 1000, 20)
	Player_SetAllResources(g_Player6, 0, 1000, 20)
	Player_SetAllResources(g_Player7, 0, 0, 0)
	Player_SetAllResources(g_Player8, 0, 0, 0)
		
	--[[ DIFFICULTY LEVEL - gets the difficulty level from the UI and passes it into the function]]
	Rule_SetDifficultyLevel( Difficulty_Get() )
	
	--[[ Get the AI doing whatever after the NIS is over ]]
	Rule_StartAI()

	Rule_AddOneShot(Rule_IntroSpeech, 2)
	
	

-- Primary Objectives Rule_AddIntervalDelay(Rule_Objective_Bomb, 1, 20) --must be added before the secondary objectives Rule_AddIntervalDelay(Rule_Objective_Survive, 5, 21) --must be added before the secondary objectives

-- Secondary Objective Rule_AddIntervalDelay(Rule_Objective_Beacons, 4, 90)

	SGroup_Create("sg_MonolithAssassins")
	SGroup_Create("sg_MonolithSaboteurs")
	SGroup_Create("sg_TunnelAssassins")
	SGroup_Create("sg_TunnelSaboteurs")


	--let the necrons make the nightbringer
	Player_GrantResearch(g_Player2, "necron_night_bringer_research")
	Player_GrantResearch(g_Player2, "necron_resurrection_orb_research")

	--[[Set up timer]]
	Rule_AddOneShot(Rule_Add_Timer, 1) --this will need to be put after the Nis
	
	Rule_AddOneShot(Rule_Create_Player_Buildings, 0)
	Rule_AddOneShot(Rule_MidNIS, 120)
	
	-- Populate the level with bad-guy buildings.
	Rule_AddOneShot(Rule_CreateNecronBuildings, 0)
	
	-- Start up all the guards
	Rule_AddOneShot(Rule_CreateGuards, 1)

	-- Start up units that hunt the hero
	g_AssassinInterval = 180 + math.floor ((g_Difficulty - g_DBase) * ((90 - 180) / (g_DMax - g_DBase)))
	Rule_AddInterval(Rule_MonolithAssassins, g_AssassinInterval)
	Rule_AddIntervalDelay(Rule_TunnelAssassins, g_AssassinInterval, 45)

	-- Start up units that raid the base
	Rule_AddIntervalDelay(Rule_MonolithSaboteurs, g_AssassinInterval, 22)
	Rule_AddIntervalDelay(Rule_TunnelSaboteurs, g_AssassinInterval, 67)
	
	-- Set up triggers for tunnel swarms
	Rule_AddInterval(Rule_TunnelTrigger1, 5)
	Rule_AddIntervalDelay(Rule_TunnelTrigger2, 5, 1)
	Rule_AddIntervalDelay(Rule_TunnelTrigger3, 5, 2)
	Rule_AddIntervalDelay(Rule_TunnelTrigger4, 5, 3)
	Rule_AddIntervalDelay(Rule_TunnelTrigger5, 5, 4)
	Rule_AddInterval(Rule_TunnelTrigger6, 5)
	Rule_AddIntervalDelay(Rule_TunnelTrigger7, 5, 1)
	Rule_AddIntervalDelay(Rule_TunnelTrigger8, 5, 2)
	Rule_AddIntervalDelay(Rule_TunnelTrigger9, 5, 3)
	
	Rule_AddInterval(Rule_DiscoverTunnel1, 2)
	Rule_AddInterval(Rule_DiscoverTunnel2, 2)
	Rule_AddInterval(Rule_DiscoverTunnel3, 2)
	Rule_AddInterval(Rule_DiscoverTunnel4, 2)
	Rule_AddInterval(Rule_DiscoverTunnel5, 2)
	
	--[[ Set up a Lose Check ]]
	Rule_AddInterval(Rule_EndGameLose, 10)		
	
	--TEST... REMOVE THIS LINE BEFORE FINAL
	Entity_Create("sm_bomb", g_Player8, Marker_GetPosition(Marker_FromName("mkr_Escape", "basic_marker")))

	--[[ Clean up ]]
	Rule_Remove(Rule_GameStart)
	

end

end

function Rule_MidNIS() Util_StartNIS( EVENTS.NIS_Mid ) Rule_AddIntervalDelay(Rule_TunnelTrigger10, 5, 120) end

function Rule_StartAI()

--Cpu_EnableAll(true)
Cpu_Enable(g_Player2, false)	
Cpu_Enable(g_Player3, false)	
Cpu_Enable(g_Player4, false)	
Cpu_Enable(g_Player5, false)	
Cpu_Enable(g_Player6, false)	
Cpu_Enable(g_Player7, false)	
Cpu_Enable(g_Player8, false)	

end


--[[ DIFFICULTY ]]

function Rule_SetDifficultyLevel( difficultyLevel )

--[[ STATIC MODIFIERS ]]
-- Use this space to set any Static Modifiers. ifiers that will not change with the difficulty setting.

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

--[[ DIFFICULTY GENERAL RULES ]]
--[[ Types of things that can me done	include: 
a) adding resource values
b) changing variables for the number of starting units a player recieves 
b) or even activating new objectives (although we refrained from this in DoW as the increased testing requirements it dictates)
]]	
-- easy
if difficultyLevel == DIFFICULTY_EASY then

	--g_Difficulty = 1
	

	
	--[[force commander]]
	
	--health and armor
	local ModID7 = Modifier_Create(MAT_EntityType , "health_maximum_modifier", MUT_Multiplication, false, 10 , "force_commander")
	Modifier_ApplyToPlayer( ModID7, g_Player2  )
	
	local ModID8 = Modifier_Create(MAT_EntityType, "armour_modifier", MUT_Multiplication, false, 1.2, "force_commander")
	Modifier_ApplyToPlayer( ModID8, g_Player2)
	
	--ranged weapon
	local ModID9 = Modifier_Create(MAT_WeaponType, "max_damage_weapon_modifier", MUT_Multiplication, false, 1.5, "space_marine_bolt_pistol_forcecommander")
	Modifier_ApplyToPlayer( ModID9, g_Player2)
	
	local ModID10 = Modifier_Create(MAT_WeaponType, "min_damage_weapon_modifier", MUT_Multiplication, false, 1.5, "space_marine_bolt_pistol_forcecommander")
	Modifier_ApplyToPlayer( ModID10, g_Player2)
	
	--melee weapon
	local ModID11 = Modifier_Create(MAT_WeaponType, "min_damage_weapon_modifier", MUT_Multiplication, false, 1.5, "space_marine_power_sword_force_commander")
	Modifier_ApplyToPlayer( ModID11, g_Player2)
	
	local ModID12 = Modifier_Create(MAT_WeaponType, "min_damage_weapon_modifier", MUT_Multiplication, false, 1.5, "space_marine_power_sword_force_commander")
	Modifier_ApplyToPlayer( ModID12, g_Player2)
	

	
-- medium
elseif difficultyLevel == DIFFICULTY_NORMAL then

	--g_Difficulty = 2
	
	--[[force commander]]
	
	--health and armor
	local ModID7 = Modifier_Create(MAT_EntityType , "health_maximum_modifier", MUT_Multiplication, false, 10 , "force_commander")
	Modifier_ApplyToPlayer( ModID7, g_Player2  )
	
	local ModID8 = Modifier_Create(MAT_EntityType, "armour_modifier", MUT_Multiplication, false, 1.2, "force_commander")
	Modifier_ApplyToPlayer( ModID8, g_Player2)
	
	--ranged weapon
	local ModID9 = Modifier_Create(MAT_WeaponType, "max_damage_weapon_modifier", MUT_Multiplication, false, 1.5, "space_marine_bolt_pistol_forcecommander")
	Modifier_ApplyToPlayer( ModID9, g_Player2)
	
	local ModID10 = Modifier_Create(MAT_WeaponType, "min_damage_weapon_modifier", MUT_Multiplication, false, 1.5, "space_marine_bolt_pistol_forcecommander")
	Modifier_ApplyToPlayer( ModID10, g_Player2)
	
	--melee weapon
	local ModID11 = Modifier_Create(MAT_WeaponType, "min_damage_weapon_modifier", MUT_Multiplication, false, 1.5, "space_marine_power_sword_force_commander")
	Modifier_ApplyToPlayer( ModID11, g_Player2)
	
	local ModID12 = Modifier_Create(MAT_WeaponType, "min_damage_weapon_modifier", MUT_Multiplication, false, 1.5, "space_marine_power_sword_force_commander")
	Modifier_ApplyToPlayer( ModID12, g_Player2)
	
	
	
-- hard
elseif difficultyLevel == DIFFICULTY_HARD then
	
	--g_Difficulty = 3
	
			--[[force commander]]
	
	--health and armor
	local ModID7 = Modifier_Create(MAT_EntityType , "health_maximum_modifier", MUT_Multiplication, false, 10 , "force_commander")
	Modifier_ApplyToPlayer( ModID7, g_Player2  )
	
	local ModID8 = Modifier_Create(MAT_EntityType, "armour_modifier", MUT_Multiplication, false, 1.2, "force_commander")
	Modifier_ApplyToPlayer( ModID8, g_Player2)
	
	--ranged weapon
	local ModID9 = Modifier_Create(MAT_WeaponType, "max_damage_weapon_modifier", MUT_Multiplication, false, 1.5, "space_marine_bolt_pistol_forcecommander")
	Modifier_ApplyToPlayer( ModID9, g_Player2)
	
	local ModID10 = Modifier_Create(MAT_WeaponType, "min_damage_weapon_modifier", MUT_Multiplication, false, 1.5, "space_marine_bolt_pistol_forcecommander")
	Modifier_ApplyToPlayer( ModID10, g_Player2)
	
	--melee weapon
	local ModID11 = Modifier_Create(MAT_WeaponType, "min_damage_weapon_modifier", MUT_Multiplication, false, 1.5, "space_marine_power_sword_force_commander")
	Modifier_ApplyToPlayer( ModID11, g_Player2)
	
	local ModID12 = Modifier_Create(MAT_WeaponType, "min_damage_weapon_modifier", MUT_Multiplication, false, 1.5, "space_marine_power_sword_force_commander")
	Modifier_ApplyToPlayer( ModID12, g_Player2)
	
	
end

end

function Rule_Increase_AI()

-- Cpu_SetDifficulty(g_Player3, AD_Standard)

Rule_AddOneShot(Rule_Increase_AI2, 1000)

end

function Rule_Increase_AI2()

Rule_AddOneShot(Rule_Increase_AI3,1000)

end

function Rule_Increase_AI3()

Rule_AddOneShot(Rule_Increase_AI4, 1000)

end

function Rule_Increase_AI4()

Cpu_SetDifficulty(g_Player2,   AD_Hard)
Cpu_SetDifficulty(g_Player3,   AD_Hard)
Cpu_SetDifficulty(g_Player4,   AD_Hard)
Cpu_SetDifficulty(g_Player5,   AD_Hard)
Cpu_SetDifficulty(g_Player6,   AD_Hard)
Cpu_SetDifficulty(g_Player7,   AD_Hard)
Cpu_SetDifficulty(g_Player8,   AD_Hard)

end


--[[ CORE GAME ]]


--[[Spawning andUpgrading Things on the map]]

--[[create the player buildings]]

function Rule_Create_Player_Buildings()

t_Player_Buildings ={

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

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

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

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

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

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

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

}

t_Player_Builder_Units = {

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

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

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

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

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

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

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


--setting up the upgrades for the commander
MetaMap_UpdatePlayerWargear(g_Player1)


if MetaMap_GetPlayerRaceName() == "chaos_marine_race" then

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

	--i'm saving the hq blueprint in order to use it later
	g_HQ_Type = "chaos_hq"
	g_Leader_Type = "chaos_squad_lord_advance_sp"
	g_Turret_Type = "chaos_turret_bolter"
						
	--win/loss
	t_building_exceptions = {
	"chaos_thermo_plasma_generator",
	"chaos_plasma_generator",
	"chaos_turret_bolter",
	"chaos_mine_field"}
		
	t_unit_exceptions = {}
		
	t_vehicle_types = Util_MakeBlueprintTable(
	"chaos_squad_defiler",
	"chaos_squad_defiler_advance_sp",
	--"chaos_squad_rhino",
	"chaos_squad_predator"
	)
	
		
elseif MetaMap_GetPlayerRaceName() == "eldar_race" then

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

	--i'm saving the hq blueprint in order to use it later
	g_HQ_Type = "eldar_hq"
	g_Leader_Type = "eldar_squad_farseer_advance_sp"
	g_Turret_Type = "eldar_support_platform_scatterlaser"
	
	--win/loss
	t_building_exceptions = {
	"eldar_advanced_warp_generator",
	"eldar_warp_generator",}
	
	t_unit_exceptions = {}

	t_vehicle_types = Util_MakeBlueprintTable(
	--"eldar_squad_falcon_grav_tank",
	--"eldar_squad_falcon_grav_tank_advance_sp",
	"eldar_squad_fire_prism",
	"eldar_squad_vypers",
	"eldar_squad_vypers_advance_sp",
	"eldar_squad_wraithlord",
	"eldar_squad_wraithlord_advance_sp")
	

elseif MetaMap_GetPlayerRaceName() == "guard_race" then

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

	--i'm saving the hq blueprint in order to use it later
	g_HQ_Type = "guard_hq"
	g_Leader_Type = "guard_squad_command_squad_advance_sp"
	g_Turret_Type = "guard_turret_heavy_bolter"
	
	--win/loss
	t_building_exceptions = {
	"guard_thermo_plasma",
	"guard_plasma_generator",
	"guard_turret_heavy_bolter",
	"guard_mines"}
	
	t_unit_exceptions = {}

	t_vehicle_types = Util_MakeBlueprintTable(
	"guard_squad_baneblade",
	"guard_squad_basilisk",
	"guard_squad_basilisk_sp_mso2",
	--"guard_squad_chimera",
	--"guard_squad_chimera_sp_test",
	"guard_squad_hellhound",
	"guard_squad_hellhound_advance_sp",
	"guard_squad_lemanruss",
	"guard_squad_sentinel",
	"guard_squad_sentinel_advance_sp")

elseif MetaMap_GetPlayerRaceName() == "ork_race" then

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

	--i'm saving the hq blueprint in order to use it later
	g_HQ_Type = "ork_hq"
	g_Leader_Type = "ork_squad_warboss_advance_sp"
	g_Turret_Type = "ork_waagh_banner"
	
	--win/loss
	t_building_exceptions = {
	"ork_bigger_generator",
	"ork_generator",
	"ork_waagh_banner",
	"ork_mine_field"}
	
	t_unit_exceptions = {}
	
	t_vehicle_types = Util_MakeBlueprintTable(
	"ork_squad_killa_kan",
	"ork_squad_killa_kan_advance_sp",
	"ork_squad_looted_tank",
	"ork_squad_looted_tank_sp",
	--"ork_squad_trukk",
	--"ork_squad_trukk_advance_sp",
	"ork_squad_wartrak",
	"ork_squad_wartrak_advance_sp")

elseif MetaMap_GetPlayerRaceName() == "space_marine_race" then

	for i = 1, table.getn(t_Player_Buildings.marines_name) do
		Entity_CreateBuildingMarker(g_Player1, t_Player_Buildings.marines_name[i], t_Player_Buildings.marines_building_blueprint[i], t_Player_Buildings.marines_marker_spawn[i], 1)
		Util_CreateSquadsAtMarkerEx(g_Player1, t_Player_Builder_Units.marines_buildername[i], t_Player_Builder_Units.marines_builder_blueprint[i], t_Player_Builder_Units.marines_buildermarker_spawn[i], 1, 1)
	end
	
	--i'm saving the hq blueprint in order to use it later
	g_HQ_Type = "space_marine_hq"
	g_Leader_Type = "space_marine_squad_force_commander_advance_sp"
	g_Turret_Type = "space_marine_turret_bolter"
	
	--win/loss
	t_building_exceptions = {
	"space_marine_thermo_generator",
	"space_marine_generator",
	"space_marine_turret_bolter",
	"space_marine_mine_field"}
	
	t_unit_exceptions = {}
	
	t_vehicle_types = Util_MakeBlueprintTable(
	"space_marine_squad_dreadnought",
	"space_marine_squad_dreadnought_advance_sp",
	"space_marine_squad_dreadnought_hellfire",
	"space_marine_squad_dreadnought_hellfire_advance_sp",
	--"space_marine_squad_land_raider",
	"space_marine_squad_land_speeder",
	"space_marine_squad_land_speeder_advance_sp",
	"space_marine_squad_predator",
	--"space_marine_squad_rhino",
	"space_marine_squad_whirlwind")

elseif MetaMap_GetPlayerRaceName() == "tau_race" then
	
	for i = 1, table.getn(t_Player_Buildings.tau_name) do
		Entity_CreateBuildingMarker(g_Player1, t_Player_Buildings.tau_name[i], t_Player_Buildings.tau_building_blueprint[i], t_Player_Buildings.tau_marker_spawn[i], 1)
		Util_CreateSquadsAtMarkerEx(g_Player1, t_Player_Builder_Units.tau_buildername[i], t_Player_Builder_Units.tau_builder_blueprint[i], t_Player_Builder_Units.tau_buildermarker_spawn[i], 1, 1)
	end
	
	--i'm saving the hq blueprint in order to use it later
	g_HQ_Type = "tau_hq"
	g_Leader_Type = "tau_commander_squad_advance_sp"
	g_Turret_Type = "space_marine_turret_bolter"
	
	--win/loss
	t_building_exceptions = {
	"tau_thermoplasma_generator",
	"tau_plasma_generator",}
	
	t_unit_exceptions = {}
	
	t_vehicle_types = Util_MakeBlueprintTable(
	--"tau_devilfish_troop_carrier",
	--"tau_devilfish_troop_carrier_clone_sp",
	"tau_drone_harbinger_squad",
	"tau_drone_harbinger_squad_advance_sp",
	"tau_drone_harbinger_squad_clone_sp",
	"tau_hammerhead_gunship_squad",
	"tau_hammerhead_gunship_squad_clone_sp",
	"tau_skyray_squad",
	"tau_skyray_squad_advance_sp",
	"tau_skyray_squad_clone_sp")

end

--blueprint table with the relevant hq

	t_no_chrono = Util_MakeBlueprintTable(
	"space_marine_squad_rhino",
	"space_marine_squad_land_raider",
	"space_marine_squad_force_commander_advance_sp",
	"ork_squad_trukk",
	"ork_squad_trukk_advance_sp",
	"ork_squad_squiggoth",
	"ork_squad_squiggoth_sp_long_rampage",
	"ork_squad_warboss_advance_sp",
	"guard_squad_chimera",
	"guard_squad_chimera_sp_test",
	"guard_squad_command_squad_advance_sp",	
	"eldar_squad_falcon_grav_tank",
	"eldar_squad_falcon_grav_tank_advance_sp",
	"eldar_squad_farseer_advance_sp",
	"chaos_squad_rhino",
	"chaos_squad_lord_advance_sp",
	"tau_devilfish_troop_carrier",
	"tau_devilfish_troop_carrier_clone_sp",
	"tau_commander_squad_advance_sp"
	)
	


t_blueprinthq = Util_MakeBlueprintTable(g_HQ_Type)
t_blueprintleader = Util_MakeBlueprintTable(g_Leader_Type, "chaos_squad_daemon_prince_advance_sp")
t_blueprintturret = Util_MakeBlueprintTable(g_Turret_Type)

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

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

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

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

if MetaMap_GetPlayerRaceName() == "chaos_marine_race" then

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

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

t_blueprintEntitybonus = {}
MetaMap_GetAttackingRaceStartingEntitiesList(t_blueprintEntitybonus)

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

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

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


SGroup_AddGroup(SGroup_CreateIfNotFound("sg_Player1_Squads"), Player_GetSquads(g_Player1))
local countsquads = SGroup_CountSpawned(SGroup_FromName("sg_Player1_Squads"))
SGroup_Clear(SGroup_CreateIfNotFound("sg_Leader"))

for i = 1, countsquads do
	
	SGroup_Clear(SGroup_CreateIfNotFound("sg_Potential"))
		
	SGroup_Add(SGroup_FromName("sg_Potential"), SGroup_GetSpawnedSquadAt("sg_Player1_Squads", i))

	if SGroup_ContainsBlueprints(SGroup_FromName("sg_Potential"), t_blueprintleader, false) then
		
			
		SGroup_Clear(SGroup_CreateIfNotFound("sg_Leader"))
		SGroup_AddGroup(SGroup_FromName("sg_Leader"), SGroup_FromName("sg_Potential"))
		
		break
	end
end

if SGroup_IsEmpty("sg_Leader") then
end

Rule_Remove(Rule_Create_Player_Buildings)

end

function Rule_CreateNecronBuildings()

--Necron Archives = 2
for i = 1, 2 do
	Entity_CreateBuildingMarker(g_Player2,"eg_Archive"..i, "necron_forbidden_archive","mkr_S_Archive"..i, 1)
end


--Necron Beacons = 4
--TODO: REPLACE WITH ACTUAL BEACON OBJECT
for i = 1, 1 do
	Entity_CreateBuildingMarker(g_Player2,"eg_Beacon"..i, "npc_necron_resurrection_beacon","mkr_S_Beacon"..i, 1)
end

for i = 2, 2 do
	Entity_CreateBuildingMarker(g_Player2,"eg_Beacon"..i, "npc_necron_possession_beacon","mkr_S_Beacon"..i, 1)
end

for i = 3, 3 do
	Entity_CreateBuildingMarker(g_Player2,"eg_Beacon"..i, "npc_necron_chronometron_beacon","mkr_S_Beacon"..i, 1)
end

for i = 4, 4 do
	Entity_CreateBuildingMarker(g_Player2,"eg_Beacon"..i, "npc_necron_veil_beacon","mkr_S_Beacon"..i, 1)
end

--Necron Corpses = 3
for i = 1, 3 do
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_Corpses"..i, "necron_basic_warrior_squad", "mkr_S_Corpses"..i, 1, g_MediumSquadSize)
	Cpu_LockSGroupAcrossPlayers("sg_Corpses"..i)
	Cmd_SetStance("sg_Corpses"..i, STANCE_Hold)
end

--Necron Cloakers = 3
for i = 1, 3 do
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_Cloakers"..i, "necron_basic_warrior_squad", "mkr_S_Cloakers"..i, 1, g_MediumSquadSize)
	Cpu_LockSGroupAcrossPlayers("sg_Cloakers"..i)
	Cmd_SetStance("sg_Cloakers"..i, STANCE_CeaseFire)
end


--Necron Energy Cores = 5
for i = 1, 5 do
	Entity_CreateBuildingMarker(g_Player2,"eg_EnergyCore"..i, "necron_energy_core","mkr_S_Energy"..i, 1)
end

--Necron Generators = 17
for i = 1, 17 do
	Entity_CreateBuildingMarker(g_Player2,"eg_Generator"..i, "necron_plasma_generator","mkr_S_Generator"..i, 1)
end

--Necron Monoliths = 9
for i = 1, 1 do
	Entity_CreateBuildingMarker(g_Player3,"eg_Monolith"..i, "monolith","mkr_S_Monolith"..i, 1)
	Cpu_LockEGroupAcrossPlayers("eg_Monolith"..i)
	EGroup_ForceAddOn("eg_Monolith"..i, "addon_necron_hq_1")
end

for i = 2, 2 do
	Entity_CreateBuildingMarker(g_Player4,"eg_Monolith"..i, "monolith","mkr_S_Monolith"..i, 1)
	Cpu_LockEGroupAcrossPlayers("eg_Monolith"..i)
	EGroup_ForceAddOn("eg_Monolith"..i, "addon_necron_hq_1")
end

for i = 3, 3 do
	Entity_CreateBuildingMarker(g_Player5,"eg_Monolith"..i, "monolith","mkr_S_Monolith"..i, 1)
	Cpu_LockEGroupAcrossPlayers("eg_Monolith"..i)
	EGroup_ForceAddOn("eg_Monolith"..i, "addon_necron_hq_1")
end

for i = 4, 4 do
	Entity_CreateBuildingMarker(g_Player6,"eg_Monolith"..i, "monolith","mkr_S_Monolith"..i, 1)
	Cpu_LockEGroupAcrossPlayers("eg_Monolith"..i)
	EGroup_ForceAddOn("eg_Monolith"..i, "addon_necron_hq_1")
end

for i = 5, 6 do
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_Monolith"..i, "necron_restored_monolith_squad", "mkr_S_Monolith"..i, 1, 1)
	Cpu_LockSGroupAcrossPlayers("sg_Monolith"..i)
	Cmd_SetStance("sg_Monolith"..i, STANCE_StandGround)
end

for i = 7, 7 do
	Entity_CreateBuildingMarker(g_Player2,"eg_Monolith"..i, "monolith","mkr_S_Monolith"..i, 1)
	Cpu_LockEGroupAcrossPlayers("eg_Monolith"..i)
end

for i = 8, 9 do
	Entity_CreateBuildingMarker(g_Player2,"eg_Monolith"..i, "monolith","mkr_S_Monolith"..i, 1)
	Cpu_LockEGroupAcrossPlayers("eg_Monolith"..i)
	EGroup_ForceAddOn("eg_Monolith"..i, "addon_necron_hq_1")
end

--Necron Summoning Cores = 4
for i = 1, 4 do
	Entity_CreateBuildingMarker(g_Player2,"eg_Summoning"..i, "necron_summoning_core","mkr_S_Summoning"..i, 1)
end

--Necron Greater Summoning Cores = 1
for i = 1, 1 do
	Entity_CreateBuildingMarker(g_Player2,"eg_GreaterSummoning"..i, "necron_greater_summoning_core","mkr_S_Greater"..i, 1)
end

--Necron Turrets = 21
for i = 1, 21 do
	Entity_CreateBuildingMarker(g_Player2,"eg_Turret"..i, "necron_turret","mkr_S_Turret"..i, 1)
end

--Necron Missile Turrets = 22
for i = 1, 22 do
	Entity_CreateBuildingMarker(g_Player2,"eg_Missile"..i, "necron_turret","mkr_S_Missile"..i, 1)
	EGroup_ForceAddOn("eg_Missile"..i, "addon_necron_turret")
end

--Necron Tomb Spyders = 3
for i = 1, 3 do
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TombSpyder"..i, "necron_tomb_spyder_squad", "mkr_S_TombSpyder"..i, 1, 1)
	Cpu_LockSGroupAcrossPlayers("sg_TombSpyder"..i)
	World_SetDeadMissionStart("sg_TombSpyder"..i)
end

Rule_AddOneShot(Rule_CreateLord, 5)
Rule_AddOneShot(Rule_Shockwave1, 5)
Rule_AddOneShot(Rule_UpgradeMonoliths, 15)
Rule_AddOneShot(Rule_KillCorpses, 1)
Rule_AddInterval(Rule_TriggerBeacon1, 4)	
Rule_AddInterval(Rule_TriggerBeacon2, 4)	
Rule_AddInterval(Rule_TriggerBeacon3, 4)	
Rule_AddInterval(Rule_TriggerBeacon4, 4)
Rule_AddInterval(Rule_EncounterMonoliths, 4)

end

function Rule_Shockwave1() if g_Difficulty > g_DBase then Command_EntityBuild( g_Player2, EGroup_FromName("eg_Monolith7"), "necron_tomb_spyder_squad") end if g_Difficulty > (g_DBase + 4) then Rule_AddOneShot(Rule_Shockwave4, 3) Util_CreateSquadsAtMarkerEx(g_Player2, "sg_ShockDestroyer1", "necron_destroyer_squad", "mkr_TunnelTrigger1", 1, 1) Util_CreateSquadsAtMarkerEx(g_Player2, "sg_ShockPariahs1", "necron_pariah_squad", "mkr_TunnelTrigger1", 1, g_SmallSquadSize) end

Util_CreateSquadsAtMarkerEx(g_Player2, "sg_Deepstrike1", "necron_flayed_one_squad", "mkr_DeepstrikeSpawn1", 1, g_MediumSquadSize)
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_Deepstrike2", "necron_flayed_one_squad", "mkr_DeepstrikeSpawn2", 1, g_MediumSquadSize)

Util_CreateSquadsAtMarkerEx(g_Player2, "sg_ShockImmortals1", "necron_immortal_squad", "mkr_TunnelTrigger1", 1, g_SmallSquadSize)
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_ShockImmortals2", "necron_immortal_squad", "mkr_TunnelTrigger1", 1, g_SmallSquadSize)
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_ShockPariahs1", "necron_pariah_squad", "mkr_TunnelTrigger1", 1, g_SmallSquadSize)
if g_Difficulty > (g_DBase + 2) then
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_ShockDestroyer1", "necron_heavy_destroyer_squad", "mkr_TunnelTrigger1", 1, 1)
else
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_ShockDestroyer1", "necron_destroyer_squad", "mkr_TunnelTrigger1", 1, 1)
end

for i = 1, 4 do
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_BombAmbush"..i, "necron_flayed_one_squad", "mkr_BombAmbush"..i, 1, g_MediumSquadSize)
	SGroup_DeSpawn("sg_BombAmbush"..i)
end

Cmd_AttackMoveMarker("sg_ShockImmortals1", "mkr_Player_HQ")

SGroup_DeSpawn("sg_Deepstrike1")
SGroup_DeSpawn("sg_Deepstrike2")

g_ShockwaveDelay = 60 + math.floor ((g_Difficulty - g_DBase) * ((20 - 50) / (g_DMax - g_DBase)))

Rule_AddOneShot(Rule_Shockwave2, g_ShockwaveDelay)

end

function Rule_Shockwave2() if g_Difficulty > (g_DBase + 2) then Command_EntityBuild( g_Player2, EGroup_FromName("eg_Monolith8"), "necron_tomb_spyder_squad") end Cmd_AttackMoveMarker("sg_ShockImmortals2", "mkr_Player_HQ") Squad_DeepStrikeToPos(SGroup_FromName("sg_Deepstrike1"), "monolith", Marker_GetPosition(Marker_FromName("mkr_Deepstrike1", "basic_marker"))) Rule_AddOneShot(Rule_Shockwave3, g_ShockwaveDelay) end

function Rule_Shockwave3() Cmd_AttackMoveMarker("sg_ShockDestroyer1", "mkr_Player_HQ") Cmd_AttackMoveMarker("sg_ShockPariahs1", "mkr_Player_HQ") Squad_DeepStrikeToPos(SGroup_FromName("sg_Deepstrike2"), "monolith", Marker_GetPosition(Marker_FromName("mkr_Deepstrike2", "basic_marker"))) end

function Rule_Shockwave4() Command_EntityBuild( g_Player2, EGroup_FromName("eg_Monolith9"), "necron_tomb_spyder_squad") end

function Rule_CreateLord() --Necron Lord for i = 1, 1 do Util_CreateSquadsAtMarkerEx(g_Player2, "sg_NecronLord", "necron_lord_squad_advance_sp", "mkr_S_Lord"..i, 1, 1) Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_NecronLord"), 1),"necron_lord_staff_of_light_gauss_flayer", 1) Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_NecronLord"), 1),"necron_lord_staff_of_light_skinning_blades", 1) Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_NecronLord"), 1),"necron_lord_staff_of_light_reaping_blades", 1) Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_NecronLord"), 1),"necron_lord_ribcage", 1) Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_NecronLord"), 1),"necron_lord_death_mask", 1) Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_NecronLord"), 1),"necron_lord_under_shoulder", 1) Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_NecronLord"), 1),"necron_lord_death_shroud", 1) Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_NecronLord"), 1),"necron_lord_gauntlets", 1)

	Player_GrantResearch(g_Player2, "necron_night_bringer_research")
	
	Cpu_LockSGroupAcrossPlayers("sg_NecronLord")
	Cmd_SetStance("sg_NecronLord", STANCE_CeaseFire)
end
Rule_Add(Rule_NecronLordAttack)

end

function Rule_KillCorpses() for i = 1, 3 do SGroup_SetPlayerOwner( "sg_Corpses"..i, g_Player8) Anim_PlaySGroupAnim("sg_Corpses"..i, "die")

	--SGroup_SelfDestroy("sg_Corpses"..i,true)
end

end

function Rule_EncounterMonoliths() if Player_AreSquadsNearMarker(g_Player1, "mkr_MonolithTrigger") then Rule_AddIntervalDelay(Rule_Objective_Monoliths, 4, 13)

	if MetaMap_GetPlayerRaceName() == "chaos_marine_race" then
		Util_StartIntel(EVENTS.IE_Chaos_Monoliths)
	elseif MetaMap_GetPlayerRaceName() == "eldar_race" then
		Util_StartIntel(EVENTS.IE_Eldar_Monoliths)
	elseif MetaMap_GetPlayerRaceName() == "guard_race" then
		Util_StartIntel(EVENTS.IE_IG_Monoliths)
	elseif MetaMap_GetPlayerRaceName() == "ork_race" then
		Util_StartIntel(EVENTS.IE_Ork_Monoliths)
	elseif MetaMap_GetPlayerRaceName() == "space_marine_race" then
		Util_StartIntel(EVENTS.IE_SM_Monoliths)
	elseif MetaMap_GetPlayerRaceName() == "tau_race" then
		Util_StartIntel(EVENTS.IE_Tau_Monoliths)
	end
	
	Rule_Remove(Rule_EncounterMonoliths)
end

end

function Rule_TriggerBeacon1() -- RESSURECTION BEACON if Player_AreSquadsNearMarker(g_Player1, "mkr_TriggerBeacon1") or g_Escape then if not EGroup_IsEmpty("eg_Beacon1") then

		if g_Escape then
			Cmd_EGroupCastAbilitySelf("eg_Beacon1", "necron_mass_resurrection_beacon2")
		else
			Cmd_EGroupCastAbilitySelf("eg_Beacon1", "necron_mass_resurrection_beacon")
		end
		
		for i = 1, 3 do
			Anim_PlaySGroupAnim("sg_Corpses"..i, "die_getup")
		end

		Util_MarkerFX("mkr_S_Beacon1", "data:Art/Events/Necron/sp/beacon_pulse")
		Util_MarkerFX("mkr_S_Beacon1", "data:Art/Events/Necron/necron_resurrect")
		
		FOW_RevealArea(57, 210, 50,  30)

		Rule_AddInterval(Rule_Objective_Ressurection, 2)

		if not g_Escape then
			if not g_BeaconEncountered then
				if MetaMap_GetPlayerRaceName() == "chaos_marine_race" then
					Util_StartIntel(EVENTS.IE_Chaos_FirstBeacon)
				elseif MetaMap_GetPlayerRaceName() == "eldar_race" then
					Util_StartIntel(EVENTS.IE_Eldar_FirstBeacon)
				elseif MetaMap_GetPlayerRaceName() == "guard_race" then
					Util_StartIntel(EVENTS.IE_IG_FirstBeacon)
				elseif MetaMap_GetPlayerRaceName() == "ork_race" then
					Util_StartIntel(EVENTS.IE_Ork_FirstBeacon)
				elseif MetaMap_GetPlayerRaceName() == "space_marine_race" then
					Util_StartIntel(EVENTS.IE_SM_FirstBeacon)
				elseif MetaMap_GetPlayerRaceName() == "tau_race" then
					Util_StartIntel(EVENTS.IE_Tau_FirstBeacon)
				end
			else
				if MetaMap_GetPlayerRaceName() == "chaos_marine_race" then
					Util_StartIntel(EVENTS.IE_Chaos_AnotherBeacon)
				elseif MetaMap_GetPlayerRaceName() == "eldar_race" then
					Util_StartIntel(EVENTS.IE_Eldar_AnotherBeacon)
				elseif MetaMap_GetPlayerRaceName() == "guard_race" then
					Util_StartIntel(EVENTS.IE_IG_AnotherBeacon)
				elseif MetaMap_GetPlayerRaceName() == "ork_race" then
					Util_StartIntel(EVENTS.IE_Ork_AnotherBeacon)
				elseif MetaMap_GetPlayerRaceName() == "space_marine_race" then
					Util_StartIntel(EVENTS.IE_SM_AnotherBeacon)
				elseif MetaMap_GetPlayerRaceName() == "tau_race" then
					Util_StartIntel(EVENTS.IE_Tau_AnotherBeacon)
				end
			end
		end
	
		g_BeaconEncountered = true
		
		Util_StartIntel(EVENTS.IE_Global_RessurectionBeacon)
		
		Rule_AddOneShot(Rule_CorpseAttack, 6)
		Rule_AddInterval(Rule_Beacon1Pulse, 30)
	end
	Rule_Remove(Rule_TriggerBeacon1)
end

end

function Rule_CorpseAttack() for i = 1, 3 do Anim_PlaySGroupAnim("sg_Corpses"..i, "default") SGroup_SetPlayerOwner( "sg_Corpses"..i, g_Player2) end end

function Rule_Beacon1Pulse() if not EGroup_IsEmpty("eg_Beacon1") then if g_Escape then Cmd_EGroupCastAbilitySelf("eg_Beacon1", "necron_mass_resurrection_beacon2") else Cmd_EGroupCastAbilitySelf("eg_Beacon1", "necron_mass_resurrection_beacon") end Util_MarkerFX("mkr_S_Beacon1", "data:Art/Events/Necron/sp/beacon_pulse") Util_MarkerFX("mkr_S_Beacon1", "data:Art/Events/Necron/necron_resurrect")

else
	Rule_Remove(Rule_Beacon1Pulse)
end

end


function Rule_TriggerBeacon2() -- VEHICLE POSSESSION if Player_AreSquadsNearMarker(g_Player1, "mkr_TriggerBeacon2") or g_Escape then if not EGroup_IsEmpty("eg_Beacon2") then

		Rule_AddInterval(Rule_Objective_Possession, 2)
		FOW_RevealArea(212, -209, 50,  30)

		if not g_Escape then
			if not g_BeaconEncountered then
				if MetaMap_GetPlayerRaceName() == "chaos_marine_race" then
					Util_StartIntel(EVENTS.IE_Chaos_FirstBeacon)
				elseif MetaMap_GetPlayerRaceName() == "eldar_race" then
					Util_StartIntel(EVENTS.IE_Eldar_FirstBeacon)
				elseif MetaMap_GetPlayerRaceName() == "guard_race" then
					Util_StartIntel(EVENTS.IE_IG_FirstBeacon)
				elseif MetaMap_GetPlayerRaceName() == "ork_race" then
					Util_StartIntel(EVENTS.IE_Ork_FirstBeacon)
				elseif MetaMap_GetPlayerRaceName() == "space_marine_race" then
					Util_StartIntel(EVENTS.IE_SM_FirstBeacon)
				elseif MetaMap_GetPlayerRaceName() == "tau_race" then
					Util_StartIntel(EVENTS.IE_Tau_FirstBeacon)
				end
			else
				if MetaMap_GetPlayerRaceName() == "chaos_marine_race" then
					Util_StartIntel(EVENTS.IE_Chaos_AnotherBeacon)
				elseif MetaMap_GetPlayerRaceName() == "eldar_race" then
					Util_StartIntel(EVENTS.IE_Eldar_AnotherBeacon)
				elseif MetaMap_GetPlayerRaceName() == "guard_race" then
					Util_StartIntel(EVENTS.IE_IG_AnotherBeacon)
				elseif MetaMap_GetPlayerRaceName() == "ork_race" then
					Util_StartIntel(EVENTS.IE_Ork_AnotherBeacon)
				elseif MetaMap_GetPlayerRaceName() == "space_marine_race" then
					Util_StartIntel(EVENTS.IE_SM_AnotherBeacon)
				elseif MetaMap_GetPlayerRaceName() == "tau_race" then
					Util_StartIntel(EVENTS.IE_Tau_AnotherBeacon)
				end
			end
		end	
		
		g_BeaconEncountered = true
		
		Util_StartIntel(EVENTS.IE_Global_PossessionBeacon)

		Rule_AddOneShot(Rule_Beacon2FirstShot, 7)
		Rule_AddInterval(Rule_Beacon2Pulse, 63)
	end
	Rule_Remove(Rule_TriggerBeacon2)
end

end

function Rule_Beacon2FirstShot()

if not EGroup_IsEmpty("eg_Beacon2") then

	SGroup_Clear(SGroup_CreateIfNotFound("sg_Player1_Squads"))
	
	SGroup_AddGroup(SGroup_CreateIfNotFound("sg_Player1_Squads"), Player_GetSquads(g_Player1))
	
	local countsquads = SGroup_CountSpawned(SGroup_FromName("sg_Player1_Squads"))
	
	for i = 1, countsquads do
	
		SGroup_Clear(SGroup_CreateIfNotFound("sg_Vehicle"))
		
		SGroup_Add(SGroup_FromName("sg_Vehicle"), SGroup_GetSpawnedSquadAt("sg_Player1_Squads", i))

		if SGroup_ContainsBlueprints(SGroup_FromName("sg_Vehicle"), t_vehicle_types, false) then
			if	Prox_AnySquadNearMarker("sg_Vehicle", "mkr_TriggerBeacon2") or g_Escape then
		
			
				SGroup_SetPlayerOwner("sg_Vehicle", g_Player6)
				Cpu_UnlockSGroupAcrossPlayers("sg_Vehicle")

				Util_MarkerFX("mkr_S_Beacon2", "data:Art/Events/Necron/sp/beacon_pulse")
				World_FXEventSquad("data:Art/Events/Necron/Monolith_phase_out_events", "sg_Vehicle")
				Util_MarkerFX("mkr_S_Beacon2", "data:Art/Events/Necron/necron_possess_vehicle")
				World_FXEventSquad("data:Art/Events/Necron/necron_possess_vehicle", "sg_Vehicle")
				break
			end
		end
	end
end

end

function Rule_Beacon2Pulse()

if not EGroup_IsEmpty("eg_Beacon2") then

	SGroup_Clear("sg_Player1_Squads")
	SGroup_AddGroup(SGroup_CreateIfNotFound("sg_Player1_Squads"), Player_GetSquads(g_Player1))
	
	local countsquads = SGroup_CountSpawned(SGroup_FromName("sg_Player1_Squads"))
	
	if SGroup_IsEmpty("sg_Vehicle") then
		for i = 1, countsquads do
		
			SGroup_Clear("sg_Vehicle")
			
			SGroup_Add(SGroup_FromName("sg_Vehicle"), SGroup_GetSpawnedSquadAt("sg_Player1_Squads", i))

			if SGroup_ContainsBlueprints(SGroup_FromName("sg_Vehicle"), t_vehicle_types, false) then
				if	Prox_AnySquadNearMarker("sg_Vehicle", "mkr_TriggerBeacon2") or g_Escape then
				
				
					SGroup_SetPlayerOwner("sg_Vehicle", g_Player6)
					Cpu_UnlockSGroupAcrossPlayers("sg_Vehicle")

					Util_MarkerFX("mkr_S_Beacon2", "data:Art/Events/Necron/sp/beacon_pulse")
					World_FXEventSquad("data:Art/Events/Necron/Monolith_phase_out_events", "sg_Vehicle")
					Util_MarkerFX("mkr_S_Beacon2", "data:Art/Events/Necron/necron_possess_vehicle")
					World_FXEventSquad("data:Art/Events/Necron/necron_possess_vehicle", "sg_Vehicle")
					break
				end
			end
		end
	end
else
	Rule_Remove(Rule_Beacon2Pulse)
end

end


function Rule_TriggerBeacon3() -- CHRONO TRIGGER if Player_AreSquadsNearMarker(g_Player1, "mkr_TriggerBeacon3") or g_Escape then if not EGroup_IsEmpty("eg_Beacon3") then

		FOW_RevealArea(-14, -134, 40,  20)
		Rule_AddInterval(Rule_Objective_Chronometron, 2)

		if not g_Escape then
			if not g_BeaconEncountered then
				if MetaMap_GetPlayerRaceName() == "chaos_marine_race" then
					Util_StartIntel(EVENTS.IE_Chaos_FirstBeacon)
				elseif MetaMap_GetPlayerRaceName() == "eldar_race" then
					Util_StartIntel(EVENTS.IE_Eldar_FirstBeacon)
				elseif MetaMap_GetPlayerRaceName() == "guard_race" then
					Util_StartIntel(EVENTS.IE_IG_FirstBeacon)
				elseif MetaMap_GetPlayerRaceName() == "ork_race" then
					Util_StartIntel(EVENTS.IE_Ork_FirstBeacon)
				elseif MetaMap_GetPlayerRaceName() == "space_marine_race" then
					Util_StartIntel(EVENTS.IE_SM_FirstBeacon)
				elseif MetaMap_GetPlayerRaceName() == "tau_race" then
					Util_StartIntel(EVENTS.IE_Tau_FirstBeacon)
				end
			else
				if MetaMap_GetPlayerRaceName() == "chaos_marine_race" then
					Util_StartIntel(EVENTS.IE_Chaos_AnotherBeacon)
				elseif MetaMap_GetPlayerRaceName() == "eldar_race" then
					Util_StartIntel(EVENTS.IE_Eldar_AnotherBeacon)
				elseif MetaMap_GetPlayerRaceName() == "guard_race" then
					Util_StartIntel(EVENTS.IE_IG_AnotherBeacon)
				elseif MetaMap_GetPlayerRaceName() == "ork_race" then
					Util_StartIntel(EVENTS.IE_Ork_AnotherBeacon)
				elseif MetaMap_GetPlayerRaceName() == "space_marine_race" then
					Util_StartIntel(EVENTS.IE_SM_AnotherBeacon)
				elseif MetaMap_GetPlayerRaceName() == "tau_race" then
					Util_StartIntel(EVENTS.IE_Tau_AnotherBeacon)
				end
			end
		end	
		
		g_BeaconEncountered = true
		
		Util_StartIntel(EVENTS.IE_Global_ChronometronBeacon)

		Rule_AddOneShot(Rule_Beacon3FirstShot, 10)
		Rule_AddInterval(Rule_Beacon3Pulse, 40)
	end
	Rule_Remove(Rule_TriggerBeacon3)
end

end

function Rule_Beacon3FirstShot()

if not EGroup_IsEmpty("eg_Beacon3") then

	SGroup_Clear(SGroup_CreateIfNotFound("sg_Player1_Squads"))
	SGroup_AddGroup(SGroup_CreateIfNotFound("sg_Player1_Squads"), Player_GetSquads(g_Player1))
	
	local countsquads = SGroup_CountSpawned(SGroup_FromName("sg_Player1_Squads"))
	
	for i = 1, countsquads do
	
		SGroup_Clear(SGroup_CreateIfNotFound("sg_Chrono"))
		
		SGroup_Add(SGroup_FromName("sg_Chrono"), SGroup_GetSpawnedSquadAt("sg_Player1_Squads", i))

		if ((Prox_AnySquadNearMarker("sg_Chrono", "mkr_TriggerBeacon3") or g_Escape) and (not (SGroup_ContainsBlueprints( "sg_Chrono", t_no_chrono, false )))) then
		
			
			SGroup_SetPlayerOwner("sg_Chrono", g_Player7)
			Cpu_LockSGroupAcrossPlayers("sg_Chrono")
			Cmd_SetStance("sg_Chrono", STANCE_CeaseFire)
			Rule_AddOneShot(Rule_Beacon3Release, 20)
			
			Util_MarkerFX("mkr_S_Beacon3", "data:Art/Events/Necron/sp/beacon_pulse")
			World_FXEventSquad("data:Art/Events/Unit_Upgrade_Morale_FX/Reinforce_Necron_Trooper", "sg_Chrono")
			Util_MarkerFX("mkr_S_Beacon3", "data:Art/Events/Necron/necron_chronometron")
			World_FXEventSquad("data:Art/Events/Necron/necron_chronometron", "sg_Chrono")
			break
			
		end
	end
end

end

function Rule_Beacon3Pulse() if not EGroup_IsEmpty("eg_Beacon3") then

	SGroup_Clear("sg_Player1_Squads")
	SGroup_AddGroup(SGroup_CreateIfNotFound("sg_Player1_Squads"), Player_GetSquads(g_Player1))
	
	local countsquads = SGroup_CountSpawned(SGroup_FromName("sg_Player1_Squads"))
	
	for i = 1, countsquads do
	
		SGroup_Clear(SGroup_CreateIfNotFound("sg_Chrono"))
		
		SGroup_Add(SGroup_FromName("sg_Chrono"), SGroup_GetSpawnedSquadAt("sg_Player1_Squads", i))

		if ((Prox_AnySquadNearMarker("sg_Chrono", "mkr_TriggerBeacon3") or g_Escape) and (not (SGroup_ContainsBlueprints( "sg_Chrono", t_no_chrono, false )))) then
		
			SGroup_SetPlayerOwner("sg_Chrono", g_Player7)
			Cpu_LockSGroupAcrossPlayers("sg_Chrono")
			Cmd_SetStance("sg_Chrono", STANCE_CeaseFire)
			Rule_AddOneShot(Rule_Beacon3Release, 20)
			
			Util_MarkerFX("mkr_S_Beacon3", "data:Art/Events/Necron/sp/beacon_pulse")
			World_FXEventSquad("data:Art/Events/Unit_Upgrade_Morale_FX/Reinforce_Necron_Trooper", "sg_Chrono")
			Util_MarkerFX("mkr_S_Beacon3", "data:Art/Events/Necron/necron_chronometron")
			World_FXEventSquad("data:Art/Events/Necron/necron_chronometron", "sg_Chrono")
			break
			
		end
	end
else
	Rule_Remove(Rule_Beacon3Pulse)
end

end

function Rule_Beacon3Release() World_FXEventSquad("data:Art/Events/Unit_Upgrade_Morale_FX/Reinforce_Trooper", "sg_Chrono") Cmd_SetStance("sg_Chrono", STANCE_Hold) Cpu_UnlockSGroupAcrossPlayers("sg_Chrono") SGroup_SetPlayerOwner("sg_Chrono", g_Player1) end


function Rule_TriggerBeacon4() -- CLOAKING BEACON if Player_AreSquadsNearMarker(g_Player1, "mkr_TriggerBeacon4") or g_Escape then if not EGroup_IsEmpty("eg_Beacon4") then Rule_AddOneShot(Rule_Beacon4Pulse, 10) else for i = 1, 3 do Cmd_SetStance("sg_Cloakers"..i, STANCE_StandGround) end

		EGroup_DestroyAllEntities("eg_Necron_Cloaker")
		EGroup_Destroy(EGroup_FromName("eg_Necron_Cloaker"))
	end

	FOW_RevealArea(-173, 145, 40,  20)
	Rule_AddInterval(Rule_Objective_Darkness, 2)

		if not g_Escape then
			if not g_BeaconEncountered then
				if MetaMap_GetPlayerRaceName() == "chaos_marine_race" then
					Util_StartIntel(EVENTS.IE_Chaos_FirstBeacon)
				elseif MetaMap_GetPlayerRaceName() == "eldar_race" then
					Util_StartIntel(EVENTS.IE_Eldar_FirstBeacon)
				elseif MetaMap_GetPlayerRaceName() == "guard_race" then
					Util_StartIntel(EVENTS.IE_IG_FirstBeacon)
				elseif MetaMap_GetPlayerRaceName() == "ork_race" then
					Util_StartIntel(EVENTS.IE_Ork_FirstBeacon)
				elseif MetaMap_GetPlayerRaceName() == "space_marine_race" then
					Util_StartIntel(EVENTS.IE_SM_FirstBeacon)
				elseif MetaMap_GetPlayerRaceName() == "tau_race" then
					Util_StartIntel(EVENTS.IE_Tau_FirstBeacon)
				end
			else
				if MetaMap_GetPlayerRaceName() == "chaos_marine_race" then
					Util_StartIntel(EVENTS.IE_Chaos_AnotherBeacon)
				elseif MetaMap_GetPlayerRaceName() == "eldar_race" then
					Util_StartIntel(EVENTS.IE_Eldar_AnotherBeacon)
				elseif MetaMap_GetPlayerRaceName() == "guard_race" then
					Util_StartIntel(EVENTS.IE_IG_AnotherBeacon)
				elseif MetaMap_GetPlayerRaceName() == "ork_race" then
					Util_StartIntel(EVENTS.IE_Ork_AnotherBeacon)
				elseif MetaMap_GetPlayerRaceName() == "space_marine_race" then
					Util_StartIntel(EVENTS.IE_SM_AnotherBeacon)
				elseif MetaMap_GetPlayerRaceName() == "tau_race" then
					Util_StartIntel(EVENTS.IE_Tau_AnotherBeacon)
				end
			end
		end
		
	g_BeaconEncountered = true
		
	Util_StartIntel(EVENTS.IE_Global_DarknessBeacon)

	Rule_Remove(Rule_TriggerBeacon4)
end

end

function Rule_Beacon4Pulse() if not EGroup_IsEmpty("eg_Beacon4") then if g_Escape then --UNCOMMENT THIS Player_GrantResearch(g_Player2, "necron_beacon_research2") --Player_GrantResearch(g_Player2, "necron_beacon_research") g_Researched = true else Player_GrantResearch(g_Player2, "necron_beacon_research") end Util_MarkerFX("mkr_S_Beacon4", "data:Art/Events/Necron/sp/beacon_pulse") Util_MarkerFX("mkr_S_Beacon4", "data:Art/Events/Necron/necron_cloak_of_darkness")

	Rule_AddInterval(Rule_Beacon4FX, 10)
else
		EGroup_DestroyAllEntities("eg_Necron_Cloaker")
		EGroup_Destroy(EGroup_FromName("eg_Necron_Cloaker"))
end

for i = 1, 3 do
	Cmd_SetStance("sg_Cloakers"..i, STANCE_StandGround)
end

end

function Rule_Beacon4FX() if not EGroup_IsEmpty("eg_Beacon4") then Util_MarkerFX("mkr_S_Beacon4", "data:Art/Events/Necron/sp/beacon_pulse") Util_MarkerFX("mkr_S_Beacon4", "data:Art/Events/Necron/necron_cloak_of_darkness")

	if g_Escape and (not g_Researched) then
		--UNCOMMENT THIS
		Player_GrantResearch(g_Player2, "necron_beacon_research2")
		--Player_GrantResearch(g_Player2, "necron_beacon_research")
		g_Researched = true
	end
	
else
		EGroup_DestroyAllEntities("eg_Necron_Cloaker")
		EGroup_Destroy(EGroup_FromName("eg_Necron_Cloaker"))
	Rule_Remove(Rule_Beacon4FX)
end

end


function Rule_UpgradeMonoliths() for i = 1, 4 do EGroup_ForceAddOn("eg_Monolith"..i, "addon_necron_hq_2") end

for i = 9, 9 do
	EGroup_ForceAddOn("eg_Monolith"..i, "addon_necron_hq_2")
end

Rule_AddIntervalDelay(Rule_SpawnMonolithGraveyard, 60, 2)

end

function Rule_SpawnMonolithGraveyard() -- If any 'liths are left after the escape in the graveyard, make them active after 30 seconds. if g_Escape then --for i = 1, 4 do -- if not EGroup_IsEmpty("eg_Monolith"..i) then -- Cmd_BuildSquad("eg_Monolith"..i, "necron_restored_monolith_squad") g_MonolithFailed = true -- end --end

	Rule_AddOneShot(Rule_TeleportMonoliths, 75)
	
	Rule_Remove(Rule_SpawnMonolithGraveyard)
end

end

function Rule_TeleportMonoliths() --SGroup_AddGroup(SGroup_CreateIfNotFound("sg_Player3_Squads"), Player_GetSquads(g_Player3)) --SGroup_AddGroup(SGroup_CreateIfNotFound("sg_Player4_Squads"), Player_GetSquads(g_Player4)) --SGroup_AddGroup(SGroup_CreateIfNotFound("sg_Player5_Squads"), Player_GetSquads(g_Player5)) --SGroup_AddGroup(SGroup_CreateIfNotFound("sg_Player6_Squads"), Player_GetSquads(g_Player6))

for i = 1, 4 do
	SGroup_CreateIfNotFound("sg_TeleportMonolith"..i)
	if not EGroup_IsEmpty("eg_Monolith"..i) then
		EGroup_DestroyAllEntities("eg_Monolith"..i)
		EGroup_Destroy(EGroup_FromName("eg_Monolith"..i))
		
		Util_CreateSquadsAtMarkerEx(g_Player3, "sg_TeleportMonolith"..i, "necron_restored_monolith_squad", "mkr_S_Monolith"..i, 1, 1)
		
		Util_MarkerFX("mkr_S_Monolith"..i, "data:Art/Events/Necron/Monolith_phase_out_events")
	end
end

--SGroup_CreateIfNotFound("sg_TeleportMonolith1")
--SGroup_CreateIfNotFound("sg_TeleportMonolith2")
--SGroup_CreateIfNotFound("sg_TeleportMonolith3")
--SGroup_CreateIfNotFound("sg_TeleportMonolith4")

--Util_GetSquadsByBP("sg_Player3_Squads", "sg_TeleportMonolith1", "necron_restored_monolith_squad")
--Util_GetSquadsByBP("sg_Player4_Squads", "sg_TeleportMonolith2", "necron_restored_monolith_squad")
--Util_GetSquadsByBP("sg_Player5_Squads", "sg_TeleportMonolith3", "necron_restored_monolith_squad")
--Util_GetSquadsByBP("sg_Player6_Squads", "sg_TeleportMonolith4", "necron_restored_monolith_squad")

for i = 1, 4 do
	if not SGroup_IsEmpty("sg_TeleportMonolith"..i) then
		Cmd_JumpToMarker("sg_TeleportMonolith"..i, "mkr_MonolithTarget"..i)
	end
end

Rule_AddOneShot(Rule_TeleportMonoliths2, 40)

end

function Rule_TeleportMonoliths2()

for i = 1, 4 do
	if not SGroup_IsEmpty("sg_TeleportMonolith"..i) then
		Cmd_JumpToMarker("sg_TeleportMonolith"..i, "mkr_MonolithTarget"..(i + 4))
	end
end
Rule_AddOneShot(Rule_TeleportMonoliths3, 10)

end

function Rule_TeleportMonoliths3()

for i = 1, 4 do
	if not SGroup_IsEmpty("sg_TeleportMonolith"..i) then
		Cmd_AttackMoveMarker("sg_TeleportMonolith"..i, "mkr_MonolithTarget"..(i + 8))
	end
end

end

--Patrolling Guards t_Guards = { sgroup_name = { --[[1]]"sg_Guards1", --[[2]]"sg_Guards2", --[[3]]"sg_Guards3", --[[4]]"sg_Guards4", --[[5]]"sg_Guards5", --[[6]]"sg_Guards6", --[[7]]"sg_Guards7", --[[8]]"sg_Guards8", --[[9]]"sg_Guards9", --[[10]]"sg_Guards10", --[[11]]"sg_Guards11", --[[12]]"sg_Guards12",
--[[13]]"sg_Guards13", --[[14]]"sg_Guards14", --[[15]]"sg_Guards15", --[[16]]"sg_Guards16"},

blueprint = { --[[1]]"necron_basic_warrior_squad", --[[2]]"necron_basic_warrior_squad", --[[3]]"necron_basic_warrior_squad", --[[4]]"necron_basic_warrior_squad",
							--[[5]]"necron_basic_warrior_squad", --[[6]]"necron_basic_warrior_squad", --[[7]]"necron_basic_warrior_squad", --[[8]]"necron_basic_warrior_squad",
							--[[9]]"necron_basic_warrior_squad", --[[10]]"necron_basic_warrior_squad", --[[11]]"necron_basic_warrior_squad", --[[12]]"necron_basic_warrior_squad",  
							--[[13]]"necron_immortal_squad", --[[14]]"necron_immortal_squad", --[[15]]"necron_heavy_destroyer_squad", --[[16]]"necron_heavy_destroyer_squad"},  

marker_spawn = { --[[1]]"mkr_S_Guards1", --[[2]]"mkr_S_Guards2", --[[3]]"mkr_S_Guards3", --[[4]]"mkr_S_Guards4",
							--[[5]]"mkr_S_Guards5", --[[6]]"mkr_S_Guards6", --[[7]]"mkr_S_Guards7", --[[8]]"mkr_S_Guards8",
							--[[9]]"mkr_S_Guards9", --[[10]]"mkr_S_Guards10", --[[11]]"mkr_S_Guards11", --[[12]]"mkr_S_Guards12",  
							--[[13]]"mkr_S_Guards9", --[[14]]"mkr_S_Guards10", --[[15]]"mkr_S_Guards11", --[[16]]"mkr_S_Guards12"},  

marker_destination = { --[[1]]"mkr_D_Guards1", --[[2]]"mkr_D_Guards2", --[[3]]"mkr_D_Guards3", --[[4]]"mkr_D_Guards4",
							--[[5]]"mkr_D_Guards5", --[[6]]"mkr_D_Guards6", --[[7]]"mkr_D_Guards7", --[[8]]"mkr_D_Guards8",
							--[[9]]"mkr_D_Guards9", --[[10]]"mkr_D_Guards10", --[[11]]"mkr_D_Guards11", --[[12]]"mkr_D_Guards12",  
							--[[13]]"mkr_D_Guards9", --[[14]]"mkr_D_Guards10", --[[15]]"mkr_D_Guards11", --[[16]]"mkr_D_Guards12"},  

boolean_destination = { --[[1]] true, --[[2]] true, --[[3]] true, --[[4]] true,
							--[[5]] true, --[[6]] true, --[[7]] true, --[[8]] true,
							--[[9]] true, --[[10]] true, --[[11]] true, --[[12]] true,
							--[[13]] true, --[[14]] true, --[[15]] true, --[[16]] true},

squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1,
							--[[5]] 1, --[[6]] 1, --[[7]] 1, --[[8]] 1,
							--[[9]] 1, --[[10]] 1, --[[11]] 1, --[[12]] 1, 
							--[[13]] 1, --[[14]] 1, --[[15]] 1, --[[16]] 1}, 

squad_size = {--[[1]] 6, --[[2]] 6, --[[3]] 6, --[[4]] 6,
							--[[5]] 8, --[[6]] 8, --[[7]] 8, --[[8]] 8,
							--[[9]] 8, --[[10]] 8, --[[11]] 8, --[[12]] 8,
							--[[13]] 6, --[[14]] 6, --[[15]] 1, --[[16]] 1},

move_delay = {--[[1]] 10, --[[2]] 15, --[[3]] 20, --[[4]] 14,
							--[[5]] 15, --[[6]] 15, --[[7]] 20, --[[8]] 9,
							--[[9]] 16, --[[10]] 14, --[[11]] 21, --[[12]] 13,
							--[[13]] 16, --[[14]] 14, --[[15]] 21, --[[16]] 13},

}

function Rule_CreateGuards()

for i = 1, table.getn(t_Guards.sgroup_name) do
	Util_CreateSquadsAtMarkerEx(g_Player3, t_Guards.sgroup_name[i], t_Guards.blueprint[i], t_Guards.marker_spawn[i], t_Guards.squad_num[i], t_Guards.squad_size[i])
	if i < 5 then
		Util_CreateSquadsAtMarkerEx(g_Player3, t_Guards.sgroup_name[i], "necron_wraith_squad", t_Guards.marker_spawn[i], 1, 1)
	else 
		if i < 13 then
			Util_CreateSquadsAtMarkerEx(g_Player3, t_Guards.sgroup_name[i], "necron_wraith_squad", t_Guards.marker_spawn[i], 2, 1)
		else
			Util_CreateSquadsAtMarkerEx(g_Player3, t_Guards.sgroup_name[i], "necron_wraith_squad", t_Guards.marker_spawn[i], 3, 1)
		end
	end
		
	Cpu_LockSGroupAcrossPlayers(t_Guards.sgroup_name[i])
	SGroup_AddLeaders(t_Guards.sgroup_name[i])
	Cmd_AttackMoveMarker( t_Guards.sgroup_name[i], t_Guards.marker_destination[i])
end

Rule_AddInterval(Rule_GuardPatrols, 10)

end

--All guards bounce back and forth between their spawn and destination. function Rule_GuardPatrols() for i = 1, table.getn(t_Guards.sgroup_name) do if not SGroup_IsEmpty( t_Guards.sgroup_name[i] ) then if t_Guards.boolean_destination[i] then if Prox_AllSquadsNearMarker( t_Guards.sgroup_name[i], t_Guards.marker_destination[i]) then Cmd_AttackMoveMarker( t_Guards.sgroup_name[i], t_Guards.marker_spawn[i]) t_Guards.boolean_destination[i] = false end else if Prox_AllSquadsNearMarker(t_Guards.sgroup_name[i], t_Guards.marker_spawn[i]) then Cmd_AttackMoveMarker( t_Guards.sgroup_name[i], t_Guards.marker_destination[i]) t_Guards.boolean_destination[i] = true end end end end end

--Assassins regularly spawn from monoliths and hunt down the player's commander. function Rule_MonolithAssassins() for i = 7, 9 do if (not EGroup_IsEmpty("eg_Monolith"..i)) and (SGroup_IsEmpty("sg_MonolithAssassins")) then if g_Timer2 then Util_CreateSquadsAtMarkerEx(g_Player2, "sg_MonolithAssassins", "necron_destroyer_squad", "mkr_S_Spawn"..i, 1, 1) else if g_Timer1 then Util_CreateSquadsAtMarkerEx(g_Player2, "sg_MonolithAssassins", "necron_pariah_squad", "mkr_S_Spawn"..i, 1, g_MediumSquadSize) else Util_CreateSquadsAtMarkerEx(g_Player2, "sg_MonolithAssassins", "necron_flayed_one_squad", "mkr_S_Spawn"..i, 1, g_MediumSquadSize) end end end end

for i = 5, 6 do
	if (not SGroup_IsEmpty("sg_Monolith"..i)) and (SGroup_IsEmpty("sg_MonolithAssassins")) then
		if g_Timer2 then
			Util_CreateSquadsAtMarkerEx(g_Player2, "sg_MonolithAssassins", "necron_heavy_destroyer_squad", "mkr_S_Spawn"..i, 1, 1)
		else
			if g_Timer1 then
				Util_CreateSquadsAtMarkerEx(g_Player2, "sg_MonolithAssassins", "necron_destroyer_squad", "mkr_S_Spawn"..i, 1, 1)
			else
				Util_CreateSquadsAtMarkerEx(g_Player2, "sg_MonolithAssassins", "necron_pariah_squad", "mkr_S_Spawn"..i, 1, g_SmallSquadSize)
			end
		end
	end
end

Cpu_LockSGroupAcrossPlayers("sg_MonolithAssassins")

EGroup_AddGroup(EGroup_CreateIfNotFound("eg_Player1_Buildings"), Player_GetEntities(g_Player1))

if SGroup_IsInHold("sg_Leader", "eg_Player1_Buildings", false) then
	Cmd_AttackMoveMarker("sg_MonolithAssassins", "mkr_Player_HQ")
else
	Cmd_AttackSGroup("sg_MonolithAssassins", "sg_Leader")
end

end

--Assassins regularly spawn from tunnels and hunt down the player's commander. function Rule_TunnelAssassins() if SGroup_IsEmpty("sg_TunnelAssassins") then Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelAssassins", "necron_wraith_squad", "mkr_S_Tunnel"..(World_GetRand(1,13)), 1, 1) Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelAssassins", "necron_flayed_one_squad", "mkr_S_Tunnel"..(World_GetRand(1,13)), 1, g_MediumSquadSize) if g_Timer1 then Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelAssassins", "necron_pariah_squad", "mkr_S_Tunnel"..(World_GetRand(1,13)), 1, g_MediumSquadSize) end if g_Timer2 then Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelAssassins", "necron_destroyer_squad", "mkr_S_Tunnel"..(World_GetRand(1,13)), 2, 1) end end

Cpu_LockSGroupAcrossPlayers("sg_TunnelAssassins")

EGroup_AddGroup(EGroup_CreateIfNotFound("eg_Player1_Buildings"), Player_GetEntities(g_Player1))

if SGroup_IsInHold("sg_Leader", "eg_Player1_Buildings", false) then
	Cmd_AttackMoveMarker("sg_TunnelAssassins", "mkr_Player_HQ")
else
	Cmd_AttackSGroup("sg_TunnelAssassins", "sg_Leader")
end

end

--Saboteurs regularly spawn from monoliths and attack the player's base. function Rule_MonolithSaboteurs() for i = 7, 9 do if (not EGroup_IsEmpty("eg_Monolith"..i)) and (SGroup_IsEmpty("sg_MonolithSaboteurs")) then if g_Timer2 then Util_CreateSquadsAtMarkerEx(g_Player2, "sg_MonolithSaboteurs", "necron_immortal_squad", "mkr_S_Spawn"..i, 1, g_MediumSquadSize) else if g_Timer1 then Util_CreateSquadsAtMarkerEx(g_Player2, "sg_MonolithSaboteurs", "necron_scarab_squad", "mkr_S_Spawn"..i, 1, g_LargeSquadSize) else Util_CreateSquadsAtMarkerEx(g_Player2, "sg_MonolithSaboteurs", "necron_wraith_squad", "mkr_S_Spawn"..i, 2, 1) end end end end

for i = 5, 6 do
	if (not SGroup_IsEmpty("sg_Monolith"..i)) and (SGroup_IsEmpty("sg_MonolithSaboteurs")) then
		if g_Timer2 then
			Util_CreateSquadsAtMarkerEx(g_Player2, "sg_MonolithSaboteurs", "necron_heavy_destroyer_squad", "mkr_S_Spawn"..i, 1, 1)
		else
			if g_Timer1 then
				Util_CreateSquadsAtMarkerEx(g_Player2, "sg_MonolithSaboteurs", "necron_destroyer_squad", "mkr_S_Spawn"..i, 1, 1)
			else
				Util_CreateSquadsAtMarkerEx(g_Player2, "sg_MonolithSaboteurs", "necron_destroyer_squad", "mkr_S_Spawn"..i, 1, 1)
			end
		end
	end
end

Cpu_LockSGroupAcrossPlayers("sg_MonolithSaboteurs")
Cmd_AttackMoveMarker("sg_MonolithSaboteurs", "mkr_Player_HQ")

end

--Saboteurs regularly spawn from tunnels and attack the player's base. function Rule_TunnelSaboteurs() if SGroup_IsEmpty("sg_TunnelSaboteurs") then Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSaboteurs", "necron_wraith_squad", "mkr_S_Tunnel"..(World_GetRand(1,13)), 1, 1) Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSaboteurs", "necron_scarab_squad", "mkr_S_Tunnel"..(World_GetRand(1,13)), 1, g_MediumSquadSize) if g_Timer1 then Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSaboteurs", "necron_scarab_squad", "mkr_S_Tunnel"..(World_GetRand(1,13)), 1, g_LargeSquadSize) end if g_Timer2 then Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSaboteurs", "necron_immortal_squad", "mkr_S_Tunnel"..(World_GetRand(1,13)), 1, g_MediumSquadSize) end end

Cpu_LockSGroupAcrossPlayers("sg_TunnelSaboteurs")
Cmd_AttackMoveMarker("sg_TunnelSaboteurs", "mkr_Player_HQ")

end

--Killers spawn from tunnels regularly in addition to all the above as soon as the bomb is placed function Rule_TunnelKillers() if SGroup_IsEmpty("sg_TunnelKillers") then Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelKillers", "necron_wraith_squad", "mkr_S_Tunnel"..(World_GetRand(1,14)), g_SmallSquadSize, 1) Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelKillers", "necron_destroyer_squad", "mkr_S_Tunnel"..(World_GetRand(1,14)), 2, 1) end

Cpu_LockSGroupAcrossPlayers("sg_TunnelKillers")

EGroup_AddGroup(EGroup_CreateIfNotFound("eg_Player1_Buildings"), Player_GetEntities(g_Player1))

if SGroup_IsInHold("sg_Leader", "eg_Player1_Buildings", false) then
	Cmd_AttackMoveMarker("sg_TunnelKillers", "mkr_Player_HQ")
else
	Cmd_AttackSGroup("sg_TunnelKillers", "sg_Leader")
end

end

-- As soon as a player unit steps into one of these triggers, enemies swarm from the tunnels nearby. function Rule_TunnelTrigger1() if Player_AreSquadsNearMarker(g_Player1, "mkr_TunnelTrigger1") then Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm1", "necron_basic_warrior_squad", "mkr_S_Tunnel1", 1, g_SmallSquadSize) Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm1", "necron_basic_warrior_squad", "mkr_S_Tunnel2", 1, g_SmallSquadSize)

	Cpu_LockSGroupAcrossPlayers("sg_TunnelSwarm1")
	Cmd_AttackMoveMarker("sg_TunnelSwarm1", "mkr_S_Beacon2")

	Rule_AddOneShot(Rule_Tunnel1_Wave1, 12)
	Rule_AddOneShot(Rule_Tunnel1_Wave2, 24)
	
	Rule_Remove(Rule_TunnelTrigger1)
end

end

function Rule_Tunnel1_Wave1() Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm1", "necron_basic_warrior_squad", "mkr_S_Tunnel1", 1, g_SmallSquadSize) Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm1", "necron_scarab_squad", "mkr_S_Tunnel2", 1, g_MediumSquadSize)

Cpu_LockSGroupAcrossPlayers("sg_TunnelSwarm1")
Cmd_AttackMoveMarker("sg_TunnelSwarm1", "mkr_S_Beacon2")

end

function Rule_Tunnel1_Wave2() Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm1", "necron_flayed_one_squad", "mkr_S_Tunnel1", 1, g_SmallSquadSize) Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm1", "necron_basic_warrior_squad", "mkr_S_Tunnel2", 1, g_SmallSquadSize)

Cpu_LockSGroupAcrossPlayers("sg_TunnelSwarm1")
Cmd_AttackMoveMarker("sg_TunnelSwarm1", "mkr_S_Beacon2")

end

function Rule_TunnelTrigger2() if Player_AreSquadsNearMarker(g_Player1, "mkr_TunnelTrigger2") then Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm2", "necron_scarab_squad", "mkr_S_Tunnel3", 1, g_SmallSquadSize) Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm2", "necron_scarab_squad", "mkr_S_Tunnel4", 1, g_SmallSquadSize)

	Cpu_LockSGroupAcrossPlayers("sg_TunnelSwarm2")
	Cmd_AttackMoveMarker("sg_TunnelSwarm2", "mkr_TunnelTrigger2")

	Rule_AddOneShot(Rule_Tunnel2_Wave1, 10)
	Rule_AddOneShot(Rule_Tunnel2_Wave2, 20)
	

	Rule_Remove(Rule_TunnelTrigger2)
end

end

function Rule_Tunnel2_Wave1() Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm2", "necron_scarab_squad", "mkr_S_Tunnel3", 1, g_MediumSquadSize) Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm2", "necron_scarab_squad", "mkr_S_Tunnel4", 1, g_MediumSquadSize)

Cpu_LockSGroupAcrossPlayers("sg_TunnelSwarm2")
Cmd_AttackMoveMarker("sg_TunnelSwarm2", "mkr_TunnelTrigger2")

end

function Rule_Tunnel2_Wave2() Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm2", "necron_scarab_squad", "mkr_S_Tunnel3", 1, g_MediumSquadSize) Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm2", "necron_scarab_squad", "mkr_S_Tunnel4", 1, g_MediumSquadSize)

Cpu_LockSGroupAcrossPlayers("sg_TunnelSwarm2")
Cmd_AttackMoveMarker("sg_TunnelSwarm2", "mkr_TunnelTrigger2")

end

function Rule_TunnelTrigger3() if Player_AreSquadsNearMarker(g_Player1, "mkr_TunnelTrigger3") then Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm3", "necron_basic_warrior_squad", "mkr_S_Tunnel5", 1, g_SmallSquadSize) Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm3", "necron_basic_warrior_squad", "mkr_S_Tunnel6", 1, g_SmallSquadSize)

	Cpu_LockSGroupAcrossPlayers("sg_TunnelSwarm3")
	Cmd_AttackMoveMarker("sg_TunnelSwarm3", "mkr_TunnelTrigger3")

	Rule_AddOneShot(Rule_Tunnel3_Wave1, 10)
	Rule_AddOneShot(Rule_Tunnel3_Wave2, 20)

	Rule_Remove(Rule_TunnelTrigger3)
end

end

function Rule_Tunnel3_Wave1() Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm3", "necron_basic_warrior_squad", "mkr_S_Tunnel5", 1, g_MediumSquadSize) Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm3", "necron_basic_warrior_squad", "mkr_S_Tunnel6", 1, g_MediumSquadSize)

Cpu_LockSGroupAcrossPlayers("sg_TunnelSwarm3")
Cmd_AttackMoveMarker("sg_TunnelSwarm3", "mkr_TunnelTrigger3")

end

function Rule_Tunnel3_Wave2() Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm3", "necron_basic_warrior_squad", "mkr_S_Tunnel5", 1, g_MediumSquadSize) Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm3", "necron_tomb_spyder_squad", "mkr_S_Tunnel6", 1, 1)

Cpu_LockSGroupAcrossPlayers("sg_TunnelSwarm3")
Cmd_AttackMoveMarker("sg_TunnelSwarm3", "mkr_TunnelTrigger3")

end

function Rule_TunnelTrigger4() if Player_AreSquadsNearMarker(g_Player1, "mkr_TunnelTrigger4") then Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm4", "necron_wraith_squad", "mkr_S_Tunnel7", 1, 1) Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm4", "necron_wraith_squad", "mkr_S_Tunnel8", 1, 1)

	Cpu_LockSGroupAcrossPlayers("sg_TunnelSwarm4")
	Cmd_AttackMoveMarker("sg_TunnelSwarm4", "mkr_TunnelTrigger4")

	Rule_AddOneShot(Rule_Tunnel4_Wave1, 8)
	Rule_AddOneShot(Rule_Tunnel4_Wave2, 16)

	Rule_Remove(Rule_TunnelTrigger4)
end

end

function Rule_Tunnel4_Wave1() Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm4", "necron_wraith_squad", "mkr_S_Tunnel7", 1, 1) Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm4", "necron_wraith_squad", "mkr_S_Tunnel8", 1, 1)

Cpu_LockSGroupAcrossPlayers("sg_TunnelSwarm4")
Cmd_AttackMoveMarker("sg_TunnelSwarm4", "mkr_TunnelTrigger4")

end

function Rule_Tunnel4_Wave2() Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm4", "necron_wraith_squad", "mkr_S_Tunnel7", 1, 1) Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm4", "necron_wraith_squad", "mkr_S_Tunnel8", 1, 1)

Cpu_LockSGroupAcrossPlayers("sg_TunnelSwarm4")
Cmd_AttackMoveMarker("sg_TunnelSwarm4", "mkr_TunnelTrigger4")

end

function Rule_TunnelTrigger5() if Player_AreSquadsNearMarker(g_Player1, "mkr_TunnelTrigger5") then Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm5", "necron_flayed_one_squad", "mkr_S_Tunnel9", 1, g_SmallSquadSize)

	Cpu_LockSGroupAcrossPlayers("sg_TunnelSwarm5")
	Cmd_AttackMoveMarker("sg_TunnelSwarm5", "mkr_TunnelTrigger5")

	Rule_AddOneShot(Rule_Tunnel5_Wave1, 10)
	Rule_AddOneShot(Rule_Tunnel5_Wave2, 20)

	Rule_Remove(Rule_TunnelTrigger5)
end

end

function Rule_Tunnel5_Wave1() Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm5", "necron_flayed_one_squad", "mkr_S_Tunnel9", 1, g_SmallSquadSize)

Cpu_LockSGroupAcrossPlayers("sg_TunnelSwarm5")
Cmd_AttackMoveMarker("sg_TunnelSwarm5", "mkr_TunnelTrigger5")

end

function Rule_Tunnel5_Wave2() Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm5", "necron_flayed_one_squad", "mkr_S_Tunnel9", 1, g_SmallSquadSize)

Cpu_LockSGroupAcrossPlayers("sg_TunnelSwarm5")
Cmd_AttackMoveMarker("sg_TunnelSwarm5", "mkr_TunnelTrigger5")

end

function Rule_TunnelTrigger6() if Player_AreSquadsNearMarker(g_Player1, "mkr_TunnelTrigger6") then Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm6", "necron_destroyer_squad", "mkr_S_Tunnel10", 1, 1)

	Cpu_LockSGroupAcrossPlayers("sg_TunnelSwarm6")
	Cmd_AttackMoveMarker("sg_TunnelSwarm6", "mkr_TunnelTrigger6")

	Rule_AddOneShot(Rule_Tunnel6_Wave1, 10)
	Rule_AddOneShot(Rule_Tunnel6_Wave2, 20)

	Rule_Remove(Rule_TunnelTrigger6)
end

end

function Rule_Tunnel6_Wave1() Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm6", "necron_destroyer_squad", "mkr_S_Tunnel10", 1, 1)

Cpu_LockSGroupAcrossPlayers("sg_TunnelSwarm6")
Cmd_AttackMoveMarker("sg_TunnelSwarm6", "mkr_TunnelTrigger6")

end

function Rule_Tunnel6_Wave2() Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm6", "necron_destroyer_squad", "mkr_S_Tunnel10", 2, 1)

Cpu_LockSGroupAcrossPlayers("sg_TunnelSwarm6")
Cmd_AttackMoveMarker("sg_TunnelSwarm6", "mkr_TunnelTrigger6")

end

function Rule_TunnelTrigger7() if Player_AreSquadsNearMarker(g_Player1, "mkr_TunnelTrigger7") then Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm7", "necron_basic_warrior_squad", "mkr_S_Tunnel13", 1, g_MediumSquadSize)

	Cpu_LockSGroupAcrossPlayers("sg_TunnelSwarm7")
	Cmd_AttackMoveMarker("sg_TunnelSwarm7", "mkr_TunnelTrigger7")

	Rule_AddOneShot(Rule_Tunnel7_Wave1, 10)
	Rule_AddOneShot(Rule_Tunnel7_Wave2, 20)

	Rule_Remove(Rule_TunnelTrigger7)
end

end

function Rule_Tunnel7_Wave1() Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm7", "necron_basic_warrior_squad", "mkr_S_Tunnel13", 1, g_MediumSquadSize)

Cpu_LockSGroupAcrossPlayers("sg_TunnelSwarm7")
Cmd_AttackMoveMarker("sg_TunnelSwarm7", "mkr_TunnelTrigger7")

end

function Rule_Tunnel7_Wave2() Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm7", "necron_basic_warrior_squad", "mkr_S_Tunnel13", 1, g_MediumSquadSize)

Cpu_LockSGroupAcrossPlayers("sg_TunnelSwarm7")
Cmd_AttackMoveMarker("sg_TunnelSwarm7", "mkr_TunnelTrigger7")

end

function Rule_TunnelTrigger8() if Player_AreSquadsNearMarker(g_Player1, "mkr_TunnelTrigger8") then Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm8", "necron_destroyer_squad", "mkr_S_Tunnel11", 1, 1)

	Cpu_LockSGroupAcrossPlayers("sg_TunnelSwarm8")
	Cmd_AttackMoveMarker("sg_TunnelSwarm8", "mkr_TunnelTrigger8")

	Rule_AddOneShot(Rule_Tunnel8_Wave1, 10)
	Rule_AddOneShot(Rule_Tunnel8_Wave2, 20)

	Rule_Remove(Rule_TunnelTrigger8)
end

end

function Rule_Tunnel8_Wave1() Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm8", "necron_lord_destroyer_squad", "mkr_S_Tunnel11", 1, 1)

Cpu_LockSGroupAcrossPlayers("sg_TunnelSwarm8")
Cmd_AttackMoveMarker("sg_TunnelSwarm8", "mkr_TunnelTrigger8")

end

function Rule_Tunnel8_Wave2() Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm8", "necron_heavy_destroyer_squad", "mkr_S_Tunnel11", 1, 1)

Cpu_LockSGroupAcrossPlayers("sg_TunnelSwarm8")
Cmd_AttackMoveMarker("sg_TunnelSwarm8", "mkr_TunnelTrigger8")

end

function Rule_TunnelTrigger9() if Player_AreSquadsNearMarker(g_Player1, "mkr_TunnelTrigger9") then Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm9", "necron_pariah_squad", "mkr_S_Tunnel12", 1, g_SmallSquadSize)

	Cpu_LockSGroupAcrossPlayers("sg_TunnelSwarm9")
	Cmd_AttackMoveMarker("sg_TunnelSwarm9", "mkr_TunnelTrigger9")

	Rule_AddOneShot(Rule_Tunnel9_Wave1, 10)
	Rule_AddOneShot(Rule_Tunnel9_Wave2, 20)

	Rule_Remove(Rule_TunnelTrigger9)
end

end

function Rule_Tunnel9_Wave1() Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm9", "necron_pariah_squad", "mkr_S_Tunnel12", 1, g_SmallSquadSize)

Cpu_LockSGroupAcrossPlayers("sg_TunnelSwarm9")
Cmd_AttackMoveMarker("sg_TunnelSwarm9", "mkr_TunnelTrigger9")

end

function Rule_Tunnel9_Wave2() Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm9", "necron_pariah_squad", "mkr_S_Tunnel12", 1, g_SmallSquadSize)

Cpu_LockSGroupAcrossPlayers("sg_TunnelSwarm9")
Cmd_AttackMoveMarker("sg_TunnelSwarm9", "mkr_TunnelTrigger9")

end

function Rule_TunnelTrigger10() if Player_AreSquadsNearMarker(g_Player1, "mkr_TunnelTrigger10") then Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm10", "necron_basic_warrior_squad", "mkr_S_Tunnel14", 1, g_MediumSquadSize)

	Cpu_LockSGroupAcrossPlayers("sg_TunnelSwarm10")
	Cmd_AttackMoveMarker("sg_TunnelSwarm10", "mkr_TunnelTrigger10")

	Rule_AddOneShot(Rule_Tunnel10_Wave1, 10)
	Rule_AddOneShot(Rule_Tunnel10_Wave2, 20)

	Rule_Remove(Rule_TunnelTrigger10)
end

end

function Rule_Tunnel10_Wave1() Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm10", "necron_basic_warrior_squad", "mkr_S_Tunnel14", 1, g_MediumSquadSize)

Cpu_LockSGroupAcrossPlayers("sg_TunnelSwarm10")
Cmd_AttackMoveMarker("sg_TunnelSwarm10", "mkr_TunnelTrigger10")

end

function Rule_Tunnel10_Wave2() Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelSwarm10", "necron_tomb_spyder_squad", "mkr_S_Tunnel14", 1, 1)

Cpu_LockSGroupAcrossPlayers("sg_TunnelSwarm10")
Cmd_AttackMoveMarker("sg_TunnelSwarm10", "mkr_TunnelTrigger10")

end

function Rule_NecronLordAttack() if SGroup_IsEmpty("sg_NecronLord") then Rule_Remove(Rule_NecronLordAttack) end

Cpu_LockSGroupAcrossPlayers("sg_NecronLord")

if Player_AreSquadsNearMarker(g_Player1, "mkr_TriggerNightbringer") then
	Cmd_Possesion("sg_NecronLord")

	Rule_AddOneShot(Rule_NecronLordAttack2, 6)
	Rule_Remove(Rule_NecronLordAttack)
end

end

function Rule_NecronLordAttack2() Cmd_SetStance("sg_NecronLord", STANCE_Hold) Cmd_AttackMoveMarker("sg_NecronLord", "mkr_S_Generator3") end

function Rule_DiscoverTunnel1() if Player_AreSquadsNearMarker( g_Player1, "mkr_Tunnel1") then EGroup_SetPlayerOwner("eg_Tunnel1", g_Player1)

	g_ping_tunnel1_mini = Ping_Marker("mkr_Tunnel1", true, "attack")
	Rule_AddOneShot(Rule_RemoveTunnelPing1, 6)

		if not g_TunnelEncountered then
			if MetaMap_GetPlayerRaceName() == "chaos_marine_race" then
				Util_StartIntel(EVENTS.IE_Chaos_FirstTunnel)
			elseif MetaMap_GetPlayerRaceName() == "eldar_race" then
				Util_StartIntel(EVENTS.IE_Eldar_FirstTunnel)
			elseif MetaMap_GetPlayerRaceName() == "guard_race" then
				Util_StartIntel(EVENTS.IE_IG_FirstTunnel)
			elseif MetaMap_GetPlayerRaceName() == "ork_race" then
				Util_StartIntel(EVENTS.IE_Ork_FirstTunnel)
			elseif MetaMap_GetPlayerRaceName() == "space_marine_race" then
				Util_StartIntel(EVENTS.IE_SM_FirstTunnel)
			elseif MetaMap_GetPlayerRaceName() == "tau_race" then
				Util_StartIntel(EVENTS.IE_Tau_FirstTunnel)
			end
		else
			if MetaMap_GetPlayerRaceName() == "chaos_marine_race" then
				Util_StartIntel(EVENTS.IE_Chaos_AnotherTunnel)
			elseif MetaMap_GetPlayerRaceName() == "eldar_race" then
				Util_StartIntel(EVENTS.IE_Eldar_AnotherTunnel)
			elseif MetaMap_GetPlayerRaceName() == "guard_race" then
				Util_StartIntel(EVENTS.IE_IG_AnotherTunnel)
			elseif MetaMap_GetPlayerRaceName() == "ork_race" then
				Util_StartIntel(EVENTS.IE_Ork_AnotherTunnel)
			elseif MetaMap_GetPlayerRaceName() == "space_marine_race" then
				Util_StartIntel(EVENTS.IE_SM_AnotherTunnel)
			elseif MetaMap_GetPlayerRaceName() == "tau_race" then
				Util_StartIntel(EVENTS.IE_Tau_AnotherTunnel)
			end
		end

	g_TunnelEncountered = true
	Rule_Remove(Rule_DiscoverTunnel1)
end

end

function Rule_DiscoverTunnel2() if Player_AreSquadsNearMarker( g_Player1, "mkr_Tunnel2") then EGroup_SetPlayerOwner("eg_Tunnel2", g_Player1)

	g_ping_tunnel2_mini = Ping_Marker("mkr_Tunnel2", true, "attack")
	Rule_AddOneShot(Rule_RemoveTunnelPing2, 6)

		if not g_TunnelEncountered then
			if MetaMap_GetPlayerRaceName() == "chaos_marine_race" then
				Util_StartIntel(EVENTS.IE_Chaos_FirstTunnel)
			elseif MetaMap_GetPlayerRaceName() == "eldar_race" then
				Util_StartIntel(EVENTS.IE_Eldar_FirstTunnel)
			elseif MetaMap_GetPlayerRaceName() == "guard_race" then
				Util_StartIntel(EVENTS.IE_IG_FirstTunnel)
			elseif MetaMap_GetPlayerRaceName() == "ork_race" then
				Util_StartIntel(EVENTS.IE_Ork_FirstTunnel)
			elseif MetaMap_GetPlayerRaceName() == "space_marine_race" then
				Util_StartIntel(EVENTS.IE_SM_FirstTunnel)
			elseif MetaMap_GetPlayerRaceName() == "tau_race" then
				Util_StartIntel(EVENTS.IE_Tau_FirstTunnel)
			end
		else
			if MetaMap_GetPlayerRaceName() == "chaos_marine_race" then
				Util_StartIntel(EVENTS.IE_Chaos_AnotherTunnel)
			elseif MetaMap_GetPlayerRaceName() == "eldar_race" then
				Util_StartIntel(EVENTS.IE_Eldar_AnotherTunnel)
			elseif MetaMap_GetPlayerRaceName() == "guard_race" then
				Util_StartIntel(EVENTS.IE_IG_AnotherTunnel)
			elseif MetaMap_GetPlayerRaceName() == "ork_race" then
				Util_StartIntel(EVENTS.IE_Ork_AnotherTunnel)
			elseif MetaMap_GetPlayerRaceName() == "space_marine_race" then
				Util_StartIntel(EVENTS.IE_SM_AnotherTunnel)
			elseif MetaMap_GetPlayerRaceName() == "tau_race" then
				Util_StartIntel(EVENTS.IE_Tau_AnotherTunnel)
			end
		end

	g_TunnelEncountered = true
	Rule_Remove(Rule_DiscoverTunnel2)
end

end

function Rule_DiscoverTunnel3() if Player_AreSquadsNearMarker( g_Player1, "mkr_Tunnel3") then EGroup_SetPlayerOwner("eg_Tunnel3", g_Player1)

	g_ping_tunnel3_mini = Ping_Marker("mkr_Tunnel3", true, "attack")
	Rule_AddOneShot(Rule_RemoveTunnelPing3, 6)

		if not g_TunnelEncountered then
			if MetaMap_GetPlayerRaceName() == "chaos_marine_race" then
				Util_StartIntel(EVENTS.IE_Chaos_FirstTunnel)
			elseif MetaMap_GetPlayerRaceName() == "eldar_race" then
				Util_StartIntel(EVENTS.IE_Eldar_FirstTunnel)
			elseif MetaMap_GetPlayerRaceName() == "guard_race" then
				Util_StartIntel(EVENTS.IE_IG_FirstTunnel)
			elseif MetaMap_GetPlayerRaceName() == "ork_race" then
				Util_StartIntel(EVENTS.IE_Ork_FirstTunnel)
			elseif MetaMap_GetPlayerRaceName() == "space_marine_race" then
				Util_StartIntel(EVENTS.IE_SM_FirstTunnel)
			elseif MetaMap_GetPlayerRaceName() == "tau_race" then
				Util_StartIntel(EVENTS.IE_Tau_FirstTunnel)
			end
		else
			if MetaMap_GetPlayerRaceName() == "chaos_marine_race" then
				Util_StartIntel(EVENTS.IE_Chaos_AnotherTunnel)
			elseif MetaMap_GetPlayerRaceName() == "eldar_race" then
				Util_StartIntel(EVENTS.IE_Eldar_AnotherTunnel)
			elseif MetaMap_GetPlayerRaceName() == "guard_race" then
				Util_StartIntel(EVENTS.IE_IG_AnotherTunnel)
			elseif MetaMap_GetPlayerRaceName() == "ork_race" then
				Util_StartIntel(EVENTS.IE_Ork_AnotherTunnel)
			elseif MetaMap_GetPlayerRaceName() == "space_marine_race" then
				Util_StartIntel(EVENTS.IE_SM_AnotherTunnel)
			elseif MetaMap_GetPlayerRaceName() == "tau_race" then
				Util_StartIntel(EVENTS.IE_Tau_AnotherTunnel)
			end
		end

	g_TunnelEncountered = true
	Rule_Remove(Rule_DiscoverTunnel3)
end

end

function Rule_DiscoverTunnel4() if Player_AreSquadsNearMarker( g_Player1, "mkr_Tunnel4") then EGroup_SetPlayerOwner("eg_Tunnel4", g_Player1)

	g_ping_tunnel4_mini = Ping_Marker("mkr_Tunnel4", true, "attack")
	Rule_AddOneShot(Rule_RemoveTunnelPing4, 6)

		if not g_TunnelEncountered then
			if MetaMap_GetPlayerRaceName() == "chaos_marine_race" then
				Util_StartIntel(EVENTS.IE_Chaos_FirstTunnel)
			elseif MetaMap_GetPlayerRaceName() == "eldar_race" then
				Util_StartIntel(EVENTS.IE_Eldar_FirstTunnel)
			elseif MetaMap_GetPlayerRaceName() == "guard_race" then
				Util_StartIntel(EVENTS.IE_IG_FirstTunnel)
			elseif MetaMap_GetPlayerRaceName() == "ork_race" then
				Util_StartIntel(EVENTS.IE_Ork_FirstTunnel)
			elseif MetaMap_GetPlayerRaceName() == "space_marine_race" then
				Util_StartIntel(EVENTS.IE_SM_FirstTunnel)
			elseif MetaMap_GetPlayerRaceName() == "tau_race" then
				Util_StartIntel(EVENTS.IE_Tau_FirstTunnel)
			end
		else
			if MetaMap_GetPlayerRaceName() == "chaos_marine_race" then
				Util_StartIntel(EVENTS.IE_Chaos_AnotherTunnel)
			elseif MetaMap_GetPlayerRaceName() == "eldar_race" then
				Util_StartIntel(EVENTS.IE_Eldar_AnotherTunnel)
			elseif MetaMap_GetPlayerRaceName() == "guard_race" then
				Util_StartIntel(EVENTS.IE_IG_AnotherTunnel)
			elseif MetaMap_GetPlayerRaceName() == "ork_race" then
				Util_StartIntel(EVENTS.IE_Ork_AnotherTunnel)
			elseif MetaMap_GetPlayerRaceName() == "space_marine_race" then
				Util_StartIntel(EVENTS.IE_SM_AnotherTunnel)
			elseif MetaMap_GetPlayerRaceName() == "tau_race" then
				Util_StartIntel(EVENTS.IE_Tau_AnotherTunnel)
			end
		end

	g_TunnelEncountered = true
	Rule_Remove(Rule_DiscoverTunnel4)
end

end

function Rule_DiscoverTunnel5() if Player_AreSquadsNearMarker( g_Player1, "mkr_Tunnel5") then EGroup_SetPlayerOwner("eg_Tunnel5", g_Player1)

	g_ping_tunnel5_mini = Ping_Marker("mkr_Tunnel5", true, "attack")
	Rule_AddOneShot(Rule_RemoveTunnelPing5, 6)

		if not g_TunnelEncountered then
			if MetaMap_GetPlayerRaceName() == "chaos_marine_race" then
				Util_StartIntel(EVENTS.IE_Chaos_FirstTunnel)
			elseif MetaMap_GetPlayerRaceName() == "eldar_race" then
				Util_StartIntel(EVENTS.IE_Eldar_FirstTunnel)
			elseif MetaMap_GetPlayerRaceName() == "guard_race" then
				Util_StartIntel(EVENTS.IE_IG_FirstTunnel)
			elseif MetaMap_GetPlayerRaceName() == "ork_race" then
				Util_StartIntel(EVENTS.IE_Ork_FirstTunnel)
			elseif MetaMap_GetPlayerRaceName() == "space_marine_race" then
				Util_StartIntel(EVENTS.IE_SM_FirstTunnel)
			elseif MetaMap_GetPlayerRaceName() == "tau_race" then
				Util_StartIntel(EVENTS.IE_Tau_FirstTunnel)
			end
		else
			if MetaMap_GetPlayerRaceName() == "chaos_marine_race" then
				Util_StartIntel(EVENTS.IE_Chaos_AnotherTunnel)
			elseif MetaMap_GetPlayerRaceName() == "eldar_race" then
				Util_StartIntel(EVENTS.IE_Eldar_AnotherTunnel)
			elseif MetaMap_GetPlayerRaceName() == "guard_race" then
				Util_StartIntel(EVENTS.IE_IG_AnotherTunnel)
			elseif MetaMap_GetPlayerRaceName() == "ork_race" then
				Util_StartIntel(EVENTS.IE_Ork_AnotherTunnel)
			elseif MetaMap_GetPlayerRaceName() == "space_marine_race" then
				Util_StartIntel(EVENTS.IE_SM_AnotherTunnel)
			elseif MetaMap_GetPlayerRaceName() == "tau_race" then
				Util_StartIntel(EVENTS.IE_Tau_AnotherTunnel)
			end
		end

	g_TunnelEncountered = true
	Rule_Remove(Rule_DiscoverTunnel5)
end

end

function Rule_IntroSpeech() if MetaMap_GetPlayerRaceName() == "chaos_marine_race" then Util_StartIntel(EVENTS.IE_Chaos_Intro) elseif MetaMap_GetPlayerRaceName() == "eldar_race" then Util_StartIntel(EVENTS.IE_Eldar_Intro) elseif MetaMap_GetPlayerRaceName() == "guard_race" then Util_StartIntel(EVENTS.IE_IG_Intro) elseif MetaMap_GetPlayerRaceName() == "ork_race" then Util_StartIntel(EVENTS.IE_Ork_Intro) elseif MetaMap_GetPlayerRaceName() == "space_marine_race" then Util_StartIntel(EVENTS.IE_SM_Intro) elseif MetaMap_GetPlayerRaceName() == "tau_race" then Util_StartIntel(EVENTS.IE_Tau_Intro) end end


--[[ OBJECTIVES ]]

--[[Primary Objective - set up them the bomb]] function Rule_Objective_Bomb()

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Bomb.title_id) == false then
	
	Util_WXP_ObjectiveCreate(Objective_Bomb, true, g_Player1)
	
	--[[adding map and mini-map pings]]
	g_ping_bomb = Objective_PingMarker(Objective_Bomb.title_id, "mkr_Bomb", true, "default")
	g_ping_bomb_mini = Ping_Marker("mkr_Bomb", true, "default")

	FOW_RevealArea(-223, -230, 50,  10)

	--Objective_ShowScreen()
	
	Rule_AddOneShot(Rule_Button_Setup, 1)
	Rule_AddDelay(Rule_Button_Available,2)
	Rule_AddDelay(Rule_Button_Click,2)
	
	
	Rule_Remove(Rule_Objective_Bomb)
	
end

end

function Rule_Button_Setup()

t_bomb = {
	button_icon = {--[[1]]"Scar_buttons/place_bomb", --[[2]]"Scar_buttons/place_bomb", --[[3]]"Scar_buttons/place_bomb"},
	button_description = {--[[1]]"$2679000", --[[2]]"$2670001"}, 
}

g_button_spawn = Util_AbilityButton_Create(t_bomb.button_icon, t_bomb.button_description, true)
Button_SetIndexHint(g_button_spawn, 6)

Util_SGroupAbilityButton_Add2Manager(g_button_spawn, "sg_Leader")
Util_ButtonManagerUpdateAll()

--UIWarning_Show("$2670001")

--Rule_AddOneShot(Rule_CommanderWarning2, 8)
--Rule_AddOneShot(Rule_CommanderWarning3, 10.5)

end

function Rule_CommanderWarning1() Objective_ShowScreen() Flash_OtherButton("dlg_objectives", 0, false, true) end

function Rule_CommanderWarning2() UIWarning_Show("$2670101") end

function Rule_CommanderWarning3() UIWarning_Show("$2670101") end

function Rule_Button_Available()

if Prox_AllSquadsNearMarker("sg_Leader", "mkr_Bomb") then

	Button_SetEnabled(g_button_spawn, true)

else

	Button_SetEnabled(g_button_spawn, false)

end

end

function Rule_ButtonObjectiveShow() if Event_IsAnyRunning() == false then Objective_ShowScreen() Flash_OtherButton("dlg_objectives", 0, false, true) Rule_Remove(Rule_ButtonObjectiveShow) end end

function Rule_Button_Click()

if Button_GetPressed(g_button_spawn) == true then

	if Prox_AllSquadsNearMarker("sg_Leader", "mkr_Bomb") then

		Button_SetEnabled(g_button_spawn, false)

		
		Util_ObjectiveComplete(Objective_Bomb.title_id)
		
		Util_WXP_ObjectiveCreate(Objective_Escape, true, g_Player1)

		Rule_AddIntervalDelay(Rule_ButtonObjectiveShow, 3, 3)
		
		UIWarning_Show("$2679003")
		
			if MetaMap_GetPlayerRaceName() == "chaos_marine_race" then
				Util_StartIntel(EVENTS.IE_Chaos_BombPlaced)
				EGroup_ReSpawn("eg_ChaosBomb")
			elseif MetaMap_GetPlayerRaceName() == "eldar_race" then
				Util_StartIntel(EVENTS.IE_Eldar_BombPlaced)
				EGroup_ReSpawn("eg_EldarBomb")
			elseif MetaMap_GetPlayerRaceName() == "guard_race" then
				Util_StartIntel(EVENTS.IE_IG_BombPlaced)
				EGroup_ReSpawn("eg_IGBomb")
			elseif MetaMap_GetPlayerRaceName() == "ork_race" then
				Util_StartIntel(EVENTS.IE_Ork_BombPlaced)
				EGroup_ReSpawn("eg_OrkBomb")
			elseif MetaMap_GetPlayerRaceName() == "space_marine_race" then
				Util_StartIntel(EVENTS.IE_SM_BombPlaced)
				EGroup_ReSpawn("eg_SMBomb")
			elseif MetaMap_GetPlayerRaceName() == "tau_race" then
				Util_StartIntel(EVENTS.IE_Tau_BombPlaced)
				EGroup_ReSpawn("eg_TauBomb")
			end

		for i = 1, 4 do
			Squad_DeepStrikeToPos(SGroup_FromName("sg_BombAmbush"..i), "monolith", Marker_GetPosition(Marker_FromName("mkr_BombAmbush"..i, "basic_marker")))
			Cmd_AttackSGroup("sg_BombAmbush"..i, "sg_Leader")
		end
		
		Rule_AddOneShot(Rule_AmbushersAttack, 10)
		
		g_ping_escape = Objective_PingMarker(Objective_Bomb.title_id, "mkr_Escape", true, "default")
		g_ping_escape_mini = Ping_Marker("mkr_Escape", true, "default")
	
		Rule_AddOneShot(Rule_Stop_Bomb_Ping, 0.5)
		
		g_Escape = true
		
		Rule_AddOneShot(Rule_Game_Win_Timer, 1) 

		--[[ Set up a Win Check ]]
		Rule_AddInterval(Rule_EndGame_Win, 1)

		Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelKillers", "necron_wraith_squad", "mkr_S_Tunnel11", 2, 1)
		Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelKillers", "necron_lord_destroyer_squad", "mkr_S_Tunnel12", 2, 1)
		Util_CreateSquadsAtMarkerEx(g_Player2, "sg_TunnelKillers", "necron_destroyer_squad", "mkr_S_Tunnel13", 2, 1)
		Cmd_AttackSGroup("sg_TunnelKillers", "sg_Leader")
		
		Rule_AddInterval(Rule_TunnelKillers, g_AssassinInterval)

		if not (g_Beacon1Dead and g_Beacon2Dead and g_Beacon3Dead and g_Beacon4Dead and g_MonolithsDead) then
			--Message
			
			g_Penalties = true
			
			Util_StartIntel(EVENTS.IE_Global_BeaconPowerup)
			Rule_AddOneShot(Rule_Penalties, 25)
		end

		Rule_Remove(Rule_Button_Available)			
		Rule_Remove(Rule_Button_Click)
		
		Button_Remove(g_button_spawn)
	--	Util_ButtonManagerUpdateAll()
		
	else
	
		UIWarning_Show("$2679002")
	
	end
end

end

function Rule_AmbushersAttack() for i = 1, 4 do Cmd_AttackSGroup("sg_BombAmbush"..i, "sg_Leader") end end

function Rule_Penalties()

--Monoliths failure?
if Rule_Exists(Rule_EncounterMonoliths) then
	Rule_Remove(Rule_EncounterMonoliths)
end
if Rule_Exists(Rule_Objective_Monoliths) then
	Rule_Remove(Rule_EncounterMonoliths)
end
if Rule_Exists(Rule_MonitorMonoliths) then
	Rule_Remove(Rule_EncounterMonoliths)
end
if Objective_Exists(Objective_Monoliths.title_id) then
	Util_ObjectiveFail(Objective_Monoliths.title_id)
end

end

function Rule_Game_Win_Timer()

UI_ShowCountDXP( "FinalTimer", g_Player1, 2679004, g_EscapeTimer )
Rule_AddInterval( Rule_Decrement_Timer, 60)

end

function Rule_Decrement_Timer()

g_EscapeTimer = g_EscapeTimer - 1
UI_ShowCountUpdateDxp("FinalTimer", g_EscapeTimer, 2679004)

end

function Rule_Objective_Survive()

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Survive.title_id) == false then
	
	Util_WXP_ObjectiveCreate(Objective_Survive, true, g_Player1)
	
	Rule_AddOneShot(Rule_CommanderWarning1, 5)

	Rule_Remove(Rule_Objective_Survive)
	
end

end

function Rule_Objective_Monoliths()

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Monoliths.title_id) == false then
	g_MonolithsFound = true
	
	FOW_RevealArea(167, 81, 50,  10)
	Util_WXP_ObjectiveCreate(Objective_Monoliths, false, g_Player1)
	
	if not g_Penalties then
		Objective_ShowScreen()
		Flash_OtherButton("dlg_objectives", 0, false, true)
	end
	
	--[[adding map and mini-map pings]]
	g_ping_monoliths = Objective_PingMarker(Objective_Monoliths.title_id, "mkr_MonolithTrigger", true, "default")
	g_ping_monoliths_mini = Ping_Marker("mkr_MonolithTrigger", true, "default")
	

-- Ping_Stop(g_ping_beacons1)

	Rule_AddOneShot(Rule_Stop_Monoliths_Ping, 5)
	
	Rule_AddInterval(Rule_MonitorMonoliths, 5)
	Rule_Remove(Rule_Objective_Monoliths)
	
end

end

function Rule_MonitorMonoliths() if (not g_Escape) and EGroup_IsEmpty("eg_Monolith1") and EGroup_IsEmpty("eg_Monolith2") and EGroup_IsEmpty("eg_Monolith3") and EGroup_IsEmpty("eg_Monolith4") then

	g_MonolithsDead = true
	
	Util_ObjectiveComplete(Objective_Monoliths.title_id)
	Rule_Remove(Rule_MonitorMonoliths)
end

end

function Rule_Objective_Beacons()

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Beacons.title_id) == false then
	
			if MetaMap_GetPlayerRaceName() == "chaos_marine_race" then
				Util_StartIntel(EVENTS.IE_Chaos_Investigate)
			elseif MetaMap_GetPlayerRaceName() == "eldar_race" then
				Util_StartIntel(EVENTS.IE_Eldar_Investigate)
			elseif MetaMap_GetPlayerRaceName() == "guard_race" then
				Util_StartIntel(EVENTS.IE_IG_Investigate)
			elseif MetaMap_GetPlayerRaceName() == "ork_race" then
				Util_StartIntel(EVENTS.IE_Ork_Investigate)
			elseif MetaMap_GetPlayerRaceName() == "space_marine_race" then
				Util_StartIntel(EVENTS.IE_SM_Investigate)
			elseif MetaMap_GetPlayerRaceName() == "tau_race" then
				Util_StartIntel(EVENTS.IE_Tau_Investigate)
			end

	Util_WXP_ObjectiveCreate(Objective_Beacons, false, g_Player1)
	
	if not g_Penalties then
		Rule_AddIntervalDelay(Rule_BeaconObjectiveShow, 3, 3)
	end

	--[[adding map and mini-map pings]]
	g_ping_beacons1 = Objective_PingMarker(Objective_Beacons.title_id, "mkr_MonolithTrigger", true, "default")
	g_ping_beacons1_mini = Ping_Marker("mkr_MonolithTrigger", true, "default")
	g_ping_beacons2 = Objective_PingMarker(Objective_Beacons.title_id, "mkr_S_Beacon1", true, "default")
	g_ping_beacons2_mini = Ping_Marker("mkr_S_Beacon1", true, "default")
	g_ping_beacons3 = Objective_PingMarker(Objective_Beacons.title_id, "mkr_S_Beacon2", true, "default")
	g_ping_beacons3_mini = Ping_Marker("mkr_S_Beacon2", true, "default")
	g_ping_beacons4 = Objective_PingMarker(Objective_Beacons.title_id, "mkr_S_Beacon3", true, "default")
	g_ping_beacons4_mini = Ping_Marker("mkr_S_Beacon3", true, "default")
	g_ping_beacons5 = Objective_PingMarker(Objective_Beacons.title_id, "mkr_S_Beacon4", true, "default")
	g_ping_beacons5_mini = Ping_Marker("mkr_S_Beacon4", true, "default")
	
	Rule_AddOneShot(Rule_Stop_Beacons_Ping, 5)
	
	Rule_AddInterval(Rule_MonitorInvestigation, 4)
	
	Rule_Remove(Rule_Objective_Beacons)
	
end

end

function Rule_BeaconObjectiveShow() if Event_IsAnyRunning() == false then Objective_ShowScreen() Flash_OtherButton("dlg_objectives", 0, false, true) Rule_Remove(Rule_BeaconObjectiveShow) end end

function Rule_Objective_Ressurection()

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Ressurection.title_id) == false then
	g_Beacon1Found = true
	
	Util_WXP_ObjectiveCreate(Objective_Ressurection, false, g_Player1)
	
	if not g_Penalties then
		Objective_ShowScreen()
		Flash_OtherButton("dlg_objectives", 0, false, true)
	end

	g_ping_ressurection = Objective_PingMarker(Objective_Ressurection.title_id, "mkr_S_Beacon1", true, "default")
	g_ping_ressurection_mini = Ping_Marker("mkr_S_Beacon1", true, "default")

-- Ping_Stop(g_ping_beacons2)

	Rule_AddOneShot(Rule_Stop_Ressurection_Ping, 5)

	Rule_AddInterval(Rule_MonitorBeacon1, 4)

	Rule_Remove(Rule_Objective_Ressurection)
	
end

end

function Rule_Objective_Possession()

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Possession.title_id) == false then
	g_Beacon2Found = true
	
	Util_WXP_ObjectiveCreate(Objective_Possession, false, g_Player1)
	
	if not g_Penalties then
		Objective_ShowScreen()
		Flash_OtherButton("dlg_objectives", 0, false, true)
	end

	g_ping_possession = Objective_PingMarker(Objective_Possession.title_id, "mkr_S_Beacon2", true, "default")
	g_ping_possession_mini = Ping_Marker("mkr_S_Beacon2", true, "default")

	--Ping_Stop(g_ping_beacons3)
	
	Rule_AddOneShot(Rule_Stop_Possession_Ping, 5)

	Rule_AddIntervalDelay(Rule_MonitorBeacon2, 4, 3)

	Rule_Remove(Rule_Objective_Possession)
	
end

end

function Rule_Objective_Chronometron()

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Chronometron.title_id) == false then
	g_Beacon3Found = true
	
	Util_WXP_ObjectiveCreate(Objective_Chronometron, false, g_Player1)
	
	if not g_Penalties then
		Objective_ShowScreen()
		Flash_OtherButton("dlg_objectives", 0, false, true)
	end

	g_ping_chronometron = Objective_PingMarker(Objective_Chronometron.title_id, "mkr_S_Beacon3", true, "default")
	g_ping_chronometron_mini = Ping_Marker("mkr_S_Beacon3", true, "default")

	--Ping_Stop(g_ping_beacons4)

	Rule_AddOneShot(Rule_Stop_Chronometron_Ping, 5)

	Rule_AddIntervalDelay(Rule_MonitorBeacon3, 4, 1)

	Rule_Remove(Rule_Objective_Chronometron)
	
end

end

function Rule_Objective_Darkness()

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Darkness.title_id) == false then
	g_Beacon4Found = true
	
	Util_WXP_ObjectiveCreate(Objective_Darkness, false, g_Player1)
	
	if not g_Penalties then
		Objective_ShowScreen()
		Flash_OtherButton("dlg_objectives", 0, false, true)
	end

	g_ping_darkness = Objective_PingMarker(Objective_Darkness.title_id, "mkr_S_Beacon4", true, "default")
	g_ping_darkness_mini = Ping_Marker("mkr_S_Beacon4", true, "default")

	--Ping_Stop(g_ping_beacons5)

	Rule_AddOneShot(Rule_Stop_Darkness_Ping, 5)

	Rule_AddIntervalDelay(Rule_MonitorBeacon4, 4, 2)

	Rule_Remove(Rule_Objective_Darkness)
	
end

end

function Rule_MonitorBeacon1() if EGroup_IsEmpty("eg_Beacon1") then Util_ObjectiveComplete(Objective_Ressurection.title_id) g_Beacon1Dead = true Rule_Remove(Rule_MonitorBeacon1) end end

function Rule_MonitorBeacon2() if EGroup_IsEmpty("eg_Beacon2") then Util_ObjectiveComplete(Objective_Possession.title_id) g_Beacon2Dead = true if SGroup_Exists("sg_Vehicle") then SGroup_SetPlayerOwner("sg_Vehicle", g_Player1) end Rule_Remove(Rule_MonitorBeacon2) end end

function Rule_MonitorBeacon3() if EGroup_IsEmpty("eg_Beacon3") then Util_ObjectiveComplete(Objective_Chronometron.title_id) g_Beacon3Dead = true Rule_Remove(Rule_MonitorBeacon3) end end

function Rule_MonitorBeacon4() if EGroup_IsEmpty("eg_Beacon4") then Util_ObjectiveComplete(Objective_Darkness.title_id) g_Beacon4Dead = true Rule_Remove(Rule_MonitorBeacon4) end end

function Rule_MonitorInvestigation() if g_Beacon1Found and g_Beacon2Found and g_Beacon3Found and g_Beacon4Found and g_MonolithsFound then Util_ObjectiveComplete(Objective_Beacons.title_id)

	Rule_Remove(Rule_MonitorInvestigation)
end

end


--[[ Forward Base Event ]]

function Rule_Stop_Bomb_Ping()

Ping_Stop(g_ping_bomb_mini)

end

function Rule_Stop_Monoliths_Ping()

Ping_Stop(g_ping_monoliths_mini)

end

function Rule_Stop_Beacons_Ping()

Ping_Stop(g_ping_beacons1_mini)
Ping_Stop(g_ping_beacons2_mini)
Ping_Stop(g_ping_beacons4_mini)
Ping_Stop(g_ping_beacons5_mini)
Ping_Stop(g_ping_beacons3_mini)

end

function Rule_Stop_Ressurection_Ping()

Ping_Stop(g_ping_ressurection_mini)

end

function Rule_Stop_Chronometron_Ping()

Ping_Stop(g_ping_chronometron_mini)

end

function Rule_Stop_Darkness_Ping()

Ping_Stop(g_ping_darkness_mini)

end

function Rule_Stop_Possession_Ping()

Ping_Stop(g_ping_possession_mini)

end

function Rule_RemoveTunnelPing1() Ping_Stop(g_ping_tunnel1_mini) end

function Rule_RemoveTunnelPing2() Ping_Stop(g_ping_tunnel2_mini) end

function Rule_RemoveTunnelPing3() Ping_Stop(g_ping_tunnel3_mini) end

function Rule_RemoveTunnelPing4() Ping_Stop(g_ping_tunnel4_mini) end

function Rule_RemoveTunnelPing5() Ping_Stop(g_ping_tunnel5_mini) end

--[[ win loss ]]

function Rule_EndGame_Win()

if Prox_AllSquadsNearMarker("sg_Leader", "mkr_Escape") then
			if MetaMap_GetPlayerRaceName() == "chaos_marine_race" then
				Util_StartIntel(EVENTS.IE_Chaos_Escape)
			elseif MetaMap_GetPlayerRaceName() == "eldar_race" then
				Util_StartIntel(EVENTS.IE_Eldar_Escape)
			elseif MetaMap_GetPlayerRaceName() == "guard_race" then
				Util_StartIntel(EVENTS.IE_IG_Escape)
			elseif MetaMap_GetPlayerRaceName() == "ork_race" then
				Util_StartIntel(EVENTS.IE_Ork_Escape)
			elseif MetaMap_GetPlayerRaceName() == "space_marine_race" then
				Util_StartIntel(EVENTS.IE_SM_Escape)
			elseif MetaMap_GetPlayerRaceName() == "tau_race" then
				Util_StartIntel(EVENTS.IE_Tau_Escape)
			end

	Rule_Remove(Rule_EndGameLose)
	Util_StartNIS( EVENTS.NIS_Outro ) 
	Rule_Remove(Rule_EndGame_Win)
	
end

end

function Rule_GameWon() g_Win = true

	World_SetTeamWin( g_Player1, "" )
	Rule_AddIntervalEx( Rule_GameOver,5,1 )

end

function Rule_CommanderFailure() UIWarning_Show("$2670100") end

function Rule_EndGameLose()

g_building_exceptions = 
{
}

g_unit_exceptions = 
{
}

-- If the player's commander dies, or the bomb timer hits 0, the mission is failed.
if not SGroup_ContainsBlueprints( "sg_Leader", t_blueprintleader, false ) then
	
	Rule_RemoveAll()

	UIWarning_Show("$1665001")
	Rule_AddOneShot(Rule_CommanderFailure, 3)

	Fade_Start(5, false)
	World_SetTeamWin( g_enemy, "" )
	Rule_AddIntervalEx( Rule_GameOver,5,1 )
	Rule_Remove( Rule_EndGameLose )
	Rule_Remove( Rule_EndGame_Win )
end

if (g_EscapeTimer == 0) then
	Rule_RemoveAll()
	Fade_Start(4, false)
	World_SetTeamWin( g_enemy, "" )
	Rule_AddIntervalEx( Rule_GameOver,5,1 )
	Rule_Remove( Rule_EndGameLose )
	Rule_Remove( Rule_EndGame_Win )
end


--[[ Lose because of Annihilation ]]	

-- if( Player_HasBuildingsExcept(g_Player1, g_building_exceptions) == false ) then -- if( Player_HasSquadsExcept(g_Player1, g_unit_exceptions ) == false ) then -- Rule_RemoveAll() -- Fade_Start(4, false) -- World_SetTeamWin( g_enemy, "" ) -- Rule_AddIntervalEx( Rule_GameOver,5,1 ) -- Rule_Remove( Rule_EndGameLose ) -- Rule_Remove( Rule_EndGame_Win ) -- end -- end

end

--[[ call this with an interval to ensure the mission ends ]] function Rule_GameOver() World_SetGameOver() end


--[[Timer ]]

function Rule_Add_Timer()

	--UI_ShowCountDXP("Timer", g_Player1, 2774601, g_Timer )
	Rule_AddInterval(Rule_Increment_Timer, 60)

end

function Rule_Increment_Timer()

g_Timer = g_Timer +1
--UI_ShowCountUpdateDxp("Timer", g_Timer, 2774601)

g_Escalation1 = 30 + math.floor ((g_Difficulty - g_DBase) * ((12 - 30) / (g_DMax - g_DBase)))
g_Escalation2 = 60 + math.floor ((g_Difficulty - g_DBase) * ((24 - 60) / (g_DMax - g_DBase)))

--Timer which increase the ferocity of tunnel and monolith attacks.
if g_Timer > g_Escalation1 then
	g_Timer1 = true
end

if g_Timer > g_Escalation2 then
	g_Timer2 = true
end

end