Skip to content

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

Split game content into one module per closed set

SandroMaglione35b7fb69391a
diff --git a/src/game/content/clock.ts b/src/game/content/clock.ts
new file mode 100644
index 0000000..042b41f
--- /dev/null
+++ b/src/game/content/clock.ts
@@ -0,0 +1,32 @@
+/**
+ * The simulation's clock: its fixed step, and seconds or steps read from
+ * data turned into whole steps and cadences.
+ */
+import { Clock } from "@typeonce/ritmo"
+
+/** The simulation's fixed step: 60 a second, shared by the page's loop, the replay recorder, and the `Time` clock. */
+export const step = Clock.hz(60)
+
+/**
+ * Seconds read from data (a kind's, a rule's) as whole steps. A span
+ * shorter than one step, which `Clock.durationRaw` refuses, is no wait at
+ * all: 0 steps (`resolveRules` refuses a kind's `seconds` that short, so a
+ * period is always at least one step).
+ */
+export const stepsOf = (seconds: number): number => {
+ const span = Clock.durationRaw(step, seconds)
+ return span.ok ? Clock.steps(span.value) : 0
+}
+
+/**
+ * A period the rules give in whole steps (patchable, so data) as a clock
+ * duration for `Clock.every`; refused when under one step (a period of 0
+ * never comes round, as `tick % 0` never did).
+ */
+export const periodOf = (steps: number) => Clock.durationRaw(step, steps / step.hz)
+
+/** A cadence supplied as whole steps by the game's rules; invalid periods never fire. */
+export const every = (time: Clock.Time<60>, steps: number): boolean => {
+ const period = periodOf(steps)
+ return period.ok && Clock.every(time, period.value)
+}
diff --git a/src/game/content/goods.ts b/src/game/content/goods.ts
new file mode 100644
index 0000000..e39678c
--- /dev/null
+++ b/src/game/content/goods.ts
@@ -0,0 +1,59 @@
+/** Goods: what they are, what they fetch, how they are counted, and how food spoils. */
+import { Clock } from "@typeonce/ritmo"
+import { step } from "./clock.ts"
+
+export const goodIds = ["wood", "planks", "stone", "ore", "tools", "fish", "smoked", "wheat", "flour", "bread", "wool", "cloth", "furniture"] as const
+export type GoodId = (typeof goodIds)[number]
+
+/** Each good's crate label colour (the only colour a good has), and what traders pay for one. */
+export const goods: Readonly<Record<GoodId, { readonly title: string; readonly color: number; readonly price: number }>> = {
+ wood: { title: "wood", color: 0x8a6a45, price: 1 },
+ planks: { title: "planks", color: 0xd27a34, price: 3 },
+ stone: { title: "stone", color: 0x8f9891, price: 2 },
+ ore: { title: "ore", color: 0x5a6479, price: 3 },
+ tools: { title: "tools", color: 0x3d4943, price: 10 },
+ fish: { title: "fish", color: 0x2f8c87, price: 2 },
+ smoked: { title: "smoked fish", color: 0x9a5b3a, price: 4 },
+ wheat: { title: "wheat", color: 0xd6ae2e, price: 1 },
+ flour: { title: "flour", color: 0xc9b48a, price: 3 },
+ bread: { title: "bread", color: 0xc4523f, price: 4 },
+ wool: { title: "wool", color: 0xa7ada4, price: 2 },
+ cloth: { title: "cloth", color: 0x8a58a8, price: 6 },
+ furniture: { title: "furniture", color: 0x9a6b3f, price: 9 }
+}
+
+/**
+ * Trade: at every collection, traders buy what the town sells beyond the
+ * reserve it keeps, up to `TRADE_LOAD` of each good.
+ */
+export const TRADE_LOAD = 12
+/** The most the town can choose to keep of each good before selling it. */
+export const RESERVE_MAX = 200
+/** A new town neither sells nor buys: what leaves the town, and what it pays for, is the mayor's to decide. */
+export const trade = { sells: [] as ReadonlyArray<GoodId>, reserve: 25 }
+
+export type Amounts = Readonly<Record<GoodId, number>>
+export const none: Amounts = { wood: 0, planks: 0, stone: 0, ore: 0, tools: 0, fish: 0, smoked: 0, wheat: 0, flour: 0, bread: 0, wool: 0, cloth: 0, furniture: 0 }
+export const amounts = (some: Partial<Record<GoodId, number>>): Amounts => ({ ...none, ...some })
+export const total = (a: Amounts): number => goodIds.reduce((sum, g) => sum + a[g], 0)
+/** Amounts made good by good. */
+export const each = (f: (good: GoodId) => number): Amounts => {
+ const out: Record<GoodId, number> = { ...none }
+ for (const g of goodIds) out[g] = f(g)
+ return out
+}
+
+/** Goods a market walker hands out to homes. */
+export const provisions: ReadonlyArray<GoodId> = ["fish", "smoked", "bread", "cloth", "furniture"]
+/** Goods the top bar shows, in order. */
+export const shownGoods: ReadonlyArray<GoodId> = ["wood", "planks", "stone", "tools", "fish", "smoked", "bread", "cloth", "furniture"]
+/** Goods that are food in store (see `larder`). */
+export const foods: ReadonlyArray<GoodId> = ["fish", "smoked", "bread"]
+
+/**
+ * Food spoils in store: about how many seconds a fish or a loaf keeps. A
+ * granary keeps it `KEEPS` times as long; smoked fish, wheat, and flour keep.
+ * Every `SPOIL_TICKS`, each shelf loses its share of what it holds.
+ */
+export const spoils: Partial<Record<GoodId, number>> = { fish: 180, bread: 300 }
+export const SPOIL_TICKS = Clock.steps(Clock.duration(step, 10))
diff --git a/src/game/content/homes.ts b/src/game/content/homes.ts
new file mode 100644
index 0000000..a74d5d1
--- /dev/null
+++ b/src/game/content/homes.ts
@@ -0,0 +1,90 @@
+/** Homes: their tiers, what their residents need, what a street does to them, and the crews they work in. */
+import { Clock } from "@typeonce/ritmo"
+import { step } from "./clock.ts"
+import type { Crew, Kind } from "./kinds/index.ts"
+
+export type Tier = 1 | 2 | 3
+export const tierIds: ReadonlyArray<Tier> = [1, 2, 3]
+/** What a home can be short of. Settlers need food (fish, smoked fish, or bread); citizens bread, cloth, and faith; burghers furniture besides. */
+export type Need = "food" | "bread" | "cloth" | "faith" | "furniture"
+
+/** A tier of homes (see `home.tiers`). */
+interface HomeTier {
+ readonly title: string
+ readonly residents: number
+ readonly tax: number
+ readonly height: number
+ readonly needs: ReadonlyArray<Need>
+ /** The desirability a home of this tier needs around it (see `appeal.ts`). */
+ readonly appeal: number
+ /**
+ * What rebuilding a home into this tier costs, paid at once from the
+ * treasury and the store when it is ready to rise, as paving is: a home
+ * that cannot be paid for waits at its tier. A home that steps down
+ * keeps its rebuilding, and rises back into it for nothing.
+ */
+ readonly rise: Kind["cost"]
+}
+
+export const home = {
+ /** Half the house's width, in units: a 1×1 cell is 8 units from centre to edge. */
+ half: 5,
+ cost: { coins: 15, materials: { planks: 1 } } as Kind["cost"],
+ tiers: {
+ 1: { title: "settlers", residents: 4, tax: 2.5, height: 24, needs: ["food"], appeal: -100, rise: { coins: 0, materials: {} } },
+ 2: { title: "citizens", residents: 8, tax: 5, height: 46, needs: ["bread", "cloth", "faith"], appeal: 5, rise: { coins: 35, materials: { planks: 4, stone: 2 } } },
+ 3: { title: "burghers", residents: 12, tax: 7, height: 68, needs: ["bread", "cloth", "faith", "furniture"], appeal: 12, rise: { coins: 45, materials: { planks: 4, stone: 4, tools: 1, furniture: 2 } } }
+ } satisfies Record<Tier, HomeTier> as Readonly<Record<Tier, HomeTier>>,
+ /** A resident moves in (or out) this often. */
+ settle: Clock.steps(Clock.duration(step, 3)),
+ /** How long each need stays met after a walker's visit: cloth and faith last longer than a meal. */
+ lasts: { food: Clock.steps(Clock.duration(step, 90)), bread: Clock.steps(Clock.duration(step, 120)), cloth: Clock.steps(Clock.duration(step, 240)), faith: Clock.steps(Clock.duration(step, 180)), furniture: Clock.steps(Clock.duration(step, 300)) } satisfies Record<Need, number> as Readonly<Record<Need, number>>,
+ /** Where nobody wants to live: the desirability the map's legend calls squalid. */
+ squalid: -5,
+ /**
+ * What a street does to a home, point by point of desirability (see
+ * `streetRoom` and `streetTax`): a home holds (1 + d / `room`) of its
+ * residents, never fewer than `roomLeast`; and pays (1 + d / `tax`),
+ * within `taxMost` either way. So a cottage beside a quarry empties a
+ * little and pays less, long before anything is squalid.
+ */
+ street: { room: 12, roomLeast: 0.5, tax: 40, taxMost: 0.25 },
+ /** A settlers' cottage with bread on the table pays this much more: bread is worth baking before anyone is a citizen. */
+ breadBonus: 0.5,
+ /**
+ * The need a finer home cannot be without: a citizens' home or a
+ * townhouse out of bread goes back to settlers, however much fish it
+ * eats (cloth or faith alone may lapse a while).
+ */
+ staple: "bread" as Need,
+ /**
+ * A walker's visit feeds a home one fish or loaf for every `perMeal`
+ * residents (rounded up): a cottage one, a citizens' home two, a
+ * townhouse three. Food demand grows with the people, not the roofs.
+ */
+ perMeal: 4,
+ /**
+ * Taxes above 100% drive people away directly, besides what they do to
+ * approval: at x = (rate − 100) / 100, a home holds 1 − `linear`·x −
+ * `square`·x² of its residents (settlers: 80% at 150%, half at 200%);
+ * citizens and burghers mind `citizens` as much. So squeezing harder
+ * empties the homes it squeezes, and the most a rate can bring in
+ * comes well before the top of the slider.
+ */
+ taxFlight: { linear: 0.3, square: 0.2, citizens: 0.6 }
+}
+
+/** What a tier's homes are called, and what its residents are. */
+export const tierHome: Readonly<Record<Tier, string>> = { 1: "settlers' cottage", 2: "citizens' home", 3: "townhouse" }
+
+/** Which crew a tier's residents work in. */
+export const crewOf = (tier: Tier): Crew => (tier === 1 ? "settlers" : "citizens")
+
+/** Road cells a resident walks to work, at most (see `AssignStaff`). */
+export const COMMUTE = 15
+/** An apprentice (a settler in a citizens' job) works at this share of the pace. */
+export const APPRENTICE = 0.75
+/** Tools a workshop that wears them keeps on hand. */
+export const TOOL_STOCK = 1
+
+export const needTitle: Readonly<Record<Need, string>> = { food: "food", bread: "bread", cloth: "cloth", faith: "faith", furniture: "furniture" }
diff --git a/src/game/content/index.ts b/src/game/content/index.ts
index 0d1128c..53deb14 100644
--- a/src/game/content/index.ts
+++ b/src/game/content/index.ts
@@ -5,992 +5,27 @@
* simulation steps by `Clock.duration` (literals) and `stepsOf` (data).
* `archetypes.ts` turns each entry into the components an entity is spawned
* with; nothing here knows about the ECS beyond its clock's step.
- */
-import { Clock } from "@typeonce/ritmo"
-
-/** The simulation's fixed step: 60 a second, shared by the page's loop, the replay recorder, and the `Time` clock. */
-export const step = Clock.hz(60)
-
-/**
- * Seconds read from data (a kind's, a rule's) as whole steps. A span
- * shorter than one step, which `Clock.durationRaw` refuses, is no wait at
- * all: 0 steps (`resolveRules` refuses a kind's `seconds` that short, so a
- * period is always at least one step).
- */
-export const stepsOf = (seconds: number): number => {
- const span = Clock.durationRaw(step, seconds)
- return span.ok ? Clock.steps(span.value) : 0
-}
-
-/**
- * A period the rules give in whole steps (patchable, so data) as a clock
- * duration for `Clock.every`; refused when under one step (a period of 0
- * never comes round, as `tick % 0` never did).
- */
-export const periodOf = (steps: number) => Clock.durationRaw(step, steps / step.hz)
-
-/** A cadence supplied as whole steps by the game's rules; invalid periods never fire. */
-export const every = (time: Clock.Time<60>, steps: number): boolean => {
- const period = periodOf(steps)
- return period.ok && Clock.every(time, period.value)
-}
-
-// ── Goods ─────────────────────────────────────────────────────────────────
-
-export const goodIds = ["wood", "planks", "stone", "ore", "tools", "fish", "smoked", "wheat", "flour", "bread", "wool", "cloth", "furniture"] as const
-export type GoodId = (typeof goodIds)[number]
-
-/** Each good's crate label colour (the only colour a good has), and what traders pay for one. */
-export const goods: Readonly<Record<GoodId, { readonly title: string; readonly color: number; readonly price: number }>> = {
- wood: { title: "wood", color: 0x8a6a45, price: 1 },
- planks: { title: "planks", color: 0xd27a34, price: 3 },
- stone: { title: "stone", color: 0x8f9891, price: 2 },
- ore: { title: "ore", color: 0x5a6479, price: 3 },
- tools: { title: "tools", color: 0x3d4943, price: 10 },
- fish: { title: "fish", color: 0x2f8c87, price: 2 },
- smoked: { title: "smoked fish", color: 0x9a5b3a, price: 4 },
- wheat: { title: "wheat", color: 0xd6ae2e, price: 1 },
- flour: { title: "flour", color: 0xc9b48a, price: 3 },
- bread: { title: "bread", color: 0xc4523f, price: 4 },
- wool: { title: "wool", color: 0xa7ada4, price: 2 },
- cloth: { title: "cloth", color: 0x8a58a8, price: 6 },
- furniture: { title: "furniture", color: 0x9a6b3f, price: 9 }
-}
-
-/**
- * Trade: at every collection, traders buy what the town sells beyond the
- * reserve it keeps, up to `TRADE_LOAD` of each good.
- */
-export const TRADE_LOAD = 12
-/** The most the town can choose to keep of each good before selling it. */
-export const RESERVE_MAX = 200
-/** A new town neither sells nor buys: what leaves the town, and what it pays for, is the mayor's to decide. */
-export const trade = { sells: [] as ReadonlyArray<GoodId>, reserve: 25 }
-
-export type Amounts = Readonly<Record<GoodId, number>>
-export const none: Amounts = { wood: 0, planks: 0, stone: 0, ore: 0, tools: 0, fish: 0, smoked: 0, wheat: 0, flour: 0, bread: 0, wool: 0, cloth: 0, furniture: 0 }
-export const amounts = (some: Partial<Record<GoodId, number>>): Amounts => ({ ...none, ...some })
-export const total = (a: Amounts): number => goodIds.reduce((sum, g) => sum + a[g], 0)
-/** Amounts made good by good. */
-export const each = (f: (good: GoodId) => number): Amounts => {
- const out: Record<GoodId, number> = { ...none }
- for (const g of goodIds) out[g] = f(g)
- return out
-}
-
-/** Goods a market walker hands out to homes. */
-export const provisions: ReadonlyArray<GoodId> = ["fish", "smoked", "bread", "cloth", "furniture"]
-/** Goods the top bar shows, in order. */
-export const shownGoods: ReadonlyArray<GoodId> = ["wood", "planks", "stone", "tools", "fish", "smoked", "bread", "cloth", "furniture"]
-/** Goods that are food in store (see `larder`). */
-export const foods: ReadonlyArray<GoodId> = ["fish", "smoked", "bread"]
-
-/**
- * Food spoils in store: about how many seconds a fish or a loaf keeps. A
- * granary keeps it `KEEPS` times as long; smoked fish, wheat, and flour keep.
- * Every `SPOIL_TICKS`, each shelf loses its share of what it holds.
- */
-export const spoils: Partial<Record<GoodId, number>> = { fish: 180, bread: 300 }
-export const SPOIL_TICKS = Clock.steps(Clock.duration(step, 10))
-
-// ── Buildings ─────────────────────────────────────────────────────────────
-
-export type Category = "storage" | "gathering" | "crafts" | "food" | "services"
-export const categoryOrder: ReadonlyArray<Category> = ["storage", "gathering", "crafts", "food", "services"]
-
-/** Awnings are coloured by what a building is for. */
-export const categoryColor: Readonly<Record<Category, number>> = {
- storage: 0x8a58a8,
- gathering: 0x6e8f36,
- crafts: 0xd27a34,
- food: 0xd6ae2e,
- services: 0x3d6db5
-}
-export const homeColor = 0xc4523f
-
-/** What a gatherer takes from the land around it. */
-export type Source = "tree" | "stone" | "ore" | "field" | "water"
-export const serviceIds = ["goods", "faith", "fire", "health", "order", "repair"] as const
-export type ServiceId = (typeof serviceIds)[number]
-/** Native crews: surplus citizens can also do rough work; settlers learn skilled jobs as apprentices. */
-export type Crew = "settlers" | "citizens"
-
-export type Topper = "none" | "chimney" | "flag" | "cupola" | "sails" | "crates"
-
-export const kindIds = [
- "townhall", "warehouse", "lumberjack", "forester", "quarry", "mine", "fishery", "sawmill",
- "smithy", "farm", "mill", "bakery", "sheep", "weaver", "market", "chapel",
- "granary", "smokehouse", "firewatch", "healer", "hospital", "watchhouse", "builder", "carpenter"
-] as const
-export type KindId = (typeof kindIds)[number]
-
-export interface Kind {
- readonly id: KindId
- readonly title: string
- readonly blurb: string
- readonly category: Category
- /** Cells a side. */
- readonly size: 1 | 2 | 3
- // ── Look (see `art.ts`) ──
- /** Half the building's width, in units: its walls stand this far from its centre. */
- readonly half: number
- readonly stories: 1 | 2
- readonly roof: "flat" | "gable"
- /** A flat roof is split into bays × bays squares, each `window` units across but the topper's. */
- readonly bays: 2 | 3
- readonly window: number
- readonly topper: Topper
- // ── Economy ──
- readonly cost: { readonly coins: number; readonly materials: Partial<Record<GoodId, number>> }
- /** Coins a minute while it stands. */
- readonly upkeep: number
- readonly workers: number
- /** Who works it: settlers, or citizens (settlers stand in as apprentices, at a slower pace). */
- readonly crew: Crew
- /** Residents (and of them citizens) the town needs before it can be built. */
- readonly unlock: { readonly residents: number; readonly citizens: number }
- /** In the build menu (the town hall is not). */
- readonly buildable: boolean
- // ── Roles: each one present becomes a component ──
- /** Turns `inputs` of `input` (or nothing, or the land) into `batch` of `output` per job. */
- readonly recipe?: { readonly input: GoodId | null; readonly inputs: number; readonly output: GoodId; readonly batch: number; readonly seconds: number }
- /** A gatherer's job needs this within `radius` cells of its footprint. */
- readonly gathers?: { readonly source: Source; readonly radius: number }
- /** Plants trees or fields within `radius`, one every `seconds`, up to `max` at once. */
- readonly plants?: { readonly what: "tree" | "field"; readonly radius: number; readonly seconds: number; readonly max: number }
- /** Holds goods: every good (storage), or just some (a market). */
- readonly holds?: { readonly accepts: ReadonlyArray<GoodId> | "all"; readonly cap: number }
- /** Carriers it sends out at once. */
- readonly carriers?: number
- /** Sends a walker down the roads every `seconds`, `range` cells out. */
- readonly service?: { readonly service: ServiceId; readonly seconds: number; readonly range: number }
- // ── Its neighbourhood ──
- /** What it does to the desirability of the cells around it, fading out to `reach` cells (see `appeal.ts`). */
- readonly appeal?: { readonly value: number; readonly reach: number; readonly full?: number }
- /** Uses up a tool every `wear` jobs, and works at half pace without one. */
- readonly wear?: number
- /** Ovens and forges: a fire risk to itself and to homes beside it. */
- readonly hot?: boolean
- /** Dust: a health risk to homes nearby. */
- readonly dusty?: boolean
- /** A storage that keeps food this many times longer. */
- readonly keeps?: number
- /**
- * What it becomes when upgraded where it stands, once the town has reached
- * `rank` (see `ranks`), and (`next`) what that becomes in turn: its coins
- * paid when the works begin, its materials carried to it while it goes on
- * working (see `Works`). Whatever an upgrade gives replaces the kind's own.
- */
- readonly upgrade?: Upgrade
-}
-
-/** A building upgraded where it stands (see `Kind.upgrade`): every field but the first five is what changes. */
-export interface Upgrade {
- readonly title: string
- readonly blurb: string
- readonly rank: number
- readonly cost: { readonly coins: number; readonly materials: Partial<Record<GoodId, number>> }
- readonly upkeep: number
- readonly service?: { readonly seconds: number; readonly range: number }
- readonly appeal?: { readonly value: number; readonly reach: number; readonly full?: number }
- /** Workers it takes, and seconds a job (a recipe's). */
- readonly workers?: number
- readonly seconds?: number
- /** What its shelves hold of each good, and the carriers it sends at once. */
- readonly cap?: number
- readonly carriers?: number
- /** Firefighters it sends out at once (a fire watch's). */
- readonly crews?: number
- /** It cuts worked faces at full pace, not a third of it (a quarry's). */
- readonly deep?: boolean
- /** The share of the town hall's administration it saves (the town hall's). */
- readonly admin?: number
- /** The upgrade after this one. */
- readonly next?: Upgrade
-}
-
-/** Upgrades a building has had: none, one, or (a town hall) two. */
-export type Level = 0 | 1 | 2
-
-/** The upgrade a building at `level` stands as (`undefined`: none), and the one it could have next. */
-export const upgradeAt = (kind: Pick<Kind, "upgrade">, level: number): Upgrade | undefined =>
- level <= 0 ? undefined : level === 1 ? kind.upgrade : kind.upgrade?.next
-export const nextUpgrade = (kind: Pick<Kind, "upgrade">, level: number): Upgrade | undefined => upgradeAt(kind, level + 1)
-
-/**
- * A kind as a building of it stands once upgraded to `level`: its upkeep,
- * crew, pace, shelves, carriers, walker, and desirability those of its
- * upgrades. Everything that works a building reads it from here.
- */
-export const asUpgraded = <K extends Kind>(kind: K, level: number): K => {
- let k: Kind = kind
- for (let l = 1; l <= level; l++) {
- const up = upgradeAt(kind, l)
- if (!up) break
- k = {
- ...k,
- upkeep: up.upkeep,
- workers: up.workers ?? k.workers,
- ...(k.recipe && up.seconds ? { recipe: { ...k.recipe, seconds: up.seconds } } : {}),
- ...(k.holds && up.cap ? { holds: { ...k.holds, cap: up.cap } } : {}),
- ...(up.carriers ? { carriers: up.carriers } : {}),
- ...(k.service && up.service ? { service: { ...k.service, ...up.service } } : {}),
- ...(up.appeal ? { appeal: up.appeal } : {})
- }
- }
- return k as K
-}
-
-/** Steps of building work an upgrade takes for each good it is made of: a market hall half a minute, a city hall four. */
-export const WORKS_TICKS = Clock.steps(Clock.duration(step, 1.5))
-/** The steps of work an upgrade of `total` goods takes. */
-export const worksNeeded = (total: number, rules: { readonly worksTicks: number } = { worksTicks: WORKS_TICKS }) => Math.max(1, total) * rules.worksTicks
-
-/** Coins a minute a building of a kind costs at its level of upgrades. */
-export const upkeepOf = (kind: Pick<Kind, "upkeep" | "upgrade">, level: number): number => upgradeAt(kind, level)?.upkeep ?? kind.upkeep
-
-/** What a building of a kind cost all told, its upgrades included: what pulling it down gives part of back. */
-export const builtCost = (kind: Pick<Kind, "cost" | "upgrade">, level: number): Kind["cost"] => {
- let coins = kind.cost.coins
- const materials: Partial<Record<GoodId, number>> = { ...kind.cost.materials }
- for (let l = 1; l <= level; l++) {
- const up = upgradeAt(kind, l)
- if (!up) break
- coins += up.cost.coins
- for (const [g, n] of Object.entries(up.cost.materials) as Array<[GoodId, number]>) materials[g] = (materials[g] ?? 0) + n
- }
- return { coins, materials }
-}
-
-const free = { residents: 0, citizens: 0 }
-
-// Each flat-roofed kind's `half` splits evenly into its bays (2 × half / bays
-// is whole), so every window and topper sits on whole units.
-export const kinds: Readonly<Record<KindId, Kind>> = {
- townhall: {
- id: "townhall", title: "Town hall", blurb: "the heart of the town: storage, taxes, and a walker with provisions",
- category: "storage", size: 3, half: 20, stories: 2, roof: "flat", bays: 2, window: 8, topper: "flag",
- cost: { coins: 0, materials: {} }, upkeep: 0, workers: 0, crew: "settlers", unlock: free, buildable: false,
- holds: { accepts: "all", cap: 100 }, carriers: 6,
- service: { service: "goods", seconds: 8, range: 20 }, appeal: { value: 4, reach: 4, full: 2 },
- upgrade: {
- title: "Guildhall", blurb: "the town hall with a clock tower: it holds twice as much, sends more carriers, its walker goes further, and it runs the town for a tenth less", rank: 1,
- cost: { coins: 500, materials: { planks: 30, stone: 40, tools: 6 } }, upkeep: 8,
- cap: 200, carriers: 8, service: { seconds: 6, range: 26 }, appeal: { value: 6, reach: 5, full: 2 }, admin: 0.1,
- next: {
- title: "City hall", blurb: "a domed seat of the city: it holds the most, sends the most carriers, walks furthest, and runs the city for a fifth less", rank: 2,
- cost: { coins: 1200, materials: { planks: 50, stone: 80, tools: 15, cloth: 20 } }, upkeep: 16,
- cap: 300, carriers: 10, service: { seconds: 5, range: 32 }, appeal: { value: 8, reach: 6, full: 3 }, admin: 0.2
- }
- }
- },
- warehouse: {
- id: "warehouse", title: "Warehouse", blurb: "stores goods nearer where they are made and used",
- category: "storage", size: 3, half: 18, stories: 1, roof: "flat", bays: 3, window: 6, topper: "crates",
- cost: { coins: 150, materials: { planks: 8, stone: 4 } }, upkeep: 6, workers: 2, crew: "settlers", unlock: free, buildable: true,
- holds: { accepts: "all", cap: 50 }, carriers: 4, appeal: { value: -2, reach: 2 },
- upgrade: {
- title: "Depot", blurb: "a loading yard and a hoist: it holds more than twice as much, and sends two more carriers", rank: 1,
- cost: { coins: 200, materials: { planks: 10, stone: 10 } }, upkeep: 10, cap: 120, carriers: 6
- }
- },
- granary: {
- id: "granary", title: "Granary", blurb: "stores food, and keeps fish and bread five times as long",
- category: "storage", size: 2, half: 11, stories: 2, roof: "flat", bays: 2, window: 4, topper: "none",
- cost: { coins: 120, materials: { planks: 6, stone: 2 } }, upkeep: 4, workers: 1, crew: "settlers", unlock: { residents: 20, citizens: 0 }, buildable: true,
- holds: { accepts: ["fish", "smoked", "bread", "wheat", "flour"], cap: 60 }, carriers: 3, keeps: 5, appeal: { value: -2, reach: 2 }
- },
- lumberjack: {
- id: "lumberjack", title: "Lumberjack", blurb: "fells grown trees nearby for wood",
- category: "gathering", size: 2, half: 10, stories: 1, roof: "gable", bays: 2, window: 4, topper: "none",
- cost: { coins: 50, materials: { planks: 2 } }, upkeep: 3, workers: 2, crew: "settlers", unlock: free, buildable: true,
- recipe: { input: null, inputs: 0, output: "wood", batch: 1, seconds: 6 }, gathers: { source: "tree", radius: 4 }, carriers: 2,
- wear: 60, appeal: { value: -2, reach: 2 }
- },
- forester: {
- id: "forester", title: "Forester", blurb: "plants trees on free ground nearby",
- category: "gathering", size: 2, half: 9, stories: 1, roof: "gable", bays: 2, window: 4, topper: "none",
- cost: { coins: 40, materials: { planks: 2 } }, upkeep: 2, workers: 1, crew: "settlers", unlock: free, buildable: true,
- plants: { what: "tree", radius: 3, seconds: 6, max: 20 }
- },
- quarry: {
- id: "quarry", title: "Quarry", blurb: "cuts stone from rocks nearby",
- category: "gathering", size: 2, half: 10, stories: 1, roof: "flat", bays: 2, window: 6, topper: "none",
- cost: { coins: 80, materials: { planks: 4 } }, upkeep: 5, workers: 3, crew: "settlers", unlock: free, buildable: true,
- recipe: { input: null, inputs: 0, output: "stone", batch: 1, seconds: 8 }, gathers: { source: "stone", radius: 3 }, carriers: 2,
- wear: 50, dusty: true, appeal: { value: -8, reach: 4 },
- upgrade: {
- title: "Masonry", blurb: "a derrick and a mason's shed: it goes on cutting worked-out rock at full pace, not a third of it; a dustier neighbour", rank: 2,
- cost: { coins: 200, materials: { planks: 6, tools: 2 } }, upkeep: 8, deep: true, appeal: { value: -10, reach: 4 }
- }
- },
- mine: {
- id: "mine", title: "Mine", blurb: "digs ore from a deposit nearby",
- category: "gathering", size: 2, half: 10, stories: 1, roof: "flat", bays: 2, window: 6, topper: "chimney",
- cost: { coins: 200, materials: { planks: 6, stone: 4 } }, upkeep: 6, workers: 4, crew: "settlers", unlock: { residents: 0, citizens: 10 }, buildable: true,
- recipe: { input: null, inputs: 0, output: "ore", batch: 1, seconds: 10 }, gathers: { source: "ore", radius: 3 }, carriers: 2,
- wear: 50, dusty: true, appeal: { value: -8, reach: 4 }
- },
- fishery: {
- id: "fishery", title: "Fishery", blurb: "catches fish; needs its own stretch of water within two cells",
- category: "food", size: 2, half: 10, stories: 1, roof: "gable", bays: 2, window: 4, topper: "none",
- cost: { coins: 60, materials: { planks: 3 } }, upkeep: 5, workers: 2, crew: "settlers", unlock: free, buildable: true,
- recipe: { input: null, inputs: 0, output: "fish", batch: 1, seconds: 4 }, gathers: { source: "water", radius: 2 }, carriers: 2,
- appeal: { value: -2, reach: 2 }
- },
- smokehouse: {
- id: "smokehouse", title: "Smokehouse", blurb: "smokes fish, which then keeps all winter",
- category: "food", size: 2, half: 10, stories: 1, roof: "gable", bays: 2, window: 4, topper: "chimney",
- cost: { coins: 90, materials: { planks: 4, stone: 1 } }, upkeep: 4, workers: 2, crew: "settlers", unlock: { residents: 20, citizens: 0 }, buildable: true,
- recipe: { input: "fish", inputs: 1, output: "smoked", batch: 1, seconds: 5 }, holds: { accepts: ["fish", "smoked"], cap: 8 }, carriers: 2,
- wear: 60, hot: true, appeal: { value: -4, reach: 3 }
- },
- sawmill: {
- id: "sawmill", title: "Sawmill", blurb: "saws wood into planks",
- category: "crafts", size: 2, half: 12, stories: 1, roof: "flat", bays: 2, window: 6, topper: "chimney",
- cost: { coins: 100, materials: { planks: 2, stone: 2 } }, upkeep: 6, workers: 2, crew: "citizens", unlock: free, buildable: true,
- recipe: { input: "wood", inputs: 1, output: "planks", batch: 1, seconds: 5 }, holds: { accepts: ["wood", "planks"], cap: 8 }, carriers: 2,
- wear: 60, appeal: { value: -4, reach: 3 }
- },
- smithy: {
- id: "smithy", title: "Smithy", blurb: "forges ore into tools",
- category: "crafts", size: 2, half: 12, stories: 1, roof: "flat", bays: 2, window: 6, topper: "chimney",
- cost: { coins: 250, materials: { planks: 4, stone: 6 } }, upkeep: 12, workers: 3, crew: "citizens", unlock: { residents: 0, citizens: 10 }, buildable: true,
- recipe: { input: "ore", inputs: 1, output: "tools", batch: 1, seconds: 10 }, holds: { accepts: ["ore", "tools"], cap: 8 }, carriers: 2,
- hot: true, appeal: { value: -8, reach: 4 }
- },
- farm: {
- id: "farm", title: "Farm", blurb: "sows fields around it and harvests the wheat",
- category: "food", size: 3, half: 12, stories: 1, roof: "gable", bays: 2, window: 4, topper: "none",
- cost: { coins: 120, materials: { planks: 4 } }, upkeep: 5, workers: 2, crew: "settlers", unlock: { residents: 60, citizens: 0 }, buildable: true,
- recipe: { input: null, inputs: 0, output: "wheat", batch: 1, seconds: 4 }, gathers: { source: "field", radius: 2 },
- plants: { what: "field", radius: 2, seconds: 3, max: 8 }, carriers: 2, appeal: { value: -2, reach: 2 },
- upgrade: {
- title: "Estate", blurb: "a barn and a dovecote: a third hand reaps the same fields half again as fast", rank: 2,
- cost: { coins: 250, materials: { planks: 8, stone: 6, tools: 1 } }, upkeep: 7, workers: 3, seconds: 2.5
- }
- },
- mill: {
- id: "mill", title: "Mill", blurb: "grinds wheat into flour",
- category: "food", size: 2, half: 8, stories: 2, roof: "flat", bays: 2, window: 4, topper: "sails",
- cost: { coins: 150, materials: { planks: 6, stone: 2, tools: 1 } }, upkeep: 8, workers: 2, crew: "citizens", unlock: { residents: 60, citizens: 0 }, buildable: true,
- recipe: { input: "wheat", inputs: 1, output: "flour", batch: 1, seconds: 6 }, holds: { accepts: ["wheat", "flour"], cap: 8 }, carriers: 2,
- wear: 60, appeal: { value: -4, reach: 3 }
- },
- bakery: {
- id: "bakery", title: "Bakery", blurb: "bakes flour into bread",
- category: "food", size: 2, half: 12, stories: 1, roof: "flat", bays: 2, window: 6, topper: "chimney",
- cost: { coins: 150, materials: { planks: 4, stone: 4, tools: 1 } }, upkeep: 8, workers: 2, crew: "citizens", unlock: { residents: 60, citizens: 0 }, buildable: true,
- recipe: { input: "flour", inputs: 1, output: "bread", batch: 2, seconds: 6 }, holds: { accepts: ["flour", "bread"], cap: 8 }, carriers: 2,
- wear: 60, hot: true, appeal: { value: -4, reach: 3 },
- upgrade: {
- title: "Ovenworks", blurb: "a second oven and a third baker: bread every four seconds instead of six", rank: 2,
- cost: { coins: 300, materials: { planks: 6, stone: 10, tools: 2 } }, upkeep: 13, workers: 3, seconds: 4
- }
- },
- sheep: {
- id: "sheep", title: "Sheep farm", blurb: "shears sheep for wool",
- category: "crafts", size: 3, half: 12, stories: 1, roof: "gable", bays: 2, window: 4, topper: "none",
- cost: { coins: 100, materials: { planks: 4 } }, upkeep: 5, workers: 2, crew: "settlers", unlock: { residents: 40, citizens: 0 }, buildable: true,
- recipe: { input: null, inputs: 0, output: "wool", batch: 1, seconds: 6 }, carriers: 2, appeal: { value: -2, reach: 2 }
- },
- weaver: {
- id: "weaver", title: "Weaver", blurb: "weaves wool into cloth",
- category: "crafts", size: 2, half: 12, stories: 1, roof: "flat", bays: 2, window: 6, topper: "none",
- cost: { coins: 150, materials: { planks: 4, stone: 2, tools: 1 } }, upkeep: 8, workers: 2, crew: "citizens", unlock: { residents: 40, citizens: 0 }, buildable: true,
- recipe: { input: "wool", inputs: 1, output: "cloth", batch: 1, seconds: 6 }, holds: { accepts: ["wool", "cloth"], cap: 8 }, carriers: 2,
- wear: 60, appeal: { value: -2, reach: 2 }
- },
- carpenter: {
- id: "carpenter", title: "Carpenter", blurb: "makes furniture from planks, for the burghers' townhouses",
- category: "crafts", size: 2, half: 12, stories: 1, roof: "gable", bays: 2, window: 4, topper: "chimney",
- cost: { coins: 160, materials: { planks: 4, stone: 2, tools: 1 } }, upkeep: 8, workers: 2, crew: "citizens", unlock: { residents: 0, citizens: 20 }, buildable: true,
- recipe: { input: "planks", inputs: 2, output: "furniture", batch: 1, seconds: 8 }, holds: { accepts: ["planks", "furniture"], cap: 8 }, carriers: 2,
- wear: 60, appeal: { value: -2, reach: 2 }
- },
- market: {
- id: "market", title: "Market", blurb: "a walker carries fish, bread, cloth, and furniture to the homes it passes",
- category: "services", size: 2, half: 12, stories: 1, roof: "flat", bays: 2, window: 6, topper: "flag",
- cost: { coins: 120, materials: { planks: 6, stone: 2 } }, upkeep: 6, workers: 2, crew: "citizens", unlock: free, buildable: true,
- holds: { accepts: ["fish", "smoked", "bread", "cloth", "furniture"], cap: 12 },
- service: { service: "goods", seconds: 6, range: 18 }, appeal: { value: 2, reach: 3, full: 2 },
- upgrade: {
- title: "Market hall", blurb: "a covered hall: its walker goes further, more often, and the street around it is finer", rank: 2,
- cost: { coins: 400, materials: { planks: 6, stone: 12, tools: 2 } }, upkeep: 12,
- service: { seconds: 4, range: 26 }, appeal: { value: 4, reach: 4, full: 2 }
- }
- },
- chapel: {
- id: "chapel", title: "Chapel", blurb: "a walker brings faith to the homes it passes",
- category: "services", size: 2, half: 12, stories: 2, roof: "flat", bays: 2, window: 6, topper: "cupola",
- cost: { coins: 200, materials: { planks: 6, stone: 6 } }, upkeep: 10, workers: 1, crew: "citizens", unlock: { residents: 40, citizens: 0 }, buildable: true,
- service: { service: "faith", seconds: 8, range: 22 }, appeal: { value: 4, reach: 4, full: 2 },
- upgrade: {
- title: "Church", blurb: "a church with a tower: its priest walks further, more often, and the streets around it are the finest", rank: 2,
- cost: { coins: 700, materials: { planks: 8, stone: 20, tools: 3 } }, upkeep: 18,
- service: { seconds: 6, range: 30 }, appeal: { value: 6, reach: 5, full: 3 }
- }
- },
- firewatch: {
- id: "firewatch", title: "Fire watch", blurb: "a watchman checks homes and workshops along the way for fire; firefighters run to any blaze",
- category: "services", size: 2, half: 9, stories: 1, roof: "gable", bays: 2, window: 4, topper: "none",
- cost: { coins: 70, materials: { planks: 3 } }, upkeep: 3, workers: 2, crew: "settlers", unlock: free, buildable: true,
- service: { service: "fire", seconds: 7, range: 30 },
- upgrade: {
- title: "Fire brigade", blurb: "a bell tower and a pump: its watchman walks further, more often, and four firefighters run instead of two", rank: 2,
- cost: { coins: 200, materials: { planks: 6, stone: 6, tools: 1 } }, upkeep: 5, service: { seconds: 5, range: 36 }, crews: 4
- }
- },
- healer: {
- id: "healer", title: "Healer", blurb: "a physician calls on the homes along the way and cures the sick",
- category: "services", size: 2, half: 10, stories: 1, roof: "flat", bays: 2, window: 4, topper: "none",
- cost: { coins: 110, materials: { planks: 4, stone: 2 } }, upkeep: 4, workers: 1, crew: "citizens", unlock: { residents: 30, citizens: 0 }, buildable: true,
- service: { service: "health", seconds: 8, range: 30 }, appeal: { value: 1, reach: 2 }
- },
- hospital: {
- id: "hospital", title: "Hospital", blurb: "physicians call more often and walk further",
- category: "services", size: 3, half: 16, stories: 2, roof: "flat", bays: 2, window: 6, topper: "cupola",
- cost: { coins: 400, materials: { planks: 10, stone: 10, tools: 2 } }, upkeep: 10, workers: 4, crew: "citizens", unlock: { residents: 0, citizens: 40 }, buildable: true,
- service: { service: "health", seconds: 4, range: 40 }, appeal: { value: 2, reach: 3, full: 2 }
- },
- watchhouse: {
- id: "watchhouse", title: "Watch house", blurb: "a constable walks the streets, keeping order in the homes along the way",
- category: "services", size: 2, half: 10, stories: 1, roof: "flat", bays: 2, window: 4, topper: "flag",
- cost: { coins: 100, materials: { planks: 4, stone: 2 } }, upkeep: 3, workers: 2, crew: "settlers", unlock: { residents: 40, citizens: 0 }, buildable: true,
- service: { service: "order", seconds: 8, range: 30 }
- },
- builder: {
- id: "builder", title: "Builder's yard", blurb: "a builder mends the homes and buildings along the way, with planks and stone",
- category: "services", size: 2, half: 10, stories: 1, roof: "gable", bays: 2, window: 4, topper: "none",
- cost: { coins: 90, materials: { planks: 4 } }, upkeep: 3, workers: 2, crew: "settlers", unlock: free, buildable: true,
- holds: { accepts: ["planks", "stone"], cap: 6 },
- service: { service: "repair", seconds: 8, range: 20 }, appeal: { value: -2, reach: 2 }
- }
-}
-
-export const kindOrder: ReadonlyArray<KindId> = [
- "warehouse", "granary", "lumberjack", "forester", "quarry", "mine", "sawmill", "smithy", "sheep", "weaver", "carpenter",
- "fishery", "smokehouse", "farm", "mill", "bakery", "market", "chapel", "firewatch", "healer", "hospital", "watchhouse", "builder"
-]
-
-export const costText = (cost: Kind["cost"]): string =>
- [cost.coins > 0 ? `${cost.coins} coins` : "", ...Object.entries(cost.materials).map(([g, n]) => `${n} ${n === 1 && g.endsWith("s") ? g.slice(0, -1) : g}`)].filter((s) => s !== "").join(" · ")
-
-// ── Parks ─────────────────────────────────────────────────────────────────
-
-/**
- * A park is laid out cell by cell: ground painted on empty land (lawn,
- * flower beds, gravel paths, a paved square), and on any of its cells one
- * furnishing (a lamp, a fountain, a statue). Cells of ground that touch
- * make one park, and the whole park is what the street around it feels
- * (see `parkSources` in `appeal.ts`): its `beauty` adds up from its
- * ground, its furnishings, and its entrances (a walk or a square beside a
- * road), and that is the desirability it gives the cells around it, out to
- * a reach that grows with its size. Nobody walks through it: it is not a
- * road.
- */
-export const groundIds = ["lawn", "flowers", "path", "square"] as const
-export type GroundId = (typeof groundIds)[number]
-export const propIds = ["lamp", "fountain", "statue"] as const
-export type PropId = (typeof propIds)[number]
-
-export interface ParkPiece {
- readonly title: string
- readonly blurb: string
- readonly cost: Kind["cost"]
- /** Coins a minute. */
- readonly upkeep: number
- /** What it adds to its park's beauty. */
- readonly beauty: number
- readonly unlock: { readonly residents: number; readonly citizens: number }
-}
-
-export const grounds: Readonly<Record<GroundId, ParkPiece>> = {
- lawn: { title: "Lawn", blurb: "grass to lay a park out on", cost: { coins: 2, materials: {} }, upkeep: 0.05, beauty: 0.25, unlock: free },
- flowers: { title: "Flower bed", blurb: "planted borders: prettier than lawn", cost: { coins: 5, materials: {} }, upkeep: 0.15, beauty: 0.75, unlock: free },
- path: { title: "Gravel path", blurb: "a walk through the park", cost: { coins: 3, materials: {} }, upkeep: 0.05, beauty: 0.25, unlock: free },
- square: { title: "Paved square", blurb: "stone setts, for a statue or a fountain to stand on", cost: { coins: 3, materials: { stone: 1 } }, upkeep: 0.05, beauty: 0.25, unlock: free }
-}
-
-export const props: Readonly<Record<PropId, ParkPiece>> = {
- lamp: { title: "Lamp", blurb: "an iron lamp post along the walk", cost: { coins: 12, materials: { tools: 1 } }, upkeep: 0.2, beauty: 1.5, unlock: free },
- fountain: { title: "Fountain", blurb: "a stone basin of fresh water", cost: { coins: 70, materials: { stone: 3 } }, upkeep: 2, beauty: 4, unlock: { residents: 30, citizens: 0 } },
- statue: { title: "Statue", blurb: "a founder in stone, the pride of the park", cost: { coins: 160, materials: { stone: 6 } }, upkeep: 3, beauty: 5, unlock: { residents: 0, citizens: 20 } }
-}
-
-/** How a park's beauty adds up (see `parkSources`). */
-export const park = {
- /** Ground counts for this much beauty at most, however big the park. */
- groundMost: 4,
- /** One furnishing counts for every this many whole cells (none on a park of one): a park crowded with benches is no nicer. */
- cellsPerProp: 2,
- /** Each furnishing of a kind after the first counts this share of the one before. */
- repeat: 0.5,
- /** A walk or a square beside a road is a way in from the street: each adds this, up to `entrances` of them. */
- entrance: 1.5,
- entrances: 2,
- /** The most a park gives the streets around it. */
- most: 15,
- /**
- * Where several parks reach a cell, the finest counts in full and the
- * others this share of theirs: a street lined with scraps of park is
- * not a park.
- */
- others: 0.5,
- /** How far it reaches: `reach[0]` cells, and one more for every `reach[1]` cells of park, up to `reach[2]`. */
- reach: [2, 6, 5] as const
-}
-
-// ── Homes ─────────────────────────────────────────────────────────────────
-
-export type Tier = 1 | 2 | 3
-export const tierIds: ReadonlyArray<Tier> = [1, 2, 3]
-/** What a home can be short of. Settlers need food (fish, smoked fish, or bread); citizens bread, cloth, and faith; burghers furniture besides. */
-export type Need = "food" | "bread" | "cloth" | "faith" | "furniture"
-
-export const home = {
- /** Half the house's width, in units: a 1×1 cell is 8 units from centre to edge. */
- half: 5,
- cost: { coins: 15, materials: { planks: 1 } } as Kind["cost"],
- tiers: {
- 1: { title: "settlers", residents: 4, tax: 2.5, height: 24, needs: ["food"], appeal: -100, rise: { coins: 0, materials: {} } },
- 2: { title: "citizens", residents: 8, tax: 5, height: 46, needs: ["bread", "cloth", "faith"], appeal: 5, rise: { coins: 35, materials: { planks: 4, stone: 2 } } },
- 3: { title: "burghers", residents: 12, tax: 7, height: 68, needs: ["bread", "cloth", "faith", "furniture"], appeal: 12, rise: { coins: 45, materials: { planks: 4, stone: 4, tools: 1, furniture: 2 } } }
- } as Readonly<Record<Tier, {
- readonly title: string
- readonly residents: number
- readonly tax: number
- readonly height: number
- readonly needs: ReadonlyArray<Need>
- /** The desirability a home of this tier needs around it (see `appeal.ts`). */
- readonly appeal: number
- /**
- * What rebuilding a home into this tier costs, paid at once from the
- * treasury and the store when it is ready to rise, as paving is: a home
- * that cannot be paid for waits at its tier. A home that steps down
- * keeps its rebuilding, and rises back into it for nothing.
- */
- readonly rise: Kind["cost"]
- }>>,
- /** A resident moves in (or out) this often. */
- settle: Clock.steps(Clock.duration(step, 3)),
- /** How long each need stays met after a walker's visit: cloth and faith last longer than a meal. */
- lasts: { food: Clock.steps(Clock.duration(step, 90)), bread: Clock.steps(Clock.duration(step, 120)), cloth: Clock.steps(Clock.duration(step, 240)), faith: Clock.steps(Clock.duration(step, 180)), furniture: Clock.steps(Clock.duration(step, 300)) } as Readonly<Record<Need, number>>,
- /** Where nobody wants to live: the desirability the map's legend calls squalid. */
- squalid: -5,
- /**
- * What a street does to a home, point by point of desirability (see
- * `streetRoom` and `streetTax`): a home holds (1 + d / `room`) of its
- * residents, never fewer than `roomLeast`; and pays (1 + d / `tax`),
- * within `taxMost` either way. So a cottage beside a quarry empties a
- * little and pays less, long before anything is squalid.
- */
- street: { room: 12, roomLeast: 0.5, tax: 40, taxMost: 0.25 },
- /** A settlers' cottage with bread on the table pays this much more: bread is worth baking before anyone is a citizen. */
- breadBonus: 0.5,
- /**
- * The need a finer home cannot be without: a citizens' home or a
- * townhouse out of bread goes back to settlers, however much fish it
- * eats (cloth or faith alone may lapse a while).
- */
- staple: "bread" as Need,
- /**
- * A walker's visit feeds a home one fish or loaf for every `perMeal`
- * residents (rounded up): a cottage one, a citizens' home two, a
- * townhouse three. Food demand grows with the people, not the roofs.
- */
- perMeal: 4,
- /**
- * Taxes above 100% drive people away directly, besides what they do to
- * approval: at x = (rate − 100) / 100, a home holds 1 − `linear`·x −
- * `square`·x² of its residents (settlers: 80% at 150%, half at 200%);
- * citizens and burghers mind `citizens` as much. So squeezing harder
- * empties the homes it squeezes, and the most a rate can bring in
- * comes well before the top of the slider.
- */
- taxFlight: { linear: 0.3, square: 0.2, citizens: 0.6 }
-}
-
-/** A word with its article: "a guildhall", "an estate". */
-export const anA = (word: string): string => `${/^[aeiou]/i.test(word) ? "an" : "a"} ${word}`
-
-/** What a tier's homes are called, and what its residents are. */
-export const tierHome: Readonly<Record<Tier, string>> = { 1: "settlers' cottage", 2: "citizens' home", 3: "townhouse" }
-
-/** Which crew a tier's residents work in. */
-export const crewOf = (tier: Tier): Crew => (tier === 1 ? "settlers" : "citizens")
-
-/** Road cells a resident walks to work, at most (see `AssignStaff`). */
-export const COMMUTE = 15
-/** An apprentice (a settler in a citizens' job) works at this share of the pace. */
-export const APPRENTICE = 0.75
-/** Tools a workshop that wears them keeps on hand. */
-export const TOOL_STOCK = 1
-
-// ── Desirability ──────────────────────────────────────────────────────────
-
-/**
- * What the land and the town do to the cells around them, besides the
- * buildings' own (`Kind.appeal`). Water and woods count once, however many
- * are near; so do paved streets.
- */
-export const appeal = {
- water: { value: 2, reach: 2 },
- forest: { value: 2, reach: 2 },
- paved: { value: 1, reach: 1 },
- ruin: { value: -3, reach: 2 },
- worn: { value: -2, reach: 1 },
- /** A citizens' home and a townhouse lift the homes beside them (never themselves), all told up to `homesMost`. */
- citizens: { value: 1, reach: 1 },
- burghers: { value: 2, reach: 1 },
- homesMost: 3,
- /** Desirability is reckoned this often. */
- every: 30,
- /** And kept within these bounds. */
- floor: -30,
- ceiling: 40
-}
-
-/** Paving a road cell: coins and stone, the stone taken from storage at once. */
-export const PAVE_COST = { coins: 3, stone: 1 }
-/** Carriers and walkers move this much faster along a paved street (see `Walk`). */
-export const PAVED_PACE = 1.5
-
-// ── Risks ─────────────────────────────────────────────────────────────────
-
-/**
- * Every home has three risk meters, 0 → `RISK_MAX`, and every building a
- * fire meter. Each rises a little every second, faster for the reasons
- * below (points a second); the matching service walker passing resets it.
- * Over `warn` a sign goes up over the home; at the top, disaster.
- */
-export const RISK_MAX = 10_000
-export const risk = {
- /** Past this, a sign goes up and the map views turn red: half way, so there is time to act. */
- warn: 5000,
- /** The three services' walkers keep a burghers' home: its meters must stay under this. */
- kept: 5000,
- /** Each home and building rises at its own pace, between these shares of the usual (fixed by where it stands), so a street does not all go up at once. */
- pace: [0.75, 1.25] as const,
- fire: {
- /** Settlers' cottages are wooden. */
- wooden: 6,
- stone: 4,
- building: 2,
- /** A bakery's oven, a smithy's forge: in itself, and to each home within `reach`. */
- hot: 10,
- near: 6,
- reach: 2,
- crowded: 3,
- worn: 6,
- /** Heating through a hard winter. */
- winter: 6,
- /** How long a blaze burns before the house is lost. */
- burns: Clock.steps(Clock.duration(step, 20)),
- /** A burning house sets a neighbour alight, each second: this chance, and up to `spread` more for a neighbour at the top of its own meter. */
- catches: 0.03,
- spread: 0.12,
- /** Firefighters a fire watch may have out at once. */
- crews: 2
- },
- health: {
- base: 3,
- hungry: 6,
- crowded: 3,
- squalid: 4,
- /** A quarry's or a mine's dust, within `reach`. */
- dust: 6,
- reach: 3,
- /** Still water within two cells. */
- water: 3,
- /** How long a sickness lasts if no physician comes; meanwhile the home holds `sickly` as many. */
- lasts: Clock.steps(Clock.duration(step, 60)),
- sickly: 0.5,
- /** Each second, the chance it reaches a home within two cells: raising its risk by `contagion` (a home a physician calls on shrugs it off). */
- spreads: 0.04,
- contagion: 3000
- },
- order: {
- base: 3,
- /** For every 50 points of approval below nothing. */
- unrest: 8,
- squalid: 4,
- /** A home standing half empty. */
- vacant: 4,
- /** A burghers' home is worth robbing. */
- wealth: 3,
- /** A theft takes this many coins and this share of the treasury, or goods instead when it is empty. */
- coins: 10,
- share: 0.02,
- most: 80,
- goods: 4,
- /** After a theft its meter falls only to here; reaching the top again, the home empties and is left derelict. */
- after: 3000
- }
-}
-
-/** How well kept a building or home is, 0 → `CONDITION_MAX`. */
-export const CONDITION_MAX = 1000
-export const condition = {
- /** A point lost every `every` steps: from new to run down in about 33 minutes, and fallen down in 67, unmended. */
- every: Clock.steps(Clock.duration(step, 4)),
- /** Below this, a builder mends it as they pass (after about 23 minutes without repair). */
- mend: 650,
- /** Below this, it works at half pace, and its fire risk rises. */
- worn: 500
-}
-
-/** Tax rates the town can set, in percent of the usual. */
-export const TAX_STEPS = [50, 75, 100, 125, 150, 200] as const
-
-export const needTitle: Readonly<Record<Need, string>> = { food: "food", bread: "bread", cloth: "cloth", faith: "faith", furniture: "furniture" }
-
-// ── The town ──────────────────────────────────────────────────────────────
-
-/** How long anything takes to go up once its materials are in. */
-export const BUILD_TICKS = Clock.steps(Clock.duration(step, 2.4))
-/** Taxes are collected and upkeep paid this often. */
-export const LEDGER_TICKS = Clock.steps(Clock.duration(step, 10))
-export const ROAD_COST = 2
-/** Trees and fields are ready to harvest once this grown. */
-export const GROWN = { tree: Clock.steps(Clock.duration(step, 40)), field: Clock.steps(Clock.duration(step, 20)) }
-/** The most a rock holds (see `lands` for how much each starts with). */
-export const ROCK_AMOUNT = 40
-/**
- * A rock quarried down to nothing stays as a worked face: it gives one more
- * stone (or ore) this often, so a quarry or mine beside it keeps going at
- * about a third of its pace instead of stopping for good.
- */
-export const FACE_TICKS = Clock.steps(Clock.duration(step, 90))
-/**
- * A cell of water fished rests this long before it gives another catch,
- * so a fishery needs a good stretch of shore to itself to work at full
- * pace, and fisheries crowded on one lake share its fish.
- */
-export const RESTOCK_TICKS = Clock.steps(Clock.duration(step, 40))
-
-// ── The charter: what a new town is founded on ────────────────────────────
-
-export const sizeIds = ["small", "medium", "large"] as const
-export type SizeId = (typeof sizeIds)[number]
-export const landIds = ["rich", "fair", "harsh"] as const
-export type LandId = (typeof landIds)[number]
-/** How long a term in office runs, in minutes of game time. */
-export const TERMS = [45, 60, 90] as const
-
-/**
- * Sizes of land: its rough radius in cells (the coast wanders in and out of
- * it, with capes reaching further), and what the town must reach to be
- * a town (see `ranks`: a village needs less of both, a city more): its
- * residents, and its income, coins a minute after upkeep and
- * administration. Income, not coins held: a treasury is for spending.
- */
-export const sizes: Readonly<Record<SizeId, {
- readonly title: string
- readonly radius: number
- readonly goal: { readonly residents: number; readonly income: number }
-}>> = {
- small: { title: "small", radius: 14, goal: { residents: 180, income: 100 } },
- medium: { title: "medium", radius: 19, goal: { residents: 320, income: 150 } },
- large: { title: "large", radius: 25, goal: { residents: 520, income: 200 } }
-}
-
-/**
- * How generous the land is: forests, outcrops of stone, deposits of ore
- * (each per thousand cells of land), how much each rock holds, lakes, and
- * what the town starts with.
- */
-export const lands: Readonly<Record<LandId, {
- readonly title: string
- readonly blurb: string
- readonly forests: number
- readonly stone: number
- readonly ore: number
- readonly rock: number
- readonly lakes: number
- readonly coins: number
- readonly stock: Amounts
-}>> = {
- rich: {
- title: "rich", blurb: "deep forests, plenty of stone and ore, two lakes, a full treasury",
- forests: 7, stone: 4.5, ore: 3, rock: 40, lakes: 2, coins: 1250,
- stock: amounts({ wood: 15, planks: 50, stone: 24, tools: 10, fish: 30 })
- },
- fair: {
- title: "fair", blurb: "enough of everything, if it is not wasted",
- forests: 5.5, stone: 3, ore: 2, rock: 32, lakes: 2, coins: 1100,
- stock: amounts({ wood: 10, planks: 40, stone: 16, tools: 10, fish: 20 })
- },
- harsh: {
- title: "harsh", blurb: "thin woods, little stone, one deposit of ore, one lake",
- forests: 4, stone: 2, ore: 1, rock: 24, lakes: 1, coins: 950,
- stock: amounts({ wood: 10, planks: 30, stone: 12, tools: 8, fish: 15 })
- }
-}
-
-export interface CharterValue {
- readonly size: SizeId
- readonly term: number
- readonly land: LandId
- readonly seed: number
-}
-export const defaultCharter = (seed: number): CharterValue => ({ size: "medium", term: 60, land: "fair", seed })
-
-// ── Pressure ──────────────────────────────────────────────────────────────
-
-/**
- * Seasons: a term is six years; the last part of each but the first is
- * winter, when fields do not grow, fisheries catch half as much, and homes
- * eat faster.
- */
-export const YEARS_PER_TERM = 6
-export const WINTER_SHARE = 0.3
-
-/**
- * Each year's winter is mild, normal, or hard, rolled from the seed when the
- * town is founded (see `Charter.winters`): how much of the year it takes,
- * what fisheries catch, and whether homes heat (a fire risk).
- */
-export const winterIds = ["mild", "normal", "hard"] as const
-export type WinterId = (typeof winterIds)[number]
-export const winters: Readonly<Record<WinterId, { readonly title: string; readonly share: number; readonly fishing: number; readonly heating: boolean; readonly chance: number }>> = {
- mild: { title: "mild", share: WINTER_SHARE, fishing: 0.75, heating: false, chance: 0.3 },
- normal: { title: "normal", share: WINTER_SHARE, fishing: 0.5, heating: false, chance: 0.45 },
- hard: { title: "hard", share: WINTER_SHARE * 1.5, fishing: 0.4, heating: true, chance: 0.25 }
-}
-/** The almanac warns of winter this many steps before it comes. */
-export const WINTER_WARNING = Clock.steps(Clock.duration(step, 60))
-
-/**
- * Running a town costs more the bigger it gets, and it is reckoned by the
- * person, not the roof: the town hall's administration costs `perResident`
- * coins a minute a resident, and a further (residents / `growth`) a
- * resident. Each more resident costs `perResident` + 2·residents /
- * `growth`: about half a settler's taxes at 320 residents (a medium
- * town's goal), and all of them by about 580, so past there a town grows by
- * finer homes; and a citizens' home of eight costs twice a cottage of
- * four, so finer homes are not had for nothing either.
- */
-export const admin = { perResident: 0.125, growth: 490 }
-
-/**
- * Approval, -100 → +100: where the town's mood is heading, and how fast it
- * gets there (points every collection). Homes hold more residents when it
- * is high and fewer when it is low (see `capacity`).
- */
-export const mood = {
- base: 10,
- /** At no needs met to every need met. */
- needs: [-35, 30] as const,
- /** Points for each percent the average tax rate is below (or above) 100%. */
- perTaxPoint: 0.6,
- debt: -20,
- /** Per unanswered crown request, while the crown remembers it. */
- snub: -20,
- winterHunger: -10,
- step: 2,
- /**
- * A grudge: taxes above `above` percent are remembered. Every collection
- * adds (rate − above) × `perPoint` tenths of a point to the town's memory,
- * up to `most`; at or below it the memory fades by `decay` tenths. The
- * grudge takes that many points off approval, so a term of 200% cannot be
- * undone by cutting taxes in the last three minutes.
- */
- grudge: { above: 125, perPoint: 0.05, decay: 5, most: 300 }
-}
-
-/**
- * Crown requests: every so often the crown asks for goods within a time.
- * Requests grow as the term goes on. Sending them earns coins; missing one
- * costs a fine and the crown's goodwill for a while.
- */
-export const crown = {
- /** Requests in a term. */
- perTerm: 9,
- /** Share of the gap between requests the town has to answer one. */
- window: 0.6,
- /**
- * How much it asks for: this share of what the town could make of the
- * good in the time given, from the start of the term to its end.
- */
- share: [0.25, 0.6] as const,
- /** Nor more than this share of what the town's storage holds of one good. */
- room: 0.6,
- /** Reward as a multiple of what the goods would fetch from traders, plus a bonus; the fine is the goods' worth plus the bonus. */
- reward: 1.3,
- fine: 1,
- bonus: 25,
- /** How long the crown remembers a missed request, in minutes. */
- memory: 4,
- /** Requests missed in a row before the crown dismisses the mayor. */
- patience: 3
-}
-
-/**
- * The market: each good's price moves with what the town trades. Selling
- * drives it down `perUnit` points a unit, buying up `perBought`. A cheap
- * price drifts back by a tenth of the gap every collection, a dear one by
- * only 1/`calms` of it: traders top up a shortfall, but a town that lives
- * on bought food pays more for it every minute. Buying costs half again
- * the price.
- */
-export const market = { floor: 30, ceiling: 250, perUnit: 1, perBought: 3, markup: 1.5, calms: 30 }
-
-/** A paused building pays this share of its upkeep. */
-export const PAUSED_UPKEEP = 0.25
-
-/**
- * Pulling down a standing building or home: a `fee` of what it cost in
- * coins, and `back` of its materials (rounded down) carried back into
- * storage. A site not yet going up is cancelled instead: its coins and
- * whatever was brought to it come back in full.
- */
-export const salvage = { fee: 0.1, back: 0.5 }
-
-/** How long each end state's danger has to last, in minutes, before the term ends with it. */
-export const fate = {
- /** Victory: every goal held this long. */
- hold: 2,
- /** Bankruptcy: in debt this long without a break. */
- debt: 3,
- /** Revolt: approval at or below `revolt` this long. */
- revolt: 2,
- revoltAt: -50,
- /** Abandonment: residents below this share of their peak, once the peak reached `peak`. */
- abandon: 0.15,
- peak: 40,
- /** The town rank's goals besides residents and coins: a share of them citizens, and approval (see `ranks`). */
- citizens: 0.3,
- approval: 15
-}
-
-/**
- * The town's ranks, from the hamlet it is founded as. It rises to the next
- * once every goal of that rank has held for `fate.hold` minutes together:
- * `residents` and `income` (out of debt) as shares of its land's goal
- * (see `sizes`), a share of the residents `citizens` (those in townhouses
- * count), a share `burghers`, approval, and (a city) a town hall upgraded
- * `hall` times, a guildhall. A rank is never lost, and the crown sends
- * `reward` coins on reaching it. The town rank is the old "complete" town;
- * nothing ends when a rank is reached.
- */
-export const ranks: ReadonlyArray<{
- readonly title: string
- readonly residents: number
- readonly income: number
- readonly citizens: number
- readonly burghers: number
- readonly approval: number
- readonly hall: number
- readonly reward: number
-}> = [
- { title: "hamlet", residents: 0, income: 0, citizens: 0, burghers: 0, approval: 0, hall: 0, reward: 0 },
- { title: "village", residents: 0.35, income: 0.3, citizens: 0.1, burghers: 0, approval: 0, hall: 0, reward: 300 },
- { title: "town", residents: 1, income: 1, citizens: fate.citizens, burghers: 0, approval: fate.approval, hall: 0, reward: 800 },
- { title: "city", residents: 1.5, income: 1.5, citizens: 0.5, burghers: 0.15, approval: 25, hall: 1, reward: 1500 }
-]
-/** The rank the old "complete" town is: the goals a balance run plays for. */
-export const TOWN_RANK = 2
-
-/** The town's history: a sample this often. */
-export const HISTORY_TICKS = Clock.steps(Clock.duration(step, 15))
+ *
+ * Each closed set lives in its own module beside this one (the building
+ * kinds one file per category, in `kinds/`); this file only gathers them,
+ * so everything is still imported from here.
+ */
+export { every, periodOf, step, stepsOf } from "./clock.ts"
+export {
+ amounts, each, foods, goodIds, goods, none, provisions, RESERVE_MAX, shownGoods, SPOIL_TICKS, spoils, total, trade, TRADE_LOAD,
+ type Amounts, type GoodId
+} from "./goods.ts"
+export {
+ asUpgraded, builtCost, categoryColor, categoryOrder, homeColor, kindIds, kindOrder, kinds, nextUpgrade, serviceIds, upgradeAt, upkeepOf, WORKS_TICKS, worksNeeded,
+ type Category, type Crew, type Kind, type KindId, type Level, type ServiceId, type Source, type Topper, type Upgrade
+} from "./kinds/index.ts"
+export { anA, costText } from "./text.ts"
+export { groundIds, grounds, park, propIds, props, type GroundId, type ParkPiece, type PropId } from "./parks.ts"
+export { APPRENTICE, COMMUTE, crewOf, home, needTitle, tierHome, tierIds, TOOL_STOCK, type Need, type Tier } from "./homes.ts"
+export { appeal, PAVE_COST, PAVED_PACE } from "./streets.ts"
+export { condition, CONDITION_MAX, risk, RISK_MAX } from "./risks.ts"
+export {
+ defaultCharter, FACE_TICKS, GROWN, landIds, lands, RESTOCK_TICKS, ROCK_AMOUNT, sizeIds, sizes, TERMS, WINTER_SHARE, WINTER_WARNING, winterIds, winters, YEARS_PER_TERM,
+ type CharterValue, type LandId, type SizeId, type WinterId
+} from "./lands.ts"
+export { admin, BUILD_TICKS, crown, fate, HISTORY_TICKS, LEDGER_TICKS, market, mood, PAUSED_UPKEEP, ranks, ROAD_COST, salvage, TAX_STEPS, TOWN_RANK } from "./town.ts"
diff --git a/src/game/content/kinds/crafts.ts b/src/game/content/kinds/crafts.ts
new file mode 100644
index 0000000..5ded045
--- /dev/null
+++ b/src/game/content/kinds/crafts.ts
@@ -0,0 +1,39 @@
+/** Crafts: the workshops that turn wood, ore, and wool into planks, tools, cloth, and furniture. */
+import { free, type Kinds } from "./kind.ts"
+
+export const crafts = {
+ sawmill: {
+ id: "sawmill", title: "Sawmill", blurb: "saws wood into planks",
+ category: "crafts", size: 2, half: 12, stories: 1, roof: "flat", bays: 2, window: 6, topper: "chimney",
+ cost: { coins: 100, materials: { planks: 2, stone: 2 } }, upkeep: 6, workers: 2, crew: "citizens", unlock: free, buildable: true,
+ recipe: { input: "wood", inputs: 1, output: "planks", batch: 1, seconds: 5 }, holds: { accepts: ["wood", "planks"], cap: 8 }, carriers: 2,
+ wear: 60, appeal: { value: -4, reach: 3 }
+ },
+ smithy: {
+ id: "smithy", title: "Smithy", blurb: "forges ore into tools",
+ category: "crafts", size: 2, half: 12, stories: 1, roof: "flat", bays: 2, window: 6, topper: "chimney",
+ cost: { coins: 250, materials: { planks: 4, stone: 6 } }, upkeep: 12, workers: 3, crew: "citizens", unlock: { residents: 0, citizens: 10 }, buildable: true,
+ recipe: { input: "ore", inputs: 1, output: "tools", batch: 1, seconds: 10 }, holds: { accepts: ["ore", "tools"], cap: 8 }, carriers: 2,
+ hot: true, appeal: { value: -8, reach: 4 }
+ },
+ sheep: {
+ id: "sheep", title: "Sheep farm", blurb: "shears sheep for wool",
+ category: "crafts", size: 3, half: 12, stories: 1, roof: "gable", bays: 2, window: 4, topper: "none",
+ cost: { coins: 100, materials: { planks: 4 } }, upkeep: 5, workers: 2, crew: "settlers", unlock: { residents: 40, citizens: 0 }, buildable: true,
+ recipe: { input: null, inputs: 0, output: "wool", batch: 1, seconds: 6 }, carriers: 2, appeal: { value: -2, reach: 2 }
+ },
+ weaver: {
+ id: "weaver", title: "Weaver", blurb: "weaves wool into cloth",
+ category: "crafts", size: 2, half: 12, stories: 1, roof: "flat", bays: 2, window: 6, topper: "none",
+ cost: { coins: 150, materials: { planks: 4, stone: 2, tools: 1 } }, upkeep: 8, workers: 2, crew: "citizens", unlock: { residents: 40, citizens: 0 }, buildable: true,
+ recipe: { input: "wool", inputs: 1, output: "cloth", batch: 1, seconds: 6 }, holds: { accepts: ["wool", "cloth"], cap: 8 }, carriers: 2,
+ wear: 60, appeal: { value: -2, reach: 2 }
+ },
+ carpenter: {
+ id: "carpenter", title: "Carpenter", blurb: "makes furniture from planks, for the burghers' townhouses",
+ category: "crafts", size: 2, half: 12, stories: 1, roof: "gable", bays: 2, window: 4, topper: "chimney",
+ cost: { coins: 160, materials: { planks: 4, stone: 2, tools: 1 } }, upkeep: 8, workers: 2, crew: "citizens", unlock: { residents: 0, citizens: 20 }, buildable: true,
+ recipe: { input: "planks", inputs: 2, output: "furniture", batch: 1, seconds: 8 }, holds: { accepts: ["planks", "furniture"], cap: 8 }, carriers: 2,
+ wear: 60, appeal: { value: -2, reach: 2 }
+ }
+} satisfies Kinds
diff --git a/src/game/content/kinds/food.ts b/src/game/content/kinds/food.ts
new file mode 100644
index 0000000..8f7dd72
--- /dev/null
+++ b/src/game/content/kinds/food.ts
@@ -0,0 +1,48 @@
+/** Food: the catch and the harvest, and the workshops that smoke, grind, and bake them. */
+import { free, type Kinds } from "./kind.ts"
+
+export const food = {
+ fishery: {
+ id: "fishery", title: "Fishery", blurb: "catches fish; needs its own stretch of water within two cells",
+ category: "food", size: 2, half: 10, stories: 1, roof: "gable", bays: 2, window: 4, topper: "none",
+ cost: { coins: 60, materials: { planks: 3 } }, upkeep: 5, workers: 2, crew: "settlers", unlock: free, buildable: true,
+ recipe: { input: null, inputs: 0, output: "fish", batch: 1, seconds: 4 }, gathers: { source: "water", radius: 2 }, carriers: 2,
+ appeal: { value: -2, reach: 2 }
+ },
+ smokehouse: {
+ id: "smokehouse", title: "Smokehouse", blurb: "smokes fish, which then keeps all winter",
+ category: "food", size: 2, half: 10, stories: 1, roof: "gable", bays: 2, window: 4, topper: "chimney",
+ cost: { coins: 90, materials: { planks: 4, stone: 1 } }, upkeep: 4, workers: 2, crew: "settlers", unlock: { residents: 20, citizens: 0 }, buildable: true,
+ recipe: { input: "fish", inputs: 1, output: "smoked", batch: 1, seconds: 5 }, holds: { accepts: ["fish", "smoked"], cap: 8 }, carriers: 2,
+ wear: 60, hot: true, appeal: { value: -4, reach: 3 }
+ },
+ farm: {
+ id: "farm", title: "Farm", blurb: "sows fields around it and harvests the wheat",
+ category: "food", size: 3, half: 12, stories: 1, roof: "gable", bays: 2, window: 4, topper: "none",
+ cost: { coins: 120, materials: { planks: 4 } }, upkeep: 5, workers: 2, crew: "settlers", unlock: { residents: 60, citizens: 0 }, buildable: true,
+ recipe: { input: null, inputs: 0, output: "wheat", batch: 1, seconds: 4 }, gathers: { source: "field", radius: 2 },
+ plants: { what: "field", radius: 2, seconds: 3, max: 8 }, carriers: 2, appeal: { value: -2, reach: 2 },
+ upgrade: {
+ title: "Estate", blurb: "a barn and a dovecote: a third hand reaps the same fields half again as fast", rank: 2,
+ cost: { coins: 250, materials: { planks: 8, stone: 6, tools: 1 } }, upkeep: 7, workers: 3, seconds: 2.5
+ }
+ },
+ mill: {
+ id: "mill", title: "Mill", blurb: "grinds wheat into flour",
+ category: "food", size: 2, half: 8, stories: 2, roof: "flat", bays: 2, window: 4, topper: "sails",
+ cost: { coins: 150, materials: { planks: 6, stone: 2, tools: 1 } }, upkeep: 8, workers: 2, crew: "citizens", unlock: { residents: 60, citizens: 0 }, buildable: true,
+ recipe: { input: "wheat", inputs: 1, output: "flour", batch: 1, seconds: 6 }, holds: { accepts: ["wheat", "flour"], cap: 8 }, carriers: 2,
+ wear: 60, appeal: { value: -4, reach: 3 }
+ },
+ bakery: {
+ id: "bakery", title: "Bakery", blurb: "bakes flour into bread",
+ category: "food", size: 2, half: 12, stories: 1, roof: "flat", bays: 2, window: 6, topper: "chimney",
+ cost: { coins: 150, materials: { planks: 4, stone: 4, tools: 1 } }, upkeep: 8, workers: 2, crew: "citizens", unlock: { residents: 60, citizens: 0 }, buildable: true,
+ recipe: { input: "flour", inputs: 1, output: "bread", batch: 2, seconds: 6 }, holds: { accepts: ["flour", "bread"], cap: 8 }, carriers: 2,
+ wear: 60, hot: true, appeal: { value: -4, reach: 3 },
+ upgrade: {
+ title: "Ovenworks", blurb: "a second oven and a third baker: bread every four seconds instead of six", rank: 2,
+ cost: { coins: 300, materials: { planks: 6, stone: 10, tools: 2 } }, upkeep: 13, workers: 3, seconds: 4
+ }
+ }
+} satisfies Kinds
diff --git a/src/game/content/kinds/gathering.ts b/src/game/content/kinds/gathering.ts
new file mode 100644
index 0000000..5988d20
--- /dev/null
+++ b/src/game/content/kinds/gathering.ts
@@ -0,0 +1,36 @@
+/** Gathering: what the town takes from the land around it, and the forester who plants trees back. */
+import { free, type Kinds } from "./kind.ts"
+
+export const gathering = {
+ lumberjack: {
+ id: "lumberjack", title: "Lumberjack", blurb: "fells grown trees nearby for wood",
+ category: "gathering", size: 2, half: 10, stories: 1, roof: "gable", bays: 2, window: 4, topper: "none",
+ cost: { coins: 50, materials: { planks: 2 } }, upkeep: 3, workers: 2, crew: "settlers", unlock: free, buildable: true,
+ recipe: { input: null, inputs: 0, output: "wood", batch: 1, seconds: 6 }, gathers: { source: "tree", radius: 4 }, carriers: 2,
+ wear: 60, appeal: { value: -2, reach: 2 }
+ },
+ forester: {
+ id: "forester", title: "Forester", blurb: "plants trees on free ground nearby",
+ category: "gathering", size: 2, half: 9, stories: 1, roof: "gable", bays: 2, window: 4, topper: "none",
+ cost: { coins: 40, materials: { planks: 2 } }, upkeep: 2, workers: 1, crew: "settlers", unlock: free, buildable: true,
+ plants: { what: "tree", radius: 3, seconds: 6, max: 20 }
+ },
+ quarry: {
+ id: "quarry", title: "Quarry", blurb: "cuts stone from rocks nearby",
+ category: "gathering", size: 2, half: 10, stories: 1, roof: "flat", bays: 2, window: 6, topper: "none",
+ cost: { coins: 80, materials: { planks: 4 } }, upkeep: 5, workers: 3, crew: "settlers", unlock: free, buildable: true,
+ recipe: { input: null, inputs: 0, output: "stone", batch: 1, seconds: 8 }, gathers: { source: "stone", radius: 3 }, carriers: 2,
+ wear: 50, dusty: true, appeal: { value: -8, reach: 4 },
+ upgrade: {
+ title: "Masonry", blurb: "a derrick and a mason's shed: it goes on cutting worked-out rock at full pace, not a third of it; a dustier neighbour", rank: 2,
+ cost: { coins: 200, materials: { planks: 6, tools: 2 } }, upkeep: 8, deep: true, appeal: { value: -10, reach: 4 }
+ }
+ },
+ mine: {
+ id: "mine", title: "Mine", blurb: "digs ore from a deposit nearby",
+ category: "gathering", size: 2, half: 10, stories: 1, roof: "flat", bays: 2, window: 6, topper: "chimney",
+ cost: { coins: 200, materials: { planks: 6, stone: 4 } }, upkeep: 6, workers: 4, crew: "settlers", unlock: { residents: 0, citizens: 10 }, buildable: true,
+ recipe: { input: null, inputs: 0, output: "ore", batch: 1, seconds: 10 }, gathers: { source: "ore", radius: 3 }, carriers: 2,
+ wear: 50, dusty: true, appeal: { value: -8, reach: 4 }
+ }
+} satisfies Kinds
diff --git a/src/game/content/kinds/index.ts b/src/game/content/kinds/index.ts
new file mode 100644
index 0000000..bf0b98e
--- /dev/null
+++ b/src/game/content/kinds/index.ts
@@ -0,0 +1,36 @@
+/**
+ * Every building kind, gathered from its category's file into the one
+ * table the game reads. A new kind is added to `kindIds` and to its
+ * category's file; `all` and `kinds` below then refuse to compile until
+ * it is in one of those files and listed here too.
+ */
+import { crafts } from "./crafts.ts"
+import { food } from "./food.ts"
+import { gathering } from "./gathering.ts"
+import type { Kind, KindId } from "./kind.ts"
+import { services } from "./services.ts"
+import { storage } from "./storage.ts"
+import { townHall } from "./townhall.ts"
+
+export * from "./kind.ts"
+
+/** Every category's kinds together: each id must be in one of the files. */
+const all = { ...townHall, ...storage, ...gathering, ...crafts, ...food, ...services } satisfies Record<KindId, Kind>
+const {
+ townhall, warehouse, granary, lumberjack, forester, quarry, mine, fishery, smokehouse, sawmill, smithy,
+ farm, mill, bakery, sheep, weaver, carpenter, market, chapel, firewatch, healer, hospital, watchhouse, builder
+} = all
+
+// Each flat-roofed kind's `half` splits evenly into its bays (2 × half / bays
+// is whole), so every window and topper sits on whole units. Listed in the
+// order the kinds have always been in (what `Object.keys` sees, and so what
+// the rules and a replay see), not by category.
+export const kinds: Readonly<Record<KindId, Kind>> = {
+ townhall, warehouse, granary, lumberjack, forester, quarry, mine, fishery, smokehouse, sawmill, smithy,
+ farm, mill, bakery, sheep, weaver, carpenter, market, chapel, firewatch, healer, hospital, watchhouse, builder
+}
+
+export const kindOrder: ReadonlyArray<KindId> = [
+ "warehouse", "granary", "lumberjack", "forester", "quarry", "mine", "sawmill", "smithy", "sheep", "weaver", "carpenter",
+ "fishery", "smokehouse", "farm", "mill", "bakery", "market", "chapel", "firewatch", "healer", "hospital", "watchhouse", "builder"
+]
diff --git a/src/game/content/kinds/kind.ts b/src/game/content/kinds/kind.ts
new file mode 100644
index 0000000..a087a61
--- /dev/null
+++ b/src/game/content/kinds/kind.ts
@@ -0,0 +1,184 @@
+/**
+ * What a building kind is: its ids, categories, and roles, the shape of its
+ * upgrades, and how a building reads its kind once upgraded. The kinds
+ * themselves live one file per category beside this one.
+ */
+import { Clock } from "@typeonce/ritmo"
+import { step } from "../clock.ts"
+import type { GoodId } from "../goods.ts"
+
+export type Category = "storage" | "gathering" | "crafts" | "food" | "services"
+export const categoryOrder: ReadonlyArray<Category> = ["storage", "gathering", "crafts", "food", "services"]
+
+/** Awnings are coloured by what a building is for. */
+export const categoryColor: Readonly<Record<Category, number>> = {
+ storage: 0x8a58a8,
+ gathering: 0x6e8f36,
+ crafts: 0xd27a34,
+ food: 0xd6ae2e,
+ services: 0x3d6db5
+}
+export const homeColor = 0xc4523f
+
+/** What a gatherer takes from the land around it. */
+export type Source = "tree" | "stone" | "ore" | "field" | "water"
+export const serviceIds = ["goods", "faith", "fire", "health", "order", "repair"] as const
+export type ServiceId = (typeof serviceIds)[number]
+/** Native crews: surplus citizens can also do rough work; settlers learn skilled jobs as apprentices. */
+export type Crew = "settlers" | "citizens"
+
+export type Topper = "none" | "chimney" | "flag" | "cupola" | "sails" | "crates"
+
+export const kindIds = [
+ "townhall", "warehouse", "lumberjack", "forester", "quarry", "mine", "fishery", "sawmill",
+ "smithy", "farm", "mill", "bakery", "sheep", "weaver", "market", "chapel",
+ "granary", "smokehouse", "firewatch", "healer", "hospital", "watchhouse", "builder", "carpenter"
+] as const
+export type KindId = (typeof kindIds)[number]
+
+export interface Kind {
+ readonly id: KindId
+ readonly title: string
+ readonly blurb: string
+ readonly category: Category
+ /** Cells a side. */
+ readonly size: 1 | 2 | 3
+ // ── Look (see `art.ts`) ──
+ /** Half the building's width, in units: its walls stand this far from its centre. */
+ readonly half: number
+ readonly stories: 1 | 2
+ readonly roof: "flat" | "gable"
+ /** A flat roof is split into bays × bays squares, each `window` units across but the topper's. */
+ readonly bays: 2 | 3
+ readonly window: number
+ readonly topper: Topper
+ // ── Economy ──
+ readonly cost: { readonly coins: number; readonly materials: Partial<Record<GoodId, number>> }
+ /** Coins a minute while it stands. */
+ readonly upkeep: number
+ readonly workers: number
+ /** Who works it: settlers, or citizens (settlers stand in as apprentices, at a slower pace). */
+ readonly crew: Crew
+ /** Residents (and of them citizens) the town needs before it can be built. */
+ readonly unlock: { readonly residents: number; readonly citizens: number }
+ /** In the build menu (the town hall is not). */
+ readonly buildable: boolean
+ // ── Roles: each one present becomes a component ──
+ /** Turns `inputs` of `input` (or nothing, or the land) into `batch` of `output` per job. */
+ readonly recipe?: { readonly input: GoodId | null; readonly inputs: number; readonly output: GoodId; readonly batch: number; readonly seconds: number }
+ /** A gatherer's job needs this within `radius` cells of its footprint. */
+ readonly gathers?: { readonly source: Source; readonly radius: number }
+ /** Plants trees or fields within `radius`, one every `seconds`, up to `max` at once. */
+ readonly plants?: { readonly what: "tree" | "field"; readonly radius: number; readonly seconds: number; readonly max: number }
+ /** Holds goods: every good (storage), or just some (a market). */
+ readonly holds?: { readonly accepts: ReadonlyArray<GoodId> | "all"; readonly cap: number }
+ /** Carriers it sends out at once. */
+ readonly carriers?: number
+ /** Sends a walker down the roads every `seconds`, `range` cells out. */
+ readonly service?: { readonly service: ServiceId; readonly seconds: number; readonly range: number }
+ // ── Its neighbourhood ──
+ /** What it does to the desirability of the cells around it, fading out to `reach` cells (see `appeal.ts`). */
+ readonly appeal?: { readonly value: number; readonly reach: number; readonly full?: number }
+ /** Uses up a tool every `wear` jobs, and works at half pace without one. */
+ readonly wear?: number
+ /** Ovens and forges: a fire risk to itself and to homes beside it. */
+ readonly hot?: boolean
+ /** Dust: a health risk to homes nearby. */
+ readonly dusty?: boolean
+ /** A storage that keeps food this many times longer. */
+ readonly keeps?: number
+ /**
+ * What it becomes when upgraded where it stands, once the town has reached
+ * `rank` (see `ranks`), and (`next`) what that becomes in turn: its coins
+ * paid when the works begin, its materials carried to it while it goes on
+ * working (see `Works`). Whatever an upgrade gives replaces the kind's own.
+ */
+ readonly upgrade?: Upgrade
+}
+
+/**
+ * Some of the kinds, as one category's file lists them: each under its own
+ * id (`kinds/index.ts` demands every id be listed once, across the files).
+ */
+export type Kinds = { readonly [Id in KindId]?: Kind & { readonly id: Id } }
+
+/** A building upgraded where it stands (see `Kind.upgrade`): every field but the first five is what changes. */
+export interface Upgrade {
+ readonly title: string
+ readonly blurb: string
+ readonly rank: number
+ readonly cost: { readonly coins: number; readonly materials: Partial<Record<GoodId, number>> }
+ readonly upkeep: number
+ readonly service?: { readonly seconds: number; readonly range: number }
+ readonly appeal?: { readonly value: number; readonly reach: number; readonly full?: number }
+ /** Workers it takes, and seconds a job (a recipe's). */
+ readonly workers?: number
+ readonly seconds?: number
+ /** What its shelves hold of each good, and the carriers it sends at once. */
+ readonly cap?: number
+ readonly carriers?: number
+ /** Firefighters it sends out at once (a fire watch's). */
+ readonly crews?: number
+ /** It cuts worked faces at full pace, not a third of it (a quarry's). */
+ readonly deep?: boolean
+ /** The share of the town hall's administration it saves (the town hall's). */
+ readonly admin?: number
+ /** The upgrade after this one. */
+ readonly next?: Upgrade
+}
+
+/** Upgrades a building has had: none, one, or (a town hall) two. */
+export type Level = 0 | 1 | 2
+
+/** The upgrade a building at `level` stands as (`undefined`: none), and the one it could have next. */
+export const upgradeAt = (kind: Pick<Kind, "upgrade">, level: number): Upgrade | undefined =>
+ level <= 0 ? undefined : level === 1 ? kind.upgrade : kind.upgrade?.next
+export const nextUpgrade = (kind: Pick<Kind, "upgrade">, level: number): Upgrade | undefined => upgradeAt(kind, level + 1)
+
+/**
+ * A kind as a building of it stands once upgraded to `level`: its upkeep,
+ * crew, pace, shelves, carriers, walker, and desirability those of its
+ * upgrades. Everything that works a building reads it from here.
+ */
+export const asUpgraded = <K extends Kind>(kind: K, level: number): K => {
+ let k: Kind = kind
+ for (let l = 1; l <= level; l++) {
+ const up = upgradeAt(kind, l)
+ if (!up) break
+ k = {
+ ...k,
+ upkeep: up.upkeep,
+ workers: up.workers ?? k.workers,
+ ...(k.recipe && up.seconds ? { recipe: { ...k.recipe, seconds: up.seconds } } : {}),
+ ...(k.holds && up.cap ? { holds: { ...k.holds, cap: up.cap } } : {}),
+ ...(up.carriers ? { carriers: up.carriers } : {}),
+ ...(k.service && up.service ? { service: { ...k.service, ...up.service } } : {}),
+ ...(up.appeal ? { appeal: up.appeal } : {})
+ }
+ }
+ return k as K
+}
+
+/** Steps of building work an upgrade takes for each good it is made of: a market hall half a minute, a city hall four. */
+export const WORKS_TICKS = Clock.steps(Clock.duration(step, 1.5))
+/** The steps of work an upgrade of `total` goods takes. */
+export const worksNeeded = (total: number, rules: { readonly worksTicks: number } = { worksTicks: WORKS_TICKS }) => Math.max(1, total) * rules.worksTicks
+
+/** Coins a minute a building of a kind costs at its level of upgrades. */
+export const upkeepOf = (kind: Pick<Kind, "upkeep" | "upgrade">, level: number): number => upgradeAt(kind, level)?.upkeep ?? kind.upkeep
+
+/** What a building of a kind cost all told, its upgrades included: what pulling it down gives part of back. */
+export const builtCost = (kind: Pick<Kind, "cost" | "upgrade">, level: number): Kind["cost"] => {
+ let coins = kind.cost.coins
+ const materials: Partial<Record<GoodId, number>> = { ...kind.cost.materials }
+ for (let l = 1; l <= level; l++) {
+ const up = upgradeAt(kind, l)
+ if (!up) break
+ coins += up.cost.coins
+ for (const [g, n] of Object.entries(up.cost.materials) as Array<[GoodId, number]>) materials[g] = (materials[g] ?? 0) + n
+ }
+ return { coins, materials }
+}
+
+/** No residents needed: what most kinds and park pieces unlock at. */
+export const free = { residents: 0, citizens: 0 }
diff --git a/src/game/content/kinds/services.ts b/src/game/content/kinds/services.ts
new file mode 100644
index 0000000..40eb7d5
--- /dev/null
+++ b/src/game/content/kinds/services.ts
@@ -0,0 +1,63 @@
+/** Services: the buildings that send a walker down the roads to the homes along the way. */
+import { free, type Kinds } from "./kind.ts"
+
+export const services = {
+ market: {
+ id: "market", title: "Market", blurb: "a walker carries fish, bread, cloth, and furniture to the homes it passes",
+ category: "services", size: 2, half: 12, stories: 1, roof: "flat", bays: 2, window: 6, topper: "flag",
+ cost: { coins: 120, materials: { planks: 6, stone: 2 } }, upkeep: 6, workers: 2, crew: "citizens", unlock: free, buildable: true,
+ holds: { accepts: ["fish", "smoked", "bread", "cloth", "furniture"], cap: 12 },
+ service: { service: "goods", seconds: 6, range: 18 }, appeal: { value: 2, reach: 3, full: 2 },
+ upgrade: {
+ title: "Market hall", blurb: "a covered hall: its walker goes further, more often, and the street around it is finer", rank: 2,
+ cost: { coins: 400, materials: { planks: 6, stone: 12, tools: 2 } }, upkeep: 12,
+ service: { seconds: 4, range: 26 }, appeal: { value: 4, reach: 4, full: 2 }
+ }
+ },
+ chapel: {
+ id: "chapel", title: "Chapel", blurb: "a walker brings faith to the homes it passes",
+ category: "services", size: 2, half: 12, stories: 2, roof: "flat", bays: 2, window: 6, topper: "cupola",
+ cost: { coins: 200, materials: { planks: 6, stone: 6 } }, upkeep: 10, workers: 1, crew: "citizens", unlock: { residents: 40, citizens: 0 }, buildable: true,
+ service: { service: "faith", seconds: 8, range: 22 }, appeal: { value: 4, reach: 4, full: 2 },
+ upgrade: {
+ title: "Church", blurb: "a church with a tower: its priest walks further, more often, and the streets around it are the finest", rank: 2,
+ cost: { coins: 700, materials: { planks: 8, stone: 20, tools: 3 } }, upkeep: 18,
+ service: { seconds: 6, range: 30 }, appeal: { value: 6, reach: 5, full: 3 }
+ }
+ },
+ firewatch: {
+ id: "firewatch", title: "Fire watch", blurb: "a watchman checks homes and workshops along the way for fire; firefighters run to any blaze",
+ category: "services", size: 2, half: 9, stories: 1, roof: "gable", bays: 2, window: 4, topper: "none",
+ cost: { coins: 70, materials: { planks: 3 } }, upkeep: 3, workers: 2, crew: "settlers", unlock: free, buildable: true,
+ service: { service: "fire", seconds: 7, range: 30 },
+ upgrade: {
+ title: "Fire brigade", blurb: "a bell tower and a pump: its watchman walks further, more often, and four firefighters run instead of two", rank: 2,
+ cost: { coins: 200, materials: { planks: 6, stone: 6, tools: 1 } }, upkeep: 5, service: { seconds: 5, range: 36 }, crews: 4
+ }
+ },
+ healer: {
+ id: "healer", title: "Healer", blurb: "a physician calls on the homes along the way and cures the sick",
+ category: "services", size: 2, half: 10, stories: 1, roof: "flat", bays: 2, window: 4, topper: "none",
+ cost: { coins: 110, materials: { planks: 4, stone: 2 } }, upkeep: 4, workers: 1, crew: "citizens", unlock: { residents: 30, citizens: 0 }, buildable: true,
+ service: { service: "health", seconds: 8, range: 30 }, appeal: { value: 1, reach: 2 }
+ },
+ hospital: {
+ id: "hospital", title: "Hospital", blurb: "physicians call more often and walk further",
+ category: "services", size: 3, half: 16, stories: 2, roof: "flat", bays: 2, window: 6, topper: "cupola",
+ cost: { coins: 400, materials: { planks: 10, stone: 10, tools: 2 } }, upkeep: 10, workers: 4, crew: "citizens", unlock: { residents: 0, citizens: 40 }, buildable: true,
+ service: { service: "health", seconds: 4, range: 40 }, appeal: { value: 2, reach: 3, full: 2 }
+ },
+ watchhouse: {
+ id: "watchhouse", title: "Watch house", blurb: "a constable walks the streets, keeping order in the homes along the way",
+ category: "services", size: 2, half: 10, stories: 1, roof: "flat", bays: 2, window: 4, topper: "flag",
+ cost: { coins: 100, materials: { planks: 4, stone: 2 } }, upkeep: 3, workers: 2, crew: "settlers", unlock: { residents: 40, citizens: 0 }, buildable: true,
+ service: { service: "order", seconds: 8, range: 30 }
+ },
+ builder: {
+ id: "builder", title: "Builder's yard", blurb: "a builder mends the homes and buildings along the way, with planks and stone",
+ category: "services", size: 2, half: 10, stories: 1, roof: "gable", bays: 2, window: 4, topper: "none",
+ cost: { coins: 90, materials: { planks: 4 } }, upkeep: 3, workers: 2, crew: "settlers", unlock: free, buildable: true,
+ holds: { accepts: ["planks", "stone"], cap: 6 },
+ service: { service: "repair", seconds: 8, range: 20 }, appeal: { value: -2, reach: 2 }
+ }
+} satisfies Kinds
diff --git a/src/game/content/kinds/storage.ts b/src/game/content/kinds/storage.ts
new file mode 100644
index 0000000..46ef9d7
--- /dev/null
+++ b/src/game/content/kinds/storage.ts
@@ -0,0 +1,21 @@
+/** Storage: where the town keeps its goods, nearer where they are made and used. */
+import { free, type Kinds } from "./kind.ts"
+
+export const storage = {
+ warehouse: {
+ id: "warehouse", title: "Warehouse", blurb: "stores goods nearer where they are made and used",
+ category: "storage", size: 3, half: 18, stories: 1, roof: "flat", bays: 3, window: 6, topper: "crates",
+ cost: { coins: 150, materials: { planks: 8, stone: 4 } }, upkeep: 6, workers: 2, crew: "settlers", unlock: free, buildable: true,
+ holds: { accepts: "all", cap: 50 }, carriers: 4, appeal: { value: -2, reach: 2 },
+ upgrade: {
+ title: "Depot", blurb: "a loading yard and a hoist: it holds more than twice as much, and sends two more carriers", rank: 1,
+ cost: { coins: 200, materials: { planks: 10, stone: 10 } }, upkeep: 10, cap: 120, carriers: 6
+ }
+ },
+ granary: {
+ id: "granary", title: "Granary", blurb: "stores food, and keeps fish and bread five times as long",
+ category: "storage", size: 2, half: 11, stories: 2, roof: "flat", bays: 2, window: 4, topper: "none",
+ cost: { coins: 120, materials: { planks: 6, stone: 2 } }, upkeep: 4, workers: 1, crew: "settlers", unlock: { residents: 20, citizens: 0 }, buildable: true,
+ holds: { accepts: ["fish", "smoked", "bread", "wheat", "flour"], cap: 60 }, carriers: 3, keeps: 5, appeal: { value: -2, reach: 2 }
+ }
+} satisfies Kinds
diff --git a/src/game/content/kinds/townhall.ts b/src/game/content/kinds/townhall.ts
new file mode 100644
index 0000000..a540ddc
--- /dev/null
+++ b/src/game/content/kinds/townhall.ts
@@ -0,0 +1,22 @@
+/** The town hall: the heart of the town, founded with it and never built. */
+import { free, type Kinds } from "./kind.ts"
+
+export const townHall = {
+ townhall: {
+ id: "townhall", title: "Town hall", blurb: "the heart of the town: storage, taxes, and a walker with provisions",
+ category: "storage", size: 3, half: 20, stories: 2, roof: "flat", bays: 2, window: 8, topper: "flag",
+ cost: { coins: 0, materials: {} }, upkeep: 0, workers: 0, crew: "settlers", unlock: free, buildable: false,
+ holds: { accepts: "all", cap: 100 }, carriers: 6,
+ service: { service: "goods", seconds: 8, range: 20 }, appeal: { value: 4, reach: 4, full: 2 },
+ upgrade: {
+ title: "Guildhall", blurb: "the town hall with a clock tower: it holds twice as much, sends more carriers, its walker goes further, and it runs the town for a tenth less", rank: 1,
+ cost: { coins: 500, materials: { planks: 30, stone: 40, tools: 6 } }, upkeep: 8,
+ cap: 200, carriers: 8, service: { seconds: 6, range: 26 }, appeal: { value: 6, reach: 5, full: 2 }, admin: 0.1,
+ next: {
+ title: "City hall", blurb: "a domed seat of the city: it holds the most, sends the most carriers, walks furthest, and runs the city for a fifth less", rank: 2,
+ cost: { coins: 1200, materials: { planks: 50, stone: 80, tools: 15, cloth: 20 } }, upkeep: 16,
+ cap: 300, carriers: 10, service: { seconds: 5, range: 32 }, appeal: { value: 8, reach: 6, full: 3 }, admin: 0.2
+ }
+ }
+ }
+} satisfies Kinds
diff --git a/src/game/content/lands.ts b/src/game/content/lands.ts
new file mode 100644
index 0000000..4db1f97
--- /dev/null
+++ b/src/game/content/lands.ts
@@ -0,0 +1,116 @@
+/**
+ * The land: the charter a new town is founded on (its size, its land, its
+ * term), what the land yields and how fast it grows back, and its winters.
+ */
+import { Clock } from "@typeonce/ritmo"
+import { step } from "./clock.ts"
+import { amounts, type Amounts } from "./goods.ts"
+
+/** Trees and fields are ready to harvest once this grown. */
+export const GROWN = { tree: Clock.steps(Clock.duration(step, 40)), field: Clock.steps(Clock.duration(step, 20)) }
+/** The most a rock holds (see `lands` for how much each starts with). */
+export const ROCK_AMOUNT = 40
+/**
+ * A rock quarried down to nothing stays as a worked face: it gives one more
+ * stone (or ore) this often, so a quarry or mine beside it keeps going at
+ * about a third of its pace instead of stopping for good.
+ */
+export const FACE_TICKS = Clock.steps(Clock.duration(step, 90))
+/**
+ * A cell of water fished rests this long before it gives another catch,
+ * so a fishery needs a good stretch of shore to itself to work at full
+ * pace, and fisheries crowded on one lake share its fish.
+ */
+export const RESTOCK_TICKS = Clock.steps(Clock.duration(step, 40))
+
+// ── The charter: what a new town is founded on ────────────────────────────
+
+export const sizeIds = ["small", "medium", "large"] as const
+export type SizeId = (typeof sizeIds)[number]
+export const landIds = ["rich", "fair", "harsh"] as const
+export type LandId = (typeof landIds)[number]
+/** How long a term in office runs, in minutes of game time. */
+export const TERMS = [45, 60, 90] as const
+
+/**
+ * Sizes of land: its rough radius in cells (the coast wanders in and out of
+ * it, with capes reaching further), and what the town must reach to be
+ * a town (see `ranks`: a village needs less of both, a city more): its
+ * residents, and its income, coins a minute after upkeep and
+ * administration. Income, not coins held: a treasury is for spending.
+ */
+export const sizes: Readonly<Record<SizeId, {
+ readonly title: string
+ readonly radius: number
+ readonly goal: { readonly residents: number; readonly income: number }
+}>> = {
+ small: { title: "small", radius: 14, goal: { residents: 180, income: 100 } },
+ medium: { title: "medium", radius: 19, goal: { residents: 320, income: 150 } },
+ large: { title: "large", radius: 25, goal: { residents: 520, income: 200 } }
+}
+
+/**
+ * How generous the land is: forests, outcrops of stone, deposits of ore
+ * (each per thousand cells of land), how much each rock holds, lakes, and
+ * what the town starts with.
+ */
+export const lands: Readonly<Record<LandId, {
+ readonly title: string
+ readonly blurb: string
+ readonly forests: number
+ readonly stone: number
+ readonly ore: number
+ readonly rock: number
+ readonly lakes: number
+ readonly coins: number
+ readonly stock: Amounts
+}>> = {
+ rich: {
+ title: "rich", blurb: "deep forests, plenty of stone and ore, two lakes, a full treasury",
+ forests: 7, stone: 4.5, ore: 3, rock: 40, lakes: 2, coins: 1250,
+ stock: amounts({ wood: 15, planks: 50, stone: 24, tools: 10, fish: 30 })
+ },
+ fair: {
+ title: "fair", blurb: "enough of everything, if it is not wasted",
+ forests: 5.5, stone: 3, ore: 2, rock: 32, lakes: 2, coins: 1100,
+ stock: amounts({ wood: 10, planks: 40, stone: 16, tools: 10, fish: 20 })
+ },
+ harsh: {
+ title: "harsh", blurb: "thin woods, little stone, one deposit of ore, one lake",
+ forests: 4, stone: 2, ore: 1, rock: 24, lakes: 1, coins: 950,
+ stock: amounts({ wood: 10, planks: 30, stone: 12, tools: 8, fish: 15 })
+ }
+}
+
+export interface CharterValue {
+ readonly size: SizeId
+ readonly term: number
+ readonly land: LandId
+ readonly seed: number
+}
+export const defaultCharter = (seed: number): CharterValue => ({ size: "medium", term: 60, land: "fair", seed })
+
+// ── Seasons ───────────────────────────────────────────────────────────────
+
+/**
+ * Seasons: a term is six years; the last part of each but the first is
+ * winter, when fields do not grow, fisheries catch half as much, and homes
+ * eat faster.
+ */
+export const YEARS_PER_TERM = 6
+export const WINTER_SHARE = 0.3
+
+/**
+ * Each year's winter is mild, normal, or hard, rolled from the seed when the
+ * town is founded (see `Charter.winters`): how much of the year it takes,
+ * what fisheries catch, and whether homes heat (a fire risk).
+ */
+export const winterIds = ["mild", "normal", "hard"] as const
+export type WinterId = (typeof winterIds)[number]
+export const winters: Readonly<Record<WinterId, { readonly title: string; readonly share: number; readonly fishing: number; readonly heating: boolean; readonly chance: number }>> = {
+ mild: { title: "mild", share: WINTER_SHARE, fishing: 0.75, heating: false, chance: 0.3 },
+ normal: { title: "normal", share: WINTER_SHARE, fishing: 0.5, heating: false, chance: 0.45 },
+ hard: { title: "hard", share: WINTER_SHARE * 1.5, fishing: 0.4, heating: true, chance: 0.25 }
+}
+/** The almanac warns of winter this many steps before it comes. */
+export const WINTER_WARNING = Clock.steps(Clock.duration(step, 60))
diff --git a/src/game/content/parks.ts b/src/game/content/parks.ts
new file mode 100644
index 0000000..76ad267
--- /dev/null
+++ b/src/game/content/parks.ts
@@ -0,0 +1,64 @@
+import { free, type Kind } from "./kinds/index.ts"
+
+/**
+ * A park is laid out cell by cell: ground painted on empty land (lawn,
+ * flower beds, gravel paths, a paved square), and on any of its cells one
+ * furnishing (a lamp, a fountain, a statue). Cells of ground that touch
+ * make one park, and the whole park is what the street around it feels
+ * (see `parkSources` in `appeal.ts`): its `beauty` adds up from its
+ * ground, its furnishings, and its entrances (a walk or a square beside a
+ * road), and that is the desirability it gives the cells around it, out to
+ * a reach that grows with its size. Nobody walks through it: it is not a
+ * road.
+ */
+export const groundIds = ["lawn", "flowers", "path", "square"] as const
+export type GroundId = (typeof groundIds)[number]
+export const propIds = ["lamp", "fountain", "statue"] as const
+export type PropId = (typeof propIds)[number]
+
+export interface ParkPiece {
+ readonly title: string
+ readonly blurb: string
+ readonly cost: Kind["cost"]
+ /** Coins a minute. */
+ readonly upkeep: number
+ /** What it adds to its park's beauty. */
+ readonly beauty: number
+ readonly unlock: { readonly residents: number; readonly citizens: number }
+}
+
+export const grounds: Readonly<Record<GroundId, ParkPiece>> = {
+ lawn: { title: "Lawn", blurb: "grass to lay a park out on", cost: { coins: 2, materials: {} }, upkeep: 0.05, beauty: 0.25, unlock: free },
+ flowers: { title: "Flower bed", blurb: "planted borders: prettier than lawn", cost: { coins: 5, materials: {} }, upkeep: 0.15, beauty: 0.75, unlock: free },
+ path: { title: "Gravel path", blurb: "a walk through the park", cost: { coins: 3, materials: {} }, upkeep: 0.05, beauty: 0.25, unlock: free },
+ square: { title: "Paved square", blurb: "stone setts, for a statue or a fountain to stand on", cost: { coins: 3, materials: { stone: 1 } }, upkeep: 0.05, beauty: 0.25, unlock: free }
+}
+
+export const props: Readonly<Record<PropId, ParkPiece>> = {
+ lamp: { title: "Lamp", blurb: "an iron lamp post along the walk", cost: { coins: 12, materials: { tools: 1 } }, upkeep: 0.2, beauty: 1.5, unlock: free },
+ fountain: { title: "Fountain", blurb: "a stone basin of fresh water", cost: { coins: 70, materials: { stone: 3 } }, upkeep: 2, beauty: 4, unlock: { residents: 30, citizens: 0 } },
+ statue: { title: "Statue", blurb: "a founder in stone, the pride of the park", cost: { coins: 160, materials: { stone: 6 } }, upkeep: 3, beauty: 5, unlock: { residents: 0, citizens: 20 } }
+}
+
+/** How a park's beauty adds up (see `parkSources`). */
+export const park = {
+ /** Ground counts for this much beauty at most, however big the park. */
+ groundMost: 4,
+ /** One furnishing counts for every this many whole cells (none on a park of one): a park crowded with benches is no nicer. */
+ cellsPerProp: 2,
+ /** Each furnishing of a kind after the first counts this share of the one before. */
+ repeat: 0.5,
+ /** A walk or a square beside a road is a way in from the street: each adds this, up to `entrances` of them. */
+ entrance: 1.5,
+ entrances: 2,
+ /** The most a park gives the streets around it. */
+ most: 15,
+ /**
+ * Where several parks reach a cell, the finest counts in full and the
+ * others this share of theirs: a street lined with scraps of park is
+ * not a park.
+ */
+ others: 0.5,
+ /** How far it reaches: `reach[0]` cells, and one more for every `reach[1]` cells of park, up to `reach[2]`. */
+ reach: [2, 6, 5] as const
+}
diff --git a/src/game/content/risks.ts b/src/game/content/risks.ts
new file mode 100644
index 0000000..0c9568b
--- /dev/null
+++ b/src/game/content/risks.ts
@@ -0,0 +1,85 @@
+/** Risks: fire, sickness, and disorder in homes and buildings, and the wear that runs them down. */
+import { Clock } from "@typeonce/ritmo"
+import { step } from "./clock.ts"
+
+/**
+ * Every home has three risk meters, 0 → `RISK_MAX`, and every building a
+ * fire meter. Each rises a little every second, faster for the reasons
+ * below (points a second); the matching service walker passing resets it.
+ * Over `warn` a sign goes up over the home; at the top, disaster.
+ */
+export const RISK_MAX = 10_000
+export const risk = {
+ /** Past this, a sign goes up and the map views turn red: half way, so there is time to act. */
+ warn: 5000,
+ /** The three services' walkers keep a burghers' home: its meters must stay under this. */
+ kept: 5000,
+ /** Each home and building rises at its own pace, between these shares of the usual (fixed by where it stands), so a street does not all go up at once. */
+ pace: [0.75, 1.25] as const,
+ fire: {
+ /** Settlers' cottages are wooden. */
+ wooden: 6,
+ stone: 4,
+ building: 2,
+ /** A bakery's oven, a smithy's forge: in itself, and to each home within `reach`. */
+ hot: 10,
+ near: 6,
+ reach: 2,
+ crowded: 3,
+ worn: 6,
+ /** Heating through a hard winter. */
+ winter: 6,
+ /** How long a blaze burns before the house is lost. */
+ burns: Clock.steps(Clock.duration(step, 20)),
+ /** A burning house sets a neighbour alight, each second: this chance, and up to `spread` more for a neighbour at the top of its own meter. */
+ catches: 0.03,
+ spread: 0.12,
+ /** Firefighters a fire watch may have out at once. */
+ crews: 2
+ },
+ health: {
+ base: 3,
+ hungry: 6,
+ crowded: 3,
+ squalid: 4,
+ /** A quarry's or a mine's dust, within `reach`. */
+ dust: 6,
+ reach: 3,
+ /** Still water within two cells. */
+ water: 3,
+ /** How long a sickness lasts if no physician comes; meanwhile the home holds `sickly` as many. */
+ lasts: Clock.steps(Clock.duration(step, 60)),
+ sickly: 0.5,
+ /** Each second, the chance it reaches a home within two cells: raising its risk by `contagion` (a home a physician calls on shrugs it off). */
+ spreads: 0.04,
+ contagion: 3000
+ },
+ order: {
+ base: 3,
+ /** For every 50 points of approval below nothing. */
+ unrest: 8,
+ squalid: 4,
+ /** A home standing half empty. */
+ vacant: 4,
+ /** A burghers' home is worth robbing. */
+ wealth: 3,
+ /** A theft takes this many coins and this share of the treasury, or goods instead when it is empty. */
+ coins: 10,
+ share: 0.02,
+ most: 80,
+ goods: 4,
+ /** After a theft its meter falls only to here; reaching the top again, the home empties and is left derelict. */
+ after: 3000
+ }
+}
+
+/** How well kept a building or home is, 0 → `CONDITION_MAX`. */
+export const CONDITION_MAX = 1000
+export const condition = {
+ /** A point lost every `every` steps: from new to run down in about 33 minutes, and fallen down in 67, unmended. */
+ every: Clock.steps(Clock.duration(step, 4)),
+ /** Below this, a builder mends it as they pass (after about 23 minutes without repair). */
+ mend: 650,
+ /** Below this, it works at half pace, and its fire risk rises. */
+ worn: 500
+}
diff --git a/src/game/content/streets.ts b/src/game/content/streets.ts
new file mode 100644
index 0000000..3b1687e
--- /dev/null
+++ b/src/game/content/streets.ts
@@ -0,0 +1,27 @@
+/** Desirability the land and the town give, and what paving a street costs and does. */
+/**
+ * What the land and the town do to the cells around them, besides the
+ * buildings' own (`Kind.appeal`). Water and woods count once, however many
+ * are near; so do paved streets.
+ */
+export const appeal = {
+ water: { value: 2, reach: 2 },
+ forest: { value: 2, reach: 2 },
+ paved: { value: 1, reach: 1 },
+ ruin: { value: -3, reach: 2 },
+ worn: { value: -2, reach: 1 },
+ /** A citizens' home and a townhouse lift the homes beside them (never themselves), all told up to `homesMost`. */
+ citizens: { value: 1, reach: 1 },
+ burghers: { value: 2, reach: 1 },
+ homesMost: 3,
+ /** Desirability is reckoned this often. */
+ every: 30,
+ /** And kept within these bounds. */
+ floor: -30,
+ ceiling: 40
+}
+
+/** Paving a road cell: coins and stone, the stone taken from storage at once. */
+export const PAVE_COST = { coins: 3, stone: 1 }
+/** Carriers and walkers move this much faster along a paved street (see `Walk`). */
+export const PAVED_PACE = 1.5
diff --git a/src/game/content/text.ts b/src/game/content/text.ts
new file mode 100644
index 0000000..2d4f476
--- /dev/null
+++ b/src/game/content/text.ts
@@ -0,0 +1,8 @@
+/** Content put into words: a cost, a word with its article. */
+import type { Kind } from "./kinds/index.ts"
+
+export const costText = (cost: Kind["cost"]): string =>
+ [cost.coins > 0 ? `${cost.coins} coins` : "", ...Object.entries(cost.materials).map(([g, n]) => `${n} ${n === 1 && g.endsWith("s") ? g.slice(0, -1) : g}`)].filter((s) => s !== "").join(" · ")
+
+/** A word with its article: "a guildhall", "an estate". */
+export const anA = (word: string): string => `${/^[aeiou]/i.test(word) ? "an" : "a"} ${word}`
diff --git a/src/game/content/town.ts b/src/game/content/town.ts
new file mode 100644
index 0000000..dd5c883
--- /dev/null
+++ b/src/game/content/town.ts
@@ -0,0 +1,150 @@
+/**
+ * Running the town: building and collecting, administration, approval,
+ * the crown, the market, the end states, and the ranks the town rises
+ * through.
+ */
+import { Clock } from "@typeonce/ritmo"
+import { step } from "./clock.ts"
+
+/** How long anything takes to go up once its materials are in. */
+export const BUILD_TICKS = Clock.steps(Clock.duration(step, 2.4))
+/** Taxes are collected and upkeep paid this often. */
+export const LEDGER_TICKS = Clock.steps(Clock.duration(step, 10))
+export const ROAD_COST = 2
+
+/** Tax rates the town can set, in percent of the usual. */
+export const TAX_STEPS = [50, 75, 100, 125, 150, 200] as const
+
+/**
+ * Running a town costs more the bigger it gets, and it is reckoned by the
+ * person, not the roof: the town hall's administration costs `perResident`
+ * coins a minute a resident, and a further (residents / `growth`) a
+ * resident. Each more resident costs `perResident` + 2·residents /
+ * `growth`: about half a settler's taxes at 320 residents (a medium
+ * town's goal), and all of them by about 580, so past there a town grows by
+ * finer homes; and a citizens' home of eight costs twice a cottage of
+ * four, so finer homes are not had for nothing either.
+ */
+export const admin = { perResident: 0.125, growth: 490 }
+
+/**
+ * Approval, -100 → +100: where the town's mood is heading, and how fast it
+ * gets there (points every collection). Homes hold more residents when it
+ * is high and fewer when it is low (see `capacity`).
+ */
+export const mood = {
+ base: 10,
+ /** At no needs met to every need met. */
+ needs: [-35, 30] as const,
+ /** Points for each percent the average tax rate is below (or above) 100%. */
+ perTaxPoint: 0.6,
+ debt: -20,
+ /** Per unanswered crown request, while the crown remembers it. */
+ snub: -20,
+ winterHunger: -10,
+ step: 2,
+ /**
+ * A grudge: taxes above `above` percent are remembered. Every collection
+ * adds (rate − above) × `perPoint` tenths of a point to the town's memory,
+ * up to `most`; at or below it the memory fades by `decay` tenths. The
+ * grudge takes that many points off approval, so a term of 200% cannot be
+ * undone by cutting taxes in the last three minutes.
+ */
+ grudge: { above: 125, perPoint: 0.05, decay: 5, most: 300 }
+}
+
+/**
+ * Crown requests: every so often the crown asks for goods within a time.
+ * Requests grow as the term goes on. Sending them earns coins; missing one
+ * costs a fine and the crown's goodwill for a while.
+ */
+export const crown = {
+ /** Requests in a term. */
+ perTerm: 9,
+ /** Share of the gap between requests the town has to answer one. */
+ window: 0.6,
+ /**
+ * How much it asks for: this share of what the town could make of the
+ * good in the time given, from the start of the term to its end.
+ */
+ share: [0.25, 0.6] as const,
+ /** Nor more than this share of what the town's storage holds of one good. */
+ room: 0.6,
+ /** Reward as a multiple of what the goods would fetch from traders, plus a bonus; the fine is the goods' worth plus the bonus. */
+ reward: 1.3,
+ fine: 1,
+ bonus: 25,
+ /** How long the crown remembers a missed request, in minutes. */
+ memory: 4,
+ /** Requests missed in a row before the crown dismisses the mayor. */
+ patience: 3
+}
+
+/**
+ * The market: each good's price moves with what the town trades. Selling
+ * drives it down `perUnit` points a unit, buying up `perBought`. A cheap
+ * price drifts back by a tenth of the gap every collection, a dear one by
+ * only 1/`calms` of it: traders top up a shortfall, but a town that lives
+ * on bought food pays more for it every minute. Buying costs half again
+ * the price.
+ */
+export const market = { floor: 30, ceiling: 250, perUnit: 1, perBought: 3, markup: 1.5, calms: 30 }
+
+/** A paused building pays this share of its upkeep. */
+export const PAUSED_UPKEEP = 0.25
+
+/**
+ * Pulling down a standing building or home: a `fee` of what it cost in
+ * coins, and `back` of its materials (rounded down) carried back into
+ * storage. A site not yet going up is cancelled instead: its coins and
+ * whatever was brought to it come back in full.
+ */
+export const salvage = { fee: 0.1, back: 0.5 }
+
+/** How long each end state's danger has to last, in minutes, before the term ends with it. */
+export const fate = {
+ /** Victory: every goal held this long. */
+ hold: 2,
+ /** Bankruptcy: in debt this long without a break. */
+ debt: 3,
+ /** Revolt: approval at or below `revolt` this long. */
+ revolt: 2,
+ revoltAt: -50,
+ /** Abandonment: residents below this share of their peak, once the peak reached `peak`. */
+ abandon: 0.15,
+ peak: 40,
+ /** The town rank's goals besides residents and coins: a share of them citizens, and approval (see `ranks`). */
+ citizens: 0.3,
+ approval: 15
+}
+
+/**
+ * The town's ranks, from the hamlet it is founded as. It rises to the next
+ * once every goal of that rank has held for `fate.hold` minutes together:
+ * `residents` and `income` (out of debt) as shares of its land's goal
+ * (see `sizes`), a share of the residents `citizens` (those in townhouses
+ * count), a share `burghers`, approval, and (a city) a town hall upgraded
+ * `hall` times, a guildhall. A rank is never lost, and the crown sends
+ * `reward` coins on reaching it. The town rank is the old "complete" town;
+ * nothing ends when a rank is reached.
+ */
+export const ranks: ReadonlyArray<{
+ readonly title: string
+ readonly residents: number
+ readonly income: number
+ readonly citizens: number
+ readonly burghers: number
+ readonly approval: number
+ readonly hall: number
+ readonly reward: number
+}> = [
+ { title: "hamlet", residents: 0, income: 0, citizens: 0, burghers: 0, approval: 0, hall: 0, reward: 0 },
+ { title: "village", residents: 0.35, income: 0.3, citizens: 0.1, burghers: 0, approval: 0, hall: 0, reward: 300 },
+ { title: "town", residents: 1, income: 1, citizens: fate.citizens, burghers: 0, approval: fate.approval, hall: 0, reward: 800 },
+ { title: "city", residents: 1.5, income: 1.5, citizens: 0.5, burghers: 0.15, approval: 25, hall: 1, reward: 1500 }
+]
+/** The rank the old "complete" town is: the goals a balance run plays for. */
+export const TOWN_RANK = 2
+
+/** The town's history: a sample this often. */
+export const HISTORY_TICKS = Clock.steps(Clock.duration(step, 15))
diff --git a/src/render/three/assets/rural.ts b/src/render/three/assets/rural.ts
index d4602de..a6ffdde 100644
--- a/src/render/three/assets/rural.ts
+++ b/src/render/three/assets/rural.ts
@@ -4,8 +4,8 @@ import { Drawing, palette, pale, type Side, type Vertex } from "./primitives.ts"
import { beam, block, iron, post, stone, wood } from "./workshops.ts"
import { human } from "./dimensions.ts"
-export const ruralIds = ["firewatch", "lumberjack", "forester", "farm", "sheep", "smokehouse", "builder", "chapel", "granary"] as const
-export const ruralDoorIds = ["lumberjack", "forester", "farm", "sheep", "smokehouse", "builder", "granary"] as const
+export const ruralIds = ["firewatch", "lumberjack", "forester", "farm", "sheep", "smokehouse", "builder", "chapel", "granary"] as const satisfies ReadonlyArray<KindId>
+export const ruralDoorIds = ["lumberjack", "forester", "farm", "sheep", "smokehouse", "builder", "granary"] as const satisfies ReadonlyArray<KindId>
type RuralDoorId = typeof ruralDoorIds[number]
export const isRuralDoor = (id: KindId): id is RuralDoorId => ruralDoorIds.some(kind => kind === id)
export const ruralNotes: Partial<Record<KindId, string>> = {
diff --git a/src/render/three/assets/trades.ts b/src/render/three/assets/trades.ts
index 6427ce7..d501bbe 100644
--- a/src/render/three/assets/trades.ts
+++ b/src/render/three/assets/trades.ts
@@ -5,7 +5,7 @@ import { Drawing, palette, pale, type Side, type Vertex } from "./primitives.ts"
import type { BuildingOptions } from "./buildings.ts"
import { beam, block, iron, orient, post, roof, stone, wheel, wood, workshopPoint } from "./workshops.ts"
-export const tradeYardIds = ["warehouse", "fishery", "bakery", "weaver"] as const
+export const tradeYardIds = ["warehouse", "fishery", "bakery", "weaver"] as const satisfies ReadonlyArray<KindId>
export type TradeYardId = typeof tradeYardIds[number]
export const isTradeYard = (id: KindId): id is TradeYardId => tradeYardIds.some(kind => kind === id)
export const tradeNotes = {
diff --git a/src/render/three/assets/workshops.ts b/src/render/three/assets/workshops.ts
index e2ec28e..e559907 100644
--- a/src/render/three/assets/workshops.ts
+++ b/src/render/three/assets/workshops.ts
@@ -5,7 +5,7 @@ import { rockOutcrop } from "./land.ts"
import { Drawing, palette, pale, type InkAsset, type Side, type Vertex } from "./primitives.ts"
import type { BuildingOptions } from "./buildings.ts"
-export const workshopIds = ["mine", "smithy", "sawmill"] as const
+export const workshopIds = ["mine", "smithy", "sawmill"] as const satisfies ReadonlyArray<KindId>
export type WorkshopId = typeof workshopIds[number]
export const isWorkshop = (id: KindId): id is WorkshopId => workshopIds.some(kind => kind === id)
export const wood = [0xe9d2a8, 0xd0b58c, 0xb08a5e] as const
diff --git a/tools/balance/provenance.ts b/tools/balance/provenance.ts
index 4d37279..7e19de5 100644
--- a/tools/balance/provenance.ts
+++ b/tools/balance/provenance.ts
@@ -11,10 +11,12 @@ export const fingerprint = (value: unknown) => createHash("sha256").update(JSON.
const sources = (dir: string): Array<string> => readdirSync(dir, { recursive: true, encoding: "utf8" }).filter((f) => f.endsWith(".ts")).map((f) => join(dir, f))
export const provenance = (rules: Rules, scenarios: ReadonlyArray<Scenario>) => {
- const paths = ["src/game/content/index.ts", "src/game/world/grid.ts", "src/game/world/appeal.ts", "tools/balance/catalog.ts", "tools/balance/scenario.ts", "tools/balance/types.ts", ...sources("src/game/rules"), ...sources("src/game/systems"), "src/game/schedule.ts", "src/game/headless.ts", ...readdirSync("tools/balance/model").filter((f) => f.endsWith(".ts")).map((f) => `tools/balance/model/${f}`)].sort()
+ /** Every content module (`content/index.ts` gathers them), in a fixed order. */
+ const content = sources("src/game/content").sort()
+ const paths = [...content, "src/game/world/grid.ts", "src/game/world/appeal.ts", "tools/balance/catalog.ts", "tools/balance/scenario.ts", "tools/balance/types.ts", ...sources("src/game/rules"), ...sources("src/game/systems"), "src/game/schedule.ts", "src/game/headless.ts", ...readdirSync("tools/balance/model").filter((f) => f.endsWith(".ts")).map((f) => `tools/balance/model/${f}`)].sort()
return { modelVersion: 2, referencePr: "https://github.com/SandroMaglione/inkline-town/pull/3", referenceSha: execFileSync("git", ["rev-parse", "HEAD"], { encoding: "utf8" }).trim(), baselineReferenceSha: "9b7ce7336a18f917a10aa6e21ae32cb57af88643",
uncommittedSource: execFileSync("git", ["status", "--porcelain", "--", "src", "scripts", "tools/balance"], { encoding: "utf8" }).trim().length > 0,
- rulesSha256: fingerprint(rules), contentSha256: createHash("sha256").update(readFileSync("src/game/content/index.ts")).digest("hex"),
+ rulesSha256: fingerprint(rules), contentSha256: fingerprint(content.map((p) => [p, readFileSync(p, "utf8")])),
modelSourceSha256: fingerprint(paths.map((p) => [p, readFileSync(p, "utf8")])), scenarioSha256: scenarios.map((s) => ({ name: s.name, sha256: fingerprint(s) })),
parametersChanged: fingerprint(rules) !== fingerprint(resolveRules()) }
}