diff options
author | terkhen <terkhen@openttd.org> | 2010-03-06 12:50:55 +0000 |
---|---|---|
committer | terkhen <terkhen@openttd.org> | 2010-03-06 12:50:55 +0000 |
commit | 4e6cac84d6d30ea07fe7035f76085f8b0b55df78 (patch) | |
tree | b16c3b54612de1357bcd3859fbab8dc183990617 /src/ground_vehicle.hpp | |
parent | 1c3b7c35a7efbd05da32c97d0a6b4fc49fed087a (diff) | |
download | openttd-4e6cac84d6d30ea07fe7035f76085f8b0b55df78.tar.xz |
(svn r19341) -Codechange: Move GOINGUP/GOINGDOWN flags to GroundVehicle.
-Codechange: Move GetSlopeResistance to GroundVehicle.
Diffstat (limited to 'src/ground_vehicle.hpp')
-rw-r--r-- | src/ground_vehicle.hpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/ground_vehicle.hpp b/src/ground_vehicle.hpp index 106b0b954..2682fb04d 100644 --- a/src/ground_vehicle.hpp +++ b/src/ground_vehicle.hpp @@ -37,6 +37,12 @@ struct AccelerationCache { uint16 cached_max_track_speed; ///< Maximum consist speed limited by track type. }; +/** Ground vehicle flags. */ +enum GroundVehicleFlags { + GVF_GOINGUP_BIT = 0, + GVF_GOINGDOWN_BIT = 1, +}; + /** * Base class for all vehicles that move through ground. * @@ -58,6 +64,7 @@ struct AccelerationCache { template <class T, VehicleType Type> struct GroundVehicle : public SpecializedVehicle<T, Type> { AccelerationCache acc_cache; + uint16 gv_flags; ///< @see GroundVehicleFlags /** * The constructor at SpecializedVehicle must be called. @@ -67,6 +74,25 @@ struct GroundVehicle : public SpecializedVehicle<T, Type> { void PowerChanged(); void CargoChanged(); int GetAcceleration() const; + + /** + * Calculates the total slope resistance for this vehicle. + * @return Slope resistance. + */ + FORCEINLINE int32 GetSlopeResistance() const + { + int32 incl = 0; + + for (const T *u = T::From(this); u != NULL; u = u->Next()) { + if (HasBit(u->gv_flags, GVF_GOINGUP_BIT)) { + incl += u->acc_cache.cached_slope_resistance; + } else if (HasBit(u->gv_flags, GVF_GOINGDOWN_BIT)) { + incl -= u->acc_cache.cached_slope_resistance; + } + } + + return incl; + } }; #endif /* GROUND_VEHICLE_HPP */ |