Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix wesnoth#3042: attack prediction gives wrong results for HP <= 0 u…
…nits One_strike_fight() assumed that if HP distribution hadn't been calculated, the unit is alive. It would normally be a valid assumption, but the Wesnoth engine allows units with negative HP (although things aren't guaranteed to work correctly in the presence of such units). The assumption, together with a completely wrong calculation for the probability that the opponent will counterattack, resulted in badly incorrect results. That, in turn, caused the calculated probability that the opponent to kill us to become negative (I observed -75 % when debugging), making the calculated probability to be poisoned/slowed to exceed 100 %, and that finally caused an assert if the AI simulated another fight for the same unit. I have now fixed those issues. I also noticed that rounding error allowed the probability to be killed to still become slightly negative, and thus changed std::min() to utils::clamp() to limit the value to the allowed range.
- Loading branch information