Phase 4: close loot/refund leaks, landing-site garrisons, speed-scaled shipping, update/offsite tooling, broad e2e
Built: - Economy: raid loot capped to the room the raiders have at home (rest stays with the victim, "lootLeft" in the report); trade escrow reserves its room so refunds always fit; trade accept refuses with no_room_for_goods when the goods would not fit. Loot destroyed per 30-day run 31-61k -> ~1k, refunds clipped ~27k -> 0 (docs/BALANCE.md, 3 seeds). - End game: members of the holding alliance garrison landing sites (migration 005_site_garrison.sql), garrison counts in site defence, 72 h capture shield, withdraw route, POP view lists garrisoned units. Shipping capacity scales with world speed (3x world: winner 76-98 -> ~30-36 days after sites open). Bot runs show real contests (84-194 attacks on held sites at 1x). - Ops: deploy/update.sh (backup, stop, ff-merge, npm ci --ignore-scripts, health check, rollback), deploy/upstream-offsite (rsync only), admin end-world snapshots results, EPIPE fix, docs/workflows/ filled in. - e2e 62 -> 163 checks: units, raids/reports, alliance+messages, trade, end game, nb, PWA, reconnect, slow polling fallback (opt-in). Two app bugs found: message push ignored, "New" button stayed English. Tested: npm test 274/274, openapi check, npm run e2e 163/163 (137 s), bot runs 50x30d seeds 1-3 and 140-day/60-day speed-3 end-game runs INVARIANTS OK, adversarial review pass (findings fixed or documented). NOT tested: update.sh on a real box (systemd, real npm, runuser; stubs only, shellcheck not installed), garrison card/loot text on a phone, Node 22.13, humans. Known leaks left open and documented (BALANCE S6): loot/shipments can still overflow when stock arrives in flight, bounced backbone shipments lose overflow (reported to the sender). Garrison numbers (heldDefenceMult 2, shield 72 h) are first guesses from 2 seeds. Not claimed: balanced. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q2MJaQ5LXAHzGnTDgceT14
This commit is contained in:
parent
9104480463
commit
3c23c51902
92 changed files with 4887 additions and 300 deletions
|
|
@ -49,12 +49,34 @@ function addPoints(db, operatorId, column, v) {
|
|||
const sumValues = (list) => list.reduce((acc, u) => U.sumInto(acc, u), {});
|
||||
|
||||
// Survivors drive home (with loot). No survivors, no movement.
|
||||
function sendHome(ctx, mv, survivors, cargo) {
|
||||
function sendHome(ctx, mv, survivors, cargo, extra) {
|
||||
const { db } = ctx;
|
||||
if (U.isEmpty(survivors)) return null;
|
||||
const dest = U.homeTownFor(db, mv.ownerId, mv.fromTownId);
|
||||
if (!dest) return null;
|
||||
return M.launchReturn(ctx, { worldId: mv.worldId, ownerId: mv.ownerId, fromTownId: mv.toTownId, at: mv.to, to: dest, units: survivors, cargo: cargo || {}, parentId: mv.id, extra: {} });
|
||||
return M.launchReturn(ctx, { worldId: mv.worldId, ownerId: mv.ownerId, fromTownId: mv.toTownId, at: mv.to, to: dest, units: survivors, cargo: cargo || {}, parentId: mv.id, extra: extra || {} });
|
||||
}
|
||||
|
||||
// What the raiders' home can bank per resource when they are back: Rack hall room minus the stock projected to that moment (pure
|
||||
// projection, nothing is written). No home or no survivors to carry anything: no room at all (the loot would never be delivered).
|
||||
function homeRoom(ctx, mv, survivors, now, world) {
|
||||
const none = { fiber: 0, hardware: 0, capital: 0 };
|
||||
const dest = U.homeTownFor(ctx.db, mv.ownerId, mv.fromTownId);
|
||||
if (!dest || U.isEmpty(survivors)) return none;
|
||||
const home = loadTown(ctx.db, dest.id);
|
||||
const bankAt = now + R.movementMs(R.distance(mv.to.x, mv.to.y, dest.x, dest.y), survivors, world.speed);
|
||||
const cur = R.resourcesAt(home, bankAt);
|
||||
// Room already promised: cargo of other return legs still on the road to this POP (earlier raids, bounced shipments) will be banked
|
||||
// too, so two raids that each see the same free room cannot both fill it (the later one is limited, not destroyed on landing).
|
||||
// One-time bonus cargo (extra.bonus) is credited above the cap and holds no room.
|
||||
const booked = { fiber: 0, hardware: 0, capital: 0 };
|
||||
for (const row of ctx.db.all("SELECT cargo, extra FROM movements WHERE type = 'return' AND status = 'out' AND to_town_id = ? AND owner_id = ?", dest.id, mv.ownerId)) {
|
||||
const c = JSON.parse(row.cargo || '{}'), bonus = (JSON.parse(row.extra || '{}').bonus) || {};
|
||||
for (const r of D.RESOURCES) booked[r] += Math.max(0, (c[r] || 0) - (bonus[r] || 0));
|
||||
}
|
||||
const room = {};
|
||||
for (const r of D.RESOURCES) room[r] = Math.max(0, Math.floor(cur.caps[r] - cur.amounts[r] - booked[r]));
|
||||
return room;
|
||||
}
|
||||
|
||||
function arrive(ctx, mv, ev) {
|
||||
|
|
@ -106,12 +128,17 @@ function arrive(ctx, mv, ev) {
|
|||
|
||||
// ---- loot
|
||||
let loot = { fiber: 0, hardware: 0, capital: 0 };
|
||||
const lootLeft = {}; // available and carried, but with no room to bank at home
|
||||
let hidden = 0;
|
||||
if (win) {
|
||||
hidden = kind === 'raid' ? R.cacheFraction(target.buildings.rack_hall ? target.buildings.rack_hall.level : 0) : 0;
|
||||
const avail = {};
|
||||
for (const r of D.RESOURCES) avail[r] = target.res[r] * (1 - hidden);
|
||||
loot = R.lootSplit(R.carryOf(survivorsAtt), avail);
|
||||
// Only what the raiders' home Rack hall can bank when they arrive is taken; the rest stays with the victim and the report says so (S4).
|
||||
const room = homeRoom(ctx, mv, survivorsAtt, now, world);
|
||||
loot = R.lootSplit(R.carryOf(survivorsAtt), avail, room);
|
||||
const wanted = R.lootSplit(R.carryOf(survivorsAtt), avail);
|
||||
for (const r of D.RESOURCES) if (wanted[r] > loot[r]) lootLeft[r] = wanted[r] - loot[r];
|
||||
for (const r of D.RESOURCES) target.res[r] -= loot[r];
|
||||
db.run('UPDATE towns SET fiber = ?, hardware = ?, capital = ? WHERE id = ?', target.res.fiber, target.res.hardware, target.res.capital, target.id);
|
||||
}
|
||||
|
|
@ -163,7 +190,7 @@ function arrive(ctx, mv, ev) {
|
|||
attacker: { operator: opBrief(attackerOp), town: townBrief(origin), units: { sent: mv.units, lost: attLost, survivors: survivorsAtt } },
|
||||
defender: { operator: opBrief(defOp), town: townBrief(target), online, groups: groupReports.map((g) => ({ ownerTownId: g.ownerTownId, sent: g.sent, lost: g.lost, survivors: g.survivors, offline: g.offline })) },
|
||||
power: { attack: b.A, defence: b.D, defenceRaw: b.defenceRaw, firewallLevel: fwLevel, effectiveFirewall: b.effectiveFirewall },
|
||||
loot, cacheHidden: hidden, siege, takeover, capturedTown: captured, returnMovementId: ret ? ret.id : null,
|
||||
loot, lootLeft, cacheHidden: hidden, siege, takeover, capturedTown: captured, returnMovementId: ret ? ret.id : null,
|
||||
};
|
||||
const summary = { type: mv.type, outcome: data.outcome, attacker: opBrief(attackerOp), defender: opBrief(defOp), target: townBrief(target), loot, captured };
|
||||
const recipients = [{ userId: U.userOfOperator(db, attackerOp.id), role: 'attacker' }, { userId: U.userOfOperator(db, defOp.id), role: 'defender' }];
|
||||
|
|
@ -247,7 +274,9 @@ function arriveSite(ctx, mv, now, world) {
|
|||
bonus = { hardware: D.INCUMBENT.hardwareBonus, researchSpeedBonus: R.researchSpeedBonus(U.incumbentTakes(db, attackerOp.id)) };
|
||||
}
|
||||
}
|
||||
const ret = sendHome(ctx, mv, survivors, cargo);
|
||||
// The once-only bonus is delivered in full even when the Rack hall is full (stock above the hall size is kept, it only stops growing): a reward
|
||||
// that can never be earned again must not vanish at the door (S4, events/return.js reads extra.bonus).
|
||||
const ret = sendHome(ctx, mv, survivors, cargo, bonus ? { bonus: { hardware: bonus.hardware } } : {});
|
||||
createReport(ctx, {
|
||||
worldId: mv.worldId, type: 'incumbent', now,
|
||||
summary: { outcome: b.attackerWins ? 'attacker_won' : 'defender_won', site, bonus },
|
||||
|
|
@ -264,6 +293,7 @@ function arriveSite(ctx, mv, now, world) {
|
|||
// standing elsewhere are re-homed, the new owner starts at conqueredLoyalty.
|
||||
function transferTown(ctx, town, newOp, oldOp, now) {
|
||||
const { db } = ctx;
|
||||
require('./garrison').releaseTown(ctx, town.id, 'town_lost'); // what this POP had standing in a landing site goes home to its old owner (E6)
|
||||
db.run('UPDATE towns SET owner_id = ?, is_capital = 0, loyalty = ?, loyalty_at = ? WHERE id = ?', newOp.id, D.EXPANSION.conqueredLoyalty, now, town.id);
|
||||
db.run("UPDATE events SET status = 'cancelled', done_at = ? WHERE town_id = ? AND type IN ('trainDone', 'researchDone') AND status = 'pending'", now, town.id);
|
||||
db.run("UPDATE events SET payload = json_set(payload, '$.userId', ?) WHERE town_id = ? AND type = 'buildDone' AND status = 'pending'", U.userOfOperator(db, newOp.id), town.id);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue