mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 17:51:24 +01:00
Fix population aggregation system to eliminate double-counting
- Fixed core issue where cells.pop and burg.population were both being counted - Changed aggregation logic across all modules to use either burg OR cell population, never both - If cell has burg: count only burg population (represents all people in that area) - If cell has no burg: count only cells.pop (represents scattered population) Files modified: - modules/burgs-and-states.js: Fixed state population aggregation - modules/ui/provinces-editor.js: Fixed province population aggregation - modules/dynamic/editors/cultures-editor.js: Fixed culture population aggregation - modules/dynamic/editors/religions-editor.js: Fixed religion population aggregation - modules/ui/biomes-editor.js: Fixed biome population aggregation - modules/ui/zones-editor.js: Fixed zone population calculations (2 locations) - modules/military-generator.js: Redesigned military generation to use only burg populations Military system changes: - Removed rural military generation (all forces now come from settlements) - Only burgs with 500+ people can maintain military forces - Military strength based on actual burg population (2.5% mobilization rate) Result: Population totals now consistent across all CSV exports (~2M total vs previous 40x discrepancy)
This commit is contained in:
parent
334ef2b58b
commit
e669549390
18 changed files with 2960 additions and 297 deletions
|
|
@ -109,9 +109,14 @@ function culturesCollectStatistics() {
|
|||
const cultureId = cells.culture[i];
|
||||
cultures[cultureId].cells += 1;
|
||||
cultures[cultureId].area += cells.area[i];
|
||||
cultures[cultureId].rural += cells.pop[i];
|
||||
const burgId = cells.burg[i];
|
||||
if (burgId) cultures[cultureId].urban += burgs[burgId].population;
|
||||
if (burgId) {
|
||||
// Burg represents ALL population for this cell (stored in thousands)
|
||||
cultures[cultureId].urban += burgs[burgId].population;
|
||||
} else {
|
||||
// Only count cells.pop for unsettled areas (no burg present)
|
||||
cultures[cultureId].rural += cells.pop[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -128,7 +133,7 @@ function culturesEditorAddLines() {
|
|||
if (c.removed) continue;
|
||||
const area = getArea(c.area);
|
||||
const rural = c.rural * populationRate;
|
||||
const urban = c.urban * populationRate * urbanization;
|
||||
const urban = c.urban * 1000 * urbanization;
|
||||
const population = rn(rural + urban);
|
||||
const populationTip = `Total population: ${si(population)}. Rural population: ${si(rural)}. Urban population: ${si(
|
||||
urban
|
||||
|
|
@ -635,7 +640,7 @@ async function showHierarchy() {
|
|||
const getDescription = culture => {
|
||||
const {name, type, rural, urban} = culture;
|
||||
|
||||
const population = rural * populationRate + urban * populationRate * urbanization;
|
||||
const population = rural * populationRate + urban * 1000 * urbanization;
|
||||
const populationText = population > 0 ? si(rn(population)) + " people" : "Extinct";
|
||||
return `${name} culture. ${type}. ${populationText}`;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -119,9 +119,14 @@ function religionsCollectStatistics() {
|
|||
const religionId = cells.religion[i];
|
||||
religions[religionId].cells += 1;
|
||||
religions[religionId].area += cells.area[i];
|
||||
religions[religionId].rural += cells.pop[i];
|
||||
const burgId = cells.burg[i];
|
||||
if (burgId) religions[religionId].urban += burgs[burgId].population;
|
||||
if (burgId) {
|
||||
// Burg represents ALL population for this cell (stored in thousands)
|
||||
religions[religionId].urban += burgs[burgId].population;
|
||||
} else {
|
||||
// Only count cells.pop for unsettled areas (no burg present)
|
||||
religions[religionId].rural += cells.pop[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -138,7 +143,7 @@ function religionsEditorAddLines() {
|
|||
|
||||
const area = getArea(r.area);
|
||||
const rural = r.rural * populationRate;
|
||||
const urban = r.urban * populationRate * urbanization;
|
||||
const urban = r.urban * 1000 * urbanization;
|
||||
const population = rn(rural + urban);
|
||||
const populationTip = `Believers: ${si(population)}; Rural areas: ${si(rural)}; Urban areas: ${si(
|
||||
urban
|
||||
|
|
@ -610,7 +615,7 @@ async function showHierarchy() {
|
|||
};
|
||||
|
||||
const formText = form === type ? "" : ". " + form;
|
||||
const population = rural * populationRate + urban * populationRate * urbanization;
|
||||
const population = rural * populationRate + urban * 1000 * urbanization;
|
||||
const populationText = population > 0 ? si(rn(population)) + " people" : "Extinct";
|
||||
|
||||
return `${name}${getTypeText()}${formText}. ${populationText}`;
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ function statesEditorAddLines() {
|
|||
if (s.removed) continue;
|
||||
const area = getArea(s.area);
|
||||
const rural = s.rural * populationRate;
|
||||
const urban = s.urban * populationRate * urbanization;
|
||||
const urban = s.urban * 1000 * urbanization;
|
||||
const population = rn(rural + urban);
|
||||
const populationTip = `Total population: ${si(population)}; Rural population: ${si(rural)}; Urban population: ${si(
|
||||
urban
|
||||
|
|
@ -1417,10 +1417,12 @@ function downloadStatesCsv() {
|
|||
const headers = `Id,State,Full Name,Form,Color,Capital,Culture,Type,Expansionism,Cells,Burgs,Area ${unit},Total Population,Rural Population,Urban Population`;
|
||||
const lines = Array.from($body.querySelectorAll(":scope > div"));
|
||||
const data = lines.map($line => {
|
||||
const {id, name, form, color, capital, culture, type, expansionism, cells, burgs, area, population} = $line.dataset;
|
||||
const {id, name, form, color, capital, culture, type, expansionism, cells, burgs, area} = $line.dataset;
|
||||
const {fullName = "", rural, urban} = pack.states[+id];
|
||||
// Rural: convert abstract points to people, Urban: already in thousands so convert to people
|
||||
const ruralPopulation = Math.round(rural * populationRate);
|
||||
const urbanPopulation = Math.round(urban * populationRate * urbanization);
|
||||
const urbanPopulation = Math.round(urban * 1000 * urbanization);
|
||||
const totalPopulation = ruralPopulation + urbanPopulation; // Ensure total matches parts
|
||||
return [
|
||||
id,
|
||||
name,
|
||||
|
|
@ -1434,7 +1436,7 @@ function downloadStatesCsv() {
|
|||
cells,
|
||||
burgs,
|
||||
area,
|
||||
population,
|
||||
totalPopulation, // Use calculated total instead of dataset.population
|
||||
ruralPopulation,
|
||||
urbanPopulation
|
||||
].join(",");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue