burgs placement change + resource style

This commit is contained in:
Azgaar 2021-07-07 21:17:39 +03:00 committed by Peter
parent 1e227642c8
commit 84965cf0ca
5 changed files with 111 additions and 97 deletions

46
main.js
View file

@ -77,8 +77,6 @@ let prec = viewbox.append("g").attr("id", "prec").style("display", "none");
let population = viewbox.append("g").attr("id", "population");
let goods = viewbox.append('g').attr('id', 'goods');
let emblems = viewbox.append("g").attr("id", "emblems").style("display", "none");
let goods = viewbox.append("g").attr("id", "goods");
let emblems = viewbox.append("g").attr("id", "emblems").style("display", "none");
let labels = viewbox.append("g").attr("id", "labels");
let icons = viewbox.append("g").attr("id", "icons");
let burgIcons = icons.append("g").attr("id", "burgIcons");
@ -1540,15 +1538,15 @@ function getBiomeId(moisture, temperature, height) {
return biomesData.biomesMartix[moistureBand][temperatureBand];
}
// 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); // get bonus resource scope
const POP_BALANCER = 1.5; // to ballance population to desired number
@ -1556,24 +1554,24 @@ function rankCells() {
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
}
}
@ -1584,9 +1582,17 @@ function rankCells() {
const resBonus = (cellRes ? cellRes + 10 : 0) + neibRes;
// 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');
}