Mission event file for Chaos Stronghold mission
Guides
/
Mission event file for Chaos Stronghold mission
Mis à jour 4 years ago par Merric

--[[ IMPORTS ]]

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


--[[ GAME SETUP ]]

-- Blood Pulse Scar -- Blood pulse nis [[this is only for the intro nis and is seperate from the regular pulse that happens during the game]] -- Raids -- Gate of Chaos [[reinforcements that come through the chaos gate]] -- Spawning the prisoners and the jailer -- Proximity check for relic chatter -- Chatty AI -- relic discovered taunt --Bastion breach taunt -- AI Definition [[sets up the ai and what it can and can't dp]] -- Spawning and Upgrading Things on the map -- Player buildings and builder units -- Spawning Armies [[most of the AI units will be under this heading]] -- Patrols -- Initial Attack --Primary Objective - Destroy the Chaos Gate --Secondary Objective - stop Blood Pulse -- Secondary Objective - Rescue prisoners

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

--[[defining the name of the player's faction]]
if MetaMap_GetPlayerRaceName() == "chaos_marine_race" then
	
	factionname = "$690014"
	colorscheme = "default_1"
	t_Prisoners = {--[[1]]"chaos_squad_khorne_berserker_advance_sp", --[[2]]"chaos_squad_khorne_berserker_advance_sp", --[[3]]"chaos_squad_khorne_berserker_advance_sp", --[[4]]"chaos_squad_khorne_berserker_advance_sp"}
	
	g_Player1 = Setup_Player(0, factionname, MetaMap_GetPlayerRaceName(), 1)
	Misc_PlayerTeamColor(g_Player1, colorscheme)
	
	
elseif MetaMap_GetPlayerRaceName() == "eldar_race" then

	factionname = "$690012"
	colorscheme = "default_5"
	t_Prisoners = {--[[1]]"eldar_squad_dark_reaper_exarch_council", --[[2]]"eldar_squad_warp_spider_exarch_council", --[[3]]"eldar_squad_warp_spider_exarch_council", --[[4]]"eldar_squad_dark_reaper_exarch_council"}
	
	g_Player1 = Setup_Player(0, factionname, MetaMap_GetPlayerRaceName(), 1)
	Misc_PlayerTeamColor(g_Player1, colorscheme)
	
elseif MetaMap_GetPlayerRaceName() == "guard_race" then

	factionname = "$690011"
	colorscheme = "default_8"
	t_Prisoners = {--[[1]]"guard_squad_assassin_advance_sp", --[[2]]"guard_squad_kasrkin_advance_sp", --[[3]]"guard_squad_ogryns_advance_sp", --[[4]]"guard_squad_psyker_advance_sp"}

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


elseif MetaMap_GetPlayerRaceName() == "ork_race" then

	factionname = "$690013"
	colorscheme = "default_4"
	t_Prisoners = {--[[1]]"ork_squad_nob_advance_sp", --[[2]]"ork_squad_shoota_boy_advance_sp", --[[3]]"ork_squad_tankbusta_advance_sp", --[[4]]"ork_squad_shoota_boy_advance_sp"}
	
	g_Player1 = Setup_Player(0, factionname, MetaMap_GetPlayerRaceName(), 1)
	Misc_PlayerTeamColor(g_Player1, colorscheme)
	
elseif MetaMap_GetPlayerRaceName() == "space_marine_race" then

	factionname = "$690010"
	colorscheme = "default_0"
	t_Prisoners = {--[[1]]"space_marine_squad_terminator_assault_veteran_sp", --[[2]]"space_marine_squad_terminator_veteran_sp",--[[3]]"space_marine_squad_veteran_sp", 
	--[[4]]"space_marine_squad_terminator_assault_veteran_sp"}
	
	g_Player1 = Setup_Player(0, factionname, MetaMap_GetPlayerRaceName(), 1)
	
elseif MetaMap_GetPlayerRaceName() == "tau_race" then
	
	factionname = "$690015"
	colorscheme = "default_0"
	t_Prisoners = {--[[1]]"tau_honor_guard_fire_warrior_squad_advance_sp", --[[2]]"tau_kroot_alpha_squad_advance_sp", --[[3]]"tau_honor_guard_stealth_suit_squad_advance_sp", 
	--[[4]]"tau_honor_guard_stealth_suit_squad_advance_sp"}
	
	g_Player1 = Setup_Player(0, factionname, MetaMap_GetPlayerRaceName(), 1)
	
elseif MetaMap_GetPlayerRaceName() == "necron_race" then

	factionname = "$690016"
	colorscheme = "default_0"
	t_Prisoners = {--[[1]]"necron_basic_warrior_squad_advance_sp", --[[2]]"necron_pariah_squad_advance_sp", --[[3]]"necron_flayed_one_squad_advance_sp", --[[4]]"necron_flayed_one_squad_advance_sp"}

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

end





g_Player2 = Setup_Player(1, "$690014", "chaos_marine_race", 2)
Misc_PlayerTeamColor(g_Player2,"default_1")

g_Player3 = Setup_Player(2, "$690014", "chaos_marine_race", 2)
Misc_PlayerTeamColor(g_Player3,"default_1")

g_Player4 = Setup_Player(3, factionname,  MetaMap_GetPlayerRaceName(), 1)

g_Player5 = Setup_Player(4, factionname,  MetaMap_GetPlayerRaceName(), TEAM_NEUTRAL)

--[[ DEFINE VARIABLES AND TABLES - define any preset values here for later use]]

g_firstrun = true
g_Counter = 40
g_Increment = 1
g_Reinforcements = 1
g_PulseStop = false
g_Timer = 0
g_reverse_obliterator = false

--difficulty variable
g_Difficulty = 0
g_Strength = 0

--army iterations
g_Bastion_Army_iter = 1
g_FWL_Army_iter = 1
g_FWR_Army_iter = 1
g_LB_Army_iter = 1
g_Right_Barrack_Army_iter = 1
g_Plains_Khorne_Army_iter = 1
g_Reinforce_Army_iter = 1
g_Relic_Army_iter = 1
g_RR_Army_iter = 1
g_Player_Army_iter = 1
g_Opening_Raid_Army_iter = 1

--building iterations
g_FB_Base_iter = 1
g_FB2_Base_iter = 1
g_RB_Base_iter = 1
g_RB2_Base_iter = 1
g_RB3_Base_iter = 1

--Army size variables
g_Bastion = 0

--Raid variables
g_FB1_Increment = 0
g_FB1_Size = 1
g_FB2_Increment = 0
g_FB2_Size = 1
g_RB_Marine_Increment = 0
g_RB_Marine_Size = 1
g_RB_Defiler_Increment = 0
g_RB_Defiler_Size = 1
g_RB2_Obliterator1_Increment = 0
g_RB2_Obliterator1_Size = 1
g_RB2_Obliterator2_Increment = 0
g_RB2_Obliterator2_Size = 1
g_RB2_Beserker1_Increment = 0
g_RB2_Beserker1_Size = 1
g_RB2_Raptor1_Increment = 0
g_RB2_Raptor1_Size = 1
g_RB2_Marine1_Increment = 0
g_RB2_Marine1_Size = 1
g_RB2_Cultist_Increment= 0
g_RB2_Cultist_Size = 1
g_Bastion_Cultist_Increment = 0
g_Bastion_Cultist_Size = 1
g_Bastion_Marine1_Increment = 0
g_Bastion_Marine1_Size = 1
g_Bastion_Predator1_Size = 1

g_RB2_Marine_AI = false
g_BT_First = true


--max squad caps
g_RaptorMaxCap = 18
g_ObliteratorMaxCap = 17
g_KhorneMaxCap = 16
g_MarineMaxCap = 18
g_DefilerMaxCap = 17

-- generator markers start at 0
g_bonus_gen_counter = 0

-- turrer markers start at 6
g_bonus_turret_counter = 6

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

--[[Win condition Objective]]

end

--

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

function OnGameRestore()

end


--[[ ON INITIALIZATION ]]

function OnInit()

--[[ RESEARCH LEVEL - sets the research level of the mission, locks researches, squads, and buildings for the appropriate mission number DOW specific!
 sets the research level of the mission, locks researches, squads, and buildings]]
Rule_SetResearchLevel( 4 )

--[[ NIS PRESETS - turn off event cues, set the viewable space to black (faded out) and preset letterboxing 
turn off event cues, set the viewable space to black (faded out) and preset letterboxing ]]
WXP_OpeningNISPreset()	

--[[ START THE MUSIC ]]
-- call the function to load the jukebox with tunes]]
Rule_SetupMusicPlaylist()	

--[[ SET AI - call the function to set the pregame state of the AI 
call the function to set the pregame state of the AI ]]
Rule_PresetAI()		
	
--[[Upgrade towers and points]]
Rule_AddOneShot(Rule_Upgrade_CM_Points, 0)
Rule_AddOneShot(Rule_Create_Chaos_Buildings, 0)	
	
	
Rule_Despawn()
		
--[[ START NIS - calls the NIS function located in the MissionName.nis file 
calls the NIS function located in the MissionName.nis file ]]	
Util_StartNIS( EVENTS.NIS_Opening )


W40k_Letterbox( true, 0 )
Fade_Start( 2.0, true )

end

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


--[[ GAME RESTRICTIONS ]]

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

function Rule_SetResearchLevel( resLevel )

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

end

function Rule_Despawn()

EGroup_DeSpawn("eg_Demon")
EGroup_DeSpawn("eg_End_Demon")
EGroup_DeSpawn("eg_Closing_Effects")
Rule_Remove(Rule_Despawn)

end

--[[ MUSIC ]]

function Rule_SetupMusicPlaylist() --music t_music = {"MU_IG_STR_Chaos", "MU_IG_STR_Chaos_perc", "MU_IG_STR_Chaos_perc_brass", "MU_IG_STR_Chaos_perc_str", "MU_IG_STR_Chaos_perc_voice"}

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


--ambient sound
t_ambient_sound = {"ambient_desert"}

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

end


--[[ PRESET AI ]]

function Rule_PresetAI()

--Cpu_EnableAll(false)
Cpu_Enable(g_Player3, false)
Cpu_Enable(g_Player2, false)	
Cpu_Enable(g_Player4, false)	
Cpu_Enable(g_Player5, false)	

end


--[[ START PLAY ]]

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

function Rule_GameStart()

if g_firstrun then
	
	g_Strength = MetaMap_GetTerritoryMilitaryStrength(MetaMap_GetDefendingTerritoryIndex())
	
	--[[ PREACTION ]]
	
	--[[ DIFFICULTY LEVEL - gets the difficulty level from the UI and passes it into the function]]
	Rule_SetDifficultyLevel( Difficulty_Get() )
	
	--[[ Get the AI doing whatever after the NIS is over ]]
	Rule_StartAI()
					 
	Rule_AddOneShot(Rule_Set_Research, 1)
	
	
	--[[create enemy buildings]]
	Rule_Add(Rule_ChaosBase_Forward_Creation)
	Rule_Add(Rule_ChaosBase_Forward2_Creation)
	Rule_Add(Rule_ChaosBase_Rear_Creation)
	Rule_Add(Rule_ChaosBase_Rear2_Creation)
	Rule_Add(Rule_ChaosBase_Rear3_Creation)
					 
	--[[create the player's buildings]]
	Rule_Add(Rule_Create_Player_Buildings)
	
	--[[Upgrade towers and points]]

-- Rule_AddOneShot(Rule_Upgrade_CM_Points, 1) -- Rule_AddOneShot(Rule_Create_Chaos_Buildings, 1) Rule_AddOneShot(Rule_Create_CM_Turrets, 1)

	--[[create armies]]
	Rule_Add(Rule_CM_Bastion_Creation)
	Rule_Add(Rule_CM_FWL_Creation)
	Rule_Add(Rule_CM_FWR_Creation)
	Rule_Add(Rule_CM_LB_Creation)
	Rule_Add(Rule_CM_Right_Barrack_Creation)
	Rule_Add(Rule_CM_Plains_Khorne_Creation)
	Rule_Add(Rule_CM_Relic_Creation)
	Rule_Add(Rule_CM_RR_Creation)
			
	--this is the opening raid on the player base, there's a slight delay so the player can get his bearings.
	Rule_AddDelay(Rule_Opening_Raid_Creation, 5)
	
	--[[sharing FOW]]
	--player 1 and four can see each other to let the player see his units being sacrificed
	World_EnablePlayerToPlayerFOW(g_Player1, g_Player4, false)
	
	--[[Chaos Gate summoning]]
	Rule_AddInterval(Rule_Reinforcement_Level, 500)
	Rule_AddInterval(Rule_Summon_Chaos_Reinforcements,400)

	--[[ Set up a Win Check ]]
	Rule_AddInterval(Rule_EndGame_Win, 10)
	
	--[[ Set up a Lose Check ]]
	Rule_AddInterval(Rule_EndGameLose, 10)		

	--[[ set up timer]]
	Rule_AddOneShot(Rule_Add_Timer, 1)
	
	--[[main objective]]
	Rule_AddIntervalDelay(Rule_Objective_Kill_Sorcerer, 1, 20)
	
	--[[Set up the opening taunting]]
	Rule_AddOneShot(Rule_Opening_Discussion, 10)
	
	--[[get the AI talking]]
	Rule_AddInterval(Rule_Trash_Talk, 420)
	
	--[[secondary objective]]
	Rule_AddIntervalDelay(Rule_Objective_Stop_Pulse, 1, 60)
	
	--[[secondary objective]]
	Rule_AddIntervalDelay(Rule_Objective_Rescue_Prisoners, 1, 120)
	

	
	--[[Creating the prisoners and jailer for the secondary objective]]
	Rule_AddOneShot(Rule_Spawn_Prisoners, 1)
	
	
	--[[ Clean up ]]
	Rule_Remove(Rule_GameStart)
	
	
	
	
	W40k_Letterbox( false , 2 )
	
end

end


--[[ DIFFICULTY ]]

function Rule_SetDifficultyLevel( difficultyLevel )

-- easy
if difficultyLevel == DIFFICULTY_EASY then

	g_Difficulty = 1
		-- medium
elseif difficultyLevel == DIFFICULTY_NORMAL then

	g_Difficulty = 2
	
	
-- hard
elseif difficultyLevel == DIFFICULTY_HARD then
	
	g_Difficulty = 3
	
end

end


--[[ AI Definition]]

function Rule_StartAI()

Cpu_Enable(g_Player3, true)	
Cpu_Enable(g_Player2, false)	

Cpu_EnableComponent(g_Player3, true, CT_Resourcing)
Cpu_EnableComponent(g_Player3, true, CT_BuildBuildings)
Cpu_EnableComponent(g_Player3, true, CT_BuildUnits)
Cpu_EnableComponent(g_Player3, false, CT_BuildResearch)
Cpu_EnableComponent(g_Player3, false, CT_BuildAddOns)
Cpu_EnableComponent(g_Player3, true, CT_Tactics)

Cpu_SetDifficulty(g_Player3, AD_Insane)

--set the squad and vehicle cap for the active AI player
Player_SetSquadCap(g_Player3, 20)
Player_SetSupportCap(g_Player3, 20)

Player_RestrictSquad(g_Player3, "chaos_marine_squad")
Player_RestrictSquad(g_Player3, "chaos_squad_bloodthirster")
Player_RestrictSquad(g_Player3, "chaos_squad_defiler")
Player_RestrictSquad(g_Player3, "chaos_squad_horror")
Player_RestrictSquad(g_Player3, "chaos_squad_khorne_berserker")
Player_RestrictSquad(g_Player3, "chaos_squad_lord")
Player_RestrictSquad(g_Player3, "chaos_squad_obliterator")
Player_RestrictSquad(g_Player3, "chaos_squad_possessed_marine")
Player_RestrictSquad(g_Player3, "chaos_squad_predator")
Player_RestrictSquad(g_Player3, "chaos_squad_raptor")
Player_RestrictSquad(g_Player3, "chaos_squad_rhino")
Player_RestrictSquad(g_Player3, "chaos_squad_sorcerer")

t_Player3_Building_Restrict = {"chaos_greater_sacrificial_circle", "chaos_hq", "chaos_machine_pit", "chaos_sacrificial_circle", 
"chaos_temple", }

Player_RestrictBuildingList(g_Player3, t_Player3_Building_Restrict)

end

function Rule_Set_Research()

Player_GrantResearch(g_Player2, "chaos_projectiles")

Player_GrantResearch(g_Player2, "chaos_cultist_sight_research")
Player_GrantResearch(g_Player3, "chaos_cultist_sight_research")

Player_GrantResearch(g_Player2, "chaos_champion_melee_research_2")
Player_GrantResearch(g_Player3, "chaos_champion_melee_research_2")

Player_GrantResearch(g_Player2, "chaos_frag_grenade_research")
Player_GrantResearch(g_Player3, "chaos_frag_grenade_research")

Player_GrantResearch(g_Player2, "chaos_furious_charge_research")
Player_GrantResearch(g_Player3, "chaos_furious_charge_research")

Player_GrantResearch(g_Player2, "chaos_health_upgrade_research_2")
Player_GrantResearch(g_Player3, "chaos_health_upgrade_research_2")

Player_GrantResearch(g_Player2, "chaos_plasma_pistol_research")
Player_GrantResearch(g_Player3, "chaos_plasma_pistol_research")


end



--[[ CORE GAME ]]



--[[Spawning and Upgrading Things on the map]]

--[[chaos buildings]] function Rule_Create_Chaos_Buildings()

	Entity_CreateBuildingMarker(g_Player3,"eg_CM_HQ", "chaos_hq","mkr_Chaos_HQ", 1)
	EGroup_AddGroup(EGroup_CreateIfNotFound("eg_Chaos_Buildings"), EGroup_FromName("eg_CM_HQ"))
	
	Entity_CreateBuildingMarker(g_Player3,"eg_CM_Vehicle_Bastion", "chaos_machine_pit","mkr_CM_Vehicle_Bastion", 1)
	EGroup_AddGroup(EGroup_CreateIfNotFound("eg_Chaos_Buildings"), EGroup_FromName("eg_CM_Vehicle_Bastion"))
			
	Entity_CreateBuildingMarker(g_Player3,"eg_CM_Armoury_Bastion", "chaos_armoury","mkr_CM_Armoury", 1)
	EGroup_AddGroup(EGroup_CreateIfNotFound("eg_Chaos_Buildings"), EGroup_FromName("eg_CM_Armoury_Bastion"))
	
	Entity_CreateBuildingMarker(g_Player3,"eg_CM_Circle_Bastion", "chaos_sacrificial_circle","mkr_CM_Circle_Bastion", 1)
	EGroup_AddGroup(EGroup_CreateIfNotFound("eg_Chaos_Buildings"), EGroup_FromName("eg_CM_Circle_Bastion"))


	
	for i = 1, 6 do
	
		Entity_CreateBuildingMarker(g_Player3,"eg_SM_Generator"..i, "chaos_plasma_generator","mkr_CM_Power"..i, 1)
		EGroup_AddGroup(EGroup_FromName("eg_Chaos_Buildings"), EGroup_FromName("eg_SM_Generator"..i))
	
	end

	Rule_AddIntervalDelay(Rule_Bastion_Spawning_Prox_Check, 3, 300)
	Rule_AddIntervalDelay(Rule_Bastion_Stealth_Prox_Check, 3, 300)
	

end

--listening posts and relics function Rule_Upgrade_CM_Points()

for i = 1, 7 do

	EGroup_ForceAddOn("eg_CM_List_Post"..i, "chaos_list_post_addon_2" )


end

	EGroup_ForceAddOn("eg_Strat_Blood", "chaos_list_post_addon_2")

end

--turrets

function Rule_Create_CM_Turrets()

for i = 1, 17 do

	Entity_CreateBuildingMarker(g_Player3,"sg_CM_Turret"..i, "chaos_turret_bolter","mkr_CM_Turret"..i, 1)

end

for j = 1, 3 do

	EGroup_ForceAddOn("sg_CM_Turret"..j, "chaos_turret_addon")

end

EGroup_ForceAddOn("sg_CM_Turret8", "chaos_turret_addon")
EGroup_ForceAddOn("sg_CM_Turret10", "chaos_turret_addon")

end


--buildings for the chaos forward base one function Rule_ChaosBase_Forward_Creation()

	t_FB_Base = {
		
		egroup_name = { --[[1]]"eg_FB1", --[[2]]"eg_FB2", --[[3]]"eg_FB3", --[[4]]"eg_FB4", --[[5]]"eg_FB5", --[[6]]"eg_FB6", --[[7]]"eg_FB7", --[[8]]"eg_FB8", --[[9]]"eg_FB9", --[[10]]"eg_FB10", --[[11]]"eg_FB11",
		--[[12]]"eg_FB12", --[[13]]"eg_FB13", --[[14]]"eg_FB14"},  
		
		blueprint = {--[[1]]"chaos_hq", --[[2]]"chaos_plasma_generator", --[[3]]"chaos_turret_bolter", --[[4]]"chaos_turret_bolter", --[[5]]"chaos_turret_bolter", --[[6]]"chaos_turret_bolter", --[[7]]"chaos_turret_bolter",
		--[[8]]"chaos_turret_bolter", --[[9]]"chaos_plasma_generator", --[[10]]"chaos_temple", --[[11]]"chaos_turret_bolter", --[[12]]"chaos_turret_bolter", --[[13]]"chaos_turret_bolter", --[[14]]"chaos_armoury"},
		
		marker_spawn = {--[[1]]"mkr_CM_FB_Building1", --[[2]]"mkr_CM_FB_Building2", --[[3]]"mkr_CM_FB_Building3", --[[4]]"mkr_CM_FB_Building4", --[[5]]"mkr_CM_FB_Building5", --[[6]]"mkr_CM_FB_Building6", 
		--[[7]]"mkr_CM_FB_Building7", --[[8]]"mkr_CM_FB_Building8", --[[9]]"mkr_CM_FB_Building9", --[[10]]"mkr_CM_FB_Building10", --[[11]]"mkr_CM_FB_Building11", --[[12]]"mkr_CM_FB_Building12", 
		--[[13]]"mkr_CM_FB_Building13", --[[14]]"mkr_CM_FB_Building14"}, 
		
		construction_percent = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1, --[[7]] 1, --[[8]] 1, --[[9]] 1, --[[10]] 1, --[[11]] 1, --[[12]] 1, --[[13]] 1, --[[14]] 1}, 
		
	}


local i = g_FB_Base_iter 
if g_FB_Base_iter <= table.getn(t_FB_Base.egroup_name) and (EGroup_Exists(t_FB_Base.egroup_name[i]) == false or EGroup_IsEmpty(t_FB_Base.egroup_name[i])) then
	local egroupID = Entity_CreateBuildingMarker(g_Player3, t_FB_Base.egroup_name[i], t_FB_Base.blueprint[i], t_FB_Base.marker_spawn[i], t_FB_Base.construction_percent[i])
	
	
	--add them all into one meta group
	EGroup_AddGroup(EGroup_CreateIfNotFound("eg_Forward_Base"),  EGroup_FromName(t_FB_Base.egroup_name[i]))
	
elseif g_FB_Base_iter > table.getn(t_FB_Base.egroup_name) then
		g_FB_Base_iter = 0


		Rule_Remove(Rule_ChaosBase_Forward_Creation)
		
		--this rule checks to see if the HQ exists before creating a raid so it's added here.
		Rule_AddIntervalDelay(Rule_FB1_Raid, 30, 5)

	
end
g_FB_Base_iter = g_FB_Base_iter+1

end


--buildings for the chaos forward base two function Rule_ChaosBase_Forward2_Creation()

	t_FB2_Base = {
		
		egroup_name = { --[[1]]"eg_FB2_1", --[[2]]"eg_FB2_2", --[[3]]"eg_FB2_3", --[[4]]"eg_FB2_4", --[[5]]"eg_FB2_5", --[[6]]"eg_FB2_6", --[[7]]"eg_FB2_7", --[[8]]"eg_FB2_8", --[[9]]"eg_FB2_9",
		--[[10]]"eg_FB2_10", --[[11]]"eg_FB2_11"},  
		
		blueprint = {--[[1]]"chaos_hq", --[[2]]"chaos_temple", --[[3]]"chaos_plasma_generator", --[[4]]"chaos_turret_bolter", --[[5]]"chaos_turret_bolter", --[[6]]"chaos_turret_bolter", --[[7]]"chaos_turret_bolter",
		--[[8]]"chaos_turret_bolter", --[[9]]"chaos_turret_bolter", --[[10]]"chaos_turret_bolter", --[[11]]"chaos_turret_bolter"},
		
		marker_spawn = {--[[1]]"mkr_CM_FB2_Building1", --[[2]]"mkr_CM_FB2_Building2", --[[3]]"mkr_CM_FB2_Building3", --[[4]]"mkr_CM_FB2_Building4", --[[5]]"mkr_CM_FB2_Building5", --[[6]]"mkr_CM_FB2_Building6", 
		--[[7]]"mkr_CM_FB2_Building7", --[[8]]"mkr_CM_FB2_Building8", --[[9]]"mkr_CM_FB2_Building9", --[[10]]"mkr_CM_FB2_Building10", --[[11]]"mkr_CM_FB2_Building11"}, 
		
		construction_percent = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1, --[[7]] 1, --[[8]] 1, --[[9]] 1, --[[10]] 1, --[[11]] 1}, 
		
	}


local i = g_FB2_Base_iter 
if g_FB2_Base_iter <= table.getn(t_FB2_Base.egroup_name) and (EGroup_Exists(t_FB2_Base.egroup_name[i]) == false or EGroup_IsEmpty(t_FB2_Base.egroup_name[i])) then
	local egroupID = Entity_CreateBuildingMarker(g_Player3, t_FB2_Base.egroup_name[i], t_FB2_Base.blueprint[i], t_FB2_Base.marker_spawn[i], t_FB2_Base.construction_percent[i])
	
	
	--add them all into one meta group
	EGroup_AddGroup(EGroup_CreateIfNotFound("eg_Forward_Base2"),  EGroup_FromName(t_FB2_Base.egroup_name[i]))
	
elseif g_FB2_Base_iter > table.getn(t_FB2_Base.egroup_name) then
		g_FB2_Base_iter = 0


		Rule_Remove(Rule_ChaosBase_Forward2_Creation)
		
		--this rule checks to see if the HQ exists before creating a raid so it's added here.
		Rule_AddIntervalDelay(Rule_FB2_Raid, 30, 5)

	
end
g_FB2_Base_iter = g_FB2_Base_iter+1

end


--buildings for the chaos rear base one function Rule_ChaosBase_Rear_Creation()

	t_RB_Base = {
		
		egroup_name = { --[[1]]"eg_RB1", --[[2]]"eg_RB2", --[[3]]"eg_RB3", --[[4]]"eg_RB4", --[[5]]"eg_RB5", --[[6]]"eg_RB6", --[[7]]"eg_RB7", --[[8]]"eg_RB8", --[[9]]"eg_RB9", --[[10]]"eg_RB10", --[[11]]"eg_RB11",
		--[[12]]"eg_RB12",},  
		
		blueprint = {--[[1]]"chaos_hq", --[[2]]"chaos_temple", --[[3]]"chaos_turret_bolter", --[[4]]"chaos_turret_bolter", --[[5]]"chaos_turret_bolter", --[[6]]"chaos_turret_bolter", --[[7]]"chaos_turret_bolter",
		--[[8]]"chaos_plasma_generator", --[[9]]"chaos_plasma_generator", --[[10]]"chaos_plasma_generator", --[[11]]"chaos_armoury", --[[12]]"chaos_machine_pit"},
		
		marker_spawn = {--[[1]]"mkr_CM_RB_Building1", --[[2]]"mkr_CM_RB_Building2", --[[3]]"mkr_CM_RB_Building3", --[[4]]"mkr_CM_RB_Building4", --[[5]]"mkr_CM_RB_Building5", --[[6]]"mkr_CM_RB_Building6", 
		--[[7]]"mkr_CM_RB_Building7", --[[8]]"mkr_CM_RB_Building8", --[[9]]"mkr_CM_RB_Building9", --[[10]]"mkr_CM_RB_Building10", --[[11]]"mkr_CM_RB_Building11", --[[12]]"mkr_CM_RB_Building12"}, 
		
		construction_percent = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1, --[[7]] 1, --[[8]] 1, --[[9]] 1, --[[10]] 1, --[[11]] 1, --[[12]] 1}, 
		
	}


local i = g_RB_Base_iter 
if g_RB_Base_iter <= table.getn(t_RB_Base.egroup_name) and (EGroup_Exists(t_RB_Base.egroup_name[i]) == false or EGroup_IsEmpty(t_RB_Base.egroup_name[i])) then
	local egroupID = Entity_CreateBuildingMarker(g_Player3, t_RB_Base.egroup_name[i], t_RB_Base.blueprint[i], t_RB_Base.marker_spawn[i], t_RB_Base.construction_percent[i])
	
	
	--add them all into one meta group
	EGroup_AddGroup(EGroup_CreateIfNotFound("eg_Rear_Base"),  EGroup_FromName(t_RB_Base.egroup_name[i]))
	
elseif g_RB_Base_iter > table.getn(t_RB_Base.egroup_name) then
		g_RB_Base_iter = 0


		Rule_Remove(Rule_ChaosBase_Rear_Creation)

		--this rule checks to see if the HQ exists before creating a raid so it's added here.
		Rule_AddIntervalDelay(Rule_RB_Marines_Raid, 150, 240)
		Rule_AddIntervalDelay(Rule_RB_Defiler_Raid, 300, 600)
end
g_RB_Base_iter = g_RB_Base_iter+1

end


--buildings for the chaos rear base two function Rule_ChaosBase_Rear2_Creation()

	t_RB2_Base = {
		
		egroup_name = { --[[1]]"eg_RB2_1", --[[2]]"eg_RB2_2", --[[3]]"eg_RB2_3", --[[4]]"eg_RB2_4", --[[5]]"eg_RB2_5", --[[6]]"eg_RB2_6", --[[7]]"eg_RB2_7", --[[8]]"eg_RB2_8", --[[9]]"eg_RB2_9", --[[10]]"eg_RB2_10"},  
		
		blueprint = {--[[1]]"chaos_temple", --[[2]]"chaos_temple", --[[3]]"chaos_greater_sacrificial_circle", --[[4]]"chaos_turret_bolter", --[[5]]"chaos_turret_bolter", --[[6]]"chaos_turret_bolter", --[[7]]"chaos_turret_bolter",
		--[[8]]"chaos_greater_sacrificial_circle", --[[9]]"chaos_turret_bolter", --[[10]]"chaos_hq"},
		
		marker_spawn = {--[[1]]"mkr_CM_RB2_Building1", --[[2]]"mkr_CM_RB2_Building2", --[[3]]"mkr_CM_RB2_Building3", --[[4]]"mkr_CM_RB2_Building4", --[[5]]"mkr_CM_RB2_Building5", --[[6]]"mkr_CM_RB2_Building6", 
		--[[7]]"mkr_CM_RB2_Building7", --[[8]]"mkr_CM_RB2_Building8", --[[9]]"mkr_CM_RB2_Building9", --[[10]]"mkr_CM_RB2_Building10"}, 
		
		construction_percent = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1, --[[7]] 1, --[[8]] 1, --[[9]] 1, --[[10]] 1}, 
		
	}


local i = g_RB2_Base_iter 
if g_RB2_Base_iter <= table.getn(t_RB2_Base.egroup_name) and (EGroup_Exists(t_RB2_Base.egroup_name[i]) == false or EGroup_IsEmpty(t_RB2_Base.egroup_name[i])) then
	local egroupID = Entity_CreateBuildingMarker(g_Player3, t_RB2_Base.egroup_name[i], t_RB2_Base.blueprint[i], t_RB2_Base.marker_spawn[i], t_RB2_Base.construction_percent[i])
	
	
	--add them all into one meta group
	EGroup_AddGroup(EGroup_CreateIfNotFound("eg_Rear_Base"),  EGroup_FromName(t_RB2_Base.egroup_name[i]))
	
elseif g_RB2_Base_iter > table.getn(t_RB2_Base.egroup_name) then
		g_RB2_Base_iter = 0


		EGroup_AddGroup(EGroup_CreateIfNotFound("eg_Greater_Sacrifical"), EGroup_FromName("eg_RB2_3"))
		EGroup_AddGroup(EGroup_CreateIfNotFound("eg_Greater_Sacrifical"), EGroup_FromName("eg_RB2_8"))
		
		Rule_Remove(Rule_ChaosBase_Rear2_Creation)
		
		--this rule checks to see if the HQ exists before creating a raid so it's added here.
		Rule_AddIntervalDelay(Rule_RB2_Marine1_Raid, 150, 390)
		Rule_AddIntervalDelay(Rule_Tier3_Raid, 2, 500)
		
		--bloodthirster raid
		--	Rule_AddOneShot(Rule_BloodThirster, 1800)
		
		g_BloodthirsterFactor = (17 - g_Strength)
		
		Rule_AddOneShot(Rule_BloodThirster, (240 * g_BloodthirsterFactor))
		

	
end
g_RB2_Base_iter = g_RB2_Base_iter+1

end


--buildings for the chaos rear base three function Rule_ChaosBase_Rear3_Creation()

	t_RB3_Base = {
		
		egroup_name = { --[[1]]"eg_RB3_1", --[[2]]"eg_RB3_2", --[[3]]"eg_RB3_3", --[[4]]"eg_RB3_4", --[[5]]"eg_RB3_5", --[[6]]"eg_RB3_6", --[[7]]"eg_RB3_7", --[[8]]"eg_RB3_8"},  
		
		blueprint = {--[[1]]"chaos_turret_bolter", --[[2]]"chaos_turret_bolter", --[[3]]"chaos_turret_bolter", --[[4]]"chaos_turret_bolter", --[[5]]"chaos_turret_bolter", --[[6]]"chaos_turret_bolter", --[[7]]"chaos_temple",
		--[[8]]"chaos_turret_bolter"},
		
		marker_spawn = {--[[1]]"mkr_CM_RB3_Building1", --[[2]]"mkr_CM_RB3_Building2", --[[3]]"mkr_CM_RB3_Building3", --[[4]]"mkr_CM_RB3_Building4", --[[5]]"mkr_CM_RB3_Building5", --[[6]]"mkr_CM_RB3_Building6", 
		--[[7]]"mkr_CM_RB3_Building7", --[[8]]"mkr_CM_RB3_Building8"}, 
		
		construction_percent = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1, --[[7]] 1, --[[8]] 1}, 
		
	}


local i = g_RB3_Base_iter 
if g_RB3_Base_iter <= table.getn(t_RB3_Base.egroup_name) and (EGroup_Exists(t_RB3_Base.egroup_name[i]) == false or EGroup_IsEmpty(t_RB3_Base.egroup_name[i])) then
	local egroupID = Entity_CreateBuildingMarker(g_Player3, t_RB3_Base.egroup_name[i], t_RB3_Base.blueprint[i], t_RB3_Base.marker_spawn[i], t_RB3_Base.construction_percent[i])
	
	
	--add them all into one meta group
	EGroup_AddGroup(EGroup_CreateIfNotFound("eg_Rear_Base"),  EGroup_FromName(t_RB3_Base.egroup_name[i]))
	
elseif g_RB3_Base_iter > table.getn(t_RB3_Base.egroup_name) then
		g_RB3_Base_iter = 0

		--upgrade some turrets
		EGroup_ForceAddOn("eg_RB3_2", "chaos_turret_addon")
		EGroup_ForceAddOn("eg_RB3_4", "chaos_turret_addon")
		
		Rule_Remove(Rule_ChaosBase_Rear3_Creation)

	
end
g_RB3_Base_iter = g_RB3_Base_iter+1

end

--[[Player buildings and builder units ]]

function Rule_Create_Player_Buildings()

t_Player_Buildings ={

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

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

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

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

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

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

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

}

