Upstream/public/js/screens/expand.js
jvanvik 931f59e11e 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
2026-10-11 20:24:41 +02:00

50 lines
3.3 KiB
JavaScript

'use strict';
/*
* Expansion on the POP screen (App.popSections, slot 'main'): your POPs (switch between them), and what founding the next
* one takes: rollout crews at home, the footprint gate, a shortcut to the map to pick a site (the map tile sheet then offers
* "Send" -> Settle with the wild-slot choice, see send.js). The founding itself is a settle movement; the settle report has
* an "Open POP" button. The POP switcher in the resource bar lives in main.js.
*/
(function () {
const { h, icon, toast } = UI;
const R = UpstreamRules;
const D = UpstreamData;
const mil = () => App.mil;
function popsList(t) {
const st = App.state;
return h('ul', { class: 'mil-list' }, st.towns.map((x) => h('li', { class: 'mil-row' + (x.id === t.id ? ' current' : '') },
h('span', { class: 'row-ic' }, icon('pop')),
h('span', { class: 'row-main' },
h('span', { class: 'row-title' }, h('b', { text: x.name }), x.isCapital ? h('span', { class: 'pill accent', text: App.t('pop.capital') }) : null),
h('span', { class: 'row-sub' }, mil().coordLink(x.x, x.y))),
x.id === t.id ? h('span', { class: 'pill green', text: App.t('exp.current') })
: h('button', { class: 'btn small', type: 'button', onclick: () => { App.setTown(x.id); } }, App.t('exp.open')))));
}
function card(t) {
const m = t.military;
const owned = App.state.towns.length;
const need = R.footprintNeeded(owned);
const crews = m ? (m.units.home[D.EXPANSION.settleUnit] || 0) : 0;
const canTrain = m && m.trainable.some((u) => u.unit === D.EXPANSION.settleUnit && !u.locked);
const rows = [
h('div', { class: 'kv' }, h('span', { class: 'k', text: App.t('exp.crews') }), h('span', { class: 'v mono' + (crews >= D.EXPANSION.crews ? ' good' : ''), text: crews + ' / ' + D.EXPANSION.crews })),
h('div', { class: 'kv' }, h('span', { class: 'k', text: App.t('exp.footprint') }), h('span', { class: 'v mono', text: App.t('exp.footprint.v', { have: App.fmt.num(t.footprint), need: App.fmt.num(need) }) })),
h('div', { class: 'kv' }, h('span', { class: 'k', text: App.t('exp.range') }), h('span', { class: 'v mono', text: D.EXPANSION.maxDistance + ' ' + App.t('common.tiles') })),
];
const actions = [];
if (crews >= D.EXPANSION.crews) {
actions.push(h('button', { class: 'btn primary wide', type: 'button', 'data-keep': '', onclick: () => { App.go('map', { x: t.x, y: t.y, zoom: 24 }); toast(App.t('exp.pick'), 'ok'); } }, icon('flag'), App.t('exp.found')));
} else {
actions.push(h('p', { class: 'row-sub wrap', text: canTrain ? App.t('exp.needCrews', { n: D.EXPANSION.crews - crews, unit: mil().unitName(D.EXPANSION.settleUnit) }) : App.t('exp.needDepot') }));
if (canTrain) actions.push(h('button', { class: 'btn wide', type: 'button', onclick: () => App.go('units') }, icon('units'), App.t('exp.train')));
}
return h('section', { class: 'card' },
h('div', { class: 'card-head' }, h('h2', null, icon('flag'), App.t('exp.title')), h('span', { class: 'pill', text: App.t('exp.count', { n: owned }) })),
rows, h('p', { class: 'row-sub wrap', text: App.t('exp.hint') }), actions,
owned > 1 ? [h('h3', { class: 'sub', text: App.t('exp.pops') }), popsList(t)] : null);
}
App.popSections.push({ slot: 'main', render: card });
}());