author | truebrain |
Mon, 30 Jun 2008 21:31:23 +0000 | |
branch | noai |
changeset 11111 | 1b984dab8cec |
parent 10455 | 22c441f5adf9 |
permissions | -rw-r--r-- |
9837 | 1 |
/* $Id$ */ |
2 |
||
3 |
/** @file station_base.h Base classes/functions for stations. */ |
|
4 |
||
5 |
#ifndef STATION_BASE_H |
|
6 |
#define STATION_BASE_H |
|
7 |
||
8 |
#include "station_type.h" |
|
9 |
#include "airport.h" |
|
10 |
#include "oldpool.h" |
|
11 |
#include "cargopacket.h" |
|
12 |
#include "cargo_type.h" |
|
13 |
#include "town_type.h" |
|
14 |
#include "strings_type.h" |
|
15 |
#include "date_type.h" |
|
16 |
#include "vehicle_type.h" |
|
17 |
#include "player_type.h" |
|
18 |
#include "core/geometry_type.hpp" |
|
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10294
diff
changeset
|
19 |
#include "viewport_type.h" |
9837 | 20 |
#include <list> |
21 |
||
22 |
DECLARE_OLD_POOL(Station, Station, 6, 1000) |
|
23 |
DECLARE_OLD_POOL(RoadStop, RoadStop, 5, 2000) |
|
24 |
||
25 |
static const byte INITIAL_STATION_RATING = 175; |
|
26 |
||
27 |
struct GoodsEntry { |
|
28 |
enum AcceptancePickup { |
|
29 |
ACCEPTANCE, |
|
30 |
PICKUP |
|
31 |
}; |
|
32 |
||
33 |
GoodsEntry() : |
|
34 |
acceptance_pickup(0), |
|
35 |
days_since_pickup(255), |
|
36 |
rating(INITIAL_STATION_RATING), |
|
37 |
last_speed(0), |
|
38 |
last_age(255) |
|
39 |
{} |
|
40 |
||
41 |
byte acceptance_pickup; |
|
42 |
byte days_since_pickup; |
|
43 |
byte rating; |
|
44 |
byte last_speed; |
|
45 |
byte last_age; |
|
46 |
CargoList cargo; ///< The cargo packets of cargo waiting in this station |
|
47 |
}; |
|
48 |
||
49 |
/** A Stop for a Road Vehicle */ |
|
50 |
struct RoadStop : PoolItem<RoadStop, RoadStopID, &_RoadStop_pool> { |
|
51 |
static const int cDebugCtorLevel = 5; ///< Debug level on which Contructor / Destructor messages are printed |
|
52 |
static const uint LIMIT = 16; ///< The maximum amount of roadstops that are allowed at a single station |
|
53 |
static const uint MAX_BAY_COUNT = 2; ///< The maximum number of loading bays |
|
54 |
||
55 |
TileIndex xy; ///< Position on the map |
|
56 |
byte status; ///< Current status of the Stop. Like which spot is taken. Access using *Bay and *Busy functions. |
|
57 |
byte num_vehicles; ///< Number of vehicles currently slotted to this stop |
|
58 |
struct RoadStop *next; ///< Next stop of the given type at this station |
|
59 |
||
60 |
RoadStop(TileIndex tile = 0); |
|
61 |
virtual ~RoadStop(); |
|
62 |
||
63 |
/** |
|
64 |
* Determines whether a road stop exists |
|
65 |
* @return true if and only is the road stop exists |
|
66 |
*/ |
|
67 |
inline bool IsValid() const { return this->xy != 0; } |
|
68 |
||
69 |
/* For accessing status */ |
|
70 |
bool HasFreeBay() const; |
|
71 |
bool IsFreeBay(uint nr) const; |
|
72 |
uint AllocateBay(); |
|
73 |
void AllocateDriveThroughBay(uint nr); |
|
74 |
void FreeBay(uint nr); |
|
75 |
bool IsEntranceBusy() const; |
|
76 |
void SetEntranceBusy(bool busy); |
|
77 |
||
78 |
RoadStop *GetNextRoadStop(const Vehicle *v) const; |
|
79 |
}; |
|
80 |
||
81 |
struct StationSpecList { |
|
82 |
const StationSpec *spec; |
|
83 |
uint32 grfid; ///< GRF ID of this custom station |
|
84 |
uint8 localidx; ///< Station ID within GRF of station |
|
85 |
}; |
|
86 |
||
87 |
/** StationRect - used to track station spread out rectangle - cheaper than scanning whole map */ |
|
88 |
struct StationRect : public Rect { |
|
89 |
enum StationRectMode |
|
90 |
{ |
|
91 |
ADD_TEST = 0, |
|
92 |
ADD_TRY, |
|
93 |
ADD_FORCE |
|
94 |
}; |
|
95 |
||
96 |
StationRect(); |
|
97 |
void MakeEmpty(); |
|
98 |
bool PtInExtendedRect(int x, int y, int distance = 0) const; |
|
99 |
bool IsEmpty() const; |
|
100 |
bool BeforeAddTile(TileIndex tile, StationRectMode mode); |
|
101 |
bool BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode); |
|
102 |
bool AfterRemoveTile(Station *st, TileIndex tile); |
|
103 |
bool AfterRemoveRect(Station *st, TileIndex tile, int w, int h); |
|
104 |
||
105 |
static bool ScanForStationTiles(StationID st_id, int left_a, int top_a, int right_a, int bottom_a); |
|
106 |
||
107 |
StationRect& operator = (Rect src); |
|
108 |
}; |
|
109 |
||
110 |
struct Station : PoolItem<Station, StationID, &_Station_pool> { |
|
111 |
public: |
|
112 |
RoadStop *GetPrimaryRoadStop(RoadStopType type) const |
|
113 |
{ |
|
114 |
return type == ROADSTOP_BUS ? bus_stops : truck_stops; |
|
115 |
} |
|
116 |
||
117 |
RoadStop *GetPrimaryRoadStop(const Vehicle *v) const; |
|
118 |
||
119 |
const AirportFTAClass *Airport() const |
|
120 |
{ |
|
121 |
if (airport_tile == 0) return GetAirport(AT_DUMMY); |
|
122 |
return GetAirport(airport_type); |
|
123 |
} |
|
124 |
||
125 |
TileIndex xy; |
|
126 |
RoadStop *bus_stops; |
|
127 |
RoadStop *truck_stops; |
|
128 |
TileIndex train_tile; |
|
129 |
TileIndex airport_tile; |
|
130 |
TileIndex dock_tile; |
|
131 |
Town *town; |
|
132 |
StringID string_id; ///< Default name (town area) of station |
|
133 |
char *name; ///< Custom name |
|
134 |
||
135 |
ViewportSign sign; |
|
136 |
||
137 |
uint16 had_vehicle_of_type; |
|
138 |
||
139 |
byte time_since_load; |
|
140 |
byte time_since_unload; |
|
141 |
byte delete_ctr; |
|
142 |
PlayerByte owner; |
|
143 |
byte facilities; |
|
144 |
byte airport_type; |
|
145 |
||
146 |
/* trainstation width/height */ |
|
147 |
byte trainst_w, trainst_h; |
|
148 |
||
149 |
/** List of custom stations (StationSpecs) allocated to the station */ |
|
150 |
uint8 num_specs; |
|
151 |
StationSpecList *speclist; |
|
152 |
||
153 |
Date build_date; |
|
154 |
||
155 |
uint64 airport_flags; ///< stores which blocks on the airport are taken. was 16 bit earlier on, then 32 |
|
156 |
||
157 |
byte last_vehicle_type; |
|
158 |
std::list<Vehicle *> loading_vehicles; |
|
159 |
GoodsEntry goods[NUM_CARGO]; |
|
160 |
||
161 |
uint16 random_bits; |
|
162 |
byte waiting_triggers; |
|
10294 | 163 |
uint8 cached_anim_triggers; ///< Combined animation trigger bitmask, used to determine if trigger processing should happen. |
9837 | 164 |
|
165 |
StationRect rect; ///< Station spread out rectangle (not saved) maintained by StationRect_xxx() functions |
|
166 |
||
167 |
static const int cDebugCtorLevel = 5; |
|
168 |
||
169 |
Station(TileIndex tile = 0); |
|
170 |
virtual ~Station(); |
|
171 |
||
172 |
void AddFacility(byte new_facility_bit, TileIndex facil_xy); |
|
173 |
||
174 |
/** |
|
175 |
* Mark the sign of a station dirty for repaint. |
|
176 |
* |
|
177 |
* @ingroup dirty |
|
178 |
*/ |
|
179 |
void MarkDirty() const; |
|
180 |
||
181 |
/** |
|
182 |
* Marks the tiles of the station as dirty. |
|
183 |
* |
|
184 |
* @ingroup dirty |
|
185 |
*/ |
|
186 |
void MarkTilesDirty(bool cargo_change) const; |
|
187 |
bool TileBelongsToRailStation(TileIndex tile) const; |
|
188 |
uint GetPlatformLength(TileIndex tile, DiagDirection dir) const; |
|
189 |
uint GetPlatformLength(TileIndex tile) const; |
|
190 |
bool IsBuoy() const; |
|
191 |
||
192 |
/** |
|
193 |
* Determines whether a station exists |
|
194 |
* @return true if and only is the station exists |
|
195 |
*/ |
|
196 |
inline bool IsValid() const { return this->xy != 0; } |
|
197 |
}; |
|
198 |
||
199 |
static inline StationID GetMaxStationIndex() |
|
200 |
{ |
|
201 |
/* TODO - This isn't the real content of the function, but |
|
202 |
* with the new pool-system this will be replaced with one that |
|
203 |
* _really_ returns the highest index. Now it just returns |
|
204 |
* the next safe value we are sure about everything is below. |
|
205 |
*/ |
|
206 |
return GetStationPoolSize() - 1; |
|
207 |
} |
|
208 |
||
209 |
static inline uint GetNumStations() |
|
210 |
{ |
|
211 |
return GetStationPoolSize(); |
|
212 |
} |
|
213 |
||
214 |
static inline bool IsValidStationID(StationID index) |
|
215 |
{ |
|
216 |
return index < GetStationPoolSize() && GetStation(index)->IsValid(); |
|
217 |
} |
|
218 |
||
219 |
#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()) |
|
220 |
#define FOR_ALL_STATIONS(st) FOR_ALL_STATIONS_FROM(st, 0) |
|
221 |
||
222 |
||
223 |
/* Stuff for ROADSTOPS */ |
|
224 |
||
225 |
#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()) |
|
226 |
#define FOR_ALL_ROADSTOPS(rs) FOR_ALL_ROADSTOPS_FROM(rs, 0) |
|
227 |
||
228 |
/* End of stuff for ROADSTOPS */ |
|
229 |
||
230 |
#endif /* STATION_BASE_H */ |