From f4c8400df19793cde580570d1890197058d665f4 Mon Sep 17 00:00:00 2001 From: Frederic Jung Date: Thu, 29 Oct 2026 01:57:32 +0000 Subject: [PATCH] Submarine upgrades that change nothing on a cable can't be bought (#198) Premium submarine terminals and Optical engineering only extend the long-haul modes of the coherent optics. On many cable lengths (all of the Atlantic, and about 17,000-18,500 km like Atlanta to Sydney) neither changes what any optic carries, yet both could be bought. subHelps() compares every optic's rate with and without the upgrade, counting an upgrade that only helps together with the other one. The link panel disables Install with a note, ACT.subUpgrade refuses, and the cable order screen disables the toggle and only quotes and charges picks that still help on the chosen design. --- CHANGELOG.md | 2 + site/i18n/de.js | 1 + site/i18n/es.js | 1 + site/i18n/fr.js | 1 + site/i18n/it.js | 1 + site/i18n/pt.js | 1 + src/game/10-catalog/60-reach-and-subsea.js | 4 + src/game/90-actions/87-fiber-and-hardware.js | 7 +- src/game/93-ui/70-link-panels.js | 4 +- src/game/95-modals/80-own-cable.js | 8 +- src/i18n/en.js | 1 + tests/regions.test.js | 12 ++- tests/subsea-upgrade-timing.test.js | 18 ++-- tests/useless-subsea-upgrades.test.js | 86 ++++++++++++++++++++ 14 files changed, 127 insertions(+), 20 deletions(-) create mode 100644 tests/useless-subsea-upgrades.test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index eb2f3d5..57684cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ All notable changes to this project are documented here. The project follows ## [Unreleased] +- Premium submarine terminals and Optical engineering can no longer be bought on a cable where they would change nothing (#198). The button now says so, and an upgrade that only helps together with the other one stays available. + ## [1.37.0] — 2026-10-28 - Series of Tubes now speaks German. The game follows your browser's language the first time, and you can switch to German under Settings or on the title screen. Networking terms like Peering and Transit stay in English, the way network engineers say them. diff --git a/site/i18n/de.js b/site/i18n/de.js index 0b751b2..406acb4 100644 --- a/site/i18n/de.js +++ b/site/i18n/de.js @@ -2661,6 +2661,7 @@ "progress.under_attack_now":"Gerade unter Beschuss", "progress.your_score_peak_traffic":"Dein Ergebnis: Spitzen-Traffic", "progress.your_traffic_to_and_from_asia":"Dein Traffic von und nach Asien", +"reach_and_subsea.makes_no_difference_on_this_cable":"Bringt auf diesem Kabel nichts", "reach_and_subsea.premium_submarine_terminals":"Premium-Seekabel-Terminals", "release_notes.and_n_more_change":{"one":"… und {n} weitere Änderung","other":"… und {n} weitere Änderungen"}, "release_notes.read_the_full_notes_on_github":"Alle Hinweise auf GitHub lesen", diff --git a/site/i18n/es.js b/site/i18n/es.js index 2f2a645..d602285 100644 --- a/site/i18n/es.js +++ b/site/i18n/es.js @@ -2659,6 +2659,7 @@ "progress.under_attack_now":"Bajo ataque ahora", "progress.your_score_peak_traffic":"Tu puntuación: tráfico pico", "progress.your_traffic_to_and_from_asia":"Tu tráfico desde y hacia Asia", +"reach_and_subsea.makes_no_difference_on_this_cable":"No cambia nada en este cable", "reach_and_subsea.premium_submarine_terminals":"Terminales submarinas premium", "release_notes.and_n_more_change":{"one":"…y {n} cambio más","other":"…y {n} cambios más"}, "release_notes.read_the_full_notes_on_github":"Lee las notas completas en GitHub", diff --git a/site/i18n/fr.js b/site/i18n/fr.js index 413ae5f..6c5dc0e 100644 --- a/site/i18n/fr.js +++ b/site/i18n/fr.js @@ -2659,6 +2659,7 @@ "progress.under_attack_now":"Sous attaque", "progress.your_score_peak_traffic":"Ton score : pic de trafic", "progress.your_traffic_to_and_from_asia":"Ton trafic vers et depuis l’Asie", +"reach_and_subsea.makes_no_difference_on_this_cable":"Ne change rien sur ce câble", "reach_and_subsea.premium_submarine_terminals":"Terminaux sous-marins premium", "release_notes.and_n_more_change":{"one":"…et {n} autre changement","other":"…et {n} autres changements"}, "release_notes.read_the_full_notes_on_github":"Lire les notes complètes sur GitHub", diff --git a/site/i18n/it.js b/site/i18n/it.js index 103bc61..339a2d3 100644 --- a/site/i18n/it.js +++ b/site/i18n/it.js @@ -2659,6 +2659,7 @@ "progress.under_attack_now":"Sotto attacco ora", "progress.your_score_peak_traffic":"Il tuo punteggio: picco di traffico", "progress.your_traffic_to_and_from_asia":"Il tuo traffico da e per l’Asia", +"reach_and_subsea.makes_no_difference_on_this_cable":"Su questo cavo non cambia nulla", "reach_and_subsea.premium_submarine_terminals":"Terminali sottomarini avanzati", "release_notes.and_n_more_change":{"one":"…e {n} altra modifica","other":"…e altre {n} modifiche"}, "release_notes.read_the_full_notes_on_github":"Leggi le note complete su GitHub", diff --git a/site/i18n/pt.js b/site/i18n/pt.js index 046f9a8..1dc3071 100644 --- a/site/i18n/pt.js +++ b/site/i18n/pt.js @@ -2659,6 +2659,7 @@ "progress.under_attack_now":"Sob ataque agora", "progress.your_score_peak_traffic":"Sua pontuação: pico de tráfego", "progress.your_traffic_to_and_from_asia":"Seu tráfego de e para a Ásia", +"reach_and_subsea.makes_no_difference_on_this_cable":"Não faz diferença neste cabo", "reach_and_subsea.premium_submarine_terminals":"Terminais submarinos premium", "release_notes.and_n_more_change":{"one":"…e mais {n} mudança","other":"…e mais {n} mudanças"}, "release_notes.read_the_full_notes_on_github":"Leia as notas completas no GitHub", diff --git a/src/game/10-catalog/60-reach-and-subsea.js b/src/game/10-catalog/60-reach-and-subsea.js index 9ff08a3..3e46b70 100644 --- a/src/game/10-catalog/60-reach-and-subsea.js +++ b/src/game/10-catalog/60-reach-and-subsea.js @@ -53,6 +53,10 @@ const subMaxTier=km=>{let t=0;LT.forEach((T,i)=>{if(!subWaveWhy(i,km,true))t=i;} // What an optic carries depends only on the optic, the span length and subsea or not; the map and compute() ask a lot. // 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;}; +// Whether upgrade k changes what any optic carries on a subsea cable this long (#198). has: the other upgrade is +// already in; otherwise k also counts when it only helps together with the other one. +const subOther=k=>k==='terminal'?'engineering':'terminal',subHelps=(km,k,has)=>{const j=subOther(k),c=(on,o)=>({kind:'df',own:true,sub:true,km,['sub'+k]:on?0:undefined,['sub'+j]:o?0:undefined}); + return (has?[1]:[0,1]).some(o=>Object.keys(OPT).some(x=>optG(x,c(1,o))!==optG(x,c(0,o))));}; const regenNeed=(o,l)=>Math.max(0,Math.ceil(l.km/OPT[o].reach)-1); // The map asks for every fiber's capacity several times per frame (width, colour, label, up or down), each time over // all its channels. Nothing changes while a frame is drawn, so draw() keeps the answers in DFC for that frame. diff --git a/src/game/90-actions/87-fiber-and-hardware.js b/src/game/90-actions/87-fiber-and-hardware.js index af3a450..474d618 100644 --- a/src/game/90-actions/87-fiber-and-hardware.js +++ b/src/game/90-actions/87-fiber-and-hardware.js @@ -1,12 +1,13 @@ Object.assign(ACT,{ 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.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();}, + seaPackage:({k})=>{const p=UI.pending;if(!own(SUB_UPGRADES,k)||!p)return;const km=seaQuote(p.a,p.b,own(SEA_DESIGNS,UI.seaDesign)?UI.seaDesign:'standard').km,up=seaUps(km); + if(!up[k]&&!subHelps(km,k,up[subOther(k)]))return;UI.seaterminal=up.terminal;UI.seaengineering=up.engineering;UI['sea'+k]=!up[k];openLinkModal(p.a,p.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||!subHelps(l.km,k,l['sub'+subOther(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';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',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; + 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=seaUps(seaQuote(a,b,design).km),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,seaPath:q.pts.map(p=>p.slice()),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}); diff --git a/src/game/93-ui/70-link-panels.js b/src/game/93-ui/70-link-panels.js index 0378b3f..582542a 100644 --- a/src/game/93-ui/70-link-panels.js +++ b/src/game/93-ui/70-link-panels.js @@ -66,9 +66,9 @@ function chinaSection(c){const st=S.cnLic?S.cnLic.state:'none',loss=S.ev.gfw>S.d if(R.gfwCross>0.5)h+=`
${tr('link_panels.your_traffic_crossing_the_border')}${fmtG(R.gfwCross)}
${tr('link_panels.lost_on_the_way')}${fmtG(R.gfwLost)}
`; return h+``;} function subUpgradePanel(l){return `

