From ddcc77352cb8913fc9b32240b43b1832840defbe Mon Sep 17 00:00:00 2001 From: Jyrki Vesterinen Date: Thu, 22 Jun 2017 21:46:24 +0300 Subject: [PATCH] calculate_probability_of_debuff(): limit probability to kill to 100 % Fixes #1808. --- src/attack_prediction.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/attack_prediction.cpp b/src/attack_prediction.cpp index a24d723a485e..f134b2600805 100644 --- a/src/attack_prediction.cpp +++ b/src/attack_prediction.cpp @@ -1762,7 +1762,9 @@ double calculate_probability_of_debuff(double initial_prob, bool enemy_gives, do assert(initial_prob >= 0.0 && initial_prob <= 1.0); assert(prob_touched >= 0.0 && prob_touched <= 1.0); assert(prob_stay_alive >= 0.0 && prob_stay_alive <= 1.0); - assert(prob_kill >= 0.0 && prob_kill <= 1.0); + // Prob_kill can creep a bit above 100 % if the AI simulates an unit being attacked by multiple units in a row, due to rounding error. + // Simply limit it to suitable range. + prob_kill = std::min(prob_kill, 1.0); // Probability we are already debuffed and the enemy doesn't hit us. const double prob_already_debuffed_not_touched = initial_prob * (1.0 - prob_touched);