mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
v1.6.01 - properly track cells.r and check it on load
This commit is contained in:
parent
e4718a0844
commit
667006db86
3 changed files with 31 additions and 19 deletions
|
|
@ -160,31 +160,35 @@ const generate = function(changeHeights = true) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function defineRivers() {
|
function defineRivers() {
|
||||||
|
cells.r = new Uint16Array(cells.i.length); // re-initiate rivers array
|
||||||
pack.rivers = []; // rivers data
|
pack.rivers = []; // rivers data
|
||||||
const riverPaths = [];
|
const riverPaths = [];
|
||||||
|
|
||||||
for (let r = 1; r <= riverNext; r++) {
|
for (let r = 1; r <= riverNext; r++) {
|
||||||
const riverSegments = riversData.filter(d => d.river === r);
|
const riverSegments = riversData.filter(d => d.river === r);
|
||||||
|
if (riverSegments.length < 3) continue;
|
||||||
|
|
||||||
if (riverSegments.length > 2) {
|
for (const segment of riverSegments) {
|
||||||
const source = riverSegments[0].cell;
|
const i = segment.cell;
|
||||||
const mouth = riverSegments[riverSegments.length-2].cell;
|
if (cells.r[i]) continue;
|
||||||
|
if (cells.h[i] < 20) continue;
|
||||||
const widthFactor = rn(.8 + Math.random() * .4, 1); // river width modifier [.8, 1.2]
|
cells.r[i] = r;
|
||||||
const sourceWidth = cells.h[source] >= 20 ? .1 : rn(Math.min(Math.max((cells.fl[source] / 500) ** .4, .5), 1.7), 2);
|
|
||||||
|
|
||||||
const riverMeandered = addMeandering(riverSegments, sourceWidth * 10, .5);
|
|
||||||
const [path, length, offset] = getPath(riverMeandered, widthFactor, sourceWidth);
|
|
||||||
riverPaths.push([path, r]);
|
|
||||||
|
|
||||||
const parent = riverSegments[0].parent || 0;
|
|
||||||
const width = rn(offset ** 2, 2); // mounth width in km
|
|
||||||
const discharge = last(riverSegments).flux; // in m3/s
|
|
||||||
pack.rivers.push({i:r, source, mouth, discharge, length, width, widthFactor, sourceWidth, parent});
|
|
||||||
} else {
|
|
||||||
// remove too short rivers
|
|
||||||
riverSegments.filter(s => cells.r[s.cell] === r).forEach(s => cells.r[s.cell] = 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const source = riverSegments[0].cell;
|
||||||
|
const mouth = riverSegments[riverSegments.length-2].cell;
|
||||||
|
|
||||||
|
const widthFactor = rn(.8 + Math.random() * .4, 1); // river width modifier [.8, 1.2]
|
||||||
|
const sourceWidth = cells.h[source] >= 20 ? .1 : rn(Math.min(Math.max((cells.fl[source] / 500) ** .4, .5), 1.7), 2);
|
||||||
|
|
||||||
|
const riverMeandered = addMeandering(riverSegments, sourceWidth * 10, .5);
|
||||||
|
const [path, length, offset] = getPath(riverMeandered, widthFactor, sourceWidth);
|
||||||
|
riverPaths.push([path, r]);
|
||||||
|
|
||||||
|
const parent = riverSegments[0].parent || 0;
|
||||||
|
const width = rn(offset ** 2, 2); // mounth width in km
|
||||||
|
const discharge = last(riverSegments).flux; // in m3/s
|
||||||
|
pack.rivers.push({i:r, source, mouth, discharge, length, width, widthFactor, sourceWidth, parent});
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw rivers
|
// draw rivers
|
||||||
|
|
|
||||||
|
|
@ -1178,6 +1178,14 @@ function parseLoadedData(data) {
|
||||||
ERROR && console.error("Data Integrity Check. Invalid burg", b, "is assigned to cells", invalidCells);
|
ERROR && console.error("Data Integrity Check. Invalid burg", b, "is assigned to cells", invalidCells);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const invalidRivers = [...new Set(cells.r)].filter(r => r && !pack.rivers.find(river => river.i === r));
|
||||||
|
invalidRivers.forEach(r => {
|
||||||
|
const invalidCells = cells.i.filter(i => cells.r[i] === r);
|
||||||
|
invalidCells.forEach(i => cells.r[i] = 0);
|
||||||
|
rivers.select("river"+r).remove();
|
||||||
|
ERROR && console.error("Data Integrity Check. Invalid river", r, "is assigned to cells", invalidCells);
|
||||||
|
});
|
||||||
|
|
||||||
pack.burgs.forEach(b => {
|
pack.burgs.forEach(b => {
|
||||||
if (!b.i || b.removed) return;
|
if (!b.i || b.removed) return;
|
||||||
if (b.port < 0) {ERROR && console.error("Data Integrity Check. Burg", b.i, "has invalid port value", b.port); b.port = 0;}
|
if (b.port < 0) {ERROR && console.error("Data Integrity Check. Burg", b.i, "has invalid port value", b.port); b.port = 0;}
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ function overviewRivers() {
|
||||||
const discharge = r.discharge + " m³/s";
|
const discharge = r.discharge + " m³/s";
|
||||||
const length = rn(r.length * distanceScaleInput.value) + " " + unit;
|
const length = rn(r.length * distanceScaleInput.value) + " " + unit;
|
||||||
const width = rn(r.width * distanceScaleInput.value, 3) + " " + unit;
|
const width = rn(r.width * distanceScaleInput.value, 3) + " " + unit;
|
||||||
const basin = pack.rivers.find(river => river.i === r.basin).name;
|
const basin = pack.rivers.find(river => river.i === r.basin)?.name;
|
||||||
|
|
||||||
lines += `<div class="states" data-id=${r.i} data-name="${r.name}" data-type="${r.type}" data-discharge="${r.discharge}" data-length="${r.length}" data-width="${r.width}" data-basin="${basin}">
|
lines += `<div class="states" data-id=${r.i} data-name="${r.name}" data-type="${r.type}" data-discharge="${r.discharge}" data-length="${r.length}" data-width="${r.width}" data-basin="${basin}">
|
||||||
<span data-tip="Click to focus on river" class="icon-dot-circled pointer"></span>
|
<span data-tip="Click to focus on river" class="icon-dot-circled pointer"></span>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue