Mission 2 Event File
Guider
/
Mission 2 Event File
Uppdaterad 3 years ago av Merric

--IMPORTS

import("ScarUtil.scar")


--GAME SETUP

function OnGameSetup()

g_Player1 = Setup_Player(0, "$214901", "space_marine_race", 1)
g_Player2 = Setup_Player(1, "$214902", "ork_race", 2)
g_Player3 = Setup_Player(2, "$214903", "space_marine_race", 1)
g_Player4 = Setup_Player(3, "$214904", "npc_race", 1)
g_Player5 = Setup_Player(4, "$214905", "npc_race", TEAM_NEUTRAL)
g_Player6 = Setup_Player(5, "$214902", "ork_race", 2)

-- Player_SetTeam(g_Player5, TEAM_NEUTRAL)

--[[variables]]
g_kanmoving = 0
g_cleansegiven = 0
g_calledonce = 0
g_patrolC = 1
g_patrolB = 1
g_OrkGuard_iter = 1
g_rand_delay = 0
g_base_delay = 1
g_kandelay = 0
g_reinforce = 0
g_reinforce = 0
g_reinforcedeadcount = 0
g_makebase = 0
t_diff_normal = {hqarmour = 0.85, banneraccuracy = 0.2, postaccuracy = 0.2, turretaccuracy = 0.2, angrymob = 1, kanhealth = 0.45, stampkan = 1, nobhealth = 0.175 }
t_diff_hard = {hqarmour = 0.95, banneraccuracy = 0.5, postaccuracy = 0.5, turretaccuracy = 0.5, angrymob = 2, kanhealth = 0.75, stampkan = 2, nobhealth = 0.25 }
t_diff_advance = {hqarmour = 1, banneraccuracy = 1, postaccuracy = 1, turretaccuracy = 1, angrymob = 2, kanhealth = 1, stampkan = 3, nobhealth = 1 }
t_angry = {
	egroup = { "eg_orkhut2", "eg_orkhut3", "eg_orkhut4", "eg_orkhut5", "eg_orkhut6", "eg_orkhut7"}, 
	blueprint = {"ork_squad_shoota_boy", "ork_squad_slugga", "ork_squad_tankbusta"}, 
	marker = { "mkr_orkhut2", "mkr_orkhut3", "mkr_orkhut4", "mkr_orkhut5", "mkr_orkhut6", "mkr_orkhut7"}, 
}
t_OrkGuard = {
	sgroup = { "sg_orkguard1", "sg_orkguard2", "sg_orkguard3", "sg_orkguard4", "sg_orkguard5"}, 
	marker = {"mkr_orkguard1", "mkr_orkguard2", "mkr_orkguard3", "mkr_orkguard4", "mkr_orkguard5"}
}

end


--GAME LOAD

function OnGameRestore()

g_Player1 = World_GetPlayerAt(0)
g_Player2 = World_GetPlayerAt(1)
g_Player3 = World_GetPlayerAt(2)
g_Player4 = World_GetPlayerAt(3)
g_Player5 = World_GetPlayerAt(4)
g_Player6 = World_GetPlayerAt(5)

end


--ON INITIALIZATION

function MS02_OnInit()

--[[eventcue]]
EventCue_Enable(false)

--[[ Preset Stage for NIS]]
Fade_Start( 0, false )
W40k_Letterbox( true, 0 )	

--[[FOW]]
FOW_RevealAll()
World_EnablePlayerToPlayerFOW(g_Player1, g_Player3, true);	

-- World_EnablePlayerToPlayerFOW(g_Player1, g_Player4, true);

SetCommanderPowerSword(g_Player1)

--[[Set Cpu]]
Cpu_Enable(g_Player1, false)
Cpu_Enable(g_Player2, false)
Cpu_Enable(g_Player3, false)
Cpu_Enable(g_Player4, false)
Cpu_Enable(g_Player5, false)
Cpu_Enable(g_Player6, false)

--[[Music]]
Rule_AddOneShot(SetupMusicPlaylist, 0.0)

--[[ NIS STARTER ]]
Util_StartNIS(EVENTS.NIS_Opening);
Rule_AddOneShot(Rule_FadeIn, 2.5)

--[[Get the Game Ready to Run]]
Rule_Add(Rule_MissionStart)

--[[ begin checking for all primary objectives complete Rule_Add(Rule_PlayerHasWon) ]] end

Scar_AddInit(MS02_OnInit)

function Rule_FadeIn()

Fade_Start(3, true)

end


-- DIFFICULTY LEVEL

-- the functions here set the difficulty level for the mission. Should be called from OnGameSetup function SetDifficultyLevel()

local difficultyLevel = Difficulty_Get()

-- easy
if difficultyLevel == DIFFICULTY_EASY then

	Difficulty_SetForPlayer(g_Player2, 0)
	Difficulty_SetForPlayer(g_Player6, 0)
	
	t_difficulty = t_diff_normal
	
-- medium
elseif difficultyLevel == DIFFICULTY_NORMAL then
	
	Difficulty_SetForPlayer(g_Player2, 1)
	Difficulty_SetForPlayer(g_Player6, 1)
	
	t_difficulty = t_diff_hard
	
-- hard
elseif difficultyLevel == DIFFICULTY_HARD then

	Difficulty_SetForPlayer(g_Player2, 2)
	Difficulty_SetForPlayer(g_Player6, 2)
	
	t_difficulty = t_diff_advance

end

Rule_AddOneShot(Rule_OrkDifficultyModifiers, 0.0)

end

function Rule_OrkDifficultyModifiers()

--[[Mod the health of the Ork SP Nob]] local modifier_nobhealthdecrease = Modifier_Create( MAT_EntityType, -- This modifier will be applied to a weapon type "health_maximum_modifier", -- Modify the max range of the weapon MUT_Multiplication, -- use multiplication false, t_difficulty.nobhealth, "ork_nob_leader_sp" -- Do this to the sniper rifle )

g_modifier_nobhealthdecrease = Modifier_ApplyToPlayer( modifier_nobhealthdecrease, g_Player2 )

--[[Mod the sight range of the Ork SP Nob]] local modifier_nobsightdecrease = Modifier_Create( MAT_EntityType, -- This modifier will be applied to a weapon type "sight_radius_modifier", -- Modify the max range of the weapon MUT_Multiplication, -- use multiplication false, 0.5, "ork_nob_leader_sp" -- Do this to the sniper rifle )

g_modifier_nobsightdecrease = Modifier_ApplyToPlayer( modifier_nobsightdecrease, g_Player2 )

--[[Mod the armourclass of the Ork HQ]] local modifier_buildingarmourdecrease = Modifier_Create( MAT_EntityType, -- This modifier will be applied to a weapon type "armour_modifier", -- Modify the max range of the weapon MUT_Multiplication, -- use multiplication false, t_difficulty.hqarmour, "ork_hq" -- Do this to the sniper rifle )

g_modifier_buildingarmourdecrease = Modifier_ApplyToPlayer( modifier_buildingarmourdecrease, g_Player2 )

--[[Mod the accuracy of the Waaagh Banners]]
local modifier_weaponaccuracydecrease1 = Modifier_Create(
	MAT_WeaponType,      -- This modifier will be applied to a weapon type
	"accuracy_weapon_modifier",   -- Modify the max range of the weapon
	MUT_Multiplication,     -- use multiplication
	false, 
	t_difficulty.banneraccuracy, 
	"ork_shoota_turret_waaaghbanner"     -- Do this to the sniper rifle
	)
	
g_modifier_weaponaccuracydecrease1 = Modifier_ApplyToPlayer( modifier_weaponaccuracydecrease1, g_Player2 )

--[[Mod the accuracy of the Ork Listening Posts]]
local modifier_weaponaccuracydecrease2 = Modifier_Create(
	MAT_WeaponType,      -- This modifier will be applied to a weapon type
	"accuracy_weapon_modifier",   -- Modify the max range of the weapon
	MUT_Multiplication,     -- use multiplication
	false, 
	t_difficulty.postaccuracy, 
	"ork_shoota_turret_listeningpost"     -- Do this to the sniper rifle
	)
	
g_modifier_weaponaccuracydecrease2 = Modifier_ApplyToPlayer( modifier_weaponaccuracydecrease2, g_Player2 )

--[[Mod the accuracy of the Ork Boy Hutz]]
local modifier_weaponaccuracydecrease3 = Modifier_Create(
	MAT_WeaponType,      -- This modifier will be applied to a weapon type
	"accuracy_weapon_modifier",   -- Modify the max range of the weapon
	MUT_Multiplication,     -- use multiplication
	false, 
	t_difficulty.turretaccuracy, 
	"ork_shoota_turret"     -- Do this to the sniper rifle
	)
	
g_modifier_weaponaccuracydecrease2 = Modifier_ApplyToPlayer( modifier_weaponaccuracydecrease3, g_Player2 )

end


--MAIN SCRIPT

function Rule_MissionStart()

if not Event_IsAnyRunning() then
	EventCue_Enable(true)

-- Camera_FocusOnTargetMarker("mkr_scout2", -1)

	--[[Difficulty]]
	Rule_AddOneShot(SetDifficultyLevel, 0.0)
	Cpu_Enable(g_Player6, true)


	--[[Lock Stuff]]
	Restrict_SpaceMarines( g_Player1, 2 )
	
	--[[ Objectives ]]
	
	obj_table_P1 = { title_id = 214050, short_desc_id = 214052, help_tip_id = 214054 }
	obj_table_P2 = { title_id = 214060, short_desc_id = 214062, help_tip_id = 214064 }
	obj_table_S1 = { title_id = 214000, short_desc_id = 214002, help_tip_id = 214004 }
	obj_table_S2 = { title_id = 214010, short_desc_id = 214012, help_tip_id = 214014 }
	obj_table_S3 = { title_id = 214020, short_desc_id = 214022, help_tip_id = 214024 }
	obj_table_S4 = { title_id = 214030, short_desc_id = 214032, help_tip_id = 214034 }
	obj_table_S5 = { title_id = 214040, short_desc_id = 214042, help_tip_id = 214044 }
	
	Util_ObjectiveCreate(obj_table_P1, true)
	
	--[[ ork stuff ]]
	Rule_OrkManager();
	
	--[[ marine stuff ]]
	Rule_ManageScouts();

	Rule_SetInitialResources()
	
	--[[character events]]
	Rule_AddOneShot(Rule_SavetheSarge, 2)
	Rule_AddOneShot(Rule_MaketheKan, 2)
	Rule_AddOneShot(Rule_MakeStampede, 5)		
	
	Rule_Remove(Rule_MissionStart)
	
	--[[Auto save]]
	Rule_AddInterval(Rule_Autosave_214910, 1)	
end

end

function Rule_Autosave_214910() if not Event_IsAnyRunning() then Rule_Remove(Rule_Autosave_214910) Util_Autosave("$214910") end end


--[[ Player 6 Aggressive Ork]] function Rule_AngryOrks()

Cpu_ForceAttack(g_Player6, g_Player1)
Rule_AddInterval(Rule_AngryOrkArmy, 55)

end

function Rule_AngryOrkArmy()

