author | bjarni |
Sat, 22 Jan 2005 23:55:45 +0000 | |
changeset 1099 | ad7522bd5c1c |
parent 1093 | 4fdc46eaf423 |
child 1139 | 1649055e5e89 |
permissions | -rw-r--r-- |
0 | 1 |
#ifndef VEHICLE_H |
2 |
#define VEHICLE_H |
|
3 |
||
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
|
4 |
#include "vehicle_gui.h" |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
5 |
#include "order.h" |
577 | 6 |
|
0 | 7 |
typedef struct VehicleRail { |
8 |
uint16 last_speed; // NOSAVE: only used in UI |
|
9 |
uint16 crash_anim_pos; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
10 |
uint16 days_since_order_progr; |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
11 |
|
0 | 12 |
uint16 cached_weight; // cached power and weight for the vehicle. |
13 |
uint32 cached_power; // no need to save those, they are recomputed on load. |
|
14 |
||
15 |
// NOSAVE: for wagon override - id of the first engine in train |
|
16 |
// 0xffff == not in train |
|
17 |
uint16 first_engine; |
|
18 |
||
19 |
byte track; |
|
20 |
byte force_proceed; |
|
21 |
byte railtype; |
|
22 |
||
23 |
byte flags; |
|
24 |
} VehicleRail; |
|
25 |
||
26 |
enum { |
|
954
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
941
diff
changeset
|
27 |
VRF_REVERSING = 0, |
0 | 28 |
|
29 |
// used to calculate if train is going up or down |
|
954
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
941
diff
changeset
|
30 |
VRF_GOINGUP = 1, |
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
941
diff
changeset
|
31 |
VRF_GOINGDOWN = 2, |
0 | 32 |
}; |
33 |
||
34 |
typedef struct VehicleAir { |
|
35 |
uint16 crashed_counter; |
|
36 |
byte pos; |
|
37 |
byte previous_pos; |
|
817
238bbdaa228b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
38 |
uint16 targetairport; |
0 | 39 |
byte state; |
40 |
} VehicleAir; |
|
41 |
||
42 |
typedef struct VehicleRoad { |
|
43 |
byte state; |
|
44 |
byte frame; |
|
45 |
uint16 unk2; |
|
46 |
byte overtaking; |
|
47 |
byte overtaking_ctr; |
|
48 |
uint16 crashed_ctr; |
|
49 |
byte reverse_ctr; |
|
50 |
} VehicleRoad; |
|
51 |
||
52 |
typedef struct VehicleSpecial { |
|
53 |
uint16 unk0; |
|
54 |
byte unk2; |
|
55 |
} VehicleSpecial; |
|
56 |
||
57 |
typedef struct VehicleDisaster { |
|
58 |
uint16 image_override; |
|
59 |
uint16 unk2; |
|
60 |
} VehicleDisaster; |
|
61 |
||
62 |
typedef struct VehicleShip { |
|
63 |
byte state; |
|
64 |
} VehicleShip; |
|
65 |
||
66 |
// not used ATM |
|
67 |
struct WorldSprite { |
|
68 |
struct WorldSprite *next; // next sprite in hash chain |
|
69 |
uint16 image; // sprite number for this vehicle |
|
70 |
||
71 |
// screen coordinates |
|
72 |
int16 left, top, right, bottom; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
73 |
|
0 | 74 |
// world coordinates |
75 |
int16 x; |
|
76 |
int16 y; |
|
77 |
byte z; |
|
78 |
||
79 |
int8 x_offs; // x offset for vehicle sprite |
|
80 |
int8 y_offs; // y offset for vehicle sprite |
|
81 |
||
82 |
byte width; // width of vehicle sprite |
|
83 |
byte height; // height of vehicle sprite |
|
84 |
byte depth; // depth of vehicle sprite |
|
85 |
||
86 |
byte flags; // draw flags |
|
87 |
}; |
|
88 |
||
89 |
struct Vehicle { |
|
90 |
byte type; // type, ie roadven,train,ship,aircraft,special |
|
22 | 91 |
byte subtype; // subtype (for trains, 0 == loco, 4 wagon ??) |
0 | 92 |
|
93 |
uint16 index; // NOSAVE: Index in vehicle array |
|
94 |
||
95 |
Vehicle *next; // next |
|
96 |
||
97 |
StringID string_id; // Displayed string |
|
98 |
||
99 |
byte unitnumber; // unit number, for display purposes only |
|
100 |
byte owner; // which player owns the vehicle? |
|
101 |
||
102 |
TileIndex tile; // Current tile index |
|
103 |
TileIndex dest_tile; // Heading for this tile |
|
104 |
||
105 |
int16 x_pos; // coordinates |
|
106 |
int16 y_pos; |
|
107 |
byte z_pos; |
|
108 |
byte direction; // facing |
|
109 |
||
110 |
byte spritenum; // currently displayed sprite index |
|
111 |
// 0xfd == custom sprite, 0xfe == custom second head sprite |
|
112 |
// 0xff == reserved for another custom sprite |
|
445
beafc0fb8f12
(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
|
113 |
uint16 cur_image; // sprite number for this vehicle |
0 | 114 |
byte sprite_width;// width of vehicle sprite |
115 |
byte sprite_height;// height of vehicle sprite |
|
116 |
byte z_height; // z-height of vehicle sprite |
|
117 |
int8 x_offs; // x offset for vehicle sprite |
|
118 |
int8 y_offs; // y offset for vehicle sprite |
|
119 |
uint16 engine_type; |
|
120 |
||
445
beafc0fb8f12
(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
|
121 |
// for randomized variational spritegroups |
beafc0fb8f12
(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
|
122 |
// bitmask used to resolve them; parts of it get reseeded when triggers |
beafc0fb8f12
(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
|
123 |
// of corresponding spritegroups get matched |
beafc0fb8f12
(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
|
124 |
byte random_bits; |
beafc0fb8f12
(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
|
125 |
byte waiting_triggers; // triggers to be yet matched |
beafc0fb8f12
(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 |
|
0 | 127 |
uint16 max_speed; // maximum speed |
128 |
uint16 cur_speed; // current speed |
|
129 |
byte subspeed; // fractional speed |
|
130 |
byte acceleration; // used by train & aircraft |
|
131 |
byte progress; |
|
132 |
||
133 |
byte vehstatus; // Status |
|
817
238bbdaa228b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
134 |
uint16 last_station_visited; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
135 |
|
0 | 136 |
byte cargo_type; // type of cargo this vehicle is carrying |
137 |
byte cargo_days; // how many days have the pieces been in transit |
|
138 |
byte cargo_source;// source of cargo |
|
139 |
uint16 cargo_cap; // total capacity |
|
140 |
uint16 cargo_count;// how many pieces are used |
|
141 |
||
142 |
byte day_counter; // increased by one for each day |
|
143 |
byte tick_counter;// increased by one for each tick |
|
144 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
145 |
/* Begin Order-stuff */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
146 |
Order current_order; //! The current order (+ status, like: loading) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
147 |
byte cur_order_index; //! The index to the current order |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
148 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
149 |
Order *orders; //! Pointer to the first order for this vehicle |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
150 |
byte num_orders; //! How many orders there are in the list |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
151 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
152 |
Vehicle *next_shared; //! If not NULL, this points to the next vehicle that shared the order |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
153 |
Vehicle *prev_shared; //! If not NULL, this points to the prev vehicle that shared the order |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
154 |
/* End Order-stuff */ |
0 | 155 |
|
156 |
// Boundaries for the current position in the world and a next hash link. |
|
157 |
// NOSAVE: All of those can be updated with VehiclePositionChanged() |
|
849
c3407041774f
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
842
diff
changeset
|
158 |
int32 left_coord; |
c3407041774f
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
842
diff
changeset
|
159 |
int32 top_coord; |
c3407041774f
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
842
diff
changeset
|
160 |
int32 right_coord; |
c3407041774f
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
842
diff
changeset
|
161 |
int32 bottom_coord; |
0 | 162 |
uint16 next_hash; |
163 |
||
164 |
// Related to age and service time |
|
165 |
uint16 age; // Age in days |
|
166 |
uint16 max_age; // Maximum age |
|
167 |
uint16 date_of_last_service; |
|
168 |
uint16 service_interval; |
|
169 |
uint16 reliability; |
|
170 |
uint16 reliability_spd_dec; |
|
171 |
byte breakdown_ctr; |
|
172 |
byte breakdown_delay; |
|
173 |
byte breakdowns_since_last_service; |
|
174 |
byte breakdown_chance; |
|
175 |
byte build_year; |
|
176 |
||
177 |
uint16 load_unload_time_rem; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
178 |
|
0 | 179 |
int32 profit_this_year; |
180 |
int32 profit_last_year; |
|
181 |
uint32 value; |
|
182 |
||
183 |
union { |
|
184 |
VehicleRail rail; |
|
185 |
VehicleAir air; |
|
186 |
VehicleRoad road; |
|
187 |
VehicleSpecial special; |
|
188 |
VehicleDisaster disaster; |
|
189 |
VehicleShip ship; |
|
190 |
} u; |
|
191 |
}; |
|
192 |
||
193 |
#define is_custom_sprite(x) (x >= 0xfd) |
|
194 |
#define is_custom_firsthead_sprite(x) (x == 0xfd) |
|
195 |
#define is_custom_secondhead_sprite(x) (x == 0xfe) |
|
196 |
||
197 |
struct Depot { |
|
198 |
TileIndex xy; |
|
199 |
uint16 town_index; |
|
200 |
}; |
|
201 |
||
395
788a9bba0889
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
193
diff
changeset
|
202 |
// train waypoint |
788a9bba0889
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
193
diff
changeset
|
203 |
struct Waypoint { |
0 | 204 |
TileIndex xy; |
205 |
uint16 town_or_string; // if this is 0xC000, it's a string id, otherwise a town. |
|
206 |
ViewportSign sign; |
|
207 |
uint16 build_date; |
|
208 |
byte stat_id; |
|
395
788a9bba0889
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
193
diff
changeset
|
209 |
byte deleted; // this is a delete counter. when it reaches 0, the waypoint struct is deleted. |
0 | 210 |
}; |
211 |
||
212 |
enum { |
|
213 |
VEH_Train = 0x10, |
|
214 |
VEH_Road = 0x11, |
|
215 |
VEH_Ship = 0x12, |
|
216 |
VEH_Aircraft = 0x13, |
|
217 |
VEH_Special = 0x14, |
|
218 |
VEH_Disaster = 0x15, |
|
219 |
}; |
|
220 |
||
221 |
enum VehStatus { |
|
222 |
VS_HIDDEN = 1, |
|
223 |
VS_STOPPED = 2, |
|
224 |
VS_UNCLICKABLE = 4, |
|
225 |
VS_DEFPAL = 0x8, |
|
226 |
VS_TRAIN_SLOWING = 0x10, |
|
227 |
VS_DISASTER = 0x20, |
|
228 |
VS_AIRCRAFT_BROKEN = 0x40, |
|
229 |
VS_CRASHED = 0x80, |
|
230 |
}; |
|
231 |
||
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1060
diff
changeset
|
232 |
// 1 and 3 do not appear to be used |
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1060
diff
changeset
|
233 |
enum TrainSubtype { |
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1060
diff
changeset
|
234 |
TS_Front_Engine = 0, |
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1060
diff
changeset
|
235 |
TS_Not_First = 2, |
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1060
diff
changeset
|
236 |
TS_Free_Car = 4, |
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1060
diff
changeset
|
237 |
}; |
0 | 238 |
|
239 |
/* Effect vehicle types */ |
|
240 |
enum { |
|
241 |
EV_INDUSTRYSMOKE = 0, |
|
242 |
EV_STEAM_SMOKE = 1, |
|
243 |
||
244 |
EV_SMOKE_1 = 2, |
|
245 |
EV_SMOKE_2 = 3, |
|
246 |
EV_SMOKE_3 = 4, |
|
247 |
||
248 |
EV_CRASHED_SMOKE = 5, |
|
249 |
EV_BREAKDOWN_SMOKE = 6, |
|
250 |
||
251 |
EV_DEMOLISH = 7, |
|
252 |
EV_ROADWORK = 8, |
|
253 |
||
254 |
EV_INDUSTRY_SMOKE = 9, |
|
255 |
||
256 |
}; |
|
257 |
||
258 |
typedef void VehicleTickProc(Vehicle *v); |
|
259 |
typedef void *VehicleFromPosProc(Vehicle *v, void *data); |
|
260 |
||
578
1e66514eb621
(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
|
261 |
void VehicleServiceInDepot(Vehicle *v); |
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1067
diff
changeset
|
262 |
Vehicle *AllocateVehicle(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1067
diff
changeset
|
263 |
Vehicle *ForceAllocateVehicle(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1067
diff
changeset
|
264 |
Vehicle *ForceAllocateSpecialVehicle(void); |
0 | 265 |
void UpdateVehiclePosHash(Vehicle *v, int x, int y); |
266 |
void VehiclePositionChanged(Vehicle *v); |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1067
diff
changeset
|
267 |
void AfterLoadVehicles(void); |
0 | 268 |
Vehicle *GetLastVehicleInChain(Vehicle *v); |
269 |
Vehicle *GetPrevVehicleInChain(Vehicle *v); |
|
270 |
Vehicle *GetFirstVehicleInChain(Vehicle *v); |
|
271 |
int CountVehiclesInChain(Vehicle *v); |
|
272 |
void DeleteVehicle(Vehicle *v); |
|
273 |
void DeleteVehicleChain(Vehicle *v); |
|
274 |
void *VehicleFromPos(TileIndex tile, void *data, VehicleFromPosProc *proc); |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1067
diff
changeset
|
275 |
void CallVehicleTicks(void); |
0 | 276 |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1067
diff
changeset
|
277 |
Depot *AllocateDepot(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1067
diff
changeset
|
278 |
Waypoint *AllocateWaypoint(void); |
395
788a9bba0889
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
193
diff
changeset
|
279 |
void UpdateWaypointSign(Waypoint *cp); |
788a9bba0889
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
193
diff
changeset
|
280 |
void RedrawWaypointSign(Waypoint *cp); |
0 | 281 |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1067
diff
changeset
|
282 |
void InitializeTrains(void); |
0 | 283 |
bool IsTrainDepotTile(TileIndex tile); |
284 |
bool IsRoadDepotTile(TileIndex tile); |
|
285 |
||
286 |
bool CanFillVehicle(Vehicle *v); |
|
287 |
||
288 |
void ViewportAddVehicles(DrawPixelInfo *dpi); |
|
289 |
||
290 |
void TrainEnterDepot(Vehicle *v, uint tile); |
|
291 |
||
1060
ae9a2238bd80
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1055
diff
changeset
|
292 |
void AddRearEngineToMultiheadedTrain(Vehicle *v, Vehicle *u, bool building) ; |
ae9a2238bd80
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1055
diff
changeset
|
293 |
|
0 | 294 |
/* train_cmd.h */ |
295 |
int GetTrainImage(Vehicle *v, byte direction); |
|
296 |
int GetAircraftImage(Vehicle *v, byte direction); |
|
297 |
int GetRoadVehImage(Vehicle *v, byte direction); |
|
298 |
int GetShipImage(Vehicle *v, byte direction); |
|
299 |
||
300 |
Vehicle *CreateEffectVehicle(int x, int y, int z, int type); |
|
301 |
Vehicle *CreateEffectVehicleAbove(int x, int y, int z, int type); |
|
302 |
Vehicle *CreateEffectVehicleRel(Vehicle *v, int x, int y, int z, int type); |
|
303 |
||
304 |
uint32 VehicleEnterTile(Vehicle *v, uint tile, int x, int y); |
|
305 |
||
306 |
void VehicleInTheWayErrMsg(Vehicle *v); |
|
307 |
Vehicle *FindVehicleBetween(TileIndex from, TileIndex to, byte z); |
|
308 |
uint GetVehicleOutOfTunnelTile(Vehicle *v); |
|
309 |
||
310 |
bool UpdateSignalsOnSegment(uint tile, byte direction); |
|
311 |
void SetSignalsOnBothDir(uint tile, byte track); |
|
312 |
||
313 |
Vehicle *CheckClickOnVehicle(ViewPort *vp, int x, int y); |
|
314 |
//uint GetVehicleWeight(Vehicle *v); |
|
315 |
||
316 |
void DecreaseVehicleValue(Vehicle *v); |
|
317 |
void CheckVehicleBreakdown(Vehicle *v); |
|
318 |
void AgeVehicle(Vehicle *v); |
|
842 | 319 |
void MaybeReplaceVehicle(Vehicle *v); |
0 | 320 |
|
321 |
void BeginVehicleMove(Vehicle *v); |
|
322 |
void EndVehicleMove(Vehicle *v); |
|
323 |
||
324 |
bool IsAircraftHangarTile(TileIndex tile); |
|
325 |
void ShowAircraftViewWindow(Vehicle *v); |
|
326 |
||
327 |
bool IsShipDepotTile(TileIndex tile); |
|
328 |
uint GetFreeUnitNumber(byte type); |
|
329 |
||
330 |
int LoadUnloadVehicle(Vehicle *v); |
|
331 |
int GetDepotByTile(uint tile); |
|
395
788a9bba0889
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
193
diff
changeset
|
332 |
uint GetWaypointByTile(uint tile); |
0 | 333 |
|
334 |
void DoDeleteDepot(uint tile); |
|
335 |
||
336 |
void UpdateTrainAcceleration(Vehicle *v); |
|
337 |
int32 GetTrainRunningCost(Vehicle *v); |
|
338 |
||
339 |
int CheckStoppedInDepot(Vehicle *v); |
|
340 |
||
593 | 341 |
bool VehicleNeedsService(const Vehicle *v); |
342 |
||
0 | 343 |
typedef struct GetNewVehiclePosResult { |
344 |
int x,y; |
|
345 |
uint old_tile; |
|
346 |
uint new_tile; |
|
347 |
} GetNewVehiclePosResult; |
|
348 |
||
349 |
/* returns true if staying in the same tile */ |
|
350 |
bool GetNewVehiclePos(Vehicle *v, GetNewVehiclePosResult *gp); |
|
351 |
byte GetDirectionTowards(Vehicle *v, int x, int y); |
|
352 |
||
353 |
#define BEGIN_ENUM_WAGONS(v) do { |
|
354 |
#define END_ENUM_WAGONS(v) } while ( (v=v->next) != NULL); |
|
355 |
||
356 |
/* vehicle.c */ |
|
357 |
enum { |
|
358 |
NUM_NORMAL_VEHICLES = 2048, |
|
359 |
NUM_SPECIAL_VEHICLES = 512, |
|
360 |
NUM_VEHICLES = NUM_NORMAL_VEHICLES + NUM_SPECIAL_VEHICLES |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
361 |
}; |
0 | 362 |
|
363 |
VARDEF Vehicle _vehicles[NUM_VEHICLES]; |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
849
diff
changeset
|
364 |
VARDEF uint _vehicles_size; |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
849
diff
changeset
|
365 |
|
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
849
diff
changeset
|
366 |
VARDEF SortStruct *_vehicle_sort; |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
849
diff
changeset
|
367 |
|
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
849
diff
changeset
|
368 |
static inline Vehicle *GetVehicle(uint index) |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
849
diff
changeset
|
369 |
{ |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
849
diff
changeset
|
370 |
assert(index < _vehicles_size); |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
849
diff
changeset
|
371 |
return &_vehicles[index]; |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
849
diff
changeset
|
372 |
} |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
849
diff
changeset
|
373 |
|
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
849
diff
changeset
|
374 |
#define FOR_ALL_VEHICLES(v) for(v = _vehicles; v != &_vehicles[_vehicles_size]; v++) |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
849
diff
changeset
|
375 |
#define FOR_ALL_VEHICLES_FROM(v, from) for(v = GetVehicle(from); v != &_vehicles[_vehicles_size]; v++) |
0 | 376 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
377 |
/* Returns order 'index' of a vehicle or NULL when it doesn't exists */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
378 |
static inline Order *GetVehicleOrder(const Vehicle *v, int index) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
379 |
{ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
380 |
Order *order = v->orders; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
381 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
382 |
if (index < 0) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
383 |
return NULL; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
384 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
385 |
while (order != NULL && index-- > 0) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
386 |
order = order->next; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
387 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
388 |
return order; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
389 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
390 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
391 |
/* Returns the last order of a vehicle, or NULL if it doesn't exists */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
392 |
static inline Order *GetLastVehicleOrder(const Vehicle *v) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
393 |
{ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
394 |
Order *order = v->orders; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
395 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
396 |
if (order == NULL) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
397 |
return NULL; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
398 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
399 |
while (order->next != NULL) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
400 |
order = order->next; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
401 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
402 |
return order; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
403 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
404 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
405 |
/* Get the first vehicle of a shared-list, so we only have to walk forwards */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
406 |
static inline Vehicle *GetFirstVehicleFromSharedList(Vehicle *v) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
407 |
{ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
408 |
Vehicle *u = v; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
409 |
while (u->prev_shared != NULL) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
410 |
u = u->prev_shared; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
411 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
412 |
return u; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
413 |
} |
0 | 414 |
|
415 |
VARDEF Depot _depots[255]; |
|
416 |
||
395
788a9bba0889
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
193
diff
changeset
|
417 |
// 128 waypoints |
788a9bba0889
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
193
diff
changeset
|
418 |
VARDEF Waypoint _waypoints[128]; |
0 | 419 |
|
420 |
// NOSAVE: Can be regenerated by inspecting the vehicles. |
|
421 |
VARDEF VehicleID _vehicle_position_hash[0x1000]; |
|
422 |
||
423 |
// NOSAVE: Return values from various commands. |
|
424 |
VARDEF VehicleID _new_train_id; |
|
425 |
VARDEF VehicleID _new_wagon_id; |
|
426 |
VARDEF VehicleID _new_aircraft_id; |
|
427 |
VARDEF VehicleID _new_ship_id; |
|
428 |
VARDEF VehicleID _new_roadveh_id; |
|
429 |
VARDEF uint16 _aircraft_refit_capacity; |
|
430 |
VARDEF byte _cmd_build_rail_veh_score; |
|
431 |
VARDEF byte _cmd_build_rail_veh_var1; |
|
432 |
||
433 |
// NOSAVE: Player specific info |
|
434 |
VARDEF TileIndex _last_built_train_depot_tile; |
|
435 |
VARDEF TileIndex _last_built_road_depot_tile; |
|
436 |
VARDEF TileIndex _last_built_aircraft_depot_tile; |
|
437 |
VARDEF TileIndex _last_built_ship_depot_tile; |
|
438 |
||
439 |
// for each player, for each vehicle type, keep a list of the vehicles. |
|
440 |
//VARDEF Vehicle *_vehicle_arr[8][4]; |
|
441 |
||
442 |
#define INVALID_VEHICLE 0xffff |
|
443 |
||
156
8fef5e5752d6
(svn r157) -Feature: [1009708] Percent-based service intervals. Send a vehicle to depot after it has lost X% of its reliability (mivlad)
darkvater
parents:
22
diff
changeset
|
444 |
#define MIN_SERVINT_PERCENT 5 |
8fef5e5752d6
(svn r157) -Feature: [1009708] Percent-based service intervals. Send a vehicle to depot after it has lost X% of its reliability (mivlad)
darkvater
parents:
22
diff
changeset
|
445 |
#define MAX_SERVINT_PERCENT 90 |
8fef5e5752d6
(svn r157) -Feature: [1009708] Percent-based service intervals. Send a vehicle to depot after it has lost X% of its reliability (mivlad)
darkvater
parents:
22
diff
changeset
|
446 |
#define MIN_SERVINT_DAYS 30 |
8fef5e5752d6
(svn r157) -Feature: [1009708] Percent-based service intervals. Send a vehicle to depot after it has lost X% of its reliability (mivlad)
darkvater
parents:
22
diff
changeset
|
447 |
#define MAX_SERVINT_DAYS 800 |
8fef5e5752d6
(svn r157) -Feature: [1009708] Percent-based service intervals. Send a vehicle to depot after it has lost X% of its reliability (mivlad)
darkvater
parents:
22
diff
changeset
|
448 |
|
755
80091de50044
(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
|
449 |
/* A lot of code calls for the invalidation of the status bar, which is widget 5. |
80091de50044
(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
|
450 |
* Best is to have a virtual value for it when it needs to change again */ |
80091de50044
(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
|
451 |
#define STATUS_BAR 5 |
80091de50044
(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
|
452 |
|
0 | 453 |
#endif /* VEHICLE_H */ |