diff --git a/src/addresses.h b/src/addresses.h index 34a652bdd9..5b0b4d5cf3 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -388,9 +388,11 @@ #define RCT2_ADDRESS_PEEP_SPAWNS 0x013573F2 +#define RCT2_ADDRESS_GUEST_CHANGE_MODIFIER 0x013573FE #define RCT2_ADDRESS_CURRENT_RESEARCH_LEVEL 0x013573FF #define RCT2_ADDRESS_EXPENDITURE_TABLE 0x01357848 +#define RCT2_ADDRESS_LAST_GUESTS_IN_PARK 0x01357BC8 #define RCT2_ADDRESS_HANDYMAN_COLOUR 0x01357BCD #define RCT2_ADDRESS_MECHANIC_COLOUR 0x01357BCE #define RCT2_ADDRESS_SECURITY_COLOUR 0x01357BCF diff --git a/src/editor.c b/src/editor.c index 58e25e0cbf..4e0f050764 100644 --- a/src/editor.c +++ b/src/editor.c @@ -398,7 +398,7 @@ static int editor_read_s6(const char *path) sawyercoding_read_chunk(file, (uint8*)RCT2_ADDRESS_GUESTS_IN_PARK); // Read ? - sawyercoding_read_chunk(file, (uint8*)0x01357BC8); + sawyercoding_read_chunk(file, (uint8*)RCT2_ADDRESS_LAST_GUESTS_IN_PARK); // Read park rating sawyercoding_read_chunk(file, (uint8*)RCT2_ADDRESS_CURRENT_PARK_RATING); @@ -449,8 +449,8 @@ static int editor_read_s6(const char *path) sub_6BD3A4(); RCT2_GLOBAL(RCT2_ADDRESS_GUESTS_IN_PARK, uint16) = 0; RCT2_GLOBAL(RCT2_ADDRESS_GUESTS_HEADING_FOR_PARK, uint16) = 0; - RCT2_GLOBAL(0x01357BC8, uint16) = 0; - RCT2_GLOBAL(0x013573FE, uint16) = 0; + RCT2_GLOBAL(RCT2_ADDRESS_LAST_GUESTS_IN_PARK, uint16) = 0; + RCT2_GLOBAL(RCT2_ADDRESS_GUEST_CHANGE_MODIFIER, uint16) = 0; if (s6Header->type != S6_TYPE_SCENARIO) { research_populate_list_random(); research_remove_non_separate_vehicle_types(); diff --git a/src/management/finance.c b/src/management/finance.c index 00db151578..1de6204ec8 100644 --- a/src/management/finance.c +++ b/src/management/finance.c @@ -46,6 +46,10 @@ const money32 research_cost_table[4] = { int dword_988E60[] = { 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0 }; +money32 *gCashHistory = RCT2_ADDRESS(RCT2_ADDRESS_BALANCE_HISTORY, money32); +money32 *gWeeklyProfitHistory = RCT2_ADDRESS(RCT2_ADDRESS_WEEKLY_PROFIT_HISTORY, money32); +money32 *gParkValueHistory = RCT2_ADDRESS(RCT2_ADDRESS_PARK_VALUE_HISTORY, money32); + /** * Pay an amount of money. * rct2: 0x069C674 @@ -143,11 +147,10 @@ void finance_pay_ride_upkeep() void finance_reset_history() { - int i; - for (i = 0; i < 128; i++) { - RCT2_ADDRESS(RCT2_ADDRESS_BALANCE_HISTORY, money32)[i] = MONEY32_UNDEFINED; - RCT2_ADDRESS(RCT2_ADDRESS_WEEKLY_PROFIT_HISTORY, money32)[i] = MONEY32_UNDEFINED; - RCT2_ADDRESS(RCT2_ADDRESS_PARK_VALUE_HISTORY, money32)[i] = MONEY32_UNDEFINED; + for (int i = 0; i < 128; i++) { + gCashHistory[i] = MONEY32_UNDEFINED; + gWeeklyProfitHistory[i] = MONEY32_UNDEFINED; + gParkValueHistory[i] = MONEY32_UNDEFINED; } } diff --git a/src/management/finance.h b/src/management/finance.h index e16d04d787..16291ab7b5 100644 --- a/src/management/finance.h +++ b/src/management/finance.h @@ -48,6 +48,10 @@ enum { extern const money32 research_cost_table[4]; +extern money32 *gCashHistory; +extern money32 *gWeeklyProfitHistory; +extern money32 *gParkValueHistory; + void finance_payment(money32 amount, rct_expenditure_type type); void finance_pay_wages(); void finance_pay_research(); diff --git a/src/rct1.c b/src/rct1.c index 794507fec8..3dfd27ca60 100644 --- a/src/rct1.c +++ b/src/rct1.c @@ -198,8 +198,8 @@ void rct1_fix_landscape() ride_init_all(); RCT2_GLOBAL(RCT2_ADDRESS_GUESTS_IN_PARK, uint16) = 0; RCT2_GLOBAL(RCT2_ADDRESS_GUESTS_HEADING_FOR_PARK, uint16) = 0; - RCT2_GLOBAL(0x01357BC8, uint16) = 0; - RCT2_GLOBAL(0x013573FE, uint8) = 0; + RCT2_GLOBAL(RCT2_ADDRESS_LAST_GUESTS_IN_PARK, uint16) = 0; + RCT2_GLOBAL(RCT2_ADDRESS_GUEST_CHANGE_MODIFIER, uint8) = 0; RCT2_CALLPROC_EBPSAFE(0x0069F44B); sub_69F06A(); RCT2_CALLPROC_EBPSAFE(0x0069F143); diff --git a/src/scenario.c b/src/scenario.c index 0680d71ee0..d89609418a 100644 --- a/src/scenario.c +++ b/src/scenario.c @@ -151,7 +151,7 @@ int scenario_load(const char *path) sawyercoding_read_chunk(file, (uint8*)RCT2_ADDRESS_GUESTS_IN_PARK); // Read ? - sawyercoding_read_chunk(file, (uint8*)0x01357BC8); + sawyercoding_read_chunk(file, (uint8*)RCT2_ADDRESS_LAST_GUESTS_IN_PARK); // Read park rating sawyercoding_read_chunk(file, (uint8*)RCT2_ADDRESS_CURRENT_PARK_RATING); diff --git a/src/windows/finances.c b/src/windows/finances.c index 92eaee00ab..686cc84f04 100644 --- a/src/windows/finances.c +++ b/src/windows/finances.c @@ -866,9 +866,8 @@ static void window_finances_financial_graph_paint() // Calculate the Y axis scale (log2 of highest [+/-]balance) int yAxisScale = 0; - money32 *balanceHistory = RCT2_ADDRESS(RCT2_ADDRESS_BALANCE_HISTORY, money32); for (i = 0; i < 64; i++) { - money32 balance = balanceHistory[i]; + money32 balance = gCashHistory[i]; if (balance == MONEY32_UNDEFINED) continue; @@ -893,7 +892,7 @@ static void window_finances_financial_graph_paint() // X axis labels and values x = graphLeft + 98; y = graphTop + 17; - graph_draw_money32(dpi, balanceHistory, 64, x, y, yAxisScale, 128); + graph_draw_money32(dpi, gCashHistory, 64, x, y, yAxisScale, 128); } #pragma endregion @@ -985,9 +984,8 @@ static void window_finances_park_value_graph_paint() // Calculate the Y axis scale (log2 of highest [+/-]balance) int yAxisScale = 0; - money32 *parkValueHistory = RCT2_ADDRESS(RCT2_ADDRESS_PARK_VALUE_HISTORY, money32); for (i = 0; i < 64; i++) { - money32 balance = parkValueHistory[i]; + money32 balance = gParkValueHistory[i]; if (balance == MONEY32_UNDEFINED) continue; @@ -1012,7 +1010,7 @@ static void window_finances_park_value_graph_paint() // X axis labels and values x = graphLeft + 98; y = graphTop + 17; - graph_draw_money32(dpi, parkValueHistory, 64, x, y, yAxisScale, 0); + graph_draw_money32(dpi, gParkValueHistory, 64, x, y, yAxisScale, 0); } #pragma endregion @@ -1104,9 +1102,8 @@ static void window_finances_profit_graph_paint() // Calculate the Y axis scale (log2 of highest [+/-]balance) int yAxisScale = 0; - money32 *weeklyProfitHistory = RCT2_ADDRESS(RCT2_ADDRESS_WEEKLY_PROFIT_HISTORY, money32); for (i = 0; i < 64; i++) { - money32 balance = weeklyProfitHistory[i]; + money32 balance = gWeeklyProfitHistory[i]; if (balance == MONEY32_UNDEFINED) continue; @@ -1131,7 +1128,7 @@ static void window_finances_profit_graph_paint() // X axis labels and values x = graphLeft + 98; y = graphTop + 17; - graph_draw_money32(dpi, weeklyProfitHistory, 64, x, y, yAxisScale, 128); + graph_draw_money32(dpi, gWeeklyProfitHistory, 64, x, y, yAxisScale, 128); } #pragma endregion diff --git a/src/windows/game_bottom_toolbar.c b/src/windows/game_bottom_toolbar.c index 9789ec2a0c..b82b44e553 100644 --- a/src/windows/game_bottom_toolbar.c +++ b/src/windows/game_bottom_toolbar.c @@ -411,7 +411,7 @@ static void window_game_bottom_toolbar_draw_left_panel(rct_drawpixelinfo *dpi, r // Draw guests gfx_draw_string_centred( dpi, - STR_NUM_GUESTS + RCT2_GLOBAL(0x013573FE, uint8), + STR_NUM_GUESTS + RCT2_GLOBAL(RCT2_ADDRESS_GUEST_CHANGE_MODIFIER, uint8), x, y, (RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_OVER_WINDOWCLASS, rct_windowclass) == 2 && RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_OVER_WIDGETINDEX, sint32) == WIDX_GUESTS ? 2 : w->colours[0] & 0x7F), (void*)RCT2_ADDRESS_GUESTS_IN_PARK diff --git a/src/windows/park.c b/src/windows/park.c index 1fe32e1dcb..27318ce991 100644 --- a/src/windows/park.c +++ b/src/windows/park.c @@ -1296,7 +1296,6 @@ static void window_park_rating_paint() rct_window *w; rct_drawpixelinfo *dpi; rct_widget *widget; - uint8 *history; window_paint_get_registers(w, dpi); @@ -1317,8 +1316,7 @@ static void window_park_rating_paint() x += widget->left + 22; y += widget->top + 26; - history = RCT2_ADDRESS(RCT2_ADDRESS_PARK_RATING_HISTORY, uint8); - graph_draw_uint8(dpi, history, 32, x, y); + graph_draw_uint8(dpi, gParkRatingHistory, 32, x, y); } #pragma endregion @@ -1430,7 +1428,6 @@ static void window_park_guests_paint() rct_window *w; rct_drawpixelinfo *dpi; rct_widget *widget; - uint8 *history; window_paint_get_registers(w, dpi); @@ -1451,8 +1448,7 @@ static void window_park_guests_paint() x += widget->left + 22; y += widget->top + 26; - history = RCT2_ADDRESS(RCT2_ADDRESS_GUESTS_IN_PARK_HISTORY, uint8); - graph_draw_uint8(dpi, history, 32, x, y); + graph_draw_uint8(dpi, gGuestsInParkHistory, 32, x, y); } #pragma endregion diff --git a/src/world/park.c b/src/world/park.c index abb2dd8c19..73230f230d 100644 --- a/src/world/park.c +++ b/src/world/park.c @@ -35,6 +35,9 @@ #include "sprite.h" #include "../config.h" +uint8 *gParkRatingHistory = RCT2_ADDRESS(RCT2_ADDRESS_PARK_RATING_HISTORY, uint8); +uint8 *gGuestsInParkHistory = RCT2_ADDRESS(RCT2_ADDRESS_GUESTS_IN_PARK_HISTORY, uint8); + /** * In a difficult guest generation scenario, no guests will be generated if over this value. */ @@ -67,9 +70,9 @@ void park_init() RCT2_GLOBAL(RCT2_ADDRESS_MECHANIC_COLOUR, uint8) = 28; RCT2_GLOBAL(RCT2_ADDRESS_SECURITY_COLOUR, uint8) = 28; RCT2_GLOBAL(RCT2_ADDRESS_GUESTS_IN_PARK, uint16) = 0; - RCT2_GLOBAL(0x01357BC8, uint16) = 0; + RCT2_GLOBAL(RCT2_ADDRESS_LAST_GUESTS_IN_PARK, uint16) = 0; RCT2_GLOBAL(RCT2_ADDRESS_GUESTS_HEADING_FOR_PARK, uint16) = 0; - RCT2_GLOBAL(0x013573FE, uint16) = 0; + RCT2_GLOBAL(RCT2_ADDRESS_GUEST_CHANGE_MODIFIER, uint16) = 0; RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_PARK_RATING, uint16) = 0; _guestGenerationProbability = 0; RCT2_GLOBAL(RCT2_TOTAL_RIDE_VALUE, uint16) = 0; @@ -119,10 +122,9 @@ void park_init() */ void park_reset_history() { - int i; - for (i = 0; i < 32; i++) { - RCT2_ADDRESS(RCT2_ADDRESS_PARK_RATING_HISTORY, uint8)[i] = 255; - RCT2_ADDRESS(RCT2_ADDRESS_GUESTS_IN_PARK_HISTORY, uint8)[i] = 255; + for (int i = 0; i < 32; i++) { + gParkRatingHistory[i] = 255; + gGuestsInParkHistory[i] = 255; } } @@ -575,7 +577,55 @@ uint8 calculate_guest_initial_happiness(uint8 percentage) { */ void park_update_histories() { - RCT2_CALLPROC_EBPSAFE(0x0066A231); + int guestsInPark = RCT2_GLOBAL(RCT2_ADDRESS_GUESTS_IN_PARK, uint16); + int lastGuestsInPark = RCT2_GLOBAL(RCT2_ADDRESS_LAST_GUESTS_IN_PARK, uint16); + RCT2_GLOBAL(RCT2_ADDRESS_LAST_GUESTS_IN_PARK, uint16) = guestsInPark; + RCT2_GLOBAL(0x009A9804, uint16) |= 4; + + int changeInGuestsInPark = guestsInPark - lastGuestsInPark; + int guestChangeModifier = 1; + if (changeInGuestsInPark > -20) { + guestChangeModifier++; + if (changeInGuestsInPark < 20) + guestChangeModifier = 0; + } + RCT2_GLOBAL(RCT2_ADDRESS_GUEST_CHANGE_MODIFIER, uint8) = guestChangeModifier; + + // Update park rating history + for (int i = 31; i > 0; i--) + gParkRatingHistory[i] = gParkRatingHistory[i - 1]; + gParkRatingHistory[0] = calculate_park_rating() / 4; + window_invalidate_by_class(WC_PARK_INFORMATION); + + // Update guests in park history + for (int i = 31; i > 0; i--) + gGuestsInParkHistory[i] = gGuestsInParkHistory[i - 1]; + gGuestsInParkHistory[0] = min(guestsInPark, 5000) / 20; + window_invalidate_by_class(WC_PARK_INFORMATION); + + // Update current cash history + for (int i = 127; i > 0; i--) + gCashHistory[i] = gCashHistory[i - 1]; + gCashHistory[0] = DECRYPT_MONEY(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, money32)) - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_LOAN, money32); + window_invalidate_by_class(WC_FINANCES); + + // Update weekly profit history + money32 currentWeeklyProfit = RCT2_GLOBAL(0x01358334, money32); + if (RCT2_GLOBAL(0x01358338, uint16) != 0) + currentWeeklyProfit /= RCT2_GLOBAL(0x01358338, uint16); + + for (int i = 127; i > 0; i--) + gWeeklyProfitHistory[i] = gWeeklyProfitHistory[i - 1]; + gWeeklyProfitHistory[0] = currentWeeklyProfit; + + RCT2_GLOBAL(0x01358334, money32) = 0; + RCT2_GLOBAL(0x01358338, uint16) = 0; + window_invalidate_by_class(WC_FINANCES); + + // Update park value history + for (int i = 127; i > 0; i--) + gParkValueHistory[i] = gParkValueHistory[i - 1]; + gParkValueHistory[0] = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_PARK_VALUE, money32); } void park_set_entrance_fee(money32 value) diff --git a/src/world/park.h b/src/world/park.h index ac00a55048..aa19444e04 100644 --- a/src/world/park.h +++ b/src/world/park.h @@ -45,6 +45,9 @@ enum { PARK_FLAGS_SIX_FLAGS = (1 << 19) }; +extern uint8 *gParkRatingHistory; +extern uint8 *gGuestsInParkHistory; + int park_is_open(); void park_init(); void park_reset_history();