Fix a rare crash in attack prediction

The crash occurred if
* the AI simulated three fights for a unit in a row
* the unit was initially slowed
* the unit had a chance of killing the attacking unit in the first
fight, removing the slow status
* the second fight was NOT simulated with Monte Carlo mode...
* ...and the third fight was.

It was my mistake from commit d83e0176. I hadn't understood the meaning
of those two function parameters correctly. They don't need to be set to
true if the target unit is already slowed... and, in fact, they must not
be set to true if the attacking unit doesn't slow.

What happened here is that the combat matrix thought that the attacker's
attack slowed the defending unit, placing the result of some of
attacker's hits in the wrong plane. Meanwhile the calculation about the
probability that the defending unit is slowed produced the correct
result. In the next battle, when Monte Carlo mode scaled the "not
slowed" HP distribution with the probability of not being slowed, it
detected the severe discrepancy (in the example case, probabilities only
added up to 12,5 % instead of 100 %) and crashed the game.

This commit fixes the issue by passing correct parameter values.
Fixes #4068.
This commit is contained in:
Jyrki Vesterinen 2019-05-11 23:15:53 +03:00
parent ea11b238b4
commit 77da93cbf2

View file

@ -2107,8 +2107,8 @@ void complex_fight(attack_prediction_mode mode,
debug(("Using exact probability calculations.\n"));
probability_combat_matrix* pm = new probability_combat_matrix(stats.max_hp, opp_stats.max_hp, stats.hp,
opp_stats.hp, summary, opp_summary, stats.slows || opp_stats.is_slowed,
opp_stats.slows || stats.is_slowed, a_damage, b_damage, a_slow_damage, b_slow_damage,
opp_stats.hp, summary, opp_summary, stats.slows, opp_stats.slows,
a_damage, b_damage, a_slow_damage, b_slow_damage,
stats.drain_percent, opp_stats.drain_percent, stats.drain_constant, opp_stats.drain_constant);
m.reset(pm);
@ -2169,8 +2169,8 @@ void complex_fight(attack_prediction_mode mode,
debug(("Using Monte Carlo simulation.\n"));
monte_carlo_combat_matrix* mcm = new monte_carlo_combat_matrix(stats.max_hp, opp_stats.max_hp, stats.hp,
opp_stats.hp, summary, opp_summary, stats.slows || opp_stats.is_slowed,
opp_stats.slows || stats.is_slowed, a_damage, b_damage, a_slow_damage, b_slow_damage,
opp_stats.hp, summary, opp_summary, stats.slows, opp_stats.slows,
a_damage, b_damage, a_slow_damage, b_slow_damage,
stats.drain_percent, opp_stats.drain_percent, stats.drain_constant, opp_stats.drain_constant, rounds,
hit_chance, opp_hit_chance, split, opp_split, initially_slowed_chance, opp_initially_slowed_chance);
m.reset(mcm);