summaryrefslogtreecommitdiff
path: root/src/vehicle_base.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/vehicle_base.h')
-rw-r--r--src/vehicle_base.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/vehicle_base.h b/src/vehicle_base.h
index ff8c34000..80f7c0581 100644
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -366,6 +366,27 @@ public:
*/
inline Vehicle *First() const { return this->first; }
+ /**
+ * Get the last vehicle of this vehicle chain.
+ * @return the last vehicle of the chain.
+ */
+ inline Vehicle *Last()
+ {
+ Vehicle *v = this;
+ while (v->Next() != NULL) v = v->Next();
+ return v;
+ }
+
+ /**
+ * Get the last vehicle of this vehicle chain.
+ * @return the last vehicle of the chain.
+ */
+ inline const Vehicle *Last() const
+ {
+ const Vehicle *v = this;
+ while (v->Next() != NULL) v = v->Next();
+ return v;
+ }
/**
* Get the first order of the vehicles order list.
@@ -538,6 +559,18 @@ struct SpecializedVehicle : public Vehicle {
FORCEINLINE T *First() const { return (T *)this->Vehicle::First(); }
/**
+ * Get the last vehicle in the chain
+ * @return last vehicle in the chain
+ */
+ FORCEINLINE T *Last() { return (T *)this->Vehicle::Last(); }
+
+ /**
+ * Get the last vehicle in the chain
+ * @return last vehicle in the chain
+ */
+ FORCEINLINE const T *Last() const { return (const T *)this->Vehicle::Last(); }
+
+ /**
* Get next vehicle in the chain
* @return next vehicle in the chain
*/