Fix possible incorrect value of VCF_GV_ZERO_SLOPE_RESIST

In case where slope resistance becomes non-zero when up/down flag removed
pull/88/head
Jonathan G Rennison 5 years ago
parent 5d4f1b488d
commit 842b2249ee

@ -123,6 +123,7 @@ struct GroundVehicle : public SpecializedVehicle<T, Type> {
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<T, Type> {
} 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;
}

Loading…
Cancel
Save