Banner Image

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.

#AMMOTRUCK AMMOTRUCK

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

AMMOTRUCK:CheckArrivedTrucks(dataset)

AMMOTRUCK:CheckDrivingTrucks(dataset)

AMMOTRUCK:CheckReturningTrucks(dataset)

AMMOTRUCK:CheckTargetsAlive()

AMMOTRUCK:CheckTrucksAlive()

AMMOTRUCK:CheckUnloadingTrucks(dataset)

AMMOTRUCK:CheckWaitingTargets(dataset)

AMMOTRUCK.ClassName

Class Name

AMMOTRUCK:FindTarget(name)

AMMOTRUCK:FindTruck(name)

AMMOTRUCK:GetAmmoStatus(Group)

AMMOTRUCK:New(Truckset, Targetset, Coalition, Alias, Homezone)

AMMOTRUCK:OnAfterRouteTruck(From, Event, To, Truck)

On after "RouteTruck" event.

AMMOTRUCK:OnAfterTruckHome(From, Event, To, Truck)

On after "TruckHome" event.

AMMOTRUCK:OnAfterTruckReturning(From, Event, To, Truck)

On after "TruckReturning" event.

AMMOTRUCK:OnAfterTruckUnloading(From, Event, To, Truck)

On after "TruckUnloading" event.

AMMOTRUCK.State

AMMOTRUCK:Stop()

Triggers the FSM event "Stop".

AMMOTRUCK:__Stop(delay)

Triggers the FSM event "Stop" after a delay.

AMMOTRUCK.alias

Alias name

AMMOTRUCK.ammothreshold

Threshold (min) ammo before sending a truck

AMMOTRUCK.coalition

Coalition this is for

AMMOTRUCK.debug

Debug flag

AMMOTRUCK.hasarmygroup

AMMOTRUCK.homezone

AMMOTRUCK.lid

Lid for log entries

AMMOTRUCK.monitor

Monitor interval in seconds

AMMOTRUCK:onafterMonitor(From, Event, To)

AMMOTRUCK:onafterRouteTruck(From, Event, To, Truckdata, Aridata)

AMMOTRUCK:onafterStart(From, Event, To)

AMMOTRUCK:onafterStop(From, Event, To)

AMMOTRUCK:onafterTruckReturning(From, Event, To, Truck)

AMMOTRUCK:onafterTruckUnloading(From, Event, To, Truckdata)

AMMOTRUCK.reloads

Number of reloads a single truck can do before he must return home

AMMOTRUCK.remunidist

Max distance trucks will go

AMMOTRUCK.remunitionqueue

List of (alive) #AMMOTRUCK.data artillery to be reloaded

AMMOTRUCK.routeonroad

Route truck on road if true (default)

AMMOTRUCK.targetlist

List of (alive) #AMMOTRUCK.data artillery

AMMOTRUCK.targetset

SET of artillery

AMMOTRUCK.trucklist

List of (alive) #AMMOTRUCK.data trucks

AMMOTRUCK.truckset

SET of trucks

AMMOTRUCK.unloadtime

Unload time in seconds

AMMOTRUCK.usearmygroup

AMMOTRUCK.version

Version string

AMMOTRUCK.waitingtargets

List of (alive) #AMMOTRUCK.data artillery waiting

AMMOTRUCK.waitingtime

Max waiting time in seconds

Fields and Methods inherited from FSM Description

AMMOTRUCK:AddEndState(State)

Adds an End state.

AMMOTRUCK:AddProcess(From, Event, Process, ReturnEvents)

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.

AMMOTRUCK:AddScore(State, ScoreText, Score)

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.

AMMOTRUCK:AddTransition(From, Event, To)

Add a new transition rule to the FSM.

AMMOTRUCK.CallScheduler

AMMOTRUCK.Events

AMMOTRUCK:GetCurrentState()

Get current state.

AMMOTRUCK:GetEndStates()

Returns the End states.

AMMOTRUCK:GetProcess(From, Event)

AMMOTRUCK:GetProcesses()

Returns a table of the SubFSM rules defined within the FSM.

AMMOTRUCK:GetScores()

Returns a table with the scores defined.

AMMOTRUCK:GetStartState()

Returns the start state of the FSM.

AMMOTRUCK:GetState()

Get current state.

AMMOTRUCK:GetSubs()

Returns a table with the Subs defined.

AMMOTRUCK:GetTransitions()

Returns a table of the transition rules defined within the FSM.

AMMOTRUCK:Is(State)

Check if FSM is in state.

AMMOTRUCK:LoadCallBacks(CallBackTable)

Load call backs.

AMMOTRUCK:New()

Creates a new FSM object.

AMMOTRUCK.Scores

AMMOTRUCK:SetProcess(From, Event, Fsm)

AMMOTRUCK:SetStartState(State)

Sets the start state of the FSM.

AMMOTRUCK._EndStates

AMMOTRUCK._EventSchedules

AMMOTRUCK._Processes

AMMOTRUCK._Scores

AMMOTRUCK._StartState

AMMOTRUCK._Transitions

AMMOTRUCK:_add_to_map(Map, Event)

Add to map.

AMMOTRUCK:_call_handler(step, trigger, params, EventName)

Call handler.

AMMOTRUCK:_create_transition(EventName)

Create transition.

AMMOTRUCK:_delayed_transition(EventName)

Delayed transition.

AMMOTRUCK:_eventmap(Events, EventStructure)

Event map.

AMMOTRUCK:_gosub(ParentFrom, ParentEvent)

Go sub.

AMMOTRUCK:_handler(EventName, ...)

Handler.

AMMOTRUCK:_isendstate(Current)

Is end state.

AMMOTRUCK:_submap(subs, sub, name)

Sub maps.

