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

@@ -680,9 +680,12 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
*/
static void CompanyCheckBankrupt(Company *c)
{
/* If "Infinite money" setting is on, companies should not go bankrupt. */
if (_settings_game.difficulty.infinite_money) return;
/* If the company has money again, it does not go bankrupt */
if (c->bankrupt_flags & CBRF_SALE) return;
if (c->money - c->current_loan >= -_economy.max_loan) {
if (c->money - c->current_loan >= -c->GetMaxLoan()) {
int previous_months_of_bankruptcy = CeilDiv(c->months_of_bankruptcy, 3);
c->months_of_bankruptcy = 0;
c->bankrupt_asked = 0;
@@ -952,17 +955,21 @@ static void CompaniesPayInterest()
/* Over a year the paid interest should be "loan * interest percentage",
* but... as that number is likely not dividable by 12 (pay each month),
* one needs to account for that in the monthly fee calculations.
*
* To easily calculate what one should pay "this" month, you calculate
* what (total) should have been paid up to this month and you subtract
* whatever has been paid in the previous months. This will mean one month
* it'll be a bit more and the other it'll be a bit less than the average
* monthly fee, but on average it will be exact.
*
* In order to prevent cheating or abuse (just not paying interest by not
* taking a loan we make companies pay interest on negative cash as well
* taking a loan) we make companies pay interest on negative cash as well,
* except if infinite money is enabled.
*/
Money yearly_fee = c->current_loan * _economy.interest_rate / 100;
if (c->money < 0) {
yearly_fee += -c->money *_economy.interest_rate / 100;
Money available_money = GetAvailableMoney(c->index);
if (available_money < 0) {
yearly_fee += -available_money * _economy.interest_rate / 100;
}
Money up_to_previous_month = yearly_fee * EconTime::CurMonth() / 12;
Money up_to_this_month = yearly_fee * (EconTime::CurMonth() + 1) / 12;