From 0b56e0deb013b8da99fac54bd25ffb96835bb87d Mon Sep 17 00:00:00 2001 From: gauvainboiche Date: Thu, 2 Apr 2026 15:51:59 +0200 Subject: [PATCH] fix: Economy factors taken in charge in websockets --- server/helpers/economy.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/server/helpers/economy.js b/server/helpers/economy.js index 21c7394..d226f37 100644 --- a/server/helpers/economy.js +++ b/server/helpers/economy.js @@ -70,6 +70,24 @@ const ELEMENT_LABEL_TO_KEY = Object.fromEntries( // ── Income computation ──────────────────────────────────────────────────────── +/** + * Population-based income multiplier (mirrors public/src/economy.js). + * 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 total income per second for a team from DB grid rows. * @@ -83,14 +101,15 @@ export function computeTeamIncome(team, rows, resourceWorth) { for (const row of rows) { if (row.discovered_by !== team) continue; if (!row.has_planet || !row.planet_json) continue; - const { naturalResources } = row.planet_json; + const { naturalResources, population } = row.planet_json; if (!naturalResources) continue; + const popFactor = population ? populationFactor(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; - total += (pct / 100) * worth; + total += (pct / 100) * worth * popFactor; } } return total;