In almost every strategy game I've played, a click is a command and the command is obeyed in the same frame. I wanted to find out what happens if you take that away. So I built Chief's Fire, a free strategy game that runs in the browser, around one rule: an order is not obeyed until it arrives.
You're the chief, one person standing on the map. People close enough to hear you act right away. Everyone else finds out when a runner reaches them on foot, or when a chain of drum towers passes the order along. This post is about how that's modelled in TypeScript, and what went wrong on the way.
The setup
| Piece | What I used |
|---|---|
| Language | TypeScript |
| Build | Vite |
| Simulation | Fixed step, 20 steps a second, separate from drawing |
| Rendering | Canvas 2D |
The simulation is deterministic and knows nothing about the screen. That matters here, because a delayed order is state that has to survive a save, a reload and an 8x fast-forward.
One entry point for every order
The player's clicks and the computer's tribes both go through the same function. That was the first decision, and it's the one I'd keep if I threw everything else out. The computer chiefs wait on runners exactly like you do, because there's no other way in.
/** Main entry point. The player's commands and the AI both come through here. */ export function issueOrder(S: State, trId: number, ids: number[], orderIn: Order, horn = false): IssueResult { const tr = S.tribes[trId]; // ...collect the living recipients that belong to this tribe... const order: Order = { ...orderIn, issued: S.t }; // stamp it with the sim time const chief = S.byId.get(tr.chiefId) as Unit | undefined; const near: Actor[] = [], far: Actor[] = []; for (const r of recips) { // inside the voice ring: hears it now. Outside: needs a carrier. if (chief && dhypot(chief.x - r.x, chief.y - r.y) <= CFG.COMMAND_RADIUS + r.r) near.push(r); else far.push(r); } for (const r of near) deliver(S, r, order); // instant let how: IssueResult['how'] = null; if (far.length && chief) how = route(S, tr, chief, far, order); // drums or a runner return { ok: true, instant: near.length, far: far.length, how }; } The return value tells the interface how many heard it at once and how the rest will get it, so the game can say "a runner sets out to 4 far away (about 12s)" instead of leaving you guessing.
A runner is a unit with a payload
My first version of "delay" was a timer: work out the distance, divide by a speed, deliver when the timer runs out. It took about ten minutes to write and it was wrong for the game. A timer can't be killed. Nothing on the map shows you the order is on its way, and wolves can't eat it.
So a runner is a real unit. It walks, it can be seen, and it carries the order with it:
export function spawnRunner(S: State, tr: Tribe, x: number, y: number, recips: Actor[], order: Order, post = 0): Unit { const r = addUnit(S, tr.id, 'runner', x + (S.rand() - 0.5) * 10, y + (S.rand() - 0.5) * 10, 20 * 60); r.post = post; // which pool it belongs to: 0 is the chief r.payload = { order, ids: recips.map((e) => e.id), done: new Set() }; // who still needs to hear it return r; } The done set is there because the people in one order aren't always standing together. The runner visits them, ticks each one off, then walks home. If the runner dies, the payload dies with it and nobody is told. The player gets no error message for that. The army just doesn't move, which is exactly the feeling I was after.
Two runners, and a queue
You only have a couple of runners. When they're all out, a new order waits:
function sendRunner(S: State, tr: Tribe, x: number, y: number, recips: Actor[], order: Order, node: number): boolean { if (runnersOut(S, tr, node) < poolSize(node)) { spawnRunner(S, tr, x, y, recips, order, node); return true; } tr.waiting.push({ ids: recips.map((r) => r.id), order, node }); // wait for one to come home if (tr.waiting.length > CFG.RUNNER_QUEUE) { tr.waiting.shift(); // the oldest order is forgotten log(S, tr.id, 'Too many orders are waiting for a runner. The oldest was dropped.', 'warn'); } return false; } This is where the first real bug showed up. Players (well, me) click twice. Click a far group, right-click a spot, decide it's the wrong spot, right-click again. With a naive queue that's two runners used and two orders delivered in sequence, so the group walks to the wrong place first. It felt like the game was punishing a habit every RTS has taught for thirty years.
The fix is two rules in the routing step:
// A newer order replaces any that are still waiting for the same people... for (const w of tr.waiting) w.ids = w.ids.filter((id) => !ids.has(id)); tr.waiting = tr.waiting.filter((w) => w.ids.length); // ...and repeating an order that is already on its way sends nothing new. for (const u of S.units) if (!u.dead && u.tribe === tr.id && u.payload && sameOrder(u.payload.order, order)) for (const id of u.payload.ids) if (!u.payload.done.has(id)) carried.add(id); A waiting order can be replaced, because it hasn't left yet. An order already in a runner's hands can't be called back, but asking for the same thing again doesn't waste a second runner. That split between "still at the fire" and "already gone" turned out to be the whole feel of the mechanic.
Drums are a graph
Later in a match your elders can remember Drums, and you build drum towers. Towers within reach of each other form a network. I keep the connected components up to date as towers are built and burned, and note which component the chief is standing in.
When an order goes out, the router picks the tower in the chief's component that is closest to the people being ordered, and uses it only if that actually beats walking:
const direct = dhypot(chief.x - c.x, chief.y - c.y); // c is the middle of the recipients if (best && bestD + 80 < direct) { const hops = dhypot(chief.x - best.x, chief.y - best.y); const delay = hops / CFG.DRUM_SPEED + 2; // sound is fast, not instant tr.drums.push({ at: S.t + delay, start: S.t, node: best.id, ids: recips.map((r) => r.id), order }); return 'drums'; } Yes, the drum signal is a timer, the thing I said was wrong for runners. Here it's fine, because the signal can still fail: when it arrives, the code checks that the tower is still standing. If it burned while the signal was on its way, the order is lost. Anyone within reach of the tower hears it, and anyone further out gets a runner from that tower's own small pool. If a tower with waiting orders is destroyed, those orders fall back to the chief's runners.
Pay when it arrives, not when you ask
This one caught me out. Raising a villager costs food. If the cost comes off when you click, a delayed order is just a slow order. So the cost is paid when the order reaches the village:
/** An order arrives at a unit or building. Costs are paid now, not when the order was given. */ if (canPay(tr, def.cost)) { pay(tr, def.cost); e.queue.push({ utype: order.utype, left: def.time || 20 }); } else log(S, tr.id, `The village could not raise a ${def.name.toLowerCase()}: not enough supplies when the order arrived.`, 'warn'); Now you can send three orders to a far village with food for two, and find out later that the third one bounced. It also meant I didn't have to write any refund logic for orders that never arrive, which I was not looking forward to.
The horn
Testing showed there are a few moments in a match when delay stops being interesting and is just cruel, like the ice reaching a village you can't warn in time. So the chief has a horn, a few uses per match, that skips routing and delivers to everyone at once. It's one if at the top of issueOrder. Give players a small, scarce way around your own rule and they're a lot happier living with it the rest of the time.
What I'd do differently
- I'd build the message log first. Delayed command with no feedback feels like input lag. Half the work was telling the player what happened to their order.
- I'd write the "replace waiting, don't duplicate carried" rules on day one instead of after getting annoyed at my own game.
- I'm still not sure two runners is the right number. That's the kind of thing I want to hear from people who play it.
You can see all of this running at chiefsfire.com. It's free, there's no signup, and it needs a mouse. The how to play page covers voice, runners, drums and the horn in a couple of minutes. It's new, so if something's broken I'd like to know.
Feel free to take the runner-with-a-payload idea and bend it to fit your own game.


