summaryrefslogtreecommitdiff
path: root/src/vehicle_base.h
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2009-07-20 19:58:33 +0000
committerfrosch <frosch@openttd.org>2009-07-20 19:58:33 +0000
commitd5a4c893656f61950595c057c7643f4082228d47 (patch)
treeae65d69eb2c0ef06cd95925420d1e3fb1c11c382 /src/vehicle_base.h
parente3752f3ef82278a34fe5cce5515e240589465c77 (diff)
downloadopenttd-d5a4c893656f61950595c057c7643f4082228d47.tar.xz
(svn r16894) -Codechange: Add [Specialised]Vehicle::Last().
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
*/