File diff r8082:9d654f9b59ea → r8083:8cd2123a0c7c
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -31,14 +31,15 @@
 
#include "water_map.h"
 
#include "yapf/yapf.h"
 
#include "date.h"
 
#include "newgrf_sound.h"
 
#include "autoslope.h"
 
#include "transparency.h"
 
#include "tunnelbridge_map.h"
 
#include "table/bridge_land.h"
 

	
 
#include "table/bridge_land.h"
 

	
 
const Bridge orig_bridge[] = {
 
/*
 
	     year of availablity
 
	     |  minimum length
 
	     |  |   maximum length
 
@@ -263,13 +264,13 @@ CommandCost CmdBuildBridge(TileIndex end
 
	                   && _patches.build_on_slopes);
 

	
 
	TransportType transport_type = railtype == INVALID_RAILTYPE ? TRANSPORT_ROAD : TRANSPORT_RAIL;
 

	
 
	if (IsBridgeTile(tile_start) && IsBridgeTile(tile_end) &&
 
			GetOtherBridgeEnd(tile_start) == tile_end &&
 
			GetBridgeTransportType(tile_start) == transport_type) {
 
			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_5007_MUST_DEMOLISH_BRIDGE_FIRST);
 
		}
 
@@ -388,13 +389,13 @@ CommandCost CmdBuildBridge(TileIndex end
 
				if (GetRoadTileType(tile) == ROAD_TILE_DEPOT) goto not_valid_below;
 
				break;
 

	
 
			case MP_TUNNELBRIDGE:
 
				if (IsTunnel(tile)) break;
 
				if (replace_bridge) break;
 
				if (direction == DiagDirToAxis(GetBridgeRampDirection(tile))) goto not_valid_below;
 
				if (direction == DiagDirToAxis(GetTunnelBridgeDirection(tile))) goto not_valid_below;
 
				if (z_start < GetBridgeHeight(tile)) goto not_valid_below;
 
				break;
 

	
 
			case MP_UNMOVABLE:
 
				if (!IsOwnedLand(tile)) goto not_valid_below;
 
				break;
 
@@ -599,13 +600,13 @@ static CommandCost DoClearTunnel(TileInd
 
		}
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		/* We first need to request the direction before calling DoClearSquare
 
		 *  else the direction is always 0.. dah!! ;) */
 
		DiagDirection dir = GetTunnelDirection(tile);
 
		DiagDirection dir = GetTunnelBridgeDirection(tile);
 
		Track track;
 

	
 
		/* Adjust the town's player rating. Do this before removing the tile owner info. */
 
		if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR)
 
			ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM);
 

	
 
@@ -633,13 +634,13 @@ static CommandCost DoClearBridge(TileInd
 
	if (!CheckAllowRemoveTunnelBridge(tile)) return CMD_ERROR;
 

	
 
	endtile = GetOtherBridgeEnd(tile);
 

	
 
	if (GetVehicleTunnelBridge(tile, endtile) != NULL) return CMD_ERROR;
 

	
 
	direction = GetBridgeRampDirection(tile);
 
	direction = GetTunnelBridgeDirection(tile);
 
	delta = TileOffsByDiagDir(direction);
 

	
 
	if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
 
		t = ClosestTownFromTile(tile, (uint)-1); // town penalty rating
 

	
 
		/* Check if you are allowed to remove the bridge owned by a town
 
@@ -698,13 +699,13 @@ static CommandCost ClearTile_TunnelBridg
 
 * @param exec        Switches between test and execute mode
 
 * @return            The cost and state of the operation
 
 * @retval CMD_ERROR  An error occured during the operation.
 
 */
 
CommandCost DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bool exec)
 
