summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Pigott <charlespigott@googlemail.com>2018-10-17 20:52:16 +0100
committerfrosch <github@elsenhans.name>2018-10-31 12:41:49 +0100
commit1778b2d66ec21e544e56e5aaaee816cf8fc955af (patch)
treed5114befa8147105935c8edea8711ad8068e1523
parentca5f73b196fc81185c2d08ad69fe9cd478fc0669 (diff)
downloadopenttd-1778b2d66ec21e544e56e5aaaee816cf8fc955af.tar.xz
Codechange: Merge some duplicated functions
-rw-r--r--src/tunnelbridge_cmd.cpp45
1 files changed, 16 insertions, 29 deletions
diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp
index 27b3ea347..297a01d30 100644
--- a/src/tunnelbridge_cmd.cpp
+++ b/src/tunnelbridge_cmd.cpp
@@ -159,40 +159,27 @@ static inline const PalSpriteID *GetBridgeSpriteTable(int index, BridgePieces ta
/**
- * Determines the foundation for the north bridge head, and tests if the resulting slope is valid.
+ * Determines the foundation for the bridge head, and tests if the resulting slope is valid.
*
+ * @param bridge_piece Direction of the bridge head.
* @param axis Axis of the bridge
* @param tileh Slope of the tile under the north bridge head; returns slope on top of foundation
* @param z TileZ corresponding to tileh, gets modified as well
* @return Error or cost for bridge foundation
*/
-static CommandCost CheckBridgeSlopeNorth(Axis axis, Slope *tileh, int *z)
+static CommandCost CheckBridgeSlope(BridgePieces bridge_piece, Axis axis, Slope *tileh, int *z)
{
- Foundation f = GetBridgeFoundation(*tileh, axis);
- *z += ApplyFoundationToSlope(f, tileh);
-
- Slope valid_inclined = (axis == AXIS_X ? SLOPE_NE : SLOPE_NW);
- if ((*tileh != SLOPE_FLAT) && (*tileh != valid_inclined)) return CMD_ERROR;
-
- if (f == FOUNDATION_NONE) return CommandCost();
-
- return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
-}
+ assert(bridge_piece == BRIDGE_PIECE_NORTH || bridge_piece == BRIDGE_PIECE_SOUTH);
-/**
- * Determines the foundation for the south bridge head, and tests if the resulting slope is valid.
- *
- * @param axis Axis of the bridge
- * @param tileh Slope of the tile under the south bridge head; returns slope on top of foundation
- * @param z TileZ corresponding to tileh, gets modified as well
- * @return Error or cost for bridge foundation
- */
-static CommandCost CheckBridgeSlopeSouth(Axis axis, Slope *tileh, int *z)
-{
Foundation f = GetBridgeFoundation(*tileh, axis);
*z += ApplyFoundationToSlope(f, tileh);
- Slope valid_inclined = (axis == AXIS_X ? SLOPE_SW : SLOPE_SE);
+ Slope valid_inclined;
+ if (bridge_piece == BRIDGE_PIECE_NORTH) {
+ valid_inclined = (axis == AXIS_X ? SLOPE_NE : SLOPE_NW);
+ } else {
+ valid_inclined = (axis == AXIS_X ? SLOPE_SW : SLOPE_SE);
+ }
if ((*tileh != SLOPE_FLAT) && (*tileh != valid_inclined)) return CMD_ERROR;
if (f == FOUNDATION_NONE) return CommandCost();
@@ -316,8 +303,8 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
Slope tileh_end = GetTileSlope(tile_end, &z_end);
bool pbs_reservation = false;
- CommandCost terraform_cost_north = CheckBridgeSlopeNorth(direction, &tileh_start, &z_start);
- CommandCost terraform_cost_south = CheckBridgeSlopeSouth(direction, &tileh_end, &z_end);
+ CommandCost terraform_cost_north = CheckBridgeSlope(BRIDGE_PIECE_NORTH, direction, &tileh_start, &z_start);
+ CommandCost terraform_cost_south = CheckBridgeSlope(BRIDGE_PIECE_SOUTH, direction, &tileh_end, &z_end);
/* Aqueducts can't be built of flat land. */
if (transport_type == TRANSPORT_WATER && (tileh_start == SLOPE_FLAT || tileh_end == SLOPE_FLAT)) return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
@@ -1900,11 +1887,11 @@ static CommandCost TerraformTile_TunnelBridge(TileIndex tile, DoCommandFlag flag
/* Check if new slope is valid for bridges in general (so we can safely call GetBridgeFoundation()) */
if ((direction == DIAGDIR_NW) || (direction == DIAGDIR_NE)) {
- CheckBridgeSlopeSouth(axis, &tileh_old, &z_old);
- res = CheckBridgeSlopeSouth(axis, &tileh_new, &z_new);
+ CheckBridgeSlope(BRIDGE_PIECE_SOUTH, axis, &tileh_old, &z_old);
+ res = CheckBridgeSlope(BRIDGE_PIECE_SOUTH, axis, &tileh_new, &z_new);
} else {
- CheckBridgeSlopeNorth(axis, &tileh_old, &z_old);
- res = CheckBridgeSlopeNorth(axis, &tileh_new, &z_new);
+ CheckBridgeSlope(BRIDGE_PIECE_NORTH, axis, &tileh_old, &z_old);
+ res = CheckBridgeSlope(BRIDGE_PIECE_NORTH, axis, &tileh_new, &z_new);
}
/* Surface slope is valid and remains unchanged? */