station_base.h

Go to the documentation of this file.
00001 /* $Id: station_base.h 14743 2008-12-26 18:01:15Z smatz $ */
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 
00056   TileIndex        xy;                    
00057   byte             status;                
00058   byte             num_vehicles;          
00059   struct RoadStop  *next;                 
00060 
00061   RoadStop(TileIndex tile = INVALID_TILE);
00062   virtual ~RoadStop();
00063 
00068   inline bool IsValid() const { return this->xy != INVALID_TILE; }
00069 
00070   /* For accessing status */
00071   bool HasFreeBay() const;
00072   bool IsFreeBay(uint nr) const;
00073   uint AllocateBay();
00074   void AllocateDriveThroughBay(uint nr);
00075   void FreeBay(uint nr);
00076   bool IsEntranceBusy() const;
00077   void SetEntranceBusy(bool busy);
00078 
00079   RoadStop *GetNextRoadStop(const Vehicle *v) const;
00080 };
00081 
00082 struct StationSpecList {
00083   const StationSpec *spec;
00084   uint32 grfid;      
00085   uint8  localidx;   
00086 };
00087 
00089 struct StationRect : public Rect {
00090   enum StationRectMode
00091   {
00092     ADD_TEST = 0,
00093     ADD_TRY,
00094     ADD_FORCE
00095   };
00096 
00097   StationRect();
00098   void MakeEmpty();
00099   bool PtInExtendedRect(int x, int y, int distance = 0) const;
00100   bool IsEmpty() const;
00101   bool BeforeAddTile(TileIndex tile, StationRectMode mode);
00102   bool BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode);
00103   bool AfterRemoveTile(Station *st, TileIndex tile);
00104   bool AfterRemoveRect(Station *st, TileIndex tile, int w, int h);
00105 
00106   static bool ScanForStationTiles(StationID st_id, int left_a, int top_a, int right_a, int bottom_a);
00107 
00108   StationRect& operator = (Rect src);
00109 };
00110 
00112 struct Station : PoolItem<Station, StationID, &_Station_pool> {
00113 public:
00114   RoadStop *GetPrimaryRoadStop(RoadStopType type) const
00115   {
00116     return type == ROADSTOP_BUS ? bus_stops : truck_stops;
00117   }
00118 
00119   RoadStop *GetPrimaryRoadStop(const Vehicle *v) const;
00120 
00121   const AirportFTAClass *Airport() const
00122   {
00123     if (airport_tile == INVALID_TILE) return GetAirport(AT_DUMMY);
00124     return GetAirport(airport_type);
00125   }
00126 
00127   TileIndex xy;
00128   RoadStop *bus_stops;
00129   RoadStop *truck_stops;
00130   TileIndex train_tile;
00131   TileIndex airport_tile;
00132   TileIndex dock_tile;
00133   Town *town;
00134 
00135   /* Place to get a name from, in order of importance: */
00136   char *name;             
00137   IndustryType indtype;   
00138   StringID string_id;     
00139 
00140   ViewportSign sign;
00141 
00142   uint16 had_vehicle_of_type;
00143 
00144   byte time_since_load;
00145   byte time_since_unload;
00146   byte delete_ctr;
00147   OwnerByte owner;
00148   byte facilities;
00149   byte airport_type;
00150 
00151   /* trainstation width/height */
00152   byte trainst_w, trainst_h;
00153 
00155   uint8 num_specs;
00156   StationSpecList *speclist;
00157 
00158   Date build_date;  
00159 
00160   uint64 airport_flags;   
00161 
00162   byte last_vehicle_type;
00163   std::list<Vehicle *> loading_vehicles;
00164   GoodsEntry goods[NUM_CARGO];  
00165 
00166   uint16 random_bits;
00167   byte waiting_triggers;
00168   uint8 cached_anim_triggers; 
00169 
00170   StationRect rect; 
00171 
00172   static const int cDebugCtorLevel = 5;
00173 
00174   Station(TileIndex tile = INVALID_TILE);
00175   virtual ~Station();
00176 
00177   void AddFacility(byte new_facility_bit, TileIndex facil_xy);
00178 
00184   void MarkDirty() const;
00185 
00191   void MarkTilesDirty(bool cargo_change) const;
00192   bool TileBelongsToRailStation(TileIndex tile) const;
00193   uint GetPlatformLength(TileIndex tile, DiagDirection dir) const;
00194   uint GetPlatformLength(TileIndex tile) const;
00195   bool IsBuoy() const;
00196 
00201   inline bool IsValid() const { return this->xy != INVALID_TILE; }
00202 
00203   uint GetCatchmentRadius() const;
00204 };
00205 
00206 static inline StationID GetMaxStationIndex()
00207 {
00208   /* TODO - This isn't the real content of the function, but
00209    *  with the new pool-system this will be replaced with one that
00210    *  _really_ returns the highest index. Now it just returns
00211    *  the next safe value we are sure about everything is below.
00212    */
00213   return GetStationPoolSize() - 1;
00214 }
00215 
00216 static inline uint GetNumStations()
00217 {
00218   return GetStationPoolSize();
00219 }
00220 
00221 static inline bool IsValidStationID(StationID index)
00222 {
00223   return index < GetStationPoolSize() && GetStation(index)->IsValid();
00224 }
00225 
00226 #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())
00227 #define FOR_ALL_STATIONS(st) FOR_ALL_STATIONS_FROM(st, 0)
00228 
00229 
00230 /* Stuff for ROADSTOPS */
00231 
00232 #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())
00233 #define FOR_ALL_ROADSTOPS(rs) FOR_ALL_ROADSTOPS_FROM(rs, 0)
00234 
00235 /* End of stuff for ROADSTOPS */
00236 
00237 #endif /* STATION_BASE_H */

Generated on Mon Feb 16 23:12:10 2009 for openttd by  doxygen 1.5.6