diff options
author | frosch <frosch@openttd.org> | 2012-07-07 15:39:46 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2012-07-07 15:39:46 +0000 |
commit | 08a8c3a773e9c730bd92a39e1e07403a172e866a (patch) | |
tree | 5fea4034f5d65bf6be9c28458ce05369d702a78d /src/ground_vehicle.cpp | |
parent | 8d004f3c63fbff4f3524f770483db90408a98c50 (diff) | |
download | openttd-08a8c3a773e9c730bd92a39e1e07403a172e866a.tar.xz |
(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.
Diffstat (limited to 'src/ground_vehicle.cpp')
-rw-r--r-- | src/ground_vehicle.cpp | 22 |
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 */ |