From 5045ee4d279d0c41d6a9123d384dbc611ac9d5e1 Mon Sep 17 00:00:00 2001 From: Roman C Date: Sun, 23 Mar 2008 22:19:19 +0000 Subject: [PATCH] Aivolution: Attempt to avoid division by 0. git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@4280 4a71c877-e1ca-e34f-864e-861f7616d084 --- data/mods/global/aivolution/multiplay/skirmish/player0.slo | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/data/mods/global/aivolution/multiplay/skirmish/player0.slo b/data/mods/global/aivolution/multiplay/skirmish/player0.slo index b2961b97e..4ad17c10c 100644 --- a/data/mods/global/aivolution/multiplay/skirmish/player0.slo +++ b/data/mods/global/aivolution/multiplay/skirmish/player0.slo @@ -15437,13 +15437,18 @@ function int LanchasterTimeToWin(float _fStartForceA, float _fStartForceB, { local float _fTimeToWin,_fKillFactor; - if(_fStartForceA <= 0.0 or _fStartForceB <= 0.0){ + if(_fStartForceA <= 0.0 or _fStartForceB <= 0.0 or _fKillRateB == 0.0){ return 0; } _fKillFactor = (_fStartForceB / _fStartForceA) * sqrt(_fKillRateA / _fKillRateB); + // avoid division by 0 + if( (1.0 - _fKillFactor) == 0.0){ + return 0; + } + _fTimeToWin = 1.0 / (2.0 * sqrt(_fKillRateA * _fKillRateB)) * log ( (1.0 + _fKillFactor) / (1.0 - _fKillFactor) );