Module Base

This module contains the BASE class.

1) #BASE class

The #BASE class is the super class for all the classes defined within MOOSE.

It handles:

  • The construction and inheritance of child classes.
  • The tracing of objects during mission execution within the DCS.log file, under the "Saved Games\DCS\Logs" folder.

Note: Normally you would not use the BASE class unless you are extending the MOOSE framework with new classes.

1.1) BASE constructor

Any class derived from BASE, must use the Core.Base#BASE.New method how this is done.

1.2) BASE Trace functionality

The BASE class contains trace methods to trace progress within a mission execution of a certain object. Note that these trace methods are inherited by each MOOSE class interiting BASE. As such, each object created from derived class from BASE can use the tracing functions to trace its execution.

1.2.1) Tracing functions

There are basically 3 types of tracing methods available within BASE:

  • BASE.F: Trace the beginning of a function and its given parameters. An F is indicated at column 44 in the DCS.log file.
  • BASE.T: Trace further logic within a function giving optional variables or parameters. A T is indicated at column 44 in the DCS.log file.
  • BASE.E: Trace an exception within a function giving optional variables or parameters. An E is indicated at column 44 in the DCS.log file. An exception will always be traced.

1.2.2) Tracing levels

There are 3 tracing levels within MOOSE.
These tracing levels were defined to avoid bulks of tracing to be generated by lots of objects.

As such, the F and T methods have additional variants to trace level 2 and 3 respectively:

  • BASE.F2: Trace the beginning of a function and its given parameters with tracing level 2.
  • BASE.F3: Trace the beginning of a function and its given parameters with tracing level 3.
  • BASE.T2: Trace further logic within a function giving optional variables or parameters with tracing level 2.
  • BASE.T3: Trace further logic within a function giving optional variables or parameters with tracing level 3.

1.2.3) Trace activation.

Tracing can be activated in several ways:

  • Switch tracing on or off through the BASE.TraceOnOff() method.
  • Activate all tracing through the BASE.TraceAll() method.
  • Activate only the tracing of a certain class (name) through the BASE.TraceClass() method.
  • Activate only the tracing of a certain method of a certain class through the BASE.TraceClassMethod() method.
  • Activate only the tracing of a certain level through the BASE.TraceLevel() method.

    1.2.4) Check if tracing is on.

The method BASE.IsTrace() will validate if tracing is activated or not.

1.3 DCS simulator Event Handling

The BASE class provides methods to catch DCS Events. These are events that are triggered from within the DCS simulator, and handled through lua scripting. MOOSE provides an encapsulation to handle these events more efficiently. Therefore, the BASE class exposes the following event handling functions:

The EventOn() methods provide the Core.Event#EVENTDATA structure to the event handling function. The Core.Event#EVENTDATA structure contains an enriched data set of information about the event being handled.

Find below an example of the prototype how to write an event handling function:

 CommandCenter:EventOnPlayerEnterUnit(
   --- @param #COMMANDCENTER self
   -- @param Core.Event#EVENTDATA EventData
   function( self, EventData )
     local PlayerUnit = EventData.IniUnit
     for MissionID, Mission in pairs( self:GetMissions() ) do
       local Mission = Mission -- Tasking.Mission#MISSION
       Mission:JoinUnit( PlayerUnit )
       Mission:ReportDetails()
     end
   end
   )

Note the function( self, EventData ). It takes two parameters:

  • self = the object that is handling the EventOnPlayerEnterUnit.
  • EventData = the Core.Event#EVENTDATA structure, containing more information of the Event.

1.4) Class identification methods

BASE provides methods to get more information of each object:

  • BASE.GetClassID(): Gets the ID (number) of the object. Each object created is assigned a number, that is incremented by one.
  • BASE.GetClassName(): Gets the name of the object, which is the name of the class the object was instantiated from.
  • BASE.GetClassNameAndID(): Gets the name and ID of the object.

1.10) BASE Inheritance (tree) support

