OpenTTD
vehicle_base.h
Go to the documentation of this file.
1 /* $Id: vehicle_base.h 27822 2017-03-24 07:33:31Z peter1138 $ */
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 
371  virtual void UpdateDeltaXY(Direction direction) {}
372 
386  inline uint GetOldAdvanceSpeed(uint speed)
387  {
388  return (this->direction & 1) ? speed : speed * 3 / 4;
389  }
390 
403  static inline uint GetAdvanceSpeed(uint speed)
404  {
405  return speed * 3 / 4;
406  }
407 
415  inline uint GetAdvanceDistance()
416  {
417  return (this->direction & 1) ? 192 : 256;
418  }
419 
424  virtual ExpensesType GetExpenseType(bool income) const { return EXPENSES_OTHER; }
425 
429  virtual void PlayLeaveStationSound() const {}
430 
434  virtual bool IsPrimaryVehicle() const { return false; }
435 
436  const Engine *GetEngine() const;
437 
443  virtual void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const { result->Clear(); }
444 
445  const GRFFile *GetGRF() const;
446  uint32 GetGRFID() const;
447 
452  inline void InvalidateNewGRFCache()
453  {
454  this->grf_cache.cache_valid = 0;
455  }
456 
462  {
463  for (Vehicle *u = this; u != NULL; u = u->Next()) {
464  u->InvalidateNewGRFCache();
465  }
466  }
467 
472  inline bool IsGroundVehicle() const
473  {
474  return this->type == VEH_TRAIN || this->type == VEH_ROAD;
475  }
476 
481  virtual int GetDisplaySpeed() const { return 0; }
482 
487  virtual int GetDisplayMaxSpeed() const { return 0; }
488 
493  virtual int GetCurrentMaxSpeed() const { return 0; }
494 
499  virtual Money GetRunningCost() const { return 0; }
500 
505  virtual bool IsInDepot() const { return false; }
506 
511  virtual bool IsChainInDepot() const { return this->IsInDepot(); }
512 
517  bool IsStoppedInDepot() const
518  {
519  assert(this == this->First());
520  /* Free wagons have no VS_STOPPED state */
521  if (this->IsPrimaryVehicle() && !(this->vehstatus & VS_STOPPED)) return false;
522  return this->IsChainInDepot();
523  }
524 
529  virtual bool Tick() { return true; };
530 
534  virtual void OnNewDay() {};
535 
541  virtual uint Crash(bool flooded = false);
542 
555  virtual Trackdir GetVehicleTrackdir() const { return INVALID_TRACKDIR; }
556 
561  Money GetDisplayRunningCost() const { return (this->GetRunningCost() >> 8); }
562 
567  Money GetDisplayProfitThisYear() const { return (this->profit_this_year >> 8); }
568 
573  Money GetDisplayProfitLastYear() const { return (this->profit_last_year >> 8); }
574 
575  void SetNext(Vehicle *next);
576 
582  inline Vehicle *Next() const { return this->next; }
583 
589  inline Vehicle *Previous() const { return this->previous; }
590 
595  inline Vehicle *First() const { return this->first; }
596 
601  inline Vehicle *Last()
602  {
603  Vehicle *v = this;
604  while (v->Next() != NULL) v = v->Next();
605  return v;
606  }
607 
612  inline const Vehicle *Last() const
613  {
614  const Vehicle *v = this;
615  while (v->Next() != NULL) v = v->Next();
616  return v;
617  }
618 
624  inline Vehicle *Move(int n)
625  {
626  Vehicle *v = this;
627  if (n < 0) {
628  for (int i = 0; i != n && v != NULL; i--) v = v->Previous();
629  } else {
630  for (int i = 0; i != n && v != NULL; i++) v = v->Next();
631  }
632  return v;
633  }
634 
640  inline const Vehicle *Move(int n) const
641  {
642  const Vehicle *v = this;
643  if (n < 0) {
644  for (int i = 0; i != n && v != NULL; i--) v = v->Previous();
645  } else {
646  for (int i = 0; i != n && v != NULL; i++) v = v->Next();
647  }
648  return v;
649  }
650 
655  inline Order *GetFirstOrder() const { return (this->orders.list == NULL) ? NULL : this->orders.list->GetFirstOrder(); }
656 
657  void AddToShared(Vehicle *shared_chain);
658  void RemoveFromShared();
659 
664  inline Vehicle *NextShared() const { return this->next_shared; }
665 
670  inline Vehicle *PreviousShared() const { return this->previous_shared; }
671 
676  inline Vehicle *FirstShared() const { return (this->orders.list == NULL) ? this->First() : this->orders.list->GetFirstSharedVehicle(); }
677 
682  inline bool IsOrderListShared() const { return this->orders.list != NULL && this->orders.list->IsShared(); }
683 
688  inline VehicleOrderID GetNumOrders() const { return (this->orders.list == NULL) ? 0 : this->orders.list->GetNumOrders(); }
689 
694  inline VehicleOrderID GetNumManualOrders() const { return (this->orders.list == NULL) ? 0 : this->orders.list->GetNumManualOrders(); }
695 
701  {
702  return (this->orders.list == NULL) ? INVALID_STATION : this->orders.list->GetNextStoppingStation(this);
703  }
704 
705  void ResetRefitCaps();
706 
713  inline void CopyVehicleConfigAndStatistics(const Vehicle *src)
714  {
715  this->CopyConsistPropertiesFrom(src);
716 
717  this->unitnumber = src->unitnumber;
718 
719  this->current_order = src->current_order;
720  this->dest_tile = src->dest_tile;
721 
722  this->profit_this_year = src->profit_this_year;
723  this->profit_last_year = src->profit_last_year;
724  }
725 
726 
727  bool HandleBreakdown();
728 
729  bool NeedsAutorenewing(const Company *c, bool use_renew_setting = true) const;
730 
731  bool NeedsServicing() const;
732  bool NeedsAutomaticServicing() const;
733 
741  virtual TileIndex GetOrderStationLocation(StationID station) { return INVALID_TILE; }
742 
751  virtual bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse) { return false; }
752 
753  CommandCost SendToDepot(DoCommandFlag flags, DepotCommand command);
754 
755  void UpdateVisualEffect(bool allow_power_change = true);
756  void ShowVisualEffect() const;
757 
758  void UpdatePosition();
759  void UpdateViewport(bool dirty);
760  void UpdatePositionAndViewport();
761  void MarkAllViewportsDirty() const;
762 
763  inline uint16 GetServiceInterval() const { return this->service_interval; }
764 
765  inline void SetServiceInterval(uint16 interval) { this->service_interval = interval; }
766 
767  inline bool ServiceIntervalIsCustom() const { return HasBit(this->vehicle_flags, VF_SERVINT_IS_CUSTOM); }
768 
769  inline bool ServiceIntervalIsPercent() const { return HasBit(this->vehicle_flags, VF_SERVINT_IS_PERCENT); }
770 
771  inline void SetServiceIntervalIsCustom(bool on) { SB(this->vehicle_flags, VF_SERVINT_IS_CUSTOM, 1, on); }
772 
773  inline void SetServiceIntervalIsPercent(bool on) { SB(this->vehicle_flags, VF_SERVINT_IS_PERCENT, 1, on); }
774 
775 private:
781  {
782  if (this->GetNumManualOrders() > 0) {
783  /* Advance to next real order */
784  do {
785  this->cur_real_order_index++;
786  if (this->cur_real_order_index >= this->GetNumOrders()) this->cur_real_order_index = 0;
787  } while (this->GetOrder(this->cur_real_order_index)->IsType(OT_IMPLICIT));
788  } else {
789  this->cur_real_order_index = 0;
790  }
791  }
792 
793 public:
800  {
801  if (this->cur_implicit_order_index == this->cur_real_order_index) {
802  /* Increment real order index as well */
803  this->SkipToNextRealOrderIndex();
804  }
805 
806  assert(this->cur_real_order_index == 0 || this->cur_real_order_index < this->GetNumOrders());
807 
808  /* Advance to next implicit order */
809  do {
810  this->cur_implicit_order_index++;
811  if (this->cur_implicit_order_index >= this->GetNumOrders()) this->cur_implicit_order_index = 0;
812  } while (this->cur_implicit_order_index != this->cur_real_order_index && !this->GetOrder(this->cur_implicit_order_index)->IsType(OT_IMPLICIT));
813 
814  InvalidateVehicleOrder(this, 0);
815  }
816 
824  {
825  if (this->cur_implicit_order_index == this->cur_real_order_index) {
826  /* Increment both real and implicit order */
827  this->IncrementImplicitOrderIndex();
828  } else {
829  /* Increment real order only */
830  this->SkipToNextRealOrderIndex();
831  InvalidateVehicleOrder(this, 0);
832  }
833  }
834 
839  {
840  /* Make sure the index is valid */
841  if (this->cur_real_order_index >= this->GetNumOrders()) this->cur_real_order_index = 0;
842 
843  if (this->GetNumManualOrders() > 0) {
844  /* Advance to next real order */
845  while (this->GetOrder(this->cur_real_order_index)->IsType(OT_IMPLICIT)) {
846  this->cur_real_order_index++;
847  if (this->cur_real_order_index >= this->GetNumOrders()) this->cur_real_order_index = 0;
848  }
849  } else {
850  this->cur_real_order_index = 0;
851  }
852  }
853 
859  inline Order *GetOrder(int index) const
860  {
861  return (this->orders.list == NULL) ? NULL : this->orders.list->GetOrderAt(index);
862  }
863 
868  inline Order *GetLastOrder() const
869  {
870  return (this->orders.list == NULL) ? NULL : this->orders.list->GetLastOrder();
871  }
872 
873  bool IsEngineCountable() const;
874  bool HasEngineType() const;
875  bool HasDepotOrder() const;
876  void HandlePathfindingResult(bool path_found);
877 
882  inline bool IsFrontEngine() const
883  {
884  return this->IsGroundVehicle() && HasBit(this->subtype, GVSF_FRONT);
885  }
886 
891  inline bool IsArticulatedPart() const
892  {
893  return this->IsGroundVehicle() && HasBit(this->subtype, GVSF_ARTICULATED_PART);
894  }
895 
900  inline bool HasArticulatedPart() const
901  {
902  return this->Next() != NULL && this->Next()->IsArticulatedPart();
903  }
904 
911  {
912  assert(this->HasArticulatedPart());
913  return this->Next();
914  }
915 
921  {
922  Vehicle *v = this;
923  while (v->IsArticulatedPart()) v = v->Previous();
924  return v;
925  }
926 
931  inline const Vehicle *GetFirstEnginePart() const
932  {
933  const Vehicle *v = this;
934  while (v->IsArticulatedPart()) v = v->Previous();
935  return v;
936  }
937 
943  {
944  Vehicle *v = this;
945  while (v->HasArticulatedPart()) v = v->GetNextArticulatedPart();
946  return v;
947  }
948 
953  inline Vehicle *GetNextVehicle() const
954  {
955  const Vehicle *v = this;
956  while (v->HasArticulatedPart()) v = v->GetNextArticulatedPart();
957 
958  /* v now contains the last articulated part in the engine */
959  return v->Next();
960  }
961 
966  inline Vehicle *GetPrevVehicle() const
967  {
968  Vehicle *v = this->Previous();
969  while (v != NULL && v->IsArticulatedPart()) v = v->Previous();
970 
971  return v;
972  }
973 };
974 
980 #define FOR_ALL_VEHICLES_FROM(var, start) FOR_ALL_ITEMS_FROM(Vehicle, vehicle_index, var, start)
981 
986 #define FOR_ALL_VEHICLES(var) FOR_ALL_VEHICLES_FROM(var, 0)
987 
992 template <class T, VehicleType Type>
993 struct SpecializedVehicle : public Vehicle {
994  static const VehicleType EXPECTED_TYPE = Type;
995 
997 
1002  {
1003  this->sprite_seq.count = 1;
1004  }
1005 
1010  inline T *First() const { return (T *)this->Vehicle::First(); }
1011 
1016  inline T *Last() { return (T *)this->Vehicle::Last(); }
1017 
1022  inline const T *Last() const { return (const T *)this->Vehicle::Last(); }
1023 
1028  inline T *Next() const { return (T *)this->Vehicle::Next(); }
1029 
1034  inline T *Previous() const { return (T *)this->Vehicle::Previous(); }
1035 
1041  inline T *GetNextArticulatedPart() { return (T *)this->Vehicle::GetNextArticulatedPart(); }
1042 
1048  inline T *GetNextArticulatedPart() const { return (T *)this->Vehicle::GetNextArticulatedPart(); }
1049 
1054  inline T *GetFirstEnginePart() { return (T *)this->Vehicle::GetFirstEnginePart(); }
1055 
1060  inline const T *GetFirstEnginePart() const { return (const T *)this->Vehicle::GetFirstEnginePart(); }
1061 
1066  inline T *GetLastEnginePart() { return (T *)this->Vehicle::GetLastEnginePart(); }
1067 
1072  inline T *GetNextVehicle() const { return (T *)this->Vehicle::GetNextVehicle(); }
1073 
1078  inline T *GetPrevVehicle() const { return (T *)this->Vehicle::GetPrevVehicle(); }
1079 
1085  static inline bool IsValidID(size_t index)
1086  {
1087  return Vehicle::IsValidID(index) && Vehicle::Get(index)->type == Type;
1088  }
1089 
1094  static inline T *Get(size_t index)
1095  {
1096  return (T *)Vehicle::Get(index);
1097  }
1098 
1103  static inline T *GetIfValid(size_t index)
1104  {
1105  return IsValidID(index) ? Get(index) : NULL;
1106  }
1107 
1113  static inline T *From(Vehicle *v)
1114  {
1115  assert(v->type == Type);
1116  return (T *)v;
1117  }
1118 
1124  static inline const T *From(const Vehicle *v)
1125  {
1126  assert(v->type == Type);
1127  return (const T *)v;
1128  }
1129 
1135  inline void UpdateViewport(bool force_update, bool update_delta)
1136  {
1137  /* Skip updating sprites on dedicated servers without screen */
1138  if (_network_dedicated) return;
1139 
1140  /* Explicitly choose method to call to prevent vtable dereference -
1141  * it gives ~3% runtime improvements in games with many vehicles */
1142  if (update_delta) ((T *)this)->T::UpdateDeltaXY(this->direction);
1143  VehicleSpriteSeq seq;
1144  ((T *)this)->T::GetImage(this->direction, EIT_ON_MAP, &seq);
1145  if (force_update || this->sprite_seq != seq) {
1146  this->sprite_seq = seq;
1147  this->Vehicle::UpdateViewport(true);
1148  }
1149  }
1150 };
1151 
1157 #define FOR_ALL_VEHICLES_OF_TYPE(name, var) FOR_ALL_ITEMS_FROM(name, vehicle_index, var, 0) if (var->type == name::EXPECTED_TYPE)
1158 
1161  bool *cache;
1164 
1166  UnitID NextID();
1167 
1169  ~FreeUnitIDGenerator() { free(this->cache); }
1170 };
1171 
1173 static const int32 INVALID_COORD = 0x7fffffff;
1174 
1175 #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:589
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:567
DirectionByte direction
facing
Definition: vehicle_base.h:271
Non-existing type of vehicle.
Definition: vehicle_type.h:35
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:920
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:252
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:88
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:517
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:799
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:823
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:443
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:1557
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:87
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:67
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:676
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:780
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:624
Base class for cargo packets.
byte subtype
subtype (Filled with values from #EffectVehicles/#TrainSubTypes/#AircraftSubTypes) ...
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:487
Money GetDisplayRunningCost() const
Gets the running cost of a vehicle that can be sent into SetDParam for string processing.
Definition: vehicle_base.h:561
Class defining several overloaded accessors so we don&#39;t have to cast vehicle types that often...
Definition: vehicle_base.h:993
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:434
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:751
int8 y_offs
y offset for vehicle sprite
Definition: vehicle_base.h:287
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
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:1872
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:931
DoCommandFlag
List of flags for a command.
Definition: command_type.h:340
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:424
bool IsArticulatedPart() const
Check if the vehicle is an articulated part of an engine.
Definition: vehicle_base.h:891
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:461
Vehicle * GetNextVehicle() const
Get the next real (non-articulated part) vehicle in the consist.
Definition: vehicle_base.h:953
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:838
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:493
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:882
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
ExpensesType
Types of expenses.
Definition: economy_type.h:150
bool HasArticulatedPart() const
Check if an engine has an articulated part.
Definition: vehicle_base.h:900
const Vehicle * Last() const
Get the last vehicle of this vehicle chain.
Definition: vehicle_base.h:612
Steam model.
Definition: vehicle_base.h:100
virtual bool IsInDepot() const
Check whether the vehicle is in the depot.
Definition: vehicle_base.h:505
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:741
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:25
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:868
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:595
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:655
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:499
~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:966
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:472
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:942
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:415
Vehicle * Next() const
Get the next vehicle of this vehicle.
Definition: vehicle_base.h:582
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:670
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:700
Vehicle * GetNextArticulatedPart() const
Get the next part of an articulated engine.
Definition: vehicle_base.h:910
SpecializedVehicle< T, Type > SpecializedVehicleBase
Our type.
Definition: vehicle_base.h:996
GroundVehicleSubtypeFlags
Enum to handle ground vehicle subtypes.
Definition: vehicle_base.h:112
virtual void UpdateDeltaXY(Direction direction)
Updates the x and y offsets and the size of the sprite used for this vehicle.
Definition: vehicle_base.h:371
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:713
virtual void OnNewDay()
Calls the new day handler of the vehicle.
Definition: vehicle_base.h:534
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:52
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:859
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
Definition: vehicle_base.h:688
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:682
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:555
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:208
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:429
int32 x_pos
x coordinate.
Definition: vehicle_base.h:268
virtual bool Tick()
Calls the tick handler of the vehicle.
Definition: vehicle_base.h:529
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:640
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:481
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:403
Vehicle * NextShared() const
Get the next vehicle of the shared vehicle chain.
Definition: vehicle_base.h:664
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:511
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:601
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:574
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:54
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:452
Money GetDisplayProfitLastYear() const
Gets the profit vehicle had last year.
Definition: vehicle_base.h:573
uint GetOldAdvanceSpeed(uint speed)
Determines the effective direction-specific vehicle movement speed.
Definition: vehicle_base.h:386
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:694
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:24
PaletteID pal
The palette (use PAL_NONE) if not needed)
Definition: gfx_type.h:26