Give POPs built by links, fiber, cables and seats the standard routers (#261)

Only Build POP applied the standard. A wave, dark fiber, own subsea cable
or consortium seat to a new city now applies it too, and their offers
quote newPopCost() (the site plus the standard's routers).
This commit is contained in:
Frederic Jung 2026-11-02 21:45:30 +01:00
parent 1a4a62d0f2
commit da1a4e2f3c
No known key found for this signature in database
8 changed files with 34 additions and 8 deletions

View file

@ -6,7 +6,7 @@ All notable changes to this project are documented here. The project follows
## [Unreleased]
- The Build POP button now shows the whole price of a new POP, including the routers of your standard POP (#261). Before, it showed only the site, although the standard routers were paid for on top; a note under the button now lists them, and the intern's one-tap template prices them in as well.
- The Build POP button now shows the whole price of a new POP, including the routers of your standard POP (#261). Before, it showed only the site, although the standard routers were paid for on top; a note under the button now lists them, and the intern's one-tap template prices them in as well. POPs that come with a new wave, dark fiber, your own subsea cable or a consortium seat now get the standard routers too, and those offers show the price with them.
## [2.5.0] — 2026-11-02

View file

@ -58,7 +58,7 @@ const seatRoute=name=>Object.values(SEAT_ROUTES).flat().find(r=>r[2]===name);
function seatOffer(c,d){const rs=(c?SEAT_ROUTES[c]||[]:Object.values(SEAT_ROUTES).flat()).filter(r=>isCity(r[0])&&isCity(r[1])&&(c||S.pops[r[0]]||S.pops[r[1]])&&!S.links.some(l=>l.seat&&l.cname===r[2]));
if(!rs.length)return null;const r=rs[hstr(S.asn+'|seat|'+d)%rs.length];return {a:r[0],b:r[1],name:r[2],km:seatKm(r[0],r[1]),exp:d+SEAT_EXP};}
function seatConf(c){if(S.seatOff||lvl()<SEAT_LV||S.scn)return;S.seatOff=seatOffer(c,S.day);if(S.seatOff)toast(tr('specialist.a_consortium_is_selling_seats_on',{name:esc(S.seatOff.name),a:CITY[S.seatOff.a].name,b:CITY[S.seatOff.b].name}),'goal',[{l:tr('common.show_me'),act:'leftTab',args:{t:'deals'}}]);}
function seatSection(){const o=S.seatOff;if(!o||o.exp<=S.day)return '';const pop=[o.a,o.b].filter(c=>!S.pops[c]).reduce((x,c)=>x+popCost(c),0);
function seatSection(){const o=S.seatOff;if(!o||o.exp<=S.day)return '';const pop=[o.a,o.b].filter(c=>!S.pops[c]).reduce((x,c)=>x+newPopCost(c),0);
return `<div class="inc" style="background:#E6F4FF"><div class="nm">🚢 ${tr('specialist.consortium_seat_name',{name:esc(o.name)})}</div><div class="meta">${tr('specialist.a_b_km_km_ready_in',{a:CITY[o.a].name,b:CITY[o.b].name,km:o.km.toLocaleString(),n:seatDays(o.km),ms:linkLat({kind:'df',own:true,sub:true,km:o.km,seaDesign:'standard'}).toFixed(1)})} · ${tr('ui.n_d_left',{n:o.exp-S.day})}</div>
<div class="meta">${tr('specialist.your_own_fiber_pairs_on_a')}${pop?' '+tr('specialist.includes_pops_at_the_landings_price',{price:fmt$(pop)}):''}</div>
<div class="btns">${SEAT_N.map(n=>{const c=seatCost(o.km,n)+pop;return btn(`${trn('specialist.n_fiber_pairs',n)} <small>${fmt$(c)} · ${tr('common.price_mo',{price:fmt$(seatMo(o.km,n))})}</small>`,'seatBuy',{n},'sm',S.cash<c);}).join('')}${btn(tr('common.decline'),'seatNo',{},'ghost sm')}</div></div>`;}

View file

@ -5,6 +5,8 @@
function popStdQuote(){const d=S.popStd;if(!d||pzOn())return null;const g=techOk('rg',d.g,RG[d.g].lvl)?d.g:0;
let cost=g?Math.max(0,Math.round(RG[g].cost*hwMul('rt')*techMul(RG[g].lvl))-tradeIn(0,1)):0;for(let n=1;n<d.rt;n++)cost+=routerCost(g,n);
const mo=(d.rt-1)*ROUTER_MO+cageMo(d.rt)+d.rt*RG[g].mo-RG[0].mo;return cost||mo?{cost,mo,g,rt:d.rt}:null;}
// A new POP's setup with the standard's routers, for every way a POP gets built (links, cables, seats).
function newPopCost(c){const q=popStdQuote();return popCost(c)+(q?q.cost:0);}
function popStdApply(city){const d=S.popStd,p=S.pops[city];if(!d||!p||pzOn())return;let miss=false;const c0=S.cash;
if(d.g!==(p.rgen||0)){if(techOk('rg',d.g,RG[d.g].lvl)&&S.cash>=swapCost(city,d.g)){spend(swapCost(city,d.g));p.rgen=d.g;}else miss=true;}
while((p.routers||1)<d.rt){const k=routerCost(p.rgen||0,p.routers||1);if(S.cash<k){miss=true;break;}spend(k);p.routers=(p.routers||1)+1;}

View file

@ -19,7 +19,7 @@ Object.assign(ACT,{
if(!waveOk(a,b,tier)){toast(tr('links.a_wave_wave_needs_need_at',{wave:LT[tier].n,need:esc(waveNeed(tier))}),'bad');sfx('err');return;}
const wr=waveRoute(a,b,mult,border);if(!wr){toast(tr('links.no_cable_available_for_that_route'),'bad');sfx('err');return;}
{const so=soldOut(a,b,tier,wr.cab);if(so){toast(tr('links.no_wave_capacity_on_this_route',{wave:LT[tier].n,why:tr(so.why),n:Math.max(1,so.until-S.day)}),'bad');sfx('err');return;}}{const w=subWaveWhy(tier,wr.km,wr.sub);if(w){toast(tr('links.no_wave_waves_on_this_cable',{wave:LT[tier].n,why:esc(w)}),'bad');sfx('err');return;}}const base=Math.round(waveMo(wr.km,wr.sub,tier)*wr.wm),cost=base+(S.pops[b]?0:popCost(b));
if(!portGate(a,1)||!portGate(b,1))return;if(!spend(cost))return;if(!S.pops[b])S.pops[b]={day:S.day,bb:null,boost:0,down:0,routers:1,gen:false};
if(!portGate(a,1)||!portGate(b,1))return;if(!spend(cost))return;if(!S.pops[b]){S.pops[b]={day:S.day,bb:null,boost:0,down:0,routers:1,gen:false};popStdApply(b);}
const id=uid();const l={id,a,b,kind:'wave',border,premium:border&&!!UI.cnPrem&&(a==='hkg'||b==='hkg'),tier,km:wr.km,sub:wr.sub,cable:wr.cab,mo:base,mult:wr.wm,trench:wr.cab?'cab:'+wr.cab:(jn?jn.k:id),cut:0,day:S.day};S.links.push(l);closeModal();
if(sib.length){UI.sel={type:'link',id};}else{UI.sel={type:'city',id:b};UI.tab='cust';}
floater((CITY[a].x+CITY[a].x+wrapDx(CITY[a].x,CITY[b].x))/2,(CITY[a].y+CITY[b].y)/2-20,tr('links.wave_lit',{wave:LT[tier].n}),'#FF4F9A');after();},

View file

@ -2,7 +2,7 @@ Object.assign(ACT,{
demoAsk:({k,id})=>{const it=demoItem(k,id);if(!it||!demoCan(it.lvl)||demoAt(k,id)!==null)return;S.demo=S.demo||{};const at=S.day+leadDays(DEMO_DAYS);S.demo[k+':'+id]=at;
toast(tr('specialist.the_vendor_ships_a_demo_name',{name:esc(it.n),n:at-S.day,p:Math.round((DEMO_MUL-1)*100)}),'good');after();},
seatBuy:({n})=>{const o=S.seatOff;n=+n;if(!o||o.exp<=S.day||!SEAT_N.includes(n))return;const miss=[o.a,o.b].filter(c=>!S.pops[c]),cost=seatCost(o.km,n)+miss.reduce((x,c)=>x+popCost(c),0);if(!spend(cost))return;
for(const c of miss)S.pops[c]={day:S.day,bb:null,boost:0,down:0,routers:1,gen:false,rgen:0};
for(const c of miss){S.pops[c]={day:S.day,bb:null,boost:0,down:0,routers:1,gen:false,rgen:0};popStdApply(c);}
const id=uid(),days=seatDays(o.km);S.links.push({id,a:o.a,b:o.b,kind:'df',own:true,sub:true,seat:true,seaDesign:'standard',sys:'roadm',ch:[],km:o.km,cable:null,cname:o.name,mo:seatMo(o.km,n),trench:'seat:'+id,cut:0,day:S.day,ready:S.day+days,spares:false,pairs:n,paid:seatCost(o.km,n)});
S.seatOff=null;S.stats.seats=(S.stats.seats||0)+1;UI.sel={type:'link',id};
toast(tr('specialist.you_own_n_fiber_pairs_on',{n,name:esc(o.name),a:CITY[o.a].name,b:CITY[o.b].name,d:days}),'goal');sfx('build');after();},

View file

@ -8,7 +8,7 @@ Object.assign(ACT,{
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=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};
if(!S.pops[b]){S.pops[b]={day:S.day,bb:null,boost:0,down:0,routers:1,gen:false,rgen:0};popStdApply(b);}
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}`,id=uid(),ship=layName({id}),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});
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;
@ -17,7 +17,7 @@ Object.assign(ACT,{
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);
const own=UI.dfSrc==='build'&&!sc,sys=DF_SYS[UI.dfSys]&&techOk('sys',UI.dfSys,DF_SYS[UI.dfSys].lvl)?UI.dfSys:'lite';if(lvl()<2)return;
const up=(own?digCost(km):0)+sysCost(sys)+ampCount(km)*AMP_COST+(S.pops[b]?0:popCost(b));if(!spend(up))return;
if(!S.pops[b])S.pops[b]={day:S.day,bb:null,boost:0,down:0,routers:1,gen:false,rgen:0};
if(!S.pops[b]){S.pops[b]={day:S.day,bb:null,boost:0,down:0,routers:1,gen:false,rgen:0};popStdApply(b);}
const sib=pairLinks(a,b).filter(l=>l.kind!=='vxc'),id=uid();
const l={id,a,b,kind:'df',own,sys,ch:[],km,sub:!!sc,cable:sc?sc.cid:null,mo:own?Math.round(km*0.15):dfLeaseMo(km),trench:sc?'cab:'+sc.cid:id,cut:0,day:S.day,ready:S.day+(own?dfBuildDays(km):leadDays(IRU_DAYS)),spares:false};
S.links.push(l);closeModal();UI.sel={type:'link',id};

View file

@ -1,7 +1,7 @@
function openLinkModal(a,b){
if([a,b].includes('kyv')&&[a,b].includes('mos')){openModal(`<div style="display:flex;align-items:center"><h2 style="font-size:24px">${tr('common.not_happening')}</h2><button class="x" data-act="closeModal" aria-label="${tr('common.close')}">×</button></div><p class="lead" style="margin-top:8px">${tr('link_modal.nobody_sells_capacity_between_kyiv')}</p>`);return;}
if((cnCity(a)||cnCity(b))&&!cnOk()){openModal(`<div style="display:flex;align-items:center"><h2 style="font-size:24px">${tr('link_modal.not_without_a_license')}</h2><button class="x" data-act="closeModal" aria-label="${tr('common.close')}">×</button></div><p class="lead" style="margin-top:8px">${tr('link_modal.building_into_mainland_china_needs_a',{city:CITY[cnCity(a)?a:b].name})}</p>`);return;}
let route='';UI.pending={a,b};const km=kmBetween(a,b),sub=isSub(a,b),pop=S.pops[b]?0:popCost(b),sib=pairLinks(a,b).filter(l=>l.kind!=='vxc');
let route='';UI.pending={a,b};const km=kmBetween(a,b),sub=isSub(a,b),pop=S.pops[b]?0:newPopCost(b),sib=pairLinks(a,b).filter(l=>l.kind!=='vxc');
if(!sib.length)UI.route='diverse';const border=cnCity(a)!==cnCity(b),jn=sib.length?routeJoin(a,b):null,ts=landTrenches(a,b),mult=(sib.length&&!(jn&&jn.k===(ts[0]||{}).k)?DIVERSE:1)*(border?3*(UI.cnPrem&&(a==='hkg'||b==='hkg')?1.6:1):1);
if(border)route+=`<p class="lead" style="margin-top:8px">${tr('link_modal.cross_border_circuits_into_mainland')}</p>${a==='hkg'||b==='hkg'?`<div class="seg">${btn(tr('common.regular_crossing'),'cnPrem',{v:0},!UI.cnPrem?'pink':'ghost')}${btn(tr('link_modal.premium_crossing_60_3_loss'),'cnPrem',{v:1},UI.cnPrem?'pink':'ghost')}</div>`:`<p class="note">${tr('link_modal.premium_crossings_are_only_sold_in')}</p>`}`;
if(sib.length&&!(isSub(a,b)&&cablesFor(a,b).length)&&!(UI.via&&UI.via!=='land'&&cablesFor(a,b).some(c=>c.cid===UI.via))){route+=`<p class="lead" style="margin-top:8px">${trn('link_modal.you_already_have_n_link_here',sib.length,{list:sib.map(l=>capName(l)).join(', ')})}</p>
@ -16,6 +16,6 @@ function openLinkModal(a,b){
const wr=waveRoute(a,b,mult,border);
openModal(`${head}
<p class="lead" style="margin-top:8px">${tr('link_modal.waves_are_leased_at_a_flat')}</p>
${pop?`<p class="lead" style="margin-top:8px">${tr('link_modal.includes_a_new_pop_in_city',{city:CITY[b].name,price:fmt$(popCost(b)),extra:ruCity(b)?', '+tr('link_modal.government_box_included'):CITY[b].uae?', '+tr('link_modal.free_zone_license_included'):CITY[b].saudi?', '+tr('link_modal.local_telecom_licence_included'):''})}</p>`:''}${route}${viaSeg(a,b)}
${pop?`<p class="lead" style="margin-top:8px">${tr('link_modal.includes_a_new_pop_in_city',{city:CITY[b].name,price:fmt$(pop),extra:ruCity(b)?', '+tr('link_modal.government_box_included'):CITY[b].uae?', '+tr('link_modal.free_zone_license_included'):CITY[b].saudi?', '+tr('link_modal.local_telecom_licence_included'):''})}</p>`:''}${route}${viaSeg(a,b)}
<div class="tiers">${LT.map((T,i)=>{const lc=Math.round(waveMo(wr.km,wr.sub,i)*wr.wm),c=lc+pop,sw=subWaveWhy(i,wr.km,wr.sub),so=!sw&&soldOut(a,b,i,wr.cab),ok=waveOk(a,b,i)&&!sw&&!so;return !waveShown(i)?'':`<button class="tierbtn" data-act="buildLink" data-args='{"tier":${i}}'${S.cash<c||!ok?' disabled':''}><span class="sz">${T.n}</span><span class="grow meta">${sw?tr('common.too_far_for_this_cable'):so?tr('link_modal.sold_out_for_n_days',{n:Math.max(1,so.until-S.day)}):!ok?tr('link_modal.needs_what_at_both_ends',{what:esc(waveNeed(i))}):pop?tr('link_modal.due_now_price',{price:fmt$(c)}):tr('common.flat_rate')}</span><span class="pr num">${tr('common.price_mo',{price:fmt$(lc)})}</span></button>`;}).join('')}</div>`);
}

View file

@ -61,3 +61,27 @@ test('the price of a new POP includes the standard routers, on the button and in
assert.equal(ev('popStdQuote()'), null);
assert.deepEqual(errors, []);
});
test('POPs built by a link, dark fiber or a consortium seat get the standard too, at the quoted price (#261)', () => {
const { ev, errors } = load();
const A = g('Arrrhipster 7280R'), Ai = ev(A);
ev(start + `;S.lvl=4;S.pops.fra.rgen=${A};S.pops.fra.routers=2;ACT.popStdSet({city:'fra'})`);
const std = ev('popStdQuote().cost');
assert.equal(ev("newPopCost('ams')"), ev("popCost('ams')") + std);
// A wave to a city without a POP.
ev("UI.pending={a:'fra',b:'ams'};UI.lmode='wave';ACT.buildLink({tier:0})");
assert.ok(ev('!!S.pops.ams'), 'the wave built the POP');
assert.equal(ev('S.pops.ams.rgen'), Ai);
assert.equal(ev('S.pops.ams.routers'), 2);
// Dark fiber to a city without a POP.
ev("UI.pending={a:'fra',b:'par'};UI.lmode='df';UI.dfSys='lite';ACT.orderDf()");
assert.equal(ev('S.pops.par.rgen'), Ai);
assert.equal(ev('S.pops.par.routers'), 2);
// A consortium seat with a landing that has no POP yet; its offer is priced with the standard.
ev("S.seatOff={a:'fra',b:'lis',name:'Test',km:seatKm('fra','lis'),exp:S.day+30};UI.tab='links'");
assert.ok(ev("seatSection()").includes(ev("fmt$(newPopCost('lis'))")));
ev('ACT.seatBuy({n:1})');
assert.equal(ev('S.pops.lis.rgen'), Ai);
assert.equal(ev('S.pops.lis.routers'), 2);
assert.deepEqual(errors, []);
});