t_Player_Builder_Units = {

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

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

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

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

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

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

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


if MetaMap_GetPlayerRaceName() == "chaos_marine_race" then

	for i = 1, table.getn(t_Player_Buildings.chaos_name) do
		
		Entity_CreateBuildingMarker(g_Player1, t_Player_Buildings.chaos_name[i], t_Player_Buildings.chaos_building_blueprint[i], t_Player_Buildings.chaos_marker_spawn[i], 1)
		Util_CreateSquadsAtMarkerEx(g_Player1, t_Player_Builder_Units.chaos_buildername[i], t_Player_Builder_Units.chaos_builder_blueprint[i], t_Player_Builder_Units.chaos_buildermarker_spawn[i], 1, 1)
		
		--i'm saving the hq blueprint in order to use it later
		g_HQ_Type = "chaos_hq"
		g_Leader_Type = "chaos_squad_lord"
		g_BaseDefense_Type = "chaos_squad_cultist"
		
	end

elseif MetaMap_GetPlayerRaceName() == "eldar_race" then

	for i = 1, table.getn(t_Player_Buildings.eldar_name) do
	
		Entity_CreateBuildingMarker(g_Player1, t_Player_Buildings.eldar_name[i], t_Player_Buildings.eldar_building_blueprint[i], t_Player_Buildings.eldar_marker_spawn[i], 1)
		Util_CreateSquadsAtMarkerEx(g_Player1, t_Player_Builder_Units.eldar_buildername[i], t_Player_Builder_Units.eldar_builder_blueprint[i], t_Player_Builder_Units.eldar_buildermarker_spawn[i], 1, 1)
	
		--i'm saving the hq blueprint in order to use it later
		g_HQ_Type = "eldar_hq"
		g_Leader_Type = "eldar_squad_farseer"
		g_BaseDefense_Type = "eldar_guardian_squad"
	
	end

elseif MetaMap_GetPlayerRaceName() == "guard_race" then

	for i = 1, table.getn(t_Player_Buildings.guard_name) do
	
		Entity_CreateBuildingMarker(g_Player1, t_Player_Buildings.guard_name[i], t_Player_Buildings.guard_building_blueprint[i], t_Player_Buildings.guard_marker_spawn[i], 1)
		Util_CreateSquadsAtMarkerEx(g_Player1, t_Player_Builder_Units.guard_buildername[i], t_Player_Builder_Units.guard_builder_blueprint[i], t_Player_Builder_Units.guard_buildermarker_spawn[i], 1, 1)
		
		--i'm saving the hq blueprint in order to use it later
		g_HQ_Type = "guard_hq"
		g_Leader_Type = "guard_squad_command_squad"
		g_BaseDefense_Type = "guard_squad_guardsmen"
	
	end

elseif MetaMap_GetPlayerRaceName() == "ork_race" then

	for i = 1, table.getn(t_Player_Buildings.ork_name) do
		
		Entity_CreateBuildingMarker(g_Player1, t_Player_Buildings.ork_name[i], t_Player_Buildings.ork_building_blueprint[i], t_Player_Buildings.ork_marker_spawn[i], 1)
		Util_CreateSquadsAtMarkerEx(g_Player1, t_Player_Builder_Units.ork_buildername[i], t_Player_Builder_Units.ork_builder_blueprint[i], t_Player_Builder_Units.ork_buildermarker_spawn[i], 1, 1)
		
		--i'm saving the hq blueprint in order to use it later
		g_HQ_Type = "ork_hq"
		g_Leader_Type = "ork_squad_warboss"
		g_BaseDefense_Type = "ork_squad_slugga"
		
	end

elseif MetaMap_GetPlayerRaceName() == "space_marine_race" then

	for i = 1, table.getn(t_Player_Buildings.marines_name) do
		
		Entity_CreateBuildingMarker(g_Player1, t_Player_Buildings.marines_name[i], t_Player_Buildings.marines_building_blueprint[i], t_Player_Buildings.marines_marker_spawn[i], 1)
		Util_CreateSquadsAtMarkerEx(g_Player1, t_Player_Builder_Units.marines_buildername[i], t_Player_Builder_Units.marines_builder_blueprint[i], t_Player_Builder_Units.marines_buildermarker_spawn[i], 1, 1)
		
		--i'm saving the hq blueprint in order to use it later
		g_HQ_Type = "space_marine_hq"
		g_Leader_Type = "space_marine_squad_force_commander"
		g_BaseDefense_Type = "space_marine_squad_tactical"
		
		
	end
	
elseif MetaMap_GetPlayerRaceName() == "tau_race" then
	
	for i = 1, table.getn(t_Player_Buildings.tau_name) do
		
		Entity_CreateBuildingMarker(g_Player1, t_Player_Buildings.tau_name[i], t_Player_Buildings.tau_building_blueprint[i], t_Player_Buildings.tau_marker_spawn[i], 1)
		Util_CreateSquadsAtMarkerEx(g_Player1, t_Player_Builder_Units.tau_buildername[i], t_Player_Builder_Units.tau_builder_blueprint[i], t_Player_Builder_Units.tau_buildermarker_spawn[i], 1, 1)
		
		--i'm saving the hq blueprint in order to use it later
		g_HQ_Type = "tau_hq"
		g_Leader_Type = "tau_commander_squad"
		g_BaseDefense_Type = "tau_fire_warrior_squad"
		
	end
	
elseif MetaMap_GetPlayerRaceName() == "necron_race" then
	
	for i = 1, table.getn(t_Player_Buildings.necron_name) do
		
		Entity_CreateBuildingMarker(g_Player1, t_Player_Buildings.tau_name[i], t_Player_Buildings.necron_building_blueprint[i], t_Player_Buildings.necron_marker_spawn[i], 1)
		Util_CreateSquadsAtMarkerEx(g_Player1, t_Player_Builder_Units.necron_buildername[i], t_Player_Builder_Units.necron_builder_blueprint[i], t_Player_Builder_Units.necron_buildermarker_spawn[i], 1, 1)
		
		--i'm saving the hq blueprint in order to use it later
		g_HQ_Type = "monolith"
		g_Leader_Type = "necron_lord_squad"
		g_BaseDefense_Type = "necron_basic_warrior_squad"
		
	end
	
end

--blueprint table with the relevant hq
t_blueprinthq = Util_MakeBlueprintTable(g_HQ_Type)
t_blueprintleader = Util_MakeBlueprintTable(g_Leader_Type)




--determine race specific blueprints to be looked for when creating forward base
if MetaMap_GetPlayerRaceName() == "chaos_marine_race" then
	
	g_bonus_generator = "chaos_plasma_generator"
	g_bonus_turret = "chaos_turret_bolter"
	g_bonus_barracks = "chaos_temple"
	g_bonus_barracks2 = 0 --value on used for tau kroot nest, dummy value for all other races, like the Tau turret.
	g_bonus_research = "chaos_armoury"
	
elseif MetaMap_GetPlayerRaceName() == "eldar_race" then
	
	g_bonus_generator = "eldar_warp_generator"
	g_bonus_turret = "eldar_support_platform_scatterlaser"
	g_bonus_barracks = "eldar_aspect_portal"
	g_bonus_barracks2 = 0 --value on used for tau kroot nest, dummy value for all other races, like the Tau turret.
	g_bonus_research = "eldar_soul_shrine"
			
elseif MetaMap_GetPlayerRaceName() == "guard_race" then

	g_bonus_generator = "guard_plasma_generator"
	g_bonus_turret = "guard_turret_heavy_bolter"
	g_bonus_barracks = "guard_infantry"
	g_bonus_barracks2 = 0 --value on used for tau kroot nest, dummy value for all other races, like the Tau turret.
	g_bonus_research = "guard_tactica"
	
elseif MetaMap_GetPlayerRaceName() == "ork_race" then

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

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

MetaMap_GetAttackingRaceStartingEntitiesList(t_blueprintEntitybonus)

for j = 1,table.getn(t_blueprintEntitybonus) do

	if t_blueprintEntitybonus[j] == g_bonus_generator then
		
		Entity_CreateBuildingMarker(g_Player1, "eg_Bonus"..j, t_blueprintEntitybonus[j], "MM_Reinforcement"..g_bonus_gen_counter, 1)
		
		--increase by one, the next generator will then spawn at the correct marker after this one
		g_bonus_gen_counter = g_bonus_gen_counter + 1
		
	elseif t_blueprintEntitybonus[j] == g_bonus_turret then

		Entity_CreateBuildingMarker(g_Player1, "eg_Bonus"..j, t_blueprintEntitybonus[j], "MM_Reinforcement"..g_bonus_turret_counter, 1)

		--increase by one, the next turret will then spawn at the correct marker after this one
		g_bonus_turret_counter = g_bonus_turret_counter + 1
	

	elseif t_blueprintEntitybonus[j] == g_bonus_barracks then

		--fixed marker spawn based on Phil's table.  Only one barracks is spawned, always at marker 10

		--Necron intentionally spawn a summoning core in place of a barracks due to the monolith doubling as their barracks.
		Entity_CreateBuildingMarker(g_Player1, "eg_Bonus"..j, t_blueprintEntitybonus[j], "MM_Reinforcement10", 1)

	elseif t_blueprintEntitybonus[j] == g_bonus_research then

		--fixed marker spawn based on Phil's table.  Only one research building is spawned, always at marker 11
		Entity_CreateBuildingMarker(g_Player1, "eg_Bonus"..j, t_blueprintEntitybonus[j], "MM_Reinforcement11", 1)
			

	elseif t_blueprintEntitybonus[j] == g_bonus_barracks2 then

		--This will only be used to spawn the kroot nest when the player is Tau, otherwise it will be passed over due to g_bonus_barracks2 being a dummy value.
		--fixed marker spawn based on Phil's table.  Only one kroot nest is spawned, always at marker 13
		Entity_CreateBuildingMarker(g_Player1, "eg_Bonus"..j, t_blueprintEntitybonus[j], "MM_Reinforcement13", 1)

	end

			

end

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


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

for j = 1,  table.getn(t_blueprintbonus) do

	if j <= 7 then
	
			k = j
	else
			k = j - 7
	
	end
	

	Util_CreateSquadsAtMarker(g_Player1, "sg_Bonus"..j, t_blueprintbonus[j], "mkr_Bonus"..k, 1)
	
	
end


Rule_Remove(Rule_Create_Player_Buildings)

-- FOW_RevealMarker("mkr_Gate", -1) -- Rule_Add(Rule_Player_Defense_Creation)

end

--[[Spawning Armies]]

function Rule_CM_Bastion_Creation()

if g_Strength == 15 then

		t_Bastion_Army = {
			
			sgroup_name = { --[[1]]"sg_CM_Bastion1", --[[2]]"sg_CM_Bastion2", --[[3]]"sg_CM_Bastion3", --[[4]]"sg_CM_Bastion4", --[[5]]"sg_CM_Bastion5", --[[6]]"sg_CM_Bastion6", --[[7]]"sg_CM_Bastion7", --[[8]]"sg_CM_Bastion8",
			--[[9]]"sg_CM_Bastion9", --[[10]]"sg_CM_Bastion10", --[[11]]"sg_CM_Bastion11", --[[12]]"sg_CM_Bastion12", --[[13]]"sg_CM_Bastion13", --[[14]]"sg_CM_Bastion14", --[[15]]"sg_CM_Bastion15", --[[16]]"sg_CM_Bastion16",
			--[[17]]"sg_CM_Bastion17", --[[18]]"sg_Sorcerer1", --[[19]]"sg_Sorcerer2", --[[20]]"sg_KhorneDefiler1", --[[21]]"sg_KhorneDefiler2", --[[22]]"sg_KhorneDefiler3", --[[23]]"sg_KhorneDefiler4", --[[24]]"sg_KhorneDefiler5",
			--[[25]]"sg_KhorneDefiler6", --[[26]]"sg_Chaos_Lord"},  
			
			blueprint = {--[[1]]"chaos_marine_squad_stronghold_sp", --[[2]]"chaos_marine_squad_stronghold_sp", --[[3]]"chaos_marine_squad_stronghold_sp", --[[4]]"chaos_marine_squad_stronghold_sp", --[[5]]"chaos_squad_defiler", 
			--[[6]]"chaos_squad_defiler", --[[7]]"chaos_squad_possessed_marine",	--[[8]]"chaos_squad_possessed_marine", --[[9]]"chaos_squad_possessed_marine", --[[10]]"chaos_squad_defiler", --[[11]]"chaos_squad_defiler", 
			--[[12]]"chaos_squad_defiler", --[[13]]"chaos_squad_defiler", --[[14]]"chaos_squad_predator", --[[15]]"chaos_squad_defiler", --[[16]]"chaos_squad_predator", --[[17]]"chaos_squad_defiler", 
			--[[18]]"chaos_squad_sorcerer_stronghold_sp",--[[19]]"chaos_squad_sorcerer_stronghold_sp", --[[20]]"chaos_squad_defiler", --[[21]]"chaos_squad_defiler", --[[22]]"chaos_squad_defiler", --[[23]]"chaos_squad_defiler", 
			--[[24]]"chaos_squad_defiler", --[[25]]"chaos_squad_defiler", --[[26]]"chaos_squad_lord_advance_sp"},
			
			marker_spawn = {--[[1]]"mkr_Bastion1", --[[2]]"mkr_Bastion2", --[[3]]"mkr_Bastion3", --[[4]]"mkr_Bastion4", --[[5]]"mkr_Bastion5", --[[6]]"mkr_Bastion6", --[[7]]"mkr_Bastion7", --[[8]]"mkr_Bastion8", 
			--[[9]]"mkr_Bastion9", --[[10]]"mkr_Bastion10", --[[11]]"mkr_Bastion11", --[[12]]"mkr_Bastion12", --[[13]]"mkr_Bastion13", --[[14]]"mkr_Bastion14", --[[15]]"mkr_Bastion15", --[[16]]"mkr_Bastion16",
			--[[17]]"mkr_Bastion17", --[[18]]"mkr_Sorcerer1", --[[19]]"mkr_Sorcerer2", --[[20]]"mkr_Khorne_Defiler1", --[[21]]"mkr_Khorne_Defiler2", --[[22]]"mkr_Khorne_Defiler3", --[[23]]"mkr_Khorne_Defiler4", --[[24]]"mkr_Khorne_Defiler5",
			--[[25]]"mkr_Khorne_Defiler6", --[[26]]"mkr_Chaos_Lord"}, 
			
			squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1, --[[7]] 1, --[[8]] 1, --[[9]] 1, --[[10]] 1, --[[11]] 1, --[[12]] 1, --[[13]] 1, --[[14]] 1, --[[15]] 1, --[[16]] 1, --[[17]] 1, --[[18]] 1, --[[19]] 1, --[[20]] 1, --[[21]] 1,
			--[[22]] 1, --[[23]] 1, --[[24]] 1, --[[25]] 1, --[[26]] 1}, 
			
			squad_size = {--[[1]] 9, --[[2]] 9, --[[3]] 9, --[[4]] 9, --[[5]] 1, --[[6]] 1, --[[7]] 9, --[[8]] 9, --[[9]] 9, --[[10]] 1, --[[11]] 1, --[[12]] 1, --[[13]] 1, --[[14]] 1, --[[15]] 1, --[[16]] 1, --[[17]] 1, --[[18]] 1, --[[19]] 1, --[[20]] 1, --[[21]] 1,
			--[[2]] 1, --[[23]] 1, --[[24]] 1, --[[25]] 1, --[[26]] 1}, 
			
		}
	
elseif g_Strength == 14 then


		t_Bastion_Army = {
			
			sgroup_name = { --[[1]]"sg_CM_Bastion1", --[[2]]"sg_CM_Bastion2", --[[3]]"sg_CM_Bastion3", --[[4]]"sg_CM_Bastion4", --[[5]]"sg_CM_Bastion5", --[[6]]"sg_CM_Bastion6", --[[7]]"sg_CM_Bastion7", --[[8]]"sg_CM_Bastion8",
			--[[9]]"sg_CM_Bastion9", --[[10]]"sg_CM_Bastion10", --[[11]]"sg_CM_Bastion11", --[[12]]"sg_CM_Bastion12", --[[13]]"sg_CM_Bastion13", --[[14]]"sg_CM_Bastion14", --[[15]]"sg_CM_Bastion15", --[[16]]"sg_CM_Bastion16",
			--[[17]]"sg_CM_Bastion17", --[[18]]"sg_Sorcerer1", --[[19]]"sg_Sorcerer2", --[[20]]"sg_KhorneDefiler1", --[[21]]"sg_KhorneDefiler2", --[[22]]"sg_KhorneDefiler3", --[[23]]"sg_KhorneDefiler4", --[[24]]"sg_KhorneDefiler5",
			--[[25]]"sg_KhorneDefiler6", --[[26]]"sg_Chaos_Lord"},  
			
			blueprint = {--[[1]]"chaos_marine_squad_stronghold_sp", --[[2]]"chaos_marine_squad_stronghold_sp", --[[3]]"chaos_marine_squad_stronghold_sp", --[[4]]"chaos_marine_squad_stronghold_sp", --[[5]]"chaos_squad_defiler", 
			--[[6]]"chaos_squad_defiler", --[[7]]"chaos_squad_possessed_marine",	--[[8]]"chaos_squad_possessed_marine", --[[9]]"chaos_squad_possessed_marine", --[[10]]"chaos_squad_defiler", --[[11]]"chaos_squad_defiler", 
			--[[12]]"chaos_squad_defiler", --[[13]]"chaos_squad_defiler", --[[14]]"chaos_squad_predator", --[[15]]"chaos_squad_defiler", --[[16]]"chaos_squad_predator", --[[17]]"chaos_squad_defiler", 
			--[[18]]"chaos_squad_sorcerer_stronghold_sp",--[[19]]"chaos_squad_sorcerer_stronghold_sp", --[[20]]"chaos_squad_defiler", --[[21]]"chaos_squad_defiler", --[[22]]"chaos_squad_defiler", --[[23]]"chaos_squad_defiler", 
			--[[24]]"chaos_squad_defiler", --[[25]]"chaos_squad_defiler", --[[26]]"chaos_squad_lord_advance_sp"},
			
			marker_spawn = {--[[1]]"mkr_Bastion1", --[[2]]"mkr_Bastion2", --[[3]]"mkr_Bastion3", --[[4]]"mkr_Bastion4", --[[5]]"mkr_Bastion5", --[[6]]"mkr_Bastion6", --[[7]]"mkr_Bastion7", --[[8]]"mkr_Bastion8", 
			--[[9]]"mkr_Bastion9", --[[10]]"mkr_Bastion10", --[[11]]"mkr_Bastion11", --[[12]]"mkr_Bastion12", --[[13]]"mkr_Bastion13", --[[14]]"mkr_Bastion14", --[[15]]"mkr_Bastion15", --[[16]]"mkr_Bastion16",
			--[[17]]"mkr_Bastion17", --[[18]]"mkr_Sorcerer1", --[[19]]"mkr_Sorcerer2", --[[20]]"mkr_Khorne_Defiler1", --[[21]]"mkr_Khorne_Defiler2", --[[22]]"mkr_Khorne_Defiler3", --[[23]]"mkr_Khorne_Defiler4", --[[24]]"mkr_Khorne_Defiler5",
			--[[25]]"mkr_Khorne_Defiler6", --[[26]]"mkr_Chaos_Lord"}, 
			
			squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1, --[[7]] 1, --[[8]] 1, --[[9]] 1, --[[10]] 1, --[[11]] 1, --[[12]] 1, --[[13]] 1, --[[14]] 1, --[[15]] 1, --[[16]] 1, --[[17]] 1, --[[18]] 1, --[[19]] 1, --[[20]] 1, --[[21]] 1,
			--[[22]] 1, --[[23]] 1, --[[24]] 1, --[[25]] 1, --[[26]] 1}, 
			
			squad_size = {--[[1]] 5, --[[2]] 5, --[[3]] 5, --[[4]] 5, --[[5]] 1, --[[6]] 1, --[[7]] 9, --[[8]] 9, --[[9]] 9, --[[10]] 1, --[[11]] 1, --[[12]] 1, --[[13]] 1, --[[14]] 1, --[[15]] 1, --[[16]] 1, --[[17]] 1, --[[18]] 1, --[[19]] 1, --[[20]] 1, --[[21]] 1,
			--[[2]] 1, --[[23]] 1, --[[24]] 1, --[[25]] 1, --[[26]] 1}, 
			
		}


elseif g_Strength == 13 then

		t_Bastion_Army = {
			
			sgroup_name = { --[[1]]"sg_CM_Bastion1", --[[2]]"sg_CM_Bastion2", --[[3]]"sg_CM_Bastion3", --[[4]]"sg_CM_Bastion4", --[[5]]"sg_CM_Bastion5", --[[6]]"sg_CM_Bastion6", --[[7]]"sg_CM_Bastion7", --[[8]]"sg_CM_Bastion8",
			--[[9]]"sg_CM_Bastion9", --[[10]]"sg_CM_Bastion10", --[[11]]"sg_CM_Bastion11", --[[12]]"sg_CM_Bastion12", --[[13]]"sg_CM_Bastion13", --[[14]]"sg_CM_Bastion14", --[[15]]"sg_CM_Bastion15", --[[16]]"sg_CM_Bastion16",
			--[[17]]"sg_CM_Bastion17", --[[18]]"sg_Sorcerer1", --[[19]]"sg_Sorcerer2", --[[20]]"sg_KhorneDefiler1", --[[21]]"sg_KhorneDefiler2", --[[22]]"sg_KhorneDefiler3", --[[23]]"sg_KhorneDefiler4", --[[24]]"sg_KhorneDefiler5",
			--[[25]]"sg_KhorneDefiler6", --[[26]]"sg_Chaos_Lord"},  
			
			blueprint = {--[[1]]"chaos_marine_squad_stronghold_sp", --[[2]]"chaos_marine_squad", --[[3]]"chaos_marine_squad_stronghold_sp", --[[4]]"chaos_marine_squad", --[[5]]"chaos_squad_defiler", 
			--[[6]]"chaos_squad_defiler", --[[7]]"chaos_squad_possessed_marine",	--[[8]]"chaos_squad_possessed_marine", --[[9]]"chaos_squad_possessed_marine", --[[10]]"chaos_squad_defiler", --[[11]]"chaos_squad_defiler", 
			--[[12]]"chaos_squad_defiler", --[[13]]"chaos_squad_defiler", --[[14]]"chaos_squad_predator", --[[15]]"chaos_squad_defiler", --[[16]]"chaos_squad_predator", --[[17]]"chaos_squad_defiler", 
			--[[18]]"chaos_squad_sorcerer_stronghold_sp",--[[19]]"chaos_squad_sorcerer_stronghold_sp", --[[20]]"chaos_squad_defiler", --[[21]]"chaos_squad_defiler", --[[22]]"chaos_squad_defiler", --[[23]]"chaos_squad_defiler", 
			--[[24]]"chaos_squad_defiler", --[[25]]"chaos_squad_defiler", --[[26]]"chaos_squad_lord_advance_sp"},
			
			marker_spawn = {--[[1]]"mkr_Bastion1", --[[2]]"mkr_Bastion2", --[[3]]"mkr_Bastion3", --[[4]]"mkr_Bastion4", --[[5]]"mkr_Bastion5", --[[6]]"mkr_Bastion6", --[[7]]"mkr_Bastion7", --[[8]]"mkr_Bastion8", 
			--[[9]]"mkr_Bastion9", --[[10]]"mkr_Bastion10", --[[11]]"mkr_Bastion11", --[[12]]"mkr_Bastion12", --[[13]]"mkr_Bastion13", --[[14]]"mkr_Bastion14", --[[15]]"mkr_Bastion15", --[[16]]"mkr_Bastion16",
			--[[17]]"mkr_Bastion17", --[[18]]"mkr_Sorcerer1", --[[19]]"mkr_Sorcerer2", --[[20]]"mkr_Khorne_Defiler1", --[[21]]"mkr_Khorne_Defiler2", --[[22]]"mkr_Khorne_Defiler3", --[[23]]"mkr_Khorne_Defiler4", --[[24]]"mkr_Khorne_Defiler5",
			--[[25]]"mkr_Khorne_Defiler6", --[[26]]"mkr_Chaos_Lord"}, 
			
			squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1, --[[7]] 1, --[[8]] 1, --[[9]] 1, --[[10]] 1, --[[11]] 1, --[[12]] 1, --[[13]] 1, --[[14]] 1, --[[15]] 1, --[[16]] 1, --[[17]] 1, --[[18]] 1, --[[19]] 1, --[[20]] 1, --[[21]] 1,
			--[[22]] 1, --[[23]] 1, --[[24]] 1, --[[25]] 1, --[[26]] 1}, 
			
			squad_size = {--[[1]] 5, --[[2]] 9, --[[3]] 5, --[[4]] 9, --[[5]] 1, --[[6]] 1, --[[7]] 9, --[[8]] 9, --[[9]] 9, --[[10]] 1, --[[11]] 1, --[[12]] 1, --[[13]] 1, --[[14]] 1, --[[15]] 1, --[[16]] 1, --[[17]] 1, --[[18]] 1, --[[19]] 1, --[[20]] 1, --[[21]] 1,
			--[[2]] 1, --[[23]] 1, --[[24]] 1, --[[25]] 1, --[[26]] 1}, 
			
		}


elseif g_Strength == 12 then

		t_Bastion_Army = {
			
			sgroup_name = { --[[1]]"sg_CM_Bastion1", --[[2]]"sg_CM_Bastion2", --[[3]]"sg_CM_Bastion3", --[[4]]"sg_CM_Bastion4", --[[5]]"sg_CM_Bastion5", --[[6]]"sg_CM_Bastion6", --[[7]]"sg_CM_Bastion7", --[[8]]"sg_CM_Bastion8",
			--[[9]]"sg_CM_Bastion9", --[[10]]"sg_CM_Bastion10", --[[11]]"sg_CM_Bastion11", --[[12]]"sg_CM_Bastion12", --[[13]]"sg_CM_Bastion13", --[[14]]"sg_CM_Bastion14", --[[15]]"sg_CM_Bastion15", --[[16]]"sg_CM_Bastion16",
			--[[17]]"sg_CM_Bastion17", --[[18]]"sg_Sorcerer1", --[[19]]"sg_Sorcerer2", --[[20]]"sg_KhorneDefiler1", --[[21]]"sg_KhorneDefiler2", --[[22]]"sg_KhorneDefiler3", --[[23]]"sg_KhorneDefiler4", --[[24]]"sg_KhorneDefiler5",
			--[[25]]"sg_KhorneDefiler6", --[[26]]"sg_Chaos_Lord"},  
			
			blueprint = {--[[1]]"chaos_marine_squad_stronghold_sp", --[[2]]"chaos_marine_squad", --[[3]]"chaos_marine_squad", --[[4]]"chaos_marine_squad", --[[5]]"chaos_squad_defiler", 
			--[[6]]"chaos_squad_defiler", --[[7]]"chaos_squad_possessed_marine",	--[[8]]"chaos_squad_possessed_marine", --[[9]]"chaos_squad_possessed_marine", --[[10]]"chaos_squad_defiler", --[[11]]"chaos_squad_defiler", 
			--[[12]]"chaos_squad_defiler", --[[13]]"chaos_squad_defiler", --[[14]]"chaos_squad_predator", --[[15]]"chaos_squad_defiler", --[[16]]"chaos_squad_predator", --[[17]]"chaos_squad_defiler", 
			--[[18]]"chaos_squad_sorcerer",--[[19]]"chaos_squad_sorcerer_stronghold_sp", --[[20]]"chaos_squad_defiler", --[[21]]"chaos_squad_defiler", --[[22]]"chaos_squad_defiler", --[[23]]"chaos_squad_defiler", 
			--[[24]]"chaos_squad_defiler", --[[25]]"chaos_squad_defiler", --[[26]]"chaos_squad_lord_advance_sp"},
			
			marker_spawn = {--[[1]]"mkr_Bastion1", --[[2]]"mkr_Bastion2", --[[3]]"mkr_Bastion3", --[[4]]"mkr_Bastion4", --[[5]]"mkr_Bastion5", --[[6]]"mkr_Bastion6", --[[7]]"mkr_Bastion7", --[[8]]"mkr_Bastion8", 
			--[[9]]"mkr_Bastion9", --[[10]]"mkr_Bastion10", --[[11]]"mkr_Bastion11", --[[12]]"mkr_Bastion12", --[[13]]"mkr_Bastion13", --[[14]]"mkr_Bastion14", --[[15]]"mkr_Bastion15", --[[16]]"mkr_Bastion16",
			--[[17]]"mkr_Bastion17", --[[18]]"mkr_Sorcerer1", --[[19]]"mkr_Sorcerer2", --[[20]]"mkr_Khorne_Defiler1", --[[21]]"mkr_Khorne_Defiler2", --[[22]]"mkr_Khorne_Defiler3", --[[23]]"mkr_Khorne_Defiler4", --[[24]]"mkr_Khorne_Defiler5",
			--[[25]]"mkr_Khorne_Defiler6", --[[26]]"mkr_Chaos_Lord"}, 
			
			squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1, --[[7]] 1, --[[8]] 1, --[[9]] 1, --[[10]] 1, --[[11]] 1, --[[12]] 1, --[[13]] 1, --[[14]] 1, --[[15]] 1, --[[16]] 1, --[[17]] 1, --[[18]] 1, --[[19]] 1, --[[20]] 1, --[[21]] 1,
			--[[22]] 1, --[[23]] 1, --[[24]] 1, --[[25]] 1, --[[26]] 1}, 
			
			squad_size = {--[[1]] 9, --[[2]] 9, --[[3]] 9, --[[4]] 9, --[[5]] 1, --[[6]] 1, --[[7]] 9, --[[8]] 9, --[[9]] 9, --[[10]] 1, --[[11]] 1, --[[12]] 1, --[[13]] 1, --[[14]] 1, --[[15]] 1, --[[16]] 1, --[[17]] 1, --[[18]] 1, --[[19]] 1, --[[20]] 1, --[[21]] 1,
			--[[2]] 1, --[[23]] 1, --[[24]] 1, --[[25]] 1, --[[26]] 1}, 
			
		}

elseif g_Strength == 11 then


		t_Bastion_Army = {
			
			sgroup_name = { --[[1]]"sg_CM_Bastion1", --[[2]]"sg_CM_Bastion2", --[[3]]"sg_CM_Bastion3", --[[4]]"sg_CM_Bastion4", --[[5]]"sg_CM_Bastion5", --[[6]]"sg_CM_Bastion6", --[[7]]"sg_CM_Bastion7", --[[8]]"sg_CM_Bastion8",
			--[[9]]"sg_CM_Bastion9", --[[10]]"sg_CM_Bastion10", --[[11]]"sg_CM_Bastion11", --[[12]]"sg_CM_Bastion12", --[[13]]"sg_CM_Bastion13", --[[14]]"sg_CM_Bastion14", --[[15]]"sg_CM_Bastion15", --[[16]]"sg_CM_Bastion16",
			--[[17]]"sg_CM_Bastion17", --[[18]]"sg_Sorcerer1", --[[19]]"sg_Sorcerer2", --[[20]]"sg_KhorneDefiler1", --[[21]]"sg_KhorneDefiler2", --[[22]]"sg_KhorneDefiler3", --[[23]]"sg_KhorneDefiler4", --[[24]]"sg_KhorneDefiler5",
			--[[25]]"sg_KhorneDefiler6", --[[26]]"sg_Chaos_Lord"},  
			
			blueprint = {--[[1]]"chaos_marine_squad", --[[2]]"chaos_marine_squad", --[[3]]"chaos_marine_squad", --[[4]]"chaos_marine_squad", --[[5]]"chaos_squad_defiler", 
			--[[6]]"chaos_squad_defiler", --[[7]]"chaos_squad_possessed_marine",	--[[8]]"chaos_squad_possessed_marine", --[[9]]"chaos_squad_possessed_marine", --[[10]]"chaos_squad_defiler", --[[11]]"chaos_squad_defiler", 
			--[[12]]"chaos_squad_defiler", --[[13]]"chaos_squad_defiler", --[[14]]"chaos_squad_predator", --[[15]]"chaos_squad_defiler", --[[16]]"chaos_squad_predator", --[[17]]"chaos_squad_defiler", 
			--[[18]]"chaos_squad_sorcerer",--[[19]]"chaos_squad_sorcerer", --[[20]]"chaos_squad_defiler", --[[21]]"chaos_squad_defiler", --[[22]]"chaos_squad_defiler", --[[23]]"chaos_squad_defiler", 
			--[[24]]"chaos_squad_defiler", --[[25]]"chaos_squad_defiler", --[[26]]"chaos_squad_lord_advance_sp"},
			
			marker_spawn = {--[[1]]"mkr_Bastion1", --[[2]]"mkr_Bastion2", --[[3]]"mkr_Bastion3", --[[4]]"mkr_Bastion4", --[[5]]"mkr_Bastion5", --[[6]]"mkr_Bastion6", --[[7]]"mkr_Bastion7", --[[8]]"mkr_Bastion8", 
			--[[9]]"mkr_Bastion9", --[[10]]"mkr_Bastion10", --[[11]]"mkr_Bastion11", --[[12]]"mkr_Bastion12", --[[13]]"mkr_Bastion13", --[[14]]"mkr_Bastion14", --[[15]]"mkr_Bastion15", --[[16]]"mkr_Bastion16",
			--[[17]]"mkr_Bastion17", --[[18]]"mkr_Sorcerer1", --[[19]]"mkr_Sorcerer2", --[[20]]"mkr_Khorne_Defiler1", --[[21]]"mkr_Khorne_Defiler2", --[[22]]"mkr_Khorne_Defiler3", --[[23]]"mkr_Khorne_Defiler4", --[[24]]"mkr_Khorne_Defiler5",
			--[[25]]"mkr_Khorne_Defiler6", --[[26]]"mkr_Chaos_Lord"}, 
			
			squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1, --[[7]] 1, --[[8]] 1, --[[9]] 1, --[[10]] 1, --[[11]] 1, --[[12]] 1, --[[13]] 1, --[[14]] 1, --[[15]] 1, --[[16]] 1, --[[17]] 1, --[[18]] 1, --[[19]] 1, --[[20]] 1, --[[21]] 1,
			--[[22]] 1, --[[23]] 1, --[[24]] 1, --[[25]] 1, --[[26]] 1}, 
			
			squad_size = {--[[1]] 9, --[[2]] 9, --[[3]] 9, --[[4]] 9, --[[5]] 1, --[[6]] 1, --[[7]] 9, --[[8]] 9, --[[9]] 9, --[[10]] 1, --[[11]] 1, --[[12]] 1, --[[13]] 1, --[[14]] 1, --[[15]] 1, --[[16]] 1, --[[17]] 1, --[[18]] 1, --[[19]] 1, --[[20]] 1, --[[21]] 1,
			--[[2]] 1, --[[23]] 1, --[[24]] 1, --[[25]] 1, --[[26]] 1}, 
			
		}
else


		t_Bastion_Army = {
			
			sgroup_name = { --[[1]]"sg_CM_Bastion1", --[[2]]"sg_CM_Bastion2", --[[3]]"sg_CM_Bastion3", --[[4]]"sg_CM_Bastion4", --[[5]]"sg_CM_Bastion5", --[[6]]"sg_CM_Bastion6", --[[7]]"sg_CM_Bastion7", --[[8]]"sg_CM_Bastion8",
			--[[9]]"sg_CM_Bastion9", --[[10]]"sg_CM_Bastion10", --[[11]]"sg_CM_Bastion11", --[[12]]"sg_CM_Bastion12", --[[13]]"sg_CM_Bastion13", --[[14]]"sg_CM_Bastion14", --[[15]]"sg_CM_Bastion15", --[[16]]"sg_CM_Bastion16",
			--[[17]]"sg_CM_Bastion17", --[[18]]"sg_Sorcerer1", --[[19]]"sg_Sorcerer2", --[[20]]"sg_KhorneDefiler1", --[[21]]"sg_KhorneDefiler2", --[[22]]"sg_KhorneDefiler3", --[[23]]"sg_KhorneDefiler4", --[[24]]"sg_KhorneDefiler5",
			--[[25]]"sg_KhorneDefiler6", --[[26]]"sg_Chaos_Lord"},  
			
			blueprint = {--[[1]]"chaos_marine_squad", --[[2]]"chaos_marine_squad", --[[3]]"chaos_marine_squad", --[[4]]"chaos_marine_squad", --[[5]]"chaos_squad_defiler", 
			--[[6]]"chaos_squad_defiler", --[[7]]"chaos_squad_possessed_marine",	--[[8]]"chaos_squad_possessed_marine", --[[9]]"chaos_squad_possessed_marine", --[[10]]"chaos_squad_defiler", --[[11]]"chaos_squad_defiler", 
			--[[12]]"chaos_squad_defiler", --[[13]]"chaos_squad_defiler", --[[14]]"chaos_squad_predator", --[[15]]"chaos_squad_defiler", --[[16]]"chaos_squad_predator", --[[17]]"chaos_squad_defiler", 
			--[[18]]"chaos_squad_sorcerer",--[[19]]"chaos_squad_sorcerer", --[[20]]"chaos_squad_defiler", --[[21]]"chaos_squad_defiler", --[[22]]"chaos_squad_defiler", --[[23]]"chaos_squad_defiler", 
			--[[24]]"chaos_squad_defiler", --[[25]]"chaos_squad_defiler", --[[26]]"chaos_squad_lord_advance_sp"},
			
			marker_spawn = {--[[1]]"mkr_Bastion1", --[[2]]"mkr_Bastion2", --[[3]]"mkr_Bastion3", --[[4]]"mkr_Bastion4", --[[5]]"mkr_Bastion5", --[[6]]"mkr_Bastion6", --[[7]]"mkr_Bastion7", --[[8]]"mkr_Bastion8", 
			--[[9]]"mkr_Bastion9", --[[10]]"mkr_Bastion10", --[[11]]"mkr_Bastion11", --[[12]]"mkr_Bastion12", --[[13]]"mkr_Bastion13", --[[14]]"mkr_Bastion14", --[[15]]"mkr_Bastion15", --[[16]]"mkr_Bastion16",
			--[[17]]"mkr_Bastion17", --[[18]]"mkr_Sorcerer1", --[[19]]"mkr_Sorcerer2", --[[20]]"mkr_Khorne_Defiler1", --[[21]]"mkr_Khorne_Defiler2", --[[22]]"mkr_Khorne_Defiler3", --[[23]]"mkr_Khorne_Defiler4", --[[24]]"mkr_Khorne_Defiler5",
			--[[25]]"mkr_Khorne_Defiler6", --[[26]]"mkr_Chaos_Lord"}, 
			
			squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1, --[[7]] 1, --[[8]] 1, --[[9]] 1, --[[10]] 1, --[[11]] 1, --[[12]] 1, --[[13]] 1, --[[14]] 1, --[[15]] 1, --[[16]] 1, --[[17]] 1, --[[18]] 1, --[[19]] 1, --[[20]] 1, --[[21]] 1,
			--[[22]] 1, --[[23]] 1, --[[24]] 1, --[[25]] 1, --[[26]] 1}, 
			
			squad_size = {--[[1]] 9, --[[2]] 9, --[[3]] 9, --[[4]] 9, --[[5]] 1, --[[6]] 1, --[[7]] 9, --[[8]] 9, --[[9]] 9, --[[10]] 1, --[[11]] 1, --[[12]] 1, --[[13]] 1, --[[14]] 1, --[[15]] 1, --[[16]] 1, --[[17]] 1, --[[18]] 1, --[[19]] 1, --[[20]] 1, --[[21]] 1,
			--[[2]] 1, --[[23]] 1, --[[24]] 1, --[[25]] 1, --[[26]] 1}, 
			
		}


