diff options
Diffstat (limited to 'src/vehicle_base.h')
-rw-r--r-- | src/vehicle_base.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/vehicle_base.h b/src/vehicle_base.h index 6c9ba195e..ab06695e2 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -534,6 +534,22 @@ public: } /** + * Get the vehicle at offset \a 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 const Vehicle *Move(int n) const + { + const 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. */ |