feat: v0.12.0 — contracts → packages: load/fly/abandon gameplay (ATR 72-600 capacity 6, manual flight to any airport, time-scaled abandon penalty 15–60%), one-time DB migration preserving wallet/clock; new endpoints /api/packages/:id/load|abandon + /api/planes/:planeId/fly

This commit is contained in:
2026-09-18 11:02:56 +00:00
parent 0208673da7
commit ab2e9fa54a
49 changed files with 2424 additions and 1409 deletions
+14
View File
@@ -1,5 +1,19 @@
# Changelog
## v0.12.0 — 2026-09-18 09:17
- **Gameplay pivot (user-driven): contracts → packages** — the job model is rebuilt end-to-end around cargo *packages* and manual flight, replacing the old accept→dispatch flow in one coherent increment. A **package** is a cargo unit origin→dest with a reward € and a game-time deadline; planes carry up to `capacity` packages (ATR 72-600 = **6 slots**, new `capacity` field on catalog entries exposed via `/api/state`). The loop: **Load** an open package onto a grounded plane at its origin → **Fly** the plane to any known airport (the destination of a loaded package, or pure repositioning) → on arrival every in-deadline package bound for that airport is **delivered** (cash += reward + rep per package); packages destined elsewhere stay loaded for a later leg
- **New player actions** (`lib/game/actions.ts`, all under the sim lock via `engine.runAction()` — tick first, then validate+mutate): `loadPackage` (open → loaded; plane must be GROUNDED at the origin with a free slot — expired packages still occupy theirs), `flyPlane` (grounded plane → any dataset ICAO; 400 unknown airport, 409 flying / insufficient fuel where burnPerKm × great-circle km > fuel), `abandonPackage` (loaded or already-expired package while its plane is GROUNDED — 409 if in flight). Removed: `acceptContract`, `dispatchPlane`
- **Abandon penalty** (`lib/game/penalty.ts`, pure + shared by server and client preview): fraction of the payout scaling with time pressure — exactly **15%** at creation, linear to **60%** at the deadline; an already-expired package abandons for free; cash floors at €0. `abandonPenaltyPct` / `elapsedFractionFor` / `abandonPenalty(pkg, clockMs)`
- **Sim engine** (`lib/sim/engine.ts`): `expirePackages` flips both OPEN and LOADED packages past their deadline to 'expired' (open ones leave the market so spawn tops it back up; loaded ones keep their slot); `deliverPackages` (was finalizeArrivals) grounds a flying plane at its `dest_icao`, then for every bound package destined there — in-deadline 'loaded' → delivered + cash/rep, 'expired' → unbind only (no reward); spawn rules (`spawnOpenPackages` / `spawnCoveragePackages`) adapted to packages via the renamed shared builder
- **Schema** (`lib/db/schema.ts` + DDL in `lib/db/client.ts`): new `packages` table (status open|loaded|delivered|expired|abandoned, planeId nullable); planes gain nullable `dest_icao` and lose `contract_id`; seed builder renamed `generateContract` → `generatePackage` (same reward/deadline formulas), `MARKET_TARGET_OPEN_PACKAGES = 10`
- **One-time migration for live DBs** (`lib/db/client.ts`, detected by the presence of the old `contracts` table so it runs exactly once per file): PRESERVES account + sim_state rows and every plane row; resets all planes to GROUNDED at their locationIcao with departure_sim_time/dest_icao cleared (an in-flight plane from the old state simply lands back where it took off); wipes old contract data (`DROP TABLE contracts`), drops the orphaned `contract_id` column, creates the empty packages table — the engine's spawn rules reseed the market on the next tick. **Wallet, fleet and sim clock survive; old contracts do not.**
- **API** (OpenAPI updated in code): NEW `POST /api/packages/:id/load {planeId}`, `POST /api/planes/:planeId/fly {destIcao}`, `POST /api/packages/:id/abandon` — all tick-first, full state snapshot on 200, `{error}` on 4xx (404 unknown id; 409 wrong status / not at origin / no free slot / in flight / insufficient fuel; 400 bad body or unknown ICAO). REMOVED `POST /api/contracts/:id/accept` and `POST /api/planes/:planeId/dispatch`. Test hooks renamed: `/api/test/create-package` (origin/dest/deadlineOffsetMs) and `/api/test/expire-package` ({packageId?}), same FLIGHT_TEST_HOOKS=1 gate
- **Snapshot** (`lib/game/state.ts`): `contracts` → `packages` field; planes gain `destIcao` + `destName` (null when grounded); catalog entries carry `capacity`. `/api/state` shape otherwise unchanged
- **UI — right pane** (`components/RightPane.tsx`): "Packages" section lists open packages with a Load button that acts directly on the single eligible plane or shows a small picker when several qualify (pure rule extracted as `loadEligiblePlanes` / `slotsUsedFor`, unit-tested); new "On board" section per plane — loaded/expired packages listed with a **fly-to-destination** button (the destination's name; enabled only while grounded) and an **Abandon** button showing the exact penalty preview computed client-side from the same formula; flying planes show their current leg "originName → destName". Left pane fleet rows gain a loadout "n/6 pkgs"
- **UI — map** (`components/Map.tsx` + `lib/mapData.ts`): route lines are now each FLYING plane's current leg (origin→dest_icao, one amber line per flying plane keyed by planeId) — the old pending/inflight contract-based layers are gone; grounded planes draw nothing. Plane popup route text comes from the plane's own dest fields
- Tests: unit 192 → **228** green — new `lib/game/penalty.test.ts` (15% start / 60% deadline / monotonic / clamped / expired→0 / cent rounding), rewritten `actions.test.ts` (load validation matrix incl. slot capacity + expired-slot occupancy; fly unknown-ICAO/flying/no-fuel; abandon penalty at exact clock points, cash floor, in-flight 409), `engine.test.ts` (expire open+loaded, terminal never flips; arrival delivery mixed loaded/expired/other-dest with exact cash+rep deltas and idempotency; spawn top-up + coverage on packages), `seed.test.ts` / `client.test.ts` (fresh seed of packages; pre-v0.12 migration wipes contracts + grounds planes + preserves account/clock, one-shot on reopen), route tests for load/fly/abandon, openapi/mapData/right-pane updated to the package model. e2e 27 → **29** — rewritten `actions.spec.ts` (full loop via UI: hook package at EDDF → Load click → fly-to-destination click → exact reward+rep on arrival; abandon deducts exactly the formula penalty; expired packages deliver/abandon with no reward and no penalty; load/fly validation 404/409/400 incl. an unfuelable return leg), `right-pane.spec.ts` (open package rows + Load enabled/disabled by origin, on-board fly+abandon with penalty preview, flying-leg display, market previews + exact refuel cost), `map-interactions.spec.ts` (no line while grounded → leg line appears keyed by planeId after fly, marker moves across polls, popup shows the leg); sim/state/api/panes updated to packages (api now asserts ten endpoints; panes asserts the "n/6 pkgs" loadout)
- Verified: `tsc --noEmit` clean; unit suite 228 green; e2e 29 green against the rebuilt compose instance with the live DB migrated in place (wallet € + sim clock preserved, old contracts wiped); scale restored to 1×/unpaused after every spec
## v0.11.0 — 2026-09-18 07:25
- **Map interactions per PLAN.md "Middle — Map"** (`components/Map.tsx` now receives the shell's polled `/api/state` snapshot from `app/page.tsx`, same single poll loop as the panes): (a) airport popup expanded — name + ICAO kept, plus **approximate local time** and a **generated weather** line; (b) **animated plane markers** — every plane rendered on the map at its polled lat/lon (server computes flying positions analytically each tick), grounded planes as small sky-blue circles at their airport, flying planes bigger + green so they stand out; movement between 1 s polls is acceptable for this increment (no client-side interpolation); (c) **plane status popup** on click — catalog model label ("ATR 72-600"), status, fuel "x / y L", and while flying the contract route "originName → destName"; (d) **active contract routes highlighted** — one origin→dest line per accepted contract: dashed muted slate when pending (accepted, not yet dispatched), solid bright amber once in-flight
- **Pure deterministic weather generator** `lib/weather.ts`: `weatherFor(icao: string, dayKey?: number)` → `{condition: 'Clear'|'Cloudy'|'Rain'|'Fog', windDirDeg, windKt, visibilityM}` — seeded by FNV-1a hash of the ICAO through mulberry32 (same PRNG as game seeding), so the same airport always shows the same weather across polls/sessions; optional `dayKey` varies it per sim-day. Display-only per PLAN.md — no gameplay effects