Module Functional.AmmoTruck
Functional -- Send a truck to supply artillery groups.
AMMOTRUCK - Send a truck to supply artillery groups.
Missions:
Demo missions can be found on GitHub
Author : applevangelist
Global(s)
Global AMMOTRUCK |
Amateurs talk about tactics, but professionals study logistics. - General Robert H Barrow, USMC Simple Class to re-arm your artillery with trucks. |
Amateurs talk about tactics, but professionals study logistics. - General Robert H Barrow, USMC
Simple Class to re-arm your artillery with trucks.
AMMOTRUCK
- Controls a SET_GROUP of trucks which will re-arm a SET_GROUP of artillery groups when they run out of ammunition.
1 The AMMOTRUCK concept
A SET_GROUP of trucks which will re-arm a SET_GROUP of artillery groups when they run out of ammunition. They will be based on a homebase and drive from there to the artillery groups and then back home. Trucks are the only known in-game mechanic to re-arm artillery and other units in DCS. Working units are e.g.: M-939 (blue), Ural-375 and ZIL-135 (both red).
2 Set-up
Define a set of trucks and a set of artillery:
local truckset = SET_GROUP:New():FilterCoalitions("blue"):FilterActive(true):FilterCategoryGround():FilterPrefixes("Ammo Truck"):FilterStart()
local ariset = SET_GROUP:New():FilterCoalitions("blue"):FilterActive(true):FilterCategoryGround():FilterPrefixes("Artillery"):FilterStart()
Create an AMMOTRUCK object to take care of the artillery using the trucks, with a homezone:
local ammotruck = AMMOTRUCK:New(truckset,ariset,coalition.side.BLUE,"Logistics",ZONE:FindByName("HomeZone")
2 Options and their default values
ammotruck.ammothreshold = 5 -- send a truck when down to this many rounds
ammotruck.remunidist = 20000 -- 20km - send trucks max this far from home
ammotruck.unloadtime = 600 -- 10 minutes - min time to unload ammunition
ammotruck.waitingtime = 1800 -- 30 mintes - wait max this long until remunition is done
ammotruck.monitor = -60 -- 1 minute - AMMOTRUCK checks run every one minute
ammotruck.routeonroad = true -- Trucks will **try** to drive on roads
ammotruck.usearmygroup = false -- If true, will make use of ARMYGROUP in the background (if used in DEV branch)
ammotruck.reloads = 5 -- Maxn re-arms a truck can do before he needs to go home and restock. Set to -1 for unlimited
3 FSM Events to shape mission
Truck has been sent off:
function ammotruck:OnAfterRouteTruck(From, Event, To, Truckdata, Aridata)
...
end
Truck has arrived:
function ammotruck:OnAfterTruckArrived(From, Event, To, Truckdata)
...
end
Truck is unloading:
function ammotruck:OnAfterTruckUnloading(From, Event, To, Truckdata)
...
end
Truck is returning home:
function ammotruck:OnAfterTruckReturning(From, Event, To, Truckdata)
...
end
Truck is arrived at home:
function ammotruck:OnAfterTruckHome(From, Event, To, Truckdata)
...
end
Type(s)
Fields and Methods inherited from AMMOTRUCK | Description |
---|---|
Class Name |
|
AMMOTRUCK:New(Truckset, Targetset, Coalition, Alias, Homezone) |
|
On after "RouteTruck" event. |
|
On after "TruckHome" event. |
|
On after "TruckReturning" event. |
|
On after "TruckUnloading" event. |
|
Triggers the FSM event "Stop". |
|
Triggers the FSM event "Stop" after a delay. |
|
Alias name |
|
Threshold (min) ammo before sending a truck |
|
Coalition this is for |
|
Debug flag |
|
Lid for log entries |
|
Monitor interval in seconds |
|
AMMOTRUCK:onafterRouteTruck(From, Event, To, Truckdata, Aridata) |
|
Number of reloads a single truck can do before he must return home |
|
Max distance trucks will go |
|
List of (alive) #AMMOTRUCK.data artillery to be reloaded |
|
Route truck on road if true (default) |
|
List of (alive) #AMMOTRUCK.data artillery |
|
SET of artillery |
|
List of (alive) #AMMOTRUCK.data trucks |
|
SET of trucks |
|
Unload time in seconds |
|
Version string |
|
List of (alive) #AMMOTRUCK.data artillery waiting |
|
Max waiting time in seconds |
Fields and Methods inherited from FSM | Description |
---|---|
Adds an End state. |
|
Set the default #FSM_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. |
|
AMMOTRUCK:AddScoreProcess(From, Event, State, ScoreText, Score) |
Adds a score for the FSM_PROCESS to be achieved. |
Add a new transition rule to the FSM. |
|
Get current state. |
|
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. |
|
Get current state. |
|
Returns a table with the Subs defined. |
|
Returns a table of the transition rules defined within the FSM. |
|
Check if FSM is in state. |
|
Load call backs. |
|
Creates a new FSM object. |
|
Sets the start state of the FSM. |
|
Add to map. |
|
Call handler. |
|
Create transition. |
|
Delayed transition. |
|
Event map. |
|
Go sub. |
|
Handler. |
|
Is end state. |
|
Sub maps. |
|
Check if can do an event. |
|
Check if cannot do an event. |
|
Check if FSM is in state. |
|
Fields and Methods inherited from AMMOTRUCK.State | Description |
---|---|
Fields and Methods inherited from AMMOTRUCK.data | Description |
---|---|
- AMMOTRUCK class, extends Core.Fsm#FSM
Field(s)
Class Name
Alias name
Threshold (min) ammo before sending a truck
Coalition this is for
Debug flag
Lid for log entries
Monitor interval in seconds
Number of reloads a single truck can do before he must return home
Max distance trucks will go
List of (alive) #AMMOTRUCK.data artillery to be reloaded
Route truck on road if true (default)
List of (alive) #AMMOTRUCK.data artillery
List of (alive) #AMMOTRUCK.data trucks
Unload time in seconds
Version string
List of (alive) #AMMOTRUCK.data artillery waiting
Max waiting time in seconds
Function(s)
Defined in:
AMMOTRUCK
Parameter:
#table dataset
table of #AMMOTRUCK.data entries
Return value:
self
Defined in:
AMMOTRUCK
Parameter:
#table dataset
table of #AMMOTRUCK.data entries
Return value:
self
Defined in:
AMMOTRUCK
Parameter:
#table dataset
table of #AMMOTRUCK.data entries
Return value:
self
Defined in:
AMMOTRUCK
Parameter:
#table dataset
table of #AMMOTRUCK.data entries
Return value:
self
Defined in:
AMMOTRUCK
Parameter:
#table dataset
table of #AMMOTRUCK.data entries
Return value:
self
Defined in:
AMMOTRUCK
Parameter:
#string name
Artillery group name to find
Return value:
Data
Defined in:
AMMOTRUCK
Parameter:
#string name
Truck group name to find
Return value:
Data
Defined in:
AMMOTRUCK
Parameters:
Core.Set#SET_GROUP Truckset
Set of truck groups
Core.Set#SET_GROUP Targetset
Set of artillery groups
#number Coalition
Coalition
#string Alias
Alias Name
Core.Zone#ZONE Homezone
Home, return zone for trucks
Return value:
self
Usage:
Define a set of trucks and a set of artillery:
local truckset = SET_GROUP:New():FilterCoalitions("blue"):FilterActive(true):FilterCategoryGround():FilterPrefixes("Ammo Truck"):FilterStart()
local ariset = SET_GROUP:New():FilterCoalitions("blue"):FilterActive(true):FilterCategoryGround():FilterPrefixes("Artillery"):FilterStart()
Create an AMMOTRUCK object to take care of the artillery using the trucks, with a homezone:
local ammotruck = AMMOTRUCK:New(truckset,ariset,coalition.side.BLUE,"Logistics",ZONE:FindByName("HomeZone")
On after "RouteTruck" event.
Defined in:
AMMOTRUCK
Parameters:
#string From
From state.
#string Event
Event.
#string To
To state.
#AMMOTRUCK.data Truck
On after "TruckHome" event.
Defined in:
AMMOTRUCK
Parameters:
#string From
From state.
#string Event
Event.
#string To
To state.
#AMMOTRUCK.data Truck
On after "TruckReturning" event.
Defined in:
AMMOTRUCK
Parameters:
#string From
From state.
#string Event
Event.
#string To
To state.
#AMMOTRUCK.data Truck
On after "TruckUnloading" event.
Defined in:
AMMOTRUCK
Parameters:
#string From
From state.
#string Event
Event.
#string To
To state.
#AMMOTRUCK.data Truck
Triggers the FSM event "Stop".
Stops the AMMOTRUCK and all its event handlers.
Defined in:
AMMOTRUCK
Triggers the FSM event "Stop" after a delay.
Stops the AMMOTRUCK and all its event handlers.
Defined in:
AMMOTRUCK
Parameter:
#number delay
Delay in seconds.
Defined in:
AMMOTRUCK
Parameters:
#string From
#string Event
#string To
Return value:
self
Defined in:
AMMOTRUCK
Parameters:
#string From
#string Event
#string To
#AMMOTRUCK.data Truckdata
#AMMOTRUCK.data Aridata
Return value:
self
Defined in:
AMMOTRUCK
Parameters:
#string From
#string Event
#string To
Return value:
self
Defined in:
AMMOTRUCK
Parameters:
#string From
#string Event
#string To
Return value:
self
Defined in:
AMMOTRUCK
Parameters:
#string From
#string Event
#string To
#AMMOTRUCK.data Truck
Return value:
self
Defined in:
AMMOTRUCK
Parameters:
#string From
#string Event
#string To
#AMMOTRUCK.data Truckdata
Return value:
self
Field(s)
Class Name
Alias name
Threshold (min) ammo before sending a truck
Coalition this is for
Debug flag
Lid for log entries
Monitor interval in seconds
Number of reloads a single truck can do before he must return home
Max distance trucks will go
List of (alive) #AMMOTRUCK.data artillery to be reloaded
Route truck on road if true (default)
List of (alive) #AMMOTRUCK.data artillery
List of (alive) #AMMOTRUCK.data trucks
Unload time in seconds
Version string
List of (alive) #AMMOTRUCK.data artillery waiting
Max waiting time in seconds
Function(s)
Adds an End state.
Set the default #FSM_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.
Get current state.
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.
Get current state.
Returns a table with the Subs defined.
Returns a table of the transition rules defined within the FSM.
Check if FSM is in state.
Defined in:
Parameter:
#string State
State name.
Return value:
#boolean:
If true, FSM is in this state.
Load call backs.
Sets the start state of the FSM.
Add to map.
Call handler.
Defined in:
Parameters:
#string step
Step "onafter", "onbefore", "onenter", "onleave".
#string trigger
Trigger.
#table params
Parameters.
#string EventName
Event name.
Return value:
Value.
Create transition.
Defined in:
Parameter:
#string EventName
Event name.
Return value:
#function:
Function.
Delayed transition.
Defined in:
Parameter:
#string EventName
Event name.
Return value:
#function:
Function.
Event map.
Go sub.
Defined in:
Parameters:
#string ParentFrom
Parent from state.
#string ParentEvent
Parent event name.
Return value:
#table:
Subs.
Handler.
Is end state.
Defined in:
Parameter:
#string Current
Current state name.
Return values:
#table:
FSM parent.
#string:
Event name.
Sub maps.
Check if can do an event.
Defined in:
Parameter:
#string e
Event name.
Return values:
#boolean:
If true, FSM can do the event.
#string:
To state.
Check if cannot do an event.
Defined in:
Parameter:
#string e
Event name.
Return value:
#boolean:
If true, FSM cannot do the event.
Check if FSM is in state.
Defined in:
Parameters:
#string State
State name.
state
Return value:
#boolean:
If true, FSM is in this state.