Cast to long to avoid overflow when multiplying by the health

This commit is contained in:
Arular101
2018-01-04 00:23:40 +01:00
committed by reaperrr
parent 32b0170785
commit 30acee38c9
9 changed files with 38 additions and 19 deletions

View File

@@ -160,7 +160,12 @@ namespace OpenRA.Mods.Common.AI
case DecisionMetric.Health:
var health = a.TraitOrDefault<Health>();
return (health != null) ? (health.HP / health.MaxHP) * Attractiveness : 0;
if (health == null)
return 0;
// Cast to long to avoid overflow when multiplying by the health
return (int)((long)health.HP * Attractiveness / health.MaxHP);
default:
return Attractiveness;