Cast to long to avoid overflow when multiplying by the health (part 2)

This commit is contained in:
Arular101
2018-01-10 18:12:37 +01:00
committed by reaperrr
parent 30acee38c9
commit 24b7f7a23f
6 changed files with 17 additions and 7 deletions

View File

@@ -43,7 +43,8 @@ namespace OpenRA.Mods.Common.Traits
Info = info;
MaxHP = info.HP > 0 ? info.HP : 1;
hp = init.Contains<HealthInit>() ? init.Get<HealthInit, int>() * MaxHP / 100 : MaxHP;
// Cast to long to avoid overflow when multiplying by the health
hp = init.Contains<HealthInit>() ? (int)(init.Get<HealthInit, int>() * (long)MaxHP / 100) : MaxHP;
DisplayHP = hp;
}