Build standard: never take a fiber dark under a customer's wave; the intern no longer skips leased pairs and IRUs

The build standard's Apply could swap the line system on a fiber that carries a
sold alien wave or a Lambda Bazaar managed wave, taking those customers dark for
a day with no warning. The intern refused any fiber with any customer on it,
leased pairs and IRUs included, though a line-system swap cannot touch them.

One helper next to fiberOk(), dfWaveCust(), says whether a customer rides the
fiber's line system (every fiber type but glass: dfpair, pairs, capfib), and both
bstdDarkOk() and opsDarkPre() use it. bstdPlan() holds such a fiber (J.held) and
lists it in J.wv; the sheet and the MCP quote give that reason. The link
panel's own upgrade button (ACT.upSys) still swaps with a warning toast.
This commit is contained in:
jvanvik 2026-11-09 22:47:21 +01:00
parent 1f76639b8f
commit 286ae48207
14 changed files with 102 additions and 24 deletions

View file

@ -305,9 +305,10 @@ function opsAround(l){const adj={};for(const x of S.links){if(x===l||linkDown(x)
// answers (OPS_ROUTE, then {dark}: opsDarkTrial(), in play in the route worker).
// Nothing rides the fiber: no traffic of its own (customers' circuits are in it), none on an express through it (#58).
const opsUnused=l=>{const L=(R&&R.load)||{};return !(L[l.id]>1e-6)&&!xpOver(l.id).some(x=>L[x.id]>1e-6);};
// What a day dark comes to, said without routing: false (a customer rides it, or it carries traffic with no other way
// between its cities), true (nothing rides it, so nothing is lost), null (a routing decides: opsDarkTrial()).
function opsDarkPre(l){if(S.biz.some(b=>b.link===l.id))return false;return opsUnused(l)?true:opsAround(l)?null:false;}
// What a day dark comes to, said without routing: false (a customer's wave rides its line system, or it carries traffic
// with no other way between its cities), true (nothing rides it, so nothing is lost), null (a routing decides:
// opsDarkTrial()). Leased pairs and IRUs are glass: a line-system swap never touches them. ws: as dfWaveCust() takes it.
function opsDarkPre(l,ws){if(dfWaveCust(l,ws))return false;return opsUnused(l)?true:opsAround(l)?null:false;}
const OPS_ROUTE={route:true};
// X.dk.t counts the tests that route.
function* opsDark(l,X){let k=opsDarkPre(l);if(k===false)return false;if(X.dirty){yield OPS_ROUTE;X.dirty=false;k=opsDarkPre(l);}

View file

@ -77,8 +77,9 @@ function bstdLine(D){const a=bstdPopParts(D),n=['lag','split','ix','pni','sys','
rest of that chain waits. A job that needs another chain's work first (optics only the new router model takes, a split
that needs the second building) names that job in dep and waits for it too. Whether a fiber may go dark is settled
here, not on the way, so the plan is what the button does and its sum is the quote.
intern: only where the intern may work (per-POP exceptions). J.held: fibers whose line system has to wait. */
function bstdPlan(intern){const J=[];J.held=[];if(!S||!S.popStd||pzOn())return J;const D=bstd(),here=c=>!intern||opsHere('std',c);
intern: only where the intern may work (per-POP exceptions). J.held: fibers whose line system has to wait; J.wv: those
of them that wait because a customer's wave rides the line system (dfWaveCust()), which no traffic test changes. */
function bstdPlan(intern){const J=[];J.held=[];J.wv=[];if(!S||!S.popStd||pzOn())return J;const D=bstd(),here=c=>!intern||opsHere('std',c);
const load=c=>Math.max((R.nodeLoad[c]||0)/(R.nodeCap[c]||nodeCap(c)||1),portsUsed(c)/Math.max(1,portsMax(c)));
const cs=Object.keys(S.pops).filter(here),ld={};for(const c of cs)ld[c]=load(c);cs.sort((a,b)=>ld[b]-ld[a]||(a<b?-1:1));
// Router ports: what the POP will have once its own jobs are done, less what pending PNI augments will take.
@ -119,7 +120,7 @@ function bstdPlan(intern){const J=[];J.held=[];if(!S||!S.popStd||pzOn())return J
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||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();
if(D.sys!=='keep'||D.opt!=='keep'||D.wv!=='keep'){const sp={...(S.spares||{})},dk=new Map(),wv=new Map();let wc=null;
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));
// Waves: the size each goes up to. The decom order hands back the smaller waves a pair no longer needs, judged with
// the sizes these upgrades give: never pay a month's rent on one it is about to return.
@ -131,13 +132,15 @@ function bstdPlan(intern){const J=[];J.held=[];if(!S||!S.popStd||pzOn())return J
if(l.kind==='wave'){const t=wv.get(l);if(t){const nm=Math.round(waveMo(l.km,l.sub,t)*(l.mult||1));job('fiber','wv',ch,l.a+'|'+l.b,nm,nm-(l.mo||0),()=>{ACT.upLink({id:l.id,tier:t});return l.tier===t;},{l});}continue;}
if(l.eqDown>S.day)continue;
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&&!(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;}
// A lit fiber goes dark for a day. Busy with nothing parallel to carry it, or a customer's wave on its line system:
// 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)){const ws=lit?wc||(wc=dfWaveSet()):null;
if(lit&&dfWaveCust(l,ws)){J.held.push(l);J.wv.push(l);}
else if(lit&&!(intern?!(OPTUP_NO.get(l.id)>S.day)&&opsDarkPre(l,ws)!==false:bstdDarkOk(l,undefined,ws)))J.held.push(l);
else if(lit&&(intern?pairLinks(l.a,l.b).some(x=>x!==l&&dk.get(x.id)):!bstdDarkOk(l,dk,ws))){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;}
@ -189,16 +192,17 @@ 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;}
// 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().)
// The button's test of a line-system swap, which darkens the fiber for a day: never under a customer's wave (it would go
// dark with the fiber: dfWaveCust()), and 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.
// traffic leans on its parallel links keeps them lit. ws: as dfWaveCust() takes it.
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;
function bstdDarkOk(l,ex,ws){if(dfWaveCust(l,ws)||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.
dark(j, ex): may the first job that darkens a fiber go ahead (ex: fibers gone dark so far, as bstdDarkOk() takes them),
@ -219,9 +223,11 @@ function bstdDo(J,can,pay){const g=bstdRun(J,can,pay,function*(j,ex){return bstd
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
// what the button does, so its sum is the bill. held: the fibers whose line system waits ("fra|ams"); they are below it.
// Of them, wait: the ones that wait for their traffic, wv: the ones that wait for a customer's wave to leave.
function bstdQuote(intern){const J=bstdPlan(intern),P=new Set(),Q=new Set(),L=new Set(J.held.map(l=>l.id));let cost=0,mo=0;
for(const j of J){cost+=j.cost;mo+=j.mo;if(j.grp==='pop')P.add(j.c);else if(j.grp==='port')Q.add(j.ch);else L.add(j.l.id);}
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)};}
const w=l=>l.a+'|'+l.b;
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(w),wait:J.held.filter(l=>!J.wv.includes(l)).map(w),wv:J.wv.map(w)};}
// 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

View file

@ -95,7 +95,15 @@ const linkIds=()=>{const m=new Map();for(const l of S.links)if(!m.has(l.id))m.se
function fiberUse(){const sold=new Map(),dfp=new Map(),pairs=new Set();
for(const b of S.biz){if(b.type==='wwave')sold.set(b.link,(sold.get(b.link)||0)+(b.slots||0));else if(b.type==='dfpair')dfp.set(b.link,(dfp.get(b.link)||0)+1);else if(b.type==='pairs'||b.type==='capfib')pairs.add(b.link);}
return {sold,dfp,pairs};}
function fiberOk(b,ids){const l=ids?ids.get(b.link):S.links.find(x=>x.id===b.link);if(!l)return false;if(b.type==='dfpair'||b.type==='pairs'||b.type==='capfib')return l.ready<=S.day&&!(l.cut>S.day);return l.ready<=S.day&&!(l.cut>S.day)&&!(l.eqDown>S.day)&&(b.type!=='mwave'||dfLit(l)>=mwG(l));}
// Fiber customers come in two kinds: glass (a leased pair, an IRU, a hyperscaler's pairs) needs only the fiber; the rest
// (alien and managed waves) ride its line system too, and go dark with it for the day a line-system swap takes.
const FIB_GLASS=new Set(['dfpair','pairs','capfib']);
function fiberOk(b,ids){const l=ids?ids.get(b.link):S.links.find(x=>x.id===b.link);if(!l)return false;if(FIB_GLASS.has(b.type))return l.ready<=S.day&&!(l.cut>S.day);return l.ready<=S.day&&!(l.cut>S.day)&&!(l.eqDown>S.day)&&(b.type!=='mwave'||dfLit(l)>=mwG(l));}
// A customer rides this fiber's line system: a swap would take it dark (the build standard and the intern wait for the
// player). ws: the fibers that carry one (dfWaveSet()), when many fibers are asked about at once.
const dfOnSys=b=>!!b.link&&!!BIZ_T[b.type]&&!!BIZ_T[b.type].fiber&&!FIB_GLASS.has(b.type);
const dfWaveSet=()=>{const s=new Set();for(const b of S.biz)if(dfOnSys(b))s.add(b.link);return s;};
const dfWaveCust=(l,ws)=>ws?ws.has(l.id):S.biz.some(b=>b.link===l.id&&dfOnSys(b));
function soldSlots(l,u){return u?u.sold.get(l.id)||0:S.biz.filter(b=>b.type==='wwave'&&b.link===l.id).reduce((a,b)=>a+(b.slots||0),0);}
// Spare capacity other carriers can rent on a dark fiber (#51): free channels for alien waves, and on your own build
// a spare pair in the trench. Random offers and broker listings follow the same rules and the same prices.

View file

@ -28,7 +28,7 @@ function bstdModal(msg){if(!S||pzOn())return;const D=bstd(),q=bstdQuote(false),h
const n={pop:q.pops,port:q.ports,fiber:q.links},w=q.held.length;
h+=`<section><h3>${tr('bstd.below')}</h3>${q.n||w?BSTD_GRP.map(([g,lab])=>`<div class="kv"><span>${tr(lab)}</span><b>${n[g]}</b></div>`).join('')
+`<div class="kv"><span>${tr('bstd.cost_now')}</span><b>${fmt$(q.cost)}</b></div><div class="kv"><span>${tr('bstd.cost_mo')}</span><b>${tr('common.price_mo',{price:opsMo$(q.mo)})}</b></div>`
+(w?`<p class="meta">${trn('bstd.held',w)}</p>`:'')
+(q.wait.length?`<p class="meta">${trn('bstd.held',q.wait.length)}</p>`:'')+(q.wv.length?`<p class="meta">${trn('bstd.held_wave',q.wv.length)}</p>`:'')
:`<p class="meta">${S.popStd?tr('bstd.all_up'):tr('bstd.none_set')}</p>`}</section>`;
// The intern keeps it there: the order's switch and budget, or a word on hiring one.
h+=`<section><h3>${tr('ops.o_std')}</h3>${hired?`<div class="ops-o${on?' on':''}"><div class="ops-h"><span class="ops-i" aria-hidden="true">${INTERNS[S.ops.intern].i}</span><div class="grow"><div class="nm">${esc(tr('bstd.intern_keeps',{name:opsName()}))}</div><div class="meta">${tr('ops.o_std_around_d')}</div></div>