SGroup_CreateIfNotFound("sg_angrymob")
if SGroup_IsEmpty("sg_angrymob") then
	if table.getn(t_angry.egroup) ~= 0 then
		if EGroup_IsEmpty(t_angry.egroup[1]) == false and Player_CanSeeEGroup(g_Player1, t_angry.egroup[1], false) == false then 
			local blueprint = t_angry.blueprint[World_GetRand(1,3)]
			local num = 1
			if t_difficulty.angrymob == 1 then
				num = World_GetRand(5, 7)
			else
				num = World_GetRand(5, 8)
			end
			Util_CreateSquadsAtMarkerEx(g_Player6, "sg_angrymob", blueprint, t_angry.marker[1], t_difficulty.angrymob, num)
		else
			table.remove(t_angry.egroup, 1)
			table.remove(t_angry.marker, 1)
		end
	else
		Rule_Remove(Rule_AngryOrkArmy)
	end
end

end


-- MUSIC/SOUND

function SetupMusicPlaylist()

-- clear the current playlist Sound_PlaylistClear( PC_Music )

-- add tracks to the playlist
Sound_PlaylistAddTrack( PC_Music, "stinger_pressure_stinger" )
Sound_PlaylistAddTrack( PC_Music, "music_theme_spacemarines_01" )
Sound_PlaylistAddTrack( PC_Music, "music_ork_theme" )
-- mark these tracks to play randomly
Sound_PlaylistSetorder( PC_Music, false )
-- add 5 to 10 seconds silence between tracks
Sound_PlaylistSetSilence( PC_Music, 20, 70 )

Sound_PlaylistClear( PC_Ambient )
-- add tracks to the playlist    
Sound_PlaylistAddTrack( PC_Ambient, "ambient_wind" )
-- mark these tracks to play randomly
Sound_PlaylistSetorder( PC_Ambient, false )
-- add 5 to 10 seconds silence between tracks
Sound_PlaylistSetSilence( PC_Ambient, 5, 10 )

-- don't play yet
Sound_PlaylistStart(PC_Ambient)
Sound_PlaylistStart(PC_Music)

Sound_PlaylistPlayNow(PC_Music, "music_theme_spacemarines_01")

end


--RESOURCES function Rule_SetInitialResources()

Player_SetResource(g_Player1, RT_Requisition, 500)
Player_SetResource(g_Player1, RT_Power, 200)

end --SNIPER COST function Rule_SetSniperCosts()

Player_AddResource(g_Player1, RT_Requisition, 200)
Player_AddResource(g_Player1, RT_Power, 120)

end --STRATEGY POINT COST function Rule_SetStrategyPointCosts()

Player_AddResource(g_Player1, RT_Requisition, 200)
Player_AddResource(g_Player1, RT_Power, 0)

end --REINFORCE COST function Rule_AddReinforceCost()

Player_AddResource(g_Player1, RT_Requisition, 500)
Player_AddResource(g_Player1, RT_Power, 0)

end --BASE STARTING COST function Rule_SetBaseConstructionCosts()

Player_AddResource(g_Player1, RT_Requisition, 1000)
Player_AddResource(g_Player1, RT_Power, 500)

end


--SCOUTS STUFF function Rule_ManageScouts()

--[[ Grant Infiltrate ]]
Player_GrantResearch(g_Player1, "marine_scout_infiltrate_research")
Player_GrantResearch(g_Player3, "marine_scout_infiltrate_research")

--[[ Watch Scout Health]]
Rule_AddInterval(Rule_ScoutHealthWatch, 1)

g_reinforcelastpos = Marker_GetPosition(Marker_FromName("mkr_scout2", "basic_marker"))

--[[ Create Scout 2]]
Rule_AddOneShot(Rule_SetSkipStart, 0.0)
Rule_AddOneShot(Rule_CreateScouts2, 1.5)

Rule_AddInterval(Rule_ScoutFirstWarning, 1)

Rule_AddInterval(Rule_InfiltrateTrack, 1)

end

--[[set the stage for if the player skips the NIS]] function Rule_SetSkipStart()

if Prox_AnySquadNearMarker("sg_scouts1", "mkr_scout2") == false then
	Cmd_MoveToMarker("sg_scouts1", "mkr_scout2")
	FOW_RevealMarker("mkr_scout2", 15)
end

end

function Rule_ScoutFirstWarning()

if SGroup_Exists("sg_reinforcefc") == false and Prox_AnySquadNearMarker("sg_scouts1", "mkr_scout2") then

	Util_ObjectiveCreate(obj_table_S1, false)
	
	Rule_AddInterval(Rule_ScoutsInfiltrated, 1)
	Rule_AddOneShot(Rule_IE_Encouter1stScouts, 1)
	

-- Util_Ping_LoopingMkr("pg_orkguard1", "mkr_orkguard1") -- Util_Ping_LoopingMkr("pg_orkguard2", "mkr_orkguard2") -- Util_Ping_LoopingMkr("pg_orkguard3", "mkr_orkguard3") Util_Ping_LoopingMkr("pg_scoutdestination", "mkr_checkpoint1")

-- Rule_AddInterval(Rule_RemovePing_Orkguard1, 1) -- Rule_AddInterval(Rule_RemovePing_Orkguard2, 1) -- Rule_AddInterval(Rule_RemovePing_Orkguard3, 1) Rule_AddInterval(Rule_Checkpoint1, 1)

	Rule_Remove(Rule_ScoutFirstWarning)
elseif SGroup_Exists("sg_reinforcefc") then
	Rule_Remove(Rule_ScoutFirstWarning)
end

end

function Rule_InfiltrateTrack()

if SGroup_IsInfiltrated("sg_scouts1", false) and Event_IsAnyRunning() == false then

--~ Util_StartIntel(EVENTS.IE_ScoutsInvisible) Rule_Remove(Rule_InfiltrateTrack) end

end

--REMOVE PINGS function Rule_RemovePing_Orkguard1()

if Prox_AnySquadNearMarker("sg_scouts1", "mkr_orkguard1") then

	Util_Ping_Stop("pg_orkguard1")

	Rule_Remove(Rule_RemovePing_Orkguard1)
end

end

function Rule_RemovePing_Orkguard2()

if Prox_AnySquadNearMarker("sg_scouts1", "mkr_orkguard2") then

	Util_Ping_Stop("pg_orkguard2")

	Rule_Remove(Rule_RemovePing_Orkguard2)
end

end

function Rule_RemovePing_Orkguard3()

if Prox_AnySquadNearMarker("sg_scouts1", "mkr_orkguard3") then

	Util_Ping_Stop("pg_orkguard3")

	Rule_Remove(Rule_RemovePing_Orkguard3)
end

end


--CHECKPOINT 1 function Rule_ScoutsInfiltrated() if SGroup_IsInfiltrated( "sg_scouts1", true ) then Util_ObjectiveComplete(obj_table_S1.title_id) Util_StartIntel(EVENTS.IE_ScoutsInvisible) Rule_Remove( Rule_ScoutsInfiltrated ) end end

function Rule_Checkpoint1()

if SGroup_Exists("sg_reinforcefc") == false and Prox_AnySquadNearMarker("sg_scouts1", "mkr_checkpoint1") then
	
	if SGroup_IsEmpty("sg_orkguard4") ~= true and EGroup_IsEmpty("eg_bridgepoint") ~= true then
		Cmd_Capture("sg_orkguard4", "eg_bridgepoint")
	end
	

--~ if SGroup_IsEmpty("sg_orkguard1") = true and SGroup_IsEmpty("sg_orkguard2") = true and SGroup_IsEmpty("sg_orkguard3") = true then -- Util_ObjectiveComplete(obj_table_S1.title_id) -- Util_StartIntel(EVENTS.IE_ScoutsInvisible) -- if Rule_Exists( Rule_ScoutsInfiltrated ) then Rule_Remove(Rule_ScoutsInfiltrated) end --~ elseif SGroup_IsEmpty("sg_orkguard1") or SGroup_IsEmpty("sg_orkguard2") or SGroup_IsEmpty("sg_orkguard3") then --~ Util_ObjectiveFail(obj_table_S1.title_id) --~ Util_StartIntel(EVENTS.IE_ScoutsInvisible) --~ if Rule_Exists( Rule_ScoutsInfiltrated ) then Rule_Remove(Rule_ScoutsInfiltrated) end --~ end

	Util_Ping_Stop("pg_orkguard1")
	Util_Ping_Stop("pg_orkguard2")
	Util_Ping_Stop("pg_orkguard3")
	Util_Ping_Stop("pg_scoutdestination")
	
	Rule_AddOneShot(Rule_Scouts2MoveIn, 0.0)
	Rule_AddOneShot(Rule_Scouts2Reveal, 1)
	Rule_AddOneShot(Rule_Scouts2Bridge, 4)
	
	Rule_AddInterval(Rule_ScoutOrkPatrolWarning, 1)
	Rule_AddInterval(Rule_ScoutsSeetheNob, 1)		
	
	Rule_Remove(Rule_Checkpoint1)
elseif SGroup_Exists("sg_reinforcefc") then
	Util_ObjectiveFail(obj_table_S1.title_id)
	if Rule_Exists( Rule_ScoutsInfiltrated ) then Rule_Remove(Rule_ScoutsInfiltrated) end
	Util_Ping_Stop("pg_scoutdestination")
	Rule_Remove(Rule_Checkpoint1)
end

end

function Rule_CreateScouts2()

if SGroup_Exists("sg_reinforcefc") == false then
	Util_CreateSquadsAtMarker(g_Player3, "sg_scouts2", "space_marine_squad_scout", "mkr_scouts2", 1)
	Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_scouts2"), 1), "space_marine_sniper_rifle", 2)
	SGroup_DeSpawn("sg_scouts2")
end

end

function Rule_Scouts2MoveIn()

if SGroup_Exists("sg_reinforcefc") == false and SGroup_Exists("sg_scouts2") and SGroup_IsEmpty("sg_scouts2") == false then
	SGroup_ReSpawn("sg_scouts2")
	Cmd_Infiltrate("sg_scouts2", true)
	Cmd_MoveToMarker("sg_scouts2", "mkr_checkpoint1")
end

end

function Rule_Scouts2Reveal()

