Light up very long dark fiber with long-haul modes and regen sites

Optics past their full-rate reach now drop to a slower, longer-reaching
modulation instead of refusing to fit, so fibers over 4,000 km are usable.
Regeneration sites split a route into shorter optical spans for full speed,
at a cost per site and per channel. The order screen warns about routes
longer than any optic's full-rate reach.

Closes #17
Closes #30
This commit is contained in:
Frederic Jung 2026-10-24 21:46:48 +02:00
parent 7457acef1e
commit 71dbc6e37b
No known key found for this signature in database
3 changed files with 55 additions and 12 deletions

View file

@ -6,6 +6,12 @@ All notable changes to this project are documented here. The project follows
## [Unreleased] ## [Unreleased]
- Very long dark fiber works now (#17, #30). Optics drop to a slower, longer-
reaching setting past their full-rate reach: the 1.6T transponder runs at
800G to 7,000 km and 400G to 12,000 km, and ZR+ optics halve their speed
to double their reach. Regeneration sites go further: each one turns the
light back into bits and sends it on fresh, so optics only have to reach
the next site. Existing long fibers light up without changes.
- "Quietest links" routing no longer flips between two paths every day. It - "Quietest links" routing no longer flips between two paths every day. It
judges how busy a link is without the customer's own traffic, splits the judges how busy a link is without the customer's own traffic, splits the
circuit over two paths that are about as quiet, and keeps yesterday's circuit over two paths that are about as quiet, and keeps yesterday's

View file

@ -538,9 +538,9 @@ const DF_SYS={
}; };
const AMP_EVERY=100, AMP_COST=8000, AMP_MO=300; const AMP_EVERY=100, AMP_COST=8000, AMP_MO=300;
const OPT={ const OPT={
zr4:{n:'Ackackia 400ZR+',g:400,cost:12000,reach:1500,rg:1,lvl:2,sys:'lite',blurb:'Coherent pluggable in the router. No transponder shelf.'}, zr4:{n:'Ackackia 400ZR+',g:400,cost:12000,reach:1500,modes:[[400,1500],[200,3000]],rg:1,lvl:2,sys:'lite',blurb:'Coherent pluggable in the router. No transponder shelf.'},
zr8:{n:'Sizzle 800ZR+',g:800,cost:22000,reach:900,rg:2,lvl:3,sys:'lite',blurb:'Twice the speed, shorter reach.'}, zr8:{n:'Sizzle 800ZR+',g:800,cost:22000,reach:900,modes:[[800,900],[400,1800],[200,3600]],rg:2,lvl:3,sys:'lite',blurb:'Twice the speed, shorter reach.'},
tp16:{n:'Sienna WaveMagic 1.6T',g:1600,cost:70000,reach:4000,rg:2,lvl:4,sys:'roadm',blurb:'Big shelf, big reach, big invoice.'}, tp16:{n:'Sienna WaveMagic 1.6T',g:1600,cost:70000,reach:4000,modes:[[1600,4000],[800,7000],[400,12000]],rg:2,lvl:4,sys:'roadm',blurb:'Big shelf, big reach, big invoice.'},
}; };
const dfLeaseMo=km=>Math.round(400+km*1.0); const dfLeaseMo=km=>Math.round(400+km*1.0);
const dfBuildCost=km=>Math.round(25000+km*120); const dfBuildCost=km=>Math.round(25000+km*120);
@ -563,10 +563,18 @@ const vxcMo=(km,sub,t)=>Math.round((150+km*0.12)*VXC[t].m*(sub?2:1));
const MET={prefer:{l:'Prefer',f:0.5},normal:{l:'Normal',f:1},avoid:{l:'Avoid',f:4},backup:{l:'Backup only',f:60}}; const MET={prefer:{l:'Prefer',f:0.5},normal:{l:'Normal',f:1},avoid:{l:'Avoid',f:4},backup:{l:'Backup only',f:60}};
const PREF={high:'Prefer',normal:'Normal',low:'Backup only'}; const PREF={high:'Prefer',normal:'Normal',low:'Backup only'};
const edgeKey=l=>l.a<l.b?l.a+'|'+l.b:l.b+'|'+l.a; const edgeKey=l=>l.a<l.b?l.a+'|'+l.b:l.b+'|'+l.a;
const dfCap=l=>{if(l.ready>S.day||l.eqDown>S.day)return 0;const ch=l.ch||[];let g=0;for(const c of ch)g+=OPT[c].g;const f=l.chFail&&l.chFail.until>S.day?l.chFail:null;if(f){const fo=f.o&&ch.includes(f.o)?f.o:ch.slice().sort((a,b)=>OPT[a].g-OPT[b].g)[0];if(fo)g-=OPT[fo].g;}return Math.max(0,g);}; /* Reach (#17, #30). Coherent optics trade speed for distance: past full-rate reach they drop to a
slower, more robust modulation. Regeneration sites go further: each one turns the light back into
bits and sends it on fresh, so every optical span is shorter. Each site needs a regen card per channel. */
const REGEN_COST=30000,REGEN_MO=900,REGEN_CH=0.5,REGEN_MAX=8;
const spanKm=l=>Math.ceil(l.km/((l.regen|0)+1));
function optMode(o,l){const O=OPT[o],km=spanKm(l);for(const [g,r] of O.modes||[[O.g,O.reach]])if(km<=r)return {g,reach:r,full:g===O.g};return null;}
const optG=(o,l)=>{const m=optMode(o,l);return m?m.g:0;};
const regenNeed=(o,l)=>Math.max(0,Math.ceil(l.km/OPT[o].reach)-1);
const dfCap=l=>{if(l.ready>S.day||l.eqDown>S.day)return 0;const ch=l.ch||[];let g=0;for(const c of ch)g+=optG(c,l);const f=l.chFail&&l.chFail.until>S.day?l.chFail:null;if(f){const fo=f.o&&ch.includes(f.o)?f.o:ch.slice().sort((a,b)=>optG(a,l)-optG(b,l))[0];if(fo)g-=optG(fo,l);}return Math.max(0,g);};
const capOf=l=>(l.kind==='vxc'?VXC[l.vt].g:l.kind==='df'?dfCap(l):LT[l.tier].g)*(l.deg>S.day?0.5:1); const capOf=l=>(l.kind==='vxc'?VXC[l.vt].g:l.kind==='df'?dfCap(l):LT[l.tier].g)*(l.deg>S.day?0.5:1);
const tierW=l=>{if(l.kind==='wave')return l.tier;if(l.kind==='vxc')return 0;const g=dfCap(l);return g>=6400?4:g>=1600?3:g>=400?2:g>=100?1:0;}; const tierW=l=>{if(l.kind==='wave')return l.tier;if(l.kind==='vxc')return 0;const g=dfCap(l);return g>=6400?4:g>=1600?3:g>=400?2:g>=100?1:0;};
const capName=l=>l.kind==='vxc'?VXC[l.vt].n:l.kind==='df'?(l.ready>S.day?'building':(l.ch||[]).length?fmtCap(dfCap(l)||(l.ch||[]).reduce((a,c)=>a+OPT[c].g,0))+' DF':'dark'):LT[l.tier].n; const capName=l=>l.kind==='vxc'?VXC[l.vt].n:l.kind==='df'?(l.ready>S.day?'building':(l.ch||[]).length?fmtCap(dfCap(l)||(l.ch||[]).reduce((a,c)=>a+optG(c,l),0))+' DF':'dark'):LT[l.tier].n;
/* ================= WORLD ================= */ /* ================= WORLD ================= */
// Simplified real geography: lon/lat outlines, equirectangular, with gentle "magnifying lenses" over the busy regions. // Simplified real geography: lon/lat outlines, equirectangular, with gentle "magnifying lenses" over the busy regions.
@ -1542,7 +1550,7 @@ function compute(){
// money // money
const C=R2.cost,V=R2.rev,pm=S.priceMul; const C=R2.cost,V=R2.rev,pm=S.priceMul;
C.pops=Object.values(S.pops).reduce((a,p)=>a+POP_MO+((p.routers||1)-1)*ROUTER_MO+(p.routers||1)*RG[p.rgen||0].mo+(p.gen?GEN_MO:0),0); C.pops=Object.values(S.pops).reduce((a,p)=>a+POP_MO+((p.routers||1)-1)*ROUTER_MO+(p.routers||1)*RG[p.rgen||0].mo+(p.gen?GEN_MO:0),0);
C.optical=S.links.filter(l=>l.kind==='df').reduce((a,l)=>a+(l.ready>S.day?0:ampCount(l.km)*AMP_MO)+(l.spares?Math.round(150+(l.ch||[]).length*80):0),0); C.optical=S.links.filter(l=>l.kind==='df').reduce((a,l)=>a+(l.ready>S.day?0:ampCount(l.km)*AMP_MO+(l.regen|0)*REGEN_MO)+(l.spares?Math.round(150+(l.ch||[]).length*80):0),0);
C.links=S.links.reduce((a,l)=>a+(l.mo||0),0); C.links=S.links.reduce((a,l)=>a+(l.mo||0),0);
C.nni=(S.nni||[]).reduce((a,x)=>a+NNI[x.tier].mo,0); C.nni=(S.nni||[]).reduce((a,x)=>a+NNI[x.tier].mo,0);
C.transit=S.transit.reduce((a,t)=>{const q=p95(t,R2.useT[t.id]||0);R2.p95[t.id]=q;const n=t.n||1;return a+Math.max(q,PORT[t.tier].g*n*0.2)*NET[t.net].price*(t.premium&&t.city==='hkg'?NET[t.net].premium:1)*pm*regionMult(t.city)+PORT[t.tier].tmo*n;},0); C.transit=S.transit.reduce((a,t)=>{const q=p95(t,R2.useT[t.id]||0);R2.p95[t.id]=q;const n=t.n||1;return a+Math.max(q,PORT[t.tier].g*n*0.2)*NET[t.net].price*(t.premium&&t.city==='hkg'?NET[t.net].premium:1)*pm*regionMult(t.city)+PORT[t.tier].tmo*n;},0);
@ -1582,7 +1590,7 @@ function sanitize(s){
for(const c of Object.keys(s.pops)){const p=s.pops[c];if(!isCity(c)||!p||typeof p!=='object'){delete s.pops[c];continue;}p.routers=int(p.routers,1,RMAX,1);if(p.rgen!==undefined)p.rgen=int(p.rgen,0,RG.length-1,0);p.down=num(p.down,0);if(p.bb&&typeof p.bb==='object')p.bb.d=num(p.bb.d,0);else p.bb=null;} for(const c of Object.keys(s.pops)){const p=s.pops[c];if(!isCity(c)||!p||typeof p!=='object'){delete s.pops[c];continue;}p.routers=int(p.routers,1,RMAX,1);if(p.rgen!==undefined)p.rgen=int(p.rgen,0,RG.length-1,0);p.down=num(p.down,0);if(p.bb&&typeof p.bb==='object')p.bb.d=num(p.bb.d,0);else p.bb=null;}
if(!isCity(s.home))s.home=Object.keys(s.pops)[0]||'fra'; if(!isCity(s.home))s.home=Object.keys(s.pops)[0]||'fra';
const tier=v=>int(v,0,PORT.length-1,0),lag=v=>int(v,1,LAG_MAX,1),sid=v=>String(v==null?uid():v).slice(0,40); const tier=v=>int(v,0,PORT.length-1,0),lag=v=>int(v,1,LAG_MAX,1),sid=v=>String(v==null?uid():v).slice(0,40);
s.links=s.links.filter(l=>l&&isCity(l.a)&&isCity(l.b)&&l.a!==l.b).map(l=>{l.id=sid(l.id);l.km=num(l.km,kmBetween(l.a,l.b));l.mo=num(l.mo,0);l.cut=num(l.cut,0);if(l.kind!=='df'&&l.kind!=='vxc')l.kind='wave';if(l.kind==='wave')l.tier=int(l.tier,0,LT.length-1,0);if(l.cable&&!own(CAB,l.cable))l.cable=null;if(l.kind==='vxc'&&!own(VXC,l.vt))l.vt=0;if(l.kind==='df'){if(!own(DF_SYS,l.sys))l.sys='lite';l.ch=Array.isArray(l.ch)?l.ch.filter(o=>own(OPT,o)):[];l.ready=num(l.ready,0);}if(l.metric&&!own(MET,l.metric))l.metric='normal';return l;}); s.links=s.links.filter(l=>l&&isCity(l.a)&&isCity(l.b)&&l.a!==l.b).map(l=>{l.id=sid(l.id);l.km=num(l.km,kmBetween(l.a,l.b));l.mo=num(l.mo,0);l.cut=num(l.cut,0);if(l.kind!=='df'&&l.kind!=='vxc')l.kind='wave';if(l.kind==='wave')l.tier=int(l.tier,0,LT.length-1,0);if(l.cable&&!own(CAB,l.cable))l.cable=null;if(l.kind==='vxc'&&!own(VXC,l.vt))l.vt=0;if(l.kind==='df'){if(!own(DF_SYS,l.sys))l.sys='lite';l.ch=Array.isArray(l.ch)?l.ch.filter(o=>own(OPT,o)):[];l.ready=num(l.ready,0);l.regen=int(l.regen,0,REGEN_MAX,0);}if(l.metric&&!own(MET,l.metric))l.metric='normal';return l;});
s.transit=s.transit.filter(t=>t&&isCity(t.city)&&isNet(t.net)).map(t=>(t.site=['a','b','ab'].includes(t.site)?t.site:'a',t.id=sid(t.id),t.tier=tier(t.tier),t.n=lag(t.n),t.down=num(t.down,0),t)); s.transit=s.transit.filter(t=>t&&isCity(t.city)&&isNet(t.net)).map(t=>(t.site=['a','b','ab'].includes(t.site)?t.site:'a',t.id=sid(t.id),t.tier=tier(t.tier),t.n=lag(t.n),t.down=num(t.down,0),t));
s.pni=s.pni.filter(x=>x&&isCity(x.city)&&isNet(x.net)).map(x=>(x.site=['a','b','ab'].includes(x.site)?x.site:'a',x.id=sid(x.id),x.tier=tier(x.tier),x.n=lag(x.n),x)); s.pni=s.pni.filter(x=>x&&isCity(x.city)&&isNet(x.net)).map(x=>(x.site=['a','b','ab'].includes(x.site)?x.site:'a',x.id=sid(x.id),x.tier=tier(x.tier),x.n=lag(x.n),x));
s.caches=s.caches.filter(x=>x&&isCity(x.city)&&isNet(x.net)&&NET[x.net].cache).map(x=>(x.id=sid(x.id),x)); s.caches=s.caches.filter(x=>x&&isCity(x.city)&&isNet(x.net)&&NET[x.net].cache).map(x=>(x.id=sid(x.id),x));
@ -2219,7 +2227,10 @@ const ACT={
const l={id,a,b,kind:'df',own,sys,ch:[],km,sub:!!sc,cable:sc?sc.cid:null,mo:own?Math.round(km*0.15):dfLeaseMo(km),trench:sc?'cab:'+sc.cid:id,cut:0,day:S.day,ready:S.day+(own?dfBuildDays(km):30),spares:false}; const l={id,a,b,kind:'df',own,sys,ch:[],km,sub:!!sc,cable:sc?sc.cid:null,mo:own?Math.round(km*0.15):dfLeaseMo(km),trench:sc?'cab:'+sc.cid:id,cut:0,day:S.day,ready:S.day+(own?dfBuildDays(km):30),spares:false};
S.links.push(l);closeModal();UI.sel={type:'link',id}; S.links.push(l);closeModal();UI.sel={type:'link',id};
toast(own?`<b>Groundbreaking!</b><br>Your own fiber from ${CITY[a].name} to ${CITY[b].name}. Permits and digging take about ${dfBuildDays(km)} days.`:`<b>Dark fiber IRU signed.</b><br>${CITY[a].name}–${CITY[b].name} will be spliced and handed over in about 30 days.`,'goal');after();}, toast(own?`<b>Groundbreaking!</b><br>Your own fiber from ${CITY[a].name} to ${CITY[b].name}. Permits and digging take about ${dfBuildDays(km)} days.`:`<b>Dark fiber IRU signed.</b><br>${CITY[a].name}–${CITY[b].name} will be spliced and handed over in about 30 days.`,'goal');after();},
addCh:({id,o})=>{const l=S.links.find(x=>x.id===id),O=OPT[o];if(!l||!O||l.kind!=='df')return;const why=chWhy(l,o);if(why){toast(`<b>Can't add ${O.n}.</b><br>${esc(why)}`,'bad');sfx('err');return;}if(!portGate(l.a,1)||!portGate(l.b,1))return;if(!spend(optCost(o)))return;(l.ch=l.ch||[]).push(o);floater((CITY[l.a].x+CITY[l.b].x)/2,(CITY[l.a].y+CITY[l.b].y)/2-20,`+${O.n}`,'#FF4F9A');after();}, regen:({id,d})=>{d=+d;const l=S.links.find(x=>x.id===id);if(!l||l.kind!=='df'||(d!==1&&d!==-1))return;const n=(l.regen|0)+d;if(n<0||n>REGEN_MAX)return;
if(d<0&&(l.ch||[]).some(o=>!optMode(o,{km:l.km,regen:n}))){toast('<b>Those optics need the regen site.</b><br>Remove the long-haul channels first, or keep the site.','bad');sfx('err');return;}
if(d>0&&!spend(REGEN_COST+Math.round((l.ch||[]).reduce((a,c)=>a+optCost(c),0)*REGEN_CH)))return;l.regen=n;toast(d>0?`<b>Regen site ${n} is up.</b><br>Optical spans on ${CITY[l.a].name}–${CITY[l.b].name} are now ${spanKm(l).toLocaleString()} km.`:'<b>Regen site removed.</b>','good');sfx('build');after();},
addCh:({id,o})=>{const l=S.links.find(x=>x.id===id),O=OPT[o];if(!l||!O||l.kind!=='df')return;const why=chWhy(l,o);if(why){toast(`<b>Can't add ${O.n}.</b><br>${esc(why)}`,'bad');sfx('err');return;}if(!portGate(l.a,1)||!portGate(l.b,1))return;if(!spend(Math.round(optCost(o)*(1+REGEN_CH*(l.regen|0)))))return;(l.ch=l.ch||[]).push(o);floater((CITY[l.a].x+CITY[l.b].x)/2,(CITY[l.a].y+CITY[l.b].y)/2-20,`+${O.n}`,'#FF4F9A');after();},
rmCh:({id,o})=>{const l=S.links.find(x=>x.id===id);if(!l)return;const i=(l.ch||[]).lastIndexOf(o);if(i>=0)l.ch.splice(i,1);after();}, rmCh:({id,o})=>{const l=S.links.find(x=>x.id===id);if(!l)return;const i=(l.ch||[]).lastIndexOf(o);if(i>=0)l.ch.splice(i,1);after();},
upSys:({id})=>{const l=S.links.find(x=>x.id===id);if(!l||l.sys==='roadm'||lvl()<3)return;if(!spend(DF_SYS.roadm.cost))return;l.sys='roadm';if(l.ready<=S.day){l.eqDown=S.day+1;toast('<b>Line system swap</b><br>All channels are dark for a day while the ROADMs go in.','bad');}after();}, upSys:({id})=>{const l=S.links.find(x=>x.id===id);if(!l||l.sys==='roadm'||lvl()<3)return;if(!spend(DF_SYS.roadm.cost))return;l.sys='roadm';if(l.ready<=S.day){l.eqDown=S.day+1;toast('<b>Line system swap</b><br>All channels are dark for a day while the ROADMs go in.','bad');}after();},
spares:({id})=>{const l=S.links.find(x=>x.id===id);if(!l)return;l.spares=!l.spares;sfx('click');after();}, spares:({id})=>{const l=S.links.find(x=>x.id===id);if(!l)return;l.spares=!l.spares;sfx('click');after();},
@ -2261,7 +2272,7 @@ function pairLinks(a,b){return S.links.filter(l=>(l.a===a&&l.b===b)||(l.a===b&&l
function subDfCable(a,b){return cablesOk(a,b).filter(c=>CAB[c.cid].df).sort((x,y)=>x.km-y.km)[0]||null;} function subDfCable(a,b){return cablesOk(a,b).filter(c=>CAB[c.cid].df).sort((x,y)=>x.km-y.km)[0]||null;}
function dfAllowed(a,b){if(isSub(a,b))return !!subDfCable(a,b);return cnCity(a)===cnCity(b)&&!uaePair(a,b);} function dfAllowed(a,b){if(isSub(a,b))return !!subDfCable(a,b);return cnCity(a)===cnCity(b)&&!uaePair(a,b);}
function optCost(o){return Math.round(OPT[o].cost*(S&&S.ev&&S.ev.tariff>S.day?1.4:1));} function optCost(o){return Math.round(OPT[o].cost*(S&&S.ev&&S.ev.tariff>S.day?1.4:1));}
function chWhy(l,o){const O=OPT[o];if(O.lvl>lvl())return `Unlocks at customer level ${O.lvl}.`;if(O.sys==='roadm'&&l.sys!=='roadm')return 'Needs a ROADMaster 9000 line system.';if(l.km>O.reach)return `Reach is ${O.reach.toLocaleString()} km; this route is ${l.km.toLocaleString()} km.`; function chWhy(l,o){const O=OPT[o];if(O.lvl>lvl())return `Unlocks at customer level ${O.lvl}.`;if(O.sys==='roadm'&&l.sys!=='roadm')return 'Needs a ROADMaster 9000 line system.';if(!optMode(o,l)){const mx=(O.modes||[[0,O.reach]]).at(-1)[1];return `Too far even at its slowest setting: an optical span here is ${spanKm(l).toLocaleString()} km and it reaches ${mx.toLocaleString()} km. Add a regen site (Line system).`;}
if((l.ch||[]).length+soldSlots(l)>=DF_SYS[l.sys].max)return `${DF_SYS[l.sys].n} is full (${DF_SYS[l.sys].max} channels${soldSlots(l)?`, ${soldSlots(l)} sold to customers`:''}).`; if((l.ch||[]).length+soldSlots(l)>=DF_SYS[l.sys].max)return `${DF_SYS[l.sys].n} is full (${DF_SYS[l.sys].max} channels${soldSlots(l)?`, ${soldSlots(l)} sold to customers`:''}).`;
for(const c of [l.a,l.b]){const p=S.pops[c];if(p&&RG[p.rgen||0].cls<O.rg)return `Needs ${RG[O.rg].n} routers at both ends (${CITY[c].name}).`;}return '';} for(const c of [l.a,l.b]){const p=S.pops[c];if(p&&RG[p.rgen||0].cls<O.rg)return `Needs ${RG[O.rg].n} routers at both ends (${CITY[c].name}).`;}return '';}
function bbCost(c){return 15000+CITY[c].P*20;} function bbCost(c){return 15000+CITY[c].P*20;}
@ -2552,8 +2563,11 @@ function dfPanel(l){
<div class="kv"><span>Latency</span><b>${linkLat(l).toFixed(1)} ms one-way</b></div><div class="kv"><span>${l.own?'Right-of-way upkeep':'IRU lease'}</span><b>${fmt$(l.mo)}/mo</b></div><div class="kv"><span>${amps} amp huts</span><b>${fmt$(amps*AMP_MO)}/mo</b></div>${!bld&&!(l.ch||[]).length?`<p class="why">This fiber is dark. Add optics below to carry traffic.</p>`:''}</section>`; <div class="kv"><span>Latency</span><b>${linkLat(l).toFixed(1)} ms one-way</b></div><div class="kv"><span>${l.own?'Right-of-way upkeep':'IRU lease'}</span><b>${fmt$(l.mo)}/mo</b></div><div class="kv"><span>${amps} amp huts</span><b>${fmt$(amps*AMP_MO)}/mo</b></div>${!bld&&!(l.ch||[]).length?`<p class="why">This fiber is dark. Add optics below to carry traffic.</p>`:''}</section>`;
h+=`<section><h3>Optics</h3><p class="lead">Each channel is a pair of optics, one per end. ZR+ optics plug straight into your routers. Transponders sit on a shelf.</p>`; h+=`<section><h3>Optics</h3><p class="lead">Each channel is a pair of optics, one per end. ZR+ optics plug straight into your routers. Transponders sit on a shelf.</p>`;
for(const k of Object.keys(OPT)){const O=OPT[k],n=(l.ch||[]).filter(x=>x===k).length,why=chWhy(l,k); for(const k of Object.keys(OPT)){const O=OPT[k],n=(l.ch||[]).filter(x=>x===k).length,why=chWhy(l,k);
h+=`<div class="row"><div class="grow"><div class="nm">${O.n} <span class="meta">${fmtG(O.g)} · reach ${O.reach.toLocaleString()} km</span></div><div class="meta">${esc(O.blurb)}${n?` · <b>${n} lit</b>`:''}</div>${why?`<div class="why">${esc(why)}</div>`:''}</div>${n?btn('−','rmCh',{id:l.id,o:k},'ghost sm'):''}${btn(`+ <small>${fmt$(optCost(k))}</small>`,'addCh',{id:l.id,o:k},'sm',!!why||S.cash<optCost(k))}</div>`;} const md=optMode(k,l),cc=Math.round(optCost(k)*(1+REGEN_CH*(l.regen|0)));
h+=`</section><section><h3>Line system</h3><div class="kv"><span>${esc(sysD.n)}</span><b>${amps} amplifiers</b></div><p class="note">${esc(sysD.blurb)}</p><div class="btns">${l.sys!=='roadm'?btn(lvl()>=3?`Upgrade to ROADMaster 9000 <small>${fmt$(DF_SYS.roadm.cost)}</small>`:'ROADMaster 9000 <small>level 3</small>','upSys',{id:l.id},'sm',lvl()<3||S.cash<DF_SYS.roadm.cost):''}${btn(l.spares?'Spares kit on ✓':`Keep a spares kit <small>${fmt$(Math.round(150+(l.ch||[]).length*80))}/mo</small>`,'spares',{id:l.id},l.spares?'green sm':'sm')}</div><p class="note">Spare optics and amplifier cards on the shelf turn multi-day hardware failures into one-day swaps.</p></section>`; h+=`<div class="row"><div class="grow"><div class="nm">${O.n} <span class="meta">${(O.modes||[[O.g,O.reach]]).map(([g,r])=>fmtG(g)+' to '+r.toLocaleString()+' km').join(' · ')}</span></div><div class="meta">${esc(O.blurb)}${n?` · <b>${n} lit</b>`:''}</div>${md&&!md.full?`<div class="meta">⚠️ Runs at <b>${fmtG(md.g)}</b> per channel on this route (long-haul mode). ${regenNeed(k,l)>(l.regen|0)?`${regenNeed(k,l)} regen site${regenNeed(k,l)===1?'':'s'} would bring it back to ${fmtG(O.g)}.`:''}</div>`:''}${why?`<div class="why">${esc(why)}</div>`:''}</div>${n?btn('−','rmCh',{id:l.id,o:k},'ghost sm'):''}${btn(`+ <small>${fmt$(cc)}</small>`,'addCh',{id:l.id,o:k},'sm',!!why||S.cash<cc)}</div>`;}
const rg=l.regen|0,rgAdd=REGEN_COST+Math.round((l.ch||[]).reduce((a,c)=>a+optCost(c),0)*REGEN_CH);
h+=`</section><section><h3>Line system</h3><div class="kv"><span>${esc(sysD.n)}</span><b>${amps} amplifiers</b></div>
<div class="kv"><span>Regen sites</span><b>${rg?`${rg} · optical spans of ${spanKm(l).toLocaleString()} km`:'none'}</b></div><p class="note">A regen site turns the light back into bits halfway and sends it on fresh, so optics only have to reach the next site. Each needs a regen card for every lit channel. ${fmt$(REGEN_MO)}/mo per site for the hut.</p><div class="btns">${rg<REGEN_MAX?btn(`+ Regen site <small>${fmt$(rgAdd)}</small>`,'regen',{id:l.id,d:1},'sm',S.cash<rgAdd):''}${rg?btn('− Regen site','regen',{id:l.id,d:-1},'ghost sm'):''}</div><p class="note">${esc(sysD.blurb)}</p><div class="btns">${l.sys!=='roadm'?btn(lvl()>=3?`Upgrade to ROADMaster 9000 <small>${fmt$(DF_SYS.roadm.cost)}</small>`:'ROADMaster 9000 <small>level 3</small>','upSys',{id:l.id},'sm',lvl()<3||S.cash<DF_SYS.roadm.cost):''}${btn(l.spares?'Spares kit on ✓':`Keep a spares kit <small>${fmt$(Math.round(150+(l.ch||[]).length*80))}/mo</small>`,'spares',{id:l.id},l.spares?'green sm':'sm')}</div><p class="note">Spare optics and amplifier cards on the shelf turn multi-day hardware failures into one-day swaps.</p></section>`;
h+=`${trafficSection(l)}${metricSection(l)}<section>${btn(UI.confirm===l.id?'Really give it up?':(l.own?'Abandon the fiber':'Cancel the IRU'),'rmLink',{id:l.id},'ghost sm')}</section></div>`; h+=`${trafficSection(l)}${metricSection(l)}<section>${btn(UI.confirm===l.id?'Really give it up?':(l.own?'Abandon the fiber':'Cancel the IRU'),'rmLink',{id:l.id},'ghost sm')}</section></div>`;
return h; return h;
} }
@ -2769,7 +2783,7 @@ function dfModalBody(a,b,km,pop){
<h4 class="sub4">The glass</h4><div class="seg">${btn(`Lease an IRU <small>${fmt$(dfLeaseMo(km))}/mo · ready in 30 days</small>`,'dfSrc',{v:'lease'},src==='lease'?'pink':'ghost')}${sc?btn('Build your own <small>not under the sea</small>','dfSrc',{v:'build'},'ghost',true):btn(lvl()>=3?`Build your own <small>${fmt$(dfBuildCost(km))} · ~${dfBuildDays(km)} days</small>`:'Build your own <small>level 3</small>','dfSrc',{v:'build'},src==='build'?'pink':'ghost',lvl()<3)}</div>${sc?`<p class="note">A fiber pair on ${esc(CAB[sc.cid].name)}, ${sc.km.toLocaleString()} km. It shares the cable with everyone else's waves, anchors included.</p>`:''} <h4 class="sub4">The glass</h4><div class="seg">${btn(`Lease an IRU <small>${fmt$(dfLeaseMo(km))}/mo · ready in 30 days</small>`,'dfSrc',{v:'lease'},src==='lease'?'pink':'ghost')}${sc?btn('Build your own <small>not under the sea</small>','dfSrc',{v:'build'},'ghost',true):btn(lvl()>=3?`Build your own <small>${fmt$(dfBuildCost(km))} · ~${dfBuildDays(km)} days</small>`:'Build your own <small>level 3</small>','dfSrc',{v:'build'},src==='build'?'pink':'ghost',lvl()<3)}</div>${sc?`<p class="note">A fiber pair on ${esc(CAB[sc.cid].name)}, ${sc.km.toLocaleString()} km. It shares the cable with everyone else's waves, anchors included.</p>`:''}
${src==='build'?`<p class="note">Your own trench: almost no rent, but permits and digging take forever, and delays happen.</p>`:''} ${src==='build'?`<p class="note">Your own trench: almost no rent, but permits and digging take forever, and delays happen.</p>`:''}
<h4 class="sub4">Line system</h4><div class="seg">${Object.keys(DF_SYS).map(k=>btn(`${DF_SYS[k].n} <small>${DF_SYS[k].lvl>lvl()?'level '+DF_SYS[k].lvl:fmt$(DF_SYS[k].cost)}</small>`,'dfSys',{v:k},sys===k?'pink':'ghost',DF_SYS[k].lvl>lvl())).join('')}</div> <h4 class="sub4">Line system</h4><div class="seg">${Object.keys(DF_SYS).map(k=>btn(`${DF_SYS[k].n} <small>${DF_SYS[k].lvl>lvl()?'level '+DF_SYS[k].lvl:fmt$(DF_SYS[k].cost)}</small>`,'dfSys',{v:k},sys===k?'pink':'ghost',DF_SYS[k].lvl>lvl())).join('')}</div>
<p class="note">${esc(DF_SYS[sys].blurb)} Plus ${amps} in-line amplifier${amps===1?'':'s'} (${fmt$(AMP_COST)} each, ${fmt$(AMP_MO)}/mo for hut rent and power).</p> <p class="note">${esc(DF_SYS[sys].blurb)} Plus ${amps} in-line amplifier${amps===1?'':'s'} (${fmt$(AMP_COST)} each, ${fmt$(AMP_MO)}/mo for hut rent and power).</p>${km>OPT.tp16.reach?`<p class="note"><b>${km.toLocaleString()} km is longer than any optic reaches at full speed.</b> Transponders will run in long-haul mode (800G or 400G per channel), or add regen sites along the way to get full speed back.</p>`:''}
<div class="kv" style="margin-top:10px"><span>Due now</span><b>${fmt$(up)}</b></div><div class="kv"><span>Monthly</span><b>${fmt$(mo)}/mo</b></div> <div class="kv" style="margin-top:10px"><span>Due now</span><b>${fmt$(up)}</b></div><div class="kv"><span>Monthly</span><b>${fmt$(mo)}/mo</b></div>
<p class="note">For comparison, a leased 1.6T wave on this route is ${fmt$(w)}/mo. Optics come next, from the link panel.</p> <p class="note">For comparison, a leased 1.6T wave on this route is ${fmt$(w)}/mo. Optics come next, from the link panel.</p>
<div class="btns" style="margin-top:10px">${btn(`${src==='build'?'Start construction':'Sign the IRU'} <small>${fmt$(up)}</small>`,'orderDf',{},'pink big',S.cash<up)}</div>`; <div class="btns" style="margin-top:10px">${btn(`${src==='build'?'Start construction':'Sign the IRU'} <small>${fmt$(up)}</small>`,'orderDf',{},'pink big',S.cash<up)}</div>`;

View file

@ -225,3 +225,26 @@ test('#28 scenic routing stays put, and splits over two equally quiet paths', ()
ev("selectCity('fra');ACT.tab({t:'cust'})"); ev("selectCity('fra');ACT.tab({t:'cust'})");
assert.deepEqual(errors, []); assert.deepEqual(errors, []);
}); });
test('#17 #30 very long dark fiber runs in long-haul mode, and regen sites bring full speed back', () => {
const { ev, errors } = load();
ev("ACT.start({});S.cash=1e9;S.lvl=4;for(const g of GOALS)S.done[g.id]=0;ACT.launchBB({city:'fra'})");
// a 4,500+ km terrestrial dark fiber with a ROADM, like the one in #30
ev("ACT.buildPop({city:'mos'});S.links.push({id:'lf',a:'lis',b:'mos',kind:'df',km:4551,sys:'roadm',ch:[],ready:0,mo:1000,day:0,cut:0});ACT.buildPop({city:'lis'});S.pops.lis.rgen=3;S.pops.mos.rgen=3;compute()");
assert.equal(ev("chWhy(S.links.find(l=>l.id==='lf'),'tp16')"), '', 'the transponder fits now');
ev("ACT.addCh({id:'lf',o:'tp16'});compute()");
assert.equal(ev("dfCap(S.links.find(l=>l.id==='lf'))"), 800, 'long-haul mode: 800G per channel');
ev("ACT.regen({id:'lf',d:1});compute()");
const l = "S.links.find(l=>l.id==='lf')";
assert.equal(ev(`${l}.regen`), 1);
assert.equal(ev(`spanKm(${l})`), 2276);
assert.equal(ev(`dfCap(${l})`), 1600, 'one regen site: full 1.6T again');
assert.ok(ev("R.cost.optical") >= ev("REGEN_MO"), 'regen huts cost rent');
assert.match(ev("chWhy({km:20000,regen:0,sys:'roadm',ch:[],a:'lis',b:'mos'},'zr4')"), /regen site/, 'hopeless spans say what to do');
// removing a regen site that optics still need is refused
ev("S.links.find(l=>l.id==='lf').km=15000;ACT.regen({id:'lf',d:-1})");
assert.equal(ev(`${l}.regen`), 1);
ev("ACT.selLink({id:'lf'})");
assert.match(ev("document.getElementById('panelBody').textContent"), /Regen sites/);
assert.deepEqual(errors, []);
});