The UnitsManager handles the creation, update, and control of units. Data is strictly updated by the server ONLY. This means that any interaction from the user will always and only result in a command to the server, executed by means of a REST PUT request. Any subsequent change in data will be reflected only when the new data is sent back by the server. This strategy allows to avoid client/server and client/client inconsistencies.

Hierarchy

  • UnitsManager

Constructors

Properties

#copiedUnits: UnitData[]
#requestDetectionUpdate: boolean = false
#selectionEventDisabled: boolean = false
#units: {
    [ID: number]: Unit;
}

Type declaration

Methods

  • Add a new unit to the manager

    Parameters

    • ID: number

      ID of the new unit

    • category: string

      Either "Aircraft", "Helicopter", "GroundUnit", or "NavyUnit". Determines what class will be used to create the new unit accordingly.

    Returns void

  • Automatically create an Integrated Air Defence System from a CoalitionArea object. The units will be mostly focused around big cities. The bigger the city, the larger the amount of units created next to it. If the CoalitionArea does not contain any city, no units will be created

    Parameters

    • coalitionArea: CoalitionArea

      Boundaries of the IADS

    • types: {
          [key: string]: boolean;
      }

      Array of unit types to add to the IADS, e.g. AAA, SAM, flak, MANPADS

      • [key: string]: boolean
    • eras: {
          [key: string]: boolean;
      }

      Array of eras to which the units added to the IADS can belong

      • [key: string]: boolean
    • ranges: {
          [key: string]: boolean;
      }

      Array of weapon ranges the units can have

      • [key: string]: boolean
    • density: number

      Value between 0 and 100, controls the amout of units created

    • distribution: number

      Value between 0 and 100, controls how "scattered" the units will be

    Returns void

  • Deselect a specific unit

    Parameters

    • ID: number

      ID of the unit to deselect

    Returns void

  • Export all the ground and navy units to file. Does not work on Aircraft and Helicopter units. TODO: Extend to aircraft and helicopters

    Returns void

  • Get all the currently selected units

    Parameters

    • Optional options: {
          excludeHumans?: boolean;
          onlyOnePerGroup?: boolean;
      }

      Selection options

      • Optional excludeHumans?: boolean
      • Optional onlyOnePerGroup?: boolean

    Returns Unit[]

    Array of selected units

  • See getUnitsCategories for more info

    Returns string[]

    Category array of the selected units.

  • See getUnitsVariable for more info

    Parameters

    • variableGetter: CallableFunction

      CallableFunction that returns the requested variable. Example: getUnitsVariable((unit: Unit) => unit.getName(), foo) will return a string value if all the units have the same name, otherwise it will return undefined.

    Returns any

    The value of the variable if all units have the same value, else undefined

  • Get a specific unit by ID

    Parameters

    • ID: number

      ID of the unit. The ID shall be the same as the unit ID in DCS.

    Returns null | Unit

    Unit object, or null if no unit with said ID exists.

  • For a given unit, it returns if and how it is being detected by other units. NOTE: this function will return how a unit is being detected, i.e. how other units are detecting it. It will not return what the unit is detecting.

    Parameters

    • unit: Unit

      The unit of which to retrieve the "detected" methods.

    Returns number[]

    Array of detection methods

  • Returns all the units that belong to a hotgroup

    Parameters

    • hotgroup: number

      Hotgroup number

    Returns Unit[]

    Array of units that belong to hotgroup

  • This function allows to quickly determine the categories (Aircraft, Helicopter, GroundUnit, NavyUnit) of an array units. This allows to enable/disable specific controls which can only be applied to specific categories.

    Parameters

    • units: Unit[]

      Array of units of which to retrieve the categories

    Returns string[]

    Array of categories. Each category is present only once.

  • This function returns the value of a variable for each of the units in the input array. If all the units have the same value, returns the value, else returns undefined. This function is useful to present units data in the control panel, which will print a specific value only if it is the same for all the units. If the values are different, the control panel will show a "mixed values" value, or similar.

    Parameters

    • variableGetter: CallableFunction

      CallableFunction that returns the requested variable. Example: getUnitsVariable((unit: Unit) => unit.getName(), foo) will return a string value if all the units have the same name, otherwise it will return undefined.

    • units: Unit[]

      Array of units of which to retrieve the variable

    Returns any

    The value of the variable if all units have the same value, else undefined

  • Import ground and navy units from file TODO: extend to support aircraft and helicopters

    Returns void

  • Paste the copied units

    Returns undefined | false

    True if units were pasted successfully

  • Select all visible units inside a bounding rectangle

    Parameters

    • bounds: LatLngBounds

      Leaflet bounds object defining the selection area

    Returns void

  • Set a unit as "selected", which will allow to perform operations on it, like giving it a destination, setting it to attack a target, and so on

    Parameters

    • ID: number

      The ID of the unit to select

    • deselectAllUnits: boolean = true

      If true, the unit will be the only selected unit

    Returns void

  • Select units by hotgroup. A hotgroup can be created to quickly select multiple units using keyboard bindings

    Parameters

    • hotgroup: number

      The hotgroup number

    Returns void

  • Give a new destination to the selected units

    Parameters

    • latlng: LatLng

      Position of the new destination

    • mantainRelativePosition: boolean

      If true, the selected units will mantain their relative positions when reaching the target. This is useful to maintain a formation for groun/navy units

    • rotation: number

      Rotation in radians by which the formation will be rigidly rotated. E.g. a ( V ) formation will look like this ( < ) if rotated pi/4 radians (90 degrees)

    Returns void

  • Add the selected units to a hotgroup. Units can be in multiple hotgroups at the same type

    Parameters

    • hotgroup: number

      Hotgroup number

    Returns void

  • Instruct units to attack a specific unit

    Parameters

    • ID: number

      ID of the unit to attack

    Returns void

  • Instruct the selected units to perform precision bombing of specific coordinates

    Parameters

    • latlng: LatLng

      Location to bomb

    Returns void

  • Instruct the selected units to perform carpet bombing of specific coordinates

    Parameters

    • latlng: LatLng

      Location to bomb

    Returns void

  • Instruct all the selected units to change their altitude

    Parameters

    • altitudeChange: string

      Altitude change, either "climb" or "descend". The specific value depends on the unit category

    Returns void

  • Instruct all the selected units to change their speed

    Parameters

    • speedChange: string

      Speed change, either "stop", "slow", or "fast". The specific value depends on the unit category

    Returns void

  • Clear the destinations of all the selected units

    Returns void

  • Compute the destinations of every unit in the selected units. This function preserves the relative positions of the units, and rotates the whole formation by rotation.

    Parameters

    • latlng: LatLng

      Center of the group after the translation

    • rotation: number

      Rotation of the group, in radians

    Returns {
        [key: number]: LatLng;
    }

    Array of positions for each unit, in order

    • [key: number]: LatLng
  • Copy the selected units and store their properties in memory

    Returns void

  • Groups the selected units in a single (DCS) group, if all the units have the same category

    Returns void

  • Delete the selected units

    Parameters

    • explosion: boolean = false

      If true, the unit will be deleted using an explosion

    Returns void

  • Instruct the selected units to fire at specific coordinates

    Parameters

    • latlng: LatLng

      Location to fire at

    Returns void

  • Instruct the selected units to follow another unit in a formation. Only works for aircrafts and helicopters.

    Parameters

    • ID: number

      ID of the unit to follow

    • Optional offset: {
          x: number;
          y: number;
          z: number;
      }

      Optional parameter, defines a static offset. X: front-rear, positive front, Y: top-bottom, positive top, Z: left-right, positive right

      • x: number
      • y: number
      • z: number
    • Optional formation: string

      Optional parameter, defines a predefined formation type. Values are: "trail", "echelon-lh", "echelon-rh", "line-abreast-lh", "line-abreast-rh", "front", "diamond"

    Returns void

  • Instruct all the selected units to land at a specific location

    Parameters

    • latlng: LatLng

      Location where to land at

    Returns void

  • Instruct units to refuel at the nearest tanker, if possible. Else units will RTB

    Returns void

  • Set a specific altitude to all the selected units

    Parameters

    • altitude: number

      Value to set, in m

    Returns void

  • Set a specific altitude type to all the selected units

    Parameters

    • altitudeType: string

      Value to set, either "ASL" or "AGL". If "AGL" is selected, the unit will try to maintain the selected Above Ground Level altitude. Due to a DCS bug, this will only be true at the final position.

    Returns void

  • Set a specific emissions & countermeasures to all the selected units

    Parameters

    • emissionCountermeasure: string

      Value to set, see constants for acceptable values

    Returns void

  • Instruct the selected units to follow roads, only works on ground units

    Parameters

    • followRoads: boolean

      If true, units will follow roads

    Returns void

  • Set the hotgroup for the selected units. It will be the only hotgroup of the unit

    Parameters

    • hotgroup: number

      Hotgroup number

    Returns void

  • Turn selected units on or off, only works on ground and navy units

    Parameters

    • onOff: boolean

      If true, the unit will be turned on

    Returns void

  • Set a specific ROE to all the selected units

    Parameters

    • ROE: string

      Value to set, see constants for acceptable values

    Returns void

  • Set a specific reaction to threat to all the selected units

    Parameters

    • reactionToThreat: string

      Value to set, see constants for acceptable values

    Returns void

  • Set a specific speed to all the selected units

    Parameters

    • speed: number

      Value to set, in m/s

    Returns void

  • Set a specific speed type to all the selected units

    Parameters

    • speedType: string

      Value to set, either "CAS" or "GS". If "CAS" is selected, the unit will try to maintain the selected Calibrated Air Speed, but DCS will still only maintain a Ground Speed value so errors may arise depending on wind.

    Returns void

  • Spawn a new group of units

    Parameters

    • category: string

      Category of the new units

    • units: UnitSpawnTable[]

      Array of unit tables

    • coalition: string = "blue"

      Coalition to which the new units will belong

    • immediate: boolean = true

      If true the command will be performed immediately, but this may cause lag on the server

    • airbase: string = ""

      If true, the location of the units will be ignored and the units will spawn at the given airbase. Only works for aircrafts and helicopters

    • country: string = ""

      Set the country of the units. If empty string, the country will be assigned automatically

    • callback: CallableFunction = ...

      CallableFunction called when the command is received by the server

    Returns boolean

    True if the spawn command was successfully sent

  • Update the data of all the units. The data is directly decoded from the binary buffer received from the REST Server. This is necessary for performance and bandwidth reasons.

    Parameters

    • buffer: ArrayBuffer

      The arraybuffer, encoded according to the ICD defined in: TODO Add reference to ICD

    Returns number

    The decoded updateTime of the data update.

Generated using TypeDoc