diff options
author | truelight <truelight@openttd.org> | 2006-08-26 14:22:54 +0000 |
---|---|---|
committer | truelight <truelight@openttd.org> | 2006-08-26 14:22:54 +0000 |
commit | 602c0d40b38c83e520667ec1585b7745278fbbf8 (patch) | |
tree | 3ffa0a94034a5993e48411c7cb9b2cb765c6b1de /train.h | |
parent | be737b80d35aebf98a7fb571b1124cd51b371953 (diff) | |
download | openttd-602c0d40b38c83e520667ec1585b7745278fbbf8.tar.xz |
(svn r6137) -Codechange: some very minor cleanups:
- Start using DeleteXXX for every pool item, not manually doing it
- Use some wrapper to improve logic
- Rewrote some pieces to improve logic
Diffstat (limited to 'train.h')
-rw-r--r-- | train.h | 38 |
1 files changed, 24 insertions, 14 deletions
@@ -173,19 +173,6 @@ static inline void ClearMultiheaded(Vehicle *v) CLRBIT(v->subtype, Train_Multiheaded); } -/** Get the next real (non-articulated part) vehicle in the consist. - * @param v Vehicle. - * @return Next vehicle in the consist. - */ -static inline Vehicle *GetNextVehicle(const Vehicle *v) -{ - Vehicle *u = v->next; - while (u != NULL && IsArticulatedPart(u)) { - u = u->next; - } - return u; -} - /** Check if an engine has an articulated part. * @param v Vehicle. * @return True if the engine has an articulated part. @@ -195,16 +182,39 @@ static inline bool EngineHasArticPart(const Vehicle *v) return (v->next != NULL && IsArticulatedPart(v->next)); } +/** + * Get the next part of a multi-part engine. + * Will only work on a multi-part engine (EngineHasArticPart(v) == true), + * Result is undefined for normal engine. + */ +static inline Vehicle *GetNextArticPart(const Vehicle *v) +{ + assert(EngineHasArticPart(v)); + return v->next; +} + /** Get the last part of a multi-part engine. * @param v Vehicle. * @return Last part of the engine. */ static inline Vehicle *GetLastEnginePart(Vehicle *v) { - while (EngineHasArticPart(v)) v = v->next; + while (EngineHasArticPart(v)) v = GetNextArticPart(v); return v; } +/** Get the next real (non-articulated part) vehicle in the consist. + * @param v Vehicle. + * @return Next vehicle in the consist. + */ +static inline Vehicle *GetNextVehicle(const Vehicle *v) +{ + while (EngineHasArticPart(v)) v = GetNextArticPart(v); + + /* v now contains the last artic part in the engine */ + return v->next; +} + void ConvertOldMultiheadToNew(void); void ConnectMultiheadedTrains(void); |