Module AI_Patrol

Single-Player:Yes / Mulit-Player:Yes / AI:Yes / Human:No / Types:Air -- Make AI patrol zones and report detected targets.

Banner Image

Examples can be found in the test missions.


1) #AI_PATROLZONE class, extends Core.Fsm#FSM_CONTROLLABLE

The #AI_PATROLZONE class implements the core functions to patrol a Zone by an AI Controllable or Group. The AIPATROLZONE is assigned a @(Group) and this must be done before the AIPATROLZONE process can be started. The AI will fly towards the random 3D point within the patrol zone, using a random speed within the given altitude and speed limits. Upon arrival at the 3D point, a new random 3D point will be selected within the patrol zone using the given limits. This cycle will continue until a fuel or damage treshold has been reached by the AI, or when the AI is commanded to RTB. 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.2) AI_PATROLZONE is a FSM

Process

1.2.1) AI_PATROLZONE States

  • None ( Group ): The process is not started yet.
  • Patrolling ( Group ): The AI is patrolling the Patrol Zone.
  • Returning ( Group ): The AI is returning to Base..

1.2.2) AI_PATROLZONE Events:

  • Start ( Group ): Start the process.
  • Route ( Group ): Route the AI to a new random 3D point within the Patrol Zone.
  • RTB ( Group ): Route the AI to the home base.
  • Detect ( Group ): The AI is detecting targets.
  • Detected ( Group ): The AI has detected new targets.
  • Status ( Group ): The AI is checking status (fuel and damage). When the tresholds have been reached, the AI will RTB.

1.3) Set or Get the AI controllable

1.4) Set the Speed and Altitude boundaries of the AI controllable

1.5) Manage the detection process of the AI controllable

The detection process of the AI controllable can be manipulated. Detection requires an amount of CPU power, which has an impact on your mission performance. Only put detection on when absolutely necessary, and the frequency of the detection can also be set.

The detection frequency can be set with AI_PATROLZONE.SetDetectionInterval( seconds ), where the amount of seconds specify how much seconds will be waited before the next detection. Use the method AI_PATROLZONE.GetDetectedTargets() to obtain a list of the Units detected by the AI.

The detection can be filtered to potential targets in a specific zone. Use the method AI_PATROLZONE.SetDetectionZone() to set the zone where targets need to be detected. Note that when the zone is too far away, or the AI is not heading towards the zone, or the AI is too high, no targets may be detected according the weather conditions.

1.6) Manage the "out of fuel" in the AI_PATROLZONE

When the AI is out of fuel, it is required that a new AI is started, before the old AI 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 AI will continue for a given time its patrol task in orbit, while a new AI is targetted to the AI_PATROLZONE. Once the time is finished, the old AI will return to the base. Use the method AI_PATROLZONE.ManageFuel() to have this proces in place.

1.7) Manage "damage" behaviour of the AI in the AI_PATROLZONE

When the AI is damaged, it is required that a new AIControllable is started. However, damage cannon be foreseen early on. Therefore, when the damage treshold is reached, the AI will return immediately to the home base (RTB). Use the method AI_PATROLZONE.ManageDamage() 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-01-15: Complete revision. AIPATROLZONE is the base class for other AIPATROL like classes.

2016-09-01: Initial class and API.


AUTHORS and CONTRIBUTIONS

Contributions:

  • Dutch_Baron: Working together with James has resulted in the creation of the AI_BALANCER class. James has shared his ideas on balancing AI with air units, and together we made a first design which you can use now :-)
  • Pikey: Testing and API concept review.

Authors:

  • FlightControl: Design & Programming.

Global(s)

AI_PATROLZONE
_NewPatrolRoute(AIControllable)

Type AI_PATROLZONE

AI_PATROLZONE.AIControllable

The Controllable patrolling.

AI_PATROLZONE.CheckStatus
AI_PATROLZONE.ClassName
AI_PATROLZONE.CoordTest
AI_PATROLZONE:Detect()

Synchronous Event Trigger for Event Detect.

AI_PATROLZONE.DetectInterval
AI_PATROLZONE.DetectUnits
AI_PATROLZONE.DetectZone
AI_PATROLZONE:Detected()

Synchronous Event Trigger for Event Detected.

AI_PATROLZONE.DetectedUnits
AI_PATROLZONE:GetDetectedUnits()

Gets a list of Wrapper.Unit#UNITs that were detected by the AI.

AI_PATROLZONE:ManageDamage(PatrolDamageTreshold)

When the AI is damaged beyond a certain treshold, it is required that the AI returns to the home base.

AI_PATROLZONE:ManageFuel(PatrolFuelTresholdPercentage, PatrolOutOfFuelOrbitTime)

When the AI is out of fuel, it is required that a new AI is started, before the old AI can return to the home base.

AI_PATROLZONE:New(PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed)

Creates a new AI_PATROLZONE object

AI_PATROLZONE:OnAfterDetect(Controllable, From, Event, To)

OnAfter Transition Handler for Event Detect.

AI_PATROLZONE:OnAfterDetected(Controllable, From, Event, To)

OnAfter Transition Handler for Event Detected.

AI_PATROLZONE:OnAfterRTB(Controllable, From, Event, To)

OnAfter Transition Handler for Event RTB.

AI_PATROLZONE:OnAfterRoute(Controllable, From, Event, To)

OnAfter Transition Handler for Event Route.

AI_PATROLZONE:OnAfterStart(Controllable, From, Event, To)

OnAfter Transition Handler for Event Start.

AI_PATROLZONE:OnAfterStatus(Controllable, From, Event, To)

OnAfter Transition Handler for Event Status.

AI_PATROLZONE:OnBeforeDetect(Controllable, From, Event, To)

OnBefore Transition Handler for Event Detect.

AI_PATROLZONE:OnBeforeDetected(Controllable, From, Event, To)

OnBefore Transition Handler for Event Detected.

AI_PATROLZONE:OnBeforeRTB(Controllable, From, Event, To)

OnBefore Transition Handler for Event RTB.

AI_PATROLZONE:OnBeforeRoute(Controllable, From, Event, To)

OnBefore Transition Handler for Event Route.

AI_PATROLZONE:OnBeforeStart(Controllable, From, Event, To)

OnBefore Transition Handler for Event Start.

AI_PATROLZONE:OnBeforeStatus(Controllable, From, Event, To)

OnBefore Transition Handler for Event Status.

AI_PATROLZONE:OnEnterPatrolling(Controllable, From, Event, To)

OnEnter Transition Handler for State Patrolling.

AI_PATROLZONE:OnEnterReturning(Controllable, From, Event, To)

OnEnter Transition Handler for State Returning.

AI_PATROLZONE:OnLeavePatrolling(Controllable, From, Event, To)

OnLeave Transition Handler for State Patrolling.

AI_PATROLZONE:OnLeaveReturning(Controllable, From, Event, To)

OnLeave Transition Handler for State Returning.

AI_PATROLZONE.PatrolCeilingAltitude

The highest altitude in meters where to execute the patrol.

AI_PATROLZONE.PatrolDamageTreshold
AI_PATROLZONE.PatrolFloorAltitude

The lowest altitude in meters where to execute the patrol.

AI_PATROLZONE.PatrolFuelTresholdPercentage
AI_PATROLZONE.PatrolManageDamage
AI_PATROLZONE.PatrolManageFuel
AI_PATROLZONE.PatrolMaxSpeed

The maximum speed of the Controllable in km/h.

AI_PATROLZONE.PatrolMinSpeed

The minimum speed of the Controllable in km/h.

AI_PATROLZONE.PatrolOutOfFuelOrbitTime
AI_PATROLZONE.PatrolZone

The Zone where the patrol needs to be executed.

AI_PATROLZONE:RTB()

Synchronous Event Trigger for Event RTB.

AI_PATROLZONE:Route()

Synchronous Event Trigger for Event Route.

