diff --git a/CHANGELOG.md b/CHANGELOG.md index f0ad822..f54e8ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project are documented here. The project follows ## [Unreleased] +- New waves can join any route you already have between two cities, so two waves can run on the main route and two on the diverse one (#77). Each extra route shows up as its own choice, priced like the route it joins. - Opening a link from the NOC on mobile now closes the NOC sheet so the link details are visible. ## [1.27.0] — 2026-10-25 diff --git a/site/i18n/it.js b/site/i18n/it.js index f01cbb5..117f4aa 100644 --- a/site/i18n/it.js +++ b/site/i18n/it.js @@ -2389,4 +2389,8 @@ "You already lease dark fiber here. Light {n} more channels for {up}, then cancel the waves to save {price}/mo.":"Qui affitti già una dark fiber. Accendi altri {n} canali per {up}, poi disdici le wave e risparmi {price}/mese.", "Your fiber here has room for {free} more channels, and moving these leases needs {n}. Light another fiber pair or upgrade the line system first.":"La tua fibra qui ha spazio per altri {free} canali, e spostare questi affitti ne richiede {n}. Prima accendi un'altra coppia di fibre o aggiorna il line system.", "No optic you can buy works on your fiber here yet.":"Nessuna ottica che puoi comprare funziona ancora sulla tua fibra qui.", +"Diverse route {n}":"Percorso diverso {n}", +"Main route":"Percorso principale", +"New diverse route +40% · survives cuts alone":"Nuovo percorso diverso +40% · sopravvive da solo ai tagli", +"Waves on the same route share its fate: one backhoe cuts them all.":"Le wave sullo stesso percorso ne condividono la sorte: una ruspa le taglia tutte.", }; diff --git a/site/index.html b/site/index.html index eba081c..f0533f5 100644 --- a/site/index.html +++ b/site/index.html @@ -2661,12 +2661,12 @@ const ACT={ myIxUp:({city})=>{const m=S.myIx[city];if(!m)return;const f=(m.fab|0)+1,N=MYIX_FAB[f];if(!N)return;if(N.lvl>lvl()){toast(tr('A {fab} fabric unlocks at customer level {lv}.',{fab:N.n,lv:N.lvl}),'bad');sfx('err');return;}if(!spend(N.cost))return;m.fab=f;toast(tr('{ix} now runs a {fab} fabric.
Room for {max} members. Expect a few more to join.',{ix:esc(m.name),fab:N.n,max:N.max}),'good');m.next=Math.min(m.next,S.day+3);after();}, foundIx:({city})=>{if(!S.pops[city]||S.myIx[city]||CITY[city].ix||CITY[city].cn)return;if(!spend(MYIX_COST))return;const nm=(S.name.split(' ')[0]||'My').replace(/[^A-Za-z0-9]/g,'').slice(0,10)+'-IX '+CITY[city].name; S.myIx[city]={name:nm,members:[],next:S.day+4};S.ixp[city]=2;toast(tr('You founded {ix}!
Networks will join over time and pay you for ports. Open members peer with you for free.',{ix:esc(nm)}),'goal');after();}, - buildLink:({tier})=>{tier=+tier;const p=UI.pending;if(!p)return;const {a,b}=p;const km=kmBetween(a,b),sub=isSub(a,b),sib=pairLinks(a,b).filter(l=>l.kind!=='vxc'),same=sib.length>0&&UI.route==='same',border=cnCity(a)!==cnCity(b),mult=(sib.length&&!same?DIVERSE:1)*(border?3*(UI.cnPrem&&(a==='hkg'||b==='hkg')?1.6:1):1); + buildLink:({tier})=>{tier=+tier;const p=UI.pending;if(!p)return;const {a,b}=p;const km=kmBetween(a,b),sub=isSub(a,b),sib=pairLinks(a,b).filter(l=>l.kind!=='vxc'),jn=sib.length?routeJoin(a,b):null,same=!!jn,border=cnCity(a)!==cnCity(b),mult=(sib.length&&!(jn&&jn.k===(landTrenches(a,b)[0]||{}).k)?DIVERSE:1)*(border?3*(UI.cnPrem&&(a==='hkg'||b==='hkg')?1.6:1):1); if((cnCity(a)||cnCity(b))&&!cnOk())return; if(!waveOk(a,b,tier)){toast(tr('A {wave} wave needs {need} routers at both ends.',{wave:LT[tier].n,need:esc(waveNeed(tier))}),'bad');sfx('err');return;} const wr=waveRoute(a,b,mult,border);if(!wr){toast(tr('No cable available for that route right now.'),'bad');sfx('err');return;}{const w=subWaveWhy(tier,wr.km,wr.sub);if(w){toast(tr('No {wave} waves on this cable.
{why}',{wave:LT[tier].n,why:esc(w)}),'bad');sfx('err');return;}}const base=Math.round(waveMo(wr.km,wr.sub,tier)*wr.wm),cost=base+(S.pops[b]?0:popCost(b)); if(!portGate(a,1)||!portGate(b,1))return;if(!spend(cost))return;if(!S.pops[b])S.pops[b]={day:S.day,bb:null,boost:0,down:0,routers:1,gen:false}; - const id=uid();const l={id,a,b,kind:'wave',border,premium:border&&!!UI.cnPrem&&(a==='hkg'||b==='hkg'),tier,km:wr.km,sub:wr.sub,cable:wr.cab,mo:base,mult:wr.wm,trench:wr.cab?'cab:'+wr.cab:(same?(sib[0].trench||sib[0].id):id),cut:0,day:S.day};S.links.push(l);closeModal(); + const id=uid();const l={id,a,b,kind:'wave',border,premium:border&&!!UI.cnPrem&&(a==='hkg'||b==='hkg'),tier,km:wr.km,sub:wr.sub,cable:wr.cab,mo:base,mult:wr.wm,trench:wr.cab?'cab:'+wr.cab:(jn?jn.k:id),cut:0,day:S.day};S.links.push(l);closeModal(); if(sib.length){UI.sel={type:'link',id};}else{UI.sel={type:'city',id:b};UI.tab='cust';} floater((CITY[a].x+CITY[a].x+wrapDx(CITY[a].x,CITY[b].x))/2,(CITY[a].y+CITY[b].y)/2-20,tr('{wave} lit!',{wave:LT[tier].n}),'#FF4F9A');after();}, buyNni:({city,prov,tier})=>{tier=+tier;if(!NNI[tier]||!isCity(city)||!own(FAB,prov)||!FAB[prov].cities.includes(city)||!S.pops[city])return;const ex=nniPort(city,prov);if(ex&&tier<=ex.tier)return;if(!ex&&!portGate(city,1))return;if(ex&&nniUsed(city,prov)>NNI[tier].g){toast(tr('Too many circuits for a smaller port.'),'bad');return;}if(!spend(NNI[tier].mo))return;if(ex)ex.tier=tier;else S.nni.push({id:uid(),city,prov,tier});toast(tr('{fab} port is up in {city}.
Now order virtual circuits to other cities on their fabric.',{fab:esc(FAB[prov].name),city:CITY[city].name}),'good');after();}, @@ -2789,6 +2789,11 @@ const ACT={ updateLater:()=>{$('update').hidden=true;UI.updLater=Date.now();}, helpClose:()=>{if(UI.started)closeModal();else showTitle();}, }; +// Overland routes already dug between two cities, in the order they were built (#77). The first is the +// main route; every other one was a diverse route and keeps that price when you add waves to it. +function landTrenches(a,b){const out=[];for(const l of pairLinks(a,b)){if(l.kind==='vxc'||l.cable||l.sub)continue;const k=l.trench||l.id;let t=out.find(x=>x.k===k);if(!t)out.push(t={k,n:0,caps:[]});t.n++;t.caps.push(capName(l));}return out;} +// Which route a new wave joins: null = a new diverse route. 'same' is the old two-way choice (the main route). +function routeJoin(a,b){const ts=landTrenches(a,b),r=UI.route||'';if(r==='same')return ts[0]||null;if(r.startsWith('t:'))return ts.find(t=>t.k===r.slice(2))||null;return null;} function pairLinks(a,b){return S.links.filter(l=>(l.a===a&&l.b===b)||(l.a===b&&l.b===a));} // Short, busy subsea routes (London–Amsterdam, London–Paris) sell dark fiber pairs too. function subDfCable(a,b){return cablesOk(a,b).filter(c=>CAB[c.cid].df).sort((x,y)=>x.km-y.km)[0]||null;} @@ -3558,10 +3563,10 @@ function openLinkModal(a,b){ if([a,b].includes('kyv')&&[a,b].includes('mos')){openModal(`

