changeset 5996:ce1790a98063 draft

(svn r8707) -Codechange: Turn IsValidStation into a method of Station
author celestar <celestar@openttd.org>
date Tue, 13 Feb 2007 15:42:52 +0000
parents c72b07427c7f
children 37c3b18068b6
files src/aircraft_cmd.cpp src/oldloader.cpp src/station.cpp src/station.h src/station_cmd.cpp src/strings.cpp
diffstat 6 files changed, 19 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -558,7 +558,7 @@
 		StationID next_airport_index = v->u.air.targetairport;
 		const Station *st = GetStation(next_airport_index);
 		/* If the station is not a valid airport or if it has no hangars */
-		if (!IsValidStation(st) || st->airport_tile == 0 || GetAirport(st->airport_type)->nof_depots == 0) {
+		if (!st->IsValid() || st->airport_tile == 0 || GetAirport(st->airport_type)->nof_depots == 0) {
 			StationID station;
 
 			// the aircraft has to search for a hangar on its own
@@ -695,7 +695,7 @@
 
 	st = GetStation(v->current_order.dest);
 	// only goto depot if the target airport has terminals (eg. it is airport)
-	if (IsValidStation(st) && st->airport_tile != 0 && GetAirport(st->airport_type)->terminals != NULL) {
+	if (st->IsValid() && st->airport_tile != 0 && GetAirport(st->airport_type)->terminals != NULL) {
 //		printf("targetairport = %d, st->index = %d\n", v->u.air.targetairport, st->index);
 //		v->u.air.targetairport = st->index;
 		v->current_order.type = OT_GOTO_DEPOT;
--- a/src/oldloader.cpp
+++ b/src/oldloader.cpp
@@ -623,7 +623,7 @@
 	if (!LoadChunk(ls, st, station_chunk))
 		return false;
 
-	if (IsValidStation(st)) {
+	if (st->IsValid()) {
 		if (st->train_tile) {
 			/* Calculate the trainst_w and trainst_h */
 			uint w = GB(_old_platforms, 3, 3);
--- a/src/station.cpp
+++ b/src/station.cpp
@@ -162,7 +162,7 @@
 	/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
 	 * TODO - This is just a temporary stage, this will be removed. */
 	for (st = GetStation(0); st != NULL; st = (st->index + 1U < GetStationPoolSize()) ? GetStation(st->index + 1U) : NULL) {
-		if (!IsValidStation(st)) {
+		if (!st->IsValid()) {
 			StationID index = st->index;
 
 			memset(st, 0, sizeof(Station));
@@ -187,6 +187,14 @@
 	return (this->had_vehicle_of_type & HVOT_BUOY) != 0;
 }
 
+/** Determines whether a station exists
+ * @todo replace 0 by INVALID_TILE
+ */
+bool Station::IsValid() const
+{
+	return xy != 0;
+}
+
 
 /************************************************************************/
 /*                     StationRect implementation                       */
--- a/src/station.h
+++ b/src/station.h
@@ -168,6 +168,7 @@
 	void MarkTilesDirty() const;
 	bool TileBelongsToRailStation(TileIndex tile) const;
 	bool IsBuoy() const;
+	bool IsValid() const;
 
 protected:
 	static Station *AllocateRaw(void);
@@ -237,20 +238,12 @@
 	return GetStationPoolSize();
 }
 
-/**
- * Check if a station really exists.
- */
-static inline bool IsValidStation(const Station *st)
+static inline bool IsValidStationID(StationID index)
 {
-	return st->xy != 0;
+	return index < GetStationPoolSize() && GetStation(index)->IsValid();
 }
 
-static inline bool IsValidStationID(StationID index)
-{
-	return index < GetStationPoolSize() && IsValidStation(GetStation(index));
-}
-
-#define FOR_ALL_STATIONS_FROM(st, start) for (st = GetStation(start); st != NULL; st = (st->index + 1U < GetStationPoolSize()) ? GetStation(st->index + 1U) : NULL) if (IsValidStation(st))
+#define FOR_ALL_STATIONS_FROM(st, start) for (st = GetStation(start); st != NULL; st = (st->index + 1U < GetStationPoolSize()) ? GetStation(st->index + 1U) : NULL) if (st->IsValid())
 #define FOR_ALL_STATIONS(st) FOR_ALL_STATIONS_FROM(st, 0)
 
 
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -54,7 +54,7 @@
 
 	for (i = start_item; i <= end_item; i++) {
 		Station *st = GetStation(i);
-		if (IsValidStation(st)) st->~Station();
+		if (st->IsValid()) st->~Station();
 	}
 }
 
@@ -167,7 +167,7 @@
 	/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
 	 * TODO - This is just a temporary stage, this will be removed. */
 	for (st = GetStation(0); st != NULL; st = (st->index + 1U < GetStationPoolSize()) ? GetStation(st->index + 1U) : NULL) {
-		if (!IsValidStation(st)) {
+		if (!st->IsValid()) {
 			StationID index = st->index;
 
 			memset(st, 0, sizeof(Station));
--- a/src/strings.cpp
+++ b/src/strings.cpp
@@ -802,7 +802,7 @@
 			case SCC_STATION_NAME: { // {STATION}
 				const Station* st = GetStation(GetInt32(&argv));
 
-				if (!IsValidStation(st)) { // station doesn't exist anymore
+				if (!st->IsValid()) { // station doesn't exist anymore
 					buff = GetStringWithArgs(buff, STR_UNKNOWN_DESTINATION, NULL, last);
 				} else {
 					int32 temp[2];