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