diff --git a/main.js b/main.js index a15f6c33..3add6200 100644 --- a/main.js +++ b/main.js @@ -530,7 +530,6 @@ function generate() { reGraph(); drawCoastline(); - elevateLakes(); Rivers.generate(); defineBiomes(); diff --git a/modules/river-generator.js b/modules/river-generator.js index f88db0e9..c5ed2d52 100644 --- a/modules/river-generator.js +++ b/modules/river-generator.js @@ -91,17 +91,19 @@ const x = p[i][0], y = p[i][1]; // lake outlets draw from lake - let n = -1, out2 = 0; - while (outlets.includes(i, n+1)) { - n = outlets.indexOf(i, n+1); + let out2; + for (let n = outlets.indexOf(i); n !== -1; n = outlets.indexOf(i, n+1)) { // in case multiple lakes share outlet const l = features[n]; if ( ! l ) {continue;} const j = cells.haven[i]; - if(cells.r[j] === l.river) { - } else { + // allow chain lakes to retain identity + if(cells.r[j] !== l.river) { let touch = false; for (const c of cells.c[j]){ - if (cells.r[c] === l.river) touch = true; + if (cells.r[c] === l.river) { + touch = true; + break; + } } if (touch) { cells.r[j] = l.river; @@ -114,7 +116,7 @@ } flowDown(i, cells.fl[i], l.totalFlux, cells.r[j]); // prevent dropping imediately back into the lake - out2 = cells.c[i].filter(c => h[c] >= 20).sort((a,b) => h[a] - h[b])[0]; // downhill land cell + out2 = cells.c[i].filter(c => cells.f[c] !== cells.f[j]).sort((a,b) => h[a] - h[b])[0]; // downhill cell not in the source lake } // near-border cell: pour out of the screen @@ -203,10 +205,6 @@ } }) } - lakes.forEach(copy => { - pack.features[copy.i].height = copy.height; - pack.features[copy.i].shoreline = copy.shoreline; - }); // write to real data land.sort((a,b) => h[b] - h[a]); // highest cells go first let depressed = false; @@ -221,11 +219,9 @@ depressed = true; } } - // write changed - depression && lakes.forEach(copy => pack.features[copy.i].height = copy.height); for (const i of land) { const minHeight = d3.min(cells.c[i].map(c => cells.t[c] > 0 ? h[c] : - pack.features[cells.f[c]].height || h[c] // NB undefined is falsy + pack.features[cells.f[c]].height || h[c] // NB undefined is falsy (a || b is short for a ? a : b) )); if (minHeight === 100) continue; // already max height if (h[i] <= minHeight) { diff --git a/modules/ui/heightmap-editor.js b/modules/ui/heightmap-editor.js index c64265f2..b2f7712a 100644 --- a/modules/ui/heightmap-editor.js +++ b/modules/ui/heightmap-editor.js @@ -288,7 +288,6 @@ function editHeightmap() { drawCoastline(); if (changeHeights.checked) { - // elevateLakes(); Rivers.generate(changeHeights.checked); } @@ -313,7 +312,6 @@ function editHeightmap() { for (const i of pack.cells.i) { const g = pack.cells.g[i]; - // if (pack.features[pack.cells.f[i]].group === "freshwater") pack.cells.h[i] = 19; // de-elevate lakes const land = pack.cells.h[i] >= 20; // check biome