Fix #2117: crash if either combatant was guaranteed to die
Regression from commit f6c4f3d214
.
The code divided by zero and the probability to stay unscathed ended up as
NaN, which triggered an assertion failure if the AI simulated one more
fight for either combatant.
This commit is contained in:
parent
73fa6bc508
commit
8bfc5eb1da
1 changed files with 4 additions and 2 deletions
|
@ -2097,7 +2097,8 @@ void complex_fight(attack_prediction_mode mode,
|
|||
double first_hit = hit_chance * opp_hit_unknown;
|
||||
opp_hit += first_hit;
|
||||
opp_hit_unknown -= first_hit;
|
||||
double this_hit_killed_b = (pm->dead_prob_b() - b_already_dead) / ((1.0 - b_already_dead) * (1.0 - pm->dead_prob_a()));
|
||||
double both_were_alive = (1.0 - b_already_dead) * (1.0 - pm->dead_prob_a());
|
||||
double this_hit_killed_b = both_were_alive != 0.0 ? (pm->dead_prob_b() - b_already_dead) / both_were_alive : 1.0;
|
||||
self_hit_unknown *= (1.0 - this_hit_killed_b);
|
||||
}
|
||||
if(i < opp_strikes) {
|
||||
|
@ -2109,7 +2110,8 @@ void complex_fight(attack_prediction_mode mode,
|
|||
double first_hit = opp_hit_chance * self_hit_unknown;
|
||||
self_hit += first_hit;
|
||||
self_hit_unknown -= first_hit;
|
||||
double this_hit_killed_a = (pm->dead_prob_a() - a_already_dead) / ((1.0 - a_already_dead) * (1.0 - pm->dead_prob_b()));
|
||||
double both_were_alive = (1.0 - a_already_dead) * (1.0 - pm->dead_prob_b());
|
||||
double this_hit_killed_a = both_were_alive != 0.0 ? (pm->dead_prob_a() - a_already_dead) / both_were_alive : 1.0;
|
||||
opp_hit_unknown *= (1.0 - this_hit_killed_a);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue