Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #10218: Sloped river tiles need water both up and downstream #10235

Merged
merged 2 commits into from
Dec 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 33 additions & 3 deletions src/landscape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1176,9 +1176,39 @@ static bool RiverMakeWider(TileIndex tile, void *data)
Command<CMD_TERRAFORM_LAND>::Do(DC_EXEC | DC_AUTO, tile, to_change, true);
}
}
/* Update cur_slope after possibly terraforming. */
cur_slope = GetTileSlope(tile);
}

/* Sloped rivers need water both upstream and downstream. */
if (IsInclinedSlope(cur_slope)) {
DiagDirection slope_direction = GetInclinedSlopeDirection(cur_slope);

TileIndex upstream_tile = TileAddByDiagDir(tile, slope_direction);
TileIndex downstream_tile = TileAddByDiagDir(tile, ReverseDiagDir(slope_direction));

/* Don't look outside the map. */
if (!IsValidTile(upstream_tile) || !IsValidTile(downstream_tile)) return false;

/* Downstream might be new ocean created by our terraforming, and it hasn't flooded yet. */
bool downstream_is_ocean = GetTileZ(downstream_tile) == 0 && (GetTileSlope(downstream_tile) == SLOPE_FLAT || IsSlopeWithOneCornerRaised(GetTileSlope(downstream_tile)));

/* If downstream is dry, flat, and not ocean, try making it a river tile. */
if (!IsWaterTile(downstream_tile) && !downstream_is_ocean) {
/* If the tile upstream isn't flat, don't bother. */
if (GetTileSlope(downstream_tile) != SLOPE_FLAT) return false;

MakeRiver(downstream_tile, Random());
}

/* If upstream is dry and flat, try making it a river tile. */
if (!IsWaterTile(upstream_tile)) {
/* If the tile upstream isn't flat, don't bother. */
if (GetTileSlope(upstream_tile) != SLOPE_FLAT) return false;

MakeRiver(upstream_tile, Random());
}
}
/* Update cur_slope after possibly terraforming. */
cur_slope = GetTileSlope(tile);

/* If the tile slope matches the desired slope, add a river tile. */
if (cur_slope == desired_slope) {
Expand Down Expand Up @@ -1289,7 +1319,7 @@ static void River_FoundEndNode(AyStar *aystar, OpenListNode *current)
current_river_length = DistanceManhattan(data->spring, tile);
radius = std::min(3u, (current_river_length / (long_river_length / 3u)) + 1u);

if (radius > 1) CircularTileSearch(&tile, radius + RandomRange(1), RiverMakeWider, (void *)&path->node.tile);
if (radius > 1) CircularTileSearch(&tile, radius, RiverMakeWider, (void *)&path->node.tile);
}
}
}
Expand Down