mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-21 05:35:45 +01:00
BLADE: Use "grow" semantics for population estimate (#1624)
This changes the way percantage-based population estimates work, so that they have a similar mechanism to grow(). This allows natural recovery from 0, and also falling to 0 in finite steps. This also changes the formula for reducing estimates to est / (1 + p) instead of est * (1 - p). The latter becomes overpowered at large p, we've seen this formula issue elsewhere (such as BN modifiers).
This commit is contained in:
parent
3d7a6f70d8
commit
f39402e8be
@ -44,13 +44,17 @@ export class City {
|
|||||||
|
|
||||||
/** @param {number} p - the percentage change, not the multiplier. e.g. pass in p = 5 for 5% */
|
/** @param {number} p - the percentage change, not the multiplier. e.g. pass in p = 5 for 5% */
|
||||||
improvePopulationEstimateByPercentage(p: number, skillMult = 1): void {
|
improvePopulationEstimateByPercentage(p: number, skillMult = 1): void {
|
||||||
p = clampNumber((p * skillMult) / 100);
|
const percentage = clampNumber(p * skillMult);
|
||||||
const diff = Math.abs(this.popEst - this.pop);
|
const m = percentage / 100;
|
||||||
// Change would overshoot actual population -> make estimate accurate
|
if (this.popEst < this.pop) {
|
||||||
if (diff <= p * this.popEst) this.popEst = this.pop;
|
// We use an additive factor so we don't get "stuck" at 0.
|
||||||
// Otherwise make estimate closer by n
|
const popGrown = (this.popEst + percentage) * (1 + m);
|
||||||
else if (this.popEst < this.pop) this.popEst = clampNumber(this.popEst * (1 + p), 1);
|
this.popEst = clampNumber(popGrown, 0, this.pop);
|
||||||
else this.popEst = clampNumber(this.popEst * (1 - p));
|
} else {
|
||||||
|
// We use an subtractive factor so we can reach 0 in finite steps.
|
||||||
|
const popShrunk = (this.popEst - percentage) / (1 + m);
|
||||||
|
this.popEst = clampNumber(popShrunk, this.pop);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user