Phase 3: trade/end-game client, bot simulator, first balance pass

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
This commit is contained in:
jvanvik 2026-10-11 20:24:41 +02:00
parent d84b0c9d12
commit 931f59e11e
49 changed files with 4750 additions and 59 deletions

View file

@ -8,6 +8,7 @@
* source.isOwn(town) -> bool
* source.movements() -> [{ from: {x,y}, to: {x,y}, kind: 'out' | 'in' | 'ret' | 'ally', p: 0..1 }] optional: lines with a marker at progress p
* source.threatened(town) -> bool optional: an incoming movement is heading for this own POP (red ring)
* source.myAllianceId() -> id | null optional: colours the end game landing sites (specials of type 'backbone')
* onTap(x, y) a finger lift / click that was not a drag or a pinch (act on lift)
* onMoveEnd(view) debounced after the camera stopped; view = { x0, y0, x1, y1, cx, cy, zoom }
*
@ -19,6 +20,7 @@
const COLORS = {
void: '#04070e', land: '#0d1626', land2: '#0f192b', grid: 'rgba(120,160,220,0.10)', grid10: 'rgba(120,160,220,0.22)', border: 'rgba(77,227,255,0.55)',
fiber: '#4de3ff', hardware: '#ff9f5a', capital: '#5be08f', incumbent: '#b06cff', incumbentFill: '#241338',
backbone: '#f5c542', backboneFill: '#2b2208', rivalSite: '#ff6bd6',
own: '#4de3ff', ownFill: '#0f4b63', select: '#ffd24d', text: '#e4f0ff', halo: 'rgba(4,7,14,0.9)', reach: 'rgba(77,227,255,0.35)',
};
@ -278,6 +280,7 @@
this.src.forEachSpecial(v.x0, v.y0, v.x1, v.y1, (sp) => {
const s = this.toScreen(sp.x, sp.y);
if (sp.type === 'rural') this._rural(s.x, s.y, sp.bonus);
else if (sp.type === 'backbone') this._backbone(s.x, s.y, sp);
else this._incumbent(s.x, s.y);
});
@ -336,6 +339,41 @@
}
}
// End game landing site: a diamond with a ring that fills with the node level; gold = nobody's (the incumbent's), cyan = your
// alliance, a rival hue = another alliance. Clearly not an incumbent square and not a POP hexagon.
_backbone(x, y, sp) {
const { ctx, zoom: z } = this;
if (x < -40 || y < -40 || x > this.w + 40 || y > this.h + 40) return;
const site = sp.site || {};
const mine = !!(this.src.myAllianceId && site.holder && site.holder.allianceId === this.src.myAllianceId());
const col = !site.holder ? COLORS.backbone : mine ? COLORS.own : COLORS.rivalSite;
const r = Math.max(4, z * 0.46);
ctx.save();
ctx.shadowColor = col; ctx.shadowBlur = Math.min(18, 4 + z * 0.3);
ctx.beginPath(); ctx.moveTo(x, y - r); ctx.lineTo(x + r, y); ctx.lineTo(x, y + r); ctx.lineTo(x - r, y); ctx.closePath();
ctx.fillStyle = COLORS.backboneFill; ctx.fill();
ctx.restore();
ctx.beginPath(); ctx.moveTo(x, y - r); ctx.lineTo(x + r, y); ctx.lineTo(x, y + r); ctx.lineTo(x - r, y); ctx.closePath();
ctx.strokeStyle = col; ctx.lineWidth = Math.max(1.5, z * 0.09); ctx.stroke();
if (z >= 7) {
const rr = r * 1.45, frac = site.maxLevel ? Math.max(0, Math.min(1, (site.level || 0) / site.maxLevel)) : 0;
ctx.lineWidth = Math.max(2, z * 0.1); ctx.lineCap = 'round';
ctx.strokeStyle = 'rgba(160,180,220,0.22)'; ctx.beginPath(); ctx.arc(x, y, rr, 0, Math.PI * 2); ctx.stroke();
if (frac > 0) { ctx.strokeStyle = col; ctx.beginPath(); ctx.arc(x, y, rr, -Math.PI / 2, -Math.PI / 2 + Math.PI * 2 * frac); ctx.stroke(); }
}
if (z >= 14) { // a lightning bolt: the backbone
ctx.fillStyle = col; ctx.beginPath();
ctx.moveTo(x + r * 0.12, y - r * 0.55); ctx.lineTo(x - r * 0.3, y + r * 0.08); ctx.lineTo(x - r * 0.02, y + r * 0.08);
ctx.lineTo(x - r * 0.14, y + r * 0.55); ctx.lineTo(x + r * 0.3, y - r * 0.1); ctx.lineTo(x + r * 0.02, y - r * 0.1); ctx.closePath(); ctx.fill();
}
if (z >= 18) {
ctx.font = '700 ' + Math.round(clamp(z * 0.3, 10, 13)) + 'px system-ui, sans-serif';
ctx.textAlign = 'center'; ctx.textBaseline = 'top'; ctx.lineWidth = 3; ctx.lineJoin = 'round'; ctx.strokeStyle = COLORS.halo;
const label = (site.index !== undefined ? 'S' + (site.index + 1) : '') + (site.holder ? ' [' + site.holder.tag + ']' : '') + ' L' + (site.level || 0);
ctx.strokeText(label, x, y + r * 1.45 + 4); ctx.fillStyle = col; ctx.fillText(label, x, y + r * 1.45 + 4);
}
}
_hex(x, y, rad) {
const { ctx } = this;
ctx.beginPath();