Skip to content

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

Upgrade Ritmo to 0.22.0

SandroMaglionef6eafbe8804b
diff --git a/.agents/skills/ritmo-onboarding b/.agents/skills/ritmo-onboarding
new file mode 120000
index 0000000..aed6428
--- /dev/null
+++ b/.agents/skills/ritmo-onboarding
@@ -0,0 +1 @@
+../../node_modules/@typeonce/ritmo/skills/ritmo-onboarding
\ No newline at end of file
diff --git a/.agents/skills/ritmo-polish b/.agents/skills/ritmo-polish
new file mode 120000
index 0000000..d53c1eb
--- /dev/null
+++ b/.agents/skills/ritmo-polish
@@ -0,0 +1 @@
+../../node_modules/@typeonce/ritmo/skills/ritmo-polish
\ No newline at end of file
diff --git a/.agents/skills/ritmo-prototype b/.agents/skills/ritmo-prototype
new file mode 120000
index 0000000..019bcf7
--- /dev/null
+++ b/.agents/skills/ritmo-prototype
@@ -0,0 +1 @@
+../../node_modules/@typeonce/ritmo/skills/ritmo-prototype
\ No newline at end of file
diff --git a/.oxlintrc.json b/.oxlintrc.json
index 05c0471..4521936 100644
--- a/.oxlintrc.json
+++ b/.oxlintrc.json
@@ -9,7 +9,6 @@
"town/no-cast-escape": "error",
"ritmo/handle-runtime-result": "error",
"ritmo/prefix-descriptor-and-system-names": "error",
- "ritmo/use-cell-value": "error",
"ritmo/no-state-spread": "error"
},
"overrides": [
diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md
index 7ab60d9..1fb2189 100644
--- a/DEVELOPMENT.md
+++ b/DEVELOPMENT.md
@@ -408,6 +408,8 @@ headless too. `pnpm lint:game` then checks the schedules themselves with
Ritmo's devtools lints (`src/app/lint.ts`).
The Ritmo skill an agent follows for every change is linked from the
installed package at `.agents/skills/ritmo`, so it updates with Ritmo.
+Its companions for prototyping, a stranger's first minute, and polish are
+linked beside it (`ritmo-prototype`, `ritmo-onboarding`, `ritmo-polish`).
## Balancing
diff --git a/package.json b/package.json
index 11619e2..7887bae 100644
--- a/package.json
+++ b/package.json
@@ -32,24 +32,24 @@
"engine:prepare": "node scripts/use-ritmo.ts"
},
"dependencies": {
- "@typeonce/ritmo": "0.16.1",
- "@typeonce/ritmo-browser": "0.16.1",
- "@typeonce/ritmo-math": "0.16.1",
- "@typeonce/ritmo-pixi": "0.16.1",
- "@typeonce/ritmo-render": "0.16.1",
+ "@typeonce/ritmo": "0.22.0",
+ "@typeonce/ritmo-browser": "0.22.0",
+ "@typeonce/ritmo-math": "0.22.0",
+ "@typeonce/ritmo-pixi": "0.22.0",
+ "@typeonce/ritmo-render": "0.22.0",
"effect": "4.0.3",
"pixi.js": "^8.22.0",
"three": "^0.186.1"
},
"devDependencies": {
- "@typeonce/oxlint-plugin-ritmo": "0.16.1",
- "@typeonce/ritmo-devtools": "0.16.1",
+ "@typeonce/oxlint-plugin-ritmo": "0.22.0",
+ "@typeonce/ritmo-devtools": "0.22.0",
"@types/node": "25.5.0",
"@types/three": "^0.186.0",
- "oxlint": "1.87.0",
+ "oxlint": "1.92.0",
"playwright": "^1.64.0",
"typescript": "7.0.2",
"vite": "8.3.1"
},
- "ritmoRelease": "0.15.0"
+ "ritmoRelease": "0.22.0"
}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 22373b6..b87b208 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -9,20 +9,20 @@ importers:
.:
dependencies:
'@typeonce/ritmo':
- specifier: 0.16.1
- version: 0.16.1([email protected])
+ specifier: 0.22.0
+ version: 0.22.0([email protected])
'@typeonce/ritmo-browser':
- specifier: 0.16.1
- version: 0.16.1([email protected])
+ specifier: 0.22.0
+ version: 0.22.0([email protected])
'@typeonce/ritmo-math':
- specifier: 0.16.1
- version: 0.16.1([email protected])
+ specifier: 0.22.0
+ version: 0.22.0([email protected])
'@typeonce/ritmo-pixi':
- specifier: 0.16.1
- version: 0.16.1([email protected])
+ specifier: 0.22.0
+ version: 0.22.0([email protected])
'@typeonce/ritmo-render':
- specifier: 0.16.1
- version: 0.16.1([email protected])
+ specifier: 0.22.0
+ version: 0.22.0([email protected])
effect:
specifier: 4.0.3
version: 4.0.3
@@ -34,11 +34,11 @@ importers:
version: 0.186.1
devDependencies:
'@typeonce/oxlint-plugin-ritmo':
- specifier: 0.16.1
- version: 0.16.1([email protected])
+ specifier: 0.22.0
+ version: 0.22.0([email protected])
'@typeonce/ritmo-devtools':
- specifier: 0.16.1
+ specifier: 0.22.0
'@types/node':
specifier: 25.5.0
version: 25.5.0
@@ -46,8 +46,8 @@ importers:
specifier: ^0.186.0
version: 0.186.0
oxlint:
- specifier: 1.87.0
- version: 1.87.0
+ specifier: 1.92.0
+ version: 1.92.0
playwright:
specifier: ^1.64.0
version: 1.64.0
@@ -66,116 +66,116 @@ packages:
'@oxc-project/[email protected]':
resolution: {integrity: sha512-jSNrRIyvPVLL5E1z/tS5zLAprosGz/FuI1PWwEOz59j3E4TTTzSpqKb/RDGqJhhW0QHYISGXxq582wGx6T11Tw==}
- '@oxlint/[email protected]':
- resolution: {integrity: sha512-22tVIHlB9898OYsBKmYB6He1MCSqdTmK1BVWuSNUTVrpS0KWNege+U9uEYqGJ+KatQag0r/oU44i3OOs46z7HQ==}
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-k3Sd4ixQfiOrybv1gT+AMI81HSdtAFsiCFx+xXxWdFkmKW2HNrSiOfwn20o5nl/ggwbzU1oNLDeU/fRPinTVZQ==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm]
os: [android]
- '@oxlint/[email protected]':
- resolution: {integrity: sha512-JfZQ3MWf74n8ov0DojZpkOduIubYJvZL5tbTMMhDutsal6u1xH1QuNpN+lK+EQwF8AeAfgwTR2fgh5U2br27XA==}
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-OZzgEuiTSG11QkBWdXEguiLOT6lL09KtfcC/BmvUQWBAjU5eVyBxIAsmWAXv8L85/eT6RE0GBEWTEFBAbYE74g==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm64]
os: [android]
- '@oxlint/[email protected]':
- resolution: {integrity: sha512-rkx6Xvvw93z2GImVOyvbZwAZcoY0Z6MJW177XNsSB+i/CBsH7ANyelTp01VZyIkM3iSXtqKVb4+ptBgPHap5pQ==}
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-We6XS7tIqxgUoany6uyGjj7mNsh/mwf4Gt9gUzhxG65NKo2Ow9s6tDfrVuI0FVg8n3YmpW5PBx80qFxiLwAfsA==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm64]
os: [darwin]
- '@oxlint/[email protected]':
- resolution: {integrity: sha512-cw5nYw7L/pQ2SgGBgOcg/Qo89llQre3vIc/kuBLhSICzu1r5s8L76H3ug6AIFsD98WpROj8/z5JVzkf4daxHaQ==}
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-jKJWijmi6AxAZcXXWA6R/NLVZHxoRTbIMnV8znsHzeiVfuEefYcyR8SJGfbBPmkG+kveLFRcBGw0fBrjLqtGmQ==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [x64]
os: [darwin]
- '@oxlint/[email protected]':
- resolution: {integrity: sha512-x/SuznE6loRZK9gz9AS4ZmzNzSu+5KdeoCS+sVHhnrE8HM6AD8UyTjwldQTTqlXGvkwHASgB0NiTNOc3o3PdAg==}
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-wkw01wvJPM8/4jh+MV3cp11859VuBc94N2q5uOzcBgdGIRAqMCg1O0W/+xsZ1fsInvuUcv2Xo4nd1nzcKhi9kg==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [x64]
os: [freebsd]
- '@oxlint/[email protected]':
- resolution: {integrity: sha512-+JEDmCAXiiFmKhAjZhgAOwaHWY6WENOQ5QA+lFuY59tgsUCDOTRi46B+lENK6CWvtxsXpwkZXNOgpjAQcpIpnA==}
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-Elm6nW308MzmR8knvk0tPqQ4XE+PGKztjXv7kVZTRLkhBQZRXHUQoBLc4E30fiIuF6gkZO5f3EpJtQc4Ok/fXw==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm]
os: [linux]
- '@oxlint/[email protected]':
- resolution: {integrity: sha512-/uC9XqXLAC9AHFLNycwmSQEvKqGrOCgU+uXALI7gNW0DG81TJ/3T2eHnKdRvcb5R1gFEfjxDwI4e4zIa29rICQ==}
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-oylpBAoeogddjhTlSPsXrzGq/aeJsvaULz/hYXvWtGn/Wt8LPLC7gFhucCicbRnzEKsShrZxIA0KyHmtFNnijQ==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm]
os: [linux]
- '@oxlint/[email protected]':
- resolution: {integrity: sha512-FTRYPsBy/M728vnUv7l+KAwSAa3Qi4BQbhVvy7NYuMTZ0sUa/OWsbMx79HVFw6u/5KWcaYayDsoOiv7xbevzDg==}
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-/EWOI0wwY+74UGvC93TldpoNP8moIcidVUPbUSoX16/SEdF7ah209yxSQia4+9JdCRWYA3+yQMofXMgWKk/16Q==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm64]
os: [linux]
- '@oxlint/[email protected]':
- resolution: {integrity: sha512-6sC+N7IY0h1egd8SrYUGNN7CUyKJZ4bIZakKa7V7hfinf4jfi8Kq4+klJvFp5DqXcwMn44I5MeBwmJluO1odFg==}
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-9Se7Zuazr104yc2PaluriJW2rqvtaN6FSi9MSjQgZGeYb6LKvEcJ586tpjek0l7hNQNoir8MID7OENPH6juN1w==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm64]
os: [linux]
- '@oxlint/[email protected]':
- resolution: {integrity: sha512-d5Mnn+ICbhoJPi37Ccjy+86T5qfH2+mSTrTMBXNPfB+wqSWOayBBLLIrCXdUy1YssluCVdGkl+DO9w5r5ODmUA==}
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-88IAchs204I/xxAbAo3NRyz1m/29tn8jUAPvc4tK4FzrT2PLwZertd93ANF6231vwbAhYiD5gl0cX8Po5xsjWQ==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [ppc64]
os: [linux]
- '@oxlint/[email protected]':
- resolution: {integrity: sha512-sf5YWuUo1Dx9loqWCgF8P278MycfcD4JHjDC/LV5j11L3Lqa4PFiwCjD6B8kP4AjsgZZkLn3xbpJEtZBaccs4Q==}
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-KtFdVdkfvBGcsrmnbjYJ9/XTDABnaniiwnptAcAm0pkaR2zhZ3sr/Xy+N1Xbz1Yq5Jegu7SoeNv9caTP0b5OTA==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [riscv64]
os: [linux]
- '@oxlint/[email protected]':
- resolution: {integrity: sha512-+aCraYbmK3uU3P0rFojjeaK9pGY6JvBDXh/0CM+gPyWKmNmXmnFe0qj4qj02U4ibFpbd9Pa9CmDvIdjJUd29rA==}
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-V43CO5FPgHtwHup4H5+dIdwzZX2FhREQGsSBZx8V1UyFEAul0Q13qviKqZfSMM6G41CGtCekVpJGGOxW5v1y8Q==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [riscv64]
os: [linux]
- '@oxlint/[email protected]':
- resolution: {integrity: sha512-7rzbZQIljo6VLWVPqUyLa2P/WV3VFsJB4M52R4NCUJn1A50yjtUsHxiMHFL9opEKGFIiTbZ3VQzmtcJOPUq4NQ==}
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-WooxeACzGH5q34olo7JgAk7XbVkTUNfwhR/TzmhwVs/y1p2R7ZWJo14hiyxiGcoYZR1iBnbBFHectADqb/KSog==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [s390x]
os: [linux]
- '@oxlint/[email protected]':
- resolution: {integrity: sha512-Dry46Fa+AXE/xt9J/YriujU1pU9mzfNWHGQwtOYibAFH8HLrKWCi93AhIGnuUMiwn2JbuBkRyz51f50Ly4r4ow==}
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-lW2pLF1oFvNN780YUCtDyoUm8oFzZGJNcOFe9RtLMX5v5+FcWfAQvHUMMPF8H8kJB0HAi3dFmWDWLa5VPuY9mw==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [x64]
os: [linux]
- '@oxlint/[email protected]':
- resolution: {integrity: sha512-f/HMZez74gJvnRpGz+b5sdGyWrEgRLmFTXg9sNoqjPWogGxYHUhXKTKyMiYsu9rUGR2ciYqL3fk+Ua4JhMJbRA==}
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-2BJAAB/eqPn7iD7mFVfs+1ZVUogAYOMCTaUgjAvbtNGg2ppCDE7gcv/9VSO6GCDybdFUqlcyeyjn9hRpl1ZHog==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [x64]
os: [linux]
- '@oxlint/[email protected]':
- resolution: {integrity: sha512-lEC6ZfPZm/07JlB7FsOWX9o1RiHlXiBW594LSUGuXmekC8LZmvUPP9XzE2WZcNxJi5cHA/Fw56o02c3JxgMA5g==}
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-iLtjNqqa/2IV5qu/3rrkpVd42Ia3yeCn4fSZoEr+m5FoGHtZvAV6J6YuU3lewg5Rg5ORGvwhdgN+7gNzwkl7tA==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm64]
os: [openharmony]
- '@oxlint/[email protected]':
- resolution: {integrity: sha512-afBWKOD36dUiA9AenaiWpCg8xfyUVPYznyAAVXu413brK4RA5UI/Xoc4yfeGIT8G1a44MV+JR7hioryerBDzGQ==}
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-ryxiR3ZqB0OJzydMu+bVC3R7ZtoU7X1rI8sEgTBCCvQvgVwoCwqSFlfmhgiZ+9wZ4IdTsFeu9tdiF9KtRCbSHQ==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm64]
os: [win32]
- '@oxlint/[email protected]':
- resolution: {integrity: sha512-daptNsEOuru4/nJTxV4DBHNJ5GepzmaBVQf+jjgKQGi9NRlZKik+RFq4hUL7ewsF1pwjKM+SkYaMbF82UwFGnw==}
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-DaE9OChj4nsdEST32BP7saGu8WtjOinTy/eS88dZ0TvTfDV26ebRDhsI1rL9OKXfO+DgehzhAQMqdPr2jgfcFw==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [ia32]
os: [win32]
- '@oxlint/[email protected]':
- resolution: {integrity: sha512-k+m/EShyXE29J/r1fjk0HlAzhN5JhIvj044oSJkXTEkCLrWZQgXb/3r4q5LTw/eaKW/4GuMXG2xmiJs3s5rPNw==}
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-0AyhqX0ciFuEnHIL+B4PIMMX3s/IpGHNEbbUqwsNhSrzWUSlEOPw/q7qFnRsEJfiKedcqVfUE/aXYuSMtpiFyw==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [x64]
os: [win32]
@@ -283,18 +283,18 @@ packages:
'@tweenjs/[email protected]':
resolution: {integrity: sha512-vJmvvwFxYuGnF2axRtPYocag6Clbb5YS7kLL+SO/TeVFzHqDIWrNKYtcsPMibjDx9O+bu+psAy9NKfWklassUA==}
- '@typeonce/[email protected]':
- resolution: {integrity: sha512-RZWhH+jGJiggchfGPvYvsvMbwEsCmrrhxA11ZD6ZqQAw5662SA9ltJc14Oa+GU/77OKOuirMyvS1AQNhZCpI4w==}
- engines: {node: '>=20'}
+ '@typeonce/[email protected]':
+ resolution: {integrity: sha512-YBEZ61AD51VunLBo9XvJ2Y7wFjgRejNZdKXB1fYr4Elr0xM9x8EfOPKxg+SppC13QrUCZ/NntuZG/13q/VGYIg==}
+ engines: {node: '>=22.12'}
peerDependencies:
oxlint: '>=1.86.0'
- '@typeonce/[email protected]':
- resolution: {integrity: sha512-gqk67SLUiN6ltKOGyGhPpatDqiUNCIj+cMJgV7DGFnkLe0shl9HmKH9s0M35s4/RZtsk4vWbgtcAzk6dvfxnFw==}
- engines: {node: '>=20'}
+ '@typeonce/[email protected]':
+ resolution: {integrity: sha512-7dJN+Fyt8M+yeItLH3ttdQwzVsmzYrOtO4lShsIzRwzoQQGbfI3P/c3CFiEgHVSgxIwevcD+837tsDV1lWgM3g==}
+ engines: {node: '>=22'}
- '@typeonce/[email protected]':
- resolution: {integrity: sha512-01Yi2Bx1c4Wz/JsabSC7THtuizt2ffTFmTG3Br+oF/664BN8yuXhkVOKU+j88KPNemqtW8BT9tJq7n1aJNtYgQ==}
+ '@typeonce/[email protected]':
+ resolution: {integrity: sha512-gkef7MqAY29Mi2JdlQT8q0Tx7077TGrXBfdqgNXaXwuvNRHh+GMINmAG7Fq6LlkE1HrfI3MAlqs7rj9GhD0pGQ==}
engines: {node: '>=22.15'}
hasBin: true
peerDependencies:
@@ -312,25 +312,25 @@ packages:
vite:
optional: true
- '@typeonce/[email protected]':
- resolution: {integrity: sha512-YzQ6s2YvFtHoNo/k3Lefa8cAp9aW9kina6210Q0jg6M4rzYFuN0Q9vnm7saCi/0Os7RzDL1vZWgOiWdvX9EWCA==}
- engines: {node: '>=20'}
+ '@typeonce/[email protected]':
+ resolution: {integrity: sha512-s8cqWlPpbvq8lHGOIkq3iuJ8hHkXUmx6XbnaX7YqFbfs99BJpxi7selmD7kKlM+dd61qFGRdgtDSpoFWxy2ndA==}
+ engines: {node: '>=22'}
- '@typeonce/[email protected]':
- resolution: {integrity: sha512-9PJCFd+ws3Q5YakO7MSJymh4hF7T2qK93CCFJk0avUE3GuyC3wCUSuhSEzfbntmm1iqxi83zl7YYAcY3iGPxQA==}
- engines: {node: '>=20'}
+ '@typeonce/[email protected]':
+ resolution: {integrity: sha512-ZuxJ4QsVGXuiRphmKQq63Dv2p58mww1nAoKPcH99tucO6GIqcFhp7up9OOjEB8eABjG+Xe2k6bIImrSUWaJNbQ==}
+ engines: {node: '>=22'}
- '@typeonce/[email protected]':
- resolution: {integrity: sha512-Ldn/hE/uUENVEoyrd29khH1hBHKJNTkwx5Tk2La4VUKSFjbvFHy8T6vjq3UwMK/EiaN0oLq4d3gVBqwqGsG/3A==}
- engines: {node: '>=20'}
+ '@typeonce/[email protected]':
+ resolution: {integrity: sha512-TQb3qz95nIviINN0Oz7AVfK5HNlIueeHswi1m3IdizPqA699LicWfB7zqu3Lstjk2jjY90ydkm7Kn/tbCgdx0w==}
+ engines: {node: '>=22'}
- '@typeonce/[email protected]':
- resolution: {integrity: sha512-x4/q1lkg1e2D14yi+Y2+pEyKCzJEgyi/lDKEOom7TDtEaTQ5ow/u24fhagNrpCz7XLnAODlC1GNwHo5dfP4OtQ==}
- engines: {node: '>=20'}
+ '@typeonce/[email protected]':
+ resolution: {integrity: sha512-T4lmbL4Jmg+A2B4mYACLlQoGHgxrvjKt/fyh4uFT25NjPHi+cvEcpAbhUBDnXl29u5SiI2nxpamTSJhtEJ8TJw==}
+ engines: {node: '>=22'}
- '@typeonce/[email protected]':
- resolution: {integrity: sha512-E3YThN6Z2BSKLk8buBq8/+k0/SQW0BNaZXtmnbmMl2zIq29w9jOx+EPOVSF4cbvYtAoBsIm20pLB3gFj092cGA==}
- engines: {node: '>=20'}
+ '@typeonce/[email protected]':
+ resolution: {integrity: sha512-D54ym3xSrp1LSM94cRYw87AIqIQT/yte1fidklxD9+We4fF3+rsVeu2z6fozjY81VE4Pml/pmMt1HDz7wQoi3Q==}
+ engines: {node: '>=22'}
peerDependencies:
typescript: '>=5.9'
peerDependenciesMeta:
@@ -596,12 +596,12 @@ packages:
engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1}
hasBin: true
- resolution: {integrity: sha512-drxVlaW7Oqq7wSy1CN25znRu00aRq8n57Q2wniJRxCmtYVz07ufCm7EVDPQFZURrTgQIjzKrVEHAD/HcvJXObg==}
+ resolution: {integrity: sha512-y9iRiRwVjVFqzKNXZJ9bT/GYRdf+F9Gy+a1Yju2Aq3xqqa4FJYXHI8VrxlpzxKDvkYRohvJX42m/eH+qkQPOFw==}
engines: {node: ^20.19.0 || >=22.12.0}
hasBin: true
peerDependencies:
- oxlint-tsgolint: '>=7.0.2003'
+ oxlint-tsgolint: '>=7.0.2005'
vite-plus: '*'
peerDependenciesMeta:
oxlint-tsgolint:
@@ -713,61 +713,61 @@ snapshots:
'@oxc-project/[email protected]': {}
- '@oxlint/[email protected]':
+ '@oxlint/[email protected]':
optional: true
- '@oxlint/[email protected]':
+ '@oxlint/[email protected]':
optional: true
- '@oxlint/[email protected]':
+ '@oxlint/[email protected]':
optional: true
- '@oxlint/[email protected]':
+ '@oxlint/[email protected]':
optional: true
- '@oxlint/[email protected]':
+ '@oxlint/[email protected]':
optional: true
- '@oxlint/[email protected]':
+ '@oxlint/[email protected]':
optional: true
- '@oxlint/[email protected]':
+ '@oxlint/[email protected]':
optional: true
- '@oxlint/[email protected]':
+ '@oxlint/[email protected]':
optional: true
- '@oxlint/[email protected]':
+ '@oxlint/[email protected]':
optional: true
- '@oxlint/[email protected]':
+ '@oxlint/[email protected]':
optional: true
- '@oxlint/[email protected]':
+ '@oxlint/[email protected]':
optional: true
- '@oxlint/[email protected]':
+ '@oxlint/[email protected]':
optional: true
- '@oxlint/[email protected]':
+ '@oxlint/[email protected]':
optional: true
- '@oxlint/[email protected]':
+ '@oxlint/[email protected]':
optional: true
- '@oxlint/[email protected]':
+ '@oxlint/[email protected]':
optional: true
- '@oxlint/[email protected]':
+ '@oxlint/[email protected]':
optional: true
- '@oxlint/[email protected]':
+ '@oxlint/[email protected]':
optional: true
- '@oxlint/[email protected]':
+ '@oxlint/[email protected]':
optional: true
- '@oxlint/[email protected]':
+ '@oxlint/[email protected]':
optional: true
'@oxlint/[email protected]': {}
@@ -823,54 +823,54 @@ snapshots:
'@tweenjs/[email protected]': {}
dependencies:
'@oxlint/plugins': 1.88.0
- oxlint: 1.87.0
+ oxlint: 1.92.0
dependencies:
- '@typeonce/ritmo': 0.16.1([email protected])
+ '@typeonce/ritmo': 0.22.0([email protected])
transitivePeerDependencies:
- typescript
dependencies:
- '@typeonce/ritmo': 0.16.1([email protected])
- '@typeonce/ritmo-netcode': 0.16.1([email protected])
+ '@typeonce/ritmo': 0.22.0([email protected])
+ '@typeonce/ritmo-netcode': 0.22.0([email protected])
optionalDependencies:
- oxlint: 1.87.0
+ oxlint: 1.92.0
playwright: 1.64.0
rolldown: 1.2.13
vite: 8.3.1(@types/[email protected])
transitivePeerDependencies:
- typescript
dependencies:
- '@typeonce/ritmo': 0.16.1([email protected])
+ '@typeonce/ritmo': 0.22.0([email protected])
transitivePeerDependencies:
- typescript
dependencies:
- '@typeonce/ritmo': 0.16.1([email protected])
+ '@typeonce/ritmo': 0.22.0([email protected])
transitivePeerDependencies:
- typescript
dependencies:
- '@typeonce/ritmo-render': 0.16.1([email protected])
+ '@typeonce/ritmo-render': 0.22.0([email protected])
transitivePeerDependencies:
- typescript
dependencies:
- '@typeonce/ritmo': 0.16.1([email protected])
+ '@typeonce/ritmo': 0.22.0([email protected])
transitivePeerDependencies:
- typescript
optionalDependencies:
typescript: 7.0.2
@@ -1035,27 +1035,27 @@ snapshots:
optionalDependencies:
- '@oxlint/binding-android-arm-eabi': 1.87.0
- '@oxlint/binding-android-arm64': 1.87.0
- '@oxlint/binding-darwin-arm64': 1.87.0
- '@oxlint/binding-darwin-x64': 1.87.0
- '@oxlint/binding-freebsd-x64': 1.87.0
- '@oxlint/binding-linux-arm-gnueabihf': 1.87.0
- '@oxlint/binding-linux-arm-musleabihf': 1.87.0
- '@oxlint/binding-linux-arm64-gnu': 1.87.0
- '@oxlint/binding-linux-arm64-musl': 1.87.0
- '@oxlint/binding-linux-ppc64-gnu': 1.87.0
- '@oxlint/binding-linux-riscv64-gnu': 1.87.0
- '@oxlint/binding-linux-riscv64-musl': 1.87.0
- '@oxlint/binding-linux-s390x-gnu': 1.87.0
- '@oxlint/binding-linux-x64-gnu': 1.87.0
- '@oxlint/binding-linux-x64-musl': 1.87.0
- '@oxlint/binding-openharmony-arm64': 1.87.0
- '@oxlint/binding-win32-arm64-msvc': 1.87.0
- '@oxlint/binding-win32-ia32-msvc': 1.87.0
- '@oxlint/binding-win32-x64-msvc': 1.87.0
+ '@oxlint/binding-android-arm-eabi': 1.92.0
+ '@oxlint/binding-android-arm64': 1.92.0
+ '@oxlint/binding-darwin-arm64': 1.92.0
+ '@oxlint/binding-darwin-x64': 1.92.0
+ '@oxlint/binding-freebsd-x64': 1.92.0
+ '@oxlint/binding-linux-arm-gnueabihf': 1.92.0
+ '@oxlint/binding-linux-arm-musleabihf': 1.92.0
+ '@oxlint/binding-linux-arm64-gnu': 1.92.0
+ '@oxlint/binding-linux-arm64-musl': 1.92.0
+ '@oxlint/binding-linux-ppc64-gnu': 1.92.0
+ '@oxlint/binding-linux-riscv64-gnu': 1.92.0
+ '@oxlint/binding-linux-riscv64-musl': 1.92.0
+ '@oxlint/binding-linux-s390x-gnu': 1.92.0
+ '@oxlint/binding-linux-x64-gnu': 1.92.0
+ '@oxlint/binding-linux-x64-musl': 1.92.0
+ '@oxlint/binding-openharmony-arm64': 1.92.0
+ '@oxlint/binding-win32-arm64-msvc': 1.92.0
+ '@oxlint/binding-win32-ia32-msvc': 1.92.0
+ '@oxlint/binding-win32-x64-msvc': 1.92.0
diff --git a/src/game/systems/decay/decay.ts b/src/game/systems/decay/decay.ts
index fde9c17..1ae3e14 100644
--- a/src/game/systems/decay/decay.ts
+++ b/src/game/systems/decay/decay.ts
@@ -42,15 +42,17 @@ export const Decay = Game.System(
// Wear: a point every `wear.every` steps; at nothing it falls down.
if (tick % wear.every === 0) {
- const landmarks = queries.landmarks.each().map(({ data }) => ({ kind: data.building.get().kind, ...data.tile.get() }))
- for (const { entity, data } of queries.worn.each()) {
- const value = data.condition.get().value - 1
+ const landmark = queries.landmarks.data
+ const landmarks = queries.landmarks.each().map((entity) => ({ kind: landmark.building.get(entity).kind, ...landmark.tile.get(entity) }))
+ const worn = queries.worn.data
+ for (const entity of queries.worn.each()) {
+ const value = worn.condition.get(entity).value - 1
if (value > 0) {
- data.condition.set({ value })
+ worn.condition.set(entity, { value })
continue
}
- const tile = data.tile.get()
- const b = data.building.value()
+ const tile = worn.tile.get(entity)
+ const b = worn.building.get(entity)
commands.despawn(entity)
commands.spawn(ruinDraft(tile, "collapsed"))
write(
@@ -67,9 +69,10 @@ export const Decay = Game.System(
if (tick % SPOIL_TICKS === 0) {
const random = Random.draw(resources.rng)
let rotted = 0
- for (const { data } of queries.shelves.each()) {
- const inv = data.inventory.get()
- const keeps = kinds[data.building.value()?.kind ?? "townhall"].keeps ?? 1
+ const { data } = queries.shelves
+ for (const entity of queries.shelves.each()) {
+ const inv = data.inventory.get(entity)
+ const keeps = kinds[data.building.get(entity)?.kind ?? "townhall"].keeps ?? 1
let stock = inv.stock
for (const g of goodIds) {
const life = spoils[g]
@@ -80,7 +83,7 @@ export const Decay = Game.System(
stock = { ...stock, [g]: stock[g] - lose }
rotted += lose
}
- if (stock !== inv.stock) data.inventory.set({ ...inv, stock })
+ if (stock !== inv.stock) data.inventory.set(entity, { ...inv, stock })
}
if (rotted > 0) resources.pantry.update((p) => ({ ...p, rotted: p.rotted + rotted }))
}
@@ -92,9 +95,10 @@ export const Decay = Game.System(
if (warn) {
// What the town could make of food a minute with the crews it has, against what it ate: rot is the difference, not a want of granaries.
let made = 0
- for (const { data } of queries.makers.each()) {
- const r = data.recipe.get()
- if (data.staff.get().assigned > 0 && (foods as ReadonlyArray<string>).includes(r.output)) made += (r.batch * 3600) / r.period
+ const { data } = queries.makers
+ for (const entity of queries.makers.each()) {
+ const r = data.recipe.get(entity)
+ if (data.staff.get(entity).assigned > 0 && (foods as ReadonlyArray<string>).includes(r.output)) made += (r.batch * 3600) / r.period
}
const cause = made > p.eaten * 1.5
? `the town makes about ${Math.round(made)} food a minute and eats ${p.eaten}: fewer fisheries, a smokehouse, or selling fish would stop the waste`
diff --git a/src/game/systems/edits/apply-edits.ts b/src/game/systems/edits/apply-edits.ts
index 276f22f..a51c843 100644
--- a/src/game/systems/edits/apply-edits.ts
+++ b/src/game/systems/edits/apply-edits.ts
@@ -91,13 +91,14 @@ export const ApplyEdits = Game.System(
if (queued.length === 0) return
const grid = new GridBuilder(resources.land.get().mask)
const rows = queries.tiles.each()
- type Id = (typeof rows)[number]["entity"]["id"]
+ type Id = (typeof rows)[number]["id"]
const entities = new Map<number, Id>()
- for (const { entity, data } of rows) {
- grid.claim(data.tile.get(), entity.id, useOf(data))
+ const { data: tiles } = queries.tiles
+ for (const entity of rows) {
+ grid.claim(tiles.tile.get(entity), entity.id, useOf(entity, tiles))
entities.set(entity.id, entity.id)
}
- const halls = new Set<number>(queries.halls.each().map((row) => row.entity.id))
+ const halls = new Set<number>(queries.halls.each().map((row) => row.id))
let coins = resources.treasury.get().coins
// Works begun in this step: they are in the world only once it ends, so a second click on the same building is refused here.
const begun = new Set<number>()
@@ -113,15 +114,16 @@ export const ApplyEdits = Game.System(
coins -= cost.coins
for (const [g, n] of Object.entries(cost.materials)) left[g] = (left[g] ?? 0) - (n ?? 0)
}
+ const { data: stores } = queries.stores
/** Takes goods out of storage at once, fullest first. */
const take = (materials: Partial<Record<string, number>>) => {
for (const [g, n] of Object.entries(materials) as Array<[keyof Amounts, number]>) {
let owed = n
- for (const { data } of [...queries.stores.each()].sort((a, b) => b.data.inventory.get().stock[g] - a.data.inventory.get().stock[g])) {
+ for (const store of [...queries.stores.each()].sort((a, b) => stores.inventory.get(b).stock[g] - stores.inventory.get(a).stock[g])) {
if (owed <= 0) break
- const inv = data.inventory.get()
+ const inv = stores.inventory.get(store)
const n = Math.min(owed, inv.stock[g])
- data.inventory.set({ ...inv, stock: { ...inv.stock, [g]: inv.stock[g] - n } })
+ stores.inventory.set(store, { ...inv, stock: { ...inv.stock, [g]: inv.stock[g] - n } })
owed -= n
}
}
@@ -131,11 +133,11 @@ export const ApplyEdits = Game.System(
let lost = 0
for (const [g, n] of Object.entries(materials) as Array<[keyof Amounts, number]>) {
let owed = n
- for (const { data } of [...queries.stores.each()].sort((a, b) => a.data.inventory.get().stock[g] - b.data.inventory.get().stock[g])) {
+ for (const store of [...queries.stores.each()].sort((a, b) => stores.inventory.get(a).stock[g] - stores.inventory.get(b).stock[g])) {
if (owed <= 0) break
- const inv = data.inventory.get()
+ const inv = stores.inventory.get(store)
const k = Math.max(0, Math.min(owed, inv.cap - inv.stock[g]))
- if (k > 0) data.inventory.set({ ...inv, stock: { ...inv.stock, [g]: inv.stock[g] + k } })
+ if (k > 0) stores.inventory.set(store, { ...inv, stock: { ...inv.stock, [g]: inv.stock[g] + k } })
left[g] = (left[g] ?? 0) + k
owed -= k
}
@@ -149,7 +151,7 @@ export const ApplyEdits = Game.System(
if (useAt(grid.value(), c.x, c.y) !== "tree") continue
const tree = entities.get(ownerAt(grid.value(), c.x, c.y))
const row = tree === undefined ? undefined : queries.tiles.get(tree)
- if (row?.ok) commands.despawn(row.value.entity)
+ if (row?.ok) commands.despawn(row.value)
}
}
/**
@@ -230,7 +232,7 @@ export const ApplyEdits = Game.System(
}
case "pave": {
// Stone comes out of storage at once, fullest first.
- const paved = new Set<number>(queries.paved.each().map((row) => row.entity.id))
+ const paved = new Set<number>(queries.paved.each().map((row) => row.id))
let short: string | null = null
let stone = 0
for (const cell of edit.cells) {
@@ -252,18 +254,19 @@ export const ApplyEdits = Game.System(
case "ground": {
// Park needs no road: it is laid at once, its materials straight out of storage.
const piece = grounds[edit.ground]
- const parks = new Map(queries.parks.each().map((row) => [row.entity.id as number, row] as const))
+ const { data: park } = queries.parks
+ const parks = new Map(queries.parks.each().map((row) => [row.id as number, row] as const))
let short: string | null = null
const spent: Record<string, number> = {}
for (const cell of edit.cells) {
const tile = { ...cell, size: 1 }
const relay = useAt(grid.value(), cell.x, cell.y) === "park" ? parks.get(ownerAt(grid.value(), cell.x, cell.y)) : undefined
- if (relay ? relay.data.park.get().ground === edit.ground : !canPlace(grid.value(), tile)) continue
+ if (relay ? park.park.get(relay).ground === edit.ground : !canPlace(grid.value(), tile)) continue
short = afford(piece.cost)
if (short) break
pay(piece.cost)
for (const [g, n] of Object.entries(piece.cost.materials)) spent[g] = (spent[g] ?? 0) + (n ?? 0)
- if (relay) relay.data.park.set({ ...relay.data.park.get(), ground: edit.ground })
+ if (relay) park.park.set(relay, { ...park.park.get(relay), ground: edit.ground })
else {
const id = place(tile, "park", () => commands.spawn(parkDraft(cell, edit.ground)))
queuedHere.set(id, () => commands.despawn(id))
@@ -280,13 +283,14 @@ export const ApplyEdits = Game.System(
break
}
const row = useAt(grid.value(), edit.cell.x, edit.cell.y) === "park"
- ? queries.parks.each().find((r) => r.entity.id === ownerAt(grid.value(), edit.cell.x, edit.cell.y))
+ ? queries.parks.each().find((r) => r.id === ownerAt(grid.value(), edit.cell.x, edit.cell.y))
: undefined
if (!row) {
events.toast.emit("Lay park ground first")
break
}
- if (row.data.park.get().prop === edit.prop) break
+ const { data: park } = queries.parks
+ if (park.park.get(row).prop === edit.prop) break
const short = afford(piece.cost)
if (short) {
events.toast.emit(short)
@@ -294,7 +298,7 @@ export const ApplyEdits = Game.System(
}
pay(piece.cost)
take(piece.cost.materials)
- row.data.park.set({ ...row.data.park.get(), prop: edit.prop })
+ park.park.set(row, { ...park.park.get(row), prop: edit.prop })
break
}
case "remove": {
@@ -305,7 +309,7 @@ export const ApplyEdits = Game.System(
// A rock goes only once it is quarried down to a worked face, and gives nothing more after.
if (use === "rock") {
const rock = queries.rocks.get(owner)
- if (!rock.ok || rock.value.data.rock.get().amount > 1) {
+ if (!rock.ok || queries.rocks.data.rock.get(rock.value).amount > 1) {
events.toast.emit("Quarry it down first: only a worked face can be cleared")
break
}
@@ -315,17 +319,19 @@ export const ApplyEdits = Game.System(
break
}
// A park's furnishing goes before its ground.
- const furnished = use === "park" ? queries.parks.each().find((r) => r.entity.id === owner && r.data.park.get().prop !== "none") : undefined
+ const { data: park } = queries.parks
+ const furnished = use === "park" ? queries.parks.each().find((r) => r.id === owner && park.park.get(r).prop !== "none") : undefined
if (furnished) {
- furnished.data.park.set({ ...furnished.data.park.get(), prop: "none" })
+ park.park.set(furnished, { ...park.park.get(furnished), prop: "none" })
break
}
// A building or a home: a fee, and part of its materials back (a site's, all of it).
const built = queries.built.get(owner)
- if (built.ok && (built.value.data.building.present || built.value.data.house.present)) {
- const b = built.value.data.building.value()
- const own = salvageOf(b ? builtCost(kinds[b.kind], built.value.data.upgraded.value()?.level ?? 0) : home.cost, built.value.data.site.value()?.owed ?? null, rules)
- const s = b ? withWorks(own, kinds[b.kind], built.value.data.works.value(), rules) : own
+ const { data: was } = queries.built
+ if (built.ok && (was.building.has(built.value) || was.house.has(built.value))) {
+ const b = was.building.get(built.value)
+ const own = salvageOf(b ? builtCost(kinds[b.kind], was.upgraded.get(built.value)?.level ?? 0) : home.cost, was.site.get(built.value)?.owed ?? null, rules)
+ const s = b ? withWorks(own, kinds[b.kind], was.works.get(built.value), rules) : own
if (s.fee > 0 && coins < s.fee) {
events.toast.emit(`Pulling it down costs ${s.fee} coins`)
break
@@ -333,11 +339,11 @@ export const ApplyEdits = Game.System(
coins -= s.fee
const lost = stash(s.back)
const said = salvageText(s)
- if (said !== "") events.toast.emit(`${built.value.data.site.present ? "Cancelled" : "Pulled down"} · ${said}${lost > 0 ? ` (${lost} found no room in storage)` : ""}`)
+ if (said !== "") events.toast.emit(`${was.site.has(built.value) ? "Cancelled" : "Pulled down"} · ${said}${lost > 0 ? ` (${lost} found no room in storage)` : ""}`)
}
// A building's walkers and a farm's fields are its children, and go with it.
const gone = queries.tiles.get(owner)
- if (gone.ok) commands.despawn(gone.value.entity)
+ if (gone.ok) commands.despawn(gone.value)
else queuedHere.get(owner)?.()
queuedHere.delete(owner)
entities.delete(owner)
@@ -366,10 +372,11 @@ export const ApplyEdits = Game.System(
// A building stops work; a home is closed, and stands empty (see `Households`).
const id = entities.get(owner)
const row = id === undefined ? undefined : queries.built.get(id)
- if (!row?.ok || halls.has(owner) || row.value.data.site.present || row.value.data.paused.present === edit.on) break
- if (!row.value.data.building.present && !row.value.data.house.present) break
- if (edit.on) commands.insert(row.value.entity, Game.Command.entry(Paused, {}))
- else commands.remove(row.value.entity, Paused)
+ const { data: built } = queries.built
+ if (!row?.ok || halls.has(owner) || built.site.has(row.value) || built.paused.has(row.value) === edit.on) break
+ if (!built.building.has(row.value) && !built.house.has(row.value)) break
+ if (edit.on) commands.insert(row.value, Game.Command.entry(Paused, {}))
+ else commands.remove(row.value, Paused)
break
}
case "deliver": {
@@ -380,11 +387,11 @@ export const ApplyEdits = Game.System(
break
}
let owed = c.amount
- for (const { data } of [...queries.stores.each()].sort((a, b) => b.data.inventory.get().stock[c.good] - a.data.inventory.get().stock[c.good])) {
+ for (const store of [...queries.stores.each()].sort((a, b) => stores.inventory.get(b).stock[c.good] - stores.inventory.get(a).stock[c.good])) {
if (owed <= 0) break
- const inv = data.inventory.get()
+ const inv = stores.inventory.get(store)
const take = Math.min(owed, inv.stock[c.good])
- data.inventory.set({ ...inv, stock: { ...inv.stock, [c.good]: inv.stock[c.good] - take } })
+ stores.inventory.set(store, { ...inv, stock: { ...inv.stock, [c.good]: inv.stock[c.good] - take } })
owed -= take
}
left[c.good] = (left[c.good] ?? 0) - c.amount
@@ -423,11 +430,11 @@ export const ApplyEdits = Game.System(
const id = entities.get(ownerAt(grid.value(), edit.cell.x, edit.cell.y))
const row = id === undefined ? undefined : queries.upgradable.get(id)
if (!row?.ok) break
- const { data } = row.value
- const kind = kinds[data.building.get().kind]
- const level = data.upgraded.value()?.level ?? 0
+ const { data } = queries.upgradable
+ const kind = kinds[data.building.get(row.value).kind]
+ const level = data.upgraded.get(row.value)?.level ?? 0
const up = nextUpgrade(kind, level)
- if (!up || data.works.present || begun.has(row.value.entity.id) || data.site.present || data.rising.present) break
+ if (!up || data.works.has(row.value) || begun.has(row.value.id) || data.site.has(row.value) || data.rising.has(row.value)) break
const blocked = upgradeBlock(up, resources.fate.get().rank, rules)
if (blocked) {
events.toast.emit(`${up.title} ${blocked}`)
@@ -438,9 +445,9 @@ export const ApplyEdits = Game.System(
break
}
coins -= up.cost.coins
- begun.add(row.value.entity.id)
+ begun.add(row.value.id)
const owed = amounts(up.cost.materials)
- commands.insert(row.value.entity, Game.Command.entry(Works, { owed, total: total(owed), done: 0, level: (level + 1) as 1 | 2 }))
+ commands.insert(row.value, Game.Command.entry(Works, { owed, total: total(owed), done: 0, level: (level + 1) as 1 | 2 }))
const was = (upgradeAt(kind, level)?.title ?? kind.title).toLowerCase()
write(resources.chronicle, t, `Works begin on the ${was}: it is to be ${anA(up.title.toLowerCase())}.`)
events.toast.emit(`${up.title} · −${up.cost.coins} coins · carriers bring ${costText({ coins: 0, materials: up.cost.materials })}`)
@@ -459,7 +466,7 @@ export const ApplyEdits = Game.System(
resources.policy.update((p) => ({ ...p, reserve: Math.max(0, Math.min(RESERVE_MAX, Math.round(edit.amount))) }))
break
case "newTown": {
- for (const { entity } of rows) commands.despawn(entity)
+ for (const entity of rows) commands.despawn(entity)
for (const drop of queuedHere.values()) drop()
queuedHere.clear()
entities.clear()
diff --git a/src/game/systems/hazards/appraise.ts b/src/game/systems/hazards/appraise.ts
index c997033..5c5cde0 100644
--- a/src/game/systems/hazards/appraise.ts
+++ b/src/game/systems/hazards/appraise.ts
@@ -25,19 +25,22 @@ export const Appraise = Game.System(
if (!every(resources.time.get(), appeal.every) && resources.appeal.get().cells.length > 0) return
const sources: Array<AppealSource> = []
- for (const { data } of queries.buildings.each()) {
- const s = buildingSource(data.building.get().kind, data.tile.get(), rules, data.upgraded.value()?.level ?? 0)
+ const { data: buildings } = queries.buildings
+ for (const entity of queries.buildings.each()) {
+ const s = buildingSource(buildings.building.get(entity).kind, buildings.tile.get(entity), rules, buildings.upgraded.get(entity)?.level ?? 0)
if (s) sources.push(s)
}
- for (const { data } of queries.trees.each()) sources.push(landSource("forest", data.tile.get(), rules))
- for (const { data } of queries.water.each()) sources.push(landSource("water", data.tile.get(), rules))
- for (const { data } of queries.paved.each()) sources.push(landSource("paved", data.tile.get(), rules))
- const roads = new Set(queries.roads.each().map(({ data }) => `${data.tile.get().x},${data.tile.get().y}`))
- sources.push(...parkSources(queries.parks.each().map(({ data }) => ({ ...data.tile.get(), ...data.park.get() })), (x, y) => roads.has(`${x},${y}`), rules))
- for (const { data } of queries.ruins.each()) sources.push(landSource("ruin", data.tile.get(), rules))
- for (const { data } of queries.homes.each()) {
- if (data.condition.get().value < wear.worn) sources.push(landSource("worn", data.tile.get(), rules))
- const fine = data.closed.present ? null : homeSource(data.house.get().tier, data.tile.get(), rules)
+ for (const entity of queries.trees.each()) sources.push(landSource("forest", queries.trees.data.tile.get(entity), rules))
+ for (const entity of queries.water.each()) sources.push(landSource("water", queries.water.data.tile.get(entity), rules))
+ for (const entity of queries.paved.each()) sources.push(landSource("paved", queries.paved.data.tile.get(entity), rules))
+ const roads = new Set(queries.roads.each().map((entity) => `${queries.roads.data.tile.get(entity).x},${queries.roads.data.tile.get(entity).y}`))
+ const { data: parks } = queries.parks
+ sources.push(...parkSources(queries.parks.each().map((entity) => ({ ...parks.tile.get(entity), ...parks.park.get(entity) })), (x, y) => roads.has(`${x},${y}`), rules))
+ for (const entity of queries.ruins.each()) sources.push(landSource("ruin", queries.ruins.data.tile.get(entity), rules))
+ const { data: homes } = queries.homes
+ for (const entity of queries.homes.each()) {
+ if (homes.condition.get(entity).value < wear.worn) sources.push(landSource("worn", homes.tile.get(entity), rules))
+ const fine = homes.closed.has(entity) ? null : homeSource(homes.house.get(entity).tier, homes.tile.get(entity), rules)
if (fine) sources.push(fine)
}
resources.appeal.set({ cells: appealGrid(sources, rules) })
diff --git a/src/game/systems/hazards/douse.ts b/src/game/systems/hazards/douse.ts
index 6c38762..d57a52d 100644
--- a/src/game/systems/hazards/douse.ts
+++ b/src/game/systems/hazards/douse.ts
@@ -15,9 +15,10 @@ export const Douse = Game.System(
commands: Game.System.commands(Game.System.spawns(Ruin), Game.System.despawns(Rescue, Burning))
},
({ queries, resources, commands }) => {
- for (const { entity, data } of queries.crews.each()) {
- const route = data.route.get()
- const rescue = data.rescue.get()
+ const { data } = queries.crews
+ for (const entity of queries.crews.each()) {
+ const route = data.route.get(entity)
+ const rescue = data.rescue.get(entity)
const arrived = route.index >= route.cells.length - 1
if (!arrived) continue
if (rescue.back) {
@@ -26,17 +27,18 @@ export const Douse = Game.System(
}
const target = queries.burning.getHandle(rescue.target)
if (target.ok) {
- const b = target.value.data.burning.get()
- commands.despawn(target.value.entity)
- commands.spawn(ruinDraft(target.value.data.tile.get(), "burnt"))
- const house = target.value.data.house.present
+ const burning = queries.burning.data
+ const b = burning.burning.get(target.value)
+ commands.despawn(target.value)
+ commands.spawn(ruinDraft(burning.tile.get(target.value), "burnt"))
+ const house = burning.house.has(target.value)
resources.fires.update((f) => ({
...f,
fires: f.fires.map((x) => (x.id === b.fire ? { ...x, homes: x.homes + (house ? 1 : 0), buildings: x.buildings + (house ? 0 : 1) } : x))
}))
}
- data.route.set({ cells: [...route.cells].reverse(), index: 0, step: 0 })
- data.rescue.set({ ...rescue, back: true })
+ data.route.set(entity, { cells: [...route.cells].reverse(), index: 0, step: 0 })
+ data.rescue.set(entity, { ...rescue, back: true })
}
}
)
diff --git a/src/game/systems/hazards/hazards.ts b/src/game/systems/hazards/hazards.ts
index a8bccd8..b5b0ea2 100644
--- a/src/game/systems/hazards/hazards.ts
+++ b/src/game/systems/hazards/hazards.ts
@@ -74,48 +74,48 @@ export const Hazards = Game.System(
const heating = season.severity !== null && winters[season.severity].heating
const random = Random.draw(resources.rng)
const news = (text: string, at: Point | null = null) => write(resources.chronicle, t, text, true, at)
- const landmarks: Array<Landmark> = queries.landmarks.each().map(({ data }) => ({ kind: data.building.get().kind, ...data.tile.get() }))
+ const landmarks: Array<Landmark> = queries.landmarks.each().map((entity) => ({ kind: queries.landmarks.data.building.get(entity).kind, ...queries.landmarks.data.tile.get(entity) }))
const where = (cell: Point) => placeName(landmarks, cell)
const fires = { ...resources.fires.get(), fires: resources.fires.get().fires.map((f) => ({ ...f })) }
const rows = queries.cared.each()
- const hot = rows.filter(({ data }) => {
- const b = data.building.value()
- return b !== undefined && kinds[b.kind].hot === true && !data.burning.present
- }).map(({ data }) => data.tile.get())
+ const { data: cared } = queries.cared
+ const hot = rows.filter((row) => {
+ const b = cared.building.get(row)
+ return b !== undefined && kinds[b.kind].hot === true && !cared.burning.has(row)
+ }).map((row) => cared.tile.get(row))
const dusty = landmarks.filter((l) => kinds[l.kind].dusty)
const waterNear = (tile: { readonly x: number; readonly y: number }) => {
for (let dy = -2; dy <= 2; dy++) for (let dx = -2; dx <= 2; dx++) if (useAt(grid, tile.x + dx, tile.y + dy) === "water") return true
return false
}
- const sickNow = rows.filter(({ data }) => data.sick.present).length
+ const sickNow = rows.filter((row) => cared.sick.has(row)).length
/** Turns a home or building into a ruin. */
const ruin = (row: (typeof rows)[number], cause: "burnt" | "collapsed" | "derelict") => {
- commands.despawn(row.entity)
- commands.spawn(ruinDraft(row.data.tile.get(), cause))
+ commands.despawn(row)
+ commands.spawn(ruinDraft(cared.tile.get(row), cause))
}
const lost = new Set<number>()
const ignited = new Map<number, number>()
// Rising risks, and what comes of them.
for (const row of rows) {
- const { data } = row
- if (data.burning.present) continue
- const tile = data.tile.get()
- const h = data.house.value()
+ if (cared.burning.has(row)) continue
+ const tile = cared.tile.get(row)
+ const h = cared.house.get(row)
// A closed home has nobody in it to fall sick, steal, or knock over a lamp.
- if (h && data.paused.present) continue
- const b = data.building.value()
- const r = { ...data.risk.get() }
+ if (h && cared.paused.has(row)) continue
+ const b = cared.building.get(row)
+ const r = { ...cared.risk.get(row) }
const increments = riskIncrements({
- tile, condition: data.condition.get().value, desirability: appealAt(cells, tile.x, tile.y), approval, heating,
+ tile, condition: cared.condition.get(row).value, desirability: appealAt(cells, tile.x, tile.y), approval, heating,
hotNearby: hot.filter((source) => near(source, tile, risk.fire.reach)).length,
dusty: dusty.some((d) => near(d, tile, risk.health.reach)), water: waterNear(tile),
...(h ? { house: h } : {}), ...(b ? { kind: b.kind } : {})
}, rules)
if (h) {
- if (!data.sick.present) r.health = Math.min(RISK_MAX, r.health + increments.health)
+ if (!cared.sick.has(row)) r.health = Math.min(RISK_MAX, r.health + increments.health)
r.order = Math.min(RISK_MAX, r.order + increments.order)
}
r.fire = Math.min(RISK_MAX, r.fire + increments.fire)
@@ -125,13 +125,13 @@ export const Hazards = Game.System(
const id = fires.next
fires.next += 1
fires.fires.push({ id, x: tile.x, y: tile.y, homes: 0, buildings: 0 })
- commands.insert(row.entity, Game.Command.entry(Burning, { left: risk.fire.burns, fire: id }))
- ignited.set(row.entity.id, id)
+ commands.insert(row, Game.Command.entry(Burning, { left: risk.fire.burns, fire: id }))
+ ignited.set(row.id, id)
r.fire = 0
news(`Fire on ${where(tile)}!`, tile)
}
- if (h && r.health >= RISK_MAX && !data.sick.present) {
- commands.insert(row.entity, Game.Command.entry(Sick, { left: risk.health.lasts }))
+ if (h && r.health >= RISK_MAX && !cared.sick.has(row)) {
+ commands.insert(row, Game.Command.entry(Sick, { left: risk.health.lasts }))
r.health = 0
if (sickNow === 0) news(`Sickness on ${where(tile)}: a physician can cure it.`, tile)
}
@@ -145,14 +145,15 @@ export const Hazards = Game.System(
news(`Thieves on ${where(tile)} made off with ${take} coins.`, tile)
} else {
const stores = queries.stores.each()
- const held = (g: GoodId) => stores.reduce((n, s) => n + s.data.inventory.get().stock[g], 0)
+ const { data: store } = queries.stores
+ const held = (g: GoodId) => stores.reduce((n, s) => n + store.inventory.get(s).stock[g], 0)
const good = [...goodIds].sort((a, b) => held(b) * goods[b].price - held(a) * goods[a].price)[0]!
let owed = Math.min(risk.order.goods, held(good))
- for (const { data: s } of stores) {
+ for (const s of stores) {
if (owed <= 0) break
- const inv = s.inventory.get()
+ const inv = store.inventory.get(s)
const n = Math.min(owed, inv.stock[good])
- s.inventory.set({ ...inv, stock: { ...inv.stock, [good]: inv.stock[good] - n } })
+ store.inventory.set(s, { ...inv, stock: { ...inv.stock, [good]: inv.stock[good] - n } })
owed -= n
}
if (held(good) > 0) news(`Thieves on ${where(tile)} made off with ${goods[good].title}.`, tile)
@@ -162,38 +163,40 @@ export const Hazards = Game.System(
} else {
news(`A home on ${where(tile)} stood empty after its thefts, and is left derelict.`, tile)
ruin(row, "derelict")
- lost.add(row.entity.id)
+ lost.add(row.id)
continue
}
}
- data.risk.set(r)
+ cared.risk.set(row, r)
}
// Sickness runs its course, and spreads to homes close by.
- const homeRows = rows.filter(({ entity, data }) => data.house.present && !data.burning.present && !lost.has(entity.id))
- for (const { entity, data } of queries.sickness.each()) {
- const s = data.sick.get()
+ const homeRows = rows.filter((row) => cared.house.has(row) && !cared.burning.has(row) && !lost.has(row.id))
+ const { data: sickness } = queries.sickness
+ for (const entity of queries.sickness.each()) {
+ const s = sickness.sick.get(entity)
const left = s.left - RISK_TICKS
if (left <= 0) {
commands.remove(entity, Sick)
continue
}
- data.sick.set({ left })
+ sickness.sick.set(entity, { left })
if (random.next() >= risk.health.spreads) continue
- const me = rows.find((row) => row.entity.id === entity.id)
+ const me = rows.find((row) => row.id === entity.id)
if (!me) continue
- const at = me.data.tile.get()
- const target = random.pick(homeRows.filter(({ entity: e, data: d }) => e.id !== entity.id && !d.sick.present && near(d.tile.get(), at, 2)))
+ const at = cared.tile.get(me)
+ const target = random.pick(homeRows.filter((e) => e.id !== entity.id && !cared.sick.has(e) && near(cared.tile.get(e), at, 2)))
if (target) {
- const r = target.data.risk.get()
- target.data.risk.set({ ...r, health: Math.min(RISK_MAX, r.health + risk.health.contagion) })
+ const r = cared.risk.get(target)
+ cared.risk.set(target, { ...r, health: Math.min(RISK_MAX, r.health + risk.health.contagion) })
}
}
// Fires burn down what they hold, and catch what stands beside them.
- const byId = new Map(rows.map((row) => [row.entity.id as number, row]))
- for (const { entity, data } of queries.blazes.each()) {
- const b = data.burning.get()
+ const byId = new Map(rows.map((row) => [row.id as number, row]))
+ const { data: blazes } = queries.blazes
+ for (const entity of queries.blazes.each()) {
+ const b = blazes.burning.get(entity)
const row = byId.get(entity.id)
if (!row) continue
const fire = fires.fires.find((f) => f.id === b.fire)
@@ -202,60 +205,62 @@ export const Hazards = Game.System(
ruin(row, "burnt")
lost.add(entity.id)
if (fire) {
- if (row.data.house.present) fire.homes += 1
+ if (cared.house.has(row)) fire.homes += 1
else fire.buildings += 1
}
continue
}
- data.burning.set({ ...b, left })
- const tile = row.data.tile.get()
- const neighbour = random.pick(rows.filter(({ entity: e, data: d }) => e.id !== entity.id && !d.burning.present && !ignited.has(e.id) && !lost.has(e.id) && near(d.tile.get(), tile, 1)))
+ blazes.burning.set(entity, { ...b, left })
+ const tile = cared.tile.get(row)
+ const neighbour = random.pick(rows.filter((e) => e.id !== entity.id && !cared.burning.has(e) && !ignited.has(e.id) && !lost.has(e.id) && near(cared.tile.get(e), tile, 1)))
if (!neighbour) continue
- const chance = risk.fire.catches + (risk.fire.spread * neighbour.data.risk.get().fire) / RISK_MAX
+ const chance = risk.fire.catches + (risk.fire.spread * cared.risk.get(neighbour).fire) / RISK_MAX
if (random.next() < chance) {
- commands.insert(neighbour.entity, Game.Command.entry(Burning, { left: risk.fire.burns, fire: b.fire }))
- ignited.set(neighbour.entity.id, b.fire)
+ commands.insert(neighbour, Game.Command.entry(Burning, { left: risk.fire.burns, fire: b.fire }))
+ ignited.set(neighbour.id, b.fire)
}
}
// Firefighters run from the nearest fire watch to every blaze no one is running to.
const out = new Map<number, number>()
const crewed = new Set<number>()
- for (const { data } of queries.crews.each()) {
- out.set(data.home.get(), (out.get(data.home.get()) ?? 0) + 1)
- if (!data.rescue.get().back) crewed.add(data.rescue.get().target)
+ const { data: crews } = queries.crews
+ for (const entity of queries.crews.each()) {
+ out.set(crews.home.get(entity), (out.get(crews.home.get(entity)) ?? 0) + 1)
+ if (!crews.rescue.get(entity).back) crewed.add(crews.rescue.get(entity).target)
}
- const watches = queries.watches.each().filter(({ data }) => data.service.get().service === "fire" && data.staff.get().assigned > 0)
- const burningNow = [...queries.blazes.each().map(({ entity }) => entity.id as number), ...ignited.keys()].filter((id) => !lost.has(id))
+ const { data: watch } = queries.watches
+ const watches = queries.watches.each().filter((entity) => watch.service.get(entity).service === "fire" && watch.staff.get(entity).assigned > 0)
+ const burningNow = [...queries.blazes.each().map((entity) => entity.id as number), ...ignited.keys()].filter((id) => !lost.has(id))
for (const id of burningNow) {
if (crewed.has(id)) continue
const target = byId.get(id)
if (!target) continue
- const goal = doors(grid, target.data.tile.get())
+ const goal = doors(grid, cared.tile.get(target))
let best: { readonly watch: (typeof watches)[number]; readonly roads: ReturnType<typeof reach>; readonly cell: Point; readonly distance: number } | null = null
- for (const watch of watches) {
+ for (const station of watches) {
// A fire brigade sends more (see `Upgrade.crews`).
- const crews = upgradeAt(kinds.firewatch, watch.data.upgraded.value()?.level ?? 0)?.crews ?? risk.fire.crews
- if ((out.get(watch.entity.id) ?? 0) >= crews) continue
- const starts = doors(grid, watch.data.tile.get())
+ const sends = upgradeAt(kinds.firewatch, watch.upgraded.get(station)?.level ?? 0)?.crews ?? risk.fire.crews
+ if ((out.get(station.id) ?? 0) >= sends) continue
+ const starts = doors(grid, watch.tile.get(station))
if (starts.length === 0) continue
const roads = reach(grid, starts)
const found = nearest(roads, goal)
- if (found && (best === null || found.distance < best.distance)) best = { watch, roads, ...found }
+ if (found && (best === null || found.distance < best.distance)) best = { watch: station, roads, ...found }
}
if (!best) continue
const draft = Game.Command.spawn(
[Figure, { role: "walker", color: 0xc4523f }],
[Route, { cells: pathTo(best.roads, best.cell), index: 0, step: 0 }],
- [Rescue, { target: Game.Entity.handle(target.entity.id, Tile), back: false }]
+ [Rescue, { target: Game.Entity.handle(target.id, Tile), back: false }]
)
- commands.spawn(Game.Command.relate(draft, WalkerOf, best.watch.entity.id))
- out.set(best.watch.entity.id, (out.get(best.watch.entity.id) ?? 0) + 1)
+ commands.spawn(Game.Command.relate(draft, WalkerOf, best.watch.id))
+ out.set(best.watch.id, (out.get(best.watch.id) ?? 0) + 1)
}
// A fire with nothing left burning is over: the news says what it took.
const stillBurning = new Set<number>()
- for (const { entity, data } of queries.blazes.each()) if (!lost.has(entity.id)) stillBurning.add(data.burning.get().fire)
+ for (const entity of queries.blazes.each()) if (!lost.has(entity.id)) stillBurning.add(blazes.burning.get(entity).fire)
for (const f of ignited.values()) stillBurning.add(f)
const over = fires.fires.filter((f) => !stillBurning.has(f.id))
for (const f of over) {
diff --git a/src/game/systems/logistics/deliver.ts b/src/game/systems/logistics/deliver.ts
index 2221838..5aada96 100644
--- a/src/game/systems/logistics/deliver.ts
+++ b/src/game/systems/logistics/deliver.ts
@@ -37,16 +37,18 @@ export const Deliver = Game.System(
const rules = services.rules
const { } = rules
- for (const { entity, data } of queries.carriers.each()) {
- const route = data.route.get()
- const errand = data.errand.get()
+ const { data } = queries.carriers
+ const shelves = queries.inventories.data.inventory
+ for (const entity of queries.carriers.each()) {
+ const route = data.route.get(entity)
+ const errand = data.errand.get(entity)
if (errand.back) {
if (!arrived(route)) continue
- const home = queries.inventories.get(data.home.get())
+ const home = queries.inventories.get(data.home.get(entity))
if (home.ok && errand.count > 0) {
- const inv = home.value.data.inventory.get()
+ const inv = shelves.get(home.value)
const room = inv.cap - inv.stock[errand.good]
- home.value.data.inventory.set({ ...inv, stock: { ...inv.stock, [errand.good]: inv.stock[errand.good] + Math.min(room, errand.count) } })
+ shelves.set(home.value, { ...inv, stock: { ...inv.stock, [errand.good]: inv.stock[errand.good] + Math.min(room, errand.count) } })
}
commands.despawn(entity)
continue
@@ -54,32 +56,32 @@ export const Deliver = Game.System(
const target = queries.targets.getHandle(errand.target)
if (!target.ok) {
// Nowhere to take it: carry it home.
- data.route.set(turnAround(route))
- data.errand.set({ ...errand, back: true })
+ data.route.set(entity, turnAround(route))
+ data.errand.set(entity, { ...errand, back: true })
continue
}
if (!arrived(route)) continue
let handed = 0
- const site = queries.sites.get(target.value.entity.id)
- const works = queries.works.get(target.value.entity.id)
- const inventory = queries.inventories.get(target.value.entity.id)
- if (works.ok && works.value.data.works.get().owed[errand.good] > 0) {
- const w = works.value.data.works.get()
+ const site = queries.sites.get(target.value.id)
+ const works = queries.works.get(target.value.id)
+ const inventory = queries.inventories.get(target.value.id)
+ if (works.ok && queries.works.data.works.get(works.value).owed[errand.good] > 0) {
+ const w = queries.works.data.works.get(works.value)
handed = Math.min(errand.count, w.owed[errand.good])
- works.value.data.works.set({ ...w, owed: { ...w.owed, [errand.good]: w.owed[errand.good] - handed } })
+ queries.works.data.works.set(works.value, { ...w, owed: { ...w.owed, [errand.good]: w.owed[errand.good] - handed } })
} else if (site.ok) {
- const s = site.value.data.site.get()
+ const s = queries.sites.data.site.get(site.value)
handed = Math.min(errand.count, s.owed[errand.good])
- site.value.data.site.set({ ...s, owed: { ...s.owed, [errand.good]: s.owed[errand.good] - handed } })
+ queries.sites.data.site.set(site.value, { ...s, owed: { ...s.owed, [errand.good]: s.owed[errand.good] - handed } })
} else if (inventory.ok) {
- const inv = inventory.value.data.inventory.get()
+ const inv = shelves.get(inventory.value)
if (inv.accepts.includes(errand.good)) {
handed = Math.min(errand.count, inv.cap - inv.stock[errand.good])
- inventory.value.data.inventory.set({ ...inv, stock: { ...inv.stock, [errand.good]: inv.stock[errand.good] + handed } })
+ shelves.set(inventory.value, { ...inv, stock: { ...inv.stock, [errand.good]: inv.stock[errand.good] + handed } })
}
}
- data.route.set({ cells: [...route.cells].reverse(), index: 0, step: 0 })
- data.errand.set({ ...errand, count: errand.count - handed, back: true })
+ data.route.set(entity, { cells: [...route.cells].reverse(), index: 0, step: 0 })
+ data.errand.set(entity, { ...errand, count: errand.count - handed, back: true })
}
}
)
diff --git a/src/game/systems/logistics/dispatch.ts b/src/game/systems/logistics/dispatch.ts
index 1f3bb18..8cd714c 100644
--- a/src/game/systems/logistics/dispatch.ts
+++ b/src/game/systems/logistics/dispatch.ts
@@ -58,13 +58,14 @@ export const Dispatch = Game.System(
const incoming = new Map<string, number>()
const inbound = (target: number, good: GoodId) => incoming.get(`${target}:${good}`) ?? 0
const expect = (target: number, good: GoodId, count: number) => incoming.set(`${target}:${good}`, inbound(target, good) + count)
- for (const { data } of queries.errands.each()) {
- const errand = data.errand.get()
- out.set(data.home.get(), (out.get(data.home.get()) ?? 0) + 1)
+ const errands = queries.errands.data
+ for (const entity of queries.errands.each()) {
+ const errand = errands.errand.get(entity)
+ out.set(errands.home.get(entity), (out.get(errands.home.get(entity)) ?? 0) + 1)
if (!errand.back) expect(errand.target, errand.good, errand.count)
}
- type Id = ReturnType<typeof queries.sites.each>[number]["entity"]["id"]
+ type Id = ReturnType<typeof queries.sites.each>[number]["id"]
// Outstanding demand and shelf fill, including goods already in transit.
interface Want {
readonly id: Id
@@ -75,28 +76,32 @@ export const Dispatch = Game.System(
readonly fill?: () => number
}
const wants: Array<Want> = []
- for (const { entity, data } of queries.sites.each()) {
- const site = data.site.get()
- const ds = doors(grid, data.tile.get())
+ const sites = queries.sites.data
+ for (const entity of queries.sites.each()) {
+ const site = sites.site.get(entity)
+ const ds = doors(grid, sites.tile.get(entity))
for (const g of goodIds) if (site.owed[g] > 0) wants.push({ id: entity.id, doors: ds, good: g, site: true, want: () => site.owed[g] - inbound(entity.id, g) })
}
// An upgrade under way is building work too: its materials go before anyone's shelves.
- for (const { entity, data } of queries.works.each()) {
- const works = data.works.get()
- const ds = doors(grid, data.tile.get())
+ const upgrades = queries.works.data
+ for (const entity of queries.works.each()) {
+ const works = upgrades.works.get(entity)
+ const ds = doors(grid, upgrades.tile.get(entity))
for (const g of goodIds) if (works.owed[g] > 0) wants.push({ id: entity.id, doors: ds, good: g, site: true, want: () => works.owed[g] - inbound(entity.id, g) })
}
const sitesWant = new Set(wants.filter((w) => w.want() > 0).map((w) => w.good))
const rooms: Array<{ readonly id: Id; readonly doors: ReadonlyArray<Point>; readonly room: (g: GoodId) => number; readonly keeps: boolean }> = []
- for (const { entity, data } of queries.wanting.each()) {
- const inventory = data.inventory.value()
+ const wanting = queries.wanting.data
+ const homes = queries.homes.data
+ for (const entity of queries.wanting.each()) {
+ const inventory = wanting.inventory.get(entity)
if (!inventory) continue
- const ds = doors(grid, data.tile.get())
+ const ds = doors(grid, wanting.tile.get(entity))
if (ds.length === 0) continue
- const recipe = data.recipe.value()
+ const recipe = wanting.recipe.get(entity)
const space = (g: GoodId) => (inventory.accepts.includes(g) ? inventory.cap - inventory.stock[g] - inbound(entity.id, g) : 0)
- const kind = data.building.value()?.kind
- if (data.storage.present) {
+ const kind = wanting.building.get(entity)?.kind
+ if (wanting.storage.has(entity)) {
rooms.push({ id: entity.id, doors: ds, room: space, keeps: kind !== undefined && (kinds[kind].keeps ?? 0) > 1 })
}
if (recipe && recipe.input !== null) {
@@ -105,16 +110,16 @@ export const Dispatch = Game.System(
}
// A workshop that wears out tools keeps a couple on hand.
if (kind !== undefined && kinds[kind].wear) wants.push({ id: entity.id, doors: ds, good: "tools", site: false, want: () => TOOL_STOCK - inventory.stock.tools - inbound(entity.id, "tools"), fill: () => (inventory.stock.tools + inbound(entity.id, "tools")) / TOOL_STOCK })
- const service = data.service.value()?.service
+ const service = wanting.service.get(entity)?.service
if (service === "goods") {
- const roads = reach(grid, [ds[0]!]), range = data.service.value()!.range
+ const roads = reach(grid, [ds[0]!]), range = wanting.service.get(entity)!.range
let citizenDistrict = false, burgherDistrict = false
- for (const { data: h } of queries.homes.each()) {
- const tile = h.tile.get(), found = nearest(roads, doors(grid, tile))
+ for (const home of queries.homes.each()) {
+ const tile = homes.tile.get(home), found = nearest(roads, doors(grid, tile))
if (found === null || found.distance >= range) continue
const desirability = appealAt(resources.appeal.get().cells, tile.x, tile.y)
- citizenDistrict ||= wantsCitizenGoods(h.house.get(), desirability, rules)
- burgherDistrict ||= wantsBurgherGoods(h.house.get(), desirability, rules)
+ citizenDistrict ||= wantsCitizenGoods(homes.house.get(home), desirability, rules)
+ burgherDistrict ||= wantsBurgherGoods(homes.house.get(home), desirability, rules)
if (burgherDistrict) break
}
for (const g of provisions) {
@@ -139,21 +144,22 @@ export const Dispatch = Game.System(
expect(to.id, good, count)
}
- for (const { entity, data } of queries.senders.each()) {
- const carriers = data.carriers.get().count
+ const { data } = queries.senders
+ for (const entity of queries.senders.each()) {
+ const carriers = data.carriers.get(entity).count
if ((out.get(entity.id) ?? 0) >= carriers) continue
- const starts = doors(grid, data.tile.get())
+ const starts = doors(grid, data.tile.get(entity))
if (starts.length === 0) continue
const roads = reach(grid, starts)
- const inventory = data.inventory.get()
+ const inventory = data.inventory.get(entity)
let stock = inventory.stock
- const recipe = data.recipe.value()
+ const recipe = data.recipe.get(entity)
// A storage meets demands with what it holds; anyone else sends on what it made.
// A producer waits for a full load (or a full shelf) so its carriers do not walk with one crate.
const ready = recipe ? stock[recipe.output] >= Math.min(LOAD, inventory.cap - recipe.batch) : false
// What sites are waiting for goes first: otherwise steady demand for one good keeps every carrier busy.
- const offers: ReadonlyArray<GoodId> = data.storage.present
+ const offers: ReadonlyArray<GoodId> = data.storage.has(entity)
? goodIds.filter((g) => stock[g] > 0).sort((a, b) => Number(!sitesWant.has(a)) - Number(!sitesWant.has(b)))
: recipe && ready ? [recipe.output] : []
for (const good of offers) {
@@ -170,11 +176,11 @@ export const Dispatch = Game.System(
// Food that spoils goes to a granary if there is one in reach, before the nearest storage; a
// storage that does not keep food sends it on to a granary that does.
const perishable = spoils[good] !== undefined
- const senderKeeps = (kinds[data.building.value()?.kind ?? "townhall"].keeps ?? 0) > 1
- if (best === null && (!data.storage.present || (perishable && !senderKeeps))) {
+ const senderKeeps = (kinds[data.building.get(entity)?.kind ?? "townhall"].keeps ?? 0) > 1
+ if (best === null && (!data.storage.has(entity) || (perishable && !senderKeeps))) {
let kept = false
for (const r of rooms) {
- if (r.id === entity.id || (data.storage.present && !r.keeps)) continue
+ if (r.id === entity.id || (data.storage.has(entity) && !r.keeps)) continue
const count = Math.min(LOAD, stock[good], r.room(good))
if (count <= 0) continue
const found = nearest(roads, r.doors)
@@ -189,7 +195,7 @@ export const Dispatch = Game.System(
send({ id: entity.id, roads }, best, good, best.count)
stock = { ...stock, [good]: stock[good] - best.count }
}
- if (stock !== inventory.stock) data.inventory.set({ ...inventory, stock })
+ if (stock !== inventory.stock) data.inventory.set(entity, { ...inventory, stock })
}
}
)
diff --git a/src/game/systems/orphans/drop-orphans.ts b/src/game/systems/orphans/drop-orphans.ts
index 194f913..bd2b4a0 100644
--- a/src/game/systems/orphans/drop-orphans.ts
+++ b/src/game/systems/orphans/drop-orphans.ts
@@ -17,12 +17,12 @@ export const DropOrphans = Game.System(
for (const failure of relationFailures.walkers.all()) {
if (failure.operation !== "relate") continue
const walker = queries.walkers.get(failure.source)
- if (walker.ok) commands.despawn(walker.value.entity)
+ if (walker.ok) commands.despawn(walker.value)
}
for (const failure of relationFailures.fields.all()) {
if (failure.operation !== "relate") continue
const field = queries.fields.get(failure.source)
- if (field.ok) commands.despawn(field.value.entity)
+ if (field.ok) commands.despawn(field.value)
}
}
)
diff --git a/src/game/systems/shared.ts b/src/game/systems/shared.ts
index 4e4f7c1..e3183a5 100644
--- a/src/game/systems/shared.ts
+++ b/src/game/systems/shared.ts
@@ -1,4 +1,6 @@
/** Queries and small helpers the simulation's systems share. */
+import type { EntityProving } from "@typeonce/ritmo/Query"
+
import { doors, type TileLike, type Use } from "../world/grid.ts"
import { Field, Game, House, Park, Paved, Road, Rock, Ruin, Tile, Tree, Water, type GridValue } from "../schema.ts"
import type { Point } from "../world/iso.ts"
@@ -19,24 +21,15 @@ export const TileRead = Game.Query({
}
})
-export const useOf = (data: {
- readonly road: { readonly present: boolean }
- readonly park: { readonly present: boolean }
- readonly house: { readonly present: boolean }
- readonly tree: { readonly present: boolean }
- readonly rock: { readonly present: boolean }
- readonly water: { readonly present: boolean }
- readonly field: { readonly present: boolean }
- readonly ruin: { readonly present: boolean }
-}): Use =>
- data.road.present ? "road"
- : data.park.present ? "park"
- : data.house.present ? "house"
- : data.tree.present ? "tree"
- : data.rock.present ? "rock"
- : data.water.present ? "water"
- : data.field.present ? "field"
- : data.ruin.present ? "ruin"
+export const useOf = (entity: EntityProving<never>, data: { readonly [K in "road" | "park" | "house" | "tree" | "rock" | "water" | "field" | "ruin"]: { has(entity: EntityProving<never>): boolean } }): Use =>
+ data.road.has(entity) ? "road"
+ : data.park.has(entity) ? "park"
+ : data.house.has(entity) ? "house"
+ : data.tree.has(entity) ? "tree"
+ : data.rock.has(entity) ? "rock"
+ : data.water.has(entity) ? "water"
+ : data.field.has(entity) ? "field"
+ : data.ruin.has(entity) ? "ruin"
: "building"
export const connected = (grid: GridValue, tile: TileLike): boolean => doors(grid, tile).length > 0
diff --git a/src/game/systems/term/approve.ts b/src/game/systems/term/approve.ts
index c2dde7a..bcda4f5 100644
--- a/src/game/systems/term/approve.ts
+++ b/src/game/systems/term/approve.ts
@@ -29,7 +29,7 @@ export const Approve = Game.System(
if (t % stepsOf(10) !== 0) return
const policy = resources.policy.get()
const m = resources.mood.get()
- const parts = approvalTarget(queries.homes.each().map(({ data }) => data.house.get()), policy,
+ const parts = approvalTarget(queries.homes.each().map((entity) => queries.homes.data.house.get(entity)), policy,
resources.treasury.get().coins, resources.crown.get().snubs.length, seasonAt(t, resources.charter.get(), rules).winter, rules, m.memory)
resources.mood.set({ approval: nextApproval(m.approval, parts.target, rules), ...parts })
diff --git a/src/game/systems/term/judge.ts b/src/game/systems/term/judge.ts
index d49f413..4e0ea54 100644
--- a/src/game/systems/term/judge.ts
+++ b/src/game/systems/term/judge.ts
@@ -49,8 +49,8 @@ export const Judge = Game.System(
const rules = services.rules
const { crown, fate, ranks } = rules
// The town hall's upgrades: a city asks for a guildhall.
- const hallRow = queries.halls.each()[0]
- const hall = hallRow ? hallRow.data.upgraded.value()?.level ?? 0 : 0
+ const townHall = queries.halls.each()[0]
+ const hall = townHall ? queries.halls.data.upgraded.get(townHall)?.level ?? 0 : 0
const charter = resources.charter.get()
const t = elapsed(resources.time.get(), charter)
diff --git a/src/game/systems/term/requests.ts b/src/game/systems/term/requests.ts
index 856571d..ac220c6 100644
--- a/src/game/systems/term/requests.ts
+++ b/src/game/systems/term/requests.ts
@@ -55,8 +55,9 @@ export const Requests = Game.System(
// what it can make in the time given, early in the term, to most of it.
// The crown waits until the town makes anything.
const rates = new Map<GoodId, number>()
- for (const { data } of queries.makers.each()) {
- const r = data.recipe.get()
+ const { data } = queries.makers
+ for (const entity of queries.makers.each()) {
+ const r = data.recipe.get(entity)
rates.set(r.output, (rates.get(r.output) ?? 0) + (r.batch * 3600) / r.period)
}
// Only what keeps: fish and bread would rot on the way.
@@ -68,7 +69,7 @@ export const Requests = Game.System(
const window = (crownGap(charter, rules) * crown.window) / 3600
const share = crown.share[0] + (crown.share[1] - crown.share[0]) * progress
// Never more than the town could keep in store.
- const room = queries.stores.each().reduce((sum, { data }) => sum + data.inventory.get().cap, 0)
+ const room = queries.stores.each().reduce((sum, entity) => sum + queries.stores.data.inventory.get(entity).cap, 0)
const amount = Math.max(4, Math.min(Math.round(room * crown.room), Math.round(rates.get(good)! * window * share)))
const reward = Math.round(amount * goods[good].price * crown.reward) + crown.bonus
const gap = crownGap(charter, rules)
diff --git a/src/game/systems/town/collect.ts b/src/game/systems/town/collect.ts
index 82e68b8..ef30b14 100644
--- a/src/game/systems/town/collect.ts
+++ b/src/game/systems/town/collect.ts
@@ -46,35 +46,38 @@ export const Collect = Game.System(
const grid = resources.grid.get()
const policy = resources.policy.get()
const hall = queries.halls.each()[0]
- const roads = hall ? reach(grid, doors(grid, hall.data.tile.get())) : null
+ const roads = hall ? reach(grid, doors(grid, queries.halls.data.tile.get(hall))) : null
const share = LEDGER_TICKS / (60 * 60)
const cells = resources.appeal.get().cells
let taxes = 0
let residents = 0
- for (const { data } of queries.homes.each()) {
- residents += data.house.get().residents
- const tile = data.tile.get()
+ const home = queries.homes.data
+ for (const entity of queries.homes.each()) {
+ residents += home.house.get(entity).residents
+ const tile = home.tile.get(entity)
const reached = roads !== null && doors(grid, tile).some((c) => roads.distance[key(c.x, c.y)]! >= 0)
- if (reached) taxes += taxOf(data.house.get(), policy, rules, appealAt(cells, tile.x, tile.y))
+ if (reached) taxes += taxOf(home.house.get(entity), policy, rules, appealAt(cells, tile.x, tile.y))
}
let upkeep = 0
- for (const { data } of queries.buildings.each()) upkeep += upkeepOf(kinds[data.building.get().kind], data.upgraded.value()?.level ?? 0) * (data.paused.present ? PAUSED_UPKEEP : 1)
- for (const { data } of queries.parks.each()) upkeep += parkUpkeep(data.park.get(), rules)
+ const building = queries.buildings.data
+ for (const entity of queries.buildings.each()) upkeep += upkeepOf(kinds[building.building.get(entity).kind], building.upgraded.get(entity)?.level ?? 0) * (building.paused.has(entity) ? PAUSED_UPKEEP : 1)
+ for (const entity of queries.parks.each()) upkeep += parkUpkeep(queries.parks.data.park.get(entity), rules)
// A guildhall or a city hall runs the town for less (see `Upgrade.admin`).
- const saves = (hall ? upgradeAt(kinds.townhall, hall.data.upgraded.value()?.level ?? 0)?.admin : undefined) ?? 0
+ const saves = (hall ? upgradeAt(kinds.townhall, queries.halls.data.upgraded.get(hall)?.level ?? 0)?.admin : undefined) ?? 0
const admin = adminOf(residents, rules, saves)
const stores = queries.stores.each()
+ const store = queries.stores.data
const before = resources.treasury.get().coins
- const traded = tradeCollection(stores.map(({ data }) => data.inventory.get()), policy, resources.market.get().prices,
+ const traded = tradeCollection(stores.map((entity) => store.inventory.get(entity)), policy, resources.market.get().prices,
before + baseCollection(taxes, upkeep, residents, rules, saves).delta, rules)
// What changed hands, for the minute's flow of goods: bought less sold.
const moved: Partial<Record<GoodId, number>> = {}
- for (const [i, row] of stores.entries()) {
- const before = row.data.inventory.get().stock
+ for (const [i, entity] of stores.entries()) {
+ const before = store.inventory.get(entity).stock
const after = traded.stores[i]!.stock
for (const g of goodIds) if (after[g] !== before[g]) moved[g] = (moved[g] ?? 0) + after[g] - before[g]
- row.data.inventory.set(traded.stores[i]!)
+ store.inventory.set(entity, traded.stores[i]!)
}
if (Object.keys(moved).length > 0) resources.flow.update((f) => ({ ...f, traded: amounts(Object.fromEntries(goodIds.map((g) => [g, f.traded[g] + (moved[g] ?? 0)]))) }))
// And the treasury's: the taxes came in, trade changed hands; upkeep and administration are left over as used.
diff --git a/src/game/systems/town/households.ts b/src/game/systems/town/households.ts
index 1d6435a..196dfbf 100644
--- a/src/game/systems/town/households.ts
+++ b/src/game/systems/town/households.ts
@@ -48,7 +48,7 @@ export const Households = Game.System(
const { home, risk } = rules
// What the store holds, reckoned only once some home is ready to rise this step.
let stock: Record<GoodId, number> | null = null
- const held = () => (stock ??= Object.fromEntries(goodIds.map((g) => [g, queries.stores.each().reduce((n, { data }) => n + data.inventory.get().stock[g], 0)])) as Record<GoodId, number>)
+ const held = () => (stock ??= Object.fromEntries(goodIds.map((g) => [g, queries.stores.each().reduce((n, entity) => n + queries.stores.data.inventory.get(entity).stock[g], 0)])) as Record<GoodId, number>)
/** Pays a home's rise from the treasury and the store, fullest first; or says it cannot. */
const pay = (cost: { readonly coins: number; readonly materials: Partial<Record<GoodId, number>> }): boolean => {
if (shortOf(cost, resources.treasury.get().coins, held())) return false
@@ -56,10 +56,11 @@ export const Households = Game.System(
for (const [g, n] of Object.entries(cost.materials) as Array<[GoodId, number]>) {
let owed = n
held()[g] -= n
- for (const { data } of [...queries.stores.each()].sort((a, b) => b.data.inventory.get().stock[g] - a.data.inventory.get().stock[g])) {
+ const { data } = queries.stores
+ for (const entity of [...queries.stores.each()].sort((a, b) => data.inventory.get(b).stock[g] - data.inventory.get(a).stock[g])) {
if (owed <= 0) break
- const inv = data.inventory.get(), k = Math.min(owed, inv.stock[g])
- data.inventory.set({ ...inv, stock: { ...inv.stock, [g]: inv.stock[g] - k } })
+ const inv = data.inventory.get(entity), k = Math.min(owed, inv.stock[g])
+ data.inventory.set(entity, { ...inv, stock: { ...inv.stock, [g]: inv.stock[g] - k } })
owed -= k
}
}
@@ -73,29 +74,30 @@ export const Households = Game.System(
const t = elapsed(resources.time.get(), resources.charter.get())
// In winter a meal lasts two thirds as long.
const eat = mealDecay(t, seasonAt(t, resources.charter.get(), rules).winter)
- for (const { entity, data } of queries.homes.each()) {
- const h = data.house.get()
+ const { data } = queries.homes
+ for (const entity of queries.homes.each()) {
+ const h = data.house.get(entity)
const next = ageNeeds(h, eat)
// A home on fire, or closed by the town, stands empty.
- if (data.burning.present || data.closed.present) next.residents = 0
+ if (data.burning.has(entity) || data.closed.has(entity)) next.residents = 0
else if (next.clock % home.settle === 0) {
- const tile = data.tile.get()
+ const tile = data.tile.get(entity)
const desirability = appealAt(cells, tile.x, tile.y)
- const tier = tierFor(next, desirability, data.risk.value() ?? { fire: 0, health: 0, order: 0 }, rules)
+ const tier = tierFor(next, desirability, data.risk.get(entity) ?? { fire: 0, health: 0, order: 0 }, rules)
// Rising a tier is a rebuilding, paid for at once, once: a home that cannot be paid for waits, and one
// that stepped down moves back up into what it was rebuilt as.
- const built = data.rebuilt.value()?.tier ?? 1
+ const built = data.rebuilt.get(entity)?.tier ?? 1
if (tier <= h.tier || tier <= built) next.tier = tier
else if (pay(home.tiers[tier].rise)) {
next.tier = tier
commands.insert(entity, Game.Command.entry(Rebuilt, { tier: tier as 2 | 3 }))
}
const well = connected(grid, tile) ? capacity(next, approval, desirability, rules, rateOf(policy, next.tier)) : 0
- const cap = data.sick.present ? Math.floor(well * risk.health.sickly) : well
+ const cap = data.sick.has(entity) ? Math.floor(well * risk.health.sickly) : well
next.residents = Math.min(next.residents, home.tiers[next.tier].residents)
next.residents += Math.sign(cap - next.residents)
}
- data.house.set(next)
+ data.house.set(entity, next)
}
}
)
diff --git a/src/game/systems/town/take-census.ts b/src/game/systems/town/take-census.ts
index cce72ad..7177c24 100644
--- a/src/game/systems/town/take-census.ts
+++ b/src/game/systems/town/take-census.ts
@@ -18,19 +18,21 @@ export const TakeCensus = Game.System(
let burghers = 0
let sick = 0
const needs = { food: 0, bread: 0, cloth: 0, faith: 0, furniture: 0 }
- for (const { data } of queries.homes.each()) {
- const h = data.house.get()
+ const home = queries.homes.data
+ for (const entity of queries.homes.each()) {
+ const h = home.house.get(entity)
homes += 1
if (h.tier === 1) settlers += h.residents
else citizens += h.residents
if (h.tier === 3) burghers += h.residents
- if (data.sick.present) sick += 1
+ if (home.sick.has(entity)) sick += 1
for (const n of ["food", "bread", "cloth", "faith", "furniture"] as const) if (met(h, n)) needs[n] += 1
}
let jobs = 0
let employed = 0
- for (const { data } of queries.workplaces.each()) {
- const s = data.staff.get()
+ const workplace = queries.workplaces.data
+ for (const entity of queries.workplaces.each()) {
+ const s = workplace.staff.get(entity)
jobs += s.needed
employed += s.assigned
}
diff --git a/src/game/systems/walkers/send-walkers.ts b/src/game/systems/walkers/send-walkers.ts
index 344654b..9e25e3e 100644
--- a/src/game/systems/walkers/send-walkers.ts
+++ b/src/game/systems/walkers/send-walkers.ts
@@ -48,20 +48,23 @@ export const SendWalkers = Game.System(
const grid = resources.grid.get()
const tick = resources.time.get().step
const out = new Map<number, number>()
- for (const { data } of queries.walkers.each()) out.set(data.home.get(), (out.get(data.home.get()) ?? 0) + 1)
+ const walkers = queries.walkers.data
+ for (const entity of queries.walkers.each()) out.set(walkers.home.get(entity), (out.get(walkers.home.get(entity)) ?? 0) + 1)
- for (const { entity, data } of queries.services.each()) {
- const service = data.service.get()
- const staff = data.staff.get()
- const starts = doors(grid, data.tile.get())
- const stock = data.inventory.value()?.stock
- const staffed = !data.paused.present && (staff.needed === 0 || staff.assigned > 0)
+ const { data } = queries.services
+ const targetData = queries.targets.data
+ for (const entity of queries.services.each()) {
+ const service = data.service.get(entity)
+ const staff = data.staff.get(entity)
+ const starts = doors(grid, data.tile.get(entity))
+ const stock = data.inventory.get(entity)?.stock
+ const staffed = !data.paused.has(entity) && (staff.needed === 0 || staff.assigned > 0)
const carries = (g: (typeof provisions)[number]) =>
service.service === "goods" ? provisions.includes(g) : service.service === "repair" ? g === "planks" || g === "stone" : false
const basket: Amounts = each((g) => (stock && carries(g) ? Math.min(BASKET, stock[g]) : 0))
const goes = service.service === "goods" ? total(basket) > 0 : service.service === "repair" ? basket.planks > 0 : true
- if (!data.recipe.value()) {
- const status: StatusValue = data.paused.present
+ if (!data.recipe.get(entity)) {
+ const status: StatusValue = data.paused.has(entity)
? "paused"
: starts.length === 0
? "unconnected"
@@ -72,23 +75,23 @@ export const SendWalkers = Game.System(
: goes
? "idle"
: "starved"
- if (data.status.get() !== status) data.status.set(status)
+ if (data.status.get(entity) !== status) data.status.set(entity, status)
}
// A crew of apprentices sends walkers less often.
const learning = staff.assigned > 0 && staff.assigned === staff.apprentices && !paced(APPRENTICE, tick)
const cooldown = learning ? service.cooldown : Math.max(0, service.cooldown - 1)
if (cooldown === 0 && (out.get(entity.id) ?? 0) < OUT && starts.length > 0 && staffed && goes) {
- const targets = queries.targets.each().filter(({ data }) => service.service === "fire" || service.service === "repair" || data.house.present)
- .map(({ entity, data }) => ({ id: entity.id as number, tile: data.tile.get() }))
- const plan = planPatrols(grid, data.tile.get(), service.range, targets)
+ const targets = queries.targets.each().filter((target) => service.service === "fire" || service.service === "repair" || targetData.house.has(target))
+ .map((target) => ({ id: target.id as number, tile: targetData.tile.get(target) }))
+ const plan = planPatrols(grid, data.tile.get(entity), service.range, targets)
if (plan.tours.length === 0) continue
const patrol = queries.patrols.get(entity.id)
- const cursor = patrol.ok ? patrol.value.data.patrol.get().next : 0
+ const cursor = patrol.ok ? queries.patrols.data.patrol.get(patrol.value).next : 0
const tour = plan.tours[cursor % plan.tours.length]!
- if (patrol.ok) patrol.value.data.patrol.set({ next: (cursor + 1) % plan.tours.length })
+ if (patrol.ok) queries.patrols.data.patrol.set(patrol.value, { next: (cursor + 1) % plan.tours.length })
else commands.insert(entity, Game.Command.entry(Patrol, { next: 1 % plan.tours.length }))
- const color = categoryColor[kinds[data.building.get().kind].category]
+ const color = categoryColor[kinds[data.building.get(entity).kind].category]
const draft = Game.Command.spawn(
[Figure, { role: "walker", color }],
[Route, { cells: [...tour], index: 0, step: 0 }],
@@ -97,11 +100,11 @@ export const SendWalkers = Game.System(
commands.spawn(Game.Command.relate(draft, WalkerOf, entity.id))
const inv = queries.inventories.get(entity.id)
if (inv.ok && total(basket) > 0) {
- const i = inv.value.data.inventory.get()
- inv.value.data.inventory.set({ ...i, stock: each((g) => i.stock[g] - basket[g]) })
+ const i = queries.inventories.data.inventory.get(inv.value)
+ queries.inventories.data.inventory.set(inv.value, { ...i, stock: each((g) => i.stock[g] - basket[g]) })
}
- data.service.set({ ...service, cooldown: service.interval })
- } else if (cooldown !== service.cooldown) data.service.set({ ...service, cooldown })
+ data.service.set(entity, { ...service, cooldown: service.interval })
+ } else if (cooldown !== service.cooldown) data.service.set(entity, { ...service, cooldown })
}
}
)
diff --git a/src/game/systems/walkers/walk.ts b/src/game/systems/walkers/walk.ts
index e4311a9..a0ebc93 100644
--- a/src/game/systems/walkers/walk.ts
+++ b/src/game/systems/walkers/walk.ts
@@ -26,8 +26,9 @@ export const Walk = Game.System(
const grid = resources.grid.get()
const tick = resources.time.get().step
const quicker = services.rules.pavedPace - 1
- for (const { entity, data } of queries.walkers.each()) {
- const route = data.route.get()
+ const { data } = queries.walkers
+ for (const entity of queries.walkers.each()) {
+ const route = data.route.get(entity)
const last = route.cells.length - 1
if (route.index >= last) continue
const next = route.cells[route.index + 1]!
@@ -35,13 +36,14 @@ export const Walk = Game.System(
commands.despawn(entity)
continue
}
- const running = data.rescue.present && !data.rescue.get().back
+ const rescue = data.rescue.get(entity)
+ const running = rescue !== undefined && !rescue.back
const paved = !running && quicker > 0 && (grid.paved?.has(key(next.x, next.y)) ?? false) && paced(quicker, tick)
const step = route.step + (running ? RUN : WALK) + (paved ? 1 : 0)
- if (step < CELL_STEPS) data.route.set({ ...route, step })
+ if (step < CELL_STEPS) data.route.set(entity, { ...route, step })
else {
const index = route.index + 1
- data.route.set({ ...route, index, step: index >= last ? 0 : step - CELL_STEPS })
+ data.route.set(entity, { ...route, index, step: index >= last ? 0 : step - CELL_STEPS })
}
}
}
diff --git a/src/game/systems/walkers/wander.ts b/src/game/systems/walkers/wander.ts
index fc1364b..5a8d4a2 100644
--- a/src/game/systems/walkers/wander.ts
+++ b/src/game/systems/walkers/wander.ts
@@ -46,28 +46,31 @@ export const Wander = Game.System(
const grid = resources.grid.get()
const walkers = queries.walkers.each()
const homes = new Map<number, ReturnType<typeof queries.homes.each>[number]>()
- for (const row of queries.homes.each()) homes.set(row.entity.id, row)
+ for (const entity of queries.homes.each()) homes.set(entity.id, entity)
const cared = new Map<number, ReturnType<typeof queries.cared.each>[number]>()
- for (const row of queries.cared.each()) cared.set(row.entity.id, row)
+ for (const entity of queries.cared.each()) cared.set(entity.id, entity)
+ const house = queries.homes.data.house
+ const care = queries.cared.data
let eaten = 0
// What each walker hands each home, for its building's last minute (see `Handed`).
const tick = resources.time.get().step
const handed: Array<HandedValue["log"][number]> = []
- for (const { entity, data } of walkers) {
- const route = data.route.get()
- const roam = data.roam.get()
+ const { data } = queries.walkers
+ for (const entity of walkers) {
+ const route = data.route.get(entity)
+ const roam = data.roam.get(entity)
// left counts cells still to serve. Older saves can finish their current short segment.
if (roam.back ? !arrived(route) : roam.left > route.cells.length ? !arrived(route) : route.index < route.cells.length - roam.left) continue
- const from = data.home.get()
+ const from = data.home.get(entity)
if (roam.back) {
const inv = queries.inventories.get(from)
if (inv.ok && total(roam.basket) > 0) {
- const i = inv.value.data.inventory.get()
+ const i = queries.inventories.data.inventory.get(inv.value)
// What it did not hand out goes back on the shelf, even past its room (the shelf filled again meanwhile):
// the building asks for no more until it is down again, and nothing is lost.
- inv.value.data.inventory.set({ ...i, stock: each((g) => i.stock[g] + roam.basket[g]) })
+ queries.inventories.data.inventory.set(inv.value, { ...i, stock: each((g) => i.stock[g] + roam.basket[g]) })
}
commands.despawn(entity)
continue
@@ -87,35 +90,35 @@ export const Wander = Game.System(
if (served.has(id)) continue
served.add(id)
const row = use === "house" ? homes.get(id) : undefined
- const care = cared.get(id)
+ const cares = cared.get(id)
if (row) {
- const h = { ...row.data.house.get() }
+ const h = { ...house.get(row) }
if (roam.service === "faith") h.faith = home.lasts.faith
else if (roam.service === "goods") {
const served = serveGoods(h, amounts(basket), rules, appealAt(resources.appeal.get().cells, x, y))
const given = Object.fromEntries(Object.entries(served.basket).filter(([g, n]) => (basket[g] ?? 0) > n).map(([g, n]) => [g, (basket[g] ?? 0) - n]))
- if (Object.keys(given).length > 0) handed.push({ at: tick, from: data.home.get(), to: id, goods: given })
+ if (Object.keys(given).length > 0) handed.push({ at: tick, from: data.home.get(entity), to: id, goods: given })
Object.assign(h, served.house)
Object.assign(basket, served.basket)
eaten += served.eaten
}
- row.data.house.set(h)
+ house.set(row, h)
}
- if (!care) continue
- const r = care.data.risk.get()
- if (roam.service === "fire" && r.fire > 0) care.data.risk.set({ ...r, fire: 0 })
+ if (!cares) continue
+ const r = care.risk.get(cares)
+ if (roam.service === "fire" && r.fire > 0) care.risk.set(cares, { ...r, fire: 0 })
if (row && roam.service === "health") {
- if (r.health > 0) care.data.risk.set({ ...r, health: 0 })
- if (care.data.sick.present) commands.remove(care.entity, Sick)
+ if (r.health > 0) care.risk.set(cares, { ...r, health: 0 })
+ if (care.sick.has(cares)) commands.remove(cares, Sick)
}
- if (row && roam.service === "order" && (r.order > 0 || r.thefts > 0)) care.data.risk.set({ ...r, order: 0, thefts: 0 })
+ if (row && roam.service === "order" && (r.order > 0 || r.thefts > 0)) care.risk.set(cares, { ...r, order: 0, thefts: 0 })
if (roam.service === "repair") {
- const c = care.data.condition.get().value
+ const c = care.condition.get(cares).value
if (c < wear.mend && (basket.planks ?? 0) > 0) {
basket.planks = (basket.planks ?? 0) - 1
const stone = !row && (basket.stone ?? 0) > 0
if (stone) basket.stone = (basket.stone ?? 0) - 1
- care.data.condition.set({ value: row || stone ? CONDITION_MAX : Math.min(CONDITION_MAX, c + 300) })
+ care.condition.set(cares, { value: row || stone ? CONDITION_MAX : Math.min(CONDITION_MAX, c + 300) })
}
}
}
@@ -123,20 +126,20 @@ export const Wander = Game.System(
const carrying = amounts(basket)
const keepsGoing = roam.service === "goods" ? total(carrying) > 0 : roam.service === "repair" ? carrying.planks > 0 : true
if (left > 0 && keepsGoing && !arrived(route)) {
- data.roam.set({ ...roam, left, basket: carrying })
+ data.roam.set(entity, { ...roam, left, basket: carrying })
continue
}
// Head home.
const building = queries.buildings.get(from)
const way = reach(grid, [cell])
- const door = building.ok ? nearest(way, doors(grid, building.value.data.tile.get())) : null
+ const door = building.ok ? nearest(way, doors(grid, queries.buildings.data.tile.get(building.value))) : null
if (!door) {
commands.despawn(entity)
continue
}
- data.route.set({ cells: pathTo(way, door.cell), index: 0, step: 0 })
- data.roam.set({ ...roam, left: 0, basket: carrying, back: true })
+ data.route.set(entity, { cells: pathTo(way, door.cell), index: 0, step: 0 })
+ data.roam.set(entity, { ...roam, left: 0, basket: carrying, back: true })
}
if (eaten > 0) resources.pantry.update((p) => ({ ...p, eaten: p.eaten + eaten }))
// The last minute only; a log from another town (its clock behind this one's) is dropped.
diff --git a/src/game/systems/work/assign-staff.ts b/src/game/systems/work/assign-staff.ts
index 19ef43c..4005102 100644
--- a/src/game/systems/work/assign-staff.ts
+++ b/src/game/systems/work/assign-staff.ts
@@ -43,15 +43,16 @@ export const AssignStaff = Game.System(
if (!every(resources.time.get(), STAFF_TICKS)) return
const grid = resources.grid.get()
const homes: Array<{ readonly id: number; readonly crew: Crew; left: number; readonly doors: ReadonlyArray<{ readonly x: number; readonly y: number }> }> = []
- for (const { entity, data } of queries.homes.each()) {
- const h = data.house.get()
- const ds = doors(grid, data.tile.get())
+ const home = queries.homes.data
+ for (const entity of queries.homes.each()) {
+ const h = home.house.get(entity)
+ const ds = doors(grid, home.tile.get(entity))
if (h.residents > 0 && ds.length > 0) homes.push({ id: entity.id, crew: crewOf(h.tier), left: h.residents, doors: ds })
}
type Row = ReturnType<typeof queries.workplaces.each>[number]
const places: Array<{
readonly id: number;
- readonly data: Row["data"]
+ readonly entity: Row
readonly staff: { readonly needed: number; readonly assigned: number; readonly apprentices: number; readonly nearby: number }
readonly crew: Crew
readonly within: ReadonlyArray<{ readonly home: (typeof homes)[number]; readonly distance: number }>
@@ -59,13 +60,14 @@ export const AssignStaff = Game.System(
apprentices: number
readonly nearby: number
}> = []
- for (const { entity, data } of queries.workplaces.each()) {
- const staff = data.staff.get()
+ const { data } = queries.workplaces
+ for (const entity of queries.workplaces.each()) {
+ const staff = data.staff.get(entity)
if (staff.needed === 0) continue
- const crew = kinds[data.building.get().kind].crew
- const starts = doors(grid, data.tile.get())
+ const crew = kinds[data.building.get(entity).kind].crew
+ const starts = doors(grid, data.tile.get(entity))
const within: Array<{ readonly home: (typeof homes)[number]; readonly distance: number }> = []
- if (starts.length > 0 && !data.paused.present && !data.burning.present) {
+ if (starts.length > 0 && !data.paused.has(entity) && !data.burning.has(entity)) {
const roads = reach(grid, starts)
for (const home of homes) {
let distance = -1
@@ -78,16 +80,16 @@ export const AssignStaff = Game.System(
within.sort((a, b) => a.distance - b.distance)
}
const nearby = within.reduce((n, w) => n + (w.home.crew === crew ? w.home.left : 0), 0)
- places.push({ id: entity.id, data, staff, crew, within, assigned: 0, apprentices: 0, nearby })
+ places.push({ id: entity.id, entity, staff, crew, within, assigned: 0, apprentices: 0, nearby })
}
const assigned = assignWorkers(
homes.map((h) => ({ id: h.id, crew: h.crew, residents: h.left })),
places.map((p) => ({ id: p.id, crew: p.crew, needed: p.staff.needed,
within: p.within.map((w) => ({ home: w.home.id, distance: w.distance })) }))
)
- for (const { id, data, staff } of places) {
+ for (const { id, entity, staff } of places) {
const next = assigned.get(id)!
- if (staff.assigned !== next.assigned || staff.apprentices !== next.apprentices || staff.nearby !== next.nearby) data.staff.set({ ...staff, ...next })
+ if (staff.assigned !== next.assigned || staff.apprentices !== next.apprentices || staff.nearby !== next.nearby) data.staff.set(entity, { ...staff, ...next })
}
}
)
diff --git a/src/game/systems/work/count-stock.ts b/src/game/systems/work/count-stock.ts
index 8540dbb..ac471b3 100644
--- a/src/game/systems/work/count-stock.ts
+++ b/src/game/systems/work/count-stock.ts
@@ -29,23 +29,23 @@ export const CountStock = Game.System(
},
({ queries, resources }) => {
const sum: Record<string, number> = { ...amounts({}) }
- for (const { data } of queries.stores.each()) {
- const s = data.inventory.get().stock
+ for (const entity of queries.stores.each()) {
+ const s = queries.stores.data.inventory.get(entity).stock
for (const g of goodIds) sum[g] = (sum[g] ?? 0) + s[g]
}
resources.stock.set(sum as Amounts)
const held: Record<string, number> = { ...amounts({}) }
- for (const { data } of queries.shelves.each()) {
- const s = data.inventory.get().stock
+ for (const entity of queries.shelves.each()) {
+ const s = queries.shelves.data.inventory.get(entity).stock
for (const g of goodIds) held[g] = held[g]! + s[g]
}
- for (const { data } of queries.baskets.each()) {
- const b = data.roam.get().basket
+ for (const entity of queries.baskets.each()) {
+ const b = queries.baskets.data.roam.get(entity).basket
for (const g of goodIds) held[g] = held[g]! + b[g]
}
- for (const { data } of queries.crates.each()) {
- const e = data.errand.get()
+ for (const entity of queries.crates.each()) {
+ const e = queries.crates.data.errand.get(entity)
held[e.good] = held[e.good]! + e.count
}
const tick = resources.time.get().step
diff --git a/src/game/systems/work/grow.ts b/src/game/systems/work/grow.ts
index d70d76d..45fdaeb 100644
--- a/src/game/systems/work/grow.ts
+++ b/src/game/systems/work/grow.ts
@@ -18,14 +18,16 @@ export const Grow = Game.System(
const { grown: GROWN, growTicks: GROW_TICKS } = rules
if (!every(resources.time.get(), GROW_TICKS)) return
- for (const { data } of queries.trees.each()) {
- const growth = data.tree.get().growth
- if (growth < GROWN.tree) data.tree.set({ growth: Math.min(GROWN.tree, growth + GROW_TICKS) })
+ const trees = queries.trees.data
+ for (const entity of queries.trees.each()) {
+ const growth = trees.tree.get(entity).growth
+ if (growth < GROWN.tree) trees.tree.set(entity, { growth: Math.min(GROWN.tree, growth + GROW_TICKS) })
}
if (seasonAt(elapsed(resources.time.get(), resources.charter.get()), resources.charter.get(), rules).winter) return
- for (const { data } of queries.fields.each()) {
- const growth = data.field.get().growth
- if (growth < GROWN.field) data.field.set({ growth: Math.min(GROWN.field, growth + GROW_TICKS) })
+ const fields = queries.fields.data
+ for (const entity of queries.fields.each()) {
+ const growth = fields.field.get(entity).growth
+ if (growth < GROWN.field) fields.field.set(entity, { growth: Math.min(GROWN.field, growth + GROW_TICKS) })
}
}
)
diff --git a/src/game/systems/work/index-grid.ts b/src/game/systems/work/index-grid.ts
index 6bbd839..349fb7a 100644
--- a/src/game/systems/work/index-grid.ts
+++ b/src/game/systems/work/index-grid.ts
@@ -26,11 +26,12 @@ export const IndexGrid = Game.System(
const grid = new GridBuilder(resources.land.get().mask)
const tiles = new Set<number>()
const paved = new Set<number>()
- for (const { entity, data } of queries.tiles.each()) {
- const t = data.tile.get()
- grid.claim(t, entity.id, useOf(data))
+ const { data } = queries.tiles
+ for (const entity of queries.tiles.each()) {
+ const t = data.tile.get(entity)
+ grid.claim(t, entity.id, useOf(entity, data))
tiles.add(entity.id)
- if (data.road.present && data.paved.present) paved.add(key(t.x, t.y))
+ if (data.road.has(entity) && data.paved.has(entity)) paved.add(key(t.x, t.y))
}
const value = grid.value()
resources.grid.set({ ...value, roads: roadPrint(value), tiles, paved })
diff --git a/src/game/systems/work/plant.ts b/src/game/systems/work/plant.ts
index 14aac1e..273ef08 100644
--- a/src/game/systems/work/plant.ts
+++ b/src/game/systems/work/plant.ts
@@ -33,13 +33,14 @@ export const Plant = Game.System(
const random = Random.draw(resources.rng)
const sown = new Set<number>()
const tick = resources.time.get().step
- for (const { entity, data } of queries.planters.each()) {
- const tile = data.tile.get()
- const staff = data.staff.get()
- const planter = data.planter.get()
+ const { data } = queries.planters
+ for (const entity of queries.planters.each()) {
+ const tile = data.tile.get(entity)
+ const staff = data.staff.get(entity)
+ const planter = data.planter.get(entity)
// While it waits to plant again, it only counts down (and looks around twice a second for its status).
if (planter.cooldown > 1 && tick % STAFF_TICKS !== 0) {
- data.planter.set({ ...planter, cooldown: planter.cooldown - 1 })
+ data.planter.set(entity, { ...planter, cooldown: planter.cooldown - 1 })
continue
}
const open = connected(grid, tile)
@@ -47,20 +48,20 @@ export const Plant = Game.System(
const grown = reach.filter((c) => useAt(grid, c.x, c.y) === planter.what).length
const spots = reach.filter((c) => useAt(grid, c.x, c.y) === "empty" && !sown.has(key(c.x, c.y)))
// A forester has no recipe of its own: its status is its planting.
- if (!data.recipe.value()) {
- const status: StatusValue = data.paused.present ? "paused" : !open ? "unconnected" : staff.assigned === 0 ? "unstaffed" : grown < planter.max && spots.length > 0 ? "working" : "idle"
- if (data.status.get() !== status) data.status.set(status)
+ if (!data.recipe.get(entity)) {
+ const status: StatusValue = data.paused.has(entity) ? "paused" : !open ? "unconnected" : staff.assigned === 0 ? "unstaffed" : grown < planter.max && spots.length > 0 ? "working" : "idle"
+ if (data.status.get(entity) !== status) data.status.set(entity, status)
}
const cooldown = Math.max(0, planter.cooldown - 1)
if (cooldown > 0 || !open || staff.assigned === 0 || grown >= planter.max || spots.length === 0) {
- if (cooldown !== planter.cooldown) data.planter.set({ ...planter, cooldown })
+ if (cooldown !== planter.cooldown) data.planter.set(entity, { ...planter, cooldown })
continue
}
const spot = random.pick(spots)!
sown.add(key(spot.x, spot.y))
if (planter.what === "tree") commands.spawn(treeDraft(spot, 0))
else commands.spawn(Game.Command.relate(fieldDraft(spot), FieldOf, entity.id))
- data.planter.set({ ...planter, cooldown: planter.interval })
+ data.planter.set(entity, { ...planter, cooldown: planter.interval })
}
}
)
diff --git a/src/game/systems/work/raise.ts b/src/game/systems/work/raise.ts
index c1666b4..a69465d 100644
--- a/src/game/systems/work/raise.ts
+++ b/src/game/systems/work/raise.ts
@@ -42,52 +42,56 @@ export const Raise = Game.System(
// An upgrade whose materials are all in stands upgraded: it works from here on as `asUpgraded` says,
// keeping what it holds and what it was in the middle of.
const tick = resources.time.get().step
- for (const { entity, data } of queries.works.each()) {
- let works = data.works.get()
+ const { data } = queries.works
+ const stocked = queries.stocked.data
+ for (const entity of queries.works.each()) {
+ let works = data.works.get(entity)
// A storage under works (the town hall) builds with what it holds itself, a crate at a time.
const shelves = queries.stocked.get(entity.id)
if (shelves.ok && tick % SELF_SUPPLY_TICKS === 0) {
- const own = shelves.value.data.inventory.get()
+ const own = stocked.inventory.get(shelves.value)
const g = goodIds.find((g) => works.owed[g] > 0 && own.stock[g] > 0)
if (g) {
const n = Math.min(rules.transport.load, works.owed[g], own.stock[g])
- shelves.value.data.inventory.set({ ...own, stock: { ...own.stock, [g]: own.stock[g] - n } })
+ stocked.inventory.set(shelves.value, { ...own, stock: { ...own.stock, [g]: own.stock[g] - n } })
works = { ...works, owed: { ...works.owed, [g]: works.owed[g] - n } }
- data.works.set(works)
+ data.works.set(entity, works)
}
}
// Builders work on as the materials come in, never ahead of them.
const needed = worksNeeded(works.total, rules), allowed = needed * (1 - total(works.owed) / Math.max(1, works.total))
if (works.done < allowed) {
works = { ...works, done: works.done + 1 }
- data.works.set(works)
+ data.works.set(entity, works)
}
if (total(works.owed) > 0 || works.done < needed) continue
- const base = rules.kinds[data.building.get().kind], kind = asUpgraded(base, works.level)
+ const base = rules.kinds[data.building.get(entity).kind], kind = asUpgraded(base, works.level)
commands.remove(entity, Works)
commands.insert(entity, Game.Command.entry(Upgraded, { level: works.level }))
- data.staff.set({ ...data.staff.get(), needed: kind.workers })
- const recipe = data.recipe.value(), carriers = data.carriers.value(), service = data.service.value()
+ data.staff.set(entity, { ...data.staff.get(entity), needed: kind.workers })
+ const recipe = data.recipe.get(entity), carriers = data.carriers.get(entity), service = data.service.get(entity)
if (recipe && kind.recipe) commands.insert(entity, Game.Command.entry(Recipe, { ...recipe, period: stepsOf(kind.recipe.seconds) }))
- if (shelves.ok && kind.holds) shelves.value.data.inventory.set({ ...shelves.value.data.inventory.get(), cap: kind.holds.cap })
+ if (shelves.ok && kind.holds) stocked.inventory.set(shelves.value, { ...stocked.inventory.get(shelves.value), cap: kind.holds.cap })
if (carriers && kind.carriers) commands.insert(entity, Game.Command.entry(Carriers, { count: kind.carriers }))
if (service && kind.service) commands.insert(entity, Game.Command.entry(Service, { ...service, interval: stepsOf(kind.service.seconds), range: kind.service.range }))
const was = (upgradeAt(base, works.level - 1)?.title ?? base.title).toLowerCase()
write(resources.chronicle, elapsed(resources.time.get(), resources.charter.get()), `The ${was} is now ${anA(upgradeAt(base, works.level)!.title.toLowerCase())}.`, true)
}
- for (const { entity, data } of queries.sites.each()) {
- if (total(data.site.get().owed) > 0) continue
+ const sites = queries.sites.data
+ for (const entity of queries.sites.each()) {
+ if (total(sites.site.get(entity).owed) > 0) continue
commands.remove(entity, Site)
commands.insert(entity, Game.Command.entry(Rising, { ticks: Math.round(BUILD_TICKS * SITE_SHARE) }))
}
- for (const { entity, data } of queries.rising.each()) {
- const ticks = data.rising.get().ticks + 1
+ const rising = queries.rising.data
+ for (const entity of queries.rising.each()) {
+ const ticks = rising.rising.get(entity).ticks + 1
if (ticks >= BUILD_TICKS) {
commands.remove(entity, Rising)
// Up and standing; its work (if it has any) says otherwise from here on.
- if (data.status.present) commands.insert(entity, Game.Command.entry(Status, "idle"))
- } else data.rising.set({ ticks })
+ if (rising.status.has(entity)) commands.insert(entity, Game.Command.entry(Status, "idle"))
+ } else rising.rising.set(entity, { ticks })
}
}
)
diff --git a/src/game/systems/work/spread.ts b/src/game/systems/work/spread.ts
index e994af2..1a40200 100644
--- a/src/game/systems/work/spread.ts
+++ b/src/game/systems/work/spread.ts
@@ -25,10 +25,11 @@ export const Spread = Game.System(
if (!every(resources.time.get(), SPREAD_TICKS)) return
const grid = resources.grid.get()
const random = Random.draw(resources.rng)
- const grown = queries.trees.each().filter(({ data }) => data.tree.get().growth >= GROWN.tree)
+ const { data } = queries.trees
+ const grown = queries.trees.each().filter((entity) => data.tree.get(entity).growth >= GROWN.tree)
const parent = random.pick(grown)
if (parent) {
- const t = parent.data.tile.get()
+ const t = data.tile.get(parent)
const spot = random.pick(wildTreeSpots(grid, t))
if (spot && canSeedTree(grid, spot)) commands.spawn(treeDraft(spot, 0))
}
diff --git a/src/game/systems/work/work.ts b/src/game/systems/work/work.ts
index 98fa5eb..d6d0839 100644
--- a/src/game/systems/work/work.ts
+++ b/src/game/systems/work/work.ts
@@ -64,16 +64,17 @@ export const Work = Game.System(
let value: T | undefined
return () => (value ??= make())
}
- 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 trees = lazy(() => new Map(queries.trees.each().map((entity) => [entity.id as number, entity])))
+ const rocks = lazy(() => new Map(queries.rocks.each().map((entity) => [entity.id as number, entity])))
+ const fields = lazy(() => new Map(queries.fields.each().map((entity) => [entity.id as number, entity])))
+ const waters = lazy(() => new Map(queries.waters.each().map((entity) => [entity.id as number, entity])))
+ const land = { tree: queries.trees.data.tree, rock: queries.rocks.data.rock, field: queries.fields.data.field, water: queries.waters.data.water }
const used = new Set<number>()
// A worked face gives one more now and then.
if (tick % rules.faceTicks === 0)
- for (const { data } of queries.rocks.each()) {
- const r = data.rock.get()
- if (r.amount <= 0) data.rock.set({ ...r, amount: 1 })
+ for (const entity of queries.rocks.each()) {
+ const r = land.rock.get(entity)
+ if (r.amount <= 0) land.rock.set(entity, { ...r, amount: 1 })
}
/** Takes what a gatherer needs from the land within reach, or says there is none. */
@@ -85,22 +86,22 @@ export const Work = Game.System(
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 })
+ if (!water || tick - land.water.get(water).fished < rules.restockTicks) continue
+ land.water.set(water, { 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
- commands.despawn(tree.entity)
+ if (!tree || land.tree.get(tree).growth < GROWN.tree) continue
+ commands.despawn(tree)
used.add(id)
return true
}
if ((source === "stone" || source === "ore") && use === "rock") {
const rock = rocks().get(id)
if (!rock) continue
- const r = rock.data.rock.get()
+ const r = land.rock.get(rock)
if (r.ore !== (source === "ore")) continue
// A masonry cuts a worked face at full pace (see `Upgrade.deep`); anyone else waits for it.
if (r.amount <= 0) {
@@ -109,8 +110,8 @@ export const Work = Game.System(
return true
}
// Quarried down, a rock stays as a worked face (see `FACE_TICKS`).
- rock.data.rock.set({ ...r, amount: r.amount - 1 })
- if (r.amount === 2 && ![...rocks().values()].some((o) => o !== rock && o.data.rock.get().ore === r.ore && o.data.rock.get().amount >= 2))
+ land.rock.set(rock, { ...r, amount: r.amount - 1 })
+ if (r.amount === 2 && ![...rocks().values()].some((o) => o !== rock && land.rock.get(o).ore === r.ore && land.rock.get(o).amount >= 2))
write(
resources.chronicle,
t,
@@ -124,8 +125,8 @@ export const Work = Game.System(
}
if (source === "field" && use === "field") {
const field = fields().get(id)
- if (!field || field.data.field.get().growth < GROWN.field) continue
- field.data.field.set({ growth: 0 })
+ if (!field || land.field.get(field).growth < GROWN.field) continue
+ land.field.set(field, { growth: 0 })
used.add(id)
return true
}
@@ -133,13 +134,14 @@ export const Work = Game.System(
return false
}
- for (const { data } of queries.workshops.each()) {
- const tile = data.tile.get()
- const kind = kinds[data.building.get().kind]
- const staff = data.staff.get()
- const gatherer = data.gatherer.value()
- let recipe = data.recipe.get()
- const inventory = data.inventory.get()
+ const { data } = queries.workshops
+ for (const entity of queries.workshops.each()) {
+ const tile = data.tile.get(entity)
+ const kind = kinds[data.building.get(entity).kind]
+ const staff = data.staff.get(entity)
+ const gatherer = data.gatherer.get(entity)
+ let recipe = data.recipe.get(entity)
+ const inventory = data.inventory.get(entity)
let stock = inventory.stock
const open = connected(grid, tile)
const room = stock[recipe.output] + recipe.batch <= inventory.cap
@@ -147,7 +149,7 @@ export const Work = Game.System(
let short = !fed
if (open && staff.assigned > 0 && recipe.progress === 0 && room && fed) {
- const deep = upgradeAt(kind, data.upgraded.value()?.level ?? 0)?.deep ?? false
+ const deep = upgradeAt(kind, data.upgraded.get(entity)?.level ?? 0)?.deep ?? false
if (gatherer && !gather(gatherer.source, tile, gatherer.radius, deep)) short = true
else {
if (recipe.input !== null) stock = { ...stock, [recipe.input]: stock[recipe.input] - recipe.inputs }
@@ -155,7 +157,7 @@ export const Work = Game.System(
}
}
- const pace = equipmentPace(kind, stock.tools, data.condition.value()?.value ?? Infinity, fishing, rules)
+ const pace = equipmentPace(kind, stock.tools, data.condition.get(entity)?.value ?? Infinity, fishing, rules)
const put = effort(staff, tick, rules)
if (open && recipe.progress > 0 && put > 0 && paced(pace, tick)) {
const progress = recipe.progress + put
@@ -167,7 +169,7 @@ export const Work = Game.System(
if (kind.wear && recipe.made % kind.wear === 0 && stock.tools > 0) stock = { ...stock, tools: stock.tools - 1 }
} else recipe = { ...recipe, progress }
}
- const status: StatusValue = data.paused.present
+ const status: StatusValue = data.paused.has(entity)
? "paused"
: !open
? "unconnected"
@@ -180,9 +182,9 @@ export const Work = Game.System(
: short
? "starved"
: "idle"
- data.recipe.set(recipe)
- if (stock !== inventory.stock) data.inventory.set({ ...inventory, stock })
- if (data.status.get() !== status) data.status.set(status)
+ data.recipe.set(entity, recipe)
+ if (stock !== inventory.stock) data.inventory.set(entity, { ...inventory, stock })
+ if (data.status.get(entity) !== status) data.status.set(entity, status)
}
if (Object.keys(made).length > 0) resources.flow.update((f) => ({ ...f, made: each((g) => f.made[g] + (made[g] ?? 0)) }))
}
diff --git a/src/render/three/draw/animate.ts b/src/render/three/draw/animate.ts
index ef02f1c..7b0e9da 100644
--- a/src/render/three/draw/animate.ts
+++ b/src/render/three/draw/animate.ts
@@ -105,78 +105,82 @@ export const Animate = Game.System(
const dt = services.clock.deltaSeconds
// Fish where the water would give a catch now; none where it rests after one.
const tick = resources.time.get().step
- services.stage.setFish(queries.water.each().filter(({ data }) => tick - data.water.get().fished >= RESTOCK_TICKS).map(({ data }) => data.tile.get()))
+ const water = queries.water.data
+ services.stage.setFish(queries.water.each().filter((entity) => tick - water.water.get(entity).fished >= RESTOCK_TICKS).map((entity) => water.tile.get(entity)))
- for (const { entity, data } of queries.buildings.each()) {
- const kind = kinds[data.building.get().kind]
- const status = data.status.get()
+ const building = queries.buildings.data
+ for (const entity of queries.buildings.each()) {
+ const kind = kinds[building.building.get(entity).kind]
+ const status = building.status.get(entity)
// An upgrade the town needs now, and can make (see `upgradesWanted`).
const upgradable = services.shown.scene.wanted.has(entity.id)
- const recipe = data.recipe.value()
- const walkers = data.walkers.value()?.length ?? 0
- const worn = (data.condition.value()?.value ?? CONDITION_MAX) < wear.worn
- const r = data.risk.value()
+ const recipe = building.recipe.get(entity)
+ const walkers = building.walkers.get(entity)?.length ?? 0
+ const worn = (building.condition.get(entity)?.value ?? CONDITION_MAX) < wear.worn
+ const r = building.risk.get(entity)
services.buildingNodes.get(entity.id)?.update(
{
alert: alertOf(r ? { fire: r.fire, health: 0, order: 0 } : undefined, false, worn),
- burning: data.burning.present,
+ burning: building.burning.has(entity),
worn,
effects: {
- wear: 1-(data.condition.value()?.value??CONDITION_MAX)/CONDITION_MAX,
+ wear: 1-(building.condition.get(entity)?.value??CONDITION_MAX)/CONDITION_MAX,
fireRisk: hazardStrength(r?.fire??0,risk.warn,RISK_MAX)
},
working: status === "working",
tint: services.shown.scene.tints.get(entity.id),
problem: problemOf(kind, status) !== null,
- build: buildOf(data.site.value(), data.rising.value()),
- beat: recipe ? recipe.made : data.service.value() ? walkers : 0,
- doors: doorsOf(grid, data.tile.get()),
- site: siteShare(data.site.value()),
- level: data.upgraded.value()?.level ?? 0,
- works: worksShare(data.works.value()),
+ build: buildOf(building.site.get(entity), building.rising.get(entity)),
+ beat: recipe ? recipe.made : building.service.get(entity) ? walkers : 0,
+ doors: doorsOf(grid, building.tile.get(entity)),
+ site: siteShare(building.site.get(entity)),
+ level: building.upgraded.get(entity)?.level ?? 0,
+ works: worksShare(building.works.get(entity)),
upgradable
},
dt,
emphasis(entity.id)
)
}
- for (const { entity, data } of queries.houses.each()) {
- const tile = data.tile.get()
- const worn = (data.condition.value()?.value ?? CONDITION_MAX) < wear.worn
+ const house = queries.houses.data
+ for (const entity of queries.houses.each()) {
+ const tile = house.tile.get(entity)
+ const worn = (house.condition.get(entity)?.value ?? CONDITION_MAX) < wear.worn
const desirability = appealAt(cells, tile.x, tile.y)
services.houseNodes
.get(entity.id)
?.update(
{
- tier: data.house.get().tier,
- build: buildOf(data.site.value(), data.rising.value()),
+ tier: house.house.get(entity).tier,
+ build: buildOf(house.site.get(entity), house.rising.get(entity)),
doors: doorsOf(grid, tile),
- site: siteShare(data.site.value()),
- alert: data.site.present ? null : alertOf(data.risk.value(), data.sick.present, worn),
- burning: data.burning.present,
+ site: siteShare(house.site.get(entity)),
+ alert: house.site.has(entity) ? null : alertOf(house.risk.get(entity), house.sick.has(entity), worn),
+ burning: house.burning.has(entity),
worn,
effects: {
- wear: Math.max(desirability<0?0.55:0,1-(data.condition.value()?.value??CONDITION_MAX)/CONDITION_MAX),
- fireRisk: hazardStrength(data.risk.value()?.fire??0,risk.warn,RISK_MAX),
- health: hazardStrength(data.risk.value()?.health??0,risk.warn,RISK_MAX),
- order: hazardStrength(data.risk.value()?.order??0,risk.warn,RISK_MAX),
- sick: Number(data.sick.present)
+ wear: Math.max(desirability<0?0.55:0,1-(house.condition.get(entity)?.value??CONDITION_MAX)/CONDITION_MAX),
+ fireRisk: hazardStrength(house.risk.get(entity)?.fire??0,risk.warn,RISK_MAX),
+ health: hazardStrength(house.risk.get(entity)?.health??0,risk.warn,RISK_MAX),
+ order: hazardStrength(house.risk.get(entity)?.order??0,risk.warn,RISK_MAX),
+ sick: Number(house.sick.has(entity))
},
band: desirability < 0 ? "poor" : desirability >= home.tiers[2].appeal ? "fine" : "plain",
- closed: data.closed.present,
+ closed: house.closed.has(entity),
tint: services.shown.scene.tints.get(entity.id)
},
emphasis(entity.id)
)
}
- for (const { entity } of queries.ruins.each()) services.ruinNodes.get(entity.id)?.update(emphasis(entity.id))
- for (const { entity, data } of queries.walkers.each()) {
- const p = walkerAt(data.route.get())
- const errand = data.errand.value()
- const roam = data.roam.value()
+ for (const entity of queries.ruins.each()) services.ruinNodes.get(entity.id)?.update(emphasis(entity.id))
+ const walker = queries.walkers.data
+ for (const entity of queries.walkers.each()) {
+ const p = walkerAt(walker.route.get(entity))
+ const errand = walker.errand.get(entity)
+ const roam = walker.roam.get(entity)
const load: Load = errand
? { kind: "cart", good: errand.good, count: !errand.back || errand.count > 0 ? errand.count : 0 }
- : data.rescue.value()
+ : walker.rescue.get(entity)
? { kind: "service", role: "firefighter" }
: roam?.service === "fire"
? { kind: "service", role: "watchman" }
@@ -193,22 +197,25 @@ export const Animate = Game.System(
: { kind: "none" }
services.walkerNodes.get(entity.id)?.update(p.x, p.y, p.dir, p.phase, load)
}
- for (const { entity, data } of queries.trees.each())
- services.treeNodes.get(entity.id)?.update(data.tree.get().growth, emphasis(entity.id))
+ const tree = queries.trees.data
+ for (const entity of queries.trees.each())
+ services.treeNodes.get(entity.id)?.update(tree.tree.get(entity).growth, emphasis(entity.id))
// Neighbouring rocks are drawn as one big outcrop; the blocks are formed again only when a rock runs out (or the land changes).
const rocks = queries.rocks.each()
- const rockKey = `${rocks.length}:${rocks.reduce((n, { entity }) => n + entity.id, 0)}`
+ const rock = queries.rocks.data
+ const rockKey = `${rocks.length}:${rocks.reduce((n, entity) => n + entity.id, 0)}`
if (rockKey !== rockShapes.key) {
rockShapes.key = rockKey
- rockShapes.parts = rockBlocks(rocks.map(({ entity, data }) => ({ id: entity.id, ...data.tile.get(), ore: data.rock.get().ore })))
+ rockShapes.parts = rockBlocks(rocks.map((entity) => ({ id: entity.id, ...rock.tile.get(entity), ore: rock.rock.get(entity).ore })))
}
- const amounts = new Map<number, number>(rocks.map(({ entity, data }) => [entity.id, data.rock.get().amount]))
- for (const { entity, data } of rocks) {
- const r = data.rock.get()
+ const amounts = new Map<number, number>(rocks.map((entity) => [entity.id, rock.rock.get(entity).amount]))
+ for (const entity of rocks) {
+ const r = rock.rock.get(entity)
const part = rockShapes.parts.get(entity.id)
if (!part || !part.draws) services.rockNodes.get(entity.id)?.update(r.ore, r.amount, part ? 0 : 1, part ? 0 : 1)
else services.rockNodes.get(entity.id)?.update(r.ore, part.members.reduce((n, id) => n + (amounts.get(id) ?? 0), 0) / part.members.length, part.w, part.h)
}
- for (const { entity, data } of queries.fields.each()) services.fieldNodes.get(entity.id)?.update(data.field.get().growth)
+ const field = queries.fields.data
+ for (const entity of queries.fields.each()) services.fieldNodes.get(entity.id)?.update(field.field.get(entity).growth)
}
)
diff --git a/src/render/three/draw/ground.ts b/src/render/three/draw/ground.ts
index 6dcfe08..195d7fe 100644
--- a/src/render/three/draw/ground.ts
+++ b/src/render/three/draw/ground.ts
@@ -21,10 +21,11 @@ export const DrawGround = Game.System(
({ queries, despawned, services }) => {
const dirty = services.stage.groundDirty
if (!dirty && queries.laid.each().length === 0 && despawned.entities.all().length === 0) return
- const cellsOf = (rows: ReadonlyArray<{ readonly data: { readonly tile: { get(): TileLike } } }>) =>
- new Set(rows.map(({ data }) => key(data.tile.get().x, data.tile.get().y)))
- const roads = cellsOf(queries.roads.each())
- services.stage.setGround(roads, cellsOf(queries.water.each()), cellsOf(queries.paved.each()))
- services.stage.setParks(new Map(queries.parks.each().map(({ data }) => [key(data.tile.get().x, data.tile.get().y), { ...data.tile.get(), ...data.park.get() }])), roads)
+ const cellsOf = <E>(query: { each(): ReadonlyArray<E>; readonly data: { readonly tile: { get(entity: E): TileLike } } }) =>
+ new Set(query.each().map((entity) => key(query.data.tile.get(entity).x, query.data.tile.get(entity).y)))
+ const roads = cellsOf(queries.roads)
+ services.stage.setGround(roads, cellsOf(queries.water), cellsOf(queries.paved))
+ const parks = queries.parks.data
+ services.stage.setParks(new Map(queries.parks.each().map((entity) => [key(parks.tile.get(entity).x, parks.tile.get(entity).y), { ...parks.tile.get(entity), ...parks.park.get(entity) }])), roads)
}
)
diff --git a/src/render/three/draw/stroll.ts b/src/render/three/draw/stroll.ts
index f5e61e6..1eceb25 100644
--- a/src/render/three/draw/stroll.ts
+++ b/src/render/three/draw/stroll.ts
@@ -24,10 +24,11 @@ export const Stroll = Game.System(
townsfolk.land = mask
townsfolk.folk.clear()
}
+ const { data } = queries.houses
const homes = queries.houses
.each()
- .filter(({ data }) => !data.site.value() && !data.rising.value())
- .map(({ data }) => ({ ...data.tile.get(), tier: data.house.get().tier, residents: data.house.get().residents }))
+ .filter((entity) => !data.site.get(entity) && !data.rising.get(entity))
+ .map((entity) => ({ ...data.tile.get(entity), tier: data.house.get(entity).tier, residents: data.house.get(entity).residents }))
townsfolk.folk.step(services.clock.deltaSeconds * services.shown.scene.pace, homes, resources.grid.get())
}
)
diff --git a/src/view/alerts.ts b/src/view/alerts.ts
index b12fc32..a881233 100644
--- a/src/view/alerts.ts
+++ b/src/view/alerts.ts
@@ -31,24 +31,24 @@ export const alertsOf = (frame: Frame, patience: Patience) => {
const census = frame.world.census
const stock = frame.world.stock
/** A building of this kind stands (built, not a site). */
- const stands = (k: KindId) => buildings.some(({ data }) => data.building.get().kind === k && !data.site.present && !data.rising.present)
+ const stands = (k: KindId) => buildings.some(({ data }) => data.building.kind === k && data.site === undefined && data.rising === undefined)
// Each line says what is wrong, then what to do about it.
- const burningRow = [...buildings, ...houses].find(({ data }) => data.burning.present)
+ const burningRow = [...buildings, ...houses].find(({ data }) => data.burning !== undefined)
const fireText = `${census.burning} on fire: ${stands("firewatch") ? "the fire watch's firefighters are on their way" : "build a fire watch nearby, whose firefighters put fires out"}`
- if (census.burning > 0) alerts.push({ tone: "bad", text: fireText, at: burningRow?.data.tile.get() ?? null, size: burningRow?.data.tile.get().size ?? 1, id: burningRow?.entity.id ?? null })
- const sickRow = houses.find(({ data }) => data.sick.present)
+ if (census.burning > 0) alerts.push({ tone: "bad", text: fireText, at: burningRow?.data.tile ?? null, size: burningRow?.data.tile.size ?? 1, id: burningRow?.entity.id ?? null })
+ const sickRow = houses.find(({ data }) => data.sick !== undefined)
const sickText = `${census.sick} home${census.sick > 1 ? "s" : ""} sick, holding half as many people: ${stands("healer") || stands("hospital") ? "a healer within reach of its road cures it" : "build a healer among the homes"}`
- if (census.sick > 0) alerts.push({ tone: "warn", text: sickText, at: sickRow?.data.tile.get() ?? null, size: 1, id: sickRow?.entity.id ?? null })
+ if (census.sick > 0) alerts.push({ tone: "warn", text: sickText, at: sickRow?.data.tile ?? null, size: 1, id: sickRow?.entity.id ?? null })
const waiting = new Map<string, { n: number; at: TileLike; id: number; kind: KindId }>()
const remote = new Map<string, { n: number; at: TileLike; id: number; kind: KindId }>()
const shortStaffed: Array<{ id: number; title: string; cell: Point; size: number; assigned: number; needed: number; nobodyNear: boolean }> = []
const seen = new Set<number>()
for (const { entity, data } of buildings) {
- if (data.site.present || data.rising.present || data.paused.present) continue
- const kind = kinds[data.building.get().kind]
- const status = data.status.get()
- const staff = data.staff.get()
- const tile = data.tile.get()
+ if (data.site !== undefined || data.rising !== undefined || data.paused !== undefined) continue
+ const kind = kinds[data.building.kind]
+ const status = data.status
+ const staff = data.staff
+ const tile = data.tile
if (status === "starved" && kind.recipe?.input) {
seen.add(entity.id)
const since = patience.starvedSince.get(entity.id) ?? tick
@@ -73,12 +73,12 @@ export const alertsOf = (frame: Frame, patience: Patience) => {
Object.fromEntries([...m.values()].map((v) => [v.kind, { at: v.at, size: v.at.size, id: v.id }]))
if (waiting.size > 0) alerts.push({ tone: "warn", text: `idle: the ${list(waiting)}. Build more of what makes it, or buy it in the [town] panel`, at: first(waiting)?.at ?? null, size: first(waiting)?.at.size ?? 1, id: first(waiting)?.id ?? null, places: placesOf(waiting) })
if (remote.size > 0) alerts.push({ tone: "warn", text: `no workers for the ${list(remote)}: lay [homes] within ${COMMUTE} road cells of it, or a road to homes nearby`, at: first(remote)?.at ?? null, size: first(remote)?.at.size ?? 1, id: first(remote)?.id ?? null, places: placesOf(remote) })
- const hallRow = buildings.find(({ data }) => data.hall.present)
+ const hallRow = buildings.find(({ data }) => data.hall !== undefined)
const empty = census.homes > 0 && larder(stock) === 0
if (!empty || (patience.emptySince !== null && patience.emptySince > tick)) patience.emptySince = null
if (empty && patience.emptySince === null) patience.emptySince = tick
if (empty && tick - patience.emptySince! >= HUNGER_PATIENCE) patience.hungryUntil = tick + HUNGER_PATIENCE
if (patience.hungryUntil > tick + HUNGER_PATIENCE) patience.hungryUntil = 0
- if (census.homes > 0 && tick < patience.hungryUntil) alerts.push({ tone: "bad", text: "no food in store, so homes go hungry and pay no taxes: build another fishery, or buy fish in the [town] panel", at: hallRow?.data.tile.get() ?? null, size: hallRow?.data.tile.get().size ?? 1, id: hallRow?.entity.id ?? null })
+ if (census.homes > 0 && tick < patience.hungryUntil) alerts.push({ tone: "bad", text: "no food in store, so homes go hungry and pay no taxes: build another fishery, or buy fish in the [town] panel", at: hallRow?.data.tile ?? null, size: hallRow?.data.tile.size ?? 1, id: hallRow?.entity.id ?? null })
return { alerts, shortStaffed, hallRow }
}
diff --git a/src/view/frame.ts b/src/view/frame.ts
index 7f5d635..3d71e6d 100644
--- a/src/view/frame.ts
+++ b/src/view/frame.ts
@@ -7,7 +7,7 @@
* first asked.
*/
import type { Descriptor } from "@typeonce/ritmo"
-import type { Query, QueryMatch } from "@typeonce/ritmo/Query"
+import type { Query, QueryData, QueryEntity } from "@typeonce/ritmo/Query"
import { buildingSource, homeSource, landSource, parkSources, parksOf, type AppealSource, type ParkCell, type ParkValue } from "../game/world/appeal.ts"
import { condition as wear, CONDITION_MAX, type KindId } from "../game/content/index.ts"
@@ -63,7 +63,25 @@ const WaterRead = Game.Query({ selection: { tile: Game.Query.read(Tile) }, with:
const RockRead = Game.Query({ selection: { tile: Game.Query.read(Tile), rock: Game.Query.read(Rock) } })
const PavedRead = Game.Query({ selection: { tile: Game.Query.read(Tile) }, with: [Road, Paved] })
-type Row<Q extends Query.Any> = QueryMatch<typeof Game.schema, Q>
+/**
+ * One entity of a frame query, its values read once when the frame is taken:
+ * an optional slot is `undefined` when the entity lacks the component. Plain
+ * values, so a row stays readable after the run (a query's `data` does not).
+ */
+type Row<Q extends Query.Any> = {
+ readonly entity: QueryEntity<typeof Game.schema, Q>
+ readonly data: { readonly [K in keyof QueryData<Q>]: ReturnType<QueryData<Q>[K]["get"]> }
+}
+type FrameQuery<Q extends Query.Any> = { each(): ReadonlyArray<QueryEntity<typeof Game.schema, Q>>; readonly data: QueryData<Q> }
+const rowsOf = <Q extends Query.Any>(query: FrameQuery<Q>): Array<Row<Q>> => {
+ const slots: QueryData<Q> = query.data
+ const names = Object.keys(slots) as Array<keyof QueryData<Q>>
+ return query.each().map((entity) => {
+ const data = {} as { -readonly [K in keyof QueryData<Q>]: ReturnType<QueryData<Q>[K]["get"]> }
+ for (const name of names) data[name] = slots[name].get(entity) as ReturnType<QueryData<Q>[typeof name]["get"]>
+ return { entity, data }
+ })
+}
export type BuildingRow = Row<typeof BuildingRead>
export type HouseRow = Row<typeof HouseRead>
export type RuinRow = Row<typeof RuinRead>
@@ -102,7 +120,7 @@ const worldResources = {
}
/** Every resource the view reads, as its value this frame. */
export type World = { readonly [K in keyof typeof worldResources]: Descriptor.Descriptor.Value<(typeof worldResources)[K]> }
-type FrameRows = { readonly [K in keyof typeof frameAccess.queries]: Row<(typeof frameAccess.queries)[K]> }
+type FrameQueries = typeof frameAccess.queries
/** A thing's hit area for the pointer, nearest first. */
interface HitBox {
@@ -121,14 +139,14 @@ const hitAt = (hits: ReadonlyArray<HitBox>, at: Point, entity?: number | null) =
entity === undefined ? (hits.find((h) => h.contains(at))?.id ?? null) : entity
/** Rows with a site's plate down or still rising are not built yet. */
-type Raised = { readonly data: { readonly site: { readonly present: boolean }; readonly rising: { readonly present: boolean } } }
+type Raised = { readonly data: { readonly site: unknown; readonly rising: unknown } }
/**
* Reads the frame: `queries` and `resources` as `Project`'s callback receives
* them (see `frameAccess`).
*/
export const frameOf = (
- queries: { readonly [K in keyof FrameRows]: { each(): ReadonlyArray<FrameRows[K]> } },
+ queries: { readonly [K in keyof FrameQueries]: FrameQuery<FrameQueries[K]> },
resources: { readonly [K in keyof World]: { get(): World[K] } }
) => {
const world: World = {
@@ -138,23 +156,26 @@ export const frameOf = (
chronicle: resources.chronicle.get(), appeal: resources.appeal.get(), pantry: resources.pantry.get(), guide: resources.guide.get()
}
const grid = world.grid
- const buildings = queries.buildings.each()
- const houses = queries.houses.each()
- const ruins = queries.ruins.each()
- const parkRows = queries.parks.each()
- const rocks = queries.rocks.each()
- const parkCells: Array<ParkCell> = parkRows.map(({ data }) => ({ ...data.tile.get(), ...data.park.get() }))
- const parkAt = new Map(parkRows.map((row) => [key(row.data.tile.get().x, row.data.tile.get().y), row] as const))
+ const buildings = rowsOf(queries.buildings)
+ const houses = rowsOf(queries.houses)
+ const ruins = rowsOf(queries.ruins)
+ const parkRows = rowsOf(queries.parks)
+ const rocks = rowsOf(queries.rocks)
+ const trees = rowsOf(queries.trees)
+ const water = rowsOf(queries.water)
+ const paved = rowsOf(queries.paved)
+ const parkCells: Array<ParkCell> = parkRows.map(({ data }) => ({ ...data.tile, ...data.park }))
+ const parkAt = new Map(parkRows.map((row) => [key(row.data.tile.x, row.data.tile.y), row] as const))
const road = (x: number, y: number) => isRoad(grid, x, y)
const hits: Array<HitBox> = [
- ...buildings.map(({ entity, data }) => hitBox(entity.id, data.tile.get())),
- ...houses.map(({ entity, data }) => hitBox(entity.id, data.tile.get())),
- ...ruins.map(({ entity, data }) => hitBox(entity.id, data.tile.get())),
- ...parkRows.map(({ entity, data }) => hitBox(entity.id, data.tile.get()))
+ ...buildings.map(({ entity, data }) => hitBox(entity.id, data.tile)),
+ ...houses.map(({ entity, data }) => hitBox(entity.id, data.tile)),
+ ...ruins.map(({ entity, data }) => hitBox(entity.id, data.tile)),
+ ...parkRows.map(({ entity, data }) => hitBox(entity.id, data.tile))
].sort((l, r) => r.depth - l.depth)
// What stands, for a fix that builds something: it offers the first link of the chain the town lacks, else the last.
- const standing = new Set<KindId>(buildings.filter((r) => !r.data.site.present).map((r) => r.data.building.get().kind))
- const finished = (row: Raised) => !row.data.site.present && !row.data.rising.present
+ const standing = new Set<KindId>(buildings.filter((r) => r.data.site === undefined).map((r) => r.data.building.kind))
+ const finished = (row: Raised) => row.data.site === undefined && row.data.rising === undefined
let unreached: number | null = null
let sources: Array<AppealSource> | null = null
const frame = {
@@ -169,11 +190,11 @@ export const frameOf = (
ruins,
parkRows,
rocks,
- trees: queries.trees.each(),
- water: queries.water.each(),
- paved: queries.paved.each(),
+ trees,
+ water,
+ paved,
/** The rocks by cell: which are ore, and which are worked down to their faces. */
- rockAt: new Map(rocks.map(({ data }) => [key(data.tile.get().x, data.tile.get().y), data.rock.get()])),
+ rockAt: new Map(rocks.map(({ data }) => [key(data.tile.x, data.tile.y), data.rock])),
parkCells,
parkAt,
road,
@@ -197,7 +218,7 @@ export const frameOf = (
const hit = hitAt(hits, at, entity)
return hit ?? parkAt.get(key(Math.floor(at.x), Math.floor(at.y)))?.entity.id ?? null
},
- tileOf: (id: number) => [...buildings, ...houses, ...ruins, ...parkRows].find((row) => row.entity.id === id)?.data.tile.get(),
+ tileOf: (id: number) => [...buildings, ...houses, ...ruins, ...parkRows].find((row) => row.entity.id === id)?.data.tile,
standing,
finished,
fixOf: (f: Fix | undefined): Line["fix"] => f && { text: f.text, build: f.build?.find((k) => !standing.has(k)) ?? f.build?.at(-1) },
@@ -205,11 +226,11 @@ export const frameOf = (
unreachedHomes: () => {
if (unreached !== null) return unreached
const walks = buildings
- .filter((row) => row.data.service.value()?.service === "goods" && finished(row))
- .map((row) => ({ way: reach(grid, doors(grid, row.data.tile.get())), range: row.data.service.value()!.range }))
+ .filter((row) => row.data.service?.service === "goods" && finished(row))
+ .map((row) => ({ way: reach(grid, doors(grid, row.data.tile)), range: row.data.service!.range }))
unreached = houses.filter((row) => {
if (!finished(row)) return false
- const ds = doors(grid, row.data.tile.get())
+ const ds = doors(grid, row.data.tile)
return ds.length > 0 && !walks.some((w) => (nearest(w.way, ds)?.distance ?? Infinity) < w.range)
}).length
return unreached
@@ -219,19 +240,19 @@ export const frameOf = (
if (sources) return sources
sources = []
for (const { data } of buildings) {
- if (data.site.present || data.rising.present) continue
- const s = buildingSource(data.building.get().kind, data.tile.get(), undefined, data.upgraded.value()?.level ?? 0)
+ if (data.site !== undefined || data.rising !== undefined) continue
+ const s = buildingSource(data.building.kind, data.tile, undefined, data.upgraded?.level ?? 0)
if (s) sources.push(s)
}
- for (const { data } of queries.trees.each()) sources.push(landSource("forest", data.tile.get()))
- for (const { data } of queries.water.each()) sources.push(landSource("water", data.tile.get()))
- for (const { data } of queries.paved.each()) sources.push(landSource("paved", data.tile.get()))
+ for (const { data } of trees) sources.push(landSource("forest", data.tile))
+ for (const { data } of water) sources.push(landSource("water", data.tile))
+ for (const { data } of paved) sources.push(landSource("paved", data.tile))
sources.push(...parkSources(parkCells, road))
- for (const { data } of ruins) sources.push(landSource("ruin", data.tile.get()))
+ for (const { data } of ruins) sources.push(landSource("ruin", data.tile))
for (const { data } of houses) {
- if (data.site.present || data.rising.present) continue
- if ((data.condition.value()?.value ?? CONDITION_MAX) < wear.worn) sources.push(landSource("worn", data.tile.get()))
- const fine = data.closed.present ? null : homeSource(data.house.get().tier, data.tile.get())
+ if (data.site !== undefined || data.rising !== undefined) continue
+ if ((data.condition?.value ?? CONDITION_MAX) < wear.worn) sources.push(landSource("worn", data.tile))
+ const fine = data.closed !== undefined ? null : homeSource(data.house.tier, data.tile)
if (fine) sources.push(fine)
}
return sources
diff --git a/src/view/guide.ts b/src/view/guide.ts
index 2df958e..cc70473 100644
--- a/src/view/guide.ts
+++ b/src/view/guide.ts
@@ -43,14 +43,14 @@ export const guideOf = (frame: Frame, ui: Interaction, send: (edit: Edit) => voi
send({ type: "guideOff", off: pending.off })
}
}
- const placedKinds = new Set(buildings.map(({ data }) => data.building.get().kind))
- const standingKinds = new Set(buildings.filter(({ data }) => !data.site.present && !data.rising.present).map(({ data }) => data.building.get().kind))
- const wornRow = buildings.find((row) => frame.finished(row) && !row.data.hall.present && (row.data.condition.value()?.value ?? CONDITION_MAX) < wear.mend)
+ const placedKinds = new Set(buildings.map(({ data }) => data.building.kind))
+ const standingKinds = new Set(buildings.filter(({ data }) => data.site === undefined && data.rising === undefined).map(({ data }) => data.building.kind))
+ const wornRow = buildings.find((row) => frame.finished(row) && row.data.hall === undefined && (row.data.condition?.value ?? CONDITION_MAX) < wear.mend)
// A settlers' home with bread, cloth, and faith, kept from citizens only by its street.
const poorRow = houses.find((row) => {
- const h = row.data.house.get()
+ const h = row.data.house
if (h.tier !== 1 || !frame.finished(row)) return false
- const tile = row.data.tile.get()
+ const tile = row.data.tile
return met(h, "bread") && met(h, "cloth") && met(h, "faith") && appealAt(cells, tile.x, tile.y) < home.tiers[2].appeal
})
const saved = frame.world.guide
@@ -73,7 +73,7 @@ export const guideOf = (frame: Frame, ui: Interaction, send: (edit: Edit) => voi
builtHomes: houses.filter(frame.finished).length,
residents: census.settlers + census.citizens,
citizens: census.citizens,
- finerHomes: houses.filter((row) => row.data.house.get().tier > 1).length,
+ finerHomes: houses.filter((row) => row.data.house.tier > 1).length,
placed: placedKinds,
standing: standingKinds,
stock,
@@ -92,22 +92,22 @@ export const guideOf = (frame: Frame, ui: Interaction, send: (edit: Edit) => voi
most: Math.max(...goodIds.map((g) => stock[g])),
sawTown: ui.menu === "town",
sawHome: houses.some((row) => row.entity.id === ui.selected),
- sawBuilding: buildings.some((row) => row.entity.id === ui.selected && !row.data.hall.present),
+ sawBuilding: buildings.some((row) => row.entity.id === ui.selected && row.data.hall === undefined),
roadToWater: put.has("road") || roadNearWater(),
coins,
unreached: put.has("market") || standingKinds.has("market") ? 0 : frame.unreachedHomes(),
rank: f.rank,
- upgraded: new Set(buildings.filter((row) => row.data.upgraded.present).map((row) => row.data.building.get().kind)),
+ upgraded: new Set(buildings.filter((row) => row.data.upgraded !== undefined).map((row) => row.data.building.kind)),
risk: {
- fire: houses.some((row) => (row.data.risk.value()?.fire ?? 0) >= RISK_MAX * 0.35),
- health: houses.some((row) => (row.data.risk.value()?.health ?? 0) >= RISK_MAX * 0.35),
- order: houses.some((row) => (row.data.risk.value()?.order ?? 0) >= RISK_MAX * 0.35)
+ fire: houses.some((row) => (row.data.risk?.fire ?? 0) >= RISK_MAX * 0.35),
+ health: houses.some((row) => (row.data.risk?.health ?? 0) >= RISK_MAX * 0.35),
+ order: houses.some((row) => (row.data.risk?.order ?? 0) >= RISK_MAX * 0.35)
},
fewTrees: buildings.some((row) => {
- if (row.data.building.get().kind !== "lumberjack" || !frame.finished(row)) return false
- const tile = row.data.tile.get()
+ if (row.data.building.kind !== "lumberjack" || !frame.finished(row)) return false
+ const tile = row.data.tile
const reach = kinds.lumberjack.gathers!.radius
- return frame.trees.map(({ data }) => data.tile.get()).filter((t) => t.x >= tile.x - reach && t.x < tile.x + tile.size + reach && t.y >= tile.y - reach && t.y < tile.y + tile.size + reach).length < 6
+ return frame.trees.map(({ data }) => data.tile).filter((t) => t.x >= tile.x - reach && t.x < tile.x + tile.size + reach && t.y >= tile.y - reach && t.y < tile.y + tile.size + reach).length < 6
})
}
const playing = f.state === "playing" && !ui.founding
@@ -125,7 +125,7 @@ export const guideOf = (frame: Frame, ui: Interaction, send: (edit: Edit) => voi
const step = guide.off || !playing ? null : guideStep(facts, put, { shown: pace.shown, quiet: t < pace.quietUntil })
if (step && !step.urgent?.(facts)) pace.shown = step.id
pace.since = t
- const hallTile = hallRow?.data.tile.get()
+ const hallTile = hallRow?.data.tile
/** Of some tiles, the one nearest the town hall. */
const nearestHall = (tiles: ReadonlyArray<TileLike>): TileLike | undefined => {
if (!hallTile) return tiles[0]
@@ -140,14 +140,14 @@ export const guideOf = (frame: Frame, ui: Interaction, send: (edit: Edit) => voi
const focusOf = (focus: GuideFocus | null): { at: TileLike | null; id: number | null } => {
if (focus === null) return { at: null, id: null }
if (focus === "hall") return { at: hallTile ?? null, id: null }
- if (focus === "water") return { at: nearestHall(frame.water.map(({ data }) => data.tile.get())) ?? null, id: null }
- if (focus === "trees") return { at: nearestHall(frame.trees.map(({ data }) => data.tile.get())) ?? null, id: null }
+ if (focus === "water") return { at: nearestHall(frame.water.map(({ data }) => data.tile)) ?? null, id: null }
+ if (focus === "trees") return { at: nearestHall(frame.trees.map(({ data }) => data.tile)) ?? null, id: null }
if (focus === "stone" || focus === "ore") {
const ore = focus === "ore"
- return { at: nearestHall(frame.rocks.filter(({ data }) => data.rock.get().ore === ore).map(({ data }) => data.tile.get())) ?? null, id: null }
+ return { at: nearestHall(frame.rocks.filter(({ data }) => data.rock.ore === ore).map(({ data }) => data.tile)) ?? null, id: null }
}
- const row = focus === "worn" ? wornRow : focus === "poorStreet" ? poorRow : buildings.find(({ data }) => data.building.get().kind === focus.kind)
- return row ? { at: row.data.tile.get(), id: row.entity.id } : { at: null, id: null }
+ const row = focus === "worn" ? wornRow : focus === "poorStreet" ? poorRow : buildings.find(({ data }) => data.building.kind === focus.kind)
+ return row ? { at: row.data.tile, id: row.entity.id } : { at: null, id: null }
}
const shown = step ? focusOf(step.focus) : null
return {
diff --git a/src/view/interaction/gestures.ts b/src/view/interaction/gestures.ts
index 52f783e..687774d 100644
--- a/src/view/interaction/gestures.ts
+++ b/src/view/interaction/gestures.ts
@@ -59,17 +59,17 @@ export const applyGestures = (frame: Frame, ui: Interaction, send: (edit: Edit)
if (gesture.panned) break
const hit = frame.pickAt(gesture.at, gesture.hit)
const row = hit !== null ? buildings.find((b) => b.entity.id === hit) : undefined
- const kind = row ? kinds[row.data.building.get().kind] : undefined
+ const kind = row ? kinds[row.data.building.kind] : undefined
if (!row || !kind || (ui.upgrading && kind.id !== ui.upgrading)) {
const wanted = ui.upgrading ? (upgradeAt(kinds[ui.upgrading], 0) ? kinds[ui.upgrading].title.toLowerCase() : "building") : "building"
toast(`Pick a ${wanted} to upgrade`)
break
}
- if (row.data.works.present) {
+ if (row.data.works !== undefined) {
toast(`The ${kind.title.toLowerCase()} is already being upgraded`)
break
}
- send({ type: "upgrade", cell: row.data.tile.get() })
+ send({ type: "upgrade", cell: row.data.tile })
break
}
case "bulldoze": {
diff --git a/src/view/interaction/placing.ts b/src/view/interaction/placing.ts
index 21bb694..9622b7b 100644
--- a/src/view/interaction/placing.ts
+++ b/src/view/interaction/placing.ts
@@ -18,8 +18,8 @@ export const placeProblem = (frame: Frame, kind: Kind, tile: TileLike): { readon
const found =
source === "stone" || source === "ore"
? frame.rocks.some(({ data }) => {
- const t = data.tile.get()
- return data.rock.get().ore === (source === "ore") && reachCells.some((c) => c.x >= t.x && c.x < t.x + t.size && c.y >= t.y && c.y < t.y + t.size)
+ const t = data.tile
+ return data.rock.ore === (source === "ore") && reachCells.some((c) => c.x >= t.x && c.x < t.x + t.size && c.y >= t.y && c.y < t.y + t.size)
})
: reachCells.some((c) => useAt(grid, c.x, c.y) === source)
const what = { tree: "trees", stone: "pale stone rocks", ore: "dark ore rocks", water: "water" }[source]
diff --git a/src/view/overlay.ts b/src/view/overlay.ts
index 46b0271..958bdce 100644
--- a/src/view/overlay.ts
+++ b/src/view/overlay.ts
@@ -103,8 +103,8 @@ export const drawOverlay = (frame: Frame, ui: Interaction, scene: SceneView, tow
// The same reading washed over each model, so the view is legible where buildings hide the ground.
const tints = new Map<number, number>()
const tintOf = (color: number) => (color === GOOD ? TINT.good : color === FAIR ? TINT.fair : color === BAD ? TINT.bad : color === COOL ? TINT.cool : TINT.plain)
- const standing = <T extends { readonly data: { readonly site: { readonly present: boolean }; readonly rising: { readonly present: boolean } } }>(rows: ReadonlyArray<T>) =>
- rows.filter(({ data }) => !data.site.present && !data.rising.present)
+ const standing = <T extends { readonly data: { readonly site: unknown; readonly rising: unknown } }>(rows: ReadonlyArray<T>) =>
+ rows.filter(({ data }) => data.site === undefined && data.rising === undefined)
if (view === "appeal") {
for (let y = 0; y < GRID; y++)
for (let x = 0; x < GRID; x++) {
@@ -113,15 +113,15 @@ export const drawOverlay = (frame: Frame, ui: Interaction, scene: SceneView, tow
out.push({ x, y, size: 1, color: appealColor(appealAt(cells, x, y)), alpha: 0.32 })
}
for (const { entity, data } of standing(houses)) {
- const t = data.tile.get()
+ const t = data.tile
const d = appealAt(cells, t.x, t.y)
tints.set(entity.id, d >= home.tiers[2].appeal ? TINT.fine : d >= 0 ? TINT.plain : d > home.squalid ? TINT.fair : TINT.bad)
}
} else if (view === "workers") {
- const picked = pickedBuilding && pickedBuilding.data.staff.get().needed > 0 ? pickedBuilding : undefined
+ const picked = pickedBuilding && pickedBuilding.data.staff.needed > 0 ? pickedBuilding : undefined
let inReach: ((t: TileLike) => boolean) | null = null
if (picked) {
- const roads = reach(grid, doors(grid, picked.data.tile.get()))
+ const roads = reach(grid, doors(grid, picked.data.tile))
for (let k = 0; k < roads.distance.length; k++) {
const d = roads.distance[k]!
if (d >= 0 && d <= COMMUTE) out.push({ x: k % GRID, y: Math.floor(k / GRID), size: 1, color: MARK, alpha: 0.14 })
@@ -132,53 +132,53 @@ export const drawOverlay = (frame: Frame, ui: Interaction, scene: SceneView, tow
})
}
for (const { entity, data } of standing(houses)) {
- const t = data.tile.get()
- const h = data.house.get()
+ const t = data.tile
+ const h = data.house
const ring = inReach !== null && inReach(t)
out.push({ ...t, color: h.tier === 1 ? 0xd6b48a : COOL, alpha: ring ? 0.75 : 0.45, ...(ring ? { ring: true } : {}) })
tints.set(entity.id, h.tier === 1 ? TINT.settlers : TINT.cool)
}
for (const { entity, data } of standing(buildings)) {
- const s = data.staff.get()
+ const s = data.staff
if (s.needed === 0) continue
const color = s.assigned >= s.needed ? GOOD : s.assigned > 0 ? FAIR : BAD
- out.push({ ...data.tile.get(), color, alpha: 0.45, ...(entity.id === picked?.entity.id ? { ring: true } : {}) })
+ out.push({ ...data.tile, color, alpha: 0.45, ...(entity.id === picked?.entity.id ? { ring: true } : {}) })
tints.set(entity.id, tintOf(color))
}
} else if (view === "fire" || view === "health" || view === "order") {
for (const { entity, data } of standing(houses)) {
- const r = data.risk.value()
+ const r = data.risk
if (!r) continue
- const struck = view === "fire" ? data.burning.present : view === "health" ? data.sick.present : r.thefts > 0
+ const struck = view === "fire" ? data.burning !== undefined : view === "health" ? data.sick !== undefined : r.thefts > 0
const color = struck ? BAD : meterColor(r[view], RISK_MAX, risk.warn)
- out.push({ ...data.tile.get(), color, alpha: struck ? 0.8 : 0.5 })
+ out.push({ ...data.tile, color, alpha: struck ? 0.8 : 0.5 })
tints.set(entity.id, tintOf(color))
}
for (const { entity, data } of standing(buildings)) {
- const service = data.service.value()?.service
- const r = data.risk.value()
+ const service = data.service?.service
+ const r = data.risk
if (service === view) {
- out.push({ ...data.tile.get(), color: MARK, alpha: 0.55, ring: true })
+ out.push({ ...data.tile, color: MARK, alpha: 0.55, ring: true })
tints.set(entity.id, TINT.mark)
} else if (view === "fire" && r) {
- const color = data.burning.present ? BAD : meterColor(r.fire, RISK_MAX, risk.warn)
- out.push({ ...data.tile.get(), color, alpha: 0.4 })
+ const color = data.burning !== undefined ? BAD : meterColor(r.fire, RISK_MAX, risk.warn)
+ out.push({ ...data.tile, color, alpha: 0.4 })
tints.set(entity.id, tintOf(color))
}
}
} else if (view === "condition") {
for (const row of [...standing(houses), ...standing(buildings)]) {
- const c = row.data.condition.value()
+ const c = row.data.condition
if (!c) continue
const color = c.value < wear.worn ? BAD : c.value < wear.mend ? FAIR : GOOD
- out.push({ ...row.data.tile.get(), color, alpha: 0.5 })
+ out.push({ ...row.data.tile, color, alpha: 0.5 })
tints.set(row.entity.id, tintOf(color))
}
- for (const { entity, data } of standing(buildings)) if (data.service.value()?.service === "repair") {
- out.push({ ...data.tile.get(), color: MARK, alpha: 0.55, ring: true })
+ for (const { entity, data } of standing(buildings)) if (data.service?.service === "repair") {
+ out.push({ ...data.tile, color: MARK, alpha: 0.55, ring: true })
tints.set(entity.id, TINT.mark)
}
- for (const { data } of ruins) out.push({ ...data.tile.get(), color: BAD, alpha: 0.8 })
+ for (const { data } of ruins) out.push({ ...data.tile, color: BAD, alpha: 0.8 })
}
scene.overlay = { key: overlayKey, cells: out }
scene.tints = tints
diff --git a/src/view/panels/building.ts b/src/view/panels/building.ts
index 0ce6681..4df6454 100644
--- a/src/view/panels/building.ts
+++ b/src/view/panels/building.ts
@@ -19,9 +19,9 @@ export const told = (frame: Frame, c: Cause | null) => (c ? { note: c.why, fix:
*/
export const describeBuilding = (frame: Frame, row: BuildingRow) => {
const grid = frame.grid
- const kind = kinds[row.data.building.get().kind]
- const status = row.data.status.get()
- const site = row.data.site.value()
+ const kind = kinds[row.data.building.kind]
+ const status = row.data.status
+ const site = row.data.site
if (site) {
const owed = (Object.entries(site.owed) as Array<[GoodId, number]>).filter(([, n]) => n > 0)
const line: Line =
@@ -30,7 +30,7 @@ export const describeBuilding = (frame: Frame, row: BuildingRow) => {
: { icon: "build", label: "builders", value: "at work", tone: "ok" }
return { kind, status, problem: null, state: { icon: "build", label: "being built", tone: "warn" } as Line, groups: [{ title: "being built", icon: "build", lines: [line] }] as Array<Group> }
}
- const staff = row.data.staff.get()
+ const staff = row.data.staff
const work: Array<Line> = []
if (staff.needed > 0) {
const crew = kind.crew
@@ -49,15 +49,15 @@ export const describeBuilding = (frame: Frame, row: BuildingRow) => {
: undefined
})
}
- const recipe = row.data.recipe.value()
+ const recipe = row.data.recipe
if (recipe)
work.push({ icon: recipe.output, label: "makes", value: recipe.input ? `${goods[recipe.input].title} → ${goods[recipe.output].title}` : goods[recipe.output].title })
- const service = row.data.service.value()
+ const service = row.data.service
if (service)
work.push({
icon: service.service === "goods" ? "trade" : service.service === "faith" ? "faith" : service.service === "repair" ? "repair" : service.service,
label: "walkers out",
- value: `${row.data.walkers.value()?.length ?? 0}`
+ value: `${row.data.walkers?.length ?? 0}`
})
// A provisions walker's building: what its walkers handed to homes over the last minute, which its shelf
// alone cannot say (food leaves in the basket as soon as it comes; furniture mostly comes back).
@@ -73,7 +73,7 @@ export const describeBuilding = (frame: Frame, row: BuildingRow) => {
: { icon: "people", label: "handed out, last minute", value: "nothing", tone: "dim", note: "no home on its walks needed what it had" }
)
}
- const inventory = row.data.inventory.value()
+ const inventory = row.data.inventory
if (inventory) {
const held = inventory.accepts.filter((g) => inventory.stock[g] > 0).map((g) => ({ good: g, count: inventory.stock[g] }))
// A market's shelf is only what waits for the next walker.
@@ -87,10 +87,10 @@ export const describeBuilding = (frame: Frame, row: BuildingRow) => {
: { icon: "tools", label: "tools", value: "none", tone: "bad", note: "half pace until one comes: a smithy makes them, or buy them in the town panel" }
)
const running: Array<Line> = []
- const level = row.data.upgraded.value()?.level ?? 0
+ const level = row.data.upgraded?.level ?? 0
const upkeep = upkeepOf(kind, level)
if (upkeep > 0) running.push({ icon: "upkeep", label: "upkeep", value: `${upkeep} coins a minute` })
- const condition = row.data.condition.value()
+ const condition = row.data.condition
if (condition)
running.push({
icon: "condition",
@@ -99,7 +99,7 @@ export const describeBuilding = (frame: Frame, row: BuildingRow) => {
tone: condition.value < wear.worn ? "bad" : condition.value < wear.mend ? "warn" : "ok",
note: condition.value < wear.worn ? "half pace, and it may fall: a builder's yard mends it" : condition.value < wear.mend ? "a builder's yard mends it as its builder passes" : undefined
})
- const r = row.data.risk.value()
+ const r = row.data.risk
if (r)
running.push({
icon: "fire",
@@ -122,8 +122,8 @@ export const describeBuilding = (frame: Frame, row: BuildingRow) => {
...(work.length > 0 ? [{ title: "at work", icon: "jobs", lines: work } as Group] : []),
...(running.length > 0 ? [{ title: "running it", icon: "coins", help, lines: running } as Group] : [])
]
- const growing = status === "starved" && growingNear(grid, row.data.tile.get(), kind, frame.rockAt)
- const trouble: Problem | null = row.data.burning.present
+ const growing = status === "starved" && growingNear(grid, row.data.tile, kind, frame.rockAt)
+ const trouble: Problem | null = row.data.burning !== undefined
? { label: "on fire!", why: "its crew has fled", fix: { text: "a fire watch's watchmen put fires out", build: ["firewatch"] } }
: problemOf(kind, status, growing, { nearby: staff.nearby, crew: kind.crew })
const state: Line = trouble
@@ -135,11 +135,11 @@ export const describeBuilding = (frame: Frame, row: BuildingRow) => {
/** The panel of a building that is picked; `needed`: why the town needs its upgrade now, if it does. */
export const buildingPanel = (frame: Frame, row: BuildingRow, needed: string | null): Panel => {
const { kind, status, problem, state, groups } = describeBuilding(frame, row)
- const standing = !row.data.site.present && !row.data.rising.present
+ const standing = row.data.site === undefined && row.data.rising === undefined
const pausable = kind.id !== "townhall" && standing
- const level = row.data.upgraded.value()?.level ?? 0
+ const level = row.data.upgraded?.level ?? 0
const now = upgradeAt(kind, level)
- const works = row.data.works.value()
+ const works = row.data.works
const up = works ? undefined : nextUpgrade(kind, level)
const coins = frame.world.treasury.coins
const upgradeOffer = up && standing
@@ -161,7 +161,7 @@ export const buildingPanel = (frame: Frame, row: BuildingRow, needed: string | n
return {
type: "building",
id: row.entity.id,
- cell: row.data.tile.get(),
+ cell: row.data.tile,
kind: kind.id,
title: now?.title ?? kind.title,
blurb: now?.blurb ?? kind.blurb,
@@ -170,8 +170,8 @@ export const buildingPanel = (frame: Frame, row: BuildingRow, needed: string | n
state,
groups,
pausable,
- paused: row.data.paused.present,
- salvage: salvageFor(builtCost(kind, level), row.data.site.value(), works && { kind, ...works }),
+ paused: row.data.paused !== undefined,
+ salvage: salvageFor(builtCost(kind, level), row.data.site, works && { kind, ...works }),
level,
upgraded: level > 0,
upgrade: upgradeOffer,
diff --git a/src/view/panels/house.ts b/src/view/panels/house.ts
index b108084..e60df2d 100644
--- a/src/view/panels/house.ts
+++ b/src/view/panels/house.ts
@@ -22,10 +22,10 @@ const workOf = (frame: Frame, tile: TileLike, tier: Tier) => {
const roads = reach(grid, ds)
let best: { title: string; distance: number } | null = null
for (const { data } of buildings) {
- const kind = kinds[data.building.get().kind]
- const staff = data.staff.get()
+ const kind = kinds[data.building.kind]
+ const staff = data.staff
if (staff.needed === 0 || staff.assigned === 0 || (kind.crew !== crewOf(tier) && !(tier === 1 && staff.apprentices > 0))) continue
- for (const d of doors(grid, data.tile.get())) {
+ for (const d of doors(grid, data.tile)) {
const n = roads.distance[key(d.x, d.y)]!
if (n >= 0 && n <= COMMUTE && (best === null || n < best.distance)) best = { title: kind.title.toLowerCase(), distance: n }
}
@@ -37,8 +37,8 @@ const inTown = (frame: Frame): InTown => {
const stock = frame.world.stock
const sum = { fish: stock.fish, smoked: stock.smoked, bread: stock.bread, cloth: stock.cloth, furniture: stock.furniture }
for (const { data } of frame.buildings) {
- const inv = data.inventory.value()
- if (!inv || data.service.value()?.service !== "goods" || data.site.present || data.rising.present) continue
+ const inv = data.inventory
+ if (!inv || data.service?.service !== "goods" || data.site !== undefined || data.rising !== undefined) continue
sum.fish += inv.stock.fish
sum.smoked += inv.stock.smoked
sum.bread += inv.stock.bread
@@ -55,11 +55,11 @@ const servedAt = (frame: Frame, tile: TileLike): Served => {
const way = reach(grid, ds)
const served = { goods: false, faith: false }
for (const { data } of buildings) {
- const service = data.service.value()
- if (!service || data.site.present || data.rising.present || data.burning.present) continue
+ const service = data.service
+ if (!service || data.site !== undefined || data.rising !== undefined || data.burning !== undefined) continue
if (service.service !== "goods" && service.service !== "faith") continue
if (served[service.service]) continue
- const found = nearest(way, doors(grid, data.tile.get()))
+ const found = nearest(way, doors(grid, data.tile))
if (found && found.distance < service.range) served[service.service] = true
}
return served
@@ -71,21 +71,21 @@ const servedAt = (frame: Frame, tile: TileLike): Served => {
*/
export const describeHouse = (frame: Frame, row: HouseRow) => {
const { cells, approval, rates } = frame
- const h = row.data.house.get()
- const site = row.data.site.value()
+ const h = row.data.house
+ const site = row.data.site
const quiet = (summary: string, line: Line) => ({ h, summary, trouble: false, groups: [{ title: "household", icon: "homes", lines: [line] }] as Array<Group> })
if (site) return quiet("being built", { icon: "planks", label: "builders", value: "waiting for its plank", tone: "warn" })
- if (row.data.closed.present)
+ if (row.data.closed !== undefined)
return quiet("closed", { icon: "settlers", label: "closed", value: "empty", tone: "warn", note: "it pays no taxes and costs the town hall nothing: reopen it and settlers move back in" })
- const tile = row.data.tile.get()
+ const tile = row.data.tile
const tier = home.tiers[h.tier]
const nextTier = h.tier < 3 ? ((h.tier + 1) as Tier) : null
const there = appealParts(frame.appealSources(), tile)
const desirability = appealAt(cells, tile.x, tile.y)
const street: Street = { desirability, parts: there.parts }
- const r = row.data.risk.value()
+ const r = row.data.risk
const work = workOf(frame, tile, h.tier)
- const condition = row.data.condition.value()
+ const condition = row.data.condition
const town = inTown(frame)
const served = servedAt(frame, tile)
const rate = h.tier === 1 ? rates.settlers : rates.citizens
@@ -93,7 +93,7 @@ export const describeHouse = (frame: Frame, row: HouseRow) => {
const whyFewer =
cap >= tier.residents
? undefined
- : row.data.sick.present
+ : row.data.sick !== undefined
? "half as many while it is sick"
: approval < 0
? "fewer while the town disapproves of its mayor"
@@ -106,8 +106,8 @@ export const describeHouse = (frame: Frame, row: HouseRow) => {
const pays = Math.round(taxOf(h, rates, undefined, desirability))
const could = Math.round(suppliedTaxOf(h, rates, undefined, desirability))
const household: Array<Line> = [
- ...(row.data.burning.present ? [{ icon: "fire", label: "on fire", value: "everyone fled", tone: "bad" } as Line] : []),
- ...(row.data.sick.present ? [{ icon: "health", label: "sick", value: "half as many", tone: "bad", note: "it passes in a minute, or when a healer's physician calls" } as Line] : []),
+ ...(row.data.burning !== undefined ? [{ icon: "fire", label: "on fire", value: "everyone fled", tone: "bad" } as Line] : []),
+ ...(row.data.sick !== undefined ? [{ icon: "health", label: "sick", value: "half as many", tone: "bad", note: "it passes in a minute, or when a healer's physician calls" } as Line] : []),
{ icon: "people", label: "residents", value: `${h.residents} of ${cap}`, tone: whyFewer ? "warn" : "ok", note: whyFewer },
{
icon: "coins",
@@ -150,7 +150,7 @@ export const describeHouse = (frame: Frame, row: HouseRow) => {
else needs.push({ icon: "appeal", label: "street", value: signed(desirability), tone: "ok" })
if (blocks.some((b) => b.what === "services")) needs.push({ icon: "order", label: "services", value: `for ${home.tiers[3].title}`, tone: "warn", ...told(frame, servicesCause(r)) })
// Rising is a rebuilding, paid at once from the treasury and the store, once.
- const rebuilt = nextTier !== null && (row.data.rebuilt.value()?.tier ?? 1) >= nextTier
+ const rebuilt = nextTier !== null && (row.data.rebuilt?.tier ?? 1) >= nextTier
const short = nextTier && !rebuilt ? shortOf(home.tiers[nextTier].rise, frame.world.treasury.coins, frame.world.stock) : null
if (nextTier)
needs.push({
@@ -191,11 +191,11 @@ export const describeHouse = (frame: Frame, row: HouseRow) => {
: h.tier === 2
? `Red: it needs this now, or goes back to settlers. Amber: it needs this to become a townhouse of burghers, on a street of ${home.tiers[3].appeal} with a fire watch, a healer, and a watch house all calling.`
: "Red: it needs this now, or goes back to citizens."
- const summary = row.data.burning.present ? "on fire" : row.data.sick.present ? "sick" : hungry ? "hungry" : `${h.residents} resident${h.residents === 1 ? "" : "s"}`
+ const summary = row.data.burning !== undefined ? "on fire" : row.data.sick !== undefined ? "sick" : hungry ? "hungry" : `${h.residents} resident${h.residents === 1 ? "" : "s"}`
return {
h,
summary,
- trouble: row.data.burning.present || row.data.sick.present || hungry,
+ trouble: row.data.burning !== undefined || row.data.sick !== undefined || hungry,
groups: [
{ title: "household", icon: "homes", lines: household },
{ title: "needs", icon: "citizens", help: needHelp, lines: needs },
@@ -208,9 +208,9 @@ export const describeHouse = (frame: Frame, row: HouseRow) => {
export const housePanel = (frame: Frame, row: HouseRow): Panel => {
const { h, summary, trouble, groups } = describeHouse(frame, row)
return {
- type: "house", id: row.entity.id, cell: row.data.tile.get(), tier: h.tier, summary, trouble, groups,
- closable: !row.data.site.present && !row.data.rising.present && !row.data.burning.present,
- closed: row.data.closed.present,
- salvage: salvageFor(home.cost, row.data.site.value())
+ type: "house", id: row.entity.id, cell: row.data.tile, tier: h.tier, summary, trouble, groups,
+ closable: row.data.site === undefined && row.data.rising === undefined && row.data.burning === undefined,
+ closed: row.data.closed !== undefined,
+ salvage: salvageFor(home.cost, row.data.site)
}
}
diff --git a/src/view/panels/park.ts b/src/view/panels/park.ts
index 4518d83..b1fd7ef 100644
--- a/src/view/panels/park.ts
+++ b/src/view/panels/park.ts
@@ -29,12 +29,12 @@ const describePark = (p: ParkValue): Array<Line> => {
/** The panel of a park that is picked: the whole park the cell belongs to, or `null` if it is not one. */
export const parkPanel = (frame: Frame, row: ParkRow): Panel | null => {
- const picked = frame.parkOf(row.data.tile.get())
+ const picked = frame.parkOf(row.data.tile)
if (!picked) return null
return {
type: "park",
id: row.entity.id,
- cell: row.data.tile.get(),
+ cell: row.data.tile,
cells: picked.cells.length,
value: picked.value,
reach: picked.reach,
diff --git a/src/view/panels/ruin.ts b/src/view/panels/ruin.ts
index 5564646..7508f25 100644
--- a/src/view/panels/ruin.ts
+++ b/src/view/panels/ruin.ts
@@ -3,11 +3,11 @@ import type { Panel } from "../contracts.ts"
import type { RuinRow } from "../frame.ts"
export const ruinPanel = (row: RuinRow): Panel => {
- const r = row.data.ruin.get()
+ const r = row.data.ruin
return {
type: "ruin",
id: row.entity.id,
- cell: row.data.tile.get(),
+ cell: row.data.tile,
cause: r.cause,
lines: [
{ icon: "condition", label: "what happened", value: r.cause === "burnt" ? "it burned down" : r.cause === "collapsed" ? "it fell down for want of mending" : "it was left derelict after its thefts", tone: "bad" },
diff --git a/src/view/preview.ts b/src/view/preview.ts
index 7691082..36aa404 100644
--- a/src/view/preview.ts
+++ b/src/view/preview.ts
@@ -24,7 +24,7 @@ import { counted, signed } from "./text.ts"
const homesWorth = (frame: Frame, at: ReadonlyArray<Point>) => {
const { houses, cells, approval, rates } = frame
if (at.length === 0) return ""
- const standing = houses.filter((row) => !row.data.closed.present).reduce((n, row) => n + row.data.house.get().residents, 0)
+ const standing = houses.filter((row) => row.data.closed === undefined).reduce((n, row) => n + row.data.house.residents, 0)
const fed = { tier: 1 as Tier, food: 1, bread: 0, cloth: 0, faith: 0, furniture: 0, residents: home.tiers[1].residents }
let people = 0
const pays = at.reduce((sum, c) => {
@@ -48,7 +48,7 @@ export const previewOf = (frame: Frame, ui: Interaction) => {
const r = reachOf(kind)
if (r !== null) preview.plots.push({ x: tile.x - r, y: tile.y - r, size: tile.size + 2 * r, look: "reach" })
}
- const pavedCells = new Set(frame.paved.map(({ data }) => key(data.tile.get().x, data.tile.get().y)))
+ const pavedCells = new Set(frame.paved.map(({ data }) => key(data.tile.x, data.tile.y)))
/** The road cells within `limit` of a tile's doors: what a service's walkers, or a commute, would reach from here. */
const rangeFrom = (tile: TileLike, limit: number, note: string) => {
const ds = doors(grid, tile)
@@ -114,7 +114,7 @@ export const previewOf = (frame: Frame, ui: Interaction) => {
const laid: Array<ParkCell> = []
for (const c of ui.dragFrom ? rectangle(ui.dragFrom, cell) : [cell]) {
if (!inside(c.x, c.y)) continue
- const there = frame.parkAt.get(key(c.x, c.y))?.data.park.get()
+ const there = frame.parkAt.get(key(c.x, c.y))?.data.park
if (there ? there.ground !== ui.ground : canPlace(grid, { ...c, size: 1 })) laid.push({ ...c, ground: ui.ground, prop: there?.prop ?? "none" })
else if (!there) preview.plots.push({ ...c, size: 1, look: "blocked" })
}
@@ -125,7 +125,7 @@ export const previewOf = (frame: Frame, ui: Interaction) => {
preview.tooltip = `${grounds[ui.ground].title.toLowerCase()} · ${cost}${after ? ` · park ${signed(after.value)} desirability` : ""}`
if (after) preview.plots.push(...frame.reachPlots(after))
} else if (ui.tool === "prop" && cell && inside(cell.x, cell.y)) {
- const there = frame.parkAt.get(key(cell.x, cell.y))?.data.park.get()
+ const there = frame.parkAt.get(key(cell.x, cell.y))?.data.park
if (there) {
const placed = { ...cell, ground: there.ground, prop: ui.prop }
preview.parks.push(placed)
@@ -155,16 +155,16 @@ export const previewOf = (frame: Frame, ui: Interaction) => {
const rank = frame.world.fate.rank, coins = frame.world.treasury.coins
for (const row of buildings) {
const { data } = row
- if (data.building.get().kind !== ui.upgrading || data.site.present || data.rising.present) continue
- const kind = kinds[ui.upgrading], level = data.upgraded.value()?.level ?? 0, up = nextUpgrade(kind, level)
- const tile = data.tile.get()
+ if (data.building.kind !== ui.upgrading || data.site !== undefined || data.rising !== undefined) continue
+ const kind = kinds[ui.upgrading], level = data.upgraded?.level ?? 0, up = nextUpgrade(kind, level)
+ const tile = data.tile
if (!up) continue
const blocked = upgradeBlock(up, rank, { ranks })
const hovered = preview.hover === row.entity.id
- preview.plots.push({ ...tile, look: data.works.present || blocked ? "blocked" : hovered ? "picked" : "reach" })
+ preview.plots.push({ ...tile, look: data.works !== undefined || blocked ? "blocked" : hovered ? "picked" : "reach" })
if (!hovered) continue
const from = (upgradeAt(kind, level)?.title ?? kind.title).toLowerCase()
- preview.tooltip = data.works.present
+ preview.tooltip = data.works !== undefined
? `${from} → ${up.title.toLowerCase()} · under way: carriers are bringing its materials`
: [`${from} → ${up.title.toLowerCase()}`, upgradePrice(up), ...upgradeChanges(kind, level).map((c) => `· ${c}`),
blocked ?? (coins < up.cost.coins ? `${up.cost.coins - coins} coins short` : "click to begin: it goes on working meanwhile")].join("\n")
@@ -174,7 +174,7 @@ export const previewOf = (frame: Frame, ui: Interaction) => {
preview.danger = true
if ((preview.hover === null || useAt(grid, cell?.x ?? -1, cell?.y ?? -1) === "park") && cell && ["road", "tree", "field", "park"].includes(useAt(grid, cell.x, cell.y)))
preview.plots.push({ ...cell, size: 1, look: "blocked" })
- const there = cell ? frame.parkAt.get(key(cell.x, cell.y))?.data.park.get() : undefined
+ const there = cell ? frame.parkAt.get(key(cell.x, cell.y))?.data.park : undefined
if (there) preview.tooltip = there.prop !== "none" ? `remove the ${props[there.prop].title.toLowerCase()}` : `remove the ${grounds[there.ground].title.toLowerCase()}`
const rock = cell ? frame.rockAt.get(key(cell.x, cell.y)) : undefined
if (rock && cell) {
@@ -193,8 +193,8 @@ export const previewOf = (frame: Frame, ui: Interaction) => {
preview.plots.push(...frame.reachPlots(whole))
} else if (tile) preview.plots.push({ ...tile, look: "picked" })
if (row && tile) {
- showReach(tile, kinds[row.data.building.get().kind])
- rangeOfKind(tile, kinds[row.data.building.get().kind], row.data.service.value()?.range)
+ showReach(tile, kinds[row.data.building.kind])
+ rangeOfKind(tile, kinds[row.data.building.kind], row.data.service?.range)
}
}
return { preview, dropping }
diff --git a/src/view/stats.ts b/src/view/stats.ts
index ddb08fa..ea64227 100644
--- a/src/view/stats.ts
+++ b/src/view/stats.ts
@@ -19,9 +19,9 @@ export const numbersOf = (frame: Frame) => {
const t = elapsed(frame.world.time, charter)
let suppliedTaxes = 0
for (const { data } of houses) {
- if (data.site.present || data.rising.present || data.burning.present) continue
- const tile = data.tile.get()
- suppliedTaxes += suppliedTaxOf(data.house.get(), rates, undefined, appealAt(cells, tile.x, tile.y))
+ if (data.site !== undefined || data.rising !== undefined || data.burning !== undefined) continue
+ const tile = data.tile
+ suppliedTaxes += suppliedTaxOf(data.house, rates, undefined, appealAt(cells, tile.x, tile.y))
}
const coins = frame.world.treasury.coins
const net = ledger.taxes + ledger.trade - ledger.upkeep - ledger.admin
@@ -30,9 +30,9 @@ export const numbersOf = (frame: Frame) => {
// What the homes would pay at each step of each tier's rate, once settled there (see `taxOutlook`).
const taxed: Array<TaxedHome> = []
for (const { data } of houses) {
- if (data.site.present || data.rising.present || data.burning.present || data.closed.present) continue
- const tile = data.tile.get()
- taxed.push({ ...data.house.get(), desirability: appealAt(cells, tile.x, tile.y), paying: true })
+ if (data.site !== undefined || data.rising !== undefined || data.burning !== undefined || data.closed !== undefined) continue
+ const tile = data.tile
+ taxed.push({ ...data.house, desirability: appealAt(cells, tile.x, tile.y), paying: true })
}
const f = frame.world.fate
const pantry = frame.world.pantry
@@ -77,7 +77,7 @@ export const statsOf = (frame: Frame, numbers: Numbers, { alerts, shortStaffed,
net,
homes: census.homes,
needs: { food: census.food, bread: census.bread, cloth: census.cloth, faith: census.faith, furniture: census.furniture },
- townhouses: houses.filter(({ data }) => data.house.get().tier === 3).length,
+ townhouses: houses.filter(({ data }) => data.house.tier === 3).length,
policy: rates,
stock,
prices: frame.world.market.prices,
@@ -140,7 +140,7 @@ export const statsOf = (frame: Frame, numbers: Numbers, { alerts, shortStaffed,
goals: goalsOf(
charter,
{ settlers: census.settlers, citizens: census.citizens, burghers: census.burghers, coins, net: steadyNet(frame.world.history.samples, net), approval: mood.approval,
- hall: hallRow ? hallRow.data.upgraded.value()?.level ?? 0 : 0 },
+ hall: hallRow ? hallRow.data.upgraded?.level ?? 0 : 0 },
undefined,
f.rank
),
diff --git a/src/view/tooltip.ts b/src/view/tooltip.ts
index 520775e..807f611 100644
--- a/src/view/tooltip.ts
+++ b/src/view/tooltip.ts
@@ -30,25 +30,25 @@ export const tooltipOf = (frame: Frame, ui: Interaction, preview: Preview, dropp
if (ui.tool === "upgrade") {
} else if (hoveredBuilding) {
const { kind, status, problem } = describeBuilding(frame, hoveredBuilding)
- const level = hoveredBuilding.data.upgraded.value()?.level ?? 0, works = hoveredBuilding.data.works.value()
+ const level = hoveredBuilding.data.upgraded?.level ?? 0, works = hoveredBuilding.data.works
const title = (upgradeAt(kind, level)?.title ?? kind.title).toLowerCase()
preview.tooltip = ui.tool === "bulldoze"
- ? `${title} · ${hoveredBuilding.data.hall.present ? "the town hall stays" : salvageFor(builtCost(kind, level), hoveredBuilding.data.site.value(), works && { kind, ...works })}`
+ ? `${title} · ${hoveredBuilding.data.hall !== undefined ? "the town hall stays" : salvageFor(builtCost(kind, level), hoveredBuilding.data.site, works && { kind, ...works })}`
: `${title} · ${problem ?? status}${works ? ` · becoming ${anA(upgradeAt(kind, works.level)!.title.toLowerCase())}, ${Math.round(worksShare(works)! * 100)}% built` : ""}`
} else if (hoveredHouse) {
- const h = hoveredHouse.data.house.get()
- const t = hoveredHouse.data.tile.get()
+ const h = hoveredHouse.data.house
+ const t = hoveredHouse.data.tile
preview.tooltip = ui.tool === "bulldoze"
- ? `${tierHome[h.tier]} · ${salvageFor(home.cost, hoveredHouse.data.site.value())}`
- : hoveredHouse.data.closed.present
+ ? `${tierHome[h.tier]} · ${salvageFor(home.cost, hoveredHouse.data.site)}`
+ : hoveredHouse.data.closed !== undefined
? `${tierHome[h.tier]} · closed`
- : `${tierHome[h.tier]} · ${h.residents} resident${h.residents === 1 ? "" : "s"} · desirability ${appealAt(cells, t.x, t.y)}${hoveredHouse.data.burning.present ? " · on fire!" : hoveredHouse.data.sick.present ? " · sick" : ""}`
+ : `${tierHome[h.tier]} · ${h.residents} resident${h.residents === 1 ? "" : "s"} · desirability ${appealAt(cells, t.x, t.y)}${hoveredHouse.data.burning !== undefined ? " · on fire!" : hoveredHouse.data.sick !== undefined ? " · sick" : ""}`
} else if (hoveredRuin) {
- preview.tooltip = `ruin · ${hoveredRuin.data.ruin.get().cause} · bulldoze to clear`
+ preview.tooltip = `ruin · ${hoveredRuin.data.ruin.cause} · bulldoze to clear`
} else if (hovered !== null && ui.tool === "select" && parkRows.some((row) => row.entity.id === hovered)) {
const row = parkRows.find((r) => r.entity.id === hovered)!
- const p = frame.parkOf(row.data.tile.get())
- const here = row.data.park.get()
+ const p = frame.parkOf(row.data.tile)
+ const here = row.data.park
preview.tooltip = `park · ${here.prop !== "none" ? props[here.prop].title.toLowerCase() : grounds[here.ground].title.toLowerCase()}${p ? ` · ${p.cells.length} cells · ${parkText(p)}` : ""}`
} else if (ui.tool === "place" && ui.placing) {
const kind = kinds[ui.placing]
diff --git a/src/view/upgrades.ts b/src/view/upgrades.ts
index da8f825..54b78e4 100644
--- a/src/view/upgrades.ts
+++ b/src/view/upgrades.ts
@@ -30,33 +30,33 @@ export const upgradesWanted = (frame: Frame, wanted: Wanted): ReadonlyMap<number
const tick = frame.world.time.step
if (Math.floor(tick / 60) === wanted.at) return wanted.why
const why = new Map<number, string>()
- const standingRows = buildings.filter((r) => !r.data.site.present && !r.data.rising.present && !r.data.works.value())
- const homes = houses.filter((r) => !r.data.site.present && !r.data.rising.present && !r.data.closed.present)
+ const standingRows = buildings.filter((r) => r.data.site === undefined && r.data.rising === undefined && !r.data.works)
+ const homes = houses.filter((r) => r.data.site === undefined && r.data.rising === undefined && r.data.closed === undefined)
const full = (r: BuildingRow) => {
- const inv = r.data.inventory.value()
+ const inv = r.data.inventory
return !!inv && goodIds.some((g) => inv.accepts.includes(g) && inv.stock[g] >= inv.cap * 0.9)
}
const near = (r: BuildingRow, tile: TileLike, range: number) => {
- const t = r.data.tile.get()
+ const t = r.data.tile
return Math.abs(tile.x - (t.x + t.size / 2)) + Math.abs(tile.y - (t.y + t.size / 2)) <= range
}
- const fishy = (r: HouseRow, need: "bread" | "faith") => r.data.house.get().tier >= 2 && !met(r.data.house.get(), need)
+ const fishy = (r: HouseRow, need: "bread" | "faith") => r.data.house.tier >= 2 && !met(r.data.house, need)
const nextHall = ranks[Math.min(frame.world.fate.rank + 1, ranks.length - 1)]!.hall
- const millsWait = standingRows.some((r) => r.data.building.get().kind === "mill" && r.data.status.get() === "starved")
+ const millsWait = standingRows.some((r) => r.data.building.kind === "mill" && r.data.status === "starved")
const breadShort = frame.world.stock.bread < 5 && homes.some((r) => fishy(r, "bread"))
for (const r of standingRows) {
- const kind = kinds[r.data.building.get().kind], level = r.data.upgraded.value()?.level ?? 0, status = r.data.status.get()
+ const kind = kinds[r.data.building.kind], level = r.data.upgraded?.level ?? 0, status = r.data.status
if (!nextUpgrade(kind, level)) continue
- const reach = r.data.service.value()?.range ?? 0
+ const reach = r.data.service?.range ?? 0
const reason =
kind.id === "townhall" ? (nextHall > level ? "the next rank asks for it" : full(r) ? "its shelves are full" : null)
: kind.id === "warehouse" ? (full(r) ? "its shelves are full" : null)
- : kind.id === "quarry" ? (status === "starved" && growingNear(grid, r.data.tile.get(), kind, frame.rockAt) ? "it has worked its rock down" : null)
+ : kind.id === "quarry" ? (status === "starved" && growingNear(grid, r.data.tile, kind, frame.rockAt) ? "it has worked its rock down" : null)
: kind.id === "farm" ? (millsWait ? "the mills wait on wheat" : null)
: kind.id === "bakery" ? (status === "working" && breadShort ? "homes go without bread while it works flat out" : null)
: kind.id === "market" ? (frame.unreachedHomes() > 0 ? "homes lie beyond every food walker" : null)
- : kind.id === "chapel" ? (homes.some((h) => fishy(h, "faith") && !near(r, h.data.tile.get(), reach)) ? "homes lie beyond its priest" : null)
- : kind.id === "firewatch" ? (homes.some((h) => (h.data.risk.value()?.fire ?? 0) >= risk.warn && near(r, h.data.tile.get(), reach + 6)) ? "homes on its streets are at high fire risk" : null)
+ : kind.id === "chapel" ? (homes.some((h) => fishy(h, "faith") && !near(r, h.data.tile, reach)) ? "homes lie beyond its priest" : null)
+ : kind.id === "firewatch" ? (homes.some((h) => (h.data.risk?.fire ?? 0) >= risk.warn && near(r, h.data.tile, reach + 6)) ? "homes on its streets are at high fire risk" : null)
: null
if (reason) why.set(r.entity.id, reason)
}
@@ -75,10 +75,10 @@ export const upgradesOf = (frame: Frame, needed: ReadonlyMap<number, string>) =>
for (const id of kindOrder) if (kinds[id].upgrade) upgradeRows.set(`${id}:0`, { kind: id, level: 0, ready: 0, underway: 0, first: null })
for (const row of buildings) {
const { data } = row
- if (data.site.present || data.rising.present) continue
- const kind = kinds[data.building.get().kind]
- const level = data.upgraded.value()?.level ?? 0
- const works = data.works.value()
+ if (data.site !== undefined || data.rising !== undefined) continue
+ const kind = kinds[data.building.kind]
+ const level = data.upgraded?.level ?? 0
+ const works = data.works
const from = works ? works.level - 1 : level
if (!nextUpgrade(kind, from)) continue
const k = `${kind.id}:${from}`
@@ -105,8 +105,8 @@ export const upgradesOf = (frame: Frame, needed: ReadonlyMap<number, string>) =>
const arrowed = new Set<KindId>()
const due = new Map([...needed].filter(([id]) => {
const row = buildings.find((b) => b.entity.id === id)
- const kind = row && kinds[row.data.building.get().kind]
- const up = row && kind && nextUpgrade(kind, row.data.upgraded.value()?.level ?? 0)
+ const kind = row && kinds[row.data.building.kind]
+ const up = row && kind && nextUpgrade(kind, row.data.upgraded?.level ?? 0)
if (!up || !kind || arrowed.has(kind.id) || upgradeBlock(up, rank, { ranks }) !== null || coinsNow < up.cost.coins) return false
arrowed.add(kind.id)
return true
@@ -114,9 +114,9 @@ export const upgradesOf = (frame: Frame, needed: ReadonlyMap<number, string>) =>
const [firstId, firstWhy] = [...due][0] ?? []
const dueFirst = firstId === undefined ? undefined : buildings.find((b) => b.entity.id === firstId)
if (dueFirst && !upgrades.some((u) => u.underway > 0)) {
- const kind = kinds[dueFirst.data.building.get().kind], level = dueFirst.data.upgraded.value()?.level ?? 0
+ const kind = kinds[dueFirst.data.building.kind], level = dueFirst.data.upgraded?.level ?? 0
const from = (upgradeAt(kind, level)?.title ?? kind.title).toLowerCase(), to = nextUpgrade(kind, level)!.title.toLowerCase()
- hint = { tone: "hint", text: `${firstWhy}: the ${from} can become ${anA(to)}. {Tap|Click} it, under its gold arrow, to begin`, at: dueFirst.data.tile.get(), size: dueFirst.data.tile.get().size, id: dueFirst.entity.id }
+ hint = { tone: "hint", text: `${firstWhy}: the ${from} can become ${anA(to)}. {Tap|Click} it, under its gold arrow, to begin`, at: dueFirst.data.tile, size: dueFirst.data.tile.size, id: dueFirst.entity.id }
}
return { upgrades: upgrades.map(({ first: _first, ...u }) => u), due, hint }
}