Fix #19475: Cannot increase loan when in debt (#19478)

* Small refactor of ParkSetLoanAction

* Fix #19475: Cannot increase loan when in debt
This commit is contained in:
Michael Steenbeek 2023-02-28 21:34:18 +01:00 committed by GitHub
parent d18de99579
commit 0674d9527c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View File

@ -53,6 +53,7 @@
- Fix: [#19379] “No platforms” station style shows platforms on the Junior Roller Coaster.
- Fix: [#19380] Startup crash when no sequences are installed and random sequences are enabled.
- Fix: [#19391] String corruption caused by an improper buffer handling in GfxWrapString.
- Fix: [#19475] Cannot increase loan when more than £1000 in debt.
0.4.3 (2022-12-14)
------------------------------------------------------------------------

View File

@ -40,19 +40,19 @@ void ParkSetLoanAction::Serialise(DataSerialiser& stream)
GameActions::Result ParkSetLoanAction::Query() const
{
auto currentLoan = gBankLoan;
auto loanDifference = currentLoan - _value;
if (_value > currentLoan && _value > gMaxBankLoan)
if (_value > gBankLoan && _value > gMaxBankLoan)
{
return GameActions::Result(
GameActions::Status::Disallowed, STR_CANT_BORROW_ANY_MORE_MONEY, STR_BANK_REFUSES_TO_INCREASE_LOAN);
}
// FIXME: use money64 literal once it is implemented
if (_value < currentLoan && _value < 0)
if (_value < gBankLoan && _value < 0.00_GBP)
{
return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_PAY_BACK_LOAN, STR_LOAN_CANT_BE_NEGATIVE);
}
if (loanDifference > gCash)
// The “isPayingBack” check is needed to allow increasing the loan when the player is in debt.
const auto isPayingBack = gBankLoan > _value;
const auto amountToPayBack = gBankLoan - _value;
if (isPayingBack && amountToPayBack > gCash)
{
return GameActions::Result(
GameActions::Status::InsufficientFunds, STR_CANT_PAY_BACK_LOAN, STR_NOT_ENOUGH_CASH_AVAILABLE);