From e2a6b16c6c178bce071ad76ab29b85633ea80693 Mon Sep 17 00:00:00 2001 From: GoteGuru Date: Wed, 6 Apr 2022 23:06:47 +0000 Subject: [PATCH] Fix port cell search algo --- modules/submap.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/submap.js b/modules/submap.js index 4d81d38e..a393045b 100644 --- a/modules/submap.js +++ b/modules/submap.js @@ -318,13 +318,13 @@ window.Submap = (function () { * returns [cellid, neighbor] tuple or undefined if no such cell. */ const findNearest = (f, g, max=3) => centerId => { - const met = new Set([centerId]); // cache, f might be expensive + const met = new Set(); // cache, f might be expensive const kernel = (c, dist) => { const ncs = pack.cells.c[c].filter(nc => !met.has(nc)); const n = ncs.find(g); if (f(c) && n) return [c, n]; if (dist >= max || !ncs.length) return undefined; - ncs.forEach(i => met.add(i)); + met.add(c); const targets = ncs.filter(f) let answer; while (targets.length && !answer) answer = kernel(targets.shift(), dist+1); @@ -360,6 +360,7 @@ window.Submap = (function () { 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.cell = null; b.removed = true; return; } @@ -391,5 +392,5 @@ window.Submap = (function () { } // export - return { resample } + return { resample, findNearest } })();