mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-22 20:11:24 +01:00
Use distance instead of distance squared in calculating cost of ocean path
This commit is contained in:
parent
13b08ef5c0
commit
ef31552cf1
1 changed files with 2 additions and 2 deletions
|
|
@ -278,8 +278,8 @@ window.Routes = (function () {
|
|||
}
|
||||
if (cells.h[c] >= 20) continue; // ignore land cells
|
||||
if (temp[cells.g[c]] <= -5) continue; // ignore cells with term <= -5
|
||||
const dist2 = (cells.p[c][1] - cells.p[n][1]) ** 2 + (cells.p[c][0] - cells.p[n][0]) ** 2;
|
||||
const totalCost = p + (cells.road[c] ? 1 + dist2 / 2 : dist2 + (cells.t[c] ? 1 : 100));
|
||||
const dist = Math.sqrt((cells.p[c][1] - cells.p[n][1]) ** 2 + (cells.p[c][0] - cells.p[n][0]) ** 2);
|
||||
const totalCost = p + (cells.road[c] ? 1 + dist / 2 : dist + (cells.t[c] ? 1 : 100));
|
||||
|
||||
if (from[c] || totalCost >= cost[c]) continue;
|
||||
(from[c] = n), (cost[c] = totalCost);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue