Show the standard POP's routers in the price of a new POP (#261)
The Build POP button quoted only the site, though popStdApply then paid for the standard routers on top. popStdQuote() prices the standard the way it is paid; the button, a note under it and the intern's one-tap template now include it, and the toast says what the routers cost.
This commit is contained in:
parent
15dc5741d4
commit
1a4a62d0f2
11 changed files with 56 additions and 10 deletions
|
|
@ -219,7 +219,9 @@ function opsTplQuote(c){if(!S||S.pops[c]||!cityOn(c)||(cnCity(c)&&!cnOk()))retur
|
|||
if(T.bb){cost+=bbCost(c);parts.push(tr('ops.tpl_bb'));}
|
||||
if(T.transit&&!scnRule('noTransit')){net=opsProv(c);if(net){cost+=PORT[0].setup;parts.push(tr('ops.tpl_transit'));}}
|
||||
// Priced as if the POP were already there (an IX port is dearer from afar). DE-KICKS wants a sales call first, so not those.
|
||||
S.pops[c]={day:S.day,bb:null,boost:0,down:0,routers:1,gen:false};
|
||||
// The standard routers go in first (#261), so they are in the price and the kit is priced for them.
|
||||
const sq=popStdQuote();if(sq){cost+=sq.cost;parts.push(tr('ops.tpl_std'));}
|
||||
S.pops[c]={day:S.day,bb:null,boost:0,down:0,routers:sq?sq.rt:1,gen:false,rgen:sq?sq.g:0};
|
||||
try{if(T.ix&&CITY[c].ix&&!isDk(c)&&S.ixp[c]===undefined){ix=c;cost+=ixPortMo(c,0);parts.push(tr('ops.tpl_ix'));}
|
||||
if(T.kit){kit=utilityKit(c);if(kit&&kit.cost){cost+=kit.cost;parts.push(tr('ops.tpl_kit'));}}}finally{delete S.pops[c];}
|
||||
return {cost,net:net&&net.id,ix,kit:!!(kit&&kit.cost),parts};}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,14 @@
|
|||
/* ---------- The standard POP (#240) ----------
|
||||
Big networks run one design everywhere. A new POP gets the standard routers at once, while the box is still idle
|
||||
(no maintenance window): the model if it is unlocked and affordable, then the extra routers as cash allows. */
|
||||
function popStdApply(city){const d=S.popStd,p=S.pops[city];if(!d||!p||pzOn())return;let miss=false;
|
||||
// What the standard adds to a fresh POP, priced the way popStdApply pays for it, so it can be on the button (#261).
|
||||
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;}
|
||||
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;}
|
||||
toast(miss?tr('pop_std.not_all_of_the_standard',{city:CITY[city].name}):tr('pop_std.city_gets_the_standard_n',{city:CITY[city].name,n:p.routers||1,model:esc(RG[p.rgen||0].n)}),miss?'bad':'good');}
|
||||
toast(miss?tr('pop_std.not_all_of_the_standard',{city:CITY[city].name}):tr('pop_std.city_gets_the_standard_cost',{city:CITY[city].name,n:p.routers||1,model:esc(RG[p.rgen||0].n),cost:fmt$(c0-S.cash)}),miss?'bad':'good');}
|
||||
// The line in a POP's router section: the standard, and a button to make this POP's routers the standard.
|
||||
function popStdHtml(c){const p=S.pops[c];if(!p||pzOn())return '';const d=S.popStd,same=d&&d.g===(p.rgen||0)&&d.rt===(p.routers||1);
|
||||
return `<div class="kv"><span>${tr('pop_std.standard_for_new_pops')}</span><b>${d?`${d.rt} × ${esc(RG[d.g].n)}`:tr('pop_std.none')}</b></div><div class="btns">${same?'':btn(tr('pop_std.make_this_the_standard'),'popStdSet',{city:c},'ghost sm')}${d?btn(tr('pop_std.clear'),'popStdClear',{},'ghost sm'):''}</div>`;}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue