${esc(CAB[wr.cab].blurb)} ${tr('geography_and_latency.all_your_waves_on_one_cable')}
`:''}`;} function bestLat(a,b,f){const ls=S.links.filter(l=>!linkDown(l)&&(!f||f(l)));const dist={[a]:0},done=new Set();for(;;){let u=null,ud=Infinity;for(const k in dist)if(!done.has(k)&&dist[k]${tr('link_modal.nobody_sells_capacity_between_kyiv')}
`);return;} + {const nt=noTalk(a,b);if(nt){openModal(`${tr(nt)}
`);return;}} if((cnCity(a)||cnCity(b))&&!cnOk()){openModal(`${tr('link_modal.building_into_mainland_china_needs_a',{city:CITY[cnCity(a)?a:b].name})}
`);return;} let route='';UI.pending={a,b};const km=kmBetween(a,b),sub=isSub(a,b),pop=S.pops[b]?0:newPopCost(b),sib=pairLinks(a,b).filter(l=>l.kind!=='vxc'); if(!sib.length)UI.route='diverse';const border=cnCity(a)!==cnCity(b),jn=sib.length?routeJoin(a,b):null,ts=landTrenches(a,b),mult=(sib.length&&!(jn&&jn.k===(ts[0]||{}).k)?DIVERSE:1)*(border?3*(UI.cnPrem&&(a==='hkg'||b==='hkg')?1.6:1):1); diff --git a/src/i18n/en.js b/src/i18n/en.js index 5a5e6ff..33977d7 100644 --- a/src/i18n/en.js +++ b/src/i18n/en.js @@ -2601,6 +2601,7 @@ "link_modal.local_telecom_licence_included":"local telecom licence included", "link_modal.needs_what_at_both_ends":"needs {what} at both ends", "link_modal.new_diverse_route_40_survives_cuts":"New diverse route +40% · survives cuts alone", +"link_modal.no_circuit_crosses_between_north_and":"No circuit crosses between North and South Korea, and no carrier will sell you one. Pyongyang reaches the world through China and Russia.", "link_modal.no_subsea_cable_lands_in_both":"No subsea cable lands in both {a} and {b}. Cables from {a} reach {list}. Hop through one of those.", "link_modal.no_subsea_cable_lands_in_city":"No subsea cable lands in {city}. The nearest landing station is {near}: run fiber there first, then take a cable from it.", "link_modal.nobody_sells_capacity_between_kyiv":"Nobody sells capacity between Kyiv and Moscow, and nobody is going to. Route through Warsaw, Bucharest or Helsinki instead.", diff --git a/tests/borders-overland.test.js b/tests/borders-overland.test.js new file mode 100644 index 0000000..ef6a7ce --- /dev/null +++ b/tests/borders-overland.test.js @@ -0,0 +1,51 @@ +// Fiber over land inside one country: cities on land with no road in (Russia's Arctic and Kamchatka, Alaska, Greenland's +// towns) can be dug to from the rest of their own country, and only their own. North and South Korea, like Kyiv and +// Moscow, get no circuit between them at all. +const test = require('node:test'); +const assert = require('node:assert/strict'); +const { load } = require('./harness'); + +const start = "ACT.start({});S.cash=1e9;S.lvl=13;S.nextFail=S.nextEvent=1e9;for(const g of GOALS)S.done[g.id]=0;"; + +test('cities of one country on one piece of land can build terrestrial fiber between them', () => { + const { ev, errors } = load(); + ev(start); + for (const [a, b, why] of [['pvs', 'dyr', 'Pevek–Anadyr, both Chukotka'], ['pvs', 'mos', 'Pevek–Moscow, across Russia'], ['pkc', 'vvo', 'Kamchatka–Vladivostok'], + ['jnu', 'sea', 'Juneau–Seattle, both US'], ['brw', 'ome', "Alaska's Arctic coast"], ['nuk', 'sis', "Greenland's towns, one island"]]) { + assert.equal(ev(`isSub('${a}','${b}')`), false, `${why}: over land`); + assert.equal(ev(`dfAllowed('${a}','${b}')`), true, `${why}: dark fiber can be built`); + assert.equal(ev(`landMult('${a}','${b}')`) < 45, true, `${why}: not priced as a crossing between continents`); + } + ev("UI.lmode='wave';openLinkModal('pvs','dyr')"); + assert.match(ev("document.getElementById('modalCard').textContent"), /Terrestrial/); + assert.deepEqual(errors, []); +}); + +test('only inside the country: islands and other countries stay across the sea', () => { + const { ev, errors } = load(); + ev(start); + for (const [a, b, why] of [['jnu', 'van', 'Juneau–Vancouver: a border'], ['yfb', 'mtl', 'Iqaluit is on Baffin Island'], ['pkc', 'uus', 'Sakhalin is an island'], + ['ome', 'vvo', 'Nome–Vladivostok: two countries'], ['hnl', 'sea', 'Hawaii']]) { + assert.equal(ev(`isSub('${a}','${b}')`), true, why); + } + assert.equal(ev("landMult('ist','esb')") < 45, true, 'Istanbul–Ankara is one country, not two continents'); + assert.deepEqual(errors, []); +}); + +test('no circuit of any kind between North and South Korea, and still none between Kyiv and Moscow', () => { + const { ev, errors } = load(); + ev(start + "ACT.launchBB({city:'icn'});S.pops.fnj={day:0,bb:null,boost:0,down:0,routers:1,gen:false,rgen:3};compute()"); + for (const [a, b, msg] of [['icn', 'fnj', /North and South Korea/], ['fnj', 'icn', /North and South Korea/], ['kyv', 'mos', /Kyiv and Moscow/]]) { + ev(`UI.pending=null;openLinkModal('${a}','${b}')`); + assert.match(ev("document.getElementById('modalCard').textContent"), msg); + assert.equal(ev('UI.pending'), null, 'nothing to order'); + assert.equal(ev(`dfAllowed('${a}','${b}')`), false); + } + // Even an action called directly (an agent, a stale window) builds nothing. + const n = ev('S.links.length'); + ev("UI.pending={a:'icn',b:'fnj'};ACT.buildLink({tier:0});UI.pending={a:'icn',b:'fnj'};UI.dfSrc='build';ACT.orderDf();UI.pending={a:'icn',b:'fnj'};ACT.orderCable()"); + assert.equal(ev('S.links.length'), n); + // Seoul and Pyongyang are still on one landmass, but a latency customer cannot count on a link between them. + assert.ok(ev("latFloor('icn','fnj')") > ev("latMaxOf('icn','fnj')")); + assert.deepEqual(errors, []); +}); diff --git a/tests/islands-and-arctic.test.js b/tests/islands-and-arctic.test.js index 78ddfc6..8619346 100644 --- a/tests/islands-and-arctic.test.js +++ b/tests/islands-and-arctic.test.js @@ -92,7 +92,10 @@ test('Alaska and northern British Columbia: towns with no road in are islands, a } assert.equal(ev("isSub('anc','sea')"), false, 'Anchorage has a road south'); assert.equal(ev("isSub('prr','van')"), false, 'so does Prince Rupert'); - for (const c of ['jnu', 'ome', 'brw', 'dut']) assert.ok(ev(`isSub('${c}','anc')`), `${c}: no road in, only the sea`); + // No road in, but US soil joined to Anchorage: a US network may dig there. Unalaska is an island. + for (const c of ['jnu', 'ome', 'brw']) assert.equal(ev(`isSub('${c}','anc')`), false, `${c}: overland inside the US`); + assert.ok(ev("isSub('dut','anc')"), 'dut: an island, only the sea'); + assert.ok(ev("isSub('jnu','van')"), 'Juneau to Canada: a border, so only the sea'); assert.ok(lands(ev, 'qtl', 'ome', 'brw') && lands(ev, 'qtl', 'brw', 'anc') && lands(ev, 'aleu', 'anc', 'dut') && lands(ev, 'topaz', 'van', 'tok')); assert.equal(ev('CAB.qtl.fragile'), true, 'sea ice keeps the repair ships away'); assert.equal(ev('CITY.anc.ix.length>0'), true, 'Anchorage has its exchange'); @@ -120,8 +123,9 @@ test("Russia's Arctic and Pacific: government boxes, real cables only, beaches w // nothing crosses the Bering Strait assert.equal(ev("CABLE_PAIRS.some(p=>CITY[p.a].ru!==CITY[p.b].ru&&(CITY[p.a].cc==='US'||CITY[p.b].cc==='US'))"), false); assert.equal(ev("isSub('dyr','anc')"), true); - // Kamchatka has no road to the rest of Russia; Magadan and Vladivostok do - assert.equal(ev("isSub('pkc','vvo')"), true); + // Kamchatka has no road to the rest of Russia, but it is Russian soil: a Russian route may dig there. Sakhalin is an island. + assert.equal(ev("isSub('pkc','vvo')"), false); + assert.equal(ev("isSub('uus','vvo')"), true); assert.equal(ev("isSub('gdx','vvo')||isSub('mmk','mos')"), false); assert.ok(ev("CITY.vvo.ix.length>0&&ixMembers('vvo').includes('mgf')&&ixMembers('vvo').includes('ert')"), 'the Vladivostok exchange'); // a sovereign-internet drill cuts the cable to Japan like any other border link diff --git a/tests/latency-offers.test.js b/tests/latency-offers.test.js index 32f9e1f..5e8e2c9 100644 --- a/tests/latency-offers.test.js +++ b/tests/latency-offers.test.js @@ -1,31 +1,39 @@ -// #273: a latency offer only asks for a ceiling something you can build meets. Pevek–Anadyr is 635 km apart as the -// crow flies, but only a 1,717 km sea route joins them, so a 4.3 ms ceiling can never be met. +// #273: a latency offer only asks for a ceiling something you can build meets. Iqaluit and Nuuk are about 750 km apart +// as the crow flies, but no cable lands in Iqaluit and no road reaches it, so a 5.5 ms ceiling can never be met. const test = require('node:test'); const assert = require('node:assert/strict'); const { load } = require('./harness'); -// Spawn many mars offers from a network at Pevek and Anadyr only: most are between the two. +// Spawn many mars offers from a network at two cities only: most are between the two. const marsOnly = "eval('('+spawnOffer.toString().replace('const t=pick(types)',\"const t='mars'\")+')')"; const spawn = (ev, n) => ev(`(()=>{S.offers=[];const f=${marsOnly};for(let i=0;i<${n};i++)f();return JSON.stringify(S.offers.map(o=>[o.city,o.city2,o.latMax]));})()`); const start = (ev, cities) => ev(`ACT.start({});S.cash=1e9;S.nextFail=1e9;S.nextEvent=1e9;for(const g of GOALS)S.done[g.id]=0;S.lvl=13;S.pops={};for(const c of ${JSON.stringify(cities)})S.pops[c]={day:0,bb:null,boost:0,down:0,routers:1,gen:false,rgen:0};compute()`); -test('#273 no latency offer between Pevek and Anadyr: no buildable path meets the straight-line ceiling', () => { +test('#273 no latency offer between Iqaluit and Nuuk: no buildable path meets the straight-line ceiling', () => { const { ev, errors } = load(); - start(ev, ['pvs', 'dyr']); + start(ev, ['yfb', 'nuk']); assert.ok(ev('lvl()') >= 13, 'mars offers are unlocked'); - assert.equal(ev("latMaxOf('pvs','dyr')"), 4.3); - const pair = o => [o[0], o[1]].sort().join('-') === 'dyr-pvs'; + assert.equal(ev("latMaxOf('yfb','nuk')"), 5.5); + const pair = o => [o[0], o[1]].sort().join('-') === 'nuk-yfb'; const offers = JSON.parse(spawn(ev, 60)); assert.ok(offers.length > 0, 'mars offers still spawn'); - assert.deepEqual(offers.filter(pair), [], 'but none asks for 4.3 ms between Pevek and Anadyr'); - assert.ok(!(ev("latFloor('pvs','dyr')") <= 4.3), 'nothing on the map gets there in 4.3 ms'); - // Even with the player's own Low latency cable, 7.7 ms is the best there is. - ev("S.links.push({id:'own1',a:'pvs',b:'dyr',kind:'df',own:true,sub:true,seaDesign:'express',sys:'roadm',ch:[],km:1717,cable:null,mo:1,trench:'own:own1',cut:0,day:0,ready:0,pairs:1});compute()"); - assert.ok(ev("bestLat('pvs','dyr')") > 4.3); + assert.deepEqual(offers.filter(pair), [], 'but none asks for 5.5 ms between Iqaluit and Nuuk'); + assert.ok(!(ev("latFloor('yfb','nuk')") <= 5.5), 'nothing on the map gets there in 5.5 ms'); + // Even with the player's own Low latency cable round Baffin Island's coast, the best is above the ceiling. + ev("S.links.push({id:'own1',a:'yfb',b:'nuk',kind:'df',own:true,sub:true,seaDesign:'express',sys:'roadm',ch:[],km:1300,cable:null,mo:1,trench:'own:own1',cut:0,day:0,ready:0,pairs:1});compute()"); + assert.ok(ev("bestLat('yfb','nuk')") > 5.5); assert.deepEqual(JSON.parse(spawn(ev, 60)).filter(pair), []); assert.deepEqual(errors, []); }); +test('#273 Pevek–Anadyr is Russian fiber over land now, so its 4.3 ms offers can be met and do come', () => { + const { ev, errors } = load(); + start(ev, ['pvs', 'dyr']); + assert.ok(ev("latFloor('pvs','dyr')") <= ev("latMaxOf('pvs','dyr')")); + assert.ok(JSON.parse(spawn(ev, 60)).some(o => [o[0], o[1]].sort().join('-') === 'dyr-pvs')); + assert.deepEqual(errors, []); +}); + test('#273 latency offers still come where a build meets the ceiling', () => { const { ev, errors } = load(); start(ev, ['lon', 'nyc']); diff --git a/tests/load-time.test.js b/tests/load-time.test.js index 9106cab..ee731af 100644 --- a/tests/load-time.test.js +++ b/tests/load-time.test.js @@ -10,7 +10,7 @@ test('diversity map: the indexed graph answers like disjointRoutes() over every ev('ACT.start({})'); // The plain map: one record per possible link, in the order the indexed one adds them. ev(`window.plainLinks=state=>{const rules=state.scn&&state.scn.rules||{},links=[],cities=CITIES.filter(c=>!(rules.banCities||[]).includes(c.id)).map(c=>c.id),add=(a,b,id)=>links.push({a,b,id}); - for(let i=0;i