430 |
430 |
431 /** |
431 /** |
432 * Calls the tick handler of the vehicle |
432 * Calls the tick handler of the vehicle |
433 */ |
433 */ |
434 virtual void Tick() = 0; |
434 virtual void Tick() = 0; |
|
435 |
|
436 bool IsValid() const { return this->type != VEH_INVALID; } |
435 }; |
437 }; |
436 |
438 |
437 /** |
439 /** |
438 * This class 'wraps' Vehicle; you do not actually instantiate this class. |
440 * This class 'wraps' Vehicle; you do not actually instantiate this class. |
439 * You create a Vehicle using AllocateVehicle, so it is added to the pool |
441 * You create a Vehicle using AllocateVehicle, so it is added to the pool |
632 static inline uint GetNumVehicles() |
634 static inline uint GetNumVehicles() |
633 { |
635 { |
634 return GetVehiclePoolSize(); |
636 return GetVehiclePoolSize(); |
635 } |
637 } |
636 |
638 |
637 /** |
|
638 * Check if a Vehicle really exists. |
|
639 */ |
|
640 static inline bool IsValidVehicle(const Vehicle *v) |
|
641 { |
|
642 return v->type != VEH_INVALID; |
|
643 } |
|
644 |
|
645 void DestroyVehicle(Vehicle *v); |
639 void DestroyVehicle(Vehicle *v); |
646 |
640 |
647 static inline void DeleteVehicle(Vehicle *v) |
641 static inline void DeleteVehicle(Vehicle *v) |
648 { |
642 { |
649 DestroyVehicle(v); |
643 DestroyVehicle(v); |
666 static inline bool IsPlayerBuildableVehicleType(const Vehicle *v) |
660 static inline bool IsPlayerBuildableVehicleType(const Vehicle *v) |
667 { |
661 { |
668 return IsPlayerBuildableVehicleType(v->type); |
662 return IsPlayerBuildableVehicleType(v->type); |
669 } |
663 } |
670 |
664 |
671 #define FOR_ALL_VEHICLES_FROM(v, start) for (v = GetVehicle(start); v != NULL; v = (v->index + 1U < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) if (IsValidVehicle(v)) |
665 #define FOR_ALL_VEHICLES_FROM(v, start) for (v = GetVehicle(start); v != NULL; v = (v->index + 1U < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) if (v->IsValid()) |
672 #define FOR_ALL_VEHICLES(v) FOR_ALL_VEHICLES_FROM(v, 0) |
666 #define FOR_ALL_VEHICLES(v) FOR_ALL_VEHICLES_FROM(v, 0) |
673 |
667 |
674 /** |
668 /** |
675 * Check if an index is a vehicle-index (so between 0 and max-vehicles) |
669 * Check if an index is a vehicle-index (so between 0 and max-vehicles) |
676 * @param index of the vehicle to query |
670 * @param index of the vehicle to query |
677 * @return Returns true if the vehicle-id is in range |
671 * @return Returns true if the vehicle-id is in range |
678 */ |
672 */ |
679 static inline bool IsValidVehicleID(uint index) |
673 static inline bool IsValidVehicleID(uint index) |
680 { |
674 { |
681 return index < GetVehiclePoolSize() && IsValidVehicle(GetVehicle(index)); |
675 return index < GetVehiclePoolSize() && GetVehicle(index)->IsValid(); |
682 } |
676 } |
683 |
677 |
684 /* Returns order 'index' of a vehicle or NULL when it doesn't exists */ |
678 /* Returns order 'index' of a vehicle or NULL when it doesn't exists */ |
685 static inline Order *GetVehicleOrder(const Vehicle *v, int index) |
679 static inline Order *GetVehicleOrder(const Vehicle *v, int index) |
686 { |
680 { |