--IMPORTS
import("ScarUtil.scar")
-- CHEAT
-- all cheats go here. these should all be deleted before ship.
function CheatClosing() --~ SGroup_ReSpawn("sg_NIS_AllFinalNISSquads") Util_StartNIS( EVENTS.NIS_Closing ) --~ Rule_Add(Rule_PlayerWinsAfterNIS) end
-- RESEARCH
-- ideally this is replaced by proper research functions
function SetResearchLevel( resLevel ) -- restrict -- global restrict Restrict_SpaceMarines( g_Player1, resLevel )
Player_RestrictSquad( g_Player1, "space_marine_squad_assault" )
Player_RestrictSquad( g_Player1, "space_marine_squad_land_speeder" )
Player_RestrictResearch( g_Player1, "marine_melta_bomb_research" )
Unrestrict_SquadWithAlerts( g_Player1, "space_marine_squad_dreadnought_hellfire", "none", "none" )
Unrestrict_ResearchWithAlerts( g_Player1, "support_cap_research_3", "none", "none" )
end
--GAME SETUP
-- this will only get called on a new game function OnGameSetup() g_Player1 = Setup_Player(0, "$252100", "space_marine_race", 1) g_Player2 = Setup_Player(1, "$252102", "eldar_race", 2) g_Player3 = Setup_Player(2, "$252104", "ork_race", 3) g_Player4 = Setup_Player(3, "$252106", "eldar_race", 2 ) g_Player5 = Setup_Player(4, "$252108", "space_marine_race", 1 )
-- arrays for the warp spiders that ambush the player
g_warpSpidersAmbush = {}
for i=1,11 do
g_warpSpidersAmbush[i] = { group="sg_WarpSpiderAmbushSquad_"..i, state=0 }
end
-- telling warp spiders where to teleport to
g_warpSpidersTracking = 1
g_warpSpiderToTeleport = nil
g_warpSpiderTeleportMarker = nil
-- variables for tracking the eldar using the gates
g_numgates = 8
g_gates = {}
g_queueGuardians = {}
g_queueDarkReapers = {}
g_queueHowlingBanshees = {}
g_queueSeerCouncil = {}
g_queueVypers = {}
-- this tracks how many guys are teleporting
g_queueTeleporting = {}
g_NIS01_AmbushSpidersToJump = 0
g_primarycomplete = 0
g_guardianstransporting = 1
-- i guess we could use a list to track where the wartrak is and where it needs to go
g_vypers = {
{ vypergroupname="sg_VyperOnPath_1", vyperstate=1, vypermarkername="mk_VyperPoint_", currentlocation=0, destination=0, vyperTimer=Timer_Start( 1, 5 ) },
{ vypergroupname="sg_VyperOnPath_2", vyperstate=1, vypermarkername="mk_VyperPoint_", currentlocation=0, destination=0, vyperTimer=Timer_Start( 2, 10 ) },
{ vypergroupname="sg_VyperOnPath_3", vyperstate=1, vypermarkername="mk_VyperPoint_", currentlocation=0, destination=0, vyperTimer=Timer_Start( 3, 15 ) },
{ vypergroupname="sg_VyperOnPath_4", vyperstate=1, vypermarkername="mk_VyperPoint_", currentlocation=0, destination=0, vyperTimer=Timer_Start( 4, 20 ) },
}
g_vypersNumberOfWaypoints = 3;
end
-- this will only get called after loading a game function OnGameRestore() g_Player1 = World_GetPlayerAt(0) g_Player2 = World_GetPlayerAt(1) g_Player3 = World_GetPlayerAt(2) g_Player4 = World_GetPlayerAt(3) g_Player5 = World_GetPlayerAt(4)
end
--ON INITIALIZATION
--OnInit should be used for pregame functions, things that should happen before the player officially enters the world.
function OnInit()
--~ Rule_Add(Rule_PlayerEncounteredOrksTEST)
-- FADE BLACK
EventCue_Enable(false)
Fade_Start( 0, false )
W40k_Letterbox( true, 0 )
-- DIFFICULTY LEVEL
SetDifficultyLevel( Difficulty_Get() )
print("diff: "..Difficulty_Get())
-- RESEARCH
SetResearchLevel( 5 )
-- MUSIC
SetupMusicPlaylist()
-- for now just play the music straight away
Sound_PlaylistStart( PC_Music )
-- NIS
Player_GrantResearch( g_Player1, "eldar_ranger_infiltration_research" )
Cmd_SetStance( "sg_NIS01_AllUnits", STANCE_CeaseFire )
PrecacheNISSpeech()
Rule_Add(Rule_NIS01_StartAmbushSequence)
SGroup_DeSpawn( "sg_NIS01_Ranger" )
SGroup_DeSpawn("sg_NIS02_AllObjects")
SGroup_DeSpawn( "sg_NIS01_Gabriel" )
SGroup_DeSpawn( "sg_NIS01_Toth" )
SGroup_DeSpawn( "sg_NIS01_Brom" )
SGroup_DeSpawn( "sg_NIS01_Matiel" )
SGroup_DeSpawn( "sg_NIS01_Isador" )
SGroup_DeSpawn( "sg_NIS01_Isador" )
SGroup_DeSpawn("sg_NIS01_tacsquad_1")
EGroup_DeSpawn("eg_PlayersHQ")
EGroup_DeSpawn("eg_PlayersChapel")
EGroup_DeSpawn("eg_PlayersTurret_1")
EGroup_DeSpawn("eg_PlayersTurret_2")
--~ SGroup_DeSpawn("sg_NIS02_AllSecondHalfObjects") -- start opening NIS Util_StartNIS( EVENTS.NIS_Opening ) Rule_Add( Rule_InitAfterNIS )
-- call Player_GetSquads once a second and use it in as many places as possible
Rule_UpdatePlayerSGroups()
Rule_AddInterval( Rule_UpdatePlayerSGroups, 0.5 )
SetCommanderPowerSword( g_Player1 )
SGroup_CreateIfNotFound( "sg_eldarTransporting" )
-- AI
Cpu_SetDifficulty( g_Player3, AD_Standard )
DisableAI()
Init_EldarPlayer()
Init_OrkPlayer()
SetModifiers()
-- OBJECTIVES
OBJ_PRIMARY_FOLLOWPATH = { title_id = 250000, short_desc_id = 250002, help_tip_id = 250004 }
OBJ_SECONDARY_DESTROYWEBWAYS = { title_id = 250010, short_desc_id = 250012, help_tip_id = 250014 }
OBJ_SECONDARY_DESTROYORKS = { title_id = 250020, short_desc_id = 250022, help_tip_id = 250024 }
OBJ_SECONDARY_RHINOSFORREAPERS = { title_id = 250040, short_desc_id = 250042, help_tip_id = 250044 }
end
-- This registers your init function with scar. This call has to be made after the defintion -- of the function and it must be called in global scope (global scope means not in any function -- or table) Scar_AddInit(OnInit)
--OPTIMIZATIONS
-- these functions are just here for optimization
-- this is just a temp function that is called once per second to reduce the number of times Player_GetSquads is called -- eventually Player_GetSquads wont be so slow, but as of now, it is. function Rule_UpdatePlayerSGroups() -- look up table indexed by player id g_PlayerSGroups = {} g_PlayerSGroups[Player_GetID(World_GetPlayerAt(0))] = Player_GetSquads( World_GetPlayerAt( 0 ) ) g_PlayerSGroups[Player_GetID(World_GetPlayerAt(1))] = Player_GetSquads( World_GetPlayerAt( 1 ) ) g_PlayerSGroups[Player_GetID(World_GetPlayerAt(2))] = Player_GetSquads( World_GetPlayerAt( 2 ) ) g_PlayerSGroups[Player_GetID(World_GetPlayerAt(3))] = Player_GetSquads( World_GetPlayerAt( 3 ) ) end
function Custom_Player_AreSquadsNearMarker( player, markername, checkinf )
local sgroup = g_PlayerSGroups[ Player_GetID( player ) ]
-- call Player_GetSquads if sgroup is not in look up table
if( sgroup == nil ) then
sgroup = Player_GetSquads( player )
end
if checkinf then
-- create a temp group containing everyone but the infiltrated units
local temp = SGroup_CreateIfNotFound( "custom_player_aresquadsnearmkr" )
SGroup_Clear( temp )
local IsInfil = function( groupid, idx, id )
if not Squad_IsInfiltrated( id ) then
-- add to temp group
SGroup_Add( temp, id )
end
end
SGroup_ForEach( sgroup, IsInfil )
return Prox_AnySquadNearMarker( SGroup_GetName( temp ), markername )
end
return Prox_AnySquadNearMarker( SGroup_GetName( sgroup ), markername )
end
-- GAME STATE
-- this controls the game state, ensures flow is properly controlled etc
-- this function serves the same purpose as OnInit, but it allows us to play the NIS then start checking all the rules. function Rule_InitAfterNIS() if Event_IsRunning( EVENTS.NIS_Opening ) == false then -- yay! tell all the paths to end
Cmd_SetStance( "sg_NIS01_AllUnits", STANCE_Hold )
-- clean up anything that was supposed to happen in NIS but didnt
SGroup_DestroyAllSquads( "sg_NIS01_SquadsToBeDestroyed" )
InitGates()
-- followpath
Util_ObjectiveCreate( OBJ_PRIMARY_FOLLOWPATH, true )
Util_Ping_LoopingMkr("PING_FOLLOWPATH", "mk_Ping_EndOfPath")
Rule_AddInterval( Rule_PlayerHasFollowedPath, 1 )
Rule_AddInterval( Rule_StartClosingNIS,1 )
-- orks flee
Rule_AddInterval(Rule_OrksFleeing,1)
--destroywebways
Rule_AddInterval(Rule_PlayerEncounteredGate,1)
-- dark reaper ambush
Rule_AddInterval(Rule_DarkReapersAmbushPlayer,1)
-- warp spider ambush
Cmd_SetStance( "sg_AllWarspiders", STANCE_CeaseFire )
Rule_AddInterval(Rule_WarpSpidersAmbush, 1)
-- howling banshees attack
Rule_AddInterval(Rule_HowlingBansheesAttack, 1)
-- vypers
--~ Rule_AddInterval( Rule_MoveVyper,1 ) --~ Rule_AddInterval( Rule_VyperAtDestination, 1 ) --~ Rule_AddInterval( Rule_CheckVyperState,1 )
-- destroyorks
Rule_AddInterval(Rule_PlayerEncounteredOrks,0.5)
-- secondary base
Rule_AddInterval(Rule_PlayerEstablishSecondaryBase,1)
-- player has won
--~ Rule_AddInterval(Rule_PlayerHasWon,1) Rule_AddInterval(Rule_TrackCharacters,10)
Rule_Remove(Rule_InitAfterNIS)
Rule_AddInterval( Rule_GiveAccessToSacredArtifact, 4 )
Rule_AddInterval(Rule_PlayerLoses,1)
-- save now
Util_Autosave( "$252000" )
--~ Rule_Add(Rule_SaveGameLocationCard) --~ Rule_AddInterval(Rule_SaveGame_AfterNIS,1) end end
function Rule_GiveAccessToSacredArtifact() Unrestrict_BuildingWithAlerts( g_Player1, "space_marine_ability_building", "$42958", 408054 ) Rule_AddInterval( Rule_GiveAccessToApothecary, 4 ) Rule_Remove( Rule_GiveAccessToSacredArtifact ) end
function Rule_GiveAccessToRhino() Unrestrict_SquadWithAlerts( g_Player1, "space_marine_squad_rhino", "$42916", 408014 ) Unrestrict_ResearchWithAlerts( g_Player1, "marine_smoke_launcher_research", "none", "none" ) Rule_Remove(Rule_GiveAccessToRhino) end
function Rule_GiveAccessToApothecary() if Player_HasBuildingType( g_Player1, "space_marine_ability_building" ) then Unrestrict_SquadWithAlerts( g_Player1, "space_marine_squad_apothecary", "$42910", 408008 ) Rule_Remove(Rule_GiveAccessToApothecary) end end
-- checks all the objectives and determines if the player needs to have won the mission function Rule_PlayerHasWon() -- if all objectives completed or failed then win the mission if Objective_GetState( OBJ_PRIMARY_FOLLOWPATH.title_id ) == OS_Complete then if ( Objective_GetState( OBJ_SECONDARY_DESTROYWEBWAYS.title_id ) == OS_Complete or Objective_GetState( OBJ_SECONDARY_DESTROYWEBWAYS.title_id ) == OS_Failed ) and ( Objective_GetState( OBJ_SECONDARY_DESTROYORKS.title_id ) == OS_Complete or Objective_GetState( OBJ_SECONDARY_DESTROYORKS.title_id ) == OS_Failed ) and ( Objective_GetState( OBJ_SECONDARY_RHINOSFORREAPERS.title_id ) == OS_Complete or Objective_GetState( OBJ_SECONDARY_RHINOSFORREAPERS.title_id ) == OS_Failed ) then World_SetTeamWin(g_Player1,"") Rule_AddIntervalEx(Rule_GameOver,5,1) Rule_Remove( Rule_PlayerHasWon ) end end end
-- call this with an interval to ensure the mission ends function Rule_GameOver() World_SetGameOver() end
-- this function detects if the player has lost their base and has no servitors left function Rule_PlayerLoses()
g_building_exceptions =
{
"space_marine_mine_field",
"space_marine_listening_post",
"space_marine_turret_bolter"
}
g_unit_exceptions =
{
"space_marine_squad_librarian",
"space_marine_squad_force_commander",
"guard_squad_inquisitor",
"guard_squad_colonel"
}
if( Player_HasBuildingsExcept(g_Player1, g_building_exceptions) == false ) then
if( Player_HasSquadsExcept(g_Player1, g_unit_exceptions ) == false ) then
World_SetTeamWin( g_Player2, "" )
Rule_AddIntervalEx( Rule_GameOver,5,1 )
Rule_Remove( Rule_PlayerLoses )
end
end
end
-- keeping track of the characters and keeping them alive. function Rule_TrackCharacters() Util_TrackCharacterAndDropPodIn( g_Player1, "sg_ForceCommander", "space_marine_squad_force_commander", "mk_PlayersBase" ) Util_TrackCharacterAndDropPodIn( g_Player1, "sg_Librarian", "space_marine_squad_librarian", "mk_PlayersBase" ) Util_TrackCharacterAndDropPodIn( g_Player1, "sg_Brom", "guard_squad_colonel", "mk_PlayersBase" ) Util_TrackCharacterAndDropPodIn( g_Player1, "sg_Toth", "guard_squad_inquisitor", "mk_PlayersBase" ) end
function Rule_NIS01_StartAmbushSequence() if g_NIS01_AmbushSpidersToJump == 1 then Rule_AddInterval(Rule_NIS01_TellAmbushSpidersToJump,7) Rule_Remove(Rule_NIS01_StartAmbushSequence) end end
function Rule_NIS01_TellAmbushSpidersToJump() Cmd_JumpToMarker( "sg_NIS01_WarpSpidersAmbushing", "mk_NIS01_WarpSpidersAmbush" ) Rule_AddInterval(Rule_NIS01_TellAmbushSpidersToJumpBack,8) Rule_Remove(Rule_NIS01_TellAmbushSpidersToJump) end
function Rule_NIS01_TellAmbushSpidersToJumpBack() Cmd_JumpToMarker( "sg_NIS01_WarpSpidersAmbushing", "mk_NIS01_WarpSpidersAmbushReturn" ) Rule_Remove(Rule_NIS01_TellAmbushSpidersToJumpBack) end
-- AI
-- this section has all functions regarding to AI
-- sets up attack stances etc on all teh eldar units in the mission function Init_EldarPlayer()
-- the assaulting howling banshees
Cmd_SetStance("sg_HowlingBanshees", STANCE_Attack)
Cmd_SetStance("sg_EldarAttackingOrk", STANCE_StandGround)
-- set guardians attacking orks to invulnerable
SGroup_SetHealthInvulnerable( "sg_EldarAttackingOrk", 1 )
-- tell the guardians to get in grav tanks
Cmd_EnterTransport( "sg_GuardiansInTank_1", "sg_GravTank_1" )
Cmd_EnterTransport( "sg_GuardiansInTank_2", "sg_GravTank_2" )
Cmd_EnterTransport( "sg_GuardiansInTank_3", "sg_GravTank_3" )
-- spawn a squad of guardians and stick them in the webway gate for them to come out at first webway
local squadBeingCreated = Squad_Create( "eldar_guardian_squad", g_Player2, EGroup_GetPosition( EGroup_FromName( "eg_EldarHomeBaseAspectPortal_1") ), 8 )
table.insert(g_queueGuardians,1, squadBeingCreated )
Squad_Spawn( squadBeingCreated, EGroup_GetPosition( EGroup_FromName( "eg_EldarHomeBaseAspectPortal_1") ) )
Transport_Squad( g_queueGuardians )
end
-- sets up attack stances etc on the ork units function Init_OrkPlayer() Cmd_SetStance("sg_OrkShootasUnderAttack", STANCE_StandGround) SGroup_SetHealthInvulnerable( "sg_OrkShootasUnderAttack", 1 ) Cmd_SetStance( "sg_OrksFleeing", STANCE_CeaseFire ) end
function DisableAI() Cpu_EnableAll( 0 ) end
-- MODIFIERS
-- this section has all functions regarding to modifiers that are applied during the mission
function SetModifiers()
sm_entity_list = {
-- units
"apothecary",
"assault_marine",
"dreadnought",
"dreadnought_hellfire_variant",
"force_commander",
"land_speeder",
"librarian",
"predator",
"rhino",
"scout_marine",
"servitor",
"skull_probe",
"sergeant",
"space_marine_tactical_bolter",
"whirlwind",
"guard_colonel",
"guard_inquisitor",
-- structures
"space_marine_ability_building",
"space_marine_armoury",
"space_marine_barracks",
"space_marine_generator",
"space_marine_hq",
"space_marine_listening_post",
"space_marine_orbital_relay",
"space_marine_thermo_generator",
"space_marine_turret_bolter",
"space_marine_turret_missiles",
"space_marine_vehicle_building"
}
-- do for all entities
for i=1,table.getn( sm_entity_list ) do
-- create the modifier
local modifier = Modifier_Create(
MAT_EntityType, -- This modifier will be applied to an entity blueprint
"sight_radius_modifier", -- Modify entity sight radius
MUT_Multiplication, -- Multiply sight radius by 0.5 non exclusive
false,
0.6,
sm_entity_list[i] -- Do this to all scout marines
)
-- apply it to the player
local modID = Modifier_ApplyToPlayer( modifier, g_Player1 )
end
end
-- DIFFICULTY LEVEL
-- the functions here set the difficulty level for the mission. Should be called from OnGameSetup
function SetDifficultyLevel( difficultyLevel )
Difficulty_SetForAll( difficultyLevel )
-- easy
if difficultyLevel == DIFFICULTY_EASY then
g_numGuardians = 1
g_numDarkReapers = 1
g_numHowlingBanshees = 1
g_numSeerCouncil = 1
g_numVypers = 1
g_maintainRate = 15
g_transportRate = 20
-- medium
elseif difficultyLevel == DIFFICULTY_NORMAL then
g_numGuardians = 2
g_numDarkReapers = 2
g_numHowlingBanshees = 2
g_numSeerCouncil = 2
g_numVypers = 2
g_maintainRate = 10
g_transportRate = 15
-- hard
elseif difficultyLevel == DIFFICULTY_HARD then
g_numGuardians = 3
g_numDarkReapers = 3
g_numHowlingBanshees = 3
g_numSeerCouncil = 3
g_numVypers = 3
g_maintainRate = 5
g_transportRate = 10
else
print("NO DIFFICULTY SET!")
end
end
-- MUSIC/SOUND
function SetupMusicPlaylist()
-- clear the current playlist
Sound_PlaylistClear( PC_Music )
-- add tracks to the playlist
Sound_PlaylistAddTrack( PC_Music, "music_EldarTheme" )
Sound_PlaylistAddTrack( PC_Music, "ambient_ingame_01" )
Sound_PlaylistAddTrack( PC_Music, "music_acid" )
-- 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_space" )
-- 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
function PrecacheNISSpeech() W40k_CacheSpeech( 253000, 253042 ) end
-- FOLLOW THE PATH
-- player is ordered to move along the path
-- when they reach the end function Rule_PlayerHasFollowedPath() if Prox_AnySquadNearMarker( "sg_ForceCommander", "mk_EndOfPath" ) and Prox_AnySquadNearMarker( "sg_Librarian", "mk_EndOfPath" ) then --~ if Custom_Player_AreSquadsNearMarker( g_Player1, "mk_EndOfPath", false ) then g_primarycomplete = g_primarycomplete + 1
Util_ObjectiveComplete( OBJ_PRIMARY_FOLLOWPATH.title_id )
Util_Ping_Stop("PING_FOLLOWPATH")
Rule_Remove( Rule_PlayerHasFollowedPath )
end
end
function Rule_PlayerHasDestroyedGates() if ( Objective_GetState( OBJ_SECONDARY_DESTROYWEBWAYS.title_id) == OS_Complete ) then g_primarycomplete = g_primarycomplete + 1 Rule_Remove(Rule_PlayerHasDestroyedGates) end end
function Rule_StartClosingNIS() if g_primarycomplete == 2 then Util_StartNIS( EVENTS.NIS_Closing ) Rule_Remove(Rule_StartClosingNIS) Rule_RemoveAll() Rule_Add(Rule_PlayerWinsAfterNIS) end end
function Rule_PlayerWinsAfterNIS() if Event_IsRunning( EVENTS.NIS_Closing ) == false then
World_SetTeamWin(g_Player1,"")
Rule_AddIntervalEx(Rule_GameOver,5,1)
Rule_Remove(Rule_PlayerWinsAfterNIS)
end
end
-- ORKS FLEEING
-- this function starts the guardians capturing the strategic point function Rule_OrksFleeing()
if Custom_Player_AreSquadsNearMarker( g_Player1, "mk_OrksFleeing", false ) then
SGroup_SetAvgMorale( "sg_OrksFleeing", 0.0 )
FOW_RevealMarker( "mk_OrksFleeing", 5 )
Cmd_MoveToMarker( "sg_OrksFleeing", "mk_OrksFleeTo" )
Util_StartIntel( EVENTS.IE_OrksFleeInFear )
Rule_Add(Rule_OrksHaveFled)
Rule_Remove(Rule_OrksFleeing)
end
end
function Rule_OrksHaveFled()
if Custom_Player_AreSquadsNearMarker( g_Player3, "mk_OrksHaveFled", false ) or SGroup_Count( "sg_OrksFleeing" ) == 0 then
Util_StartIntel( EVENTS.IE_OrksWerentAttacking )
Rule_Remove( Rule_OrksHaveFled )
end
end
-- DESTROY WEBWAY GATES
-- opening event. player is ordered to move along the path function Rule_PlayerEncounteredGate() if Custom_Player_AreSquadsNearMarker( g_Player1, "mk_FirstEldarPortal", false ) then
Util_StartIntel( EVENTS.IE_EldarDiscovered )
Rule_Add(Rule_PlayerEncounteredGate_Save)
--~ Cmd_ConstructBlueprintOnEGroup( "sg_BonesingerBuildingLP", "eldar_listening_post", "eg_SPForBonesingerToBuildOn" )
Cmd_EmptyBuilding( "eg_WebGate_1" )
Rule_AddInterval(Rule_PlayerDestroyedAllGates,1)
Rule_Remove(Rule_PlayerEncounteredGate)
Rule_AddInterval(Rule_GravTank_MoveToListeningPost, 60 )
end
end
function Rule_PlayerEncounteredGate_Save() if not Event_IsRunning( EVENTS.IE_EldarDiscovered ) then Util_ObjectiveCreate( OBJ_SECONDARY_DESTROYWEBWAYS, true ) Rule_AddInterval(Rule_PlayerHasDestroyedGates,1) Rule_Remove(Rule_PlayerEncounteredGate_Save) -- save now Util_Autosave( "$252002" ) end end
function Rule_PlayerDestroyedAllGates() if EGroup_Count( EGroup_FromName("eg_WebGate_All") ) == 0 then
Util_ObjectiveComplete( OBJ_SECONDARY_DESTROYWEBWAYS.title_id )
Rule_Remove(Rule_PlayerDestroyedAllGates)
end
end
-- DARK REAPER AMBUSH
function Rule_DarkReapersAmbushPlayer() if Custom_Player_AreSquadsNearMarker( g_Player1, "mk_EnteringAmbushArea", false ) then
Sound_PlayStinger( "stinger_tensedanger" )
Util_StartIntel( EVENTS.IE_DarkReaperAmbushAhead )
Rule_Add(Rule_DarkReapersAmbushPlayer_1)
Rule_Remove(Rule_DarkReapersAmbushPlayer)
end
end
-- this tells the dark reapers to ambush the player in the valley function Rule_DarkReapersAmbushPlayer_1() if Custom_Player_AreSquadsNearMarker( g_Player1, "mk_DarkReaperAmbushPosition_1", true ) and not Event_IsAnyRunning() then
Util_StartIntel( EVENTS.IE_DarkReapersAttack )
Rule_Add(Rule_DarkReapersAmbushPlayer_Save)
Cmd_MoveToMarker("sg_DarkReaperAmbushSquad_1", "mk_DarkReaperStaging_1" )
Cmd_MoveToMarker("sg_DarkReaperAmbushSquad_2", "mk_DarkReaperStaging_2" )
FOW_RevealSGroup( "sg_DarkReaperAmbushSquad_1", 15 )
FOW_RevealSGroup( "sg_DarkReaperAmbushSquad_2", 15 )
Rule_Remove(Rule_DarkReapersAmbushPlayer_1)
Rule_Add(Rule_DarkReapersAmbushPlayer_2)
end
end
function Rule_DarkReapersAmbushPlayer_Save() if not Event_IsRunning( EVENTS.IE_DarkReapersAttack ) then Util_ObjectiveCreate( OBJ_SECONDARY_RHINOSFORREAPERS, false ) Util_Ping_LoopingMkr("PING_REAPERS", "mk_Ping_DarkReapers")
Rule_Add(Rule_DarkReapersDestroyed)
Rule_AddInterval(Rule_GiveAccessToRhino, 4 )
Rule_Remove(Rule_DarkReapersAmbushPlayer_Save)
-- save now
Util_Autosave( "$252004" )
end
end
function Rule_DarkReapersAmbushPlayer_2() if Custom_Player_AreSquadsNearMarker( g_Player1, "mk_DarkReaperAmbushPosition_2", true ) then Cmd_MoveToMarker("sg_DarkReaperAmbushSquad_3", "mk_DarkReaperStaging_3" ) Cmd_MoveToMarker("sg_DarkReaperAmbushSquad_4", "mk_DarkReaperStaging_4" ) FOW_RevealSGroup( "sg_DarkReaperAmbushSquad_3", 15 ) FOW_RevealSGroup( "sg_DarkReaperAmbushSquad_4", 15 ) Rule_Remove(Rule_DarkReapersAmbushPlayer_2) end end
function Rule_DarkReapersDestroyed() if SGroup_Count( "sg_DarkReaperAmbushSquad_1" ) == 0 and SGroup_Count( "sg_DarkReaperAmbushSquad_2" ) == 0 and SGroup_Count( "sg_DarkReaperAmbushSquad_3" ) == 0 and SGroup_Count( "sg_DarkReaperAmbushSquad_4" ) == 0 then Util_ObjectiveComplete( OBJ_SECONDARY_RHINOSFORREAPERS.title_id ) Util_Ping_Stop("PING_REAPERS") Rule_Remove(Rule_DarkReapersDestroyed) end end
-- WARP SPIDER AMBUSH
-- this tells the warp spiders to teleport in and attack the player
function Rule_TeleportSpider() Cmd_JumpToMarker( g_warpSpiderToTeleport, g_warpSpiderTeleportMarker ) Cmd_SetStance( g_warpSpiderToTeleport, STANCE_Attack )
end
function Rule_WarpSpidersAmbush() if Custom_Player_AreSquadsNearMarker( g_Player1, "mk_WarpSpiderAmbushTeleport_"..g_warpSpidersTracking, true ) then
g_warpSpiderToTeleport = "sg_WarpSpiderAmbushSquad_"..g_warpSpidersTracking
g_warpSpiderTeleportMarker = "mk_WarpSpiderAmbushTeleport_"..g_warpSpidersTracking
if not Rule_Exists( Rule_TeleportSpider ) then
Rule_AddOneShot( Rule_TeleportSpider, 3 )
g_warpSpidersTracking = g_warpSpidersTracking + 1
end
if g_warpSpidersTracking > 11 then
Rule_Remove(Rule_WarpSpidersAmbush)
end
end
end
-- HOWLING BANSHEES ATTACK
-- this tells the howling banshees to attack the player
function Rule_HowlingBansheesAttack() if Custom_Player_AreSquadsNearMarker( g_Player1, "mk_HowlingBansheesAssault", true ) then Cmd_AttackMoveMarker( "sg_HowlingBanshees", "mk_HowlingBansheesAssault" ) Rule_Remove( Rule_HowlingBansheesAttack ) end end
-- ELDAR USING GATES
-- all the code that handles the eldar "using" the gates to move about. -- not too sure if we will actually have them using the gates or if we will just have them spawning next to the gates -- for now we will just spawn
-- just a container function that starts all the gates up. function InitGates()
for i=1,8 do
g_gates[i] = 1
end
Rule_AddInterval( Rule_MaintainBaseUnits, g_maintainRate )
Rule_AddInterval( Rule_TransportToWebway, g_transportRate )
Rule_AddInterval( Rule_RespawnAtWebway_1, 2 )
Rule_AddInterval( Rule_RespawnAtWebway_2, 2 )
Rule_AddInterval( Rule_RespawnAtWebway_3, 2 )
Rule_AddInterval( Rule_RespawnAtWebway_4, 2 )
Rule_AddInterval( Rule_RespawnAtWebway_5, 2 )
Rule_AddInterval( Rule_RespawnAtWebway_6, 2 )
Rule_AddInterval( Rule_RespawnAtWebway_7, 2 )
Rule_AddInterval( Rule_RespawnAtWebway_8, 2 )
Rule_AddInterval( Rule_RespawnAtWebway_9, 2 )
Rule_AddInterval( Rule_RespawnAtWebway_10, 2 )
--~ Rule_AddInterval( Rule_SpawnGuardians, 10 ) --~ Rule_AddInterval( Rule_SpawnDarkReapers, 20 ) end
-- this function maintains the guys at home base -- if there arent enough guys in the list, then create some more function Rule_MaintainBaseUnits()
-- for every queue, take a look at the number of units in the queue. if not enough, add another guy
if g_numGuardians ~= 0 and table.getn(g_queueGuardians) < g_numGuardians then
-- spawn a new guardian and add him to the queue
local squadBeingCreated = Squad_Create( "eldar_guardian_squad", g_Player2, EGroup_GetPosition( EGroup_FromName( "eg_EldarHomeBaseAspectPortal_1") ), 8 )
table.insert(g_queueGuardians,1, squadBeingCreated )
Squad_Spawn( squadBeingCreated, EGroup_GetPosition( EGroup_FromName( "eg_EldarHomeBaseAspectPortal_1") ) )
end
if g_numDarkReapers ~= 0 and table.getn(g_queueDarkReapers) < g_numDarkReapers then
-- spawn a new guardian and add him to the queue
local squadBeingCreated = Squad_Create( "eldar_squad_dark_reapers", g_Player2, EGroup_GetPosition( EGroup_FromName( "eg_EldarHomeBaseAspectPortal_1") ), 4 )
table.insert(g_queueDarkReapers,1, squadBeingCreated )
Squad_Spawn( squadBeingCreated, EGroup_GetPosition( EGroup_FromName( "eg_EldarHomeBaseAspectPortal_1") ) )
end
if g_numHowlingBanshees ~= 0 and table.getn(g_queueHowlingBanshees) < g_numHowlingBanshees then
-- spawn a new guardian and add him to the queue
local squadBeingCreated = Squad_Create( "eldar_squad_banshees", g_Player2, EGroup_GetPosition( EGroup_FromName( "eg_EldarHomeBaseAspectPortal_1") ), 8 )
table.insert(g_queueHowlingBanshees,1, squadBeingCreated )
Squad_Spawn( squadBeingCreated, EGroup_GetPosition( EGroup_FromName( "eg_EldarHomeBaseAspectPortal_1") ) )
end
if g_numSeerCouncil ~= 0 and table.getn(g_queueSeerCouncil) < g_numSeerCouncil then
-- spawn a new guardian and add him to the queue
local squadBeingCreated = Squad_Create( "eldar_squad_seer_council", g_Player2, EGroup_GetPosition( EGroup_FromName( "eg_EldarHomeBaseAspectPortal_1") ), 5 )
table.insert(g_queueSeerCouncil,1, squadBeingCreated )
Squad_Spawn( squadBeingCreated, EGroup_GetPosition( EGroup_FromName( "eg_EldarHomeBaseAspectPortal_1") ) )
end
end
-- this function sends function Rule_TransportToWebway() -- need to ensure there arent too many people in the transporting queue if SGroup_Count( "sg_eldarTransporting" ) <= 10 then -- this gate needs guardians if EGroup_Count( "eg_WebGate_1" ) == 1 and Custom_Player_AreSquadsNearMarker( g_Player1, "mk_FirstEldarPortal", true ) then -- we need guardians in the webway Transport_Squad( g_queueGuardians )
elseif EGroup_Count( "eg_WebGate_2" ) == 1 and Custom_Player_AreSquadsNearMarker( g_Player1, "mk_DarkReaper_EldarPortal", true ) then
-- we need guardians and dark reapers in the webway
Transport_Squad( g_queueDarkReapers )
elseif EGroup_Count( "eg_WebGate_3" ) == 1 and Custom_Player_AreSquadsNearMarker( g_Player1, "mk_ThirdPortal", true ) then
-- we need guardians in the webway
Transport_Squad( g_queueGuardians )
elseif EGroup_Count( "eg_WebGate_4" ) == 1 and Custom_Player_AreSquadsNearMarker( g_Player1, "mk_FourthPortal", true ) then
-- we need guardians in the webway
Transport_Squad( g_queueHowlingBanshees )
elseif ( EGroup_Count( "eg_WebGate_5" ) == 1 or EGroup_Count( "eg_WebGate_6" ) == 1 ) and Custom_Player_AreSquadsNearMarker( g_Player1, "mk_FifthSixthPortal", true ) then
-- we need lots in the webway
Transport_Squad( g_queueGuardians )
Transport_Squad( g_queueDarkReapers )
Transport_Squad( g_queueSeerCouncil )
elseif EGroup_Count( "eg_WebGate_7" ) == 1 and Custom_Player_AreSquadsNearMarker( g_Player1, "mk_FifthPortal", true ) then
-- we need guardians in the webway
Transport_Squad( g_queueGuardians )
Transport_Squad( g_queueHowlingBanshees )
elseif ( EGroup_Count( "eg_WebGate_8" ) == 1 or EGroup_Count( "eg_WebGate_9" ) == 1 or EGroup_Count( "eg_WebGate_10" ) == 1) and Custom_Player_AreSquadsNearMarker( g_Player1, "mk_FinalPortal", true ) then
-- transport everything
Transport_Squad( g_queueGuardians )
Transport_Squad( g_queueDarkReapers )
Transport_Squad( g_queueHowlingBanshees )
Transport_Squad( g_queueSeerCouncil )
end
end
end
function Transport_Squad( queue ) if table.getn(queue) > 0 then
-- first take him out of the table (reserve him for our use)
local squadtransporting = table.remove( queue )
-- create a dummy group we can use for transporting
SGroup_CreateIfNotFound( "sg_eldar_enteringbuilding" )
-- clear it, just in case it existed before
SGroup_Clear( SGroup_FromName( "sg_eldar_enteringbuilding" ) )
SGroup_Add( "sg_eldar_enteringbuilding", squadtransporting )
Cmd_SetStance( "sg_eldar_enteringbuilding", STANCE_Attack )
SGroup_AddGroup( "sg_eldarTransporting", "sg_eldar_enteringbuilding" )
-- now tell him to get in the webway
Cmd_EnterBuilding( "sg_eldar_enteringbuilding", "eg_webportalsatbase" )
end
end
function Rule_RespawnAtWebway_1() if Custom_Player_AreSquadsNearMarker( g_Player1, "mk_FirstEldarPortal", true ) and SGroup_Count( "sg_eldarTransporting" ) > 0 and EGroup_Count( "eg_WebGate_1" ) == 1 then -- there is someone waiting to get out of the gate Cmd_EmptyBuilding( "eg_WebGate_1" ) elseif EGroup_Count( "eg_WebGate_1" ) == 0 then Rule_Remove( Rule_RespawnAtWebway_1 ) end end
function Rule_RespawnAtWebway_2() if Custom_Player_AreSquadsNearMarker( g_Player1, "mk_DarkReaper_EldarPortal", true ) and SGroup_Count( "sg_eldarTransporting" ) > 0 and EGroup_Count( "eg_WebGate_2" ) == 1 then -- there is someone waiting to get out of the gate Cmd_EmptyBuilding( "eg_WebGate_2" ) elseif EGroup_Count( "eg_WebGate_2" ) == 0 then Rule_Remove( Rule_RespawnAtWebway_2 ) end end
function Rule_RespawnAtWebway_3() if Custom_Player_AreSquadsNearMarker( g_Player1, "mk_ThirdPortal", true ) and SGroup_Count( "sg_eldarTransporting" ) > 0 and EGroup_Count( "eg_WebGate_3" ) == 1 then -- there is someone waiting to get out of the gate Cmd_EmptyBuilding( "eg_WebGate_3" ) elseif EGroup_Count( "eg_WebGate_3" ) == 0 then Rule_Remove( Rule_RespawnAtWebway_3 ) end end
function Rule_RespawnAtWebway_4() if Custom_Player_AreSquadsNearMarker( g_Player1, "mk_FourthPortal", true ) and SGroup_Count( "sg_eldarTransporting" ) > 0 and EGroup_Count( "eg_WebGate_4" ) == 1 then -- there is someone waiting to get out of the gate Cmd_EmptyBuilding( "eg_WebGate_4" ) elseif EGroup_Count( "eg_WebGate_4" ) == 0 then Rule_Remove( Rule_RespawnAtWebway_4 ) end end
function Rule_RespawnAtWebway_5() if Custom_Player_AreSquadsNearMarker( g_Player1, "mk_FifthSixthPortal", true ) and SGroup_Count( "sg_eldarTransporting" ) > 0 and EGroup_Count( "eg_WebGate_5" ) == 1 then -- there is someone waiting to get out of the gate Cmd_EmptyBuilding( "eg_WebGate_5" ) elseif EGroup_Count( "eg_WebGate_5" ) == 0 then Rule_Remove( Rule_RespawnAtWebway_5 ) end end
function Rule_RespawnAtWebway_6() if Custom_Player_AreSquadsNearMarker( g_Player1, "mk_FifthSixthPortal", true ) and SGroup_Count( "sg_eldarTransporting" ) > 0 and EGroup_Count( "eg_WebGate_6" ) == 1 then -- there is someone waiting to get out of the gate Cmd_EmptyBuilding( "eg_WebGate_6" ) elseif EGroup_Count( "eg_WebGate_6" ) == 0 then Rule_Remove( Rule_RespawnAtWebway_6 ) end end
function Rule_RespawnAtWebway_7() if Custom_Player_AreSquadsNearMarker( g_Player1, "mk_FifthPortal", true ) and SGroup_Count( "sg_eldarTransporting" ) > 0 and EGroup_Count( "eg_WebGate_7" ) == 1 then -- there is someone waiting to get out of the gate Cmd_EmptyBuilding( "eg_WebGate_7" ) elseif EGroup_Count( "eg_WebGate_7" ) == 0 then Rule_Remove( Rule_RespawnAtWebway_7 ) end end
function Rule_RespawnAtWebway_8() if Custom_Player_AreSquadsNearMarker( g_Player1, "mk_FinalPortal", true ) and SGroup_Count( "sg_eldarTransporting" ) > 0 and EGroup_Count( "eg_WebGate_8" ) == 1 then -- there is someone waiting to get out of the gate Cmd_EmptyBuilding( "eg_WebGate_8" ) elseif EGroup_Count( "eg_WebGate_8" ) == 0 then Rule_Remove( Rule_RespawnAtWebway_8 ) end end
function Rule_RespawnAtWebway_9() if Custom_Player_AreSquadsNearMarker( g_Player1, "mk_FinalPortal", true ) and SGroup_Count( "sg_eldarTransporting" ) > 0 and EGroup_Count( "eg_WebGate_9" ) == 1 then -- there is someone waiting to get out of the gate Cmd_EmptyBuilding( "eg_WebGate_9" ) elseif EGroup_Count( "eg_WebGate_9" ) == 0 then Rule_Remove( Rule_RespawnAtWebway_9 ) end end
function Rule_RespawnAtWebway_10() if Custom_Player_AreSquadsNearMarker( g_Player1, "mk_FinalPortal", true ) and SGroup_Count( "sg_eldarTransporting" ) > 0 and EGroup_Count( "eg_WebGate_10" ) == 1 then -- there is someone waiting to get out of the gate Cmd_EmptyBuilding( "eg_WebGate_10" ) elseif EGroup_Count( "eg_WebGate_10" ) == 0 then Rule_Remove( Rule_RespawnAtWebway_10 ) end end
-- guardians spawn at the first gate the player comes across function Rule_SpawnGuardians() if Custom_Player_AreSquadsNearMarker( g_Player1, "mk_FirstEldarPortal", true ) and EGroup_Count( "eg_WebGate_1" ) == 1 then local squadSpawned = Squad_Create( "eldar_guardian_squad", g_Player2, EGroup_GetPosition( EGroup_FromName( "eg_WebGate_1") ), 5 ) SGroup_Add( SGroup_FromName("sg_SpawnedEldar"), squadSpawned ) SGroup_Add( SGroup_FromName("sg_SpawnedEldar_Guardians"), squadSpawned ) Squad_Spawn( squadSpawned, EGroup_GetPosition( EGroup_FromName( "eg_WebGate_1") ) ) elseif EGroup_Count( "eg_WebGate_1" ) == 0 then Rule_Remove(Rule_SpawnGuardians) end end
-- dark reapers spawn at their gate function Rule_SpawnDarkReapers() if Custom_Player_AreSquadsNearMarker( g_Player1, "mk_DarkReaper_EldarPortal", true ) and EGroup_Count( "eg_WebGate_2" ) == 1 then local squadSpawned = Squad_Create( "eldar_squad_dark_reapers", g_Player2, EGroup_GetPosition( EGroup_FromName( "eg_WebGate_2") ), 5 ) SGroup_Add( SGroup_FromName("sg_SpawnedEldar"), squadSpawned ) SGroup_Add( SGroup_FromName("sg_SpawnedEldar_DarkReapers"), squadSpawned ) Squad_Spawn( squadSpawned, EGroup_GetPosition( EGroup_FromName( "eg_WebGate_2") ) ) elseif EGroup_Count( "eg_WebGate_2" ) == 0 then Rule_Remove(Rule_SpawnDarkReapers) end end
-- DESTROY ORKS
-- player finds some orks being attacked by eldar.
function Rule_PlayerEncounteredOrksTEST() --~ and not Event_IsAnyRunning() if Custom_Player_AreSquadsNearMarker( g_Player1, "mk_OrksAttackEldar", false ) then
print("player in prox of orks false" )
end
if Custom_Player_AreSquadsNearMarker( g_Player1, "mk_OrksAttackEldar", true ) then
print("player in prox of orks true" )
end
end
function Rule_PlayerEncounteredOrks() --~ and not Event_IsAnyRunning() --~ if Custom_Player_AreSquadsNearMarker( g_Player1, "mk_OrksAttackEldar", false ) then --~ --~ print("player in prox of orks false" ) --~ end if Custom_Player_AreSquadsNearMarker( g_Player1, "mk_OrksAttackEldar", false ) then
-- turn on the ORK AI
Cpu_Enable( g_Player3, 1 )
Player_RestrictSquad( g_Player3, "ork_squad_warboss" )
Player_RestrictSquad( g_Player3, "ork_squad_mek_boy" )
Player_RestrictSquad( g_Player3, "ork_squad_looted_tank" )
Player_RestrictSquad( g_Player3, "ork_squad_squiggoth" )
Cpu_EnableComponent( g_Player3, false, CT_BuildBuildings )
Cpu_EnableComponent( g_Player3, false, CT_Resourcing )
-- eldar start attacking orks
Cmd_AttackSGroup("sg_EldarAttackingOrk","sg_OrkShootasUnderAttack")
FOW_RevealMarker( "mk_RevealEldarAttackingOrks", -1 )
SGroup_SetHealthInvulnerable( "sg_EldarAttackingOrk", 0 )
SGroup_SetHealthInvulnerable( "sg_OrkShootasUnderAttack", 0 )
Util_StartIntel( EVENTS.IE_EldarAttackOrks )
Rule_Add(Rule_PlayerEncounteredOrks_Save)
Rule_AddInterval(Rule_OrksAttackAfterWaiting, 1*60 )
Rule_Add(Rule_PlayerDestroyedOrks)
Rule_Remove(Rule_PlayerEncounteredOrks)
end
end
function Rule_PlayerEncounteredOrks_Save() if not Event_IsRunning( EVENTS.IE_EldarAttackOrks ) then Util_ObjectiveCreate( OBJ_SECONDARY_DESTROYORKS, false ) Util_Ping_LoopingMkr("PING_ORKS", "mk_Ping_Orks") Rule_Remove(Rule_PlayerEncounteredOrks_Save) -- save now Util_Autosave( "$252006" ) end end
function Rule_PlayerDestroyedOrks() g_ork_building_exceptions = { "empty" }
g_ork_unit_exceptions =
{
"empty"
}
if( Player_HasBuildingsExcept(g_Player3, g_ork_building_exceptions) == false ) then
if( Player_HasSquadsExcept(g_Player3, g_ork_unit_exceptions ) == false ) then
Util_ObjectiveComplete( OBJ_SECONDARY_DESTROYORKS.title_id )
Util_Ping_Stop("PING_ORKS")
Rule_Remove(Rule_OrksAttackAfterWaiting)
Rule_Remove(Rule_PlayerDestroyedOrks)
end
end
end
function Rule_OrksAttackAfterWaiting() Cmd_AttackMoveMarker( "sg_OrksUnderAttack", "mk_VyperPoint_2" ) Rule_Remove( Rule_OrksAttackAfterWaiting ) end
-- ELDAR IN TRANSPORTS
-- controls the eldar in transports jumping around the place and attacking
-- once the player has captured the 1st listening post, send some guardians to attack it function Rule_GravTank_MoveToListeningPost() Cmd_JumpToMarker( "sg_GravTank_"..g_guardianstransporting, "mk_GravTankJumpTo_1" )
Rule_AddInterval( Rule_EmptyGravTank, 7 )
Rule_Remove(Rule_GravTank_MoveToListeningPost)
Rule_AddInterval(Rule_StartNextGuardians,1)
end
function Rule_EmptyGravTank() Cmd_EmptyTransport( "sg_GravTank_"..g_guardianstransporting, SGroup_GetPosition( "sg_GravTank_"..g_guardianstransporting )) Rule_Remove(Rule_EmptyGravTank) Rule_AddInterval(Rule_GuardiansAttackBase,3) end
function Rule_GuardiansAttackBase() Cmd_AttackMoveMarker( "sg_GuardiansInTank_"..g_guardianstransporting, "mk_PlayersBase" ) Cmd_JumpToMarker( "sg_GravTank_"..g_guardianstransporting, "mk_GravTankLaunch_1" ) Rule_Remove(Rule_GuardiansAttackBase) end
function Rule_StartNextGuardians() if SGroup_Count( "sg_GuardiansInTank_"..g_guardianstransporting ) == 0 then g_guardianstransporting = g_guardianstransporting + 1 if g_guardianstransporting < 3 then Rule_AddInterval(Rule_GravTank_MoveToListeningPost,60) Rule_Remove(Rule_StartNextGuardians) end end end
-- ESTABLISH SECONDARY BASE
-- once the player has reached entrance to final fight area, tell them to setup secondary base.
function Rule_PlayerEstablishSecondaryBase() if Custom_Player_AreSquadsNearMarker( g_Player1, "mk_EstablishSecondaryBase", true ) then Util_StartIntel( EVENTS.IE_SetupSecondaryBase )
Rule_Remove(Rule_PlayerEstablishSecondaryBase)
end
end