Codechange: Optimize FlowsDown (#13262)

This commit is contained in:
SamuXarick 2025-01-10 16:18:54 +00:00 committed by GitHub
parent 4f33819fc2
commit d74255a3ec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1200,14 +1200,21 @@ static bool FlowsDown(TileIndex begin, TileIndex end)
{ {
assert(DistanceManhattan(begin, end) == 1); assert(DistanceManhattan(begin, end) == 1);
auto [slope_begin, height_begin] = GetTileSlopeZ(begin);
auto [slope_end, height_end] = GetTileSlopeZ(end); 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 either is inclined or flat; rivers don't support other slopes. */
(slope_end == SLOPE_FLAT || IsInclinedSlope(slope_end)) && if (slope_end != SLOPE_FLAT && !IsInclinedSlope(slope_end)) return false;
/* 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); 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. */ /** Parameters for river generation to pass as AyStar user data. */