Mission event file for Chaos final mission
Gidsen
/
Mission event file for Chaos final mission
Geüpdatet 3 years ago door Merric

--[[ IMPORTS ]]

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


--[[ GAME SETUP ]]

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

g_Player1 = Setup_Player(0, "$690088", "chaos_marine_race", 0)
Misc_PlayerTeamColor(g_Player1,"default_6")
Player_DoNotPrecache(g_Player1, _t_MSD5C_Player1)

g_Player2 = Setup_Player(1, "$690082", "guard_race", 1)
Player_DoNotPrecache(g_Player2, _t_MSD5C_Player2)

g_Player3 = Setup_Player(2, "$900014", "npc_race", 2) -- placeholder Necrons
Player_DoNotPrecache(g_Player3, _t_MSD5C_Player3)

g_Player4 = Setup_Player(3, "$900016", "guard_race", TEAM_NEUTRAL) -- placeholder Heavy Weapons and "controlled" guardsmen

--[[ JUST GUARDSMEN ]] Player_DoNotPrecache(g_Player4, _t_MSD5C_Player4)

--[[ DEFINE VARIABLES AND TABLES - define any preset values here for later use]]
g_firstrun = true
--[[ define the "enemy" who will win if the player 'loses' ]]
g_enemy = g_Player2
t_sacrifice_dude = {}
t_titan_defenders_converted = {false, false, false, false, false, false, false, false, false, false, false, false, false, false}
t_sacrifice_ok = {false, false, false, false}
t_sgroup_titan_heavy_weapon = {false, false, false, false, false, false}
g_bodycount = 0
t_sgroup_IG_defenders = {}
t_sgroup_monoliths = {}
t_owner_of_sg_titan_defender = {}
t_sacrifice_dudes_flag = {false, false, false, false, false, false}
g_necron_appearance = false
g_ultramarine_appearance = false
g_necrons_advanced = false
g_necron_appear_flag = false
g_sacrifice_finished = false
g_necron_moved = false
g_number_captured = 0
t_drop_slot_number_occupied = {false, false, false, false, false, false, false, false}
g_slot_found = false
g_dropcount = 1
t_outpost2and3_counterattack = {false, false, false, false}
t_outpost1and3_counterattack = {false, false, false ,false}
t_outpost1and2_counterattack = {false, false, false, false}
t_restockcount = {42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42}

-- t_IG_random_attack_on = {false, false, false} -- g_IG_random_attack_on = false -- t_piece_captured = {false, false, false, false, false, false}

g_add_button = false
g_captured = false

g_add_button_titan = false
g_captured_titan = false

t_titan_piece_owned = {false, false, false, false, false, false}
g_pieces_owned_count = 0
t_pos = {}
g_IG_Random_Raid_Army_iter = 1

g_random_ig_attack_on_chaos_base_started = true

end

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

--[[ nothing at the moment ]]

end

--[[ the OnLoad() function acts like the OnInit() but for saved games only ]] function OnLoad()

if g_titanactive then
	Anim_PlayEGroupAnim(EGroup_FromName("eg_maintitanbody"), "d_idle")
	Anim_PlayEGroupAnim(EGroup_FromName("eg_titanarm"), "d_idle")
	Anim_PlayEGroupAnim(EGroup_FromName("eg_titanskull"), "d_idle")
end

 Rule_AddOneShot(Rule_FOW_Reset, 1)
 

end

Scar_AddLoad(OnLoad)

--[[ ON INITIALIZATION ]]

function OnInit()

--[[ RESEARCH LEVEL ]]
-- 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 ]]
WXP_OpeningNISPreset()
SGroup_DeSpawn("sg_NISD_lord")

--[[ 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 ]]
Rule_PresetAI()		

--[[ START NIS ]]
-- calls the NIS function located in the MissionName.nis file ]]
Util_StartNIS( EVENTS.NIS_Opening ) 	

--[[ GET THE START PLAY MISSION READY TO ROLL ]]
Rule_Add( Rule_GameStart )	

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 )

Player_RestrictSquad(g_Player1, "chaos_squad_lord")
Player_RestrictSquad(g_Player1, "chaos_squad_sorcerer")
Player_RestrictBuilding(g_Player1, "chaos_hq")

Player_RestrictAbility(g_Player1, "sp_dxp_abilities_titanmaincannon")
Player_RestrictAbility(g_Player1, "guard_psyker_lightning_arc2")
Player_RestrictAbility(g_Player1, "guard_psyker_lightning_arc")

-- Player_RestrictAbility(g_Player1, "guard_psyker_machine_curse") Player_RestrictAbility(g_Player1, "guard_psyker_strip_soul") -- Player_RestrictAbility(g_Player1, "guard_psyker_telepathic_order") Player_RestrictAbility(g_Player1, "chaos_chains_of_torment") Player_RestrictAbility(g_Player1, "chaos_corruption")

Player_RestrictResearch(g_Player1, "chaos_sorcerer_research_1")
Player_RestrictResearch(g_Player1, "chaos_sorcerer_research_2")



local buildings = {"guard_mines", "guard_plasma_generator", "guard_thermo_plasma"}
local squads = {
	"guard_squad_priest", 
	"guard_squad_command_squad", 
	"guard_squad_psyker", 
	"guard_squad_enginseer", 
	"guard_squad_basilisk_sp_mso2", 
	"guard_squad_sentinel"
}
Player_RestrictBuildingList(g_Player2, buildings)
Player_RestrictSquadList(g_Player2, squads)

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

end


--[[ MUSIC ]]

function Rule_SetupMusicPlaylist()

t_ambient = {"Snowy_wind_1", "Warhammer_XP_battle_BG" }
Playlist_Manager( PC_Ambient, t_ambient, true , true , {5, 10})

end


--[[ PRESET AI ]]

function Rule_PresetAI()

Cpu_EnableAll(false)	

end


--[[ START PLAY ]]

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

function Rule_GameStart()

if g_firstrun then
	
	--[[ SET RESOURCES ]]
	Player_SetAllResources(g_Player1, 1200, 500)
	
	--[[ PREACTION ]]
	-- Use this space to add core mission functions that should be in place during the opening NIS
	Rule_AddInterval(Rule_Timer, 1)
	
	--[[ Army Kickoff ]] -- Spawn armies
	Rule_AddOneShot(Rule_Player_Army_Kickoff, 0)
	Rule_AddInterval(Rule_Crull_Track, 4)
	
	Rule_AddOneShot(Rule_Imperial_Guard_Army_Kickoff, 0)
	
	--[[ DIFFICULTY LEVEL ]]
	-- gets the difficulty level from the UI and passes it into the function
	Rule_SetDifficultyLevel( Difficulty_Get() )
	
	g_firstrun = false
	
elseif Event_IsAnyRunning() == false then		
	
	--[[ Get the AI doing whatever after the NIS is over ]]
	Rule_StartAI()
	
	--[[ FOW ]]
	World_EnablePlayerToPlayerFOW(g_Player2, g_Player1, true)
	
	--[[ WIN CHECK ]]
	Rule_AddInterval(Rule_EndGameWin, 1)
	
	--[[ LOSE CHECK ]]
	Rule_AddInterval(Rule_EndGameLose, 1)
	
	--[[ ASSIGN OBJECTIVES ]]
	Rule_AddInterval(Rule_Objective_ClaimTheTitan, 1)
	
	--[[ GENERATE ACTION ]]
	-- Use this space to add all core mission functions
	
	--[[ harassment rules ]]
	g_ig_randattackID = SGroup_CreateIfNotFound("sg_ig_random_attack")
	Rule_AddInterval(Rule_Random_IG_Attack_On_Chaos_Base_Control_Kickoff, 30) 
	
	Rule_AddInterval(Rule_Idle_Defender_Return, 30)
	
	--[[ haven't debugged this one yet - deg ]]
	Rule_AddInterval(Rule_IG_Reaction, 1) 
	
	
	--[[ Clean up ]]
	Rule_Remove(Rule_GameStart)
	
end

end


--[[ DIFFICULTY ]]

function Rule_SetDifficultyLevel( difficultyLevel )

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

Difficulty_SetForPlayer( g_Player3, 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
	
	--Cpu_SetDifficulty( g_Player2, AD_Standard )
	
-- medium
elseif difficultyLevel == DIFFICULTY_NORMAL then
	
-- hard
elseif difficultyLevel == DIFFICULTY_HARD then
	
end

--[[ PLAYER MODIFIERS ]]
--CHAOS LORD
local mod_crullarmourincrease = Modifier_Create(MAT_EntityType, "armour_modifier", MUT_Multiplication, false, 5, "chaos_squad_lord")
Modifier_ApplyToPlayer( mod_crullarmourincrease, g_Player1)
local mod_crullhealthincrease = Modifier_Create(MAT_EntityType, "health_maximum_modifier", MUT_Multiplication, false, 5, "chaos_squad_lord")
Modifier_ApplyToPlayer( mod_crullhealthincrease, g_Player1)	
--TAINTED PSYKER
local mod_psykerarmourincrease = Modifier_Create(MAT_EntityType, "armour_modifier", MUT_Multiplication, false, 3, "guard_leaders_psyker_sp_mdc5")
Modifier_ApplyToPlayer( mod_psykerarmourincrease, g_Player1)
local mod_psykerhealthincrease = Modifier_Create(MAT_EntityType, "health_maximum_modifier", MUT_Multiplication, false, 3, "guard_leaders_psyker_sp_mdc5")
Modifier_ApplyToPlayer( mod_psykerhealthincrease, g_Player1)	
--[[ Titan weapon recharge ]]
local mod_rechargerate = Modifier_Create(MAT_EntityType, "ability_recharge_modifier", MUT_Multiplication, false, 15, "spo_05_titan_target_weapon_01")
Modifier_ApplyToPlayer( mod_rechargerate, g_Player1)

--[[ IMPERIAL GUARD ]]
local mod_kasrkinweaponrange = Modifier_Create(MAT_WeaponType, "max_range_weapon_modifier", MUT_Multiplication, false, .6, "guard_hellgun_kasrkin")
Modifier_ApplyToPlayer( mod_kasrkinweaponrange, g_Player2)
local mod_kasrkinweapondamage = Modifier_Create(MAT_WeaponType, "max_damage_weapon_modifier", MUT_Multiplication, false, .7, "guard_hellgun_kasrkin")
Modifier_ApplyToPlayer( mod_kasrkinweapondamage, g_Player2)
local mod_kassargweaponrange = Modifier_Create(MAT_WeaponType, "max_range_weapon_modifier", MUT_Multiplication, false, .5, "guard_hellgun_kasrkin_sergeant")
Modifier_ApplyToPlayer( mod_kassargweaponrange, g_Player2)

--[[ Slow Down the Necrons ]]
local mod_monolithspeed = Modifier_Create(MAT_EntityType, "speed_maximum_modifier", MUT_Multiplication, false, .7, "necron_monolith")
Modifier_ApplyToPlayer( mod_monolithspeed, g_Player3)

end


--[[ AI ]]

function Rule_StartAI()

-- Cpu_EnableAll(false)

end


--[[ CORE GAME ]]

function Rule_Timer() if g_time == nil then g_time = 0 end g_time = g_time+1 end

function Rule_FOW_Reset() FOW_Reset() end


--[[ Player Army Generation ]]

--[[ Kicks off player army ]] function Rule_Player_Army_Kickoff()

end

--[[ Tracks Crull ]] function Rule_Crull_Track() local blueprinttable = Util_MakeBlueprintTable("chaos_squad_lord") --[[ check to see if the group is empty AND if the boolean has been returned to false - this prevents duplicate rule adds ]] if g_crullreturn ~= true and SGroup_Exists("sg_crull") and (SGroup_IsEmpty("sg_crull") or SGroup_ContainsBlueprints( "sg_crull", blueprinttable, false) == false) then --[[ prevents duplicate rule adds ]] g_crullreturn = true --[[ 6 second delay, keeps it from being instantaneous ]] Rule_AddOneShot(Rule_Crull_Return, 6) end end

function Rule_Crull_Return()

--[[ recreate the unit ]]
Util_CreateSquadsAtMarker(g_Player1, "sg_crull", "chaos_squad_lord", "mkr_chaos_origin1", 1)
--[[ play the fx ]]
World_FXEventSquad("data:Art/Events/Unit_Upgrade_Morale_FX/Reinforce_Trooper", SGroup_FromName("sg_crull"))
--[[ reset the flag ]]
g_crullreturn = false
--[[ if no messages have played recently, play the Intel Event - this keeps messages from flooding the player ]]
if Event_TimeSinceLast() > 10 then
	Util_StartIntel(EVENTS.IE_Chaos_ImBack)
end
EventCue_DoEvent( "recruit_commander", "/Races/Shared/Upgrade_weapon", "$42890", "$42892" )

end

--[[ replaces the psycker when he dies ]] function Rule_Psyker_Track()

local blueprinttable = Util_MakeBlueprintTable("guard_squad_psyker_sp_msdc5", "chaos_squad_sorcerer")

if g_psykerreturn ~= true and SGroup_Exists("sg_tainted_psyker") 
and ( SGroup_IsEmpty("sg_tainted_psyker") or SGroup_ContainsBlueprints( "sg_tainted_psyker", blueprinttable, false) == false ) then		
	g_psykerreturn = true
	if g_psykerswap ~= true then
		Rule_AddOneShot(Rule_Psyker_Return, 6)
		Rule_AddOneShot(Rule_Psyker_BeaconCreate, 6)
	else
		Rule_AddOneShot(Rule_Sorcerer_Return, 6)
		Rule_AddOneShot(Rule_Psyker_BeaconCreate, 6)
	end
end

end

function Rule_Psyker_Return()

Util_CreateSquadsAtMarker(g_Player1, "sg_tainted_psyker", "guard_squad_psyker_sp_msdc5", "mkr_sorceror_origin1", 1) 
World_FXEventSquad("data:Art/Events/Unit_Upgrade_Morale_FX/Reinforce_Trooper", SGroup_FromName("sg_tainted_psyker"))
Cmd_SetStance("sg_tainted_psyker", STANCE_CeaseFire)
g_psykerreturn = false
if Event_TimeSinceLast() > 10 then
	Util_StartIntel(EVENTS.IE_Psyker_ImBack)
end
EventCue_DoEvent( "recruit_commander", "/Races/Shared/Upgrade_weapon", "$42890", "$42892" )

end

function Rule_Sorcerer_Return()

Util_CreateSquadsAtMarker(g_Player1, "sg_tainted_psyker", "chaos_squad_sorcerer", "mkr_sorceror_origin1", 1) 
World_FXEventSquad("data:Art/Events/Unit_Upgrade_Morale_FX/Reinforce_Trooper", SGroup_FromName("sg_tainted_psyker"))
Cmd_SetStance("sg_tainted_psyker", STANCE_CeaseFire)
g_psykerreturn = false
if Event_TimeSinceLast() > 10 then
	Util_StartIntel(EVENTS.IE_Sorcerer_ImBack)
end
EventCue_DoEvent( "recruit_commander", "/Races/Shared/Upgrade_weapon", "$42890", "$42892" )

end

--[[ COUNTERS ]] --[[ count of sacrifices ]] function Rule_Sacrifice_Counter_Display() UI_ShowCount("cnt_sacrifice_number", g_Player1, 900900, 0) end --[[ count of titan pieces captured ]] function Rule_Piece_Capture_Display() UI_ShowCount("cnt_pieces_captured", g_Player1, 900902, 0) end

function Rule_Sacrifice_KillSacrificeSquad()

if SGroup_Exists("_sg_sacrificesquad") and SGroup_IsEmpty("_sg_sacrificesquad") == false then
	SGroup_DestroyAllSquads("_sg_sacrificesquad")
end

Button_SetEnabled(g_btn_captureguardID, true)

end

--[[ this function looks to track number of guard killed and do the actual killing - deg ]] function Rule_Sacrifice_Mechanic()

--[[ this tracks who is within the sacrifice area]]
if g_bodycount <= 5 and SGroup_Exists("sg_Guardsmen") and SGroup_IsEmpty("sg_Guardsmen") == false 
and Button_GetEnabled(g_btn_captureguardID)
and Prox_AnySquadNearMarker("sg_Guardsmen", "mkr_kill_area1") then
	Button_SetEnabled(g_btn_captureguardID, false)
	Sound_Play( "Single_player/Blood_pit/Blood_pit_bubble" )
	
	SGroup_AddGroup(SGroup_CreateIfNotFound("_sg_sacrificesquad"), "sg_Guardsmen")
	SGroup_Clear(SGroup_FromName("sg_Guardsmen"))
	Cmd_StopSquads("_sg_sacrificesquad")
	Anim_PlaySGroupAnim(SGroup_FromName("_sg_sacrificesquad"), "sp_sacrifice")
	Rule_Check_AddOneShot(Rule_Sacrifice_KillSacrificeSquad, 10)
	
	g_bodycount = g_bodycount + 1
	UI_ShowCountUpdate("cnt_sacrifice_number", g_bodycount)
	
	Sound_PlayStinger("stinger_msd5c_sacrificingforglory")	
	
end	

if g_bodycount >= 1 and g_first_sacrifice == nil then
	g_first_sacrifice = true
	--[[ Autosave ]]
	Rule_AddIntervalDelay(Rule_Autosave_Sacrificed1stSquad, 1, 5)
end

if g_bodycount >= 2 and g_ultramarine_appearance == false then
	g_ultramarine_appearance = true
--	Rule_AddInterval(Rule_Deploy_Ultramarines, 3) - removed the function - deg
end

if g_bodycount >= 4 and g_necron_appearance == false then
	
	--[[ Autosave ]]
	Rule_AddIntervalDelay(Rule_Autosave_AlmostThere, 1, 5)
	
	g_necron_appear_flag = true
	
	--[[ Starts Necron attack! ]]
	local rand = World_GetRand(10, 40)
	Rule_AddOneShot(Rule_Necron_Army_Kickoff, rand) 
	
	g_necron_appearance = true
end

if g_bodycount >= 6 and g_necron_appearance == true then
	
	--[[ Autosave ]]
	Rule_AddIntervalDelay(Rule_Autosave_PossessTitan, 1, 5)
	
	--[[ this is the complete variable for the Sacrifice Objective ]]
	g_obj_sacrificeguard = true 
	
	--[[ Clean up ]]
	UI_HideCount("cnt_sacrifice_number")
	Rule_Remove(Rule_Sacrifice_Mechanic)
	
	--[[ remove the guard capture button ]]
	Rule_Check_Remove(Rule_Capture_Button_Click)
	Rule_Check_Remove(Rule_Captured_Guardsman_Control)
	Button_SetVisible(g_btn_captureguardID, false)
	Util_SGroupAbilityButton_Remove(g_btn_captureguardID)
	
	--[[ add the titan capture stuff ]]
	Rule_AddOneShot(Rule_Capture_Button2, 0)
	Rule_AddInterval(Rule_Piece_Capture, 2)
	Rule_AddOneShot(Rule_Piece_Capture_Display, 2)
	
end

end

--[[ Imperial Army Generation ]]

function Rule_Imperial_Guard_Army_Kickoff()

local tableresearch = {
	"guard_upgrade_guardsmen_health", 
	"guard_upgrade_guardsmen_range", 
	"guard_guardsman_morale", 
}
for i = 1, table.getn(tableresearch) do
	Player_GrantResearch( g_Player2, tableresearch[i])
end

EGroup_ForceAddOn( "eg_depot_listening_post", "addon_guard_list_post_2")

g_sgroup_titan_defenders = SGroup_CreateIfNotFound("sg_titan_defenders")
g_sg_randattackID = SGroup_CreateIfNotFound("sg_ig_random_attack")
g_sg_allinfantryID = SGroup_CreateIfNotFound("sg_ig_allinfantry")
g_sg_vehiclesID = SGroup_CreateIfNotFound("sg_ig_vehicles")

for i = 1, 12 do
	local rand = World_GetRand(5, 8)
	t_sgroup_IG_defenders[i] = Util_CreateSquadsAtMarkerEx(g_Player2, "sg_titan_defender"..i, "guard_squad_guardsmen", "mkr_imperial_guard_perimeter"..i, 1, rand)
	SGroup_AddGroup(g_sgroup_titan_defenders, t_sgroup_IG_defenders[i])
	SGroup_AddGroup(g_sg_allinfantryID, t_sgroup_IG_defenders[i])
end

--[[ Generic Barracks Defenders ]]
local table1 =  {
	name = {"lemanruss", "hellhound", "commissar", "chimera"},
	blue = {"guard_squad_lemanruss", "guard_squad_hellhound", "guard_squad_commissar", "guard_squad_chimera", },
	source = {"imperial_guard_last_stand", "imperial_guard_last_stand", "commissar_spawn", "chimera_spawn", },
}
for i = 1, 4 do
	for y = 1, table.getn(table1.name) do
		local sgroupID = Util_CreateSquadsAtMarker(g_Player2, "sg_"..table1.name[y]..i, table1.blue[y], "mkr_"..table1.source[y]..i, 1) 
		SGroup_AddGroup(g_sg_vehiclesID, sgroupID)
		Cmd_MoveToMarker("sg_"..table1.name[y]..i, "mkr_"..table1.source[y]..i)
	end
end

--[[ Weapons Depot Defenders ]]
local table2 =  {
	name = {"baneblade", "basilisk1", "basilisk2", "depot_infantry_kasrkin", "sniper"},
	blue = {"guard_squad_baneblade", "guard_squad_basilisk", "guard_squad_basilisk", "guard_squad_kasrkin", "guard_squad_assassin", },
	source = {"IG_tanks", "rooftop_basilisk1", "rooftop_basilisk2", "IG_weapons_depot", "rooftop_sniper1", },
}
for y = 1, table.getn(table2.name) do
	Util_CreateSquadsAtMarker(g_Player2, "sg_"..table2.name[y], table2.blue[y], "mkr_"..table2.source[y], 1) 
	Cmd_MoveToMarker("sg_"..table2.name[y], "mkr_"..table2.source[y])
end

for i = 1, 3 do
	if EGroup_Exists("eg_production"..i) then
		EGroup_AddGroup(EGroup_CreateIfNotFound("eg_barracks"), EGroup_FromName("eg_production"..i))
	end
end

Rule_AddInterval(Rule_Imperial_Guard_ActionStart, 1)

end

--[[ WAITS FOR THE OPENING NIS TO FINISH ]] function Rule_Imperial_Guard_ActionStart()

if Event_IsAnyRunning() == false then
	Rule_AddInterval(Rule_Imperial_Guard_Army_Track, 10)
	Rule_AddInterval(Rule_Guard_PostReOutfit, 17)
	Rule_AddInterval(Rule_Imperial_Guard_EmergencyTrack, 15)
	
	--[[ test cheat ]]

-- Rule_AddInterval(Rule_Cheat_CeaseFireGuard, 15)

	Rule_AddInterval(Rule_IG_Vehicle_Track, 45)
	Rule_AddInterval(Rule_IG_Vehicle_AttackTrigger, 5)
	
	Rule_Remove(Rule_Imperial_Guard_ActionStart)
end

end

--[[ cheat to facilitate testing ]] function Rule_Cheat_CeaseFireGuard()

SGroup_AddGroup(SGroup_CreateIfNotFound("sg_cheat_dontshoot"), Player_GetSquads(g_Player2))
Cmd_SetStance("sg_cheat_dontshoot", STANCE_CeaseFire)

end

--[[ VEHICLE BEHAVIOR ]]

--[[ this will send new vehicles out to replace those that have been destroyed ]] function Rule_IG_Vehicle_Track()

--[[ Generic Barracks Defenders ]]
local table1 =  {
	name = {"lemanruss", "hellhound", "chimera"},
	blue = {"guard_squad_lemanruss", "guard_squad_hellhound", "guard_squad_chimera", },
	source = {"imperial_guard_last_stand", "imperial_guard_last_stand", "chimera_spawn", },
}

if EGroup_Exists("eg_weapons_depot_structures") and EGroup_IsEmpty("eg_weapons_depot_structures") == false then
	for i = 1, 4 do
		if EGroup_Exists("eg_production"..i) and EGroup_IsEmpty("eg_production"..i) == false then
			for y = 1, table.getn(table1.name) do
				if SGroup_Exists("sg_"..table1.name[y]..i) == false or SGroup_IsEmpty("sg_"..table1.name[y]..i) then
					local sgroupID = Util_CreateSquadsAtMarker(g_Player2, "sg_"..table1.name[y]..i, table1.blue[y], "mkr_IG_weapons_depot", 1) 
					SGroup_AddGroup(g_sg_vehiclesID, sgroupID)
					Cmd_AttackMoveMarker("sg_"..table1.name[y]..i, "mkr_"..table1.source[y]..i)
					break
				end
			end
		end
	end
elseif EGroup_Exists("eg_weapons_depot_structures") == false or EGroup_IsEmpty("eg_weapons_depot_structures") then
	g_obj_destroydepot = true
	Rule_Remove(Rule_IG_Vehicle_Track)
end

end

--[[ VEHICLE ASSAULT ]] function Rule_IG_Vehicle_AttackTrigger() local table1 = {{ name = "chaos_machine_pit", count = 1 }} if EGroup_ContainsBlueprints(Player_GetEntities(g_Player1), table1, false) then Rule_AddIntervalDelay(Rule_IG_Vehicle_Attack, 35, 60) Rule_Remove(Rule_IG_Vehicle_AttackTrigger) end

end

--[[ VEHICLE ASSAULT ]] function Rule_IG_Vehicle_Attack()

if SGroup_IsEmpty("sg_ig_vehicles") then
	Rule_Remove(Rule_IG_Vehicle_Attack)
end

local rand = World_GetRand(1, 3) 
if g_vehicles_attackedlast == true then
	g_vehicles_attackedlast = false
elseif rand < 3 and (SGroup_Exists("sg_ig_vehicleattack") == false or SGroup_IsEmpty("sg_ig_vehicleattack")) then
	
	
	local count = SGroup_CountSpawned(g_sg_vehiclesID)
	if count > 0 then
		local rand = World_GetRand(1, count)
		local squadID = SGroup_GetSpawnedSquadAt(g_sg_vehiclesID, rand)
		SGroup_Add(SGroup_CreateIfNotFound("sg_ig_vehicleattack"), squadID)
		
		if EGroup_Exists("eg_chaos_hq") and EGroup_IsEmpty("eg_chaos_hq") == false then
			local pos = EGroup_GetPosition(EGroup_FromName("eg_chaos_hq"))
			Cmd_AttackMovePos("sg_ig_vehicleattack", pos)
		end
		
		g_vehicles_attackedlast = true
	end
	
else
end

end

function Rule_Guard_PostReOutfit() --make a utility group local sgroupID_outfit = SGroup_CreateIfNotFound("_sg_outfit") SGroup_Clear(sgroupID_outfit) --check the outpost group local sgroupID = SGroup_FromName("sg_ig_allinfantry") local count = SGroup_CountSpawned(sgroupID) -- if the outpost group is not empty if count > 0 then for i = 1, count do -- we want a random squad out of the group local randsquad = World_GetRand(1, count) -- there is a chance this will crash local squadID = SGroup_GetSpawnedSquadAt(sgroupID, randsquad)

		if Squad_GetPlayerOwner(squadID) == g_Player2 then
			-- add it to the group cause somethings are easier to do to a sgroup
			SGroup_Add(sgroupID_outfit, squadID)
			--check to see if there is a sergeant
			--check to see if they have any weapons
			if Squad_WeaponCount(squadID, "guard_grenade_launcher_guardsmen") == 0 and Squad_WeaponCount(squadID, "guard_plasma_gun_guardsmen") == 0 then
				local weapons = {"guard_grenade_launcher_guardsmen", "guard_plasma_gun_guardsmen", "guard_grenade_launcher_guardsmen"}
				local randweapon = World_GetRand(1, 2)
				Squad_ForceUpgradeWeapons(squadID, weapons[randweapon], randweapon)
				SGroup_Clear(sgroupID_outfit)
				break
			end
			--reinforce
			Cmd_ReinforceTrooper("_sg_outfit", 1)
		end
	end
end

if SGroup_IsEmpty("sg_ig_allinfantry") then
	Rule_Remove(Rule_Guard_PostReOutfit)
end

end

--[[ Replenishes the Guardsmen at the outposts ]] function Rule_Imperial_Guard_Army_Track() --[[ difficulty handle - multiply value by 10 for number of seconds of delay ]] g_guardrestock = 42

local source = {1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3}

-- print("restock") for i = 1, 12 do if t_restockcount[i] == 0 and EGroup_IsEmpty( "eg_production"..source[i]) == false then if SGroup_IsEmpty("sg_titan_defender"..i) then local rand = World_GetRand(5, 8) local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player2, "sg_titan_defender"..i, "guard_squad_guardsmen", "mkr_imperial_guard_last_stand"..source[i], 1, rand) SGroup_AddGroup(g_sg_allinfantryID, sgroupID) Cmd_MoveToMarker("sg_titan_defender"..i, "mkr_imperial_guard_perimeter"..i) t_restockcount[i] = g_guardrestock break end elseif t_restockcount[i] > 0 and SGroup_IsEmpty("sg_titan_defender"..i) then t_restockcount[i] = t_restockcount[i]-1 -- print(t_restockcount[i]) else -- print(t_restockcount[i]) end end

if EGroup_IsEmpty("eg_barracks") then
	Rule_Remove(Rule_Imperial_Guard_Army_Track)
end

end

--[[ EMERGENCY SUPPLY IF THE PLAYER KILLS ALL THE OTHER ONES ]] function Rule_Imperial_Guard_EmergencyTrack()

--[[ table of markers to be used as the seed locations for the random drop sites ]]
local table1 = {"mkr_ig_rally1", "mkr_ig_rally2", "mkr_ig_rally3", "mkr_ig_rally4"}

--[[ list of criteria before a drop is called ]]
if EGroup_IsEmpty("eg_barracks") and g_onitsway ~= true 
and ( SGroup_Exists("sg_ig_dropship") == false or SGroup_IsEmpty("sg_ig_dropship") ) 
and ( SGroup_Exists("sg_emergency_defender") == false or SGroup_IsEmpty("sg_emergency_defender") ) then
	
	--[[ grab a random marker, translate into a pos and get a random pos based on that ]]
	local rand1 = World_GetRand(1, table.getn(table1))
	local randx = World_GetRand(-30, 30)
	local randz = World_GetRand(-30, 30)
	local pos = Marker_GetPosition(Marker_FromName(table1[rand1], "basic_marker"))
	pos.x = pos.x+randx
	pos.z = pos.z+randz
	g_droppos = pos
	
	g_onitsway = true
	--[[ call the drop a variable number of seconds from now ]]
	local rand2 = World_GetRand(10, 35)
	Rule_AddOneShot(Rule_IG_EmergencyDrop_Land, rand2)
	
end

end

--[[ the drop ship comes in ]] function Rule_IG_EmergencyDrop_Land()

--[[ create the drop ship ]]
local sgroupID  = Util_CreateSquadsAtPosition(g_Player2, "sg_ig_dropship", "npc_valkyrie", g_droppos, 1)
Anim_PlaySGroupAnim(sgroupID, "sp_land")
SGroup_SetHealthInvulnerable("sg_ig_dropship", true)

--[[ reveal and ping the location ]]
FOW_RevealArea(g_droppos.x, g_droppos.z, 20, 45)
Util_Ping_LoopingPos("png_emergency", g_droppos)

g_onitsway = false
Rule_AddOneShot(Rule_IG_EmergencyDrop_Deploy, 10)

end

--[[ generate some guardsmen ]] function Rule_IG_EmergencyDrop_Deploy()

for i = 1, 3 do
	local rand = World_GetRand(4, 8)
	local sgroupID = Util_CreateSquadsAtPositionEx(g_Player2, "sg_emergency_defender", "guard_squad_guardsmen", g_droppos, 1, rand)
	
	Cmd_AttackEGroup("sg_emergency_defender", "eg_chaos_hq")
end

Rule_AddOneShot(Rule_IG_EmergencyDrop_TakeOff, 15)

end

--[[ drop ship takes off ]] function Rule_IG_EmergencyDrop_TakeOff()

Anim_PlaySGroupAnim(SGroup_FromName("sg_ig_dropship"), "sp_take_off")

Rule_AddOneShot(Rule_IG_EmergencyDrop_Remove, 10)

end

--[[ clean up ]] function Rule_IG_EmergencyDrop_Remove()

Util_Ping_Stop("png_emergency")
SGroup_DeSpawn("sg_ig_dropship")
SGroup_DestroyAllSquads("sg_ig_dropship")

end


--[[ This is to show the commissars moving into the Chimeras, to let the player know they are inside. ]] function Rule_Commissar_Warning()

Rule_AddOneShot(Rule_Commissar_Board, 13)

end

--[[ puts the commissars inside their chimeras ]] function Rule_Commissar_Board()

for i = 1, 3 do
	if SGroup_IsEmpty("sg_commissar"..i) == false and SGroup_IsEmpty("sg_chimera"..i) == false then
		Cmd_EnterTransport("sg_commissar"..i, "sg_chimera"..i) 
	end
end

end

function Rule_IG_Reaction() -- Determines IG behaviour when a tainted psyker comes nearby. At first nothing happens, but after the 3rd capture they start actively attacking the psyker -- As more guardsmen are sacrificed, the more units that get sent to attack the player

if g_bodycount >= 3 then -- won't start any of this until 3 squads are sacrificed

	
	t_IG_Reaction_Units = {
		commissars = {"sg_commissar1", "sg_commissar1", "sg_commissar1", "sg_commissar1", "sg_commissar2", "sg_commissar2", "sg_commissar2", "sg_commissar2", "sg_commissar3", "sg_commissar3", "sg_commissar3", "sg_commissar3"},
		chimeras = {"sg_chimera1", "sg_chimera1", "sg_chimera1", "sg_chimera1", "sg_chimera2", "sg_chimera2", "sg_chimera2", "sg_chimera2", "sg_chimera3", "sg_chimera3", "sg_chimera3", "sg_chimera3"}
		}
		
	
	for i = 1, 12 do

		if SGroup_Exists("sg_titan_defender"..i) and SGroup_IsEmpty("sg_titan_defender"..i) == false then
			local guardpos = SGroup_GetPosition(SGroup_FromName("sg_titan_defender"..i))
			
			if SGroup_Exists("sg_tainted_psyker") and SGroup_IsEmpty("sg_tainted_psyker") == false and SGroup_CountDeSpawned(SGroup_FromName("sg_tainted_psyker")) == 0 then
			
				if World_DistanceSGroupToPoint("sg_tainted_psyker", guardpos, true) <= 25 then
			
					if SGroup_Exists(t_IG_Reaction_Units.commissars[i]) and SGroup_IsEmpty(t_IG_Reaction_Units.commissars[i]) == false then
						Cmd_AttackSGroup(t_IG_Reaction_Units.commissars[i], "sg_tainted_psyker")
					end
			
					if g_bodycount >= 5 then 	
						if SGroup_Exists("sg_titan_defender"..i) and SGroup_IsEmpty("sg_titan_defender"..i) == false then
							Cmd_AttackSGroup("sg_titan_defender"..i, "sg_tainted_psyker")
						end
					end
									
					if g_bodycount >= 6 then 	
						if SGroup_Exists(t_IG_Reaction_Units.chimeras[i]) and SGroup_IsEmpty(t_IG_Reaction_Units.chimeras[i]) == false then
							Cmd_AttackSGroup(t_IG_Reaction_Units.chimeras[i], "sg_tainted_psyker")
						end
					end
				end
			end
		end
	end

end

end

--[[ RANDOM RAID STUFF ]]

function Rule_Random_IG_Attack_On_Chaos_Base_Control_Kickoff() if g_random_ig_attack_on_chaos_base_started == true and (SGroup_Exists("sg_random_IG_attack") == false or (SGroup_Exists("sg_random_IG_attack") and SGroup_IsEmpty("sg_random_IG_attack"))) then local l_random_time = World_GetRand(20, 60)

	Rule_AddOneShot(Rule_Random_IG_Attack_On_Chaos_Base_Control, l_random_time) 
	--g_random_ig_attack_on_chaos_base_started will be made "false" after the control is started, overriding the "true" value next.
	
	g_random_ig_attack_on_chaos_base_started = false
end

end

function Rule_Random_IG_Attack_On_Chaos_Base_Control() -- controlled by g_bodycount, which keeps track of how many squads were sacrificed so far

t_mobsize = { 3, 4, 6, 5}

t_possible_IG_raid_spawns = {"mkr_imperial_guard_last_stand1", "mkr_imperial_guard_last_stand2", "mkr_imperial_guard_last_stand3", "mkr_IG_tanks"}

g_random_spawn = World_GetRand(1, table.getn(t_possible_IG_raid_spawns)) -- need to spawn outside of unit generation so that there is a consistant area the enemies will spawn from

if g_bodycount == 0 then
	if g_random_ig_attack_on_chaos_base_started == false and (SGroup_Exists("sg_random_IG_attack") == false or (SGroup_Exists("sg_random_IG_attack") and SGroup_IsEmpty("sg_random_IG_attack"))) then
		local rand = World_GetRand(5, 10)
		g_mobsize = t_mobsize[1]
		t_ig_random = {
			blue = {"guard_squad_guardsmen", "guard_squad_guardsmen", "guard_squad_guardsmen", "guard_squad_guardsmen", "guard_squad_kasrkin", "guard_squad_guardsmen"}, 
			source = {"mkr_imperial_guard_last_stand1", "mkr_imperial_guard_last_stand2", "mkr_imperial_guard_last_stand3", "mkr_IG_weapons_depot_infantry"},
		}
		
		Rule_AddInterval(Rule_IG_Random_Raid, rand)
		
	end
elseif g_bodycount >= 1 and g_bodycount <= 2 then
	if g_random_ig_attack_on_chaos_base_started == false and (SGroup_Exists("sg_random_IG_attack") == false or (SGroup_Exists("sg_random_IG_attack") and SGroup_IsEmpty("sg_random_IG_attack"))) then
		local rand = World_GetRand(5, 10)
		g_mobsize = t_mobsize[2]
		t_ig_random = {
			blue = {"guard_squad_kasrkin", "guard_squad_guardsmen", "guard_squad_kasrkin", "guard_squad_guardsmen"}, 
			source = {"mkr_imperial_guard_last_stand1", "mkr_imperial_guard_last_stand2", "mkr_imperial_guard_last_stand3", "mkr_IG_weapons_depot_infantry"},
		}
		
		Rule_AddInterval(Rule_IG_Random_Raid, rand)
		
	end
elseif g_bodycount >= 3 and g_bodycount <= 4 then
	if g_random_ig_attack_on_chaos_base_started == false and (SGroup_Exists("sg_random_IG_attack") == false or (SGroup_Exists("sg_random_IG_attack") and SGroup_IsEmpty("sg_random_IG_attack"))) then
		local rand = World_GetRand(5, 10)
		g_mobsize = t_mobsize[3]
		t_ig_random = {
			blue = {"guard_squad_guardsmen", "guard_squad_kasrkin", "guard_squad_guardsmen", "guard_squad_kasrkin", "guard_squad_guardsmen", "guard_squad_ogryns", "guard_squad_guardsmen"}, 
			source = {"mkr_imperial_guard_last_stand1", "mkr_imperial_guard_last_stand2", "mkr_imperial_guard_last_stand3", "mkr_IG_weapons_depot_infantry"},
		}
		
		Rule_AddInterval(Rule_IG_Random_Raid, rand)
		
	end	
elseif g_bodycount >= 5 then
	if g_random_ig_attack_on_chaos_base_started == false and (SGroup_Exists("sg_random_IG_attack") == false or (SGroup_Exists("sg_random_IG_attack") and SGroup_IsEmpty("sg_random_IG_attack"))) then
		local rand = World_GetRand(5, 10)
		g_mobsize = t_mobsize[4]
		t_ig_random = {
			blue = {"guard_squad_ogryns", "guard_squad_guardsmen", "guard_squad_kasrkin", "guard_squad_ogryns", "guard_squad_guardsmen", "guard_squad_kasrkin", "guard_squad_kasrkin", "guard_squad_ogryns"}, 
			source = {"mkr_imperial_guard_last_stand1", "mkr_imperial_guard_last_stand2", "mkr_imperial_guard_last_stand3", "mkr_IG_weapons_depot_infantry"},
		}
		
		Rule_AddInterval(Rule_IG_Random_Raid, rand)
		
	end	
end

end

--[[ the new RAID function - deg ]] function Rule_IG_Random_Raid()

--[[ checks to see if the production facilities exist in the first place ]]
if EGroup_Exists("eg_production"..g_random_spawn) and EGroup_IsEmpty("eg_production"..g_random_spawn) == false then 
	
	if SGroup_Count(g_ig_randattackID) < g_mobsize  then
		local rand1 = World_GetRand(1, table.getn(t_ig_random.blue))
		local rand2 = World_GetRand(3, 6)
		local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player2, "sg_ig_random_attack"..g_time, t_ig_random.blue[rand1], t_ig_random.source[g_random_spawn], 1, rand2)
		SGroup_AddLeaders("sg_ig_random_attack"..g_time)
		SGroup_AddGroup(g_sg_randattackID, sgroupID)
		SGroup_AddGroup(g_sg_allinfantryID, sgroupID)
		Cmd_MoveToMarker("sg_ig_random_attack", "mkr_ig_rally"..g_random_spawn)
		
	elseif SGroup_Count(g_ig_randattackID) >= g_mobsize  then
		
		if EGroup_Exists("eg_chaos_hq") and EGroup_IsEmpty("eg_chaos_hq") == false then
			local pos = EGroup_GetPosition(EGroup_FromName("eg_chaos_hq"))
			Cmd_AttackMovePos("sg_ig_random_attack", pos)
		end
		g_random_ig_attack_on_chaos_base_started = true		
		Rule_Remove(Rule_IG_Random_Raid)
		
	end
	
--[[ if the barracks is broken, go back ]]
elseif EGroup_Exists("eg_production"..g_random_spawn) and EGroup_IsEmpty("eg_production"..g_random_spawn) then
	g_random_ig_attack_on_chaos_base_started = true
	Rule_Remove(Rule_IG_Random_Raid)
end

end


--[[ NECRONS ]]

--[[ Necron Army Generation ]]

function Rule_Necron_Army_Kickoff() if g_necron_appear_flag == true then

	g_warrior_num = 2
	g_sgroup_monolith_list = SGroup_CreateIfNotFound("sg_monoliths")
	
	World_EnablePlayerToPlayerFOW(g_Player1, g_Player3, false)
	
	--[[ call in rest of monoliths ]]
	Rule_AddIntervalEx(Rule_Necron_Army_Creation, 65, 5)
	
	--[[ trigger the nis ]]
	Util_StartNIS(EVENTS.NIS_Mid_NecronsArrive)
	
end

end

function Rule_Necron_Army_Creation()

for i = 1, 4 do
	if SGroup_Exists("sg_necron_monolith"..i) == false then
		t_sgroup_monoliths[i] = Util_CreateSquadsAtMarker(g_Player3, "sg_necron_monolith"..i, "npc_necron_monolith", "mkr_necron_origin"..i, 1)
		Cmd_SetStance("sg_necron_monolith"..i, STANCE_CeaseFire )
		SGroup_AddGroup(g_sgroup_monolith_list, t_sgroup_monoliths[i])
		
		Anim_PlaySGroupAnim(t_sgroup_monoliths[i], "land")
		
		break
	end
end	

end

function Rule_Necron_Army_Track() for i = 1, 4 do if SGroup_Exists("sg_necron_monolith"..i) and SGroup_IsEmpty("sg_necron_monolith"..i) == false then local pos = SGroup_GetPosition( t_sgroup_monoliths[i]) if SGroup_Exists("sg_necron_attackers"..i) == false or SGroup_Count(SGroup_FromName("sg_necron_attackers"..i)) < g_warrior_num then local sgroupID = Util_CreateSquadsAtPositionEx(g_Player3, "sg_necron_attackers"..g_time, "npc_necron_warrior", pos, 1, 7) World_FXEventSquad("data:Art/Events/Necron/appear_fx", sgroupID) SGroup_AddGroup(SGroup_CreateIfNotFound("sg_necron_attackers"..i), sgroupID) Cmd_SetStance("sg_necron_attackers"..g_time, STANCE_Hold ) Cmd_AttackMoveMarker("sg_necron_attackers"..i, "mkr_chaos_base") break end end end end

function Rule_Monolith_Advance() for i = 1, 4 do if SGroup_Exists("sg_necron_monolith"..i) and SGroup_IsEmpty("sg_necron_monolith"..i) == false then Cmd_MoveToMarker("sg_necron_monolith"..i, "mkr_monolith_destination"..i.."a") end end end

--[[ THE PINGS ]] --OUTPOSTS function Rule_Outpost_Pings() t_infantryPings = {egroup = {}, ping = {}} for i = 1, 3 do if EGroup_Exists("eg_production"..i) and EGroup_IsEmpty("eg_production"..i) == false then Util_Ping_LoopingMkr("ping_outpost"..i, "mkr_outpost"..i) table.insert(t_infantryPings.egroup, "eg_production"..i) table.insert(t_infantryPings.ping, "ping_outpost"..i) end end Rule_AddInterval(Rule_Stop_Outpost_Pings, 2) end

function Rule_Stop_Outpost_Pings() local count = table.getn(t_infantryPings.egroup) if count == 0 then Rule_Remove(Rule_Stop_Outpost_Pings) else for i = count, 1, -1 do if g_obj_sacrificeguard == true or EGroup_IsEmpty(t_infantryPings.egroup[i]) then Util_Ping_Stop(t_infantryPings.ping[i]) table.remove(t_infantryPings.egroup, i) table.remove(t_infantryPings.ping, i) end end end end

--TITAN WEAPONS function Rule_Titan_Weapon_Pings() t_titanPings = {egroup = {}, ping = {}, state = {}} t_objtitanings = {} for i = 1,6 do if EGroup_Exists("eg_titan_heavy_weapons"..i) and EGroup_IsEmpty("eg_titan_heavy_weapons"..i) == false then Util_Ping_LoopingMkr("ping_heavy_weapon"..i, "mkr_heavy_weapon"..i) table.insert(t_titanPings.egroup, "eg_titan_heavy_weapons"..i) table.insert(t_titanPings.ping, "ping_heavy_weapon"..i) table.insert(t_titanPings.state, false)

		t_objtitanings[i] = Objective_PingMarker(Objective_Take_Over_Titan_Pieces.title_id, "mkr_heavy_weapon"..i, true, "default")
		
	end
end
Rule_AddInterval(Rule_Stop_Titan_Weapon_Pings, 2)

end

function Rule_Stop_Titan_Weapon_Pings() local count = table.getn(t_titanPings.egroup) if count == 0 then Rule_Remove(Rule_Stop_Titan_Weapon_Pings) else for i = count, 1, -1 do if t_titanPings.state[i] == true or EGroup_IsEmpty(t_titanPings.egroup[i]) then Util_Ping_Stop(t_titanPings.ping[i]) table.remove(t_titanPings.egroup, i) table.remove(t_titanPings.ping, i) table.remove(t_titanPings.state, i)

			Objective_PingRemove(Objective_Take_Over_Titan_Pieces.title_id, t_objtitanings[i])
			table.remove(t_objtitanings, i)
			
		end
	end
end

end


--[[ Guardsmen Capture button]]

function Rule_Capture_Button()

t_capture_button = {
	button_icon = {"Scar_buttons/capture_guards", "Scar_buttons/capture_guards", "Scar_buttons/capture_guards"},
	button_description = {"$900904", "$900906"}, 
}

g_btn_captureguardID = Util_AbilityButton_CreateModal(t_capture_button.button_icon, t_capture_button.button_description, true)
Button_SetModalInstruction(g_btn_captureguardID, "$900917")

Util_SGroupAbilityButton_Add2Manager(g_btn_captureguardID, "sg_tainted_psyker")

Rule_AddInterval(Rule_Capture_Button_Click, 1)
Rule_AddInterval(Rule_Captured_Guardsman_Control, 1)

end

function Rule_Capture_Button_Click()

--[[ CAPTURE DISTANCE - difficulty hookup ]]
g_capture_distance = 35

if Button_GetPressed(g_btn_captureguardID) == true then  
	SGroup_Clear(SGroup_CreateIfNotFound("sg_Guardsmen_Potentials")) 
	Button_GetPressedSquad(g_btn_captureguardID, SGroup_FromName("sg_Guardsmen_Potentials"))
	
	--[[ this makes sure that the sorcerer squad hasn't gotten destroyed or been despawned before capturing the guards]]
	if SGroup_IsEmpty("sg_Guardsmen_Potentials") == false 
	and SGroup_Exists("sg_tainted_psyker") and SGroup_IsEmpty("sg_tainted_psyker") == false 
	and SGroup_CountDeSpawned(SGroup_FromName("sg_tainted_psyker")) == 0 then
		
		--[[this is the position of where the button is pressed in the game world]]
		local pos1 = SGroup_GetPosition(SGroup_FromName("sg_Guardsmen_Potentials"))
		local pos2 = SGroup_GetPosition(SGroup_FromName("sg_tainted_psyker"))
		
		SGroup_FaceSGroup("sg_tainted_psyker", "sg_Guardsmen_Potentials")
		Anim_PlaySGroupAnim( SGroup_FromName( "sg_tainted_psyker"), "special_attack_1_sp" )
		
		if g_captured == false 
		and Squad_GetBlueprintName(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Guardsmen_Potentials"), 1)) == "guard_squad_guardsmen" 
		and Squad_HasLeader(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Guardsmen_Potentials"), 1)) == false 
		and World_DistancePointToPoint(pos1, pos2) < g_capture_distance then 
			
			SGroup_AddGroup(SGroup_CreateIfNotFound("sg_Guardsmen"), SGroup_FromName("sg_Guardsmen_Potentials"))
			
			World_FXEventSquad("data:Art/Events/Unit_Upgrade_Morale_FX/Reinforce_Trooper", SGroup_FromName("sg_Guardsmen"))
			SGroup_SetPlayerOwner("sg_Guardsmen", g_Player4)
			--Util_StartIntel(EVENTS.IE_Guardsmen_Captured)
			g_captured = true
			
		elseif g_captured == true then
			
			UIWarning_Show("$900920")
			
		elseif Squad_GetBlueprintName(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Guardsmen_Potentials"), 1)) == "guard_squad_guardsmen" 
		and World_DistancePointToPoint(pos1, pos2) > g_capture_distance then
			
			UIWarning_Show("$900914")
			
		elseif Squad_GetBlueprintName(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Guardsmen_Potentials"), 1)) ~= "guard_squad_guardsmen" 
		or Squad_HasLeader(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Guardsmen_Potentials"), 1)) == true then
			
			UIWarning_Show("$900913")
			
		end
	end
	
end

end

--[[ this rule dictates what the guardsmen squads do once they've been converted]]

function Rule_Captured_Guardsman_Control()

if 	SGroup_Exists("sg_Guardsmen") and SGroup_IsEmpty("sg_Guardsmen") == false then
	
	if SGroup_Exists("sg_tainted_psyker") and SGroup_IsEmpty("sg_tainted_psyker") == false and SGroup_CountDeSpawned(SGroup_FromName("sg_tainted_psyker")) == 0 then
		
		local sorcerpos = SGroup_GetPosition("sg_tainted_psyker")
		
		if World_DistanceSGroupToPoint(SGroup_FromName("sg_Guardsmen"), sorcerpos, true) <= 38 then
			
			Cmd_MoveToPosOffset("sg_Guardsmen", sorcerpos, 4, 5)
			
		end
		
		if World_DistanceSGroupToPoint(SGroup_FromName("sg_Guardsmen"), sorcerpos, true) > 40 then
			
			Cmd_StopSquads("sg_Guardsmen")
			SGroup_SetPlayerOwner("sg_Guardsmen", g_Player2)
			SGroup_Clear(SGroup_FromName("sg_Guardsmen"))
			g_captured = false
			
		end
		
	elseif (SGroup_Exists("sg_tainted_psyker") and SGroup_IsEmpty("sg_tainted_psyker") ) 
	or (SGroup_Exists("sg_tainted_psyker") and SGroup_IsEmpty("sg_tainted_psyker") == false and SGroup_CountDeSpawned(SGroup_FromName("sg_tainted_psyker")) == 0)  then 
		
		Cmd_StopSquads("sg_Guardsmen")
		SGroup_SetPlayerOwner("sg_Guardsmen", g_Player2)
		SGroup_Clear(SGroup_FromName("sg_Guardsmen"))
		g_captured = false
		
	end
	
elseif SGroup_Exists("sg_Guardsmen") == false or SGroup_IsEmpty("sg_Guardsmen") then
	
	if SGroup_Exists("sg_Guardsmen") then
		SGroup_Clear(SGroup_FromName("sg_Guardsmen"))
	end
	g_captured = false
	
end

end

--[[ Rule for what happens as the TITAN PIECES are captured ]]

function Rule_Piece_Capture()

if g_number_captured >= 3 and g_necron_moved == false then
	
	for n = 1,4 do
		--SGroup_SetHealthInvulnerable("sg_necron_monolith"..n, false)  -- sets Monoliths to vulnerable
		Cmd_MoveToMarker("sg_necron_monolith"..n, "mkr_monolith_destination"..n.."a")
		--Rule_Remove(Rule_Piece_Capture)
		g_necron_moved = true
	end
	
elseif g_number_captured >= 6 and g_necron_moved == true then
	
	FOW_RevealMarker("mkr_titan_sensor_radius", 3600)
	World_EnablePlayerToPlayerFOW(g_Player1, g_Player3, false)
	
	Util_StartNIS( EVENTS.NIS_Mid_TitanAwakes ) 	
	Rule_AddInterval(Rule_IE_Heavy_Weapons_Online, 1)
	

--[[ why the hell is this here? - deg for i = 1,6 do EGroup_SetPlayerOwner("eg_titan_heavy_weapons"..i, g_Player1) end ]]

	for n = 1,4 do
		SGroup_SetHealthInvulnerable("sg_necron_monolith"..n, false)  -- sets Monoliths to vulnerable
		Cmd_MoveToMarker("sg_necron_monolith"..n, "mkr_monolith_destination"..n.."b")
		Rule_Remove(Rule_Piece_Capture)
	end
	
end

end

function Rule_Idle_Defender_Return() for i = 1, 12 do if SGroup_Exists("sg_titan_defender"..i) and SGroup_IsEmpty("sg_titan_defender"..i) == false then if Player_OwnsSGroup( g_Player2, SGroup_FromName("sg_titan_defender"..i)) then Cmd_MoveToMarker("sg_titan_defender"..i, "mkr_imperial_guard_perimeter"..i) end end end end

--[[ Titan Piece Capture button]]

function Rule_Capture_Button2() -- Needed because the icon for the titan piece capture button is different than the one that is used for capturing guardsmen

t_capture_button = {
	button_icon = {--[[1]]"Scar_buttons/capture_titan", --[[2]]"Scar_buttons/capture_titan", --[[3]]"Scar_buttons/capture_titan"},
	button_description = {--[[1]]"$900908", --[[2]]"$900910"}, 
}

-- g_buttonID1 = Util_ScarButton_Create("btn_ScarUI", t_capture_button.button_icon, t_capture_button.button_description, true, false) g_btn_capturetitanID = Util_AbilityButton_CreateModal(t_capture_button.button_icon, t_capture_button.button_description, true) Button_SetModalInstruction(g_btn_capturetitanID, "$900918")

Util_SGroupAbilityButton_Add2Manager(g_btn_capturetitanID, "sg_tainted_psyker")

g_btn_titancapture = 0
Rule_AddInterval(Rule_Capture_Titan_Piece_Button_Click, 1)

end

function Rule_Capture_Titan_Piece_Button_Click()

--[[ balancing ]]
g_titancapturedelay = 60
g_titancapturedist = 20

local close_enough = false
local titan_num = false

if Button_GetPressed(g_btn_capturetitanID) == true then  
	if Button_GetEnabled(g_btn_capturetitanID) then 
		-- gets the position the button was pressed
		local buttonpos1 = Button_GetPressedPosition( g_btn_capturetitanID)
		--gets the position of your target, in this case an Sgroup
		
		for i = 1, 6 do
			
			t_pos[i] = EGroup_GetPosition(EGroup_FromName("eg_titan_heavy_weapons"..i))
			
			--compares the distance between the groups
			if World_DistancePointToPoint(buttonpos1, t_pos[i]) < g_titancapturedist and t_titan_piece_owned[i] == false then
				
				titan_num = i
				close_enough = true
				
				break
			end	
		end
		
		if close_enough == true then
			local i = titan_num
			
			Anim_PlaySGroupAnim( SGroup_FromName( "sg_tainted_psyker"), "special_attack_1_sp" )
			EGroup_SetPlayerOwner("eg_titan_heavy_weapons"..i, g_Player1)
			
			t_titan_piece_owned[i] = true
			
			--[[ condition for removing the pings ]]
			local count = table.getn(t_titanPings.egroup)
			if count > 0 then
				for y = count, 1, -1 do 
					if  t_titanPings.egroup[y] ==  "eg_titan_heavy_weapons"..i then
						t_titanPings.state[y] = true
						break
					end
				end
			end
			
			
			g_number_captured = g_number_captured + 1
			UI_ShowCountUpdate("cnt_pieces_captured", g_number_captured)
			
			g_btn_titancapture = g_titancapturedelay
			Button_SetEnabled(g_btn_capturetitanID, false)
			
		else
			UIWarning_Show("$900914")
		end
		
	elseif Button_GetEnabled(g_btn_capturetitanID) == false then
		UIWarning_Show("$900919")
	end
	
end

if g_btn_titancapture > 1 then
	g_btn_titancapture = g_btn_titancapture-1
elseif g_btn_titancapture == 1 then
	g_btn_titancapture = 0 
	Button_SetEnabled(g_btn_capturetitanID, true)
end

--[[ this IS the check for when you've captured 6 pieces ]]
if g_number_captured == 6 then
	
	g_obj_titanpiece = true
	
	Util_SGroupAbilityButton_Remove(g_btn_capturetitanID)	
	
	Rule_Remove(Rule_Capture_Titan_Piece_Button_Click)
	
end

end

function Rule_Moment_Shortcut() Util_StartNIS( EVENTS.NIS_Moment ) end


--[[ GAME OVER - Player Wins ]]

function Rule_EndGameWin()

if g_playerHasWon == true then
	Rule_RemoveAll()
	Util_StartNIS(EVENTS.NIS_Closing)
end

end


--[[ GAME OVER - Player Loses ]]

--[[ The Player Loses condition will be mission specific this version of the function detects if the player has lost their base and has no servitors left ]]

function Rule_EndGameLose()

--[[ Lose because of the HQ is destroyed ]]	
if g_playerHasWon == false then
	World_SetTeamWin( g_Player2, "" )
	Fade_Start(4, false)
	Rule_AddIntervalEx( Rule_GameOver,5,1 )
	Rule_Remove( Rule_EndGameLose )
end

end

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


--[[ OBJECTIVES ]]

--[[ OBJECTIVES //MASTER PRIMARY OBJECTIVE 901033 Claim the Titan for Khorne 901034 We have come to claim the Titan! It will be ours or Khorne will feast upon our souls! //SUB Primary 901006 Sacrifice the Guardsmen
901008 Using your Tainted Psyker, lead the believers of the False Emperor to their doom at our sacrificial pits. However, take care with their bases. Without their barracks we will not have a supply of fresh blood... //SUB Primary 901018 Capture the Titan pieces 901020 The Tainted Psykers have collected enough blood to please the Blood God. Go forth and capture the Titan pieces through posession. //SUB Primary 901012 Destroy the Monoliths 901014 The Necrons threaten our newly possessed Titan! The weak point of their force appears to be the Monoliths. Destroy these Monoliths! We may use the Titan heavy weapons when they become operational. //SECONDARY OBJ 901000 Destroy the Weapons Depot 901002 The Imperial Guard have retreated to various spots around the Titan, including a previously abandoned Weapons Depot. Taking this out will deny our enemy the source of their pathetic vehicles.
//SECONDARY OBJ 901024 Build a Daemon Pit 901026 We must build a Daemon Pit if we are to unleash Khorne's greatest gifts; the unstoppable Obliterators and the ultimate tribute to Khorne, the Bloodthirster. //PRIMARY OBJ 901030 Chaos HQ Must Survive 901031 We cannot let our most sacred of structures fall to the enemies of Khorne. Protect it at all costs! ]]

--[[ MASTER OBJECTIVE ]] function Rule_Objective_ClaimTheTitan()

Objective_ClaimTheTitan = { title_id = 901033, short_desc_id = 901034, help_tip_id = 000000 }

if Event_IsAnyRunning() == false and Objective_Exists(Objective_ClaimTheTitan.title_id) == false then
	
	Util_WXP_ObjectiveCreate(Objective_ClaimTheTitan, true, g_Player1)
	
	--[[ stagger the opening rules ]]
	Rule_AddInterval(Rule_Objective_ProtectTheHQ, 1)
	
elseif Event_IsAnyRunning() == false and g_obj_claimtitan == true  then
	
	Util_ObjectiveComplete(Objective_ClaimTheTitan.title_id)
	Rule_Remove(Rule_Objective_ClaimTheTitan)
	
	g_playerHasWon = true
	
	--[[ fails if generic fail condition trips (doesn't exist) or the HQ is destroyed ]]
elseif Event_IsAnyRunning() == false and (g_obj_claimtitan == false or g_obj_protecthq == false or g_obj_titanpiece == false ) then
	
	Util_ObjectiveFail(Objective_ClaimTheTitan.title_id)
	Rule_Remove(Rule_Objective_ClaimTheTitan)
	
	g_playerHasWon = false
	
end

end

--[[ SUB ONE ]] function Rule_Objective_Sacrifice_Guardsmen()

Objective_Sacrifice_Guardsmen = { title_id = 901006, short_desc_id = 901008, help_tip_id = 901010 }

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Sacrifice_Guardsmen.title_id) == false then
	
	--[[ add the button stuff ]]
	Rule_AddOneShot(Rule_Capture_Button, 0)
	
	Util_WXP_ObjectiveSubCreate(Objective_Sacrifice_Guardsmen, Objective_ClaimTheTitan.title_id)
	
	--[[ mark the area ]]
	Rule_AddOneShot(Rule_Outpost_Pings, 0)
	local markers = { "mkr_outpost1", "mkr_outpost2", "mkr_outpost3", }
	t_objpings1 = {}
	for i = 1, table.getn(markers) do
		FOW_RevealMarker(markers[i], 30)
		t_objpings1[i] = Objective_PingMarker( Objective_Sacrifice_Guardsmen.title_id, markers[i], true, "default" )
	end
	
	--[[ AUTOSAVE AFTER NIS ]]
	Rule_AddIntervalDelay(Rule_Autosave_MissionStart, 1, 5)
	
	--[[ stagger the opening rules ]]
	Rule_AddIntervalDelay(Rule_Objective_Build_Daemon_Pit, 1, 30)
	
elseif Event_IsAnyRunning() == false and g_obj_sacrificeguard == true  then
	
	Util_ObjectiveComplete(Objective_Sacrifice_Guardsmen.title_id)
	
	g_sacrifice_finished = true
	g_psykerswap = true
	SGroup_SelfDestroy("sg_tainted_psyker", true)
	
	for i = 1, table.getn(t_objpings1) do
		Objective_PingRemove( Objective_Sacrifice_Guardsmen.title_id, t_objpings1[i] )
	end
	
	Rule_AddInterval(Rule_Objective_Take_Over_Titan_Pieces, 1)
	
	Rule_Remove(Rule_Objective_Sacrifice_Guardsmen)
	
	--[[ fails if generic fail condition trips (doesn't exist) or the HQ is destroyed ]]
elseif Event_IsAnyRunning() == false and (g_obj_sacrificeguard == false or g_obj_protecthq == false ) then
	
	Util_ObjectiveFail(Objective_Sacrifice_Guardsmen.title_id)
	
	for i = 1, table.getn(t_objpings1) do
		Objective_PingRemove( Objective_Sacrifice_Guardsmen.title_id, t_objpings1[i] )
	end
	
	Rule_Remove(Rule_Objective_Sacrifice_Guardsmen)
	
end

end

function Rule_Psyker_BeaconCreate()

if SGroup_Exists("sg_tainted_psyker") and SGroup_IsEmpty("sg_tainted_psyker") == false and SGroup_CountDeSpawned(g_sg_psykerID) == 0 then
	Cmd_StopSquads("sg_tainted_psyker")
	local pos = SGroup_GetPosition(g_sg_psykerID)
	g_psykerbeaconID = Util_CreateBeaconPosition_Red(pos)
	Rule_AddInterval(Rule_Psyker_BeaconRemove, 1)
end

end

function Rule_Psyker_BeaconRemove()

if SGroup_IsSelected("sg_tainted_psyker") or SGroup_IsEmpty("sg_tainted_psyker") then
	Util_RemoveBeaconMarker(g_psykerbeaconID)
	Rule_Remove(Rule_Psyker_BeaconRemove)
end

end

--[[ SUB TWO ]] function Rule_Objective_Take_Over_Titan_Pieces()

Objective_Take_Over_Titan_Pieces = { title_id = 901018, short_desc_id = 901020, help_tip_id = 901022 }

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Take_Over_Titan_Pieces.title_id) == false then
	
	Util_WXP_ObjectiveSubCreate(Objective_Take_Over_Titan_Pieces, Objective_ClaimTheTitan.title_id)
	
	--[[ check for titan pieces ]]
	Rule_AddInterval(Rule_TitanPiece_Destroyed, 5)
	
	--[[ Add the titan objective supporting bits ]]
	Rule_AddOneShot(Rule_IE_Objective_Capture_Titan_Piece, 0)
	Rule_AddOneShot(Rule_Titan_Weapon_Pings, 0)
	
elseif Event_IsAnyRunning() == false and g_obj_titanpiece == true  then
	
	Util_ObjectiveComplete(Objective_Take_Over_Titan_Pieces.title_id)
	g_titanactive = true
	
	Player_UnRestrictAbility(g_Player1, "sp_dxp_abilities_titanmaincannon")
	
	Rule_AddInterval(Rule_Objective_Defeat_Necron, 1)
	
	--[[ Autosave ]]
	Rule_AddIntervalDelay(Rule_Autosave_TitanofKhorne, 1, 5)
	
	Rule_Remove(Rule_Objective_Take_Over_Titan_Pieces)
	
	--[[ fails if generic fail condition trips (doesn't exist) or the HQ is destroyed ]]
elseif Event_IsAnyRunning() == false and (g_obj_titanpiece == false or g_obj_protecthq == false ) then
	
	Util_ObjectiveFail(Objective_Take_Over_Titan_Pieces.title_id)
	Rule_Remove(Rule_Objective_Take_Over_Titan_Pieces)
	
end

end

--[[ Are any of the Titan Pieces Missing? ]] function Rule_TitanPiece_Destroyed()

for i = 1, 6 do
	if EGroup_Exists("eg_titan_heavy_weapons"..i) and EGroup_IsEmpty("eg_titan_heavy_weapons"..i) then
		g_obj_titanpiece = false
		g_titanpiece_destroyed = true
		Rule_Remove(Rule_TitanPiece_Destroyed)
		break
	end
end

end --[[ SUB 3 ]] function Rule_Objective_Defeat_Necron()

Objective_Defeat_Necron = { title_id = 901012, short_desc_id = 901014, help_tip_id = 901016 }

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Defeat_Necron.title_id) == false then
	
	Util_WXP_ObjectiveSubCreate(Objective_Defeat_Necron, Objective_ClaimTheTitan.title_id)
	
	Rule_AddInterval(Rule_MonolithsEmpty_Check, 5)
	
elseif Event_IsAnyRunning() == false and g_obj_defeatnecrons == true then
	
	Util_ObjectiveComplete(Objective_Defeat_Necron.title_id)
	Rule_AddOneShot(Rule_IE_Objective_Necrons_Destroyed, 0)
	
	g_obj_claimtitan = true  
	
	Rule_Remove(Rule_Objective_Defeat_Necron)
	
--[[ fails if generic fail condition trips (doesn't exist) or the HQ is destroyed ]]
elseif Event_IsAnyRunning() == false and (g_obj_defeatnecrons == false or g_obj_protecthq == false ) then
	
	Util_ObjectiveFail(Objective_Defeat_Necron.title_id)
	Rule_Remove(Rule_Objective_Defeat_Necron)
	
end

end

function Rule_MonolithsEmpty_Check()

if SGroup_Exists("sg_monoliths") and SGroup_IsEmpty("sg_monoliths") then
	g_obj_defeatnecrons = true
	Rule_Remove(Rule_MonolithsEmpty_Check)
end

end

--[[ PRIMARY OBJECTIVE ]] function Rule_Objective_ProtectTheHQ()

Objective_ProtectTheHQ = { title_id = 901030, short_desc_id = 901031, help_tip_id = 000000 }

if Event_IsAnyRunning() == false and Objective_Exists(Objective_ProtectTheHQ.title_id) == false then
	
	Util_WXP_ObjectiveCreate(Objective_ProtectTheHQ, true, g_Player1)
	if EGroup_Exists("eg_chaos_hq") and EGroup_IsEmpty("eg_chaos_hq") == false then
		local pos = EGroup_GetPosition(EGroup_FromName("eg_chaos_hq"))
		g_objhqping = Objective_PingPosition(Objective_ProtectTheHQ.title_id, pos, true, "default")
	end
	
	Rule_AddInterval(Rule_ChaosHQ_Check, 5)
	
	--[[ staggering opening obj ]]
	Rule_AddIntervalDelay(Rule_Objective_Sacrifice_Guardsmen, 1, 1)
	
elseif Event_IsAnyRunning() == false and (g_obj_protecthq == true or g_obj_claimtitan == true)  then
	
	Util_ObjectiveComplete(Objective_ProtectTheHQ.title_id)
	if g_objhqpingID ~= nil then
		Objective_PingRemove(Objective_ProtectTheHQ.title_id, g_objhqpingID)
	end
	Rule_Remove(Rule_Objective_ProtectTheHQ)
	
elseif Event_IsAnyRunning() == false and (g_obj_protecthq == false or g_obj_claimtitan == false ) then
	
	g_playerHasWon = false
	if g_objhqpingID ~= nil then
		Objective_PingRemove(Objective_ProtectTheHQ.title_id, g_objhqpingID)
	end
	
	Util_ObjectiveFail(Objective_ProtectTheHQ.title_id)
	Rule_Remove(Rule_Objective_ProtectTheHQ)
	
end

end

function Rule_ChaosHQ_Check()

if EGroup_Exists("eg_chaos_hq") and EGroup_IsEmpty("eg_chaos_hq") then
	g_obj_protecthq = false
	Rule_Remove(Rule_ChaosHQ_Check)
end

end

--[[ FIRST SECONDARY OBJ ]] function Rule_Objective_Build_Daemon_Pit()

Objective_Build_Daemon_Pit = { title_id = 901024, short_desc_id = 901026, help_tip_id = 901028 }

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Build_Daemon_Pit.title_id) == false then
	
	Util_WXP_ObjectiveCreate(Objective_Build_Daemon_Pit, false, g_Player1)
	
	Rule_AddInterval(Rule_BuildDaemonPit_Check, 5)
	
	--[[ stagger the opening objs ]]
	Rule_AddIntervalDelay(Rule_Objective_Destroy_Weapons_Depot, 1, 300)

elseif Event_IsAnyRunning() == false and g_obj_buildpit == true  then
	
	Util_ObjectiveComplete(Objective_Build_Daemon_Pit.title_id)
	Rule_Remove(Rule_Objective_Build_Daemon_Pit)
	
--[[ fails if generic fail condition trips (doesn't exist) or the HQ is destroyed or Necrons are defeated before this obj is complete ]]
elseif Event_IsAnyRunning() == false and (g_obj_buildpit == false or g_obj_protecthq == false or g_obj_defeatnecrons == true) then
	
	Util_ObjectiveFail(Objective_Build_Daemon_Pit.title_id)
	Rule_Remove(Rule_Objective_Build_Daemon_Pit)
	
end

end

function Rule_BuildDaemonPit_Check()

if Player_GetBlueprintCount(g_Player1, "chaos_greater_sacrificial_circle" ) >=1 then
	
	local Rule_AllBuilt = function( egroupid, itemindex, entityID )
		if Entity_GetBlueprintName(entityID) == "chaos_greater_sacrificial_circle" and Entity_GetBuildingProgress(entityID) == 1.0 then
			--print(local_blueprint.." is built")
			return true
		else
			--print(local_blueprint.." isn't built")
			return false
		end
	end
	EGroup_AddGroup(EGroup_CreateIfNotFound("eg_daemonpitdetect"), Player_GetEntities( g_Player1 ))
	if EGroup_ForEach(EGroup_FromName("eg_daemonpitdetect"), Rule_AllBuilt) then
		g_obj_buildpit = true
		Rule_Remove(Rule_BuildDaemonPit_Check)
	end
	
end

end

--[[ SECOND SECONDARY OBJ ]] function Rule_Objective_Destroy_Weapons_Depot()

Objective_Destroy_Weapons_Depot = { title_id = 901000, short_desc_id = 901002, help_tip_id = 901004 }

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Destroy_Weapons_Depot.title_id) == false then
	
	Util_WXP_ObjectiveCreate(Objective_Destroy_Weapons_Depot, false, g_Player1)
	
	g_objpingID = Objective_PingMarker(Objective_Destroy_Weapons_Depot.title_id, "mkr_IG_weapons_depot", true, "attack")
	
	Util_Ping_LoopingMkr("ping_IG_weapons_depot", "mkr_IG_weapons_depot")
	FOW_RevealMarker("mkr_IG_weapons_depot", 30)
	
	Rule_AddOneShot(Rule_IE_Beware_of_Depot, 0)
	
elseif Event_IsAnyRunning() == false and g_obj_destroydepot == true then
	
	Util_ObjectiveComplete(Objective_Destroy_Weapons_Depot.title_id)
	Objective_PingRemove(Objective_Destroy_Weapons_Depot.title_id, g_objpingID)
	
	Util_Ping_Stop("ping_IG_weapons_depot")
	
	Rule_Remove(Rule_Objective_Destroy_Weapons_Depot)
	
--[[ fails if generic fail condition trips (doesn't exist) or the HQ is destroyed or Necrons are defeated before this obj is complete ]]
elseif Event_IsAnyRunning() == false and (g_obj_destroydepot == false or g_obj_protecthq == false or g_obj_defeatnecrons == true) then
	
	Util_ObjectiveFail(Objective_Destroy_Weapons_Depot.title_id)
	Objective_PingRemove(Objective_Destroy_Weapons_Depot.title_id, g_objpingID)
	
	Rule_Remove(Rule_Objective_Destroy_Weapons_Depot)
	
end

end


--[[ AUTOSAVES ]]

function Rule_Autosave_MissionStart() if not Event_IsAnyRunning() then Util_Autosave( "$900200" ) Rule_Remove(Rule_Autosave_MissionStart) end end

function Rule_Autosave_Sacrificed1stSquad() if not Event_IsAnyRunning() then Util_Autosave( "$900201" ) Rule_Remove(Rule_Autosave_Sacrificed1stSquad) end end

function Rule_Autosave_AlmostThere() if not Event_IsAnyRunning() then Util_Autosave( "$900202" ) Rule_Remove(Rule_Autosave_AlmostThere) end end

function Rule_Autosave_PossessTitan() if not Event_IsAnyRunning() then Util_Autosave( "$900203" ) Rule_Remove(Rule_Autosave_PossessTitan) end end

function Rule_Autosave_TitanofKhorne() if not Event_IsAnyRunning() then Util_Autosave( "$900204" ) Rule_Remove(Rule_Autosave_TitanofKhorne) end end

--[[ INTEL EVENTS ]]

function Rule_IE_Beware_of_Depot()

Util_StartIntel(EVENTS.IE_Beware_of_Depot)

end

--[[ Outpost Destroyed ]] function Rule_IE_Objective_Start_Sacrifice()

Util_StartIntel(EVENTS.IE_Objective_Start_Sacrifice)

end

--[[ Heavy Weapons Online ]] function Rule_IE_Heavy_Weapons_Online() if Event_IsAnyRunning() == false then Util_StartIntel(EVENTS.IE_Heavy_Weapons_Online) Rule_Remove(Rule_IE_Heavy_Weapons_Online) end end

--[[Necrons Destroyed]] function Rule_IE_Objective_Necrons_Destroyed()

Util_StartIntel(EVENTS.IE_Objective_Necrons_Destroyed)

end

--[[Titan Piece Capture Objective Speech]] function Rule_IE_Objective_Capture_Titan_Piece()

Util_StartIntel(EVENTS.IE_Objective_Capture_Titan_Piece)

end




--[[ CHEATS ]]

--~ function CheatClosing()

--~ Rule_RemoveAll() --~ Util_StartNIS(EVENTS.NIS_Closing)

--~ end

--~ function CheatTitanAwakes()

--~ Rule_RemoveAll() --~ Util_StartNIS(EVENTS.NIS_Mid_TitanAwakes)

--~ end

--~ function CheatNecronsArrive() --~ --~ g_warrior_num = 2 --~ Rule_RemoveAll() --~ Util_StartNIS(EVENTS.NIS_Mid_NecronsArrive)

--~ end

--~ function CheatMidMissionName()

--~ Rule_RemoveAll() --~ Util_StartNIS(EVENTS.NIS_MidName)

--~ end




Game statistieken
Volgers
12
Runs
58
Spelers
7
Recente runs
Niveau: Titan of the Emperor (Order 5 / Imperial guard)
Niveau: Hunter! (Disorder 2)
Niveau: Trophies (Disorder 5 / Orks)
Niveau: Keep Your Enemies Closer (Disorder 4)
Niveau: Blood for the Blood God! (Disorder 3)
Moderators