diff --git a/public/src/economy.js b/public/src/economy.js index 6a92661..571f3f3 100644 --- a/public/src/economy.js +++ b/public/src/economy.js @@ -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: + * 0–10 B → ×10, 10–100 B → ×5, 100–1000 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 }); }