if SGroup_Exists("sg_reinforcefc") == false and SGroup_Exists("sg_scouts2") and SGroup_IsEmpty("sg_scouts2") == false then
	SGroup_SetPlayerOwner("sg_scouts2", g_Player1)
	table.insert(t_scouts, "sg_scouts2")

	Util_StartIntel(EVENTS.IE_ScoutsHere)
	
	Ping_Position(Squad_GetPosition(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_scouts2"), 1)), false)
	Cmd_Infiltrate("sg_scouts2", false)
	
	SGroup_AddGroup(SGroup_FromName("sg_scouts1"), SGroup_FromName("sg_scouts2"))
end

end

function Rule_Scouts2Bridge()

if SGroup_Exists("sg_reinforcefc") == false and SGroup_IsEmpty("sg_scouts1") == false and SGroup_Exists("sg_scouts2") and SGroup_IsEmpty("sg_scouts2") == false then
	Util_Ping_LoopingMkr("pg_orkguard4", "mkr_orkguard4")
	Util_ObjectiveCreate(obj_table_S2, false)

	Rule_AddInterval(Rule_OrkGuardOnBridge, 1)

	Rule_AddOneShot(Rule_IE_Encouter2ndScouts, 0)
end

end

function Rule_OrkGuardOnBridge()

if SGroup_Exists("sg_reinforcefc") == false and SGroup_IsEmpty("sg_orkguard4") and SGroup_IsEmpty("sg_scouts1") == false then
	Util_StartIntel(EVENTS.IE_ScoutsAreaSecure)
	Util_ObjectiveComplete(obj_table_S2.title_id)
	Util_Ping_Stop("pg_orkguard4")
	Rule_Remove(Rule_OrkGuardOnBridge)
end

end

function Rule_ScoutOrkPatrolWarning()

if SGroup_Exists("sg_reinforcefc") == false or SGroup_IsEmpty("sg_civiork") == false then
	if Prox_AnySquadNearMarker("sg_scouts1", "mkr_scout3") then
		Util_StartIntel(EVENTS.IE_OrkPatrolWarning)
		FOW_RevealSGroup(SGroup_FromName("sg_civiork"), 30)
		if SGroup_CountSpawned(SGroup_FromName("sg_civiork")) == 2 then
			Ping_Position(Squad_GetPosition(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_civiork"), 2)), false)
		elseif SGroup_CountSpawned(SGroup_FromName("sg_civiork")) == 1 then
			Ping_Position(Squad_GetPosition(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_civiork"), 1)), false)
		end
		Rule_Remove(Rule_ScoutOrkPatrolWarning)
	end
else
	Rule_Remove(Rule_ScoutOrkPatrolWarning)
end

end

function Rule_ScoutsSeetheNob()

SGroup_CreateIfNotFound("sg_nearfirstnob")
if SGroup_IsEmpty("sg_scouts1") == false and SGroup_IsEmpty("sg_orknob1") == false then
	SGroup_Clear(SGroup_FromName("sg_nearfirstnob"))
	local sgroupID = Player_GetAllSquadsNearMarker(g_Player1, "sg_nearfirstnob", "mkr_hill1")
	if not SGroup_IsEmpty("sg_nearfirstnob") then
		
		Util_StartIntel(EVENTS.IE_ScoutsSeetheNob)
		FOW_RevealMarker("mkr_firstnob", 120)
		Rule_Remove(Rule_ScoutsSeetheNob)
	end
	
else
	Rule_Remove(Rule_ScoutsSeetheNob)
end

end


--SCOUTS DIE CAUSE THE PLAYER DIDN'T LISTEN

function Rule_ScoutHealthWatch()

t_scouts = {"sg_scouts1"}

for i = table.getn(t_scouts), 1, -1 do
	if SGroup_Exists(t_scouts[i]) then
		if not SGroup_IsEmpty(t_scouts[i]) then

--[[ g_reinforcepos = Squad_GetPosition(SGroup_GetSpawnedSquadAt(SGroup_FromName(t_scouts[i]), 1))

			if g_reinforcepos ~= Util_ScarPos(0, 0) then
				g_reinforcelastpos = g_reinforcepos
			elseif g_reinforcepos == Util_ScarPos(0, 0) then
				g_reinforcepos = g_reinforcelastpos
			end
			
			if SGroup_IsUnderAttack(t_scouts[i], false) then
				break
			end
]]			
		elseif SGroup_IsEmpty(t_scouts[i]) then
			table.remove(t_scouts, i)
			if table.getn(t_scouts) == 0 then
			
				Rule_AddInterval(Rule_MarinesArrive, 1)
				
				Rule_Remove(Rule_ScoutHealthWatch)
				
				break
			end
		end
	end
end

end

--MARINES DROP POD IN function Rule_MarinesArrive()

if SGroup_Exists("sg_reinforcefc") ~= true then

t_BaseDefense = {
	sgroup = {  "sg_orkhut1", "sg_orkhut2", "sg_orkhut3", "sg_orkhut4", "sg_orkhut5", "sg_orkhut6", "sg_orkhut7"}, 
	egroup = { "eg_orkhut1", "eg_orkhut2", "eg_orkhut3", "eg_orkhut4", "eg_orkhut5", "eg_orkhut6", "eg_orkhut7"}, 
	blueprint = {"ork_squad_shoota_boy", "ork_squad_slugga", "ork_squad_shoota_boy", "ork_squad_slugga", "ork_squad_shoota_boy", "ork_squad_killa_kan", "ork_squad_shoota_boy"}, 
	marker = {"mkr_orkhut1", "mkr_orkhut2", "mkr_orkhut3", "mkr_orkhut4", "mkr_orkhut5", "mkr_orkhut6", "mkr_orkhut7"}, 
	num = {1, 1, 1, 1, 1, 1, 1}, 
	size = {6, 5, 8, 7, 9, 1, 8},
	upgrade = {0, 0, 0},
	load = {1},
	weapon = {"weapon"}
}

	Rule_AddOneShot(Rule_IE_ScoutsDyingEarly, 5)

end

-- Rule_KillAllScoutThings();

g_reinforce = g_reinforce+1
SGroup_CreateIfNotFound("sg_reinforcefc")
local pos = Marker_GetPosition(Marker_FromName("mkr_orkguard5", "basic_marker"))
if g_reinforce == 1 and SGroup_IsEmpty("sg_reinforcefc") then

-- SGroup_Clear(SGroup_CreateIfNotFound("sg_reinforce"))

	Rule_AddOneShot(Rule_TrackCharacters_v1, 0.0)
	
	if not Rule_Exists(Rule_AllDeadTooEarly) then
		Rule_AddInterval(Rule_AllDeadTooEarly, 2)
	end	
	
	if not Rule_Exists(Rule_FCLives) then
		Rule_AddInterval(Rule_FCLives, 1)
	end	
	
elseif g_reinforce == 2 then
	Util_CreateSquadsAndDropPodIn(g_Player1, "sg_reinforcemarines1", "space_marine_squad_tactical", pos--[[g_reinforcepos]], 1, 8)
	SGroup_AddGroup(SGroup_CreateIfNotFound("sg_reinforce"), SGroup_FromName("sg_reinforcemarines1"))
	
	if not Rule_Exists(Rule_MarineLives) then
		Rule_AddInterval(Rule_MarineLives, 3)
	end	

elseif g_reinforce == 3 then
	Util_CreateSquadsAndDropPodIn(g_Player1, "sg_reinforcemarines2", "space_marine_squad_tactical", pos--[[g_reinforcepos]], 1, 8)
	SGroup_AddGroup(SGroup_CreateIfNotFound("sg_reinforce"), SGroup_FromName("sg_reinforcemarines2"))

elseif g_reinforce > 7 then
	
	SGroup_AddGroup(SGroup_CreateIfNotFound("sg_scouts1"), SGroup_FromName("sg_reinforce"))
	table.insert(t_scouts, "sg_scouts1")
	
	if not Rule_Exists(Rule_MarinesUpgrade) then
		Rule_AddOneShot(Rule_MarinesUpgrade, 4)
	end

-- Rule_AddInterval(Rule_ScoutHealthWatch, 1)

	g_reinforce = 0
	
	Rule_Remove(Rule_MarinesArrive)
end

end

function Rule_TrackCharacters_v1() SGroup_CreateIfNotFound("sg_reinforcefc") Util_TrackCharacterAndDropPodIn( g_Player1, "sg_reinforcefc", "space_marine_squad_force_commander", "mkr_orkguard5" ) SGroup_AddGroup(SGroup_CreateIfNotFound("sg_reinforce"), SGroup_FromName("sg_reinforcefc")) end

function Rule_MarinesUpgrade()

--[[ Watch "Scout" Health	
Marine Reinforcements are added to "sg_scouts1" so that all of the functions detecting "sg_scouts1" still work!
]]

if SGroup_CountSpawned(SGroup_FromName("sg_reinforcemarines1")) == 1 then Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_reinforcemarines1"), 1), "space_marine_heavy_bolter_tactical", 2) end

if SGroup_CountSpawned(SGroup_FromName("sg_reinforcemarines2")) == 1 then Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_reinforcemarines2"), 1), "space_marine_heavy_bolter_tactical", 2) end

if not Rule_Exists(Rule_Autosave_214912) then
	Rule_AddInterval(Rule_Autosave_214912, 1)
end

end

function Rule_Autosave_214912() if not Event_IsAnyRunning() then Rule_Remove(Rule_Autosave_214912) Util_Autosave("$214912") end end


--[[ Marines Arrive at Waterworks]]

--MARINES DROP POD IN

function Rule_MarinesArrive2()

if SGroup_Exists("sg_reinforcefc") == true and g_reinforce == 0  then
	Rule_Remove(Rule_MarinesArrive2)

-- print("removing the rule") end

Rule_Remove(Rule_ScoutHealthWatch)

g_reinforce = g_reinforce+1
SGroup_CreateIfNotFound("sg_reinforcefc")
local pos = Marker_GetPosition(Marker_FromName("mkr_orkguard5", "basic_marker"))
if g_reinforce == 1 and SGroup_IsEmpty("sg_reinforcefc") then

-- SGroup_Clear(SGroup_CreateIfNotFound("sg_reinforce")) -- SGroup_Clear(SGroup_CreateIfNotFound("sg_reinforcefc"))

	Rule_AddOneShot(Rule_TrackCharacters_v1, 0.0)
	
	if not Rule_Exists(Rule_FCLives) then
		Rule_AddInterval(Rule_FCLives, 1)
	end	
	
	if not Rule_Exists(Rule_AllDeadTooEarly) then
		Rule_AddInterval(Rule_AllDeadTooEarly, 2)
	end	

--[[ Util_CreateSquadsAndDropPodIn(g_Player1, "sg_reinforcefc", "space_marine_squad_force_commander", pos--[[g_reinforcepos]], 1, 1) SGroup_AddGroup(SGroup_CreateIfNotFound("sg_reinforce"), SGroup_FromName("sg_reinforcefc")) ]] elseif g_reinforce == 2 then SGroup_Clear(SGroup_CreateIfNotFound("sg_reinforcemarines1")) Util_CreateSquadsAndDropPodIn(g_Player1, "sg_reinforcemarines1", "space_marine_squad_tactical", pos--[[g_reinforcepos]], 1, 8) SGroup_AddGroup(SGroup_CreateIfNotFound("sg_reinforce"), SGroup_FromName("sg_reinforcemarines1"))

	if not Rule_Exists(Rule_MarineLives) then
		Rule_AddInterval(Rule_MarineLives, 3)
	end	

elseif g_reinforce == 3 then
	SGroup_Clear(SGroup_CreateIfNotFound("sg_reinforcemarines2"))
	Util_CreateSquadsAndDropPodIn(g_Player1, "sg_reinforcemarines2", "space_marine_squad_tactical", pos--[[g_reinforcepos]], 1, 8)
	SGroup_AddGroup(SGroup_CreateIfNotFound("sg_reinforce"), SGroup_FromName("sg_reinforcemarines2"))

elseif g_reinforce > 7 then

	Util_StartIntel(EVENTS.IE_ScoutsKilltheNob)
	
	SGroup_AddGroup(SGroup_CreateIfNotFound("sg_scouts1"), SGroup_FromName("sg_reinforce"))
	table.insert(t_scouts, "sg_scouts1")
	
	if not Rule_Exists(Rule_MarinesUpgrade2) then
		Rule_AddOneShot(Rule_MarinesUpgrade2, 6)
	end
	
	g_reinforce = 0
	
	Rule_Remove(Rule_MarinesArrive2)
end

end

function Rule_MarinesUpgrade2()

if SGroup_CountSpawned(SGroup_FromName("sg_reinforcemarines1")) == 1 then Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_reinforcemarines1"), 1), "space_marine_heavy_bolter_tactical", 2) end

if SGroup_CountSpawned(SGroup_FromName("sg_reinforcemarines2")) == 1 then Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_reinforcemarines2"), 1), "space_marine_heavy_bolter_tactical", 2) end

if not Rule_Exists(Rule_Autosave_214912) then
	Rule_AddInterval(Rule_Autosave_214912, 1)
end

end

--[[Call the FC back]] function Rule_FCLives() SGroup_CreateIfNotFound("sg_reinforcefc") Util_TrackCharacterAndDropPodIn( g_Player1, "sg_reinforcefc", "space_marine_squad_force_commander", "mkr_orkguard5" ) SGroup_AddGroup(SGroup_CreateIfNotFound("sg_reinforce"), SGroup_FromName("sg_reinforcefc")) end

function Rule_MarineLives() local sgID = SGroup_CreateIfNotFound("sg_reinforcemarines1") local sgID2 = SGroup_CreateIfNotFound("sg_reinforcemarines2") if SGroup_CountDeSpawned(sgID2) == 0 and SGroup_CountSpawned(sgID2) == 0 and SGroup_CountDeSpawned(sgID) == 0 and SGroup_CountSpawned(sgID) == 0 then Util_CreateSquadsAndDropPodIn(g_Player1, "sg_reinforcemarines1", "space_marine_squad_tactical", Marker_GetPosition(Marker_FromName("mkr_orkguard5", "basic_marker")), 1, 8) SGroup_AddGroup(SGroup_CreateIfNotFound("sg_reinforce"), SGroup_FromName("sg_reinforcemarines1")) end end

function Rule_AllDeadTooEarly()

if SGroup_CountSpawned(SGroup_FromName("sg_reinforce")) == 0 and SGroup_IsEmpty("sg_scouts1") then
	g_reinforcedeadcount = g_reinforcedeadcount+1
	if g_reinforcedeadcount > 3 then
		Util_ObjectiveFail(obj_table_P1.title_id)
		World_SetTeamWin( g_Player2, "" )
		Rule_AddIntervalEx( Rule_GameOver,2,1 )
		if Rule_Exists(Rule_FCLives) then
			Rule_Remove(Rule_FCLives)
		end
		if Rule_Exists(Rule_MarineLives) then
			Rule_Remove(Rule_MarineLives)
		end
		Rule_Remove(Rule_AllDeadTooEarly)
	end
elseif g_makebase == 1 then
	Rule_Remove(Rule_AllDeadTooEarly)
end

end


--ORKS

function Rule_OrkManager()

--[[Create Base Defenses for Orks]]
Rule_AddInterval(Rule_BaseDefense, 5)

--[[Create First Ork Guard]]
Rule_Add(Rule_OrkGuardSetup);

--[[Create Orks In Homestead]]
Rule_AddOneShot(Rule_CiviOrkCreate, 2);

--[[Create Orks Guarding the Hill]]
Rule_AddOneShot(Rule_HillOrkCreate, 1);

--[[Create Orks On the Pump Station]]
Rule_AddOneShot(Rule_OrkPumpGuardCreate, 3);

--[[Create the Target]]
Rule_AddOneShot(Rule_OrkNob1Create, 4);

end


--BASE DEFENSE

function Rule_BaseDefense()

if SGroup_Exists("sg_reinforce") then
	t_BaseDefense = {
		sgroup = {  "sg_orkhut1", "sg_orkhut2", "sg_orkhut3", "sg_orkhut4", "sg_orkhut5", "sg_orkhut6", "sg_orkhut7"}, 
		egroup = { "eg_orkhut1", "eg_orkhut2", "eg_orkhut3", "eg_orkhut4", "eg_orkhut5", "eg_orkhut6", "eg_orkhut7"}, 
		blueprint = {"ork_squad_shoota_boy", "ork_squad_slugga", "ork_squad_shoota_boy", "ork_squad_slugga", "ork_squad_shoota_boy", "ork_squad_killa_kan", "ork_squad_shoota_boy"}, 
		marker = {"mkr_orkhut1", "mkr_orkhut2", "mkr_orkhut3", "mkr_orkhut4", "mkr_orkhut5", "mkr_orkhut6", "mkr_orkhut7"}, 
		num = {1, 1, 1, 1, 1, 1, 1}, 
		size = {6, 5, 8, 7, 9, 1, 8},
		upgrade = {0, 0, 0},
		load = {1},
		weapon = {"weapon"}
	}
else
	t_BaseDefense = {
		sgroup = { "sg_orkhut3", "sg_orkhut4", "sg_orkhut5", "sg_orkhut6", "sg_orkhut7"}, 
		egroup = { "eg_orkhut3", "eg_orkhut4", "eg_orkhut5", "eg_orkhut6", "eg_orkhut7"}, 
		blueprint = { "ork_squad_shoota_boy", "ork_squad_slugga", "ork_squad_shoota_boy", "ork_squad_killa_kan", "ork_squad_shoota_boy"}, 
		marker = {"mkr_orkhut3", "mkr_orkhut4", "mkr_orkhut5", "mkr_orkhut6", "mkr_orkhut7"}, 
		num = {1, 1, 1, 1, 1}, 
		size = {8, 7, 9, 1, 8},
		upgrade = {0, 0, 0},
		load = {1},
		weapon = {"weapon"}
	}
end

if table.getn(t_BaseDefense.egroup) < 1 then
	Rule_Remove(Rule_BaseDefense)
else
	
	SGroup_CreateIfNotFound("sg_nearbase")
	for i = table.getn(t_BaseDefense.egroup), 1, -1 do
	
		SGroup_CreateIfNotFound(t_BaseDefense.sgroup[i])
		
		if not EGroup_IsEmpty(t_BaseDefense.egroup[i]) then
			

-- print("base "..i.." is not empty")

			SGroup_Clear(SGroup_FromName("sg_nearbase"))
			local sgroupID = Player_GetAllSquadsNearMarker(g_Player1, "sg_nearbase", t_BaseDefense.marker[i])
			
			if SGroup_IsEmpty("sg_nearbase") ~= true and SGroup_IsEmpty( t_BaseDefense.sgroup[i]) == true and g_base_delay > g_rand_delay then
				
				g_rand_delay = World_GetRand(3, 6)
				g_base_delay = 0
				if t_BaseDefense.blueprint[i] == "ork_squad_killa_kan" then
					g_kandelay = g_kandelay +1
					if g_kandelay == 4 then
						g_kandelay = 1
					end
				end
				

-- print("should be creating someone now") if t_BaseDefense.blueprint[i] ~= "ork_squad_killa_kan" or g_kandelay > 2 then Util_CreateSquadsAtMarkerEx(g_Player2, t_BaseDefense.sgroup[i],t_BaseDefense.blueprint[i],t_BaseDefense.marker[i], t_BaseDefense.num[i], t_BaseDefense.size[i])

					if t_BaseDefense.upgrade[i] == 1 then
						for y = 1,t_BaseDefense.load[i] do
							SGroup_ForEach( t_BaseDefense.sgroup[i],	function( sgroupid, itemindex, squadID ) Squad_UpgradeWeapon( squadID, t_BaseDefense.weapon[i])  end )
						end
					end
					
					Cmd_SetStance(t_BaseDefense.sgroup[i], STANCE_Attack)
					Cmd_AttackMovePos(t_BaseDefense.sgroup[i], Squad_GetPosition(SGroup_GetSpawnedSquadAt("sg_nearbase", 1)))
				end
				
			end
		else
			table.remove(t_BaseDefense.egroup, i)
			table.remove(t_BaseDefense.sgroup, i)
			table.remove(t_BaseDefense.marker, i)
		end
	end
	
	g_base_delay = g_base_delay+1
	
end

end


--ORK GUARD 1

function Rule_OrkGuardSetup()

t_OrkGuard = {
	sgroup = { "sg_orkguard1", "sg_orkguard2", "sg_orkguard3", "sg_orkguard4", "sg_orkguard5"}, 
	blueprint = {"ork_squad_slugga", "ork_squad_shoota_boy", "ork_squad_slugga", "ork_squad_shoota_boy", "ork_squad_shoota_boy"}, 
	marker = {"mkr_orkguard1", "mkr_orkguard2", "mkr_orkguard3", "mkr_orkguard4", "mkr_orkguard5"}, 
	num = {1, 1, 1, 1, 1}, 
	size = {3, 4, 9, 6, 3},
	upgrade = {0, 0, 0, 0, 0},
	load = {1},
	weapon = {"weapon"}
}

if g_OrkGuard_iter <= table.getn(t_OrkGuard.sgroup)then

	for i = g_OrkGuard_iter, table.getn(t_OrkGuard.sgroup) do
		SGroup_CreateIfNotFound(t_OrkGuard.sgroup[i])
		if SGroup_IsEmpty(t_OrkGuard.sgroup[i]) then
			Util_CreateSquadsAtMarkerEx(g_Player2, t_OrkGuard.sgroup[i], t_OrkGuard.blueprint[i], t_OrkGuard.marker[i], t_OrkGuard.num[i], t_OrkGuard.size[i])
			
			if t_OrkGuard.upgrade[i] == 1 then
				for y = 1, t_OrkGuard.load[i] do
					SGroup_ForEach( t_OrkGuard.sgroup[i],	function( sgroupid, itemindex, squadID ) Squad_UpgradeWeapon( squadID, t_OrkGuard.weapon[i])  end )
				end
			end
			
			Cmd_SetStance(t_OrkGuard.sgroup[i], STANCE_Hold)
		end
		break
	end
	
else	

	--[[CREATE GUARD TO DIE ]]
	Util_CreateSquadsAtMarkerEx(g_Player5, "sg_killguard01", "guard_squad_soldier", "mkr_killguard01", 1, 10)
	SGroup_SetAvgHealth("sg_killguard01", 0.47)
	
	--[[CREATE GROTZ ]]
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_scavangegrotz", "ork_squad_grot", "mkr_scavangegrotz", 1, 7)
	Cmd_SetStance("sg_scavangegrotz", STANCE_CeaseFire)
	
	if not Rule_Exists(Rule_OrkGuardDetect) then
		
		Rule_AddInterval(Rule_OrkGuardDetect, 1)
		Rule_AddInterval(Rule_OrkGuard1UnderAttack, 1)
		Rule_AddInterval(Rule_GuardSlaughter, 1)
		Rule_AddInterval(Rule_ScavangingGrotz, 1)
		
	end
	Rule_Remove(Rule_OrkGuardSetup)
	
end

g_OrkGuard_iter = g_OrkGuard_iter+1

end

function Rule_OrkGuardDetect()

if table.getn(t_OrkGuard.sgroup) < 1 then
	Rule_Remove(Rule_OrkGuardDetect)
else
	
	SGroup_CreateIfNotFound("sg_nearOrkGuard")
	for i = table.getn(t_OrkGuard.sgroup), 1, -1 do
		
		if not SGroup_IsEmpty(t_OrkGuard.sgroup[i]) then
			SGroup_Clear(SGroup_FromName("sg_nearOrkGuard"))
			local sgroupID = Player_GetAllSquadsNearMarker(g_Player1, "sg_nearOrkGuard", t_OrkGuard.marker[i])
			if SGroup_IsEmpty("sg_nearOrkGuard") ~= true or SGroup_IsUnderAttack("sg_orkguard1", false) then
				
				Cmd_SetStance(t_OrkGuard.sgroup[i], STANCE_Hold)
			--[[	Cmd_AttackSGroup(t_OrkGuard.sgroup[i], "sg_nearOrkGuard")
				]]
			elseif SGroup_IsUnderAttack(t_OrkGuard.sgroup[i], false) then
				Cmd_SetStance(t_OrkGuard.sgroup[i], STANCE_Attack)
			end
		else
			table.remove(t_OrkGuard.sgroup, i)
			table.remove(t_OrkGuard.marker, i)
		end
	end
	
end

end

--[[ ORK GUARD 1: Chicken Shit ]] function Rule_OrkGuard1UnderAttack()

if not SGroup_IsEmpty("sg_orkguard1") then
	if SGroup_IsUnderAttack("sg_orkguard1", false) then
		
		Rule_AddOneShot(Rule_IE_1stStealthAttackonOrks, 0.0)
		
		if not Rule_Exists(Rule_OrkGuard1Retreat) then
			Rule_AddInterval(Rule_OrkGuard1Retreat, 1);
		end
		Rule_Remove(Rule_OrkGuard1UnderAttack);
	end
end

end

function Rule_OrkGuard1Retreat()

if not SGroup_IsEmpty("sg_orkguard1") then
	if Squad_Count(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_orkguard1"), 1)) < 3 then

		Rule_AddOneShot(Rule_IE_1stSquadofOrksRun, 0 )

		Cmd_MoveToMarker("sg_orkguard1", "mkr_orkguard2");
		
		table.remove(t_OrkGuard.sgroup, 1)
		table.remove(t_OrkGuard.marker, 1)
		
		Rule_Remove(Rule_OrkGuard1Retreat)
	end
end

end


--Scavanging Grotz function Rule_ScavangingGrotz()

if Prox_AnySquadNearMarker("sg_scouts1", "mkr_scavangegrotz") then

	Cmd_MoveToMarker("sg_scavangegrotz", "mkr_killguard01")
	Cmd_SetStance("sg_scavangegrotz", STANCE_Hold)
	
	Rule_Remove(Rule_ScavangingGrotz)
end

end


--GUARDSMen Slaughtered function Rule_GuardSlaughter()

if Prox_AnySquadNearMarker("sg_scouts1", "mkr_killguard01") then

	SGroup_SetPlayerOwner("sg_killguard01", g_Player4)
	
	Rule_AddInterval(Rule_ResetOrkGuard3, 1)

	Rule_Remove(Rule_GuardSlaughter)
end

end

function Rule_ResetOrkGuard3()

if SGroup_IsEmpty("sg_killguard01") then

	if not SGroup_IsEmpty("sg_orkguard3") and SGroup_IsUnderAttack("sg_orkguard3", false) ~= true then

		Cmd_SetStance("sg_orkguard3", STANCE_CeaseFire)
	
	end

	Rule_Remove(Rule_ResetOrkGuard3)
end

end


--ORK CIVI GUARD function Rule_CiviOrkCreate()

Util_CreateSquadsAtMarkerEx(g_Player2, "sg_civiork", "ork_squad_slugga", "mkr_orkhut2", 1, 7)
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_civiork", "ork_squad_nob_sp", "mkr_orkhut2", 1, 1)
Cmd_AttackMoveMarker("sg_civiork", "mkr_civiork2")
Cmd_SetStance("sg_civiork", STANCE_StandGround)

Rule_AddInterval(Rule_CiviOrkPatrol, 20)
Rule_AddInterval(Rule_CiviOrkUnderAttack, 10);
Rule_Remove(Rule_CiviOrkCreate);

end

function Rule_CiviOrkPatrol()

if SGroup_Exists("sg_civiork") and SGroup_IsEmpty("sg_civiork") ~= true then
	if SGroup_IsUnderAttack("sg_civiork", false) ~= true then
		if g_patrolB == 1 then
			Cmd_AttackMoveMarker("sg_civiork", "mkr_civiork1")
			g_patrolB = 2
		elseif g_patrolB == 2 then
			Cmd_AttackMoveMarker("sg_civiork", "mkr_civiork2")
			g_patrolB = 3
		elseif g_patrolB == 3 then
			Cmd_AttackMoveMarker("sg_civiork", "mkr_civiork3")
			g_patrolB = 1
		end
	end
elseif SGroup_Count(SGroup_FromName("sg_civiork")) == 0 then
	Rule_Remove(Rule_CiviOrkPatrol);
end

end

function Rule_CiviOrkUnderAttack()

if SGroup_Exists("sg_civiork") and SGroup_IsEmpty("sg_civiork") ~= true then
	if SGroup_IsUnderAttack("sg_civiork", false) then
		
		Cmd_SetStance("sg_civiork", STANCE_Attack ) 
		
	end
elseif SGroup_Count(SGroup_FromName("sg_civiork")) == 0 then
	Rule_Remove(Rule_CiviOrkUnderAttack);
end

end


--ORK HILL GUARD function Rule_HillOrkCreate()

Util_CreateSquadsAtMarkerEx(g_Player2, "sg_hillork", "ork_squad_slugga", "mkr_orkhut3", 1, 7)
Cmd_AttackMoveMarker("sg_hillork", "mkr_hill1")
Cmd_SetStance("sg_hillork", STANCE_Hold)

Rule_AddInterval(Rule_HillOrkUnderAttack, 10);
Rule_AddInterval(Rule_HillOrkPatrol, 20);
Rule_Remove(Rule_HillOrkCreate);

end

function Rule_HillOrkPatrol()

if SGroup_Exists("sg_hillork") and SGroup_Count(SGroup_FromName("sg_hillork")) > 0  then
	if not SGroup_IsUnderAttack("sg_hillork", 0) or Squad_Count(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_hillork"), 1)) < 4 then
		if g_patrolC == 1 then
			Cmd_AttackMoveMarker("sg_hillork", "mkr_pump2")
			g_patrolC = 2
		elseif g_patrolC == 2 then
			Cmd_AttackMoveMarker("sg_hillork", "mkr_pump2")
			g_patrolC = 3
		elseif g_patrolC == 3 then
			Cmd_AttackMoveMarker("sg_hillork", "mkr_hill2")
			g_patrolC = 4
		elseif g_patrolC == 4 then
			Cmd_AttackMoveMarker("sg_hillork", "mkr_hill3")
			g_patrolC = 1
		end
	end
elseif SGroup_Count(SGroup_FromName("sg_hillork")) == 0 then
	Rule_Remove(Rule_HillOrkPatrol);
end

end

function Rule_HillOrkUnderAttack()

if SGroup_Exists("sg_hillork") then
	if SGroup_Count(SGroup_FromName("sg_hillork")) > 0 then
		if SGroup_IsUnderAttack("sg_hillork", 0) or Squad_Count(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_hillork"), 1)) < 4 then
			
			Cmd_SetStance("sg_hillork", STANCE_Attack ) 
		--	Cmd_ReinforceTrooper("sg_hillork", 1)
			
		end
	elseif SGroup_Count(SGroup_FromName("sg_hillork")) == 0 then
		Rule_Remove(Rule_HillOrkUnderAttack);
	end
end

end


--ORK PUMP GUARD function Rule_OrkPumpGuardCreate()

for i = 1, 3 do
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_pump"..i, "ork_squad_slugga", "mkr_orkhut3", 1, 5)
	Cmd_AttackMoveMarker("sg_pump"..i, "mkr_pump"..i)
	Cmd_SetStance("sg_pump"..i, STANCE_Hold)
end

Rule_AddInterval(Rule_OrkPumpGuardUnderAttack, 2);
Rule_Remove(Rule_OrkPumpGuardCreate);

end

function Rule_OrkPumpGuardUnderAttack()

for i = 1, 3 do
	if SGroup_Exists("sg_pump"..i) and SGroup_Count(SGroup_FromName("sg_pump"..i)) > 0 then
		
		if SGroup_Count(SGroup_FromName("sg_orknob1")) == 0 then
			SGroup_SetAvgMorale("sg_pump"..i, 0.0)
			Cmd_AttackMoveMarker("sg_pump"..i, "mkr_hill2" )
		end
		
	elseif SGroup_IsEmpty("sg_pump"..i) then
		Rule_Remove(Rule_OrkPumpGuardUnderAttack);
	end
end

end


--ORK NOB 1 function Rule_OrkNob1Create()

Util_CreateSquadsAtMarkerEx(g_Player2, "sg_orknob1", "ork_squad_nob_sp", "mkr_orkhut3", 1, 1)
Cmd_MoveToMarker("sg_orknob1", "mkr_hill1")
Cmd_SetStance("sg_orknob1", STANCE_CeaseFire)

Util_Ping_LoopingMkr("pg_nobPing", "mkr_hill1")

Rule_AddInterval(Rule_OrkNob1UnderAttack, 1);
Rule_Remove(Rule_OrkNob1Create);

end

function Rule_OrkNob1UnderAttack()

if SGroup_Exists("sg_orknob1") and SGroup_IsEmpty("sg_orknob1") == false then
	if SGroup_IsUnderAttack("sg_orknob1", 0) and g_underattack == nil then
		
		g_underattack = 1
		
		Cmd_SetStance("sg_orknob1", STANCE_Attack ) 
		Cmd_SetMeleeStance("sg_orknob1", MSTANCE_Assault ) 
		

--[[ if not Rule_Exists(Rule_OtherOrksManager) then Rule_AddInterval(Rule_OtherOrksManager, 1) end ]] if not Rule_Exists(Rule_WaterworksOwnerCheck) then Rule_AddInterval(Rule_WaterworksOwnerCheck, 1) end

	end
elseif SGroup_IsEmpty("sg_orknob1") then
	
	Util_Ping_Stop("pg_nobPing")
	

--[[ if not Rule_Exists(Rule_OtherOrksManager) then Rule_Add(Rule_OtherOrksManager) end ]] if not Rule_Exists(Rule_MarinesArrive2) then Rule_Add(Rule_MarinesArrive2) end if not Rule_Exists(Rule_ThoseOtherNobz) then Rule_AddInterval(Rule_ThoseOtherNobz, 1) end if not Rule_Exists(Rule_WaterworksOwnerCheck) then Rule_AddInterval(Rule_WaterworksOwnerCheck, 1) end

	Rule_Remove(Rule_OrkNob1UnderAttack);
end

end

--[[THE WATERWORKS CHECKER]]--------------------------------------------------------------------------------

function Rule_WaterworksOwnerCheck()

if g_calledonce == 0 and EGroup_Count(EGroup_FromName("eg_orkwaterworks")) < 1 then
	Util_StartIntel(EVENTS.IE_WaterworksCaptured)
	Util_ObjectiveComplete(obj_table_P1.title_id)
	
	--[[add the angry orks]]
	Rule_AddOneShot(Rule_AngryOrks, 60)
	
	--[[Add the Build a base stuff]]
	Rule_AddOneShot(Rule_Objective_BuildBase, 0.0)

	Rule_AddOneShot(Rule_ServitorsDropIn, 5)
	Rule_AddInterval(Rule_GuardDefense, 12)
	
	if Rule_Exists(Rule_FCLives) then
		Rule_Remove(Rule_FCLives)
	end
	if Rule_Exists(Rule_MarineLives) then
		Rule_Remove(Rule_MarineLives)
	end
	Rule_AddInterval(Rule_FCLives_v2, 1)
	
	Rule_Remove(Rule_WaterworksOwnerCheck)
	g_calledonce = 1
elseif g_calledonce == 1 then
	Rule_Remove(Rule_WaterworksOwnerCheck)
end

end

--[[CALL IN THE SERVITORS]]--------------------------------------------------------------------------------------------- function Rule_ServitorsDropIn()

--[[Mod the Build Speed of Servitors]]
local modifier_hqconstructionspeed = Modifier_Create(
		MAT_EntityType,      -- This modifier will be applied to a weapon type
		"construction_speed_modifier",   -- Modify the max range of the weapon
		MUT_Multiplication,     -- use multiplication
		false, 
		1.2, 
		"servitor"     -- Do this to the sniper rifle
	)
	
g_modifier_hqconstructionspeed = Modifier_ApplyToPlayer( modifier_hqconstructionspeed, g_Player1 )

--[[Unlocking announcement]]
Unrestrict_SquadWithAlerts( g_Player1, "space_marine_squad_scout", "$42904", "none" )
Unrestrict_ResearchWithAlerts( g_Player1, "marine_scout_infiltrate_research", "none", "none" )
Player_UnRestrictResearch( g_Player1, "marine_max_weapons_research")
Player_UnRestrictResearch( g_Player1, "squad_cap_research_1")

local pos = Marker_GetPosition(Marker_FromName("mkr_servitordrop", "basic_marker"))

Util_CreateSquadsAndDropPodIn(g_Player1, "sg_servitor", "space_marine_squad_servitor", pos, 2, 1)

Rule_AddInterval(Rule_ServitorsGo, 1)

Rule_SetBaseConstructionCosts();

end

function Rule_ServitorsGo()

if SGroup_CountSpawned(SGroup_FromName("sg_servitor")) > 0 then
	if Rule_Exists(Rule_PlayerLoses) == false then
		Rule_AddInterval(Rule_PlayerLoses, 1)
	end
	Rule_AddInterval(Rule_ServitorsDead, 1)
	Cmd_MoveToMarker("sg_servitor", "mkr_pump4")
	Rule_Remove(Rule_ServitorsGo)
end

end

function Rule_ServitorsDead()

if SGroup_IsEmpty("sg_servitor") and Player_HasBuildingType(g_Player1, "space_marine_hq") == false then
	Util_ObjectiveFail(obj_table_base.title_id)
	World_SetTeamWin( g_Player2, "" )
	Rule_AddIntervalEx( Rule_GameOver,5,1 )
	Rule_Remove(Rule_ServitorsDead)
elseif Player_HasBuildingType(g_Player1, "space_marine_hq") then
	Rule_Remove(Rule_ServitorsDead)
end

end

--[[Call the FC back]] function Rule_FCLives_v2() SGroup_CreateIfNotFound("sg_reinforcefc") Util_TrackCharacterAndDropPodIn( g_Player1, "sg_reinforcefc", "space_marine_squad_force_commander", "mkr_orkhut2" ) SGroup_AddGroup(SGroup_CreateIfNotFound("sg_reinforce"), SGroup_FromName("sg_reinforcefc")) end

--[[PINGING THE NOBS]]------------------------------------------------------------------------------------------------

function Rule_ThoseOtherNobz()

t_nobmarker = {"mkr_nobhouse1", "mkr_nobhouse2", "mkr_nobhouse3"}

for i = 1, 3 do
	
	if not SGroup_Exists("sg_nobhouse"..i) then
		local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player2, "sg_nobhouse"..i, "ork_squad_nob_sp", t_nobmarker[i], 1, 1)
		
		SGroup_AddGroup(SGroup_CreateIfNotFound("sg_nobhouseall"), sgroupID)
		
	elseif SGroup_Exists("sg_nobhouse"..i) and SGroup_IsEmpty("sg_nobhouse"..i) and g_cleansegiven == 1 then
		Util_Ping_Stop("pg_nobhouse"..i)
	end
	
end

if not Rule_Exists(Rule_FinalBaseDead) then
	Rule_AddInterval(Rule_FinalBaseDead, 5)
end

end

--[[BASE ERADICATION]]--------------------------------------------------------------------------------------------------- function Rule_FinalBaseDead()

EGroup_AddGroup(EGroup_CreateIfNotFound("eg_Player2All"), Player_GetEntities(g_Player2))

local blueprinttable = {
	{ name = "ork_boy_hut", count = 1 },
	{ name = "ork_generator", count = 1 },
	{ name = "ork_hq", count = 1 },
	{ name = "ork_mek_shop", count = 1 },
	{ name = "ork_pile_o_guns", count = 1 }
}

Rule_AddBuildings	= function( egroupid, itemindex, entityID )

	if Entity_GetBlueprintName(entityID) == "ork_boy_hut" 
		or Entity_GetBlueprintName(entityID) == "ork_generator" 
		or Entity_GetBlueprintName(entityID) == "ork_hq" 
		or Entity_GetBlueprintName(entityID) == "ork_mek_shop" 
		or Entity_GetBlueprintName(entityID) == "ork_pile_o_guns" 
		then
		EGroup_Add(EGroup_CreateIfNotFound("eg_Orkendbase"), entityID)
	end
	
end

if EGroup_ContainsBlueprints("eg_Player2All", blueprinttable, false) == false then

	if Objective_Exists(obj_table_P2.title_id) == false then Util_ObjectiveCreate(obj_table_P2, true) end
	
	Util_ObjectiveComplete(obj_table_P2.title_id)		

	if not Rule_Exists(Rule_ClosingNISsetup) then Rule_AddOneShot(Rule_ClosingNISsetup, 3) end
	
	Rule_Remove( Rule_FinalBaseDead )
	
else
	EGroup_ForEach(EGroup_FromName("eg_Player2All"), Rule_AddBuildings)
	g_baseisdead = 0
end

end

function Rule_ClosingNISsetup()

--Fade_Start(2, false)
Player_GetAllSquadsNearMarker(g_Player1, "sg_NISendclear", "mkr_NISgabend")
Player_GetAllSquadsNearMarker(g_Player1, "sg_NISendclear", "mkr_NISIsend")
Player_AddSquadsToSGroup(g_Player2, "sg_NISendclear")

Rule_AddOneShot(Rule_ClosingNISstart, 2)

end

function Rule_ClosingNISstart()

--[[ if not EGroup_IsEmpty("eg_NISorkbase") then EGroup_DeSpawn("eg_NISorkbase") end SGroup_DeSpawn("sg_NISendclear") Util_CreateSquadsAtMarker(g_Player1, "sg_NISfcend", "space_marine_squad_force_commander", "mkr_NISgabend", 1) SGroup_SetHealthInvulnerable("sg_NISfcend", 1) Cmd_SetStance("sg_NISfcend", STANCE_CeaseFire) Cmd_MoveToMarker("sg_NISfcend", "mkr_NISgabend") Util_CreateSquadsAtMarker(g_Player1, "sg_NISisend", "space_marine_squad_librarian", "mkr_NISIsend", 1) SGroup_SetHealthInvulnerable("sg_NISisend", 1) Cmd_SetStance("sg_NISisend", STANCE_CeaseFire) Cmd_MoveToMarker("sg_NISisend", "mkr_NISIsend") ]] Rule_RemoveAll() Util_StartNIS(EVENTS.NIS_Closing)

end

--[[ GUARD DEFENSE]]----------------------------------------------------------------------------------------------------------------------------------- function Rule_GuardDefense()

t_GuardDefense = {
	sgroup = { "sg_orkguard7", "sg_orkguard8", "sg_orkguard9", "sg_orkguard6", "sg_orkguard10",  "sg_orkguard18", "sg_orkguard15", "sg_orkguard12", "sg_orkguard11", "sg_orkguard19", "sg_orkguard14", "sg_orkguard13"}, 
	egroup = { "eg_orkhut3", "eg_orkhut3", "eg_orkhut3", "eg_orkhut3", "eg_orkhut3", "eg_orkhut4", "eg_orkhut4", "eg_orkhut4", "eg_orkhut7", "eg_orkhut7", "eg_orkhut7", "eg_orkhut7", "eg_orkhut7"}, 
	blueprint = { "ork_squad_shoota_boy", "ork_squad_slugga", "ork_squad_tankbusta", "ork_squad_slugga"}, 
	marker = {"mkr_orkhut3", "mkr_orkhut3", "mkr_orkhut3", "mkr_orkhut3", "mkr_orkhut3", "mkr_orkhut4", "mkr_orkhut4", "mkr_orkhut4", "mkr_orkhut7", "mkr_orkhut7", "mkr_orkhut7", "mkr_orkhut7", "mkr_orkhut7"}, 
	marker2 = {"mkr_orkguard7", "mkr_orkguard8", "mkr_orkguard9", "mkr_orkguard6", "mkr_orkguard10",  "mkr_orkguard18", "mkr_orkguard15", "mkr_orkguard12", "mkr_orkguard11", "mkr_orkguard19", "mkr_orkguard14", "mkr_orkguard13"}, 
}

if table.getn(t_GuardDefense.egroup) < 1 then
	Rule_Remove(Rule_GuardDefense)
else
	
	SGroup_CreateIfNotFound("sg_Guardnearbase")
	for i = table.getn(t_GuardDefense.sgroup), 1, -1 do
	

-- print(t_GuardDefense.sgroup[i])

		SGroup_CreateIfNotFound(t_GuardDefense.sgroup[i])
		
		if not EGroup_IsEmpty(t_GuardDefense.egroup[i]) then
			

-- print("base "..i.." is not empty")

			SGroup_Clear(SGroup_FromName("sg_Guardnearbase"))
			local sgroupID = Player_GetAllSquadsNearMarker(g_Player1, "sg_Guardnearbase", t_GuardDefense.marker[i])
			
			if SGroup_IsEmpty("sg_Guardnearbase") == true and SGroup_IsEmpty( t_GuardDefense.sgroup[i]) == true then
				

-- print("should be creating someone now") local size = World_GetRand(4, 7) local rand = World_GetRand(1, 4) Util_CreateSquadsAtMarkerEx(g_Player2, t_GuardDefense.sgroup[i],t_GuardDefense.blueprint[rand],t_GuardDefense.marker[i], 1, size)

				Cmd_SetStance(t_GuardDefense.sgroup[i], STANCE_Attack)
				Cmd_AttackMoveMarker(t_GuardDefense.sgroup[i], t_GuardDefense.marker2[i])
				
			end
		else
			table.remove(t_GuardDefense.egroup, i)
			table.remove(t_GuardDefense.sgroup, i)
			table.remove(t_GuardDefense.marker, i)
			table.remove(t_GuardDefense.marker2, i)
		end
	end
	
end

end


--[[ADDITIONAL CHARACTER STUFF ]]

--[[SAVE THE SERGEANT]] function Rule_SavetheSarge()

--[[Mod the armourclass of the Space Marine Sergeant]] local modifier_sargepowerarmour = Modifier_Create( MAT_EntityType, -- This modifier will be applied to a weapon type "armour_modifier", -- Modify the max range of the weapon MUT_Multiplication, -- use multiplication false, 5, "sergeant" -- Do this to the sniper rifle ) g_modifier_sargepowerarmour = Modifier_ApplyToPlayer( modifier_sargepowerarmour, g_Player3 )

Util_CreateSquadsAtMarkerEx(g_Player3, "sg_sarge", "space_marine_squad_tactical", "mkr_orkguard17", 1, 2)
Cmd_SetStance("sg_sarge", STANCE_CeaseFire)
SGroup_SetHealthInvulnerable("sg_sarge", true)

Util_CreateSquadsAtMarkerEx(g_Player3, "sg_sargesmen", "space_marine_squad_tactical", "mkr_sargesmen", 1, 1)
Cmd_SetStance("sg_sargesmen", STANCE_CeaseFire)
SGroup_SetAvgHealth("sg_sargesmen", .05)
SGroup_AddLeaders( "sg_sargesmen" ) 
SGroup_SetHealthInvulnerable("sg_sargesmen", true)

Util_CreateSquadsAtMarkerEx(g_Player2, "sg_sargesorks", "ork_squad_slugga", "mkr_orkguard17", 1, 15)
Cmd_SetStance("sg_sargesorks", STANCE_CeaseFire)
SGroup_SetHealthInvulnerable("sg_sargesorks", true)

Rule_AddInterval(Rule_SargesMenRun, 1)
Rule_AddInterval(Rule_SargeFights, 1)

end

function Rule_SargesMenRun()

SGroup_CreateIfNotFound("sg_nearsarge")
if not SGroup_IsEmpty("sg_sargesmen") then
	SGroup_Clear(SGroup_FromName("sg_nearsarge"))
	local sgroupID = Player_GetAllSquadsNearMarker(g_Player1, "sg_nearsarge", "mkr_sargesmen")
	if not SGroup_IsEmpty("sg_nearsarge") then
		
		Util_StartIntel(EVENTS.IE_SaveSarge)
		Util_Ping_LoopingMkr("p_sarge", "mkr_orkguard17")
		
		Cmd_SetStance("sg_sargesmen", STANCE_Attack)
		Cmd_AttackMoveMarker("sg_sargesmen", "mkr_orkguard17")
		SGroup_SetHealthInvulnerable("sg_sargesmen", false)
		
		Rule_Remove(Rule_SargesMenRun)
	end
	
else
	Rule_Remove(Rule_SargesMenRun)
end

end

function Rule_SargeFights()

SGroup_CreateIfNotFound("sg_nearsarge2")
if not SGroup_IsEmpty("sg_sarge") then
	SGroup_Clear(SGroup_FromName("sg_nearsarge2"))
	local sgroupID = Player_GetAllSquadsNearMarker(g_Player1, "sg_nearsarge2", "mkr_sargesmen")
	if not SGroup_IsEmpty("sg_nearsarge2") then
		
	--	SGroup_SetAvgHealth("sg_sargesmen", .00)
		

-- Util_StartIntel(EVENTS.IE_SargeFights) Util_Ping_Stop("p_sarge")

		Cmd_SetStance("sg_sarge", STANCE_Attack)
		Cmd_SetMeleeStance("sg_sarge", MSTANCE_Assault)
		Cmd_SetMeleeStance("sg_sargesmen", MSTANCE_Assault)
		
		Cmd_SetStance("sg_sargesorks", STANCE_Attack)
		Cmd_AttackSGroup("sg_sargesorks", "sg_sarge")
		
		SGroup_SetHealthInvulnerable("sg_sarge", false)
		SGroup_SetHealthInvulnerable("sg_sargesorks", false)
		
		Rule_AddInterval(Rule_SargeJoinsUp, 1)
		Rule_Remove(Rule_SargeFights)
	end
	
else
	Rule_Remove(Rule_SargeFights)
end

end

function Rule_SargeJoinsUp()

if SGroup_IsEmpty("sg_sargesorks") then
	if SGroup_IsEmpty("sg_sarge") == false then
		Util_StartIntel(EVENTS.IE_SargeJoins)
		SGroup_SetPlayerOwner("sg_sarge", g_Player1)
	end
	if SGroup_IsEmpty("sg_sargesmen") == false then
		SGroup_SetPlayerOwner("sg_sargesmen", g_Player1)
	end
	if EGroup_IsEmpty("eg_sargespost") == false then
		EGroup_SetPlayerOwner("eg_sargespost", g_Player1)
	end
	Rule_Remove(Rule_SargeJoinsUp)
end

end


--[[The Kan Intro]]

function Rule_MaketheKan()

Util_CreateSquadsAtMarkerEx(g_Player5, "sg_kanmarines", "guard_squad_soldier", "mkr_kanmarines", 1, 8)
Cmd_SetStance("sg_kanmarines", STANCE_CeaseFire)
SGroup_SetHealthInvulnerable("sg_kanmarines", true)

Util_CreateSquadsAtMarkerEx(g_Player5, "sg_kanguard", "guard_squad_soldier", "mkr_kanguard", 1, 8)
Cmd_SetStance("sg_kanguard", STANCE_CeaseFire)
SGroup_SetHealthInvulnerable("sg_kanguard", true)

Util_CreateSquadsAtMarker(g_Player2, "sg_strandedkan", "ork_squad_killa_kan", "mkr_strandedkan", 1)
Cmd_SetStance("sg_strandedkan", STANCE_CeaseFire)

-- SGroup_SetAvgHealth("sg_strandedkan", t_difficulty.kanhealth) -- SGroup_SetHealthInvulnerable("sg_strandedkan", true)

Rule_AddInterval(Rule_SeetheKan, 1)
Rule_AddInterval(Rule_KanDead_backup, 1)

end

function Rule_SeetheKan()

SGroup_CreateIfNotFound("sg_nearkan")
if not SGroup_IsEmpty("sg_strandedkan") then
	SGroup_Clear(SGroup_FromName("sg_nearkan"))
	local sgroupID = Player_GetAllSquadsNearMarker(g_Player1, "sg_nearkan", "mkr_strandedkan")
	if not SGroup_IsEmpty("sg_nearkan") then
		
		Util_StartIntel(EVENTS.IE_SeetheKan)
		Util_Ping_LoopingMkr("p_kan", "mkr_strandedkan")
		FOW_RevealMarker("mkr_seekan", 15)
		

-- SGroup_SetHealthInvulnerable("sg_strandedkan", false)

		Rule_AddOneShot(Rule_KanFights, 4)
		Rule_Remove(Rule_SeetheKan)
	end
	
else
	Rule_Remove(Rule_SeetheKan)
end

end

function Rule_KanFights()

g_kandeadearly = 1

Util_Ping_Stop("p_kan")

Cmd_SetStance("sg_strandedkan", STANCE_Attack)
Cmd_MoveToMarker("sg_strandedkan", "mkr_kanmarines")

Cmd_SetMeleeStance("sg_kanmarines", MSTANCE_Assault)
Cmd_SetMeleeStance("sg_kanguard", MSTANCE_Assault)
Cmd_SetStance("sg_kanmarines", STANCE_Hold)
Cmd_SetStance("sg_kanguard", STANCE_Hold)
SGroup_SetHealthInvulnerable("sg_kanmarines", false)
SGroup_SetHealthInvulnerable("sg_kanguard", false)

Rule_AddOneShot(KanKills, 8)
Rule_AddInterval(Rule_KanDead, 1)

Rule_AddInterval(Rule_Autosave_214920, 1)

end

function Rule_Autosave_214920() if not Event_IsAnyRunning() then Rule_Remove(Rule_Autosave_214920) Util_Autosave("$214920") end end

function KanKills() FOW_RevealMarker("mkr_revealkankilling", 30) end

function Rule_KanDead() if g_kanmoving == 10 then Cmd_AttackMoveMarker("sg_strandedkan", "mkr_kanmarines") SGroup_SetPlayerOwner("sg_kanmarines", g_Player3) SGroup_SetPlayerOwner("sg_kanguard", g_Player4) end if SGroup_IsEmpty("sg_strandedkan") then if SGroup_IsEmpty("sg_kanmarines") == false then SGroup_SetPlayerOwner("sg_kanmarines", g_Player1) end if SGroup_IsEmpty("sg_kanguard") == false then SGroup_SetPlayerOwner("sg_kanguard", g_Player1) end Rule_Remove(Rule_KanDead) end

g_kanmoving = g_kanmoving+1

end

function Rule_KanDead_backup()

if g_kandeadearly == nil and SGroup_IsEmpty("sg_strandedkan") then
	if Rule_Exists(Rule_SeetheKan) then
		Rule_Remove(Rule_SeetheKan)
	end
	if Rule_Exists(Rule_KanFights) then
		Rule_Remove(Rule_KanFights)
	end
	
	if SGroup_IsEmpty("sg_kanmarines") == false then
		SGroup_SetPlayerOwner("sg_kanmarines", g_Player1)
		Cmd_SetMeleeStance("sg_kanmarines", MSTANCE_Assault)
		Cmd_SetStance("sg_kanmarines", STANCE_Hold)
		SGroup_SetHealthInvulnerable("sg_kanmarines", false)
	end
	if SGroup_IsEmpty("sg_kanguard") == false then
		SGroup_SetPlayerOwner("sg_kanguard", g_Player1)
		Cmd_SetMeleeStance("sg_kanguard", MSTANCE_Assault)
		Cmd_SetStance("sg_kanguard", STANCE_Hold)
		SGroup_SetHealthInvulnerable("sg_kanguard", false)
	end
	Rule_Remove(Rule_KanDead_backup)
elseif g_kandeadearly == 1 then
	Rule_Remove(Rule_KanDead_backup)
end

end

--[[THE STAMPEDE ]]------------------------------------------------------------------------------------------------------------------------------- function Rule_MakeStampede()

Util_CreateSquadsAtMarkerEx(g_Player2, "sg_stampede1", "ork_squad_slugga", "mkr_stampederally", 2, 3)
SGroup_AddLeaders("sg_stampede1")

SGroup_CreateIfNotFound("sg_stampede3")
SGroup_CreateIfNotFound("sg_stampede2")

if difficultyLevel == DIFFICULTY_NORMAL or difficultyLevel == DIFFICULTY_HARD then

Util_CreateSquadsAtMarker(g_Player2, "sg_stampede1", "ork_squad_killa_kan", "mkr_stampederally", t_difficulty.stampkan)
Cmd_SetStance("sg_stampede1", STANCE_Hold)
	
	Util_CreateSquadsAtMarkerEx(g_Player2, "sg_stampede3", "ork_squad_shoota_boy", "mkr_stampederally", 1, 3)
	SGroup_AddLeaders("sg_stampede3")
	Cmd_SetStance("sg_stampede3", STANCE_Hold)
	
	if difficultyLevel == DIFFICULTY_HARD then
		Util_CreateSquadsAtMarkerEx(g_Player2, "sg_stampede2", "ork_squad_tankbusta", "mkr_stampederally", 1, 3)
		SGroup_AddLeaders("sg_stampede2")
		Cmd_SetStance("sg_stampede2", STANCE_Hold)
	end
end

Rule_AddInterval(Rule_ManageStampede, 5)

end

function Rule_ManageStampede()

SGroup_CreateIfNotFound("sg_InStampede")
if SGroup_IsEmpty("sg_stampede1") == false
	or SGroup_IsEmpty("sg_stampede2") == false
	or SGroup_IsEmpty("sg_stampede3") == false then
		SGroup_Clear(SGroup_FromName("sg_InStampede"))
		local sgroupID = Player_GetAllSquadsNearMarker(g_Player1, "sg_InStampede", "mkr_stampedetarget")
		if SGroup_IsEmpty("sg_InStampede") == false then
			for i = 1, 3 do 
				if SGroup_IsEmpty("sg_stampede"..i) == false then
					Cmd_AttackMoveMarker("sg_stampede"..i, "mkr_stampedetarget")
					Cmd_SetStance("sg_stampede"..i, STANCE_Attack)
				end
			end
		else
			for i = 1, 3 do 
				if SGroup_IsEmpty("sg_stampede"..i) == false then
					Cmd_MoveToMarker("sg_stampede"..i, "mkr_stampederally")
					Cmd_ReinforceTrooper("sg_stampede"..i, 2)
					Cmd_SetStance("sg_stampede"..i, STANCE_Hold)
				end
			end
		end
else
	Rule_Remove(Rule_SeetheKan)
end

end


--[[ Start Base ]]---------------------------------------------------------------------------------------------------------------------------------------

function Rule_Objective_BuildBase()

--[[intel event]]

-- Rule_AddOneShot(Rule_IE_BaseBuild, 0)

--[[create Objective]]
obj_table_base = { title_id = 208005, short_desc_id = 208006, help_tip_id = 208007 }
Util_ObjectiveCreate(obj_table_base, true)
g_makebase = 1
--[[ Unrestrict Things]]

-- Unrestrict_BuildingWithAlerts( g_Player1, "space_marine_barracks", "$42946", "none"--[[408042]] )

--[[Add next rule]]
Rule_AddInterval(Rule_Objective_BaseCheck, 2)

end

--[[ See if the player has all the things they need for their base]] function Rule_Objective_BaseCheck()

if Player_HasBuildingType(g_Player1, "space_marine_hq") 
	and Player_HasBuildingType(g_Player1, "space_marine_generator") 
	and Player_HasBuildingType(g_Player1, "space_marine_barracks") 
	and Player_HasBuildingType(g_Player1, "space_marine_armoury")  then
		Util_ObjectiveComplete(obj_table_base.title_id)
		
		--[[ Patch 1.1 - Fix for the Cleanse the Valley issue ]]
		if Objective_Exists(obj_table_P2.title_id) == false then
			--[[add next objective]]
			Util_ObjectiveCreate(obj_table_P2, true)
			
			g_cleansegiven = 1
			
			Rule_AddInterval(Rule_Base1Checker, 5)
			Rule_AddInterval(Rule_Base2Checker, 5)
			
			t_nobmarker2 = {"mkr_nobhouse1", "mkr_nobhouse2", "mkr_nobhouse3"}
		
			for i = 1, 3 do
				if SGroup_Exists("sg_nobhouse"..i) and SGroup_IsEmpty("sg_nobhouse"..i) == false then
					Util_Ping_LoopingMkr("pg_nobhouse"..i, t_nobmarker2[i])
					g_cleansegiven = 1
				end
			end
			
			--[[add next rule]]
			Rule_AddOneShot(Rule_Objective_Addon, 60)
			
			Rule_Remove(Rule_Objective_BaseCheck)
			
			Rule_AddInterval(Rule_Autosave_214914, 1)
		end
end

end

function Rule_Autosave_214914() if not Event_IsAnyRunning() then Rule_Remove(Rule_Autosave_214914) Util_Autosave("$214914") end end

--[[ The Addon for the Stronghold ]]----------------------------------------------------------------------- function Rule_Objective_Addon()

obj_table_addon = { title_id = 208040, short_desc_id = 208041, help_tip_id = 208042 }
Util_ObjectiveCreate(obj_table_addon, false)

Util_StartIntel(EVENTS.IE_Obj_Addon_Create)

Unrestrict_AddOnWithAlerts( g_Player1, "space_marine_hq_addon_1", "$42942", "none" )

Rule_AddInterval(Rule_Objective_AddonCheck, 2)

end

--[[ Obj is complete when a Generator is constructed ]] function Rule_Objective_AddonCheck() EGroup_AddGroup(EGroup_CreateIfNotFound("eg_Player1All"), Player_GetEntities(g_Player1)) if not EGroup_IsEmpty("eg_Player1All") then if EGroup_ContainsAddOn("eg_Player1All", "space_marine_hq_addon_1", false) == true then Util_ObjectiveComplete(obj_table_addon.title_id)

		Util_StartIntel(EVENTS.IE_Obj_Addon_Complete)
		
		--[[next rule]]
		Rule_AddOneShot(Rule_Objective_PostAddon_Trigger, 60)
		
		Rule_Remove(Rule_Objective_AddonCheck)
		
		Unrestrict_SquadWithAlerts( g_Player1, "space_marine_squad_skull_probe", "$42914", 408012 )
	end
end

end

--[[ Listening Post Objective ]]------------------------------------------------------------------------ function Rule_Objective_PostAddon_Trigger() Rule_AddInterval(Rule_Objective_PostAddon, 1) end

function Rule_Objective_PostAddon()

if Player_HasBuildingType( g_Player1, "space_marine_listening_post" ) then
	
	--[[add objective ]]
	obj_table_post = { title_id = 214070, short_desc_id = 214072, help_tip_id = 214074 }
	Util_ObjectiveCreate(obj_table_post , false)
	
	Util_StartIntel(EVENTS.IE_Objective_PostAddon)
	
	Unrestrict_AddOnWithAlerts( g_Player1, "space_marine_list_post_addon_1", "none", "none" )
	
	Rule_AddInterval(Rule_Objective_PostAddonCheck, 2)
	
	Rule_Remove(Rule_Objective_PostAddon)
end

end

--[[ Obj is complete when a Listening Post is constructed ]] function Rule_Objective_PostAddonCheck()

EGroup_AddGroup(EGroup_CreateIfNotFound("eg_allP1"), Player_GetEntities(g_Player1))
if EGroup_ContainsAddOn( "eg_allP1", "space_marine_list_post_addon_1", false ) then
	
	Util_ObjectiveComplete(obj_table_post.title_id)
	
	Util_StartIntel(EVENTS.IE_Objective_PostAddonComplete)
	
	--[[Next rule]]
	
	Rule_Remove(Rule_Objective_PostAddonCheck)
end

end

--[[Base Killed Checker]] function Rule_Base1Checker()

Player_GetAllEntitiesNearMarker(g_Player2, "eg_base1check", "mkr_orkhut3")
if EGroup_Count(EGroup_FromName("eg_base1check")) == 0 then
	
	Rule_Remove(Rule_Base1Checker)
	
	Rule_AddInterval(Rule_Autosave_214916, 1)
end

end

function Rule_Autosave_214916() if not Event_IsAnyRunning() then Rule_Remove(Rule_Autosave_214916) Util_Autosave("$214916") end end

function Rule_Base2Checker()

Player_GetAllEntitiesNearMarker(g_Player2, "eg_base2check", "mkr_orkhut4")
if EGroup_Count(EGroup_FromName("eg_base2check")) == 0 then
	
	Rule_Remove(Rule_Base2Checker)
	
	Rule_AddInterval(Rule_Autosave_214918, 1)
end

end

function Rule_Autosave_214918() if not Event_IsAnyRunning() then Rule_Remove(Rule_Autosave_214918) Util_Autosave("$214918") end end


--END GAMES

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

-- this function detects if the player has lost their base and has no servitors left function Rule_PlayerLoses()

g_building_exceptions = 
{
	"space_marine_mine_field",
	"space_marine_listening_post",
	"space_marine_turret_bolter"
}

g_unit_exceptions = 
{
	"space_marine_squad_librarian",
	"space_marine_squad_force_commander"
}

if( Player_HasBuildingsExcept(g_Player1, g_building_exceptions) == false ) then
	if( Player_HasSquadsExcept(g_Player1, g_unit_exceptions ) == false ) then
		Rule_RemoveAll()
		World_SetTeamWin( g_Player2, "" )
		Rule_AddIntervalEx( Rule_GameOver,5,1 )
		Rule_Remove( Rule_PlayerLoses )
	end
end

end

--INTEL EVENTS

function Rule_IE_Encouter1stScouts()

Util_StartIntel(EVENTS.IE_Encouter1stScouts)

end

function Rule_IE_1stStealthAttackonOrks()

Util_StartIntel(EVENTS.IE_1stStealthAttackonOrks)

end

function Rule_IE_1stSquadofOrksRun()

Util_StartIntel(EVENTS.IE_1stSquadofOrksRun)

end

function Rule_IE_Encouter2ndScouts()

Util_StartIntel(EVENTS.IE_Encouter2ndScouts)

end

function Rule_IE_ScoutsDyingEarly()

Util_StartIntel(EVENTS.IE_ScoutsDyingEarly)

end


--UTILITIES

function Deg_FindClosestMarker( sgroupName, markerNameTable ) local sgroupId = SGroup_FromName(sgroupName)

if( SGroup_CountSpawned( sgroupId ) == 0 ) then
	error( "Cannot issue order on empty group" )
end
t_destinationPoint = {}
local range = table.getn(markerNameTable)
local distance = {}
local closest = 9999
local closestPoint = 0
local startPoint = 0
for r = 1, range do
	table.insert( 
		distance,	r,
		World_DistanceSGroupToPoint( sgroupId, Marker_GetPosition( Marker_FromName(markerNameTable[r], "basic_marker") ), 1)
	)
end

-- table.foreachi(distance,print) for r = 1, range do if distance[r] < closest then closest = distance[r] closestPoint = r startPoint = markerNameTable[closestPoint] table.insert(t_destinationPoint, 1, closestPoint) -- print("the closest point currently is "..tableName[closestPoint]) end end -- print("the starting marker is "..startPoint) if startPoint == markerNameTable[closestPoint] then table.insert(t_destinationPoint, 2, startPoint) return t_destinationPoint end end

--[[ Scar_DoString( "Rule_AddOneShot(Rule_FlyThru, 0.0)") ]] function Rule_FlyThru() CPath_Start("canim_flythru", "start", "end") end

function CheatClosing()

Cpu_Enable(g_Player1, false)
Cpu_Enable(g_Player2, false)
Cpu_Enable(g_Player3, false)
Cpu_Enable(g_Player4, false)
Cpu_Enable(g_Player5, false)

Rule_RemoveAll()
Util_StartNIS(EVENTS.NIS_Closing)

end

Spelstatistik
Följare
27
Körningar
99
Spelare
12
Senaste omgångarna
Senaste trådarna
Postad 5 years ago
3 svar
Postad 5 years ago
0 svar
Postad 7 years ago
0 svar