Fix #4307: possible crash in attack prediction with high number of strikes
If a unit has an attack with ability to poison/slow and a high number of strikes (24 in the provided test case), the calculated probability of the other unit being hit and therefore poisoned/slowed could exceed 100 % due to floating point rounding errors. It caused an assertion failure if the AI simulated another fight for the target unit afterwards. Fixed by limiting the probability of being hit to 100 %.
This commit is contained in:
parent
6f468a3757
commit
1b7f9a3ef8
1 changed files with 3 additions and 0 deletions
|
@ -2146,6 +2146,9 @@ void complex_fight(attack_prediction_mode mode,
|
|||
pm->dump();
|
||||
} while(--rounds && pm->dead_prob() < 0.99);
|
||||
|
||||
self_hit = std::min(self_hit, 1.0);
|
||||
opp_hit = std::min(opp_hit, 1.0);
|
||||
|
||||
self_not_hit = original_self_not_hit * (1.0 - self_hit);
|
||||
opp_not_hit = original_opp_not_hit * (1.0 - opp_hit);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue