burgs placement change + resource style

This commit is contained in:
Azgaar 2021-07-07 21:17:39 +03:00
parent dc6528665a
commit b7545d2805
6 changed files with 687 additions and 479 deletions

57
main.js
View file

@ -357,7 +357,7 @@ function applyDefaultBiomesSystem() {
'Wetland'
];
const color = ['#466eab', '#fbe79f', '#b5b887', '#d2d082', '#c8d68f', '#b6d95d', '#29bc56', '#7dcb35', '#409c43', '#4b6b32', '#96784b', '#d5e7eb', '#0b9131'];
const habitability = [0, 4, 10, 22, 30, 50, 100, 80, 90, 12, 4, 0, 12];
const habitability = [0, 4, 10, 25, 40, 60, 100, 80, 90, 12, 4, 0, 12];
const iconsDensity = [0, 3, 2, 120, 120, 120, 120, 150, 150, 100, 5, 0, 150];
const icons = [
{},
@ -1411,45 +1411,62 @@ function getBiomeId(moisture, temperature, height) {
return biomesData.biomesMartix[m][t];
}
// assess cells suitability to calculate population and rand cells for culture center and burgs placement
// assess cells suitability to calculate population and rang cells for culture center and burgs placement
function rankCells() {
TIME && console.time('rankCells');
const {cells, features} = pack;
cells.s = new Int16Array(cells.i.length); // cell suitability array
cells.pop = new Float32Array(cells.i.length); // cell population array
const flMean = d3.median(cells.fl.filter((f) => f)) || 0,
flMax = d3.max(cells.fl) + d3.max(cells.conf); // to normalize flux
const flMean = d3.median(cells.fl.filter((f) => f)) || 0;
const 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 getResValue = (i) => (cells.resource[i] ? Resources.get(cells.resource[i])?.value : 0);
const resBonuses = [];
const POP_BALANCER = 1.5; // contant to ballance population to desired number not changing ranking
for (const i of cells.i) {
if (cells.b[i]) continue; // avoid adding burgs on map border
if (cells.h[i] < 20) continue; // no population in water
let s = +biomesData.habitability[cells.biome[i]]; // base suitability derived from biome habitability
let s = biomesData.habitability[cells.biome[i]] / 10; // base suitability derived from biome habitability
if (!s) continue; // uninhabitable biomes has 0 suitability
if (flMean) s += normalize(cells.fl[i] + cells.conf[i], flMean, flMax) * 250; // big rivers and confluences are valued
s -= (cells.h[i] - 50) / 5; // low elevation is valued, high is not;
if (flMean) s += normalize(cells.fl[i] + cells.conf[i], flMean, flMax) * 50; // big rivers and confluences are valued
s -= (cells.h[i] - 50) / 25; // low elevation is valued, high is not;
if (cells.t[i] === 1) {
if (cells.r[i]) s += 15; // estuary is valued
const feature = features[cells.f[cells.haven[i]]];
if (feature.type === 'lake') {
if (feature.group === 'freshwater') s += 30;
else if (feature.group == 'salt') s += 10;
else if (feature.group == 'frozen') s += 1;
else if (feature.group == 'dry') s -= 5;
else if (feature.group == 'sinkhole') s -= 5;
else if (feature.group == 'lava') s -= 30;
if (cells.r[i]) s += 3; // estuary is valued
const {type, group} = features[cells.f[cells.haven[i]]];
if (type === 'lake') {
if (group === 'freshwater') s += 5;
else if (group == 'salt') s += 2;
else if (group == 'dry') s -= 1;
else if (group == 'sinkhole') s -= 1;
else if (group == 'lava') s -= 6;
} else {
s += 5; // ocean coast is valued
if (cells.harbor[i] === 1) s += 20; // safe sea harbor is valued
s += 1; // ocean coast is valued
if (cells.harbor[i] === 1) s += 4; // safe sea harbor is valued
}
}
cells.s[i] = s / 5; // general population rate
// add bonus for resources around
const cellRes = getResValue(i);
const neibRes = d3.mean(cells.c[i].map((c) => getResValue(c)));
const resBonus = (cellRes ? cellRes + 10 : 0) + neibRes;
resBonuses.push(resBonus);
// cell rural population is suitability adjusted by cell area
cells.pop[i] = cells.s[i] > 0 ? (cells.s[i] * cells.area[i]) / areaMean : 0;
cells.pop[i] = s > 0 ? (s * POP_BALANCER * cells.area[i]) / areaMean : 0;
cells.s[i] = s + resBonus;
debug.append('text').attr('x', cells.p[i][0]).attr('y', cells.p[i][1]).text(cells.s[i]);
}
console.log(resBonuses);
console.log(d3.max(resBonuses));
console.log(d3.mean(resBonuses));
console.log(d3.median(resBonuses.map((v) => rn(v))));
TIME && console.timeEnd('rankCells');
}