Mission event file for Disorder mission 2
Gidsen
/
Mission event file for Disorder mission 2
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", 1)
Misc_PlayerTeamColor(g_Player1,"default_6")
Player_DoNotPrecache(g_Player1, _t_MSD1_Player1)

g_Player2 = Setup_Player(1, "$690087", "ork_race", 2)
Misc_PlayerTeamColor(g_Player2,"default_4")
Player_DoNotPrecache(g_Player2, _t_MSD1_Player2)

g_Player3 = Setup_Player(2, "$690088", "chaos_marine_race", 1)
Misc_PlayerTeamColor(g_Player3,"default_6")
Player_DoNotPrecache(g_Player3, _t_MSD1_Player3)

g_Player4 = Setup_Player(3, "$690081", "guard_race", 4)
Player_DoNotPrecache(g_Player4, _t_MSD1_Player4)

g_Player5 = Setup_Player(4, "$860013", "npc_race", TEAM_NEUTRAL)
Player_DoNotPrecache(g_Player5, _t_MSD1_Player5)

g_Player6 = Setup_Player(5, "$690087", "ork_race", 2)
Misc_PlayerTeamColor(g_Player6,"default_4")
Player_DoNotPrecache(g_Player6, _t_MSD1_Player6)


--[[ DEFINE VARIABLES AND TABLES - define any preset values here for later use]]
g_firstrun = true
g_time = 0
--[[ define the "enemy" who will win if the player 'loses' ]]
g_enemy = g_Player2
g_playerswitch = "g_Player1"

end

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

--[[ nothing at the moment ]]

end


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

--[[ 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()		
	g_sgorksID = SGroup_CreateIfNotFound("sg_orks")
	g_sgallorksID = SGroup_CreateIfNotFound("sg_allorks")

--[[ 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 1 - Chaos ]]
local table1 = {
	"chaos_greater_sacrificial_circle", 
	"chaos_hq", 
	"chaos_machine_pit", 
}
Player_RestrictBuildingList(g_Player1, table1)

local table2 = {
	"chaos_squad_bloodthirster", 
	"chaos_squad_khorne_berserker", 
	"chaos_squad_possessed_marine", 
	"chaos_squad_lord", 
	"chaos_squad_obliterator", 
}
Player_RestrictSquadList(g_Player1, table2)

local table3 = {
	"ork_squad_armored_nob", 
	"ork_squad_bad_dok", 
	"ork_squad_bad_dok_sp_trainer", 
	"ork_squad_killa_kan", 
	"ork_squad_looted_tank", 
	"ork_squad_looted_tank_sp",
	"ork_squad_mek_boy", 
	"ork_squad_squiggoth", 
}
Player_RestrictSquadList(g_Player2, table3)

local table4 = {
	"guard_squad_ogryns", 
	"guard_squad_assassin", 
	"guard_squad_command_squad",
	"guard_squad_priest", 
	"guard_squad_psyker", 
	"guard_squad_baneblade", 
	"guard_squad_basilisk_sp_mso2", 
	"guard_squad_lemanruss",
}
Player_RestrictSquadList(g_Player4, table4)

Player_RestrictResearch(g_Player1, "chaos_possessed_daemon_fire_research")
Player_RestrictResearch(g_Player1, "chaos_possessed_daemon_mutation_research")
Player_RestrictResearch(g_Player1, "chaos_requisition_research_2")
Player_RestrictResearch(g_Player1, "chaos_power_research_2")
Player_RestrictResearch(g_Player1, "chaos_commander_health_research_2")
Player_RestrictResearch(g_Player1, "chaos_lord_research_2")
Player_RestrictResearch(g_Player1, "chaos_sorcerer_research_2")

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

end


--[[ MUSIC ]]

function Rule_SetupMusicPlaylist()

t_ambient = {"Snowy_wind_1" }
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, 800, 100)
	
	--[[ PREACTION ]]
	-- Use this space to add core mission functions that should be in place during the opening NIS
	Rule_AddOneShot(Rule_WorldEvents_Kickoff, 0)
	for i = 11, 16 do
		if EGroup_Exists("eg_ork_rubble"..i) and EGroup_IsEmpty("eg_ork_rubble"..i) == false then
			EGroup_DeSpawn("eg_ork_rubble"..i)
		end
	end

	--[[ DIFFICULTY LEVEL ]]
	-- gets the difficulty level from the UI and passes it into the function
	Rule_SetDifficultyLevel( Difficulty_Get() )
	
	Rule_AddInterval(Rule_Timer, 1)
	
	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, false) World_EnablePlayerToPlayerFOW(g_Player2, g_Player4, false) World_EnablePlayerToPlayerFOW(g_Player1, g_Player6, false)

	--[[ WIN CHECK ]]
	Rule_AddInterval(Rule_EndGameWin, 1)
	
	--[[ LOSE CHECK ]]
	Rule_AddInterval(Rule_EndGameLose, 1)
	
	--[[ ASSIGN OBJECTIVES ]]
	Rule_AddInterval(Rule_Objective_HuntWarboss, 1)
	
	
	--[[ AUTOSAVE AFTER NIS ]]
	Rule_AddIntervalDelay(Rule_Autosave_MissionStart, 1, 5)
	
	Rule_AddOneShot(Rule_IE_MissionIntro, 1)
	
	--[[ GENERATE ACTION ]]
	-- Use this space to add all core mission functions
	Rule_AddOneShot(Rule_Chaos_Kickoff, 0)
	Rule_AddOneShot(Rule_Orks_Kickoff, 0)
	
	--[[ 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_Player4, 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

local mod_bossarmour = Modifier_Create(MAT_EntityType, "armour_modifier", MUT_Multiplication, false, 2.2, "ork_warboss")
Modifier_ApplyToPlayer( mod_bossarmour, g_Player6)	
Modifier_ApplyToPlayer( mod_bossarmour, g_Player2)	

local mod_lordarmour = Modifier_Create(MAT_EntityType, "armour_modifier", MUT_Multiplication, false, 2.5, "chaos_lord_sp_msd01")
g_mod_lordarmour = Modifier_ApplyToPlayer( mod_lordarmour, g_Player1)	

end


--[[ AI ]]

function Rule_StartAI()

g_orkAIon = nil
Cpu_Enable(g_Player2, true)
Cpu_SetDifficulty(g_Player2,   AD_Hard)
Cpu_EnableComponent(g_Player2, false,  CT_Attacking)

end


--[[ CORE GAME ]]

function Rule_Timer() g_time = g_time+1 end

--[[ WORLD EVENTS ]]

function Rule_WorldEvents_Kickoff()

--[[ make the generator invulnerable to prevent player exploits ]]
EGroup_SetHealthInvulnerable("eg_ork_energysource", true)

for i = 11, 16 do
	EGroup_SetPlayerOwner("eg_ork_rubble"..i, g_Player5)
end

--[[ make other shit happen ]]
Rule_AddOneShot(Rule_World_CreateBases, 0)

end

function MSD1_Explosion1(markername) local pos = Marker_GetPosition ( Marker_FromName( markername, "basic_marker" ) ) local eventfile = "data:Art/Events/ground_impact/Impact_Artillery_L_Dirt.events" World_FXEvent (eventfile, pos) end

function MSD1_Explosion2(markername, iteration) local pos = Marker_GetPosition ( Marker_FromName( markername, "basic_marker" ) ) local eventfile = "data:Art/Events/ground_impact/Impact_Artillery_L_Dirt.events" World_FXEvent (eventfile, pos)

if Rule_Exists(MSD1_Explosion2_Extended) == false then
	_extend_explosion = pos
	Rule_AddIntervalEx(MSD1_Explosion2_Extended, 1, iteration)
end

end

function MSD1_Explosion2_Extended() local pos = _extend_explosion pos.x = pos.x+World_GetRand(-10, 10) pos.z = pos.z+World_GetRand(-10, 10) local eventfile = "data:Art/Events/ground_impact/Impact_Artillery_L_Dirt.events" World_FXEvent (eventfile, pos) end

function MSD1_OntheSpot(sgroupname, marker1, marker2) SGroup_DeSpawn(sgroupname) SGroup_ReSpawnMarker(sgroupname, marker1) if marker2 ~= nil then SGroup_FaceMarker(sgroupname, marker2) end end

--[[ make the bases that populate the starting area ]] function Rule_World_CreateBases()

--[[ make chaos buildings ]]
local blue = {"chaos_hq", "chaos_temple", "chaos_armoury", "chaos_plasma_generator"}
for i = 1, table.getn(blue) do
	Entity_CreateBuildingMarker(g_Player1, "eg_chaos_build"..i, blue[i], "mkr_chaos_build"..i, 1)
	EGroup_AddGroup(EGroup_CreateIfNotFound("eg_chaos_buildings"), EGroup_FromName("eg_chaos_build"..i))
end

t_rubblepiles = {eg = {}, mkr = {}}

--[[ SET UP ORKS ]]
t_orkbuild = {
	"ork_boy_hut",
	"ork_generator",
	"ork_mek_shop",
	"ork_pile_o_guns",
	"ork_waagh_banner",
}

Player_SetAllResources(g_Player2, 100000, 100000, 100)

Player_SetMaxSquadCap( g_Player2, 100 )
Player_SetSquadCap( g_Player2, 100 )

g_egorkbaseID = EGroup_CreateIfNotFound("eg_ork_base")

local j = 1
--[[ create the HQ ]]
Entity_CreateBuildingMarker(g_Player2, "eg_ork_hq"..j, "ork_hq", "mkr_ork_base", 1)
EGroup_AddGroup(g_egorkbaseID, EGroup_FromName( "eg_ork_hq"..j))
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_ork_builder"..j, "ork_squad_grot", "mkr_ork_base", 3, 1)
for i = 1, 5 do
	local num = World_GetRand(2, 4)
	for y = 1, num do
		local newx = World_GetRand(-30, 30)
		local newz = World_GetRand(-30, 30)
		local pos = Marker_GetPosition(Marker_FromName("mkr_ork_base", "basic_marker"))
		pos.x = pos.x + newx
		pos.z = pos.z + newz
		Entity_CreateBuildingPosition(g_Player2, "eg_ork_base"..i, t_orkbuild[i], pos, 1)
		if EGroup_Exists("eg_ork_base"..i) then EGroup_AddGroup(g_egorkbaseID, EGroup_FromName( "eg_ork_base"..i)) end
	end
end

end

--[[ CHAOS - Stage 1 ]]

function Rule_Chaos_Kickoff()

--[[ BALANCE handle - deg]]
Player_SetAllResources(g_Player1, 2000, 1000)

Rule_AddOneShot(Rule_Chaos_Restrictions, 0)

Rule_AddOneShot(Rule_Chaos_CreateTransports, 0.5)
Rule_AddOneShot(Rule_Chaos_BezerkerButton, 2)

-- Rule_AddOneShot(Rule_Chaos_CreateSupport, 0) -- Rule_AddOneShot(Rule_Chaos_CreateBlock, 0)

Rule_AddInterval(Rule_Chaos_LordDies, 1)
Rule_AddInterval(Rule_Chaos_HealingStation, 1)

end

function Rule_Chaos_PostMessage()

if Event_IsAnyRunning() == false and Event_TimeSinceLast() > 60 and EGroup_IsUnderAttackByPlayer("eg_chaos_posts", false, g_Player2) then
	--[[ INTEL EVENT ]]
	Util_StartIntel(EVENTS.IE_CrullUpgradePosts)
	
	Rule_Remove(Rule_Chaos_PostMessage)
end

end

function Rule_Chaos_PopCapMessage()

if Event_IsAnyRunning() == false and Event_TimeSinceLast() > 30 and Player_GetMaxSquadCap(g_Player1, CT_SquadCap) < 11 then
	--[[ INTEL EVENT ]]
	Util_StartIntel(EVENTS.IE_CrullPopReached)
	
	Rule_Remove(Rule_Chaos_PopCapMessage)
end

end

--[[ placeholder to make the starting chaos forces ]] function Rule_Chaos_CreateTransports()

local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player1, "sg_chaos_rhinos", "chaos_squad_rhino", "mkr_chaos_start", 2, 1)
SGroup_AddGroup(g_chaosID, sgroupID)
Cmd_MoveToMarker("sg_chaos_rhinos", "mkr_chaos_rally5")

end

--[[ lock stuff so the player can't have it ]] function Rule_Chaos_Restrictions()

--[[ restrict the following ]]
Player_RestrictResearch(g_Player1, "chaos_squad_cap_research")
Player_RestrictResearch(g_Player1, "chaos_support_cap_research")

Player_RestrictBuilding(g_Player1, "chaos_hq")
Player_RestrictBuilding(g_Player1, "chaos_machine_pit")

Player_RestrictSquad(g_Player1, "chaos_squad_lord")
Player_RestrictSquad(g_Player1, "chaos_squad_khorne_berserker")

Player_RestrictAddOn(g_Player1, "chaos_hq_addon_2")
Player_RestrictAddOn(g_Player1, "chaos_list_post_addon_2")

end

--[[ the temples and their healing powers ]] function Rule_Chaos_HealingStation() local SquadHealth = function( sgroupID, itemindex, squadID ) Squad_SetHealth(squadID, 1) end

for i = 1, 4 do
	if EGroup_Exists("eg_temple"..i) and EGroup_IsEmpty("eg_temple"..i) == false then
		Player_GetAllSquadsNearMarker(g_Player1, "sg_chaos_healing", "mkr_chaos_temple"..i)
		
		
		if SGroup_IsEmpty("sg_chaos_healing") == false then
			SGroup_ForEach( SGroup_FromName("sg_chaos_healing"), SquadHealth )
			SGroup_Clear(SGroup_FromName("sg_chaos_healing"))
		end
	end
end

end

--[[ BABY SIT THE LEADER ]] function Rule_Chaos_LordDies()

local blueprinttable = Util_MakeBlueprintTable("chaos_squad_lord_sp_msd01")

if SGroup_Exists("sg_chaos_lord") and SGroup_CountDeSpawned(SGroup_FromName("sg_chaos_lord")) == 0 
and ( SGroup_IsEmpty("sg_chaos_lord") or SGroup_ContainsBlueprints( "sg_chaos_lord", blueprinttable, false) == false ) then
	
	Rule_AddOneShot(Rule_Chaos_LordReturns, 7)
	Rule_Remove(Rule_Chaos_LordDies)
end

end

--[[ LORD RETURNS ]] function Rule_Chaos_LordReturns()

local sgroupID = Util_CreateSquadsAtMarker(g_Player1, "sg_chaos_lord", "chaos_squad_lord_sp_msd01", "mkr_chaos_start", 1)
SGroup_AddGroup(g_chaosID, sgroupID)
World_FXEventSquad("data:Art/Events/Unit_Upgrade_Morale_FX/Reinforce_Trooper", sgroupID)

if Event_TimeSinceLast() > 10 then
	Util_StartIntel(EVENTS.IE_Chaos_ImBack )
end
EventCue_DoEvent( "recruit_commander", "/Races/Shared/Upgrade_weapon", "$42890", "$42892" )

Rule_AddInterval(Rule_Chaos_LordDies, 1)

end

--[[ Temples Under Attack ]] function Rule_Chaos_TempleUnderAttack() local count = EGroup_Count(EGroup_FromName("eg_alltemples")) if count < g_lasttemplecount then if count == 3 then --[[ INTEL EVENT ]] Util_StartIntel(EVENTS.IE_CrullTempleLost1) elseif count == 2 then --[[ INTEL EVENT ]] Util_StartIntel(EVENTS.IE_CrullTempleLost2) elseif count == 1 then --[[ INTEL EVENT ]] Util_StartIntel(EVENTS.IE_CrullTempleLost3) end

	g_lasttemplecount = count
	
elseif g_templewarninglimit == 0 then
	if EGroup_IsUnderAttackByPlayer("eg_alltemples", false, g_Player2) then
		--[[ INTEL EVENT ]]
		Util_StartIntel(EVENTS.IE_CrullTempleUnderAttack)
		
		g_templewarninglimit = 30
	end
elseif g_templewarninglimit > 0 then
	g_templewarninglimit = g_templewarninglimit-1
end

end

--[[ SUMMONING BEZERKERS ]]

function Rule_Chaos_BezerkerButton() t_bezbutton = { button_icon = {--[[1]]"Scar_buttons/summon_berzerker", --[[2]]"Scar_buttons/summon_berzerker", --[[3]]"Scar_buttons/summon_berzerker"}, button_description = {--[[1]]"$860050", --[[2]]"$860051"}, }

g_bezbuttonID = Util_AbilityButton_Create(t_bezbutton.button_icon, t_bezbutton.button_description, false)

g_summonbezDelay = 0

--[[ BUTTON ADDED AFTER OBJECTIVE IS GIVEN ]]

end

--[[ DETECTING THE BUTTON PRESS ]] function Rule_Chaos_BezerkerButton_Check()

if Button_GetEnabled(g_bezbuttonID) and Button_GetPressed(g_bezbuttonID) then
	--[[ is the lord around ]]
	if SGroup_Exists("sg_chaos_lord") and SGroup_CountDeSpawned(SGroup_FromName("sg_chaos_lord")) == 0 and SGroup_IsEmpty("sg_chaos_lord") == false then
		--[[ is the player still within range of a valid temple]]
		if EGroup_IsEmpty("eg_temple"..g_summonbezNum) == false and Prox_AnySquadNearMarker("sg_chaos_lord", g_summonbezMKR) then
			--[[ check to see if the player is low on bezerkers ]]
			if SGroup_Count(SGroup_FromName("sg_chaos_bezerker")) == 0 then
				--[[ INTEL EVENT ]]
				Util_StartIntel(EVENTS.IE_CrullSummonSuccess)
				
				Sound_PlayStinger("stinger_completeobjective")
				local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player1, "sg_chaos_summonbez", "chaos_squad_khorne_berserker", g_summonbezMKR, 1, 4)
				World_FXEventSquad("data:Art/Events/Unit_Upgrade_Morale_FX/Reinforce_Trooper", SGroup_FromName("sg_chaos_summonbez"))
				Cmd_AttackSGroup("sg_chaos_summonbez", "sg_chaos_lord")
				SGroup_AddGroup(SGroup_FromName("sg_chaos_bezerker"), sgroupID)
				SGroup_AddGroup(g_chaosID, sgroupID)
				SGroup_Clear(sgroupID)
				
				--[[ the is is for the opening progression tracker ]]
				g_summonedbez = true
				
				--[[ this is to emulate a delay ]]
				Button_SetEnabled(g_bezbuttonID, false)
				g_summonbezDelay = 30
				Rule_AddInterval(Rule_Chaos_BezerkerConditionCheck, 1)
				Rule_Remove(Rule_Chaos_BezerkerButton_Check)
				
			--[[ tell the player they already have enough bezerkers - greedy bastards ]]
			else
				--[[ INTEL EVENT ]]
				Util_StartIntel(EVENTS.IE_CrullSummonNoRoom)
				
				-- restart the condition check but do not set the delay
				Button_SetEnabled(g_bezbuttonID, false)
				Rule_AddInterval(Rule_Chaos_BezerkerConditionCheck, 1)
				Rule_Remove(Rule_Chaos_BezerkerButton_Check)
				
			end
			
		--[[ if the temple is suddenly destroyed or the lord has moved away from the marker ]]			
		elseif EGroup_IsEmpty("eg_temple"..g_summonbezNum) or Prox_AnySquadNearMarker("sg_chaos_lord", g_summonbezMKR) == false then
			
			-- tell the player they are too far away
			--[[ INTEL EVENT ]]
			Util_StartIntel(EVENTS.IE_CrullTooFarToSummon)
			
			-- restart the button check but do not set the delay
			Button_SetEnabled(g_bezbuttonID, false)
			Rule_AddInterval(Rule_Chaos_BezerkerConditionCheck, 1)
			Rule_Remove(Rule_Chaos_BezerkerButton_Check)
			
		end
		
	--[[ if he's dead, fail silently ]]
	elseif SGroup_Exists("sg_chaos_lord") and SGroup_IsEmpty("sg_chaos_lord") then
		
		Button_SetEnabled(g_bezbuttonID, false)
		Rule_AddInterval(Rule_Chaos_BezerkerConditionCheck, 1)
		Rule_Remove(Rule_Chaos_BezerkerButton_Check)
		
	end
	
end

end

--[[ ARE THE CONDITIONS RIGHT FOR SUMMONING ]] function Rule_Chaos_BezerkerConditionCheck()

if g_summonbezDelay == 0 then
	if SGroup_Exists("sg_chaos_lord") and SGroup_CountDeSpawned(SGroup_FromName("sg_chaos_lord")) == 0 and SGroup_IsEmpty("sg_chaos_lord") == false then
		for i = 1, 4 do
			if EGroup_IsEmpty("eg_temple"..i) == false and Prox_AnySquadNearMarker("sg_chaos_lord", "mkr_chaos_temple"..i) then
				g_summonbezMKR = "mkr_chaos_temple"..i
				g_summonbezNum = i
				if Button_GetEnabled(g_bezbuttonID) == false then
					Button_SetEnabled(g_bezbuttonID, true)
				end
				Rule_AddInterval(Rule_Chaos_BezerkerButton_Check, 1)
				Rule_Remove(Rule_Chaos_BezerkerConditionCheck)
				break
			end
		end
	end
elseif g_summonbezDelay > 0 then
	g_summonbezDelay = g_summonbezDelay-1		
end

end

--[[ ORKS - Stage 1 ]]

-- do all the orky things for phase 1 function Rule_Orks_Kickoff()

--[[ BALANCE handle - deg]]
g_templeattack = 1

--[[ BALANCE handle - deg ]]
g_grotcount = 8

Rule_AddOneShot(Rule_Ork_Restrictions, 0)
Rule_AddOneShot(Rule_Orks_CreateGeneratorDefense, 0)

--[[ force field related nonsense ]]
g_vulnerable = false
g_invulnerable = false
Rule_AddInterval(Rule_Orks_WarbossForceField_On, 1)
Rule_AddInterval(Rule_Orks_GeneratorDefense, 1)
Rule_AddIntervalDelay(Rule_Orks_FindGenerator, 1, 60)

Rule_AddInterval(Rule_Orks_AIDefendsBase, 2)
Rule_AddInterval(Rule_Orks_AITurnOn, 1)

Rule_AddInterval(Rule_Orks_GetAll, 5)

end

--[[ A general rule that gets all orks for various functions to use ]] function Rule_Orks_GetAll()

SGroup_AddGroup(g_sgallorksID, Player_GetSquads(g_Player2))

end

function Rule_RandomOrk()

local blue = {"ork_squad_slugga", "ork_squad_shoota_boy", "ork_squad_tankbusta", "ork_squad_slugga", "ork_squad_stormboy" }
local rand = World_GetRand(1, table.getn(blue))
return blue[rand]

end

--[[ make the starting Orks ]]

function Rule_Orks_CreateGeneratorDefense()

--[[ Generator defense ]]
for i = 1, 3 do
	local rand = World_GetRand(6, 9)
	local sgroupID  = Util_CreateSquadsAtMarkerRandomEx(g_Player2, "sg_ork_gendef"..i, Rule_RandomOrk(), "mkr_ork_generator", 1, rand)
	SGroup_AddLeaders("sg_ork_gendef"..i)
	SGroup_AddGroup(g_sgorksID, sgroupID)
	Cpu_LockSGroup(g_Player2, "sg_ork_gendef"..i)
end

end

--[[ INITIAL PROGRESSION ]]

-- this is the chunk of code that controls the opening sequence of events -- it's located inthe ORK section because this was the easiest place to put it --when I hacked it in. - deg

function Rule_Orks_StartersReplenish()

if SGroup_Count(SGroup_FromName("sg_ork_start")) < 5 then
	local rand = World_GetRand(3, 5)
	local sgroupID  = Util_CreateSquadsAtMarkerRandomEx(g_Player2, "sg_ork_start", Rule_RandomOrk(), "mkr_ork_sewer6", 1, rand)
	SGroup_AddGroup(g_sgorksID, sgroupID)
	Cpu_LockSGroup(g_Player2, "sg_ork_start")
	Cmd_AttackMoveMarker("sg_ork_start", "mkr_chaos_start2")
end

end

function Rule_Orks_WarbossBacksOff()

if Event_IsAnyRunning() == false then
	Cmd_MoveToMarker("sg_ork_leader", "mkr_ork_sewer6")
	Cmd_CastAbilitySelf("sg_ork_leader", "ork_warboss_throw_sp")
	
	Util_StartIntel(EVENTS.IE_GorgutzGetsAway1)
	
	Rule_AddInterval(Rule_Chaos_CallstoStop, 1)
	
	Rule_Remove(Rule_Orks_WarbossBacksOff)
end

end

function Rule_Chaos_CallstoStop() if Event_IsAnyRunning() == false then Util_StartIntel(EVENTS.IE_GorgutzGetsAway2)

	Rule_AddInterval(Rule_Orks_WarbossFirstFlee, 3)
	
	Rule_Remove(Rule_Chaos_CallstoStop)
end

end

--[[ Warboss Teases - flees the first time ]] -- this is the first step to introducing the player to the game mechanics function Rule_Orks_WarbossFirstFlee()

if SGroup_IsEmpty("sg_ork_leader") == false and Prox_AnySquadNearMarker("sg_ork_leader", "mkr_ork_sewer6") then
	SGroup_DeSpawn("sg_ork_leader")
	g_warbossdespawned = true
	
	Util_StartIntel(EVENTS.IE_GorgutzGetsAway3)
	
	--[[ START THE PROGRESSION ]]
	--[[ contingency for player deleting temples ]]
	if EGroup_IsEmpty("eg_temple4") == false then
		Rule_AddOneShot(Rule_Prog_GoToTemple, 25)
	else
		Rule_AddOneShot(Rule_Prog_Timeout1, 25)
	end
	
	Rule_Remove(Rule_Orks_WarbossFirstFlee)
else
	Cmd_MoveToMarker("sg_ork_leader", "mkr_ork_sewer6")
end

end

--[[ Get Crull to the Temple ]] function Rule_Prog_GoToTemple()

if EGroup_IsEmpty("eg_temple4") == false then
	--[[ INTEL EVENT ]]
	Util_StartIntel(EVENTS.IE_CrullTempleIntro)
	Util_Ping_LoopingMkr("png_temple", "mkr_chaos_templestart")
	g_templebeaconID = Util_CreateBeaconMarker_Red("mkr_chaos_templestart")
	
	--[[ anti stall out contingency ]]
	Rule_AddOneShot(Rule_Prog_Timeout2, 120)
	
	Rule_AddInterval(Rule_Prog_GoToTemple_Check, 1)
elseif EGroup_IsEmpty("eg_alltemples") == false then
	Rule_AddOneShot(Rule_Prog_Timeout1, 0)
else
	
	--[[ contingency for player deleting temples ]]
	Rule_AddOneShot(Rule_Prog_Timeout1, 0)
	
end

end

--[[ Check to see if he's there ]] function Rule_Prog_GoToTemple_Check() if SGroup_Exists("sg_chaos_lord") and SGroup_CountDeSpawned(SGroup_FromName("sg_chaos_lord")) == 0 and SGroup_IsEmpty("sg_chaos_lord") == false and Prox_AnySquadNearMarker("sg_chaos_lord", "mkr_chaos_templestart") then

	Util_RemoveBeaconMarker(g_templebeaconID)
	Util_Ping_Stop("png_temple")
	g_templebeaconID = nil
	
	if EGroup_IsEmpty("eg_temple4") == false then
		--[[ INTEL EVENT ]]
		Rule_AddOneShot(Rule_IE_LordHealing, 0)
		Rule_AddIntervalDelay(Rule_Prog_SummonBezerkers, 1, 1)
		Rule_Remove(Rule_Prog_GoToTemple_Check)
	else
		--[[ contingency for player deleting temples ]]
		Rule_Check_Remove(Rule_Prog_Timeout1)
		Rule_AddOneShot(Rule_Prog_Timeout1, 0)
		Rule_Remove(Rule_Prog_GoToTemple_Check)
	end
		
	
end

end

function Rule_Prog_SummonBezerkers()

if Event_IsAnyRunning() == false and EGroup_IsEmpty("eg_temple4") == false then
	--[[ INTEL EVENT ]]
	Util_StartIntel(EVENTS.IE_CrullSummonBezNow)
	
	--[[ Add the Summon Objective ]]
	Rule_AddInterval(Rule_Objective_SummonBez, 1)
	
	Rule_AddInterval(Rule_Prog_BezerkersHaveBeenSummoned, 1)
	Rule_Remove(Rule_Prog_SummonBezerkers)
elseif EGroup_IsEmpty("eg_temple4") then
	
	--[[ contingency for player deleting temples ]]
		Rule_Check_Remove(Rule_Prog_Timeout1)
	Rule_AddOneShot(Rule_Prog_Timeout1, 0)
	Rule_Remove(Rule_Prog_SummonBezerkers)
	
end

end

function Rule_Prog_BezerkersHaveBeenSummoned()

if g_summonedbez == true and EGroup_IsEmpty("eg_temple4") == false then
	g_obj_summonbez = true
	Sound_PlayStinger("stinger_msd5c_bloodforthebloodgod")	
	
	if g_firstprogskip ~= true and g_secprogskip ~= true then
		Rule_AddInterval(Rule_Autosave_SummonBez, 1)
		g_firsttempleattack = true
		Rule_AddOneShot(Rule_Prog_OrksAttackTemple, 17)
	end
	
	Rule_AddOneShot(Rule_Prog_Timeout1, 10)
	
	Rule_Remove(Rule_Prog_BezerkersHaveBeenSummoned)
	
elseif EGroup_IsEmpty("eg_temple4") then
	
	--[[ contingency for player deleting temples ]]
		Rule_Check_Remove(Rule_Prog_Timeout1)
	Rule_AddOneShot(Rule_Prog_Timeout1, 0)
	Rule_Remove(Rule_Prog_BezerkersHaveBeenSummoned)
	
end

end

--[[ this is to keep the game from hanging if the player doesn't move past this point ]] function Rule_Prog_Timeout1()

g_firstprogskip = true

if g_firsttempleattack == nil and g_secprogskip ~= true then
	Rule_AddOneShot(Rule_Prog_OrksAttackTemple, 17)
end

end --[[ this is to keep the game from hanging if the player doesn't move past this point ]] function Rule_Prog_Timeout2()

g_secprogskip = true

if g_firsttempleattack == nil and g_firstprogskip ~= true then
	Rule_AddOneShot(Rule_Prog_OrksAttackTemple, 17)
end

end

--[[ Attack a Temple ]] function Rule_Prog_OrksAttackTemple()

local rand = World_GetRand(4, 6)
local sgroupID  = Util_CreateSquadsAtMarkerRandomEx(g_Player2, "sg_ork_temple", "ork_squad_slugga", "mkr_ork_sewer1", 2, rand)
SGroup_AddGroup(g_sgorksID, sgroupID)
Cpu_LockSGroup(g_Player2, "sg_ork_temple")
Cmd_MoveToMarker("sg_ork_temple", "mkr_prog_temple3")

Rule_AddOneShot(Rule_IE_CrullDefendTemple, 10)

end

function Rule_IE_CrullDefendTemple() --[[ INTEL EVENT ]] Util_StartIntel(EVENTS.IE_CrullTempleInDanger) Util_Ping_LoopingMkr("png_temple3", "mkr_prog_temple3") g_temple3beaconID = Util_CreateBeaconMarker_Red("mkr_prog_temple3")

if EGroup_IsEmpty("eg_alltemples") == false then
	--[[ Add the Defend Temple Objective ]]
	Rule_AddInterval(Rule_Objective_ProtectTemples, 1)
end

Rule_AddInterval(Rule_Prog_FirstTempleOutofDanger, 1)

end

function Rule_Prog_FirstTempleOutofDanger()

if SGroup_IsEmpty("sg_ork_temple") or EGroup_IsEmpty("eg_temple3") then
	
	--[[ INTEL EVENT ]]
	Util_StartIntel(EVENTS.IE_CrullArmOurselves)
	
	Util_RemoveBeaconMarker(g_temple3beaconID)
	Util_Ping_Stop("png_temple3")
	
	
	
	
	
	--[[ AND NOW THE REAL STUFF BEGINS ]]
	------------------------------------------------------------------------------------------------------
	
	--[[ this is the random Orks attacking the Temples ]]
	--[[ BALANCE - deg ]]
	local delay = 40
	Rule_AddIntervalDelay(Rule_Orks_TempleAttack, 10, delay)
	
	--[[ This is the warning message manager for the Temples ]]
	g_templewarninglimit = 0
	g_lasttemplecount = EGroup_Count(EGroup_FromName("eg_alltemples"))
	Rule_AddInterval(Rule_Chaos_TempleUnderAttack, 1)
	
	Rule_Check_AddInterval(Rule_Objective_OrkPowerBase, 1)
	
	--[[ This is the warning for defenses on Posts and Pop Cap ]]
	Rule_AddIntervalDelay(Rule_Chaos_PostMessage, 1, 65)
	Rule_AddIntervalDelay(Rule_Chaos_PopCapMessage, 1, 115)
	
	--[[ THE WARBOSS ATTACKING THE TEMPLES ]]
	--[[ BALANCE handle - deg ]]
	t_sewerrange = {low = 3, high = 5}
	
	g_orklastaction = 0
	t_active = {ping = 0, beacon = 0}
	-- this is the warboss attacking the temples
	Rule_AddIntervalDelay(Rule_Orks_TempleManager, 1, 15)
	
	
	Util_Music_CreateSingleLoop( {"music_msd1_perc_choir"}, {"music_msd1_perc"}, 140 )
	
	Rule_Remove(Rule_Prog_FirstTempleOutofDanger)
end

end

--[[ AI BEHAVIOR FUNCTIONS ]]

--[[ lock stuff so the AI can't have it ]] function Rule_Ork_Restrictions()

--[[ restrict the following not based on precaching ]]

Player_RestrictSquad(g_Player2, "ork_squad_warboss")

end --[[ Orks attack the Chaos Temples ]] function Rule_Orks_TempleAttack()

if EGroup_IsEmpty("eg_temple2") and EGroup_IsEmpty("eg_temple3") and EGroup_IsEmpty("eg_temple4") then
	Rule_AddInterval(Rule_Orks_FinalTemple, 5)
	Rule_Remove(Rule_Orks_TempleAttack)
end

if SGroup_Exists("sg_orks_templeattack") == false or SGroup_IsEmpty("sg_orks_templeattack") then
	local count = 0 
	if SGroup_IsEmpty("sg_allorks") == false then 
		count = SGroup_CountSpawned(g_sgallorksID) 
		if count > 4 then
			for i = 1, g_templeattack do 
				SGroup_Add(SGroup_CreateIfNotFound("sg_orks_templeattack"), SGroup_GetSpawnedSquadAt(g_sgallorksID, count-i))
			end
		end
	end
	if SGroup_Exists("sg_orks_templeattack") and SGroup_IsEmpty("sg_orks_templeattack") == false then
		Cpu_LockSGroup(g_Player2, "sg_orks_templeattack")
		
		local targets = {}
		for i = 2, 4 do
			if EGroup_IsEmpty("eg_temple"..i) == false then table.insert(targets, "eg_temple"..i) end
		end
		if table.getn(targets) > 0 then
			local rand = World_GetRand(1, table.getn(targets))
			Cmd_AttackEGroup("sg_orks_templeattack", targets[rand])
		end
	end
end

end

--[[ Orks attack the last remaining Temple ]] function Rule_Orks_FinalTemple()

if EGroup_IsEmpty("eg_temple1") then
	
	Rule_Remove(Rule_Orks_FinalTemple)
	
end

if SGroup_Exists("sg_orks_templeattack") == false or SGroup_IsEmpty("sg_orks_templeattack") then
	local count = 0 
	if SGroup_IsEmpty("sg_allorks") == false then 
		count = SGroup_CountSpawned(g_sgallorksID) 
		if count > 4 then
			for i = 1, g_templeattack do 
				SGroup_Add(SGroup_CreateIfNotFound("sg_orks_templeattack"), SGroup_GetSpawnedSquadAt(g_sgallorksID, i))
			end
		end
	end
	if SGroup_Exists("sg_orks_templeattack") and SGroup_IsEmpty("sg_orks_templeattack") == false then
		Cpu_LockSGroup(g_Player2, "sg_orks_templeattack")
		
		Cmd_AttackEGroup("sg_orks_templeattack", "eg_temple1")
	end
end

end

--[[ THE AI DEFENDS ITS BASE ]]

function Rule_Orks_AITurnOn()

if g_orkAIon == false then
	g_orkAIon = true
	Cpu_EnableComponent(g_Player2, true,  CT_Attacking)
	Cpu_SetDifficulty(g_Player2,   AD_Standard)
	Rule_Remove(Rule_Orks_AITurnOn)
end

end

function Rule_Orks_AIDefendsBase() if EGroup_IsEmpty("eg_ork_base") == false and EGroup_IsUnderAttackByPlayer("eg_ork_base", false, g_Player1 ) then

	if g_orkAIon ~= true then
		g_orkAIon = true
		Cpu_EnableComponent(g_Player2, true,  CT_Attacking)
		Rule_Check_Remove(Rule_Orks_AITurnOn)
	end
	
	--[[ trying changing the difficulty rather than turning attacking on and off ]]
	--[[ balance ]]
	Cpu_SetDifficulty(g_Player2,   AD_Hard)
	
	--[[ ADD OBJECTIVE ]]
	g_obj_findbase = true
	Rule_Check_AddInterval(Rule_Objective_OrkPowerBase, 1)
	
	Rule_AddIntervalDelay(Rule_Orks_AIgoesDormantAgain, 5, 30)
	Rule_Remove(Rule_Orks_AIDefendsBase)
elseif EGroup_IsEmpty("eg_ork_base") then
	g_obj_destbase = true
	Rule_Remove(Rule_Orks_AIDefendsBase)
end

end

function Rule_Orks_AIgoesDormantAgain() if EGroup_IsEmpty("eg_ork_base") == false and EGroup_IsUnderAttackByPlayer("eg_ork_base", false, g_Player1 ) == false then

	--[[ trying changing the difficulty rather than turning attacking on and off ]]

-- Cpu_EnableComponent(g_Player2, false, CT_Attacking) --[[ balance ]] Cpu_SetDifficulty(g_Player2, AD_Standard)

	Rule_AddInterval(Rule_Orks_AIDefendsBase, 2)
	Rule_Remove(Rule_Orks_AIgoesDormantAgain)
elseif EGroup_IsEmpty("eg_ork_base") then
	g_obj_destbase = true
	Rule_Remove(Rule_Orks_AIgoesDormantAgain)
end

end

--[[ WARBOSS FORCE FIELD FUNCTIONS ]]

-- this is to keep the Warboss alive, cause we can't kill him - deg function Rule_Orks_WarbossForceField_On()

if SGroup_IsEmpty("sg_ork_leader") == false and SGroup_CountDeSpawned(SGroup_FromName("sg_ork_leader")) == 0 and SGroup_GetAvgHealth("sg_ork_leader") < 0.5 then
	
	CustUtil_Invulnerable("sg_ork_leader")
	SGroup_SetAvgHealth("sg_ork_leader", 0.52)
	
	--[[ INTEL EVENT ]]
	Rule_Check_AddOneShot(Rule_IE_FieldUp, 0)
	

-- Rule_Check_AddOneShot(Rule_Orks_FindGenerator, 300) if g_genspot == nil and Rule_Exists(Rule_Orks_GeneratorSpotted) == false then Rule_AddIntervalDelay(Rule_Orks_GeneratorSpotted, 1, 45) end

	Rule_AddOneShot(Rule_Orks_WarbossForceField_Off, 30)
	
	Rule_Remove(Rule_Orks_WarbossForceField_On)
end

end

function Rule_IE_FieldUp() if g_IE_FieldUp == nil then Util_StartIntel(EVENTS.IE_GorgutzFieldUp) Util_StartIntel(EVENTS.IE_CrullFindPowerSource) end g_IE_FieldUp = true end

function Rule_Orks_WarbossForceField_Off()

g_vulnerabletarget = "sg_ork_leader"
Rule_AddInterval(CustUtil_Vulnerable, 1)

end

--[[ INVULNERABILITY UTILITY FUNCTION ]] function CustUtil_Invulnerable(sgroupname)

Rule_Check_Remove(CustUtil_Vulnerable)

if SGroup_CountDeSpawned(SGroup_FromName(sgroupname)) == 0 and g_invulnerable == false then
	
	
	g_vulnerable = false
	g_invulnerable = true
	SGroup_SetHealthInvulnerable(sgroupname, true)
	

-- Player_UnRestrictAbility(g_Player6, "sp_dxp_abilities_warbossforcefield") Cmd_CastAbilitySelf(sgroupname, "sp_dxp_abilities_warbossforcefield") -- print("inv on")

	Rule_Remove(CustUtil_Invulnerable)
elseif g_invulnerable == true then
	Rule_Remove(CustUtil_Invulnerable)

-- print("inv - no change - on") end end

function CustUtil_Vulnerable()

Rule_Check_Remove(CustUtil_Invulnerable)

if SGroup_CountDeSpawned(SGroup_FromName("sg_ork_leader")) == 0 and g_vulnerable == false then
	
	g_vulnerable = true
	g_invulnerable = false
	SGroup_SetHealthInvulnerable("sg_ork_leader", false)

-- print("inv off")

-- Player_RestrictAbility(g_Player6, "sp_dxp_abilities_warbossforcefield")

	if g_gendead ~= true then
		Rule_Check_AddInterval(Rule_Orks_WarbossForceField_On, 1)
	end
	Rule_Remove(CustUtil_Vulnerable)
elseif g_vulnerable == true then
	
	if g_gendead ~= true then
		Rule_Check_AddInterval(Rule_Orks_WarbossForceField_On, 1)
	end
	Rule_Remove(CustUtil_Vulnerable)

-- print("inv - no change - off") end end

--[[ this is used to turn off the Forcefield functions once the generator is destroyed ]] function Rule_Orks_GeneratorDead_FieldOff()

g_gendead = true

Rule_Check_Remove(Rule_Orks_WarbossForceField_Off) 
Rule_Check_Remove(Rule_Orks_WarbossForceField_On) 

if Rule_Exists(CustUtil_Vulnerable) == false then
	Rule_AddInterval(CustUtil_Vulnerable, 1)
end

Rule_Add(Rule_Orks_Warboss_LastBreath)

end

--[[ Warboss Last Breath ]] -- catch when the Warboss Dies function Rule_Orks_Warboss_LastBreath()

if SGroup_IsEmpty("sg_ork_leader") == false and SGroup_CountDeSpawned(SGroup_FromName("sg_ork_leader")) == 0 and SGroup_GetAvgHealth("sg_ork_leader") < 0.01 then
	SGroup_SelfDestroy("sg_ork_leader", true)
	
	--[[ INTEL EVENT ]]
	
	if t_active ~= nil and t_active.ping ~= nil and t_active.ping ~= 0 then
		Util_Ping_Stop(t_active.ping)
		Util_RemoveBeaconMarker(t_active.beacon)
	end
	
	g_obj_huntboss = true
	g_obj_lord2boss = true
	
	Util_SGroupAbilityButton_Remove(g_bezbuttonID)
	Rule_Remove(Rule_Orks_Warboss_LastBreath)
	
elseif SGroup_IsEmpty("sg_ork_leader") then
	
	if t_active ~= nil and t_active.ping ~= nil and t_active.ping ~= 0 then
		Util_Ping_Stop(t_active.ping)
		Util_RemoveBeaconMarker(t_active.beacon)
	end
	
	Util_SGroupAbilityButton_Remove(g_bezbuttonID)
	g_obj_huntboss = true
	g_obj_lord2boss = true
	
	Rule_Remove(Rule_Orks_Warboss_LastBreath)	
else
	if Rule_Exists(CustUtil_Vulnerable) == false then
		CustUtil_Vulnerable("sg_ork_leader")
	end
end

end

--[[ GENERATOR FUNCTIONS ]]

--[[ this is to point out the generator if the player finds it before triggering the forcefield ]] function Rule_Orks_FindGenerator()

if g_genspot == nil and EGroup_Exists("eg_ork_energysource") and EGroup_IsEmpty("eg_ork_energysource") == false and Player_CanSeeEGroup(g_Player1, "eg_ork_energysource", false) then
	
	g_genspot = true
	Rule_Check_Remove(Rule_Orks_GeneratorSpotted) 
	
	for i = 1, 3 do
		if SGroup_IsEmpty("sg_ork_gendef"..i) == false then
			Cmd_AttackMoveMarker("sg_ork_gendef"..i, "mkr_ork_gendef"..i)
		end
	end
	
	--[[ INTEL EVENT ]]
	Util_StartIntel(EVENTS.IE_CrullSourceFound)
	Util_Ping_LoopingMkr("png_generator", "mkr_ork_generator")
	g_genbeaconID = Util_CreateBeaconMarker_Red("mkr_ork_generator")
	FOW_RevealMarker("mkr_ork_generator", 60)
	
	--[[ ADD OBJECTIVE ]]
	Rule_AddIntervalDelay( Rule_Objective_DestroyPowerSource, 1, 5)
	
	Rule_Remove(Rule_Orks_FindGenerator) 
	
elseif g_genspot ~= nil then
	Rule_Remove(Rule_Orks_FindGenerator) 
end

end

--[[ this is when the Player spots the Generator ]] function Rule_Orks_GeneratorSpotted()

if Event_IsAnyRunning() == false and g_genspot == nil then
	
	g_genspot = true
	Rule_Check_Remove(Rule_Orks_FindGenerator) 
	
	for i = 1, 3 do
		if SGroup_IsEmpty("sg_ork_gendef"..i) == false then
			Cmd_AttackMoveMarker("sg_ork_gendef"..i, "mkr_ork_gendef"..i)
		end
	end
	
	--[[ INTEL EVENT ]]
	Util_StartIntel(EVENTS.IE_CrullSourceFound)
	Util_Ping_LoopingMkr("png_generator", "mkr_ork_generator")
	g_genbeaconID = Util_CreateBeaconMarker_Red("mkr_ork_generator")
	FOW_RevealMarker("mkr_ork_generator", 60)
	Camera_FocusOnTargetMarker("mkr_ork_generator", -1)
	
	--[[ ADD OBJECTIVE ]]
	Rule_AddIntervalDelay( Rule_Objective_DestroyPowerSource, 1,5)
	
	Rule_Remove(Rule_Orks_GeneratorSpotted) 
	
elseif g_genspot ~= nil then
	
	Rule_Remove(Rule_Orks_GeneratorSpotted) 
end

end

--[[ the orks show up to defend the Generator ]] function Rule_Orks_GeneratorDefense()

if EGroup_Exists("eg_ork_energysource") and EGroup_IsEmpty("eg_ork_energysource") == false and EGroup_IsUnderAttackByPlayer("eg_ork_energysource", false, g_Player1) then
	
	--[[ INTEL EVENT ]]
	Util_StartIntel(EVENTS.IE_GorgutzFieldGetAway)
	
	local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player2, "sg_ork_gendefense", "ork_squad_wartrak", "mkr_orks_sourcedefense", 2, 1)
	SGroup_AddGroup(g_sgorksID, sgroupID)		
	Cpu_LockSGroup(g_Player2, "sg_ork_gendefense")
	local pos = EGroup_GetPosition(EGroup_FromName("eg_ork_energysource"))
	Cmd_AttackMovePos("sg_ork_gendefense", pos)
	
	Rule_AddInterval(Rule_Orks_GeneratorDestroyed, 1)
	
	Rule_Remove(Rule_Orks_GeneratorDefense) 
end

end

--[[ the generator is destroyed ]] function Rule_Orks_GeneratorDestroyed()

if EGroup_Exists("eg_ork_energysource") and EGroup_IsEmpty("eg_ork_energysource") then
	
	--[[ INTEL EVENT ]]
	Util_StartIntel(EVENTS.IE_GorgutzFieldBroken)
	Util_Ping_Stop("png_generator")
	Util_RemoveBeaconMarker(g_genbeaconID)
	
	g_obj_destpower = true
	
	Rule_AddOneShot(Rule_Orks_GeneratorDead_FieldOff, 0)
	Rule_AddOneShot(Rule_Orks_WarbossStayOutAndPlay, 1)
	
	Rule_Remove(Rule_Orks_GeneratorDestroyed) 
end

end

function Rule_Orks_WarbossStayOutAndPlay()

--[[ remove all of the other sewer rules ]]
local RemoveRules = {
	Rule_Orks_TempleManager, 
	Rule_Orks_2ndTempleStart, 
	Rule_Orks_2ndTempleCreate, 
	Rule_Orks_2ndTempleAttack, 
	Rule_Orks_2ndTempleFlee, 
	Rule_Orks_3rdTempleStart, 
	Rule_Orks_3rdTempleCreate, 
	Rule_Orks_3rdTempleAttack, 
	Rule_Orks_3rdTempleFlee, 
	Rule_Orks_4thTempleStart, 
	Rule_Orks_4thTempleCreate, 
	Rule_Orks_4thTempleAttack, 
	Rule_Orks_4thTempleFlee, 
	Rule_Orks_1stTempleStart, 
	Rule_Orks_1stTempleCreate, 
	Rule_Orks_1stTempleAttack, 
	Rule_Orks_1stTempleFlee, 
	Rule_Orks_GrotAttack, 
}
for i = 1, table.getn(RemoveRules) do
	Rule_Check_Remove( RemoveRules[i] )
end

--[[ find out where the warboss is, spawned or despawned, and keep him out ]]
if g_warbossdespawned == false then
	Cmd_MoveToMarker("sg_ork_leader", "mkr_ork_boss_rally3")
elseif g_warbossdespawned == true then
	SGroup_ReSpawnMarker("sg_ork_leader", "mkr_ork_sewer3")
	SGroup_SetAvgHealth("sg_ork_leader", 1.0)
end

local mod_bosshealthregen = Modifier_Create(MAT_EntityType, "health_regeneration_modifier", MUT_Multiplication, false, 2, "ork_warboss")
Modifier_ApplyToPlayer( mod_bosshealthregen, g_Player6)	

--[[ move the warboss to mkr_ork_boss_rally3 ]]
Cmd_MoveToMarker("sg_ork_leader", "mkr_ork_boss_rally3")

--[[ BALANCE hook up ]]
t_temples = {
	{mkr = "temple1", delay = 55}, 
	{mkr = "temple2", delay = 55}, 
	{mkr = "temple3", delay = 55},
	{mkr = "rally1", delay = 20},
	{mkr = "rally2", delay = 15},
	{mkr = "rally3", delay = 20},
	{mkr = "rally4", delay = 17},
}
g_delay = 0
Rule_AddInterval(Rule_Orks_WarbossOnTheRun, 1)
Rule_AddInterval(Rule_Orks_WarbossCallingOutTheBoyz, 5)

end

function Rule_Orks_WarbossOnTheRun()

if g_delay == 0 then
	--[[ managing where he will move to ]]
	for i = table.getn(t_temples), 1, -1 do
		if EGroup_Exists("eg_"..t_temples[i].mkr) and EGroup_IsEmpty("eg_"..t_temples[i].mkr) then
			table.remove(t_temples, i)
		end
	end
	if g_lastchance == nil and table.getn(t_temples) < 6 then
		table.insert(t_temples, {mkr = "temple4", delay = 40})
		g_lastchance = true
	elseif table.getn(t_temples) < 5 then 
		table.insert(t_temples, {mkr = "rally5", delay = 40})
	end
	
	--[[ move the warboss in between Temples 1, 2 and 3 ]]
	local rand = World_GetRand(1, table.getn(t_temples))
	if SGroup_Exists("sg_ork_leader") and SGroup_IsEmpty("sg_ork_leader") == false then
		Cmd_MoveToMarker("sg_ork_leader", "mkr_chaos_"..t_temples[rand].mkr)
	end
	
	g_delay = World_GetRand(t_temples[rand].delay-10, t_temples[rand].delay+10)
	
else
	g_delay = g_delay - 1
end

end

function Rule_Orks_WarbossCallingOutTheBoyz()

--[[ balance handle ]]
g_callingoutboyz = 8

--[[ create boyz from random sewers ]]
if SGroup_Exists("sg_ork_final") == false or SGroup_Count(SGroup_FromName("sg_ork_final")) < g_callingoutboyz then
	local rand1 = World_GetRand(1, 6)
	local rand2 = World_GetRand(4, 6)
	local sgroupID  = Util_CreateSquadsAtMarkerRandomEx(g_Player2, "sg_ork_final_spawn", Rule_RandomOrk(), "mkr_ork_sewer"..rand1, 2, rand2)
	SGroup_AddGroup(g_sgorksID, sgroupID)
	SGroup_AddGroup(SGroup_CreateIfNotFound("sg_ork_final"), sgroupID)
	Cpu_LockSGroup(g_Player2, "sg_ork_final_spawn")
	if SGroup_Exists("sg_ork_leader") and SGroup_IsEmpty("sg_ork_leader") == false then
		Cmd_MoveToSGroup("sg_ork_final_spawn", "sg_ork_leader")
	end
end

--[[ if they get withing 20 meters of the boss, move them out of their current group, into a new group and order them to attack the current Temple Target ]]
local RemoveSquadWhenClose = function(sgroupID, itemindex, squadID)
	local pos = Squad_GetPosition(squadID)
	if World_DistanceSGroupToPoint(SGroup_FromName("sg_ork_leader"), pos, true) < 12 then
		SGroup_Add(SGroup_CreateIfNotFound("sg_ork_final_rush"), squadID)
		SGroup_Remove(sgroupID, squadID)
	end
	return false
end
if SGroup_Exists("sg_ork_leader") and SGroup_IsEmpty("sg_ork_leader") == false 
and SGroup_Exists("sg_ork_final_spawn") and SGroup_IsEmpty("sg_ork_final_spawn") == false then
	
	SGroup_ForEach(SGroup_FromName("sg_ork_final_spawn"), RemoveSquadWhenClose)
	
	local rand = World_GetRand(1, table.getn(t_temples))
	if SGroup_Exists("sg_ork_final_rush") and SGroup_IsEmpty("sg_ork_final_rush") == false then
		Cmd_AttackMoveMarker("sg_ork_final_rush", "mkr_chaos_"..t_temples[rand].mkr)
	end
end

end

--[[ THE TEMPLE ATTACK MANAGER ]] -- this should take care of spawning the Orks at the appropriate places -- to attack the temples function Rule_Orks_TempleManager()

local t_sewerRules = {Rule_Orks_1stTempleStart, Rule_Orks_2ndTempleStart, Rule_Orks_3rdTempleStart, Rule_Orks_4thTempleStart, Rule_Orks_GrotAttack}

if EGroup_IsEmpty("eg_bordertemples") then
	
	local rand = World_GetRand(1, 2)
	
	if rand == 1 then
		Rule_AddOneShot(t_sewerRules[1], 30)
	elseif g_orklastaction ~= 2 then
		g_grotiter = 0
		Rule_AddIntervalDelay(t_sewerRules[5], 8, 55)
	end
	
	g_orklastaction = rand
	Rule_Remove(Rule_Orks_TempleManager)
	
else
	
	local rand = 2
	if g_firstcall == nil then
		rand = 2
		g_firstcall = true
	else
		rand = World_GetRand(2, 5)
	end
	
	if rand < 5 then
		if EGroup_IsEmpty("eg_temple"..rand) == false then 
			Rule_AddOneShot(t_sewerRules[rand], 30) 
			Rule_Remove(Rule_Orks_TempleManager)
		end
	elseif g_orklastaction ~= 5 then
		g_grotiter = 0
		Rule_AddIntervalDelay(t_sewerRules[5], 8, 55)
		Rule_Remove(Rule_Orks_TempleManager)
	end
	
	g_orklastaction = rand
	
end

end

--[[ ORKS at the 2nd Temple ]]

function Rule_Orks_2ndTempleStart()

--[[ BALANCE handle - deg ]]
g_2ndtempleorks = 4
g_2nditerations = 0

--[[ INTEL EVENT ]]
Util_StartIntel(EVENTS.IE_CrullGorgutzSpotted1)
Util_Ping_LoopingMkr("png_sewer4", "mkr_ork_boss_rally4")
t_active.ping = "png_sewer4"
t_active.beacon = Util_CreateBeaconMarker_Red("mkr_ork_boss_rally4")

SGroup_ReSpawnMarker("sg_ork_leader", "mkr_ork_sewer4")
SGroup_SetAvgHealth("sg_ork_leader", 1.0)
g_warbossdespawned = false	

Cmd_MoveToMarker("sg_ork_leader", "mkr_ork_boss_rally4")

Rule_AddIntervalDelay(Rule_Orks_2ndTempleCreate, 1, 5)

end

function Rule_Orks_2ndTempleCreate()

if SGroup_IsEmpty("sg_ork_leader") == false and Prox_AnySquadNearMarker("sg_ork_leader", "mkr_ork_boss_rally4") then
	
	if SGroup_CountSpawned(g_sgorksID) < g_2ndtempleorks then
		
		local chance = World_GetRand(1, 3)
		if chance < 3 then
			local rand = World_GetRand(t_sewerrange.low, t_sewerrange.high)
			local sgroupID  = Util_CreateSquadsAtMarkerEx(g_Player2, "sg_ork_sewer"..g_time, Rule_RandomOrk(), "mkr_ork_sewer4", 2, rand)
			SGroup_AddGroup(SGroup_CreateIfNotFound("sg_ork_sewer"), sgroupID)		
			Cpu_LockSGroup(g_Player2, "sg_ork_sewer")
			SGroup_AddGroup(g_sgorksID, sgroupID)		
			Cmd_AttackSGroup("sg_ork_sewer"..g_time, "sg_ork_leader")
		end
		
	end
	
end

--[[ BALANCE handle - deg]]
if g_2nditerations >= 8 or g_invulnerable == true then
	Rule_AddInterval(Rule_Orks_2ndTempleFlee, 1)
	Rule_Remove(Rule_Orks_2ndTempleCreate)
else
	Rule_AddOneShot(Rule_Orks_2ndTempleAttack, 5)
	Rule_Remove(Rule_Orks_2ndTempleCreate)		
end

g_2nditerations = g_2nditerations+1

end

--this is where they charge their targets function Rule_Orks_2ndTempleAttack()

if EGroup_IsEmpty("eg_temple2") == false then
	
	if SGroup_Exists("sg_ork_sewer") and SGroup_IsEmpty("sg_ork_sewer") == false and EGroup_IsEmpty("eg_temple2") == false then
		Cmd_AttackEGroup("sg_ork_sewer", "eg_temple2")
	end
	
	Rule_AddIntervalDelay(Rule_Orks_2ndTempleCreate, 1, World_GetRand(5, 7))
	
else
	Rule_Check_AddInterval(Rule_Orks_2ndTempleFlee, 1)
end

end

-- if their spawn point dies they flee function Rule_Orks_2ndTempleFlee()

if SGroup_IsEmpty("sg_ork_leader") == false then
	
	--[[ If the Power Generator is not dead yet ]]
	if g_obj_destpower ~= true then
		--[[ the warboss will flee as normal ]]
		if Prox_AnySquadNearMarker("sg_ork_leader", "mkr_ork_sewer4") then
			
			SGroup_DeSpawn("sg_ork_leader")
			g_warbossdespawned = true
			
			--[[ INTEL EVENT ]]
			if Event_IsAnyRunning() == false then
				Util_StartIntel(EVENTS.IE_GorgutzEscapes1)
			end
			Util_Ping_Stop(t_active.ping)
			Util_RemoveBeaconMarker(t_active.beacon)
			t_active = {ping = 0, beacon = 0}
			
			Rule_AddIntervalDelay(Rule_Orks_TempleManager, 1, 45)
			Rule_Remove(Rule_Orks_2ndTempleFlee)
		else
			Cmd_MoveToMarker("sg_ork_leader", "mkr_ork_sewer4")
		end
		
	--[[ Once the Power Generator goes down ]]
	elseif g_obj_destpower then
		
		--[[ the warboss goes for a walk ]]
		Cmd_MoveToMarker("sg_ork_leader", "mkr_ork_boss_rally3")
		
		--[[ INTEL EVENT ]]
		if Event_IsAnyRunning() == false then
			Util_StartIntel(EVENTS.IE_GorgutzEscapes1)
		end
		Util_Ping_Stop(t_active.ping)
		Util_RemoveBeaconMarker(t_active.beacon)
		t_active = {ping = 0, beacon = 0}
		
		Rule_AddIntervalDelay(Rule_Orks_TempleManager, 1, 5)
		
		Rule_Remove(Rule_Orks_2ndTempleFlee)
	end
	
end

end

--[[ ORKS at the 3rd Temple ]]

function Rule_Orks_3rdTempleStart()

--[[ BALANCE handle - deg ]]
g_3rdtempleorks = 4
g_3rditerations = 0

--[[ INTEL EVENT ]]
Util_StartIntel(EVENTS.IE_CrullGorgutzSpotted1)
Util_Ping_LoopingMkr("png_sewer2", "mkr_ork_boss_rally2")
t_active.ping = "png_sewer2"
t_active.beacon = Util_CreateBeaconMarker_Red("mkr_ork_boss_rally2")

SGroup_ReSpawnMarker("sg_ork_leader", "mkr_ork_sewer2")
SGroup_SetAvgHealth("sg_ork_leader", 1.0)
g_warbossdespawned = false	

Cmd_MoveToMarker("sg_ork_leader", "mkr_ork_boss_rally2")

Rule_AddIntervalDelay(Rule_Orks_3rdTempleCreate, 1, 5)

end

function Rule_Orks_3rdTempleCreate()

if SGroup_IsEmpty("sg_ork_leader") == false and Prox_AnySquadNearMarker("sg_ork_leader", "mkr_ork_boss_rally2") then
	
	if SGroup_CountSpawned(g_sgorksID) < g_3rdtempleorks then
		
		local chance = World_GetRand(1, 3)
		if chance < 3 then
			local rand = World_GetRand(t_sewerrange.low, t_sewerrange.high)
			local sgroupID  = Util_CreateSquadsAtMarkerEx(g_Player2, "sg_ork_sewer"..g_time, Rule_RandomOrk(), "mkr_ork_sewer2", 2, rand)
			SGroup_AddGroup(SGroup_CreateIfNotFound("sg_ork_sewer"), sgroupID)		
			Cpu_LockSGroup(g_Player2, "sg_ork_sewer")
			SGroup_AddGroup(g_sgorksID, sgroupID)		
			Cmd_AttackSGroup("sg_ork_sewer"..g_time, "sg_ork_leader")
		end
		
	end
	
end

--[[ BALANCE handle - deg]]
if g_3rditerations >= 8 or g_invulnerable == true then
	Rule_AddInterval(Rule_Orks_3rdTempleFlee, 1)
	Rule_Remove(Rule_Orks_3rdTempleCreate)
else
	Rule_AddOneShot(Rule_Orks_3rdTempleAttack, 5)
	Rule_Remove(Rule_Orks_3rdTempleCreate)		
end

g_3rditerations =  g_3rditerations+1

end

--this is where they charge their targets function Rule_Orks_3rdTempleAttack()

if EGroup_IsEmpty("eg_temple3") == false then
	
	if SGroup_Exists("sg_ork_sewer") and SGroup_IsEmpty("sg_ork_sewer") == false and EGroup_IsEmpty("eg_temple3") == false  then
		Cmd_AttackEGroup("sg_ork_sewer", "eg_temple3")
	end
	
	Rule_AddIntervalDelay(Rule_Orks_3rdTempleCreate, 1, World_GetRand(1, 5))
	
else
	Rule_AddInterval(Rule_Orks_3rdTempleFlee, 1)
end

end

-- if their spawn point dies they flee function Rule_Orks_3rdTempleFlee()

if SGroup_IsEmpty("sg_ork_leader") == false then
	
	--[[ If the Power Generator is not dead yet ]]
	if g_obj_destpower ~= true then
		--[[ the warboss will flee as normal ]]
		if Prox_AnySquadNearMarker("sg_ork_leader", "mkr_ork_sewer2") then
			
			SGroup_DeSpawn("sg_ork_leader")
			g_warbossdespawned = true
			
			--[[ INTEL EVENT ]]
			if Event_IsAnyRunning() == false then
				Util_StartIntel(EVENTS.IE_GorgutzEscapes1)
			end
			Util_Ping_Stop(t_active.ping)
			Util_RemoveBeaconMarker(t_active.beacon)
			t_active = {ping = 0, beacon = 0}
			
			Rule_AddIntervalDelay(Rule_Orks_TempleManager, 1, 30)
			
			Rule_Remove(Rule_Orks_3rdTempleFlee)
		else
			Cmd_MoveToMarker("sg_ork_leader", "mkr_ork_sewer2")
		end
		
	--[[ Once the Power Generator goes down ]]
	elseif g_obj_destpower then
		
		--[[ the warboss goes for a walk ]]
		Cmd_MoveToMarker("sg_ork_leader", "mkr_ork_boss_rally3")
		
		--[[ INTEL EVENT ]]
		if Event_IsAnyRunning() == false then
			Util_StartIntel(EVENTS.IE_GorgutzEscapes1)
		end
		Util_Ping_Stop(t_active.ping)
		Util_RemoveBeaconMarker(t_active.beacon)
		t_active = {ping = 0, beacon = 0}
		
		Rule_AddIntervalDelay(Rule_Orks_TempleManager, 1, 5)
		
		Rule_Remove(Rule_Orks_3rdTempleFlee)
	end
	
end

end

--[[ ORKS at the 4th Temple ]]

function Rule_Orks_4thTempleStart()

--[[ BALANCE handle - deg ]]
g_4thtempleorks = 4
g_4thiterations = 0

--[[ INTEL EVENT ]]
Util_StartIntel(EVENTS.IE_CrullGorgutzSpotted1)
Util_Ping_LoopingMkr("png_sewer6", "mkr_ork_boss_rally6")
t_active.ping = "png_sewer6"
t_active.beacon = Util_CreateBeaconMarker_Red("mkr_ork_boss_rally6")

SGroup_ReSpawnMarker("sg_ork_leader", "mkr_ork_sewer6")
SGroup_SetAvgHealth("sg_ork_leader", 1.0)
g_warbossdespawned = false	

Cmd_MoveToMarker("sg_ork_leader", "mkr_ork_boss_rally6")

Rule_AddIntervalDelay(Rule_Orks_4thTempleCreate, 1, 5)

end

function Rule_Orks_4thTempleCreate()

if SGroup_IsEmpty("sg_ork_leader") == false and Prox_AnySquadNearMarker("sg_ork_leader", "mkr_ork_boss_rally6") then
	
	if SGroup_CountSpawned(g_sgorksID) < g_4thtempleorks then
		
		local chance = World_GetRand(1, 3)
		if chance < 3 then
			local rand = World_GetRand(t_sewerrange.low, t_sewerrange.high)
			local sgroupID  = Util_CreateSquadsAtMarkerEx(g_Player2, "sg_ork_sewer"..g_time, Rule_RandomOrk(), "mkr_ork_sewer6", 2, rand)
			SGroup_AddGroup(SGroup_CreateIfNotFound("sg_ork_sewer"), sgroupID)		
			Cpu_LockSGroup(g_Player2, "sg_ork_sewer")
			SGroup_AddGroup(g_sgorksID, sgroupID)		
			Cmd_AttackSGroup("sg_ork_sewer"..g_time, "sg_ork_leader")
		end
		
	end
	
end

--[[ BALANCE handle - deg]]
if g_4thiterations >= 8 or g_invulnerable == true then
	Rule_AddInterval(Rule_Orks_4thTempleFlee, 1)
	Rule_Remove(Rule_Orks_4thTempleCreate)
else
	Rule_AddOneShot(Rule_Orks_4thTempleAttack, 5)
	Rule_Remove(Rule_Orks_4thTempleCreate)		
end

g_4thiterations = g_4thiterations+1

end

--this is where they charge their targets function Rule_Orks_4thTempleAttack()

if EGroup_IsEmpty("eg_temple4") == false then
	
	if SGroup_Exists("sg_ork_sewer") and SGroup_IsEmpty("sg_ork_sewer") == false and EGroup_IsEmpty("eg_temple4") == false then
		Cmd_AttackEGroup("sg_ork_sewer", "eg_temple4")
	end
	
	Rule_AddIntervalDelay(Rule_Orks_4thTempleCreate, 1, World_GetRand(5, 7))
	
else
	Rule_AddInterval(Rule_Orks_4thTempleFlee, 1)
end

end

-- if their spawn point dies they flee function Rule_Orks_4thTempleFlee()

if SGroup_IsEmpty("sg_ork_leader") == false then
	
	--[[ If the Power Generator is not dead yet ]]
	if g_obj_destpower ~= true then
		--[[ the warboss will flee as normal ]]
		if Prox_AnySquadNearMarker("sg_ork_leader", "mkr_ork_sewer6") then
			
			SGroup_DeSpawn("sg_ork_leader")
			g_warbossdespawned = true
			
			--[[ INTEL EVENT ]]
			if Event_IsAnyRunning() == false then
				Util_StartIntel(EVENTS.IE_GorgutzEscapes1)
			end
			Util_Ping_Stop(t_active.ping)
			Util_RemoveBeaconMarker(t_active.beacon)
			t_active = {ping = 0, beacon = 0}
			
			Rule_AddIntervalDelay(Rule_Orks_TempleManager, 1, 45)
			
			Rule_Remove(Rule_Orks_4thTempleFlee)
		else
			Cmd_MoveToMarker("sg_ork_leader", "mkr_ork_sewer6")
		end
		
	--[[ Once the Power Generator goes down ]]
	elseif g_obj_destpower then
		
		--[[ the warboss goes for a walk ]]
		Cmd_MoveToMarker("sg_ork_leader", "mkr_ork_boss_rally3")
		
		--[[ INTEL EVENT ]]
		if Event_IsAnyRunning() == false then
			Util_StartIntel(EVENTS.IE_GorgutzEscapes1)
		end
		Util_Ping_Stop(t_active.ping)
		Util_RemoveBeaconMarker(t_active.beacon)
		t_active = {ping = 0, beacon = 0}
		
		Rule_AddIntervalDelay(Rule_Orks_TempleManager, 1, 5)
		
		Rule_Remove(Rule_Orks_4thTempleFlee)
	end
	
end

end

--[[ ORKS at the 1st Temple ]]

function Rule_Orks_1stTempleStart()

g_1sttempleorks = 10
g_1stiterations = 0

--[[ INTEL EVENT ]]
Util_StartIntel(EVENTS.IE_CrullGorgutzSpotted1)
Util_Ping_LoopingMkr("png_sewer3", "mkr_ork_boss_rally3")
t_active.ping = "png_sewer3"
t_active.beacon = Util_CreateBeaconMarker_Red("mkr_ork_boss_rally3")

SGroup_ReSpawnMarker("sg_ork_leader", "mkr_ork_sewer3")
SGroup_SetAvgHealth("sg_ork_leader", 1.0)
g_warbossdespawned = false	

Cmd_MoveToMarker("sg_ork_leader", "mkr_ork_boss_rally3")

Rule_AddIntervalDelay(Rule_Orks_1stTempleCreate, 1, 5)

end

function Rule_Orks_1stTempleCreate()

if SGroup_IsEmpty("sg_ork_leader") == false and Prox_AnySquadNearMarker("sg_ork_leader", "mkr_ork_boss_rally3") then
	
	if SGroup_CountSpawned(g_sgorksID) < g_1sttempleorks then
		
		local chance = World_GetRand(1, 3)
		if chance < 3 then
			local rand = World_GetRand(t_sewerrange.low, t_sewerrange.high)
			local sgroupID  = Util_CreateSquadsAtMarkerEx(g_Player2, "sg_ork_sewer"..g_time, Rule_RandomOrk(), "mkr_ork_sewer3", 2, rand)
			SGroup_AddGroup(SGroup_CreateIfNotFound("sg_ork_sewer"), sgroupID)		
			Cpu_LockSGroup(g_Player2, "sg_ork_sewer")
			SGroup_AddGroup(g_sgorksID, sgroupID)		
			Cmd_AttackSGroup("sg_ork_sewer"..g_time, "sg_ork_leader")
		end
		
	end
	
end

--[[ BALANCE handle - deg]]
if g_1stiterations >= 20 or g_invulnerable == true then
	Rule_AddInterval(Rule_Orks_1stTempleFlee, 1)
	Rule_Remove(Rule_Orks_1stTempleCreate)
else
	Rule_AddOneShot(Rule_Orks_1stTempleAttack, 5)
	Rule_Remove(Rule_Orks_1stTempleCreate)		
end

g_1stiterations = g_1stiterations+1

end

--this is where they charge their targets function Rule_Orks_1stTempleAttack()

if EGroup_IsEmpty("eg_temple1") == false then
	
	if SGroup_Exists("sg_ork_sewer") and SGroup_IsEmpty("sg_ork_sewer") == false and EGroup_IsEmpty("eg_temple1") == false then
		Cmd_AttackEGroup("sg_ork_sewer", "eg_temple1")
	end
	
	Rule_AddIntervalDelay(Rule_Orks_1stTempleCreate, 1, World_GetRand(5, 7))
	
else
	
end

end

-- if their spawn point dies they flee function Rule_Orks_1stTempleFlee()

if SGroup_IsEmpty("sg_ork_leader") == false then
	--[[ If the Power Generator is not dead yet ]]
	if g_obj_destpower ~= true then
		--[[ the warboss will flee as normal ]]
		if Prox_AnySquadNearMarker("sg_ork_leader", "mkr_ork_sewer3") then
			
			SGroup_DeSpawn("sg_ork_leader")
			g_warbossdespawned = true
			
			--[[ INTEL EVENT ]]
			if Event_IsAnyRunning() == false then
				Util_StartIntel(EVENTS.IE_GorgutzEscapes1)
			end
			Util_Ping_Stop(t_active.ping)
			Util_RemoveBeaconMarker(t_active.beacon)
			t_active = {ping = 0, beacon = 0}
			
			Rule_AddIntervalDelay(Rule_Orks_TempleManager, 1, 45)
			
			Rule_Remove(Rule_Orks_1stTempleFlee)
		else
			Cmd_MoveToMarker("sg_ork_leader", "mkr_ork_sewer3")
		end
		
	--[[ Once the Power Generator goes down ]]
	elseif g_obj_destpower then
		
		--[[ the warboss goes for a walk ]]
		Cmd_MoveToMarker("sg_ork_leader", "mkr_ork_boss_rally3")
		
		--[[ INTEL EVENT ]]
		if Event_IsAnyRunning() == false then
			Util_StartIntel(EVENTS.IE_GorgutzEscapes1)
		end
		Util_Ping_Stop(t_active.ping)
		Util_RemoveBeaconMarker(t_active.beacon)
		t_active = {ping = 0, beacon = 0}
		
		Rule_AddIntervalDelay(Rule_Orks_TempleManager, 1, 5)
		
		Rule_Remove(Rule_Orks_1stTempleFlee)
	end
end

end

--[[ Attack of the grotz ]] function Rule_Orks_GrotAttack()

if g_grotiter < 12 and SGroup_CountSpawned(g_sgorksID) < g_grotcount then
	--[[ make the Ork builders ]]
	for i = 1, 6 do
		local rand = World_GetRand(8, 12)
		local sgroupID  = Util_CreateSquadsAtMarkerEx(g_Player2, "sg_ork_grotattack"..i, "ork_squad_grot", "mkr_ork_sewer"..i, 1, rand)
		SGroup_AddGroup(g_sgorksID, sgroupID)
		Cpu_LockSGroup(g_Player2, "sg_ork_grotattack"..i)
		if SGroup_IsEmpty("sg_chaos_lord") == false then 
			Cmd_AttackSGroup("sg_ork_grotattack"..i, "sg_chaos_lord")
		end
	end
else
	Rule_AddIntervalDelay(Rule_Orks_TempleManager, 1, 45)
	
	Rule_Remove(Rule_Orks_GrotAttack)
end

g_grotiter = g_grotiter+1

end


--[[ STAGE 2 - Post Twist ]]

--[[ IG STAGE 2 ]] function Rule_IG2_Kickoff()

g_sgigID = SGroup_CreateIfNotFound("sg_ig")
Rule_AddOneShot(Rule_IG2_Create, 0)

Rule_AddInterval(Rule_IG2_AreaA_Create, 1)
Rule_AddInterval(Rule_IG2_AreaA_Orders, 5)
Rule_AddInterval(Rule_IG2_Chimeras, 5)
Rule_AddInterval(Rule_IG2_DropShips, 5)

end

function Rule_IG2_Create() g_egIGbarracks = EGroup_CreateIfNotFound("eg_ig_barracks") g_egIGbase = EGroup_CreateIfNotFound("eg_ig_base")

--[[ make the IG bases ]]
for i = 1, 5 do
	Entity_CreateBuildingMarker(g_Player4, "eg_ig_barracks"..i, "guard_infantry", "mkr_ig_barracks"..i, 1)
	EGroup_AddGroup(g_egIGbarracks, EGroup_FromName("eg_ig_barracks"..i))
	EGroup_AddGroup(g_egIGbase, EGroup_FromName("eg_ig_barracks"..i))
end

--[[ SET UP IF ]] t_igbuild = { "guard_hq", "guard_turret_heavy_bolter", "guard_plasma_generator", "guard_tactica", }

local j = 1
for i = 1, 4 do
	local num = World_GetRand(2, 4)
	for y = 1, num do
		local newx = World_GetRand(-30, 30)
		local newz = World_GetRand(-30, 30)
		local pos = Marker_GetPosition(Marker_FromName("mkr_ig_barracks5", "basic_marker"))
		pos.x = pos.x + newx
		pos.z = pos.z + newz
		Entity_CreateBuildingPosition(g_Player4, "eg_ig_base"..i, t_igbuild[i], pos, 1)
		if EGroup_Exists("eg_ig_base"..i) then EGroup_AddGroup(g_egIGbase, EGroup_FromName( "eg_ig_base"..i)) end
	end
end

--[[ make the IG drop ships ]]
t_dropship = {state = {}, target = {}}
t_dropship.state = {"landed", "landed", "landed"}
t_dropship.target = { "sg_ork_leader", "sg_ork_leader", "sg_chaos_lord"}
t_dropship.attack = { false, false, true}

for i = 1, 3 do
	local sgroupID  = Util_CreateSquadsAtMarker(g_Player4, "sg_ig_dropship"..i, "npc_valkyrie", "mkr_ig_dropship"..i, 1)
	SGroup_AddGroup(SGroup_CreateIfNotFound("sg_ig_dropships"), sgroupID)
	SGroup_AddGroup(g_sgigID, SGroup_FromName("sg_ig_dropship"..i))
end	
--[[ make the IG chimeras ]]
for i = 1, 3 do
	local sgroupID  = Util_CreateSquadsAtMarker(g_Player4, "sg_ig_chimera"..i, "guard_squad_chimera", "mkr_ig_chimera"..i, 1)
	SGroup_AddGroup(SGroup_CreateIfNotFound("sg_ig_chimeras"), sgroupID)
	SGroup_AddGroup(g_sgigID, SGroup_FromName("sg_ig_chimera"..i))
end	
--[[ make the IG artillery ]]
for i = 1, 3 do
	local sgroupID  = Util_CreateSquadsAtMarker(g_Player4, "sg_ig_artilery"..i, "guard_squad_basilisk", "mkr_ig_arty"..i, 1)
	SGroup_AddGroup(SGroup_CreateIfNotFound("sg_ig_artilery"), sgroupID)
	SGroup_AddGroup(g_sgigID, SGroup_FromName("sg_ig_artilery"..i))
	--Cmd_SetStance("sg_ig_artilery"..i, STANCE_CeaseFire)
	
end	

Rule_AddInterval(Rule_IG2_BaseDestroyed, 2)

end

function Rule_IG2_BaseDestroyed()

if EGroup_IsEmpty("eg_ig_base") then
	
	g_obj_bossleave = true
	g_obj_killbaz = true
	g_playerHasWon = true
	
	Rule_Remove(Rule_IG2_BaseDestroyed)
end

end

--[[ Guard Area A ]]

function Rule_IG2_AreaA_Create()

for i = 1, 2 do
	if EGroup_IsEmpty("eg_ig_barracks2") == false then
		for y = 1, 2 do
			if SGroup_Exists("sg_ig_barracks"..i..y) == false or SGroup_IsEmpty("sg_ig_barracks"..i..y) then
				local sgroupID  = Util_CreateSquadsAtMarkerEx(g_Player4, "sg_ig_barracks"..i..y, "guard_squad_guardsmen", "mkr_ig_barracks"..i, 1, 6)
				SGroup_AddGroup(g_sgigID, sgroupID)
				if (i == 2 and y == 2) and SGroup_Exists("sg_ig_barracks22") and SGroup_IsEmpty("sg_ig_barracks22") == false then
					Cmd_MoveToMarker("sg_ig_barracks22", "mkr_ig_in1")
				end
			end
		end
	end
end

if EGroup_IsEmpty("eg_ig_barracks2") then
	
	if EGroup_IsEmpty("eg_ig_barracks1")  then
		--[[ next ]]
		Rule_AddInterval(Rule_IG2_AreaB_Create, 1)
		Rule_AddInterval(Rule_IG2_AreaB_Orders, 5)
		
		--[[ clean up ]]
		Rule_Remove(Rule_IG2_AreaA_Create)
		Rule_Remove(Rule_IG2_AreaA_Orders)
	else
		
	end
end

end

function Rule_IG2_AreaA_Orders()

for y = 1, 3 do
	if SGroup_Exists("sg_ig_barracks1"..y) and SGroup_IsEmpty("sg_ig_barracks1"..y) == false then
		Cmd_SetMeleeStance("sg_ig_barracks1"..y, MSTANCE_Assault)
		Cmd_AttackMoveMarker("sg_ig_barracks1"..y, "mkr_ig_line1")
	end
end

if SGroup_Exists("sg_ig_barracks21") and SGroup_IsEmpty("sg_ig_barracks21") == false then
	Cmd_AttackMoveMarker("sg_ig_barracks21", "mkr_ork_boss_start2")
end	

if SGroup_Exists("sg_ig_barracks22") and SGroup_IsEmpty("sg_ig_barracks22") == false and Prox_AnySquadNearMarker("sg_ig_barracks22", "mkr_ig_in1") then
	SGroup_DeSpawn("sg_ig_barracks22")
	SGroup_ReSpawnMarker("sg_ig_barracks22", "mkr_ig_out1")
	Cmd_AttackMoveMarker("sg_ig_barracks22", "mkr_ig_line1")
end

end

--[[ Guard Area B ]]

function Rule_IG2_AreaB_Create()

for i = 3, 4 do
	if EGroup_IsEmpty("eg_ig_barracks3") == false then
		for y = 1, 3 do
			if SGroup_Exists("sg_ig_barracks"..i..y) == false or SGroup_IsEmpty("sg_ig_barracks"..i..y) then
				local sgroupID  = Util_CreateSquadsAtMarkerEx(g_Player4, "sg_ig_barracks"..i..y, "guard_squad_guardsmen", "mkr_ig_barracks"..i, 1, 9)
				SGroup_AddGroup(g_sgigID, sgroupID)
				Cmd_AttackMoveMarker("sg_ig_barracks"..i..y, "mkr_ig_line"..i.."_"..y)
			end
		end
	end
end

if EGroup_IsEmpty("eg_ig_barracks3") then
	
	if EGroup_IsEmpty("eg_ig_barracks4") then
		
		--[[ next ]]
		Rule_AddInterval(Rule_IG2_AreaC_Create, 1)
		Rule_AddInterval(Rule_IG2_AreaC_Orders, 5)
		
		--[[ clean up ]]
		Rule_Remove(Rule_IG2_AreaB_Create)
		Rule_Remove(Rule_IG2_AreaB_Orders)
	else
		
	end
end

end

function Rule_IG2_AreaB_Orders()

for y = 1, 3 do
	if SGroup_Exists("sg_ig_barracks4"..y) == false or SGroup_IsEmpty("sg_ig_barracks4"..y) then
		Cmd_SetMeleeStance("sg_ig_barracks4"..y, MSTANCE_Assault)
		Cmd_AttackMoveMarker("sg_ig_barracks4"..y, "mkr_ig_line4_"..y)
	end
end

for y = 1, 3 do
	if SGroup_Exists("sg_ig_barracks3"..y) == false or SGroup_IsEmpty("sg_ig_barracks3"..y) then
		if SGroup_IsUnderAttackByPlayer("sg_ig_barracks3"..y, false, g_Player2) then
			Cmd_SetMeleeStance("sg_ig_barracks3"..y, MSTANCE_Assault)
		else
			Cmd_SetMeleeStance("sg_ig_barracks3"..y, MSTANCE_Ranged)
		end
	end
end

end

--[[ Guard Area C ]]

function Rule_IG2_AreaC_Create()

if EGroup_IsEmpty("eg_ig_barracks5") == false then
	for y = 1, 2 do
		if SGroup_Exists("eg_ig_barracks5"..y) == false or SGroup_IsEmpty("eg_ig_barracks5"..y) then
			local sgroupID  = Util_CreateSquadsAtMarkerEx(g_Player4, "eg_ig_barracks5"..y, "guard_squad_guardsmen", "mkr_ig_barracks5", 1, 9)
			SGroup_AddGroup(g_sgigID, sgroupID)
			Cmd_AttackMoveMarker("eg_ig_barracks5"..y, "mkr_ig_line5_"..y)
		end
	end
end

if EGroup_IsEmpty("eg_ig_barracks5") then
	
	--[[ next ]]
	
	--[[ clean up ]]
	Rule_Remove(Rule_IG2_AreaC_Create)
	Rule_Remove(Rule_IG2_AreaC_Orders)
end

end

function Rule_IG2_AreaC_Orders()

for y = 1, 3 do
	if SGroup_Exists("sg_ig_artilery"..y) == false or SGroup_IsEmpty("sg_ig_artilery"..y) then
		Cmd_AttackGroundMarker("sg_ig_artilery"..y, "mkr_ig_arty_target")
	end
end

end

--[[ Guard Chimeras ]]

function Rule_IG2_Chimeras()

for i = 1, 3 do
	if SGroup_IsEmpty("sg_ig_chimera"..i) == false then
		local pos = SGroup_GetPosition(SGroup_FromName("sg_ork_leader"))
		if World_DistanceSGroupToPoint(SGroup_FromName("sg_ig_chimera"..i), pos, true) < 30 then
			if SGroup_Exists("sg_ig_mechanized"..i) == false --[[or SGroup_IsEmpty("sg_ig_mechanized"..i)]] then
				local sgroupID  = Util_CreateSquadsAtMarkerEx(g_Player4, "sg_ig_mechanized"..i, "guard_squad_kasrkin", "mkr_ig_chimera"..i, 1, 6)
				SGroup_AddGroup(g_sgigID, sgroupID)
				Cmd_AttackSGroup("sg_ig_mechanized"..i, "sg_ork_leader")
			end
		end
	end
end

if SGroup_IsEmpty("sg_ig_chimera1") and SGroup_IsEmpty("sg_ig_chimera2") and SGroup_IsEmpty("sg_ig_chimera3") then
	Rule_Remove(Rule_IG2_Chimeras)
end

end

--[[ Guard DropShips ]]

function Rule_IG2_DropShips()

for i = 1, 3 do
	if SGroup_IsEmpty("sg_ig_dropship"..i) == false then
		if SGroup_IsUnderAttack("sg_ig_dropship"..i, false) and (t_dropship.state[i] ~= "taken off" or  t_dropship.state[i] ~= "gone") then
			SGroup_SetPlayerOwner("sg_ig_dropship"..i, g_Player5)
			Anim_PlaySGroupAnim(SGroup_FromName("sg_ig_dropship"..i), "sp_take_off")
			t_dropship.state[i] = "taken off"
			if i == 1 then
				Rule_Check_AddOneShot(Rule_IG2_DropShip_Remove1, 10)
			elseif i == 2 then
				Rule_Check_AddOneShot(Rule_IG2_DropShip_Remove2, 10)
			elseif i == 3 then
				Rule_Check_AddOneShot(Rule_IG2_DropShip_Remove3, 10)
			end
		elseif t_dropship.state[i] ~= "taken off" or  t_dropship.state[i] ~= "gone" then
			local pos = SGroup_GetPosition(SGroup_FromName("sg_ork_leader"))
			if World_DistanceSGroupToPoint(SGroup_FromName("sg_ig_dropship"..i), pos, true) < 50 or t_dropship.attack[i] == true then
				if SGroup_Exists("sg_ig_droptroops"..i) == false or SGroup_IsEmpty("sg_ig_droptroops"..i) then
					local sgroupID  = Util_CreateSquadsAtMarkerEx(g_Player4, "sg_ig_droptroops"..i, "guard_squad_guardsmen", "mkr_ig_dropship"..i, 3, 6)
					SGroup_AddGroup(g_sgigID, sgroupID)
					Cmd_AttackSGroup("sg_ig_droptroops"..i, t_dropship.target[i])
				end
			end
		end
	end
end

if SGroup_IsEmpty("sg_ig_dropship1") and SGroup_IsEmpty("sg_ig_dropship2") and SGroup_IsEmpty("sg_ig_dropship3") then
	Rule_Remove(Rule_IG2_DropShips)
end

end

function Rule_IG2_DropShip_Remove1()

if t_dropship.state[1] == "taken off" then
	t_dropship.state[1] = "gone"
	SGroup_DeSpawn("sg_ig_dropship1")
	SGroup_DestroyAllSquads("sg_ig_dropship1")
end

end

function Rule_IG2_DropShip_Remove2()

if t_dropship.state[2] == "taken off" then
	t_dropship.state[2] = "gone"
	SGroup_DeSpawn("sg_ig_dropship2")
	SGroup_DestroyAllSquads("sg_ig_dropship2")
end

end

function Rule_IG2_DropShip_Remove3()

if t_dropship.state[3] == "taken off" then
	t_dropship.state[3] = "gone"
	SGroup_DeSpawn("sg_ig_dropship3")
	SGroup_DestroyAllSquads("sg_ig_dropship3")
end

end

--[[ CHAOS STAGE 2 - Post Twist ]]

function Rule_Chaos2_Kickoff()

Rule_AddOneShot(Rule_Chaos2_Create, 0)

Rule_AddInterval(Rule_Chaos2_MoveToAreaB, 1)

end

function Rule_Chaos2_Create()

Entity_CreateBuildingMarker(g_Player1, "eg_chaos2_barracks", "chaos_temple", "mkr_bridge1", 1)
EGroup_SetHealthInvulnerable("eg_chaos2_barracks", true)

g_chaosID = SGroup_CreateIfNotFound("sg_chaos")
SGroup_Clear(SGroup_FromName("sg_chaos_lord"))
local sgroupID = Util_CreateSquadsAtMarker(g_Player1, "sg_chaos_lord", "chaos_squad_lord_sp_msd01", "mkr_bridge1", 1)
SGroup_AddGroup(g_chaosID, sgroupID)
SGroup_SetHealthInvulnerable("sg_chaos", true)

local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player1, "sg_chaos_bezerker", "chaos_squad_khorne_berserker", "mkr_bridge1", 1, 4)
SGroup_AddGroup(g_chaosID, sgroupID)

for i = 1, 3 do
	local rand = World_GetRand(5, 7)
	local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player1, "sg_chaos_cultist"..i, "chaos_squad_cultist", "mkr_bridge1", 1, rand)
	SGroup_AddGroup(g_chaosID, sgroupID)
end

Rule_AddInterval(Rule_Chaos2_Maintain, 5)

end

function Rule_Chaos2_Maintain()

if SGroup_IsEmpty("sg_chaos_bezerker") then
	local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player1, "sg_chaos_bezerker", "chaos_squad_khorne_berserker", "mkr_bridge1", 1, 4)
	SGroup_AddGroup(g_chaosID, sgroupID)
end

for i = 1, 3 do
	if SGroup_IsEmpty("sg_chaos_cultist"..i) then
		local rand = World_GetRand(5, 7)
		local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player1, "sg_chaos_cultist"..i, "chaos_squad_cultist", "mkr_bridge1", 1, rand)
		SGroup_AddGroup(g_chaosID, sgroupID)
	end
end

end

--[[ Chaos Move Orders ]]

function Rule_Chaos2_MoveToAreaB()

if EGroup_Exists("eg_ig_barracks1") and EGroup_IsEmpty("eg_ig_barracks1") then
	Rule_AddInterval(Rule_Chaos2_MoveToAreaC, 1)
	
	Rule_Remove(Rule_Chaos2_MoveToAreaB)
elseif EGroup_Exists("eg_ig_barracks1") and EGroup_IsEmpty("eg_ig_barracks1") == false then
	Cmd_AttackMoveMarker("sg_chaos", "mkr_ig_line1")
end

end

function Rule_Chaos2_MoveToAreaC()

if EGroup_IsEmpty("eg_ig_barracks4") then
	Cmd_MoveToMarker("sg_chaos_lord", "mkr_chaos_cover1")
	Cmd_MoveToMarker("sg_chaos_bezerker", "mkr_chaos_cover2")
	
	Rule_AddInterval(Rule_Chaos2_MoveToFinalArea, 1)
	
	Rule_Remove(Rule_Chaos2_MoveToAreaC)
else
	Cmd_AttackMoveMarker("sg_chaos", "mkr_ig_barracks4")
end

end

function Rule_Chaos2_MoveToFinalArea()

if SGroup_IsEmpty("sg_ig_artilery") then
	Cmd_AttackMoveMarker("sg_chaos", "mkr_ig_barracks5")
	Rule_Remove(Rule_Chaos2_MoveToFinalArea)
end

end

--[[ ORKS STAGE 2 - Post Twist ]]

function Rule_Orks2_Kickoff()

Player_SetAllResources(g_Player2, 1000, 1000, 40)
Player_SetMaxSquadCap( g_Player2, 30 )
Player_SetSquadCap( g_Player2, 30 )

--[[ Player 2 - Orks ]]
local table1 = {
	"ork_boy_hut", 
	"ork_generator", 
	"ork_waagh_banner", 
	"ork_pile_o_guns", 
	"ork_mek_shop", 
	"ork_hq", 
}
Player_RestrictBuildingList(g_Player2, table1)

local table2 = {
	"ork_research_big_mek_1", 
	"ork_research_big_mek_2", 
	"ork_research_big_mek_3", 
}
Player_RestrictResearchList(g_Player2, table2)

Player_RestrictSquad(g_Player2, "ork_squad_mek_boy")


Rule_AddOneShot(Rule_Orks2_Create, 0)
Rule_AddInterval(Rule_Orks2_BossHelp, 2)

-- Rule_AddOneShot(Rule_Orks2_CallingBoyz_Button, 1) Rule_AddInterval(Rule_Objective_LeaveTown, 1)

Rule_AddIntervalDelay(Rule_Objective_DestroyBarracks, 1, 10)
Rule_AddIntervalDelay(Rule_Obj_DestroyBarracks_Check, 1, 10)

Rule_AddIntervalDelay(Rule_Objective_RallyBoyz, 1, 20)
Rule_AddIntervalDelay(Rule_Obj_RallyBoyz_Check, 1, 20)

Rule_AddInterval(Rule_Orks_BossDies, 1)

end

function Rule_Obj_RallyBoyz_Check()

if SGroup_CountSpawned(g_sgorksID) > 3 then
	g_obj_rallyboyz = true
	Rule_Remove(Rule_Obj_RallyBoyz_Check)
end

end

function Rule_Obj_DestroyBarracks_Check()

if EGroup_IsEmpty("eg_ig_barracks2") and EGroup_IsEmpty("eg_ig_barracks3")  then
	g_obj_destbarracks = true
	Rule_Remove(Rule_Obj_RallyBoyz_Check)
end

end

function Rule_Orks2_Create()

t_rubblepiles2 = {eg = {}, mkr = {}}

for i = 11, 16 do

-- EGroup_SetPlayerOwner("eg_ork_rubble"..i, g_Player2) -- Entity_CreateBuildingMarker(g_Player2, "eg_ork_rubble"..i, "ork_generator", "mkr_ork_rubble"..i, 1) EGroup_AddGroup(EGroup_CreateIfNotFound("eg_ork_rubble"), EGroup_FromName("eg_ork_rubble"..i)) table.insert(t_rubblepiles2.eg, "eg_ork_rubble"..i) table.insert(t_rubblepiles2.mkr, "mkr_ork_rubble"..i) EGroup_DeSpawn("eg_ork_rubblecover"..i) EGroup_ReSpawn("eg_ork_rubble"..i) end

Util_CreateSquadsAtMarkerEx(g_Player2, "sg_ork_trak", "ork_squad_wartrak","mkr_ork_trak", 1, 1)
SGroup_SetPlayerOwner("sg_ork_trak", g_Player5)
g_beacontrakID = Util_CreateBeaconMarker_Red("mkr_ork_trak")

Rule_AddInterval(Rule_Ork_GiveTrak, 1)


Entity_CreateBuildingMarker(g_Player2, "eg_ork_hut", "ork_boy_hut", "mkr_ork_hut", 1)
EGroup_SetPlayerOwner("eg_ork_hut", g_Player5)
g_beaconhutID = Util_CreateBeaconMarker_Red("mkr_ork_hut")

Rule_AddInterval(Rule_Ork_GiveHut, 1)


Util_CreateSquadsAtMarkerEx(g_Player2, "sg_ork_loota", "ork_squad_looted_tank","mkr_ork_lootatank", 1, 1)
SGroup_SetPlayerOwner("sg_ork_loota", g_Player5)
g_beacontankID = Util_CreateBeaconMarker_Red("mkr_ork_lootatank")

Rule_AddInterval(Rule_Ork_GiveTank, 1)

end

function Rule_Ork_GiveTrak() if SGroup_Exists("sg_ork_leader") and SGroup_IsEmpty("sg_ork_leader") == false and Prox_AnySquadNearMarker("sg_ork_leader", "mkr_ork_trak") then SGroup_SetPlayerOwner("sg_ork_trak", g_Player2) Util_RemoveBeaconMarker(g_beacontrakID) Sound_PlayStinger("stinger_completeobjective")

	--[[ INTEL EVENT ]]
	Util_StartIntel(EVENTS.IE_GorgutzGetMoreBoyz)
	
	Rule_Remove(Rule_Ork_GiveTrak)
end

end

function Rule_Ork_GiveHut() if SGroup_Exists("sg_ork_leader") and SGroup_IsEmpty("sg_ork_leader") == false and Prox_AnySquadNearMarker("sg_ork_leader", "mkr_ork_hut") then EGroup_SetPlayerOwner("eg_ork_hut", g_Player2) Util_RemoveBeaconMarker(g_beaconhutID)

	Playlist_Manager( PC_Music, {"music_msd2_perc_choir"}, true, false , {0, 0})
	
	Rule_AddInterval(Rule_Autosave_FoundHut, 1)
	
	Player_AddResource(g_Player2, RT_Requisition, 2000)
	Player_AddResource(g_Player2, RT_Power, 800)
	Player_AddResource(g_Player2, RT_Pop, 40)
	
	--[[ INTEL EVENT ]]
	Util_StartIntel(EVENTS.IE_GorgutzGrabBuilding)
	
	Rule_Remove(Rule_Ork_GiveHut)
end

end

function Rule_Ork_GiveTank() if SGroup_Exists("sg_ork_leader") and SGroup_IsEmpty("sg_ork_leader") == false and Prox_AnySquadNearMarker("sg_ork_leader", "mkr_ork_lootatank") then SGroup_SetPlayerOwner("sg_ork_loota", g_Player2) Util_RemoveBeaconMarker(g_beacontankID) Sound_PlayStinger("stinger_completeobjective")

	--[[ INTEL EVENT ]]
	Util_StartIntel(EVENTS.IE_GorgutzGetMoreBoyz)
	
	Rule_Remove(Rule_Ork_GiveTank)
end

end

function Rule_Orks2_BossHelp()

for i = 11, 16 do
	if EGroup_IsEmpty("eg_ork_rubble"..i) == false then
		local pos = Marker_GetPosition(Marker_FromName("mkr_ork_rubble"..i, "basic_marker"))
		if SGroup_IsEmpty("sg_ork_leader") == false 
		and SGroup_CountDeSpawned(SGroup_FromName("sg_ork_leader")) == 0 
		and World_DistanceSGroupToPoint(SGroup_FromName("sg_ork_leader"), pos, false) < 15 then
			EGroup_SetPlayerOwner("eg_ork_rubble"..i, g_Player2)

-- EGroup_ReSpawn("eg_ork_rubble"..i) -- EGroup_Clear("eg_ork_rubble"..i)

			if SGroup_Exists("sg_ork_sewer"..i) == false or SGroup_IsEmpty("sg_ork_sewer"..i) then
				local rand = World_GetRand(2, 4)
				local sgroupID  = Util_CreateSquadsAtMarkerEx(g_Player2, "sg_ork_sewer"..i, Rule_RandomOrk(),"mkr_ork_rubble"..i, 2, rand)
				
				Player_AddResource(g_Player2, RT_Pop, 4)
				Player_AddResource(g_Player2, RT_Requisition, 200)
				Player_AddResource(g_Player2, RT_Power, 100)
				
				SGroup_AddGroup(SGroup_CreateIfNotFound("sg_ork_sewer"), sgroupID)		
				SGroup_AddGroup(g_sgorksID, sgroupID)		
				Cmd_AttackSGroup("sg_ork_sewer"..i, "sg_ork_leader")
			end
		end
	end
end	

end

function Rule_Orks_BossDies()

local blueprinttable = Util_MakeBlueprintTable("ork_squad_warboss")

if SGroup_IsEmpty("sg_ork_leader") or SGroup_ContainsBlueprints( "sg_ork_leader", blueprinttable, false) == false then
	
	Cmd_MoveToMarker("sg_orks", "mkr_ork_boss_start2")
	
	Rule_AddOneShot(Rule_Orks_BossComesBack, 5)
	
	Rule_Remove(Rule_Orks_BossDies)
end

end

function Rule_Orks_BossComesBack()

local sgroupID  = Util_CreateSquadsAtMarkerEx(g_Player2, "sg_ork_leader", "ork_squad_warboss", "mkr_ork_boss_start2", 1, 1)
World_FXEventSquad("data:Art/Events/Unit_Upgrade_Morale_FX/Reinforce_Trooper", sgroupID)

if Event_TimeSinceLast() > 10 then
	Util_StartIntel(EVENTS.IE_Ork_ImBack)
end
EventCue_DoEvent( "recruit_commander", "/Races/Shared/Upgrade_weapon", "$42890", "$42892" )

SGroup_AddGroup(g_sgorksID, sgroupID)
Camera_FocusOnTargetSGroup(sgroupID, -1)

Rule_AddInterval(Rule_Orks_BossDies, 1)

end

--[[ CALLING ALL BOYZ ]]

-- this function set is to call out the boyz -- it makes a button that lets the player 'call' to find the nearest places to get more boyz -- these places will be marked with beacons function Rule_Orks2_CallingBoyz_Button() t_orkbutton = { button_icon = {--[[1]]"Scar_buttons/calling_all_boyz", --[[2]]"Scar_buttons/calling_all_boyz", --[[3]]"Scar_buttons/calling_all_boyz"}, button_description = {--[[1]]"$860050", --[[2]]"$860051"}, }

g_boyzbuttonID = Util_AbilityButton_Create(t_orkbutton.button_icon, t_orkbutton.button_description, false)

g_callboyzDelay = 0

Util_SGroupAbilityButton_Add2Manager(g_boyzbuttonID, "sg_ork_leader")
Rule_AddInterval(Rule_Orks2_CallingBoyz_Countdown, 1)
Rule_AddOneShot(Rule_Orks2_CallingBoyz_Reminder, 1)

end

function Rule_Orks2_CallingBoyz_Reminder()

--[[ INTEL EVENT ]]
Util_StartIntel(EVENTS.IE_GorgutzWhereDaBoyzAbility)

end

--[[ ARE THE CONDITIONS RIGHT FOR SUMMONING ]] function Rule_Orks2_CallingBoyz_Countdown()

if g_callboyzDelay == 0 then
	if Button_GetEnabled(g_boyzbuttonID) == false then
		Button_SetEnabled(g_boyzbuttonID, true)
	end
	Rule_AddInterval(Rule_Orks2_CallingBoyz_Check, 1)
	Rule_Remove(Rule_Orks2_CallingBoyz_Countdown)
elseif g_callboyzDelay > 0 then
	g_callboyzDelay = g_callboyzDelay-1		
end

end

--[[ DETECTING THE BUTTON PRESS ]] function Rule_Orks2_CallingBoyz_Check()

if Button_GetEnabled(g_boyzbuttonID) and Button_GetPressed(g_boyzbuttonID) then
	--[[ is the warboss around ]]
	Rule_Check_Remove(Rule_Orks2_CallingBoyz_Reminder)
	
	if SGroup_Exists("sg_ork_leader") and SGroup_CountDeSpawned(SGroup_FromName("sg_ork_leader")) == 0 and SGroup_IsEmpty("sg_ork_leader") == false then
		
		g_callboyzDelay = g_callboyzDelay+10
		--[[ INTEL EVENT ]]
		Util_StartIntel(EVENTS.IE_GorgutzWhereDaBoyz)
		
		local pos1 = SGroup_GetPosition(SGroup_FromName("sg_ork_leader"))
		
		for i = 11, 16 do
			if EGroup_IsEmpty("eg_ork_rubble"..i) == false then
				local pos2 = Marker_GetPosition(Marker_FromName("mkr_ork_rubble"..i, "basic_marker"))
				if World_DistancePointToPoint(pos1, pos2) < 30 then
					EGroup_ReSpawn("eg_ork_rubble"..i)

-- EGroup_Clear("eg_ork_rubble"..i)

					if SGroup_Exists("sg_ork_sewer"..i) == false or SGroup_IsEmpty("sg_ork_sewer"..i) then
						local rand = World_GetRand(2, 4)
						local sgroupID  = Util_CreateSquadsAtMarkerEx(g_Player2, "sg_ork_sewer"..i, Rule_RandomOrk(),"mkr_ork_rubble"..i, 2, rand)
						
						Player_AddResource(g_Player2, RT_Pop, 4)
						Player_AddResource(g_Player2, RT_Requisition, 200)
						Player_AddResource(g_Player2, RT_Power, 100)
						
						SGroup_AddGroup(SGroup_CreateIfNotFound("sg_ork_sewer"), sgroupID)		
						SGroup_AddGroup(g_sgorksID, sgroupID)		
						Cmd_AttackSGroup("sg_ork_sewer"..i, "sg_ork_leader")
						
						g_callboyzDelay = g_callboyzDelay+10
					end
				end
			end
		end
		
	--[[ if he's dead, fail silently ]]
	elseif SGroup_Exists("sg_ork_leader") and SGroup_IsEmpty("sg_ork_leader") then
		
		Button_SetEnabled(g_boyzbuttonID, false)
		Rule_AddInterval(Rule_Orks2_CallingBoyz_Countdown, 1)
		Rule_Remove(Rule_Orks2_CallingBoyz_Check)
		
	end
	
end

end


--[[ GAME OVER - Player Wins ]]

function Rule_EndGameWin()

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

end

function Rule_EndGameWin2()

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

if g_playerswitch == "g_Player1" then
	
	g_building_exceptions = 
	{
		"chaos_listening_post",
		"chaos_armoury",
		"chaos_plasma_generator",
		"chaos_turret_bolter",
		"chaos_mine_field"
	}
	
	g_unit_exceptions = 
	{
		"chaos_squad_lord",
		"chaos_squad_lord_sp_msd01",
	}
	
	--[[ 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 )
		end
	end
	
else
	
	g_building_exceptions = 
	{
		"chaos_listening_post",
		"chaos_armoury",
		"chaos_plasma_generator",
		"chaos_turret_bolter",
		"chaos_mine_field"
	}
	
	g_unit_exceptions = 
	{
		"chaos_squad_lord",
		"chaos_squad_lord_sp_msd01",
	}
	
	--[[ Lose because of Annihilation 
	if( Player_HasBuildingsExcept(g_Player2, g_building_exceptions) == false ) then
		if( Player_HasSquadsExcept(g_Player2, g_unit_exceptions ) == false ) then
			Rule_RemoveAll()
			Fade_Start(4, false)
			World_SetTeamWin( g_Player4, "" )
			Rule_AddIntervalEx( Rule_GameOver,5,1 )
			Rule_Remove( Rule_EndGameLose )
		end
	end
	]]
	
end

--[[ Lose because of the Objectives Failed ]]
if g_playerHasWon == false then
	Rule_RemoveAll()
	Fade_Start(4, false)
	World_SetTeamWin( g_enemy, "" )
	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 ]]

--[[ CHAOS PRIMARY MASTER - Hunt Warboss ]] function Rule_Objective_HuntWarboss() Objective_HuntWarboss = { title_id = 861000, short_desc_id = 861001, help_tip_id = 861002 } if Event_IsAnyRunning() == false and Objective_Exists(Objective_HuntWarboss.title_id) == false then Util_WXP_ObjectiveCreate(Objective_HuntWarboss, true, g_Player1)

elseif Event_IsAnyRunning() == false and g_obj_huntboss == true and g_obj_killwarbossgranted == true then
	Util_ObjectiveComplete(Objective_HuntWarboss.title_id)
	
	if g_templebeaconID ~= nil then
		Util_RemoveBeaconMarker(g_templebeaconID)
		Util_Ping_Stop("png_temple")
		g_templebeaconID = nil
	end
	
	--[[ THE HALTIME SHOW ]]
	Rule_AddOneShot(Rule_PlayTwist, 5)
	
	--[[ IF THIS IS THE FINAL WIN CONDITION - uncomment out the following
	g_playerHasWon = true
	]]
	
	Rule_Remove(Rule_Objective_HuntWarboss)
elseif Event_IsAnyRunning() == false and g_obj_huntboss == false then
	Util_ObjectiveFail(Objective_HuntWarboss.title_id)
	
	--[[ IF THIS IS A FAILURE/LOSE CONDITION - uncomment out the following
	g_playerHasWon = false
	]]
	
	Rule_Remove(Rule_Objective_HuntWarboss)
end

end

function Rule_PlayTwist()

Util_StartNIS(EVENTS.NIS_Twist)

end

--[[ CHAOS HUNT WARBOSS SUB - Destroy Ork FORCE FIELD POWER SOURCE ]] function Rule_Objective_DestroyPowerSource() Objective_DestroyPowerSource = { title_id = 861020, short_desc_id = 861021, help_tip_id = 861022 }

if Objective_Exists(Objective_HuntWarboss.title_id) == true then
	
	if Event_IsAnyRunning() == false and Objective_Exists(Objective_DestroyPowerSource.title_id) == false then
		Util_WXP_ObjectiveSubCreate(Objective_DestroyPowerSource, Objective_HuntWarboss.title_id)
		
		g_objgenping = Objective_PingMarker(Objective_DestroyPowerSource.title_id, "mkr_ork_generator", true, "attack")
		
		--[[ the player can now destroy it ]]
		EGroup_SetHealthInvulnerable("eg_ork_energysource", false)
		
		Util_Music_CreateSingleLoop( {"music_msd1"}, {"music_msd1_perc"}, 140 )
		
		Rule_AddInterval(Rule_Autosave_DestroyGen, 1)
		
	elseif Event_IsAnyRunning() == false and g_obj_destpower == true  then
		Util_ObjectiveComplete(Objective_DestroyPowerSource.title_id)
		Objective_PingRemove(Objective_DestroyPowerSource.title_id, g_objgenping)
		
		Rule_AddInterval(Rule_Objective_KillWarboss, 1)
		
		Rule_Remove(Rule_Objective_DestroyPowerSource)
	elseif Event_IsAnyRunning() == false and g_obj_destpower == false then
		Util_ObjectiveFail(Objective_DestroyPowerSource.title_id)
		Objective_PingRemove(Objective_DestroyPowerSource.title_id, g_objgenping)
		
		Rule_Remove(Rule_Objective_DestroyPowerSource)
	end
	
end

end

--[[ CHAOS HUNT WARBOSS SUB - Kill the Warboss ]] function Rule_Objective_KillWarboss() Objective_KillWarboss = { title_id = 861100, short_desc_id = 861101, help_tip_id = 861022 } if Event_IsAnyRunning() == false and Objective_Exists(Objective_KillWarboss.title_id) == false then

	Util_WXP_ObjectiveSubCreate(Objective_KillWarboss, Objective_HuntWarboss.title_id)
	
	Rule_AddInterval(Rule_Autosave_KillWarboss, 1)
	
	g_obj_killwarbossgranted = true
	
elseif Event_IsAnyRunning() == false and g_obj_killwarboss == true  then
	Util_ObjectiveComplete(Objective_KillWarboss.title_id)
	
	Rule_Remove(Rule_Objective_KillWarboss)
elseif Event_IsAnyRunning() == false and g_obj_killwarboss == false then
	Util_ObjectiveFail(Objective_KillWarboss.title_id)
	
	Rule_Remove(Rule_Objective_KillWarboss)
end

end

--[[ CHAOS SECONDARY - Summon BEzerkers ]] function Rule_Objective_SummonBez() Objective_SummonBez = { title_id = 861080, short_desc_id = 861081, help_tip_id = 861082 } if Event_IsAnyRunning() == false and Objective_Exists(Objective_SummonBez.title_id) == false then Util_WXP_ObjectiveCreate(Objective_SummonBez, false, g_Player1)

	--[[ THE BEZERKER ABILITY BUTTON ]]
	Util_SGroupAbilityButton_Add2Manager(g_bezbuttonID, "sg_chaos_lord")
	Rule_AddInterval(Rule_Chaos_BezerkerConditionCheck, 1)
	Rule_AddInterval(Rule_Temple4_Destroyed, 1)
	
elseif Event_IsAnyRunning() == false and g_obj_summonbez == true  then
	Util_ObjectiveComplete(Objective_SummonBez.title_id)
	
	if g_templebeaconID ~= nil then
		Util_RemoveBeaconMarker(g_templebeaconID)
		Util_Ping_Stop("png_temple")
		g_templebeaconID = nil
	end
	
	Rule_Remove(Rule_Objective_SummonBez)
elseif Event_IsAnyRunning() == false and (g_obj_summonbez == false 
or ( Objective_GetState(Objective_HuntWarboss.title_id) == OS_Complete and g_obj_summonbez ~= true  ) ) then
	Util_ObjectiveFail(Objective_SummonBez.title_id)
	
	Rule_Remove(Rule_Objective_SummonBez)
end

end

function Rule_Temple4_Destroyed()

if EGroup_IsEmpty("eg_temple4") 
and ( g_obj_summonbez ~= true or (Objective_Exists(Objective_SummonBez.title_id) and Objective_GetState(Objective_SummonBez.title_id) ~= OS_Complete) ) then
	g_obj_summonbez = false 
	Rule_Remove(Rule_Temple4_Destroyed)
end

end

--[[ CHAOS SECONDARY MASTER - Ork Power Base ]] function Rule_Objective_OrkPowerBase() Objective_OrkPowerBase = { title_id = 861110, short_desc_id = 861111, help_tip_id = 861012 } if Event_IsAnyRunning() == false and Objective_Exists(Objective_OrkPowerBase.title_id) == false then Util_WXP_ObjectiveCreate(Objective_OrkPowerBase, false, g_Player1)

	Rule_AddIntervalDelay(Rule_Objective_FindOrkBase, 1, 10)
	
elseif Event_IsAnyRunning() == false and g_obj_powerbase == true  then
	Util_ObjectiveComplete(Objective_OrkPowerBase.title_id)
	
	Rule_Remove(Rule_Objective_OrkPowerBase)
elseif Event_IsAnyRunning() == false and ( g_obj_powerbase == false 
or ( Objective_GetState(Objective_HuntWarboss.title_id) == OS_Complete and g_obj_powerbase ~= true  ) ) then
	Util_ObjectiveFail(Objective_OrkPowerBase.title_id)
	
	Rule_Remove(Rule_Objective_OrkPowerBase)
end

end

--[[ CHAOS POWER BASE SUB - Find Ork Base ]] function Rule_Objective_FindOrkBase() Objective_FindOrkBase = { title_id = 861090, short_desc_id = 861091, help_tip_id = 861012 } if Event_IsAnyRunning() == false and Objective_Exists(Objective_FindOrkBase.title_id) == false then Util_WXP_ObjectiveSubCreate(Objective_FindOrkBase, Objective_OrkPowerBase.title_id)

elseif Event_IsAnyRunning() == false and g_obj_findbase == true  then
	Util_ObjectiveComplete(Objective_FindOrkBase.title_id)
	
	Rule_AddIntervalDelay(Rule_Objective_DestroyBase, 1, 2)
	
	Rule_Remove(Rule_Objective_FindOrkBase)
elseif Event_IsAnyRunning() == false and g_obj_findbase == false then
	Util_ObjectiveFail(Objective_FindOrkBase.title_id)
	
	Rule_Remove(Rule_Objective_FindOrkBase)
end

end

--[[ CHAOS POWER BASE SUB - Destroy Ork Base ]] function Rule_Objective_DestroyBase()

Objective_DestroyBase = { title_id = 861010, short_desc_id = 861011, help_tip_id = 861012 }
if Event_IsAnyRunning() == false and Objective_Exists(Objective_DestroyBase.title_id) == false then
	Util_WXP_ObjectiveSubCreate(Objective_DestroyBase, Objective_OrkPowerBase.title_id)
	
	g_objorkbaseping = Objective_PingMarker(Objective_DestroyBase.title_id, "mkr_ork_base", true, "attack")
	
	--[[ INTEL EVENT ]]
	Util_StartIntel(EVENTS.IE_CrullOrkBaseSpotted)
	
elseif Event_IsAnyRunning() == false and g_obj_destbase == true  then
	Util_ObjectiveComplete(Objective_DestroyBase.title_id)
	Objective_PingRemove(Objective_DestroyBase.title_id, g_objorkbaseping)
	
	g_obj_powerbase = true
	
	Rule_Remove(Rule_Objective_DestroyBase)
elseif Event_IsAnyRunning() == false and g_obj_destbase == false then
	Util_ObjectiveFail(Objective_DestroyBase.title_id)
	Objective_PingRemove(Objective_DestroyBase.title_id, g_objorkbaseping)
	
	Rule_Remove(Rule_Objective_DestroyBase)
end

end

--[[ CHAOS SECONDARY - Protect the Temples ]] function Rule_Objective_ProtectTemples() Objective_ProtectTemples = { title_id = 861030, short_desc_id = 861031, help_tip_id = 861032 } if Event_IsAnyRunning() == false and Objective_Exists(Objective_ProtectTemples.title_id) == false then Util_WXP_ObjectiveCreate(Objective_ProtectTemples, false, g_Player1)

	local count = EGroup_Count(EGroup_FromName("eg_alltemples"))
	UI_ShowCount( "ct_temples", g_Player1, 861032, count )
	
	t_objtempping = {}
	for i = 1, 4 do
		t_objtempping[i] = Objective_PingMarker(Objective_ProtectTemples.title_id, "mkr_chaos_temple"..i, true, "default")
	end
	
elseif Event_IsAnyRunning() == false and ( g_obj_protecttemp == true 
or ( Objective_GetState(Objective_HuntWarboss.title_id) == OS_Complete and g_obj_protecttemp ~= false  ) ) then
	
	Util_ObjectiveComplete(Objective_ProtectTemples.title_id)
	
	for i = 1, 4 do
		Objective_PingRemove(Objective_ProtectTemples.title_id, t_objtempping[i])
	end
	
	UI_HideCount( "ct_temples" )
	
	Rule_Remove(Rule_Objective_ProtectTemples)
	
elseif Event_IsAnyRunning() == false and g_obj_protecttemp == false then
	
	Util_ObjectiveFail(Objective_ProtectTemples.title_id)
	
	for i = 1, 4 do
		Objective_PingRemove(Objective_ProtectTemples.title_id, t_objtempping[i])
	end
	
	UI_HideCount( "ct_temples" )
	
	Rule_Remove(Rule_Objective_ProtectTemples)
	
end

--[[ CUSTOM ARGUEMENT ADDED FOR THE COUNTER - this was the easiest place to put it - deg ]]
if Objective_Exists(Objective_ProtectTemples.title_id) and Objective_GetState(Objective_ProtectTemples.title_id) == OS_Incomplete then
	local count = EGroup_Count(EGroup_FromName("eg_alltemples"))
	UI_ShowCountUpdate( "ct_temples", count )
end

if EGroup_Exists("eg_alltemples") and EGroup_IsEmpty("eg_alltemples") then
	print("temples dead")
	g_obj_protecttemp = false
end

end

--[[ THE WARBOSS OBJECTIVES ]]

--[[ WARBOSS - Leave Town ]] function Rule_Objective_LeaveTown() Objective_LeaveTown = { title_id = 861040, short_desc_id = 861041, help_tip_id = 861042 } if Event_IsAnyRunning() == false and Objective_Exists(Objective_LeaveTown.title_id) == false then Util_WXP_ObjectiveCreate(Objective_LeaveTown, true, g_Player2)

	--[[ INTEL EVENT ]]
	Util_StartIntel(EVENTS.IE_GorgutzPlayerSwitch)
	
elseif Event_IsAnyRunning() == false and g_obj_bossleave == true  then
	Util_ObjectiveComplete(Objective_LeaveTown.title_id)
	g_playerHasWon = true
	
	Rule_Remove(Rule_Objective_LeaveTown)
elseif Event_IsAnyRunning() == false and g_obj_bossleave == false then
	Util_ObjectiveFail(Objective_LeaveTown.title_id)
	
	Rule_Remove(Rule_Objective_LeaveTown)
end

end

--[[ WARBOSS - Rally the Boyz ]] function Rule_Objective_RallyBoyz() Objective_RallyBoyz = { title_id = 861050, short_desc_id = 861051, help_tip_id = 861052 } if Event_IsAnyRunning() == false and Objective_Exists(Objective_RallyBoyz.title_id) == false then Util_WXP_ObjectiveSubCreate(Objective_RallyBoyz, Objective_LeaveTown.title_id)

elseif Event_IsAnyRunning() == false and g_obj_rallyboyz == true  then
	Util_ObjectiveComplete(Objective_RallyBoyz.title_id)
	
	Rule_Remove(Rule_Objective_RallyBoyz)
elseif Event_IsAnyRunning() == false and g_obj_rallyboyz == false then
	Util_ObjectiveFail(Objective_RallyBoyz.title_id)
	
	Rule_Remove(Rule_Objective_RallyBoyz)
end

end

-- --[[ WARBOSS - Destroy the Barracks ]] function Rule_Objective_DestroyBarracks() Objective_DestroyBarracks = { title_id = 861060, short_desc_id = 861061, help_tip_id = 861062 } if Event_IsAnyRunning() == false and Objective_Exists(Objective_DestroyBarracks.title_id) == false then Util_WXP_ObjectiveSubCreate(Objective_DestroyBarracks, Objective_LeaveTown.title_id) t_objbarping = {0, 0, 0} for i = 2, 3 do t_objbarping[i] = Objective_PingMarker(Objective_DestroyBarracks.title_id, "mkr_ig_barracks"..i, true, "attack") end

elseif Event_IsAnyRunning() == false and g_obj_destbarracks == true  then
	Util_ObjectiveComplete(Objective_DestroyBarracks.title_id)
	Rule_AddInterval(Rule_Objective_KillBase, 1)
	for i = 2, 3 do
		Objective_PingRemove(Objective_DestroyBarracks.title_id, t_objbarping[i])
	end
	
	Rule_Remove(Rule_Objective_DestroyBarracks)
elseif Event_IsAnyRunning() == false and g_obj_destbarracks == false then
	Util_ObjectiveFail(Objective_DestroyBarracks.title_id)
	for i = 2, 3 do
		Objective_PingRemove(Objective_DestroyBarracks.title_id, t_objbarping[i])
	end
	
	Rule_Remove(Rule_Objective_DestroyBarracks)
end

end

-- --[[ WARBOSS - Kill the Base ]] function Rule_Objective_KillBase() Objective_KillBase = { title_id = 861070, short_desc_id = 861071, help_tip_id = 861072 } if Event_IsAnyRunning() == false and Objective_Exists(Objective_KillBase.title_id) == false then Util_WXP_ObjectiveSubCreate(Objective_KillBase, Objective_LeaveTown.title_id) g_objbaseping = Objective_PingMarker(Objective_KillBase.title_id, "mkr_ork_base", true, "attack")

	--[[ INTEL EVENT ]]
	Util_StartIntel(EVENTS.IE_GorgutzDestroyBase)
	
	Playlist_Manager( PC_Music, {"music_msd2"}, true, false , {0, 0}) 
	
elseif Event_IsAnyRunning() == false and g_obj_killbaz == true  then
	Util_ObjectiveComplete(Objective_KillBase.title_id)
	Objective_PingRemove(Objective_KillBase.title_id, g_objbaseping)
	
	Rule_Remove(Rule_Objective_KillBase)
elseif Event_IsAnyRunning() == false and g_obj_killbaz == false then
	Util_ObjectiveFail(Objective_KillBase.title_id)
	Objective_PingRemove(Objective_KillBase.title_id, g_objbaseping)
	
	Rule_Remove(Rule_Objective_KillBase)
end

end


--[[ AUTOSAVES ]]

function Rule_Autosave_MissionStart()

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

end

function Rule_Autosave_SummonBez()

if not Event_IsAnyRunning() then
	Util_Autosave( "$860201" )
	Rule_Remove(Rule_Autosave_SummonBez)
end

end

function Rule_Autosave_DestroyGen()

if not Event_IsAnyRunning() then
	Util_Autosave( "$860203" )
	Rule_Remove(Rule_Autosave_DestroyGen)
end

end

function Rule_Autosave_KillWarboss()

if not Event_IsAnyRunning() then
	Util_Autosave( "$860204" )
	Rule_Remove(Rule_Autosave_KillWarboss)
end

end

function Rule_Autosave_WarbossinCharge()

if not Event_IsAnyRunning() then
	Util_Autosave( "$860205" )
	Rule_Remove(Rule_Autosave_WarbossinCharge)
end

end

function Rule_Autosave_FoundHut()

if not Event_IsAnyRunning() then
	Util_Autosave( "$860206" )
	Rule_Remove(Rule_Autosave_FoundHut)
end

end


--[[ INTEL EVENTS ]]

function Rule_IE_MissionIntro() Util_StartIntel(EVENTS.IE_ThisIsAWaagh) end

function Rule_IE_LordHealing() Util_StartIntel(EVENTS.IE_CrullTempleUsage) end




--[[ CHEATS ]]




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