{
 
	if (IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_RAIL) {
 
	if (IsTunnel(tile) && GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) {
 
		TileIndex endtile = GetOtherTunnelEnd(tile);
 

	
 
		/* If not coverting rail <-> el. rail, any vehicle cannot be in tunnel */
 
		if (!IsCompatibleRail(GetRailType(tile), totype) &&
 
				GetVehicleTunnelBridge(tile, endtile) != NULL) {
 
			return CMD_ERROR;
 
@@ -713,23 +714,23 @@ CommandCost DoConvertTunnelBridgeRail(Ti
 
		if (exec) {
 
			SetRailType(tile, totype);
 
			SetRailType(endtile, totype);
 
			MarkTileDirtyByTile(tile);
 
			MarkTileDirtyByTile(endtile);
 

	
 
			Track track = AxisToTrack(DiagDirToAxis(GetTunnelDirection(tile)));
 
			Track track = AxisToTrack(DiagDirToAxis(GetTunnelBridgeDirection(tile)));
 

	
 
			YapfNotifyTrackLayoutChange(tile, track);
 
			YapfNotifyTrackLayoutChange(endtile, track);
 

	
 
			VehicleFromPos(tile, NULL, &UpdateTrainPowerProc);
 
			VehicleFromPos(endtile, NULL, &UpdateTrainPowerProc);
 
		}
 

	
 
		return CommandCost((DistanceManhattan(tile, endtile) + 1) * RailConvertCost(GetRailType(tile), totype));
 
	} else if (IsBridge(tile) && GetBridgeTransportType(tile) == TRANSPORT_RAIL) {
 
	} else if (IsBridge(tile) && GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) {
 
		TileIndex endtile = GetOtherBridgeEnd(tile);
 

	
 
		if (!IsCompatibleRail(GetRailType(tile), totype) &&
 
				GetVehicleTunnelBridge(tile, endtile) != NULL) {
 
			return CMD_ERROR;
 
		}
 
@@ -737,14 +738,14 @@ CommandCost DoConvertTunnelBridgeRail(Ti
 
		if (exec) {
 
			SetRailType(tile, totype);
 
			SetRailType(endtile, totype);
 
			MarkTileDirtyByTile(tile);
 
			MarkTileDirtyByTile(endtile);
 

	
 
			Track track = AxisToTrack(DiagDirToAxis(GetBridgeRampDirection(tile)));
 
			TileIndexDiff delta = TileOffsByDiagDir(GetBridgeRampDirection(tile));
 
			Track track = AxisToTrack(DiagDirToAxis(GetTunnelBridgeDirection(tile)));
 
			TileIndexDiff delta = TileOffsByDiagDir(GetTunnelBridgeDirection(tile));
 

	
 
			YapfNotifyTrackLayoutChange(tile, track);
 
			YapfNotifyTrackLayoutChange(endtile, track);
 

	
 
			VehicleFromPos(tile, NULL, &UpdateTrainPowerProc);
 
			VehicleFromPos(endtile, NULL, &UpdateTrainPowerProc);
 
@@ -891,28 +892,28 @@ static void DrawTile_TunnelBridge(TileIn
 
			 * w  h  bb_x bb_y| x   y   w   h |bb_x bb_y w h */
 
			{  1,  0, -15, -14,  0, 15, 16,  1, 0, 1, 16, 15 }, // NE
 
			{  0,  1, -14, -15, 15,  0,  1, 16, 1, 0, 15, 16 }, // SE
 
			{  1,  0, -15, -14,  0, 15, 16,  1, 0, 1, 16, 15 }, // SW
 
			{  0,  1, -14, -15, 15,  0,  1, 16, 1, 0, 15, 16 }, // NW
 
		};
 
		const int *BB_data = _tunnel_BB[GetTunnelDirection(ti->tile)];
 
		const int *BB_data = _tunnel_BB[GetTunnelBridgeDirection(ti->tile)];
 

	
 
		bool catenary = false;
 

	
 
		if (GetTunnelTransportType(ti->tile) == TRANSPORT_RAIL) {
 
		if (GetTunnelBridgeTransportType(ti->tile) == TRANSPORT_RAIL) {
 
			image = GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.tunnel;
 
		} else {
 
			image = SPR_TUNNEL_ENTRY_REAR_ROAD;
 
		}
 

	
 
		if (HasTunnelSnowOrDesert(ti->tile)) image += 32;
 
		if (HasTunnelBridgeSnowOrDesert(ti->tile)) image += 32;
 

	
 
		image += GetTunnelDirection(ti->tile) * 2;
 
		image += GetTunnelBridgeDirection(ti->tile) * 2;
 
		DrawGroundSprite(image, PAL_NONE);
 
		if (GetTunnelTransportType(ti->tile) == TRANSPORT_ROAD) {
 
			DiagDirection dir = GetTunnelDirection(ti->tile);
 
		if (GetTunnelBridgeTransportType(ti->tile) == TRANSPORT_ROAD) {
 
			DiagDirection dir = GetTunnelBridgeDirection(ti->tile);
 
			RoadTypes rts = GetRoadTypes(ti->tile);
 

	
 
			if (HasBit(rts, ROADTYPE_TRAM)) {
 
				static const SpriteID tunnel_sprites[2][4] = { { 28, 78, 79, 27 }, {  5, 76, 77,  4 } };
 

	
 
				DrawGroundSprite(SPR_TRAMWAY_BASE + tunnel_sprites[rts - ROADTYPES_TRAM][dir], PAL_NONE);
 
@@ -938,28 +939,28 @@ static void DrawTile_TunnelBridge(TileIn
 
		AddSortableSpriteToDraw(SPR_EMPTY_BOUNDING_BOX, PAL_NONE, ti->x + BB_data[4], ti->y + BB_data[5], BB_data[6], BB_data[7], TILE_HEIGHT, ti->z);
 

	
 
		DrawBridgeMiddle(ti);
 
	} else if (IsBridge(ti->tile)) { // XXX is this necessary?
 
		const PalSpriteID *psid;
 
		int base_offset;
 
		bool ice = HasBridgeSnowOrDesert(ti->tile);
 
		bool ice = HasTunnelBridgeSnowOrDesert(ti->tile);
 

	
 
		if (GetBridgeTransportType(ti->tile) == TRANSPORT_RAIL) {
 
		if (GetTunnelBridgeTransportType(ti->tile) == TRANSPORT_RAIL) {
 
			base_offset = GetRailTypeInfo(GetRailType(ti->tile))->bridge_offset;
 
			assert(base_offset != 8); // This one is used for roads
 
		} else {
 
			base_offset = 8;
 
		}
 

	
 
		/* as the lower 3 bits are used for other stuff, make sure they are clear */
 
		assert( (base_offset & 0x07) == 0x00);
 

	
 
		DrawFoundation(ti, GetBridgeFoundation(ti->tileh, DiagDirToAxis(GetBridgeRampDirection(ti->tile))));
 
		DrawFoundation(ti, GetBridgeFoundation(ti->tileh, DiagDirToAxis(GetTunnelBridgeDirection(ti->tile))));
 

	
 
		/* HACK Wizardry to convert the bridge ramp direction into a sprite offset */
 
		base_offset += (6 - GetBridgeRampDirection(ti->tile)) % 4;
 
		base_offset += (6 - GetTunnelBridgeDirection(ti->tile)) % 4;
 

	
 
		if (ti->tileh == SLOPE_FLAT) base_offset += 4; // sloped bridge head
 

	
 
		/* Table number 6 always refers to the bridge heads for any bridge type */
 
		psid = &GetBridgeSpriteTable(GetBridgeType(ti->tile), 6)[base_offset];
 

	
 
@@ -969,26 +970,26 @@ static void DrawTile_TunnelBridge(TileIn
 
			DrawGroundSprite(SPR_FLAT_SNOWY_TILE + _tileh_to_sprite[ti->tileh], PAL_NONE);
 
		}
 

	
 
		/* draw ramp */
 

	
 
		/* Draw Trambits as SpriteCombine */
 
		if (GetBridgeTransportType(ti->tile) == TRANSPORT_ROAD) StartSpriteCombine();
 
		if (GetTunnelBridgeTransportType(ti->tile) == TRANSPORT_ROAD) StartSpriteCombine();
 

	
 
		/* HACK set the height of the BB of a sloped ramp to 1 so a vehicle on
 
		 * it doesn't disappear behind it
 
		 */
 
		AddSortableSpriteToDraw(
 
			psid->sprite, psid->pal, ti->x, ti->y, 16, 16, ti->tileh == SLOPE_FLAT ? 0 : 8, ti->z, IsTransparencySet(TO_BRIDGES)
 
		);
 

	
 
		if (GetBridgeTransportType(ti->tile) == TRANSPORT_ROAD) {
 
		if (GetTunnelBridgeTransportType(ti->tile) == TRANSPORT_ROAD) {
 
			RoadTypes rts = GetRoadTypes(ti->tile);
 

	
 
			if (HasBit(rts, ROADTYPE_TRAM)) {
 
				uint offset = GetBridgeRampDirection(ti->tile);
 
				uint offset = GetTunnelBridgeDirection(ti->tile);
 
				uint z = ti->z;
 
				if (ti->tileh != SLOPE_FLAT) {
 
					offset = (offset + 1) & 1;
 
					z += TILE_HEIGHT;
 
				} else {
 
					offset += 2;
 
@@ -1081,13 +1082,13 @@ void DrawBridgeMiddle(const TileInfo* ti
 
	piece = CalcBridgePiece(
 
		DistanceManhattan(ti->tile, rampnorth),
 
		DistanceManhattan(ti->tile, rampsouth)
 
	);
 
	type = GetBridgeType(rampsouth);
 

	
 
	if (GetBridgeTransportType(rampsouth) == TRANSPORT_RAIL) {
 
	if (GetTunnelBridgeTransportType(rampsouth) == TRANSPORT_RAIL) {
 
		base_offset = GetRailTypeInfo(GetRailType(rampsouth))->bridge_offset;
 
	} else {
 
		base_offset = 8;
 
	}
 

	
 
	psid = base_offset + GetBridgeSpriteTable(type, piece);
 
@@ -1099,24 +1100,24 @@ void DrawBridgeMiddle(const TileInfo* ti
 
	z = bridge_z - BRIDGE_Z_START;
 

	
 
	/* Add a bounding box, that separates the bridge from things below it. */
 
	AddSortableSpriteToDraw(SPR_EMPTY_BOUNDING_BOX, PAL_NONE, x, y, 16, 16, 1, bridge_z - TILE_HEIGHT + BB_Z_SEPARATOR);
 

	
 
	/* Draw Trambits as SpriteCombine */
 
	if (GetBridgeTransportType(rampsouth) == TRANSPORT_ROAD) StartSpriteCombine();
 
	if (GetTunnelBridgeTransportType(rampsouth) == TRANSPORT_ROAD) StartSpriteCombine();
 

	
 
	/* Draw floor and far part of bridge*/
 
	if (axis == AXIS_X) {
 
		AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 16, 1, 0x28, z, IsTransparencySet(TO_BRIDGES), 0, 0, BRIDGE_Z_START);
 
	} else {
 
		AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 1, 16, 0x28, z, IsTransparencySet(TO_BRIDGES), 0, 0, BRIDGE_Z_START);
 
	}
 

	
 
	psid++;
 

	
 
	if (GetBridgeTransportType(rampsouth) == TRANSPORT_ROAD) {
 
	if (GetTunnelBridgeTransportType(rampsouth) == TRANSPORT_ROAD) {
 
		RoadTypes rts = GetRoadTypes(rampsouth);
 

	
 
		if (HasBit(rts, ROADTYPE_TRAM)) {
 
			/* DrawBridgeTramBits() calls EndSpriteCombine() and StartSpriteCombine() */
 
			DrawBridgeTramBits(x, y, bridge_z, axis ^ 1, HasBit(rts, ROADTYPE_ROAD));
 
		} else {
 
@@ -1134,13 +1135,13 @@ void DrawBridgeMiddle(const TileInfo* ti
 
	} else {
 
		x += 12;
 
		if (psid->sprite & SPRITE_MASK) AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 4, 16, 0x28, z, IsTransparencySet(TO_BRIDGES), 3, 0, BRIDGE_Z_START);
 
	}
 

	
 
	/* Draw TramFront as SpriteCombine */
 
	if (GetBridgeTransportType(rampsouth) == TRANSPORT_ROAD) EndSpriteCombine();
 
	if (GetTunnelBridgeTransportType(rampsouth) == TRANSPORT_ROAD) EndSpriteCombine();
 

	
 
	psid++;
 
	if (ti->z + 5 == z) {
 
		/* draw poles below for small bridges */
 
		if (psid->sprite != 0) {
 
			SpriteID image = psid->sprite;
 
@@ -1165,18 +1166,18 @@ static uint GetSlopeZ_TunnelBridge(TileI
 
	Slope tileh = GetTileSlope(tile, &z);
 

	
 
	x &= 0xF;
 
	y &= 0xF;
 

	
 
	if (IsTunnel(tile)) {
 
		uint pos = (DiagDirToAxis(GetTunnelDirection(tile)) == AXIS_X ? y : x);
 
		uint pos = (DiagDirToAxis(GetTunnelBridgeDirection(tile)) == AXIS_X ? y : x);
 

	
 
		/* In the tunnel entrance? */
 
		if (5 <= pos && pos <= 10) return z;
 
	} else {
 
		DiagDirection dir = GetBridgeRampDirection(tile);
 
		DiagDirection dir = GetTunnelBridgeDirection(tile);
 
		uint pos = (DiagDirToAxis(dir) == AXIS_X ? y : x);
 

	
 
		z += ApplyFoundationToSlope(GetBridgeFoundation(tileh, DiagDirToAxis(dir)), &tileh);
 

	
 
		/* On the bridge ramp? */
 
		if (5 <= pos && pos <= 10) {
 
@@ -1197,13 +1198,13 @@ static uint GetSlopeZ_TunnelBridge(TileI
 

	
 
	return z + GetPartialZ(x, y, tileh);
 
}
 

	
 
static Foundation GetFoundation_TunnelBridge(TileIndex tile, Slope tileh)
 
{
 
	return IsTunnel(tile) ? FOUNDATION_NONE : GetBridgeFoundation(tileh, DiagDirToAxis(GetBridgeRampDirection(tile)));
 
	return IsTunnel(tile) ? FOUNDATION_NONE : GetBridgeFoundation(tileh, DiagDirToAxis(GetTunnelBridgeDirection(tile)));
 
}
 

	
 

	
 
static void GetAcceptedCargo_TunnelBridge(TileIndex tile, AcceptedCargo ac)
 
{
 
	/* not used */
 
@@ -1241,47 +1242,47 @@ static const StringID _bridge_tile_str[(
 
	0, 0, 0,
 
};
 

	
 
static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc *td)
 
{
 
	if (IsTunnel(tile)) {
 
		td->str = (GetTunnelTransportType(tile) == TRANSPORT_RAIL) ?
 
		td->str = (GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) ?
 
			STR_5017_RAILROAD_TUNNEL : STR_5018_ROAD_TUNNEL;
 
	} else {
 
		td->str = _bridge_tile_str[GetBridgeTransportType(tile) << 4 | GetBridgeType(tile)];
 
		td->str = _bridge_tile_str[GetTunnelBridgeTransportType(tile) << 4 | GetBridgeType(tile)];
 
	}
 
	td->owner = GetTileOwner(tile);
 
}
 

	
 

	
 
static void AnimateTile_TunnelBridge(TileIndex tile)
 
{
 
	/* not used */
 
}
 

	
 
static void TileLoop_TunnelBridge(TileIndex tile)
 
{
 
	bool snow_or_desert = IsTunnelTile(tile) ? HasTunnelSnowOrDesert(tile) : HasBridgeSnowOrDesert(tile);
 
	bool snow_or_desert = IsTunnelTile(tile) ? HasTunnelBridgeSnowOrDesert(tile) : HasTunnelBridgeSnowOrDesert(tile);
 
	switch (_opt.landscape) {
 
		case LT_ARCTIC:
 
			if (snow_or_desert != (GetTileZ(tile) > GetSnowLine())) {
 
				if (IsTunnelTile(tile)) {
 
					SetTunnelSnowOrDesert(tile, !snow_or_desert);
 
					SetTunnelBridgeSnowOrDesert(tile, !snow_or_desert);
 
				} else {
 
					SetBridgeSnowOrDesert(tile, !snow_or_desert);
 
					SetTunnelBridgeSnowOrDesert(tile, !snow_or_desert);
 
				}
 
				MarkTileDirtyByTile(tile);
 
			}
 
			break;
 

	
 
		case LT_TROPIC:
 
			if (GetTropicZone(tile) == TROPICZONE_DESERT && !snow_or_desert) {
 
				if (IsTunnelTile(tile)) {
 
					SetTunnelSnowOrDesert(tile, true);
 
					SetTunnelBridgeSnowOrDesert(tile, true);
 
				} else {
 
					SetBridgeSnowOrDesert(tile, true);
 
					SetTunnelBridgeSnowOrDesert(tile, true);
 
				}
 
				MarkTileDirtyByTile(tile);
 
			}
 
			break;
 
	}
 
}
 
@@ -1292,19 +1293,19 @@ static void ClickTile_TunnelBridge(TileI
 
}
 

	
 

	
 
static uint32 GetTileTrackStatus_TunnelBridge(TileIndex tile, TransportType mode, uint sub_mode)
 
{
 
	if (IsTunnel(tile)) {
 
		if (GetTunnelTransportType(tile) != mode) return 0;
 
		if (GetTunnelTransportType(tile) == TRANSPORT_ROAD && (GetRoadTypes(tile) & sub_mode) == 0) return 0;
 
		return AxisToTrackBits(DiagDirToAxis(GetTunnelDirection(tile))) * 0x101;
 
		if (GetTunnelBridgeTransportType(tile) != mode) return 0;
 
		if (GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD && (GetRoadTypes(tile) & sub_mode) == 0) return 0;
 
		return AxisToTrackBits(DiagDirToAxis(GetTunnelBridgeDirection(tile))) * 0x101;
 
	} else {
 
		if (GetBridgeTransportType(tile) != mode) return 0;
 
		if (GetBridgeTransportType(tile) == TRANSPORT_ROAD && (GetRoadTypes(tile) & sub_mode) == 0) return 0;
 
		return AxisToTrackBits(DiagDirToAxis(GetBridgeRampDirection(tile))) * 0x101;
 
		if (GetTunnelBridgeTransportType(tile) != mode) return 0;
 
		if (GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD && (GetRoadTypes(tile) & sub_mode) == 0) return 0;
 
		return AxisToTrackBits(DiagDirToAxis(GetTunnelBridgeDirection(tile))) * 0x101;
 
	}
 
}
 

	
 
static void ChangeTileOwner_TunnelBridge(TileIndex tile, PlayerID old_player, PlayerID new_player)
 
{
 
	if (!IsTileOwner(tile, old_player)) return;
 
@@ -1314,13 +1315,13 @@ static void ChangeTileOwner_TunnelBridge
 
	} else {
 
		if (CmdFailed(DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
 
			/* When clearing the bridge/tunnel failed there are still vehicles on/in
 
			 * the bridge/tunnel. As all *our* vehicles are already removed, they
 
			 * must be of another owner. Therefor this must be a road bridge/tunnel.
 
			 * In that case we can safely reassign the ownership to OWNER_NONE. */
 
			assert((IsTunnel(tile) ? GetTunnelTransportType(tile) : GetBridgeTransportType(tile)) == TRANSPORT_ROAD);
 
			assert((IsTunnel(tile) ? GetTunnelBridgeTransportType(tile) : GetTunnelBridgeTransportType(tile)) == TRANSPORT_ROAD);
 
			SetTileOwner(tile, OWNER_NONE);
 
		}
 
	}
 
}
 

	
 

	
 
@@ -1351,13 +1352,13 @@ static uint32 VehicleEnter_TunnelBridge(
 
		DiagDirection dir;
 
		DiagDirection vdir;
 

	
 
		if (v->type == VEH_TRAIN) {
 
			fc = (x & 0xF) + (y << 4);
 

	
 
			dir = GetTunnelDirection(tile);
 
			dir = GetTunnelBridgeDirection(tile);
 
			vdir = DirToDiagDir(v->direction);
 

	
 
			if (v->u.rail.track != TRACK_BIT_WORMHOLE && dir == vdir) {
 
				if (IsFrontEngine(v) && fc == _tunnel_fractcoord_1[dir]) {
 
					if (!PlayVehicleSound(v, VSE_TUNNEL) && RailVehInfo(v->engine_type)->engclass == 0) {
 
						SndPlayVehicleFx(SND_05_TRAIN_THROUGH_TUNNEL, v);
 
@@ -1379,13 +1380,13 @@ static uint32 VehicleEnter_TunnelBridge(
 
				assert(v->u.rail.track);
 
				v->vehstatus &= ~VS_HIDDEN;
 
				return VETSB_ENTERED_WORMHOLE;
 
			}
 
		} else if (v->type == VEH_ROAD) {
 
			fc = (x & 0xF) + (y << 4);
 
			dir = GetTunnelDirection(tile);
 
			dir = GetTunnelBridgeDirection(tile);
 
			vdir = DirToDiagDir(v->direction);
 

	
 
			/* Enter tunnel? */
 
			if (v->u.road.state != RVSB_WORMHOLE && dir == vdir) {
 
				if (fc == _tunnel_fractcoord_4[dir] ||
 
						fc == _tunnel_fractcoord_5[dir]) {
 
@@ -1419,13 +1420,13 @@ static uint32 VehicleEnter_TunnelBridge(
 
			uint16 spd = _bridge[GetBridgeType(tile)].speed;
 

	
 
			if (v->type == VEH_ROAD) spd *= 2;
 
			if (v->cur_speed > spd) v->cur_speed = spd;
 
		}
 

	
 
		dir = GetBridgeRampDirection(tile);
 
		dir = GetTunnelBridgeDirection(tile);
 
		if (DirToDiagDir(v->direction) == dir) {
 
			switch (dir) {
 
				default: NOT_REACHED();
 
				case DIAGDIR_NE: if ((x & 0xF) != 0)             return VETSB_CONTINUE; break;
 
				case DIAGDIR_SE: if ((y & 0xF) != TILE_SIZE - 1) return VETSB_CONTINUE; break;
 
				case DIAGDIR_SW: if ((x & 0xF) != TILE_SIZE - 1) return VETSB_CONTINUE; break;
 
@@ -1459,13 +1460,13 @@ static uint32 VehicleEnter_TunnelBridge(
 
	return VETSB_CONTINUE;
 
}
 

	
 
static CommandCost TerraformTile_TunnelBridge(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
 
{
 
	if (_patches.build_on_slopes && AutoslopeEnabled() && IsBridge(tile)) {
 
		DiagDirection direction = GetBridgeRampDirection(tile);
 
		DiagDirection direction = GetTunnelBridgeDirection(tile);
 
		Axis axis = DiagDirToAxis(direction);
 
		CommandCost res;
 

	
 
		/* Check if new slope is valid for bridges in general (so we can savely call GetBridgeFoundation()) */
 
		if ((direction == DIAGDIR_NW) || (direction == DIAGDIR_NE)) {
 
			res = CheckBridgeSlopeSouth(axis, tileh_new);