Behaviour
Rules that make a def change form, spawn units, heal, pay or blow up; buttons on its card; shields; and a carrier's wing of planes.
A def may carry rules: things that happen to it — it turns into another of the mod's defs, spawns units, heals, pays, takes a buff, blows up — when something happens to it (on), when a condition comes true (when), on a clock (every), or when the player presses a button on its card (button). The words are a closed vocabulary checked when the mod loads, so a rule can only do what the game already does safely; there is no scripting, a spawn never takes a side past its population cap, and the game's own units have no rules at all.
Changing form
A tank that is a tree while it stands, and a tank again when it moves or fires — two defs, each turning into the other. The sheet's anims show the tank's frames while it moves and the tree's while it stands; the disguised form is untargetable, so nothing on the other side can pick it out:
{ "id": "mymod-mirage", "extends": "mbt", "name": "Mirage Tank",
"rules": [{ "when": { "still": 1, "quiet": 0.8 }, "do": { "morph": "mymod-mirage-tree" } }] },
{ "id": "mymod-mirage-tree", "extends": "mymod-mirage", "name": "Mirage Tank", "producedBy": [],
"untargetable": true,
"rules": [{ "when": { "moving": true }, "do": { "morph": "mymod-mirage" } },
{ "on": "fired", "do": { "morph": "mymod-mirage" } }] }
A hero that ranks itself up from its card: each button is a tile showing the form it makes, paid as the work is done like production, and it waits for what it requires:
{ "id": "mymod-hero", "extends": "mbt", "name": "Hero Tank",
"rules": [
{ "button": { "cost": 600, "time": 20, "ai": true }, "do": { "morph": "mymod-hero-gunner" } },
{ "button": { "cost": 900, "time": 30, "requires": ["radar"] }, "do": { "morph": "mymod-hero-sniper" } }
] }
A change of form (morph) keeps the unit: its selection and groups, its kills and rank, its health's share of the whole, and the orders the new form can carry out.
Spawning
The dead rising for whoever killed them is { "on": "destroyed", "do": { "spawn": { "unit": "mymod-zombie", "side": "killer" } } }; a nest that breeds is an every with a spawn; a car that arrives crewed is { "on": "created", "do": { "spawn": { "unit": "…", "count": 4, "into": "hold" } } }.
Shields
A def may have an energy shield that takes harm before the hull, and a regen that mends it.
A carrier's wing
A unit may carry a wing: planes of the mod's own that it keeps aboard, sends out at what it fights, takes back to rearm and makes again when lost — a light carrier's drones, a destroyer's one anti-submarine plane. The planes fight as units of their side, but they are never the player's to select or order.
Reference
A rule (defs[].rules[])
| field | type | required | default | meaning |
|---|---|---|---|---|
| on | created | destroyed | fired | damaged | kill | morphed | runs when this happens to it: made (`created`, and when a map stands it), killed (`destroyed`, where it fell), a shot fired (`fired`), hurt (`damaged`), a kill made (`kill`), or a change of form finished (`morphed`) | ||
| when | condition | runs when this condition becomes true, and again only after it has been false (see Conditions) | ||
| every | number 0.25–3600 | runs every so many seconds of its life | ||
| button | button | a button on its card the player presses (see Buttons) | ||
| if | condition | also checked when triggered: the rule runs only if this holds too; on a button, the button is greyed while it does not | ||
| chance | number 0–1 | 1 | the odds it runs when triggered | |
| cooldown | number 0–3600 | seconds before it may run again | ||
| max | integer 1–1000 | times it may run on one unit, ever | ||
| do | effect | effect[] | yes | what it does: an effect or a list of up to 8, in order (see Effects) |
Exactly one trigger. A when runs the moment its condition becomes true and not again until it has been false; one held back by its if or its cooldown tries again while the condition still holds. An every counts from the unit's making or its last change of form. A rule's do runs in order and stops at a change of form.
Conditions (when, if)
| field | type | required | default | meaning |
|---|---|---|---|---|
| moving | boolean | is driving, flying or swimming (true) or standing (false) | ||
| still | number 0–3600 | has not moved for at least this many seconds | ||
| firedWithin | number 0–3600 | fired within the last so many seconds | ||
| quiet | number 0–3600 | has not fired for at least this many seconds | ||
| hurtWithin | number 0–3600 | was hurt within the last so many seconds | ||
| hpBelow | number 0–1 | health below this share of its whole | ||
| hpAbove | number 0–1 | health above this share of its whole | ||
| age | number 0–36000 | seconds since it was made, or last changed form | ||
| flag | string | a flag a rule has set on it is up | ||
| noFlag | string | that flag is down | ||
| kills | integer 0–10000 | it has made at least this many kills | ||
| rank | integer 1–3 | its veteran rank is at least this | ||
| onWater | boolean | stands on water (true) or on land (false) | ||
| enemyWithin | number 0.5–32 | an enemy its side can see is within this many tiles | ||
| near | { units, kind, side, within, count } | others stand near it: at least `count` of these `units` or this `kind`, on this `side`, `within` so many tiles (see Near) | ||
| night | boolean | it is night (true) or day (false) | ||
| carrying | integer 1–50 | has at least this many units in its hold | ||
| killedBy | id[] | on `destroyed`: what killed it was one of these defs (the dead rise only when the dead killed them) | ||
| any | condition | a list of conditions, one of which must hold | ||
| not | condition | a condition that must not hold |
Near (when.near)
| field | type | required | default | meaning |
|---|---|---|---|---|
| units | id[] | these defs only: the game's or any mod's | ||
| kind | unit | building | only units, or only buildings | ||
| side | friend | enemy | any | any | whose: its own side and its allies (`friend`), an enemy's (only what its side can see), or anyone's | |
| within | number 0.5–32 | yes | tiles from it to the other's edge | |
| count | integer 1–50 | 1 | at least this many |
What stands near the unit, measured to the other's edge: a flyer that takes off only with something to hook onto ({ "kind": "building", "within": 8 }), troops that fight harder beside their commander ({ "units": ["mymod-captain"], "side": "friend", "within": 10 }), a wall that wakes when its master comes by. An enemy is counted only when its side can see it.
Effects (do)
| field | type | required | default | meaning |
|---|---|---|---|---|
| morph | id | become another def of this mod, in place: the same unit (its selection, its kills and rank, the orders the new form can carry out), its health keeping its share of the whole. A building only takes the form of a building of the same footprint | ||
| spawn | { unit, count, side, into, max } | units put down beside it, or into its hold (see Spawn) | ||
| heal | number -1000000–1000000 | hit points given back; negative takes them, never the last one | ||
| healPct | number -1–1 | a share of its whole health given back | ||
| metal | number -99999–99999 | metal to its side; negative takes it, never below nothing | ||
| flag | string | raise a flag on it, for a condition to read | ||
| unflag | string | lower that flag | ||
| buff | { speed, damage, reload, taken, for } | multipliers held for `for` seconds: `speed`, the `damage` it deals, its `reload` time, and the harm it is `taken`; a new buff replaces the one it has | ||
| explode | { dmg, radius, cls, friendlyFire } | a blast round it: `dmg` at the centre falling to half at the edge of `radius` (world px), through the armour row of `cls` (default he); its own side is spared unless `friendlyFire` | ||
| fx | string | an effect played where it stands: one of this mod's `fx.<name>` sheets, or fx.expl.s, fx.expl.m, fx.expl.l, fx.spark, fx.flak, fx.smoke, fx.splash, fx.splash.l, fx.muzzle, fx.repair, fx.emp, fx.nuke | ||
| fxScale | number 0.05–8 | 1 | the effect drawn at this multiple | |
| sound | string | a sound played where it stands: a weapon sound, expl, explBig, upgrade, or one of this mod's `sounds` | ||
| die | boolean | it is destroyed, as if killed by nobody (its own `destroyed` rules run) | ||
| remove | boolean | it is gone without a trace: no wreck, no loss, no `destroyed` |
A spawn (do.spawn)
| field | type | required | default | meaning |
|---|---|---|---|---|
| unit | id | yes | the unit: one of the game's or this mod's | |
| count | integer 1–16 | 1 | how many | |
| side | own | killer | own | whose they are: its own side's, or (on `destroyed`) the side that killed it | |
| into | hold | straight into its own hold, as far as the room goes, instead of beside it | ||
| max | integer 1–64 | at most this many of the units this rule has spawned alive at once |
A button (rule.button)
| field | type | required | default | meaning |
|---|---|---|---|---|
| name | text | the form it makes | the button's label | |
| desc | text | its tooltip line | ||
| cost | number 0–99999 | 0 | metal, paid as the work is done | |
| time | number 0–3600 | 0 | seconds of work at full power; 0 is at once | |
| requires | id[] | buildings that must stand, or tech nodes researched, for it to be pressed (and to go on) | ||
| ai | boolean | a computer side presses it too, when it can spare the metal |
A shield (shield)
| field | type | required | default | meaning |
|---|---|---|---|---|
| hp | number 1–1000000 | yes | what it takes before the hull does | |
| regen | number 0–100000 | 0 | recharged a second | |
| delay | number 0–600 | 3 | seconds unhurt before it starts to recharge |
A carrier's wing (wing)
| field | type | required | default | meaning |
|---|---|---|---|---|
| unit | id | yes | the plane: an aircraft of this mod with `"pop": 0` and `"producedBy": []`, made by its carrier alone | |
| count | integer 1–16 | 1 | planes it keeps | |
| rebuild | number 0.5–600 | 10 | seconds to make a lost one again, for nothing, one at a time | |
| sortie | number 1–600 | 15 | seconds a plane stays out before it comes back to rearm | |
| rearm | number 0–120 | 3 | seconds a plane back aboard waits before it flies again, mended as it waits | |
| range | number 1–32 | 10 | tiles from the carrier its planes go out to fight |
Last edited