diff --git a/slope.h b/slope.h new file mode 100644 index 0000000000..79678780ba --- /dev/null +++ b/slope.h @@ -0,0 +1,30 @@ +/* $Id$ */ + +#ifndef SLOPE_H +#define SLOPE_H + +typedef enum Slope { + SLOPE_FLAT = 0x00, + SLOPE_W = 0x01, + SLOPE_S = 0x02, + SLOPE_E = 0x04, + SLOPE_N = 0x08, + SLOPE_STEEP = 0x10, + SLOPE_NW = SLOPE_N | SLOPE_W, + SLOPE_SW = SLOPE_S | SLOPE_W, + SLOPE_SE = SLOPE_S | SLOPE_E, + SLOPE_NE = SLOPE_N | SLOPE_E, + SLOPE_EW = SLOPE_E | SLOPE_W, + SLOPE_NS = SLOPE_N | SLOPE_S, + SLOPE_ELEVATED = SLOPE_N | SLOPE_E | SLOPE_S | SLOPE_W, + SLOPE_NWS = SLOPE_N | SLOPE_W | SLOPE_S, + SLOPE_WSE = SLOPE_W | SLOPE_S | SLOPE_E, + SLOPE_SEN = SLOPE_S | SLOPE_E | SLOPE_N, + SLOPE_ENW = SLOPE_E | SLOPE_N | SLOPE_W, + SLOPE_STEEP_W = SLOPE_STEEP | SLOPE_NWS, + SLOPE_STEEP_S = SLOPE_STEEP | SLOPE_WSE, + SLOPE_STEEP_E = SLOPE_STEEP | SLOPE_SEN, + SLOPE_STEEP_N = SLOPE_STEEP | SLOPE_ENW +} Slope; + +#endif diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c index 7a3f6abbc7..aad26ad8d7 100644 --- a/tunnelbridge_cmd.c +++ b/tunnelbridge_cmd.c @@ -8,6 +8,7 @@ #include "stdafx.h" #include "openttd.h" #include "bridge_map.h" +#include "slope.h" #include "table/sprites.h" #include "table/strings.h" #include "functions.h" @@ -713,6 +714,19 @@ static TileIndex FindEdgesOfBridge(TileIndex tile, TileIndex *endtile) return start; } + +static uint GetBridgeHeightRamp(TileIndex t) +{ + /* Return the height there (the height of the NORTH CORNER) + * If the end of the bridge is on a tile with all corners except the north corner raised, + * the z coordinate is 1 height level too low. Compensate for that */ + return + TilePixelHeight(t) + + (GetTileSlope(t, NULL) == SLOPE_WSE ? TILE_HEIGHT : 0) + + TILE_HEIGHT; +} + + static int32 DoClearBridge(TileIndex tile, uint32 flags) { TileIndex endtile; @@ -898,16 +912,13 @@ int32 DoConvertTunnelBridgeRail(TileIndex tile, uint totype, bool exec) } else if ((_m[tile].m5 & 0xC6) == 0x80) { TileIndex starttile; int32 cost; - uint z = TilePixelHeight(tile); - - z += 8; if (!CheckTileOwnership(tile)) return CMD_ERROR; // railway bridge starttile = tile = FindEdgesOfBridge(tile, &endtile); // Make sure there's no vehicle on the bridge - v = FindVehicleBetween(tile, endtile, z); + v = FindVehicleBetween(tile, endtile, GetBridgeHeightRamp(tile)); if (v != NULL) { VehicleInTheWayErrMsg(v); return CMD_ERROR;