One game, four doors: a per-save ruleset with Change Freeze, On-call and BGP at 3 a.m., a real Sandbox, and a new start screen

This commit is contained in:
Frederic Jung 2026-10-28 15:27:00 +01:00
parent c011022203
commit 531f90f107
No known key found for this signature in database
40 changed files with 560 additions and 67 deletions

View file

@ -50,7 +50,8 @@ const LEVELS=[
// What each level asks for (peak Gbps, POPs, continents). Continents carry over to the levels above.
const LV_REQ=[null,{pk:200,pops:3},{pk:1000,pops:6},{pk:3000,pops:10,reg:3},{pk:6000,pops:15,reg:4},{pk:9000,pops:20},{pk:12000,pops:25,reg:5},{pk:16000,pops:32},{pk:21000,pops:40,reg:6},{pk:26000,pops:50},{pk:33000,pops:60},{pk:40000,pops:70},{pk:50000,pops:80}];
const lvReg=i=>Math.max(0,...LV_REQ.slice(1,i+1).map(q=>q.reg||0));
const lvl=()=>(S&&S.lvl)||1;
// Open gates (sandbox, puzzles): every level's unlocks are there from the start.
const lvl=()=>S&&S.rules&&S.rules.gates==='open'?LEVELS.length:(S&&S.lvl)||1;
// Lower-case just the first word for mid-sentence use, so names like Tel-Mess or AGI keep their capitals.
const lc1=t=>/^[A-Z][a-z]/.test(t)?t[0].toLowerCase()+t.slice(1):t;
function custLevel(){const pops=Object.keys(S.pops).length,pk=S.stats.peak,rc=regionsCount();let lv=1;for(let i=1;i<LV_REQ.length;i++){const q=LV_REQ[i];if(pk>=q.pk&&pops>=q.pops&&rc>=lvReg(i))lv=i+1;else break;}return lv;}

View file

@ -0,0 +1,42 @@
/* ---------- The ruleset: one game, many doors ----------
Every network carries its own rules (S.rules), picked when it starts and locked from then on. Modes are presets of
these rules, not separate code: Normal comes as Change Freeze, On-call (the classic game) and BGP at 3 a.m.;
Sandbox and Puzzles are presets too. Saves without rules load as On-call, so nothing changes for them.
Scenarios and the weekly challenge run on On-call plus their own S.scn.rules (scnRule()). */
const RULE_DEF={clock:true,chaos:'normal',lead:'real',market:true,inbox:true,money:'normal',gates:'ladder',mods:[]};
const RULE_OK={clock:[true,false],chaos:['none','calm','normal','spicy'],lead:['real','quick'],market:[true,false],inbox:[true,false],money:['normal','infinite'],gates:['ladder','open']};
// i: icon, n: name, d: the one-line joke, x: what is different, in small print.
const PRESETS={
freeze:{i:'🧊',n:tr('rules.change_freeze'),d:tr('rules.nobody_touches_prod_even_the_backhoes'),x:tr('rules.fewer_outages_pnis_and_builds_in'),clock:true,chaos:'calm',lead:'quick',market:false,inbox:false,money:'normal',gates:'ladder'},
oncall:{i:'📟',n:tr('rules.on_call'),d:tr('rules.the_real_thing_your_pager_has'),x:tr('rules.real_lead_times_real_outages_a'),clock:true,chaos:'normal',lead:'real',market:true,inbox:true,money:'normal',gates:'ladder'},
bgp:{i:'🔥',n:tr('rules.bgp_at_3_a_m'),d:tr('rules.everything_is_on_fire_and_it'),x:tr('rules.more_and_longer_outages_more_ddos'),clock:true,chaos:'spicy',lead:'real',market:true,inbox:true,money:'normal',gates:'ladder'},
sandbox:{i:'🏖️',n:tr('common.sandbox'),d:tr('rules.a_billion_dollars_every_unlock_your'),x:tr('rules.infinite_money_everything_unlocked_quick'),clock:true,chaos:'none',lead:'quick',market:true,inbox:true,money:'infinite',gates:'open'},
puzzle:{i:'🧩',n:tr('rules.puzzle'),d:tr('rules.one_small_network_one_tricky_goal'),x:tr('rules.no_clock_no_bills_nothing_breaks'),clock:false,chaos:'none',lead:'quick',market:false,inbox:false,money:'normal',gates:'open'},
};
const NORMAL_PRESETS=['freeze','oncall','bgp'];
// How often things break, against the classic game. Spicy outages also last half as long again.
const CHAOS={none:{i:'😴',n:tr('rules.chaos_none'),d:tr('rules.nothing_ever_breaks'),m:0},calm:{i:'🧊',n:tr('rules.chaos_calm'),d:tr('rules.a_cut_now_and_then'),m:0.35},normal:{i:'📟',n:tr('rules.chaos_normal'),d:tr('rules.like_the_real_game'),m:1},spicy:{i:'🔥',n:tr('rules.chaos_spicy'),d:tr('rules.your_pager_never_sleeps'),m:1.8}};
const SPICY_LONG=1.5,LEAD_QUICK=10;
function rule(k){const r=S&&S.rules;return r&&r[k]!==undefined?r[k]:RULE_DEF[k];}
function rulePreset(){const p=S&&S.rules&&S.rules.preset;return p&&Object.prototype.hasOwnProperty.call(PRESETS,p)?p:'oncall';}
function gatesOpen(){return rule('gates')==='open';}
function chaosMul(){const c=CHAOS[rule('chaos')];return c?c.m:1;}
// Days until something ordered arrives: as quoted, or a tenth of it (at least a day) with quick lead times.
function leadDays(n){return rule('lead')==='quick'?Math.max(1,Math.round(n/LEAD_QUICK)):n;}
// A fresh, valid rules object: the preset's values, with any valid overrides on top.
function makeRules(preset,o){const p=Object.prototype.hasOwnProperty.call(PRESETS,preset)?preset:'oncall',P=PRESETS[p],r={preset:p};o=o&&typeof o==='object'?o:{};
for(const k of Object.keys(RULE_OK)){const d=P[k]!==undefined?P[k]:RULE_DEF[k];r[k]=RULE_OK[k].includes(o[k])?o[k]:d;}
r.mods=Array.isArray(o.mods)?[...new Set(o.mods.filter(m=>typeof m==='string'&&/^[a-z0-9_-]{1,24}$/.test(m)))].slice(0,16):[];
return r;}
// What the HUD and the share card say about the rules. On-call says nothing: it is the game.
function ruleTag(){const p=rulePreset();if(S&&S.mode==='sandbox'){const c=CHAOS[rule('chaos')];return tr('common.sandbox')+(c&&rule('chaos')!=='none'?' '+c.i:'');}
return p==='oncall'||p==='sandbox'?'':PRESETS[p].i+' '+PRESETS[p].n;}
/* Spicy outages last longer: stretch a fresh incident, and whatever it holds down until the same day, by half. */
function stretchInc(i){if(rule('chaos')!=='spicy'||!i||!(i.until>S.day)||i.start!==S.day)return;const U=i.until,V=S.day+Math.ceil((U-S.day)*SPICY_LONG);if(V===U)return;i.until=V;
const f=(o,k)=>{if(o&&o[k]===U)o[k]=V;},E=S.ev;
for(const l of S.links){f(l,'cut');f(l,'eqDown');f(l,'deg');f(l.loss,'until');f(l.chFail,'until');}
for(const c in S.pops){const p=S.pops[c];f(p,'down');f(p,'ringcut');f(p,'hot');}
for(const t of S.transit){f(t,'down');f(t.lacp,'until');}for(const p of S.pni)f(p.lacp,'until');
for(const k of ['ixdown','fab'])if(E[k])for(const x in E[k])if(E[k][x]===U)E[k][x]=V;
if(E.ixlacp)for(const x in E.ixlacp)f(E.ixlacp[x],'until');
for(const k of ['leak','rpki','pmtud','ddos'])f(E[k],'until');}