AI_PATROLZONE:SetAltitude(PatrolFloorAltitude, PatrolCeilingAltitude)

Sets the floor and ceiling altitude of the patrol.

AI_PATROLZONE:SetDetectionInterval(Seconds)

Set the interval in seconds between each detection executed by the AI.

AI_PATROLZONE:SetDetectionOff()

Set the detection off.

AI_PATROLZONE:SetDetectionOn()

Set the detection on.

AI_PATROLZONE:SetDetectionZone(DetectionZone)

Set the detection zone where the AI is detecting targets.

AI_PATROLZONE:SetSpeed(PatrolMinSpeed, PatrolMaxSpeed)

Sets (modifies) the minimum and maximum speed of the patrol.

AI_PATROLZONE:Start()

Synchronous Event Trigger for Event Start.

AI_PATROLZONE:Status()

Synchronous Event Trigger for Event Status.

AI_PATROLZONE:__Detect(Delay)

Asynchronous Event Trigger for Event Detect.

AI_PATROLZONE:__Detected(Delay)

Asynchronous Event Trigger for Event Detected.

AI_PATROLZONE:__RTB(Delay)

Asynchronous Event Trigger for Event RTB.

AI_PATROLZONE:__Route(Delay)

Asynchronous Event Trigger for Event Route.

AI_PATROLZONE:__Start(Delay)

Asynchronous Event Trigger for Event Start.

AI_PATROLZONE:__Status(Delay)

Asynchronous Event Trigger for Event Status.

AI_PATROLZONE:onafterDetect(Controllable, From, Event, To)
AI_PATROLZONE:onafterRTB()
AI_PATROLZONE:onafterRoute(Controllable, From, Event, To)

Defines a new patrol route using the Process_PatrolZone parameters and settings.

AI_PATROLZONE:onafterStart(Controllable, From, Event, To)

Defines a new patrol route using the Process_PatrolZone parameters and settings.

AI_PATROLZONE:onafterStatus()
AI_PATROLZONE:onbeforeDetect(Controllable, From, Event, To)
AI_PATROLZONE:onbeforeStatus()

Global(s)

#AI_PATROLZONE AI_PATROLZONE
_NewPatrolRoute(AIControllable)

Parameter

Type AI_Patrol

Type AI_PATROLZONE

AI_PATROLZONE class

Field(s)

Wrapper.Controllable#CONTROLLABLE AI_PATROLZONE.AIControllable

The Controllable patrolling.

#boolean AI_PATROLZONE.CheckStatus
#string AI_PATROLZONE.ClassName
Functional.Spawn#SPAWN AI_PATROLZONE.CoordTest
AI_PATROLZONE:Detect()

Synchronous Event Trigger for Event Detect.

AI_PATROLZONE.DetectInterval
#boolean AI_PATROLZONE.DetectUnits
AI_PATROLZONE.DetectZone
AI_PATROLZONE:Detected()

Synchronous Event Trigger for Event Detected.

AI_PATROLZONE.DetectedUnits

This table contains the targets detected during patrol.

AI_PATROLZONE:GetDetectedUnits()

Gets a list of Wrapper.Unit#UNITs that were detected by the AI.

No filtering is applied, so, ANY detected UNIT can be in this list. It is up to the mission designer to use the Unit class and methods to filter the targets.

Return value

#table: The list of Wrapper.Unit#UNITs

AI_PATROLZONE:ManageDamage(PatrolDamageTreshold)

When the AI is damaged beyond a certain treshold, it is required that the AI returns to the home base.

However, damage cannot be foreseen early on. Therefore, when the damage treshold is reached, the AI will return immediately to the home base (RTB). Note that for groups, the average damage of the complete group will be calculated. So, in a group of 4 airplanes, 2 lost and 2 with damage 0.2, the damage treshold will be 0.25.

Parameter

  • #number PatrolDamageTreshold : The treshold in percentage (between 0 and 1) when the AI is considered to be damaged.

Return value

#AI_PATROLZONE: self

