author | celestar |
Tue, 29 Mar 2005 11:19:10 +0000 | |
changeset 1601 | 9fd461d00287 |
parent 1587 | e6bcc5a3cb86 |
child 1605 | c4630be67467 |
permissions | -rw-r--r-- |
0 | 1 |
#ifndef VEHICLE_H |
2 |
#define VEHICLE_H |
|
3 |
||
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
4 |
#include "pool.h" |
164
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
156
diff
changeset
|
5 |
#include "vehicle_gui.h" |
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
6 |
#include "order.h" |
577 | 7 |
|
0 | 8 |
typedef struct VehicleRail { |
9 |
uint16 last_speed; // NOSAVE: only used in UI |
|
10 |
uint16 crash_anim_pos; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
11 |
uint16 days_since_order_progr; |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
12 |
|
0 | 13 |
uint16 cached_weight; // cached power and weight for the vehicle. |
14 |
uint32 cached_power; // no need to save those, they are recomputed on load. |
|
15 |
||
16 |
// NOSAVE: for wagon override - id of the first engine in train |
|
17 |
// 0xffff == not in train |
|
18 |
uint16 first_engine; |
|
19 |
||
20 |
byte track; |
|
21 |
byte force_proceed; |
|
22 |
byte railtype; |
|
23 |
||
24 |
byte flags; |
|
25 |
} VehicleRail; |
|
26 |
||
27 |
enum { |
|
954
4d052517a993
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
941
diff
changeset
|
28 |
VRF_REVERSING = 0, |
0 | 29 |
|
30 |
// used to calculate if train is going up or down |
|
954
4d052517a993
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
941
diff
changeset
|
31 |
VRF_GOINGUP = 1, |
4d052517a993
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
941
diff
changeset
|
32 |
VRF_GOINGDOWN = 2, |
0 | 33 |
}; |
34 |
||
35 |
typedef struct VehicleAir { |
|
36 |
uint16 crashed_counter; |
|
37 |
byte pos; |
|
38 |
byte previous_pos; |
|
817
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
39 |
uint16 targetairport; |
0 | 40 |
byte state; |
41 |
} VehicleAir; |
|
42 |
||
43 |
typedef struct VehicleRoad { |
|
44 |
byte state; |
|
45 |
byte frame; |
|
46 |
uint16 unk2; |
|
47 |
byte overtaking; |
|
48 |
byte overtaking_ctr; |
|
49 |
uint16 crashed_ctr; |
|
50 |
byte reverse_ctr; |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1174
diff
changeset
|
51 |
struct RoadStop *slot; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1174
diff
changeset
|
52 |
byte slotindex; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1174
diff
changeset
|
53 |
byte slot_age; |
0 | 54 |
} VehicleRoad; |
55 |
||
56 |
typedef struct VehicleSpecial { |
|
57 |
uint16 unk0; |
|
58 |
byte unk2; |
|
59 |
} VehicleSpecial; |
|
60 |
||
61 |
typedef struct VehicleDisaster { |
|
62 |
uint16 image_override; |
|
63 |
uint16 unk2; |
|
64 |
} VehicleDisaster; |
|
65 |
||
66 |
typedef struct VehicleShip { |
|
67 |
byte state; |
|
68 |
} VehicleShip; |
|
69 |
||
70 |
// not used ATM |
|
71 |
struct WorldSprite { |
|
72 |
struct WorldSprite *next; // next sprite in hash chain |
|
73 |
uint16 image; // sprite number for this vehicle |
|
74 |
||
75 |
// screen coordinates |
|
76 |
int16 left, top, right, bottom; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
77 |
|
0 | 78 |
// world coordinates |
79 |
int16 x; |
|
80 |
int16 y; |
|
81 |
byte z; |
|
82 |
||
83 |
int8 x_offs; // x offset for vehicle sprite |
|
84 |
int8 y_offs; // y offset for vehicle sprite |
|
85 |
||
86 |
byte width; // width of vehicle sprite |
|
87 |
byte height; // height of vehicle sprite |
|
88 |
byte depth; // depth of vehicle sprite |
|
89 |
||
90 |
byte flags; // draw flags |
|
91 |
}; |
|
92 |
||
93 |
struct Vehicle { |
|
94 |
byte type; // type, ie roadven,train,ship,aircraft,special |
|
22 | 95 |
byte subtype; // subtype (for trains, 0 == loco, 4 wagon ??) |
0 | 96 |
|
97 |
uint16 index; // NOSAVE: Index in vehicle array |
|
98 |
||
99 |
Vehicle *next; // next |
|
1601
9fd461d00287
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1587
diff
changeset
|
100 |
Vehicle *first; // NOSAVE: pointer to the first vehicle in the chain |
0 | 101 |
|
102 |
StringID string_id; // Displayed string |
|
103 |
||
1282
e7a73ee62d2f
(svn r1786) -Fix: unitnumber is increased to 16bit, so now you can have up to 5000
truelight
parents:
1279
diff
changeset
|
104 |
UnitID unitnumber; // unit number, for display purposes only |
0 | 105 |
byte owner; // which player owns the vehicle? |
106 |
||
107 |
TileIndex tile; // Current tile index |
|
108 |
TileIndex dest_tile; // Heading for this tile |
|
109 |
||
1174
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1139
diff
changeset
|
110 |
int32 x_pos; // coordinates |
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1139
diff
changeset
|
111 |
int32 y_pos; |
0 | 112 |
byte z_pos; |
113 |
byte direction; // facing |
|
114 |
||
115 |
byte spritenum; // currently displayed sprite index |
|
116 |
// 0xfd == custom sprite, 0xfe == custom second head sprite |
|
117 |
// 0xff == reserved for another custom sprite |
|
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
395
diff
changeset
|
118 |
uint16 cur_image; // sprite number for this vehicle |
0 | 119 |
byte sprite_width;// width of vehicle sprite |
120 |
byte sprite_height;// height of vehicle sprite |
|
121 |
byte z_height; // z-height of vehicle sprite |
|
122 |
int8 x_offs; // x offset for vehicle sprite |
|
123 |
int8 y_offs; // y offset for vehicle sprite |
|
124 |
uint16 engine_type; |
|
125 |
||
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
395
diff
changeset
|
126 |
// for randomized variational spritegroups |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
395
diff
changeset
|
127 |
// bitmask used to resolve them; parts of it get reseeded when triggers |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
395
diff
changeset
|
128 |
// of corresponding spritegroups get matched |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
395
diff
changeset
|
129 |
byte random_bits; |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
395
diff
changeset
|
130 |
byte waiting_triggers; // triggers to be yet matched |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
395
diff
changeset
|
131 |
|
0 | 132 |
uint16 max_speed; // maximum speed |
133 |
uint16 cur_speed; // current speed |
|
134 |
byte subspeed; // fractional speed |
|
135 |
byte acceleration; // used by train & aircraft |
|
136 |
byte progress; |
|
137 |
||
138 |
byte vehstatus; // Status |
|
817
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
139 |
uint16 last_station_visited; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
140 |
|
0 | 141 |
byte cargo_type; // type of cargo this vehicle is carrying |
142 |
byte cargo_days; // how many days have the pieces been in transit |
|
1266
9dc5638fe8cc
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1237
diff
changeset
|
143 |
uint16 cargo_source;// source of cargo |
0 | 144 |
uint16 cargo_cap; // total capacity |
145 |
uint16 cargo_count;// how many pieces are used |
|
146 |
||
147 |
byte day_counter; // increased by one for each day |
|
148 |
byte tick_counter;// increased by one for each tick |
|
149 |
||
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
150 |
/* Begin Order-stuff */ |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
151 |
Order current_order; //! The current order (+ status, like: loading) |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
152 |
byte cur_order_index; //! The index to the current order |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
153 |
|
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
154 |
Order *orders; //! Pointer to the first order for this vehicle |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
155 |
byte num_orders; //! How many orders there are in the list |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
156 |
|
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
157 |
Vehicle *next_shared; //! If not NULL, this points to the next vehicle that shared the order |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
158 |
Vehicle *prev_shared; //! If not NULL, this points to the prev vehicle that shared the order |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
159 |
/* End Order-stuff */ |
0 | 160 |
|
161 |
// Boundaries for the current position in the world and a next hash link. |
|
162 |
// NOSAVE: All of those can be updated with VehiclePositionChanged() |
|
849
c6223dbdb202
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
842
diff
changeset
|
163 |
int32 left_coord; |
c6223dbdb202
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
842
diff
changeset
|
164 |
int32 top_coord; |
c6223dbdb202
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
842
diff
changeset
|
165 |
int32 right_coord; |
c6223dbdb202
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
842
diff
changeset
|
166 |
int32 bottom_coord; |
0 | 167 |
uint16 next_hash; |
168 |
||
169 |
// Related to age and service time |
|
170 |
uint16 age; // Age in days |
|
171 |
uint16 max_age; // Maximum age |
|
172 |
uint16 date_of_last_service; |
|
173 |
uint16 service_interval; |
|
174 |
uint16 reliability; |
|
175 |
uint16 reliability_spd_dec; |
|
176 |
byte breakdown_ctr; |
|
177 |
byte breakdown_delay; |
|
178 |
byte breakdowns_since_last_service; |
|
179 |
byte breakdown_chance; |
|
180 |
byte build_year; |
|
181 |
||
182 |
uint16 load_unload_time_rem; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
183 |
|
0 | 184 |
int32 profit_this_year; |
185 |
int32 profit_last_year; |
|
186 |
uint32 value; |
|
187 |
||
188 |
union { |
|
189 |
VehicleRail rail; |
|
190 |
VehicleAir air; |
|
191 |
VehicleRoad road; |
|
192 |
VehicleSpecial special; |
|
193 |
VehicleDisaster disaster; |
|
194 |
VehicleShip ship; |
|
195 |
} u; |
|
196 |
}; |
|
197 |
||
198 |
#define is_custom_sprite(x) (x >= 0xfd) |
|
199 |
#define is_custom_firsthead_sprite(x) (x == 0xfd) |
|
200 |
#define is_custom_secondhead_sprite(x) (x == 0xfe) |
|
201 |
||
202 |
enum { |
|
203 |
VEH_Train = 0x10, |
|
204 |
VEH_Road = 0x11, |
|
205 |
VEH_Ship = 0x12, |
|
206 |
VEH_Aircraft = 0x13, |
|
207 |
VEH_Special = 0x14, |
|
208 |
VEH_Disaster = 0x15, |
|
209 |
}; |
|
210 |
||
211 |
enum VehStatus { |
|
212 |
VS_HIDDEN = 1, |
|
213 |
VS_STOPPED = 2, |
|
214 |
VS_UNCLICKABLE = 4, |
|
215 |
VS_DEFPAL = 0x8, |
|
216 |
VS_TRAIN_SLOWING = 0x10, |
|
217 |
VS_DISASTER = 0x20, |
|
218 |
VS_AIRCRAFT_BROKEN = 0x40, |
|
219 |
VS_CRASHED = 0x80, |
|
220 |
}; |
|
221 |
||
1067
a083a6dd1419
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1060
diff
changeset
|
222 |
// 1 and 3 do not appear to be used |
a083a6dd1419
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1060
diff
changeset
|
223 |
enum TrainSubtype { |
a083a6dd1419
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1060
diff
changeset
|
224 |
TS_Front_Engine = 0, |
a083a6dd1419
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1060
diff
changeset
|
225 |
TS_Not_First = 2, |
a083a6dd1419
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1060
diff
changeset
|
226 |
TS_Free_Car = 4, |
a083a6dd1419
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1060
diff
changeset
|
227 |
}; |
0 | 228 |
|
229 |
/* Effect vehicle types */ |
|
1359
8ba976aed634
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1330
diff
changeset
|
230 |
typedef enum EffectVehicle { |
8ba976aed634
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1330
diff
changeset
|
231 |
EV_CHIMNEY_SMOKE = 0, |
8ba976aed634
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1330
diff
changeset
|
232 |
EV_STEAM_SMOKE = 1, |
8ba976aed634
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1330
diff
changeset
|
233 |
EV_DIESEL_SMOKE = 2, |
8ba976aed634
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1330
diff
changeset
|
234 |
EV_ELECTRIC_SPARK = 3, |
8ba976aed634
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1330
diff
changeset
|
235 |
EV_SMOKE = 4, |
8ba976aed634
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1330
diff
changeset
|
236 |
EV_EXPLOSION_LARGE = 5, |
0 | 237 |
EV_BREAKDOWN_SMOKE = 6, |
1359
8ba976aed634
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1330
diff
changeset
|
238 |
EV_EXPLOSION_SMALL = 7, |
8ba976aed634
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1330
diff
changeset
|
239 |
EV_BULLDOZER = 8, |
8ba976aed634
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1330
diff
changeset
|
240 |
EV_BUBBLE = 9 |
8ba976aed634
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1330
diff
changeset
|
241 |
} EffectVehicle; |
0 | 242 |
|
243 |
typedef void VehicleTickProc(Vehicle *v); |
|
244 |
typedef void *VehicleFromPosProc(Vehicle *v, void *data); |
|
245 |
||
578
86e352980acd
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
577
diff
changeset
|
246 |
void VehicleServiceInDepot(Vehicle *v); |
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1067
diff
changeset
|
247 |
Vehicle *AllocateVehicle(void); |
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1067
diff
changeset
|
248 |
Vehicle *ForceAllocateVehicle(void); |
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1067
diff
changeset
|
249 |
Vehicle *ForceAllocateSpecialVehicle(void); |
0 | 250 |
void UpdateVehiclePosHash(Vehicle *v, int x, int y); |
251 |
void VehiclePositionChanged(Vehicle *v); |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1067
diff
changeset
|
252 |
void AfterLoadVehicles(void); |
0 | 253 |
Vehicle *GetLastVehicleInChain(Vehicle *v); |
1475 | 254 |
Vehicle *GetPrevVehicleInChain(const Vehicle *v); |
255 |
Vehicle *GetFirstVehicleInChain(const Vehicle *v); |
|
0 | 256 |
int CountVehiclesInChain(Vehicle *v); |
257 |
void DeleteVehicle(Vehicle *v); |
|
258 |
void DeleteVehicleChain(Vehicle *v); |
|
259 |
void *VehicleFromPos(TileIndex tile, void *data, VehicleFromPosProc *proc); |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1067
diff
changeset
|
260 |
void CallVehicleTicks(void); |
0 | 261 |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1067
diff
changeset
|
262 |
void InitializeTrains(void); |
0 | 263 |
|
264 |
bool CanFillVehicle(Vehicle *v); |
|
265 |
||
266 |
void ViewportAddVehicles(DrawPixelInfo *dpi); |
|
267 |
||
268 |
void TrainEnterDepot(Vehicle *v, uint tile); |
|
269 |
||
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1055
diff
changeset
|
270 |
void AddRearEngineToMultiheadedTrain(Vehicle *v, Vehicle *u, bool building) ; |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1055
diff
changeset
|
271 |
|
0 | 272 |
/* train_cmd.h */ |
1475 | 273 |
int GetTrainImage(const Vehicle *v, byte direction); |
0 | 274 |
int GetAircraftImage(Vehicle *v, byte direction); |
275 |
int GetRoadVehImage(Vehicle *v, byte direction); |
|
276 |
int GetShipImage(Vehicle *v, byte direction); |
|
277 |
||
1359
8ba976aed634
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1330
diff
changeset
|
278 |
Vehicle *CreateEffectVehicle(int x, int y, int z, EffectVehicle type); |
8ba976aed634
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1330
diff
changeset
|
279 |
Vehicle *CreateEffectVehicleAbove(int x, int y, int z, EffectVehicle type); |
8ba976aed634
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1330
diff
changeset
|
280 |
Vehicle *CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, EffectVehicle type); |
0 | 281 |
|
282 |
uint32 VehicleEnterTile(Vehicle *v, uint tile, int x, int y); |
|
283 |
||
284 |
void VehicleInTheWayErrMsg(Vehicle *v); |
|
285 |
Vehicle *FindVehicleBetween(TileIndex from, TileIndex to, byte z); |
|
1587
e6bcc5a3cb86
(svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents:
1542
diff
changeset
|
286 |
TileIndex GetVehicleOutOfTunnelTile(const Vehicle *v); |
0 | 287 |
|
288 |
bool UpdateSignalsOnSegment(uint tile, byte direction); |
|
289 |
void SetSignalsOnBothDir(uint tile, byte track); |
|
290 |
||
291 |
Vehicle *CheckClickOnVehicle(ViewPort *vp, int x, int y); |
|
292 |
//uint GetVehicleWeight(Vehicle *v); |
|
293 |
||
294 |
void DecreaseVehicleValue(Vehicle *v); |
|
295 |
void CheckVehicleBreakdown(Vehicle *v); |
|
296 |
void AgeVehicle(Vehicle *v); |
|
842 | 297 |
void MaybeReplaceVehicle(Vehicle *v); |
0 | 298 |
|
299 |
void BeginVehicleMove(Vehicle *v); |
|
300 |
void EndVehicleMove(Vehicle *v); |
|
301 |
||
302 |
bool IsAircraftHangarTile(TileIndex tile); |
|
303 |
void ShowAircraftViewWindow(Vehicle *v); |
|
304 |
||
1282
e7a73ee62d2f
(svn r1786) -Fix: unitnumber is increased to 16bit, so now you can have up to 5000
truelight
parents:
1279
diff
changeset
|
305 |
UnitID GetFreeUnitNumber(byte type); |
0 | 306 |
|
307 |
int LoadUnloadVehicle(Vehicle *v); |
|
308 |
||
309 |
void UpdateTrainAcceleration(Vehicle *v); |
|
310 |
int32 GetTrainRunningCost(Vehicle *v); |
|
311 |
||
1472
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1359
diff
changeset
|
312 |
int CheckTrainStoppedInDepot(const Vehicle *v); |
0 | 313 |
|
593 | 314 |
bool VehicleNeedsService(const Vehicle *v); |
315 |
||
0 | 316 |
typedef struct GetNewVehiclePosResult { |
317 |
int x,y; |
|
318 |
uint old_tile; |
|
319 |
uint new_tile; |
|
320 |
} GetNewVehiclePosResult; |
|
321 |
||
322 |
/* returns true if staying in the same tile */ |
|
323 |
bool GetNewVehiclePos(Vehicle *v, GetNewVehiclePosResult *gp); |
|
324 |
byte GetDirectionTowards(Vehicle *v, int x, int y); |
|
325 |
||
326 |
#define BEGIN_ENUM_WAGONS(v) do { |
|
327 |
#define END_ENUM_WAGONS(v) } while ( (v=v->next) != NULL); |
|
328 |
||
329 |
/* vehicle.c */ |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
849
diff
changeset
|
330 |
VARDEF SortStruct *_vehicle_sort; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
849
diff
changeset
|
331 |
|
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
332 |
extern MemoryPool _vehicle_pool; |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
333 |
|
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
334 |
/** |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
335 |
* Get the pointer to the vehicle with index 'index' |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
336 |
*/ |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
337 |
static inline Vehicle *GetVehicle(VehicleID index) |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
849
diff
changeset
|
338 |
{ |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
339 |
return (Vehicle*)GetItemFromPool(&_vehicle_pool, index); |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
849
diff
changeset
|
340 |
} |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
849
diff
changeset
|
341 |
|
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
342 |
/** |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
343 |
* Get the current size of the VehiclePool |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
344 |
*/ |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
345 |
static inline uint16 GetVehiclePoolSize(void) |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
346 |
{ |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
347 |
return _vehicle_pool.total_items; |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
348 |
} |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
349 |
|
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
350 |
#define FOR_ALL_VEHICLES_FROM(v, start) for (v = GetVehicle(start); v != NULL; v = (v->index + 1 < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
351 |
#define FOR_ALL_VEHICLES(v) FOR_ALL_VEHICLES_FROM(v, 0) |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
352 |
|
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
353 |
/** |
1330
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
354 |
* Check if a Vehicle really exists. |
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
355 |
*/ |
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
356 |
static inline bool IsValidVehicle(Vehicle* v) |
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
357 |
{ |
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
358 |
return v->type != 0; |
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
359 |
} |
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
360 |
|
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
361 |
/** |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
362 |
* Check if an index is a vehicle-index (so between 0 and max-vehicles) |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
363 |
* |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
364 |
* @return Returns true if the vehicle-id is in range |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
365 |
*/ |
1237
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1217
diff
changeset
|
366 |
static inline bool IsVehicleIndex(uint index) |
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1217
diff
changeset
|
367 |
{ |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
368 |
if (index < GetVehiclePoolSize()) |
1237
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1217
diff
changeset
|
369 |
return true; |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
370 |
|
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
371 |
return false; |
1237
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1217
diff
changeset
|
372 |
} |
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1217
diff
changeset
|
373 |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
374 |
/* Returns order 'index' of a vehicle or NULL when it doesn't exists */ |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
375 |
static inline Order *GetVehicleOrder(const Vehicle *v, int index) |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
376 |
{ |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
377 |
Order *order = v->orders; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
378 |
|
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
379 |
if (index < 0) |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
380 |
return NULL; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
381 |
|
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
382 |
while (order != NULL && index-- > 0) |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
383 |
order = order->next; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
384 |
|
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
385 |
return order; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
386 |
} |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
387 |
|
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
388 |
/* Returns the last order of a vehicle, or NULL if it doesn't exists */ |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
389 |
static inline Order *GetLastVehicleOrder(const Vehicle *v) |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
390 |
{ |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
391 |
Order *order = v->orders; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
392 |
|
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
393 |
if (order == NULL) |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
394 |
return NULL; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
395 |
|
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
396 |
while (order->next != NULL) |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
397 |
order = order->next; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
398 |
|
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
399 |
return order; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
400 |
} |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
401 |
|
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
402 |
/* Get the first vehicle of a shared-list, so we only have to walk forwards */ |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
403 |
static inline Vehicle *GetFirstVehicleFromSharedList(Vehicle *v) |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
404 |
{ |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
405 |
Vehicle *u = v; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
406 |
while (u->prev_shared != NULL) |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
407 |
u = u->prev_shared; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
408 |
|
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
409 |
return u; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
410 |
} |
0 | 411 |
|
412 |
// NOSAVE: Can be regenerated by inspecting the vehicles. |
|
413 |
VARDEF VehicleID _vehicle_position_hash[0x1000]; |
|
414 |
||
415 |
// NOSAVE: Return values from various commands. |
|
416 |
VARDEF VehicleID _new_train_id; |
|
417 |
VARDEF VehicleID _new_wagon_id; |
|
418 |
VARDEF VehicleID _new_aircraft_id; |
|
419 |
VARDEF VehicleID _new_ship_id; |
|
420 |
VARDEF VehicleID _new_roadveh_id; |
|
421 |
VARDEF uint16 _aircraft_refit_capacity; |
|
422 |
VARDEF byte _cmd_build_rail_veh_score; |
|
423 |
VARDEF byte _cmd_build_rail_veh_var1; |
|
424 |
||
425 |
// for each player, for each vehicle type, keep a list of the vehicles. |
|
426 |
//VARDEF Vehicle *_vehicle_arr[8][4]; |
|
427 |
||
428 |
#define INVALID_VEHICLE 0xffff |
|
429 |
||
755
823358e83abf
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
593
diff
changeset
|
430 |
/* A lot of code calls for the invalidation of the status bar, which is widget 5. |
823358e83abf
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
593
diff
changeset
|
431 |
* Best is to have a virtual value for it when it needs to change again */ |
823358e83abf
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
593
diff
changeset
|
432 |
#define STATUS_BAR 5 |
823358e83abf
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
593
diff
changeset
|
433 |
|
0 | 434 |
#endif /* VEHICLE_H */ |