From 49d7afe7ae6238797322d28e2a2af796b8b8ffcd Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 11 Apr 2021 23:44:14 +0100 Subject: [PATCH] Fix brakes overheated breakdown triggering only with a lower advisory max speed --- src/ground_vehicle.hpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/ground_vehicle.hpp b/src/ground_vehicle.hpp index bd27eae11d..ee1c83f24a 100644 --- a/src/ground_vehicle.hpp +++ b/src/ground_vehicle.hpp @@ -476,12 +476,7 @@ protected: tempmax = std::max(this->cur_speed - (this->cur_speed / 10) - 1, max_speed); } - /* Enforce a maximum and minimum speed. Normally we would use something like - * Clamp for this, but in this case min_speed might be below the maximum speed - * threshold for some reason. That makes acceleration fail and assertions - * happen in Clamp. So make it explicit that min_speed overrules the maximum - * speed by explicit ordering of min and max. */ - int tempspeed = std::min(this->cur_speed + ((int)spd >> 8), tempmax); + int tempspeed = this->cur_speed + ((int)spd >> 8); if (Type == VEH_TRAIN && _settings_game.vehicle.train_braking_model == TBM_REALISTIC && tempspeed > advisory_max_speed && accel.braking != accel.acceleration) { spd = initial_subspeed + accel.braking; @@ -504,6 +499,13 @@ protected: } } + /* Enforce a maximum and minimum speed. Normally we would use something like + * Clamp for this, but in this case min_speed might be below the maximum speed + * threshold for some reason. That makes acceleration fail and assertions + * happen in Clamp. So make it explicit that min_speed overrules the maximum + * speed by explicit ordering of min and max. */ + tempspeed = std::min(tempspeed, tempmax); + this->cur_speed = std::max(tempspeed, min_speed); int scaled_spd = this->GetAdvanceSpeed(this->cur_speed);