diff --git a/src/game/60-features/95-standing-orders.js b/src/game/60-features/95-standing-orders.js index 636f8ce..a4200ff 100644 --- a/src/game/60-features/95-standing-orders.js +++ b/src/game/60-features/95-standing-orders.js @@ -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()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'); diff --git a/tests/standing-orders.test.js b/tests/standing-orders.test.js index 5f0d6d5..f839520 100644 --- a/tests/standing-orders.test.js +++ b/tests/standing-orders.test.js @@ -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 }),