9723
|
1 |
/* $Id$ */
|
|
2 |
|
|
3 |
/** @file vehicle_base.h Base class for all vehicles. */
|
|
4 |
|
|
5 |
#ifndef VEHICLE_BASE_H
|
|
6 |
#define VEHICLE_BASE_H
|
|
7 |
|
|
8 |
#include "vehicle_type.h"
|
|
9 |
#include "track_type.h"
|
|
10 |
#include "rail_type.h"
|
|
11 |
#include "road_type.h"
|
|
12 |
#include "cargo_type.h"
|
|
13 |
#include "direction_type.h"
|
|
14 |
#include "window_type.h"
|
|
15 |
#include "gfx_type.h"
|
|
16 |
#include "command_type.h"
|
|
17 |
#include "date_type.h"
|
|
18 |
#include "oldpool.h"
|
|
19 |
#include "order.h"
|
|
20 |
#include "cargopacket.h"
|
|
21 |
#include "texteff.hpp"
|
|
22 |
|
|
23 |
/** Road vehicle states */
|
|
24 |
enum RoadVehicleStates {
|
|
25 |
/*
|
|
26 |
* Lower 4 bits are used for vehicle track direction. (Trackdirs)
|
|
27 |
* When in a road stop (bit 5 or bit 6 set) these bits give the
|
|
28 |
* track direction of the entry to the road stop.
|
|
29 |
* As the entry direction will always be a diagonal
|
|
30 |
* direction (X_NE, Y_SE, X_SW or Y_NW) only bits 0 and 3
|
|
31 |
* are needed to hold this direction. Bit 1 is then used to show
|
|
32 |
* that the vehicle is using the second road stop bay.
|
|
33 |
* Bit 2 is then used for drive-through stops to show the vehicle
|
|
34 |
* is stopping at this road stop.
|
|
35 |
*/
|
|
36 |
|
|
37 |
/* Numeric values */
|
|
38 |
RVSB_IN_DEPOT = 0xFE, ///< The vehicle is in a depot
|
|
39 |
RVSB_WORMHOLE = 0xFF, ///< The vehicle is in a tunnel and/or bridge
|
|
40 |
|
|
41 |
/* Bit numbers */
|
|
42 |
RVS_USING_SECOND_BAY = 1, ///< Only used while in a road stop
|
|
43 |
RVS_IS_STOPPING = 2, ///< Only used for drive-through stops. Vehicle will stop here
|
|
44 |
RVS_DRIVE_SIDE = 4, ///< Only used when retrieving move data
|
|
45 |
RVS_IN_ROAD_STOP = 5, ///< The vehicle is in a road stop
|
|
46 |
RVS_IN_DT_ROAD_STOP = 6, ///< The vehicle is in a drive-through road stop
|
|
47 |
|
|
48 |
/* Bit sets of the above specified bits */
|
|
49 |
RVSB_IN_ROAD_STOP = 1 << RVS_IN_ROAD_STOP, ///< The vehicle is in a road stop
|
|
50 |
RVSB_IN_ROAD_STOP_END = RVSB_IN_ROAD_STOP + TRACKDIR_END,
|
|
51 |
RVSB_IN_DT_ROAD_STOP = 1 << RVS_IN_DT_ROAD_STOP, ///< The vehicle is in a drive-through road stop
|
|
52 |
RVSB_IN_DT_ROAD_STOP_END = RVSB_IN_DT_ROAD_STOP + TRACKDIR_END,
|
|
53 |
|
|
54 |
RVSB_TRACKDIR_MASK = 0x0F, ///< The mask used to extract track dirs
|
|
55 |
RVSB_ROAD_STOP_TRACKDIR_MASK = 0x09 ///< Only bits 0 and 3 are used to encode the trackdir for road stops
|
|
56 |
};
|
|
57 |
|
|
58 |
enum VehStatus {
|
|
59 |
VS_HIDDEN = 0x01,
|
|
60 |
VS_STOPPED = 0x02,
|
|
61 |
VS_UNCLICKABLE = 0x04,
|
|
62 |
VS_DEFPAL = 0x08,
|
|
63 |
VS_TRAIN_SLOWING = 0x10,
|
|
64 |
VS_SHADOW = 0x20,
|
|
65 |
VS_AIRCRAFT_BROKEN = 0x40,
|
|
66 |
VS_CRASHED = 0x80,
|
|
67 |
};
|
|
68 |
|
|
69 |
enum VehicleFlags {
|
|
70 |
VF_LOADING_FINISHED,
|
|
71 |
VF_CARGO_UNLOADING,
|
|
72 |
VF_BUILT_AS_PROTOTYPE,
|
|
73 |
VF_TIMETABLE_STARTED, ///< Whether the vehicle has started running on the timetable yet.
|
|
74 |
VF_AUTOFILL_TIMETABLE, ///< Whether the vehicle should fill in the timetable automatically.
|
|
75 |
};
|
|
76 |
|
|
77 |
struct VehicleRail {
|
|
78 |
uint16 last_speed; // NOSAVE: only used in UI
|
|
79 |
uint16 crash_anim_pos;
|
|
80 |
|
|
81 |
/* cached values, recalculated on load and each time a vehicle is added to/removed from the consist. */
|
|
82 |
uint16 cached_max_speed; // max speed of the consist. (minimum of the max speed of all vehicles in the consist)
|
|
83 |
uint32 cached_power; // total power of the consist.
|
|
84 |
bool cached_tilt; // train can tilt; feature provides a bonus in curves
|
|
85 |
uint8 cached_veh_length; // length of this vehicle in units of 1/8 of normal length, cached because this can be set by a callback
|
|
86 |
uint16 cached_total_length; ///< Length of the whole train, valid only for first engine.
|
|
87 |
|
|
88 |
/* cached values, recalculated when the cargo on a train changes (in addition to the conditions above) */
|
|
89 |
uint32 cached_weight; // total weight of the consist.
|
|
90 |
uint32 cached_veh_weight; // weight of the vehicle.
|
|
91 |
uint32 cached_max_te; // max tractive effort of consist
|
|
92 |
/**
|
|
93 |
* Position/type of visual effect.
|
|
94 |
* bit 0 - 3 = position of effect relative to vehicle. (0 = front, 8 = centre, 15 = rear)
|
|
95 |
* bit 4 - 5 = type of effect. (0 = default for engine class, 1 = steam, 2 = diesel, 3 = electric)
|
|
96 |
* bit 6 = disable visual effect.
|
|
97 |
* bit 7 = disable powered wagons.
|
|
98 |
*/
|
|
99 |
byte cached_vis_effect;
|
|
100 |
byte user_def_data;
|
|
101 |
|
|
102 |
/* NOSAVE: for wagon override - id of the first engine in train
|
|
103 |
* 0xffff == not in train */
|
|
104 |
EngineID first_engine;
|
|
105 |
|
|
106 |
TrackBitsByte track;
|
|
107 |
byte force_proceed;
|
|
108 |
RailTypeByte railtype;
|
|
109 |
RailTypeMask compatible_railtypes;
|
|
110 |
|
|
111 |
byte flags;
|
|
112 |
|
|
113 |
/* Link between the two ends of a multiheaded engine */
|
|
114 |
Vehicle *other_multiheaded_part;
|
|
115 |
|
|
116 |
/* Cached wagon override spritegroup */
|
|
117 |
const struct SpriteGroup *cached_override;
|
|
118 |
};
|
|
119 |
|
|
120 |
enum {
|
|
121 |
VRF_REVERSING = 0,
|
|
122 |
|
|
123 |
/* used to calculate if train is going up or down */
|
|
124 |
VRF_GOINGUP = 1,
|
|
125 |
VRF_GOINGDOWN = 2,
|
|
126 |
|
|
127 |
/* used to store if a wagon is powered or not */
|
|
128 |
VRF_POWEREDWAGON = 3,
|
|
129 |
|
|
130 |
/* used to reverse the visible direction of the vehicle */
|
|
131 |
VRF_REVERSE_DIRECTION = 4,
|
|
132 |
|
|
133 |
/* used to mark train as lost because PF can't find the route */
|
|
134 |
VRF_NO_PATH_TO_DESTINATION = 5,
|
|
135 |
|
|
136 |
/* used to mark that electric train engine is allowed to run on normal rail */
|
|
137 |
VRF_EL_ENGINE_ALLOWED_NORMAL_RAIL = 6,
|
|
138 |
};
|
|
139 |
|
|
140 |
struct VehicleAir {
|
|
141 |
uint16 crashed_counter;
|
|
142 |
uint16 cached_max_speed;
|
|
143 |
byte pos;
|
|
144 |
byte previous_pos;
|
|
145 |
StationID targetairport;
|
|
146 |
byte state;
|
|
147 |
};
|
|
148 |
|
|
149 |
struct VehicleRoad {
|
|
150 |
byte state; ///< @see RoadVehicleStates
|
|
151 |
byte frame;
|
|
152 |
uint16 blocked_ctr;
|
|
153 |
byte overtaking;
|
|
154 |
byte overtaking_ctr;
|
|
155 |
uint16 crashed_ctr;
|
|
156 |
byte reverse_ctr;
|
|
157 |
struct RoadStop *slot;
|
|
158 |
byte slot_age;
|
|
159 |
EngineID first_engine;
|
|
160 |
byte cached_veh_length;
|
|
161 |
|
|
162 |
RoadType roadtype;
|
|
163 |
RoadTypes compatible_roadtypes;
|
|
164 |
};
|
|
165 |
|
|
166 |
struct VehicleSpecial {
|
|
167 |
uint16 animation_state;
|
|
168 |
byte animation_substate;
|
|
169 |
};
|
|
170 |
|
|
171 |
struct VehicleDisaster {
|
|
172 |
uint16 image_override;
|
|
173 |
VehicleID big_ufo_destroyer_target;
|
|
174 |
};
|
|
175 |
|
|
176 |
struct VehicleShip {
|
|
177 |
TrackBitsByte state;
|
|
178 |
};
|
|
179 |
|
|
180 |
DECLARE_OLD_POOL(Vehicle, Vehicle, 9, 125)
|
|
181 |
|
|
182 |
/* Some declarations of functions, so we can make them friendly */
|
|
183 |
struct SaveLoad;
|
|
184 |
extern const SaveLoad *GetVehicleDescription(VehicleType vt);
|
|
185 |
extern void AfterLoadVehicles(bool clear_te_id);
|
|
186 |
struct LoadgameState;
|
|
187 |
extern bool LoadOldVehicle(LoadgameState *ls, int num);
|
|
188 |
|
|
189 |
struct Vehicle : PoolItem<Vehicle, VehicleID, &_Vehicle_pool>, BaseVehicle {
|
|
190 |
byte subtype; // subtype (Filled with values from EffectVehicles/TrainSubTypes/AircraftSubTypes)
|
|
191 |
|
|
192 |
private:
|
|
193 |
Vehicle *next; // pointer to the next vehicle in the chain
|
|
194 |
Vehicle *previous; // NOSAVE: pointer to the previous vehicle in the chain
|
|
195 |
Vehicle *first; // NOSAVE: pointer to the first vehicle in the chain
|
|
196 |
public:
|
|
197 |
friend const SaveLoad *GetVehicleDescription(VehicleType vt); // So we can use private/protected variables in the saveload code
|
|
198 |
friend void AfterLoadVehicles(bool clear_te_id); // So we can set the previous and first pointers while loading
|
|
199 |
friend bool LoadOldVehicle(LoadgameState *ls, int num); // So we can set the proper next pointer while loading
|
|
200 |
|
|
201 |
Vehicle *depot_list; // NOSAVE: linked list to tell what vehicles entered a depot during the last tick. Used by autoreplace
|
|
202 |
|
|
203 |
StringID string_id; // Displayed string
|
|
204 |
|
|
205 |
UnitID unitnumber; // unit number, for display purposes only
|
|
206 |
PlayerByte owner; // which player owns the vehicle?
|
|
207 |
|
|
208 |
TileIndex tile; // Current tile index
|
|
209 |
TileIndex dest_tile; // Heading for this tile
|
|
210 |
|
|
211 |
int32 x_pos; // coordinates
|
|
212 |
int32 y_pos;
|
|
213 |
byte z_pos;
|
|
214 |
DirectionByte direction; // facing
|
|
215 |
|
|
216 |
byte spritenum; // currently displayed sprite index
|
|
217 |
// 0xfd == custom sprite, 0xfe == custom second head sprite
|
|
218 |
// 0xff == reserved for another custom sprite
|
|
219 |
uint16 cur_image; // sprite number for this vehicle
|
|
220 |
byte sprite_width; // width of vehicle sprite
|
|
221 |
byte sprite_height; // height of vehicle sprite
|
|
222 |
byte z_height; // z-height of vehicle sprite
|
|
223 |
int8 x_offs; // x offset for vehicle sprite
|
|
224 |
int8 y_offs; // y offset for vehicle sprite
|
|
225 |
EngineID engine_type;
|
|
226 |
|
|
227 |
TextEffectID fill_percent_te_id; // a text-effect id to a loading indicator object
|
|
228 |
|
|
229 |
/* for randomized variational spritegroups
|
|
230 |
* bitmask used to resolve them; parts of it get reseeded when triggers
|
|
231 |
* of corresponding spritegroups get matched */
|
|
232 |
byte random_bits;
|
|
233 |
byte waiting_triggers; // triggers to be yet matched
|
|
234 |
|
|
235 |
uint16 max_speed; // maximum speed
|
|
236 |
uint16 cur_speed; // current speed
|
|
237 |
byte subspeed; // fractional speed
|
|
238 |
byte acceleration; // used by train & aircraft
|
|
239 |
byte progress;
|
|
240 |
uint32 motion_counter;
|
|
241 |
|
|
242 |
byte vehstatus; // Status
|
|
243 |
StationID last_station_visited;
|
|
244 |
|
|
245 |
CargoID cargo_type; // type of cargo this vehicle is carrying
|
|
246 |
uint16 cargo_cap; // total capacity
|
|
247 |
byte cargo_subtype; ///< Used for livery refits (NewGRF variations)
|
|
248 |
CargoList cargo; ///< The cargo this vehicle is carrying
|
|
249 |
|
|
250 |
|
|
251 |
byte day_counter; // increased by one for each day
|
|
252 |
byte tick_counter; // increased by one for each tick
|
|
253 |
|
|
254 |
/* Begin Order-stuff */
|
|
255 |
Order current_order; ///< The current order (+ status, like: loading)
|
|
256 |
VehicleOrderID cur_order_index; ///< The index to the current order
|
|
257 |
|
|
258 |
Order *orders; ///< Pointer to the first order for this vehicle
|
|
259 |
VehicleOrderID num_orders; ///< How many orders there are in the list
|
|
260 |
|
|
261 |
Vehicle *next_shared; ///< If not NULL, this points to the next vehicle that shared the order
|
|
262 |
Vehicle *prev_shared; ///< If not NULL, this points to the prev vehicle that shared the order
|
|
263 |
/* End Order-stuff */
|
|
264 |
|
|
265 |
/* Boundaries for the current position in the world and a next hash link.
|
|
266 |
* NOSAVE: All of those can be updated with VehiclePositionChanged() */
|
|
267 |
int32 left_coord;
|
|
268 |
int32 top_coord;
|
|
269 |
int32 right_coord;
|
|
270 |
int32 bottom_coord;
|
|
271 |
Vehicle *next_hash;
|
|
272 |
Vehicle *next_new_hash;
|
|
273 |
Vehicle **old_new_hash;
|
|
274 |
|
|
275 |
/* Related to age and service time */
|
|
276 |
Date age; // Age in days
|
|
277 |
Date max_age; // Maximum age
|
|
278 |
Date date_of_last_service;
|
|
279 |
Date service_interval;
|
|
280 |
uint16 reliability;
|
|
281 |
uint16 reliability_spd_dec;
|
|
282 |
byte breakdown_ctr;
|
|
283 |
byte breakdown_delay;
|
|
284 |
byte breakdowns_since_last_service;
|
|
285 |
byte breakdown_chance;
|
|
286 |
Year build_year;
|
|
287 |
|
|
288 |
bool leave_depot_instantly; // NOSAVE: stores if the vehicle needs to leave the depot it just entered. Used by autoreplace
|
|
289 |
|
|
290 |
uint16 load_unload_time_rem;
|
|
291 |
byte vehicle_flags; // Used for gradual loading and other miscellaneous things (@see VehicleFlags enum)
|
|
292 |
|
|
293 |
Money profit_this_year;
|
|
294 |
Money profit_last_year;
|
|
295 |
Money value;
|
|
296 |
|
|
297 |
GroupID group_id; ///< Index of group Pool array
|
|
298 |
|
|
299 |
/* Used for timetabling. */
|
|
300 |
uint32 current_order_time; ///< How many ticks have passed since this order started.
|
|
301 |
int32 lateness_counter; ///< How many ticks late (or early if negative) this vehicle is.
|
|
302 |
|
|
303 |
SpriteID colormap; // NOSAVE: cached color mapping
|
|
304 |
|
|
305 |
union {
|
|
306 |
VehicleRail rail;
|
|
307 |
VehicleAir air;
|
|
308 |
VehicleRoad road;
|
|
309 |
VehicleSpecial special;
|
|
310 |
VehicleDisaster disaster;
|
|
311 |
VehicleShip ship;
|
|
312 |
} u;
|
|
313 |
|
|
314 |
|
|
315 |
/**
|
|
316 |
* Allocates a lot of vehicles.
|
|
317 |
* @param vl pointer to an array of vehicles to get allocated. Can be NULL if the vehicles aren't needed (makes it test only)
|
|
318 |
* @param num number of vehicles to allocate room for
|
|
319 |
* @return true if there is room to allocate all the vehicles
|
|
320 |
*/
|
|
321 |
static bool AllocateList(Vehicle **vl, int num);
|
|
322 |
|
|
323 |
/** Create a new vehicle */
|
|
324 |
Vehicle();
|
|
325 |
|
|
326 |
/** Destroy all stuff that (still) needs the virtual functions to work properly */
|
|
327 |
void PreDestructor();
|
|
328 |
/** We want to 'destruct' the right class. */
|
|
329 |
virtual ~Vehicle();
|
|
330 |
|
|
331 |
void BeginLoading();
|
|
332 |
void LeaveStation();
|
|
333 |
|
|
334 |
/**
|
|
335 |
* Handle the loading of the vehicle; when not it skips through dummy
|
|
336 |
* orders and does nothing in all other cases.
|
|
337 |
* @param mode is the non-first call for this vehicle in this tick?
|
|
338 |
*/
|
|
339 |
void HandleLoading(bool mode = false);
|
|
340 |
|
|
341 |
/**
|
|
342 |
* Get a string 'representation' of the vehicle type.
|
|
343 |
* @return the string representation.
|
|
344 |
*/
|
|
345 |
virtual const char* GetTypeString() const { return "base vehicle"; }
|
|
346 |
|
|
347 |
/**
|
|
348 |
* Marks the vehicles to be redrawn and updates cached variables
|
|
349 |
*
|
|
350 |
* This method marks the area of the vehicle on the screen as dirty.
|
|
351 |
* It can be use to repaint the vehicle.
|
|
352 |
*
|
|
353 |
* @ingroup dirty
|
|
354 |
*/
|
|
355 |
virtual void MarkDirty() {}
|
|
356 |
|
|
357 |
/**
|
|
358 |
* Updates the x and y offsets and the size of the sprite used
|
|
359 |
* for this vehicle.
|
|
360 |
* @param direction the direction the vehicle is facing
|
|
361 |
*/
|
|
362 |
virtual void UpdateDeltaXY(Direction direction) {}
|
|
363 |
|
|
364 |
/**
|
|
365 |
* Sets the expense type associated to this vehicle type
|
|
366 |
* @param income whether this is income or (running) expenses of the vehicle
|
|
367 |
*/
|
|
368 |
virtual ExpensesType GetExpenseType(bool income) const { return EXPENSES_OTHER; }
|
|
369 |
|
|
370 |
/**
|
|
371 |
* Invalidates the vehicle list window of this type of vehicle
|
|
372 |
*/
|
|
373 |
virtual WindowClass GetVehicleListWindowClass() const { return WC_NONE; }
|
|
374 |
|
|
375 |
/**
|
|
376 |
* Play the sound associated with leaving the station
|
|
377 |
*/
|
|
378 |
virtual void PlayLeaveStationSound() const {}
|
|
379 |
|
|
380 |
/**
|
|
381 |
* Whether this is the primary vehicle in the chain.
|
|
382 |
*/
|
|
383 |
virtual bool IsPrimaryVehicle() const { return false; }
|
|
384 |
|
|
385 |
/**
|
|
386 |
* Gets the sprite to show for the given direction
|
|
387 |
* @param direction the direction the vehicle is facing
|
|
388 |
* @return the sprite for the given vehicle in the given direction
|
|
389 |
*/
|
|
390 |
virtual int GetImage(Direction direction) const { return 0; }
|
|
391 |
|
|
392 |
/**
|
|
393 |
* Gets the speed in mph that can be sent into SetDParam for string processing.
|
|
394 |
* @return the vehicle's speed
|
|
395 |
*/
|
|
396 |
virtual int GetDisplaySpeed() const { return 0; }
|
|
397 |
|
|
398 |
/**
|
|
399 |
* Gets the maximum speed in mph that can be sent into SetDParam for string processing.
|
|
400 |
* @return the vehicle's maximum speed
|
|
401 |
*/
|
|
402 |
virtual int GetDisplayMaxSpeed() const { return 0; }
|
|
403 |
|
|
404 |
/**
|
|
405 |
* Gets the running cost of a vehicle
|
|
406 |
* @return the vehicle's running cost
|
|
407 |
*/
|
|
408 |
virtual Money GetRunningCost() const { return 0; }
|
|
409 |
|
|
410 |
/**
|
|
411 |
* Check whether the vehicle is in the depot.
|
|
412 |
* @return true if and only if the vehicle is in the depot.
|
|
413 |
*/
|
|
414 |
virtual bool IsInDepot() const { return false; }
|
|
415 |
|
|
416 |
/**
|
|
417 |
* Check whether the vehicle is in the depot *and* stopped.
|
|
418 |
* @return true if and only if the vehicle is in the depot and stopped.
|
|
419 |
*/
|
|
420 |
virtual bool IsStoppedInDepot() const { return this->IsInDepot() && (this->vehstatus & VS_STOPPED) != 0; }
|
|
421 |
|
|
422 |
/**
|
|
423 |
* Calls the tick handler of the vehicle
|
|
424 |
*/
|
|
425 |
virtual void Tick() {};
|
|
426 |
|
|
427 |
/**
|
|
428 |
* Gets the running cost of a vehicle that can be sent into SetDParam for string processing.
|
|
429 |
* @return the vehicle's running cost
|
|
430 |
*/
|
|
431 |
Money GetDisplayRunningCost() const { return (this->GetRunningCost() >> 8); }
|
|
432 |
|
|
433 |
/**
|
|
434 |
* Set the next vehicle of this vehicle.
|
|
435 |
* @param next the next vehicle. NULL removes the next vehicle.
|
|
436 |
*/
|
|
437 |
void SetNext(Vehicle *next);
|
|
438 |
|
|
439 |
/**
|
|
440 |
* Get the next vehicle of this vehicle.
|
|
441 |
* @note articulated parts are also counted as vehicles.
|
|
442 |
* @return the next vehicle or NULL when there isn't a next vehicle.
|
|
443 |
*/
|
|
444 |
inline Vehicle *Next() const { return this->next; }
|
|
445 |
|
|
446 |
/**
|
|
447 |
* Get the previous vehicle of this vehicle.
|
|
448 |
* @note articulated parts are also counted as vehicles.
|
|
449 |
* @return the previous vehicle or NULL when there isn't a previous vehicle.
|
|
450 |
*/
|
|
451 |
inline Vehicle *Previous() const { return this->previous; }
|
|
452 |
|
|
453 |
/**
|
|
454 |
* Get the first vehicle of this vehicle chain.
|
|
455 |
* @return the first vehicle of the chain.
|
|
456 |
*/
|
|
457 |
inline Vehicle *First() const { return this->first; }
|
|
458 |
};
|
|
459 |
|
|
460 |
/**
|
|
461 |
* This class 'wraps' Vehicle; you do not actually instantiate this class.
|
|
462 |
* You create a Vehicle using AllocateVehicle, so it is added to the pool
|
|
463 |
* and you reinitialize that to a Train using:
|
|
464 |
* v = new (v) Train();
|
|
465 |
*
|
|
466 |
* As side-effect the vehicle type is set correctly.
|
|
467 |
*
|
|
468 |
* A special vehicle is one of the following:
|
|
469 |
* - smoke
|
|
470 |
* - electric sparks for trains
|
|
471 |
* - explosions
|
|
472 |
* - bulldozer (road works)
|
|
473 |
* - bubbles (industry)
|
|
474 |
*/
|
|
475 |
struct SpecialVehicle : public Vehicle {
|
|
476 |
/** Initializes the Vehicle to a special vehicle */
|
|
477 |
SpecialVehicle() { this->type = VEH_SPECIAL; }
|
|
478 |
|
|
479 |
/** We want to 'destruct' the right class. */
|
|
480 |
virtual ~SpecialVehicle() {}
|
|
481 |
|
|
482 |
const char *GetTypeString() const { return "special vehicle"; }
|
|
483 |
void UpdateDeltaXY(Direction direction);
|
|
484 |
void Tick();
|
|
485 |
};
|
|
486 |
|
|
487 |
/**
|
|
488 |
* This class 'wraps' Vehicle; you do not actually instantiate this class.
|
|
489 |
* You create a Vehicle using AllocateVehicle, so it is added to the pool
|
|
490 |
* and you reinitialize that to a Train using:
|
|
491 |
* v = new (v) Train();
|
|
492 |
*
|
|
493 |
* As side-effect the vehicle type is set correctly.
|
|
494 |
*/
|
|
495 |
struct DisasterVehicle : public Vehicle {
|
|
496 |
/** Initializes the Vehicle to a disaster vehicle */
|
|
497 |
DisasterVehicle() { this->type = VEH_DISASTER; }
|
|
498 |
|
|
499 |
/** We want to 'destruct' the right class. */
|
|
500 |
virtual ~DisasterVehicle() {}
|
|
501 |
|
|
502 |
const char *GetTypeString() const { return "disaster vehicle"; }
|
|
503 |
void UpdateDeltaXY(Direction direction);
|
|
504 |
void Tick();
|
|
505 |
};
|
|
506 |
|
|
507 |
/**
|
|
508 |
* This class 'wraps' Vehicle; you do not actually instantiate this class.
|
|
509 |
* You create a Vehicle using AllocateVehicle, so it is added to the pool
|
|
510 |
* and you reinitialize that to a Train using:
|
|
511 |
* v = new (v) Train();
|
|
512 |
*
|
|
513 |
* As side-effect the vehicle type is set correctly.
|
|
514 |
*/
|
|
515 |
struct InvalidVehicle : public Vehicle {
|
|
516 |
/** Initializes the Vehicle to a invalid vehicle */
|
|
517 |
InvalidVehicle() { this->type = VEH_INVALID; }
|
|
518 |
|
|
519 |
/** We want to 'destruct' the right class. */
|
|
520 |
virtual ~InvalidVehicle() {}
|
|
521 |
|
|
522 |
const char *GetTypeString() const { return "invalid vehicle"; }
|
|
523 |
void Tick() {}
|
|
524 |
};
|
|
525 |
|
|
526 |
#define BEGIN_ENUM_WAGONS(v) do {
|
|
527 |
#define END_ENUM_WAGONS(v) } while ((v = v->Next()) != NULL);
|
|
528 |
|
|
529 |
static inline VehicleID GetMaxVehicleIndex()
|
|
530 |
{
|
|
531 |
/* TODO - This isn't the real content of the function, but
|
|
532 |
* with the new pool-system this will be replaced with one that
|
|
533 |
* _really_ returns the highest index. Now it just returns
|
|
534 |
* the next safe value we are sure about everything is below.
|
|
535 |
*/
|
|
536 |
return GetVehiclePoolSize() - 1;
|
|
537 |
}
|
|
538 |
|
|
539 |
static inline uint GetNumVehicles()
|
|
540 |
{
|
|
541 |
return GetVehiclePoolSize();
|
|
542 |
}
|
|
543 |
|
|
544 |
#define FOR_ALL_VEHICLES_FROM(v, start) for (v = GetVehicle(start); v != NULL; v = (v->index + 1U < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) if (v->IsValid())
|
|
545 |
#define FOR_ALL_VEHICLES(v) FOR_ALL_VEHICLES_FROM(v, 0)
|
|
546 |
|
|
547 |
/**
|
|
548 |
* Check if an index is a vehicle-index (so between 0 and max-vehicles)
|
|
549 |
* @param index of the vehicle to query
|
|
550 |
* @return Returns true if the vehicle-id is in range
|
|
551 |
*/
|
|
552 |
static inline bool IsValidVehicleID(uint index)
|
|
553 |
{
|
|
554 |
return index < GetVehiclePoolSize() && GetVehicle(index)->IsValid();
|
|
555 |
}
|
|
556 |
|
|
557 |
/* Returns order 'index' of a vehicle or NULL when it doesn't exists */
|
|
558 |
static inline Order *GetVehicleOrder(const Vehicle *v, int index)
|
|
559 |
{
|
|
560 |
Order *order = v->orders;
|
|
561 |
|
|
562 |
if (index < 0) return NULL;
|
|
563 |
|
|
564 |
while (order != NULL && index-- > 0)
|
|
565 |
order = order->next;
|
|
566 |
|
|
567 |
return order;
|
|
568 |
}
|
|
569 |
|
|
570 |
/**
|
|
571 |
* Returns the last order of a vehicle, or NULL if it doesn't exists
|
|
572 |
* @param v Vehicle to query
|
|
573 |
* @return last order of a vehicle, if available
|
|
574 |
*/
|
|
575 |
static inline Order *GetLastVehicleOrder(const Vehicle *v)
|
|
576 |
{
|
|
577 |
Order *order = v->orders;
|
|
578 |
|
|
579 |
if (order == NULL) return NULL;
|
|
580 |
|
|
581 |
while (order->next != NULL)
|
|
582 |
order = order->next;
|
|
583 |
|
|
584 |
return order;
|
|
585 |
}
|
|
586 |
|
|
587 |
/** Get the first vehicle of a shared-list, so we only have to walk forwards
|
|
588 |
* @param v Vehicle to query
|
|
589 |
* @return first vehicle of a shared-list
|
|
590 |
*/
|
|
591 |
static inline Vehicle *GetFirstVehicleFromSharedList(const Vehicle *v)
|
|
592 |
{
|
|
593 |
Vehicle *u = (Vehicle *)v;
|
|
594 |
while (u->prev_shared != NULL) u = u->prev_shared;
|
|
595 |
|
|
596 |
return u;
|
|
597 |
}
|
|
598 |
|
|
599 |
/**
|
|
600 |
* Returns the Trackdir on which the vehicle is currently located.
|
|
601 |
* Works for trains and ships.
|
|
602 |
* Currently works only sortof for road vehicles, since they have a fuzzy
|
|
603 |
* concept of being "on" a trackdir. Dunno really what it returns for a road
|
|
604 |
* vehicle that is halfway a tile, never really understood that part. For road
|
|
605 |
* vehicles that are at the beginning or end of the tile, should just return
|
|
606 |
* the diagonal trackdir on which they are driving. I _think_.
|
|
607 |
* For other vehicles types, or vehicles with no clear trackdir (such as those
|
|
608 |
* in depots), returns 0xFF.
|
|
609 |
*/
|
|
610 |
Trackdir GetVehicleTrackdir(const Vehicle* v);
|
|
611 |
|
|
612 |
void CheckVehicle32Day(Vehicle *v);
|
|
613 |
|
|
614 |
#endif /* VEHICLE_BASE_H */
|