diff options
-rw-r--r-- | src/rail_cmd.cpp | 2 | ||||
-rw-r--r-- | src/road_cmd.cpp | 16 | ||||
-rw-r--r-- | src/train_cmd.cpp | 2 | ||||
-rw-r--r-- | src/tunnelbridge_cmd.cpp | 8 | ||||
-rw-r--r-- | src/vehicle.cpp | 8 | ||||
-rw-r--r-- | src/vehicle_func.h | 2 |
6 files changed, 23 insertions, 15 deletions
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index dd6e6c7da..86e0fbbc7 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -1466,7 +1466,7 @@ CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 /* When not coverting rail <-> el. rail, any vehicle cannot be in tunnel/bridge */ if (!IsCompatibleRail(GetRailType(tile), totype) && - HasVehicleOnTunnelBridge(tile, endtile)) continue; + TunnelBridgeIsFree(tile, endtile).Failed()) continue; if (flags & DC_EXEC) { Track track = DiagDirToDiagTrack(GetTunnelBridgeDirection(tile)); diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp index 9e9f9c141..7ee64c795 100644 --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -192,10 +192,12 @@ static CommandCost RemoveRoad(TileIndex tile, DoCommandFlag flags, RoadBits piec if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; break; - case MP_TUNNELBRIDGE: + case MP_TUNNELBRIDGE: { if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR; - if (HasVehicleOnTunnelBridge(tile, GetOtherTunnelBridgeEnd(tile))) return CMD_ERROR; - break; + CommandCost ret = TunnelBridgeIsFree(tile, GetOtherTunnelBridgeEnd(tile)); + ret.SetGlobalErrorMessage(); + if (ret.Failed()) return ret; + } break; default: return CMD_ERROR; @@ -573,13 +575,15 @@ CommandCost CmdBuildRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 if (HasTileRoadType(tile, rt)) return_cmd_error(STR_ERROR_ALREADY_BUILT); } break; - case MP_TUNNELBRIDGE: + case MP_TUNNELBRIDGE: { if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) goto do_clear; if (MirrorRoadBits(DiagDirToRoadBits(GetTunnelBridgeDirection(tile))) != pieces) goto do_clear; if (HasTileRoadType(tile, rt)) return_cmd_error(STR_ERROR_ALREADY_BUILT); /* Don't allow adding roadtype to the bridge/tunnel when vehicles are already driving on it */ - if (HasVehicleOnTunnelBridge(tile, GetOtherTunnelBridgeEnd(tile))) return CMD_ERROR; - break; + CommandCost ret = TunnelBridgeIsFree(tile, GetOtherTunnelBridgeEnd(tile)); + ret.SetGlobalErrorMessage(); + if (ret.Failed()) return ret; + } break; default: { do_clear:; diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 5723f3d47..c0575f9ec 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -2342,7 +2342,7 @@ static void ClearPathReservation(const Train *v, TileIndex tile, Trackdir track_ if (GetTunnelBridgeDirection(tile) == ReverseDiagDir(dir)) { TileIndex end = GetOtherTunnelBridgeEnd(tile); - if (!HasVehicleOnTunnelBridge(tile, end, v)) { + if (TunnelBridgeIsFree(tile, end, v).Succeeded()) { /* Free the reservation only if no other train is on the tiles. */ SetTunnelBridgeReservation(tile, false); SetTunnelBridgeReservation(end, false); diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp index fdbfc8a67..020b9f810 100644 --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -611,7 +611,9 @@ static CommandCost DoClearTunnel(TileIndex tile, DoCommandFlag flags) endtile = GetOtherTunnelEnd(tile); - if (HasVehicleOnTunnelBridge(tile, endtile)) return CMD_ERROR; + CommandCost ret = TunnelBridgeIsFree(tile, endtile); + ret.SetGlobalErrorMessage(); + if (ret.Failed()) return ret; _build_tunnel_endtile = endtile; @@ -676,7 +678,9 @@ static CommandCost DoClearBridge(TileIndex tile, DoCommandFlag flags) endtile = GetOtherBridgeEnd(tile); - if (HasVehicleOnTunnelBridge(tile, endtile)) return CMD_ERROR; + CommandCost ret = TunnelBridgeIsFree(tile, endtile); + ret.SetGlobalErrorMessage(); + if (ret.Failed()) return ret; direction = GetTunnelBridgeDirection(tile); delta = TileOffsByDiagDir(direction); diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 1a72220a8..9c32c14a6 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -437,9 +437,9 @@ static Vehicle *GetVehicleTunnelBridgeProc(Vehicle *v, void *data) * @param tile first end * @param endtile second end * @param ignore Ignore this vehicle when searching - * @return true if the bridge has a vehicle + * @return Succeeded command (if tunnel/bridge is free) or failed command (if a vehicle is using the tunnel/bridge). */ -bool HasVehicleOnTunnelBridge(TileIndex tile, TileIndex endtile, const Vehicle *ignore) +CommandCost TunnelBridgeIsFree(TileIndex tile, TileIndex endtile, const Vehicle *ignore) { /* Value v is not safe in MP games, however, it is used to generate a local * error message only (which may be different for different machines). @@ -448,8 +448,8 @@ bool HasVehicleOnTunnelBridge(TileIndex tile, TileIndex endtile, const Vehicle * Vehicle *v = VehicleFromPos(tile, (void *)ignore, &GetVehicleTunnelBridgeProc, true); if (v == NULL) v = VehicleFromPos(endtile, (void *)ignore, &GetVehicleTunnelBridgeProc, true); - if (v != NULL) _error_message = STR_ERROR_TRAIN_IN_THE_WAY + v->type; - return v != NULL; + if (v != NULL) return_cmd_error(STR_ERROR_TRAIN_IN_THE_WAY + v->type); + return CommandCost(); } diff --git a/src/vehicle_func.h b/src/vehicle_func.h index 7aa48bb3e..82b465478 100644 --- a/src/vehicle_func.h +++ b/src/vehicle_func.h @@ -46,7 +46,7 @@ CommandCost RefitVehicle(Vehicle *v, bool only_this, CargoID new_cid, byte new_s void ViewportAddVehicles(DrawPixelInfo *dpi); void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRFBugs bug_type, bool critical); -bool HasVehicleOnTunnelBridge(TileIndex tile, TileIndex endtile, const Vehicle *ignore = NULL); +CommandCost TunnelBridgeIsFree(TileIndex tile, TileIndex endtile, const Vehicle *ignore = NULL); void DecreaseVehicleValue(Vehicle *v); void CheckVehicleBreakdown(Vehicle *v); |