OpenTTD Source: src/vehicle_base.h Source File

OpenTTD Source 15.3

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef VEHICLE_BASE_H
11#define VEHICLE_BASE_H
12
13#include "sprite.h"
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 "saveload/saveload.h"
26#include "timer/timer_game_calendar.h"
27
28const uint TILE_AXIAL_DISTANCE = 192; // Logical length of the tile in any DiagDirection used in vehicle movement.
29const uint TILE_CORNER_DISTANCE = 128; // Logical length of the tile corner crossing in any non-diagonal direction used in vehicle movement.
30
32 enum class VehState : uint8_t {
33 Hidden = 0,
34 Stopped = 1,
35 Unclickable = 2,
36 DefaultPalette = 3,
37 TrainSlowing = 4,
38 Shadow = 5,
39 AircraftBroken = 6,
40 Crashed = 7,
41};
42using VehStates = EnumBitSet<VehState, uint8_t>;
43
45 enum NewGRFCacheValidValues : uint8_t {
46 NCVV_POSITION_CONSIST_LENGTH = 0,
47 NCVV_POSITION_SAME_ID_LENGTH = 1,
48 NCVV_CONSIST_CARGO_INFORMATION = 2,
49 NCVV_COMPANY_INFORMATION = 3,
50 NCVV_POSITION_IN_VEHICLE = 4,
51 NCVV_END,
52};
53
55 struct NewGRFCache {
56 /* Values calculated when they are requested for the first time after invalidating the NewGRF cache. */
57 uint32_t position_consist_length = 0;
58 uint32_t position_same_id_length = 0;
59 uint32_t consist_cargo_information = 0;
60 uint32_t company_information = 0;
61 uint32_t position_in_vehicle = 0;
62 uint8_t cache_valid = 0;
63
64 auto operator<=>(const NewGRFCache &) const = default;
65};
66
68 enum VisualEffectSpawnModel : uint8_t {
69 VESM_NONE = 0,
70 VESM_STEAM,
71 VESM_DIESEL,
72 VESM_ELECTRIC,
73
74 VESM_END
75};
76
82 enum GroundVehicleSubtypeFlags : uint8_t {
83 GVSF_FRONT = 0,
84 GVSF_ARTICULATED_PART = 1,
85 GVSF_WAGON = 2,
86 GVSF_ENGINE = 3,
87 GVSF_FREE_WAGON = 4,
88 GVSF_MULTIHEADED = 5,
89};
90
92 struct VehicleCache {
93 uint16_t cached_max_speed = 0;
94 uint16_t cached_cargo_age_period = 0;
95
96 uint8_t cached_vis_effect = 0;
97
98 auto operator<=>(const VehicleCache &) const = default;
99};
100
102 struct VehicleSpriteSeq {
103 std::array<PalSpriteID, 8> seq;
104 uint count;
105
106 bool operator==(const VehicleSpriteSeq &other) const
107 {
108 return std::ranges::equal(std::span(this->seq.data(), this->count), std::span(other.seq.data(), other.count));
109 }
110
114 bool IsValid() const
115 {
116 return this->count != 0;
117 }
118
122 void Clear()
123 {
124 this->count = 0;
125 }
126
130 void Set(SpriteID sprite)
131 {
132 this->count = 1;
133 this->seq[0].sprite = sprite;
134 this->seq[0].pal = 0;
135 }
136
140 void CopyWithoutPalette(const VehicleSpriteSeq &src)
141 {
142 this->count = src.count;
143 for (uint i = 0; i < src.count; ++i) {
144 this->seq[i].sprite = src.seq[i].sprite;
145 this->seq[i].pal = 0;
146 }
147 }
148
149 void GetBounds(Rect *bounds) const;
150 void Draw(int x, int y, PaletteID default_pal, bool force_pal) const;
151};
152
157 struct MutableSpriteCache {
158 Direction last_direction = INVALID_DIR;
159 bool revalidate_before_draw = false;
160 bool is_viewport_candidate = false;
161 Rect old_coord{};
162 VehicleSpriteSeq sprite_seq{};
163};
164
166 typedef Pool<Vehicle, VehicleID, 512> VehiclePool;
167extern VehiclePool _vehicle_pool;
168
169/* Some declarations of functions, so we can make them friendly */
170struct GroundVehicleCache;
171struct LoadgameState;
172extern bool LoadOldVehicle(LoadgameState &ls, int num);
173extern void FixOldVehicles(LoadgameState &ls);
174
175struct GRFFile;
176
180 struct RefitDesc {
181 CargoType cargo;
182 uint16_t capacity;
183 uint16_t remaining;
184 RefitDesc(CargoType cargo, uint16_t capacity, uint16_t remaining) :
185 cargo(cargo), capacity(capacity), remaining(remaining) {}
186};
187
192 struct ClosestDepot {
193 TileIndex location = INVALID_TILE;
194 DestinationID destination{};
195 bool reverse = false;
196 bool found = false;
197
198 ClosestDepot() = default;
199
200 ClosestDepot(TileIndex location, DestinationID destination, bool reverse = false) :
201 location(location), destination(destination), reverse(reverse), found(true) {}
202};
203
205 struct Vehicle : VehiclePool::PoolItem<&_vehicle_pool>, BaseVehicle, BaseConsist {
206private:
207 typedef std::list<RefitDesc> RefitList;
208
209 Vehicle *next = nullptr;
210 Vehicle *previous = nullptr;
211 Vehicle *first = nullptr;
212
213 Vehicle *next_shared = nullptr;
214 Vehicle *previous_shared = nullptr;
215
216public:
217 friend void FixOldVehicles(LoadgameState &ls);
218 friend void AfterLoadVehiclesPhase1(bool part_of_load);
219 friend bool LoadOldVehicle(LoadgameState &ls, int num);
220 /* So we can use private/protected variables in the saveload code */
221 friend class SlVehicleCommon;
222 friend class SlVehicleDisaster;
223 friend void Ptrs_VEHS();
224
225 TileIndex tile = INVALID_TILE;
226
232 TileIndex dest_tile = INVALID_TILE;
233
234 Money profit_this_year = 0;
235 Money profit_last_year = 0;
236 Money value = 0;
237
238 CargoPayment *cargo_payment = nullptr;
239
240 mutable Rect coord{};
241
242 Vehicle *hash_viewport_next = nullptr;
243 Vehicle **hash_viewport_prev = nullptr;
244
245 Vehicle *hash_tile_next = nullptr;
246 Vehicle **hash_tile_prev = nullptr;
247 Vehicle **hash_tile_current = nullptr;
248
249 SpriteID colourmap{};
250
251 /* Related to age and service time */
252 TimerGameCalendar::Year build_year{};
253 TimerGameCalendar::Date age{};
254 TimerGameEconomy::Date economy_age{};
255 TimerGameCalendar::Date max_age{};
256 TimerGameEconomy::Date date_of_last_service{};
257 TimerGameCalendar::Date date_of_last_service_newgrf{};
258 uint16_t reliability = 0;
259 uint16_t reliability_spd_dec = 0;
260 uint8_t breakdown_ctr = 0;
261 uint8_t breakdown_delay = 0;
262 uint8_t breakdowns_since_last_service = 0;
263 uint8_t breakdown_chance = 0;
264
265 int32_t x_pos = 0;
266 int32_t y_pos = 0;
267 int32_t z_pos = 0;
268 Direction direction = INVALID_DIR;
269
270 Owner owner = INVALID_OWNER;
276 uint8_t spritenum = 0;
277 SpriteBounds bounds{};
278 EngineID engine_type = EngineID::Invalid();
279
280 TextEffectID fill_percent_te_id = INVALID_TE_ID;
281 UnitID unitnumber{};
282
283 uint16_t cur_speed = 0;
284 uint8_t subspeed = 0;
285 uint8_t acceleration = 0;
286 uint32_t motion_counter = 0;
287 uint8_t progress = 0;
288
289 VehicleRandomTriggers waiting_random_triggers;
290 uint16_t random_bits = 0;
291
292 StationID last_station_visited = StationID::Invalid();
293 StationID last_loading_station = StationID::Invalid();
294 TimerGameTick::TickCounter last_loading_tick{};
295
296 VehicleCargoList cargo{};
297 CargoType cargo_type{};
298 uint8_t cargo_subtype = 0;
299 uint16_t cargo_cap = 0;
300 uint16_t refit_cap = 0;
301 uint16_t cargo_age_counter = 0;
302 int8_t trip_occupancy = 0;
303
304 uint8_t day_counter = 0;
305 uint8_t tick_counter = 0;
306 uint8_t running_ticks = 0;
307 uint16_t load_unload_ticks = 0;
308
309 VehStates vehstatus{};
310 uint8_t subtype = 0;
311 Order current_order{};
312
313 union {
314 OrderList *orders = nullptr;
315 uint32_t old_orders;
316 };
317
318 NewGRFCache grf_cache{};
319 VehicleCache vcache{};
320
321 GroupID group_id = GroupID::Invalid();
322
323 mutable MutableSpriteCache sprite_cache{};
324
329 virtual uint16_t GetMaxWeight() const
330 {
331 return 0;
332 }
333
334 Vehicle(VehicleType type = VEH_INVALID);
335
336 void PreDestructor();
338 virtual ~Vehicle();
339
340 void BeginLoading();
341 void CancelReservation(StationID next, Station *st);
342 void LeaveStation();
343
344 GroundVehicleCache *GetGroundVehicleCache();
345 const GroundVehicleCache *GetGroundVehicleCache() const;
346
347 uint16_t &GetGroundVehicleFlags();
348 const uint16_t &GetGroundVehicleFlags() const;
349
350 void DeleteUnreachedImplicitOrders();
351
352 void HandleLoading(bool mode = false);
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) ? TILE_AXIAL_DISTANCE : TILE_CORNER_DISTANCE * 2;
415 }
416
421 virtual ExpensesType GetExpenseType([[maybe_unused]] bool income) const { return EXPENSES_OTHER; }
422
427 virtual void PlayLeaveStationSound([[maybe_unused]] bool force = false) const {}
428
432 virtual bool IsPrimaryVehicle() const { return false; }
433
434 const Engine *GetEngine() const;
435
441 virtual void GetImage([[maybe_unused]] Direction direction, [[maybe_unused]] EngineImageType image_type, [[maybe_unused]] VehicleSpriteSeq *result) const { result->Clear(); }
442
443 const GRFFile *GetGRF() const;
444 uint32_t GetGRFID() const;
445
450 inline void InvalidateNewGRFCache()
451 {
452 this->grf_cache.cache_valid = 0;
453 }
454
459 inline void InvalidateNewGRFCacheOfChain()
460 {
461 for (Vehicle *u = this; u != nullptr; u = u->Next()) {
462 u->InvalidateNewGRFCache();
463 }
464 }
465
470 [[debug_inline]] inline bool IsGroundVehicle() const
471 {
472 return this->type == VEH_TRAIN || this->type == VEH_ROAD;
473 }
474
479 virtual int GetDisplaySpeed() const { return 0; }
480
485 virtual int GetDisplayMaxSpeed() const { return 0; }
486
491 virtual int GetCurrentMaxSpeed() const { return 0; }
492
497 virtual Money GetRunningCost() const { return 0; }
498
503 virtual bool IsInDepot() const { return false; }
504
509 virtual bool IsChainInDepot() const { return this->IsInDepot(); }
510
515 bool IsStoppedInDepot() const
516 {
517 assert(this == this->First());
518 /* Free wagons have no VehState::Stopped state */
519 if (this->IsPrimaryVehicle() && !this->vehstatus.Test(VehState::Stopped)) return false;
520 return this->IsChainInDepot();
521 }
522
527 virtual bool Tick() { return true; };
528
532 virtual void OnNewCalendarDay() {};
533
537 virtual void OnNewEconomyDay() {};
538
539 void ShiftDates(TimerGameEconomy::Date interval);
540
546 virtual uint Crash(bool flooded = false);
547
560 virtual Trackdir GetVehicleTrackdir() const { return INVALID_TRACKDIR; }
561
566 Money GetDisplayRunningCost() const { return (this->GetRunningCost() >> 8); }
567
572 Money GetDisplayProfitThisYear() const { return (this->profit_this_year >> 8); }
573
578 Money GetDisplayProfitLastYear() const { return (this->profit_last_year >> 8); }
579
580 void SetNext(Vehicle *next);
581
587 inline Vehicle *Next() const { return this->next; }
588
594 inline Vehicle *Previous() const { return this->previous; }
595
600 inline Vehicle *First() const { return this->first; }
601
606 inline Vehicle *Last()
607 {
608 Vehicle *v = this;
609 while (v->Next() != nullptr) v = v->Next();
610 return v;
611 }
612
617 inline const Vehicle *Last() const
618 {
619 const Vehicle *v = this;
620 while (v->Next() != nullptr) v = v->Next();
621 return v;
622 }
623
629 inline Vehicle *Move(int n)
630 {
631 Vehicle *v = this;
632 if (n < 0) {
633 for (int i = 0; i != n && v != nullptr; i--) v = v->Previous();
634 } else {
635 for (int i = 0; i != n && v != nullptr; i++) v = v->Next();
636 }
637 return v;
638 }
639
645 inline const Vehicle *Move(int n) const
646 {
647 const Vehicle *v = this;
648 if (n < 0) {
649 for (int i = 0; i != n && v != nullptr; i--) v = v->Previous();
650 } else {
651 for (int i = 0; i != n && v != nullptr; i++) v = v->Next();
652 }
653 return v;
654 }
655
660 inline const Order *GetFirstOrder() const { return (this->orders == nullptr) ? nullptr : this->GetOrder(this->orders->GetFirstOrder()); }
661
662 inline std::span<const Order> Orders() const
663 {
664 if (this->orders == nullptr) return {};
665 return this->orders->GetOrders();
666 }
667
668 inline std::span<Order> Orders()
669 {
670 if (this->orders == nullptr) return {};
671 return this->orders->GetOrders();
672 }
673
674 void AddToShared(Vehicle *shared_chain);
675 void RemoveFromShared();
676
681 inline Vehicle *NextShared() const { return this->next_shared; }
682
687 inline Vehicle *PreviousShared() const { return this->previous_shared; }
688
693 inline Vehicle *FirstShared() const { return (this->orders == nullptr) ? this->First() : this->orders->GetFirstSharedVehicle(); }
694
699 inline bool IsOrderListShared() const { return this->orders != nullptr && this->orders->IsShared(); }
700
705 inline VehicleOrderID GetNumOrders() const { return (this->orders == nullptr) ? 0 : this->orders->GetNumOrders(); }
706
711 inline VehicleOrderID GetNumManualOrders() const { return (this->orders == nullptr) ? 0 : this->orders->GetNumManualOrders(); }
712
717 inline void GetNextStoppingStation(std::vector<StationID> &next_station) const
718 {
719 if (this->orders == nullptr) return;
720 this->orders->GetNextStoppingStation(next_station, this);
721 }
722
723 void ResetRefitCaps();
724
725 void ReleaseUnitNumber();
726
733 inline void CopyVehicleConfigAndStatistics(Vehicle *src)
734 {
735 this->CopyConsistPropertiesFrom(src);
736
737 this->ReleaseUnitNumber();
738 this->unitnumber = src->unitnumber;
739
740 this->current_order = src->current_order;
741 this->dest_tile = src->dest_tile;
742
743 this->profit_this_year = src->profit_this_year;
744 this->profit_last_year = src->profit_last_year;
745
746 src->unitnumber = 0;
747 }
748
749
750 bool HandleBreakdown();
751
752 bool NeedsAutorenewing(const Company *c, bool use_renew_setting = true) const;
753
754 bool NeedsServicing() const;
755 bool NeedsAutomaticServicing() const;
756
764 virtual TileIndex GetOrderStationLocation([[maybe_unused]] StationID station) { return INVALID_TILE; }
765
766 virtual TileIndex GetCargoTile() const { return this->tile; }
767
773 virtual ClosestDepot FindClosestDepot() { return {}; }
774
775 virtual void SetDestTile(TileIndex tile) { this->dest_tile = tile; }
776
777 CommandCost SendToDepot(DoCommandFlags flags, DepotCommandFlags command);
778
779 void UpdateVisualEffect(bool allow_power_change = true);
780 void ShowVisualEffect() const;
781
782 void UpdatePosition();
783 void UpdateViewport(bool dirty);
784 void UpdateBoundingBoxCoordinates(bool update_cache) const;
785 void UpdatePositionAndViewport();
786 bool MarkAllViewportsDirty() const;
787
788 inline uint16_t GetServiceInterval() const { return this->service_interval; }
789
790 inline void SetServiceInterval(uint16_t interval) { this->service_interval = interval; }
791
792 inline bool ServiceIntervalIsCustom() const { return this->vehicle_flags.Test(VehicleFlag::ServiceIntervalIsCustom); }
793
794 inline bool ServiceIntervalIsPercent() const { return this->vehicle_flags.Test(VehicleFlag::ServiceIntervalIsPercent); }
795
796 inline void SetServiceIntervalIsCustom(bool on) { this->vehicle_flags.Set(VehicleFlag::ServiceIntervalIsCustom, on); }
797
798 inline void SetServiceIntervalIsPercent(bool on) { this->vehicle_flags.Set(VehicleFlag::ServiceIntervalIsPercent, on); }
799
800 bool HasFullLoadOrder() const;
801 bool HasConditionalOrder() const;
802 bool HasUnbunchingOrder() const;
803 void LeaveUnbunchingDepot();
804 bool IsWaitingForUnbunching() const;
805
806private:
811 void SkipToNextRealOrderIndex()
812 {
813 if (this->GetNumManualOrders() > 0) {
814 /* Advance to next real order */
815 do {
816 this->cur_real_order_index++;
817 if (this->cur_real_order_index >= this->GetNumOrders()) this->cur_real_order_index = 0;
818 } while (this->GetOrder(this->cur_real_order_index)->IsType(OT_IMPLICIT));
819 } else {
820 this->cur_real_order_index = 0;
821 }
822 }
823
824public:
830 void IncrementImplicitOrderIndex()
831 {
832 if (this->cur_implicit_order_index == this->cur_real_order_index) {
833 /* Increment real order index as well */
834 this->SkipToNextRealOrderIndex();
835 }
836
837 assert(this->cur_real_order_index == 0 || this->cur_real_order_index < this->GetNumOrders());
838
839 /* Advance to next implicit order */
840 do {
841 this->cur_implicit_order_index++;
842 if (this->cur_implicit_order_index >= this->GetNumOrders()) this->cur_implicit_order_index = 0;
843 } while (this->cur_implicit_order_index != this->cur_real_order_index && !this->GetOrder(this->cur_implicit_order_index)->IsType(OT_IMPLICIT));
844
845 InvalidateVehicleOrder(this, 0);
846 }
847
854 void IncrementRealOrderIndex()
855 {
856 if (this->cur_implicit_order_index == this->cur_real_order_index) {
857 /* Increment both real and implicit order */
858 this->IncrementImplicitOrderIndex();
859 } else {
860 /* Increment real order only */
861 this->SkipToNextRealOrderIndex();
862 InvalidateVehicleOrder(this, 0);
863 }
864 }
865
869 void UpdateRealOrderIndex()
870 {
871 /* Make sure the index is valid */
872 if (this->cur_real_order_index >= this->GetNumOrders()) this->cur_real_order_index = 0;
873
874 if (this->GetNumManualOrders() > 0) {
875 /* Advance to next real order */
876 while (this->GetOrder(this->cur_real_order_index)->IsType(OT_IMPLICIT)) {
877 this->cur_real_order_index++;
878 if (this->cur_real_order_index >= this->GetNumOrders()) this->cur_real_order_index = 0;
879 }
880 } else {
881 this->cur_real_order_index = 0;
882 }
883 }
884
890 inline Order *GetOrder(int index) const
891 {
892 return (this->orders == nullptr) ? nullptr : this->orders->GetOrderAt(index);
893 }
894
899 inline const Order *GetLastOrder() const
900 {
901 return (this->orders == nullptr) ? nullptr : this->orders->GetOrderAt(this->orders->GetLastOrder());
902 }
903
904 bool IsEngineCountable() const;
905 bool HasEngineType() const;
906 bool HasDepotOrder() const;
907 void HandlePathfindingResult(bool path_found);
908
913 [[debug_inline]] inline bool IsFrontEngine() const
914 {
915 return this->IsGroundVehicle() && HasBit(this->subtype, GVSF_FRONT);
916 }
917
922 inline bool IsArticulatedPart() const
923 {
924 return this->IsGroundVehicle() && HasBit(this->subtype, GVSF_ARTICULATED_PART);
925 }
926
931 inline bool HasArticulatedPart() const
932 {
933 return this->Next() != nullptr && this->Next()->IsArticulatedPart();
934 }
935
941 inline Vehicle *GetNextArticulatedPart() const
942 {
943 assert(this->HasArticulatedPart());
944 return this->Next();
945 }
946
951 inline Vehicle *GetFirstEnginePart()
952 {
953 Vehicle *v = this;
954 while (v->IsArticulatedPart()) v = v->Previous();
955 return v;
956 }
957
962 inline const Vehicle *GetFirstEnginePart() const
963 {
964 const Vehicle *v = this;
965 while (v->IsArticulatedPart()) v = v->Previous();
966 return v;
967 }
968
973 inline Vehicle *GetLastEnginePart()
974 {
975 Vehicle *v = this;
976 while (v->HasArticulatedPart()) v = v->GetNextArticulatedPart();
977 return v;
978 }
979
984 inline Vehicle *GetNextVehicle() const
985 {
986 const Vehicle *v = this;
987 while (v->HasArticulatedPart()) v = v->GetNextArticulatedPart();
988
989 /* v now contains the last articulated part in the engine */
990 return v->Next();
991 }
992
997 inline Vehicle *GetPrevVehicle() const
998 {
999 Vehicle *v = this->Previous();
1000 while (v != nullptr && v->IsArticulatedPart()) v = v->Previous();
1001
1002 return v;
1003 }
1004
1005 uint32_t GetDisplayMaxWeight() const;
1006 uint32_t GetDisplayMinPowerToWeight() const;
1007};
1008
1013template <class T, VehicleType Type>
1014 struct SpecializedVehicle : public Vehicle {
1015 static const VehicleType EXPECTED_TYPE = Type;
1016
1017 typedef SpecializedVehicle<T, Type> SpecializedVehicleBase;
1018
1022 inline SpecializedVehicle() : Vehicle(Type)
1023 {
1024 this->sprite_cache.sprite_seq.count = 1;
1025 }
1026
1031 inline T *First() const { return (T *)this->Vehicle::First(); }
1032
1037 inline T *Last() { return (T *)this->Vehicle::Last(); }
1038
1043 inline const T *Last() const { return (const T *)this->Vehicle::Last(); }
1044
1049 inline T *Next() const { return (T *)this->Vehicle::Next(); }
1050
1055 inline T *Previous() const { return (T *)this->Vehicle::Previous(); }
1056
1062 inline T *GetNextArticulatedPart() { return (T *)this->Vehicle::GetNextArticulatedPart(); }
1063
1069 inline T *GetNextArticulatedPart() const { return (T *)this->Vehicle::GetNextArticulatedPart(); }
1070
1075 inline T *GetFirstEnginePart() { return (T *)this->Vehicle::GetFirstEnginePart(); }
1076
1081 inline const T *GetFirstEnginePart() const { return (const T *)this->Vehicle::GetFirstEnginePart(); }
1082
1087 inline T *GetLastEnginePart() { return (T *)this->Vehicle::GetLastEnginePart(); }
1088
1093 inline T *GetNextVehicle() const { return (T *)this->Vehicle::GetNextVehicle(); }
1094
1099 inline T *GetPrevVehicle() const { return (T *)this->Vehicle::GetPrevVehicle(); }
1100
1106 static inline bool IsValidID(auto index)
1107 {
1108 return Vehicle::IsValidID(index) && Vehicle::Get(index)->type == Type;
1109 }
1110
1115 static inline T *Get(auto index)
1116 {
1117 return (T *)Vehicle::Get(index);
1118 }
1119
1124 static inline T *GetIfValid(auto index)
1125 {
1126 return IsValidID(index) ? Get(index) : nullptr;
1127 }
1128
1134 static inline T *From(Vehicle *v)
1135 {
1136 assert(v->type == Type);
1137 return (T *)v;
1138 }
1139
1145 static inline const T *From(const Vehicle *v)
1146 {
1147 assert(v->type == Type);
1148 return (const T *)v;
1149 }
1150
1156 inline void UpdateViewport(bool force_update, bool update_delta)
1157 {
1158 bool sprite_has_changed = false;
1159
1160 /* Skip updating sprites on dedicated servers without screen */
1161 if (_network_dedicated) return;
1162
1163 /* Explicitly choose method to call to prevent vtable dereference -
1164 * it gives ~3% runtime improvements in games with many vehicles */
1165 if (update_delta) ((T *)this)->T::UpdateDeltaXY();
1166
1167 /*
1168 * Only check for a new sprite sequence if the vehicle direction
1169 * has changed since we last checked it, assuming that otherwise
1170 * there won't be enough change in bounding box or offsets to need
1171 * to resolve a new sprite.
1172 */
1173 if (this->direction != this->sprite_cache.last_direction || this->sprite_cache.is_viewport_candidate) {
1174 VehicleSpriteSeq seq;
1175
1176 ((T*)this)->T::GetImage(this->direction, EIT_ON_MAP, &seq);
1177 if (this->sprite_cache.sprite_seq != seq) {
1178 sprite_has_changed = true;
1179 this->sprite_cache.sprite_seq = seq;
1180 }
1181
1182 this->sprite_cache.last_direction = this->direction;
1183 this->sprite_cache.revalidate_before_draw = false;
1184 } else {
1185 /*
1186 * A change that could potentially invalidate the sprite has been
1187 * made, signal that we should still resolve it before drawing on a
1188 * viewport.
1189 */
1190 this->sprite_cache.revalidate_before_draw = true;
1191 }
1192
1193 if (force_update || sprite_has_changed) {
1194 this->Vehicle::UpdateViewport(true);
1195 }
1196 }
1197
1203 static Pool::IterateWrapper<T> Iterate(size_t from = 0) { return Pool::IterateWrapper<T>(from); }
1204};
1205
1207 static const int32_t INVALID_COORD = 0x7fffffff;
1208
1209#endif /* VEHICLE_BASE_H */
base_consist.h
Properties for front vehicles/consists.
VehicleFlag::ServiceIntervalIsCustom
@ ServiceIntervalIsCustom
Service interval is custom.
VehicleFlag::ServiceIntervalIsPercent
@ ServiceIntervalIsPercent
Service interval is percent.
HasBit
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition bitmath_func.hpp:103
CargoType
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:21
cargopacket.h
Base class for cargo packets.
BaseBitSet::Test
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Definition base_bitset_type.hpp:141
BaseBitSet::Set
constexpr Timpl & Set()
Set all bits.
Definition base_bitset_type.hpp:40
CommandCost
Common return value for all commands.
Definition command_type.h:24
Engine
Definition engine_base.h:38
EnumBitSet< VehState, uint8_t >
OverflowSafeInt< int64_t >
SlVehicleCommon
Definition vehicle_sl.cpp:645
SlVehicleDisaster
Definition vehicle_sl.cpp:1037
TimerGameTick::TickCounter
uint64_t TickCounter
The type that the tick counter is stored in.
Definition timer_game_tick.h:25
VehicleCargoList
CargoList that is used for vehicles.
Definition cargopacket.h:342
command_type.h
Types related to commands.
INVALID_OWNER
static constexpr Owner INVALID_OWNER
An invalid owner.
Definition company_type.h:30
Direction
Direction
Defines the 8 directions on the map.
Definition direction_type.h:24
INVALID_DIR
@ INVALID_DIR
Flag for an invalid direction.
Definition direction_type.h:35
ExpensesType
ExpensesType
Types of expenses.
Definition economy_type.h:178
EXPENSES_OTHER
@ EXPENSES_OTHER
Other expenses.
Definition economy_type.h:191
engine_type.h
Types related to engines.
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
PaletteID
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
Vehicle::MarkDirty
virtual void MarkDirty()
Marks the vehicles to be redrawn and updates cached variables.
Definition vehicle_base.h:362
group_type.h
Types of a group.
_network_dedicated
bool _network_dedicated
are we a dedicated server?
Definition network.cpp:70
network.h
Basic functions/variables used all over the place.
order_base.h
Base class for orders.
InvalidateVehicleOrder
void InvalidateVehicleOrder(const Vehicle *v, int data)
Updates the widgets of a vehicle which contains the order-data.
Definition order_cmd.cpp:213
order_func.h
Functions related to orders.
VehicleOrderID
uint8_t VehicleOrderID
The index of an order within its current vehicle (not pool related)
Definition order_type.h:18
saveload.h
Functions/types related to saving and loading games.
sprite.h
Base for drawing complex sprites.
BaseConsist
Various front vehicle properties that are preserved when autoreplacing, using order-backup or switchi...
Definition base_consist.h:33
BaseConsist::cur_real_order_index
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
Definition base_consist.h:47
BaseConsist::vehicle_flags
VehicleFlags vehicle_flags
Used for gradual loading and other miscellaneous things (.
Definition base_consist.h:50
BaseConsist::cur_implicit_order_index
VehicleOrderID cur_implicit_order_index
The index to the current implicit order.
Definition base_consist.h:48
BaseConsist::service_interval
uint16_t service_interval
The interval for (automatic) servicing; either in days or %.
Definition base_consist.h:45
BaseConsist::CopyConsistPropertiesFrom
void CopyConsistPropertiesFrom(const BaseConsist *src)
Copy properties of other BaseConsist.
Definition base_consist.cpp:22
BaseVehicle
Base vehicle class.
Definition vehicle_type.h:50
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition vehicle_type.h:51
CargoPayment
Helper class to perform the cargo payment.
Definition economy_base.h:23
ClosestDepot
Structure to return information about the closest depot location, and whether it could be found.
Definition vehicle_base.h:192
ClosestDepot::destination
DestinationID destination
The DestinationID as used for orders.
Definition vehicle_base.h:194
Company
Definition company_base.h:127
DestinationID
Definition order_type.h:21
GRFFile
Dynamic data of a loaded NewGRF.
Definition newgrf.h:114
GroundVehicleCache
Cached, frequently calculated values.
Definition ground_vehicle.hpp:30
LoadgameState
Definition oldloader.h:19
MutableSpriteCache
Cache for vehicle sprites and values relating to whether they should be updated before drawing,...
Definition vehicle_base.h:157
MutableSpriteCache::revalidate_before_draw
bool revalidate_before_draw
We need to do a GetImage() and check bounds before drawing this sprite.
Definition vehicle_base.h:159
MutableSpriteCache::sprite_seq
VehicleSpriteSeq sprite_seq
Vehicle appearance.
Definition vehicle_base.h:162
MutableSpriteCache::is_viewport_candidate
bool is_viewport_candidate
This vehicle can potentially be drawn on a viewport.
Definition vehicle_base.h:160
MutableSpriteCache::last_direction
Direction last_direction
Last direction we obtained sprites for.
Definition vehicle_base.h:158
MutableSpriteCache::old_coord
Rect old_coord
Co-ordinates from the last valid bounding box.
Definition vehicle_base.h:161
NewGRFCache
Cached often queried (NewGRF) values.
Definition vehicle_base.h:55
NewGRFCache::position_in_vehicle
uint32_t position_in_vehicle
Cache for NewGRF var 4D.
Definition vehicle_base.h:61
NewGRFCache::position_consist_length
uint32_t position_consist_length
Cache for NewGRF var 40.
Definition vehicle_base.h:57
NewGRFCache::consist_cargo_information
uint32_t consist_cargo_information
Cache for NewGRF var 42. (Note: The cargotype is untranslated in the cache because the accessing GRF ...
Definition vehicle_base.h:59
NewGRFCache::cache_valid
uint8_t cache_valid
Bitset that indicates which cache values are valid.
Definition vehicle_base.h:62
NewGRFCache::company_information
uint32_t company_information
Cache for NewGRF var 43.
Definition vehicle_base.h:60
NewGRFCache::position_same_id_length
uint32_t position_same_id_length
Cache for NewGRF var 41.
Definition vehicle_base.h:58
OrderList
Shared order list linking together the linked list of orders and the list of vehicles sharing this or...
Definition order_base.h:274
OrderList::GetFirstSharedVehicle
Vehicle * GetFirstSharedVehicle() const
Get the first vehicle of this vehicle chain.
Definition order_base.h:397
OrderList::GetFirstOrder
VehicleOrderID GetFirstOrder() const
Get the first order of the order chain.
Definition order_base.h:328
OrderList::GetNextStoppingStation
void GetNextStoppingStation(std::vector< StationID > &next_station, const Vehicle *v, VehicleOrderID first=INVALID_VEH_ORDER_ID, uint hops=0) const
Recursively determine the next deterministic station to stop at.
Definition order_cmd.cpp:363
OrderList::GetNumOrders
VehicleOrderID GetNumOrders() const
Get number of orders in the order list.
Definition order_base.h:372
OrderList::GetNumManualOrders
VehicleOrderID GetNumManualOrders() const
Get number of manually added orders in the order list.
Definition order_base.h:378
OrderList::IsShared
bool IsShared() const
Is this a shared order list?
Definition order_base.h:391
OrderList::GetLastOrder
VehicleOrderID GetLastOrder() const
Get the last order of the order chain.
Definition order_base.h:354
OrderList::GetOrderAt
const Order * GetOrderAt(VehicleOrderID index) const
Get a certain order of the order chain.
Definition order_base.h:338
Order
Definition order_base.h:33
PoolID< uint8_t, struct CompanyIDTag, 0xF, 0xFF >
Pool::IterateWrapper
Definition pool_type.hpp:227
Pool::PoolItem
Base class for all PoolItems.
Definition pool_type.hpp:285
Pool::PoolItem<&_vehicle_pool >::Get
static Titem * Get(auto index)
Returns Titem with given index.
Definition pool_type.hpp:387
Pool::PoolItem<&_vehicle_pool >::index
Tindex index
Index of this pool item.
Definition pool_type.hpp:286
Pool::PoolItem<&_vehicle_pool >::IsValidID
static bool IsValidID(auto index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition pool_type.hpp:376
Pool
Base class for all pools.
Definition pool_type.hpp:133
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition geometry_type.hpp:101
RefitDesc
Simulated cargo type and capacity for prediction of future links.
Definition vehicle_base.h:180
RefitDesc::cargo
CargoType cargo
Cargo type the vehicle will be carrying.
Definition vehicle_base.h:181
RefitDesc::capacity
uint16_t capacity
Capacity the vehicle will have.
Definition vehicle_base.h:182
RefitDesc::remaining
uint16_t remaining
Capacity remaining from before the previous refit.
Definition vehicle_base.h:183
SpecializedVehicle
Class defining several overloaded accessors so we don't have to cast vehicle types that often.
Definition vehicle_base.h:1014
SpecializedVehicle::Next
T * Next() const
Get next vehicle in the chain.
Definition vehicle_base.h:1049
SpecializedVehicle::Iterate
static Pool::IterateWrapper< T > Iterate(size_t from=0)
Returns an iterable ensemble of all valid vehicles of type T.
Definition vehicle_base.h:1203
SpecializedVehicle::Previous
T * Previous() const
Get previous vehicle in the chain.
Definition vehicle_base.h:1055
SpecializedVehicle::From
static const T * From(const Vehicle *v)
Converts a const Vehicle to const SpecializedVehicle with type checking.
Definition vehicle_base.h:1145
SpecializedVehicle::From
static T * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition vehicle_base.h:1134
SpecializedVehicle::GetNextArticulatedPart
T * GetNextArticulatedPart()
Get the next part of an articulated engine.
Definition vehicle_base.h:1062
SpecializedVehicle::IsValidID
static bool IsValidID(auto index)
Tests whether given index is a valid index for vehicle of this type.
Definition vehicle_base.h:1106
SpecializedVehicle::GetIfValid
static T * GetIfValid(auto index)
Returns vehicle if the index is a valid index for this vehicle type.
Definition vehicle_base.h:1124
SpecializedVehicle::GetFirstEnginePart
const T * GetFirstEnginePart() const
Get the first part of an articulated engine.
Definition vehicle_base.h:1081
SpecializedVehicle::First
T * First() const
Get the first vehicle in the chain.
Definition vehicle_base.h:1031
SpecializedVehicle::GetPrevVehicle
T * GetPrevVehicle() const
Get the previous real (non-articulated part) vehicle in the consist.
Definition vehicle_base.h:1099
SpecializedVehicle::GetNextVehicle
T * GetNextVehicle() const
Get the next real (non-articulated part) vehicle in the consist.
Definition vehicle_base.h:1093
SpecializedVehicle::GetNextArticulatedPart
T * GetNextArticulatedPart() const
Get the next part of an articulated engine.
Definition vehicle_base.h:1069
SpecializedVehicle::Get
static T * Get(auto index)
Gets vehicle with given index.
Definition vehicle_base.h:1115
SpecializedVehicle::SpecializedVehicle
SpecializedVehicle()
Set vehicle type correctly.
Definition vehicle_base.h:1022
SpecializedVehicle::UpdateViewport
void UpdateViewport(bool force_update, bool update_delta)
Update vehicle sprite- and position caches.
Definition vehicle_base.h:1156
SpecializedVehicle::GetLastEnginePart
T * GetLastEnginePart()
Get the last part of an articulated engine.
Definition vehicle_base.h:1087
SpecializedVehicle::GetFirstEnginePart
T * GetFirstEnginePart()
Get the first part of an articulated engine.
Definition vehicle_base.h:1075
SpecializedVehicle::SpecializedVehicleBase
SpecializedVehicle< T, Type > SpecializedVehicleBase
Our type.
Definition vehicle_base.h:1017
SpecializedVehicle::Last
T * Last()
Get the last vehicle in the chain.
Definition vehicle_base.h:1037
SpecializedVehicle::EXPECTED_TYPE
static const VehicleType EXPECTED_TYPE
Specialized type.
Definition vehicle_base.h:1015
SpecializedVehicle::Last
const T * Last() const
Get the last vehicle in the chain.
Definition vehicle_base.h:1043
SpriteBounds
Definition sprite.h:18
Station
Station data structure.
Definition station_base.h:520
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
VehicleCache
Cached often queried values common to all vehicles.
Definition vehicle_base.h:92
VehicleCache::cached_vis_effect
uint8_t cached_vis_effect
Visual effect to show (see VisualEffect)
Definition vehicle_base.h:96
VehicleCache::cached_cargo_age_period
uint16_t cached_cargo_age_period
Number of ticks before carried cargo is aged.
Definition vehicle_base.h:94
VehicleCache::cached_max_speed
uint16_t cached_max_speed
Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
Definition vehicle_base.h:93
VehicleSpriteSeq
Sprite sequence for a vehicle part.
Definition vehicle_base.h:102
VehicleSpriteSeq::IsValid
bool IsValid() const
Check whether the sequence contains any sprites.
Definition vehicle_base.h:114
VehicleSpriteSeq::GetBounds
void GetBounds(Rect *bounds) const
Determine shared bounds of all sprites.
Definition vehicle.cpp:114
VehicleSpriteSeq::Set
void Set(SpriteID sprite)
Assign a single sprite to the sequence.
Definition vehicle_base.h:130
VehicleSpriteSeq::Clear
void Clear()
Clear all information.
Definition vehicle_base.h:122
VehicleSpriteSeq::CopyWithoutPalette
void CopyWithoutPalette(const VehicleSpriteSeq &src)
Copy data from another sprite sequence, while dropping all recolouring information.
Definition vehicle_base.h:140
VehicleSpriteSeq::Draw
void Draw(int x, int y, PaletteID default_pal, bool force_pal) const
Draw the sprite sequence.
Definition vehicle.cpp:142
Vehicle
Vehicle data structure.
Definition vehicle_base.h:205
Vehicle::GetDisplayProfitThisYear
Money GetDisplayProfitThisYear() const
Gets the profit vehicle had this year.
Definition vehicle_base.h:572
Vehicle::cargo_payment
CargoPayment * cargo_payment
The cargo payment we're currently in.
Definition vehicle_base.h:238
Vehicle::engine_type
EngineID engine_type
The type of engine used for this vehicle.
Definition vehicle_base.h:278
Vehicle::cargo_age_counter
uint16_t cargo_age_counter
Ticks till cargo is aged next.
Definition vehicle_base.h:301
Vehicle::GetDisplaySpeed
virtual int GetDisplaySpeed() const
Gets the speed in km-ish/h that can be sent into string parameters for string processing.
Definition vehicle_base.h:479
Vehicle::GetAdvanceSpeed
static uint GetAdvanceSpeed(uint speed)
Determines the effective vehicle movement speed.
Definition vehicle_base.h:400
Vehicle::z_pos
int32_t z_pos
z coordinate.
Definition vehicle_base.h:267
Vehicle::GetGroundVehicleFlags
uint16_t & GetGroundVehicleFlags()
Access the ground vehicle flags of the vehicle.
Definition vehicle.cpp:3173
Vehicle::direction
Direction direction
facing
Definition vehicle_base.h:268
Vehicle::ShiftDates
void ShiftDates(TimerGameEconomy::Date interval)
Shift all dates by given interval.
Definition vehicle.cpp:748
Vehicle::GetLastOrder
const Order * GetLastOrder() const
Returns the last order of a vehicle, or nullptr if it doesn't exists.
Definition vehicle_base.h:899
Vehicle::AfterLoadVehiclesPhase1
friend void AfterLoadVehiclesPhase1(bool part_of_load)
So we can set the previous and first pointers while loading.
Definition vehicle_sl.cpp:256
Vehicle::economy_age
TimerGameEconomy::Date economy_age
Age in economy days.
Definition vehicle_base.h:254
Vehicle::IsOrderListShared
bool IsOrderListShared() const
Check if we share our orders with another vehicle.
Definition vehicle_base.h:699
Vehicle::GetEngine
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
Definition vehicle.cpp:718
Vehicle::IncrementRealOrderIndex
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:854
Vehicle::Crash
virtual uint Crash(bool flooded=false)
Crash the (whole) vehicle chain.
Definition vehicle.cpp:291
Vehicle::IsStoppedInDepot
bool IsStoppedInDepot() const
Check whether the vehicle is in the depot and stopped.
Definition vehicle_base.h:515
Vehicle::GetExpenseType
virtual ExpensesType GetExpenseType(bool income) const
Sets the expense type associated to this vehicle type.
Definition vehicle_base.h:421
Vehicle::GetNextArticulatedPart
Vehicle * GetNextArticulatedPart() const
Get the next part of an articulated engine.
Definition vehicle_base.h:941
Vehicle::GetOrder
Order * GetOrder(int index) const
Returns order 'index' of a vehicle or nullptr when it doesn't exists.
Definition vehicle_base.h:890
Vehicle::HasDepotOrder
bool HasDepotOrder() const
Checks if a vehicle has a depot in its order list.
Definition order_cmd.cpp:1819
Vehicle::FixOldVehicles
friend void FixOldVehicles(LoadgameState &ls)
Convert the old style vehicles into something that resembles the old new style savegames.
Definition oldloader_sl.cpp:160
Vehicle::LeaveStation
void LeaveStation()
Perform all actions when leaving a station.
Definition vehicle.cpp:2327
Vehicle::IsChainInDepot
virtual bool IsChainInDepot() const
Check whether the whole vehicle chain is in the depot.
Definition vehicle_base.h:509
Vehicle::AddToShared
void AddToShared(Vehicle *shared_chain)
Adds this vehicle to a shared vehicle chain.
Definition vehicle.cpp:2956
Vehicle::cargo
VehicleCargoList cargo
The cargo this vehicle is carrying.
Definition vehicle_base.h:296
Vehicle::hash_tile_prev
Vehicle ** hash_tile_prev
NOSAVE: Previous vehicle in the tile location hash.
Definition vehicle_base.h:246
Vehicle::HasUnbunchingOrder
bool HasUnbunchingOrder() const
Check if the current vehicle has an unbunching order.
Definition vehicle.cpp:2462
Vehicle::date_of_last_service
TimerGameEconomy::Date date_of_last_service
Last economy date the vehicle had a service at a depot.
Definition vehicle_base.h:256
Vehicle::cargo_cap
uint16_t cargo_cap
total capacity
Definition vehicle_base.h:299
Vehicle::last_loading_station
StationID last_loading_station
Last station the vehicle has stopped at and could possibly leave from with any cargo loaded.
Definition vehicle_base.h:293
Vehicle::GetNumOrders
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
Definition vehicle_base.h:705
Vehicle::GetFirstEnginePart
Vehicle * GetFirstEnginePart()
Get the first part of an articulated engine.
Definition vehicle_base.h:951
Vehicle::subtype
uint8_t subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
Definition vehicle_base.h:310
Vehicle::GetFirstOrder
const Order * GetFirstOrder() const
Get the first order of the vehicles order list.
Definition vehicle_base.h:660
Vehicle::SendToDepot
CommandCost SendToDepot(DoCommandFlags flags, DepotCommandFlags command)
Send this vehicle to the depot using the given command(s).
Definition vehicle.cpp:2555
Vehicle::LoadOldVehicle
friend bool LoadOldVehicle(LoadgameState &ls, int num)
So we can set the proper next pointer while loading.
Definition oldloader_sl.cpp:1258
Vehicle::UpdateDeltaXY
virtual void UpdateDeltaXY()
Updates the x and y offsets and the size of the sprite used for this vehicle.
Definition vehicle_base.h:368
Vehicle::Last
Vehicle * Last()
Get the last vehicle of this vehicle chain.
Definition vehicle_base.h:606
Vehicle::random_bits
uint16_t random_bits
Bits used for randomized variational spritegroups.
Definition vehicle_base.h:290
Vehicle::ReleaseUnitNumber
void ReleaseUnitNumber()
Release the vehicle's unit number.
Definition vehicle.cpp:2396
Vehicle::UpdateBoundingBoxCoordinates
void UpdateBoundingBoxCoordinates(bool update_cache) const
Update the bounding box co-ordinates of the vehicle.
Definition vehicle.cpp:1671
Vehicle::day_counter
uint8_t day_counter
Increased by one for each day.
Definition vehicle_base.h:304
Vehicle::HandleLoading
void HandleLoading(bool mode=false)
Handle the loading of the vehicle; when not it skips through dummy orders and does nothing in all oth...
Definition vehicle.cpp:2407
Vehicle::profit_this_year
Money profit_this_year
Profit this year << 8, low 8 bits are fract.
Definition vehicle_base.h:234
Vehicle::HasArticulatedPart
bool HasArticulatedPart() const
Check if an engine has an articulated part.
Definition vehicle_base.h:931
Vehicle::colourmap
SpriteID colourmap
NOSAVE: cached colour mapping.
Definition vehicle_base.h:249
Vehicle::breakdown_ctr
uint8_t breakdown_ctr
Counter for managing breakdown events.
Definition vehicle_base.h:260
Vehicle::GetOldAdvanceSpeed
uint GetOldAdvanceSpeed(uint speed)
Determines the effective direction-specific vehicle movement speed.
Definition vehicle_base.h:383
Vehicle::breakdown_delay
uint8_t breakdown_delay
Counter for managing breakdown length.
Definition vehicle_base.h:261
Vehicle::GetNextVehicle
Vehicle * GetNextVehicle() const
Get the next real (non-articulated part) vehicle in the consist.
Definition vehicle_base.h:984
Vehicle::GetAdvanceDistance
uint GetAdvanceDistance()
Determines the vehicle "progress" needed for moving a step.
Definition vehicle_base.h:412
Vehicle::group_id
GroupID group_id
Index of group Pool array.
Definition vehicle_base.h:321
Vehicle::Move
const Vehicle * Move(int n) const
Get the vehicle at offset n of this vehicle chain.
Definition vehicle_base.h:645
Vehicle::GetDisplayMaxSpeed
virtual int GetDisplayMaxSpeed() const
Gets the maximum speed in km-ish/h that can be sent into string parameters for string processing.
Definition vehicle_base.h:485
Vehicle::IncrementImplicitOrderIndex
void IncrementImplicitOrderIndex()
Increments cur_implicit_order_index, keeps care of the wrap-around and invalidates the GUI.
Definition vehicle_base.h:830
Vehicle::IsGroundVehicle
bool IsGroundVehicle() const
Check if the vehicle is a ground vehicle.
Definition vehicle_base.h:470
Vehicle::vehstatus
VehStates vehstatus
Status.
Definition vehicle_base.h:309
Vehicle::date_of_last_service_newgrf
TimerGameCalendar::Date date_of_last_service_newgrf
Last calendar date the vehicle had a service at a depot, unchanged by the date cheat to protect again...
Definition vehicle_base.h:257
Vehicle::first
Vehicle * first
NOSAVE: pointer to the first vehicle in the chain.
Definition vehicle_base.h:211
Vehicle::CancelReservation
void CancelReservation(StationID next, Station *st)
Return all reserved cargo packets to the station and reset all packets staged for transfer.
Definition vehicle.cpp:2311
Vehicle::profit_last_year
Money profit_last_year
Profit last year << 8, low 8 bits are fract.
Definition vehicle_base.h:235
Vehicle::IsEngineCountable
bool IsEngineCountable() const
Check if a vehicle is counted in num_engines in each company struct.
Definition vehicle.cpp:685
Vehicle::~Vehicle
virtual ~Vehicle()
We want to 'destruct' the right class.
Definition vehicle.cpp:863
Vehicle::subspeed
uint8_t subspeed
fractional speed
Definition vehicle_base.h:284
Vehicle::IsArticulatedPart
bool IsArticulatedPart() const
Check if the vehicle is an articulated part of an engine.
Definition vehicle_base.h:922
Vehicle::NeedsAutorenewing
bool NeedsAutorenewing(const Company *c, bool use_renew_setting=true) const
Function to tell if a vehicle needs to be autorenewed.
Definition vehicle.cpp:156
Vehicle::UpdateVisualEffect
void UpdateVisualEffect(bool allow_power_change=true)
Update the cached visual effect.
Definition vehicle.cpp:2636
Vehicle::LeaveUnbunchingDepot
void LeaveUnbunchingDepot()
Leave an unbunching depot and calculate the next departure time for shared order vehicles.
Definition vehicle.cpp:2486
Vehicle::Move
Vehicle * Move(int n)
Get the vehicle at offset n of this vehicle chain.
Definition vehicle_base.h:629
Vehicle::GetNextStoppingStation
void GetNextStoppingStation(std::vector< StationID > &next_station) const
Get the next station the vehicle will stop at.
Definition vehicle_base.h:717
Vehicle::cargo_type
CargoType cargo_type
type of cargo this vehicle is carrying
Definition vehicle_base.h:297
Vehicle::acceleration
uint8_t acceleration
used by train & aircraft
Definition vehicle_base.h:285
Vehicle::previous_shared
Vehicle * previous_shared
NOSAVE: pointer to the previous vehicle in the shared order chain.
Definition vehicle_base.h:214
Vehicle::GetNumManualOrders
VehicleOrderID GetNumManualOrders() const
Get the number of manually added orders this vehicle has.
Definition vehicle_base.h:711
Vehicle::First
Vehicle * First() const
Get the first vehicle of this vehicle chain.
Definition vehicle_base.h:600
Vehicle::trip_occupancy
int8_t trip_occupancy
NOSAVE: Occupancy of vehicle of the current trip (updated after leaving a station).
Definition vehicle_base.h:302
Vehicle::GetOrderStationLocation
virtual TileIndex GetOrderStationLocation(StationID station)
Determine the location for the station where the vehicle goes to next.
Definition vehicle_base.h:764
Vehicle::current_order
Order current_order
The current order (+ status, like: loading)
Definition vehicle_base.h:311
Vehicle::PreDestructor
void PreDestructor()
Destroy all stuff that (still) needs the virtual functions to work properly.
Definition vehicle.cpp:796
Vehicle::last_loading_tick
TimerGameTick::TickCounter last_loading_tick
Last TimerGameTick::counter tick that the vehicle has stopped at a station and could possibly leave w...
Definition vehicle_base.h:294
Vehicle::HandlePathfindingResult
void HandlePathfindingResult(bool path_found)
Handle the pathfinding result, especially the lost status.
Definition vehicle.cpp:762
Vehicle::Next
Vehicle * Next() const
Get the next vehicle of this vehicle.
Definition vehicle_base.h:587
Vehicle::y_pos
int32_t y_pos
y coordinate.
Definition vehicle_base.h:266
Vehicle::x_pos
int32_t x_pos
x coordinate.
Definition vehicle_base.h:265
Vehicle::GetGRF
const GRFFile * GetGRF() const
Retrieve the NewGRF the vehicle is tied to.
Definition vehicle.cpp:728
Vehicle::orders
OrderList * orders
Pointer to the order list for this vehicle.
Definition vehicle_base.h:314
Vehicle::GetDisplayMinPowerToWeight
uint32_t GetDisplayMinPowerToWeight() const
Calculates the minimum power-to-weight ratio using the maximum weight of the ground vehicle.
Definition vehicle.cpp:3247
Vehicle::FindClosestDepot
virtual ClosestDepot FindClosestDepot()
Find the closest depot for this vehicle and tell us the location, DestinationID and whether we should...
Definition vehicle_base.h:773
Vehicle::UpdateViewport
void UpdateViewport(bool dirty)
Update the vehicle on the viewport, updating the right hash and setting the new coordinates.
Definition vehicle.cpp:1716
Vehicle::value
Money value
Value of the vehicle.
Definition vehicle_base.h:236
Vehicle::MarkAllViewportsDirty
bool MarkAllViewportsDirty() const
Marks viewports dirty where the vehicle's image is.
Definition vehicle.cpp:1755
Vehicle::refit_cap
uint16_t refit_cap
Capacity left over from before last refit.
Definition vehicle_base.h:300
Vehicle::InvalidateNewGRFCache
void InvalidateNewGRFCache()
Invalidates cached NewGRF variables.
Definition vehicle_base.h:450
Vehicle::waiting_random_triggers
VehicleRandomTriggers waiting_random_triggers
Triggers to be yet matched before rerandomizing the random bits.
Definition vehicle_base.h:289
Vehicle::vcache
VehicleCache vcache
Cache of often used vehicle values.
Definition vehicle_base.h:319
Vehicle::GetLastEnginePart
Vehicle * GetLastEnginePart()
Get the last part of an articulated engine.
Definition vehicle_base.h:973
Vehicle::motion_counter
uint32_t motion_counter
counter to occasionally play a vehicle sound.
Definition vehicle_base.h:286
Vehicle::grf_cache
NewGRFCache grf_cache
Cache of often used calculated NewGRF values.
Definition vehicle_base.h:318
Vehicle::GetGRFID
uint32_t GetGRFID() const
Retrieve the GRF ID of the NewGRF the vehicle is tied to.
Definition vehicle.cpp:738
Vehicle::bounds
SpriteBounds bounds
Bounding box of vehicle.
Definition vehicle_base.h:277
Vehicle::GetGroundVehicleCache
GroundVehicleCache * GetGroundVehicleCache()
Access the ground vehicle cache of the vehicle.
Definition vehicle.cpp:3143
Vehicle::OnNewEconomyDay
virtual void OnNewEconomyDay()
Calls the new economy day handler of the vehicle.
Definition vehicle_base.h:537
Vehicle::hash_tile_current
Vehicle ** hash_tile_current
NOSAVE: Cache of the current hash chain.
Definition vehicle_base.h:247
Vehicle::OnNewCalendarDay
virtual void OnNewCalendarDay()
Calls the new calendar day handler of the vehicle.
Definition vehicle_base.h:532
Vehicle::NextShared
Vehicle * NextShared() const
Get the next vehicle of the shared vehicle chain.
Definition vehicle_base.h:681
Vehicle::GetCurrentMaxSpeed
virtual int GetCurrentMaxSpeed() const
Calculates the maximum speed of the vehicle under its current conditions.
Definition vehicle_base.h:491
Vehicle::HasFullLoadOrder
bool HasFullLoadOrder() const
Check if the current vehicle has a full load order.
Definition vehicle.cpp:2442
Vehicle::IsPrimaryVehicle
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
Definition vehicle_base.h:432
Vehicle::BeginLoading
void BeginLoading()
Prepare everything to begin the loading when arriving at a station.
Definition vehicle.cpp:2183
Vehicle::old_orders
uint32_t old_orders
Only used during conversion of old save games.
Definition vehicle_base.h:315
Vehicle::load_unload_ticks
uint16_t load_unload_ticks
Ticks to wait before starting next cycle.
Definition vehicle_base.h:307
Vehicle::GetDisplayProfitLastYear
Money GetDisplayProfitLastYear() const
Gets the profit vehicle had last year.
Definition vehicle_base.h:578
Vehicle::hash_tile_next
Vehicle * hash_tile_next
NOSAVE: Next vehicle in the tile location hash.
Definition vehicle_base.h:245
Vehicle::spritenum
uint8_t spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
Definition vehicle_base.h:276
Vehicle::cur_speed
uint16_t cur_speed
current speed
Definition vehicle_base.h:283
Vehicle::previous
Vehicle * previous
NOSAVE: pointer to the previous vehicle in the chain.
Definition vehicle_base.h:210
Vehicle::cargo_subtype
uint8_t cargo_subtype
Used for livery refits (NewGRF variations)
Definition vehicle_base.h:298
Vehicle::IsFrontEngine
bool IsFrontEngine() const
Check if the vehicle is a front engine.
Definition vehicle_base.h:913
Vehicle::HasEngineType
bool HasEngineType() const
Check whether Vehicle::engine_type has any meaning.
Definition vehicle.cpp:702
Vehicle::age
TimerGameCalendar::Date age
Age in calendar days.
Definition vehicle_base.h:253
Vehicle::IsWaitingForUnbunching
bool IsWaitingForUnbunching() const
Check whether a vehicle inside a depot is waiting for unbunching.
Definition vehicle.cpp:2533
Vehicle::fill_percent_te_id
TextEffectID fill_percent_te_id
a text-effect id to a loading indicator object
Definition vehicle_base.h:280
Vehicle::GetDisplayRunningCost
Money GetDisplayRunningCost() const
Gets the running cost of a vehicle that can be sent into string parameters for string processing.
Definition vehicle_base.h:566
Vehicle::SetNext
void SetNext(Vehicle *next)
Set the next vehicle of this vehicle.
Definition vehicle.cpp:2927
Vehicle::breakdowns_since_last_service
uint8_t breakdowns_since_last_service
Counter for the amount of breakdowns.
Definition vehicle_base.h:262
Vehicle::next
Vehicle * next
pointer to the next vehicle in the chain
Definition vehicle_base.h:209
Vehicle::max_age
TimerGameCalendar::Date max_age
Maximum age.
Definition vehicle_base.h:255
Vehicle::sprite_cache
MutableSpriteCache sprite_cache
Cache of sprites and values related to recalculating them, see MutableSpriteCache.
Definition vehicle_base.h:323
Vehicle::reliability
uint16_t reliability
Reliability.
Definition vehicle_base.h:258
Vehicle::GetDisplayMaxWeight
uint32_t GetDisplayMaxWeight() const
Calculates the maximum weight of the ground vehicle when loaded.
Definition vehicle.cpp:3232
Vehicle::Last
const Vehicle * Last() const
Get the last vehicle of this vehicle chain.
Definition vehicle_base.h:617
Vehicle::PreviousShared
Vehicle * PreviousShared() const
Get the previous vehicle of the shared vehicle chain.
Definition vehicle_base.h:687
Vehicle::FirstShared
Vehicle * FirstShared() const
Get the first vehicle of this vehicle chain.
Definition vehicle_base.h:693
Vehicle::RemoveFromShared
void RemoveFromShared()
Removes the vehicle from the shared order list.
Definition vehicle.cpp:2979
Vehicle::HandleBreakdown
bool HandleBreakdown()
Handle all of the aspects of a vehicle breakdown This includes adding smoke and sounds,...
Definition vehicle.cpp:1332
Vehicle::progress
uint8_t progress
The percentage (if divided by 256) this vehicle already crossed the tile unit.
Definition vehicle_base.h:287
Vehicle::UpdatePositionAndViewport
void UpdatePositionAndViewport()
Update the position of the vehicle, and update the viewport.
Definition vehicle.cpp:1745
Vehicle::Previous
Vehicle * Previous() const
Get the previous vehicle of this vehicle.
Definition vehicle_base.h:594
Vehicle::PlayLeaveStationSound
virtual void PlayLeaveStationSound(bool force=false) const
Play the sound associated with leaving the station.
Definition vehicle_base.h:427
Vehicle::GetPrevVehicle
Vehicle * GetPrevVehicle() const
Get the previous real (non-articulated part) vehicle in the consist.
Definition vehicle_base.h:997
Vehicle::coord
Rect coord
NOSAVE: Graphical bounding box of the vehicle, i.e. what to redraw on moves.
Definition vehicle_base.h:240
Vehicle::reliability_spd_dec
uint16_t reliability_spd_dec
Reliability decrease speed.
Definition vehicle_base.h:259
Vehicle::tick_counter
uint8_t tick_counter
Increased by one for each tick.
Definition vehicle_base.h:305
Vehicle::SkipToNextRealOrderIndex
void SkipToNextRealOrderIndex()
Advance cur_real_order_index to the next real order.
Definition vehicle_base.h:811
Vehicle::IsInDepot
virtual bool IsInDepot() const
Check whether the vehicle is in the depot.
Definition vehicle_base.h:503
Vehicle::tile
TileIndex tile
Current tile index.
Definition vehicle_base.h:225
Vehicle::Tick
virtual bool Tick()
Calls the tick handler of the vehicle.
Definition vehicle_base.h:527
Vehicle::dest_tile
TileIndex dest_tile
Heading for this tile.
Definition vehicle_base.h:232
Vehicle::CopyVehicleConfigAndStatistics
void CopyVehicleConfigAndStatistics(Vehicle *src)
Copy certain configurations and statistics of a vehicle after successful autoreplace/renew The functi...
Definition vehicle_base.h:733
Vehicle::NeedsServicing
bool NeedsServicing() const
Check if the vehicle needs to go to a depot in near future (if a opportunity presents itself) for ser...
Definition vehicle.cpp:201
Vehicle::HasConditionalOrder
bool HasConditionalOrder() const
Check if the current vehicle has a conditional order.
Definition vehicle.cpp:2453
Vehicle::GetMaxWeight
virtual uint16_t GetMaxWeight() const
Calculates the weight value that this vehicle will have when fully loaded with its current cargo.
Definition vehicle_base.h:329
Vehicle::UpdatePosition
void UpdatePosition()
Update the position of the vehicle.
Definition vehicle.cpp:1662
Vehicle::GetRunningCost
virtual Money GetRunningCost() const
Gets the running cost of a vehicle.
Definition vehicle_base.h:497
Vehicle::last_station_visited
StationID last_station_visited
The last station we stopped at.
Definition vehicle_base.h:292
Vehicle::ResetRefitCaps
void ResetRefitCaps()
Reset all refit_cap in the consist to cargo_cap.
Definition vehicle.cpp:2388
Vehicle::InvalidateNewGRFCacheOfChain
void InvalidateNewGRFCacheOfChain()
Invalidates cached NewGRF variables of all vehicles in the chain (after the current vehicle)
Definition vehicle_base.h:459
Vehicle::breakdown_chance
uint8_t breakdown_chance
Current chance of breakdowns.
Definition vehicle_base.h:263
Vehicle::ShowVisualEffect
void ShowVisualEffect() const
Draw visual effects (smoke and/or sparks) for a vehicle chain.
Definition vehicle.cpp:2777
Vehicle::build_year
TimerGameCalendar::Year build_year
Year the vehicle has been built.
Definition vehicle_base.h:252
Vehicle::owner
Owner owner
Which company owns the vehicle?
Definition vehicle_base.h:270
Vehicle::unitnumber
UnitID unitnumber
unit number, for display purposes only
Definition vehicle_base.h:281
Vehicle::next_shared
Vehicle * next_shared
pointer to the next vehicle that shares the order
Definition vehicle_base.h:213
Vehicle::NeedsAutomaticServicing
bool NeedsAutomaticServicing() const
Checks if the current order should be interrupted for a service-in-depot order.
Definition vehicle.cpp:283
Vehicle::DeleteUnreachedImplicitOrders
void DeleteUnreachedImplicitOrders()
Delete all implicit orders which were not reached.
Definition vehicle.cpp:2145
Vehicle::running_ticks
uint8_t running_ticks
Number of ticks this vehicle was not stopped this day.
Definition vehicle_base.h:306
Vehicle::hash_viewport_prev
Vehicle ** hash_viewport_prev
NOSAVE: Previous vehicle in the visual location hash.
Definition vehicle_base.h:243
Vehicle::GetImage
virtual void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const
Gets the sprite to show for the given direction.
Definition vehicle_base.h:441
Vehicle::hash_viewport_next
Vehicle * hash_viewport_next
NOSAVE: Next vehicle in the visual location hash.
Definition vehicle_base.h:242
Vehicle::GetVehicleTrackdir
virtual Trackdir GetVehicleTrackdir() const
Returns the Trackdir on which the vehicle is currently located.
Definition vehicle_base.h:560
Vehicle::UpdateRealOrderIndex
void UpdateRealOrderIndex()
Skip implicit orders until cur_real_order_index is a non-implicit order.
Definition vehicle_base.h:869
Vehicle::GetFirstEnginePart
const Vehicle * GetFirstEnginePart() const
Get the first part of an articulated engine.
Definition vehicle_base.h:962
texteff.hpp
Functions related to text effects.
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:95
timer_game_calendar.h
Definition of the game-calendar-timer.
track_type.h
All types related to tracks.
Trackdir
Trackdir
Enumeration for tracks and directions.
Definition track_type.h:66
INVALID_TRACKDIR
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
Definition track_type.h:85
transport_type.h
Base types related to transport.
UnitID
uint16_t UnitID
Type for the company global vehicle unit number.
Definition transport_type.h:14
_vehicle_pool
VehiclePool _vehicle_pool("Vehicle")
The pool with all our precious vehicles.
FixOldVehicles
void FixOldVehicles(LoadgameState &ls)
Convert the old style vehicles into something that resembles the old new style savegames.
Definition oldloader_sl.cpp:160
LoadOldVehicle
bool LoadOldVehicle(LoadgameState &ls, int num)
Load the vehicles of an old style savegame.
Definition oldloader_sl.cpp:1258
VehState
VehState
Vehicle state bits in Vehicle::vehstatus.
Definition vehicle_base.h:32
VehState::Unclickable
@ Unclickable
Vehicle is not clickable by the user (shadow vehicles).
VehState::Crashed
@ Crashed
Vehicle is crashed.
VehState::Shadow
@ Shadow
Vehicle is a shadow vehicle.
VehState::TrainSlowing
@ TrainSlowing
Train is slowing down.
VehState::AircraftBroken
@ AircraftBroken
Aircraft is broken down.
VehState::Hidden
@ Hidden
Vehicle is not visible.
VehState::DefaultPalette
@ DefaultPalette
Use default vehicle palette.
VehState::Stopped
@ Stopped
Vehicle is stopped by the player.
GroundVehicleSubtypeFlags
GroundVehicleSubtypeFlags
Enum to handle ground vehicle subtypes.
Definition vehicle_base.h:82
GVSF_ARTICULATED_PART
@ GVSF_ARTICULATED_PART
Articulated part of an engine.
Definition vehicle_base.h:84
GVSF_FRONT
@ GVSF_FRONT
Leading engine of a consist.
Definition vehicle_base.h:83
GVSF_MULTIHEADED
@ GVSF_MULTIHEADED
Engine is multiheaded (not used for road vehicles).
Definition vehicle_base.h:88
GVSF_FREE_WAGON
@ GVSF_FREE_WAGON
First in a wagon chain (in depot) (not used for road vehicles).
Definition vehicle_base.h:87
GVSF_WAGON
@ GVSF_WAGON
Wagon (not used for road vehicles).
Definition vehicle_base.h:85
GVSF_ENGINE
@ GVSF_ENGINE
Engine that can be front engine, but might be placed behind another engine (not used for road vehicle...
Definition vehicle_base.h:86
VisualEffectSpawnModel
VisualEffectSpawnModel
Models for spawning visual effects.
Definition vehicle_base.h:68
VESM_ELECTRIC
@ VESM_ELECTRIC
Electric model.
Definition vehicle_base.h:72
VESM_STEAM
@ VESM_STEAM
Steam model.
Definition vehicle_base.h:70
VESM_DIESEL
@ VESM_DIESEL
Diesel model.
Definition vehicle_base.h:71
VESM_NONE
@ VESM_NONE
No visual effect.
Definition vehicle_base.h:69
VehiclePool
Pool< Vehicle, VehicleID, 512 > VehiclePool
A vehicle pool for a little over 1 million vehicles.
Definition vehicle_base.h:166
NewGRFCacheValidValues
NewGRFCacheValidValues
Bit numbers used to indicate which of the NewGRFCache values are valid.
Definition vehicle_base.h:45
NCVV_COMPANY_INFORMATION
@ NCVV_COMPANY_INFORMATION
This bit will be set if the NewGRF var 43 currently stored is valid.
Definition vehicle_base.h:49
NCVV_CONSIST_CARGO_INFORMATION
@ NCVV_CONSIST_CARGO_INFORMATION
This bit will be set if the NewGRF var 42 currently stored is valid.
Definition vehicle_base.h:48
NCVV_POSITION_CONSIST_LENGTH
@ NCVV_POSITION_CONSIST_LENGTH
This bit will be set if the NewGRF var 40 currently stored is valid.
Definition vehicle_base.h:46
NCVV_POSITION_SAME_ID_LENGTH
@ NCVV_POSITION_SAME_ID_LENGTH
This bit will be set if the NewGRF var 41 currently stored is valid.
Definition vehicle_base.h:47
NCVV_POSITION_IN_VEHICLE
@ NCVV_POSITION_IN_VEHICLE
This bit will be set if the NewGRF var 4D currently stored is valid.
Definition vehicle_base.h:50
NCVV_END
@ NCVV_END
End of the bits.
Definition vehicle_base.h:51
INVALID_COORD
static const int32_t INVALID_COORD
Sentinel for an invalid coordinate.
Definition vehicle_base.h:1207
EngineImageType
EngineImageType
Visualisation contexts of vehicles and engines.
Definition vehicle_type.h:74
EIT_ON_MAP
@ EIT_ON_MAP
Vehicle drawn in viewport.
Definition vehicle_type.h:75
VehicleType
VehicleType
Available vehicle types.
Definition vehicle_type.h:22
VEH_INVALID
@ VEH_INVALID
Non-existing type of vehicle.
Definition vehicle_type.h:36
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition vehicle_type.h:26
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition vehicle_type.h:25