end
	
	
local i = g_Bastion_Army_iter 
if g_Bastion_Army_iter <= table.getn(t_Bastion_Army.sgroup_name) and (SGroup_Exists(t_Bastion_Army.sgroup_name[i]) == false or SGroup_IsEmpty(t_Bastion_Army.sgroup_name[i])) then
	local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player2, t_Bastion_Army.sgroup_name[i], t_Bastion_Army.blueprint[i], t_Bastion_Army.marker_spawn[i], t_Bastion_Army.squad_num[i], t_Bastion_Army.squad_size[i])
	
	--these space marines don't break
	if Squad_HasMorale(SGroup_GetSpawnedSquadAt(SGroup_FromName(t_Bastion_Army.sgroup_name[i]), 1)) then
		SGroup_SetMoraleInvulnerable(t_Bastion_Army.sgroup_name[i], true)
	end
	
	--add them all into one meta group
	SGroup_AddGroup(SGroup_CreateIfNotFound("sg_CM_Bastion_Army"),  SGroup_FromName(t_Bastion_Army.sgroup_name[i]))
	Cmd_SetStance(t_Bastion_Army.sgroup_name[i], STANCE_Hold)

	--prevent AI from using these units
	Cpu_LockSGroupAcrossPlayers(t_Bastion_Army.sgroup_name[i])
	Cpu_LockSGroupAcrossPlayers("sg_CM_Bastion_Army")
	
elseif g_Bastion_Army_iter > table.getn(t_Bastion_Army.sgroup_name) then
		g_Bastion_Army_iter = 0
		
		
		SGroup_AddGroup(SGroup_CreateIfNotFound("sg_Sorcerers"),  SGroup_FromName("sg_Sorcerer1"))
		SGroup_AddGroup(SGroup_CreateIfNotFound("sg_Sorcerers"),  SGroup_FromName("sg_Sorcerer2"))
		
		if g_Strength == 15 then
				
				--upgrading the tac marines to chain guns
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion1"), 1), "chaos_heavy_bolter_tactical_stronghold_sp", 6)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion2"), 1), "chaos_heavy_bolter_tactical_stronghold_sp", 7)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion3"), 1), "chaos_heavy_bolter_tactical_stronghold_sp", 6)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion4"), 1), "chaos_heavy_bolter_tactical_stronghold_sp", 7)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion5"), 1), "chaos_obliterator_ranged_group", 3)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion6"), 1), "chaos_obliterator_ranged_group", 3)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion7"), 1), "chaos_flamer_possessed", 5)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion8"), 1), "chaos_flamer_possessed", 4)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion9"), 1), "chaos_flamer_possessed", 5)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion10"), 1), "chaos_obliterator_ranged_group",3)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion11"), 1), "chaos_obliterator_ranged_group",3)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion12"), 1), "chaos_obliterator_ranged_group",3)
		
		elseif g_Strength == 14 then
		
				--upgrading the tac marines to chain guns
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion1"), 1), "chaos_heavy_bolter_tactical_stronghold_sp", 3)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion2"), 1), "chaos_heavy_bolter_tactical_stronghold_sp", 3)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion3"), 1), "chaos_heavy_bolter_tactical_stronghold_sp", 3)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion4"), 1), "chaos_heavy_bolter_tactical_stronghold_sp", 3)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion5"), 1), "chaos_obliterator_ranged_group", 2)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion6"), 1), "chaos_obliterator_ranged_group", 2)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion7"), 1), "chaos_flamer_possessed", 4)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion8"), 1), "chaos_flamer_possessed", 4)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion9"), 1), "chaos_flamer_possessed", 4)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion10"), 1), "chaos_obliterator_ranged_group",2)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion11"), 1), "chaos_obliterator_ranged_group",2)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion12"), 1), "chaos_obliterator_ranged_group",2)
		
		
		elseif g_Strength == 13 then
		
		
				--upgrading the tac marines to chain guns
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion1"), 1), "chaos_heavy_bolter_tactical_stronghold_sp", 3)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion2"), 1), "chaos_heavy_bolter_tactical", 3)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion3"), 1), "chaos_heavy_bolter_tactical_stronghold_sp", 3)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion4"), 1), "chaos_heavy_bolter_tactical", 3)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion5"), 1), "chaos_obliterator_ranged_group", 2)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion6"), 1), "chaos_obliterator_ranged_group", 2)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion7"), 1), "chaos_flamer_possessed", 2)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion8"), 1), "chaos_flamer_possessed", 4)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion9"), 1), "chaos_flamer_possessed", 2)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion10"), 1), "chaos_obliterator_ranged_group",1)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion11"), 1), "chaos_obliterator_ranged_group",3)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion12"), 1), "chaos_obliterator_ranged_group",1)
		
		
		elseif g_Strength == 12 then
		
		
				--upgrading the tac marines to chain guns
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion1"), 1), "chaos_heavy_bolter_tactical_stronghold_sp", 2)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion2"), 1), "chaos_heavy_bolter_tactical", 5)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion3"), 1), "chaos_heavy_bolter_tactical", 5)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion4"), 1), "chaos_heavy_bolter_tactical", 5)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion5"), 1), "chaos_obliterator_ranged_group", 2)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion6"), 1), "chaos_obliterator_ranged_group", 2)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion7"), 1), "chaos_flamer_possessed", 2)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion8"), 1), "chaos_flamer_possessed", 4)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion9"), 1), "chaos_flamer_possessed", 2)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion10"), 1), "chaos_obliterator_ranged_group",1)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion11"), 1), "chaos_obliterator_ranged_group",3)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion12"), 1), "chaos_obliterator_ranged_group",1)
				
		elseif g_Strength == 11 then
		
				--upgrading the tac marines to chain guns
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion1"), 1), "chaos_heavy_bolter_tactical", 5)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion2"), 1), "chaos_heavy_bolter_tactical", 5)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion3"), 1), "chaos_heavy_bolter_tactical", 5)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion4"), 1), "chaos_heavy_bolter_tactical", 5)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion5"), 1), "chaos_obliterator_ranged_group", 2)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion6"), 1), "chaos_obliterator_ranged_group", 2)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion7"), 1), "chaos_flamer_possessed", 2)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion8"), 1), "chaos_flamer_possessed", 4)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion9"), 1), "chaos_flamer_possessed", 2)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion10"), 1), "chaos_obliterator_ranged_group",1)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion11"), 1), "chaos_obliterator_ranged_group",3)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion12"), 1), "chaos_obliterator_ranged_group",1)
		
		
		else
		
		
				--upgrading the tac marines to chain guns
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion1"), 1), "chaos_heavy_bolter_tactical", 5)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion2"), 1), "chaos_heavy_bolter_tactical", 5)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion3"), 1), "chaos_heavy_bolter_tactical", 5)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion4"), 1), "chaos_heavy_bolter_tactical", 5)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion5"), 1), "chaos_obliterator_ranged_group", 2)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion6"), 1), "chaos_obliterator_ranged_group", 2)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion7"), 1), "chaos_flamer_possessed", 2)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion8"), 1), "chaos_flamer_possessed", 4)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion9"), 1), "chaos_flamer_possessed", 2)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion10"), 1), "chaos_obliterator_ranged_group",1)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion11"), 1), "chaos_obliterator_ranged_group",3)
				Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion12"), 1), "chaos_obliterator_ranged_group",1)
		
		end
		
		
		Cmd_SetStance("sg_CM_Bastion1", STANCE_StandGround)
		Cmd_SetStance("sg_CM_Bastion2", STANCE_StandGround)
		Cmd_SetStance("sg_CM_Bastion3", STANCE_StandGround)
		Cmd_SetStance("sg_CM_Bastion4", STANCE_StandGround)


		Cmd_SetStance("sg_CM_Bastion5", STANCE_Hold)
		Cmd_SetStance("sg_CM_Bastion6", STANCE_Hold)
		Cmd_SetStance("sg_CM_Bastion7", STANCE_Hold)
		Cmd_SetStance("sg_CM_Bastion8", STANCE_Hold)
		Cmd_SetStance("sg_CM_Bastion9", STANCE_Hold)
		Cmd_SetStance("sg_CM_Bastion10", STANCE_Hold)
		Cmd_SetStance("sg_CM_Bastion11", STANCE_Hold)
		Cmd_SetStance("sg_CM_Bastion12", STANCE_Hold)

		
		Rule_AddInterval(Rule_PatrolA, 5)
		Rule_AddInterval(Rule_PatrolB, 5)
		
		Rule_AddInterval(Rule_KD_Patrol, 5)
		Rule_AddInterval(Rule_KDPatrol_Check, 5)
		
		
		Rule_AddInterval(Rule_Defiler_Static_Movement, 30)
		Rule_AddInterval(Rule_Defiler_Static_Movement2, 33)
		Rule_AddInterval(Rule_Defiler_Static_Movement3, 36)
		Rule_AddInterval(Rule_Defiler_Static_Movement4, 39)
		Rule_AddInterval(Rule_Defiler_Static_Movement5, 41)
		Rule_AddInterval(Rule_Defiler_Static_Movement6, 44)
		
		
		Rule_AddInterval(Rule_Inner_Bastion_Patrol1, 40)
		Rule_AddInterval(Rule_Inner_Bastion_Patrol2, 43)
		Rule_AddInterval(Rule_Inner_Bastion_Patrol3,46)
		
		Rule_Remove(Rule_CM_Bastion_Creation)

	
end
g_Bastion_Army_iter = g_Bastion_Army_iter+1

end


--First Chaos Wave defending the left bridge

function Rule_CM_FWL_Creation()

if g_Strength == 15 then
	
	t_FWL_Army = {
		
		sgroup_name = { --[[1]]"sg_CM_FWL1", --[[2]]"sg_CM_FWL2", --[[3]]"sg_CM_FWL3", --[[4]]"sg_CM_FWL4", --[[5]]"sg_CM_FWL5", --[[6]]"sg_CM_FWL6"},  
		
		blueprint = {--[[1]]"chaos_squad_cultist", --[[2]]"chaos_squad_cultist", --[[3]]"chaos_squad_cultist", --[[4]]"chaos_squad_cultist", --[[5]]"chaos_marine_squad_stronghold_sp", --[[6]]"chaos_squad_cultist"},
		
		marker_spawn = {--[[1]]"mkr_FWL1", --[[2]]"mkr_FWL2", --[[3]]"mkr_FWL3", --[[4]]"mkr_FWL4", --[[5]]"mkr_FWL5", --[[6]]"mkr_FWL6"}, 
		
		squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1}, 
		
		squad_size = {--[[1]] 9, --[[2]] 9, --[[3]] 9, --[[4]] 9, --[[5]] 2, --[[6]] 9}, 
		
	}
	
elseif g_Strength == 14 then

	t_FWL_Army = {
		
		sgroup_name = { --[[1]]"sg_CM_FWL1", --[[2]]"sg_CM_FWL2", --[[3]]"sg_CM_FWL3", --[[4]]"sg_CM_FWL4", --[[5]]"sg_CM_FWL5", --[[6]]"sg_CM_FWL6"},  
		
		blueprint = {--[[1]]"chaos_squad_cultist", --[[2]]"chaos_squad_cultist", --[[3]]"chaos_squad_cultist", --[[4]]"chaos_squad_cultist", --[[5]]"chaos_marine_squad", --[[6]]"chaos_squad_cultist"},
		
		marker_spawn = {--[[1]]"mkr_FWL1", --[[2]]"mkr_FWL2", --[[3]]"mkr_FWL3", --[[4]]"mkr_FWL4", --[[5]]"mkr_FWL5", --[[6]]"mkr_FWL6"}, 
		
		squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1}, 
		
		squad_size = {--[[1]] 9, --[[2]] 9, --[[3]] 9, --[[4]] 9, --[[5]] 2, --[[6]] 9}, 
		
	}

elseif g_Strength == 13 then

	t_FWL_Army = {
		
		sgroup_name = { --[[1]]"sg_CM_FWL1", --[[2]]"sg_CM_FWL2", --[[3]]"sg_CM_FWL3", --[[4]]"sg_CM_FWL4", --[[5]]"sg_CM_FWL5", --[[6]]"sg_CM_FWL6"},  
		
		blueprint = {--[[1]]"chaos_squad_cultist", --[[2]]"chaos_squad_cultist", --[[3]]"chaos_squad_cultist", --[[4]]"chaos_squad_cultist", --[[5]]"chaos_marine_squad", --[[6]]"chaos_squad_cultist"},
		
		marker_spawn = {--[[1]]"mkr_FWL1", --[[2]]"mkr_FWL2", --[[3]]"mkr_FWL3", --[[4]]"mkr_FWL4", --[[5]]"mkr_FWL5", --[[6]]"mkr_FWL6"}, 
		
		squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1}, 
		
		squad_size = {--[[1]] 8, --[[2]] 8, --[[3]] 8, --[[4]] 8, --[[5]] 2, --[[6]] 8}, 
		
	}

elseif g_Strength == 12 then


	t_FWL_Army = {
		
		sgroup_name = { --[[1]]"sg_CM_FWL1", --[[2]]"sg_CM_FWL2", --[[3]]"sg_CM_FWL3", --[[4]]"sg_CM_FWL4", --[[5]]"sg_CM_FWL5", --[[6]]"sg_CM_FWL6"},  
		
		blueprint = {--[[1]]"chaos_squad_cultist", --[[2]]"chaos_squad_cultist", --[[3]]"chaos_squad_cultist", --[[4]]"chaos_squad_cultist", --[[5]]"chaos_marine_squad", --[[6]]"chaos_squad_cultist"},
		
		marker_spawn = {--[[1]]"mkr_FWL1", --[[2]]"mkr_FWL2", --[[3]]"mkr_FWL3", --[[4]]"mkr_FWL4", --[[5]]"mkr_FWL5", --[[6]]"mkr_FWL6"}, 
		
		squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1}, 
		
		squad_size = {--[[1]] 7, --[[2]] 7, --[[3]] 7, --[[4]] 7, --[[5]] 2, --[[6]] 7}, 
		
	}

elseif g_Strength == 11 then

	t_FWL_Army = {
		
		sgroup_name = { --[[1]]"sg_CM_FWL1", --[[2]]"sg_CM_FWL2", --[[3]]"sg_CM_FWL3", --[[4]]"sg_CM_FWL4", --[[5]]"sg_CM_FWL5", --[[6]]"sg_CM_FWL6"},  
		
		blueprint = {--[[1]]"chaos_squad_cultist", --[[2]]"chaos_squad_cultist", --[[3]]"chaos_squad_cultist", --[[4]]"chaos_squad_cultist", --[[5]]"chaos_marine_squad", --[[6]]"chaos_squad_cultist"},
		
		marker_spawn = {--[[1]]"mkr_FWL1", --[[2]]"mkr_FWL2", --[[3]]"mkr_FWL3", --[[4]]"mkr_FWL4", --[[5]]"mkr_FWL5", --[[6]]"mkr_FWL6"}, 
		
		squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1}, 
		
		squad_size = {--[[1]] 6, --[[2]] 6, --[[3]] 6, --[[4]] 6, --[[5]] 2, --[[6]] 6}, 
		
	}


else


	t_FWL_Army = {
		
		sgroup_name = { --[[1]]"sg_CM_FWL1", --[[2]]"sg_CM_FWL2", --[[3]]"sg_CM_FWL3", --[[4]]"sg_CM_FWL4", --[[5]]"sg_CM_FWL5", --[[6]]"sg_CM_FWL6"},  
		
		blueprint = {--[[1]]"chaos_squad_cultist", --[[2]]"chaos_squad_cultist", --[[3]]"chaos_squad_cultist", --[[4]]"chaos_squad_cultist", --[[5]]"chaos_marine_squad", --[[6]]"chaos_squad_cultist"},
		
		marker_spawn = {--[[1]]"mkr_FWL1", --[[2]]"mkr_FWL2", --[[3]]"mkr_FWL3", --[[4]]"mkr_FWL4", --[[5]]"mkr_FWL5", --[[6]]"mkr_FWL6"}, 
		
		squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1}, 
		
		squad_size = {--[[1]] 5, --[[2]] 5, --[[3]] 5, --[[4]] 5, --[[5]] 2, --[[6]] 5}, 
		
	}


end

local i = g_FWL_Army_iter 
if g_FWL_Army_iter <= table.getn(t_FWL_Army.sgroup_name) and (SGroup_Exists(t_FWL_Army.sgroup_name[i]) == false or SGroup_IsEmpty(t_FWL_Army.sgroup_name[i])) then
	local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player2, t_FWL_Army.sgroup_name[i], t_FWL_Army.blueprint[i], t_FWL_Army.marker_spawn[i], t_FWL_Army.squad_num[i], t_FWL_Army.squad_size[i])
	
	
	--add them all into one meta group
	SGroup_AddGroup(SGroup_CreateIfNotFound("sg_CM_FWL_Army"),  SGroup_FromName(t_FWL_Army.sgroup_name[i]))

	--prevent AI from using these units
	Cpu_LockSGroupAcrossPlayers(t_FWL_Army.sgroup_name[i])
	Cpu_LockSGroupAcrossPlayers("sg_CM_FWL_Army")
	
elseif g_FWL_Army_iter > table.getn(t_FWL_Army.sgroup_name) then
		g_FWL_Army_iter = 0
		
		
		if g_Strength == 15 then
		
			--upgrading weaponry
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL1"), 1), "chaos_grenade_launcher", 9)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL1"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL2"), 1), "chaos_grenade_launcher", 9)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL2"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL3"), 1), "chaos_grenade_launcher", 9)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL3"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL4"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL5"), 1), "chaos_heavy_bolter_tactical_stronghold_sp", 2)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL6"), 1), "chaos_grenade_launcher", 5)

		
		elseif g_Strength == 14 then
		
			--upgrading weaponry
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL1"), 1), "chaos_grenade_launcher", 9)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL1"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL2"), 1), "chaos_grenade_launcher", 9)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL2"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL3"), 1), "chaos_grenade_launcher", 9)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL3"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL4"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL5"), 1), "chaos_heavy_bolter_tactical", 2)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL6"), 1), "chaos_grenade_launcher", 5)
		
		
		elseif g_Strength == 13 then
		
			--upgrading weaponry
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL1"), 1), "chaos_grenade_launcher", 7)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL1"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL2"), 1), "chaos_grenade_launcher", 7)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL2"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL3"), 1), "chaos_grenade_launcher", 7)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL3"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL4"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL5"), 1), "chaos_heavy_bolter_tactical", 1)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL6"), 1), "chaos_grenade_launcher", 5)
		
		
		elseif g_Strength == 12 then
		
			--upgrading weaponry
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL1"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL1"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL2"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL2"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL3"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL3"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL4"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL5"), 1), "chaos_heavy_bolter_tactical", 1)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL6"), 1), "chaos_grenade_launcher", 5)
		
		
		elseif g_Strength == 11 then
		
		
			--upgrading weaponry
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL1"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL1"), 1), "chaos_plasma_gun_cultist", 1)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL2"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL2"), 1), "chaos_plasma_gun_cultist", 1)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL3"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL3"), 1), "chaos_plasma_gun_cultist", 1)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL4"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL5"), 1), "chaos_heavy_bolter_tactical", 1)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL6"), 1), "chaos_grenade_launcher", 5)
		
		
		else
		
		
			--upgrading weaponry
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL1"), 1), "chaos_grenade_launcher", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL1"), 1), "chaos_plasma_gun_cultist", 2)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL2"), 1), "chaos_grenade_launcher", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL2"), 1), "chaos_plasma_gun_cultist", 2)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL3"), 1), "chaos_grenade_launcher", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL3"), 1), "chaos_plasma_gun_cultist", 2)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL4"), 1), "chaos_grenade_launcher", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL5"), 1), "chaos_heavy_bolter_tactical", 2)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWL6"), 1), "chaos_grenade_launcher", 5)
		
		
		end
		
		
		--set them to attack
		Cmd_SetStance("sg_CM_FWL1", STANCE_Attack)
		Cmd_SetStance("sg_CM_FWL2", STANCE_Attack)
		Cmd_SetStance("sg_CM_FWL3", STANCE_Attack)
		Cmd_SetStance("sg_CM_FWL4", STANCE_Attack)
		Cmd_SetStance("sg_CM_FWL6", STANCE_Attack)
		Cmd_SetStance("sg_CM_FWL5", STANCE_Attack)

		Rule_Remove(Rule_CM_FWL_Creation)

	
end
g_FWL_Army_iter = g_FWL_Army_iter+1

end


--First Chaos Wave defending the Right bridge

function Rule_CM_FWR_Creation()

 if g_Strength == 15 then
	
	t_FWR_Army = {
		
		sgroup_name = { --[[1]]"sg_CM_FWR1", --[[2]]"sg_CM_FWR2", --[[3]]"sg_CM_FWR3", --[[4]]"sg_CM_FWR4", --[[5]]"sg_CM_FWR5", --[[6]]"sg_CM_FWR6"},  
		
		blueprint = {--[[1]]"chaos_squad_cultist", --[[2]]"chaos_squad_cultist", --[[3]]"chaos_squad_cultist", --[[4]]"chaos_squad_cultist", --[[5]]"chaos_marine_squad_stronghold_sp", --[[6]]"chaos_squad_cultist"},
		
		marker_spawn = {--[[1]]"mkr_FWR1", --[[2]]"mkr_FWR2", --[[3]]"mkr_FWR3", --[[4]]"mkr_FWR4", --[[5]]"mkr_FWR5", --[[6]]"mkr_FWR6"}, 
		
		squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1}, 
		
		squad_size = {--[[1]] 9, --[[2]] 9, --[[3]] 9, --[[4]] 9, --[[5]] 2, --[[6]] 9}, 
		
	}

elseif g_Strength == 14 then	

	t_FWR_Army = {
		
		sgroup_name = { --[[1]]"sg_CM_FWR1", --[[2]]"sg_CM_FWR2", --[[3]]"sg_CM_FWR3", --[[4]]"sg_CM_FWR4", --[[5]]"sg_CM_FWR5", --[[6]]"sg_CM_FWR6"},  
		
		blueprint = {--[[1]]"chaos_squad_cultist", --[[2]]"chaos_squad_cultist", --[[3]]"chaos_squad_cultist", --[[4]]"chaos_squad_cultist", --[[5]]"chaos_marine_squad", --[[6]]"chaos_squad_cultist"},
		
		marker_spawn = {--[[1]]"mkr_FWR1", --[[2]]"mkr_FWR2", --[[3]]"mkr_FWR3", --[[4]]"mkr_FWR4", --[[5]]"mkr_FWR5", --[[6]]"mkr_FWR6"}, 
		
		squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1}, 
		
		squad_size = {--[[1]] 9, --[[2]] 9, --[[3]] 9, --[[4]] 9, --[[5]] 2, --[[6]] 9}, 
		
	}



elseif g_Strength == 13 then


	t_FWR_Army = {
		
		sgroup_name = { --[[1]]"sg_CM_FWR1", --[[2]]"sg_CM_FWR2", --[[3]]"sg_CM_FWR3", --[[4]]"sg_CM_FWR4", --[[5]]"sg_CM_FWR5", --[[6]]"sg_CM_FWR6"},  
		
		blueprint = {--[[1]]"chaos_squad_cultist", --[[2]]"chaos_squad_cultist", --[[3]]"chaos_squad_cultist", --[[4]]"chaos_squad_cultist", --[[5]]"chaos_marine_squad", --[[6]]"chaos_squad_cultist"},
		
		marker_spawn = {--[[1]]"mkr_FWR1", --[[2]]"mkr_FWR2", --[[3]]"mkr_FWR3", --[[4]]"mkr_FWR4", --[[5]]"mkr_FWR5", --[[6]]"mkr_FWR6"}, 
		
		squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1}, 
		
		squad_size = {--[[1]] 8, --[[2]] 8, --[[3]] 8, --[[4]] 8, --[[5]] 2, --[[6]] 8}, 
		
	}
elseif g_Strength == 12 then

	t_FWR_Army = {
		
		sgroup_name = { --[[1]]"sg_CM_FWR1", --[[2]]"sg_CM_FWR2", --[[3]]"sg_CM_FWR3", --[[4]]"sg_CM_FWR4", --[[5]]"sg_CM_FWR5", --[[6]]"sg_CM_FWR6"},  
		
		blueprint = {--[[1]]"chaos_squad_cultist", --[[2]]"chaos_squad_cultist", --[[3]]"chaos_squad_cultist", --[[4]]"chaos_squad_cultist", --[[5]]"chaos_marine_squad", --[[6]]"chaos_squad_cultist"},
		
		marker_spawn = {--[[1]]"mkr_FWR1", --[[2]]"mkr_FWR2", --[[3]]"mkr_FWR3", --[[4]]"mkr_FWR4", --[[5]]"mkr_FWR5", --[[6]]"mkr_FWR6"}, 
		
		squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1}, 
		
		squad_size = {--[[1]] 7, --[[2]] 7, --[[3]] 7, --[[4]] 7, --[[5]] 2, --[[6]] 7}, 
		
	}	

elseif g_Strength == 11 then

	t_FWR_Army = {
		
		sgroup_name = { --[[1]]"sg_CM_FWR1", --[[2]]"sg_CM_FWR2", --[[3]]"sg_CM_FWR3", --[[4]]"sg_CM_FWR4", --[[5]]"sg_CM_FWR5", --[[6]]"sg_CM_FWR6"},  
		
		blueprint = {--[[1]]"chaos_squad_cultist", --[[2]]"chaos_squad_cultist", --[[3]]"chaos_squad_cultist", --[[4]]"chaos_squad_cultist", --[[5]]"chaos_marine_squad", --[[6]]"chaos_squad_cultist"},
		
		marker_spawn = {--[[1]]"mkr_FWR1", --[[2]]"mkr_FWR2", --[[3]]"mkr_FWR3", --[[4]]"mkr_FWR4", --[[5]]"mkr_FWR5", --[[6]]"mkr_FWR6"}, 
		
		squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1}, 
		
		squad_size = {--[[1]] 6, --[[2]] 6, --[[3]] 6, --[[4]] 6, --[[5]] 2, --[[6]] 6}, 
		
	}

else


	t_FWR_Army = {
		
		sgroup_name = { --[[1]]"sg_CM_FWR1", --[[2]]"sg_CM_FWR2", --[[3]]"sg_CM_FWR3", --[[4]]"sg_CM_FWR4", --[[5]]"sg_CM_FWR5", --[[6]]"sg_CM_FWR6"},  
		
		blueprint = {--[[1]]"chaos_squad_cultist", --[[2]]"chaos_squad_cultist", --[[3]]"chaos_squad_cultist", --[[4]]"chaos_squad_cultist", --[[5]]"chaos_marine_squad", --[[6]]"chaos_squad_cultist"},
		
		marker_spawn = {--[[1]]"mkr_FWR1", --[[2]]"mkr_FWR2", --[[3]]"mkr_FWR3", --[[4]]"mkr_FWR4", --[[5]]"mkr_FWR5", --[[6]]"mkr_FWR6"}, 
		
		squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1}, 
		
		squad_size = {--[[1]] 5, --[[2]] 5, --[[3]] 5, --[[4]] 5, --[[5]] 2, --[[6]] 5}, 
		
	}

end	

local i = g_FWR_Army_iter 
if g_FWR_Army_iter <= table.getn(t_FWR_Army.sgroup_name) and (SGroup_Exists(t_FWR_Army.sgroup_name[i]) == false or SGroup_IsEmpty(t_FWR_Army.sgroup_name[i])) then
	local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player2, t_FWR_Army.sgroup_name[i], t_FWR_Army.blueprint[i], t_FWR_Army.marker_spawn[i], t_FWR_Army.squad_num[i], t_FWR_Army.squad_size[i])
	
	
	--add them all into one meta group
	SGroup_AddGroup(SGroup_CreateIfNotFound("sg_CM_FWR_Army"),  SGroup_FromName(t_FWR_Army.sgroup_name[i]))

	--prevent AI from using these units
	Cpu_LockSGroupAcrossPlayers(t_FWR_Army.sgroup_name[i])
	Cpu_LockSGroupAcrossPlayers("sg_CM_FWR_Army")
	
elseif g_FWR_Army_iter > table.getn(t_FWR_Army.sgroup_name) then
		g_FWR_Army_iter = 0
		
		
		if g_Strength == 15 then
		
			--upgrading the tac marines to chain guns
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR1"), 1), "chaos_grenade_launcher", 9)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR1"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR2"), 1), "chaos_grenade_launcher", 9)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR2"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR3"), 1), "chaos_grenade_launcher", 9)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR3"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR4"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR5"), 1), "chaos_heavy_bolter_tactical_stronghold_sp", 2)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR6"), 1), "chaos_grenade_launcher", 5)

		elseif g_Strength ==14 then
		
			--upgrading the tac marines to chain guns
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR1"), 1), "chaos_grenade_launcher", 9)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR1"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR2"), 1), "chaos_grenade_launcher", 9)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR2"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR3"), 1), "chaos_grenade_launcher", 9)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR3"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR4"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR5"), 1), "chaos_heavy_bolter_tactical", 2)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR6"), 1), "chaos_grenade_launcher", 5)
		
		elseif g_Strength ==13 then
		
			--upgrading the tac marines to chain guns
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR1"), 1), "chaos_grenade_launcher", 7)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR1"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR2"), 1), "chaos_grenade_launcher", 7)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR2"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR3"), 1), "chaos_grenade_launcher", 7)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR3"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR4"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR5"), 1), "chaos_heavy_bolter_tactical", 2)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR6"), 1), "chaos_grenade_launcher", 5)
		
		elseif g_Strength ==12 then
		
			--upgrading the tac marines to chain guns
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR1"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR1"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR2"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR2"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR3"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR3"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR4"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR5"), 1), "chaos_heavy_bolter_tactical", 2)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR6"), 1), "chaos_grenade_launcher", 5)
		
		elseif g_Strength ==11 then
		
			--upgrading the tac marines to chain guns
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR1"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR1"), 1), "chaos_plasma_gun_cultist", 1)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR2"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR2"), 1), "chaos_plasma_gun_cultist", 1)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR3"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR3"), 1), "chaos_plasma_gun_cultist", 1)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR4"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR5"), 1), "chaos_heavy_bolter_tactical", 2)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR6"), 1), "chaos_grenade_launcher", 5)
		
		else
		
			--upgrading the tac marines to chain guns
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR1"), 1), "chaos_grenade_launcher", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR1"), 1), "chaos_plasma_gun_cultist", 2)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR2"), 1), "chaos_grenade_launcher", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR2"), 1), "chaos_plasma_gun_cultist", 2)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR3"), 1), "chaos_grenade_launcher", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR3"), 1), "chaos_plasma_gun_cultist", 2)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR4"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR5"), 1), "chaos_heavy_bolter_tactical", 2)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_FWR6"), 1), "chaos_grenade_launcher", 5)
		
		end
		
		
		--set them to attack
		Cmd_SetStance("sg_CM_FWR1", STANCE_Attack)
		Cmd_SetStance("sg_CM_FWR2", STANCE_Attack)
		Cmd_SetStance("sg_CM_FWR3", STANCE_Attack)
		Cmd_SetStance("sg_CM_FWR4", STANCE_Attack)
		Cmd_SetStance("sg_CM_FWR6", STANCE_Attack)
		Cmd_SetStance("sg_CM_FWR5", STANCE_Attack)

		Rule_Remove(Rule_CM_FWR_Creation)

	
end
g_FWR_Army_iter = g_FWR_Army_iter+1

end


--Left bridge defenders

function Rule_CM_LB_Creation()

if g_Strength == 15 then
		
		t_LB_Army = {
			
			sgroup_name = { --[[1]]"sg_CM_LB1", --[[2]]"sg_CM_LB2", --[[3]]"sg_CM_LB3", --[[4]]"sg_CM_LB4", --[[5]]"sg_CM_LB5"},  
			
			blueprint = {--[[1]]"chaos_squad_cultist", --[[2]]"chaos_squad_cultist", --[[3]]"chaos_squad_cultist", --[[4]]"chaos_squad_cultist", --[[5]]"chaos_marine_squad_stronghold_sp"},
			
			marker_spawn = {--[[1]]"mkr_Bridge_Left1", --[[2]]"mkr_Bridge_Left2", --[[3]]"mkr_Bridge_Left3", --[[4]]"mkr_Bridge_Left4", --[[5]]"mkr_Bridge_Left5"}, 
			
			squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1}, 
			
			squad_size = {--[[1]] 9, --[[2]] 9, --[[3]] 9, --[[4]] 9, --[[5]] 2}, 
			
		}
		
elseif g_Strength == 14 then

		t_LB_Army = {
			
			sgroup_name = { --[[1]]"sg_CM_LB1", --[[2]]"sg_CM_LB2", --[[3]]"sg_CM_LB3", --[[4]]"sg_CM_LB4", --[[5]]"sg_CM_LB5"},  
			
			blueprint = {--[[1]]"chaos_squad_cultist", --[[2]]"chaos_squad_cultist", --[[3]]"chaos_squad_cultist", --[[4]]"chaos_squad_cultist", --[[5]]"chaos_marine_squad"},
			
			marker_spawn = {--[[1]]"mkr_Bridge_Left1", --[[2]]"mkr_Bridge_Left2", --[[3]]"mkr_Bridge_Left3", --[[4]]"mkr_Bridge_Left4", --[[5]]"mkr_Bridge_Left5"}, 
			
			squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1}, 
			
			squad_size = {--[[1]] 9, --[[2]] 9, --[[3]] 9, --[[4]] 9, --[[5]] 2}, 
			
		}

elseif g_Strength == 13 then

		t_LB_Army = {
			
			sgroup_name = { --[[1]]"sg_CM_LB1", --[[2]]"sg_CM_LB2", --[[3]]"sg_CM_LB3", --[[4]]"sg_CM_LB4", --[[5]]"sg_CM_LB5"},  
			
			blueprint = {--[[1]]"chaos_squad_cultist", --[[2]]"chaos_squad_cultist", --[[3]]"chaos_squad_cultist", --[[4]]"chaos_squad_cultist", --[[5]]"chaos_marine_squad"},
			
			marker_spawn = {--[[1]]"mkr_Bridge_Left1", --[[2]]"mkr_Bridge_Left2", --[[3]]"mkr_Bridge_Left3", --[[4]]"mkr_Bridge_Left4", --[[5]]"mkr_Bridge_Left5"}, 
			
			squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1}, 
			
			squad_size = {--[[1]] 8, --[[2]] 8, --[[3]] 8, --[[4]] 8, --[[5]] 2}, 
			
		}

elseif g_Strength == 12 then

		t_LB_Army = {
			
			sgroup_name = { --[[1]]"sg_CM_LB1", --[[2]]"sg_CM_LB2", --[[3]]"sg_CM_LB3", --[[4]]"sg_CM_LB4", --[[5]]"sg_CM_LB5"},  
			
			blueprint = {--[[1]]"chaos_squad_cultist", --[[2]]"chaos_squad_cultist", --[[3]]"chaos_squad_cultist", --[[4]]"chaos_squad_cultist", --[[5]]"chaos_marine_squad"},
			
			marker_spawn = {--[[1]]"mkr_Bridge_Left1", --[[2]]"mkr_Bridge_Left2", --[[3]]"mkr_Bridge_Left3", --[[4]]"mkr_Bridge_Left4", --[[5]]"mkr_Bridge_Left5"}, 
			
			squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1}, 
			
			squad_size = {--[[1]] 7, --[[2]] 7, --[[3]] 7, --[[4]] 7, --[[5]] 2}, 
			
		}

elseif g_Strength == 11 then


		t_LB_Army = {
			
			sgroup_name = { --[[1]]"sg_CM_LB1", --[[2]]"sg_CM_LB2", --[[3]]"sg_CM_LB3", --[[4]]"sg_CM_LB4", --[[5]]"sg_CM_LB5"},  
			
			blueprint = {--[[1]]"chaos_squad_cultist", --[[2]]"chaos_squad_cultist", --[[3]]"chaos_squad_cultist", --[[4]]"chaos_squad_cultist", --[[5]]"chaos_marine_squad"},
			
			marker_spawn = {--[[1]]"mkr_Bridge_Left1", --[[2]]"mkr_Bridge_Left2", --[[3]]"mkr_Bridge_Left3", --[[4]]"mkr_Bridge_Left4", --[[5]]"mkr_Bridge_Left5"}, 
			
			squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1}, 
			
			squad_size = {--[[1]] 6, --[[2]] 6, --[[3]] 6, --[[4]] 6, --[[5]] 2}, 
			
		}

else

	
		t_LB_Army = {
			
			sgroup_name = { --[[1]]"sg_CM_LB1", --[[2]]"sg_CM_LB2", --[[3]]"sg_CM_LB3", --[[4]]"sg_CM_LB4", --[[5]]"sg_CM_LB5"},  
			
			blueprint = {--[[1]]"chaos_squad_cultist", --[[2]]"chaos_squad_cultist", --[[3]]"chaos_squad_cultist", --[[4]]"chaos_squad_cultist", --[[5]]"chaos_marine_squad"},
			
			marker_spawn = {--[[1]]"mkr_Bridge_Left1", --[[2]]"mkr_Bridge_Left2", --[[3]]"mkr_Bridge_Left3", --[[4]]"mkr_Bridge_Left4", --[[5]]"mkr_Bridge_Left5"}, 
			
			squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1}, 
			
			squad_size = {--[[1]] 5, --[[2]] 5, --[[3]] 5, --[[4]] 5, --[[5]] 2}, 
			
		}


