mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-23 12:31:24 +01:00
FIX: coast detection (for burgs)
This commit is contained in:
parent
d32edefac8
commit
1a61c85d93
1 changed files with 8 additions and 7 deletions
|
|
@ -324,8 +324,8 @@ window.Submap = (function () {
|
||||||
const inMap = (x,y) => x>0 && x<graphWidth && y>0 && y<graphHeight;
|
const inMap = (x,y) => x>0 && x<graphWidth && y>0 && y<graphHeight;
|
||||||
const cells = pack.cells;
|
const cells = pack.cells;
|
||||||
const childMap = { grid, pack }
|
const childMap = { grid, pack }
|
||||||
const isCoast = c => cells.t[c] === -1
|
const isCoast = c => cells.t[c] === 1
|
||||||
const isNearCoast = c => cells.t[c] === 1
|
const isNearCoast = c => cells.t[c] === -1
|
||||||
pack.burgs = parentMap.pack.burgs;
|
pack.burgs = parentMap.pack.burgs;
|
||||||
|
|
||||||
// remap burgs to the best new cell
|
// remap burgs to the best new cell
|
||||||
|
|
@ -342,10 +342,10 @@ window.Submap = (function () {
|
||||||
|
|
||||||
let cityCell = findCell(b.x, b.y);
|
let cityCell = findCell(b.x, b.y);
|
||||||
|
|
||||||
|
const searchCoastCell = findNearest(isCoast, isNearCoast, 6);
|
||||||
// pull sunken burgs out of water
|
// pull sunken burgs out of water
|
||||||
if (isWater(childMap, cityCell)) {
|
if (isWater(childMap, cityCell)) {
|
||||||
const searchPlace = findNearest(isCoast, isNearCoast);
|
const res = searchCoastCell(cityCell)
|
||||||
const res = searchPlace(cityCell)
|
|
||||||
if (!res) {
|
if (!res) {
|
||||||
WARN && console.warn(`Burg ${b.name} sank like Atlantis. Unable to find coastal cells nearby. Try to reduce resample zoom level.`);
|
WARN && console.warn(`Burg ${b.name} sank like Atlantis. Unable to find coastal cells nearby. Try to reduce resample zoom level.`);
|
||||||
b.removed = true;
|
b.removed = true;
|
||||||
|
|
@ -357,15 +357,16 @@ window.Submap = (function () {
|
||||||
b.cell = coast;
|
b.cell = coast;
|
||||||
} if (b.port) {
|
} if (b.port) {
|
||||||
// find coast for ports on land
|
// find coast for ports on land
|
||||||
const searchPortCell = findNearest(isCoast, isNearCoast);
|
const res = searchCoastCell(cityCell);
|
||||||
const res = searchPortCell(cityCell);
|
|
||||||
if (res) {
|
if (res) {
|
||||||
const [coast, water] = res;
|
const [coast, water] = res;
|
||||||
[b.x, b.y] = getMiddlePoint(coast, water);
|
[b.x, b.y] = getMiddlePoint(coast, water);
|
||||||
b.port = cells.f[water]; // copy feature number
|
b.port = cells.f[water]; // copy feature number
|
||||||
b.cell = coast;
|
b.cell = coast;
|
||||||
} else {
|
} else {
|
||||||
WARN && console.warn(`Can't find water near port ${b.name}. :-/`);
|
WARN && console.warn(`Can't find water near port ${b.name}. Increase search radius in searchCoastCell. (Removing port status)`);
|
||||||
|
b.cell = cityCell;
|
||||||
|
[b.x, b.y] = cells.p[cityCell];
|
||||||
b.port = 0;
|
b.port = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue