OpenTTD
vehicle_base.h
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8  */
9 
12 #ifndef VEHICLE_BASE_H
13 #define VEHICLE_BASE_H
14 
15 #include "core/smallmap_type.hpp"
16 #include "track_type.h"
17 #include "command_type.h"
18 #include "order_base.h"
19 #include "cargopacket.h"
20 #include "texteff.hpp"
21 #include "engine_type.h"
22 #include "order_func.h"
23 #include "transport_type.h"
24 #include "group_type.h"
25 #include "base_consist.h"
26 #include "network/network.h"
27 #include <list>
28 #include <map>
29 
31 enum VehStatus {
32  VS_HIDDEN = 0x01,
33  VS_STOPPED = 0x02,
34  VS_UNCLICKABLE = 0x04,
35  VS_DEFPAL = 0x08,
37  VS_SHADOW = 0x20,
39  VS_CRASHED = 0x80,
40 };
41 
54 };
55 
64 };
65 
67 struct NewGRFCache {
68  /* Values calculated when they are requested for the first time after invalidating the NewGRF cache. */
74  uint8 cache_valid;
75 };
76 
82 
89 
93 
94  VE_DEFAULT = 0xFF,
95 };
96 
99  VESM_NONE = 0,
103 
104  VESM_END
105 };
106 
119 };
120 
122 struct VehicleCache {
125 
127 };
128 
131  PalSpriteID seq[4];
132  uint count;
133 
134  bool operator==(const VehicleSpriteSeq &other) const
135  {
136  return this->count == other.count && MemCmpT<PalSpriteID>(this->seq, other.seq, this->count) == 0;
137  }
138 
139  bool operator!=(const VehicleSpriteSeq &other) const
140  {
141  return !this->operator==(other);
142  }
143 
147  bool IsValid() const
148  {
149  return this->count != 0;
150  }
151 
155  void Clear()
156  {
157  this->count = 0;
158  }
159 
163  void Set(SpriteID sprite)
164  {
165  this->count = 1;
166  this->seq[0].sprite = sprite;
167  this->seq[0].pal = 0;
168  }
169 
174  {
175  this->count = src.count;
176  for (uint i = 0; i < src.count; ++i) {
177  this->seq[i].sprite = src.seq[i].sprite;
178  this->seq[i].pal = 0;
179  }
180  }
181 
182  void GetBounds(Rect *bounds) const;
183  void Draw(int x, int y, PaletteID default_pal, bool force_pal) const;
184 };
185 
189 
190 /* Some declarations of functions, so we can make them friendly */
191 struct SaveLoad;
192 struct GroundVehicleCache;
193 extern const SaveLoad *GetVehicleDescription(VehicleType vt);
194 struct LoadgameState;
195 extern bool LoadOldVehicle(LoadgameState *ls, int num);
196 extern void FixOldVehicles();
197 
198 struct GRFFile;
199 
203 struct RefitDesc {
205  uint16 capacity;
206  uint16 remaining;
207  RefitDesc(CargoID cargo, uint16 capacity, uint16 remaining) :
208  cargo(cargo), capacity(capacity), remaining(remaining) {}
209 };
210 
213 private:
214  typedef std::list<RefitDesc> RefitList;
215  typedef std::map<CargoID, uint> CapacitiesMap;
216 
220 
223 
224 public:
225  friend const SaveLoad *GetVehicleDescription(VehicleType vt);
226  friend void FixOldVehicles();
227  friend void AfterLoadVehicles(bool part_of_load);
228  friend bool LoadOldVehicle(LoadgameState *ls, int num);
229 
231 
238 
242 
244 
246 
249 
253 
255 
256  /* Related to age and service time */
261  uint16 reliability;
267 
268  int32 x_pos;
269  int32 y_pos;
270  int32 z_pos;
272 
274 
279  byte spritenum;
281  byte x_extent;
282  byte y_extent;
283  byte z_extent;
284  int8 x_bb_offs;
285  int8 y_bb_offs;
286  int8 x_offs;
287  int8 y_offs;
289 
290  TextEffectID fill_percent_te_id;
292 
293  uint16 cur_speed;
294  byte subspeed;
296  uint32 motion_counter;
297  byte progress;
298 
299  byte random_bits;
301 
304 
307  uint16 cargo_cap;
308  uint16 refit_cap;
312 
313  byte day_counter;
316 
317  byte vehstatus;
319 
320  union {
323  } orders;
324 
327  byte subtype;
328 
331 
333 
334  void PreDestructor();
336  virtual ~Vehicle();
337 
338  void BeginLoading();
339  void CancelReservation(StationID next, Station *st);
340  void LeaveStation();
341 
342  GroundVehicleCache *GetGroundVehicleCache();
343  const GroundVehicleCache *GetGroundVehicleCache() const;
344 
345  uint16 &GetGroundVehicleFlags();
346  const uint16 &GetGroundVehicleFlags() const;
347 
348  void DeleteUnreachedImplicitOrders();
349 
350  void HandleLoading(bool mode = false);
351 
352  void GetConsistFreeCapacities(SmallMap<CargoID, uint> &capacities) const;
353 
354  uint GetConsistTotalCapacity() const;
355 
364  virtual void MarkDirty() {}
365 
370  virtual void UpdateDeltaXY() {}
371 
385  inline uint GetOldAdvanceSpeed(uint speed)
386  {
387  return (this->direction & 1) ? speed : speed * 3 / 4;
388  }
389 
402  static inline uint GetAdvanceSpeed(uint speed)
403  {
404  return speed * 3 / 4;
405  }
406 
414  inline uint GetAdvanceDistance()
415  {
416  return (this->direction & 1) ? 192 : 256;
417  }
418 
423  virtual ExpensesType GetExpenseType(bool income) const { return EXPENSES_OTHER; }
424 
428  virtual void PlayLeaveStationSound() const {}
429 
433  virtual bool IsPrimaryVehicle() const { return false; }
434 
435  const Engine *GetEngine() const;
436 
442  virtual void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const { result->Clear(); }
443 
444  const GRFFile *GetGRF() const;
445  uint32 GetGRFID() const;
446 
451  inline void InvalidateNewGRFCache()
452  {
453  this->grf_cache.cache_valid = 0;
454  }
455 
461  {
462  for (Vehicle *u = this; u != NULL; u = u->Next()) {
463  u->InvalidateNewGRFCache();
464  }
465  }
466 
471  inline bool IsGroundVehicle() const
472  {
473  return this->type == VEH_TRAIN || this->type == VEH_ROAD;
474  }
475 
480  virtual int GetDisplaySpeed() const { return 0; }
481 
486  virtual int GetDisplayMaxSpeed() const { return 0; }
487 
492  virtual int GetCurrentMaxSpeed() const { return 0; }
493 
498  virtual Money GetRunningCost() const { return 0; }
499 
504  virtual bool IsInDepot() const { return false; }
505 
510  virtual bool IsChainInDepot() const { return this->IsInDepot(); }
511 
516  bool IsStoppedInDepot() const
517  {
518  assert(this == this->First());
519  /* Free wagons have no VS_STOPPED state */
520  if (this->IsPrimaryVehicle() && !(this->vehstatus & VS_STOPPED)) return false;
521  return this->IsChainInDepot();
522  }
523 
528  virtual bool Tick() { return true; };
529 
533  virtual void OnNewDay() {};
534 
540  virtual uint Crash(bool flooded = false);
541 
554  virtual Trackdir GetVehicleTrackdir() const { return INVALID_TRACKDIR; }
555 
560  Money GetDisplayRunningCost() const { return (this->GetRunningCost() >> 8); }
561 
566  Money GetDisplayProfitThisYear() const { return (this->profit_this_year >> 8); }
567 
572  Money GetDisplayProfitLastYear() const { return (this->profit_last_year >> 8); }
573 
574  void SetNext(Vehicle *next);
575 
581  inline Vehicle *Next() const { return this->next; }
582 
588  inline Vehicle *Previous() const { return this->previous; }
589 
594  inline Vehicle *First() const { return this->first; }
595 
600  inline Vehicle *Last()
601  {
602  Vehicle *v = this;
603  while (v->Next() != NULL) v = v->Next();
604  return v;
605  }
606 
611  inline const Vehicle *Last() const
612  {
613  const Vehicle *v = this;
614  while (v->Next() != NULL) v = v->Next();
615  return v;
616  }
617 
623  inline Vehicle *Move(int n)
624  {
625  Vehicle *v = this;
626  if (n < 0) {
627  for (int i = 0; i != n && v != NULL; i--) v = v->Previous();
628  } else {
629  for (int i = 0; i != n && v != NULL; i++) v = v->Next();
630  }
631  return v;
632  }
633 
639  inline const Vehicle *Move(int n) const
640  {
641  const Vehicle *v = this;
642  if (n < 0) {
643  for (int i = 0; i != n && v != NULL; i--) v = v->Previous();
644  } else {
645  for (int i = 0; i != n && v != NULL; i++) v = v->Next();
646  }
647  return v;
648  }
649 
654  inline Order *GetFirstOrder() const { return (this->orders.list == NULL) ? NULL : this->orders.list->GetFirstOrder(); }
655 
656  void AddToShared(Vehicle *shared_chain);
657  void RemoveFromShared();
658 
663  inline Vehicle *NextShared() const { return this->next_shared; }
664 
669  inline Vehicle *PreviousShared() const { return this->previous_shared; }
670 
675  inline Vehicle *FirstShared() const { return (this->orders.list == NULL) ? this->First() : this->orders.list->GetFirstSharedVehicle(); }
676 
681  inline bool IsOrderListShared() const { return this->orders.list != NULL && this->orders.list->IsShared(); }
682 
687  inline VehicleOrderID GetNumOrders() const { return (this->orders.list == NULL) ? 0 : this->orders.list->GetNumOrders(); }
688 
693  inline VehicleOrderID GetNumManualOrders() const { return (this->orders.list == NULL) ? 0 : this->orders.list->GetNumManualOrders(); }
694 
700  {
701  return (this->orders.list == NULL) ? INVALID_STATION : this->orders.list->GetNextStoppingStation(this);
702  }
703 
704  void ResetRefitCaps();
705 
712  inline void CopyVehicleConfigAndStatistics(const Vehicle *src)
713  {
714  this->CopyConsistPropertiesFrom(src);
715 
716  this->unitnumber = src->unitnumber;
717 
718  this->current_order = src->current_order;
719  this->dest_tile = src->dest_tile;
720 
721  this->profit_this_year = src->profit_this_year;
722  this->profit_last_year = src->profit_last_year;
723  }
724 
725 
726  bool HandleBreakdown();
727 
728  bool NeedsAutorenewing(const Company *c, bool use_renew_setting = true) const;
729 
730  bool NeedsServicing() const;
731  bool NeedsAutomaticServicing() const;
732 
740  virtual TileIndex GetOrderStationLocation(StationID station) { return INVALID_TILE; }
741 
750  virtual bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse) { return false; }
751 
752  virtual void SetDestTile(TileIndex tile) { this->dest_tile = tile; }
753 
754  CommandCost SendToDepot(DoCommandFlag flags, DepotCommand command);
755 
756  void UpdateVisualEffect(bool allow_power_change = true);
757  void ShowVisualEffect() const;
758 
759  void UpdatePosition();
760  void UpdateViewport(bool dirty);
761  void UpdatePositionAndViewport();
762  void MarkAllViewportsDirty() const;
763 
764  inline uint16 GetServiceInterval() const { return this->service_interval; }
765 
766  inline void SetServiceInterval(uint16 interval) { this->service_interval = interval; }
767 
768  inline bool ServiceIntervalIsCustom() const { return HasBit(this->vehicle_flags, VF_SERVINT_IS_CUSTOM); }
769 
770  inline bool ServiceIntervalIsPercent() const { return HasBit(this->vehicle_flags, VF_SERVINT_IS_PERCENT); }
771 
772  inline void SetServiceIntervalIsCustom(bool on) { SB(this->vehicle_flags, VF_SERVINT_IS_CUSTOM, 1, on); }
773 
774  inline void SetServiceIntervalIsPercent(bool on) { SB(this->vehicle_flags, VF_SERVINT_IS_PERCENT, 1, on); }
775 
776 private:
782  {
783  if (this->GetNumManualOrders() > 0) {
784  /* Advance to next real order */
785  do {
786  this->cur_real_order_index++;
787  if (this->cur_real_order_index >= this->GetNumOrders()) this->cur_real_order_index = 0;
788  } while (this->GetOrder(this->cur_real_order_index)->IsType(OT_IMPLICIT));
789  } else {
790  this->cur_real_order_index = 0;
791  }
792  }
793 
794 public:
801  {
802  if (this->cur_implicit_order_index == this->cur_real_order_index) {
803  /* Increment real order index as well */
804  this->SkipToNextRealOrderIndex();
805  }
806 
807  assert(this->cur_real_order_index == 0 || this->cur_real_order_index < this->GetNumOrders());
808 
809  /* Advance to next implicit order */
810  do {
811  this->cur_implicit_order_index++;
812  if (this->cur_implicit_order_index >= this->GetNumOrders()) this->cur_implicit_order_index = 0;
813  } while (this->cur_implicit_order_index != this->cur_real_order_index && !this->GetOrder(this->cur_implicit_order_index)->IsType(OT_IMPLICIT));
814 
815  InvalidateVehicleOrder(this, 0);
816  }
817 
825  {
826  if (this->cur_implicit_order_index == this->cur_real_order_index) {
827  /* Increment both real and implicit order */
828  this->IncrementImplicitOrderIndex();
829  } else {
830  /* Increment real order only */
831  this->SkipToNextRealOrderIndex();
832  InvalidateVehicleOrder(this, 0);
833  }
834  }
835 
840  {
841  /* Make sure the index is valid */
842  if (this->cur_real_order_index >= this->GetNumOrders()) this->cur_real_order_index = 0;
843 
844  if (this->GetNumManualOrders() > 0) {
845  /* Advance to next real order */
846  while (this->GetOrder(this->cur_real_order_index)->IsType(OT_IMPLICIT)) {
847  this->cur_real_order_index++;
848  if (this->cur_real_order_index >= this->GetNumOrders()) this->cur_real_order_index = 0;
849  }
850  } else {
851  this->cur_real_order_index = 0;
852  }
853  }
854 
860  inline Order *GetOrder(int index) const
861  {
862  return (this->orders.list == NULL) ? NULL : this->orders.list->GetOrderAt(index);
863  }
864 
869  inline Order *GetLastOrder() const
870  {
871  return (this->orders.list == NULL) ? NULL : this->orders.list->GetLastOrder();
872  }
873 
874  bool IsEngineCountable() const;
875  bool HasEngineType() const;
876  bool HasDepotOrder() const;
877  void HandlePathfindingResult(bool path_found);
878 
883  inline bool IsFrontEngine() const
884  {
885  return this->IsGroundVehicle() && HasBit(this->subtype, GVSF_FRONT);
886  }
887 
892  inline bool IsArticulatedPart() const
893  {
894  return this->IsGroundVehicle() && HasBit(this->subtype, GVSF_ARTICULATED_PART);
895  }
896 
901  inline bool HasArticulatedPart() const
902  {
903  return this->Next() != NULL && this->Next()->IsArticulatedPart();
904  }
905 
912  {
913  assert(this->HasArticulatedPart());
914  return this->Next();
915  }
916 
922  {
923  Vehicle *v = this;
924  while (v->IsArticulatedPart()) v = v->Previous();
925  return v;
926  }
927 
932  inline const Vehicle *GetFirstEnginePart() const
933  {
934  const Vehicle *v = this;
935  while (v->IsArticulatedPart()) v = v->Previous();
936  return v;
937  }
938 
944  {
945  Vehicle *v = this;
946  while (v->HasArticulatedPart()) v = v->GetNextArticulatedPart();
947  return v;
948  }
949 
954  inline Vehicle *GetNextVehicle() const
955  {
956  const Vehicle *v = this;
957  while (v->HasArticulatedPart()) v = v->GetNextArticulatedPart();
958 
959  /* v now contains the last articulated part in the engine */
960  return v->Next();
961  }
962 
967  inline Vehicle *GetPrevVehicle() const
968  {
969  Vehicle *v = this->Previous();
970  while (v != NULL && v->IsArticulatedPart()) v = v->Previous();
971 
972  return v;
973  }
974 };
975 
981 #define FOR_ALL_VEHICLES_FROM(var, start) FOR_ALL_ITEMS_FROM(Vehicle, vehicle_index, var, start)
982 
987 #define FOR_ALL_VEHICLES(var) FOR_ALL_VEHICLES_FROM(var, 0)
988 
993 template <class T, VehicleType Type>
994 struct SpecializedVehicle : public Vehicle {
995  static const VehicleType EXPECTED_TYPE = Type;
996 
998 
1003  {
1004  this->sprite_seq.count = 1;
1005  }
1006 
1011  inline T *First() const { return (T *)this->Vehicle::First(); }
1012 
1017  inline T *Last() { return (T *)this->Vehicle::Last(); }
1018 
1023  inline const T *Last() const { return (const T *)this->Vehicle::Last(); }
1024 
1029  inline T *Next() const { return (T *)this->Vehicle::Next(); }
1030 
1035  inline T *Previous() const { return (T *)this->Vehicle::Previous(); }
1036 
1042  inline T *GetNextArticulatedPart() { return (T *)this->Vehicle::GetNextArticulatedPart(); }
1043 
1049  inline T *GetNextArticulatedPart() const { return (T *)this->Vehicle::GetNextArticulatedPart(); }
1050 
1055  inline T *GetFirstEnginePart() { return (T *)this->Vehicle::GetFirstEnginePart(); }
1056 
1061  inline const T *GetFirstEnginePart() const { return (const T *)this->Vehicle::GetFirstEnginePart(); }
1062 
1067  inline T *GetLastEnginePart() { return (T *)this->Vehicle::GetLastEnginePart(); }
1068 
1073  inline T *GetNextVehicle() const { return (T *)this->Vehicle::GetNextVehicle(); }
1074 
1079  inline T *GetPrevVehicle() const { return (T *)this->Vehicle::GetPrevVehicle(); }
1080 
1086  static inline bool IsValidID(size_t index)
1087  {
1088  return Vehicle::IsValidID(index) && Vehicle::Get(index)->type == Type;
1089  }
1090 
1095  static inline T *Get(size_t index)
1096  {
1097  return (T *)Vehicle::Get(index);
1098  }
1099 
1104  static inline T *GetIfValid(size_t index)
1105  {
1106  return IsValidID(index) ? Get(index) : NULL;
1107  }
1108 
1114  static inline T *From(Vehicle *v)
1115  {
1116  assert(v->type == Type);
1117  return (T *)v;
1118  }
1119 
1125  static inline const T *From(const Vehicle *v)
1126  {
1127  assert(v->type == Type);
1128  return (const T *)v;
1129  }
1130 
1136  inline void UpdateViewport(bool force_update, bool update_delta)
1137  {
1138  /* Skip updating sprites on dedicated servers without screen */
1139  if (_network_dedicated) return;
1140 
1141  /* Explicitly choose method to call to prevent vtable dereference -
1142  * it gives ~3% runtime improvements in games with many vehicles */
1143  if (update_delta) ((T *)this)->T::UpdateDeltaXY();
1144  VehicleSpriteSeq seq;
1145  ((T *)this)->T::GetImage(this->direction, EIT_ON_MAP, &seq);
1146  if (force_update || this->sprite_seq != seq) {
1147  this->sprite_seq = seq;
1148  this->Vehicle::UpdateViewport(true);
1149  }
1150  }
1151 };
1152 
1158 #define FOR_ALL_VEHICLES_OF_TYPE(name, var) FOR_ALL_ITEMS_FROM(name, vehicle_index, var, 0) if (var->type == name::EXPECTED_TYPE)
1159 
1162  bool *cache;
1165 
1167  UnitID NextID();
1168 
1170  ~FreeUnitIDGenerator() { free(this->cache); }
1171 };
1172 
1174 static const int32 INVALID_COORD = 0x7fffffff;
1175 
1176 #endif /* VEHICLE_BASE_H */
All types related to tracks.
Cached often queried (NewGRF) values.
Definition: vehicle_base.h:67
Date max_age
Maximum age.
Definition: vehicle_base.h:259
This bit will be set if the NewGRF var 41 currently stored is valid.
Definition: vehicle_base.h:59
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:20
Vehicle * Previous() const
Get the previous vehicle of this vehicle.
Definition: vehicle_base.h:588
Vehicle is stopped by the player.
Definition: vehicle_base.h:33
VehicleCargoList cargo
The cargo this vehicle is carrying.
Definition: vehicle_base.h:309
uint32 motion_counter
counter to occasionally play a vehicle sound.
Definition: vehicle_base.h:296
Money value
Value of the vehicle.
Definition: vehicle_base.h:241
uint16 capacity
Capacity the vehicle will have.
Definition: vehicle_base.h:205
This bit will be set if the NewGRF var 40 currently stored is valid.
Definition: vehicle_base.h:58
virtual void MarkDirty()
Marks the vehicles to be redrawn and updates cached variables.
Definition: vehicle_base.h:364
Minimal stack that uses a pool to avoid pointers.
Money GetDisplayProfitThisYear() const
Gets the profit vehicle had this year.
Definition: vehicle_base.h:566
DirectionByte direction
facing
Definition: vehicle_base.h:271
Non-existing type of vehicle.
Definition: vehicle_type.h:37
Vehicle * hash_tile_next
NOSAVE: Next vehicle in the tile location hash.
Definition: vehicle_base.h:250
Vehicle * GetFirstEnginePart()
Get the first part of an articulated engine.
Definition: vehicle_base.h:921
Vehicle has finished loading.
Definition: vehicle_base.h:44
Aircraft is broken down.
Definition: vehicle_base.h:38
void InvalidateVehicleOrder(const Vehicle *v, int data)
Updates the widgets of a vehicle which contains the order-data.
Definition: order_cmd.cpp:253
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:246
Whether the vehicle has started running on the timetable yet.
Definition: vehicle_base.h:47
Vehicle ** hash_viewport_prev
NOSAVE: Previous vehicle in the visual location hash.
Definition: vehicle_base.h:248
Simulated cargo type and capacity for prediction of future links.
Definition: vehicle_base.h:203
byte breakdown_delay
Counter for managing breakdown length.
Definition: vehicle_base.h:264
Use default vehicle palette.
Definition: vehicle_base.h:35
Vehicle is a shadow vehicle.
Definition: vehicle_base.h:37
void CopyWithoutPalette(const VehicleSpriteSeq &src)
Copy data from another sprite sequence, while dropping all recolouring information.
Definition: vehicle_base.h:173
Vehicle drawn in viewport.
Definition: vehicle_type.h:90
uint16 cur_speed
current speed
Definition: vehicle_base.h:293
uint16 cached_cargo_age_period
Number of ticks before carried cargo is aged.
Definition: vehicle_base.h:124
No visual effect.
Definition: vehicle_base.h:99
uint16 cargo_age_counter
Ticks till cargo is aged next.
Definition: vehicle_base.h:310
Types related to engines.
Base types related to transport.
Leading engine of a consist.
Definition: vehicle_base.h:113
byte spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
Definition: vehicle_base.h:279
bool IsStoppedInDepot() const
Check whether the vehicle is in the depot and stopped.
Definition: vehicle_base.h:516
VehStatus
Vehicle status bits in Vehicle::vehstatus.
Definition: vehicle_base.h:31
OrderList * list
Pointer to the order list for this vehicle.
Definition: vehicle_base.h:321
StationID last_loading_station
Last station the vehicle has stopped at and could possibly leave from with any cargo loaded...
Definition: vehicle_base.h:303
Vehicle ** hash_tile_prev
NOSAVE: Previous vehicle in the tile location hash.
Definition: vehicle_base.h:251
TileIndex dest_tile
Heading for this tile.
Definition: vehicle_base.h:237
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:800
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:824
This bit will be set if the NewGRF var 43 currently stored is valid.
Definition: vehicle_base.h:61
Combination of a palette sprite and a &#39;real&#39; sprite.
Definition: gfx_type.h:24
Vehicle data structure.
Definition: vehicle_base.h:212
void Clear()
Clear all information.
Definition: vehicle_base.h:155
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:163
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:442
Cached often queried values common to all vehicles.
Definition: vehicle_base.h:122
void UpdateViewport(bool force_update, bool update_delta)
Update vehicle sprite- and position caches.
Vehicle is unloading cargo.
Definition: vehicle_base.h:45
Engine that can be front engine, but might be placed behind another engine (not used for road vehicle...
Definition: vehicle_base.h:116
StationID last_station_visited
The last station we stopped at.
Definition: vehicle_base.h:302
uint16 reliability_spd_dec
Reliability decrease speed.
Definition: vehicle_base.h:262
uint32 position_consist_length
Cache for NewGRF var 40.
Definition: vehicle_base.h:69
Electric model.
Definition: vehicle_base.h:102
void UpdateViewport(bool dirty)
Update the vehicle on the viewport, updating the right hash and setting the new coordinates.
Definition: vehicle.cpp:1570
First bit that contains the offset (0 = front, 8 = centre, 15 = rear)
Definition: vehicle_base.h:79
Common return value for all commands.
Definition: command_type.h:25
int32 Year
Type for the year, note: 0 based, i.e. starts at the year 0.
Definition: date_type.h:20
Wagon (not used for road vehicles).
Definition: vehicle_base.h:115
byte vehstatus
Status.
Definition: vehicle_base.h:317
EngineImageType
Visualisation contexts of vehicles and engines.
Definition: vehicle_type.h:89
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:123
Generates sequence of free UnitID numbers.
Vehicle * next_shared
pointer to the next vehicle that shares the order
Definition: vehicle_base.h:221
Use default from engine class.
Definition: vehicle_base.h:85
VehicleSpriteSeq sprite_seq
Vehicle appearance.
Definition: vehicle_base.h:280
Direction
Defines the 8 directions on the map.
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:247
Types related to commands.
int8 x_bb_offs
x offset of vehicle bounding box
Definition: vehicle_base.h:284
DepotCommand
Flags to add to p1 for goto depot commands.
Definition: vehicle_type.h:69
Base class for orders.
Money profit_last_year
Profit last year << 8, low 8 bits are fract.
Definition: vehicle_base.h:240
bool _network_dedicated
are we a dedicated server?
Definition: network.cpp:59
Vehicle * FirstShared() const
Get the first vehicle of this vehicle chain.
Definition: vehicle_base.h:675
Diesel model.
Definition: vehicle_base.h:101
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:781
Value of offset corresponding to a position above the centre of the vehicle.
Definition: vehicle_base.h:81
Vehicle ** hash_tile_current
NOSAVE: Cache of the current hash chain.
Definition: vehicle_base.h:252
static const int32 INVALID_COORD
Sentinel for an invalid coordinate.
int8 y_bb_offs
y offset of vehicle bounding box
Definition: vehicle_base.h:285
byte breakdown_ctr
Counter for managing breakdown events.
Definition: vehicle_base.h:263
Vehicle * Move(int n)
Get the vehicle at offset n of this vehicle chain.
Definition: vehicle_base.h:623
Base class for cargo packets.
byte subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
Definition: vehicle_base.h:327
TextEffectID fill_percent_te_id
a text-effect id to a loading indicator object
Definition: vehicle_base.h:290
uint16 cargo_cap
total capacity
Definition: vehicle_base.h:307
Shared order list linking together the linked list of orders and the list of vehicles sharing this or...
Definition: order_base.h:252
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:486
Money GetDisplayRunningCost() const
Gets the running cost of a vehicle that can be sent into SetDParam for string processing.
Definition: vehicle_base.h:560
Class defining several overloaded accessors so we don&#39;t have to cast vehicle types that often...
Definition: vehicle_base.h:994
Vehicle is crashed.
Definition: vehicle_base.h:39
Vehicle is a prototype (accepted as exclusive preview).
Definition: vehicle_base.h:46
byte acceleration
used by train & aircraft
Definition: vehicle_base.h:295
First bit used for the type of effect.
Definition: vehicle_base.h:83
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
Definition: vehicle_base.h:433
Various front vehicle properties that are preserved when autoreplacing, using order-backup or switchi...
Definition: base_consist.h:19
UnitID unitnumber
unit number, for display purposes only
Definition: vehicle_base.h:291
byte cargo_subtype
Used for livery refits (NewGRF variations)
Definition: vehicle_base.h:306
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:222
bool IsValid() const
Check whether the sequence contains any sprites.
Definition: vehicle_base.h:147
uint16 remaining
Capacity remaining from before the previous refit.
Definition: vehicle_base.h:206
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:750
int8 y_offs
y offset for vehicle sprite
Definition: vehicle_base.h:287
VehicleType
Available vehicle types.
Definition: vehicle_type.h:23
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:1752
Don&#39;t load anymore during the next load cycle.
Definition: vehicle_base.h:50
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:932
DoCommandFlag
List of flags for a command.
Definition: command_type.h:343
VisualEffectSpawnModel
Models for spawning visual effects.
Definition: vehicle_base.h:98
virtual ExpensesType GetExpenseType(bool income) const
Sets the expense type associated to this vehicle type.
Definition: vehicle_base.h:423
bool IsArticulatedPart() const
Check if the vehicle is an articulated part of an engine.
Definition: vehicle_base.h:892
byte x_extent
x-extent of vehicle bounding box
Definition: vehicle_base.h:281
Pool< Vehicle, VehicleID, 512, 0xFF000 > VehiclePool
A vehicle pool for a little over 1 million vehicles.
Definition: vehicle_base.h:187
void InvalidateNewGRFCacheOfChain()
Invalidates cached NewGRF variables of all vehicles in the chain (after the current vehicle) ...
Definition: vehicle_base.h:460
Vehicle * GetNextVehicle() const
Get the next real (non-articulated part) vehicle in the consist.
Definition: vehicle_base.h:954
NewGRFCacheValidValues
Bit numbers used to indicate which of the NewGRFCache values are valid.
Definition: vehicle_base.h:57
byte waiting_triggers
Triggers to be yet matched before rerandomizing the random bits.
Definition: vehicle_base.h:300
Electric sparks.
Definition: vehicle_base.h:88
uint16 GroupID
Type for all group identifiers.
Definition: group_type.h:15
uint32 position_same_id_length
Cache for NewGRF var 41.
Definition: vehicle_base.h:70
byte z_extent
z-extent of vehicle bounding box
Definition: vehicle_base.h:283
Trackdir
Enumeration for tracks and directions.
Definition: track_type.h:74
void UpdateRealOrderIndex()
Skip implicit orders until cur_real_order_index is a non-implicit order.
Definition: vehicle_base.h:839
Service interval is custom.
Definition: vehicle_base.h:52
virtual int GetCurrentMaxSpeed() const
Calculates the maximum speed of the vehicle under its current conditions.
Definition: vehicle_base.h:492
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:205
CargoID cargo_type
type of cargo this vehicle is carrying
Definition: vehicle_base.h:305
Whether the vehicle should fill in the timetable automatically.
Definition: vehicle_base.h:48
uint16 load_unload_ticks
Ticks to wait before starting next cycle.
Definition: vehicle_base.h:325
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:322
bool IsFrontEngine() const
Check if the vehicle is a front engine.
Definition: vehicle_base.h:883
Properties for front vehicles/consists.
TileIndex tile
Current tile index.
Definition: vehicle_base.h:230
This bit will be set if the NewGRF var 42 currently stored is valid.
Definition: vehicle_base.h:60
virtual void UpdateDeltaXY()
Updates the x and y offsets and the size of the sprite used for this vehicle.
Definition: vehicle_base.h:370
ExpensesType
Types of expenses.
Definition: economy_type.h:150
bool HasArticulatedPart() const
Check if an engine has an articulated part.
Definition: vehicle_base.h:901
const Vehicle * Last() const
Get the last vehicle of this vehicle chain.
Definition: vehicle_base.h:611
Steam model.
Definition: vehicle_base.h:100
virtual bool IsInDepot() const
Check whether the vehicle is in the depot.
Definition: vehicle_base.h:504
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:740
int8 x_offs
x offset for vehicle sprite
Definition: vehicle_base.h:286
Sprite sequence for a vehicle part.
Definition: vehicle_base.h:130
Road vehicle type.
Definition: vehicle_type.h:27
Helper class to perform the cargo payment.
Definition: economy_base.h:26
Order * GetLastOrder() const
Returns the last order of a vehicle, or NULL if it doesn&#39;t exists.
Definition: vehicle_base.h:869
uint16 refit_cap
Capacity left over from before last refit.
Definition: vehicle_base.h:308
byte random_bits
Bits used for determining which randomized variational spritegroups to use when drawing.
Definition: vehicle_base.h:299
byte breakdowns_since_last_service
Counter for the amount of breakdowns.
Definition: vehicle_base.h:265
uint16 reliability
Reliability.
Definition: vehicle_base.h:261
Vehicle * First() const
Get the first vehicle of this vehicle chain.
Definition: vehicle_base.h:594
Vehicle&#39;s pathfinder is lost.
Definition: vehicle_base.h:51
byte tick_counter
Increased by one for each tick.
Definition: vehicle_base.h:314
Order * GetFirstOrder() const
Get the first order of the vehicles order list.
Definition: vehicle_base.h:654
UnitID curid
last ID returned; 0 if none
Base class for all PoolItems.
Definition: pool_type.hpp:146
Year build_year
Year the vehicle has been built.
Definition: vehicle_base.h:257
Engine is multiheaded (not used for road vehicles).
Definition: vehicle_base.h:118
Base class for all pools.
Definition: pool_type.hpp:83
virtual Money GetRunningCost() const
Gets the running cost of a vehicle.
Definition: vehicle_base.h:498
~FreeUnitIDGenerator()
Releases allocated memory.
byte breakdown_chance
Current chance of breakdowns.
Definition: vehicle_base.h:266
Diesel fumes.
Definition: vehicle_base.h:87
This bit will be set if the NewGRF var 4D currently stored is valid.
Definition: vehicle_base.h:62
int8 trip_occupancy
NOSAVE: Occupancy of vehicle of the current trip (updated after leaving a station).
Definition: vehicle_base.h:311
static EngineID GetNextArticulatedPart(uint index, EngineID front_type, Vehicle *front=NULL, bool *mirrored=NULL)
Determines the next articulated part to attach.
Flag to disable visual effect.
Definition: vehicle_base.h:90
Steam plumes.
Definition: vehicle_base.h:86
uint32 company_information
Cache for NewGRF var 43.
Definition: vehicle_base.h:72
Vehicle * GetPrevVehicle() const
Get the previous real (non-articulated part) vehicle in the consist.
Definition: vehicle_base.h:967
Articulated part of an engine.
Definition: vehicle_base.h:114
bool IsGroundVehicle() const
Check if the vehicle is a ground vehicle.
Definition: vehicle_base.h:471
byte subspeed
fractional speed
Definition: vehicle_base.h:294
CargoList that is used for vehicles.
Definition: cargopacket.h:283
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:19
Vehicle * GetLastEnginePart()
Get the last part of an articulated engine.
Definition: vehicle_base.h:943
uint16 EngineID
Unique identification number of an engine.
Definition: engine_type.h:22
Number of bits used for the effect type.
Definition: vehicle_base.h:84
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
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:414
Vehicle * Next() const
Get the next vehicle of this vehicle.
Definition: vehicle_base.h:581
Date date_of_last_service
Last date the vehicle had a service at a depot.
Definition: vehicle_base.h:260
CargoPayment * cargo_payment
The cargo payment we&#39;re currently in.
Definition: vehicle_base.h:243
Vehicle * PreviousShared() const
Get the previous vehicle of the shared vehicle chain.
Definition: vehicle_base.h:669
CargoID cargo
Cargo type the vehicle will be carrying.
Definition: vehicle_base.h:204
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:71
void FixOldVehicles()
Convert the old style vehicles into something that resembles the old new style savegames.
OwnerByte owner
Which company owns the vehicle?
Definition: vehicle_base.h:273
uint32 position_in_vehicle
Cache for NewGRF var 4D.
Definition: vehicle_base.h:73
StationIDStack GetNextStoppingStation() const
Get the next station the vehicle will stop at.
Definition: vehicle_base.h:699
Vehicle * GetNextArticulatedPart() const
Get the next part of an articulated engine.
Definition: vehicle_base.h:911
SpecializedVehicle< T, Type > SpecializedVehicleBase
Our type.
Definition: vehicle_base.h:997
GroundVehicleSubtypeFlags
Enum to handle ground vehicle subtypes.
Definition: vehicle_base.h:112
Vehicle * next
pointer to the next vehicle in the chain
Definition: vehicle_base.h:217
void AfterLoadVehicles(bool part_of_load)
Called after load to update coordinates.
Definition: vehicle_sl.cpp:249
First in a wagon chain (in depot) (not used for road vehicles).
Definition: vehicle_base.h:117
Vehicle * previous_shared
NOSAVE: pointer to the previous vehicle in the shared order chain.
Definition: vehicle_base.h:222
End of the bits.
Definition: vehicle_base.h:63
void CopyVehicleConfigAndStatistics(const Vehicle *src)
Copy certain configurations and statistics of a vehicle after successful autoreplace/renew The functi...
Definition: vehicle_base.h:712
virtual void OnNewDay()
Calls the new day handler of the vehicle.
Definition: vehicle_base.h:533
Default value to indicate that visual effect should be based on engine class.
Definition: vehicle_base.h:94
int32 z_pos
z coordinate.
Definition: vehicle_base.h:270
Vehicle is not visible.
Definition: vehicle_base.h:32
Vehicle * previous
NOSAVE: pointer to the previous vehicle in the chain.
Definition: vehicle_base.h:218
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-NULL) Titem.
Definition: pool_type.hpp:235
Base vehicle class.
Definition: vehicle_type.h:54
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 NULL when it doesn&#39;t exists.
Definition: vehicle_base.h:860
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
Definition: vehicle_base.h:687
int32 Date
The type to store our dates in.
Definition: date_type.h:16
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: depend.cpp:114
bool IsOrderListShared() const
Check if we share our orders with another vehicle.
Definition: vehicle_base.h:681
byte running_ticks
Number of ticks this vehicle was not stopped this day.
Definition: vehicle_base.h:315
virtual Trackdir GetVehicleTrackdir() const
Returns the Trackdir on which the vehicle is currently located.
Definition: vehicle_base.h:554
byte y_extent
y-extent of vehicle bounding box
Definition: vehicle_base.h:282
Flag to disable wagon power.
Definition: vehicle_base.h:92
EngineID engine_type
The type of engine used for this vehicle.
Definition: vehicle_base.h:288
SaveLoad type struct.
Definition: saveload.h:486
byte cached_vis_effect
Visual effect to show (see VisualEffect)
Definition: vehicle_base.h:126
virtual void PlayLeaveStationSound() const
Play the sound associated with leaving the station.
Definition: vehicle_base.h:428
int32 x_pos
x coordinate.
Definition: vehicle_base.h:268
virtual bool Tick()
Calls the tick handler of the vehicle.
Definition: vehicle_base.h:528
byte VehicleOrderID
The index of an order within its current vehicle (not pool related)
Definition: order_type.h:17
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:639
uint8 cache_valid
Bitset that indicates which cache values are valid.
Definition: vehicle_base.h:74
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:85
Whether non-destructive auto-fill should preserve waiting times.
Definition: vehicle_base.h:49
byte progress
The percentage (if divided by 256) this vehicle already crossed the tile unit.
Definition: vehicle_base.h:297
virtual int GetDisplaySpeed() const
Gets the speed in km-ish/h that can be sent into SetDParam for string processing. ...
Definition: vehicle_base.h:480
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:22
int32 y_pos
y coordinate.
Definition: vehicle_base.h:269
Other expenses.
Definition: economy_type.h:163
static uint GetAdvanceSpeed(uint speed)
Determines the effective vehicle movement speed.
Definition: vehicle_base.h:402
Vehicle * NextShared() const
Get the next vehicle of the shared vehicle chain.
Definition: vehicle_base.h:663
Owner
Enum for all companies/owners.
Definition: company_type.h:20
virtual bool IsChainInDepot() const
Check whether the whole vehicle chain is in the depot.
Definition: vehicle_base.h:510
Flag for advanced effects.
Definition: vehicle_base.h:91
Flag for an invalid trackdir.
Definition: track_type.h:93
Vehicle * Last()
Get the last vehicle of this vehicle chain.
Definition: vehicle_base.h:600
VehicleFlags
Bit numbers in Vehicle::vehicle_flags.
Definition: vehicle_base.h:43
Functions related to text effects.
SpriteID sprite
The &#39;real&#39; sprite.
Definition: gfx_type.h:25
Money profit_this_year
Profit this year << 8, low 8 bits are fract.
Definition: vehicle_base.h:239
const SaveLoad * GetVehicleDescription(VehicleType vt)
Make it possible to make the saveload tables "friends" of other classes.
Definition: vehicle_sl.cpp:593
VehicleCache vcache
Cache of often used vehicle values.
Definition: vehicle_base.h:330
Number of bits used for the offset.
Definition: vehicle_base.h:80
VisualEffect
Meaning of the various bits of the visual effect.
Definition: vehicle_base.h:78
Rect coord
NOSAVE: Graphical bounding box of the vehicle, i.e. what to redraw on moves.
Definition: vehicle_base.h:245
Vehicle * first
NOSAVE: pointer to the first vehicle in the chain.
Definition: vehicle_base.h:219
Date age
Age in days.
Definition: vehicle_base.h:258
VehicleTypeByte type
Type of vehicle.
Definition: vehicle_type.h:56
Types of a group.
Station data structure.
Definition: station_base.h:446
NewGRFCache grf_cache
Cache of often used calculated NewGRF values.
Definition: vehicle_base.h:329
void InvalidateNewGRFCache()
Invalidates cached NewGRF variables.
Definition: vehicle_base.h:451
Money GetDisplayProfitLastYear() const
Gets the profit vehicle had last year.
Definition: vehicle_base.h:572
uint GetOldAdvanceSpeed(uint speed)
Determines the effective direction-specific vehicle movement speed.
Definition: vehicle_base.h:385
Train is slowing down.
Definition: vehicle_base.h:36
byte day_counter
Increased by one for each day.
Definition: vehicle_base.h:313
Order current_order
The current order (+ status, like: loading)
Definition: vehicle_base.h:318
GroupID group_id
Index of group Pool array.
Definition: vehicle_base.h:326
Vehicle is not clickable by the user (shadow vehicles).
Definition: vehicle_base.h:34
SpriteID colourmap
NOSAVE: cached colour mapping.
Definition: vehicle_base.h:254
VehicleOrderID GetNumManualOrders() const
Get the number of manually added orders this vehicle has.
Definition: vehicle_base.h:693
Service interval is percent.
Definition: vehicle_base.h:53
Dynamic data of a loaded NewGRF.
Definition: newgrf.h:104
Train vehicle type.
Definition: vehicle_type.h:26
PaletteID pal
The palette (use PAL_NONE) if not needed)
Definition: gfx_type.h:26