station_base.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef STATION_BASE_H
00013 #define STATION_BASE_H
00014
00015 #include "base_station_base.h"
00016 #include "newgrf_airport.h"
00017 #include "cargopacket.h"
00018 #include "industry_type.h"
00019 #include "newgrf_storage.h"
00020 #include "cargodest_type.h"
00021
00022 typedef Pool<BaseStation, StationID, 32, 64000> StationPool;
00023 extern StationPool _station_pool;
00024
00025 static const byte INITIAL_STATION_RATING = 175;
00026
00028 typedef std::list<RouteLink *> RouteLinkList;
00029
00030 struct GoodsEntry {
00031 enum AcceptancePickup {
00032 ACCEPTANCE,
00033 PICKUP
00034 };
00035
00036 GoodsEntry() :
00037 acceptance_pickup(0),
00038 days_since_pickup(255),
00039 rating(INITIAL_STATION_RATING),
00040 last_speed(0),
00041 last_age(255),
00042 cargo_counter(0)
00043 {}
00044
00045 byte acceptance_pickup;
00046 byte days_since_pickup;
00047 byte rating;
00048 byte last_speed;
00049 byte last_age;
00050 byte amount_fract;
00051 uint16 cargo_counter;
00052 StationCargoList cargo;
00053 RouteLinkList routes;
00054 };
00055
00057 struct Airport : public TileArea {
00058 typedef PersistentStorageArray<int32, 16> PersistentStorage;
00059
00060 Airport() : TileArea(INVALID_TILE, 0, 0) {}
00061
00062 uint64 flags;
00063 byte type;
00064 byte layout;
00065 Direction rotation;
00066 PersistentStorage psa;
00067
00073 const AirportSpec *GetSpec() const
00074 {
00075 if (this->tile == INVALID_TILE) return &AirportSpec::dummy;
00076 return AirportSpec::Get(this->type);
00077 }
00078
00085 const AirportFTAClass *GetFTA() const
00086 {
00087 return this->GetSpec()->fsm;
00088 }
00089
00091 FORCEINLINE bool HasHangar() const
00092 {
00093 return this->GetSpec()->nof_depots > 0;
00094 }
00095
00104 FORCEINLINE TileIndex GetRotatedTileFromOffset(TileIndexDiffC tidc) const
00105 {
00106 const AirportSpec *as = this->GetSpec();
00107 switch (this->rotation) {
00108 case DIR_N: return this->tile + ToTileIndexDiff(tidc);
00109
00110 case DIR_E: return this->tile + TileDiffXY(tidc.y, as->size_x - 1 - tidc.x);
00111
00112 case DIR_S: return this->tile + TileDiffXY(as->size_x - 1 - tidc.x, as->size_y - 1 - tidc.y);
00113
00114 case DIR_W: return this->tile + TileDiffXY(as->size_y - 1 - tidc.y, tidc.x);
00115
00116 default: NOT_REACHED();
00117 }
00118 }
00119
00126 FORCEINLINE TileIndex GetHangarTile(uint hangar_num) const
00127 {
00128 const AirportSpec *as = this->GetSpec();
00129 for (uint i = 0; i < as->nof_depots; i++) {
00130 if (as->depot_table[i].hangar_num == hangar_num) {
00131 return this->GetRotatedTileFromOffset(as->depot_table[i].ti);
00132 }
00133 }
00134 NOT_REACHED();
00135 }
00136
00143 FORCEINLINE uint GetHangarNum(TileIndex tile) const
00144 {
00145 const AirportSpec *as = this->GetSpec();
00146 for (uint i = 0; i < as->nof_depots; i++) {
00147 if (this->GetRotatedTileFromOffset(as->depot_table[i].ti) == tile) {
00148 return as->depot_table[i].hangar_num;
00149 }
00150 }
00151 NOT_REACHED();
00152 }
00153
00155 FORCEINLINE uint GetNumHangars() const
00156 {
00157 uint num = 0;
00158 uint counted = 0;
00159 const AirportSpec *as = this->GetSpec();
00160 for (uint i = 0; i < as->nof_depots; i++) {
00161 if (!HasBit(counted, as->depot_table[i].hangar_num)) {
00162 num++;
00163 SetBit(counted, as->depot_table[i].hangar_num);
00164 }
00165 }
00166 return num;
00167 }
00168 };
00169
00170 typedef SmallVector<Industry *, 2> IndustryVector;
00171
00173 struct Station : SpecializedStation<Station, false> {
00174 public:
00175 RoadStop *GetPrimaryRoadStop(RoadStopType type) const
00176 {
00177 return type == ROADSTOP_BUS ? bus_stops : truck_stops;
00178 }
00179
00180 RoadStop *GetPrimaryRoadStop(const struct RoadVehicle *v) const;
00181
00182 RoadStop *bus_stops;
00183 TileArea bus_station;
00184 RoadStop *truck_stops;
00185 TileArea truck_station;
00186
00187 Airport airport;
00188 TileIndex dock_tile;
00189
00190 IndustryType indtype;
00191
00192 StationHadVehicleOfTypeByte had_vehicle_of_type;
00193
00194 byte time_since_load;
00195 byte time_since_unload;
00196
00197 byte last_vehicle_type;
00198 std::list<Vehicle *> loading_vehicles;
00199 GoodsEntry goods[NUM_CARGO];
00200 uint32 always_accepted;
00201
00202 IndustryVector industries_near;
00203
00204 Station(TileIndex tile = INVALID_TILE);
00205 ~Station();
00206
00207 void AddFacility(StationFacility new_facility_bit, TileIndex facil_xy);
00208
00209 void MarkTilesDirty(bool cargo_change) const;
00210
00211 void UpdateVirtCoord();
00212
00213 uint GetPlatformLength(TileIndex tile, DiagDirection dir) const;
00214 uint GetPlatformLength(TileIndex tile) const;
00215 void RecomputeIndustriesNear();
00216 static void RecomputeIndustriesNearForAll();
00217
00218 uint GetCatchmentRadius() const;
00219 Rect GetCatchmentRect() const;
00220
00221 FORCEINLINE bool TileBelongsToRailStation(TileIndex tile) const
00222 {
00223 return IsRailStationTile(tile) && GetStationIndex(tile) == this->index;
00224 }
00225
00226 FORCEINLINE bool TileBelongsToAirport(TileIndex tile) const
00227 {
00228 return IsAirportTile(tile) && GetStationIndex(tile) == this->index;
00229 }
00230
00231 uint32 GetNewGRFVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) const;
00232
00233 void GetTileArea(TileArea *ta, StationType type) const;
00234 };
00235
00236 #define FOR_ALL_STATIONS(var) FOR_ALL_BASE_STATIONS_OF_TYPE(Station, var)
00237
00238 #endif