Merge upstream: route worker for every routing, intern specialisations, sales renewals, French cities
Some checks are pending
CI / test 1/4 (push) Waiting to run
CI / test 2/4 (push) Waiting to run
CI / test 3/4 (push) Waiting to run
CI / test 4/4 (push) Waiting to run
CI / build (push) Waiting to run
CI / test (push) Blocked by required conditions
CI / translations (push) Waiting to run
Some checks are pending
CI / test 1/4 (push) Waiting to run
CI / test 2/4 (push) Waiting to run
CI / test 3/4 (push) Waiting to run
CI / test 4/4 (push) Waiting to run
CI / build (push) Waiting to run
CI / test (push) Blocked by required conditions
CI / translations (push) Waiting to run
# Conflicts: # CHANGELOG.md # src/game/60-features/39-sales-auto.js # src/game/60-features/95-standing-orders.js # src/game/85-incidents/40-chaos-monkey.js # src/game/88-days/10-day-tick.js # tests/gameplay-rules.test.js # tests/i18n.test.js
This commit is contained in:
commit
032470f486
54 changed files with 1123 additions and 181 deletions
|
|
@ -89,11 +89,13 @@ function ddosAttack(recompute=true){const fl=scnRule('ddos');ddosExpire();
|
|||
return a;}
|
||||
/* After the day's routing: announce new attacks with what they are doing, pull the plug when Auto-RTBH says so, and
|
||||
teach each lesson once. */
|
||||
function ddosNews(){let again=false;const auto=S.ddosAuto&&S.ddosAuto.rtbh;
|
||||
function ddosNews(){runNow(ddosNewsRun());}
|
||||
// The same as a step of the day: its yield is the routing after Auto-RTBH pulled a plug.
|
||||
function* ddosNewsRun(){let again=false;const auto=S.ddosAuto&&S.ddosAuto.rtbh;
|
||||
for(const a of ddosAll()){const m=ddosReport(a);if(!m)continue;
|
||||
if(auto&&!a.bh&&m.full>0&&ddosCol(a)>=0.01){a.bh=true;a.sac=1;S.stats.rtbh=(S.stats.rtbh||0)+1;ddosRtbhMood(a);again=true;
|
||||
toast(tr('ddos.auto_rtbh',{who:esc(ddosWho(a))}),'bad',[{l:tr('common.open_noc'),act:'leftTab',args:{t:'noc'}}],{a:'city',v:a.city});}}
|
||||
if(again)compute();
|
||||
if(again)yield;
|
||||
const T=S.stats.ddT||(S.stats.ddT={});
|
||||
for(const a of ddosAll()){const m=ddosReport(a);if(!m)continue;
|
||||
if(a.fresh){delete a.fresh;const fl=scnRule('ddos'),col=ddosCol(a),sf=ddosSf(a),bad=col>=0.01||sf<0.97;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,12 @@
|
|||
const anchorProne=l=>!!(l.cable&&CAB[l.cable]&&CAB[l.cable].anchor)||anchorPair(l);
|
||||
// The wet season in the tropical north (November to April): floods close the tracks, so a cut on land takes twice as long to reach.
|
||||
const wetSeason=()=>{const m=cal(S.day).m;return m>=10||m<=3;},wetCut=l=>!l.sub&&!!(CITY[l.a].wet||CITY[l.b].wet)&&wetSeason();
|
||||
function fireFailure(only){
|
||||
/* failureRun() is a failure as a step of the day (10-day-tick.js): its yield is the routing that tells what it cost,
|
||||
done by the route worker in play. fireFailure() is the same failure all at once, routed on the spot. */
|
||||
function fireFailure(only){runNow(failureRun(only));}
|
||||
// A step of the day played all at once: every routing it asks for, on the spot (tests, a failure outside a day).
|
||||
function runNow(g){dayGo(g,(g,v)=>g.next(v));}
|
||||
function* failureRun(only){
|
||||
const opts=[];
|
||||
const live=S.links.filter(l=>l.kind!=='vxc'&&l.kind!=='xp'&&l.kind!=='sat'&&!linkDown(l));const fabsUsed=[...new Set(S.links.filter(l=>l.kind==='vxc').map(l=>l.prov))];
|
||||
// A fiber that only carries expresses is dark as a link of its own, but there is light in it: a backhoe still finds it.
|
||||
|
|
@ -114,13 +119,15 @@ function fireFailure(only){
|
|||
}else if(type==='fabric'){
|
||||
const f=pick(fabsUsed);S.ev.fab=S.ev.fab||{};S.ev.fab[f]=S.day+2+Math.floor(Math.random()*3);
|
||||
addInc({type,ref:f,until:S.ev.fab[f],msg:tr('failures.fabric_is_having_a_bad_day',{fabric:FAB[f].name}),cost:0});
|
||||
}else if(type==='ddos'){ddosAttack();return;
|
||||
}else if(type==='ddos'){ddosAttack(false);yield;yield* ddosNewsRun();return;
|
||||
}
|
||||
compute();
|
||||
// This failure's incident, kept before the routing: the player may repair it (or another) while the worker routes.
|
||||
const last=S.inc[S.inc.length-1];
|
||||
yield;
|
||||
if(!last)return;
|
||||
last.impact=Math.max(0,before-R.served);
|
||||
if(before>1&&last.impact<before*0.03&&type!=='ddos'){S.stats.survived++;toast(`<b>${incTitle(type)}</b><br>${esc(last.msg)} ${tr('failures.traffic_rerouted_customers_barely')}`,'good',[],incOpen(last));}
|
||||
else{const paused=pref('pauseIncident')&&autoPause();toast(`<b>${incTitle(type)}</b><br>${esc(last.msg)}${paused?`<br><b>${tr('common.game_paused')}</b>`:''}`,'bad',(last.cost?[{l:`${last.fix||tr('common.rush_repair')} ${fmt$(last.cost)}`,act:'fixInc',args:{id:last.id}}]:[]).concat(paused?[resumeAct()]:[]),incOpen(last));}
|
||||
else{const paused=pref('pauseIncident')&&autoPause();toast(`<b>${incTitle(type)}</b><br>${esc(last.msg)}${paused?`<br><b>${tr('common.game_paused')}</b>`:''}`,'bad',(last.cost&&S.inc.includes(last)?[{l:`${last.fix||tr('common.rush_repair')} ${fmt$(last.cost)}`,act:'fixInc',args:{id:last.id}}]:[]).concat(paused?[resumeAct()]:[]),incOpen(last));}
|
||||
sfx('alert');
|
||||
}
|
||||
const gamingCount=()=>S.biz.reduce((n,b)=>n+(BIZ_T[b.type]?.gaming?1:0),0);
|
||||
|
|
|
|||
|
|
@ -1,3 +1,8 @@
|
|||
/* An event that cuts cables or power routes at once, as its last move (evRoute()). As a step of the day (eventRun())
|
||||
that routing is the day's next yield instead: nothing reads R in between, so it is the same routing. */
|
||||
let EV_DEFER=null;
|
||||
const evRoute=()=>{if(EV_DEFER)EV_DEFER.n++;else compute();};
|
||||
function* eventRun(){const k={n:0};EV_DEFER=k;try{fireEvent();}finally{EV_DEFER=null;}for(let i=0;i<k.n;i++)yield;}
|
||||
function fireEvent(){
|
||||
const opts=['viral','price','grant'];
|
||||
if(S.day>50)opts.push('sanction','tariff','hijack','landban','shutdown','redsea','baltic');
|
||||
|
|
@ -36,16 +41,16 @@ function fireEvent(){
|
|||
if(e==='shutdown'){const ps=Object.keys(S.pops).filter(c=>c!==S.home);if(!ps.length)return;const c=pick(ps);S.pops[c].down=Math.max(S.pops[c].down||0,S.day+1);addInc({type:'shutdown',ref:c,until:S.day+1,msg:tr('events.regulators_ordered_every_network_in',{city:CITY[c].name}),cost:0});toast(tr('events.ordered_offline_in_city_a_government',{city:CITY[c].name}),'bad');sfx('alert');return;}
|
||||
if(e==='typhoon'){const c=pick(['mnl','ceb','hkg','tok','icn','sha','jkt'].filter(x=>S.pops[x])),p=S.pops[c],nm=pick([tr('common.typhoon_bandwidth'),tr('common.typhoon_latency'),tr('common.typhoon_jitter'),tr('events.typhoon_packet_loss')]);
|
||||
if(p.gen){S.stats.survived++;toast(tr('events.name_hits_city_the_grid_is',{name:nm,city:CITY[c].name}),'good');sfx('alert');return;}
|
||||
p.down=Math.max(p.down||0,S.day+2);addInc({type:'power',ref:c,until:p.down,msg:tr('events.name_knocked_out_power_in_city',{name:nm,city:CITY[c].name}),cost:7000,fix:tr('incidents.rent_a_generator')});toast(tr('events.name_hits_city_power_is_out',{name:nm,city:CITY[c].name}),'bad');sfx('alert');compute();return;}
|
||||
if(e==='runet'){S.ev.runet=S.day+1;toast(tr('events.sovereign_internet_drill_moscow'),'bad');sfx('alert');compute();return;}
|
||||
p.down=Math.max(p.down||0,S.day+2);addInc({type:'power',ref:c,until:p.down,msg:tr('events.name_knocked_out_power_in_city',{name:nm,city:CITY[c].name}),cost:7000,fix:tr('incidents.rent_a_generator')});toast(tr('events.name_hits_city_power_is_out',{name:nm,city:CITY[c].name}),'bad');sfx('alert');evRoute();return;}
|
||||
if(e==='runet'){S.ev.runet=S.day+1;toast(tr('events.sovereign_internet_drill_moscow'),'bad');sfx('alert');evRoute();return;}
|
||||
if(e==='baltic'){const BAL=['clion','havf','danice'];const hit=S.links.filter(l=>l.cable&&BAL.includes(l.cable)&&!(l.cut>S.day));
|
||||
if(!hit.length){toast(tr('events.baltic_cable_damaged_a_cargo_ship'),'goal');return;}
|
||||
const dur=15+Math.floor(Math.random()*15),en=N_('events.a_cargo_ship_dragged_its_anchor');for(const tk of new Set(hit.map(l=>l.trench||l.id))){S.links.filter(l=>(l.trench||l.id)===tk).forEach(l=>l.cut=Math.max(l.cut||0,S.day+dur));addInc({type:'redsea',ref:tk,until:S.day+dur,msg:tr(en),cost:0},en);}
|
||||
toast(tr('events.baltic_cable_damaged_n_of_your',{n:hit.length,d:dur}),'bad');sfx('alert');compute();return;}
|
||||
toast(tr('events.baltic_cable_damaged_n_of_your',{n:hit.length,d:dur}),'bad');sfx('alert');evRoute();return;}
|
||||
if(e==='redsea'){const RED=['twoaf','smw6','peace','aae','eig','eassy'];const hit=S.links.filter(l=>l.cable&&RED.includes(l.cable)&&!(l.cut>S.day));
|
||||
if(!hit.length){toast(tr('events.cables_cut_in_the_red_sea'),'goal');return;}
|
||||
const dur=20+Math.floor(Math.random()*15),en=N_('events.a_ship_drifting_without_power');for(const tk of new Set(hit.map(l=>l.trench||l.id))){S.links.filter(l=>(l.trench||l.id)===tk).forEach(l=>l.cut=Math.max(l.cut||0,S.day+dur));addInc({type:'redsea',ref:tk,until:S.day+dur,msg:tr(en),cost:0},en);}
|
||||
toast(tr('events.cables_cut_in_the_red_sea_03e8',{n:hit.length,d:dur}),'bad');sfx('alert');compute();return;}
|
||||
toast(tr('events.cables_cut_in_the_red_sea_03e8',{n:hit.length,d:dur}),'bad');sfx('alert');evRoute();return;}
|
||||
if(e==='golden'){S.ev.golden=S.day+7;toast(tr('events.golden_week_demand_in_mainland_china'),'goal');return;}
|
||||
if(e==='gfw'){S.ev.gfw=S.day+10;toast(tr('events.the_border_got_stricter_cross_border'),'bad');sfx('alert');return;}
|
||||
if(e==='viral'){S.ev.viral=S.day+8;toast(tr('events.new_season_of_stranger_pings_just'),'goal');}
|
||||
|
|
|
|||
|
|
@ -18,25 +18,29 @@ const mkBonus=()=>Math.round(Math.min(2e6,Math.max(20000,(R.revMo||0)*0.5))/1000
|
|||
function mkWeak(l){const trc=l.trench||l.id,adj={};
|
||||
for(const x of S.links){if(x===l||(x.trench||x.id)===trc||linkDown(x))continue;(adj[x.a]||(adj[x.a]=[])).push(x.b);(adj[x.b]||(adj[x.b]=[])).push(x.a);}
|
||||
const seen=new Set([l.a]),q=[l.a];while(q.length){const c=q.pop();if(c===l.b)return false;for(const n of adj[c]||[])if(!seen.has(n)){seen.add(n);q.push(n);}}return true;}
|
||||
function mkTick(d){const M=S.monkey;if(!M)return;
|
||||
function mkTick(d){runNow(mkTickRun(d));}
|
||||
// The monkey's day as a step of the day: a snip's yield is the routing that tells what it cost.
|
||||
function* mkTickRun(d){const M=S.monkey;if(!M)return;
|
||||
if(!mkElig()){if(M.on)mkLeave('quiet');return;}
|
||||
// The first visit is spread by the ASN, not the dice, so a game's other luck stays exactly as it was.
|
||||
if(M.next==null)M.next=d+(mkSpicy()?180:270)+(S.asn||0)%120;
|
||||
if(!M.on){if(d<M.next)return;if(S.links.filter(l=>l.kind!=='vxc'&&l.kind!=='xp'&&l.kind!=='sat'&&(!linkDown(l)||xpBare(l))).length<3){M.next=d+30;return;}mkArrive(d);return;}
|
||||
if(d>=M.until){mkLeave();return;}
|
||||
if(d>=M.snip){mkSnip();M.snip=d+(mkSpicy()?rint(9,7):rint(14,11));}}
|
||||
if(d>=M.snip){yield* mkSnipRun();M.snip=d+(mkSpicy()?rint(9,7):rint(14,11));}}
|
||||
function mkArrive(d){const M=S.monkey,cs=Object.keys(S.pops),len=mkSpicy()?rint(180,61):rint(120,121);
|
||||
S.stats.mkMet=(S.stats.mkMet||0)+1;
|
||||
Object.assign(M,{on:1,start:d,until:d+len,snip:d+3,n:0,hurt:0,c:cs.length?pick(cs):S.home});
|
||||
toast(tr('chaos_monkey.arrived',{n:len}),'bad',[{l:tr('chaos_monkey.banana',{cost:fmt$(mkBananaCost())}),act:'mkBanana',args:{}}],{a:'tab',v:'noc'});sfx('alert');track('monkey_arrive');
|
||||
if(typeof mkStart==='function'&&CITY[M.c])mkStart(M.c);}
|
||||
function mkSnip(){const M=S.monkey,live=S.links.filter(l=>l.kind!=='vxc'&&l.kind!=='xp'&&l.kind!=='sat'&&(!linkDown(l)||xpBare(l)));if(!live.length)return;
|
||||
function mkSnip(){runNow(mkSnipRun());}
|
||||
function* mkSnipRun(){const M=S.monkey,live=S.links.filter(l=>l.kind!=='vxc'&&l.kind!=='xp'&&l.kind!=='sat'&&(!linkDown(l)||xpBare(l)));if(!live.length)return;
|
||||
// Weak spots first: a sample keeps this cheap on big networks.
|
||||
const smp=live.length>40?Array.from({length:40},()=>pick(live)):live,l=pick(smp.flatMap(x=>mkWeak(x)?[x,x,x,x,x]:[x]));
|
||||
const dur=rint(3,4),trc=l.trench||l.id,hit=S.links.filter(x=>(x.trench||x.id)===trc),A=CITY[l.a].name,B=CITY[l.b].name,before=R.served;
|
||||
hit.forEach(x=>x.cut=Math.max(x.cut||0,S.day+dur));M.n++;M.c=l.a;
|
||||
addInc({type:'cut',ref:trc,until:S.day+dur,msg:tr(pick(MK_SNIPS),{a:A,b:B}),cost:Math.max(4000,Math.round(hit.reduce((a,x)=>a+x.mo,0)*0.5))},'');
|
||||
compute();const i=S.inc[S.inc.length-1],imp=Math.max(0,before-R.served);if(i)i.impact=imp;
|
||||
// The snip's incident, kept before the routing: the player may repair it (or another) while the worker routes.
|
||||
const i=S.inc[S.inc.length-1];yield;const imp=Math.max(0,before-R.served);if(i)i.impact=imp;
|
||||
const felt=before>1&&imp>=before*0.03;if(felt)M.hurt++;else S.stats.survived++;
|
||||
toast(felt?`<b>🐒 ${incTitle('cut')}</b><br>${esc(i?i.msg:'')}`:tr('chaos_monkey.rerouted',{a:A,b:B}),felt?'bad':'good',[],i?incOpen(i):null);sfx(felt?'err':'alert');
|
||||
if(typeof mkRun==='function'){if(!UI.mk&&CITY[M.c])mkStart(M.c);mkRun(l,1400,felt);}}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue