author | truelight |
Thu, 24 Mar 2005 14:43:40 +0000 | |
changeset 1540 | 6eef12dab5bf |
parent 1520 | d88442095697 |
child 1542 | 62a03537ad0b |
permissions | -rw-r--r-- |
0 | 1 |
#ifndef VEHICLE_H |
2 |
#define VEHICLE_H |
|
3 |
||
1279
bc761aad52b3
(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
5e446b5b3ec5
(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
66c89362a778
(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
66c89362a778
(svn r1445) -Fix: reversing a train also reverses the UP and DOWN status for the
truelight
parents:
941
diff
changeset
|
31 |
VRF_GOINGUP = 1, |
66c89362a778
(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
238bbdaa228b
(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
59c024cfaf54
(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; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1174
diff
changeset
|
52 |
byte slotindex; |
59c024cfaf54
(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 |
|
100 |
||
101 |
StringID string_id; // Displayed string |
|
102 |
||
1282
ea2ae881814c
(svn r1786) -Fix: unitnumber is increased to 16bit, so now you can have up to 5000
truelight
parents:
1279
diff
changeset
|
103 |
UnitID unitnumber; // unit number, for display purposes only |
0 | 104 |
byte owner; // which player owns the vehicle? |
105 |
||
106 |
TileIndex tile; // Current tile index |
|
107 |
TileIndex dest_tile; // Heading for this tile |
|
108 |
||
1174
6a5e747f3ba6
(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
|
109 |
int32 x_pos; // coordinates |
6a5e747f3ba6
(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 y_pos; |
0 | 111 |
byte z_pos; |
112 |
byte direction; // facing |
|
113 |
||
114 |
byte spritenum; // currently displayed sprite index |
|
115 |
// 0xfd == custom sprite, 0xfe == custom second head sprite |
|
116 |
// 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
|
117 |
uint16 cur_image; // sprite number for this vehicle |
0 | 118 |
byte sprite_width;// width of vehicle sprite |
119 |
byte sprite_height;// height of vehicle sprite |
|
120 |
byte z_height; // z-height of vehicle sprite |
|
121 |
int8 x_offs; // x offset for vehicle sprite |
|
122 |
int8 y_offs; // y offset for vehicle sprite |
|
123 |
uint16 engine_type; |
|
124 |
||
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
|
125 |
// 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
|
126 |
// 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
|
127 |
// 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
|
128 |
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
|
129 |
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
|
130 |
|
0 | 131 |
uint16 max_speed; // maximum speed |
132 |
uint16 cur_speed; // current speed |
|
133 |
byte subspeed; // fractional speed |
|
134 |
byte acceleration; // used by train & aircraft |
|
135 |
byte progress; |
|
136 |
||
137 |
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
|
138 |
uint16 last_station_visited; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
139 |
|
0 | 140 |
byte cargo_type; // type of cargo this vehicle is carrying |
141 |
byte cargo_days; // how many days have the pieces been in transit |
|
1266
eccd576e322f
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1237
diff
changeset
|
142 |
uint16 cargo_source;// source of cargo |
0 | 143 |
uint16 cargo_cap; // total capacity |
144 |
uint16 cargo_count;// how many pieces are used |
|
145 |
||
146 |
byte day_counter; // increased by one for each day |
|
147 |
byte tick_counter;// increased by one for each tick |
|
148 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
149 |
/* Begin Order-stuff */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
150 |
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
|
151 |
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
|
152 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
153 |
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
|
154 |
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
|
155 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
156 |
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
|
157 |
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
|
158 |
/* End Order-stuff */ |
0 | 159 |
|
160 |
// Boundaries for the current position in the world and a next hash link. |
|
161 |
// 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
|
162 |
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
|
163 |
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
|
164 |
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
|
165 |
int32 bottom_coord; |
0 | 166 |
uint16 next_hash; |
167 |
||
168 |
// Related to age and service time |
|
169 |
uint16 age; // Age in days |
|
170 |
uint16 max_age; // Maximum age |
|
171 |
uint16 date_of_last_service; |
|
172 |
uint16 service_interval; |
|
173 |
uint16 reliability; |
|
174 |
uint16 reliability_spd_dec; |
|
175 |
byte breakdown_ctr; |
|
176 |
byte breakdown_delay; |
|
177 |
byte breakdowns_since_last_service; |
|
178 |
byte breakdown_chance; |
|
179 |
byte build_year; |
|
180 |
||
181 |
uint16 load_unload_time_rem; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
182 |
|
0 | 183 |
int32 profit_this_year; |
184 |
int32 profit_last_year; |
|
185 |
uint32 value; |
|
186 |
||
187 |
union { |
|
188 |
VehicleRail rail; |
|
189 |
VehicleAir air; |
|
190 |
VehicleRoad road; |
|
191 |
VehicleSpecial special; |
|
192 |
VehicleDisaster disaster; |
|
193 |
VehicleShip ship; |
|
194 |
} u; |
|
195 |
}; |
|
196 |
||
197 |
#define is_custom_sprite(x) (x >= 0xfd) |
|
198 |
#define is_custom_firsthead_sprite(x) (x == 0xfd) |
|
199 |
#define is_custom_secondhead_sprite(x) (x == 0xfe) |
|
200 |
||
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
|
201 |
// 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
|
202 |
struct Waypoint { |
0 | 203 |
TileIndex xy; |
204 |
uint16 town_or_string; // if this is 0xC000, it's a string id, otherwise a town. |
|
205 |
ViewportSign sign; |
|
206 |
uint16 build_date; |
|
207 |
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
|
208 |
byte deleted; // this is a delete counter. when it reaches 0, the waypoint struct is deleted. |
0 | 209 |
}; |
210 |
||
211 |
enum { |
|
212 |
VEH_Train = 0x10, |
|
213 |
VEH_Road = 0x11, |
|
214 |
VEH_Ship = 0x12, |
|
215 |
VEH_Aircraft = 0x13, |
|
216 |
VEH_Special = 0x14, |
|
217 |
VEH_Disaster = 0x15, |
|
218 |
}; |
|
219 |
||
220 |
enum VehStatus { |
|
221 |
VS_HIDDEN = 1, |
|
222 |
VS_STOPPED = 2, |
|
223 |
VS_UNCLICKABLE = 4, |
|
224 |
VS_DEFPAL = 0x8, |
|
225 |
VS_TRAIN_SLOWING = 0x10, |
|
226 |
VS_DISASTER = 0x20, |
|
227 |
VS_AIRCRAFT_BROKEN = 0x40, |
|
228 |
VS_CRASHED = 0x80, |
|
229 |
}; |
|
230 |
||
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1060
diff
changeset
|
231 |
// 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
|
232 |
enum TrainSubtype { |
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1060
diff
changeset
|
233 |
TS_Front_Engine = 0, |
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1060
diff
changeset
|
234 |
TS_Not_First = 2, |
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1060
diff
changeset
|
235 |
TS_Free_Car = 4, |
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1060
diff
changeset
|
236 |
}; |
0 | 237 |
|
238 |
/* Effect vehicle types */ |
|
1359
52782e5cf7c9
(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 |
typedef enum EffectVehicle { |
52782e5cf7c9
(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_CHIMNEY_SMOKE = 0, |
52782e5cf7c9
(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 |
EV_STEAM_SMOKE = 1, |
52782e5cf7c9
(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
|
242 |
EV_DIESEL_SMOKE = 2, |
52782e5cf7c9
(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
|
243 |
EV_ELECTRIC_SPARK = 3, |
52782e5cf7c9
(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
|
244 |
EV_SMOKE = 4, |
52782e5cf7c9
(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
|
245 |
EV_EXPLOSION_LARGE = 5, |
0 | 246 |
EV_BREAKDOWN_SMOKE = 6, |
1359
52782e5cf7c9
(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
|
247 |
EV_EXPLOSION_SMALL = 7, |
52782e5cf7c9
(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
|
248 |
EV_BULLDOZER = 8, |
52782e5cf7c9
(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
|
249 |
EV_BUBBLE = 9 |
52782e5cf7c9
(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
|
250 |
} EffectVehicle; |
0 | 251 |
|
252 |
typedef void VehicleTickProc(Vehicle *v); |
|
253 |
typedef void *VehicleFromPosProc(Vehicle *v, void *data); |
|
254 |
||
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
|
255 |
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
|
256 |
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
|
257 |
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
|
258 |
Vehicle *ForceAllocateSpecialVehicle(void); |
0 | 259 |
void UpdateVehiclePosHash(Vehicle *v, int x, int y); |
260 |
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
|
261 |
void AfterLoadVehicles(void); |
0 | 262 |
Vehicle *GetLastVehicleInChain(Vehicle *v); |
1475 | 263 |
Vehicle *GetPrevVehicleInChain(const Vehicle *v); |
264 |
Vehicle *GetFirstVehicleInChain(const Vehicle *v); |
|
0 | 265 |
int CountVehiclesInChain(Vehicle *v); |
266 |
void DeleteVehicle(Vehicle *v); |
|
267 |
void DeleteVehicleChain(Vehicle *v); |
|
268 |
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
|
269 |
void CallVehicleTicks(void); |
0 | 270 |
|
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
|
271 |
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
|
272 |
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
|
273 |
void RedrawWaypointSign(Waypoint *cp); |
0 | 274 |
|
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 InitializeTrains(void); |
0 | 276 |
|
277 |
bool CanFillVehicle(Vehicle *v); |
|
278 |
||
279 |
void ViewportAddVehicles(DrawPixelInfo *dpi); |
|
280 |
||
281 |
void TrainEnterDepot(Vehicle *v, uint tile); |
|
282 |
||
1060
ae9a2238bd80
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1055
diff
changeset
|
283 |
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
|
284 |
|
0 | 285 |
/* train_cmd.h */ |
1475 | 286 |
int GetTrainImage(const Vehicle *v, byte direction); |
0 | 287 |
int GetAircraftImage(Vehicle *v, byte direction); |
288 |
int GetRoadVehImage(Vehicle *v, byte direction); |
|
289 |
int GetShipImage(Vehicle *v, byte direction); |
|
290 |
||
1359
52782e5cf7c9
(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
|
291 |
Vehicle *CreateEffectVehicle(int x, int y, int z, EffectVehicle type); |
52782e5cf7c9
(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
|
292 |
Vehicle *CreateEffectVehicleAbove(int x, int y, int z, EffectVehicle type); |
52782e5cf7c9
(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
|
293 |
Vehicle *CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, EffectVehicle type); |
0 | 294 |
|
295 |
uint32 VehicleEnterTile(Vehicle *v, uint tile, int x, int y); |
|
296 |
||
297 |
void VehicleInTheWayErrMsg(Vehicle *v); |
|
298 |
Vehicle *FindVehicleBetween(TileIndex from, TileIndex to, byte z); |
|
299 |
uint GetVehicleOutOfTunnelTile(Vehicle *v); |
|
300 |
||
301 |
bool UpdateSignalsOnSegment(uint tile, byte direction); |
|
302 |
void SetSignalsOnBothDir(uint tile, byte track); |
|
303 |
||
304 |
Vehicle *CheckClickOnVehicle(ViewPort *vp, int x, int y); |
|
305 |
//uint GetVehicleWeight(Vehicle *v); |
|
306 |
||
307 |
void DecreaseVehicleValue(Vehicle *v); |
|
308 |
void CheckVehicleBreakdown(Vehicle *v); |
|
309 |
void AgeVehicle(Vehicle *v); |
|
842 | 310 |
void MaybeReplaceVehicle(Vehicle *v); |
0 | 311 |
|
312 |
void BeginVehicleMove(Vehicle *v); |
|
313 |
void EndVehicleMove(Vehicle *v); |
|
314 |
||
315 |
bool IsAircraftHangarTile(TileIndex tile); |
|
316 |
void ShowAircraftViewWindow(Vehicle *v); |
|
317 |
||
1282
ea2ae881814c
(svn r1786) -Fix: unitnumber is increased to 16bit, so now you can have up to 5000
truelight
parents:
1279
diff
changeset
|
318 |
UnitID GetFreeUnitNumber(byte type); |
0 | 319 |
|
320 |
int LoadUnloadVehicle(Vehicle *v); |
|
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
|
321 |
uint GetWaypointByTile(uint tile); |
0 | 322 |
|
323 |
void UpdateTrainAcceleration(Vehicle *v); |
|
324 |
int32 GetTrainRunningCost(Vehicle *v); |
|
325 |
||
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1359
diff
changeset
|
326 |
int CheckTrainStoppedInDepot(const Vehicle *v); |
0 | 327 |
|
593 | 328 |
bool VehicleNeedsService(const Vehicle *v); |
329 |
||
0 | 330 |
typedef struct GetNewVehiclePosResult { |
331 |
int x,y; |
|
332 |
uint old_tile; |
|
333 |
uint new_tile; |
|
334 |
} GetNewVehiclePosResult; |
|
335 |
||
336 |
/* returns true if staying in the same tile */ |
|
337 |
bool GetNewVehiclePos(Vehicle *v, GetNewVehiclePosResult *gp); |
|
338 |
byte GetDirectionTowards(Vehicle *v, int x, int y); |
|
339 |
||
340 |
#define BEGIN_ENUM_WAGONS(v) do { |
|
341 |
#define END_ENUM_WAGONS(v) } while ( (v=v->next) != NULL); |
|
342 |
||
343 |
/* vehicle.c */ |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
849
diff
changeset
|
344 |
VARDEF SortStruct *_vehicle_sort; |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
849
diff
changeset
|
345 |
|
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
346 |
extern MemoryPool _vehicle_pool; |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
347 |
|
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
348 |
/** |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
349 |
* Get the pointer to the vehicle with index 'index' |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
350 |
*/ |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
351 |
static inline Vehicle *GetVehicle(VehicleID index) |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
849
diff
changeset
|
352 |
{ |
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
353 |
return (Vehicle*)GetItemFromPool(&_vehicle_pool, index); |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
849
diff
changeset
|
354 |
} |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
849
diff
changeset
|
355 |
|
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
356 |
/** |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
357 |
* Get the current size of the VehiclePool |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
358 |
*/ |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
359 |
static inline uint16 GetVehiclePoolSize(void) |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
360 |
{ |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
361 |
return _vehicle_pool.total_items; |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
362 |
} |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
363 |
|
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
364 |
#define FOR_ALL_VEHICLES_FROM(v, start) for (v = GetVehicle(start); v != NULL; v = (v->index + 1 < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
365 |
#define FOR_ALL_VEHICLES(v) FOR_ALL_VEHICLES_FROM(v, 0) |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
366 |
|
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
367 |
/** |
1330
5d76a0522a11
(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
|
368 |
* Check if a Vehicle really exists. |
5d76a0522a11
(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
|
369 |
*/ |
5d76a0522a11
(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
|
370 |
static inline bool IsValidVehicle(Vehicle* v) |
5d76a0522a11
(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
|
371 |
{ |
5d76a0522a11
(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
|
372 |
return v->type != 0; |
5d76a0522a11
(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
|
373 |
} |
5d76a0522a11
(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
|
374 |
|
5d76a0522a11
(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
|
375 |
/** |
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
376 |
* Check if an index is a vehicle-index (so between 0 and max-vehicles) |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
377 |
* |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
378 |
* @return Returns true if the vehicle-id is in range |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
379 |
*/ |
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1217
diff
changeset
|
380 |
static inline bool IsVehicleIndex(uint index) |
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1217
diff
changeset
|
381 |
{ |
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
382 |
if (index < GetVehiclePoolSize()) |
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1217
diff
changeset
|
383 |
return true; |
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
384 |
|
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
385 |
return false; |
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1217
diff
changeset
|
386 |
} |
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1217
diff
changeset
|
387 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
388 |
/* 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
|
389 |
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
|
390 |
{ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
391 |
Order *order = v->orders; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
392 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
393 |
if (index < 0) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
394 |
return NULL; |
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 |
while (order != NULL && index-- > 0) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
397 |
order = order->next; |
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 |
return order; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
400 |
} |
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 |
/* 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
|
403 |
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
|
404 |
{ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
405 |
Order *order = v->orders; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
406 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
407 |
if (order == NULL) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
408 |
return NULL; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
409 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
410 |
while (order->next != NULL) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
411 |
order = order->next; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
412 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
413 |
return order; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
414 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
415 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
416 |
/* 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
|
417 |
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
|
418 |
{ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
419 |
Vehicle *u = v; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
420 |
while (u->prev_shared != NULL) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
421 |
u = u->prev_shared; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
422 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
423 |
return u; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
424 |
} |
0 | 425 |
|
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
|
426 |
// 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
|
427 |
VARDEF Waypoint _waypoints[128]; |
0 | 428 |
|
429 |
// NOSAVE: Can be regenerated by inspecting the vehicles. |
|
430 |
VARDEF VehicleID _vehicle_position_hash[0x1000]; |
|
431 |
||
432 |
// NOSAVE: Return values from various commands. |
|
433 |
VARDEF VehicleID _new_train_id; |
|
434 |
VARDEF VehicleID _new_wagon_id; |
|
435 |
VARDEF VehicleID _new_aircraft_id; |
|
436 |
VARDEF VehicleID _new_ship_id; |
|
437 |
VARDEF VehicleID _new_roadveh_id; |
|
438 |
VARDEF uint16 _aircraft_refit_capacity; |
|
439 |
VARDEF byte _cmd_build_rail_veh_score; |
|
440 |
VARDEF byte _cmd_build_rail_veh_var1; |
|
441 |
||
442 |
// for each player, for each vehicle type, keep a list of the vehicles. |
|
443 |
//VARDEF Vehicle *_vehicle_arr[8][4]; |
|
444 |
||
445 |
#define INVALID_VEHICLE 0xffff |
|
446 |
||
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
|
447 |
/* 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
|
448 |
* 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
|
449 |
#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
|
450 |
|
0 | 451 |
#endif /* VEHICLE_H */ |