mirror of https://github.com/OpenTTD/OpenTTD
Change: Don't check for sufficient money if infinite money setting is on
parent
44c83ccb4c
commit
f41bba8f02
|
@ -202,14 +202,15 @@ void InvalidateCompanyWindows(const Company *company)
|
|||
*/
|
||||
Money GetAvailableMoney(CompanyID company)
|
||||
{
|
||||
if (_settings_game.difficulty.infinite_money) return INT64_MAX;
|
||||
if (!Company::IsValidID(company)) return INT64_MAX;
|
||||
return Company::Get(company)->money;
|
||||
}
|
||||
|
||||
/**
|
||||
* This functions returns the money which can be used to execute a command.
|
||||
* This is either the money of the current company or INT64_MAX if there
|
||||
* is no such a company "at the moment" like the server itself.
|
||||
* This is either the money of the current company, or INT64_MAX if infinite money
|
||||
* is enabled or there is no such a company "at the moment" like the server itself.
|
||||
*
|
||||
* @return The available money of the current company or INT64_MAX
|
||||
*/
|
||||
|
@ -221,17 +222,19 @@ Money GetAvailableMoneyForCommand()
|
|||
/**
|
||||
* Verify whether the company can pay the bill.
|
||||
* @param[in,out] cost Money to pay, is changed to an error if the company does not have enough money.
|
||||
* @return Function returns \c true if the company has enough money, else it returns \c false.
|
||||
* @return Function returns \c true if the company has enough money or infinite money is enabled,
|
||||
* else it returns \c false.
|
||||
*/
|
||||
bool CheckCompanyHasMoney(CommandCost &cost)
|
||||
{
|
||||
if (cost.GetCost() > 0) {
|
||||
const Company *c = Company::GetIfValid(_current_company);
|
||||
if (c != nullptr && cost.GetCost() > c->money) {
|
||||
SetDParam(0, cost.GetCost());
|
||||
cost.MakeError(STR_ERROR_NOT_ENOUGH_CASH_REQUIRES_CURRENCY);
|
||||
return false;
|
||||
}
|
||||
if (cost.GetCost() <= 0) return true;
|
||||
if (_settings_game.difficulty.infinite_money) return true;
|
||||
|
||||
const Company *c = Company::GetIfValid(_current_company);
|
||||
if (c != nullptr && cost.GetCost() > c->money) {
|
||||
SetDParam(0, cost.GetCost());
|
||||
cost.MakeError(STR_ERROR_NOT_ENOUGH_CASH_REQUIRES_CURRENCY);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -179,7 +179,7 @@
|
|||
company = ResolveCompanyID(company);
|
||||
if (company == COMPANY_INVALID) return -1;
|
||||
|
||||
return ::Company::Get(company)->money;
|
||||
return GetAvailableMoney((::CompanyID)company);
|
||||
}
|
||||
|
||||
/* static */ Money ScriptCompany::GetLoanAmount()
|
||||
|
|
|
@ -220,7 +220,7 @@ bool Vehicle::NeedsServicing() const
|
|||
* There are a lot more reasons for autoreplace to fail than we can test here reasonably. */
|
||||
bool pending_replace = false;
|
||||
Money needed_money = c->settings.engine_renew_money;
|
||||
if (needed_money > c->money) return false;
|
||||
if (needed_money > GetAvailableMoney(c->index)) return false;
|
||||
|
||||
for (const Vehicle *v = this; v != nullptr; v = (v->type == VEH_TRAIN) ? Train::From(v)->GetNextUnit() : nullptr) {
|
||||
bool replace_when_old = false;
|
||||
|
@ -258,7 +258,7 @@ bool Vehicle::NeedsServicing() const
|
|||
* We want 2*(the price of the new vehicle) without looking at the value of the vehicle we are going to sell. */
|
||||
pending_replace = true;
|
||||
needed_money += 2 * Engine::Get(new_engine)->GetCost();
|
||||
if (needed_money > c->money) return false;
|
||||
if (needed_money > GetAvailableMoney(c->index)) return false;
|
||||
}
|
||||
|
||||
return pending_replace;
|
||||
|
|
Loading…
Reference in New Issue