From b21c8a3450239ea73319b775bc8a61e5ba19a3ea Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Tue, 8 Jul 2025 13:55:36 +0100 Subject: [PATCH] Codechange: Simplify test for bridges above bridge ramps. (#14421) --- src/tunnelbridge_cmd.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp index 458fa5b785..3a4e62ad1d 100644 --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -413,17 +413,13 @@ CommandCost CmdBuildBridge(DoCommandFlags flags, TileIndex tile_end, TileIndex t if (terraform_cost_south.Failed() || (terraform_cost_south.GetCost() != 0 && !allow_on_slopes)) return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION); cost.AddCost(terraform_cost_south.GetCost()); - const TileIndex heads[] = {tile_start, tile_end}; - for (int i = 0; i < 2; i++) { - if (IsBridgeAbove(heads[i])) { - TileIndex north_head = GetNorthernBridgeEnd(heads[i]); + /* Check for bridges above the bridge ramps. */ + for (TileIndex tile : {tile_start, tile_end}) { + if (!IsBridgeAbove(tile)) continue; - if (direction == GetBridgeAxis(heads[i])) return CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST); + if (direction == GetBridgeAxis(tile)) return CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST); - if (z_start + 1 == GetBridgeHeight(north_head)) { - return CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST); - } - } + if (z_start + 1 == GetBridgeHeight(GetNorthernBridgeEnd(tile))) return CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST); } TileIndexDiff delta = TileOffsByAxis(direction);