From 842b2249ee38526f231d95cc12cc7d18d44e798f Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Thu, 2 May 2019 00:05:35 +0100 Subject: [PATCH] Fix possible incorrect value of VCF_GV_ZERO_SLOPE_RESIST In case where slope resistance becomes non-zero when up/down flag removed --- src/ground_vehicle.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ground_vehicle.hpp b/src/ground_vehicle.hpp index 6c238a16eb..f983cb0e8d 100644 --- a/src/ground_vehicle.hpp +++ b/src/ground_vehicle.hpp @@ -123,6 +123,7 @@ struct GroundVehicle : public SpecializedVehicle { if (likely(HasBit(this->vcache.cached_veh_flags, VCF_GV_ZERO_SLOPE_RESIST))) return 0; int64 incl = 0; + bool zero_slope_resist = true; for (const T *u = T::From(this); u != nullptr; u = u->Next()) { if (HasBit(u->gv_flags, GVF_GOINGUP_BIT)) { @@ -130,8 +131,9 @@ struct GroundVehicle : public SpecializedVehicle { } else if (HasBit(u->gv_flags, GVF_GOINGDOWN_BIT)) { incl -= u->gcache.cached_slope_resistance; } + if (incl != 0) zero_slope_resist = false; } - if (incl == 0) SetBit(this->vcache.cached_veh_flags, VCF_GV_ZERO_SLOPE_RESIST); + SB(this->vcache.cached_veh_flags, VCF_GV_ZERO_SLOPE_RESIST, 1, zero_slope_resist ? 1 : 0); return incl; }