Skip to content
Snippets Groups Projects
Commit 99ed2470 authored by Arkerthan's avatar Arkerthan
Browse files

Scale final distribution by nationality population

parent bea72c53
Branches
Tags
1 merge request!12359Add system to create slave pop distribution based on location in world [READY for testing]
App.Data.World.TravelFrictionExponent = -0.5; // The smaller, the more global
App.Data.World.TravelFrictionExponent = -0.6;
// The smaller, the more are large nationalities downscaled
App.Data.World.PopScaleFactor = 23;
/** /**
* @typedef {Record<number, number>} gridPoint * @typedef {Record<number, number>} gridPoint
......
...@@ -410,8 +410,7 @@ App.Intro.CustomSlaveTrade = function() { ...@@ -410,8 +410,7 @@ App.Intro.CustomSlaveTrade = function() {
g.append("circle").attr("cx", lon).attr("cy", lat).attr("r", 0.5).attr("fill", "red"); g.append("circle").attr("cx", lon).attr("cy", lat).attr("r", 0.5).attr("fill", "red");
}*/ }*/
/*
/*
if (App.Data.World.nationIdAt(p) >= 223) { if (App.Data.World.nationIdAt(p) >= 223) {
console.log(p); console.log(p);
const [lat, lon] = App.Data.World.gridPointToCoordinate(p); const [lat, lon] = App.Data.World.gridPointToCoordinate(p);
...@@ -427,6 +426,47 @@ App.Intro.CustomSlaveTrade = function() { ...@@ -427,6 +426,47 @@ App.Intro.CustomSlaveTrade = function() {
let lat = ((y / height) * 180 - 90) * -1; let lat = ((y / height) * 180 - 90) * -1;
console.log(lon, lat); console.log(lon, lat);
populateFromCoordinates(lat, lon); populateFromCoordinates(lat, lon);
scalePopulations();
refresh();
}
}
/**
* Scale final nationalities by their global population.
* This decreases the impact large countries have while increasing the relevance of smaller ones
*/
function scalePopulations() {
// Build pop cache
const cache = {};
for (const p of App.Data.World.gridPoints()) {
const nation = App.Data.World.nationAt(p);
const pop = App.Data.World.populationAt(p);
if (cache.hasOwnProperty(nation)) {
cache[nation] += pop;
} else {
cache[nation] = pop;
}
}
// Build pop scale cache
for (const p in cache) {
const pop = cache[p];
const a = Math.exp(App.Data.World.PopScaleFactor);
const scaled = a * Math.log1p(pop / a);
cache[p] = scaled / pop;
}
// Apply pop scale
for (const n in V.nationalities) {
const pop = Math.round(V.nationalities[n] * cache[n]);
if (n === "Vatican") {
console.log(pop, V.nationalities[n]);
}
if (pop > 0) {
V.nationalities[n] = pop;
} else {
delete V.nationalities[n];
}
} }
} }
...@@ -467,10 +507,10 @@ App.Intro.CustomSlaveTrade = function() { ...@@ -467,10 +507,10 @@ App.Intro.CustomSlaveTrade = function() {
gravity = 1; // always give _some_ population for the grid cell you clicked on, if it's inhabited gravity = 1; // always give _some_ population for the grid cell you clicked on, if it's inhabited
} }
const nation = App.Data.World.nationAt(p); const nation = App.Data.World.nationAt(p);
addNationality(nation, Math.round(gravity)); // console.log(nation, gravity, Math.round(gravity));
addNationality(nation, gravity);
} }
} }
refresh();
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment