summaryrefslogtreecommitdiff
path: root/train.h
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2006-08-26 14:22:54 +0000
committertruelight <truelight@openttd.org>2006-08-26 14:22:54 +0000
commit602c0d40b38c83e520667ec1585b7745278fbbf8 (patch)
tree3ffa0a94034a5993e48411c7cb9b2cb765c6b1de /train.h
parentbe737b80d35aebf98a7fb571b1124cd51b371953 (diff)
downloadopenttd-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.h38
1 files changed, 24 insertions, 14 deletions
diff --git a/train.h b/train.h
index 8399e8cc2..792c5e937 100644
--- a/train.h
+++ b/train.h
@@ -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);