summaryrefslogtreecommitdiff
path: root/src/station_base.h
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-07-17 19:44:13 +0000
committerrubidium <rubidium@openttd.org>2009-07-17 19:44:13 +0000
commit84df3ba2b40054b751fd9d39c3a9b3a7589422b8 (patch)
tree81e3445d33e5b22e9d220819eeb5ab0e608495a2 /src/station_base.h
parent869fb4fa788aae6369030a14ff083b524ebb36f5 (diff)
downloadopenttd-84df3ba2b40054b751fd9d39c3a9b3a7589422b8.tar.xz
(svn r16859) -Codechange: split the Station struct into two so parts of it can be reused for Waypoints.
Diffstat (limited to 'src/station_base.h')
-rw-r--r--src/station_base.h75
1 files changed, 57 insertions, 18 deletions
diff --git a/src/station_base.h b/src/station_base.h
index 1af0a067a..821ed1dd6 100644
--- a/src/station_base.h
+++ b/src/station_base.h
@@ -77,10 +77,53 @@ struct StationRect : public Rect {
StationRect& operator = (Rect src);
};
+/** Base class for all station-ish types */
+struct BaseStation {
+ char *name; ///< Custom name
+ StringID string_id; ///< Default name (town area) of station
+
+ Town *town; ///< The town this station is associated with
+ OwnerByte owner; ///< The owner of this station
+ StationFacilityByte facilities; ///< The facilities that this station has
+
+ uint8 num_specs; ///< NOSAVE: Number of specs in the speclist
+ StationSpecList *speclist; ///< NOSAVE: List of station specs of this station
+
+ Date build_date; ///< Date of construction
+
+ uint16 random_bits; ///< Random bits assigned to this station
+ byte waiting_triggers; ///< Waiting triggers (NewGRF) for this station
+ uint8 cached_anim_triggers; ///< NOSAVE: Combined animation trigger bitmask, used to determine if trigger processing should happen.
+
+ /**
+ * Check whether a specific tile belongs to this station.
+ * @param tile the tile to check
+ * @return true if the tile belongs to this station
+ */
+ virtual bool TileBelongsToRailStation(TileIndex tile) const = 0;
+
+ /**
+ * Helper function to get a NewGRF variable that isn't implemented by the base class.
+ * @param object the resolver object related to this query
+ * @param variable that is queried
+ * @param parameter parameter for that variable
+ * @param available will return false if ever the variable asked for does not exist
+ * @return the value stored in the corresponding variable
+ */
+ virtual uint32 GetNewGRFVariable(const struct ResolverObject *object, byte variable, byte parameter, bool *available) const = 0;
+
+ /**
+ * Get the base station belonging to a specific tile.
+ * @param tile The tile to get the base station from.
+ * @return the station associated with that tile.
+ */
+ static BaseStation *GetByTile(TileIndex tile);
+};
+
typedef SmallVector<Industry *, 2> IndustryVector;
/** Station data structure */
-struct Station : StationPool::PoolItem<&_station_pool> {
+struct Station : StationPool::PoolItem<&_station_pool>, BaseStation {
public:
RoadStop *GetPrimaryRoadStop(RoadStopType type) const
{
@@ -101,12 +144,8 @@ public:
TileIndex train_tile;
TileIndex airport_tile;
TileIndex dock_tile;
- Town *town;
- /* Place to get a name from, in order of importance: */
- char *name; ///< Custom name
IndustryType indtype; ///< Industry type to get the name from
- StringID string_id; ///< Default name (town area) of station
ViewportSign sign;
@@ -115,19 +154,11 @@ public:
byte time_since_load;
byte time_since_unload;
byte delete_ctr;
- OwnerByte owner;
- StationFacilityByte facilities;
byte airport_type;
/* trainstation width/height */
byte trainst_w, trainst_h;
- /** List of custom stations (StationSpecs) allocated to the station */
- uint8 num_specs;
- StationSpecList *speclist;
-
- Date build_date; ///< Date of construction
-
uint64 airport_flags; ///< stores which blocks on the airport are taken. was 16 bit earlier on, then 32
byte last_vehicle_type;
@@ -136,10 +167,6 @@ public:
IndustryVector industries_near; ///< Cached list of industries near the station that can accept cargo, @see DeliverGoodsToIndustry()
- uint16 random_bits;
- byte waiting_triggers;
- uint8 cached_anim_triggers; ///< Combined animation trigger bitmask, used to determine if trigger processing should happen.
-
StationRect rect; ///< Station spread out rectangle (not saved) maintained by StationRect_xxx() functions
Station(TileIndex tile = INVALID_TILE);
@@ -163,11 +190,13 @@ public:
uint GetCatchmentRadius() const;
- FORCEINLINE bool TileBelongsToRailStation(TileIndex tile) const
+ /* virtual */ FORCEINLINE bool TileBelongsToRailStation(TileIndex tile) const
{
return IsRailwayStationTile(tile) && GetStationIndex(tile) == this->index;
}
+ /* virtual */ uint32 GetNewGRFVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) const;
+
/**
* Determines whether a station is a buoy only.
* @todo Ditch this encoding of buoys
@@ -183,6 +212,16 @@ public:
}
static void PostDestructor(size_t index);
+
+ static FORCEINLINE Station *From(BaseStation *st)
+ {
+ return (Station *)st;
+ }
+
+ static FORCEINLINE const Station *From(const BaseStation *st)
+ {
+ return (const Station *)st;
+ }
};
#define FOR_ALL_STATIONS_FROM(var, start) FOR_ALL_ITEMS_FROM(Station, station_index, var, start)