diff --git a/Moose Development/Moose/AI/AI_CAS.lua b/Moose Development/Moose/AI/AI_CAS.lua new file mode 100644 index 000000000..99405281d --- /dev/null +++ b/Moose Development/Moose/AI/AI_CAS.lua @@ -0,0 +1,495 @@ +--- 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 + + 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/Functional/Scoring.lua b/Moose Development/Moose/Functional/Scoring.lua index 3d1292c74..40e3496b9 100644 --- a/Moose Development/Moose/Functional/Scoring.lua +++ b/Moose Development/Moose/Functional/Scoring.lua @@ -436,7 +436,7 @@ function SCORING:_EventOnHit( Event ) ):ToAll() self:ScoreCSV( InitPlayerName, "HIT_PENALTY", 1, -25, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType ) else - self.Players[InitPlayerName].Score = self.Players[InitPlayerName].Score + 10 + self.Players[InitPlayerName].Score = self.Players[InitPlayerName].Score + 1 self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].Score = self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].Score + 1 self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].ScoreHit = self.Players[InitPlayerName].Hit[TargetCategory][TargetUnitName].ScoreHit + 1 MESSAGE:New( "Player '" .. InitPlayerName .. "' hit a target " .. TargetUnitCategory .. " ( " .. TargetType .. " ) " .. 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 bf94e2e05..1ba317318 100644 --- a/Moose Development/Moose/Wrapper/Controllable.lua +++ b/Moose Development/Moose/Wrapper/Controllable.lua @@ -123,7 +123,6 @@ -- === -- -- @module Controllable --- @author FlightControl --- The CONTROLLABLE class -- @type CONTROLLABLE diff --git a/Moose Development/Moose/Wrapper/Identifiable.lua b/Moose Development/Moose/Wrapper/Identifiable.lua index 34f87b25a..c11b5cee7 100644 --- a/Moose Development/Moose/Wrapper/Identifiable.lua +++ b/Moose Development/Moose/Wrapper/Identifiable.lua @@ -29,7 +29,6 @@ -- === -- -- @module Identifiable --- @author FlightControl --- The IDENTIFIABLE class -- @type IDENTIFIABLE diff --git a/Moose Development/Moose/Wrapper/Object.lua b/Moose Development/Moose/Wrapper/Object.lua index ed00a0cfe..14650e584 100644 --- a/Moose Development/Moose/Wrapper/Object.lua +++ b/Moose Development/Moose/Wrapper/Object.lua @@ -23,7 +23,6 @@ -- === -- -- @module Object --- @author FlightControl --- The OBJECT class -- @type OBJECT diff --git a/Moose Development/Moose/Wrapper/Positionable.lua b/Moose Development/Moose/Wrapper/Positionable.lua index e011f6f8c..696f64c10 100644 --- a/Moose Development/Moose/Wrapper/Positionable.lua +++ b/Moose Development/Moose/Wrapper/Positionable.lua @@ -24,7 +24,6 @@ -- === -- -- @module Positionable --- @author FlightControl --- 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 544390cf6..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_1201' ) +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 544390cf6..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_1201' ) +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/AIB - AI Balancing/AIB-006 - Declutter AI at Airbases/AIB-006 - Declutter AI at Airbases.lua b/Moose Test Missions/AIB - AI Balancing/AIB-006 - Declutter AI at Airbases/AIB-006 - Declutter AI at Airbases.lua index c04dc441f..650aca254 100644 --- a/Moose Test Missions/AIB - AI Balancing/AIB-006 - Declutter AI at Airbases/AIB-006 - Declutter AI at Airbases.lua +++ b/Moose Test Missions/AIB - AI Balancing/AIB-006 - Declutter AI at Airbases/AIB-006 - Declutter AI at Airbases.lua @@ -24,7 +24,7 @@ local RU_PlanesClientSet = SET_CLIENT:New():FilterCountries( "RUSSIA" ):FilterCa -- Define the SPAWN object for the red AI plane template. -- We use InitCleanUp to check every 20 seconds, if there are no planes blocked at the airbase, waithing for take-off. -- If a blocked plane exists, this red plane will be ReSpawned. -local RU_PlanesSpawn = SPAWN:New( "AI RU" ):InitCleanUp( 60 ) +local RU_PlanesSpawn = SPAWN:New( "AI RU" ):InitCleanUp( 20 ) -- Start the AI_BALANCER, using the SET of red CLIENTs, and the SPAWN object as a parameter. local RU_AI_Balancer = AI_BALANCER:New( RU_PlanesClientSet, RU_PlanesSpawn ) 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