From 1a61c85d934831a3e0080119d1111343b9f3709d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9sz=C3=A1ros=20Gergely?= Date: Fri, 17 Sep 2021 01:24:20 +0200 Subject: [PATCH] FIX: coast detection (for burgs) --- modules/submap.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/submap.js b/modules/submap.js index d2c74f08..1a3f9eb8 100644 --- a/modules/submap.js +++ b/modules/submap.js @@ -324,8 +324,8 @@ window.Submap = (function () { const inMap = (x,y) => x>0 && x0 && y cells.t[c] === -1 - const isNearCoast = c => cells.t[c] === 1 + const isCoast = c => cells.t[c] === 1 + const isNearCoast = c => cells.t[c] === -1 pack.burgs = parentMap.pack.burgs; // remap burgs to the best new cell @@ -342,10 +342,10 @@ window.Submap = (function () { let cityCell = findCell(b.x, b.y); + const searchCoastCell = findNearest(isCoast, isNearCoast, 6); // pull sunken burgs out of water if (isWater(childMap, cityCell)) { - const searchPlace = findNearest(isCoast, isNearCoast); - const res = searchPlace(cityCell) + const res = searchCoastCell(cityCell) if (!res) { WARN && console.warn(`Burg ${b.name} sank like Atlantis. Unable to find coastal cells nearby. Try to reduce resample zoom level.`); b.removed = true; @@ -357,15 +357,16 @@ window.Submap = (function () { b.cell = coast; } if (b.port) { // find coast for ports on land - const searchPortCell = findNearest(isCoast, isNearCoast); - const res = searchPortCell(cityCell); + const res = searchCoastCell(cityCell); if (res) { const [coast, water] = res; [b.x, b.y] = getMiddlePoint(coast, water); b.port = cells.f[water]; // copy feature number b.cell = coast; } 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; } } else {