Fix a division by zero error in FindAndDeliverResources

by preventing an overflow through dividing directly
This commit is contained in:
abcdefg30
2019-09-05 15:11:18 +02:00
committed by Paul Chote
parent aff3bf369b
commit ca8ca2df5c

View File

@@ -214,7 +214,7 @@ namespace OpenRA.Mods.Common.Activities
if (b != WVec.Zero && c != WVec.Zero)
{
var cosA = (int)(1024 * (b.LengthSquared + c.LengthSquared - a.LengthSquared) / (2 * b.Length * c.Length));
var cosA = (int)(512 * (b.LengthSquared + c.LengthSquared - a.LengthSquared) / b.Length / c.Length);
// Cost modifier varies between 0 and ResourceRefineryDirectionPenalty
return Math.Abs(harvInfo.ResourceRefineryDirectionPenalty / 2) + harvInfo.ResourceRefineryDirectionPenalty * cosA / 2048;