diff --git a/CHANGELOG.md b/CHANGELOG.md index 6052ce9..3573716 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project are documented here. The project follows ## [Unreleased] +- Your own subsea cables now come in three designs, from the budget route to one as fast as the fastest cable on the map, and two upgrades carry faster channels further (#65). Each design shows its latency, price and build time before you order: optimized costs three times as much and low latency seven times, and both take months longer. Premium terminals and optical engineering light longer routes at higher speeds, so a cable as long as New York to Sydney can now carry traffic, and the order screen tells you which upgrade a route needs. Calling off a cable while it is being laid refunds what you actually paid for it. - Series of Tubes now speaks French. The game follows your browser's language the first time, and you can switch to Français under Settings or on the title screen. - PNI buttons now show the monthly port fee next to the one-off setup cost, so a $1.8k cross-connect no longer looks like a monthly bill (#110). Upgrading a PNI shows what the bigger port costs per month too. - Düsseldorf joins the map with the Altbier-IX (#108). It is Germany's second carrier hub, an hour from the Dutch border, and the networks you meet there are the ones really present: Voda-Phony's home market, Doitsche Telekomm, the big Tier 1s and the clouds. diff --git a/site/i18n/fr.js b/site/i18n/fr.js index c7f2402..e1cc80e 100644 --- a/site/i18n/fr.js +++ b/site/i18n/fr.js @@ -2584,4 +2584,20 @@ "1.6T on every hop from Los Angeles to Sydney":"1.6T sur chaque saut de Los Angeles à Sydney", "A path from Los Angeles to Tokyo":"Un chemin de Los Angeles à Tokyo", "The Rhine-Ruhr hub: more carrier-neutral data centers than Hamburg or Munich, and an hour from the Dutch border, so fiber to Amsterdam is short and cheap. Order an Altbier here, never a Kölsch.":"Le hub de la Rhénanie-Ruhr : plus de data centers neutres que Hamburg ou Munich, et à une heure de la frontière néerlandaise, donc la fibre vers Amsterdam est courte et pas chère. Ici, on commande une Altbier, jamais une Kölsch.", +"Premium submarine terminals":"Terminaux sous-marins premium", +"Optical engineering":"Ingénierie optique", +"This channel reaches {max} km on this cable; the route is {span} km. Consider submarine terminals or optical engineering.":"Ce canal porte à {max} km sur ce câble ; le tracé fait {span} km. Pense aux terminaux sous-marins ou à l’ingénierie optique.", +"Submarine transmission":"Transmission sous-marine", +"Better terminals and optical tuning extend long-haul reach. Repeaters are already included; these upgrades do not change latency.":"De meilleurs terminaux et un réglage optique allongent la portée longue distance. Les répéteurs sont déjà inclus ; ces améliorations ne changent pas la latence.", +"Ready in {n} days":"Prêt dans {n} jours", +"{price} · {n} days":"{price} · {n} jours", +"Up to {g} per channel":"Jusqu’à {g} par canal", +"Cable design":"Conception du câble", +"Standard":"Standard", +"Optimized":"Optimisé", +"Low latency":"Faible latence", +"+{n} days":"+{n} jours", +"This design’s route is {km} km: too long for any optics, even with both upgrades. A shorter design can make it.":"Le tracé de cette conception fait {km} km : trop long pour toute optique, même avec les deux améliorations. Une conception plus courte peut y arriver.", +"{km} km is too far for your optics on their own. Add {what} to light this cable.":"{km} km, c’est trop loin pour tes optiques seules. Ajoute {what} pour allumer ce câble.", +"Estimated latency":"Latence estimée", }; diff --git a/site/i18n/it.js b/site/i18n/it.js index baeaa48..43ae091 100644 --- a/site/i18n/it.js +++ b/site/i18n/it.js @@ -2597,5 +2597,7 @@ "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", +"+{n} days":"+{n} giorni", +"This design’s route is {km} km: too long for any optics, even with both upgrades. A shorter design can make it.":"Il percorso di questo progetto è di {km} km: troppo lungo per qualsiasi ottica, anche con entrambi i miglioramenti. Un progetto più corto ce la fa.", +"{km} km is too far for your optics on their own. Add {what} to light this cable.":"{km} km sono troppi per le tue ottiche da sole. Aggiungi {what} per accendere questo cavo.", }; diff --git a/site/i18n/pt.js b/site/i18n/pt.js index bc05eb9..1912b0b 100644 --- a/site/i18n/pt.js +++ b/site/i18n/pt.js @@ -2584,4 +2584,20 @@ "Tonga hangs on one cable from Fiji. In 2022 an undersea volcano cut it, and the country was offline for weeks.":"Tonga depende de um único cabo vindo de Fiji. Em 2022 um vulcão submarino o cortou, e o país ficou offline por semanas.", "Tonga’s own telco. Lived through a volcano that cut its only cable, and jokes about it now.":"A operadora de Tonga. Sobreviveu a um vulcão que cortou seu único cabo e hoje faz piada disso.", "The Rhine-Ruhr hub: more carrier-neutral data centers than Hamburg or Munich, and an hour from the Dutch border, so fiber to Amsterdam is short and cheap. Order an Altbier here, never a Kölsch.":"O hub do Reno-Ruhr: mais data centers neutros do que Hamburgo ou Munique, e a uma hora da fronteira holandesa, então a fibra até Amsterdã é curta e barata. Aqui se pede uma Altbier, nunca uma Kölsch.", +"Premium submarine terminals":"Terminais submarinos premium", +"Optical engineering":"Engenharia óptica", +"This channel reaches {max} km on this cable; the route is {span} km. Consider submarine terminals or optical engineering.":"Este canal alcança {max} km neste cabo; a rota tem {span} km. Considere terminais submarinos ou engenharia óptica.", +"Submarine transmission":"Transmissão submarina", +"Better terminals and optical tuning extend long-haul reach. Repeaters are already included; these upgrades do not change latency.":"Terminais melhores e ajuste óptico aumentam o alcance de longa distância. Os repetidores já estão incluídos; essas melhorias não mudam a latência.", +"Ready in {n} days":"Pronto em {n} dias", +"{price} · {n} days":"{price} · {n} dias", +"Up to {g} per channel":"Até {g} por canal", +"Cable design":"Projeto do cabo", +"Standard":"Padrão", +"Optimized":"Otimizado", +"Low latency":"Baixa latência", +"+{n} days":"+{n} dias", +"This design’s route is {km} km: too long for any optics, even with both upgrades. A shorter design can make it.":"A rota deste projeto tem {km} km: longa demais para qualquer óptica, mesmo com as duas melhorias. Um projeto mais curto consegue.", +"{km} km is too far for your optics on their own. Add {what} to light this cable.":"{km} km é longe demais para as suas ópticas sozinhas. Adicione {what} para acender este cabo.", +"Estimated latency":"Latência estimada", }; diff --git a/site/index.html b/site/index.html index e4dd328..35fe5fa 100644 --- a/site/index.html +++ b/site/index.html @@ -319,6 +319,7 @@ input.t{width:100%;box-sizing:border-box;border:3px solid var(--ink);border-radi .plug:hover{background:#FFF6D6}.plug .pi{font-size:30px;line-height:1}.plug b{font-family:var(--display);font-size:16px}.plug .meta{display:block;margin-top:2px}.plug .go{margin-left:auto;font-weight:900;white-space:nowrap} .starts{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px} .start{border:3px solid var(--ink);border-radius:14px;padding:8px 10px;background:var(--paper);cursor:pointer;text-align:left;box-shadow:0 3px 0 var(--ink)} +.starts.one{grid-template-columns:1fr} .start.on{background:#FFE3F0;border-color:var(--me);box-shadow:0 3px 0 var(--me)} .start b{font-family:var(--display);font-size:17px;display:block} .start span{font-size:12px;color:var(--ink2);line-height:1.3;display:block} @@ -729,7 +730,7 @@ 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; -const SUB_MAXKM=()=>Math.max(...Object.values(OPT).flatMap(O=>(O.modes||[[O.g,O.reach]]).map(m=>reachOn(m[1],true)))); +const SUB_MAXKM=()=>subReach(1,1); // 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; @@ -742,6 +743,12 @@ function optModes(o,l){return (OPT[o].modes||[[OPT[o].g,OPT[o].reach]]).map(([g, } 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;} +// The longest subsea span any optic lights with these upgrades in service, and the cheapest upgrades a length needs +// (null: nothing can light it). The length limit, the order screen and refunds all use these, so they agree. +const SUBR=[],subReach=(t,e)=>SUBR[(t?1:0)+(e?2:0)]??(SUBR[(t?1:0)+(e?2:0)]=Math.max(...Object.keys(OPT).flatMap(o=>optModes(o,{kind:'df',own:true,sub:true,subterminal:t?0:undefined,subengineering:e?0:undefined}).map(m=>m[1])))), + subNeed=km=>km<=subReach(0,0)?[]:km<=subReach(1,0)?['terminal']:km<=subReach(0,1)?['engineering']:km<=subReach(1,1)?['terminal','engineering']:null; +// Upgrades a cable of this length still needs on top of the chosen ones; ['design'] when nothing can light it. +const seaLack=(km,up)=>{const n=subNeed(km);return n?n.filter(k=>!up[k]):['design'];}; 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;})); @@ -750,7 +757,8 @@ const waveCar=i=>LT[i].car||LT[i].g; function subWaveWhy(i,km,sub){if(!sub)return '';const c=subCarrier(km);return waveCar(i)>c?tr('{km} km of cable carries at most {g} per carrier.',{km:Math.round(km).toLocaleString(),g:fmtCap(c)}):'';} const subMaxTier=km=>{let t=0;LT.forEach((T,i)=>{if(!subWaveWhy(i,km,true))t=i;});return t;}; // What an optic carries depends only on the optic, the span length and subsea or not; the map and compute() ask a lot. -const OPTG={};const optG=(o,l)=>{const km=spanKm(l),m=OPTG[o]||(OPTG[o]=new Map()),k=km*2+(l.sub?1:0);let g=m.get(k);if(g===undefined){const x=optMode(o,l);m.set(k,g=x?x.g:0);}return g;}; +// Cached per optic, span and cable state: subsea, and which submarine upgrades are in service (#78). +const OPTG={};const optG=(o,l)=>{const km=spanKm(l),fl=l.sub?1+(subUpgradeReady(l,'terminal')?2:0)+(subUpgradeReady(l,'engineering')?4:0):0,c=OPTG[o]||(OPTG[o]=[]),m=c[fl]||(c[fl]=new Map());let g=m.get(km);if(g===undefined){const x=optMode(o,l);m.set(km,g=x?x.g:0);}return g;}; 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)*(l.loss&&l.loss.until>S.day?l.loss.f:1); @@ -2183,7 +2191,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);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;}); + 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&&Number.isFinite(l[f])&&l[f]>=0)l[f]=Math.round(l[f]);else delete l[f];}}if(l.paid!==undefined){if(l.own&&l.sub&&Number.isFinite(l.paid)&&l.paid>=0)l.paid=Math.round(l.paid);else delete l.paid;}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)); @@ -3042,16 +3050,16 @@ const ACT={ 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();}, + 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.paid=(l.paid>0?l.paid:ownCabCost(l.km))+subUpgradeCost(l,k);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);}, + ownCab:()=>{UI.lmode='df';UI.dfSrc='cable';UI.seaDesign='standard';UI.seaterminal=UI.seaengineering=false;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 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; + 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',up={terminal:!!UI.seaterminal,engineering:!!UI.seaengineering},q=seaQuote(a,b,design,up),km=q.km,cost=q.cost+(S.pops[b]?0:popCost(b));if(seaLack(km,up).length||!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=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; + const laid=S.links[S.links.length-1];laid.paid=q.cost;for(const k of Object.keys(SUB_UPGRADES))if(up[k])laid['sub'+k]=laid.ready;UI.seaDesign='standard';UI.seaterminal=UI.seaengineering=false; 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); @@ -3127,7 +3135,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=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()});} +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&&l.own)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].clsMath.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}}; +// Real low-latency builds (a straighter survey, more permits, a pricier route) took months longer, not years. +const SEA_DESIGNS={standard:{n:N_('Standard'),cost:1,time:1},optimized:{n:N_('Optimized'),cost:3,time:1.3},express:{n:N_('Low latency'),cost:7,time:1.7}}; 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);} +// Routing asks for link latency often; the cables on a route never change, so the express factor is worked out once. +const SEA_XF=new Map(); +function seaLatencyFactor(l){if(l.seaDesign==='optimized')return 1;if(l.seaDesign!=='express')return 1.1; + const k=CIDX[l.a]*4096+CIDX[l.b];let f=SEA_XF.get(k);if(f===undefined){const c=seaReference(l.a,l.b,true);SEA_XF.set(k,f=Math.min(0.9,c?(CAB[c.cid].lat||1):0.9));}return f;} 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. @@ -3976,31 +3986,32 @@ function seaQuote(a,b,design='standard',upgrades={}){ } // 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); -// What you get back for giving up your own subsea cable (#88): a cable no optic can light goes back in full, +// What you get back for giving up your own subsea cable (#88): what you paid for it (design and upgrades included) +// if no optic can light it even with both upgrades, // one still being laid returns most of the part not laid yet, a working one is yours for good. -const cabBack=l=>{if(!l||l.kind!=='df'||!l.own||!l.sub)return 0;const c=ownCabCost(l.km);if(!subCarrier(l.km))return c; +const cabBack=l=>{if(!l||l.kind!=='df'||!l.own||!l.sub)return 0;const c=l.paid>0?l.paid:ownCabCost(l.km);if(!subNeed(l.km))return c; if(l.ready>S.day){const tot=Math.max(1,l.ready-(l.day||0));return Math.round(c*0.75*Math.min(1,(l.ready-S.day)/tot));}return 0;}; function ownCabWhy(a,b){if(!seaCab(a,b))return tr('This route is on land. Build your own fiber instead.'); - {const km=ownCabKm(a,b);if(!subCarrier(km))return tr('{km} km is more than any optic can light, even on the best subsea gear ({max} km at most). Real cables stop at an island or a landing station on the way: lay two shorter ones.',{km:km.toLocaleString(),max:Math.round(SUB_MAXKM()).toLocaleString()});} + {const km=Math.min(...Object.keys(SEA_DESIGNS).map(v=>seaQuote(a,b,v).km));if(!subNeed(km))return tr('{km} km is more than any optic can light, even on the best subsea gear ({max} km at most). Real cables stop at an island or a landing station on the way: lay two shorter ones.',{km:km.toLocaleString(),max:Math.round(SUB_MAXKM()).toLocaleString()});} if(!S.won)return tr('Laying your own subsea cable is a Tier 1 thing. Go transit-free first.'); for(const c of [a,b])if(!landing(c))return tr('{city} has no cable landing station.',{city:CITY[c].name}); if(cnCity(a)||cnCity(b))return tr('Nobody gives a foreign network a landing licence in mainland China.'); 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 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; + 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,lack=seaLack(km,upgrades),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('Cable design')}

${Object.entries(SEA_DESIGNS).map(([v,D])=>{const o=seaQuote(a,b,v,upgrades);return ``;}).join('')}
+

${tr('Submarine transmission')}

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

${lack[0]==='design'?tr('This design’s route is {km} km: too long for any optics, even with both upgrades. A shorter design can make it.',{km:km.toLocaleString()}):tr('{km} km is too far for your optics on their own. Add {what} to light this cable.',{km:km.toLocaleString(),what:lack.length>1?tr('{a} and {b}',{a:tr(SUB_UPGRADES[lack[0]].n),b:tr(SUB_UPGRADES[lack[1]].n)}):tr(SUB_UPGRADES[lack[0]].n)})}

`:`

${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})}
${tr('Build time')}${tr('about {n} days',{n:days})}
${tr('Due now')}${fmt$(cost+pop)}
${tr('Monthly')}${tr('{price}/mo',{price:fmt$(mo)})}
-

${tr('A leased {wave} wave on this route costs {price}/mo.',{wave:LT[wt].n,price:fmt$(w)})} ${pay?tr('Replace 16 Tbps of them and the cable pays for itself in about {n} months.',{n:pay}):''} ${tr('Cuts still happen, anchors and sharks included, but the repair ship is yours to call.')}

-
${btn(tr('Lay the cable {price}',{price:fmt$(cost+pop)}),'orderCable',{},'pink big',S.cash`;} +

${subCarrier(km)?`${tr('A leased {wave} wave on this route costs {price}/mo.',{wave:LT[wt].n,price:fmt$(w)})} ${pay?tr('Replace 16 Tbps of them and the cable pays for itself in about {n} months.',{n:pay}):''} `:''}${tr('Cuts still happen, anchors and sharks included, but the repair ship is yours to call.')}

+
${btn(tr('Lay the cable {price}',{price:fmt$(cost+pop)}),'orderCable',{},'pink big',S.cash0)}${btn(tr('Back'),'dfSrc',{v:'lease'},'ghost')}
`;} function dfModalBody(a,b,km,pop){ if(seaCab(a,b)&&UI.dfSrc==='cable')return ownCabBody(a,b,pop); const sea=!isSub(a,b)&&seaCab(a,b)?ownCabTeaser(a,b):''; diff --git a/tests/issues.test.js b/tests/issues.test.js index 77e76d4..05ee434 100644 --- a/tests/issues.test.js +++ b/tests/issues.test.js @@ -1058,7 +1058,11 @@ test('#104 declining a loan offer clears the bank badge while paused', () => { test('#88 no subsea cable longer than any optic can light, and a refund for calling one off', () => { const { ev, errors } = load(); ev("ACT.start({});S.cash=1e10;S.lvl=13;S.won=true;for(const g of GOALS)S.done[g.id]=0"); - assert.match(ev("ownCabWhy('nyc','syd')"), /more than any optic can light/); + // New York to Sydney is too long for plain optics; since #78 premium terminals light it, so the order screen asks + // for them instead of refusing. Only a length beyond even both upgrades is refused. + assert.equal(ev("ownCabWhy('nyc','syd')"), ''); + assert.deepEqual(JSON.parse(ev("JSON.stringify(subNeed(ownCabKm('nyc','syd')))")), ['terminal']); + assert.equal(ev('subNeed(26000)'), null, 'nothing lights 26,000 km'); assert.equal(ev("ownCabWhy('lax','syd')"), '', 'Los Angeles to Sydney still works'); assert.ok(ev("subCarrier(ownCabKm('lax','syd'))") > 0); // half-way through laying it: most of the unlaid part comes back @@ -1071,7 +1075,9 @@ test('#88 no subsea cable longer than any optic can light, and a refund for call assert.equal(ev('S.cash') - c0, want); // a finished cable that works is yours for good; one nothing can light (old saves) goes back in full assert.equal(ev("cabBack({kind:'df',own:true,sub:true,km:ownCabKm('lax','syd'),ready:0})"), 0); - assert.equal(ev("cabBack({kind:'df',own:true,sub:true,km:18387,ready:0})"), ev('ownCabCost(18387)')); + assert.equal(ev("cabBack({kind:'df',own:true,sub:true,km:26000,ready:0})"), ev('ownCabCost(26000)')); + assert.equal(ev("cabBack({kind:'df',own:true,sub:true,km:26000,ready:0,paid:5e8})"), 5e8, 'what was really paid'); + assert.equal(ev("cabBack({kind:'df',own:true,sub:true,km:18387,ready:0})"), 0, 'a finished cable upgrades can light is yours for good'); assert.deepEqual(errors, []); }); diff --git a/tests/regions.test.js b/tests/regions.test.js index 9b1c16d..427078e 100644 --- a/tests/regions.test.js +++ b/tests/regions.test.js @@ -648,7 +648,8 @@ test('subsea cable designs trade construction cost and time for previewed latenc 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.ok(quotes[1].days >= quotes[0].days * 1.3 && quotes[2].days >= quotes[0].days * 1.7); + assert.ok(quotes[2].days < 3 * 365, 'a low-latency Atlantic cable takes years, not most of a decade'); 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()) { @@ -765,3 +766,45 @@ test('submarine upgrades reject invalid purchases and preserve baseline and terr assert.deepEqual(errors, []); } finally { dom.window.close(); } }); + +test('own subsea cables after #78: refunds of what was paid, upgrades a route needs, fresh choices', () => { + const { ev, errors } = load(); + ev("ACT.start({});S.cash=1e11;S.lvl=13;S.won=true;for(const g of GOALS)S.done[g.id]=0;for(const c of ['lon','nyc','syd'])if(!S.pops[c])ACT.buildPop({city:c})"); + const open = (a, b) => ev(`UI.pending=null;openLinkModal('${a}','${b}');ACT.ownCab()`); + const q = (sel) => ev(`(()=>{const e=document.querySelector('#modalCard ${sel}');return e?e.textContent:null;})()`); + // a low-latency cable called off at once returns 75% of what it really cost, not of a standard cable + open('lon', 'nyc'); + assert.equal(ev("document.querySelectorAll('#modalCard button.start[data-act=seaDesign]').length"), 3, 'each design is one tappable card'); + ev("document.querySelector('#modalCard [data-act=seaDesign][data-args*=express]').click()"); + assert.match(q('button.start.on'), /Low latency/); + const c0 = ev('S.cash'); ev('ACT.orderCable()'); + const lon = JSON.parse(ev("JSON.stringify(S.links.at(-1))")), paid = c0 - ev('S.cash'); + assert.equal(lon.seaDesign, 'express'); assert.equal(lon.paid, paid); + assert.equal(ev('cabBack(S.links.at(-1))'), Math.round(paid * 0.75)); + assert.equal(ev('UI.seaDesign'), 'standard', 'the next order starts from the standard design'); + // its latency is worked out once per route, and stays the same + const ms = ev('linkLat(S.links.at(-1))'); assert.equal(ev('linkLat(S.links.at(-1))'), ms); assert.ok(ev('SEA_XF.size') >= 1); + // New York to Sydney needs premium terminals: the screen says so and will not order without them + open('nyc', 'syd'); + assert.match(q('.why'), /Add Premium submarine terminals/); + assert.doesNotMatch(ev("document.getElementById('modalCard').textContent"), /A leased .* wave on this route/, 'no leased wave reaches that far, so no comparison with one'); + assert.equal(ev("document.querySelector('#modalCard [data-act=orderCable]').disabled"), true); + const n = ev('S.links.length'); ev('ACT.orderCable()'); assert.equal(ev('S.links.length'), n, 'the order itself checks too'); + ev("document.querySelector('#modalCard [data-act=seaPackage][data-args*=terminal]').click()"); + assert.equal(q('.why'), null); assert.match(q('[data-act=seaPackage][data-args*=terminal]'), /\+30 days/); + // leaving and coming back to another route starts fresh + open('lon', 'nyc'); assert.equal(ev('!!UI.seaterminal'), false); + open('nyc', 'syd'); ev("document.querySelector('#modalCard [data-act=seaPackage][data-args*=terminal]').click();ACT.orderCable()"); + const syd = JSON.parse(ev("JSON.stringify(S.links.at(-1))")); + assert.equal(syd.b, 'syd'); assert.equal(syd.subterminal, syd.ready); + ev('S.day=S.links.at(-1).ready'); assert.equal(ev("optG('tp16',S.links.at(-1))"), 400, 'lit across 18,387 km'); + // upgrades bought later count toward the price; sanitize keeps a sane price and drops junk + ev("S.links.at(-1).subengineering=undefined;ACT.subUpgrade({id:S.links.at(-1).id,k:'engineering'})"); + assert.ok(ev('S.links.at(-1).paid') > syd.paid); + ev("S.links.at(-1).paid='lots';S.links[0].paid=-5;S=sanitize(S)"); + assert.equal(ev('S.links.at(-1).paid'), undefined); assert.equal(ev('S.links[0].paid'), undefined); + // advice about upgrades only on cables you own + ev("S.links.push({id:'iru',a:'lon',b:'nyc',kind:'df',own:false,sub:true,km:30000,sys:'roadm',ch:[],ready:0,cut:0,mo:1})"); + assert.doesNotMatch(ev("chWhy(S.links.at(-1),'tp16')"), /submarine terminals/); + assert.deepEqual(errors, []); +});