This commit is contained in:
FlightControl 2017-06-12 06:44:01 +02:00
parent 4f91ba6081
commit f56b2229a7
7 changed files with 326 additions and 49249 deletions

View File

@ -428,7 +428,7 @@ function AI_A2A.RTBRoute( AIGroup )
AIGroup:E( { "RTBRoute:", AIGroup:GetName() } ) AIGroup:E( { "RTBRoute:", AIGroup:GetName() } )
local _AI_A2A = AIGroup:GetState( AIGroup, "AI_A2A" ) -- #AI_A2A local _AI_A2A = AIGroup:GetState( AIGroup, "AI_A2A" ) -- #AI_A2A
_AI_A2A:__RTB( 1 ) _AI_A2A:RTB()
end end
--- @param #AI_A2A self --- @param #AI_A2A self

View File

@ -351,7 +351,7 @@ end
function AI_A2A_CAP.AttackRoute( AIGroup ) function AI_A2A_CAP.AttackRoute( AIGroup )
local EngageZone = AIGroup:GetState( AIGroup, "EngageZone" ) -- AI.AI_Cap#AI_A2A_CAP local EngageZone = AIGroup:GetState( AIGroup, "EngageZone" ) -- AI.AI_Cap#AI_A2A_CAP
EngageZone:__Engage( 1 ) EngageZone:Engage()
end end
--- @param #AI_A2A_CAP self --- @param #AI_A2A_CAP self
@ -373,7 +373,7 @@ end
-- @param #string To The To State string. -- @param #string To The To State string.
function AI_A2A_CAP:onafterAbort( AIGroup, From, Event, To ) function AI_A2A_CAP:onafterAbort( AIGroup, From, Event, To )
AIGroup:ClearTasks() AIGroup:ClearTasks()
self:__Route( 1 ) self:Route()
end end
@ -435,8 +435,8 @@ function AI_A2A_CAP:onafterEngage( AIGroup, From, Event, To, AttackSetUnit )
if #AttackTasks == 0 then if #AttackTasks == 0 then
self:E("No targets found -> Going back to Patrolling") self:E("No targets found -> Going back to Patrolling")
self:__Abort( 1 ) self:Abort()
self:__Route( 1 ) self:Route()
else else
AttackTasks[#AttackTasks+1] = AIGroup:TaskFunction( 1, #AttackTasks, "AI_A2A_CAP.AttackRoute" ) AttackTasks[#AttackTasks+1] = AIGroup:TaskFunction( 1, #AttackTasks, "AI_A2A_CAP.AttackRoute" )
EngageRoute[1].task = AIGroup:TaskCombo( AttackTasks ) EngageRoute[1].task = AIGroup:TaskCombo( AttackTasks )
@ -450,8 +450,8 @@ function AI_A2A_CAP:onafterEngage( AIGroup, From, Event, To, AttackSetUnit )
end end
else else
self:E("No targets found -> Going back to Patrolling") self:E("No targets found -> Going back to Patrolling")
self:__Abort( 1 ) self:Abort()
self:__Route( 1 ) self:Route()
end end
end end

View File

@ -248,29 +248,29 @@ do -- AI_A2A_DISPATCHER
-- @param #AI_A2A_DISPATCHER self -- @param #AI_A2A_DISPATCHER self
-- @param #number Delay -- @param #number Delay
self:AddTransition( "*", "INTERCEPT", "*" ) self:AddTransition( "*", "GCI", "*" )
--- INTERCEPT Handler OnBefore for AI_A2A_DISPATCHER --- GCI Handler OnBefore for AI_A2A_DISPATCHER
-- @function [parent=#AI_A2A_DISPATCHER] OnBeforeINTERCEPT -- @function [parent=#AI_A2A_DISPATCHER] OnBeforeGCI
-- @param #AI_A2A_DISPATCHER self -- @param #AI_A2A_DISPATCHER self
-- @param #string From -- @param #string From
-- @param #string Event -- @param #string Event
-- @param #string To -- @param #string To
-- @return #boolean -- @return #boolean
--- INTERCEPT Handler OnAfter for AI_A2A_DISPATCHER --- GCI Handler OnAfter for AI_A2A_DISPATCHER
-- @function [parent=#AI_A2A_DISPATCHER] OnAfterINTERCEPT -- @function [parent=#AI_A2A_DISPATCHER] OnAfterGCI
-- @param #AI_A2A_DISPATCHER self -- @param #AI_A2A_DISPATCHER self
-- @param #string From -- @param #string From
-- @param #string Event -- @param #string Event
-- @param #string To -- @param #string To
--- INTERCEPT Trigger for AI_A2A_DISPATCHER --- GCI Trigger for AI_A2A_DISPATCHER
-- @function [parent=#AI_A2A_DISPATCHER] INTERCEPT -- @function [parent=#AI_A2A_DISPATCHER] GCI
-- @param #AI_A2A_DISPATCHER self -- @param #AI_A2A_DISPATCHER self
--- INTERCEPT Asynchronous Trigger for AI_A2A_DISPATCHER --- GCI Asynchronous Trigger for AI_A2A_DISPATCHER
-- @function [parent=#AI_A2A_DISPATCHER] __INTERCEPT -- @function [parent=#AI_A2A_DISPATCHER] __GCI
-- @param #AI_A2A_DISPATCHER self -- @param #AI_A2A_DISPATCHER self
-- @param #number Delay -- @param #number Delay
@ -652,6 +652,7 @@ do -- AI_A2A_DISPATCHER
--- ---
-- @param #AI_A2A_DISPATCHER self -- @param #AI_A2A_DISPATCHER self
-- @param #string SquadronName The squadron name. -- @param #string SquadronName The squadron name.
-- @return #table DefenderSquadron
function AI_A2A_DISPATCHER:CanCAP( SquadronName ) function AI_A2A_DISPATCHER:CanCAP( SquadronName )
self:F({SquadronName = SquadronName}) self:F({SquadronName = SquadronName})
@ -660,21 +661,45 @@ do -- AI_A2A_DISPATCHER
local DefenderSquadron = self:GetSquadron( SquadronName ) local DefenderSquadron = self:GetSquadron( SquadronName )
local Cap = DefenderSquadron.Cap if DefenderSquadron.Resources > 0 then
if Cap then
local CapCount = self:CountCapAirborne( SquadronName ) local Cap = DefenderSquadron.Cap
if CapCount < Cap.CapLimit then if Cap then
local Probability = math.random() local CapCount = self:CountCapAirborne( SquadronName )
if Probability <= Cap.Probability then if CapCount < Cap.CapLimit then
return true local Probability = math.random()
if Probability <= Cap.Probability then
return DefenderSquadron
end
end end
end end
return false
else
error( "This squadron does not exist:" .. SquadronName )
end end
return nil
end end
---
-- @param #AI_A2A_DISPATCHER self
-- @param #string SquadronName The squadron name.
-- @return #table DefenderSquadron
function AI_A2A_DISPATCHER:CanGCI( SquadronName )
self:F({SquadronName = SquadronName})
self.DefenderSquadrons[SquadronName] = self.DefenderSquadrons[SquadronName] or {}
self.DefenderSquadrons[SquadronName].Cap = self.DefenderSquadrons[SquadronName].Cap or {}
local DefenderSquadron = self:GetSquadron( SquadronName )
if DefenderSquadron.Resources > 0 then
local Gci = DefenderSquadron.Gci
if Gci then
return DefenderSquadron
end
end
return nil
end
--- ---
-- @param #AI_A2A_DISPATCHER self -- @param #AI_A2A_DISPATCHER self
-- @param #string SquadronName The squadron name. -- @param #string SquadronName The squadron name.
@ -684,9 +709,9 @@ do -- AI_A2A_DISPATCHER
function AI_A2A_DISPATCHER:SetSquadronGci( SquadronName, EngageMinSpeed, EngageMaxSpeed ) function AI_A2A_DISPATCHER:SetSquadronGci( SquadronName, EngageMinSpeed, EngageMaxSpeed )
self.DefenderSquadrons[SquadronName] = self.DefenderSquadrons[SquadronName] or {} self.DefenderSquadrons[SquadronName] = self.DefenderSquadrons[SquadronName] or {}
self.DefenderSquadrons[SquadronName].Intercept = self.DefenderSquadrons[SquadronName].Intercept or {} self.DefenderSquadrons[SquadronName].Gci = self.DefenderSquadrons[SquadronName].Gci or {}
local Intercept = self.DefenderSquadrons[SquadronName].Intercept local Intercept = self.DefenderSquadrons[SquadronName].Gci
Intercept.Name = SquadronName Intercept.Name = SquadronName
Intercept.EngageMinSpeed = EngageMinSpeed Intercept.EngageMinSpeed = EngageMinSpeed
Intercept.EngageMaxSpeed = EngageMaxSpeed Intercept.EngageMaxSpeed = EngageMaxSpeed
@ -1120,8 +1145,8 @@ do -- AI_A2A_DISPATCHER
-- Now we need to check if the AIGroup has a Task. -- Now we need to check if the AIGroup has a Task.
local DefenderTask = self:GetDefenderTask( Friendly ) local DefenderTask = self:GetDefenderTask( Friendly )
if DefenderTask then if DefenderTask then
-- The Task should be CAP or INTERCEPT -- The Task should be CAP or GCI
if DefenderTask.Type == "CAP" or DefenderTask.Type == "INTERCEPT" then if DefenderTask.Type == "CAP" or DefenderTask.Type == "GCI" then
-- If there is no target, then add the AIGroup to the ResultAIGroups for Engagement to the TargetSet -- If there is no target, then add the AIGroup to the ResultAIGroups for Engagement to the TargetSet
if DefenderTask.Target == nil then if DefenderTask.Target == nil then
if DefenderTask.Fsm:Is( "Returning" ) if DefenderTask.Fsm:Is( "Returning" )
@ -1153,12 +1178,14 @@ do -- AI_A2A_DISPATCHER
self.DefenderSquadrons[SquadronName] = self.DefenderSquadrons[SquadronName] or {} self.DefenderSquadrons[SquadronName] = self.DefenderSquadrons[SquadronName] or {}
self.DefenderSquadrons[SquadronName].Cap = self.DefenderSquadrons[SquadronName].Cap or {} self.DefenderSquadrons[SquadronName].Cap = self.DefenderSquadrons[SquadronName].Cap or {}
local DefenderSquadron = self:GetSquadron( SquadronName ) local DefenderSquadron = self:CanCAP( SquadronName )
local Cap = DefenderSquadron.Cap
if Cap then if DefenderSquadron then
local Cap = DefenderSquadron.Cap
if Cap 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 )
@ -1177,8 +1204,6 @@ do -- AI_A2A_DISPATCHER
self:SetDefenderTask( DefenderCAP, "CAP", Fsm ) self:SetDefenderTask( DefenderCAP, "CAP", Fsm )
end end
end end
else
error( "This squadron does not exist:" .. SquadronName )
end end
end end
@ -1210,7 +1235,7 @@ do -- AI_A2A_DISPATCHER
--- ---
-- @param #AI_A2A_DISPATCHER self -- @param #AI_A2A_DISPATCHER self
function AI_A2A_DISPATCHER:onafterINTERCEPT( From, Event, To, Target, DefendersMissing, AIGroups ) function AI_A2A_DISPATCHER:onafterGCI( From, Event, To, Target, DefendersMissing, AIGroups )
local ClosestDistance = 0 local ClosestDistance = 0
local ClosestDefenderSquadronName = nil local ClosestDefenderSquadronName = nil
@ -1232,7 +1257,7 @@ do -- AI_A2A_DISPATCHER
while( DefendersCount > 0 ) do while( DefendersCount > 0 ) do
for SquadronName, DefenderSquadron in pairs( self.DefenderSquadrons or {} ) do for SquadronName, DefenderSquadron in pairs( self.DefenderSquadrons or {} ) do
for InterceptID, Intercept in pairs( DefenderSquadron.Intercept or {} ) do for InterceptID, Intercept in pairs( DefenderSquadron.Gci or {} ) do
local SpawnCoord = DefenderSquadron.Airbase:GetCoordinate() -- Core.Point#COORDINATE local SpawnCoord = DefenderSquadron.Airbase:GetCoordinate() -- Core.Point#COORDINATE
local TargetCoord = Target.Set:GetFirst():GetCoordinate() local TargetCoord = Target.Set:GetFirst():GetCoordinate()
@ -1247,49 +1272,57 @@ do -- AI_A2A_DISPATCHER
if ClosestDefenderSquadronName then if ClosestDefenderSquadronName then
local DefenderSquadron = self:GetSquadron( ClosestDefenderSquadronName ) local DefenderSquadron = self:CanGCI( ClosestDefenderSquadronName )
local DefenderOverhead = DefenderSquadron.Overhead
local DefenderGrouping = DefenderSquadron.Grouping
local DefendersNeeded = math.ceil( DefendersCount * DefenderOverhead )
local Intercept = self.DefenderSquadrons[ClosestDefenderSquadronName].Intercept
local Spawn = DefenderSquadron.Spawn[ math.random( 1, #DefenderSquadron.Spawn ) ] if DefenderSquadron then
if DefenderGrouping then
Spawn:InitGrouping( ( DefenderGrouping < DefendersNeeded ) and DefenderGrouping or DefendersNeeded )
else
Spawn:InitGrouping()
end
local TakeoffMethod = self:GetSquadronTakeoff( ClosestDefenderSquadronName ) local Gci = self.DefenderSquadrons[ClosestDefenderSquadronName].Gci
local DefenderGCI = Spawn:SpawnAtAirbase( DefenderSquadron.Airbase, TakeoffMethod )
self:F( { GCIDefender = DefenderGCI:GetName() } )
self:AddDefenderToSquadron( DefenderSquadron, DefenderGCI ) if Gci then
local DefenderOverhead = DefenderSquadron.Overhead
local DefenderGrouping = DefenderSquadron.Grouping
local DefendersNeeded = math.ceil( DefendersCount * DefenderOverhead )
local Spawn = DefenderSquadron.Spawn[ math.random( 1, #DefenderSquadron.Spawn ) ]
if DefenderGrouping then
Spawn:InitGrouping( ( DefenderGrouping < DefendersNeeded ) and DefenderGrouping or DefendersNeeded )
else
Spawn:InitGrouping()
end
local TakeoffMethod = self:GetSquadronTakeoff( ClosestDefenderSquadronName )
local DefenderGCI = Spawn:SpawnAtAirbase( DefenderSquadron.Airbase, TakeoffMethod )
self:F( { GCIDefender = DefenderGCI:GetName() } )
self:AddDefenderToSquadron( DefenderSquadron, DefenderGCI )
if DefenderGCI then if DefenderGCI then
DefendersCount = DefendersCount - DefenderGCI:GetSize() DefendersCount = DefendersCount - DefenderGCI:GetSize()
local Fsm = AI_A2A_INTERCEPT:New( DefenderGCI, Intercept.EngageMinSpeed, Intercept.EngageMaxSpeed ) local Fsm = AI_A2A_GCI:New( DefenderGCI, Gci.EngageMinSpeed, Gci.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( DefenderGCI, "INTERCEPT", Fsm, Target ) self:SetDefenderTask( DefenderGCI, "GCI", Fsm, Target )
function Fsm:onafterRTB( AIGroup, From, Event, To ) function Fsm:onafterRTB( AIGroup, From, Event, To )
self:F({"INTERCEPT RTB"}) self:F({"GCI RTB"})
self:GetParent(self).onafterRTB( self, AIGroup, From, Event, To ) self:GetParent(self).onafterRTB( self, AIGroup, From, Event, To )
local Dispatcher = self:GetDispatcher() -- #AI_A2A_DISPATCHER local Dispatcher = self:GetDispatcher() -- #AI_A2A_DISPATCHER
local AIGroup = self:GetControllable() local AIGroup = self:GetControllable()
Dispatcher:ClearDefenderTaskTarget( AIGroup ) Dispatcher:ClearDefenderTaskTarget( AIGroup )
end
end
end end
end end
end end
end end
@ -1324,12 +1357,12 @@ do -- AI_A2A_DISPATCHER
return nil, nil return nil, nil
end end
--- Creates an INTERCEPT task when there are targets for it. --- Creates an GCI task when there are targets for it.
-- @param #AI_A2A_DISPATCHER self -- @param #AI_A2A_DISPATCHER self
-- @param Functional.Detection#DETECTION_BASE.DetectedItem DetectedItem -- @param Functional.Detection#DETECTION_BASE.DetectedItem DetectedItem
-- @return Set#SET_UNIT TargetSetUnit: The target set of units. -- @return Set#SET_UNIT TargetSetUnit: The target set of units.
-- @return #nil If there are no targets to be set. -- @return #nil If there are no targets to be set.
function AI_A2A_DISPATCHER:EvaluateINTERCEPT( Target ) function AI_A2A_DISPATCHER:EvaluateGCI( Target )
self:F( { Target.ItemID } ) self:F( { Target.ItemID } )
local AttackerSet = Target.Set local AttackerSet = Target.Set
@ -1404,7 +1437,7 @@ do -- AI_A2A_DISPATCHER
local DetectedItemChanged = DetectedItem.Changed local DetectedItemChanged = DetectedItem.Changed
do do
local Friendlies = self:EvaluateENGAGE( DetectedItem ) -- Returns a SetUnit if there are targets to be INTERCEPTed... local Friendlies = self:EvaluateENGAGE( DetectedItem ) -- Returns a SetUnit if there are targets to be GCIed...
if Friendlies then if Friendlies then
self:F( { AIGroups = Friendlies } ) self:F( { AIGroups = Friendlies } )
self:ENGAGE( DetectedItem, Friendlies ) self:ENGAGE( DetectedItem, Friendlies )
@ -1412,10 +1445,10 @@ do -- AI_A2A_DISPATCHER
end end
do do
local DefendersMissing, Friendlies = self:EvaluateINTERCEPT( DetectedItem ) local DefendersMissing, Friendlies = self:EvaluateGCI( DetectedItem )
if DefendersMissing then if DefendersMissing then
self:F( { DefendersMissing = DefendersMissing } ) self:F( { DefendersMissing = DefendersMissing } )
self:INTERCEPT( DetectedItem, DefendersMissing, Friendlies ) self:GCI( DetectedItem, DefendersMissing, Friendlies )
end end
end end
@ -1423,7 +1456,7 @@ do -- AI_A2A_DISPATCHER
Report:Add( string.format( "\n - Target %s ( %s ): %s" , DetectedItem.ItemID, DetectedItem.Index, DetectedItem.Set:GetObjectNames() ) ) Report:Add( string.format( "\n - Target %s ( %s ): %s" , DetectedItem.ItemID, DetectedItem.Index, 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.ItemID == DetectedItem.ItemID then if DefenderTask.Target and DefenderTask.Target.Index == DetectedItem.Index then
Report:Add( string.format( " - %s ( %s - %s )", Defender:GetName(), DefenderTask.Type, DefenderTask.Fsm:GetState() ) ) Report:Add( string.format( " - %s ( %s - %s )", Defender:GetName(), DefenderTask.Type, DefenderTask.Fsm:GetState() ) )
end end
end end
@ -1547,6 +1580,4 @@ do
self:CAP( SquadronName ) self:CAP( SquadronName )
end end
end end

View File

@ -1,14 +1,14 @@
--- **AI** -- **Execute Interception of Intruders (CAP).** --- **AI** -- **Execute Ground Controlled Interception (GCI).**
-- --
-- ![Banner Image](..\Presentations\AI_CAP\Dia1.JPG) -- ![Banner Image](..\Presentations\AI_GCI\Dia1.JPG)
-- --
-- === -- ===
-- --
-- AI A2A_INTEREPT class makes AI Groups execute an Intercept. -- AI A2A_INTEREPT class makes AI Groups execute an Intercept.
-- --
-- There are the following types of CAP classes defined: -- There are the following types of GCI classes defined:
-- --
-- * @{#AI_A2A_INTERCEPT}: Perform a CAP in a zone. -- * @{#AI_A2A_GCI}: Perform a GCI in a zone.
-- --
-- ==== -- ====
-- --
@ -18,111 +18,111 @@
-- --
-- ==== -- ====
-- --
-- @module AI_A2A_Intercept -- @module AI_A2A_GCI
--BASE:TraceClass("AI_A2A_INTERCEPT") --BASE:TraceClass("AI_A2A_GCI")
--- @type AI_A2A_INTERCEPT --- @type AI_A2A_GCI
-- @extends AI.AI_A2A#AI_A2A -- @extends AI.AI_A2A#AI_A2A
--- # AI_A2A_INTERCEPT class, extends @{AI_A2A#AI_A2A} --- # AI_A2A_GCI class, extends @{AI_A2A#AI_A2A}
-- --
-- The AI_A2A_INTERCEPT class implements the core functions to intercept intruders. The Engage function will intercept intruders. -- The AI_A2A_GCI class implements the core functions to intercept intruders. The Engage function will intercept intruders.
-- --
-- ![Process](..\Presentations\AI_CAP\Dia3.JPG) -- ![Process](..\Presentations\AI_GCI\Dia3.JPG)
-- --
-- The AI_A2A_INTERCEPT is assigned a @{Group} and this must be done before the AI_A2A_INTERCEPT process can be started using the **Start** event. -- The AI_A2A_GCI is assigned a @{Group} and this must be done before the AI_A2A_GCI process can be started using the **Start** event.
-- --
-- ![Process](..\Presentations\AI_CAP\Dia4.JPG) -- ![Process](..\Presentations\AI_GCI\Dia4.JPG)
-- --
-- The AI will fly towards the random 3D point within the patrol zone, using a random speed within the given altitude and speed limits. -- The AI will fly towards the random 3D point within the patrol zone, using a random speed within the given altitude and speed limits.
-- Upon arrival at the 3D point, a new random 3D point will be selected within the patrol zone using the given limits. -- Upon arrival at the 3D point, a new random 3D point will be selected within the patrol zone using the given limits.
-- --
-- ![Process](..\Presentations\AI_CAP\Dia5.JPG) -- ![Process](..\Presentations\AI_GCI\Dia5.JPG)
-- --
-- This cycle will continue. -- This cycle will continue.
-- --
-- ![Process](..\Presentations\AI_CAP\Dia6.JPG) -- ![Process](..\Presentations\AI_GCI\Dia6.JPG)
-- --
-- During the patrol, the AI will detect enemy targets, which are reported through the **Detected** event. -- During the patrol, the AI will detect enemy targets, which are reported through the **Detected** event.
-- --
-- ![Process](..\Presentations\AI_CAP\Dia9.JPG) -- ![Process](..\Presentations\AI_GCI\Dia9.JPG)
-- --
-- When enemies are detected, the AI will automatically engage the enemy. -- When enemies are detected, the AI will automatically engage the enemy.
-- --
-- ![Process](..\Presentations\AI_CAP\Dia10.JPG) -- ![Process](..\Presentations\AI_GCI\Dia10.JPG)
-- --
-- Until a fuel or damage treshold has been reached by the AI, or when the AI is commanded to RTB. -- Until a fuel or damage treshold has been reached by the AI, or when the AI is commanded to RTB.
-- When the fuel treshold has been reached, the airplane will fly towards the nearest friendly airbase and will land. -- When the fuel treshold has been reached, the airplane will fly towards the nearest friendly airbase and will land.
-- --
-- ![Process](..\Presentations\AI_CAP\Dia13.JPG) -- ![Process](..\Presentations\AI_GCI\Dia13.JPG)
-- --
-- ## 1. AI_A2A_INTERCEPT constructor -- ## 1. AI_A2A_GCI constructor
-- --
-- * @{#AI_A2A_INTERCEPT.New}(): Creates a new AI_A2A_INTERCEPT object. -- * @{#AI_A2A_GCI.New}(): Creates a new AI_A2A_GCI object.
-- --
-- ## 2. AI_A2A_INTERCEPT is a FSM -- ## 2. AI_A2A_GCI is a FSM
-- --
-- ![Process](..\Presentations\AI_CAP\Dia2.JPG) -- ![Process](..\Presentations\AI_GCI\Dia2.JPG)
-- --
-- ### 2.1 AI_A2A_INTERCEPT States -- ### 2.1 AI_A2A_GCI States
-- --
-- * **None** ( Group ): The process is not started yet. -- * **None** ( Group ): The process is not started yet.
-- * **Patrolling** ( Group ): The AI is patrolling the Patrol Zone. -- * **Patrolling** ( Group ): The AI is patrolling the Patrol Zone.
-- * **Engaging** ( Group ): The AI is engaging the bogeys. -- * **Engaging** ( Group ): The AI is engaging the bogeys.
-- * **Returning** ( Group ): The AI is returning to Base.. -- * **Returning** ( Group ): The AI is returning to Base..
-- --
-- ### 2.2 AI_A2A_INTERCEPT Events -- ### 2.2 AI_A2A_GCI Events
-- --
-- * **@{AI_Patrol#AI_PATROL_ZONE.Start}**: Start the process. -- * **@{AI_Patrol#AI_PATROL_ZONE.Start}**: Start the process.
-- * **@{AI_Patrol#AI_PATROL_ZONE.Route}**: Route the AI to a new random 3D point within the Patrol Zone. -- * **@{AI_Patrol#AI_PATROL_ZONE.Route}**: Route the AI to a new random 3D point within the Patrol Zone.
-- * **@{#AI_A2A_INTERCEPT.Engage}**: Let the AI engage the bogeys. -- * **@{#AI_A2A_GCI.Engage}**: Let the AI engage the bogeys.
-- * **@{#AI_A2A_INTERCEPT.Abort}**: Aborts the engagement and return patrolling in the patrol zone. -- * **@{#AI_A2A_GCI.Abort}**: Aborts the engagement and return patrolling in the patrol zone.
-- * **@{AI_Patrol#AI_PATROL_ZONE.RTB}**: Route the AI to the home base. -- * **@{AI_Patrol#AI_PATROL_ZONE.RTB}**: Route the AI to the home base.
-- * **@{AI_Patrol#AI_PATROL_ZONE.Detect}**: The AI is detecting targets. -- * **@{AI_Patrol#AI_PATROL_ZONE.Detect}**: The AI is detecting targets.
-- * **@{AI_Patrol#AI_PATROL_ZONE.Detected}**: The AI has detected new targets. -- * **@{AI_Patrol#AI_PATROL_ZONE.Detected}**: The AI has detected new targets.
-- * **@{#AI_A2A_INTERCEPT.Destroy}**: The AI has destroyed a bogey @{Unit}. -- * **@{#AI_A2A_GCI.Destroy}**: The AI has destroyed a bogey @{Unit}.
-- * **@{#AI_A2A_INTERCEPT.Destroyed}**: The AI has destroyed all bogeys @{Unit}s assigned in the CAS task. -- * **@{#AI_A2A_GCI.Destroyed}**: The AI has destroyed all bogeys @{Unit}s assigned in the CAS task.
-- * **Status** ( Group ): The AI is checking status (fuel and damage). When the tresholds have been reached, the AI will RTB. -- * **Status** ( Group ): The AI is checking status (fuel and damage). When the tresholds have been reached, the AI will RTB.
-- --
-- ## 3. Set the Range of Engagement -- ## 3. Set the Range of Engagement
-- --
-- ![Range](..\Presentations\AI_CAP\Dia11.JPG) -- ![Range](..\Presentations\AI_GCI\Dia11.JPG)
-- --
-- An optional range can be set in meters, -- An optional range can be set in meters,
-- that will define when the AI will engage with the detected airborne enemy targets. -- that will define when the AI will engage with the detected airborne enemy targets.
-- The range can be beyond or smaller than the range of the Patrol Zone. -- The range can be beyond or smaller than the range of the Patrol Zone.
-- The range is applied at the position of the AI. -- The range is applied at the position of the AI.
-- Use the method @{AI_CAP#AI_A2A_INTERCEPT.SetEngageRange}() to define that range. -- Use the method @{AI_GCI#AI_A2A_GCI.SetEngageRange}() to define that range.
-- --
-- ## 4. Set the Zone of Engagement -- ## 4. Set the Zone of Engagement
-- --
-- ![Zone](..\Presentations\AI_CAP\Dia12.JPG) -- ![Zone](..\Presentations\AI_GCI\Dia12.JPG)
-- --
-- An optional @{Zone} can be set, -- An optional @{Zone} can be set,
-- that will define when the AI will engage with the detected airborne enemy targets. -- that will define when the AI will engage with the detected airborne enemy targets.
-- Use the method @{AI_Cap#AI_A2A_INTERCEPT.SetEngageZone}() to define that Zone. -- Use the method @{AI_Cap#AI_A2A_GCI.SetEngageZone}() to define that Zone.
-- --
-- === -- ===
-- --
-- @field #AI_A2A_INTERCEPT -- @field #AI_A2A_GCI
AI_A2A_INTERCEPT = { AI_A2A_GCI = {
ClassName = "AI_A2A_INTERCEPT", ClassName = "AI_A2A_GCI",
} }
--- Creates a new AI_A2A_INTERCEPT object --- Creates a new AI_A2A_GCI object
-- @param #AI_A2A_INTERCEPT self -- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup -- @param Wrapper.Group#GROUP AIGroup
-- @return #AI_A2A_INTERCEPT -- @return #AI_A2A_GCI
function AI_A2A_INTERCEPT:New( AIGroup, EngageMinSpeed, EngageMaxSpeed ) function AI_A2A_GCI:New( AIGroup, EngageMinSpeed, EngageMaxSpeed )
-- Inherits from BASE -- Inherits from BASE
local self = BASE:Inherit( self, AI_A2A:New( AIGroup ) ) -- #AI_A2A_INTERCEPT local self = BASE:Inherit( self, AI_A2A:New( AIGroup ) ) -- #AI_A2A_GCI
self.Accomplished = false self.Accomplished = false
self.Engaging = false self.Engaging = false
@ -134,11 +134,11 @@ function AI_A2A_INTERCEPT:New( AIGroup, EngageMinSpeed, EngageMaxSpeed )
self.PatrolAltType = "RADIO" self.PatrolAltType = "RADIO"
self:AddTransition( { "Started", "Engaging", "Returning" }, "Engage", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_A2A_INTERCEPT. self:AddTransition( { "Started", "Engaging", "Returning" }, "Engage", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_A2A_GCI.
--- OnBefore Transition Handler for Event Engage. --- OnBefore Transition Handler for Event Engage.
-- @function [parent=#AI_A2A_INTERCEPT] OnBeforeEngage -- @function [parent=#AI_A2A_GCI] OnBeforeEngage
-- @param #AI_A2A_INTERCEPT self -- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup Object managed by the FSM. -- @param Wrapper.Group#GROUP AIGroup The AIGroup 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.
@ -146,25 +146,25 @@ function AI_A2A_INTERCEPT:New( AIGroup, EngageMinSpeed, EngageMaxSpeed )
-- @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 Engage.
-- @function [parent=#AI_A2A_INTERCEPT] OnAfterEngage -- @function [parent=#AI_A2A_GCI] OnAfterEngage
-- @param #AI_A2A_INTERCEPT self -- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup Object managed by the FSM. -- @param Wrapper.Group#GROUP AIGroup The AIGroup 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 Engage.
-- @function [parent=#AI_A2A_INTERCEPT] Engage -- @function [parent=#AI_A2A_GCI] Engage
-- @param #AI_A2A_INTERCEPT self -- @param #AI_A2A_GCI self
--- Asynchronous Event Trigger for Event Engage. --- Asynchronous Event Trigger for Event Engage.
-- @function [parent=#AI_A2A_INTERCEPT] __Engage -- @function [parent=#AI_A2A_GCI] __Engage
-- @param #AI_A2A_INTERCEPT self -- @param #AI_A2A_GCI self
-- @param #number Delay The delay in seconds. -- @param #number Delay The delay in seconds.
--- OnLeave Transition Handler for State Engaging. --- OnLeave Transition Handler for State Engaging.
-- @function [parent=#AI_A2A_INTERCEPT] OnLeaveEngaging -- @function [parent=#AI_A2A_GCI] OnLeaveEngaging
-- @param #AI_A2A_INTERCEPT self -- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup Object managed by the FSM. -- @param Wrapper.Group#GROUP AIGroup The AIGroup 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.
@ -172,18 +172,18 @@ function AI_A2A_INTERCEPT:New( AIGroup, EngageMinSpeed, EngageMaxSpeed )
-- @return #boolean Return false to cancel Transition. -- @return #boolean Return false to cancel Transition.
--- OnEnter Transition Handler for State Engaging. --- OnEnter Transition Handler for State Engaging.
-- @function [parent=#AI_A2A_INTERCEPT] OnEnterEngaging -- @function [parent=#AI_A2A_GCI] OnEnterEngaging
-- @param #AI_A2A_INTERCEPT self -- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup Object managed by the FSM. -- @param Wrapper.Group#GROUP AIGroup The AIGroup 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.
self:AddTransition( "Engaging", "Fired", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_A2A_INTERCEPT. self:AddTransition( "Engaging", "Fired", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_A2A_GCI.
--- OnBefore Transition Handler for Event Fired. --- OnBefore Transition Handler for Event Fired.
-- @function [parent=#AI_A2A_INTERCEPT] OnBeforeFired -- @function [parent=#AI_A2A_GCI] OnBeforeFired
-- @param #AI_A2A_INTERCEPT self -- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup Object managed by the FSM. -- @param Wrapper.Group#GROUP AIGroup The AIGroup 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.
@ -191,27 +191,27 @@ function AI_A2A_INTERCEPT:New( AIGroup, EngageMinSpeed, EngageMaxSpeed )
-- @return #boolean Return false to cancel Transition. -- @return #boolean Return false to cancel Transition.
--- OnAfter Transition Handler for Event Fired. --- OnAfter Transition Handler for Event Fired.
-- @function [parent=#AI_A2A_INTERCEPT] OnAfterFired -- @function [parent=#AI_A2A_GCI] OnAfterFired
-- @param #AI_A2A_INTERCEPT self -- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup Object managed by the FSM. -- @param Wrapper.Group#GROUP AIGroup The AIGroup 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. --- Synchronous Event Trigger for Event Fired.
-- @function [parent=#AI_A2A_INTERCEPT] Fired -- @function [parent=#AI_A2A_GCI] Fired
-- @param #AI_A2A_INTERCEPT self -- @param #AI_A2A_GCI self
--- Asynchronous Event Trigger for Event Fired. --- Asynchronous Event Trigger for Event Fired.
-- @function [parent=#AI_A2A_INTERCEPT] __Fired -- @function [parent=#AI_A2A_GCI] __Fired
-- @param #AI_A2A_INTERCEPT self -- @param #AI_A2A_GCI self
-- @param #number Delay The delay in seconds. -- @param #number Delay The delay in seconds.
self:AddTransition( "*", "Destroy", "*" ) -- FSM_CONTROLLABLE Transition for type #AI_A2A_INTERCEPT. self:AddTransition( "*", "Destroy", "*" ) -- FSM_CONTROLLABLE Transition for type #AI_A2A_GCI.
--- OnBefore Transition Handler for Event Destroy. --- OnBefore Transition Handler for Event Destroy.
-- @function [parent=#AI_A2A_INTERCEPT] OnBeforeDestroy -- @function [parent=#AI_A2A_GCI] OnBeforeDestroy
-- @param #AI_A2A_INTERCEPT self -- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup Object managed by the FSM. -- @param Wrapper.Group#GROUP AIGroup The AIGroup 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.
@ -219,28 +219,28 @@ function AI_A2A_INTERCEPT:New( AIGroup, EngageMinSpeed, EngageMaxSpeed )
-- @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 Destroy.
-- @function [parent=#AI_A2A_INTERCEPT] OnAfterDestroy -- @function [parent=#AI_A2A_GCI] OnAfterDestroy
-- @param #AI_A2A_INTERCEPT self -- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup Object managed by the FSM. -- @param Wrapper.Group#GROUP AIGroup The AIGroup 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 Destroy.
-- @function [parent=#AI_A2A_INTERCEPT] Destroy -- @function [parent=#AI_A2A_GCI] Destroy
-- @param #AI_A2A_INTERCEPT self -- @param #AI_A2A_GCI self
--- Asynchronous Event Trigger for Event Destroy. --- Asynchronous Event Trigger for Event Destroy.
-- @function [parent=#AI_A2A_INTERCEPT] __Destroy -- @function [parent=#AI_A2A_GCI] __Destroy
-- @param #AI_A2A_INTERCEPT self -- @param #AI_A2A_GCI 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_A2A_INTERCEPT. self:AddTransition( "Engaging", "Abort", "Patrolling" ) -- FSM_CONTROLLABLE Transition for type #AI_A2A_GCI.
--- OnBefore Transition Handler for Event Abort. --- OnBefore Transition Handler for Event Abort.
-- @function [parent=#AI_A2A_INTERCEPT] OnBeforeAbort -- @function [parent=#AI_A2A_GCI] OnBeforeAbort
-- @param #AI_A2A_INTERCEPT self -- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup Object managed by the FSM. -- @param Wrapper.Group#GROUP AIGroup The AIGroup 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.
@ -248,27 +248,27 @@ function AI_A2A_INTERCEPT:New( AIGroup, EngageMinSpeed, EngageMaxSpeed )
-- @return #boolean Return false to cancel Transition. -- @return #boolean Return false to cancel Transition.
--- OnAfter Transition Handler for Event Abort. --- OnAfter Transition Handler for Event Abort.
-- @function [parent=#AI_A2A_INTERCEPT] OnAfterAbort -- @function [parent=#AI_A2A_GCI] OnAfterAbort
-- @param #AI_A2A_INTERCEPT self -- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup Object managed by the FSM. -- @param Wrapper.Group#GROUP AIGroup The AIGroup 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 Abort. --- Synchronous Event Trigger for Event Abort.
-- @function [parent=#AI_A2A_INTERCEPT] Abort -- @function [parent=#AI_A2A_GCI] Abort
-- @param #AI_A2A_INTERCEPT self -- @param #AI_A2A_GCI self
--- Asynchronous Event Trigger for Event Abort. --- Asynchronous Event Trigger for Event Abort.
-- @function [parent=#AI_A2A_INTERCEPT] __Abort -- @function [parent=#AI_A2A_GCI] __Abort
-- @param #AI_A2A_INTERCEPT self -- @param #AI_A2A_GCI self
-- @param #number Delay The delay in seconds. -- @param #number Delay The delay in seconds.
self:AddTransition( "Engaging", "Accomplish", "Patrolling" ) -- FSM_CONTROLLABLE Transition for type #AI_A2A_INTERCEPT. self:AddTransition( "Engaging", "Accomplish", "Patrolling" ) -- FSM_CONTROLLABLE Transition for type #AI_A2A_GCI.
--- OnBefore Transition Handler for Event Accomplish. --- OnBefore Transition Handler for Event Accomplish.
-- @function [parent=#AI_A2A_INTERCEPT] OnBeforeAccomplish -- @function [parent=#AI_A2A_GCI] OnBeforeAccomplish
-- @param #AI_A2A_INTERCEPT self -- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup Object managed by the FSM. -- @param Wrapper.Group#GROUP AIGroup The AIGroup 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.
@ -276,20 +276,20 @@ function AI_A2A_INTERCEPT:New( AIGroup, EngageMinSpeed, EngageMaxSpeed )
-- @return #boolean Return false to cancel Transition. -- @return #boolean Return false to cancel Transition.
--- OnAfter Transition Handler for Event Accomplish. --- OnAfter Transition Handler for Event Accomplish.
-- @function [parent=#AI_A2A_INTERCEPT] OnAfterAccomplish -- @function [parent=#AI_A2A_GCI] OnAfterAccomplish
-- @param #AI_A2A_INTERCEPT self -- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup Object managed by the FSM. -- @param Wrapper.Group#GROUP AIGroup The AIGroup 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 Accomplish. --- Synchronous Event Trigger for Event Accomplish.
-- @function [parent=#AI_A2A_INTERCEPT] Accomplish -- @function [parent=#AI_A2A_GCI] Accomplish
-- @param #AI_A2A_INTERCEPT self -- @param #AI_A2A_GCI self
--- Asynchronous Event Trigger for Event Accomplish. --- Asynchronous Event Trigger for Event Accomplish.
-- @function [parent=#AI_A2A_INTERCEPT] __Accomplish -- @function [parent=#AI_A2A_GCI] __Accomplish
-- @param #AI_A2A_INTERCEPT self -- @param #AI_A2A_GCI self
-- @param #number Delay The delay in seconds. -- @param #number Delay The delay in seconds.
return self return self
@ -297,12 +297,12 @@ end
--- onafter State Transition for Event Patrol. --- onafter State Transition for Event Patrol.
-- @param #AI_A2A_INTERCEPT self -- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AI Group managed by the FSM. -- @param Wrapper.Group#GROUP AIGroup The AI 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_A2A_INTERCEPT:onafterEngage( AIGroup, From, Event, To ) function AI_A2A_GCI:onafterEngage( AIGroup, From, Event, To )
self:HandleEvent( EVENTS.Dead ) self:HandleEvent( EVENTS.Dead )
@ -311,43 +311,43 @@ end
-- todo: need to fix this global function -- todo: need to fix this global function
--- @param Wrapper.Group#GROUP AIControllable --- @param Wrapper.Group#GROUP AIControllable
function AI_A2A_INTERCEPT.InterceptRoute( AIControllable ) function AI_A2A_GCI.InterceptRoute( AIControllable )
AIControllable:T( "NewEngageRoute" ) AIControllable:T( "NewEngageRoute" )
local EngageZone = AIControllable:GetState( AIControllable, "EngageZone" ) -- AI.AI_Cap#AI_A2A_INTERCEPT local EngageZone = AIControllable:GetState( AIControllable, "EngageZone" ) -- AI.AI_Cap#AI_A2A_GCI
EngageZone:__Engage( 1 ) EngageZone:Engage()
end end
--- @param #AI_A2A_INTERCEPT self --- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup Object managed by the FSM. -- @param Wrapper.Group#GROUP AIGroup The AIGroup 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_A2A_INTERCEPT:onbeforeEngage( AIGroup, From, Event, To ) function AI_A2A_GCI:onbeforeEngage( AIGroup, From, Event, To )
if self.Accomplished == true then if self.Accomplished == true then
return false return false
end end
end end
--- @param #AI_A2A_INTERCEPT self --- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AI Group managed by the FSM. -- @param Wrapper.Group#GROUP AIGroup The AI 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_A2A_INTERCEPT:onafterAbort( AIGroup, From, Event, To ) function AI_A2A_GCI:onafterAbort( AIGroup, From, Event, To )
AIGroup:ClearTasks() AIGroup:ClearTasks()
self:Return() self:Return()
self:__RTB( 1 ) self:RTB()
end end
--- @param #AI_A2A_INTERCEPT self --- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup Object managed by the FSM. -- @param Wrapper.Group#GROUP AIGroup The AIGroup 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_A2A_INTERCEPT:onafterEngage( AIGroup, From, Event, To, AttackSetUnit ) function AI_A2A_GCI:onafterEngage( AIGroup, From, Event, To, AttackSetUnit )
self:F( { AIGroup, From, Event, To, AttackSetUnit} ) self:F( { AIGroup, From, Event, To, AttackSetUnit} )
@ -407,7 +407,7 @@ function AI_A2A_INTERCEPT:onafterEngage( AIGroup, From, Event, To, AttackSetUnit
self:Return() self:Return()
self:RTB() self:RTB()
else else
AttackTasks[#AttackTasks+1] = AIGroup:TaskFunction( 1, #AttackTasks, "AI_A2A_INTERCEPT.InterceptRoute" ) AttackTasks[#AttackTasks+1] = AIGroup:TaskFunction( 1, #AttackTasks, "AI_A2A_GCI.InterceptRoute" )
EngageRoute[1].task = AIGroup:TaskCombo( AttackTasks ) EngageRoute[1].task = AIGroup:TaskCombo( AttackTasks )
--- Do a trick, link the NewEngageRoute function of the object to the AIControllable in a temporary variable ... --- Do a trick, link the NewEngageRoute function of the object to the AIControllable in a temporary variable ...
@ -425,32 +425,32 @@ function AI_A2A_INTERCEPT:onafterEngage( AIGroup, From, Event, To, AttackSetUnit
end end
end end
--- @param #AI_A2A_INTERCEPT self --- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup Object managed by the FSM. -- @param Wrapper.Group#GROUP AIGroup The AIGroup 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_A2A_INTERCEPT:onafterAccomplish( AIGroup, From, Event, To ) function AI_A2A_GCI:onafterAccomplish( AIGroup, From, Event, To )
self.Accomplished = true self.Accomplished = true
self:SetDetectionOff() self:SetDetectionOff()
end end
--- @param #AI_A2A_INTERCEPT self --- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup Object managed by the FSM. -- @param Wrapper.Group#GROUP AIGroup The AIGroup 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.
-- @param Core.Event#EVENTDATA EventData -- @param Core.Event#EVENTDATA EventData
function AI_A2A_INTERCEPT:onafterDestroy( AIGroup, From, Event, To, EventData ) function AI_A2A_GCI:onafterDestroy( AIGroup, From, Event, To, EventData )
if EventData.IniUnit then if EventData.IniUnit then
self.AttackUnits[EventData.IniUnit] = nil self.AttackUnits[EventData.IniUnit] = nil
end end
end end
--- @param #AI_A2A_INTERCEPT self --- @param #AI_A2A_GCI self
-- @param Core.Event#EVENTDATA EventData -- @param Core.Event#EVENTDATA EventData
function AI_A2A_INTERCEPT:OnEventDead( EventData ) function AI_A2A_GCI:OnEventDead( EventData )
self:F( { "EventDead", EventData } ) self:F( { "EventDead", EventData } )
if EventData.IniDCSUnit then if EventData.IniDCSUnit then

View File

@ -312,23 +312,23 @@ end
--- @param Wrapper.Controllable#CONTROLLABLE AIControllable --- @param Wrapper.Group#GROUP AIGroup
-- This statis method is called from the route path within the last task at the last waaypoint of the Controllable. -- This statis method is called from the route path within the last task at the last waaypoint of the Controllable.
-- Note that this method is required, as triggers the next route when patrolling for the Controllable. -- Note that this method is required, as triggers the next route when patrolling for the Controllable.
function AI_A2A_PATROL:_NewPatrolRoute( AIControllable ) function AI_A2A_PATROL:PatrolRoute( AIGroup )
local PatrolZone = AIControllable:GetState( AIControllable, "PatrolZone" ) -- PatrolCore.Zone#AI_A2A_PATROL local _AI_A2A_Patrol = AIGroup:GetState( AIGroup, "AI_A2A_PATROL" ) -- #AI_A2A_PATROL
PatrolZone:__Route( 1 ) _AI_A2A_Patrol:Route()
end end
--- Defines a new patrol route using the @{Process_PatrolZone} parameters and settings. --- Defines a new patrol route using the @{Process_PatrolZone} parameters and settings.
-- @param #AI_A2A_PATROL self -- @param #AI_A2A_PATROL self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param Wrapper.Group#GROUP AIGroup The AIGroup 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_A2A_PATROL:onafterRoute( Controllable, From, Event, To ) function AI_A2A_PATROL:onafterRoute( AIGroup, From, Event, To )
self:F2() self:F2()
@ -338,69 +338,21 @@ function AI_A2A_PATROL:onafterRoute( Controllable, From, Event, To )
end end
if self.Controllable:IsAlive() then if AIGroup:IsAlive() then
-- Determine if the AIControllable is within the PatrolZone.
-- If not, make a waypoint within the to that the AIControllable will fly at maximum speed to that point.
local PatrolRoute = {} local PatrolRoute = {}
-- Calculate the current route point of the controllable as the start point of the route. --- Calculate the target route point.
-- However, when the controllable is not in the air,
-- the controllable current waypoint is probably the airbase...
-- Thus, if we would take the current waypoint as the startpoint, upon take-off, the controllable flies
-- immediately back to the airbase, and this is not correct.
-- Therefore, when on a runway, get as the current route point a random point within the PatrolZone.
-- This will make the plane fly immediately to the patrol zone.
if self.Controllable:InAir() == false then local CurrentCoord = AIGroup:GetCoordinate()
self:E( "Not in the air, finding route path within PatrolZone" )
local CurrentVec2 = self.Controllable:GetVec2()
--TODO: Create GetAltitude function for GROUP, and delete GetUnit(1).
local CurrentAltitude = self.Controllable:GetUnit(1):GetAltitude()
local CurrentPointVec3 = POINT_VEC3:New( CurrentVec2.x, CurrentAltitude, CurrentVec2.y )
local ToPatrolZoneSpeed = self.PatrolMaxSpeed
local CurrentRoutePoint = CurrentPointVec3:RoutePointAir(
self.PatrolAltType,
POINT_VEC3.RoutePointType.TakeOffParking,
POINT_VEC3.RoutePointAction.FromParkingArea,
ToPatrolZoneSpeed,
true
)
PatrolRoute[#PatrolRoute+1] = CurrentRoutePoint
else
self:E( "In the air, finding route path within PatrolZone" )
local CurrentVec2 = self.Controllable:GetVec2()
--TODO: Create GetAltitude function for GROUP, and delete GetUnit(1).
local CurrentAltitude = self.Controllable:GetUnit(1):GetAltitude()
local CurrentPointVec3 = POINT_VEC3:New( CurrentVec2.x, CurrentAltitude, CurrentVec2.y )
local ToPatrolZoneSpeed = self.PatrolMaxSpeed
local CurrentRoutePoint = CurrentPointVec3:RoutePointAir(
self.PatrolAltType,
POINT_VEC3.RoutePointType.TurningPoint,
POINT_VEC3.RoutePointAction.TurningPoint,
ToPatrolZoneSpeed,
true
)
PatrolRoute[#PatrolRoute+1] = CurrentRoutePoint
end
local ToTargetCoord = self.PatrolZone:GetRandomPointVec2()
self:SetTargetDistance( ToTargetCoord ) -- For RTB status check
--- Define a random point in the @{Zone}. The AI will fly to that point within the zone.
--- Find a random 2D point in PatrolZone.
local ToTargetVec2 = self.PatrolZone:GetRandomVec2()
self:T2( ToTargetVec2 )
--- Define Speed and Altitude.
local ToTargetAltitude = math.random( self.PatrolFloorAltitude, self.PatrolCeilingAltitude )
local ToTargetSpeed = math.random( self.PatrolMinSpeed, self.PatrolMaxSpeed ) local ToTargetSpeed = math.random( self.PatrolMinSpeed, self.PatrolMaxSpeed )
self:T2( { self.PatrolMinSpeed, self.PatrolMaxSpeed, ToTargetSpeed } )
--- Obtain a 3D @{Point} from the 2D point + altitude.
local ToTargetPointVec3 = POINT_VEC3:New( ToTargetVec2.x, ToTargetAltitude, ToTargetVec2.y )
--- Create a route point of type air. --- Create a route point of type air.
local ToTargetRoutePoint = ToTargetPointVec3:RoutePointAir( local ToPatrolRoutePoint = ToTargetCoord:RoutePointAir(
self.PatrolAltType, self.PatrolAltType,
POINT_VEC3.RoutePointType.TurningPoint, POINT_VEC3.RoutePointType.TurningPoint,
POINT_VEC3.RoutePointAction.TurningPoint, POINT_VEC3.RoutePointAction.TurningPoint,
@ -408,21 +360,21 @@ function AI_A2A_PATROL:onafterRoute( Controllable, From, Event, To )
true true
) )
--self.CoordTest:SpawnFromVec3( ToTargetPointVec3:GetVec3() ) PatrolRoute[#PatrolRoute+1] = ToPatrolRoutePoint
--ToTargetPointVec3:SmokeRed()
PatrolRoute[#PatrolRoute+1] = ToTargetRoutePoint
--- Now we're going to do something special, we're going to call a function from a waypoint action at the AIControllable... --- Now we're going to do something special, we're going to call a function from a waypoint action at the AIControllable...
self.Controllable:WayPointInitialize( PatrolRoute ) AIGroup:WayPointInitialize( PatrolRoute )
local Tasks = {}
Tasks[#Tasks+1] = AIGroup:TaskFunction( 1, 1, "AI_A2A_PATROL.PatrolRoute" )
PatrolRoute[1].task = AIGroup:TaskCombo( Tasks )
--- Do a trick, link the NewPatrolRoute function of the PATROLGROUP object to the AIControllable in a temporary variable ... --- Do a trick, link the NewPatrolRoute function of the PATROLGROUP object to the AIControllable in a temporary variable ...
self.Controllable:SetState( self.Controllable, "PatrolZone", self ) AIGroup:SetState( AIGroup, "AI_A2A_PATROL", self )
self.Controllable:WayPointFunction( #PatrolRoute, 1, "AI_A2A_PATROL:_NewPatrolRoute" )
--- NOW ROUTE THE GROUP! --- NOW ROUTE THE GROUP!
self.Controllable:WayPointExecute( 1, 2 ) AIGroup:WayPointExecute( 1, 2 )
end end
end end

View File

@ -44,7 +44,7 @@ AI/AI_Balancer.lua
AI/AI_A2A.lua AI/AI_A2A.lua
AI/AI_A2A_Patrol.lua AI/AI_A2A_Patrol.lua
AI/AI_A2A_Cap.lua AI/AI_A2A_Cap.lua
AI/AI_A2A_Intercept.lua AI/AI_A2A_Gci.lua
AI/AI_A2A_Dispatcher.lua AI/AI_A2A_Dispatcher.lua
AI/AI_Patrol.lua AI/AI_Patrol.lua
AI/AI_Cap.lua AI/AI_Cap.lua

File diff suppressed because it is too large Load Diff