Upstream/server/events/arrive.js
jvanvik 249818a7aa Stage 3-5 server (military, expansion, social), web client for stages 1-2, ops/deploy
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
2026-10-11 18:32:36 +02:00

19 lines
963 B
JavaScript

'use strict';
/* A movement reached its destination. Payload { movementId }. Dispatches by movement type; everything runs at the
* event's own due time, inside the scheduler's transaction. Idempotent: only an `out` movement is processed. */
const M = require('../military/movements');
const A = require('../military/arrivals');
const combat = require('../military/combat');
module.exports = function arrive(ctx, ev) {
const mv = M.getMovement(ctx.db, ev.payload.movementId);
if (!mv || mv.status !== 'out') return;
ctx.db.run("UPDATE movements SET status = 'done' WHERE id = ?", mv.id);
switch (mv.type) {
case 'scan': case 'raid': case 'attack': case 'takeover': return combat.arrive(ctx, mv, ev);
case 'reinforce': return A.arriveReinforce(ctx, mv, ev);
case 'transport': return A.arriveTransport(ctx, mv, ev);
case 'settle': return A.arriveSettle(ctx, mv, ev);
default: throw new Error('unknown movement type ' + mv.type);
}
};