Phase 4: close loot/refund leaks, landing-site garrisons, speed-scaled shipping, update/offsite tooling, broad e2e
Built: - Economy: raid loot capped to the room the raiders have at home (rest stays with the victim, "lootLeft" in the report); trade escrow reserves its room so refunds always fit; trade accept refuses with no_room_for_goods when the goods would not fit. Loot destroyed per 30-day run 31-61k -> ~1k, refunds clipped ~27k -> 0 (docs/BALANCE.md, 3 seeds). - End game: members of the holding alliance garrison landing sites (migration 005_site_garrison.sql), garrison counts in site defence, 72 h capture shield, withdraw route, POP view lists garrisoned units. Shipping capacity scales with world speed (3x world: winner 76-98 -> ~30-36 days after sites open). Bot runs show real contests (84-194 attacks on held sites at 1x). - Ops: deploy/update.sh (backup, stop, ff-merge, npm ci --ignore-scripts, health check, rollback), deploy/upstream-offsite (rsync only), admin end-world snapshots results, EPIPE fix, docs/workflows/ filled in. - e2e 62 -> 163 checks: units, raids/reports, alliance+messages, trade, end game, nb, PWA, reconnect, slow polling fallback (opt-in). Two app bugs found: message push ignored, "New" button stayed English. Tested: npm test 274/274, openapi check, npm run e2e 163/163 (137 s), bot runs 50x30d seeds 1-3 and 140-day/60-day speed-3 end-game runs INVARIANTS OK, adversarial review pass (findings fixed or documented). NOT tested: update.sh on a real box (systemd, real npm, runuser; stubs only, shellcheck not installed), garrison card/loot text on a phone, Node 22.13, humans. Known leaks left open and documented (BALANCE S6): loot/shipments can still overflow when stock arrives in flight, bounced backbone shipments lose overflow (reported to the sender). Garrison numbers (heldDefenceMult 2, shield 72 h) are first guesses from 2 seeds. Not claimed: balanced. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q2MJaQ5LXAHzGnTDgceT14
This commit is contained in:
parent
9104480463
commit
3c23c51902
92 changed files with 4887 additions and 300 deletions
|
|
@ -152,8 +152,8 @@ target's owner `incoming` (town + ETA) and no plain `town` hint, so the type and
|
|||
would have to be excluded from footprint rankings, the last-POP / capital / footprint-gate counts, `homeTownFor`, `/me`, spawn spacing and
|
||||
the Rack hall cap (shipped resources would be thrown away at 250), and a leader change would have to re-own it. The holder is the
|
||||
alliance (`holder_alliance_id`, FK `ON DELETE SET NULL`, the disband hook also clears it), `holder_operator_id` only records who took it.
|
||||
Consequence, on purpose and to be revisited after the first world: **no units can stand at a site**, so there is no garrison and no
|
||||
reinforcement. A site is defended by the static value `incumbentDefence x 12 x (1 + 0.03 x level)` only, i.e. exactly the "incumbent
|
||||
Consequence, on purpose and to be revisited after the first world (**revisited in E6: garrisons exist now**; the rest of this paragraph is the
|
||||
original reasoning): **no units can stand at a site**, so there is no garrison and no reinforcement. A site is defended by the static value `incumbentDefence x 12 x (1 + 0.03 x level)` only, i.e. exactly the "incumbent
|
||||
with a backbone multiplier" of DESIGN.md; holders defend by growing the node (higher level = harder to take), attackers can scan the exact
|
||||
number. Hooks into the military code are small: `combat.arriveSite` hands `backbone` tiles to `military/landing.js`,
|
||||
`arrivals.arriveTransport` hands shipments (`extra.siteId`) to `endgame.deliverShipment`, `sendMovement` calls `endgame.checkLandingTarget`.
|
||||
|
|
@ -187,11 +187,45 @@ automatically as long as they carry one of those arguments.
|
|||
about 36 world days of building in total, level 100 alone 312 k each and 23 h). Pure guesses until a bot run (stage 7) says how much an
|
||||
alliance can ship; nothing here is balanced.
|
||||
|
||||
## E6 — Garrisons at landing sites, a light static defence for held sites, a capture shield (BALANCE.md section 5, E1 follow-up)
|
||||
Problem (bot runs, BALANCE.md section 5): after the opening scramble nobody could contest a held site. Its static defence was 12 x incumbent x (1 + 0.03 x level),
|
||||
200 to 440 k at node level 89+, and one attack is one movement from one POP, whose army tops out around 60 k attack; with no garrison there is nothing a wave can
|
||||
wear down, so "attacks cannot be added up". Adding a garrison ON TOP of that static value would only have made held sites harder, not contestable.
|
||||
Decided:
|
||||
- **Static defence of a HELD site drops to `ENDGAME.heldDefenceMult` = 2** x incumbent defence (x the per-level bonus); an unheld site keeps `defenceMult` 12 (the
|
||||
opening scramble is unchanged). The rule behind the number: static defence must stay below what one POP can send (about 60 k), otherwise the last wave of
|
||||
a fight could never win and a built-up site would be out of reach again. At day 100 a held site is ~7 k at level 0, ~28 k at level 100; at day 170 level 100 it is ~37 k.
|
||||
- **A garrison**: table `site_stationed(site_id, owner_town_id, unit, count)` (migration 005; `stationed` has a POP as host, a site is not a POP, E1). Members of the
|
||||
holding alliance, and only them, `reinforce` a site with the existing movement type (target = the site's x,y); the check is made when sending and again at arrival
|
||||
(a site that changed hands, or an alliance the sender left, turns the units back with a `movement_failed` report). Units are in exactly one place at a time; a table
|
||||
of its own makes the conservation ledger count them (`tools/bot/ledger.js`).
|
||||
- **Power**: garrison units draw their OWNER's POP (`state.unitDraw`, `power.drawingUnits`, `power.decommission`), because a site has no power budget; sending them
|
||||
changes no one's total draw, units on the road draw nothing (as everywhere), an owner POP without power takes its group offline (it does not defend, a won attack still
|
||||
wipes it) and decommission takes units out of the garrison last. Alternative rejected: free upkeep at the site (a bottomless defence) or an upkeep charged to the
|
||||
alliance (no such budget exists).
|
||||
- **Combat** is the POP law: `resolveBattle` with `staticDefence` AND defenders: D = static + the online groups' defence (their owner's research), no firewall, no
|
||||
base defence; a lost attack kills (A/D)^1.5 of each group's units, a won attack kills them all and the attacker's alliance holds the site (level, stockpile and a
|
||||
running build stay, as before). The static part loses nothing. No new combat rule, so waves resolve in arrival order, `(due_at, id)`, like every battle.
|
||||
Rejected: a "breach" counter on the static part that heals over time (one more number and one more stored timestamp for the same effect).
|
||||
- **Leaving**: `POST /backbone/:id/withdraw` (owner only, any time, works after the site changed hands) and automatic returns (a return movement each) when the owner
|
||||
leaves or is kicked (`allianceLeave`, `allianceKick`), the alliance disbands (`onAllianceDissolved`, before the holder is cleared) or the owner's POP is taken over
|
||||
(`combat.transferTown`, to the old owner's other POP). Rejected: "left in the site, withdrawable later" (the units of a non-member would defend a rival).
|
||||
- **Capture shield**: `ENDGAME.captureShieldHours` = 72 world hours (/ speed) after a site changes hands, no attack on it (refused when sent, bounced at arrival).
|
||||
A freshly taken held site has no garrison yet: with no shield bot runs flipped sites ~240 times in 27 to 35 days at 3x, with 24 h still ~140 to 175 times, with 72 h
|
||||
54 to 65 times and no slower a winner (BALANCE.md section 5; all of that is bots). Not a rule for unheld sites.
|
||||
- **The static rule expires**: `incumbentDefence` grows with world age, so the held static part of a level-100 site passes one POP's ceiling (~60 k) around world age 280
|
||||
(real day ~93 at 3x). From then on only a garrison that waves have already worn down can be finished by one army; `heldDefenceMult` has to come down or the
|
||||
growth stop at some age if a world is meant to run that long.
|
||||
- **Not decided here, and why**: a captured site keeps its node level (the existing rule, "take it over"; the task also named "down a level" as an option); if the first
|
||||
world shows the race ends by one late strike on a finished node, `captureLevelLoss` is the lever.
|
||||
- **Notifications**: `backbone_incoming` (holders, no type, no sender), `garrison_arrived`, `garrison_released`; push gets a `town` hint for the owner POP.
|
||||
Gaps: bots do not react to `backbone_incoming`, there is no sitter, `tools/admin.js inspect` does not list garrisons, a human alliance can still leave a site with zero garrison.
|
||||
|
||||
## T1 — Trade: escrow, one link per side, reach by exchange level
|
||||
- Offers are escrowed in `trade_offers` and hold one transport link of the poster's POP while open (`movements.activeLinks` counts open
|
||||
offers), so accepting never fails for lack of a link on the poster's side and cannot exceed the exchange level.
|
||||
- Each side of an offer must fit ONE transport (<= 1000, was 500 until B2); larger deals are several offers. The ratio band is count-based 1:2.
|
||||
- Escrow returned WITHOUT the Rack hall cap at first (conservation beats the cap); review round 1 (R1) reversed that: refunds are capped like `cancelBuild` (stock already above the cap stays, the clipped part is lost silently, BALANCE.md S2). Deliveries keep the cap rule (`cargoLost`).
|
||||
- Each side of an offer must fit ONE transport (`rules.transportCapacity(speed)`: 1000 x world speed, B7; was 500 until B2); larger deals are several offers. The ratio band is count-based 1:2.
|
||||
- Escrow returned WITHOUT the Rack hall cap at first (conservation beats the cap); review round 1 (R1) reversed that: refunds are capped like `cancelBuild` (stock already above the cap stays, the clipped part is lost silently, BALANCE.md S2; superseded by B6: escrow keeps its room in the hall, so the refund fits). Deliveries keep the cap rule (`cargoLost`).
|
||||
- Reach: `10 tiles x exchange level` of the taker's POP, and the offer's own `maxDistance`; the poster's level only matters for the number of
|
||||
offers they can hold open.
|
||||
- A POP changing hands voids its open offers (`combat.transferTown` calls `trade.onTownTransferred`); the escrow stays in the POP.
|
||||
|
|
@ -246,7 +280,7 @@ The end game is shipping-limited, not production-limited: 21.6 M units (7.2 M of
|
|||
won in each seed, 55 to 78 days after the sites opened (node build time alone is 36 days). Raising `ENDGAME.costGrowth` to 1.035 or
|
||||
the capacity to 2000 were measured and not taken (2000 leaves only the 36-day build floor as a constraint). Not solved: a 3x world takes about as
|
||||
long after the sites open as a 1x world, because shipping is per sitting, not per hour; `capacityPerLink x world speed` would fix it but the
|
||||
client reads the constant. See BALANCE.md section 5.
|
||||
client reads the constant. See BALANCE.md section 5. (Done in B7.)
|
||||
|
||||
## B3 — A bounced shipment reports its overflow
|
||||
`events/return.js` stayed silent for empty-carrier return legs AND for shipments that came home with cargo; cargo above the Rack hall cap is
|
||||
|
|
@ -264,3 +298,73 @@ different slope (default mix field level +2 % on day 30, +0.1 % on day 60; 2 a d
|
|||
were measured and dropped: the first does nothing for the first hour and shifts the mid game, the second multiplies the head start (up to ~11 days) for no first-hour gain.
|
||||
Not done, and probably the bigger lever for an engaged player: a higher starting stock (1000 of each moved the mid game by 0 days and gave a 60-minute first sitting 15.4 builds at 1 h
|
||||
instead of 12.1). Left for the owner to call.
|
||||
|
||||
## O1 — Admin `end-world` runs the real `worldEnd` handler (ops)
|
||||
The first CLI version only set `status = 'ended'`: no ranking snapshot, `/results` stayed unavailable, pending events and trade escrow were left
|
||||
behind. It now enqueues a `worldEnd` event (`reason: 'admin'`, due now) and processes it through the real `Scheduler` and the real handler, after
|
||||
processing that world's already-due events in order; every handler call is guarded by a status re-check inside the transaction, so a running
|
||||
server that handles the same event at the same moment cannot double-apply it. One implementation of "a world ends" instead of two. Cost: the CLI
|
||||
is a separate process, so the `world_ended` notification rows it writes are not pushed over a running server's sockets. Not repairable: a world
|
||||
the old command ended has no snapshot.
|
||||
|
||||
## O2 — `deploy/update.sh` rolls back one step with `git reset --hard`, and does not touch migrations
|
||||
The checkout is on `main` and the tree is required to be clean, so `git reset --hard <old rev>` loses nothing and keeps the branch (a
|
||||
`git checkout <rev>` would leave a detached HEAD that the next update refuses). The snapshot is taken (and verified) before any change; no
|
||||
snapshot, no update. Migrations are forward-only (`DEPLOY.md` section 8): the script announces new ones before it starts and names the
|
||||
snapshot to restore after a rollback, instead of pretending it can undo them. Origins with credentials in the URL are refused (the
|
||||
checkout must use plain HTTPS; nothing secret in `.git/config`).
|
||||
|
||||
## B6 — Trade escrow keeps its room in the Rack hall; loot is limited to what home can bank (BALANCE.md S2 and S4)
|
||||
Two economy leaks the bot ledger priced (30 days, 50 players, seeds 1 to 3): 43 to 48 trade refunds a run clipped at the Rack hall cap, 26 to 28k lost
|
||||
silently (S2); 17 to 22 % of the raid loot destroyed on arrival because the raiders' Hardware/Capital stores were full (S4), plus 83 to 84 % of the one-time
|
||||
incumbent Hardware bonus (64 to 82k a run; BALANCE.md had blamed raid loot for this).
|
||||
- **S2, chosen: escrow keeps its room.** `rules.storageCapOf(town, res) = hall size - town.escrow[res]` (the escrow is the sum of the POP's open offers, loaded by
|
||||
`state.townFromRow`). While an offer is open that resource stops filling at hall size minus the escrow, so a refund always fits and the escrow is never extra
|
||||
storage: R1's exploit (refill to the cap while the escrow is out, then cancel for cap + escrow) cannot happen, and nothing is lost. The one invariant to keep:
|
||||
**every way out of `open` must settle the POP first**, because the cap changes there (`closeOffer` settles and credits BEFORE the status change; `tradeAccept`
|
||||
settles the poster; creation settles before the insert). The same cap is used by deliveries (`addCargo`) and `cancelBuild`. The only residual clip is a Rack hall
|
||||
shot down below stock + escrow; it sends `trade_refund_clipped` and the ledger books that notification as a sink (the SQL-statement tap is gone).
|
||||
Rejected: a "held" amount the owner claims later (new state, command, route, expiry and a bounded hiding place, for the same outcome), and limiting the escrow
|
||||
so it always fits (impossible: stock grows while the offer is open). Cost to the player: a POP with 700 Fiber escrowed has a Fiber store 700 smaller for up to 48 h;
|
||||
the trade screen says so.
|
||||
- **S4, chosen: take only what home can bank.** `combat.homeRoom` = hall room minus the stock projected to the moment the raiders are back (pure projection, no
|
||||
write); `rules.lootSplit(carry, avail, room)` skips a resource with no room and shares the carry among the others; the rest stays with the victim and the report
|
||||
has `lootLeft`. Not exact (other deliveries can still fill the store in between: 0.7k of 175k looted remains destroyed and reported via `cargoLost`). No home POP:
|
||||
nothing is taken (before, it was deducted from the victim and vanished).
|
||||
- **Incumbent bonus, chosen: delivered above the cap.** It can be earned once per site, so a full store must not eat it; `extra.bonus` on the return leg is credited
|
||||
uncapped (kept, it only stops growing: the same rule as a lowered Rack hall). Bounded by 2 500 Hardware per site per operator; a reward gate (deferring the take)
|
||||
was rejected because bots would re-attack for nothing.
|
||||
Not changed: transport deliveries onto a full store still lose the overflow (reported; 0 to 1 event per 30-day run now).
|
||||
|
||||
## B7 — Transport capacity scales with world speed (`rules.transportCapacity`)
|
||||
Follow-up of B2: shipping is per sitting (one trip per link), not per hour, so the end game did not shorten with world speed. `D.TRANSPORT.capacityPerLink` stays the number
|
||||
at speed 1 and `rules.transportCapacity(speed)` = `capacityPerLink x speed` is the ONLY reader of it: `transportPlan` (by `town.speed`), `tradeTermsCheck(terms, speed)`
|
||||
(each side of an offer fits one transport), the POP view's `transport.capacityPerLink` (which the send dialog and the site sheet show), `client trade.js`, the bots. A test
|
||||
(`test/transport-speed.test.js`) fails when a source file outside rules.js/data.js mentions the constant. Rejected: a flag in data.js to turn the scaling off (a bot run
|
||||
with `--set TRANSPORT.capacityPerLink=...` reproduces any old value at a given speed). Numbers: BALANCE.md section 5.
|
||||
|
||||
## E2E: how flights are made to land, and what the nb detector can and cannot see
|
||||
- **Moving flights up instead of waiting.** `rules.latencyMs` has a 10 minute floor in real time, so a speed-1 raid, a trade leg or a site shipment cannot finish inside a test. The e2e
|
||||
(`e2e/lib.js` `hurryMovement` / `hurryEvents`) writes the new due time into the movement row and its pending event and calls `scheduler.arm()`; the handlers run unchanged. Chosen over a fake
|
||||
clock (the page uses the real browser clock and the server's `serverTime` offset) and over a speed-4000 world for everything (the flight must be on screen first: checks assert the countdown
|
||||
before the move-up). Rejected: a test-only latency override in server code.
|
||||
- **Norwegian check = detector + snapshot.** A raw key is any visible text matching `<known namespace>.<name>`; an English leftover is visible text equal to the English text of a key whose nb text
|
||||
differs (placeholders become wildcards). Both tables are snapshotted before the test touches anything, and the detector is calibrated on every run (it must find >= 8 English strings on the English POP
|
||||
screen, and a planted key / a deleted nb string). It cannot see an nb string that was copy-pasted from English, so a separate check fails on any multi-word nb string identical to its English text.
|
||||
Live switching is checked for visible text only; stale aria-labels after a live switch are reported in the run log, not failed (NEXT.md gaps).
|
||||
- **`{type:'message'}` push now acts.** `messages.js` refetches the unread count (a poll that arrives while one is in flight asks once more) and the visible inbox / alliance feed / open thread. Before, the
|
||||
hint was received and dropped.
|
||||
|
||||
## R2 — Review round 2 fixes: update.sh order, offsite scp, room reservation, garrisons in the POP view
|
||||
- **update.sh stops the service before it touches the tree** (it used to merge and `npm ci` under a running process that lazily `require()`s modules). The optional `--test` runs
|
||||
on a `git archive` copy of the new rev in a temp dir, as the service user (`runuser`), with `npm ci --ignore-scripts`; never as root, never in `/opt/upstream`. The snapshot is
|
||||
taken after the stop (final state of the database), so a failed snapshot costs a short outage and then the service is started again. Rejected: running tests as root in the live
|
||||
tree (fetched code as root, and the mixed-code window); a second snapshot before the stop (two snapshots, still not the final state).
|
||||
- **Rollback across migration 005** (site_stationed) is documented as unclean once anybody has garrisoned a site: old code does not know the table. No downgrade script (migrations are one-way, B-series rule).
|
||||
- **scp removed from upstream-offsite**: scp cannot refuse to overwrite, and the docs promised never to. rsync with `--ignore-existing` is the only method; `OFFSITE_METHOD=scp` is rejected (exit 2).
|
||||
- **Room for loot** is reserved only against return legs already on the road to the home POP (`combat.homeRoom`), not against production or deliveries that land meanwhile; bounced
|
||||
shipments are reported with exact `cargoLost`, not prevented. Rejected for now: reserving room through the escrow mechanism for every shipment (caps production for as long as it is
|
||||
out; a real economy change that wants a bot comparison first). BALANCE.md S6.
|
||||
- **Trade accept refuses with `no_room_for_goods`** when the projected hall of the acceptor cannot take the goods; it does not clip or split the trade. The projection ignores stock that appears on the way.
|
||||
- **`units.garrisoned`** in the POP view: units standing in landing sites draw the owner POP's power, so the owner's POP view lists them (site id and coordinates, units).
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue