Fixed possible division by zero in CritterMoth

This commit is contained in:
Eddoursul 2024-02-08 06:51:35 +01:00
parent c806c1a482
commit 1a9175d4b7
2 changed files with 12 additions and 5 deletions

Binary file not shown.

View File

@ -362,13 +362,20 @@ ObjectReference Function PickNextPlant()
float distanceTraveled = Math.sqrt(Math.pow(distanceTraveledX, 2) + Math.pow(distanceTraveledY, 2))
wanderRangeX = RandomFloat(fMinWander, fMaxWander) * Math.cos(distanceTraveledX / distanceTraveled)
if (distanceTraveledX < 0) ; more efficient than calling math.abs
wanderRangeX *= -1
if distanceTraveled > 0
wanderRangeX = RandomFloat(fMinWander, fMaxWander) * Math.cos(distanceTraveledX / distanceTraveled)
if (distanceTraveledX < 0) ; more efficient than calling math.abs
wanderRangeX *= -1
endif
wanderRangeY = RandomFloat(fMinWander, fMaxWander) * Math.sin(distanceTraveledY / distanceTraveled)
endif
wanderRangeY = RandomFloat(fMinWander, fMaxWander) * Math.sin(distanceTraveledY / distanceTraveled)
else
endif
if wanderRangeX == 0
wanderRangeX = RandomFloat(fMinWander, fMaxWander) * RandomInt(-1, 1)
endif
if wanderRangeY == 0
wanderRangeY = RandomFloat(fMinWander, fMaxWander) * RandomInt(-1, 1)
endif