refacto: Adding population factors to the money gained from planets
This commit is contained in:
+22
-2
@@ -60,6 +60,24 @@ const LABEL_TO_RESOURCE = (() => {
|
|||||||
|
|
||||||
// ── Income calculation ────────────────────────────────────────────────────────
|
// ── 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.
|
* 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;
|
const { naturalResources } = meta.planet;
|
||||||
if (!naturalResources) continue;
|
if (!naturalResources) continue;
|
||||||
|
|
||||||
|
const popFactor = meta.planet.population ? populationFactor(meta.planet.population.billions) : 1;
|
||||||
for (const [label, pct] of Object.entries(naturalResources)) {
|
for (const [label, pct] of Object.entries(naturalResources)) {
|
||||||
const info = LABEL_TO_RESOURCE.get(label);
|
const info = LABEL_TO_RESOURCE.get(label);
|
||||||
if (!info) continue;
|
if (!info) continue;
|
||||||
const worth = resourceWorth?.[info.cat]?.[info.key] ?? 0;
|
const worth = resourceWorth?.[info.cat]?.[info.key] ?? 0;
|
||||||
if (worth === 0) continue;
|
if (worth === 0) continue;
|
||||||
const income = (pct / 100) * worth;
|
const income = (pct / 100) * worth * popFactor;
|
||||||
byResource.set(label, (byResource.get(label) ?? 0) + income);
|
byResource.set(label, (byResource.get(label) ?? 0) + income);
|
||||||
total += income;
|
total += income;
|
||||||
}
|
}
|
||||||
@@ -109,13 +128,14 @@ export function computeTeamIncomeByPlanet(team, cells, resourceWorth) {
|
|||||||
if (!meta.hasPlanet || !meta.planet) continue;
|
if (!meta.hasPlanet || !meta.planet) continue;
|
||||||
const { name, naturalResources } = meta.planet;
|
const { name, naturalResources } = meta.planet;
|
||||||
if (!naturalResources) continue;
|
if (!naturalResources) continue;
|
||||||
|
const popFactor = meta.planet.population ? populationFactor(meta.planet.population.billions) : 1;
|
||||||
let income = 0;
|
let income = 0;
|
||||||
for (const [label, pct] of Object.entries(naturalResources)) {
|
for (const [label, pct] of Object.entries(naturalResources)) {
|
||||||
const info = LABEL_TO_RESOURCE.get(label);
|
const info = LABEL_TO_RESOURCE.get(label);
|
||||||
if (!info) continue;
|
if (!info) continue;
|
||||||
const worth = resourceWorth?.[info.cat]?.[info.key] ?? 0;
|
const worth = resourceWorth?.[info.cat]?.[info.key] ?? 0;
|
||||||
if (worth === 0) continue;
|
if (worth === 0) continue;
|
||||||
income += (pct / 100) * worth;
|
income += (pct / 100) * worth * popFactor;
|
||||||
}
|
}
|
||||||
if (income > 0) rows.push({ name: name ?? "?", income });
|
if (income > 0) rows.push({ name: name ?? "?", income });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user