mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Publish new release
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- 1) @{#PATROLZONE} class, extends @{Core.Fsm#FSM_CONTROLLABLE}
|
||||
-- 1) @{#AI_PATROLZONE} class, extends @{Core.Fsm#FSM_CONTROLLABLE}
|
||||
-- ================================================================
|
||||
-- The @{#PATROLZONE} class implements the core functions to patrol a @{Zone} by an AIR @{Controllable} @{Group}.
|
||||
-- The @{#AI_PATROLZONE} class implements the core functions to patrol a @{Zone} by an AIR @{Controllable} @{Group}.
|
||||
-- The patrol algorithm works that for each airplane patrolling, upon arrival at the patrol zone,
|
||||
-- a random point is selected as the route point within the 3D space, within the given boundary limits.
|
||||
-- The airplane will fly towards the random 3D point within the patrol zone, using a random speed within the given altitude and speed limits.
|
||||
@@ -12,24 +12,24 @@
|
||||
-- This cycle will continue until a fuel treshold has been reached by the airplane.
|
||||
-- When the fuel treshold has been reached, the airplane will fly towards the nearest friendly airbase and will land.
|
||||
--
|
||||
-- 1.1) PATROLZONE constructor:
|
||||
-- 1.1) AI_PATROLZONE constructor:
|
||||
-- ----------------------------
|
||||
--
|
||||
-- * @{#PATROLZONE.New}(): Creates a new PATROLZONE object.
|
||||
-- * @{#AI_PATROLZONE.New}(): Creates a new AI_PATROLZONE object.
|
||||
--
|
||||
-- 1.2) PATROLZONE state machine:
|
||||
-- 1.2) AI_PATROLZONE state machine:
|
||||
-- ----------------------------------
|
||||
-- The PATROLZONE is a state machine: it manages the different events and states of the AIControllable it is controlling.
|
||||
-- The AI_PATROLZONE is a state machine: it manages the different events and states of the AIControllable it is controlling.
|
||||
--
|
||||
-- ### 1.2.1) PATROLZONE Events:
|
||||
-- ### 1.2.1) AI_PATROLZONE Events:
|
||||
--
|
||||
-- * @{#PATROLZONE.Route}( AIControllable ): A new 3D route point is selected and the AIControllable will fly towards that point with the given speed.
|
||||
-- * @{#PATROLZONE.Patrol}( AIControllable ): The AIControllable reports it is patrolling. This event is called every 30 seconds.
|
||||
-- * @{#PATROLZONE.RTB}( AIControllable ): The AIControllable will report return to base.
|
||||
-- * @{#PATROLZONE.End}( AIControllable ): The end of the PATROLZONE process.
|
||||
-- * @{#PATROLZONE.Dead}( AIControllable ): The AIControllable is dead. The PATROLZONE process will be ended.
|
||||
-- * @{#AI_PATROLZONE.Route}( AIControllable ): A new 3D route point is selected and the AIControllable will fly towards that point with the given speed.
|
||||
-- * @{#AI_PATROLZONE.Patrol}( AIControllable ): The AIControllable reports it is patrolling. This event is called every 30 seconds.
|
||||
-- * @{#AI_PATROLZONE.RTB}( AIControllable ): The AIControllable will report return to base.
|
||||
-- * @{#AI_PATROLZONE.End}( AIControllable ): The end of the AI_PATROLZONE process.
|
||||
-- * @{#AI_PATROLZONE.Dead}( AIControllable ): The AIControllable is dead. The AI_PATROLZONE process will be ended.
|
||||
--
|
||||
-- ### 1.2.2) PATROLZONE States:
|
||||
-- ### 1.2.2) AI_PATROLZONE States:
|
||||
--
|
||||
-- * **Route**: A new 3D route point is selected and the AIControllable will fly towards that point with the given speed.
|
||||
-- * **Patrol**: The AIControllable is patrolling. This state is set every 30 seconds, so every 30 seconds, a state transition method can be used.
|
||||
@@ -37,7 +37,7 @@
|
||||
-- * **Dead**: The AIControllable is dead ...
|
||||
-- * **End**: The process has come to an end.
|
||||
--
|
||||
-- ### 1.2.3) PATROLZONE state transition methods:
|
||||
-- ### 1.2.3) AI_PATROLZONE state transition methods:
|
||||
--
|
||||
-- State transition functions can be set **by the mission designer** customizing or improving the behaviour of the state.
|
||||
-- There are 2 moments when state transition methods will be called by the state machine:
|
||||
@@ -52,7 +52,7 @@
|
||||
-- The state transition method needs to start with the name **OnAfter + the name of the state**.
|
||||
-- These state transition methods need to provide a return value, which is specified at the function description.
|
||||
--
|
||||
-- An example how to manage a state transition for an PATROLZONE object **Patrol** for the state **RTB**:
|
||||
-- An example how to manage a state transition for an AI_PATROLZONE object **Patrol** for the state **RTB**:
|
||||
--
|
||||
-- local PatrolZoneGroup = GROUP:FindByName( "Patrol Zone" )
|
||||
-- local PatrolZone = ZONE_POLYGON:New( "PatrolZone", PatrolZoneGroup )
|
||||
@@ -60,46 +60,46 @@
|
||||
-- local PatrolSpawn = SPAWN:New( "Patrol Group" )
|
||||
-- local PatrolGroup = PatrolSpawn:Spawn()
|
||||
--
|
||||
-- local Patrol = PATROLZONE:New( PatrolZone, 3000, 6000, 300, 600 )
|
||||
-- local Patrol = AI_PATROLZONE:New( PatrolZone, 3000, 6000, 300, 600 )
|
||||
-- Patrol:SetControllable( PatrolGroup )
|
||||
-- Patrol:ManageFuel( 0.2, 60 )
|
||||
--
|
||||
-- **OnBefore**RTB( AIGroup ) will be called by the PATROLZONE object when the AIGroup reports RTB, but **before** the RTB default action is processed by the PATROLZONE object.
|
||||
-- **OnBefore**RTB( AIGroup ) will be called by the AI_PATROLZONE object when the AIGroup reports RTB, but **before** the RTB default action is processed by the AI_PATROLZONE object.
|
||||
--
|
||||
-- --- State transition function for the PATROLZONE **Patrol** object
|
||||
-- -- @param #PATROLZONE self
|
||||
-- --- State transition function for the AI_PATROLZONE **Patrol** object
|
||||
-- -- @param #AI_PATROLZONE self
|
||||
-- -- @param Wrapper.Controllable#CONTROLLABLE AIGroup
|
||||
-- -- @return #boolean If false is returned, then the OnAfter state transition method will not be called.
|
||||
-- function Patrol:OnBeforeRTB( AIGroup )
|
||||
-- AIGroup:MessageToRed( "Returning to base", 20 )
|
||||
-- end
|
||||
--
|
||||
-- **OnAfter**RTB( AIGroup ) will be called by the PATROLZONE object when the AIGroup reports RTB, but **after** the RTB default action was processed by the PATROLZONE object.
|
||||
-- **OnAfter**RTB( AIGroup ) will be called by the AI_PATROLZONE object when the AIGroup reports RTB, but **after** the RTB default action was processed by the AI_PATROLZONE object.
|
||||
--
|
||||
-- --- State transition function for the PATROLZONE **Patrol** object
|
||||
-- -- @param #PATROLZONE self
|
||||
-- --- State transition function for the AI_PATROLZONE **Patrol** object
|
||||
-- -- @param #AI_PATROLZONE self
|
||||
-- -- @param Wrapper.Controllable#CONTROLLABLE AIGroup
|
||||
-- -- @return #Wrapper.Controllable#CONTROLLABLE The new AIGroup object that is set to be patrolling the zone.
|
||||
-- function Patrol:OnAfterRTB( AIGroup )
|
||||
-- return PatrolSpawn:Spawn()
|
||||
-- end
|
||||
--
|
||||
-- 1.3) Manage the PATROLZONE parameters:
|
||||
-- 1.3) Manage the AI_PATROLZONE parameters:
|
||||
-- ------------------------------------------
|
||||
-- The following methods are available to modify the parameters of a PATROLZONE object:
|
||||
-- The following methods are available to modify the parameters of a AI_PATROLZONE object:
|
||||
--
|
||||
-- * @{#PATROLZONE.SetControllable}(): Set the AIControllable.
|
||||
-- * @{#PATROLZONE.GetControllable}(): Get the AIControllable.
|
||||
-- * @{#PATROLZONE.SetSpeed}(): Set the patrol speed of the AI, for the next patrol.
|
||||
-- * @{#PATROLZONE.SetAltitude}(): Set altitude of the AI, for the next patrol.
|
||||
-- * @{#AI_PATROLZONE.SetControllable}(): Set the AIControllable.
|
||||
-- * @{#AI_PATROLZONE.GetControllable}(): Get the AIControllable.
|
||||
-- * @{#AI_PATROLZONE.SetSpeed}(): Set the patrol speed of the AI, for the next patrol.
|
||||
-- * @{#AI_PATROLZONE.SetAltitude}(): Set altitude of the AI, for the next patrol.
|
||||
--
|
||||
-- 1.3) Manage the out of fuel in the PATROLZONE:
|
||||
-- 1.3) Manage the out of fuel in the AI_PATROLZONE:
|
||||
-- ----------------------------------------------
|
||||
-- When the AIControllable is out of fuel, it is required that a new AIControllable is started, before the old AIControllable can return to the home base.
|
||||
-- Therefore, with a parameter and a calculation of the distance to the home base, the fuel treshold is calculated.
|
||||
-- When the fuel treshold is reached, the AIControllable will continue for a given time its patrol task in orbit, while a new AIControllable is targetted to the PATROLZONE.
|
||||
-- When the fuel treshold is reached, the AIControllable will continue for a given time its patrol task in orbit, while a new AIControllable is targetted to the AI_PATROLZONE.
|
||||
-- Once the time is finished, the old AIControllable will return to the base.
|
||||
-- Use the method @{#PATROLZONE.ManageFuel}() to have this proces in place.
|
||||
-- Use the method @{#AI_PATROLZONE.ManageFuel}() to have this proces in place.
|
||||
--
|
||||
-- ====
|
||||
--
|
||||
@@ -135,20 +135,20 @@
|
||||
-- State Transition Functions
|
||||
|
||||
--- OnBefore State Transition Function
|
||||
-- @function [parent=#PATROLZONE] OnBeforeRoute
|
||||
-- @param #PATROLZONE self
|
||||
-- @function [parent=#AI_PATROLZONE] OnBeforeRoute
|
||||
-- @param #AI_PATROLZONE self
|
||||
-- @param Wrapper.Controllable#CONTROLLABLE Controllable
|
||||
-- @return #boolean
|
||||
|
||||
--- OnAfter State Transition Function
|
||||
-- @function [parent=#PATROLZONE] OnAfterRoute
|
||||
-- @param #PATROLZONE self
|
||||
-- @function [parent=#AI_PATROLZONE] OnAfterRoute
|
||||
-- @param #AI_PATROLZONE self
|
||||
-- @param Wrapper.Controllable#CONTROLLABLE Controllable
|
||||
|
||||
|
||||
|
||||
--- PATROLZONE class
|
||||
-- @type PATROLZONE
|
||||
--- AI_PATROLZONE class
|
||||
-- @type AI_PATROLZONE
|
||||
-- @field Wrapper.Controllable#CONTROLLABLE AIControllable The @{Controllable} patrolling.
|
||||
-- @field Core.Zone#ZONE_BASE PatrolZone The @{Zone} where the patrol needs to be executed.
|
||||
-- @field Dcs.DCSTypes#Altitude PatrolFloorAltitude The lowest altitude in meters where to execute the patrol.
|
||||
@@ -156,26 +156,26 @@
|
||||
-- @field Dcs.DCSTypes#Speed PatrolMinSpeed The minimum speed of the @{Controllable} in km/h.
|
||||
-- @field Dcs.DCSTypes#Speed PatrolMaxSpeed The maximum speed of the @{Controllable} in km/h.
|
||||
-- @extends Core.Fsm#FSM_CONTROLLABLE
|
||||
PATROLZONE = {
|
||||
ClassName = "PATROLZONE",
|
||||
AI_PATROLZONE = {
|
||||
ClassName = "AI_PATROLZONE",
|
||||
}
|
||||
|
||||
|
||||
|
||||
--- Creates a new PATROLZONE object
|
||||
-- @param #PATROLZONE self
|
||||
--- Creates a new AI_PATROLZONE object
|
||||
-- @param #AI_PATROLZONE 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.
|
||||
-- @return #PATROLZONE self
|
||||
-- @return #AI_PATROLZONE self
|
||||
-- @usage
|
||||
-- -- Define a new PATROLZONE Object. This PatrolArea will patrol an AIControllable within PatrolZone between 3000 and 6000 meters, with a variying speed between 600 and 900 km/h.
|
||||
-- -- Define a new AI_PATROLZONE Object. This PatrolArea will patrol an AIControllable within PatrolZone between 3000 and 6000 meters, with a variying speed between 600 and 900 km/h.
|
||||
-- PatrolZone = ZONE:New( 'PatrolZone' )
|
||||
-- PatrolSpawn = SPAWN:New( 'Patrol Group' )
|
||||
-- PatrolArea = PATROLZONE:New( PatrolZone, 3000, 6000, 600, 900 )
|
||||
function PATROLZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed )
|
||||
-- PatrolArea = AI_PATROLZONE:New( PatrolZone, 3000, 6000, 600, 900 )
|
||||
function AI_PATROLZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed )
|
||||
|
||||
-- Inherits from BASE
|
||||
local self = BASE:Inherit( self, FSM_CONTROLLABLE:New() ) -- Core.Fsm#FSM_CONTROLLABLE
|
||||
@@ -201,11 +201,11 @@ end
|
||||
|
||||
|
||||
--- Sets (modifies) the minimum and maximum speed of the patrol.
|
||||
-- @param #PATROLZONE self
|
||||
-- @param #AI_PATROLZONE self
|
||||
-- @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.
|
||||
-- @return #PATROLZONE self
|
||||
function PATROLZONE:SetSpeed( PatrolMinSpeed, PatrolMaxSpeed )
|
||||
-- @return #AI_PATROLZONE self
|
||||
function AI_PATROLZONE:SetSpeed( PatrolMinSpeed, PatrolMaxSpeed )
|
||||
self:F2( { PatrolMinSpeed, PatrolMaxSpeed } )
|
||||
|
||||
self.PatrolMinSpeed = PatrolMinSpeed
|
||||
@@ -215,11 +215,11 @@ end
|
||||
|
||||
|
||||
--- Sets the floor and ceiling altitude of the patrol.
|
||||
-- @param #PATROLZONE self
|
||||
-- @param #AI_PATROLZONE self
|
||||
-- @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.
|
||||
-- @return #PATROLZONE self
|
||||
function PATROLZONE:SetAltitude( PatrolFloorAltitude, PatrolCeilingAltitude )
|
||||
-- @return #AI_PATROLZONE self
|
||||
function AI_PATROLZONE:SetAltitude( PatrolFloorAltitude, PatrolCeilingAltitude )
|
||||
self:F2( { PatrolFloorAltitude, PatrolCeilingAltitude } )
|
||||
|
||||
self.PatrolFloorAltitude = PatrolFloorAltitude
|
||||
@@ -232,7 +232,7 @@ end
|
||||
function _NewPatrolRoute( AIControllable )
|
||||
|
||||
AIControllable:T( "NewPatrolRoute" )
|
||||
local PatrolZone = AIControllable:GetState( AIControllable, "PatrolZone" ) -- PatrolCore.Zone#PATROLZONE
|
||||
local PatrolZone = AIControllable:GetState( AIControllable, "PatrolZone" ) -- PatrolCore.Zone#AI_PATROLZONE
|
||||
PatrolZone:__Route( 1 )
|
||||
end
|
||||
|
||||
@@ -241,13 +241,13 @@ end
|
||||
|
||||
--- When the AIControllable is out of fuel, it is required that a new AIControllable is started, before the old AIControllable can return to the home base.
|
||||
-- Therefore, with a parameter and a calculation of the distance to the home base, the fuel treshold is calculated.
|
||||
-- When the fuel treshold is reached, the AIControllable will continue for a given time its patrol task in orbit, while a new AIControllable is targetted to the PATROLZONE.
|
||||
-- When the fuel treshold is reached, the AIControllable will continue for a given time its patrol task in orbit, while a new AIControllable is targetted to the AI_PATROLZONE.
|
||||
-- Once the time is finished, the old AIControllable will return to the base.
|
||||
-- @param #PATROLZONE self
|
||||
-- @param #AI_PATROLZONE self
|
||||
-- @param #number PatrolFuelTresholdPercentage The treshold in percentage (between 0 and 1) when the AIControllable is considered to get out of fuel.
|
||||
-- @param #number PatrolOutOfFuelOrbitTime The amount of seconds the out of fuel AIControllable will orbit before returning to the base.
|
||||
-- @return #PATROLZONE self
|
||||
function PATROLZONE:ManageFuel( PatrolFuelTresholdPercentage, PatrolOutOfFuelOrbitTime )
|
||||
-- @return #AI_PATROLZONE self
|
||||
function AI_PATROLZONE:ManageFuel( PatrolFuelTresholdPercentage, PatrolOutOfFuelOrbitTime )
|
||||
|
||||
self.PatrolManageFuel = true
|
||||
self.PatrolFuelTresholdPercentage = PatrolFuelTresholdPercentage
|
||||
@@ -257,9 +257,9 @@ function PATROLZONE:ManageFuel( PatrolFuelTresholdPercentage, PatrolOutOfFuelOrb
|
||||
end
|
||||
|
||||
--- Defines a new patrol route using the @{Process_PatrolZone} parameters and settings.
|
||||
-- @param #PATROLZONE self
|
||||
-- @return #PATROLZONE self
|
||||
function PATROLZONE:onenterRoute()
|
||||
-- @param #AI_PATROLZONE self
|
||||
-- @return #AI_PATROLZONE self
|
||||
function AI_PATROLZONE:onenterRoute()
|
||||
|
||||
self:F2()
|
||||
|
||||
@@ -354,8 +354,8 @@ function PATROLZONE:onenterRoute()
|
||||
end
|
||||
|
||||
|
||||
--- @param #PATROLZONE self
|
||||
function PATROLZONE:onenterPatrol()
|
||||
--- @param #AI_PATROLZONE self
|
||||
function AI_PATROLZONE:onenterPatrol()
|
||||
self:F2()
|
||||
|
||||
if self.Controllable and self.Controllable:IsAlive() then
|
||||
|
||||
Reference in New Issue
Block a user