${tr('common.submarine_transmission')}

${tr('common.better_terminals_and_optical_tuning')}

`+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 at=l['sub'+k],done=subUpgradeReady(l,k),cost=subUpgradeCost(l,k),preview={...l,['sub'+k]:S.day},use=at!==undefined||subHelps(l.km,k,l['sub'+subOther(k)]!==undefined); const status=done?tr('common.installed'):at!==undefined?tr('link_panels.ready_in_n_days',{n:Math.max(0,at-S.day)}):tr('link_panels.price_n_days',{price:fmt$(cost),n:U.days}); - return `
${tr(U.n)}
${status}
${tr('common.up_to_g_per_channel',{g:fmtG(submarineRate(preview))})}
${at===undefined?btn(tr('common.install'),'subUpgrade',{id:l.id,k},'sm',lvl()<4||S.cash`;}).join('');} + return `
${tr(U.n)}
${status}
${tr('common.up_to_g_per_channel',{g:fmtG(submarineRate(preview))})}
${use?'':`
${tr('reach_and_subsea.makes_no_difference_on_this_cable')}
`}
${at===undefined?btn(tr('common.install'),'subUpgrade',{id:l.id,k},'sm',!use||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('link_panels.dark_fiber_kind_km_km',{kind:l.own?tr('link_panels.your_own_build'):tr('common.leased_iru'),km:l.km.toLocaleString()})}

${A} ⇄ ${B}

`; diff --git a/src/game/95-modals/80-own-cable.js b/src/game/95-modals/80-own-cable.js index aaa986e..630d0c9 100644 --- a/src/game/95-modals/80-own-cable.js +++ b/src/game/95-modals/80-own-cable.js @@ -183,6 +183,10 @@ function seaQuote(a,b,design='standard',upgrades={}){ const ms=linkLat({a,b,kind:'df',own:true,sub:true,km,seaDesign:design}); return {km,cost,days,ms,pts:route?.pts,shore:route?.shore,cor:!!cor&&route===cor}; } +// The picked upgrades that change something on a cable this long (#198): a pick can stop helping when the design +// or the other pick changes. When each makes the other redundant, keep the cheaper terminals. +const seaUps=km=>{const up={terminal:!!UI.seaterminal,engineering:!!UI.seaengineering}; + for(const k of ['engineering','terminal'])if(up[k]&&!subHelps(km,k,up[subOther(k)]))up[k]=false;return up;}; // 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): what you paid for it (design and upgrades included) @@ -200,10 +204,10 @@ function ownCabWhy(a,b){if(!seaCab(a,b))return tr('own_cable.this_route_is_on_la return '';} function ownCabTeaser(a,b){const why=ownCabWhy(a,b);return `
${btn(S.won?tr('modals.lay_your_own_subsea_cable'):tr('modals.your_own_subsea_cable_tier_1'),'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('common.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,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; + const design=own(SEA_DESIGNS,UI.seaDesign)?UI.seaDesign:'standard',upgrades=seaUps(seaQuote(a,b,design).km),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('own_cable.your_very_own_subsea_cable_a')}

${tr('common.cable_design')}

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

${tr('common.submarine_transmission')}

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

${tr('common.submarine_transmission')}

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

${lack[0]==='design'?tr('own_cable.this_design_s_route_is_km',{km:km.toLocaleString()}):tr('own_cable.km_km_is_too_far_for',{km:km.toLocaleString(),what:lack.length>1?tr('own_cable.a_and_b',{a:tr(SUB_UPGRADES[lack[0]].n),b:tr(SUB_UPGRADES[lack[1]].n)}):tr(SUB_UPGRADES[lack[0]].n)})}

`:`

${tr('common.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('common.better_terminals_and_optical_tuning')}

`}
${tr('common.estimated_latency')}${tr('common.ms_ms_one_way',{ms:q.ms.toFixed(1)})}
${tr('common.route')}${tr('own_cable.km_km_of_seabed',{km:km.toLocaleString()})}
diff --git a/src/i18n/en.js b/src/i18n/en.js index 008cdfd..4212756 100644 --- a/src/i18n/en.js +++ b/src/i18n/en.js @@ -2660,6 +2660,7 @@ "progress.under_attack_now":"Under attack now", "progress.your_score_peak_traffic":"Your score: peak traffic", "progress.your_traffic_to_and_from_asia":"Your traffic to and from Asia", +"reach_and_subsea.makes_no_difference_on_this_cable":"Makes no difference on this cable", "reach_and_subsea.premium_submarine_terminals":"Premium submarine terminals", "release_notes.and_n_more_change":{"one":"…and {n} more change","other":"…and {n} more changes"}, "release_notes.read_the_full_notes_on_github":"Read the full notes on GitHub", diff --git a/tests/regions.test.js b/tests/regions.test.js index 1ac3be1..b2dc55c 100644 --- a/tests/regions.test.js +++ b/tests/regions.test.js @@ -898,10 +898,11 @@ test('submarine terminal and engineering upgrades commission independently and c 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("ACT.start({});S.cash=1e9;S.lvl=4;S.won=true;for(const g of GOALS)S.done[g.id]=0;ACT.buildPop({city:'sin'});ACT.buildPop({city:'lax'});UI.lmode='df';UI.dfSrc='cable';openLinkModal('sin','lax')"); + // Across the Pacific, where the two packages together lift it from 400G to 800G (#198). + const baseline = JSON.parse(ev("JSON.stringify(seaQuote('sin','lax'))")); 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}))")); + const quote = JSON.parse(ev("JSON.stringify(seaQuote('sin','lax','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); @@ -972,9 +973,12 @@ test('own subsea cables after #78: refunds of what was paid, upgrades a route ne 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 + // engineering adds nothing once the terminals light it (#198); upgrades bought later count toward the price ev("S.links.at(-1).subengineering=undefined;ACT.subUpgrade({id:S.links.at(-1).id,k:'engineering'})"); + assert.equal(ev('S.links.at(-1).paid'), syd.paid); + ev("S.links.at(-1).subterminal=undefined;ACT.subUpgrade({id:S.links.at(-1).id,k:'engineering'})"); assert.ok(ev('S.links.at(-1).paid') > syd.paid); + // sanitize keeps a sane price and drops junk 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 diff --git a/tests/subsea-upgrade-timing.test.js b/tests/subsea-upgrade-timing.test.js index d2d6a55..0f88d39 100644 --- a/tests/subsea-upgrade-timing.test.js +++ b/tests/subsea-upgrade-timing.test.js @@ -4,7 +4,7 @@ const { load } = require('./harness'); function setup(ev) { ev(`ACT.start({});S.cash=1e11;S.lvl=13;S.day=100;for(const g of GOALS)S.done[g.id]=0; - S.links=[{id:'cable',a:'lag',b:'bde',kind:'df',own:true,sub:true,sys:'roadm',km:7000,ch:[],day:100,ready:1000,cut:0,mo:1}];`); + S.links=[{id:'cable',a:'lag',b:'bde',kind:'df',own:true,sub:true,sys:'roadm',km:15000,ch:[],day:100,ready:1000,cut:0,mo:1}];`); } function dates(ev) { @@ -55,7 +55,7 @@ test('packages included in the original order stay aligned with its accelerated const { ev, dom } = load(); try { setup(ev); - ev("S.won=true;UI.pending={a:'lag',b:'bde'};UI.seaterminal=UI.seaengineering=true;ACT.orderCable();S.links=[S.links.at(-1)]"); + ev("S.won=true;UI.pending={a:'sin',b:'lax'};UI.seaterminal=UI.seaengineering=true;ACT.orderCable();S.links=[S.links.at(-1)]"); assert.equal(ev('S.links[0].subterminal'), ev('S.links[0].ready')); assert.equal(ev('S.links[0].subengineering'), ev('S.links[0].ready')); ev("ACT.crews({id:S.links[0].id})"); @@ -129,11 +129,11 @@ test('one-click completion costs the same as repeated crew hires and advances pe const button = [...dom.window.document.querySelectorAll('#panelBody [data-act=crews]')].find(b => JSON.parse(b.dataset.args).all); assert.ok(button && !button.disabled, 'one-click option is available'); const cash = ev('S.cash'); - assert.ok(button.textContent.includes(ev('fmt$(30*Math.round(15000+7000*6))')), 'full price is shown before purchase'); + assert.ok(button.textContent.includes(ev('fmt$(30*Math.round(15000+15000*6))')), 'full price is shown before purchase'); button.click(); const bulkDates = dates(ev), bulkCash = ev('S.cash'); assert.deepEqual(bulkDates, [101, 131, 281]); - assert.equal(cash - bulkCash, 30 * 57000); + assert.equal(cash - bulkCash, 30 * 105000); const after = [...dom.window.document.querySelectorAll('#panelBody [data-act=crews]')]; assert.ok(after.every(b => b.disabled), 'both options stop at one day'); ev("ACT.crews({id:'cable',all:1})"); @@ -150,18 +150,18 @@ test('one-click completion is atomic when unaffordable and handles short or comp const { ev, dom } = load(); try { setup(ev); - ev("S.cash=30*57000-1;UI.sel={type:'link',id:'cable'};renderPanel()"); + ev("S.cash=30*105000-1;UI.sel={type:'link',id:'cable'};renderPanel()"); const bulk = [...dom.window.document.querySelectorAll('#panelBody [data-act=crews]')].find(b => JSON.parse(b.dataset.args).all); assert.equal(bulk.disabled, true); ev("ACT.crews({id:'cable',all:1})"); - assert.equal(ev('S.cash'), 30 * 57000 - 1); + assert.equal(ev('S.cash'), 30 * 105000 - 1); assert.equal(ev('S.links[0].ready'), 1000, 'no partial purchase'); - ev("S.cash=57000;S.links[0].ready=102;ACT.crews({id:'cable',all:1})"); + ev("S.cash=105000;S.links[0].ready=102;ACT.crews({id:'cable',all:1})"); assert.equal(ev('S.cash'), 0); assert.equal(ev('S.links[0].ready'), 101, 'two days remaining costs one normal hire'); assert.match(dom.window.document.body.textContent, /Construction is 1 day ahead\./); - ev("S.cash=57000;S.day=101;ACT.crews({id:'cable',all:1})"); - assert.equal(ev('S.cash'), 57000, 'completed construction cannot be rushed'); + ev("S.cash=105000;S.day=101;ACT.crews({id:'cable',all:1})"); + assert.equal(ev('S.cash'), 105000, 'completed construction cannot be rushed'); ev("S.day=100;S.links[0].ready=1000;S.links[0].own=false;ACT.crews({id:'cable',all:1})"); assert.equal(ev('S.links[0].ready'), 1000, 'leased handovers cannot buy construction crews'); } finally { dom.window.close(); } diff --git a/tests/useless-subsea-upgrades.test.js b/tests/useless-subsea-upgrades.test.js new file mode 100644 index 0000000..b0f790c --- /dev/null +++ b/tests/useless-subsea-upgrades.test.js @@ -0,0 +1,86 @@ +const test = require('node:test'); +const assert = require('node:assert/strict'); +const { load } = require('./harness'); + +// #198: submarine upgrades that change nothing on a cable can't be bought. +function cable(ev, km) { + ev(`ACT.start({});S.cash=1e11;S.lvl=13;S.day=100;S.won=true;for(const g of GOALS)S.done[g.id]=0; + S.links=[{id:'c',a:'atn',b:'syd',kind:'df',own:true,sub:true,sys:'roadm',km:${km},ch:['tp16'],day:0,ready:50,cut:0,mo:1}]; + UI.sel={type:'link',id:'c'};renderPanel()`); +} +const installBtn = (dom, k) => dom.window.document.querySelector(`#panelBody [data-act=subUpgrade][data-args*="${k}"]`); + +test('#198 upgrades that do nothing on a long Pacific cable are disabled and refused', () => { + const { ev, dom, errors } = load(); + try { + cable(ev, 17500); // about Atlanta to Sydney: 400G per channel with or without upgrades + for (const k of ['terminal', 'engineering']) { + assert.equal(installBtn(dom, k).disabled, true, `${k} button disabled`); + const cash = ev('S.cash'); + ev(`ACT.subUpgrade({id:'c',k:'${k}'})`); + assert.equal(ev('S.cash'), cash, `${k}: no charge`); + assert.equal(ev(`S.links[0].sub${k}`), undefined, `${k}: not installed`); + } + assert.match(dom.window.document.getElementById('panelBody').textContent, /Makes no difference on this cable/); + assert.deepEqual(errors, []); + } finally { dom.window.close(); } +}); + +test('#198 upgrades that only help together stay buyable, and one made useless by the other is not', () => { + const { ev, dom, errors } = load(); + try { + cable(ev, 15000); // each alone: 400G, both: 800G + assert.equal(installBtn(dom, 'terminal').disabled, false); + assert.equal(installBtn(dom, 'engineering').disabled, false); + ev("ACT.subUpgrade({id:'c',k:'terminal'})"); + assert.ok(ev('S.links[0].subterminal') > 0, 'terminal bought'); + ev('renderPanel()'); + assert.equal(installBtn(dom, 'engineering').disabled, false, 'engineering finishes the job'); + ev("ACT.subUpgrade({id:'c',k:'engineering'})"); + assert.ok(ev('S.links[0].subengineering') > 0, 'engineering bought'); + + cable(ev, 20000); // terminal lights it; engineering adds nothing once terminal is in + ev("ACT.subUpgrade({id:'c',k:'terminal'});renderPanel()"); + assert.ok(ev('S.links[0].subterminal') > 0); + assert.equal(installBtn(dom, 'engineering').disabled, true); + ev("ACT.subUpgrade({id:'c',k:'engineering'})"); + assert.equal(ev('S.links[0].subengineering'), undefined); + assert.deepEqual(errors, []); + } finally { dom.window.close(); } +}); + +test('#198 ordering a cable: useless upgrades can not be picked, and stale picks are not charged', () => { + const { ev, dom, errors } = load(); + try { + ev("ACT.start({});S.cash=1e11;S.lvl=13;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';UI.seaDesign='standard';openLinkModal('lon','nyc')"); + // A transatlantic cable already runs every optic at its long-haul best. + const btn = k => dom.window.document.querySelector(`#modalCard [data-act=seaPackage][data-args*="${k}"]`); + assert.equal(btn('terminal').disabled, true); + assert.equal(btn('engineering').disabled, true); + ev("ACT.seaPackage({k:'terminal'})"); + assert.equal(ev('!!UI.seaterminal'), false, 'refused'); + // Picks left over from a longer route (or a different design) neither show as picked nor get charged. + ev("UI.seaterminal=true;UI.seaengineering=true;ACT.seaDesign({v:'standard'})"); + assert.equal(btn('terminal').textContent.includes('✓'), false); + assert.equal(btn('engineering').textContent.includes('✓'), false); + const cash = ev('S.cash'), cost = ev("seaQuote('lon','nyc','standard').cost"); + ev('ACT.orderCable()'); + assert.equal(cash - ev('S.cash'), cost, 'no upgrade charged'); + assert.deepEqual(errors, []); + } finally { dom.window.close(); } +}); + +test('#198 ordering a transpacific cable: both upgrades help together, and the redundant one of a pair drops out', () => { + const { ev, dom, errors } = load(); + try { + ev("ACT.start({});S.cash=1e11;S.lvl=13;S.won=true;for(const g of GOALS)S.done[g.id]=0;ACT.buildPop({city:'sin'});ACT.buildPop({city:'lax'});UI.lmode='df';UI.dfSrc='cable';ACT.ownCab();UI.pending={a:'sin',b:'lax'};openLinkModal('sin','lax')"); + const km = ev("seaQuote('sin','lax','standard').km"); + assert.ok(km > 14000 && km < 17000, 'a route where only both upgrades together beat 400G'); + ev("ACT.seaPackage({k:'terminal'});ACT.seaPackage({k:'engineering'})"); + assert.equal(ev('!!UI.seaterminal&&!!UI.seaengineering'), true, 'both picked'); + assert.equal(ev("JSON.stringify(seaUps(seaQuote('sin','lax','standard').km))"), '{"terminal":true,"engineering":true}'); + // At 20,000 km either one alone lights the cable, so a pair keeps only the cheaper terminals. + assert.equal(ev("JSON.stringify(seaUps(20000))"), '{"terminal":true,"engineering":false}'); + assert.deepEqual(errors, []); + } finally { dom.window.close(); } +});