mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 17:51:24 +01:00
check lakes before depressiong fill
This commit is contained in:
parent
e7cf6e4f5a
commit
234814ee56
3 changed files with 39 additions and 3 deletions
3
main.js
3
main.js
|
|
@ -795,11 +795,11 @@ function addLakesInDeepDepressions() {
|
||||||
|
|
||||||
for (const n of c[q]) {
|
for (const n of c[q]) {
|
||||||
if (checked[n]) continue;
|
if (checked[n]) continue;
|
||||||
|
if (h[n] >= treshold) continue;
|
||||||
if (h[n] < 20) {
|
if (h[n] < 20) {
|
||||||
deep = false;
|
deep = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (h[n] >= treshold) continue;
|
|
||||||
|
|
||||||
checked[n] = true;
|
checked[n] = true;
|
||||||
queue.push(n);
|
queue.push(n);
|
||||||
|
|
@ -808,7 +808,6 @@ function addLakesInDeepDepressions() {
|
||||||
|
|
||||||
// if not, add a lake
|
// if not, add a lake
|
||||||
if (deep) {
|
if (deep) {
|
||||||
debug.append("circle").attr("cx", points[i][0]).attr("cy", points[i][1]).attr("r", 1).attr("fill", "red");
|
|
||||||
const lakeCells = [i].concat(c[i].filter(n => h[n] === h[i]));
|
const lakeCells = [i].concat(c[i].filter(n => h[n] === h[i]));
|
||||||
addLake(lakeCells);
|
addLake(lakeCells);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@
|
||||||
delete feature.shoreline;
|
delete feature.shoreline;
|
||||||
delete feature.outCell;
|
delete feature.outCell;
|
||||||
delete feature.closed;
|
delete feature.closed;
|
||||||
feature.height = rn(feature.height);
|
feature.height = rn(feature.height, 3);
|
||||||
|
|
||||||
const inlets = feature.inlets?.filter(r => pack.rivers.find(river => river.i === r));
|
const inlets = feature.inlets?.filter(r => pack.rivers.find(river => river.i === r));
|
||||||
if (!inlets || !inlets.length) delete feature.inlets;
|
if (!inlets || !inlets.length) delete feature.inlets;
|
||||||
|
|
|
||||||
|
|
@ -27,13 +27,50 @@
|
||||||
TIME && console.timeEnd("generateRivers");
|
TIME && console.timeEnd("generateRivers");
|
||||||
|
|
||||||
function prepareLakeData() {
|
function prepareLakeData() {
|
||||||
|
const ELEVATION_LIMIT = 10;
|
||||||
|
|
||||||
features.forEach(f => {
|
features.forEach(f => {
|
||||||
if (f.type !== "lake") return;
|
if (f.type !== "lake") return;
|
||||||
delete f.flux;
|
delete f.flux;
|
||||||
delete f.inlets;
|
delete f.inlets;
|
||||||
delete f.outlet;
|
delete f.outlet;
|
||||||
delete f.height;
|
delete f.height;
|
||||||
|
delete f.closed;
|
||||||
!f.shoreline && Lakes.getShoreline(f);
|
!f.shoreline && Lakes.getShoreline(f);
|
||||||
|
|
||||||
|
// lake surface height is as lowest land cells around
|
||||||
|
const min = f.shoreline.sort((a, b) => h[a] - h[b])[0];
|
||||||
|
f.height = h[min] - 0.1;
|
||||||
|
|
||||||
|
// check if lake can be open (not in deep depression)
|
||||||
|
let deep = true;
|
||||||
|
const treshold = f.height + ELEVATION_LIMIT;
|
||||||
|
const queue = [min];
|
||||||
|
const checked = [];
|
||||||
|
checked[min] = true;
|
||||||
|
|
||||||
|
// check if elevated lake can potentially pour to another water body
|
||||||
|
while (deep && queue.length) {
|
||||||
|
const q = queue.pop();
|
||||||
|
|
||||||
|
for (const n of cells.c[q]) {
|
||||||
|
if (checked[n]) continue;
|
||||||
|
if (h[n] >= treshold) continue;
|
||||||
|
|
||||||
|
if (h[n] < 20) {
|
||||||
|
const nFeature = features[cells.f[n]];
|
||||||
|
if (nFeature.type === "ocean" || f.height > nFeature.height) {
|
||||||
|
deep = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
checked[n] = true;
|
||||||
|
queue.push(n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
f.closed = deep;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue