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.
3.8 KiB
3.8 KiB
10 — Snapshot and orders (wire shape)
Depends on: 01-; interleave with 02-, 05-, 06-, 07-.
Goal
Define the snapshot fields and server order handling for the simple economy so the client can render it and the server can validate it. Keep the snapshot path cheap, and keep the delta mechanism honest.
Current behaviour
shared/game_state/serialization.jsbuilds the state snapshot and the per-viewer stats. The market block is around line 726 (price: getResourcePrice(id)); taxes/approval around lines 180–250 and 460–490.server/game_server.jsbuilds deltas usingDELTA_COLLECTIONS(top of file), pairing each large collection with theversionskey that reports it. A mismatch re-sends a whole collection on every broadcast.- Orders are dispatched in
GameServer.handleOrder; economy orders today areset_interest_rateandset_tax_rate. - The client keeps previous collections until the version moves
(
client/js/game_screen.js).
Target behaviour
Snapshot
- Ship
economyModel(top level) so the client picks the UI. - Ship the viewer's resource pool (
{ steel, food, luxury, hightech, ... }) and, if public, every civ's pool for rankings. Decide visibility: only the viewer's own pool is economically necessary; others may be omitted for fairness/perf. - Ship the global market: per resource
stock(availability) andprice, the player's pool amount is separate. This is read every broadcast by open nation modals, so make it a small, versioned collection. - Ship the single daily tax income / treasury rather than the three trade
taxes.
taxTakebecomes a singleincomefigure in simple mode. - Ensure
migrations/migrationGraphare present and empty (or policy-only) in simple mode (see08-). - For any new large collection, add a
DELTA_COLLECTIONSentry and bump a version when it changes. Recommended:["resourcePools", "resourcePools"]and["market", "market"], each with a matchingversionskey. If the pool is small (four numbers per civ) prefer sending it inline and skip the delta machinery.
Orders
- Add
market_trade→requestMarketTrade(civ, resource, side, qty)(06-). Validate resource id, side, lot membership, treasury/pool, and mutate atomically on the server. Never trustfree. - Reject
set_tax_rateandset_interest_ratefor simple games (return false). - Keep every hard-mode order working when
economyModel === "hard". - If construction/training no longer cost money (
05-), the existing order handlers need no economy-specific validation change beyond delegating to the simple state.
Files
shared/game_state/serialization.jsserver/game_server.js—DELTA_COLLECTIONS,handleOrder, new handlerserver/server.js— setup field (already via01-)client/js/game_screen.js/client/js/net.js— consume the new fieldstests/simple_snapshot_test.js— new
Acceptance criteria
- A simple snapshot includes
economyModel, the market (stock+price per resource) and the viewer's pool; the client can render the market from it with no extra fields. - A changed market/pool is shipped at most once until it changes again (delta works, version key matches).
market_tradeis validated server-side; a bad lot/resource/side is refused.- Hard snapshots are unchanged.
Notes / decisions
- Pool visibility. Sending every civ's pool is useful for rankings but not required; start with the viewer's own and add others only if the UI needs it.
- Market in the snapshot every broadcast. The price derives from the stock, so ship the stock (and the price for convenience). Version both together.
- Fog. The pool and market are national, not tile data, so no visibility filtering beyond the viewer's own nation.