Log inGet started
World

Escapement

Branchmain
Branchesmain
Commit7683e73a7f

README.md

Director

The referee. One of these sits on the scene's Director entity and owns Core.state() — it is the only thing that writes the tick, the phase, the outcome, and every unit's ring, sector, winding and rust. Everything else in Escapement reads that state and reacts to the signals fired here.

The law it applies lives next door in game.rules, which answers every legality question purely off the shared state. This component is the half that is allowed to write: it asks the law, applies the answer, and fires the signal.

Getting hold of it

local d = entity.find("Director").component.get("Director")

Commanding an automaton

One action each per turn. Winding is the resource that carries across turns, so the question is never "what can I afford this turn" but "how long can this automaton keep going".

CallCostsDoes
d:move(unitId, ring, sector)1steps one open link
d:strike(unitId, targetId)2bites power off a blight's rust
d:windAlly(unitId, targetId)2gives an adjacent automaton 3, thawing it
d:hold(unitId)—stands still, and books the end-of-turn winding
d:endTurn()—the blight's turn, the winding, then the machine turns

Every one of them answers { ok = boolean, reason = string }. A refusal carries the reason in plain words — "the machine offers no crossing there this tick", "frozen — an adjacent automaton must wind it back up" — so an interface can tell the player why rather than doing nothing.

Ask before you spend with d:canMove(unitId, ring, sector), d:canStrike(unitId, targetId) and d:canWind(unitId, targetId), which answer the same shape without touching anything.

Reading the board

CallAnswers
d:snapshot()tick, phase, outcome, selection, every unit, the planks down
d:reachable(unitId)the cells this automaton may step onto, this tick
d:strikeTargets(unitId)the blight ids it may bite, this tick
d:windTargets(unitId)the ally ids it may wind, this tick
d:preview(unitId)the world point its cell will be at once the machine turns
d:planks()the counterweight ground currently lying on the board
d:cost(kind)what "move", "strike" or "windAlly" costs
d:unit(unitId)the live unit record

d:snapshot() is the one to use from a script, a tool or a test. Components and modules share one require registry and can read Core.state() directly; an execute call gets its own registry and therefore its own, empty Core.

The turn, in order

d:endTurn() runs the rest of the turn in one call:

  1. blight — the rust takes its turn. If the unit host offers a runBlight, that is the blight's turn and the referee only supplies the economy calls it makes. Otherwise the referee runs its own climb, and sends its own reinforcements in through the vents.
  2. the winding — every automaton that stood still all turn is wound: three on a mainspring node, one anywhere else. Standing still means it was not commanded and its winding is no lower than when the turn began, so rust in the gears is the one thing a spring cannot be wound through.
  3. advance — the tick lands. Every address stays where it is and every cell moves, so every unit is carried wherever the metal takes it.

The match ends the moment any of these is true, checked after every phase: the rust stands on the escapement (lost), every automaton has run down (lost), or the tick reaches Core.TICKS_TO_HOUR (won). Core.SIGNAL.matchEnded carries { outcome, reason }.

d:newMatch() clears the board and musters the roster again — what an end-of-match screen calls to play once more.

Fields

FieldDefaultMeaning
autoPlayfalseend the turn on a timer, with nobody commanding
secondsPerAutoTurn2.5how long each of those turns lasts
blightWavestruesend reinforcements when the referee is running the blight itself