Skip to content

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

Ticker chips go to standing buildings; clearer crown request; guide orders citizens' needs

SandroMaglione9de5dbb3acbf
diff --git a/docs/how-to-play.md b/docs/how-to-play.md
index cae1473..1af76d1 100644
--- a/docs/how-to-play.md
+++ b/docs/how-to-play.md
@@ -154,7 +154,9 @@ 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. It opens with homes, food, planks, and stone, one after
-another, each once the last is built. After that it speaks when the town
+another, each once the last is built, and then shows where to look: a
+home's panel, and the town panel. Citizens' needs come as one goal once
+bread can be made, bread first, since settlers want only food. 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
diff --git a/src/factory.css b/src/factory.css
index 3b9b142..3aac8db 100644
--- a/src/factory.css
+++ b/src/factory.css
@@ -15,6 +15,9 @@ body { font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
/* ── The top bar: the term and the treasury on the left, the people on the right ── */
.hud { position: fixed; top: 12px; display: flex; flex-direction: column; gap: 8px; font-size: 12px; max-width: calc(50vw - 24px); z-index: 2; }
+/* The column is as wide as its widest card; the space beside a narrower card is the map, and takes its clicks. */
+.hud { pointer-events: none; }
+.hud > * { pointer-events: auto; }
.hud.left { left: 16px; align-items: flex-start; }
.hud.right { right: 16px; align-items: flex-end; cursor: pointer; transition: right 240ms cubic-bezier(.2,.8,.2,1); }
.panel-open .hud.right { right: 376px; }
@@ -50,7 +53,9 @@ body { font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
.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)); }
+/* With the panel open: a column of icons beside it, above the toolbar. */
+.panel-open .system { right: 376px; bottom: calc(70px + env(safe-area-inset-bottom)); flex-direction: column; }
+.panel-open .system button.labelled { font-size: 0; gap: 0; padding: 6px 9px; }
@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;
@@ -185,12 +190,19 @@ body { font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
.hud .clock .winter { color: #3d6db5; font-weight: 600; }
.hud .request, .hud .alarm { display: none; }
.hud .request.show, .hud .alarm.show { display: flex; }
-.hud .request { border-color: #d6ae2e; box-shadow: 0 2px 0 #eadca7; }
+.hud .request { border-color: #d6ae2e; box-shadow: 0 2px 0 #eadca7; width: 440px; max-width: 100%; box-sizing: border-box; }
+.hud .request .cell { flex: 1; min-width: 0; gap: 12px; }
+.hud .request .lines { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
+.hud .request .ask { display: flex; align-items: center; gap: 5px; white-space: nowrap; font-size: 13px; }
+.hud .request .terms { white-space: normal; font-size: 11px; color: #77817a; }
+.hud .request .terms b { color: #3d4943; }
.hud .request .send {
- font: inherit; font-size: 12px; margin: 4px 6px 4px 0; padding: 2px 12px; border: 1px solid #3d4943; border-radius: 3px;
- background: #3d4943; color: #f7f8f4; cursor: pointer;
+ font: inherit; font-size: 12px; margin: 8px 8px 8px 0; padding: 4px 16px; border: 1px solid #3d4943; border-radius: 5px;
+ background: #3d4943; color: #f7f8f4; cursor: pointer; transition: background 120ms ease, box-shadow 120ms ease;
}
-.hud .request .send:disabled { background: transparent; color: #8a938c; border-color: #c9cec4; cursor: default; }
+.hud .request .send:not(:disabled):hover { background: #26302b; box-shadow: 0 2px 0 #c9b25e; }
+.hud .request .send:not(:disabled):active { transform: translateY(1px); box-shadow: none; }
+.hud .request .send:disabled { background: transparent; color: #8a938c; border-color: #c9cec4; cursor: not-allowed; }
.hud .alarm { flex-direction: column; border-color: #b04a39; box-shadow: 0 2px 0 #e6c3bc; color: #b04a39; white-space: normal; }
.hud .alarm .cell + .cell { border-left: 0; border-top: 1px solid #ecd2cc; }
.hud .alarm.good { border-color: #4f8a3e; box-shadow: 0 2px 0 #cfe0c5; color: #4f8a3e; }
@@ -362,7 +374,8 @@ body { font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
box-shadow: inset 3px 0 0 transparent;
}
.hud .ticker .cell + .cell { border-left: none; border-top: 1px dashed #e3e6df; }
-.hud .ticker .cell .mark { margin-top: 2px; }
+/* The icon as tall as a line of text, so it sits centred on the first line. */
+.hud .ticker .cell .mark { height: 1.55em; }
.hud .ticker .cell .text { flex: 1; min-width: 0; }
.hud .ticker .cell em { font-style: normal; color: #9aa29b; white-space: nowrap; }
.hud .ticker .cell.place { cursor: pointer; }
@@ -400,6 +413,9 @@ body { font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
.ref.kind { background: #eef3fb; border: 1px solid #c9d6ee; color: #2f5a9c; }
button.ref.kind { cursor: pointer; }
button.ref.kind:hover { background: #dce6f5; border-color: #3d6db5; }
+/* A building that stands already: its chip goes there. */
+.ref.kind.go { background: #f4f2ea; border-color: #d9d3bf; color: #5b5338; }
+button.ref.kind.go:hover { background: #ebe7d8; border-color: #8a7d55; }
kbd.key {
display: inline-block; min-width: 1.6ch; padding: 0 4px; font: inherit; font-size: 10px; line-height: 1.5; text-align: center;
color: #3d4943; background: #fbfcf9; border: 1px solid #c9cec4; border-bottom-width: 2px; border-radius: 4px; vertical-align: 1px;
diff --git a/src/host.ts b/src/host.ts
index 6a892a9..6d29c56 100644
--- a/src/host.ts
+++ b/src/host.ts
@@ -94,13 +94,15 @@ const namedPattern = new RegExp(`\\b(${namedThings.map((t) => t.word.replace(/[.
* A message as markup: each building it names becomes a chip to click (to
* build one), each good a chip with its icon, and each key in brackets a key.
*/
-const callouts = (text: string): string =>
+/** `standing`: buildings the line is about, which stand already; their chips go to them rather than placing another. */
+const callouts = (text: string, standing: ReadonlySet<KindId> = new Set()): string =>
escapeHtml(text).replace(namedPattern, (match, word: string | undefined, key: string | undefined) => {
if (key) return `<kbd class="key">${key}</kbd>`
const thing = namedThings.find((t) => t.word === word!.toLowerCase())
if (!thing) return match
if ("good" in thing.ref) return `<span class="ref ware" title="${goods[thing.ref.good].title}">${goodIcon(thing.ref.good, 13)}${match}</span>`
const kind = kinds[thing.ref.kind]
+ if (standing.has(thing.ref.kind)) return `<button class="ref kind go" data-go="${thing.ref.kind}" title="Go to the ${kind.title.toLowerCase()}">${icon("locate", 13)}${match}</button>`
return kind.buildable
? `<button class="ref kind" data-kind="${thing.ref.kind}" title="Build a ${kind.title.toLowerCase()}: ${escapeHtml(kind.blurb)}">${icon("build", 13)}${match}</button>`
: `<span class="ref kind" title="${escapeHtml(kind.blurb)}">${icon("town", 13)}${match}</span>`
@@ -1580,6 +1582,14 @@ export const createHost = async (mount: HTMLElement, persistence: () => Persiste
ui.toast("Guide off · turn it back on from the bottom right")
return
}
+ // A building the line is about: go to it.
+ const go = target.closest<HTMLElement>("[data-go]")
+ if (go) {
+ const row = go.closest<HTMLElement>("[data-alert]")
+ const there = row ? tickerLines.alerts[Number(row.dataset.alert)]?.places?.[go.dataset.go as KindId] : undefined
+ if (there) goTo(there.at, there.size, there.id)
+ return
+ }
const ref = target.closest<HTMLElement>("[data-kind]")
if (ref) {
const kind = ref.dataset.kind as KindId
@@ -1632,7 +1642,13 @@ export const createHost = async (mount: HTMLElement, persistence: () => Persiste
request.classList.toggle("show", s.crown.open && s.fate.state === "playing")
if (s.crown.open) {
const have = s.stock[s.crown.good]
- setHtml(requestText, `${icon("crown", 18)}<span>the crown asks for <b>${s.crown.amount}</b> ${goodIcon(s.crown.good, 14)} <b>${goods[s.crown.good].title}</b> <span class="muted">(${have} in store)</span> · <b>${clockText(s.crown.left)}</b> · +${s.crown.reward} coins</span>`)
+ // What is asked on top, in one line; the terms under it.
+ setHtml(
+ requestText,
+ `${icon("crown", 18)}<span class="lines"><span class="ask">the crown asks for <b>${s.crown.amount}</b> ${goodIcon(s.crown.good, 14)} <b>${goods[s.crown.good].title}</b></span>` +
+ `<span class="terms"><span class="${have < s.crown.amount ? "down" : "up"}">${have} in store</span> · due in <b>${clockText(s.crown.left)}</b> · +${s.crown.reward} coins</span></span>`
+ )
+ send.title = have < s.crown.amount ? `Not enough ${goods[s.crown.good].title} in store yet` : `Send ${s.crown.amount} ${goods[s.crown.good].title} to the crown for ${s.crown.reward} coins`
send.disabled = have < s.crown.amount
}
// What threatens the term, or is about to complete it.
@@ -1666,7 +1682,8 @@ export const createHost = async (mount: HTMLElement, persistence: () => Persiste
return sec < 5 ? "just now" : sec < 60 ? `${sec} s ago` : `${Math.round(sec / 60)} min ago`
}
const alerts = s.alerts.filter((a) => !dismissed.has(`a:${a.text}`))
- const fresh = news.filter((l) => !dismissed.has(`n:${l.tick}:${l.text}`))
+ // The crown's request has its own card while it is open, and is settled after: its news line would only repeat it.
+ const fresh = news.filter((l) => !dismissed.has(`n:${l.tick}:${l.text}`) && !l.text.startsWith("The crown asks"))
const toneIcon = { hint: "hint", warn: "caution", bad: "warning" } as const
const row = (kind: string, tone: string, glyph: IconName, text: string, place: boolean, key: string, data: string) =>
`<div class="cell ${kind} ${tone}${place ? " place" : ""}" ${data}>${icon(glyph, 16, "mark")}<span class="text">${text}</span><span class="acts">${place ? `<button class="act locate" title="Show me where">${icon("locate", 14)}</button>` : ""}<button class="act dismiss" data-dismiss="${escapeHtml(key)}" title="Dismiss">${icon("close", 12)}</button></span></div>`
@@ -1681,7 +1698,7 @@ export const createHost = async (mount: HTMLElement, persistence: () => Persiste
const tickerHtml = [
...guideHtml,
...(alerts.length > 0 ? [`<div class="head">now</div>`] : []),
- ...alerts.map((a) => row("alert", a.tone, toneIcon[a.tone], callouts(a.text), a.at !== null, `a:${a.text}`, `data-alert="${s.alerts.indexOf(a)}"`)),
+ ...alerts.map((a) => row("alert", a.tone, toneIcon[a.tone], callouts(a.text, new Set(Object.keys(a.places ?? {}) as Array<KindId>)), a.at !== null, `a:${a.text}`, `data-alert="${s.alerts.indexOf(a)}"`)),
...(fresh.length > 0 ? [`<div class="head">lately</div>`] : []),
...fresh.map((l) => row("news", "", "chronicle", `${callouts(l.text)} <em data-tick="${l.tick}"></em>`, l.at !== null, `n:${l.tick}:${l.text}`, `data-news="${news.indexOf(l)}"`))
].join("")
diff --git a/src/present.ts b/src/present.ts
index 790bfaf..5b9b209 100644
--- a/src/present.ts
+++ b/src/present.ts
@@ -13,7 +13,7 @@ import { BuildingView, HouseView, WalkerView, TreeView, RockView, FieldView, Rui
import type { DoorSet, OverlayCell } from "./render3d/models.ts"
import {
BUILD_TICKS, COMMUTE, condition as wear, CONDITION_MAX, costText, crewOf, crown as crownRules, fate, goodIds, goods, grounds, home, kinds, needTitle,
- PAVE_COST, propIds, props, risk, RISK_MAX, ROAD_COST, tierHome, total, winters, type GoodId, type Kind, type Tier
+ PAVE_COST, propIds, props, risk, RISK_MAX, ROAD_COST, tierHome, total, winters, type GoodId, type Kind, type KindId, type Tier
} from "./content.ts"
import { around, canPlace, cellOf, doors, entrances, isRoad, key, lPath, nearest, reach, useAt, type TileLike } from "./grid.ts"
import { GRID, inside, U, type Point } from "./iso.ts"
@@ -1034,8 +1034,8 @@ export const Interact = Game.System(
if (census.burning > 0) alerts.push({ tone: "bad", text: `${census.burning} on fire`, at: burningRow?.data.tile.get() ?? null, size: burningRow?.data.tile.get().size ?? 1, id: burningRow?.entity.id ?? null })
const sickRow = houses.find(({ data }) => data.sick.present)
if (census.sick > 0) alerts.push({ tone: "warn", text: `${census.sick} home${census.sick > 1 ? "s" : ""} sick`, at: sickRow?.data.tile.get() ?? null, size: 1, id: sickRow?.entity.id ?? null })
- const waiting = new Map<string, { n: number; at: TileLike; id: number }>()
- const remote = new Map<string, { n: number; at: TileLike; id: number }>()
+ const waiting = new Map<string, { n: number; at: TileLike; id: number; kind: KindId }>()
+ const remote = new Map<string, { n: number; at: TileLike; id: number; kind: KindId }>()
const shortStaffed: Array<{ id: number; title: string; cell: Point; size: number; assigned: number; needed: number; nobodyNear: boolean }> = []
const seen = new Set<number>()
for (const { entity, data } of buildings) {
@@ -1051,21 +1051,23 @@ export const Interact = Game.System(
if (tick - since >= ALERT_PATIENCE) {
const label = `${kind.title.toLowerCase()} (${kind.recipe.input})`
const was = waiting.get(label)
- waiting.set(label, was ? { ...was, n: was.n + 1 } : { n: 1, at: tile, id: entity.id })
+ waiting.set(label, was ? { ...was, n: was.n + 1 } : { n: 1, at: tile, id: entity.id, kind: kind.id })
}
}
if (staff.needed > 0 && staff.assigned < staff.needed) shortStaffed.push({ id: entity.id, title: kind.title.toLowerCase(), cell: tile, size: tile.size, assigned: staff.assigned, needed: staff.needed, nobodyNear: staff.nearby === 0 })
if (status === "unstaffed" && staff.nearby === 0) {
const label = kind.title.toLowerCase()
const was = remote.get(label)
- remote.set(label, was ? { ...was, n: was.n + 1 } : { n: 1, at: tile, id: entity.id })
+ remote.set(label, was ? { ...was, n: was.n + 1 } : { n: 1, at: tile, id: entity.id, kind: kind.id })
}
}
for (const id of [...starvedSince.keys()]) if (!seen.has(id)) starvedSince.delete(id)
const list = (m: Map<string, { n: number }>) => [...m].map(([k, v]) => `${k}${v.n > 1 ? ` ×${v.n}` : ""}`).join(", ")
const first = (m: Map<string, { at: TileLike; id: number }>) => [...m.values()][0]
- if (waiting.size > 0) alerts.push({ tone: "warn", text: `waiting for inputs: ${list(waiting)}`, at: first(waiting)?.at ?? null, size: first(waiting)?.at.size ?? 1, id: first(waiting)?.id ?? null })
- if (remote.size > 0) alerts.push({ tone: "warn", text: `no workers within ${COMMUTE} road cells: ${list(remote)}`, at: first(remote)?.at ?? null, size: first(remote)?.at.size ?? 1, id: first(remote)?.id ?? null })
+ const placesOf = (m: Map<string, { at: TileLike; id: number; kind: KindId }>) =>
+ Object.fromEntries([...m.values()].map((v) => [v.kind, { at: v.at, size: v.at.size, id: v.id }]))
+ if (waiting.size > 0) alerts.push({ tone: "warn", text: `waiting for inputs: ${list(waiting)}`, at: first(waiting)?.at ?? null, size: first(waiting)?.at.size ?? 1, id: first(waiting)?.id ?? null, places: placesOf(waiting) })
+ if (remote.size > 0) alerts.push({ tone: "warn", text: `no workers within ${COMMUTE} road cells: ${list(remote)}`, at: first(remote)?.at ?? null, size: first(remote)?.at.size ?? 1, id: first(remote)?.id ?? null, places: placesOf(remote) })
const hallRow = buildings.find(({ data }) => data.hall.present)
if (census.homes > 0 && larder(stock) === 0) alerts.push({ tone: "bad", text: "no food in store: homes go hungry", at: hallRow?.data.tile.get() ?? null, size: hallRow?.data.tile.get().size ?? 1, id: hallRow?.entity.id ?? null })
const ledger = resources.ledger.get()
@@ -1129,6 +1131,7 @@ export const Interact = Game.System(
taxed: rates.settlers !== 100 || rates.citizens !== 100,
most: Math.max(...goodIds.map((g) => stock[g])),
sawTown: ui.menu === "town",
+ sawHome: houses.some((row) => row.entity.id === ui.selected),
risk: {
fire: houses.some((row) => (maybe(row.data.risk)?.fire ?? 0) >= RISK_MAX * 0.35),
health: houses.some((row) => (maybe(row.data.risk)?.health ?? 0) >= RISK_MAX * 0.35),
diff --git a/src/rules/guide.ts b/src/rules/guide.ts
index 55d2f5f..a6f56cc 100644
--- a/src/rules/guide.ts
+++ b/src/rules/guide.ts
@@ -10,7 +10,8 @@
*
* 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,
+ * the store and its chains; then where to look as the town grows (a home's
+ * panel, the town panel). 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
@@ -53,8 +54,9 @@ export interface GuideFacts {
readonly taxed: boolean
/** The most of any one good in store. */
readonly most: number
- /** The page: the town panel has been open. */
+ /** The page: the town panel has been open; a home has been selected. */
readonly sawTown: boolean
+ readonly sawHome: boolean
/** A home whose risk of fire, sickness, or theft is rising. */
readonly risk: { readonly fire: boolean; readonly health: boolean; readonly order: boolean }
/** A lumberjack with few trees left in reach. */
@@ -165,6 +167,24 @@ export const guideSteps: ReadonlyArray<GuideStep> = [
when: (f) => f.stock.stone < 10 || has(f, "lumberjack", "sawmill"),
done: (f) => has(f, "quarry")
},
+ {
+ id: "look",
+ chapter: "Founding",
+ text: "The town is on its feet. Click a home to see who lives there, what it needs, and what it pays; click any building to see what it makes and what holds it back.",
+ focus: "hall",
+ opening: true,
+ when: (f) => has(f, "quarry") && f.builtHomes > 0,
+ done: (f) => f.sawHome
+ },
+ {
+ id: "watch",
+ chapter: "Founding",
+ text: "As the town grows, keep an eye on the store at the top (goods running low), approval and jobs at the top right, and this ticker, which says what needs looking at. The town panel (T) holds the term's goals, trade, and taxes.",
+ focus: null,
+ opening: true,
+ when: (f) => has(f, "quarry") && f.builtHomes > 0,
+ done: (f) => f.sawTown
+ },
{
id: "firewatch",
kinds: ["firewatch"],
@@ -202,24 +222,24 @@ export const guideSteps: ReadonlyArray<GuideStep> = [
when: (f) => f.poorStreet,
done: (f) => f.finerHomes > 0
},
- {
- 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",
- when: (f) => f.residents >= 15,
- done: (f) => has(f, "sheep", "weaver", "chapel")
- },
{
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.",
+ text: "Settlers become citizens, who pay twice as much, once they have bread, cloth, and faith, all three; settlers want only food until then. Start with bread, the longest chain: a farm grows wheat, a mill grinds it into flour, and a bakery bakes the bread.",
focus: "hall",
when: (f) => f.residents >= 30,
done: (f) => has(f, "farm", "mill", "bakery")
},
+ {
+ id: "cloth",
+ kinds: ["sheep", "weaver", "chapel"],
+ chapter: "Growing citizens",
+ text: "Bread alone makes no citizens: they need cloth and faith too. A sheep farm and a weaver make cloth, and a chapel brings faith (and makes its street more desirable).",
+ focus: "hall",
+ when: (f) => has(f, "farm", "mill", "bakery") || f.residents >= 60,
+ done: (f) => has(f, "sheep", "weaver", "chapel")
+ },
{
id: "goals",
chapter: "Growing citizens",
diff --git a/src/ui.ts b/src/ui.ts
index 525aa01..584447a 100644
--- a/src/ui.ts
+++ b/src/ui.ts
@@ -36,6 +36,8 @@ export interface Alert {
readonly size: number
/** The entity to select on the way there, if there is one. */
readonly id: number | null
+ /** Buildings the line names, by kind: where one of each stands, so its chip goes there rather than placing another. */
+ readonly places?: Partial<Record<KindId, { readonly at: Point; readonly size: number; readonly id: number }>>
}
export type Tool = "select" | "road" | "pave" | "home" | "bulldoze" | "place" | "ground" | "prop"
diff --git a/test/guide.test.ts b/test/guide.test.ts
index e643182..d8668b2 100644
--- a/test/guide.test.ts
+++ b/test/guide.test.ts
@@ -32,6 +32,7 @@ const fresh: GuideFacts = {
taxed: false,
most: 40,
sawTown: false,
+ sawHome: false,
risk: { fire: false, health: false, order: false },
fewTrees: false
}
@@ -73,12 +74,27 @@ test("the opening comes step after step, each once the last is built", () => {
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")
+ // Then where to look: a home's panel, and the town's.
+ const quarried = town({ homes: 4, residents: 8 }, ["fishery", "lumberjack", "sawmill", "quarry"])
+ assert.equal(guideStep(quarried, new Set(guideDone(quarried, none)), { quiet: true })?.id, "look")
+ const looked = { ...quarried, sawHome: true }
+ assert.equal(guideStep(looked, new Set(guideDone(looked, none)), { quiet: true })?.id, "watch")
+})
+
+test("citizens' needs come as one goal, bread first, and not before bread can be made", () => {
+ const ready = town({ homes: 10, residents: 25, sawHome: true, sawTown: true }, ["fishery", "lumberjack", "sawmill", "quarry"])
+ const put = new Set(guideDone(ready, none))
+ assert.notEqual(guideStep(ready, put)?.id, "cloth", "cloth and faith are no use to settlers")
+ const grown = { ...ready, residents: 30 }
+ assert.equal(guideStep(grown, put)?.id, "bread")
+ const baking = town({ homes: 12, residents: 34, sawHome: true, sawTown: true }, ["fishery", "lumberjack", "sawmill", "quarry", "farm", "mill", "bakery"])
+ assert.equal(guideStep(baking, new Set(guideDone(baking, none)))?.id, "cloth")
})
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 settled = town({ homes: 4, residents: 8, sawHome: true, sawTown: true }, 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(settled, put), null)
@@ -87,7 +103,7 @@ test("after the opening, steps wait for the town to need them", () => {
})
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 }, founded)
+ const facts = town({ homes: 8, residents: 16, fewTrees: true, sawHome: true, sawTown: 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")
@@ -95,7 +111,7 @@ 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 thinning = town({ homes: 4, residents: 8, fewTrees: true }, founded)
+ const thinning = town({ homes: 4, residents: 8, fewTrees: true, sawHome: true, sawTown: true }, founded)
const put = new Set(guideDone(thinning, none))
assert.equal(guideStep(thinning, put)?.id, "forester")
const planted = { ...thinning, fewTrees: false }
@@ -161,7 +177,7 @@ test("every step can be done, and a town that has done them all is told nothing"
assert.equal(new Set(all).size, all.length, "step ids are unique")
const finished = town(
{
- homes: 200, residents: 400, citizens: 200, finerHomes: 30, crown: { open: true, met: 3 }, trading: true, taxed: true, sawTown: true,
+ homes: 200, residents: 400, citizens: 200, finerHomes: 30, crown: { open: true, met: 3 }, trading: true, taxed: true, sawTown: true, sawHome: true,
winter: true, worn: true, poorStreet: true, approval: 40, net: -5, most: 120, stock: amounts({ tools: 0 })
},
["fishery", "lumberjack", "sawmill", "forester", "quarry", "granary", "firewatch", "builder", "market", "sheep", "weaver", "chapel", "farm", "mill", "bakery", "healer", "watchhouse", "mine", "smithy"]