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