Simple economy — implementation prompts
This directory decomposes the "simple economy" replacement into one implementable unit per file. Each file is written as a self-contained prompt: a future session should be able to pick up one file and implement it without re-reading the whole codebase.
The existing economy is not deleted. It is frozen as the hard economy and kept selectable. The simple economy is the default from now on.
1. Shared project context (read this first)
Battle for 'Tismo is an HTML5 port of a turn-of-the-millennium strategy game. Pure JavaScript, no build step, no runtime dependencies.
- Server-authoritative.
shared/game_state.js(GameState) is the model;server/game_server.jsvalidates orders; the browser renders snapshots and sends orders back. The client never runsGameStateagainst a live game. - GameState is mixins.
shared/game_state.jscomposes the modules inshared/game_state/onto the prototype (Object.assignof each*Methodsexport). All state lives on the one instance. - Shared logic runs in Node and the browser.
shared/must stay framework-free (no Node built-ins, no DOM).server/websocket.jsis the only place Node built-ins are expected. - Data lives in
shared/data/(barrel:shared/data.js); import from the barrel, edit the file undershared/data/. - No new libraries. Everything is hand-written; only the vendored jQuery
under
client/vendor/is third-party. Indent.jswith 2 spaces. - Tests live in
tests/<topic>_test.jsextendingTestCase(base intests/framework/). During development run one suite:node tests/run_tests.js --file <name>.js. Never run the full suite by hand; the commit hook runs it. - Snapshot cost matters. Large collections are delta-shipped via
DELTA_COLLECTIONSinserver/game_server.js, each paired with theversionskey that reports it. A new snapshot collection needs an entry and a version, or it ships on every 10 Hz broadcast. - UI changes need approval. Per
AGENTS.md, any change that alters what the player sees must first be shown as a minimal standalone HTML example opened in the user's Firefox, and only committed once the user has seen and approved it. See09-ui.md.
Commands
- Install once:
npm install. - One suite:
node tests/run_tests.js --file <name>.js. - Server:
node server/server.js --port 27015 --bind 127.0.0.1.
2. The simple economy at a glance
| Area | Hard economy (today) | Simple economy (target) |
|---|---|---|
| Resources | per-region/tile stores, transport, trade graph | one global pool per player, available everywhere |
| Production buildings | private agents with cash/debt/upgrades | public, output to the player's pool |
| Building | gathers steel/high-tech over days, then builds | starts immediately, speed driven by regional energy |
| Construction capacity | GDP → ECONOMY.productionCapacity |
energy available in the region, with modifiers |
| Warmup | settles the world until prices are steady | none |
| Currency | one per nation, floating FX, central banks | euro (€) only, no conversion |
| Money use | construction, training, internal bills | market purchases only |
| Taxes | trade taxes (sales/export/import) | 1 inhabitant = 100 €/day × (approval × 2) × modifiers |
| Market | read-only reference prices, drifting | global buy/sell market in the Resources tab |
| Procurement | bidding across reachable stores + global market | draw from the player's pool, no bidding |
| Migration | income-driven people move between regions | no economic migration |
Open questions are called out in each module file; settle them before or while implementing that module.
3. Suggested order and dependencies
Implement in this order. Later modules assume the earlier switch exists.
01-decoupling-hard-economy.md— theeconomyModelswitch everything hangs off. Do this first.02-resource-pool-and-production.md— the pool and public producers.03-construction.md— immediate build, energy-driven speed, starting plants.04-warmup.md— skip the settle in simple mode.05-money-and-taxes.md— euro-only treasury and per-inhabitant income.06-global-market.md— the global market and its order.07-procurement.md— pool draws instead of bidding.08-migrations.md— turn off economic migration.09-ui.md— the visible changes (approval gate).10-snapshot-and-orders.md— wire protocol and server validation.11-tests.md— test plan spanning the above.
10 is naturally interleaved with 02, 05, 06 and 07; treat it as the
checklist for the wire shape of whatever those modules add.
4. Cross-cutting rules for every module
- Keep the hard economy working when
economyModel === "hard". Do not delete hard code paths; gate them. - Default
economyModelis"simple"everywhere it is not explicitly set. - Do not add libraries; do not touch
client/vendor/. - Every new snapshot field must be cheap and versioned.
- Add or extend the matching
tests/<topic>_test.js; run only that file. - No comments unless the surrounding file already uses them heavily; match the house style (the code is heavily commented on purpose — follow suit for new modules).
- Commit only when asked; the hook runs the full suite.
5. Module index
| File | Module |
|---|---|
01-decoupling-hard-economy.md |
The economy-model switch; freeze current model as hard. |
02-resource-pool-and-production.md |
Global pool per player; public production buildings. |
03-construction.md |
Immediate building; speed from regional energy; starting plants. |
04-warmup.md |
No warmup in the simple economy. |
05-money-and-taxes.md |
Euro only; per-inhabitant approval tax; drop taxes tab. |
06-global-market.md |
Global market, lots, price formula, starting stock. |
07-procurement.md |
Regions draw from the player's pool; no bidding. |
08-migrations.md |
No economic migration. |
09-ui.md |
All client changes (approval gate). |
10-snapshot-and-orders.md |
Snapshot fields, deltas, server order handling. |
11-tests.md |
Test plan and fixtures. |