This commit is contained in:
Azgaar 2019-10-03 00:48:33 +03:00
parent 481d7da4e6
commit 8ff1fe46b8
9 changed files with 31 additions and 28 deletions

View file

@ -1186,7 +1186,7 @@ function rankCells() {
console.time('rankCells'); console.time('rankCells');
const cells = pack.cells, f = pack.features; const cells = pack.cells, f = pack.features;
cells.s = new Int16Array(cells.i.length); // cell suitability array cells.s = new Int16Array(cells.i.length); // cell suitability array
cells.pop = new Uint16Array(cells.i.length); // cell population array cells.pop = new Float32Array(cells.i.length); // cell population array
const flMean = d3.median(cells.fl.filter(f => f)), flMax = d3.max(cells.fl) + d3.max(cells.conf); // to normalize flux const flMean = d3.median(cells.fl.filter(f => f)), flMax = d3.max(cells.fl) + d3.max(cells.conf); // to normalize flux
const areaMean = d3.mean(cells.area); // to adjust population by cell area const areaMean = d3.mean(cells.area); // to adjust population by cell area

View file

@ -198,12 +198,15 @@ function getMapData() {
return `${b.name}|${b.min}|${b.max}|${b.d}|${b.m}|${names}`; return `${b.name}|${b.min}|${b.max}|${b.d}|${b.m}|${names}`;
}).join("/"); }).join("/");
// round population to save resources
const pop = Array.from(pack.cells.pop).map(p => rn(p, 4));
// data format as below // data format as below
const data = [params, options, coords, biomes, notesData, svg_xml, const data = [params, options, coords, biomes, notesData, svg_xml,
gridGeneral, grid.cells.h, grid.cells.prec, grid.cells.f, grid.cells.t, grid.cells.temp, gridGeneral, grid.cells.h, grid.cells.prec, grid.cells.f, grid.cells.t, grid.cells.temp,
features, cultures, states, burgs, features, cultures, states, burgs,
pack.cells.biome, pack.cells.burg, pack.cells.conf, pack.cells.culture, pack.cells.fl, pack.cells.biome, pack.cells.burg, pack.cells.conf, pack.cells.culture, pack.cells.fl,
pack.cells.pop, pack.cells.r, pack.cells.road, pack.cells.s, pack.cells.state, pop, pack.cells.r, pack.cells.road, pack.cells.s, pack.cells.state,
pack.cells.religion, pack.cells.province, pack.cells.crossroad, religions, provinces, pack.cells.religion, pack.cells.province, pack.cells.crossroad, religions, provinces,
namesData].join("\r\n"); namesData].join("\r\n");
const blob = new Blob([data], {type: "text/plain"}); const blob = new Blob([data], {type: "text/plain"});
@ -666,7 +669,7 @@ function parseLoadedData(data) {
cells.conf = Uint8Array.from(data[18].split(",")); cells.conf = Uint8Array.from(data[18].split(","));
cells.culture = Uint16Array.from(data[19].split(",")); cells.culture = Uint16Array.from(data[19].split(","));
cells.fl = Uint16Array.from(data[20].split(",")); cells.fl = Uint16Array.from(data[20].split(","));
cells.pop = Uint16Array.from(data[21].split(",")); cells.pop = Float32Array.from(data[21].split(","));
cells.r = Uint16Array.from(data[22].split(",")); cells.r = Uint16Array.from(data[22].split(","));
cells.road = Uint16Array.from(data[23].split(",")); cells.road = Uint16Array.from(data[23].split(","));
cells.s = Uint16Array.from(data[24].split(",")); cells.s = Uint16Array.from(data[24].split(","));

View file

@ -235,7 +235,7 @@ function editBurg(id) {
function changePopulation() { function changePopulation() {
const id = +elSelected.attr("data-id"); const id = +elSelected.attr("data-id");
pack.burgs[id].population = burgPopulation.value / populationRate.value / urbanization.value; pack.burgs[id].population = rn(burgPopulation.value / populationRate.value / urbanization.value, 4);
} }
function toggleFeature() { function toggleFeature() {

View file

@ -237,7 +237,7 @@ function editCultures() {
}); });
function applyPopulationChange() { function applyPopulationChange() {
const ruralChange = rn(ruralPop.value / rural, 4); const ruralChange = ruralPop.value / rural;
if (isFinite(ruralChange) && ruralChange !== 1) { if (isFinite(ruralChange) && ruralChange !== 1) {
const cells = pack.cells.i.filter(i => pack.cells.culture[i] === culture); const cells = pack.cells.i.filter(i => pack.cells.culture[i] === culture);
cells.forEach(i => pack.cells.pop[i] *= ruralChange); cells.forEach(i => pack.cells.pop[i] *= ruralChange);
@ -249,13 +249,13 @@ function editCultures() {
cells.forEach(i => pack.cells.pop[i] = pop); cells.forEach(i => pack.cells.pop[i] = pop);
} }
const urbanChange = rn(urbanPop.value / urban, 4); const urbanChange = urbanPop.value / urban;
if (isFinite(urbanChange) && urbanChange !== 1) { if (isFinite(urbanChange) && urbanChange !== 1) {
burgs.forEach(b => b.population *= urbanChange); burgs.forEach(b => b.population = rn(b.population * urbanChange, 4));
} }
if (!isFinite(urbanChange) && +urbanPop.value > 0) { if (!isFinite(urbanChange) && +urbanPop.value > 0) {
const points = urbanPop.value / populationRate.value / urbanization.value; const points = urbanPop.value / populationRate.value / urbanization.value;
const population = rn(points / burgs.length); const population = rn(points / burgs.length, 4);
burgs.forEach(b => b.population = population); burgs.forEach(b => b.population = population);
} }

View file

@ -263,7 +263,7 @@ function getHeight(h) {
// assign saved pack data from grid back to pack // assign saved pack data from grid back to pack
const n = pack.cells.i.length; const n = pack.cells.i.length;
pack.cells.pop = new Uint16Array(n); pack.cells.pop = new Float32Array(n);
pack.cells.road = new Uint16Array(n); pack.cells.road = new Uint16Array(n);
pack.cells.crossroad = new Uint16Array(n); pack.cells.crossroad = new Uint16Array(n);
pack.cells.s = new Uint16Array(n); pack.cells.s = new Uint16Array(n);

View file

@ -114,9 +114,9 @@ function editProvinces() {
const focused = defs.select("#fog #focusProvince"+p.i).size(); const focused = defs.select("#fog #focusProvince"+p.i).size();
lines += `<div class="states" data-id=${p.i} data-name=${p.name} data-form=${p.formName} data-color="${p.color}" data-capital="${capital}" data-state="${stateName}" data-area=${area} data-population=${population}> lines += `<div class="states" data-id=${p.i} data-name=${p.name} data-form=${p.formName} data-color="${p.color}" data-capital="${capital}" data-state="${stateName}" data-area=${area} data-population=${population}>
<svg data-tip="Province fill style. Click to change" width=".9em" height=".9em" style="margin-bottom:-1px"><rect x="0" y="0" width="100%" height="100%" fill="${p.color}" class="zoneFill"></svg> <svg data-tip="Province fill style. Click to change" width=".9em" height=".9em" style="margin-bottom:-1px"><rect x="0" y="0" width="100%" height="100%" fill="${p.color}" class="zoneFill"></svg>
<input data-tip="Province name. Click and type to change" class="name pointer" value="${p.name}" readonly> <input data-tip="Province name. Click to change" class="name pointer" value="${p.name}" readonly>
<span data-tip="Click to open province COA in the Iron Arachne Heraldry Generator. Ctrl + click to change the seed" class="icon-fleur pointer hide"></span> <span data-tip="Click to open province COA in the Iron Arachne Heraldry Generator. Ctrl + click to change the seed" class="icon-fleur pointer hide"></span>
<input data-tip="Province form name. Click and type to change" class="name pointer hide" value="${p.formName}" readonly> <input data-tip="Province form name. Click to change" class="name pointer hide" value="${p.formName}" readonly>
<span data-tip="Province capital. Click to zoom into view" class="icon-star-empty pointer hide ${p.burg?'':'placeholder'}"></span> <span data-tip="Province capital. Click to zoom into view" class="icon-star-empty pointer hide ${p.burg?'':'placeholder'}"></span>
<select data-tip="Province capital. Click to select from burgs within the state. No capital means the province is governed from the state capital" class="cultureBase hide ${p.burgs.length?'':'placeholder'}">${p.burgs.length ? getCapitalOptions(p.burgs, p.burg) : ''}</select> <select data-tip="Province capital. Click to select from burgs within the state. No capital means the province is governed from the state capital" class="cultureBase hide ${p.burgs.length?'':'placeholder'}">${p.burgs.length ? getCapitalOptions(p.burgs, p.burg) : ''}</select>
<input data-tip="Province owner" class="provinceOwner" value="${stateName}" disabled"> <input data-tip="Province owner" class="provinceOwner" value="${stateName}" disabled">
@ -305,7 +305,7 @@ function editProvinces() {
}); });
function applyPopulationChange() { function applyPopulationChange() {
const ruralChange = rn(ruralPop.value / rural, 4); const ruralChange = ruralPop.value / rural;
if (isFinite(ruralChange) && ruralChange !== 1) { if (isFinite(ruralChange) && ruralChange !== 1) {
cells.forEach(i => pack.cells.pop[i] *= ruralChange); cells.forEach(i => pack.cells.pop[i] *= ruralChange);
} }
@ -315,13 +315,13 @@ function editProvinces() {
cells.forEach(i => pack.cells.pop[i] = pop); cells.forEach(i => pack.cells.pop[i] = pop);
} }
const urbanChange = rn(urbanPop.value / urban, 4); const urbanChange = urbanPop.value / urban;
if (isFinite(urbanChange) && urbanChange !== 1) { if (isFinite(urbanChange) && urbanChange !== 1) {
p.burgs.forEach(b => pack.burgs[b].population *= urbanChange); p.burgs.forEach(b => pack.burgs[b].population = rn(pack.burgs[b].population * urbanChange, 4));
} }
if (!isFinite(urbanChange) && +urbanPop.value > 0) { if (!isFinite(urbanChange) && +urbanPop.value > 0) {
const points = urbanPop.value / populationRate.value / urbanization.value; const points = urbanPop.value / populationRate.value / urbanization.value;
const population = rn(points / burgs.length); const population = rn(points / burgs.length, 4);
p.burgs.forEach(b => pack.burgs[b].population = population); p.burgs.forEach(b => pack.burgs[b].population = population);
} }

View file

@ -263,7 +263,7 @@ function editReligions() {
}); });
function applyPopulationChange() { function applyPopulationChange() {
const ruralChange = rn(ruralPop.value / rural, 4); const ruralChange = ruralPop.value / rural;
if (isFinite(ruralChange) && ruralChange !== 1) { if (isFinite(ruralChange) && ruralChange !== 1) {
const cells = pack.cells.i.filter(i => pack.cells.religion[i] === religion); const cells = pack.cells.i.filter(i => pack.cells.religion[i] === religion);
cells.forEach(i => pack.cells.pop[i] *= ruralChange); cells.forEach(i => pack.cells.pop[i] *= ruralChange);
@ -275,13 +275,13 @@ function editReligions() {
cells.forEach(i => pack.cells.pop[i] = pop); cells.forEach(i => pack.cells.pop[i] = pop);
} }
const urbanChange = rn(urbanPop.value / urban, 4); const urbanChange = urbanPop.value / urban;
if (isFinite(urbanChange) && urbanChange !== 1) { if (isFinite(urbanChange) && urbanChange !== 1) {
burgs.forEach(b => b.population *= urbanChange); burgs.forEach(b => b.population = rn(b.population * urbanChange, 4));
} }
if (!isFinite(urbanChange) && +urbanPop.value > 0) { if (!isFinite(urbanChange) && +urbanPop.value > 0) {
const points = urbanPop.value / populationRate.value / urbanization.value; const points = urbanPop.value / populationRate.value / urbanization.value;
const population = rn(points / burgs.length); const population = rn(points / burgs.length, 4);
burgs.forEach(b => b.population = population); burgs.forEach(b => b.population = population);
} }

View file

@ -331,7 +331,7 @@ function editStates() {
}); });
function applyPopulationChange() { function applyPopulationChange() {
const ruralChange = rn(ruralPop.value / rural, 4); const ruralChange = ruralPop.value / rural;
if (isFinite(ruralChange) && ruralChange !== 1) { if (isFinite(ruralChange) && ruralChange !== 1) {
const cells = pack.cells.i.filter(i => pack.cells.state[i] === state); const cells = pack.cells.i.filter(i => pack.cells.state[i] === state);
cells.forEach(i => pack.cells.pop[i] *= ruralChange); cells.forEach(i => pack.cells.pop[i] *= ruralChange);
@ -339,19 +339,19 @@ function editStates() {
if (!isFinite(ruralChange) && +ruralPop.value > 0) { if (!isFinite(ruralChange) && +ruralPop.value > 0) {
const points = ruralPop.value / populationRate.value; const points = ruralPop.value / populationRate.value;
const cells = pack.cells.i.filter(i => pack.cells.state[i] === state); const cells = pack.cells.i.filter(i => pack.cells.state[i] === state);
const pop = rn(points / cells.length); const pop = points / cells.length;
cells.forEach(i => pack.cells.pop[i] = pop); cells.forEach(i => pack.cells.pop[i] = pop);
} }
const urbanChange = rn(urbanPop.value / urban, 4); const urbanChange = urbanPop.value / urban;
if (isFinite(urbanChange) && urbanChange !== 1) { if (isFinite(urbanChange) && urbanChange !== 1) {
const burgs = pack.burgs.filter(b => !b.removed && b.state === state); const burgs = pack.burgs.filter(b => !b.removed && b.state === state);
burgs.forEach(b => b.population *= urbanChange); burgs.forEach(b => b.population = rn(b.population * urbanChange, 4));
} }
if (!isFinite(urbanChange) && +urbanPop.value > 0) { if (!isFinite(urbanChange) && +urbanPop.value > 0) {
const points = urbanPop.value / populationRate.value / urbanization.value; const points = urbanPop.value / populationRate.value / urbanization.value;
const burgs = pack.burgs.filter(b => !b.removed && b.state === state); const burgs = pack.burgs.filter(b => !b.removed && b.state === state);
const population = rn(points / burgs.length); const population = rn(points / burgs.length, 4);
burgs.forEach(b => b.population = population); burgs.forEach(b => b.population = population);
} }

View file

@ -393,7 +393,7 @@ function editZones() {
}); });
function applyPopulationChange() { function applyPopulationChange() {
const ruralChange = rn(ruralPop.value / rural, 4); const ruralChange = ruralPop.value / rural;
if (isFinite(ruralChange) && ruralChange !== 1) { if (isFinite(ruralChange) && ruralChange !== 1) {
cells.forEach(i => pack.cells.pop[i] *= ruralChange); cells.forEach(i => pack.cells.pop[i] *= ruralChange);
} }
@ -403,13 +403,13 @@ function editZones() {
cells.forEach(i => pack.cells.pop[i] = pop); cells.forEach(i => pack.cells.pop[i] = pop);
} }
const urbanChange = rn(urbanPop.value / urban, 4); const urbanChange = urbanPop.value / urban;
if (isFinite(urbanChange) && urbanChange !== 1) { if (isFinite(urbanChange) && urbanChange !== 1) {
burgs.forEach(b => b.population *= urbanChange); burgs.forEach(b => b.population = rn(b.population * urbanChange, 4));
} }
if (!isFinite(urbanChange) && +urbanPop.value > 0) { if (!isFinite(urbanChange) && +urbanPop.value > 0) {
const points = urbanPop.value / populationRate.value / urbanization.value; const points = urbanPop.value / populationRate.value / urbanization.value;
const population = rn(points / burgs.length); const population = rn(points / burgs.length, 4);
burgs.forEach(b => b.population = population); burgs.forEach(b => b.population = population);
} }