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

OpenTTD Source 14.0-beta1

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
12 #include "saveload.h"
13 #include "compat/vehicle_sl_compat.h"
14
15 #include "../vehicle_func.h"
16 #include "../train.h"
17 #include "../roadveh.h"
18 #include "../ship.h"
19 #include "../aircraft.h"
20 #include "../timetable.h"
21 #include "../station_base.h"
22 #include "../effectvehicle_base.h"
23 #include "../company_base.h"
24 #include "../company_func.h"
25 #include "../disaster_vehicle.h"
26 #include "../economy_base.h"
27
28 #include "../safeguards.h"
29
34 void ConnectMultiheadedTrains()
35 {
36 for (Train *v : Train::Iterate()) {
37 v->other_multiheaded_part = nullptr;
38 }
39
40 for (Train *v : Train::Iterate()) {
41 if (v->IsFrontEngine() || v->IsFreeWagon()) {
42 /* Two ways to associate multiheaded parts to each other:
43 * sequential-matching: Trains shall be arranged to look like <..>..<..>..<..>..
44 * bracket-matching: Free vehicle chains shall be arranged to look like ..<..<..>..<..>..>..
45 *
46 * Note: Old savegames might contain chains which do not comply with these rules, e.g.
47 * - the front and read parts have invalid orders
48 * - different engine types might be combined
49 * - there might be different amounts of front and rear parts.
50 *
51 * Note: The multiheaded parts need to be matched exactly like they are matched on the server, else desyncs will occur.
52 * This is why two matching strategies are needed.
53 */
54
55 bool sequential_matching = v->IsFrontEngine();
56
57 for (Train *u = v; u != nullptr; u = u->GetNextVehicle()) {
58 if (u->other_multiheaded_part != nullptr) continue; // we already linked this one
59
60 if (u->IsMultiheaded()) {
61 if (!u->IsEngine()) {
62 /* we got a rear car without a front car. We will convert it to a front one */
63 u->SetEngine();
64 u->spritenum--;
65 }
66
67 /* Find a matching back part */
68 EngineID eid = u->engine_type;
69 Train *w;
70 if (sequential_matching) {
71 for (w = u->GetNextVehicle(); w != nullptr; w = w->GetNextVehicle()) {
72 if (w->engine_type != eid || w->other_multiheaded_part != nullptr || !w->IsMultiheaded()) continue;
73
74 /* we found a car to partner with this engine. Now we will make sure it face the right way */
75 if (w->IsEngine()) {
76 w->ClearEngine();
77 w->spritenum++;
78 }
79 break;
80 }
81 } else {
82 uint stack_pos = 0;
83 for (w = u->GetNextVehicle(); w != nullptr; w = w->GetNextVehicle()) {
84 if (w->engine_type != eid || w->other_multiheaded_part != nullptr || !w->IsMultiheaded()) continue;
85
86 if (w->IsEngine()) {
87 stack_pos++;
88 } else {
89 if (stack_pos == 0) break;
90 stack_pos--;
91 }
92 }
93 }
94
95 if (w != nullptr) {
96 w->other_multiheaded_part = u;
97 u->other_multiheaded_part = w;
98 } else {
99 /* we got a front car and no rear cars. We will fake this one for forget that it should have been multiheaded */
100 u->ClearMultiheaded();
101 }
102 }
103 }
104 }
105 }
106 }
107
112 void ConvertOldMultiheadToNew()
113 {
114 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
115
116 for (Train *t : Train::Iterate()) {
117 if (HasBit(t->subtype, 7) && ((t->subtype & ~0x80) == 0 || (t->subtype & ~0x80) == 4)) {
118 for (Train *u = t; u != nullptr; u = u->Next()) {
119 const RailVehicleInfo *rvi = RailVehInfo(u->engine_type);
120
121 ClrBit(u->subtype, 7);
122 switch (u->subtype) {
123 case 0: // TS_Front_Engine
124 if (rvi->railveh_type == RAILVEH_MULTIHEAD) u->SetMultiheaded();
125 u->SetFrontEngine();
126 u->SetEngine();
127 break;
128
129 case 1: // TS_Artic_Part
130 u->subtype = 0;
131 u->SetArticulatedPart();
132 break;
133
134 case 2: // TS_Not_First
135 u->subtype = 0;
136 if (rvi->railveh_type == RAILVEH_WAGON) {
137 /* normal wagon */
138 u->SetWagon();
139 break;
140 }
141 if (rvi->railveh_type == RAILVEH_MULTIHEAD && rvi->image_index == u->spritenum - 1) {
142 /* rear end of a multiheaded engine */
143 u->SetMultiheaded();
144 break;
145 }
146 if (rvi->railveh_type == RAILVEH_MULTIHEAD) u->SetMultiheaded();
147 u->SetEngine();
148 break;
149
150 case 4: // TS_Free_Car
151 u->subtype = 0;
152 u->SetWagon();
153 u->SetFreeWagon();
154 break;
155 default: SlErrorCorrupt("Invalid train subtype");
156 }
157 }
158 }
159 }
160 }
161
162
164 void UpdateOldAircraft()
165 {
166 /* set airport_flags to 0 for all airports just to be sure */
167 for (Station *st : Station::Iterate()) {
168 st->airport.flags = 0; // reset airport
169 }
170
171 for (Aircraft *a : Aircraft::Iterate()) {
172 /* airplane has another vehicle with subtype 4 (shadow), helicopter also has 3 (rotor)
173 * skip those */
174 if (a->IsNormalAircraft()) {
175 /* airplane in terminal stopped doesn't hurt anyone, so goto next */
176 if ((a->vehstatus & VS_STOPPED) && a->state == 0) {
177 a->state = HANGAR;
178 continue;
179 }
180
181 AircraftLeaveHangar(a, a->direction); // make airplane visible if it was in a depot for example
182 a->vehstatus &= ~VS_STOPPED; // make airplane moving
183 UpdateAircraftCache(a);
184 a->cur_speed = a->vcache.cached_max_speed; // so aircraft don't have zero speed while in air
185 if (!a->current_order.IsType(OT_GOTO_STATION) && !a->current_order.IsType(OT_GOTO_DEPOT)) {
186 /* reset current order so aircraft doesn't have invalid "station-only" order */
187 a->current_order.MakeDummy();
188 }
189 a->state = FLYING;
190 AircraftNextAirportPos_and_Order(a); // move it to the entry point of the airport
191 GetNewVehiclePosResult gp = GetNewVehiclePos(a);
192 a->tile = 0; // aircraft in air is tile=0
193
194 /* correct speed of helicopter-rotors */
195 if (a->subtype == AIR_HELICOPTER) a->Next()->Next()->cur_speed = 32;
196
197 /* set new position x,y,z */
198 GetAircraftFlightLevelBounds(a, &a->z_pos, nullptr);
199 SetAircraftPosition(a, gp.x, gp.y, GetAircraftFlightLevel(a));
200 }
201 }
202
203 /* Clear aircraft from loading vehicles, if we bumped them into the air. */
204 for (Station *st : Station::Iterate()) {
205 for (auto iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end(); /* nothing */) {
206 Vehicle *v = *iter;
207 if (v->type == VEH_AIRCRAFT && !v->current_order.IsType(OT_LOADING)) {
208 iter = st->loading_vehicles.erase(iter);
209 delete v->cargo_payment;
210 } else {
211 ++iter;
212 }
213 }
214 }
215 }
216
224 static void CheckValidVehicles()
225 {
226 size_t total_engines = Engine::GetPoolSize();
227 EngineID first_engine[4] = { INVALID_ENGINE, INVALID_ENGINE, INVALID_ENGINE, INVALID_ENGINE };
228
229 for (const Engine *e : Engine::IterateType(VEH_TRAIN)) { first_engine[VEH_TRAIN] = e->index; break; }
230 for (const Engine *e : Engine::IterateType(VEH_ROAD)) { first_engine[VEH_ROAD] = e->index; break; }
231 for (const Engine *e : Engine::IterateType(VEH_SHIP)) { first_engine[VEH_SHIP] = e->index; break; }
232 for (const Engine *e : Engine::IterateType(VEH_AIRCRAFT)) { first_engine[VEH_AIRCRAFT] = e->index; break; }
233
234 for (Vehicle *v : Vehicle::Iterate()) {
235 /* Test if engine types match */
236 switch (v->type) {
237 case VEH_TRAIN:
238 case VEH_ROAD:
239 case VEH_SHIP:
240 case VEH_AIRCRAFT:
241 if (v->engine_type >= total_engines || v->type != v->GetEngine()->type) {
242 v->engine_type = first_engine[v->type];
243 }
244 break;
245
246 default:
247 break;
248 }
249 }
250 }
251
252 extern byte _age_cargo_skip_counter; // From misc_sl.cpp
253
255 void AfterLoadVehicles(bool part_of_load)
256 {
257 for (Vehicle *v : Vehicle::Iterate()) {
258 /* Reinstate the previous pointer */
259 if (v->Next() != nullptr) v->Next()->previous = v;
260 if (v->NextShared() != nullptr) v->NextShared()->previous_shared = v;
261
262 if (part_of_load) v->fill_percent_te_id = INVALID_TE_ID;
263 v->first = nullptr;
264 if (v->IsGroundVehicle()) v->GetGroundVehicleCache()->first_engine = INVALID_ENGINE;
265 }
266
267 /* AfterLoadVehicles may also be called in case of NewGRF reload, in this
268 * case we may not convert orders again. */
269 if (part_of_load) {
270 /* Create shared vehicle chain for very old games (pre 5,2) and create
271 * OrderList from shared vehicle chains. For this to work correctly, the
272 * following conditions must be fulfilled:
273 * a) both next_shared and previous_shared are not set for pre 5,2 games
274 * b) both next_shared and previous_shared are set for later games
275 */
276 std::map<Order*, OrderList*> mapping;
277
278 for (Vehicle *v : Vehicle::Iterate()) {
279 if (v->old_orders != nullptr) {
280 if (IsSavegameVersionBefore(SLV_105)) { // Pre-105 didn't save an OrderList
281 if (mapping[v->old_orders] == nullptr) {
282 /* This adds the whole shared vehicle chain for case b */
283
284 /* Creating an OrderList here is safe because the number of vehicles
285 * allowed in these savegames matches the number of OrderLists. As
286 * such each vehicle can get an OrderList and it will (still) fit. */
287 assert(OrderList::CanAllocateItem());
288 v->orders = mapping[v->old_orders] = new OrderList(v->old_orders, v);
289 } else {
290 v->orders = mapping[v->old_orders];
291 /* For old games (case a) we must create the shared vehicle chain */
292 if (IsSavegameVersionBefore(SLV_5, 2)) {
293 v->AddToShared(v->orders->GetFirstSharedVehicle());
294 }
295 }
296 } else { // OrderList was saved as such, only recalculate not saved values
297 if (v->PreviousShared() == nullptr) {
298 v->orders->Initialize(v->orders->first, v);
299 }
300 }
301 }
302 }
303 }
304
305 for (Vehicle *v : Vehicle::Iterate()) {
306 /* Fill the first pointers */
307 if (v->Previous() == nullptr) {
308 for (Vehicle *u = v; u != nullptr; u = u->Next()) {
309 u->first = v;
310 }
311 }
312 }
313
314 if (part_of_load) {
315 if (IsSavegameVersionBefore(SLV_105)) {
316 /* Before 105 there was no order for shared orders, thus it messed up horribly */
317 for (Vehicle *v : Vehicle::Iterate()) {
318 if (v->First() != v || v->orders != nullptr || v->previous_shared != nullptr || v->next_shared == nullptr) continue;
319
320 /* As above, allocating OrderList here is safe. */
321 assert(OrderList::CanAllocateItem());
322 v->orders = new OrderList(nullptr, v);
323 for (Vehicle *u = v; u != nullptr; u = u->next_shared) {
324 u->orders = v->orders;
325 }
326 }
327 }
328
329 if (IsSavegameVersionBefore(SLV_157)) {
330 /* The road vehicle subtype was converted to a flag. */
331 for (RoadVehicle *rv : RoadVehicle::Iterate()) {
332 if (rv->subtype == 0) {
333 /* The road vehicle is at the front. */
334 rv->SetFrontEngine();
335 } else if (rv->subtype == 1) {
336 /* The road vehicle is an articulated part. */
337 rv->subtype = 0;
338 rv->SetArticulatedPart();
339 } else {
340 SlErrorCorrupt("Invalid road vehicle subtype");
341 }
342 }
343 }
344
345 if (IsSavegameVersionBefore(SLV_160)) {
346 /* In some old savegames there might be some "crap" stored. */
347 for (Vehicle *v : Vehicle::Iterate()) {
348 if (!v->IsPrimaryVehicle() && v->type != VEH_DISASTER) {
349 v->current_order.Free();
350 v->unitnumber = 0;
351 }
352 }
353 }
354
355 if (IsSavegameVersionBefore(SLV_162)) {
356 /* Set the vehicle-local cargo age counter from the old global counter. */
357 for (Vehicle *v : Vehicle::Iterate()) {
358 v->cargo_age_counter = _age_cargo_skip_counter;
359 }
360 }
361
362 if (IsSavegameVersionBefore(SLV_180)) {
363 /* Set service interval flags */
364 for (Vehicle *v : Vehicle::Iterate()) {
365 if (!v->IsPrimaryVehicle()) continue;
366
367 const Company *c = Company::Get(v->owner);
368 int interval = CompanyServiceInterval(c, v->type);
369
370 v->SetServiceIntervalIsCustom(v->GetServiceInterval() != interval);
371 v->SetServiceIntervalIsPercent(c->settings.vehicle.servint_ispercent);
372 }
373 }
374
375 if (IsSavegameVersionBefore(SLV_SHIP_ROTATION)) {
376 /* Ship rotation added */
377 for (Ship *s : Ship::Iterate()) {
378 s->rotation = s->direction;
379 }
380 } else {
381 for (Ship *s : Ship::Iterate()) {
382 if (s->rotation == s->direction) continue;
383 /* In case we are rotating on gameload, set the rotation position to
384 * the current position, otherwise the applied workaround offset would
385 * be with respect to 0,0.
386 */
387 s->rotation_x_pos = s->x_pos;
388 s->rotation_y_pos = s->y_pos;
389 }
390 }
391
392 if (IsSavegameVersionBefore(SLV_TIMETABLE_START_TICKS)) {
393 /* Convert timetable start from a date to an absolute tick in TimerGameTick::counter. */
394 for (Vehicle *v : Vehicle::Iterate()) {
395 /* If the start date is 0, the vehicle is not waiting to start and can be ignored. */
396 if (v->timetable_start == 0) continue;
397
398 v->timetable_start = GetStartTickFromDate(v->timetable_start);
399 }
400 }
401 }
402
403 CheckValidVehicles();
404
405 for (Vehicle *v : Vehicle::Iterate()) {
406 assert(v->first != nullptr);
407
408 v->trip_occupancy = CalcPercentVehicleFilled(v, nullptr);
409
410 switch (v->type) {
411 case VEH_TRAIN: {
412 Train *t = Train::From(v);
413 if (t->IsFrontEngine() || t->IsFreeWagon()) {
414 t->gcache.last_speed = t->cur_speed; // update displayed train speed
415 t->ConsistChanged(CCF_SAVELOAD);
416 }
417 break;
418 }
419
420 case VEH_ROAD: {
421 RoadVehicle *rv = RoadVehicle::From(v);
422 if (rv->IsFrontEngine()) {
423 rv->gcache.last_speed = rv->cur_speed; // update displayed road vehicle speed
424
425 rv->roadtype = Engine::Get(rv->engine_type)->u.road.roadtype;
426 rv->compatible_roadtypes = GetRoadTypeInfo(rv->roadtype)->powered_roadtypes;
427 RoadTramType rtt = GetRoadTramType(rv->roadtype);
428 for (RoadVehicle *u = rv; u != nullptr; u = u->Next()) {
429 u->roadtype = rv->roadtype;
430 u->compatible_roadtypes = rv->compatible_roadtypes;
431 if (GetRoadType(u->tile, rtt) == INVALID_ROADTYPE) SlErrorCorrupt("Road vehicle on invalid road type");
432 }
433
434 RoadVehUpdateCache(rv);
435 if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) {
436 rv->CargoChanged();
437 }
438 }
439 break;
440 }
441
442 case VEH_SHIP:
443 Ship::From(v)->UpdateCache();
444 break;
445
446 default: break;
447 }
448 }
449
450 /* Stop non-front engines */
451 if (part_of_load && IsSavegameVersionBefore(SLV_112)) {
452 for (Vehicle *v : Vehicle::Iterate()) {
453 if (v->type == VEH_TRAIN) {
454 Train *t = Train::From(v);
455 if (!t->IsFrontEngine()) {
456 if (t->IsEngine()) t->vehstatus |= VS_STOPPED;
457 /* cur_speed is now relevant for non-front parts - nonzero breaks
458 * moving-wagons-inside-depot- and autoreplace- code */
459 t->cur_speed = 0;
460 }
461 }
462 /* trains weren't stopping gradually in old OTTD versions (and TTO/TTD)
463 * other vehicle types didn't have zero speed while stopped (even in 'recent' OTTD versions) */
464 if ((v->vehstatus & VS_STOPPED) && (v->type != VEH_TRAIN || IsSavegameVersionBefore(SLV_2, 1))) {
465 v->cur_speed = 0;
466 }
467 }
468 }
469
470 for (Vehicle *v : Vehicle::Iterate()) {
471 switch (v->type) {
472 case VEH_ROAD:
473 case VEH_TRAIN:
474 case VEH_SHIP:
475 v->GetImage(v->direction, EIT_ON_MAP, &v->sprite_cache.sprite_seq);
476 break;
477
478 case VEH_AIRCRAFT:
479 if (Aircraft::From(v)->IsNormalAircraft()) {
480 v->GetImage(v->direction, EIT_ON_MAP, &v->sprite_cache.sprite_seq);
481
482 /* The aircraft's shadow will have the same image as the aircraft, but no colour */
483 Vehicle *shadow = v->Next();
484 if (shadow == nullptr) SlErrorCorrupt("Missing shadow for aircraft");
485
486 shadow->sprite_cache.sprite_seq.CopyWithoutPalette(v->sprite_cache.sprite_seq);
487
488 /* In the case of a helicopter we will update the rotor sprites */
489 if (v->subtype == AIR_HELICOPTER) {
490 Vehicle *rotor = shadow->Next();
491 if (rotor == nullptr) SlErrorCorrupt("Missing rotor for helicopter");
492
493 GetRotorImage(Aircraft::From(v), EIT_ON_MAP, &rotor->sprite_cache.sprite_seq);
494 }
495
496 UpdateAircraftCache(Aircraft::From(v), true);
497 }
498 break;
499 default: break;
500 }
501
502 v->UpdateDeltaXY();
503 v->coord.left = INVALID_COORD;
504 v->sprite_cache.old_coord.left = INVALID_COORD;
505 v->UpdatePosition();
506 v->UpdateViewport(false);
507 }
508 }
509
510 bool TrainController(Train *v, Vehicle *nomove, bool reverse = true); // From train_cmd.cpp
511 void ReverseTrainDirection(Train *v);
512 void ReverseTrainSwapVeh(Train *v, int l, int r);
513
515 void FixupTrainLengths()
516 {
517 /* Vehicle center was moved from 4 units behind the front to half the length
518 * behind the front. Move vehicles so they end up on the same spot. */
519 for (Vehicle *v : Vehicle::Iterate()) {
520 if (v->type == VEH_TRAIN && v->IsPrimaryVehicle()) {
521 /* The vehicle center is now more to the front depending on vehicle length,
522 * so we need to move all vehicles forward to cover the difference to the
523 * old center, otherwise wagon spacing in trains would be broken upon load. */
524 for (Train *u = Train::From(v); u != nullptr; u = u->Next()) {
525 if (u->track == TRACK_BIT_DEPOT || (u->vehstatus & VS_CRASHED)) continue;
526
527 Train *next = u->Next();
528
529 /* Try to pull the vehicle half its length forward. */
530 int diff = (VEHICLE_LENGTH - u->gcache.cached_veh_length) / 2;
531 int done;
532 for (done = 0; done < diff; done++) {
533 if (!TrainController(u, next, false)) break;
534 }
535
536 if (next != nullptr && done < diff && u->IsFrontEngine()) {
537 /* Pulling the front vehicle forwards failed, we either encountered a dead-end
538 * or a red signal. To fix this, we try to move the whole train the required
539 * space backwards and re-do the fix up of the front vehicle. */
540
541 /* Ignore any signals when backtracking. */
542 TrainForceProceeding old_tfp = u->force_proceed;
543 u->force_proceed = TFP_SIGNAL;
544
545 /* Swap start<>end, start+1<>end-1, ... */
546 int r = CountVehiclesInChain(u) - 1; // number of vehicles - 1
547 int l = 0;
548 do ReverseTrainSwapVeh(u, l++, r--); while (l <= r);
549
550 /* We moved the first vehicle which is now the last. Move it back to the
551 * original position as we will fix up the last vehicle later in the loop. */
552 for (int i = 0; i < done; i++) TrainController(u->Last(), nullptr);
553
554 /* Move the train backwards to get space for the first vehicle. As the stopping
555 * distance from a line end is rounded up, move the train one unit more to cater
556 * for front vehicles with odd lengths. */
557 int moved;
558 for (moved = 0; moved < diff + 1; moved++) {
559 if (!TrainController(u, nullptr, false)) break;
560 }
561
562 /* Swap start<>end, start+1<>end-1, ... again. */
563 r = CountVehiclesInChain(u) - 1; // number of vehicles - 1
564 l = 0;
565 do ReverseTrainSwapVeh(u, l++, r--); while (l <= r);
566
567 u->force_proceed = old_tfp;
568
569 /* Tracks are too short to fix the train length. The player has to fix the
570 * train in a depot. Bail out so we don't damage the vehicle chain any more. */
571 if (moved < diff + 1) break;
572
573 /* Re-do the correction for the first vehicle. */
574 for (done = 0; done < diff; done++) TrainController(u, next, false);
575
576 /* We moved one unit more backwards than needed for even-length front vehicles,
577 * try to move that unit forward again. We don't care if this step fails. */
578 TrainController(u, nullptr, false);
579 }
580
581 /* If the next wagon is still in a depot, check if it shouldn't be outside already. */
582 if (next != nullptr && next->track == TRACK_BIT_DEPOT) {
583 int d = TicksToLeaveDepot(u);
584 if (d <= 0) {
585 /* Next vehicle should have left the depot already, show it and pull forward. */
586 next->vehstatus &= ~VS_HIDDEN;
587 next->track = TrackToTrackBits(GetRailDepotTrack(next->tile));
588 for (int i = 0; i >= d; i--) TrainController(next, nullptr);
589 }
590 }
591 }
592
593 /* Update all cached properties after moving the vehicle chain around. */
594 Train::From(v)->ConsistChanged(CCF_TRACK);
595 }
596 }
597 }
598
599 static uint8_t _cargo_periods;
600 static uint16_t _cargo_source;
601 static uint32_t _cargo_source_xy;
602 static uint16_t _cargo_count;
603 static uint16_t _cargo_paid_for;
604 static Money _cargo_feeder_share;
605
606 class SlVehicleCommon : public DefaultSaveLoadHandler<SlVehicleCommon, Vehicle> {
607 public:
608 #if defined(_MSC_VER) && (_MSC_VER == 1915 || _MSC_VER == 1916)
609 /* This table access private members of other classes; they have this
610 * class as friend. For MSVC CL 19.15 and 19.16 this doesn't work for
611 * "inline static const", so we are forced to wrap the table in a
612 * function. CL 19.16 is the latest for VS2017. */
613 inline static const SaveLoad description[] = {{}};
614 SaveLoadTable GetDescription() const override {
615 #else
616 inline
617 #endif
618 static const SaveLoad description[] = {
619 SLE_VAR(Vehicle, subtype, SLE_UINT8),
620
621 SLE_REF(Vehicle, next, REF_VEHICLE_OLD),
622 SLE_CONDVAR(Vehicle, name, SLE_NAME, SL_MIN_VERSION, SLV_84),
623 SLE_CONDSSTR(Vehicle, name, SLE_STR | SLF_ALLOW_CONTROL, SLV_84, SL_MAX_VERSION),
624 SLE_CONDVAR(Vehicle, unitnumber, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_8),
625 SLE_CONDVAR(Vehicle, unitnumber, SLE_UINT16, SLV_8, SL_MAX_VERSION),
626 SLE_VAR(Vehicle, owner, SLE_UINT8),
627 SLE_CONDVAR(Vehicle, tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
628 SLE_CONDVAR(Vehicle, tile, SLE_UINT32, SLV_6, SL_MAX_VERSION),
629 SLE_CONDVAR(Vehicle, dest_tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
630 SLE_CONDVAR(Vehicle, dest_tile, SLE_UINT32, SLV_6, SL_MAX_VERSION),
631
632 SLE_CONDVAR(Vehicle, x_pos, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
633 SLE_CONDVAR(Vehicle, x_pos, SLE_UINT32, SLV_6, SL_MAX_VERSION),
634 SLE_CONDVAR(Vehicle, y_pos, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
635 SLE_CONDVAR(Vehicle, y_pos, SLE_UINT32, SLV_6, SL_MAX_VERSION),
636 SLE_CONDVAR(Vehicle, z_pos, SLE_FILE_U8 | SLE_VAR_I32, SL_MIN_VERSION, SLV_164),
637 SLE_CONDVAR(Vehicle, z_pos, SLE_INT32, SLV_164, SL_MAX_VERSION),
638 SLE_VAR(Vehicle, direction, SLE_UINT8),
639
640 SLE_VAR(Vehicle, spritenum, SLE_UINT8),
641 SLE_VAR(Vehicle, engine_type, SLE_UINT16),
642 SLE_VAR(Vehicle, cur_speed, SLE_UINT16),
643 SLE_VAR(Vehicle, subspeed, SLE_UINT8),
644 SLE_VAR(Vehicle, acceleration, SLE_UINT8),
645 SLE_CONDVAR(Vehicle, motion_counter, SLE_UINT32, SLV_VEH_MOTION_COUNTER, SL_MAX_VERSION),
646 SLE_VAR(Vehicle, progress, SLE_UINT8),
647
648 SLE_VAR(Vehicle, vehstatus, SLE_UINT8),
649 SLE_CONDVAR(Vehicle, last_station_visited, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_5),
650 SLE_CONDVAR(Vehicle, last_station_visited, SLE_UINT16, SLV_5, SL_MAX_VERSION),
651 SLE_CONDVAR(Vehicle, last_loading_station, SLE_UINT16, SLV_182, SL_MAX_VERSION),
652
653 SLE_VAR(Vehicle, cargo_type, SLE_UINT8),
654 SLE_CONDVAR(Vehicle, cargo_subtype, SLE_UINT8, SLV_35, SL_MAX_VERSION),
655 SLEG_CONDVAR("cargo_days", _cargo_periods, SLE_UINT8, SL_MIN_VERSION, SLV_68),
656 SLEG_CONDVAR("cargo_source", _cargo_source, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_7),
657 SLEG_CONDVAR("cargo_source", _cargo_source, SLE_UINT16, SLV_7, SLV_68),
658 SLEG_CONDVAR("cargo_source_xy", _cargo_source_xy, SLE_UINT32, SLV_44, SLV_68),
659 SLE_VAR(Vehicle, cargo_cap, SLE_UINT16),
660 SLE_CONDVAR(Vehicle, refit_cap, SLE_UINT16, SLV_182, SL_MAX_VERSION),
661 SLEG_CONDVAR("cargo_count", _cargo_count, SLE_UINT16, SL_MIN_VERSION, SLV_68),
662 SLE_CONDREFLIST(Vehicle, cargo.packets, REF_CARGO_PACKET, SLV_68, SL_MAX_VERSION),
663 SLE_CONDARR(Vehicle, cargo.action_counts, SLE_UINT, VehicleCargoList::NUM_MOVE_TO_ACTION, SLV_181, SL_MAX_VERSION),
664 SLE_CONDVAR(Vehicle, cargo_age_counter, SLE_UINT16, SLV_162, SL_MAX_VERSION),
665
666 SLE_VAR(Vehicle, day_counter, SLE_UINT8),
667 SLE_VAR(Vehicle, tick_counter, SLE_UINT8),
668 SLE_CONDVAR(Vehicle, running_ticks, SLE_UINT8, SLV_88, SL_MAX_VERSION),
669
670 SLE_VAR(Vehicle, cur_implicit_order_index, SLE_UINT8),
671 SLE_CONDVAR(Vehicle, cur_real_order_index, SLE_UINT8, SLV_158, SL_MAX_VERSION),
672
673 /* This next line is for version 4 and prior compatibility.. it temporarily reads
674 type and flags (which were both 4 bits) into type. Later on this is
675 converted correctly */
676 SLE_CONDVAR(Vehicle, current_order.type, SLE_UINT8, SL_MIN_VERSION, SLV_5),
677 SLE_CONDVAR(Vehicle, current_order.dest, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_5),
678
679 /* Orders for version 5 and on */
680 SLE_CONDVAR(Vehicle, current_order.type, SLE_UINT8, SLV_5, SL_MAX_VERSION),
681 SLE_CONDVAR(Vehicle, current_order.flags, SLE_UINT8, SLV_5, SL_MAX_VERSION),
682 SLE_CONDVAR(Vehicle, current_order.dest, SLE_UINT16, SLV_5, SL_MAX_VERSION),
683
684 /* Refit in current order */
685 SLE_CONDVAR(Vehicle, current_order.refit_cargo, SLE_UINT8, SLV_36, SL_MAX_VERSION),
686
687 /* Timetable in current order */
688 SLE_CONDVAR(Vehicle, current_order.wait_time, SLE_UINT16, SLV_67, SL_MAX_VERSION),
689 SLE_CONDVAR(Vehicle, current_order.travel_time, SLE_UINT16, SLV_67, SL_MAX_VERSION),
690 SLE_CONDVAR(Vehicle, current_order.max_speed, SLE_UINT16, SLV_174, SL_MAX_VERSION),
691 SLE_CONDVAR(Vehicle, timetable_start, SLE_FILE_I32 | SLE_VAR_U64, SLV_129, SLV_TIMETABLE_START_TICKS),
692 SLE_CONDVAR(Vehicle, timetable_start, SLE_UINT64, SLV_TIMETABLE_START_TICKS, SL_MAX_VERSION),
693
694 SLE_CONDREF(Vehicle, orders, REF_ORDER, SL_MIN_VERSION, SLV_105),
695 SLE_CONDREF(Vehicle, orders, REF_ORDERLIST, SLV_105, SL_MAX_VERSION),
696
697 SLE_CONDVAR(Vehicle, age, SLE_FILE_U16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_31),
698 SLE_CONDVAR(Vehicle, age, SLE_INT32, SLV_31, SL_MAX_VERSION),
699 SLE_CONDVAR(Vehicle, max_age, SLE_FILE_U16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_31),
700 SLE_CONDVAR(Vehicle, max_age, SLE_INT32, SLV_31, SL_MAX_VERSION),
701 SLE_CONDVAR(Vehicle, date_of_last_service, SLE_FILE_U16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_31),
702 SLE_CONDVAR(Vehicle, date_of_last_service, SLE_INT32, SLV_31, SL_MAX_VERSION),
703 SLE_CONDVAR(Vehicle, date_of_last_service_newgrf, SLE_INT32, SLV_NEWGRF_LAST_SERVICE, SL_MAX_VERSION),
704 SLE_CONDVAR(Vehicle, service_interval, SLE_UINT16, SL_MIN_VERSION, SLV_31),
705 SLE_CONDVAR(Vehicle, service_interval, SLE_FILE_U32 | SLE_VAR_U16, SLV_31, SLV_180),
706 SLE_CONDVAR(Vehicle, service_interval, SLE_UINT16, SLV_180, SL_MAX_VERSION),
707 SLE_VAR(Vehicle, reliability, SLE_UINT16),
708 SLE_VAR(Vehicle, reliability_spd_dec, SLE_UINT16),
709 SLE_VAR(Vehicle, breakdown_ctr, SLE_UINT8),
710 SLE_VAR(Vehicle, breakdown_delay, SLE_UINT8),
711 SLE_VAR(Vehicle, breakdowns_since_last_service, SLE_UINT8),
712 SLE_VAR(Vehicle, breakdown_chance, SLE_UINT8),
713 SLE_CONDVAR(Vehicle, build_year, SLE_FILE_U8 | SLE_VAR_I32, SL_MIN_VERSION, SLV_31),
714 SLE_CONDVAR(Vehicle, build_year, SLE_INT32, SLV_31, SL_MAX_VERSION),
715
716 SLE_VAR(Vehicle, load_unload_ticks, SLE_UINT16),
717 SLEG_CONDVAR("cargo_paid_for", _cargo_paid_for, SLE_UINT16, SLV_45, SL_MAX_VERSION),
718 SLE_CONDVAR(Vehicle, vehicle_flags, SLE_FILE_U8 | SLE_VAR_U16, SLV_40, SLV_180),
719 SLE_CONDVAR(Vehicle, vehicle_flags, SLE_UINT16, SLV_180, SL_MAX_VERSION),
720
721 SLE_CONDVAR(Vehicle, profit_this_year, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_65),
722 SLE_CONDVAR(Vehicle, profit_this_year, SLE_INT64, SLV_65, SL_MAX_VERSION),
723 SLE_CONDVAR(Vehicle, profit_last_year, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_65),
724 SLE_CONDVAR(Vehicle, profit_last_year, SLE_INT64, SLV_65, SL_MAX_VERSION),
725 SLEG_CONDVAR("cargo_feeder_share", _cargo_feeder_share, SLE_FILE_I32 | SLE_VAR_I64, SLV_51, SLV_65),
726 SLEG_CONDVAR("cargo_feeder_share", _cargo_feeder_share, SLE_INT64, SLV_65, SLV_68),
727 SLE_CONDVAR(Vehicle, value, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_65),
728 SLE_CONDVAR(Vehicle, value, SLE_INT64, SLV_65, SL_MAX_VERSION),
729
730 SLE_CONDVAR(Vehicle, random_bits, SLE_FILE_U8 | SLE_VAR_U16, SLV_2, SLV_EXTEND_VEHICLE_RANDOM),
731 SLE_CONDVAR(Vehicle, random_bits, SLE_UINT16, SLV_EXTEND_VEHICLE_RANDOM, SL_MAX_VERSION),
732 SLE_CONDVAR(Vehicle, waiting_triggers, SLE_UINT8, SLV_2, SL_MAX_VERSION),
733
734 SLE_CONDREF(Vehicle, next_shared, REF_VEHICLE, SLV_2, SL_MAX_VERSION),
735 SLE_CONDVAR(Vehicle, group_id, SLE_UINT16, SLV_60, SL_MAX_VERSION),
736
737 SLE_CONDVAR(Vehicle, current_order_time, SLE_FILE_U32 | SLE_VAR_I32, SLV_67, SLV_TIMETABLE_TICKS_TYPE),
738 SLE_CONDVAR(Vehicle, current_order_time, SLE_INT32, SLV_TIMETABLE_TICKS_TYPE, SL_MAX_VERSION),
739 SLE_CONDVAR(Vehicle, last_loading_tick, SLE_UINT64, SLV_LAST_LOADING_TICK, SL_MAX_VERSION),
740 SLE_CONDVAR(Vehicle, lateness_counter, SLE_INT32, SLV_67, SL_MAX_VERSION),
741
742 SLE_CONDVAR(Vehicle, depot_unbunching_last_departure, SLE_UINT64, SLV_DEPOT_UNBUNCHING, SL_MAX_VERSION),
743 SLE_CONDVAR(Vehicle, depot_unbunching_next_departure, SLE_UINT64, SLV_DEPOT_UNBUNCHING, SL_MAX_VERSION),
744 SLE_CONDVAR(Vehicle, round_trip_time, SLE_INT32, SLV_DEPOT_UNBUNCHING, SL_MAX_VERSION),
745 };
746 #if defined(_MSC_VER) && (_MSC_VER == 1915 || _MSC_VER == 1916)
747 return description;
748 }
749 #endif
750 inline const static SaveLoadCompatTable compat_description = _vehicle_common_sl_compat;
751
752 void Save(Vehicle *v) const override
753 {
754 SlObject(v, this->GetDescription());
755 }
756
757 void Load(Vehicle *v) const override
758 {
759 SlObject(v, this->GetLoadDescription());
760 }
761
762 void FixPointers(Vehicle *v) const override
763 {
764 SlObject(v, this->GetDescription());
765 }
766 };
767
768 class SlVehicleTrain : public DefaultSaveLoadHandler<SlVehicleTrain, Vehicle> {
769 public:
770 inline static const SaveLoad description[] = {
771 SLEG_STRUCT("common", SlVehicleCommon),
772 SLE_VAR(Train, crash_anim_pos, SLE_UINT16),
773 SLE_VAR(Train, force_proceed, SLE_UINT8),
774 SLE_VAR(Train, railtype, SLE_UINT8),
775 SLE_VAR(Train, track, SLE_UINT8),
776
777 SLE_CONDVAR(Train, flags, SLE_FILE_U8 | SLE_VAR_U16, SLV_2, SLV_100),
778 SLE_CONDVAR(Train, flags, SLE_UINT16, SLV_100, SL_MAX_VERSION),
779 SLE_CONDVAR(Train, wait_counter, SLE_UINT16, SLV_136, SL_MAX_VERSION),
780 SLE_CONDVAR(Train, gv_flags, SLE_UINT16, SLV_139, SL_MAX_VERSION),
781 };
782 inline const static SaveLoadCompatTable compat_description = _vehicle_train_sl_compat;
783
784 void Save(Vehicle *v) const override
785 {
786 if (v->type != VEH_TRAIN) return;
787 SlObject(v, this->GetDescription());
788 }
789
790 void Load(Vehicle *v) const override
791 {
792 if (v->type != VEH_TRAIN) return;
793 SlObject(v, this->GetLoadDescription());
794 }
795
796 void FixPointers(Vehicle *v) const override
797 {
798 if (v->type != VEH_TRAIN) return;
799 SlObject(v, this->GetDescription());
800 }
801 };
802
803 class SlVehicleRoadVeh : public DefaultSaveLoadHandler<SlVehicleRoadVeh, Vehicle> {
804 public:
805 inline static const SaveLoad description[] = {
806 SLEG_STRUCT("common", SlVehicleCommon),
807 SLE_VAR(RoadVehicle, state, SLE_UINT8),
808 SLE_VAR(RoadVehicle, frame, SLE_UINT8),
809 SLE_VAR(RoadVehicle, blocked_ctr, SLE_UINT16),
810 SLE_VAR(RoadVehicle, overtaking, SLE_UINT8),
811 SLE_VAR(RoadVehicle, overtaking_ctr, SLE_UINT8),
812 SLE_VAR(RoadVehicle, crashed_ctr, SLE_UINT16),
813 SLE_VAR(RoadVehicle, reverse_ctr, SLE_UINT8),
814 SLE_CONDDEQUE(RoadVehicle, path.td, SLE_UINT8, SLV_ROADVEH_PATH_CACHE, SL_MAX_VERSION),
815 SLE_CONDDEQUE(RoadVehicle, path.tile, SLE_UINT32, SLV_ROADVEH_PATH_CACHE, SL_MAX_VERSION),
816 SLE_CONDVAR(RoadVehicle, gv_flags, SLE_UINT16, SLV_139, SL_MAX_VERSION),
817 };
818 inline const static SaveLoadCompatTable compat_description = _vehicle_roadveh_sl_compat;
819
820 void Save(Vehicle *v) const override
821 {
822 if (v->type != VEH_ROAD) return;
823 SlObject(v, this->GetDescription());
824 }
825
826 void Load(Vehicle *v) const override
827 {
828 if (v->type != VEH_ROAD) return;
829 SlObject(v, this->GetLoadDescription());
830 }
831
832 void FixPointers(Vehicle *v) const override
833 {
834 if (v->type != VEH_ROAD) return;
835 SlObject(v, this->GetDescription());
836 }
837 };
838
839 class SlVehicleShip : public DefaultSaveLoadHandler<SlVehicleShip, Vehicle> {
840 public:
841 inline static const SaveLoad description[] = {
842 SLEG_STRUCT("common", SlVehicleCommon),
843 SLE_VAR(Ship, state, SLE_UINT8),
844 SLE_CONDDEQUE(Ship, path, SLE_UINT8, SLV_SHIP_PATH_CACHE, SL_MAX_VERSION),
845 SLE_CONDVAR(Ship, rotation, SLE_UINT8, SLV_SHIP_ROTATION, SL_MAX_VERSION),
846 };
847 inline const static SaveLoadCompatTable compat_description = _vehicle_ship_sl_compat;
848
849 void Save(Vehicle *v) const override
850 {
851 if (v->type != VEH_SHIP) return;
852 SlObject(v, this->GetDescription());
853 }
854
855 void Load(Vehicle *v) const override
856 {
857 if (v->type != VEH_SHIP) return;
858 SlObject(v, this->GetLoadDescription());
859 }
860
861 void FixPointers(Vehicle *v) const override
862 {
863 if (v->type != VEH_SHIP) return;
864 SlObject(v, this->GetDescription());
865 }
866 };
867
868 class SlVehicleAircraft : public DefaultSaveLoadHandler<SlVehicleAircraft, Vehicle> {
869 public:
870 inline static const SaveLoad description[] = {
871 SLEG_STRUCT("common", SlVehicleCommon),
872 SLE_VAR(Aircraft, crashed_counter, SLE_UINT16),
873 SLE_VAR(Aircraft, pos, SLE_UINT8),
874
875 SLE_CONDVAR(Aircraft, targetairport, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_5),
876 SLE_CONDVAR(Aircraft, targetairport, SLE_UINT16, SLV_5, SL_MAX_VERSION),
877
878 SLE_VAR(Aircraft, state, SLE_UINT8),
879
880 SLE_CONDVAR(Aircraft, previous_pos, SLE_UINT8, SLV_2, SL_MAX_VERSION),
881 SLE_CONDVAR(Aircraft, last_direction, SLE_UINT8, SLV_2, SL_MAX_VERSION),
882 SLE_CONDVAR(Aircraft, number_consecutive_turns, SLE_UINT8, SLV_2, SL_MAX_VERSION),
883
884 SLE_CONDVAR(Aircraft, turn_counter, SLE_UINT8, SLV_136, SL_MAX_VERSION),
885 SLE_CONDVAR(Aircraft, flags, SLE_UINT8, SLV_167, SL_MAX_VERSION),
886 };
887 inline const static SaveLoadCompatTable compat_description = _vehicle_aircraft_sl_compat;
888
889 void Save(Vehicle *v) const override
890 {
891 if (v->type != VEH_AIRCRAFT) return;
892 SlObject(v, this->GetDescription());
893 }
894
895 void Load(Vehicle *v) const override
896 {
897 if (v->type != VEH_AIRCRAFT) return;
898 SlObject(v, this->GetLoadDescription());
899 }
900
901 void FixPointers(Vehicle *v) const override
902 {
903 if (v->type != VEH_AIRCRAFT) return;
904 SlObject(v, this->GetDescription());
905 }
906 };
907
908 class SlVehicleEffect : public DefaultSaveLoadHandler<SlVehicleEffect, Vehicle> {
909 public:
910 inline static const SaveLoad description[] = {
911 SLE_VAR(Vehicle, subtype, SLE_UINT8),
912
913 SLE_CONDVAR(Vehicle, tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
914 SLE_CONDVAR(Vehicle, tile, SLE_UINT32, SLV_6, SL_MAX_VERSION),
915
916 SLE_CONDVAR(Vehicle, x_pos, SLE_FILE_I16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_6),
917 SLE_CONDVAR(Vehicle, x_pos, SLE_INT32, SLV_6, SL_MAX_VERSION),
918 SLE_CONDVAR(Vehicle, y_pos, SLE_FILE_I16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_6),
919 SLE_CONDVAR(Vehicle, y_pos, SLE_INT32, SLV_6, SL_MAX_VERSION),
920 SLE_CONDVAR(Vehicle, z_pos, SLE_FILE_U8 | SLE_VAR_I32, SL_MIN_VERSION, SLV_164),
921 SLE_CONDVAR(Vehicle, z_pos, SLE_INT32, SLV_164, SL_MAX_VERSION),
922
923 SLE_VAR(Vehicle, sprite_cache.sprite_seq.seq[0].sprite, SLE_FILE_U16 | SLE_VAR_U32),
924 SLE_VAR(Vehicle, progress, SLE_UINT8),
925 SLE_VAR(Vehicle, vehstatus, SLE_UINT8),
926
927 SLE_VAR(EffectVehicle, animation_state, SLE_UINT16),
928 SLE_VAR(EffectVehicle, animation_substate, SLE_UINT8),
929
930 SLE_CONDVAR(Vehicle, spritenum, SLE_UINT8, SLV_2, SL_MAX_VERSION),
931 };
932 inline const static SaveLoadCompatTable compat_description = _vehicle_effect_sl_compat;
933
934 void Save(Vehicle *v) const override
935 {
936 if (v->type != VEH_EFFECT) return;
937 SlObject(v, this->GetDescription());
938 }
939
940 void Load(Vehicle *v) const override
941 {
942 if (v->type != VEH_EFFECT) return;
943 SlObject(v, this->GetLoadDescription());
944 }
945
946 void FixPointers(Vehicle *v) const override
947 {
948 if (v->type != VEH_EFFECT) return;
949 SlObject(v, this->GetDescription());
950 }
951 };
952
953 class SlVehicleDisaster : public DefaultSaveLoadHandler<SlVehicleDisaster, Vehicle> {
954 public:
955 #if defined(_MSC_VER) && (_MSC_VER == 1915 || _MSC_VER == 1916)
956 /* This table access private members of other classes; they have this
957 * class as friend. For MSVC CL 19.15 and 19.16 this doesn't work for
958 * "inline static const", so we are forced to wrap the table in a
959 * function. CL 19.16 is the latest for VS2017. */
960 inline static const SaveLoad description[] = {{}};
961 SaveLoadTable GetDescription() const override {
962 #else
963 inline
964 #endif
965 static const SaveLoad description[] = {
966 SLE_REF(Vehicle, next, REF_VEHICLE_OLD),
967
968 SLE_VAR(Vehicle, subtype, SLE_UINT8),
969 SLE_CONDVAR(Vehicle, tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
970 SLE_CONDVAR(Vehicle, tile, SLE_UINT32, SLV_6, SL_MAX_VERSION),
971 SLE_CONDVAR(Vehicle, dest_tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
972 SLE_CONDVAR(Vehicle, dest_tile, SLE_UINT32, SLV_6, SL_MAX_VERSION),
973
974 SLE_CONDVAR(Vehicle, x_pos, SLE_FILE_I16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_6),
975 SLE_CONDVAR(Vehicle, x_pos, SLE_INT32, SLV_6, SL_MAX_VERSION),
976 SLE_CONDVAR(Vehicle, y_pos, SLE_FILE_I16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_6),
977 SLE_CONDVAR(Vehicle, y_pos, SLE_INT32, SLV_6, SL_MAX_VERSION),
978 SLE_CONDVAR(Vehicle, z_pos, SLE_FILE_U8 | SLE_VAR_I32, SL_MIN_VERSION, SLV_164),
979 SLE_CONDVAR(Vehicle, z_pos, SLE_INT32, SLV_164, SL_MAX_VERSION),
980 SLE_VAR(Vehicle, direction, SLE_UINT8),
981
982 SLE_VAR(Vehicle, owner, SLE_UINT8),
983 SLE_VAR(Vehicle, vehstatus, SLE_UINT8),
984 SLE_CONDVARNAME(DisasterVehicle, state, "current_order.dest", SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_5),
985 SLE_CONDVARNAME(DisasterVehicle, state, "current_order.dest", SLE_UINT16, SLV_5, SLV_DISASTER_VEH_STATE),
986 SLE_CONDVAR(DisasterVehicle, state, SLE_UINT16, SLV_DISASTER_VEH_STATE, SL_MAX_VERSION),
987
988 SLE_VAR(Vehicle, sprite_cache.sprite_seq.seq[0].sprite, SLE_FILE_U16 | SLE_VAR_U32),
989 SLE_CONDVAR(Vehicle, age, SLE_FILE_U16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_31),
990 SLE_CONDVAR(Vehicle, age, SLE_INT32, SLV_31, SL_MAX_VERSION),
991 SLE_VAR(Vehicle, tick_counter, SLE_UINT8),
992
993 SLE_CONDVAR(DisasterVehicle, image_override, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_191),
994 SLE_CONDVAR(DisasterVehicle, image_override, SLE_UINT32, SLV_191, SL_MAX_VERSION),
995 SLE_CONDVAR(DisasterVehicle, big_ufo_destroyer_target, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_191),
996 SLE_CONDVAR(DisasterVehicle, big_ufo_destroyer_target, SLE_UINT32, SLV_191, SL_MAX_VERSION),
997 SLE_CONDVAR(DisasterVehicle, flags, SLE_UINT8, SLV_194, SL_MAX_VERSION),
998 };
999 #if defined(_MSC_VER) && (_MSC_VER == 1915 || _MSC_VER == 1916)
1000 return description;
1001 }
1002 #endif
1003 inline const static SaveLoadCompatTable compat_description = _vehicle_disaster_sl_compat;
1004
1005 void Save(Vehicle *v) const override
1006 {
1007 if (v->type != VEH_DISASTER) return;
1008 SlObject(v, this->GetDescription());
1009 }
1010
1011 void Load(Vehicle *v) const override
1012 {
1013 if (v->type != VEH_DISASTER) return;
1014 SlObject(v, this->GetLoadDescription());
1015 }
1016
1017 void FixPointers(Vehicle *v) const override
1018 {
1019 if (v->type != VEH_DISASTER) return;
1020 SlObject(v, this->GetDescription());
1021 }
1022 };
1023
1024 const static SaveLoad _vehicle_desc[] = {
1025 SLE_SAVEBYTE(Vehicle, type),
1026 SLEG_STRUCT("train", SlVehicleTrain),
1027 SLEG_STRUCT("roadveh", SlVehicleRoadVeh),
1028 SLEG_STRUCT("ship", SlVehicleShip),
1029 SLEG_STRUCT("aircraft", SlVehicleAircraft),
1030 SLEG_STRUCT("effect", SlVehicleEffect),
1031 SLEG_STRUCT("disaster", SlVehicleDisaster),
1032 };
1033
1034 struct VEHSChunkHandler : ChunkHandler {
1035 VEHSChunkHandler() : ChunkHandler('VEHS', CH_SPARSE_TABLE) {}
1036
1037 void Save() const override
1038 {
1039 SlTableHeader(_vehicle_desc);
1040
1041 /* Write the vehicles */
1042 for (Vehicle *v : Vehicle::Iterate()) {
1043 SlSetArrayIndex(v->index);
1044 SlObject(v, _vehicle_desc);
1045 }
1046 }
1047
1048 void Load() const override
1049 {
1050 const std::vector<SaveLoad> slt = SlCompatTableHeader(_vehicle_desc, _vehicle_sl_compat);
1051
1052 int index;
1053
1054 _cargo_count = 0;
1055
1056 while ((index = SlIterateArray()) != -1) {
1057 Vehicle *v;
1058 VehicleType vtype = (VehicleType)SlReadByte();
1059
1060 switch (vtype) {
1061 case VEH_TRAIN: v = new (index) Train(); break;
1062 case VEH_ROAD: v = new (index) RoadVehicle(); break;
1063 case VEH_SHIP: v = new (index) Ship(); break;
1064 case VEH_AIRCRAFT: v = new (index) Aircraft(); break;
1065 case VEH_EFFECT: v = new (index) EffectVehicle(); break;
1066 case VEH_DISASTER: v = new (index) DisasterVehicle(); break;
1067 case VEH_INVALID: // Savegame shouldn't contain invalid vehicles
1068 default: SlErrorCorrupt("Invalid vehicle type");
1069 }
1070
1071 SlObject(v, slt);
1072
1073 if (_cargo_count != 0 && IsCompanyBuildableVehicleType(v) && CargoPacket::CanAllocateItem()) {
1074 /* Don't construct the packet with station here, because that'll fail with old savegames */
1075 CargoPacket *cp = new CargoPacket(_cargo_count, _cargo_periods, _cargo_source, _cargo_source_xy, _cargo_feeder_share);
1076 v->cargo.Append(cp);
1077 }
1078
1079 /* Old savegames used 'last_station_visited = 0xFF' */
1080 if (IsSavegameVersionBefore(SLV_5) && v->last_station_visited == 0xFF) {
1081 v->last_station_visited = INVALID_STATION;
1082 }
1083
1084 if (IsSavegameVersionBefore(SLV_182)) v->last_loading_station = INVALID_STATION;
1085
1086 if (IsSavegameVersionBefore(SLV_5)) {
1087 /* Convert the current_order.type (which is a mix of type and flags, because
1088 * in those versions, they both were 4 bits big) to type and flags */
1089 v->current_order.flags = GB(v->current_order.type, 4, 4);
1090 v->current_order.type &= 0x0F;
1091 }
1092
1093 /* Advanced vehicle lists got added */
1094 if (IsSavegameVersionBefore(SLV_60)) v->group_id = DEFAULT_GROUP;
1095 }
1096 }
1097
1098 void FixPointers() const override
1099 {
1100 for (Vehicle *v : Vehicle::Iterate()) {
1101 SlObject(v, _vehicle_desc);
1102 }
1103 }
1104 };
1105
1106 static const VEHSChunkHandler VEHS;
1107 static const ChunkHandlerRef veh_chunk_handlers[] = {
1108 VEHS,
1109 };
1110
1111 extern const ChunkHandlerTable _veh_chunk_handlers(veh_chunk_handlers);
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:1160
RoadVehicle
Buses, trucks and trams belong to this class.
Definition: roadveh.h:106
Vehicle::IsFrontEngine
debug_inline bool IsFrontEngine() const
Check if the vehicle is a front engine.
Definition: vehicle_base.h:931
INVALID_ENGINE
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
Definition: engine_type.h:205
REF_ORDER
@ REF_ORDER
Load/save a reference to an order.
Definition: saveload.h:580
ConnectMultiheadedTrains
void ConnectMultiheadedTrains()
Link front and rear multiheaded engines to each other This is done when loading a savegame.
Definition: vehicle_sl.cpp:34
SlVehicleShip
Definition: vehicle_sl.cpp:839
vehicle_sl_compat.h
AircraftNextAirportPos_and_Order
void AircraftNextAirportPos_and_Order(Aircraft *v)
set the right pos when heading to other airports after takeoff
Definition: aircraft_cmd.cpp:1440
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:186
DefaultSaveLoadHandler
Default handler for saving/loading an object to/from disk.
Definition: saveload.h:560
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
SLV_5
@ SLV_5
5.0 1429 5.1 1440 5.2 1525 0.3.6
Definition: saveload.h:43
Order::IsType
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition: order_base.h:71
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:335
MutableSpriteCache::sprite_seq
VehicleSpriteSeq sprite_seq
Vehicle appearance.
Definition: vehicle_base.h:196
VehicleSpriteSeq::CopyWithoutPalette
void CopyWithoutPalette(const VehicleSpriteSeq &src)
Copy data from another sprite sequence, while dropping all recolouring information.
Definition: vehicle_base.h:174
SLV_60
@ SLV_60
60 9874
Definition: saveload.h:115
SlVehicleAircraft
Definition: vehicle_sl.cpp:868
SaveLoadTable
std::span< const struct SaveLoad > SaveLoadTable
A table of SaveLoad entries.
Definition: saveload.h:494
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
FixupTrainLengths
void FixupTrainLengths()
Fixup old train spacing.
Definition: vehicle_sl.cpp:515
INVALID_COORD
static const int32_t INVALID_COORD
Sentinel for an invalid coordinate.
Definition: vehicle_base.h:1287
Vehicle::Next
Vehicle * Next() const
Get the next vehicle of this vehicle.
Definition: vehicle_base.h:627
SpecializedVehicle::Next
T * Next() const
Get next vehicle in the chain.
Definition: vehicle_base.h:1116
SLE_CONDSSTR
#define SLE_CONDSSTR(base, variable, type, from, to)
Storage of a std::string in some savegame versions.
Definition: saveload.h:909
Station
Station data structure.
Definition: station_base.h:442
ChunkHandlerRef
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
Definition: saveload.h:488
SLE_CONDVARNAME
#define SLE_CONDVARNAME(base, variable, name, type, from, to)
Storage of a variable in some savegame versions.
Definition: saveload.h:855
SLE_CONDARR
#define SLE_CONDARR(base, variable, type, length, from, to)
Storage of a fixed-size array of SL_VAR elements in some savegame versions.
Definition: saveload.h:876
SL_MIN_VERSION
@ SL_MIN_VERSION
First savegame version.
Definition: saveload.h:31
SLV_194
@ SLV_194
194 26881 v1.5
Definition: saveload.h:276
Vehicle::vehstatus
byte vehstatus
Status.
Definition: vehicle_base.h:348
GB
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
SLV_105
@ SLV_105
105 14803
Definition: saveload.h:169
SlVehicleTrain
Definition: vehicle_sl.cpp:768
SLE_CONDVAR
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Definition: saveload.h:844
SLV_EXTEND_VEHICLE_RANDOM
@ SLV_EXTEND_VEHICLE_RANDOM
310 PR#10701 Extend vehicle random bits.
Definition: saveload.h:352
SlErrorCorrupt
void SlErrorCorrupt(const std::string &msg)
Error handler for corrupt savegames.
Definition: saveload.cpp:362
_age_cargo_skip_counter
byte _age_cargo_skip_counter
Skip aging of cargo? Used before savegame version 162.
Definition: misc_sl.cpp:80
Vehicle::group_id
GroupID group_id
Index of group Pool array.
Definition: vehicle_base.h:357
SLV_51
@ SLV_51
51 8978
Definition: saveload.h:104
CompanySettings::vehicle
VehicleDefaultSettings vehicle
default settings for vehicles
Definition: settings_type.h:613
SLV_67
@ SLV_67
67 10236
Definition: saveload.h:123
SaveLoadHandler::GetLoadDescription
SaveLoadTable GetLoadDescription() const
Get the description for how to load the chunk.
Definition: saveload.cpp:3246
saveload.h
AircraftLeaveHangar
void AircraftLeaveHangar(Aircraft *v, Direction exit_dir)
Aircraft is about to leave the hangar.
Definition: aircraft_cmd.cpp:1460
SaveLoadCompatTable
std::span< const struct SaveLoadCompat > SaveLoadCompatTable
A table of SaveLoadCompat entries.
Definition: saveload.h:497
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:1627
RoadVehicle::roadtype
RoadType roadtype
Roadtype of this vehicle.
Definition: roadveh.h:116
Engine
Definition: engine_base.h:37
SLV_8
@ SLV_8
8.0 1786
Definition: saveload.h:49
Order::type
uint8_t type
The type of order + non-stop flags.
Definition: order_base.h:48
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
ChunkHandler
Handlers and description of chunk.
Definition: saveload.h:442
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:240
VEHSChunkHandler
Definition: vehicle_sl.cpp:1034
_vehicle_common_sl_compat
const SaveLoadCompat _vehicle_common_sl_compat[]
Original field order for SlVehicleCommon.
Definition: vehicle_sl_compat.h:16
SLV_36
@ SLV_36
36 6624
Definition: saveload.h:86
SLV_LAST_LOADING_TICK
@ SLV_LAST_LOADING_TICK
301 PR#9693 Store tick of last loading for vehicles.
Definition: saveload.h:341
SLV_167
@ SLV_167
167 23504
Definition: saveload.h:243
_vehicle_disaster_sl_compat
const SaveLoadCompat _vehicle_disaster_sl_compat[]
Original field order for SlVehicleDisaster.
Definition: vehicle_sl_compat.h:174
HANGAR
@ HANGAR
Heading for hangar.
Definition: airport.h:62
INVALID_ROADTYPE
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition: road_type.h:30
GroundVehicleCache::last_speed
uint16_t last_speed
The last speed we did display, so we only have to redraw when this changes.
Definition: ground_vehicle.hpp:47
GroundVehicle::ClearEngine
void ClearEngine()
Clear engine status.
Definition: ground_vehicle.hpp:283
SLV_174
@ SLV_174
174 23973 1.2.x
Definition: saveload.h:251
TrackToTrackBits
TrackBits TrackToTrackBits(Track track)
Maps a Track to the corresponding TrackBits value.
Definition: track_func.h:77
_vehicle_effect_sl_compat
const SaveLoadCompat _vehicle_effect_sl_compat[]
Original field order for SlVehicleEffect.
Definition: vehicle_sl_compat.h:157
SLV_6
@ SLV_6
6.0 1721 6.1 1768
Definition: saveload.h:46
SLE_REF
#define SLE_REF(base, variable, type)
Storage of a reference in every version of a savegame.
Definition: saveload.h:965
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:310
UpdateOldAircraft
void UpdateOldAircraft()
need to be called to load aircraft from old version
Definition: vehicle_sl.cpp:164
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:238
SlVehicleCommon
Definition: vehicle_sl.cpp:606
Pool::PoolItem<&_engine_pool >::GetPoolSize
static size_t GetPoolSize()
Returns first unused index.
Definition: pool_type.hpp:356
VS_HIDDEN
@ VS_HIDDEN
Vehicle is not visible.
Definition: vehicle_base.h:33
RailVehicleInfo
Information about a rail vehicle.
Definition: engine_type.h:42
RoadTypeInfo::powered_roadtypes
RoadTypes powered_roadtypes
bitmask to the OTHER roadtypes on which a vehicle of THIS roadtype generates power
Definition: road.h:122
SLF_ALLOW_CONTROL
@ SLF_ALLOW_CONTROL
Allow control codes in the strings.
Definition: saveload.h:667
SLV_TIMETABLE_TICKS_TYPE
@ SLV_TIMETABLE_TICKS_TYPE
323 PR#11435 Convert timetable current order time to ticks.
Definition: saveload.h:367
SLV_180
@ SLV_180
180 24998 1.3.x
Definition: saveload.h:259
GetRailDepotTrack
Track GetRailDepotTrack(Tile t)
Returns the track of a depot, ignoring direction.
Definition: rail_map.h:182
SLV_162
@ SLV_162
162 22713
Definition: saveload.h:237
SLV_SHIP_PATH_CACHE
@ SLV_SHIP_PATH_CACHE
203 PR#7072 Add path cache for ships
Definition: saveload.h:287
IsSavegameVersionBefore
bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor=0)
Checks whether the savegame is below major.
Definition: saveload.h:1203
Vehicle::tile
TileIndex tile
Current tile index.
Definition: vehicle_base.h:260
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:318
SLE_SAVEBYTE
#define SLE_SAVEBYTE(base, variable)
Only write byte during saving; never read it during loading.
Definition: saveload.h:1021
VS_CRASHED
@ VS_CRASHED
Vehicle is crashed.
Definition: vehicle_base.h:40
SLV_TIMETABLE_START_TICKS
@ SLV_TIMETABLE_START_TICKS
321 PR#11468 Convert timetable start from a date to ticks.
Definition: saveload.h:365
Vehicle::last_station_visited
StationID last_station_visited
The last station we stopped at.
Definition: vehicle_base.h:332
VehicleCargoList::Append
void Append(CargoPacket *cp, MoveToAction action=MTA_KEEP)
Appends the given cargo packet.
Definition: cargopacket.cpp:260
Vehicle::cargo
VehicleCargoList cargo
The cargo this vehicle is carrying.
Definition: vehicle_base.h:340
Vehicle::current_order
Order current_order
The current order (+ status, like: loading)
Definition: vehicle_base.h:349
GroundVehicle::gcache
GroundVehicleCache gcache
Cache of often calculated values.
Definition: ground_vehicle.hpp:80
VEH_EFFECT
@ VEH_EFFECT
Effect vehicle type (smoke, explosions, sparks, bubbles)
Definition: vehicle_type.h:31
Vehicle::cur_speed
uint16_t cur_speed
current speed
Definition: vehicle_base.h:323
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:55
IsCompanyBuildableVehicleType
bool IsCompanyBuildableVehicleType(VehicleType type)
Is the given vehicle type buildable by a company?
Definition: vehicle_func.h:89
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:724
CompanyProperties::settings
CompanySettings settings
settings specific for each company
Definition: company_base.h:105
AfterLoadVehicles
void AfterLoadVehicles(bool part_of_load)
Called after load to update coordinates.
Definition: vehicle_sl.cpp:255
SetAircraftPosition
void SetAircraftPosition(Aircraft *v, int x, int y, int z)
Set aircraft position.
Definition: aircraft_cmd.cpp:528
VS_STOPPED
@ VS_STOPPED
Vehicle is stopped by the player.
Definition: vehicle_base.h:34
SLV_182
@ SLV_182
182 25115 FS#5492, r25259, r25296 Goal status
Definition: saveload.h:261
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:333
Train
'Train' is either a loco or a wagon.
Definition: train.h:89
VEH_INVALID
@ VEH_INVALID
Non-existing type of vehicle.
Definition: vehicle_type.h:35
SLV_65
@ SLV_65
65 10210
Definition: saveload.h:121
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:865
SLV_31
@ SLV_31
31 5999
Definition: saveload.h:80
TrainController
bool TrainController(Train *v, Vehicle *nomove, bool reverse=true)
Move a vehicle chain one movement stop forwards.
Definition: train_cmd.cpp:3275
SL_MAX_VERSION
@ SL_MAX_VERSION
Highest possible saveload version.
Definition: saveload.h:379
VEHSChunkHandler::FixPointers
void FixPointers() const override
Fix the pointers.
Definition: vehicle_sl.cpp:1098
RoadVehicle::compatible_roadtypes
RoadTypes compatible_roadtypes
Roadtypes this consist is powered on.
Definition: roadveh.h:117
SLV_VEH_MOTION_COUNTER
@ SLV_VEH_MOTION_COUNTER
288 PR#8591 Desync safe motion counter
Definition: saveload.h:325
SLV_164
@ SLV_164
164 23290
Definition: saveload.h:239
REF_VEHICLE
@ REF_VEHICLE
Load/save a reference to a vehicle.
Definition: saveload.h:581
REF_CARGO_PACKET
@ REF_CARGO_PACKET
Load/save a reference to a cargo packet.
Definition: saveload.h:587
SLV_DISASTER_VEH_STATE
@ SLV_DISASTER_VEH_STATE
312 PR#10798 Explicit storage of disaster vehicle state.
Definition: saveload.h:354
REF_VEHICLE_OLD
@ REF_VEHICLE_OLD
Load/save an old-style reference to a vehicle (for pre-4.4 savegames).
Definition: saveload.h:584
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:363
_vehicle_ship_sl_compat
const SaveLoadCompat _vehicle_ship_sl_compat[]
Original field order for SlVehicleShip.
Definition: vehicle_sl_compat.h:133
CCF_SAVELOAD
@ CCF_SAVELOAD
Valid changes when loading a savegame. (Everything that is not stored in the save....
Definition: train.h:53
RAILVEH_WAGON
@ RAILVEH_WAGON
simple wagon, not motorized
Definition: engine_type.h:29
DisasterVehicle
Disasters, like submarines, skyrangers and their shadows, belong to this class.
Definition: disaster_vehicle.h:37
Order::flags
uint8_t flags
Load/unload types, depot order/action types.
Definition: order_base.h:49
SLV_181
@ SLV_181
181 25012
Definition: saveload.h:260
TrainForceProceeding
TrainForceProceeding
Modes for ignoring signals.
Definition: train.h:37
SLV_84
@ SLV_84
84 11822
Definition: saveload.h:143
TRACK_BIT_DEPOT
@ TRACK_BIT_DEPOT
Bitflag for a depot.
Definition: track_type.h:53
GetRoadTypeInfo
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition: road.h:227
UpdateAircraftCache
void UpdateAircraftCache(Aircraft *v, bool update_range=false)
Update cached values of an aircraft.
Definition: aircraft_cmd.cpp:597
VehicleSettings::roadveh_acceleration_model
uint8_t roadveh_acceleration_model
realistic acceleration for road vehicles
Definition: settings_type.h:519
Vehicle::next_shared
Vehicle * next_shared
pointer to the next vehicle that shares the order
Definition: vehicle_base.h:248
SLV_35
@ SLV_35
35 6602
Definition: saveload.h:85
Ship
All ships have this type.
Definition: ship.h:24
SLV_45
@ SLV_45
45 8501
Definition: saveload.h:97
SlVehicleEffect
Definition: vehicle_sl.cpp:908
SLE_VAR
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
Definition: saveload.h:948
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:384
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:112
REF_ORDERLIST
@ REF_ORDERLIST
Load/save a reference to an orderlist.
Definition: saveload.h:588
SLV_ROADVEH_PATH_CACHE
@ SLV_ROADVEH_PATH_CACHE
211 PR#7261 Add path cache for road vehicles.
Definition: saveload.h:297
SLEG_CONDVAR
#define SLEG_CONDVAR(name, variable, type, from, to)
Storage of a global variable in some savegame versions.
Definition: saveload.h:1047
RoadVehUpdateCache
void RoadVehUpdateCache(RoadVehicle *v, bool same_length=false)
Update the cache of a road vehicle.
Definition: roadveh_cmd.cpp:219
GroundVehicle::ClearMultiheaded
void ClearMultiheaded()
Clear multiheaded engine property.
Definition: ground_vehicle.hpp:303
SpecializedVehicle< Train, Type >::From
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition: vehicle_base.h:1201
Train::ConsistChanged
void ConsistChanged(ConsistChangeFlags allowed_changes)
Recalculates the cached stuff of a train.
Definition: train_cmd.cpp:111
CompanyServiceInterval
int CompanyServiceInterval(const Company *c, VehicleType type)
Get the service interval for the given company and vehicle type.
Definition: company_cmd.cpp:1190
AIR_HELICOPTER
@ AIR_HELICOPTER
an helicopter
Definition: aircraft.h:31
DefaultSaveLoadHandler< SlVehicleCommon, Vehicle >::GetDescription
SaveLoadTable GetDescription() const override
Definition: saveload.h:562
SLV_157
@ SLV_157
157 21862
Definition: saveload.h:231
_vehicle_sl_compat
const SaveLoadCompat _vehicle_sl_compat[]
Original field order for vehicle_desc.
Definition: vehicle_sl_compat.h:197
OrderList
Shared order list linking together the linked list of orders and the list of vehicles sharing this or...
Definition: order_base.h:260
GroundVehicle::IsEngine
bool IsEngine() const
Check if a vehicle is an engine (can be first in a consist).
Definition: ground_vehicle.hpp:315
SLV_139
@ SLV_139
139 19346
Definition: saveload.h:209
Vehicle::cargo_payment
CargoPayment * cargo_payment
The cargo payment we're currently in.
Definition: vehicle_base.h:273
RAILVEH_MULTIHEAD
@ RAILVEH_MULTIHEAD
indicates a combination of two locomotives
Definition: engine_type.h:28
SLV_136
@ SLV_136
136 18764
Definition: saveload.h:206
SlReadByte
byte SlReadByte()
Wrapper for reading a byte from the buffer.
Definition: saveload.cpp:403
SLV_2
@ SLV_2
2.0 0.3.0 2.1 0.3.1, 0.3.2
Definition: saveload.h:34
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:305
ChunkHandlerTable
std::span< const ChunkHandlerRef > ChunkHandlerTable
A table of ChunkHandler entries.
Definition: saveload.h:491
SLV_7
@ SLV_7
7.0 1770
Definition: saveload.h:48
EffectVehicle
A special vehicle is one of the following:
Definition: effectvehicle_base.h:24
SLV_40
@ SLV_40
40 7326
Definition: saveload.h:91
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:1270
SLE_CONDREFLIST
#define SLE_CONDREFLIST(base, variable, type, from, to)
Storage of a list of SL_REF elements in some savegame versions.
Definition: saveload.h:930
ReverseTrainDirection
void ReverseTrainDirection(Train *v)
Turn a train around.
Definition: train_cmd.cpp:1964
SLV_SHIP_ROTATION
@ SLV_SHIP_ROTATION
204 PR#7065 Add extra rotation stages for ships.
Definition: saveload.h:288
VEH_DISASTER
@ VEH_DISASTER
Disaster vehicle type.
Definition: vehicle_type.h:32
VehicleDefaultSettings::servint_ispercent
bool servint_ispercent
service intervals are in percents
Definition: settings_type.h:600
TicksToLeaveDepot
int TicksToLeaveDepot(const Train *v)
Compute number of ticks when next wagon will leave a depot.
Definition: rail_cmd.cpp:2928
CargoPacket
Container for cargo from the same location and time.
Definition: cargopacket.h:40
_vehicle_train_sl_compat
const SaveLoadCompat _vehicle_train_sl_compat[]
Original field order for SlVehicleTrain.
Definition: vehicle_sl_compat.h:99
SlVehicleRoadVeh
Definition: vehicle_sl.cpp:803
OverflowSafeInt< int64_t >
TFP_SIGNAL
@ TFP_SIGNAL
Ignore next signal, after the signal ignore being stuck.
Definition: train.h:40
SLV_NEWGRF_LAST_SERVICE
@ SLV_NEWGRF_LAST_SERVICE
317 PR#11124 Added stable date_of_last_service to avoid NewGRF trouble.
Definition: saveload.h:360
GroundVehicle::CargoChanged
void CargoChanged()
Recalculates the cached weight of a vehicle and its parts.
Definition: ground_vehicle.cpp:79
SlCompatTableHeader
std::vector< SaveLoad > SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct)
Load a table header in a savegame compatible way.
Definition: saveload.cpp:1843
SLV_68
@ SLV_68
68 10266
Definition: saveload.h:124
Vehicle::spritenum
byte spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
Definition: vehicle_base.h:310
SLV_129
@ SLV_129
129 18292
Definition: saveload.h:197
SlVehicleDisaster
Definition: vehicle_sl.cpp:953
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:627
EngineID
uint16_t EngineID
Unique identification number of an engine.
Definition: engine_type.h:21
CalcPercentVehicleFilled
uint8_t CalcPercentVehicleFilled(const Vehicle *front, StringID *colour)
Calculates how full a vehicle is.
Definition: vehicle.cpp:1475
GroundVehicle::IsFreeWagon
bool IsFreeWagon() const
Check if the vehicle is a free wagon (got no engine in front of it).
Definition: ground_vehicle.hpp:309
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:51
SlObject
void SlObject(void *object, const SaveLoadTable &slt)
Main SaveLoad function.
Definition: saveload.cpp:1652
SlTableHeader
std::vector< SaveLoad > SlTableHeader(const SaveLoadTable &slt)
Save or Load a table header.
Definition: saveload.cpp:1705
VEHSChunkHandler::Save
void Save() const override
Save the chunk.
Definition: vehicle_sl.cpp:1037
SLV_160
@ SLV_160
160 21974 1.1.x
Definition: saveload.h:235
SLE_CONDDEQUE
#define SLE_CONDDEQUE(base, variable, type, from, to)
Storage of a deque of SL_VAR elements in some savegame versions.
Definition: saveload.h:940
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:694
SLV_112
@ SLV_112
112 15290
Definition: saveload.h:177
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
Company
Definition: company_base.h:116
ClrBit
constexpr T ClrBit(T &x, const uint8_t y)
Clears a bit in a variable.
Definition: bitmath_func.hpp:151
SLV_100
@ SLV_100
100 13952
Definition: saveload.h:163
SLV_88
@ SLV_88
88 12134
Definition: saveload.h:148
SLV_DEPOT_UNBUNCHING
@ SLV_DEPOT_UNBUNCHING
330 PR#11945 Allow unbunching shared order vehicles at a depot.
Definition: saveload.h:377
VEHSChunkHandler::Load
void Load() const override
Load the chunk.
Definition: vehicle_sl.cpp:1048
SLV_44
@ SLV_44
44 8144
Definition: saveload.h:95
_vehicle_aircraft_sl_compat
const SaveLoadCompat _vehicle_aircraft_sl_compat[]
Original field order for SlVehicleAircraft.
Definition: vehicle_sl_compat.h:142
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:647
SLV_158
@ SLV_158
158 21933
Definition: saveload.h:232
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:224
GetStartTickFromDate
TimerGameTick::TickCounter GetStartTickFromDate(TimerGameEconomy::Date start_date)
Get the TimerGameTick::TickCounter tick of a given date.
Definition: timetable_cmd.cpp:29
GroundVehicle::IsMultiheaded
bool IsMultiheaded() const
Check if the vehicle is a multiheaded engine.
Definition: ground_vehicle.hpp:327
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:1759
_vehicle_roadveh_sl_compat
const SaveLoadCompat _vehicle_roadveh_sl_compat[]
Original field order for SlVehicleRoadVeh.
Definition: vehicle_sl_compat.h:114
SLEG_STRUCT
#define SLEG_STRUCT(name, handler)
Storage of a structs in every savegame version.
Definition: saveload.h:1155
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103