summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/train.h70
-rw-r--r--src/vehicle_base.h112
2 files changed, 112 insertions, 70 deletions
diff --git a/src/train.h b/src/train.h
index 1d153337c..e416dd3d9 100644
--- a/src/train.h
+++ b/src/train.h
@@ -136,76 +136,6 @@ struct Train : public GroundVehicle<Train, VEH_TRAIN> {
int GetCurrentMaxSpeed() const;
/**
- * Get the next part of a multi-part engine.
- * Will only work on a multi-part engine (this->EngineHasArticPart() == true),
- * Result is undefined for normal engine.
- * @return next part of articulated engine
- */
- FORCEINLINE Train *GetNextArticulatedPart() const
- {
- assert(this->HasArticulatedPart());
- 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.
- */
- FORCEINLINE Train *GetLastEnginePart()
- {
- Train *v = this;
- while (v->HasArticulatedPart()) v = v->GetNextArticulatedPart();
- return v;
- }
-
- /**
- * Get the next real (non-articulated part) vehicle in the consist.
- * @return Next vehicle in the consist.
- */
- FORCEINLINE Train *GetNextVehicle() const
- {
- const Train *v = this;
- while (v->HasArticulatedPart()) v = v->GetNextArticulatedPart();
-
- /* v now contains the last artic part in the engine */
- return v->Next();
- }
-
- /**
- * Get the previous real (non-articulated part) vehicle in the consist.
- * @return Previous vehicle in the consist.
- */
- FORCEINLINE Train *GetPrevVehicle() const
- {
- Train *v = this->Previous();
- while (v != NULL && v->IsArticulatedPart()) v = v->Previous();
-
- return v;
- }
-
- /**
* Get the next real (non-articulated part and non rear part of dualheaded engine) vehicle in the consist.
* @return Next vehicle in the consist.
*/
diff --git a/src/vehicle_base.h b/src/vehicle_base.h
index d63d97b89..60de8b968 100644
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -671,6 +671,75 @@ public:
{
return this->Next() != NULL && this->Next()->IsArticulatedPart();
}
+
+ /**
+ * Get the next part of an articulated engine.
+ * @return Next part of the articulated engine.
+ * @pre The vehicle is an articulated engine.
+ */
+ FORCEINLINE Vehicle *GetNextArticulatedPart() const
+ {
+ assert(this->HasArticulatedPart());
+ return this->Next();
+ }
+
+ /**
+ * Get the first part of an articulated engine.
+ * @return First part of the engine.
+ */
+ FORCEINLINE Vehicle *GetFirstEnginePart()
+ {
+ Vehicle *v = this;
+ while (v->IsArticulatedPart()) v = v->Previous();
+ return v;
+ }
+
+ /**
+ * Get the first part of an articulated engine.
+ * @return First part of the engine.
+ */
+ FORCEINLINE const Vehicle *GetFirstEnginePart() const
+ {
+ const Vehicle *v = this;
+ while (v->IsArticulatedPart()) v = v->Previous();
+ return v;
+ }
+
+ /**
+ * Get the last part of an articulated engine.
+ * @return Last part of the engine.
+ */
+ FORCEINLINE Vehicle *GetLastEnginePart()
+ {
+ Vehicle *v = this;
+ while (v->HasArticulatedPart()) v = v->GetNextArticulatedPart();
+ return v;
+ }
+
+ /**
+ * Get the next real (non-articulated part) vehicle in the consist.
+ * @return Next vehicle in the consist.
+ */
+ FORCEINLINE Vehicle *GetNextVehicle() const
+ {
+ const Vehicle *v = this;
+ while (v->HasArticulatedPart()) v = v->GetNextArticulatedPart();
+
+ /* v now contains the last articulated part in the engine */
+ return v->Next();
+ }
+
+ /**
+ * Get the previous real (non-articulated part) vehicle in the consist.
+ * @return Previous vehicle in the consist.
+ */
+ FORCEINLINE Vehicle *GetPrevVehicle() const
+ {
+ Vehicle *v = this->Previous();
+ while (v != NULL && v->IsArticulatedPart()) v = v->Previous();
+
+ return v;
+ }
};
#define FOR_ALL_VEHICLES_FROM(var, start) FOR_ALL_ITEMS_FROM(Vehicle, vehicle_index, var, start)
@@ -721,6 +790,49 @@ struct SpecializedVehicle : public Vehicle {
*/
FORCEINLINE T *Previous() const { return (T *)this->Vehicle::Previous(); }
+ /**
+ * Get the next part of an articulated engine.
+ * @return Next part of the articulated engine.
+ * @pre The vehicle is an articulated engine.
+ */
+ FORCEINLINE T *GetNextArticulatedPart() { return (T *)this->Vehicle::GetNextArticulatedPart(); }
+
+ /**
+ * Get the next part of an articulated engine.
+ * @return Next part of the articulated engine.
+ * @pre The vehicle is an articulated engine.
+ */
+ FORCEINLINE T *GetNextArticulatedPart() const { return (T *)this->Vehicle::GetNextArticulatedPart(); }
+
+ /**
+ * Get the first part of an articulated engine.
+ * @return First part of the engine.
+ */
+ FORCEINLINE T *GetFirstEnginePart() { return (T *)this->Vehicle::GetFirstEnginePart(); }
+
+ /**
+ * Get the first part of an articulated engine.
+ * @return First part of the engine.
+ */
+ FORCEINLINE const T *GetFirstEnginePart() const { return (const T *)this->Vehicle::GetFirstEnginePart(); }
+
+ /**
+ * Get the last part of an articulated engine.
+ * @return Last part of the engine.
+ */
+ FORCEINLINE T *GetLastEnginePart() { return (T *)this->Vehicle::GetLastEnginePart(); }
+
+ /**
+ * Get the next real (non-articulated part) vehicle in the consist.
+ * @return Next vehicle in the consist.
+ */
+ FORCEINLINE T *GetNextVehicle() const { return (T *)this->Vehicle::GetNextVehicle(); }
+
+ /**
+ * Get the previous real (non-articulated part) vehicle in the consist.
+ * @return Previous vehicle in the consist.
+ */
+ FORCEINLINE T *GetPrevVehicle() const { return (T *)this->Vehicle::GetPrevVehicle(); }
/**
* Tests whether given index is a valid index for vehicle of this type