Merge #204: Submarine upgrades that change nothing on a cable can't be bought (#198)

Submarine upgrades that change nothing on a cable can't be bought (#198)
This commit is contained in:
Frederic Jung 2026-10-30 19:51:19 +01:00 • committed by GitHub
commit 2d7aff4956
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 126 additions and 20 deletions

View file

@ -6,6 +6,7 @@ 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.
- A wave size that is sold out on a route can no longer be reached by upgrading a smaller wave on it (#201). The upgrade button says how long it is sold out, just like when buying.
- Choosing Both for a PNI with one member now really splits it: the second member arrives in the other building when the augment lands, instead of joining the first (#219).

View file

@ -3204,6 +3204,7 @@
"puzzles_weekly.ocean_crossing":"Ozeanüberquerung",
"puzzles_weekly.region_tour":"Rundreise",
"puzzles_weekly.ring":"Ring",
"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",

View file

@ -3202,6 +3202,7 @@
"puzzles_weekly.ocean_crossing":"Cruzar el océano",
"puzzles_weekly.region_tour":"Gira regional",
"puzzles_weekly.ring":"Anillo",
"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",

View file

@ -3202,6 +3202,7 @@
"puzzles_weekly.ocean_crossing":"Traversée de l’océan",
"puzzles_weekly.region_tour":"Tour de la région",
"puzzles_weekly.ring":"Anneau",
"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",

View file

@ -3202,6 +3202,7 @@
"puzzles_weekly.ocean_crossing":"Traversata oceanica",
"puzzles_weekly.region_tour":"Giro della regione",
"puzzles_weekly.ring":"Anello",
"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",

View file

@ -3202,6 +3202,7 @@
"puzzles_weekly.ocean_crossing":"Travessia do oceano",
"puzzles_weekly.region_tour":"Volta pela região",
"puzzles_weekly.ring":"Anel",
"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",

View file

@ -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.

View file

@ -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||l.seat||!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)+leadDays(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||l.seat||!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)+leadDays(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});

View file

@ -92,9 +92,9 @@ function chinaSection(c){const st=S.cnLic?S.cnLic.state:'none',loss=S.ev.gfw>S.d
if(R.gfwCross>0.5)h+=`<div class="kv"><span>${tr('link_panels.your_traffic_crossing_the_border')}</span><b>${fmtG(R.gfwCross)}</b></div><div class="kv"><span>${tr('link_panels.lost_on_the_way')}</span><b style="color:var(--bad)">${fmtG(R.gfwLost)}</b></div>`;
return h+`</section>`;}
function subUpgradePanel(l){return `<h4 class="sub4">${tr('common.submarine_transmission')}</h4><p class="note">${tr('common.better_terminals_and_optical_tuning')}</p>`+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:leadDays(U.days)});
return `<div class="row"><div class="grow"><div class="nm">${tr(U.n)}</div><div class="meta">${status}</div><div class="meta">${tr('common.up_to_g_per_channel',{g:fmtG(submarineRate(preview))})}</div></div>${at===undefined?btn(tr('common.install'),'subUpgrade',{id:l.id,k},'sm',lvl()<4||S.cash<cost):''}</div>`;}).join('');}
return `<div class="row"><div class="grow"><div class="nm">${tr(U.n)}</div><div class="meta">${status}</div><div class="meta">${tr('common.up_to_g_per_channel',{g:fmtG(submarineRate(preview))})}</div>${use?'':`<div class="why">${tr('reach_and_subsea.makes_no_difference_on_this_cable')}</div>`}</div>${at===undefined?btn(tr('common.install'),'subUpgrade',{id:l.id,k},'sm',!use||lvl()<4||S.cash<cost):''}</div>`;}).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=`<div class="ph"><div><div class="eyebrow">${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()})}</div><h2>${A} ⇄ ${B}</h2></div><button class="x" data-act="closePanel" aria-label="${tr('common.close')}">×</button></div><div class="scroll">`;

View file

@ -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)
@ -202,10 +206,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 `<div class="btns" style="margin-top:8px">${btn(cabOpen()?tr('modals.lay_your_own_subsea_cable'):tr('modals.your_own_subsea_cable_tier_1'),'ownCab',{},cabOpen()&&!why?'pink':'ghost',!!why)}</div>${why&&cabOpen()?`<p class="note" ${seaSurveyAttr(a,b)}>${esc(why)}</p>`:''}`;}
function ownCabBody(a,b,pop){const why=ownCabWhy(a,b);if(why)return `<p class="lead" style="margin-top:10px" ${seaSurveyAttr(a,b)}>${esc(why)}</p>${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 `<p class="lead" style="margin-top:8px">${tr('own_cable.your_very_own_subsea_cable_a')}</p>
<h4 class="sub4">${tr('common.cable_design')}</h4><div class="starts one">${Object.entries(SEA_DESIGNS).map(([v,D])=>{const o=seaQuote(a,b,v,upgrades);return `<button class="start ${design===v?'on':''}" data-act="seaDesign" data-args='{"v":"${v}"}'><b>${tr(D.n)}</b><span>${tr('common.ms_ms_one_way',{ms:o.ms.toFixed(1)})} · ${fmt$(o.cost+pop)} · ${tr('own_cable.about_n_days',{n:o.days})}</span></button>`;}).join('')}</div>
<h4 class="sub4">${tr('common.submarine_transmission')}</h4>${Object.entries(SUB_UPGRADES).map(([k,U])=>btn(`${tr(U.n)} <small>${upgrades[k]?'✓ · ':''}${fmt$(subUpgradeCost({km},k))} · ${tr('own_cable.n_days',{n:U.days})}</small>`,'seaPackage',{k},upgrades[k]?'green sm':'ghost sm')).join('')}
<h4 class="sub4">${tr('common.submarine_transmission')}</h4>${Object.entries(SUB_UPGRADES).map(([k,U])=>btn(`${tr(U.n)} <small>${upgrades[k]?'✓ · ':''}${fmt$(subUpgradeCost({km},k))} · ${tr('own_cable.n_days',{n:U.days})}</small>`,'seaPackage',{k},upgrades[k]?'green sm':'ghost sm',!upgrades[k]&&!subHelps(km,k,upgrades[subOther(k)]))).join('')}
${lack.length?`<p class="why">${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)})}</p>`:`<p class="note">${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')}</p>`}
<div class="kv"><span>${tr('common.estimated_latency')}</span><b>${tr('common.ms_ms_one_way',{ms:q.ms.toFixed(1)})}</b></div>
<div class="kv"><span>${tr('common.route')}</span><b>${tr('own_cable.km_km_of_seabed',{km:km.toLocaleString()})}</b></div>

View file

@ -3203,6 +3203,7 @@
"puzzles_weekly.ocean_crossing":"Ocean crossing",
"puzzles_weekly.region_tour":"Region tour",
"puzzles_weekly.ring":"Ring",
"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",

View file

@ -903,10 +903,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);
@ -977,9 +978,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

View file

@ -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(); }

View file

@ -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(); }
});