not good but not bad
This commit is contained in:
parent
5c82bfcab7
commit
4f0df3f6c5
11 changed files with 1284 additions and 622 deletions
69
mapOutput.js
69
mapOutput.js
|
|
@ -24,6 +24,48 @@ function municipalityNameFromRoot(root, center, fields, seed, ordinal = 0) {
|
|||
return `${value}${municipalitySuffixForCenter(center, fields, seed, ordinal)}`;
|
||||
}
|
||||
|
||||
function buildPrefectureRegions(prefectureRegionId, sea, fields, seed, usedNames, nameDebug) {
|
||||
if (!prefectureRegionId) return [];
|
||||
const byId = new Map();
|
||||
for (let i = 0; i < prefectureRegionId.length; i++) {
|
||||
const id = prefectureRegionId[i];
|
||||
if (sea[i] || id < 0) continue;
|
||||
if (!byId.has(id)) byId.set(id, { id, area: 0, sx: 0, sy: 0, cells: [] });
|
||||
const row = byId.get(id);
|
||||
const x = i % MAP_W;
|
||||
const y = Math.floor(i / MAP_W);
|
||||
row.area++;
|
||||
row.sx += x;
|
||||
row.sy += y;
|
||||
row.cells.push(i);
|
||||
}
|
||||
const regions = [];
|
||||
for (const row of [...byId.values()].sort((a, b) => a.id - b.id)) {
|
||||
const cx = row.sx / Math.max(1, row.area);
|
||||
const cy = row.sy / Math.max(1, row.area);
|
||||
let bestI = row.cells[0];
|
||||
let bestScore = -INF;
|
||||
for (const i of row.cells) {
|
||||
const x = i % MAP_W;
|
||||
const y = Math.floor(i / MAP_W);
|
||||
const score =
|
||||
(fields.populationDensity?.[i] || 0) * 1.6 +
|
||||
(fields.plain?.[i] || 0) * 0.28 +
|
||||
(fields.basinField?.[i] || 0) * 0.22 +
|
||||
(fields.coastalLowland?.[i] || 0) * 0.16 -
|
||||
(fields.slope?.[i] || 0) * 0.36 -
|
||||
(fields.ridgeField?.[i] || 0) * 0.30 -
|
||||
Math.hypot(x - cx, y - cy) * 0.08;
|
||||
if (score > bestScore) { bestScore = score; bestI = i; }
|
||||
}
|
||||
const x = bestI % MAP_W;
|
||||
const y = Math.floor(bestI / MAP_W);
|
||||
regions.push({ id: row.id, x, y, area: row.area, kind: row.id === 0 ? "Current Prefecture" : "Prefecture", labelPriorityBase: 900 + Math.sqrt(row.area) });
|
||||
}
|
||||
return attachIdsAndNames(regions, "prefecture", seed + 41000, null, fields, usedNames, nameDebug)
|
||||
.map((region, index) => ({ ...region, featureId: region.id, id: regions[index].id, labelName: region.name }));
|
||||
}
|
||||
|
||||
export function finishMapOutput({
|
||||
seed,
|
||||
options,
|
||||
|
|
@ -65,10 +107,7 @@ export function finishMapOutput({
|
|||
smallStreams,
|
||||
prefectureMask,
|
||||
prefectureBorder,
|
||||
prefectureRegionId,
|
||||
regionalDebug,
|
||||
terrainDebug,
|
||||
regionalPrefectureBorders,
|
||||
} = terrain;
|
||||
|
||||
const {
|
||||
|
|
@ -115,6 +154,12 @@ export function finishMapOutput({
|
|||
adminId,
|
||||
adminBorders,
|
||||
adminDebug,
|
||||
prefectureRegionId,
|
||||
municipalityToPrefectureId,
|
||||
regionalPrefectureBorders: adminRegionalPrefectureBorders,
|
||||
regionalDebug,
|
||||
naturalCompartmentId,
|
||||
naturalCompartments,
|
||||
} = admin;
|
||||
|
||||
let villages = inputVillages;
|
||||
|
|
@ -206,6 +251,8 @@ export function finishMapOutput({
|
|||
if (best) {
|
||||
center.representativeFeatureId = best.id;
|
||||
center.representativeFeatureName = best.name;
|
||||
center.canonicalSettlementId = best.id;
|
||||
center.canonicalSettlementName = best.name;
|
||||
center.municipalityRootName = best.name;
|
||||
} else {
|
||||
center.municipalityRootName = center.generatedMunicipalityName;
|
||||
|
|
@ -215,12 +262,12 @@ export function finishMapOutput({
|
|||
for (const [index, center] of adminCenters.entries()) {
|
||||
center.adminNumericId = index;
|
||||
center.municipalityId = index;
|
||||
let candidate = municipalityNameFromRoot(center.municipalityRootName || center.generatedMunicipalityName || center.name, center, nameFields, seed, index);
|
||||
let candidate = center.canonicalSettlementName || municipalityNameFromRoot(center.municipalityRootName || center.generatedMunicipalityName || center.name, center, nameFields, seed, index);
|
||||
const generated = municipalityNameFromRoot(center.generatedMunicipalityName || center.name, center, nameFields, seed + 177, index);
|
||||
if (usedAdminNames.has(candidate) && Array.from(generated).length >= 2 && !usedAdminNames.has(generated)) {
|
||||
if (!center.canonicalSettlementName && usedAdminNames.has(candidate) && Array.from(generated).length >= 2 && !usedAdminNames.has(generated)) {
|
||||
candidate = generated;
|
||||
}
|
||||
if (usedAdminNames.has(candidate)) {
|
||||
if (!center.canonicalSettlementName && usedAdminNames.has(candidate)) {
|
||||
const suffix = municipalitySuffixForCenter(center, nameFields, seed + 313, index);
|
||||
const base = String(center.generatedMunicipalityName || center.municipalityRootName || center.name || `自治${index + 1}`).replace(/[市町村区]$/u, "");
|
||||
candidate = `${base}${index + 1}${suffix}`;
|
||||
|
|
@ -231,6 +278,12 @@ export function finishMapOutput({
|
|||
usedAdminNames.add(center.name);
|
||||
}
|
||||
nameDebug.maxDerivedPerBase = 0;
|
||||
const prefectureRegions = buildPrefectureRegions(prefectureRegionId, sea, nameFields, seed, usedNames, nameDebug);
|
||||
const regionalPrefectureBorders = adminRegionalPrefectureBorders || [];
|
||||
if (regionalDebug) {
|
||||
regionalDebug.finalRegionalPrefectureBorderCount = regionalPrefectureBorders.length;
|
||||
regionalDebug.regionalPrefectureBordersRebuiltFromFinalId = true;
|
||||
}
|
||||
|
||||
outputProgress("final package");
|
||||
const entitiesForNames = [
|
||||
|
|
@ -260,6 +313,8 @@ export function finishMapOutput({
|
|||
humanRegionMask,
|
||||
prefectureBorder,
|
||||
prefectureRegionId,
|
||||
municipalityToPrefectureId,
|
||||
prefectureRegions,
|
||||
regionalDebug,
|
||||
terrainDebug,
|
||||
regionalPrefectureBorders,
|
||||
|
|
@ -289,6 +344,8 @@ export function finishMapOutput({
|
|||
alluvialFanField,
|
||||
deltaField,
|
||||
naturalBarrierScore,
|
||||
naturalCompartmentId,
|
||||
naturalCompartments,
|
||||
villages,
|
||||
ports,
|
||||
crossings,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue