Built: units/research/training, movements (scan, raid, attack, takeover, reinforce, settle, transport), deterministic combat resolved in the event queue, reports, power/offline units, founding + conquest + incumbent sites; alliances, roles, diplomacy (24h pact cancel via events), messages, rankings; vanilla-JS phone-first client (auth, POP, map, alerts, settings, en/nb); systemd units, backup timer, DEPLOY.md, tools/admin.js. Tested: npm test 96/96 (fake clock, in-memory db, a few real-HTTP tests); client checked with headless Chromium screenshots only. NOT done: marketplace/transport trade, client screens for military/social, WebSocket push, bots/balance, e2e suite. All unit stats and costs are unbalanced first guesses. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q2MJaQ5LXAHzGnTDgceT14
28 lines
1.3 KiB
JavaScript
28 lines
1.3 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);
|
|
if (uid && !mv.extra.link) ctx.notify(uid, mv.worldId, 'movement_returned', { movementId: mv.id, townId: town.id, units: mv.units, cargo: mv.cargo, cargoLost: lost });
|
|
};
|