summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2010-03-07 18:24:41 +0000
committeralberth <alberth@openttd.org>2010-03-07 18:24:41 +0000
commit55f8d5d80234bbeb7668c6d3263687185cd263d9 (patch)
tree8dfcf7d8ca049547e39e95a32edd6be55fbfd834
parentf0de6366bac6857a85fe1677fb6703b8be187be4 (diff)
downloadopenttd-55f8d5d80234bbeb7668c6d3263687185cd263d9.tar.xz
(svn r19369) -Codechange: EnsureNoTrainOnTrackBits() returns a CommandCost now.
-rw-r--r--src/rail_cmd.cpp4
-rw-r--r--src/signal.cpp3
-rw-r--r--src/vehicle.cpp6
-rw-r--r--src/vehicle_func.h2
4 files changed, 9 insertions, 6 deletions
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index 19c044e31..7bab2a254 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -155,7 +155,9 @@ static const byte _track_sloped_sprites[14] = {
static bool EnsureNoTrainOnTrack(TileIndex tile, Track track)
{
TrackBits rail_bits = TrackToTrackBits(track);
- return EnsureNoTrainOnTrackBits(tile, rail_bits);
+ CommandCost ret = EnsureNoTrainOnTrackBits(tile, rail_bits);
+ ret.SetGlobalErrorMessage();
+ return ret.Succeeded();
}
/** Check that the new track bits may be built.
diff --git a/src/signal.cpp b/src/signal.cpp
index 778e19c0e..cdcde264e 100644
--- a/src/signal.cpp
+++ b/src/signal.cpp
@@ -301,7 +301,8 @@ static SigFlags ExploreSegment(Owner owner)
if (tracks == TRACK_BIT_HORZ || tracks == TRACK_BIT_VERT) { // there is exactly one incidating track, no need to check
tracks = tracks_masked;
- if (!(flags & SF_TRAIN) && !EnsureNoTrainOnTrackBits(tile, tracks)) flags |= SF_TRAIN;
+ /* If no train detected yet, and there is not no train -> there is a train -> set the flag */
+ if (!(flags & SF_TRAIN) && EnsureNoTrainOnTrackBits(tile, tracks).Failed()) flags |= SF_TRAIN;
} else {
if (tracks_masked == TRACK_BIT_NONE) continue; // no incidating track
if (!(flags & SF_TRAIN) && HasVehicleOnPos(tile, NULL, &TrainOnTileEnum)) flags |= SF_TRAIN;
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 312813c36..44e3991ff 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -472,15 +472,15 @@ static Vehicle *EnsureNoTrainOnTrackProc(Vehicle *v, void *data)
* @param track_bits The track bits.
* @return \c true if no train that interacts, is found. \c false if a train is found.
*/
-bool EnsureNoTrainOnTrackBits(TileIndex tile, TrackBits track_bits)
+CommandCost EnsureNoTrainOnTrackBits(TileIndex tile, TrackBits track_bits)
{
/* 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).
* Such a message does not affect MP synchronisation.
*/
Vehicle *v = VehicleFromPos(tile, &track_bits, &EnsureNoTrainOnTrackProc, 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();
}
static void UpdateNewVehiclePosHash(Vehicle *v, bool remove)
diff --git a/src/vehicle_func.h b/src/vehicle_func.h
index ed9f16e65..a0b976ef4 100644
--- a/src/vehicle_func.h
+++ b/src/vehicle_func.h
@@ -158,7 +158,7 @@ static inline uint32 GetCmdSendToDepot(const BaseVehicle *v)
}
CommandCost EnsureNoVehicleOnGround(TileIndex tile);
-bool EnsureNoTrainOnTrackBits(TileIndex tile, TrackBits track_bits);
+CommandCost EnsureNoTrainOnTrackBits(TileIndex tile, TrackBits track_bits);
void StopAllVehicles();
extern VehicleID _vehicle_id_ctr_day;