The following methods are available to support inheritance:

  • BASE.Inherit: Inherits from a class.
  • BASE.GetParent: Returns the parent object from the object it is handling, or nil if there is no parent object.

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.

YYYY-MM-DD: CLASS:NewFunction( Params ) replaces CLASS:OldFunction( Params ) YYYY-MM-DD: CLASS:NewFunction( Params ) added

Hereby the change log:


AUTHORS and CONTRIBUTIONS

Contributions:

  • None.

Authors:

  • FlightControl: Design & Programming

Global(s)

BASE
FORMATION

Type BASE

BASE:AddEvent(Event, EventFunction)

Set a new listener for the class.

BASE.ClassID

The ID number of the class.

BASE.ClassName

The name of the class.

BASE.ClassNameAndID

The name of the class concatenated with the ID number of the class.

BASE:ClearState(Object, StateName)
BASE:CreateEventBirth(EventTime, Initiator, IniUnitName, place, subplace)

Creation of a Birth Event.

BASE:CreateEventCrash(EventTime, Initiator)

Creation of a Crash Event.

BASE:DisableEvents()

Disable the event listeners for the class.

BASE:E(Arguments)

Log an exception which will be traced always.

BASE:EnableEvents()

Enable the event listeners for the class.

BASE:Event()

Returns the event dispatcher

BASE:EventOnBaseCaptured(EventFunction)

Subscribe to a SEVENTBASE_CAPTURED event.

BASE:EventOnBirth(EventFunction)

Subscribe to a S_EVENT_BIRTH event.

BASE:EventOnCrash(EventFunction)

Subscribe to a S_EVENT_CRASH event.

BASE:EventOnDead(EventFunction)

Subscribe to a S_EVENT_DEAD event.

BASE:EventOnEjection(EventFunction)

Subscribe to a S_EVENT_EJECTION event.

BASE:EventOnEngineShutdown(EventFunction)

Subscribe to a SEVENTENGINE_SHUTDOWN event.

BASE:EventOnEngineStartup(EventFunction)

Subscribe to a SEVENTENGINE_STARTUP event.

BASE:EventOnHit(EventFunction)

Subscribe to a S_EVENT_HIT event.

BASE:EventOnHumanFailure(EventFunction)

Subscribe to a SEVENTHUMAN_FAILURE event.

BASE:EventOnLand(EventFunction)

Subscribe to a S_EVENT_LAND event.

BASE:EventOnMissionStart(EventFunction)

Subscribe to a SEVENTMISSION_START event.

BASE:EventOnPilotDead(EventFunction)

Subscribe to a SEVENTPILOT_DEAD event.

BASE:EventOnPlayerComment(EventFunction)

Subscribe to a SEVENTPLAYER_COMMENT event.

BASE:EventOnPlayerEnterUnit(EventFunction)

Subscribe to a SEVENTPLAYER_ENTER_UNIT event.

BASE:EventOnPlayerLeaveUnit(EventFunction)

Subscribe to a SEVENTPLAYER_LEAVE_UNIT event.

BASE:EventOnPlayerMissionEnd(EventFunction)

Subscribe to a SEVENTMISSION_END event.

BASE:EventOnRefueling(EventFunction)

Subscribe to a S_EVENT_REFUELING event.

BASE:EventOnRefuelingStop(EventFunction)

Subscribe to a SEVENTREFUELING_STOP event.

BASE:EventOnShootingEnd(EventFunction)

Subscribe to a SEVENTSHOOTING_END event.

BASE:EventOnShootingStart(EventFunction)

Subscribe to a SEVENTSHOOTING_START event.

BASE:EventOnShot(EventFunction)

Subscribe to a S_EVENT_SHOT event.

BASE:EventOnTakeOff(EventFunction)

Subscribe to a S_EVENT_TAKEOFF event.

BASE:EventOnTookControl(EventFunction)

Subscribe to a SEVENTTOOK_CONTROL event.

BASE:EventRemoveAll()

Remove all subscribed events