end


local i = g_LB_Army_iter 
if g_LB_Army_iter <= table.getn(t_LB_Army.sgroup_name) and (SGroup_Exists(t_LB_Army.sgroup_name[i]) == false or SGroup_IsEmpty(t_LB_Army.sgroup_name[i])) then
	local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player2, t_LB_Army.sgroup_name[i], t_LB_Army.blueprint[i], t_LB_Army.marker_spawn[i], t_LB_Army.squad_num[i], t_LB_Army.squad_size[i])
	
	
	--add them all into one meta group
	SGroup_AddGroup(SGroup_CreateIfNotFound("sg_CM_LB_Army"),  SGroup_FromName(t_LB_Army.sgroup_name[i]))

	--prevent AI from using these units
	Cpu_LockSGroupAcrossPlayers(t_LB_Army.sgroup_name[i])
	Cpu_LockSGroupAcrossPlayers("sg_CM_LB_Army")
	
elseif g_LB_Army_iter > table.getn(t_LB_Army.sgroup_name) then
		g_LB_Army_iter = 0
		
		
		if g_Strength == 15 then
			
			--upgrading the tac marines to chain guns
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB1"), 1), "chaos_grenade_launcher", 9)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB1"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB2"), 1), "chaos_grenade_launcher", 9)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB2"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB3"), 1), "chaos_grenade_launcher", 9)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB3"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB4"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB5"), 1), "chaos_heavy_bolter_tactical_stronghold_sp", 2)
		
		elseif g_Strength == 14 then
					
			--upgrading the tac marines to chain guns
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB1"), 1), "chaos_grenade_launcher", 9)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB1"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB2"), 1), "chaos_grenade_launcher", 9)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB2"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB3"), 1), "chaos_grenade_launcher", 9)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB3"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB4"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB5"), 1), "chaos_heavy_bolter_tactical", 2)
		
		elseif g_Strength == 13 then
		
					
			--upgrading the tac marines to chain guns
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB1"), 1), "chaos_grenade_launcher", 7)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB1"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB2"), 1), "chaos_grenade_launcher", 7)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB2"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB3"), 1), "chaos_grenade_launcher", 7)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB3"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB4"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB5"), 1), "chaos_heavy_bolter_tactical", 2)
		
		elseif g_Strength == 12 then
					
			--upgrading the tac marines to chain guns
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB1"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB1"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB2"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB2"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB3"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB3"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB4"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB5"), 1), "chaos_heavy_bolter_tactical", 2)
		
		elseif g_Strength == 11 then
		
			--upgrading the tac marines to chain guns
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB1"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB1"), 1), "chaos_plasma_gun_cultist", 1)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB2"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB2"), 1), "chaos_plasma_gun_cultist", 1)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB3"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB3"), 1), "chaos_plasma_gun_cultist", 1)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB4"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB5"), 1), "chaos_heavy_bolter_tactical", 2)
		
		
		else
		
		
			--upgrading the tac marines to chain guns
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB1"), 1), "chaos_grenade_launcher", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB1"), 1), "chaos_plasma_gun_cultist", 2)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB2"), 1), "chaos_grenade_launcher", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB2"), 1), "chaos_plasma_gun_cultist", 2)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB3"), 1), "chaos_grenade_launcher", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB3"), 1), "chaos_plasma_gun_cultist", 2)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB4"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_LB5"), 1), "chaos_heavy_bolter_tactical", 2)
		
					
		end

		
		
		--these units will follow the player for a little distance applaying pressure
		Cmd_SetStance("sg_CM_LB1", STANCE_Hold)
		Cmd_SetStance("sg_CM_LB2", STANCE_Hold)
		Cmd_SetStance("sg_CM_LB3", STANCE_Hold)
		Cmd_SetStance("sg_CM_LB4", STANCE_Hold)
		
		--these units will not follow the player
		Cmd_SetStance("sg_CM_LB5", STANCE_StandGround)

		
		Rule_AddIntervalDelay(Rule_Left_Bridge_Static_Movement, 60, 25)
		Rule_AddIntervalDelay(Rule_Left_Bridge_Static_Movement2, 60, 40)
		Rule_AddIntervalDelay(Rule_Left_Bridge_Static_Movement3, 60, 60)
		Rule_AddIntervalDelay(Rule_Left_Bridge_Static_Movement4, 60, 70)
		Rule_AddIntervalDelay(Rule_Left_Bridge_Static_Movement5, 60, 80)
		
		Rule_Remove(Rule_CM_LB_Creation)

	
end
g_LB_Army_iter = g_LB_Army_iter+1

end


--Right Barrack

function Rule_CM_Right_Barrack_Creation()

if g_Strength == 15 then

	t_Right_Barrack_Army = {
		
		sgroup_name = { --[[1]]"sg_CM_Right_Barrack1", --[[2]]"sg_CM_Right_Barrack2", --[[3]]"sg_CM_Right_Barrack3", --[[4]]"sg_CM_Right_Barrack4", --[[5]]"sg_CM_Right_Barrack5"},  
		
		blueprint = {--[[1]]"chaos_squad_cultist", --[[2]]"chaos_squad_cultist", --[[3]]"chaos_squad_horror", --[[4]]"chaos_squad_horror", --[[5]]"chaos_marine_squad_stronghold_sp"},
		
		marker_spawn = {--[[1]]"mkr_Barrack_Right1", --[[2]]"mkr_Barrack_Right2", --[[3]]"mkr_Barrack_Right3", --[[4]]"mkr_Barrack_Right4", --[[5]]"mkr_Barrack_Right5"}, 
		
		squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1}, 
		
		squad_size = {--[[1]] 9, --[[2]] 9, --[[3]] 4, --[[4]] 4, --[[5]] 2}, 
		
	}
	
elseif g_Strength == 14 then

	t_Right_Barrack_Army = {
		
		sgroup_name = { --[[1]]"sg_CM_Right_Barrack1", --[[2]]"sg_CM_Right_Barrack2", --[[3]]"sg_CM_Right_Barrack3", --[[4]]"sg_CM_Right_Barrack4", --[[5]]"sg_CM_Right_Barrack5"},  
		
		blueprint = {--[[1]]"chaos_squad_cultist", --[[2]]"chaos_squad_cultist", --[[3]]"chaos_squad_horror", --[[4]]"chaos_squad_horror", --[[5]]"chaos_marine_squad_stronghold_sp"},
		
		marker_spawn = {--[[1]]"mkr_Barrack_Right1", --[[2]]"mkr_Barrack_Right2", --[[3]]"mkr_Barrack_Right3", --[[4]]"mkr_Barrack_Right4", --[[5]]"mkr_Barrack_Right5"}, 
		
		squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1}, 
		
		squad_size = {--[[1]] 9, --[[2]] 9, --[[3]] 4, --[[4]] 4, --[[5]] 2}, 
		
	}


elseif g_Strength == 13 then

	t_Right_Barrack_Army = {
		
		sgroup_name = { --[[1]]"sg_CM_Right_Barrack1", --[[2]]"sg_CM_Right_Barrack2", --[[3]]"sg_CM_Right_Barrack3", --[[4]]"sg_CM_Right_Barrack4", --[[5]]"sg_CM_Right_Barrack5"},  
		
		blueprint = {--[[1]]"chaos_squad_cultist", --[[2]]"chaos_squad_cultist", --[[3]]"chaos_squad_horror", --[[4]]"chaos_squad_horror", --[[5]]"chaos_marine_squad"},
		
		marker_spawn = {--[[1]]"mkr_Barrack_Right1", --[[2]]"mkr_Barrack_Right2", --[[3]]"mkr_Barrack_Right3", --[[4]]"mkr_Barrack_Right4", --[[5]]"mkr_Barrack_Right5"}, 
		
		squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1}, 
		
		squad_size = {--[[1]] 8, --[[2]] 8, --[[3]] 4, --[[4]] 4, --[[5]] 2}, 
		
	}

elseif g_Strength == 12 then

	t_Right_Barrack_Army = {
		
		sgroup_name = { --[[1]]"sg_CM_Right_Barrack1", --[[2]]"sg_CM_Right_Barrack2", --[[3]]"sg_CM_Right_Barrack3", --[[4]]"sg_CM_Right_Barrack4", --[[5]]"sg_CM_Right_Barrack5"},  
		
		blueprint = {--[[1]]"chaos_squad_cultist", --[[2]]"chaos_squad_cultist", --[[3]]"chaos_squad_horror", --[[4]]"chaos_squad_horror", --[[5]]"chaos_marine_squad"},
		
		marker_spawn = {--[[1]]"mkr_Barrack_Right1", --[[2]]"mkr_Barrack_Right2", --[[3]]"mkr_Barrack_Right3", --[[4]]"mkr_Barrack_Right4", --[[5]]"mkr_Barrack_Right5"}, 
		
		squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1}, 
		
		squad_size = {--[[1]] 7, --[[2]] 7, --[[3]] 3, --[[4]] 4, --[[5]] 2}, 
		
	}

elseif g_Strength == 11 then
	
	t_Right_Barrack_Army = {
		
		sgroup_name = { --[[1]]"sg_CM_Right_Barrack1", --[[2]]"sg_CM_Right_Barrack2", --[[3]]"sg_CM_Right_Barrack3", --[[4]]"sg_CM_Right_Barrack4", --[[5]]"sg_CM_Right_Barrack5"},  
		
		blueprint = {--[[1]]"chaos_squad_cultist", --[[2]]"chaos_squad_cultist", --[[3]]"chaos_squad_horror", --[[4]]"chaos_squad_horror", --[[5]]"chaos_marine_squad"},
		
		marker_spawn = {--[[1]]"mkr_Barrack_Right1", --[[2]]"mkr_Barrack_Right2", --[[3]]"mkr_Barrack_Right3", --[[4]]"mkr_Barrack_Right4", --[[5]]"mkr_Barrack_Right5"}, 
		
		squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1}, 
		
		squad_size = {--[[1]] 6, --[[2]] 6, --[[3]] 3, --[[4]] 3, --[[5]] 2}, 
		
	}

else
	
	t_Right_Barrack_Army = {
		
		sgroup_name = { --[[1]]"sg_CM_Right_Barrack1", --[[2]]"sg_CM_Right_Barrack2", --[[3]]"sg_CM_Right_Barrack3", --[[4]]"sg_CM_Right_Barrack4", --[[5]]"sg_CM_Right_Barrack5"},  
		
		blueprint = {--[[1]]"chaos_squad_cultist", --[[2]]"chaos_squad_cultist", --[[3]]"chaos_squad_horror", --[[4]]"chaos_squad_horror", --[[5]]"chaos_marine_squad"},
		
		marker_spawn = {--[[1]]"mkr_Barrack_Right1", --[[2]]"mkr_Barrack_Right2", --[[3]]"mkr_Barrack_Right3", --[[4]]"mkr_Barrack_Right4", --[[5]]"mkr_Barrack_Right5"}, 
		
		squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1}, 
		
		squad_size = {--[[1]] 5, --[[2]] 5, --[[3]] 3, --[[4]] 2, --[[5]] 2}, 
		
	}


end	
	
local i = g_Right_Barrack_Army_iter 
if g_Right_Barrack_Army_iter <= table.getn(t_Right_Barrack_Army.sgroup_name) and (SGroup_Exists(t_Right_Barrack_Army.sgroup_name[i]) == false or SGroup_IsEmpty(t_Right_Barrack_Army.sgroup_name[i])) then
	local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player2, t_Right_Barrack_Army.sgroup_name[i], t_Right_Barrack_Army.blueprint[i], t_Right_Barrack_Army.marker_spawn[i], t_Right_Barrack_Army.squad_num[i], t_Right_Barrack_Army.squad_size[i])
	
	
	--add them all into one meta group
	SGroup_AddGroup(SGroup_CreateIfNotFound("sg_CM_Right_Barrack_Army"),  SGroup_FromName(t_Right_Barrack_Army.sgroup_name[i]))

	--prevent AI from using these units
	Cpu_LockSGroupAcrossPlayers(t_Right_Barrack_Army.sgroup_name[i])
	Cpu_LockSGroupAcrossPlayers("sg_CM_Right_Barrack_Army")
	
elseif g_Right_Barrack_Army_iter > table.getn(t_Right_Barrack_Army.sgroup_name) then
		g_Right_Barrack_Army_iter = 0
		
		
		if g_Strength == 15 then
		
			--upgrading weapons
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Right_Barrack1"), 1), "chaos_grenade_launcher", 9)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Right_Barrack1"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Right_Barrack2"), 1), "chaos_grenade_launcher", 9)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Right_Barrack2"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Right_Barrack5"), 1), "chaos_heavy_bolter_tactical_stronghold_sp", 2)
	
		elseif g_Strength == 14 then
		
			--upgrading weapons
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Right_Barrack1"), 1), "chaos_grenade_launcher", 9)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Right_Barrack1"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Right_Barrack2"), 1), "chaos_grenade_launcher", 9)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Right_Barrack2"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Right_Barrack5"), 1), "chaos_heavy_bolter_tactical", 2)
		
		elseif g_Strength == 13 then
		
			--upgrading weapons
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Right_Barrack1"), 1), "chaos_grenade_launcher", 7)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Right_Barrack1"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Right_Barrack2"), 1), "chaos_grenade_launcher", 9)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Right_Barrack2"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Right_Barrack5"), 1), "chaos_heavy_bolter_tactical", 2)
		
		elseif g_Strength == 12 then
		
			--upgrading weapons
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Right_Barrack1"), 1), "chaos_grenade_launcher", 7)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Right_Barrack1"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Right_Barrack2"), 1), "chaos_grenade_launcher", 7)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Right_Barrack2"), 1), "chaos_plasma_gun_cultist", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Right_Barrack5"), 1), "chaos_heavy_bolter_tactical", 2)
		
		elseif g_Strength == 11 then
		
			--upgrading weapons
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Right_Barrack1"), 1), "chaos_grenade_launcher", 6)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Right_Barrack1"), 1), "chaos_plasma_gun_cultist", 2)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Right_Barrack2"), 1), "chaos_grenade_launcher", 6)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Right_Barrack2"), 1), "chaos_plasma_gun_cultist", 2)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Right_Barrack5"), 1), "chaos_heavy_bolter_tactical", 2)
		
		else
		
			--upgrading weapons
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Right_Barrack1"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Right_Barrack1"), 1), "chaos_plasma_gun_cultist", 2)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Right_Barrack2"), 1), "chaos_grenade_launcher", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Right_Barrack2"), 1), "chaos_plasma_gun_cultist", 2)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Right_Barrack5"), 1), "chaos_heavy_bolter_tactical", 2)
		
		end
		
		
		--these units will follow the player for a little distance applaying pressure
		Cmd_SetStance("sg_CM_Right_Barrack1", STANCE_Hold)
		Cmd_SetStance("sg_CM_Right_Barrack2", STANCE_Hold)
		Cmd_SetStance("sg_CM_Right_Barrack3", STANCE_Hold)
		Cmd_SetStance("sg_CM_Right_Barrack4", STANCE_Hold)
		Cmd_SetStance("sg_CM_Right_Barrack5", STANCE_Attack)
		
		
		Rule_AddIntervalDelay(Rule_Right_Static_Movement, 60, 15)
		Rule_AddIntervalDelay(Rule_Right_Static_Movement2, 60, 30)
		Rule_AddIntervalDelay(Rule_Right_Static_Movement3, 60, 45)
		Rule_AddIntervalDelay(Rule_Right_Static_Movement4, 60, 55)
		Rule_AddIntervalDelay(Rule_Right_Static_Movement5, 60, 60)

		Rule_Remove(Rule_CM_Right_Barrack_Creation)

	
end
g_Right_Barrack_Army_iter = g_Right_Barrack_Army_iter+1

end


--Plains of Khorne

function Rule_CM_Plains_Khorne_Creation()

if g_Strength == 15 then

	t_Plains_Khorne_Army = {
		
		sgroup_name = { --[[1]]"sg_Plains_Khorne1", --[[2]]"sg_Plains_Khorne2", --[[3]]"sg_Plains_Khorne3", --[[4]]"sg_Plains_Khorne4", --[[5]]"sg_Plains_Khorne5", --[[6]]"sg_Plains_Khorne6"},  
		
		blueprint = {--[[1]]"chaos_squad_khorne_berserker_stronghold_sp", --[[2]]"chaos_squad_khorne_berserker_stronghold_sp", --[[3]]"chaos_squad_khorne_berserker_stronghold_sp", --[[4]]"chaos_squad_khorne_berserker_stronghold_sp", 
		--[[5]]"chaos_squad_khorne_berserker_stronghold_sp", --[[6]]"chaos_squad_khorne_berserker_stronghold_sp"},
		
		marker_spawn = {--[[1]]"mkr_Plain_Khorne1", --[[2]]"mkr_Plain_Khorne2", --[[3]]"mkr_Plain_Khorne3", --[[4]]"mkr_Plain_Khorne4", --[[5]]"mkr_Plain_Khorne5", --[[6]]"mkr_Plain_Khorne6"}, 
		
		squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1}, 
		
		squad_size = {--[[1]] 5, --[[2]] 4, --[[3]] 3, --[[4]] 4, --[[5]] 3, --[[6]] 3}, 
		
	}

elseif g_Strength == 14 then

	t_Plains_Khorne_Army = {
	
		sgroup_name = { --[[1]]"sg_Plains_Khorne1", --[[2]]"sg_Plains_Khorne2", --[[3]]"sg_Plains_Khorne3", --[[4]]"sg_Plains_Khorne4", --[[5]]"sg_Plains_Khorne5", --[[6]]"sg_Plains_Khorne6"},  
		
		blueprint = {--[[1]]"chaos_squad_khorne_berserker_stronghold_sp", --[[2]]"chaos_squad_khorne_berserker_stronghold_sp", --[[3]]"chaos_squad_khorne_berserker_stronghold_sp", --[[4]]"chaos_squad_khorne_berserker_stronghold_sp", 
		--[[5]]"chaos_squad_khorne_berserker_stronghold_sp", --[[6]]"chaos_squad_khorne_berserker_stronghold_sp"},
		
		marker_spawn = {--[[1]]"mkr_Plain_Khorne1", --[[2]]"mkr_Plain_Khorne2", --[[3]]"mkr_Plain_Khorne3", --[[4]]"mkr_Plain_Khorne4", --[[5]]"mkr_Plain_Khorne5", --[[6]]"mkr_Plain_Khorne6"}, 
		
		squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1}, 
		
		squad_size = {--[[1]] 4, --[[2]] 3, --[[3]] 2, --[[4]] 3, --[[5]] 2, --[[6]] 2}, 
		
	}

elseif g_Strength == 13 then

	t_Plains_Khorne_Army = {
	
		sgroup_name = { --[[1]]"sg_Plains_Khorne1", --[[2]]"sg_Plains_Khorne2", --[[3]]"sg_Plains_Khorne3", --[[4]]"sg_Plains_Khorne4", --[[5]]"sg_Plains_Khorne5", --[[6]]"sg_Plains_Khorne6"},  
		
		blueprint = {--[[1]]"chaos_squad_khorne_berserker", --[[2]]"chaos_squad_khorne_berserker", --[[3]]"chaos_squad_khorne_berserker_stronghold_sp", --[[4]]"chaos_squad_khorne_berserker", 
		--[[5]]"chaos_squad_khorne_berserker_stronghold_sp", --[[6]]"chaos_squad_khorne_berserker_stronghold_sp"},
		
		marker_spawn = {--[[1]]"mkr_Plain_Khorne1", --[[2]]"mkr_Plain_Khorne2", --[[3]]"mkr_Plain_Khorne3", --[[4]]"mkr_Plain_Khorne4", --[[5]]"mkr_Plain_Khorne5", --[[6]]"mkr_Plain_Khorne6"}, 
		
		squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1}, 
		
		squad_size = {--[[1]] 5, --[[2]] 4, --[[3]] 3, --[[4]] 4, --[[5]] 3, --[[6]] 3}, 
		
	}

elseif g_Strength == 12 then

	t_Plains_Khorne_Army = {
	
		sgroup_name = { --[[1]]"sg_Plains_Khorne1", --[[2]]"sg_Plains_Khorne2", --[[3]]"sg_Plains_Khorne3", --[[4]]"sg_Plains_Khorne4", --[[5]]"sg_Plains_Khorne5", --[[6]]"sg_Plains_Khorne6"},  
		
		blueprint = {--[[1]]"chaos_squad_khorne_berserker", --[[2]]"chaos_squad_khorne_berserker", --[[3]]"chaos_squad_khorne_berserker", --[[4]]"chaos_squad_khorne_berserker", 
		--[[5]]"chaos_squad_khorne_berserker", --[[6]]"chaos_squad_khorne_berserker"},
		
		marker_spawn = {--[[1]]"mkr_Plain_Khorne1", --[[2]]"mkr_Plain_Khorne2", --[[3]]"mkr_Plain_Khorne3", --[[4]]"mkr_Plain_Khorne4", --[[5]]"mkr_Plain_Khorne5", --[[6]]"mkr_Plain_Khorne6"}, 
		
		squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1}, 
		
		squad_size = {--[[1]] 5, --[[2]] 4, --[[3]] 3, --[[4]] 4, --[[5]] 3, --[[6]] 3}, 
		
	}

elseif g_Strength == 11 then

	t_Plains_Khorne_Army = {
	
		sgroup_name = { --[[1]]"sg_Plains_Khorne1", --[[2]]"sg_Plains_Khorne2", --[[3]]"sg_Plains_Khorne3", --[[4]]"sg_Plains_Khorne4", --[[5]]"sg_Plains_Khorne5", --[[6]]"sg_Plains_Khorne6"},  
		
		blueprint = {--[[1]]"chaos_squad_khorne_berserker", --[[2]]"chaos_squad_khorne_berserker", --[[3]]"chaos_squad_khorne_berserker", --[[4]]"chaos_squad_khorne_berserker", 
		--[[5]]"chaos_squad_khorne_berserker", --[[6]]"chaos_squad_khorne_berserker"},
		
		marker_spawn = {--[[1]]"mkr_Plain_Khorne1", --[[2]]"mkr_Plain_Khorne2", --[[3]]"mkr_Plain_Khorne3", --[[4]]"mkr_Plain_Khorne4", --[[5]]"mkr_Plain_Khorne5", --[[6]]"mkr_Plain_Khorne6"}, 
		
		squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1}, 
		
		squad_size = {--[[1]] 4, --[[2]] 3, --[[3]] 3, --[[4]] 3, --[[5]] 3, --[[6]] 3}, 
		
	}
		

else

	t_Plains_Khorne_Army = {
	
		sgroup_name = { --[[1]]"sg_Plains_Khorne1", --[[2]]"sg_Plains_Khorne2", --[[3]]"sg_Plains_Khorne3", --[[4]]"sg_Plains_Khorne4", --[[5]]"sg_Plains_Khorne5", --[[6]]"sg_Plains_Khorne6"},  
		
		blueprint = {--[[1]]"chaos_squad_khorne_berserker", --[[2]]"chaos_squad_khorne_berserker", --[[3]]"chaos_squad_khorne_berserker", --[[4]]"chaos_squad_khorne_berserker", 
		--[[5]]"chaos_squad_khorne_berserker", --[[6]]"chaos_squad_khorne_berserker"},
		
		marker_spawn = {--[[1]]"mkr_Plain_Khorne1", --[[2]]"mkr_Plain_Khorne2", --[[3]]"mkr_Plain_Khorne3", --[[4]]"mkr_Plain_Khorne4", --[[5]]"mkr_Plain_Khorne5", --[[6]]"mkr_Plain_Khorne6"}, 
		
		squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1}, 
		
		squad_size = {--[[1]] 3, --[[2]] 3, --[[3]] 3, --[[4]] 3, --[[5]] 2, --[[6]] 3}, 
	}

end

local i = g_Plains_Khorne_Army_iter 
if g_Plains_Khorne_Army_iter <= table.getn(t_Plains_Khorne_Army.sgroup_name) and (SGroup_Exists(t_Plains_Khorne_Army.sgroup_name[i]) == false or SGroup_IsEmpty(t_Plains_Khorne_Army.sgroup_name[i])) then
	local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player2, t_Plains_Khorne_Army.sgroup_name[i], t_Plains_Khorne_Army.blueprint[i], t_Plains_Khorne_Army.marker_spawn[i], t_Plains_Khorne_Army.squad_num[i], t_Plains_Khorne_Army.squad_size[i])
	
	
	--add them all into one meta group
	SGroup_AddGroup(SGroup_CreateIfNotFound("sg_CM_Plains_Khorne_Army"),  SGroup_FromName(t_Plains_Khorne_Army.sgroup_name[i]))

	--prevent AI from using these units
	Cpu_LockSGroupAcrossPlayers(t_Plains_Khorne_Army.sgroup_name[i])
	Cpu_LockSGroupAcrossPlayers("sg_CM_Plains_Khorne_Army")
	
elseif g_Plains_Khorne_Army_iter > table.getn(t_Plains_Khorne_Army.sgroup_name) then
		g_Plains_Khorne_Army_iter = 0
		
		
		if g_Strength == 15 then
		
			--upgrading the tac marines to chain guns
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne1"), 1), "chaos_khornate_chainaxe_advance_sp", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne2"), 1), "chaos_khornate_chainaxe_advance_sp", 4)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne3"), 1), "chaos_khornate_chainaxe_advance_sp", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne4"), 1), "chaos_khornate_chainaxe_advance_sp", 4)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne5"), 1), "chaos_khornate_chainaxe_advance_sp", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne6"), 1), "chaos_khornate_chainaxe_advance_sp", 3)
			
		elseif g_Strength == 14 then
		
			--upgrading the tac marines to chain guns
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne1"), 1), "chaos_khornate_chainaxe_advance_sp", 4)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne2"), 1), "chaos_khornate_chainaxe_advance_sp", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne3"), 1), "chaos_khornate_chainaxe_advance_sp", 2)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne4"), 1), "chaos_khornate_chainaxe_advance_sp", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne5"), 1), "chaos_khornate_chainaxe_advance_sp", 2)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne6"), 1), "chaos_khornate_chainaxe_advance_sp", 2)
		
		elseif g_Strength == 13 then
		
			--upgrading the tac marines to chain guns
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne1"), 1), "chaos_khornate_chainaxe", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne2"), 1), "chaos_khornate_chainaxe", 4)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne3"), 1), "chaos_khornate_chainaxe_advance_sp", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne4"), 1), "chaos_khornate_chainaxe", 4)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne5"), 1), "chaos_khornate_chainaxe_advance_sp", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne6"), 1), "chaos_khornate_chainaxe_advance_sp", 3)
		
		elseif g_Strength == 12 then
		
			--upgrading the tac marines to chain guns
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne1"), 1), "chaos_khornate_chainaxe", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne2"), 1), "chaos_khornate_chainaxe", 4)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne3"), 1), "chaos_khornate_chainaxe", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne4"), 1), "chaos_khornate_chainaxe", 4)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne5"), 1), "chaos_khornate_chainaxe", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne6"), 1), "chaos_khornate_chainaxe", 3)
		
		elseif g_Strength == 11 then
		
			--upgrading the tac marines to chain guns
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne1"), 1), "chaos_khornate_chainaxe", 4)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne2"), 1), "chaos_khornate_chainaxe", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne3"), 1), "chaos_khornate_chainaxe", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne4"), 1), "chaos_khornate_chainaxe", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne5"), 1), "chaos_khornate_chainaxe", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne6"), 1), "chaos_khornate_chainaxe", 3)
		
		else
					
			--upgrading the tac marines to chain guns
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne1"), 1), "chaos_khornate_chainaxe", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne2"), 1), "chaos_khornate_chainaxe", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne3"), 1), "chaos_khornate_chainaxe", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne4"), 1), "chaos_khornate_chainaxe", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne5"), 1), "chaos_khornate_chainaxe", 2)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_Plains_Khorne6"), 1), "chaos_khornate_chainaxe", 3)
		
		end

		
		
		--these units will follow the player for a little distance applaying pressure
		Cmd_SetStance("sg_Plains_Khorne1", STANCE_Hold)
		Cmd_SetStance("sg_Plains_Khorne2", STANCE_Hold)
		Cmd_SetStance("sg_Plains_Khorne3", STANCE_Hold)
		Cmd_SetStance("sg_Plains_Khorne4", STANCE_Hold)
		Cmd_SetStance("sg_Plains_Khorne5", STANCE_Hold)
		Cmd_SetStance("sg_Plains_Khorne6", STANCE_Hold)


		
		Rule_AddInterval(Rule_PatrolC, 5)
		Rule_AddInterval(Rule_PatrolD, 5)
		Rule_AddInterval(Rule_PatrolE, 5)
		Rule_AddInterval(Rule_PatrolF, 5)
		Rule_AddInterval(Rule_PatrolG, 5)
		Rule_AddInterval(Rule_PatrolH, 5)
		
		Rule_Remove(Rule_CM_Plains_Khorne_Creation)

	
end
g_Plains_Khorne_Army_iter = g_Plains_Khorne_Army_iter+1

end


--units defending the relic and chaos temple function Rule_CM_Relic_Creation()

if g_Strength == 15 then

		t_Relic_Army = {
			
			sgroup_name = { --[[1]]"sg_CM_Relic1", --[[2]]"sg_CM_Relic2", --[[3]]"sg_CM_Relic3", --[[4]]"sg_CM_Relic4", --[[5]]"sg_CM_Relic5", --[[6]]"sg_CM_Relic6"},  
			
			blueprint = {--[[1]]"chaos_squad_obliterator_stronghold_sp", --[[2]]"chaos_squad_obliterator_stronghold_sp", --[[3]]"chaos_squad_khorne_berserker_stronghold_sp", --[[4]]"chaos_marine_squad_stronghold_sp", 
			--[[5]]"chaos_squad_obliterator_stronghold_sp", --[[6]]"chaos_marine_squad_stronghold_sp"},
			
			marker_spawn = {--[[1]]"mkr_Khorne_Defender1", --[[2]]"mkr_Khorne_Defender2", --[[3]]"mkr_Khorne_Defender3", --[[4]]"mkr_Khorne_Defender4", --[[5]]"mkr_Khorne_Defender5", --[[6]]"mkr_Khorne_Defender6"}, 
			
			squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1}, 
			
			squad_size = {--[[1]] 1, --[[2]] 1, --[[3]] 5, --[[4]] 9, --[[5]] 3, --[[6]] 9}, 
			
		}
		
elseif g_Strength == 14 then
		
		t_Relic_Army = {
			
			sgroup_name = { --[[1]]"sg_CM_Relic1", --[[2]]"sg_CM_Relic2", --[[3]]"sg_CM_Relic3", --[[4]]"sg_CM_Relic4", --[[5]]"sg_CM_Relic5", --[[6]]"sg_CM_Relic6"},  
			
			blueprint = {--[[1]]"chaos_squad_obliterator_stronghold_sp", --[[2]]"chaos_squad_obliterator", --[[3]]"chaos_squad_khorne_berserker", --[[4]]"chaos_marine_squad_stronghold_sp", 
			--[[5]]"chaos_squad_obliterator", --[[6]]"chaos_marine_squad_stronghold_sp"},
			
			marker_spawn = {--[[1]]"mkr_Khorne_Defender1", --[[2]]"mkr_Khorne_Defender2", --[[3]]"mkr_Khorne_Defender3", --[[4]]"mkr_Khorne_Defender4", --[[5]]"mkr_Khorne_Defender5", --[[6]]"mkr_Khorne_Defender6"}, 
			
			squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1}, 
			
			squad_size = {--[[1]] 1, --[[2]] 1, --[[3]] 5, --[[4]] 5, --[[5]] 3, --[[6]] 9}, 
			
		}


elseif g_Strength == 13 then

		t_Relic_Army = {
			
			sgroup_name = { --[[1]]"sg_CM_Relic1", --[[2]]"sg_CM_Relic2", --[[3]]"sg_CM_Relic3", --[[4]]"sg_CM_Relic4", --[[5]]"sg_CM_Relic5", --[[6]]"sg_CM_Relic6"},  
			
			blueprint = {--[[1]]"chaos_squad_obliterator", --[[2]]"chaos_squad_obliterator", --[[3]]"chaos_squad_khorne_berserker", --[[4]]"chaos_marine_squad_stronghold_sp", 
			--[[5]]"chaos_squad_obliterator", --[[6]]"chaos_marine_squad_stronghold_sp"},
			
			marker_spawn = {--[[1]]"mkr_Khorne_Defender1", --[[2]]"mkr_Khorne_Defender2", --[[3]]"mkr_Khorne_Defender3", --[[4]]"mkr_Khorne_Defender4", --[[5]]"mkr_Khorne_Defender5", --[[6]]"mkr_Khorne_Defender6"}, 
			
			squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1}, 
			
			squad_size = {--[[1]] 1, --[[2]] 1, --[[3]] 5, --[[4]] 5, --[[5]] 3, --[[6]] 5}, 
			
		}


elseif g_Strength == 12 then


		t_Relic_Army = {
			
			sgroup_name = { --[[1]]"sg_CM_Relic1", --[[2]]"sg_CM_Relic2", --[[3]]"sg_CM_Relic3", --[[4]]"sg_CM_Relic4", --[[5]]"sg_CM_Relic5", --[[6]]"sg_CM_Relic6"},  
			
			blueprint = {--[[1]]"chaos_squad_obliterator", --[[2]]"chaos_squad_obliterator", --[[3]]"chaos_squad_khorne_berserker", --[[4]]"chaos_marine_squad", 
			--[[5]]"chaos_squad_obliterator", --[[6]]"chaos_marine_squad"},
			
			marker_spawn = {--[[1]]"mkr_Khorne_Defender1", --[[2]]"mkr_Khorne_Defender2", --[[3]]"mkr_Khorne_Defender3", --[[4]]"mkr_Khorne_Defender4", --[[5]]"mkr_Khorne_Defender5", --[[6]]"mkr_Khorne_Defender6"}, 
			
			squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1}, 
			
			squad_size = {--[[1]] 1, --[[2]] 1, --[[3]] 5, --[[4]] 9, --[[5]] 3, --[[6]] 9}, 
			
		}


elseif g_Strength == 11 then

		t_Relic_Army = {
			
			sgroup_name = { --[[1]]"sg_CM_Relic1", --[[2]]"sg_CM_Relic2", --[[3]]"sg_CM_Relic3", --[[4]]"sg_CM_Relic4", --[[5]]"sg_CM_Relic5", --[[6]]"sg_CM_Relic6"},  
			
			blueprint = {--[[1]]"chaos_squad_obliterator", --[[2]]"chaos_squad_obliterator", --[[3]]"chaos_squad_khorne_berserker", --[[4]]"chaos_marine_squad", 
			--[[5]]"chaos_squad_obliterator", --[[6]]"chaos_marine_squad"},
			
			marker_spawn = {--[[1]]"mkr_Khorne_Defender1", --[[2]]"mkr_Khorne_Defender2", --[[3]]"mkr_Khorne_Defender3", --[[4]]"mkr_Khorne_Defender4", --[[5]]"mkr_Khorne_Defender5", --[[6]]"mkr_Khorne_Defender6"}, 
			
			squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1}, 
			
			squad_size = {--[[1]] 1, --[[2]] 1, --[[3]] 3, --[[4]] 7, --[[5]] 3, --[[6]] 7}, 
			
		}


else


		t_Relic_Army = {
			
			sgroup_name = { --[[1]]"sg_CM_Relic1", --[[2]]"sg_CM_Relic2", --[[3]]"sg_CM_Relic3", --[[4]]"sg_CM_Relic4", --[[5]]"sg_CM_Relic5", --[[6]]"sg_CM_Relic6"},  
			
			blueprint = {--[[1]]"chaos_squad_obliterator", --[[2]]"chaos_squad_obliterator", --[[3]]"chaos_squad_khorne_berserker", --[[4]]"chaos_marine_squad", 
			--[[5]]"chaos_squad_obliterator", --[[6]]"chaos_marine_squad"},
			
			marker_spawn = {--[[1]]"mkr_Khorne_Defender1", --[[2]]"mkr_Khorne_Defender2", --[[3]]"mkr_Khorne_Defender3", --[[4]]"mkr_Khorne_Defender4", --[[5]]"mkr_Khorne_Defender5", --[[6]]"mkr_Khorne_Defender6"}, 
			
			squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1}, 
			
			squad_size = {--[[1]] 1, --[[2]] 1, --[[3]] 3, --[[4]] 6, --[[5]] 3, --[[6]] 6}, 
			
		}


end
	
local i = g_Relic_Army_iter 
if g_Relic_Army_iter <= table.getn(t_Relic_Army.sgroup_name) and (SGroup_Exists(t_Relic_Army.sgroup_name[i]) == false or SGroup_IsEmpty(t_Relic_Army.sgroup_name[i])) then
	local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player2, t_Relic_Army.sgroup_name[i], t_Relic_Army.blueprint[i], t_Relic_Army.marker_spawn[i], t_Relic_Army.squad_num[i], t_Relic_Army.squad_size[i])
	

	--prevent AI from using these units
	Cpu_LockSGroupAcrossPlayers(t_Relic_Army.sgroup_name[i])

	
