The simple economy is now the default and the old simulation is frozen as the hard model, selectable per game. A nation keeps one resource pool available in every region, fed by public production works rather than private per-region stores, and construction and training begin at once, paced by the region's spare power instead of gathering materials over days. Money is euro only: a per-inhabitant daily tax funds a treasury spent in a global market, where buy and sell lots trade against the world stock and move its price. The hard economy keeps its per-nation currencies, central banks and exchange rates. Simple games skip the price-settling warmup and economic migration; the snapshot carries the economy model, the market and the pool figures the client draws. Added the matching test suites and the design briefs under docs/simple_economy.
125 lines
6.2 KiB
Markdown
125 lines
6.2 KiB
Markdown
# 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.js` validates orders; the browser renders snapshots and
|
||
sends orders back. The client never runs `GameState` against a live game.
|
||
- **GameState is mixins.** `shared/game_state.js` composes the modules in
|
||
`shared/game_state/` onto the prototype (`Object.assign` of each
|
||
`*Methods` export). 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.js` is the only
|
||
place Node built-ins are expected.
|
||
- **Data** lives in `shared/data/` (barrel: `shared/data.js`); import from the
|
||
barrel, edit the file under `shared/data/`.
|
||
- **No new libraries.** Everything is hand-written; only the vendored jQuery
|
||
under `client/vendor/` is third-party. Indent `.js` with 2 spaces.
|
||
- **Tests** live in `tests/<topic>_test.js` extending `TestCase` (base in
|
||
`tests/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_COLLECTIONS` in `server/game_server.js`, each paired with the
|
||
`versions` key 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.
|
||
See `09-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.
|
||
|
||
1. `01-decoupling-hard-economy.md` — the `economyModel` switch everything hangs
|
||
off. **Do this first.**
|
||
2. `02-resource-pool-and-production.md` — the pool and public producers.
|
||
3. `03-construction.md` — immediate build, energy-driven speed, starting plants.
|
||
4. `04-warmup.md` — skip the settle in simple mode.
|
||
5. `05-money-and-taxes.md` — euro-only treasury and per-inhabitant income.
|
||
6. `06-global-market.md` — the global market and its order.
|
||
7. `07-procurement.md` — pool draws instead of bidding.
|
||
8. `08-migrations.md` — turn off economic migration.
|
||
9. `09-ui.md` — the visible changes (approval gate).
|
||
10. `10-snapshot-and-orders.md` — wire protocol and server validation.
|
||
11. `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 `economyModel` is `"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. |
|