File diff r19938:9607b3bf5142 → r19939:167f99380426
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -284,51 +284,52 @@ CommandCost CmdBuildBridge(TileIndex end
 
	int 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);
 
		}
 

	
 
		/* Do not replace town bridges with lower speed bridges. */
 
		/* Do not replace town bridges with lower speed bridges, unless in scenario editor. */
 
		if (!(flags & DC_QUERY_COST) && IsTileOwner(tile_start, OWNER_TOWN) &&
 
				GetBridgeSpec(bridge_type)->speed < GetBridgeSpec(GetBridgeType(tile_start))->speed) {
 
				GetBridgeSpec(bridge_type)->speed < GetBridgeSpec(GetBridgeType(tile_start))->speed &&
 
				_game_mode != GM_EDITOR) {
 
			Town *t = ClosestTownFromTile(tile_start, UINT_MAX);
 

	
 
			if (t == NULL) {
 
				return CMD_ERROR;
 
			} else {
 
				SetDParam(0, t->index);
 
				return_cmd_error(STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS);
 
			}
 
		}
 

	
 
		/* Do not replace the bridge with the same bridge type. */
 
		if (!(flags & DC_QUERY_COST) && (bridge_type == GetBridgeType(tile_start)) && (transport_type != TRANSPORT_ROAD || (roadtypes & ~GetRoadTypes(tile_start)) == 0)) {
 
			return_cmd_error(STR_ERROR_ALREADY_BUILT);
 
		}
 

	
 
		/* Do not allow replacing another company's bridges. */
 
		if (!IsTileOwner(tile_start, company) && !IsTileOwner(tile_start, OWNER_TOWN)) {
 
			return_cmd_error(STR_ERROR_AREA_IS_OWNED_BY_ANOTHER);
 
		}
 

	
 
		cost.AddCost((bridge_len + 1) * _price[PR_CLEAR_BRIDGE]); // The cost of clearing the current bridge.
 
		owner = GetTileOwner(tile_start);
 

	
 
		switch (transport_type) {