AI_PATROLZONE:ManageFuel(PatrolFuelTresholdPercentage, PatrolOutOfFuelOrbitTime)

When the AI is out of fuel, it is required that a new AI is started, before the old AI 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 AI 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 AI will return to the base.

Parameters

  • #number PatrolFuelTresholdPercentage : The treshold in percentage (between 0 and 1) when the AIControllable is considered to get out of fuel.

  • #number PatrolOutOfFuelOrbitTime : The amount of seconds the out of fuel AIControllable will orbit before returning to the base.

Return value

#AI_PATROLZONE: self

AI_PATROLZONE:New(PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed)

Creates a new AI_PATROLZONE object

Parameters

Return value

#AI_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.
PatrolZone = ZONE:New( 'PatrolZone' )
PatrolSpawn = SPAWN:New( 'Patrol Group' )
PatrolArea = AI_PATROLZONE:New( PatrolZone, 3000, 6000, 600, 900 )
AI_PATROLZONE:OnAfterDetect(Controllable, From, Event, To)

OnAfter Transition Handler for Event Detect.

Parameters

  • Wrapper.Controllable#CONTROLLABLE Controllable : The Controllable Object managed by the FSM.

  • #string From : The From State string.

  • #string Event : The Event string.

  • #string To : The To State string.

AI_PATROLZONE:OnAfterDetected(Controllable, From, Event, To)

OnAfter Transition Handler for Event Detected.

Parameters

  • Wrapper.Controllable#CONTROLLABLE Controllable : The Controllable Object managed by the FSM.

  • #string From : The From State string.

  • #string Event : The Event string.

  • #string To : The To State string.

AI_PATROLZONE:OnAfterRTB(Controllable, From, Event, To)

OnAfter Transition Handler for Event RTB.

Parameters

  • Wrapper.Controllable#CONTROLLABLE Controllable : The Controllable Object managed by the FSM.

  • #string From : The From State string.

  • #string Event : The Event string.

  • #string To : The To State string.

AI_PATROLZONE:OnAfterRoute(Controllable, From, Event, To)

OnAfter Transition Handler for Event Route.

Parameters

  • Wrapper.Controllable#CONTROLLABLE Controllable : The Controllable Object managed by the FSM.

  • #string From : The From State string.

  • #string Event : The Event string.

  • #string To : The To State string.

AI_PATROLZONE:OnAfterStart(Controllable, From, Event, To)

OnAfter Transition Handler for Event Start.

Parameters

  • Wrapper.Controllable#CONTROLLABLE Controllable : The Controllable Object managed by the FSM.

  • #string From : The From State string.

  • #string Event : The Event string.

  • #string To : The To State string.

AI_PATROLZONE:OnAfterStatus(Controllable, From, Event, To)

OnAfter Transition Handler for Event Status.

Parameters

  • Wrapper.Controllable#CONTROLLABLE Controllable : The Controllable Object managed by the FSM.

  • #string From : The From State string.

  • #string Event : The Event string.

  • #string To : The To State string.

AI_PATROLZONE:OnBeforeDetect(Controllable, From, Event, To)

OnBefore Transition Handler for Event Detect.

Parameters

  • Wrapper.Controllable#CONTROLLABLE Controllable : The Controllable Object managed by the FSM.

  • #string From : The From State string.

  • #string Event : The Event string.

  • #string To : The To State string.

Return value

#boolean: Return false to cancel Transition.

AI_PATROLZONE:OnBeforeDetected(Controllable, From, Event, To)

OnBefore Transition Handler for Event Detected.

Parameters

  • Wrapper.Controllable#CONTROLLABLE Controllable : The Controllable Object managed by the FSM.

  • #string From : The From State string.

  • #string Event : The Event string.

  • #string To : The To State string.

Return value

#boolean: Return false to cancel Transition.

AI_PATROLZONE:OnBeforeRTB(Controllable, From, Event, To)

OnBefore Transition Handler for Event RTB.

