City density rule: retire 15 crowded Brazilian cities from new games

A small city (P < 60) may not sit within 300 km of a bigger city in the
same country unless it is a cable landing or a capital (Canberra gets a
capital flag); a test enforces it everywhere. The 15 Brazilian cities
that broke it get off:true: still in the data so saves keep their POPs,
routing and links there, but new games do not draw them, offer them to
customers, list them in network presence, or let you build a POP there.
Brazil goes from 40 to 25 cities (Europe has 44). Order and Progress now
needs 15 IX.brrr ports.
This commit is contained in:
Frederic Jung 2026-10-27 10:09:12 +01:00
parent 295e68cc46
commit 3d469d9a93
No known key found for this signature in database
7 changed files with 63 additions and 34 deletions

View file

@ -1281,17 +1281,17 @@ test('#51 a dark fiber shows what is rented out, and spare capacity can be liste
test('#126 you can zoom in far enough, and pick a short link between two close cities', () => {
const { ev, errors } = load();
ev("ACT.start({city:'sao'});S.cash=1e9;for(const g of GOALS)S.done[g.id]=0;for(const c of ['poa','fln'])ACT.buildPop({city:c});UI.pending=null;UI.via=null;UI.lmode='wave';UI.route='main';openLinkModal('poa','fln');ACT.buildLink({tier:1});closeModal()");
ev("ACT.start({city:'sao'});S.cash=1e9;for(const g of GOALS)S.done[g.id]=0;for(const c of ['cpq'])ACT.buildPop({city:c});UI.pending=null;UI.via=null;UI.lmode='wave';UI.route='main';openLinkModal('sao','cpq');ACT.buildLink({tier:1});closeModal()");
assert.ok(ev('ZMAX') >= 16);
const id = ev("S.links.find(l=>l.a==='poa'||l.b==='poa').id");
const id = ev("S.links.find(l=>l.a==='sao'||l.b==='sao').id");
// the middle of the drawn link, on screen, fully zoomed in on it
const at = (z) => JSON.parse(ev(`(()=>{const l=S.links.find(x=>x.id==='${id}'),g=linkGeom(l,pairIdx().get(edgeKey(l))),p=g.pts[Math.floor(g.pts.length/2)];
cam.x=p[0];cam.y=p[1];cam.z=1;zoomAt(CW/2,CH/2,${z});const [sx,sy]=toS(p[0],p[1],visibleKs()[0]);const c=toS(CITY.poa.x,CITY.poa.y,visibleKs()[0]);return JSON.stringify({sx,sy,cx:c[0],cy:c[1],z:cam.z});})()`));
cam.x=p[0];cam.y=p[1];cam.z=1;zoomAt(CW/2,CH/2,${z});const [sx,sy]=toS(p[0],p[1],visibleKs()[0]);const c=toS(CITY.sao.x,CITY.sao.y,visibleKs()[0]);return JSON.stringify({sx,sy,cx:c[0],cy:c[1],z:cam.z});})()`));
const m = at(100);
assert.equal(m.z, ev('ZMAX'), 'zoom stops at the new maximum');
assert.equal(ev(`pickCity(${m.sx},${m.sy})`), null, 'the middle of the link is not grabbed by a city');
assert.equal(ev(`hitLink(${m.sx},${m.sy})`), id);
assert.equal(ev(`pickCity(${m.cx},${m.cy-4}).id`), 'poa', 'tapping the city icon still picks the city');
assert.equal(ev(`pickCity(${m.cx},${m.cy-4}).id`), 'sao', 'tapping the city icon still picks the city');
// even at the old maximum, a click on the link now picks the link where it is not under a city icon
const o = at(6);
assert.ok(Math.abs(o.z - 6) < 1e-9);

View file

@ -1044,3 +1044,26 @@ test('an old save with Australian POPs is told once that Australia changed', ()
assert.doesNotMatch(c.ev("S.log.map(e=>e.t).join(' | ')"), /Australia got more/);
assert.deepEqual(errors, []);
});
test('city density: no small city crowds a bigger one, Brazil is slimmer than Europe, and old saves keep retired cities', () => {
const { ev, errors } = load();
// A small city (P < 60) never sits within 300 km of a bigger city in the same country, unless it is a cable landing or a capital.
const bad = JSON.parse(ev(`JSON.stringify((()=>{const ctry=c=>c.cc||(c.br&&'BR')||(c.au&&'AU')||(c.ca&&'CA')||'land:'+c.land,out=[];
for(const c of CITIES){if(c.off||c.P>=60||c.capital||landing(c.id))continue;
for(const o of CITIES)if(o!==c&&!o.off&&o.P>c.P&&ctry(o)===ctry(c)&&kmBetween(c.id,o.id)<300)out.push(c.id+' near '+o.id+' ('+kmBetween(c.id,o.id)+' km)');}
return out;})())`));
assert.deepEqual(bad, [], 'add a bigger city, a capital flag or a cable landing, or mark it off');
const br = ev("CITIES.filter(c=>c.br&&!c.off).length"), eu = ev("CITIES.filter(c=>c.reg==='EU'&&!c.off).length");
assert.ok(br < eu * 0.7, `Brazil (${br}) well below Europe (${eu})`);
// a new game never shows or offers a retired city
ev("ACT.start({});S.cash=1e9;for(const g of GOALS)S.done[g.id]=0");
assert.equal(ev("cityOn('cpv')"), false);
assert.equal(ev("OFFC.includes('cpv')"), false);
assert.equal(ev("NETS.some(n=>{const p=netPlaces(n.id);return p.x.includes('cpv')||p.p.includes('cpv');})"), false);
// an old save with a POP there keeps it, on the map and in routing
ev("ACT.buildPop({city:'rec'});S.pops.cpv={day:0,bb:{d:5},boost:0,down:0,routers:1,gen:false};const o=JSON.parse(JSON.stringify(S));S=migrate(o);compute()");
assert.ok(ev("!!S.pops.cpv&&cityOn('cpv')"));
assert.ok(ev("R.cityDem.cpv>0"));
ev('cam.x=CITY.cpv.x;cam.y=CITY.cpv.y;cam.z=6;draw(0)');
assert.deepEqual(errors, []);
});