Steadier taps, lighter map drawing, Sinai land route, live Tier 1, courtesy route, optics spares

Fixes #43, fixes #44, fixes #45, fixes #46, fixes #47
This commit is contained in:
Frederic Jung 2026-10-25 14:08:55 +01:00
parent 6a8df55dd9
commit 8e921693c5
No known key found for this signature in database
6 changed files with 185 additions and 32 deletions

View file

@ -327,9 +327,10 @@ test('#40 overland between continents costs ten times subsea or more, and has no
base(ev);
const r = JSON.parse(ev(`JSON.stringify(CABLE_PAIRS.filter(c=>landX(c.a,c.b)).map(c=>{
const land=waveMo(kmBetween(c.a,c.b),false,2)*landMult(c.a,c.b)*waveMarket(c.a,c.b,false).m;
const sub=waveMo(c.km,true,2)*CAB[c.cid].price*waveMarket(c.a,c.b,true).m;return land/sub;}))`));
const sub=waveMo(c.km,true,2)*CAB[c.cid].price*waveMarket(c.a,c.b,true).m;return [land/sub,!!(CITY[c.a].land2||CITY[c.b].land2)];}))`));
assert.ok(r.length >= 4, 'Europe–Asia cable routes exist to compare');
for (const x of r) assert.ok(x >= 10, `overland is at least 10× subsea (${x.toFixed(1)})`);
// Across a land bridge (Cairo, #47) the cable goes the long way round Arabia, so overland is "only" 4–9× dearer.
for (const [x, bridge] of r) assert.ok(x >= (bridge ? 4 : 10), `overland is at least ${bridge ? 4 : 10}× subsea (${x.toFixed(1)})`);
assert.equal(ev("landX('mrs','hkg')"), true);
assert.equal(ev("landX('fra','mrs')"), false, 'inside Europe stays normal');
assert.equal(ev("landMult('fra','mrs')"), 1);
@ -489,3 +490,28 @@ test('#42 the share card draws links across the date line on both edges of the m
ev('shareCanvas()');
assert.deepEqual(errors, []);
});
test('#45 unplugged optics go on a spares shelf, get reused for free, or sold for 40%', () => {
const { ev, errors } = load();
base(ev);
ev("S.lvl=4;ACT.buildPop({city:'ams'});S.pops.fra.rgen=S.pops.ams.rgen=RG.length-1;S.links.push({id:'df1',a:'fra',b:'ams',kind:'df',km:450,sys:'roadm',ch:[],ready:0,mo:500,day:0,cut:0});compute()");
const o = ev("Object.keys(OPT).find(k=>!chWhy(S.links[0],k))");
const c0 = ev('S.cash');
ev(`ACT.addCh({id:'df1',o:'${o}'})`);
const price = c0 - ev('S.cash');
assert.ok(price > 0);
ev(`ACT.rmCh({id:'df1',o:'${o}'})`);
assert.equal(ev(`S.spares['${o}']`), 1, 'the optic goes on the shelf');
const c1 = ev('S.cash');
ev(`ACT.addCh({id:'df1',o:'${o}'})`);
assert.equal(ev('S.cash'), c1, 'plugging it back in is free');
assert.equal(ev(`S.spares['${o}']`), 0);
ev(`ACT.rmCh({id:'df1',o:'${o}'});ACT.sellSpare({o:'${o}'})`);
assert.equal(ev('S.cash') - c1, Math.round(price * 0.4), 'sold for 40% of its price');
ev(`ACT.sellSpare({o:'${o}'})`);
assert.equal(ev('S.cash') - c1, Math.round(price * 0.4), 'nothing to sell twice');
// the shelf survives a save and junk is cleaned
ev(`S.spares={'${o}':2,nope:5,x:-1};S=migrate(JSON.parse(JSON.stringify(S)))`);
assert.deepEqual(JSON.parse(ev('JSON.stringify(S.spares)')), { [o]: 2 });
assert.deepEqual(errors, []);
});

View file

@ -293,3 +293,20 @@ test('NOC dashboard has a tab bar for its sections', () => {
assert.equal(ev('UI.dtab'), 'infra', 'unknown tabs are ignored');
assert.deepEqual(errors, []);
});
test('a brand-new phone player can click through the install pitch and the title screen buttons', () => {
const { ev, dom, errors } = load();
const w = dom.window, doc = w.document;
Object.defineProperty(w, 'innerWidth', { value: 390, configurable: true });
ev('showTitle()');
assert.equal(ev('S'), null, 'no game yet');
const click = (sel) => { const el = doc.querySelector(sel); assert.ok(el, sel); el.dispatchEvent(new w.MouseEvent('click', { bubbles: true })); };
click('#modal [data-act="settings"]');
assert.match(doc.getElementById('modal').textContent, /Pause when a customer is furious/, 'Settings opens before any game exists');
click('#modal [data-act="settingsClose"]');
click('#modal [data-act="start"]');
assert.match(doc.getElementById('modal').textContent, /Play it as an app/);
click('#modal .cta [data-act="pitchSkip"]');
assert.equal(ev('!!(S&&UI.started)'), true, 'Play in the browser anyway really starts the game');
assert.deepEqual(errors, []);
});

View file

@ -50,3 +50,29 @@ test('version comparison for the update banner', () => {
assert.equal(ev("newerVer('1.1.0','1.1.0')"), false);
assert.equal(ev("newerVer('1.0.9','1.1.0')"), false);
});
test('#46 an update that adds networks gives a courtesy route, and Tier 1 is shown only while it is true', () => {
const { ev, errors } = load();
ev("ACT.start({});S.cash=1e8;for(const g of GOALS)S.done[g.id]=0;ACT.launchBB({city:'fra'});ACT.buyTransit({city:'fra',net:'cog',tier:1});compute()");
assert.ok(ev('R.reach') > 0.99);
assert.ok(Array.isArray(JSON.parse(ev('JSON.stringify(S.seen)'))), 'new games remember which networks existed');
// a transit-free network that has never heard of two of today's networks
ev("S.transit=[];S.day=400;S.seen=S.seen.filter(id=>id!=='btt'&&id!=='sky');const s=JSON.parse(JSON.stringify(S));S=migrate(s);compute()");
assert.deepEqual(JSON.parse(ev('JSON.stringify(S.grace.nets.sort())')), ['btt', 'sky']);
assert.equal(ev('S.grace.until'), 460);
assert.equal(ev('R.reachable.btt'), true, 'the courtesy route reaches a network from the update');
assert.equal(ev('R.reachable.cog'), false, 'but not networks the player already knew about');
ev('S.day=461;compute()');
assert.equal(ev('R.reachable.btt'), false, 'it ends after 60 days');
// a save from before this change, with no record at all, gets the grace for everything it cannot reach
ev("S.day=10;delete S.seen;delete S.grace;S=migrate(JSON.parse(JSON.stringify(S)));compute()");
assert.ok(ev('S.grace.nets.length') > 50);
assert.ok(ev('R.reach') > 0.99, 'nothing drops overnight');
// Tier 1 is a state, not a trophy
ev("S.won=true;S.t1Now=true;S.grace=null;compute()");
assert.notEqual(ev('tierLabel()'), 'Tier 1');
ev("window.__t=[];const _t=toast;toast=(h,...a)=>{window.__t.push(h);return _t(h,...a);};dayTick()");
assert.match(ev("window.__t.join(' ')"), /no longer Tier 1/);
assert.equal(ev("BADGES.find(b=>b.id==='t1').ok()"), true, 'the badge stays');
assert.deepEqual(errors, []);
});

View file

@ -386,3 +386,16 @@ test('#41 real coastlines: every city is on land, and the far view drops tiny is
ev('ACT.start({});cam.z=0.5;draw(0);cam.z=2;draw(0)');
assert.deepEqual(errors, []);
});
test('#47 Cairo reaches Asia overland across the Sinai, priced like the Bosporus', () => {
const { ev, errors } = load();
assert.equal(ev("isSub('cai','dxb')"), false, 'Cairo–Dubai can go overland');
assert.equal(ev("isSub('ist','dxb')"), false, 'like Istanbul–Dubai');
assert.equal(ev("landX('cai','dxb')"), true, 'at the intercontinental price');
assert.equal(ev("landMult('cai','dxb')"), ev("landMult('ist','dxb')"));
assert.equal(ev("dfAllowed('cai','dxb')"), false, 'no dark fiber across a dozen borders');
assert.equal(ev("isSub('cai','nbo')"), false, 'still part of Africa');
assert.equal(ev("isSub('lag','dxb')"), true, 'the rest of Africa still needs a cable or a hop via Cairo');
assert.equal(ev("isSub('cai','lon')"), true, 'the Channel is still the sea');
assert.deepEqual(errors, []);
});