From ff8bef8fc3a608743014a9dc7e36a9804c74ef7f Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sat, 21 Feb 2015 02:04:33 +0000 Subject: [PATCH] try to fix to scenario complete issues --- data/language/english_uk.txt | 2 +- src/scenario.c | 82 +++++++++++++++++++++--------------- src/scenario.h | 2 + src/util/util.c | 22 ++++++++++ src/util/util.h | 2 + src/windows/cheats.c | 20 ++++++--- 6 files changed, 88 insertions(+), 42 deletions(-) diff --git a/data/language/english_uk.txt b/data/language/english_uk.txt index 5f48a2dda5..c54554b3d2 100644 --- a/data/language/english_uk.txt +++ b/data/language/english_uk.txt @@ -2769,7 +2769,7 @@ STR_2762 :Pay For Rides STR_2763 :??? STR_2764 :Happy Guests STR_2765 :Large Tram -STR_2766 :??? +STR_2766 :Win scenario STR_2767 :Freeze Climate STR_2768 :Unfreeze Climate STR_2769 :Open Park diff --git a/src/scenario.c b/src/scenario.c index 6005c1cae6..7609e3d68c 100644 --- a/src/scenario.c +++ b/src/scenario.c @@ -39,6 +39,9 @@ #include "world/park.h" #include "world/sprite.h" +static char _scenarioPath[MAX_PATH]; +static const char *_scenarioFileName; + static int scenario_create_ducks(); /** @@ -210,6 +213,9 @@ int scenario_load_and_play_from_path(const char *path) if (!scenario_load(path)) return 0; + strcpy(_scenarioPath, path); + _scenarioFileName = path_get_filename(_scenarioPath); + log_verbose("starting scenario, %s", path); RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) = SCREEN_FLAGS_PLAYING; @@ -351,18 +357,20 @@ void scenario_end() window_park_objective_open(); } -/* -* rct2: 0x0066A752 -**/ +/** + * + * rct2: 0x0066A752 + **/ void scenario_failure() { RCT2_GLOBAL(RCT2_ADDRESS_COMPLETED_COMPANY_VALUE, uint32) = 0x80000001; scenario_end(); } -/* - * rct2: 0x0066A75E - **/ +/** + * + * rct2: 0x0066A75E + */ void scenario_success() { int i; @@ -373,18 +381,19 @@ void scenario_success() peep_applause(); for (i = 0; i < gScenarioListCount; i++) { - char *cur_scenario_name = RCT2_ADDRESS(0x135936C, char); scenario = &gScenarioList[i]; - if (0 == strncmp(cur_scenario_name, scenario->path, 256)){ - if (scenario->flags & SCENARIO_FLAGS_COMPLETED && scenario->company_value < current_val) - break; // not a new high score -> no glory + if (strequals(scenario->path, _scenarioFileName, 256, true)) { + // Check if record company value has been broken + if ((scenario->flags & SCENARIO_FLAGS_COMPLETED) && scenario->company_value >= current_val) + break; + // Allow name entry RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) |= PARK_FLAGS_SCENARIO_COMPLETE_NAME_INPUT; scenario->company_value = current_val; scenario->flags |= SCENARIO_FLAGS_COMPLETED; scenario->completed_by[0] = 0; - RCT2_GLOBAL(0x013587C0, uint32) = current_val; // value used in window for score? + RCT2_GLOBAL(0x013587C0, uint32) = current_val; scenario_scores_save(); break; } @@ -392,6 +401,33 @@ void scenario_success() scenario_end(); } +/** + * + * rct2: 0x006695E8 + */ +void scenario_success_submit_name(const char *name) +{ + int i; + rct_scenario_basic* scenario; + uint32 scenarioWinCompanyValue; + + for (i = 0; i < gScenarioListCount; i++) { + scenario = &gScenarioList[i]; + + if (strequals(scenario->path, _scenarioFileName, 256, true)) { + scenarioWinCompanyValue = RCT2_GLOBAL(0x013587C0, uint32); + if (scenario->company_value == scenarioWinCompanyValue) { + strncpy(scenario->completed_by, name, 64); + strncpy((char*)0x013587D8, name, 32); + scenario_scores_save(); + } + break; + } + } + + RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) &= ~PARK_FLAGS_SCENARIO_COMPLETE_NAME_INPUT; +} + /** * Checks if there are 10 rollercoasters of different subtype with * excitement >= 600 . @@ -1061,27 +1097,3 @@ int scenario_save(char *path, int flags) RCT2_GLOBAL(0x009DEA66, uint16) = 0; return 1; } - -void scenario_success_submit_name(const char *name) -{ - int i; - rct_scenario_basic* scenario; - uint32 scenarioWinCompanyValue; - - for (i = 0; i < gScenarioListCount; i++) { - char *cur_scenario_name = RCT2_ADDRESS(0x135936C, char); - scenario = &gScenarioList[i]; - - if (strncmp(cur_scenario_name, scenario->path, 256) == 0) { - scenarioWinCompanyValue = RCT2_GLOBAL(0x013587C0, uint32); - if (scenario->company_value == scenarioWinCompanyValue) { - strncpy(scenario->completed_by, name, 64); - strncpy((char*)0x013587D8, name, 32); - scenario_scores_save(); - } - break; - } - } - - RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) &= ~PARK_FLAGS_SCENARIO_COMPLETE_NAME_INPUT; -} diff --git a/src/scenario.h b/src/scenario.h index 33c1cb9433..1e07ac6372 100644 --- a/src/scenario.h +++ b/src/scenario.h @@ -407,6 +407,8 @@ void scenario_update(); unsigned int scenario_rand(); int scenario_prepare_for_save(); int scenario_save(char *path, int flags); +void scenario_failure(); +void scenario_success(); void scenario_success_submit_name(const char *name); #endif diff --git a/src/util/util.c b/src/util/util.c index dffbb8a5ee..8c63b6b471 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -41,6 +41,21 @@ int mph_to_kmph(int mph) return (mph * 1648) / 1024; } +const char *path_get_filename(const char *path) +{ + const char *result, *ch; + + result = path; + for (ch = path; *ch != 0; ch++) { + if (*ch == '/' || *ch == '\\') { + if (*(ch + 1) != 0) + result = ch + 1; + } + } + + return result; +} + void path_set_extension(char *path, const char *extension) { char *ch = path; @@ -77,6 +92,13 @@ int bitscanforward(int source) return -1; } +bool strequals(const char *a, const char *b, int length, bool caseInsensitive) +{ + return caseInsensitive ? + _strnicmp(a, b, length) == 0 : + strncmp(a, b, length) == 0; +} + /* case insensitve compare */ int strcicmp(char const *a, char const *b) { diff --git a/src/util/util.h b/src/util/util.h index ac62a3ad79..8ecaf7af4b 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -27,10 +27,12 @@ int squaredmetres_to_squaredfeet(int squaredMetres); int metres_to_feet(int metres); int mph_to_kmph(int mph); +const char *path_get_filename(const char *path); void path_set_extension(char *path, const char *extension); long fsize(FILE *fp); int bitscanforward(int source); +bool strequals(const char *a, const char *b, int length, bool caseInsensitive); int strcicmp(char const *a, char const *b); #endif diff --git a/src/windows/cheats.c b/src/windows/cheats.c index 361e042f9e..1fbeeebe72 100644 --- a/src/windows/cheats.c +++ b/src/windows/cheats.c @@ -65,7 +65,8 @@ enum WINDOW_CHEATS_WIDGET_IDX { WIDX_MOWED_GRASS, WIDX_WATER_PLANTS, WIDX_FIX_VANDALISM, - WIDX_REMOVE_LITTER + WIDX_REMOVE_LITTER, + WIDX_WIN_SCENARIO }; #pragma region MEASUREMENTS @@ -134,6 +135,8 @@ static rct_widget window_cheats_misc_widgets[] = { { WWT_CLOSEBOX, 1, XPL(0), WPL(0), YPL(6), HPL(6), 2754, STR_NONE}, // Water plants { WWT_CLOSEBOX, 1, XPL(1), WPL(1), YPL(6), HPL(6), 2755, STR_NONE}, // Fix vandalism { WWT_CLOSEBOX, 1, XPL(1), WPL(1), YPL(7), HPL(7), 2756, STR_NONE}, // Remove litter + + { WWT_CLOSEBOX, 1, XPL(1), WPL(1), YPL(0), HPL(0), 2766, STR_NONE}, // Win scenario { WIDGETS_END }, }; @@ -147,8 +150,8 @@ static void window_cheats_emptysub() { } static void window_cheats_money_mouseup(); static void window_cheats_guests_mouseup(); static void window_cheats_misc_mouseup(); -void window_cheats_misc_tool_update(); -void window_cheats_misc_tool_down(); +static void window_cheats_misc_tool_update(); +static void window_cheats_misc_tool_down(); static void window_cheats_update(rct_window *w); static void window_cheats_invalidate(); static void window_cheats_paint(); @@ -256,7 +259,7 @@ static void* window_cheats_page_events[] = { static uint32 window_cheats_page_enabled_widgets[] = { (1 << WIDX_CLOSE) | (1 << WIDX_TAB_1) | (1 << WIDX_TAB_2) | (1 << WIDX_TAB_3) | (1 << WIDX_HIGH_MONEY) | (1 << WIDX_PARK_ENTRANCE_FEE), (1 << WIDX_CLOSE) | (1 << WIDX_TAB_1) | (1 << WIDX_TAB_2) | (1 << WIDX_TAB_3) | (1 << WIDX_HAPPY_GUESTS) | (1 << WIDX_TRAM_GUESTS), - (1 << WIDX_CLOSE) | (1 << WIDX_TAB_1) | (1 << WIDX_TAB_2) | (1 << WIDX_TAB_3) | (1 << WIDX_FREEZE_CLIMATE) | (1 << WIDX_OPEN_CLOSE_PARK) | (1 << WIDX_DECREASE_GAME_SPEED) | (1 << WIDX_INCREASE_GAME_SPEED) | (1 << WIDX_ZERO_CLEARANCE) | (1 << WIDX_WEATHER_SUN) | (1 << WIDX_WEATHER_THUNDER) | (1 << WIDX_CLEAR_GRASS) | (1 << WIDX_MOWED_GRASS) | (1 << WIDX_WATER_PLANTS) | (1 << WIDX_FIX_VANDALISM) | (1 << WIDX_REMOVE_LITTER) + (1 << WIDX_CLOSE) | (1 << WIDX_TAB_1) | (1 << WIDX_TAB_2) | (1 << WIDX_TAB_3) | (1 << WIDX_FREEZE_CLIMATE) | (1 << WIDX_OPEN_CLOSE_PARK) | (1 << WIDX_DECREASE_GAME_SPEED) | (1 << WIDX_INCREASE_GAME_SPEED) | (1 << WIDX_ZERO_CLEARANCE) | (1 << WIDX_WEATHER_SUN) | (1 << WIDX_WEATHER_THUNDER) | (1 << WIDX_CLEAR_GRASS) | (1 << WIDX_MOWED_GRASS) | (1 << WIDX_WATER_PLANTS) | (1 << WIDX_FIX_VANDALISM) | (1 << WIDX_REMOVE_LITTER) | (1 << WIDX_WIN_SCENARIO) }; static void window_cheats_draw_tab_images(rct_drawpixelinfo *dpi, rct_window *w); @@ -513,6 +516,9 @@ static void window_cheats_misc_mouseup() case WIDX_REMOVE_LITTER: cheat_remove_litter(); break; + case WIDX_WIN_SCENARIO: + scenario_success(); + break; } } @@ -627,7 +633,8 @@ static void window_cheats_set_page(rct_window *w, int page) window_invalidate(w); } -void window_cheats_misc_tool_update(){ +static void window_cheats_misc_tool_update() +{ short widgetIndex; rct_window* w; short x, y; @@ -656,7 +663,8 @@ void window_cheats_misc_tool_update(){ RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_SPRITE, sint32) = -1; } -void window_cheats_misc_tool_down(){ +static void window_cheats_misc_tool_down() +{ short widgetIndex; rct_window* w; short x, y;