From d74255a3ec0091832d960abc5d579b2b0d7959d4 Mon Sep 17 00:00:00 2001 From: SamuXarick <43006711+SamuXarick@users.noreply.github.com> Date: Fri, 10 Jan 2025 16:18:54 +0000 Subject: [PATCH] Codechange: Optimize FlowsDown (#13262) --- src/landscape.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/landscape.cpp b/src/landscape.cpp index 544a41876b..9f92912c91 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -1200,14 +1200,21 @@ static bool FlowsDown(TileIndex begin, TileIndex end) { assert(DistanceManhattan(begin, end) == 1); - auto [slope_begin, height_begin] = GetTileSlopeZ(begin); auto [slope_end, height_end] = GetTileSlopeZ(end); - return height_end <= height_begin && - /* Slope either is inclined or flat; rivers don't support other slopes. */ - (slope_end == SLOPE_FLAT || IsInclinedSlope(slope_end)) && - /* Slope continues, then it must be lower... or either end must be flat. */ - ((slope_end == slope_begin && height_end < height_begin) || slope_end == SLOPE_FLAT || slope_begin == SLOPE_FLAT); + /* Slope either is inclined or flat; rivers don't support other slopes. */ + if (slope_end != SLOPE_FLAT && !IsInclinedSlope(slope_end)) return false; + + auto [slope_begin, height_begin] = GetTileSlopeZ(begin); + + /* It can't flow uphill. */ + if (height_end > height_begin) return false; + + /* Slope continues, then it must be lower... */ + if (slope_end == slope_begin && height_end < height_begin) return true; + + /* ... or either end must be flat. */ + return slope_end == SLOPE_FLAT || slope_begin == SLOPE_FLAT; } /** Parameters for river generation to pass as AyStar user data. */