diff --git a/Moose Development/Moose/AI/AI_CAS.lua b/Moose Development/Moose/AI/AI_CAS.lua index 50e4009be..99405281d 100644 --- a/Moose Development/Moose/AI/AI_CAS.lua +++ b/Moose Development/Moose/AI/AI_CAS.lua @@ -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.Hold}( AIControllable ): The AI is holding in airspace at a zone. --- * @{#AI_CAS.Engage}( AIControllable ): The AI is engaging the targets. --- * @{#AI_CAS.WeaponReleased}( AIControllable ): The AI has released a weapon to the target. --- * @{#AI_CAS.Destroy}( AIControllable ): The AI has destroyed a target. --- * @{#AI_CAS.Complete}( AIControllable ): The AI has destroyed all defined targets. --- * @{#AI_CAS.RTB}( AIControllable ): The AI is returning to the home base. +-- * @{#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 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.GetControllable}(): Get the AIControllable. +-- * @{#AI_CAS_ZONE.SetControllable}(): Set the AIControllable. +-- * @{#AI_CAS_ZONE.GetControllable}(): Get the AIControllable. -- -- ==== -- @@ -70,181 +70,44 @@ -- @module Cas ---- AI_CAS class --- @type AI_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 Core.Fsm#FSM_CONTROLLABLE -AI_CAS = { - ClassName = "AI_CAS", +-- @extends AI.AI_Patrol#AI_PATROLZONE +AI_CAS_ZONE = { + ClassName = "AI_CAS_ZONE", } ---- Creates a new AI_CAS object. --- @param #AI_CAS self --- @param Wrapper.Controllable#CONTROLLABLE Ct --- @param Core.Zone#ZONE_BASE TargetZone The @{Zone} where the CAS needs to be executed. --- @param Core.Set#SET_UNIT TargetSet The @{Set} of units to be destroyed. --- @return #AI_CAS The new AI_CAS object. -function AI_CAS:New( Ct, TargetZone, TargetSet ) +--- 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, FSM_CONTROLLABLE:New() ) -- #AI_CAS + local self = BASE:Inherit( self, AI_PATROLZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed ) ) -- #AI_CAS_ZONE - self:SetStartState( "None" ) - - env.info( Ct ) - - do self:AddTransition( "*", "TakeOff", "RTH" ) -- 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 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. + 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] OnLeaveHolding - -- @param #AI_CAS self + -- @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. @@ -252,16 +115,16 @@ function AI_CAS:New( Ct, TargetZone, TargetSet ) -- @return #boolean Return false to cancel Transition. --- OnEnter State Transition for Engaging. - -- @function [parent=#AI_CAS] OnEnterEngaging - -- @param #AI_CAS self + -- @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] OnBeforeEngage - -- @param #AI_CAS self + -- @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. @@ -269,29 +132,30 @@ function AI_CAS:New( Ct, TargetZone, TargetSet ) -- @return #boolean Return false to cancel Transition. --- OnAfter State Transition for Engage. - -- @function [parent=#AI_CAS] OnAfterEngage - -- @param #AI_CAS self + -- @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] Engage - -- @param #AI_CAS self + -- @function [parent=#AI_CAS_ZONE] Engage + -- @param #AI_CAS_ZONE self --- Delayed Event Trigger for Engage - -- @function [parent=#AI_CAS] __Engage - -- @param #AI_CAS self + -- @function [parent=#AI_CAS_ZONE] __Engage + -- @param #AI_CAS_ZONE self -- @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. - -- @function [parent=#AI_CAS] OnLeaveEngaging - -- @param #AI_CAS self + -- @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. @@ -299,16 +163,16 @@ function AI_CAS:New( Ct, TargetZone, TargetSet ) -- @return #boolean Return false to cancel Transition. --- OnEnter State Transition for Engaging. - -- @function [parent=#AI_CAS] OnEnterEngaging - -- @param #AI_CAS self + -- @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] OnBeforeFired - -- @param #AI_CAS self + -- @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. @@ -316,8 +180,8 @@ function AI_CAS:New( Ct, TargetZone, TargetSet ) -- @return #boolean Return false to cancel Transition. --- OnAfter State Transition for Fired. - -- @function [parent=#AI_CAS] OnAfterFired - -- @param #AI_CAS self + -- @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. @@ -325,21 +189,21 @@ function AI_CAS:New( Ct, TargetZone, TargetSet ) -- @return #boolean --- Embedded Event Trigger for Fired. - -- @function [parent=#AI_CAS] Fired - -- @param #AI_CAS self + -- @function [parent=#AI_CAS_ZONE] Fired + -- @param #AI_CAS_ZONE self --- Delayed Event Trigger for Fired - -- @function [parent=#AI_CAS] __Fired - -- @param #AI_CAS self + -- @function [parent=#AI_CAS_ZONE] __Fired + -- @param #AI_CAS_ZONE self -- @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. - -- @function [parent=#AI_CAS] OnLeaveEngaging - -- @param #AI_CAS self + -- @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. @@ -347,16 +211,16 @@ function AI_CAS:New( Ct, TargetZone, TargetSet ) -- @return #boolean Return false to cancel Transition. --- OnEnter State Transition for Engaging. - -- @function [parent=#AI_CAS] OnEnterEngaging - -- @param #AI_CAS self + -- @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] OnBeforeDestroy - -- @param #AI_CAS self + -- @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. @@ -364,221 +228,268 @@ function AI_CAS:New( Ct, TargetZone, TargetSet ) -- @return #boolean Return false to cancel Transition. --- OnAfter State Transition for Destroy. - -- @function [parent=#AI_CAS] OnAfterDestroy - -- @param #AI_CAS self + -- @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] Destroy - -- @param #AI_CAS self + -- @function [parent=#AI_CAS_ZONE] Destroy + -- @param #AI_CAS_ZONE self --- Delayed Event Trigger for Destroy - -- @function [parent=#AI_CAS] __Destroy - -- @param #AI_CAS self + -- @function [parent=#AI_CAS_ZONE] __Destroy + -- @param #AI_CAS_ZONE self -- @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. - -- @function [parent=#AI_CAS] OnLeaveEngaging - -- @param #AI_CAS self + --- 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 Holding. - -- @function [parent=#AI_CAS] OnEnterHolding - -- @param #AI_CAS self + + --- 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] OnBeforeAbort - -- @param #AI_CAS self + + --- 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 Abort. - -- @function [parent=#AI_CAS] OnAfterAbort - -- @param #AI_CAS self + + --- 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 Abort. - -- @function [parent=#AI_CAS] Abort - -- @param #AI_CAS self - - --- Delayed Event Trigger for Abort - -- @function [parent=#AI_CAS] __Abort - -- @param #AI_CAS self + + --- 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 - - - 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 - + + 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 + + diff --git a/Moose Development/Moose/AI/AI_Patrol.lua b/Moose Development/Moose/AI/AI_Patrol.lua index cd517e450..ed76c1fc8 100644 --- a/Moose Development/Moose/AI/AI_Patrol.lua +++ b/Moose Development/Moose/AI/AI_Patrol.lua @@ -130,22 +130,7 @@ -- * **FlightControl**: Design & Programming. -- -- --- @module 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 - - +-- @module AI_Patrol --- AI_PATROLZONE class -- @type AI_PATROLZONE @@ -180,20 +165,206 @@ function AI_PATROLZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitu -- Inherits from BASE 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.PatrolCeilingAltitude = PatrolCeilingAltitude self.PatrolMinSpeed = PatrolMinSpeed 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 end diff --git a/Moose Development/Moose/Moose.lua b/Moose Development/Moose/Moose.lua index 32b309b3b..710bc0da7 100644 --- a/Moose Development/Moose/Moose.lua +++ b/Moose Development/Moose/Moose.lua @@ -43,6 +43,7 @@ Include.File( "Functional/Detection" ) Include.File( "AI/AI_Balancer" ) Include.File( "AI/AI_Patrol" ) Include.File( "AI/AI_Cargo" ) +Include.File( "AI/AI_Cas" ) --- Actions Include.File( "Actions/Act_Assign" ) diff --git a/Moose Development/Moose/Wrapper/Controllable.lua b/Moose Development/Moose/Wrapper/Controllable.lua index 3a39ef887..1ba317318 100644 --- a/Moose Development/Moose/Wrapper/Controllable.lua +++ b/Moose Development/Moose/Wrapper/Controllable.lua @@ -126,6 +126,7 @@ --- The CONTROLLABLE class -- @type CONTROLLABLE +-- @extends Wrapper.Positionable#POSITIONABLE -- @field Dcs.DCSWrapper.Controllable#Controllable DCSControllable The DCS controllable class. -- @field #string ControllableName The name of the controllable. CONTROLLABLE = { diff --git a/Moose Development/Moose/Wrapper/Identifiable.lua b/Moose Development/Moose/Wrapper/Identifiable.lua index 19b0d6c14..c11b5cee7 100644 --- a/Moose Development/Moose/Wrapper/Identifiable.lua +++ b/Moose Development/Moose/Wrapper/Identifiable.lua @@ -28,7 +28,7 @@ -- -- === -- --- @module Wrapper.Identifiable +-- @module Identifiable --- The IDENTIFIABLE class -- @type IDENTIFIABLE diff --git a/Moose Development/Moose/Wrapper/Object.lua b/Moose Development/Moose/Wrapper/Object.lua index 1215e004f..14650e584 100644 --- a/Moose Development/Moose/Wrapper/Object.lua +++ b/Moose Development/Moose/Wrapper/Object.lua @@ -22,7 +22,7 @@ -- -- === -- --- @module Wrapper.Object +-- @module Object --- The OBJECT class -- @type OBJECT diff --git a/Moose Development/Moose/Wrapper/Positionable.lua b/Moose Development/Moose/Wrapper/Positionable.lua index d9219fcf5..696f64c10 100644 --- a/Moose Development/Moose/Wrapper/Positionable.lua +++ b/Moose Development/Moose/Wrapper/Positionable.lua @@ -23,7 +23,7 @@ -- -- === -- --- @module Wrapper.Positionable +-- @module Positionable --- The POSITIONABLE class -- @type POSITIONABLE diff --git a/Moose Mission Setup/Moose Mission Update/l10n/DEFAULT/Moose.lua b/Moose Mission Setup/Moose Mission Update/l10n/DEFAULT/Moose.lua index 07060d824..20365da69 100644 --- a/Moose Mission Setup/Moose Mission Update/l10n/DEFAULT/Moose.lua +++ b/Moose Mission Setup/Moose Mission Update/l10n/DEFAULT/Moose.lua @@ -1,5 +1,5 @@ env.info( '*** MOOSE STATIC INCLUDE START *** ' ) -env.info( 'Moose Generation Timestamp: 20170112_1219' ) +env.info( 'Moose Generation Timestamp: 20170113_1404' ) local base = _G Include = {} @@ -11769,7 +11769,6 @@ end -- FSM_SET -- === -- -- @module Object --- @author FlightControl --- The OBJECT class -- @type OBJECT @@ -11864,7 +11863,6 @@ end -- === -- -- @module Identifiable --- @author FlightControl --- The IDENTIFIABLE class -- @type IDENTIFIABLE @@ -12086,7 +12084,6 @@ end -- === -- -- @module Positionable --- @author FlightControl --- The POSITIONABLE class -- @type POSITIONABLE @@ -12608,7 +12605,6 @@ end -- === -- -- @module Controllable --- @author FlightControl --- The CONTROLLABLE class -- @type CONTROLLABLE @@ -24644,22 +24640,7 @@ end -- * **FlightControl**: Design & Programming. -- -- --- @module 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 - - +-- @module AI_Patrol --- AI_PATROLZONE class -- @type AI_PATROLZONE @@ -24694,20 +24675,206 @@ function AI_PATROLZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitu -- Inherits from BASE 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.PatrolCeilingAltitude = PatrolCeilingAltitude self.PatrolMinSpeed = PatrolMinSpeed 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 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. -- -- === @@ -29882,6 +30544,7 @@ Include.File( "Functional/Detection" ) Include.File( "AI/AI_Balancer" ) Include.File( "AI/AI_Patrol" ) Include.File( "AI/AI_Cargo" ) +Include.File( "AI/AI_Cas" ) --- Actions Include.File( "Actions/Act_Assign" ) diff --git a/Moose Mission Setup/Moose.lua b/Moose Mission Setup/Moose.lua index 07060d824..20365da69 100644 --- a/Moose Mission Setup/Moose.lua +++ b/Moose Mission Setup/Moose.lua @@ -1,5 +1,5 @@ env.info( '*** MOOSE STATIC INCLUDE START *** ' ) -env.info( 'Moose Generation Timestamp: 20170112_1219' ) +env.info( 'Moose Generation Timestamp: 20170113_1404' ) local base = _G Include = {} @@ -11769,7 +11769,6 @@ end -- FSM_SET -- === -- -- @module Object --- @author FlightControl --- The OBJECT class -- @type OBJECT @@ -11864,7 +11863,6 @@ end -- === -- -- @module Identifiable --- @author FlightControl --- The IDENTIFIABLE class -- @type IDENTIFIABLE @@ -12086,7 +12084,6 @@ end -- === -- -- @module Positionable --- @author FlightControl --- The POSITIONABLE class -- @type POSITIONABLE @@ -12608,7 +12605,6 @@ end -- === -- -- @module Controllable --- @author FlightControl --- The CONTROLLABLE class -- @type CONTROLLABLE @@ -24644,22 +24640,7 @@ end -- * **FlightControl**: Design & Programming. -- -- --- @module 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 - - +-- @module AI_Patrol --- AI_PATROLZONE class -- @type AI_PATROLZONE @@ -24694,20 +24675,206 @@ function AI_PATROLZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitu -- Inherits from BASE 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.PatrolCeilingAltitude = PatrolCeilingAltitude self.PatrolMinSpeed = PatrolMinSpeed 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 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. -- -- === @@ -29882,6 +30544,7 @@ Include.File( "Functional/Detection" ) Include.File( "AI/AI_Balancer" ) Include.File( "AI/AI_Patrol" ) Include.File( "AI/AI_Cargo" ) +Include.File( "AI/AI_Cas" ) --- Actions Include.File( "Actions/Act_Assign" ) diff --git a/Moose Mission Setup/Moose_Create.bat b/Moose Mission Setup/Moose_Create.bat index 151558dbe..9ef11dac0 100644 --- a/Moose Mission Setup/Moose_Create.bat +++ b/Moose Mission Setup/Moose_Create.bat @@ -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_Patrol.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 diff --git a/Moose Test Missions/CAS - Close Air Support/CAS-001 - CAS in a ZONE/CAS-001 - CAS in a ZONE.lua b/Moose Test Missions/CAS - Close Air Support/CAS-001 - CAS in a ZONE/CAS-001 - CAS in a ZONE.lua new file mode 100644 index 000000000..30c25eb7e --- /dev/null +++ b/Moose Test Missions/CAS - Close Air Support/CAS-001 - CAS in a ZONE/CAS-001 - CAS in a ZONE.lua @@ -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 ) + + + diff --git a/Moose Test Missions/CAS - Close Air Support/CAS-001 - CAS in a ZONE/CAS-001 - CAS in a ZONE.miz b/Moose Test Missions/CAS - Close Air Support/CAS-001 - CAS in a ZONE/CAS-001 - CAS in a ZONE.miz new file mode 100644 index 000000000..cf78acaad Binary files /dev/null and b/Moose Test Missions/CAS - Close Air Support/CAS-001 - CAS in a ZONE/CAS-001 - CAS in a ZONE.miz differ