mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Merge some duplicated functions
parent
ca5f73b196
commit
1778b2d66e
|
@ -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)
|
||||
{
|
||||
assert(bridge_piece == BRIDGE_PIECE_NORTH || bridge_piece == BRIDGE_PIECE_SOUTH);
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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? */
|
||||
|
|
Loading…
Reference in New Issue