diff options
author | alberth <alberth@openttd.org> | 2010-03-07 15:54:58 +0000 |
---|---|---|
committer | alberth <alberth@openttd.org> | 2010-03-07 15:54:58 +0000 |
commit | 29b79e03e80f0e57f9af5ec4eeedc6de205f201b (patch) | |
tree | 5b37b2a70727b65ca2d7dd5be9c87c7aa57f01ef /src | |
parent | 58012c6e6bde1dc6d480d928de24773f75957938 (diff) | |
download | openttd-29b79e03e80f0e57f9af5ec4eeedc6de205f201b.tar.xz |
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
Diffstat (limited to 'src')
-rw-r--r-- | src/rail.h | 1 | ||||
-rw-r--r-- | src/rail_cmd.cpp | 20 | ||||
-rw-r--r-- | src/signal.cpp | 2 | ||||
-rw-r--r-- | src/vehicle.cpp | 25 | ||||
-rw-r--r-- | src/vehicle_func.h | 2 |
5 files changed, 31 insertions, 19 deletions
diff --git a/src/rail.h b/src/rail.h index aaa592da9..68efa0121 100644 --- a/src/rail.h +++ b/src/rail.h @@ -300,7 +300,6 @@ static inline Money RailConvertCost(RailType from, RailType to) } void DrawTrainDepotSprite(int x, int y, int image, RailType railtype); -Vehicle *EnsureNoTrainOnTrackProc(Vehicle *v, void *data); int TicksToLeaveDepot(const Train *v); Foundation GetRailFoundation(Slope tileh, TrackBits bits); diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index 439d33b3b..19c044e31 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -144,32 +144,18 @@ static const byte _track_sloped_sprites[14] = { * 11uuuudd => rail depot */ - -Vehicle *EnsureNoTrainOnTrackProc(Vehicle *v, void *data) -{ - TrackBits rail_bits = *(TrackBits *)data; - - if (v->type != VEH_TRAIN) return NULL; - - Train *t = Train::From(v); - if ((t->track != rail_bits) && !TracksOverlap(t->track | rail_bits)) return NULL; - - _error_message = STR_ERROR_TRAIN_IN_THE_WAY + v->type; - return v; -} - /** * Tests if a vehicle interacts with the specified track. - * All track bits interact except parallel TRACK_BIT_HORZ or TRACK_BIT_VERT. + * All track bits interact except parallel #TRACK_BIT_HORZ or #TRACK_BIT_VERT. * * @param tile The tile. * @param track The track. + * @return \c true if no train that interacts, is found. \c false if a train is found. */ static bool EnsureNoTrainOnTrack(TileIndex tile, Track track) { TrackBits rail_bits = TrackToTrackBits(track); - - return !HasVehicleOnPos(tile, &rail_bits, &EnsureNoTrainOnTrackProc); + return EnsureNoTrainOnTrackBits(tile, rail_bits); } /** Check that the new track bits may be built. diff --git a/src/signal.cpp b/src/signal.cpp index 2eeef336c..778e19c0e 100644 --- a/src/signal.cpp +++ b/src/signal.cpp @@ -301,7 +301,7 @@ 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) && HasVehicleOnPos(tile, &tracks, &EnsureNoTrainOnTrackProc)) flags |= SF_TRAIN; + if (!(flags & SF_TRAIN) && !EnsureNoTrainOnTrackBits(tile, tracks)) 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 05df6ad9f..440f59bf8 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -452,6 +452,31 @@ CommandCost TunnelBridgeIsFree(TileIndex tile, TileIndex endtile, const Vehicle return CommandCost(); } +static Vehicle *EnsureNoTrainOnTrackProc(Vehicle *v, void *data) +{ + TrackBits rail_bits = *(TrackBits *)data; + + if (v->type != VEH_TRAIN) return NULL; + + Train *t = Train::From(v); + if ((t->track != rail_bits) && !TracksOverlap(t->track | rail_bits)) return NULL; + + _error_message = STR_ERROR_TRAIN_IN_THE_WAY + v->type; + return v; +} + +/** + * Tests if a vehicle interacts with the specified track bits. + * All track bits interact except parallel #TRACK_BIT_HORZ or #TRACK_BIT_VERT. + * + * @param tile The tile. + * @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) +{ + return !HasVehicleOnPos(tile, &track_bits, &EnsureNoTrainOnTrackProc); +} static void UpdateNewVehiclePosHash(Vehicle *v, bool remove) { diff --git a/src/vehicle_func.h b/src/vehicle_func.h index e1e2e2d55..ed9f16e65 100644 --- a/src/vehicle_func.h +++ b/src/vehicle_func.h @@ -20,6 +20,7 @@ #include "transport_type.h" #include "newgrf_config.h" #include "company_type.h" +#include "track_type.h" #define is_custom_sprite(x) (x >= 0xFD) #define IS_CUSTOM_FIRSTHEAD_SPRITE(x) (x == 0xFD) @@ -157,6 +158,7 @@ static inline uint32 GetCmdSendToDepot(const BaseVehicle *v) } CommandCost EnsureNoVehicleOnGround(TileIndex tile); +bool EnsureNoTrainOnTrackBits(TileIndex tile, TrackBits track_bits); void StopAllVehicles(); extern VehicleID _vehicle_id_ctr_day; |