summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2007-12-15 13:59:38 +0000
committersmatz <smatz@openttd.org>2007-12-15 13:59:38 +0000
commit46724104fe611cf6fd6baf546145fbd875bf091e (patch)
tree37542f63db70e9e0ec76e345fddb5a0dd2cef3f0 /src
parent828c24229128ee5e58b4069211e12023671df73d (diff)
downloadopenttd-46724104fe611cf6fd6baf546145fbd875bf091e.tar.xz
(svn r11636) -Fix: it was possible to build/remove road/tram in tunnel/bridge when there was vehicle in it
Diffstat (limited to 'src')
-rw-r--r--src/road_cmd.cpp38
1 files changed, 27 insertions, 11 deletions
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index c1446c01c..f527a970e 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -121,16 +121,27 @@ CommandCost CmdRemoveRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
switch (GetTileType(tile)) {
case MP_ROAD:
if (_game_mode != GM_EDITOR && GetRoadOwner(tile, rt) == OWNER_TOWN) t = GetTownByTile(tile);
+ if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
break;
case MP_STATION:
if (!IsDriveThroughStopTile(tile)) return CMD_ERROR;
+ if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
break;
case MP_TUNNELBRIDGE:
- if ((IsTunnel(tile) && GetTunnelTransportType(tile) != TRANSPORT_ROAD) ||
- (IsBridge(tile) && GetBridgeTransportType(tile) != TRANSPORT_ROAD)) return CMD_ERROR;
- break;
+ {
+ TileIndex endtile;
+ if (IsTunnel(tile)) {
+ if (GetTunnelTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
+ endtile = GetOtherTunnelEnd(tile);
+ } else {
+ if (GetBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
+ endtile = GetOtherBridgeEnd(tile);
+ }
+
+ if (GetVehicleTunnelBridge(tile, endtile) != NULL) return CMD_ERROR;
+ } break;
default:
return CMD_ERROR;
@@ -143,8 +154,6 @@ CommandCost CmdRemoveRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (!CheckAllowRemoveRoad(tile, pieces, &edge_road, rt)) return CMD_ERROR;
- if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
-
/* check if you're allowed to remove the street owned by a town
* removal allowance depends on difficulty setting */
if (!CheckforTownRating(flags, t, ROAD_REMOVE)) return CMD_ERROR;
@@ -502,12 +511,19 @@ CommandCost CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
break;
case MP_TUNNELBRIDGE:
- if ((IsTunnel(tile) && GetTunnelTransportType(tile) != TRANSPORT_ROAD) ||
- (IsBridge(tile) && GetBridgeTransportType(tile) != TRANSPORT_ROAD)) return CMD_ERROR;
- if (HasBit(GetRoadTypes(tile), rt)) return_cmd_error(STR_1007_ALREADY_BUILT);
- /* Don't allow "upgrading" the bridge/tunnel when vehicles are already driving on it */
- if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
- break;
+ {
+ TileIndex endtile;
+ if (IsTunnel(tile)) {
+ if (GetTunnelTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
+ endtile = GetOtherTunnelEnd(tile);
+ } else {
+ if (GetBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
+ endtile = GetOtherBridgeEnd(tile);
+ }
+ if (HasBit(GetRoadTypes(tile), rt)) return_cmd_error(STR_1007_ALREADY_BUILT);
+ /* Don't allow "upgrading" the bridge/tunnel when vehicles are already driving on it */
+ if (GetVehicleTunnelBridge(tile, endtile) != NULL) return CMD_ERROR;
+ } break;
default:
do_clear:;