Skip to content

A town simulation in pale isometric line art, implemented with Ritmo ECS and PixiJs 3D

Open the guide step by step, wait for buildings to stand, and tidy the bars

SandroMaglione978de0608b44
diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md
index d2f3e1c..e6417bf 100644
--- a/DEVELOPMENT.md
+++ b/DEVELOPMENT.md
@@ -264,7 +264,7 @@ pnpm balance -- --snapshot 40 # save each seed's town at minut
## Sharing a town
-**share** (top right, and on the reckoning) draws the town as the camera
+**share** (bottom right, and on the reckoning) draws the town as the camera
sees it into a 1200 × 630 card (at 2×), with the term's state and numbers on a
strip of paper. **Save the picture** downloads it; on a phone it goes to the
share sheet instead. **Make a link** uploads the town (its save file, gzipped,
diff --git a/docs/how-to-play.md b/docs/how-to-play.md
index ce110f2..cae1473 100644
--- a/docs/how-to-play.md
+++ b/docs/how-to-play.md
@@ -27,7 +27,7 @@ town, the levers you hold, how a term ends, and how the town works underneath.
| **1**, **2**, **3** | run at 1×, 2×, 4× |
| **Esc** | stop placing, close the panel |
-Share, the guide, save, load, and new town sit in the top right, beside the people. The town also autosaves
+Share, the guide, save, load, and new town sit in the bottom right. The town also autosaves
every two minutes of game time, and **load** takes whichever save is newer.
New town and load ask before they replace the town you have.
@@ -153,13 +153,16 @@ walk to, no food in store) and, under *lately*, the news of the last minute
and a half, which also pops up as it happens. Click a line to go there.
Above them, the **guide** tells a new mayor the next step to take and why,
-one at a time: homes and food first, then planks and stone, then fire,
-winter, wear, and the services, then the chains that turn settlers into
-citizens, and last the crown, trade, and taxes. Each building it names is a
+one at a time. It opens with homes, food, planks, and stone, one after
+another, each once the last is built. After that it speaks when the town
+needs it (planks or stone running low, the woods thinning, a risk rising)
+and keeps quiet for a while after each step; the crown's request, winter, a
+fire, and the sick do not wait. A step that asks for a building is done when
+the building stands, not when it is laid. Each building it names is a
chip that starts placing one, and "show me where" goes to the water, woods,
or rocks it means. A step is put away for good once the town has done it
(shown or not), or when the ✕ skips it; *hide guide* turns it off, and the
-**guide** button in the top right turns it back on. The guide is saved
+**guide** button in the bottom right turns it back on. The guide is saved
with the town, and starts over with a new one.
## Wear, spoilage, and winters
diff --git a/scripts/check-browser.ts b/scripts/check-browser.ts
index 377ca56..618a11a 100644
--- a/scripts/check-browser.ts
+++ b/scripts/check-browser.ts
@@ -47,7 +47,7 @@ try {
await page.waitForFunction(()=>!window.town.ui.founding)
await page.locator(".toolbar .pause").click()
const hall=(await entities("Town/TownHall"))[0]!,tile=hall.components["Town/Tile"]
- await page.getByRole("button",{name:"Rotate map right",exact:true}).click()
+ await page.keyboard.press("e")
await clickGrid(tile.x+1.5,tile.y+1.5,48)
await page.waitForFunction(id=>window.town.ui.selected===id,hall.id)
assert.equal((await page.evaluate(()=>window.town.ui.panel))?.type,"building")
@@ -73,7 +73,7 @@ try {
assert.ok((await entities("Town/House")).some(e=>!("Town/Site" in e.components)))
facts.liveConstruction=true
await tool("select")
- await page.getByRole("button",{name:"Rotate map right",exact:true}).click()
+ await page.keyboard.press("e")
const lt=lumber.components["Town/Tile"]
await clickGrid(lt.x+1,lt.y+1,16)
await page.waitForFunction(id=>window.town.ui.selected===id,lumber.id)
@@ -138,13 +138,13 @@ try {
await page.evaluate(([x,y])=>window.town.view.focus(x!,y!),[ht.x+1.5,ht.y+1.5])
await capture("populated-town")
for (let angle=0;angle<8;angle++) {
- await page.getByRole("button",{name:"Rotate map right",exact:true}).click()
+ await page.keyboard.press("e")
await clickGrid(ht.x+1.5,ht.y+1.5,48)
await page.waitForFunction(id=>window.town.ui.selected===id,grownHall.id)
await page.locator(".panel .close").click()
}
facts.selectionAllEightAngles=true
- await page.getByRole("button",{name:"Rotate map right",exact:true}).click()
+ await page.keyboard.press("e")
await capture("populated-rotated")
await page.getByRole("button",{name:"4×",exact:true}).click()
const before=await snapshot()
@@ -159,7 +159,7 @@ try {
facts.liveWalkerMovement=true
await page.setViewportSize({width:390,height:844})
await page.getByRole("button",{name:"Reset camera",exact:true}).click()
- await page.getByRole("button",{name:"Rotate map left",exact:true}).click()
+ await page.keyboard.press("q")
assert.equal(await page.evaluate(()=>[...document.querySelectorAll(".camera-controls,.toolbar,.system,.hud")].some(e=>{const r=e.getBoundingClientRect();return r.left<0||r.right>innerWidth+1})),false)
facts.phoneViewport=true
await tool("homes")
diff --git a/src/factory.css b/src/factory.css
index a433284..3b9b142 100644
--- a/src/factory.css
+++ b/src/factory.css
@@ -44,11 +44,14 @@ body { font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
.hud .good.empty { opacity: 0.55; }
/* ── The toolbar: the town's panel, the tools, the speed ── */
-.toolbar, .system { position: fixed; display: flex; align-items: stretch; gap: 8px; z-index: 2; }
-.toolbar { bottom: calc(14px + env(safe-area-inset-bottom)); left: 16px; max-width: calc(100vw - 32px); overflow-x: auto; }
-/* Share, the guide, save, load, new town: icons in a row at the top, left of the people's card (its width set by the page). */
-.system { top: 12px; right: calc(24px + var(--people-width, 330px)); transition: right 240ms cubic-bezier(.2,.8,.2,1); }
-.panel-open .system { right: calc(384px + var(--people-width, 330px)); }
+.toolbar, .system {
+ position: fixed; bottom: calc(14px + env(safe-area-inset-bottom)); display: flex; align-items: stretch; gap: 8px; z-index: 2;
+}
+.toolbar { left: 16px; max-width: calc(100vw - 32px); overflow-x: auto; }
+/* Share, the guide, save, load, new town: icons in the bottom right. With the panel open it moves over, and up above the toolbar it would cover. */
+.system { right: 16px; transition: right 240ms cubic-bezier(.2,.8,.2,1), bottom 240ms cubic-bezier(.2,.8,.2,1); }
+.panel-open .system { right: 376px; bottom: calc(70px + env(safe-area-inset-bottom)); }
+@media (max-width: 1210px) { .system { bottom: calc(70px + env(safe-area-inset-bottom)); } }
.toolbar .group, .system {
display: flex; gap: 4px; padding: 5px; background: #f7f8f4; border: 1px solid #c9cec4; border-radius: 8px; box-shadow: 0 2px 0 #dfe2db;
}
@@ -62,8 +65,6 @@ body { font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
.toolbar button kbd { font: inherit; font-size: 10px; opacity: 0.55; }
.toolbar .pause { padding: 6px 9px; }
.toolbar .pause.on .glyph { background: none; }
-/* With the panel open, the people move over and leave no room beside them, unless the screen is wide. */
-@media (max-width: 1440px) { .panel-open .system { display: none; } }
.system button { color: #5d6861; font-size: 0; gap: 0; padding: 6px 9px; }
.system button.labelled { font-size: 12px; gap: 7px; padding: 6px 10px; }
.system .guide-toggle.on { color: #2f5a9c; background: #eef3fb; border-color: #c9d6ee; }
diff --git a/src/host.ts b/src/host.ts
index 141063b..6a892a9 100644
--- a/src/host.ts
+++ b/src/host.ts
@@ -353,10 +353,8 @@ export const createHost = async (mount: HTMLElement, persistence: () => Persiste
ui.view = view
for (const v of viewEls) v.button.classList.toggle("on", v.view === view)
}
- // Share, the guide, save, load, and new town: a row of icons at the top,
- // beside the people (it keeps its distance as their card grows). Founding
- // or loading replaces the town, so each asks first.
- new ResizeObserver(() => document.body.style.setProperty("--people-width", `${folk.offsetWidth}px`)).observe(folk)
+ // Share, the guide, save, load, and new town: a row of icons in the bottom
+ // right. Founding or loading replaces the town, so each asks first.
const action = (name: IconName, label: string, tip: string, run: () => void) => {
const button = el("button", name === "share" ? "labelled" : "")
button.title = tip
@@ -1571,7 +1569,7 @@ export const createHost = async (mount: HTMLElement, persistence: () => Persiste
dismissed.add(off.dataset.dismiss!)
return
}
- // The guide: put this step away, or turn the guide off (the top-right button turns it back on).
+ // The guide: put this step away, or turn the guide off (the bottom-right button turns it back on).
const skip = target.closest<HTMLElement>("[data-skip]")
if (skip) {
ui.guide.push({ type: "skip", id: skip.dataset.skip! })
@@ -1579,7 +1577,7 @@ export const createHost = async (mount: HTMLElement, persistence: () => Persiste
}
if (target.closest("[data-guide-off]")) {
ui.guide.push({ type: "off" })
- ui.toast("Guide off · turn it back on from the top right")
+ ui.toast("Guide off · turn it back on from the bottom right")
return
}
const ref = target.closest<HTMLElement>("[data-kind]")
@@ -1676,7 +1674,7 @@ export const createHost = async (mount: HTMLElement, persistence: () => Persiste
const g = s.guide.step
const guideHtml = g
? [
- `<div class="head guide"><span>guide · ${escapeHtml(g.chapter)}</span><span class="progress" title="Steps of the guide done">${s.guide.done} of ${s.guide.total} done</span><button class="quiet" data-guide-off title="Turn the guide off (the guide button in the top right turns it back on)">hide guide</button></div>`,
+ `<div class="head guide"><span>guide · ${escapeHtml(g.chapter)}</span><span class="progress" title="Steps of the guide done">${s.guide.done} of ${s.guide.total} done</span><button class="quiet" data-guide-off title="Turn the guide off (the guide button in the bottom right turns it back on)">hide guide</button></div>`,
`<div class="cell alert hint guide${g.at !== null ? " place" : ""}" data-guide>${icon("hint", 16, "mark")}<span class="text">${callouts(g.text)}</span><span class="acts">${g.at !== null ? `<button class="act locate" title="Show me where">${icon("locate", 14)}</button>` : ""}<button class="act dismiss" data-skip="${escapeHtml(g.key)}" title="Skip this step">${icon("close", 12)}</button></span></div>`
]
: []
diff --git a/src/map-lab/map.ts b/src/map-lab/map.ts
index 30917b6..476dd01 100644
--- a/src/map-lab/map.ts
+++ b/src/map-lab/map.ts
@@ -139,14 +139,17 @@ const quarter: Array<[string, number, number]> = [
for (const [id, x, y] of quarter) place(id, x, y)
// The review annex gives seasonal/condition variants their own ground,
// keeping them apart from the functioning town streets.
-face([[-20, 17, -0.5], [18, 17, -0.5], [18, 29, -0.5], [-20, 29, -0.5]], 0xf0f2ec, true)
+face([[-20, 17, -0.5], [18, 17, -0.5], [18, 31, -0.5], [-20, 31, -0.5]], 0xf0f2ec, true)
inkAssets.filter(a => a.category === "buildings" && a.appearance).forEach((a, i) => place(a.id, -17 + (i % 7) * 5, 18 + Math.floor(i / 7) * 5))
const homes = inkAssets.filter((a) => a.category === "homes")
homes.forEach((a, i) => place(a.id, -7 + (i % 4) * 1.8, 6 + Math.floor(i / 4) * 2))
const trees = inkAssets.filter((a) => a.reference?.type === "tree")
trees.forEach((a, i) => place(a.id, -17 + (i % 3) * 1.3, -11 + Math.floor(i / 3) * 1.4))
for (let i = 0; i < 18; i++) place(trees[i % trees.length]!.id, -8 + (i % 9) * 2.4, -14 + Math.floor(i / 9) * 1.2, 1, false)
-inkAssets.filter((a) => a.reference?.type === "rock").forEach((a, i) => place(a.id, -16 + (i % 2) * 1.5, 4 + Math.floor(i / 2) * 1.5))
+// Single-cell rocks in a pair of rows; the bigger outcrops (2×1, 2×2, 3×3, stone then ore) in a row along the annex.
+const rocks = inkAssets.filter((a) => a.reference?.type === "rock")
+rocks.filter((a) => a.footprint === 1).forEach((a, i) => place(a.id, -16 + (i % 2) * 1.5, 4 + Math.floor(i / 2) * 1.5))
+rocks.filter((a) => a.footprint! > 1).forEach((a, i) => place(a.id, -17 + i * 4.5, 28.5))
inkAssets.filter((a) => a.reference?.type === "field").forEach((a, i) => place(a.id, -8 + (i % 2) * 1.2, -10 + Math.floor(i / 2) * 1.2))
place("roads", 15, 8)
place("paved-street", 15, 12)
diff --git a/src/phone.css b/src/phone.css
index b978b73..9fac52f 100644
--- a/src/phone.css
+++ b/src/phone.css
@@ -85,7 +85,7 @@
.hud { top: calc(6px + env(safe-area-inset-top)); gap: 5px; }
.hud .card .cell { padding: 5px 10px; }
.toolbar { bottom: calc(6px + env(safe-area-inset-bottom)); }
- .system { top: calc(6px + env(safe-area-inset-top)); }
+ .system { bottom: calc(6px + env(safe-area-inset-bottom)); }
.panel-open .system { display: none; }
.camera-controls { bottom: calc(60px + env(safe-area-inset-bottom)); padding: 3px; }
.views { bottom: calc(60px + env(safe-area-inset-bottom)); }
@@ -97,6 +97,8 @@
/* A small landscape window: the map views stand in a column on the right, so the ticker and the speed keep left of it. */
@media (max-width: 760px) and (max-height: 500px) {
.hud.left { right: 66px; }
+ /* Portrait puts the bar at the top; it must not also keep landscape's bottom. */
+ .system, .panel-open .system { bottom: auto; }
.toolbar .speed { right: 66px; }
}
diff --git a/src/present.ts b/src/present.ts
index 805d2df..790bfaf 100644
--- a/src/present.ts
+++ b/src/present.ts
@@ -87,7 +87,7 @@ import { emptyPreview, type Alert as Notice, type HitBox, type Legend, type Line
import { blockers as blockersOf, streetAdvice, type InTown, type Served, type Street } from "./rules/explain.ts"
import { breadBonus, streetTax, suppliedTaxOf } from "./rules/households.ts"
import { rockBlocks, type RockPart } from "./render3d/rock-blocks.ts"
-import { GUIDE_QUIET, guideDone, guideStep, guideSteps, type GuideFacts, type GuideFocus } from "./rules/guide.ts"
+import { GUIDE_QUIET, guideBuilding, guideDone, guideStep, guideSteps, type GuideFacts, type GuideFocus } from "./rules/guide.ts"
import { ticks } from "./content.ts"
const cellAt = (at: Point): Point => {
@@ -1109,6 +1109,7 @@ export const Interact = Game.System(
})
const facts: GuideFacts = {
homes: houses.length,
+ builtHomes: houses.filter(finished).length,
residents: census.settlers + census.citizens,
citizens: census.citizens,
finerHomes: houses.filter((row) => row.data.house.get().tier > 1).length,
@@ -1254,7 +1255,7 @@ export const Interact = Game.System(
chronicle: resources.chronicle.get().lines,
alerts,
guide: {
- step: step && shown ? { key: step.id, chapter: step.chapter, text: step.text, at: shown.at, size: shown.at?.size ?? 1, id: shown.id } : null,
+ step: step && shown ? { key: step.id, chapter: step.chapter, text: guideBuilding(step, facts) ? `${step.text} Laid: it starts once the builders finish it.` : step.text, at: shown.at, size: shown.at?.size ?? 1, id: shown.id } : null,
done: guideSteps.filter((s) => put.has(s.id)).length,
total: guideSteps.length,
off: guide.off
diff --git a/src/render3d/input.ts b/src/render3d/input.ts
index 836567c..6ff4deb 100644
--- a/src/render3d/input.ts
+++ b/src/render3d/input.ts
@@ -138,7 +138,7 @@ export class MapInput {
this.controls = document.createElement("nav")
this.controls.className = "camera-controls"
this.controls.setAttribute("aria-label", "Map camera")
- this.controls.innerHTML = `<button data-mode="pan" aria-pressed="true" title="Drag to pan; the road, pave, home, and park ground tools drag to build">Pan</button><button data-mode="rotate" aria-pressed="false" title="Drag to rotate instead of placing. Right-drag also rotates.">Rotate</button><button data-action="left" aria-label="Rotate map left" title="Rotate left (Q)">↶</button><button data-action="right" aria-label="Rotate map right" title="Rotate right (E)">↷</button><button data-action="out" aria-label="Zoom out">−</button><output aria-label="Camera zoom"></output><button data-action="in" aria-label="Zoom in">+</button><button data-action="reset" aria-label="Reset camera" title="Original angle and centre (Home)">⌂</button>`
+ this.controls.innerHTML = `<button data-mode="pan" aria-pressed="true" title="Drag to pan; the road, pave, home, and park ground tools drag to build">Pan</button><button data-mode="rotate" aria-pressed="false" title="Drag to rotate instead of placing. Right-drag also rotates, and Q and E turn it an eighth.">Rotate</button><button data-action="out" aria-label="Zoom out">−</button><output aria-label="Camera zoom"></output><button data-action="in" aria-label="Zoom in">+</button><button data-action="reset" aria-label="Reset camera" title="Original angle and centre (Home)">⌂</button>`
this.controls.querySelectorAll<HTMLButtonElement>("button").forEach(
(button) =>
(button.onclick = () => {
@@ -148,8 +148,6 @@ export class MapInput {
ui.dragFrom = null
this.press = null
}
- if (button.dataset.action === "left") scene.rotate(-Math.PI / 4)
- if (button.dataset.action === "right") scene.rotate(Math.PI / 4)
if (button.dataset.action === "out") scene.zoomBy(0.8)
if (button.dataset.action === "in") scene.zoomBy(1.25)
if (button.dataset.action === "reset") scene.resetCamera()
diff --git a/src/rules/guide.ts b/src/rules/guide.ts
index 705b637..55d2f5f 100644
--- a/src/rules/guide.ts
+++ b/src/rules/guide.ts
@@ -8,19 +8,25 @@
* is in order of priority, not of chapters: a request from the crown with a
* deadline goes ahead of a chain that takes minutes to build.
*
- * Steps come when the town needs them, not back to back: each waits for a
+ * The first steps (`opening`) come one after another, each once the last
+ * is built: homes, then food, then planks, then stone, so a new mayor learns
+ * the store and its chains. After them, steps come when the town needs them,
+ * not back to back: each waits for a
* sign (planks running low, the woods thinning, a fire risk rising), and
* after one is done the guide keeps quiet for `GUIDE_QUIET` seconds. An
* urgent step (the crown's request, winter, a fire, the sick, a building
* falling apart) does not wait for the quiet. A step once shown stays until
- * it is done or put away, so the ticker does not hop between steps.
+ * it is done or put away, so the ticker does not hop between steps. A step
+ * that asks for a building is done when the building stands, not when it is
+ * laid.
*/
import type { Amounts, KindId } from "../content.ts"
/** What the guide reads of the town. */
export interface GuideFacts {
- /** Homes laid, built or not. */
+ /** Homes laid, built or not; and built. */
readonly homes: number
+ readonly builtHomes: number
readonly residents: number
/** Citizens, and homes that hold them (citizens' homes and townhouses). */
readonly citizens: number
@@ -71,28 +77,36 @@ export interface GuideStep {
readonly text: string
readonly focus: GuideFocus | null
readonly when: (f: GuideFacts) => boolean
+ /** The buildings it asks for (done when they stand). */
+ readonly kinds?: ReadonlyArray<KindId>
+ /** One of the first steps, which come one after another, without the quiet. */
+ readonly opening?: boolean
/** It cannot wait for the guide's quiet (and goes ahead of the step shown). */
readonly urgent?: (f: GuideFacts) => boolean
readonly done: (f: GuideFacts) => boolean
}
-const has = (f: GuideFacts, ...kinds: ReadonlyArray<KindId>) => kinds.every((k) => f.placed.has(k))
+/** Every one of these buildings stands (built, not only laid). */
+const has = (f: GuideFacts, ...kinds: ReadonlyArray<KindId>) => kinds.every((k) => f.standing.has(k))
export const guideSteps: ReadonlyArray<GuideStep> = [
{
id: "homes",
chapter: "Founding",
- text: "Drag a row of homes along the road from the town hall (H), or lay more road first (R). Settlers move in on their own, and every home pays taxes.",
+ text: "Drag a row of homes along the road from the town hall (H), or lay more road first (R). Builders carry planks from the store to each one; once it stands, settlers move in on their own, and every home pays taxes.",
focus: "hall",
+ opening: true,
when: () => true,
- done: (f) => f.homes > 0
+ done: (f) => f.builtHomes > 0
},
{
id: "fishery",
chapter: "Founding",
- text: "Settlers eat, and the fish in store will not last. Build a fishery (B) on a road within two cells of water; the town hall's walker carries the fish to the homes.",
+ text: "The bar at the top is the town's store. Settlers eat fish from it, and the fish there will not last. Build a fishery (B) on a road within two cells of water; the town hall's walker carries the fish to the homes.",
focus: "water",
- when: (f) => f.homes > 0,
+ kinds: ["fishery"],
+ opening: true,
+ when: (f) => f.builtHomes > 0,
done: (f) => has(f, "fishery") || has(f, "bakery")
},
{
@@ -106,6 +120,7 @@ export const guideSteps: ReadonlyArray<GuideStep> = [
},
{
id: "winter",
+ kinds: ["granary", "smokehouse"],
chapter: "Keeping it standing",
text: "Winter is coming: fishing slows, homes eat faster, and fish rots in store. A granary keeps fish five times as long, and a smokehouse makes fish that keeps all winter.",
focus: "hall",
@@ -124,13 +139,16 @@ export const guideSteps: ReadonlyArray<GuideStep> = [
{
id: "planks",
chapter: "Founding",
- text: "Every home and building costs planks. A lumberjack by the woods fells wood, and a sawmill saws it into planks.",
+ text: "Every home and building costs planks from the store, and they run out. Goods come in chains: a lumberjack by the woods fells wood, and a sawmill saws the wood into planks.",
focus: "trees",
- when: (f) => f.stock.planks < 25 || (f.standing.has("fishery") && f.homes >= 6),
+ kinds: ["lumberjack", "sawmill"],
+ opening: true,
+ when: (f) => f.stock.planks < 25 || f.standing.has("fishery"),
done: (f) => has(f, "lumberjack", "sawmill")
},
{
id: "forester",
+ kinds: ["forester"],
chapter: "Founding",
text: "The lumberjack is running out of trees. A forester beside it plants new ones for it to fell.",
focus: { kind: "lumberjack" },
@@ -140,13 +158,16 @@ export const guideSteps: ReadonlyArray<GuideStep> = [
{
id: "quarry",
chapter: "Founding",
- text: "Storage, workshops, and paving take stone, and the town starts with little. A quarry cuts it from the rocks nearby.",
+ text: "Storage, workshops, and paving take stone, and the town starts with little. A quarry cuts it from the pale rocks nearby (the dark ones are ore, for later).",
focus: "stone",
- when: (f) => f.stock.stone < 10 || (f.standing.has("sawmill") && f.homes >= 10),
+ kinds: ["quarry"],
+ opening: true,
+ when: (f) => f.stock.stone < 10 || has(f, "lumberjack", "sawmill"),
done: (f) => has(f, "quarry")
},
{
id: "firewatch",
+ kinds: ["firewatch"],
chapter: "Keeping it standing",
text: "The risk of fire is rising: wooden cottages catch fire, and a fire spreads to its neighbours. A fire watch sends a watchman along the streets, and firefighters to any blaze. Press F to see the risk.",
focus: "hall",
@@ -156,6 +177,7 @@ export const guideSteps: ReadonlyArray<GuideStep> = [
},
{
id: "builder",
+ kinds: ["builder"],
chapter: "Keeping it standing",
text: "Buildings wear out, and a run-down one works at half pace and may fall. A builder's yard mends what its builder passes, with planks and stone. Press C to see their condition.",
focus: "worn",
@@ -165,6 +187,7 @@ export const guideSteps: ReadonlyArray<GuideStep> = [
},
{
id: "market",
+ kinds: ["market"],
chapter: "Keeping it standing",
text: "The town hall's walker only reaches 20 road cells. A market sends a walker with fish, bread, and cloth further along the streets.",
focus: "hall",
@@ -181,6 +204,7 @@ export const guideSteps: ReadonlyArray<GuideStep> = [
},
{
id: "cloth",
+ kinds: ["sheep", "weaver", "chapel"],
chapter: "Growing citizens",
text: "Settlers become citizens, who pay twice as much, once they have bread, cloth, and faith. Now open: a sheep farm and a weaver make cloth, and a chapel brings faith.",
focus: "hall",
@@ -189,6 +213,7 @@ export const guideSteps: ReadonlyArray<GuideStep> = [
},
{
id: "bread",
+ kinds: ["farm", "mill", "bakery"],
chapter: "Growing citizens",
text: "Bread is the last of a citizen's needs. Now open: a farm grows wheat, a mill grinds it into flour, and a bakery bakes the bread.",
focus: "hall",
@@ -205,6 +230,7 @@ export const guideSteps: ReadonlyArray<GuideStep> = [
},
{
id: "healer",
+ kinds: ["healer"],
chapter: "Keeping it standing",
text: "Sickness is spreading: hunger, crowding, and a quarry's dust make homes sick, and a sick home holds half as many. A healer's physician calls on the homes and cures them. Press A to see the risk.",
focus: "hall",
@@ -214,6 +240,7 @@ export const guideSteps: ReadonlyArray<GuideStep> = [
},
{
id: "watchhouse",
+ kinds: ["watchhouse"],
chapter: "Keeping it standing",
text: "Thieves are about: poor streets, half-empty homes, and low approval breed them. A watch house sends a constable along the streets to keep order. Press O to see the risk.",
focus: "hall",
@@ -238,6 +265,7 @@ export const guideSteps: ReadonlyArray<GuideStep> = [
},
{
id: "smithy",
+ kinds: ["mine", "smithy"],
chapter: "Governing",
text: "Ore is for one thing: tools. Now open: a mine by the dark, rust-veined rocks digs ore, and a smithy forges it into tools, which every workshop and lamp needs and which wear out.",
focus: "ore",
@@ -250,6 +278,10 @@ export const guideSteps: ReadonlyArray<GuideStep> = [
export const guideDone = (f: GuideFacts, done: ReadonlySet<string>): Array<string> =>
guideSteps.filter((s) => !done.has(s.id) && s.done(f)).map((s) => s.id)
+/** The step asks for buildings that are laid but not all standing yet: say so, rather than ask again. */
+export const guideBuilding = (step: GuideStep, f: GuideFacts) =>
+ step.id === "homes" ? f.homes > 0 && f.builtHomes === 0 : (step.kinds ?? []).some((k) => f.placed.has(k) && !f.standing.has(k))
+
/**
* The step to show now, if any: an urgent one first; else the step already
* shown (`shown`), until it is done or put away; else, unless the guide is
@@ -261,5 +293,6 @@ export const guideStep = (f: GuideFacts, done: ReadonlySet<string>, pace: { read
if (urgent) return urgent
const shown = guideSteps.find((s) => s.id === pace.shown && open(s) && (!s.urgent || s.when(f)))
if (shown) return shown
- return pace.quiet ? null : (guideSteps.find((s) => open(s) && s.when(f)) ?? null)
+ // The opening steps come one after another; the rest wait out the quiet.
+ return guideSteps.find((s) => open(s) && s.when(f) && (!pace.quiet || s.opening)) ?? null
}
diff --git a/test/guide.test.ts b/test/guide.test.ts
index bc89559..e643182 100644
--- a/test/guide.test.ts
+++ b/test/guide.test.ts
@@ -8,10 +8,11 @@ import assert from "node:assert/strict"
import { test } from "node:test"
import { amounts, kinds, type KindId } from "../src/content.ts"
-import { guideDone, guideStep, guideSteps, type GuideFacts } from "../src/rules/guide.ts"
+import { guideBuilding, guideDone, guideStep, guideSteps, type GuideFacts } from "../src/rules/guide.ts"
const fresh: GuideFacts = {
homes: 0,
+ builtHomes: 0,
residents: 0,
citizens: 0,
finerHomes: 0,
@@ -38,6 +39,7 @@ const town = (over: Partial<GuideFacts>, built: ReadonlyArray<KindId> = []): Gui
...fresh,
placed: new Set(built),
standing: new Set(built),
+ builtHomes: over.homes ?? 0,
...over
})
const none = new Set<string>()
@@ -56,17 +58,36 @@ test("what the town has done is put away, shown or not", () => {
assert.ok(next && !put.includes(next.id), "the next step is one not yet done")
})
-test("steps wait for the town to need them, not for the last one to be done", () => {
- const founded = town({ homes: 4, residents: 8 }, ["fishery", "lumberjack", "sawmill"])
- const put = new Set(guideDone(founded, none))
+test("the opening comes step after step, each once the last is built", () => {
+ assert.equal(guideStep(fresh, none, { quiet: true })?.id, "homes")
+ const laid = town({ homes: 4, builtHomes: 0 })
+ assert.equal(guideStep(laid, new Set(guideDone(laid, none)))?.id, "homes", "laid homes are not yet done")
+ const housed = town({ homes: 4, residents: 8 })
+ const put = new Set(guideDone(housed, none))
+ assert.equal(guideStep(housed, put, { quiet: true })?.id, "fishery", "no quiet in the opening")
+ const building = { ...housed, placed: new Set<KindId>(["fishery"]) }
+ const step = guideStep(building, put)!
+ assert.equal(step.id, "fishery")
+ assert.ok(guideBuilding(step, building), "a laid fishery is told as being built")
+ const fed = town({ homes: 4, residents: 8 }, ["fishery"])
+ assert.equal(guideStep(fed, new Set(guideDone(fed, none)), { quiet: true })?.id, "planks")
+ const sawn = town({ homes: 4, residents: 8 }, ["fishery", "lumberjack", "sawmill"])
+ assert.equal(guideStep(sawn, new Set(guideDone(sawn, none)), { quiet: true })?.id, "quarry")
+})
+
+const founded: ReadonlyArray<KindId> = ["fishery", "lumberjack", "sawmill", "quarry"]
+
+test("after the opening, steps wait for the town to need them", () => {
+ const settled = town({ homes: 4, residents: 8 }, founded)
+ const put = new Set(guideDone(settled, none))
// Planks in hand, stone in hand, the woods full, no risk: nothing to say.
- assert.equal(guideStep(founded, put), null)
- assert.equal(guideStep(town({ homes: 4, residents: 8, fewTrees: true }, ["fishery", "lumberjack", "sawmill"]), put)?.id, "forester")
- assert.equal(guideStep(town({ homes: 4, residents: 8, stock: amounts({ planks: 40, stone: 6 }) }, ["fishery", "lumberjack", "sawmill"]), put)?.id, "quarry")
+ assert.equal(guideStep(settled, put), null)
+ assert.equal(guideStep({ ...settled, fewTrees: true }, put)?.id, "forester")
+ assert.equal(guideStep({ ...settled, risk: { fire: true, health: false, order: false } }, put)?.id, "firewatch")
})
test("after a step the guide keeps quiet, but not through a fire or the crown's request", () => {
- const facts = town({ homes: 8, residents: 16, fewTrees: true }, ["fishery", "lumberjack", "sawmill"])
+ const facts = town({ homes: 8, residents: 16, fewTrees: true }, founded)
const put = new Set(guideDone(facts, none))
assert.equal(guideStep(facts, put, { quiet: true }), null)
assert.equal(guideStep({ ...facts, burning: 1 }, put, { quiet: true })?.id, "firewatch")
@@ -74,13 +95,12 @@ test("after a step the guide keeps quiet, but not through a fire or the crown's
})
test("a step once shown stays until it is done, even if its sign fades", () => {
- const built: ReadonlyArray<KindId> = ["fishery", "lumberjack", "sawmill"]
- const put = new Set(["homes", "fishery", "planks"])
- const low = town({ homes: 4, residents: 8, stock: amounts({ planks: 40, stone: 6 }) }, built)
- assert.equal(guideStep(low, put)?.id, "quarry")
- const bought = town({ homes: 4, residents: 8, stock: amounts({ planks: 40, stone: 30 }) }, built)
- assert.equal(guideStep(bought, put), null)
- assert.equal(guideStep(bought, put, { shown: "quarry" })?.id, "quarry")
+ const thinning = town({ homes: 4, residents: 8, fewTrees: true }, founded)
+ const put = new Set(guideDone(thinning, none))
+ assert.equal(guideStep(thinning, put)?.id, "forester")
+ const planted = { ...thinning, fewTrees: false }
+ assert.equal(guideStep(planted, put), null)
+ assert.equal(guideStep(planted, put, { shown: "forester" })?.id, "forester")
})
test("a step the mayor skipped stays away", () => {