mirror of
https://github.com/FlightControl-Master/MOOSE_MISSIONS.git
synced 2025-08-15 10:37:46 +00:00
MOOSE demonstration missions [skip ci]
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,77 +1,114 @@
|
||||
-- At startup of the overall mission, we spawn 10 possible escort planes in "Uncontrolled" state.
|
||||
|
||||
EscortSpawn = SPAWN:NewWithAlias( "Red A2G Escort Template", "Red A2G Escort AI" )
|
||||
EscortSpawn = SPAWN
|
||||
:NewWithAlias( "Red A2G Escort Template", "Red A2G Escort AI" )
|
||||
:InitUnControlled( true )
|
||||
|
||||
for ID = 1, 10 do
|
||||
EscortSpawn:SpawnAtAirbase( AIRBASE:FindByName( AIRBASE.Caucasus.Sochi_Adler ), SPAWN.Takeoff.Cold )
|
||||
end
|
||||
|
||||
Escort = {} -- #list<#number>
|
||||
EscortSpawn:InitUnControlled( false )
|
||||
EscortSpawn:SetSpawnIndex() -- Reset the spawning. So new planes will be respawned from the beginning.
|
||||
|
||||
|
||||
--- @type EscortTable
|
||||
-- @field Core.Set#SET_GROUP Set
|
||||
-- @field AI.AI_Escort#ESCORT Escort
|
||||
|
||||
--- @list<#EscortTable>
|
||||
Escort = {}
|
||||
|
||||
EscortClients = SET_CLIENT:New():FilterPrefixes( "Red A2G Pilot" ):FilterStart()
|
||||
|
||||
-- We setup a process where a new spawn of a client plane will trigger a menu option
|
||||
-- to request an escort from the pool of escorts.
|
||||
|
||||
EventHandlerBirth = EVENTHANDLER:New()
|
||||
|
||||
EventHandlerBirth:HandleEvent( EVENTS.Birth )
|
||||
|
||||
|
||||
function SpawnNewEscorts( EscortUnit )
|
||||
env.info("new escort")
|
||||
local ID = EscortUnit:GetID()
|
||||
Escort[ID] = Escort[ID] or {}
|
||||
Escort[ID].Set = SET_GROUP:New():FilterCoalitions( "red" ):FilterPrefixes( "Red A2G Escort AI" ):_FilterStart()
|
||||
Escort[ID] = Escort[ID] or {}
|
||||
Escort[ID].Set = SET_GROUP:New():FilterCoalitions( "red" ):FilterPrefixes( "Red A2G Escort AI" ):FilterCrashes():FilterDeads()
|
||||
|
||||
-- Spawn a new escort
|
||||
local EscortGroup = EscortSpawn:SpawnAtAirbase( AIRBASE:FindByName( AIRBASE.Caucasus.Sochi_Adler ), SPAWN.Takeoff.Cold )
|
||||
Escort[ID].Set:AddGroup( EscortGroup )
|
||||
|
||||
-- Now setup the AI_ESCORT to make the new spawned escort follow the EscortUnit.
|
||||
Escort[ID].Escort = AI_ESCORT:New( EscortUnit, Escort[ID].Set, "Escort A2G", "Briefing" )
|
||||
Escort[ID].Escort:Menus()
|
||||
Escort[ID].Escort:__Start( 5 )
|
||||
Escort[ID].Escort = AI_ESCORT:New( EscortUnit, Escort[ID].Set, "Escort A2G", "Briefing" )
|
||||
local EscortObject = Escort[ID].Escort -- AI.AI_Escort#AI_ESCORT
|
||||
EscortObject:Menus()
|
||||
end
|
||||
|
||||
-- We setup a process where a new spawn of a client plane will trigger a menu option
|
||||
-- to request an escort from the pool of escorts.
|
||||
|
||||
EventHandlerPlayer = EVENTHANDLER:New()
|
||||
|
||||
EventHandlerPlayer:HandleEvent( EVENTS.Birth )
|
||||
|
||||
|
||||
--- @param Core.Event#EVENT self
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
function EventHandlerBirth:OnEventBirth( EventData )
|
||||
function EventHandlerPlayer:OnEventBirth( EventData )
|
||||
|
||||
local EventUnit = EventData.IniUnit
|
||||
local EventGroup = EventUnit:GetGroup()
|
||||
|
||||
if EscortClients:FindClient( EventUnit:GetName() ) then
|
||||
|
||||
if not EventGroup.MenuRequestEscort then
|
||||
EventGroup.MenuRequestEscort = MENU_GROUP_COMMAND:New( EventGroup, "Request A2G Escort", nil,
|
||||
function( EventUnit )
|
||||
env.info("call")
|
||||
local ID = EventUnit:GetID()
|
||||
if Escort[ID] then
|
||||
-- There is already an escort group set spawned previously. Let's check if the escorts are still alive.
|
||||
local EscortGroupSet = Escort[ID].Set
|
||||
local OneEscortAlive = false
|
||||
EscortGroupSet:ForEachGroupAlive(
|
||||
function( EscortGroup )
|
||||
OneEscortAlive = true
|
||||
end
|
||||
)
|
||||
|
||||
if OneEscortAlive == false then
|
||||
SpawnNewEscorts( EventUnit )
|
||||
end
|
||||
EventGroup.MenuRequestEscort = MENU_GROUP_COMMAND:New( EventGroup, "Request A2G Escort", nil,
|
||||
function( EventUnit )
|
||||
env.info("call")
|
||||
local ID = EventUnit:GetID()
|
||||
if Escort[ID] then
|
||||
|
||||
else
|
||||
SpawnNewEscorts( EventUnit )
|
||||
|
||||
end
|
||||
|
||||
end, EventUnit
|
||||
)
|
||||
end
|
||||
end
|
||||
-- There is already an escort group set spawned previously. Let's check if the escorts are still alive.
|
||||
local EscortGroupSet = Escort[ID].Set
|
||||
local OneEscortAlive = false
|
||||
EscortGroupSet:ForEachGroupAlive(
|
||||
function( EscortGroup )
|
||||
SpawnNewEscorts( EventUnit, EscortGroup )
|
||||
end
|
||||
)
|
||||
else
|
||||
SpawnNewEscorts( EventUnit )
|
||||
end
|
||||
|
||||
Escort[ID].Escort:FormationTrail( 50, 100, 50)
|
||||
Escort[ID].Escort:__Start( 5 )
|
||||
|
||||
end, EventUnit
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
EventHandlerPlayer:HandleEvent( EVENTS.PlayerLeaveUnit )
|
||||
|
||||
--- @param Core.Event#EVENT self
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
function EventHandlerPlayer:OnEventPlayerLeaveUnit( EventData )
|
||||
|
||||
local FollowGroupSet = SET_GROUP:New():FilterCategories( { "plane" } ):FilterCoalitions( "red" ):FilterPrefixes( { "Red A2G Escort" } )
|
||||
local EventUnit = EventData.IniUnit
|
||||
local EventGroup = EventUnit:GetGroup()
|
||||
|
||||
if EscortClients:FindClient( EventUnit:GetName() ) then
|
||||
|
||||
local ID = EventUnit:GetID()
|
||||
local EscortGroupSet = Escort[ID].Set -- Core.Set#SET_GROUP
|
||||
local EscortGroup = Escort[ID].Escort -- Core.Set#SET_GROUP
|
||||
EscortGroupSet:ForEachGroupAlive(
|
||||
function( EscortGroup )
|
||||
EscortGroup:Destroy()
|
||||
end
|
||||
)
|
||||
|
||||
local LeaderUnit = UNIT:FindByName( "Leader" )
|
||||
EscortGroupSet:Clear()
|
||||
EscortGroup = nil
|
||||
|
||||
if EventGroup.MenuRequestEscort then
|
||||
EventGroup.MenuRequestEscort:Remove()
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user