summaryrefslogtreecommitdiff
path: root/src/ground_vehicle.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ground_vehicle.cpp')
-rw-r--r--src/ground_vehicle.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/ground_vehicle.cpp b/src/ground_vehicle.cpp
index 27e9776b9..5712b28f9 100644
--- a/src/ground_vehicle.cpp
+++ b/src/ground_vehicle.cpp
@@ -12,6 +12,7 @@
#include "stdafx.h"
#include "train.h"
#include "roadveh.h"
+#include "depot_map.h"
/**
* Recalculates the cached total power of a vehicle. Should be called when the consist is changed.
@@ -164,6 +165,27 @@ int GroundVehicle<T, Type>::GetAcceleration() const
}
}
+/**
+ * Check whether the whole vehicle chain is in the depot.
+ * @return true if and only if the whole chain is in the depot.
+ */
+template <class T, VehicleType Type>
+bool GroundVehicle<T, Type>::IsChainInDepot() const
+{
+ const T *v = this->First();
+ /* Is the front engine stationary in the depot? */
+ assert_compile((int)TRANSPORT_RAIL == (int)VEH_TRAIN);
+ assert_compile((int)TRANSPORT_ROAD == (int)VEH_ROAD);
+ if (!IsDepotTypeTile(v->tile, (TransportType)Type) || v->cur_speed != 0) return false;
+
+ /* Check whether the rest is also already trying to enter the depot. */
+ for (; v != NULL; v = v->Next()) {
+ if (!v->T::IsInDepot() || v->tile != this->tile) return false;
+ }
+
+ return true;
+}
+
/* Instantiation for Train */
template struct GroundVehicle<Train, VEH_TRAIN>;
/* Instantiation for RoadVehicle */