Skip to content

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

Fish opens the town but does not carry it

Claudee58424c73287
diff --git a/src/archetypes.ts b/src/archetypes.ts
index 7f1df65..a58a0b1 100644
--- a/src/archetypes.ts
+++ b/src/archetypes.ts
@@ -81,5 +81,7 @@ export const parkDraft = (cell: Point, ground: GroundId) => Game.Command.spawn([
export const roadDraft = (cell: Point) => Game.Command.spawn([Tile, { x: cell.x, y: cell.y, size: 1 }], [Road, {}])
export const treeDraft = (cell: Point, growth: number) => Game.Command.spawn([Tile, { x: cell.x, y: cell.y, size: 1 }], [Tree, { growth }])
export const rockDraft = (cell: Point, ore: boolean, amount: number) => Game.Command.spawn([Tile, { x: cell.x, y: cell.y, size: 1 }], [Rock, { ore, amount }])
-export const waterDraft = (cell: Point) => Game.Command.spawn([Tile, { x: cell.x, y: cell.y, size: 1 }], [Water, {}])
+/** A cell of water never fished: long rested. */
+export const UNFISHED = -1_000_000
+export const waterDraft = (cell: Point) => Game.Command.spawn([Tile, { x: cell.x, y: cell.y, size: 1 }], [Water, { fished: UNFISHED }])
export const fieldDraft = (cell: Point) => Game.Command.spawn([Tile, { x: cell.x, y: cell.y, size: 1 }], [Field, { growth: 0 }])
diff --git a/src/content.ts b/src/content.ts
index cc7525d..8c55887 100644
--- a/src/content.ts
+++ b/src/content.ts
@@ -231,9 +231,9 @@ export const kinds: Readonly<Record<KindId, Kind>> = {
wear: 50, dusty: true, appeal: { value: -8, reach: 4 }
},
fishery: {
- id: "fishery", title: "Fishery", blurb: "catches fish; needs water within two cells",
+ 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: 3, workers: 2, crew: "settlers", unlock: free, buildable: true,
+ 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 }
},
@@ -462,6 +462,12 @@ export const home = {
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
@@ -627,6 +633,12 @@ export const ROCK_AMOUNT = 40
* about a third of its pace instead of stopping for good.
*/
export const FACE_TICKS = ticks(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 = ticks(40)
// ── The charter: what a new town is founded on ────────────────────────────
diff --git a/src/rules/config.ts b/src/rules/config.ts
index 053cfc3..5536e6b 100644
--- a/src/rules/config.ts
+++ b/src/rules/config.ts
@@ -16,7 +16,7 @@ const inputs = () => ({
commute: content.COMMUTE, apprentice: content.APPRENTICE, toolStock: content.TOOL_STOCK,
conditionMax: content.CONDITION_MAX, riskMax: content.RISK_MAX, pausedUpkeep: content.PAUSED_UPKEEP, salvage: content.salvage,
buildTicks: content.BUILD_TICKS, roadCost: content.ROAD_COST, paveCost: content.PAVE_COST, pavedPace: content.PAVED_PACE,
- grown: content.GROWN, faceTicks: content.FACE_TICKS, yearsPerTerm: content.YEARS_PER_TERM, staffTicks: content.ticks(0.5), riskTicks: 60,
+ grown: content.GROWN, faceTicks: content.FACE_TICKS, restockTicks: content.RESTOCK_TICKS, yearsPerTerm: content.YEARS_PER_TERM, staffTicks: content.ticks(0.5), riskTicks: 60,
spreadTicks: content.ticks(1.5), growTicks: 10
})
diff --git a/src/rules/guide.ts b/src/rules/guide.ts
index 7efb1aa..94a88fb 100644
--- a/src/rules/guide.ts
+++ b/src/rules/guide.ts
@@ -330,7 +330,7 @@ export const guideSteps: ReadonlyArray<GuideStep> = [
chapter: "Growing citizens",
course: true,
action: "Pick [select] and {tap|click} a home to see what it still lacks to hold citizens.",
- why: "A home becomes a citizens' home with bread, cloth, and faith, on a street of desirability 5 or more, once the store can pay for its rebuilding: planks and stone. Its panel lists what is missing.",
+ why: "With bread, cloth, faith, and a street of desirability 5, a home rises once the store pays its planks and stone. Its panel lists what is missing.",
goal: "the first home holds citizens",
focus: "hall",
when: () => true,
diff --git a/src/rules/households.ts b/src/rules/households.ts
index 827b9cf..10b7193 100644
--- a/src/rules/households.ts
+++ b/src/rules/households.ts
@@ -64,13 +64,14 @@ export const kept = (r: { readonly fire: number; readonly health: number; readon
* The tier a home settles into: settlers whose every citizens' need is met,
* on a street desirable enough, become citizens; citizens with a street
* nicer still and all three services calling become burghers in a
- * townhouse. A home that loses more than one of its needs, or whose street
- * falls below its tier, steps back down.
+ * townhouse. A home that loses its staple (bread: fish will not do), or
+ * more than one of its needs, or whose street falls below its tier, steps
+ * back down.
*/
export const tierFor = (h: Needs, desirability: number, r: { readonly fire: number; readonly health: number; readonly order: number }, rules: Rules = shippedRules): Tier => {
const fits = (tier: Tier) => desirability >= rules.home.tiers[tier].appeal
if (h.tier === 1) return satisfaction(h, 2, rules) === 1 && fits(2) ? 2 : 1
- if (satisfaction(h, h.tier, rules) < 2 / 3 || !fits(2)) return 1
+ if (satisfaction(h, h.tier, rules) < 2 / 3 || !met(h, rules.home.staple) || !fits(2)) return 1
if (h.tier === 2) return satisfaction(h, 3, rules) === 1 && fits(3) && kept(r, rules) ? 3 : 2
return fits(3) && kept(r, rules) ? 3 : 2
}
diff --git a/src/save.ts b/src/save.ts
index c4c97fe..44e2e26 100644
--- a/src/save.ts
+++ b/src/save.ts
@@ -18,9 +18,9 @@ export const SAVE_FORMAT = "inkline-town/save"
* winters). 4: parks and patrols. 5: the grudge over taxes, and where each piece of news happened.
* 6: how much of each good may be traded at a collection. 7: the mayor's guide. 8: terms that follow one
* another, the town's rank, and upgraded buildings.
- * Version 4 to 7 saves are carried forward (see `carry`); older ones cannot be loaded.
+ * Version 4 to 8 saves are carried forward (see `carry`); older ones cannot be loaded.
*/
-export const SAVE_VERSION = 8
+export const SAVE_VERSION = 9
/**
* Fills in what a save from an earlier version lacks, so a town in progress
@@ -29,14 +29,21 @@ export const SAVE_VERSION = 8
* guide from its start (it puts away at once what the town has already
* done); from 7, its first term, and its rank: a town that was complete
* (or governed on after) is a town, any other a hamlet that rises as its
- * goals hold. A complete town waiting on its mayor carries on playing.
+ * goals hold. A complete town waiting on its mayor carries on playing;
+ * from 8, its water as never fished.
* Anything else is left to the world's own validation.
*/
const carry = (version: number, world: unknown): unknown | null => {
- if (version < 4 || version > 7 || typeof world !== "object" || world === null) return null
- const w = world as { resources?: Record<string, unknown> }
+ if (version < 4 || version > 8 || typeof world !== "object" || world === null) return null
+ const w = world as { resources?: Record<string, unknown>; entities?: Array<{ components?: Record<string, unknown> }> }
const r = w.resources
if (!r || typeof r !== "object") return null
+ // From 8, water that was never fished.
+ for (const e of Array.isArray(w.entities) ? w.entities : []) {
+ const water = e.components?.["Town/Water"]
+ if (water && typeof water === "object" && !("fished" in water)) e.components!["Town/Water"] = { fished: -1_000_000 }
+ }
+ if (version === 8) return w
const fate = r["Town/Fate"] as Record<string, unknown> | undefined
if (fate && typeof fate === "object" && !("rank" in fate)) {
const { governing, won, ...rest } = fate
diff --git a/src/schema.ts b/src/schema.ts
index 92f64d5..f65136c 100644
--- a/src/schema.ts
+++ b/src/schema.ts
@@ -59,7 +59,8 @@ export const Rising = Descriptor.ConstructedComponent(Decode.struct({ ticks: int
export const Tree = Descriptor.ConstructedComponent(Decode.struct({ growth: integer }))("Town/Tree")
export const Rock = Descriptor.ConstructedComponent(Decode.struct({ ore: Decode.boolean, amount: integer }))("Town/Rock")
-export const Water = Descriptor.Tag("Town/Water")
+/** A cell of water: the step it was last fished (see `RESTOCK_TICKS`). */
+export const Water = Descriptor.ConstructedComponent(Decode.struct({ fished: integer }))("Town/Water")
export const Field = Descriptor.ConstructedComponent(Decode.struct({ growth: integer }))("Town/Field")
// ── Homes ─────────────────────────────────────────────────────────────────
diff --git a/src/sim/work.ts b/src/sim/work.ts
index 6fa60c5..ca4de9b 100644
--- a/src/sim/work.ts
+++ b/src/sim/work.ts
@@ -16,7 +16,7 @@ const FLOW_SLICES = 6
const each = (f: (g: (typeof goodIds)[number]) => number): Amounts => Object.fromEntries(goodIds.map((g) => [g, f(g)])) as Amounts
import { around, doors, GridBuilder, key, ownerAt, reach, roadPrint, useAt } from "../grid.ts"
-import { Building, Burning, Charter, Chronicle, Errand, Flow, Roam, Condition, Field, FieldOf, Game, Rules, Gatherer, Grid, House, Inventory, Land, Paused, Paved, Planter, Recipe, Rising, Rng, Rock, Site, Staff, Status, Stock, Storage, Tile, Time, Treasury, Tree, maybe, type Status as StatusValue } from "../schema.ts"
+import { Building, Burning, Charter, Chronicle, Errand, Flow, Roam, Condition, Field, FieldOf, Game, Rules, Gatherer, Grid, House, Inventory, Land, Paused, Paved, Planter, Recipe, Rising, Rng, Rock, Site, Staff, Status, Stock, Storage, Tile, Time, Treasury, Tree, maybe, type Status as StatusValue, Water } from "../schema.ts"
import { connected, elapsed, seasonAt, TileRead, useOf, write } from "./shared.ts"
import { assignWorkers, equipmentPace, effort, paced } from "../rules/production.ts"
@@ -272,8 +272,9 @@ export const AssignStaff = Game.System(
* One step of every recipe. A job starts when there is room for what it
* makes, its input is in, and (for a gatherer) the land has what it needs
* within reach: a grown tree is felled, a rock chipped, a ripe field
- * reaped. Then the crew puts its worker-steps in; a full crew finishes in
- * `period` steps. It goes at half pace without the tools it wears out, and
+ * reaped, a rested cell of water fished. Then the crew puts its
+ * worker-steps in; a full crew finishes in `period` steps. It goes at half
+ * pace without the tools it wears out, and
* at half pace again once it is run down; in winter, fishing goes at the
* winter's pace (a hard winter's is a quarter).
*/
@@ -297,7 +298,8 @@ export const Work = Game.System(
}),
trees: Game.Query({ selection: { tree: Game.Query.read(Tree) } }),
rocks: Game.Query({ selection: { rock: Game.Query.write(Rock) } }),
- fields: Game.Query({ selection: { field: Game.Query.write(Field) } })
+ fields: Game.Query({ selection: { field: Game.Query.write(Field) } }),
+ waters: Game.Query({ selection: { water: Game.Query.write(Water) } })
},
resources: {
grid: Game.System.readResource(Grid),
@@ -326,6 +328,7 @@ export const Work = Game.System(
const trees = lazy(() => new Map(queries.trees.each().map((row) => [row.entity.id as number, row])))
const rocks = lazy(() => new Map(queries.rocks.each().map((row) => [row.entity.id as number, row])))
const fields = lazy(() => new Map(queries.fields.each().map((row) => [row.entity.id as number, row])))
+ const waters = lazy(() => new Map(queries.waters.each().map((row) => [row.entity.id as number, row])))
const used = new Set<number>()
// A worked face gives one more now and then.
if (tick % rules.faceTicks === 0)
@@ -340,7 +343,14 @@ export const Work = Game.System(
const use = useAt(grid, c.x, c.y)
const id = ownerAt(grid, c.x, c.y)
if (used.has(id)) continue
- if (source === "water" && use === "water") return true
+ if (source === "water" && use === "water") {
+ // A cell fished rests a while before it gives another catch.
+ const water = waters().get(id)
+ if (!water || tick - water.data.water.get().fished < rules.restockTicks) continue
+ water.data.water.set({ fished: tick })
+ used.add(id)
+ return true
+ }
if (source === "tree" && use === "tree") {
const tree = trees().get(id)
if (!tree || tree.data.tree.get().growth < GROWN.tree) continue
diff --git a/test/economy.test.ts b/test/economy.test.ts
index 405c7c4..93b6f28 100644
--- a/test/economy.test.ts
+++ b/test/economy.test.ts
@@ -49,7 +49,7 @@ test("no way of making a food is cheaper on every count than another that meets
none(chains.flatMap((a) => chains.filter((b) => a !== b && same(a.meets, b.meets) && dominates(a, b)).map((b) => `${a.good} dominates ${b.good}`)), "dominated food")
})
-test("foods that all meet a need cost within a few times one another to keep making", { todo: "bread's chain costs 4.8× fish's upkeep a unit, and stops in winter" }, () => {
+test("foods that all meet a need cost within a few times one another to keep making", () => {
const chains = foods.map((g) => chainWorth(g, rules))
const out: Array<string> = []
for (const need of ["food"] as const) {
@@ -60,12 +60,12 @@ test("foods that all meet a need cost within a few times one another to keep mak
none(out, "substitutes too far apart")
})
-test("a tier's staple is needed to keep the tier: a citizens' home fed fish instead of bread steps down", { todo: "a citizens' home keeps its tier on fish, cloth, and faith (2 of 3 needs)" }, () => {
+test("a tier's staple is needed to keep the tier: a citizens' home fed fish instead of bread steps down", () => {
const fish = { tier: 2 as const, food: 100, bread: 0, cloth: 100, faith: 100 }
assert.equal(tierFor(fish, rules.home.tiers[3].appeal, { fire: 0, health: 0, order: 0 }, rules), 1)
})
-test("fisheries sharing one stretch of water share its catch", { todo: "water never runs out: every fishery on it catches at full pace" }, () => {
+test("fisheries sharing one stretch of water share its catch", () => {
const base = district("shared-water", [1, 1, 1, 1], ["fishery", "fishery"], false, rules)
const [a, b] = base.buildings.filter((x) => x.kind === "fishery")
// One cell of water, within reach of both.
@@ -77,9 +77,9 @@ test("fisheries sharing one stretch of water share its catch", { todo: "water ne
town.run(1)
}
const made = [a!, b!].map((f) => component(town.snapshot(), f.id, "Town/Recipe").made as number)
- const alone = 60 / rules.kinds.fishery.recipe!.seconds
- assert(made[0]! > 0 && made[1]! > 0, `both fish: ${made}`)
- assert(made[0]! + made[1]! <= alone * 1.25, `two fisheries on one cell of water caught ${made.join(" + ")}, one alone catches ${alone}`)
+ // One cell gives a catch, then rests: a minute holds two catches at most, whoever makes them.
+ const most = Math.floor(60 / (rules.restockTicks * rules.stepSeconds)) + 1
+ assert(made[0]! + made[1]! <= most, `two fisheries on one cell of water caught ${made.join(" + ")}; the water gives ${most} a minute`)
})
// ── Homes ─────────────────────────────────────────────────────────────────
diff --git a/tools/balance/model/project.ts b/tools/balance/model/project.ts
index 3cb75f3..d99b9b6 100644
--- a/tools/balance/model/project.ts
+++ b/tools/balance/model/project.ts
@@ -105,7 +105,7 @@ export const project = ({ rules, scenario }: Inputs, options: ProjectionOptions)
const k = rules.kinds[row.kind], r = k.recipe!, transport = analysis.transport.find((t) => t.id === row.id)?.sharedGoodsPerMinuteCeiling ?? Infinity
let jobs = Math.min(row.capacity.outputPerMinute, transport) * share / r.batch
if (r.input) jobs = Math.min(jobs, stock[r.input] / Math.max(1, r.inputs))
- if (k.gathers?.source === "water" && row.sourceCeiling === 0) jobs = 0
+ if (k.gathers?.source === "water") jobs = Math.min(jobs, (row.sourceCeiling ?? Infinity) * share)
if (k.gathers?.source === "field") {
const b = buildings.find((b) => b.id === row.id)!, state = crop(b)
if (!season.winter) {
diff --git a/tools/balance/model/throughput.ts b/tools/balance/model/throughput.ts
index 4ab9fda..8662ef6 100644
--- a/tools/balance/model/throughput.ts
+++ b/tools/balance/model/throughput.ts
@@ -43,7 +43,8 @@ export const sourceCeiling = (b: ModelBuilding, scenario: Scenario, grid: GridBu
if (!g) return Infinity
const ids = new Set(around(b.tile, g.radius).filter((p) => useAt(grid.value(), p.x, p.y) === (g.source === "ore" || g.source === "stone" ? "rock" : g.source)).map((p) => ownerAt(grid.value(), p.x, p.y)))
const sources = scenario.land.filter((l, i) => ids.has(-1 - i) && l.type === g.source)
- if (g.source === "water") return sources.length > 0 ? Infinity : 0
+ // Each cell of water gives a catch, then rests (see `RESTOCK_TICKS`): shared with other fisheries, this is a ceiling.
+ if (g.source === "water") return sources.length * 60 / (rules.restockTicks * rules.stepSeconds)
if (g.source === "field") {
const ripe = sources.filter((l) => l.growth >= rules.grown.field).length
return severity === null ? Math.max(sources.length, k.plants?.max ?? 0) * 60 / (rules.grown.field * rules.stepSeconds) : ripe / Math.max(minutes, 1 / 60)
diff --git a/tools/balance/scenario.ts b/tools/balance/scenario.ts
index 8fce480..f2cd51b 100644
--- a/tools/balance/scenario.ts
+++ b/tools/balance/scenario.ts
@@ -1,6 +1,6 @@
import type { ParkCell } from "../../src/appeal.ts"
import { amounts, goodIds, type KindId, type Tier } from "../../src/content.ts"
-import { GridBuilder, canPlace, doors, nearest, reach, type Use, type TileLike } from "../../src/grid.ts"
+import { GridBuilder, canPlace, doors, key, nearest, reach, type Use, type TileLike } from "../../src/grid.ts"
import { GRID } from "../../src/iso.ts"
import { shippedRules, type Rules } from "../../src/rules/config.ts"
import type { Snapshot } from "../../src/sim/headless.ts"
@@ -92,10 +92,15 @@ export const district = (name: string, tiers: ReadonlyArray<Tier>, kinds: Readon
grid.claim(tile, id, "building")
}
const land: Scenario["land"][number][] = []
- for (const b of buildings) if (b.kind === "fishery") for (let x = b.tile.x; x < b.tile.x + b.tile.size; x++) land.push({ tile: { x, y: b.tile.y + b.tile.size, size: 1 }, type: "water", amount: 1, growth: 0 })
for (const b of buildings) if (b.kind === "farm") {
for (let i = 0; i < rules.kinds.farm.plants!.max; i++) land.push({ tile: { x: b.tile.x + i % 4, y: b.tile.y + b.tile.size + Math.floor(i / 4), size: 1 }, type: "field", amount: 1, growth: rules.grown.field })
}
+ // A fishery's own stretch of shore, two cells deep and wide enough to fish at full pace (see `RESTOCK_TICKS`).
+ const taken = new Set(land.map((l) => key(l.tile.x, l.tile.y)))
+ for (const b of buildings) if (b.kind === "fishery")
+ for (let x = b.tile.x - 2; x < b.tile.x + b.tile.size + 2; x++)
+ for (let y = b.tile.y + b.tile.size; y < b.tile.y + b.tile.size + 2; y++)
+ if (!taken.has(key(x, y))) land.push({ tile: { x, y, size: 1 }, type: "water", amount: 1, growth: 0 })
return { name, charter: { size: "medium", term: 60, land: "fair", seed: 1000 }, tick: 0, coins: rules.lands.fair.coins, approval: 40,
policy: { settlers: 100, citizens: 100 }, homes: houses, buildings, roads, land }
}
diff --git a/tools/balance/verify/fixture.ts b/tools/balance/verify/fixture.ts
index a4f1255..cc2ef41 100644
--- a/tools/balance/verify/fixture.ts
+++ b/tools/balance/verify/fixture.ts
@@ -39,7 +39,7 @@ export const fixture = (scenario: Scenario, rules: Rules): Headless => {
const grid = scenarioGrid(scenario, rules).value()
for (const [i, l] of scenario.land.entries()) {
if (ownerAt(grid, l.tile.x, l.tile.y) !== -1 - i) continue
- const component = l.type === "tree" ? { "Town/Tree": { growth: l.growth } } : l.type === "field" ? { "Town/Field": { growth: l.growth } } : l.type === "water" ? { "Town/Water": {} } : { "Town/Rock": { amount: l.amount, ore: l.type === "ore" } }
+ const component = l.type === "tree" ? { "Town/Tree": { growth: l.growth } } : l.type === "field" ? { "Town/Field": { growth: l.growth } } : l.type === "water" ? { "Town/Water": { fished: -1_000_000 } } : { "Town/Rock": { amount: l.amount, ore: l.type === "ore" } }
add({ "Town/Tile": l.tile, ...component })
}
s.resources["Town/Land"] = { mask: scenario.mask ?? "1".repeat(GRID * GRID), cells: GRID * GRID }