Fixes for patrol.

This commit is contained in:
FlightControl 2018-12-17 19:39:23 +01:00
parent 810cebfe0a
commit cfc9c655c5
7 changed files with 138 additions and 281 deletions

View File

@ -31,11 +31,19 @@ AI_A2G_BAI = {
--- Creates a new AI_A2G_BAI object --- Creates a new AI_A2G_BAI object
-- @param #AI_A2G_BAI self -- @param #AI_A2G_BAI self
-- @param Wrapper.Group#GROUP AIGroup -- @param Wrapper.Group#GROUP AIGroup
-- @param DCS#Speed EngageMinSpeed The minimum speed of the @{Wrapper.Group} in km/h when engaging a target.
-- @param DCS#Speed EngageMaxSpeed The maximum speed of the @{Wrapper.Group} in km/h when engaging a target.
-- @param Core.Zone#ZONE_BASE PatrolZone The @{Zone} where the patrol needs to be executed.
-- @param DCS#Altitude PatrolFloorAltitude The lowest altitude in meters where to execute the patrol.
-- @param DCS#Altitude PatrolCeilingAltitude The highest altitude in meters where to execute the patrol.
-- @param DCS#Speed PatrolMinSpeed The minimum speed of the @{Wrapper.Group} in km/h.
-- @param DCS#Speed PatrolMaxSpeed The maximum speed of the @{Wrapper.Group} in km/h.
-- @param DCS#AltitudeType PatrolAltType The altitude type ("RADIO"=="AGL", "BARO"=="ASL"). Defaults to RADIO
-- @return #AI_A2G_BAI -- @return #AI_A2G_BAI
function AI_A2G_BAI:New( AIGroup, EngageMinSpeed, EngageMaxSpeed ) function AI_A2G_BAI:New( AIGroup, EngageMinSpeed, EngageMaxSpeed, PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed, PatrolAltType )
-- Inherits from BASE -- Inherits from BASE
local self = BASE:Inherit( self, AI_A2G_ENGAGE:New( AIGroup, EngageMinSpeed, EngageMaxSpeed ) ) -- #AI_A2G_BAI local self = BASE:Inherit( self, AI_A2G_PATROL:New( AIGroup, EngageMinSpeed, EngageMaxSpeed, PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed, PatrolAltType ) ) -- #AI_A2G_BAI
return self return self
end end

View File

@ -31,11 +31,19 @@ AI_A2G_CAS = {
--- Creates a new AI_A2G_CAS object --- Creates a new AI_A2G_CAS object
-- @param #AI_A2G_CAS self -- @param #AI_A2G_CAS self
-- @param Wrapper.Group#GROUP AIGroup -- @param Wrapper.Group#GROUP AIGroup
-- @param DCS#Speed EngageMinSpeed The minimum speed of the @{Wrapper.Group} in km/h when engaging a target.
-- @param DCS#Speed EngageMaxSpeed The maximum speed of the @{Wrapper.Group} in km/h when engaging a target.
-- @param Core.Zone#ZONE_BASE PatrolZone The @{Zone} where the patrol needs to be executed.
-- @param DCS#Altitude PatrolFloorAltitude The lowest altitude in meters where to execute the patrol.
-- @param DCS#Altitude PatrolCeilingAltitude The highest altitude in meters where to execute the patrol.
-- @param DCS#Speed PatrolMinSpeed The minimum speed of the @{Wrapper.Group} in km/h.
-- @param DCS#Speed PatrolMaxSpeed The maximum speed of the @{Wrapper.Group} in km/h.
-- @param DCS#AltitudeType PatrolAltType The altitude type ("RADIO"=="AGL", "BARO"=="ASL"). Defaults to RADIO
-- @return #AI_A2G_CAS -- @return #AI_A2G_CAS
function AI_A2G_CAS:New( AIGroup, EngageMinSpeed, EngageMaxSpeed ) function AI_A2G_CAS:New( AIGroup, EngageMinSpeed, EngageMaxSpeed, PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed, PatrolAltType )
-- Inherits from BASE -- Inherits from BASE
local self = BASE:Inherit( self, AI_A2G_ENGAGE:New( AIGroup, EngageMinSpeed, EngageMaxSpeed ) ) -- #AI_A2G_CAS local self = BASE:Inherit( self, AI_A2G_PATROL:New( AIGroup, EngageMinSpeed, EngageMaxSpeed, PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed, PatrolAltType ) ) -- #AI_A2G_CAS
return self return self
end end

View File

@ -2761,7 +2761,7 @@ do -- AI_A2G_DISPATCHER
-- Count the total of defenders on the battlefield. -- Count the total of defenders on the battlefield.
--local DefenderSize = Defender:GetInitialSize() --local DefenderSize = Defender:GetInitialSize()
if DefenderTask.Target then if DefenderTask.Target then
--if DefenderTask.Fsm:Is( "Engaging" ) then if DefenderTask.Fsm:Is( "Engaging" ) then
self:F( "Defender Group Name: " .. Defender:GetName() .. ", Size: " .. DefenderSize ) self:F( "Defender Group Name: " .. Defender:GetName() .. ", Size: " .. DefenderSize )
DefendersTotal = DefendersTotal + DefenderSize DefendersTotal = DefendersTotal + DefenderSize
if DefenderTaskTarget and DefenderTaskTarget.Index == AttackerDetection.Index then if DefenderTaskTarget and DefenderTaskTarget.Index == AttackerDetection.Index then
@ -2775,7 +2775,7 @@ do -- AI_A2G_DISPATCHER
DefendersEngaged = 0 DefendersEngaged = 0
end end
end end
--end end
end end
@ -2921,7 +2921,9 @@ do -- AI_A2G_DISPATCHER
if DefenderPatrol then if DefenderPatrol then
local Fsm = AI_A2G_PATROL:New( DefenderPatrol, Patrol.Zone, Patrol.FloorAltitude, Patrol.CeilingAltitude, Patrol.PatrolMinSpeed, Patrol.PatrolMaxSpeed, Patrol.EngageMinSpeed, Patrol.EngageMaxSpeed, Patrol.AltType ) local AI_A2G_PATROL = { SEAD = AI_A2G_SEAD, BAI = AI_A2G_BAI, CAS = AI_A2G_CAS }
local Fsm = AI_A2G_PATROL[DefenseTaskType]:New( DefenderPatrol, Patrol.EngageMinSpeed, Patrol.EngageMaxSpeed, Patrol.Zone, Patrol.FloorAltitude, Patrol.CeilingAltitude, Patrol.PatrolMinSpeed, Patrol.PatrolMaxSpeed, Patrol.AltType )
Fsm:SetDispatcher( self ) Fsm:SetDispatcher( self )
Fsm:SetHomeAirbase( DefenderSquadron.Airbase ) Fsm:SetHomeAirbase( DefenderSquadron.Airbase )
Fsm:SetFuelThreshold( DefenderSquadron.FuelThreshold or self.DefenderDefault.FuelThreshold, 60 ) Fsm:SetFuelThreshold( DefenderSquadron.FuelThreshold or self.DefenderDefault.FuelThreshold, 60 )
@ -2930,7 +2932,7 @@ do -- AI_A2G_DISPATCHER
Fsm:SetTanker( DefenderSquadron.TankerName or self.DefenderDefault.TankerName ) Fsm:SetTanker( DefenderSquadron.TankerName or self.DefenderDefault.TankerName )
Fsm:Start() Fsm:Start()
self:SetDefenderTask( SquadronName, DefenderPatrol, DefenseTaskType, Fsm ) self:SetDefenderTask( SquadronName, DefenderPatrol, DefenseTaskType, Fsm, nil, DefenderGrouping )
function Fsm:onafterTakeoff( Defender, From, Event, To ) function Fsm:onafterTakeoff( Defender, From, Event, To )
self:F({"Patrol Birth", Defender:GetName()}) self:F({"Patrol Birth", Defender:GetName()})
@ -2967,7 +2969,7 @@ do -- AI_A2G_DISPATCHER
if Dispatcher:GetSquadronLanding( Squadron.Name ) == AI_A2G_DISPATCHER.Landing.NearAirbase then if Dispatcher:GetSquadronLanding( Squadron.Name ) == AI_A2G_DISPATCHER.Landing.NearAirbase then
Dispatcher:RemoveDefenderFromSquadron( Squadron, Defender ) Dispatcher:RemoveDefenderFromSquadron( Squadron, Defender )
Defender:Destroy() Defender:Destroy()
self:ParkDefender( Squadron, Defender ) Dispatcher:ParkDefender( Squadron, Defender )
end end
end end
end end
@ -3425,7 +3427,7 @@ do -- AI_A2G_DISPATCHER
if self.TacticalDisplay then if self.TacticalDisplay then
-- Show tactical situation -- Show tactical situation
Report:Add( string.format( "\n - %s %s ( %s ): ( #%d ) %s" , DetectedItem.Type or " --- ", DetectedItem.ItemID, DetectedItem.Index, DetectedItem.Set:Count(), DetectedItem.Set:GetObjectNames() ) ) Report:Add( string.format( "\n - %4s %s ( %s ): ( #%d ) %s" , DetectedItem.Type or " --- ", DetectedItem.ItemID, DetectedItem.Index, DetectedItem.Set:Count(), DetectedItem.Set:GetObjectNames() ) )
for Defender, DefenderTask in pairs( self:GetDefenderTasks() ) do for Defender, DefenderTask in pairs( self:GetDefenderTasks() ) do
local Defender = Defender -- Wrapper.Group#GROUP local Defender = Defender -- Wrapper.Group#GROUP
if DefenderTask.Target and DefenderTask.Target.Index == DetectedItem.Index then if DefenderTask.Target and DefenderTask.Target.Index == DetectedItem.Index then

View File

@ -97,7 +97,7 @@ function AI_A2G_ENGAGE:New( AIGroup, EngageMinSpeed, EngageMaxSpeed )
self.PatrolAltType = "RADIO" self.PatrolAltType = "RADIO"
self:AddTransition( { "Started", "Engaging", "Returning", "Airborne" }, "Engage", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_A2G_ENGAGE. self:AddTransition( { "Started", "Engaging", "Returning", "Airborne", "Patrolling" }, "Engage", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_A2G_ENGAGE.
--- OnBefore Transition Handler for Event Engage. --- OnBefore Transition Handler for Event Engage.
-- @function [parent=#AI_A2G_ENGAGE] OnBeforeEngage -- @function [parent=#AI_A2G_ENGAGE] OnBeforeEngage

View File

@ -10,7 +10,7 @@
-- @image AI_Air_To_Ground_Patrol.JPG -- @image AI_Air_To_Ground_Patrol.JPG
--- @type AI_A2G_PATROL --- @type AI_A2G_PATROL
-- @extends AI.AI_A2A_Patrol#AI_A2A_PATROL -- @extends AI.AI_A2G_Engage#AI_A2G_ENGAGE
--- The AI_A2G_PATROL class implements the core functions to patrol a @{Zone} by an AI @{Wrapper.Group} or @{Wrapper.Group} --- The AI_A2G_PATROL class implements the core functions to patrol a @{Zone} by an AI @{Wrapper.Group} or @{Wrapper.Group}
@ -100,30 +100,33 @@ AI_A2G_PATROL = {
--- Creates a new AI_A2G_PATROL object --- Creates a new AI_A2G_PATROL object
-- @param #AI_A2G_PATROL self -- @param #AI_A2G_PATROL self
-- @param Wrapper.Group#GROUP AIPatrol -- @param Wrapper.Group#GROUP AIPatrol
-- @param DCS#Speed EngageMinSpeed The minimum speed of the @{Wrapper.Group} in km/h when engaging a target.
-- @param DCS#Speed EngageMaxSpeed The maximum speed of the @{Wrapper.Group} in km/h when engaging a target.
-- @param Core.Zone#ZONE_BASE PatrolZone The @{Zone} where the patrol needs to be executed. -- @param Core.Zone#ZONE_BASE PatrolZone The @{Zone} where the patrol needs to be executed.
-- @param DCS#Altitude PatrolFloorAltitude The lowest altitude in meters where to execute the patrol. -- @param DCS#Altitude PatrolFloorAltitude The lowest altitude in meters where to execute the patrol.
-- @param DCS#Altitude PatrolCeilingAltitude The highest altitude in meters where to execute the patrol. -- @param DCS#Altitude PatrolCeilingAltitude The highest altitude in meters where to execute the patrol.
-- @param DCS#Speed PatrolMinSpeed The minimum speed of the @{Wrapper.Group} in km/h. -- @param DCS#Speed PatrolMinSpeed The minimum speed of the @{Wrapper.Group} in km/h.
-- @param DCS#Speed PatrolMaxSpeed The maximum speed of the @{Wrapper.Group} in km/h. -- @param DCS#Speed PatrolMaxSpeed The maximum speed of the @{Wrapper.Group} in km/h.
-- @param DCS#Speed EngageMinSpeed The minimum speed of the @{Wrapper.Group} in km/h when engaging a target.
-- @param DCS#Speed EngageMaxSpeed The maximum speed of the @{Wrapper.Group} in km/h when engaging a target.
-- @param DCS#AltitudeType PatrolAltType The altitude type ("RADIO"=="AGL", "BARO"=="ASL"). Defaults to RADIO -- @param DCS#AltitudeType PatrolAltType The altitude type ("RADIO"=="AGL", "BARO"=="ASL"). Defaults to RADIO
-- @return #AI_A2G_PATROL -- @return #AI_A2G_PATROL
function AI_A2G_PATROL:New( AIPatrol, PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed, EngageMinSpeed, EngageMaxSpeed, PatrolAltType ) function AI_A2G_PATROL:New( AIPatrol, EngageMinSpeed, EngageMaxSpeed, PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed, PatrolAltType )
-- Inherits from BASE -- Inherits from BASE
local self = BASE:Inherit( self, AI_A2G:New( AIPatrol ) ) -- #AI_A2G_PATROL local self = BASE:Inherit( self, AI_A2G_ENGAGE:New( AIPatrol, EngageMinSpeed, EngageMaxSpeed ) ) -- #AI_A2G_PATROL
self.Accomplished = false self.PatrolZone = PatrolZone
self.Engaging = false self.PatrolFloorAltitude = PatrolFloorAltitude
self.PatrolCeilingAltitude = PatrolCeilingAltitude
self.PatrolMinSpeed = PatrolMinSpeed
self.PatrolMaxSpeed = PatrolMaxSpeed
self.EngageMinSpeed = EngageMinSpeed -- defafult PatrolAltType to "RADIO" if not specified
self.EngageMaxSpeed = EngageMaxSpeed self.PatrolAltType = PatrolAltType or "RADIO"
self:AddTransition( { "Patrolling", "Engaging", "Returning", "Airborne" }, "Engage", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_A2G_PATROL. self:AddTransition( { "Started", "Airborne", "Refuelling" }, "Patrol", "Patrolling" )
--- OnBefore Transition Handler for Event Engage. --- OnBefore Transition Handler for Event Patrol.
-- @function [parent=#AI_A2G_PATROL] OnBeforeEngage -- @function [parent=#AI_A2G_PATROL] OnBeforePatrol
-- @param #AI_A2G_PATROL self -- @param #AI_A2G_PATROL self
-- @param Wrapper.Group#GROUP AIPatrol The Group Object managed by the FSM. -- @param Wrapper.Group#GROUP AIPatrol The Group Object managed by the FSM.
-- @param #string From The From State string. -- @param #string From The From State string.
@ -131,44 +134,25 @@ function AI_A2G_PATROL:New( AIPatrol, PatrolZone, PatrolFloorAltitude, PatrolCei
-- @param #string To The To State string. -- @param #string To The To State string.
-- @return #boolean Return false to cancel Transition. -- @return #boolean Return false to cancel Transition.
--- OnAfter Transition Handler for Event Engage. --- OnAfter Transition Handler for Event Patrol.
-- @function [parent=#AI_A2G_PATROL] OnAfterEngage -- @function [parent=#AI_A2G_PATROL] OnAfterPatrol
-- @param #AI_A2G_PATROL self -- @param #AI_A2G_PATROL self
-- @param Wrapper.Group#GROUP AIPatrol The Group Object managed by the FSM. -- @param Wrapper.Group#GROUP AIPatrol The Group Object managed by the FSM.
-- @param #string From The From State string. -- @param #string From The From State string.
-- @param #string Event The Event string. -- @param #string Event The Event string.
-- @param #string To The To State string. -- @param #string To The To State string.
--- Synchronous Event Trigger for Event Engage. --- Synchronous Event Trigger for Event Patrol.
-- @function [parent=#AI_A2G_PATROL] Engage -- @function [parent=#AI_A2G_PATROL] Patrol
-- @param #AI_A2G_PATROL self -- @param #AI_A2G_PATROL self
--- Asynchronous Event Trigger for Event Engage. --- Asynchronous Event Trigger for Event Patrol.
-- @function [parent=#AI_A2G_PATROL] __Engage -- @function [parent=#AI_A2G_PATROL] __Patrol
-- @param #AI_A2G_PATROL self -- @param #AI_A2G_PATROL self
-- @param #number Delay The delay in seconds. -- @param #number Delay The delay in seconds.
--- OnLeave Transition Handler for State Engaging.
-- @function [parent=#AI_A2G_PATROL] OnLeaveEngaging
-- @param #AI_A2G_PATROL self
-- @param Wrapper.Group#GROUP AIPatrol The Group Object managed by the FSM.
-- @param #string From The From State string.
-- @param #string Event The Event string.
-- @param #string To The To State string.
-- @return #boolean Return false to cancel Transition.
--- OnEnter Transition Handler for State Engaging.
-- @function [parent=#AI_A2G_PATROL] OnEnterEngaging
-- @param #AI_A2G_PATROL self
-- @param Wrapper.Group#GROUP AIPatrol The Group Object managed by the FSM.
-- @param #string From The From State string.
-- @param #string Event The Event string.
-- @param #string To The To State string.
self:AddTransition( "Engaging", "Fired", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_A2G_PATROL.
--- OnBefore Transition Handler for Event Fired. --- OnLeave Transition Handler for State Patrolling.
-- @function [parent=#AI_A2G_PATROL] OnBeforeFired -- @function [parent=#AI_A2G_PATROL] OnLeavePatrolling
-- @param #AI_A2G_PATROL self -- @param #AI_A2G_PATROL self
-- @param Wrapper.Group#GROUP AIPatrol The Group Object managed by the FSM. -- @param Wrapper.Group#GROUP AIPatrol The Group Object managed by the FSM.
-- @param #string From The From State string. -- @param #string From The From State string.
@ -176,27 +160,18 @@ function AI_A2G_PATROL:New( AIPatrol, PatrolZone, PatrolFloorAltitude, PatrolCei
-- @param #string To The To State string. -- @param #string To The To State string.
-- @return #boolean Return false to cancel Transition. -- @return #boolean Return false to cancel Transition.
--- OnAfter Transition Handler for Event Fired. --- OnEnter Transition Handler for State Patrolling.
-- @function [parent=#AI_A2G_PATROL] OnAfterFired -- @function [parent=#AI_A2G_PATROL] OnEnterPatrolling
-- @param #AI_A2G_PATROL self -- @param #AI_A2G_PATROL self
-- @param Wrapper.Group#GROUP AIPatrol The Group Object managed by the FSM. -- @param Wrapper.Group#GROUP AIPatrol The Group Object managed by the FSM.
-- @param #string From The From State string. -- @param #string From The From State string.
-- @param #string Event The Event string. -- @param #string Event The Event string.
-- @param #string To The To State string. -- @param #string To The To State string.
--- Synchronous Event Trigger for Event Fired.
-- @function [parent=#AI_A2G_PATROL] Fired
-- @param #AI_A2G_PATROL self
--- Asynchronous Event Trigger for Event Fired. self:AddTransition( "Patrolling", "Route", "Patrolling" ) -- FSM_CONTROLLABLE Transition for type #AI_A2G_PATROL.
-- @function [parent=#AI_A2G_PATROL] __Fired
-- @param #AI_A2G_PATROL self --- OnBefore Transition Handler for Event Route.
-- @param #number Delay The delay in seconds. -- @function [parent=#AI_A2G_PATROL] OnBeforeRoute
self:AddTransition( "*", "Destroy", "*" ) -- FSM_CONTROLLABLE Transition for type #AI_A2G_PATROL.
--- OnBefore Transition Handler for Event Destroy.
-- @function [parent=#AI_A2G_PATROL] OnBeforeDestroy
-- @param #AI_A2G_PATROL self -- @param #AI_A2G_PATROL self
-- @param Wrapper.Group#GROUP AIPatrol The Group Object managed by the FSM. -- @param Wrapper.Group#GROUP AIPatrol The Group Object managed by the FSM.
-- @param #string From The From State string. -- @param #string From The From State string.
@ -204,110 +179,30 @@ function AI_A2G_PATROL:New( AIPatrol, PatrolZone, PatrolFloorAltitude, PatrolCei
-- @param #string To The To State string. -- @param #string To The To State string.
-- @return #boolean Return false to cancel Transition. -- @return #boolean Return false to cancel Transition.
--- OnAfter Transition Handler for Event Destroy. --- OnAfter Transition Handler for Event Route.
-- @function [parent=#AI_A2G_PATROL] OnAfterDestroy -- @function [parent=#AI_A2G_PATROL] OnAfterRoute
-- @param #AI_A2G_PATROL self -- @param #AI_A2G_PATROL self
-- @param Wrapper.Group#GROUP AIPatrol The Group Object managed by the FSM. -- @param Wrapper.Group#GROUP AIPatrol The Group Object managed by the FSM.
-- @param #string From The From State string. -- @param #string From The From State string.
-- @param #string Event The Event string. -- @param #string Event The Event string.
-- @param #string To The To State string. -- @param #string To The To State string.
--- Synchronous Event Trigger for Event Destroy. --- Synchronous Event Trigger for Event Route.
-- @function [parent=#AI_A2G_PATROL] Destroy -- @function [parent=#AI_A2G_PATROL] Route
-- @param #AI_A2G_PATROL self -- @param #AI_A2G_PATROL self
--- Asynchronous Event Trigger for Event Destroy. --- Asynchronous Event Trigger for Event Route.
-- @function [parent=#AI_A2G_PATROL] __Destroy -- @function [parent=#AI_A2G_PATROL] __Route
-- @param #AI_A2G_PATROL self -- @param #AI_A2G_PATROL self
-- @param #number Delay The delay in seconds. -- @param #number Delay The delay in seconds.
self:AddTransition( "Engaging", "Abort", "Patrolling" ) -- FSM_CONTROLLABLE Transition for type #AI_A2G_PATROL. self:AddTransition( "*", "Reset", "Patrolling" ) -- FSM_CONTROLLABLE Transition for type #AI_A2G_PATROL.
--- OnBefore Transition Handler for Event Abort.
-- @function [parent=#AI_A2G_PATROL] OnBeforeAbort
-- @param #AI_A2G_PATROL self
-- @param Wrapper.Group#GROUP AIPatrol The Group Object managed by the FSM.
-- @param #string From The From State string.
-- @param #string Event The Event string.
-- @param #string To The To State string.
-- @return #boolean Return false to cancel Transition.
--- OnAfter Transition Handler for Event Abort.
-- @function [parent=#AI_A2G_PATROL] OnAfterAbort
-- @param #AI_A2G_PATROL self
-- @param Wrapper.Group#GROUP AIPatrol The Group Object managed by the FSM.
-- @param #string From The From State string.
-- @param #string Event The Event string.
-- @param #string To The To State string.
--- Synchronous Event Trigger for Event Abort.
-- @function [parent=#AI_A2G_PATROL] Abort
-- @param #AI_A2G_PATROL self
--- Asynchronous Event Trigger for Event Abort.
-- @function [parent=#AI_A2G_PATROL] __Abort
-- @param #AI_A2G_PATROL self
-- @param #number Delay The delay in seconds.
self:AddTransition( "Engaging", "Accomplish", "Patrolling" ) -- FSM_CONTROLLABLE Transition for type #AI_A2G_PATROL.
--- OnBefore Transition Handler for Event Accomplish.
-- @function [parent=#AI_A2G_PATROL] OnBeforeAccomplish
-- @param #AI_A2G_PATROL self
-- @param Wrapper.Group#GROUP AIPatrol The Group Object managed by the FSM.
-- @param #string From The From State string.
-- @param #string Event The Event string.
-- @param #string To The To State string.
-- @return #boolean Return false to cancel Transition.
--- OnAfter Transition Handler for Event Accomplish.
-- @function [parent=#AI_A2G_PATROL] OnAfterAccomplish
-- @param #AI_A2G_PATROL self
-- @param Wrapper.Group#GROUP AIPatrol The Group Object managed by the FSM.
-- @param #string From The From State string.
-- @param #string Event The Event string.
-- @param #string To The To State string.
--- Synchronous Event Trigger for Event Accomplish.
-- @function [parent=#AI_A2G_PATROL] Accomplish
-- @param #AI_A2G_PATROL self
--- Asynchronous Event Trigger for Event Accomplish.
-- @function [parent=#AI_A2G_PATROL] __Accomplish
-- @param #AI_A2G_PATROL self
-- @param #number Delay The delay in seconds.
return self return self
end end
--- onafter State Transition for Event Patrol.
-- @param #AI_A2G_PATROL self
-- @param Wrapper.Group#GROUP AIPatrol The AI Group managed by the FSM.
-- @param #string From The From State string.
-- @param #string Event The Event string.
-- @param #string To The To State string.
function AI_A2G_PATROL:onafterStart( AIPatrol, From, Event, To )
AIPatrol:HandleEvent( EVENTS.Takeoff, nil, self )
end
--- Set the Engage Zone which defines where the AI will engage bogies.
-- @param #AI_A2G_PATROL self
-- @param Core.Zone#ZONE EngageZone The zone where the AI is performing CAP.
-- @return #AI_A2G_PATROL self
function AI_A2G_PATROL:SetEngageZone( EngageZone )
self:F2()
if EngageZone then
self.EngageZone = EngageZone
else
self.EngageZone = nil
end
end
--- Set the Engage Range when the AI will engage with airborne enemies. --- Set the Engage Range when the AI will engage with airborne enemies.
-- @param #AI_A2G_PATROL self -- @param #AI_A2G_PATROL self
-- @param #number EngageRange The Engage Range. -- @param #number EngageRange The Engage Range.
@ -322,157 +217,93 @@ function AI_A2G_PATROL:SetEngageRange( EngageRange )
end end
end end
--- onafter State Transition for Event Patrol. --- Defines a new patrol route using the @{Process_PatrolZone} parameters and settings.
-- @param #AI_A2G_PATROL self -- @param #AI_A2G_PATROL self
-- @param Wrapper.Group#GROUP AIPatrol The AI Group managed by the FSM. -- @return #AI_A2G_PATROL self
-- @param Wrapper.Group#GROUP AIPatrol The Group Object managed by the FSM.
-- @param #string From The From State string. -- @param #string From The From State string.
-- @param #string Event The Event string. -- @param #string Event The Event string.
-- @param #string To The To State string. -- @param #string To The To State string.
function AI_A2G_PATROL:onafterPatrol( AIPatrol, From, Event, To ) function AI_A2G_PATROL:onafterPatrol( AIPatrol, From, Event, To )
self:F2()
-- Call the parent Start event handler self:ClearTargetDistance()
self:GetParent(self).onafterPatrol( self, AIPatrol, From, Event, To )
self:HandleEvent( EVENTS.Dead )
self:__Route( 1 )
AIPatrol:OnReSpawn(
function( PatrolGroup )
self:__Reset( 1 )
self:__Route( 5 )
end
)
end end
-- todo: need to fix this global function
--- @param Wrapper.Group#GROUP AIPatrol --- @param Wrapper.Group#GROUP AIPatrol
function AI_A2G_PATROL.AttackRoute( AIPatrol, Fsm ) -- This statis method is called from the route path within the last task at the last waaypoint of the AIPatrol.
-- Note that this method is required, as triggers the next route when patrolling for the AIPatrol.
function AI_A2G_PATROL.PatrolRoute( AIPatrol, Fsm )
AIPatrol:F( { "AI_A2G_PATROL.AttackRoute:", AIPatrol:GetName() } ) AIPatrol:F( { "AI_A2G_PATROL.PatrolRoute:", AIPatrol:GetName() } )
if AIPatrol:IsAlive() then if AIPatrol:IsAlive() then
Fsm:__Engage( 0.5 ) Fsm:Route()
end end
end end
--- @param #AI_A2G_PATROL self --- Defines a new patrol route using the @{Process_PatrolZone} parameters and settings.
-- @param Wrapper.Group#GROUP AIPatrol The Group Object managed by the FSM. -- @param #AI_A2G_PATROL self
-- @param Wrapper.Group#GROUP AIPatrol The Group managed by the FSM.
-- @param #string From The From State string. -- @param #string From The From State string.
-- @param #string Event The Event string. -- @param #string Event The Event string.
-- @param #string To The To State string. -- @param #string To The To State string.
function AI_A2G_PATROL:onbeforeEngage( AIPatrol, From, Event, To ) function AI_A2G_PATROL:onafterRoute( AIPatrol, From, Event, To )
if self.Accomplished == true then self:F2()
return false
-- When RTB, don't allow anymore the routing.
if From == "RTB" then
return
end end
end
--- @param #AI_A2G_PATROL self
-- @param Wrapper.Group#GROUP AIPatrol The AI Group managed by the FSM.
-- @param #string From The From State string.
-- @param #string Event The Event string.
-- @param #string To The To State string.
function AI_A2G_PATROL:onafterAbort( AIPatrol, From, Event, To )
AIPatrol:ClearTasks()
self:__Route( 0.5 )
end
--- @param #AI_A2G_PATROL self
-- @param Wrapper.Group#GROUP AIPatrol The AIPatrol Object managed by the FSM.
-- @param #string From The From State string.
-- @param #string Event The Event string.
-- @param #string To The To State string.
function AI_A2G_PATROL:onafterEngage( AIPatrol, From, Event, To, AttackSetUnit )
self:F( { AIPatrol, From, Event, To, AttackSetUnit} )
self.AttackSetUnit = AttackSetUnit or self.AttackSetUnit -- Core.Set#SET_UNIT
local FirstAttackUnit = self.AttackSetUnit:GetFirst() -- Wrapper.Unit#UNIT if AIPatrol:IsAlive() then
if FirstAttackUnit and FirstAttackUnit:IsAlive() then -- If there is no attacker anymore, stop the engagement. local PatrolRoute = {}
if AIPatrol:IsAlive() then
local EngageRoute = {} --- Calculate the target route point.
local CurrentCoord = AIPatrol:GetCoordinate()
local ToTargetCoord = self.PatrolZone:GetRandomPointVec2()
ToTargetCoord:SetAlt( math.random( self.PatrolFloorAltitude, self.PatrolCeilingAltitude ) )
self:SetTargetDistance( ToTargetCoord ) -- For RTB status check
local ToTargetSpeed = math.random( self.PatrolMinSpeed, self.PatrolMaxSpeed )
--- Create a route point of type air.
local ToPatrolRoutePoint = ToTargetCoord:WaypointAir(
self.PatrolAltType,
POINT_VEC3.RoutePointType.TurningPoint,
POINT_VEC3.RoutePointAction.TurningPoint,
ToTargetSpeed,
true
)
--- Calculate the target route point. PatrolRoute[#PatrolRoute+1] = ToPatrolRoutePoint
local CurrentCoord = AIPatrol:GetCoordinate() PatrolRoute[#PatrolRoute+1] = ToPatrolRoutePoint
local ToTargetCoord = self.AttackSetUnit:GetFirst():GetCoordinate()
local ToTargetSpeed = math.random( self.EngageMinSpeed, self.EngageMaxSpeed ) local Tasks = {}
local ToInterceptAngle = CurrentCoord:GetAngleDegrees( CurrentCoord:GetDirectionVec3( ToTargetCoord ) ) Tasks[#Tasks+1] = AIPatrol:TaskFunction( "AI_A2G_PATROL.PatrolRoute", self )
PatrolRoute[#PatrolRoute].task = AIPatrol:TaskCombo( Tasks )
--- Create a route point of type air.
local ToPatrolRoutePoint = CurrentCoord:Translate( 5000, ToInterceptAngle ):WaypointAir( AIPatrol:OptionROEReturnFire()
self.PatrolAltType, AIPatrol:OptionROTEvadeFire()
POINT_VEC3.RoutePointType.TurningPoint,
POINT_VEC3.RoutePointAction.TurningPoint,
ToTargetSpeed,
true
)
self:F( { Angle = ToInterceptAngle, ToTargetSpeed = ToTargetSpeed } )
self:T2( { self.MinSpeed, self.MaxSpeed, ToTargetSpeed } )
EngageRoute[#EngageRoute+1] = ToPatrolRoutePoint
EngageRoute[#EngageRoute+1] = ToPatrolRoutePoint
local AttackTasks = {} AIPatrol:Route( PatrolRoute, 0.5 )
for AttackUnitID, AttackUnit in pairs( self.AttackSetUnit:GetSet() ) do
local AttackUnit = AttackUnit -- Wrapper.Unit#UNIT
self:T( { "Attacking Unit:", AttackUnit:GetName(), AttackUnit:IsAlive(), AttackUnit:IsAir() } )
if AttackUnit:IsAlive() and AttackUnit:IsGround() then
AttackTasks[#AttackTasks+1] = AIPatrol:TaskAttackUnit( AttackUnit )
end
end
if #AttackTasks == 0 then
self:E("No targets found -> Going back to Patrolling")
self:__Abort( 0.5 )
else
AIPatrol:OptionROEOpenFire()
AIPatrol:OptionROTEvadeFire()
AttackTasks[#AttackTasks+1] = AIPatrol:TaskFunction( "AI_A2G_PATROL.AttackRoute", self )
EngageRoute[#EngageRoute].task = AIPatrol:TaskCombo( AttackTasks )
end
AIPatrol:Route( EngageRoute, 0.5 )
end
else
self:E("No targets found -> Going back to Patrolling")
self:__Abort( 0.5 )
end end
end
--- @param #AI_A2G_PATROL self
-- @param Wrapper.Group#GROUP AIPatrol The Group Object managed by the FSM.
-- @param #string From The From State string.
-- @param #string Event The Event string.
-- @param #string To The To State string.
function AI_A2G_PATROL:onafterAccomplish( AIPatrol, From, Event, To )
self.Accomplished = true
self:SetDetectionOff()
end
--- @param #AI_A2G_PATROL self
-- @param Wrapper.Group#GROUP AIPatrol The Group Object managed by the FSM.
-- @param #string From The From State string.
-- @param #string Event The Event string.
-- @param #string To The To State string.
-- @param Core.Event#EVENTDATA EventData
function AI_A2G_PATROL:onafterDestroy( AIPatrol, From, Event, To, EventData )
if EventData.IniUnit then
self.AttackUnits[EventData.IniUnit] = nil
end
end
--- @param #AI_A2G_PATROL self
-- @param Core.Event#EVENTDATA EventData
function AI_A2G_PATROL:OnEventDead( EventData )
self:F( { "EventDead", EventData } )
if EventData.IniDCSUnit then
if self.AttackUnits and self.AttackUnits[EventData.IniUnit] then
self:__Destroy( 1, EventData )
end
end
end end
--- @param Wrapper.Group#GROUP AIPatrol --- @param Wrapper.Group#GROUP AIPatrol

View File

@ -81,11 +81,19 @@ AI_A2G_SEAD = {
--- Creates a new AI_A2G_SEAD object --- Creates a new AI_A2G_SEAD object
-- @param #AI_A2G_SEAD self -- @param #AI_A2G_SEAD self
-- @param Wrapper.Group#GROUP AIGroup -- @param Wrapper.Group#GROUP AIGroup
-- @param DCS#Speed EngageMinSpeed The minimum speed of the @{Wrapper.Group} in km/h when engaging a target.
-- @param DCS#Speed EngageMaxSpeed The maximum speed of the @{Wrapper.Group} in km/h when engaging a target.
-- @param Core.Zone#ZONE_BASE PatrolZone The @{Zone} where the patrol needs to be executed.
-- @param DCS#Altitude PatrolFloorAltitude The lowest altitude in meters where to execute the patrol.
-- @param DCS#Altitude PatrolCeilingAltitude The highest altitude in meters where to execute the patrol.
-- @param DCS#Speed PatrolMinSpeed The minimum speed of the @{Wrapper.Group} in km/h.
-- @param DCS#Speed PatrolMaxSpeed The maximum speed of the @{Wrapper.Group} in km/h.
-- @param DCS#AltitudeType PatrolAltType The altitude type ("RADIO"=="AGL", "BARO"=="ASL"). Defaults to RADIO
-- @return #AI_A2G_SEAD -- @return #AI_A2G_SEAD
function AI_A2G_SEAD:New( AIGroup, EngageMinSpeed, EngageMaxSpeed ) function AI_A2G_SEAD:New( AIGroup, EngageMinSpeed, EngageMaxSpeed, PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed, PatrolAltType )
-- Inherits from BASE -- Inherits from BASE
local self = BASE:Inherit( self, AI_A2G_ENGAGE:New( AIGroup, EngageMinSpeed, EngageMaxSpeed ) ) -- #AI_A2G_SEAD local self = BASE:Inherit( self, AI_A2G_PATROL:New( AIGroup, EngageMinSpeed, EngageMaxSpeed, PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed, PatrolAltType ) ) -- #AI_A2G_SEAD
return self return self
end end

View File

@ -511,7 +511,7 @@ function AI_AIR:onafterStatus()
end end
if not self:Is("Home") then if not self:Is("Home") then
self:__Status( 10 ) self:__Status( 30 )
end end
end end