BASE.Events
BASE:F(Arguments)

Trace a function call.

BASE:F2(Arguments)

Trace a function call level 2.

BASE:F3(Arguments)

Trace a function call level 3.

BASE:GetClassID()

Get the ClassID of the class instance.

BASE:GetClassName()

Get the ClassName of the class instance.

BASE:GetClassNameAndID()

Get the ClassName + ClassID of the class instance.

BASE:GetParent(Child)

This is the worker method to retrieve the Parent class.

BASE:GetState(Object, StateName)
BASE:Inherit(Child, Parent)

This is the worker method to inherit from a parent class.

BASE:IsTrace()

Enquires if tracing is on (for the class).

BASE:New()
BASE:SetState(Object, StateName, State)
BASE.States
BASE:T(Arguments)

Trace a function logic level 1.

BASE:T2(Arguments)

Trace a function logic level 2.

BASE:T3(Arguments)

Trace a function logic level 3.

BASE:TraceAll(TraceAll)

Trace all methods in MOOSE

BASE:TraceClass(Class)

Set tracing for a class

BASE:TraceClassMethod(Class, Method)

Set tracing for a specific method of class

BASE:TraceLevel(Level)

Set trace level

BASE:TraceOnOff(TraceOnOff)

Set trace on or off Note that when trace is off, no debug statement is performed, increasing performance! When Moose is loaded statically, (as one file), tracing is switched off by default.

BASE:_Destructor()
BASE:_F(Arguments, DebugInfoCurrentParam, DebugInfoFromParam)

Trace a function call.

BASE:_SetDestructor()
BASE:_T(Arguments, DebugInfoCurrentParam, DebugInfoFromParam)

Trace a function logic.

BASE:onEvent(event)

Type FORMATION

FORMATION.Cone

A cone formation.

Global(s)

#BASE BASE
#FORMATION FORMATION

Type Base

Type BASE

The BASE Class

Field(s)

BASE:AddEvent(Event, EventFunction)

Set a new listener for the class.

Parameters

Return value

#BASE:

BASE.ClassID

The ID number of the class.

BASE.ClassName

The name of the class.

BASE.ClassNameAndID

The name of the class concatenated with the ID number of the class.

BASE:ClearState(Object, StateName)

Parameters

  • Object :

  • StateName :

BASE:CreateEventBirth(EventTime, Initiator, IniUnitName, place, subplace)

Creation of a Birth Event.

Parameters

BASE:CreateEventCrash(EventTime, Initiator)

Creation of a Crash Event.

Parameters

BASE:DisableEvents()

Disable the event listeners for the class.

Return value

#BASE:

BASE:E(Arguments)

Log an exception which will be traced always.

Can be anywhere within the function logic.

Parameter

  • Arguments : A #table or any field.

BASE:EnableEvents()

Enable the event listeners for the class.

Return value

#BASE:

BASE:Event()

Returns the event dispatcher

Return value

Core.Event#EVENT:

BASE:EventOnBaseCaptured(EventFunction)

Subscribe to a SEVENTBASE_CAPTURED event.

Parameter

  • #function EventFunction : The function to be called when the event occurs for the unit.

Return value

#BASE:

BASE:EventOnBirth(EventFunction)

Subscribe to a S_EVENT_BIRTH event.

Parameter

  • #function EventFunction : The function to be called when the event occurs for the unit.

Return value

#BASE:

BASE:EventOnCrash(EventFunction)

Subscribe to a S_EVENT_CRASH event.

Parameter

  • #function EventFunction : The function to be called when the event occurs for the unit.

Return value

#BASE:

BASE:EventOnDead(EventFunction)

Subscribe to a S_EVENT_DEAD event.

Parameter

  • #function EventFunction : The function to be called when the event occurs for the unit.

Return value

#BASE:

BASE:EventOnEjection(EventFunction)

Subscribe to a S_EVENT_EJECTION event.

Parameter

  • #function EventFunction : The function to be called when the event occurs for the unit.

Return value

#BASE:

BASE:EventOnEngineShutdown(EventFunction)

Subscribe to a SEVENTENGINE_SHUTDOWN event.

Parameter

  • #function EventFunction : The function to be called when the event occurs for the unit.

Return value

#BASE:

BASE:EventOnEngineStartup(EventFunction)

Subscribe to a SEVENTENGINE_STARTUP event.

Parameter

  • #function EventFunction : The function to be called when the event occurs for the unit.

Return value

#BASE:

BASE:EventOnHit(EventFunction)

Subscribe to a S_EVENT_HIT event.

Parameter

  • #function EventFunction : The function to be called when the event occurs for the unit.

Return value

#BASE:

BASE:EventOnHumanFailure(EventFunction)

Subscribe to a SEVENTHUMAN_FAILURE event.

Parameter

  • #function EventFunction : The function to be called when the event occurs for the unit.

Return value

#BASE:

BASE:EventOnLand(EventFunction)

Subscribe to a S_EVENT_LAND event.

Parameter

  • #function EventFunction : The function to be called when the event occurs for the unit.

Return value

#BASE:

BASE:EventOnMissionStart(EventFunction)

Subscribe to a SEVENTMISSION_START event.

Parameter

  • #function EventFunction : The function to be called when the event occurs for the unit.

Return value

#BASE:

BASE:EventOnPilotDead(EventFunction)

Subscribe to a SEVENTPILOT_DEAD event.

Parameter

  • #function EventFunction : The function to be called when the event occurs for the unit.

Return value

#BASE:

BASE:EventOnPlayerComment(EventFunction)

Subscribe to a SEVENTPLAYER_COMMENT event.

Parameter

  • #function EventFunction : The function to be called when the event occurs for the unit.

Return value

#BASE:

BASE:EventOnPlayerEnterUnit(EventFunction)

Subscribe to a SEVENTPLAYER_ENTER_UNIT event.

Parameter

  • #function EventFunction : The function to be called when the event occurs for the unit.

Return value

#BASE:

BASE:EventOnPlayerLeaveUnit(EventFunction)

Subscribe to a SEVENTPLAYER_LEAVE_UNIT event.

Parameter

  • #function EventFunction : The function to be called when the event occurs for the unit.

Return value

#BASE:

BASE:EventOnPlayerMissionEnd(EventFunction)

Subscribe to a SEVENTMISSION_END event.

Parameter

  • #function EventFunction : The function to be called when the event occurs for the unit.

Return value

#BASE:

BASE:EventOnRefueling(EventFunction)

Subscribe to a S_EVENT_REFUELING event.

Parameter

  • #function EventFunction : The function to be called when the event occurs for the unit.

Return value

#BASE:

BASE:EventOnRefuelingStop(EventFunction)

Subscribe to a SEVENTREFUELING_STOP event.

Parameter

  • #function EventFunction : The function to be called when the event occurs for the unit.

Return value

#BASE:

BASE:EventOnShootingEnd(EventFunction)

Subscribe to a SEVENTSHOOTING_END event.

Parameter

  • #function EventFunction : The function to be called when the event occurs for the unit.

Return value

#BASE:

BASE:EventOnShootingStart(EventFunction)

Subscribe to a SEVENTSHOOTING_START event.

Parameter

  • #function EventFunction : The function to be called when the event occurs for the unit.

Return value

#BASE:

BASE:EventOnShot(EventFunction)

Subscribe to a S_EVENT_SHOT event.

Parameter

  • #function EventFunction : The function to be called when the event occurs for the unit.

Return value

#BASE:

BASE:EventOnTakeOff(EventFunction)

Subscribe to a S_EVENT_TAKEOFF event.

Parameter

  • #function EventFunction : The function to be called when the event occurs for the unit.

Return value

#BASE:

BASE:EventOnTookControl(EventFunction)

Subscribe to a SEVENTTOOK_CONTROL event.

Parameter

  • #function EventFunction : The function to be called when the event occurs for the unit.

