Author: anonymissimus
Date: Wed Oct 19 22:01:56 2011
New Revision: 51545
URL: http://svn.gna.org/viewcvs/wesnoth?rev=51545&view=rev
Log:
fix a devision by zero (bug #18795)
There seem to be more possible cases in this whole algorithm.
Modified:
trunk/src/attack_prediction.cpp
Modified: trunk/src/attack_prediction.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/attack_prediction.cpp?rev=51545&r1=51544&r2=51545&view=diff
==============================================================================
--- trunk/src/attack_prediction.cpp (original)
+++ trunk/src/attack_prediction.cpp Wed Oct 19 22:01:56 2011
@@ -22,6 +22,8 @@
* @file
* Simulate combat to calculate attacks. Standalone program, benchmark.
*/
+
+#include <cfloat>
#include "attack_prediction.hpp"
@@ -658,7 +660,9 @@
/* If we kill, we will level up. So then the damage we had becomes
less probable since it's now conditional on us not levelling up.
This doesn't apply to the probability of us dying, of course. */
- double scalefactor = 1 - kill_prob / (1 - hp_dist.front());
+ double scalefactor = 0;
+ const double chance_to_survive = 1 - hp_dist.front();
+ if(chance_to_survive > DBL_MIN) scalefactor = 1 - kill_prob /
chance_to_survive;
std::vector<double>::iterator i = hp_dist.begin();
++i; // Skip to the second value.
for (; i != hp_dist.end(); ++i) *i *= scalefactor;
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits