Changeset - r16725:b9041c857d37
[Not reviewed]
master
0 1 0
rubidium - 14 years ago 2010-12-11 18:28:34
rubidium@openttd.org
(svn r21468) -Change: make sure the end of a bridge is always a valid tile as well, and for aqueducts show "wrong land slope" when that would be more appropriate than "bridge heads not at same height"
1 file changed with 3 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -202,25 +202,25 @@ CommandCost CheckBridgeAvailability(Brid
 
 * - p2 = (bit 15-16) - transport type.
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	RailType railtype = INVALID_RAILTYPE;
 
	RoadTypes roadtypes = ROADTYPES_NONE;
 

	
 
	/* unpack parameters */
 
	BridgeType bridge_type = GB(p2, 0, 8);
 

	
 
	if (p1 >= MapSize()) return CMD_ERROR;
 
	if (!IsValidTile(p1)) return CMD_ERROR;
 

	
 
	TransportType transport_type = Extract<TransportType, 15, 2>(p2);
 

	
 
	/* type of bridge */
 
	switch (transport_type) {
 
		case TRANSPORT_ROAD:
 
			roadtypes = Extract<RoadTypes, 8, 2>(p2);
 
			if (!HasExactlyOneBit(roadtypes) || !HasRoadTypesAvail(_current_company, roadtypes)) return CMD_ERROR;
 
			break;
 

	
 
		case TRANSPORT_RAIL:
 
			railtype = Extract<RailType, 8, 4>(p2);
 
@@ -261,24 +261,26 @@ CommandCost CmdBuildBridge(TileIndex end
 
		if (bridge_len > (_settings_game.construction.longbridges ? MAX_BRIDGE_LENGTH_LONGBRIDGES : MAX_BRIDGE_LENGTH)) return_cmd_error(STR_ERROR_BRIDGE_TOO_LONG);
 
	}
 

	
 
	uint z_start;
 
	uint z_end;
 
	Slope tileh_start = GetTileSlope(tile_start, &z_start);
 
	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);
 

	
 
	/* 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);
 
	if (z_start != z_end) return_cmd_error(STR_ERROR_BRIDGEHEADS_NOT_SAME_HEIGHT);
 

	
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	Owner owner;
 
	if (IsBridgeTile(tile_start) && IsBridgeTile(tile_end) &&
 
			GetOtherBridgeEnd(tile_start) == tile_end &&
 
			GetTunnelBridgeTransportType(tile_start) == transport_type) {
 
		/* Replace a current bridge. */
 

	
 
		/* If this is a railway bridge, make sure the railtypes match. */
 
		if (transport_type == TRANSPORT_RAIL && GetRailType(tile_start) != railtype) {
 
			return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
 
@@ -336,26 +338,24 @@ CommandCost CmdBuildBridge(TileIndex end
 
		if (terraform_cost_north.Failed() || (terraform_cost_north.GetCost() != 0 && !allow_on_slopes)) return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
 
		cost.AddCost(terraform_cost_north);
 

	
 
		/* Try and clear the end landscape */
 
		ret = DoCommand(tile_end, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
		if (ret.Failed()) return ret;
 
		cost.AddCost(ret);
 

	
 
		/* false - end tile slope check */
 
		if (terraform_cost_south.Failed() || (terraform_cost_south.GetCost() != 0 && !allow_on_slopes)) return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
 
		cost.AddCost(terraform_cost_south);
 

	
 
		if (transport_type == TRANSPORT_WATER && (tileh_start == SLOPE_FLAT || tileh_end == SLOPE_FLAT)) return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
 

	
 
		const TileIndex heads[] = {tile_start, tile_end};
 
		for (int i = 0; i < 2; i++) {
 
			if (MayHaveBridgeAbove(heads[i])) {
 
				if (IsBridgeAbove(heads[i])) {
 
					TileIndex north_head = GetNorthernBridgeEnd(heads[i]);
 

	
 
					if (direction == GetBridgeAxis(heads[i])) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
 

	
 
					if (z_start + TILE_HEIGHT == GetBridgeHeight(north_head)) {
 
						return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
 
					}
 
				}
0 comments (0 inline, 0 general)