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