${tr('Not happening')}

${tr('Nobody sells capacity between Kyiv and Moscow, and nobody is going to. Route through Warsaw, Bucharest or Helsinki instead.')}

`);return;} if((cnCity(a)||cnCity(b))&&!cnOk()){openModal(`

${tr('Not without a license')}

${tr('Building into mainland China needs a joint venture and an operating license. Open {city} to apply.',{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:popCost(b),sib=pairLinks(a,b).filter(l=>l.kind!=='vxc'); - if(!sib.length)UI.route='diverse';const border=cnCity(a)!==cnCity(b),same=sib.length>0&&UI.route==='same',mult=(sib.length&&!same?DIVERSE:1)*(border?3*(UI.cnPrem&&(a==='hkg'||b==='hkg')?1.6:1):1); + 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); if(border)route+=`

${tr('Cross-border circuits into mainland China are sold only by licensed carriers, at 3× the price. Regular ones lose about 20% of traffic at the border.')}

${a==='hkg'||b==='hkg'?`
${btn(tr('Regular crossing'),'cnPrem',{v:0},!UI.cnPrem?'pink':'ghost')}${btn(tr('Premium crossing +60% · ~3% loss'),'cnPrem',{v:1},UI.cnPrem?'pink':'ghost')}
`:`

${tr('Premium crossings are only sold in Hong Kong.')}

`}`; if(sib.length&&!(isSub(a,b)&&cablesFor(a,b).length)&&!(UI.via&&UI.via!=='land'&&cablesFor(a,b).some(c=>c.cid===UI.via))){route+=`

${trn('You already have {n} link here ({list}). Parallel links add capacity. How should this one be routed?','You already have {n} links here ({list}). Parallel links add capacity. How should this one be routed?',sib.length,{list:sib.map(l=>capName(l)).join(', ')})}

-
${btn(tr('Diverse route +40% · survives cuts alone'),'route',{r:'diverse'},UI.route!=='same'?'pink':'ghost')}${btn(tr('Same trench cheaper · one backhoe cuts all'),'route',{r:'same'},UI.route==='same'?'pink':'ghost')}
`;} +
${ts.length>1?ts.map((t,i)=>btn(`${i?tr('Diverse route {n}',{n:i}):tr('Main route')} ${esc(t.caps.join(', '))}${i?' · +40%':''}`,'route',{r:'t:'+t.k},jn&&jn.k===t.k?'pink':'ghost')).join('')+btn(tr('New diverse route +40% · survives cuts alone'),'route',{r:'diverse'},!jn?'pink':'ghost'):btn(tr('Diverse route +40% · survives cuts alone'),'route',{r:'diverse'},!jn?'pink':'ghost')+btn(tr('Same trench cheaper · one backhoe cuts all'),'route',{r:'same'},jn?'pink':'ghost')}
${ts.length>1?`

${tr('Waves on the same route share its fate: one backhoe cuts them all.')}

`:''}`;} const mode=UI.lmode==='df'?'df':'wave',tabs=`
${btn(tr('Lease a wave'),'dfMode',{m:'wave'},mode==='wave'?'pink':'ghost')}${btn(tr('Dark fiber'),'dfMode',{m:'df'},mode==='df'?'pink':'ghost')}
`; const head=`
${sub?tr('Subsea'):tr('Terrestrial')} · ${km.toLocaleString()} km

${CITY[a].name} → ${CITY[b].name}

${tabs}`; if(mode==='df'){openModal(head+dfModalBody(a,b,km,pop));return;} diff --git a/tests/issues.test.js b/tests/issues.test.js index c33267d..3247565 100644 --- a/tests/issues.test.js +++ b/tests/issues.test.js @@ -904,3 +904,30 @@ test('opening a link on desktop keeps the NOC sidebar available', () => { assert.deepEqual(errors, []); dom.window.close(); }); + +test('#77 waves can join any route already dug between two cities', () => { + 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.buildPop({city:'ams'})"); + const add = r => ev(`UI.via=null;UI.lmode='wave';UI.route=${JSON.stringify(r)};openLinkModal('fra','ams');ACT.buildLink({tier:1});closeModal()`); + add('diverse'); // first wave: the main route + add('diverse'); // second: a diverse route + const ts = () => JSON.parse(ev("JSON.stringify(landTrenches('fra','ams').map(t=>[t.k,t.n]))")); + assert.equal(ts().length, 2); + const [main, div] = ts().map(t => t[0]); + // the old two-way choice still works, and two routes now show a button each + ev("UI.route='diverse';openLinkModal('fra','ams')"); + assert.equal(ev("document.querySelectorAll('#modalCard [data-act=route]').length"), 3, 'main, diverse 1 and a new one'); + ev("closeModal()"); + add('t:' + main); // third: on the main route + add('t:' + div); // fourth: on the diverse route + assert.deepEqual(ts().map(t => t[1]), [2, 2], 'two waves on each route'); + // prices follow the route: the main route at list price, a diverse one at +40% + const w = id => ev(`S.links.filter(l=>l.kind==='wave').map(l=>l.mult)[${id}]`); + assert.ok(Math.abs(w(2) - w(0)) < 1e-9, 'joining the main route costs like the main route'); + assert.ok(Math.abs(w(3) - w(1)) < 1e-9, 'joining the diverse route costs like the diverse route'); + assert.ok(w(1) > w(0) * 1.3); + // a route id from another pair falls back to a new diverse route + add('t:nonsense'); + assert.equal(ts().length, 3); + assert.deepEqual(errors, []); +});