summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/disaster_cmd.cpp2
-rw-r--r--src/industry_cmd.cpp4
-rw-r--r--src/rail_cmd.cpp32
-rw-r--r--src/road_cmd.cpp37
-rw-r--r--src/station_cmd.cpp28
-rw-r--r--src/unmovable_cmd.cpp4
-rw-r--r--src/vehicle.cpp8
-rw-r--r--src/vehicle_func.h2
-rw-r--r--src/water_cmd.cpp23
-rw-r--r--src/waypoint_cmd.cpp11
10 files changed, 109 insertions, 42 deletions
diff --git a/src/disaster_cmd.cpp b/src/disaster_cmd.cpp
index 6ff1ed1ba..d2f34f2cc 100644
--- a/src/disaster_cmd.cpp
+++ b/src/disaster_cmd.cpp
@@ -67,7 +67,7 @@ enum DisasterSubType {
static void DisasterClearSquare(TileIndex tile)
{
- if (!EnsureNoVehicleOnGround(tile)) return;
+ if (EnsureNoVehicleOnGround(tile).Failed()) return;
switch (GetTileType(tile)) {
case MP_RAILWAY:
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index 0ebe23c9a..66686ee9f 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -1337,7 +1337,9 @@ static CommandCost CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTil
return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
}
} else {
- if (!EnsureNoVehicleOnGround(cur_tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
+ CommandCost ret = EnsureNoVehicleOnGround(cur_tile);
+ ret.SetGlobalErrorMessage();
+ if (ret.Failed()) return ret;
if (MayHaveBridgeAbove(cur_tile) && IsBridgeAbove(cur_tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
const IndustryTileSpec *its = GetIndustryTileSpec(gfx);
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);
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index 7ee64c795..0f6cc1581 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -183,14 +183,19 @@ static CommandCost RemoveRoad(TileIndex tile, DoCommandFlag flags, RoadBits piec
if (!HasBit(rts, rt)) return CMD_ERROR;
switch (GetTileType(tile)) {
- case MP_ROAD:
- if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
- break;
+ case MP_ROAD: {
+ CommandCost ret = EnsureNoVehicleOnGround(tile);
+ ret.SetGlobalErrorMessage();
+ if (ret.Failed()) return ret;
+ } break;
- case MP_STATION:
+ case MP_STATION: {
if (!IsDriveThroughStopTile(tile)) return CMD_ERROR;
- if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
- break;
+
+ CommandCost ret = EnsureNoVehicleOnGround(tile);
+ ret.SetGlobalErrorMessage();
+ if (ret.Failed()) return ret;
+ } break;
case MP_TUNNELBRIDGE: {
if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
@@ -493,7 +498,9 @@ CommandCost CmdBuildRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
Owner owner = GetRoadOwner(tile, ROADTYPE_ROAD);
if (owner != OWNER_NONE && !CheckOwnership(owner, tile)) return CMD_ERROR;
- if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
+ CommandCost ret = EnsureNoVehicleOnGround(tile);
+ ret.SetGlobalErrorMessage();
+ if (ret.Failed()) return ret;
/* Ignore half built tiles */
if ((flags & DC_EXEC) && rt != ROADTYPE_TRAM && IsStraightRoad(existing)) {
@@ -549,7 +556,9 @@ CommandCost CmdBuildRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
default: goto do_clear;
}
- if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
+ CommandCost ret = EnsureNoVehicleOnGround(tile);
+ ret.SetGlobalErrorMessage();
+ if (ret.Failed()) return ret;
if (flags & DC_EXEC) {
Track railtrack = AxisToTrack(OtherAxis(roaddir));
@@ -627,7 +636,11 @@ do_clear:;
}
}
- if (!tile_cleared && !EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
+ if (!tile_cleared) {
+ CommandCost ret = EnsureNoVehicleOnGround(tile);
+ ret.SetGlobalErrorMessage();
+ if (ret.Failed()) return ret;
+ }
cost.AddCost(CountBits(pieces) * _price[PR_BUILD_ROAD]);
if (!tile_cleared && IsTileType(tile, MP_TUNNELBRIDGE)) {
@@ -900,7 +913,9 @@ static CommandCost RemoveRoadDepot(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) {
delete Depot::GetByTile(tile);
@@ -1358,7 +1373,7 @@ static void TileLoop_Road(TileIndex tile)
if (t->road_build_months != 0 &&
(DistanceManhattan(t->xy, tile) < 8 || grp != HZB_TOWN_EDGE) &&
IsNormalRoad(tile) && !HasAtMostOneBit(GetAllRoadBits(tile))) {
- if (GetFoundationSlope(tile, NULL) == SLOPE_FLAT && EnsureNoVehicleOnGround(tile) && Chance16(1, 40)) {
+ if (GetFoundationSlope(tile, NULL) == SLOPE_FLAT && EnsureNoVehicleOnGround(tile).Succeeded() && Chance16(1, 40)) {
StartRoadWorks(tile);
SndPlayTileFx(SND_21_JACKHAMMER, tile);
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index 51072e4c9..45fa5ce06 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -671,7 +671,9 @@ CommandCost CheckBuildableTile(TileIndex tile, uint invalid_dirs, int &allowed_z
return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
}
- if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
+ CommandCost ret = EnsureNoVehicleOnGround(tile);
+ ret.SetGlobalErrorMessage();
+ if (ret.Failed()) return ret;
uint z;
Slope tileh = GetTileSlope(tile, &z);
@@ -1362,7 +1364,11 @@ CommandCost RemoveFromRailBaseStation(TileArea ta, SmallVector<T *, 4> &affected
if (!HasStationTileRail(tile)) continue;
/* If there is a vehicle on ground, do not allow to remove (flood) the tile */
- if (!EnsureNoVehicleOnGround(tile)) continue;
+ CommandCost ret = EnsureNoVehicleOnGround(tile);
+ if (ret.Failed()) {
+ ret.SetGlobalErrorMessage();
+ continue;
+ }
/* Check ownership of station */
T *st = T::GetByTile(tile);
@@ -1526,7 +1532,9 @@ CommandCost RemoveRailStation(T *st, DoCommandFlag flags)
/* for nonuniform stations, only remove tiles that are actually train station tiles */
if (!st->TileBelongsToRailStation(tile)) continue;
- if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
+ CommandCost ret = EnsureNoVehicleOnGround(tile);
+ ret.SetGlobalErrorMessage();
+ if (ret.Failed()) return ret;
cost.AddCost(_price[PR_CLEAR_STATION_RAIL]);
if (flags & DC_EXEC) {
@@ -1832,7 +1840,9 @@ static CommandCost RemoveRoadStop(TileIndex tile, DoCommandFlag flags)
/* remove the 'going through road stop' status from all vehicles on that tile */
if (flags & DC_EXEC) FindVehicleOnPos(tile, NULL, &ClearRoadStopStatusEnum);
} else {
- if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
+ CommandCost ret = EnsureNoVehicleOnGround(tile);
+ ret.SetGlobalErrorMessage();
+ if (ret.Failed()) return ret;
}
if (flags & DC_EXEC) {
@@ -2234,7 +2244,9 @@ static CommandCost RemoveAirport(TileIndex tile, DoCommandFlag flags)
TILE_AREA_LOOP(tile_cur, st->airport) {
if (!st->TileBelongsToAirport(tile_cur)) continue;
- if (!EnsureNoVehicleOnGround(tile_cur)) return CMD_ERROR;
+ CommandCost ret = EnsureNoVehicleOnGround(tile);
+ ret.SetGlobalErrorMessage();
+ if (ret.Failed()) return ret;
cost.AddCost(_price[PR_CLEAR_STATION_AIRPORT]);
@@ -2432,8 +2444,10 @@ static CommandCost RemoveDock(TileIndex tile, DoCommandFlag flags)
TileIndex tile1 = st->dock_tile;
TileIndex tile2 = tile1 + TileOffsByDiagDir(GetDockDirection(tile1));
- if (!EnsureNoVehicleOnGround(tile1)) return CMD_ERROR;
- if (!EnsureNoVehicleOnGround(tile2)) return CMD_ERROR;
+ CommandCost ret = EnsureNoVehicleOnGround(tile1);
+ if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile2);
+ ret.SetGlobalErrorMessage();
+ if (ret.Failed()) return ret;
if (flags & DC_EXEC) {
DoClearSquare(tile1);
diff --git a/src/unmovable_cmd.cpp b/src/unmovable_cmd.cpp
index 55fe0a4c5..039a0162f 100644
--- a/src/unmovable_cmd.cpp
+++ b/src/unmovable_cmd.cpp
@@ -177,7 +177,9 @@ CommandCost CmdSellLandArea(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
if (!IsOwnedLandTile(tile)) return CMD_ERROR;
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) DoClearSquare(tile);
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index bba6a5219..05df6ad9f 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -408,9 +408,9 @@ static Vehicle *EnsureNoVehicleProcZ(Vehicle *v, void *data)
/* Ensure there is no vehicle at the ground at the given position.
* @param tile Position to examine.
- * @return A vehicle has been found.
+ * @return Succeeded command (ground is free) or failed command (a vehicle is found).
*/
-bool EnsureNoVehicleOnGround(TileIndex tile)
+CommandCost EnsureNoVehicleOnGround(TileIndex tile)
{
byte z = GetTileMaxZ(tile);
@@ -419,8 +419,8 @@ bool EnsureNoVehicleOnGround(TileIndex tile)
* Such a message does not affect MP synchronisation.
*/
Vehicle *v = VehicleFromPos(tile, &z, &EnsureNoVehicleProcZ, 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();
}
/** Procedure called for every vehicle found in tunnel/bridge in the hash map */
diff --git a/src/vehicle_func.h b/src/vehicle_func.h
index 82b465478..e1e2e2d55 100644
--- a/src/vehicle_func.h
+++ b/src/vehicle_func.h
@@ -156,7 +156,7 @@ static inline uint32 GetCmdSendToDepot(const BaseVehicle *v)
return GetCmdSendToDepot(v->type);
}
-bool EnsureNoVehicleOnGround(TileIndex tile);
+CommandCost EnsureNoVehicleOnGround(TileIndex tile);
void StopAllVehicles();
extern VehicleID _vehicle_id_ctr_day;
diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp
index 8074abe19..01c25157f 100644
--- a/src/water_cmd.cpp
+++ b/src/water_cmd.cpp
@@ -174,7 +174,10 @@ static CommandCost RemoveShipDepot(TileIndex tile, DoCommandFlag flags)
/* do not check for ship on tile when company goes bankrupt */
if (!(flags & DC_BANKRUPT)) {
- if (!EnsureNoVehicleOnGround(tile) || !EnsureNoVehicleOnGround(tile2)) return CMD_ERROR;
+ CommandCost ret = EnsureNoVehicleOnGround(tile);
+ if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile2);
+ ret.SetGlobalErrorMessage();
+ if (ret.Failed()) return ret;
}
if (flags & DC_EXEC) {
@@ -244,8 +247,11 @@ static CommandCost RemoveShiplift(TileIndex tile, DoCommandFlag flags)
if (!CheckTileOwnership(tile) && GetTileOwner(tile) != OWNER_NONE) return CMD_ERROR;
/* make sure no vehicle is on the tile. */
- if (!EnsureNoVehicleOnGround(tile) || !EnsureNoVehicleOnGround(tile + delta) || !EnsureNoVehicleOnGround(tile - delta))
- return CMD_ERROR;
+ CommandCost ret = EnsureNoVehicleOnGround(tile);
+ if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile + delta);
+ if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile - delta);
+ ret.SetGlobalErrorMessage();
+ if (ret.Failed()) return ret;
if (flags & DC_EXEC) {
DoClearSquare(tile);
@@ -341,7 +347,7 @@ CommandCost CmdBuildCanal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
static CommandCost ClearTile_Water(TileIndex tile, DoCommandFlag flags)
{
switch (GetWaterTileType(tile)) {
- case WATER_TILE_CLEAR:
+ case WATER_TILE_CLEAR: {
if (flags & DC_NO_WATER) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
/* Make sure freeform edges are allowed or it's not an edge tile. */
@@ -351,7 +357,9 @@ static CommandCost ClearTile_Water(TileIndex tile, DoCommandFlag flags)
}
/* Make sure no vehicle is on the tile */
- if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
+ CommandCost ret = EnsureNoVehicleOnGround(tile);
+ ret.SetGlobalErrorMessage();
+ if (ret.Failed()) return ret;
if (GetTileOwner(tile) != OWNER_WATER && GetTileOwner(tile) != OWNER_NONE && !CheckTileOwnership(tile)) return CMD_ERROR;
@@ -360,12 +368,15 @@ static CommandCost ClearTile_Water(TileIndex tile, DoCommandFlag flags)
MarkCanalsAndRiversAroundDirty(tile);
}
return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_WATER]);
+ }
case WATER_TILE_COAST: {
Slope slope = GetTileSlope(tile, NULL);
/* Make sure no vehicle is on the tile */
- if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
+ CommandCost ret = EnsureNoVehicleOnGround(tile);
+ ret.SetGlobalErrorMessage();
+ if (ret.Failed()) return ret;
if (flags & DC_EXEC) {
DoClearSquare(tile);
diff --git a/src/waypoint_cmd.cpp b/src/waypoint_cmd.cpp
index 413d7be66..7be4a6ce4 100644
--- a/src/waypoint_cmd.cpp
+++ b/src/waypoint_cmd.cpp
@@ -179,7 +179,10 @@ static CommandCost IsValidTileForWaypoint(TileIndex tile, Axis axis, StationID *
Owner owner = GetTileOwner(tile);
if (!CheckOwnership(owner)) return CMD_ERROR;
- if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
+
+ CommandCost ret = EnsureNoVehicleOnGround(tile);
+ ret.SetGlobalErrorMessage();
+ if (ret.Failed()) return ret;
Slope tileh = GetTileSlope(tile, NULL);
if (tileh != SLOPE_FLAT &&
@@ -390,7 +393,11 @@ CommandCost RemoveBuoy(TileIndex tile, DoCommandFlag flags)
if (HasStationInUse(wp->index, INVALID_COMPANY)) return_cmd_error(STR_ERROR_BUOY_IS_IN_USE);
/* remove the buoy if there is a ship on tile when company goes bankrupt... */
- if (!(flags & DC_BANKRUPT) && !EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
+ if (!(flags & DC_BANKRUPT)) {
+ CommandCost ret = EnsureNoVehicleOnGround(tile);
+ ret.SetGlobalErrorMessage();
+ if (ret.Failed()) return ret;
+ }
if (flags & DC_EXEC) {
wp->facilities &= ~FACIL_DOCK;