From 0461d896123b918b492a3d16439bb46b041528cd Mon Sep 17 00:00:00 2001 From: truelight Date: Tue, 22 Aug 2006 15:33:35 +0000 Subject: (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones -Codechange: use IsValidXXX where ever possible Note: both changes to prepare for new pool system, which needs those changes. For every pool there are 2 ugly lines, which will be removed when done implementing new pool system. Based on FS#13 by blathijs, partly implemented. --- station.h | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'station.h') diff --git a/station.h b/station.h index 6c2fb6d3a..c28e6d093 100644 --- a/station.h +++ b/station.h @@ -166,7 +166,15 @@ static inline bool IsStationIndex(StationID index) return index < GetStationPoolSize(); } -#define FOR_ALL_STATIONS_FROM(st, start) for (st = GetStation(start); st != NULL; st = (st->index + 1 < GetStationPoolSize()) ? GetStation(st->index + 1) : NULL) +/** + * Check if a station really exists. + */ +static inline bool IsValidStation(const Station *st) +{ + return st->xy != 0; +} + +#define FOR_ALL_STATIONS_FROM(st, start) for (st = GetStation(start); st != NULL; st = (st->index + 1 < GetStationPoolSize()) ? GetStation(st->index + 1) : NULL) if (IsValidStation(st)) #define FOR_ALL_STATIONS(st) FOR_ALL_STATIONS_FROM(st, 0) @@ -190,7 +198,15 @@ static inline uint16 GetRoadStopPoolSize(void) return _roadstop_pool.total_items; } -#define FOR_ALL_ROADSTOPS_FROM(rs, start) for (rs = GetRoadStop(start); rs != NULL; rs = (rs->index + 1 < GetRoadStopPoolSize()) ? GetRoadStop(rs->index + 1) : NULL) +/** + * Check if a RaodStop really exists. + */ +static inline bool IsValidRoadStop(const RoadStop *rs) +{ + return rs->used; +} + +#define FOR_ALL_ROADSTOPS_FROM(rs, start) for (rs = GetRoadStop(start); rs != NULL; rs = (rs->index + 1 < GetRoadStopPoolSize()) ? GetRoadStop(rs->index + 1) : NULL) if (IsValidRoadStop(rs)) #define FOR_ALL_ROADSTOPS(rs) FOR_ALL_ROADSTOPS_FROM(rs, 0) /* End of stuff for ROADSTOPS */ @@ -212,14 +228,6 @@ uint GetNumRoadStops(const Station* st, RoadStopType type); RoadStop * AllocateRoadStop( void ); void ClearSlot(Vehicle *v); -/** - * Check if a station really exists. - */ -static inline bool IsValidStation(const Station *st) -{ - return st->xy != 0; /* XXX: Replace by INVALID_TILE someday */ -} - static inline bool IsBuoy(const Station* st) { return (st->had_vehicle_of_type & HVOT_BUOY) != 0; /* XXX: We should really ditch this ugly coding and switch to something sane... */ -- cgit v1.2.3-54-g00ecf