OpenTTD Source  20241120-master-g6d3adc6169
vehicle_base.h
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #ifndef VEHICLE_BASE_H
11 #define VEHICLE_BASE_H
12 
13 #include "track_type.h"
14 #include "command_type.h"
15 #include "order_base.h"
16 #include "cargopacket.h"
17 #include "texteff.hpp"
18 #include "engine_type.h"
19 #include "order_func.h"
20 #include "transport_type.h"
21 #include "group_type.h"
22 #include "base_consist.h"
23 #include "network/network.h"
24 #include "saveload/saveload.h"
26 #include "core/mem_func.hpp"
27 
28 const uint TILE_AXIAL_DISTANCE = 192; // Logical length of the tile in any DiagDirection used in vehicle movement.
29 const uint TILE_CORNER_DISTANCE = 128; // Logical length of the tile corner crossing in any non-diagonal direction used in vehicle movement.
30 
32 enum VehStatus {
33  VS_HIDDEN = 0x01,
34  VS_STOPPED = 0x02,
35  VS_UNCLICKABLE = 0x04,
36  VS_DEFPAL = 0x08,
38  VS_SHADOW = 0x20,
40  VS_CRASHED = 0x80,
41 };
42 
55 };
56 
65 };
66 
68 struct NewGRFCache {
69  /* Values calculated when they are requested for the first time after invalidating the NewGRF cache. */
75  uint8_t cache_valid;
76 
77  auto operator<=>(const NewGRFCache &) const = default;
78 };
79 
85 
92 
96 
97  VE_DEFAULT = 0xFF,
98 };
99 
102  VESM_NONE = 0,
106 
107  VESM_END
108 };
109 
122 };
123 
125 struct VehicleCache {
126  uint16_t cached_max_speed;
128 
130 
131  auto operator<=>(const VehicleCache &) const = default;
132 };
133 
136  PalSpriteID seq[8];
137  uint count;
138 
139  bool operator==(const VehicleSpriteSeq &other) const
140  {
141  return this->count == other.count && MemCmpT<PalSpriteID>(this->seq, other.seq, this->count) == 0;
142  }
143 
144  bool operator!=(const VehicleSpriteSeq &other) const
145  {
146  return !this->operator==(other);
147  }
148 
152  bool IsValid() const
153  {
154  return this->count != 0;
155  }
156 
160  void Clear()
161  {
162  this->count = 0;
163  }
164 
168  void Set(SpriteID sprite)
169  {
170  this->count = 1;
171  this->seq[0].sprite = sprite;
172  this->seq[0].pal = 0;
173  }
174 
179  {
180  this->count = src.count;
181  for (uint i = 0; i < src.count; ++i) {
182  this->seq[i].sprite = src.seq[i].sprite;
183  this->seq[i].pal = 0;
184  }
185  }
186 
187  void GetBounds(Rect *bounds) const;
188  void Draw(int x, int y, PaletteID default_pal, bool force_pal) const;
189 };
190 
201 };
202 
206 
207 /* Some declarations of functions, so we can make them friendly */
208 struct GroundVehicleCache;
209 struct LoadgameState;
210 extern bool LoadOldVehicle(LoadgameState *ls, int num);
211 extern void FixOldVehicles();
212 
213 struct GRFFile;
214 
218 struct RefitDesc {
220  uint16_t capacity;
221  uint16_t remaining;
222  RefitDesc(CargoID cargo, uint16_t capacity, uint16_t remaining) :
224 };
225 
230 struct ClosestDepot {
231  TileIndex location;
232  DestinationID destination;
233  bool reverse;
234  bool found;
235 
236  ClosestDepot() :
237  location(INVALID_TILE), destination(0), reverse(false), found(false) {}
238 
239  ClosestDepot(TileIndex location, DestinationID destination, bool reverse = false) :
240  location(location), destination(destination), reverse(reverse), found(true) {}
241 };
242 
245 private:
246  typedef std::list<RefitDesc> RefitList;
247 
251 
254 
255 public:
256  friend void FixOldVehicles();
257  friend void AfterLoadVehiclesPhase1(bool part_of_load);
258  friend bool LoadOldVehicle(LoadgameState *ls, int num);
259  /* So we can use private/protected variables in the saveload code */
260  friend class SlVehicleCommon;
261  friend class SlVehicleDisaster;
262  friend void Ptrs_VEHS();
263 
265 
272 
276 
278 
279  mutable Rect coord;
280 
283 
287 
289 
290  /* Related to age and service time */
293  TimerGameEconomy::Date economy_age;
295  TimerGameEconomy::Date date_of_last_service;
297  uint16_t reliability;
299  uint8_t breakdown_ctr;
300  uint8_t breakdown_delay;
303 
304  int32_t x_pos;
305  int32_t y_pos;
306  int32_t z_pos;
308 
315  uint8_t spritenum;
316  uint8_t x_extent;
317  uint8_t y_extent;
318  uint8_t z_extent;
319  int8_t x_bb_offs;
320  int8_t y_bb_offs;
321  int8_t x_offs;
322  int8_t y_offs;
324 
325  TextEffectID fill_percent_te_id;
327 
328  uint16_t cur_speed;
329  uint8_t subspeed;
330  uint8_t acceleration;
331  uint32_t motion_counter;
332  uint8_t progress;
333 
335  uint16_t random_bits;
336 
340 
343  uint8_t cargo_subtype;
344  uint16_t cargo_cap;
345  uint16_t refit_cap;
346  uint16_t cargo_age_counter;
347  int8_t trip_occupancy;
348 
349  uint8_t day_counter;
350  uint8_t tick_counter;
351  uint8_t running_ticks;
352  uint16_t load_unload_ticks;
353 
354  uint8_t vehstatus;
355  uint8_t subtype;
357 
358  union {
361  };
362 
365 
367 
369 
374  virtual uint16_t GetMaxWeight() const
375  {
376  return 0;
377  }
378 
380 
381  void PreDestructor();
383  virtual ~Vehicle();
384 
385  void BeginLoading();
386  void CancelReservation(StationID next, Station *st);
387  void LeaveStation();
388 
391 
392  uint16_t &GetGroundVehicleFlags();
393  const uint16_t &GetGroundVehicleFlags() const;
394 
396 
397  void HandleLoading(bool mode = false);
398 
407  virtual void MarkDirty() {}
408 
413  virtual void UpdateDeltaXY() {}
414 
428  inline uint GetOldAdvanceSpeed(uint speed)
429  {
430  return (this->direction & 1) ? speed : speed * 3 / 4;
431  }
432 
445  static inline uint GetAdvanceSpeed(uint speed)
446  {
447  return speed * 3 / 4;
448  }
449 
457  inline uint GetAdvanceDistance()
458  {
459  return (this->direction & 1) ? TILE_AXIAL_DISTANCE : TILE_CORNER_DISTANCE * 2;
460  }
461 
466  virtual ExpensesType GetExpenseType([[maybe_unused]] bool income) const { return EXPENSES_OTHER; }
467 
472  virtual void PlayLeaveStationSound([[maybe_unused]] bool force = false) const {}
473 
477  virtual bool IsPrimaryVehicle() const { return false; }
478 
479  const Engine *GetEngine() const;
480 
486  virtual void GetImage([[maybe_unused]] Direction direction, [[maybe_unused]] EngineImageType image_type, [[maybe_unused]] VehicleSpriteSeq *result) const { result->Clear(); }
487 
488  const GRFFile *GetGRF() const;
489  uint32_t GetGRFID() const;
490 
495  inline void InvalidateNewGRFCache()
496  {
497  this->grf_cache.cache_valid = 0;
498  }
499 
505  {
506  for (Vehicle *u = this; u != nullptr; u = u->Next()) {
507  u->InvalidateNewGRFCache();
508  }
509  }
510 
515  debug_inline bool IsGroundVehicle() const
516  {
517  return this->type == VEH_TRAIN || this->type == VEH_ROAD;
518  }
519 
524  virtual int GetDisplaySpeed() const { return 0; }
525 
530  virtual int GetDisplayMaxSpeed() const { return 0; }
531 
536  virtual int GetCurrentMaxSpeed() const { return 0; }
537 
542  virtual Money GetRunningCost() const { return 0; }
543 
548  virtual bool IsInDepot() const { return false; }
549 
554  virtual bool IsChainInDepot() const { return this->IsInDepot(); }
555 
560  bool IsStoppedInDepot() const
561  {
562  assert(this == this->First());
563  /* Free wagons have no VS_STOPPED state */
564  if (this->IsPrimaryVehicle() && !(this->vehstatus & VS_STOPPED)) return false;
565  return this->IsChainInDepot();
566  }
567 
572  virtual bool Tick() { return true; };
573 
577  virtual void OnNewCalendarDay() {};
578 
582  virtual void OnNewEconomyDay() {};
583 
584  void ShiftDates(TimerGameEconomy::Date interval);
585 
591  virtual uint Crash(bool flooded = false);
592 
605  virtual Trackdir GetVehicleTrackdir() const { return INVALID_TRACKDIR; }
606 
611  Money GetDisplayRunningCost() const { return (this->GetRunningCost() >> 8); }
612 
617  Money GetDisplayProfitThisYear() const { return (this->profit_this_year >> 8); }
618 
623  Money GetDisplayProfitLastYear() const { return (this->profit_last_year >> 8); }
624 
625  void SetNext(Vehicle *next);
626 
632  inline Vehicle *Next() const { return this->next; }
633 
639  inline Vehicle *Previous() const { return this->previous; }
640 
645  inline Vehicle *First() const { return this->first; }
646 
651  inline Vehicle *Last()
652  {
653  Vehicle *v = this;
654  while (v->Next() != nullptr) v = v->Next();
655  return v;
656  }
657 
662  inline const Vehicle *Last() const
663  {
664  const Vehicle *v = this;
665  while (v->Next() != nullptr) v = v->Next();
666  return v;
667  }
668 
674  inline Vehicle *Move(int n)
675  {
676  Vehicle *v = this;
677  if (n < 0) {
678  for (int i = 0; i != n && v != nullptr; i--) v = v->Previous();
679  } else {
680  for (int i = 0; i != n && v != nullptr; i++) v = v->Next();
681  }
682  return v;
683  }
684 
690  inline const Vehicle *Move(int n) const
691  {
692  const Vehicle *v = this;
693  if (n < 0) {
694  for (int i = 0; i != n && v != nullptr; i--) v = v->Previous();
695  } else {
696  for (int i = 0; i != n && v != nullptr; i++) v = v->Next();
697  }
698  return v;
699  }
700 
705  inline Order *GetFirstOrder() const { return (this->orders == nullptr) ? nullptr : this->orders->GetFirstOrder(); }
706 
707  void AddToShared(Vehicle *shared_chain);
708  void RemoveFromShared();
709 
714  inline Vehicle *NextShared() const { return this->next_shared; }
715 
720  inline Vehicle *PreviousShared() const { return this->previous_shared; }
721 
726  inline Vehicle *FirstShared() const { return (this->orders == nullptr) ? this->First() : this->orders->GetFirstSharedVehicle(); }
727 
732  inline bool IsOrderListShared() const { return this->orders != nullptr && this->orders->IsShared(); }
733 
738  inline VehicleOrderID GetNumOrders() const { return (this->orders == nullptr) ? 0 : this->orders->GetNumOrders(); }
739 
744  inline VehicleOrderID GetNumManualOrders() const { return (this->orders == nullptr) ? 0 : this->orders->GetNumManualOrders(); }
745 
751  {
752  return (this->orders == nullptr) ? INVALID_STATION : this->orders->GetNextStoppingStation(this);
753  }
754 
755  void ResetRefitCaps();
756 
757  void ReleaseUnitNumber();
758 
766  {
767  this->CopyConsistPropertiesFrom(src);
768 
769  this->ReleaseUnitNumber();
770  this->unitnumber = src->unitnumber;
771 
772  this->current_order = src->current_order;
773  this->dest_tile = src->dest_tile;
774 
775  this->profit_this_year = src->profit_this_year;
776  this->profit_last_year = src->profit_last_year;
777 
778  src->unitnumber = 0;
779  }
780 
781 
782  bool HandleBreakdown();
783 
784  bool NeedsAutorenewing(const Company *c, bool use_renew_setting = true) const;
785 
786  bool NeedsServicing() const;
787  bool NeedsAutomaticServicing() const;
788 
796  virtual TileIndex GetOrderStationLocation([[maybe_unused]] StationID station) { return INVALID_TILE; }
797 
798  virtual TileIndex GetCargoTile() const { return this->tile; }
799 
805  virtual ClosestDepot FindClosestDepot() { return {}; }
806 
807  virtual void SetDestTile(TileIndex tile) { this->dest_tile = tile; }
808 
810 
811  void UpdateVisualEffect(bool allow_power_change = true);
812  void ShowVisualEffect() const;
813 
814  void UpdatePosition();
815  void UpdateViewport(bool dirty);
816  void UpdateBoundingBoxCoordinates(bool update_cache) const;
818  bool MarkAllViewportsDirty() const;
819 
820  inline uint16_t GetServiceInterval() const { return this->service_interval; }
821 
822  inline void SetServiceInterval(uint16_t interval) { this->service_interval = interval; }
823 
824  inline bool ServiceIntervalIsCustom() const { return HasBit(this->vehicle_flags, VF_SERVINT_IS_CUSTOM); }
825 
826  inline bool ServiceIntervalIsPercent() const { return HasBit(this->vehicle_flags, VF_SERVINT_IS_PERCENT); }
827 
828  inline void SetServiceIntervalIsCustom(bool on) { AssignBit(this->vehicle_flags, VF_SERVINT_IS_CUSTOM, on); }
829 
830  inline void SetServiceIntervalIsPercent(bool on) { AssignBit(this->vehicle_flags, VF_SERVINT_IS_PERCENT, on); }
831 
832  bool HasFullLoadOrder() const;
833  bool HasConditionalOrder() const;
834  bool HasUnbunchingOrder() const;
835  void LeaveUnbunchingDepot();
836  bool IsWaitingForUnbunching() const;
837 
838 private:
844  {
845  if (this->GetNumManualOrders() > 0) {
846  /* Advance to next real order */
847  do {
848  this->cur_real_order_index++;
849  if (this->cur_real_order_index >= this->GetNumOrders()) this->cur_real_order_index = 0;
850  } while (this->GetOrder(this->cur_real_order_index)->IsType(OT_IMPLICIT));
851  } else {
852  this->cur_real_order_index = 0;
853  }
854  }
855 
856 public:
863  {
864  if (this->cur_implicit_order_index == this->cur_real_order_index) {
865  /* Increment real order index as well */
866  this->SkipToNextRealOrderIndex();
867  }
868 
869  assert(this->cur_real_order_index == 0 || this->cur_real_order_index < this->GetNumOrders());
870 
871  /* Advance to next implicit order */
872  do {
873  this->cur_implicit_order_index++;
874  if (this->cur_implicit_order_index >= this->GetNumOrders()) this->cur_implicit_order_index = 0;
875  } while (this->cur_implicit_order_index != this->cur_real_order_index && !this->GetOrder(this->cur_implicit_order_index)->IsType(OT_IMPLICIT));
876 
877  InvalidateVehicleOrder(this, 0);
878  }
879 
887  {
888  if (this->cur_implicit_order_index == this->cur_real_order_index) {
889  /* Increment both real and implicit order */
891  } else {
892  /* Increment real order only */
893  this->SkipToNextRealOrderIndex();
894  InvalidateVehicleOrder(this, 0);
895  }
896  }
897 
902  {
903  /* Make sure the index is valid */
904  if (this->cur_real_order_index >= this->GetNumOrders()) this->cur_real_order_index = 0;
905 
906  if (this->GetNumManualOrders() > 0) {
907  /* Advance to next real order */
908  while (this->GetOrder(this->cur_real_order_index)->IsType(OT_IMPLICIT)) {
909  this->cur_real_order_index++;
910  if (this->cur_real_order_index >= this->GetNumOrders()) this->cur_real_order_index = 0;
911  }
912  } else {
913  this->cur_real_order_index = 0;
914  }
915  }
916 
922  inline Order *GetOrder(int index) const
923  {
924  return (this->orders == nullptr) ? nullptr : this->orders->GetOrderAt(index);
925  }
926 
931  inline Order *GetLastOrder() const
932  {
933  return (this->orders == nullptr) ? nullptr : this->orders->GetLastOrder();
934  }
935 
936  bool IsEngineCountable() const;
937  bool HasEngineType() const;
938  bool HasDepotOrder() const;
939  void HandlePathfindingResult(bool path_found);
940 
945  debug_inline bool IsFrontEngine() const
946  {
947  return this->IsGroundVehicle() && HasBit(this->subtype, GVSF_FRONT);
948  }
949 
954  inline bool IsArticulatedPart() const
955  {
956  return this->IsGroundVehicle() && HasBit(this->subtype, GVSF_ARTICULATED_PART);
957  }
958 
963  inline bool HasArticulatedPart() const
964  {
965  return this->Next() != nullptr && this->Next()->IsArticulatedPart();
966  }
967 
974  {
975  assert(this->HasArticulatedPart());
976  return this->Next();
977  }
978 
984  {
985  Vehicle *v = this;
986  while (v->IsArticulatedPart()) v = v->Previous();
987  return v;
988  }
989 
994  inline const Vehicle *GetFirstEnginePart() const
995  {
996  const Vehicle *v = this;
997  while (v->IsArticulatedPart()) v = v->Previous();
998  return v;
999  }
1000 
1006  {
1007  Vehicle *v = this;
1008  while (v->HasArticulatedPart()) v = v->GetNextArticulatedPart();
1009  return v;
1010  }
1011 
1016  inline Vehicle *GetNextVehicle() const
1017  {
1018  const Vehicle *v = this;
1019  while (v->HasArticulatedPart()) v = v->GetNextArticulatedPart();
1020 
1021  /* v now contains the last articulated part in the engine */
1022  return v->Next();
1023  }
1024 
1029  inline Vehicle *GetPrevVehicle() const
1030  {
1031  Vehicle *v = this->Previous();
1032  while (v != nullptr && v->IsArticulatedPart()) v = v->Previous();
1033 
1034  return v;
1035  }
1036 
1041  struct OrderIterator {
1042  typedef Order value_type;
1043  typedef Order *pointer;
1044  typedef Order &reference;
1045  typedef size_t difference_type;
1046  typedef std::forward_iterator_tag iterator_category;
1047 
1048  explicit OrderIterator(OrderList *list) : list(list), prev(nullptr)
1049  {
1050  this->order = (this->list == nullptr) ? nullptr : this->list->GetFirstOrder();
1051  }
1052 
1053  bool operator==(const OrderIterator &other) const { return this->order == other.order; }
1054  bool operator!=(const OrderIterator &other) const { return !(*this == other); }
1055  Order * operator*() const { return this->order; }
1056  OrderIterator & operator++()
1057  {
1058  this->prev = (this->prev == nullptr) ? this->list->GetFirstOrder() : this->prev->next;
1059  this->order = (this->prev == nullptr) ? nullptr : this->prev->next;
1060  return *this;
1061  }
1062 
1063  private:
1064  OrderList *list;
1065  Order *order;
1066  Order *prev;
1067  };
1068 
1073  OrderList *list;
1074  IterateWrapper(OrderList *list = nullptr) : list(list) {}
1075  OrderIterator begin() { return OrderIterator(this->list); }
1076  OrderIterator end() { return OrderIterator(nullptr); }
1077  bool empty() { return this->begin() == this->end(); }
1078  };
1079 
1084  IterateWrapper Orders() const { return IterateWrapper(this->orders); }
1085 
1086  uint32_t GetDisplayMaxWeight() const;
1087  uint32_t GetDisplayMinPowerToWeight() const;
1088 };
1089 
1094 template <class T, VehicleType Type>
1095 struct SpecializedVehicle : public Vehicle {
1096  static const VehicleType EXPECTED_TYPE = Type;
1097 
1099 
1103  inline SpecializedVehicle() : Vehicle(Type)
1104  {
1105  this->sprite_cache.sprite_seq.count = 1;
1106  }
1107 
1112  inline T *First() const { return (T *)this->Vehicle::First(); }
1113 
1118  inline T *Last() { return (T *)this->Vehicle::Last(); }
1119 
1124  inline const T *Last() const { return (const T *)this->Vehicle::Last(); }
1125 
1130  inline T *Next() const { return (T *)this->Vehicle::Next(); }
1131 
1136  inline T *Previous() const { return (T *)this->Vehicle::Previous(); }
1137 
1143  inline T *GetNextArticulatedPart() { return (T *)this->Vehicle::GetNextArticulatedPart(); }
1144 
1150  inline T *GetNextArticulatedPart() const { return (T *)this->Vehicle::GetNextArticulatedPart(); }
1151 
1156  inline T *GetFirstEnginePart() { return (T *)this->Vehicle::GetFirstEnginePart(); }
1157 
1162  inline const T *GetFirstEnginePart() const { return (const T *)this->Vehicle::GetFirstEnginePart(); }
1163 
1168  inline T *GetLastEnginePart() { return (T *)this->Vehicle::GetLastEnginePart(); }
1169 
1174  inline T *GetNextVehicle() const { return (T *)this->Vehicle::GetNextVehicle(); }
1175 
1180  inline T *GetPrevVehicle() const { return (T *)this->Vehicle::GetPrevVehicle(); }
1181 
1187  static inline bool IsValidID(size_t index)
1188  {
1189  return Vehicle::IsValidID(index) && Vehicle::Get(index)->type == Type;
1190  }
1191 
1196  static inline T *Get(size_t index)
1197  {
1198  return (T *)Vehicle::Get(index);
1199  }
1200 
1205  static inline T *GetIfValid(size_t index)
1206  {
1207  return IsValidID(index) ? Get(index) : nullptr;
1208  }
1209 
1215  static inline T *From(Vehicle *v)
1216  {
1217  assert(v->type == Type);
1218  return (T *)v;
1219  }
1220 
1226  static inline const T *From(const Vehicle *v)
1227  {
1228  assert(v->type == Type);
1229  return (const T *)v;
1230  }
1231 
1237  inline void UpdateViewport(bool force_update, bool update_delta)
1238  {
1239  bool sprite_has_changed = false;
1240 
1241  /* Skip updating sprites on dedicated servers without screen */
1242  if (_network_dedicated) return;
1243 
1244  /* Explicitly choose method to call to prevent vtable dereference -
1245  * it gives ~3% runtime improvements in games with many vehicles */
1246  if (update_delta) ((T *)this)->T::UpdateDeltaXY();
1247 
1248  /*
1249  * Only check for a new sprite sequence if the vehicle direction
1250  * has changed since we last checked it, assuming that otherwise
1251  * there won't be enough change in bounding box or offsets to need
1252  * to resolve a new sprite.
1253  */
1254  if (this->direction != this->sprite_cache.last_direction || this->sprite_cache.is_viewport_candidate) {
1255  VehicleSpriteSeq seq;
1256 
1257  ((T*)this)->T::GetImage(this->direction, EIT_ON_MAP, &seq);
1258  if (this->sprite_cache.sprite_seq != seq) {
1259  sprite_has_changed = true;
1260  this->sprite_cache.sprite_seq = seq;
1261  }
1262 
1263  this->sprite_cache.last_direction = this->direction;
1264  this->sprite_cache.revalidate_before_draw = false;
1265  } else {
1266  /*
1267  * A change that could potentially invalidate the sprite has been
1268  * made, signal that we should still resolve it before drawing on a
1269  * viewport.
1270  */
1271  this->sprite_cache.revalidate_before_draw = true;
1272  }
1273 
1274  if (force_update || sprite_has_changed) {
1275  this->Vehicle::UpdateViewport(true);
1276  }
1277  }
1278 
1284  static Pool::IterateWrapper<T> Iterate(size_t from = 0) { return Pool::IterateWrapper<T>(from); }
1285 };
1286 
1288 static const int32_t INVALID_COORD = 0x7fffffff;
1289 
1290 #endif /* VEHICLE_BASE_H */
Properties for front vehicles/consists.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr T AssignBit(T &x, const uint8_t y, bool value)
Assigns a bit in a variable.
uint8_t CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:22
Base class for cargo packets.
Common return value for all commands.
Definition: command_type.h:23
Minimal stack that uses a pool to avoid pointers.
uint64_t TickCounter
The type that the tick counter is stored in.
CargoList that is used for vehicles.
Definition: cargopacket.h:351
Types related to commands.
DoCommandFlag
List of flags for a command.
Definition: command_type.h:374
Owner
Enum for all companies/owners.
Definition: company_type.h:18
Direction
Defines the 8 directions on the map.
ExpensesType
Types of expenses.
Definition: economy_type.h:172
@ EXPENSES_OTHER
Other expenses.
Definition: economy_type.h:185
Types related to engines.
uint16_t EngineID
Unique identification number of an engine.
Definition: engine_type.h:21
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:18
uint32_t PaletteID
The number of the palette.
Definition: gfx_type.h:19
virtual void MarkDirty()
Marks the vehicles to be redrawn and updates cached variables.
Definition: vehicle_base.h:407
Types of a group.
uint16_t GroupID
Type for all group identifiers.
Definition: group_type.h:13
Functions related to memory operations.
bool _network_dedicated
are we a dedicated server?
Definition: network.cpp:68
Basic functions/variables used all over the place.
Base class for orders.
void InvalidateVehicleOrder(const Vehicle *v, int data)
Updates the widgets of a vehicle which contains the order-data.
Definition: order_cmd.cpp:235
Functions related to orders.
uint8_t VehicleOrderID
The index of an order within its current vehicle (not pool related)
Definition: order_type.h:15
Functions/types related to saving and loading games.
Various front vehicle properties that are preserved when autoreplacing, using order-backup or switchi...
Definition: base_consist.h:17
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
Definition: base_consist.h:31
VehicleOrderID cur_implicit_order_index
The index to the current implicit order.
Definition: base_consist.h:32
uint16_t service_interval
The interval for (automatic) servicing; either in days or %.
Definition: base_consist.h:29
void CopyConsistPropertiesFrom(const BaseConsist *src)
Copy properties of other BaseConsist.
uint16_t vehicle_flags
Used for gradual loading and other miscellaneous things (.
Definition: base_consist.h:34
Base vehicle class.
Definition: vehicle_type.h:50
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:51
Helper class to perform the cargo payment.
Definition: economy_base.h:24
Structure to return information about the closest depot location, and whether it could be found.
Definition: vehicle_base.h:230
DestinationID destination
The DestinationID as used for orders.
Definition: vehicle_base.h:232
Dynamic data of a loaded NewGRF.
Definition: newgrf.h:108
Cached, frequently calculated values.
Cache for vehicle sprites and values relating to whether they should be updated before drawing,...
Definition: vehicle_base.h:195
bool revalidate_before_draw
We need to do a GetImage() and check bounds before drawing this sprite.
Definition: vehicle_base.h:197
VehicleSpriteSeq sprite_seq
Vehicle appearance.
Definition: vehicle_base.h:200
bool is_viewport_candidate
This vehicle can potentially be drawn on a viewport.
Definition: vehicle_base.h:198
Direction last_direction
Last direction we obtained sprites for.
Definition: vehicle_base.h:196
Rect old_coord
Co-ordinates from the last valid bounding box.
Definition: vehicle_base.h:199
Cached often queried (NewGRF) values.
Definition: vehicle_base.h:68
uint32_t position_in_vehicle
Cache for NewGRF var 4D.
Definition: vehicle_base.h:74
uint32_t position_consist_length
Cache for NewGRF var 40.
Definition: vehicle_base.h:70
uint32_t consist_cargo_information
Cache for NewGRF var 42. (Note: The cargotype is untranslated in the cache because the accessing GRF ...
Definition: vehicle_base.h:72
uint8_t cache_valid
Bitset that indicates which cache values are valid.
Definition: vehicle_base.h:75
uint32_t company_information
Cache for NewGRF var 43.
Definition: vehicle_base.h:73
uint32_t position_same_id_length
Cache for NewGRF var 41.
Definition: vehicle_base.h:71
Shared order list linking together the linked list of orders and the list of vehicles sharing this or...
Definition: order_base.h:259
StationIDStack GetNextStoppingStation(const Vehicle *v, const Order *first=nullptr, uint hops=0) const
Recursively determine the next deterministic station to stop at.
Definition: order_cmd.cpp:399
Order * GetLastOrder() const
Get the last order of the order chain.
Definition: order_base.h:305
Order * GetOrderAt(int index) const
Get a certain order of the order chain.
Definition: order_cmd.cpp:341
VehicleOrderID GetNumOrders() const
Get number of orders in the order list.
Definition: order_base.h:319
VehicleOrderID GetNumManualOrders() const
Get number of manually added orders in the order list.
Definition: order_base.h:325
Order * GetFirstOrder() const
Get the first order of the order chain.
Definition: order_base.h:297
Vehicle * GetFirstSharedVehicle() const
Get the first vehicle of this vehicle chain.
Definition: order_base.h:344
bool IsShared() const
Is this a shared order list?
Definition: order_base.h:338
Order * next
Pointer to next order. If nullptr, end of list.
Definition: order_base.h:59
Combination of a palette sprite and a 'real' sprite.
Definition: gfx_type.h:23
SpriteID sprite
The 'real' sprite.
Definition: gfx_type.h:24
PaletteID pal
The palette (use PAL_NONE) if not needed)
Definition: gfx_type.h:25
Base class for all PoolItems.
Definition: pool_type.hpp:237
Tindex index
Index of this pool item.
Definition: pool_type.hpp:238
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:339
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:328
Base class for all pools.
Definition: pool_type.hpp:80
Specification of a rectangle with absolute coordinates of all edges.
Simulated cargo type and capacity for prediction of future links.
Definition: vehicle_base.h:218
CargoID cargo
Cargo type the vehicle will be carrying.
Definition: vehicle_base.h:219
uint16_t capacity
Capacity the vehicle will have.
Definition: vehicle_base.h:220
uint16_t remaining
Capacity remaining from before the previous refit.
Definition: vehicle_base.h:221
Class defining several overloaded accessors so we don't have to cast vehicle types that often.
T * Previous() const
Get previous vehicle in the chain.
T * GetLastEnginePart()
Get the last part of an articulated engine.
T * GetPrevVehicle() const
Get the previous real (non-articulated part) vehicle in the consist.
T * Last()
Get the last vehicle in the chain.
static T * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
T * GetNextVehicle() const
Get the next real (non-articulated part) vehicle in the consist.
SpecializedVehicle()
Set vehicle type correctly.
T * Next() const
Get next vehicle in the chain.
void UpdateViewport(bool force_update, bool update_delta)
Update vehicle sprite- and position caches.
T * GetFirstEnginePart()
Get the first part of an articulated engine.
T * GetNextArticulatedPart()
Get the next part of an articulated engine.
static Pool::IterateWrapper< T > Iterate(size_t from=0)
Returns an iterable ensemble of all valid vehicles of type T.
static bool IsValidID(size_t index)
Tests whether given index is a valid index for vehicle of this type.
T * First() const
Get the first vehicle in the chain.
SpecializedVehicle< T, Type > SpecializedVehicleBase
Our type.
static const VehicleType EXPECTED_TYPE
Specialized type.
static T * GetIfValid(size_t index)
Returns vehicle if the index is a valid index for this vehicle type.
static T * Get(size_t index)
Gets vehicle with given index.
Station data structure.
Definition: station_base.h:439
Cached often queried values common to all vehicles.
Definition: vehicle_base.h:125
uint8_t cached_vis_effect
Visual effect to show (see VisualEffect)
Definition: vehicle_base.h:129
uint16_t cached_cargo_age_period
Number of ticks before carried cargo is aged.
Definition: vehicle_base.h:127
uint16_t cached_max_speed
Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
Definition: vehicle_base.h:126
Sprite sequence for a vehicle part.
Definition: vehicle_base.h:135
bool IsValid() const
Check whether the sequence contains any sprites.
Definition: vehicle_base.h:152
void GetBounds(Rect *bounds) const
Determine shared bounds of all sprites.
Definition: vehicle.cpp:103
void Set(SpriteID sprite)
Assign a single sprite to the sequence.
Definition: vehicle_base.h:168
void Clear()
Clear all information.
Definition: vehicle_base.h:160
void CopyWithoutPalette(const VehicleSpriteSeq &src)
Copy data from another sprite sequence, while dropping all recolouring information.
Definition: vehicle_base.h:178
void Draw(int x, int y, PaletteID default_pal, bool force_pal) const
Draw the sprite sequence.
Definition: vehicle.cpp:131
Iterable ensemble of orders.
Iterator to iterate orders Supports deletion of current order.
Vehicle data structure.
Definition: vehicle_base.h:244
Money GetDisplayProfitThisYear() const
Gets the profit vehicle had this year.
Definition: vehicle_base.h:617
CargoPayment * cargo_payment
The cargo payment we're currently in.
Definition: vehicle_base.h:277
const Vehicle * GetFirstEnginePart() const
Get the first part of an articulated engine.
Definition: vehicle_base.h:994
EngineID engine_type
The type of engine used for this vehicle.
Definition: vehicle_base.h:323
Vehicle * Move(int n)
Get the vehicle at offset n of this vehicle chain.
Definition: vehicle_base.h:674
uint16_t cargo_age_counter
Ticks till cargo is aged next.
Definition: vehicle_base.h:346
virtual int GetDisplaySpeed() const
Gets the speed in km-ish/h that can be sent into SetDParam for string processing.
Definition: vehicle_base.h:524
Vehicle * Previous() const
Get the previous vehicle of this vehicle.
Definition: vehicle_base.h:639
static uint GetAdvanceSpeed(uint speed)
Determines the effective vehicle movement speed.
Definition: vehicle_base.h:445
int32_t z_pos
z coordinate.
Definition: vehicle_base.h:306
uint16_t & GetGroundVehicleFlags()
Access the ground vehicle flags of the vehicle.
Definition: vehicle.cpp:3185
Direction direction
facing
Definition: vehicle_base.h:307
void ShiftDates(TimerGameEconomy::Date interval)
Shift all dates by given interval.
Definition: vehicle.cpp:777
friend void AfterLoadVehiclesPhase1(bool part_of_load)
So we can set the previous and first pointers while loading.
Definition: vehicle_sl.cpp:256
StationIDStack GetNextStoppingStation() const
Get the next station the vehicle will stop at.
Definition: vehicle_base.h:750
TimerGameEconomy::Date economy_age
Age in economy days.
Definition: vehicle_base.h:293
bool IsOrderListShared() const
Check if we share our orders with another vehicle.
Definition: vehicle_base.h:732
Vehicle * GetNextArticulatedPart() const
Get the next part of an articulated engine.
Definition: vehicle_base.h:973
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
Definition: vehicle.cpp:747
void IncrementRealOrderIndex()
Advanced cur_real_order_index to the next real order, keeps care of the wrap-around and invalidates t...
Definition: vehicle_base.h:886
virtual uint Crash(bool flooded=false)
Crash the (whole) vehicle chain.
Definition: vehicle.cpp:280
bool IsStoppedInDepot() const
Check whether the vehicle is in the depot and stopped.
Definition: vehicle_base.h:560
bool HasDepotOrder() const
Checks if a vehicle has a depot in its order list.
Definition: order_cmd.cpp:1851
void LeaveStation()
Perform all actions when leaving a station.
Definition: vehicle.cpp:2350
virtual bool IsChainInDepot() const
Check whether the whole vehicle chain is in the depot.
Definition: vehicle_base.h:554
void AddToShared(Vehicle *shared_chain)
Adds this vehicle to a shared vehicle chain.
Definition: vehicle.cpp:2966
VehicleCargoList cargo
The cargo this vehicle is carrying.
Definition: vehicle_base.h:341
Vehicle * First() const
Get the first vehicle of this vehicle chain.
Definition: vehicle_base.h:645
uint8_t x_extent
x-extent of vehicle bounding box
Definition: vehicle_base.h:316
Vehicle ** hash_tile_prev
NOSAVE: Previous vehicle in the tile location hash.
Definition: vehicle_base.h:285
bool HasUnbunchingOrder() const
Check if the current vehicle has an unbunching order.
Definition: vehicle.cpp:2489
TimerGameEconomy::Date date_of_last_service
Last economy date the vehicle had a service at a depot.
Definition: vehicle_base.h:295
uint16_t cargo_cap
total capacity
Definition: vehicle_base.h:344
StationID last_loading_station
Last station the vehicle has stopped at and could possibly leave from with any cargo loaded.
Definition: vehicle_base.h:338
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
Definition: vehicle_base.h:738
uint8_t subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
Definition: vehicle_base.h:355
Vehicle * GetLastEnginePart()
Get the last part of an articulated engine.
virtual void UpdateDeltaXY()
Updates the x and y offsets and the size of the sprite used for this vehicle.
Definition: vehicle_base.h:413
uint16_t random_bits
Bits used for randomized variational spritegroups.
Definition: vehicle_base.h:335
void ReleaseUnitNumber()
Release the vehicle's unit number.
Definition: vehicle.cpp:2419
void UpdateBoundingBoxCoordinates(bool update_cache) const
Update the bounding box co-ordinates of the vehicle.
Definition: vehicle.cpp:1702
uint8_t day_counter
Increased by one for each day.
Definition: vehicle_base.h:349
void HandleLoading(bool mode=false)
Handle the loading of the vehicle; when not it skips through dummy orders and does nothing in all oth...
Definition: vehicle.cpp:2430
Money profit_this_year
Profit this year << 8, low 8 bits are fract.
Definition: vehicle_base.h:273
virtual void GetImage([[maybe_unused]] Direction direction, [[maybe_unused]] EngineImageType image_type, [[maybe_unused]] VehicleSpriteSeq *result) const
Gets the sprite to show for the given direction.
Definition: vehicle_base.h:486
bool HasArticulatedPart() const
Check if an engine has an articulated part.
Definition: vehicle_base.h:963
SpriteID colourmap
NOSAVE: cached colour mapping.
Definition: vehicle_base.h:288
uint8_t breakdown_ctr
Counter for managing breakdown events.
Definition: vehicle_base.h:299
uint GetOldAdvanceSpeed(uint speed)
Determines the effective direction-specific vehicle movement speed.
Definition: vehicle_base.h:428
uint8_t breakdown_delay
Counter for managing breakdown length.
Definition: vehicle_base.h:300
uint GetAdvanceDistance()
Determines the vehicle "progress" needed for moving a step.
Definition: vehicle_base.h:457
GroupID group_id
Index of group Pool array.
Definition: vehicle_base.h:366
friend bool LoadOldVehicle(LoadgameState *ls, int num)
So we can set the proper next pointer while loading.
CommandCost SendToDepot(DoCommandFlag flags, DepotCommand command)
Send this vehicle to the depot using the given command(s).
Definition: vehicle.cpp:2583
virtual int GetDisplayMaxSpeed() const
Gets the maximum speed in km-ish/h that can be sent into SetDParam for string processing.
Definition: vehicle_base.h:530
void IncrementImplicitOrderIndex()
Increments cur_implicit_order_index, keeps care of the wrap-around and invalidates the GUI.
Definition: vehicle_base.h:862
uint8_t z_extent
z-extent of vehicle bounding box
Definition: vehicle_base.h:318
TimerGameCalendar::Date date_of_last_service_newgrf
Last calendar date the vehicle had a service at a depot, unchanged by the date cheat to protect again...
Definition: vehicle_base.h:296
Vehicle * first
NOSAVE: pointer to the first vehicle in the chain.
Definition: vehicle_base.h:250
void CancelReservation(StationID next, Station *st)
Return all reserved cargo packets to the station and reset all packets staged for transfer.
Definition: vehicle.cpp:2334
Money profit_last_year
Profit last year << 8, low 8 bits are fract.
Definition: vehicle_base.h:274
virtual TileIndex GetOrderStationLocation([[maybe_unused]] StationID station)
Determine the location for the station where the vehicle goes to next.
Definition: vehicle_base.h:796
bool IsEngineCountable() const
Check if a vehicle is counted in num_engines in each company struct.
Definition: vehicle.cpp:714
Order * GetOrder(int index) const
Returns order 'index' of a vehicle or nullptr when it doesn't exists.
Definition: vehicle_base.h:922
virtual ~Vehicle()
We want to 'destruct' the right class.
Definition: vehicle.cpp:893
uint8_t subspeed
fractional speed
Definition: vehicle_base.h:329
bool IsArticulatedPart() const
Check if the vehicle is an articulated part of an engine.
Definition: vehicle_base.h:954
Vehicle * GetPrevVehicle() const
Get the previous real (non-articulated part) vehicle in the consist.
bool NeedsAutorenewing(const Company *c, bool use_renew_setting=true) const
Function to tell if a vehicle needs to be autorenewed.
Definition: vehicle.cpp:145
void UpdateVisualEffect(bool allow_power_change=true)
Update the cached visual effect.
Definition: vehicle.cpp:2664
Vehicle * Last()
Get the last vehicle of this vehicle chain.
Definition: vehicle_base.h:651
void LeaveUnbunchingDepot()
Leave an unbunching depot and calculate the next departure time for shared order vehicles.
Definition: vehicle.cpp:2514
Vehicle * GetFirstEnginePart()
Get the first part of an articulated engine.
Definition: vehicle_base.h:983
int8_t y_offs
y offset for vehicle sprite
Definition: vehicle_base.h:322
Vehicle * Next() const
Get the next vehicle of this vehicle.
Definition: vehicle_base.h:632
debug_inline bool IsFrontEngine() const
Check if the vehicle is a front engine.
Definition: vehicle_base.h:945
uint8_t acceleration
used by train & aircraft
Definition: vehicle_base.h:330
Vehicle * previous_shared
NOSAVE: pointer to the previous vehicle in the shared order chain.
Definition: vehicle_base.h:253
VehicleOrderID GetNumManualOrders() const
Get the number of manually added orders this vehicle has.
Definition: vehicle_base.h:744
int8_t trip_occupancy
NOSAVE: Occupancy of vehicle of the current trip (updated after leaving a station).
Definition: vehicle_base.h:347
int8_t x_bb_offs
x offset of vehicle bounding box
Definition: vehicle_base.h:319
Order current_order
The current order (+ status, like: loading)
Definition: vehicle_base.h:356
void PreDestructor()
Destroy all stuff that (still) needs the virtual functions to work properly.
Definition: vehicle.cpp:826
TimerGameTick::TickCounter last_loading_tick
Last TimerGameTick::counter tick that the vehicle has stopped at a station and could possibly leave w...
Definition: vehicle_base.h:339
CargoID cargo_type
type of cargo this vehicle is carrying
Definition: vehicle_base.h:342
void HandlePathfindingResult(bool path_found)
Handle the pathfinding result, especially the lost status.
Definition: vehicle.cpp:791
int8_t x_offs
x offset for vehicle sprite
Definition: vehicle_base.h:321
int32_t y_pos
y coordinate.
Definition: vehicle_base.h:305
int32_t x_pos
x coordinate.
Definition: vehicle_base.h:304
const GRFFile * GetGRF() const
Retrieve the NewGRF the vehicle is tied to.
Definition: vehicle.cpp:757
OrderList * orders
Pointer to the order list for this vehicle.
Definition: vehicle_base.h:359
const Vehicle * Move(int n) const
Get the vehicle at offset n of this vehicle chain.
Definition: vehicle_base.h:690
uint32_t GetDisplayMinPowerToWeight() const
Calculates the minimum power-to-weight ratio using the maximum weight of the ground vehicle.
Definition: vehicle.cpp:3259
const Vehicle * Last() const
Get the last vehicle of this vehicle chain.
Definition: vehicle_base.h:662
uint8_t y_extent
y-extent of vehicle bounding box
Definition: vehicle_base.h:317
virtual ClosestDepot FindClosestDepot()
Find the closest depot for this vehicle and tell us the location, DestinationID and whether we should...
Definition: vehicle_base.h:805
void UpdateViewport(bool dirty)
Update the vehicle on the viewport, updating the right hash and setting the new coordinates.
Definition: vehicle.cpp:1735
Order * old_orders
Only used during conversion of old save games.
Definition: vehicle_base.h:360
Money value
Value of the vehicle.
Definition: vehicle_base.h:275
bool MarkAllViewportsDirty() const
Marks viewports dirty where the vehicle's image is.
Definition: vehicle.cpp:1774
uint16_t refit_cap
Capacity left over from before last refit.
Definition: vehicle_base.h:345
void InvalidateNewGRFCache()
Invalidates cached NewGRF variables.
Definition: vehicle_base.h:495
uint8_t waiting_triggers
Triggers to be yet matched before rerandomizing the random bits.
Definition: vehicle_base.h:334
uint8_t vehstatus
Status.
Definition: vehicle_base.h:354
friend void FixOldVehicles()
Convert the old style vehicles into something that resembles the old new style savegames.
VehicleCache vcache
Cache of often used vehicle values.
Definition: vehicle_base.h:364
uint32_t motion_counter
counter to occasionally play a vehicle sound.
Definition: vehicle_base.h:331
NewGRFCache grf_cache
Cache of often used calculated NewGRF values.
Definition: vehicle_base.h:363
uint32_t GetGRFID() const
Retrieve the GRF ID of the NewGRF the vehicle is tied to.
Definition: vehicle.cpp:767
Order * GetFirstOrder() const
Get the first order of the vehicles order list.
Definition: vehicle_base.h:705
GroundVehicleCache * GetGroundVehicleCache()
Access the ground vehicle cache of the vehicle.
Definition: vehicle.cpp:3155
virtual void OnNewEconomyDay()
Calls the new economy day handler of the vehicle.
Definition: vehicle_base.h:582
Vehicle ** hash_tile_current
NOSAVE: Cache of the current hash chain.
Definition: vehicle_base.h:286
virtual void OnNewCalendarDay()
Calls the new calendar day handler of the vehicle.
Definition: vehicle_base.h:577
int8_t y_bb_offs
y offset of vehicle bounding box
Definition: vehicle_base.h:320
virtual int GetCurrentMaxSpeed() const
Calculates the maximum speed of the vehicle under its current conditions.
Definition: vehicle_base.h:536
virtual ExpensesType GetExpenseType([[maybe_unused]] bool income) const
Sets the expense type associated to this vehicle type.
Definition: vehicle_base.h:466
bool HasFullLoadOrder() const
Check if the current vehicle has a full load order.
Definition: vehicle.cpp:2465
virtual void PlayLeaveStationSound([[maybe_unused]] bool force=false) const
Play the sound associated with leaving the station.
Definition: vehicle_base.h:472
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
Definition: vehicle_base.h:477
void BeginLoading()
Prepare everything to begin the loading when arriving at a station.
Definition: vehicle.cpp:2203
uint16_t load_unload_ticks
Ticks to wait before starting next cycle.
Definition: vehicle_base.h:352
Money GetDisplayProfitLastYear() const
Gets the profit vehicle had last year.
Definition: vehicle_base.h:623
Vehicle * hash_tile_next
NOSAVE: Next vehicle in the tile location hash.
Definition: vehicle_base.h:284
uint8_t spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
Definition: vehicle_base.h:315
uint16_t cur_speed
current speed
Definition: vehicle_base.h:328
Vehicle * previous
NOSAVE: pointer to the previous vehicle in the chain.
Definition: vehicle_base.h:249
uint8_t cargo_subtype
Used for livery refits (NewGRF variations)
Definition: vehicle_base.h:343
bool HasEngineType() const
Check whether Vehicle::engine_type has any meaning.
Definition: vehicle.cpp:731
TimerGameCalendar::Date age
Age in calendar days.
Definition: vehicle_base.h:292
bool IsWaitingForUnbunching() const
Check whether a vehicle inside a depot is waiting for unbunching.
Definition: vehicle.cpp:2561
TextEffectID fill_percent_te_id
a text-effect id to a loading indicator object
Definition: vehicle_base.h:325
IterateWrapper Orders() const
Returns an iterable ensemble of orders of a vehicle.
Money GetDisplayRunningCost() const
Gets the running cost of a vehicle that can be sent into SetDParam for string processing.
Definition: vehicle_base.h:611
void SetNext(Vehicle *next)
Set the next vehicle of this vehicle.
Definition: vehicle.cpp:2937
Vehicle * FirstShared() const
Get the first vehicle of this vehicle chain.
Definition: vehicle_base.h:726
uint8_t breakdowns_since_last_service
Counter for the amount of breakdowns.
Definition: vehicle_base.h:301
Vehicle * next
pointer to the next vehicle in the chain
Definition: vehicle_base.h:248
TimerGameCalendar::Date max_age
Maximum age.
Definition: vehicle_base.h:294
MutableSpriteCache sprite_cache
Cache of sprites and values related to recalculating them, see MutableSpriteCache.
Definition: vehicle_base.h:368
uint16_t reliability
Reliability.
Definition: vehicle_base.h:297
uint32_t GetDisplayMaxWeight() const
Calculates the maximum weight of the ground vehicle when loaded.
Definition: vehicle.cpp:3244
Vehicle * NextShared() const
Get the next vehicle of the shared vehicle chain.
Definition: vehicle_base.h:714
void RemoveFromShared()
Removes the vehicle from the shared order list.
Definition: vehicle.cpp:2989
bool HandleBreakdown()
Handle all of the aspects of a vehicle breakdown This includes adding smoke and sounds,...
Definition: vehicle.cpp:1363
Vehicle * GetNextVehicle() const
Get the next real (non-articulated part) vehicle in the consist.
debug_inline bool IsGroundVehicle() const
Check if the vehicle is a ground vehicle.
Definition: vehicle_base.h:515
uint8_t progress
The percentage (if divided by 256) this vehicle already crossed the tile unit.
Definition: vehicle_base.h:332
void UpdatePositionAndViewport()
Update the position of the vehicle, and update the viewport.
Definition: vehicle.cpp:1764
Vehicle(VehicleType type=VEH_INVALID)
Vehicle constructor.
Definition: vehicle.cpp:361
Rect coord
NOSAVE: Graphical bounding box of the vehicle, i.e. what to redraw on moves.
Definition: vehicle_base.h:279
uint16_t reliability_spd_dec
Reliability decrease speed.
Definition: vehicle_base.h:298
uint8_t tick_counter
Increased by one for each tick.
Definition: vehicle_base.h:350
void SkipToNextRealOrderIndex()
Advance cur_real_order_index to the next real order.
Definition: vehicle_base.h:843
virtual bool IsInDepot() const
Check whether the vehicle is in the depot.
Definition: vehicle_base.h:548
TileIndex tile
Current tile index.
Definition: vehicle_base.h:264
virtual bool Tick()
Calls the tick handler of the vehicle.
Definition: vehicle_base.h:572
TileIndex dest_tile
Heading for this tile.
Definition: vehicle_base.h:271
void CopyVehicleConfigAndStatistics(Vehicle *src)
Copy certain configurations and statistics of a vehicle after successful autoreplace/renew The functi...
Definition: vehicle_base.h:765
bool NeedsServicing() const
Check if the vehicle needs to go to a depot in near future (if a opportunity presents itself) for ser...
Definition: vehicle.cpp:190
bool HasConditionalOrder() const
Check if the current vehicle has a conditional order.
Definition: vehicle.cpp:2477
virtual uint16_t GetMaxWeight() const
Calculates the weight value that this vehicle will have when fully loaded with its current cargo.
Definition: vehicle_base.h:374
void UpdatePosition()
Update the position of the vehicle.
Definition: vehicle.cpp:1693
virtual Money GetRunningCost() const
Gets the running cost of a vehicle.
Definition: vehicle_base.h:542
StationID last_station_visited
The last station we stopped at.
Definition: vehicle_base.h:337
void ResetRefitCaps()
Reset all refit_cap in the consist to cargo_cap.
Definition: vehicle.cpp:2411
void InvalidateNewGRFCacheOfChain()
Invalidates cached NewGRF variables of all vehicles in the chain (after the current vehicle)
Definition: vehicle_base.h:504
Vehicle * PreviousShared() const
Get the previous vehicle of the shared vehicle chain.
Definition: vehicle_base.h:720
uint8_t breakdown_chance
Current chance of breakdowns.
Definition: vehicle_base.h:302
void ShowVisualEffect() const
Draw visual effects (smoke and/or sparks) for a vehicle chain.
Definition: vehicle.cpp:2787
TimerGameCalendar::Year build_year
Year the vehicle has been built.
Definition: vehicle_base.h:291
Owner owner
Which company owns the vehicle?
Definition: vehicle_base.h:309
Order * GetLastOrder() const
Returns the last order of a vehicle, or nullptr if it doesn't exists.
Definition: vehicle_base.h:931
UnitID unitnumber
unit number, for display purposes only
Definition: vehicle_base.h:326
Vehicle * next_shared
pointer to the next vehicle that shares the order
Definition: vehicle_base.h:252
bool NeedsAutomaticServicing() const
Checks if the current order should be interrupted for a service-in-depot order.
Definition: vehicle.cpp:272
void DeleteUnreachedImplicitOrders()
Delete all implicit orders which were not reached.
Definition: vehicle.cpp:2164
uint8_t running_ticks
Number of ticks this vehicle was not stopped this day.
Definition: vehicle_base.h:351
Vehicle ** hash_viewport_prev
NOSAVE: Previous vehicle in the visual location hash.
Definition: vehicle_base.h:282
Vehicle * hash_viewport_next
NOSAVE: Next vehicle in the visual location hash.
Definition: vehicle_base.h:281
virtual Trackdir GetVehicleTrackdir() const
Returns the Trackdir on which the vehicle is currently located.
Definition: vehicle_base.h:605
void UpdateRealOrderIndex()
Skip implicit orders until cur_real_order_index is a non-implicit order.
Definition: vehicle_base.h:901
Functions related to text effects.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:95
Definition of the game-calendar-timer.
All types related to tracks.
Trackdir
Enumeration for tracks and directions.
Definition: track_type.h:67
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
Definition: track_type.h:86
Base types related to transport.
uint16_t UnitID
Type for the company global vehicle unit number.
VehiclePool _vehicle_pool("Vehicle")
The pool with all our precious vehicles.
GroundVehicleSubtypeFlags
Enum to handle ground vehicle subtypes.
Definition: vehicle_base.h:115
@ GVSF_ARTICULATED_PART
Articulated part of an engine.
Definition: vehicle_base.h:117
@ GVSF_FRONT
Leading engine of a consist.
Definition: vehicle_base.h:116
@ GVSF_MULTIHEADED
Engine is multiheaded (not used for road vehicles).
Definition: vehicle_base.h:121
@ GVSF_FREE_WAGON
First in a wagon chain (in depot) (not used for road vehicles).
Definition: vehicle_base.h:120
@ GVSF_WAGON
Wagon (not used for road vehicles).
Definition: vehicle_base.h:118
@ GVSF_ENGINE
Engine that can be front engine, but might be placed behind another engine (not used for road vehicle...
Definition: vehicle_base.h:119
bool LoadOldVehicle(LoadgameState *ls, int num)
Load the vehicles of an old style savegame.
VehicleFlags
Bit numbers in Vehicle::vehicle_flags.
Definition: vehicle_base.h:44
@ VF_STOP_LOADING
Don't load anymore during the next load cycle.
Definition: vehicle_base.h:51
@ VF_SERVINT_IS_PERCENT
Service interval is percent.
Definition: vehicle_base.h:54
@ VF_BUILT_AS_PROTOTYPE
Vehicle is a prototype (accepted as exclusive preview).
Definition: vehicle_base.h:47
@ VF_CARGO_UNLOADING
Vehicle is unloading cargo.
Definition: vehicle_base.h:46
@ VF_AUTOFILL_TIMETABLE
Whether the vehicle should fill in the timetable automatically.
Definition: vehicle_base.h:49
@ VF_PATHFINDER_LOST
Vehicle's pathfinder is lost.
Definition: vehicle_base.h:52
@ VF_AUTOFILL_PRES_WAIT_TIME
Whether non-destructive auto-fill should preserve waiting times.
Definition: vehicle_base.h:50
@ VF_LOADING_FINISHED
Vehicle has finished loading.
Definition: vehicle_base.h:45
@ VF_SERVINT_IS_CUSTOM
Service interval is custom.
Definition: vehicle_base.h:53
@ VF_TIMETABLE_STARTED
Whether the vehicle has started running on the timetable yet.
Definition: vehicle_base.h:48
VisualEffectSpawnModel
Models for spawning visual effects.
Definition: vehicle_base.h:101
@ VESM_ELECTRIC
Electric model.
Definition: vehicle_base.h:105
@ VESM_STEAM
Steam model.
Definition: vehicle_base.h:103
@ VESM_DIESEL
Diesel model.
Definition: vehicle_base.h:104
@ VESM_NONE
No visual effect.
Definition: vehicle_base.h:102
void FixOldVehicles()
Convert the old style vehicles into something that resembles the old new style savegames.
NewGRFCacheValidValues
Bit numbers used to indicate which of the NewGRFCache values are valid.
Definition: vehicle_base.h:58
@ NCVV_COMPANY_INFORMATION
This bit will be set if the NewGRF var 43 currently stored is valid.
Definition: vehicle_base.h:62
@ NCVV_CONSIST_CARGO_INFORMATION
This bit will be set if the NewGRF var 42 currently stored is valid.
Definition: vehicle_base.h:61
@ NCVV_POSITION_CONSIST_LENGTH
This bit will be set if the NewGRF var 40 currently stored is valid.
Definition: vehicle_base.h:59
@ NCVV_POSITION_SAME_ID_LENGTH
This bit will be set if the NewGRF var 41 currently stored is valid.
Definition: vehicle_base.h:60
@ NCVV_POSITION_IN_VEHICLE
This bit will be set if the NewGRF var 4D currently stored is valid.
Definition: vehicle_base.h:63
@ NCVV_END
End of the bits.
Definition: vehicle_base.h:64
VehStatus
Vehicle status bits in Vehicle::vehstatus.
Definition: vehicle_base.h:32
@ VS_UNCLICKABLE
Vehicle is not clickable by the user (shadow vehicles).
Definition: vehicle_base.h:35
@ VS_TRAIN_SLOWING
Train is slowing down.
Definition: vehicle_base.h:37
@ VS_AIRCRAFT_BROKEN
Aircraft is broken down.
Definition: vehicle_base.h:39
@ VS_SHADOW
Vehicle is a shadow vehicle.
Definition: vehicle_base.h:38
@ VS_STOPPED
Vehicle is stopped by the player.
Definition: vehicle_base.h:34
@ VS_HIDDEN
Vehicle is not visible.
Definition: vehicle_base.h:33
@ VS_CRASHED
Vehicle is crashed.
Definition: vehicle_base.h:40
@ VS_DEFPAL
Use default vehicle palette.
Definition: vehicle_base.h:36
VisualEffect
Meaning of the various bits of the visual effect.
Definition: vehicle_base.h:81
@ VE_TYPE_DEFAULT
Use default from engine class.
Definition: vehicle_base.h:88
@ VE_TYPE_COUNT
Number of bits used for the effect type.
Definition: vehicle_base.h:87
@ VE_OFFSET_CENTRE
Value of offset corresponding to a position above the centre of the vehicle.
Definition: vehicle_base.h:84
@ VE_TYPE_ELECTRIC
Electric sparks.
Definition: vehicle_base.h:91
@ VE_TYPE_START
First bit used for the type of effect.
Definition: vehicle_base.h:86
@ VE_OFFSET_COUNT
Number of bits used for the offset.
Definition: vehicle_base.h:83
@ VE_ADVANCED_EFFECT
Flag for advanced effects.
Definition: vehicle_base.h:94
@ VE_DISABLE_EFFECT
Flag to disable visual effect.
Definition: vehicle_base.h:93
@ VE_TYPE_STEAM
Steam plumes.
Definition: vehicle_base.h:89
@ VE_TYPE_DIESEL
Diesel fumes.
Definition: vehicle_base.h:90
@ VE_DEFAULT
Default value to indicate that visual effect should be based on engine class.
Definition: vehicle_base.h:97
@ VE_OFFSET_START
First bit that contains the offset (0 = front, 8 = centre, 15 = rear)
Definition: vehicle_base.h:82
@ VE_DISABLE_WAGON_POWER
Flag to disable wagon power.
Definition: vehicle_base.h:95
Pool< Vehicle, VehicleID, 512, 0xFF000 > VehiclePool
A vehicle pool for a little over 1 million vehicles.
Definition: vehicle_base.h:204
static const int32_t INVALID_COORD
Sentinel for an invalid coordinate.
EngineImageType
Visualisation contexts of vehicles and engines.
Definition: vehicle_type.h:78
@ EIT_ON_MAP
Vehicle drawn in viewport.
Definition: vehicle_type.h:79
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
@ VEH_INVALID
Non-existing type of vehicle.
Definition: vehicle_type.h:35
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
DepotCommand
Flags for goto depot commands.
Definition: vehicle_type.h:57