Built: - Client: trade screen, world/end-game screen (landing sites, shipping, node build, final ranking), report sharing + alliance reports tab, alert describers for all notification types, error-code strings (en+nb) for every server CODE. - tools/bot.js (+ tools/bot/): 50 headless bots against the real server in-process with a fake clock; resource/unit conservation ledger, exit 1 on broken invariants. docs/BALANCE.md has method and every run behind a number. - Balance changes (evidence in docs/BALANCE.md): secondQueueCoreLevel 10 -> 3, TRANSPORT.capacityPerLink 500 -> 1000 (end game was shipping-limited in bot runs). - Server fixes: POST /reports/:id/share 500 without a pending reportCleanup; bounced link shipments were silent about cargo overflow. Tested: npm test 207/207 (new: bot determinism + invariants, client alerts/world/i18n over CODES, two regression tests that failed before their fix); openapi check up to date. Real-browser scratch runs (not in repo): WebSocket push shows an incoming-attack banner ~214 ms after launch, polling fallback ~52 s, 15 scripted flows, 71 screenshots. NOT tested: Playwright suite (e2e/ still empty), real devices/Safari, nginx proxy websockets, throttled networks, HTTP-level bot load. NOT claimed: balance. Bots are not humans; open balance items (loot waste, escrow refund clipping, no garrisons at landing sites, end game not scaling with world speed) are listed in docs/BALANCE.md. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q2MJaQ5LXAHzGnTDgceT14
30 lines
1.6 KiB
JavaScript
30 lines
1.6 KiB
JavaScript
'use strict';
|
|
/*
|
|
* A return leg arrived: units and cargo go back home. If the origin POP changed hands meanwhile they go to the
|
|
* operator's capital (or oldest POP) instead; with no POP left they are lost. Cargo above the Rack hall cap is lost.
|
|
*/
|
|
const R = require('../../public/js/rules.js');
|
|
const D = require('../../public/js/data.js');
|
|
const { loadTown, settle } = require('../state');
|
|
const M = require('../military/movements');
|
|
const U = require('../military/units');
|
|
const P = require('../military/power');
|
|
const { addCargo } = require('../military/arrivals');
|
|
|
|
module.exports = function ret(ctx, ev) {
|
|
const { db } = ctx;
|
|
const mv = M.getMovement(db, ev.payload.movementId);
|
|
if (!mv || mv.status !== 'out') return;
|
|
db.run("UPDATE movements SET status = 'done' WHERE id = ?", mv.id);
|
|
const dest = U.homeTownFor(db, mv.ownerId, mv.toTownId);
|
|
const uid = U.userOfOperator(db, mv.ownerId);
|
|
if (!dest) { if (uid) ctx.notify(uid, mv.worldId, 'movement_lost', { movementId: mv.id }); return; }
|
|
const town = loadTown(db, dest.id);
|
|
settle(db, town, ev.dueAt);
|
|
U.addHome(db, town.id, mv.units);
|
|
const lost = addCargo(db, town, mv.cargo);
|
|
P.reschedule(ctx, town.id, ev.dueAt);
|
|
// Empty carriers coming home (extra.link) are silent; a bounced shipment that carries cargo is not: its overflow is reported.
|
|
const carrying = D.RESOURCES.some((r) => mv.cargo && mv.cargo[r] > 0);
|
|
if (uid && (!mv.extra.link || carrying)) ctx.notify(uid, mv.worldId, 'movement_returned', { movementId: mv.id, townId: town.id, units: mv.units, cargo: mv.cargo, cargoLost: lost });
|
|
};
|