mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 01:41:22 +01:00
river type - memoize what is small size for river
This commit is contained in:
parent
50f497c62a
commit
4902a321ea
2 changed files with 15 additions and 11 deletions
|
|
@ -388,14 +388,11 @@
|
||||||
const specify = function () {
|
const specify = function () {
|
||||||
const rivers = pack.rivers;
|
const rivers = pack.rivers;
|
||||||
if (!rivers.length) return;
|
if (!rivers.length) return;
|
||||||
Math.random = aleaPRNG(seed);
|
|
||||||
const thresholdElement = Math.ceil(rivers.length * 0.15);
|
|
||||||
const smallLength = rivers.map(r => r.length || 0).sort((a, b) => a - b)[thresholdElement];
|
|
||||||
|
|
||||||
for (const r of rivers) {
|
for (const river of rivers) {
|
||||||
r.basin = getBasin(r.i);
|
river.basin = getBasin(river.i);
|
||||||
r.name = getName(r.mouth);
|
river.name = getName(river.mouth);
|
||||||
r.type = getType(r, r.length < smallLength);
|
river.type = getType(river);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -414,8 +411,16 @@
|
||||||
small: {Branch: 1}
|
small: {Branch: 1}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const getType = function (river, isSmall) {
|
|
||||||
const isFork = each(3)(river.i) && river.parent && river.parent !== river.i;
|
let smallLength = null;
|
||||||
|
const getType = function ({i, length, parent}) {
|
||||||
|
if (smallLength === null) {
|
||||||
|
const threshold = Math.ceil(pack.rivers.length * 0.15);
|
||||||
|
smallLength = pack.rivers.map(r => r.length || 0).sort((a, b) => a - b)[threshold];
|
||||||
|
}
|
||||||
|
|
||||||
|
const isSmall = length < smallLength;
|
||||||
|
const isFork = each(3)(i) && parent && parent !== i;
|
||||||
return rw(riverTypes[isFork ? "fork" : "main"][isSmall ? "small" : "big"]);
|
return rw(riverTypes[isFork ? "fork" : "main"][isSmall ? "small" : "big"]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -639,8 +639,7 @@ function addRiverOnClick() {
|
||||||
} else {
|
} else {
|
||||||
const basin = Rivers.getBasin(parent);
|
const basin = Rivers.getBasin(parent);
|
||||||
const name = Rivers.getName(mouth);
|
const name = Rivers.getName(mouth);
|
||||||
const smallLength = rivers.map(r => r.length || 0).sort((a, b) => a - b)[Math.ceil(pack.rivers.length * 0.15)];
|
const type = Rivers.getType({i: riverId, length, parent});
|
||||||
const type = length < smallLength ? rw({Creek: 9, River: 3, Brook: 3, Stream: 1}) : "River";
|
|
||||||
|
|
||||||
rivers.push({i: riverId, source, mouth, discharge, length, width, widthFactor, sourceWidth, parent, cells: riverCells, basin, name, type});
|
rivers.push({i: riverId, source, mouth, discharge, length, width, widthFactor, sourceWidth, parent, cells: riverCells, basin, name, type});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue