Fix #488: Repeated clicking may lead to a negative loan. (#489)

This commit is contained in:
Aaron van Geffen 2020-05-25 13:50:14 +02:00 committed by GitHub
parent a1371819f5
commit fb9e14e24f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View File

@ -1,3 +1,7 @@
20.05+ (???)
------------------------------------------------------------------------
- Fix: [#488] Repeated clicking may lead to a negative loan.
20.05 (2020-05-24)
------------------------------------------------------------------------
- Feature: [#77] Add "Exit OpenLoco" to the main menu.

View File

@ -1894,8 +1894,8 @@ namespace openloco::ui::windows::CompanyWindow
case widx::loan_decrease:
{
currency32_t newLoan = companymgr::get(self->number)->current_loan;
if (newLoan == 0)
auto company = companymgr::get(self->number);
if (company->current_loan == 0)
return;
currency32_t stepSize{};
@ -1906,7 +1906,8 @@ namespace openloco::ui::windows::CompanyWindow
else if (*_clickRepeatTicks >= 200)
stepSize = 100000;
newLoan -= stepSize;
auto newLoan = std::max<currency32_t>(0, company->current_loan - stepSize);
gGameCommandErrorTitle = string_ids::cant_pay_back_loan;
game_commands::do_9(newLoan);
break;