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 = NULL;
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 != NULL; u = u->GetNextVehicle()) {
60  if (u->other_multiheaded_part != NULL) 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 != NULL; w = w->GetNextVehicle()) {
74  if (w->engine_type != eid || w->other_multiheaded_part != NULL || !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 != NULL; w = w->GetNextVehicle()) {
86  if (w->engine_type != eid || w->other_multiheaded_part != NULL || !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 != NULL) {
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 != NULL; 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, NULL);
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() != NULL) v->Next()->previous = v;
256  if (v->NextShared() != NULL) v->NextShared()->previous_shared = v;
257 
258  if (part_of_load) v->fill_percent_te_id = INVALID_TE_ID;
259  v->first = NULL;
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 != NULL) {
276  if (IsSavegameVersionBefore(SLV_105)) { // Pre-105 didn't save an OrderList
277  if (mapping[v->orders.old] == NULL) {
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() == NULL) {
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() == NULL) {
304  for (Vehicle *u = v; u != NULL; 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 != NULL || v->previous_shared != NULL || v->next_shared == NULL) continue;
315 
316  /* As above, allocating OrderList here is safe. */
317  assert(OrderList::CanAllocateItem());
318  v->orders.list = new OrderList(NULL, v);
319  for (Vehicle *u = v; u != NULL; 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 != NULL);
396 
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  RoadVehUpdateCache(rv);
415  rv->CargoChanged();
416  }
417  }
418  break;
419  }
420 
421  case VEH_SHIP:
422  Ship::From(v)->UpdateCache();
423  break;
424 
425  default: break;
426  }
427  }
428 
429  /* Stop non-front engines */
430  if (part_of_load && IsSavegameVersionBefore(SLV_112)) {
431  FOR_ALL_VEHICLES(v) {
432  if (v->type == VEH_TRAIN) {
433  Train *t = Train::From(v);
434  if (!t->IsFrontEngine()) {
435  if (t->IsEngine()) t->vehstatus |= VS_STOPPED;
436  /* cur_speed is now relevant for non-front parts - nonzero breaks
437  * moving-wagons-inside-depot- and autoreplace- code */
438  t->cur_speed = 0;
439  }
440  }
441  /* trains weren't stopping gradually in old OTTD versions (and TTO/TTD)
442  * other vehicle types didn't have zero speed while stopped (even in 'recent' OTTD versions) */
443  if ((v->vehstatus & VS_STOPPED) && (v->type != VEH_TRAIN || IsSavegameVersionBefore(SLV_2, 1))) {
444  v->cur_speed = 0;
445  }
446  }
447  }
448 
449  FOR_ALL_VEHICLES(v) {
450  switch (v->type) {
451  case VEH_ROAD: {
453  rv->roadtype = HasBit(EngInfo(v->First()->engine_type)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD;
454  rv->compatible_roadtypes = RoadTypeToRoadTypes(rv->roadtype);
455  FALLTHROUGH;
456  }
457 
458  case VEH_TRAIN:
459  case VEH_SHIP:
461  break;
462 
463  case VEH_AIRCRAFT:
464  if (Aircraft::From(v)->IsNormalAircraft()) {
466 
467  /* The plane's shadow will have the same image as the plane, but no colour */
468  Vehicle *shadow = v->Next();
470 
471  /* In the case of a helicopter we will update the rotor sprites */
472  if (v->subtype == AIR_HELICOPTER) {
473  Vehicle *rotor = shadow->Next();
474  GetRotorImage(Aircraft::From(v), EIT_ON_MAP, &rotor->sprite_seq);
475  }
476 
478  }
479  break;
480  default: break;
481  }
482 
483  v->UpdateDeltaXY();
484  v->coord.left = INVALID_COORD;
485  v->UpdatePosition();
486  v->UpdateViewport(false);
487  }
488 }
489 
490 bool TrainController(Train *v, Vehicle *nomove, bool reverse = true); // From train_cmd.cpp
492 void ReverseTrainSwapVeh(Train *v, int l, int r);
493 
496 {
497  /* Vehicle center was moved from 4 units behind the front to half the length
498  * behind the front. Move vehicles so they end up on the same spot. */
499  Vehicle *v;
500  FOR_ALL_VEHICLES(v) {
501  if (v->type == VEH_TRAIN && v->IsPrimaryVehicle()) {
502  /* The vehicle center is now more to the front depending on vehicle length,
503  * so we need to move all vehicles forward to cover the difference to the
504  * old center, otherwise wagon spacing in trains would be broken upon load. */
505  for (Train *u = Train::From(v); u != NULL; u = u->Next()) {
506  if (u->track == TRACK_BIT_DEPOT || (u->vehstatus & VS_CRASHED)) continue;
507 
508  Train *next = u->Next();
509 
510  /* Try to pull the vehicle half its length forward. */
511  int diff = (VEHICLE_LENGTH - u->gcache.cached_veh_length) / 2;
512  int done;
513  for (done = 0; done < diff; done++) {
514  if (!TrainController(u, next, false)) break;
515  }
516 
517  if (next != NULL && done < diff && u->IsFrontEngine()) {
518  /* Pulling the front vehicle forwards failed, we either encountered a dead-end
519  * or a red signal. To fix this, we try to move the whole train the required
520  * space backwards and re-do the fix up of the front vehicle. */
521 
522  /* Ignore any signals when backtracking. */
523  TrainForceProceeding old_tfp = u->force_proceed;
524  u->force_proceed = TFP_SIGNAL;
525 
526  /* Swap start<>end, start+1<>end-1, ... */
527  int r = CountVehiclesInChain(u) - 1; // number of vehicles - 1
528  int l = 0;
529  do ReverseTrainSwapVeh(u, l++, r--); while (l <= r);
530 
531  /* We moved the first vehicle which is now the last. Move it back to the
532  * original position as we will fix up the last vehicle later in the loop. */
533  for (int i = 0; i < done; i++) TrainController(u->Last(), NULL);
534 
535  /* Move the train backwards to get space for the first vehicle. As the stopping
536  * distance from a line end is rounded up, move the train one unit more to cater
537  * for front vehicles with odd lengths. */
538  int moved;
539  for (moved = 0; moved < diff + 1; moved++) {
540  if (!TrainController(u, NULL, false)) break;
541  }
542 
543  /* Swap start<>end, start+1<>end-1, ... again. */
544  r = CountVehiclesInChain(u) - 1; // number of vehicles - 1
545  l = 0;
546  do ReverseTrainSwapVeh(u, l++, r--); while (l <= r);
547 
548  u->force_proceed = old_tfp;
549 
550  /* Tracks are too short to fix the train length. The player has to fix the
551  * train in a depot. Bail out so we don't damage the vehicle chain any more. */
552  if (moved < diff + 1) break;
553 
554  /* Re-do the correction for the first vehicle. */
555  for (done = 0; done < diff; done++) TrainController(u, next, false);
556 
557  /* We moved one unit more backwards than needed for even-length front vehicles,
558  * try to move that unit forward again. We don't care if this step fails. */
559  TrainController(u, NULL, false);
560  }
561 
562  /* If the next wagon is still in a depot, check if it shouldn't be outside already. */
563  if (next != NULL && next->track == TRACK_BIT_DEPOT) {
564  int d = TicksToLeaveDepot(u);
565  if (d <= 0) {
566  /* Next vehicle should have left the depot already, show it and pull forward. */
567  next->vehstatus &= ~VS_HIDDEN;
568  next->track = TrackToTrackBits(GetRailDepotTrack(next->tile));
569  for (int i = 0; i >= d; i--) TrainController(next, NULL);
570  }
571  }
572  }
573 
574  /* Update all cached properties after moving the vehicle chain around. */
576  }
577  }
578 }
579 
580 static uint8 _cargo_days;
581 static uint16 _cargo_source;
582 static uint32 _cargo_source_xy;
583 static uint16 _cargo_count;
584 static uint16 _cargo_paid_for;
585 static Money _cargo_feeder_share;
586 static uint32 _cargo_loaded_at_xy;
587 
594 {
596  static const SaveLoad _common_veh_desc[] = {
597  SLE_VAR(Vehicle, subtype, SLE_UINT8),
598 
600  SLE_CONDVAR(Vehicle, name, SLE_NAME, SL_MIN_VERSION, SLV_84),
602  SLE_CONDVAR(Vehicle, unitnumber, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_8),
603  SLE_CONDVAR(Vehicle, unitnumber, SLE_UINT16, SLV_8, SL_MAX_VERSION),
604  SLE_VAR(Vehicle, owner, SLE_UINT8),
605  SLE_CONDVAR(Vehicle, tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
606  SLE_CONDVAR(Vehicle, tile, SLE_UINT32, SLV_6, SL_MAX_VERSION),
607  SLE_CONDVAR(Vehicle, dest_tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
608  SLE_CONDVAR(Vehicle, dest_tile, SLE_UINT32, SLV_6, SL_MAX_VERSION),
609 
610  SLE_CONDVAR(Vehicle, x_pos, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
611  SLE_CONDVAR(Vehicle, x_pos, SLE_UINT32, SLV_6, SL_MAX_VERSION),
612  SLE_CONDVAR(Vehicle, y_pos, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
613  SLE_CONDVAR(Vehicle, y_pos, SLE_UINT32, SLV_6, SL_MAX_VERSION),
614  SLE_CONDVAR(Vehicle, z_pos, SLE_FILE_U8 | SLE_VAR_I32, SL_MIN_VERSION, SLV_164),
615  SLE_CONDVAR(Vehicle, z_pos, SLE_INT32, SLV_164, SL_MAX_VERSION),
616  SLE_VAR(Vehicle, direction, SLE_UINT8),
617 
619  SLE_VAR(Vehicle, spritenum, SLE_UINT8),
621  SLE_VAR(Vehicle, engine_type, SLE_UINT16),
622 
624  SLE_VAR(Vehicle, cur_speed, SLE_UINT16),
625  SLE_VAR(Vehicle, subspeed, SLE_UINT8),
626  SLE_VAR(Vehicle, acceleration, SLE_UINT8),
627  SLE_VAR(Vehicle, progress, SLE_UINT8),
628 
629  SLE_VAR(Vehicle, vehstatus, SLE_UINT8),
630  SLE_CONDVAR(Vehicle, last_station_visited, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_5),
631  SLE_CONDVAR(Vehicle, last_station_visited, SLE_UINT16, SLV_5, SL_MAX_VERSION),
632  SLE_CONDVAR(Vehicle, last_loading_station, SLE_UINT16, SLV_182, SL_MAX_VERSION),
633 
634  SLE_VAR(Vehicle, cargo_type, SLE_UINT8),
635  SLE_CONDVAR(Vehicle, cargo_subtype, SLE_UINT8, SLV_35, SL_MAX_VERSION),
636  SLEG_CONDVAR( _cargo_days, SLE_UINT8, SL_MIN_VERSION, SLV_68),
637  SLEG_CONDVAR( _cargo_source, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_7),
638  SLEG_CONDVAR( _cargo_source, SLE_UINT16, SLV_7, SLV_68),
639  SLEG_CONDVAR( _cargo_source_xy, SLE_UINT32, SLV_44, SLV_68),
640  SLE_VAR(Vehicle, cargo_cap, SLE_UINT16),
641  SLE_CONDVAR(Vehicle, refit_cap, SLE_UINT16, SLV_182, SL_MAX_VERSION),
642  SLEG_CONDVAR( _cargo_count, SLE_UINT16, SL_MIN_VERSION, SLV_68),
644  SLE_CONDARR(Vehicle, cargo.action_counts, SLE_UINT, VehicleCargoList::NUM_MOVE_TO_ACTION, SLV_181, SL_MAX_VERSION),
645  SLE_CONDVAR(Vehicle, cargo_age_counter, SLE_UINT16, SLV_162, SL_MAX_VERSION),
646 
647  SLE_VAR(Vehicle, day_counter, SLE_UINT8),
648  SLE_VAR(Vehicle, tick_counter, SLE_UINT8),
649  SLE_CONDVAR(Vehicle, running_ticks, SLE_UINT8, SLV_88, SL_MAX_VERSION),
650 
651  SLE_VAR(Vehicle, cur_implicit_order_index, SLE_UINT8),
652  SLE_CONDVAR(Vehicle, cur_real_order_index, SLE_UINT8, SLV_158, SL_MAX_VERSION),
653  /* num_orders is now part of OrderList and is not saved but counted */
655 
656  /* This next line is for version 4 and prior compatibility.. it temporarily reads
657  type and flags (which were both 4 bits) into type. Later on this is
658  converted correctly */
659  SLE_CONDVAR(Vehicle, current_order.type, SLE_UINT8, SL_MIN_VERSION, SLV_5),
660  SLE_CONDVAR(Vehicle, current_order.dest, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_5),
661 
662  /* Orders for version 5 and on */
663  SLE_CONDVAR(Vehicle, current_order.type, SLE_UINT8, SLV_5, SL_MAX_VERSION),
664  SLE_CONDVAR(Vehicle, current_order.flags, SLE_UINT8, SLV_5, SL_MAX_VERSION),
665  SLE_CONDVAR(Vehicle, current_order.dest, SLE_UINT16, SLV_5, SL_MAX_VERSION),
666 
667  /* Refit in current order */
668  SLE_CONDVAR(Vehicle, current_order.refit_cargo, SLE_UINT8, SLV_36, SL_MAX_VERSION),
669  SLE_CONDNULL(1, SLV_36, SLV_182), // refit_subtype
670 
671  /* Timetable in current order */
672  SLE_CONDVAR(Vehicle, current_order.wait_time, SLE_UINT16, SLV_67, SL_MAX_VERSION),
673  SLE_CONDVAR(Vehicle, current_order.travel_time, SLE_UINT16, SLV_67, SL_MAX_VERSION),
674  SLE_CONDVAR(Vehicle, current_order.max_speed, SLE_UINT16, SLV_174, SL_MAX_VERSION),
675  SLE_CONDVAR(Vehicle, timetable_start, SLE_INT32, SLV_129, SL_MAX_VERSION),
676 
679 
680  SLE_CONDVAR(Vehicle, age, SLE_FILE_U16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_31),
681  SLE_CONDVAR(Vehicle, age, SLE_INT32, SLV_31, SL_MAX_VERSION),
682  SLE_CONDVAR(Vehicle, max_age, SLE_FILE_U16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_31),
683  SLE_CONDVAR(Vehicle, max_age, SLE_INT32, SLV_31, SL_MAX_VERSION),
684  SLE_CONDVAR(Vehicle, date_of_last_service, SLE_FILE_U16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_31),
685  SLE_CONDVAR(Vehicle, date_of_last_service, SLE_INT32, SLV_31, SL_MAX_VERSION),
686  SLE_CONDVAR(Vehicle, service_interval, SLE_UINT16, SL_MIN_VERSION, SLV_31),
687  SLE_CONDVAR(Vehicle, service_interval, SLE_FILE_U32 | SLE_VAR_U16, SLV_31, SLV_180),
688  SLE_CONDVAR(Vehicle, service_interval, SLE_UINT16, SLV_180, SL_MAX_VERSION),
689  SLE_VAR(Vehicle, reliability, SLE_UINT16),
690  SLE_VAR(Vehicle, reliability_spd_dec, SLE_UINT16),
691  SLE_VAR(Vehicle, breakdown_ctr, SLE_UINT8),
692  SLE_VAR(Vehicle, breakdown_delay, SLE_UINT8),
693  SLE_VAR(Vehicle, breakdowns_since_last_service, SLE_UINT8),
694  SLE_VAR(Vehicle, breakdown_chance, SLE_UINT8),
695  SLE_CONDVAR(Vehicle, build_year, SLE_FILE_U8 | SLE_VAR_I32, SL_MIN_VERSION, SLV_31),
696  SLE_CONDVAR(Vehicle, build_year, SLE_INT32, SLV_31, SL_MAX_VERSION),
697 
698  SLE_VAR(Vehicle, load_unload_ticks, SLE_UINT16),
699  SLEG_CONDVAR( _cargo_paid_for, SLE_UINT16, SLV_45, SL_MAX_VERSION),
700  SLE_CONDVAR(Vehicle, vehicle_flags, SLE_FILE_U8 | SLE_VAR_U16, SLV_40, SLV_180),
701  SLE_CONDVAR(Vehicle, vehicle_flags, SLE_UINT16, SLV_180, SL_MAX_VERSION),
702 
703  SLE_CONDVAR(Vehicle, profit_this_year, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_65),
704  SLE_CONDVAR(Vehicle, profit_this_year, SLE_INT64, SLV_65, SL_MAX_VERSION),
705  SLE_CONDVAR(Vehicle, profit_last_year, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_65),
706  SLE_CONDVAR(Vehicle, profit_last_year, SLE_INT64, SLV_65, SL_MAX_VERSION),
707  SLEG_CONDVAR( _cargo_feeder_share, SLE_FILE_I32 | SLE_VAR_I64, SLV_51, SLV_65),
708  SLEG_CONDVAR( _cargo_feeder_share, SLE_INT64, SLV_65, SLV_68),
709  SLEG_CONDVAR( _cargo_loaded_at_xy, SLE_UINT32, SLV_51, SLV_68),
710  SLE_CONDVAR(Vehicle, value, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_65),
711  SLE_CONDVAR(Vehicle, value, SLE_INT64, SLV_65, SL_MAX_VERSION),
712 
713  SLE_CONDVAR(Vehicle, random_bits, SLE_UINT8, SLV_2, SL_MAX_VERSION),
714  SLE_CONDVAR(Vehicle, waiting_triggers, SLE_UINT8, SLV_2, SL_MAX_VERSION),
715 
719 
720  SLE_CONDVAR(Vehicle, group_id, SLE_UINT16, SLV_60, SL_MAX_VERSION),
721 
722  SLE_CONDVAR(Vehicle, current_order_time, SLE_UINT32, SLV_67, SL_MAX_VERSION),
723  SLE_CONDVAR(Vehicle, lateness_counter, SLE_INT32, SLV_67, SL_MAX_VERSION),
724 
725  SLE_CONDNULL(10, SLV_2, SLV_144), // old reserved space
726 
727  SLE_END()
728  };
729 
730 
731  static const SaveLoad _train_desc[] = {
732  SLE_WRITEBYTE(Vehicle, type),
733  SLE_VEH_INCLUDE(),
734  SLE_VAR(Train, crash_anim_pos, SLE_UINT16),
735  SLE_VAR(Train, force_proceed, SLE_UINT8),
736  SLE_VAR(Train, railtype, SLE_UINT8),
737  SLE_VAR(Train, track, SLE_UINT8),
738 
739  SLE_CONDVAR(Train, flags, SLE_FILE_U8 | SLE_VAR_U16, SLV_2, SLV_100),
740  SLE_CONDVAR(Train, flags, SLE_UINT16, SLV_100, SL_MAX_VERSION),
742 
743  SLE_CONDVAR(Train, wait_counter, SLE_UINT16, SLV_136, SL_MAX_VERSION),
744 
746  SLE_CONDVAR(Train, gv_flags, SLE_UINT16, SLV_139, SL_MAX_VERSION),
747  SLE_CONDNULL(11, SLV_2, SLV_144), // old reserved space
748 
749  SLE_END()
750  };
751 
752  static const SaveLoad _roadveh_desc[] = {
753  SLE_WRITEBYTE(Vehicle, type),
754  SLE_VEH_INCLUDE(),
755  SLE_VAR(RoadVehicle, state, SLE_UINT8),
756  SLE_VAR(RoadVehicle, frame, SLE_UINT8),
757  SLE_VAR(RoadVehicle, blocked_ctr, SLE_UINT16),
758  SLE_VAR(RoadVehicle, overtaking, SLE_UINT8),
759  SLE_VAR(RoadVehicle, overtaking_ctr, SLE_UINT8),
760  SLE_VAR(RoadVehicle, crashed_ctr, SLE_UINT16),
761  SLE_VAR(RoadVehicle, reverse_ctr, SLE_UINT8),
762 
764  SLE_CONDVAR(RoadVehicle, gv_flags, SLE_UINT16, SLV_139, SL_MAX_VERSION),
767  SLE_CONDNULL(16, SLV_2, SLV_144), // old reserved space
768 
769  SLE_END()
770  };
771 
772  static const SaveLoad _ship_desc[] = {
773  SLE_WRITEBYTE(Vehicle, type),
774  SLE_VEH_INCLUDE(),
775  SLE_VAR(Ship, state, SLE_UINT8),
777  SLE_CONDVAR(Ship, rotation, SLE_UINT8, SLV_SHIP_ROTATION, SL_MAX_VERSION),
778 
779  SLE_CONDNULL(16, SLV_2, SLV_144), // old reserved space
780 
781  SLE_END()
782  };
783 
784  static const SaveLoad _aircraft_desc[] = {
785  SLE_WRITEBYTE(Vehicle, type),
786  SLE_VEH_INCLUDE(),
787  SLE_VAR(Aircraft, crashed_counter, SLE_UINT16),
788  SLE_VAR(Aircraft, pos, SLE_UINT8),
789 
790  SLE_CONDVAR(Aircraft, targetairport, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_5),
791  SLE_CONDVAR(Aircraft, targetairport, SLE_UINT16, SLV_5, SL_MAX_VERSION),
792 
793  SLE_VAR(Aircraft, state, SLE_UINT8),
794 
795  SLE_CONDVAR(Aircraft, previous_pos, SLE_UINT8, SLV_2, SL_MAX_VERSION),
796  SLE_CONDVAR(Aircraft, last_direction, SLE_UINT8, SLV_2, SL_MAX_VERSION),
797  SLE_CONDVAR(Aircraft, number_consecutive_turns, SLE_UINT8, SLV_2, SL_MAX_VERSION),
798 
799  SLE_CONDVAR(Aircraft, turn_counter, SLE_UINT8, SLV_136, SL_MAX_VERSION),
800  SLE_CONDVAR(Aircraft, flags, SLE_UINT8, SLV_167, SL_MAX_VERSION),
801 
802  SLE_CONDNULL(13, SLV_2, SLV_144), // old reserved space
803 
804  SLE_END()
805  };
806 
807  static const SaveLoad _special_desc[] = {
808  SLE_WRITEBYTE(Vehicle, type),
809 
810  SLE_VAR(Vehicle, subtype, SLE_UINT8),
811 
812  SLE_CONDVAR(Vehicle, tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
813  SLE_CONDVAR(Vehicle, tile, SLE_UINT32, SLV_6, SL_MAX_VERSION),
814 
815  SLE_CONDVAR(Vehicle, x_pos, SLE_FILE_I16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_6),
816  SLE_CONDVAR(Vehicle, x_pos, SLE_INT32, SLV_6, SL_MAX_VERSION),
817  SLE_CONDVAR(Vehicle, y_pos, SLE_FILE_I16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_6),
818  SLE_CONDVAR(Vehicle, y_pos, SLE_INT32, SLV_6, SL_MAX_VERSION),
819  SLE_CONDVAR(Vehicle, z_pos, SLE_FILE_U8 | SLE_VAR_I32, SL_MIN_VERSION, SLV_164),
820  SLE_CONDVAR(Vehicle, z_pos, SLE_INT32, SLV_164, SL_MAX_VERSION),
821 
822  SLE_VAR(Vehicle, sprite_seq.seq[0].sprite, SLE_FILE_U16 | SLE_VAR_U32),
824  SLE_VAR(Vehicle, progress, SLE_UINT8),
825  SLE_VAR(Vehicle, vehstatus, SLE_UINT8),
826 
827  SLE_VAR(EffectVehicle, animation_state, SLE_UINT16),
828  SLE_VAR(EffectVehicle, animation_substate, SLE_UINT8),
829 
830  SLE_CONDVAR(Vehicle, spritenum, SLE_UINT8, SLV_2, SL_MAX_VERSION),
831 
832  SLE_CONDNULL(15, SLV_2, SLV_144), // old reserved space
833 
834  SLE_END()
835  };
836 
837  static const SaveLoad _disaster_desc[] = {
838  SLE_WRITEBYTE(Vehicle, type),
839 
841 
842  SLE_VAR(Vehicle, subtype, SLE_UINT8),
843  SLE_CONDVAR(Vehicle, tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
844  SLE_CONDVAR(Vehicle, tile, SLE_UINT32, SLV_6, SL_MAX_VERSION),
845  SLE_CONDVAR(Vehicle, dest_tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
846  SLE_CONDVAR(Vehicle, dest_tile, SLE_UINT32, SLV_6, SL_MAX_VERSION),
847 
848  SLE_CONDVAR(Vehicle, x_pos, SLE_FILE_I16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_6),
849  SLE_CONDVAR(Vehicle, x_pos, SLE_INT32, SLV_6, SL_MAX_VERSION),
850  SLE_CONDVAR(Vehicle, y_pos, SLE_FILE_I16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_6),
851  SLE_CONDVAR(Vehicle, y_pos, SLE_INT32, SLV_6, SL_MAX_VERSION),
852  SLE_CONDVAR(Vehicle, z_pos, SLE_FILE_U8 | SLE_VAR_I32, SL_MIN_VERSION, SLV_164),
853  SLE_CONDVAR(Vehicle, z_pos, SLE_INT32, SLV_164, SL_MAX_VERSION),
854  SLE_VAR(Vehicle, direction, SLE_UINT8),
855 
857  SLE_VAR(Vehicle, owner, SLE_UINT8),
858  SLE_VAR(Vehicle, vehstatus, SLE_UINT8),
859  SLE_CONDVAR(Vehicle, current_order.dest, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_5),
860  SLE_CONDVAR(Vehicle, current_order.dest, SLE_UINT16, SLV_5, SL_MAX_VERSION),
861 
862  SLE_VAR(Vehicle, sprite_seq.seq[0].sprite, SLE_FILE_U16 | SLE_VAR_U32),
863  SLE_CONDVAR(Vehicle, age, SLE_FILE_U16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_31),
864  SLE_CONDVAR(Vehicle, age, SLE_INT32, SLV_31, SL_MAX_VERSION),
865  SLE_VAR(Vehicle, tick_counter, SLE_UINT8),
866 
867  SLE_CONDVAR(DisasterVehicle, image_override, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_191),
868  SLE_CONDVAR(DisasterVehicle, image_override, SLE_UINT32, SLV_191, SL_MAX_VERSION),
869  SLE_CONDVAR(DisasterVehicle, big_ufo_destroyer_target, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_191),
870  SLE_CONDVAR(DisasterVehicle, big_ufo_destroyer_target, SLE_UINT32, SLV_191, SL_MAX_VERSION),
871  SLE_CONDVAR(DisasterVehicle, flags, SLE_UINT8, SLV_194, SL_MAX_VERSION),
872 
873  SLE_CONDNULL(16, SLV_2, SLV_144), // old reserved space
874 
875  SLE_END()
876  };
877 
878 
879  static const SaveLoad * const _veh_descs[] = {
880  _train_desc,
881  _roadveh_desc,
882  _ship_desc,
883  _aircraft_desc,
884  _special_desc,
885  _disaster_desc,
886  _common_veh_desc,
887  };
888 
889  return _veh_descs[vt];
890 }
891 
893 static void Save_VEHS()
894 {
895  Vehicle *v;
896  /* Write the vehicles */
897  FOR_ALL_VEHICLES(v) {
898  SlSetArrayIndex(v->index);
900  }
901 }
902 
904 void Load_VEHS()
905 {
906  int index;
907 
908  _cargo_count = 0;
909 
910  while ((index = SlIterateArray()) != -1) {
911  Vehicle *v;
913 
914  switch (vtype) {
915  case VEH_TRAIN: v = new (index) Train(); break;
916  case VEH_ROAD: v = new (index) RoadVehicle(); break;
917  case VEH_SHIP: v = new (index) Ship(); break;
918  case VEH_AIRCRAFT: v = new (index) Aircraft(); break;
919  case VEH_EFFECT: v = new (index) EffectVehicle(); break;
920  case VEH_DISASTER: v = new (index) DisasterVehicle(); break;
921  case VEH_INVALID: // Savegame shouldn't contain invalid vehicles
922  default: SlErrorCorrupt("Invalid vehicle type");
923  }
924 
925  SlObject(v, GetVehicleDescription(vtype));
926 
927  if (_cargo_count != 0 && IsCompanyBuildableVehicleType(v) && CargoPacket::CanAllocateItem()) {
928  /* Don't construct the packet with station here, because that'll fail with old savegames */
929  CargoPacket *cp = new CargoPacket(_cargo_count, _cargo_days, _cargo_source, _cargo_source_xy, _cargo_loaded_at_xy, _cargo_feeder_share);
930  v->cargo.Append(cp);
931  }
932 
933  /* Old savegames used 'last_station_visited = 0xFF' */
935  v->last_station_visited = INVALID_STATION;
936  }
937 
938  if (IsSavegameVersionBefore(SLV_182)) v->last_loading_station = INVALID_STATION;
939 
941  /* Convert the current_order.type (which is a mix of type and flags, because
942  * in those versions, they both were 4 bits big) to type and flags */
943  v->current_order.flags = GB(v->current_order.type, 4, 4);
944  v->current_order.type &= 0x0F;
945  }
946 
947  /* Advanced vehicle lists got added */
949  }
950 }
951 
952 static void Ptrs_VEHS()
953 {
954  Vehicle *v;
955  FOR_ALL_VEHICLES(v) {
957  }
958 }
959 
960 extern const ChunkHandler _veh_chunk_handlers[] = {
961  { 'VEHS', Save_VEHS, Load_VEHS, Ptrs_VEHS, NULL, CH_SPARSE_ARRAY | CH_LAST},
962 };
#define SLE_CONDNULL(length, from, to)
Empty space in some savegame versions.
Definition: saveload.h:632
VehicleSettings vehicle
options for vehicles
#define SLE_CONDDEQUE(base, variable, type, from, to)
Storage of a deque in some savegame versions.
Definition: saveload.h:576
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:3091
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:77
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:893
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:593
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:753
129 18292
Definition: saveload.h:198
void Load_VEHS()
Will be called when vehicles need to be loaded.
Definition: vehicle_sl.cpp:904
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
DirectionByte direction
facing
Definition: vehicle_base.h:271
Non-existing type of vehicle.
Definition: vehicle_type.h:37
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:2900
#define SLE_CONDSTR(base, variable, type, length, from, to)
Storage of a string in some savegame versions.
Definition: saveload.h:556
#define SLE_CONDREF(base, variable, type, from, to)
Storage of a reference in some savegame versions.
Definition: saveload.h:534
void NORETURN SlErrorCorrupt(const char *msg)
Error handler for corrupt savegames.
Definition: saveload.cpp:348
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:246
Basic road type.
Definition: road_type.h:24
void CopyWithoutPalette(const VehicleSpriteSeq &src)
Copy data from another sprite sequence, while dropping all recolouring information.
Definition: vehicle_base.h:173
TrainForceProceeding
Modes for ignoring signals.
Definition: train.h:39
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Vehicle drawn in viewport.
Definition: vehicle_type.h:90
51 8978
Definition: saveload.h:105
uint16 cur_speed
current speed
Definition: vehicle_base.h:293
uint16 cargo_age_counter
Ticks till cargo is aged next.
Definition: vehicle_base.h:310
Disaster vehicle type.
Definition: vehicle_type.h:34
#define SLE_REF(base, variable, type)
Storage of a reference in every version of a savegame.
Definition: saveload.h:592
byte spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
Definition: vehicle_base.h:279
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
static RoadTypes RoadTypeToRoadTypes(RoadType rt)
Maps a RoadType to the corresponding RoadTypes value.
Definition: road_func.h:56
Load/save an old-style reference to a vehicle (for pre-4.4 savegames).
Definition: saveload.h:365
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
DirectionByte rotation
Visible direction.
Definition: ship.h:31
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:1570
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...
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:566
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:126
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
Definition: vehicle.cpp:744
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:88
Shared order list linking together the linked list of orders and the list of vehicles sharing this or...
Definition: order_base.h:252
Aircraft vehicle type.
Definition: vehicle_type.h:29
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:524
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
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:295
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:135
allow control codes in the strings
Definition: saveload.h:461
GroundVehicleCache * GetGroundVehicleCache()
Access the ground vehicle cache of the vehicle.
Definition: vehicle.cpp:2826
5.0 1429 5.1 1440 5.2 1525 0.3.6
Definition: saveload.h:44
VehicleType
Available vehicle types.
Definition: vehicle_type.h:23
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:30
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:80
Trams.
Definition: road_type.h:25
#define SLE_WRITEBYTE(base, variable)
Translate values ingame to different values in the savegame and vv.
Definition: saveload.h:635
158 21933
Definition: saveload.h:233
VehicleType type
Vehicle type, ie VEH_ROAD, VEH_TRAIN, etc.
Definition: engine_base.h:42
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:2689
Effect vehicle type (smoke, explosions, sparks, bubbles)
Definition: vehicle_type.h:33
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
35 6602
Definition: saveload.h:86
Load/save a reference to an order.
Definition: saveload.h:361
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:293
TileIndex tile
Current tile index.
Definition: vehicle_base.h:230
void ReverseTrainDirection(Train *v)
Turn a train around.
Definition: train_cmd.cpp:1801
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
static Track GetRailDepotTrack(TileIndex t)
Returns the track of a depot, ignoring direction.
Definition: rail_map.h:183
uint64 flags
stores which blocks on the airport are taken. was 16 bit earlier on, then 32
Definition: station_base.h:308
84 11822
Definition: saveload.h:144
Road vehicle type.
Definition: vehicle_type.h:27
byte SlReadByte()
Wrapper for reading a byte from the buffer.
Definition: saveload.cpp:411
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:1582
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:634
All ships have this type.
Definition: ship.h:28
Load/save a reference to a vehicle.
Definition: saveload.h:362
Handlers and description of chunk.
Definition: saveload.h:346
Information about a rail vehicle.
Definition: engine_type.h:43
byte state
State of the airport.
Definition: aircraft.h:81
#define FOR_ALL_SHIPS(var)
Iterate over all ships.
Definition: ship.h:66
Ship vehicle type.
Definition: vehicle_type.h:28
#define SLEG_CONDVAR(variable, type, from, to)
Storage of a global variable in some savegame versions.
Definition: saveload.h:661
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:88
174 23973 1.2.x
Definition: saveload.h:252
#define SLE_END()
End marker of a struct/class save or load.
Definition: saveload.h:641
union Vehicle::@47 orders
The orders currently assigned to the vehicle.
int8 trip_occupancy
NOSAVE: Occupancy of vehicle of the current trip (updated after leaving a station).
Definition: vehicle_base.h:311
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: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:1621
void UpdatePosition()
Update the position of the vehicle.
Definition: vehicle.cpp:1560
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:368
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:545
uint16 EngineID
Unique identification number of an engine.
Definition: engine_type.h:22
181 25012
Definition: saveload.h:261
Bitflag for a depot.
Definition: track_type.h:59
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:65
Disasters, like submarines, skyrangers and their shadows, belong to this class.
OwnerByte owner
Which company owns the vehicle?
Definition: vehicle_base.h:273
indicates a combination of two locomotives
Definition: engine_type.h:29
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
Definition: saveload.cpp:1543
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
void FixupTrainLengths()
Fixup old train spacing.
Definition: vehicle_sl.cpp:495
uint8 CalcPercentVehicleFilled(const Vehicle *front, StringID *colour)
Calculates how full a vehicle is.
Definition: vehicle.cpp:1378
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
Ignore next signal, after the signal ignore being stuck.
Definition: train.h:42
an helicopter
Definition: aircraft.h:33
Valid changes when loading a savegame. (Everything that is not stored in the save.)
Definition: train.h:56
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:460
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:486
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:584
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:369
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:610
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
Road vehicle is a tram/light rail vehicle.
Definition: engine_type.h:154
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
VehicleTypeByte type
Type of vehicle.
Definition: vehicle_type.h:56
Valid changes while vehicle is driving, and possibly changing tracks.
Definition: train.h:51
40 7326
Definition: saveload.h:92
67 10236
Definition: saveload.h:124
Station data structure.
Definition: station_base.h:446
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:381
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
Train vehicle type.
Definition: vehicle_type.h:26
167 23504
Definition: saveload.h:244