refacto: Adding population factors to the money gained from planets

This commit is contained in:
gauvainboiche
2026-04-02 15:20:36 +02:00
parent 5ce2ae6c98
commit e573ea0d37
+22 -2
View File
@@ -60,6 +60,24 @@ const LABEL_TO_RESOURCE = (() => {
// ── Income calculation ────────────────────────────────────────────────────────
/**
* Returns a multiplier based on planet population.
* Base factor = billions / 10, plus an efficiency boost for smaller populations:
* 010 B → ×10, 10100 B → ×5, 1001000 B → ×2.5, >1000 B → ×1
*
* @param {number} billions
* @returns {number}
*/
function populationFactor(billions) {
const base = billions / 10;
let boost;
if (billions < 10) boost = 10;
else if (billions < 100) boost = 5;
else if (billions < 1000) boost = 2.5;
else boost = 1;
return base * boost;
}
/**
* Compute income per second for a team based on their discovered planets.
*
@@ -80,12 +98,13 @@ export function computeTeamIncome(team, cells, resourceWorth) {
const { naturalResources } = meta.planet;
if (!naturalResources) continue;
const popFactor = meta.planet.population ? populationFactor(meta.planet.population.billions) : 1;
for (const [label, pct] of Object.entries(naturalResources)) {
const info = LABEL_TO_RESOURCE.get(label);
if (!info) continue;
const worth = resourceWorth?.[info.cat]?.[info.key] ?? 0;
if (worth === 0) continue;
const income = (pct / 100) * worth;
const income = (pct / 100) * worth * popFactor;
byResource.set(label, (byResource.get(label) ?? 0) + income);
total += income;
}
@@ -109,13 +128,14 @@ export function computeTeamIncomeByPlanet(team, cells, resourceWorth) {
if (!meta.hasPlanet || !meta.planet) continue;
const { name, naturalResources } = meta.planet;
if (!naturalResources) continue;
const popFactor = meta.planet.population ? populationFactor(meta.planet.population.billions) : 1;
let income = 0;
for (const [label, pct] of Object.entries(naturalResources)) {
const info = LABEL_TO_RESOURCE.get(label);
if (!info) continue;
const worth = resourceWorth?.[info.cat]?.[info.key] ?? 0;
if (worth === 0) continue;
income += (pct / 100) * worth;
income += (pct / 100) * worth * popFactor;
}
if (income > 0) rows.push({ name: name ?? "?", income });
}