OpenTTD Source  13.2.1
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"
14 
15 #include "../vehicle_func.h"
16 #include "../train.h"
17 #include "../roadveh.h"
18 #include "../ship.h"
19 #include "../aircraft.h"
20 #include "../station_base.h"
21 #include "../effectvehicle_base.h"
22 #include "../company_base.h"
23 #include "../company_func.h"
24 #include "../disaster_vehicle.h"
25 
26 #include <map>
27 
28 #include "../safeguards.h"
29 
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 
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 
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
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
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 
211 static void CheckValidVehicles()
212 {
213  size_t total_engines = Engine::GetPoolSize();
215 
216  for (const Engine *e : Engine::IterateType(VEH_TRAIN)) { first_engine[VEH_TRAIN] = e->index; break; }
217  for (const Engine *e : Engine::IterateType(VEH_ROAD)) { first_engine[VEH_ROAD] = e->index; break; }
218  for (const Engine *e : Engine::IterateType(VEH_SHIP)) { first_engine[VEH_SHIP] = e->index; break; }
219  for (const Engine *e : Engine::IterateType(VEH_AIRCRAFT)) { first_engine[VEH_AIRCRAFT] = e->index; break; }
220 
221  for (Vehicle *v : Vehicle::Iterate()) {
222  /* Test if engine types match */
223  switch (v->type) {
224  case VEH_TRAIN:
225  case VEH_ROAD:
226  case VEH_SHIP:
227  case VEH_AIRCRAFT:
228  if (v->engine_type >= total_engines || v->type != v->GetEngine()->type) {
229  v->engine_type = first_engine[v->type];
230  }
231  break;
232 
233  default:
234  break;
235  }
236  }
237 }
238 
239 extern byte _age_cargo_skip_counter; // From misc_sl.cpp
240 
242 void AfterLoadVehicles(bool part_of_load)
243 {
244  for (Vehicle *v : Vehicle::Iterate()) {
245  /* Reinstate the previous pointer */
246  if (v->Next() != nullptr) v->Next()->previous = v;
247  if (v->NextShared() != nullptr) v->NextShared()->previous_shared = v;
248 
249  if (part_of_load) v->fill_percent_te_id = INVALID_TE_ID;
250  v->first = nullptr;
251  if (v->IsGroundVehicle()) v->GetGroundVehicleCache()->first_engine = INVALID_ENGINE;
252  }
253 
254  /* AfterLoadVehicles may also be called in case of NewGRF reload, in this
255  * case we may not convert orders again. */
256  if (part_of_load) {
257  /* Create shared vehicle chain for very old games (pre 5,2) and create
258  * OrderList from shared vehicle chains. For this to work correctly, the
259  * following conditions must be fulfilled:
260  * a) both next_shared and previous_shared are not set for pre 5,2 games
261  * b) both next_shared and previous_shared are set for later games
262  */
263  std::map<Order*, OrderList*> mapping;
264 
265  for (Vehicle *v : Vehicle::Iterate()) {
266  if (v->old_orders != nullptr) {
267  if (IsSavegameVersionBefore(SLV_105)) { // Pre-105 didn't save an OrderList
268  if (mapping[v->old_orders] == nullptr) {
269  /* This adds the whole shared vehicle chain for case b */
270 
271  /* Creating an OrderList here is safe because the number of vehicles
272  * allowed in these savegames matches the number of OrderLists. As
273  * such each vehicle can get an OrderList and it will (still) fit. */
274  assert(OrderList::CanAllocateItem());
275  v->orders = mapping[v->old_orders] = new OrderList(v->old_orders, v);
276  } else {
277  v->orders = mapping[v->old_orders];
278  /* For old games (case a) we must create the shared vehicle chain */
279  if (IsSavegameVersionBefore(SLV_5, 2)) {
280  v->AddToShared(v->orders->GetFirstSharedVehicle());
281  }
282  }
283  } else { // OrderList was saved as such, only recalculate not saved values
284  if (v->PreviousShared() == nullptr) {
285  v->orders->Initialize(v->orders->first, v);
286  }
287  }
288  }
289  }
290  }
291 
292  for (Vehicle *v : Vehicle::Iterate()) {
293  /* Fill the first pointers */
294  if (v->Previous() == nullptr) {
295  for (Vehicle *u = v; u != nullptr; u = u->Next()) {
296  u->first = v;
297  }
298  }
299  }
300 
301  if (part_of_load) {
303  /* Before 105 there was no order for shared orders, thus it messed up horribly */
304  for (Vehicle *v : Vehicle::Iterate()) {
305  if (v->First() != v || v->orders != nullptr || v->previous_shared != nullptr || v->next_shared == nullptr) continue;
306 
307  /* As above, allocating OrderList here is safe. */
308  assert(OrderList::CanAllocateItem());
309  v->orders = new OrderList(nullptr, v);
310  for (Vehicle *u = v; u != nullptr; u = u->next_shared) {
311  u->orders = v->orders;
312  }
313  }
314  }
315 
317  /* The road vehicle subtype was converted to a flag. */
318  for (RoadVehicle *rv : RoadVehicle::Iterate()) {
319  if (rv->subtype == 0) {
320  /* The road vehicle is at the front. */
321  rv->SetFrontEngine();
322  } else if (rv->subtype == 1) {
323  /* The road vehicle is an articulated part. */
324  rv->subtype = 0;
325  rv->SetArticulatedPart();
326  } else {
327  SlErrorCorrupt("Invalid road vehicle subtype");
328  }
329  }
330  }
331 
333  /* In some old savegames there might be some "crap" stored. */
334  for (Vehicle *v : Vehicle::Iterate()) {
335  if (!v->IsPrimaryVehicle() && v->type != VEH_DISASTER) {
336  v->current_order.Free();
337  v->unitnumber = 0;
338  }
339  }
340  }
341 
343  /* Set the vehicle-local cargo age counter from the old global counter. */
344  for (Vehicle *v : Vehicle::Iterate()) {
345  v->cargo_age_counter = _age_cargo_skip_counter;
346  }
347  }
348 
350  /* Set service interval flags */
351  for (Vehicle *v : Vehicle::Iterate()) {
352  if (!v->IsPrimaryVehicle()) continue;
353 
354  const Company *c = Company::Get(v->owner);
355  int interval = CompanyServiceInterval(c, v->type);
356 
357  v->SetServiceIntervalIsCustom(v->GetServiceInterval() != interval);
358  v->SetServiceIntervalIsPercent(c->settings.vehicle.servint_ispercent);
359  }
360  }
361 
363  /* Ship rotation added */
364  for (Ship *s : Ship::Iterate()) {
365  s->rotation = s->direction;
366  }
367  } else {
368  for (Ship *s : Ship::Iterate()) {
369  if (s->rotation == s->direction) continue;
370  /* In case we are rotating on gameload, set the rotation position to
371  * the current position, otherwise the applied workaround offset would
372  * be with respect to 0,0.
373  */
374  s->rotation_x_pos = s->x_pos;
375  s->rotation_y_pos = s->y_pos;
376  }
377  }
378  }
379 
381 
382  for (Vehicle *v : Vehicle::Iterate()) {
383  assert(v->first != nullptr);
384 
385  v->trip_occupancy = CalcPercentVehicleFilled(v, nullptr);
386 
387  switch (v->type) {
388  case VEH_TRAIN: {
389  Train *t = Train::From(v);
390  if (t->IsFrontEngine() || t->IsFreeWagon()) {
391  t->gcache.last_speed = t->cur_speed; // update displayed train speed
393  }
394  break;
395  }
396 
397  case VEH_ROAD: {
399  if (rv->IsFrontEngine()) {
400  rv->gcache.last_speed = rv->cur_speed; // update displayed road vehicle speed
401 
402  rv->roadtype = Engine::Get(rv->engine_type)->u.road.roadtype;
404  RoadTramType rtt = GetRoadTramType(rv->roadtype);
405  for (RoadVehicle *u = rv; u != nullptr; u = u->Next()) {
406  u->roadtype = rv->roadtype;
407  u->compatible_roadtypes = rv->compatible_roadtypes;
408  if (GetRoadType(u->tile, rtt) == INVALID_ROADTYPE) SlErrorCorrupt("Road vehicle on invalid road type");
409  }
410 
411  RoadVehUpdateCache(rv);
413  rv->CargoChanged();
414  }
415  }
416  break;
417  }
418 
419  case VEH_SHIP:
420  Ship::From(v)->UpdateCache();
421  break;
422 
423  default: break;
424  }
425  }
426 
427  /* Stop non-front engines */
428  if (part_of_load && IsSavegameVersionBefore(SLV_112)) {
429  for (Vehicle *v : Vehicle::Iterate()) {
430  if (v->type == VEH_TRAIN) {
431  Train *t = Train::From(v);
432  if (!t->IsFrontEngine()) {
433  if (t->IsEngine()) t->vehstatus |= VS_STOPPED;
434  /* cur_speed is now relevant for non-front parts - nonzero breaks
435  * moving-wagons-inside-depot- and autoreplace- code */
436  t->cur_speed = 0;
437  }
438  }
439  /* trains weren't stopping gradually in old OTTD versions (and TTO/TTD)
440  * other vehicle types didn't have zero speed while stopped (even in 'recent' OTTD versions) */
441  if ((v->vehstatus & VS_STOPPED) && (v->type != VEH_TRAIN || IsSavegameVersionBefore(SLV_2, 1))) {
442  v->cur_speed = 0;
443  }
444  }
445  }
446 
447  for (Vehicle *v : Vehicle::Iterate()) {
448  switch (v->type) {
449  case VEH_ROAD:
450  case VEH_TRAIN:
451  case VEH_SHIP:
452  v->GetImage(v->direction, EIT_ON_MAP, &v->sprite_cache.sprite_seq);
453  break;
454 
455  case VEH_AIRCRAFT:
456  if (Aircraft::From(v)->IsNormalAircraft()) {
457  v->GetImage(v->direction, EIT_ON_MAP, &v->sprite_cache.sprite_seq);
458 
459  /* The plane's shadow will have the same image as the plane, but no colour */
460  Vehicle *shadow = v->Next();
461  shadow->sprite_cache.sprite_seq.CopyWithoutPalette(v->sprite_cache.sprite_seq);
462 
463  /* In the case of a helicopter we will update the rotor sprites */
464  if (v->subtype == AIR_HELICOPTER) {
465  Vehicle *rotor = shadow->Next();
466  GetRotorImage(Aircraft::From(v), EIT_ON_MAP, &rotor->sprite_cache.sprite_seq);
467  }
468 
470  }
471  break;
472  default: break;
473  }
474 
475  v->UpdateDeltaXY();
476  v->coord.left = INVALID_COORD;
477  v->sprite_cache.old_coord.left = INVALID_COORD;
478  v->UpdatePosition();
479  v->UpdateViewport(false);
480  }
481 }
482 
483 bool TrainController(Train *v, Vehicle *nomove, bool reverse = true); // From train_cmd.cpp
485 void ReverseTrainSwapVeh(Train *v, int l, int r);
486 
489 {
490  /* Vehicle center was moved from 4 units behind the front to half the length
491  * behind the front. Move vehicles so they end up on the same spot. */
492  for (Vehicle *v : Vehicle::Iterate()) {
493  if (v->type == VEH_TRAIN && v->IsPrimaryVehicle()) {
494  /* The vehicle center is now more to the front depending on vehicle length,
495  * so we need to move all vehicles forward to cover the difference to the
496  * old center, otherwise wagon spacing in trains would be broken upon load. */
497  for (Train *u = Train::From(v); u != nullptr; u = u->Next()) {
498  if (u->track == TRACK_BIT_DEPOT || (u->vehstatus & VS_CRASHED)) continue;
499 
500  Train *next = u->Next();
501 
502  /* Try to pull the vehicle half its length forward. */
503  int diff = (VEHICLE_LENGTH - u->gcache.cached_veh_length) / 2;
504  int done;
505  for (done = 0; done < diff; done++) {
506  if (!TrainController(u, next, false)) break;
507  }
508 
509  if (next != nullptr && done < diff && u->IsFrontEngine()) {
510  /* Pulling the front vehicle forwards failed, we either encountered a dead-end
511  * or a red signal. To fix this, we try to move the whole train the required
512  * space backwards and re-do the fix up of the front vehicle. */
513 
514  /* Ignore any signals when backtracking. */
515  TrainForceProceeding old_tfp = u->force_proceed;
516  u->force_proceed = TFP_SIGNAL;
517 
518  /* Swap start<>end, start+1<>end-1, ... */
519  int r = CountVehiclesInChain(u) - 1; // number of vehicles - 1
520  int l = 0;
521  do ReverseTrainSwapVeh(u, l++, r--); while (l <= r);
522 
523  /* We moved the first vehicle which is now the last. Move it back to the
524  * original position as we will fix up the last vehicle later in the loop. */
525  for (int i = 0; i < done; i++) TrainController(u->Last(), nullptr);
526 
527  /* Move the train backwards to get space for the first vehicle. As the stopping
528  * distance from a line end is rounded up, move the train one unit more to cater
529  * for front vehicles with odd lengths. */
530  int moved;
531  for (moved = 0; moved < diff + 1; moved++) {
532  if (!TrainController(u, nullptr, false)) break;
533  }
534 
535  /* Swap start<>end, start+1<>end-1, ... again. */
536  r = CountVehiclesInChain(u) - 1; // number of vehicles - 1
537  l = 0;
538  do ReverseTrainSwapVeh(u, l++, r--); while (l <= r);
539 
540  u->force_proceed = old_tfp;
541 
542  /* Tracks are too short to fix the train length. The player has to fix the
543  * train in a depot. Bail out so we don't damage the vehicle chain any more. */
544  if (moved < diff + 1) break;
545 
546  /* Re-do the correction for the first vehicle. */
547  for (done = 0; done < diff; done++) TrainController(u, next, false);
548 
549  /* We moved one unit more backwards than needed for even-length front vehicles,
550  * try to move that unit forward again. We don't care if this step fails. */
551  TrainController(u, nullptr, false);
552  }
553 
554  /* If the next wagon is still in a depot, check if it shouldn't be outside already. */
555  if (next != nullptr && next->track == TRACK_BIT_DEPOT) {
556  int d = TicksToLeaveDepot(u);
557  if (d <= 0) {
558  /* Next vehicle should have left the depot already, show it and pull forward. */
559  next->vehstatus &= ~VS_HIDDEN;
560  next->track = TrackToTrackBits(GetRailDepotTrack(next->tile));
561  for (int i = 0; i >= d; i--) TrainController(next, nullptr);
562  }
563  }
564  }
565 
566  /* Update all cached properties after moving the vehicle chain around. */
568  }
569  }
570 }
571 
572 static uint8 _cargo_days;
573 static uint16 _cargo_source;
574 static uint32 _cargo_source_xy;
575 static uint16 _cargo_count;
576 static uint16 _cargo_paid_for;
577 static Money _cargo_feeder_share;
578 static uint32 _cargo_loaded_at_xy;
579 
580 class SlVehicleCommon : public DefaultSaveLoadHandler<SlVehicleCommon, Vehicle> {
581 public:
582 #if defined(_MSC_VER) && (_MSC_VER == 1915 || _MSC_VER == 1916)
583  /* This table access private members of other classes; they have this
584  * class as friend. For MSVC CL 19.15 and 19.16 this doesn't work for
585  * "inline static const", so we are forced to wrap the table in a
586  * function. CL 19.16 is the latest for VS2017. */
587  inline static const SaveLoad description[] = {{}};
588  SaveLoadTable GetDescription() const override {
589 #else
590  inline
591 #endif
592  static const SaveLoad description[] = {
593  SLE_VAR(Vehicle, subtype, SLE_UINT8),
594 
596  SLE_CONDVAR(Vehicle, name, SLE_NAME, SL_MIN_VERSION, SLV_84),
598  SLE_CONDVAR(Vehicle, unitnumber, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_8),
599  SLE_CONDVAR(Vehicle, unitnumber, SLE_UINT16, SLV_8, SL_MAX_VERSION),
600  SLE_VAR(Vehicle, owner, SLE_UINT8),
601  SLE_CONDVAR(Vehicle, tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
602  SLE_CONDVAR(Vehicle, tile, SLE_UINT32, SLV_6, SL_MAX_VERSION),
603  SLE_CONDVAR(Vehicle, dest_tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
604  SLE_CONDVAR(Vehicle, dest_tile, SLE_UINT32, SLV_6, SL_MAX_VERSION),
605 
606  SLE_CONDVAR(Vehicle, x_pos, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
607  SLE_CONDVAR(Vehicle, x_pos, SLE_UINT32, SLV_6, SL_MAX_VERSION),
608  SLE_CONDVAR(Vehicle, y_pos, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
609  SLE_CONDVAR(Vehicle, y_pos, SLE_UINT32, SLV_6, SL_MAX_VERSION),
610  SLE_CONDVAR(Vehicle, z_pos, SLE_FILE_U8 | SLE_VAR_I32, SL_MIN_VERSION, SLV_164),
611  SLE_CONDVAR(Vehicle, z_pos, SLE_INT32, SLV_164, SL_MAX_VERSION),
612  SLE_VAR(Vehicle, direction, SLE_UINT8),
613 
614  SLE_VAR(Vehicle, spritenum, SLE_UINT8),
615  SLE_VAR(Vehicle, engine_type, SLE_UINT16),
616  SLE_VAR(Vehicle, cur_speed, SLE_UINT16),
617  SLE_VAR(Vehicle, subspeed, SLE_UINT8),
618  SLE_VAR(Vehicle, acceleration, SLE_UINT8),
619  SLE_CONDVAR(Vehicle, motion_counter, SLE_UINT32, SLV_VEH_MOTION_COUNTER, SL_MAX_VERSION),
620  SLE_VAR(Vehicle, progress, SLE_UINT8),
621 
622  SLE_VAR(Vehicle, vehstatus, SLE_UINT8),
623  SLE_CONDVAR(Vehicle, last_station_visited, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_5),
624  SLE_CONDVAR(Vehicle, last_station_visited, SLE_UINT16, SLV_5, SL_MAX_VERSION),
625  SLE_CONDVAR(Vehicle, last_loading_station, SLE_UINT16, SLV_182, SL_MAX_VERSION),
626 
627  SLE_VAR(Vehicle, cargo_type, SLE_UINT8),
628  SLE_CONDVAR(Vehicle, cargo_subtype, SLE_UINT8, SLV_35, SL_MAX_VERSION),
629  SLEG_CONDVAR("cargo_days", _cargo_days, SLE_UINT8, SL_MIN_VERSION, SLV_68),
630  SLEG_CONDVAR("cargo_source", _cargo_source, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_7),
631  SLEG_CONDVAR("cargo_source", _cargo_source, SLE_UINT16, SLV_7, SLV_68),
632  SLEG_CONDVAR("cargo_source_xy", _cargo_source_xy, SLE_UINT32, SLV_44, SLV_68),
633  SLE_VAR(Vehicle, cargo_cap, SLE_UINT16),
634  SLE_CONDVAR(Vehicle, refit_cap, SLE_UINT16, SLV_182, SL_MAX_VERSION),
635  SLEG_CONDVAR("cargo_count", _cargo_count, SLE_UINT16, SL_MIN_VERSION, SLV_68),
637  SLE_CONDARR(Vehicle, cargo.action_counts, SLE_UINT, VehicleCargoList::NUM_MOVE_TO_ACTION, SLV_181, SL_MAX_VERSION),
638  SLE_CONDVAR(Vehicle, cargo_age_counter, SLE_UINT16, SLV_162, SL_MAX_VERSION),
639 
640  SLE_VAR(Vehicle, day_counter, SLE_UINT8),
641  SLE_VAR(Vehicle, tick_counter, SLE_UINT8),
642  SLE_CONDVAR(Vehicle, running_ticks, SLE_UINT8, SLV_88, SL_MAX_VERSION),
643 
644  SLE_VAR(Vehicle, cur_implicit_order_index, SLE_UINT8),
645  SLE_CONDVAR(Vehicle, cur_real_order_index, SLE_UINT8, SLV_158, SL_MAX_VERSION),
646 
647  /* This next line is for version 4 and prior compatibility.. it temporarily reads
648  type and flags (which were both 4 bits) into type. Later on this is
649  converted correctly */
650  SLE_CONDVAR(Vehicle, current_order.type, SLE_UINT8, SL_MIN_VERSION, SLV_5),
651  SLE_CONDVAR(Vehicle, current_order.dest, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_5),
652 
653  /* Orders for version 5 and on */
654  SLE_CONDVAR(Vehicle, current_order.type, SLE_UINT8, SLV_5, SL_MAX_VERSION),
655  SLE_CONDVAR(Vehicle, current_order.flags, SLE_UINT8, SLV_5, SL_MAX_VERSION),
656  SLE_CONDVAR(Vehicle, current_order.dest, SLE_UINT16, SLV_5, SL_MAX_VERSION),
657 
658  /* Refit in current order */
659  SLE_CONDVAR(Vehicle, current_order.refit_cargo, SLE_UINT8, SLV_36, SL_MAX_VERSION),
660 
661  /* Timetable in current order */
662  SLE_CONDVAR(Vehicle, current_order.wait_time, SLE_UINT16, SLV_67, SL_MAX_VERSION),
663  SLE_CONDVAR(Vehicle, current_order.travel_time, SLE_UINT16, SLV_67, SL_MAX_VERSION),
664  SLE_CONDVAR(Vehicle, current_order.max_speed, SLE_UINT16, SLV_174, SL_MAX_VERSION),
665  SLE_CONDVAR(Vehicle, timetable_start, SLE_INT32, SLV_129, SL_MAX_VERSION),
666 
669 
670  SLE_CONDVAR(Vehicle, age, SLE_FILE_U16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_31),
671  SLE_CONDVAR(Vehicle, age, SLE_INT32, SLV_31, SL_MAX_VERSION),
672  SLE_CONDVAR(Vehicle, max_age, SLE_FILE_U16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_31),
673  SLE_CONDVAR(Vehicle, max_age, SLE_INT32, SLV_31, SL_MAX_VERSION),
674  SLE_CONDVAR(Vehicle, date_of_last_service, SLE_FILE_U16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_31),
675  SLE_CONDVAR(Vehicle, date_of_last_service, SLE_INT32, SLV_31, SL_MAX_VERSION),
676  SLE_CONDVAR(Vehicle, service_interval, SLE_UINT16, SL_MIN_VERSION, SLV_31),
677  SLE_CONDVAR(Vehicle, service_interval, SLE_FILE_U32 | SLE_VAR_U16, SLV_31, SLV_180),
678  SLE_CONDVAR(Vehicle, service_interval, SLE_UINT16, SLV_180, SL_MAX_VERSION),
679  SLE_VAR(Vehicle, reliability, SLE_UINT16),
680  SLE_VAR(Vehicle, reliability_spd_dec, SLE_UINT16),
681  SLE_VAR(Vehicle, breakdown_ctr, SLE_UINT8),
682  SLE_VAR(Vehicle, breakdown_delay, SLE_UINT8),
683  SLE_VAR(Vehicle, breakdowns_since_last_service, SLE_UINT8),
684  SLE_VAR(Vehicle, breakdown_chance, SLE_UINT8),
685  SLE_CONDVAR(Vehicle, build_year, SLE_FILE_U8 | SLE_VAR_I32, SL_MIN_VERSION, SLV_31),
686  SLE_CONDVAR(Vehicle, build_year, SLE_INT32, SLV_31, SL_MAX_VERSION),
687 
688  SLE_VAR(Vehicle, load_unload_ticks, SLE_UINT16),
689  SLEG_CONDVAR("cargo_paid_for", _cargo_paid_for, SLE_UINT16, SLV_45, SL_MAX_VERSION),
690  SLE_CONDVAR(Vehicle, vehicle_flags, SLE_FILE_U8 | SLE_VAR_U16, SLV_40, SLV_180),
691  SLE_CONDVAR(Vehicle, vehicle_flags, SLE_UINT16, SLV_180, SL_MAX_VERSION),
692 
693  SLE_CONDVAR(Vehicle, profit_this_year, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_65),
694  SLE_CONDVAR(Vehicle, profit_this_year, SLE_INT64, SLV_65, SL_MAX_VERSION),
695  SLE_CONDVAR(Vehicle, profit_last_year, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_65),
696  SLE_CONDVAR(Vehicle, profit_last_year, SLE_INT64, SLV_65, SL_MAX_VERSION),
697  SLEG_CONDVAR("cargo_feeder_share", _cargo_feeder_share, SLE_FILE_I32 | SLE_VAR_I64, SLV_51, SLV_65),
698  SLEG_CONDVAR("cargo_feeder_share", _cargo_feeder_share, SLE_INT64, SLV_65, SLV_68),
699  SLEG_CONDVAR("cargo_loaded_at_xy", _cargo_loaded_at_xy, SLE_UINT32, SLV_51, SLV_68),
700  SLE_CONDVAR(Vehicle, value, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_65),
701  SLE_CONDVAR(Vehicle, value, SLE_INT64, SLV_65, SL_MAX_VERSION),
702 
703  SLE_CONDVAR(Vehicle, random_bits, SLE_UINT8, SLV_2, SL_MAX_VERSION),
704  SLE_CONDVAR(Vehicle, waiting_triggers, SLE_UINT8, SLV_2, SL_MAX_VERSION),
705 
707  SLE_CONDVAR(Vehicle, group_id, SLE_UINT16, SLV_60, SL_MAX_VERSION),
708 
709  SLE_CONDVAR(Vehicle, current_order_time, SLE_UINT32, SLV_67, SL_MAX_VERSION),
710  SLE_CONDVAR(Vehicle, last_loading_tick, SLE_UINT64, SLV_LAST_LOADING_TICK, SL_MAX_VERSION),
711  SLE_CONDVAR(Vehicle, lateness_counter, SLE_INT32, SLV_67, SL_MAX_VERSION),
712  };
713 #if defined(_MSC_VER) && (_MSC_VER == 1915 || _MSC_VER == 1916)
714  return description;
715  }
716 #endif
717  inline const static SaveLoadCompatTable compat_description = _vehicle_common_sl_compat;
718 
719  void Save(Vehicle *v) const override
720  {
721  SlObject(v, this->GetDescription());
722  }
723 
724  void Load(Vehicle *v) const override
725  {
726  SlObject(v, this->GetLoadDescription());
727  }
728 
729  void FixPointers(Vehicle *v) const override
730  {
731  SlObject(v, this->GetDescription());
732  }
733 };
734 
735 class SlVehicleTrain : public DefaultSaveLoadHandler<SlVehicleTrain, Vehicle> {
736 public:
737  inline static const SaveLoad description[] = {
738  SLEG_STRUCT("common", SlVehicleCommon),
739  SLE_VAR(Train, crash_anim_pos, SLE_UINT16),
740  SLE_VAR(Train, force_proceed, SLE_UINT8),
741  SLE_VAR(Train, railtype, SLE_UINT8),
742  SLE_VAR(Train, track, SLE_UINT8),
743 
744  SLE_CONDVAR(Train, flags, SLE_FILE_U8 | SLE_VAR_U16, SLV_2, SLV_100),
745  SLE_CONDVAR(Train, flags, SLE_UINT16, SLV_100, SL_MAX_VERSION),
746  SLE_CONDVAR(Train, wait_counter, SLE_UINT16, SLV_136, SL_MAX_VERSION),
747  SLE_CONDVAR(Train, gv_flags, SLE_UINT16, SLV_139, SL_MAX_VERSION),
748  };
749  inline const static SaveLoadCompatTable compat_description = _vehicle_train_sl_compat;
750 
751  void Save(Vehicle *v) const override
752  {
753  if (v->type != VEH_TRAIN) return;
754  SlObject(v, this->GetDescription());
755  }
756 
757  void Load(Vehicle *v) const override
758  {
759  if (v->type != VEH_TRAIN) return;
760  SlObject(v, this->GetLoadDescription());
761  }
762 
763  void FixPointers(Vehicle *v) const override
764  {
765  if (v->type != VEH_TRAIN) return;
766  SlObject(v, this->GetDescription());
767  }
768 };
769 
770 class SlVehicleRoadVeh : public DefaultSaveLoadHandler<SlVehicleRoadVeh, Vehicle> {
771 public:
772  inline static const SaveLoad description[] = {
773  SLEG_STRUCT("common", SlVehicleCommon),
774  SLE_VAR(RoadVehicle, state, SLE_UINT8),
775  SLE_VAR(RoadVehicle, frame, SLE_UINT8),
776  SLE_VAR(RoadVehicle, blocked_ctr, SLE_UINT16),
777  SLE_VAR(RoadVehicle, overtaking, SLE_UINT8),
778  SLE_VAR(RoadVehicle, overtaking_ctr, SLE_UINT8),
779  SLE_VAR(RoadVehicle, crashed_ctr, SLE_UINT16),
780  SLE_VAR(RoadVehicle, reverse_ctr, SLE_UINT8),
783  SLE_CONDVAR(RoadVehicle, gv_flags, SLE_UINT16, SLV_139, SL_MAX_VERSION),
784  };
785  inline const static SaveLoadCompatTable compat_description = _vehicle_roadveh_sl_compat;
786 
787  void Save(Vehicle *v) const override
788  {
789  if (v->type != VEH_ROAD) return;
790  SlObject(v, this->GetDescription());
791  }
792 
793  void Load(Vehicle *v) const override
794  {
795  if (v->type != VEH_ROAD) return;
796  SlObject(v, this->GetLoadDescription());
797  }
798 
799  void FixPointers(Vehicle *v) const override
800  {
801  if (v->type != VEH_ROAD) return;
802  SlObject(v, this->GetDescription());
803  }
804 };
805 
806 class SlVehicleShip : public DefaultSaveLoadHandler<SlVehicleShip, Vehicle> {
807 public:
808  inline static const SaveLoad description[] = {
809  SLEG_STRUCT("common", SlVehicleCommon),
810  SLE_VAR(Ship, state, SLE_UINT8),
812  SLE_CONDVAR(Ship, rotation, SLE_UINT8, SLV_SHIP_ROTATION, SL_MAX_VERSION),
813  };
814  inline const static SaveLoadCompatTable compat_description = _vehicle_ship_sl_compat;
815 
816  void Save(Vehicle *v) const override
817  {
818  if (v->type != VEH_SHIP) return;
819  SlObject(v, this->GetDescription());
820  }
821 
822  void Load(Vehicle *v) const override
823  {
824  if (v->type != VEH_SHIP) return;
825  SlObject(v, this->GetLoadDescription());
826  }
827 
828  void FixPointers(Vehicle *v) const override
829  {
830  if (v->type != VEH_SHIP) return;
831  SlObject(v, this->GetDescription());
832  }
833 };
834 
835 class SlVehicleAircraft : public DefaultSaveLoadHandler<SlVehicleAircraft, Vehicle> {
836 public:
837  inline static const SaveLoad description[] = {
838  SLEG_STRUCT("common", SlVehicleCommon),
839  SLE_VAR(Aircraft, crashed_counter, SLE_UINT16),
840  SLE_VAR(Aircraft, pos, SLE_UINT8),
841 
842  SLE_CONDVAR(Aircraft, targetairport, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_5),
843  SLE_CONDVAR(Aircraft, targetairport, SLE_UINT16, SLV_5, SL_MAX_VERSION),
844 
845  SLE_VAR(Aircraft, state, SLE_UINT8),
846 
847  SLE_CONDVAR(Aircraft, previous_pos, SLE_UINT8, SLV_2, SL_MAX_VERSION),
848  SLE_CONDVAR(Aircraft, last_direction, SLE_UINT8, SLV_2, SL_MAX_VERSION),
849  SLE_CONDVAR(Aircraft, number_consecutive_turns, SLE_UINT8, SLV_2, SL_MAX_VERSION),
850 
851  SLE_CONDVAR(Aircraft, turn_counter, SLE_UINT8, SLV_136, SL_MAX_VERSION),
852  SLE_CONDVAR(Aircraft, flags, SLE_UINT8, SLV_167, SL_MAX_VERSION),
853  };
854  inline const static SaveLoadCompatTable compat_description = _vehicle_aircraft_sl_compat;
855 
856  void Save(Vehicle *v) const override
857  {
858  if (v->type != VEH_AIRCRAFT) return;
859  SlObject(v, this->GetDescription());
860  }
861 
862  void Load(Vehicle *v) const override
863  {
864  if (v->type != VEH_AIRCRAFT) return;
865  SlObject(v, this->GetLoadDescription());
866  }
867 
868  void FixPointers(Vehicle *v) const override
869  {
870  if (v->type != VEH_AIRCRAFT) return;
871  SlObject(v, this->GetDescription());
872  }
873 };
874 
875 class SlVehicleEffect : public DefaultSaveLoadHandler<SlVehicleEffect, Vehicle> {
876 public:
877  inline static const SaveLoad description[] = {
878  SLE_VAR(Vehicle, subtype, SLE_UINT8),
879 
880  SLE_CONDVAR(Vehicle, tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
881  SLE_CONDVAR(Vehicle, tile, SLE_UINT32, SLV_6, SL_MAX_VERSION),
882 
883  SLE_CONDVAR(Vehicle, x_pos, SLE_FILE_I16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_6),
884  SLE_CONDVAR(Vehicle, x_pos, SLE_INT32, SLV_6, SL_MAX_VERSION),
885  SLE_CONDVAR(Vehicle, y_pos, SLE_FILE_I16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_6),
886  SLE_CONDVAR(Vehicle, y_pos, SLE_INT32, SLV_6, SL_MAX_VERSION),
887  SLE_CONDVAR(Vehicle, z_pos, SLE_FILE_U8 | SLE_VAR_I32, SL_MIN_VERSION, SLV_164),
888  SLE_CONDVAR(Vehicle, z_pos, SLE_INT32, SLV_164, SL_MAX_VERSION),
889 
890  SLE_VAR(Vehicle, sprite_cache.sprite_seq.seq[0].sprite, SLE_FILE_U16 | SLE_VAR_U32),
891  SLE_VAR(Vehicle, progress, SLE_UINT8),
892  SLE_VAR(Vehicle, vehstatus, SLE_UINT8),
893 
894  SLE_VAR(EffectVehicle, animation_state, SLE_UINT16),
895  SLE_VAR(EffectVehicle, animation_substate, SLE_UINT8),
896 
897  SLE_CONDVAR(Vehicle, spritenum, SLE_UINT8, SLV_2, SL_MAX_VERSION),
898  };
899  inline const static SaveLoadCompatTable compat_description = _vehicle_effect_sl_compat;
900 
901  void Save(Vehicle *v) const override
902  {
903  if (v->type != VEH_EFFECT) return;
904  SlObject(v, this->GetDescription());
905  }
906 
907  void Load(Vehicle *v) const override
908  {
909  if (v->type != VEH_EFFECT) return;
910  SlObject(v, this->GetLoadDescription());
911  }
912 
913  void FixPointers(Vehicle *v) const override
914  {
915  if (v->type != VEH_EFFECT) return;
916  SlObject(v, this->GetDescription());
917  }
918 };
919 
920 class SlVehicleDisaster : public DefaultSaveLoadHandler<SlVehicleDisaster, Vehicle> {
921 public:
922 #if defined(_MSC_VER) && (_MSC_VER == 1915 || _MSC_VER == 1916)
923  /* This table access private members of other classes; they have this
924  * class as friend. For MSVC CL 19.15 and 19.16 this doesn't work for
925  * "inline static const", so we are forced to wrap the table in a
926  * function. CL 19.16 is the latest for VS2017. */
927  inline static const SaveLoad description[] = {{}};
928  SaveLoadTable GetDescription() const override {
929 #else
930  inline
931 #endif
932  static const SaveLoad description[] = {
934 
935  SLE_VAR(Vehicle, subtype, SLE_UINT8),
936  SLE_CONDVAR(Vehicle, tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
937  SLE_CONDVAR(Vehicle, tile, SLE_UINT32, SLV_6, SL_MAX_VERSION),
938  SLE_CONDVAR(Vehicle, dest_tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
939  SLE_CONDVAR(Vehicle, dest_tile, SLE_UINT32, SLV_6, SL_MAX_VERSION),
940 
941  SLE_CONDVAR(Vehicle, x_pos, SLE_FILE_I16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_6),
942  SLE_CONDVAR(Vehicle, x_pos, SLE_INT32, SLV_6, SL_MAX_VERSION),
943  SLE_CONDVAR(Vehicle, y_pos, SLE_FILE_I16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_6),
944  SLE_CONDVAR(Vehicle, y_pos, SLE_INT32, SLV_6, SL_MAX_VERSION),
945  SLE_CONDVAR(Vehicle, z_pos, SLE_FILE_U8 | SLE_VAR_I32, SL_MIN_VERSION, SLV_164),
946  SLE_CONDVAR(Vehicle, z_pos, SLE_INT32, SLV_164, SL_MAX_VERSION),
947  SLE_VAR(Vehicle, direction, SLE_UINT8),
948 
949  SLE_VAR(Vehicle, owner, SLE_UINT8),
950  SLE_VAR(Vehicle, vehstatus, SLE_UINT8),
951  SLE_CONDVAR(Vehicle, current_order.dest, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_5),
952  SLE_CONDVAR(Vehicle, current_order.dest, SLE_UINT16, SLV_5, SL_MAX_VERSION),
953 
954  SLE_VAR(Vehicle, sprite_cache.sprite_seq.seq[0].sprite, SLE_FILE_U16 | SLE_VAR_U32),
955  SLE_CONDVAR(Vehicle, age, SLE_FILE_U16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_31),
956  SLE_CONDVAR(Vehicle, age, SLE_INT32, SLV_31, SL_MAX_VERSION),
957  SLE_VAR(Vehicle, tick_counter, SLE_UINT8),
958 
959  SLE_CONDVAR(DisasterVehicle, image_override, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_191),
960  SLE_CONDVAR(DisasterVehicle, image_override, SLE_UINT32, SLV_191, SL_MAX_VERSION),
961  SLE_CONDVAR(DisasterVehicle, big_ufo_destroyer_target, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_191),
962  SLE_CONDVAR(DisasterVehicle, big_ufo_destroyer_target, SLE_UINT32, SLV_191, SL_MAX_VERSION),
963  SLE_CONDVAR(DisasterVehicle, flags, SLE_UINT8, SLV_194, SL_MAX_VERSION),
964  };
965 #if defined(_MSC_VER) && (_MSC_VER == 1915 || _MSC_VER == 1916)
966  return description;
967  }
968 #endif
969  inline const static SaveLoadCompatTable compat_description = _vehicle_disaster_sl_compat;
970 
971  void Save(Vehicle *v) const override
972  {
973  if (v->type != VEH_DISASTER) return;
974  SlObject(v, this->GetDescription());
975  }
976 
977  void Load(Vehicle *v) const override
978  {
979  if (v->type != VEH_DISASTER) return;
980  SlObject(v, this->GetLoadDescription());
981  }
982 
983  void FixPointers(Vehicle *v) const override
984  {
985  if (v->type != VEH_DISASTER) return;
986  SlObject(v, this->GetDescription());
987  }
988 };
989 
990 const static SaveLoad _vehicle_desc[] = {
991  SLE_SAVEBYTE(Vehicle, type),
992  SLEG_STRUCT("train", SlVehicleTrain),
993  SLEG_STRUCT("roadveh", SlVehicleRoadVeh),
994  SLEG_STRUCT("ship", SlVehicleShip),
995  SLEG_STRUCT("aircraft", SlVehicleAircraft),
996  SLEG_STRUCT("effect", SlVehicleEffect),
997  SLEG_STRUCT("disaster", SlVehicleDisaster),
998 };
999 
1001  VEHSChunkHandler() : ChunkHandler('VEHS', CH_SPARSE_TABLE) {}
1002 
1003  void Save() const override
1004  {
1005  SlTableHeader(_vehicle_desc);
1006 
1007  /* Write the vehicles */
1008  for (Vehicle *v : Vehicle::Iterate()) {
1009  SlSetArrayIndex(v->index);
1010  SlObject(v, _vehicle_desc);
1011  }
1012  }
1013 
1014  void Load() const override
1015  {
1016  const std::vector<SaveLoad> slt = SlCompatTableHeader(_vehicle_desc, _vehicle_sl_compat);
1017 
1018  int index;
1019 
1020  _cargo_count = 0;
1021 
1022  while ((index = SlIterateArray()) != -1) {
1023  Vehicle *v;
1024  VehicleType vtype = (VehicleType)SlReadByte();
1025 
1026  switch (vtype) {
1027  case VEH_TRAIN: v = new (index) Train(); break;
1028  case VEH_ROAD: v = new (index) RoadVehicle(); break;
1029  case VEH_SHIP: v = new (index) Ship(); break;
1030  case VEH_AIRCRAFT: v = new (index) Aircraft(); break;
1031  case VEH_EFFECT: v = new (index) EffectVehicle(); break;
1032  case VEH_DISASTER: v = new (index) DisasterVehicle(); break;
1033  case VEH_INVALID: // Savegame shouldn't contain invalid vehicles
1034  default: SlErrorCorrupt("Invalid vehicle type");
1035  }
1036 
1037  SlObject(v, slt);
1038 
1039  if (_cargo_count != 0 && IsCompanyBuildableVehicleType(v) && CargoPacket::CanAllocateItem()) {
1040  /* Don't construct the packet with station here, because that'll fail with old savegames */
1041  CargoPacket *cp = new CargoPacket(_cargo_count, _cargo_days, _cargo_source, _cargo_source_xy, _cargo_loaded_at_xy, _cargo_feeder_share);
1042  v->cargo.Append(cp);
1043  }
1044 
1045  /* Old savegames used 'last_station_visited = 0xFF' */
1046  if (IsSavegameVersionBefore(SLV_5) && v->last_station_visited == 0xFF) {
1047  v->last_station_visited = INVALID_STATION;
1048  }
1049 
1050  if (IsSavegameVersionBefore(SLV_182)) v->last_loading_station = INVALID_STATION;
1051 
1053  /* Convert the current_order.type (which is a mix of type and flags, because
1054  * in those versions, they both were 4 bits big) to type and flags */
1055  v->current_order.flags = GB(v->current_order.type, 4, 4);
1056  v->current_order.type &= 0x0F;
1057  }
1058 
1059  /* Advanced vehicle lists got added */
1061  }
1062  }
1063 
1064  void FixPointers() const override
1065  {
1066  for (Vehicle *v : Vehicle::Iterate()) {
1067  SlObject(v, _vehicle_desc);
1068  }
1069  }
1070 };
1071 
1072 static const VEHSChunkHandler VEHS;
1073 static const ChunkHandlerRef veh_chunk_handlers[] = {
1074  VEHS,
1075 };
1076 
1077 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:1142
RoadVehicle
Buses, trucks and trams belong to this class.
Definition: roadveh.h:107
SLV_65
@ SLV_65
65 10210
Definition: saveload.h:125
INVALID_ENGINE
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
Definition: engine_type.h:203
IsCompanyBuildableVehicleType
static bool IsCompanyBuildableVehicleType(VehicleType type)
Is the given vehicle type buildable by a company?
Definition: vehicle_func.h:89
REF_ORDER
@ REF_ORDER
Load/save a reference to an order.
Definition: saveload.h:541
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:806
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:1435
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:173
DefaultSaveLoadHandler
Default handler for saving/loading an object to/from disk.
Definition: saveload.h:521
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:337
MutableSpriteCache::sprite_seq
VehicleSpriteSeq sprite_seq
Vehicle appearance.
Definition: vehicle_base.h:197
VehicleSpriteSeq::CopyWithoutPalette
void CopyWithoutPalette(const VehicleSpriteSeq &src)
Copy data from another sprite sequence, while dropping all recolouring information.
Definition: vehicle_base.h:175
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:241
SlVehicleAircraft
Definition: vehicle_sl.cpp:835
SL_MIN_VERSION
@ SL_MIN_VERSION
First savegame version.
Definition: saveload.h:35
FixupTrainLengths
void FixupTrainLengths()
Fixup old train spacing.
Definition: vehicle_sl.cpp:488
SLV_40
@ SLV_40
40 7326
Definition: saveload.h:95
Vehicle::Next
Vehicle * Next() const
Get the next vehicle of this vehicle.
Definition: vehicle_base.h:610
SpecializedVehicle::Next
T * Next() const
Get next vehicle in the chain.
Definition: vehicle_base.h:1098
SLE_CONDSSTR
#define SLE_CONDSSTR(base, variable, type, from, to)
Storage of a std::string in some savegame versions.
Definition: saveload.h:750
Station
Station data structure.
Definition: station_base.h:454
ChunkHandlerRef
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
Definition: saveload.h:449
SLV_112
@ SLV_112
112 15290
Definition: saveload.h:181
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:729
Vehicle::vehstatus
byte vehstatus
Status.
Definition: vehicle_base.h:332
SlVehicleTrain
Definition: vehicle_sl.cpp:735
SLE_CONDVAR
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Definition: saveload.h:708
SLV_84
@ SLV_84
84 11822
Definition: saveload.h:147
_age_cargo_skip_counter
byte _age_cargo_skip_counter
Skip aging of cargo? Used before savegame version 162.
Definition: misc_sl.cpp:71
Vehicle::group_id
GroupID group_id
Index of group Pool array.
Definition: vehicle_base.h:341
SLE_STR
#define SLE_STR(base, variable, type, length)
Storage of a string in every savegame version.
Definition: saveload.h:804
SLV_157
@ SLV_157
157 21862
Definition: saveload.h:235
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:581
SLV_88
@ SLV_88
88 12134
Definition: saveload.h:152
SaveLoadHandler::GetLoadDescription
SaveLoadTable GetLoadDescription() const
Get the description for how to load the chunk.
Definition: saveload.cpp:3430
saveload.h
SLV_35
@ SLV_35
35 6602
Definition: saveload.h:89
AircraftLeaveHangar
void AircraftLeaveHangar(Aircraft *v, Direction exit_dir)
Aircraft is about to leave the hangar.
Definition: aircraft_cmd.cpp:1455
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:1610
RoadVehicle::roadtype
RoadType roadtype
Roadtype of this vehicle.
Definition: roadveh.h:117
SLV_LAST_LOADING_TICK
@ SLV_LAST_LOADING_TICK
301 PR#9693 Store tick of last loading for vehicles.
Definition: saveload.h:345
Engine
Definition: engine_base.h:36
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
Vehicle::cur_speed
uint16 cur_speed
current speed
Definition: vehicle_base.h:307
ChunkHandler
Handlers and description of chunk.
Definition: saveload.h:412
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:224
VEHSChunkHandler
Definition: vehicle_sl.cpp:1000
_vehicle_common_sl_compat
const SaveLoadCompat _vehicle_common_sl_compat[]
Original field order for SlVehicleCommon.
Definition: vehicle_sl_compat.h:16
SLV_181
@ SLV_181
181 25012
Definition: saveload.h:264
_vehicle_disaster_sl_compat
const SaveLoadCompat _vehicle_disaster_sl_compat[]
Original field order for SlVehicleDisaster.
Definition: vehicle_sl_compat.h:174
SLV_100
@ SLV_100
100 13952
Definition: saveload.h:167
HANGAR
@ HANGAR
Heading for hangar.
Definition: airport.h:62
INVALID_ROADTYPE
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition: road_type.h:27
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:76
_vehicle_effect_sl_compat
const SaveLoadCompat _vehicle_effect_sl_compat[]
Original field order for SlVehicleEffect.
Definition: vehicle_sl_compat.h:157
SLE_REF
#define SLE_REF(base, variable, type)
Storage of a reference in every version of a savegame.
Definition: saveload.h:786
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:269
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:203
SlVehicleCommon
Definition: vehicle_sl.cpp:580
SLV_160
@ SLV_160
160 21974 1.1.x
Definition: saveload.h:239
Pool::PoolItem<&_engine_pool >::GetPoolSize
static size_t GetPoolSize()
Returns first unused index.
Definition: pool_type.hpp:358
VS_HIDDEN
@ VS_HIDDEN
Vehicle is not visible.
Definition: vehicle_base.h:34
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:47
RailVehicleInfo
Information about a rail vehicle.
Definition: engine_type.h:42
SLV_174
@ SLV_174
174 23973 1.2.x
Definition: saveload.h:255
RoadTypeInfo::powered_roadtypes
RoadTypes powered_roadtypes
bitmask to the OTHER roadtypes on which a vehicle of THIS roadtype generates power
Definition: road.h:120
SLF_ALLOW_CONTROL
@ SLF_ALLOW_CONTROL
Allow control codes in the strings.
Definition: saveload.h:631
CalcPercentVehicleFilled
uint8 CalcPercentVehicleFilled(const Vehicle *front, StringID *colour)
Calculates how full a vehicle is.
Definition: vehicle.cpp:1428
SLV_164
@ SLV_164
164 23290
Definition: saveload.h:243
span
A trimmed down version of what std::span will be in C++20.
Definition: span_type.hpp:60
SLV_31
@ SLV_31
31 5999
Definition: saveload.h:84
Vehicle::tile
TileIndex tile
Current tile index.
Definition: vehicle_base.h:245
EIT_ON_MAP
@ EIT_ON_MAP
Vehicle drawn in viewport.
Definition: vehicle_type.h:87
Vehicle::engine_type
EngineID engine_type
The type of engine used for this vehicle.
Definition: vehicle_base.h:302
SLE_SAVEBYTE
#define SLE_SAVEBYTE(base, variable)
Only write byte during saving; never read it during loading.
Definition: saveload.h:832
VS_CRASHED
@ VS_CRASHED
Vehicle is crashed.
Definition: vehicle_base.h:41
SLV_67
@ SLV_67
67 10236
Definition: saveload.h:127
Vehicle::last_station_visited
StationID last_station_visited
The last station we stopped at.
Definition: vehicle_base.h:316
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:324
Vehicle::current_order
Order current_order
The current order (+ status, like: loading)
Definition: vehicle_base.h:333
GroundVehicle::gcache
GroundVehicleCache gcache
Cache of often calculated values.
Definition: ground_vehicle.hpp:80
SLV_158
@ SLV_158
158 21933
Definition: saveload.h:236
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:913
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:54
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:717
CompanyProperties::settings
CompanySettings settings
settings specific for each company
Definition: company_base.h:106
AfterLoadVehicles
void AfterLoadVehicles(bool part_of_load)
Called after load to update coordinates.
Definition: vehicle_sl.cpp:242
SLV_ROADVEH_PATH_CACHE
@ SLV_ROADVEH_PATH_CACHE
211 PR#7261 Add path cache for road vehicles.
Definition: saveload.h:301
SetAircraftPosition
void SetAircraftPosition(Aircraft *v, int x, int y, int z)
Set aircraft position.
Definition: aircraft_cmd.cpp:521
VS_STOPPED
@ VS_STOPPED
Vehicle is stopped by the player.
Definition: vehicle_base.h:35
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:317
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
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:718
IsSavegameVersionBefore
static bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor=0)
Checks whether the savegame is below major.
Definition: saveload.h:1030
SLV_45
@ SLV_45
45 8501
Definition: saveload.h:101
TrainController
bool TrainController(Train *v, Vehicle *nomove, bool reverse=true)
Move a vehicle chain one movement stop forwards.
Definition: train_cmd.cpp:3259
VEHSChunkHandler::FixPointers
void FixPointers() const override
Fix the pointers.
Definition: vehicle_sl.cpp:1064
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:52
REF_VEHICLE
@ REF_VEHICLE
Load/save a reference to a vehicle.
Definition: saveload.h:542
REF_CARGO_PACKET
@ REF_CARGO_PACKET
Load/save a reference to a cargo packet.
Definition: saveload.h:548
SLV_182
@ SLV_182
182 25115 FS#5492, r25259, r25296 Goal status
Definition: saveload.h:265
REF_VEHICLE_OLD
@ REF_VEHICLE_OLD
Load/save an old-style reference to a vehicle (for pre-4.4 savegames).
Definition: saveload.h:545
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:347
_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
SLV_136
@ SLV_136
136 18764
Definition: saveload.h:210
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:38
DisasterVehicle
Disasters, like submarines, skyrangers and their shadows, belong to this class.
Definition: disaster_vehicle.h:37
TrainForceProceeding
TrainForceProceeding
Modes for ignoring signals.
Definition: train.h:37
SLV_139
@ SLV_139
139 19346
Definition: saveload.h:213
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:348
UpdateAircraftCache
void UpdateAircraftCache(Aircraft *v, bool update_range=false)
Update cached values of an aircraft.
Definition: aircraft_cmd.cpp:590
SLV_8
@ SLV_8
8.0 1786
Definition: saveload.h:53
Vehicle::next_shared
Vehicle * next_shared
pointer to the next vehicle that shares the order
Definition: vehicle_base.h:233
Ship
All ships have this type.
Definition: ship.h:26
SlVehicleEffect
Definition: vehicle_sl.cpp:875
SLE_VAR
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
Definition: saveload.h:778
VEHICLE_LENGTH
static const uint VEHICLE_LENGTH
The length of a vehicle in tile units.
Definition: vehicle_type.h:77
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:386
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:549
SLEG_CONDVAR
#define SLEG_CONDVAR(name, variable, type, from, to)
Storage of a global variable in some savegame versions.
Definition: saveload.h:855
RoadVehUpdateCache
void RoadVehUpdateCache(RoadVehicle *v, bool same_length=false)
Update the cache of a road vehicle.
Definition: roadveh_cmd.cpp:217
SLV_VEH_MOTION_COUNTER
@ SLV_VEH_MOTION_COUNTER
288 PR#8591 Desync safe motion counter
Definition: saveload.h:329
SLV_6
@ SLV_6
6.0 1721 6.1 1768
Definition: saveload.h:50
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:1183
VehicleSettings::roadveh_acceleration_model
uint8 roadveh_acceleration_model
realistic acceleration for road vehicles
Definition: settings_type.h:490
Train::ConsistChanged
void ConsistChanged(ConsistChangeFlags allowed_changes)
Recalculates the cached stuff of a train.
Definition: train_cmd.cpp:108
SlErrorCorrupt
void NORETURN SlErrorCorrupt(const char *msg)
Error handler for corrupt savegames.
Definition: saveload.cpp:365
SLV_36
@ SLV_36
36 6624
Definition: saveload.h:90
CompanyServiceInterval
int CompanyServiceInterval(const Company *c, VehicleType type)
Get the service interval for the given company and vehicle type.
Definition: company_cmd.cpp:1137
SLV_44
@ SLV_44
44 8144
Definition: saveload.h:99
AIR_HELICOPTER
@ AIR_HELICOPTER
an helicopter
Definition: aircraft.h:31
DefaultSaveLoadHandler< SlVehicleCommon, Vehicle >::GetDescription
SaveLoadTable GetDescription() const override
Definition: saveload.h:523
_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:316
SLV_60
@ SLV_60
60 9874
Definition: saveload.h:119
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:280
SlReadByte
byte SlReadByte()
Wrapper for reading a byte from the buffer.
Definition: saveload.cpp:425
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:307
SLV_129
@ SLV_129
129 18292
Definition: saveload.h:201
GetRoadTypeInfo
static const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition: road.h:225
EffectVehicle
A special vehicle is one of the following:
Definition: effectvehicle_base.h:24
SLV_105
@ SLV_105
105 14803
Definition: saveload.h:173
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:1252
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:760
ReverseTrainDirection
void ReverseTrainDirection(Train *v)
Turn a train around.
Definition: train_cmd.cpp:1947
VEH_DISASTER
@ VEH_DISASTER
Disaster vehicle type.
Definition: vehicle_type.h:32
SLV_167
@ SLV_167
167 23504
Definition: saveload.h:247
SLV_68
@ SLV_68
68 10266
Definition: saveload.h:128
VehicleDefaultSettings::servint_ispercent
bool servint_ispercent
service intervals are in percents
Definition: settings_type.h:568
TicksToLeaveDepot
int TicksToLeaveDepot(const Train *v)
Compute number of ticks when next wagon will leave a depot.
Definition: rail_cmd.cpp:2902
SLV_SHIP_PATH_CACHE
@ SLV_SHIP_PATH_CACHE
203 PR#7072 Add path cache for ships
Definition: saveload.h:291
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:43
_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:770
OverflowSafeInt< int64 >
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
SlCompatTableHeader
std::vector< SaveLoad > SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct)
Load a table header in a savegame compatible way.
Definition: saveload.cpp:2030
SLV_180
@ SLV_180
180 24998 1.3.x
Definition: saveload.h:263
Vehicle::spritenum
byte spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
Definition: vehicle_base.h:294
SlVehicleDisaster
Definition: vehicle_sl.cpp:920
SLV_191
@ SLV_191
191 26636 FS#6026 Fix disaster vehicle storage (No bump) 191 26646 FS#6041 Linkgraph - store location...
Definition: saveload.h:276
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:595
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
SlObject
void SlObject(void *object, const SaveLoadTable &slt)
Main SaveLoad function.
Definition: saveload.cpp:1839
SlTableHeader
std::vector< SaveLoad > SlTableHeader(const SaveLoadTable &slt)
Save or Load a table header.
Definition: saveload.cpp:1892
VEHSChunkHandler::Save
void Save() const override
Save the chunk.
Definition: vehicle_sl.cpp:1003
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:770
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:659
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
Company
Definition: company_base.h:117
Order::flags
uint8 flags
Load/unload types, depot order/action types.
Definition: order_base.h:49
SLV_51
@ SLV_51
51 8978
Definition: saveload.h:108
VEHSChunkHandler::Load
void Load() const override
Load the chunk.
Definition: vehicle_sl.cpp:1014
INVALID_COORD
static const int32 INVALID_COORD
Sentinel for an invalid coordinate.
Definition: vehicle_base.h:1269
Order::type
uint8 type
The type of order + non-stop flags.
Definition: order_base.h:48
_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:671
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:211
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:1701
_vehicle_roadveh_sl_compat
const SaveLoadCompat _vehicle_roadveh_sl_compat[]
Original field order for SlVehicleRoadVeh.
Definition: vehicle_sl_compat.h:114
SLV_SHIP_ROTATION
@ SLV_SHIP_ROTATION
204 PR#7065 Add extra rotation stages for ships.
Definition: saveload.h:292
SLEG_STRUCT
#define SLEG_STRUCT(name, handler)
Storage of a structs in every savegame version.
Definition: saveload.h:982