diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c8f16f..bcb71ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ All notable changes to this project are documented here. The project follows ## [Unreleased] +- Equip owned subsea cables with premium terminals and commission optical engineering to carry faster channels over longer routes. Order them with a new cable or upgrade an existing one; benefits start after commissioning. + +- Choose standard, optimized or low-latency designs for your own subsea cables. Faster designs cost much more and take longer; compare latency, cost and build time before ordering. + + - Fiber between nearby cities bends gently again instead of looping wide around the neighbourhood, so dense regions like Toronto, Ottawa and Montreal stay readable. - Swapping router models now sells the old ones on eBuy for 30% of their price, and removing a router does too (#82). A POP takes one swap a day, so a double click no longer buys two upgrades, and optics and waves now say which port speed they need instead of naming one model. - Hamburg and Munich join the map, with the Moin-IX and the Brezn-IX. Stuttgart and Frankfurt are back where they belong on the map, with Stuttgart between Frankfurt and Zurich instead of halfway to Prague. diff --git a/site/i18n/it.js b/site/i18n/it.js index 0b4de07..9a59549 100644 --- a/site/i18n/it.js +++ b/site/i18n/it.js @@ -2430,4 +2430,18 @@ "Needs routers with {pn} ports or bigger at both ends ({city}).":"Servono router con porte da {pn} o più grandi a entrambe le estremità ({city}).", "Prices include {p} back for the old routers on eBuy.":"I prezzi includono {p} recuperati vendendo i vecchi router su eBuy.", "New routers went in today. The next swap can wait until tomorrow.":"I nuovi router sono stati montati oggi. Il prossimo cambio può aspettare domani.", +"Standard":"Standard", +"Optimized":"Ottimizzato", +"Low latency":"Bassa latenza", +"Cable design":"Progetto del cavo", +"Estimated latency":"Latenza stimata", +"Premium submarine terminals":"Terminali sottomarini avanzati", +"Optical engineering":"Ingegneria ottica", +"This channel reaches {max} km on this cable; the route is {span} km. Consider submarine terminals or optical engineering.":"Questo canale raggiunge {max} km su questo cavo; il percorso è di {span} km. Valuta terminali sottomarini o ingegneria ottica.", +"Submarine transmission":"Trasmissione sottomarina", +"Better terminals and optical tuning extend long-haul reach. Repeaters are already included; these upgrades do not change latency.":"Terminali migliori e ottimizzazione ottica estendono la portata sulle lunghe distanze. I ripetitori sono già inclusi; questi aggiornamenti non modificano la latenza.", +"Ready in {n} days":"Pronto tra {n} giorni", +"{price} · {n} days":"{price} · {n} giorni", +"Up to {g} per channel":"Fino a {g} per canale", +"days":"giorni", }; diff --git a/site/index.html b/site/index.html index 5f7ab75..f4ab387 100644 --- a/site/index.html +++ b/site/index.html @@ -727,7 +727,19 @@ const spanKm=l=>Math.ceil(l.km/((l.regen|0)+1)); ~70 km, no regens (#66, #68). Optics reach about half as far again as on land, and the same physics caps every wave on a cable, leased or your own: transatlantic gets 1.6T, transpacific 800G. */ const SUB_REACH=1.5,reachOn=(r,sub)=>sub?Math.round(r*SUB_REACH):r; -function optMode(o,l){const O=OPT[o],km=spanKm(l);for(const [g,r] of O.modes||[[O.g,O.reach]])if(km<=reachOn(r,l.sub))return {g,reach:reachOn(r,l.sub),full:g===O.g};return null;} +// Upgrades improve long-haul modes, not the nominal 1.6T/3.2T rate. +const SUB_UPGRADES={terminal:{n:N_('Premium submarine terminals'),cost:5000000,days:30},engineering:{n:N_('Optical engineering'),cost:12000000,days:180}}; +const subUpgradeReady=(l,k)=>l.kind==='df'&&l.sub&&l.own&&Number.isFinite(l['sub'+k])&&l['sub'+k]<=S.day; +const subUpgradeCost=(l,k)=>SUB_UPGRADES[k].cost+(k==='engineering'?Math.round(l.km*1000):0); +function optModes(o,l){return (OPT[o].modes||[[OPT[o].g,OPT[o].reach]]).map(([g,r])=>{ + let reach=reachOn(r,l.sub); + if(l.sub&&['tp16','tp32'].includes(o)&&g<=1200){ + if(subUpgradeReady(l,'terminal'))reach=Math.max(reach,({1200:9000,800:13500,400:20000})[g]||reach); + if(subUpgradeReady(l,'engineering'))reach=Math.round(reach*1.25); + } + return [g,reach];});} +function optMode(o,l){const km=spanKm(l);for(const [g,r] of optModes(o,l))if(km<=r)return {g,reach:r,full:g===OPT[o].g};return null;} +const submarineRate=l=>Math.max(0,...Object.keys(OPT).filter(o=>OPT[o].lvl<=lvl()&&(OPT[o].sys!=='roadm'||isRdm(l.sys||'roadm'))).map(o=>optG(o,l))); // The fastest single carrier any optic can run over this much subsea cable. const subCarrier=km=>Math.max(0,...Object.values(OPT).map(O=>{const m=(O.modes||[[O.g,O.reach]]).find(([,r])=>km<=reachOn(r,true));return m?m[0]:0;})); // A big leased wave is several carriers (6.4T = 4×1.6T), so each carrier has to make it across on its own. @@ -1906,7 +1918,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.rupDay!==undefined)p.rupDay=num(p.rupDay,-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'; 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.pairs!==undefined)l.pairs=Math.min(l.sub?SUB_PAIRS_MAX:s.lvl>=PAIRS_LV?PAIRS_BIG:PAIRS_MAX,Math.max(1,Math.floor(+l.pairs)||1));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);}const deg=v=>v&&typeof v==='object'?{until:num(v.until,0),f:Math.min(1,Math.max(0,num(v.f,1)))}:null;if(l.loss)l.loss=deg(l.loss);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.pairs!==undefined)l.pairs=Math.min(l.sub?SUB_PAIRS_MAX:s.lvl>=PAIRS_LV?PAIRS_BIG:PAIRS_MAX,Math.max(1,Math.floor(+l.pairs)||1));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);for(const k of Object.keys(SUB_UPGRADES)){const f='sub'+k;if(l[f]!==undefined){if(l.own&&l.sub&&typeof l[f]==='number'&&Number.isFinite(l[f])&&l[f]>=0)l[f]=Math.round(l[f]);else delete l[f];}}if(l.own&&l.sub&&!own(SEA_DESIGNS,l.seaDesign))l.seaDesign='standard';l.regen=int(l.regen,0,REGEN_MAX,0);}const deg=v=>v&&typeof v==='object'?{until:num(v.until,0),f:Math.min(1,Math.max(0,num(v.f,1)))}:null;if(l.loss)l.loss=deg(l.loss);if(l.metric&&!own(MET,l.metric))l.metric='normal';return l;}); const degO=v=>v&&typeof v==='object'?{until:num(v.until,0),f:Math.min(1,Math.max(0,num(v.f,1)))}:null; s.transit=s.transit.filter(t=>t&&isCity(t.city)&&isNet(t.net)).map(t=>(t.lacp=degO(t.lacp),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.clean=!!t.clean,t)); s.pni=s.pni.filter(x=>x&&isCity(x.city)&&isNet(x.net)).map(x=>(x.lacp=degO(x.lacp),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.sacrif=!!x.sacrif,x)); @@ -2048,7 +2060,7 @@ const LAND_X=45,landX=(a,b)=>!isSub(a,b)&&CITY[a].reg!==CITY[b].reg; function landMult(a,b){if(isSub(a,b))return 1;if(uaePair(a,b))return 3;return (landX(a,b)?LAND_X:1)*(andesPair(a,b)?2:1);} function landWhy(a,b){if(isSub(a,b))return '';if(uaePair(a,b))return tr('Inside the UAE only the two licensed operators, Etis-a-lot and Du-opoly, may run fiber. No dark fiber, no digging your own, and waves cost 3×.'); const r=[];if(CITY[a].reg!==CITY[b].reg)r.push(tr('Overland between continents crosses a dozen borders, and every carrier on the way takes a cut: {x}× the price. Subsea is far cheaper.',{x:LAND_X}));if(andesPair(a,b))r.push(tr('This route crosses the Andes: 2× the price, and landslides and snow cut it far more often than flat fiber.'));return r.join(' ');} -function linkLat(l){const f=l.kind==='df'?(l.own?1.1:1.25):l.kind==='vxc'?1.4:l.cable?(CAB[l.cable].lat||1):1.3;return l.km*f/200;} +function linkLat(l){const f=l.kind==='df'?(l.own?(l.sub?seaLatencyFactor(l):1.1):1.25):l.kind==='vxc'?1.4:l.cable?(CAB[l.cable].lat||1):1.3;return l.km*f/200;} /* Wave prices differ a lot by market (TeleGeography): Europe's dense, competitive metro and long-haul routes are cheap (Frankfurt–London 100G ≈ $1,150/mo), the US costs more, and routes into Africa are several times dearer (Africa–Europe ≈ 5.9× London–New York). @@ -2754,13 +2766,17 @@ const ACT={ else toast(tr('Rolling upgrade in {city}
{n} × {model}, swapped one at a time. Zero downtime.',{city:CITY[city].name,n:rt,model:esc(RG[g].n)}),'good'); floater(CITY[city].x,CITY[city].y-30,RG[g].n+'!','#FF4F9A');after();}, dfMode:({m})=>{UI.lmode=m;if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);}, + seaPackage:({k})=>{if(!own(SUB_UPGRADES,k))return;UI['sea'+k]=!UI['sea'+k];if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);}, + subUpgrade:({id,k})=>{const l=S.links.find(l=>l.id===id);if(!l||l.kind!=='df'||!l.own||!l.sub||!own(SUB_UPGRADES,k)||lvl()<4||l['sub'+k]!==undefined)return;if(!spend(subUpgradeCost(l,k)))return;l['sub'+k]=Math.max(S.day,l.ready||0)+SUB_UPGRADES[k].days;after();}, + seaDesign:({v})=>{if(!own(SEA_DESIGNS,v))return;UI.seaDesign=v;if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);}, ownCab:()=>{UI.lmode='df';UI.dfSrc='cable';if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);}, dfSrc:({v})=>{UI.dfSrc=v;if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);}, dfSys:({v})=>{UI.dfSys=v;if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);}, - orderCable:()=>{const p=UI.pending;if(!p)return;const {a,b}=p;if(ownCabWhy(a,b))return;const km=ownCabKm(a,b),cost=ownCabCost(km)+(S.pops[b]?0:popCost(b));if(!spend(cost))return; + orderCable:()=>{const p=UI.pending;if(!p)return;const {a,b}=p;if(ownCabWhy(a,b))return;const design=own(SEA_DESIGNS,UI.seaDesign)?UI.seaDesign:'standard',q=seaQuote(a,b,design,{terminal:!!UI.seaterminal,engineering:!!UI.seaengineering}),km=q.km,cost=q.cost+(S.pops[b]?0:popCost(b));if(!spend(cost))return; if(!S.pops[b])S.pops[b]={day:S.day,bb:null,boost:0,down:0,routers:1,gen:false,rgen:0}; - const used=new Set(S.links.map(l=>l.cname).filter(Boolean)),cname=OWNCAB_NAMES.find(n=>!used.has(n))||`${pick(OWNCAB_NAMES)} ${used.size+1}`,ship=pick(OWNCAB_SHIPS),id=uid(),days=ownCabDays(km); - S.links.push({id,a,b,kind:'df',own:true,sub:true,sys:'roadm',ch:[],km,cable:null,cname,mo:Math.round(km*OWNCAB_OM),trench:'own:'+id,cut:0,day:S.day,ready:S.day+days,spares:false,pairs:1}); + const used=new Set(S.links.map(l=>l.cname).filter(Boolean)),cname=OWNCAB_NAMES.find(n=>!used.has(n))||`${pick(OWNCAB_NAMES)} ${used.size+1}`,ship=pick(OWNCAB_SHIPS),id=uid(),days=q.days; + S.links.push({id,a,b,kind:'df',own:true,sub:true,seaDesign:design,sys:'roadm',ch:[],km,cable:null,cname,mo:Math.round(km*OWNCAB_OM),trench:'own:'+id,cut:0,day:S.day,ready:S.day+days,spares:false,pairs:1}); + const laid=S.links[S.links.length-1];for(const k of Object.keys(SUB_UPGRADES))if(UI['sea'+k])laid['sub'+k]=laid.ready; S.stats.ownCab=(S.stats.ownCab||0)+1;UI.dfSrc='lease';closeModal();UI.sel={type:'link',id}; toast(tr('The {ship} sets sail!
{name}, your own {km} km cable from {a} to {b}. Ready in about {n} days, if the whales cooperate.',{ship,name:cname,km:km.toLocaleString(),a:CITY[a].name,b:CITY[b].name,n:days}),'goal');sfx('build');after();}, orderDf:()=>{const p=UI.pending;if(!p)return;const {a,b}=p;if(!dfAllowed(a,b))return;const sc=isSub(a,b)?subDfCable(a,b):null,km=sc?sc.km:kmBetween(a,b); @@ -2836,7 +2852,7 @@ function optCost(o){return Math.round(OPT[o].cost*(S&&S.ev&&S.ev.tariff>S.day?1. const sysNext=l=>l.sys==='lite'?'roadm':l.sys==='roadm'?'cl':null,sysUpCost=l=>{const t=sysNext(l);return t?DF_SYS[t].cost*(t==='cl'&&l.own?Math.max(1,l.pairs|0):1):0;}; function pairBtn(l){if(!l.own||!isRdm(l.sys)||l.ready>S.day)return '';const n=Math.max(1,l.pairs|0);if(n>=pairsMax(l))return `${tr('{n} fiber pairs lit, the trench is full',{n})}`; const full=(l.ch||[]).length+soldSlots(l)>=chMax(l),c=pairCost(l);return btn(l.sub?tr('Light fiber pair {n} {price}',{n:n+1,price:fmt$(c)}):tr('Light fiber pair {n} {price} + {mo}/mo',{n:n+1,price:fmt$(c),mo:fmt$(ampCount(l.km)*AMP_MO)}),'addPair',{id:l.id},full?'pink sm':'ghost sm',!full||S.cashlvl())return tr('Unlocks at customer level {n}.',{n:O.lvl});if(O.sys==='roadm'&&!isRdm(l.sys))return tr('Needs a ROADMaster 9000 line system.');if(!optMode(o,l)){const mx=reachOn((O.modes||[[0,O.reach]]).at(-1)[1],l.sub);return tr('Too far even at its slowest setting: an optical span here is {span} km and it reaches {max} km. Add a regen site (Line system).',{span:spanKm(l).toLocaleString(),max:mx.toLocaleString()});} +function chWhy(l,o){const O=OPT[o];if(O.lvl>lvl())return tr('Unlocks at customer level {n}.',{n:O.lvl});if(O.sys==='roadm'&&!isRdm(l.sys))return tr('Needs a ROADMaster 9000 line system.');if(!optMode(o,l)){const mx=optModes(o,l).at(-1)[1];if(l.sub)return tr('This channel reaches {max} km on this cable; the route is {span} km. Consider submarine terminals or optical engineering.',{max:mx.toLocaleString(),span:spanKm(l).toLocaleString()});return tr('Too far even at its slowest setting: an optical span here is {span} km and it reaches {max} km. Add a regen site (Line system).',{span:spanKm(l).toLocaleString(),max:mx.toLocaleString()});} if((l.ch||[]).length+soldSlots(l)>=chMax(l))return soldSlots(l)?tr('{sys} is full ({max} channels, {sold} sold to customers).',{sys:DF_SYS[l.sys].n,max:chMax(l),sold:soldSlots(l)}):tr('{sys} is full ({max} channels).',{sys:DF_SYS[l.sys].n,max:chMax(l)}); for(const c of [l.a,l.b]){const p=S.pops[c];if(p&&RG[p.rgen||0].clsS.d else h+=`

${tr('Your joint venture holds an operating license.')}

`; if(R.gfwCross>0.5)h+=`
${tr('Your traffic crossing the border')}${fmtG(R.gfwCross)}
${tr('Lost on the way')}${fmtG(R.gfwLost)}
`; return h+``;} +function subUpgradePanel(l){return `

${tr('Submarine transmission')}

${tr('Better terminals and optical tuning extend long-haul reach. Repeaters are already included; these upgrades do not change latency.')}

`+Object.entries(SUB_UPGRADES).map(([k,U])=>{ + const at=l['sub'+k],done=subUpgradeReady(l,k),cost=subUpgradeCost(l,k),preview={...l,['sub'+k]:S.day}; + const status=done?tr('Installed'):at!==undefined?tr('Ready in {n} days',{n:Math.max(0,at-S.day)}):tr('{price} · {n} days',{price:fmt$(cost),n:U.days}); + return `
${tr(U.n)}
${status}
${tr('Up to {g} per channel',{g:fmtG(submarineRate(preview))})}
${at===undefined?btn(tr('Install'),'subUpgrade',{id:l.id,k},'sm',lvl()<4||S.cash`;}).join('');} function dfPanel(l){ const load=R.load[l.id]||0,cap=dfCap(l),u=cap?load/cap:0,bld=l.ready>S.day,A=CITY[l.a].name,B=CITY[l.b].name,inc=S.inc.find(i=>i.ref===l.id||i.ref===(l.trench||l.id)),amps=ampCount(l.km),sysD=DF_SYS[l.sys]; let h=`
${tr('Dark fiber · {kind} · {km} km',{kind:l.own?tr('your own build'):tr('leased IRU'),km:l.km.toLocaleString()})}

${A} ⇄ ${B}

`; @@ -3220,11 +3240,13 @@ function dfPanel(l){ h+=`

${l.own?tr('Under construction'):tr('Being spliced')}

${l.own?tr('Permits, trenching, splicing'):tr('IRU handover')}${tr('{n} days left',{n:l.ready-S.day})}
${l.own?btn(tr('Hire extra crews {price} · −30 days',{price:fmt$(Math.round(15000+l.km*6))}),'crews',{id:l.id},'sm',S.cash<15000+l.km*6):''}

${tr("You can pre-install optics now so it lights up the day it's ready.")}

`;} else if(inc&&linkDown(l))h+=`

${tr('Dark!')}

${esc(inc.msg)}

${inc.cost?btn(`${esc(inc.fix||tr('Rush repair'))} ${fmt$(inc.cost)}`,'fixInc',{id:inc.id},'red',S.cash`; h+=`

${tr('Capacity')}

${tr('{n} of {max} channels lit',{n:(l.ch||[]).length,max:chMax(l)})}${soldSlots(l)?` · ${tr('{n} sold as alien waves',{n:soldSlots(l)})}`:''}${fmtG(load)} / ${fmtG(cap)}
+ ${l.own&&l.sub?`
${tr('Cable design')}${tr((SEA_DESIGNS[l.seaDesign]||SEA_DESIGNS.standard).n)}
`:''}
${tr('Latency')}${tr('{ms} ms one-way',{ms:linkLat(l).toFixed(1)})}
${l.own?tr('Right-of-way upkeep'):tr('IRU lease')}${tr('{price}/mo',{price:fmt$(l.mo)})}
${tr('{n} amp huts',{n:amps})}${tr('{price}/mo',{price:fmt$(amps*AMP_MO)})}
${!bld&&!(l.ch||[]).length?`

${tr('This fiber is dark. Add optics below to carry traffic.')}

`:''}
`; h+=`

${tr('Optics')}

${tr('Each channel is a pair of optics, one per end. ZR+ optics plug straight into your routers. Transponders sit on a shelf.')}

`; + if(l.own&&l.sub)h+=subUpgradePanel(l); for(const k of Object.keys(OPT)){const O=OPT[k],n=(l.ch||[]).filter(x=>x===k).length,why=chWhy(l,k); const md=optMode(k,l),cc=chCost(l,k),sp=spareN(k); - h+=`
${O.n} ${(O.modes||[[O.g,O.reach]]).map(([g,r])=>tr('{g} to {km} km',{g:fmtG(g),km:reachOn(r,l.sub).toLocaleString()})).join(' · ')}
${esc(O.blurb)}${n?` · ${tr('{n} lit',{n})}`:''}${sp?` · ${trn('{n} spare on the shelf','{n} spares on the shelf',sp)}`:''}
${md&&!md.full?`
⚠️ ${tr('Runs at {g} per channel on this route (long-haul mode).',{g:fmtG(md.g)})} ${!l.sub&®enNeed(k,l)>(l.regen|0)?trn('{n} regen site would bring it back to {g}.','{n} regen sites would bring it back to {g}.',regenNeed(k,l),{g:fmtG(O.g)}):''}
`:''}${why?`
${esc(why)}
`:''}
${n?btn('−','rmCh',{id:l.id,o:k},'ghost sm'):''}${btn(sp?`+ ${cc?tr('spare + {price}',{price:fmt$(cc)}):tr('spare')}`:`+ ${fmt$(cc)}`,'addCh',{id:l.id,o:k},'sm',!!why||S.cash`;} + h+=`
${O.n} ${optModes(k,l).map(([g,r])=>tr('{g} to {km} km',{g:fmtG(g),km:r.toLocaleString()})).join(' · ')}
${esc(O.blurb)}${n?` · ${tr('{n} lit',{n})}`:''}${sp?` · ${trn('{n} spare on the shelf','{n} spares on the shelf',sp)}`:''}
${md&&!md.full?`
⚠️ ${tr('Runs at {g} per channel on this route (long-haul mode).',{g:fmtG(md.g)})} ${!l.sub&®enNeed(k,l)>(l.regen|0)?trn('{n} regen site would bring it back to {g}.','{n} regen sites would bring it back to {g}.',regenNeed(k,l),{g:fmtG(O.g)}):''}
`:''}${why?`
${esc(why)}
`:''}
${n?btn('−','rmCh',{id:l.id,o:k},'ghost sm'):''}${btn(sp?`+ ${cc?tr('spare + {price}',{price:fmt$(cc)}):tr('spare')}`:`+ ${fmt$(cc)}`,'addCh',{id:l.id,o:k},'sm',!!why||S.cash`;} {const st=Object.keys(OPT).filter(k=>spareN(k)>0);h+=`

${tr('Unplugged optics go on the spares shelf and are used first next time.')}

`;if(st.length)h+=`

${tr('Spares shelf')}

`+st.map(k=>`
${spareN(k)} × ${OPT[k].n}
${btn(tr('Sell one {price}',{price:fmt$(spareValue(k))}),'sellSpare',{o:k},'ghost sm')}
`).join('');} const rg=l.regen|0,rgAdd=REGEN_COST+Math.round((l.ch||[]).reduce((a,c)=>a+optCost(c),0)*REGEN_CH); h+=`

${tr('Line system')}

${esc(sysD.n)}${tr('{n} amplifiers',{n:amps})}
@@ -3624,6 +3646,25 @@ const ownCabKm=(a,b)=>Math.round(kmBetween(a,b)*OWNCAB_ROUTE); const ownCabCost=km=>2*OWNCAB_LAND+km*OWNCAB_KM+DF_SYS.roadm.cost; const ownCabMo=km=>Math.round(km*OWNCAB_OM)+ampCount(km)*AMP_MO; const ownCabDays=km=>Math.round(300+km*0.05); +// Standard keeps the original budget route. Premium designs pay for a better +// survey and landing route; they do not share the reference cable's trench. +const SEA_DESIGNS={standard:{n:N_('Standard'),cost:1,time:1},optimized:{n:N_('Optimized'),cost:3,time:2},express:{n:N_('Low latency'),cost:7,time:3.5}}; +function seaReference(a,b,express){ + const cs=cablesFor(a,b).filter(c=>express||(CAB[c.cid].lat||1)>=1); + return cs.sort((x,y)=>x.km*(express?(CAB[x.cid].lat||1):1)-y.km*(express?(CAB[y.cid].lat||1):1))[0]; +} +function seaLatencyFactor(l){return l.seaDesign==='optimized'?1:l.seaDesign==='express'?seaExpressFactor(l.a,l.b):1.1;} +function seaExpressFactor(a,b){const c=seaReference(a,b,true);return Math.min(0.9,c?(CAB[c.cid].lat||1):0.9);} +function seaQuote(a,b,design='standard',upgrades={}){ + if(!own(SEA_DESIGNS,design))design='standard'; + const D=SEA_DESIGNS[design],base=ownCabKm(a,b),ref=design==='standard'?null:seaReference(a,b,design==='express'); + const km=design==='standard'?base:ref?ref.km:Math.round(kmBetween(a,b)*(design==='express'?1.02:1.08)); + // Higher survey and permitting costs dominate any savings from shorter glass. + let cost=Math.round(ownCabCost(Math.max(base,km))*D.cost),days=Math.round(ownCabDays(Math.max(base,km))*D.time); + for(const k of Object.keys(SUB_UPGRADES))if(upgrades[k]){cost+=subUpgradeCost({km},k);days+=SUB_UPGRADES[k].days;} + const ms=linkLat({a,b,kind:'df',own:true,sub:true,km,seaDesign:design}); + return {km,cost,days,ms}; +} // Some pairs share a landmass and still have cables between them (Marseille–Singapore, Cairo–Palermo) (#67). const seaCab=(a,b)=>isSub(a,b)||(landing(a)&&landing(b)&&cablesFor(a,b).length>0); function ownCabWhy(a,b){if(!seaCab(a,b))return tr('This route is on land. Build your own fiber instead.'); @@ -3633,8 +3674,12 @@ function ownCabWhy(a,b){if(!seaCab(a,b))return tr('This route is on land. Build return '';} function ownCabTeaser(a,b){const why=ownCabWhy(a,b);return `
${btn(S.won?tr('Lay your own subsea cable…'):tr('Your own subsea cable Tier 1 only'),'ownCab',{},S.won&&!why?'pink':'ghost',!!why)}
${why&&S.won?`

${esc(why)}

`:''}`;} function ownCabBody(a,b,pop){const why=ownCabWhy(a,b);if(why)return `

${esc(why)}

${btn(tr('Back'),'dfSrc',{v:'lease'},'ghost sm')}`; - const km=ownCabKm(a,b),cost=ownCabCost(km),mo=ownCabMo(km),days=ownCabDays(km),wt=subMaxTier(km),w=Math.round(waveMo(km,true,wt)*waveMarket(a,b,true).m),save=10*w*LT[4].g/LT[wt].g-mo,pay=save>0?Math.ceil(cost/save):0; + const design=own(SEA_DESIGNS,UI.seaDesign)?UI.seaDesign:'standard',upgrades={terminal:!!UI.seaterminal,engineering:!!UI.seaengineering},q=seaQuote(a,b,design,upgrades),{km,cost,days}=q,mo=ownCabMo(km),wt=subMaxTier(km),w=Math.round(waveMo(km,true,wt)*waveMarket(a,b,true).m),save=10*w*LT[4].g/LT[wt].g-mo,pay=save>0?Math.ceil(cost/save):0; return `

${tr('Your very own subsea cable. A ship lays it across the seabed, you own every fiber pair in it, and nobody else’s waves share your glass. It costs a frankly rude amount of money and takes a long time.')}

+

${tr('Cable design')}

${Object.entries(SEA_DESIGNS).map(([v,D])=>{const o=seaQuote(a,b,v,upgrades);return `
${tr(D.n)}
${tr('{ms} ms one-way',{ms:o.ms.toFixed(1)})} · ${fmt$(o.cost+pop)} · ${tr('about {n} days',{n:o.days})}
${btn(tr(D.n),'seaDesign',{v},design===v?'pink sm':'ghost sm')}
`;}).join('')} +

${tr('Submarine transmission')}

${Object.entries(SUB_UPGRADES).map(([k,U])=>btn(`${tr(U.n)} ${upgrades[k]?'✓ · ':''}${fmt$(subUpgradeCost({km},k))} · +${U.days} ${tr('days')}`,'seaPackage',{k},upgrades[k]?'green sm':'ghost sm')).join('')} +

${tr('Up to {g} per channel',{g:fmtG(submarineRate({a,b,km,kind:'df',own:true,sub:true,subterminal:upgrades.terminal?S.day:undefined,subengineering:upgrades.engineering?S.day:undefined}))})} · ${tr('Better terminals and optical tuning extend long-haul reach. Repeaters are already included; these upgrades do not change latency.')}

+
${tr('Estimated latency')}${tr('{ms} ms one-way',{ms:q.ms.toFixed(1)})}
${tr('Route')}${tr('{km} km of seabed',{km:km.toLocaleString()})}
${tr('Fiber pairs')}${tr('{n} in the cable, the first one lit',{n:SUB_PAIRS_MAX})}
${tr('Landing stations')}${tr('{a} and {b}',{a:CITY[a].name,b:CITY[b].name})}
diff --git a/tests/regions.test.js b/tests/regions.test.js index d55109c..e20bdb1 100644 --- a/tests/regions.test.js +++ b/tests/regions.test.js @@ -520,3 +520,128 @@ test('Stuttgart sits between Frankfurt and Zurich, and Hamburg and Munich are on assert.equal(ev("NET.lvl.pops.includes('ham')&&NET.dtk.pops.includes('ham')"), true); assert.deepEqual(errors, []); }); + +test('subsea cable designs trade construction cost and time for previewed latency', () => { + const { ev, dom, errors } = load(); + try { + ev("ACT.start({});S.cash=1e10;S.lvl=4;S.won=true;for(const g of GOALS)S.done[g.id]=0;ACT.buildPop({city:'lon'});ACT.buildPop({city:'nyc'});UI.lmode='df';UI.dfSrc='cable';openLinkModal('lon','nyc')"); + const quotes = JSON.parse(ev("JSON.stringify(['standard','optimized','express'].map(d=>seaQuote('lon','nyc',d)))")); + assert.ok(quotes[0].ms > quotes[1].ms && quotes[1].ms > quotes[2].ms); + assert.ok(quotes[1].cost >= quotes[0].cost * 3 && quotes[2].cost >= quotes[0].cost * 7); + assert.ok(quotes[1].days >= quotes[0].days * 2 && quotes[2].days >= quotes[0].days * 3.5); + assert.equal(quotes[2].ms, ev("Math.min(...cablesFor('lon','nyc').map(c=>linkLat({kind:'wave',km:c.km,cable:c.cid})))"), 'express competes with Hibernia'); + for (const q of quotes) assert.ok(dom.window.document.getElementById('modalCard').textContent.includes(q.ms.toFixed(1) + ' ms one-way'), 'every latency is visible before ordering'); + for (const [i, design] of ['standard', 'optimized', 'express'].entries()) { + ev("UI.lmode='df';UI.dfSrc='cable';openLinkModal('lon','nyc')"); + ev(`document.querySelector('#modalCard [data-act=seaDesign][data-args*=${design}]').click()`); + const cash = ev('S.cash'), day = ev('S.day'); + ev('ACT.orderCable()'); + const l = JSON.parse(ev('JSON.stringify(S.links[S.links.length-1])')); + assert.equal(l.seaDesign, design); + assert.equal(cash - ev('S.cash'), quotes[i].cost); + assert.equal(l.ready - day, quotes[i].days); + assert.equal(ev(`linkLat(S.links[S.links.length-1])`), quotes[i].ms); + assert.equal(l.km, quotes[i].km); + assert.match(l.trench, /^own:/, 'independent from the reference cable'); + ev('S=migrate(JSON.parse(JSON.stringify(S)))'); + assert.equal(ev('linkLat(S.links[S.links.length-1])'), quotes[i].ms, 'save round trip retains latency'); + } + ev("UI.pending={a:'lon',b:'nyc'};UI.seaDesign='express';S.cash=seaQuote('lon','nyc','express').cost-1;window.__n=S.links.length;ACT.orderCable()"); + assert.equal(ev('S.links.length'), ev('__n'), 'premium funds checked at purchase'); + ev("S.links[0].seaDesign='bogus';S=sanitize(S)"); + assert.equal(ev('S.links[0].seaDesign'), 'standard'); + assert.deepEqual(errors, []); + } finally { dom.window.close(); } +}); + +test('old owned cables keep their latency and premium designs work without a leased route', () => { + const { ev, dom, errors } = load(); + try { + ev('ACT.start({})'); + assert.equal(ev("linkLat({kind:'df',own:true,sub:true,km:6405})"), 6405 * 1.1 / 200); + assert.equal(ev("linkLat({kind:'df',own:true,sub:false,seaDesign:'express',km:6405})"), 6405 * 1.1 / 200, 'land fiber is unchanged'); + const q = JSON.parse(ev("JSON.stringify(['standard','optimized','express'].map(d=>seaQuote('cbo','nyc',d)))")); + assert.ok(q[0].ms > q[1].ms && q[1].ms > q[2].ms); + assert.deepEqual(errors, []); + } finally { dom.window.close(); } +}); + +test('submarine terminal and engineering upgrades commission independently and combine for Pacific reach', () => { + const { ev, dom, errors } = load(); + try { + ev("ACT.start({});S.cash=1e9;S.lvl=4;for(const g of GOALS)S.done[g.id]=0;S.links.push({id:'pacific',a:'sin',b:'lax',kind:'df',own:true,sub:true,km:16608,sys:'roadm',ch:['tp16'],ready:0,cut:0,mo:1})"); + const before = ev("linkLat(S.links[0])"), cash = ev('S.cash'); + assert.equal(ev('dfCap(S.links[0])'), 400); + ev("ACT.subUpgrade({id:'pacific',k:'terminal'})"); + assert.equal(cash - ev('S.cash'), 5000000); + assert.equal(ev('dfCap(S.links[0])'), 400, 'no benefit during commissioning'); + const paid = ev('S.cash'); + ev("ACT.subUpgrade({id:'pacific',k:'terminal'})"); + assert.equal(ev('S.cash'), paid, 'cannot pay twice'); + ev('S.day=S.links[0].subterminal'); + assert.equal(ev("optG('tp16',{...S.links[0],km:12000})"), 800, 'terminals improve reach independently'); + assert.equal(ev('dfCap(S.links[0])'), 400, 'this Pacific route still needs engineering'); + ev("ACT.subUpgrade({id:'pacific',k:'engineering'})"); + assert.equal(paid - ev('S.cash'), 12000000 + 16608 * 1000); + ev('S.day=S.links[0].subengineering-1'); + assert.equal(ev('dfCap(S.links[0])'), 400); + ev('S.day++;compute()'); + assert.equal(ev('dfCap(S.links[0])'), 800, 'combined upgrades deliver 800G across 16,608 km'); + assert.equal(ev('linkLat(S.links[0])'), before, 'transmission upgrades do not change latency'); + ev('S=migrate(JSON.parse(JSON.stringify(S)))'); + assert.equal(ev('dfCap(S.links[0])'), 800, 'upgrades survive a save round trip'); + ev("UI.sel={type:'link',id:'pacific'};renderPanel()"); + assert.match(dom.window.document.getElementById('panelBody').textContent, /Premium submarine terminals/); + assert.match(dom.window.document.getElementById('panelBody').textContent, /800 Gbps to 16,875 km/); + assert.equal(ev("optG('tp16',{...S.links[0],km:12000,subterminal:undefined})"), 800, 'engineering also helps without premium terminals'); + assert.equal(ev("optG('tp16',{...S.links[0],km:7000})"), 1200, 'upgrades do not extend full-rate reach'); + assert.equal(ev("optG('zr4',{...S.links[0],km:5000})"), 0, 'router pluggables do not gain submarine terminal benefits'); + assert.deepEqual(errors, []); + } finally { dom.window.close(); } +}); + +test('new subsea builds include chosen transmission packages in the quote and saved order', () => { + const { ev, dom, errors } = load(); + try { + ev("ACT.start({});S.cash=1e9;S.lvl=4;S.won=true;for(const g of GOALS)S.done[g.id]=0;ACT.buildPop({city:'lon'});ACT.buildPop({city:'nyc'});UI.lmode='df';UI.dfSrc='cable';openLinkModal('lon','nyc')"); + const baseline = JSON.parse(ev("JSON.stringify(seaQuote('lon','nyc'))")); + ev("document.querySelector('#modalCard [data-act=seaPackage][data-args*=terminal]').click();document.querySelector('#modalCard [data-act=seaPackage][data-args*=engineering]').click()"); + const quote = JSON.parse(ev("JSON.stringify(seaQuote('lon','nyc','standard',{terminal:true,engineering:true}))")); + assert.equal(quote.days, baseline.days + 210); + assert.equal(quote.cost, baseline.cost + 5000000 + 12000000 + baseline.km * 1000); + assert.equal(quote.ms, baseline.ms); + const cash = ev('S.cash'); + ev('ACT.orderCable()'); + const cable = JSON.parse(ev('JSON.stringify(S.links[S.links.length-1])')); + assert.equal(cash - ev('S.cash'), quote.cost); + assert.equal(cable.ready - ev('S.day'), quote.days); + assert.equal(cable.subterminal, cable.ready); + assert.equal(cable.subengineering, cable.ready); + assert.equal(ev("subUpgradeReady(S.links[S.links.length-1],'terminal')"), false); + ev('S=migrate(JSON.parse(JSON.stringify(S)));S.day=S.links[S.links.length-1].ready'); + assert.equal(ev("subUpgradeReady(S.links[S.links.length-1],'terminal')"), true); + assert.equal(ev("subUpgradeReady(S.links[S.links.length-1],'engineering')"), true); + assert.deepEqual(errors, []); + } finally { dom.window.close(); } +}); + +test('submarine upgrades reject invalid purchases and preserve baseline and terrestrial optics', () => { + const { ev, dom, errors } = load(); + try { + ev("ACT.start({});S.cash=1e9;S.lvl=4;S.links.push({id:'land',a:'fra',b:'ams',kind:'df',own:true,km:7000,sys:'roadm',ch:['tp16'],ready:0},{id:'sea',a:'lon',b:'nyc',kind:'df',own:false,sub:true,km:7000,sys:'roadm',ch:['tp16'],ready:0})"); + const cash = ev('S.cash'); + ev("ACT.subUpgrade({id:'land',k:'terminal'});ACT.subUpgrade({id:'sea',k:'engineering'});ACT.subUpgrade({id:'land',k:'bogus'})"); + assert.equal(ev('S.cash'), cash); + assert.equal(ev('dfCap(S.links[0])'), 800); + assert.equal(ev('dfCap(S.links[1])'), 1200); + ev("S.links[1].own=true;S.cash=1;ACT.subUpgrade({id:'sea',k:'terminal'})"); + assert.equal(ev('S.links[1].subterminal'), undefined, 'insufficient cash'); + ev("S.cash=1e9;S.lvl=3;ACT.subUpgrade({id:'sea',k:'terminal'})"); + assert.equal(ev('S.links[1].subterminal'), undefined, 'locked below level 4'); + ev("S.links[1].subterminal=-1;S.links[1].subengineering='yes';S.links[0].subterminal=0;S=sanitize(S)"); + assert.equal(ev('S.links[1].subterminal'), undefined); + assert.equal(ev('S.links[1].subengineering'), undefined); + assert.equal(ev('S.links[0].subterminal'), undefined); + assert.deepEqual(errors, []); + } finally { dom.window.close(); } +});