Changeset - r23028:0602ed02c6b4
[Not reviewed]
master
0 1 0
Charles Pigott - 6 years ago 2018-10-17 19:52:16
charlespigott@googlemail.com
Codechange: Merge some duplicated functions
1 file changed with 17 insertions and 30 deletions:
0 comments (0 inline, 0 general)
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -159,40 +159,27 @@ static inline const PalSpriteID *GetBrid
 

	
 

	
 
/**
 
 * 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
 
	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_TunnelB
 

	
 
		/* 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? */
0 comments (0 inline, 0 general)