From aef83362bc8aeabee3f874118cf90a1bece02d1d Mon Sep 17 00:00:00 2001 From: Maciek Baron Date: Tue, 6 May 2014 22:04:09 +0100 Subject: [PATCH] Cleaning up small shared functions Cleaning up small shared functions and moving them to appropriate files --- src/addresses.h | 4 ++ src/audio.c | 22 +++++++++ src/audio.h | 2 + src/editor.c | 98 ++++------------------------------------ src/editor.h | 5 -- src/finance.c | 37 +++++++++++++++ src/finance.h | 1 + src/game.c | 12 ++--- src/park.c | 15 ++++++ src/park.h | 1 + src/rct2.c | 8 ++-- src/strings.c | 10 ++++ src/strings.h | 1 + src/title.c | 9 ++-- src/window.c | 24 ++++++++++ src/window.h | 3 ++ src/window_save_prompt.c | 5 +- 17 files changed, 147 insertions(+), 110 deletions(-) diff --git a/src/addresses.h b/src/addresses.h index a453f9c7bd..0182a37ad5 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -215,6 +215,10 @@ #define RCT2_ADDRESS_NEW_WINDOW_PTR 0x014234B8 #define RCT2_ADDRESS_VIEWPORT_LIST 0x014234BC #define RCT2_ADDRESS_NEW_VIEWPORT_PTR 0x01423570 +#define RCT2_ADDRESS_WINDOW_GUEST_LIST_SELECTED_FILTER 0x00F1EE06 +#define RCT2_ADDRESS_WINDOW_GUEST_LIST_SELECTED_TAB 0x00F1EE12 +#define RCT2_ADDRESS_WINDOW_GUEST_LIST_SELECTED_VIEW 0x00F1EE13 + #define RCT2_ADDRESS_OS_TIME_MINUTE 0x01424654 #define RCT2_ADDRESS_OS_TIME_HOUR 0x01424656 diff --git a/src/audio.c b/src/audio.c index 468ff26d08..20925d1a25 100644 --- a/src/audio.c +++ b/src/audio.c @@ -20,6 +20,7 @@ #include "audio.h" #include "addresses.h" +#include "rct2.h" void get_dsound_devices() { @@ -45,3 +46,24 @@ void sound_stop(rct_sound* sound) { RCT2_CALLPROC_1(0x00404DD8, rct_sound*, sound); } + +/** +* +* rct2: 0x006BABB4 +*/ +void pause_sounds() { + if (++RCT2_GLOBAL(0x009AF59C, uint8) == 1) { + RCT2_CALLPROC_EBPSAFE(0x006BCAE5); + RCT2_CALLPROC_EBPSAFE(0x006BABDF); + RCT2_CALLPROC_EBPSAFE(0x006BCA9F); + RCT2_CALLPROC_EBPSAFE(0x006BD07F); + } +} + +/** +* +* rct2: 0x006BABD8 +*/ +void unpause_sounds() { + RCT2_GLOBAL(0x009AF59C, uint8)--; +} \ No newline at end of file diff --git a/src/audio.h b/src/audio.h index bb82236c96..2f5f9981ae 100644 --- a/src/audio.h +++ b/src/audio.h @@ -48,6 +48,8 @@ int sound_prepare(int sound_id, rct_sound *sound, int var_8, int var_c); void sound_play_panned(int sound_id, int x); int sound_play(rct_sound* sound, int looping, int volume, int pan, int frequency); void sound_stop(rct_sound *sound); +void pause_sounds(); +void unpause_sounds(); typedef enum { RCT2_SOUND_SCREAM = 11, diff --git a/src/editor.c b/src/editor.c index 31e77b4229..766bb8da6f 100644 --- a/src/editor.c +++ b/src/editor.c @@ -29,6 +29,9 @@ #include "ride.h" #include "window.h" #include "viewport.h" +#include "finance.h" +#include "audio.h" +#include "strings.h" static void set_all_land_owned(); @@ -49,12 +52,12 @@ void editor_load() reset_saved_strings(); RCT2_CALLPROC_EBPSAFE(0x0069EB13); // sprites_init ride_init_all(); - RCT2_CALLPROC_EBPSAFE(0x0068F083); // window_guest_list_init_vars_a + window_guest_list_init_vars_a(); RCT2_CALLPROC_EBPSAFE(0x006BD3A4); park_init(); finance_init(); date_reset(); - RCT2_CALLPROC_EBPSAFE(0x0068F050); // window_guest_list_init_vars_b + window_guest_list_init_vars_b(); RCT2_CALLPROC_EBPSAFE(0x006BD39C); RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) = SCREEN_FLAGS_SCENARIO_EDITOR; RCT2_GLOBAL(0x0141F570, uint8) = 0; @@ -98,12 +101,12 @@ void trackdesigner_load() reset_saved_strings(); RCT2_CALLPROC_EBPSAFE(0x0069EB13); // reset_sprites ride_init_all(); - RCT2_CALLPROC_EBPSAFE(0x0068F083); // window_guest_list_init_vars_a + window_guest_list_init_vars_a(); RCT2_CALLPROC_EBPSAFE(0x006BD3A4); park_init(); finance_init(); date_reset(); - RCT2_CALLPROC_EBPSAFE(0x0068F050); // window_guest_list_init_vars_b + window_guest_list_init_vars_b(); RCT2_CALLPROC_EBPSAFE(0x006BD39C); RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) = SCREEN_FLAGS_TRACK_DESIGNER; RCT2_GLOBAL(0x0141F570, uint8) = 0; @@ -136,12 +139,12 @@ void trackmanager_load() reset_saved_strings(); RCT2_CALLPROC_EBPSAFE(0x0069EB13); // reset_sprites ride_init_all(); - RCT2_CALLPROC_EBPSAFE(0x0068F083); // window_guest_list_init_vars_a + window_guest_list_init_vars_a(); RCT2_CALLPROC_EBPSAFE(0x006BD3A4); park_init(); finance_init(); date_reset(); - RCT2_CALLPROC_EBPSAFE(0x0068F050); // window_guest_list_init_vars_b + window_guest_list_init_vars_b(); RCT2_CALLPROC_EBPSAFE(0x006BD39C); RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) = SCREEN_FLAGS_TRACK_MANAGER; RCT2_GLOBAL(0x0141F570, uint8) = 0; @@ -167,87 +170,4 @@ static void set_all_land_owned() int mapSize = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, sint16); game_do_command(64, 1, 64, 2, 56, (mapSize - 2) * 32, (mapSize - 2) * 32); -} - -/** -* -* rct2: 0x00667104 -*/ -void reset_park_entrances() { - RCT2_GLOBAL(0x013573D4, uint16) = 0; - - for (short i = 0; i < 4; i++) { - RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_X, uint16)[i] = 0x8000; - } - - RCT2_GLOBAL(0x013573F2, uint16) = 0xFFFF; - RCT2_GLOBAL(0x013573F8, uint16) = 0xFFFF; -} - -/** -* -* rct2: 0x006C4209 -*/ -void reset_saved_strings() { - for (int i = 0; i < 1024; i++) { - RCT2_ADDRESS(0x135A8F4, uint8)[i * 32] = 0; - } -} - -/** -* -* rct2: 0x006BABB4 -*/ -void pause_sounds() { - if (++RCT2_GLOBAL(0x009AF59C, uint8) == 1) { - RCT2_CALLPROC_EBPSAFE(0x006BCAE5); - RCT2_CALLPROC_EBPSAFE(0x006BABDF); - RCT2_CALLPROC_EBPSAFE(0x006BCA9F); - RCT2_CALLPROC_EBPSAFE(0x006BD07F); - } -} - -/** -* -* rct2: 0x006BABD8 -*/ -void unpause_sounds() { - RCT2_GLOBAL(0x009AF59C, uint8)--; -} - -/** -* -* rct2: 0x0069DEFB -*/ -void finance_init() { - - for (short i = 0; i < 56; i++) { - RCT2_ADDRESS(0x01357848, uint32)[i] = 0; - } - - RCT2_GLOBAL(0x0135832C, uint32) = 0; - - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_PROFIT, uint32) = 0; - - RCT2_GLOBAL(0x01358334, uint32) = 0; - RCT2_GLOBAL(0x01358338, uint16) = 0; - - RCT2_GLOBAL(0x013573DC, uint32) = 100000; - - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, sint32) = ENCRYPT_MONEY(100000); - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_LOAN, sint32) = 100000; - RCT2_GLOBAL(RCT2_ADDRESS_MAXIMUM_LOAN, uint32) = 200000; - - RCT2_GLOBAL(0x013587D0, uint32) = 0; - - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_INTEREST_RATE, uint8) = 10; - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_PARK_VALUE, sint32) = 0; - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_COMPANY_VALUE, sint32) = 0; - RCT2_GLOBAL(RCT2_ADDRESS_COMPLETED_COMPANY_VALUE, sint32) = 0x80000000; - RCT2_GLOBAL(RCT2_ADDRESS_TOTAL_ADMISSIONS, uint32) = 0; - RCT2_GLOBAL(RCT2_ADDRESS_INCOME_FROM_ADMISSIONS, uint32) = 0; - - RCT2_GLOBAL(0x013587D8, uint16) = 0x3F; - - RCT2_CALLPROC_EBPSAFE(0x0069E869); } \ No newline at end of file diff --git a/src/editor.h b/src/editor.h index d350e8a24f..34a7ef5ab3 100644 --- a/src/editor.h +++ b/src/editor.h @@ -25,10 +25,5 @@ void editor_load(); void editor_convert_save_to_scenario(); void trackdesigner_load(); void trackmanager_load(); -void reset_park_entrances(); -void reset_saved_strings(); -void pause_sounds(); -void unpause_sounds(); -void finance_init(); #endif diff --git a/src/finance.c b/src/finance.c index 37c4a14d60..b011b4ccec 100644 --- a/src/finance.c +++ b/src/finance.c @@ -101,3 +101,40 @@ void finance_pay_interest() finance_payment((sint32)tempcost, RCT_EXPENDITURE_TYPE_INTEREST); } + +/** +* +* rct2: 0x0069DEFB +*/ +void finance_init() { + + for (short i = 0; i < 56; i++) { + RCT2_ADDRESS(0x01357848, uint32)[i] = 0; + } + + RCT2_GLOBAL(0x0135832C, uint32) = 0; + + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_PROFIT, uint32) = 0; + + RCT2_GLOBAL(0x01358334, uint32) = 0; + RCT2_GLOBAL(0x01358338, uint16) = 0; + + RCT2_GLOBAL(0x013573DC, uint32) = 100000; + + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, sint32) = ENCRYPT_MONEY(100000); + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_LOAN, sint32) = 100000; + RCT2_GLOBAL(RCT2_ADDRESS_MAXIMUM_LOAN, uint32) = 200000; + + RCT2_GLOBAL(0x013587D0, uint32) = 0; + + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_INTEREST_RATE, uint8) = 10; + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_PARK_VALUE, sint32) = 0; + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_COMPANY_VALUE, sint32) = 0; + RCT2_GLOBAL(RCT2_ADDRESS_COMPLETED_COMPANY_VALUE, sint32) = 0x80000000; + RCT2_GLOBAL(RCT2_ADDRESS_TOTAL_ADMISSIONS, uint32) = 0; + RCT2_GLOBAL(RCT2_ADDRESS_INCOME_FROM_ADMISSIONS, uint32) = 0; + + RCT2_GLOBAL(0x013587D8, uint16) = 0x3F; + + RCT2_CALLPROC_EBPSAFE(0x0069E869); +} \ No newline at end of file diff --git a/src/finance.h b/src/finance.h index 6c8d75fdfa..4a81abe34f 100644 --- a/src/finance.h +++ b/src/finance.h @@ -36,5 +36,6 @@ void finance_payment(int amount, rct_expenditure_type type); void finance_pay_wages(); void finance_pay_research(); void finance_pay_interest(); +void finance_init(); #endif \ No newline at end of file diff --git a/src/game.c b/src/game.c index c20491046e..a68cd91245 100644 --- a/src/game.c +++ b/src/game.c @@ -1097,9 +1097,9 @@ static void game_pause_toggle() RCT2_GLOBAL(0x009DEA6E, uint32) ^= 1; window_invalidate_by_id(WC_TOP_TOOLBAR, 0); if (RCT2_GLOBAL(0x009DEA6E, uint32) & 1) - RCT2_CALLPROC_EBPSAFE(0x006BABB4); // pause_sounds + pause_sounds(); else - RCT2_CALLPROC_EBPSAFE(0x006BABD8); // unpause_sounds + unpause_sounds(); } __asm mov ebx, 0 @@ -1147,9 +1147,9 @@ static int open_landscape_file_dialog() format_string(0x0141ED68, STR_LOAD_LANDSCAPE_DIALOG_TITLE, 0); strcpy(0x0141EF68, RCT2_ADDRESS_LANDSCAPES_PATH); format_string(0x0141EE68, STR_RCT2_LANDSCAPE_FILE, 0); - RCT2_CALLPROC_EBPSAFE(0x006BABB4); // pause_sounds + pause_sounds(); osinterface_open_common_file_dialog(1, 0x0141ED68, 0x0141EF68, "*.SV6;*.SV4;*.SC6", 0x0141EE68); - RCT2_CALLPROC_EBPSAFE(0x006BABD8); // unpause_sounds + unpause_sounds(); // window_proc } @@ -1162,9 +1162,9 @@ static int open_load_game_dialog() format_string(0x0141ED68, STR_LOAD_GAME_DIALOG_TITLE, 0); strcpy(0x0141EF68, RCT2_ADDRESS_SAVED_GAMES_PATH); format_string(0x0141EE68, STR_RCT2_SAVED_GAME, 0); - RCT2_CALLPROC_EBPSAFE(0x006BABB4); // pause_sounds + pause_sounds(); osinterface_open_common_file_dialog(1, 0x0141ED68, 0x0141EF68, "*.SV6", 0x0141EE68); - RCT2_CALLPROC_EBPSAFE(0x006BABD8); // unpause_sounds + unpause_sounds(); // window_proc } diff --git a/src/park.c b/src/park.c index a8f5a90f37..7edfe1679b 100644 --- a/src/park.c +++ b/src/park.c @@ -273,3 +273,18 @@ int calculate_company_value() return result; } + +/** +* +* rct2: 0x00667104 +*/ +void reset_park_entrances() { + RCT2_GLOBAL(0x013573D4, uint16) = 0; + + for (short i = 0; i < 4; i++) { + RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_X, uint16)[i] = 0x8000; + } + + RCT2_GLOBAL(0x013573F2, uint16) = 0xFFFF; + RCT2_GLOBAL(0x013573F8, uint16) = 0xFFFF; +} diff --git a/src/park.h b/src/park.h index 287729ac6f..ee91fa5b46 100644 --- a/src/park.h +++ b/src/park.h @@ -74,5 +74,6 @@ int park_calculate_size(); int calculate_park_rating(); int calculate_park_value(); int calculate_company_value(); +void reset_park_entrances(); #endif diff --git a/src/rct2.c b/src/rct2.c index 25b51bc217..24ea502be0 100644 --- a/src/rct2.c +++ b/src/rct2.c @@ -123,11 +123,11 @@ void rct2_init() viewport_init_all(); news_item_init_queue(); get_local_time(); - RCT2_CALLPROC_EBPSAFE(0x00667104); - RCT2_CALLPROC_EBPSAFE(0x006C4209); + reset_park_entrances(); + reset_saved_strings(); RCT2_CALLPROC_EBPSAFE(0x0069EB13); ride_init_all(); - RCT2_CALLPROC_EBPSAFE(0x0068F083); // window guest list init vars a + window_guest_list_init_vars_a(); RCT2_CALLPROC_EBPSAFE(0x006BD3A4); map_init(); park_init(); @@ -136,7 +136,7 @@ void rct2_init() climate_reset(CLIMATE_COOL_AND_WET); RCT2_CALLPROC_EBPSAFE(0x006DFEE4); RCT2_CALLPROC_EBPSAFE(0x006ACA58); - RCT2_CALLPROC_EBPSAFE(0x0068F050); // window guest list init vars b + window_guest_list_init_vars_b(); RCT2_CALLPROC_EBPSAFE(0x006BD39C); title_load(); diff --git a/src/strings.c b/src/strings.c index c26db5a171..540e644252 100644 --- a/src/strings.c +++ b/src/strings.c @@ -124,3 +124,13 @@ void generate_string_file() fclose(f); } + +/** +* +* rct2: 0x006C4209 +*/ +void reset_saved_strings() { + for (int i = 0; i < 1024; i++) { + RCT2_ADDRESS(0x135A8F4, uint8)[i * 32] = 0; + } +} \ No newline at end of file diff --git a/src/strings.h b/src/strings.h index 3afedf5f26..1e9f80a450 100644 --- a/src/strings.h +++ b/src/strings.h @@ -25,6 +25,7 @@ typedef unsigned short rct_string_id; void format_string(char *dest, rct_string_id format, void *args); void generate_string_file(); +void reset_saved_strings(); enum { FORMAT_TINYFONT = 7, diff --git a/src/title.c b/src/title.c index 17cc541e60..db3b8e7baa 100644 --- a/src/title.c +++ b/src/title.c @@ -34,6 +34,7 @@ #include "scenario.h" #include "strings.h" #include "viewport.h" +#include "editor.h" static const int gOldMusic = 0; static const int gRandomShowcase = 0; @@ -91,11 +92,11 @@ void title_load() RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) = SCREEN_FLAGS_TITLE_DEMO; - RCT2_CALLPROC_EBPSAFE(0x00667104); - RCT2_CALLPROC_EBPSAFE(0x006C4209); + reset_park_entrances(); + reset_saved_strings(); RCT2_CALLPROC_EBPSAFE(0x0069EB13); ride_init_all(); - RCT2_CALLPROC_EBPSAFE(0x0068F083); // window_guest_list_init_vars_a + window_guest_list_init_vars_a(); RCT2_CALLPROC_EBPSAFE(0x006BD3A4); map_init(); park_init(); @@ -103,7 +104,7 @@ void title_load() RCT2_CALLPROC_X(0x006C45ED, 0, 0, 0, 0, 0, 0, 0); RCT2_CALLPROC_EBPSAFE(0x006DFEE4); RCT2_CALLPROC_EBPSAFE(0x006ACA58); - RCT2_CALLPROC_EBPSAFE(0x0068F050); // window_guest_list_init_vars_b + window_guest_list_init_vars_b(); RCT2_CALLPROC_EBPSAFE(0x006BD39C); RCT2_CALLPROC_EBPSAFE(0x0068AFFD); RCT2_CALLPROC_EBPSAFE(0x0069EBE4); diff --git a/src/window.c b/src/window.c index a1644e98c8..0a7f726040 100644 --- a/src/window.c +++ b/src/window.c @@ -1179,4 +1179,28 @@ void tool_cancel() RCT2_CALLPROC_X(w->event_handlers[WE_TOOL_ABORT], 0, 0, 0, RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WIDGETINDEX, uint16), w, 0, 0); } } +} + +/** +* +* rct2: 0x0068F083 +*/ +void window_guest_list_init_vars_a() { + RCT2_GLOBAL(0x013B0E6C, uint32) = 1; + RCT2_GLOBAL(0x00F1AF1C, uint32) = 0xFFFFFFFF; + RCT2_GLOBAL(0x00F1EE02, uint32) = 0xFFFFFFFF; + RCT2_GLOBAL(RCT2_ADDRESS_WINDOW_GUEST_LIST_SELECTED_FILTER, uint8) = 0xFF; +} + +/** +* +* rct2: 0x0068F050 +*/ +void window_guest_list_init_vars_b() { + RCT2_GLOBAL(RCT2_ADDRESS_WINDOW_GUEST_LIST_SELECTED_TAB, uint8) = 0; + RCT2_GLOBAL(RCT2_ADDRESS_WINDOW_GUEST_LIST_SELECTED_VIEW, uint8) = 0; + RCT2_GLOBAL(0x00F1AF1C, uint32) = 0xFFFFFFFF; + RCT2_GLOBAL(0x00F1EE02, uint32) = 0xFFFFFFFF; + RCT2_GLOBAL(RCT2_ADDRESS_WINDOW_GUEST_LIST_SELECTED_FILTER, uint8) = 0xFF; + RCT2_GLOBAL(0x00F1AF20, uint16) = 0; } \ No newline at end of file diff --git a/src/window.h b/src/window.h index c5d432e2ef..1aefaf65e4 100644 --- a/src/window.h +++ b/src/window.h @@ -347,4 +347,7 @@ void window_park_objective_open(); void window_ride_list_open(); void window_cheats_open(); +void window_guest_list_init_vars_a(); +void window_guest_list_init_vars_b(); + #endif diff --git a/src/window_save_prompt.c b/src/window_save_prompt.c index 35c95a7797..3978cc1154 100644 --- a/src/window_save_prompt.c +++ b/src/window_save_prompt.c @@ -26,6 +26,7 @@ #include "tutorial.h" #include "widget.h" #include "window.h" +#include "audio.h" static enum WINDOW_SAVE_PROMPT_WIDGET_IDX { WIDX_BACKGROUND, @@ -118,7 +119,7 @@ void window_save_prompt_open() // Pause the game RCT2_GLOBAL(0x009DEA6E, uint8) |= 2; - RCT2_CALLPROC_EBPSAFE(0x006BABB4); + pause_sounds(); window_invalidate_by_id(0x80 | WC_TOP_TOOLBAR, 0); } @@ -161,7 +162,7 @@ static void window_save_prompt_close() { // Unpause the game RCT2_GLOBAL(0x009DEA6E, uint8) &= ~2; - RCT2_CALLPROC_EBPSAFE(0x006BABD8); + unpause_sounds(); window_invalidate_by_id(0x80 | WC_TOP_TOOLBAR, 0); }