Intern: write the shift log as a reload keeps it, and drop opsTidy()
The day's log named every order that ran out of budget, and the week's tally got an empty list for a job with no place (a rushed repair, a route server); a reload keeps three places a kind and no empty lists, so opsTidy() trimmed live state after every shift. The shift now writes it that way itself: the broken orders are cut to three ([...X.broke].slice(0,3)), and W.wh[k] is made only for a job that names a place. tests/canonical-state.test.js passes without opsTidy() (a year of the big network with everything on, checked every day), so it is gone.
This commit is contained in:
parent
286ae48207
commit
02b6c24d7b
3 changed files with 25 additions and 7 deletions
|
|
@ -371,7 +371,8 @@ function* opsRun(d){if(!opsHired())return;const O=S.ops,m=monthIdx(d);if(m!==O.m
|
|||
for(const k of OPS_ORDER.slice(0,-1))if(O.on[k]){yield* order(k);yield DAY_REST;}
|
||||
if(O.on.decom&&X.dirty&&opsDecomWaits()){yield;X.dirty=false;}
|
||||
ui=null;if(O.on.decom)yield* order('decom');
|
||||
const e={d,i:O.intern,r:[]};for(const [k,x] of X.r)e.r.push([k,x.n,x.w]);if(X.broke.size)e.r.push(['broke',X.broke.size,[...X.broke]]);
|
||||
// At most three places a kind, as the shift log keeps them (opsLogOk()): the count still says how many budgets ran out.
|
||||
const e={d,i:O.intern,r:[]};for(const [k,x] of X.r)e.r.push([k,x.n,x.w]);if(X.broke.size)e.r.push(['broke',X.broke.size,[...X.broke].slice(0,3)]);
|
||||
// Very rarely, and never under Change Freeze, the intern fat-fingers something harmless.
|
||||
// Kevin rolls the same dice (so a seeded game plays the same whoever is hired) and catches it before pressing Enter.
|
||||
const ff=OPS_FF_RATE[rulePreset()];if(ff&&Object.keys(S.pops).length&&Math.random()<ff){const c=pick(Object.keys(S.pops));let f=Math.floor(Math.random()*OPS_FF.length);
|
||||
|
|
@ -383,7 +384,8 @@ function* opsRun(d){if(!opsHired())return;const O=S.ops,m=monthIdx(d);if(m!==O.m
|
|||
if(X.dirty)yield;
|
||||
if(e.r.length||e.f!==undefined){O.log.unshift(e);O.log.length=Math.min(O.log.length,OPS_LOG);}
|
||||
// The day's detail stays in the Ops sheet; the NOC gets one notice a week (above).
|
||||
const W=O.wk;for(const [k,n,ws] of e.r){W.n[k]=(W.n[k]||0)+n;const a=W.wh[k]||(W.wh[k]=[]);for(const x of ws)if(a.length<3&&!a.includes(x))a.push(x);}
|
||||
// A job with no place (a rushed repair, a route server) adds no empty list to the tally: a reload keeps none (opsWkOk()).
|
||||
const W=O.wk;for(const [k,n,ws] of e.r){W.n[k]=(W.n[k]||0)+n;if(!ws.length)continue;const a=W.wh[k]||(W.wh[k]=[]);for(const x of ws)if(a.length<3&&!a.includes(x))a.push(x);}
|
||||
W.up+=e.up||0;W.mo+=e.mo||0;if(e.f!==undefined)W.ff=Math.min(7,W.ff+1);}
|
||||
// New POP from the template: price the whole bundle first, then click through it in one go.
|
||||
function opsTplQuote(c){if(!S||S.pops[c]||!cityOn(c)||(cnCity(c)&&!cnOk()))return null;const T=S.ops.tpl,parts=[];let cost=popCost(c),net=null,ix=null,kit=null;
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ function* dayPost(d){
|
|||
// the sales desk signs and declines deals, when the player lets it (39-sales-auto.js), then the intern's shift sees them
|
||||
yield* slAutoRun(d);
|
||||
if(opsHired())yield DAY_REST;
|
||||
yield* opsRun(d);opsTidy();
|
||||
yield* opsRun(d);
|
||||
if(S.pie){pieDay(d);pieTier();}
|
||||
// payday floaters
|
||||
if(cal(d).d===1){for(const c in S.pops){let v=(R.cityEye[c]*sfOf(R,c)*EYE_RATE)+S.biz.filter(b=>b.city===c).reduce((a,b)=>a+b.bw*b.rate,0);v=v-R.cityEye[c]*sfOf(R,c)*EYE_RATE*(1-arpuOf(c));if(v>500)floater(CITY[c].x,CITY[c].y-30,'+'+fmt$(v),'#16A866');}sfx('coin');}
|
||||
|
|
@ -130,10 +130,6 @@ function* dayPost(d){
|
|||
{const c=cal(d);if(c.m===0&&c.d===1&&[2,3,5].includes(c.y))track('game_year_'+c.y,true);}
|
||||
if(d%10===0)save();
|
||||
}
|
||||
// The shift's notes as a reload keeps them (opsSanitize): at most three places a job in the day's log (the broken links
|
||||
// were all listed), and no empty list in the week's tally. So live state is what a reload makes of it (server-sim 5.4).
|
||||
function opsTidy(){const O=S.ops;if(!O)return;for(const e of O.log||[])for(const r of e.r||[])if(Array.isArray(r[2])&&r[2].length>3)r[2]=r[2].slice(0,3);
|
||||
for(const w of [O.wk,O.rep])if(w&&w.wh)for(const k of Object.keys(w.wh))if(Array.isArray(w.wh[k])&&!w.wh[k].length)delete w.wh[k];}
|
||||
function spawnOffer(){
|
||||
const mine=spMine(Object.keys(S.pops).filter(bizCity)),lv=lvl();
|
||||
const types=['dia','dia','game','host'];if(mine.length>=2)types.push('l2vpn','l2vpn');if(S.day>60)types.push('scrub');
|
||||
|
|
|
|||
|
|
@ -146,6 +146,26 @@ test('repairs: rush what has a price, as the Rush repair button would', t => {
|
|||
ev => on(ev, 'repair'), "ACT.fixInc({id:'amp'})", 'S.inc.length');
|
||||
});
|
||||
|
||||
test("the shift's log and the week's tally are what a reload keeps: three places a kind at most, no empty lists", t => {
|
||||
const { ev, errors } = game(t, "S.links=[{id:'f',a:'fra',b:'ams',kind:'df',sys:'lite',ch:['zr4'],km:450,sub:false,ready:0,cut:0,eqDown:10,mo:1}];S.inc=[{id:'amp',type:'amp',ref:'f',until:10,cost:3000,msg:'amp'}];S.pops.ams={day:0,bb:null,boost:0,down:0,routers:1,gen:false}");
|
||||
hire(ev);
|
||||
on(ev, 'repair');
|
||||
// Five orders that each find a job today's money cannot pay for.
|
||||
const K = ['transit', 'ports', 'routers', 'std', 'optics'];
|
||||
ev(`for(const k of ${lit(K)}){S.ops.on[k]=true;OPS_RUN[k]=function*(X){X.can(k,1e12);};}`);
|
||||
shift(ev);
|
||||
const r = JSON.parse(ev('JSON.stringify(S.ops.log[0].r)'));
|
||||
assert.deepEqual(r.find(x => x[0] === 'repair'), ['repair', 1, []], 'a rushed repair names no place');
|
||||
assert.deepEqual(r.find(x => x[0] === 'broke'), ['broke', 5, ['std', 'routers', 'transit']], 'five budgets ran out, the first three in the shift named');
|
||||
assert.equal(ev("own(S.ops.wk.wh,'repair')"), false, "no empty list in the week's tally");
|
||||
assert.equal(ev("S.ops.wk.wh.broke.length"), 3);
|
||||
// Straight from the shift (dayTick() is not in between): what a reload makes of it, key for key.
|
||||
const same = ev(`(()=>{const u0=uidN,r0=S.rng,k=v=>Array.isArray(v)?v.map(k):v&&typeof v==='object'?Object.keys(v).sort().reduce((o,x)=>(v[x]!==undefined&&(o[x]=k(v[x])),o),{}):v,
|
||||
pick=o=>JSON.stringify(k({log:o.log,wk:o.wk,rep:o.rep})),a=pick(JSON.parse(JSON.stringify(S.ops))),b=pick(migrate(JSON.parse(JSON.stringify(S))).ops);uidN=u0;S.rng=r0;return a===b||a+' vs '+b;})()`);
|
||||
assert.equal(same, true);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('optics: light hot fiber with the optic already in it, at the #177 batch price', t => {
|
||||
const extra = "ACT.buildPop({city:'ams'});S.pops.ams.rgen=1;S.links.push({id:'f',a:'fra',b:'ams',kind:'df',sys:'lite',ch:['zr4'],km:450,sub:false,ready:0,cut:0,mo:1,trench:'f'});compute();R.load.f=dfCap(S.links.at(-1))*0.95";
|
||||
const A = twins(t, extra, ev => on(ev, 'optics', { at: 70 }),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue