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