summaryrefslogtreecommitdiff
path: root/station.h
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2006-08-22 15:33:35 +0000
committertruelight <truelight@openttd.org>2006-08-22 15:33:35 +0000
commit0461d896123b918b492a3d16439bb46b041528cd (patch)
tree618708068f10739a382af83313db9c96b4744ef5 /station.h
parent4c2abf1de53e28a5c3c6c6920efabc4653693c4c (diff)
downloadopenttd-0461d896123b918b492a3d16439bb46b041528cd.tar.xz
(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.
Diffstat (limited to 'station.h')
-rw-r--r--station.h28
1 files changed, 18 insertions, 10 deletions
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... */