(svn r19369) -Codechange: EnsureNoTrainOnTrackBits() returns a CommandCost now.

This commit is contained in:
alberth 2010-03-07 18:24:41 +00:00
parent f0de6366ba
commit 55f8d5d802
4 changed files with 9 additions and 6 deletions

View File

@ -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.

View File

@ -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;

View File

@ -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)

View File

@ -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;