13 #include "road.h" |
13 #include "road.h" |
14 #include "newgrf_station.h" |
14 #include "newgrf_station.h" |
15 #include "cargopacket.h" |
15 #include "cargopacket.h" |
16 #include <list> |
16 #include <list> |
17 |
17 |
|
18 struct Station; |
|
19 struct RoadStop; |
|
20 |
|
21 DECLARE_OLD_POOL(Station, Station, 6, 1000) |
|
22 DECLARE_OLD_POOL(RoadStop, RoadStop, 5, 2000) |
|
23 |
18 static const byte INITIAL_STATION_RATING = 175; |
24 static const byte INITIAL_STATION_RATING = 175; |
19 |
25 |
20 struct GoodsEntry { |
26 struct GoodsEntry { |
21 GoodsEntry() : |
27 GoodsEntry() : |
22 acceptance(false), |
28 acceptance(false), |
33 byte last_age; |
39 byte last_age; |
34 CargoList cargo; ///< The cargo packets of cargo waiting in this station |
40 CargoList cargo; ///< The cargo packets of cargo waiting in this station |
35 }; |
41 }; |
36 |
42 |
37 /** A Stop for a Road Vehicle */ |
43 /** A Stop for a Road Vehicle */ |
38 struct RoadStop { |
44 struct RoadStop : PoolItem<RoadStop, RoadStopID, &_RoadStop_pool> { |
39 /** Types of RoadStops */ |
45 /** Types of RoadStops */ |
40 enum Type { |
46 enum Type { |
41 BUS, ///< A standard stop for buses |
47 BUS, ///< A standard stop for buses |
42 TRUCK ///< A standard stop for trucks |
48 TRUCK ///< A standard stop for trucks |
43 }; |
49 }; |
45 static const int cDebugCtorLevel = 3; ///< Debug level on which Contructor / Destructor messages are printed |
51 static const int cDebugCtorLevel = 3; ///< Debug level on which Contructor / Destructor messages are printed |
46 static const uint LIMIT = 16; ///< The maximum amount of roadstops that are allowed at a single station |
52 static const uint LIMIT = 16; ///< The maximum amount of roadstops that are allowed at a single station |
47 static const uint MAX_BAY_COUNT = 2; ///< The maximum number of loading bays |
53 static const uint MAX_BAY_COUNT = 2; ///< The maximum number of loading bays |
48 |
54 |
49 TileIndex xy; ///< Position on the map |
55 TileIndex xy; ///< Position on the map |
50 RoadStopID index; ///< Global (i.e. pool-wide) index |
|
51 byte status; ///< Current status of the Stop. Like which spot is taken. Access using *Bay and *Busy functions. |
56 byte status; ///< Current status of the Stop. Like which spot is taken. Access using *Bay and *Busy functions. |
52 byte num_vehicles; ///< Number of vehicles currently slotted to this stop |
57 byte num_vehicles; ///< Number of vehicles currently slotted to this stop |
53 struct RoadStop *next; ///< Next stop of the given type at this station |
58 struct RoadStop *next; ///< Next stop of the given type at this station |
54 |
59 |
55 RoadStop(TileIndex tile); |
60 RoadStop(TileIndex tile = 0); |
56 ~RoadStop(); |
61 virtual ~RoadStop(); |
57 |
|
58 void *operator new (size_t size); |
|
59 void operator delete(void *rs); |
|
60 |
|
61 /* For loading games */ |
|
62 void *operator new (size_t size, int index); |
|
63 void operator delete(void *rs, int index); |
|
64 |
62 |
65 bool IsValid() const; |
63 bool IsValid() const; |
66 |
64 |
67 /* For accessing status */ |
65 /* For accessing status */ |
68 bool HasFreeBay() const; |
66 bool HasFreeBay() const; |
70 uint AllocateBay(); |
68 uint AllocateBay(); |
71 void AllocateDriveThroughBay(uint nr); |
69 void AllocateDriveThroughBay(uint nr); |
72 void FreeBay(uint nr); |
70 void FreeBay(uint nr); |
73 bool IsEntranceBusy() const; |
71 bool IsEntranceBusy() const; |
74 void SetEntranceBusy(bool busy); |
72 void SetEntranceBusy(bool busy); |
75 protected: |
|
76 static RoadStop *AllocateRaw(); |
|
77 }; |
73 }; |
78 |
74 |
79 struct StationSpecList { |
75 struct StationSpecList { |
80 const StationSpec *spec; |
76 const StationSpec *spec; |
81 uint32 grfid; ///< GRF ID of this custom station |
77 uint32 grfid; ///< GRF ID of this custom station |
103 static bool ScanForStationTiles(StationID st_id, int left_a, int top_a, int right_a, int bottom_a); |
99 static bool ScanForStationTiles(StationID st_id, int left_a, int top_a, int right_a, int bottom_a); |
104 |
100 |
105 StationRect& operator = (Rect src); |
101 StationRect& operator = (Rect src); |
106 }; |
102 }; |
107 |
103 |
108 struct Station { |
104 struct Station : PoolItem<Station, StationID, &_Station_pool> { |
109 public: |
105 public: |
110 RoadStop *GetPrimaryRoadStop(RoadStop::Type type) const |
106 RoadStop *GetPrimaryRoadStop(RoadStop::Type type) const |
111 { |
107 { |
112 return type == RoadStop::BUS ? bus_stops : truck_stops; |
108 return type == RoadStop::BUS ? bus_stops : truck_stops; |
113 } |
109 } |
146 StationSpecList *speclist; |
142 StationSpecList *speclist; |
147 |
143 |
148 Date build_date; |
144 Date build_date; |
149 |
145 |
150 uint64 airport_flags; ///< stores which blocks on the airport are taken. was 16 bit earlier on, then 32 |
146 uint64 airport_flags; ///< stores which blocks on the airport are taken. was 16 bit earlier on, then 32 |
151 StationID index; |
|
152 |
147 |
153 byte last_vehicle_type; |
148 byte last_vehicle_type; |
154 std::list<Vehicle *> loading_vehicles; |
149 std::list<Vehicle *> loading_vehicles; |
155 GoodsEntry goods[NUM_CARGO]; |
150 GoodsEntry goods[NUM_CARGO]; |
156 |
151 |
160 StationRect rect; ///< Station spread out rectangle (not saved) maintained by StationRect_xxx() functions |
155 StationRect rect; ///< Station spread out rectangle (not saved) maintained by StationRect_xxx() functions |
161 |
156 |
162 static const int cDebugCtorLevel = 3; |
157 static const int cDebugCtorLevel = 3; |
163 |
158 |
164 Station(TileIndex tile = 0); |
159 Station(TileIndex tile = 0); |
165 ~Station(); |
160 virtual ~Station(); |
166 |
161 |
167 /* normal new/delete operators. Used when building/removing station */ |
162 void QuickFree(); |
168 void* operator new (size_t size); |
|
169 void operator delete(void *p); |
|
170 |
|
171 /* new/delete operators accepting station index. Used when loading station from savegame. */ |
|
172 void* operator new (size_t size, int st_idx); |
|
173 void operator delete(void *p, int st_idx); |
|
174 |
163 |
175 void AddFacility(byte new_facility_bit, TileIndex facil_xy); |
164 void AddFacility(byte new_facility_bit, TileIndex facil_xy); |
176 void MarkDirty() const; |
165 void MarkDirty() const; |
177 void MarkTilesDirty(bool cargo_change) const; |
166 void MarkTilesDirty(bool cargo_change) const; |
178 bool TileBelongsToRailStation(TileIndex tile) const; |
167 bool TileBelongsToRailStation(TileIndex tile) const; |
179 uint GetPlatformLength(TileIndex tile, DiagDirection dir) const; |
168 uint GetPlatformLength(TileIndex tile, DiagDirection dir) const; |
180 uint GetPlatformLength(TileIndex tile) const; |
169 uint GetPlatformLength(TileIndex tile) const; |
181 bool IsBuoy() const; |
170 bool IsBuoy() const; |
182 bool IsValid() const; |
171 bool IsValid() const; |
183 |
|
184 protected: |
|
185 static Station *AllocateRaw(); |
|
186 }; |
172 }; |
187 |
173 |
188 enum StationType { |
174 enum StationType { |
189 STATION_RAIL, |
175 STATION_RAIL, |
190 STATION_AIRPORT, |
176 STATION_AIRPORT, |
230 |
216 |
231 /* sorter stuff */ |
217 /* sorter stuff */ |
232 void RebuildStationLists(); |
218 void RebuildStationLists(); |
233 void ResortStationLists(); |
219 void ResortStationLists(); |
234 |
220 |
235 DECLARE_OLD_POOL(Station, Station, 6, 1000) |
|
236 |
|
237 static inline StationID GetMaxStationIndex() |
221 static inline StationID GetMaxStationIndex() |
238 { |
222 { |
239 /* TODO - This isn't the real content of the function, but |
223 /* TODO - This isn't the real content of the function, but |
240 * with the new pool-system this will be replaced with one that |
224 * with the new pool-system this will be replaced with one that |
241 * _really_ returns the highest index. Now it just returns |
225 * _really_ returns the highest index. Now it just returns |
258 #define FOR_ALL_STATIONS(st) FOR_ALL_STATIONS_FROM(st, 0) |
242 #define FOR_ALL_STATIONS(st) FOR_ALL_STATIONS_FROM(st, 0) |
259 |
243 |
260 |
244 |
261 /* Stuff for ROADSTOPS */ |
245 /* Stuff for ROADSTOPS */ |
262 |
246 |
263 DECLARE_OLD_POOL(RoadStop, RoadStop, 5, 2000) |
|
264 |
|
265 #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()) |
247 #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()) |
266 #define FOR_ALL_ROADSTOPS(rs) FOR_ALL_ROADSTOPS_FROM(rs, 0) |
248 #define FOR_ALL_ROADSTOPS(rs) FOR_ALL_ROADSTOPS_FROM(rs, 0) |
267 |
249 |
268 /* End of stuff for ROADSTOPS */ |
250 /* End of stuff for ROADSTOPS */ |
269 |
251 |