From 7b92d9efe4efbc69b4a2b4563f2fc7645bc8938d Mon Sep 17 00:00:00 2001 From: frosch Date: Sun, 19 Jul 2009 19:17:41 +0000 Subject: (svn r16884) -Codechange: Add Train::GetFirstEnginePart() and use it. --- src/train.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/train.h') diff --git a/src/train.h b/src/train.h index 5dc3c1cfa..965d45baf 100644 --- a/src/train.h +++ b/src/train.h @@ -273,6 +273,28 @@ struct Train : public SpecializedVehicle { return this->Next(); } + /** + * Get the first part of a multi-part engine. + * @return First part of the engine. + */ + FORCEINLINE Train *GetFirstEnginePart() + { + Train *v = this; + while (v->IsArticulatedPart()) v = v->Previous(); + return v; + } + + /** + * Get the first part of a multi-part engine. + * @return First part of the engine. + */ + FORCEINLINE const Train *GetFirstEnginePart() const + { + const Train *v = this; + while (v->IsArticulatedPart()) v = v->Previous(); + return v; + } + /** * Get the last part of a multi-part engine. * @return Last part of the engine. -- cgit v1.2.3-54-g00ecf