19 lines
945 B
JavaScript
19 lines
945 B
JavaScript
// Sector quality drifts toward a target set by the budget ratio (alloc / need).
|
|
// Each sector has its own time constant: police reacts in weeks, infrastructure in years.
|
|
|
|
import { clamp, qualityFromRatio } from "./state.js";
|
|
import { biasFor } from "./modifiers.js";
|
|
|
|
export function stepSectors(state, bal, fiscal) {
|
|
const s = bal.sector;
|
|
for (const [id, sec] of Object.entries(state.sectors)) {
|
|
// Needs grow with population, ageing and prices: standing still buys less each year.
|
|
sec.need *= Math.pow(1 + (bal.needGrowth?.[id] ?? 0), 1 / 365);
|
|
let target = qualityFromRatio(sec.alloc / sec.need, bal) + biasFor(state, "sector", id);
|
|
if (id === "industry" && fiscal.debtRatio > s.industryDebtPenaltyFrom) {
|
|
target -= s.industryDebtPenaltyPerPoint * (fiscal.debtRatio - s.industryDebtPenaltyFrom);
|
|
}
|
|
sec.quality = clamp(sec.quality + (clamp(target, 0, 100) - sec.quality) / bal.sectorTau[id], 0, 100);
|
|
}
|
|
}
|