Changeset - r28700:ba3fdb413da6
[Not reviewed]
master
0 2 0
merni-ns - 10 months ago 2024-02-06 18:54:38
66267867+merni-ns@users.noreply.github.com
Fix 5a88027: [Script] Avoid overflow in scripts when infinite money is enabled (#12016)
2 files changed with 4 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/script/api/script_company.cpp
Show inline comments
 
@@ -178,6 +178,8 @@
 
{
 
	company = ResolveCompanyID(company);
 
	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);
 
}
src/script/api/script_company.hpp
Show inline comments
 
@@ -258,9 +258,10 @@ public:
 

	
 
	/**
 
	 * 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.
 
	 * @pre ResolveCompanyID(company) != COMPANY_INVALID.
 
	 * @return The actual bank balance.
 
	 * @return The actual bank balance or INT32_MAX.
 
	 */
 
	static Money GetBankBalance(CompanyID company);
 

	
0 comments (0 inline, 0 general)