summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordarkvater <darkvater@openttd.org>2005-01-21 19:52:32 +0000
committerdarkvater <darkvater@openttd.org>2005-01-21 19:52:32 +0000
commit0a944dc950a8c32e5ae23a9194134e833f840770 (patch)
tree0aa97722ee76d847689d945b957ecc279f9e5699
parent5290d5f667871863876345069d1767afe5a9bd54 (diff)
downloadopenttd-0a944dc950a8c32e5ae23a9194134e833f840770.tar.xz
(svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
-rw-r--r--functions.h1
-rw-r--r--tunnelbridge_cmd.c17
-rw-r--r--vehicle.c22
3 files changed, 24 insertions, 16 deletions
diff --git a/functions.h b/functions.h
index 886010b50..0a97ef0ae 100644
--- a/functions.h
+++ b/functions.h
@@ -214,6 +214,7 @@ bool ScrollWindowTo(int x, int y, Window * w);
bool ScrollMainWindowToTile(TileIndex tile);
bool ScrollMainWindowTo(int x, int y);
void DrawSprite(uint32 img, int x, int y);
+uint GetCorrectTileHeight(TileIndex tile);
bool EnsureNoVehicle(TileIndex tile);
bool EnsureNoVehicleZ(TileIndex tile, byte z);
void MarkAllViewportsDirty(int left, int top, int right, int bottom);
diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c
index e6ae13b89..fe451099c 100644
--- a/tunnelbridge_cmd.c
+++ b/tunnelbridge_cmd.c
@@ -742,7 +742,8 @@ static int32 DoClearBridge(uint tile, uint32 flags)
*/
tile += direction ? TILE_XY(0, 1) : TILE_XY( 1,0);
endtile -= direction ? TILE_XY(0, 1) : TILE_XY( 1,0);
- if ((v = FindVehicleBetween(tile, endtile, TilePixelHeight(tile) + 8)) != NULL) {
+ /* Bridges on slopes might have their Z-value offset..correct this */
+ if ((v = FindVehicleBetween(tile, endtile, TilePixelHeight(tile) + 8 + GetCorrectTileHeight(tile))) != NULL) {
VehicleInTheWayErrMsg(v);
return CMD_ERROR;
}
@@ -804,25 +805,21 @@ clear_it:;
}
static int32 ClearTile_TunnelBridge(uint tile, byte flags) {
- int32 ret;
byte m5 = _map5[tile];
if ((m5 & 0xF0) == 0) {
if (flags & DC_AUTO)
return_cmd_error(STR_5006_MUST_DEMOLISH_TUNNEL_FIRST);
+
return DoClearTunnel(tile, flags);
} else if (m5 & 0x80) {
if (flags & DC_AUTO)
return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
- ret = DoClearBridge(tile, flags);
- if (ret == CMD_ERROR)
- return CMD_ERROR;
-
- return ret;
- } else {
- return CMD_ERROR;
- }
+ return DoClearBridge(tile, flags);
+ }
+
+ return CMD_ERROR;
}
int32 DoConvertTunnelBridgeRail(uint tile, uint totype, bool exec)
diff --git a/vehicle.c b/vehicle.c
index 55843adf0..525b83594 100644
--- a/vehicle.c
+++ b/vehicle.c
@@ -73,17 +73,27 @@ static void *EnsureNoVehicleProcZ(Vehicle *v, void *data)
return v;
}
-bool EnsureNoVehicleZ(TileIndex tile, byte z)
+static inline uint Correct_Z(uint tileh)
+{
+ // needs z correction for slope-type graphics that have the NORTHERN tile lowered
+ // 1, 2, 3, 4, 5, 6 and 7
+ return (CORRECT_Z(tileh)) ? 8 : 0;
+}
+
+uint GetCorrectTileHeight(TileIndex tile)
{
TileInfo ti;
FindLandscapeHeightByTile(&ti, tile);
- // needs z correction for slope-type graphics that have the NORTHERN tile lowered
- // 1, 2, 3, 4, 5, 6 and 7
- if (CORRECT_Z(ti.tileh))
- z += 8;
+ return Correct_Z(ti.tileh);
+}
- ti.z = z;
+bool EnsureNoVehicleZ(TileIndex tile, byte z)
+{
+ TileInfo ti;
+
+ FindLandscapeHeightByTile(&ti, tile);
+ ti.z = z + Correct_Z(ti.tileh);
return VehicleFromPos(tile, &ti, EnsureNoVehicleProcZ) == NULL;
}