base_station_base.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef BASE_STATION_BASE_H
00013 #define BASE_STATION_BASE_H
00014
00015 #include "station_type.h"
00016 #include "core/pool_type.hpp"
00017 #include "town_type.h"
00018 #include "strings_type.h"
00019 #include "date_type.h"
00020 #include "company_type.h"
00021 #include "viewport_type.h"
00022 #include "station_map.h"
00023
00024 typedef Pool<BaseStation, StationID, 32, 64000> StationPool;
00025 extern StationPool _station_pool;
00026
00027 struct StationSpecList {
00028 const StationSpec *spec;
00029 uint32 grfid;
00030 uint8 localidx;
00031 };
00032
00033
00035 struct StationRect : public Rect {
00036 enum StationRectMode
00037 {
00038 ADD_TEST = 0,
00039 ADD_TRY,
00040 ADD_FORCE
00041 };
00042
00043 StationRect();
00044 void MakeEmpty();
00045 bool PtInExtendedRect(int x, int y, int distance = 0) const;
00046 bool IsEmpty() const;
00047 bool BeforeAddTile(TileIndex tile, StationRectMode mode);
00048 bool BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode);
00049 bool AfterRemoveTile(BaseStation *st, TileIndex tile);
00050 bool AfterRemoveRect(BaseStation *st, TileIndex tile, int w, int h);
00051
00052 static bool ScanForStationTiles(StationID st_id, int left_a, int top_a, int right_a, int bottom_a);
00053
00054 StationRect& operator = (Rect src);
00055 };
00056
00058 struct BaseStation : StationPool::PoolItem<&_station_pool> {
00059 TileIndex xy;
00060 ViewportSign sign;
00061 byte delete_ctr;
00062
00063 char *name;
00064 StringID string_id;
00065
00066 Town *town;
00067 OwnerByte owner;
00068 StationFacilityByte facilities;
00069
00070 uint8 num_specs;
00071 StationSpecList *speclist;
00072
00073 Date build_date;
00074
00075 uint16 random_bits;
00076 byte waiting_triggers;
00077 uint8 cached_anim_triggers;
00078
00079 TileArea train_station;
00080 StationRect rect;
00081
00086 BaseStation(TileIndex tile) :
00087 xy(tile),
00088 train_station(INVALID_TILE, 0, 0)
00089 {
00090 }
00091
00092 virtual ~BaseStation();
00093
00099 virtual bool TileBelongsToRailStation(TileIndex tile) const = 0;
00100
00109 virtual uint32 GetNewGRFVariable(const struct ResolverObject *object, byte variable, byte parameter, bool *available) const = 0;
00110
00114 virtual void UpdateVirtCoord() = 0;
00115
00121 virtual void GetTileArea(TileArea *ta, StationType type) const = 0;
00122
00123
00130 virtual uint GetPlatformLength(TileIndex tile) const = 0;
00131
00139 virtual uint GetPlatformLength(TileIndex tile, DiagDirection dir) const = 0;
00140
00146 static FORCEINLINE BaseStation *GetByTile(TileIndex tile)
00147 {
00148 return BaseStation::Get(GetStationIndex(tile));
00149 }
00150
00157 FORCEINLINE bool IsInUse() const
00158 {
00159 return (this->facilities & ~FACIL_WAYPOINT) != 0;
00160 }
00161
00162 static void PostDestructor(size_t index);
00163 };
00164
00165 #define FOR_ALL_BASE_STATIONS(var) FOR_ALL_ITEMS_FROM(BaseStation, station_index, var, 0)
00166
00171 template <class T, bool Tis_waypoint>
00172 struct SpecializedStation : public BaseStation {
00173 static const StationFacility EXPECTED_FACIL = Tis_waypoint ? FACIL_WAYPOINT : FACIL_NONE;
00174
00179 FORCEINLINE SpecializedStation<T, Tis_waypoint>(TileIndex tile) :
00180 BaseStation(tile)
00181 {
00182 this->facilities = EXPECTED_FACIL;
00183 }
00184
00190 static FORCEINLINE bool IsExpected(const BaseStation *st)
00191 {
00192 return (st->facilities & FACIL_WAYPOINT) == EXPECTED_FACIL;
00193 }
00194
00200 static FORCEINLINE bool IsValidID(size_t index)
00201 {
00202 return BaseStation::IsValidID(index) && IsExpected(BaseStation::Get(index));
00203 }
00204
00209 static FORCEINLINE T *Get(size_t index)
00210 {
00211 return (T *)BaseStation::Get(index);
00212 }
00213
00218 static FORCEINLINE T *GetIfValid(size_t index)
00219 {
00220 return IsValidID(index) ? Get(index) : NULL;
00221 }
00222
00228 static FORCEINLINE T *GetByTile(TileIndex tile)
00229 {
00230 return GetIfValid(GetStationIndex(tile));
00231 }
00232
00238 static FORCEINLINE T *From(BaseStation *st)
00239 {
00240 assert(IsExpected(st));
00241 return (T *)st;
00242 }
00243
00249 static FORCEINLINE const T *From(const BaseStation *st)
00250 {
00251 assert(IsExpected(st));
00252 return (const T *)st;
00253 }
00254 };
00255
00256 #define FOR_ALL_BASE_STATIONS_OF_TYPE(name, var) FOR_ALL_ITEMS_FROM(name, station_index, var, 0) if (name::IsExpected(var))
00257
00258 #endif