elseif g_Relic_Army_iter > table.getn(t_Relic_Army.sgroup_name) then
		g_Relic_Army_iter = 0
		
		
		if g_Strength == 15 then
		
			--upgrading the tac marines to chain guns
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic1"), 1), "chaos_obliterator_ranged_group_advance_sp",3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic2"), 1), "chaos_obliterator_ranged_group_advance_sp",3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic3"), 1), "chaos_khornate_chainaxe_advance_sp", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic4"), 1), "chaos_heavy_bolter_tactical_stronghold_sp", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic5"), 1), "chaos_obliterator_ranged_group_advance_sp",3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic6"), 1), "chaos_heavy_bolter_tactical_stronghold_sp", 3)
		
		elseif g_Strength == 14 then
		
			--upgrading the tac marines to chain guns
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic1"), 1), "chaos_obliterator_ranged_group_advance_sp",3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic2"), 1), "chaos_obliterator_ranged_group",3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic3"), 1), "chaos_khornate_chainaxe", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic4"), 1), "chaos_heavy_bolter_tactical_stronghold_sp", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic5"), 1), "chaos_obliterator_ranged_group",3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic6"), 1), "chaos_heavy_bolter_tactical_stronghold_sp", 3)
		
		elseif g_Strength == 13 then
		
			--upgrading the tac marines to chain guns
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic1"), 1), "chaos_obliterator_ranged_group",3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic2"), 1), "chaos_obliterator_ranged_group",3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic3"), 1), "chaos_khornate_chainaxe", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic4"), 1), "chaos_heavy_bolter_tactical_stronghold_sp", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic5"), 1), "chaos_obliterator_ranged_group",3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic6"), 1), "chaos_heavy_bolter_tactical_stronghold_sp", 3)
		
		elseif g_Strength == 12 then
		
			--upgrading the tac marines to chain guns
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic1"), 1), "chaos_obliterator_ranged_group",3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic2"), 1), "chaos_obliterator_ranged_group",3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic3"), 1), "chaos_khornate_chainaxe", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic4"), 1), "chaos_heavy_bolter_tactical", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic5"), 1), "chaos_obliterator_ranged_group",3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic6"), 1), "chaos_heavy_bolter_tactical", 3)
		
		elseif g_Strength == 11 then
		
	--upgrading the tac marines to chain guns
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic1"), 1), "chaos_obliterator_ranged_group",1)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic2"), 1), "chaos_obliterator_ranged_group",1)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic3"), 1), "chaos_khornate_chainaxe", 1)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic4"), 1), "chaos_heavy_bolter_tactical", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic5"), 1), "chaos_obliterator_ranged_group",1)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic6"), 1), "chaos_heavy_bolter_tactical", 3)
		
		else
		
	--upgrading the tac marines to chain guns
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic1"), 1), "chaos_obliterator_ranged_group",1)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic2"), 1), "chaos_obliterator_ranged_group",1)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic3"), 1), "chaos_khornate_chainaxe", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic4"), 1), "chaos_heavy_bolter_tactical", 2)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic5"), 1), "chaos_obliterator_ranged_group",1)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Relic6"), 1), "chaos_heavy_bolter_tactical", 2)
		
		
		end
		
		Cmd_SetStance("sg_CM_Relic1", STANCE_Hold)
		Cmd_SetStance("sg_CM_Relic2", STANCE_Hold)
		Cmd_SetStance("sg_CM_Relic3", STANCE_Hold)
		Cmd_SetStance("sg_CM_Relic4", STANCE_Hold)
		Cmd_SetStance("sg_CM_Relic5", STANCE_Hold)
		Cmd_SetStance("sg_CM_Relic6", STANCE_Hold)


		--gets an obliterator squad to go on a small patrol inside the relic base
		Rule_AddInterval(Rule_KO5_Patrol, 5)
		
		Rule_AddIntervalDelay(Rule_Relic_Static_Movement, 60, 30)
		Rule_AddIntervalDelay(Rule_Relic_Static_Movement2, 60, 45)
		Rule_AddIntervalDelay(Rule_Relic_Static_Movement3, 60, 60)
		Rule_AddIntervalDelay(Rule_Relic_Static_Movement4, 60, 90)
		
		Rule_Remove(Rule_CM_Relic_Creation)

	
end
g_Relic_Army_iter = g_Relic_Army_iter+1

end


--army on the right ridge

function Rule_CM_RR_Creation()

if g_Strength == 15 then
		
		t_RR_Army = {
			
			sgroup_name = { --[[1]]"sg_CM_RR1", --[[2]]"sg_CM_RR2", --[[3]]"sg_CM_RR3", --[[4]]"sg_CM_RR4", --[[5]]"sg_CM_RR5", --[[6]]"sg_CM_RR6", --[[7]]"sg_CM_RR7", --[[8]]"sg_CM_RR8"},  
			
			blueprint = {--[[1]]"chaos_squad_horror", --[[2]]"chaos_squad_horror", --[[3]]"chaos_squad_horror", --[[4]]"chaos_squad_raptor_stronghold_sp", --[[5]]"chaos_squad_raptor_stronghold_sp", --[[6]]"chaos_squad_obliterator_stronghold_sp",
			--[[7]]"chaos_squad_raptor_stronghold_sp",	--[[8]]"chaos_squad_obliterator_stronghold_sp"},
			
			marker_spawn = {--[[1]]"mkr_RR1", --[[2]]"mkr_RR2", --[[3]]"mkr_RR3", --[[4]]"mkr_RR4", --[[5]]"mkr_RR5", --[[6]]"mkr_RR6", --[[7]]"mkr_RR7", --[[8]]"mkr_RR8", }, 
			
			squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1, --[[7]] 1, --[[8]] 1}, 
			
			squad_size = {--[[1]] 5, --[[2]] 5, --[[3]] 5, --[[4]] 7, --[[5]] 7, --[[6]] 1, --[[7]] 9, --[[8]] 1}, 
			
		}

elseif g_Strength == 14 then

		t_RR_Army = {
			
			sgroup_name = { --[[1]]"sg_CM_RR1", --[[2]]"sg_CM_RR2", --[[3]]"sg_CM_RR3", --[[4]]"sg_CM_RR4", --[[5]]"sg_CM_RR5", --[[6]]"sg_CM_RR6", --[[7]]"sg_CM_RR7", --[[8]]"sg_CM_RR8"},  
			
			blueprint = {--[[1]]"chaos_squad_horror", --[[2]]"chaos_squad_horror", --[[3]]"chaos_squad_horror", --[[4]]"chaos_squad_raptor", --[[5]]"chaos_squad_raptor", --[[6]]"chaos_squad_obliterator_stronghold_sp",
			--[[7]]"chaos_squad_raptor",	--[[8]]"chaos_squad_obliterator"},
			
			marker_spawn = {--[[1]]"mkr_RR1", --[[2]]"mkr_RR2", --[[3]]"mkr_RR3", --[[4]]"mkr_RR4", --[[5]]"mkr_RR5", --[[6]]"mkr_RR6", --[[7]]"mkr_RR7", --[[8]]"mkr_RR8", }, 
			
			squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1, --[[7]] 1, --[[8]] 1}, 
			
			squad_size = {--[[1]] 5, --[[2]] 5, --[[3]] 5, --[[4]] 7, --[[5]] 7, --[[6]] 1, --[[7]] 9, --[[8]] 1}, 
			
		}


elseif g_Strength == 13 then

		t_RR_Army = {
			
			sgroup_name = { --[[1]]"sg_CM_RR1", --[[2]]"sg_CM_RR2", --[[3]]"sg_CM_RR3", --[[4]]"sg_CM_RR4", --[[5]]"sg_CM_RR5", --[[6]]"sg_CM_RR6", --[[7]]"sg_CM_RR7", --[[8]]"sg_CM_RR8"},  
			
			blueprint = {--[[1]]"chaos_squad_horror", --[[2]]"chaos_squad_horror", --[[3]]"chaos_squad_horror", --[[4]]"chaos_squad_raptor", --[[5]]"chaos_squad_raptor", --[[6]]"chaos_squad_obliterator",
			--[[7]]"chaos_squad_raptor",	--[[8]]"chaos_squad_obliterator"},
			
			marker_spawn = {--[[1]]"mkr_RR1", --[[2]]"mkr_RR2", --[[3]]"mkr_RR3", --[[4]]"mkr_RR4", --[[5]]"mkr_RR5", --[[6]]"mkr_RR6", --[[7]]"mkr_RR7", --[[8]]"mkr_RR8", }, 
			
			squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1, --[[7]] 1, --[[8]] 1}, 
			
			squad_size = {--[[1]] 5, --[[2]] 5, --[[3]] 5, --[[4]] 7, --[[5]] 7, --[[6]] 1, --[[7]] 9, --[[8]] 1}, 
			
		}

elseif g_Strength == 12 then

		t_RR_Army = {
			
			sgroup_name = { --[[1]]"sg_CM_RR1", --[[2]]"sg_CM_RR2", --[[3]]"sg_CM_RR3", --[[4]]"sg_CM_RR4", --[[5]]"sg_CM_RR5", --[[6]]"sg_CM_RR6", --[[7]]"sg_CM_RR7", --[[8]]"sg_CM_RR8"},  
			
			blueprint = {--[[1]]"chaos_squad_horror", --[[2]]"chaos_squad_horror", --[[3]]"chaos_squad_horror", --[[4]]"chaos_squad_raptor", --[[5]]"chaos_squad_raptor", --[[6]]"chaos_squad_obliterator",
			--[[7]]"chaos_squad_raptor",	--[[8]]"chaos_squad_obliterator"},
			
			marker_spawn = {--[[1]]"mkr_RR1", --[[2]]"mkr_RR2", --[[3]]"mkr_RR3", --[[4]]"mkr_RR4", --[[5]]"mkr_RR5", --[[6]]"mkr_RR6", --[[7]]"mkr_RR7", --[[8]]"mkr_RR8", }, 
			
			squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1, --[[7]] 1, --[[8]] 1}, 
			
			squad_size = {--[[1]] 5, --[[2]] 5, --[[3]] 5, --[[4]] 6, --[[5]] 6, --[[6]] 1, --[[7]] 7, --[[8]] 1}, 
			
		}

elseif g_Strength == 11 then

		t_RR_Army = {
			
			sgroup_name = { --[[1]]"sg_CM_RR1", --[[2]]"sg_CM_RR2", --[[3]]"sg_CM_RR3", --[[4]]"sg_CM_RR4", --[[5]]"sg_CM_RR5", --[[6]]"sg_CM_RR6", --[[7]]"sg_CM_RR7", --[[8]]"sg_CM_RR8"},  
			
			blueprint = {--[[1]]"chaos_squad_horror", --[[2]]"chaos_squad_horror", --[[3]]"chaos_squad_horror", --[[4]]"chaos_squad_raptor", --[[5]]"chaos_squad_raptor", --[[6]]"chaos_squad_obliterator",
			--[[7]]"chaos_squad_raptor",	--[[8]]"chaos_squad_obliterator"},
			
			marker_spawn = {--[[1]]"mkr_RR1", --[[2]]"mkr_RR2", --[[3]]"mkr_RR3", --[[4]]"mkr_RR4", --[[5]]"mkr_RR5", --[[6]]"mkr_RR6", --[[7]]"mkr_RR7", --[[8]]"mkr_RR8", }, 
			
			squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1, --[[7]] 1, --[[8]] 1}, 
			
			squad_size = {--[[1]] 4, --[[2]] 4, --[[3]] 4, --[[4]] 6, --[[5]] 6, --[[6]] 1, --[[7]] 7, --[[8]] 1}, 
			
		}

else

		t_RR_Army = {
			
			sgroup_name = { --[[1]]"sg_CM_RR1", --[[2]]"sg_CM_RR2", --[[3]]"sg_CM_RR3", --[[4]]"sg_CM_RR4", --[[5]]"sg_CM_RR5", --[[6]]"sg_CM_RR6", --[[7]]"sg_CM_RR7", --[[8]]"sg_CM_RR8"},  
			
			blueprint = {--[[1]]"chaos_squad_horror", --[[2]]"chaos_squad_horror", --[[3]]"chaos_squad_horror", --[[4]]"chaos_squad_raptor", --[[5]]"chaos_squad_raptor", --[[6]]"chaos_squad_obliterator",
			--[[7]]"chaos_squad_raptor",	--[[8]]"chaos_squad_obliterator"},
			
			marker_spawn = {--[[1]]"mkr_RR1", --[[2]]"mkr_RR2", --[[3]]"mkr_RR3", --[[4]]"mkr_RR4", --[[5]]"mkr_RR5", --[[6]]"mkr_RR6", --[[7]]"mkr_RR7", --[[8]]"mkr_RR8", }, 
			
			squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1, --[[6]] 1, --[[7]] 1, --[[8]] 1}, 
			
			squad_size = {--[[1]] 5, --[[2]] 3, --[[3]] 5, --[[4]] 5, --[[5]] 7, --[[6]] 1, --[[7]] 6, --[[8]] 1}, 
			
		}


end
	
local i = g_RR_Army_iter 
if g_RR_Army_iter <= table.getn(t_RR_Army.sgroup_name) and (SGroup_Exists(t_RR_Army.sgroup_name[i]) == false or SGroup_IsEmpty(t_RR_Army.sgroup_name[i])) then
	local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player2, t_RR_Army.sgroup_name[i], t_RR_Army.blueprint[i], t_RR_Army.marker_spawn[i], t_RR_Army.squad_num[i], t_RR_Army.squad_size[i])
	

	--add them all into one meta group
	SGroup_AddGroup(SGroup_CreateIfNotFound("sg_CM_Bastion_Army"),  SGroup_FromName(t_RR_Army.sgroup_name[i]))

	--prevent AI from using these units
	Cpu_LockSGroupAcrossPlayers(t_RR_Army.sgroup_name[i])
	Cpu_LockSGroupAcrossPlayers("sg_CM_Bastion_Army")
	
elseif g_RR_Army_iter > table.getn(t_RR_Army.sgroup_name) then
		g_RR_Army_iter = 0
		
	
		if g_Strength == 15 then
		
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_RR4"), 1), "chaos_flamer_raptor", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_RR5"), 1), "chaos_flamer_raptor", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_RR6"), 1), "chaos_power_fist_obliterator",3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_RR7"), 1), "chaos_chainsword_raptor", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_RR8"), 1), "chaos_power_fist_obliterator",3)
		
		elseif g_Strength == 14 then
		
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_RR4"), 1), "chaos_flamer_raptor", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_RR5"), 1), "chaos_flamer_raptor", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_RR6"), 1), "chaos_power_fist_obliterator",3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_RR7"), 1), "chaos_chainsword_raptor", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_RR8"), 1), "chaos_power_fist_obliterator",3)
					
		elseif g_Strength == 13 then
		
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_RR4"), 1), "chaos_flamer_raptor", 4)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_RR5"), 1), "chaos_flamer_raptor", 4)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_RR6"), 1), "chaos_power_fist_obliterator",2)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_RR7"), 1), "chaos_chainsword_raptor", 4)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_RR8"), 1), "chaos_power_fist_obliterator",2)
		
		elseif g_Strength == 12 then
		
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_RR4"), 1), "chaos_flamer_raptor", 4)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_RR5"), 1), "chaos_flamer_raptor", 5)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_RR6"), 1), "chaos_power_fist_obliterator",1)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_RR7"), 1), "chaos_chainsword_raptor", 4)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_RR8"), 1), "chaos_power_fist_obliterator",1)
		
		elseif g_Strength == 11 then
		
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_RR4"), 1), "chaos_flamer_raptor", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_RR5"), 1), "chaos_flamer_raptor", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_RR6"), 1), "chaos_power_fist_obliterator",2)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_RR7"), 1), "chaos_chainsword_raptor", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_RR8"), 1), "chaos_power_fist_obliterator",2)
		
		else
		
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_RR4"), 1), "chaos_flamer_raptor", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_RR5"), 1), "chaos_flamer_raptor", 2)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_RR6"), 1), "chaos_power_fist_obliterator",2)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_RR7"), 1), "chaos_chainsword_raptor", 3)
			Squad_ForceUpgradeWeapons(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_RR8"), 1), "chaos_power_fist_obliterator",1)
					
		end
		
		
		Cmd_SetStance("sg_CM_RR1", STANCE_Hold)
		Cmd_SetStance("sg_CM_RR2", STANCE_Hold)
		Cmd_SetStance("sg_CM_RR3", STANCE_Hold)
		Cmd_SetStance("sg_CM_RR4", STANCE_Hold)
		Cmd_SetStance("sg_CM_RR5", STANCE_Hold)
		Cmd_SetStance("sg_CM_RR6", STANCE_Hold)
		Cmd_SetStance("sg_CM_RR7", STANCE_Hold)
		Cmd_SetStance("sg_CM_RR8", STANCE_Hold)


		Rule_AddIntervalDelay(Rule_RR_Static_Movement, 60, 30)
		Rule_AddIntervalDelay(Rule_RR_Static_Movement2, 60, 45)
		Rule_AddIntervalDelay(Rule_RR_Static_Movement3, 60, 60)
		Rule_AddIntervalDelay(Rule_RR_Static_Movement4, 60, 80)
		Rule_AddIntervalDelay(Rule_RR_Static_Movement5, 60, 95)
		Rule_AddIntervalDelay(Rule_RR_Static_Movement6, 60, 120)
		Rule_AddIntervalDelay(Rule_RR_Static_Movement7, 60, 150)
		Rule_AddIntervalDelay(Rule_RR_Static_Movement8, 60, 180)
		
		Rule_Remove(Rule_CM_RR_Creation)

	
end
g_RR_Army_iter = g_RR_Army_iter+1

end


--a few units the player begins with in order to be able to defend his base (not the bonus units)

function Rule_Player_Defense_Creation()

	t_Player_Army = {
		
		sgroup_name = { --[[1]]"sg_Player_Defense1", --[[2]]"sg_Player_Defense2", --[[3]]"sg_Player_Defense3", --[[4]]"sg_Player_Defense4"},  
		
		blueprint = {--[[1]] g_BaseDefense_Type, --[[2]] g_BaseDefense_Type, --[[3]] g_BaseDefense_Type, --[[4]] g_BaseDefense_Type},
		
		marker_spawn = {--[[1]]"mkr_P_Defense1", --[[2]]"mkr_P_Defense2", --[[3]]"mkr_P_Defense3", --[[4]]"mkr_P_Defense4"}, 
		
		squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1}, 
		
		squad_size = {--[[1]] 9, --[[2]] 9, --[[3]] 9, --[[4]] 9}, 
		
	}



local i = g_Player_Army_iter 
if g_Player_Army_iter <= table.getn(t_Player_Army.sgroup_name) and (SGroup_Exists(t_Player_Army.sgroup_name[i]) == false or SGroup_IsEmpty(t_Player_Army.sgroup_name[i])) then
	local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player1, t_Player_Army.sgroup_name[i], t_Player_Army.blueprint[i], t_Player_Army.marker_spawn[i], t_Player_Army.squad_num[i], t_Player_Army.squad_size[i])
	
	
	
elseif g_Player_Army_iter > table.getn(t_Player_Army.sgroup_name) then
		g_Player_Army_iter = 0
		

		Rule_Remove(Rule_Player_Defense_Creation)

	
end
g_Player_Army_iter = g_Player_Army_iter+1

end


--[[Initial Attack]]

--a few unitsto attack the player at the start and get things rolling... initial attack

function Rule_Opening_Raid_Creation()

if g_Strength == 15 then
	
	t_Opening_Raid_Army = {
		
		sgroup_name = { --[[1]]"sg_CM_Opening1", --[[2]]"sg_CM_Opening2", --[[3]]"sg_CM_Opening3", --[[4]]"sg_CM_Opening4"},  
		
		blueprint = {--[[1]] "chaos_squad_khorne_berserker_stronghold_sp", --[[2]] "chaos_marine_squad_stronghold_sp", --[[3]] "chaos_squad_cultist", --[[4]] "chaos_squad_horror"},
		
		marker_spawn = {--[[1]]"mkr_OpeningRaid2", --[[2]]"mkr_OpeningRaid2", --[[3]]"mkr_OpeningRaid1", --[[4]]"mkr_OpeningRaid1"}, 
		
		squad_num = {--[[1]] 7, --[[2]] 3, --[[3]] 3, --[[4]] 2}, 
		
		squad_size = {--[[1]] 1, --[[2]] 6, --[[3]] 5, --[[4]] 6}, 
		
	}

	elseif g_Strength == 14 then
	
		t_Opening_Raid_Army = {
			
			sgroup_name = { --[[1]]"sg_CM_Opening1", --[[2]]"sg_CM_Opening2", --[[3]]"sg_CM_Opening3", --[[4]]"sg_CM_Opening4"},  
			
			blueprint = {--[[1]] "chaos_squad_khorne_berserker_stronghold_sp", --[[2]] "chaos_marine_squad_stronghold_sp", --[[3]] "chaos_squad_cultist", --[[4]] "chaos_squad_horror"},
			
			marker_spawn = {--[[1]]"mkr_OpeningRaid2", --[[2]]"mkr_OpeningRaid2", --[[3]]"mkr_OpeningRaid1", --[[4]]"mkr_OpeningRaid1"}, 
			
			squad_num = {--[[1]] 6, --[[2]] 3, --[[3]] 3, --[[4]] 2}, 
			
			squad_size = {--[[1]] 1, --[[2]] 5, --[[3]] 8, --[[4]] 5}, 
			
		}
	
	elseif g_Strength == 13 then
	
		t_Opening_Raid_Army = {
			
			sgroup_name = { --[[1]]"sg_CM_Opening1", --[[2]]"sg_CM_Opening2", --[[3]]"sg_CM_Opening3", --[[4]]"sg_CM_Opening4"},  
			
			blueprint = {--[[1]] "chaos_squad_khorne_berserker_stronghold_sp", --[[2]] "chaos_marine_squad", --[[3]] "chaos_squad_cultist", --[[4]] "chaos_squad_horror"},
			
			marker_spawn = {--[[1]]"mkr_OpeningRaid2", --[[2]]"mkr_OpeningRaid2", --[[3]]"mkr_OpeningRaid1", --[[4]]"mkr_OpeningRaid1"}, 
			
			squad_num = {--[[1]] 5, --[[2]] 3, --[[3]] 3, --[[4]] 2}, 
			
			squad_size = {--[[1]] 1, --[[2]] 4, --[[3]] 8, --[[4]] 4}, 
			
		}
	
	elseif g_Strength == 12 then
	
		t_Opening_Raid_Army = {
			
			sgroup_name = { --[[1]]"sg_CM_Opening1", --[[2]]"sg_CM_Opening2", --[[3]]"sg_CM_Opening3", --[[4]]"sg_CM_Opening4"},  
			
			blueprint = {--[[1]] "chaos_squad_khorne_berserker_stronghold_sp", --[[2]] "chaos_marine_squad", --[[3]] "chaos_squad_cultist", --[[4]] "chaos_squad_horror"},
			
			marker_spawn = {--[[1]]"mkr_OpeningRaid2", --[[2]]"mkr_OpeningRaid2", --[[3]]"mkr_OpeningRaid1", --[[4]]"mkr_OpeningRaid1"}, 
			
			squad_num = {--[[1]] 3, --[[2]] 2, --[[3]] 2, --[[4]] 2}, 
			
			squad_size = {--[[1]] 1, --[[2]] 4, --[[3]] 8, --[[4]] 4}, 
			
		}
	
	elseif g_Strength == 11 then
	
		t_Opening_Raid_Army = {
			
			sgroup_name = { --[[1]]"sg_CM_Opening1", --[[2]]"sg_CM_Opening2", --[[3]]"sg_CM_Opening3", --[[4]]"sg_CM_Opening4"},  
			
			blueprint = {--[[1]] "chaos_squad_khorne_berserker_stronghold_sp", --[[2]] "chaos_marine_squad", --[[3]] "chaos_squad_cultist", --[[4]] "chaos_squad_horror"},
			
			marker_spawn = {--[[1]]"mkr_OpeningRaid2", --[[2]]"mkr_OpeningRaid2", --[[3]]"mkr_OpeningRaid1", --[[4]]"mkr_OpeningRaid1"}, 
			
			squad_num = {--[[1]] 2, --[[2]] 1, --[[3]] 1, --[[4]] 1}, 
			
			squad_size = {--[[1]] 1, --[[2]] 4, --[[3]] 8, --[[4]] 4}, 
			
		}
	
	else
	
	
		t_Opening_Raid_Army = {
			
			sgroup_name = { --[[1]]"sg_CM_Opening1", --[[2]]"sg_CM_Opening2", --[[3]]"sg_CM_Opening3", --[[4]]"sg_CM_Opening4"},  
			
			blueprint = {--[[1]] "chaos_squad_khorne_berserker_stronghold_sp", --[[2]] "chaos_marine_squad", --[[3]] "chaos_squad_cultist", --[[4]] "chaos_squad_horror"},
			
			marker_spawn = {--[[1]]"mkr_OpeningRaid2", --[[2]]"mkr_OpeningRaid2", --[[3]]"mkr_OpeningRaid1", --[[4]]"mkr_OpeningRaid1"}, 
			
			squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1}, 
			
			squad_size = {--[[1]] 1, --[[2]] 3, --[[3]] 8, --[[4]] 1}, 
			
		}
	
	
	end
	

local i = g_Opening_Raid_Army_iter 
if g_Opening_Raid_Army_iter <= table.getn(t_Opening_Raid_Army.sgroup_name) and (SGroup_Exists(t_Opening_Raid_Army.sgroup_name[i]) == false or SGroup_IsEmpty(t_Opening_Raid_Army.sgroup_name[i])) then
	local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player2, t_Opening_Raid_Army.sgroup_name[i], t_Opening_Raid_Army.blueprint[i], t_Opening_Raid_Army.marker_spawn[i], 
	t_Opening_Raid_Army.squad_num[i], t_Opening_Raid_Army.squad_size[i])
	
	Cmd_AttackMoveMarker(t_Opening_Raid_Army.sgroup_name[i], "mkr_Player_HQ")
	
elseif g_Opening_Raid_Army_iter > table.getn(t_Opening_Raid_Army.sgroup_name) then
		g_Opening_Raid_Army_iter = 0
		

		Rule_Remove(Rule_Opening_Raid_Creation)

	
end
g_Opening_Raid_Army_iter = g_Opening_Raid_Army_iter+1

end

--[[ Patrols ]]

--predator patrol function Rule_PatrolA()

if SGroup_Exists("sg_CM_Bastion14") and SGroup_IsEmpty("sg_CM_Bastion14") == false then

	if Prox_AnySquadNearMarker("sg_CM_Bastion14", "mkr_PatrolA1") then
	
		Cmd_AttackMoveMarker("sg_CM_Bastion14", "mkr_PatrolA2")
	
	elseif Prox_AnySquadNearMarker("sg_CM_Bastion14", "mkr_PatrolA2") then

		Cmd_AttackMoveMarker("sg_CM_Bastion14", "mkr_PatrolA1")
	end

else
	
	Rule_Remove(Rule_PatrolA)

end
	

end

--predator patrol function Rule_PatrolB()

if SGroup_Exists("sg_CM_Bastion16") and SGroup_IsEmpty("sg_CM_Bastion16") == false then

	if Prox_AnySquadNearMarker("sg_CM_Bastion16", "mkr_PatrolB1") then
	
		Cmd_AttackMoveMarker("sg_CM_Bastion16", "mkr_PatrolB2")
	
	elseif Prox_AnySquadNearMarker("sg_CM_Bastion16", "mkr_PatrolB2") then

		Cmd_AttackMoveMarker("sg_CM_Bastion16", "mkr_PatrolB1")
	end

else
	
	Rule_Remove(Rule_PatrolB)

end

end

--khorne berserker patrol function Rule_PatrolC()

if SGroup_Exists("sg_Plains_Khorne1") and SGroup_IsEmpty("sg_Plains_Khorne1") == false then

	if Prox_AnySquadNearMarker("sg_Plains_Khorne1", "mkr_Plain_Khorne1") then
	
		Cmd_AttackMoveMarker("sg_Plains_Khorne1", "mkr_PatrolC1")
	
	elseif Prox_AnySquadNearMarker("sg_Plains_Khorne1", "mkr_PatrolC1") then

		Cmd_AttackMoveMarker("sg_Plains_Khorne1", "mkr_PatrolC2")
		
	elseif Prox_AnySquadNearMarker("sg_Plains_Khorne1", "mkr_PatrolC2") then

		Cmd_AttackMoveMarker("sg_Plains_Khorne1", "mkr_PatrolC3")
		
	elseif Prox_AnySquadNearMarker("sg_Plains_Khorne1", "mkr_PatrolC3") then

		Cmd_AttackMoveMarker("sg_Plains_Khorne1", "mkr_PatrolC4")
		
	elseif Prox_AnySquadNearMarker("sg_Plains_Khorne1", "mkr_PatrolC4") then

		Cmd_AttackMoveMarker("sg_Plains_Khorne1", "mkr_Plain_Khorne1")
	end

else
	
	Rule_Remove(Rule_PatrolC)

end

end

--khorne berserker patrol function Rule_PatrolD()

if SGroup_Exists("sg_Plains_Khorne2") and SGroup_IsEmpty("sg_Plains_Khorne2") == false then

	if Prox_AnySquadNearMarker("sg_Plains_Khorne2", "mkr_Plain_Khorne2") then
	
		Cmd_AttackMoveMarker("sg_Plains_Khorne2", "mkr_PatrolD1")
	
	elseif Prox_AnySquadNearMarker("sg_Plains_Khorne2", "mkr_PatrolD1") then

		Cmd_AttackMoveMarker("sg_Plains_Khorne2", "mkr_PatrolD2")
		
	elseif Prox_AnySquadNearMarker("sg_Plains_Khorne2", "mkr_PatrolD2") then

		Cmd_AttackMoveMarker("sg_Plains_Khorne2", "mkr_Plain_Khorne2")
		

	end

else
	
	Rule_Remove(Rule_PatrolD)

end

end

--khorne berserker patrol function Rule_PatrolE()

if SGroup_Exists("sg_Plains_Khorne3") and SGroup_IsEmpty("sg_Plains_Khorne3") == false then

	if Prox_AnySquadNearMarker("sg_Plains_Khorne3", "mkr_Plain_Khorne3") then
	
		Cmd_AttackMoveMarker("sg_Plains_Khorne3", "mkr_PatrolE1")
	
	elseif Prox_AnySquadNearMarker("sg_Plains_Khorne3", "mkr_PatrolE1") then

		Cmd_AttackMoveMarker("sg_Plains_Khorne3", "mkr_PatrolE2")
		
	elseif Prox_AnySquadNearMarker("sg_Plains_Khorne3", "mkr_PatrolE2") then

		Cmd_AttackMoveMarker("sg_Plains_Khorne3", "mkr_Plain_Khorne3")
		
	end

else
	
	Rule_Remove(Rule_PatrolE)

end

end

--khorne berserker patrol function Rule_PatrolF()

if SGroup_Exists("sg_Plains_Khorne5") and SGroup_IsEmpty("sg_Plains_Khorne5") == false then

	if Prox_AnySquadNearMarker("sg_Plains_Khorne5", "mkr_Plain_Khorne5") then
	
		Cmd_AttackMoveMarker("sg_Plains_Khorne5", "mkr_PatrolF1")
	
	elseif Prox_AnySquadNearMarker("sg_Plains_Khorne5", "mkr_PatrolF1") then

		Cmd_AttackMoveMarker("sg_Plains_Khorne5", "mkr_PatrolF2")
		
	elseif Prox_AnySquadNearMarker("sg_Plains_Khorne5", "mkr_PatrolF2") then

		Cmd_AttackMoveMarker("sg_Plains_Khorne5", "mkr_Plain_Khorne5")
		
	end

else
	
	Rule_Remove(Rule_PatrolF)

end

end

--khorne berserker patrol function Rule_PatrolG()

if SGroup_Exists("sg_Plains_Khorne4") and SGroup_IsEmpty("sg_Plains_Khorne4") == false then

	if Prox_AnySquadNearMarker("sg_Plains_Khorne4", "mkr_Plain_Khorne4") then
	
		Cmd_AttackMoveMarker("sg_Plains_Khorne4", "mkr_PatrolG1")
	
	elseif Prox_AnySquadNearMarker("sg_Plains_Khorne4", "mkr_PatrolG1") then

		Cmd_AttackMoveMarker("sg_Plains_Khorne4", "mkr_PatrolG2")
		
	elseif Prox_AnySquadNearMarker("sg_Plains_Khorne4", "mkr_PatrolG2") then

		Cmd_AttackMoveMarker("sg_Plains_Khorne4", "mkr_Plain_Khorne4")
		
	end

else
	
	Rule_Remove(Rule_PatrolG)

end

end

--khorne berserker patrol function Rule_PatrolH()

if SGroup_Exists("sg_Plains_Khorne6") and SGroup_IsEmpty("sg_Plains_Khorne6") == false then

	if Prox_AnySquadNearMarker("sg_Plains_Khorne6", "mkr_Plain_Khorne6") then
	
		Cmd_AttackMoveMarker("sg_Plains_Khorne6", "mkr_PatrolH1")
	
	elseif Prox_AnySquadNearMarker("sg_Plains_Khorne6", "mkr_PatrolH1") then

		Cmd_AttackMoveMarker("sg_Plains_Khorne6", "mkr_Plain_Khorne6")
		
	end

else
	
	Rule_Remove(Rule_PatrolH)

end

end


--obliterator patrol in the relic base

function Rule_KO5_Patrol()

t_obliterator_relic_patrol ={--[[1]]"mkr_KO5_1", --[[2]]"mkr_KO5_2", --[[3]]"mkr_KO5_3", --[[4]]"mkr_KO5_4"}

if SGroup_Exists("sg_CM_Relic5") and SGroup_IsEmpty("sg_CM_Relic5") == false then

	if g_reverse_obliterator == false then
	
		for i = 1, 4 do
	
			if Prox_AnySquadNearMarker("sg_CM_Relic5", t_obliterator_relic_patrol[i]) then
				
				--if the group has made it to the end of the patrol then reverse it
				if i == 4 then
				
					g_reverse_obliterator = true
					j = i - 1
					Cmd_AttackMoveMarker("sg_CM_Relic5", t_obliterator_relic_patrol[j])
					
				else
					
					j = i + 1 
					Cmd_AttackMoveMarker("sg_CM_Relic5", t_obliterator_relic_patrol[j])
					
				end
			
				break
				
			end
		end
	
	elseif g_reverse_obliterator == true then
	
		for i = 1, 4 do
					
			if Prox_AnySquadNearMarker("sg_CM_Relic5", t_obliterator_relic_patrol[i]) then
				
				--if the group has made it to the end of the patrol then reverse it
				if i == 1 then
				
					g_reverse_obliterator = false
					j = i + 1
					Cmd_AttackMoveMarker("sg_CM_Relic5", t_obliterator_relic_patrol[j])
					
				else
					
					j = i - 1 
					Cmd_AttackMoveMarker("sg_CM_Relic5", t_obliterator_relic_patrol[j])
				end
				
				break
				
			end
		
		end
	
	end

else	

	Rule_Remove(Rule_KO5_Patrol)

end

end


--defiler patrol infront of the bastion

--if the number of defilers patrolling is increased or decreased that change has to be made to the two tables below. t_existence_table = {--[[1]]6}

function Rule_KDPatrol_Check() --this is to check if there are still any defilers left, if not then remove the KD patrol rule. This could as easily have been done by adding all the defilers into a meta group and checking if it was empty of course.

local numdefile = t_existence_table[1]
g_total_defiler = 0

if numdefile == 0 then
	Rule_Remove(Rule_KDPatrol_Check)
	Rule_Remove(Rule_KD_Patrol)
else

	for i = 1, 6 do

		if SGroup_Exists("sg_KhorneDefiler"..i) and SGroup_IsEmpty("sg_KhorneDefiler"..i) == false then
		
			g_total_defiler =g_total_defiler +1
		
		end

		t_existence_table[1] = g_total_defiler

	end

end

end

t_reverse_table = {--[[1]]false, --[[2]]false, --[[3]]false, --[[4]]false, --[[5]]false, --[[6]]false}

function Rule_KD_Patrol()

t_KD1_patrol ={--[[1]]"mkr_KD1_1", --[[2]]"mkr_KD1_2", --[[3]]"mkr_KD1_3", --[[4]]"mkr_KD1_4"} t_KD2_patrol ={--[[1]]"mkr_KD2_1", --[[2]]"mkr_KD2_2", --[[3]]"mkr_KD2_3", --[[4]]"mkr_KD2_4"} t_KD3_patrol ={--[[1]]"mkr_KD3_1", --[[2]]"mkr_KD3_2", --[[3]]"mkr_KD3_3", --[[4]]"mkr_KD3_4", --[[5]]"mkr_KD3_5"} t_KD4_patrol ={--[[1]]"mkr_KD4_1", --[[2]]"mkr_KD4_2", --[[3]]"mkr_KD4_3"} t_KD5_patrol ={--[[1]]"mkr_KD5_1", --[[2]]"mkr_KD5_2", --[[3]]"mkr_KD5_3"} t_KD6_patrol ={--[[1]]"mkr_KD6_1", --[[2]]"mkr_KD6_2", --[[3]]"mkr_KD6_3", --[[4]]"mkr_KD6_4", --[[5]]"mkr_KD6_5"} t_KD_patroltables = {--[[1]]t_KD1_patrol, --[[2]]t_KD2_patrol, --[[3]]t_KD3_patrol, --[[4]]t_KD4_patrol, --[[5]]t_KD5_patrol, --[[6]]t_KD6_patrol}

