Added a check for overflowing player credits

This commit is contained in:
DeadlySurprise
2015-01-23 15:04:29 +01:00
parent bcda232a1c
commit 4f07de2af8

View File

@@ -79,8 +79,35 @@ namespace OpenRA.Traits
public void GiveCash(int num)
{
Cash += num;
Earned += num;
if (Cash < int.MaxValue)
{
try
{
checked
{
Cash += num;
}
}
catch (OverflowException)
{
Cash = int.MaxValue;
}
}
if (Earned < int.MaxValue)
{
try
{
checked
{
Earned += num;
}
}
catch (OverflowException)
{
Earned = int.MaxValue;
}
}
}
public bool TakeCash(int num)