(svn r22997) -Feature: [NewGRF] Allow access to other vehicles in the vehicle chain in VarAction 2.

This commit is contained in:
michi_cc
2011-10-04 21:35:29 +00:00
parent 655cee276c
commit 3cb1dcf31c
2 changed files with 62 additions and 29 deletions

View File

@@ -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.