From 5cb25c390f67b770f7b7b18efd63fd3661453285 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sat, 23 Apr 2016 02:06:56 +0100 Subject: [PATCH] add global macro: gBankLoanInterestRate --- src/editor.c | 6 +----- src/management/finance.c | 4 ++-- src/management/finance.h | 1 + src/windows/editor_scenario_options.c | 18 +++++++++--------- src/windows/finances.c | 2 +- 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/editor.c b/src/editor.c index 2f9f774803..9b2cd4b501 100644 --- a/src/editor.c +++ b/src/editor.c @@ -472,11 +472,7 @@ static void editor_clear_map_for_editing() MONEY(5000000,00) ); - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_INTEREST_RATE, uint8) = clamp( - 5, - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_INTEREST_RATE, uint8), - 80 - ); + gBankLoanInterestRate = clamp(5, gBankLoanInterestRate, 80); } climate_reset(RCT2_GLOBAL(RCT2_ADDRESS_CLIMATE, uint8)); diff --git a/src/management/finance.c b/src/management/finance.c index 0a20038cbf..fccd42ab72 100644 --- a/src/management/finance.c +++ b/src/management/finance.c @@ -110,7 +110,7 @@ void finance_pay_research() void finance_pay_interest() { money32 current_loan = gBankLoan; - sint16 current_interest = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_INTEREST_RATE, sint16); + sint16 current_interest = gBankLoanInterestRate; money32 tempcost = (current_loan * 5 * current_interest) >> 14; // (5 * interest) / 2^14 is pretty close to if (gParkFlags & PARK_FLAGS_NO_MONEY) @@ -183,7 +183,7 @@ void finance_init() { RCT2_GLOBAL(0x013587D0, uint32) = 0; - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_INTEREST_RATE, uint8) = 10; + gBankLoanInterestRate = 10; gParkValue = 0; gCompanyValue = 0; RCT2_GLOBAL(RCT2_ADDRESS_COMPLETED_COMPANY_VALUE, money32) = MONEY32_UNDEFINED; diff --git a/src/management/finance.h b/src/management/finance.h index 55d3966df1..79b9780e06 100644 --- a/src/management/finance.h +++ b/src/management/finance.h @@ -48,6 +48,7 @@ enum { #define gCashEncrypted RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, money32) #define gBankLoan RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_LOAN, money32) +#define gBankLoanInterestRate RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_INTEREST_RATE, sint8) extern const money32 research_cost_table[4]; diff --git a/src/windows/editor_scenario_options.c b/src/windows/editor_scenario_options.c index 71d4700343..744615ef09 100644 --- a/src/windows/editor_scenario_options.c +++ b/src/windows/editor_scenario_options.c @@ -542,11 +542,11 @@ static void window_editor_scenario_options_financial_mousedown(int widgetIndex, window_invalidate(w); break; case WIDX_INTEREST_RATE_INCREASE: - if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_INTEREST_RATE, money32) < 80) { - if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_INTEREST_RATE, money32) < 0) { - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_INTEREST_RATE, money32) = 0; + if (gBankLoanInterestRate < 80) { + if (gBankLoanInterestRate < 0) { + gBankLoanInterestRate = 0; } else { - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_INTEREST_RATE, money32)++; + gBankLoanInterestRate++; } } else { window_error_open(3254, STR_NONE); @@ -554,11 +554,11 @@ static void window_editor_scenario_options_financial_mousedown(int widgetIndex, window_invalidate(w); break; case WIDX_INTEREST_RATE_DECREASE: - if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_INTEREST_RATE, money32) > 0) { - if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_INTEREST_RATE, money32) > 80) { - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_INTEREST_RATE, money32) = 80; + if (gBankLoanInterestRate > 0) { + if (gBankLoanInterestRate > 80) { + gBankLoanInterestRate = 80; } else { - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_INTEREST_RATE, money32)--; + gBankLoanInterestRate--; } } else { window_error_open(3255, STR_NONE); @@ -685,7 +685,7 @@ static void window_editor_scenario_options_financial_paint(rct_window *w, rct_dr x = w->x + w->widgets[WIDX_INTEREST_RATE].left + 1; y = w->y + w->widgets[WIDX_INTEREST_RATE].top; - money16 interestRate = (money16)clamp(INT16_MIN, RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_INTEREST_RATE, money32), INT16_MAX); + money16 interestRate = (money16)clamp(INT16_MIN, gBankLoanInterestRate, INT16_MAX); gfx_draw_string_left(dpi, 3247, &interestRate, 0, x, y); } } diff --git a/src/windows/finances.c b/src/windows/finances.c index f553dbe74a..02094866c0 100644 --- a/src/windows/finances.c +++ b/src/windows/finances.c @@ -734,7 +734,7 @@ static void window_finances_summary_paint(rct_window *w, rct_drawpixelinfo *dpi) // Loan and interest rate gfx_draw_string_left(dpi, STR_FINANCES_SUMMARY_LOAN, NULL, 0, w->x + 4, w->y + 229); - RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS, uint16) = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_INTEREST_RATE, uint8); + RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS, uint16) = gBankLoanInterestRate; gfx_draw_string_left(dpi, STR_FINANCES_SUMMARY_AT_X_PER_YEAR, (void*)RCT2_ADDRESS_COMMON_FORMAT_ARGS, 0, w->x + 156, w->y + 229); // Current cash