Module Functional.ZoneCaptureCoalition
Functional -- Models the process to zone guarding and capturing.
Features:
- Models the possible state transitions between the Guarded, Attacked, Empty and Captured states.
- A zone has an owning coalition, that means that at a specific point in time, a zone can be owned by the red or blue coalition.
- Provide event handlers to tailor the actions when a zone changes coalition or state.
Missions:
Player Experience
The above models the possible state transitions between the Guarded, Attacked, Empty and Captured states.
A zone has an owning coalition, that means that at a specific point in time, a zone can be owned by the red or blue coalition.
The Zone can be in the state Guarded by the owning coalition, which is the coalition that initially occupies the zone with units of its coalition.
Once units of an other coalition are entering the Zone, the state will change to Attacked. As long as these units remain in the zone, the state keeps set to Attacked.
When all units are destroyed in the Zone, the state will change to Empty, which expresses that the Zone is empty, and can be captured.
When units of the other coalition are in the Zone, and no other units of the owning coalition is in the Zone, the Zone is captured, and its state will change to Captured.
The zone needs to be monitored regularly for the presence of units to interprete the correct state transition required.
This monitoring process MUST be started using the ZONE_CAPTURE_COALITION.Start() method.
Otherwise no monitoring will be active and the zone will stay in the current state forever.
YouTube Playlist
Author: FlightControl
Contributions: Millertime - Concept
Global(s)
Global ZONE_CAPTURE_COALITION |
Models the process to capture a Zone for a Coalition, which is guarded by another Coalition. |
Models the process to capture a Zone for a Coalition, which is guarded by another Coalition.
This is a powerful concept that allows to create very dynamic missions based on the different state transitions of various zones.
In order to use ZONE_CAPTURE_COALITION, you need to:
- Create a Zone object from one of the ZONE_ classes.
Note that ZONE_POLYGON_ classes are not yet functional.
The only functional ZONE_ classses are those derived from a ZONE_RADIUS. - Set the state of the zone. Most of the time, Guarded would be the initial state.
- Start the zone capturing monitoring process.
This will check the presence of friendly and/or enemy units within the zone and will transition the state of the zone when the tactical situation changed. The frequency of the monitoring must not be real-time, a 30 second interval to execute the checks is sufficient.
Important:
You must start the monitoring process within your code, or there won't be any state transition checks executed.
See further the start/stop monitoring process.
Important:
Ensure that the object containing the ZONE_CAPTURE_COALITION object is persistent.
Otherwise the garbage collector of lua will remove the object and the monitoring process will stop.
This will result in your object to be destroyed (removed) from internal memory and there won't be any zone state transitions anymore detected!
So use the local keyword in lua with thought! Most of the time, you can declare your object gobally.
Example:
-- Define a new ZONE object, which is based on the trigger zone `CaptureZone`, which is defined within the mission editor.
CaptureZone = ZONE:New( "CaptureZone" )
-- Here we create a new ZONE_CAPTURE_COALITION object, using the :New constructor.
ZoneCaptureCoalition = ZONE_CAPTURE_COALITION:New( CaptureZone, coalition.side.RED )
-- Set the zone to Guarding state.
ZoneCaptureCoalition:__Guard( 1 )
-- Start the zone monitoring process in 30 seconds and check every 30 seconds.
ZoneCaptureCoalition:Start( 30, 30 )
Constructor:
Use the ZONE_CAPTURE_COALITION.New() constructor to create a new ZONE_CAPTURE_COALITION object.
ZONE_CAPTURE_COALITION is a finite state machine (FSM).
ZONE_CAPTURE_COALITION States
- Captured: The Zone has been captured by an other coalition.
- Attacked: The Zone is currently intruded by an other coalition. There are units of the owning coalition and an other coalition in the Zone.
- Guarded: The Zone is guarded by the owning coalition. There is no other unit of an other coalition in the Zone.
- Empty: The Zone is empty. There is not valid unit in the Zone.
2.2 ZONE_CAPTURE_COALITION Events
- Capture: The Zone has been captured by an other coalition.
- Attack: The Zone is currently intruded by an other coalition. There are units of the owning coalition and an other coalition in the Zone.
- Guard: The Zone is guarded by the owning coalition. There is no other unit of an other coalition in the Zone.
- Empty: The Zone is empty. There is not valid unit in the Zone.
"Script It"
ZONE_CAPTURE_COALITION allows to take action on the various state transitions and add your custom code and logic.
Take action using state- and event handlers.
The most important to understand is how states and events can be tailored. Carefully study the diagram and the explanations.
State Handlers capture the moment:
- On Leave from the old state. Return false to cancel the transition.
- On Enter to the new state.
Event Handlers capture the moment:
- On Before the event is triggered. Return false to cancel the transition.
- On After the event is triggered.
Each handler can receive optionally 3 parameters:
- From: A string containing the From State.
- Event: A string containing the Event.
- To: A string containing the To State.
The mission designer can use these values to alter the logic. For example:
--- @param Functional.ZoneCaptureCoalition#ZONE_CAPTURE_COALITION self
function ZoneCaptureCoalition:OnEnterGuarded( From, Event, To )
if From ~= "Empty" then
-- Display a message
end
end
This code checks that when the Guarded state has been reached, that if the From state was Empty, then display a message.
Example Event Handler.
--- @param Functional.ZoneCaptureCoalition#ZONE_CAPTURE_COALITION self
function ZoneCaptureCoalition:OnEnterGuarded( From, Event, To )
if From ~= To then
local Coalition = self:GetCoalition()
self:E( { Coalition = Coalition } )
if Coalition == coalition.side.BLUE then
ZoneCaptureCoalition:Smoke( SMOKECOLOR.Blue )
US_CC:MessageTypeToCoalition( string.format( "%s is under protection of the USA", ZoneCaptureCoalition:GetZoneName() ), MESSAGE.Type.Information )
RU_CC:MessageTypeToCoalition( string.format( "%s is under protection of the USA", ZoneCaptureCoalition:GetZoneName() ), MESSAGE.Type.Information )
else
ZoneCaptureCoalition:Smoke( SMOKECOLOR.Red )
RU_CC:MessageTypeToCoalition( string.format( "%s is under protection of Russia", ZoneCaptureCoalition:GetZoneName() ), MESSAGE.Type.Information )
US_CC:MessageTypeToCoalition( string.format( "%s is under protection of Russia", ZoneCaptureCoalition:GetZoneName() ), MESSAGE.Type.Information )
end
end
end
Stop and Start the zone monitoring process.
At regular intervals, the state of the zone needs to be monitored. The zone needs to be scanned for the presence of units within the zone boundaries. Depending on the owning coalition of the zone and the presence of units (of the owning and/or other coalition(s)), the zone will transition to another state.
However, ... this scanning process is rather CPU intensive. Imagine you have 10 of these capture zone objects setup within your mission. That would mean that your mission would check 10 capture zones simultaneously, each checking for the presence of units. It would be highly CPU inefficient, as some of these zones are not required to be monitored (yet).
Therefore, the mission designer is given 2 methods that allow to take control of the CPU utilization efficiency:
- ZONE_CAPTURE_COALITION.Start(): This starts the monitoring process.
- ZONE_CAPTURE_COALITION.Stop(): This stops the monitoring process.
IMPORTANT
Each capture zone object must have the monitoring process started specifically. The monitoring process is NOT started by default!!!
Full Example
The following annotated code shows a real example of how ZONE_CAPTURE_COALITION can be applied.
The concept is simple.
The USA (US), blue coalition, needs to capture the Russian (RU), red coalition, zone, which is near groom lake.
A capture zone has been setup that guards the presence of the troops. Troops are guarded by red forces. Blue is required to destroy the red forces and capture the zones.
At first, we setup the Command Centers
do
RU_CC = COMMANDCENTER:New( GROUP:FindByName( "REDHQ" ), "Russia HQ" )
US_CC = COMMANDCENTER:New( GROUP:FindByName( "BLUEHQ" ), "USA HQ" )
end
Next, we define the mission, and add some scoring to it.
do -- Missions
US_Mission_EchoBay = MISSION:New( US_CC, "Echo Bay", "Primary",
"Welcome trainee. The airport Groom Lake in Echo Bay needs to be captured.\n" ..
"There are five random capture zones located at the airbase.\n" ..
"Move to one of the capture zones, destroy the fuel tanks in the capture zone, " ..
"and occupy each capture zone with a platoon.\n " ..
"Your orders are to hold position until all capture zones are taken.\n" ..
"Use the map (F10) for a clear indication of the location of each capture zone.\n" ..
"Note that heavy resistance can be expected at the airbase!\n" ..
"Mission 'Echo Bay' is complete when all five capture zones are taken, and held for at least 5 minutes!"
, coalition.side.RED )
US_Mission_EchoBay:Start()
end
Now the real work starts. We define a CaptureZone object, which is a ZONE object. Within the mission, a trigger zone is created with the name CaptureZone, with the defined radius within the mission editor.
CaptureZone = ZONE:New( "CaptureZone" )
Next, we define the ZoneCaptureCoalition object, as explained above.
ZoneCaptureCoalition = ZONE_CAPTURE_COALITION:New( CaptureZone, coalition.side.RED )
Of course, we want to let the ZoneCaptureCoalition object do something when the state transitions. Do accomodate this, it is very simple, as explained above. We use Event Handlers to tailor the logic.
Here we place an Event Handler at the Guarded event. So when the Guarded event is triggered, then this method is called! With the variables From, Event, To. Each of these variables containing a string.
We check if the previous state wasn't Guarded also.
If not, we retrieve the owning Coalition of the ZoneCaptureCoalition, using self:GetCoalition().
So Coalition will contain the current owning coalition of the zone.
Depending on the zone ownership, different messages are sent.
Note the methods ZoneCaptureCoalition:GetZoneName().
--- @param Functional.ZoneCaptureCoalition#ZONE_CAPTURE_COALITION self
function ZoneCaptureCoalition:OnEnterGuarded( From, Event, To )
if From ~= To then
local Coalition = self:GetCoalition()
self:E( { Coalition = Coalition } )
if Coalition == coalition.side.BLUE then
ZoneCaptureCoalition:Smoke( SMOKECOLOR.Blue )
US_CC:MessageTypeToCoalition( string.format( "%s is under protection of the USA", ZoneCaptureCoalition:GetZoneName() ), MESSAGE.Type.Information )
RU_CC:MessageTypeToCoalition( string.format( "%s is under protection of the USA", ZoneCaptureCoalition:GetZoneName() ), MESSAGE.Type.Information )
else
ZoneCaptureCoalition:Smoke( SMOKECOLOR.Red )
RU_CC:MessageTypeToCoalition( string.format( "%s is under protection of Russia", ZoneCaptureCoalition:GetZoneName() ), MESSAGE.Type.Information )
US_CC:MessageTypeToCoalition( string.format( "%s is under protection of Russia", ZoneCaptureCoalition:GetZoneName() ), MESSAGE.Type.Information )
end
end
end
As you can see, not a rocket science.
Next is the Event Handler when the Empty state transition is triggered.
Now we smoke the ZoneCaptureCoalition with a green color, using self:Smoke( SMOKECOLOR.Green ).
--- @param Functional.Protect#ZONE_CAPTURE_COALITION self
function ZoneCaptureCoalition:OnEnterEmpty()
self:Smoke( SMOKECOLOR.Green )
US_CC:MessageTypeToCoalition( string.format( "%s is unprotected, and can be captured!", ZoneCaptureCoalition:GetZoneName() ), MESSAGE.Type.Information )
RU_CC:MessageTypeToCoalition( string.format( "%s is unprotected, and can be captured!", ZoneCaptureCoalition:GetZoneName() ), MESSAGE.Type.Information )
end
The next Event Handlers speak for itself. When the zone is Attacked, we smoke the zone white and send some messages to each coalition.
--- @param Functional.Protect#ZONE_CAPTURE_COALITION self
function ZoneCaptureCoalition:OnEnterAttacked()
ZoneCaptureCoalition:Smoke( SMOKECOLOR.White )
local Coalition = self:GetCoalition()
self:E({Coalition = Coalition})
if Coalition == coalition.side.BLUE then
US_CC:MessageTypeToCoalition( string.format( "%s is under attack by Russia", ZoneCaptureCoalition:GetZoneName() ), MESSAGE.Type.Information )
RU_CC:MessageTypeToCoalition( string.format( "We are attacking %s", ZoneCaptureCoalition:GetZoneName() ), MESSAGE.Type.Information )
else
RU_CC:MessageTypeToCoalition( string.format( "%s is under attack by the USA", ZoneCaptureCoalition:GetZoneName() ), MESSAGE.Type.Information )
US_CC:MessageTypeToCoalition( string.format( "We are attacking %s", ZoneCaptureCoalition:GetZoneName() ), MESSAGE.Type.Information )
end
end
When the zone is Captured, we send some victory or loss messages to the correct coalition. And we add some score.
--- @param Functional.Protect#ZONE_CAPTURE_COALITION self
function ZoneCaptureCoalition:OnEnterCaptured()
local Coalition = self:GetCoalition()
self:E({Coalition = Coalition})
if Coalition == coalition.side.BLUE then
RU_CC:MessageTypeToCoalition( string.format( "%s is captured by the USA, we lost it!", ZoneCaptureCoalition:GetZoneName() ), MESSAGE.Type.Information )
US_CC:MessageTypeToCoalition( string.format( "We captured %s, Excellent job!", ZoneCaptureCoalition:GetZoneName() ), MESSAGE.Type.Information )
else
US_CC:MessageTypeToCoalition( string.format( "%s is captured by Russia, we lost it!", ZoneCaptureCoalition:GetZoneName() ), MESSAGE.Type.Information )
RU_CC:MessageTypeToCoalition( string.format( "We captured %s, Excellent job!", ZoneCaptureCoalition:GetZoneName() ), MESSAGE.Type.Information )
end
self:__Guard( 30 )
end
And this call is the most important of all! In the context of the mission, we need to start the zone capture monitoring process. Or nothing will be monitored and the zone won't change states. We start the monitoring after 5 seconds, and will repeat every 30 seconds a check.
ZoneCaptureCoalition:Start( 5, 30 )
Type(s)
| Fields and Methods inherited from ZONE_CAPTURE_COALITION | Description |
|---|---|
|
Attack Trigger for ZONE_CAPTURE_COALITION |
|
|
Capture Trigger for ZONE_CAPTURE_COALITION |
|
|
Empty Trigger for ZONE_CAPTURE_COALITION |
|
|
Guard Trigger for ZONE_CAPTURE_COALITION |
|
|
Mark. |
|
|
ZONE_CAPTURE_COALITION Constructor. |
|
|
Attack Handler OnAfter for ZONE_CAPTURE_COALITION |
|
|
Capture Handler OnAfter for ZONE_CAPTURE_COALITION |
|
|
Empty Handler OnAfter for ZONE_CAPTURE_COALITION |
|
|
Guard Handler OnAfter for ZONE_CAPTURE_COALITION |
|
|
Attack Handler OnBefore for ZONE_CAPTURE_COALITION |
|
|
Capture Handler OnBefore for ZONE_CAPTURE_COALITION |
|
|
Empty Handler OnBefore for ZONE_CAPTURE_COALITION |
|
|
Guard Handler OnBefore for ZONE_CAPTURE_COALITION |
|
|
Starts the zone capturing monitoring process. |
|
|
Check status Coalition ownership. |
|
|
Stops the zone capturing monitoring process. |
|
|
Attack Asynchronous Trigger for ZONE_CAPTURE_COALITION |
|
|
Capture Asynchronous Trigger for ZONE_CAPTURE_COALITION |
|
|
Empty Asynchronous Trigger for ZONE_CAPTURE_COALITION |
|
|
Guard Asynchronous Trigger for ZONE_CAPTURE_COALITION |
|
|
When started, check the Coalition status. |
|
|
Bound. |
| Fields and Methods inherited from ZONE_GOAL_COALITION | Description |
|---|---|
|
Get the owning coalition of the zone. |
|
|
Get the owning coalition name of the zone. |
|
|
ZONE_GOAL_COALITION Constructor. |
|
|
Set the owning coalition of the zone. |
|
|
Check status Coalition ownership. |
| Fields and Methods inherited from ZONE_GOAL | Description |
|---|---|
ZONE_CAPTURE_COALITION:OnAfterDestroyedUnit(From, Event, To, DestroyedUnit, PlayerName) |
DestroyedUnit Handler OnAfter for ZONE_GOAL |
| Fields and Methods inherited from FSM | Description |
|---|---|
|
Adds an End state. |
|
ZONE_CAPTURE_COALITION:AddProcess(From, Event, Process, ReturnEvents) |
Set the default Process template with key ProcessName providing the ProcessClass and the process object when it is assigned to a Wrapper.Controllable by the task. |
|
Adds a score for the FSM to be achieved. |
|
ZONE_CAPTURE_COALITION:AddScoreProcess(From, Event, State, ScoreText, Score) |
Adds a score for the FSM_PROCESS to be achieved. |
|
Add a new transition rule to the FSM. |
|
|
Returns the End states. |
|
|
Returns a table of the SubFSM rules defined within the FSM. |
|
|
Returns a table with the scores defined. |
|
|
Returns the start state of the FSM. |
|
|
Returns a table with the Subs defined. |
|
|
Returns a table of the transition rules defined within the FSM. |
|
|
Creates a new FSM object. |
|
|
Sets the start state of the FSM. |
|
ZONE_CAPTURE_COALITION:_call_handler(step, trigger, params, EventName) |
|
| Fields and Methods inherited from BASE | Description |
|---|---|
|
The ID number of the class. |
|
|
The name of the class. |
|
|
The name of the class concatenated with the ID number of the class. |
|
|
Clear the state of an object. |
|
ZONE_CAPTURE_COALITION:CreateEventBirth(EventTime, Initiator, IniUnitName, place, subplace) |
Creation of a Birth Event. |
ZONE_CAPTURE_COALITION:CreateEventCrash(EventTime, Initiator) |
Creation of a Crash Event. |
ZONE_CAPTURE_COALITION:CreateEventDead(EventTime, Initiator) |
Creation of a Dead Event. |
ZONE_CAPTURE_COALITION:CreateEventRemoveUnit(EventTime, Initiator) |
Creation of a Remove Unit Event. |
ZONE_CAPTURE_COALITION:CreateEventTakeoff(EventTime, Initiator) |
Creation of a Takeoff Event. |
|
Log an exception which will be traced always. |
|
|
Returns the event dispatcher |
|
|
Remove all subscribed events |
|
|
Trace a function call. |
|
|
Trace a function call level 2. |
|
|
Trace a function call level 3. |
|
|
Get the ClassID of the class instance. |
|
|
Get the ClassName of the class instance. |
|
|
Get the ClassName + ClassID of the class instance. |
|
|
Get the Class Event processing Priority. |
|
|
This is the worker method to retrieve the Parent class. |
|
|
Get a Value given a Key from the Object. |
|
|
Subscribe to a DCS Event. |
|
|
Log an information which will be traced always. |
|
|
This is the worker method to inherit from a parent class. |
|
|
This is the worker method to check if an object is an (sub)instance of a class. |
|
|
Enquires if tracing is on (for the class). |
|
|
BASE constructor. |
|
|
Occurs when an object is completely destroyed. |
|
|
Occurs when a ground unit captures either an airbase or a farp. |
|
|
Occurs when any object is spawned into the mission. |
|
|
Occurs when any aircraft crashes into the ground and is completely destroyed. |
|
|
Occurs when an object is dead. |
|
|
Occurs when a pilot ejects from an aircraft initiator : The unit that has ejected |
|
|
Occurs when any aircraft shuts down its engines. |
|
|
Occurs when any aircraft starts its engines. |
|
|
Occurs whenever an object is hit by a weapon. |
|
|
Occurs when any system fails on a human controlled aircraft. |
|
|
Occurs when an aircraft lands at an airbase, farp or ship initiator : The unit that has landed place: Object that the unit landed on. |
|
|
Occurs when a mission ends |
|
|
Occurs when a mission starts |
|
|
Occurs when the pilot of an aircraft is killed. |
|
|
Occurs when any player assumes direct control of a unit. |
|
|
Occurs when any player relieves control of a unit to the AI. |
|
|
Occurs when an aircraft connects with a tanker and begins taking on fuel. |
|
|
Occurs when an aircraft is finished taking fuel. |
|
|
Occurs when any unit stops firing its weapon. |
|
|
Occurs when any unit begins firing a weapon that has a high rate of fire. |
|
|
Occurs whenever any unit in a mission fires a weapon. |
|
|
Occurs when an aircraft takes off from an airbase, farp, or ship. |
|
ZONE_CAPTURE_COALITION:ScheduleOnce(Start, SchedulerFunction, ...) |
Schedule a new time event. |
ZONE_CAPTURE_COALITION:ScheduleRepeat(Start, Repeat, RandomizeFactor, Stop, SchedulerFunction, ...) |
Schedule a new time event. |
|
Stops the Schedule. |
|
|
Set the Class Event processing Priority. |
|
|
Set a state or property of the Object given a Key and a Value. |
|
|
Trace a function logic level 1. |
|
|
Trace a function logic level 2. |
|
|
Trace a function logic level 3. |
|
|
Trace all methods in MOOSE |
|
|
Set tracing for a class |
|
|
Set tracing for a specific method of class |
|
|
Set trace level |
|
|
Set trace on or off Note that when trace is off, no BASE.Debug statement is performed, increasing performance! When Moose is loaded statically, (as one file), tracing is switched off by default. |
|
|
UnSubscribe to a DCS event. |
|
ZONE_CAPTURE_COALITION:_F(Arguments, DebugInfoCurrentParam, DebugInfoFromParam) |
Trace a function call. |
ZONE_CAPTURE_COALITION:_T(Arguments, DebugInfoCurrentParam, DebugInfoFromParam) |
Trace a function logic. |
Field(s)
Function(s)
Attack Trigger for ZONE_CAPTURE_COALITION
Defined in:
ZONE_CAPTURE_COALITION
Capture Trigger for ZONE_CAPTURE_COALITION
Defined in:
ZONE_CAPTURE_COALITION
Empty Trigger for ZONE_CAPTURE_COALITION
Defined in:
ZONE_CAPTURE_COALITION
Guard Trigger for ZONE_CAPTURE_COALITION
Defined in:
ZONE_CAPTURE_COALITION
Defined in:
ZONE_CAPTURE_COALITION
Defined in:
ZONE_CAPTURE_COALITION
Defined in:
ZONE_CAPTURE_COALITION
Defined in:
ZONE_CAPTURE_COALITION
ZONE_CAPTURE_COALITION Constructor.
Defined in:
ZONE_CAPTURE_COALITION
Parameters:
Core.Zone#ZONE Zone
A Zone object with the goal to be achieved.
DCSCoalition.DCSCoalition#coalition Coalition
The initial coalition owning the zone.
Return value:
Usage:
AttackZone = ZONE:New( "AttackZone" )
ZoneCaptureCoalition = ZONE_CAPTURE_COALITION:New( AttackZone, coalition.side.RED ) -- Create a new ZONE_CAPTURE_COALITION object of zone AttackZone with ownership RED coalition.
ZoneCaptureCoalition:__Guard( 1 ) -- Start the Guarding of the AttackZone.
Attack Handler OnAfter for ZONE_CAPTURE_COALITION
Defined in:
ZONE_CAPTURE_COALITION
Parameters:
#string From
#string Event
#string To
Capture Handler OnAfter for ZONE_CAPTURE_COALITION
Defined in:
ZONE_CAPTURE_COALITION
Parameters:
#string From
#string Event
#string To
Empty Handler OnAfter for ZONE_CAPTURE_COALITION
Defined in:
ZONE_CAPTURE_COALITION
Parameters:
#string From
#string Event
#string To
Guard Handler OnAfter for ZONE_CAPTURE_COALITION
Defined in:
ZONE_CAPTURE_COALITION
Parameters:
#string From
#string Event
#string To
Attack Handler OnBefore for ZONE_CAPTURE_COALITION
Defined in:
ZONE_CAPTURE_COALITION
Parameters:
#string From
#string Event
#string To
Return value:
#boolean:
Capture Handler OnBefore for ZONE_CAPTURE_COALITION
Defined in:
ZONE_CAPTURE_COALITION
Parameters:
#string From
#string Event
#string To
Return value:
#boolean:
Empty Handler OnBefore for ZONE_CAPTURE_COALITION
Defined in:
ZONE_CAPTURE_COALITION
Parameters:
#string From
#string Event
#string To
Return value:
#boolean:
Guard Handler OnBefore for ZONE_CAPTURE_COALITION
Defined in:
ZONE_CAPTURE_COALITION
Parameters:
#string From
#string Event
#string To
Return value:
#boolean:
Starts the zone capturing monitoring process.
This process can be CPU intensive, ensure that you specify reasonable time intervals for the monitoring process.
Note that the monitoring process is NOT started automatically during the :New() constructor.
It is advised that the zone monitoring process is only started when the monitoring is of relevance in context of the current mission goals.
When the zone is of no relevance, it is advised NOT to start the monitoring process, or to stop the monitoring process to save CPU resources.
Therefore, the mission designer will need to use the :Start() method within his script to start the monitoring process specifically.
Defined in:
ZONE_CAPTURE_COALITION
Parameters:
#number StartInterval
(optional) Specifies the start time interval in seconds when the zone state will be checked for the first time.
#number RepeatInterval
(optional) Specifies the repeat time interval in seconds when the zone state will be checked repeatedly.
Usage:
-- Setup the zone.
CaptureZone = ZONE:New( "CaptureZone" )
ZoneCaptureCoalition = ZONE_CAPTURE_COALITION:New( CaptureZone, coalition.side.RED )
-- This starts the monitoring process within 15 seconds, repeating every 15 seconds.
ZoneCaptureCoalition:Start()
-- This starts the monitoring process immediately, but repeats every 30 seconds.
ZoneCaptureCoalition:Start( 0, 30 )
Check status Coalition ownership.
Defined in:
ZONE_CAPTURE_COALITION
Stops the zone capturing monitoring process.
When the zone capturing monitor process is stopped, there won't be any changes anymore in the state and the owning coalition of the zone. This method becomes really useful when the zone is of no relevance anymore within a long lasting mission. In this case, it is advised to stop the monitoring process, not to consume unnecessary the CPU intensive scanning of units presence within the zone.
Defined in:
ZONE_CAPTURE_COALITION
Usages:
-- Setup the zone. CaptureZone = ZONE:New( "CaptureZone" ) ZoneCaptureCoalition = ZONE_CAPTURE_COALITION:New( CaptureZone, coalition.side.RED ) -- This starts the monitoring process within 15 seconds, repeating every 15 seconds. ZoneCaptureCoalition:Start() -- When the zone capturing is of no relevance anymore, stop the monitoring! ZoneCaptureCoalition:Stop()-- For example, one could stop the monitoring when the zone was captured! --- @param Functional.Protect#ZONE_CAPTURE_COALITION self function ZoneCaptureCoalition:OnEnterCaptured() local Coalition = self:GetCoalition() self:E({Coalition = Coalition}) if Coalition == coalition.side.BLUE then RU_CC:MessageTypeToCoalition( string.format( "%s is captured by the USA, we lost it!", ZoneCaptureCoalition:GetZoneName() ), MESSAGE.Type.Information ) US_CC:MessageTypeToCoalition( string.format( "We captured %s, Excellent job!", ZoneCaptureCoalition:GetZoneName() ), MESSAGE.Type.Information ) else US_CC:MessageTypeToCoalition( string.format( "%s is captured by Russia, we lost it!", ZoneCaptureCoalition:GetZoneName() ), MESSAGE.Type.Information ) RU_CC:MessageTypeToCoalition( string.format( "We captured %s, Excellent job!", ZoneCaptureCoalition:GetZoneName() ), MESSAGE.Type.Information ) end self:AddScore( "Captured", "Zone captured: Extra points granted.", 200 ) self:Stop() end
Attack Asynchronous Trigger for ZONE_CAPTURE_COALITION
Defined in:
ZONE_CAPTURE_COALITION
Parameter:
#number Delay
Capture Asynchronous Trigger for ZONE_CAPTURE_COALITION
Defined in:
ZONE_CAPTURE_COALITION
Parameter:
#number Delay
Empty Asynchronous Trigger for ZONE_CAPTURE_COALITION
Defined in:
ZONE_CAPTURE_COALITION
Parameter:
#number Delay
Guard Asynchronous Trigger for ZONE_CAPTURE_COALITION
Defined in:
ZONE_CAPTURE_COALITION
Parameter:
#number Delay
When started, check the Coalition status.
Defined in:
ZONE_CAPTURE_COALITION
Defined in:
ZONE_CAPTURE_COALITION
Defined in:
ZONE_CAPTURE_COALITION
Defined in:
ZONE_CAPTURE_COALITION
Field(s)
Function(s)
Get the owning coalition of the zone.
Defined in:
Return value:
Coalition.
Get the owning coalition name of the zone.
ZONE_GOAL_COALITION Constructor.
Defined in:
Parameters:
Core.Zone#ZONE Zone
A Zone object with the goal to be achieved.
DCSCoalition.DCSCoalition#coalition Coalition
The initial coalition owning the zone.
Return value:
Set the owning coalition of the zone.
Check status Coalition ownership.
Defined in:
Field(s)
Function(s)
DestroyedUnit Handler OnAfter for ZONE_GOAL
Defined in:
Parameters:
#string From
#string Event
#string To
Wrapper.Unit#UNIT DestroyedUnit
The destroyed unit.
#string PlayerName
The name of the player.
Field(s)
Function(s)
Adds an End state.
Set the default Process template with key ProcessName providing the ProcessClass and the process object when it is assigned to a Wrapper.Controllable by the task.
Defined in:
Parameters:
#table From
Can contain a string indicating the From state or a table of strings containing multiple From states.
#string Event
The Event name.
Core.Fsm#FSM_PROCESS Process
An sub-process FSM.
#table ReturnEvents
A table indicating for which returned events of the SubFSM which Event must be triggered in the FSM.
Return value:
The SubFSM.
Adds a score for the FSM to be achieved.
Defined in:
Parameters:
#string State
is the state of the process when the score needs to be given. (See the relevant state descriptions of the process).
#string ScoreText
is a text describing the score that is given according the status.
#number Score
is a number providing the score of the status.
Return value:
#FSM:
self
Adds a score for the FSM_PROCESS to be achieved.
Defined in:
Parameters:
#string From
is the From State of the main process.
#string Event
is the Event of the main process.
#string State
is the state of the process when the score needs to be given. (See the relevant state descriptions of the process).
#string ScoreText
is a text describing the score that is given according the status.
#number Score
is a number providing the score of the status.
Return value:
#FSM:
self
Add a new transition rule to the FSM.
A transition rule defines when and if the FSM can transition from a state towards another state upon a triggered event.
Defined in:
Parameters:
#table From
Can contain a string indicating the From state or a table of strings containing multiple From states.
#string Event
The Event name.
#string To
The To state.
Defined in:
Returns a table of the SubFSM rules defined within the FSM.
Returns a table with the scores defined.
Defined in:
Returns the start state of the FSM.
Defined in:
Returns a table of the transition rules defined within the FSM.
Sets the start state of the FSM.
Field(s)
Function(s)
Clear the state of an object.
Defined in:
Parameters:
Object
The object that holds the Value set by the Key.
StateName
The key that is should be cleared.
Creation of a Birth Event.
Defined in:
Parameters:
DCS#Time EventTime
The time stamp of the event.
DCS#Object Initiator
The initiating object of the event.
#string IniUnitName
The initiating unit name.
place
subplace
Creation of a Crash Event.
Defined in:
Parameters:
DCS#Time EventTime
The time stamp of the event.
DCS#Object Initiator
The initiating object of the event.
Creation of a Dead Event.
Defined in:
Parameters:
DCS#Time EventTime
The time stamp of the event.
DCS#Object Initiator
The initiating object of the event.
Creation of a Remove Unit Event.
Defined in:
Parameters:
DCS#Time EventTime
The time stamp of the event.
DCS#Object Initiator
The initiating object of the event.
Creation of a Takeoff Event.
Defined in:
Parameters:
DCS#Time EventTime
The time stamp of the event.
DCS#Object Initiator
The initiating object of the event.
Log an exception which will be traced always.
Can be anywhere within the function logic.
Returns the event dispatcher
Remove all subscribed events
Trace a function call.
Must be at the beginning of the function logic.
Trace a function call level 2.
Must be at the beginning of the function logic.
Trace a function call level 3.
Must be at the beginning of the function logic.
Get the ClassID of the class instance.
Get the ClassName of the class instance.
Get the ClassName + ClassID of the class instance.
The ClassName + ClassID is formatted as '%s#%09d'.
Get the Class Event processing Priority.
The Event processing Priority is a number from 1 to 10, reflecting the order of the classes subscribed to the Event to be processed.
This is the worker method to retrieve the Parent class.
Note that the Parent class must be passed to call the parent class method.
self:GetParent(self):ParentMethod()
Defined in:
Parameters:
#BASE Child
is the Child class from which the Parent class needs to be retrieved.
FromClass
Return value:
Get a Value given a Key from the Object.
Note that if the Object is destroyed, nillified or garbage collected, then the Values and Keys will also be gone.
Defined in:
Parameters:
Object
The object that holds the Value set by the Key.
Key
The key that is used to retrieve the value. Note that the key can be a #string, but it can also be any other type!
Return value:
The Value retrieved or nil if the Key was not found and thus the Value could not be retrieved.
Subscribe to a DCS Event.
Defined in:
Parameters:
Core.Event#EVENTS Event
#function EventFunction
(optional) The function to be called when the event occurs for the unit.
Return value:
Log an information which will be traced always.
Can be anywhere within the function logic.
This is the worker method to inherit from a parent class.
Defined in:
Parameters:
Child
is the Child class that inherits.
#BASE Parent
is the Parent class that the Child inherits from.
Return value:
Child
This is the worker method to check if an object is an (sub)instance of a class.
Examples:
ZONE:New( 'some zone' ):IsInstanceOf( ZONE ) will return true
ZONE:New( 'some zone' ):IsInstanceOf( 'ZONE' ) will return true
ZONE:New( 'some zone' ):IsInstanceOf( 'zone' ) will return true
ZONE:New( 'some zone' ):IsInstanceOf( 'BASE' ) will return true
ZONE:New( 'some zone' ):IsInstanceOf( 'GROUP' ) will return false
Defined in:
Parameter:
ClassName
is the name of the class or the class itself to run the check against
Return value:
#boolean:
Enquires if tracing is on (for the class).
BASE constructor.
This is an example how to use the BASE:New() constructor in a new class definition when inheriting from BASE.
function EVENT:New()
local self = BASE:Inherit( self, BASE:New() ) -- #EVENT
return self
end
Occurs when an object is completely destroyed.
initiator : The unit that is was destroyed.
Occurs when a ground unit captures either an airbase or a farp.
initiator : The unit that captured the base place: The airbase that was captured, can be a FARP or Airbase. When calling place:getCoalition() the faction will already be the new owning faction.
Occurs when any object is spawned into the mission.
initiator : The unit that was spawned
Occurs when any aircraft crashes into the ground and is completely destroyed.
initiator : The unit that has crashed
Occurs when an object is dead.
initiator : The unit that is dead.
Occurs when a pilot ejects from an aircraft initiator : The unit that has ejected
Occurs when any aircraft shuts down its engines.
initiator : The unit that is stopping its engines.
Occurs when any aircraft starts its engines.
initiator : The unit that is starting its engines.
Occurs whenever an object is hit by a weapon.
initiator : The unit object the fired the weapon weapon: Weapon object that hit the target target: The Object that was hit.
Occurs when any system fails on a human controlled aircraft.
initiator : The unit that had the failure
Occurs when an aircraft lands at an airbase, farp or ship initiator : The unit that has landed place: Object that the unit landed on.
Can be an Airbase Object, FARP, or Ships
Occurs when a mission ends
Occurs when a mission starts
Occurs when the pilot of an aircraft is killed.
Can occur either if the player is alive and crashes or if a weapon kills the pilot without completely destroying the plane. initiator : The unit that the pilot has died in.
Occurs when any player assumes direct control of a unit.
initiator : The unit that is being taken control of.
Occurs when any player relieves control of a unit to the AI.
initiator : The unit that the player left.
Occurs when an aircraft connects with a tanker and begins taking on fuel.
initiator : The unit that is receiving fuel.
Occurs when an aircraft is finished taking fuel.
initiator : The unit that was receiving fuel.
Occurs when any unit stops firing its weapon.
Event will always correspond with a shooting start event. initiator : The unit that was doing the shooing.
Occurs when any unit begins firing a weapon that has a high rate of fire.
Most common with aircraft cannons (GAU-8), autocannons, and machine guns. initiator : The unit that is doing the shooing. target: The unit that is being targeted.
Occurs whenever any unit in a mission fires a weapon.
But not any machine gun or autocannon based weapon, those are handled by EVENT.ShootingStart.
Occurs when an aircraft takes off from an airbase, farp, or ship.
initiator : The unit that tookoff place: Object from where the AI took-off from. Can be an Airbase Object, FARP, or Ships
Schedule a new time event.
Note that the schedule will only take place if the scheduler is started. Even for a single schedule event, the scheduler needs to be started also.
Defined in:
Parameters:
#number Start
Specifies the amount of seconds that will be waited before the scheduling is started, and the event function is called.
#function SchedulerFunction
The event function to be called when a timer event occurs. The event function needs to accept the parameters specified in SchedulerArguments.
#table ...
Optional arguments that can be given as part of scheduler. The arguments need to be given as a table { param1, param 2, ... }.
Return value:
#number:
The ScheduleID of the planned schedule.
Schedule a new time event.
Note that the schedule will only take place if the scheduler is started. Even for a single schedule event, the scheduler needs to be started also.
Defined in:
Parameters:
#number Start
Specifies the amount of seconds that will be waited before the scheduling is started, and the event function is called.
#number Repeat
Specifies the interval in seconds when the scheduler will call the event function.
#number RandomizeFactor
Specifies a randomization factor between 0 and 1 to randomize the Repeat.
#number Stop
Specifies the amount of seconds when the scheduler will be stopped.
#function SchedulerFunction
The event function to be called when a timer event occurs. The event function needs to accept the parameters specified in SchedulerArguments.
#table ...
Optional arguments that can be given as part of scheduler. The arguments need to be given as a table { param1, param 2, ... }.
Return value:
#number:
The ScheduleID of the planned schedule.
Stops the Schedule.
Defined in:
Parameter:
#function SchedulerFunction
The event function to be called when a timer event occurs. The event function needs to accept the parameters specified in SchedulerArguments.
Set the Class Event processing Priority.
The Event processing Priority is a number from 1 to 10, reflecting the order of the classes subscribed to the Event to be processed.
Set a state or property of the Object given a Key and a Value.
Note that if the Object is destroyed, nillified or garbage collected, then the Values and Keys will also be gone.
Defined in:
Parameters:
Object
The object that will hold the Value set by the Key.
Key
The key that is used as a reference of the value. Note that the key can be a #string, but it can also be any other type!
Value
The value to is stored in the object.
Return value:
The Value set.
Trace a function logic level 1.
Can be anywhere within the function logic.
Trace a function logic level 2.
Can be anywhere within the function logic.
Trace a function logic level 3.
Can be anywhere within the function logic.
Trace all methods in MOOSE
Set tracing for a class
Set tracing for a specific method of class
Set trace level
Set trace on or off Note that when trace is off, no BASE.Debug statement is performed, increasing performance! When Moose is loaded statically, (as one file), tracing is switched off by default.
So tracing must be switched on manually in your mission if you are using Moose statically. When moose is loading dynamically (for moose class development), tracing is switched on by default.
Defined in:
Parameter:
#boolean TraceOnOff
Switch the tracing on or off.
Usage:
-- Switch the tracing On
BASE:TraceOnOff( true )
-- Switch the tracing Off
BASE:TraceOnOff( false )
UnSubscribe to a DCS event.
Trace a function call.
This function is private.
Defined in:
Parameters:
Arguments
A #table or any field.
DebugInfoCurrentParam
DebugInfoFromParam
Trace a function logic.
Defined in:
Parameters:
Arguments
A #table or any field.
DebugInfoCurrentParam
DebugInfoFromParam
TODO: Complete DCS#Event structure.
- The main event handling function... This function captures all events generated for the class.
@param #BASE self
@param DCS#Event event