From 3cb1dcf31cc9c01b0c6e6f4b65808a580d2bc9bd Mon Sep 17 00:00:00 2001 From: michi_cc Date: Tue, 4 Oct 2011 21:35:29 +0000 Subject: (svn r22997) -Feature: [NewGRF] Allow access to other vehicles in the vehicle chain in VarAction 2. --- src/vehicle_base.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/vehicle_base.h') diff --git a/src/vehicle_base.h b/src/vehicle_base.h index 958144115..5fc2500eb 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -498,6 +498,22 @@ public: return v; } + /** + * Get the vehicle at offset #n of this vehicle chain. + * @param n Offset from the current vehicle. + * @return The new vehicle or NULL if the offset is out-of-bounds. + */ + inline Vehicle *Move(int n) + { + Vehicle *v = this; + if (n < 0) { + for (int i = 0; i != n && v != NULL; i--) v = v->Previous(); + } else { + for (int i = 0; i != n && v != NULL; i++) v = v->Next(); + } + return v; + } + /** * Get the first order of the vehicles order list. * @return first order of order list. -- cgit v1.2.3-54-g00ecf