mirror of https://github.com/OpenTTD/OpenTTD
Fix 5a88027: [Script] Avoid overflow in scripts when infinite money is enabled (#12016)
parent
02cdd5ba8b
commit
34b05465d5
|
@ -178,6 +178,8 @@
|
||||||
{
|
{
|
||||||
company = ResolveCompanyID(company);
|
company = ResolveCompanyID(company);
|
||||||
if (company == COMPANY_INVALID) return -1;
|
if (company == COMPANY_INVALID) return -1;
|
||||||
|
/* If we return INT64_MAX as usual, overflows may occur in the script. So return a smaller value. */
|
||||||
|
if (_settings_game.difficulty.infinite_money) return INT32_MAX;
|
||||||
|
|
||||||
return GetAvailableMoney((::CompanyID)company);
|
return GetAvailableMoney((::CompanyID)company);
|
||||||
}
|
}
|
||||||
|
|
|
@ -258,9 +258,10 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the bank balance. In other words, the amount of money the given company can spent.
|
* Gets the bank balance. In other words, the amount of money the given company can spent.
|
||||||
|
* If infinite money is enabled, it returns INT32_MAX.
|
||||||
* @param company The company to get the bank balance of.
|
* @param company The company to get the bank balance of.
|
||||||
* @pre ResolveCompanyID(company) != COMPANY_INVALID.
|
* @pre ResolveCompanyID(company) != COMPANY_INVALID.
|
||||||
* @return The actual bank balance.
|
* @return The actual bank balance or INT32_MAX.
|
||||||
*/
|
*/
|
||||||
static Money GetBankBalance(CompanyID company);
|
static Money GetBankBalance(CompanyID company);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue