Skip to content

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

Merge main (#16: ranks, terms that follow, worked faces, upgrades) into the tutorial

SandroMaglioneda09414370e8
diff --cc docs/how-to-play.md
index dfdbbb3,f080ef1..16be564
--- a/docs/how-to-play.md
+++ b/docs/how-to-play.md
@@@ -165,38 -180,23 +181,39 @@@ from spreading, a fire watch near the c
time, and industry away from homes keeps them healthy and orderly. The town
ticker under the top bar lists what needs attention *now* (fires, sickness,
workshops that have waited half a minute for inputs, workplaces nobody can
-walk to, no food in store) and, under *lately*, the news of the last minute
+walk to, no food in store), each saying what to do about it, 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. It opens with homes, food, planks, and stone, one after
-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
-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 bottom right turns it back on. The guide is saved
-with the town, and starts over with a new one.
+Above them, the **guide** teaches a new mayor the game, one step at a
+time: one thing to do, and one reason for it. It is a course, taught in
+order chapter by chapter and counted (*step 3 of 8*). *Founding*: lay homes
+along the town hall's road, lay a road to the water, build a fishery there,
+open its panel to see its workers, build a lumberjack and a sawmill (once
+planks run low), open the town panel to read the goal, and grow to ten
+homes. *Growing citizens*:
+a quarry, cloth, a chapel, bread, a look at what a home still lacks, and the
- goals again. *Governing*: every goal met. While a step's homes or building
++goals again. *Governing*: the ranks, up to a city (and, once the town rank opens it,
++a market hall where homes lie beyond every walker). While a step's homes or building
+are going up it says so (carriers bringing planks to the site), so you know
+you did your part; when the town cannot build what a step asks for yet, it
+says what opens it (*the farm opens at 30 residents*), or that the treasury
+must save up, and goes on to a building it can. It never asks for a
+building before the town needs it, as upkeep starts the day it stands: the
+lumberjack and sawmill wait until planks fall below 25, the quarry until
+stone falls below 8, a market until homes lie beyond the town hall's walker,
+a smithy until tools run low. Meanwhile the course goes on, and the card
+says what comes next and when. Around the course, it speaks up when the town needs
+something (stone running low, the woods thinning, a risk rising), ahead of
+the course once the town is founded, and keeps quiet about such signs for a
+while after each one; the crown's request, winter, a fire, and the sick do
+not wait. Each building it asks for is a chip that starts placing one, each
+tool, panel, or map view it names is a chip that picks it, and "show me
+where" goes to the water, woods, rocks, or building it means. Its words
+suit the screen: *tap* on a phone, *click* and the key on a computer. 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
+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 --cc src/host.ts
index db6856d,6f7ebcb..1798935
--- a/src/host.ts
+++ b/src/host.ts
@@@ -89,55 -91,7 +91,57 @@@ const namedThings: ReadonlyArray<{ read
{ word: "loaves", ref: { good: "bread" as GoodId } },
{ word: "loaf", ref: { good: "bread" as GoodId } }
].sort((a, b) => b.word.length - a.word.length)
-const namedPattern = new RegExp(`\\b(${namedThings.map((t) => t.word.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|")})\\b|\\(([A-Z])\\)`, "gi")
+/**
+ * Tools, panels, and map views a message can name in brackets ("[homes]",
+ * "[view:fire]"): a chip that picks the tool, opens the panel, or shows the
+ * view. The key goes beside it, for a keyboard (touch screens hide it).
+ */
+const toolRefs: Readonly<Record<string, { readonly label: string; readonly icon: IconName; readonly key?: string; readonly title: string }>> = {
+ select: { label: "select", icon: "select", key: "S", title: "Select: pick a building or home to see what it does" },
+ road: { label: "road", icon: "road", key: "R", title: "Road: drag to lay one" },
+ pave: { label: "pave", icon: "pave", key: "P", title: "Pave: drag along a road to pave it" },
+ homes: { label: "homes", icon: "homes", key: "H", title: "Homes: drag along a road to lay a row" },
+ build: { label: "build", icon: "build", key: "B", title: "Open the build menu" },
+ bulldoze: { label: "bulldoze", icon: "bulldoze", key: "X", title: "Bulldoze: remove what stands on a cell" },
+ town: { label: "town", icon: "town", key: "T", title: "Open the town panel: goals, taxes, and trade" },
+ speed: { label: "speed", icon: "clock", title: "Run time faster: 1×, 2×, 4×" },
+ pause: { label: "pause", icon: "pause", key: "space", title: "Pause the town, or run it again" },
+ "view:appeal": { label: "desirability map", icon: "appeal", key: "D", title: "Colour the map by desirability" },
+ "view:workers": { label: "workers map", icon: "workers", key: "W", title: "Colour the map by workers" },
+ "view:fire": { label: "fire map", icon: "fire", key: "F", title: "Colour the map by fire risk" },
+ "view:health": { label: "health map", icon: "health", key: "A", title: "Colour the map by health risk" },
+ "view:order": { label: "order map", icon: "order", key: "O", title: "Colour the map by the risk of theft" },
+ "view:condition": { label: "condition map", icon: "condition", key: "C", title: "Colour the map by the condition of buildings" }
+}
+const namedPattern = new RegExp(
+ `\\b(${namedThings.map((t) => t.word.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|")})\\b|\\(([A-Z])\\)|\\[([a-z]+(?::[a-z]+)?)\\]`,
+ "gi"
+)
+/** Goods as numbers name them ("2 planks", "1 plank"), and as recipes do ("flour → bread"), by title. */
+const goodWords: ReadonlyArray<readonly [string, GoodId]> = [
+ ...goodIds.map((id) => [goods[id].title, id] as const),
+ ...goodIds.filter((id) => goods[id].title.endsWith("s")).map((id) => [goods[id].title.slice(0, -1), id] as const)
+].sort((a, b) => b[0].length - a[0].length)
+const goodAlternatives = goodWords.map(([w]) => w).join("|")
+const goodOf = (word: string) => goodWords.find(([w]) => w === word)![1]
+/**
+ * Amounts in a line of (escaped) text as icons, where the icon says it as
+ * well as the word: "3 coins a minute" as a coin and 3/min, "2 planks" as a
+ * plank and 2, "flour → bread" with each good's icon.
+ */
+const iconize = (html: string): string =>
+ html
+ .replace(/([+−-]?)(\d+) coins a minute/g, (_, sign: string, n: string) => `<span class="amount">${sign}${icon("coins", 13)}${n}/min</span>`)
+ .replace(/(\d+) coins\b/g, (_, n: string) => `<span class="amount">${icon("coins", 13)}${n}</span>`)
+ .replace(new RegExp(`(\\d+) (${goodAlternatives})\\b`, "g"), (_, n: string, w: string) => `<span class="amount">${goodIcon(goodOf(w), 13)}${n}</span>`)
+ .replace(new RegExp(`\\b(${goodAlternatives}) → (${goodAlternatives})\\b`, "g"), (_, a: string, b: string) => `<span class="amount">${goodIcon(goodOf(a), 13)}${a}</span> → <span class="amount">${goodIcon(goodOf(b), 13)}${b}</span>`)
++ // A cost as icons side by side: the dots between them only crowd it.
++ .replace(/<\/span> · <span class="amount">/g, '</span> <span class="amount">')
+
+/** A finger rather than a mouse: messages say "tap", and keys are left out. */
+const touchScreen = () => matchMedia("(pointer: coarse)").matches
+/** `{tap|click}`: the first on a touch screen, the second with a mouse. */
+const forDevice = (text: string) => text.replace(/\{([^{}|]*)\|([^{}|]*)\}/g, (_, touch: string, mouse: string) => (touchScreen() ? touch : mouse))
/**
* A message as markup: each building it names becomes a chip to click (to
@@@ -412,14 -352,11 +416,14 @@@ export const createHost = async
tints: new Map(),
legend: null,
flash: null,
+ // Long enough to read (about 15 letters a second, and a moment to look), and gone as soon as the mayor
+ // touches the map again: by then they have read it, or are acting on it.
toast: (message) => {
-- toastBox.textContent = message
++ toastBox.innerHTML = iconize(escapeHtml(message))
toastBox.classList.add("show")
+ toastAt = Date.now()
window.clearTimeout(toastTimer)
- toastTimer = window.setTimeout(() => toastBox.classList.remove("show"), 1800)
+ toastTimer = window.setTimeout(() => toastBox.classList.remove("show"), Math.min(8000, Math.max(2200, 1200 + message.length * 65)))
}
}
@@@ -1300,29 -1247,19 +1318,29 @@@
)
const below = el("div", "")
below.append(status, about)
- panel.append(header(title, p.type === "ruin" ? iconEl("condition", 30) : p.type === "park" ? iconEl("decor", 30) : picture(p.type === "building" ? p.kind : p.tier), below))
+ panel.append(header(title, p.type === "ruin" ? iconEl("condition", 30) : p.type === "park" ? iconEl("decor", 30) : picture(p.type === "building" ? p.kind : p.tier, p.type === "building" && p.upgraded), below))
- const box = section(p.type === "building" ? "at work" : p.type === "ruin" ? "what is left" : p.type === "park" ? "what makes it" : "household", p.type === "building" ? "jobs" : p.type === "park" ? "appeal" : "homes")
- box.classList.add("lines")
- const rows: Array<HTMLElement> = []
- panel.append(box)
- // A home: what keeps it from the next tier, in its own box, so the cause is never a word in a longer line.
- const nextBox = p.type === "house" && p.tier < 3 ? section(`to become ${home.tiers[(p.tier + 1) as Tier].title}`, "citizens", "Every line here must clear before the home grows. Needs come from walkers; the street from what stands around it.") : null
- const nextRows: Array<HTMLElement> = []
- const nextNote = el("p", "empty")
- if (nextBox) {
- nextBox.classList.add("lines")
- nextBox.append(nextNote)
- panel.append(nextBox)
+ // A building or a home: its rows in boxes under headings, kept in step with what the town says each frame.
+ // A park or a ruin: one box.
+ const holder = el("div", "")
+ panel.append(holder)
+ const slots: Array<{ box: HTMLElement; rows: Array<HTMLElement>; key: string }> = []
+ const syncGroups = (groups: ReadonlyArray<Group>) => {
+ groups.forEach((g, i) => {
+ const key = `${g.title}|${g.icon}|${g.help ?? ""}`
+ let slot = slots[i]
+ if (!slot || slot.key !== key) {
+ const box = section(g.title, g.icon, g.help)
+ box.classList.add("lines")
+ const fresh = { box, rows: [] as Array<HTMLElement>, key }
+ if (slot) slot.box.replaceWith(box)
+ else holder.append(box)
+ slots[i] = fresh
+ slot = fresh
+ }
+ slot.box.style.display = ""
+ syncLines(slot.box, slot.rows, g.lines)
+ })
+ for (const extra of slots.slice(groups.length)) extra.box.style.display = "none"
}
live.push(() => {
const now = ui.panel
diff --cc src/present.ts
index 5b9d21d,e642a4f..13ad33d
--- a/src/present.ts
+++ b/src/present.ts
@@@ -12,8 -12,8 +12,8 @@@ import { homeHeight, topOf, type Alert
import { BuildingView, HouseView, WalkerView, TreeView, RockView, FieldView, RuinView } from "./render3d/views.ts"
import type { DoorSet, OverlayCell } from "./render3d/models.ts"
import {
- amounts, 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 Amounts, type GoodId, type Kind, type KindId, type Need, type Tier
+ amounts, BUILD_TICKS, builtCost, COMMUTE, condition as wear, CONDITION_MAX, costText, crewOf, crown as crownRules, fate, goodIds, goods, grounds, home, kinds, needTitle,
- PAVE_COST, propIds, props, ranks, risk, RISK_MAX, ROAD_COST, tierHome, total, upkeepOf, winters, type Amounts, type GoodId, type Kind, type KindId, type Tier
++ PAVE_COST, propIds, props, ranks, risk, RISK_MAX, ROAD_COST, tierHome, total, upkeepOf, winters, type Amounts, type GoodId, type Kind, type KindId, type Need, 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"
@@@ -82,10 -83,10 +83,10 @@@ import
type GridValue,
type Status as StatusValue
} from "./schema.ts"
- import { capacity, CELL_STEPS, elapsed, goalsOf, larder, lockReason, met, seasonAt, SITE_SHARE, steadyNet, taxOf, termTicks, winterOf } from "./sim/index.ts"
+ import { capacity, CELL_STEPS, elapsed, goalsOf, larder, lockReason, met, seasonAt, SITE_SHARE, steadyNet, taxOf, termTicks, upgradeBlock, winterOf } from "./sim/index.ts"
import { Townsfolk } from "./townsfolk.ts"
-import { emptyPreview, type Alert as Notice, type HitBox, type Legend, type Line, type View } from "./ui.ts"
-import { blockers as blockersOf, streetAdvice, type InTown, type Served, type Street } from "./rules/explain.ts"
+import { emptyPreview, type Alert as Notice, type Group, type HitBox, type Legend, type Line, type View } from "./ui.ts"
+import { blockers as blockersOf, streetAdvice, streetShort, whyUnmet, type InTown, type Served, type Street } from "./rules/explain.ts"
import { breadBonus, moreAdmin, streetTax, suppliedTaxOf, taxOutlook, type TaxedHome } from "./rules/households.ts"
import { approvalTarget } from "./rules/approval.ts"
import { salvageOf, salvageText } from "./rules/salvage.ts"
@@@ -640,6 -622,14 +651,12 @@@ export const Interact = Game.System
preview.plots.push({ ...cell, size: 1, look: "blocked" })
const there = cell ? parkAt.get(key(cell.x, cell.y))?.data.park.get() : undefined
if (there) preview.tooltip = there.prop !== "none" ? `remove the ${props[there.prop].title.toLowerCase()}` : `remove the ${grounds[there.ground].title.toLowerCase()}`
+ const rock = cell ? rockAt.get(key(cell.x, cell.y)) : undefined
+ if (rock && cell) {
+ const worked = rock.amount <= 1
+ if (worked) preview.plots.push({ ...cell, size: 1, look: "blocked" })
- preview.tooltip = worked
- ? `worked ${rock.ore ? "ore" : "stone"} face · clear it for building: it gives no more`
- : `${rock.ore ? "ore" : "stone"} · ${rock.amount} left · quarry it down to a worked face before it can be cleared`
++ preview.tooltip = worked ? `worked ${rock.ore ? "ore" : "stone"} face · bulldoze to clear it` : `${rock.ore ? "ore" : "stone"} · ${rock.amount} left`
+ }
}
if (ui.selected !== null) {
const row = buildings.find((b) => b.entity.id === ui.selected)
@@@ -726,39 -714,41 +743,41 @@@
tone: !short ? "ok" : staff.assigned > 0 ? "warn" : "bad",
note: short
? staff.nearby === 0
- ? `no ${crew} live within ${COMMUTE} road cells: lay homes nearer${crew === "citizens" ? ", or settlers stand in as apprentices" : ""}`
- : `every ${one} nearby already has a job: lay more homes within ${COMMUTE} road cells`
+ ? `no ${crew} live within ${COMMUTE} road cells: lay homes nearer`
+ : `everyone nearby has a job: lay more homes within ${COMMUTE} road cells`
: staff.apprentices > 0
- ? `${staff.apprentices} settler apprentice${staff.apprentices > 1 ? "s" : ""} stand in for citizens, at three-quarters pace`
+ ? `settlers stand in for citizens, at three-quarters pace`
: undefined
})
- lines.push({ icon: crew, label: `${crew} within ${COMMUTE} road cells`, value: `${staff.nearby}`, tone: "dim" })
}
const recipe = maybe(row.data.recipe)
- const inventory = maybe(row.data.inventory)
if (recipe)
- lines.push({
- icon: recipe.output,
- label: "makes",
- value: `${recipe.input ? `${recipe.inputs} ${goods[recipe.input].title} → ` : ""}${recipe.batch} ${goods[recipe.output].title} · a job every ${Math.round(recipe.period / 60)} s`,
- note: `${recipe.made} made so far${recipe.input ? ` · carriers bring ${goods[recipe.input].title} from whoever makes it, or storage` : ""}`
+ work.push({ icon: recipe.output, label: "makes", value: recipe.input ? `${goods[recipe.input].title} → ${goods[recipe.output].title}` : goods[recipe.output].title })
+ const service = maybe(row.data.service)
+ if (service)
+ work.push({
+ icon: service.service === "goods" ? "trade" : service.service === "faith" ? "faith" : service.service === "repair" ? "repair" : service.service,
+ label: "walkers out",
+ value: `${maybe(row.data.walkers)?.length ?? 0}`
})
+ const inventory = maybe(row.data.inventory)
if (inventory) {
const held = inventory.accepts.filter((g) => inventory.stock[g] > 0).map((g) => ({ good: g, count: inventory.stock[g] }))
- const hall = maybe(row.data.hall) !== undefined
- lines.push(
- held.length > 0
- ? { icon: "jobs", label: "holds", goods: held, note: hall ? `up to ${inventory.cap} of each good; carriers take what sites and workshops ask for, and ${kinds.townhall.carriers} are out at once` : undefined }
- : { icon: "jobs", label: "holds", value: "nothing yet", tone: "dim" }
- )
+ work.push(held.length > 0 ? { icon: "jobs", label: "holds", goods: held } : { icon: "jobs", label: "holds", value: "nothing yet", tone: "dim" })
}
if (kind.wear && inventory)
- lines.push(
+ work.push(
inventory.stock.tools > 0
- ? { icon: "tools", label: "tools", value: `${inventory.stock.tools} on hand`, note: `one wears out every ${kind.wear} jobs; a carrier brings another from storage` }
- : { icon: "tools", label: "tools", value: "none", tone: "bad", note: "half pace until a carrier brings one: a smithy forges them, or buy them in the town panel" }
+ ? { icon: "tools", label: "tools", value: `${inventory.stock.tools}`, tone: "ok" }
+ : { icon: "tools", label: "tools", value: "none", tone: "bad", note: "half pace until one comes: a smithy makes them, or buy them in the town panel" }
)
+ const running: Array<Line> = []
- if (kind.upkeep > 0) running.push({ icon: "upkeep", label: "upkeep", value: `${kind.upkeep} coins a minute` })
++ const upgraded = row.data.upgraded.present
++ const upkeep = upkeepOf(kind, upgraded)
++ if (upkeep > 0) running.push({ icon: "upkeep", label: "upkeep", value: `${upkeep} coins a minute` })
const condition = maybe(row.data.condition)
if (condition)
- lines.push({
+ running.push({
icon: "condition",
label: "condition",
value: percent(condition.value, CONDITION_MAX),
@@@ -772,24 -767,32 +791,25 @@@
label: "fire risk",
value: riskText(r.fire),
tone: r.fire >= risk.warn ? "bad" : r.fire >= RISK_MAX * 0.35 ? "warn" : "ok",
- note: r.fire >= risk.warn ? "a fire watch's watchman resets it as he passes" : kind.hot ? "an oven or a forge: a risk to itself and to homes within 2 cells" : undefined
- })
- const service = maybe(row.data.service)
- const walkers = maybe(row.data.walkers)?.length ?? 0
- if (service)
- lines.push({
- icon: service.service === "goods" ? "trade" : service.service === "faith" ? "faith" : service.service === "repair" ? "repair" : service.service,
- label: "walkers",
- value: `${walkers} out · ${service.range} road cells from the door`,
- note: `one sets out every ${Math.round(service.interval / 60)} s while it is staffed, and serves the homes beside its way`
+ note: r.fire >= RISK_MAX * 0.35 ? "a fire watch's watchman lowers it as he passes" : undefined
})
- if (kind.appeal) running.push({ icon: "appeal", label: "desirability nearby", value: signed(kind.appeal.value) })
- const upgraded = row.data.upgraded.present
+ const appealHere = (upgraded ? kind.upgrade?.appeal : undefined) ?? kind.appeal
- if (appealHere)
- lines.push({
- icon: "appeal",
- label: "desirability around it",
- value: `${signed(appealHere.value)} beside it, fading out to ${appealHere.reach} cells`,
- tone: appealHere.value < 0 ? "warn" : "ok",
- note: appealHere.value < 0 ? "homes this close hold fewer people and pay less; citizens need a street at 5 or more" : undefined
- })
- const upkeep = upkeepOf(kind, upgraded)
- if (upkeep > 0) lines.push({ icon: "upkeep", label: "upkeep", value: `${upkeep} coins a minute` })
++ if (appealHere) running.push({ icon: "appeal", label: "desirability nearby", value: signed(appealHere.value) })
+ const help = [
- kind.upkeep > 0 ? "Upkeep is paid every minute it stands, a quarter of it while paused." : "",
++ upkeep > 0 ? "Upkeep is paid every minute it stands, a quarter of it while paused." : "",
+ condition ? "Everything wears down; a builder's yard mends it." : "",
+ kind.hot ? "An oven or a forge: a fire risk to itself and to homes within 2 cells." : "",
- kind.appeal ? `It changes how nice the streets are out to ${kind.appeal.reach} cells${kind.appeal.value < 0 ? ": homes close by hold fewer people and pay less" : ""}.` : ""
++ appealHere ? `It changes how nice the streets are out to ${appealHere.reach} cells${appealHere.value < 0 ? ": homes close by hold fewer people and pay less" : ""}.` : ""
+ ]
+ .filter((t) => t !== "")
+ .join(" ")
+ const groups: Array<Group> = [
+ ...(work.length > 0 ? [{ title: "at work", icon: "jobs", lines: work } as Group] : []),
+ ...(running.length > 0 ? [{ title: "running it", icon: "coins", help, lines: running } as Group] : [])
+ ]
- const growing = status === "starved" && growingNear(grid, row.data.tile.get(), kind)
+ const growing = status === "starved" && growingNear(grid, row.data.tile.get(), kind, rockAt)
const problem = row.data.burning.present ? "on fire!" : problemOf(kind, status, growing, { nearby: staff.nearby, crew: kind.crew })
- return { kind, status, problem, lines }
+ return { kind, status, problem, groups }
}
/** What the town has of each provision, in storage and on market shelves. */
const inTown = (): InTown => {
@@@ -1000,8 -980,11 +1020,19 @@@
const pickedPark = ui.selected !== null ? parkRows.find((row) => row.entity.id === ui.selected) : undefined
const picked = pickedPark ? parkOf(pickedPark.data.tile.get()) : undefined
if (pickedBuilding) {
- const { kind, status, problem, lines } = describeBuilding(pickedBuilding)
+ const { kind, status, problem, groups } = describeBuilding(pickedBuilding)
- const pausable = kind.id !== "townhall" && !pickedBuilding.data.site.present && !pickedBuilding.data.rising.present
+ const standing = !pickedBuilding.data.site.present && !pickedBuilding.data.rising.present
+ const pausable = kind.id !== "townhall" && standing
+ const upgraded = pickedBuilding.data.upgraded.present
+ const up = kind.upgrade
++ const upgradeOffer = up && standing && !upgraded ? { title: up.title, cost: costText(up.cost), blocked: upgradeBlock(up, resources.fate.get().rank, { ranks }) } : null
++ // The upgrade it could have, as a box of its own: what it is, what it costs, and what keeps it from it now.
++ if (up && upgradeOffer)
++ groups.push({
++ title: `upgrade to ${up.title.toLowerCase()}`,
++ icon: "build",
++ lines: [{ icon: "coins", label: "costs", value: upgradeOffer.cost, tone: upgradeOffer.blocked ? "dim" : undefined, note: upgradeOffer.blocked ?? up.blurb }]
++ })
ui.panel = {
type: "building",
id: pickedBuilding.entity.id,
@@@ -1009,15 -992,19 +1040,17 @@@
kind: kind.id,
status,
problem,
- lines,
+ groups,
pausable,
paused: pickedBuilding.data.paused.present,
- salvage: salvageFor(kind.cost, maybe(pickedBuilding.data.site))
+ salvage: salvageFor(builtCost(kind, upgraded), maybe(pickedBuilding.data.site)),
+ upgraded,
- upgrade: up && standing && !upgraded
- ? { title: up.title, cost: costText(up.cost), blocked: upgradeBlock(up, resources.fate.get().rank, { ranks }) }
- : null
++ upgrade: upgradeOffer
}
} else if (pickedHouse) {
- const { h, lines, blockers } = describeHouse(pickedHouse)
+ const { h, summary, trouble, groups } = describeHouse(pickedHouse)
ui.panel = {
- type: "house", id: pickedHouse.entity.id, cell: pickedHouse.data.tile.get(), tier: h.tier, lines, blockers,
+ type: "house", id: pickedHouse.entity.id, cell: pickedHouse.data.tile.get(), tier: h.tier, summary, trouble, groups,
closable: !pickedHouse.data.site.present && !pickedHouse.data.rising.present && !pickedHouse.data.burning.present,
closed: pickedHouse.data.closed.present,
salvage: salvageFor(home.cost, maybe(pickedHouse.data.site))
@@@ -1299,11 -1258,6 +1332,12 @@@
most: Math.max(...goodIds.map((g) => stock[g])),
sawTown: ui.menu === "town",
sawHome: houses.some((row) => row.entity.id === ui.selected),
+ sawBuilding: buildings.some((row) => row.entity.id === ui.selected && !row.data.hall.present),
+ roadToWater: put.has("road") || roadNearWater(),
+ coins,
+ unreached: put.has("market") || standingKinds.has("market") ? 0 : unreachedHomes(),
- goalsMet: goalsOf(charter, { settlers: census.settlers, citizens: census.citizens, coins, net: steadyNet(resources.history.get().samples, net), approval: mood.approval }).every((g) => g.met),
++ rank: f.rank,
++ upgraded: new Set(buildings.filter((row) => row.data.upgraded.present).map((row) => row.data.building.get().kind)),
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 --cc src/rules/guide.ts
index 0347d30,be54fe6..171ed12
--- a/src/rules/guide.ts
+++ b/src/rules/guide.ts
@@@ -1,49 -1,27 +1,49 @@@
/**
* The mayor's guide: a tutorial told through the ticker, one step at a
- * time. Each step says what to build or do next and why, and names the
- * buildings it means so the ticker can turn them into chips that place
- * them. A step shows while it applies (`when`) and is put away for good
- * once the town has done it (`done`), whether or not it was ever shown, so
- * a mayor who already knows the game is not told what they did. The list
- * is in order of priority, not of chapters: a request from the crown with a
+ * time, written for someone who has never played a town-builder. Each step
+ * is one thing to do (`action`) and one reason for it (`why`), and names the
+ * buildings it asks for (`asks`) so the ticker can turn them into chips that
+ * place them. A step shows while it applies (`when`) and is put away for good
+ * once the town has done it (`done`), whether or not it was ever shown, so a
+ * mayor who already knows the game is not told what they did. The list 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.
*
- * 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; 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
- * 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. A step
- * that asks for a building is done when the building stands, not when it is
- * laid.
+ * Most steps are a course (`course`), taught in order, chapter by chapter,
+ * and counted ("step 3 of 8"). Founding: homes, a road to the water, a
+ * fishery, a look at what it needs, a lumberjack, a sawmill, the term's goal,
+ * and ten homes. Growing citizens: a quarry, cloth, faith, bread, the first
- * citizens, the goals again. Governing: every goal met. The course always has
++ * citizens, the goals again. Governing: the ranks, up to a city. The course always has
+ * something to say, so the guide never falls silent on a mayor who does not
+ * know what comes next; a step whose buildings the town cannot build yet
+ * says what opens them (`lockedNote`), and the course goes on to one it can.
+ *
+ * The course never asks for a building before the town needs it: a
+ * building's upkeep starts the day it stands. A step with a `need` waits for
+ * it (planks running low, stone running low), the course goes on past it,
+ * and the card says what comes next and when (`upcoming`: "next: a
+ * lumberjack and a sawmill, once planks fall below 25 (31 now)").
+ *
+ * Around the course, steps come when the town needs them: each waits for a
+ * sign (stone running low, the woods thinning, a fire risk rising), goes
+ * ahead of the course once Founding is done, and after one is done the guide
+ * keeps quiet about such signs 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 sign once shown stays until 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; in between, `waiting` says what is happening (carriers bringing
+ * planks to the site), so the mayor knows they did the right thing.
+ *
+ * The texts are written once for mouse and touch. In them:
+ * - a building's name (in `asks`) becomes a chip that starts placing one;
+ * - `[homes]`, `[road]`, `[select]`, `[build]`, `[town]`, `[speed]`,
+ * `[pause]`, and `[view:fire]` (any map view) become chips that pick that
+ * tool, open that panel, or show that view; on a keyboard they carry the key;
+ * - `{tap|click}` reads "tap" on a touch screen and "click" with a mouse.
*/
-import type { Amounts, KindId } from "../content.ts"
+import { kinds, type Amounts, type KindId } from "../content.ts"
/** What the guide reads of the town. */
export interface GuideFacts {
@@@ -78,18 -56,9 +78,20 @@@
readonly taxed: boolean
/** The most of any one good in store. */
readonly most: number
- /** The page: the town panel has been open; a home has been selected. */
+ /** The page: the town panel is open; a home is selected; a building (not the town hall) is selected. */
readonly sawTown: boolean
readonly sawHome: boolean
+ readonly sawBuilding: boolean
+ /** A road comes within two cells of water, close enough for a fishery on it. */
+ readonly roadToWater: boolean
- /** Every goal of the term is met now. */
- readonly goalsMet: boolean
++ /** The town's rank: 0 hamlet, 1 village, 2 town, 3 city. */
++ readonly rank: number
++ /** Kinds of building upgraded where they stand (a market hall, a church). */
++ readonly upgraded: ReadonlySet<KindId>
+ /** Coins in the treasury. */
+ readonly coins: number
+ /** Built homes no food walker reaches (the town hall's or a market's). */
+ readonly unreached: number
/** 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. */
@@@ -179,230 -106,101 +181,230 @@@ export const guideSteps: ReadonlyArray<
},
{
id: "fishery",
- goal: "a fishery stands",
chapter: "Founding",
- 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.",
+ course: true,
+ action: "{Tap|Click} fishery, then place it on that road, with water no more than two cells away.",
+ why: "Settlers eat fish. The town starts with a little, and fish rots in store.",
+ goal: "a fishery stands",
+ asks: ["fishery"],
focus: "water",
- opening: true,
- when: (f) => f.builtHomes > 0,
- done: (f) => has(f, "fishery") || has(f, "bakery")
+ when: () => true,
+ done: (f) => has(f, "fishery") || has(f, "bakery"),
+ waiting: rising("fishery")
},
{
- id: "crown",
- goal: "the goods are sent, with the button on the request",
- chapter: "Governing",
- text: "The crown asks for goods by a deadline. Send them from the bar at the top for coins; an unanswered request is a fine, and three missed in a row and the mayor is dismissed.",
- focus: null,
- when: (f) => f.crown.open,
- urgent: () => true,
- done: (f) => f.crown.met > 0
+ id: "look",
+ chapter: "Founding",
+ course: true,
+ action: "Pick [select] and {tap|click} the fishery to open its panel.",
+ why: "A building needs workers from homes within 15 road cells; its panel says how many it has, and what holds it back. The jobs counter at the top adds them all up.",
+ goal: "you open a building's panel",
+ focus: { kind: "fishery" },
+ when: (f) => f.standing.has("fishery"),
+ done: (f) => f.sawBuilding
},
{
- id: "winter",
- goal: "a granary or a smokehouse stands",
- 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",
- when: (f) => f.residents >= 20 && (f.winter || (f.winterIn !== null && f.winterIn <= 120)),
- urgent: () => true,
- done: (f) => has(f, "granary") || has(f, "smokehouse")
+ id: "lumberjack",
+ chapter: "Founding",
+ course: true,
+ action: "Build a lumberjack on a road beside the trees.",
+ why: "Planks are running low, and every home and building costs some. Wood is where planks start.",
+ goal: "a lumberjack stands",
+ asks: ["lumberjack"],
+ focus: "trees",
+ when: () => true,
+ need: (f) => f.stock.planks < PLANKS_LOW || f.placed.has("lumberjack"),
+ soon: (f) => `a lumberjack and a sawmill, once planks fall below ${PLANKS_LOW} (${f.stock.planks} now)`,
+ done: (f) => has(f, "lumberjack"),
+ waiting: rising("lumberjack")
},
{
- id: "tools",
- goal: "the town buys tools (town panel, trade), or a smithy stands",
- chapter: "Growing citizens",
- text: "Tools are running low, and only a smithy makes new ones, which opens at 10 citizens. Until then, buy tools from traders in the town panel (T), and keep them for workshops.",
- focus: null,
- when: (f) => f.residents >= 15 && f.stock.tools <= 3 && !has(f, "smithy"),
- done: (f) => f.buysTools || has(f, "smithy")
+ id: "sawmill",
+ chapter: "Founding",
+ course: true,
+ action: "Build a sawmill on a road near the lumberjack.",
+ why: "Goods come in chains: the lumberjack fells wood, and the sawmill saws it into planks. Carriers walk the goods between them along the roads.",
+ goal: "a sawmill stands",
+ asks: ["sawmill"],
+ focus: { kind: "lumberjack" },
+ when: () => true,
+ need: (f) => f.stock.planks < PLANKS_LOW || f.placed.has("lumberjack") || f.placed.has("sawmill"),
+ soon: (f) => `a sawmill, once planks fall below ${PLANKS_LOW} (${f.stock.planks} now)`,
+ done: (f) => has(f, "sawmill"),
+ waiting: rising("sawmill")
},
{
- id: "planks",
- goal: "a lumberjack and a sawmill stand",
+ id: "term",
chapter: "Founding",
- 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",
- opening: true,
- when: (f) => f.stock.planks < 25 || f.standing.has("fishery"),
- done: (f) => has(f, "lumberjack", "sawmill")
+ course: true,
+ action: "Open the [town] panel and read the goals at its top.",
- why: "Meet every goal before the clock at the top runs out and the town is complete. [pause] stops the clock whenever you need to think.",
++ why: "Meeting them raises the town from hamlet to village, town, and city, each with a reward from the crown. [pause] stops the clock whenever you need to think.",
+ goal: "you open the town panel",
+ focus: null,
+ when: () => true,
+ done: (f) => f.sawTown
},
{
- id: "forester",
- goal: "a forester stands",
+ id: "grow",
chapter: "Founding",
- text: "The lumberjack is running out of trees. A forester beside it plants new ones for it to fell.",
- focus: { kind: "lumberjack" },
- when: (f) => f.fewTrees,
- done: (f) => has(f, "forester")
+ course: true,
+ action: "Lay more roads and homes until ten homes stand.",
+ why: "More people pay more taxes, and unlock new buildings in [build]. The guide asks for a building only once the town needs it.",
+ goal: "10 homes stand",
+ focus: "hall",
+ when: () => true,
+ done: (f) => f.builtHomes >= 10,
+ waiting: (f) => (f.homes >= 10 && f.builtHomes < 10 ? "Ten homes are laid: builders are putting them up." : null)
},
+
+ // ── The course goes on: citizens ──
{
id: "quarry",
+ chapter: "Growing citizens",
+ course: true,
+ action: "Build a quarry on a road beside the pale rocks.",
+ why: "Stone is running low, and the workshops citizens need cost some. The dark rocks are ore, for later.",
goal: "a quarry stands",
- chapter: "Founding",
- 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).",
+ asks: ["quarry"],
focus: "stone",
- opening: true,
- when: (f) => f.stock.stone < 10 || has(f, "lumberjack", "sawmill"),
- done: (f) => has(f, "quarry")
+ when: () => true,
+ need: (f) => f.stock.stone < STONE_LOW || f.placed.has("quarry"),
+ soon: (f) => `a quarry, once stone falls below ${STONE_LOW} (${f.stock.stone} now)`,
+ done: (f) => has(f, "quarry"),
+ waiting: rising("quarry")
},
{
- id: "look",
- goal: "you click a home",
- 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.",
+ id: "cloth",
+ chapter: "Growing citizens",
+ course: true,
+ action: "Build a sheep farm and a weaver, on roads near each other.",
+ why: "A home becomes a citizens' home with bread, cloth, and faith. The sheep farm shears wool, and the weaver weaves it into cloth.",
+ goal: "a sheep farm and a weaver stand",
+ asks: ["sheep", "weaver"],
focus: "hall",
- opening: true,
- when: (f) => has(f, "quarry") && f.builtHomes > 0,
- done: (f) => f.sawHome
+ when: () => true,
+ done: (f) => has(f, "sheep", "weaver"),
+ waiting: rising("sheep", "weaver")
},
{
- id: "watch",
- goal: "you open the town panel (T)",
- 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.",
+ id: "chapel",
+ chapter: "Growing citizens",
+ course: true,
+ action: "Build a chapel on a road among the homes.",
+ why: "Faith is the second need. The chapel's walker brings it to the homes it passes, and the chapel makes its street nicer to live on.",
+ goal: "a chapel stands",
+ asks: ["chapel"],
+ focus: "hall",
+ when: () => true,
+ done: (f) => has(f, "chapel"),
+ waiting: rising("chapel")
+ },
+ {
+ id: "wheat",
+ chapter: "Growing citizens",
+ course: true,
+ action: "Build a farm and a mill.",
+ why: "Bread is the third need, and the longest chain: the farm grows wheat, and the mill grinds it into flour.",
+ goal: "a farm and a mill stand",
+ asks: ["farm", "mill"],
+ focus: "hall",
+ when: () => true,
+ done: (f) => has(f, "farm", "mill"),
+ waiting: rising("farm", "mill")
+ },
+ {
+ id: "bakery",
+ chapter: "Growing citizens",
+ course: true,
+ action: "Build a bakery near the mill.",
+ why: "It bakes the mill's flour into bread. Even a settlers' cottage with bread on the table pays half again.",
+ goal: "a bakery stands",
+ asks: ["bakery"],
+ focus: { kind: "mill" },
+ when: (f) => has(f, "farm", "mill"),
+ done: (f) => has(f, "bakery"),
+ waiting: rising("bakery")
+ },
+ {
+ id: "citizens",
+ chapter: "Growing citizens",
+ course: true,
+ action: "Pick [select] and {tap|click} a home to see what it still lacks to hold citizens.",
+ why: "A home becomes a citizens' home with bread, cloth, and faith, on a street of desirability 5 or more. Its panel lists what is missing.",
+ goal: "the first home holds citizens",
+ focus: "hall",
+ when: () => true,
+ done: (f) => f.finerHomes > 0
+ },
+ {
+ id: "goals",
+ chapter: "Growing citizens",
+ course: true,
+ action: "Open the [town] panel to see how close the goals are.",
- why: "The first citizens have moved in, and three in ten residents must be citizens to complete the town.",
++ why: "The first citizens have moved in, and each rank asks for a bigger share of them.",
+ goal: "you open the town panel",
focus: null,
- opening: true,
- when: (f) => has(f, "quarry") && f.builtHomes > 0,
+ when: (f) => f.finerHomes > 0,
done: (f) => f.sawTown
},
{
- id: "complete",
- id: "grow",
- goal: "10 homes stand",
- chapter: "Founding",
- text: "Now grow. Lay new streets and homes: more residents pay more taxes and open new buildings in the build menu (B). The guide speaks up again when the town needs something.",
++ id: "ranks",
+ chapter: "Governing",
+ course: true,
- action: "Grow the town until every goal in the [town] panel is met.",
- why: "More citizens' homes, approval of 15 or more, and coins to spare. Hold every goal for two minutes and the town is complete. The guide speaks up when something needs you.",
- goal: "every goal is met",
++ action: "Meet every goal in the [town] panel to raise the town's rank.",
++ why: "Hold them for two minutes and the town rises, up to a city. The town rank opens upgrades for the market and the chapel. The guide speaks up when something needs you.",
++ goal: "the town is a city",
+ focus: null,
+ when: () => true,
- done: (f) => f.goalsMet
++ done: (f) => f.rank >= 3
+ },
+
+ // ── Around the course, when the town needs them ──
+ {
+ id: "crown",
+ chapter: "Governing",
+ action: "Send the crown what it asks for, with the send button on its request at the top.",
+ why: "It pays coins. An unanswered request is a fine, and three missed in a row end your term.",
+ goal: "the goods are sent",
+ focus: null,
+ when: (f) => f.crown.open,
+ urgent: () => true,
+ done: (f) => f.crown.met > 0
+ },
+ {
+ id: "winter",
+ chapter: "Keeping it standing",
+ action: "Build a granary or a smokehouse before winter comes.",
+ why: "In winter fishing slows, homes eat more, and fish rots in store. A granary keeps it five times as long, and smoked fish keeps all winter.",
+ goal: "a granary or a smokehouse stands",
+ asks: ["granary", "smokehouse"],
focus: "hall",
- opening: true,
- when: (f) => has(f, "quarry") && f.sawHome && f.sawTown,
- done: (f) => f.builtHomes >= 10
+ when: (f) => f.residents >= 20 && (f.winter || (f.winterIn !== null && f.winterIn <= 120)),
+ urgent: () => true,
+ done: (f) => has(f, "granary") || has(f, "smokehouse"),
+ waiting: rising("granary", "smokehouse")
+ },
+ {
+ id: "tools",
+ chapter: "Growing citizens",
+ action: "In the [town] panel, under goods and trade, set tools to buy.",
+ why: "Workshops use up tools, and only a smithy makes new ones, which opens at 10 citizens.",
+ goal: "the town buys tools, or a smithy stands",
+ focus: null,
+ when: (f) => f.residents >= 15 && f.citizens < 10 && f.stock.tools <= 3 && !has(f, "smithy"),
+ done: (f) => f.buysTools || has(f, "smithy")
+ },
+ {
+ id: "forester",
+ chapter: "Founding",
+ action: "Build a forester next to the lumberjack.",
+ why: "The lumberjack is running out of trees, and a forester plants new ones for it.",
+ goal: "a forester stands",
+ asks: ["forester"],
+ focus: { kind: "lumberjack" },
+ when: (f) => f.fewTrees,
+ done: (f) => has(f, "forester"),
+ waiting: rising("forester")
},
{
id: "firewatch",
@@@ -432,23 -224,18 +434,33 @@@
},
{
id: "market",
- goal: "a market stands",
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.",
+ action: "Build a market among the homes furthest from the town hall.",
+ why: "Some homes are beyond the town hall's walker, which only reaches 20 road cells, and get no food. A market's walker carries it further.",
+ goal: "a market stands",
+ asks: ["market"],
focus: "hall",
- when: (f) => f.residents >= 40 && f.standing.has("fishery"),
- done: (f) => has(f, "market")
+ when: (f) => f.unreached >= 2,
+ done: (f) => has(f, "market"),
+ waiting: rising("market")
+ },
++ {
++ id: "markethall",
++ chapter: "Keeping it standing",
++ action: "Select a market and upgrade it to a market hall, from its panel.",
++ why: "Some homes are beyond every food walker. A market hall's walker goes further and more often, without a second market's upkeep.",
++ goal: "a market hall stands",
++ focus: { kind: "market" },
++ when: (f) => f.rank >= 2 && has(f, "market") && f.unreached >= 2,
++ done: (f) => f.upgraded.has("market")
+ },
{
id: "street",
- goal: "a home on a fine street holds citizens",
chapter: "Growing citizens",
- text: "A home here has bread, cloth, and faith, but its street is too poor for citizens: it needs desirability 5. Press D to see it; keep workshops away, and add a chapel, a market, or a park.",
+ action: "Raise this home's street to desirability 5: add a chapel, a market, or a park nearby, and keep workshops away.",
+ why: "It has bread, cloth, and faith, but citizens only live on a decent street. [view:appeal] shows desirability.",
+ goal: "a home on a fine street holds citizens",
+ asks: ["chapel", "market"],
focus: "poorStreet",
when: (f) => f.poorStreet,
done: (f) => f.finerHomes > 0
diff --cc src/ui.ts
index c555a0a,cacdc69..c6a69ed
--- a/src/ui.ts
+++ b/src/ui.ts
@@@ -138,7 -128,10 +140,10 @@@ export type Panel
readonly paused: boolean
/** What pulling it down costs and gives back: "pull down: −25 coins · 2 planks back". */
readonly salvage: string
- readonly lines: ReadonlyArray<Line>
+ readonly groups: ReadonlyArray<Group>
+ /** Whether it is upgraded; and the upgrade it could have, what it costs, and what keeps it from it now (`null`: nothing). */
+ readonly upgraded: boolean
+ readonly upgrade: { readonly title: string; readonly cost: string; readonly blocked: string | null } | null
}
| {
readonly type: "house"
diff --cc test/guide.test.ts
index fbbe89d,0040a98..9756f33
--- a/test/guide.test.ts
+++ b/test/guide.test.ts
@@@ -36,11 -34,6 +36,12 @@@ const fresh: GuideFacts =
most: 40,
sawTown: false,
sawHome: false,
+ sawBuilding: false,
+ roadToWater: false,
- goalsMet: false,
++ rank: 0,
++ upgraded: new Set(),
+ coins: 1900,
+ unreached: 0,
risk: { fire: false, health: false, order: false },
fewTrees: false
}
@@@ -52,83 -45,57 +53,87 @@@ const town = (over: Partial<GuideFacts>
...over
})
const none = new Set<string>()
+/** What the guide says next for a town, with what it has done put away. */
+const next = (facts: GuideFacts, pace: { readonly shown?: string | null; readonly quiet?: boolean } = { quiet: true }, skipped: ReadonlyArray<string> = []) =>
+ guideStep(facts, new Set([...guideDone(facts, none), ...skipped]), pace)?.id
+const founding = courseSteps.filter((s) => s.chapter === "Founding")
+/** A town through the Founding chapter. */
+const founded = (over: Partial<GuideFacts> = {}, built: ReadonlyArray<KindId> = []) =>
+ town({ homes: 10, residents: 30, roadToWater: true, sawBuilding: true, sawTown: true, ...over }, ["fishery", "lumberjack", "sawmill", ...built])
-test("a new town is told to lay homes, then to feed them", () => {
+const low = amounts({ planks: PLANKS_LOW - 5, stone: 16, tools: 10, fish: 20 })
+
+test("a new town is founded in order: homes, a road to the water, a fishery, its panel, planks (once low), the goal, ten homes", () => {
+ assert.deepEqual(
+ founding.map((s) => s.id),
+ ["homes", "road", "fishery", "look", "lumberjack", "sawmill", "term", "grow"]
+ )
assert.equal(guideStep(fresh, none)?.id, "homes")
- assert.equal(guideStep(town({ homes: 6, residents: 12 }), new Set(["homes"]))?.id, "fishery")
- assert.equal(guideStep(town({ homes: 6, residents: 12 }, ["fishery"]), new Set(["homes", "fishery"]))?.id, "planks")
-})
-
-test("what the town has done is put away, shown or not", () => {
- const experienced = town({ homes: 20, residents: 60, citizens: 0 }, ["fishery", "lumberjack", "sawmill", "forester", "quarry", "firewatch"])
- const put = guideDone(experienced, none)
- for (const id of ["homes", "fishery", "planks", "forester", "quarry", "firewatch"]) assert.ok(put.includes(id), id)
- const next = guideStep(experienced, new Set(put))
- assert.ok(next && !put.includes(next.id), "the next step is one not yet done")
-})
-
-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"]) }
- assert.equal(guideStep(building, put)?.id, "fishery", "a laid fishery is not done until it stands")
- 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")
- // 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")
- // And last, the go-ahead to grow, until ten homes stand.
- const told = { ...looked, sawTown: true }
- assert.equal(guideStep(told, new Set(guideDone(told, none)), { quiet: true })?.id, "grow")
- const grown = { ...told, homes: 10, builtHomes: 10 }
- assert.ok(guideDone(grown, none).includes("grow"))
-})
-
-test("citizens' needs come bread first, a building or two at a time, and not before bread can be made", () => {
- const ready = town({ homes: 12, 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, "wheat")
- // One or two buildings at a time: wheat and flour, then the bakery, then cloth, then the chapel.
- const chain: ReadonlyArray<[ReadonlyArray<KindId>, string]> = [[["farm", "mill"], "bakery"], [["farm", "mill", "bakery"], "cloth"], [["farm", "mill", "bakery", "sheep", "weaver"], "chapel"]]
- for (const [more, next] of chain) {
- const facts = town({ homes: 12, residents: 34, sawHome: true, sawTown: true }, ["fishery", "lumberjack", "sawmill", "quarry", ...more])
- assert.equal(guideStep(facts, new Set(guideDone(facts, none)))?.id, next)
+ assert.equal(next(town({ homes: 4, residents: 8 })), "road", "no quiet in the opening")
+ assert.equal(next(town({ homes: 4, residents: 8, roadToWater: true })), "fishery")
+ assert.equal(next(town({ homes: 4, residents: 8, roadToWater: true }, ["fishery"])), "look")
+ assert.equal(next(town({ homes: 4, residents: 8, roadToWater: true, sawBuilding: true, stock: low }, ["fishery"])), "lumberjack")
+ assert.equal(next(town({ homes: 4, residents: 8, roadToWater: true, sawBuilding: true }, ["fishery", "lumberjack"])), "sawmill", "a lumberjack wants its sawmill")
+ assert.equal(next(town({ homes: 4, residents: 8, roadToWater: true, sawBuilding: true }, ["fishery", "lumberjack", "sawmill"])), "term")
+ assert.equal(next(town({ homes: 4, residents: 8, roadToWater: true, sawBuilding: true, sawTown: true }, ["fishery", "lumberjack", "sawmill"])), "grow")
+ assert.ok(guideDone(founded(), none).includes("grow"))
+ assert.deepEqual(courseCount(founding[2]!), { at: 3, of: 8 })
+})
+
+test("after ten homes the course goes on to citizens, never falling silent, a building the town can build first", () => {
+ // Ten homes stand, and quiet or not, the guide has the next step. Stone in store: no quarry yet.
+ assert.equal(next(founded()), "cloth")
+ assert.equal(next(founded({ stock: amounts({ planks: 30, stone: STONE_LOW - 2 }) })), "quarry", "a quarry once stone runs low")
+ // Cloth and faith open at 15 residents, bread at 30: with 20, cloth comes first.
+ const twenty = founded({ residents: 20 }, ["quarry"])
+ assert.equal(next(twenty), "cloth")
+ assert.equal(next(founded({ residents: 20 }, ["quarry", "sheep", "weaver"])), "chapel")
+ // Bread cannot be made yet: the step says what opens it.
+ const short = founded({ residents: 20 }, ["quarry", "sheep", "weaver", "chapel"])
+ assert.equal(next(short), "wheat")
+ assert.match(lockedNote(guideSteps.find((s) => s.id === "wheat")!, short)!, /opens at 30 residents \(20 now\)/)
+ assert.equal(next(founded({ residents: 30 }, ["quarry", "sheep", "weaver", "chapel", "farm", "mill"])), "bakery")
+ const supplied = founded({ residents: 40 }, ["quarry", "sheep", "weaver", "chapel", "farm", "mill", "bakery"])
+ assert.equal(next(supplied), "citizens")
+ assert.equal(next({ ...supplied, finerHomes: 1, sawTown: false }, { quiet: true }, founding.map((s) => s.id)), "goals")
- // The last word: every goal, until they are met.
- assert.equal(next({ ...supplied, finerHomes: 1 }), "complete")
- assert.equal(next({ ...supplied, finerHomes: 1, goalsMet: true }), undefined)
++ // The last word: the ranks, up to a city.
++ assert.equal(next({ ...supplied, finerHomes: 1 }), "ranks")
++ assert.equal(next({ ...supplied, finerHomes: 1, rank: 2 }), "ranks")
++ assert.equal(next({ ...supplied, finerHomes: 1, rank: 3 }), undefined)
+})
+
+test("the course never asks for a building before the town needs it, and says what comes next", () => {
+ // Plenty of planks: past the lumberjack and sawmill to the goal, saying when they come.
+ const plenty = town({ homes: 4, residents: 8, roadToWater: true, sawBuilding: true, stock: amounts({ planks: 31, stone: 16 }) }, ["fishery"])
+ assert.equal(next(plenty), "term")
+ assert.equal(upcoming(plenty, new Set(guideDone(plenty, none))), `Next: a lumberjack and a sawmill, once planks fall below ${PLANKS_LOW} (31 now).`)
+ // A laid lumberjack stays asked for while it goes up, whatever the planks.
+ const laying = { ...plenty, placed: new Set<KindId>(["fishery", "lumberjack"]) }
+ assert.equal(next(laying), "lumberjack")
+ // The quarry waits for stone; the market for homes beyond the walkers; the smithy for tools.
+ assert.equal(upcoming(founded(), new Set(guideDone(founded(), none))), `Next: a quarry, once stone falls below ${STONE_LOW} (16 now).`)
+ assert.notEqual(next(founded({ residents: 60 }), {}), "market")
+ assert.equal(next(founded({ unreached: 3 }), {}), "market")
++ // A town rank town with a market: upgrade it rather than build another.
++ assert.equal(next(founded({ unreached: 3, rank: 2 }, ["market"]), {}), "markethall")
++ assert.notEqual(next(founded({ unreached: 3, rank: 1 }, ["market"]), {}), "markethall", "not before the town rank")
+ assert.notEqual(next(founded({ citizens: 12, residents: 80 }, ["quarry", "sheep", "weaver", "chapel", "farm", "mill", "bakery"]), {}), "smithy")
+ assert.equal(next(founded({ citizens: 12, residents: 80, stock: amounts({ tools: 3, planks: 40, stone: 20 }) }, ["quarry", "sheep", "weaver", "chapel", "farm", "mill", "bakery"]), {}), "smithy")
+})
+
+test("a step the treasury cannot pay for says to save up, and gives way to one it can", () => {
+ const poor = founded({ residents: 20, coins: 120 }, [])
+ const chapel = guideSteps.find((s) => s.id === "chapel")!
+ assert.match(lockedNote(chapel, poor)!, /Save up: the chapel costs 200 coins \(120 now\)/)
+ // The sheep farm (100) can be paid for, the weaver (150) not yet: the cloth step asks, the cheaper first.
+ assert.equal(lockedNote(guideSteps.find((s) => s.id === "cloth")!, poor), null)
+})
+
+test("every course step is one thing to do and one reason, short enough for a phone", () => {
+ for (const step of courseSteps) {
+ assert.ok(step.action.length <= 110, `${step.id}: the action fits a phone's peek`)
+ assert.equal(step.action.match(/[.!?](\s|$)/g)?.length, 1, `${step.id}: the action is one sentence`)
+ assert.ok(step.why.length <= 180, `${step.id}: the reason is short`)
}
})
@@@ -241,8 -191,8 +246,8 @@@ test("every step can be done, and a tow
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, sawHome: true,
- winter: true, worn: true, poorStreet: true, approval: 40, net: -5, most: 120, stock: amounts({ tools: 0 })
+ homes: 200, residents: 400, citizens: 200, finerHomes: 30, crown: { open: true, met: 3 }, trading: true, taxed: true, sawTown: true, sawHome: true, sawBuilding: true,
- roadToWater: true, goalsMet: true, unreached: 5, winter: true, worn: true, poorStreet: true, approval: 40, net: -5, most: 120, stock: amounts({ tools: 0 })
++ roadToWater: true, rank: 3, upgraded: new Set<KindId>(["market"]), unreached: 5, 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"]
)