From 08a8c3a773e9c730bd92a39e1e07403a172e866a Mon Sep 17 00:00:00 2001 From: frosch Date: Sat, 7 Jul 2012 15:39:46 +0000 Subject: (svn r24384) -Fix [FS#5188-ish]: Make IsInDepot() functions behave consistent across vehicle types and add IsChainInDepot instead, if that is what shall be checked. --- src/ground_vehicle.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/ground_vehicle.cpp') 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::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 +bool GroundVehicle::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; /* Instantiation for RoadVehicle */ -- cgit v1.2.3-54-g00ecf