Auto-TE and the chaos monkey's leaving are written as a reload makes them

Two places left a key in a shape that sanitize() repairs on the next load, so
the live game was not its own save (the server-run engine refuses such an
action at its gate, and its strict day check would refuse such a day):

- buyTE wrote S.te as {on, day}; a reload adds script:''. It now writes the
  script slot itself (src/game/90-actions/30-route-script-and-tools.js).
- mkLeave turned the monkey off but kept start, until, snip, n, hurt and c;
  sanitize() keeps only next and on for a monkey that is away. It now leaves
  S.monkey as {next, on:0}, after the toasts that still read the visit's count
  (src/game/85-incidents/40-chaos-monkey.js). This covers the visit running
  out, the banana and the rules sending it home.

No new state field, nothing for old saves: both keys load as before. Nothing a
player sees changes, so no CHANGELOG bullet.

Tests: tests/backbone-core.test.js (S.te after buyTE equals what a reload makes
of it) and tests/chaos-monkey.test.js (S.monkey after each way home: outlasted,
hurt, sent home by calmer rules, bribed). Both fail without this change. The
server-run tests take their workarounds out: buyTE and the banana pass the gate
and leave the network the page leaves (tests/mp-sim-acts.test.js, the former
todo), the 60-day realm-vs-page plan clicks buyTE on day 21 instead of setting
S.te, and the gate audit no longer excuses either act.

The Pie in the Sky line the review also named (60-pie.js:66, S.monkey.n++ on a
monkey that is away) is not reachable: its only caller fires a laser incident
behind mkOn(), so it is left as it is.

Performance (npm run perf -- --base-ref 61e31c5, headless, big network, median
of 15 runs, ms):

| What | Base | This | Change | p |
|---|--:|--:|--:|--:|
| Routing: compute() | 27.3 | 26.1 | -4% | 0.51 |
| One game day: dayTick() | 29.7 | 30.1 | +1% | 0.71 |
| An action: after() | 1.96 | 1.86 | -5% | 0.48 |
| Side panel and left list | 62.0 | 59.2 | -5% | 0.023 |
| NOC dashboard tabs | 110 | 110 | +0% | 0.93 |
| Map at three zoom levels | 3.69 | 3.90 | +6% | 0.43 |
| The NOC intern's shift: opsDay() | 4.06 | 3.95 | -3% | 0.11 |

Routing results identical to the base; no change beyond noise.
This commit is contained in:
jvanvik 2026-11-09 20:47:42 +01:00
parent 72f31e809b
commit 3b8c331556
6 changed files with 32 additions and 20 deletions

View file

@ -51,6 +51,8 @@ function mkLeave(why){const M=S.monkey,d=S.day,ok=!why&&M.n>0&&M.hurt===0;M.on=0
if(why==='banana')toast(tr('chaos_monkey.bribed'),'good');
else if(ok){const b=mkBonus();S.cash+=b;S.stats.mkSurv=(S.stats.mkSurv||0)+1;toast(tr('chaos_monkey.survived',{n:M.n,cash:fmt$(b)}),'goal');sfx('coin');track('monkey_survived');}
else if(!why)toast(tr('chaos_monkey.went_home',{n:M.n,hurt:M.hurt}),'');
// Away, it is only its next visit: what a reload keeps of it (sanitize), so the live game is its own save.
S.monkey={next:M.next,on:0};
if(typeof mkEnd==='function')mkEnd(ok,true);}
// The NOC tab's card while it is here.
function mkCard(){if(!mkOn())return '';const M=S.monkey,c=mkBananaCost();

View file

@ -15,7 +15,7 @@ Object.assign(ACT,{
if(drop>0.1&&UI.slop===src){if(drop>0.3)S.stats.fat=1;toast(tr('route_script_and_tools.commit_complete_traffic_down_p_the',{p:pct(drop)}),'bad');sfx('alert');}
else if(drop>0.3){S.stats.fat=1;toast(tr('route_script_and_tools.commit_complete_traffic_down_p_you',{p:pct(drop)}),'bad');sfx('alert');}
else{if(saved>0.1&&drop<0.01)S.stats.kiddie=1;toast(`<b>${tr('common.commit_complete')}</b><br>${saved>0.01?trn('route_script_and_tools.n_rule_live_transit_bill_down',p.n,{p:pct(saved)}):trn('route_script_and_tools.n_rule_live',p.n)}`,'good');sfx('build');}closeModal();UI.slop=undefined;checkGoals();},
buyTE:()=>{if(S.te)return;if(lvl()<3){toast(tr('route_script_and_tools.auto_te_unlocks_at_customer_level'),'bad');sfx('err');return;}if(!coreTE()){toast(tr('core.auto_te_needs_an_rsvp_te_or'),'bad');sfx('err');return;}if(!spend(TE_COST))return;S.te={on:true,day:S.day};toast(tr('route_script_and_tools.auto_te_is_live_the_controller'),'good');after();},
buyTE:()=>{if(S.te)return;if(lvl()<3){toast(tr('route_script_and_tools.auto_te_unlocks_at_customer_level'),'bad');sfx('err');return;}if(!coreTE()){toast(tr('core.auto_te_needs_an_rsvp_te_or'),'bad');sfx('err');return;}if(!spend(TE_COST))return;S.te={on:true,day:S.day,script:''};toast(tr('route_script_and_tools.auto_te_is_live_the_controller'),'good');after();},
teToggle:()=>{if(!S.te)return;S.te.on=!S.te.on;after();},
trace:({city})=>traceModal(city),
traceRun:()=>{const f=$('trFrom'),t=$('trTo');traceModal(f&&f.value,t&&t.value);},