The build standard owns the router model and the line system; one owner per fiber
The routers order reads its model from the build standard (bstd().g, 'keep' is the old next-model-up rule) and the optical upgrade order its line system (bstd().sys). The Ops sheet shows "From the build standard: X" with a button to the sheet. Old saves move a model or line system from an order that was running into the standard when it has none of its own; a paused order's or an unhired intern's setting is dropped. opsParam refuses model/sys and points at bstdSet. The build standard's order is a generator now: every first job that takes a fiber dark goes through the optical order's routing test (opsDark, in the route worker in play), under one shared budget of dark swaps a night (two for Kevin) and the week-long memory for a failed fiber. A fiber one order worked on is the other's no more that shift, and decom keeps waves the standard just upgraded. The plan is checked at every job, since the shift rests between them: a POP gone or changed by hand meanwhile is skipped. The button still runs the whole plan at once on the page.
This commit is contained in:
parent
032470f486
commit
fbae6fc3ed
22 changed files with 573 additions and 138 deletions
|
|
@ -26,6 +26,13 @@ function bstd(d=S&&S.popStd){const o={},ob=d&&typeof d==='object'&&!Array.isArra
|
|||
// Back to the saved form: the model and router count, and any other target that is not "keep". Nothing set: null.
|
||||
function bstdPut(o){const d={};for(const x of BSTD)if(x.k==='rt'||o[x.k]!==x.d)d[x.k]=o[x.k];return Object.keys(d).length>1||d.rt>1?d:null;}
|
||||
function popStdSanitize(s){s.popStd=s.popStd&&typeof s.popStd==='object'&&!Array.isArray(s.popStd)?bstdPut(bstd(s.popStd)):null;}
|
||||
// Saves from when the intern's orders had their own router model (routers) and line system (optup): the standard takes
|
||||
// them where it has none of its own; one that names its own keeps it. 'next' was no choice at all: nothing moves.
|
||||
// opsSanitize() passes only what an order that was running used (undefined otherwise): the rest is dropped.
|
||||
function bstdAdopt(s,g,sys){const D=bstd(s.popStd);let n=0;
|
||||
if(D.g==='keep'&&Number.isInteger(g)&&bstdOk(BSTDK.g,g)){D.g=g;n++;}
|
||||
if(D.sys==='keep'&&sys!=='keep'&&bstdOk(BSTDK.sys,sys)){D.sys=sys;n++;}
|
||||
if(n)s.popStd=bstdPut(D);}
|
||||
// A bank that forbids generators (Stormy Weather's covenant): the standard never installs one while that loan runs.
|
||||
const bstdNoGen=()=>(S.loans||[]).some(l=>(l.covs||[]).includes('nogen'));
|
||||
// The model a POP should get: the standard's if you can buy it, else the best main-line model that is unlocked and no
|
||||
|
|
@ -80,12 +87,14 @@ function bstdPlan(intern){const J=[];J.held=[];if(!S||!S.popStd||pzOn())return J
|
|||
const take=(c,n,dry)=>{if(n<=0)return true;if(room(c)<n)return false;if(!dry)rmn[c]-=n;return true;};
|
||||
const job=(grp,k,ch,w,cost,mo,go,x)=>{const j={grp,k,ch,w,cost,mo,go,...x};J.push(j);return j;};
|
||||
for(const c of cs){const p=S.pops[c],ch='p:'+c;let g=p.rgen||0,rt=p.routers||1,sw=null,s2=null;
|
||||
const add=()=>{const g0=g,r0=rt;job('pop','rt',ch,c+' +1',routerCost(g0,r0),routerMo(g0)+cageMo(r0+1)-cageMo(r0),()=>{const n=S.pops[c].routers||1;ACT.addRouter({city:c});return (S.pops[c].routers||1)>n;},{c});rt++;};
|
||||
// A router job checks the POP still has what the plan counted on: the intern's shift rests between jobs, and the player
|
||||
// may click meanwhile (the button, a router by hand). So does a PNI job: one ordered meanwhile is not upgraded.
|
||||
const add=()=>{const g0=g,r0=rt;job('pop','rt',ch,c+' +1',routerCost(g0,r0),routerMo(g0)+cageMo(r0+1)-cageMo(r0),()=>{const n=S.pops[c].routers||1;if(n!==r0)return false;ACT.addRouter({city:c});return (S.pops[c].routers||1)>n;},{c});rt++;};
|
||||
const m=p.rupDay===S.day?-1:bstdModel(D.g,c);
|
||||
if(m>=0){
|
||||
// One router carrying traffic: a second goes in first, so the swap rolls through with no maintenance window.
|
||||
if(rt===1&&!popIdle(c))add();
|
||||
const old=g,r=rt;sw=job('pop','g',ch,c+' ⇧'+RG[m].pn,swapCostOf(m,old,r),r*(RG[m].mo-RG[old].mo),()=>{ACT.upRouter({city:c,g:m});return (S.pops[c].rgen||0)===m;},{c});g=m;}
|
||||
const old=g,r=rt;sw=job('pop','g',ch,c+' ⇧'+RG[m].pn,swapCostOf(m,old,r),r*(RG[m].mo-RG[old].mo),()=>{if((S.pops[c].rgen||0)!==old)return false;ACT.upRouter({city:c,g:m});return (S.pops[c].rgen||0)===m;},{c});g=m;}
|
||||
while(rt<D.rt&&rt<RMAX)add();
|
||||
// A building and a generator do not wait for the routers, nor for each other.
|
||||
if(D.site2&&!p.site2)s2=job('pop','site2','s:'+c,c,SITE2_COST,SITE2_MO,()=>{ACT.addSite({city:c});return !!S.pops[c].site2;},{c});
|
||||
|
|
@ -108,7 +117,7 @@ function bstdPlan(intern){const J=[];J.held=[];if(!S||!S.popStd||pzOn())return J
|
|||
const opts=NET[net].pops.filter(c=>S.pops[c]&&here(c)&&!by[net].has(c)).map(c=>({c,v:pniVal(net,c)})).filter(o=>o.v.worth).sort((a,b)=>b.v.want-a.v.want||(a.c<b.c?-1:1));
|
||||
for(const {c,v} of opts){if(k<=0)break;let q=null;for(let t=Math.max(v.tier,pniMin(net));t>=pniMin(net)&&!q;t--){const x=pniQuote(c,net,t,resv(c));if(x&&!x.why)q=x;}
|
||||
if(!q||!take(c,q.slots))continue;const tier=q.tier;k--;
|
||||
job('port','pni','n:'+net+'@'+c,c+' '+net,q.cost,pniMo({net,tier,n:1},0),()=>{const x=pniQuote(c,net,tier,resv(c));if(!x||x.why||!spend(x.cost))return false;pniPlace(x);return true;},{c});}}}
|
||||
job('port','pni','n:'+net+'@'+c,c+' '+net,q.cost,pniMo({net,tier,n:1},0),()=>{const x=pniQuote(c,net,tier,resv(c));if(!x||x.why||x.ex||!spend(x.cost))return false;pniPlace(x);return true;},{c});}}}
|
||||
// Fiber and waves, hottest first. A POP excepted from the order keeps its links as they are too.
|
||||
if(D.sys!=='keep'||D.opt!=='keep'||D.wv!=='keep'){const sp={...(S.spares||{})},dk=new Map(),wv=new Map();
|
||||
const ls=S.links.filter(l=>(l.kind==='df'||l.kind==='wave')&&here(l.a)&&here(l.b)&&S.pops[l.a]&&S.pops[l.b]).map(l=>({l,u:(R.load[l.id]||0)/Math.max(1e-9,capOf(l))})).sort((a,b)=>b.u-a.u||(a.l.id<b.l.id?-1:1));
|
||||
|
|
@ -124,10 +133,12 @@ function bstdPlan(intern){const J=[];J.held=[];if(!S||!S.popStd||pzOn())return J
|
|||
let sys=l.sys;const lit=l.ready<=S.day,nx=D.sys!=='keep'&&BSTD_SYS[sys]<BSTD_SYS[D.sys]&&sysNext({sys});
|
||||
// A lit fiber goes dark for a day. Busy with nothing parallel to carry it: it keeps its line system for now, and
|
||||
// gets the best optics that one takes. A parallel fiber goes dark first in this plan: it waits for next time.
|
||||
// The intern's plan leaves the rest to the shift's own test (opsDark(): a routing without the fiber), as the optical
|
||||
// order does: here only what is known without one (opsDarkPre()), and a fiber that failed the test this week.
|
||||
if(nx&&techOk('sys',nx,DF_SYS[nx].lvl)){
|
||||
if(lit&&!bstdDarkOk(l))J.held.push(l);
|
||||
else if(lit&&!bstdDarkOk(l,dk)){J.held.push(l);continue;}
|
||||
else{const busy=lit&&bstdBusy(l);
|
||||
if(lit&&!(intern?!(OPTUP_NO.get(l.id)>S.day)&&opsDarkPre(l)!==false:bstdDarkOk(l)))J.held.push(l);
|
||||
else if(lit&&(intern?pairLinks(l.a,l.b).some(x=>x!==l&&dk.get(x.id)):!bstdDarkOk(l,dk))){J.held.push(l);continue;}
|
||||
else{const busy=lit&&(intern?!opsUnused(l):bstdBusy(l));
|
||||
while(BSTD_SYS[sys]<BSTD_SYS[D.sys]){const to=sysNext({sys});if(!to||!techOk('sys',to,DF_SYS[to].lvl))break;
|
||||
const s0=sys;job('fiber','sys',ch,l.a+'|'+l.b,sysCost(to)*(to==='cl'&&l.own?Math.max(1,l.pairs|0):1),0,()=>{if(l.sys!==s0)return false;ACT.upSys({id:l.id});return l.sys===to;},{l,dark:lit,busy});sys=to;}
|
||||
if(lit)dk.set(l.id,busy);}}
|
||||
|
|
@ -178,25 +189,32 @@ function bstdOptJobs(l,sys,sp,V,take,ch){const rg=c=>V[c]?V[c].g:(S.pops[c].rgen
|
|||
// The new ones could not go in (ports, cash): the old optics go back in from the shelf.
|
||||
(l.ch=l.ch||[]).push(...Array(k).fill(o0));S.spares[o0]-=k;return false;}});}
|
||||
return out;}
|
||||
// A line-system swap darkens the fiber for a day: only while it carries little, or its parallel links can take its load.
|
||||
// The button's test of a line-system swap, which darkens the fiber for a day: only while it carries little, or its
|
||||
// parallel links can take its load. No routing, so the quote is what the click does. (The intern routes: opsDark().)
|
||||
// ex: fibers already going dark today (id → whether they carry traffic): they carry nothing for this one, and one whose
|
||||
// traffic leans on its parallel links keeps them lit.
|
||||
const bstdBusy=l=>((R.load&&R.load[l.id])||0)>Math.max(1,capOf(l)*0.1);
|
||||
// Express lightpaths (#58) ride the fiber's glass: its own load says nothing about them, and its parallel links do not
|
||||
// carry them, so an express with any traffic at all keeps the fiber lit (the line system waits, as for a busy fiber).
|
||||
// The intern's routing test needs no such rule: an express goes dark with its fiber there (opsDarkTrial()).
|
||||
const bstdXpBusy=l=>xpSlots(l)>0&&xpOver(l.id).some(x=>((R.load&&R.load[x.id])||0)>1e-6);
|
||||
function bstdDarkOk(l,ex){if(bstdXpBusy(l))return false;const P=pairLinks(l.a,l.b).filter(x=>x!==l);if(ex&&P.some(x=>ex.get(x.id)))return false;if(!bstdBusy(l))return true;
|
||||
return P.filter(x=>!linkDown(x)&&!x.standby&&!(ex&&ex.has(x.id))).reduce((a,x)=>a+Math.max(0,capOf(x)-((R.load&&R.load[x.id])||0)),0)>=((R.load&&R.load[l.id])||0);}
|
||||
// Do the plan's jobs in order. can(j): may it be paid for (budget, floor, cash); pay(j): run it, true if it took.
|
||||
// one: at most one fiber goes dark (the intern's shift); max: at most that many jobs tried, done or failed, so a shift's
|
||||
// work stays bounded whatever goes wrong. Returns what was done.
|
||||
function bstdDo(J,can,pay,one,max=1e9){const stop=new Set(),done=new Set(),dark=new Map();let n=0;
|
||||
/* Do the plan's jobs in order. can(j): may it be paid for (budget, floor, cash); pay(j): run it, true if it took.
|
||||
dark(j, ex): may the first job that darkens a fiber go ahead (ex: fibers gone dark so far, as bstdDarkOk() takes them),
|
||||
a generator, so a test can route (yields included); done1(j, first): after each job done (first: it took a fiber dark).
|
||||
max: at most that many jobs tried, done or failed, so a shift's work stays bounded whatever goes wrong. A bare yield
|
||||
after each job is a place to let a frame through. Returns what was done. */
|
||||
function* bstdRun(J,can,pay,dark,done1,max=1e9){const stop=new Set(),done=new Set(),dk=new Map();let n=0;
|
||||
for(const j of J){if(n>=max)break;if(stop.has(j.ch))continue;if(j.dep&&!j.dep.every(d=>done.has(d))){stop.add(j.ch);continue;}
|
||||
if(j.dark&&!dark.has(j.l.id)&&((one&&dark.size)||!bstdDarkOk(j.l,dark))){stop.add(j.ch);continue;}
|
||||
if(!can(j)){stop.add(j.ch);continue;}n++;
|
||||
// The money first: no fiber is tested for a job the budget cannot pay, and asked again after a test that routed.
|
||||
const first=!!j.dark&&!dk.has(j.l.id);
|
||||
if(!can(j)||first&&(!(yield* dark(j,dk))||!can(j))){stop.add(j.ch);continue;}n++;
|
||||
if(!pay(j)){stop.add(j.ch);continue;}
|
||||
if(j.dark)dark.set(j.l.id,!!j.busy);done.add(j);}
|
||||
if(j.dark)dk.set(j.l.id,!!j.busy);done.add(j);if(done1)done1(j,first);yield;}
|
||||
return [...done];}
|
||||
// The button: the whole plan at once, on the page, every fiber judged as the plan judged it.
|
||||
function bstdDo(J,can,pay){const g=bstdRun(J,can,pay,function*(j,ex){return bstdDarkOk(j.l,ex);});for(;;){const s=g.next();if(s.done)return s.value;}}
|
||||
// What a job costs as it runs (an optics swap is priced again then: see bstdOptJobs).
|
||||
const bstdPrice=j=>j.price?j.price():j.cost;
|
||||
// The sheet's summary and the MCP quote: how much is below the standard, and what bringing it all up costs. The plan is
|
||||
|
|
@ -206,5 +224,14 @@ function bstdQuote(intern){const J=bstdPlan(intern),P=new Set(),Q=new Set(),L=ne
|
|||
return {cost:Math.round(cost),mo:Math.round(mo),pops:P.size,ports:Q.size,links:L.size,n:J.length,held:J.held.map(l=>l.a+'|'+l.b)};}
|
||||
// The optics order lights the standard's fastest optics while this order keeps to a standard that wants them.
|
||||
const bstdFast=()=>!!(S.popStd&&opsHired()&&S.ops.on.std&&bstd().opt==='fast');
|
||||
// The intern's shift: the same plan, every job through the budget and the cash floor at what it costs then, a few at a time.
|
||||
function bstdShift(X){bstdDo(bstdPlan(true),j=>X.can('std',bstdPrice(j),j.mo),j=>X.pay('std',()=>j.go())&&(X.did('std',j.w),true),true,BSTD_MAX);}
|
||||
/* The intern's shift: the same plan, every job through the budget and the cash floor at what it costs then, a few at a
|
||||
time. A fiber goes dark only on the optical order's test (opsDark(): a routing without it, in play in the route
|
||||
worker), within the night's dark swaps that order shares (opsDarkRoom()), and a fiber that fails waits a week. One
|
||||
owner per fiber: a fiber or wave the optical order worked on this shift is left alone, and what this order works on
|
||||
is its own until tomorrow (X.fib: that order and decom leave it alone). The plan is made once a shift, and the shift
|
||||
rests between jobs: a POP decommissioned or a link given up meanwhile is not worked on (the links last: a walk of them,
|
||||
only for a job the budget lets through). */
|
||||
function* bstdShift(X){const mine=j=>(!j.c||!!S.pops[j.c])&&(!j.l||(X.fib.get(j.l.id)||'std')==='std');
|
||||
yield* bstdRun(bstdPlan(true),j=>mine(j)&&X.can('std',bstdPrice(j),j.mo)&&(!j.l||S.links.includes(j.l)),j=>X.pay('std',()=>j.go())&&(X.did('std',j.w),true),
|
||||
function*(j){const l=j.l;if(OPTUP_NO.get(l.id)>S.day||!opsDarkRoom(X))return false;const ok=yield* opsDark(l,X);if(!ok)OPTUP_NO.set(l.id,S.day+OPTUP_WAIT);return ok;},
|
||||
(j,first)=>{if(j.l)X.fib.set(j.l.id,'std');if(first)X.dk.n++;},BSTD_MAX);}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue