innerWidth>760&&innerWidth<=1200;
@@ -3186,9 +3188,9 @@ function cityPanel(c){
${tr('Forwarding chip')}${esc(G.chip)}
${tr('Boot time')}${slowBoot(c)?`${tr('~{n} min · a slow one',{n:bootMin(c)})}`:tr('~{n} min',{n:bootMin(c)})}
${slowBoot(c)?`${tr('This chassis takes forever to boot: crashes last longer, and swapping the only router here takes 3 days. A second router hides it.')}
`:''}
${tr('Forwarding load')}${fmtG(nl)} / ${fmtG(nc)}
${nl>=nc*0.95?`${tr('Maxed out. Traffic here is being dropped.')}
`:''}
- ${N?btn(N.lvl>lvl()?tr('{model} level {lv}',{model:esc(N.n),lv:N.lvl}):tr('Upgrade to {model} {cost} + {mo}/mo',{model:esc(N.n),cost:fmt$(N.cost*rt),mo:fmt$(N.mo*rt)}),'upRouter',{city:c,g:Ni},'pink',N.lvl>lvl()||S.cash{cost} + {mo}/mo',{cost:fmt$(routerCost(g)),mo:fmt$(ROUTER_MO+G.mo)}),'addRouter',{city:c},'',S.cash1?btn(tr('Remove one'),'rmRouter',{city:c},'ghost sm'):''}
+ ${N?btn(N.lvl>lvl()?tr('{model} level {lv}',{model:esc(N.n),lv:N.lvl}):tr('Upgrade to {model} {cost} + {mo}/mo',{model:esc(N.n),cost:fmt$(swapCost(c,Ni)),mo:fmt$(N.mo*rt)}),'upRouter',{city:c,g:Ni},'pink',N.lvl>lvl()||S.cash{cost} + {mo}/mo',{cost:fmt$(routerCost(g)),mo:fmt$(ROUTER_MO+G.mo)}),'addRouter',{city:c},'',S.cash1?btn(tr('Remove one'),'rmRouter',{city:c},'ghost sm'):''}
${UI.models?routerModels(c):''}
- ${N||UI.models?`${rt>1?tr('Rolling upgrade: one router at a time, no downtime.'):tr('With one router, the upgrade needs a maintenance window: this POP goes dark for a day.')}
`:''}
+ ${N||UI.models?`${(p.rgen||0)>0?tr('Prices include {p} back for the old routers on eBuy.',{p:fmt$(tradeIn(p.rgen||0,rt))})+' ':''}${p.rupDay===S.day?tr('New routers went in today. The next swap can wait until tomorrow.')+' ':''}${rt>1?tr('Rolling upgrade: one router at a time, no downtime.'):tr('With one router, the upgrade needs a maintenance window: this POP goes dark for a day.')}
`:''}
${rt>=2?tr('A crash here only costs one router’s capacity for a few days.'):tr('One router is a single point of failure.')}
${tr('Metro diversity')}
${p.site2?(()=>{const up=s=>[...S.transit.filter(t=>t.city===c&&onSite(t.site,s)).map(t=>tr('{net} transit',{net:NET[t.net].name})+(t.site==='ab'?' '+tr('(split)'):'')),...S.pni.filter(x=>x.city===c&&onSite(x.site,s)).map(x=>'PNI '+NET[x.net].name+(x.site==='ab'?' '+tr('(split)'):'')),...ixIdsIn(c).filter(x=>S.ixp[x]!==undefined&&!S.myIx[x]&&onSite((S.ixSite||{})[x],s)).map(x=>tr('{port} port',{port:ixName(x)})+((S.ixSite||{})[x]==='ab'?' '+tr('(split)'):'')),...S.caches.filter(x=>x.city===c&&(x.site==='b'?'b':'a')===s).map(x=>NET[x.net].cache.name)];
const row=s=>{const dn=siteDown(c,s),u=up(s);return `${s.toUpperCase()}${esc(siteName(c,s))}${dn?' DOWN':''}
${u.length?esc(u.join(', ')):tr('Nothing plugged in here yet')}
`;};
@@ -3894,14 +3896,17 @@ function drawCables(ks){const z=cam.z,selC=UI.drag&&UI.drag.mode==='link'?UI.dra
ctx.globalAlpha=1;}}}
function bezGeom(l,at){const A=CITY[l.a],B=CITY[l.b];const i=at!==undefined?at:lineIdx(l);const key=l.id+'|b'+i;const hit=GEO.get(key);if(hit)return hit;
const bx=A.x+wrapDx(A.x,B.x),by=B.y;const dx=bx-A.x,dy=by-A.y,len=Math.hypot(dx,dy)||1;let nx=-dy/len,ny=dx/len;if(ny>0){nx=-nx;ny=-ny;}
- const base=Math.max(10,Math.min(len*0.13,110)),step=Math.min(16,len*.06),off0=i<=0?base:(i%2?-1:1)*(base*(i%2?0.2:1)+Math.ceil(i/2)*step);
+ const base=Math.max(4,Math.min(len*0.1,90)),step=Math.min(16,len*.06),off0=i<=0?base:(i%2?-1:1)*(base*(i%2?0.2:1)+Math.ceil(i/2)*step);
const mx=(A.x+bx)/2,my=(A.y+by)/2;
const obs=CITIES.filter(c=>c.id!==l.a&&c.id!==l.b).map(c=>[mx+wrapDx(mx,c.x),c.y]);
const clear=(cx,cy)=>{let m=Infinity;const g={ax:A.x,ay:A.y,bx,by,cx,cy};for(let t=0.08;t<0.93;t+=0.06){const [px,py]=qpt(g,t);for(const [ox,oy] of obs){const d=Math.hypot(px-ox,py-oy);if(dsg*mag*k).concat([1,1.5,2.1,2.9,3.8].map(k=>-sg*Math.max(mag,base)*k));
- let best=null,bc=-1;
- for(const off of cand){const cx=mx+nx*off,cy=my+ny*off,c=clear(cx,cy);if(c>=24){best=[cx,cy];break;}if(c>bc){bc=c;best=[cx,cy];}}
+ // Bend around cities in the way, but gently: short links need less room, no curve bows out more than about a
+ // third of its length, and when nothing clears, a modest curve beats a giant loop around the neighbourhood.
+ const need=Math.min(24,Math.max(7,len*0.2)),cap=Math.max(mag,len*0.32),lim=o=>Math.sign(o)*Math.min(Math.abs(o),cap);
+ const cand=[1,1.5,2.1,2.9,3.8].map(k=>lim(sg*mag*k)).concat([1,1.5,2.1,2.9,3.8].map(k=>lim(-sg*Math.max(mag,base)*k)));
+ let best=null,bs=-Infinity;
+ for(const off of cand){const cx=mx+nx*off,cy=my+ny*off,c=clear(cx,cy);if(c>=need){best=[cx,cy];break;}const sc=Math.min(c,need)-Math.abs(off)*0.35;if(sc>bs){bs=sc;best=[cx,cy];}}
const g={ax:A.x,ay:A.y,bx,by,cx:best[0],cy:best[1],len};GEO.set(key,g);return g;}
const qpt=(g,t)=>[(1-t)*(1-t)*g.ax+2*(1-t)*t*g.cx+t*t*g.bx,(1-t)*(1-t)*g.ay+2*(1-t)*t*g.cy+t*t*g.by];
const utilCol=u=>u<=0.001?'#AFC0D6':u<0.65?'#22C47A':u<0.9?'#FFAA1F':'#FF4D5E';
diff --git a/tests/issues.test.js b/tests/issues.test.js
index 2d4d27b..bdc84a8 100644
--- a/tests/issues.test.js
+++ b/tests/issues.test.js
@@ -991,3 +991,36 @@ test('#63 incidents you can fix with one click sit above hot ports in the NOC',
assert.ok(t.indexOf('DDoS scrubbing') > fix, 'status lines come after the incidents');
assert.deepEqual(errors, []);
});
+
+test('#82 router swaps trade in the old gear, one swap a day, and requirements name the speed', () => {
+ const { ev, errors } = load();
+ ev("ACT.start({});S.cash=1e8;S.lvl=4;for(const g of GOALS)S.done[g.id]=0;ACT.launchBB({city:'fra'});S.pops.fra.rgen=1;S.pops.fra.routers=2");
+ const c0 = ev('S.cash'), back = ev('tradeIn(1,2)');
+ assert.equal(back, Math.round(ev('RG[1].cost') * 2 * 0.3));
+ ev("ACT.upRouter({city:'fra',g:2})");
+ assert.equal(ev('S.pops.fra.rgen'), 2);
+ assert.equal(c0 - ev('S.cash'), ev('RG[2].cost') * 2 - back, 'you pay the new routers minus the old ones sold on eBuy');
+ // a double click does not chain a second upgrade
+ ev("ACT.upRouter({city:'fra',g:3})");
+ assert.equal(ev('S.pops.fra.rgen'), 2, 'one swap a day');
+ ev("S.day++;ACT.upRouter({city:'fra',g:3})");
+ assert.equal(ev('S.pops.fra.rgen'), 3);
+ // removing a router sells it too
+ const c1 = ev('S.cash');
+ ev("ACT.rmRouter({city:'fra'})");
+ assert.equal(ev('S.cash') - c1, ev('tradeIn(3,1)'));
+ // requirements say the speed, not one model
+ ev("ACT.buildPop({city:'ams'});S.pops.ams.rgen=0;S.links.push({id:'df',a:'fra',b:'ams',kind:'df',km:450,sys:'roadm',ch:[],ready:0,mo:1,day:0,cut:0});compute()");
+ assert.match(ev("chWhy(S.links.find(l=>l.id==='df'),'tp16')"), /routers with 800G ports or bigger/);
+ assert.equal(ev('waveNeed(4)'), '1.6T routers');
+ assert.deepEqual(errors, []);
+});
+
+test('fiber between nearby cities bends gently instead of looping around the neighbourhood', () => {
+ const { ev, errors } = load();
+ ev("ACT.start({});S.cash=1e9;for(const g of GOALS)S.done[g.id]=0;for(const x of ['tor','ott','mtl','nyc','ash'])if(!S.pops[x])ACT.buildPop({city:x})");
+ ev("const L=(a,b)=>{UI.via=null;UI.lmode='wave';UI.route='diverse';openLinkModal(a,b);ACT.buildLink({tier:1});closeModal();};L('tor','ott');L('ott','mtl');L('tor','nyc');L('tor','mtl');L('mtl','nyc');L('tor','ash');L('ash','nyc');GEO.clear()");
+ const worst = ev("Math.max(...S.links.map(l=>{const g=linkGeom(l),A=CITY[l.a],B=CITY[l.b],L=Math.hypot(B.x-A.x,B.y-A.y);return Math.max(...g.pts.map(p=>segDist(p[0],p[1],[A.x,A.y],[B.x,B.y])))/L;}))");
+ assert.ok(worst < 0.3, `worst bend is ${worst.toFixed(2)}× its length`);
+ assert.deepEqual(errors, []);
+});
diff --git a/tests/levels.test.js b/tests/levels.test.js
index 41fdf4d..150efe3 100644
--- a/tests/levels.test.js
+++ b/tests/levels.test.js
@@ -53,9 +53,9 @@ test('new routers: the 3.2T main line, side-grades, and 3.2T ports only once unl
assert.equal(ev('waveShown(6)'), true);
ev("S.pops.fra.rgen=3;S.pops.fra.routers=1;ACT.upRouter({city:'fra'})");
assert.equal(ev("RG[S.pops.fra.rgen].n"), 'Absolute Unit 3.2T');
- ev("const g=RG.findIndex(r=>r.lvl===13);ACT.upRouter({city:'fra',g})");
+ ev("S.day++;const g=RG.findIndex(r=>r.lvl===13);ACT.upRouter({city:'fra',g})");
assert.equal(ev("RG[S.pops.fra.rgen].n"), 'Absolute Unit 3.2T', 'the Router at the End of the Universe waits for level 13');
- ev("S.lvl=13;ACT.upRouter({city:'fra',g:RG.findIndex(r=>r.lvl===13)})");
+ ev("S.lvl=13;S.day++;ACT.upRouter({city:'fra',g:RG.findIndex(r=>r.lvl===13)})");
assert.equal(ev("RG[S.pops.fra.rgen].ports"), 256);
// every model's numbers make sense for its class
assert.equal(ev("RG.every(r=>PORT[r.maxP]&<[r.maxLT]&&r.pn===PORT[r.maxP].n&&r.lvl>=1&&r.lvl<=LEVELS.length)"), true);