# HG changeset patch # User celestar # Date 1171381372 0 # Node ID 3d191e6e89bc31c20da1253f9d8f852b3d7250e8 # Parent 62564548351b9c45379d29783a2312a943ad71e7 (svn r8707) -Codechange: Turn IsValidStation into a method of Station diff -r 62564548351b -r 3d191e6e89bc src/aircraft_cmd.cpp --- a/src/aircraft_cmd.cpp Tue Feb 13 12:34:54 2007 +0000 +++ b/src/aircraft_cmd.cpp Tue Feb 13 15:42:52 2007 +0000 @@ -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; diff -r 62564548351b -r 3d191e6e89bc src/oldloader.cpp --- a/src/oldloader.cpp Tue Feb 13 12:34:54 2007 +0000 +++ b/src/oldloader.cpp Tue Feb 13 15:42:52 2007 +0000 @@ -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); diff -r 62564548351b -r 3d191e6e89bc src/station.cpp --- a/src/station.cpp Tue Feb 13 12:34:54 2007 +0000 +++ b/src/station.cpp Tue Feb 13 15:42:52 2007 +0000 @@ -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 */ diff -r 62564548351b -r 3d191e6e89bc src/station.h --- a/src/station.h Tue Feb 13 12:34:54 2007 +0000 +++ b/src/station.h Tue Feb 13 15:42:52 2007 +0000 @@ -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) diff -r 62564548351b -r 3d191e6e89bc src/station_cmd.cpp --- a/src/station_cmd.cpp Tue Feb 13 12:34:54 2007 +0000 +++ b/src/station_cmd.cpp Tue Feb 13 15:42:52 2007 +0000 @@ -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)); diff -r 62564548351b -r 3d191e6e89bc src/strings.cpp --- a/src/strings.cpp Tue Feb 13 12:34:54 2007 +0000 +++ b/src/strings.cpp Tue Feb 13 15:42:52 2007 +0000 @@ -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];