for i = 1, 6 do

	if SGroup_Exists("sg_KhorneDefiler"..i) and SGroup_IsEmpty("sg_KhorneDefiler"..i) == false then
		
		if t_reverse_table[i] == false then
			
			local maxsize = table.getn(t_KD_patroltables[i])
			for k = 1, maxsize do
			
				if Prox_AnySquadNearMarker("sg_KhorneDefiler"..i, t_KD_patroltables[i][k]) then
	
					if k == maxsize then
				
						t_reverse_table[i] = true
						
						j = k - 1
						Cmd_AttackMoveMarker("sg_KhorneDefiler"..i, t_KD_patroltables[i][j])
				
					else
				
						j = k + 1
						Cmd_AttackMoveMarker("sg_KhorneDefiler"..i, t_KD_patroltables[i][j])
					
					end
					break
				end
			end
	
		elseif t_reverse_table[i] == true then
		
			local maxsize = table.getn(t_KD_patroltables[i])
			for k = 1, maxsize do
			
				if Prox_AnySquadNearMarker("sg_KhorneDefiler"..i, t_KD_patroltables[i][k]) then
	
					if k == 1 then
				
						t_reverse_table[i] = false
						
						j = k + 1
						Cmd_AttackMoveMarker("sg_KhorneDefiler"..i, t_KD_patroltables[i][j])
				
					else
				
						j = k - 1
						Cmd_AttackMoveMarker("sg_KhorneDefiler"..i, t_KD_patroltables[i][j])
					
					end
					break
				end
			end
		end
	end

end

end

--patrol inside the bastion

function Rule_Inner_Bastion_Patrol1()

if SGroup_Exists("sg_CM_Bastion1") and SGroup_IsEmpty("sg_CM_Bastion1") == false then

	if Prox_AnySquadNearMarker("sg_CM_Bastion1", "mkr_Bastion1_P1") and Squad_IsUnderAttack(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion1"), 1)) == false then
	
		Cmd_AttackMoveMarker("sg_CM_Bastion1", "mkr_Bastion1_P2")
		
	elseif Prox_AnySquadNearMarker("sg_CM_Bastion1", "mkr_Bastion1_P2") and Squad_IsUnderAttack(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion1"), 1)) == false then

		Cmd_AttackMoveMarker("sg_CM_Bastion1", "mkr_Bastion1_P1")
		
	end

else

	Rule_Remove(Rule_Inner_Bastion_Patrol1)

end

end

function Rule_Inner_Bastion_Patrol2()

if SGroup_Exists("sg_CM_Bastion2") and SGroup_IsEmpty("sg_CM_Bastion2") == false then

	if Prox_AnySquadNearMarker("sg_CM_Bastion2", "mkr_Bastion2_P1") and Squad_IsUnderAttack(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion2"), 1)) == false then
	
		Cmd_AttackMoveMarker("sg_CM_Bastion2", "mkr_Bastion2_P2")
		
	elseif Prox_AnySquadNearMarker("sg_CM_Bastion2", "mkr_Bastion2_P2") and Squad_IsUnderAttack(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion2"), 1)) == false then

		Cmd_AttackMoveMarker("sg_CM_Bastion2", "mkr_Bastion2_P1")
		
	end

else

	Rule_Remove(Rule_Inner_Bastion_Patrol2)

end

end

function Rule_Inner_Bastion_Patrol3()

if SGroup_Exists("sg_CM_Bastion3") and SGroup_IsEmpty("sg_CM_Bastion3") == false then

	if Prox_AnySquadNearMarker("sg_CM_Bastion3", "mkr_Bastion3_P1") and Squad_IsUnderAttack(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion3"), 1)) == false then
	
		Cmd_AttackMoveMarker("sg_CM_Bastion3", "mkr_Bastion3_P2")
		
	elseif Prox_AnySquadNearMarker("sg_CM_Bastion3", "mkr_Bastion3_P2") and Squad_IsUnderAttack(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_CM_Bastion3"), 1)) == false then

		Cmd_AttackMoveMarker("sg_CM_Bastion3", "mkr_Bastion3_P1")
		
	end

else

	Rule_Remove(Rule_Inner_Bastion_Patrol3)

end

end


--[[these are all in seperate functions to give more randomness]] --static random movement in the bastion function Rule_Defiler_Static_Movement()

if SGroup_Exists("sg_CM_Bastion5") and SGroup_IsEmpty("sg_CM_Bastion5") == false then

	Util_AttackMoveMarkerRandomRadius("sg_CM_Bastion5", "mkr_Bastion5")

else

	Rule_Remove(Rule_Defiler_Static_Movement)

end

end

function Rule_Defiler_Static_Movement2()

if SGroup_Exists("sg_CM_Bastion6") and SGroup_IsEmpty("sg_CM_Bastion6") == false then

	Util_AttackMoveMarkerRandomRadius("sg_CM_Bastion6", "mkr_Bastion6")

else

	Rule_Remove(Rule_Defiler_Static_Movement2)

end

end

function Rule_Defiler_Static_Movement3()

if SGroup_Exists("sg_CM_Bastion10") and SGroup_IsEmpty("sg_CM_Bastion10") == false then

	Util_AttackMoveMarkerRandomRadius("sg_CM_Bastion10", "mkr_Bastion10")

else

	Rule_Remove(Rule_Defiler_Static_Movement3)

end

end

function Rule_Defiler_Static_Movement4()

if SGroup_Exists("sg_CM_Bastion11") and SGroup_IsEmpty("sg_CM_Bastion11") == false then

	Util_AttackMoveMarkerRandomRadius("sg_CM_Bastion11", "mkr_Bastion11")

else

	Rule_Remove(Rule_Defiler_Static_Movement4)

end

end

function Rule_Defiler_Static_Movement5()

if SGroup_Exists("sg_CM_Bastion12") and SGroup_IsEmpty("sg_CM_Bastion12") == false then

	Util_AttackMoveMarkerRandomRadius("sg_CM_Bastion12", "mkr_Bastion12")

else

	Rule_Remove(Rule_Defiler_Static_Movement5)

end

end

function Rule_Defiler_Static_Movement6()

if SGroup_Exists("sg_CM_Bastion17") and SGroup_IsEmpty("sg_CM_Bastion17") == false then

	Util_AttackMoveMarkerRandomRadius("sg_CM_Bastion17", "mkr_Bastion17")

else

	Rule_Remove(Rule_Defiler_Static_Movement6)

end

end

--static random movement in the relic area

function Rule_Relic_Static_Movement()

if SGroup_Exists("sg_CM_Relic2") and SGroup_IsEmpty("sg_CM_Relic2") == false then

	Util_AttackMoveMarkerRandomRadius("sg_CM_Relic2", "mkr_Khorne_Defender2")

else

	Rule_Remove(Rule_Relic_Static_Movement)

end

end

function Rule_Relic_Static_Movement2()

if SGroup_Exists("sg_CM_Relic3") and SGroup_IsEmpty("sg_CM_Relic3") == false then

	Util_AttackMoveMarkerRandomRadius("sg_CM_Relic3", "mkr_Khorne_Defender3")

else

	Rule_Remove(Rule_Relic_Static_Movement2)

end

end

function Rule_Relic_Static_Movement3()

if SGroup_Exists("sg_CM_Relic4") and SGroup_IsEmpty("sg_CM_Relic4") == false then

	Util_AttackMoveMarkerRandomRadius("sg_CM_Relic4", "mkr_Khorne_Defender4")

else

	Rule_Remove(Rule_Relic_Static_Movement3)

end

end

function Rule_Relic_Static_Movement4()

if SGroup_Exists("sg_CM_Relic6") and SGroup_IsEmpty("sg_CM_Relic6") == false then

	Util_AttackMoveMarkerRandomRadius("sg_CM_Relic6", "mkr_Khorne_Defender6")

else

	Rule_Remove(Rule_Relic_Static_Movement4)

end

end

--static random in the right rear base

function Rule_RR_Static_Movement()

if SGroup_Exists("sg_CM_RR1") and SGroup_IsEmpty("sg_CM_RR1") == false then

	Util_AttackMoveMarkerRandomRadius("sg_CM_RR1", "mkr_RR1")

else

	Rule_Remove(Rule_RR_Static_Movement)

end

end

function Rule_RR_Static_Movement2()

if SGroup_Exists("sg_CM_RR2") and SGroup_IsEmpty("sg_CM_RR2") == false then

	Util_AttackMoveMarkerRandomRadius("sg_CM_RR2", "mkr_RR2")

else

	Rule_Remove(Rule_RR_Static_Movement2)

end

end

function Rule_RR_Static_Movement3()

if SGroup_Exists("sg_CM_RR3") and SGroup_IsEmpty("sg_CM_RR3") == false then

	Util_AttackMoveMarkerRandomRadius("sg_CM_RR3", "mkr_RR3")

else

	Rule_Remove(Rule_RR_Static_Movement3)

end

end

function Rule_RR_Static_Movement4()

if SGroup_Exists("sg_CM_RR4") and SGroup_IsEmpty("sg_CM_RR4") == false then

	Util_AttackMoveMarkerRandomRadius("sg_CM_RR4", "mkr_RR4")

else

	Rule_Remove(Rule_RR_Static_Movement4)

end

end

function Rule_RR_Static_Movement5()

if SGroup_Exists("sg_CM_RR5") and SGroup_IsEmpty("sg_CM_RR5") == false then

	Util_AttackMoveMarkerRandomRadius("sg_CM_RR5", "mkr_RR5")

else

	Rule_Remove(Rule_RR_Static_Movement5)

end

end

function Rule_RR_Static_Movement6()

if SGroup_Exists("sg_CM_RR6") and SGroup_IsEmpty("sg_CM_RR6") == false then

	Util_AttackMoveMarkerRandomRadius("sg_CM_RR6", "mkr_RR6")

else

	Rule_Remove(Rule_RR_Static_Movement6)

end

end

function Rule_RR_Static_Movement7()

if SGroup_Exists("sg_CM_RR7") and SGroup_IsEmpty("sg_CM_RR7") == false then

	Util_AttackMoveMarkerRandomRadius("sg_CM_RR7", "mkr_RR7")

else

	Rule_Remove(Rule_RR_Static_Movement7)

end

end

function Rule_RR_Static_Movement8()

if SGroup_Exists("sg_CM_RR8") and SGroup_IsEmpty("sg_CM_RR8") == false then

	Util_AttackMoveMarkerRandomRadius("sg_CM_RR8", "mkr_RR8")

else

	Rule_Remove(Rule_RR_Static_Movement8)

end

end

--static movement for the area immediatly north of the player's starting spot

function Rule_Right_Static_Movement()

if SGroup_Exists("sg_CM_Right_Barrack1") and SGroup_IsEmpty("sg_CM_Right_Barrack1") == false then

	Util_AttackMoveMarkerRandomRadius("sg_CM_Right_Barrack1", "mkr_Barrack_Right1")

else

	Rule_Remove(Rule_Right_Static_Movement)

end

end

function Rule_Right_Static_Movement2()

if SGroup_Exists("sg_CM_Right_Barrack2") and SGroup_IsEmpty("sg_CM_Right_Barrack2") == false then

	Util_AttackMoveMarkerRandomRadius("sg_CM_Right_Barrack2", "mkr_Barrack_Right2")

else

	Rule_Remove(Rule_Right_Static_Movement2)

end

end

function Rule_Right_Static_Movement3()

if SGroup_Exists("sg_CM_Right_Barrack3") and SGroup_IsEmpty("sg_CM_Right_Barrack3") == false then

	Util_AttackMoveMarkerRandomRadius("sg_CM_Right_Barrack3", "mkr_Barrack_Right3")

else

	Rule_Remove(Rule_Right_Static_Movement3)

end

end

function Rule_Right_Static_Movement4()

if SGroup_Exists("sg_CM_Right_Barrack4") and SGroup_IsEmpty("sg_CM_Right_Barrack4") == false then

	Util_AttackMoveMarkerRandomRadius("sg_CM_Right_Barrack4", "mkr_Barrack_Right4")

else

	Rule_Remove(Rule_Right_Static_Movement4)

end

end

function Rule_Right_Static_Movement5()

if SGroup_Exists("sg_CM_Right_Barrack5") and SGroup_IsEmpty("sg_CM_Right_Barrack5") == false then

	Util_AttackMoveMarkerRandomRadius("sg_CM_Right_Barrack5", "mkr_Barrack_Right5")

else

	Rule_Remove(Rule_Right_Static_Movement5)

end

end

--static movement for the left bridge area

function Rule_Left_Bridge_Static_Movement()

if SGroup_Exists("sg_CM_LB1") and SGroup_IsEmpty("sg_CM_LB1") == false then

	Util_AttackMoveMarkerRandomRadius("sg_CM_LB1", "mkr_Bridge_Left1")

else

	Rule_Remove(Rule_Left_Bridge_Static_Movement)

end

end

function Rule_Left_Bridge_Static_Movement2()

if SGroup_Exists("sg_CM_LB2") and SGroup_IsEmpty("sg_CM_LB2") == false then

	Util_AttackMoveMarkerRandomRadius("sg_CM_LB2", "mkr_Bridge_Left2")

else

	Rule_Remove(Rule_Left_Bridge_Static_Movement2)

end

end

function Rule_Left_Bridge_Static_Movement3()

if SGroup_Exists("sg_CM_LB3") and SGroup_IsEmpty("sg_CM_LB3") == false then

	Util_AttackMoveMarkerRandomRadius("sg_CM_LB3", "mkr_Bridge_Left3")

else

	Rule_Remove(Rule_Left_Bridge_Static_Movement3)

end

end

function Rule_Left_Bridge_Static_Movement4()

if SGroup_Exists("sg_CM_LB4") and SGroup_IsEmpty("sg_CM_LB4") == false then

	Util_AttackMoveMarkerRandomRadius("sg_CM_LB4", "mkr_Bridge_Left4")

else

	Rule_Remove(Rule_Left_Bridge_Static_Movement4)

end

end

function Rule_Left_Bridge_Static_Movement5()

if SGroup_Exists("sg_CM_LB5") and SGroup_IsEmpty("sg_CM_LB5") == false then

	Util_AttackMoveMarkerRandomRadius("sg_CM_LB5", "mkr_Bridge_Left5")

else

	Rule_Remove(Rule_Left_Bridge_Static_Movement5)

end

end

--[[ Util functions ]]

--[[ --this is a function to make units that are stationary appear more life like by having them move around within the confines of a marker function Util_AttackMoveMarkerRandomRadius( squadgroupname, markername)

	local pos = Marker_GetPosition( Marker_FromName( markername, "basic_marker" ) )
	local prox = Marker_GetProximity( Marker_FromName( markername, "basic_marker" ) )
	
	
	local xrand = World_GetRand( -prox, prox ) 
	local zrand = World_GetRand( -prox, prox ) 
		
			
	local attackpos = World_Pos( xrand + pos.x, pos.y, zrand + pos.z )

	
	Cmd_AttackMovePos(squadgroupname, attackpos)
	

end]]


--[[ OBJECTIVES ]]

--[[Primary Objective - Destroy the Chaos Gate]] function Rule_Objective_Kill_Sorcerer()

Objective_Kill_Sorcerer = {title_id = 2520000, short_desc_id = 2520001, help_tip_id = 2520000}

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Kill_Sorcerer.title_id) == false then
	
	Util_WXP_ObjectiveCreate(Objective_Kill_Sorcerer, true, g_Player1)
	
	Objective_ShowScreen()
	Flash_OtherButton("dlg_objectives", 0, false, true)
	
	--[[adding map and mini-map pings]]
	g_ping_hq = Objective_PingMarker(Objective_Kill_Sorcerer.title_id, "mkr_Sorcerer_Ping", true, "default")
	g_ping_hq_mini = Ping_Marker("mkr_Sorcerer_Ping", true, "default")
	
	Rule_AddOneShot(Rule_Stop_HQ_Ping, 5)
	
elseif Event_IsAnyRunning() == false and g_Win == true then 

	--[[removing map and mini-map pings]]
	Objective_PingRemove(Objective_Kill_Sorcerer.title_id, g_ping_hq)
	
	Util_ObjectiveComplete(Objective_Kill_Sorcerer.title_id)
	Rule_Remove(Rule_Objective_Kill_Sorcerer)
	
	--[[game is won]]
	Fade_Start(4, false)
	World_SetTeamWin( g_Player1, "" )
	Rule_AddIntervalEx( Rule_GameOver,5,1 )
		
	
end

end

function Rule_Stop_HQ_Ping()

Ping_Stop(g_ping_hq_mini)

end

--[[Secondary Objective - stop Blood Pulse]] function Rule_Objective_Stop_Pulse()

Objective_Stop_Pulse = {title_id = 2520100, short_desc_id = 2520101, help_tip_id = 2520100}

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Stop_Pulse.title_id) == false then
	
	Util_WXP_ObjectiveCreate(Objective_Stop_Pulse, false, g_Player1)
	Objective_ShowScreen()
	Flash_OtherButton("dlg_objectives", 0, false, true)
	
	--[[adding map and mini-map pings]]
	g_ping_Blood = Objective_PingMarker(Objective_Stop_Pulse.title_id, "mkr_Blood_Pit_Ping", true, "default")
	g_ping_Blood_mini = Ping_Marker("mkr_Blood_Pit_Ping", true, "default")
	
	Rule_AddOneShot(Rule_Stop_Blood_Ping, 5)
	
	--[[Set up the Pulse]]
	Rule_AddOneShot(Rule_Set_Counter, 1)
	
elseif Event_IsAnyRunning() == false and g_PulseStop == true then 

	--[[removing map and mini-map pings]]
	Objective_PingRemove(Objective_Stop_Pulse.title_id, g_ping_Blood)
	
	Util_ObjectiveComplete(Objective_Stop_Pulse.title_id)
	Rule_Remove(Rule_Objective_Stop_Pulse)
	
	
end

end

function Rule_Stop_Blood_Ping()

Ping_Stop(g_ping_Blood_mini)

end


--[[Secondary Objective - Rescue prisoners]] function Rule_Objective_Rescue_Prisoners()

Objective_Rescue_Prisoners = {title_id = 2520200, short_desc_id = 2520201, help_tip_id = 2520200}

if Event_IsAnyRunning() == false and Objective_Exists(Objective_Rescue_Prisoners.title_id) == false then
	
	Util_WXP_ObjectiveCreate(Objective_Rescue_Prisoners, false, g_Player1)
	Objective_ShowScreen()
	Flash_OtherButton("dlg_objectives", 0, false, true)
	
	--[[adding map and mini-map pings]]
	g_ping_Prisoners = Objective_PingMarker(Objective_Rescue_Prisoners.title_id, "mkr_Jailer", true, "default")
	g_ping_Prisoners_mini = Ping_Marker("mkr_Jailer", true, "default")
	
	Rule_AddOneShot(Rule_Stop_Prisoner_Ping, 5)
	
	
elseif Event_IsAnyRunning() == false and g_PrisonersStop == true then 

	--[[removing map and mini-map pings]]
	Objective_PingRemove(Objective_Rescue_Prisoners.title_id, g_ping_Prisoners)
	
	Util_ObjectiveComplete(Objective_Rescue_Prisoners.title_id)
	Rule_Remove(Rule_Objective_Rescue_Prisoners)
	
	
end

end

function Rule_Stop_Prisoner_Ping()

Ping_Stop(g_ping_Prisoners_mini)

end

--[[ Gate of Chaos ]]

function Rule_Summon_Chaos_Reinforcements()

Anim_PlaySGroupAnim(SGroup_FromName("sg_Sorcerer1"), "doombolt")
Anim_PlaySGroupAnim(SGroup_FromName("sg_Sorcerer2"), "doombolt")

Rule_AddOneShot(Rule_Open_Gate, 4)

end

function Rule_Open_Gate()

Rule_AddIntervalDelay(Rule_Summon_Reinforcements, 1, 15)

end

function Rule_Reinforcement_Level()

if g_Increment <= 10 then
	
	g_Reinforcements = g_Reinforcements +1
	g_Increment = g_Increment +1
			

elseif g_Increment <= 20 then
	
	g_Reinforcements = g_Reinforcements +1
	g_Increment = g_Increment +1

elseif g_Increment <= 30 then
	
	g_Reinforcements = g_Reinforcements +1
	g_Increment = g_Increment +1

elseif g_Increment <= 40 then
	
	g_Reinforcements = g_Reinforcements +1
	g_Increment = g_Increment +1

elseif g_Increment <= 50 then
	
	Rule_Remove(Rule_Reinforcement_Level)

end

end

function Rule_Summon_Reinforcements()

if g_Reinforcements == 1 then
	
	t_Reinforce_Army = {
		
		sgroup_name = { --[[1]]"sg_CM_Raid1", --[[2]]"sg_CM_Raid2", --[[3]]"sg_CM_Raid3", --[[4]]"sg_CM_Raid4", --[[5]]"sg_CM_Raid5"},  
		
		blueprint = {--[[1]]"chaos_squad_cultist", --[[2]]"chaos_squad_cultist", --[[3]]"chaos_marine_squad_stronghold_sp", --[[4]]"chaos_marine_squad_stronghold_sp", 
		--[[5]]"chaos_marine_squad_stronghold_sp"},
		
		marker_spawn = {--[[1]]"mkr_Chaos_Summoning", --[[2]]"mkr_Chaos_Summoning", --[[3]]"mkr_Chaos_Summoning", --[[4]]"mkr_Chaos_Summoning", --[[5]]"mkr_Chaos_Summoning"}, 
		
		squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1}, 
		
		squad_size = {--[[1]] 5, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1}, 
		
	}
elseif g_Reinforcements == 2 then

	t_Reinforce_Army = {
		
		sgroup_name = { --[[1]]"sg_CM_Raid1", --[[2]]"sg_CM_Raid2", --[[3]]"sg_CM_Raid3", --[[4]]"sg_CM_Raid4", --[[5]]"sg_CM_Raid5"},  
		
		blueprint = {--[[1]]"chaos_squad_cultist", --[[2]]"chaos_squad_cultist", --[[3]]"chaos_marine_squad_stronghold_sp", --[[4]]"chaos_marine_squad_stronghold_sp", 
		--[[5]]"chaos_marine_squad_stronghold_sp"},
		
		marker_spawn = {--[[1]]"mkr_Chaos_Summoning", --[[2]]"mkr_Chaos_Summoning", --[[3]]"mkr_Chaos_Summoning", --[[4]]"mkr_Chaos_Summoning", --[[5]]"mkr_Chaos_Summoning"}, 
		
		squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1}, 
		
		squad_size = {--[[1]] 4, --[[2]] 4, --[[3]] 1, --[[4]] 2, --[[5]] 2}, 
		
	}
elseif g_Reinforcements == 3 then

	t_Reinforce_Army = {
		
		sgroup_name = { --[[1]]"sg_CM_Raid1", --[[2]]"sg_CM_Raid2", --[[3]]"sg_CM_Raid3", --[[4]]"sg_CM_Raid4", --[[5]]"sg_CM_Raid5"},  
		
		blueprint = {--[[1]]"chaos_squad_cultist", --[[2]]"chaos_marine_squad_stronghold_sp", --[[3]]"chaos_marine_squad_stronghold_sp", 
		--[[4]]"chaos_marine_squad_stronghold_sp", --[[5]]"chaos_marine_squad_stronghold_sp"},
		
		marker_spawn = {--[[1]]"mkr_Chaos_Summoning", --[[2]]"mkr_Chaos_Summoning", --[[3]]"mkr_Chaos_Summoning", --[[4]]"mkr_Chaos_Summoning", --[[5]]"mkr_Chaos_Summoning"}, 
		
		squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1}, 
		
		squad_size = {--[[1]] 4, --[[2]] 1, --[[3]] 1, --[[4]] 2, --[[5]] 2}, 
		
	}
elseif g_Reinforcements == 4 then

	t_Reinforce_Army = {
		
		sgroup_name = { --[[1]]"sg_CM_Raid1", --[[2]]"sg_CM_Raid2", --[[3]]"sg_CM_Raid3", --[[4]]"sg_CM_Raid4", --[[5]]"sg_CM_Raid5"},  
		
		blueprint = {--[[1]]"chaos_squad_horror", --[[2]]"chaos_squad_horror", 
		--[[3]]"chaos_marine_squad_stronghold_sp", --[[4]]"chaos_squad_possessed_marine_advance_sp", --[[5]]"chaos_marine_squad_stronghold_sp"},
		
		marker_spawn = {--[[1]]"mkr_Chaos_Summoning", --[[2]]"mkr_Chaos_Summoning", --[[3]]"mkr_Chaos_Summoning", --[[4]]"mkr_Chaos_Summoning", --[[5]]"mkr_Chaos_Summoning"}, 
		
		squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1}, 
		
		squad_size = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 2, --[[5]] 2}, 
		
	}
	
elseif 	g_Reinforcements == 5 then

	t_Reinforce_Army = {
		
		sgroup_name = { --[[1]]"sg_CM_Raid1", --[[2]]"sg_CM_Raid2", --[[3]]"sg_CM_Raid3", --[[4]]"sg_CM_Raid4", --[[5]]"sg_CM_Raid5"},  
		
		blueprint = {--[[1]]"chaos_squad_horror", --[[2]]"chaos_squad_khorne_berserker_stronghold_sp", --[[3]]"chaos_squad_horror", --[[4]]"chaos_marine_squad_stronghold_sp", 
		--[[5]]"chaos_squad_possessed_marine_advance_sp"},
		
		marker_spawn = {--[[1]]"mkr_Chaos_Summoning", --[[2]]"mkr_Chaos_Summoning", --[[3]]"mkr_Chaos_Summoning", --[[4]]"mkr_Chaos_Summoning", --[[5]]"mkr_Chaos_Summoning"}, 
		
		squad_num = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 1}, 
		
		squad_size = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1, --[[5]] 2}, 
		
	}
end


local i = g_Reinforce_Army_iter 
if g_Reinforce_Army_iter <= table.getn(t_Reinforce_Army.sgroup_name) and (SGroup_Exists(t_Reinforce_Army.sgroup_name[i]) == false or SGroup_IsEmpty(t_Reinforce_Army.sgroup_name[i])) then
	local sgroupID = Util_CreateSquadsAtMarkerEx(g_Player2, t_Reinforce_Army.sgroup_name[i], t_Reinforce_Army.blueprint[i], t_Reinforce_Army.marker_spawn[i], t_Reinforce_Army.squad_num[i], t_Reinforce_Army.squad_size[i])
	World_FXEventSquad("data:Art/Events/Unit_Upgrade_Morale_FX/Reinforce_Trooper", SGroup_FromName(t_Reinforce_Army.sgroup_name[i]))
	
	Cmd_SetStance(t_Reinforce_Army.sgroup_name[i], STANCE_Hold)
	Cmd_AttackMoveMarker(t_Reinforce_Army.sgroup_name[i], "mkr_Player_HQ")

	--prevent AI from using these units
	Cpu_LockSGroupAcrossPlayers(t_Bastion_Army.sgroup_name[i])

		--this will add a leader after Xmn of gameplay to the raiding parties
		if g_Timer >= 20 then
		
			Cmd_ReinforceLeader(t_Reinforce_Army.sgroup_name[i], 1)
		
		end
	
	
	
elseif g_Reinforce_Army_iter > table.getn(t_Bastion_Army.sgroup_name) then
		g_Reinforce_Army_iter = 0
		
		--Rule_AddOneShot(Rule_Summon_Chaos_Reinforcements_Close, 5)
		Rule_Remove(Rule_Summon_Reinforcements)
				
end
g_Reinforce_Army_iter = g_Reinforce_Army_iter+1

end


--[[Blood Pulse Scar]]

--this is the rule that sets up the pulse on the map. Each time the pulse hits any player units near one of the towers will die.

function Rule_Set_Counter()

--creating the counter g_Counter is set at 40 for the moment
UI_ShowCountDXP("BloodPulse", g_Player1, 2530000, g_Counter )

Rule_AddInterval(Rule_Pulse_Warning, 1)
Rule_AddInterval(Rule_Pulse_Halt, 1)

end

function Rule_Pulse_Warning()

--counting down from 30 to 0
g_Counter = g_Counter -1
UI_ShowCountUpdateDxp("BloodPulse", g_Counter, 2530000)
	
	--once you hit 0 the pulse fires
	
	if g_Counter == 10 then
	
		--this will play the warning laugh
		Anim_PlayEGroupAnim(EGroup_FromName("eg_Blood_Warning"), "audio_warning")
	

	end
	
	
	if g_Counter == 0 then
		Rule_AddOneShot(Rule_Blood_Pulse_Effect, 0.5)
		Rule_AddOneShot(Rule_Blood_Pulse, 1)
		Rule_Remove(Rule_Pulse_Warning)

				
	end

end

function Rule_Blood_Pulse_Effect()

for i = 1, 6 do
	Util_MarkerFX("mkr_Pulse"..i, "data:Art/Events/Chaos/Blood_Pulse")

end
	

end

function Rule_Blood_Pulse() --units that should be ignored by the blood pulse t_Vehicle = Util_MakeBlueprintTable(--[[eldar]]"eldar_squad_farseer", "eldar_squad_farseer_advance_sp","eldar_squad_farseer_sp","eldar_squad_farseer_stronghold_sp", "eldar_squad_avatar","eldar_squad_falcon_grav_tank", "eldar_squad_falcon_grav_tank_advance_sp", "eldar_squad_fire_prism","eldar_squad_grav_platform", "eldar_squad_grav_platform_brightlance", "eldar_squad_grav_platform_brightlance_advance_sp","eldar_squad_vypers", "eldar_squad_vypers_advance_sp", "eldar_squad_wraithlord", "eldar_squad_wraithlord_advance_sp",

--[[IG]]"guard_squad_command_squad", "guard_squad_command_squad_advance_sp", "guard_squad_baneblade", "guard_squad_basilisk","guard_squad_basilisk_sp_mso2", "guard_squad_chimera","guard_squad_chimera_sp_test","guard_squad_hellhound", "guard_squad_hellhound_advance_sp", "guard_squad_lemanruss", "guard_squad_sentinel", "guard_squad_sentinel_advance_sp",

--[[ork]]"ork_squad_warboss", "ork_squad_warboss_advance_sp", "ork_squad_warboss_sp_md2", "ork_squad_warboss_stronghold_sp","ork_squad_killa_kan", "ork_squad_killa_kan_advance_sp", "ork_squad_looted_tank", "ork_squad_looted_tank_sp", "ork_squad_squiggoth", "ork_squad_squiggoth_sp_long_rampage","ork_squad_trukk", "ork_squad_trukk_advance_sp","ork_squad_wartrak", "ork_squad_wartrak_advance_sp",

--[[space marine]]"space_marine_squad_force_commander", "space_marine_squad_force_commander_advance_sp", "space_marine_squad_dreadnought", "space_marine_squad_dreadnought_advance_sp", "space_marine_squad_dreadnought_hellfire","space_marine_squad_dreadnought_hellfire_advance_sp", "space_marine_squad_land_raider", "space_marine_squad_land_speeder", "space_marine_squad_land_speeder_advance_sp","space_marine_squad_predator", "space_marine_squad_rhino", "space_marine_squad_skull_probe", "space_marine_squad_whirlwind",

--[[Tau]] "tau_devilfish_troop_carrier", "tau_drone_harbinger_squad", "tau_drone_harbinger_squad_advance_sp", "tau_drone_squad", "tau_ethereal_squad", "tau_ethereal_squad_stronghold_sp", "tau_hammerhead_gunship_squad", "tau_skyray_squad", "tau_skyray_squad_advance_sp", "tau_greater_knarloc_squad", "tau_broadside_battlesuit_squad", "tau_broadside_battlesuit_squad_clone_sp", "tau_commander_squad", "tau_commander_squad_advance_sp",

--[[Necron]]"necron_night_bringer", "necron_restored_monolith_squad", "necron_destroyer_squad", "necron_destroyer_squad_advance_sp", "necron_heavy_destroyer_squad", "necron_lord_destroyer_squad", "necron_lord_squad", "necron_lord_squad_advance_sp", "necron_tomb_spyder_squad", "necron_tomb_spyder_squad_advance_sp")

for i = 1, 6 do

	if Player_AreSquadsNearMarker(g_Player1, "mkr_Pulse"..i) then
		
		--clean up the group to make sure nothing odd happens
		SGroup_Clear(SGroup_CreateIfNotFound("sg_Sacrifice"..i))
		
		--get all the player's units near that specific pulse tower and place them in a specific group
		Player_GetAllSquadsNearMarker(g_Player1, "sg_Sacrifice"..i, "mkr_Pulse"..i)
		count = SGroup_Count(SGroup_FromName("sg_Sacrifice" ..i))

			for j =1, count do

				SGroup_Clear(SGroup_CreateIfNotFound("sg_Potentials"..j))
				SGroup_Add(SGroup_FromName("sg_Potentials"..j), SGroup_GetSpawnedSquadAt("sg_Sacrifice"..i, j))

				--check to see if the group does not contain any of the forbidden units.
				if SGroup_ContainsBlueprints("sg_Potentials"..j, t_Vehicle, false) == false then
					
					--give them to the sacrifice player
					SGroup_SetPlayerOwner("sg_Potentials"..j, g_Player4)
					
					--stop them from going anywhere
					Cmd_StopSquads("sg_Potentials"..j)
					
					--play a suitably gruesome animation
					if MetaMap_GetPlayerRaceName() == "necron_race" then
						World_FXEventSquad("data:Art/Events/Chaos/Blood_Pulse_Hit", SGroup_FromName("sg_Potentials"..j))
					else
						
						World_FXEventSquad("data:Art/Events/Chaos/Blood_Pulse_Hit", SGroup_FromName("sg_Potentials"..j))
					
					end
					
					--kill the units
					SGroup_SelfDestroy("sg_Potentials"..j, true)
		
				
				end
		end

	end
end

g_Counter = 41
Rule_AddInterval(Rule_Pulse_Warning, 1)

end

--[[Blood pulse nis]] --special rule for the intro nis which is seperate from the regular pulse. It is a one shot and doesn't re-add the loop nor trigger the timer. function Rule_Blood_Pulse_Nis() --vehicles that should be ignored by the blood pulse t_Vehicle = Util_MakeBlueprintTable(--[[eldar]]"eldar_squad_farseer", "eldar_squad_farseer_advance_sp","eldar_squad_farseer_sp","eldar_squad_farseer_stronghold_sp", "eldar_squad_avatar","eldar_squad_falcon_grav_tank", "eldar_squad_falcon_grav_tank_advance_sp", "eldar_squad_fire_prism","eldar_squad_grav_platform", "eldar_squad_grav_platform_brightlance", "eldar_squad_grav_platform_brightlance_advance_sp","eldar_squad_vypers", "eldar_squad_vypers_advance_sp", "eldar_squad_wraithlord", "eldar_squad_wraithlord_advance_sp",

--[[IG]]"guard_squad_command_squad", "guard_squad_command_squad_advance_sp", "guard_squad_baneblade", "guard_squad_basilisk","guard_squad_basilisk_sp_mso2", "guard_squad_chimera","guard_squad_chimera_sp_test","guard_squad_hellhound", "guard_squad_hellhound_advance_sp", "guard_squad_lemanruss", "guard_squad_sentinel", "guard_squad_sentinel_advance_sp",

--[[ork]]"ork_squad_warboss", "ork_squad_warboss_advance_sp", "ork_squad_warboss_sp_md2", "ork_squad_warboss_stronghold_sp","ork_squad_killa_kan", "ork_squad_killa_kan_advance_sp", "ork_squad_looted_tank", "ork_squad_looted_tank_sp", "ork_squad_squiggoth", "ork_squad_squiggoth_sp_long_rampage","ork_squad_trukk", "ork_squad_trukk_advance_sp","ork_squad_wartrak", "ork_squad_wartrak_advance_sp",

--[[space marine]]"space_marine_squad_force_commander", "space_marine_squad_force_commander_advance_sp", "space_marine_squad_dreadnought", "space_marine_squad_dreadnought_advance_sp", "space_marine_squad_dreadnought_hellfire","space_marine_squad_dreadnought_hellfire_advance_sp", "space_marine_squad_land_raider", "space_marine_squad_land_speeder", "space_marine_squad_land_speeder_advance_sp","space_marine_squad_predator", "space_marine_squad_rhino", "space_marine_squad_skull_probe", "space_marine_squad_whirlwind",

--[[Tau]] "tau_devilfish_troop_carrier", "tau_drone_harbinger_squad", "tau_drone_harbinger_squad_advance_sp", "tau_drone_squad", "tau_ethereal_squad", "tau_ethereal_squad_stronghold_sp", "tau_hammerhead_gunship_squad", "tau_skyray_squad", "tau_skyray_squad_advance_sp", "tau_greater_knarloc_squad", "tau_broadside_battlesuit_squad", "tau_broadside_battlesuit_squad_clone_sp", "tau_commander_squad", "tau_commander_squad_advance_sp",

--[[Necron]]"necron_night_bringer", "necron_restored_monolith_squad", "necron_destroyer_squad", "necron_destroyer_squad_advance_sp", "necron_heavy_destroyer_squad", "necron_lord_destroyer_squad", "necron_lord_squad", "necron_lord_squad_advance_sp", "necron_tomb_spyder_squad", "necron_tomb_spyder_squad_advance_sp")

