CAS first prototype

This commit is contained in:
FlightControl 2017-01-13 14:05:09 +01:00
parent f5f59c4137
commit 60bb6de4a5
12 changed files with 1933 additions and 485 deletions

View File

@ -1,42 +1,42 @@
--- SP:Y MP:Y AI:Y HU:N TYP:Air -- This module contains the AI_CAS class. --- SP:Y MP:Y AI:Y HU:N TYP:Air -- This module contains the AI_CAS_ZONE class.
-- --
-- === -- ===
-- --
-- 1) @{#AI_CAS} class, extends @{Core.Fsm#FSM_CONTROLLABLE} -- 1) @{#AI_CAS_ZONE} class, extends @{Core.Fsm#FSM_CONTROLLABLE}
-- ================================================================ -- ================================================================
-- The @{#AI_CAS} class implements the core functions to CAS a @{Zone} by an AIR @{Controllable} @{Group}. -- The @{#AI_CAS_ZONE} class implements the core functions to CAS a @{Zone} by an AIR @{Controllable} @{Group}.
-- --
-- 1.1) AI_CAS constructor: -- 1.1) AI_CAS_ZONE constructor:
-- ---------------------------- -- ----------------------------
-- --
-- * @{#AI_CAS.New}(): Creates a new AI_CAS object. -- * @{#AI_CAS_ZONE.New}(): Creates a new AI_CAS_ZONE object.
-- --
-- 1.2) AI_CAS state machine: -- 1.2) AI_CAS_ZONE state machine:
-- ---------------------------------- -- ----------------------------------
-- The AI_CAS is a state machine: it manages the different events and states of the AIControllable it is controlling. -- The AI_CAS_ZONE is a state machine: it manages the different events and states of the AIControllable it is controlling.
-- --
-- ### 1.2.1) AI_CAS Events: -- ### 1.2.1) AI_CAS_ZONE Events:
-- --
-- * @{#AI_CAS.TakeOff}( AIControllable ): The AI is taking-off from an airfield. -- * @{#AI_CAS_ZONE.TakeOff}( AIControllable ): The AI is taking-off from an airfield.
-- * @{#AI_CAS.Hold}( AIControllable ): The AI is holding in airspace at a zone. -- * @{#AI_CAS_ZONE.Hold}( AIControllable ): The AI is holding in airspace at a zone.
-- * @{#AI_CAS.Engage}( AIControllable ): The AI is engaging the targets. -- * @{#AI_CAS_ZONE.Engage}( AIControllable ): The AI is engaging the targets.
-- * @{#AI_CAS.WeaponReleased}( AIControllable ): The AI has released a weapon to the target. -- * @{#AI_CAS_ZONE.WeaponReleased}( AIControllable ): The AI has released a weapon to the target.
-- * @{#AI_CAS.Destroy}( AIControllable ): The AI has destroyed a target. -- * @{#AI_CAS_ZONE.Destroy}( AIControllable ): The AI has destroyed a target.
-- * @{#AI_CAS.Complete}( AIControllable ): The AI has destroyed all defined targets. -- * @{#AI_CAS_ZONE.Complete}( AIControllable ): The AI has destroyed all defined targets.
-- * @{#AI_CAS.RTB}( AIControllable ): The AI is returning to the home base. -- * @{#AI_CAS_ZONE.RTB}( AIControllable ): The AI is returning to the home base.
-- --
-- ### 1.2.2) AI_CAS States: -- ### 1.2.2) AI_CAS_ZONE States:
-- --
-- --
-- ### 1.2.3) AI_CAS state transition methods: -- ### 1.2.3) AI_CAS_ZONE state transition methods:
-- --
-- --
-- 1.3) Manage the AI_CAS parameters: -- 1.3) Manage the AI_CAS_ZONE parameters:
-- ------------------------------------------ -- ------------------------------------------
-- The following methods are available to modify the parameters of an AI_CAS object: -- The following methods are available to modify the parameters of an AI_CAS_ZONE object:
-- --
-- * @{#AI_CAS.SetControllable}(): Set the AIControllable. -- * @{#AI_CAS_ZONE.SetControllable}(): Set the AIControllable.
-- * @{#AI_CAS.GetControllable}(): Get the AIControllable. -- * @{#AI_CAS_ZONE.GetControllable}(): Get the AIControllable.
-- --
-- ==== -- ====
-- --
@ -70,181 +70,44 @@
-- @module Cas -- @module Cas
--- AI_CAS class --- AI_CAS_ZONE class
-- @type AI_CAS -- @type AI_CAS_ZONE
-- @field Wrapper.Controllable#CONTROLLABLE AIControllable The @{Controllable} patrolling. -- @field Wrapper.Controllable#CONTROLLABLE AIControllable The @{Controllable} patrolling.
-- @field Core.Zone#ZONE_BASE TargetZone The @{Zone} where the patrol needs to be executed. -- @field Core.Zone#ZONE_BASE TargetZone The @{Zone} where the patrol needs to be executed.
-- @extends Core.Fsm#FSM_CONTROLLABLE -- @extends AI.AI_Patrol#AI_PATROLZONE
AI_CAS = { AI_CAS_ZONE = {
ClassName = "AI_CAS", ClassName = "AI_CAS_ZONE",
} }
--- Creates a new AI_CAS object. --- Creates a new AI_CAS_ZONE object
-- @param #AI_CAS self -- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Ct -- @param Core.Zone#ZONE_BASE PatrolZone The @{Zone} where the patrol needs to be executed.
-- @param Core.Zone#ZONE_BASE TargetZone The @{Zone} where the CAS needs to be executed. -- @param Dcs.DCSTypes#Altitude PatrolFloorAltitude The lowest altitude in meters where to execute the patrol.
-- @param Core.Set#SET_UNIT TargetSet The @{Set} of units to be destroyed. -- @param Dcs.DCSTypes#Altitude PatrolCeilingAltitude The highest altitude in meters where to execute the patrol.
-- @return #AI_CAS The new AI_CAS object. -- @param Dcs.DCSTypes#Speed PatrolMinSpeed The minimum speed of the @{Controllable} in km/h.
function AI_CAS:New( Ct, TargetZone, TargetSet ) -- @param Dcs.DCSTypes#Speed PatrolMaxSpeed The maximum speed of the @{Controllable} in km/h.
-- @param Core.Zone#ZONE EngageZone
-- @return #AI_CAS_ZONE self
function AI_CAS_ZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed, EngageZone )
-- Inherits from BASE -- Inherits from BASE
local self = BASE:Inherit( self, FSM_CONTROLLABLE:New() ) -- #AI_CAS local self = BASE:Inherit( self, AI_PATROLZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed ) ) -- #AI_CAS_ZONE
self:SetStartState( "None" ) self.PatrolZone = PatrolZone
self.PatrolFloorAltitude = PatrolFloorAltitude
env.info( Ct ) self.PatrolCeilingAltitude = PatrolCeilingAltitude
self.PatrolMinSpeed = PatrolMinSpeed
do self:AddTransition( "*", "TakeOff", "RTH" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS. self.PatrolMaxSpeed = PatrolMaxSpeed
--- OnLeave State Transition for *. self.EngageZone = EngageZone
-- @function [parent=#AI_CAS] OnLeave
-- @param #AI_CAS self do self:AddTransition( { "Patrol", "Route", "Engaging" }, "Engage", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for RTH.
-- @function [parent=#AI_CAS] OnEnterRTH
-- @param #AI_CAS self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for TakeOff.
-- @function [parent=#AI_CAS] OnBeforeTakeOff
-- @param #AI_CAS self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for TakeOff.
-- @function [parent=#AI_CAS] OnAfterTakeOff
-- @param #AI_CAS self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- Embedded Event Trigger for TakeOff.
-- @function [parent=#AI_CAS] TakeOff
-- @param #AI_CAS self
--- Delayed Event Trigger for TakeOff
-- @function [parent=#AI_CAS] __TakeOff
-- @param #AI_CAS self
-- @param #number Delay The delay in seconds.
end -- AI_CAS
do self:AddTransition( "RTH", "RouteToHold", "RTH" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS.
--- OnLeave State Transition for RTH.
-- @function [parent=#AI_CAS] OnLeaveRTH
-- @param #AI_CAS self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for RTH.
-- @function [parent=#AI_CAS] OnEnterRTH
-- @param #AI_CAS self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for RouteToHold.
-- @function [parent=#AI_CAS] OnBeforeRouteToHold
-- @param #AI_CAS self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for RouteToHold.
-- @function [parent=#AI_CAS] OnAfterRouteToHold
-- @param #AI_CAS self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- Embedded Event Trigger for RouteToHold.
-- @function [parent=#AI_CAS] RouteToHold
-- @param #AI_CAS self
--- Delayed Event Trigger for RouteToHold
-- @function [parent=#AI_CAS] __RouteToHold
-- @param #AI_CAS self
-- @param #number Delay The delay in seconds.
end -- AI_CAS
do self:AddTransition( "RTH", "Hold", "Holding" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS.
--- OnLeave State Transition for RTH.
-- @function [parent=#AI_CAS] OnLeaveRTH
-- @param #AI_CAS self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Holding.
-- @function [parent=#AI_CAS] OnEnterHolding
-- @param #AI_CAS self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for Hold.
-- @function [parent=#AI_CAS] OnBeforeHold
-- @param #AI_CAS self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Hold.
-- @function [parent=#AI_CAS] OnAfterHold
-- @param #AI_CAS self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- Embedded Event Trigger for Hold.
-- @function [parent=#AI_CAS] Hold
-- @param #AI_CAS self
--- Delayed Event Trigger for Hold
-- @function [parent=#AI_CAS] __Hold
-- @param #AI_CAS self
-- @param #number Delay The delay in seconds.
end -- AI_CAS
do self:AddTransition( "Holding", "Engage", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS.
--- OnLeave State Transition for Holding. --- OnLeave State Transition for Holding.
-- @function [parent=#AI_CAS] OnLeaveHolding -- @function [parent=#AI_CAS_ZONE] OnLeaveHolding
-- @param #AI_CAS self -- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
@ -252,16 +115,16 @@ function AI_CAS:New( Ct, TargetZone, TargetSet )
-- @return #boolean Return false to cancel Transition. -- @return #boolean Return false to cancel Transition.
--- OnEnter State Transition for Engaging. --- OnEnter State Transition for Engaging.
-- @function [parent=#AI_CAS] OnEnterEngaging -- @function [parent=#AI_CAS_ZONE] OnEnterEngaging
-- @param #AI_CAS self -- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for Engage. --- OnBefore State Transition for Engage.
-- @function [parent=#AI_CAS] OnBeforeEngage -- @function [parent=#AI_CAS_ZONE] OnBeforeEngage
-- @param #AI_CAS self -- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
@ -269,29 +132,30 @@ function AI_CAS:New( Ct, TargetZone, TargetSet )
-- @return #boolean Return false to cancel Transition. -- @return #boolean Return false to cancel Transition.
--- OnAfter State Transition for Engage. --- OnAfter State Transition for Engage.
-- @function [parent=#AI_CAS] OnAfterEngage -- @function [parent=#AI_CAS_ZONE] OnAfterEngage
-- @param #AI_CAS self -- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- Embedded Event Trigger for Engage. --- Embedded Event Trigger for Engage.
-- @function [parent=#AI_CAS] Engage -- @function [parent=#AI_CAS_ZONE] Engage
-- @param #AI_CAS self -- @param #AI_CAS_ZONE self
--- Delayed Event Trigger for Engage --- Delayed Event Trigger for Engage
-- @function [parent=#AI_CAS] __Engage -- @function [parent=#AI_CAS_ZONE] __Engage
-- @param #AI_CAS self -- @param #AI_CAS_ZONE self
-- @param #number Delay The delay in seconds. -- @param #number Delay The delay in seconds.
end -- AI_CAS end -- AI_CAS_ZONE
do self:AddTransition( "Engaging", "Fired", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS.
do self:AddTransition( "Engaging", "Fired", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
--- OnLeave State Transition for Engaging. --- OnLeave State Transition for Engaging.
-- @function [parent=#AI_CAS] OnLeaveEngaging -- @function [parent=#AI_CAS_ZONE] OnLeaveEngaging
-- @param #AI_CAS self -- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
@ -299,16 +163,16 @@ function AI_CAS:New( Ct, TargetZone, TargetSet )
-- @return #boolean Return false to cancel Transition. -- @return #boolean Return false to cancel Transition.
--- OnEnter State Transition for Engaging. --- OnEnter State Transition for Engaging.
-- @function [parent=#AI_CAS] OnEnterEngaging -- @function [parent=#AI_CAS_ZONE] OnEnterEngaging
-- @param #AI_CAS self -- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for Fired. --- OnBefore State Transition for Fired.
-- @function [parent=#AI_CAS] OnBeforeFired -- @function [parent=#AI_CAS_ZONE] OnBeforeFired
-- @param #AI_CAS self -- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
@ -316,8 +180,8 @@ function AI_CAS:New( Ct, TargetZone, TargetSet )
-- @return #boolean Return false to cancel Transition. -- @return #boolean Return false to cancel Transition.
--- OnAfter State Transition for Fired. --- OnAfter State Transition for Fired.
-- @function [parent=#AI_CAS] OnAfterFired -- @function [parent=#AI_CAS_ZONE] OnAfterFired
-- @param #AI_CAS self -- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
@ -325,21 +189,21 @@ function AI_CAS:New( Ct, TargetZone, TargetSet )
-- @return #boolean -- @return #boolean
--- Embedded Event Trigger for Fired. --- Embedded Event Trigger for Fired.
-- @function [parent=#AI_CAS] Fired -- @function [parent=#AI_CAS_ZONE] Fired
-- @param #AI_CAS self -- @param #AI_CAS_ZONE self
--- Delayed Event Trigger for Fired --- Delayed Event Trigger for Fired
-- @function [parent=#AI_CAS] __Fired -- @function [parent=#AI_CAS_ZONE] __Fired
-- @param #AI_CAS self -- @param #AI_CAS_ZONE self
-- @param #number Delay The delay in seconds. -- @param #number Delay The delay in seconds.
end -- AI_CAS end -- AI_CAS_ZONE
do self:AddTransition( "Engaging", "Destroy", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS. do self:AddTransition( "Engaging", "Destroy", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
--- OnLeave State Transition for Engaging. --- OnLeave State Transition for Engaging.
-- @function [parent=#AI_CAS] OnLeaveEngaging -- @function [parent=#AI_CAS_ZONE] OnLeaveEngaging
-- @param #AI_CAS self -- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
@ -347,16 +211,16 @@ function AI_CAS:New( Ct, TargetZone, TargetSet )
-- @return #boolean Return false to cancel Transition. -- @return #boolean Return false to cancel Transition.
--- OnEnter State Transition for Engaging. --- OnEnter State Transition for Engaging.
-- @function [parent=#AI_CAS] OnEnterEngaging -- @function [parent=#AI_CAS_ZONE] OnEnterEngaging
-- @param #AI_CAS self -- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for Destroy. --- OnBefore State Transition for Destroy.
-- @function [parent=#AI_CAS] OnBeforeDestroy -- @function [parent=#AI_CAS_ZONE] OnBeforeDestroy
-- @param #AI_CAS self -- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
@ -364,221 +228,268 @@ function AI_CAS:New( Ct, TargetZone, TargetSet )
-- @return #boolean Return false to cancel Transition. -- @return #boolean Return false to cancel Transition.
--- OnAfter State Transition for Destroy. --- OnAfter State Transition for Destroy.
-- @function [parent=#AI_CAS] OnAfterDestroy -- @function [parent=#AI_CAS_ZONE] OnAfterDestroy
-- @param #AI_CAS self -- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- Embedded Event Trigger for Destroy. --- Embedded Event Trigger for Destroy.
-- @function [parent=#AI_CAS] Destroy -- @function [parent=#AI_CAS_ZONE] Destroy
-- @param #AI_CAS self -- @param #AI_CAS_ZONE self
--- Delayed Event Trigger for Destroy --- Delayed Event Trigger for Destroy
-- @function [parent=#AI_CAS] __Destroy -- @function [parent=#AI_CAS_ZONE] __Destroy
-- @param #AI_CAS self -- @param #AI_CAS_ZONE self
-- @param #number Delay The delay in seconds. -- @param #number Delay The delay in seconds.
end -- AI_CAS end -- AI_CAS_ZONE
do self:AddTransition( "Engaging", "Abort", "Holding" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS. do self:AddTransition( "Engaging", "Abort", "Patrol" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
--- OnLeave State Transition for Engaging. --- OnLeave State Transition for Engaging.
-- @function [parent=#AI_CAS] OnLeaveEngaging -- @function [parent=#AI_CAS_ZONE] OnLeaveEngaging
-- @param #AI_CAS self -- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Patrol.
-- @function [parent=#AI_CAS_ZONE] OnEnterPatrol
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for Abort.
-- @function [parent=#AI_CAS_ZONE] OnBeforeAbort
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Abort.
-- @function [parent=#AI_CAS_ZONE] OnAfterAbort
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- Embedded Event Trigger for Abort.
-- @function [parent=#AI_CAS_ZONE] Abort
-- @param #AI_CAS_ZONE self
--- Delayed Event Trigger for Abort
-- @function [parent=#AI_CAS_ZONE] __Abort
-- @param #AI_CAS_ZONE self
-- @param #number Delay The delay in seconds.
end -- AI_CAS_ZONE
do self:AddTransition( "Engaging", "Completed", "Patrol" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
--- OnLeave State Transition for Engaging.
-- @function [parent=#AI_CAS_ZONE] OnLeaveEngaging
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
-- @return #boolean Return false to cancel Transition. -- @return #boolean Return false to cancel Transition.
--- OnEnter State Transition for Holding. --- OnEnter State Transition for Patrol.
-- @function [parent=#AI_CAS] OnEnterHolding -- @function [parent=#AI_CAS_ZONE] OnEnterPatrol
-- @param #AI_CAS self -- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for Abort. --- OnBefore State Transition for Completed.
-- @function [parent=#AI_CAS] OnBeforeAbort -- @function [parent=#AI_CAS_ZONE] OnBeforeCompleted
-- @param #AI_CAS self -- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
-- @return #boolean Return false to cancel Transition. -- @return #boolean Return false to cancel Transition.
--- OnAfter State Transition for Abort. --- OnAfter State Transition for Completed.
-- @function [parent=#AI_CAS] OnAfterAbort -- @function [parent=#AI_CAS_ZONE] OnAfterCompleted
-- @param #AI_CAS self -- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- Embedded Event Trigger for Abort. --- Embedded Event Trigger for Completed.
-- @function [parent=#AI_CAS] Abort -- @function [parent=#AI_CAS_ZONE] Completed
-- @param #AI_CAS self -- @param #AI_CAS_ZONE self
--- Delayed Event Trigger for Abort --- Delayed Event Trigger for Completed
-- @function [parent=#AI_CAS] __Abort -- @function [parent=#AI_CAS_ZONE] __Completed
-- @param #AI_CAS self -- @param #AI_CAS_ZONE self
-- @param #number Delay The delay in seconds. -- @param #number Delay The delay in seconds.
end -- AI_CAS end -- AI_CAS_ZONE
do self:AddTransition( "Engaging", "Completed", "Holding" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS.
--- OnLeave State Transition for Engaging.
-- @function [parent=#AI_CAS] OnLeaveEngaging
-- @param #AI_CAS self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Holding.
-- @function [parent=#AI_CAS] OnEnterHolding
-- @param #AI_CAS self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for Completed.
-- @function [parent=#AI_CAS] OnBeforeCompleted
-- @param #AI_CAS self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Completed.
-- @function [parent=#AI_CAS] OnAfterCompleted
-- @param #AI_CAS self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- Embedded Event Trigger for Completed.
-- @function [parent=#AI_CAS] Completed
-- @param #AI_CAS self
--- Delayed Event Trigger for Completed
-- @function [parent=#AI_CAS] __Completed
-- @param #AI_CAS self
-- @param #number Delay The delay in seconds.
end -- AI_CAS
do self:AddTransition( "Holding", "RTH", "RTB" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS.
--- OnLeave State Transition for Holding.
-- @function [parent=#AI_CAS] OnLeaveHolding
-- @param #AI_CAS self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for RTB.
-- @function [parent=#AI_CAS] OnEnterRTB
-- @param #AI_CAS self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for RTH.
-- @function [parent=#AI_CAS] OnBeforeRTH
-- @param #AI_CAS self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for RTH.
-- @function [parent=#AI_CAS] OnAfterRTH
-- @param #AI_CAS self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- Embedded Event Trigger for RTH.
-- @function [parent=#AI_CAS] RTH
-- @param #AI_CAS self
--- Delayed Event Trigger for RTH
-- @function [parent=#AI_CAS] __RTH
-- @param #AI_CAS self
-- @param #number Delay The delay in seconds.
end -- AI_CAS
do self:AddTransition( "*", "Dead", "Dead" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS.
--- OnLeave State Transition for *.
-- @function [parent=#AI_CAS] OnLeave
-- @param #AI_CAS self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Dead.
-- @function [parent=#AI_CAS] OnEnterDead
-- @param #AI_CAS self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for Dead.
-- @function [parent=#AI_CAS] OnBeforeDead
-- @param #AI_CAS self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Dead.
-- @function [parent=#AI_CAS] OnAfterDead
-- @param #AI_CAS self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- Embedded Event Trigger for Dead.
-- @function [parent=#AI_CAS] Dead
-- @param #AI_CAS self
--- Delayed Event Trigger for Dead
-- @function [parent=#AI_CAS] __Dead
-- @param #AI_CAS self
-- @param #number Delay The delay in seconds.
end -- AI_CAS
self.TargetZone = TargetZone
self.TargetSet = TargetSet
return self return self
end end
--- onafter State Transition for Event Start.
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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_CAS_ZONE:onafterStart( Controllable, From, Event, To )
if Controllable:IsAlive() then
self:__Route( 1 )
end
self:EventOnDead( self.OnDead )
Controllable:OptionROEHoldFire()
Controllable:OptionROTVertical()
end
--- @param Wrapper.Controllable#CONTROLLABLE AIControllable
function _NewEngageRoute( AIControllable )
AIControllable:T( "NewEngageRoute" )
local EngageZone = AIControllable:GetState( AIControllable, "EngageZone" ) -- AI.AI_Patrol#AI_PATROLZONE
EngageZone:__Engage( 1 )
end
--- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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_CAS_ZONE:onafterEngage( Controllable, From, Event, To )
if Controllable:IsAlive() then
local EngageRoute = {}
if self.Controllable:IsNotInZone( self.EngageZone ) then
-- Find a random 2D point in EngageZone.
local ToEngageZoneVec2 = self.EngageZone:GetRandomVec2()
self:T2( ToEngageZoneVec2 )
-- Define Speed and Altitude.
local ToEngageZoneAltitude = math.random( self.EngageFloorAltitude, self.EngageCeilingAltitude )
local ToEngageZoneSpeed = self.PatrolMaxSpeed
self:T2( ToEngageZoneSpeed )
-- Obtain a 3D @{Point} from the 2D point + altitude.
local ToEngageZonePointVec3 = POINT_VEC3:New( ToEngageZoneVec2.x, ToEngageZoneAltitude, ToEngageZoneVec2.y )
-- Create a route point of type air.
local ToEngageZoneRoutePoint = ToEngageZonePointVec3:RoutePointAir(
POINT_VEC3.RoutePointAltType.BARO,
POINT_VEC3.RoutePointType.TurningPoint,
POINT_VEC3.RoutePointAction.TurningPoint,
ToEngageZoneSpeed,
true
)
EngageRoute[#EngageRoute+1] = ToEngageZoneRoutePoint
end
--- Define a random point in the @{Zone}. The AI will fly to that point within the zone.
--- Find a random 2D point in EngageZone.
local ToTargetVec2 = self.EngageZone:GetRandomVec2()
self:T2( ToTargetVec2 )
--- Define Speed and Altitude.
local ToTargetAltitude = math.random( self.EngageFloorAltitude, self.EngageCeilingAltitude )
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(
POINT_VEC3.RoutePointAltType.BARO,
POINT_VEC3.RoutePointType.TurningPoint,
POINT_VEC3.RoutePointAction.TurningPoint,
ToTargetSpeed,
true
)
ToTargetPointVec3:SmokeRed()
EngageRoute[#EngageRoute+1] = ToTargetRoutePoint
--- 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( EngageRoute )
--- Do a trick, link the NewEngageRoute function of the PATROLGROUP object to the AIControllable in a temporary variable ...
self.Controllable:SetState( self.Controllable, "EngageZone", self )
self.Controllable:WayPointFunction( #EngageRoute, 1, "_NewEngageRoute" )
--- NOW ROUTE THE GROUP!
self.Controllable:WayPointExecute( 1, 5 )
local DetectedTargets = Controllable:GetDetectedTargets()
for TargetID, Target in pairs( DetectedTargets ) do
local TargetObject = Target.object
self:T( TargetObject )
if TargetObject and TargetObject:isExist() and TargetObject.id_ < 50000000 then
local TargetUnit = UNIT:Find( TargetObject )
local TargetUnitName = TargetUnit:GetName()
if TargetUnit:IsInZone( self.EngageZone ) then
--local EngageTask = Controllable:EnRouteTaskEngageUnit( TargetUnit, 1 )
local EngageTask = Controllable:TaskAttackUnit( TargetUnit )
Controllable:PushTask( EngageTask, 1 )
end
end
end
Controllable:OptionROEWeaponFree()
Controllable:OptionROTPassiveDefense()
end
end
--- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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_CAS_ZONE:onafterDestroy( Controllable, From, Event, To )
Controllable:MessageToAll( "Destroyed a target", 15 , "Destroyed!" )
end
--- @param #AI_CAS_ZONE self
-- @param Core.Event#EVENTDATA EventData
function AI_CAS_ZONE:OnDead( EventData )
self:T( { "EventDead", EventData } )
if EventData.IniDCSUnit then
self:__Destroy( 1, EventData )
end
end

View File

@ -130,22 +130,7 @@
-- * **FlightControl**: Design & Programming. -- * **FlightControl**: Design & Programming.
-- --
-- --
-- @module Patrol -- @module AI_Patrol
-- State Transition Functions
--- OnBefore State Transition Function
-- @function [parent=#AI_PATROLZONE] OnBeforeRoute
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable
-- @return #boolean
--- OnAfter State Transition Function
-- @function [parent=#AI_PATROLZONE] OnAfterRoute
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable
--- AI_PATROLZONE class --- AI_PATROLZONE class
-- @type AI_PATROLZONE -- @type AI_PATROLZONE
@ -180,20 +165,206 @@ function AI_PATROLZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitu
-- Inherits from BASE -- Inherits from BASE
local self = BASE:Inherit( self, FSM_CONTROLLABLE:New() ) -- Core.Fsm#FSM_CONTROLLABLE local self = BASE:Inherit( self, FSM_CONTROLLABLE:New() ) -- Core.Fsm#FSM_CONTROLLABLE
self:SetStartState( "None" )
self:AddTransition( "*", "Start", "Route" )
self:AddTransition( "*", "Route", "Route" )
self:AddTransition( { "Patrol", "Route" }, "Patrol", "Patrol" )
self:AddTransition( "Patrol", "RTB", "RTB" )
self:AddTransition( "*", "End", "End" )
self:AddTransition( "*", "Dead", "End" )
self.PatrolZone = PatrolZone self.PatrolZone = PatrolZone
self.PatrolFloorAltitude = PatrolFloorAltitude self.PatrolFloorAltitude = PatrolFloorAltitude
self.PatrolCeilingAltitude = PatrolCeilingAltitude self.PatrolCeilingAltitude = PatrolCeilingAltitude
self.PatrolMinSpeed = PatrolMinSpeed self.PatrolMinSpeed = PatrolMinSpeed
self.PatrolMaxSpeed = PatrolMaxSpeed self.PatrolMaxSpeed = PatrolMaxSpeed
self.PatrolFuelTresholdPercentage = 0.2
self:SetStartState( "Route" )
do self:AddTransition( "Route", "Start", "Route" ) -- FSM_CONTROLLABLE Transition for type #AI_PATROLZONE.
--- OnLeave State Transition for Route.
-- @function [parent=#AI_PATROLZONE] OnLeaveRoute
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Route.
-- @function [parent=#AI_PATROLZONE] OnEnterRoute
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for Start.
-- @function [parent=#AI_PATROLZONE] OnBeforeStart
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Start.
-- @function [parent=#AI_PATROLZONE] OnAfterStart
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- Embedded Event Trigger for Start.
-- @function [parent=#AI_PATROLZONE] Start
-- @param #AI_PATROLZONE self
--- Delayed Event Trigger for Start
-- @function [parent=#AI_PATROLZONE] __Start
-- @param #AI_PATROLZONE self
-- @param #number Delay The delay in seconds.
end -- AI_PATROLZONE
do self:AddTransition( "Route", "Route", "Route" ) -- FSM_CONTROLLABLE Transition for type #AI_PATROLZONE.
--- OnLeave State Transition for Route.
-- @function [parent=#AI_PATROLZONE] OnLeaveRoute
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Route.
-- @function [parent=#AI_PATROLZONE] OnEnterRoute
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for Route.
-- @function [parent=#AI_PATROLZONE] OnBeforeRoute
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Route.
-- @function [parent=#AI_PATROLZONE] OnAfterRoute
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- Embedded Event Trigger for Route.
-- @function [parent=#AI_PATROLZONE] Route
-- @param #AI_PATROLZONE self
--- Delayed Event Trigger for Route
-- @function [parent=#AI_PATROLZONE] __Route
-- @param #AI_PATROLZONE self
-- @param #number Delay The delay in seconds.
end -- AI_PATROLZONE
do self:AddTransition( { "Patrol", "Route" }, "Patrol", "Patrol" ) -- FSM_CONTROLLABLE Transition for type #AI_PATROLZONE.
--- OnLeave State Transition for Patrol.
-- @function [parent=#AI_PATROLZONE] OnLeavePatrol
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Patrol.
-- @function [parent=#AI_PATROLZONE] OnEnterPatrol
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for Patrol.
-- @function [parent=#AI_PATROLZONE] OnBeforePatrol
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Patrol.
-- @function [parent=#AI_PATROLZONE] OnAfterPatrol
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- Embedded Event Trigger for Patrol.
-- @function [parent=#AI_PATROLZONE] Patrol
-- @param #AI_PATROLZONE self
--- Delayed Event Trigger for Patrol
-- @function [parent=#AI_PATROLZONE] __Patrol
-- @param #AI_PATROLZONE self
-- @param #number Delay The delay in seconds.
end -- AI_PATROLZONE
do self:AddTransition( "Patrol", "RTB", "RTB" ) -- FSM_CONTROLLABLE Transition for type #AI_PATROLZONE.
--- OnLeave State Transition for Patrol.
-- @function [parent=#AI_PATROLZONE] OnLeavePatrol
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for RTB.
-- @function [parent=#AI_PATROLZONE] OnEnterRTB
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for RTB.
-- @function [parent=#AI_PATROLZONE] OnBeforeRTB
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for RTB.
-- @function [parent=#AI_PATROLZONE] OnAfterRTB
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- Embedded Event Trigger for RTB.
-- @function [parent=#AI_PATROLZONE] RTB
-- @param #AI_PATROLZONE self
--- Delayed Event Trigger for RTB
-- @function [parent=#AI_PATROLZONE] __RTB
-- @param #AI_PATROLZONE self
-- @param #number Delay The delay in seconds.
end -- AI_PATROLZONE
return self return self
end end

View File

@ -43,6 +43,7 @@ Include.File( "Functional/Detection" )
Include.File( "AI/AI_Balancer" ) Include.File( "AI/AI_Balancer" )
Include.File( "AI/AI_Patrol" ) Include.File( "AI/AI_Patrol" )
Include.File( "AI/AI_Cargo" ) Include.File( "AI/AI_Cargo" )
Include.File( "AI/AI_Cas" )
--- Actions --- Actions
Include.File( "Actions/Act_Assign" ) Include.File( "Actions/Act_Assign" )

View File

@ -126,6 +126,7 @@
--- The CONTROLLABLE class --- The CONTROLLABLE class
-- @type CONTROLLABLE -- @type CONTROLLABLE
-- @extends Wrapper.Positionable#POSITIONABLE
-- @field Dcs.DCSWrapper.Controllable#Controllable DCSControllable The DCS controllable class. -- @field Dcs.DCSWrapper.Controllable#Controllable DCSControllable The DCS controllable class.
-- @field #string ControllableName The name of the controllable. -- @field #string ControllableName The name of the controllable.
CONTROLLABLE = { CONTROLLABLE = {

View File

@ -28,7 +28,7 @@
-- --
-- === -- ===
-- --
-- @module Wrapper.Identifiable -- @module Identifiable
--- The IDENTIFIABLE class --- The IDENTIFIABLE class
-- @type IDENTIFIABLE -- @type IDENTIFIABLE

View File

@ -22,7 +22,7 @@
-- --
-- === -- ===
-- --
-- @module Wrapper.Object -- @module Object
--- The OBJECT class --- The OBJECT class
-- @type OBJECT -- @type OBJECT

View File

@ -23,7 +23,7 @@
-- --
-- === -- ===
-- --
-- @module Wrapper.Positionable -- @module Positionable
--- The POSITIONABLE class --- The POSITIONABLE class
-- @type POSITIONABLE -- @type POSITIONABLE

View File

@ -1,5 +1,5 @@
env.info( '*** MOOSE STATIC INCLUDE START *** ' ) env.info( '*** MOOSE STATIC INCLUDE START *** ' )
env.info( 'Moose Generation Timestamp: 20170112_1219' ) env.info( 'Moose Generation Timestamp: 20170113_1404' )
local base = _G local base = _G
Include = {} Include = {}
@ -11769,7 +11769,6 @@ end -- FSM_SET
-- === -- ===
-- --
-- @module Object -- @module Object
-- @author FlightControl
--- The OBJECT class --- The OBJECT class
-- @type OBJECT -- @type OBJECT
@ -11864,7 +11863,6 @@ end
-- === -- ===
-- --
-- @module Identifiable -- @module Identifiable
-- @author FlightControl
--- The IDENTIFIABLE class --- The IDENTIFIABLE class
-- @type IDENTIFIABLE -- @type IDENTIFIABLE
@ -12086,7 +12084,6 @@ end
-- === -- ===
-- --
-- @module Positionable -- @module Positionable
-- @author FlightControl
--- The POSITIONABLE class --- The POSITIONABLE class
-- @type POSITIONABLE -- @type POSITIONABLE
@ -12608,7 +12605,6 @@ end
-- === -- ===
-- --
-- @module Controllable -- @module Controllable
-- @author FlightControl
--- The CONTROLLABLE class --- The CONTROLLABLE class
-- @type CONTROLLABLE -- @type CONTROLLABLE
@ -24644,22 +24640,7 @@ end
-- * **FlightControl**: Design & Programming. -- * **FlightControl**: Design & Programming.
-- --
-- --
-- @module Patrol -- @module AI_Patrol
-- State Transition Functions
--- OnBefore State Transition Function
-- @function [parent=#AI_PATROLZONE] OnBeforeRoute
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable
-- @return #boolean
--- OnAfter State Transition Function
-- @function [parent=#AI_PATROLZONE] OnAfterRoute
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable
--- AI_PATROLZONE class --- AI_PATROLZONE class
-- @type AI_PATROLZONE -- @type AI_PATROLZONE
@ -24694,20 +24675,206 @@ function AI_PATROLZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitu
-- Inherits from BASE -- Inherits from BASE
local self = BASE:Inherit( self, FSM_CONTROLLABLE:New() ) -- Core.Fsm#FSM_CONTROLLABLE local self = BASE:Inherit( self, FSM_CONTROLLABLE:New() ) -- Core.Fsm#FSM_CONTROLLABLE
self:SetStartState( "None" )
self:AddTransition( "*", "Start", "Route" )
self:AddTransition( "*", "Route", "Route" )
self:AddTransition( { "Patrol", "Route" }, "Patrol", "Patrol" )
self:AddTransition( "Patrol", "RTB", "RTB" )
self:AddTransition( "*", "End", "End" )
self:AddTransition( "*", "Dead", "End" )
self.PatrolZone = PatrolZone self.PatrolZone = PatrolZone
self.PatrolFloorAltitude = PatrolFloorAltitude self.PatrolFloorAltitude = PatrolFloorAltitude
self.PatrolCeilingAltitude = PatrolCeilingAltitude self.PatrolCeilingAltitude = PatrolCeilingAltitude
self.PatrolMinSpeed = PatrolMinSpeed self.PatrolMinSpeed = PatrolMinSpeed
self.PatrolMaxSpeed = PatrolMaxSpeed self.PatrolMaxSpeed = PatrolMaxSpeed
self.PatrolFuelTresholdPercentage = 0.2
self:SetStartState( "Route" )
do self:AddTransition( "Route", "Start", "Route" ) -- FSM_CONTROLLABLE Transition for type #AI_PATROLZONE.
--- OnLeave State Transition for Route.
-- @function [parent=#AI_PATROLZONE] OnLeaveRoute
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Route.
-- @function [parent=#AI_PATROLZONE] OnEnterRoute
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for Start.
-- @function [parent=#AI_PATROLZONE] OnBeforeStart
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Start.
-- @function [parent=#AI_PATROLZONE] OnAfterStart
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- Embedded Event Trigger for Start.
-- @function [parent=#AI_PATROLZONE] Start
-- @param #AI_PATROLZONE self
--- Delayed Event Trigger for Start
-- @function [parent=#AI_PATROLZONE] __Start
-- @param #AI_PATROLZONE self
-- @param #number Delay The delay in seconds.
end -- AI_PATROLZONE
do self:AddTransition( "Route", "Route", "Route" ) -- FSM_CONTROLLABLE Transition for type #AI_PATROLZONE.
--- OnLeave State Transition for Route.
-- @function [parent=#AI_PATROLZONE] OnLeaveRoute
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Route.
-- @function [parent=#AI_PATROLZONE] OnEnterRoute
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for Route.
-- @function [parent=#AI_PATROLZONE] OnBeforeRoute
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Route.
-- @function [parent=#AI_PATROLZONE] OnAfterRoute
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- Embedded Event Trigger for Route.
-- @function [parent=#AI_PATROLZONE] Route
-- @param #AI_PATROLZONE self
--- Delayed Event Trigger for Route
-- @function [parent=#AI_PATROLZONE] __Route
-- @param #AI_PATROLZONE self
-- @param #number Delay The delay in seconds.
end -- AI_PATROLZONE
do self:AddTransition( { "Patrol", "Route" }, "Patrol", "Patrol" ) -- FSM_CONTROLLABLE Transition for type #AI_PATROLZONE.
--- OnLeave State Transition for Patrol.
-- @function [parent=#AI_PATROLZONE] OnLeavePatrol
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Patrol.
-- @function [parent=#AI_PATROLZONE] OnEnterPatrol
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for Patrol.
-- @function [parent=#AI_PATROLZONE] OnBeforePatrol
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Patrol.
-- @function [parent=#AI_PATROLZONE] OnAfterPatrol
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- Embedded Event Trigger for Patrol.
-- @function [parent=#AI_PATROLZONE] Patrol
-- @param #AI_PATROLZONE self
--- Delayed Event Trigger for Patrol
-- @function [parent=#AI_PATROLZONE] __Patrol
-- @param #AI_PATROLZONE self
-- @param #number Delay The delay in seconds.
end -- AI_PATROLZONE
do self:AddTransition( "Patrol", "RTB", "RTB" ) -- FSM_CONTROLLABLE Transition for type #AI_PATROLZONE.
--- OnLeave State Transition for Patrol.
-- @function [parent=#AI_PATROLZONE] OnLeavePatrol
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for RTB.
-- @function [parent=#AI_PATROLZONE] OnEnterRTB
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for RTB.
-- @function [parent=#AI_PATROLZONE] OnBeforeRTB
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for RTB.
-- @function [parent=#AI_PATROLZONE] OnAfterRTB
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- Embedded Event Trigger for RTB.
-- @function [parent=#AI_PATROLZONE] RTB
-- @param #AI_PATROLZONE self
--- Delayed Event Trigger for RTB
-- @function [parent=#AI_PATROLZONE] __RTB
-- @param #AI_PATROLZONE self
-- @param #number Delay The delay in seconds.
end -- AI_PATROLZONE
return self return self
end end
@ -25915,6 +26082,501 @@ end -- AI_CARGO_GROUPED
--- SP:Y MP:Y AI:Y HU:N TYP:Air -- This module contains the AI_CAS_ZONE class.
--
-- ===
--
-- 1) @{#AI_CAS_ZONE} class, extends @{Core.Fsm#FSM_CONTROLLABLE}
-- ================================================================
-- The @{#AI_CAS_ZONE} class implements the core functions to CAS a @{Zone} by an AIR @{Controllable} @{Group}.
--
-- 1.1) AI_CAS_ZONE constructor:
-- ----------------------------
--
-- * @{#AI_CAS_ZONE.New}(): Creates a new AI_CAS_ZONE object.
--
-- 1.2) AI_CAS_ZONE state machine:
-- ----------------------------------
-- The AI_CAS_ZONE is a state machine: it manages the different events and states of the AIControllable it is controlling.
--
-- ### 1.2.1) AI_CAS_ZONE Events:
--
-- * @{#AI_CAS_ZONE.TakeOff}( AIControllable ): The AI is taking-off from an airfield.
-- * @{#AI_CAS_ZONE.Hold}( AIControllable ): The AI is holding in airspace at a zone.
-- * @{#AI_CAS_ZONE.Engage}( AIControllable ): The AI is engaging the targets.
-- * @{#AI_CAS_ZONE.WeaponReleased}( AIControllable ): The AI has released a weapon to the target.
-- * @{#AI_CAS_ZONE.Destroy}( AIControllable ): The AI has destroyed a target.
-- * @{#AI_CAS_ZONE.Complete}( AIControllable ): The AI has destroyed all defined targets.
-- * @{#AI_CAS_ZONE.RTB}( AIControllable ): The AI is returning to the home base.
--
-- ### 1.2.2) AI_CAS_ZONE States:
--
--
-- ### 1.2.3) AI_CAS_ZONE state transition methods:
--
--
-- 1.3) Manage the AI_CAS_ZONE parameters:
-- ------------------------------------------
-- The following methods are available to modify the parameters of an AI_CAS_ZONE object:
--
-- * @{#AI_CAS_ZONE.SetControllable}(): Set the AIControllable.
-- * @{#AI_CAS_ZONE.GetControllable}(): Get the AIControllable.
--
-- ====
--
-- **API CHANGE HISTORY**
-- ======================
--
-- The underlying change log documents the API changes. Please read this carefully. The following notation is used:
--
-- * **Added** parts are expressed in bold type face.
-- * _Removed_ parts are expressed in italic type face.
--
-- Hereby the change log:
--
-- 2017-01-12: Initial class and API.
--
-- ===
--
-- AUTHORS and CONTRIBUTIONS
-- =========================
--
-- ### Contributions:
--
-- * **Quax**: Concept & Testing.
-- * **Pikey**: Concept & Testing.
--
-- ### Authors:
--
-- * **FlightControl**: Concept, Design & Programming.
--
--
-- @module Cas
--- AI_CAS_ZONE class
-- @type AI_CAS_ZONE
-- @field Wrapper.Controllable#CONTROLLABLE AIControllable The @{Controllable} patrolling.
-- @field Core.Zone#ZONE_BASE TargetZone The @{Zone} where the patrol needs to be executed.
-- @extends AI.AI_Patrol#AI_PATROLZONE
AI_CAS_ZONE = {
ClassName = "AI_CAS_ZONE",
}
--- Creates a new AI_CAS_ZONE object
-- @param #AI_CAS_ZONE self
-- @param Core.Zone#ZONE_BASE PatrolZone The @{Zone} where the patrol needs to be executed.
-- @param Dcs.DCSTypes#Altitude PatrolFloorAltitude The lowest altitude in meters where to execute the patrol.
-- @param Dcs.DCSTypes#Altitude PatrolCeilingAltitude The highest altitude in meters where to execute the patrol.
-- @param Dcs.DCSTypes#Speed PatrolMinSpeed The minimum speed of the @{Controllable} in km/h.
-- @param Dcs.DCSTypes#Speed PatrolMaxSpeed The maximum speed of the @{Controllable} in km/h.
-- @param Core.Zone#ZONE EngageZone
-- @return #AI_CAS_ZONE self
function AI_CAS_ZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed, EngageZone )
-- Inherits from BASE
local self = BASE:Inherit( self, AI_PATROLZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed ) ) -- #AI_CAS_ZONE
self.PatrolZone = PatrolZone
self.PatrolFloorAltitude = PatrolFloorAltitude
self.PatrolCeilingAltitude = PatrolCeilingAltitude
self.PatrolMinSpeed = PatrolMinSpeed
self.PatrolMaxSpeed = PatrolMaxSpeed
self.EngageZone = EngageZone
do self:AddTransition( { "Patrol", "Route", "Engaging" }, "Engage", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
--- OnLeave State Transition for Holding.
-- @function [parent=#AI_CAS_ZONE] OnLeaveHolding
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Engaging.
-- @function [parent=#AI_CAS_ZONE] OnEnterEngaging
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for Engage.
-- @function [parent=#AI_CAS_ZONE] OnBeforeEngage
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Engage.
-- @function [parent=#AI_CAS_ZONE] OnAfterEngage
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- Embedded Event Trigger for Engage.
-- @function [parent=#AI_CAS_ZONE] Engage
-- @param #AI_CAS_ZONE self
--- Delayed Event Trigger for Engage
-- @function [parent=#AI_CAS_ZONE] __Engage
-- @param #AI_CAS_ZONE self
-- @param #number Delay The delay in seconds.
end -- AI_CAS_ZONE
do self:AddTransition( "Engaging", "Fired", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
--- OnLeave State Transition for Engaging.
-- @function [parent=#AI_CAS_ZONE] OnLeaveEngaging
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Engaging.
-- @function [parent=#AI_CAS_ZONE] OnEnterEngaging
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for Fired.
-- @function [parent=#AI_CAS_ZONE] OnBeforeFired
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Fired.
-- @function [parent=#AI_CAS_ZONE] OnAfterFired
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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
--- Embedded Event Trigger for Fired.
-- @function [parent=#AI_CAS_ZONE] Fired
-- @param #AI_CAS_ZONE self
--- Delayed Event Trigger for Fired
-- @function [parent=#AI_CAS_ZONE] __Fired
-- @param #AI_CAS_ZONE self
-- @param #number Delay The delay in seconds.
end -- AI_CAS_ZONE
do self:AddTransition( "Engaging", "Destroy", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
--- OnLeave State Transition for Engaging.
-- @function [parent=#AI_CAS_ZONE] OnLeaveEngaging
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Engaging.
-- @function [parent=#AI_CAS_ZONE] OnEnterEngaging
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for Destroy.
-- @function [parent=#AI_CAS_ZONE] OnBeforeDestroy
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Destroy.
-- @function [parent=#AI_CAS_ZONE] OnAfterDestroy
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- Embedded Event Trigger for Destroy.
-- @function [parent=#AI_CAS_ZONE] Destroy
-- @param #AI_CAS_ZONE self
--- Delayed Event Trigger for Destroy
-- @function [parent=#AI_CAS_ZONE] __Destroy
-- @param #AI_CAS_ZONE self
-- @param #number Delay The delay in seconds.
end -- AI_CAS_ZONE
do self:AddTransition( "Engaging", "Abort", "Patrol" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
--- OnLeave State Transition for Engaging.
-- @function [parent=#AI_CAS_ZONE] OnLeaveEngaging
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Patrol.
-- @function [parent=#AI_CAS_ZONE] OnEnterPatrol
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for Abort.
-- @function [parent=#AI_CAS_ZONE] OnBeforeAbort
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Abort.
-- @function [parent=#AI_CAS_ZONE] OnAfterAbort
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- Embedded Event Trigger for Abort.
-- @function [parent=#AI_CAS_ZONE] Abort
-- @param #AI_CAS_ZONE self
--- Delayed Event Trigger for Abort
-- @function [parent=#AI_CAS_ZONE] __Abort
-- @param #AI_CAS_ZONE self
-- @param #number Delay The delay in seconds.
end -- AI_CAS_ZONE
do self:AddTransition( "Engaging", "Completed", "Patrol" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
--- OnLeave State Transition for Engaging.
-- @function [parent=#AI_CAS_ZONE] OnLeaveEngaging
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Patrol.
-- @function [parent=#AI_CAS_ZONE] OnEnterPatrol
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for Completed.
-- @function [parent=#AI_CAS_ZONE] OnBeforeCompleted
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Completed.
-- @function [parent=#AI_CAS_ZONE] OnAfterCompleted
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- Embedded Event Trigger for Completed.
-- @function [parent=#AI_CAS_ZONE] Completed
-- @param #AI_CAS_ZONE self
--- Delayed Event Trigger for Completed
-- @function [parent=#AI_CAS_ZONE] __Completed
-- @param #AI_CAS_ZONE self
-- @param #number Delay The delay in seconds.
end -- AI_CAS_ZONE
return self
end
--- onafter State Transition for Event Start.
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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_CAS_ZONE:onafterStart( Controllable, From, Event, To )
if Controllable:IsAlive() then
self:__Route( 1 )
end
self:EventOnDead( self.OnDead )
Controllable:OptionROEHoldFire()
Controllable:OptionROTVertical()
end
--- @param Wrapper.Controllable#CONTROLLABLE AIControllable
function _NewEngageRoute( AIControllable )
AIControllable:T( "NewEngageRoute" )
local EngageZone = AIControllable:GetState( AIControllable, "EngageZone" ) -- AI.AI_Patrol#AI_PATROLZONE
EngageZone:__Engage( 1 )
end
--- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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_CAS_ZONE:onafterEngage( Controllable, From, Event, To )
if Controllable:IsAlive() then
local EngageRoute = {}
if self.Controllable:IsNotInZone( self.EngageZone ) then
-- Find a random 2D point in EngageZone.
local ToEngageZoneVec2 = self.EngageZone:GetRandomVec2()
self:T2( ToEngageZoneVec2 )
-- Define Speed and Altitude.
local ToEngageZoneAltitude = math.random( self.EngageFloorAltitude, self.EngageCeilingAltitude )
local ToEngageZoneSpeed = self.PatrolMaxSpeed
self:T2( ToEngageZoneSpeed )
-- Obtain a 3D @{Point} from the 2D point + altitude.
local ToEngageZonePointVec3 = POINT_VEC3:New( ToEngageZoneVec2.x, ToEngageZoneAltitude, ToEngageZoneVec2.y )
-- Create a route point of type air.
local ToEngageZoneRoutePoint = ToEngageZonePointVec3:RoutePointAir(
POINT_VEC3.RoutePointAltType.BARO,
POINT_VEC3.RoutePointType.TurningPoint,
POINT_VEC3.RoutePointAction.TurningPoint,
ToEngageZoneSpeed,
true
)
EngageRoute[#EngageRoute+1] = ToEngageZoneRoutePoint
end
--- Define a random point in the @{Zone}. The AI will fly to that point within the zone.
--- Find a random 2D point in EngageZone.
local ToTargetVec2 = self.EngageZone:GetRandomVec2()
self:T2( ToTargetVec2 )
--- Define Speed and Altitude.
local ToTargetAltitude = math.random( self.EngageFloorAltitude, self.EngageCeilingAltitude )
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(
POINT_VEC3.RoutePointAltType.BARO,
POINT_VEC3.RoutePointType.TurningPoint,
POINT_VEC3.RoutePointAction.TurningPoint,
ToTargetSpeed,
true
)
ToTargetPointVec3:SmokeRed()
EngageRoute[#EngageRoute+1] = ToTargetRoutePoint
--- 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( EngageRoute )
--- Do a trick, link the NewEngageRoute function of the PATROLGROUP object to the AIControllable in a temporary variable ...
self.Controllable:SetState( self.Controllable, "EngageZone", self )
self.Controllable:WayPointFunction( #EngageRoute, 1, "_NewEngageRoute" )
--- NOW ROUTE THE GROUP!
self.Controllable:WayPointExecute( 1, 5 )
local DetectedTargets = Controllable:GetDetectedTargets()
for TargetID, Target in pairs( DetectedTargets ) do
local TargetObject = Target.object
self:T( TargetObject )
if TargetObject and TargetObject:isExist() and TargetObject.id_ < 50000000 then
local TargetUnit = UNIT:Find( TargetObject )
local TargetUnitName = TargetUnit:GetName()
if TargetUnit:IsInZone( self.EngageZone ) then
--local EngageTask = Controllable:EnRouteTaskEngageUnit( TargetUnit, 1 )
local EngageTask = Controllable:TaskAttackUnit( TargetUnit )
Controllable:PushTask( EngageTask, 1 )
end
end
end
Controllable:OptionROEWeaponFree()
Controllable:OptionROTPassiveDefense()
end
end
--- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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_CAS_ZONE:onafterDestroy( Controllable, From, Event, To )
Controllable:MessageToAll( "Destroyed a target", 15 , "Destroyed!" )
end
--- @param #AI_CAS_ZONE self
-- @param Core.Event#EVENTDATA EventData
function AI_CAS_ZONE:OnDead( EventData )
self:T( { "EventDead", EventData } )
if EventData.IniDCSUnit then
self:__Destroy( 1, EventData )
end
end
--- (SP) (MP) (FSM) Accept or reject process for player (task) assignments. --- (SP) (MP) (FSM) Accept or reject process for player (task) assignments.
-- --
-- === -- ===
@ -29882,6 +30544,7 @@ Include.File( "Functional/Detection" )
Include.File( "AI/AI_Balancer" ) Include.File( "AI/AI_Balancer" )
Include.File( "AI/AI_Patrol" ) Include.File( "AI/AI_Patrol" )
Include.File( "AI/AI_Cargo" ) Include.File( "AI/AI_Cargo" )
Include.File( "AI/AI_Cas" )
--- Actions --- Actions
Include.File( "Actions/Act_Assign" ) Include.File( "Actions/Act_Assign" )

View File

@ -1,5 +1,5 @@
env.info( '*** MOOSE STATIC INCLUDE START *** ' ) env.info( '*** MOOSE STATIC INCLUDE START *** ' )
env.info( 'Moose Generation Timestamp: 20170112_1219' ) env.info( 'Moose Generation Timestamp: 20170113_1404' )
local base = _G local base = _G
Include = {} Include = {}
@ -11769,7 +11769,6 @@ end -- FSM_SET
-- === -- ===
-- --
-- @module Object -- @module Object
-- @author FlightControl
--- The OBJECT class --- The OBJECT class
-- @type OBJECT -- @type OBJECT
@ -11864,7 +11863,6 @@ end
-- === -- ===
-- --
-- @module Identifiable -- @module Identifiable
-- @author FlightControl
--- The IDENTIFIABLE class --- The IDENTIFIABLE class
-- @type IDENTIFIABLE -- @type IDENTIFIABLE
@ -12086,7 +12084,6 @@ end
-- === -- ===
-- --
-- @module Positionable -- @module Positionable
-- @author FlightControl
--- The POSITIONABLE class --- The POSITIONABLE class
-- @type POSITIONABLE -- @type POSITIONABLE
@ -12608,7 +12605,6 @@ end
-- === -- ===
-- --
-- @module Controllable -- @module Controllable
-- @author FlightControl
--- The CONTROLLABLE class --- The CONTROLLABLE class
-- @type CONTROLLABLE -- @type CONTROLLABLE
@ -24644,22 +24640,7 @@ end
-- * **FlightControl**: Design & Programming. -- * **FlightControl**: Design & Programming.
-- --
-- --
-- @module Patrol -- @module AI_Patrol
-- State Transition Functions
--- OnBefore State Transition Function
-- @function [parent=#AI_PATROLZONE] OnBeforeRoute
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable
-- @return #boolean
--- OnAfter State Transition Function
-- @function [parent=#AI_PATROLZONE] OnAfterRoute
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable
--- AI_PATROLZONE class --- AI_PATROLZONE class
-- @type AI_PATROLZONE -- @type AI_PATROLZONE
@ -24694,20 +24675,206 @@ function AI_PATROLZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitu
-- Inherits from BASE -- Inherits from BASE
local self = BASE:Inherit( self, FSM_CONTROLLABLE:New() ) -- Core.Fsm#FSM_CONTROLLABLE local self = BASE:Inherit( self, FSM_CONTROLLABLE:New() ) -- Core.Fsm#FSM_CONTROLLABLE
self:SetStartState( "None" )
self:AddTransition( "*", "Start", "Route" )
self:AddTransition( "*", "Route", "Route" )
self:AddTransition( { "Patrol", "Route" }, "Patrol", "Patrol" )
self:AddTransition( "Patrol", "RTB", "RTB" )
self:AddTransition( "*", "End", "End" )
self:AddTransition( "*", "Dead", "End" )
self.PatrolZone = PatrolZone self.PatrolZone = PatrolZone
self.PatrolFloorAltitude = PatrolFloorAltitude self.PatrolFloorAltitude = PatrolFloorAltitude
self.PatrolCeilingAltitude = PatrolCeilingAltitude self.PatrolCeilingAltitude = PatrolCeilingAltitude
self.PatrolMinSpeed = PatrolMinSpeed self.PatrolMinSpeed = PatrolMinSpeed
self.PatrolMaxSpeed = PatrolMaxSpeed self.PatrolMaxSpeed = PatrolMaxSpeed
self.PatrolFuelTresholdPercentage = 0.2
self:SetStartState( "Route" )
do self:AddTransition( "Route", "Start", "Route" ) -- FSM_CONTROLLABLE Transition for type #AI_PATROLZONE.
--- OnLeave State Transition for Route.
-- @function [parent=#AI_PATROLZONE] OnLeaveRoute
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Route.
-- @function [parent=#AI_PATROLZONE] OnEnterRoute
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for Start.
-- @function [parent=#AI_PATROLZONE] OnBeforeStart
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Start.
-- @function [parent=#AI_PATROLZONE] OnAfterStart
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- Embedded Event Trigger for Start.
-- @function [parent=#AI_PATROLZONE] Start
-- @param #AI_PATROLZONE self
--- Delayed Event Trigger for Start
-- @function [parent=#AI_PATROLZONE] __Start
-- @param #AI_PATROLZONE self
-- @param #number Delay The delay in seconds.
end -- AI_PATROLZONE
do self:AddTransition( "Route", "Route", "Route" ) -- FSM_CONTROLLABLE Transition for type #AI_PATROLZONE.
--- OnLeave State Transition for Route.
-- @function [parent=#AI_PATROLZONE] OnLeaveRoute
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Route.
-- @function [parent=#AI_PATROLZONE] OnEnterRoute
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for Route.
-- @function [parent=#AI_PATROLZONE] OnBeforeRoute
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Route.
-- @function [parent=#AI_PATROLZONE] OnAfterRoute
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- Embedded Event Trigger for Route.
-- @function [parent=#AI_PATROLZONE] Route
-- @param #AI_PATROLZONE self
--- Delayed Event Trigger for Route
-- @function [parent=#AI_PATROLZONE] __Route
-- @param #AI_PATROLZONE self
-- @param #number Delay The delay in seconds.
end -- AI_PATROLZONE
do self:AddTransition( { "Patrol", "Route" }, "Patrol", "Patrol" ) -- FSM_CONTROLLABLE Transition for type #AI_PATROLZONE.
--- OnLeave State Transition for Patrol.
-- @function [parent=#AI_PATROLZONE] OnLeavePatrol
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Patrol.
-- @function [parent=#AI_PATROLZONE] OnEnterPatrol
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for Patrol.
-- @function [parent=#AI_PATROLZONE] OnBeforePatrol
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Patrol.
-- @function [parent=#AI_PATROLZONE] OnAfterPatrol
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- Embedded Event Trigger for Patrol.
-- @function [parent=#AI_PATROLZONE] Patrol
-- @param #AI_PATROLZONE self
--- Delayed Event Trigger for Patrol
-- @function [parent=#AI_PATROLZONE] __Patrol
-- @param #AI_PATROLZONE self
-- @param #number Delay The delay in seconds.
end -- AI_PATROLZONE
do self:AddTransition( "Patrol", "RTB", "RTB" ) -- FSM_CONTROLLABLE Transition for type #AI_PATROLZONE.
--- OnLeave State Transition for Patrol.
-- @function [parent=#AI_PATROLZONE] OnLeavePatrol
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for RTB.
-- @function [parent=#AI_PATROLZONE] OnEnterRTB
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for RTB.
-- @function [parent=#AI_PATROLZONE] OnBeforeRTB
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for RTB.
-- @function [parent=#AI_PATROLZONE] OnAfterRTB
-- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- Embedded Event Trigger for RTB.
-- @function [parent=#AI_PATROLZONE] RTB
-- @param #AI_PATROLZONE self
--- Delayed Event Trigger for RTB
-- @function [parent=#AI_PATROLZONE] __RTB
-- @param #AI_PATROLZONE self
-- @param #number Delay The delay in seconds.
end -- AI_PATROLZONE
return self return self
end end
@ -25915,6 +26082,501 @@ end -- AI_CARGO_GROUPED
--- SP:Y MP:Y AI:Y HU:N TYP:Air -- This module contains the AI_CAS_ZONE class.
--
-- ===
--
-- 1) @{#AI_CAS_ZONE} class, extends @{Core.Fsm#FSM_CONTROLLABLE}
-- ================================================================
-- The @{#AI_CAS_ZONE} class implements the core functions to CAS a @{Zone} by an AIR @{Controllable} @{Group}.
--
-- 1.1) AI_CAS_ZONE constructor:
-- ----------------------------
--
-- * @{#AI_CAS_ZONE.New}(): Creates a new AI_CAS_ZONE object.
--
-- 1.2) AI_CAS_ZONE state machine:
-- ----------------------------------
-- The AI_CAS_ZONE is a state machine: it manages the different events and states of the AIControllable it is controlling.
--
-- ### 1.2.1) AI_CAS_ZONE Events:
--
-- * @{#AI_CAS_ZONE.TakeOff}( AIControllable ): The AI is taking-off from an airfield.
-- * @{#AI_CAS_ZONE.Hold}( AIControllable ): The AI is holding in airspace at a zone.
-- * @{#AI_CAS_ZONE.Engage}( AIControllable ): The AI is engaging the targets.
-- * @{#AI_CAS_ZONE.WeaponReleased}( AIControllable ): The AI has released a weapon to the target.
-- * @{#AI_CAS_ZONE.Destroy}( AIControllable ): The AI has destroyed a target.
-- * @{#AI_CAS_ZONE.Complete}( AIControllable ): The AI has destroyed all defined targets.
-- * @{#AI_CAS_ZONE.RTB}( AIControllable ): The AI is returning to the home base.
--
-- ### 1.2.2) AI_CAS_ZONE States:
--
--
-- ### 1.2.3) AI_CAS_ZONE state transition methods:
--
--
-- 1.3) Manage the AI_CAS_ZONE parameters:
-- ------------------------------------------
-- The following methods are available to modify the parameters of an AI_CAS_ZONE object:
--
-- * @{#AI_CAS_ZONE.SetControllable}(): Set the AIControllable.
-- * @{#AI_CAS_ZONE.GetControllable}(): Get the AIControllable.
--
-- ====
--
-- **API CHANGE HISTORY**
-- ======================
--
-- The underlying change log documents the API changes. Please read this carefully. The following notation is used:
--
-- * **Added** parts are expressed in bold type face.
-- * _Removed_ parts are expressed in italic type face.
--
-- Hereby the change log:
--
-- 2017-01-12: Initial class and API.
--
-- ===
--
-- AUTHORS and CONTRIBUTIONS
-- =========================
--
-- ### Contributions:
--
-- * **Quax**: Concept & Testing.
-- * **Pikey**: Concept & Testing.
--
-- ### Authors:
--
-- * **FlightControl**: Concept, Design & Programming.
--
--
-- @module Cas
--- AI_CAS_ZONE class
-- @type AI_CAS_ZONE
-- @field Wrapper.Controllable#CONTROLLABLE AIControllable The @{Controllable} patrolling.
-- @field Core.Zone#ZONE_BASE TargetZone The @{Zone} where the patrol needs to be executed.
-- @extends AI.AI_Patrol#AI_PATROLZONE
AI_CAS_ZONE = {
ClassName = "AI_CAS_ZONE",
}
--- Creates a new AI_CAS_ZONE object
-- @param #AI_CAS_ZONE self
-- @param Core.Zone#ZONE_BASE PatrolZone The @{Zone} where the patrol needs to be executed.
-- @param Dcs.DCSTypes#Altitude PatrolFloorAltitude The lowest altitude in meters where to execute the patrol.
-- @param Dcs.DCSTypes#Altitude PatrolCeilingAltitude The highest altitude in meters where to execute the patrol.
-- @param Dcs.DCSTypes#Speed PatrolMinSpeed The minimum speed of the @{Controllable} in km/h.
-- @param Dcs.DCSTypes#Speed PatrolMaxSpeed The maximum speed of the @{Controllable} in km/h.
-- @param Core.Zone#ZONE EngageZone
-- @return #AI_CAS_ZONE self
function AI_CAS_ZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed, EngageZone )
-- Inherits from BASE
local self = BASE:Inherit( self, AI_PATROLZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed ) ) -- #AI_CAS_ZONE
self.PatrolZone = PatrolZone
self.PatrolFloorAltitude = PatrolFloorAltitude
self.PatrolCeilingAltitude = PatrolCeilingAltitude
self.PatrolMinSpeed = PatrolMinSpeed
self.PatrolMaxSpeed = PatrolMaxSpeed
self.EngageZone = EngageZone
do self:AddTransition( { "Patrol", "Route", "Engaging" }, "Engage", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
--- OnLeave State Transition for Holding.
-- @function [parent=#AI_CAS_ZONE] OnLeaveHolding
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Engaging.
-- @function [parent=#AI_CAS_ZONE] OnEnterEngaging
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for Engage.
-- @function [parent=#AI_CAS_ZONE] OnBeforeEngage
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Engage.
-- @function [parent=#AI_CAS_ZONE] OnAfterEngage
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- Embedded Event Trigger for Engage.
-- @function [parent=#AI_CAS_ZONE] Engage
-- @param #AI_CAS_ZONE self
--- Delayed Event Trigger for Engage
-- @function [parent=#AI_CAS_ZONE] __Engage
-- @param #AI_CAS_ZONE self
-- @param #number Delay The delay in seconds.
end -- AI_CAS_ZONE
do self:AddTransition( "Engaging", "Fired", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
--- OnLeave State Transition for Engaging.
-- @function [parent=#AI_CAS_ZONE] OnLeaveEngaging
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Engaging.
-- @function [parent=#AI_CAS_ZONE] OnEnterEngaging
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for Fired.
-- @function [parent=#AI_CAS_ZONE] OnBeforeFired
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Fired.
-- @function [parent=#AI_CAS_ZONE] OnAfterFired
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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
--- Embedded Event Trigger for Fired.
-- @function [parent=#AI_CAS_ZONE] Fired
-- @param #AI_CAS_ZONE self
--- Delayed Event Trigger for Fired
-- @function [parent=#AI_CAS_ZONE] __Fired
-- @param #AI_CAS_ZONE self
-- @param #number Delay The delay in seconds.
end -- AI_CAS_ZONE
do self:AddTransition( "Engaging", "Destroy", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
--- OnLeave State Transition for Engaging.
-- @function [parent=#AI_CAS_ZONE] OnLeaveEngaging
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Engaging.
-- @function [parent=#AI_CAS_ZONE] OnEnterEngaging
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for Destroy.
-- @function [parent=#AI_CAS_ZONE] OnBeforeDestroy
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Destroy.
-- @function [parent=#AI_CAS_ZONE] OnAfterDestroy
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- Embedded Event Trigger for Destroy.
-- @function [parent=#AI_CAS_ZONE] Destroy
-- @param #AI_CAS_ZONE self
--- Delayed Event Trigger for Destroy
-- @function [parent=#AI_CAS_ZONE] __Destroy
-- @param #AI_CAS_ZONE self
-- @param #number Delay The delay in seconds.
end -- AI_CAS_ZONE
do self:AddTransition( "Engaging", "Abort", "Patrol" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
--- OnLeave State Transition for Engaging.
-- @function [parent=#AI_CAS_ZONE] OnLeaveEngaging
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Patrol.
-- @function [parent=#AI_CAS_ZONE] OnEnterPatrol
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for Abort.
-- @function [parent=#AI_CAS_ZONE] OnBeforeAbort
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Abort.
-- @function [parent=#AI_CAS_ZONE] OnAfterAbort
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- Embedded Event Trigger for Abort.
-- @function [parent=#AI_CAS_ZONE] Abort
-- @param #AI_CAS_ZONE self
--- Delayed Event Trigger for Abort
-- @function [parent=#AI_CAS_ZONE] __Abort
-- @param #AI_CAS_ZONE self
-- @param #number Delay The delay in seconds.
end -- AI_CAS_ZONE
do self:AddTransition( "Engaging", "Completed", "Patrol" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
--- OnLeave State Transition for Engaging.
-- @function [parent=#AI_CAS_ZONE] OnLeaveEngaging
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Patrol.
-- @function [parent=#AI_CAS_ZONE] OnEnterPatrol
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- OnBefore State Transition for Completed.
-- @function [parent=#AI_CAS_ZONE] OnBeforeCompleted
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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 State Transition for Completed.
-- @function [parent=#AI_CAS_ZONE] OnAfterCompleted
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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.
--- Embedded Event Trigger for Completed.
-- @function [parent=#AI_CAS_ZONE] Completed
-- @param #AI_CAS_ZONE self
--- Delayed Event Trigger for Completed
-- @function [parent=#AI_CAS_ZONE] __Completed
-- @param #AI_CAS_ZONE self
-- @param #number Delay The delay in seconds.
end -- AI_CAS_ZONE
return self
end
--- onafter State Transition for Event Start.
-- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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_CAS_ZONE:onafterStart( Controllable, From, Event, To )
if Controllable:IsAlive() then
self:__Route( 1 )
end
self:EventOnDead( self.OnDead )
Controllable:OptionROEHoldFire()
Controllable:OptionROTVertical()
end
--- @param Wrapper.Controllable#CONTROLLABLE AIControllable
function _NewEngageRoute( AIControllable )
AIControllable:T( "NewEngageRoute" )
local EngageZone = AIControllable:GetState( AIControllable, "EngageZone" ) -- AI.AI_Patrol#AI_PATROLZONE
EngageZone:__Engage( 1 )
end
--- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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_CAS_ZONE:onafterEngage( Controllable, From, Event, To )
if Controllable:IsAlive() then
local EngageRoute = {}
if self.Controllable:IsNotInZone( self.EngageZone ) then
-- Find a random 2D point in EngageZone.
local ToEngageZoneVec2 = self.EngageZone:GetRandomVec2()
self:T2( ToEngageZoneVec2 )
-- Define Speed and Altitude.
local ToEngageZoneAltitude = math.random( self.EngageFloorAltitude, self.EngageCeilingAltitude )
local ToEngageZoneSpeed = self.PatrolMaxSpeed
self:T2( ToEngageZoneSpeed )
-- Obtain a 3D @{Point} from the 2D point + altitude.
local ToEngageZonePointVec3 = POINT_VEC3:New( ToEngageZoneVec2.x, ToEngageZoneAltitude, ToEngageZoneVec2.y )
-- Create a route point of type air.
local ToEngageZoneRoutePoint = ToEngageZonePointVec3:RoutePointAir(
POINT_VEC3.RoutePointAltType.BARO,
POINT_VEC3.RoutePointType.TurningPoint,
POINT_VEC3.RoutePointAction.TurningPoint,
ToEngageZoneSpeed,
true
)
EngageRoute[#EngageRoute+1] = ToEngageZoneRoutePoint
end
--- Define a random point in the @{Zone}. The AI will fly to that point within the zone.
--- Find a random 2D point in EngageZone.
local ToTargetVec2 = self.EngageZone:GetRandomVec2()
self:T2( ToTargetVec2 )
--- Define Speed and Altitude.
local ToTargetAltitude = math.random( self.EngageFloorAltitude, self.EngageCeilingAltitude )
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(
POINT_VEC3.RoutePointAltType.BARO,
POINT_VEC3.RoutePointType.TurningPoint,
POINT_VEC3.RoutePointAction.TurningPoint,
ToTargetSpeed,
true
)
ToTargetPointVec3:SmokeRed()
EngageRoute[#EngageRoute+1] = ToTargetRoutePoint
--- 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( EngageRoute )
--- Do a trick, link the NewEngageRoute function of the PATROLGROUP object to the AIControllable in a temporary variable ...
self.Controllable:SetState( self.Controllable, "EngageZone", self )
self.Controllable:WayPointFunction( #EngageRoute, 1, "_NewEngageRoute" )
--- NOW ROUTE THE GROUP!
self.Controllable:WayPointExecute( 1, 5 )
local DetectedTargets = Controllable:GetDetectedTargets()
for TargetID, Target in pairs( DetectedTargets ) do
local TargetObject = Target.object
self:T( TargetObject )
if TargetObject and TargetObject:isExist() and TargetObject.id_ < 50000000 then
local TargetUnit = UNIT:Find( TargetObject )
local TargetUnitName = TargetUnit:GetName()
if TargetUnit:IsInZone( self.EngageZone ) then
--local EngageTask = Controllable:EnRouteTaskEngageUnit( TargetUnit, 1 )
local EngageTask = Controllable:TaskAttackUnit( TargetUnit )
Controllable:PushTask( EngageTask, 1 )
end
end
end
Controllable:OptionROEWeaponFree()
Controllable:OptionROTPassiveDefense()
end
end
--- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable 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_CAS_ZONE:onafterDestroy( Controllable, From, Event, To )
Controllable:MessageToAll( "Destroyed a target", 15 , "Destroyed!" )
end
--- @param #AI_CAS_ZONE self
-- @param Core.Event#EVENTDATA EventData
function AI_CAS_ZONE:OnDead( EventData )
self:T( { "EventDead", EventData } )
if EventData.IniDCSUnit then
self:__Destroy( 1, EventData )
end
end
--- (SP) (MP) (FSM) Accept or reject process for player (task) assignments. --- (SP) (MP) (FSM) Accept or reject process for player (task) assignments.
-- --
-- === -- ===
@ -29882,6 +30544,7 @@ Include.File( "Functional/Detection" )
Include.File( "AI/AI_Balancer" ) Include.File( "AI/AI_Balancer" )
Include.File( "AI/AI_Patrol" ) Include.File( "AI/AI_Patrol" )
Include.File( "AI/AI_Cargo" ) Include.File( "AI/AI_Cargo" )
Include.File( "AI/AI_Cas" )
--- Actions --- Actions
Include.File( "Actions/Act_Assign" ) Include.File( "Actions/Act_Assign" )

View File

@ -81,6 +81,7 @@ rem AI Classes
COPY /b Moose.lua + %1\AI\AI_Balancer.lua Moose.lua COPY /b Moose.lua + %1\AI\AI_Balancer.lua Moose.lua
COPY /b Moose.lua + %1\AI\AI_Patrol.lua Moose.lua COPY /b Moose.lua + %1\AI\AI_Patrol.lua Moose.lua
COPY /b Moose.lua + %1\AI\AI_Cargo.lua Moose.lua COPY /b Moose.lua + %1\AI\AI_Cargo.lua Moose.lua
COPY /b Moose.lua + %1\AI\AI_CAS.lua Moose.lua
rem Actions rem Actions

View File

@ -0,0 +1,37 @@
-- Name: CAS in a ZONE
-- Author: FlightControl
-- Date Created: 13 January 2017
--
-- # Situation:
--
-- # Test cases:
--
local CASEngagementZone = ZONE:New( "Engagement Zone" )
local CASPlane = GROUP:FindByName( "Plane" )
local PatrolZone = ZONE:New( "Patrol Zone" )
local AICasZone = AI_CAS_ZONE:New( PatrolZone, 500, 1000, 350, 600, CASEngagementZone )
local Targets = GROUP:FindByName("Targets")
AICasZone:SetControllable(CASPlane)
AICasZone:__Start(1)
AICasZone:__Engage(10)
-- Check every 60 seconds whether the Targets have been eliminated.
-- When the trigger completed has been fired, the Plane will go back to the Patrol Zone.
Check = SCHEDULER:New(nil,
function()
BASE:E( { "In Scheduler: ", Targets:GetSize() } )
if Targets:IsAlive() and Targets:GetSize() ~= 0 then
BASE:E("Still alive")
else
BASE:E("Destroyed")
AICasZone:__Completed(1)
end
end, {}, 20, 60, 0.2 )