diff --git a/src/game/85-incidents/20-failures.js b/src/game/85-incidents/20-failures.js index 3057019..404b912 100644 --- a/src/game/85-incidents/20-failures.js +++ b/src/game/85-incidents/20-failures.js @@ -7,9 +7,10 @@ function fireFailure(){ if(S.transit.some(t=>!(t.down>S.day)))opts.push(['transit',3]); if(Object.keys(S.ixp).length)opts.push(['ixloop',2]); if(S.transit.length&&S.day>60)opts.push(['leak',2]); - // Flood Season brings its own; Change Freeze (calm) has none. Spicy chaos or gaming customers put DDoS on its own, - // busier schedule (ddosTick) instead of this one, so it is never counted twice. - if(S.day>40&&!scnRule('ddos')&&!ddosOff()&&!ddosSpicy())opts.push(['ddos',2]); + // Flood Season brings its own; Change Freeze (calm) has none. Gaming customers put DDoS on its own, busier schedule + // (ddosTick) instead of this one, so it is never counted twice. Spicy failures already come 1.8x as often; a slightly + // heavier weight makes that twice On-call's DDoS, as BGP at 3 a.m. promises. + if(S.day>40&&!scnRule('ddos')&&!ddosOff()&&!gamingCount())opts.push(['ddos',rule('chaos')==='spicy'?2.25:2]); if(fabsUsed.length)opts.push(['fabric',1.5]); const lit=S.links.filter(l=>l.kind==='df'&&dfCap(l)>0&&!linkDown(l));if(lit.length)opts.push(['amp',1.5+lit.length*0.3],['optic',1.5+lit.length*0.3]); opts.push(['funny',4]); @@ -134,12 +135,13 @@ function ddosSize(vec){const fl=scnRule('ddos'),r=Math.random(),roll=fl?1/3+r*2/ // Calm (Change Freeze) and no chaos at all mean no attacks, gamers or not. const ddosOff=()=>{const c=rule('chaos');return c==='calm'||c==='none';}; // More frequent attacks are opt-in: the spicy chaos setting, or hosting gamers (who attract them in real life). +// Outside Flood Season, only gamers move attacks onto ddosTick's daily schedule; spicy alone doubles the usual one. const ddosSpicy=()=>!ddosOff()&&(rule('chaos')==='spicy'||gamingCount()>0); function ddosTick(){if(ddosOff()&&!scnRule('ddos'))return;if(scnRule('ddos')){let next=+S.scn.nextDdos||3,n=0; // Unless spicy, floods take turns as they always did: the next one waits until the last is over. if(!ddosSpicy()&&ddosAll().length)return; while(S.day>=next&&n++<2){ddosAttack(false);next+=floodGap();}S.scn.nextDdos=next40||gamingCount()))for(let i=0;i<2;i++)if(Math.random()d>S.day-7&&d<=S.day);if(S.ddosStarts.length>=14||!Object.keys(S.pops).length)return;S.ddosStarts.push(S.day); diff --git a/tests/ddos-floods.test.js b/tests/ddos-floods.test.js index 33bc30a..29d1e4b 100644 --- a/tests/ddos-floods.test.js +++ b/tests/ddos-floods.test.js @@ -106,3 +106,20 @@ test('spicy chaos stretches exactly the attack (or outage) an incident is about, assert.equal(ev("S.links.find(l=>l.id==='M').cut-S.day"), 4); assert.deepEqual(errors, []); }); + +test('BGP at 3 a.m. brings about twice On-call\'s DDoS; gaming customers bring their own, busier schedule', () => { + const picks = {}; + for (const preset of ['oncall', 'bgp']) { + const { ev, errors } = load({ seed: 7 }); + ev(`beginGame('R','fra',{mode:'normal',preset:'${preset}'});if(UI.pendGame)ACT.pitchSkip();S.cash=1e12;ACT.launchBB({city:'fra'});ACT.buyTransit({city:'fra',net:'cog',tier:1});S.day=100;compute()`); + // No daily attacks without gamers, spicy or not. + ev("window.__n=0;const real=ddosAttack;ddosAttack=()=>{window.__n++;};for(let i=0;i<300;i++)ddosTick();window.__tick=window.__n;window.__n=0;for(let i=0;i<4000;i++)fireFailure();ddosAttack=real"); + assert.equal(ev('window.__tick'), 0, `${preset}: no daily DDoS schedule without gaming customers`); + picks[preset] = ev('window.__n') * ev('chaosMul()'); + ev("S.biz.push({id:'g',type:'game',name:'G',city:'fra',bw:1,rate:1,mood:80,since:0});window.__n=0;const real=ddosAttack;ddosAttack=()=>{window.__n++;};for(let i=0;i<300;i++)ddosTick();ddosAttack=real"); + assert.ok(ev('window.__n') > 5, `${preset}: gamers attract attacks on their own schedule`); + assert.deepEqual(errors, []); + } + const ratio = picks.bgp / picks.oncall; + assert.ok(ratio > 1.7 && ratio < 2.3, `about twice the DDoS (${ratio.toFixed(2)}x)`); +});