author | tron |
Fri, 07 Jan 2005 17:02:43 +0000 | |
changeset 926 | bd4312619522 |
parent 924 | 433faaf547c1 |
child 931 | 524393b0c842 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
445
diff
changeset
|
3 |
#include "table/strings.h" |
679
e959706a3e4d
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
593
diff
changeset
|
4 |
#include "map.h" |
0 | 5 |
#include "vehicle.h" |
6 |
#include "gfx.h" |
|
7 |
#include "viewport.h" |
|
8 |
#include "news.h" |
|
9 |
#include "command.h" |
|
10 |
#include "saveload.h" |
|
11 |
#include "player.h" |
|
12 |
#include "engine.h" |
|
337
66647f97e7c0
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
260
diff
changeset
|
13 |
#include "sound.h" |
0 | 14 |
|
15 |
#define INVALID_COORD (-0x8000) |
|
16 |
#define GEN_HASH(x,y) (((x & 0x1F80)>>7) + ((y & 0xFC0))) |
|
17 |
||
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
18 |
enum { |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
19 |
VEHICLES_MIN_FREE_FOR_AI = 90 |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
20 |
}; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
21 |
|
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
|
22 |
void VehicleServiceInDepot(Vehicle *v) |
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
|
23 |
{ |
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
|
24 |
v->date_of_last_service = _date; |
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
|
25 |
v->breakdowns_since_last_service = 0; |
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
|
26 |
v->reliability = _engines[v->engine_type].reliability; |
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
|
27 |
} |
0 | 28 |
|
593 | 29 |
bool VehicleNeedsService(const Vehicle *v) |
30 |
{ |
|
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
31 |
return _patches.servint_ispercent ? |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
32 |
(v->reliability < _engines[v->engine_type].reliability * (100 - v->service_interval) / 100) : |
593 | 33 |
(v->date_of_last_service + v->service_interval < _date); |
34 |
} |
|
35 |
||
577 | 36 |
Order UnpackOldOrder(uint16 packed) |
37 |
{ |
|
38 |
Order order; |
|
39 |
order.type = (packed & 0x000f); |
|
584
19dbfc84e766
(svn r1004) Fix harmless typo (comma instead of semicolon)
tron
parents:
578
diff
changeset
|
40 |
order.flags = (packed & 0x00f0) >> 4; |
577 | 41 |
order.station = (packed & 0xff00) >> 8; |
42 |
||
43 |
// Sanity check |
|
44 |
// TTD stores invalid orders as OT_NOTHING with non-zero flags/station |
|
45 |
if (order.type == OT_NOTHING && (order.flags != 0 || order.station != 0)) { |
|
46 |
order.type = OT_DUMMY; |
|
47 |
order.flags = 0; |
|
48 |
} |
|
49 |
||
50 |
return order; |
|
51 |
} |
|
52 |
||
53 |
||
0 | 54 |
void VehicleInTheWayErrMsg(Vehicle *v) |
55 |
{ |
|
56 |
StringID id; |
|
57 |
||
58 |
(id = STR_8803_TRAIN_IN_THE_WAY,v->type == VEH_Train) || |
|
59 |
(id = STR_9000_ROAD_VEHICLE_IN_THE_WAY,v->type == VEH_Road) || |
|
60 |
(id = STR_A015_AIRCRAFT_IN_THE_WAY,v->type == VEH_Aircraft) || |
|
61 |
(id = STR_980E_SHIP_IN_THE_WAY, true); |
|
62 |
||
63 |
_error_message = id; |
|
64 |
} |
|
65 |
||
66 |
static void *EnsureNoVehicleProc(Vehicle *v, void *data) |
|
67 |
{ |
|
537
88d71dbdcd13
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
68 |
if (v->tile != *(const TileIndex*)data || v->type == VEH_Disaster) |
0 | 69 |
return NULL; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
70 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
71 |
VehicleInTheWayErrMsg(v); |
537
88d71dbdcd13
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
72 |
return v; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
73 |
} |
0 | 74 |
|
75 |
bool EnsureNoVehicle(TileIndex tile) |
|
76 |
{ |
|
537
88d71dbdcd13
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
77 |
return VehicleFromPos(tile, &tile, EnsureNoVehicleProc) == NULL; |
0 | 78 |
} |
79 |
||
80 |
static void *EnsureNoVehicleProcZ(Vehicle *v, void *data) |
|
81 |
{ |
|
537
88d71dbdcd13
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
82 |
const TileInfo *ti = data; |
88d71dbdcd13
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
83 |
|
88d71dbdcd13
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
84 |
if (v->tile != ti->tile || v->z_pos != ti->z || v->type == VEH_Disaster) |
0 | 85 |
return NULL; |
86 |
||
87 |
VehicleInTheWayErrMsg(v); |
|
537
88d71dbdcd13
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
88 |
return v; |
0 | 89 |
} |
90 |
||
91 |
bool EnsureNoVehicleZ(TileIndex tile, byte z) |
|
92 |
{ |
|
93 |
TileInfo ti; |
|
537
88d71dbdcd13
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
94 |
|
0 | 95 |
FindLandscapeHeightByTile(&ti, tile); |
96 |
// needs z correction for slope-type graphics that have the NORTHERN tile lowered |
|
97 |
// 1, 2, 3, 4, 5, 6 and 7 |
|
98 |
if (CORRECT_Z(ti.tileh)) |
|
99 |
z += 8; |
|
100 |
||
537
88d71dbdcd13
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
101 |
ti.z = z; |
88d71dbdcd13
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
102 |
|
88d71dbdcd13
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
103 |
return VehicleFromPos(tile, &ti, EnsureNoVehicleProcZ) == NULL; |
0 | 104 |
} |
105 |
||
106 |
Vehicle *FindVehicleBetween(TileIndex from, TileIndex to, byte z) |
|
107 |
{ |
|
926
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
924
diff
changeset
|
108 |
int x1 = TileX(from); |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
924
diff
changeset
|
109 |
int y1 = TileY(from); |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
924
diff
changeset
|
110 |
int x2 = TileX(to); |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
924
diff
changeset
|
111 |
int y2 = TileY(to); |
0 | 112 |
Vehicle *veh; |
113 |
||
114 |
/* Make sure x1 < x2 or y1 < y2 */ |
|
115 |
if (x1 > x2 || y1 > y2) { |
|
116 |
intswap(x1,x2); |
|
117 |
intswap(y1,y2); |
|
118 |
} |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
119 |
FOR_ALL_VEHICLES(veh) { |
0 | 120 |
if ((veh->type == VEH_Train || veh->type == VEH_Road) && (z==0xFF || veh->z_pos == z)) { |
121 |
if ((veh->x_pos>>4) >= x1 && (veh->x_pos>>4) <= x2 && |
|
122 |
(veh->y_pos>>4) >= y1 && (veh->y_pos>>4) <= y2) { |
|
123 |
return veh; |
|
124 |
} |
|
125 |
} |
|
126 |
} |
|
127 |
return NULL; |
|
128 |
} |
|
129 |
||
130 |
void VehiclePositionChanged(Vehicle *v) |
|
131 |
{ |
|
132 |
int img = v->cur_image; |
|
133 |
const SpriteDimension *sd; |
|
134 |
Point pt = RemapCoords(v->x_pos + v->x_offs, v->y_pos + v->y_offs, v->z_pos); |
|
135 |
||
136 |
sd = GetSpriteDimension(img); |
|
137 |
||
138 |
pt.x += sd->xoffs; |
|
139 |
pt.y += sd->yoffs; |
|
140 |
||
141 |
UpdateVehiclePosHash(v, pt.x, pt.y); |
|
142 |
||
143 |
v->left_coord = pt.x; |
|
144 |
v->top_coord = pt.y; |
|
145 |
v->right_coord = pt.x + sd->xsize + 2; |
|
146 |
v->bottom_coord = pt.y + sd->ysize + 2; |
|
147 |
} |
|
148 |
||
395
4c990f33dab7
(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:
337
diff
changeset
|
149 |
void UpdateWaypointSign(Waypoint *cp) |
0 | 150 |
{ |
926
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
924
diff
changeset
|
151 |
Point pt = RemapCoords2(TileX(cp->xy) * 16, TileY(cp->xy) * 16); |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
152 |
SetDParam(0, cp - _waypoints); |
395
4c990f33dab7
(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:
337
diff
changeset
|
153 |
UpdateViewportSignPos(&cp->sign, pt.x, pt.y - 0x20, STR_WAYPOINT_VIEWPORT); |
0 | 154 |
} |
155 |
||
395
4c990f33dab7
(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:
337
diff
changeset
|
156 |
void RedrawWaypointSign(Waypoint *cp) |
0 | 157 |
{ |
158 |
MarkAllViewportsDirty( |
|
159 |
cp->sign.left - 6, |
|
160 |
cp->sign.top, |
|
161 |
cp->sign.left + (cp->sign.width_1 << 2) + 12, |
|
162 |
cp->sign.top + 48); |
|
163 |
} |
|
164 |
||
165 |
// Called after load to update coordinates |
|
166 |
void AfterLoadVehicles() |
|
167 |
{ |
|
168 |
Vehicle *v; |
|
395
4c990f33dab7
(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:
337
diff
changeset
|
169 |
Waypoint *cp; |
0 | 170 |
|
171 |
FOR_ALL_VEHICLES(v) { |
|
172 |
if (v->type != 0) { |
|
173 |
v->left_coord = INVALID_COORD; |
|
174 |
VehiclePositionChanged(v); |
|
175 |
||
176 |
if (v->type == VEH_Train) { |
|
177 |
if (v->subtype == 0) |
|
178 |
UpdateTrainAcceleration(v); |
|
179 |
} |
|
180 |
||
181 |
#if defined(_DEBUG) |
|
182 |
if (!(v->schedule_ptr == NULL || (v->schedule_ptr >= _order_array && v->schedule_ptr < _ptr_to_next_order))) |
|
183 |
v->schedule_ptr = NULL; |
|
184 |
#endif |
|
185 |
} |
|
186 |
} |
|
187 |
||
395
4c990f33dab7
(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:
337
diff
changeset
|
188 |
// update waypoint signs |
4c990f33dab7
(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:
337
diff
changeset
|
189 |
for(cp=_waypoints; cp != endof(_waypoints); cp++) if (cp->xy) UpdateWaypointSign(cp); |
0 | 190 |
} |
191 |
||
192 |
||
193 |
static Vehicle *InitializeVehicle(Vehicle *v) |
|
194 |
{ |
|
195 |
VehicleID index = v->index; |
|
196 |
memset(v, 0, sizeof(Vehicle)); |
|
197 |
v->index = index; |
|
198 |
||
199 |
assert(v->schedule_ptr == NULL); |
|
200 |
||
201 |
v->left_coord = INVALID_COORD; |
|
202 |
v->next = NULL; |
|
203 |
v->next_hash = 0xffff; |
|
204 |
v->string_id = 0; |
|
548
bd14538d4a66
(svn r948) -Codechange: clearified my last commit a bit more with some comment in the code
truelight
parents:
547
diff
changeset
|
205 |
/* random_bits is used to pick out a random sprite for vehicles |
bd14538d4a66
(svn r948) -Codechange: clearified my last commit a bit more with some comment in the code
truelight
parents:
547
diff
changeset
|
206 |
which are technical the same (newgrf stuff). |
bd14538d4a66
(svn r948) -Codechange: clearified my last commit a bit more with some comment in the code
truelight
parents:
547
diff
changeset
|
207 |
Because RandomRange() results in desyncs, and because it does |
826 | 208 |
not really matter that one client has other visual vehicles than |
548
bd14538d4a66
(svn r948) -Codechange: clearified my last commit a bit more with some comment in the code
truelight
parents:
547
diff
changeset
|
209 |
the other, it can be InteractiveRandomRange() without any problem |
bd14538d4a66
(svn r948) -Codechange: clearified my last commit a bit more with some comment in the code
truelight
parents:
547
diff
changeset
|
210 |
*/ |
547 | 211 |
v->random_bits = InteractiveRandomRange(256); |
0 | 212 |
return v; |
213 |
} |
|
214 |
||
215 |
Vehicle *ForceAllocateSpecialVehicle() |
|
216 |
{ |
|
217 |
Vehicle *v; |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
218 |
FOR_ALL_VEHICLES_FROM(v, NUM_NORMAL_VEHICLES) { |
0 | 219 |
if (v->type == 0) |
220 |
return InitializeVehicle(v); |
|
221 |
} |
|
222 |
return NULL; |
|
223 |
||
224 |
} |
|
225 |
||
226 |
Vehicle *ForceAllocateVehicle() |
|
227 |
{ |
|
228 |
Vehicle *v; |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
229 |
FOR_ALL_VEHICLES(v) { |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
230 |
if (v->index >= NUM_NORMAL_VEHICLES) |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
231 |
return NULL; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
232 |
|
0 | 233 |
if (v->type == 0) |
234 |
return InitializeVehicle(v); |
|
235 |
} |
|
236 |
return NULL; |
|
237 |
} |
|
238 |
||
239 |
Vehicle *AllocateVehicle() |
|
240 |
{ |
|
241 |
Vehicle *v; |
|
242 |
int num; |
|
243 |
||
244 |
if (IS_HUMAN_PLAYER(_current_player)) { |
|
245 |
num = 0; |
|
246 |
||
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
247 |
FOR_ALL_VEHICLES(v) { |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
248 |
if (v->index >= NUM_NORMAL_VEHICLES) |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
249 |
break; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
250 |
|
0 | 251 |
if (v->type == 0) |
252 |
num++; |
|
253 |
} |
|
254 |
||
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
255 |
if (num <= VEHICLES_MIN_FREE_FOR_AI) |
0 | 256 |
return NULL; |
257 |
} |
|
258 |
||
259 |
return ForceAllocateVehicle(); |
|
260 |
} |
|
261 |
||
262 |
void *VehicleFromPos(TileIndex tile, void *data, VehicleFromPosProc *proc) |
|
263 |
{ |
|
264 |
int x,y,x2,y2; |
|
265 |
VehicleID veh; |
|
926
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
924
diff
changeset
|
266 |
Point pt = RemapCoords(TileX(tile) * 16, TileY(tile) * 16, 0); |
0 | 267 |
|
268 |
x2 = ((pt.x + 104) & 0x1F80) >> 7; |
|
269 |
x = ((pt.x - 174) & 0x1F80) >> 7; |
|
270 |
||
271 |
y2 = ((pt.y + 56) & 0xFC0); |
|
272 |
y = ((pt.y - 294) & 0xFC0); |
|
273 |
||
274 |
for(;;) { |
|
275 |
int xb = x; |
|
276 |
for(;;) { |
|
277 |
veh = _vehicle_position_hash[ (x+y)&0xFFFF ]; |
|
278 |
while (veh != INVALID_VEHICLE) { |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
279 |
Vehicle *v = GetVehicle(veh); |
0 | 280 |
void *a; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
281 |
|
0 | 282 |
if ((a = proc(v, data)) != NULL) |
283 |
return a; |
|
284 |
veh = v->next_hash; |
|
285 |
} |
|
286 |
||
287 |
if (x == x2) |
|
288 |
break; |
|
289 |
||
290 |
x = (x + 1) & 0x3F; |
|
291 |
} |
|
292 |
x = xb; |
|
293 |
||
294 |
if (y == y2) |
|
295 |
break; |
|
296 |
||
297 |
y = (y + 0x40) & ((0x3F) << 6); |
|
298 |
} |
|
299 |
return NULL; |
|
300 |
} |
|
301 |
||
302 |
||
303 |
||
304 |
void UpdateVehiclePosHash(Vehicle *v, int x, int y) |
|
305 |
{ |
|
306 |
VehicleID *old_hash, *new_hash; |
|
307 |
int old_x = v->left_coord; |
|
308 |
int old_y = v->top_coord; |
|
309 |
Vehicle *u; |
|
310 |
||
311 |
new_hash = (x == INVALID_COORD) ? NULL : &_vehicle_position_hash[GEN_HASH(x,y)]; |
|
312 |
old_hash = (old_x == INVALID_COORD) ? NULL : &_vehicle_position_hash[GEN_HASH(old_x, old_y)]; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
313 |
|
0 | 314 |
if (old_hash == new_hash) |
315 |
return; |
|
316 |
||
317 |
/* remove from hash table? */ |
|
318 |
if (old_hash != NULL) { |
|
319 |
Vehicle *last = NULL; |
|
320 |
int idx = *old_hash; |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
321 |
while ((u = GetVehicle(idx)) != v) { |
0 | 322 |
idx = u->next_hash; |
323 |
assert(idx != INVALID_VEHICLE); |
|
324 |
last = u; |
|
325 |
} |
|
326 |
||
327 |
if (last == NULL) |
|
328 |
*old_hash = v->next_hash; |
|
329 |
else |
|
330 |
last->next_hash = v->next_hash; |
|
331 |
} |
|
332 |
||
333 |
/* insert into hash table? */ |
|
334 |
if (new_hash != NULL) { |
|
335 |
v->next_hash = *new_hash; |
|
336 |
*new_hash = v->index; |
|
337 |
} |
|
338 |
} |
|
339 |
||
340 |
void InitializeVehicles() |
|
341 |
{ |
|
342 |
Vehicle *v; |
|
343 |
int i; |
|
344 |
||
345 |
// clear it... |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
346 |
memset(&_vehicles, 0, sizeof(_vehicles[0]) * _vehicles_size); |
395
4c990f33dab7
(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:
337
diff
changeset
|
347 |
memset(&_waypoints, 0, sizeof(_waypoints)); |
0 | 348 |
memset(&_depots, 0, sizeof(_depots)); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
349 |
|
0 | 350 |
// setup indexes.. |
351 |
i = 0; |
|
352 |
FOR_ALL_VEHICLES(v) |
|
353 |
v->index = i++; |
|
354 |
||
355 |
memset(_vehicle_position_hash, -1, sizeof(_vehicle_position_hash)); |
|
356 |
||
357 |
_ptr_to_next_order = _order_array; |
|
358 |
} |
|
359 |
||
360 |
Vehicle *GetLastVehicleInChain(Vehicle *v) |
|
361 |
{ |
|
362 |
while (v->next != NULL) v = v->next; |
|
363 |
return v; |
|
364 |
} |
|
365 |
||
366 |
Vehicle *GetPrevVehicleInChain(Vehicle *v) |
|
367 |
{ |
|
368 |
Vehicle *org = v; |
|
369 |
||
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
370 |
FOR_ALL_VEHICLES(v) { |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
371 |
if (v->type == VEH_Train && org == v->next) |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
372 |
return v; |
0 | 373 |
} |
374 |
||
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
375 |
return NULL; |
0 | 376 |
} |
377 |
||
378 |
Vehicle *GetFirstVehicleInChain(Vehicle *v) |
|
379 |
{ |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
380 |
Vehicle *u; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
381 |
|
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
382 |
while (true) { |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
383 |
u = v; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
384 |
v = GetPrevVehicleInChain(v); |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
385 |
/* If there is no such vehicle, |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
386 |
'v' == NULL and so 'u' is the first vehicle in chain */ |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
387 |
if (v == NULL) |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
388 |
return u; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
389 |
} |
0 | 390 |
} |
391 |
||
392 |
int CountVehiclesInChain(Vehicle *v) |
|
393 |
{ |
|
394 |
int count = 0; |
|
395 |
do count++; while ( (v=v->next) != NULL); |
|
396 |
return count; |
|
397 |
} |
|
398 |
||
399 |
||
400 |
Depot *AllocateDepot() |
|
401 |
{ |
|
402 |
Depot *dep, *free_dep = NULL; |
|
403 |
int num_free = 0; |
|
404 |
||
405 |
for(dep = _depots; dep != endof(_depots); dep++) { |
|
406 |
if (dep->xy == 0) { |
|
407 |
num_free++; |
|
408 |
if (free_dep==NULL) |
|
409 |
free_dep = dep; |
|
410 |
} |
|
411 |
} |
|
412 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
413 |
if (free_dep == NULL || |
0 | 414 |
(num_free < 30 && IS_HUMAN_PLAYER(_current_player))) { |
415 |
_error_message = STR_1009_TOO_MANY_DEPOTS; |
|
416 |
return NULL; |
|
417 |
} |
|
418 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
419 |
return free_dep; |
0 | 420 |
} |
421 |
||
395
4c990f33dab7
(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:
337
diff
changeset
|
422 |
Waypoint *AllocateWaypoint() |
0 | 423 |
{ |
395
4c990f33dab7
(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:
337
diff
changeset
|
424 |
Waypoint *cp; |
0 | 425 |
|
395
4c990f33dab7
(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:
337
diff
changeset
|
426 |
for(cp = _waypoints; cp != endof(_waypoints); cp++) { |
0 | 427 |
if (cp->xy == 0) |
428 |
return cp; |
|
429 |
} |
|
430 |
||
431 |
return NULL; |
|
432 |
} |
|
433 |
||
395
4c990f33dab7
(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:
337
diff
changeset
|
434 |
uint GetWaypointByTile(uint tile) |
0 | 435 |
{ |
395
4c990f33dab7
(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:
337
diff
changeset
|
436 |
Waypoint *cp; |
0 | 437 |
int i=0; |
395
4c990f33dab7
(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:
337
diff
changeset
|
438 |
for(cp=_waypoints; cp->xy != (TileIndex)tile; cp++) { i++; } |
0 | 439 |
return i; |
440 |
} |
|
441 |
||
442 |
||
443 |
Vehicle *IsScheduleShared(Vehicle *u) |
|
444 |
{ |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
445 |
const Order *sched = u->schedule_ptr; |
0 | 446 |
Vehicle *v; |
447 |
||
448 |
FOR_ALL_VEHICLES(v) { |
|
449 |
if (v->schedule_ptr == sched && u != v && v->type != 0) |
|
450 |
return v; |
|
451 |
} |
|
452 |
return NULL; |
|
453 |
} |
|
454 |
||
455 |
void DeleteVehicleSchedule(Vehicle *v) |
|
456 |
{ |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
457 |
Order *sched; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
458 |
Order *cur; |
0 | 459 |
int num; |
460 |
Vehicle *u; |
|
461 |
||
462 |
// if the schedule is shared, don't delete it. |
|
463 |
if ((u = IsScheduleShared(v)) != NULL) { |
|
464 |
v->schedule_ptr = NULL; |
|
465 |
InvalidateWindow(WC_VEHICLE_ORDERS, u->index); |
|
466 |
return; |
|
467 |
} |
|
468 |
||
469 |
sched = v->schedule_ptr; |
|
470 |
v->schedule_ptr = NULL; |
|
471 |
||
472 |
num = v->num_orders + 1; |
|
473 |
||
474 |
_ptr_to_next_order -= num; |
|
475 |
||
476 |
cur = sched; |
|
477 |
while (cur != _ptr_to_next_order) { |
|
478 |
assert(cur < _ptr_to_next_order); |
|
479 |
cur[0] = cur[num]; |
|
480 |
cur++; |
|
481 |
} |
|
482 |
||
483 |
FOR_ALL_VEHICLES(v) { |
|
484 |
if (v->schedule_ptr != NULL && sched < v->schedule_ptr) { |
|
485 |
v->schedule_ptr -= num; |
|
486 |
} |
|
487 |
} |
|
488 |
} |
|
489 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
490 |
void DeleteCommandFromVehicleSchedule(Order cmd) |
0 | 491 |
{ |
492 |
Vehicle *v; |
|
493 |
bool need_invalidate; |
|
494 |
||
495 |
FOR_ALL_VEHICLES(v) { |
|
496 |
if (v->type != 0 && v->schedule_ptr != NULL) { |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
497 |
Order *sched; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
498 |
|
0 | 499 |
// clear last station visited |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
500 |
if (v->last_station_visited == cmd.station && cmd.type == OT_GOTO_STATION) |
817
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
501 |
v->last_station_visited = 0xFFFF; |
0 | 502 |
|
503 |
// check the next order |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
504 |
if (v->current_order.type == cmd.type && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
505 |
v->current_order.station == cmd.station) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
506 |
v->current_order.type = OT_DUMMY; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
507 |
v->current_order.flags = 0; |
0 | 508 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
509 |
} |
|
510 |
||
511 |
// clear the order list |
|
512 |
need_invalidate = false; |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
513 |
for (sched = v->schedule_ptr; sched->type != OT_NOTHING; ++sched) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
514 |
if (sched->type == cmd.type && sched->station == cmd.station) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
515 |
sched->type = OT_DUMMY; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
516 |
sched->flags = 0; |
0 | 517 |
need_invalidate = true; |
518 |
} |
|
519 |
} |
|
520 |
||
521 |
if (need_invalidate) |
|
522 |
InvalidateWindow(WC_VEHICLE_ORDERS, v->index); |
|
523 |
} |
|
524 |
} |
|
525 |
} |
|
526 |
||
527 |
void DoDeleteDepot(uint tile) |
|
528 |
{ |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
529 |
Order order; |
0 | 530 |
byte dep_index; |
531 |
Depot *d; |
|
532 |
||
533 |
// Clear it |
|
534 |
DoClearSquare(tile); |
|
535 |
||
536 |
// Nullify the depot struct |
|
537 |
for(d=_depots,dep_index=0; d->xy != (TileIndex)tile; d++) {dep_index++;} |
|
538 |
d->xy = 0; |
|
539 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
540 |
order.type = OT_GOTO_DEPOT; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
541 |
order.flags = 0; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
542 |
order.station = dep_index; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
543 |
DeleteCommandFromVehicleSchedule(order); |
0 | 544 |
|
545 |
// Delete the depot |
|
546 |
DeleteWindowById(WC_VEHICLE_DEPOT, tile); |
|
547 |
} |
|
548 |
||
549 |
void DeleteVehicle(Vehicle *v) |
|
550 |
{ |
|
551 |
DeleteName(v->string_id); |
|
552 |
v->type = 0; |
|
553 |
UpdateVehiclePosHash(v, INVALID_COORD, 0); |
|
554 |
v->next_hash = 0xffff; |
|
555 |
||
556 |
if (v->schedule_ptr != NULL) |
|
557 |
DeleteVehicleSchedule(v); |
|
558 |
} |
|
559 |
||
560 |
void DeleteVehicleChain(Vehicle *v) |
|
561 |
{ |
|
562 |
do { |
|
563 |
Vehicle *u = v; |
|
564 |
v = v->next; |
|
565 |
DeleteVehicle(u); |
|
566 |
} while (v); |
|
567 |
} |
|
568 |
||
569 |
||
570 |
void Aircraft_Tick(Vehicle *v); |
|
571 |
void RoadVeh_Tick(Vehicle *v); |
|
572 |
void Ship_Tick(Vehicle *v); |
|
573 |
void Train_Tick(Vehicle *v); |
|
410 | 574 |
static void EffectVehicle_Tick(Vehicle *v); |
0 | 575 |
void DisasterVehicle_Tick(Vehicle *v); |
576 |
||
577 |
VehicleTickProc *_vehicle_tick_procs[] = { |
|
578 |
Train_Tick, |
|
579 |
RoadVeh_Tick, |
|
580 |
Ship_Tick, |
|
581 |
Aircraft_Tick, |
|
582 |
EffectVehicle_Tick, |
|
583 |
DisasterVehicle_Tick, |
|
584 |
}; |
|
585 |
||
586 |
void CallVehicleTicks() |
|
587 |
{ |
|
588 |
Vehicle *v; |
|
589 |
||
590 |
FOR_ALL_VEHICLES(v) { |
|
591 |
if (v->type != 0) |
|
592 |
_vehicle_tick_procs[v->type - 0x10](v); |
|
593 |
} |
|
594 |
} |
|
595 |
||
596 |
static bool CanFillVehicle_FullLoadAny(Vehicle *v) |
|
597 |
{ |
|
598 |
uint32 full = 0, not_full = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
599 |
|
924
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
600 |
//special handling of aircraft |
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
601 |
|
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
602 |
//if the aircraft carries passengers and is NOT full, then |
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
603 |
//continue loading, no matter how much mail is in |
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
604 |
if ((v->type == VEH_Aircraft) && (v->cargo_type == CT_PASSENGERS) && (v->cargo_cap != v->cargo_count)) { |
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
605 |
return true; |
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
606 |
} |
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
607 |
|
0 | 608 |
// patch should return "true" to continue loading, i.e. when there is no cargo type that is fully loaded. |
609 |
do { |
|
610 |
//Should never happen, but just in case future additions change this |
|
611 |
assert(v->cargo_type<32); |
|
612 |
||
613 |
if (v->cargo_cap != 0) { |
|
614 |
uint32 mask = 1 << v->cargo_type; |
|
615 |
if (v->cargo_cap == v->cargo_count) full |= mask; else not_full |= mask; |
|
616 |
} |
|
617 |
} while ( (v=v->next) != NULL); |
|
618 |
||
619 |
// continue loading if there is a non full cargo type and no cargo type that is full |
|
620 |
return not_full && (full & ~not_full) == 0; |
|
621 |
} |
|
622 |
||
623 |
bool CanFillVehicle(Vehicle *v) |
|
624 |
{ |
|
625 |
byte *t = &_map_type_and_height[v->tile]; |
|
626 |
||
627 |
if (t[0] >> 4 == MP_STATION || |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
628 |
(v->type == VEH_Ship && |
0 | 629 |
(t[TILE_XY(1,0)] >> 4 == MP_STATION || |
630 |
t[TILE_XY(-1,0)] >> 4 == MP_STATION || |
|
631 |
t[TILE_XY(0,1)] >> 4 == MP_STATION || |
|
632 |
t[TILE_XY(0,-1)] >> 4 == MP_STATION || |
|
633 |
t[TILE_XY(-2,0)] >> 4 == MP_STATION))) { |
|
634 |
||
635 |
// If patch is active, use alternative CanFillVehicle-function |
|
636 |
if (_patches.full_load_any) |
|
637 |
return CanFillVehicle_FullLoadAny(v); |
|
638 |
||
639 |
do { |
|
640 |
if (v->cargo_count != v->cargo_cap) |
|
641 |
return true; |
|
642 |
} while ( (v=v->next) != NULL); |
|
643 |
} |
|
644 |
return false; |
|
645 |
} |
|
646 |
||
647 |
static void DoDrawVehicle(Vehicle *v) |
|
648 |
{ |
|
649 |
uint32 image = v->cur_image; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
650 |
|
0 | 651 |
if (v->vehstatus & VS_DISASTER) { |
652 |
image |= 0x3224000; |
|
653 |
} else if (v->vehstatus & VS_DEFPAL) { |
|
654 |
image |= (v->vehstatus & VS_CRASHED) ? 0x3248000 : SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner)); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
655 |
} |
0 | 656 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
657 |
AddSortableSpriteToDraw(image, v->x_pos + v->x_offs, v->y_pos + v->y_offs, |
0 | 658 |
v->sprite_width, v->sprite_height, v->z_height, v->z_pos); |
659 |
} |
|
660 |
||
661 |
void ViewportAddVehicles(DrawPixelInfo *dpi) |
|
662 |
{ |
|
663 |
int x,xb, y, x2, y2; |
|
664 |
VehicleID veh; |
|
665 |
Vehicle *v; |
|
666 |
||
667 |
x = ((dpi->left - 70) & 0x1F80) >> 7; |
|
668 |
x2 = ((dpi->left + dpi->width) & 0x1F80) >> 7; |
|
669 |
||
670 |
y = ((dpi->top - 70) & 0xFC0); |
|
671 |
y2 = ((dpi->top + dpi->height) & 0xFC0); |
|
672 |
||
673 |
for(;;) { |
|
674 |
xb = x; |
|
675 |
for(;;) { |
|
676 |
veh = _vehicle_position_hash[ (x+y)&0xFFFF ]; |
|
677 |
while (veh != INVALID_VEHICLE) { |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
678 |
v = GetVehicle(veh); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
679 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
680 |
if (!(v->vehstatus & VS_HIDDEN) && |
0 | 681 |
dpi->left <= v->right_coord && |
682 |
dpi->top <= v->bottom_coord && |
|
683 |
dpi->left + dpi->width >= v->left_coord && |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
684 |
dpi->top + dpi->height >= v->top_coord) { |
0 | 685 |
DoDrawVehicle(v); |
686 |
} |
|
687 |
veh = v->next_hash; |
|
688 |
} |
|
689 |
||
690 |
if (x == x2) |
|
691 |
break; |
|
692 |
x = (x + 1) & 0x3F; |
|
693 |
} |
|
694 |
x = xb; |
|
695 |
||
696 |
if (y == y2) |
|
697 |
break; |
|
698 |
y = (y + 0x40) & ((0x3F) << 6); |
|
699 |
} |
|
700 |
} |
|
701 |
||
702 |
static void EffectInit_0(Vehicle *v) |
|
703 |
{ |
|
704 |
uint32 r = Random(); |
|
705 |
v->cur_image = (uint16)((r & 7) + 3701); |
|
706 |
v->progress = (byte)((r >> 16)&7); |
|
707 |
} |
|
708 |
||
709 |
static void EffectTick_0(Vehicle *v) |
|
710 |
{ |
|
711 |
uint tile; |
|
712 |
uint img; |
|
713 |
||
714 |
if (--v->progress & 0x80) { |
|
715 |
BeginVehicleMove(v); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
716 |
|
0 | 717 |
tile = TILE_FROM_XY(v->x_pos, v->y_pos); |
718 |
if (!IS_TILETYPE(tile, MP_INDUSTRY)) { |
|
719 |
EndVehicleMove(v); |
|
720 |
DeleteVehicle(v); |
|
721 |
return; |
|
722 |
} |
|
723 |
||
724 |
img = v->cur_image + 1; |
|
725 |
if (img > 3708) img = 3701; |
|
726 |
v->cur_image = img; |
|
727 |
v->progress = 7; |
|
728 |
VehiclePositionChanged(v); |
|
729 |
EndVehicleMove(v); |
|
730 |
} |
|
731 |
} |
|
732 |
||
733 |
static void EffectInit_1(Vehicle *v) |
|
734 |
{ |
|
735 |
v->cur_image = 3079; |
|
736 |
v->progress = 12; |
|
737 |
} |
|
738 |
||
739 |
static void EffectTick_1(Vehicle *v) |
|
740 |
{ |
|
741 |
bool moved; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
742 |
|
0 | 743 |
BeginVehicleMove(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
744 |
|
0 | 745 |
moved = false; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
746 |
|
0 | 747 |
if ((++v->progress & 7) == 0) { |
748 |
v->z_pos++; |
|
749 |
moved = true; |
|
750 |
} |
|
751 |
||
752 |
if ((v->progress & 0xF)==4) { |
|
753 |
if (++v->cur_image > 3083) { |
|
754 |
EndVehicleMove(v); |
|
755 |
DeleteVehicle(v); |
|
756 |
return; |
|
757 |
} |
|
758 |
moved = true; |
|
759 |
} |
|
760 |
||
761 |
if (moved) { |
|
762 |
VehiclePositionChanged(v); |
|
763 |
EndVehicleMove(v); |
|
764 |
} |
|
765 |
} |
|
766 |
||
767 |
static void EffectInit_2(Vehicle *v) |
|
768 |
{ |
|
769 |
v->cur_image = 3073; |
|
770 |
v->progress = 0; |
|
771 |
} |
|
772 |
||
773 |
static void EffectTick_2(Vehicle *v) |
|
774 |
{ |
|
775 |
if ((++v->progress & 3) == 0) { |
|
776 |
BeginVehicleMove(v); |
|
777 |
v->z_pos++; |
|
778 |
VehiclePositionChanged(v); |
|
779 |
EndVehicleMove(v); |
|
780 |
} else if ((v->progress & 7) == 1) { |
|
781 |
BeginVehicleMove(v); |
|
782 |
if (++v->cur_image > 3078) { |
|
783 |
EndVehicleMove(v); |
|
784 |
DeleteVehicle(v); |
|
785 |
} else { |
|
786 |
VehiclePositionChanged(v); |
|
787 |
EndVehicleMove(v); |
|
788 |
} |
|
789 |
} |
|
790 |
} |
|
791 |
||
792 |
static void EffectInit_3(Vehicle *v) |
|
793 |
{ |
|
794 |
v->cur_image = 3084; |
|
795 |
v->progress = 1; |
|
796 |
} |
|
797 |
||
798 |
static void EffectTick_3(Vehicle *v) |
|
799 |
{ |
|
800 |
if (++v->progress > 2) { |
|
801 |
v->progress = 0; |
|
802 |
BeginVehicleMove(v); |
|
803 |
if (++v->cur_image > 3089) { |
|
804 |
EndVehicleMove(v); |
|
805 |
DeleteVehicle(v); |
|
806 |
} else { |
|
807 |
VehiclePositionChanged(v); |
|
808 |
EndVehicleMove(v); |
|
809 |
} |
|
810 |
} |
|
811 |
} |
|
812 |
||
813 |
static void EffectInit_4(Vehicle *v) |
|
814 |
{ |
|
815 |
v->cur_image = 2040; |
|
816 |
v->progress = 12; |
|
817 |
} |
|
818 |
||
819 |
static void EffectTick_4(Vehicle *v) |
|
820 |
{ |
|
821 |
bool moved; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
822 |
|
0 | 823 |
BeginVehicleMove(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
824 |
|
0 | 825 |
moved = false; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
826 |
|
0 | 827 |
if ((++v->progress & 3) == 0) { |
828 |
v->z_pos++; |
|
829 |
moved = true; |
|
830 |
} |
|
831 |
||
832 |
if ((v->progress & 0xF)==4) { |
|
833 |
if (++v->cur_image > 2044) { |
|
834 |
EndVehicleMove(v); |
|
835 |
DeleteVehicle(v); |
|
836 |
return; |
|
837 |
} |
|
838 |
moved = true; |
|
839 |
} |
|
840 |
||
841 |
if (moved) { |
|
842 |
VehiclePositionChanged(v); |
|
843 |
EndVehicleMove(v); |
|
844 |
} |
|
845 |
} |
|
846 |
||
847 |
static void EffectInit_5(Vehicle *v) |
|
848 |
{ |
|
849 |
v->cur_image = 3709; |
|
850 |
v->progress = 0; |
|
851 |
} |
|
852 |
||
853 |
static void EffectTick_5(Vehicle *v) |
|
854 |
{ |
|
855 |
if (!(++v->progress & 3)) { |
|
856 |
BeginVehicleMove(v); |
|
857 |
if (++v->cur_image > 3724) { |
|
858 |
EndVehicleMove(v); |
|
859 |
DeleteVehicle(v); |
|
860 |
} else { |
|
861 |
VehiclePositionChanged(v); |
|
862 |
EndVehicleMove(v); |
|
863 |
} |
|
864 |
} |
|
865 |
} |
|
866 |
||
867 |
static void EffectInit_6(Vehicle *v) |
|
868 |
{ |
|
869 |
v->cur_image = 3737; |
|
870 |
v->progress = 0; |
|
871 |
} |
|
872 |
||
873 |
static void EffectTick_6(Vehicle *v) |
|
874 |
{ |
|
875 |
if (!(++v->progress & 7)) { |
|
876 |
BeginVehicleMove(v); |
|
877 |
if (++v->cur_image > 3740) v->cur_image = 3737; |
|
878 |
VehiclePositionChanged(v); |
|
879 |
EndVehicleMove(v); |
|
880 |
} |
|
881 |
||
882 |
if (!--v->u.special.unk0) { |
|
883 |
BeginVehicleMove(v); |
|
884 |
EndVehicleMove(v); |
|
885 |
DeleteVehicle(v); |
|
886 |
} |
|
887 |
} |
|
888 |
||
889 |
static void EffectInit_7(Vehicle *v) |
|
890 |
{ |
|
891 |
v->cur_image = 3725; |
|
892 |
v->progress = 0; |
|
893 |
} |
|
894 |
||
895 |
static void EffectTick_7(Vehicle *v) |
|
896 |
{ |
|
897 |
if (!(++v->progress & 3)) { |
|
898 |
BeginVehicleMove(v); |
|
899 |
if (++v->cur_image > 3736) { |
|
900 |
EndVehicleMove(v); |
|
901 |
DeleteVehicle(v); |
|
902 |
} else { |
|
903 |
VehiclePositionChanged(v); |
|
904 |
EndVehicleMove(v); |
|
905 |
} |
|
906 |
} |
|
907 |
} |
|
908 |
||
909 |
static void EffectInit_8(Vehicle *v) |
|
910 |
{ |
|
911 |
v->cur_image = 1416; |
|
912 |
v->progress = 0; |
|
913 |
v->u.special.unk0 = 0; |
|
914 |
v->u.special.unk2 = 0; |
|
915 |
} |
|
916 |
||
917 |
#define MK(imag,dir,dur) (imag<<6)+(dir<<4)+dur |
|
918 |
static const byte _effecttick8_data[] = { |
|
919 |
MK(0,0,4), |
|
920 |
MK(3,3,4), |
|
921 |
MK(2,2,7), |
|
922 |
MK(0,2,7), |
|
923 |
MK(1,1,3), |
|
924 |
MK(2,2,7), |
|
925 |
MK(0,2,7), |
|
926 |
MK(1,1,3), |
|
927 |
MK(2,2,7), |
|
928 |
MK(0,2,7), |
|
929 |
MK(3,3,6), |
|
930 |
MK(2,2,6), |
|
931 |
MK(1,1,7), |
|
932 |
MK(3,1,7), |
|
933 |
MK(0,0,3), |
|
934 |
MK(1,1,7), |
|
935 |
MK(3,1,7), |
|
936 |
MK(0,0,3), |
|
937 |
MK(1,1,7), |
|
938 |
MK(3,1,7), |
|
939 |
255 |
|
940 |
}; |
|
941 |
#undef MK |
|
942 |
||
943 |
static const int8 _xy_inc_by_dir[5] = { |
|
944 |
-1, 0, 1, 0, -1, |
|
945 |
}; |
|
946 |
||
947 |
#define GET_X_INC_BY_DIR(d) _xy_inc_by_dir[d] |
|
948 |
#define GET_Y_INC_BY_DIR(d) _xy_inc_by_dir[(d)+1] |
|
949 |
||
950 |
static void EffectTick_8(Vehicle *v) |
|
951 |
{ |
|
952 |
byte b; |
|
953 |
||
954 |
if (!(++v->progress & 7)) { |
|
955 |
v->u.special.unk2++; |
|
956 |
BeginVehicleMove(v); |
|
957 |
||
958 |
b = _effecttick8_data[v->u.special.unk0]; |
|
959 |
||
960 |
v->cur_image = 0x588 + (b>>6); |
|
961 |
||
962 |
v->x_pos += GET_X_INC_BY_DIR((b>>4)&3); |
|
963 |
v->y_pos += GET_X_INC_BY_DIR((b>>4)&3); |
|
964 |
||
965 |
if (v->u.special.unk2 < (b & 7)) { |
|
966 |
v->u.special.unk2 = 0; |
|
967 |
v->u.special.unk0++; |
|
968 |
if (_effecttick8_data[v->u.special.unk0] == 0xFF) { |
|
969 |
EndVehicleMove(v); |
|
970 |
DeleteVehicle(v); |
|
971 |
return; |
|
972 |
} |
|
973 |
} |
|
974 |
VehiclePositionChanged(v); |
|
975 |
EndVehicleMove(v); |
|
976 |
} |
|
977 |
} |
|
978 |
||
979 |
static void EffectInit_9(Vehicle *v) |
|
980 |
{ |
|
981 |
v->cur_image = 4751; |
|
982 |
v->spritenum = 0; |
|
983 |
v->progress = 0; |
|
984 |
} |
|
985 |
||
986 |
#define MK(x,y,z,i) (x+4)+(y+4)*16,(z+4)+i*16 |
|
987 |
||
988 |
/* -1,0,1,2 = 2*/ |
|
989 |
/* -1,0,1 = 2*/ |
|
990 |
/* */ |
|
991 |
static const byte _effecttick9_data1[] = { |
|
992 |
MK(0,0,1,0), |
|
993 |
MK(1,0,1,1), |
|
994 |
MK(0,0,1,0), |
|
995 |
MK(1,0,1,2), |
|
996 |
0x81, |
|
997 |
}; |
|
998 |
||
999 |
||
1000 |
static const byte _effecttick9_data2[] = { |
|
1001 |
MK(0,0,1,0), |
|
1002 |
MK(-1,0,1,1), |
|
1003 |
MK(0,0,1,0), |
|
1004 |
MK(-1,0,1,2), |
|
1005 |
0x81, |
|
1006 |
}; |
|
1007 |
||
1008 |
static const byte _effecttick9_data3[] = { |
|
1009 |
MK(0,0,1,0), |
|
1010 |
MK(0,1,1,1), |
|
1011 |
MK(0,0,1,0), |
|
1012 |
MK(0,1,1,2), |
|
1013 |
0x81, |
|
1014 |
}; |
|
1015 |
||
1016 |
static const byte _effecttick9_data4[] = { |
|
1017 |
MK(0,0,1,0), |
|
1018 |
MK(0,-1,1,1), |
|
1019 |
MK(0,0,1,0), |
|
1020 |
MK(0,-1,1,2), |
|
1021 |
0x81, |
|
1022 |
}; |
|
1023 |
||
1024 |
static const byte _effecttick9_data5[] = { |
|
1025 |
MK(0,0,1,2), |
|
1026 |
MK(0,0,1,7), |
|
1027 |
MK(0,0,1,8), |
|
1028 |
MK(0,0,1,9), |
|
1029 |
0x80, |
|
1030 |
}; |
|
1031 |
||
1032 |
static const byte _effecttick9_data6[] = { |
|
1033 |
MK(0,0,1,0), |
|
1034 |
MK(0,0,1,1), |
|
1035 |
MK(0,0,1,0), |
|
1036 |
MK(0,0,1,2), |
|
1037 |
MK(0,0,1,0), |
|
1038 |
MK(0,0,1,1), |
|
1039 |
MK(0,0,1,0), |
|
1040 |
MK(0,0,1,2), |
|
1041 |
MK(0,0,1,0), |
|
1042 |
MK(0,0,1,1), |
|
1043 |
MK(0,0,1,0), |
|
1044 |
MK(0,0,1,2), |
|
1045 |
MK(0,0,1,0), |
|
1046 |
MK(0,0,1,1), |
|
1047 |
MK(0,0,1,0), |
|
1048 |
MK(0,0,1,2), |
|
1049 |
MK(0,0,1,0), |
|
1050 |
MK(0,0,1,1), |
|
1051 |
MK(0,0,1,0), |
|
1052 |
MK(0,0,1,2), |
|
1053 |
MK(0,0,1,0), |
|
1054 |
MK(0,0,1,1), |
|
1055 |
MK(0,0,1,0), |
|
1056 |
MK(0,0,1,2), |
|
1057 |
MK(0,0,1,0), |
|
1058 |
MK(0,0,1,1), |
|
1059 |
MK(0,0,1,0), |
|
1060 |
MK(0,0,1,2), |
|
1061 |
MK(0,0,1,0), |
|
1062 |
MK(0,0,1,1), |
|
1063 |
MK(0,0,1,0), |
|
1064 |
MK(0,0,1,2), |
|
1065 |
MK(0,0,1,0), |
|
1066 |
MK(0,0,1,1), |
|
1067 |
MK(0,0,1,0), |
|
1068 |
MK(0,0,1,2), |
|
1069 |
MK(0,0,1,0), |
|
1070 |
MK(0,0,1,1), |
|
1071 |
MK(0,0,1,0), |
|
1072 |
MK(0,0,1,2), |
|
1073 |
MK(0,0,1,0), |
|
1074 |
MK(0,0,1,1), |
|
1075 |
MK(0,0,1,0), |
|
1076 |
MK(0,0,1,2), |
|
1077 |
MK(0,0,1,0), |
|
1078 |
MK(0,0,1,1), |
|
1079 |
MK(0,0,1,0), |
|
1080 |
MK(0,0,1,2), |
|
1081 |
MK(0,0,1,0), |
|
1082 |
MK(0,0,1,1), |
|
1083 |
MK(0,0,1,0), |
|
1084 |
MK(0,0,1,2), |
|
1085 |
MK(0,0,1,0), |
|
1086 |
MK(0,0,1,1), |
|
1087 |
MK(0,0,1,0), |
|
1088 |
MK(0,0,1,2), |
|
1089 |
MK(0,0,1,0), |
|
1090 |
MK(0,0,1,1), |
|
1091 |
MK(0,0,1,0), |
|
1092 |
MK(0,0,1,2), |
|
1093 |
MK(0,0,1,0), |
|
1094 |
MK(0,0,1,1), |
|
1095 |
MK(2,1,3,0), |
|
1096 |
MK(1,1,3,1), |
|
1097 |
MK(2,1,3,0), |
|
1098 |
MK(1,1,3,2), |
|
1099 |
MK(2,1,3,0), |
|
1100 |
MK(1,1,3,1), |
|
1101 |
MK(2,1,3,0), |
|
1102 |
MK(1,0,1,2), |
|
1103 |
MK(0,0,1,0), |
|
1104 |
MK(1,0,1,1), |
|
1105 |
MK(0,0,1,0), |
|
1106 |
MK(1,0,1,2), |
|
1107 |
MK(0,0,1,0), |
|
1108 |
MK(1,0,1,1), |
|
1109 |
MK(0,0,1,0), |
|
1110 |
MK(1,0,1,2), |
|
1111 |
0x82,0, |
|
1112 |
MK(0,0,0,0xA), |
|
1113 |
MK(0,0,0,0xB), |
|
1114 |
MK(0,0,0,0xC), |
|
1115 |
MK(0,0,0,0xD), |
|
1116 |
MK(0,0,0,0xE), |
|
1117 |
0x80 |
|
1118 |
}; |
|
1119 |
#undef MK |
|
1120 |
||
1121 |
static const byte * const _effecttick9_data[6] = { |
|
1122 |
_effecttick9_data1, |
|
1123 |
_effecttick9_data2, |
|
1124 |
_effecttick9_data3, |
|
1125 |
_effecttick9_data4, |
|
1126 |
_effecttick9_data5, |
|
1127 |
_effecttick9_data6, |
|
1128 |
}; |
|
1129 |
||
1130 |
static void EffectTick_9(Vehicle *v) |
|
1131 |
{ |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1132 |
/* |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1133 |
* Warning: those effects can NOT use Random(), and have to use |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1134 |
* InteractiveRandom(), because somehow someone forgot to save |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1135 |
* spritenum to the savegame, and so it will cause desyncs in |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1136 |
* multiplayer!! (that is: in ToyLand) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1137 |
*/ |
0 | 1138 |
int et; |
1139 |
const byte *b; |
|
1140 |
||
1141 |
if (((++v->progress)&3) != 0) |
|
1142 |
return; |
|
1143 |
||
1144 |
BeginVehicleMove(v); |
|
1145 |
||
1146 |
et = v->engine_type + 1; |
|
1147 |
||
1148 |
if (v->spritenum == 0) { |
|
1149 |
if (++v->cur_image < 4754) { |
|
1150 |
VehiclePositionChanged(v); |
|
1151 |
EndVehicleMove(v); |
|
1152 |
return; |
|
1153 |
} |
|
1154 |
if (v->u.special.unk2 != 0) { |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1155 |
v->spritenum = (byte)((InteractiveRandom()&3)+1); |
0 | 1156 |
} else { |
1157 |
v->spritenum = 6; |
|
1158 |
} |
|
1159 |
et = 0; |
|
1160 |
} |
|
1161 |
||
1162 |
again: |
|
1163 |
v->engine_type = et; |
|
1164 |
b = &_effecttick9_data[v->spritenum - 1][et*2]; |
|
1165 |
||
1166 |
if (*b == 0x80) { |
|
1167 |
EndVehicleMove(v); |
|
1168 |
DeleteVehicle(v); |
|
1169 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1170 |
} |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1171 |
|
0 | 1172 |
if (*b == 0x81) { |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1173 |
if (v->z_pos > 180 || CHANCE16I(1,96, InteractiveRandom())) { |
0 | 1174 |
v->spritenum = 5; |
541 | 1175 |
SndPlayVehicleFx(SND_2F_POP, v); |
0 | 1176 |
} |
1177 |
et = 0; |
|
1178 |
goto again; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1179 |
} |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1180 |
|
0 | 1181 |
if (*b == 0x82) { |
1182 |
uint tile; |
|
1183 |
||
1184 |
et++; |
|
541 | 1185 |
SndPlayVehicleFx(SND_31_EXTRACT, v); |
0 | 1186 |
|
1187 |
tile = TILE_FROM_XY(v->x_pos, v->y_pos); |
|
1188 |
if (IS_TILETYPE(tile, MP_INDUSTRY) && |
|
1189 |
_map5[tile]==0xA2) { |
|
1190 |
AddAnimatedTile(tile); |
|
1191 |
} |
|
1192 |
goto again; |
|
1193 |
} |
|
1194 |
||
1195 |
v->x_pos += (b[0]&0xF) - 4; |
|
1196 |
v->y_pos += (b[0]>>4) - 4; |
|
1197 |
v->z_pos += (b[1]&0xF) - 4; |
|
1198 |
v->cur_image = 4748 + (b[1] >> 4); |
|
1199 |
||
1200 |
VehiclePositionChanged(v); |
|
1201 |
EndVehicleMove(v); |
|
1202 |
} |
|
1203 |
||
1204 |
||
1205 |
typedef void EffectInitProc(Vehicle *v); |
|
1206 |
typedef void EffectTickProc(Vehicle *v); |
|
1207 |
||
1208 |
static EffectInitProc * const _effect_init_procs[] = { |
|
1209 |
EffectInit_0, |
|
1210 |
EffectInit_1, |
|
1211 |
EffectInit_2, |
|
1212 |
EffectInit_3, |
|
1213 |
EffectInit_4, |
|
1214 |
EffectInit_5, |
|
1215 |
EffectInit_6, |
|
1216 |
EffectInit_7, |
|
1217 |
EffectInit_8, |
|
1218 |
EffectInit_9, |
|
1219 |
}; |
|
1220 |
||
1221 |
static EffectTickProc * const _effect_tick_procs[] = { |
|
1222 |
EffectTick_0, |
|
1223 |
EffectTick_1, |
|
1224 |
EffectTick_2, |
|
1225 |
EffectTick_3, |
|
1226 |
EffectTick_4, |
|
1227 |
EffectTick_5, |
|
1228 |
EffectTick_6, |
|
1229 |
EffectTick_7, |
|
1230 |
EffectTick_8, |
|
1231 |
EffectTick_9, |
|
1232 |
}; |
|
1233 |
||
1234 |
||
1235 |
Vehicle *CreateEffectVehicle(int x, int y, int z, int type) |
|
1236 |
{ |
|
1237 |
Vehicle *v; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1238 |
|
0 | 1239 |
v = ForceAllocateSpecialVehicle(); |
1240 |
if (v != NULL) { |
|
1241 |
v->type = VEH_Special; |
|
1242 |
v->subtype = type; |
|
1243 |
v->x_pos = x; |
|
1244 |
v->y_pos = y; |
|
1245 |
v->z_pos = z; |
|
1246 |
v->z_height = v->sprite_width = v->sprite_height = 1; |
|
1247 |
v->x_offs = v->y_offs = 0; |
|
1248 |
v->tile = 0; |
|
1249 |
v->vehstatus = VS_UNCLICKABLE; |
|
1250 |
||
1251 |
_effect_init_procs[type](v); |
|
1252 |
||
1253 |
VehiclePositionChanged(v); |
|
1254 |
BeginVehicleMove(v); |
|
1255 |
EndVehicleMove(v); |
|
1256 |
} |
|
1257 |
return v; |
|
1258 |
} |
|
1259 |
||
1260 |
Vehicle *CreateEffectVehicleAbove(int x, int y, int z, int type) |
|
1261 |
{ |
|
1262 |
return CreateEffectVehicle(x, y, GetSlopeZ(x, y) + z, type); |
|
1263 |
} |
|
1264 |
||
1265 |
Vehicle *CreateEffectVehicleRel(Vehicle *v, int x, int y, int z, int type) |
|
1266 |
{ |
|
1267 |
return CreateEffectVehicle(v->x_pos + x, v->y_pos + y, v->z_pos + z, type); |
|
1268 |
} |
|
1269 |
||
410 | 1270 |
static void EffectVehicle_Tick(Vehicle *v) |
0 | 1271 |
{ |
1272 |
_effect_tick_procs[v->subtype](v); |
|
1273 |
} |
|
1274 |
||
1275 |
Vehicle *CheckClickOnVehicle(ViewPort *vp, int x, int y) |
|
1276 |
{ |
|
1277 |
Vehicle *found = NULL, *v; |
|
1278 |
uint dist, best_dist = (uint)-1; |
|
1279 |
||
1280 |
if ( (uint)(x -= vp->left) >= (uint)vp->width || |
|
1281 |
(uint)(y -= vp->top) >= (uint)vp->height) |
|
1282 |
return NULL; |
|
1283 |
||
1284 |
x = (x << vp->zoom) + vp->virtual_left; |
|
1285 |
y = (y << vp->zoom) + vp->virtual_top; |
|
1286 |
||
1287 |
FOR_ALL_VEHICLES(v) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1288 |
if (v->type != 0 && (v->vehstatus & (VS_HIDDEN|VS_UNCLICKABLE)) == 0 && |
0 | 1289 |
x >= v->left_coord && x <= v->right_coord && |
1290 |
y >= v->top_coord && y <= v->bottom_coord) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1291 |
|
0 | 1292 |
dist = max( |
1293 |
myabs( ((v->left_coord + v->right_coord)>>1) - x ), |
|
1294 |
myabs( ((v->top_coord + v->bottom_coord)>>1) - y ) |
|
1295 |
); |
|
1296 |
||
1297 |
if (dist < best_dist) { |
|
1298 |
found = v; |
|
1299 |
best_dist = dist; |
|
1300 |
} |
|
1301 |
} |
|
1302 |
} |
|
1303 |
||
1304 |
return found; |
|
1305 |
} |
|
1306 |
||
1307 |
||
1308 |
void DecreaseVehicleValue(Vehicle *v) |
|
1309 |
{ |
|
1310 |
v->value -= v->value >> 8; |
|
1311 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1312 |
} |
|
1313 |
||
1314 |
static const byte _breakdown_chance[64] = { |
|
1315 |
3, 3, 3, 3, 3, 3, 3, 3, |
|
1316 |
4, 4, 5, 5, 6, 6, 7, 7, |
|
1317 |
8, 8, 9, 9, 10, 10, 11, 11, |
|
1318 |
12, 13, 13, 13, 13, 14, 15, 16, |
|
1319 |
17, 19, 21, 25, 28, 31, 34, 37, |
|
1320 |
40, 44, 48, 52, 56, 60, 64, 68, |
|
1321 |
72, 80, 90, 100, 110, 120, 130, 140, |
|
1322 |
150, 170, 190, 210, 230, 250, 250, 250, |
|
1323 |
}; |
|
1324 |
||
1325 |
void CheckVehicleBreakdown(Vehicle *v) |
|
1326 |
{ |
|
1327 |
int rel, rel_old; |
|
1328 |
uint32 r; |
|
1329 |
int chance; |
|
1330 |
||
1331 |
/* decrease reliability */ |
|
1332 |
v->reliability = rel = max((rel_old = v->reliability) - v->reliability_spd_dec, 0); |
|
1333 |
if ((rel_old >> 8) != (rel >> 8)) |
|
1334 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1335 |
||
1336 |
if (v->breakdown_ctr != 0 || (v->vehstatus & VS_STOPPED) != 0 || |
|
1337 |
v->cur_speed < 5 || _game_mode == GM_MENU) |
|
1338 |
return; |
|
1339 |
||
1340 |
r = Random(); |
|
1341 |
||
1342 |
/* increase chance of failure */ |
|
1343 |
chance = v->breakdown_chance + 1; |
|
1344 |
if (CHANCE16I(1,25,r)) chance += 25; |
|
1345 |
v->breakdown_chance = min(255, chance); |
|
1346 |
||
1347 |
/* calculate reliability value to use in comparison */ |
|
1348 |
rel = v->reliability; |
|
1349 |
if (v->type == VEH_Ship) rel += 0x6666; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1350 |
|
0 | 1351 |
/* disabled breakdowns? */ |
1352 |
if (_opt.diff.vehicle_breakdowns < 1) |
|
1353 |
return; |
|
1354 |
||
1355 |
/* reduced breakdowns? */ |
|
1356 |
if (_opt.diff.vehicle_breakdowns == 1) rel += 0x6666; |
|
1357 |
||
1358 |
/* check if to break down */ |
|
1359 |
if (_breakdown_chance[(uint)min(rel, 0xffff) >> 10] <= v->breakdown_chance) { |
|
1360 |
v->breakdown_ctr = (byte)(((r >> 16) & 0x3F) + 0x3F); |
|
1361 |
v->breakdown_delay = (byte)(((r >> 24) & 0x7F) | 0x80); |
|
1362 |
v->breakdown_chance = 0; |
|
1363 |
} |
|
1364 |
} |
|
1365 |
||
1366 |
static const StringID _vehicle_type_names[4] = { |
|
1367 |
STR_019F_TRAIN, |
|
1368 |
STR_019C_ROAD_VEHICLE, |
|
1369 |
STR_019E_SHIP, |
|
1370 |
STR_019D_AIRCRAFT, |
|
1371 |
}; |
|
1372 |
||
1373 |
static void ShowVehicleGettingOld(Vehicle *v, StringID msg) |
|
1374 |
{ |
|
1375 |
if (v->owner != _local_player) |
|
1376 |
return; |
|
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1377 |
|
26 | 1378 |
// Do not show getting-old message if autorenew is active |
1379 |
if (_patches.autorenew) |
|
1380 |
return; |
|
0 | 1381 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1382 |
SetDParam(0, _vehicle_type_names[v->type - 0x10]); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1383 |
SetDParam(1, v->unitnumber); |
0 | 1384 |
AddNewsItem(msg, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0); |
1385 |
} |
|
1386 |
||
1387 |
void AgeVehicle(Vehicle *v) |
|
1388 |
{ |
|
1389 |
int age; |
|
1390 |
||
1391 |
if (v->age < 65535) |
|
1392 |
v->age++; |
|
1393 |
||
1394 |
age = v->age - v->max_age; |
|
1395 |
if (age == 366*0 || age == 366*1 || age == 366*2 || age == 366*3 || age == 366*4) |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1396 |
v->reliability_spd_dec <<= 1; |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1397 |
|
0 | 1398 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
1399 |
||
1400 |
if (age == -366) { |
|
1401 |
ShowVehicleGettingOld(v, STR_01A0_IS_GETTING_OLD); |
|
1402 |
} else if (age == 0) { |
|
1403 |
ShowVehicleGettingOld(v, STR_01A1_IS_GETTING_VERY_OLD); |
|
1404 |
} else if (age == 366*1 || age == 366*2 || age == 366*3 || age == 366*4 || age == 366*5) { |
|
1405 |
ShowVehicleGettingOld(v, STR_01A2_IS_GETTING_VERY_OLD_AND); |
|
1406 |
} |
|
1407 |
} |
|
1408 |
||
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1409 |
extern int32 EstimateTrainCost(const RailVehicleInfo *rvi); |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1410 |
extern int32 EstimateRoadVehCost(byte engine_type); |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1411 |
extern int32 EstimateShipCost(uint16 engine_type); |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1412 |
extern int32 EstimateAircraftCost(uint16 engine_type); |
842 | 1413 |
extern int32 CmdRefitRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2); |
1414 |
extern int32 CmdRefitShip(int x, int y, uint32 flags, uint32 p1, uint32 p2); |
|
1415 |
extern int32 CmdRefitAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2); |
|
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1416 |
|
842 | 1417 |
/* Replaces a vehicle (used to be called autorenew) |
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1418 |
p1 - Index of vehicle |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1419 |
p2 - Type of new engine */ |
842 | 1420 |
int32 CmdReplaceVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
0 | 1421 |
{ |
842 | 1422 |
/* makesvariables to inform about how much money the player wants to have left after replacing |
1423 |
and which engine to replace with out of p2. |
|
1424 |
the first 16 bit is the money. The last 5 digits (all 0) were removed when sent, so we add them again. |
|
1425 |
This way the max is 6553 millions and it is more than the 32 bit that is stored in _patches |
|
1426 |
This is a nice way to send 32 bit and only use 16 bit |
|
1427 |
the last 8 bit is the engine. The 8 bits in front of the engine is free so it have room for 16 bit engine entries */ |
|
1428 |
uint16 new_engine_type = (uint16)(p2 & 0xFFFF); |
|
915 | 1429 |
uint32 autorefit_money = (p2 >> 16) * 100000; |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
1430 |
Vehicle *v = GetVehicle(p1); |
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1431 |
int cost, build_cost; |
889
7f8630bfea41
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
842
diff
changeset
|
1432 |
|
7f8630bfea41
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
842
diff
changeset
|
1433 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
915 | 1434 |
|
1435 |
||
890
a39ee70d9886
(svn r1376) fixed an issue where a modified client could try to replace a vehicle to an invalid engine ID and crash the server. Now the server just rejects the request. Also added a check for vehicle ownership, so you should not be able to replace other player's vehicles
bjarni
parents:
889
diff
changeset
|
1436 |
// first we make sure that it's a valid type the user requested |
a39ee70d9886
(svn r1376) fixed an issue where a modified client could try to replace a vehicle to an invalid engine ID and crash the server. Now the server just rejects the request. Also added a check for vehicle ownership, so you should not be able to replace other player's vehicles
bjarni
parents:
889
diff
changeset
|
1437 |
// check that it's an engine that is in the engine array |
a39ee70d9886
(svn r1376) fixed an issue where a modified client could try to replace a vehicle to an invalid engine ID and crash the server. Now the server just rejects the request. Also added a check for vehicle ownership, so you should not be able to replace other player's vehicles
bjarni
parents:
889
diff
changeset
|
1438 |
if (new_engine_type >= TOTAL_NUM_ENGINES ) return CMD_ERROR; |
915 | 1439 |
|
890
a39ee70d9886
(svn r1376) fixed an issue where a modified client could try to replace a vehicle to an invalid engine ID and crash the server. Now the server just rejects the request. Also added a check for vehicle ownership, so you should not be able to replace other player's vehicles
bjarni
parents:
889
diff
changeset
|
1440 |
// check that the new vehicle type is the same as the original one |
907
60cb7cfb0580
(svn r1393) fix [ 1096026 ]. Autorenew trains should now hopefully work like it did before autoreplace was added
bjarni
parents:
892
diff
changeset
|
1441 |
if (v->type != DEREF_ENGINE(new_engine_type)->type) return CMD_ERROR; |
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1442 |
|
890
a39ee70d9886
(svn r1376) fixed an issue where a modified client could try to replace a vehicle to an invalid engine ID and crash the server. Now the server just rejects the request. Also added a check for vehicle ownership, so you should not be able to replace other player's vehicles
bjarni
parents:
889
diff
changeset
|
1443 |
// check that it's the vehicle's owner that requested the replace |
a39ee70d9886
(svn r1376) fixed an issue where a modified client could try to replace a vehicle to an invalid engine ID and crash the server. Now the server just rejects the request. Also added a check for vehicle ownership, so you should not be able to replace other player's vehicles
bjarni
parents:
889
diff
changeset
|
1444 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
a39ee70d9886
(svn r1376) fixed an issue where a modified client could try to replace a vehicle to an invalid engine ID and crash the server. Now the server just rejects the request. Also added a check for vehicle ownership, so you should not be able to replace other player's vehicles
bjarni
parents:
889
diff
changeset
|
1445 |
|
a39ee70d9886
(svn r1376) fixed an issue where a modified client could try to replace a vehicle to an invalid engine ID and crash the server. Now the server just rejects the request. Also added a check for vehicle ownership, so you should not be able to replace other player's vehicles
bjarni
parents:
889
diff
changeset
|
1446 |
|
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1447 |
switch (v->type) { |
842 | 1448 |
case VEH_Train: build_cost = EstimateTrainCost(RailVehInfo(new_engine_type)); break; |
1449 |
case VEH_Road: build_cost = EstimateRoadVehCost(new_engine_type); break; |
|
1450 |
case VEH_Ship: build_cost = EstimateShipCost(new_engine_type); break; |
|
1451 |
case VEH_Aircraft: build_cost = EstimateAircraftCost(new_engine_type); break; |
|
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1452 |
default: return CMD_ERROR; |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1453 |
} |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1454 |
|
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1455 |
/* In a rare situation, when 2 clients are connected to 1 company and have the same |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1456 |
settings, a vehicle can be replaced twice.. check if this is the situation here */ |
842 | 1457 |
if (v->engine_type == new_engine_type && v->age == 0) |
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1458 |
return CMD_ERROR; |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1459 |
|
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1460 |
/* Check if there is money for the upgrade.. if not, give a nice news-item |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1461 |
(that is needed, because this CMD is called automaticly) */ |
842 | 1462 |
if ( DEREF_PLAYER(v->owner)->money64 < (int32)(autorefit_money + build_cost - v->value)) { |
1463 |
if (( _local_player == v->owner ) && ( v->unitnumber != 0 )) { //v->unitnumber = 0 for train cars |
|
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1464 |
int message; |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1465 |
SetDParam(0, v->unitnumber); |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1466 |
switch (v->type) { |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1467 |
case VEH_Train: message = STR_TRAIN_AUTORENEW_FAILED; break; |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1468 |
case VEH_Road: message = STR_ROADVEHICLE_AUTORENEW_FAILED; break; |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1469 |
case VEH_Ship: message = STR_SHIP_AUTORENEW_FAILED; break; |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1470 |
case VEH_Aircraft: message = STR_AIRCRAFT_AUTORENEW_FAILED; break; |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1471 |
// This should never happen |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1472 |
default: message = 0; break; |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1473 |
} |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1474 |
|
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1475 |
AddNewsItem(message, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0); |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1476 |
} |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1477 |
|
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1478 |
return CMD_ERROR; |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1479 |
} |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1480 |
cost = build_cost - v->value; |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1481 |
|
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1482 |
|
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1483 |
if (flags & DC_EXEC) { |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1484 |
Engine *e; |
907
60cb7cfb0580
(svn r1393) fix [ 1096026 ]. Autorenew trains should now hopefully work like it did before autoreplace was added
bjarni
parents:
892
diff
changeset
|
1485 |
e = DEREF_ENGINE(new_engine_type); |
915 | 1486 |
|
842 | 1487 |
// TODO make it check if refit is possible before actually doing it |
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1488 |
|
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1489 |
/* We do not really buy a new vehicle, we upgrade the old one */ |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1490 |
if (v->engine_type != new_engine_type) { |
842 | 1491 |
byte cargo_type = v->cargo_type; |
1492 |
v->engine_type = new_engine_type; |
|
1493 |
v->max_age = e->lifelength * 366; |
|
915 | 1494 |
|
842 | 1495 |
/* Update limits of the vehicle (for when upgraded) */ |
1496 |
switch (v->type) { |
|
1497 |
case VEH_Train: |
|
1498 |
// using if (true) to declare the const |
|
1499 |
{ |
|
1500 |
const RailVehicleInfo *rvi = RailVehInfo(new_engine_type); |
|
1501 |
byte capacity = rvi->capacity; |
|
1502 |
||
1503 |
v->spritenum = rvi->image_index; |
|
1504 |
v->cargo_type = rvi->cargo_type; |
|
1505 |
v->cargo_cap = rvi->capacity; |
|
1506 |
v->max_speed = rvi->max_speed; |
|
1507 |
||
1508 |
v->u.rail.railtype = e->railtype; |
|
915 | 1509 |
|
842 | 1510 |
// 0x0100 means that we skip the check for being stopped inside the depot |
1511 |
// since we do not stop it for autorefitting |
|
1512 |
if (v->cargo_type != cargo_type && capacity) { |
|
1513 |
// BUG: somehow v->index is not transfered properly |
|
1514 |
//CmdRefitRailVehicle(v->x_pos, v->y_pos, DC_EXEC, v->index , cargo_type + 0x0100 ); |
|
1515 |
v->cargo_type = cargo_type; // workaround, but it do not check the refit table |
|
1516 |
} else { |
|
1517 |
v->cargo_type = rvi->cargo_type; |
|
1518 |
} |
|
1519 |
break; |
|
1520 |
} |
|
1521 |
case VEH_Road: |
|
1522 |
// using if (true) to declare the const |
|
1523 |
if (true) { |
|
1524 |
const RoadVehicleInfo *rvi = RoadVehInfo(new_engine_type); |
|
1525 |
||
1526 |
v->spritenum = rvi->image_index; |
|
1527 |
v->cargo_type = rvi->cargo_type; |
|
1528 |
v->cargo_cap = rvi->capacity; |
|
1529 |
v->max_speed = rvi->max_speed; |
|
1530 |
break; |
|
1531 |
} |
|
1532 |
case VEH_Ship: |
|
1533 |
// using if (true) to declare the const |
|
1534 |
if (true) { |
|
1535 |
const ShipVehicleInfo *svi = ShipVehInfo(new_engine_type); |
|
1536 |
||
1537 |
v->spritenum = svi->image_index; |
|
1538 |
v->cargo_type = svi->cargo_type; |
|
1539 |
v->cargo_cap = svi->capacity; |
|
1540 |
v->max_speed = svi->max_speed; |
|
915 | 1541 |
|
842 | 1542 |
// 0x0100 means that we skip the check for being stopped inside the depot |
1543 |
// since we do not stop it for autorefitting |
|
1544 |
if (v->cargo_type != cargo_type) |
|
1545 |
CmdRefitShip(v->x_pos, v->y_pos, DC_EXEC, v->index , cargo_type + 0x0100 ); |
|
1546 |
break; |
|
1547 |
} |
|
1548 |
case VEH_Aircraft: |
|
1549 |
// using if (true) to declare the const |
|
1550 |
if (true) { |
|
1551 |
const AircraftVehicleInfo *avi = AircraftVehInfo(new_engine_type); |
|
1552 |
Vehicle *u; |
|
1553 |
||
1554 |
v->max_speed = avi->max_speed; |
|
1555 |
v->acceleration = avi->acceleration; |
|
1556 |
v->spritenum = avi->image_index; |
|
1557 |
||
1558 |
if ( cargo_type == CT_PASSENGERS ) { |
|
922
fc040662bd43
(svn r1410) Replaced all occurences of 'passanger' by 'passenger' in the code
celestar
parents:
919
diff
changeset
|
1559 |
v->cargo_cap = avi->passenger_capacity; |
842 | 1560 |
u = v->next; |
1561 |
u->cargo_cap = avi->mail_capacity; |
|
1562 |
} else { |
|
1563 |
// 0x0100 means that we skip the check for being stopped inside the hangar |
|
1564 |
// since we do not stop it for autorefitting |
|
1565 |
CmdRefitAircraft(v->x_pos, v->y_pos, DC_EXEC, v->index , cargo_type + 0x0100 ); |
|
1566 |
} |
|
1567 |
break; |
|
1568 |
} |
|
1569 |
default: return CMD_ERROR; |
|
1570 |
} |
|
1571 |
// makes sure that the cargo is still valid compared to new capacity |
|
1572 |
if (v->cargo_count != 0) { |
|
1573 |
if ( v->cargo_type != cargo_type ) |
|
1574 |
v->cargo_count = 0; |
|
1575 |
else if ( v->cargo_count > v->cargo_cap ) |
|
1576 |
v->cargo_count = v->cargo_cap; |
|
1577 |
} |
|
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1578 |
} |
915 | 1579 |
|
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1580 |
v->reliability = e->reliability; |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1581 |
v->reliability_spd_dec = e->reliability_spd_dec; |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1582 |
v->age = 0; |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1583 |
|
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1584 |
v->date_of_last_service = _date; |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1585 |
v->build_year = _cur_year; |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1586 |
|
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1587 |
v->value = build_cost; |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1588 |
|
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1589 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1590 |
} |
842 | 1591 |
//needs to be down here because refitting will change SET_EXPENSES_TYPE if called |
1592 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
|
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1593 |
|
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1594 |
return cost; |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1595 |
} |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1596 |
|
842 | 1597 |
void MaybeReplaceVehicle(Vehicle *v) |
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1598 |
{ |
842 | 1599 |
uint32 new_engine_and_autoreplace_money; |
915 | 1600 |
|
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1601 |
if (v->owner != _local_player) |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1602 |
return; |
842 | 1603 |
// uncomment next line if you want to see what engine type just entered a depot |
1604 |
//printf("engine type: %d\n", v->engine_type); |
|
0 | 1605 |
|
26 | 1606 |
// A vehicle is autorenewed when it it gets the amount of months |
1607 |
// give by _patches.autorenew_months away for his max age. |
|
1608 |
// Standard is -6, meaning 6 months before his max age |
|
1609 |
// It can be any value between -12 and 12. |
|
842 | 1610 |
// Here it also checks if the vehicles is listed for replacement |
1611 |
if (!_patches.autorenew || v->age - v->max_age < (_patches.autorenew_months * 30)) { //replace if engine is too old |
|
1612 |
if (_autoreplace_array[v->engine_type] == v->engine_type && v->type != VEH_Train) //updates to a new model |
|
1613 |
return; |
|
1614 |
} |
|
1615 |
/* Now replace the vehicle */ |
|
829
b71111ccf2cc
(svn r1300) -Fix: The cost for an autorenew was not always send to the right player ;)
truelight
parents:
826
diff
changeset
|
1616 |
_current_player = v->owner; |
915 | 1617 |
|
842 | 1618 |
/* makes the variable to inform about how much money the player wants to have left after replacing |
1619 |
and which engine to replace with |
|
1620 |
the first 16 bit is the money. Since we know the last 5 digits is 0, they are thrown away. |
|
1621 |
This way the max is 6553 millions and it is more than the 32 bit that is stored in _patches |
|
1622 |
This is a nice way to send 32 bit and only use 16 bit |
|
1623 |
the last 8 bit is the engine. The 8 bits in front of the engine is free so it have room for 16 bit engine entries */ |
|
892
3e5dd4c4d5b3
(svn r1378) Fix: train engines are now only replaced if the engine is really set to be replaced and they are replaced to the type that engine type is set to be replaced to (instead of whtat the first engine in the train is set to)
bjarni
parents:
890
diff
changeset
|
1624 |
new_engine_and_autoreplace_money = ((_patches.autorenew_money / 100000) << 16) + _autoreplace_array[v->engine_type]; |
915 | 1625 |
|
907
60cb7cfb0580
(svn r1393) fix [ 1096026 ]. Autorenew trains should now hopefully work like it did before autoreplace was added
bjarni
parents:
892
diff
changeset
|
1626 |
assert(v->type == DEREF_ENGINE(_autoreplace_array[v->engine_type])->type); |
915 | 1627 |
|
842 | 1628 |
if ( v->type != VEH_Train ) { |
1629 |
DoCommandP(v->tile, v->index, new_engine_and_autoreplace_money, NULL, CMD_REPLACE_VEHICLE | CMD_SHOW_NO_ERROR); |
|
1630 |
} else { |
|
892
3e5dd4c4d5b3
(svn r1378) Fix: train engines are now only replaced if the engine is really set to be replaced and they are replaced to the type that engine type is set to be replaced to (instead of whtat the first engine in the train is set to)
bjarni
parents:
890
diff
changeset
|
1631 |
// checks if any of the engines in the train are either old or listed for replacement |
3e5dd4c4d5b3
(svn r1378) Fix: train engines are now only replaced if the engine is really set to be replaced and they are replaced to the type that engine type is set to be replaced to (instead of whtat the first engine in the train is set to)
bjarni
parents:
890
diff
changeset
|
1632 |
do { |
907
60cb7cfb0580
(svn r1393) fix [ 1096026 ]. Autorenew trains should now hopefully work like it did before autoreplace was added
bjarni
parents:
892
diff
changeset
|
1633 |
if ( v->engine_type != _autoreplace_array[v->engine_type] || (_patches.autorenew && (v->age - v->max_age) > (_patches.autorenew_months * 30))) { |
892
3e5dd4c4d5b3
(svn r1378) Fix: train engines are now only replaced if the engine is really set to be replaced and they are replaced to the type that engine type is set to be replaced to (instead of whtat the first engine in the train is set to)
bjarni
parents:
890
diff
changeset
|
1634 |
new_engine_and_autoreplace_money = (new_engine_and_autoreplace_money & 0xFFFF0000) + _autoreplace_array[v->engine_type]; // sets the new engine replacement type |
3e5dd4c4d5b3
(svn r1378) Fix: train engines are now only replaced if the engine is really set to be replaced and they are replaced to the type that engine type is set to be replaced to (instead of whtat the first engine in the train is set to)
bjarni
parents:
890
diff
changeset
|
1635 |
DoCommandP(v->tile, v->index, new_engine_and_autoreplace_money, NULL, CMD_REPLACE_VEHICLE | CMD_SHOW_NO_ERROR); |
842 | 1636 |
} |
892
3e5dd4c4d5b3
(svn r1378) Fix: train engines are now only replaced if the engine is really set to be replaced and they are replaced to the type that engine type is set to be replaced to (instead of whtat the first engine in the train is set to)
bjarni
parents:
890
diff
changeset
|
1637 |
} while ((v=v->next) != NULL); |
842 | 1638 |
} |
1639 |
_current_player = OWNER_NONE; |
|
0 | 1640 |
} |
1641 |
||
1642 |
||
1643 |
int32 CmdNameVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
1644 |
{ |
|
1645 |
Vehicle *v; |
|
1646 |
StringID str; |
|
1647 |
||
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
1648 |
v = GetVehicle(p1); |
0 | 1649 |
|
1650 |
if (!CheckOwnership(v->owner)) |
|
1651 |
return CMD_ERROR; |
|
1652 |
||
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1653 |
str = AllocateNameUnique((byte*)_decode_parameters, 2); |
0 | 1654 |
if (str == 0) |
1655 |
return CMD_ERROR; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1656 |
|
0 | 1657 |
if (flags & DC_EXEC) { |
1658 |
StringID old_str = v->string_id; |
|
1659 |
v->string_id = str; |
|
1660 |
DeleteName(old_str); |
|
588 | 1661 |
ResortVehicleLists(); |
0 | 1662 |
MarkWholeScreenDirty(); |
1663 |
} else { |
|
1664 |
DeleteName(str); |
|
1665 |
} |
|
1666 |
||
1667 |
return 0; |
|
1668 |
} |
|
1669 |
||
1670 |
||
1671 |
||
1672 |
static Rect _old_vehicle_coords; |
|
1673 |
||
1674 |
void BeginVehicleMove(Vehicle *v) { |
|
1675 |
_old_vehicle_coords.left = v->left_coord; |
|
1676 |
_old_vehicle_coords.top = v->top_coord; |
|
1677 |
_old_vehicle_coords.right = v->right_coord; |
|
1678 |
_old_vehicle_coords.bottom = v->bottom_coord; |
|
1679 |
} |
|
1680 |
||
1681 |
void EndVehicleMove(Vehicle *v) |
|
1682 |
{ |
|
1683 |
MarkAllViewportsDirty( |
|
1684 |
min(_old_vehicle_coords.left,v->left_coord), |
|
1685 |
min(_old_vehicle_coords.top,v->top_coord), |
|
1686 |
max(_old_vehicle_coords.right,v->right_coord)+1, |
|
1687 |
max(_old_vehicle_coords.bottom,v->bottom_coord)+1 |
|
1688 |
); |
|
1689 |
} |
|
1690 |
||
1691 |
void InvalidateVehicleOrderWidget(Vehicle *v) |
|
1692 |
{ |
|
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:
679
diff
changeset
|
1693 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1694 |
InvalidateWindowWidget(WC_VEHICLE_ORDERS, v->index, 2); |
1695 |
} |
|
1696 |
||
1697 |
/* returns true if staying in the same tile */ |
|
1698 |
bool GetNewVehiclePos(Vehicle *v, GetNewVehiclePosResult *gp) |
|
1699 |
{ |
|
1700 |
static const int8 _delta_coord[16] = { |
|
1701 |
-1,-1,-1, 0, 1, 1, 1, 0, /* x */ |
|
1702 |
-1, 0, 1, 1, 1, 0,-1,-1, /* y */ |
|
1703 |
}; |
|
1704 |
||
1705 |
int x = v->x_pos + _delta_coord[v->direction]; |
|
1706 |
int y = v->y_pos + _delta_coord[v->direction + 8]; |
|
1707 |
||
1708 |
gp->x = x; |
|
1709 |
gp->y = y; |
|
1710 |
gp->old_tile = v->tile; |
|
1711 |
gp->new_tile = TILE_FROM_XY(x,y); |
|
1712 |
return gp->old_tile == gp->new_tile; |
|
1713 |
} |
|
1714 |
||
1715 |
static const byte _new_direction_table[9] = { |
|
1716 |
0, 7, 6, |
|
1717 |
1, 3, 5, |
|
1718 |
2, 3, 4, |
|
1719 |
}; |
|
1720 |
||
1721 |
byte GetDirectionTowards(Vehicle *v, int x, int y) |
|
1722 |
{ |
|
1723 |
byte dirdiff, dir; |
|
1724 |
int i = 0; |
|
1725 |
||
1726 |
if (y >= v->y_pos) { |
|
1727 |
if (y != v->y_pos) i+=3; |
|
1728 |
i+=3; |
|
1729 |
} |
|
1730 |
||
1731 |
if (x >= v->x_pos) { |
|
1732 |
if (x != v->x_pos) i++; |
|
1733 |
i++; |
|
1734 |
} |
|
1735 |
||
1736 |
dir = v->direction; |
|
1737 |
||
1738 |
dirdiff = _new_direction_table[i] - dir; |
|
1739 |
if (dirdiff == 0) |
|
1740 |
return dir; |
|
1741 |
return (dir+((dirdiff&7)<5?1:-1)) & 7; |
|
1742 |
} |
|
1743 |
||
22 | 1744 |
/* Return value has bit 0x2 set, when the vehicle enters a station. Then, |
1745 |
* result << 8 contains the id of the station entered. If the return value has |
|
1746 |
* bit 0x8 set, the vehicle could not and did not enter the tile. Are there |
|
1747 |
* other bits that can be set? */ |
|
0 | 1748 |
uint32 VehicleEnterTile(Vehicle *v, uint tile, int x, int y) |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1749 |
{ |
0 | 1750 |
uint old_tile = v->tile; |
1751 |
uint32 result = _tile_type_procs[GET_TILETYPE(tile)]->vehicle_enter_tile_proc(v, tile, x, y); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1752 |
|
22 | 1753 |
/* When vehicle_enter_tile_proc returns 8, that apparently means that |
1754 |
* we cannot enter the tile at all. In that case, don't call |
|
1755 |
* leave_tile. */ |
|
0 | 1756 |
if (!(result & 8) && old_tile != tile) { |
1757 |
VehicleLeaveTileProc *proc = _tile_type_procs[GET_TILETYPE(old_tile)]->vehicle_leave_tile_proc; |
|
1758 |
if (proc != NULL) |
|
1759 |
proc(v, old_tile, x, y); |
|
1760 |
} |
|
1761 |
return result; |
|
1762 |
} |
|
1763 |
||
1764 |
uint GetFreeUnitNumber(byte type) |
|
1765 |
{ |
|
1766 |
uint unit_num = 0; |
|
1767 |
Vehicle *u; |
|
1768 |
||
1769 |
restart: |
|
1770 |
unit_num++; |
|
1771 |
FOR_ALL_VEHICLES(u) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1772 |
if (u->type == type && u->owner == _current_player && |
0 | 1773 |
unit_num == u->unitnumber) |
1774 |
goto restart; |
|
1775 |
} |
|
1776 |
return unit_num; |
|
1777 |
} |
|
1778 |
||
1779 |
||
1780 |
// Save and load of vehicles |
|
1781 |
const byte _common_veh_desc[] = { |
|
1782 |
SLE_VAR(Vehicle,subtype, SLE_UINT8), |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1783 |
|
0 | 1784 |
SLE_VAR(Vehicle,next_in_chain_old, SLE_UINT16), |
1785 |
SLE_VAR(Vehicle,string_id, SLE_STRINGID), |
|
1786 |
SLE_VAR(Vehicle,unitnumber, SLE_UINT8), |
|
1787 |
SLE_VAR(Vehicle,owner, SLE_UINT8), |
|
1788 |
SLE_VAR(Vehicle,tile, SLE_UINT16), |
|
1789 |
SLE_VAR(Vehicle,dest_tile, SLE_UINT16), |
|
1790 |
||
1791 |
SLE_VAR(Vehicle,x_pos, SLE_INT16), |
|
1792 |
SLE_VAR(Vehicle,y_pos, SLE_INT16), |
|
1793 |
SLE_VAR(Vehicle,z_pos, SLE_UINT8), |
|
1794 |
SLE_VAR(Vehicle,direction, SLE_UINT8), |
|
1795 |
||
1796 |
SLE_VAR(Vehicle,cur_image, SLE_UINT16), |
|
1797 |
SLE_VAR(Vehicle,spritenum, SLE_UINT8), |
|
1798 |
SLE_VAR(Vehicle,sprite_width, SLE_UINT8), |
|
1799 |
SLE_VAR(Vehicle,sprite_height, SLE_UINT8), |
|
1800 |
SLE_VAR(Vehicle,z_height, SLE_UINT8), |
|
1801 |
SLE_VAR(Vehicle,x_offs, SLE_INT8), |
|
1802 |
SLE_VAR(Vehicle,y_offs, SLE_INT8), |
|
1803 |
SLE_VAR(Vehicle,engine_type, SLE_UINT16), |
|
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:
410
diff
changeset
|
1804 |
|
0 | 1805 |
SLE_VAR(Vehicle,max_speed, SLE_UINT16), |
1806 |
SLE_VAR(Vehicle,cur_speed, SLE_UINT16), |
|
1807 |
SLE_VAR(Vehicle,subspeed, SLE_UINT8), |
|
1808 |
SLE_VAR(Vehicle,acceleration, SLE_UINT8), |
|
1809 |
SLE_VAR(Vehicle,progress, SLE_UINT8), |
|
1810 |
||
1811 |
SLE_VAR(Vehicle,vehstatus, SLE_UINT8), |
|
817
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
1812 |
SLE_CONDVAR(Vehicle,last_station_visited, SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
1813 |
SLE_CONDVAR(Vehicle,last_station_visited, SLE_UINT16, 5, 255), |
0 | 1814 |
|
1815 |
SLE_VAR(Vehicle,cargo_type, SLE_UINT8), |
|
1816 |
SLE_VAR(Vehicle,cargo_days, SLE_UINT8), |
|
1817 |
SLE_VAR(Vehicle,cargo_source, SLE_UINT8), |
|
1818 |
SLE_VAR(Vehicle,cargo_cap, SLE_UINT16), |
|
1819 |
SLE_VAR(Vehicle,cargo_count, SLE_UINT16), |
|
1820 |
||
1821 |
SLE_VAR(Vehicle,day_counter, SLE_UINT8), |
|
1822 |
SLE_VAR(Vehicle,tick_counter, SLE_UINT8), |
|
1823 |
||
1824 |
SLE_VAR(Vehicle,cur_order_index, SLE_UINT8), |
|
1825 |
SLE_VAR(Vehicle,num_orders, SLE_UINT8), |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
1826 |
SLE_VAR(Vehicle,current_order, SLE_UINT8), /* XXX hack to avoid version bump */ |
556
d6b9bbfe0596
(svn r957) -Fix: vehicle.c compiler problems for MSVC6 only! (Tron)
darkvater
parents:
555
diff
changeset
|
1827 |
#if _MSC_VER != 1200 |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
1828 |
SLE_VAR(Vehicle,current_order.station, SLE_UINT8), |
556
d6b9bbfe0596
(svn r957) -Fix: vehicle.c compiler problems for MSVC6 only! (Tron)
darkvater
parents:
555
diff
changeset
|
1829 |
#else /* XXX workaround for MSVC6 */ |
d6b9bbfe0596
(svn r957) -Fix: vehicle.c compiler problems for MSVC6 only! (Tron)
darkvater
parents:
555
diff
changeset
|
1830 |
SLE_VAR2(Vehicle, current_order, Order, station, SLE_UINT8), |
d6b9bbfe0596
(svn r957) -Fix: vehicle.c compiler problems for MSVC6 only! (Tron)
darkvater
parents:
555
diff
changeset
|
1831 |
#endif |
0 | 1832 |
SLE_REF(Vehicle,schedule_ptr, REF_SCHEDULE), |
1833 |
||
1834 |
SLE_VAR(Vehicle,age, SLE_UINT16), |
|
1835 |
SLE_VAR(Vehicle,max_age, SLE_UINT16), |
|
1836 |
SLE_VAR(Vehicle,date_of_last_service,SLE_UINT16), |
|
1837 |
SLE_VAR(Vehicle,service_interval, SLE_UINT16), |
|
1838 |
SLE_VAR(Vehicle,reliability, SLE_UINT16), |
|
1839 |
SLE_VAR(Vehicle,reliability_spd_dec,SLE_UINT16), |
|
1840 |
SLE_VAR(Vehicle,breakdown_ctr, SLE_UINT8), |
|
1841 |
SLE_VAR(Vehicle,breakdown_delay, SLE_UINT8), |
|
1842 |
SLE_VAR(Vehicle,breakdowns_since_last_service, SLE_UINT8), |
|
1843 |
SLE_VAR(Vehicle,breakdown_chance, SLE_UINT8), |
|
1844 |
SLE_VAR(Vehicle,build_year, SLE_UINT8), |
|
1845 |
||
1846 |
SLE_VAR(Vehicle,load_unload_time_rem, SLE_UINT16), |
|
1847 |
||
1848 |
SLE_VAR(Vehicle,profit_this_year, SLE_INT32), |
|
1849 |
SLE_VAR(Vehicle,profit_last_year, SLE_INT32), |
|
1850 |
SLE_VAR(Vehicle,value, SLE_UINT32), |
|
1851 |
||
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:
410
diff
changeset
|
1852 |
SLE_VAR(Vehicle,random_bits, SLE_UINT8), |
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:
410
diff
changeset
|
1853 |
SLE_VAR(Vehicle,waiting_triggers, SLE_UINT8), |
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:
410
diff
changeset
|
1854 |
|
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:
410
diff
changeset
|
1855 |
// reserve extra space in savegame here. (currently 14 bytes) |
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:
410
diff
changeset
|
1856 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U8 | SLE_VAR_NULL, 2, 2, 255), /* 2 */ |
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:
410
diff
changeset
|
1857 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U16 | SLE_VAR_NULL, 2, 2, 255), /* 4 */ |
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:
410
diff
changeset
|
1858 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U32 | SLE_VAR_NULL, 2, 2, 255), /* 8 */ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1859 |
|
0 | 1860 |
SLE_END() |
1861 |
}; |
|
1862 |
||
1863 |
||
1864 |
static const byte _train_desc[] = { |
|
1865 |
SLE_WRITEBYTE(Vehicle,type,VEH_Train, 0), // Train type. VEH_Train in mem, 0 in file. |
|
1866 |
SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
|
1867 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRail,crash_anim_pos), SLE_UINT16), |
|
1868 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRail,force_proceed), SLE_UINT8), |
|
1869 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRail,railtype), SLE_UINT8), |
|
1870 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRail,track), SLE_UINT8), |
|
1871 |
||
1872 |
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleRail,flags), SLE_UINT8, 2, 255), |
|
1873 |
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleRail,days_since_order_progr), SLE_UINT16, 2, 255), |
|
1874 |
||
1875 |
// reserve extra space in savegame here. (currently 13 bytes) |
|
1876 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U8 | SLE_VAR_NULL, 13, 2, 255), |
|
1877 |
||
1878 |
SLE_END() |
|
1879 |
}; |
|
1880 |
||
1881 |
static const byte _roadveh_desc[] = { |
|
1882 |
SLE_WRITEBYTE(Vehicle,type,VEH_Road, 1), // Road type. VEH_Road in mem, 1 in file. |
|
1883 |
SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
|
1884 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,state), SLE_UINT8), |
|
1885 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,frame), SLE_UINT8), |
|
1886 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,unk2), SLE_UINT16), |
|
1887 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,overtaking), SLE_UINT8), |
|
1888 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,overtaking_ctr),SLE_UINT8), |
|
1889 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,crashed_ctr), SLE_UINT16), |
|
1890 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,reverse_ctr), SLE_UINT8), |
|
1891 |
||
1892 |
// reserve extra space in savegame here. (currently 16 bytes) |
|
1893 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U64 | SLE_VAR_NULL, 2, 2, 255), |
|
1894 |
||
1895 |
SLE_END() |
|
1896 |
}; |
|
1897 |
||
1898 |
static const byte _ship_desc[] = { |
|
1899 |
SLE_WRITEBYTE(Vehicle,type,VEH_Ship, 2), // Ship type. VEH_Ship in mem, 2 in file. |
|
1900 |
SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
|
1901 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleShip,state), SLE_UINT8), |
|
1902 |
||
1903 |
// reserve extra space in savegame here. (currently 16 bytes) |
|
1904 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U64 | SLE_VAR_NULL, 2, 2, 255), |
|
1905 |
||
1906 |
SLE_END() |
|
1907 |
}; |
|
1908 |
||
1909 |
static const byte _aircraft_desc[] = { |
|
1910 |
SLE_WRITEBYTE(Vehicle,type,VEH_Aircraft, 3), // Aircraft type. VEH_Aircraft in mem, 3 in file. |
|
1911 |
SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
|
1912 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleAir,crashed_counter), SLE_UINT16), |
|
1913 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleAir,pos), SLE_UINT8), |
|
817
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
1914 |
|
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
1915 |
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleAir,targetairport), SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
1916 |
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleAir,targetairport), SLE_UINT16, 5, 255), |
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
1917 |
|
0 | 1918 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleAir,state), SLE_UINT8), |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1919 |
|
0 | 1920 |
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleAir,previous_pos), SLE_UINT8, 2, 255), |
1921 |
||
1922 |
// reserve extra space in savegame here. (currently 15 bytes) |
|
1923 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U8 | SLE_VAR_NULL, 15, 2, 255), |
|
1924 |
||
1925 |
SLE_END() |
|
1926 |
}; |
|
1927 |
||
1928 |
static const byte _special_desc[] = { |
|
1929 |
SLE_WRITEBYTE(Vehicle,type,VEH_Special, 4), |
|
1930 |
||
1931 |
SLE_VAR(Vehicle,subtype, SLE_UINT8), |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1932 |
|
0 | 1933 |
SLE_VAR(Vehicle,tile, SLE_UINT16), |
1934 |
||
1935 |
SLE_VAR(Vehicle,x_pos, SLE_INT16), |
|
1936 |
SLE_VAR(Vehicle,y_pos, SLE_INT16), |
|
1937 |
SLE_VAR(Vehicle,z_pos, SLE_UINT8), |
|
1938 |
||
1939 |
SLE_VAR(Vehicle,cur_image, SLE_UINT16), |
|
1940 |
SLE_VAR(Vehicle,sprite_width, SLE_UINT8), |
|
1941 |
SLE_VAR(Vehicle,sprite_height, SLE_UINT8), |
|
1942 |
SLE_VAR(Vehicle,z_height, SLE_UINT8), |
|
1943 |
SLE_VAR(Vehicle,x_offs, SLE_INT8), |
|
1944 |
SLE_VAR(Vehicle,y_offs, SLE_INT8), |
|
1945 |
SLE_VAR(Vehicle,progress, SLE_UINT8), |
|
1946 |
SLE_VAR(Vehicle,vehstatus, SLE_UINT8), |
|
1947 |
||
1948 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleSpecial,unk0), SLE_UINT16), |
|
1949 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleSpecial,unk2), SLE_UINT8), |
|
1950 |
||
1951 |
// reserve extra space in savegame here. (currently 16 bytes) |
|
1952 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U64 | SLE_VAR_NULL, 2, 2, 255), |
|
1953 |
||
1954 |
SLE_END() |
|
1955 |
}; |
|
1956 |
||
1957 |
static const byte _disaster_desc[] = { |
|
1958 |
SLE_WRITEBYTE(Vehicle,type,VEH_Disaster, 5), |
|
1959 |
||
1960 |
SLE_VAR(Vehicle,next_in_chain_old,SLE_UINT16), |
|
1961 |
||
1962 |
SLE_VAR(Vehicle,subtype, SLE_UINT8), |
|
1963 |
SLE_VAR(Vehicle,tile, SLE_UINT16), |
|
1964 |
SLE_VAR(Vehicle,dest_tile, SLE_UINT16), |
|
1965 |
||
1966 |
SLE_VAR(Vehicle,x_pos, SLE_INT16), |
|
1967 |
SLE_VAR(Vehicle,y_pos, SLE_INT16), |
|
1968 |
SLE_VAR(Vehicle,z_pos, SLE_UINT8), |
|
1969 |
SLE_VAR(Vehicle,direction, SLE_UINT8), |
|
1970 |
||
1971 |
SLE_VAR(Vehicle,x_offs, SLE_INT8), |
|
1972 |
SLE_VAR(Vehicle,y_offs, SLE_INT8), |
|
1973 |
SLE_VAR(Vehicle,sprite_width, SLE_UINT8), |
|
1974 |
SLE_VAR(Vehicle,sprite_height, SLE_UINT8), |
|
1975 |
SLE_VAR(Vehicle,z_height, SLE_UINT8), |
|
1976 |
SLE_VAR(Vehicle,owner, SLE_UINT8), |
|
1977 |
SLE_VAR(Vehicle,vehstatus, SLE_UINT8), |
|
556
d6b9bbfe0596
(svn r957) -Fix: vehicle.c compiler problems for MSVC6 only! (Tron)
darkvater
parents:
555
diff
changeset
|
1978 |
#if _MSC_VER != 1200 |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
1979 |
SLE_VAR(Vehicle,current_order.station, SLE_UINT8), |
556
d6b9bbfe0596
(svn r957) -Fix: vehicle.c compiler problems for MSVC6 only! (Tron)
darkvater
parents:
555
diff
changeset
|
1980 |
#else /* XXX workaround for MSVC6 */ |
d6b9bbfe0596
(svn r957) -Fix: vehicle.c compiler problems for MSVC6 only! (Tron)
darkvater
parents:
555
diff
changeset
|
1981 |
SLE_VAR2(Vehicle, current_order, Order, station, SLE_UINT8), |
d6b9bbfe0596
(svn r957) -Fix: vehicle.c compiler problems for MSVC6 only! (Tron)
darkvater
parents:
555
diff
changeset
|
1982 |
#endif |
0 | 1983 |
|
1984 |
SLE_VAR(Vehicle,cur_image, SLE_UINT16), |
|
1985 |
SLE_VAR(Vehicle,age, SLE_UINT16), |
|
1986 |
||
1987 |
SLE_VAR(Vehicle,tick_counter, SLE_UINT8), |
|
1988 |
||
1989 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleDisaster,image_override), SLE_UINT16), |
|
1990 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleDisaster,unk2), SLE_UINT16), |
|
1991 |
||
1992 |
// reserve extra space in savegame here. (currently 16 bytes) |
|
1993 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U64 | SLE_VAR_NULL, 2, 2, 255), |
|
1994 |
||
1995 |
SLE_END() |
|
1996 |
}; |
|
1997 |
||
1998 |
||
1999 |
static const void *_veh_descs[] = { |
|
2000 |
_train_desc, |
|
2001 |
_roadveh_desc, |
|
2002 |
_ship_desc, |
|
2003 |
_aircraft_desc, |
|
2004 |
_special_desc, |
|
2005 |
_disaster_desc, |
|
2006 |
}; |
|
2007 |
||
2008 |
// Will be called when the vehicles need to be saved. |
|
2009 |
static void Save_VEHS() |
|
2010 |
{ |
|
2011 |
Vehicle *v; |
|
2012 |
// Write the vehicles |
|
2013 |
FOR_ALL_VEHICLES(v) { |
|
2014 |
if (v->type != 0) { |
|
817
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
2015 |
/* XXX - Here for now, because we did not bump the savegame to version 5 yet */ |
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
2016 |
if (_sl.version < 5 && v->last_station_visited == 0xFFFF) |
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
2017 |
v->last_station_visited = 0xFF; |
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
2018 |
|
0 | 2019 |
SlSetArrayIndex(v->index); |
2020 |
v->next_in_chain_old = v->next ? v->next->index : INVALID_VEHICLE; |
|
2021 |
SlObject(v, _veh_descs[v->type - 0x10]); |
|
2022 |
} |
|
2023 |
} |
|
2024 |
} |
|
2025 |
||
2026 |
// Will be called when vehicles need to be loaded. |
|
2027 |
static void Load_VEHS() |
|
2028 |
{ |
|
2029 |
int index; |
|
2030 |
Vehicle *v; |
|
2031 |
||
2032 |
while ((index = SlIterateArray()) != -1) { |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
2033 |
Vehicle *v = GetVehicle(index); |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
2034 |
|
0 | 2035 |
v->next_in_chain_old = INVALID_VEHICLE; |
2036 |
SlObject(v, _veh_descs[SlReadByte()]); |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
2037 |
v->next = (v->next_in_chain_old == INVALID_VEHICLE) ? NULL : GetVehicle(v->next_in_chain_old); |
0 | 2038 |
if (v->type == VEH_Train) |
2039 |
v->u.rail.first_engine = 0xffff; |
|
817
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
2040 |
|
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
2041 |
/* Old savegames used 'last_station_visited = 0xFF', should be 0xFFFF */ |
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
2042 |
if (_sl.version < 5 && v->last_station_visited == 0xFF) |
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
2043 |
v->last_station_visited = 0xFFFF; |
0 | 2044 |
} |
2045 |
||
2046 |
// Iterate through trains and set first_engine appropriately. |
|
2047 |
FOR_ALL_VEHICLES(v) { |
|
2048 |
Vehicle *w; |
|
2049 |
||
2050 |
if (v->type != VEH_Train || v->subtype != 0) |
|
2051 |
continue; |
|
2052 |
||
2053 |
for (w = v->next; w; w = w->next) |
|
2054 |
w->u.rail.first_engine = v->engine_type; |
|
2055 |
} |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
2056 |
|
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
2057 |
/* This is to ensure all pointers are within the limits of |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
2058 |
_vehicles_size */ |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
2059 |
if (_vehicle_id_ctr_day >= _vehicles_size) |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
2060 |
_vehicle_id_ctr_day = 0; |
0 | 2061 |
} |
2062 |
||
2063 |
static const byte _depot_desc[] = { |
|
2064 |
SLE_VAR(Depot,xy, SLE_UINT16), |
|
2065 |
SLE_VAR(Depot,town_index, SLE_UINT16), |
|
2066 |
SLE_END() |
|
2067 |
}; |
|
2068 |
||
2069 |
static void Save_DEPT() |
|
2070 |
{ |
|
2071 |
Depot *d; |
|
2072 |
int i; |
|
2073 |
for(i=0,d=_depots; i!=lengthof(_depots); i++,d++) { |
|
2074 |
if (d->xy != 0) { |
|
2075 |
SlSetArrayIndex(i); |
|
2076 |
SlObject(d, _depot_desc); |
|
2077 |
} |
|
2078 |
} |
|
2079 |
} |
|
2080 |
||
2081 |
static void Load_DEPT() |
|
2082 |
{ |
|
2083 |
int index; |
|
2084 |
while ((index = SlIterateArray()) != -1) { |
|
2085 |
SlObject(&_depots[index], _depot_desc); |
|
2086 |
} |
|
2087 |
} |
|
2088 |
||
395
4c990f33dab7
(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:
337
diff
changeset
|
2089 |
static const byte _waypoint_desc[] = { |
4c990f33dab7
(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:
337
diff
changeset
|
2090 |
SLE_VAR(Waypoint,xy, SLE_UINT16), |
4c990f33dab7
(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:
337
diff
changeset
|
2091 |
SLE_VAR(Waypoint,town_or_string, SLE_UINT16), |
4c990f33dab7
(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:
337
diff
changeset
|
2092 |
SLE_VAR(Waypoint,deleted, SLE_UINT8), |
0 | 2093 |
|
395
4c990f33dab7
(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:
337
diff
changeset
|
2094 |
SLE_CONDVAR(Waypoint, build_date, SLE_UINT16, 3, 255), |
4c990f33dab7
(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:
337
diff
changeset
|
2095 |
SLE_CONDVAR(Waypoint, stat_id, SLE_UINT8, 3, 255), |
0 | 2096 |
|
2097 |
SLE_END() |
|
2098 |
}; |
|
2099 |
||
2100 |
static void Save_CHKP() |
|
2101 |
{ |
|
395
4c990f33dab7
(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:
337
diff
changeset
|
2102 |
Waypoint *cp; |
0 | 2103 |
int i; |
395
4c990f33dab7
(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:
337
diff
changeset
|
2104 |
for(i=0,cp=_waypoints; i!=lengthof(_waypoints); i++,cp++) { |
0 | 2105 |
if (cp->xy != 0) { |
2106 |
SlSetArrayIndex(i); |
|
395
4c990f33dab7
(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:
337
diff
changeset
|
2107 |
SlObject(cp, _waypoint_desc); |
0 | 2108 |
} |
2109 |
} |
|
2110 |
} |
|
2111 |
||
2112 |
static void Load_CHKP() |
|
2113 |
{ |
|
2114 |
int index; |
|
2115 |
while ((index = SlIterateArray()) != -1) { |
|
395
4c990f33dab7
(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:
337
diff
changeset
|
2116 |
SlObject(&_waypoints[index], _waypoint_desc); |
0 | 2117 |
} |
2118 |
} |
|
2119 |
||
2120 |
||
2121 |
static void Save_ORDR() |
|
2122 |
{ |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
2123 |
uint16 orders[lengthof(_order_array)]; |
0 | 2124 |
uint len = _ptr_to_next_order - _order_array; |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
2125 |
uint i; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
2126 |
|
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
2127 |
assert (len <= lengthof(orders)); |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
2128 |
|
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
2129 |
for (i = 0; i < len; ++i) |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
2130 |
orders[i] = PackOrder(&_order_array[i]); |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
2131 |
|
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
2132 |
SlArray(orders, len, SLE_UINT16); |
0 | 2133 |
} |
2134 |
||
2135 |
static void Load_ORDR() |
|
2136 |
{ |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
2137 |
uint16 orders[lengthof(_order_array)]; |
0 | 2138 |
uint len = SlGetFieldLength() >> 1; |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
2139 |
uint i; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
2140 |
|
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
2141 |
assert (len <= lengthof(orders)); |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
2142 |
|
0 | 2143 |
_ptr_to_next_order = _order_array + len; |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
2144 |
SlArray(orders, len, SLE_UINT16); |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
2145 |
|
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
548
diff
changeset
|
2146 |
for (i = 0; i < len; ++i) |
585
f93cb3611b1f
(svn r1005) Don't treat orders in the normal load routine as old orders, this lead to corruption on load.
tron
parents:
584
diff
changeset
|
2147 |
_order_array[i] = UnpackOrder(orders[i]); |
0 | 2148 |
} |
2149 |
||
2150 |
const ChunkHandler _veh_chunk_handlers[] = { |
|
2151 |
{ 'VEHS', Save_VEHS, Load_VEHS, CH_SPARSE_ARRAY}, |
|
2152 |
{ 'ORDR', Save_ORDR, Load_ORDR, CH_RIFF}, |
|
2153 |
{ 'DEPT', Save_DEPT, Load_DEPT, CH_ARRAY}, |
|
2154 |
{ 'CHKP', Save_CHKP, Load_CHKP, CH_ARRAY | CH_LAST}, |
|
2155 |
}; |
|
2156 |
||
2157 |