summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2011-01-26 17:37:12 +0000
committerrubidium <rubidium@openttd.org>2011-01-26 17:37:12 +0000
commitab4c419fcff3c565e4f2785b5bb06b79175bed86 (patch)
tree2defb8aaa39d33ccfecf4b9fbac83a2bbae65b03
parent430fda01dcaf6c6abd3a6b6b4b0a4ae6bae51e65 (diff)
downloadopenttd-ab4c419fcff3c565e4f2785b5bb06b79175bed86.tar.xz
(svn r21916) -Fix [FS#4442]: the minimum speed needed for (realistic) acceleration to work properly can sometimes be more than the (temporary) maximum speed causing Clamp to "fail". Make sure that the minimum speed always overrules the maximum speed
-rw-r--r--src/ground_vehicle.hpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/ground_vehicle.hpp b/src/ground_vehicle.hpp
index 65bcb7653..a4be384a6 100644
--- a/src/ground_vehicle.hpp
+++ b/src/ground_vehicle.hpp
@@ -404,7 +404,12 @@ protected:
tempmax = max(this->cur_speed - (this->cur_speed / 10) - 1, max_speed);
}
- this->cur_speed = spd = Clamp(this->cur_speed + ((int)spd >> 8), min_speed, tempmax);
+ /* 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. */
+ this->cur_speed = spd = max(min(this->cur_speed + ((int)spd >> 8), tempmax), min_speed);
int scaled_spd = this->GetAdvanceSpeed(spd);