// POP standards by kind (#315: micro, medium, regional hub) next to the build standard (96-pop-standard.js): a POP the // player marked as a kind keeps that kind's routers, so the build standard's router row, its button and the intern never // pull its routers another way. Every other target of the build standard still applies to it, and every unmarked POP // follows the build standard's routers as before. Both only ever add or swap up: neither takes a router out. const test = require('node:test'); const assert = require('node:assert/strict'); const { load } = require('./harness'); // Frankfurt (busy, broadband, two routers), Amsterdam and Paris (empty), all on the Edge Lord, level 7, Change Freeze. const BASE = "ACT.start({});S.cash=1e9;for(const g of GOALS)S.done[g.id]=0;S.lvl=7;S.nextFail=S.nextEvent=1e9;UI.speed=0;S.rules=makeRules('freeze');" + "ACT.launchBB({city:'fra'});ACT.buyTransit({city:'fra',net:'cog',tier:1});for(const c of ['ams','par'])ACT.buildPop({city:c});" + "for(const c of ['fra','ams','par']){S.pops[c].rgen=1;S.pops[c].routers=2;}compute()"; const AU = "RG.findIndex(r=>r.n==='Absolute Unit 3.2T')"; function game(t) { const h = load(); t.after(() => h.dom.window.close()); h.ev(BASE); return h; } const J = (ev, x) => JSON.parse(ev(`JSON.stringify(${x})`)); const routers = (ev) => J(ev, "['fra','ams','par'].map(c=>[S.pops[c].rgen,S.pops[c].routers])"); const jobs = (ev, c) => J(ev, `bstdPlan(false).filter(j=>j.c==='${c}').map(j=>j.k)`); test('a POP marked as a kind keeps its kind\'s routers: the build standard\'s plan, button and intern leave them alone', t => { const { ev, errors } = game(t); const au = ev(AU); // Amsterdam is a micro POP: two Edge Lords. The build standard wants four Absolute Units and a generator everywhere. ev("ACT.ptSave({city:'ams',k:'micro'})"); assert.deepEqual(J(ev, 'S.popTiers.def.micro'), { g: 1, rt: 2 }); assert.equal(ev("ptKind('ams')"), 'micro'); assert.equal(ev("ptKind('par')"), null, 'an unmarked POP has no kind'); ev(`S.popStd=bstdPut({...bstd(),g:${au},rt:4,gen:true});compute()`); assert.deepEqual(jobs(ev, 'ams'), ['gen'], 'only the generator: its routers are the micro standard\'s'); assert.ok(jobs(ev, 'par').includes('g') && jobs(ev, 'par').filter((k) => k === 'rt').length === 2, 'an unmarked POP gets the model and two more routers'); // The button brings the rest up and leaves Amsterdam's routers as they are. const q = J(ev, 'bstdQuote(false)'); ev(`ACT.bstdApply({quote:bstdPlanKey(bstdPlan(false)),q:${q.cost}})`); assert.deepEqual(routers(ev), [[au, 4], [1, 2], [au, 4]]); assert.equal(ev('S.pops.ams.gen'), true, 'the build standard\'s other targets still apply to it'); assert.deepEqual(jobs(ev, 'ams'), [], 'nothing left below the standard there'); // The intern's routers order, standardizing on the build standard's model: Amsterdam is not swapped either. ev("S.pops.par.rgen=1;S.pops.par.rupDay=-1;ACT.opsHire({id:'kevin'});S.ops.floor=0;closeModal();S.ops.on.routers=true;S.ops.p.routers={at:90,how:'auto'};S.ops.cap.routers=0;S.day++;compute();for(const c in R.nodeLoad)R.nodeLoad[c]=0;opsDay(S.day)"); assert.deepEqual(routers(ev).map((r) => r[0]), [au, 1, au], 'Paris is swapped back up to the standard\'s model, Amsterdam keeps the micro model'); // The kind's own button still works: a medium standard of three Absolute Units, Amsterdam marked as medium. ev(`S.popTiers.def.medium={g:${au},rt:3};S.day++;compute()`); const pq = J(ev, "ptPlan('ams','medium')"); assert.deepEqual(pq.steps, ['swap', 'add'], 'swap up, then one more router'); ev(`ACT.ptApply({city:'ams',k:'medium',cost:${pq.cost}})`); assert.deepEqual(routers(ev)[1], [au, 3]); assert.equal(ev("ptKind('ams')"), 'medium'); assert.deepEqual(jobs(ev, 'ams'), [], 'three routers is not below the build standard\'s four there: the kind owns them'); // Neither ever steps down: a kind below the build standard leaves an unmarked POP that has more as it is. ev("S.popTiers.def.micro={g:1,rt:1};S.popTiers.at.par='micro'"); assert.equal(ev("ptPlan('par','micro')"), null, 'a smaller kind is no plan at all'); assert.deepEqual(errors, []); }); test('the build standard sheet and a POP\'s panel say who owns the routers, at 360 px', t => { const { ev, dom, errors } = game(t); const au = ev(AU); ev(`ACT.ptSave({city:'ams',k:'hub'});S.popStd=bstdPut({...bstd(),g:${au}});compute()`); ev('innerWidth=360;ACT.bstdOpen({})'); assert.match(dom.window.document.getElementById('modalCard').textContent, /A POP marked as a kind in POP standards keeps that kind's routers/); ev("closeModal();selectCity('ams');UI.tab='infra';renderPanel()"); const body = dom.window.document.getElementById('panelBody').textContent; assert.match(body, /This POP: Regional hub/); assert.match(body, /keeps that kind's routers/); // No build standard routers: no note in the panel. ev("S.popStd=null;renderPanel()"); assert.doesNotMatch(dom.window.document.getElementById('panelBody').textContent, /keeps that kind's routers/); // Old saves: no popTiers at all, or junk in it, load as no kinds. ev('S=migrate(JSON.parse(JSON.stringify({...S,popTiers:undefined})));compute()'); assert.deepEqual(J(ev, 'S.popTiers'), { def: { micro: null, medium: null, hub: null }, at: {} }); ev("S=migrate(JSON.parse(JSON.stringify({...S,popTiers:{def:{hub:{g:'x'}},at:{ams:'hub',nowhere:'micro',par:'giant'}}})));compute()"); assert.equal(ev("ptKind('ams')"), null, 'a kind without a valid standard owns nothing'); assert.deepEqual(errors, []); }); test('a decommissioned POP loses its mark, as a reload would: a POP built there again has no kind', t => { const { ev, errors } = game(t); const au = ev(AU); ev("ACT.ptSave({city:'ams',k:'micro'});ACT.ptApply({city:'par',k:'micro',cost:0})"); assert.deepEqual(J(ev, 'S.popTiers.at'), { ams: 'micro', par: 'micro' }); ev("UI.decom=['ams'];ACT.decomGo()"); assert.equal(ev('!!S.pops.ams'), false); assert.deepEqual(J(ev, 'S.popTiers.at'), { par: 'micro' }, 'the mark goes with the POP'); // The live state is what a reload makes of it (the server-run gate refuses every later act that touches it otherwise). assert.equal(ev('JSON.stringify(migrate(JSON.parse(JSON.stringify(packSave(S)))).popTiers)'), ev('JSON.stringify(S.popTiers)')); // Built again in the same session: an unmarked POP, which the build standard's routers reach. ev(`ACT.buildPop({city:'ams'});S.pops.ams.rgen=1;S.pops.ams.routers=1;S.popStd=bstdPut({...bstd(),g:${au},rt:4});compute()`); assert.equal(ev("ptKind('ams')"), null); assert.ok(jobs(ev, 'ams').includes('g'), 'the build standard swaps its model'); assert.deepEqual(errors, []); }); test('a name every object has (toString, valueOf) is no POP: the kinds and the build standard stay as they were', t => { const { ev, errors } = game(t); const au = ev(AU); ev(`ACT.ptSave({city:'ams',k:'micro'});S.pops.par.gen=true;ACT.popStdSet({city:'par'});S.popStd=bstdPut({...bstd(),g:${au},rt:3});compute()`); const tiers = ev('JSON.stringify(S.popTiers)'), std = ev('JSON.stringify(S.popStd)'), cash = ev('S.cash'); for (const c of ['toString', 'valueOf', 'hasOwnProperty', 'constructor']) { ev(`ACT.ptSave({city:'${c}',k:'micro'});ACT.ptApply({city:'${c}',k:'micro',cost:0});ACT.popStdSet({city:'${c}'});closeModal()`); assert.equal(ev('JSON.stringify(S.popTiers)'), tiers, `ptSave and ptApply on '${c}'`); assert.equal(ev('JSON.stringify(S.popStd)'), std, `popStdSet on '${c}'`); assert.equal(ev(`ptPlan('${c}','micro')`), null); } assert.equal(ev('S.cash'), cash); assert.deepEqual(errors, []); });