Skip to content

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

Parks cannot be split for profit

Claudedc2eaf707be9
diff --git a/docs/how-to-play.md b/docs/how-to-play.md
index 56c515c..d1ce64f 100644
--- a/docs/how-to-play.md
+++ b/docs/how-to-play.md
@@ -132,11 +132,13 @@ Nobody tells you to build it that way; it works best that way.
live in town, a statue once 20 are citizens). Ground that touches is one
park, and the whole park is what the streets around it feel: its beauty
adds up from its ground (at most 4), its furnishings (the first of a
- kind in full, each more of it half as much, and one for every two
- cells), and its ways in from the street (a walk or a square beside a
- road: 1.5 each, two count), up to 15, out to 2 cells and one more for
- every 6 cells of park, up to 5; its whole worth reaches half that far
- before it fades. A lone statue is worth little; a lawn
+ kind in full, each more of it half as much, and one for every two whole
+ cells, so none on a park of one), and its ways in from the street (a
+ walk or a square beside a road: 1.5 each, two count), up to 15, out to
+ 2 cells and one more for every 6 cells of park, up to 5; its whole worth
+ reaches half that far before it fades. Where several parks reach a
+ street, the finest counts in full and the others half, so scraps of park
+ are no match for one park. A lone statue is worth little; a lawn
with walks in from the street, lamps, and a statue is worth a street of
citizens.
Parks cost upkeep by the cell and by the furnishing: a fine centre is
diff --git a/src/appeal.ts b/src/appeal.ts
index 9281f63..b20d0d9 100644
--- a/src/appeal.ts
+++ b/src/appeal.ts
@@ -28,9 +28,10 @@ export interface AppealSource {
/**
* `sum`: adds up with others; `nature` and `paved`: only the strongest of
* their kind counts; `homes`: adds up, to `appeal.homesMost` at most, and
- * never on the home's own cell.
+ * never on the home's own cell; `park`: the finest counts in full, the
+ * others `park.others` of theirs.
*/
- readonly mode: "sum" | "nature" | "paved" | "homes"
+ readonly mode: "sum" | "nature" | "paved" | "homes" | "park"
/** A park: the cells it covers, inside the square (x, y, size) around them. */
readonly cells?: ReadonlyArray<Point>
}
@@ -95,7 +96,18 @@ export const appealGrid = (sources: ReadonlyArray<AppealSource>, rules: Rules =
const nature = new Int32Array(GRID * GRID)
const paved = new Int32Array(GRID * GRID)
const homes = new Int32Array(GRID * GRID)
+ const parkBest = new Int32Array(GRID * GRID)
+ const parkAll = new Int32Array(GRID * GRID)
for (const s of sources) {
+ if (s.mode === "park") {
+ for (let y = Math.max(0, s.y - s.reach); y < Math.min(GRID, s.y + s.size + s.reach); y++)
+ for (let x = Math.max(0, s.x - s.reach); x < Math.min(GRID, s.x + s.size + s.reach); x++) {
+ const e = effectOf(s, ringTo(s, x, y)), k = key(x, y)
+ parkAll[k] = parkAll[k]! + e
+ if (e > parkBest[k]!) parkBest[k] = e
+ }
+ continue
+ }
const into = s.mode === "sum" ? sum : s.mode === "nature" ? nature : s.mode === "paved" ? paved : homes
for (let y = Math.max(0, s.y - s.reach); y < Math.min(GRID, s.y + s.size + s.reach); y++) {
for (let x = Math.max(0, s.x - s.reach); x < Math.min(GRID, s.x + s.size + s.reach); x++) {
@@ -107,7 +119,8 @@ export const appealGrid = (sources: ReadonlyArray<AppealSource>, rules: Rules =
}
}
}
- return Array.from({ length: GRID * GRID }, (_, k) => clamp(sum[k]! + nature[k]! + paved[k]! + Math.min(rules.appeal.homesMost, homes[k]!), rules))
+ const parks = (k: number) => parkBest[k]! + Math.trunc((parkAll[k]! - parkBest[k]!) * rules.park.others)
+ return Array.from({ length: GRID * GRID }, (_, k) => clamp(sum[k]! + nature[k]! + paved[k]! + Math.min(rules.appeal.homesMost, homes[k]!) + parks(k), rules))
}
/** One cell's desirability and what makes it, strongest first: "park +6", "bakery −4". */
@@ -115,14 +128,20 @@ export const appealParts = (sources: ReadonlyArray<AppealSource>, cell: { readon
const parts = new Map<string, number>()
const best = { nature: { label: "", value: 0 }, paved: { label: "", value: 0 } }
let homes = { label: "", value: 0 }
+ const parks: Array<number> = []
for (const s of sources) {
const e = effectOf(s, ringTo(s, cell.x, cell.y))
if (e === 0) continue
- if (s.mode === "sum") parts.set(s.label, (parts.get(s.label) ?? 0) + e)
+ if (s.mode === "park") parks.push(e)
+ else if (s.mode === "sum") parts.set(s.label, (parts.get(s.label) ?? 0) + e)
else if (s.mode === "homes") homes = { label: s.label, value: Math.min(rules.appeal.homesMost, homes.value + e) }
else if (Math.abs(e) > Math.abs(best[s.mode].value)) best[s.mode] = { label: s.label, value: e }
}
for (const b of [best.nature, best.paved, homes]) if (b.value !== 0) parts.set(b.label, (parts.get(b.label) ?? 0) + b.value)
+ if (parks.length > 0) {
+ const finest = Math.max(...parks), all = parks.reduce((n, e) => n + e, 0)
+ parts.set("park", (parts.get("park") ?? 0) + finest + Math.trunc((all - finest) * rules.park.others))
+ }
const list = [...parts].map(([label, value]) => ({ label, value })).filter((p) => p.value !== 0)
list.sort((a, b) => Math.abs(b.value) - Math.abs(a.value))
return { value: clamp(list.reduce((n, p) => n + p.value, 0), rules), parts: list }
@@ -159,7 +178,7 @@ const tenth = (n: number) => Math.round(n * 10) / 10
/**
* One park's worth: its ground (each cell a little, flower beds more, up to
* `park.groundMost`), and its furnishings, the best first: one for every
- * `park.cellsPerProp` cells counts, and each one of a kind after the first
+ * `park.cellsPerProp` whole cells counts, and each one of a kind after the first
* counts `park.repeat` of the one before; and its entrances, each walk or
* square beside a road (`road`), up to `park.entrances`. A lawn is
* pleasant; a lawn with walks in from the street, lamps, and a statue is a
@@ -169,7 +188,7 @@ export const parkValue = (cells: ReadonlyArray<ParkCell>, road: (x: number, y: n
const { grounds, props, park } = rules
const groundRaw = cells.reduce((n, c) => n + grounds[c.ground].beauty, 0)
const ground = Math.min(park.groundMost, groundRaw)
- const room = Math.ceil(cells.length / park.cellsPerProp)
+ const room = Math.floor(cells.length / park.cellsPerProp)
const placed = cells.filter((c) => c.prop !== "none").map((c) => c.prop as PropId)
// Each furnishing's worth given those of its kind before it; the best count first.
const seen = new Map<PropId, number>()
@@ -242,7 +261,7 @@ export const parkSources = (cells: ReadonlyArray<ParkCell>, road?: (x: number, y
const y = Math.min(...ys)
const size = Math.max(Math.max(...xs) - x, Math.max(...ys) - y) + 1
// A bigger park gives its whole worth further out: half its reach, rounded down.
- return { x, y, size, value: p.value, reach: p.reach, full: Math.max(1, Math.floor(p.reach / 2)), label: "park", mode: "sum", cells: p.cells }
+ return { x, y, size, value: p.value, reach: p.reach, full: Math.max(1, Math.floor(p.reach / 2)), label: "park", mode: "park", cells: p.cells }
})
/** Per-minute upkeep paid for a park cell, including its furnishing. */
diff --git a/src/content.ts b/src/content.ts
index 8c55887..1b8485e 100644
--- a/src/content.ts
+++ b/src/content.ts
@@ -402,7 +402,7 @@ export const props: Readonly<Record<PropId, ParkPiece>> = {
export const park = {
/** Ground counts for this much beauty at most, however big the park. */
groundMost: 4,
- /** One furnishing counts for every this many cells: a park crowded with benches is no nicer. */
+ /** 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,
@@ -411,6 +411,12 @@ export const park = {
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/host.ts b/src/host.ts
index 4a93220..40b1ab0 100644
--- a/src/host.ts
+++ b/src/host.ts
@@ -916,7 +916,7 @@ export const createHost = async (
const parks = section(
"parks",
"decor",
- `Lay ground, then set furnishings on it. Ground that touches is one park: the more it holds the nicer the streets around it (citizens need ${home.tiers[2].appeal}, townhouses ${home.tiers[3].appeal}). One furnishing counts for every ${parkRules.cellsPerProp} cells.`
+ `Lay ground, then set furnishings on it. Ground that touches is one park: the more it holds the nicer the streets around it (citizens need ${home.tiers[2].appeal}, townhouses ${home.tiers[3].appeal}). One furnishing counts for every ${parkRules.cellsPerProp} cells; where parks meet, the finest counts in full.`
)
parks.style.borderTop = "3px solid #4f9a6a"
const pieces: ReadonlyArray<{ readonly id: GroundId | PropId; readonly piece: ParkPiece; readonly pick: () => void; readonly ground: boolean }> = [
diff --git a/src/present.ts b/src/present.ts
index b2bc3ac..d36520d 100644
--- a/src/present.ts
+++ b/src/present.ts
@@ -417,7 +417,7 @@ export const Interact = Game.System(
p.entrances > 0
? { icon: "road", label: "ways in from the street", value: `${p.entrances}${p.entrances > 2 ? " (2 count)" : ""}` }
: { icon: "road", label: "ways in from the street", value: "none", tone: "warn", note: "lay a gravel walk or a paved square out to a road: +1.5 each, two count" },
- { icon: "decor", label: "furnishings that count", value: `${placed} of ${Math.ceil(p.cells.length / 2)}`, tone: p.crowded > 0 ? "warn" : undefined, note: p.crowded > 0 ? `${p.crowded} too many: one counts for every 2 cells, so lay more ground` : undefined },
+ { icon: "decor", label: "furnishings that count", value: `${placed} of ${Math.floor(p.cells.length / 2)}`, tone: p.crowded > 0 ? "warn" : undefined, note: p.crowded > 0 ? `${p.crowded} too many: one counts for every 2 cells of park, so lay more ground` : undefined },
...(missing.length > 0 ? [{ icon: "info", label: "nicer with", value: missing.join(", "), tone: "dim" } as Line] : []),
{ icon: "upkeep", label: "upkeep", value: `${Math.round(upkeep * 10) / 10} coins a minute` }
]
diff --git a/test/balance-model.test.ts b/test/balance-model.test.ts
index 90efada..0e23027 100644
--- a/test/balance-model.test.ts
+++ b/test/balance-model.test.ts
@@ -131,10 +131,10 @@ test("the mathematical plan reaches citizens through ordinary game construction"
const rules = resolveRules(), { scenario, builds } = buildScenario(rules)
const r = verifyBuilds({ rules, scenario }, builds)
assert.deepEqual(r.messages, [])
- // 32 in citizens' homes, and 12 more once fine homes lift one of them past the townhouse threshold.
- assert.equal(r.actual.at(-1)!.citizens, 44)
+ // 32 in citizens' homes: its three-cell park holds one furnishing that counts, too few to lift a townhouse.
+ assert.equal(r.actual.at(-1)!.citizens, 32)
assert(r.firstCitizenSecond !== null && r.firstCitizenSecond <= 300)
- assert.equal(r.prediction.rows.at(-1)!.citizens, 44)
+ assert.equal(r.prediction.rows.at(-1)!.citizens, 32)
assert(r.prediction.assumptions.length > 0)
assert.equal(r.errors.length, r.actual.length)
})
diff --git a/test/economy.test.ts b/test/economy.test.ts
index 93b6f28..389c2a4 100644
--- a/test/economy.test.ts
+++ b/test/economy.test.ts
@@ -14,7 +14,7 @@
import assert from "node:assert/strict"
import { test } from "node:test"
import { amounts, type GoodId, type GroundId, type Need, type PropId } from "../src/content.ts"
-import { parksOf } from "../src/appeal.ts"
+import { appealGrid, parkSources, parksOf, type ParkCell } from "../src/appeal.ts"
import { shippedRules } from "../src/rules/config.ts"
import { moreAdmin, tierFor } from "../src/rules/households.ts"
import { chainWorth, crownMargin, dominates, homes, median, openingKit, producers, services } from "../src/rules/worth.ts"
@@ -145,7 +145,7 @@ test("a bigger building for a service walks at least as far for its upkeep as a
const ONE_CELL_MOST = 2
const road = (_x: number, y: number) => y === 0
-test("a park of one cell gives little, whatever stands on it", { todo: "a lamp makes it 3, a fountain 6, a statue 7: more than a chapel" }, () => {
+test("a park of one cell gives little, whatever stands on it", () => {
const out: Array<string> = []
for (const ground of ["lawn", "flowers", "path", "square"] as Array<GroundId>)
for (const prop of ["none", "lamp", "fountain", "statue"] as Array<PropId | "none">) {
@@ -155,15 +155,16 @@ test("a park of one cell gives little, whatever stands on it", { todo: "a lamp m
none(out, "one-cell park too fine")
})
-test("cells laid as separate parks give no more than the same cells as one", { todo: "parks touching only at a corner are separate, and their values add up" }, () => {
+test("cells laid as separate parks give a street no more than the same cells as one", () => {
const out: Array<string> = []
- for (const n of [2, 3, 4, 5])
+ /** The finest desirability any cell gets from these park cells. */
+ const finest = (cells: ReadonlyArray<ParkCell>) => Math.max(...appealGrid(parkSources(cells, road, rules), rules))
+ for (const n of [2, 3, 4, 5, 6])
for (const prop of ["none", "lamp"] as const) {
// A diagonal of cells (each its own park) against a row of them (one park), both beside the road.
- const apart = Array.from({ length: n }, (_, i) => ({ x: 2 * i, y: 1 + (i % 2), ground: "path" as const, prop }))
- const joined = Array.from({ length: n }, (_, i) => ({ x: i, y: 1, ground: "path" as const, prop }))
- const value = (cells: typeof apart) => parksOf(cells, road, rules).reduce((s, p) => s + p.value, 0)
- if (value(apart) > value(joined)) out.push(`${n} paths${prop === "none" ? "" : ` with ${prop}s`}: ${value(apart)} apart, ${value(joined)} as one`)
+ const apart = Array.from({ length: n }, (_, i) => ({ x: 10 + 2 * i, y: 1 + (i % 2), ground: "path" as const, prop }))
+ const joined = Array.from({ length: n }, (_, i) => ({ x: 10 + i, y: 1, ground: "path" as const, prop }))
+ if (finest(apart) > finest(joined)) out.push(`${n} paths${prop === "none" ? "" : ` with ${prop}s`}: ${finest(apart)} apart, ${finest(joined)} as one`)
}
none(out, "splitting a park pays")
})