summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcelestar <celestar@openttd.org>2007-02-13 15:42:52 +0000
committercelestar <celestar@openttd.org>2007-02-13 15:42:52 +0000
commit8eab3964b4ad7ebe0151aa292d42d74400214f4a (patch)
tree97f07e8c9bbb7b74d420386b638d4c6d8944d7a7
parent6f68ac46b8c603b23123b5d899afa6988836f497 (diff)
downloadopenttd-8eab3964b4ad7ebe0151aa292d42d74400214f4a.tar.xz
(svn r8707) -Codechange: Turn IsValidStation into a method of Station
-rw-r--r--src/aircraft_cmd.cpp4
-rw-r--r--src/oldloader.cpp2
-rw-r--r--src/station.cpp10
-rw-r--r--src/station.h13
-rw-r--r--src/station_cmd.cpp4
-rw-r--r--src/strings.cpp2
6 files changed, 18 insertions, 17 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index f3d990eaa..7ff79b500 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -558,7 +558,7 @@ int32 CmdSendAircraftToHangar(TileIndex tile, uint32 flags, uint32 p1, uint32 p2
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 @@ static void CheckIfAircraftNeedsService(Vehicle *v)
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 --git a/src/oldloader.cpp b/src/oldloader.cpp
index e88c37748..480ab4836 100644
--- a/src/oldloader.cpp
+++ b/src/oldloader.cpp
@@ -623,7 +623,7 @@ static bool LoadOldStation(LoadgameState *ls, int num)
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 --git a/src/station.cpp b/src/station.cpp
index 296a974fd..1f72df7ba 100644
--- a/src/station.cpp
+++ b/src/station.cpp
@@ -162,7 +162,7 @@ bool Station::TileBelongsToRailStation(TileIndex tile) const
/* 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 @@ bool Station::IsBuoy() const
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 --git a/src/station.h b/src/station.h
index 40d5297ef..38fcf058f 100644
--- a/src/station.h
+++ b/src/station.h
@@ -168,6 +168,7 @@ struct Station {
void MarkTilesDirty() const;
bool TileBelongsToRailStation(TileIndex tile) const;
bool IsBuoy() const;
+ bool IsValid() const;
protected:
static Station *AllocateRaw(void);
@@ -237,20 +238,12 @@ static inline uint GetNumStations(void)
return GetStationPoolSize();
}
-/**
- * Check if a station really exists.
- */
-static inline bool IsValidStation(const Station *st)
-{
- return st->xy != 0;
-}
-
static inline bool IsValidStationID(StationID index)
{
- return index < GetStationPoolSize() && IsValidStation(GetStation(index));
+ return index < GetStationPoolSize() && GetStation(index)->IsValid();
}
-#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 --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index ac597e27b..be67f3712 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -54,7 +54,7 @@ static void StationPoolCleanBlock(uint start_item, uint end_item)
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 @@ static Station *AllocateStation(void)
/* 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 --git a/src/strings.cpp b/src/strings.cpp
index 341cfa446..d794e9c97 100644
--- a/src/strings.cpp
+++ b/src/strings.cpp
@@ -802,7 +802,7 @@ static char* FormatString(char* buff, const char* str, const int32* argv, uint c
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];