Parameters

  • Wrapper.Controllable#CONTROLLABLE Controllable : The Controllable Object managed by the FSM.

  • #string From : The From State string.

  • #string Event : The Event string.

  • #string To : The To State string.

Return value

#boolean: Return false to cancel Transition.

AI_PATROLZONE:OnBeforeRoute(Controllable, From, Event, To)

OnBefore Transition Handler for Event Route.

Parameters

  • Wrapper.Controllable#CONTROLLABLE Controllable : The Controllable Object managed by the FSM.

  • #string From : The From State string.

  • #string Event : The Event string.

  • #string To : The To State string.

Return value

#boolean: Return false to cancel Transition.

AI_PATROLZONE:OnBeforeStart(Controllable, From, Event, To)

OnBefore Transition Handler for Event Start.

Parameters

  • Wrapper.Controllable#CONTROLLABLE Controllable : The Controllable Object managed by the FSM.

  • #string From : The From State string.

  • #string Event : The Event string.

  • #string To : The To State string.

Return value

#boolean: Return false to cancel Transition.

AI_PATROLZONE:OnBeforeStatus(Controllable, From, Event, To)

OnBefore Transition Handler for Event Status.

Parameters

  • Wrapper.Controllable#CONTROLLABLE Controllable : The Controllable Object managed by the FSM.

  • #string From : The From State string.

  • #string Event : The Event string.

  • #string To : The To State string.

Return value

#boolean: Return false to cancel Transition.

AI_PATROLZONE:OnEnterPatrolling(Controllable, From, Event, To)

OnEnter Transition Handler for State Patrolling.

Parameters

  • Wrapper.Controllable#CONTROLLABLE Controllable : The Controllable Object managed by the FSM.

  • #string From : The From State string.

  • #string Event : The Event string.

  • #string To : The To State string.

AI_PATROLZONE:OnEnterReturning(Controllable, From, Event, To)

OnEnter Transition Handler for State Returning.

Parameters

  • Wrapper.Controllable#CONTROLLABLE Controllable : The Controllable Object managed by the FSM.

  • #string From : The From State string.

  • #string Event : The Event string.

  • #string To : The To State string.

AI_PATROLZONE:OnLeavePatrolling(Controllable, From, Event, To)

OnLeave Transition Handler for State Patrolling.

Parameters

  • Wrapper.Controllable#CONTROLLABLE Controllable : The Controllable Object managed by the FSM.

  • #string From : The From State string.

  • #string Event : The Event string.

  • #string To : The To State string.

Return value

#boolean: Return false to cancel Transition.

AI_PATROLZONE:OnLeaveReturning(Controllable, From, Event, To)

OnLeave Transition Handler for State Returning.

Parameters

  • Wrapper.Controllable#CONTROLLABLE Controllable : The Controllable Object managed by the FSM.

  • #string From : The From State string.

  • #string Event : The Event string.

  • #string To : The To State string.

Return value

#boolean: Return false to cancel Transition.

Dcs.DCSTypes#Altitude AI_PATROLZONE.PatrolCeilingAltitude

The highest altitude in meters where to execute the patrol.

AI_PATROLZONE.PatrolDamageTreshold
Dcs.DCSTypes#Altitude AI_PATROLZONE.PatrolFloorAltitude

The lowest altitude in meters where to execute the patrol.

AI_PATROLZONE.PatrolFuelTresholdPercentage
#boolean AI_PATROLZONE.PatrolManageDamage
#boolean AI_PATROLZONE.PatrolManageFuel
Dcs.DCSTypes#Speed AI_PATROLZONE.PatrolMaxSpeed

The maximum speed of the Controllable in km/h.

Dcs.DCSTypes#Speed AI_PATROLZONE.PatrolMinSpeed

The minimum speed of the Controllable in km/h.

AI_PATROLZONE.PatrolOutOfFuelOrbitTime
Core.Zone#ZONE_BASE AI_PATROLZONE.PatrolZone

The Zone where the patrol needs to be executed.

AI_PATROLZONE:RTB()

Synchronous Event Trigger for Event RTB.

AI_PATROLZONE:Route()

