MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / CmdIncreaseLoan

Function CmdIncreaseLoan

src/misc_cmd.cpp:39–74  ·  view source on GitHub ↗

* Increase the loan of your company. * @param flags operation to perform * @param cmd when LoanCommand::Interval: loans LOAN_INTERVAL, * when LoanCommand::Max: loans the maximum loan permitting money (press CTRL), * when LoanCommand::Amount: loans the amount specified in \c amount * @param amount amount to increase the loan with, multitude of LOAN_INTERVAL. Only used whe

Source from the content-addressed store, hash-verified

37 * @return the cost of this operation or an error
38 */
39CommandCost CmdIncreaseLoan(DoCommandFlags flags, LoanCommand cmd, Money amount)
40{
41 Company *c = Company::Get(_current_company);
42 Money max_loan = c->GetMaxLoan();
43 if (c->current_loan >= max_loan) {
44 return CommandCostWithParam(STR_ERROR_MAXIMUM_PERMITTED_LOAN, max_loan);
45 }
46
47 Money loan;
48 switch (cmd) {
49 default: return CMD_ERROR; // Invalid method
50 case LoanCommand::Interval: // Take some extra loan
51 loan = LOAN_INTERVAL;
52 break;
53 case LoanCommand::Max: // Take a loan as big as possible
54 loan = max_loan - c->current_loan;
55 break;
56 case LoanCommand::Amount: // Take the given amount of loan
57 loan = amount;
58 if (loan < LOAN_INTERVAL || c->current_loan + loan > max_loan || loan % LOAN_INTERVAL != 0) return CMD_ERROR;
59 break;
60 }
61
62 /* In case adding the loan triggers the overflow protection of Money,
63 * we would essentially be losing money as taking and repaying the loan
64 * immediately would not get us back to the same bank balance anymore. */
65 if (c->money > Money::max() - loan) return CMD_ERROR;
66
67 if (flags.Test(DoCommandFlag::Execute)) {
68 c->money += loan;
69 c->current_loan += loan;
70 InvalidateCompanyWindows(c);
71 }
72
73 return CommandCost(EXPENSES_OTHER);
74}
75
76/**
77 * Decrease the loan of your company.

Callers

nothing calls this directly

Calls 5

InvalidateCompanyWindowsFunction · 0.85
CommandCostClass · 0.85
GetMaxLoanMethod · 0.80
TestMethod · 0.80
CommandCostWithParamFunction · 0.70

Tested by

no test coverage detected