map/mapFeatureSettlements.js

47 lines
1.8 KiB
JavaScript
Raw Normal View History

2026-05-28 02:47:33 +09:00
import { MAP_H, MAP_W, SIZE, clamp, indexOf } from "./mapUtils.js";
import { influenceFromPoints } from "./mapGeneratorHelpers.js";
export function buildSettlementDemandFields(ctx) {
const {
sea, agriculture, plain, basinField, coastalLowland, slope, ridgeField,
modernCities, markets, commercialPorts, villages,
} = ctx;
const preliminaryUrbanInfluence = influenceFromPoints(modernCities, 18, (c) => clamp((c.population || 60000) / 260000, 0.55, 2.0));
const preliminaryTownInfluence = influenceFromPoints([...markets, ...commercialPorts], 10, (p) => p.portClass === "major" ? 1.35 : clamp((p.population || 12000) / 36000, 0.42, 1.1));
const preliminaryVillageInfluence = influenceFromPoints(villages, 7, (v) => clamp((v.population || 1800) / 5200, 0.22, 0.9));
const settlementDemand = new Float32Array(SIZE);
const urbanEdge = new Float32Array(SIZE);
const logisticsPreSuitability = new Float32Array(SIZE);
for (let y = 0; y < MAP_H; y++) {
for (let x = 0; x < MAP_W; x++) {
const i = indexOf(x, y);
if (sea[i]) continue;
const density = clamp(preliminaryUrbanInfluence[i] * 0.62 + preliminaryTownInfluence[i] * 0.34 + preliminaryVillageInfluence[i] * 0.16);
settlementDemand[i] = density;
urbanEdge[i] = clamp(1 - Math.abs(density - 0.46) / 0.32);
logisticsPreSuitability[i] = clamp(
agriculture[i] * 0.30 +
plain[i] * 0.24 +
basinField[i] * 0.14 +
coastalLowland[i] * 0.12 +
preliminaryTownInfluence[i] * 0.18 +
urbanEdge[i] * 0.34 -
preliminaryUrbanInfluence[i] * 0.20 -
slope[i] * 0.50 -
ridgeField[i] * 0.32
);
}
}
return {
preliminaryUrbanInfluence,
preliminaryTownInfluence,
preliminaryVillageInfluence,
settlementDemand,
urbanEdge,
logisticsPreSuitability,
};
}