Synchronous Event Trigger for Event Route.

AI_PATROLZONE:SetAltitude(PatrolFloorAltitude, PatrolCeilingAltitude)

Sets the floor and ceiling altitude of the patrol.

Parameters

  • Dcs.DCSTypes#Altitude PatrolFloorAltitude : The lowest altitude in meters where to execute the patrol.

  • Dcs.DCSTypes#Altitude PatrolCeilingAltitude : The highest altitude in meters where to execute the patrol.

Return value

#AI_PATROLZONE: self

AI_PATROLZONE:SetDetectionInterval(Seconds)

Set the interval in seconds between each detection executed by the AI.

The list of already detected targets will be kept and updated. Newly detected targets will be added, but already detected targets that were not detected in this cycle, will NOT be removed! The default interval is 30 seconds.

Parameter

  • #number Seconds : The interval in seconds.

Return value

#AI_PATROLZONE: self

AI_PATROLZONE:SetDetectionOff()

Set the detection off.

The AI will NOT detect for targets. However, the list of already detected targets will be kept and can be enquired!

Return value

#AI_PATROLZONE: self

AI_PATROLZONE:SetDetectionOn()

Set the detection on.

The AI will detect for targets.

Return value

#AI_PATROLZONE: self

AI_PATROLZONE:SetDetectionZone(DetectionZone)

Set the detection zone where the AI is detecting targets.

Parameter

Return value

#AI_PATROLZONE: self

AI_PATROLZONE:SetSpeed(PatrolMinSpeed, PatrolMaxSpeed)

Sets (modifies) the minimum and maximum speed of the patrol.

Parameters

Return value

#AI_PATROLZONE: self

AI_PATROLZONE:Start()

Synchronous Event Trigger for Event Start.

AI_PATROLZONE:Status()

Synchronous Event Trigger for Event Status.

AI_PATROLZONE:__Detect(Delay)

Asynchronous Event Trigger for Event Detect.

Parameter

  • #number Delay : The delay in seconds.

AI_PATROLZONE:__Detected(Delay)

Asynchronous Event Trigger for Event Detected.

Parameter

  • #number Delay : The delay in seconds.

AI_PATROLZONE:__RTB(Delay)

Asynchronous Event Trigger for Event RTB.

Parameter

  • #number Delay : The delay in seconds.

AI_PATROLZONE:__Route(Delay)

Asynchronous Event Trigger for Event Route.

Parameter

  • #number Delay : The delay in seconds.

AI_PATROLZONE:__Start(Delay)

Asynchronous Event Trigger for Event Start.

Parameter

  • #number Delay : The delay in seconds.

AI_PATROLZONE:__Status(Delay)

Asynchronous Event Trigger for Event Status.

Parameter

  • #number Delay : The delay in seconds.

AI_PATROLZONE:onafterDetect(Controllable, From, Event, To)

Parameters

  • Controllable :

  • From :

  • Event :

  • To :

AI_PATROLZONE:onafterRTB()
AI_PATROLZONE:onafterRoute(Controllable, From, Event, To)

Defines a new patrol route using the Process_PatrolZone parameters and settings.

Parameters

  • Wrapper.Controllable#CONTROLLABLE Controllable : The Controllable Object managed by the FSM.

  • #string From : The From State string.

  • #string Event : The Event string.

  • #string To : The To State string.

AI_PATROLZONE:onafterStart(Controllable, From, Event, To)

Defines a new patrol route using the Process_PatrolZone parameters and settings.

Parameters

  • Wrapper.Controllable#CONTROLLABLE Controllable : The Controllable Object managed by the FSM.

  • #string From : The From State string.

  • #string Event : The Event string.

  • #string To : The To State string.

Return value

#AI_PATROLZONE: self

AI_PATROLZONE:onafterStatus()
AI_PATROLZONE:onbeforeDetect(Controllable, From, Event, To)

Parameters

  • Controllable :

  • From :

  • Event :

  • To :

AI_PATROLZONE:onbeforeStatus()