OpenTTD
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 "core/smallmap_type.hpp"
14 #include "track_type.h"
15 #include "command_type.h"
16 #include "order_base.h"
17 #include "cargopacket.h"
18 #include "texteff.hpp"
19 #include "engine_type.h"
20 #include "order_func.h"
21 #include "transport_type.h"
22 #include "group_type.h"
23 #include "base_consist.h"
24 #include "network/network.h"
25 #include <list>
26 #include <map>
27 
29 enum VehStatus {
30  VS_HIDDEN = 0x01,
31  VS_STOPPED = 0x02,
32  VS_UNCLICKABLE = 0x04,
33  VS_DEFPAL = 0x08,
35  VS_SHADOW = 0x20,
37  VS_CRASHED = 0x80,
38 };
39 
52 };
53 
62 };
63 
65 struct NewGRFCache {
66  /* Values calculated when they are requested for the first time after invalidating the NewGRF cache. */
72  uint8 cache_valid;
73 };
74 
80 
87 
91 
92  VE_DEFAULT = 0xFF,
93 };
94 
97  VESM_NONE = 0,
101 
102  VESM_END
103 };
104 
117 };
118 
120 struct VehicleCache {
123 
125 };
126 
129  PalSpriteID seq[4];
130  uint count;
131 
132  bool operator==(const VehicleSpriteSeq &other) const
133  {
134  return this->count == other.count && MemCmpT<PalSpriteID>(this->seq, other.seq, this->count) == 0;
135  }
136 
137  bool operator!=(const VehicleSpriteSeq &other) const
138  {
139  return !this->operator==(other);
140  }
141 
145  bool IsValid() const
146  {
147  return this->count != 0;
148  }
149 
153  void Clear()
154  {
155  this->count = 0;
156  }
157 
161  void Set(SpriteID sprite)
162  {
163  this->count = 1;
164  this->seq[0].sprite = sprite;
165  this->seq[0].pal = 0;
166  }
167 
172  {
173  this->count = src.count;
174  for (uint i = 0; i < src.count; ++i) {
175  this->seq[i].sprite = src.seq[i].sprite;
176  this->seq[i].pal = 0;
177  }
178  }
179 
180  void GetBounds(Rect *bounds) const;
181  void Draw(int x, int y, PaletteID default_pal, bool force_pal) const;
182 };
183 
187 
188 /* Some declarations of functions, so we can make them friendly */
189 struct SaveLoad;
190 struct GroundVehicleCache;
191 extern const SaveLoad *GetVehicleDescription(VehicleType vt);
192 struct LoadgameState;
193 extern bool LoadOldVehicle(LoadgameState *ls, int num);
194 extern void FixOldVehicles();
195 
196 struct GRFFile;
197 
201 struct RefitDesc {
203  uint16 capacity;
204  uint16 remaining;
205  RefitDesc(CargoID cargo, uint16 capacity, uint16 remaining) :
206  cargo(cargo), capacity(capacity), remaining(remaining) {}
207 };
208 
211 private:
212  typedef std::list<RefitDesc> RefitList;
213  typedef std::map<CargoID, uint> CapacitiesMap;
214 
218 
221 
222 public:
223  friend const SaveLoad *GetVehicleDescription(VehicleType vt);
224  friend void FixOldVehicles();
225  friend void AfterLoadVehicles(bool part_of_load);
226  friend bool LoadOldVehicle(LoadgameState *ls, int num);
227 
229 
236 
240 
242 
244 
247 
251 
253 
254  /* Related to age and service time */
259  uint16 reliability;
265 
266  int32 x_pos;
267  int32 y_pos;
268  int32 z_pos;
270 
272 
277  byte spritenum;
279  byte x_extent;
280  byte y_extent;
281  byte z_extent;
282  int8 x_bb_offs;
283  int8 y_bb_offs;
284  int8 x_offs;
285  int8 y_offs;
287 
288  TextEffectID fill_percent_te_id;
290 
291  uint16 cur_speed;
292  byte subspeed;
294  uint32 motion_counter;
295  byte progress;
296 
297  byte random_bits;
299 
302 
305  uint16 cargo_cap;
306  uint16 refit_cap;
310 
311  byte day_counter;
314 
315  byte vehstatus;
317 
318  union {
321  } orders;
322 
325  byte subtype;
326 
329 
331 
332  void PreDestructor();
334  virtual ~Vehicle();
335 
336  void BeginLoading();
337  void CancelReservation(StationID next, Station *st);
338  void LeaveStation();
339 
340  GroundVehicleCache *GetGroundVehicleCache();
341  const GroundVehicleCache *GetGroundVehicleCache() const;
342 
343  uint16 &GetGroundVehicleFlags();
344  const uint16 &GetGroundVehicleFlags() const;
345 
346  void DeleteUnreachedImplicitOrders();
347 
348  void HandleLoading(bool mode = false);
349 
350  void GetConsistFreeCapacities(SmallMap<CargoID, uint> &capacities) const;
351 
352  uint GetConsistTotalCapacity() const;
353 
362  virtual void MarkDirty() {}
363 
368  virtual void UpdateDeltaXY() {}
369 
383  inline uint GetOldAdvanceSpeed(uint speed)
384  {
385  return (this->direction & 1) ? speed : speed * 3 / 4;
386  }
387 
400  static inline uint GetAdvanceSpeed(uint speed)
401  {
402  return speed * 3 / 4;
403  }
404 
412  inline uint GetAdvanceDistance()
413  {
414  return (this->direction & 1) ? 192 : 256;
415  }
416 
421  virtual ExpensesType GetExpenseType(bool income) const { return EXPENSES_OTHER; }
422 
426  virtual void PlayLeaveStationSound() const {}
427 
431  virtual bool IsPrimaryVehicle() const { return false; }
432 
433  const Engine *GetEngine() const;
434 
440  virtual void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const { result->Clear(); }
441 
442  const GRFFile *GetGRF() const;
443  uint32 GetGRFID() const;
444 
449  inline void InvalidateNewGRFCache()
450  {
451  this->grf_cache.cache_valid = 0;
452  }
453 
459  {
460  for (Vehicle *u = this; u != nullptr; u = u->Next()) {
461  u->InvalidateNewGRFCache();
462  }
463  }
464 
469  inline bool IsGroundVehicle() const
470  {
471  return this->type == VEH_TRAIN || this->type == VEH_ROAD;
472  }
473 
478  virtual int GetDisplaySpeed() const { return 0; }
479 
484  virtual int GetDisplayMaxSpeed() const { return 0; }
485 
490  virtual int GetCurrentMaxSpeed() const { return 0; }
491 
496  virtual Money GetRunningCost() const { return 0; }
497 
502  virtual bool IsInDepot() const { return false; }
503 
508  virtual bool IsChainInDepot() const { return this->IsInDepot(); }
509 
514  bool IsStoppedInDepot() const
515  {
516  assert(this == this->First());
517  /* Free wagons have no VS_STOPPED state */
518  if (this->IsPrimaryVehicle() && !(this->vehstatus & VS_STOPPED)) return false;
519  return this->IsChainInDepot();
520  }
521 
526  virtual bool Tick() { return true; };
527 
531  virtual void OnNewDay() {};
532 
538  virtual uint Crash(bool flooded = false);
539 
552  virtual Trackdir GetVehicleTrackdir() const { return INVALID_TRACKDIR; }
553 
558  Money GetDisplayRunningCost() const { return (this->GetRunningCost() >> 8); }
559 
564  Money GetDisplayProfitThisYear() const { return (this->profit_this_year >> 8); }
565 
570  Money GetDisplayProfitLastYear() const { return (this->profit_last_year >> 8); }
571 
572  void SetNext(Vehicle *next);
573 
579  inline Vehicle *Next() const { return this->next; }
580 
586  inline Vehicle *Previous() const { return this->previous; }
587 
592  inline Vehicle *First() const { return this->first; }
593 
598  inline Vehicle *Last()
599  {
600  Vehicle *v = this;
601  while (v->Next() != nullptr) v = v->Next();
602  return v;
603  }
604 
609  inline const Vehicle *Last() const
610  {
611  const Vehicle *v = this;
612  while (v->Next() != nullptr) v = v->Next();
613  return v;
614  }
615 
621  inline Vehicle *Move(int n)
622  {
623  Vehicle *v = this;
624  if (n < 0) {
625  for (int i = 0; i != n && v != nullptr; i--) v = v->Previous();
626  } else {
627  for (int i = 0; i != n && v != nullptr; i++) v = v->Next();
628  }
629  return v;
630  }
631 
637  inline const Vehicle *Move(int n) const
638  {
639  const Vehicle *v = this;
640  if (n < 0) {
641  for (int i = 0; i != n && v != nullptr; i--) v = v->Previous();
642  } else {
643  for (int i = 0; i != n && v != nullptr; i++) v = v->Next();
644  }
645  return v;
646  }
647 
652  inline Order *GetFirstOrder() const { return (this->orders.list == nullptr) ? nullptr : this->orders.list->GetFirstOrder(); }
653 
654  void AddToShared(Vehicle *shared_chain);
655  void RemoveFromShared();
656 
661  inline Vehicle *NextShared() const { return this->next_shared; }
662 
667  inline Vehicle *PreviousShared() const { return this->previous_shared; }
668 
673  inline Vehicle *FirstShared() const { return (this->orders.list == nullptr) ? this->First() : this->orders.list->GetFirstSharedVehicle(); }
674 
679  inline bool IsOrderListShared() const { return this->orders.list != nullptr && this->orders.list->IsShared(); }
680 
685  inline VehicleOrderID GetNumOrders() const { return (this->orders.list == nullptr) ? 0 : this->orders.list->GetNumOrders(); }
686 
691  inline VehicleOrderID GetNumManualOrders() const { return (this->orders.list == nullptr) ? 0 : this->orders.list->GetNumManualOrders(); }
692 
698  {
699  return (this->orders.list == nullptr) ? INVALID_STATION : this->orders.list->GetNextStoppingStation(this);
700  }
701 
702  void ResetRefitCaps();
703 
710  inline void CopyVehicleConfigAndStatistics(const Vehicle *src)
711  {
712  this->CopyConsistPropertiesFrom(src);
713 
714  this->unitnumber = src->unitnumber;
715 
716  this->current_order = src->current_order;
717  this->dest_tile = src->dest_tile;
718 
719  this->profit_this_year = src->profit_this_year;
720  this->profit_last_year = src->profit_last_year;
721  }
722 
723 
724  bool HandleBreakdown();
725 
726  bool NeedsAutorenewing(const Company *c, bool use_renew_setting = true) const;
727 
728  bool NeedsServicing() const;
729  bool NeedsAutomaticServicing() const;
730 
738  virtual TileIndex GetOrderStationLocation(StationID station) { return INVALID_TILE; }
739 
748  virtual bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse) { return false; }
749 
750  virtual void SetDestTile(TileIndex tile) { this->dest_tile = tile; }
751 
752  CommandCost SendToDepot(DoCommandFlag flags, DepotCommand command);
753 
754  void UpdateVisualEffect(bool allow_power_change = true);
755  void ShowVisualEffect() const;
756 
757  void UpdatePosition();
758  void UpdateViewport(bool dirty);
759  void UpdatePositionAndViewport();
760  void MarkAllViewportsDirty() const;
761 
762  inline uint16 GetServiceInterval() const { return this->service_interval; }
763 
764  inline void SetServiceInterval(uint16 interval) { this->service_interval = interval; }
765 
766  inline bool ServiceIntervalIsCustom() const { return HasBit(this->vehicle_flags, VF_SERVINT_IS_CUSTOM); }
767 
768  inline bool ServiceIntervalIsPercent() const { return HasBit(this->vehicle_flags, VF_SERVINT_IS_PERCENT); }
769 
770  inline void SetServiceIntervalIsCustom(bool on) { SB(this->vehicle_flags, VF_SERVINT_IS_CUSTOM, 1, on); }
771 
772  inline void SetServiceIntervalIsPercent(bool on) { SB(this->vehicle_flags, VF_SERVINT_IS_PERCENT, 1, on); }
773 
774 private:
780  {
781  if (this->GetNumManualOrders() > 0) {
782  /* Advance to next real order */
783  do {
784  this->cur_real_order_index++;
785  if (this->cur_real_order_index >= this->GetNumOrders()) this->cur_real_order_index = 0;
786  } while (this->GetOrder(this->cur_real_order_index)->IsType(OT_IMPLICIT));
787  } else {
788  this->cur_real_order_index = 0;
789  }
790  }
791 
792 public:
799  {
800  if (this->cur_implicit_order_index == this->cur_real_order_index) {
801  /* Increment real order index as well */
802  this->SkipToNextRealOrderIndex();
803  }
804 
805  assert(this->cur_real_order_index == 0 || this->cur_real_order_index < this->GetNumOrders());
806 
807  /* Advance to next implicit order */
808  do {
809  this->cur_implicit_order_index++;
810  if (this->cur_implicit_order_index >= this->GetNumOrders()) this->cur_implicit_order_index = 0;
811  } while (this->cur_implicit_order_index != this->cur_real_order_index && !this->GetOrder(this->cur_implicit_order_index)->IsType(OT_IMPLICIT));
812 
813  InvalidateVehicleOrder(this, 0);
814  }
815 
823  {
824  if (this->cur_implicit_order_index == this->cur_real_order_index) {
825  /* Increment both real and implicit order */
826  this->IncrementImplicitOrderIndex();
827  } else {
828  /* Increment real order only */
829  this->SkipToNextRealOrderIndex();
830  InvalidateVehicleOrder(this, 0);
831  }
832  }
833 
838  {
839  /* Make sure the index is valid */
840  if (this->cur_real_order_index >= this->GetNumOrders()) this->cur_real_order_index = 0;
841 
842  if (this->GetNumManualOrders() > 0) {
843  /* Advance to next real order */
844  while (this->GetOrder(this->cur_real_order_index)->IsType(OT_IMPLICIT)) {
845  this->cur_real_order_index++;
846  if (this->cur_real_order_index >= this->GetNumOrders()) this->cur_real_order_index = 0;
847  }
848  } else {
849  this->cur_real_order_index = 0;
850  }
851  }
852 
858  inline Order *GetOrder(int index) const
859  {
860  return (this->orders.list == nullptr) ? nullptr : this->orders.list->GetOrderAt(index);
861  }
862 
867  inline Order *GetLastOrder() const
868  {
869  return (this->orders.list == nullptr) ? nullptr : this->orders.list->GetLastOrder();
870  }
871 
872  bool IsEngineCountable() const;
873  bool HasEngineType() const;
874  bool HasDepotOrder() const;
875  void HandlePathfindingResult(bool path_found);
876 
881  inline bool IsFrontEngine() const
882  {
883  return this->IsGroundVehicle() && HasBit(this->subtype, GVSF_FRONT);
884  }
885 
890  inline bool IsArticulatedPart() const
891  {
892  return this->IsGroundVehicle() && HasBit(this->subtype, GVSF_ARTICULATED_PART);
893  }
894 
899  inline bool HasArticulatedPart() const
900  {
901  return this->Next() != nullptr && this->Next()->IsArticulatedPart();
902  }
903 
910  {
911  assert(this->HasArticulatedPart());
912  return this->Next();
913  }
914 
920  {
921  Vehicle *v = this;
922  while (v->IsArticulatedPart()) v = v->Previous();
923  return v;
924  }
925 
930  inline const Vehicle *GetFirstEnginePart() const
931  {
932  const Vehicle *v = this;
933  while (v->IsArticulatedPart()) v = v->Previous();
934  return v;
935  }
936 
942  {
943  Vehicle *v = this;
944  while (v->HasArticulatedPart()) v = v->GetNextArticulatedPart();
945  return v;
946  }
947 
952  inline Vehicle *GetNextVehicle() const
953  {
954  const Vehicle *v = this;
955  while (v->HasArticulatedPart()) v = v->GetNextArticulatedPart();
956 
957  /* v now contains the last articulated part in the engine */
958  return v->Next();
959  }
960 
965  inline Vehicle *GetPrevVehicle() const
966  {
967  Vehicle *v = this->Previous();
968  while (v != nullptr && v->IsArticulatedPart()) v = v->Previous();
969 
970  return v;
971  }
972 };
973 
978 template <class T, VehicleType Type>
979 struct SpecializedVehicle : public Vehicle {
980  static const VehicleType EXPECTED_TYPE = Type;
981 
983 
988  {
989  this->sprite_seq.count = 1;
990  }
991 
996  inline T *First() const { return (T *)this->Vehicle::First(); }
997 
1002  inline T *Last() { return (T *)this->Vehicle::Last(); }
1003 
1008  inline const T *Last() const { return (const T *)this->Vehicle::Last(); }
1009 
1014  inline T *Next() const { return (T *)this->Vehicle::Next(); }
1015 
1020  inline T *Previous() const { return (T *)this->Vehicle::Previous(); }
1021 
1027  inline T *GetNextArticulatedPart() { return (T *)this->Vehicle::GetNextArticulatedPart(); }
1028 
1034  inline T *GetNextArticulatedPart() const { return (T *)this->Vehicle::GetNextArticulatedPart(); }
1035 
1040  inline T *GetFirstEnginePart() { return (T *)this->Vehicle::GetFirstEnginePart(); }
1041 
1046  inline const T *GetFirstEnginePart() const { return (const T *)this->Vehicle::GetFirstEnginePart(); }
1047 
1052  inline T *GetLastEnginePart() { return (T *)this->Vehicle::GetLastEnginePart(); }
1053 
1058  inline T *GetNextVehicle() const { return (T *)this->Vehicle::GetNextVehicle(); }
1059 
1064  inline T *GetPrevVehicle() const { return (T *)this->Vehicle::GetPrevVehicle(); }
1065 
1071  static inline bool IsValidID(size_t index)
1072  {
1073  return Vehicle::IsValidID(index) && Vehicle::Get(index)->type == Type;
1074  }
1075 
1080  static inline T *Get(size_t index)
1081  {
1082  return (T *)Vehicle::Get(index);
1083  }
1084 
1089  static inline T *GetIfValid(size_t index)
1090  {
1091  return IsValidID(index) ? Get(index) : nullptr;
1092  }
1093 
1099  static inline T *From(Vehicle *v)
1100  {
1101  assert(v->type == Type);
1102  return (T *)v;
1103  }
1104 
1110  static inline const T *From(const Vehicle *v)
1111  {
1112  assert(v->type == Type);
1113  return (const T *)v;
1114  }
1115 
1121  inline void UpdateViewport(bool force_update, bool update_delta)
1122  {
1123  /* Skip updating sprites on dedicated servers without screen */
1124  if (_network_dedicated) return;
1125 
1126  /* Explicitly choose method to call to prevent vtable dereference -
1127  * it gives ~3% runtime improvements in games with many vehicles */
1128  if (update_delta) ((T *)this)->T::UpdateDeltaXY();
1129  VehicleSpriteSeq seq;
1130  ((T *)this)->T::GetImage(this->direction, EIT_ON_MAP, &seq);
1131  if (force_update || this->sprite_seq != seq) {
1132  this->sprite_seq = seq;
1133  this->Vehicle::UpdateViewport(true);
1134  }
1135  }
1136 
1142  static Pool::IterateWrapper<T> Iterate(size_t from = 0) { return Pool::IterateWrapper<T>(from); }
1143 };
1144 
1147  bool *cache;
1150 
1152  UnitID NextID();
1153 
1155  ~FreeUnitIDGenerator() { free(this->cache); }
1156 };
1157 
1159 static const int32 INVALID_COORD = 0x7fffffff;
1160 
1161 #endif /* VEHICLE_BASE_H */
All types related to tracks.
Owner
Enum for all companies/owners.
Definition: company_type.h:18
Cached often queried (NewGRF) values.
Definition: vehicle_base.h:65
Date max_age
Maximum age.
Definition: vehicle_base.h:257
This bit will be set if the NewGRF var 41 currently stored is valid.
Definition: vehicle_base.h:57
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:18
Vehicle * Previous() const
Get the previous vehicle of this vehicle.
Definition: vehicle_base.h:586
Vehicle is stopped by the player.
Definition: vehicle_base.h:31
VehicleCargoList cargo
The cargo this vehicle is carrying.
Definition: vehicle_base.h:307
uint32 motion_counter
counter to occasionally play a vehicle sound.
Definition: vehicle_base.h:294
Money value
Value of the vehicle.
Definition: vehicle_base.h:239
uint16 capacity
Capacity the vehicle will have.
Definition: vehicle_base.h:203
This bit will be set if the NewGRF var 40 currently stored is valid.
Definition: vehicle_base.h:56
virtual void MarkDirty()
Marks the vehicles to be redrawn and updates cached variables.
Definition: vehicle_base.h:362
Direction direction
facing
Definition: vehicle_base.h:269
Non-existing type of vehicle.
Definition: vehicle_type.h:35
Minimal stack that uses a pool to avoid pointers.
Money GetDisplayProfitThisYear() const
Gets the profit vehicle had this year.
Definition: vehicle_base.h:564
Vehicle * hash_tile_next
NOSAVE: Next vehicle in the tile location hash.
Definition: vehicle_base.h:248
Vehicle * GetFirstEnginePart()
Get the first part of an articulated engine.
Definition: vehicle_base.h:919
Vehicle has finished loading.
Definition: vehicle_base.h:42
Aircraft is broken down.
Definition: vehicle_base.h:36
void InvalidateVehicleOrder(const Vehicle *v, int data)
Updates the widgets of a vehicle which contains the order-data.
Definition: order_cmd.cpp:250
Train vehicle type.
Definition: vehicle_type.h:24
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:291
Whether the vehicle has started running on the timetable yet.
Definition: vehicle_base.h:45
Vehicle ** hash_viewport_prev
NOSAVE: Previous vehicle in the visual location hash.
Definition: vehicle_base.h:246
Simulated cargo type and capacity for prediction of future links.
Definition: vehicle_base.h:201
byte breakdown_delay
Counter for managing breakdown length.
Definition: vehicle_base.h:262
Use default vehicle palette.
Definition: vehicle_base.h:33
Vehicle is a shadow vehicle.
Definition: vehicle_base.h:35
void CopyWithoutPalette(const VehicleSpriteSeq &src)
Copy data from another sprite sequence, while dropping all recolouring information.
Definition: vehicle_base.h:171
Vehicle drawn in viewport.
Definition: vehicle_type.h:86
Trackdir
Enumeration for tracks and directions.
Definition: track_type.h:70
uint16 cur_speed
current speed
Definition: vehicle_base.h:291
uint16 cached_cargo_age_period
Number of ticks before carried cargo is aged.
Definition: vehicle_base.h:122
No visual effect.
Definition: vehicle_base.h:97
uint16 cargo_age_counter
Ticks till cargo is aged next.
Definition: vehicle_base.h:308
Types related to engines.
Base types related to transport.
Leading engine of a consist.
Definition: vehicle_base.h:111
byte spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
Definition: vehicle_base.h:277
bool IsStoppedInDepot() const
Check whether the vehicle is in the depot and stopped.
Definition: vehicle_base.h:514
VehStatus
Vehicle status bits in Vehicle::vehstatus.
Definition: vehicle_base.h:29
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
OrderList * list
Pointer to the order list for this vehicle.
Definition: vehicle_base.h:319
StationID last_loading_station
Last station the vehicle has stopped at and could possibly leave from with any cargo loaded...
Definition: vehicle_base.h:301
Vehicle ** hash_tile_prev
NOSAVE: Previous vehicle in the tile location hash.
Definition: vehicle_base.h:249
TileIndex dest_tile
Heading for this tile.
Definition: vehicle_base.h:235
Implementation of simple mapping class.
void IncrementImplicitOrderIndex()
Increments cur_implicit_order_index, keeps care of the wrap-around and invalidates the GUI...
Definition: vehicle_base.h:798
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:822
This bit will be set if the NewGRF var 43 currently stored is valid.
Definition: vehicle_base.h:59
Combination of a palette sprite and a &#39;real&#39; sprite.
Definition: gfx_type.h:22
Vehicle data structure.
Definition: vehicle_base.h:210
void Clear()
Clear all information.
Definition: vehicle_base.h:153
bool LoadOldVehicle(LoadgameState *ls, int num)
Load the vehicles of an old style savegame.
void Set(SpriteID sprite)
Assign a single sprite to the sequence.
Definition: vehicle_base.h:161
Functions related to orders.
virtual void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const
Gets the sprite to show for the given direction.
Definition: vehicle_base.h:440
Cached often queried values common to all vehicles.
Definition: vehicle_base.h:120
void UpdateViewport(bool force_update, bool update_delta)
Update vehicle sprite- and position caches.
Vehicle is unloading cargo.
Definition: vehicle_base.h:43
Engine that can be front engine, but might be placed behind another engine (not used for road vehicle...
Definition: vehicle_base.h:114
Other expenses.
Definition: economy_type.h:161
StationID last_station_visited
The last station we stopped at.
Definition: vehicle_base.h:300
uint16 reliability_spd_dec
Reliability decrease speed.
Definition: vehicle_base.h:260
uint32 position_consist_length
Cache for NewGRF var 40.
Definition: vehicle_base.h:67
Electric model.
Definition: vehicle_base.h:100
void UpdateViewport(bool dirty)
Update the vehicle on the viewport, updating the right hash and setting the new coordinates.
Definition: vehicle.cpp:1569
First bit that contains the offset (0 = front, 8 = centre, 15 = rear)
Definition: vehicle_base.h:77
Common return value for all commands.
Definition: command_type.h:23
int32 Year
Type for the year, note: 0 based, i.e. starts at the year 0.
Definition: date_type.h:18
Wagon (not used for road vehicles).
Definition: vehicle_base.h:113
byte vehstatus
Status.
Definition: vehicle_base.h:315
EngineImageType
Visualisation contexts of vehicles and engines.
Definition: vehicle_type.h:85
Cached, frequently calculated values.
uint16 cached_max_speed
Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
Definition: vehicle_base.h:121
Generates sequence of free UnitID numbers.
Vehicle * next_shared
pointer to the next vehicle that shares the order
Definition: vehicle_base.h:219
Use default from engine class.
Definition: vehicle_base.h:83
VehicleSpriteSeq sprite_seq
Vehicle appearance.
Definition: vehicle_base.h:278
static T SB(T &x, const uint8 s, const uint8 n, const U d)
Set n bits in x starting at bit s to d.
Vehicle * hash_viewport_next
NOSAVE: Next vehicle in the visual location hash.
Definition: vehicle_base.h:245
Types related to commands.
int8 x_bb_offs
x offset of vehicle bounding box
Definition: vehicle_base.h:282
DepotCommand
Flags to add to p1 for goto depot commands.
Definition: vehicle_type.h:65
Base class for orders.
Money profit_last_year
Profit last year << 8, low 8 bits are fract.
Definition: vehicle_base.h:238
bool _network_dedicated
are we a dedicated server?
Definition: network.cpp:55
Vehicle * FirstShared() const
Get the first vehicle of this vehicle chain.
Definition: vehicle_base.h:673
Diesel model.
Definition: vehicle_base.h:99
Simple mapping class targeted for small sets of data.
void SkipToNextRealOrderIndex()
Advance cur_real_order_index to the next real order.
Definition: vehicle_base.h:779
Value of offset corresponding to a position above the centre of the vehicle.
Definition: vehicle_base.h:79
Vehicle ** hash_tile_current
NOSAVE: Cache of the current hash chain.
Definition: vehicle_base.h:250
static const int32 INVALID_COORD
Sentinel for an invalid coordinate.
int8 y_bb_offs
y offset of vehicle bounding box
Definition: vehicle_base.h:283
byte breakdown_ctr
Counter for managing breakdown events.
Definition: vehicle_base.h:261
Vehicle * Move(int n)
Get the vehicle at offset n of this vehicle chain.
Definition: vehicle_base.h:621
Base class for cargo packets.
byte subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
Definition: vehicle_base.h:325
TextEffectID fill_percent_te_id
a text-effect id to a loading indicator object
Definition: vehicle_base.h:288
uint16 cargo_cap
total capacity
Definition: vehicle_base.h:305
Shared order list linking together the linked list of orders and the list of vehicles sharing this or...
Definition: order_base.h:250
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:484
Money GetDisplayRunningCost() const
Gets the running cost of a vehicle that can be sent into SetDParam for string processing.
Definition: vehicle_base.h:558
Class defining several overloaded accessors so we don&#39;t have to cast vehicle types that often...
Definition: vehicle_base.h:979
Vehicle is crashed.
Definition: vehicle_base.h:37
Vehicle is a prototype (accepted as exclusive preview).
Definition: vehicle_base.h:44
byte acceleration
used by train & aircraft
Definition: vehicle_base.h:293
First bit used for the type of effect.
Definition: vehicle_base.h:81
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
Definition: vehicle_base.h:431
Various front vehicle properties that are preserved when autoreplacing, using order-backup or switchi...
Definition: base_consist.h:17
UnitID unitnumber
unit number, for display purposes only
Definition: vehicle_base.h:289
byte cargo_subtype
Used for livery refits (NewGRF variations)
Definition: vehicle_base.h:304
bool operator!=(const MultiMapIterator< Tmap_iter1, Tlist_iter1, Tkey, Tvalue1, Tcompare > &iter1, const MultiMapIterator< Tmap_iter2, Tlist_iter2, Tkey, Tvalue2, Tcompare > &iter2)
Inverse of operator==().
Definition: multimap.hpp:220
bool IsValid() const
Check whether the sequence contains any sprites.
Definition: vehicle_base.h:145
uint16 remaining
Capacity remaining from before the previous refit.
Definition: vehicle_base.h:204
virtual bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse)
Find the closest depot for this vehicle and tell us the location, DestinationID and whether we should...
Definition: vehicle_base.h:748
int8 y_offs
y offset for vehicle sprite
Definition: vehicle_base.h:285
void MarkAllViewportsDirty(int left, int top, int right, int bottom)
Mark all viewports that display an area as dirty (in need of repaint).
Definition: viewport.cpp:1905
Don&#39;t load anymore during the next load cycle.
Definition: vehicle_base.h:48
UnitID maxid
maximum ID at the moment of constructor call
const Vehicle * GetFirstEnginePart() const
Get the first part of an articulated engine.
Definition: vehicle_base.h:930
DoCommandFlag
List of flags for a command.
Definition: command_type.h:342
VisualEffectSpawnModel
Models for spawning visual effects.
Definition: vehicle_base.h:96
virtual ExpensesType GetExpenseType(bool income) const
Sets the expense type associated to this vehicle type.
Definition: vehicle_base.h:421
bool IsArticulatedPart() const
Check if the vehicle is an articulated part of an engine.
Definition: vehicle_base.h:890
byte x_extent
x-extent of vehicle bounding box
Definition: vehicle_base.h:279
Pool< Vehicle, VehicleID, 512, 0xFF000 > VehiclePool
A vehicle pool for a little over 1 million vehicles.
Definition: vehicle_base.h:185
void InvalidateNewGRFCacheOfChain()
Invalidates cached NewGRF variables of all vehicles in the chain (after the current vehicle) ...
Definition: vehicle_base.h:458
Direction
Defines the 8 directions on the map.
Flag for an invalid trackdir.
Definition: track_type.h:89
Vehicle * GetNextVehicle() const
Get the next real (non-articulated part) vehicle in the consist.
Definition: vehicle_base.h:952
NewGRFCacheValidValues
Bit numbers used to indicate which of the NewGRFCache values are valid.
Definition: vehicle_base.h:55
byte waiting_triggers
Triggers to be yet matched before rerandomizing the random bits.
Definition: vehicle_base.h:298
Electric sparks.
Definition: vehicle_base.h:86
uint16 GroupID
Type for all group identifiers.
Definition: group_type.h:13
uint32 position_same_id_length
Cache for NewGRF var 41.
Definition: vehicle_base.h:68
byte z_extent
z-extent of vehicle bounding box
Definition: vehicle_base.h:281
void UpdateRealOrderIndex()
Skip implicit orders until cur_real_order_index is a non-implicit order.
Definition: vehicle_base.h:837
Service interval is custom.
Definition: vehicle_base.h:50
virtual int GetCurrentMaxSpeed() const
Calculates the maximum speed of the vehicle under its current conditions.
Definition: vehicle_base.h:490
bool operator==(const MultiMapIterator< Tmap_iter1, Tlist_iter1, Tkey, Tvalue1, Tcompare > &iter1, const MultiMapIterator< Tmap_iter2, Tlist_iter2, Tkey, Tvalue2, Tcompare > &iter2)
Compare two MultiMap iterators.
Definition: multimap.hpp:203
CargoID cargo_type
type of cargo this vehicle is carrying
Definition: vehicle_base.h:303
Whether the vehicle should fill in the timetable automatically.
Definition: vehicle_base.h:46
uint16 load_unload_ticks
Ticks to wait before starting next cycle.
Definition: vehicle_base.h:323
static bool IsValidID(size_t index)
Tests whether given index is a valid index for vehicle of this type.
Order * old
Only used during conversion of old save games.
Definition: vehicle_base.h:320
bool IsFrontEngine() const
Check if the vehicle is a front engine.
Definition: vehicle_base.h:881
Properties for front vehicles/consists.
TileIndex tile
Current tile index.
Definition: vehicle_base.h:228
This bit will be set if the NewGRF var 42 currently stored is valid.
Definition: vehicle_base.h:58
virtual void UpdateDeltaXY()
Updates the x and y offsets and the size of the sprite used for this vehicle.
Definition: vehicle_base.h:368
bool HasArticulatedPart() const
Check if an engine has an articulated part.
Definition: vehicle_base.h:899
const Vehicle * Last() const
Get the last vehicle of this vehicle chain.
Definition: vehicle_base.h:609
Steam model.
Definition: vehicle_base.h:98
virtual bool IsInDepot() const
Check whether the vehicle is in the depot.
Definition: vehicle_base.h:502
Basic functions/variables used all over the place.
virtual TileIndex GetOrderStationLocation(StationID station)
Determine the location for the station where the vehicle goes to next.
Definition: vehicle_base.h:738
int8 x_offs
x offset for vehicle sprite
Definition: vehicle_base.h:284
Owner owner
Which company owns the vehicle?
Definition: vehicle_base.h:271
Sprite sequence for a vehicle part.
Definition: vehicle_base.h:128
Helper class to perform the cargo payment.
Definition: economy_base.h:24
Order * GetLastOrder() const
Returns the last order of a vehicle, or nullptr if it doesn&#39;t exists.
Definition: vehicle_base.h:867
uint16 refit_cap
Capacity left over from before last refit.
Definition: vehicle_base.h:306
byte random_bits
Bits used for determining which randomized variational spritegroups to use when drawing.
Definition: vehicle_base.h:297
byte breakdowns_since_last_service
Counter for the amount of breakdowns.
Definition: vehicle_base.h:263
uint16 reliability
Reliability.
Definition: vehicle_base.h:259
Vehicle * First() const
Get the first vehicle of this vehicle chain.
Definition: vehicle_base.h:592
Vehicle&#39;s pathfinder is lost.
Definition: vehicle_base.h:49
byte tick_counter
Increased by one for each tick.
Definition: vehicle_base.h:312
Order * GetFirstOrder() const
Get the first order of the vehicles order list.
Definition: vehicle_base.h:652
UnitID curid
last ID returned; 0 if none
Base class for all PoolItems.
Definition: pool_type.hpp:188
static EngineID GetNextArticulatedPart(uint index, EngineID front_type, Vehicle *front=nullptr, bool *mirrored=nullptr)
Determines the next articulated part to attach.
Year build_year
Year the vehicle has been built.
Definition: vehicle_base.h:255
Engine is multiheaded (not used for road vehicles).
Definition: vehicle_base.h:116
Base class for all pools.
Definition: pool_type.hpp:82
virtual Money GetRunningCost() const
Gets the running cost of a vehicle.
Definition: vehicle_base.h:496
~FreeUnitIDGenerator()
Releases allocated memory.
byte breakdown_chance
Current chance of breakdowns.
Definition: vehicle_base.h:264
Diesel fumes.
Definition: vehicle_base.h:85
This bit will be set if the NewGRF var 4D currently stored is valid.
Definition: vehicle_base.h:60
int8 trip_occupancy
NOSAVE: Occupancy of vehicle of the current trip (updated after leaving a station).
Definition: vehicle_base.h:309
Flag to disable visual effect.
Definition: vehicle_base.h:88
Steam plumes.
Definition: vehicle_base.h:84
uint32 company_information
Cache for NewGRF var 43.
Definition: vehicle_base.h:70
Vehicle * GetPrevVehicle() const
Get the previous real (non-articulated part) vehicle in the consist.
Definition: vehicle_base.h:965
Articulated part of an engine.
Definition: vehicle_base.h:112
bool IsGroundVehicle() const
Check if the vehicle is a ground vehicle.
Definition: vehicle_base.h:469
byte subspeed
fractional speed
Definition: vehicle_base.h:292
CargoList that is used for vehicles.
Definition: cargopacket.h:268
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
Vehicle * GetLastEnginePart()
Get the last part of an articulated engine.
Definition: vehicle_base.h:941
uint16 EngineID
Unique identification number of an engine.
Definition: engine_type.h:21
Number of bits used for the effect type.
Definition: vehicle_base.h:82
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
VehiclePool _vehicle_pool
The pool with all our precious vehicles.
uint GetAdvanceDistance()
Determines the vehicle "progress" needed for moving a step.
Definition: vehicle_base.h:412
Vehicle * Next() const
Get the next vehicle of this vehicle.
Definition: vehicle_base.h:579
Date date_of_last_service
Last date the vehicle had a service at a depot.
Definition: vehicle_base.h:258
CargoPayment * cargo_payment
The cargo payment we&#39;re currently in.
Definition: vehicle_base.h:241
Vehicle * PreviousShared() const
Get the previous vehicle of the shared vehicle chain.
Definition: vehicle_base.h:667
CargoID cargo
Cargo type the vehicle will be carrying.
Definition: vehicle_base.h:202
uint32 consist_cargo_information
Cache for NewGRF var 42. (Note: The cargotype is untranslated in the cache because the accessing GRF ...
Definition: vehicle_base.h:69
void FixOldVehicles()
Convert the old style vehicles into something that resembles the old new style savegames.
uint32 position_in_vehicle
Cache for NewGRF var 4D.
Definition: vehicle_base.h:71
StationIDStack GetNextStoppingStation() const
Get the next station the vehicle will stop at.
Definition: vehicle_base.h:697
Vehicle * GetNextArticulatedPart() const
Get the next part of an articulated engine.
Definition: vehicle_base.h:909
SpecializedVehicle< T, Type > SpecializedVehicleBase
Our type.
Definition: vehicle_base.h:982
GroundVehicleSubtypeFlags
Enum to handle ground vehicle subtypes.
Definition: vehicle_base.h:110
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:52
Vehicle * next
pointer to the next vehicle in the chain
Definition: vehicle_base.h:215
void AfterLoadVehicles(bool part_of_load)
Called after load to update coordinates.
Definition: vehicle_sl.cpp:240
First in a wagon chain (in depot) (not used for road vehicles).
Definition: vehicle_base.h:115
Vehicle * previous_shared
NOSAVE: pointer to the previous vehicle in the shared order chain.
Definition: vehicle_base.h:220
End of the bits.
Definition: vehicle_base.h:61
void CopyVehicleConfigAndStatistics(const Vehicle *src)
Copy certain configurations and statistics of a vehicle after successful autoreplace/renew The functi...
Definition: vehicle_base.h:710
virtual void OnNewDay()
Calls the new day handler of the vehicle.
Definition: vehicle_base.h:531
Default value to indicate that visual effect should be based on engine class.
Definition: vehicle_base.h:92
int32 z_pos
z coordinate.
Definition: vehicle_base.h:268
Vehicle is not visible.
Definition: vehicle_base.h:30
Vehicle * previous
NOSAVE: pointer to the previous vehicle in the chain.
Definition: vehicle_base.h:216
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:280
Base vehicle class.
Definition: vehicle_type.h:50
uint16 UnitID
Type for the company global vehicle unit number.
bool * cache
array of occupied unit id numbers
Order * GetOrder(int index) const
Returns order &#39;index&#39; of a vehicle or nullptr when it doesn&#39;t exists.
Definition: vehicle_base.h:858
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
Definition: vehicle_base.h:685
static Pool::IterateWrapper< T > Iterate(size_t from=0)
Returns an iterable ensemble of all valid vehicles of type T.
int32 Date
The type to store our dates in.
Definition: date_type.h:14
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: depend.cpp:129
bool IsOrderListShared() const
Check if we share our orders with another vehicle.
Definition: vehicle_base.h:679
byte running_ticks
Number of ticks this vehicle was not stopped this day.
Definition: vehicle_base.h:313
virtual Trackdir GetVehicleTrackdir() const
Returns the Trackdir on which the vehicle is currently located.
Definition: vehicle_base.h:552
byte y_extent
y-extent of vehicle bounding box
Definition: vehicle_base.h:280
Flag to disable wagon power.
Definition: vehicle_base.h:90
EngineID engine_type
The type of engine used for this vehicle.
Definition: vehicle_base.h:286
SaveLoad type struct.
Definition: saveload.h:496
byte cached_vis_effect
Visual effect to show (see VisualEffect)
Definition: vehicle_base.h:124
virtual void PlayLeaveStationSound() const
Play the sound associated with leaving the station.
Definition: vehicle_base.h:426
int32 x_pos
x coordinate.
Definition: vehicle_base.h:266
virtual bool Tick()
Calls the tick handler of the vehicle.
Definition: vehicle_base.h:526
byte VehicleOrderID
The index of an order within its current vehicle (not pool related)
Definition: order_type.h:15
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
const Vehicle * Move(int n) const
Get the vehicle at offset n of this vehicle chain.
Definition: vehicle_base.h:637
uint8 cache_valid
Bitset that indicates which cache values are valid.
Definition: vehicle_base.h:72
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:83
Whether non-destructive auto-fill should preserve waiting times.
Definition: vehicle_base.h:47
byte progress
The percentage (if divided by 256) this vehicle already crossed the tile unit.
Definition: vehicle_base.h:295
virtual int GetDisplaySpeed() const
Gets the speed in km-ish/h that can be sent into SetDParam for string processing. ...
Definition: vehicle_base.h:478
Specification of a rectangle with absolute coordinates of all edges.
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:20
int32 y_pos
y coordinate.
Definition: vehicle_base.h:267
static uint GetAdvanceSpeed(uint speed)
Determines the effective vehicle movement speed.
Definition: vehicle_base.h:400
Vehicle * NextShared() const
Get the next vehicle of the shared vehicle chain.
Definition: vehicle_base.h:661
virtual bool IsChainInDepot() const
Check whether the whole vehicle chain is in the depot.
Definition: vehicle_base.h:508
Flag for advanced effects.
Definition: vehicle_base.h:89
Vehicle * Last()
Get the last vehicle of this vehicle chain.
Definition: vehicle_base.h:598
VehicleFlags
Bit numbers in Vehicle::vehicle_flags.
Definition: vehicle_base.h:41
Functions related to text effects.
SpriteID sprite
The &#39;real&#39; sprite.
Definition: gfx_type.h:23
Money profit_this_year
Profit this year << 8, low 8 bits are fract.
Definition: vehicle_base.h:237
const SaveLoad * GetVehicleDescription(VehicleType vt)
Make it possible to make the saveload tables "friends" of other classes.
Definition: vehicle_sl.cpp:580
VehicleCache vcache
Cache of often used vehicle values.
Definition: vehicle_base.h:328
Number of bits used for the offset.
Definition: vehicle_base.h:78
VisualEffect
Meaning of the various bits of the visual effect.
Definition: vehicle_base.h:76
Rect coord
NOSAVE: Graphical bounding box of the vehicle, i.e. what to redraw on moves.
Definition: vehicle_base.h:243
Vehicle * first
NOSAVE: pointer to the first vehicle in the chain.
Definition: vehicle_base.h:217
Date age
Age in days.
Definition: vehicle_base.h:256
ExpensesType
Types of expenses.
Definition: economy_type.h:148
Types of a group.
Station data structure.
Definition: station_base.h:450
NewGRFCache grf_cache
Cache of often used calculated NewGRF values.
Definition: vehicle_base.h:327
void InvalidateNewGRFCache()
Invalidates cached NewGRF variables.
Definition: vehicle_base.h:449
Money GetDisplayProfitLastYear() const
Gets the profit vehicle had last year.
Definition: vehicle_base.h:570
Road vehicle type.
Definition: vehicle_type.h:25
uint GetOldAdvanceSpeed(uint speed)
Determines the effective direction-specific vehicle movement speed.
Definition: vehicle_base.h:383
Train is slowing down.
Definition: vehicle_base.h:34
byte day_counter
Increased by one for each day.
Definition: vehicle_base.h:311
Order current_order
The current order (+ status, like: loading)
Definition: vehicle_base.h:316
GroupID group_id
Index of group Pool array.
Definition: vehicle_base.h:324
Vehicle is not clickable by the user (shadow vehicles).
Definition: vehicle_base.h:32
SpriteID colourmap
NOSAVE: cached colour mapping.
Definition: vehicle_base.h:252
VehicleOrderID GetNumManualOrders() const
Get the number of manually added orders this vehicle has.
Definition: vehicle_base.h:691
Service interval is percent.
Definition: vehicle_base.h:51
Dynamic data of a loaded NewGRF.
Definition: newgrf.h:105
PaletteID pal
The palette (use PAL_NONE) if not needed)
Definition: gfx_type.h:24