OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

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,
36 VS_TRAIN_SLOWING = 0x10,
37 VS_SHADOW = 0x20,
38 VS_AIRCRAFT_BROKEN = 0x40,
39 VS_CRASHED = 0x80,
40 };
41
43 enum VehicleFlags {
44 VF_LOADING_FINISHED,
45 VF_CARGO_UNLOADING,
46 VF_BUILT_AS_PROTOTYPE,
47 VF_TIMETABLE_STARTED,
48 VF_AUTOFILL_TIMETABLE,
49 VF_AUTOFILL_PRES_WAIT_TIME,
50 VF_STOP_LOADING,
51 VF_PATHFINDER_LOST,
52 VF_SERVINT_IS_CUSTOM,
53 VF_SERVINT_IS_PERCENT,
54 };
55
57 enum NewGRFCacheValidValues {
58 NCVV_POSITION_CONSIST_LENGTH = 0,
59 NCVV_POSITION_SAME_ID_LENGTH = 1,
60 NCVV_CONSIST_CARGO_INFORMATION = 2,
61 NCVV_COMPANY_INFORMATION = 3,
62 NCVV_POSITION_IN_VEHICLE = 4,
63 NCVV_END,
64 };
65
67 struct NewGRFCache {
68 /* Values calculated when they are requested for the first time after invalidating the NewGRF cache. */
69 uint32 position_consist_length;
70 uint32 position_same_id_length;
71 uint32 consist_cargo_information;
72 uint32 company_information;
73 uint32 position_in_vehicle;
74 uint8 cache_valid;
75 };
76
78 enum VisualEffect {
79 VE_OFFSET_START = 0,
80 VE_OFFSET_COUNT = 4,
81 VE_OFFSET_CENTRE = 8,
82
83 VE_TYPE_START = 4,
84 VE_TYPE_COUNT = 2,
85 VE_TYPE_DEFAULT = 0,
86 VE_TYPE_STEAM = 1,
87 VE_TYPE_DIESEL = 2,
88 VE_TYPE_ELECTRIC = 3,
89
90 VE_DISABLE_EFFECT = 6,
91 VE_ADVANCED_EFFECT = VE_DISABLE_EFFECT,
92 VE_DISABLE_WAGON_POWER = 7,
93
94 VE_DEFAULT = 0xFF,
95 };
96
98 enum VisualEffectSpawnModel {
99 VESM_NONE = 0,
100 VESM_STEAM,
101 VESM_DIESEL,
102 VESM_ELECTRIC,
103
104 VESM_END
105 };
106
112 enum GroundVehicleSubtypeFlags {
113 GVSF_FRONT = 0,
114 GVSF_ARTICULATED_PART = 1,
115 GVSF_WAGON = 2,
116 GVSF_ENGINE = 3,
117 GVSF_FREE_WAGON = 4,
118 GVSF_MULTIHEADED = 5,
119 };
120
122 struct VehicleCache {
123 uint16 cached_max_speed;
124 uint16 cached_cargo_age_period;
125
126 byte cached_vis_effect;
127 };
128
130 struct VehicleSpriteSeq {
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
173 void CopyWithoutPalette(const VehicleSpriteSeq &src)
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
187 typedef Pool<Vehicle, VehicleID, 512, 0xFF000> VehiclePool;
188 extern VehiclePool _vehicle_pool;
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 {
204 CargoID cargo;
205 uint16 capacity;
206 uint16 remaining;
207 RefitDesc(CargoID cargo, uint16 capacity, uint16 remaining) :
208 cargo(cargo), capacity(capacity), remaining(remaining) {}
209 };
210
212 struct Vehicle : VehiclePool::PoolItem<&_vehicle_pool>, BaseVehicle, BaseConsist {
213 private:
214 typedef std::list<RefitDesc> RefitList;
215 typedef std::map<CargoID, uint> CapacitiesMap;
216
217 Vehicle *next;
218 Vehicle *previous;
219 Vehicle *first;
220
221 Vehicle *next_shared;
222 Vehicle *previous_shared;
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
230 TileIndex tile;
231
237 TileIndex dest_tile;
238
239 Money profit_this_year;
240 Money profit_last_year;
241 Money value;
242
243 CargoPayment *cargo_payment;
244
245 Rect coord;
246
247 Vehicle *hash_viewport_next;
248 Vehicle **hash_viewport_prev;
249
250 Vehicle *hash_tile_next;
251 Vehicle **hash_tile_prev;
252 Vehicle **hash_tile_current;
253
254 SpriteID colourmap;
255
256 /* Related to age and service time */
257 Year build_year;
258 Date age;
259 Date max_age;
260 Date date_of_last_service;
261 uint16 reliability;
262 uint16 reliability_spd_dec;
263 byte breakdown_ctr;
264 byte breakdown_delay;
265 byte breakdowns_since_last_service;
266 byte breakdown_chance;
267
268 int32 x_pos;
269 int32 y_pos;
270 int32 z_pos;
271 DirectionByte direction;
272
273 OwnerByte owner;
274
279 byte spritenum;
280 VehicleSpriteSeq sprite_seq;
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;
288 EngineID engine_type;
289
290 TextEffectID fill_percent_te_id;
291 UnitID unitnumber;
292
293 uint16 cur_speed;
294 byte subspeed;
295 byte acceleration;
296 uint32 motion_counter;
297 byte progress;
298
299 byte random_bits;
300 byte waiting_triggers;
301
302 StationID last_station_visited;
303 StationID last_loading_station;
304
305 CargoID cargo_type;
306 byte cargo_subtype;
307 uint16 cargo_cap;
308 uint16 refit_cap;
309 VehicleCargoList cargo;
310 uint16 cargo_age_counter;
311 int8 trip_occupancy;
312
313 byte day_counter;
314 byte tick_counter;
315 byte running_ticks;
316
317 byte vehstatus;
318 Order current_order;
319
320 union {
321 OrderList *list;
322 Order *old;
323 } orders;
324
325 uint16 load_unload_ticks;
326 GroupID group_id;
327 byte subtype;
328
329 NewGRFCache grf_cache;
330 VehicleCache vcache;
331
332 Vehicle(VehicleType type = VEH_INVALID);
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
461 inline void InvalidateNewGRFCacheOfChain()
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
700 inline StationIDStack GetNextStoppingStation() const
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:
780 void SkipToNextRealOrderIndex()
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:
799 void IncrementImplicitOrderIndex()
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
823 void IncrementRealOrderIndex()
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
838 void UpdateRealOrderIndex()
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
910 inline Vehicle *GetNextArticulatedPart() const
911 {
912 assert(this->HasArticulatedPart());
913 return this->Next();
914 }
915
920 inline Vehicle *GetFirstEnginePart()
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
942 inline Vehicle *GetLastEnginePart()
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
996 typedef SpecializedVehicle<T, Type> SpecializedVehicleBase;
997
1001 inline SpecializedVehicle<T, Type>() : Vehicle(Type)
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
1160 struct FreeUnitIDGenerator {
1161 bool *cache;
1162 UnitID maxid;
1163 UnitID curid;
1164
1165 FreeUnitIDGenerator(VehicleType type, CompanyID owner);
1166 UnitID NextID();
1167
1169 ~FreeUnitIDGenerator() { free(this->cache); }
1170 };
1171
1173 static const int32 INVALID_COORD = 0x7fffffff;
1174
1175 #endif /* VEHICLE_BASE_H */