Stop loan offers once you have half a billion in the bank

Fixes #52
This commit is contained in:
Frederic Jung 2026-10-25 14:48:49 +01:00
parent bfe12cca7d
commit 856ecfbb37
No known key found for this signature in database
3 changed files with 17 additions and 0 deletions

View file

@ -2219,4 +2219,5 @@
"<b>Fiber pair {n} is lit: {a}–{b}.</b><br>Another ROADMaster 9000 and a fresh chain of amplifiers. Room for {m} more channels.":"<b>Coppia di fibre {n} accesa: {a}–{b}.</b><br>Un altro ROADMaster 9000 e una nuova catena di amplificatori. Spazio per altri {m} canali.",
"{n} fiber pairs lit, the trench is full":"{n} coppie di fibre accese, il cavidotto è pieno",
"Light fiber pair {n} <small>{price} + {mo}/mo</small>":"Accendi la coppia {n} <small>{price} + {mo}/mese</small>",
"<b>The banks have stopped calling.</b><br>You have more money than most of them. Loan offers come back if your cash ever drops below {cash}.":"<b>Le banche hanno smesso di chiamare.</b><br>Hai più soldi della maggior parte di loro. Le offerte di prestito tornano se la tua cassa scende sotto {cash}.",
};

View file

@ -1270,8 +1270,11 @@ function loanTick(d){
// offers: now and then, and much more often when you are in trouble
S.loanOffers=S.loanOffers.filter(o=>o.exp>d);
const broke=S.cash<0;
// With half a billion in the vault, loan offers are just noise (#52): banks stop calling, open offers lapse.
if(S.cash>=RICH_NO_LOANS){if(S.loanOffers.length||!S.richTold){S.loanOffers=[];if(!S.richTold&&S.mode!=='sandbox'){S.richTold=1;toast(tr('<b>The banks have stopped calling.</b><br>You have more money than most of them. Loan offers come back if your cash ever drops below {cash}.',{cash:fmt$(RICH_NO_LOANS)}),'good');}}return;}
if(S.loanOffers.length<4&&(broke?Math.random()<0.25:(d>20&&Math.random()<1/40)))spawnLoanOffer(broke);
}
const RICH_NO_LOANS=5e8;
/* Seeded games (scenarios, weekly challenge) draw every random number from S.rng, so the same seed
gives the same world. Free play keeps using the browser's Math.random. */
const _rand=Math.random;

View file

@ -299,3 +299,16 @@ test('DDoS goal and badges unlock from the right state', () => {
assert.equal(ev("R.served=999999;BADGES.find(b=>b.id==='petabit').ok()"), false, 'just under a petabit is not enough');
assert.equal(ev("R.served=1e6;BADGES.find(b=>b.id==='petabit').ok()"), true, 'a petabit per second earns it');
});
test('#52 loan offers stop once you have half a billion in the bank, and come back if you lose it', () => {
const { ev, errors } = load();
ev("ACT.start({});S.day=100;S.cash=6e8;S.loanOffers=[{id:'x',bank:Object.keys(BANKS)[0],amount:1e5,exp:200}]");
for (let i = 0; i < 60; i++) ev('S.day++;loanTick(S.day)');
assert.equal(ev('S.loanOffers.length'), 0, 'no offers while rich');
assert.match(ev("document.getElementById('toasts').textContent"), /stopped calling/);
ev('S.cash=-5e4');
let seen = 0;
for (let i = 0; i < 40; i++) seen += ev('S.day++;loanTick(S.day);S.loanOffers.length') > 0 ? 1 : 0;
assert.ok(seen > 0, 'broke again: the banks are back');
assert.deepEqual(errors, []);
});