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() } )
local _AI_A2A = AIGroup:GetState( AIGroup, "AI_A2A" ) -- #AI_A2A
_AI_A2A:__RTB( 1 )
_AI_A2A:RTB()
end
--- @param #AI_A2A self

View File

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

View File

@ -248,29 +248,29 @@ do -- AI_A2A_DISPATCHER
-- @param #AI_A2A_DISPATCHER self
-- @param #number Delay
self:AddTransition( "*", "INTERCEPT", "*" )
self:AddTransition( "*", "GCI", "*" )
--- INTERCEPT Handler OnBefore for AI_A2A_DISPATCHER
-- @function [parent=#AI_A2A_DISPATCHER] OnBeforeINTERCEPT
--- GCI Handler OnBefore for AI_A2A_DISPATCHER
-- @function [parent=#AI_A2A_DISPATCHER] OnBeforeGCI
-- @param #AI_A2A_DISPATCHER self
-- @param #string From
-- @param #string Event
-- @param #string To
-- @return #boolean
--- INTERCEPT Handler OnAfter for AI_A2A_DISPATCHER
-- @function [parent=#AI_A2A_DISPATCHER] OnAfterINTERCEPT
--- GCI Handler OnAfter for AI_A2A_DISPATCHER
-- @function [parent=#AI_A2A_DISPATCHER] OnAfterGCI
-- @param #AI_A2A_DISPATCHER self
-- @param #string From
-- @param #string Event
-- @param #string To
--- INTERCEPT Trigger for AI_A2A_DISPATCHER
-- @function [parent=#AI_A2A_DISPATCHER] INTERCEPT
--- GCI Trigger for AI_A2A_DISPATCHER
-- @function [parent=#AI_A2A_DISPATCHER] GCI
-- @param #AI_A2A_DISPATCHER self
--- INTERCEPT Asynchronous Trigger for AI_A2A_DISPATCHER
-- @function [parent=#AI_A2A_DISPATCHER] __INTERCEPT
--- GCI Asynchronous Trigger for AI_A2A_DISPATCHER
-- @function [parent=#AI_A2A_DISPATCHER] __GCI
-- @param #AI_A2A_DISPATCHER self
-- @param #number Delay
@ -652,6 +652,7 @@ do -- AI_A2A_DISPATCHER
---
-- @param #AI_A2A_DISPATCHER self
-- @param #string SquadronName The squadron name.
-- @return #table DefenderSquadron
function AI_A2A_DISPATCHER:CanCAP( SquadronName )
self:F({SquadronName = SquadronName})
@ -660,20 +661,44 @@ do -- AI_A2A_DISPATCHER
local DefenderSquadron = self:GetSquadron( SquadronName )
local Cap = DefenderSquadron.Cap
if Cap then
local CapCount = self:CountCapAirborne( SquadronName )
if CapCount < Cap.CapLimit then
local Probability = math.random()
if Probability <= Cap.Probability then
return true
if DefenderSquadron.Resources > 0 then
local Cap = DefenderSquadron.Cap
if Cap then
local CapCount = self:CountCapAirborne( SquadronName )
if CapCount < Cap.CapLimit then
local Probability = math.random()
if Probability <= Cap.Probability then
return DefenderSquadron
end
end
end
return false
else
error( "This squadron does not exist:" .. SquadronName )
end
return nil
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
@ -684,9 +709,9 @@ do -- AI_A2A_DISPATCHER
function AI_A2A_DISPATCHER:SetSquadronGci( SquadronName, EngageMinSpeed, EngageMaxSpeed )
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.EngageMinSpeed = EngageMinSpeed
Intercept.EngageMaxSpeed = EngageMaxSpeed
@ -1120,8 +1145,8 @@ do -- AI_A2A_DISPATCHER
-- Now we need to check if the AIGroup has a Task.
local DefenderTask = self:GetDefenderTask( Friendly )
if DefenderTask then
-- The Task should be CAP or INTERCEPT
if DefenderTask.Type == "CAP" or DefenderTask.Type == "INTERCEPT" then
-- The Task should be CAP or GCI
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 DefenderTask.Target == nil then
if DefenderTask.Fsm:Is( "Returning" )
@ -1153,12 +1178,14 @@ do -- AI_A2A_DISPATCHER
self.DefenderSquadrons[SquadronName] = self.DefenderSquadrons[SquadronName] or {}
self.DefenderSquadrons[SquadronName].Cap = self.DefenderSquadrons[SquadronName].Cap or {}
local DefenderSquadron = self:GetSquadron( SquadronName )
local Cap = DefenderSquadron.Cap
local DefenderSquadron = self:CanCAP( SquadronName )
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 ) ]
Spawn:InitGrouping( DefenderSquadron.Grouping )
@ -1177,8 +1204,6 @@ do -- AI_A2A_DISPATCHER
self:SetDefenderTask( DefenderCAP, "CAP", Fsm )
end
end
else
error( "This squadron does not exist:" .. SquadronName )
end
end
@ -1210,7 +1235,7 @@ do -- AI_A2A_DISPATCHER
---
-- @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 ClosestDefenderSquadronName = nil
@ -1232,7 +1257,7 @@ do -- AI_A2A_DISPATCHER
while( DefendersCount > 0 ) 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 TargetCoord = Target.Set:GetFirst():GetCoordinate()
@ -1247,49 +1272,57 @@ do -- AI_A2A_DISPATCHER
if ClosestDefenderSquadronName then
local DefenderSquadron = self:GetSquadron( 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 DefenderGrouping then
Spawn:InitGrouping( ( DefenderGrouping < DefendersNeeded ) and DefenderGrouping or DefendersNeeded )
else
Spawn:InitGrouping()
end
local DefenderSquadron = self:CanGCI( ClosestDefenderSquadronName )
local TakeoffMethod = self:GetSquadronTakeoff( ClosestDefenderSquadronName )
local DefenderGCI = Spawn:SpawnAtAirbase( DefenderSquadron.Airbase, TakeoffMethod )
self:F( { GCIDefender = DefenderGCI:GetName() } )
if DefenderSquadron then
self:AddDefenderToSquadron( DefenderSquadron, DefenderGCI )
local Gci = self.DefenderSquadrons[ClosestDefenderSquadronName].Gci
if Gci then
if DefenderGCI then
DefendersCount = DefendersCount - DefenderGCI:GetSize()
local DefenderOverhead = DefenderSquadron.Overhead
local DefenderGrouping = DefenderSquadron.Grouping
local DefendersNeeded = math.ceil( DefendersCount * DefenderOverhead )
local Fsm = AI_A2A_INTERCEPT:New( DefenderGCI, Intercept.EngageMinSpeed, Intercept.EngageMaxSpeed )
Fsm:SetDispatcher( self )
Fsm:SetHomeAirbase( DefenderSquadron.Airbase )
Fsm:Start()
Fsm:__Engage( 1, Target.Set ) -- Engage on the TargetSetUnit
self:SetDefenderTask( DefenderGCI, "INTERCEPT", Fsm, Target )
function Fsm:onafterRTB( AIGroup, From, Event, To )
self:F({"INTERCEPT RTB"})
self:GetParent(self).onafterRTB( self, AIGroup, From, Event, To )
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 Dispatcher = self:GetDispatcher() -- #AI_A2A_DISPATCHER
local AIGroup = self:GetControllable()
Dispatcher:ClearDefenderTaskTarget( AIGroup )
local TakeoffMethod = self:GetSquadronTakeoff( ClosestDefenderSquadronName )
local DefenderGCI = Spawn:SpawnAtAirbase( DefenderSquadron.Airbase, TakeoffMethod )
self:F( { GCIDefender = DefenderGCI:GetName() } )
self:AddDefenderToSquadron( DefenderSquadron, DefenderGCI )
if DefenderGCI then
DefendersCount = DefendersCount - DefenderGCI:GetSize()
local Fsm = AI_A2A_GCI:New( DefenderGCI, Gci.EngageMinSpeed, Gci.EngageMaxSpeed )
Fsm:SetDispatcher( self )
Fsm:SetHomeAirbase( DefenderSquadron.Airbase )
Fsm:Start()
Fsm:__Engage( 1, Target.Set ) -- Engage on the TargetSetUnit
self:SetDefenderTask( DefenderGCI, "GCI", Fsm, Target )
function Fsm:onafterRTB( AIGroup, From, Event, To )
self:F({"GCI RTB"})
self:GetParent(self).onafterRTB( self, AIGroup, From, Event, To )
local Dispatcher = self:GetDispatcher() -- #AI_A2A_DISPATCHER
local AIGroup = self:GetControllable()
Dispatcher:ClearDefenderTaskTarget( AIGroup )
end
end
end
end
end
end
@ -1324,12 +1357,12 @@ do -- AI_A2A_DISPATCHER
return nil, nil
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 Functional.Detection#DETECTION_BASE.DetectedItem DetectedItem
-- @return Set#SET_UNIT TargetSetUnit: The target set of units.
-- @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 } )
local AttackerSet = Target.Set
@ -1404,7 +1437,7 @@ do -- AI_A2A_DISPATCHER
local DetectedItemChanged = DetectedItem.Changed
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
self:F( { AIGroups = Friendlies } )
self:ENGAGE( DetectedItem, Friendlies )
@ -1412,10 +1445,10 @@ do -- AI_A2A_DISPATCHER
end
do
local DefendersMissing, Friendlies = self:EvaluateINTERCEPT( DetectedItem )
local DefendersMissing, Friendlies = self:EvaluateGCI( DetectedItem )
if DefendersMissing then
self:F( { DefendersMissing = DefendersMissing } )
self:INTERCEPT( DetectedItem, DefendersMissing, Friendlies )
self:GCI( DetectedItem, DefendersMissing, Friendlies )
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() ) )
for Defender, DefenderTask in pairs( self:GetDefenderTasks() ) do
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() ) )
end
end
@ -1546,7 +1579,5 @@ do
function AI_A2A_DISPATCHER:SchedulerCAP( SquadronName )
self:CAP( SquadronName )
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.
--
-- 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
--- # 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.
-- 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.
--
-- ![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.
--
-- ![Process](..\Presentations\AI_CAP\Dia9.JPG)
-- ![Process](..\Presentations\AI_GCI\Dia9.JPG)
--
-- 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.
-- 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.
-- * **Patrolling** ( Group ): The AI is patrolling the Patrol Zone.
-- * **Engaging** ( Group ): The AI is engaging the bogeys.
-- * **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.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_INTERCEPT.Abort}**: Aborts the engagement and return patrolling in the patrol zone.
-- * **@{#AI_A2A_GCI.Engage}**: Let the AI engage the bogeys.
-- * **@{#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.Detect}**: The AI is detecting 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_INTERCEPT.Destroyed}**: The AI has destroyed all bogeys @{Unit}s assigned in the CAS task.
-- * **@{#AI_A2A_GCI.Destroy}**: The AI has destroyed a bogey @{Unit}.
-- * **@{#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.
--
-- ## 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,
-- 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 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
--
-- ![Zone](..\Presentations\AI_CAP\Dia12.JPG)
-- ![Zone](..\Presentations\AI_GCI\Dia12.JPG)
--
-- An optional @{Zone} can be set,
-- 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
AI_A2A_INTERCEPT = {
ClassName = "AI_A2A_INTERCEPT",
-- @field #AI_A2A_GCI
AI_A2A_GCI = {
ClassName = "AI_A2A_GCI",
}
--- Creates a new AI_A2A_INTERCEPT object
-- @param #AI_A2A_INTERCEPT self
--- Creates a new AI_A2A_GCI object
-- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup
-- @return #AI_A2A_INTERCEPT
function AI_A2A_INTERCEPT:New( AIGroup, EngageMinSpeed, EngageMaxSpeed )
-- @return #AI_A2A_GCI
function AI_A2A_GCI:New( AIGroup, EngageMinSpeed, EngageMaxSpeed )
-- 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.Engaging = false
@ -134,11 +134,11 @@ function AI_A2A_INTERCEPT:New( AIGroup, EngageMinSpeed, EngageMaxSpeed )
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.
-- @function [parent=#AI_A2A_INTERCEPT] OnBeforeEngage
-- @param #AI_A2A_INTERCEPT self
-- @function [parent=#AI_A2A_GCI] OnBeforeEngage
-- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup Object managed by the FSM.
-- @param #string From The From State 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.
--- OnAfter Transition Handler for Event Engage.
-- @function [parent=#AI_A2A_INTERCEPT] OnAfterEngage
-- @param #AI_A2A_INTERCEPT self
-- @function [parent=#AI_A2A_GCI] OnAfterEngage
-- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup 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 Engage.
-- @function [parent=#AI_A2A_INTERCEPT] Engage
-- @param #AI_A2A_INTERCEPT self
-- @function [parent=#AI_A2A_GCI] Engage
-- @param #AI_A2A_GCI self
--- Asynchronous Event Trigger for Event Engage.
-- @function [parent=#AI_A2A_INTERCEPT] __Engage
-- @param #AI_A2A_INTERCEPT self
-- @function [parent=#AI_A2A_GCI] __Engage
-- @param #AI_A2A_GCI self
-- @param #number Delay The delay in seconds.
--- OnLeave Transition Handler for State Engaging.
-- @function [parent=#AI_A2A_INTERCEPT] OnLeaveEngaging
-- @param #AI_A2A_INTERCEPT self
-- @function [parent=#AI_A2A_GCI] OnLeaveEngaging
-- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup Object managed by the FSM.
-- @param #string From The From State 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.
--- OnEnter Transition Handler for State Engaging.
-- @function [parent=#AI_A2A_INTERCEPT] OnEnterEngaging
-- @param #AI_A2A_INTERCEPT self
-- @function [parent=#AI_A2A_GCI] OnEnterEngaging
-- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup 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_A2A_INTERCEPT.
self:AddTransition( "Engaging", "Fired", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_A2A_GCI.
--- OnBefore Transition Handler for Event Fired.
-- @function [parent=#AI_A2A_INTERCEPT] OnBeforeFired
-- @param #AI_A2A_INTERCEPT self
-- @function [parent=#AI_A2A_GCI] OnBeforeFired
-- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup Object managed by the FSM.
-- @param #string From The From State 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.
--- OnAfter Transition Handler for Event Fired.
-- @function [parent=#AI_A2A_INTERCEPT] OnAfterFired
-- @param #AI_A2A_INTERCEPT self
-- @function [parent=#AI_A2A_GCI] OnAfterFired
-- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup 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 Fired.
-- @function [parent=#AI_A2A_INTERCEPT] Fired
-- @param #AI_A2A_INTERCEPT self
-- @function [parent=#AI_A2A_GCI] Fired
-- @param #AI_A2A_GCI self
--- Asynchronous Event Trigger for Event Fired.
-- @function [parent=#AI_A2A_INTERCEPT] __Fired
-- @param #AI_A2A_INTERCEPT self
-- @function [parent=#AI_A2A_GCI] __Fired
-- @param #AI_A2A_GCI self
-- @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.
-- @function [parent=#AI_A2A_INTERCEPT] OnBeforeDestroy
-- @param #AI_A2A_INTERCEPT self
-- @function [parent=#AI_A2A_GCI] OnBeforeDestroy
-- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup Object managed by the FSM.
-- @param #string From The From State 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.
--- OnAfter Transition Handler for Event Destroy.
-- @function [parent=#AI_A2A_INTERCEPT] OnAfterDestroy
-- @param #AI_A2A_INTERCEPT self
-- @function [parent=#AI_A2A_GCI] OnAfterDestroy
-- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup 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 Destroy.
-- @function [parent=#AI_A2A_INTERCEPT] Destroy
-- @param #AI_A2A_INTERCEPT self
-- @function [parent=#AI_A2A_GCI] Destroy
-- @param #AI_A2A_GCI self
--- Asynchronous Event Trigger for Event Destroy.
-- @function [parent=#AI_A2A_INTERCEPT] __Destroy
-- @param #AI_A2A_INTERCEPT self
-- @function [parent=#AI_A2A_GCI] __Destroy
-- @param #AI_A2A_GCI self
-- @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.
-- @function [parent=#AI_A2A_INTERCEPT] OnBeforeAbort
-- @param #AI_A2A_INTERCEPT self
-- @function [parent=#AI_A2A_GCI] OnBeforeAbort
-- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup Object managed by the FSM.
-- @param #string From The From State 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.
--- OnAfter Transition Handler for Event Abort.
-- @function [parent=#AI_A2A_INTERCEPT] OnAfterAbort
-- @param #AI_A2A_INTERCEPT self
-- @function [parent=#AI_A2A_GCI] OnAfterAbort
-- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup 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_A2A_INTERCEPT] Abort
-- @param #AI_A2A_INTERCEPT self
-- @function [parent=#AI_A2A_GCI] Abort
-- @param #AI_A2A_GCI self
--- Asynchronous Event Trigger for Event Abort.
-- @function [parent=#AI_A2A_INTERCEPT] __Abort
-- @param #AI_A2A_INTERCEPT self
-- @function [parent=#AI_A2A_GCI] __Abort
-- @param #AI_A2A_GCI self
-- @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.
-- @function [parent=#AI_A2A_INTERCEPT] OnBeforeAccomplish
-- @param #AI_A2A_INTERCEPT self
-- @function [parent=#AI_A2A_GCI] OnBeforeAccomplish
-- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup Object managed by the FSM.
-- @param #string From The From State 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.
--- OnAfter Transition Handler for Event Accomplish.
-- @function [parent=#AI_A2A_INTERCEPT] OnAfterAccomplish
-- @param #AI_A2A_INTERCEPT self
-- @function [parent=#AI_A2A_GCI] OnAfterAccomplish
-- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup 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_A2A_INTERCEPT] Accomplish
-- @param #AI_A2A_INTERCEPT self
-- @function [parent=#AI_A2A_GCI] Accomplish
-- @param #AI_A2A_GCI self
--- Asynchronous Event Trigger for Event Accomplish.
-- @function [parent=#AI_A2A_INTERCEPT] __Accomplish
-- @param #AI_A2A_INTERCEPT self
-- @function [parent=#AI_A2A_GCI] __Accomplish
-- @param #AI_A2A_GCI self
-- @param #number Delay The delay in seconds.
return self
@ -297,12 +297,12 @@ end
--- 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 #string From The From State string.
-- @param #string Event The Event 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 )
@ -311,43 +311,43 @@ end
-- todo: need to fix this global function
--- @param Wrapper.Group#GROUP AIControllable
function AI_A2A_INTERCEPT.InterceptRoute( AIControllable )
function AI_A2A_GCI.InterceptRoute( AIControllable )
AIControllable:T( "NewEngageRoute" )
local EngageZone = AIControllable:GetState( AIControllable, "EngageZone" ) -- AI.AI_Cap#AI_A2A_INTERCEPT
EngageZone:__Engage( 1 )
local EngageZone = AIControllable:GetState( AIControllable, "EngageZone" ) -- AI.AI_Cap#AI_A2A_GCI
EngageZone:Engage()
end
--- @param #AI_A2A_INTERCEPT self
--- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup 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_A2A_INTERCEPT:onbeforeEngage( AIGroup, From, Event, To )
function AI_A2A_GCI:onbeforeEngage( AIGroup, From, Event, To )
if self.Accomplished == true then
return false
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 #string From The From State string.
-- @param #string Event The Event 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()
self:Return()
self:__RTB( 1 )
self:RTB()
end
--- @param #AI_A2A_INTERCEPT self
--- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup 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_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} )
@ -407,7 +407,7 @@ function AI_A2A_INTERCEPT:onafterEngage( AIGroup, From, Event, To, AttackSetUnit
self:Return()
self:RTB()
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 )
--- 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
--- @param #AI_A2A_INTERCEPT self
--- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup 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_A2A_INTERCEPT:onafterAccomplish( AIGroup, From, Event, To )
function AI_A2A_GCI:onafterAccomplish( AIGroup, From, Event, To )
self.Accomplished = true
self:SetDetectionOff()
end
--- @param #AI_A2A_INTERCEPT self
--- @param #AI_A2A_GCI self
-- @param Wrapper.Group#GROUP AIGroup The AIGroup 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_A2A_INTERCEPT:onafterDestroy( AIGroup, From, Event, To, EventData )
function AI_A2A_GCI:onafterDestroy( AIGroup, From, Event, To, EventData )
if EventData.IniUnit then
self.AttackUnits[EventData.IniUnit] = nil
end
end
--- @param #AI_A2A_INTERCEPT self
--- @param #AI_A2A_GCI self
-- @param Core.Event#EVENTDATA EventData
function AI_A2A_INTERCEPT:OnEventDead( EventData )
function AI_A2A_GCI:OnEventDead( EventData )
self:F( { "EventDead", EventData } )
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.
-- 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
PatrolZone:__Route( 1 )
local _AI_A2A_Patrol = AIGroup:GetState( AIGroup, "AI_A2A_PATROL" ) -- #AI_A2A_PATROL
_AI_A2A_Patrol:Route()
end
--- Defines a new patrol route using the @{Process_PatrolZone} parameters and settings.
-- @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 Event The Event 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()
@ -338,91 +338,43 @@ function AI_A2A_PATROL:onafterRoute( Controllable, From, Event, To )
end
if self.Controllable: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.
if AIGroup:IsAlive() then
local PatrolRoute = {}
-- Calculate the current route point of the controllable as the start point of the route.
-- 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.
--- Calculate the target route point.
if self.Controllable:InAir() == false then
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 CurrentCoord = AIGroup:GetCoordinate()
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 )
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.
local ToTargetRoutePoint = ToTargetPointVec3:RoutePointAir(
local ToPatrolRoutePoint = ToTargetCoord:RoutePointAir(
self.PatrolAltType,
POINT_VEC3.RoutePointType.TurningPoint,
POINT_VEC3.RoutePointAction.TurningPoint,
ToTargetSpeed,
true
)
--self.CoordTest:SpawnFromVec3( ToTargetPointVec3:GetVec3() )
--ToTargetPointVec3:SmokeRed()
PatrolRoute[#PatrolRoute+1] = ToTargetRoutePoint
PatrolRoute[#PatrolRoute+1] = ToPatrolRoutePoint
--- 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 ...
self.Controllable:SetState( self.Controllable, "PatrolZone", self )
self.Controllable:WayPointFunction( #PatrolRoute, 1, "AI_A2A_PATROL:_NewPatrolRoute" )
AIGroup:SetState( AIGroup, "AI_A2A_PATROL", self )
--- NOW ROUTE THE GROUP!
self.Controllable:WayPointExecute( 1, 2 )
AIGroup:WayPointExecute( 1, 2 )
end
end

View File

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

File diff suppressed because it is too large Load Diff