From 208399ffc1516b2f10bc428b7137a6cc00d417a5 Mon Sep 17 00:00:00 2001 From: IR0NSIGHT Date: Thu, 18 Jan 2024 12:25:15 +0100 Subject: [PATCH] fix: rivers ending nowhere, holes in rivers sort starting points by height: highest riverstarts go first --- src/index.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 395b57c..d17651f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,6 +11,7 @@ import { River, } from "./pathing/river"; import { applyRiverLayers } from "./pathing/postprocessing"; +import {getZ} from "./terrain"; const TILE_SIZE_BITS = 7; const SHIFT_AMOUNT = 1 << TILE_SIZE_BITS; // Equivalent to 128 @@ -82,9 +83,13 @@ const main = () => { const dims = mapDimensions(); log("map dimension: " + JSON.stringify(dims)); - const startPoints: point[] = allAnnotatedPoints(getAllTiles()) + const sortHighestFirst = (ps: point[]): point[] => { + ps.sort((a,b) => getZ(b) - getZ(a)); + return ps; + } + const startPoints: point[] = sortHighestFirst(allAnnotatedPoints(getAllTiles())) - const passRandom = (p: point, chance: number): boolean => { + const passRandom = (p: point, chance: number): boolean => { const seed = p.x * p.y + p.x; //@ts-expect-error: provided by worldpainter context return new java.util.Random(seed).nextFloat() < chance;