Return value

#BASE:

BASE:EventRemoveAll()

Remove all subscribed events

Return value

#BASE:

BASE.Events
BASE:F(Arguments)

Trace a function call.

Must be at the beginning of the function logic.

Parameter

  • Arguments : A #table or any field.

BASE:F2(Arguments)

Trace a function call level 2.

Must be at the beginning of the function logic.

Parameter

  • Arguments : A #table or any field.

BASE:F3(Arguments)

Trace a function call level 3.

Must be at the beginning of the function logic.

Parameter

  • Arguments : A #table or any field.

BASE:GetClassID()

Get the ClassID of the class instance.

Return value

#string: The ClassID of the class instance.

BASE:GetClassName()

Get the ClassName of the class instance.

Return value

#string: The ClassName of the class instance.

BASE:GetClassNameAndID()

Get the ClassName + ClassID of the class instance.

The ClassName + ClassID is formatted as '%s#%09d'.

Return value

#string: The ClassName + ClassID of the class instance.

BASE:GetParent(Child)

This is the worker method to retrieve the Parent class.

Parameter

  • #BASE Child : is the Child class from which the Parent class needs to be retrieved.

Return value

#BASE:

BASE:GetState(Object, StateName)

Parameters

  • Object :

  • StateName :

BASE:Inherit(Child, Parent)

This is the worker method to inherit from a parent class.

Parameters

  • Child : is the Child class that inherits.

  • #BASE Parent : is the Parent class that the Child inherits from.

Return value

#BASE: Child

BASE:IsTrace()

Enquires if tracing is on (for the class).

Return value

#boolean:

BASE:New()

@todo need to investigate if the deepCopy is really needed... Don't think so.

BASE:SetState(Object, StateName, State)

Parameters

  • Object :

  • StateName :

  • State :

BASE.States
BASE:T(Arguments)

Trace a function logic level 1.

Can be anywhere within the function logic.

Parameter

  • Arguments : A #table or any field.

BASE:T2(Arguments)

Trace a function logic level 2.

Can be anywhere within the function logic.

Parameter

  • Arguments : A #table or any field.

BASE:T3(Arguments)

Trace a function logic level 3.

Can be anywhere within the function logic.

Parameter

  • Arguments : A #table or any field.

BASE:TraceAll(TraceAll)

Trace all methods in MOOSE

Parameter

  • #boolean TraceAll : true = trace all methods in MOOSE.

BASE:TraceClass(Class)

Set tracing for a class

Parameter

  • #string Class :

BASE:TraceClassMethod(Class, Method)

Set tracing for a specific method of class

Parameters

  • #string Class :

  • #string Method :

BASE:TraceLevel(Level)

Set trace level

Parameter

  • #number Level :

BASE:TraceOnOff(TraceOnOff)

Set trace on or off Note that when trace is off, no 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.

Parameter

  • #boolean TraceOnOff : Switch the tracing on or off.

Usage:

-- Switch the tracing On
BASE:TraceOnOff( true )

-- Switch the tracing Off
BASE:TraceOnOff( false )
BASE:_Destructor()
BASE:_F(Arguments, DebugInfoCurrentParam, DebugInfoFromParam)

Trace a function call.

This function is private.

Parameters

  • Arguments : A #table or any field.

  • DebugInfoCurrentParam :

  • DebugInfoFromParam :

BASE:_SetDestructor()
BASE:_T(Arguments, DebugInfoCurrentParam, DebugInfoFromParam)

Trace a function logic.

Parameters

  • Arguments : A #table or any field.

  • DebugInfoCurrentParam :

  • DebugInfoFromParam :

BASE:onEvent(event)

TODO: Complete Dcs.DCSTypes#Event structure.
- The main event handling function... This function captures all events generated for the class. @param #BASE self @param Dcs.DCSTypes#Event event

Parameter

  • event :

Type FORMATION

The Formation Class

Field(s)

FORMATION.Cone

A cone formation.