mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Cargo Group is working...
This commit is contained in:
@@ -1,35 +1,35 @@
|
||||
--- This module contains the AISET_BALANCER class.
|
||||
--- This module contains the AIBALANCER class.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- 1) @{AISet_Balancer#AISET_BALANCER} class, extends @{StateMachine#STATEMACHINE_SET}
|
||||
-- 1) @{AIBalancer#AIBALANCER} class, extends @{StateMachine#STATEMACHINE_SET}
|
||||
-- ===================================================================================
|
||||
-- The @{AISet_Balancer#AISET_BALANCER} class monitors and manages as many AI GROUPS as there are
|
||||
-- The @{AIBalancer#AIBALANCER} class monitors and manages as many AI GROUPS as there are
|
||||
-- CLIENTS in a SET_CLIENT collection not occupied by players.
|
||||
-- The AI_BALANCER class manages internally a collection of AI_MANAGEMENT objects, which govern the behaviour
|
||||
-- The AIBALANCER class manages internally a collection of AI management objects, which govern the behaviour
|
||||
-- of the underlying AI GROUPS.
|
||||
--
|
||||
-- The parent class @{StateMachine#STATEMACHINE_SET} manages the functionality to control the Finite State Machine (FSM)
|
||||
-- and calls for each event the state transition functions providing the internal @{StateMachine#STATEMACHINE_SET.Set} object containing the
|
||||
-- SET_GROUP and additional event parameters provided during the event.
|
||||
--
|
||||
-- 1.1) AISET_BALANCER construction method
|
||||
-- 1.1) AIBALANCER construction method
|
||||
-- ---------------------------------------
|
||||
-- Create a new AISET_BALANCER object with the @{#AISET_BALANCER.New} method:
|
||||
-- Create a new AIBALANCER object with the @{#AIBALANCER.New} method:
|
||||
--
|
||||
-- * @{#AISET_BALANCER.New}: Creates a new AISET_BALANCER object.
|
||||
-- * @{#AIBALANCER.New}: Creates a new AIBALANCER object.
|
||||
--
|
||||
-- 1.2)
|
||||
-- ----
|
||||
-- * Add
|
||||
-- * Remove
|
||||
--
|
||||
-- 1.2) AISET_BALANCER returns AI to Airbases
|
||||
-- 1.2) AIBALANCER returns AI to Airbases
|
||||
-- ------------------------------------------
|
||||
-- You can configure to have the AI to return to:
|
||||
--
|
||||
-- * @{#AISET_BALANCER.ReturnToHomeAirbase}: Returns the AI to the home @{Airbase#AIRBASE}.
|
||||
-- * @{#AISET_BALANCER.ReturnToNearestAirbases}: Returns the AI to the nearest friendly @{Airbase#AIRBASE}.
|
||||
-- * @{#AIBALANCER.ReturnToHomeAirbase}: Returns the AI to the home @{Airbase#AIRBASE}.
|
||||
-- * @{#AIBALANCER.ReturnToNearestAirbases}: Returns the AI to the nearest friendly @{Airbase#AIRBASE}.
|
||||
-- --
|
||||
-- ===
|
||||
--
|
||||
@@ -56,39 +56,39 @@
|
||||
-- ### Contributions:
|
||||
--
|
||||
-- * **Dutch_Baron (James)**: Who you can search on the Eagle Dynamics Forums.
|
||||
-- Working together with James has resulted in the creation of the AISET_BALANCER class.
|
||||
-- Working together with James has resulted in the creation of the AIBALANCER class.
|
||||
-- James has shared his ideas on balancing AI with air units, and together we made a first design which you can use now :-)
|
||||
--
|
||||
-- * **SNAFU**:
|
||||
-- Had a couple of mails with the guys to validate, if the same concept in the GCI/CAP script could be reworked within MOOSE.
|
||||
-- None of the script code has been used however within the new AISET_BALANCER moose class.
|
||||
-- None of the script code has been used however within the new AIBALANCER moose class.
|
||||
--
|
||||
-- ### Authors:
|
||||
--
|
||||
-- * FlightControl: Framework Design & Programming
|
||||
--
|
||||
-- @module AISet_Balancer
|
||||
-- @module AIBalancer
|
||||
|
||||
|
||||
|
||||
--- AISET_BALANCER class
|
||||
-- @type AISET_BALANCER
|
||||
--- AIBALANCER class
|
||||
-- @type AIBALANCER
|
||||
-- @field Set#SET_CLIENT SetClient
|
||||
-- @extends StateMachine#STATEMACHINE_SET
|
||||
AISET_BALANCER = {
|
||||
ClassName = "AISET_BALANCER",
|
||||
AIBALANCER = {
|
||||
ClassName = "AIBALANCER",
|
||||
PatrolZones = {},
|
||||
AIGroups = {},
|
||||
}
|
||||
|
||||
--- Creates a new AI\_SET\_BALANCER object
|
||||
-- @param #AISET_BALANCER self
|
||||
--- Creates a new AIBALANCER object
|
||||
-- @param #AIBALANCER self
|
||||
-- @param Set#SET_CLIENT SetClient A SET\_CLIENT object that will contain the CLIENT objects to be monitored if they are alive or not (joined by a player).
|
||||
-- @param Spawn#SPAWN SpawnAI The default Spawn object to spawn new AI Groups when needed.
|
||||
-- @return #AISET_BALANCER
|
||||
-- @return #AIBALANCER
|
||||
-- @usage
|
||||
-- -- Define a new AISET_BALANCER Object.
|
||||
function AISET_BALANCER:New( SetClient, SpawnAI )
|
||||
-- -- Define a new AIBALANCER Object.
|
||||
function AIBALANCER:New( SetClient, SpawnAI )
|
||||
|
||||
local FSMT = {
|
||||
initial = 'None',
|
||||
@@ -117,10 +117,10 @@ function AISET_BALANCER:New( SetClient, SpawnAI )
|
||||
end
|
||||
|
||||
--- Returns the AI to the nearest friendly @{Airbase#AIRBASE}.
|
||||
-- @param #AISET_BALANCER self
|
||||
-- @param #AIBALANCER self
|
||||
-- @param DCSTypes#Distance ReturnTresholdRange If there is an enemy @{Client#CLIENT} within the ReturnTresholdRange given in meters, the AI will not return to the nearest @{Airbase#AIRBASE}.
|
||||
-- @param Set#SET_AIRBASE ReturnAirbaseSet The SET of @{Set#SET_AIRBASE}s to evaluate where to return to.
|
||||
function AISET_BALANCER:ReturnToNearestAirbases( ReturnTresholdRange, ReturnAirbaseSet )
|
||||
function AIBALANCER:ReturnToNearestAirbases( ReturnTresholdRange, ReturnAirbaseSet )
|
||||
|
||||
self.ToNearestAirbase = true
|
||||
self.ReturnTresholdRange = ReturnTresholdRange
|
||||
@@ -128,19 +128,19 @@ function AISET_BALANCER:ReturnToNearestAirbases( ReturnTresholdRange, ReturnAirb
|
||||
end
|
||||
|
||||
--- Returns the AI to the home @{Airbase#AIRBASE}.
|
||||
-- @param #AISET_BALANCER self
|
||||
-- @param #AIBALANCER self
|
||||
-- @param DCSTypes#Distance ReturnTresholdRange If there is an enemy @{Client#CLIENT} within the ReturnTresholdRange given in meters, the AI will not return to the nearest @{Airbase#AIRBASE}.
|
||||
function AISET_BALANCER:ReturnToHomeAirbase( ReturnTresholdRange )
|
||||
function AIBALANCER:ReturnToHomeAirbase( ReturnTresholdRange )
|
||||
|
||||
self.ToHomeAirbase = true
|
||||
self.ReturnTresholdRange = ReturnTresholdRange
|
||||
end
|
||||
|
||||
--- @param #AISET_BALANCER self
|
||||
--- @param #AIBALANCER self
|
||||
-- @param Set#SET_GROUP SetGroup
|
||||
-- @param #string ClientName
|
||||
-- @param Group#GROUP AIGroup
|
||||
function AISET_BALANCER:onenterSpawning( SetGroup, ClientName )
|
||||
function AIBALANCER:onenterSpawning( SetGroup, ClientName )
|
||||
|
||||
-- OK, Spawn a new group from the default SpawnAI object provided.
|
||||
local AIGroup = self.SpawnAI:Spawn()
|
||||
@@ -150,18 +150,18 @@ function AISET_BALANCER:onenterSpawning( SetGroup, ClientName )
|
||||
SetGroup:Add( ClientName, AIGroup )
|
||||
end
|
||||
|
||||
--- @param #AISET_BALANCER self
|
||||
--- @param #AIBALANCER self
|
||||
-- @param Set#SET_GROUP SetGroup
|
||||
-- @param Group#GROUP AIGroup
|
||||
function AISET_BALANCER:onenterDestroying( SetGroup, AIGroup )
|
||||
function AIBALANCER:onenterDestroying( SetGroup, AIGroup )
|
||||
|
||||
AIGroup:Destroy()
|
||||
end
|
||||
|
||||
--- @param #AISET_BALANCER self
|
||||
--- @param #AIBALANCER self
|
||||
-- @param Set#SET_GROUP SetGroup
|
||||
-- @param Group#GROUP AIGroup
|
||||
function AISET_BALANCER:onenterReturning( SetGroup, AIGroup )
|
||||
function AIBALANCER:onenterReturning( SetGroup, AIGroup )
|
||||
|
||||
local AIGroupTemplate = AIGroup:GetTemplate()
|
||||
if self.ToHomeAirbase == true then
|
||||
@@ -184,8 +184,8 @@ function AISET_BALANCER:onenterReturning( SetGroup, AIGroup )
|
||||
end
|
||||
|
||||
|
||||
--- @param #AISET_BALANCER self
|
||||
function AISET_BALANCER:onenterMonitoring( SetGroup )
|
||||
--- @param #AIBALANCER self
|
||||
function AIBALANCER:onenterMonitoring( SetGroup )
|
||||
|
||||
self.SetClient:ForEachClient(
|
||||
--- @param Client#CLIENT Client
|
||||
File diff suppressed because it is too large
Load Diff
@@ -48,16 +48,15 @@ Include.File( "Process_Route" )
|
||||
Include.File( "Process_Smoke" )
|
||||
Include.File( "Process_Destroy" )
|
||||
Include.File( "Process_JTAC" )
|
||||
Include.File( "Process_PatrolZone" )
|
||||
|
||||
Include.File( "Task" )
|
||||
Include.File( "Task_SEAD" )
|
||||
Include.File( "Task_A2G" )
|
||||
|
||||
--- AI Set Handling Classes
|
||||
Include.File( "AISet_Balancer" )
|
||||
Include.File( "AIBalancer" )
|
||||
|
||||
--- AI Task Handling Classes
|
||||
Include.File( "AI_PatrolZone" )
|
||||
|
||||
-- The order of the declarations is important here. Don't touch it.
|
||||
|
||||
|
||||
@@ -1,310 +0,0 @@
|
||||
--- This module contains the PATROLZONE class.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- 1) @{#PATROLZONE} class, extends @{Base#BASE}
|
||||
-- ===================================================
|
||||
-- The @{#PATROLZONE} class implements the core functions to patrol a @{Zone} by air units.
|
||||
-- The PATROLZONE class will guide the airplanes towards the patrolzone.
|
||||
-- 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 point using a randomly selected speed within given boundary limits.
|
||||
-- Upon arrival at the random point, a new random point will be selected within the patrol zone within boundary limits.
|
||||
-- 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:
|
||||
-- ----------------------------
|
||||
-- @{#PATROLZONE.New}(): Creates a new PATROLZONE object.
|
||||
--
|
||||
-- 1.2) Modify the PATROLZONE parameters:
|
||||
-- --------------------------------------
|
||||
-- The following methods are available to modify the parameters of a PATROLZONE object:
|
||||
--
|
||||
-- * @{#PATROLZONE.SetGroup}(): Set the AI Patrol Group.
|
||||
-- * @{#PATROLZONE.SetSpeed}(): Set the patrol speed of the AI, for the next patrol.
|
||||
-- * @{#PATROLZONE.SetAltitude}(): Set altitude of the AI, for the next patrol.
|
||||
--
|
||||
-- 1.3) Manage the out of fuel in the PATROLZONE:
|
||||
-- ----------------------------------------------
|
||||
-- When the PatrolGroup is out of fuel, it is required that a new PatrolGroup is started, before the old PatrolGroup 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 PatrolGroup will continue for a given time its patrol task in orbit, while a new PatrolGroup is targetted to the PATROLZONE.
|
||||
-- Once the time is finished, the old PatrolGroup will return to the base.
|
||||
-- Use the method @{#PATROLZONE.ManageFuel}() to have this proces in place.
|
||||
--
|
||||
-- ====
|
||||
--
|
||||
-- **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:
|
||||
--
|
||||
-- 2016-08-17: PATROLZONE:New( **PatrolSpawn,** PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed ) replaces PATROLZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed )
|
||||
--
|
||||
-- 2016-07-01: Initial class and API.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- AUTHORS and CONTRIBUTIONS
|
||||
-- =========================
|
||||
--
|
||||
-- ### Contributions:
|
||||
--
|
||||
-- * **DutchBaron**: Testing.
|
||||
--
|
||||
-- ### Authors:
|
||||
--
|
||||
-- * **FlightControl**: Design & Programming
|
||||
--
|
||||
--
|
||||
-- @module PatrolZone
|
||||
|
||||
|
||||
|
||||
--- PATROLZONE class
|
||||
-- @type PATROLZONE
|
||||
-- @field Group#GROUP PatrolGroup The @{Group} patrolling.
|
||||
-- @field Zone#ZONE_BASE PatrolZone The @{Zone} where the patrol needs to be executed.
|
||||
-- @field DCSTypes#Altitude PatrolFloorAltitude The lowest altitude in meters where to execute the patrol.
|
||||
-- @field DCSTypes#Altitude PatrolCeilingAltitude The highest altitude in meters where to execute the patrol.
|
||||
-- @field DCSTypes#Speed PatrolMinSpeed The minimum speed of the @{Group} in km/h.
|
||||
-- @field DCSTypes#Speed PatrolMaxSpeed The maximum speed of the @{Group} in km/h.
|
||||
-- @extends Base#BASE
|
||||
PATROLZONE = {
|
||||
ClassName = "PATROLZONE",
|
||||
}
|
||||
|
||||
|
||||
|
||||
--- Creates a new PATROLZONE object, taking a @{Group} object as a parameter. The GROUP needs to be alive.
|
||||
-- @param #PATROLZONE self
|
||||
-- @param Spawn#SPAWN PatrolSpawn The @{SPAWN} object to spawn new group objects when required due to the fuel treshold.
|
||||
-- @param Zone#ZONE_BASE PatrolZone The @{Zone} where the patrol needs to be executed.
|
||||
-- @param DCSTypes#Altitude PatrolFloorAltitude The lowest altitude in meters where to execute the patrol.
|
||||
-- @param DCSTypes#Altitude PatrolCeilingAltitude The highest altitude in meters where to execute the patrol.
|
||||
-- @param DCSTypes#Speed PatrolMinSpeed The minimum speed of the @{Group} in km/h.
|
||||
-- @param DCSTypes#Speed PatrolMaxSpeed The maximum speed of the @{Group} in km/h.
|
||||
-- @return #PATROLZONE self
|
||||
-- @usage
|
||||
-- -- Define a new PATROLZONE Object. This PatrolArea will patrol a group 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( PatrolSpawn, PatrolZone, 3000, 6000, 600, 900 )
|
||||
function PATROLZONE:New( PatrolSpawn, PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed )
|
||||
|
||||
-- Inherits from BASE
|
||||
local self = BASE:Inherit( self, BASE:New() )
|
||||
|
||||
self.PatrolSpawn = PatrolSpawn
|
||||
self.PatrolZone = PatrolZone
|
||||
self.PatrolFloorAltitude = PatrolFloorAltitude
|
||||
self.PatrolCeilingAltitude = PatrolCeilingAltitude
|
||||
self.PatrolMinSpeed = PatrolMinSpeed
|
||||
self.PatrolMaxSpeed = PatrolMaxSpeed
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Set the @{Group} to act as the Patroller.
|
||||
-- @param #PATROLZONE self
|
||||
-- @param Group#GROUP PatrolGroup The @{Group} patrolling.
|
||||
-- @return #PATROLZONE self
|
||||
function PATROLZONE:SetGroup( PatrolGroup )
|
||||
|
||||
self.PatrolGroup = PatrolGroup
|
||||
self.PatrolGroupTemplateName = PatrolGroup:GetName()
|
||||
self:NewPatrolRoute()
|
||||
|
||||
if not self.PatrolOutOfFuelMonitor then
|
||||
self.PatrolOutOfFuelMonitor = SCHEDULER:New( nil, _MonitorOutOfFuelScheduled, { self }, 1, 120, 0 )
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Sets (modifies) the minimum and maximum speed of the patrol.
|
||||
-- @param #PATROLZONE self
|
||||
-- @param DCSTypes#Speed PatrolMinSpeed The minimum speed of the @{Group} in km/h.
|
||||
-- @param DCSTypes#Speed PatrolMaxSpeed The maximum speed of the @{Group} in km/h.
|
||||
-- @return #PATROLZONE self
|
||||
function PATROLZONE:SetSpeed( PatrolMinSpeed, PatrolMaxSpeed )
|
||||
self:F2( { PatrolMinSpeed, PatrolMaxSpeed } )
|
||||
|
||||
self.PatrolMinSpeed = PatrolMinSpeed
|
||||
self.PatrolMaxSpeed = PatrolMaxSpeed
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Sets the floor and ceiling altitude of the patrol.
|
||||
-- @param #PATROLZONE self
|
||||
-- @param DCSTypes#Altitude PatrolFloorAltitude The lowest altitude in meters where to execute the patrol.
|
||||
-- @param DCSTypes#Altitude PatrolCeilingAltitude The highest altitude in meters where to execute the patrol.
|
||||
-- @return #PATROLZONE self
|
||||
function PATROLZONE:SetAltitude( PatrolFloorAltitude, PatrolCeilingAltitude )
|
||||
self:F2( { PatrolFloorAltitude, PatrolCeilingAltitude } )
|
||||
|
||||
self.PatrolFloorAltitude = PatrolFloorAltitude
|
||||
self.PatrolCeilingAltitude = PatrolCeilingAltitude
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- @param Group#GROUP PatrolGroup
|
||||
function _NewPatrolRoute( PatrolGroup )
|
||||
|
||||
PatrolGroup:T( "NewPatrolRoute" )
|
||||
local PatrolZone = PatrolGroup:GetState( PatrolGroup, "PatrolZone" ) -- PatrolZone#PATROLZONE
|
||||
PatrolZone:NewPatrolRoute()
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Defines a new patrol route using the @{PatrolZone} parameters and settings.
|
||||
-- @param #PATROLZONE self
|
||||
-- @return #PATROLZONE self
|
||||
function PATROLZONE:NewPatrolRoute()
|
||||
|
||||
self:F2()
|
||||
|
||||
local PatrolRoute = {}
|
||||
|
||||
if self.PatrolGroup:IsAlive() then
|
||||
--- Determine if the PatrolGroup is within the PatrolZone.
|
||||
-- If not, make a waypoint within the to that the PatrolGroup will fly at maximum speed to that point.
|
||||
|
||||
-- --- Calculate the current route point.
|
||||
-- local CurrentVec2 = self.PatrolGroup:GetVec2()
|
||||
-- local CurrentAltitude = self.PatrolGroup:GetUnit(1):GetAltitude()
|
||||
-- local CurrentPointVec3 = POINT_VEC3:New( CurrentVec2.x, CurrentAltitude, CurrentVec2.y )
|
||||
-- local CurrentRoutePoint = CurrentPointVec3:RoutePointAir(
|
||||
-- POINT_VEC3.RoutePointAltType.BARO,
|
||||
-- POINT_VEC3.RoutePointType.TurningPoint,
|
||||
-- POINT_VEC3.RoutePointAction.TurningPoint,
|
||||
-- ToPatrolZoneSpeed,
|
||||
-- true
|
||||
-- )
|
||||
--
|
||||
-- PatrolRoute[#PatrolRoute+1] = CurrentRoutePoint
|
||||
|
||||
self:T2( PatrolRoute )
|
||||
|
||||
if self.PatrolGroup:IsNotInZone( self.PatrolZone ) then
|
||||
--- Find a random 2D point in PatrolZone.
|
||||
local ToPatrolZoneVec2 = self.PatrolZone:GetRandomVec2()
|
||||
self:T2( ToPatrolZoneVec2 )
|
||||
|
||||
--- Define Speed and Altitude.
|
||||
local ToPatrolZoneAltitude = math.random( self.PatrolFloorAltitude, self.PatrolCeilingAltitude )
|
||||
local ToPatrolZoneSpeed = self.PatrolMaxSpeed
|
||||
self:T2( ToPatrolZoneSpeed )
|
||||
|
||||
--- Obtain a 3D @{Point} from the 2D point + altitude.
|
||||
local ToPatrolZonePointVec3 = POINT_VEC3:New( ToPatrolZoneVec2.x, ToPatrolZoneAltitude, ToPatrolZoneVec2.y )
|
||||
|
||||
--- Create a route point of type air.
|
||||
local ToPatrolZoneRoutePoint = ToPatrolZonePointVec3:RoutePointAir(
|
||||
POINT_VEC3.RoutePointAltType.BARO,
|
||||
POINT_VEC3.RoutePointType.TurningPoint,
|
||||
POINT_VEC3.RoutePointAction.TurningPoint,
|
||||
ToPatrolZoneSpeed,
|
||||
true
|
||||
)
|
||||
|
||||
PatrolRoute[#PatrolRoute+1] = ToPatrolZoneRoutePoint
|
||||
|
||||
end
|
||||
|
||||
--- Define a random point in the @{Zone}. The AI will fly to that point within the zone.
|
||||
|
||||
--- Find a random 2D point in PatrolZone.
|
||||
local ToTargetVec2 = self.PatrolZone:GetRandomVec2()
|
||||
self:T2( ToTargetVec2 )
|
||||
|
||||
--- Define Speed and Altitude.
|
||||
local ToTargetAltitude = math.random( self.PatrolFloorAltitude, self.PatrolCeilingAltitude )
|
||||
local ToTargetSpeed = math.random( self.PatrolMinSpeed, self.PatrolMaxSpeed )
|
||||
self:T2( { self.PatrolMinSpeed, self.PatrolMaxSpeed, ToTargetSpeed } )
|
||||
|
||||
--- Obtain a 3D @{Point} from the 2D point + altitude.
|
||||
local ToTargetPointVec3 = POINT_VEC3:New( ToTargetVec2.x, ToTargetAltitude, ToTargetVec2.y )
|
||||
|
||||
--- Create a route point of type air.
|
||||
local ToTargetRoutePoint = ToTargetPointVec3:RoutePointAir(
|
||||
POINT_VEC3.RoutePointAltType.BARO,
|
||||
POINT_VEC3.RoutePointType.TurningPoint,
|
||||
POINT_VEC3.RoutePointAction.TurningPoint,
|
||||
ToTargetSpeed,
|
||||
true
|
||||
)
|
||||
|
||||
--ToTargetPointVec3:SmokeRed()
|
||||
|
||||
PatrolRoute[#PatrolRoute+1] = ToTargetRoutePoint
|
||||
|
||||
--- Now we're going to do something special, we're going to call a function from a waypoint action at the PatrolGroup...
|
||||
self.PatrolGroup:WayPointInitialize( PatrolRoute )
|
||||
|
||||
--- Do a trick, link the NewPatrolRoute function of the PATROLGROUP object to the PatrolGroup in a temporary variable ...
|
||||
self.PatrolGroup:SetState( self.PatrolGroup, "PatrolZone", self )
|
||||
self.PatrolGroup:WayPointFunction( #PatrolRoute, 1, "_NewPatrolRoute" )
|
||||
|
||||
--- NOW ROUTE THE GROUP!
|
||||
self.PatrolGroup:WayPointExecute( 1, 2 )
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- When the PatrolGroup is out of fuel, it is required that a new PatrolGroup is started, before the old PatrolGroup 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 PatrolGroup will continue for a given time its patrol task in orbit, while a new PatrolGroup is targetted to the PATROLZONE.
|
||||
-- Once the time is finished, the old PatrolGroup will return to the base.
|
||||
-- @param #PATROLZONE self
|
||||
-- @param #number PatrolFuelTresholdPercentage The treshold in percentage (between 0 and 1) when the PatrolGroup is considered to get out of fuel.
|
||||
-- @param #number PatrolOutOfFuelOrbitTime The amount of seconds the out of fuel PatrolGroup will orbit before returning to the base.
|
||||
-- @return #PATROLZONE self
|
||||
function PATROLZONE:ManageFuel( PatrolFuelTresholdPercentage, PatrolOutOfFuelOrbitTime )
|
||||
|
||||
self.PatrolManageFuel = true
|
||||
self.PatrolFuelTresholdPercentage = PatrolFuelTresholdPercentage
|
||||
self.PatrolOutOfFuelOrbitTime = PatrolOutOfFuelOrbitTime
|
||||
|
||||
if self.PatrolGroup then
|
||||
self.PatrolOutOfFuelMonitor = SCHEDULER:New( self, self._MonitorOutOfFuelScheduled, {}, 1, 120, 0 )
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
--- @param #PATROLZONE self
|
||||
function _MonitorOutOfFuelScheduled( self )
|
||||
self:F2( "_MonitorOutOfFuelScheduled" )
|
||||
|
||||
if self.PatrolGroup and self.PatrolGroup:IsAlive() then
|
||||
|
||||
local Fuel = self.PatrolGroup:GetUnit(1):GetFuel()
|
||||
if Fuel < self.PatrolFuelTresholdPercentage then
|
||||
local OldPatrolGroup = self.PatrolGroup
|
||||
local PatrolGroupTemplate = self.PatrolGroup:GetTemplate()
|
||||
|
||||
local OrbitTask = OldPatrolGroup:TaskOrbitCircle( math.random( self.PatrolFloorAltitude, self.PatrolCeilingAltitude ), self.PatrolMinSpeed )
|
||||
local TimedOrbitTask = OldPatrolGroup:TaskControlled( OrbitTask, OldPatrolGroup:TaskCondition(nil,nil,nil,nil,self.PatrolOutOfFuelOrbitTime,nil ) )
|
||||
OldPatrolGroup:SetTask( TimedOrbitTask, 10 )
|
||||
|
||||
local NewPatrolGroup = self.PatrolSpawn:Spawn()
|
||||
self.PatrolGroup = NewPatrolGroup
|
||||
self:NewPatrolRoute()
|
||||
end
|
||||
else
|
||||
self.PatrolOutOfFuelMonitor:Stop()
|
||||
end
|
||||
end
|
||||
@@ -1,10 +1,10 @@
|
||||
--- This module contains the AI\_PATROLZONE class.
|
||||
--- This module contains the PROCESS\_PATROLZONE class.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- 1) @{#AI_PATROLZONE} class, extends @{StateMachine#STATEMACHINE}
|
||||
-- 1) @{#PROCESS_PATROLZONE} class, extends @{StateMachine#STATEMACHINE}
|
||||
-- ================================================================
|
||||
-- The @{#AI_PATROLZONE} class implements the core functions to patrol a @{Zone} by an AIR @{Controllable}.
|
||||
-- The @{#PROCESS_PATROLZONE} class implements the core functions to patrol a @{Zone} by an AIR @{Controllable}.
|
||||
-- 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) AI\_PATROLZONE constructor:
|
||||
-- 1.1) PROCESS\_PATROLZONE constructor:
|
||||
-- ----------------------------
|
||||
--
|
||||
-- * @{#AI_PATROLZONE.New}(): Creates a new AI\_PATROLZONE object.
|
||||
-- * @{#PROCESS_PATROLZONE.New}(): Creates a new PROCESS\_PATROLZONE object.
|
||||
--
|
||||
-- 1.2) AI\_PATROLZONE state machine:
|
||||
-- 1.2) PROCESS\_PATROLZONE state machine:
|
||||
-- ----------------------------------
|
||||
-- The AI\_PATROLZONE is a state machine: it manages the different events and states of the AIControllable it is controlling.
|
||||
-- The PROCESS\_PATROLZONE is a state machine: it manages the different events and states of the AIControllable it is controlling.
|
||||
--
|
||||
-- ### 1.2.1) AI\_PATROLZONE Events:
|
||||
-- ### 1.2.1) PROCESS\_PATROLZONE Events:
|
||||
--
|
||||
-- * @{#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.
|
||||
-- * @{#PROCESS_PATROLZONE.Route}( AIControllable ): A new 3D route point is selected and the AIControllable will fly towards that point with the given speed.
|
||||
-- * @{#PROCESS_PATROLZONE.Patrol}( AIControllable ): The AIControllable reports it is patrolling. This event is called every 30 seconds.
|
||||
-- * @{#PROCESS_PATROLZONE.RTB}( AIControllable ): The AIControllable will report return to base.
|
||||
-- * @{#PROCESS_PATROLZONE.End}( AIControllable ): The end of the PROCESS\_PATROLZONE process.
|
||||
-- * @{#PROCESS_PATROLZONE.Dead}( AIControllable ): The AIControllable is dead. The PROCESS\_PATROLZONE process will be ended.
|
||||
--
|
||||
-- ### 1.2.2) AI\_PATROLZONE States:
|
||||
-- ### 1.2.2) PROCESS\_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 function can be used.
|
||||
@@ -37,7 +37,7 @@
|
||||
-- * **Dead**: The AIControllable is dead ...
|
||||
-- * **End**: The process has come to an end.
|
||||
--
|
||||
-- ### 1.2.3) AI\_PATROLZONE state transition functions:
|
||||
-- ### 1.2.3) PROCESS\_PATROLZONE state transition functions:
|
||||
--
|
||||
-- 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 functions will be called by the state machine:
|
||||
@@ -52,7 +52,7 @@
|
||||
-- The state transition function needs to start with the name **OnAfter + the name of the state**.
|
||||
-- These state transition functions need to provide a return value, which is specified at the function description.
|
||||
--
|
||||
-- An example how to manage a state transition for an AI\_PATROLZONE object **Patrol** for the state **RTB**:
|
||||
-- An example how to manage a state transition for an PROCESS\_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 = AI_PATROLZONE:New( PatrolZone, 3000, 6000, 300, 600 )
|
||||
-- local Patrol = PROCESS_PATROLZONE:New( PatrolZone, 3000, 6000, 300, 600 )
|
||||
-- Patrol:SetControllable( PatrolGroup )
|
||||
-- Patrol:ManageFuel( 0.2, 60 )
|
||||
--
|
||||
-- **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.
|
||||
-- **OnBefore**RTB( AIGroup ) will be called by the PROCESS\_PATROLZONE object when the AIGroup reports RTB, but **before** the RTB default action is processed by the PROCESS_PATROLZONE object.
|
||||
--
|
||||
-- --- State transition function for the AI\_PATROLZONE **Patrol** object
|
||||
-- -- @param #AI_PATROLZONE self
|
||||
-- --- State transition function for the PROCESS\_PATROLZONE **Patrol** object
|
||||
-- -- @param #PROCESS_PATROLZONE self
|
||||
-- -- @param Controllable#CONTROLLABLE AIGroup
|
||||
-- -- @return #boolean If false is returned, then the OnAfter state transition function will not be called.
|
||||
-- function Patrol:OnBeforeRTB( AIGroup )
|
||||
-- AIGroup:MessageToRed( "Returning to base", 20 )
|
||||
-- end
|
||||
--
|
||||
-- **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.
|
||||
-- **OnAfter**RTB( AIGroup ) will be called by the PROCESS\_PATROLZONE object when the AIGroup reports RTB, but **after** the RTB default action was processed by the PROCESS_PATROLZONE object.
|
||||
--
|
||||
-- --- State transition function for the AI\_PATROLZONE **Patrol** object
|
||||
-- -- @param #AI_PATROLZONE self
|
||||
-- --- State transition function for the PROCESS\_PATROLZONE **Patrol** object
|
||||
-- -- @param #PROCESS_PATROLZONE self
|
||||
-- -- @param Controllable#CONTROLLABLE AIGroup
|
||||
-- -- @return #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 AI\_PATROLZONE parameters:
|
||||
-- 1.3) Manage the PROCESS\_PATROLZONE parameters:
|
||||
-- ------------------------------------------
|
||||
-- The following methods are available to modify the parameters of a AI\_PATROLZONE object:
|
||||
-- The following methods are available to modify the parameters of a PROCESS\_PATROLZONE object:
|
||||
--
|
||||
-- * @{#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.
|
||||
-- * @{#PROCESS_PATROLZONE.SetControllable}(): Set the AIControllable.
|
||||
-- * @{#PROCESS_PATROLZONE.GetControllable}(): Get the AIControllable.
|
||||
-- * @{#PROCESS_PATROLZONE.SetSpeed}(): Set the patrol speed of the AI, for the next patrol.
|
||||
-- * @{#PROCESS_PATROLZONE.SetAltitude}(): Set altitude of the AI, for the next patrol.
|
||||
--
|
||||
-- 1.3) Manage the out of fuel in the AI\_PATROLZONE:
|
||||
-- 1.3) Manage the out of fuel in the PROCESS\_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 AI\_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 PROCESS\_PATROLZONE.
|
||||
-- Once the time is finished, the old AIControllable will return to the base.
|
||||
-- Use the method @{#AI_PATROLZONE.ManageFuel}() to have this proces in place.
|
||||
-- Use the method @{#PROCESS_PATROLZONE.ManageFuel}() to have this proces in place.
|
||||
--
|
||||
-- ====
|
||||
--
|
||||
@@ -113,7 +113,7 @@
|
||||
--
|
||||
-- Hereby the change log:
|
||||
--
|
||||
-- 2016-08-17: AI\_PATROLZONE:New( **PatrolSpawn,** PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed ) replaces AI\_PATROLZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed )
|
||||
-- 2016-08-17: PROCESS\_PATROLZONE:New( **PatrolSpawn,** PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed ) replaces PROCESS\_PATROLZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed )
|
||||
--
|
||||
-- 2016-07-01: Initial class and API.
|
||||
--
|
||||
@@ -132,12 +132,25 @@
|
||||
-- * **FlightControl**: Design & Programming.
|
||||
--
|
||||
--
|
||||
-- @module AI_PatrolZone
|
||||
-- @module Process_PatrolZone
|
||||
|
||||
-- State Transition Functions
|
||||
|
||||
--- OnBefore State Transition Function
|
||||
-- @function [parent=#PROCESS_PATROLZONE] OnBeforeRoute
|
||||
-- @param #PROCESS_PATROLZONE self
|
||||
-- @param Controllable#CONTROLLABLE Controllable
|
||||
-- @return #boolean
|
||||
|
||||
--- OnAfter State Transition Function
|
||||
-- @function [parent=#PROCESS_PATROLZONE] OnAfterRoute
|
||||
-- @param #PROCESS_PATROLZONE self
|
||||
-- @param Controllable#CONTROLLABLE Controllable
|
||||
|
||||
|
||||
|
||||
--- AI\_PATROLZONE class
|
||||
-- @type AI_PATROLZONE
|
||||
--- PROCESS\_PATROLZONE class
|
||||
-- @type PROCESS_PATROLZONE
|
||||
-- @field Controllable#CONTROLLABLE AIControllable The @{Controllable} patrolling.
|
||||
-- @field Zone#ZONE_BASE PatrolZone The @{Zone} where the patrol needs to be executed.
|
||||
-- @field DCSTypes#Altitude PatrolFloorAltitude The lowest altitude in meters where to execute the patrol.
|
||||
@@ -145,26 +158,26 @@
|
||||
-- @field DCSTypes#Speed PatrolMinSpeed The minimum speed of the @{Controllable} in km/h.
|
||||
-- @field DCSTypes#Speed PatrolMaxSpeed The maximum speed of the @{Controllable} in km/h.
|
||||
-- @extends StateMachine#STATEMACHINE_CONTROLLABLE
|
||||
AI_PATROLZONE = {
|
||||
ClassName = "AI_PATROLZONE",
|
||||
PROCESS_PATROLZONE = {
|
||||
ClassName = "PROCESS_PATROLZONE",
|
||||
}
|
||||
|
||||
|
||||
|
||||
--- Creates a new AI\_PATROLZONE object
|
||||
-- @param #AI_PATROLZONE self
|
||||
--- Creates a new PROCESS\_PATROLZONE object
|
||||
-- @param #PROCESS_PATROLZONE self
|
||||
-- @param Zone#ZONE_BASE PatrolZone The @{Zone} where the patrol needs to be executed.
|
||||
-- @param DCSTypes#Altitude PatrolFloorAltitude The lowest altitude in meters where to execute the patrol.
|
||||
-- @param DCSTypes#Altitude PatrolCeilingAltitude The highest altitude in meters where to execute the patrol.
|
||||
-- @param DCSTypes#Speed PatrolMinSpeed The minimum speed of the @{Controllable} in km/h.
|
||||
-- @param DCSTypes#Speed PatrolMaxSpeed The maximum speed of the @{Controllable} in km/h.
|
||||
-- @return #AI_PATROLZONE self
|
||||
-- @return #PROCESS_PATROLZONE self
|
||||
-- @usage
|
||||
-- -- 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.
|
||||
-- -- Define a new PROCESS_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 = AI_PATROLZONE:New( PatrolZone, 3000, 6000, 600, 900 )
|
||||
function AI_PATROLZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed )
|
||||
-- PatrolArea = PROCESS_PATROLZONE:New( PatrolZone, 3000, 6000, 600, 900 )
|
||||
function PROCESS_PATROLZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed )
|
||||
|
||||
local FSMT = {
|
||||
initial = 'None',
|
||||
@@ -194,11 +207,11 @@ end
|
||||
|
||||
|
||||
--- Sets (modifies) the minimum and maximum speed of the patrol.
|
||||
-- @param #AI_PATROLZONE self
|
||||
-- @param #PROCESS_PATROLZONE self
|
||||
-- @param DCSTypes#Speed PatrolMinSpeed The minimum speed of the @{Controllable} in km/h.
|
||||
-- @param DCSTypes#Speed PatrolMaxSpeed The maximum speed of the @{Controllable} in km/h.
|
||||
-- @return #AI_PATROLZONE self
|
||||
function AI_PATROLZONE:SetSpeed( PatrolMinSpeed, PatrolMaxSpeed )
|
||||
-- @return #PROCESS_PATROLZONE self
|
||||
function PROCESS_PATROLZONE:SetSpeed( PatrolMinSpeed, PatrolMaxSpeed )
|
||||
self:F2( { PatrolMinSpeed, PatrolMaxSpeed } )
|
||||
|
||||
self.PatrolMinSpeed = PatrolMinSpeed
|
||||
@@ -208,11 +221,11 @@ end
|
||||
|
||||
|
||||
--- Sets the floor and ceiling altitude of the patrol.
|
||||
-- @param #AI_PATROLZONE self
|
||||
-- @param #PROCESS_PATROLZONE self
|
||||
-- @param DCSTypes#Altitude PatrolFloorAltitude The lowest altitude in meters where to execute the patrol.
|
||||
-- @param DCSTypes#Altitude PatrolCeilingAltitude The highest altitude in meters where to execute the patrol.
|
||||
-- @return #AI_PATROLZONE self
|
||||
function AI_PATROLZONE:SetAltitude( PatrolFloorAltitude, PatrolCeilingAltitude )
|
||||
-- @return #PROCESS_PATROLZONE self
|
||||
function PROCESS_PATROLZONE:SetAltitude( PatrolFloorAltitude, PatrolCeilingAltitude )
|
||||
self:F2( { PatrolFloorAltitude, PatrolCeilingAltitude } )
|
||||
|
||||
self.PatrolFloorAltitude = PatrolFloorAltitude
|
||||
@@ -225,7 +238,7 @@ end
|
||||
function _NewPatrolRoute( AIControllable )
|
||||
|
||||
AIControllable:T( "NewPatrolRoute" )
|
||||
local PatrolZone = AIControllable:GetState( AIControllable, "PatrolZone" ) -- PatrolZone#AI_PATROLZONE
|
||||
local PatrolZone = AIControllable:GetState( AIControllable, "PatrolZone" ) -- PatrolZone#PROCESS_PATROLZONE
|
||||
PatrolZone:__Route( 1 )
|
||||
end
|
||||
|
||||
@@ -234,13 +247,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 AI\_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 PROCESS\_PATROLZONE.
|
||||
-- Once the time is finished, the old AIControllable will return to the base.
|
||||
-- @param #AI_PATROLZONE self
|
||||
-- @param #PROCESS_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 #AI_PATROLZONE self
|
||||
function AI_PATROLZONE:ManageFuel( PatrolFuelTresholdPercentage, PatrolOutOfFuelOrbitTime )
|
||||
-- @return #PROCESS_PATROLZONE self
|
||||
function PROCESS_PATROLZONE:ManageFuel( PatrolFuelTresholdPercentage, PatrolOutOfFuelOrbitTime )
|
||||
|
||||
self.PatrolManageFuel = true
|
||||
self.PatrolFuelTresholdPercentage = PatrolFuelTresholdPercentage
|
||||
@@ -249,10 +262,10 @@ function AI_PATROLZONE:ManageFuel( PatrolFuelTresholdPercentage, PatrolOutOfFuel
|
||||
return self
|
||||
end
|
||||
|
||||
--- Defines a new patrol route using the @{AI_PatrolZone} parameters and settings.
|
||||
-- @param #AI_PATROLZONE self
|
||||
-- @return #AI_PATROLZONE self
|
||||
function AI_PATROLZONE:onenterRoute()
|
||||
--- Defines a new patrol route using the @{Process_PatrolZone} parameters and settings.
|
||||
-- @param #PROCESS_PATROLZONE self
|
||||
-- @return #PROCESS_PATROLZONE self
|
||||
function PROCESS_PATROLZONE:onenterRoute()
|
||||
|
||||
self:F2()
|
||||
|
||||
@@ -347,8 +360,8 @@ function AI_PATROLZONE:onenterRoute()
|
||||
end
|
||||
|
||||
|
||||
--- @param #AI_PATROLZONE self
|
||||
function AI_PATROLZONE:onenterPatrol()
|
||||
--- @param #PROCESS_PATROLZONE self
|
||||
function PROCESS_PATROLZONE:onenterPatrol()
|
||||
self:F2()
|
||||
|
||||
if self.Controllable and self.Controllable:IsAlive() then
|
||||
@@ -284,7 +284,7 @@ function SET_BASE:GetSet()
|
||||
return self.Set
|
||||
end
|
||||
|
||||
--- Adds a @{Base#BASE} object in the @{Set#SET_BASE}, using the Object Name as the index.
|
||||
--- Adds a @{Base#BASE} object in the @{Set#SET_BASE}, using a given ObjectName as the index.
|
||||
-- @param #SET_BASE self
|
||||
-- @param #string ObjectName
|
||||
-- @param Base#BASE Object
|
||||
@@ -310,6 +310,21 @@ function SET_BASE:Add( ObjectName, Object )
|
||||
|
||||
end
|
||||
|
||||
--- Adds a @{Base#BASE} object in the @{Set#SET_BASE}, using the Object Name as the index.
|
||||
-- @param #SET_BASE self
|
||||
-- @param Object#OBJECT Object
|
||||
-- @return Base#BASE The added BASE Object.
|
||||
function SET_BASE:AddObject( Object )
|
||||
self:F2( Object.ObjectName )
|
||||
|
||||
self:T( Object.UnitName )
|
||||
self:T( Object.ObjectName )
|
||||
self:Add( Object.ObjectName, Object )
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Removes a @{Base#BASE} object from the @{Set#SET_BASE} and derived classes, based on the Object Name.
|
||||
-- @param #SET_BASE self
|
||||
-- @param #string ObjectName
|
||||
@@ -590,6 +605,9 @@ end
|
||||
function SET_BASE:ForEach( IteratorFunction, arg, Set, Function, FunctionArguments )
|
||||
self:F3( arg )
|
||||
|
||||
Set = Set or self:GetSet()
|
||||
arg = arg or {}
|
||||
|
||||
local function CoRoutine()
|
||||
local Count = 0
|
||||
for ObjectID, ObjectData in pairs( Set ) do
|
||||
|
||||
@@ -101,7 +101,7 @@ end
|
||||
|
||||
function STATEMACHINE._handler( self, EventName, ... )
|
||||
|
||||
self:F( EventName )
|
||||
self:F( { EventName, ... } )
|
||||
|
||||
local can, to = self:can(EventName)
|
||||
self:T( { EventName, can, to } )
|
||||
@@ -262,23 +262,16 @@ STATEMACHINE_PROCESS = {
|
||||
--- Creates a new STATEMACHINE_PROCESS object.
|
||||
-- @param #STATEMACHINE_PROCESS self
|
||||
-- @return #STATEMACHINE_PROCESS
|
||||
function STATEMACHINE_PROCESS:New( Process, options )
|
||||
function STATEMACHINE_PROCESS:New( FSMT )
|
||||
|
||||
local FsmProcess = routines.utils.deepCopy( self ) -- Create a new self instance
|
||||
local Parent = STATEMACHINE:New(options)
|
||||
local self = BASE:Inherit( self, STATEMACHINE:New( FSMT ) ) -- StateMachine#STATEMACHINE_PROCESS
|
||||
|
||||
setmetatable( FsmProcess, Parent )
|
||||
FsmProcess.__index = FsmProcess
|
||||
|
||||
FsmProcess["onstatechange"] = Process.OnStateChange
|
||||
FsmProcess.Process = Process
|
||||
|
||||
return FsmProcess
|
||||
return self
|
||||
end
|
||||
|
||||
function STATEMACHINE_PROCESS:_call_handler( handler, params )
|
||||
if handler then
|
||||
return handler( self.Process, unpack( params ) )
|
||||
return handler( self, unpack( params ) )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -189,13 +189,14 @@ function UNIT:ReSpawn( SpawnVec3, Heading )
|
||||
|
||||
local SpawnGroupTemplate = UTILS.DeepCopy( _DATABASE:GetGroupTemplateFromUnitName( self:Name() ) )
|
||||
self:T( SpawnGroupTemplate )
|
||||
|
||||
local SpawnGroup = self:GetGroup()
|
||||
|
||||
if SpawnGroup then
|
||||
|
||||
local Vec3 = SpawnGroup:GetVec3()
|
||||
SpawnGroupTemplate.x = Vec3.x
|
||||
SpawnGroupTemplate.y = Vec3.z
|
||||
SpawnGroupTemplate.x = SpawnVec3.x
|
||||
SpawnGroupTemplate.y = SpawnVec3.z
|
||||
|
||||
self:E( #SpawnGroupTemplate.units )
|
||||
for UnitID, UnitData in pairs( SpawnGroup:GetUnits() ) do
|
||||
@@ -222,6 +223,36 @@ function UNIT:ReSpawn( SpawnVec3, Heading )
|
||||
SpawnGroupTemplate.units[UnitTemplateID].y = SpawnVec3.z
|
||||
SpawnGroupTemplate.units[UnitTemplateID].heading = Heading
|
||||
self:E( { UnitTemplateID, SpawnGroupTemplate.units[UnitTemplateID], SpawnGroupTemplate.units[UnitTemplateID] } )
|
||||
else
|
||||
self:E( SpawnGroupTemplate.units[UnitTemplateID].name )
|
||||
local GroupUnit = UNIT:FindByName( SpawnGroupTemplate.units[UnitTemplateID].name ) -- Unit#UNIT
|
||||
if GroupUnit and GroupUnit:IsAlive() then
|
||||
local GroupUnitVec3 = GroupUnit:GetVec3()
|
||||
local GroupUnitHeading = GroupUnit:GetHeading()
|
||||
UnitTemplateData.alt = GroupUnitVec3.y
|
||||
UnitTemplateData.x = GroupUnitVec3.x
|
||||
UnitTemplateData.y = GroupUnitVec3.z
|
||||
UnitTemplateData.heading = GroupUnitHeading
|
||||
else
|
||||
if SpawnGroupTemplate.units[UnitTemplateID].name ~= self:Name() then
|
||||
self:T("nilling")
|
||||
SpawnGroupTemplate.units[UnitTemplateID].delete = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Remove obscolete units from the group structure
|
||||
i = 1
|
||||
while i <= #SpawnGroupTemplate.units do
|
||||
|
||||
local UnitTemplateData = SpawnGroupTemplate.units[i]
|
||||
self:T( UnitTemplateData.name )
|
||||
|
||||
if UnitTemplateData.delete then
|
||||
table.remove( SpawnGroupTemplate.units, i )
|
||||
else
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user