Skip to content

Commit

Permalink
Fix #488: Repeated clicking may lead to a negative loan. (#489)
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronVanGeffen committed May 25, 2020
1 parent a137181 commit fb9e14e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
7 changes: 4 additions & 3 deletions src/openloco/windows/CompanyWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{};
Expand All @@ -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;
Expand Down

0 comments on commit fb9e14e

Please sign in to comment.