From 92f3c368b8685580353172e7979c7d7d816db21f Mon Sep 17 00:00:00 2001 From: frosch Date: Sat, 16 Aug 2008 14:02:20 +0000 Subject: (svn r14083) -Fix [FS#1264, FS#2037, FS#2038, FS#2110]: Rewrite the autoreplace kernel. --- src/train.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/train.h') diff --git a/src/train.h b/src/train.h index 0e92a962c..22ed95b04 100644 --- a/src/train.h +++ b/src/train.h @@ -247,6 +247,20 @@ static inline Vehicle *GetNextVehicle(const Vehicle *v) return v->Next(); } +/** Get the previous real (non-articulated part) vehicle in the consist. + * @param w Vehicle. + * @return Previous vehicle in the consist. + */ +static inline Vehicle *GetPrevVehicle(const Vehicle *w) +{ + assert(w->type == VEH_TRAIN); + + Vehicle *v = w->Previous(); + while (v != NULL && IsArticulatedPart(v)) v = v->Previous(); + + return v; +} + /** Get the next real (non-articulated part and non rear part of dualheaded engine) vehicle in the consist. * @param v Vehicle. * @return Next vehicle in the consist. @@ -260,6 +274,19 @@ static inline Vehicle *GetNextUnit(Vehicle *v) return v; } +/** Get the previous real (non-articulated part and non rear part of dualheaded engine) vehicle in the consist. + * @param v Vehicle. + * @return Previous vehicle in the consist. + */ +static inline Vehicle *GetPrevUnit(Vehicle *v) +{ + assert(v->type == VEH_TRAIN); + v = GetPrevVehicle(v); + if (v != NULL && IsRearDualheaded(v)) v = GetPrevVehicle(v); + + return v; +} + void ConvertOldMultiheadToNew(); void ConnectMultiheadedTrains(); -- cgit v1.2.3-54-g00ecf