Merge branch 'master' into jgrpp

# Conflicts:
#	src/cheat_gui.cpp
#	src/command.cpp
#	src/command_func.h
#	src/company_base.h
#	src/debug.cpp
#	src/debug.h
#	src/economy.cpp
#	src/engine_type.h
#	src/graph_gui.cpp
#	src/misc_cmd.cpp
#	src/misc_cmd.h
#	src/network/core/os_abstraction.cpp
#	src/openttd.cpp
#	src/saveload/saveload.cpp
#	src/saveload/saveload.h
#	src/settings_type.h
#	src/ship_cmd.cpp
#	src/stdafx.h
#	src/tests/bitmath_func.cpp
#	src/town_cmd.cpp
#	src/town_gui.cpp
This commit is contained in:
Jonathan G Rennison
2024-02-17 11:53:23 +00:00
66 changed files with 554 additions and 234 deletions

View File

@@ -109,6 +109,16 @@ void Company::PostDestructor(size_t index)
InvalidateWindowData(WC_ERRMSG, 0);
}
/**
* Calculate the max allowed loan for this company.
* @return the max loan amount.
*/
Money Company::GetMaxLoan() const
{
if (this->max_loan == COMPANY_MAX_LOAN_DEFAULT) return _economy.max_loan;
return this->max_loan;
}
/**
* Sets the local company and updates the settings that are set on a
* per-company basis to reflect the core's state in the GUI.
@@ -216,20 +226,48 @@ void InvalidateCompanyWindows(const Company *company)
SetWindowDirty(WC_FINANCES, cid);
}
/**
* Get the amount of money that a company has available, or INT64_MAX
* if there is no such valid company.
*
* @param company Company to check
* @return The available money of the company or INT64_MAX
*/
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 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
*/
Money GetAvailableMoneyForCommand()
{
return GetAvailableMoney(_current_company);
}
/**
* 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;
}