# station_base.h

Go to the documentation of this file.

    00001 /* $Id: station_base.h 15635 2009-03-07 18:19:53Z rubidium $ */
    00002
    00005 #ifndef STATION_BASE_H
    00006 #define STATION_BASE_H
    00007
    00008 #include "station_type.h"
    00009 #include "airport.h"
    00010 #include "oldpool.h"
    00011 #include "cargopacket.h"
    00012 #include "cargo_type.h"
    00013 #include "town_type.h"
    00014 #include "strings_type.h"
    00015 #include "date_type.h"
    00016 #include "vehicle_type.h"
    00017 #include "company_type.h"
    00018 #include "industry_type.h"
    00019 #include "core/geometry_type.hpp"
    00020 #include "viewport_type.h"
    00021 #include <list>
    00022
    00023 DECLARE_OLD_POOL(Station, Station, 6, 1000)
    00024 DECLARE_OLD_POOL(RoadStop, RoadStop, 5, 2000)
    00025
    00026 static const byte INITIAL_STATION_RATING = 175;
    00027
    00028 struct GoodsEntry {
    00029   enum AcceptancePickup {
    00030     ACCEPTANCE,
    00031     PICKUP
    00032   };
    00033
    00034   GoodsEntry() :
    00035     acceptance_pickup(0),
    00036     days_since_pickup(255),
    00037     rating(INITIAL_STATION_RATING),
    00038     last_speed(0),
    00039     last_age(255)
    00040   {}
    00041
    00042   byte acceptance_pickup;
    00043   byte days_since_pickup;
    00044   byte rating;
    00045   byte last_speed;
    00046   byte last_age;
    00047   CargoList cargo;
    00048 };
    00049
    00051 struct RoadStop : PoolItem<RoadStop, RoadStopID, &_RoadStop_pool> {
    00052   static const int  cDebugCtorLevel =  5;
    00053   static const uint LIMIT           = 16;
    00054   static const uint MAX_BAY_COUNT   =  2;
    00055   static const uint MAX_VEHICLES    = 64;
    00056
    00057   TileIndex        xy;
    00058   byte             status;
    00059   byte             num_vehicles;
    00060   struct RoadStop  *next;
    00061
    00062   RoadStop(TileIndex tile = INVALID_TILE);
    00063   virtual ~RoadStop();
    00064
    00069   inline bool IsValid() const { return this->xy != INVALID_TILE; }
    00070
    00071   /* For accessing status */
    00072   bool HasFreeBay() const;
    00073   bool IsFreeBay(uint nr) const;
    00074   uint AllocateBay();
    00075   void AllocateDriveThroughBay(uint nr);
    00076   void FreeBay(uint nr);
    00077   bool IsEntranceBusy() const;
    00078   void SetEntranceBusy(bool busy);
    00079
    00080   RoadStop *GetNextRoadStop(const Vehicle *v) const;
    00081 };
    00082
    00083 struct StationSpecList {
    00084   const StationSpec *spec;
    00085   uint32 grfid;
    00086   uint8  localidx;
    00087 };
    00088
    00090 struct StationRect : public Rect {
    00091   enum StationRectMode
    00092   {
    00093     ADD_TEST = 0,
    00094     ADD_TRY,
    00095     ADD_FORCE
    00096   };
    00097
    00098   StationRect();
    00099   void MakeEmpty();
    00100   bool PtInExtendedRect(int x, int y, int distance = 0) const;
    00101   bool IsEmpty() const;
    00102   bool BeforeAddTile(TileIndex tile, StationRectMode mode);
    00103   bool BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode);
    00104   bool AfterRemoveTile(Station *st, TileIndex tile);
    00105   bool AfterRemoveRect(Station *st, TileIndex tile, int w, int h);
    00106
    00107   static bool ScanForStationTiles(StationID st_id, int left_a, int top_a, int right_a, int bottom_a);
    00108
    00109   StationRect& operator = (Rect src);
    00110 };
    00111
    00113 struct Station : PoolItem<Station, StationID, &_Station_pool> {
    00114 public:
    00115   RoadStop *GetPrimaryRoadStop(RoadStopType type) const
    00116   {
    00117     return type == ROADSTOP_BUS ? bus_stops : truck_stops;
    00118   }
    00119
    00120   RoadStop *GetPrimaryRoadStop(const Vehicle *v) const;
    00121
    00122   const AirportFTAClass *Airport() const
    00123   {
    00124     if (airport_tile == INVALID_TILE) return GetAirport(AT_DUMMY);
    00125     return GetAirport(airport_type);
    00126   }
    00127
    00128   TileIndex xy;
    00129   RoadStop *bus_stops;
    00130   RoadStop *truck_stops;
    00131   TileIndex train_tile;
    00132   TileIndex airport_tile;
    00133   TileIndex dock_tile;
    00134   Town *town;
    00135
    00136   /* Place to get a name from, in order of importance: */
    00137   char *name;
    00138   IndustryType indtype;
    00139   StringID string_id;
    00140
    00141   ViewportSign sign;
    00142
    00143   uint16 had_vehicle_of_type;
    00144
    00145   byte time_since_load;
    00146   byte time_since_unload;
    00147   byte delete_ctr;
    00148   OwnerByte owner;
    00149   byte facilities;
    00150   byte airport_type;
    00151
    00152   /* trainstation width/height */
    00153   byte trainst_w, trainst_h;
    00154
    00156   uint8 num_specs;
    00157   StationSpecList *speclist;
    00158
    00159   Date build_date;
    00160
    00161   uint64 airport_flags;
    00162
    00163   byte last_vehicle_type;
    00164   std::list<Vehicle *> loading_vehicles;
    00165   GoodsEntry goods[NUM_CARGO];
    00166
    00167   uint16 random_bits;
    00168   byte waiting_triggers;
    00169   uint8 cached_anim_triggers;
    00170
    00171   StationRect rect;
    00172
    00173   static const int cDebugCtorLevel = 5;
    00174
    00175   Station(TileIndex tile = INVALID_TILE);
    00176   virtual ~Station();
    00177
    00178   void AddFacility(byte new_facility_bit, TileIndex facil_xy);
    00179
    00185   void MarkDirty() const;
    00186
    00192   void MarkTilesDirty(bool cargo_change) const;
    00193   bool TileBelongsToRailStation(TileIndex tile) const;
    00194   uint GetPlatformLength(TileIndex tile, DiagDirection dir) const;
    00195   uint GetPlatformLength(TileIndex tile) const;
    00196   bool IsBuoy() const;
    00197
    00202   inline bool IsValid() const { return this->xy != INVALID_TILE; }
    00203
    00204   uint GetCatchmentRadius() const;
    00205 };
    00206
    00207 static inline StationID GetMaxStationIndex()
    00208 {
    00209   /* TODO - This isn't the real content of the function, but
    00210    *  with the new pool-system this will be replaced with one that
    00211    *  _really_ returns the highest index. Now it just returns
    00212    *  the next safe value we are sure about everything is below.
    00213    */
    00214   return GetStationPoolSize() - 1;
    00215 }
    00216
    00217 static inline uint GetNumStations()
    00218 {
    00219   return GetStationPoolSize();
    00220 }
    00221
    00222 static inline bool IsValidStationID(StationID index)
    00223 {
    00224   return index < GetStationPoolSize() && GetStation(index)->IsValid();
    00225 }
    00226
    00227 #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())
    00228 #define FOR_ALL_STATIONS(st) FOR_ALL_STATIONS_FROM(st, 0)
    00229
    00230
    00231 /* Stuff for ROADSTOPS */
    00232
    00233 #define FOR_ALL_ROADSTOPS_FROM(rs, start) for (rs = GetRoadStop(start); rs != NULL; rs = (rs->index + 1U < GetRoadStopPoolSize()) ? GetRoadStop(rs->index + 1U) : NULL) if (rs->IsValid())
    00234 #define FOR_ALL_ROADSTOPS(rs) FOR_ALL_ROADSTOPS_FROM(rs, 0)
    00235
    00236 /* End of stuff for ROADSTOPS */
    00237
    00238 #endif /* STATION_BASE_H */