mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-19 10:31:24 +01:00
refactor: submap - relocate burgs
This commit is contained in:
parent
304311d135
commit
3dfe1b3b27
2 changed files with 18 additions and 10 deletions
|
|
@ -878,6 +878,7 @@ window.BurgsAndStates = (() => {
|
||||||
generateDiplomacy,
|
generateDiplomacy,
|
||||||
defineStateForms,
|
defineStateForms,
|
||||||
getFullName,
|
getFullName,
|
||||||
updateCultures
|
updateCultures,
|
||||||
|
getCloseToEdgePoint
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
|
|
@ -133,28 +133,35 @@ window.Submap = (function () {
|
||||||
|
|
||||||
function restoreBurgs(parentMap, projection, options) {
|
function restoreBurgs(parentMap, projection, options) {
|
||||||
const packLandCellsQuadtree = d3.quadtree(groupCellsByType(pack).land);
|
const packLandCellsQuadtree = d3.quadtree(groupCellsByType(pack).land);
|
||||||
|
const findLandCell = (x, y) => packLandCellsQuadtree.find(x, y, Infinity)?.[2];
|
||||||
|
|
||||||
pack.burgs = parentMap.pack.burgs.map(burg => {
|
pack.burgs = parentMap.pack.burgs.map(burg => {
|
||||||
if (!burg.i || burg.removed) return burg;
|
if (!burg.i || burg.removed) return burg;
|
||||||
burg.population *= options.scale; // adjust for populationRate change
|
burg.population *= options.scale; // adjust for populationRate change
|
||||||
|
|
||||||
const [xp, yp] = projection(burg.x, burg.y);
|
const [xp, yp] = projection(burg.x, burg.y);
|
||||||
const [x, y] = [rn(xp, 2), rn(yp, 2)];
|
if (!isInMap(xp, yp)) return {...burg, removed: true, lock: false};
|
||||||
if (!isInMap(x, y)) return {...burg, removed: true, lock: false};
|
|
||||||
|
const closestCell = findCell(xp, yp);
|
||||||
|
const cell = isWater(pack, closestCell) ? findLandCell(xp, yp) : closestCell;
|
||||||
|
|
||||||
const cell = packLandCellsQuadtree.find(x, y, Infinity)?.[2];
|
|
||||||
if (!cell) {
|
|
||||||
ERROR && console.error(`Could not find cell for burg ${burg.name} (${burg.i}). Had to remove it`);
|
|
||||||
return {...burg, removed: true, lock: false};
|
|
||||||
}
|
|
||||||
if (pack.cells.burg[cell]) {
|
if (pack.cells.burg[cell]) {
|
||||||
WARN && console.warn(`Cell ${cell} already has a burg. Had to remove burg ${burg.name} (${burg.i})`);
|
WARN && console.warn(`Cell ${cell} already has a burg. Removing burg ${burg.name} (${burg.i})`);
|
||||||
return {...burg, removed: true, lock: false};
|
return {...burg, removed: true, lock: false};
|
||||||
}
|
}
|
||||||
|
|
||||||
pack.cells.burg[cell] = burg.i;
|
pack.cells.burg[cell] = burg.i;
|
||||||
return {...burg, x, y, cell};
|
const [x, y] = getBurgCoordinates(burg, closestCell, cell, xp, yp);
|
||||||
|
return {...burg, cell, x, y};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function getBurgCoordinates(burg, closestCell, cell, xp, yp) {
|
||||||
|
const haven = pack.cells.haven[cell];
|
||||||
|
if (burg.port && haven) return BurgsAndStates.getCloseToEdgePoint(cell, haven);
|
||||||
|
|
||||||
|
if (closestCell !== cell) return pack.cells.p[cell];
|
||||||
|
return [rn(xp, 2), rn(yp, 2)];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function restoreStates(parentMap, projection) {
|
function restoreStates(parentMap, projection) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue