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.
This commit is contained in:
parent
48e6200c53
commit
f4c8400df1
14 changed files with 127 additions and 20 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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});
|
||||
|
|
|
|||
|
|
@ -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+=`<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: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">`;
|
||||
|
|
|
|||
|
|
@ -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 `<div class="btns" style="margin-top:8px">${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)}</div>${why&&S.won?`<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>
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue