This commit is contained in:
FlightControl
2017-06-09 20:35:46 +02:00
parent e17de754a3
commit 9f22e2cc71
5 changed files with 426 additions and 55 deletions
+390 -44
View File
@@ -162,7 +162,22 @@ do -- AI_A2A_DISPATCHER
Tasks = {}, Tasks = {},
SweepZones = {}, SweepZones = {},
} }
--- Enumerator for spawns at airbases
-- @type AI_A2A_DISPATCHER.Takeoff
-- @extends Wrapper.Group#GROUP.Takeoff
--- @field #AI_A2A_DISPATCHER.Takeoff Takeoff
AI_A2A_DISPATCHER.Takeoff = GROUP.Takeoff
--- Defnes Landing location.
-- @field Landing
AI_A2A_DISPATCHER.Landing = {
NearAirbase = 1,
AtRunway = 2,
AtEngineShutdown = 3,
}
--- AI_A2A_DISPATCHER constructor. --- AI_A2A_DISPATCHER constructor.
-- @param #AI_A2A_DISPATCHER self -- @param #AI_A2A_DISPATCHER self
@@ -294,6 +309,10 @@ do -- AI_A2A_DISPATCHER
self:HandleEvent( EVENTS.Crash, self.OnEventCrashOrDead ) self:HandleEvent( EVENTS.Crash, self.OnEventCrashOrDead )
self:HandleEvent( EVENTS.Dead, self.OnEventCrashOrDead ) self:HandleEvent( EVENTS.Dead, self.OnEventCrashOrDead )
self:HandleEvent( EVENTS.Land )
self:HandleEvent( EVENTS.EngineShutdown )
self:__Start( 5 ) self:__Start( 5 )
return self return self
@@ -305,6 +324,44 @@ do -- AI_A2A_DISPATCHER
self.Detection:ForgetDetectedUnit( EventData.IniUnitName ) self.Detection:ForgetDetectedUnit( EventData.IniUnitName )
end end
--- @param #AI_A2A_DISPATCHER self
-- @param Core.Event#EVENTDATA EventData
function AI_A2A_DISPATCHER:OnEventLand( EventData )
local DefenderUnit = EventData.IniUnit
local Defender = EventData.IniGroup
local Squadron = self:GetSquadronFromDefender( Defender )
if Squadron then
self:F( { SquadronName = Squadron.Name } )
local LandingMethod = self:GetSquadronLanding( Squadron.Name )
if LandingMethod == AI_A2A_DISPATCHER.Landing.AtRunway then
local DefenderSize = Defender:GetSize()
if DefenderSize == 1 then
self:RemoveDefenderFromSquadron( Squadron, Defender )
end
DefenderUnit:Destroy()
end
end
end
--- @param #AI_A2A_DISPATCHER self
-- @param Core.Event#EVENTDATA EventData
function AI_A2A_DISPATCHER:OnEventEngineShutdown( EventData )
local DefenderUnit = EventData.IniUnit
local Defender = EventData.IniGroup
local Squadron = self:GetSquadronFromDefender( Defender )
if Squadron then
self:F( { SquadronName = Squadron.Name } )
local LandingMethod = self:GetSquadronLanding( Squadron.Name )
if LandingMethod == AI_A2A_DISPATCHER.Landing.AtEngineShutdown then
local DefenderSize = Defender:GetSize()
if DefenderSize == 1 then
self:RemoveDefenderFromSquadron( Squadron, Defender )
end
DefenderUnit:Destroy()
end
end
end
--- Define the radius to engage any target by airborne friendlies, which are executing cap or returning from an intercept mission. --- Define the radius to engage any target by airborne friendlies, which are executing cap or returning from an intercept mission.
-- So, if there is a target area detected and reported, -- So, if there is a target area detected and reported,
-- then any friendlies that are airborne near this target area, -- then any friendlies that are airborne near this target area,
@@ -369,61 +426,61 @@ do -- AI_A2A_DISPATCHER
--- ---
-- @param #AI_A2A_DISPATCHER self -- @param #AI_A2A_DISPATCHER self
function AI_A2A_DISPATCHER:GetDefenderTask( AIGroup ) function AI_A2A_DISPATCHER:GetDefenderTask( Defender )
return self.DefenderTasks[AIGroup] return self.DefenderTasks[Defender]
end end
--- ---
-- @param #AI_A2A_DISPATCHER self -- @param #AI_A2A_DISPATCHER self
function AI_A2A_DISPATCHER:GetDefenderTaskFsm( AIGroup ) function AI_A2A_DISPATCHER:GetDefenderTaskFsm( Defender )
return self:GetDefenderTask( AIGroup ).Fsm return self:GetDefenderTask( Defender ).Fsm
end end
--- ---
-- @param #AI_A2A_DISPATCHER self -- @param #AI_A2A_DISPATCHER self
function AI_A2A_DISPATCHER:GetDefenderTaskTarget( AIGroup ) function AI_A2A_DISPATCHER:GetDefenderTaskTarget( Defender )
return self:GetDefenderTask( AIGroup ).Target return self:GetDefenderTask( Defender ).Target
end end
--- ---
-- @param #AI_A2A_DISPATCHER self -- @param #AI_A2A_DISPATCHER self
function AI_A2A_DISPATCHER:ClearDefenderTask( AIGroup ) function AI_A2A_DISPATCHER:ClearDefenderTask( Defender )
if AIGroup:IsAlive() and self.DefenderTasks[AIGroup] then if Defender:IsAlive() and self.DefenderTasks[Defender] then
local Target = self.DefenderTasks[AIGroup].Target local Target = self.DefenderTasks[Defender].Target
local Message = "Clearing (" .. self.DefenderTasks[AIGroup].Type .. ") " local Message = "Clearing (" .. self.DefenderTasks[Defender].Type .. ") "
Message = Message .. AIGroup:GetName() Message = Message .. Defender:GetName()
if Target then if Target then
Message = Message .. ( Target and ( " from " .. Target.Index .. " [" .. Target.Set:Count() .. "]" ) ) or "" Message = Message .. ( Target and ( " from " .. Target.Index .. " [" .. Target.Set:Count() .. "]" ) ) or ""
end end
self:F( { Target = Message } ) self:F( { Target = Message } )
end end
self.DefenderTasks[AIGroup] = nil self.DefenderTasks[Defender] = nil
return self return self
end end
--- ---
-- @param #AI_A2A_DISPATCHER self -- @param #AI_A2A_DISPATCHER self
function AI_A2A_DISPATCHER:ClearDefenderTaskTarget( AIGroup ) function AI_A2A_DISPATCHER:ClearDefenderTaskTarget( Defender )
local DefenderTask = self:GetDefenderTask( AIGroup ) local DefenderTask = self:GetDefenderTask( Defender )
if AIGroup:IsAlive() and DefenderTask then if Defender:IsAlive() and DefenderTask then
local Target = DefenderTask.Target local Target = DefenderTask.Target
local Message = "Clearing (" .. DefenderTask.Type .. ") " local Message = "Clearing (" .. DefenderTask.Type .. ") "
Message = Message .. AIGroup:GetName() Message = Message .. Defender:GetName()
if Target then if Target then
Message = Message .. ( Target and ( " from " .. Target.Index .. " [" .. Target.Set:Count() .. "]" ) ) or "" Message = Message .. ( Target and ( " from " .. Target.Index .. " [" .. Target.Set:Count() .. "]" ) ) or ""
end end
self:F( { Target = Message } ) self:F( { Target = Message } )
end end
if AIGroup and DefenderTask and DefenderTask.Target then if Defender and DefenderTask and DefenderTask.Target then
DefenderTask.Target = nil DefenderTask.Target = nil
end end
if AIGroup and DefenderTask then if Defender and DefenderTask then
if DefenderTask.Fsm:Is( "Fuel" ) if DefenderTask.Fsm:Is( "Fuel" )
or DefenderTask.Fsm:Is( "LostControl") or DefenderTask.Fsm:Is( "LostControl")
or DefenderTask.Fsm:Is( "Damaged" ) then or DefenderTask.Fsm:Is( "Damaged" ) then
self:ClearDefenderTask( AIGroup ) self:ClearDefenderTask( Defender )
end end
end end
return self return self
@@ -432,13 +489,14 @@ do -- AI_A2A_DISPATCHER
--- ---
-- @param #AI_A2A_DISPATCHER self -- @param #AI_A2A_DISPATCHER self
function AI_A2A_DISPATCHER:SetDefenderTask( AIGroup, Type, Fsm, Target ) function AI_A2A_DISPATCHER:SetDefenderTask( Defender, Type, Fsm, Target )
self.DefenderTasks[AIGroup] = self.DefenderTasks[AIGroup] or {}
self.DefenderTasks[AIGroup].Type = Type self.DefenderTasks[Defender] = self.DefenderTasks[Defender] or {}
self.DefenderTasks[AIGroup].Fsm = Fsm self.DefenderTasks[Defender].Type = Type
self.DefenderTasks[Defender].Fsm = Fsm
if Target then if Target then
self:SetDefenderTaskTarget( AIGroup, Target ) self:SetDefenderTaskTarget( Defender, Target )
end end
return self return self
end end
@@ -447,15 +505,15 @@ do -- AI_A2A_DISPATCHER
--- ---
-- @param #AI_A2A_DISPATCHER self -- @param #AI_A2A_DISPATCHER self
-- @param Wrapper.Group#GROUP AIGroup -- @param Wrapper.Group#GROUP AIGroup
function AI_A2A_DISPATCHER:SetDefenderTaskTarget( AIGroup, Target ) function AI_A2A_DISPATCHER:SetDefenderTaskTarget( Defender, Target )
local Message = "(" .. self.DefenderTasks[AIGroup].Type .. ") " local Message = "(" .. self.DefenderTasks[Defender].Type .. ") "
Message = Message .. AIGroup:GetName() Message = Message .. Defender:GetName()
Message = Message .. ( Target and ( " target " .. Target.Index .. " [" .. Target.Set:Count() .. "]" ) ) or "" Message = Message .. ( Target and ( " target " .. Target.Index .. " [" .. Target.Set:Count() .. "]" ) ) or ""
self:F( { Target = Message } ) self:F( { Target = Message } )
if Target then if Target then
AIGroup:MessageToAll( Message, 1200 ) Defender:MessageToAll( Message, 1200 )
self.DefenderTasks[AIGroup].Target = Target self.DefenderTasks[Defender].Target = Target
end end
return self return self
end end
@@ -471,6 +529,7 @@ do -- AI_A2A_DISPATCHER
local DefenderSquadron = self.DefenderSquadrons[SquadronName] local DefenderSquadron = self.DefenderSquadrons[SquadronName]
self:E( { AirbaseName = AirbaseName } ) self:E( { AirbaseName = AirbaseName } )
DefenderSquadron.Name = SquadronName
DefenderSquadron.Airbase = AIRBASE:FindByName( AirbaseName ) DefenderSquadron.Airbase = AIRBASE:FindByName( AirbaseName )
self:E( { Airbase = DefenderSquadron.Airbase } ) self:E( { Airbase = DefenderSquadron.Airbase } )
self:E( { AirbaseObject = DefenderSquadron.Airbase:GetDCSObject() } ) self:E( { AirbaseObject = DefenderSquadron.Airbase:GetDCSObject() } )
@@ -478,17 +537,18 @@ do -- AI_A2A_DISPATCHER
DefenderSquadron.Spawn = {} DefenderSquadron.Spawn = {}
if type( SpawnTemplates ) == "string" then if type( SpawnTemplates ) == "string" then
local SpawnTemplate = SpawnTemplates local SpawnTemplate = SpawnTemplates
self.DefenderSpawns[SpawnTemplate] = self.DefenderSpawns[SpawnTemplate] or SPAWN:New( SpawnTemplate ) self.DefenderSpawns[SpawnTemplate] = self.DefenderSpawns[SpawnTemplate] or SPAWN:New( SpawnTemplate ):InitCleanUp( 30 )
DefenderSquadron.Spawn[1] = self.DefenderSpawns[SpawnTemplate] DefenderSquadron.Spawn[1] = self.DefenderSpawns[SpawnTemplate]
else else
for TemplateID, SpawnTemplate in pairs( SpawnTemplates ) do for TemplateID, SpawnTemplate in pairs( SpawnTemplates ) do
self.DefenderSpawns[SpawnTemplate] = self.DefenderSpawns[SpawnTemplate] or SPAWN:New( SpawnTemplate ) self.DefenderSpawns[SpawnTemplate] = self.DefenderSpawns[SpawnTemplate] or SPAWN:New( SpawnTemplate ):InitCleanUp( 30 )
DefenderSquadron.Spawn[#DefenderSquadron.Spawn+1] = self.DefenderSpawns[SpawnTemplate] DefenderSquadron.Spawn[#DefenderSquadron.Spawn+1] = self.DefenderSpawns[SpawnTemplate]
end end
end end
DefenderSquadron.Resources = Resources DefenderSquadron.Resources = Resources
self:SetSquadronOverhead( SquadronName, 1 ) self:SetSquadronOverhead( SquadronName, 1 )
self:SetSquadronTakeoffFromParkingHot( SquadronName )
return self return self
end end
@@ -680,7 +740,7 @@ do -- AI_A2A_DISPATCHER
-- @usage: -- @usage:
-- --
-- local Dispatcher = AI_A2A_DISPATCHER:New( ... ) -- local Dispatcher = AI_A2A_DISPATCHER:New( ... )
-- Dispatcher:SetSquadronGrouping( 2 ) -- Dispatcher:SetSquadronGrouping( "SquadronName", 2 )
-- --
-- --
-- @return #AI_A2A_DISPATCHER -- @return #AI_A2A_DISPATCHER
@@ -692,6 +752,285 @@ do -- AI_A2A_DISPATCHER
return self return self
end end
--- Defines the method at which new flights will spawn and take-off as part of the defense system.
-- @param #AI_A2A_DISPATCHER self
-- @param #string SquadronName The name of the squadron.
-- @param #number Takeoff From the airbase hot, from the airbase cold, in the air, from the runway.
-- @usage:
--
-- local Dispatcher = AI_A2A_DISPATCHER:New( ... )
--
-- -- Let new flights take-off in the air.
-- Dispatcher:SetSquadronTakeoff( "SquadronName", AI_A2A_Dispatcher.Takeoff.Air )
--
-- -- Let new flights take-off from the runway.
-- Dispatcher:SetSquadronTakeoff( "SquadronName", AI_A2A_Dispatcher.Takeoff.Runway )
--
-- -- Let new flights take-off from the airbase hot.
-- Dispatcher:SetSquadronTakeoff( "SquadronName", AI_A2A_Dispatcher.Takeoff.Hot )
--
-- -- Let new flights take-off from the airbase cold.
-- Dispatcher:SetSquadronTakeoff( "SquadronName", AI_A2A_Dispatcher.Takeoff.Cold )
--
--
-- @return #AI_A2A_DISPATCHER
--
function AI_A2A_DISPATCHER:SetSquadronTakeoff( SquadronName, Takeoff )
local DefenderSquadron = self:GetSquadron( SquadronName )
DefenderSquadron.Takeoff = Takeoff
return self
end
--- Gets the method at which new flights will spawn and take-off as part of the defense system.
-- @param #AI_A2A_DISPATCHER self
-- @param #string SquadronName The name of the squadron.
-- @return #number Takeoff From the airbase hot, from the airbase cold, in the air, from the runway.
-- @usage:
--
-- local Dispatcher = AI_A2A_DISPATCHER:New( ... )
--
-- -- Let new flights take-off in the air.
-- local TakeoffMethod = Dispatcher:GetSquadronTakeoff( "SquadronName" )
-- if TakeOffMethod == , AI_A2A_Dispatcher.Takeoff.InAir then
-- ...
-- end
--
function AI_A2A_DISPATCHER:GetSquadronTakeoff( SquadronName )
local DefenderSquadron = self:GetSquadron( SquadronName )
return DefenderSquadron.Takeoff
end
--- Sets flights to take-off in the air, as part of the defense system.
-- @param #AI_A2A_DISPATCHER self
-- @param #string SquadronName The name of the squadron.
-- @usage:
--
-- local Dispatcher = AI_A2A_DISPATCHER:New( ... )
--
-- -- Let new flights take-off in the air.
-- Dispatcher:SetSquadronTakeoffInAir( "SquadronName" )
--
-- @return #AI_A2A_DISPATCHER
--
function AI_A2A_DISPATCHER:SetSquadronTakeoffInAir( SquadronName )
self:SetSquadronTakeoff( SquadronName, AI_A2A_DISPATCHER.Takeoff.Air )
return self
end
--- Sets flights to take-off from the runway, as part of the defense system.
-- @param #AI_A2A_DISPATCHER self
-- @param #string SquadronName The name of the squadron.
-- @usage:
--
-- local Dispatcher = AI_A2A_DISPATCHER:New( ... )
--
-- -- Let new flights take-off in the air.
-- Dispatcher:SetSquadronTakeoffFromRunway( "SquadronName" )
--
-- @return #AI_A2A_DISPATCHER
--
function AI_A2A_DISPATCHER:SetSquadronTakeoffFromRunway( SquadronName )
self:SetSquadronTakeoff( SquadronName, AI_A2A_DISPATCHER.Takeoff.Runway )
return self
end
--- Sets flights to take-off from the airbase at a hot location, as part of the defense system.
-- @param #AI_A2A_DISPATCHER self
-- @param #string SquadronName The name of the squadron.
-- @usage:
--
-- local Dispatcher = AI_A2A_DISPATCHER:New( ... )
--
-- -- Let new flights take-off in the air.
-- Dispatcher:SetSquadronTakeoffFromParkingHot( "SquadronName" )
--
-- @return #AI_A2A_DISPATCHER
--
function AI_A2A_DISPATCHER:SetSquadronTakeoffFromParkingHot( SquadronName )
self:SetSquadronTakeoff( SquadronName, AI_A2A_DISPATCHER.Takeoff.Hot )
return self
end
--- Sets flights to take-off from the airbase at a cold location, as part of the defense system.
-- @param #AI_A2A_DISPATCHER self
-- @param #string SquadronName The name of the squadron.
-- @usage:
--
-- local Dispatcher = AI_A2A_DISPATCHER:New( ... )
--
-- -- Let new flights take-off in the air.
-- Dispatcher:SetSquadronTakeoffFromParkingCold( "SquadronName" )
--
-- @return #AI_A2A_DISPATCHER
--
function AI_A2A_DISPATCHER:SetSquadronTakeoffFromParkingCold( SquadronName )
self:SetSquadronTakeoff( SquadronName, AI_A2A_DISPATCHER.Takeoff.Cold )
return self
end
--- Defines the method at which flights will land and despawn as part of the defense system.
-- @param #AI_A2A_DISPATCHER self
-- @param #string SquadronName The name of the squadron.
-- @param #number Landing The landing method which can be NearAirbase, AtRunway, AtEngineShutdown
-- @usage:
--
-- local Dispatcher = AI_A2A_DISPATCHER:New( ... )
--
-- -- Let new flights take-off in the air.
-- Dispatcher:SetSquadronLanding( "SquadronName", AI_A2A_Dispatcher.Landing.NearAirbase )
--
-- -- Let new flights take-off from the runway.
-- Dispatcher:SetSquadronLanding( "SquadronName", AI_A2A_Dispatcher.Landing.AtRunway )
--
-- -- Let new flights take-off from the airbase hot.
-- Dispatcher:SetSquadronLanding( "SquadronName", AI_A2A_Dispatcher.Landing.AtEngineShutdown )
--
-- @return #AI_A2A_DISPATCHER
function AI_A2A_DISPATCHER:SetSquadronLanding( SquadronName, Landing )
local DefenderSquadron = self:GetSquadron( SquadronName )
DefenderSquadron.Landing = Landing
return self
end
--- Gets the method at which flights will land and despawn as part of the defense system.
-- @param #AI_A2A_DISPATCHER self
-- @param #string SquadronName The name of the squadron.
-- @return #number Landing The landing method which can be NearAirbase, AtRunway, AtEngineShutdown
-- @usage:
--
-- local Dispatcher = AI_A2A_DISPATCHER:New( ... )
--
-- -- Let new flights take-off in the air.
-- local LandingMethod = Dispatcher:GetSquadronLanding( "SquadronName", AI_A2A_Dispatcher.Landing.NearAirbase )
-- if LandingMethod == AI_A2A_Dispatcher.Landing.NearAirbase then
-- ...
-- end
--
function AI_A2A_DISPATCHER:GetSquadronLanding( SquadronName )
local DefenderSquadron = self:GetSquadron( SquadronName )
return DefenderSquadron.Landing
end
--- Sets flights to land and despawn near the airbase in the air, as part of the defense system.
-- @param #AI_A2A_DISPATCHER self
-- @param #string SquadronName The name of the squadron.
-- @usage:
--
-- local Dispatcher = AI_A2A_DISPATCHER:New( ... )
--
-- -- Let flights land in the air and despawn.
-- Dispatcher:SetSquadronLandingNearAirbase( "SquadronName" )
--
-- @return #AI_A2A_DISPATCHER
function AI_A2A_DISPATCHER:SetSquadronLandingNearAirbase( SquadronName )
self:SetSquadronLanding( SquadronName, AI_A2A_DISPATCHER.Landing.NearAirbase )
return self
end
--- Sets flights to land and despawn at the runway, as part of the defense system.
-- @param #AI_A2A_DISPATCHER self
-- @param #string SquadronName The name of the squadron.
-- @usage:
--
-- local Dispatcher = AI_A2A_DISPATCHER:New( ... )
--
-- -- Let flights land at the runway and despawn.
-- Dispatcher:SetSquadronLandingAtRunway( "SquadronName" )
--
-- @return #AI_A2A_DISPATCHER
function AI_A2A_DISPATCHER:SetSquadronLandingAtRunway( SquadronName )
self:SetSquadronLanding( SquadronName, AI_A2A_DISPATCHER.Landing.AtRunway )
return self
end
--- Sets flights to land and despawn at engine shutdown, as part of the defense system.
-- @param #AI_A2A_DISPATCHER self
-- @param #string SquadronName The name of the squadron.
-- @usage:
--
-- local Dispatcher = AI_A2A_DISPATCHER:New( ... )
--
-- -- Let flights land and despawn at engine shutdown.
-- Dispatcher:SetSquadronLandingAtEngineShutdown( "SquadronName" )
--
-- @return #AI_A2A_DISPATCHER
function AI_A2A_DISPATCHER:SetSquadronLandingAtEngineShutdown( SquadronName )
self:SetSquadronLanding( SquadronName, AI_A2A_DISPATCHER.Landing.AtEngineShutdown )
return self
end
--- Sets flights to take-off from the airbase at a cold location, as part of the defense system.
-- @param #AI_A2A_DISPATCHER self
-- @param #string SquadronName The name of the squadron.
-- @usage:
--
-- local Dispatcher = AI_A2A_DISPATCHER:New( ... )
--
-- -- Let new flights take-off in the air.
-- Dispatcher:SetSquadronLandingFromAirbaseCold( "SquadronName" )
--
-- @return #AI_A2A_DISPATCHER
function AI_A2A_DISPATCHER:SetSquadronLandingFromAirbaseCold( SquadronName )
self:SetSquadronLanding( SquadronName, AI_A2A_DISPATCHER.Landing.FromAirbaseCold )
return self
end
--- @param #AI_A2A_DISPATCHER self
function AI_A2A_DISPATCHER:AddDefenderToSquadron( Squadron, Defender )
self.Defenders = self.Defenders or {}
local DefenderName = Defender:GetName()
self.Defenders[ DefenderName ] = Squadron
Squadron.Resources = Squadron.Resources - 1
self:F( { DefenderName = DefenderName, SquadronResources = Squadron.Resources } )
end
--- @param #AI_A2A_DISPATCHER self
function AI_A2A_DISPATCHER:RemoveDefenderFromSquadron( Squadron, Defender )
self.Defenders = self.Defenders or {}
local DefenderName = Defender:GetName()
Squadron.Resources = Squadron.Resources + 1
self.Defenders[ DefenderName ] = nil
self:F( { DefenderName = DefenderName, SquadronResources = Squadron.Resources } )
end
function AI_A2A_DISPATCHER:GetSquadronFromDefender( Defender )
self.Defenders = self.Defenders or {}
local DefenderName = Defender:GetName()
self:F( { DefenderName = DefenderName } )
return self.Defenders[ DefenderName ]
end
--- Creates an SWEEP task when there are targets for it. --- Creates an SWEEP task when there are targets for it.
-- @param #AI_A2A_DISPATCHER self -- @param #AI_A2A_DISPATCHER self
@@ -820,18 +1159,20 @@ do -- AI_A2A_DISPATCHER
if self:CanCAP( SquadronName ) then if self:CanCAP( SquadronName ) then
local Spawn = DefenderSquadron.Spawn[ math.random( 1, #DefenderSquadron.Spawn ) ] local Spawn = DefenderSquadron.Spawn[ math.random( 1, #DefenderSquadron.Spawn ) ]
Spawn:InitGrouping( DefenderSquadron.Grouping ) Spawn:InitGrouping( DefenderSquadron.Grouping )
local AIGroup = Spawn:SpawnAtAirbase( DefenderSquadron.Airbase )
self:F( { AIGroup = AIGroup:GetName() } ) local TakeoffMethod = self:GetSquadronTakeoff( SquadronName )
local DefenderCAP = Spawn:SpawnAtAirbase( DefenderSquadron.Airbase, TakeoffMethod )
self:AddDefenderToSquadron( DefenderSquadron, DefenderCAP )
if AIGroup then if DefenderCAP then
local Fsm = AI_A2A_CAP:New( AIGroup, Cap.Zone, Cap.FloorAltitude, Cap.CeilingAltitude, Cap.PatrolMinSpeed, Cap.PatrolMaxSpeed, Cap.EngageMinSpeed, Cap.EngageMaxSpeed, Cap.AltType ) local Fsm = AI_A2A_CAP:New( DefenderCAP, Cap.Zone, Cap.FloorAltitude, Cap.CeilingAltitude, Cap.PatrolMinSpeed, Cap.PatrolMaxSpeed, Cap.EngageMinSpeed, Cap.EngageMaxSpeed, Cap.AltType )
Fsm:SetDispatcher( self ) Fsm:SetDispatcher( self )
Fsm:SetHomeAirbase( DefenderSquadron.Airbase ) Fsm:SetHomeAirbase( DefenderSquadron.Airbase )
Fsm:Start() Fsm:Start()
Fsm:__Patrol( 1 ) Fsm:__Patrol( 1 )
self:SetDefenderTask( AIGroup, "CAP", Fsm ) self:SetDefenderTask( DefenderCAP, "CAP", Fsm )
end end
end end
else else
@@ -916,21 +1257,26 @@ do -- AI_A2A_DISPATCHER
else else
Spawn:InitGrouping() Spawn:InitGrouping()
end end
local AIGroup = Spawn:SpawnAtAirbase( DefenderSquadron.Airbase )
self:F( { AIGroup = AIGroup:GetName() } ) local TakeoffMethod = self:GetSquadronTakeoff( ClosestDefenderSquadronName )
local DefenderGCI = Spawn:SpawnAtAirbase( DefenderSquadron.Airbase, TakeoffMethod )
if AIGroup then self:F( { GCIDefender = DefenderGCI:GetName() } )
DefendersCount = DefendersCount - AIGroup:GetSize() self:AddDefenderToSquadron( DefenderSquadron, DefenderGCI )
if DefenderGCI then
DefendersCount = DefendersCount - DefenderGCI:GetSize()
local Fsm = AI_A2A_INTERCEPT:New( AIGroup, Intercept.EngageMinSpeed, Intercept.EngageMaxSpeed ) local Fsm = AI_A2A_INTERCEPT:New( DefenderGCI, Intercept.EngageMinSpeed, Intercept.EngageMaxSpeed )
Fsm:SetDispatcher( self ) Fsm:SetDispatcher( self )
Fsm:SetHomeAirbase( DefenderSquadron.Airbase ) Fsm:SetHomeAirbase( DefenderSquadron.Airbase )
Fsm:Start() Fsm:Start()
Fsm:__Engage( 1, Target.Set ) -- Engage on the TargetSetUnit Fsm:__Engage( 1, Target.Set ) -- Engage on the TargetSetUnit
self:SetDefenderTask( AIGroup, "INTERCEPT", Fsm, Target ) self:SetDefenderTask( DefenderGCI, "INTERCEPT", Fsm, Target )
function Fsm:onafterRTB( AIGroup, From, Event, To ) function Fsm:onafterRTB( AIGroup, From, Event, To )
@@ -129,6 +129,8 @@ function AI_A2A_INTERCEPT:New( AIGroup, EngageMinSpeed, EngageMaxSpeed )
self.EngageMinSpeed = EngageMinSpeed self.EngageMinSpeed = EngageMinSpeed
self.EngageMaxSpeed = EngageMaxSpeed self.EngageMaxSpeed = EngageMaxSpeed
self.PatrolMinSpeed = EngageMinSpeed
self.PatrolMaxSpeed = EngageMaxSpeed
self.PatrolAltType = "RADIO" self.PatrolAltType = "RADIO"
+14 -10
View File
@@ -265,6 +265,14 @@ SPAWN = {
} }
--- Enumerator for spawns at airbases
-- @type SPAWN.Takeoff
-- @extends Wrapper.Group#GROUP.Takeoff
--- @field #SPAWN.Takeoff Takeoff
SPAWN.Takeoff = GROUP.Takeoff
--- @type SPAWN.SpawnZoneTable --- @type SPAWN.SpawnZoneTable
-- @list <Core.Zone#ZONE_BASE> SpawnZone -- @list <Core.Zone#ZONE_BASE> SpawnZone
@@ -980,21 +988,18 @@ end
-- You can use the returned group to further define the route to be followed. -- You can use the returned group to further define the route to be followed.
-- @param #SPAWN self -- @param #SPAWN self
-- @param Wrapper.Airbase#AIRBASE Airbase The @{Airbase} where to spawn the group. -- @param Wrapper.Airbase#AIRBASE Airbase The @{Airbase} where to spawn the group.
-- @param #number SpawnIndex (optional) The index which group to spawn within the given zone. -- @param #SPAWN.Takeoff Takeoff (optional) The location and takeoff method. Default is Hot.
-- @return Wrapper.Group#GROUP that was spawned. -- @return Wrapper.Group#GROUP that was spawned.
-- @return #nil Nothing was spawned. -- @return #nil Nothing was spawned.
function SPAWN:SpawnAtAirbase( Airbase, SpawnIndex ) -- R2.2 function SPAWN:SpawnAtAirbase( Airbase, Takeoff ) -- R2.2
self:F( { self.SpawnTemplatePrefix, Airbase, SpawnIndex } ) self:F( { self.SpawnTemplatePrefix, Airbase } )
local PointVec3 = Airbase:GetPointVec3() local PointVec3 = Airbase:GetPointVec3()
self:T2(PointVec3) self:T2(PointVec3)
if SpawnIndex then Takeoff = Takeoff or SPAWN.Takeoff.Hot
else
SpawnIndex = self.SpawnIndex + 1
end
if self:_GetSpawnIndex( SpawnIndex ) then if self:_GetSpawnIndex( self.SpawnIndex + 1 ) then
local SpawnTemplate = self.SpawnGroups[self.SpawnIndex].SpawnTemplate local SpawnTemplate = self.SpawnGroups[self.SpawnIndex].SpawnTemplate
@@ -1021,8 +1026,7 @@ function SPAWN:SpawnAtAirbase( Airbase, SpawnIndex ) -- R2.2
SpawnTemplate.route.points[1].x = PointVec3.x SpawnTemplate.route.points[1].x = PointVec3.x
SpawnTemplate.route.points[1].y = PointVec3.z SpawnTemplate.route.points[1].y = PointVec3.z
SpawnTemplate.route.points[1].alt = Airbase.y SpawnTemplate.route.points[1].alt = Airbase.y
SpawnTemplate.route.points[1].action = "From Parking Area Hot" SpawnTemplate.route.points[1].type = GROUPTEMPLATE.Takeoff[Takeoff]
SpawnTemplate.route.points[1].type = "TakeOffParkingHot"
SpawnTemplate.route.points[1].airdromeId = Airbase:GetID() SpawnTemplate.route.points[1].airdromeId = Airbase:GetID()
SpawnTemplate.x = PointVec3.x SpawnTemplate.x = PointVec3.x
+19
View File
@@ -91,6 +91,25 @@ GROUP = {
ClassName = "GROUP", ClassName = "GROUP",
} }
--- Enumerator for location at airbases
-- @type GROUP.Takeoff
GROUP.Takeoff = {
Air = 1,
Runway = 2,
Hot = 3,
Cold = 4,
}
GROUPTEMPLATE = {}
GROUPTEMPLATE.Takeoff = {
[GROUP.Takeoff.Air] = "Turning Point",
[GROUP.Takeoff.Runway] = "TakeOff",
[GROUP.Takeoff.Hot] = "TakeOffParkingHot",
[GROUP.Takeoff.Cold] = "TakeOffParking",
}
--- Create a new GROUP from a DCSGroup --- Create a new GROUP from a DCSGroup
-- @param #GROUP self -- @param #GROUP self
-- @param Dcs.DCSWrapper.Group#Group GroupName The DCS Group name -- @param Dcs.DCSWrapper.Group#Group GroupName The DCS Group name
+1 -1
View File
@@ -1,5 +1,5 @@
env.info( '*** MOOSE DYNAMIC INCLUDE START *** ' ) env.info( '*** MOOSE DYNAMIC INCLUDE START *** ' )
env.info( 'Moose Generation Timestamp: 20170608_1332' ) env.info( 'Moose Generation Timestamp: 20170609_2035' )
local base = _G local base = _G