for i = 1, 6 do
--	Util_MarkerFX("mkr_Pulse"..i, "data:Art/Events/Chaos/Blood_Pulse")
	if Player_AreSquadsNearMarker(g_Player1, "mkr_Pulse"..i) then
		
		--clean up the group to make sure nothing odd happens
		SGroup_Clear(SGroup_CreateIfNotFound("sg_Sacrifice"..i))
		
		--get all the player's units near that specific pulse tower and place them in a specific group
		Player_GetAllSquadsNearMarker(g_Player1, "sg_Sacrifice"..i, "mkr_Pulse"..i)
		count = SGroup_Count(SGroup_FromName("sg_Sacrifice" ..i))

			for j =1, count do

				SGroup_Clear(SGroup_CreateIfNotFound("sg_Potentials"..j))
				SGroup_Add(SGroup_FromName("sg_Potentials"..j), SGroup_GetSpawnedSquadAt("sg_Sacrifice"..i, j))

				if SGroup_ContainsBlueprints("sg_Potentials"..j, t_Vehicle, false) == false then
					--give them to the sacrifice player
					SGroup_SetPlayerOwner("sg_Potentials"..j, g_Player4)
					
					--stop them from going anywhere
					Cmd_StopSquads("sg_Potentials"..j)
					
					--play a suitably gruesome animation
				--	Anim_PlaySGroupAnim(SGroup_FromName("sg_Potentials"..j), "syncdeath_2")
					if MetaMap_GetPlayerRaceName() == "necron_race" then
						World_FXEventSquad("data:Art/Events/Chaos/Blood_Pulse_Hit", SGroup_FromName("sg_Potentials"..j))
					else
						
						World_FXEventSquad("data:Art/Events/Chaos/Blood_Pulse_Hit", SGroup_FromName("sg_Potentials"..j))
					
					end
					
					SGroup_SelfDestroy("sg_Potentials"..j, true)
		
				
				end
		end

	end
end

end

--[[Stopping the pulse ]]

--Capturing the blood pit strategic point stops the pulses

function Rule_Pulse_Halt()

if EGroup_IsCapturedByPlayer("eg_Blood_Point", g_Player1, false) then

	Rule_Remove(Rule_Pulse_Warning)
	Rule_Remove(Rule_Blood_Pulse)
	
	--despawns the effect that's around the strat point.
	EGroup_DeSpawn("eg_Chaos_Star")
	
	UI_HideCount("BloodPulse")
	
	--making the objective complete
	g_PulseStop = true
	Rule_Remove(Rule_Pulse_Halt)

end

end


--[[ Raids ]]

--the following raids are set up in two different ways; some have units being sent to attack the player in the traditional fashion. For others units are spawned and then given to the AI to play with.

--Forward Base 1 function Rule_FB1_Raid()

t_FB1_Raid_Army = {
squadname = {--[[1]]"sg_FB1_Raiders1", --[[2]]"sg_FB1_Raiders2", --[[3]]"sg_FB1_Raiders3", --[[4]]"sg_FB1_Raiders4"},
squadnum = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1},
squadsize = {--[[1]] 4, --[[2]] 5, --[[3]] 6, --[[4]] 7},
reinforceleader = {--[[1]] true, --[[2]] false, --[[3]]false, --[[4]]false},
}

if EGroup_Exists("eg_FB1") and EGroup_IsEmpty("eg_FB1") == false then

	--FB1Inc can never be freater than the number of entries in the squadsize and squadnum tables.
	if g_FB1_Increment <= 5 then

		FB1Inc = 1
		
	elseif  g_FB1_Increment <= 10 then
		
		FB1Inc = 2
		
	elseif  g_FB1_Increment <= 15 then
		
		FB1Inc = 3
		
	elseif  g_FB1_Increment > 15 then
		
		FB1Inc = 4
		
	end

	local i = g_FB1_Size
	
	--checking how many squads in this group in order to prevent over population
	if SGroup_CountSpawned(SGroup_CreateIfNotFound("sg_FB1_Raid")) <= 10 then
	
		--there are two variables here "i" and "FB1Inc" they are linked to different systems. "i" incrememnts where in the spawning cycle we are for the number of squads and "FB1Inc" where we are in the difficulty cycle. The reason i am using "i' instead of a for loop
		--is that I didn't want to have four squads spawning at once and looking unfair to the player. 
		Util_CreateSquadsAtMarkerEx(g_Player2, t_FB1_Raid_Army.squadname[i], "chaos_squad_cultist", "mkr_FB1_Building1_Spawn", t_FB1_Raid_Army.squadnum[FB1Inc], t_FB1_Raid_Army.squadsize[FB1Inc])

		SGroup_AddGroup(SGroup_CreateIfNotFound("sg_FB1_Raid"), SGroup_FromName( t_FB1_Raid_Army.squadname[i]))
		
		if t_FB1_Raid_Army.reinforceleader[i] == true then
		
			Cmd_ReinforceLeader(t_FB1_Raid_Army.squadname[i], 1)
		
		end

	
		--this will add a leader after Xmn of gameplay to the raiding parties
		if g_Timer >= 20 then
		
			t_FB1_Raid_Army.reinforceleader[i] = true
		
		end
	
		if g_FB1_Size <  table.getn(t_FB1_Raid_Army.squadname) then

			g_FB1_Size = g_FB1_Size + 1
		
		elseif g_FB1_Size == table.getn(t_FB1_Raid_Army.squadname) then
		
			g_FB1_Size = 1
			
			Rule_Remove(Rule_FB1_Raid)			
			Rule_Add(Rule_FB1_Raid_Attack)
		
		end
	

		g_FB1_Increment = g_FB1_Increment +1
	end
else

	--if this raid is stopped begin the one further back
	Rule_AddIntervalDelay(Rule_RB2_Cultist_Raid, 30, 320)
	
	--check for player incursion to trigger some chatter near the relic
	Rule_AddInterval(Rule_Relic_Talk, 5)
	Rule_Remove(Rule_FB1_Raid)

end

end

--this is done in a seperate function than Rule_FB1_Raid in order to be able to to re-add Rule_FB1_Raid after a delay and not get an error about the rule still existing. function Rule_FB1_Raid_Attack()

	--checks to see if the player has an HQ and if yes to go attack it
	EGroup_Clear(EGroup_CreateIfNotFound("eg_Player1_Buildings"))
	EGroup_AddGroup(EGroup_FromName("eg_Player1_Buildings"), Player_GetEntities(g_Player1))
	
	local countbuilding = EGroup_CountSpawned(EGroup_FromName("eg_Player1_Buildings"))
	
	for i = 1, countbuilding do
	
		EGroup_Clear(EGroup_CreateIfNotFound("eg_Potential_HQ"))
		EGroup_Add(EGroup_FromName("eg_Potential_HQ"), EGroup_GetSpawnedEntityAt("eg_Player1_Buildings", i))

		if EGroup_ContainsBlueprints(EGroup_FromName("eg_Potential_HQ"), t_blueprinthq, true) then
		
			pos_HQ = Entity_GetPosition( EGroup_GetSpawnedEntityAt("eg_Potential_HQ", 1))
			Cmd_AttackMovePos("sg_FB1_Raid", pos_HQ)
			
			--at this point we want to stop the for loop
			break

		end
	end

	--this is the table in the spawning rule Rule_FB1_Raid
	for j = 1, table.getn(t_FB1_Raid_Army.squadname) do 
		--check to see if the squads are idle. if they are then it means the player has no HQ in which case they are given to the active AI player
		if SGroup_IsEmpty(t_FB1_Raid_Army.squadname[j]) == false and  
		Squad_GetActiveCommand(SGroup_GetSpawnedSquadAt(SGroup_FromName(t_FB1_Raid_Army.squadname[j]), 1)) == SQUADSTATEID_Idle then 

			Squad_SetPlayerOwner(SGroup_GetSpawnedSquadAt(SGroup_FromName(t_FB1_Raid_Army.squadname[j]), 1), g_Player3)
			
		
		end
	end
	
	--this is to prevent the squads from going back to their spawn point while en route to their attack
	for d = 1, table.getn(t_FB1_Raid_Army.squadname) do 
	
		SGroup_Clear(SGroup_FromName(t_FB1_Raid_Army.squadname[d]))
		
	end

	Rule_Remove(Rule_FB1_Raid_Attack)
	Rule_AddIntervalDelay(Rule_FB1_Raid, 30, 5)

end


--Forward Base 2 function Rule_FB2_Raid()

t_FB2_Raid_Army = {
squadname = {--[[1]]"sg_FB2_Raiders1", --[[2]]"sg_FB2_Raiders2", --[[3]]"sg_FB2_Raiders3", --[[4]]"sg_FB2_Raiders4"},
squadnum = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1},
squadsize = {--[[1]] 4, --[[2]] 5, --[[3]] 6, --[[4]] 7},
reinforceleader = {--[[1]] true, --[[2]] false, --[[3]]false, --[[4]]false},
}

if EGroup_Exists("eg_FB2_1") and EGroup_IsEmpty("eg_FB2_1") == false then

	--FB2Inc can never be freater than the number of entries in the squadsize and squadnum tables.
	if g_FB2_Increment <= 5 then

		FB2Inc = 1
		
	elseif  g_FB2_Increment <= 10 then
		
		FB2Inc = 2
		
	elseif  g_FB2_Increment <= 15 then
		
		FB2Inc = 3
		
	elseif  g_FB2_Increment > 15 then
		
		FB2Inc = 4
		
	end

	local i = g_FB2_Size
	
	--checking how many squads in this group in order to prevent over population
	if SGroup_CountSpawned(SGroup_CreateIfNotFound("sg_FB2_Raid")) <= 5 then
	
		--there are two variables here "i" and "FB2Inc" they are linked to different systems. "i" incrememnts where in the spawning cycle we are for the number of squads and "FB2Inc" where we are in the difficulty cycle. The reason i am using "i' instead of a for loop
		--is that I didn't want to have four squads spawning at once and looking unfair to the player. 
		Util_CreateSquadsAtMarkerEx(g_Player2, t_FB2_Raid_Army.squadname[i], "chaos_squad_cultist", "mkr_FB2_Building1_Spawn", t_FB2_Raid_Army.squadnum[FB2Inc], t_FB2_Raid_Army.squadsize[FB2Inc])

		SGroup_AddGroup(SGroup_CreateIfNotFound("sg_FB2_Raid"), SGroup_FromName( t_FB2_Raid_Army.squadname[i]))

		
		if t_FB2_Raid_Army.reinforceleader[i] == true then
		
			Cmd_ReinforceLeader(t_FB2_Raid_Army.squadname[i], 1)
		
		end

	
		--this will add a leader after Xmn of gameplay to the raiding parties
		if g_Timer >= 20 then
		
			t_FB2_Raid_Army.reinforceleader[i] = true
		
		end
			
		if g_FB2_Size <  table.getn(t_FB2_Raid_Army.squadname) then

			g_FB2_Size = g_FB2_Size + 1
		
		elseif g_FB2_Size == table.getn(t_FB2_Raid_Army.squadname) then
		
			g_FB2_Size = 1
			
			Rule_Remove(Rule_FB2_Raid)			
			Rule_Add(Rule_FB2_Raid_Attack)
		
		end
	

		g_FB2_Increment = g_FB2_Increment +1
	end
else

	Rule_Remove(Rule_FB2_Raid)

end

end

--this is done in a seperate function than Rule_FB2_Raid in order to be able to to re-add Rule_FB2_Raid after a delay and not get an error about the rule still existing. function Rule_FB2_Raid_Attack()

	--checks to see if the player has an HQ and if yes to go attack it
	EGroup_Clear(EGroup_CreateIfNotFound("eg_Player1_Buildings"))
	EGroup_AddGroup(EGroup_FromName("eg_Player1_Buildings"), Player_GetEntities(g_Player1))
	
	local countbuilding = EGroup_CountSpawned(EGroup_FromName("eg_Player1_Buildings"))
	
	for i = 1, countbuilding do
	
		EGroup_Clear(EGroup_CreateIfNotFound("eg_Potential_HQ"))
		EGroup_Add(EGroup_FromName("eg_Potential_HQ"), EGroup_GetSpawnedEntityAt("eg_Player1_Buildings", i))

		if EGroup_ContainsBlueprints(EGroup_FromName("eg_Potential_HQ"), t_blueprinthq, true) then
		
			pos_HQ = Entity_GetPosition( EGroup_GetSpawnedEntityAt("eg_Potential_HQ", 1))
			Cmd_AttackMovePos("sg_FB2_Raid", pos_HQ)
			

			
			--at this point we want to stop the for loop
			break

		end
	end

	--this is the table in the spawning rule Rule_FB2_Raid
	for j = 1, table.getn(t_FB2_Raid_Army.squadname) do 
		--check to see if the squads are idle. if they are then it means the player has no HQ in which case they are given to the active AI player
		if SGroup_IsEmpty(t_FB2_Raid_Army.squadname[j]) == false and
		Squad_GetActiveCommand(SGroup_GetSpawnedSquadAt(SGroup_FromName(t_FB2_Raid_Army.squadname[j]), 1)) == SQUADSTATEID_Idle then 

			Squad_SetPlayerOwner(SGroup_GetSpawnedSquadAt(SGroup_FromName(t_FB2_Raid_Army.squadname[j]), 1), g_Player3)
			
		end
	end

	
	--this is to prevent the squads from going back to their spawn point while en route to their attack
	for d = 1, table.getn(t_FB2_Raid_Army.squadname) do 
	
		SGroup_Clear(SGroup_FromName(t_FB2_Raid_Army.squadname[d]))
		
	end
	
	Rule_Remove(Rule_FB2_Raid_Attack)
	Rule_AddIntervalDelay(Rule_FB2_Raid, 30, 5)

end


function Rule_Tier3_Raid()

if Player_AreSquadsNearMarker(g_Player1, "mkr_RB2_Trigger") then

	g_RB2_Marine_AI = true
	
	Rule_AddIntervalDelay(Rule_RB2_Beserker1_Raid, 300, 800)
	Rule_AddIntervalDelay(Rule_RB2_Raptor1_Raid, 200, 250)

	Rule_Remove(Rule_Tier3_Raid)

end

end

--Rear Base 1 Chaos marines function Rule_RB_Marines_Raid()

t_RB_Marine_Raid_Army = {
squadname = {--[[1]]"sg_RB_Marine_Raiders1", --[[2]]"sg_RB_Marine_Raiders2"},
squadnum = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1},
squadsize = {--[[1]] 2, --[[2]] 2, --[[3]] 3, --[[4]] 3},
}


if EGroup_Exists("eg_RB2") and EGroup_IsEmpty("eg_RB2") == false and Player_GetCurrentSquadCap(g_Player3, CT_SquadCap) <= g_MarineMaxCap then

	--RB1Inc can never be freater than the number of entries in the squadsize and squadnum tables.
	if g_RB_Marine_Increment <= 5 then

		RB1Inc = 1
		
	elseif  g_RB_Marine_Increment <= 10 then
		
		RB1Inc = 2
		
	elseif  g_RB_Marine_Increment <= 15 then
		
		RB1Inc = 3
		
	elseif  g_RB_Marine_Increment > 15 then
		
		RB1Inc = 4
		
	end

			
	local i = g_RB_Marine_Size
	--there are two variables here "i" and "RB1Inc" they are linked to different systems. "i" incrememnts where in the spawning cycle we are for the number of squads and "RB1Inc" where we are in the difficulty cycle. The reason i am using "i' instead of a for loop
	--is that I didn't want to have four squads spawning at once and looking unfair to the player. 
	
	--checking how many squads in this group in order to prevent over population
	if SGroup_CountSpawned(SGroup_CreateIfNotFound("sg_RB_Marines_Raid")) <= 2 then
	
		Util_CreateSquadsAtMarkerEx(g_Player2, t_RB_Marine_Raid_Army.squadname[i], "chaos_marine_squad_stronghold_sp", "mkr_RB_Building2_Spawn", t_RB_Marine_Raid_Army.squadnum[RB1Inc], 
		t_RB_Marine_Raid_Army.squadsize[RB1Inc])

		SGroup_AddGroup(SGroup_CreateIfNotFound("sg_RB_Marines_Raid"), SGroup_FromName( t_RB_Marine_Raid_Army.squadname[i]))

		--this will add a leader after Xmn of gameplay to the raiding parties
		if g_Timer >= 30 then
		
			Cmd_ReinforceLeader(t_RB_Marine_Raid_Army.squadname[i], 1)
		
		end

		if g_RB_Marine_Size <  table.getn(t_RB_Marine_Raid_Army.squadname) then

			g_RB_Marine_Size = g_RB_Marine_Size + 1
		
		elseif g_RB_Marine_Size == table.getn(t_RB_Marine_Raid_Army.squadname) then
		
			g_RB_Marine_Size = 1
			
			Rule_Remove(Rule_RB_Marines_Raid)			
			Rule_Add(Rule_RB_Marines_Attack)
		
		end

		g_RB_Marine_Increment = g_RB_Marine_Increment +1
	end

	
elseif EGroup_Exists("eg_RB2") and EGroup_IsEmpty("eg_RB2") == false and Player_GetCurrentSquadCap(g_Player3, CT_SquadCap) > g_MarineMaxCap then



else

	Rule_Remove(Rule_RB_Marines_Raid)

end

end

--this is done in a seperate function than Rule_RB_Marines_Raid in order to be able to to re-add Rule_RB_Marines_Raid after a delay and not get an error about the rule still existing. function Rule_RB_Marines_Attack()

	--checks to see if the player has an HQ and if yes to go attack it
	EGroup_Clear(EGroup_CreateIfNotFound("eg_Player1_Buildings"))
	EGroup_AddGroup(EGroup_FromName("eg_Player1_Buildings"), Player_GetEntities(g_Player1))
	
	local countbuilding = EGroup_CountSpawned(EGroup_FromName("eg_Player1_Buildings"))
	
	for i = 1, countbuilding do
	
		EGroup_Clear(EGroup_CreateIfNotFound("eg_Potential_HQ"))
		EGroup_Add(EGroup_FromName("eg_Potential_HQ"), EGroup_GetSpawnedEntityAt("eg_Player1_Buildings", i))

		if EGroup_ContainsBlueprints(EGroup_FromName("eg_Potential_HQ"), t_blueprinthq, true) then
		
			pos_HQ = Entity_GetPosition( EGroup_GetSpawnedEntityAt("eg_Potential_HQ", 1))
			Cmd_AttackMovePos("sg_RB_Marines_Raid", pos_HQ)
							
		
			--at this point we want to stop the for loop
			break

		end
	end

	--this is the table in the spawning rule Rule_RB_Marines_Raid
	for j = 1, table.getn(t_RB_Marine_Raid_Army.squadname) do 
		--check to see if the squads are idle. if they are then it means the player has no HQ in which case they are given to the active AI player
		if SGroup_IsEmpty(t_RB_Marine_Raid_Army.squadname[j]) == false and 
		Squad_GetActiveCommand(SGroup_GetSpawnedSquadAt(SGroup_FromName(t_RB_Marine_Raid_Army.squadname[j]), 1)) == SQUADSTATEID_Idle then 

			Squad_SetPlayerOwner(SGroup_GetSpawnedSquadAt(SGroup_FromName(t_RB_Marine_Raid_Army.squadname[j]), 1), g_Player3)
			
		
		end
	end
	
	
	--this is to prevent the squads from going back to their spawn point while en route to their attack
	for d = 1, table.getn(t_RB_Marine_Raid_Army.squadname) do 
	
		SGroup_Clear(SGroup_FromName(t_RB_Marine_Raid_Army.squadname[d]))
		
	end

	Rule_Remove(Rule_RB_Marines_Attack)
	Rule_AddIntervalDelay(Rule_RB_Marines_Raid, 150, 5)

end


--Rear Base 1 defiler function Rule_RB_Defiler_Raid()

t_RB_Defiler_Raid_Army = {
squadname = {--[[1]]"sg_RB_Defiler_Raiders1"},
squadnum = {--[[1]] 1, --[[2]] 1, --[[3]] 2, --[[4]] 2},
squadsize = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1},
}

if EGroup_Exists("eg_RB12") and EGroup_IsEmpty("eg_RB12") == false then

	--RB2Inc can never be freater than the number of entries in the squadsize and squadnum tables.
	if g_RB_Defiler_Increment <= 5 then

		RB2Inc = 1
		
	elseif  g_RB_Defiler_Increment <= 10 then
		
		RB2Inc = 2
		
	elseif  g_RB_Defiler_Increment <= 15 then
		
		RB2Inc = 3
		
	elseif  g_RB_Defiler_Increment > 15 then
		
		RB2Inc = 4
		
	end

	
		
	local i = g_RB_Defiler_Size
	--there are two variables here "i" and "RB2Inc" they are linked to different systems. "i" incrememnts where in the spawning cycle we are for the number of squads and "RB2Inc" where we are in the difficulty cycle. The reason i am using "i' instead of a for loop
	--is that I didn't want to have four squads spawning at once and looking unfair to the player. 
	Util_CreateSquadsAtMarkerEx(g_Player2, t_RB_Defiler_Raid_Army.squadname[i], "chaos_squad_defiler", "mkr_RB_Building12_Spawn", t_RB_Defiler_Raid_Army.squadnum[RB2Inc], 
	t_RB_Defiler_Raid_Army.squadsize[RB2Inc])

	SGroup_AddGroup(SGroup_CreateIfNotFound("sg_RB_Defiler_Raid"), SGroup_FromName( t_RB_Defiler_Raid_Army.squadname[i]))


	if g_RB_Defiler_Size <  table.getn(t_RB_Defiler_Raid_Army.squadname) then

		g_RB_Defiler_Size = g_RB_Defiler_Size + 1
	
	elseif g_RB_Defiler_Size == table.getn(t_RB_Defiler_Raid_Army.squadname) then
	
		g_RB_Defiler_Size = 1
		
		Rule_Remove(Rule_RB_Defiler_Raid)			
		Rule_Add(Rule_RB_Defiler_Attack)
	
	end

	g_RB_Defiler_Increment = g_RB_Defiler_Increment +1
	
		

else

	Rule_Remove(Rule_RB_Defiler_Raid)

end

end

--this is done in a seperate function than Rule_RB_Defiler_Raid in order to be able to to re-add Rule_RB_Defiler_Raid after a delay and not get an error about the rule still existing. function Rule_RB_Defiler_Attack()

	--checks to see if the player has an HQ and if yes to go attack it
	EGroup_Clear(EGroup_CreateIfNotFound("eg_Player1_Buildings"))
	EGroup_AddGroup(EGroup_FromName("eg_Player1_Buildings"), Player_GetEntities(g_Player1))
	
	local countbuilding = EGroup_CountSpawned(EGroup_FromName("eg_Player1_Buildings"))
	
	for i = 1, countbuilding do
	
		EGroup_Clear(EGroup_CreateIfNotFound("eg_Potential_HQ"))
		EGroup_Add(EGroup_FromName("eg_Potential_HQ"), EGroup_GetSpawnedEntityAt("eg_Player1_Buildings", i))

		if EGroup_ContainsBlueprints(EGroup_FromName("eg_Potential_HQ"), t_blueprinthq, true) then
		
			pos_HQ = Entity_GetPosition( EGroup_GetSpawnedEntityAt("eg_Potential_HQ", 1))
			Cmd_AttackMovePos("sg_RB_Defiler_Raid", pos_HQ)
						
			--at this point we want to stop the for loop
			break

		end
	end

--[[ --this is the table in the spawning rule Rule_RB_Defiler_Raid for j = 1, table.getn(t_RB_Defiler_Raid_Army.squadname) do --check to see if the squads are idle. if they are then it means the player has no HQ in which case they are given to the active AI player if Squad_GetActiveCommand(SGroup_GetSpawnedSquadAt(SGroup_FromName(t_RB_Defiler_Raid_Army.squadname[j]), 1)) == SQUADSTATEID_Idle then

			Squad_SetPlayerOwner(SGroup_GetSpawnedSquadAt(SGroup_FromName(t_RB_Defiler_Raid_Army.squadname[j]), 1), g_Player3)
			
		end
	end]]

	--this is to prevent the squads from going back to their spawn point while en route to their attack
	for d = 1, table.getn(t_RB_Defiler_Raid_Army.squadname) do 
	
		SGroup_Clear(SGroup_FromName(t_RB_Defiler_Raid_Army.squadname[d]))
		
	end
	
	
	Rule_Remove(Rule_RB_Defiler_Attack)
	Rule_AddIntervalDelay(Rule_RB_Defiler_Raid, 300, 5)

end


--Rear Base 2 Beserkers 1 function Rule_RB2_Beserker1_Raid()

t_RB2_Beserker1_Raid_Army = {
squadname = {--[[1]]"sg_RB2_Beserker_Raid1", --[[2]]"sg_RB2_Beserker_Raid2", --[[3]]"sg_RB2_Beserker_Raid3"},
squadnum = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 2},
squadsize = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1},
}

if EGroup_Exists("eg_RB2_1") and EGroup_IsEmpty("eg_RB2_1") == false and Player_GetCurrentSquadCap(g_Player3, CT_SquadCap) <= g_KhorneMaxCap then

	--RB4Inc can never be freater than the number of entries in the squadsize and squadnum tables.
	if g_RB2_Beserker1_Increment <= 5 then

		RB4Inc = 1
		
	elseif  g_RB2_Beserker1_Increment <= 10 then
		
		RB4Inc = 2
		
	elseif  g_RB2_Beserker1_Increment <= 15 then
		
		RB4Inc = 3
		
	elseif  g_RB2_Beserker1_Increment > 15 then
		
		RB4Inc = 4
		
	end

	local i = g_RB2_Beserker1_Size
	--there are two variables here "i" and "RB3Inc" they are linked to different systems. "i" incrememnts where in the spawning cycle we are for the number of squads and "RB3Inc" where we are in the difficulty cycle. The reason i am using "i' instead of a for loop
	--is that I didn't want to have four squads spawning at once and looking unfair to the player. 
	
		--checking how many squads in this group in order to prevent over population
	if SGroup_CountSpawned(SGroup_CreateIfNotFound("sg_RB2_Beserker1_Raid")) <= 3 then
		
		Util_CreateSquadsAtMarkerEx(g_Player2, t_RB2_Beserker1_Raid_Army.squadname[i], "chaos_squad_khorne_berserker_stronghold_sp", "mkr_RB2_Building1_Spawn", t_RB2_Beserker1_Raid_Army.squadnum[RB4Inc], 
		t_RB2_Beserker1_Raid_Army.squadsize[RB4Inc])

		SGroup_AddGroup(SGroup_CreateIfNotFound("sg_RB2_Beserker1_Raid"), SGroup_FromName( t_RB2_Beserker1_Raid_Army.squadname[i]))


		if g_RB2_Beserker1_Size <  table.getn(t_RB2_Beserker1_Raid_Army.squadname) then

			g_RB2_Beserker1_Size = g_RB2_Beserker1_Size + 1
		
		elseif g_RB2_Beserker1_Size == table.getn(t_RB2_Beserker1_Raid_Army.squadname) then
		
			g_RB2_Beserker1_Size = 1
			
			Rule_Remove(Rule_RB2_Beserker1_Raid)			
			Rule_Add(Rule_RB2_Beserker1_Attack)
		
		end

		g_RB2_Beserker1_Increment = g_RB2_Beserker1_Increment +1
		
	end	

elseif EGroup_Exists("eg_RB2_1") and EGroup_IsEmpty("eg_RB2_1") == false and Player_GetCurrentSquadCap(g_Player3, CT_SquadCap) > g_KhorneMaxCap then


else

	Rule_Remove(Rule_RB2_Beserker1_Raid)
	
end

end

--this is done in a seperate function than Rule_RB2_Beserker1_Raid in order to be able to to re-add Rule_RB2_Beserker1_Raid after a delay and not get an error about the rule still existing. function Rule_RB2_Beserker1_Attack()

	--checks to see if the player has an HQ and if yes to go attack it
	EGroup_Clear(EGroup_CreateIfNotFound("eg_Player1_Buildings"))
	EGroup_AddGroup(EGroup_FromName("eg_Player1_Buildings"), Player_GetEntities(g_Player1))
	
	local countbuilding = EGroup_CountSpawned(EGroup_FromName("eg_Player1_Buildings"))
	
	for i = 1, countbuilding do
	
		EGroup_Clear(EGroup_CreateIfNotFound("eg_Potential_HQ"))
		EGroup_Add(EGroup_FromName("eg_Potential_HQ"), EGroup_GetSpawnedEntityAt("eg_Player1_Buildings", i))

		if EGroup_ContainsBlueprints(EGroup_FromName("eg_Potential_HQ"), t_blueprinthq, true) then
		
			pos_HQ = Entity_GetPosition( EGroup_GetSpawnedEntityAt("eg_Potential_HQ", 1))
			Cmd_AttackMovePos("sg_RB2_Beserker1_Raid", pos_HQ)
			
			
			--at this point we want to stop the for loop
			break

		end
	end

--[[ --this is the table in the spawning rule Rule_RB2_Beserker1_Raid for j = 1, table.getn(t_RB2_Beserker1_Raid_Army.squadname) do --check to see if the squads are idle. if they are then it means the player has no HQ in which case they are given to the active AI player if Squad_GetActiveCommand(SGroup_GetSpawnedSquadAt(SGroup_FromName(t_RB2_Beserker1_Raid_Army.squadname[j]), 1)) == SQUADSTATEID_Idle then

			Squad_SetPlayerOwner(SGroup_GetSpawnedSquadAt(SGroup_FromName(t_RB2_Beserker1_Raid_Army.squadname[j]), 1), g_Player3)
			
		end
	end]]

	--this is to prevent the squads from going back to their spawn point while en route to their attack
	for d = 1, table.getn(t_RB2_Beserker1_Raid_Army.squadname) do 
	
		SGroup_Clear(SGroup_FromName(t_RB2_Beserker1_Raid_Army.squadname[d]))
		
	end
	
	Rule_Remove(Rule_RB2_Beserker1_Attack)
	Rule_AddIntervalDelay(Rule_RB2_Beserker1_Raid, 300, 90)

end


--Rear Base 2 Marine 1 function Rule_RB2_Marine1_Raid()

t_RB2_Marine1_Raid_Army = {
squadname = {--[[1]]"sg_RB2_Marine_Raid1", --[[2]]"sg_RB2_Marine_Raid2", --[[3]]"sg_RB2_Marine_Raid3"},
squadnum = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1},
squadsize = {--[[1]] 2, --[[2]] 2, --[[3]] 2, --[[4]] 2},
}

if EGroup_Exists("eg_RB2_1") and EGroup_IsEmpty("eg_RB2_1") == false and Player_GetCurrentSquadCap(g_Player3, CT_SquadCap) <= g_MarineMaxCap then

	--RB5Inc can never be freater than the number of entries in the squadsize and squadnum tables.
	if g_RB2_Marine1_Increment <= 5 then

		RB5Inc = 1
		
	elseif  g_RB2_Marine1_Increment <= 10 then
		
		RB5Inc = 2
		
	elseif  g_RB2_Marine1_Increment <= 15 then
		
		RB5Inc = 3
		
	elseif  g_RB2_Marine1_Increment > 15 then
		
		RB5Inc = 4
		
	end

	local i = g_RB2_Marine1_Size
	--there are two variables here "i" and "RB5Inc" they are linked to different systems. "i" incrememnts where in the spawning cycle we are for the number of squads and "RB5Inc" where we are in the difficulty cycle. The reason i am using "i' instead of a for loop
	--is that I didn't want to have four squads spawning at once and looking unfair to the player. 
	
				--checking how many squads in this group in order to prevent over population
	if SGroup_CountSpawned(SGroup_CreateIfNotFound("sg_RB2_Marine1_Raid")) <= 3 then
		
		Util_CreateSquadsAtMarkerEx(g_Player2, t_RB2_Marine1_Raid_Army.squadname[i], "chaos_marine_squad_stronghold_sp", "mkr_RB2_Building1_Spawn", t_RB2_Marine1_Raid_Army.squadnum[RB5Inc], 
		t_RB2_Marine1_Raid_Army.squadsize[RB5Inc])

		SGroup_AddGroup(SGroup_CreateIfNotFound("sg_RB2_Marine1_Raid"), SGroup_FromName( t_RB2_Marine1_Raid_Army.squadname[i]))
		
		--this will add a leader after Xmn of gameplay to the raiding parties
		if g_Timer >= 30 then
		
			Cmd_ReinforceLeader(t_RB2_Marine1_Raid_Army.squadname[i], 1)
		
		end

		if g_RB2_Marine1_Size <  table.getn(t_RB2_Marine1_Raid_Army.squadname) then

			g_RB2_Marine1_Size = g_RB2_Marine1_Size + 1
		
		elseif g_RB2_Marine1_Size == table.getn(t_RB2_Marine1_Raid_Army.squadname) then
		
			g_RB2_Marine1_Size = 1
			
			Rule_Remove(Rule_RB2_Marine1_Raid)			
			Rule_Add(Rule_RB2_Marine1_Attack)
		
		end

		g_RB2_Marine1_Increment = g_RB2_Marine1_Increment +1

	end
elseif EGroup_Exists("eg_RB2_1") and EGroup_IsEmpty("eg_RB2_1") == false and Player_GetCurrentSquadCap(g_Player3, CT_SquadCap) > g_MarineMaxCap then


else

	Rule_Remove(Rule_RB2_Marine1_Raid)

end

end

--this is done in a seperate function than Rule_RB2_Marine1_Raid in order to be able to to re-add Rule_RB2_Marine1_Raid after a delay and not get an error about the rule still existing. function Rule_RB2_Marine1_Attack()

	--checks to see if the player has an HQ and if yes to go attack it
	EGroup_Clear(EGroup_CreateIfNotFound("eg_Player1_Buildings"))
	EGroup_AddGroup(EGroup_FromName("eg_Player1_Buildings"), Player_GetEntities(g_Player1))
	
	local countbuilding = EGroup_CountSpawned(EGroup_FromName("eg_Player1_Buildings"))
	
	for i = 1, countbuilding do
	
		EGroup_Clear(EGroup_CreateIfNotFound("eg_Potential_HQ"))
		EGroup_Add(EGroup_FromName("eg_Potential_HQ"), EGroup_GetSpawnedEntityAt("eg_Player1_Buildings", i))

		if EGroup_ContainsBlueprints(EGroup_FromName("eg_Potential_HQ"), t_blueprinthq, true) then
		
			pos_HQ = Entity_GetPosition( EGroup_GetSpawnedEntityAt("eg_Potential_HQ", 1))
			Cmd_AttackMovePos("sg_RB2_Marine1_Raid", pos_HQ)
	
			
			--at this point we want to stop the for loop
			break

		end
	end

	--this is the table in the spawning rule Rule_RB2_Marine1_Raid
	for j = 1, table.getn(t_RB2_Marine1_Raid_Army.squadname) do 
		--check to see if the squads are idle. if they are then it means the player has no HQ in which case they are given to the active AI player
		if SGroup_IsEmpty(t_RB2_Marine1_Raid_Army.squadname[j]) == false and g_RB2_Marine_AI == true then 

			Squad_SetPlayerOwner(SGroup_GetSpawnedSquadAt(SGroup_FromName(t_RB2_Marine1_Raid_Army.squadname[j]), 1), g_Player3)
			
		end
	end

	--this is to prevent the squads from going back to their spawn point while en route to their attack
	for d = 1, table.getn(t_RB2_Marine1_Raid_Army.squadname) do 
	
		SGroup_Clear(SGroup_FromName(t_RB2_Marine1_Raid_Army.squadname[d]))
		
	end
	
	Rule_Remove(Rule_RB2_Marine1_Attack)
	Rule_AddIntervalDelay(Rule_RB2_Marine1_Raid, 150, 60)

end


--Rear Base 2 Raptors 1 These units are given to the AI to do as it pleases with. function Rule_RB2_Raptor1_Raid()

t_RB2_Raptor1_Raid_Army = {
squadname = {--[[1]]"sg_RB2_Raptor_Raid1", --[[2]]"sg_RB2_Raptor_Raid2", --[[3]]"sg_RB2_Raptor_Raid3"},
squadnum = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1},
squadsize = {--[[1]] 2, --[[2]] 2, --[[3]] 3, --[[4]] 4},
}

if EGroup_Exists("eg_RB2_2") and EGroup_IsEmpty("eg_RB2_2") == false and Player_GetCurrentSquadCap(g_Player3, CT_SquadCap) <= g_RaptorMaxCap then

	--RB6Inc can never be freater than the number of entries in the squadsize and squadnum tables.
	if g_RB2_Raptor1_Increment <= 5 then

		RB6Inc = 1
		
	elseif  g_RB2_Raptor1_Increment <= 10 then
		
		RB6Inc = 2
		
	elseif  g_RB2_Raptor1_Increment <= 15 then
		
		RB6Inc = 3
		
	elseif  g_RB2_Raptor1_Increment > 15 then
		
		RB6Inc = 4
		
	end

	local i = g_RB2_Raptor1_Size
	--there are two variables here "i" and "RB3Inc" they are linked to different systems. "i" incrememnts where in the spawning cycle we are for the number of squads and "RB3Inc" where we are in the difficulty cycle. The reason i am using "i' instead of a for loop
	--is that I didn't want to have four squads spawning at once and looking unfair to the player. 
	
	--checking how many squads in this group in order to prevent over population
	if SGroup_CountSpawned(SGroup_CreateIfNotFound("sg_RB2_Raptor1_Raid")) <= 3 then
	
		Util_CreateSquadsAtMarkerEx(g_Player2, t_RB2_Raptor1_Raid_Army.squadname[i], "chaos_squad_raptor_stronghold_sp", "mkr_RB2_Building2_Spawn", t_RB2_Raptor1_Raid_Army.squadnum[RB6Inc], 
		t_RB2_Raptor1_Raid_Army.squadsize[RB6Inc])

		SGroup_AddGroup(SGroup_CreateIfNotFound("sg_RB2_Raptor1_Raid"), SGroup_FromName( t_RB2_Raptor1_Raid_Army.squadname[i]))
		
		--this will add a leader after Xmn of gameplay to the raiding parties
		if g_Timer >= 30 then
		
			Cmd_ReinforceLeader(t_RB2_Raptor1_Raid_Army.squadname[i], 1)
		
		end

		if g_RB2_Raptor1_Size <  table.getn(t_RB2_Raptor1_Raid_Army.squadname) then

			g_RB2_Raptor1_Size = g_RB2_Raptor1_Size + 1
		
		elseif g_RB2_Raptor1_Size == table.getn(t_RB2_Raptor1_Raid_Army.squadname) then
		
			g_RB2_Raptor1_Size = 1
			
			Rule_Remove(Rule_RB2_Raptor1_Raid)			
			Rule_Add(Rule_RB2_Raptor1_Attack)
		
		end

		g_RB2_Raptor1_Increment = g_RB2_Raptor1_Increment +1
	end

