Skip to content

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[])

fieldtyperequireddefaultmeaning
oncreated | destroyed | fired | damaged | kill | morphedruns 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`)
whenconditionruns when this condition becomes true, and again only after it has been false (see Conditions)
everynumber 0.25–3600runs every so many seconds of its life
buttonbuttona button on its card the player presses (see Buttons)
ifconditionalso checked when triggered: the rule runs only if this holds too; on a button, the button is greyed while it does not
chancenumber 0–11the odds it runs when triggered
cooldownnumber 0–3600seconds before it may run again
maxinteger 1–1000times it may run on one unit, ever
doeffect | effect[]yeswhat 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)

fieldtyperequireddefaultmeaning
movingbooleanis driving, flying or swimming (true) or standing (false)
stillnumber 0–3600has not moved for at least this many seconds
firedWithinnumber 0–3600fired within the last so many seconds
quietnumber 0–3600has not fired for at least this many seconds
hurtWithinnumber 0–3600was hurt within the last so many seconds
hpBelownumber 0–1health below this share of its whole
hpAbovenumber 0–1health above this share of its whole
agenumber 0–36000seconds since it was made, or last changed form
flagstringa flag a rule has set on it is up
noFlagstringthat flag is down
killsinteger 0–10000it has made at least this many kills
rankinteger 1–3its veteran rank is at least this
onWaterbooleanstands on water (true) or on land (false)
enemyWithinnumber 0.5–32an 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)
nightbooleanit is night (true) or day (false)
carryinginteger 1–50has at least this many units in its hold
killedByid[]on `destroyed`: what killed it was one of these defs (the dead rise only when the dead killed them)
anyconditiona list of conditions, one of which must hold
notconditiona condition that must not hold

Near (when.near)

fieldtyperequireddefaultmeaning
unitsid[]these defs only: the game's or any mod's
kindunit | buildingonly units, or only buildings
sidefriend | enemy | anyanywhose: its own side and its allies (`friend`), an enemy's (only what its side can see), or anyone's
withinnumber 0.5–32yestiles from it to the other's edge
countinteger 1–501at 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)

fieldtyperequireddefaultmeaning
morphidbecome 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)
healnumber -1000000–1000000hit points given back; negative takes them, never the last one
healPctnumber -1–1a share of its whole health given back
metalnumber -99999–99999metal to its side; negative takes it, never below nothing
flagstringraise a flag on it, for a condition to read
unflagstringlower 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`
fxstringan 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
fxScalenumber 0.05–81the effect drawn at this multiple
soundstringa sound played where it stands: a weapon sound, expl, explBig, upgrade, or one of this mod's `sounds`
diebooleanit is destroyed, as if killed by nobody (its own `destroyed` rules run)
removebooleanit is gone without a trace: no wreck, no loss, no `destroyed`

A spawn (do.spawn)

fieldtyperequireddefaultmeaning
unitidyesthe unit: one of the game's or this mod's
countinteger 1–161how many
sideown | killerownwhose they are: its own side's, or (on `destroyed`) the side that killed it
intoholdstraight into its own hold, as far as the room goes, instead of beside it
maxinteger 1–64at most this many of the units this rule has spawned alive at once

A button (rule.button)

fieldtyperequireddefaultmeaning
nametextthe form it makesthe button's label
desctextits tooltip line
costnumber 0–999990metal, paid as the work is done
timenumber 0–36000seconds of work at full power; 0 is at once
requiresid[]buildings that must stand, or tech nodes researched, for it to be pressed (and to go on)
aibooleana computer side presses it too, when it can spare the metal

A shield (shield)

fieldtyperequireddefaultmeaning
hpnumber 1–1000000yeswhat it takes before the hull does
regennumber 0–1000000recharged a second
delaynumber 0–6003seconds unhurt before it starts to recharge

A carrier's wing (wing)

fieldtyperequireddefaultmeaning
unitidyesthe plane: an aircraft of this mod with `"pop": 0` and `"producedBy": []`, made by its carrier alone
countinteger 1–161planes it keeps
rebuildnumber 0.5–60010seconds to make a lost one again, for nothing, one at a time
sortienumber 1–60015seconds a plane stays out before it comes back to rearm
rearmnumber 0–1203seconds a plane back aboard waits before it flies again, mended as it waits
rangenumber 1–3210tiles from the carrier its planes go out to fight

Last edited