OpenTTD Source: src/saveload/vehicle_sl.cpp Source File

OpenTTD Source 1.11.0-RC1

vehicle_sl.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #include "../stdafx.h"
11 #include "../vehicle_func.h"
12 #include "../train.h"
13 #include "../roadveh.h"
14 #include "../ship.h"
15 #include "../aircraft.h"
16 #include "../station_base.h"
17 #include "../effectvehicle_base.h"
18 #include "../company_base.h"
19 #include "../company_func.h"
20 #include "../disaster_vehicle.h"
21
22 #include "saveload.h"
23
24 #include <map>
25
26 #include "../safeguards.h"
27
32 void ConnectMultiheadedTrains()
33 {
34 for (Train *v : Train::Iterate()) {
35 v->other_multiheaded_part = nullptr;
36 }
37
38 for (Train *v : Train::Iterate()) {
39 if (v->IsFrontEngine() || v->IsFreeWagon()) {
40 /* Two ways to associate multiheaded parts to each other:
41 * sequential-matching: Trains shall be arranged to look like <..>..<..>..<..>..
42 * bracket-matching: Free vehicle chains shall be arranged to look like ..<..<..>..<..>..>..
43 *
44 * Note: Old savegames might contain chains which do not comply with these rules, e.g.
45 * - the front and read parts have invalid orders
46 * - different engine types might be combined
47 * - there might be different amounts of front and rear parts.
48 *
49 * Note: The multiheaded parts need to be matched exactly like they are matched on the server, else desyncs will occur.
50 * This is why two matching strategies are needed.
51 */
52
53 bool sequential_matching = v->IsFrontEngine();
54
55 for (Train *u = v; u != nullptr; u = u->GetNextVehicle()) {
56 if (u->other_multiheaded_part != nullptr) continue; // we already linked this one
57
58 if (u->IsMultiheaded()) {
59 if (!u->IsEngine()) {
60 /* we got a rear car without a front car. We will convert it to a front one */
61 u->SetEngine();
62 u->spritenum--;
63 }
64
65 /* Find a matching back part */
66 EngineID eid = u->engine_type;
67 Train *w;
68 if (sequential_matching) {
69 for (w = u->GetNextVehicle(); w != nullptr; w = w->GetNextVehicle()) {
70 if (w->engine_type != eid || w->other_multiheaded_part != nullptr || !w->IsMultiheaded()) continue;
71
72 /* we found a car to partner with this engine. Now we will make sure it face the right way */
73 if (w->IsEngine()) {
74 w->ClearEngine();
75 w->spritenum++;
76 }
77 break;
78 }
79 } else {
80 uint stack_pos = 0;
81 for (w = u->GetNextVehicle(); w != nullptr; w = w->GetNextVehicle()) {
82 if (w->engine_type != eid || w->other_multiheaded_part != nullptr || !w->IsMultiheaded()) continue;
83
84 if (w->IsEngine()) {
85 stack_pos++;
86 } else {
87 if (stack_pos == 0) break;
88 stack_pos--;
89 }
90 }
91 }
92
93 if (w != nullptr) {
94 w->other_multiheaded_part = u;
95 u->other_multiheaded_part = w;
96 } else {
97 /* we got a front car and no rear cars. We will fake this one for forget that it should have been multiheaded */
98 u->ClearMultiheaded();
99 }
100 }
101 }
102 }
103 }
104 }
105
110 void ConvertOldMultiheadToNew()
111 {
112 for (Train *t : Train::Iterate()) SetBit(t->subtype, 7); // indicates that it's the old format and needs to be converted in the next loop
113
114 for (Train *t : Train::Iterate()) {
115 if (HasBit(t->subtype, 7) && ((t->subtype & ~0x80) == 0 || (t->subtype & ~0x80) == 4)) {
116 for (Train *u = t; u != nullptr; u = u->Next()) {
117 const RailVehicleInfo *rvi = RailVehInfo(u->engine_type);
118
119 ClrBit(u->subtype, 7);
120 switch (u->subtype) {
121 case 0: // TS_Front_Engine
122 if (rvi->railveh_type == RAILVEH_MULTIHEAD) u->SetMultiheaded();
123 u->SetFrontEngine();
124 u->SetEngine();
125 break;
126
127 case 1: // TS_Artic_Part
128 u->subtype = 0;
129 u->SetArticulatedPart();
130 break;
131
132 case 2: // TS_Not_First
133 u->subtype = 0;
134 if (rvi->railveh_type == RAILVEH_WAGON) {
135 /* normal wagon */
136 u->SetWagon();
137 break;
138 }
139 if (rvi->railveh_type == RAILVEH_MULTIHEAD && rvi->image_index == u->spritenum - 1) {
140 /* rear end of a multiheaded engine */
141 u->SetMultiheaded();
142 break;
143 }
144 if (rvi->railveh_type == RAILVEH_MULTIHEAD) u->SetMultiheaded();
145 u->SetEngine();
146 break;
147
148 case 4: // TS_Free_Car
149 u->subtype = 0;
150 u->SetWagon();
151 u->SetFreeWagon();
152 break;
153 default: SlErrorCorrupt("Invalid train subtype");
154 }
155 }
156 }
157 }
158 }
159
160
162 void UpdateOldAircraft()
163 {
164 /* set airport_flags to 0 for all airports just to be sure */
165 for (Station *st : Station::Iterate()) {
166 st->airport.flags = 0; // reset airport
167 }
168
169 for (Aircraft *a : Aircraft::Iterate()) {
170 /* airplane has another vehicle with subtype 4 (shadow), helicopter also has 3 (rotor)
171 * skip those */
172 if (a->IsNormalAircraft()) {
173 /* airplane in terminal stopped doesn't hurt anyone, so goto next */
174 if ((a->vehstatus & VS_STOPPED) && a->state == 0) {
175 a->state = HANGAR;
176 continue;
177 }
178
179 AircraftLeaveHangar(a, a->direction); // make airplane visible if it was in a depot for example
180 a->vehstatus &= ~VS_STOPPED; // make airplane moving
181 UpdateAircraftCache(a);
182 a->cur_speed = a->vcache.cached_max_speed; // so aircraft don't have zero speed while in air
183 if (!a->current_order.IsType(OT_GOTO_STATION) && !a->current_order.IsType(OT_GOTO_DEPOT)) {
184 /* reset current order so aircraft doesn't have invalid "station-only" order */
185 a->current_order.MakeDummy();
186 }
187 a->state = FLYING;
188 AircraftNextAirportPos_and_Order(a); // move it to the entry point of the airport
189 GetNewVehiclePosResult gp = GetNewVehiclePos(a);
190 a->tile = 0; // aircraft in air is tile=0
191
192 /* correct speed of helicopter-rotors */
193 if (a->subtype == AIR_HELICOPTER) a->Next()->Next()->cur_speed = 32;
194
195 /* set new position x,y,z */
196 GetAircraftFlightLevelBounds(a, &a->z_pos, nullptr);
197 SetAircraftPosition(a, gp.x, gp.y, GetAircraftFlightLevel(a));
198 }
199 }
200 }
201
209 static void CheckValidVehicles()
210 {
211 size_t total_engines = Engine::GetPoolSize();
212 EngineID first_engine[4] = { INVALID_ENGINE, INVALID_ENGINE, INVALID_ENGINE, INVALID_ENGINE };
213
214 for (const Engine *e : Engine::IterateType(VEH_TRAIN)) { first_engine[VEH_TRAIN] = e->index; break; }
215 for (const Engine *e : Engine::IterateType(VEH_ROAD)) { first_engine[VEH_ROAD] = e->index; break; }
216 for (const Engine *e : Engine::IterateType(VEH_SHIP)) { first_engine[VEH_SHIP] = e->index; break; }
217 for (const Engine *e : Engine::IterateType(VEH_AIRCRAFT)) { first_engine[VEH_AIRCRAFT] = e->index; break; }
218
219 for (Vehicle *v : Vehicle::Iterate()) {
220 /* Test if engine types match */
221 switch (v->type) {
222 case VEH_TRAIN:
223 case VEH_ROAD:
224 case VEH_SHIP:
225 case VEH_AIRCRAFT:
226 if (v->engine_type >= total_engines || v->type != v->GetEngine()->type) {
227 v->engine_type = first_engine[v->type];
228 }
229 break;
230
231 default:
232 break;
233 }
234 }
235 }
236
237 extern byte _age_cargo_skip_counter; // From misc_sl.cpp
238
240 void AfterLoadVehicles(bool part_of_load)
241 {
242 for (Vehicle *v : Vehicle::Iterate()) {
243 /* Reinstate the previous pointer */
244 if (v->Next() != nullptr) v->Next()->previous = v;
245 if (v->NextShared() != nullptr) v->NextShared()->previous_shared = v;
246
247 if (part_of_load) v->fill_percent_te_id = INVALID_TE_ID;
248 v->first = nullptr;
249 if (v->IsGroundVehicle()) v->GetGroundVehicleCache()->first_engine = INVALID_ENGINE;
250 }
251
252 /* AfterLoadVehicles may also be called in case of NewGRF reload, in this
253 * case we may not convert orders again. */
254 if (part_of_load) {
255 /* Create shared vehicle chain for very old games (pre 5,2) and create
256 * OrderList from shared vehicle chains. For this to work correctly, the
257 * following conditions must be fulfilled:
258 * a) both next_shared and previous_shared are not set for pre 5,2 games
259 * b) both next_shared and previous_shared are set for later games
260 */
261 std::map<Order*, OrderList*> mapping;
262
263 for (Vehicle *v : Vehicle::Iterate()) {
264 if (v->orders.old != nullptr) {
265 if (IsSavegameVersionBefore(SLV_105)) { // Pre-105 didn't save an OrderList
266 if (mapping[v->orders.old] == nullptr) {
267 /* This adds the whole shared vehicle chain for case b */
268
269 /* Creating an OrderList here is safe because the number of vehicles
270 * allowed in these savegames matches the number of OrderLists. As
271 * such each vehicle can get an OrderList and it will (still) fit. */
272 assert(OrderList::CanAllocateItem());
273 v->orders.list = mapping[v->orders.old] = new OrderList(v->orders.old, v);
274 } else {
275 v->orders.list = mapping[v->orders.old];
276 /* For old games (case a) we must create the shared vehicle chain */
277 if (IsSavegameVersionBefore(SLV_5, 2)) {
278 v->AddToShared(v->orders.list->GetFirstSharedVehicle());
279 }
280 }
281 } else { // OrderList was saved as such, only recalculate not saved values
282 if (v->PreviousShared() == nullptr) {
283 v->orders.list->Initialize(v->orders.list->first, v);
284 }
285 }
286 }
287 }
288 }
289
290 for (Vehicle *v : Vehicle::Iterate()) {
291 /* Fill the first pointers */
292 if (v->Previous() == nullptr) {
293 for (Vehicle *u = v; u != nullptr; u = u->Next()) {
294 u->first = v;
295 }
296 }
297 }
298
299 if (part_of_load) {
300 if (IsSavegameVersionBefore(SLV_105)) {
301 /* Before 105 there was no order for shared orders, thus it messed up horribly */
302 for (Vehicle *v : Vehicle::Iterate()) {
303 if (v->First() != v || v->orders.list != nullptr || v->previous_shared != nullptr || v->next_shared == nullptr) continue;
304
305 /* As above, allocating OrderList here is safe. */
306 assert(OrderList::CanAllocateItem());
307 v->orders.list = new OrderList(nullptr, v);
308 for (Vehicle *u = v; u != nullptr; u = u->next_shared) {
309 u->orders.list = v->orders.list;
310 }
311 }
312 }
313
314 if (IsSavegameVersionBefore(SLV_157)) {
315 /* The road vehicle subtype was converted to a flag. */
316 for (RoadVehicle *rv : RoadVehicle::Iterate()) {
317 if (rv->subtype == 0) {
318 /* The road vehicle is at the front. */
319 rv->SetFrontEngine();
320 } else if (rv->subtype == 1) {
321 /* The road vehicle is an articulated part. */
322 rv->subtype = 0;
323 rv->SetArticulatedPart();
324 } else {
325 SlErrorCorrupt("Invalid road vehicle subtype");
326 }
327 }
328 }
329
330 if (IsSavegameVersionBefore(SLV_160)) {
331 /* In some old savegames there might be some "crap" stored. */
332 for (Vehicle *v : Vehicle::Iterate()) {
333 if (!v->IsPrimaryVehicle() && v->type != VEH_DISASTER) {
334 v->current_order.Free();
335 v->unitnumber = 0;
336 }
337 }
338 }
339
340 if (IsSavegameVersionBefore(SLV_162)) {
341 /* Set the vehicle-local cargo age counter from the old global counter. */
342 for (Vehicle *v : Vehicle::Iterate()) {
343 v->cargo_age_counter = _age_cargo_skip_counter;
344 }
345 }
346
347 if (IsSavegameVersionBefore(SLV_180)) {
348 /* Set service interval flags */
349 for (Vehicle *v : Vehicle::Iterate()) {
350 if (!v->IsPrimaryVehicle()) continue;
351
352 const Company *c = Company::Get(v->owner);
353 int interval = CompanyServiceInterval(c, v->type);
354
355 v->SetServiceIntervalIsCustom(v->GetServiceInterval() != interval);
356 v->SetServiceIntervalIsPercent(c->settings.vehicle.servint_ispercent);
357 }
358 }
359
360 if (IsSavegameVersionBefore(SLV_SHIP_ROTATION)) {
361 /* Ship rotation added */
362 for (Ship *s : Ship::Iterate()) {
363 s->rotation = s->direction;
364 }
365 } else {
366 for (Ship *s : Ship::Iterate()) {
367 if (s->rotation == s->direction) continue;
368 /* In case we are rotating on gameload, set the rotation position to
369 * the current position, otherwise the applied workaround offset would
370 * be with respect to 0,0.
371 */
372 s->rotation_x_pos = s->x_pos;
373 s->rotation_y_pos = s->y_pos;
374 }
375 }
376 }
377
378 CheckValidVehicles();
379
380 for (Vehicle *v : Vehicle::Iterate()) {
381 assert(v->first != nullptr);
382
383 v->trip_occupancy = CalcPercentVehicleFilled(v, nullptr);
384
385 switch (v->type) {
386 case VEH_TRAIN: {
387 Train *t = Train::From(v);
388 if (t->IsFrontEngine() || t->IsFreeWagon()) {
389 t->gcache.last_speed = t->cur_speed; // update displayed train speed
390 t->ConsistChanged(CCF_SAVELOAD);
391 }
392 break;
393 }
394
395 case VEH_ROAD: {
396 RoadVehicle *rv = RoadVehicle::From(v);
397 if (rv->IsFrontEngine()) {
398 rv->gcache.last_speed = rv->cur_speed; // update displayed road vehicle speed
399
400 rv->roadtype = Engine::Get(rv->engine_type)->u.road.roadtype;
401 rv->compatible_roadtypes = GetRoadTypeInfo(rv->roadtype)->powered_roadtypes;
402 for (RoadVehicle *u = rv; u != nullptr; u = u->Next()) {
403 u->roadtype = rv->roadtype;
404 u->compatible_roadtypes = rv->compatible_roadtypes;
405 }
406
407 RoadVehUpdateCache(rv);
408 if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) {
409 rv->CargoChanged();
410 }
411 }
412 break;
413 }
414
415 case VEH_SHIP:
416 Ship::From(v)->UpdateCache();
417 break;
418
419 default: break;
420 }
421 }
422
423 /* Stop non-front engines */
424 if (part_of_load && IsSavegameVersionBefore(SLV_112)) {
425 for (Vehicle *v : Vehicle::Iterate()) {
426 if (v->type == VEH_TRAIN) {
427 Train *t = Train::From(v);
428 if (!t->IsFrontEngine()) {
429 if (t->IsEngine()) t->vehstatus |= VS_STOPPED;
430 /* cur_speed is now relevant for non-front parts - nonzero breaks
431 * moving-wagons-inside-depot- and autoreplace- code */
432 t->cur_speed = 0;
433 }
434 }
435 /* trains weren't stopping gradually in old OTTD versions (and TTO/TTD)
436 * other vehicle types didn't have zero speed while stopped (even in 'recent' OTTD versions) */
437 if ((v->vehstatus & VS_STOPPED) && (v->type != VEH_TRAIN || IsSavegameVersionBefore(SLV_2, 1))) {
438 v->cur_speed = 0;
439 }
440 }
441 }
442
443 for (Vehicle *v : Vehicle::Iterate()) {
444 switch (v->type) {
445 case VEH_ROAD:
446 case VEH_TRAIN:
447 case VEH_SHIP:
448 v->GetImage(v->direction, EIT_ON_MAP, &v->sprite_cache.sprite_seq);
449 break;
450
451 case VEH_AIRCRAFT:
452 if (Aircraft::From(v)->IsNormalAircraft()) {
453 v->GetImage(v->direction, EIT_ON_MAP, &v->sprite_cache.sprite_seq);
454
455 /* The plane's shadow will have the same image as the plane, but no colour */
456 Vehicle *shadow = v->Next();
457 shadow->sprite_cache.sprite_seq.CopyWithoutPalette(v->sprite_cache.sprite_seq);
458
459 /* In the case of a helicopter we will update the rotor sprites */
460 if (v->subtype == AIR_HELICOPTER) {
461 Vehicle *rotor = shadow->Next();
462 GetRotorImage(Aircraft::From(v), EIT_ON_MAP, &rotor->sprite_cache.sprite_seq);
463 }
464
465 UpdateAircraftCache(Aircraft::From(v), true);
466 }
467 break;
468 default: break;
469 }
470
471 v->UpdateDeltaXY();
472 v->coord.left = INVALID_COORD;
473 v->sprite_cache.old_coord.left = INVALID_COORD;
474 v->UpdatePosition();
475 v->UpdateViewport(false);
476 }
477 }
478
479 bool TrainController(Train *v, Vehicle *nomove, bool reverse = true); // From train_cmd.cpp
480 void ReverseTrainDirection(Train *v);
481 void ReverseTrainSwapVeh(Train *v, int l, int r);
482
484 void FixupTrainLengths()
485 {
486 /* Vehicle center was moved from 4 units behind the front to half the length
487 * behind the front. Move vehicles so they end up on the same spot. */
488 for (Vehicle *v : Vehicle::Iterate()) {
489 if (v->type == VEH_TRAIN && v->IsPrimaryVehicle()) {
490 /* The vehicle center is now more to the front depending on vehicle length,
491 * so we need to move all vehicles forward to cover the difference to the
492 * old center, otherwise wagon spacing in trains would be broken upon load. */
493 for (Train *u = Train::From(v); u != nullptr; u = u->Next()) {
494 if (u->track == TRACK_BIT_DEPOT || (u->vehstatus & VS_CRASHED)) continue;
495
496 Train *next = u->Next();
497
498 /* Try to pull the vehicle half its length forward. */
499 int diff = (VEHICLE_LENGTH - u->gcache.cached_veh_length) / 2;
500 int done;
501 for (done = 0; done < diff; done++) {
502 if (!TrainController(u, next, false)) break;
503 }
504
505 if (next != nullptr && done < diff && u->IsFrontEngine()) {
506 /* Pulling the front vehicle forwards failed, we either encountered a dead-end
507 * or a red signal. To fix this, we try to move the whole train the required
508 * space backwards and re-do the fix up of the front vehicle. */
509
510 /* Ignore any signals when backtracking. */
511 TrainForceProceeding old_tfp = u->force_proceed;
512 u->force_proceed = TFP_SIGNAL;
513
514 /* Swap start<>end, start+1<>end-1, ... */
515 int r = CountVehiclesInChain(u) - 1; // number of vehicles - 1
516 int l = 0;
517 do ReverseTrainSwapVeh(u, l++, r--); while (l <= r);
518
519 /* We moved the first vehicle which is now the last. Move it back to the
520 * original position as we will fix up the last vehicle later in the loop. */
521 for (int i = 0; i < done; i++) TrainController(u->Last(), nullptr);
522
523 /* Move the train backwards to get space for the first vehicle. As the stopping
524 * distance from a line end is rounded up, move the train one unit more to cater
525 * for front vehicles with odd lengths. */
526 int moved;
527 for (moved = 0; moved < diff + 1; moved++) {
528 if (!TrainController(u, nullptr, false)) break;
529 }
530
531 /* Swap start<>end, start+1<>end-1, ... again. */
532 r = CountVehiclesInChain(u) - 1; // number of vehicles - 1
533 l = 0;
534 do ReverseTrainSwapVeh(u, l++, r--); while (l <= r);
535
536 u->force_proceed = old_tfp;
537
538 /* Tracks are too short to fix the train length. The player has to fix the
539 * train in a depot. Bail out so we don't damage the vehicle chain any more. */
540 if (moved < diff + 1) break;
541
542 /* Re-do the correction for the first vehicle. */
543 for (done = 0; done < diff; done++) TrainController(u, next, false);
544
545 /* We moved one unit more backwards than needed for even-length front vehicles,
546 * try to move that unit forward again. We don't care if this step fails. */
547 TrainController(u, nullptr, false);
548 }
549
550 /* If the next wagon is still in a depot, check if it shouldn't be outside already. */
551 if (next != nullptr && next->track == TRACK_BIT_DEPOT) {
552 int d = TicksToLeaveDepot(u);
553 if (d <= 0) {
554 /* Next vehicle should have left the depot already, show it and pull forward. */
555 next->vehstatus &= ~VS_HIDDEN;
556 next->track = TrackToTrackBits(GetRailDepotTrack(next->tile));
557 for (int i = 0; i >= d; i--) TrainController(next, nullptr);
558 }
559 }
560 }
561
562 /* Update all cached properties after moving the vehicle chain around. */
563 Train::From(v)->ConsistChanged(CCF_TRACK);
564 }
565 }
566 }
567
568 static uint8 _cargo_days;
569 static uint16 _cargo_source;
570 static uint32 _cargo_source_xy;
571 static uint16 _cargo_count;
572 static uint16 _cargo_paid_for;
573 static Money _cargo_feeder_share;
574 static uint32 _cargo_loaded_at_xy;
575
581 const SaveLoad *GetVehicleDescription(VehicleType vt)
582 {
584 static const SaveLoad _common_veh_desc[] = {
585 SLE_VAR(Vehicle, subtype, SLE_UINT8),
586
587 SLE_REF(Vehicle, next, REF_VEHICLE_OLD),
588 SLE_CONDVAR(Vehicle, name, SLE_NAME, SL_MIN_VERSION, SLV_84),
589 SLE_CONDSSTR(Vehicle, name, SLE_STR | SLF_ALLOW_CONTROL, SLV_84, SL_MAX_VERSION),
590 SLE_CONDVAR(Vehicle, unitnumber, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_8),
591 SLE_CONDVAR(Vehicle, unitnumber, SLE_UINT16, SLV_8, SL_MAX_VERSION),
592 SLE_VAR(Vehicle, owner, SLE_UINT8),
593 SLE_CONDVAR(Vehicle, tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
594 SLE_CONDVAR(Vehicle, tile, SLE_UINT32, SLV_6, SL_MAX_VERSION),
595 SLE_CONDVAR(Vehicle, dest_tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
596 SLE_CONDVAR(Vehicle, dest_tile, SLE_UINT32, SLV_6, SL_MAX_VERSION),
597
598 SLE_CONDVAR(Vehicle, x_pos, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
599 SLE_CONDVAR(Vehicle, x_pos, SLE_UINT32, SLV_6, SL_MAX_VERSION),
600 SLE_CONDVAR(Vehicle, y_pos, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
601 SLE_CONDVAR(Vehicle, y_pos, SLE_UINT32, SLV_6, SL_MAX_VERSION),
602 SLE_CONDVAR(Vehicle, z_pos, SLE_FILE_U8 | SLE_VAR_I32, SL_MIN_VERSION, SLV_164),
603 SLE_CONDVAR(Vehicle, z_pos, SLE_INT32, SLV_164, SL_MAX_VERSION),
604 SLE_VAR(Vehicle, direction, SLE_UINT8),
605
606 SLE_CONDNULL(2, SL_MIN_VERSION, SLV_58),
607 SLE_VAR(Vehicle, spritenum, SLE_UINT8),
608 SLE_CONDNULL(5, SL_MIN_VERSION, SLV_58),
609 SLE_VAR(Vehicle, engine_type, SLE_UINT16),
610
611 SLE_CONDNULL(2, SL_MIN_VERSION, SLV_152),
612 SLE_VAR(Vehicle, cur_speed, SLE_UINT16),
613 SLE_VAR(Vehicle, subspeed, SLE_UINT8),
614 SLE_VAR(Vehicle, acceleration, SLE_UINT8),
615 SLE_CONDVAR(Vehicle, motion_counter, SLE_UINT32, SLV_VEH_MOTION_COUNTER, SL_MAX_VERSION),
616 SLE_VAR(Vehicle, progress, SLE_UINT8),
617
618 SLE_VAR(Vehicle, vehstatus, SLE_UINT8),
619 SLE_CONDVAR(Vehicle, last_station_visited, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_5),
620 SLE_CONDVAR(Vehicle, last_station_visited, SLE_UINT16, SLV_5, SL_MAX_VERSION),
621 SLE_CONDVAR(Vehicle, last_loading_station, SLE_UINT16, SLV_182, SL_MAX_VERSION),
622
623 SLE_VAR(Vehicle, cargo_type, SLE_UINT8),
624 SLE_CONDVAR(Vehicle, cargo_subtype, SLE_UINT8, SLV_35, SL_MAX_VERSION),
625 SLEG_CONDVAR( _cargo_days, SLE_UINT8, SL_MIN_VERSION, SLV_68),
626 SLEG_CONDVAR( _cargo_source, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_7),
627 SLEG_CONDVAR( _cargo_source, SLE_UINT16, SLV_7, SLV_68),
628 SLEG_CONDVAR( _cargo_source_xy, SLE_UINT32, SLV_44, SLV_68),
629 SLE_VAR(Vehicle, cargo_cap, SLE_UINT16),
630 SLE_CONDVAR(Vehicle, refit_cap, SLE_UINT16, SLV_182, SL_MAX_VERSION),
631 SLEG_CONDVAR( _cargo_count, SLE_UINT16, SL_MIN_VERSION, SLV_68),
632 SLE_CONDLST(Vehicle, cargo.packets, REF_CARGO_PACKET, SLV_68, SL_MAX_VERSION),
633 SLE_CONDARR(Vehicle, cargo.action_counts, SLE_UINT, VehicleCargoList::NUM_MOVE_TO_ACTION, SLV_181, SL_MAX_VERSION),
634 SLE_CONDVAR(Vehicle, cargo_age_counter, SLE_UINT16, SLV_162, SL_MAX_VERSION),
635
636 SLE_VAR(Vehicle, day_counter, SLE_UINT8),
637 SLE_VAR(Vehicle, tick_counter, SLE_UINT8),
638 SLE_CONDVAR(Vehicle, running_ticks, SLE_UINT8, SLV_88, SL_MAX_VERSION),
639
640 SLE_VAR(Vehicle, cur_implicit_order_index, SLE_UINT8),
641 SLE_CONDVAR(Vehicle, cur_real_order_index, SLE_UINT8, SLV_158, SL_MAX_VERSION),
642 /* num_orders is now part of OrderList and is not saved but counted */
643 SLE_CONDNULL(1, SL_MIN_VERSION, SLV_105),
644
645 /* This next line is for version 4 and prior compatibility.. it temporarily reads
646 type and flags (which were both 4 bits) into type. Later on this is
647 converted correctly */
648 SLE_CONDVAR(Vehicle, current_order.type, SLE_UINT8, SL_MIN_VERSION, SLV_5),
649 SLE_CONDVAR(Vehicle, current_order.dest, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_5),
650
651 /* Orders for version 5 and on */
652 SLE_CONDVAR(Vehicle, current_order.type, SLE_UINT8, SLV_5, SL_MAX_VERSION),
653 SLE_CONDVAR(Vehicle, current_order.flags, SLE_UINT8, SLV_5, SL_MAX_VERSION),
654 SLE_CONDVAR(Vehicle, current_order.dest, SLE_UINT16, SLV_5, SL_MAX_VERSION),
655
656 /* Refit in current order */
657 SLE_CONDVAR(Vehicle, current_order.refit_cargo, SLE_UINT8, SLV_36, SL_MAX_VERSION),
658 SLE_CONDNULL(1, SLV_36, SLV_182), // refit_subtype
659
660 /* Timetable in current order */
661 SLE_CONDVAR(Vehicle, current_order.wait_time, SLE_UINT16, SLV_67, SL_MAX_VERSION),
662 SLE_CONDVAR(Vehicle, current_order.travel_time, SLE_UINT16, SLV_67, SL_MAX_VERSION),
663 SLE_CONDVAR(Vehicle, current_order.max_speed, SLE_UINT16, SLV_174, SL_MAX_VERSION),
664 SLE_CONDVAR(Vehicle, timetable_start, SLE_INT32, SLV_129, SL_MAX_VERSION),
665
666 SLE_CONDREF(Vehicle, orders, REF_ORDER, SL_MIN_VERSION, SLV_105),
667 SLE_CONDREF(Vehicle, orders, REF_ORDERLIST, SLV_105, SL_MAX_VERSION),
668
669 SLE_CONDVAR(Vehicle, age, SLE_FILE_U16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_31),
670 SLE_CONDVAR(Vehicle, age, SLE_INT32, SLV_31, SL_MAX_VERSION),
671 SLE_CONDVAR(Vehicle, max_age, SLE_FILE_U16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_31),
672 SLE_CONDVAR(Vehicle, max_age, SLE_INT32, SLV_31, SL_MAX_VERSION),
673 SLE_CONDVAR(Vehicle, date_of_last_service, SLE_FILE_U16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_31),
674 SLE_CONDVAR(Vehicle, date_of_last_service, SLE_INT32, SLV_31, SL_MAX_VERSION),
675 SLE_CONDVAR(Vehicle, service_interval, SLE_UINT16, SL_MIN_VERSION, SLV_31),
676 SLE_CONDVAR(Vehicle, service_interval, SLE_FILE_U32 | SLE_VAR_U16, SLV_31, SLV_180),
677 SLE_CONDVAR(Vehicle, service_interval, SLE_UINT16, SLV_180, SL_MAX_VERSION),
678 SLE_VAR(Vehicle, reliability, SLE_UINT16),
679 SLE_VAR(Vehicle, reliability_spd_dec, SLE_UINT16),
680 SLE_VAR(Vehicle, breakdown_ctr, SLE_UINT8),
681 SLE_VAR(Vehicle, breakdown_delay, SLE_UINT8),
682 SLE_VAR(Vehicle, breakdowns_since_last_service, SLE_UINT8),
683 SLE_VAR(Vehicle, breakdown_chance, SLE_UINT8),
684 SLE_CONDVAR(Vehicle, build_year, SLE_FILE_U8 | SLE_VAR_I32, SL_MIN_VERSION, SLV_31),
685 SLE_CONDVAR(Vehicle, build_year, SLE_INT32, SLV_31, SL_MAX_VERSION),
686
687 SLE_VAR(Vehicle, load_unload_ticks, SLE_UINT16),
688 SLEG_CONDVAR( _cargo_paid_for, SLE_UINT16, SLV_45, SL_MAX_VERSION),
689 SLE_CONDVAR(Vehicle, vehicle_flags, SLE_FILE_U8 | SLE_VAR_U16, SLV_40, SLV_180),
690 SLE_CONDVAR(Vehicle, vehicle_flags, SLE_UINT16, SLV_180, SL_MAX_VERSION),
691
692 SLE_CONDVAR(Vehicle, profit_this_year, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_65),
693 SLE_CONDVAR(Vehicle, profit_this_year, SLE_INT64, SLV_65, SL_MAX_VERSION),
694 SLE_CONDVAR(Vehicle, profit_last_year, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_65),
695 SLE_CONDVAR(Vehicle, profit_last_year, SLE_INT64, SLV_65, SL_MAX_VERSION),
696 SLEG_CONDVAR( _cargo_feeder_share, SLE_FILE_I32 | SLE_VAR_I64, SLV_51, SLV_65),
697 SLEG_CONDVAR( _cargo_feeder_share, SLE_INT64, SLV_65, SLV_68),
698 SLEG_CONDVAR( _cargo_loaded_at_xy, SLE_UINT32, SLV_51, SLV_68),
699 SLE_CONDVAR(Vehicle, value, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_65),
700 SLE_CONDVAR(Vehicle, value, SLE_INT64, SLV_65, SL_MAX_VERSION),
701
702 SLE_CONDVAR(Vehicle, random_bits, SLE_UINT8, SLV_2, SL_MAX_VERSION),
703 SLE_CONDVAR(Vehicle, waiting_triggers, SLE_UINT8, SLV_2, SL_MAX_VERSION),
704
705 SLE_CONDREF(Vehicle, next_shared, REF_VEHICLE, SLV_2, SL_MAX_VERSION),
706 SLE_CONDNULL(2, SLV_2, SLV_69),
707 SLE_CONDNULL(4, SLV_69, SLV_101),
708
709 SLE_CONDVAR(Vehicle, group_id, SLE_UINT16, SLV_60, SL_MAX_VERSION),
710
711 SLE_CONDVAR(Vehicle, current_order_time, SLE_UINT32, SLV_67, SL_MAX_VERSION),
712 SLE_CONDVAR(Vehicle, lateness_counter, SLE_INT32, SLV_67, SL_MAX_VERSION),
713
714 SLE_CONDNULL(10, SLV_2, SLV_144), // old reserved space
715
716 SLE_END()
717 };
718
719
720 static const SaveLoad _train_desc[] = {
721 SLE_WRITEBYTE(Vehicle, type),
722 SLE_VEH_INCLUDE(),
723 SLE_VAR(Train, crash_anim_pos, SLE_UINT16),
724 SLE_VAR(Train, force_proceed, SLE_UINT8),
725 SLE_VAR(Train, railtype, SLE_UINT8),
726 SLE_VAR(Train, track, SLE_UINT8),
727
728 SLE_CONDVAR(Train, flags, SLE_FILE_U8 | SLE_VAR_U16, SLV_2, SLV_100),
729 SLE_CONDVAR(Train, flags, SLE_UINT16, SLV_100, SL_MAX_VERSION),
730 SLE_CONDNULL(2, SLV_2, SLV_60),
731
732 SLE_CONDVAR(Train, wait_counter, SLE_UINT16, SLV_136, SL_MAX_VERSION),
733
734 SLE_CONDNULL(2, SLV_2, SLV_20),
735 SLE_CONDVAR(Train, gv_flags, SLE_UINT16, SLV_139, SL_MAX_VERSION),
736 SLE_CONDNULL(11, SLV_2, SLV_144), // old reserved space
737
738 SLE_END()
739 };
740
741 static const SaveLoad _roadveh_desc[] = {
742 SLE_WRITEBYTE(Vehicle, type),
743 SLE_VEH_INCLUDE(),
744 SLE_VAR(RoadVehicle, state, SLE_UINT8),
745 SLE_VAR(RoadVehicle, frame, SLE_UINT8),
746 SLE_VAR(RoadVehicle, blocked_ctr, SLE_UINT16),
747 SLE_VAR(RoadVehicle, overtaking, SLE_UINT8),
748 SLE_VAR(RoadVehicle, overtaking_ctr, SLE_UINT8),
749 SLE_VAR(RoadVehicle, crashed_ctr, SLE_UINT16),
750 SLE_VAR(RoadVehicle, reverse_ctr, SLE_UINT8),
751 SLE_CONDDEQUE(RoadVehicle, path.td, SLE_UINT8, SLV_ROADVEH_PATH_CACHE, SL_MAX_VERSION),
752 SLE_CONDDEQUE(RoadVehicle, path.tile, SLE_UINT32, SLV_ROADVEH_PATH_CACHE, SL_MAX_VERSION),
753
754 SLE_CONDNULL(2, SLV_6, SLV_69),
755 SLE_CONDVAR(RoadVehicle, gv_flags, SLE_UINT16, SLV_139, SL_MAX_VERSION),
756 SLE_CONDNULL(4, SLV_69, SLV_131),
757 SLE_CONDNULL(2, SLV_6, SLV_131),
758 SLE_CONDNULL(16, SLV_2, SLV_144), // old reserved space
759
760 SLE_END()
761 };
762
763 static const SaveLoad _ship_desc[] = {
764 SLE_WRITEBYTE(Vehicle, type),
765 SLE_VEH_INCLUDE(),
766 SLE_VAR(Ship, state, SLE_UINT8),
767 SLE_CONDDEQUE(Ship, path, SLE_UINT8, SLV_SHIP_PATH_CACHE, SL_MAX_VERSION),
768 SLE_CONDVAR(Ship, rotation, SLE_UINT8, SLV_SHIP_ROTATION, SL_MAX_VERSION),
769
770 SLE_CONDNULL(16, SLV_2, SLV_144), // old reserved space
771
772 SLE_END()
773 };
774
775 static const SaveLoad _aircraft_desc[] = {
776 SLE_WRITEBYTE(Vehicle, type),
777 SLE_VEH_INCLUDE(),
778 SLE_VAR(Aircraft, crashed_counter, SLE_UINT16),
779 SLE_VAR(Aircraft, pos, SLE_UINT8),
780
781 SLE_CONDVAR(Aircraft, targetairport, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_5),
782 SLE_CONDVAR(Aircraft, targetairport, SLE_UINT16, SLV_5, SL_MAX_VERSION),
783
784 SLE_VAR(Aircraft, state, SLE_UINT8),
785
786 SLE_CONDVAR(Aircraft, previous_pos, SLE_UINT8, SLV_2, SL_MAX_VERSION),
787 SLE_CONDVAR(Aircraft, last_direction, SLE_UINT8, SLV_2, SL_MAX_VERSION),
788 SLE_CONDVAR(Aircraft, number_consecutive_turns, SLE_UINT8, SLV_2, SL_MAX_VERSION),
789
790 SLE_CONDVAR(Aircraft, turn_counter, SLE_UINT8, SLV_136, SL_MAX_VERSION),
791 SLE_CONDVAR(Aircraft, flags, SLE_UINT8, SLV_167, SL_MAX_VERSION),
792
793 SLE_CONDNULL(13, SLV_2, SLV_144), // old reserved space
794
795 SLE_END()
796 };
797
798 static const SaveLoad _special_desc[] = {
799 SLE_WRITEBYTE(Vehicle, type),
800
801 SLE_VAR(Vehicle, subtype, SLE_UINT8),
802
803 SLE_CONDVAR(Vehicle, tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
804 SLE_CONDVAR(Vehicle, tile, SLE_UINT32, SLV_6, SL_MAX_VERSION),
805
806 SLE_CONDVAR(Vehicle, x_pos, SLE_FILE_I16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_6),
807 SLE_CONDVAR(Vehicle, x_pos, SLE_INT32, SLV_6, SL_MAX_VERSION),
808 SLE_CONDVAR(Vehicle, y_pos, SLE_FILE_I16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_6),
809 SLE_CONDVAR(Vehicle, y_pos, SLE_INT32, SLV_6, SL_MAX_VERSION),
810 SLE_CONDVAR(Vehicle, z_pos, SLE_FILE_U8 | SLE_VAR_I32, SL_MIN_VERSION, SLV_164),
811 SLE_CONDVAR(Vehicle, z_pos, SLE_INT32, SLV_164, SL_MAX_VERSION),
812
813 SLE_VAR(Vehicle, sprite_cache.sprite_seq.seq[0].sprite, SLE_FILE_U16 | SLE_VAR_U32),
814 SLE_CONDNULL(5, SL_MIN_VERSION, SLV_59),
815 SLE_VAR(Vehicle, progress, SLE_UINT8),
816 SLE_VAR(Vehicle, vehstatus, SLE_UINT8),
817
818 SLE_VAR(EffectVehicle, animation_state, SLE_UINT16),
819 SLE_VAR(EffectVehicle, animation_substate, SLE_UINT8),
820
821 SLE_CONDVAR(Vehicle, spritenum, SLE_UINT8, SLV_2, SL_MAX_VERSION),
822
823 SLE_CONDNULL(15, SLV_2, SLV_144), // old reserved space
824
825 SLE_END()
826 };
827
828 static const SaveLoad _disaster_desc[] = {
829 SLE_WRITEBYTE(Vehicle, type),
830
831 SLE_REF(Vehicle, next, REF_VEHICLE_OLD),
832
833 SLE_VAR(Vehicle, subtype, SLE_UINT8),
834 SLE_CONDVAR(Vehicle, tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
835 SLE_CONDVAR(Vehicle, tile, SLE_UINT32, SLV_6, SL_MAX_VERSION),
836 SLE_CONDVAR(Vehicle, dest_tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
837 SLE_CONDVAR(Vehicle, dest_tile, SLE_UINT32, SLV_6, SL_MAX_VERSION),
838
839 SLE_CONDVAR(Vehicle, x_pos, SLE_FILE_I16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_6),
840 SLE_CONDVAR(Vehicle, x_pos, SLE_INT32, SLV_6, SL_MAX_VERSION),
841 SLE_CONDVAR(Vehicle, y_pos, SLE_FILE_I16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_6),
842 SLE_CONDVAR(Vehicle, y_pos, SLE_INT32, SLV_6, SL_MAX_VERSION),
843 SLE_CONDVAR(Vehicle, z_pos, SLE_FILE_U8 | SLE_VAR_I32, SL_MIN_VERSION, SLV_164),
844 SLE_CONDVAR(Vehicle, z_pos, SLE_INT32, SLV_164, SL_MAX_VERSION),
845 SLE_VAR(Vehicle, direction, SLE_UINT8),
846
847 SLE_CONDNULL(5, SL_MIN_VERSION, SLV_58),
848 SLE_VAR(Vehicle, owner, SLE_UINT8),
849 SLE_VAR(Vehicle, vehstatus, SLE_UINT8),
850 SLE_CONDVAR(Vehicle, current_order.dest, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_5),
851 SLE_CONDVAR(Vehicle, current_order.dest, SLE_UINT16, SLV_5, SL_MAX_VERSION),
852
853 SLE_VAR(Vehicle, sprite_cache.sprite_seq.seq[0].sprite, SLE_FILE_U16 | SLE_VAR_U32),
854 SLE_CONDVAR(Vehicle, age, SLE_FILE_U16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_31),
855 SLE_CONDVAR(Vehicle, age, SLE_INT32, SLV_31, SL_MAX_VERSION),
856 SLE_VAR(Vehicle, tick_counter, SLE_UINT8),
857
858 SLE_CONDVAR(DisasterVehicle, image_override, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_191),
859 SLE_CONDVAR(DisasterVehicle, image_override, SLE_UINT32, SLV_191, SL_MAX_VERSION),
860 SLE_CONDVAR(DisasterVehicle, big_ufo_destroyer_target, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_191),
861 SLE_CONDVAR(DisasterVehicle, big_ufo_destroyer_target, SLE_UINT32, SLV_191, SL_MAX_VERSION),
862 SLE_CONDVAR(DisasterVehicle, flags, SLE_UINT8, SLV_194, SL_MAX_VERSION),
863
864 SLE_CONDNULL(16, SLV_2, SLV_144), // old reserved space
865
866 SLE_END()
867 };
868
869
870 static const SaveLoad * const _veh_descs[] = {
871 _train_desc,
872 _roadveh_desc,
873 _ship_desc,
874 _aircraft_desc,
875 _special_desc,
876 _disaster_desc,
877 _common_veh_desc,
878 };
879
880 return _veh_descs[vt];
881 }
882
884 static void Save_VEHS()
885 {
886 /* Write the vehicles */
887 for (Vehicle *v : Vehicle::Iterate()) {
888 SlSetArrayIndex(v->index);
889 SlObject(v, GetVehicleDescription(v->type));
890 }
891 }
892
894 void Load_VEHS()
895 {
896 int index;
897
898 _cargo_count = 0;
899
900 while ((index = SlIterateArray()) != -1) {
901 Vehicle *v;
902 VehicleType vtype = (VehicleType)SlReadByte();
903
904 switch (vtype) {
905 case VEH_TRAIN: v = new (index) Train(); break;
906 case VEH_ROAD: v = new (index) RoadVehicle(); break;
907 case VEH_SHIP: v = new (index) Ship(); break;
908 case VEH_AIRCRAFT: v = new (index) Aircraft(); break;
909 case VEH_EFFECT: v = new (index) EffectVehicle(); break;
910 case VEH_DISASTER: v = new (index) DisasterVehicle(); break;
911 case VEH_INVALID: // Savegame shouldn't contain invalid vehicles
912 default: SlErrorCorrupt("Invalid vehicle type");
913 }
914
915 SlObject(v, GetVehicleDescription(vtype));
916
917 if (_cargo_count != 0 && IsCompanyBuildableVehicleType(v) && CargoPacket::CanAllocateItem()) {
918 /* Don't construct the packet with station here, because that'll fail with old savegames */
919 CargoPacket *cp = new CargoPacket(_cargo_count, _cargo_days, _cargo_source, _cargo_source_xy, _cargo_loaded_at_xy, _cargo_feeder_share);
920 v->cargo.Append(cp);
921 }
922
923 /* Old savegames used 'last_station_visited = 0xFF' */
924 if (IsSavegameVersionBefore(SLV_5) && v->last_station_visited == 0xFF) {
925 v->last_station_visited = INVALID_STATION;
926 }
927
928 if (IsSavegameVersionBefore(SLV_182)) v->last_loading_station = INVALID_STATION;
929
930 if (IsSavegameVersionBefore(SLV_5)) {
931 /* Convert the current_order.type (which is a mix of type and flags, because
932 * in those versions, they both were 4 bits big) to type and flags */
933 v->current_order.flags = GB(v->current_order.type, 4, 4);
934 v->current_order.type &= 0x0F;
935 }
936
937 /* Advanced vehicle lists got added */
938 if (IsSavegameVersionBefore(SLV_60)) v->group_id = DEFAULT_GROUP;
939 }
940 }
941
942 static void Ptrs_VEHS()
943 {
944 for (Vehicle *v : Vehicle::Iterate()) {
945 SlObject(v, GetVehicleDescription(v->type));
946 }
947 }
948
949 extern const ChunkHandler _veh_chunk_handlers[] = {
950 { 'VEHS', Save_VEHS, Load_VEHS, Ptrs_VEHS, nullptr, CH_SPARSE_ARRAY | CH_LAST},
951 };
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
SpecializedVehicle::GetNextVehicle
T * GetNextVehicle() const
Get the next real (non-articulated part) vehicle in the consist.
Definition: vehicle_base.h:1121
SLV_131
@ SLV_131
131 18481
Definition: saveload.h:200
RoadVehicle
Buses, trucks and trams belong to this class.
Definition: roadveh.h:107
SLV_65
@ SLV_65
65 10210
Definition: saveload.h:121
INVALID_ENGINE
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
Definition: engine_type.h:174
IsCompanyBuildableVehicleType
static bool IsCompanyBuildableVehicleType(VehicleType type)
Is the given vehicle type buildable by a company?
Definition: vehicle_func.h:89
SLV_69
@ SLV_69
69 10319
Definition: saveload.h:125
REF_ORDER
@ REF_ORDER
Load/save a reference to an order.
Definition: saveload.h:390
SLV_144
@ SLV_144
144 20334
Definition: saveload.h:215
ConnectMultiheadedTrains
void ConnectMultiheadedTrains()
Link front and rear multiheaded engines to each other This is done when loading a savegame.
Definition: vehicle_sl.cpp:32
AircraftNextAirportPos_and_Order
void AircraftNextAirportPos_and_Order(Aircraft *v)
set the right pos when heading to other airports after takeoff
Definition: aircraft_cmd.cpp:1431
Engine::IterateType
static Pool::IterateWrapperFiltered< Engine, EngineTypeFilter > IterateType(VehicleType vt, size_t from=0)
Returns an iterable ensemble of all valid engines of the given type.
Definition: engine_base.h:157
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:329
MutableSpriteCache::sprite_seq
VehicleSpriteSeq sprite_seq
Vehicle appearance.
Definition: vehicle_base.h:193
VehicleSpriteSeq::CopyWithoutPalette
void CopyWithoutPalette(const VehicleSpriteSeq &src)
Copy data from another sprite sequence, while dropping all recolouring information.
Definition: vehicle_base.h:171
GB
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
SLV_162
@ SLV_162
162 22713
Definition: saveload.h:237
SL_MIN_VERSION
@ SL_MIN_VERSION
First savegame version.
Definition: saveload.h:31
FixupTrainLengths
void FixupTrainLengths()
Fixup old train spacing.
Definition: vehicle_sl.cpp:484
SLV_40
@ SLV_40
40 7326
Definition: saveload.h:91
Vehicle::Next
Vehicle * Next() const
Get the next vehicle of this vehicle.
Definition: vehicle_base.h:592
SpecializedVehicle::Next
T * Next() const
Get next vehicle in the chain.
Definition: vehicle_base.h:1077
SLE_CONDSSTR
#define SLE_CONDSSTR(base, variable, type, from, to)
Storage of a std::string in some savegame versions.
Definition: saveload.h:593
Station
Station data structure.
Definition: station_base.h:450
SLE_CONDLST
#define SLE_CONDLST(base, variable, type, from, to)
Storage of a list in some savegame versions.
Definition: saveload.h:603
SLV_112
@ SLV_112
112 15290
Definition: saveload.h:177
SLE_CONDARR
#define SLE_CONDARR(base, variable, type, length, from, to)
Storage of an array in some savegame versions.
Definition: saveload.h:572
Vehicle::vehstatus
byte vehstatus
Status.
Definition: vehicle_base.h:326
SLE_CONDVAR
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Definition: saveload.h:551
SLV_84
@ SLV_84
84 11822
Definition: saveload.h:143
_age_cargo_skip_counter
byte _age_cargo_skip_counter
Skip aging of cargo? Used before savegame version 162.
Definition: misc_sl.cpp:69
Vehicle::group_id
GroupID group_id
Index of group Pool array.
Definition: vehicle_base.h:335
SLE_STR
#define SLE_STR(base, variable, type, length)
Storage of a string in every savegame version.
Definition: saveload.h:647
SLV_157
@ SLV_157
157 21862
Definition: saveload.h:231
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
ClrBit
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
Definition: bitmath_func.hpp:151
CompanySettings::vehicle
VehicleDefaultSettings vehicle
default settings for vehicles
Definition: settings_type.h:554
SLV_20
@ SLV_20
20 3403
Definition: saveload.h:67
CH_LAST
@ CH_LAST
Last chunk in this array.
Definition: saveload.h:410
SLV_88
@ SLV_88
88 12134
Definition: saveload.h:148
saveload.h
SLV_35
@ SLV_35
35 6602
Definition: saveload.h:85
AircraftLeaveHangar
void AircraftLeaveHangar(Aircraft *v, Direction exit_dir)
Aircraft is about to leave the hangar.
Definition: aircraft_cmd.cpp:1451
GroundVehicleCache::last_speed
uint16 last_speed
The last speed we did display, so we only have to redraw when this changes.
Definition: ground_vehicle.hpp:47
ReverseTrainSwapVeh
void ReverseTrainSwapVeh(Train *v, int l, int r)
Swap vehicles l and r in consist v, and reverse their direction.
Definition: train_cmd.cpp:1589
RoadVehicle::roadtype
RoadType roadtype
Roadtype of this vehicle.
Definition: roadveh.h:117
Engine
Definition: engine_base.h:21
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
Vehicle::cur_speed
uint16 cur_speed
current speed
Definition: vehicle_base.h:302
ChunkHandler
Handlers and description of chunk.
Definition: saveload.h:379
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:222
SLV_181
@ SLV_181
181 25012
Definition: saveload.h:260
SLE_WRITEBYTE
#define SLE_WRITEBYTE(base, variable)
Translate values ingame to different values in the savegame and vv.
Definition: saveload.h:680
SLEG_CONDVAR
#define SLEG_CONDVAR(variable, type, from, to)
Storage of a global variable in some savegame versions.
Definition: saveload.h:707
SLV_100
@ SLV_100
100 13952
Definition: saveload.h:163
HANGAR
@ HANGAR
Heading for hangar.
Definition: airport.h:62
Save_VEHS
static void Save_VEHS()
Will be called when the vehicles need to be saved.
Definition: vehicle_sl.cpp:884
SLE_CONDNULL
#define SLE_CONDNULL(length, from, to)
Empty space in some savegame versions.
Definition: saveload.h:677
GroundVehicle::ClearEngine
void ClearEngine()
Clear engine status.
Definition: ground_vehicle.hpp:284
TrackToTrackBits
static TrackBits TrackToTrackBits(Track track)
Maps a Track to the corresponding TrackBits value.
Definition: track_func.h:85
SLE_REF
#define SLE_REF(base, variable, type)
Storage of a reference in every version of a savegame.
Definition: saveload.h:629
SpecializedStation< Station, false >::Iterate
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
Returns an iterable ensemble of all valid stations of type T.
Definition: base_station_base.h:270
UpdateOldAircraft
void UpdateOldAircraft()
need to be called to load aircraft from old version
Definition: vehicle_sl.cpp:162
Aircraft
Aircraft, helicopters, rotors and their shadows belong to this class.
Definition: aircraft.h:74
Ship::UpdateCache
void UpdateCache()
Update the caches of this ship.
Definition: ship_cmd.cpp:202
SLV_160
@ SLV_160
160 21974 1.1.x
Definition: saveload.h:235
Pool::PoolItem<&_engine_pool >::GetPoolSize
static size_t GetPoolSize()
Returns first unused index.
Definition: pool_type.hpp:350
VS_HIDDEN
@ VS_HIDDEN
Vehicle is not visible.
Definition: vehicle_base.h:30
EngineID
uint16 EngineID
Unique identification number of an engine.
Definition: engine_type.h:21
SLV_5
@ SLV_5
5.0 1429 5.1 1440 5.2 1525 0.3.6
Definition: saveload.h:43
RailVehicleInfo
Information about a rail vehicle.
Definition: engine_type.h:42
SLV_174
@ SLV_174
174 23973 1.2.x
Definition: saveload.h:251
RoadTypeInfo::powered_roadtypes
RoadTypes powered_roadtypes
bitmask to the OTHER roadtypes on which a vehicle of THIS roadtype generates power
Definition: road.h:119
SLF_ALLOW_CONTROL
@ SLF_ALLOW_CONTROL
allow control codes in the strings
Definition: saveload.h:489
CalcPercentVehicleFilled
uint8 CalcPercentVehicleFilled(const Vehicle *front, StringID *colour)
Calculates how full a vehicle is.
Definition: vehicle.cpp:1413
SLV_164
@ SLV_164
164 23290
Definition: saveload.h:239
SLV_31
@ SLV_31
31 5999
Definition: saveload.h:80
Vehicle::tile
TileIndex tile
Current tile index.
Definition: vehicle_base.h:240
EIT_ON_MAP
@ EIT_ON_MAP
Vehicle drawn in viewport.
Definition: vehicle_type.h:86
Vehicle::engine_type
EngineID engine_type
The type of engine used for this vehicle.
Definition: vehicle_base.h:297
VS_CRASHED
@ VS_CRASHED
Vehicle is crashed.
Definition: vehicle_base.h:37
SLV_67
@ SLV_67
67 10236
Definition: saveload.h:123
Vehicle::last_station_visited
StationID last_station_visited
The last station we stopped at.
Definition: vehicle_base.h:311
VehicleCargoList::Append
void Append(CargoPacket *cp, MoveToAction action=MTA_KEEP)
Appends the given cargo packet.
Definition: cargopacket.cpp:250
Vehicle::cargo
VehicleCargoList cargo
The cargo this vehicle is carrying.
Definition: vehicle_base.h:318
SLE_END
#define SLE_END()
End marker of a struct/class save or load.
Definition: saveload.h:686
Vehicle::current_order
Order current_order
The current order (+ status, like: loading)
Definition: vehicle_base.h:327
Load_VEHS
void Load_VEHS()
Will be called when vehicles need to be loaded.
Definition: vehicle_sl.cpp:894
GroundVehicle::gcache
GroundVehicleCache gcache
Cache of often calculated values.
Definition: ground_vehicle.hpp:80
SLV_158
@ SLV_158
158 21933
Definition: saveload.h:232
VEH_EFFECT
@ VEH_EFFECT
Effect vehicle type (smoke, explosions, sparks, bubbles)
Definition: vehicle_type.h:31
Vehicle::IsFrontEngine
bool IsFrontEngine() const
Check if the vehicle is a front engine.
Definition: vehicle_base.h:895
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:80
GetAircraftFlightLevelBounds
void GetAircraftFlightLevelBounds(const Vehicle *v, int *min, int *max)
Get the 'flight level' bounds, in pixels from 'z_pos' 0 for a particular vehicle for normal flight si...
Definition: aircraft_cmd.cpp:718
AfterLoadVehicles
void AfterLoadVehicles(bool part_of_load)
Called after load to update coordinates.
Definition: vehicle_sl.cpp:240
SLV_ROADVEH_PATH_CACHE
@ SLV_ROADVEH_PATH_CACHE
211 PR#7261 Add path cache for road vehicles.
Definition: saveload.h:297
SetAircraftPosition
void SetAircraftPosition(Aircraft *v, int x, int y, int z)
Set aircraft position.
Definition: aircraft_cmd.cpp:522
VS_STOPPED
@ VS_STOPPED
Vehicle is stopped by the player.
Definition: vehicle_base.h:31
Vehicle::last_loading_station
StationID last_loading_station
Last station the vehicle has stopped at and could possibly leave from with any cargo loaded.
Definition: vehicle_base.h:312
Train
'Train' is either a loco or a wagon.
Definition: train.h:85
VEH_INVALID
@ VEH_INVALID
Non-existing type of vehicle.
Definition: vehicle_type.h:35
DEFAULT_GROUP
static const GroupID DEFAULT_GROUP
Ungrouped vehicles are in this group.
Definition: group_type.h:17
SLE_CONDREF
#define SLE_CONDREF(base, variable, type, from, to)
Storage of a reference in some savegame versions.
Definition: saveload.h:561
IsSavegameVersionBefore
static bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor=0)
Checks whether the savegame is below major.
Definition: saveload.h:815
SLV_45
@ SLV_45
45 8501
Definition: saveload.h:97
TrainController
bool TrainController(Train *v, Vehicle *nomove, bool reverse=true)
Move a vehicle chain one movement stop forwards.
Definition: train_cmd.cpp:3098
RoadVehicle::compatible_roadtypes
RoadTypes compatible_roadtypes
Roadtypes this consist is powered on.
Definition: roadveh.h:118
SLV_7
@ SLV_7
7.0 1770
Definition: saveload.h:48
SlObject
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
Definition: saveload.cpp:1612
REF_VEHICLE
@ REF_VEHICLE
Load/save a reference to a vehicle.
Definition: saveload.h:391
REF_CARGO_PACKET
@ REF_CARGO_PACKET
Load/save a reference to a cargo packet.
Definition: saveload.h:397
SLV_182
@ SLV_182
182 25115 FS#5492, r25259, r25296 Goal status
Definition: saveload.h:261
REF_VEHICLE_OLD
@ REF_VEHICLE_OLD
Load/save an old-style reference to a vehicle (for pre-4.4 savegames).
Definition: saveload.h:394
VehicleType
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
Vehicle::sprite_cache
MutableSpriteCache sprite_cache
Cache of sprites and values related to recalculating them, see MutableSpriteCache.
Definition: vehicle_base.h:341
CCF_SAVELOAD
@ CCF_SAVELOAD
Valid changes when loading a savegame. (Everything that is not stored in the save....
Definition: train.h:53
SLV_136
@ SLV_136
136 18764
Definition: saveload.h:206
RAILVEH_WAGON
@ RAILVEH_WAGON
simple wagon, not motorized
Definition: engine_type.h:29
SLV_2
@ SLV_2
2.0 0.3.0 2.1 0.3.1, 0.3.2
Definition: saveload.h:34
DisasterVehicle
Disasters, like submarines, skyrangers and their shadows, belong to this class.
Definition: disaster_vehicle.h:37
SLV_59
@ SLV_59
59 9779
Definition: saveload.h:113
TrainForceProceeding
TrainForceProceeding
Modes for ignoring signals.
Definition: train.h:37
SLV_139
@ SLV_139
139 19346
Definition: saveload.h:209
TRACK_BIT_DEPOT
@ TRACK_BIT_DEPOT
Bitflag for a depot.
Definition: track_type.h:56
SL_MAX_VERSION
@ SL_MAX_VERSION
Highest possible saveload version.
Definition: saveload.h:328
UpdateAircraftCache
void UpdateAircraftCache(Aircraft *v, bool update_range=false)
Update cached values of an aircraft.
Definition: aircraft_cmd.cpp:591
SLV_8
@ SLV_8
8.0 1786
Definition: saveload.h:49
Vehicle::next_shared
Vehicle * next_shared
pointer to the next vehicle that shares the order
Definition: vehicle_base.h:231
Ship
All ships have this type.
Definition: ship.h:26
SLE_VAR
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
Definition: saveload.h:621
VEHICLE_LENGTH
static const uint VEHICLE_LENGTH
The length of a vehicle in tile units.
Definition: vehicle_type.h:76
Pool::PoolItem<&_vehicle_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:378
ConvertOldMultiheadToNew
void ConvertOldMultiheadToNew()
Converts all trains to the new subtype format introduced in savegame 16.2 It also links multiheaded e...
Definition: vehicle_sl.cpp:110
REF_ORDERLIST
@ REF_ORDERLIST
Load/save a reference to an orderlist.
Definition: saveload.h:398
RoadVehUpdateCache
void RoadVehUpdateCache(RoadVehicle *v, bool same_length=false)
Update the cache of a road vehicle.
Definition: roadveh_cmd.cpp:215
SLV_VEH_MOTION_COUNTER
@ SLV_VEH_MOTION_COUNTER
288 PR#8591 Desync safe motion counter
Definition: saveload.h:325
SLV_6
@ SLV_6
6.0 1721 6.1 1768
Definition: saveload.h:46
GroundVehicle::ClearMultiheaded
void ClearMultiheaded()
Clear multiheaded engine property.
Definition: ground_vehicle.hpp:304
SpecializedVehicle< Train, Type >::From
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition: vehicle_base.h:1162
VehicleSettings::roadveh_acceleration_model
uint8 roadveh_acceleration_model
realistic acceleration for road vehicles
Definition: settings_type.h:463
Train::ConsistChanged
void ConsistChanged(ConsistChangeFlags allowed_changes)
Recalculates the cached stuff of a train.
Definition: train_cmd.cpp:106
SlErrorCorrupt
void NORETURN SlErrorCorrupt(const char *msg)
Error handler for corrupt savegames.
Definition: saveload.cpp:358
SLV_36
@ SLV_36
36 6624
Definition: saveload.h:86
CompanyServiceInterval
int CompanyServiceInterval(const Company *c, VehicleType type)
Get the service interval for the given company and vehicle type.
Definition: company_cmd.cpp:1153
SLV_44
@ SLV_44
44 8144
Definition: saveload.h:95
AIR_HELICOPTER
@ AIR_HELICOPTER
an helicopter
Definition: aircraft.h:31
OrderList
Shared order list linking together the linked list of orders and the list of vehicles sharing this or...
Definition: order_base.h:250
GroundVehicle::IsEngine
bool IsEngine() const
Check if a vehicle is an engine (can be first in a consist).
Definition: ground_vehicle.hpp:316
SLV_60
@ SLV_60
60 9874
Definition: saveload.h:115
RAILVEH_MULTIHEAD
@ RAILVEH_MULTIHEAD
indicates a combination of two locomotives
Definition: engine_type.h:28
SLV_194
@ SLV_194
194 26881 v1.5
Definition: saveload.h:276
SlReadByte
byte SlReadByte()
Wrapper for reading a byte from the buffer.
Definition: saveload.cpp:418
GetNewVehiclePosResult
Position information of a vehicle after it moved.
Definition: vehicle_func.h:75
Pool::PoolItem<&_orderlist_pool >::CanAllocateItem
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
Definition: pool_type.hpp:299
SLV_129
@ SLV_129
129 18292
Definition: saveload.h:197
GetRoadTypeInfo
static const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition: road.h:224
EffectVehicle
A special vehicle is one of the following:
Definition: effectvehicle_base.h:24
SLV_105
@ SLV_105
105 14803
Definition: saveload.h:169
GetRailDepotTrack
static Track GetRailDepotTrack(TileIndex t)
Returns the track of a depot, ignoring direction.
Definition: rail_map.h:182
SpecializedVehicle< Train, Type >::Iterate
static Pool::IterateWrapper< Train > Iterate(size_t from=0)
Returns an iterable ensemble of all valid vehicles of type T.
Definition: vehicle_base.h:1231
ReverseTrainDirection
void ReverseTrainDirection(Train *v)
Turn a train around.
Definition: train_cmd.cpp:1808
VEH_DISASTER
@ VEH_DISASTER
Disaster vehicle type.
Definition: vehicle_type.h:32
SLV_167
@ SLV_167
167 23504
Definition: saveload.h:243
SLV_68
@ SLV_68
68 10266
Definition: saveload.h:124
VehicleDefaultSettings::servint_ispercent
bool servint_ispercent
service intervals are in percents
Definition: settings_type.h:541
TicksToLeaveDepot
int TicksToLeaveDepot(const Train *v)
Compute number of ticks when next wagon will leave a depot.
Definition: rail_cmd.cpp:2943
SLV_SHIP_PATH_CACHE
@ SLV_SHIP_PATH_CACHE
203 PR#7072 Add path cache for ships
Definition: saveload.h:287
SetBit
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
CargoPacket
Container for cargo from the same location and time.
Definition: cargopacket.h:42
GetVehicleDescription
const SaveLoad * GetVehicleDescription(VehicleType vt)
Make it possible to make the saveload tables "friends" of other classes.
Definition: vehicle_sl.cpp:581
OverflowSafeInt< int64, INT64_MAX, INT64_MIN >
TFP_SIGNAL
@ TFP_SIGNAL
Ignore next signal, after the signal ignore being stuck.
Definition: train.h:40
GroundVehicle::CargoChanged
void CargoChanged()
Recalculates the cached weight of a vehicle and its parts.
Definition: ground_vehicle.cpp:79
SLV_180
@ SLV_180
180 24998 1.3.x
Definition: saveload.h:259
SLV_101
@ SLV_101
101 14233
Definition: saveload.h:164
Vehicle::spritenum
byte spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
Definition: vehicle_base.h:289
SLV_191
@ SLV_191
191 26636 FS#6026 Fix disaster vehicle storage (No bump) 191 26646 FS#6041 Linkgraph - store location...
Definition: saveload.h:272
SLV_58
@ SLV_58
58 9762
Definition: saveload.h:112
CCF_TRACK
@ CCF_TRACK
Valid changes while vehicle is driving, and possibly changing tracks.
Definition: train.h:48
GameSettings::vehicle
VehicleSettings vehicle
options for vehicles
Definition: settings_type.h:568
GroundVehicle::IsFreeWagon
bool IsFreeWagon() const
Check if the vehicle is a free wagon (got no engine in front of it).
Definition: ground_vehicle.hpp:310
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:52
SLE_CONDDEQUE
#define SLE_CONDDEQUE(base, variable, type, from, to)
Storage of a deque in some savegame versions.
Definition: saveload.h:613
GetNewVehiclePosResult::y
int y
x and y position of the vehicle after moving
Definition: vehicle_func.h:76
SaveLoad
SaveLoad type struct.
Definition: saveload.h:516
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
Company
Definition: company_base.h:110
Order::flags
uint8 flags
Load/unload types, depot order/action types.
Definition: order_base.h:39
Company::settings
CompanySettings settings
settings specific for each company
Definition: company_base.h:122
SLV_51
@ SLV_51
51 8978
Definition: saveload.h:104
INVALID_COORD
static const int32 INVALID_COORD
Sentinel for an invalid coordinate.
Definition: vehicle_base.h:1248
Order::type
uint8 type
The type of order + non-stop flags.
Definition: order_base.h:38
SLV_152
@ SLV_152
152 21171
Definition: saveload.h:225
FLYING
@ FLYING
Vehicle is flying in the air.
Definition: airport.h:75
SlIterateArray
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition: saveload.cpp:631
CheckValidVehicles
static void CheckValidVehicles()
Check all vehicles to ensure their engine type is valid for the currently loaded NewGRFs (that includ...
Definition: vehicle_sl.cpp:209
GroundVehicle::IsMultiheaded
bool IsMultiheaded() const
Check if the vehicle is a multiheaded engine.
Definition: ground_vehicle.hpp:328
GetNewVehiclePos
GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v)
Get position information of a vehicle when moving one pixel in the direction it is facing.
Definition: vehicle.cpp:1680
SLV_SHIP_ROTATION
@ SLV_SHIP_ROTATION
204 PR#7065 Add extra rotation stages for ships.
Definition: saveload.h:288