summaryrefslogtreecommitdiff
path: root/src/rail_cmd.cpp
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2010-03-05 21:20:22 +0000
committeralberth <alberth@openttd.org>2010-03-05 21:20:22 +0000
commitc395b93acd69106df6005e66264d9114e0198440 (patch)
tree5cab6ad9aa5c0ff7ee6ddb129ed9b8d439bbedbe /src/rail_cmd.cpp
parent0bfd06245b57aa1276cc321fc8d841fd655f7b79 (diff)
downloadopenttd-c395b93acd69106df6005e66264d9114e0198440.tar.xz
(svn r19319) -Codechange: EnsureNoVehicleOnGround() returns a CommandCost.
Diffstat (limited to 'src/rail_cmd.cpp')
-rw-r--r--src/rail_cmd.cpp32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index 86e0fbbc7..eb29fef07 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -416,7 +416,7 @@ CommandCost CmdBuildSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, u
break;
}
- case MP_ROAD:
+ case MP_ROAD: {
#define M(x) (1 << (x))
/* Level crossings may only be built on these slopes */
if (!HasBit(M(SLOPE_SEN) | M(SLOPE_ENW) | M(SLOPE_NWS) | M(SLOPE_NS) | M(SLOPE_WSE) | M(SLOPE_EW) | M(SLOPE_FLAT), tileh)) {
@@ -424,7 +424,9 @@ CommandCost CmdBuildSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, u
}
#undef M
- if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
+ CommandCost ret = EnsureNoVehicleOnGround(tile);
+ ret.SetGlobalErrorMessage();
+ if (ret.Failed()) return ret;
if (IsNormalRoad(tile)) {
if (HasRoadWorks(tile)) return_cmd_error(STR_ERROR_ROAD_WORKS_IN_PROGRESS);
@@ -463,6 +465,7 @@ CommandCost CmdBuildSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, u
return_cmd_error(STR_ERROR_ALREADY_BUILT);
}
/* FALLTHROUGH */
+ }
default: {
/* Will there be flat water on the lower halftile? */
@@ -528,10 +531,14 @@ CommandCost CmdRemoveSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1,
case MP_ROAD: {
if (!IsLevelCrossing(tile) ||
GetCrossingRailBits(tile) != trackbit ||
- (_current_company != OWNER_WATER && !CheckTileOwnership(tile)) ||
- (!(flags & DC_BANKRUPT) && !EnsureNoVehicleOnGround(tile))) {
+ (_current_company != OWNER_WATER && !CheckTileOwnership(tile))) {
return CMD_ERROR;
}
+ if (!(flags & DC_BANKRUPT)) {
+ CommandCost ret = EnsureNoVehicleOnGround(tile);
+ ret.SetGlobalErrorMessage();
+ if (ret.Failed()) return ret;
+ }
if (flags & DC_EXEC) {
if (HasReservedTracks(tile, trackbit)) {
@@ -1408,7 +1415,13 @@ CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
/* Vehicle on the tile when not converting Rail <-> ElRail
* Tunnels and bridges have special check later */
if (tt != MP_TUNNELBRIDGE) {
- if (!IsCompatibleRail(type, totype) && !EnsureNoVehicleOnGround(tile)) continue;
+ if (!IsCompatibleRail(type, totype)) {
+ CommandCost ret = EnsureNoVehicleOnGround(tile);
+ if (ret.Failed()) {
+ ret.SetGlobalErrorMessage();
+ continue;
+ }
+ }
if (flags & DC_EXEC) { // we can safely convert, too
TrackBits reserved = GetReservedTrackbits(tile);
Track track;
@@ -1524,8 +1537,9 @@ static CommandCost RemoveTrainDepot(TileIndex tile, DoCommandFlag flags)
if (!CheckTileOwnership(tile) && _current_company != OWNER_WATER)
return CMD_ERROR;
- if (!EnsureNoVehicleOnGround(tile))
- return CMD_ERROR;
+ CommandCost ret = EnsureNoVehicleOnGround(tile);
+ ret.SetGlobalErrorMessage();
+ if (ret.Failed()) return ret;
if (flags & DC_EXEC) {
/* read variables before the depot is removed */
@@ -1581,7 +1595,9 @@ static CommandCost ClearTile_Track(TileIndex tile, DoCommandFlag flags)
/* when bankrupting, don't make water dirty, there could be a ship on lower halftile */
if (water_ground && !(flags & DC_BANKRUPT)) {
- if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
+ CommandCost ret = EnsureNoVehicleOnGround(tile);
+ ret.SetGlobalErrorMessage();
+ if (ret.Failed()) return ret;
/* The track was removed, and left a coast tile. Now also clear the water. */
if (flags & DC_EXEC) DoClearSquare(tile);