TFE Custom Logics

From DF21 Wiki

This article explains how to use custom (user-defined) AI logics in TFE.

This feature allows modders to create new enemy logics that behave similarly to the "standard" (non-boss) enemies in Dark Forces, for example Officers, Stormtroopers, Bossk, Probe Droids.

JSON locations

Custom logics are defined in JSON files. TFE will search for and load logics from all logic .JSON files found in these locations

  • DARK\Logics
  • TheForceEngine\Mods\Logics

where DARK is your Dark Forces game directory which TFE is pointing to.

In addition, if you are running a Mod from a ZIP, TFE will look for a \Logics subfolder inside the ZIP and load logics from any .JSON files found there.

Logics loaded from a Mod will take preference over any logics found in other locations that have the same name.

You can have as many logic .JSON files as you want, and each .JSON file can contain as many logics as you want. If multiple logics are loaded that have the same name, only the first one encountered with that name will be used. If you have multiple .JSON files, the order in which they are loaded by TFE is unpredictable, so the only way to be sure that your logics work the way you intend is to avoid duplicate names.

Logic JSON structure

A logic JSON should consist of a single array called "logics".

Each element of the "logics" array must consist of two items

  • "logicName" - a string which is the name of the logic
  • "data" - an object containing properties that are set for the logic

Example:

{
   "logics": [
      {
         "logicName": "LogicA",
         "data": {
            "alertSound": "alert1.voc",
            "painSound": "pain1.voc",
            "hitpoints": 25,
            "projectile": "rifle_bolt"
         }
      },
      {
         "logicName": "LogicB",
         "data": {
            "alertSound": "alert2.voc",
            "painSound": "pain2.voc",
            "hitpoints": 39,
            "speed": 20,
            "projectile": "thermal_det",
            "dropItem": "red_key"
         }
      }
   ]
}

Logic JSONs are not case sensitive. The text inside the JSON can be all uppercase, all lowercase, or any mix of upper and lowercase; it will all be read the same.

Data properties

Here is a list of the properties that you can set for each logic.

Property Type Description
hasGravity boolean If true, will be affected by gravity
isFlying boolean If true, will be a flying enemy (like probe droid)
fieldOfView number (integer) Field of view, in degrees. If set to 360, the enemy will be able to see you even if you are standing behind it.
awareRange number (integer) If you are within this distance from the enemy (in DFU), it will be alerted even if you are outside its field of view. (However, this can be affected by other things, such as the ambient light.)
alertSound string VOC file to play when enemy is alerted
painSound string VOC file to play when enemy takes pain
dieSound string VOC file to play when enemy dies
attack1Sound string VOC file to play for primary attack
attack2Sound string VOC file to play for secondary attack
hitPoints number (integer) Hitpoints. The enemy will die when it reaches 0.
dropItem string or number What item is dropped when the enemy dies. See table below for options.
dieEffect string or number An effect (eg. explosion) that will play when the enemy dies. See table below for options.
hasMeleeAttack boolean If true, the enemy will have a melee attack. If the enemy has a melee attack, it will always be the primary attack.
hasRangedAttack boolean If true, the enemy will have a ranged attack. If the enemy has a melee attack, the ranged attack will be the secondary attack. If it does not have a melee attack, the ranged attack will be the primary attack.
litWithMeleeAttack boolean If true, the sprite will light up when it attacks with melee.
litWithRangedAttack boolean If true, the sprite will light up when it does its ranged attack.