AMMOTRUCK:can(e)

Check if can do an event.

AMMOTRUCK:cannot(e)

Check if cannot do an event.

AMMOTRUCK.current

AMMOTRUCK.endstates

AMMOTRUCK:is(State, state)

Check if FSM is in state.

AMMOTRUCK.options

AMMOTRUCK.subs

  • AMMOTRUCK class, extends Core.Fsm#FSM

Field(s)

#string AMMOTRUCK.ClassName

Class Name

#string AMMOTRUCK.alias

Alias name

#number AMMOTRUCK.ammothreshold

Threshold (min) ammo before sending a truck

#number AMMOTRUCK.coalition

Coalition this is for

#boolean AMMOTRUCK.debug

Debug flag

#string AMMOTRUCK.lid

Lid for log entries

#number AMMOTRUCK.monitor

Monitor interval in seconds

#number AMMOTRUCK.reloads

Number of reloads a single truck can do before he must return home

#number AMMOTRUCK.remunidist

Max distance trucks will go

#table AMMOTRUCK.remunitionqueue

List of (alive) #AMMOTRUCK.data artillery to be reloaded

#boolean AMMOTRUCK.routeonroad

Route truck on road if true (default)

#table AMMOTRUCK.targetlist

List of (alive) #AMMOTRUCK.data artillery

#table AMMOTRUCK.trucklist

List of (alive) #AMMOTRUCK.data trucks

#number AMMOTRUCK.unloadtime

Unload time in seconds

#string AMMOTRUCK.version

Version string

#table AMMOTRUCK.waitingtargets

List of (alive) #AMMOTRUCK.data artillery waiting

#number AMMOTRUCK.waitingtime

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

Return value:

self

Defined in:

AMMOTRUCK

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:

Defined in:

AMMOTRUCK

Parameter:

#string name

Truck group name to find

Return value:

Defined in:

AMMOTRUCK

Parameter:

Return value:

self

Defined in:

AMMOTRUCK

Parameters:

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.

On after "TruckHome" event.

Defined in:

AMMOTRUCK

Parameters:

#string From

From state.

#string Event

Event.

#string To

To state.

On after "TruckReturning" event.

Defined in:

AMMOTRUCK

Parameters:

#string From

From state.

#string Event

Event.

#string To

To state.

On after "TruckUnloading" event.

Defined in:

AMMOTRUCK

Parameters:

#string From

From state.

#string Event

Event.

#string To

To state.

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

Return value:

self

Defined in:

AMMOTRUCK

Parameters:

#string From

#string Event

#string To

#AMMOTRUCK.data Truckdata

Return value:

self

Field(s)

#string AMMOTRUCK.ClassName

Class Name

#string AMMOTRUCK.alias

Alias name

#number AMMOTRUCK.ammothreshold

Threshold (min) ammo before sending a truck

#number AMMOTRUCK.coalition

Coalition this is for

#boolean AMMOTRUCK.debug

Debug flag

#string AMMOTRUCK.lid

Lid for log entries

#number AMMOTRUCK.monitor

Monitor interval in seconds

#number AMMOTRUCK.reloads

Number of reloads a single truck can do before he must return home

#number AMMOTRUCK.remunidist

Max distance trucks will go

#table AMMOTRUCK.remunitionqueue

List of (alive) #AMMOTRUCK.data artillery to be reloaded

#boolean AMMOTRUCK.routeonroad

Route truck on road if true (default)

#table AMMOTRUCK.targetlist

List of (alive) #AMMOTRUCK.data artillery

#table AMMOTRUCK.trucklist

List of (alive) #AMMOTRUCK.data trucks

#number AMMOTRUCK.unloadtime

Unload time in seconds

#string AMMOTRUCK.version

Version string

#table AMMOTRUCK.waitingtargets

List of (alive) #AMMOTRUCK.data artillery waiting

#number AMMOTRUCK.waitingtime

Max waiting time in seconds

Function(s)

Adds an End state.

Defined in:

Parameter:

#string State

The FSM 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.

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.

Defined in:

Return value:

#string:

Current FSM state.

Returns the End states.

Defined in:

Return value:

#table:

End states.

Defined in:

Parameters:

From

Event

Returns a table of the SubFSM rules defined within the FSM.

Defined in:

Return value:

#table:

Sub processes.

Returns a table with the scores defined.

Defined in:

Return value:

#table:

Scores.

Returns the start state of the FSM.

Defined in:

Return value:

#string:

A string containing the start state.

Get current state.

Defined in:

Return value:

#string:

Current FSM state.

Returns a table with the Subs defined.

Defined in:

Return value:

#table:

Sub processes.

Returns a table of the transition rules defined within the FSM.

Defined in:

Return value:

#table:

Transitions.

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.

Defined in:

Parameter:

#table CallBackTable

Table of call backs.

Creates a new FSM object.

Defined in:

Return value:

#FSM:

Defined in:

Parameters:

From

Event

Fsm

Sets the start state of the FSM.

Defined in:

Parameter:

#string State

A string defining the start state.

Add to map.

Defined in:

Parameters:

#table Map

Map.

#table Event

Event table.

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.

Defined in:

Parameters:

#table Events

Events.

#table EventStructure

Event structure.

Go sub.

Defined in:

Parameters:

#string ParentFrom

Parent from state.

#string ParentEvent

Parent event name.

Return value:

#table:

Subs.

Handler.

Defined in:

Parameters:

#string EventName

Event name.

...

Arguments.

Is end state.

Defined in:

Parameter:

#string Current

Current state name.

Return values:

#table:

FSM parent.

#string:

Event name.

Sub maps.

Defined in:

Parameters:

#table subs

Subs.

#table sub

Sub.

#string name

Name.

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.