elseif EGroup_Exists("eg_RB2_2") and EGroup_IsEmpty("eg_RB2_2") == false and Player_GetCurrentSquadCap(g_Player3, CT_SquadCap) > g_RaptorMaxCap then

else

	Rule_Remove(Rule_RB2_Raptor1_Raid)

end

end

--this is done in a seperate function than Rule_RB2_Raptor1_Raid in order to be able to to re-add Rule_RB2_Raptor1_Raid after a delay and not get an error about the rule still existing. function Rule_RB2_Raptor1_Attack()

	--this is the table in the spawning rule Rule_RB2_Raptor1_Raid
	for i = 1, table.getn(t_RB2_Raptor1_Raid_Army.squadname) do 

		if SGroup_Exists(t_RB2_Raptor1_Raid_Army.squadname[i]) and SGroup_IsEmpty(t_RB2_Raptor1_Raid_Army.squadname[i]) == false then 

			Squad_SetPlayerOwner(SGroup_GetSpawnedSquadAt(SGroup_FromName(t_RB2_Raptor1_Raid_Army.squadname[i]), 1), g_Player3)
			SGroup_Clear(SGroup_FromName(t_RB2_Raptor1_Raid_Army.squadname[i]))
		
		end
	end

	Rule_Remove(Rule_RB2_Raptor1_Attack)
	Rule_AddIntervalDelay(Rule_RB2_Raptor1_Raid, 200, 60)

end


--Rear Base2 cultists function Rule_RB2_Cultist_Raid()

t_RB2_Cultist_Raid_Army = {
squadname = {--[[1]]"sg_RB2_Cultist_Raiders1", --[[2]]"sg_RB2_Cultist_Raiders2", --[[3]]"sg_RB2_Cultist_Raiders3", --[[4]]"sg_RB2_Cultist_Raiders4"},
squadnum = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1},
squadsize = {--[[1]] 4, --[[2]] 5, --[[3]] 6, --[[4]] 7},
reinforceleader = {--[[1]] true, --[[2]] false, --[[3]]false, --[[4]]false},
}

if EGroup_Exists("eg_RB2_10") and EGroup_IsEmpty("eg_RB2_10") == false then

	--FB1Inc can never be freater than the number of entries in the squadsize and squadnum tables.
	if g_RB2_Cultist_Increment <= 5 then

		RB7Inc = 1
		
	elseif  g_RB2_Cultist_Increment <= 10 then
		
		RB7Inc = 2
		
	elseif  g_RB2_Cultist_Increment <= 15 then
		
		RB7Inc = 3
		
	elseif  g_RB2_Cultist_Increment > 15 then
		
		RB7Inc = 4
		
	end

	local i = g_RB2_Cultist_Size
	--there are two variables here "i" and "FB1Inc" they are linked to different systems. "i" incrememnts where in the spawning cycle we are for the number of squads and "FB1Inc" where we are in the difficulty cycle. The reason i am using "i' instead of a for loop
	--is that I didn't want to have four squads spawning at once and looking unfair to the player. 
			
	--checking how many squads in this group in order to prevent over population
	if SGroup_CountSpawned(SGroup_CreateIfNotFound("sg_RB2_Cultist_Raid")) <= 5 then
	
		Util_CreateSquadsAtMarkerEx(g_Player2, t_RB2_Cultist_Raid_Army.squadname[i], "chaos_squad_cultist", "mkr_RB2_Building10_Spawn", t_RB2_Cultist_Raid_Army.squadnum[RB7Inc], t_RB2_Cultist_Raid_Army.squadsize[RB7Inc])

		SGroup_AddGroup(SGroup_CreateIfNotFound("sg_RB2_Cultist_Raid"), SGroup_FromName( t_RB2_Cultist_Raid_Army.squadname[i]))

		if t_RB2_Cultist_Raid_Army.reinforceleader[i] == true then
		
			Cmd_ReinforceLeader(t_RB2_Cultist_Raid_Army.squadname[i], 1)
		
		end

	
		--this will add a leader after Xmn of gameplay to the raiding parties
		if g_Timer >= 20 then
		
			t_RB2_Cultist_Raid_Army.reinforceleader[i] = true
		
		end

		if g_RB2_Cultist_Size <  table.getn(t_RB2_Cultist_Raid_Army.squadname) then

			g_RB2_Cultist_Size = g_RB2_Cultist_Size + 1
		
		elseif g_RB2_Cultist_Size == table.getn(t_RB2_Cultist_Raid_Army.squadname) then
		
			g_RB2_Cultist_Size = 1
			
			Rule_Remove(Rule_RB2_Cultist_Raid)			
			Rule_Add(Rule_RB2_Cultist_Raid_Attack)
		
		end

		g_RB2_Cultist_Increment = g_RB2_Cultist_Increment +1
	end
	
else

	Rule_Remove(Rule_RB2_Cultist_Raid)

end

end

--this is done in a seperate function than Rule_FB1_Raid in order to be able to to re-add Rule_FB1_Raid after a delay and not get an error about the rule still existing. function Rule_RB2_Cultist_Raid_Attack()

	--checks to see if the player has an HQ and if yes to go attack it
	EGroup_Clear(EGroup_CreateIfNotFound("eg_Player1_Buildings"))
	EGroup_AddGroup(EGroup_FromName("eg_Player1_Buildings"), Player_GetEntities(g_Player1))
	
	local countbuilding = EGroup_CountSpawned(EGroup_FromName("eg_Player1_Buildings"))
	
	for i = 1, countbuilding do
	
		EGroup_Clear(EGroup_CreateIfNotFound("eg_Potential_HQ"))
		EGroup_Add(EGroup_FromName("eg_Potential_HQ"), EGroup_GetSpawnedEntityAt("eg_Player1_Buildings", i))

		if EGroup_ContainsBlueprints(EGroup_FromName("eg_Potential_HQ"), t_blueprinthq, true) then
		
			pos_HQ = Entity_GetPosition( EGroup_GetSpawnedEntityAt("eg_Potential_HQ", 1))
			Cmd_AttackMovePos("sg_RB2_Cultist_Raid", pos_HQ)
			
			--at this point we want to stop the for loop
			break

		end
	end

	--this is the table in the spawning rule Rule_FB1_Raid
	for j = 1, table.getn(t_RB2_Cultist_Raid_Army.squadname) do 
		--check to see if the squads are idle. if they are then it means the player has no HQ in which case they are given to the active AI player
		if SGroup_IsEmpty(t_RB2_Cultist_Raid_Army.squadname[j]) == false and  
		Squad_GetActiveCommand(SGroup_GetSpawnedSquadAt(SGroup_FromName(t_RB2_Cultist_Raid_Army.squadname[j]), 1)) == SQUADSTATEID_Idle then 

			Squad_SetPlayerOwner(SGroup_GetSpawnedSquadAt(SGroup_FromName(t_RB2_Cultist_Raid_Army.squadname[j]), 1), g_Player3)
			
		
		end
	end
	
	--this is to prevent the squads from going back to their spawn point while en route to their attack
	for d = 1, table.getn(t_RB2_Cultist_Raid_Army.squadname) do 
	
		SGroup_Clear(SGroup_FromName(t_RB2_Cultist_Raid_Army.squadname[d]))
		
	end

	Rule_Remove(Rule_RB2_Cultist_Raid_Attack)
	Rule_AddIntervalDelay(Rule_RB2_Cultist_Raid, 30, 5)

end


--Bastion Marine 1 function Rule_Bastion_Marine1_Raid()

t_Bastion_Marine1_Raid_Army = {
squadname = {--[[1]]"sg_Bastion_Marine_Raid1", --[[2]]"sg_Bastion_Marine_Raid2", --[[3]]"sg_Bastion_Marine_Raid3"},
squadnum = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1},
squadsize = {--[[1]] 2, --[[2]] 3, --[[3]] 3, --[[4]] 4},
}

if EGroup_Exists("eg_CM_Barrack_Bastion") and EGroup_IsEmpty("eg_CM_Barrack_Bastion") == false then

	--RB9Inc can never be freater than the number of entries in the squadsize and squadnum tables.
	if g_Bastion_Marine1_Increment <= 5 then

		RB9Inc = 1
		
	elseif  g_Bastion_Marine1_Increment <= 10 then
		
		RB9Inc = 2
		
	elseif  g_Bastion_Marine1_Increment <= 15 then
		
		RB9Inc = 3
		
	elseif  g_Bastion_Marine1_Increment > 15 then
		
		RB9Inc = 4
		
	end

	local i = g_Bastion_Marine1_Size
	--there are two variables here "i" and "RB9Inc" they are linked to different systems. "i" incrememnts where in the spawning cycle we are for the number of squads and "RB9Inc" where we are in the difficulty cycle. The reason i am using "i' instead of a for loop
	--is that I didn't want to have four squads spawning at once and looking unfair to the player. 
	
	--checking how many squads in this group in order to prevent over population
	if SGroup_CountSpawned(SGroup_CreateIfNotFound("sg_Bastion_Marine1_Raid")) <= 3 then
	
		Util_CreateSquadsAtMarkerEx(g_Player2, t_Bastion_Marine1_Raid_Army.squadname[i], "chaos_marine_squad_stronghold_sp", "mkr_CM_Barrack_Bastion_Spawn", t_Bastion_Marine1_Raid_Army.squadnum[RB9Inc], 
		t_RB2_Marine1_Raid_Army.squadsize[RB9Inc])

		SGroup_AddGroup(SGroup_CreateIfNotFound("sg_Bastion_Marine1_Raid"), SGroup_FromName( t_Bastion_Marine1_Raid_Army.squadname[i]))

		--this will add a leader after Xmn of gameplay to the raiding parties
		if g_Timer >= 20 then
		
			Cmd_ReinforceLeader(t_Bastion_Marine1_Raid_Army.squadname[i], 1)
		
		end

		if g_Bastion_Marine1_Size <  table.getn(t_Bastion_Marine1_Raid_Army.squadname) then

			g_Bastion_Marine1_Size = g_Bastion_Marine1_Size + 1
		
		elseif g_Bastion_Marine1_Size == table.getn(t_Bastion_Marine1_Raid_Army.squadname) then
		
			g_Bastion_Marine1_Size = 1
			
			Rule_Remove(Rule_Bastion_Marine1_Raid)			
			Rule_Add(Rule_Bastion_Marine1_Attack)
		
		end

		g_Bastion_Marine1_Increment = g_Bastion_Marine1_Increment +1
	end

else

	Rule_Remove(Rule_Bastion_Marine1_Raid)

end

end

--this is done in a seperate function than Rule_RB2_Marine1_Raid in order to be able to to re-add Rule_RB2_Marine1_Raid after a delay and not get an error about the rule still existing. function Rule_Bastion_Marine1_Attack()

	--checks to see if the player has an HQ and if yes to go attack it
	EGroup_Clear(EGroup_CreateIfNotFound("eg_Player1_Buildings"))
	EGroup_AddGroup(EGroup_FromName("eg_Player1_Buildings"), Player_GetEntities(g_Player1))
	
	local countbuilding = EGroup_CountSpawned(EGroup_FromName("eg_Player1_Buildings"))
	
	for i = 1, countbuilding do
	
		EGroup_Clear(EGroup_CreateIfNotFound("eg_Potential_HQ"))
		EGroup_Add(EGroup_FromName("eg_Potential_HQ"), EGroup_GetSpawnedEntityAt("eg_Player1_Buildings", i))

		if EGroup_ContainsBlueprints(EGroup_FromName("eg_Potential_HQ"), t_blueprinthq, true) then
		
			pos_HQ = Entity_GetPosition( EGroup_GetSpawnedEntityAt("eg_Potential_HQ", 1))
			Cmd_AttackMovePos("sg_Bastion_Marine1_Raid", pos_HQ)
	
			
			--at this point we want to stop the for loop
			break

		end
	end

	--this is the table in the spawning rule Rule_RB2_Marine1_Raid
	for j = 1, table.getn(t_Bastion_Marine1_Raid_Army.squadname) do 
		--check to see if the squads are idle. if they are then it means the player has no HQ in which case they are given to the active AI player
		if SGroup_IsEmpty(t_Bastion_Marine1_Raid_Army.squadname[j]) == false then 

			Squad_SetPlayerOwner(SGroup_GetSpawnedSquadAt(SGroup_FromName(t_Bastion_Marine1_Raid_Army.squadname[j]), 1), g_Player3)
			
		end
	end

	--this is to prevent the squads from going back to their spawn point while en route to their attack
	for d = 1, table.getn(t_Bastion_Marine1_Raid_Army.squadname) do 
	
		SGroup_Clear(SGroup_FromName(t_Bastion_Marine1_Raid_Army.squadname[d]))
		
	end
	
	Rule_Remove(Rule_Bastion_Marine1_Attack)
	Rule_AddIntervalDelay(Rule_Bastion_Marine1_Raid, 150, 60)

end

--Bastion cultists function Rule_Bastion_Cultist_Raid()

t_Bastion_Cultist_Raid_Army = {
squadname = {--[[1]]"sg_Bastion_Cultist_Raiders1", --[[2]]"sg_Bastion_Cultist_Raiders2", --[[3]]"sg_Bastion_Cultist_Raiders3", --[[4]]"sg_Bastion_Cultist_Raiders4"},
squadnum = {--[[1]] 1, --[[2]] 1, --[[3]] 1, --[[4]] 1},
squadsize = {--[[1]] 4, --[[2]] 5, --[[3]] 6, --[[4]] 7},
reinforceleader = {--[[1]] true, --[[2]] false, --[[3]]false, --[[4]]false},
}

if EGroup_Exists("eg_CM_HQ") and EGroup_IsEmpty("eg_CM_HQ") == false then

	--FB1Inc can never be freater than the number of entries in the squadsize and squadnum tables.
	if g_Bastion_Cultist_Increment <= 5 then

		RB8Inc = 1
		
	elseif  g_Bastion_Cultist_Increment <= 10 then
		
		RB8Inc = 2
		
	elseif  g_Bastion_Cultist_Increment <= 15 then
		
		RB8Inc = 3
		
	elseif  g_Bastion_Cultist_Increment > 15 then
		
		RB8Inc = 4
		
	end

	local i = g_Bastion_Cultist_Size
	--there are two variables here "i" and "FB1Inc" they are linked to different systems. "i" incrememnts where in the spawning cycle we are for the number of squads and "FB1Inc" where we are in the difficulty cycle. The reason i am using "i' instead of a for loop
	--is that I didn't want to have four squads spawning at once and looking unfair to the player. 
	
	--checking how many squads in this group in order to prevent over population
	if SGroup_CountSpawned(SGroup_CreateIfNotFound("sg_Bastion_Cultist_Raid")) <= 4 then
	
		Util_CreateSquadsAtMarkerEx(g_Player2, t_Bastion_Cultist_Raid_Army.squadname[i], "chaos_squad_cultist", "mkr_Chaos_HQ", t_Bastion_Cultist_Raid_Army.squadnum[RB8Inc], t_Bastion_Cultist_Raid_Army.squadsize[RB8Inc])

		SGroup_AddGroup(SGroup_CreateIfNotFound("sg_Bastion_Cultist_Raid"), SGroup_FromName( t_Bastion_Cultist_Raid_Army.squadname[i]))

		if t_Bastion_Cultist_Raid_Army.reinforceleader[i] == true then
		
			Cmd_ReinforceLeader(t_Bastion_Cultist_Raid_Army.squadname[i], 1)
		
		end

	
		--this will add a leader after Xmn of gameplay to the raiding parties
		if g_Timer >= 20 then
		
			t_Bastion_Cultist_Raid_Army.reinforceleader[i] = true
		
		end

		if g_Bastion_Cultist_Size <  table.getn(t_Bastion_Cultist_Raid_Army.squadname) then

			g_Bastion_Cultist_Size = g_Bastion_Cultist_Size + 1
		
		elseif g_Bastion_Cultist_Size == table.getn(t_Bastion_Cultist_Raid_Army.squadname) then
		
			g_Bastion_Cultist_Size = 1
			
			Rule_Remove(Rule_Bastion_Cultist_Raid)			
			Rule_Add(Rule_Bastion_Cultist_Raid_Attack)
		
		end

		g_Bastion_Cultist_Increment = g_Bastion_Cultist_Increment +1
	
	end
	
else

	Rule_Remove(Rule_Bastion_Cultist_Raid)

end

end

--this is done in a seperate function than Rule_FB1_Raid in order to be able to to re-add Rule_FB1_Raid after a delay and not get an error about the rule still existing. function Rule_Bastion_Cultist_Raid_Attack()

	--checks to see if the player has an HQ and if yes to go attack it
	EGroup_Clear(EGroup_CreateIfNotFound("eg_Player1_Buildings"))
	EGroup_AddGroup(EGroup_FromName("eg_Player1_Buildings"), Player_GetEntities(g_Player1))
	
	local countbuilding = EGroup_CountSpawned(EGroup_FromName("eg_Player1_Buildings"))
	
	for i = 1, countbuilding do
	
		EGroup_Clear(EGroup_CreateIfNotFound("eg_Potential_HQ"))
		EGroup_Add(EGroup_FromName("eg_Potential_HQ"), EGroup_GetSpawnedEntityAt("eg_Player1_Buildings", i))

		if EGroup_ContainsBlueprints(EGroup_FromName("eg_Potential_HQ"), t_blueprinthq, true) then
		
			pos_HQ = Entity_GetPosition( EGroup_GetSpawnedEntityAt("eg_Potential_HQ", 1))
			Cmd_AttackMovePos("sg_Bastion_Cultist_Raid", pos_HQ)
			
			--at this point we want to stop the for loop
			break

		end
	end

	--this is the table in the spawning rule Rule_FB1_Raid
	for j = 1, table.getn(t_Bastion_Cultist_Raid_Army.squadname) do 
		--check to see if the squads are idle. if they are then it means the player has no HQ in which case they are given to the active AI player
		if SGroup_IsEmpty(t_Bastion_Cultist_Raid_Army.squadname[j]) == false and  
		Squad_GetActiveCommand(SGroup_GetSpawnedSquadAt(SGroup_FromName(t_Bastion_Cultist_Raid_Army.squadname[j]), 1)) == SQUADSTATEID_Idle then 

			Squad_SetPlayerOwner(SGroup_GetSpawnedSquadAt(SGroup_FromName(t_Bastion_Cultist_Raid_Army.squadname[j]), 1), g_Player3)
			
		
		end
	end
	
	--this is to prevent the squads from going back to their spawn point while en route to their attack
	for d = 1, table.getn(t_Bastion_Cultist_Raid_Army.squadname) do 
	
		SGroup_Clear(SGroup_FromName(t_Bastion_Cultist_Raid_Army.squadname[d]))
		
	end

	Rule_Remove(Rule_Bastion_Cultist_Raid_Attack)
	Rule_AddIntervalDelay(Rule_Bastion_Cultist_Raid, 30, 5)

end


--Bastion predator 1 function Rule_Bastion_Predator1_Raid()

t_Bastion_Predator1_Raid_Army = {
squadname = {--[[1]]"sg_Bastion_Predator_Raid1"},
squadnum = {--[[1]] 1},
squadsize = {--[[1]] 1},
}

if EGroup_Exists("eg_CM_Barrack_Bastion") and EGroup_IsEmpty("eg_CM_Barrack_Bastion") == false then


	local i = g_Bastion_Predator1_Size
	--there are two variables here "i" and "RB9Inc" they are linked to different systems. "i" incrememnts where in the spawning cycle we are for the number of squads and "RB9Inc" where we are in the difficulty cycle. The reason i am using "i' instead of a for loop
	--is that I didn't want to have four squads spawning at once and looking unfair to the player. 
	
	--checking how many squads in this group in order to prevent over population
	if SGroup_CountSpawned(SGroup_CreateIfNotFound("sg_Bastion_Predator1_Raid")) < 1 then
	
		Util_CreateSquadsAtMarkerEx(g_Player2, t_Bastion_Predator1_Raid_Army.squadname[i], "chaos_squad_predator", "mkr_CM_Vehicle_Bastion_Spawn", t_Bastion_Predator1_Raid_Army.squadnum[1], 
		t_Bastion_Predator1_Raid_Army.squadsize[1])

		SGroup_AddGroup(SGroup_CreateIfNotFound("sg_Bastion_Predator1_Raid"), SGroup_FromName( t_Bastion_Predator1_Raid_Army.squadname[i]))


		if g_Bastion_Predator1_Size <  table.getn(t_Bastion_Predator1_Raid_Army.squadname) then

			g_Bastion_Predator1_Size = g_Bastion_Predator1_Size + 1
	
	end
	
	elseif g_Bastion_Predator1_Size == table.getn(t_Bastion_Predator1_Raid_Army.squadname) then
	
		g_Bastion_Predator1_Size = 1
		
		Rule_Remove(Rule_Bastion_Predator1_Raid)			
		Rule_Add(Rule_Bastion_Predator1_Attack)
	
	end


else

	Rule_Remove(Rule_Bastion_Predator1_Raid)

end

end

--this is done in a seperate function than Rule_RB2_Marine1_Raid in order to be able to to re-add Rule_RB2_Marine1_Raid after a delay and not get an error about the rule still existing. function Rule_Bastion_Predator1_Attack()

	--checks to see if the player has an HQ and if yes to go attack it
	EGroup_Clear(EGroup_CreateIfNotFound("eg_Player1_Buildings"))
	EGroup_AddGroup(EGroup_FromName("eg_Player1_Buildings"), Player_GetEntities(g_Player1))
	
	local countbuilding = EGroup_CountSpawned(EGroup_FromName("eg_Player1_Buildings"))
	
	for i = 1, countbuilding do
	
		EGroup_Clear(EGroup_CreateIfNotFound("eg_Potential_HQ"))
		EGroup_Add(EGroup_FromName("eg_Potential_HQ"), EGroup_GetSpawnedEntityAt("eg_Player1_Buildings", i))

		if EGroup_ContainsBlueprints(EGroup_FromName("eg_Potential_HQ"), t_blueprinthq, true) then
		
			pos_HQ = Entity_GetPosition( EGroup_GetSpawnedEntityAt("eg_Potential_HQ", 1))
			Cmd_AttackMovePos("sg_Bastion_Predator1_Raid", pos_HQ)
	
			
			--at this point we want to stop the for loop
			break

		end
	end

	--this is the table in the spawning rule Rule_RB2_Marine1_Raid
	for j = 1, table.getn(t_Bastion_Predator1_Raid_Army.squadname) do 
		--check to see if the squads are idle. if they are then it means the player has no HQ in which case they are given to the active AI player
		if SGroup_IsEmpty(t_Bastion_Predator1_Raid_Army.squadname[j]) == false then 

			Squad_SetPlayerOwner(SGroup_GetSpawnedSquadAt(SGroup_FromName(t_Bastion_Predator1_Raid_Army.squadname[j]), 1), g_Player3)
			
		end
	end

	--this is to prevent the squads from going back to their spawn point while en route to their attack
	for d = 1, table.getn(t_Bastion_Marine1_Raid_Army.squadname) do 
	
		SGroup_Clear(SGroup_FromName(t_Bastion_Marine1_Raid_Army.squadname[d]))
		
	end
	
	Rule_Remove(Rule_Bastion_Predator1_Attack)
	Rule_AddIntervalDelay(Rule_Bastion_Predator1_Raid, 300, 300)

end

function Rule_BloodThirster()

if EGroup_IsCapturedByPlayer("eg_CM_Strat1", g_Player1, true) == false then

	if EGroup_Exists("eg_RB2_3") and EGroup_IsEmpty("eg_RB2_3") == false then

		if SGroup_Exists("sg_BloodThirster") == false or SGroup_Exists("sg_BloodThirster") and SGroup_IsEmpty("sg_BloodThirster") then

			if EGroup_Exists("eg_RB2_10") and EGroup_IsEmpty("eg_RB2_10") == false then

				--create a sorcerer
				Util_CreateSquadsAtMarker(g_Player2, "sg_BloodThirster", "chaos_squad_sorcerer_stronghold_sp", "mkr_RB2_Building10_Spawn", 1)
				
				Cmd_MoveToMarker("sg_BloodThirster", "mkr_KO5_4")
				
				if g_BT_First == true then
				
					Rule_AddInterval(Rule_Sorcerer_First_Transform, 5)
				
				elseif g_BT_First ==  false then
					
					Rule_AddInterval(Rule_Sorcerer_Transformation, 5)
				
				end
				
				Rule_AddInterval(Rule_Make_New_Bloodthirster, 1200)

			end
		
		end

	elseif EGroup_Exists("eg_RB2_8") and EGroup_IsEmpty("eg_RB2_8") == false then

			if EGroup_Exists("eg_RB2_10") and EGroup_IsEmpty("eg_RB2_10") == false then
				
				--create a sorcerer
				Util_CreateSquadsAtMarker(g_Player2, "sg_BloodThirster", "chaos_squad_sorcerer_stronghold_sp", "mkr_RB2_Building10_Spawn", 1)
				
				Cmd_MoveToMarker("sg_BloodThirster", "mkr_KO5_4")
				
				if g_BT_First == true then
				
					Rule_AddOneShot(Rule_Sorcerer_First_Transform, 5)
				
				elseif g_BT_First ==  false then
					
					Rule_AddInterval(Rule_Sorcerer_Transformation, 5)
				
				end
				
				Rule_AddInterval(Rule_Make_New_Bloodthirster, 1200)
	
			
			end
	
	else

		Rule_Remove(Rule_BloodThirster)
	
	end

else

	Rule_Remove(Rule_BloodThirster)

end

end

function Rule_Sorcerer_First_Transform()

if Prox_AllSquadsNearMarker("sg_BloodThirster", "mkr_KO5_4") then
	
	if EGroup_Exists("eg_Greater_Sacrifical") and EGroup_IsEmpty("eg_Greater_Sacrifical") == false and EGroup_IsCapturedByPlayer("eg_CM_Strat1", g_Player1, true) == false then

		Util_StartNIS( EVENTS.NIS_Bloodthirster )
		Rule_Remove(Rule_Sorcerer_First_Transform)
	else
	
		Rule_Remove(Rule_Sorcerer_First_Transform)
	
	end
end
	

end

function Rule_Sorcerer_Transformation()

if Prox_AllSquadsNearMarker("sg_BloodThirster", "mkr_KO5_4") then

	if EGroup_Exists("eg_Greater_Sacrifical") and EGroup_IsEmpty("eg_Greater_Sacrifical") == false and EGroup_IsCapturedByPlayer("eg_CM_Strat1", g_Player1, true) == false then
		
		--the research grant than restrict is to prevent the AI from pumping out its own Bloodthirsters.
		Player_GrantResearch(g_Player2, "chaos_bloodthirster_research")
		Cmd_Possesion("sg_BloodThirster")
		Rule_AddOneShot(Rule_Transfer_Ownership, 10)
		Rule_Remove(Rule_Sorcerer_Transformation)
		Player_RestrictResearch(g_Player2, "chaos_bloodthirster_research")
	else
	
		Rule_Remove(Rule_Sorcerer_Transformation)
	
	end


end

end

function Rule_Transfer_Ownership()

--gives the bloodthirster to the active ai
SGroup_SetPlayerOwner("sg_BloodThirster", g_Player3)

end

function Rule_Make_New_Bloodthirster()

if SGroup_Exists("sg_BloodThirster") == false or SGroup_Exists("sg_BloodThirster") and SGroup_IsEmpty("sg_BloodThirster") then

	Rule_AddOneShot(Rule_BloodThirster, 30)
	Rule_Remove(Rule_Make_New_Bloodthirster)

end

end


--[[Proximity check for bastion spawning ]]

function Rule_Bastion_Spawning_Prox_Check() --check to see if the player has breached the perimiter of the bastion before begining the spawning of raids from there for i = 1, 6 do

	if Player_AreSquadsNearMarker(g_Player1, "mkr_Bastion_Breach"..i) then

		Rule_AddOneShot(Rule_Bastion_Discussion, 5)	

		Rule_AddIntervalDelay(Rule_Bastion_Cultist_Raid, 30, 5)
		Rule_AddIntervalDelay(Rule_Bastion_Marine1_Raid, 150, 60)
		Rule_AddIntervalDelay(Rule_Bastion_Predator1_Raid, 300, 300)
		
		Rule_Remove(Rule_Bastion_Spawning_Prox_Check)


	end
	
end

end


--[[Proximity check for chaos stealth ]]

function Rule_Bastion_Stealth_Prox_Check() --check to see if the player has breached the perimiter of the bastion and if he has give the chaos player his stealth research for i = 1, 2 do

	if Player_AreSquadsNearMarker(g_Player1, "mkr_Bastion_Stealth_Check"..i) then

		Player_GrantResearch(g_Player2, "chaos_infiltration_research")
		Player_GrantResearch(g_Player3, "chaos_infiltration_research")
		
		Player_GrantResearch(g_Player2, "chaos_purge_the_weak")
		Player_GrantResearch(g_Player3, "chaos_purge_the_weak")
		
		--REMOVED FROM GAME
		--Player_GrantResearch(g_Player2, "chaos_possessed_daemon_mutation_research")
		--Player_GrantResearch(g_Player3, "chaos_possessed_daemon_mutation_research")
		
		Player_GrantResearch(g_Player2, "chaos_possessed_daemon_fire_research")
		Player_GrantResearch(g_Player3, "chaos_possessed_daemon_fire_research")
	
		Rule_Remove(Rule_Bastion_Stealth_Prox_Check)


	end
	
end

end


--[[Proximity check for relic chatter ]]

function Rule_Relic_Talk()

if Player_AreSquadsNearMarker(g_Player1, "mkr_Khorne_Defender3") then

	Rule_Check_AddOneShot(Rule_Relic_Discussion, 5)
	Rule_Remove(Rule_Relic_Talk)
	
end

end


--[[ Spawning the prisoners and the jailer ]]

function Rule_Spawn_Prisoners()

for i = 1, table.getn(t_Prisoners) do
	
	Util_CreateSquadsAtMarker(g_Player5, "sg_Prisoners"..i, t_Prisoners[i], "mkr_Prisoner"..i, 1)
	SGroup_AddGroup(SGroup_CreateIfNotFound("sg_Prisoners"), SGroup_CreateIfNotFound("sg_Prisoners"..i))
	
end

Util_CreateSquadsAtMarker(g_Player2, "sg_Jailer", "chaos_squad_sorcerer_torment_sp", "mkr_Jailer", 1)


Rule_AddOneShot(Rule_Jail, 2)
	

end

function Rule_Jail()

Cmd_CastAbilitySGroup("sg_Jailer", "Chaos_chains_of_torment_sp", "sg_Prisoners1")
Rule_AddOneShot(Rule_Jail2, 1)	

end

function Rule_Jail2()

Cmd_CastAbilitySGroup("sg_Jailer", "Chaos_chains_of_torment_sp_2", "sg_Prisoners2")
Rule_AddOneShot(Rule_Jail3, 1)	

end

function Rule_Jail3()

Cmd_CastAbilitySGroup("sg_Jailer", "Chaos_chains_of_torment_sp_3", "sg_Prisoners3")
Rule_AddOneShot(Rule_Jail4, 1)	

end

function Rule_Jail4()

Cmd_CastAbilitySGroup("sg_Jailer", "Chaos_chains_of_torment_sp_4", "sg_Prisoners4")
Rule_Add(Rule_Jailer_Dead)

end

function Rule_Jailer_Dead() --check to see the health of the jailer before transfering the prisoners to the player

	if SGroup_Exists("sg_Jailer") == false or SGroup_Exists("sg_Jailer") and SGroup_IsEmpty("sg_Jailer") then
		g_PrisonersStop = true
		
		World_FXEventSquad("data:Art/Events/Unit_Upgrade_Morale_FX/Reinforce_Trooper", SGroup_FromName("sg_Prisoners"))
		SGroup_SetPlayerOwner("sg_Prisoners", g_Player1)
		Rule_Remove(Rule_Jailer_Dead)
	
	end

end

--[[ Chatty AI ]]

--this is to have the AI send generic messages to the player every x seconds. So far they're not supposed to repeat but are supposed to be random

t_Talk = { false, false, false, false, false, false, false, false, false, false}

function Rule_Trash_Talk()

t_Event ={EVENTS.IE_Generic1, EVENTS.IE_Generic2, EVENTS.IE_Generic3, EVENTS.IE_Generic4, EVENTS.IE_Generic5, EVENTS.IE_Generic6, EVENTS.IE_Generic7, EVENTS.IE_Generic8, EVENTS.IE_Generic9, EVENTS.IE_Generic10} local i = World_GetRand(1, 10)

if Event_IsAnyRunning() == false and t_Talk[i] == false then

	Util_StartIntel(t_Event[i])
	t_Talk[i] = true

end

end

---[[opening taunts]]

function Rule_Opening_Discussion()

local humanplayer = MetaMap_GetPlayerRaceName()

if humanplayer == "chaos_marine_race" then

	--[[no text since this is the chaos stronghold]]
	
elseif humanplayer == "eldar_race" then

	Util_StartIntel(EVENTS.IE_Eldar_Start)

elseif humanplayer == "guard_race" then

	Util_StartIntel(EVENTS.IE_IG_Start)

elseif humanplayer == "ork_race" then

	Util_StartIntel(EVENTS.IE_Ork_Start)	

elseif humanplayer =="space_marine_race" then

	Util_StartIntel(EVENTS.IE_SM_Start)

elseif humanplayer == "tau_race" then

	Util_StartIntel(EVENTS.IE_Tau_Start)

elseif humanplayer == "necron_race" then

	Util_StartIntel(EVENTS.IE_Necron_Start)
	
end

end

--[[relic discovered taunt]]

function Rule_Relic_Discussion()

local humanplayer = MetaMap_GetPlayerRaceName()

if humanplayer == "chaos_marine_race" then

	--[[no text since this is the chaos stronghold]]
	
elseif humanplayer == "eldar_race" then

	Util_StartIntel(EVENTS.IE_Eldar_Relic)

elseif humanplayer == "guard_race" then

	Util_StartIntel(EVENTS.IE_IG_Relic)

elseif humanplayer == "ork_race" then

	Util_StartIntel(EVENTS.IE_Ork_Relic)	

elseif humanplayer =="space_marine_race" then

	Util_StartIntel(EVENTS.IE_SM_Relic)

elseif humanplayer == "tau_race" then

	Util_StartIntel(EVENTS.IE_Tau_Relic)

elseif humanplayer == "necron_race" then

	Util_StartIntel(EVENTS.IE_Necron_Relic)
	
end

end

--[[Bastion breach taunt]]

function Rule_Bastion_Discussion()

local humanplayer = MetaMap_GetPlayerRaceName()

if humanplayer == "chaos_marine_race" then

	--[[no text since this is the chaos stronghold]]
	
elseif humanplayer == "eldar_race" then

	Util_StartIntel(EVENTS.IE_Eldar_Bastion)

elseif humanplayer == "guard_race" then

	Util_StartIntel(EVENTS.IE_IG_Bastion)

elseif humanplayer == "ork_race" then

	Util_StartIntel(EVENTS.IE_Ork_Bastion)	

elseif humanplayer =="space_marine_race" then

	Util_StartIntel(EVENTS.IE_SM_Bastion)

elseif humanplayer == "tau_race" then

	Util_StartIntel(EVENTS.IE_Tau_Bastion)

elseif humanplayer == "necron_race" then

	Util_StartIntel(EVENTS.IE_Necron_Bastion)
	
end

end


--[[Timer ]]

function Rule_Add_Timer() --warning g_Timer is used elsewhere. if you remove the counter make sure that you leave the function updating the timer

	Rule_AddInterval(Rule_Increment_Timer, 60)

end

function Rule_Increment_Timer() --warning g_Timer is used elsewhere. if you remove the counter make sure that you leave the function updating the timer g_Timer = g_Timer +1

end

--[[ win loss ]]

function Rule_EndGame_Win()

if EGroup_Exists("eg_Gate") == false or (EGroup_Exists("eg_Gate") and EGroup_IsEmpty("eg_Gate")) then

	g_Win = true
	
	Util_StartNIS(EVENTS.NIS_Closing)
	Rule_Remove( Rule_EndGame_Win )
	Rule_Remove(Rule_EndGameLose)

end

end

function Rule_EndGameLose()

g_building_exceptions = 
{
	"guard_thermo_plasma",
	"guard_plasma_generator",
	"guard_turret_heavy_bolter",
	"guard_mines"
}

g_unit_exceptions = 
{

}

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

end

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


--[[ test ]]