A POP in a retired city says why it can't open

buildPop returned without a word for a city that is off the map (the small
Brazilian towns retired in 3d469d9), so the agent API reported no_effect
with no toast. It now toasts that the city is off the map and names the
nearest open city in its country to build in instead, and its dry run
reports that as blocked. An old save that kept a POP there is unchanged.
This commit is contained in:
Charlie Allom 2026-11-04 22:46:10 +10:00
parent 3fd44908af
commit 4b554f2ecb
No known key found for this signature in database
11 changed files with 50 additions and 5 deletions

View file

@ -1,5 +1,7 @@
// Typed orders (the MCP act tool) name both ends of a link, where the map only drags one from a POP of yours.
// A link from a city with no POP is refused, with a toast that says why and a dry run that reports it as blocked.
// Typed orders (the MCP act tool) name both ends of a link and any city for a POP, where the map only offers what
// a player can reach: a link dragged from one of your POPs, a POP in a city that is on the map. These hold the same
// lines: a link from a city with no POP is refused, and so is a POP in a retired small city, each with a toast that
// says why and a dry run that reports it as blocked.
const test = require('node:test');
const assert = require('node:assert/strict');
const { createSession, TOOLS } = require('../scripts/lib/mcp-game');
@ -54,3 +56,36 @@ test('from one of your POPs the same orders still go through and open a POP at t
assert.ok(ev('!!S.pops.cwb'));
assert.deepEqual(s.errors(), []);
});
test('a POP in a retired small city is refused with a toast naming an open city nearby, and its dry run is blocked', () => {
const { s, ev, act, pops } = sandbox();
const q = act('buildPop', { city: 'aju' }, true);
assert.deepEqual(q.quote.blocked, [ev("apiText(popOffWhy('aju'))")]);
assert.match(q.quote.blocked[0], /Aracaju is off the map/);
const r = act('buildPop', { city: 'aju' });
assert.equal(r.outcome, 'rejected');
assert.ok(r.toasts.some((t) => /Aracaju is off the map.*\n.*Build in Salvador instead/s.test(t)), JSON.stringify(r.toasts));
assert.equal(r.charged, 0);
// every retired city names an open city in its own country to build in instead
const near = JSON.parse(ev(`JSON.stringify(CITIES.filter(c=>c.off).map(c=>{const m=popOffWhy(c.id).match(/Build in (.+) instead/);
const o=m&&CITIES.find(x=>x.name===m[1]);return {c:c.id,ok:!!o&&!o.off&&o.cc===c.cc};}))`));
assert.ok(near.length > 0, 'there are retired cities');
assert.deepEqual(near.filter((x) => !x.ok), []);
// an open city still takes a POP; an unknown id does nothing and says nothing
assert.equal(act('buildPop', { city: 'ssa' }).outcome, 'applied');
ev("ACT.buildPop({city:'nope'})");
assert.deepEqual(pops(), ['sao', 'ssa']);
assert.deepEqual(s.errors(), []);
});
test('an old save that kept a POP in a retired city keeps it, and buildPop there stays quiet', () => {
const { s, ev, act } = sandbox();
ev("S.pops.aju={day:0,bb:null,boost:0,down:0,routers:1,gen:false};S=migrate(JSON.parse(JSON.stringify(S)));compute()");
assert.ok(ev("!!S.pops.aju&&cityOn('aju')"));
const r = act('buildPop', { city: 'aju' });
assert.equal(r.outcome, 'no_effect');
assert.deepEqual(r.toasts, []);
// and a link may start there, since it is one of your POPs
assert.equal(act('orderDf', { a: 'aju', b: 'rec', source: 'lease', system: 'roadm' }).outcome, 'applied');
assert.deepEqual(s.errors(), []);
});