station.h

Go to the documentation of this file.
00001 /* $Id: station.h 12154 2008-02-15 23:57:03Z glx $ */
00002 
00005 #ifndef STATION_H
00006 #define STATION_H
00007 
00008 #include "airport.h"
00009 #include "oldpool.h"
00010 #include "sprite.h"
00011 #include "road_type.h"
00012 #include "newgrf_station.h"
00013 #include "cargopacket.h"
00014 #include "cargo_type.h"
00015 #include "town_type.h"
00016 #include "core/geometry_type.hpp"
00017 #include <list>
00018 #include <set>
00019 
00020 struct Station;
00021 struct RoadStop;
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> {
00053   enum Type {
00054     BUS,                                
00055     TRUCK                               
00056   };
00057 
00058   static const int  cDebugCtorLevel =  5;  
00059   static const uint LIMIT           = 16;  
00060   static const uint MAX_BAY_COUNT   =  2;  
00061 
00062   TileIndex        xy;                    
00063   byte             status;                
00064   byte             num_vehicles;          
00065   struct RoadStop  *next;                 
00066 
00067   RoadStop(TileIndex tile = 0);
00068   virtual ~RoadStop();
00069 
00074   inline bool IsValid() const { return this->xy != 0; }
00075 
00076   /* For accessing status */
00077   bool HasFreeBay() const;
00078   bool IsFreeBay(uint nr) const;
00079   uint AllocateBay();
00080   void AllocateDriveThroughBay(uint nr);
00081   void FreeBay(uint nr);
00082   bool IsEntranceBusy() const;
00083   void SetEntranceBusy(bool busy);
00084 
00085   RoadStop *GetNextRoadStop(const Vehicle *v) const;
00086 };
00087 
00088 struct StationSpecList {
00089   const StationSpec *spec;
00090   uint32 grfid;      
00091   uint8  localidx;   
00092 };
00093 
00095 struct StationRect : public Rect {
00096   enum StationRectMode
00097   {
00098     ADD_TEST = 0,
00099     ADD_TRY,
00100     ADD_FORCE
00101   };
00102 
00103   StationRect();
00104   void MakeEmpty();
00105   bool PtInExtendedRect(int x, int y, int distance = 0) const;
00106   bool IsEmpty() const;
00107   bool BeforeAddTile(TileIndex tile, StationRectMode mode);
00108   bool BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode);
00109   bool AfterRemoveTile(Station *st, TileIndex tile);
00110   bool AfterRemoveRect(Station *st, TileIndex tile, int w, int h);
00111 
00112   static bool ScanForStationTiles(StationID st_id, int left_a, int top_a, int right_a, int bottom_a);
00113 
00114   StationRect& operator = (Rect src);
00115 };
00116 
00117 struct Station : PoolItem<Station, StationID, &_Station_pool> {
00118 public:
00119   RoadStop *GetPrimaryRoadStop(RoadStop::Type type) const
00120   {
00121     return type == RoadStop::BUS ? bus_stops : truck_stops;
00122   }
00123 
00124   RoadStop *GetPrimaryRoadStop(const Vehicle *v) const;
00125 
00126   const AirportFTAClass *Airport() const
00127   {
00128     if (airport_tile == 0) return GetAirport(AT_DUMMY);
00129     return GetAirport(airport_type);
00130   }
00131 
00132   TileIndex xy;
00133   RoadStop *bus_stops;
00134   RoadStop *truck_stops;
00135   TileIndex train_tile;
00136   TileIndex airport_tile;
00137   TileIndex dock_tile;
00138   Town *town;
00139   StringID string_id;     
00140   char *name;             
00141 
00142   ViewportSign sign;
00143 
00144   uint16 had_vehicle_of_type;
00145 
00146   byte time_since_load;
00147   byte time_since_unload;
00148   byte delete_ctr;
00149   PlayerByte owner;
00150   byte facilities;
00151   byte airport_type;
00152 
00153   /* trainstation width/height */
00154   byte trainst_w, trainst_h;
00155 
00157   uint8 num_specs;
00158   StationSpecList *speclist;
00159 
00160   Date build_date;
00161 
00162   uint64 airport_flags;   
00163 
00164   byte last_vehicle_type;
00165   std::list<Vehicle *> loading_vehicles;
00166   GoodsEntry goods[NUM_CARGO];
00167 
00168   uint16 random_bits;
00169   byte waiting_triggers;
00170 
00171   StationRect rect; 
00172 
00173   static const int cDebugCtorLevel = 5;
00174 
00175   Station(TileIndex tile = 0);
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 != 0; }
00203 };
00204 
00205 enum StationType {
00206   STATION_RAIL,
00207   STATION_AIRPORT,
00208   STATION_TRUCK,
00209   STATION_BUS,
00210   STATION_OILRIG,
00211   STATION_DOCK,
00212   STATION_BUOY
00213 };
00214 
00215 enum {
00216   FACIL_TRAIN      = 0x01,
00217   FACIL_TRUCK_STOP = 0x02,
00218   FACIL_BUS_STOP   = 0x04,
00219   FACIL_AIRPORT    = 0x08,
00220   FACIL_DOCK       = 0x10,
00221 };
00222 
00223 enum {
00224 //  HVOT_PENDING_DELETE = 1 << 0, // not needed anymore
00225   HVOT_TRAIN    = 1 << 1,
00226   HVOT_BUS      = 1 << 2,
00227   HVOT_TRUCK    = 1 << 3,
00228   HVOT_AIRCRAFT = 1 << 4,
00229   HVOT_SHIP     = 1 << 5,
00230   /* This bit is used to mark stations. No, it does not belong here, but what
00231    * can we do? ;-) */
00232   HVOT_BUOY     = 1 << 6
00233 };
00234 
00235 enum CatchmentArea {
00236   CA_NONE            =  0,
00237   CA_BUS             =  3,
00238   CA_TRUCK           =  3,
00239   CA_TRAIN           =  4,
00240   CA_DOCK            =  5,
00241 
00242   CA_UNMODIFIED      =  4, 
00243 
00244   MAX_CATCHMENT      = 10, 
00245 };
00246 
00247 void ModifyStationRatingAround(TileIndex tile, PlayerID owner, int amount, uint radius);
00248 
00250 typedef std::set<Station*> StationSet;
00251 
00252 StationSet FindStationsAroundIndustryTile(TileIndex tile, int w, int h);
00253 
00254 void ShowStationViewWindow(StationID station);
00255 void UpdateAllStationVirtCoord();
00256 
00257 static inline StationID GetMaxStationIndex()
00258 {
00259   /* TODO - This isn't the real content of the function, but
00260    *  with the new pool-system this will be replaced with one that
00261    *  _really_ returns the highest index. Now it just returns
00262    *  the next safe value we are sure about everything is below.
00263    */
00264   return GetStationPoolSize() - 1;
00265 }
00266 
00267 static inline uint GetNumStations()
00268 {
00269   return GetStationPoolSize();
00270 }
00271 
00272 static inline bool IsValidStationID(StationID index)
00273 {
00274   return index < GetStationPoolSize() && GetStation(index)->IsValid();
00275 }
00276 
00277 #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())
00278 #define FOR_ALL_STATIONS(st) FOR_ALL_STATIONS_FROM(st, 0)
00279 
00280 
00281 /* Stuff for ROADSTOPS */
00282 
00283 #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())
00284 #define FOR_ALL_ROADSTOPS(rs) FOR_ALL_ROADSTOPS_FROM(rs, 0)
00285 
00286 /* End of stuff for ROADSTOPS */
00287 
00288 
00289 void AfterLoadStations();
00290 void GetProductionAroundTiles(AcceptedCargo produced, TileIndex tile, int w, int h, int rad);
00291 void GetAcceptanceAroundTiles(AcceptedCargo accepts, TileIndex tile, int w, int h, int rad);
00292 
00293 
00294 const DrawTileSprites *GetStationTileLayout(StationType st, byte gfx);
00295 void StationPickerDrawSprite(int x, int y, StationType st, RailType railtype, RoadType roadtype, int image);
00296 
00297 RoadStop * GetRoadStopByTile(TileIndex tile, RoadStop::Type type);
00298 uint GetNumRoadStops(const Station* st, RoadStop::Type type);
00299 RoadStop * AllocateRoadStop();
00300 void ClearSlot(Vehicle *v);
00301 
00302 bool HasStationInUse(StationID station, PlayerID player);
00303 
00304 void DeleteOilRig(TileIndex t);
00305 
00306 #endif /* STATION_H */

Generated on Mon Sep 22 20:34:18 2008 for openttd by  doxygen 1.5.6