--IMPORTS
import("ScarUtil.scar")
function CheatClosing()
Util_StartNIS( EVENTS.NIS_Closing )
end
function SetResearchLevel(level)
Restrict_SpaceMarines( g_Player1, level )
Player_RestrictResearch( g_Player1, "marine_librarian_research_1" )
Player_RestrictResearch( g_Player1, "marine_librarian_research_2" )
end
--GAME SETUP
function OnGameSetup() -- globals g_Player1 = Setup_Player(0, "$320001", "space_marine_race", 1) g_Player2 = Setup_Player(1, "$320002", "chaos_marine_race", 2) g_Player3 = Setup_Player(2, "$320003", "npc_race", TEAM_NEUTRAL ) g_Player4 = Setup_Player(3, "$320002", "chaos_marine_race", TEAM_NEUTRAL )
-- Initialised variable
g_aggrolevel = 0
--
-- Variable parameters for different difficulty modes
--
difficulty = { -- { EASY, NORMAL, HARD }
deepstriketermies = {3, 2, 1}, -- number of terminators dropped in with Garbiel's team
deepstrikeservitors = {3, 2, 1}, -- number of servitors dropped in with Garbiel's team
defendingdefilers = {1, 2, 2},
lemanrepairspeed = {2, 4, 6}, -- recovery rate of leman tanks
aggro1 = {500, 400, 300}, -- number of seconds before AI is forced up to Aggro Level 1
aggro2 = {800, 650, 500}, -- number of seconds before AI is forced up to Aggro Level 2
aggro3 = {1100, 900, 700} -- number of seconds before AI is forced up to Aggro Level 3
}
g_difset = 1
t_BaseDefense = {
sgroup = {"sg_harasspt2", "sg_harasspt3", "sg_harasspt4", "sg_harasspt5", "sg_relic1", "sg_relic2", "sg_relic3", "sg_relic4"},
marker = {"mkr_harasspt2", "mkr_harasspt3", "mkr_harasspt4", "mkr_harasspt5", "mkr_relic1", "mkr_relic2", "mkr_relic3", "mkr_relic4"},
blueprint = {"chaos_marine_squad", "chaos_squad_cultist", "chaos_squad_cultist"}
}
t_buildlimit = {
{"chaos_armoury", 2},
{"chaos_greater_sacrificial_circle", 2},
{"chaos_hq", 2},
{"chaos_machine_pit", 2},
{"chaos_plasma_generator", 8},
{"chaos_sacrificial_circle", 3},
{"chaos_temple", 4},
{"chaos_turret_bolter", 10}
}
g_timetoholdrelics = 180
t_deepstrikedone = false
t_deepstrikeping = 0
t_cultistambush = {}
t_cultistambush[1] = "mkr_cultistambush1"
t_cultistambush[2] = "mkr_cultistambush2"
t_cultistambush[3] = "mkr_cultistambush3"
t_cultistambush[4] = "mkr_cultistambush4"
t_cultistambush[5] = "mkr_cultistambush5"
t_cultistambush[6] = "mkr_cultistambush6"
t_cultistambush[7] = "mkr_cultistambush7"
t_cultistambush[8] = "mkr_cultistambush8"
t_ambushspawn = {}
t_ambushspawn[1] = "mkr_ambushspawn1"
t_ambushspawn[2] = "mkr_ambushspawn2"
t_ambushspawn[3] = "mkr_ambushspawn3"
t_ambushspawn[4] = "mkr_ambushspawn4"
t_ambushspawn[5] = "mkr_ambushspawn5"
t_ambushspawn[6] = "mkr_ambushspawn6"
t_ambushspawn[7] = "mkr_ambushspawn7"
t_ambushspawn[8] = "mkr_ambushspawn8"
-- List of tanks to be recuperated
t_lemanruss = {"sg_igtank1", "sg_igtank2", "sg_igtank3", "sg_igtank4", "sg_igtank5", "sg_igtank6"}
-- Some initial variables
t_balewanders = {"mkr_bale1", "mkr_bale2", "mkr_bale3", "mkr_bale4", "mkr_bale5"}
t_lastprotectorspawn = World_GetGameTime()
t_protectorsnum = 1
t_protectorsload = 4
g_timeron = false
end
function OnGameRestore()
g_Player1 = World_GetPlayerAt(0)
g_Player2 = World_GetPlayerAt(1)
g_Player3 = World_GetPlayerAt(2)
g_Player4 = World_GetPlayerAt(3)
g_timeron = false
end
--[[ ON INITIALIZATION ]]
function OnInit()
EventCue_Enable(false)
-- RESEARCH
SetResearchLevel( 9 )
SetupMusicPlaylist()
--[[ Preset Stage for NIS]]
Fade_Start( 0, false )
W40k_Letterbox( true, 0 )
SetDifficultyLevel()
Cpu_EnableAll(false)
--~ EGroup_DeSpawn( "eg_Maledictum" ) EGroup_DeSpawn( "eg_DeadMarines" ) Util_StartNIS(EVENTS.NIS_Opening);
--[[Start the Game]]
Rule_AddInterval(Rule_StartGame, 1);
g_objectiveP1completed = false
SetCommanderPowerSword( g_Player1 )
end
Scar_AddInit(OnInit)
-- MUSIC/SOUND
function SetupMusicPlaylist()
-- clear the current playlist
Sound_PlaylistClear( PC_Music )
-- add tracks to the playlist
Sound_PlaylistAddTrack( PC_Music, "music_tank_march" )
Sound_PlaylistAddTrack( PC_Music, "music_coming_of_chaos" )
Sound_PlaylistAddTrack( PC_Music, "music_theme_chaos_01" )
Sound_PlaylistAddTrack( PC_Music, "music_urban_wasteland" )
Sound_PlaylistAddTrack( PC_Music, "ambient_ingame_02" )
-- mark these tracks to play randomly
Sound_PlaylistSetorder( PC_Music, true )
-- add 5 to 10 seconds silence between tracks
Sound_PlaylistSetSilence( PC_Music, 20, 70 )
-- don't play yet
Sound_PlaylistClear( PC_Ambient )
-- add tracks to the playlist
Sound_PlaylistAddTrack( PC_Ambient, "ambient_wind" )
-- mark these tracks to play randomly
Sound_PlaylistSetorder( PC_Ambient, false )
-- add 5 to 10 seconds silence between tracks
Sound_PlaylistSetSilence( PC_Ambient, 5, 10 )
end
-- [[ DIFFICULTY LEVEL ]]
function SetDifficultyLevel()
local difficultyLevel = Difficulty_Get()
if difficultyLevel == DIFFICULTY_EASY then
g_difset = 1
Difficulty_SetForPlayer(g_Player2, 0)
Cpu_SetDifficulty(g_Player2, AD_Standard)
elseif difficultyLevel == DIFFICULTY_NORMAL then
g_difset = 2
Difficulty_SetForPlayer(g_Player2, 1)
Cpu_SetDifficulty(g_Player2, AD_Hard)
elseif difficultyLevel == DIFFICULTY_HARD then
g_difset = 3
Difficulty_SetForPlayer(g_Player2, 2)
Cpu_SetDifficulty(g_Player2, AD_Advanced)
end
end
-- START THE GAME CHECKS TO SEE IF NIS"S ARE PLAYING function Rule_StartGame()
if not Event_IsAnyRunning() then
--[[ Manage AI ]]
Rule_EnableAIPlayer2()
--~ Rule_EnableAIPlayer3()
--[[ Manage Guard Reinforcements ]]
Rule_Add(Rule_MachineSpiritsSetup)
Rule_AddInterval(Rule_GenerateFodder, 12)
Rule_AddInterval(Rule_MonitorInquisitor, 15)
--[[ Mid Game Deepstrike ]]
Rule_AddOneShot(Rule_DropZoneTimer, 740)
--[[ Chaos Stuff ]]
Rule_AddInterval(Rule_AggressionLevel, 5) -- check on the player's actions to up the aggro level
Rule_AddOneShot(Rule_AggressionLevelTimerSet1, difficulty.aggro1[g_difset]) -- set an automatic aggro level upgrade on a timer
Rule_AddOneShot(Rule_AggressionLevelTimerSet2, difficulty.aggro2[g_difset]) -- ditto
Rule_AddOneShot(Rule_AggressionLevelTimerSet3, difficulty.aggro3[g_difset]) -- ditto
Rule_AddInterval(Rule_ImplementAggressionLevel1, 15) -- make the changes once aggro level 1 has been attained
Rule_AddInterval(Rule_ImplementAggressionLevel2, 15) -- make the changes once aggro level 2 has been attained
Rule_AddInterval(Rule_ImplementAggressionLevel3, 15) -- make the changes once aggro level 3 has been attained
Rule_AddInterval(Rule_CultistAmbushGenerate, 15)
Rule_AddInterval(Rule_RelicArtillery, 135);
Rule_AddInterval(Rule_ChaosTempleChecker, 4)
Rule_AddInterval(Rule_ChaosBaseChecker, 7)
--[[ Lord Bale Stuff ]]
Rule_AddInterval(Rule_WanderingLordBale, 20)
Rule_AddInterval(Rule_ProtectLordBale, 5)
Cpu_LockSGroup(g_Player2, SGroup_FromName("sg_bale"))
--[[ Win Condition things ]]
Rule_AddInterval(Rule_AllRelicsCaptured, 5)
Rule_AddInterval(Rule_FirstRelicCaptured, 10)
Rule_AddInterval(Rule_Relic1Captured, 1)
Rule_AddInterval(Rule_Relic2Captured, 1)
Rule_AddInterval(Rule_Relic3Captured, 1)
Rule_AddInterval(Rule_Relic4Captured, 1)
obj_table_P1 = { title_id = 320010, short_desc_id = 320011, help_tip_id = 320012 } -- Capture the Relics
obj_table_P2 = { title_id = 320020, short_desc_id = 320021, help_tip_id = 320022 } -- Hold the Relics
obj_table_S1 = { title_id = 320015, short_desc_id = 320016, help_tip_id = 320017 } -- Destroy the Chaos Bases
Rule_AddOneShot(Rule_Objective_P1, 3)
Rule_AddOneShot(Rule_IE_TothCommand, 15)
Rule_AddOneShot(Rule_Objective_S1, 35)
Rule_AddInterval(Rule_PlayerLoses, 5)
Rule_Remove(Rule_StartGame)
Util_Autosave( "$320030" )
end
end
-- [[ AGGRESSION LEVEL ]]
-- -- Up Aggression Level at certain points following player actions
function Rule_AggressionLevel()
-- If you move into any of the four choke points
-- Up to Aggro Level 1
if (g_aggrolevel < 1) and (Player_AreSquadsNearMarker(g_Player1, "mkr_harasspt1") or Player_AreSquadsNearMarker(g_Player1, "mkr_harasspt2") or Player_AreSquadsNearMarker(g_Player1, "mkr_harasspt5") or Player_AreSquadsNearMarker(g_Player1, "mkr_harasspt6")) then
g_aggrolevel = 1
end
-- If you move into the center of the temple or the four entrance areas
-- Up to Aggro Level 2
if (g_aggrolevel < 2) and ( (Player_AreSquadsNearMarker(g_Player1, "mkr_centertemple")) or
(Player_AreSquadsNearMarker(g_Player1, "mkr_entrance1")) or
(Player_AreSquadsNearMarker(g_Player1, "mkr_entrance2")) or
(Player_AreSquadsNearMarker(g_Player1, "mkr_entrance3")) or
(Player_AreSquadsNearMarker(g_Player1, "mkr_entrance4")) ) then
g_aggrolevel = 2
end
-- If you capture any of the four relic points
-- Up to Aggro Level 3
if (g_aggrolevel < 3) and ((g_objrelic1 + g_objrelic2 + g_objrelic3 + g_objrelic4) >= 1) then
g_aggrolevel = 3
Rule_Remove(Rule_AggressionLevel)
end
end
-- -- Force Aggression Levels to a minimum (set on timers)
function Rule_AggressionLevelTimerSet1() if (g_aggrolevel < 1) then g_aggrolevel = 1 end end
function Rule_AggressionLevelTimerSet2() if (g_aggrolevel < 2) then g_aggrolevel = 2 end end
function Rule_AggressionLevelTimerSet3() if (g_aggrolevel < 3) then g_aggrolevel = 3 Rule_Remove(Rule_AggressionLevel) end end
-- -- Implement Changes for Aggression Level 1
function Rule_ImplementAggressionLevel1() if g_aggrolevel == 1 then
t_BaseDefense = {
sgroup = {"sg_harasspt1", "sg_harasspt2", "sg_harasspt3", "sg_harasspt4", "sg_harasspt5", "sg_harasspt6", "sg_relic1", "sg_relic2", "sg_relic3", "sg_relic4"},
marker = {"mkr_harasspt1", "mkr_harasspt2", "mkr_harasspt3", "mkr_harasspt4", "mkr_harasspt5", "mkr_harasspt6", "mkr_relic1", "mkr_relic2", "mkr_relic3", "mkr_relic4"},
blueprint = {"chaos_marine_squad", "chaos_marine_squad", "chaos_squad_cultist"}
}
t_balewanders = {"mkr_bale1", "mkr_bale2", "mkr_bale3", "mkr_bale4", "mkr_bale5", "mkr_aggro1a", "mkr_aggro1b"}
Rule_AddOneShot(Rule_UpgradeAIPlayer2, 1)
Rule_Remove(Rule_ImplementAggressionLevel1)
end
end
-- -- Implement Changes for Aggression Level 2
function Rule_ImplementAggressionLevel2() if g_aggrolevel == 2 then
t_BaseDefense = {
sgroup = {"sg_harasspt1", "sg_harasspt2", "sg_harasspt3", "sg_harasspt4", "sg_harasspt5", "sg_harasspt6", "sg_aggro1a", "sg_aggro1b", "sg_relic1", "sg_relic2", "sg_relic3", "sg_relic4"},
marker = {"mkr_harasspt1", "mkr_harasspt2", "mkr_harasspt3", "mkr_harasspt4", "mkr_harasspt5", "mkr_harasspt6", "mkr_aggro1a", "mkr_aggro1b", "mkr_relic1", "mkr_relic2", "mkr_relic3", "mkr_relic4"},
blueprint = {"chaos_squad_raptor", "chaos_marine_squad", "chaos_marine_squad"}
}
t_balewanders = {"mkr_aggro1a", "mkr_aggro1b", "mkr_aggro2a", "mkr_aggro2b", "mkr_aggro2c"}
Rule_Remove(Rule_ImplementAggressionLevel2)
end
end
-- -- Implement Changes for Aggression Level 3
function Rule_ImplementAggressionLevel3() if g_aggrolevel == 3 then
t_BaseDefense = {
sgroup = {"sg_harasspt1", "sg_harasspt2", "sg_harasspt5", "sg_harasspt6", "sg_aggro1a", "sg_aggro1b", "sg_aggro2a", "sg_aggro2b", "sg_aggro2c", "sg_relic1", "sg_relic2", "sg_relic3", "sg_relic4"},
marker = {"mkr_harasspt1", "mkr_harasspt2", "mkr_harasspt5", "mkr_harasspt6", "mkr_aggro1a", "mkr_aggro1b", "mkr_aggro2a", "mkr_aggro2b", "mkr_aggro2c", "mkr_relic1", "mkr_relic2", "mkr_relic3", "mkr_relic4"},
blueprint = {"chaos_squad_obliterator", "chaos_squad_raptor", "chaos_squad_raptor", "chaos_squad_raptor", "chaos_marine_squad", "chaos_marine_squad", "chaos_marine_squad"}
}
t_balewanders = {"mkr_relic1", "mkr_relic2", "mkr_relic3", "mkr_relic4"}
Rule_Remove(Rule_ImplementAggressionLevel3)
end
end
--[[OBJECTIVES ]] function Rule_Objective_P1() Util_ObjectiveCreate(obj_table_P1, true) Util_Ping_LoopingMkr("pg_Relic1", "mkr_relic1") Util_Ping_LoopingMkr("pg_Relic2", "mkr_relic2") Util_Ping_LoopingMkr("pg_Relic3", "mkr_relic3") Util_Ping_LoopingMkr("pg_Relic4", "mkr_relic4") Rule_AddOneShot(Rule_IE_CaptureRelics, 0.5) end
function Rule_Objective_P2() Util_ObjectiveCreate(obj_table_P2, true) Rule_AddOneShot(Rule_IE_HoldRelics, 0.5) end
function Rule_Objective_S1() Util_ObjectiveCreate(obj_table_S1, false) Rule_AddOneShot(Rule_IE_DestroyBases, 0.5) end
--[[INTEL EVENTS ]] function Rule_IE_TothCommand() Util_StartIntel(EVENTS.IE_TothCommand) end
function Rule_IE_GabrielArrives() Util_StartIntel(EVENTS.IE_GabrielArrives) Util_Autosave( "$320031" ) end
function Rule_IE_CaptureRelics() Util_StartIntel(EVENTS.IE_CaptureRelics) end
function Rule_IE_DestroyBases() Util_StartIntel(EVENTS.IE_DestroyBases) end
function Rule_IE_HoldRelics() Util_StartIntel(EVENTS.IE_HoldRelics) end
--[[ AI STUFF ]]
function Rule_EnableAIPlayer2()
Cpu_Enable( g_Player2, true )
Player_GrantResearch( g_Player2, "squad_cap_research_1")
Player_GrantResearch( g_Player2, "squad_cap_research_2")
Player_GrantResearch( g_Player2, "squad_cap_research_3")
Player_GrantResearch( g_Player2, "support_cap_research_1")
Player_RestrictSquad( g_Player2, "chaos_squad_lord" )
Player_RestrictSquad( g_Player2, "chaos_squad_bloodthirster" )
Player_RestrictSquad( g_Player2, "chaos_squad_sorcerer" )
Player_RestrictResearch( g_Player2, "chaos_bloodthirster_research" )
--[[ Cpu_StopBuildOrder( g_Player2 ) ]]
Cpu_LockSGroup(g_Player2, "sg_cpulock")
Cpu_SetClassPreference(g_Player2, UC_LightInfantryLow, 10)
Cpu_SetClassPreference(g_Player2, UC_LightInfantryMed, 10)
Cpu_SetClassPreference(g_Player2, UC_LightInfantryHigh, 10)
Cpu_SetClassPreference(g_Player2, UC_HeavyInfantryMed, 1)
Cpu_SetClassPreference(g_Player2, UC_HeavyInfantryHigh, 1)
Cpu_SetClassPreference(g_Player2, UC_VehicleLow, 1)
Cpu_SetClassPreference(g_Player2, UC_VehicleMed, 1)
Cpu_SetClassPreference(g_Player2, UC_VehicleHigh, 1)
Cpu_SetBuildingLimitsTable(g_Player2, t_buildlimit)
end
function Rule_UpgradeAIPlayer2()
Cpu_SetClassPreference(g_Player2, UC_LightInfantryLow, 1)
Cpu_SetClassPreference(g_Player2, UC_LightInfantryMed, 1)
Cpu_SetClassPreference(g_Player2, UC_LightInfantryHigh, 1)
Cpu_SetClassPreference(g_Player2, UC_HeavyInfantryMed, 5)
Cpu_SetClassPreference(g_Player2, UC_HeavyInfantryHigh, 5)
Cpu_SetClassPreference(g_Player2, UC_VehicleLow, 2)
Cpu_SetClassPreference(g_Player2, UC_VehicleMed, 2)
Cpu_SetClassPreference(g_Player2, UC_VehicleHigh, 2)
end
function Rule_EnableAIPlayer3()
Cpu_Enable(g_Player3, 0)
Cpu_Enable(g_Player4, 0)
end
-- [[ WIN CONDITION STUFF ]] -- [[ Relic Tracker ]]
-- -- Individual Relic Checks
function Rule_Relic1Captured() if EGroup_IsCapturedByPlayer("eg_objrelic1", g_Player1, false) then g_objrelic1 = 1 Util_Ping_Stop("pg_Relic1") else g_objrelic1 = 0 end end
function Rule_Relic2Captured() if EGroup_IsCapturedByPlayer("eg_objrelic2", g_Player1, false) then Util_Ping_Stop("pg_Relic2") g_objrelic2 = 1 else g_objrelic2 = 0 end end
function Rule_Relic3Captured() if EGroup_IsCapturedByPlayer("eg_objrelic3", g_Player1, false) then Util_Ping_Stop("pg_Relic3") g_objrelic3 = 1 else g_objrelic3 = 0 end end
function Rule_Relic4Captured() if EGroup_IsCapturedByPlayer("eg_objrelic4", g_Player1, false) then Util_Ping_Stop("pg_Relic4") g_objrelic4 = 1 else g_objrelic4 = 0 end end
-- -- Trigger the dropships to come in early once the first relic has been captured
function Rule_FirstRelicCaptured() if (g_objrelic1 + g_objrelic2 + g_objrelic3 + g_objrelic4) >= 1 then if (t_deepstrikedone == false) then
-- call it in
Rule_AddOneShot(Rule_DropZoneDo, 10)
-- set a flag to stop this triggering again
t_deepstrikedone = true
end
Rule_Remove(Rule_FirstRelicCaptured)
end
end
-- -- Check if all relics have been captured
function Rule_AllRelicsCaptured()
if (g_objrelic1+g_objrelic2+g_objrelic3+g_objrelic4) == 4 then
if not Rule_Exists(Rule_AllRelicsHeld) then
g_allrelics = 0
-- if this is the first time all four Relics have been captured
if (g_objectiveP1completed == false) then
g_objectiveP1completed = true
Rule_AddOneShot(Rule_Objective_P2, 0.5)
Util_ObjectiveComplete(obj_table_P1.title_id)
--~ Rule_Remove(Rule_AllRelicsCaptured) Util_Autosave( "$320032" ) --~ return end
Rule_AddInterval(Rule_AllRelicsHeld, 1)
end
else
end
end
-- -- Check if all the relics have been held for three minutes
function Rule_AllRelicsHeld()
if (g_objrelic1+g_objrelic2+g_objrelic3+g_objrelic4) < 4 then
UI_HideCountdown()
g_allrelics = 0
Rule_Remove(Rule_AllRelicsHeld)
elseif (g_objrelic1+g_objrelic2+g_objrelic3+g_objrelic4) == 4 and g_allrelics < g_timetoholdrelics then
g_allrelics = g_allrelics+1
--~ print(g_allrelics) if not Rule_Exists( Rule_DisplayTimer ) and g_timeron == false then Rule_Add(Rule_DisplayTimer) end elseif (g_objrelic1+g_objrelic2+g_objrelic3+g_objrelic4) == 4 and g_allrelics >= g_timetoholdrelics then
Util_ObjectiveComplete(obj_table_P2.title_id)
if g_baseisdead == 0 then
Util_ObjectiveFail(obj_table_S1.title_id)
end
Util_StartNIS(EVENTS.NIS_Closing)
--~ Rule_Remove( Rule_AllRelicsHeld ) Rule_RemoveAll() end
end
function Rule_DisplayTimer() UI_ShowCountdown( 320200, g_timetoholdrelics ) g_timeron = true Rule_Remove(Rule_DisplayTimer) end
-- [[ CHAOS STUFF ]] --[[ Temple Tracker ]] function Rule_ChaosTempleChecker()
EGroup_AddGroup(EGroup_CreateIfNotFound("eg_Player2All"), Player_GetEntities(g_Player2))
local blueprinttable = {
{ name = "chaos_temple", count = 1 }
}
Rule_AddTemples = function( egroupid, itemindex, entityID )
if Entity_GetBlueprintName(entityID) == "chaos_temple" and Entity_GetBuildingProgress(entityID) == 1.0 then
EGroup_Add(EGroup_CreateIfNotFound("eg_Player2Temples"), entityID)
end
end
if EGroup_ContainsBlueprints("eg_Player2All", blueprinttable, false) == true then
EGroup_ForEach(EGroup_FromName("eg_Player2All"), Rule_AddTemples)
if not EGroup_IsEmpty("eg_Player2Temples") then
if not Rule_Exists(Rule_BaseDefense) then
Rule_AddInterval(Rule_BaseDefense, 5)
end
end
end
end
--[[ Chaos Base Tracker ]] function Rule_ChaosBaseChecker()
EGroup_AddGroup(EGroup_CreateIfNotFound("eg_Player2All"), Player_GetEntities(g_Player2))
local blueprinttable = {
{ name = "chaos_temple", count = 1 },
{ name = "chaos_armoury", count = 1 },
{ name = "chaos_greater_sacrificial_circle", count = 1 },
{ name = "chaos_machine_pit", count = 1 },
{ name = "chaos_plasma_generator", count = 1 },
{ name = "chaos_thermo_plasma_generator", count = 1 },
{ name = "chaos_sacrificial_circle", count = 1 }
}
local Rule_AddBuildings = function( egroupid, itemindex, entityID )
if Entity_GetBlueprintName(entityID) == "chaos_temple"
or Entity_GetBlueprintName(entityID) == "chaos_armoury"
or Entity_GetBlueprintName(entityID) == "chaos_greater_sacrificial_circle"
or Entity_GetBlueprintName(entityID) == "chaos_machine_pit"
or Entity_GetBlueprintName(entityID) == "chaos_plasma_generator"
or Entity_GetBlueprintName(entityID) == "chaos_thermo_plasma_generator"
or Entity_GetBlueprintName(entityID) == "chaos_sacrificial_circle"
then
EGroup_Add(EGroup_CreateIfNotFound("eg_Player2Base"), entityID)
end
end
if EGroup_ContainsBlueprints("eg_Player2All", blueprinttable, false) == false then
-- print("Player 2's bases have been Anihilated") g_baseisdead = 1 Util_ObjectiveComplete(obj_table_S1.title_id) Rule_Remove(Rule_ChaosBaseChecker) else EGroup_ForEach(EGroup_FromName("eg_Player2All"), Rule_AddBuildings) g_baseisdead = 0 -- print("Player 2's base complex has "..EGroup_Count(EGroup_FromName("eg_Player2Base")).." entities") end end
--[[ BASE DEFENSE ]]
-- -- Run the base defenses
function Rule_BaseDefense()
if EGroup_IsEmpty("eg_Player2Temples") or g_baseisdead == 1 then
Rule_Remove(Rule_BaseDefense)
else
for i = table.getn(t_BaseDefense.sgroup), 1, -1 do
SGroup_CreateIfNotFound(t_BaseDefense.sgroup[i])
SGroup_Clear(SGroup_CreateIfNotFound("sg_marker"))
local sgroupID = Player_GetAllSquadsNearMarker(g_Player1, "sg_marker", t_BaseDefense.marker[i])
if SGroup_IsEmpty("sg_marker") ~= true and SGroup_IsEmpty( t_BaseDefense.sgroup[i]) == true then
local rand1 = World_GetRand(1, table.getn(t_BaseDefense.blueprint)) -- a random blueprint from the list
local numberoftemples = EGroup_Count(EGroup_FromName("eg_Player2Temples")) -- number of Chaos Temples
local randomtemple = 1
if (numberoftemples > 1) then
randomtemple = World_GetRand(1, numberoftemples)
end
local pos = Entity_GetPosition(EGroup_GetSpawnedEntityAt(EGroup_FromName("eg_Player2Temples"), randomtemple)) -- Position of a random Temple in list
local rand2 = World_GetRand(5, 8) -- a random squad size
--print("rand1 = "..rand1)
--print("number of temples is "..num)
--table.foreach(pos, print)
--print("rand2 = "..rand2)
Util_CreateSquadsAtPositionEx(g_Player2, t_BaseDefense.sgroup[i],t_BaseDefense.blueprint[rand1],pos, 1, rand2)
Deg_AddtoCpuLockGroup(g_Player2, t_BaseDefense.sgroup[i])
Cmd_SetStance(t_BaseDefense.sgroup[i], STANCE_Attack)
Cmd_AttackMoveMarker(t_BaseDefense.sgroup[i], t_BaseDefense.marker[i])
break
end
end
end
end
--[[ DEEP STRIKE ACTION ]]
-- -- Timer Check
function Rule_DropZoneTimer() -- if the drop hasn't been called in by now if (t_deepstrikedone == false) then
-- call it in
Rule_AddOneShot(Rule_DropZoneDo, 1)
-- set a flag to stop this triggering again
t_deepstrikedone = true
end
end
-- -- Set up the sequence
function Rule_DropZoneDo()
-- clear the fog in the strike area and ping on minimap
FOW_RevealMarker("mkr_dsdrop", -1);
t_deepstrikeping = Ping_Marker("mkr_dsdrop", true)
-- call all of the individual drop-pods
Rule_AddOneShot(Rule_DeepstrikeScouts, 10)
Rule_AddOneShot(Rule_DeepstrikeGabriel, 13)
Rule_AddOneShot(Rule_DeepstrikeTermies, 17)
Rule_AddOneShot(Rule_DeepstrikeServitors, 19)
Rule_AddOneShot(Rule_DeepstrikeCleanup, 20)
-- set up the ambush
Rule_AddOneShot(Rule_DeepstrikeAmbush, 30)
end
-- -- Individual drop-pod elements
function Rule_DeepstrikeScouts() Util_CreateSquadsAndDropPodIn(g_Player1, "sg_dsscouts", "space_marine_squad_scout", Marker_GetPosition(Marker_FromName("mkr_dsscouts", "basic_marker")), 2, 2) end
function Rule_DeepstrikeGabriel() SetCommanderPowerSword( g_Player1) Util_CreateSquadsAndDropPodIn(g_Player1, "sg_dsgabriel", "space_marine_squad_force_commander", Marker_GetPosition(Marker_FromName("mkr_dsgabriel", "basic_marker")), 1, 1) Rule_AddOneShot(Rule_IE_GabrielArrives, 5) Rule_AddInterval(Rule_MonitorGabriel, 15)
end
function Rule_DeepstrikeTermies() local numtermies = difficulty.deepstriketermies[g_difset] -- Player_UnRestrictSquad(g_Player1, "space_marine_squad_force_commander") Util_CreateSquadsAndDropPodIn(g_Player1, "sg_dstermies", "space_marine_squad_terminator", Marker_GetPosition(Marker_FromName("mkr_dstermies", "basic_marker")), numtermies, 4) end
function Rule_DeepstrikeServitors() local numservitor = difficulty.deepstrikeservitors[g_difset] Util_CreateSquadsAndDropPodIn(g_Player1, "sg_dsservitor", "space_marine_squad_servitor", Marker_GetPosition(Marker_FromName("mkr_dsservitor", "basic_marker")), numservitor, 1) end
function Rule_DeepstrikeCleanup() -- clear up the fog reveal you did earlier and kill the ping local pos = Marker_GetPosition(Marker_FromName("mkr_dsdrop", "basic_marker")) local radius = Marker_GetProximity(Marker_FromName("mkr_dsdrop", "basic_marker")) FOW_UnRevealArea(pos.x, pos.z, radius); Ping_Stop(t_deepstrikeping) end
-- -- Lead Character Respawn Functions
function Rule_MonitorGabriel() Util_TrackCharacterAndDropPodIn(g_Player1, "sg_dsgabriel", "space_marine_squad_force_commander", "mkr_dsgabriel") end
function Rule_MonitorInquisitor() Util_TrackCharacterAndDropPodIn(g_Player1, "sg_Inquisition", "guard_squad_inquisitor", "mkr_guardspawn" ) end
--[[ DEEPSTRIKE RETALIATION ]] --Initial Ambush function Rule_DeepstrikeAmbush()
for i = 1, 2 do
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_dsambush"..i, "chaos_squad_cultist", "mkr_dsambush"..i, 2, 9)
Cmd_AttackMoveMarker("sg_dsambush"..i, "mkr_dsdrop")
Deg_AddtoCpuLockGroup(g_Player2, "sg_dsambush"..i);
end
end
--[ CULTIST AMBUSH ACTION ]]
--[[RANDOM TIME CALLER FOR THE AMBUSH
function Rule_CultistAmbushCaller()
if not Rule_Exists(Rule_CultistAmbushGenerate) then
Rule_AddInterval(Rule_CultistAmbushGenerate, 5)
end
end]]
--CHECKING THE SPAWN POINTS AND CREATING THE CULTISTS function Rule_CultistAmbushGenerate()
local sgroupname = Player_AddSquadsToSGroup(g_Player1, "sg_ambushtarget")
-- If the player ventures far enough to see a spawn point, never spawn from that point again
for i = table.getn(t_cultistambush), 1, -1 do
if Player_CanSeePosition(g_Player1, Marker_GetPosition(Marker_FromName(t_ambushspawn[i], "basic_marker"))) then
if table.getn(t_cultistambush) == 0 then
Rule_Remove(Rule_CultistAmbushCaller)
Rule_Remove(Rule_CultistAmbushGenerate)
break
elseif table.getn(t_cultistambush) > 1 then
table.remove(t_cultistambush, i)
table.remove(t_ambushspawn, i)
end
end
end
-- Spawn enemies to ambush any marker zone the player is in
for i = 1, table.getn(t_cultistambush) do
if Prox_AnySquadNearMarker("sg_ambushtarget", t_cultistambush[i]) then
SGroup_CreateIfNotFound("sg_cultistambush"..i)
if SGroup_IsEmpty("sg_cultistambush"..i) and Player_CanSeePosition(g_Player1, Marker_GetPosition(Marker_FromName(t_ambushspawn[i], "basic_marker"))) == false then
Util_CreateSquadsAtMarkerEx(g_Player2, "sg_cultistambush"..i, t_BaseDefense.blueprint[World_GetRand(1, table.getn(t_BaseDefense.blueprint))], t_ambushspawn[i], 1, 8)
Deg_AddtoCpuLockGroup(g_Player2, "sg_cultistambush"..i)
end
Cmd_AttackMoveMarker("sg_cultistambush"..i, "mkr_dsdrop")
end
end
-- Remove the rule if all zones have been killed off
if (table.getn(t_cultistambush) == 0) then
Rule_Remove(Rule_CultistAmbushGenerate)
end
end
--[[ ARTILLERY DEFENSE OF RELICS ]] function Rule_RelicArtillery()
-- First, generate a list of completed P2 Vehicle Pits which the player cannot see
EGroup_CreateIfNotFound("eg_P2vehiclepits")
EGroup_AddGroup(EGroup_CreateIfNotFound("eg_P2all"), Player_GetEntities(g_Player2))
if not EGroup_IsEmpty ("eg_P2all") then
local CullVehiclePits = function( egroupid, itemindex, entityID )
if Entity_GetBlueprintName(entityID) == "chaos_machine_pit" then
if Entity_GetBuildingProgress(entityID) == 1 then
if not Player_CanSeeEntity(g_Player1, entityID) then
EGroup_Add(EGroup_FromName"eg_P2vehiclepits", entityID)
end
end
end
end
EGroup_ForEach( EGroup_FromName("eg_P2all"), CullVehiclePits)
end
-- Populate the artillery groups
for i = 1, 4 do
local artillerygroup = "sg_relicartillery"..i
SGroup_CreateIfNotFound(artillerygroup)
-- if the artillery group is empty, and there are some suitable pits present
if SGroup_IsEmpty(artillerygroup) then
if not EGroup_IsEmpty("eg_P2vehiclepits") then
-- create a defiler at a random pit, and lock it out of AI control
local numberofpits = EGroup_Count(EGroup_FromName("eg_P2vehiclepits"))
local randompit = 1
if (numberofpits > 1) then
randompit = World_GetRand(1, numberofpits)
end
local pos = Entity_GetPosition(EGroup_GetSpawnedEntityAt(EGroup_FromName("eg_P2vehiclepits"), randompit))
Util_CreateSquadsAtPosition(g_Player2, artillerygroup, "chaos_squad_defiler", pos, difficulty.defendingdefilers[g_difset])
Cpu_LockSGroup(g_Player2, artillerygroup)
end
end
end
-- Send the artillery groups to their spots
for i = 1, 4 do
local artillerygroup = "sg_relicartillery"..i
local artillerymarker = "mkr_relicartillery"..i
local relicmarker = "mkr_relic"..i
local relic = "eg_objrelic"..i
if not SGroup_IsEmpty(artillerygroup) then
-- Shell the ground around the Relic if it's not secured by the AI, else move into position
if (EGroup_IsCapturedByPlayer(relic, g_Player1, true) or not EGroup_HasStrategicPointWithStructure(relic))
and not (Player_AreSquadsNearMarker(g_Player2, relicmarker)) then
local pos = Entity_GetPosition(EGroup_GetSpawnedEntityAt(EGroup_FromName(relic), 1))
Cmd_AttackGroundPos(artillerygroup, pos)
else
Cmd_MoveToMarker(artillerygroup, artillerymarker)
end
end
end
end
--[[ GUARDSMEN ]] --g_guardgen = 0 function Rule_GenerateFodder()
SGroup_CreateIfNotFound("sg_guardsmen")
if SGroup_Count(SGroup_FromName("sg_guardsmen")) < 3 then
Util_CreateSquadsAtMarkerEx(g_Player1, "sg_guardconscripts", "guard_squad_soldier", "mkr_guardspawn", 1, 9)
Cmd_MoveToMarker("sg_guardconscripts", "mkr_guardrally")
SGroup_AddGroup(SGroup_FromName("sg_guardsmen"), SGroup_FromName("sg_guardconscripts"))
SGroup_Clear(SGroup_FromName("sg_guardconscripts"))
local soundBite = World_GetRand( 1, 3 )
if soundBite == 1 then
Sound_Play( "Speech/Single_player/Guardsman/Unit_complete/403760" )
elseif soundBite == 2 then
Sound_Play( "Speech/Single_player/Guardsman/Unit_complete/403761" )
elseif soundBite == 3 then
Sound_Play( "Speech/Single_player/Guardsman/Unit_complete/403762" )
end
--g_guardgen = g_guardgen+1
end
end
--[[ LEMAN RUSS MACHINE SPIRITS ]]
-- -- Set up the initial state of the Leman Russ tanks
function Rule_MachineSpiritsSetup()
for i = 1 , table.getn(t_lemanruss) do
SGroup_SetPlayerOwner(t_lemanruss[i], g_Player3)
SGroup_SetAvgHealth(t_lemanruss[i], 0.1)
end
-- Set up the recovery rule to run at a set interval (depending on difficulty level)
Rule_AddInterval(Rule_MachineSpirits, difficulty.lemanrepairspeed[g_difset])
Rule_Remove(Rule_MachineSpiritsSetup)
end
-- -- Gradually increase health of the last tank in the list, and release it when recovered
function Rule_MachineSpirits()
-- pick out the current tank from the table, and get it's health
local tank = table.getn(t_lemanruss)
local health = SGroup_GetAvgHealth(t_lemanruss[tank])
if health < 1.0 then
-- let it recuperate slowly
health = health + 0.01
SGroup_SetAvgHealth(t_lemanruss[tank], health)
else
-- release the tank to Player 1, and move it to it's "ready" spot
SGroup_SetPlayerOwner(t_lemanruss[tank], g_Player1)
Cmd_MoveToMarker(t_lemanruss[tank], "mkr_guardrally")
-- remove the tank from the list
table.remove(t_lemanruss, tank)
-- if that was the last tank, kill off this rule
if table.getn(t_lemanruss) == 0 then
Rule_Remove(Rule_MachineSpirits)
end
end
end
--CUSTOM UTIL SCRIPTS --[[ This one can be called to add whatever group is created to a single group for purposes of locking the AI out of it ]] function Deg_AddtoCpuLockGroup(playerID, sgroupname)
SGroup_CreateIfNotFound("sg_cpulock")
Cpu_UnlockSGroup(playerID, "sg_cpulock")
SGroup_AddGroup(SGroup_FromName("sg_cpulock"), SGroup_FromName(sgroupname))
Cpu_LockSGroup(playerID, "sg_cpulock")
end
--[[ LORD BALE STUFF ]]
-- -- Make Lord Bale wander around a bit (call intermittently)
function Rule_WanderingLordBale()
if SGroup_Exists("sg_bale") then
-- If Bale is about...
if not SGroup_IsEmpty("sg_bale") then
-- Pick a random point from the list
local y = World_GetRand(1, table.getn(t_balewanders))
-- Tell Lord Bale to go move to that point
--Cmd_SetStance("sg_bale", STANCE_StandGround)
Cmd_AttackMoveMarker("sg_bale", t_balewanders[y])
-- If any horrors are about, tell them to move there as well
if SGroup_Exists("sg_baleguard") then
Cmd_SetStance("sg_baleguard", STANCE_Hold)
Cmd_AttackMoveMarker("sg_baleguard", t_balewanders[y])
end
-- If Bale has been killed
else
-- Set up a respawn for him in 60 seconds
if not Rule_Exists(Rule_RespawnLordBale) then
Rule_AddOneShot(Rule_RespawnLordBale, 60)
end
end
end
end
-- -- Respawn Lord Bale at a random Temple after he dies
function Rule_RespawnLordBale()
-- Only respawn if there are some Chaos Temples left
if not EGroup_IsEmpty("eg_Player2Temples") then
-- Pick a random Chaos Temple and get its position
local numberoftemples = EGroup_Count(EGroup_FromName("eg_Player2Temples"))
local rand = 1
if (numberoftemples > 1) then
rand = World_GetRand(1, numberoftemples)
end
local pos = Entity_GetPosition(EGroup_GetSpawnedEntityAt(EGroup_FromName("eg_Player2Temples"), rand))
-- Spawn Lord Bale there
Util_CreateSquadsAtPosition(g_Player2, "sg_bale", "chaos_squad_lord", pos, 1)
Cpu_LockSGroup(g_Player2, SGroup_FromName("sg_bale"))
Cmd_SetStance("sg_bale", STANCE_Hold)
Cmd_SetMeleeStance("sg_bale", MSTANCE_Assault)
-- if there are any protectors, send them over to meet him
if SGroup_Exists("sg_baleguard") then
Cmd_AttackMovePos("sg_baleguard", pos)
end
-- up the number of protectors that will spawn for him this time
if (t_protectorsload == 5) then
if (t_protectorsnum < 3) then
t_protectorsnum = t_protectorsnum + 1
t_protectorsload = 3
end
else
t_protectorsload = t_protectorsload + 1
end
else
-- Set this rule to run again in the off-chance the AI builds another temple at some point
if not Rule_Exists(Rule_RespawnLordBale) then
Rule_AddOneShot(Rule_RespawnLordBale, 60)
end
end
end
-- -- Spawn in some Horrors if Bale comes under fire
function Rule_ProtectLordBale()
-- If Lord Bale exists and is under attack
if SGroup_Exists("sg_bale") then
if not SGroup_IsEmpty("sg_bale") then
if SGroup_IsUnderAttack("sg_bale", 0) then
-- Check to see if it's been more than a minute since the last horror spawn
if ((World_GetGameTime() - t_lastprotectorspawn) > 60) then
-- Check to see if this is the first time horrors have been created for Bale
if not SGroup_Exists("sg_baleguard") then
-- This is the first time, so go ahead and spawn some in
local balepos = Squad_GetPosition(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_bale"), 1))
Util_CreateHorrorsAndSummon(g_Player2, "sg_baleguard", balepos, t_protectorsnum, t_protectorsload)
Cpu_LockSGroup(g_Player2, SGroup_FromName("sg_baleguard"))
-- Set lastprotectorspawn to the current time
t_lastprotectorspawn = World_GetGameTime()
else
-- Horrors have been spawned in before, so check to see if the number remaining is beneath a threshold
if (SGroup_Count(SGroup_FromName("sg_baleguard")) < 3) then
local balepos = Squad_GetPosition(SGroup_GetSpawnedSquadAt(SGroup_FromName("sg_bale"), 1))
Util_CreateHorrorsAndSummon(g_Player2, "sg_baleguard", balepos, t_protectorsnum, t_protectorsload)
Cpu_LockSGroup(g_Player2, SGroup_FromName("sg_baleguard"))
-- Set lastprotectorspawn to the current time
t_lastprotectorspawn = World_GetGameTime()
end
end
end
end
end
end
end
--END GAMES
-- call this with an interval to ensure the mission ends function Rule_GameOver() World_SetGameOver() end
-- this function detects if the player has lost their base and has no servitors left function Rule_PlayerLoses()
g_building_exceptions =
{
"space_marine_mine_field",
"space_marine_listening_post",
"space_marine_turret_bolter"
}
g_unit_exceptions =
{
"space_marine_squad_librarian",
"guard_squad_inquisitor",
"guard_squad_soldier",
"space_marine_squad_force_commander"
}
if( Player_HasBuildingsExcept(g_Player1, g_building_exceptions) == false ) then
if( Player_HasSquadsExcept(g_Player1, g_unit_exceptions ) == false ) then
Rule_RemoveAll()
World_SetTeamWin( g_Player2, "" )
Rule_AddIntervalEx( Rule_GameOver,5,1 )
Rule_Remove( Rule_PlayerLoses )
end
end
end