A town simulation in pale isometric line art, implemented with Ritmo ECS and PixiJs 3D
Declare component requirements and drop hand-kept part lists
SandroMaglione1209819e1d6f
diff --git a/src/archetypes.ts b/src/archetypes.tsindex f592cc3..784b681 100644--- a/src/archetypes.ts+++ b/src/archetypes.ts@@ -16,8 +16,6 @@ const site = (cost: Kind["cost"]) => {return total(owed) > 0 ? Game.Command.entry(Site, { owed, total: total(owed) }) : Game.Command.entry(Rising, { ticks: 0 })}-/** The components of `buildingDraft`. */-export const BuildingParts = [Tile, Building, Status, Staff] as const/** A building of `kind` on `cell`: a site waiting for materials, or (`standing`) already up. */export const buildingDraft = (kind: Kind, cell: Point) =>Game.Command.spawn(@@ -76,29 +74,20 @@ export const rolesOf = (kind: Kind, rules: Rules = shippedRules) => {return roles}-/** The components of `houseDraft`. */-export const HouseParts = [Tile, House] as constexport const houseDraft = (cell: Point) =>Game.Command.spawn([Tile, { x: cell.x, y: cell.y, size: 1 }],[House, { tier: 1, residents: 0, food: 0, bread: 0, cloth: 0, faith: 0, furniture: 0, clock: 0 }])export const houseStart = (rules: Rules = shippedRules) => [site(rules.home.cost), ...wearOf(rules)]-export const RuinParts = [Tile, Ruin] as constexport const ruinDraft = (tile: { readonly x: number; readonly y: number; readonly size: number }, cause: "burnt" | "collapsed" | "derelict") =>Game.Command.spawn([Tile, { x: tile.x, y: tile.y, size: tile.size }], [Ruin, { cause }])-export const ParkParts = [Tile, Park] as constexport const parkDraft = (cell: Point, ground: GroundId) => Game.Command.spawn([Tile, { x: cell.x, y: cell.y, size: 1 }], [Park, { ground, prop: "none" }])-export const RoadParts = [Tile, Road] as constexport const roadDraft = (cell: Point) => Game.Command.spawn([Tile, { x: cell.x, y: cell.y, size: 1 }], [Road, {}])-export const TreeParts = [Tile, Tree] as constexport const treeDraft = (cell: Point, growth: number) => Game.Command.spawn([Tile, { x: cell.x, y: cell.y, size: 1 }], [Tree, { growth }])-export const RockParts = [Tile, Rock] as constexport const rockDraft = (cell: Point, ore: boolean, amount: number) => Game.Command.spawn([Tile, { x: cell.x, y: cell.y, size: 1 }], [Rock, { ore, amount }])/** A cell of water never fished: long rested. */export const UNFISHED = -1_000_000-export const WaterParts = [Tile, Water] as constexport const waterDraft = (cell: Point) => Game.Command.spawn([Tile, { x: cell.x, y: cell.y, size: 1 }], [Water, { fished: UNFISHED }])-export const FieldParts = [Tile, Field] as constexport const fieldDraft = (cell: Point) => Game.Command.spawn([Tile, { x: cell.x, y: cell.y, size: 1 }], [Field, { growth: 0 }])diff --git a/src/schema.ts b/src/schema.tsindex 59f89cb..a4c47ee 100644--- a/src/schema.ts+++ b/src/schema.ts@@ -457,7 +457,23 @@ export const Game = Schema.bind(Grid, Stock, Flow, Handed},events: { Toast, Selection },- relations: { WalkerOf, FieldOf }+ relations: { WalkerOf, FieldOf },+ // What always comes together: a draft or insert missing one of these does not compile.+ requires: [+ Schema.requires(Building, Tile, Status, Staff),+ Schema.requires(House, Tile),+ Schema.requires(Ruin, Tile),+ Schema.requires(Park, Tile),+ Schema.requires(Road, Tile),+ Schema.requires(Tree, Tile),+ Schema.requires(Rock, Tile),+ Schema.requires(Water, Tile),+ Schema.requires(Field, Tile),+ Schema.requires(Figure, Route),+ Schema.requires(Errand, Figure),+ Schema.requires(Roam, Figure),+ Schema.requires(Rescue, Figure)+ ]}),Root)diff --git a/src/sim/decay.ts b/src/sim/decay.tsindex e23e2dc..cbc208b 100644--- a/src/sim/decay.ts+++ b/src/sim/decay.ts@@ -7,9 +7,10 @@ import { spoilExpectation } from "../rules/decay.ts"*/import * as Random from "@typeonce/ritmo-math/Random"-import { RuinParts, ruinDraft } from "../archetypes.ts"+import { ruinDraft } from "../archetypes.ts"import { foods, goodIds, stepsOf } from "../content.ts"import { counted, placeName } from "../places.ts"+import { Ruin } from "../schema.ts"import { Building, Burning, Charter, Chronicle, Condition, Game, Rules, House, Inventory, Pantry, Recipe, Rising, Rng, Site, Staff, Tile, Time, maybe } from "../schema.ts"import { elapsed, write } from "./shared.ts"@@ -37,7 +38,7 @@ export const Decay = Game.System(chronicle: Game.System.writeResource(Chronicle)},services: { rules: Game.System.service(Rules) },- commands: Game.System.commands(Game.System.spawns(...RuinParts), Game.System.despawns(Condition))+ commands: Game.System.commands(Game.System.spawns(Ruin), Game.System.despawns(Condition))},({ queries, resources, commands, services }) => {const rules = services.rulesdiff --git a/src/sim/edits.ts b/src/sim/edits.tsindex 8a3581b..f511357 100644--- a/src/sim/edits.ts+++ b/src/sim/edits.ts@@ -6,12 +6,13 @@* carried to the site afterwards. Upgrading a building is paid at once.* Once the term has ended, only a new town, or another term, is taken.*/-import { BuildingParts, buildingDraft, houseDraft, HouseParts, houseStart, ParkParts, parkDraft, RoadParts, roadDraft, RockParts, rockDraft, RoleParts, rolesOf, StartParts, startOf, TreeParts, treeDraft, WaterParts, waterDraft } from "../archetypes.ts"+import { buildingDraft, houseDraft, houseStart, parkDraft, roadDraft, rockDraft, RoleParts, rolesOf, StartParts, startOf, treeDraft, waterDraft } from "../archetypes.ts"import * as Random from "@typeonce/ritmo-math/Random"import { amounts, anA, builtCost, costText, goodIds, nextUpgrade, RESERVE_MAX, TAX_STEPS, stepsOf, total, upgradeAt, type Amounts, type Kind, type ParkPiece, type Upgrade } from "../content.ts"import { canPlace, cellsOf, GridBuilder, ownerAt, useAt } from "../grid.ts"import { inside } from "../iso.ts"import { generate } from "../mapgen.ts"+import { Road, Water, Tree } from "../schema.ts"import { Appeal, Building, Tile, Census, Charter, Chronicle, Crown, Fate, Fires, Game, Guide, Rules, History, House, Inventory, Land, Ledger, Market, maybe, Mood, Pantry, Park, Paved, Paused, Policy, Rising, Rng, Rock, Service, Site, Status, Stock, Storage, Time, TownHall, Toast, Treasury, Upgraded, Works, Edits, Selection } from "../schema.ts"import { salvageOf, salvageText, withWorks } from "../rules/salvage.ts"import { elapsed, rollWinters, termTicks, TileRead, useOf, write } from "./shared.ts"@@ -84,7 +85,7 @@ export const ApplyEdits = Game.System(events: { toast: Game.System.writeEvent(Toast), selection: Game.System.writeEvent(Selection) },services: { edits: Game.System.service(Edits), rules: Game.System.service(Rules) },commands: Game.System.commands(- Game.System.spawns(...BuildingParts, ...HouseParts, ...RoadParts, ...ParkParts, ...WaterParts, ...TreeParts, ...RockParts),+ Game.System.spawns(Building, House, Road, Park, Water, Tree, Rock),Game.System.inserts(...StartParts, ...RoleParts, Paved, Paused, Works, TownHall, Status, Inventory),Game.System.removes(Paused),Game.System.despawns(Tile)diff --git a/src/sim/hazards.ts b/src/sim/hazards.tsindex ee27971..3b30cdd 100644--- a/src/sim/hazards.ts+++ b/src/sim/hazards.ts@@ -13,7 +13,7 @@ import { near, riskIncrements } from "../rules/risks.ts"import * as Random from "@typeonce/ritmo-math/Random"import { appealGrid, appealAt, buildingSource, homeSource, landSource, parkSources, type AppealSource } from "../appeal.ts"-import { RuinParts, ruinDraft } from "../archetypes.ts"+import { ruinDraft } from "../archetypes.ts"import { goodIds, risk, upgradeAt, type GoodId } from "../content.ts"import { doors, nearest, pathTo, reach, useAt } from "../grid.ts"import { counted, placeName, type Landmark } from "../places.ts"@@ -112,7 +112,7 @@ export const Hazards = Game.System(},services: { rules: Game.System.service(Rules) },commands: Game.System.commands(- Game.System.spawns(...RuinParts, Figure, Route, Rescue),+ Game.System.spawns(Ruin, Rescue),Game.System.inserts(Burning, Sick),Game.System.removes(Sick),Game.System.despawns(Tile)@@ -337,7 +337,7 @@ export const Douse = Game.System({queries: { crews: Game.Query({ selection: { route: Game.Query.write(Route), rescue: Game.Query.write(Rescue) } }), burning: BurningRead },resources: { fires: Game.System.writeResource(Fires) },- commands: Game.System.commands(Game.System.spawns(...RuinParts), Game.System.despawns(Rescue, Burning))+ commands: Game.System.commands(Game.System.spawns(Ruin), Game.System.despawns(Rescue, Burning))},({ queries, resources, commands }) => {for (const { entity, data } of queries.crews.each()) {diff --git a/src/sim/logistics.ts b/src/sim/logistics.tsindex 2d2307e..550b0e1 100644--- a/src/sim/logistics.ts+++ b/src/sim/logistics.ts@@ -55,7 +55,7 @@ export const Dispatch = Game.System(},resources: { grid: Game.System.readResource(Grid), appeal: Game.System.readResource(Appeal), time: Game.System.readResource(Time) },services: { rules: Game.System.service(Rules) },- commands: Game.System.commands(Game.System.spawns(Figure, Route, Errand))+ commands: Game.System.commands(Game.System.spawns(Errand))},({ queries, resources, commands, services }) => {const rules = services.rulesdiff --git a/src/sim/walkers.ts b/src/sim/walkers.tsindex 5330e6e..898e25f 100644--- a/src/sim/walkers.ts+++ b/src/sim/walkers.ts@@ -94,7 +94,7 @@ export const SendWalkers = Game.System(},resources: { grid: Game.System.readResource(Grid), time: Game.System.readResource(Time) },services: { rules: Game.System.service(Rules) },- commands: Game.System.commands(Game.System.spawns(Figure, Route, Roam), Game.System.inserts(Patrol))+ commands: Game.System.commands(Game.System.spawns(Roam), Game.System.inserts(Patrol))},({ queries, resources, commands, services }) => {const rules = services.rulesdiff --git a/src/sim/work.ts b/src/sim/work.tsindex 9e0cd68..c9dd39f 100644--- a/src/sim/work.ts+++ b/src/sim/work.ts@@ -8,7 +8,7 @@ import { wildTreeSpots, canSeedTree } from "../rules/land.ts"*/import * as Random from "@typeonce/ritmo-math/Random"-import { FieldParts, fieldDraft, TreeParts, treeDraft } from "../archetypes.ts"+import { fieldDraft, treeDraft } from "../archetypes.ts"import { amounts, anA, asUpgraded, crewOf, goodIds, stepsOf, total, upgradeAt, worksNeeded, type Amounts, type Crew } from "../content.ts"/** The flow of goods is counted in slices this many seconds long, and the last `FLOW_SLICES` of them (a minute) are kept. */@@ -530,7 +530,7 @@ export const Plant = Game.System(},resources: { grid: Game.System.readResource(Grid), rng: Game.System.writeResource(Rng), time: Game.System.readResource(Time) },services: { rules: Game.System.service(Rules) },- commands: Game.System.commands(Game.System.spawns(...TreeParts, ...FieldParts))+ commands: Game.System.commands(Game.System.spawns(Tree, Field))},({ queries, resources, commands, services }) => {const rules = services.rules@@ -585,7 +585,7 @@ export const Spread = Game.System(queries: { trees: Game.Query({ selection: { tile: Game.Query.read(Tile), tree: Game.Query.read(Tree) } }) },resources: { grid: Game.System.readResource(Grid), rng: Game.System.writeResource(Rng), time: Game.System.readResource(Time) },services: { rules: Game.System.service(Rules) },- commands: Game.System.commands(Game.System.spawns(...TreeParts))+ commands: Game.System.commands(Game.System.spawns(Tree))},({ queries, resources, commands, services }) => {const rules = services.rules