From e23bb8c24360edf2e9d22012ae884691ba966365 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Thu, 30 Nov 2017 18:19:26 +0100 Subject: [PATCH] Update formatting of Game.cpp and Game.h --- src/openrct2/Game.cpp | 669 ++++++++++++++++++++++++++---------------- src/openrct2/Game.h | 68 +++-- 2 files changed, 451 insertions(+), 286 deletions(-) diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index 4982889156..17e645a292 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -67,14 +67,14 @@ #define NUMBER_OF_AUTOSAVES_TO_KEEP 9 uint16 gTicksSinceLastUpdate; -uint8 gGamePaused = 0; -sint32 gGameSpeed = 1; -float gDayNightCycle = 0; -bool gInUpdateCode = false; -bool gInMapInitCode = false; +uint8 gGamePaused = 0; +sint32 gGameSpeed = 1; +float gDayNightCycle = 0; +bool gInUpdateCode = false; +bool gInMapInitCode = false; sint32 gGameCommandNestLevel; -bool gGameCommandIsNetworked; -char gCurrentLoadedPath[MAX_PATH]; +bool gGameCommandIsNetworked; +char gCurrentLoadedPath[MAX_PATH]; bool gLoadKeepWindowsOpen = false; @@ -83,8 +83,8 @@ uint8 gUnk141F568; uint32 gCurrentTicks; -GAME_COMMAND_CALLBACK_POINTER* game_command_callback = 0; -static GAME_COMMAND_CALLBACK_POINTER* const game_command_callback_table[] = { +GAME_COMMAND_CALLBACK_POINTER * game_command_callback = 0; +static GAME_COMMAND_CALLBACK_POINTER * const game_command_callback_table[] = { 0, 0, game_command_callback_ride_construct_placed_front, @@ -101,22 +101,25 @@ sint32 game_command_playerid = -1; rct_string_id gGameCommandErrorTitle; rct_string_id gGameCommandErrorText; -uint8 gErrorType; +uint8 gErrorType; rct_string_id gErrorStringId; -sint32 game_command_callback_get_index(GAME_COMMAND_CALLBACK_POINTER* callback) +sint32 game_command_callback_get_index(GAME_COMMAND_CALLBACK_POINTER * callback) { - for (sint32 i = 0; i < Util::CountOf(game_command_callback_table); i++ ) { - if (game_command_callback_table[i] == callback) { + for (sint32 i = 0; i < Util::CountOf(game_command_callback_table); i++) + { + if (game_command_callback_table[i] == callback) + { return i; } } return 0; } -GAME_COMMAND_CALLBACK_POINTER* game_command_callback_get_callback(sint32 index) +GAME_COMMAND_CALLBACK_POINTER * game_command_callback_get_callback(sint32 index) { - if (index < Util::CountOf(game_command_callback_table)) { + if (index < Util::CountOf(game_command_callback_table)) + { return game_command_callback_table[index]; } return 0; @@ -124,7 +127,7 @@ GAME_COMMAND_CALLBACK_POINTER* game_command_callback_get_callback(sint32 index) void game_increase_game_speed() { - gGameSpeed = Math::Min(gConfigGeneral.debugging_tools ? 5 : 4, gGameSpeed + 1); + gGameSpeed = Math::Min(gConfigGeneral.debugging_tools ? 5 : 4, gGameSpeed + 1); if (gGameSpeed == 5) gGameSpeed = 8; window_invalidate_by_class(WC_TOP_TOOLBAR); @@ -132,7 +135,7 @@ void game_increase_game_speed() void game_reduce_game_speed() { - gGameSpeed = Math::Max(1, gGameSpeed - 1); + gGameSpeed = Math::Max(1, gGameSpeed - 1); if (gGameSpeed == 7) gGameSpeed = 4; window_invalidate_by_class(WC_TOP_TOOLBAR); @@ -150,17 +153,18 @@ void game_create_windows() window_resize_gui(context_get_width(), context_get_height()); } -enum { - SPR_GAME_PALETTE_DEFAULT = 1532, - SPR_GAME_PALETTE_WATER = 1533, +enum +{ + SPR_GAME_PALETTE_DEFAULT = 1532, + SPR_GAME_PALETTE_WATER = 1533, SPR_GAME_PALETTE_WATER_DARKER_1 = 1534, SPR_GAME_PALETTE_WATER_DARKER_2 = 1535, - SPR_GAME_PALETTE_3 = 1536, - SPR_GAME_PALETTE_3_DARKER_1 = 1537, - SPR_GAME_PALETTE_3_DARKER_2 = 1538, - SPR_GAME_PALETTE_4 = 1539, - SPR_GAME_PALETTE_4_DARKER_1 = 1540, - SPR_GAME_PALETTE_4_DARKER_2 = 1541, + SPR_GAME_PALETTE_3 = 1536, + SPR_GAME_PALETTE_3_DARKER_1 = 1537, + SPR_GAME_PALETTE_3_DARKER_2 = 1538, + SPR_GAME_PALETTE_4 = 1539, + SPR_GAME_PALETTE_4_DARKER_1 = 1540, + SPR_GAME_PALETTE_4_DARKER_2 = 1541, }; /** @@ -169,13 +173,15 @@ enum { */ void update_palette_effects() { - rct_water_type* water_type = (rct_water_type*)object_entry_groups[OBJECT_TYPE_WATER].chunks[0]; + rct_water_type * water_type = (rct_water_type *) object_entry_groups[OBJECT_TYPE_WATER].chunks[0]; - if (gClimateLightningFlash == 1) { + if (gClimateLightningFlash == 1) + { // Change palette to lighter colour during lightning sint32 palette = SPR_GAME_PALETTE_DEFAULT; - if (water_type != NULL) { + if (water_type != NULL) + { palette = water_type->image_id; } const rct_g1_element * g1 = gfx_get_g1_element(palette); @@ -193,12 +199,16 @@ void update_palette_effects() platform_update_palette(gGamePalette, 10, 236); } gClimateLightningFlash++; - } else { - if (gClimateLightningFlash == 2) { + } + else + { + if (gClimateLightningFlash == 2) + { // Change palette back to normal after lightning sint32 palette = SPR_GAME_PALETTE_DEFAULT; - if (water_type != NULL) { + if (water_type != NULL) + { palette = water_type->image_id; } @@ -219,20 +229,24 @@ void update_palette_effects() // Animate the water/lava/chain movement palette uint32 shade = 0; - if (gConfigGeneral.render_weather_gloom) { + if (gConfigGeneral.render_weather_gloom) + { uint8 gloom = gClimateCurrentWeatherGloom; - if (gloom != 0) { + if (gloom != 0) + { FILTER_PALETTE_ID weatherColour = ClimateWeatherGloomColours[gloom]; shade = 1; - if (weatherColour != PALETTE_DARKEN_1) { + if (weatherColour != PALETTE_DARKEN_1) + { shade = 2; } } } - uint32 j = gPaletteEffectFrame; - j = (((uint16)((~j / 2) * 128) * 15) >> 16); + uint32 j = gPaletteEffectFrame; + j = (((uint16) ((~j / 2) * 128) * 15) >> 16); uint32 waterId = SPR_GAME_PALETTE_WATER; - if (water_type != NULL) { + if (water_type != NULL) + { waterId = water_type->palette_index_1; } const rct_g1_element * g1 = gfx_get_g1_element(shade + waterId); @@ -240,7 +254,7 @@ void update_palette_effects() { uint8 * vs = &g1->offset[j * 3]; uint8 * vd = &gGamePalette[230 * 4]; - sint32 n = 5; + sint32 n = 5; for (sint32 i = 0; i < n; i++) { vd[0] = vs[0]; @@ -256,15 +270,16 @@ void update_palette_effects() } waterId = SPR_GAME_PALETTE_3; - if (water_type != NULL) { + if (water_type != NULL) + { waterId = water_type->palette_index_2; } - g1 = gfx_get_g1_element(shade + waterId); + g1 = gfx_get_g1_element(shade + waterId); if (g1 != NULL) { uint8 * vs = &g1->offset[j * 3]; uint8 * vd = &gGamePalette[235 * 4]; - sint32 n = 5; + sint32 n = 5; for (sint32 i = 0; i < n; i++) { vd[0] = vs[0]; @@ -279,21 +294,22 @@ void update_palette_effects() } } - j = ((uint16)(gPaletteEffectFrame * -960) * 3) >> 16; + j = ((uint16) (gPaletteEffectFrame * -960) * 3) >> 16; waterId = SPR_GAME_PALETTE_4; - g1 = gfx_get_g1_element(shade + waterId); + g1 = gfx_get_g1_element(shade + waterId); if (g1 != NULL) { uint8 * vs = &g1->offset[j * 3]; uint8 * vd = &gGamePalette[243 * 4]; - sint32 n = 3; + sint32 n = 3; for (sint32 i = 0; i < n; i++) { vd[0] = vs[0]; vd[1] = vs[1]; vd[2] = vs[2]; vs += 3; - if (vs >= &g1->offset[3 * n]) { + if (vs >= &g1->offset[3 * n]) + { vs -= 3 * n; } vd += 4; @@ -301,7 +317,8 @@ void update_palette_effects() } platform_update_palette(gGamePalette, 230, 16); - if (gClimateLightningFlash == 2) { + if (gClimateLightningFlash == 2) + { platform_update_palette(gGamePalette, 10, 236); gClimateLightningFlash = 0; } @@ -320,25 +337,31 @@ void game_update() if (game_is_not_paused() && gPreviewingTitleSequenceInGame) { - title_sequence_player_update((ITitleSequencePlayer*)title_get_sequence_player()); + title_sequence_player_update((ITitleSequencePlayer *) title_get_sequence_player()); } // Determine how many times we need to update the game - if (gGameSpeed > 1) { + if (gGameSpeed > 1) + { numUpdates = 1 << (gGameSpeed - 1); - } else { + } + else + { numUpdates = gTicksSinceLastUpdate / GAME_UPDATE_TIME_MS; - numUpdates = Math::Clamp(1u, numUpdates, (uint32)GAME_MAX_UPDATES); + numUpdates = Math::Clamp(1u, numUpdates, (uint32) GAME_MAX_UPDATES); } - if (network_get_mode() == NETWORK_MODE_CLIENT && network_get_status() == NETWORK_STATUS_CONNECTED && network_get_authstatus() == NETWORK_AUTH_OK) { - if (network_get_server_tick() - gCurrentTicks >= 10) { + if (network_get_mode() == NETWORK_MODE_CLIENT && network_get_status() == NETWORK_STATUS_CONNECTED && network_get_authstatus() == NETWORK_AUTH_OK) + { + if (network_get_server_tick() - gCurrentTicks >= 10) + { // Make sure client doesn't fall behind the server too much numUpdates += 10; } } - if (game_is_paused()) { + if (game_is_paused()) + { numUpdates = 0; // Update the animation list. Note this does not // increment the map animation. @@ -351,7 +374,8 @@ void game_update() } // Update the game one or more times - for (sint32 i = 0; i < numUpdates; i++) { + for (sint32 i = 0; i < numUpdates; i++) + { game_logic_update(); if (gGameSpeed > 1) @@ -359,12 +383,16 @@ void game_update() if (input_get_state() == INPUT_STATE_RESET || input_get_state() == INPUT_STATE_NORMAL - ) { - if (input_test_flag(INPUT_FLAG_VIEWPORT_SCROLLING)) { + ) + { + if (input_test_flag(INPUT_FLAG_VIEWPORT_SCROLLING)) + { input_set_flag(INPUT_FLAG_VIEWPORT_SCROLLING, false); break; } - } else { + } + else + { break; } } @@ -403,14 +431,15 @@ void game_update() if (!(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) && !(gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) && !(gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER) - ) { + ) + { scenario_autosave_check(); } window_dispatch_update_all(); gGameCommandNestLevel = 0; - gInUpdateCode = false; + gInUpdateCode = false; } void game_logic_update() @@ -421,9 +450,11 @@ void game_logic_update() network_update(); - if (network_get_mode() == NETWORK_MODE_CLIENT && network_get_status() == NETWORK_STATUS_CONNECTED && network_get_authstatus() == NETWORK_AUTH_OK) { + if (network_get_mode() == NETWORK_MODE_CLIENT && network_get_status() == NETWORK_STATUS_CONNECTED && network_get_authstatus() == NETWORK_AUTH_OK) + { // Can't be in sync with server, round trips won't work if we are at same level. - if (gCurrentTicks >= network_get_server_tick()) { + if (gCurrentTicks >= network_get_server_tick()) + { // Don't run past the server return; } @@ -439,7 +470,7 @@ void game_logic_update() // Check desync. network_check_desynchronization(); } - + sub_68B089(); scenario_update(); climate_update(); @@ -467,20 +498,23 @@ void game_logic_update() // Update windows //window_dispatch_update_all(); - if (gErrorType != ERROR_TYPE_NONE) { + if (gErrorType != ERROR_TYPE_NONE) + { rct_string_id title_text = STR_UNABLE_TO_LOAD_FILE; - rct_string_id body_text = gErrorStringId; - if (gErrorType == ERROR_TYPE_GENERIC) { + rct_string_id body_text = gErrorStringId; + if (gErrorType == ERROR_TYPE_GENERIC) + { title_text = gErrorStringId; - body_text = 0xFFFF; + body_text = 0xFFFF; } - gErrorType = ERROR_TYPE_NONE; + gErrorType = ERROR_TYPE_NONE; context_show_error(title_text, body_text); } // Start autosave timer after update - if (gLastAutoSaveUpdate == AUTOSAVE_PAUSE) { + if (gLastAutoSaveUpdate == AUTOSAVE_PAUSE) + { gLastAutoSaveUpdate = platform_get_ticks(); } @@ -503,9 +537,12 @@ void game_logic_update() */ static sint32 game_check_affordability(sint32 cost) { - if (cost <= 0)return cost; - if (gUnk141F568 & 0xF0) return cost; - if (cost <= (sint32)(DECRYPT_MONEY(gCashEncrypted)))return cost; + if (cost <= 0) + return cost; + if (gUnk141F568 & 0xF0) + return cost; + if (cost <= (sint32) (DECRYPT_MONEY(gCashEncrypted))) + return cost; set_format_arg(0, uint32, cost); @@ -532,7 +569,7 @@ sint32 game_do_command(sint32 eax, sint32 ebx, sint32 ecx, sint32 edx, sint32 es * @param flags (ebx) * @param command (esi) */ -sint32 game_do_command_p(sint32 command, sint32 *eax, sint32 *ebx, sint32 *ecx, sint32 *edx, sint32 *esi, sint32 *edi, sint32 *ebp) +sint32 game_do_command_p(sint32 command, sint32 * eax, sint32 * ebx, sint32 * ecx, sint32 * edx, sint32 * esi, sint32 * edi, sint32 * ebp) { sint32 cost, flags; sint32 original_ebx, original_edx, original_esi, original_edi, original_ebp; @@ -544,14 +581,16 @@ sint32 game_do_command_p(sint32 command, sint32 *eax, sint32 *ebx, sint32 *ecx, original_edi = *edi; original_ebp = *ebp; - if (command >= Util::CountOf(new_game_command_table)) { + if (command >= Util::CountOf(new_game_command_table)) + { return MONEY32_UNDEFINED; } flags = *ebx; - if (gGameCommandNestLevel == 0) { - gGameCommandErrorText = STR_NONE; + if (gGameCommandNestLevel == 0) + { + gGameCommandErrorText = STR_NONE; gGameCommandIsNetworked = (flags & GAME_COMMAND_FLAG_NETWORKED) != 0; } @@ -561,21 +600,24 @@ sint32 game_do_command_p(sint32 command, sint32 *eax, sint32 *ebx, sint32 *ecx, // Remove ghost scenery so it doesn't interfere with incoming network command if ((flags & GAME_COMMAND_FLAG_NETWORKED) && !(flags & GAME_COMMAND_FLAG_GHOST) && (command == GAME_COMMAND_PLACE_WALL || - command == GAME_COMMAND_PLACE_SCENERY || - command == GAME_COMMAND_PLACE_LARGE_SCENERY || - command == GAME_COMMAND_PLACE_BANNER || - command == GAME_COMMAND_PLACE_PATH)) { + command == GAME_COMMAND_PLACE_SCENERY || + command == GAME_COMMAND_PLACE_LARGE_SCENERY || + command == GAME_COMMAND_PLACE_BANNER || + command == GAME_COMMAND_PLACE_PATH)) + { scenery_remove_ghost_tool_placement(); } - if (game_command_playerid == -1) { + if (game_command_playerid == -1) + { game_command_playerid = network_get_current_player_id(); } // Log certain commands if we are in multiplayer and logging is enabled bool serverLog = (network_get_mode() == NETWORK_MODE_SERVER) && gGameCommandNestLevel == 1 && gConfigNetwork.log_server_actions; bool clientLog = (network_get_mode() == NETWORK_MODE_CLIENT) && (flags & GAME_COMMAND_FLAG_NETWORKED) && gGameCommandNestLevel == 1 && gConfigNetwork.log_server_actions; - if (serverLog || clientLog) { + if (serverLog || clientLog) + { game_log_multiplayer_command(command, eax, ebx, ecx, edx, edi, ebp); } @@ -585,29 +627,35 @@ sint32 game_do_command_p(sint32 command, sint32 *eax, sint32 *ebx, sint32 *ecx, new_game_command_table[command](eax, ebx, ecx, edx, esi, edi, ebp); cost = *ebx; - if (cost != MONEY32_UNDEFINED) { + if (cost != MONEY32_UNDEFINED) + { // Check funds sint32 insufficientFunds = 0; if (gGameCommandNestLevel == 1 && !(flags & GAME_COMMAND_FLAG_2) && !(flags & GAME_COMMAND_FLAG_5) && cost != 0) insufficientFunds = game_check_affordability(cost); - if (insufficientFunds != MONEY32_UNDEFINED) { + if (insufficientFunds != MONEY32_UNDEFINED) + { *ebx = original_ebx; *edx = original_edx; *esi = original_esi; *edi = original_edi; *ebp = original_ebp; - if (!(flags & GAME_COMMAND_FLAG_APPLY)) { + if (!(flags & GAME_COMMAND_FLAG_APPLY)) + { // Decrement nest count gGameCommandNestLevel--; return cost; } - if (network_get_mode() != NETWORK_MODE_NONE && !(flags & GAME_COMMAND_FLAG_NETWORKED) && !(flags & GAME_COMMAND_FLAG_GHOST) && !(flags & GAME_COMMAND_FLAG_5) && gGameCommandNestLevel == 1 /* Send only top-level commands */) { - if (command != GAME_COMMAND_LOAD_OR_QUIT) { // Disable these commands over the network + if (network_get_mode() != NETWORK_MODE_NONE && !(flags & GAME_COMMAND_FLAG_NETWORKED) && !(flags & GAME_COMMAND_FLAG_GHOST) && !(flags & GAME_COMMAND_FLAG_5) && gGameCommandNestLevel == 1 /* Send only top-level commands */) + { + if (command != GAME_COMMAND_LOAD_OR_QUIT) + { // Disable these commands over the network network_send_gamecmd(*eax, *ebx, *ecx, *edx, *esi, *edi, *ebp, game_command_callback_get_index(game_command_callback)); - if (network_get_mode() == NETWORK_MODE_CLIENT) { // Client sent the command to the server, do not run it locally, just return. It will run when server sends it + if (network_get_mode() == NETWORK_MODE_CLIENT) + { // Client sent the command to the server, do not run it locally, just return. It will run when server sends it game_command_callback = 0; // Decrement nest count gGameCommandNestLevel--; @@ -620,7 +668,8 @@ sint32 game_do_command_p(sint32 command, sint32 *eax, sint32 *ebx, sint32 *ecx, new_game_command_table[command](eax, ebx, ecx, edx, esi, edi, ebp); // Do the callback (required for multiplayer to work correctly), but only for top level commands - if (gGameCommandNestLevel == 1) { + if (gGameCommandNestLevel == 1) + { if (game_command_callback && !(flags & GAME_COMMAND_FLAG_GHOST)) { game_command_callback(*eax, *ebx, *ecx, *edx, *esi, *edi, *ebp); @@ -641,17 +690,20 @@ sint32 game_do_command_p(sint32 command, sint32 *eax, sint32 *ebx, sint32 *ecx, return cost; // - if (!(flags & 0x20)) { + if (!(flags & 0x20)) + { // Update money balance finance_payment(cost, gCommandExpenditureType); - if (gUnk141F568 == gUnk13CA740) { + if (gUnk141F568 == gUnk13CA740) + { // Create a +/- money text effect if (cost != 0 && game_is_not_paused()) money_effect_create(cost); } } - if (network_get_mode() == NETWORK_MODE_SERVER && !(flags & GAME_COMMAND_FLAG_NETWORKED) && !(flags & GAME_COMMAND_FLAG_GHOST)) { + if (network_get_mode() == NETWORK_MODE_SERVER && !(flags & GAME_COMMAND_FLAG_NETWORKED) && !(flags & GAME_COMMAND_FLAG_GHOST)) + { network_set_player_last_action(network_get_player_index(network_get_current_player_id()), command); network_add_player_money_spent(network_get_current_player_id(), cost); } @@ -679,182 +731,226 @@ sint32 game_do_command_p(sint32 command, sint32 *eax, sint32 *ebx, sint32 *ecx, return MONEY32_UNDEFINED; } -void game_log_multiplayer_command(int command, int *eax, int* ebx, int* ecx, int* edx, int* edi, int* ebp) +void game_log_multiplayer_command(int command, int * eax, int * ebx, int * ecx, int * edx, int * edi, int * ebp) { // Get player name int player_index = network_get_player_index(game_command_playerid); - const char* player_name = network_get_player_name(player_index); + const char * player_name = network_get_player_name(player_index); char log_msg[256]; - if (command == GAME_COMMAND_CHEAT) { + if (command == GAME_COMMAND_CHEAT) + { // Get cheat name - const char* cheat = cheats_get_cheat_string(*ecx, *edx, *edi); - char* args[2] = { - (char *)player_name, - (char *)cheat + const char * cheat = cheats_get_cheat_string(*ecx, *edx, *edi); + char * args[2] = { + (char *) player_name, + (char *) cheat }; format_string(log_msg, 256, STR_LOG_CHEAT_USED, args); network_append_server_log(log_msg); - } else if (command == GAME_COMMAND_CREATE_RIDE && *ebp == 1) { // ebp is 1 if the command comes from ride_create method in ride.c, other calls send ride_entry instead of ride and wont work + } + else if (command == GAME_COMMAND_CREATE_RIDE && *ebp == 1) + { // ebp is 1 if the command comes from ride_create method in ride.c, other calls send ride_entry instead of ride and wont work // Get ride name - Ride* ride = get_ride(*edx); + Ride * ride = get_ride(*edx); char ride_name[128]; format_string(ride_name, 128, ride->name, &ride->name_arguments); - char* args[2] = { - (char *)player_name, + char * args[2] = { + (char *) player_name, ride_name }; format_string(log_msg, 256, STR_LOG_CREATE_RIDE, args); network_append_server_log(log_msg); - } else if (command == GAME_COMMAND_DEMOLISH_RIDE && (*ebp == 1 || *ebp == 0)) { // ebp is 1 if command comes from ride window prompt, so we don't log "demolishing" ride previews + } + else if (command == GAME_COMMAND_DEMOLISH_RIDE && (*ebp == 1 || *ebp == 0)) + { // ebp is 1 if command comes from ride window prompt, so we don't log "demolishing" ride previews // Get ride name - Ride* ride = get_ride(*edx); + Ride * ride = get_ride(*edx); char ride_name[128]; format_string(ride_name, 128, ride->name, &ride->name_arguments); - char* args[2] = { + char * args[2] = { (char *) player_name, ride_name }; format_string(log_msg, 256, STR_LOG_DEMOLISH_RIDE, args); network_append_server_log(log_msg); - } else if (command == GAME_COMMAND_SET_RIDE_APPEARANCE || command == GAME_COMMAND_SET_RIDE_VEHICLES || command == GAME_COMMAND_SET_RIDE_SETTING) { + } + else if (command == GAME_COMMAND_SET_RIDE_APPEARANCE || command == GAME_COMMAND_SET_RIDE_VEHICLES || command == GAME_COMMAND_SET_RIDE_SETTING) + { // Get ride name int ride_index = *edx & 0xFF; - Ride* ride = get_ride(ride_index); + Ride * ride = get_ride(ride_index); char ride_name[128]; format_string(ride_name, 128, ride->name, &ride->name_arguments); - char* args[2] = { + char * args[2] = { (char *) player_name, ride_name }; - switch (command) { - case GAME_COMMAND_SET_RIDE_APPEARANCE: format_string(log_msg, 256, STR_LOG_RIDE_APPEARANCE, args); break; - case GAME_COMMAND_SET_RIDE_VEHICLES: format_string(log_msg, 256, STR_LOG_RIDE_VEHICLES, args); break; - case GAME_COMMAND_SET_RIDE_SETTING: format_string(log_msg, 256, STR_LOG_RIDE_SETTINGS, args); break; + switch (command) + { + case GAME_COMMAND_SET_RIDE_APPEARANCE: + format_string(log_msg, 256, STR_LOG_RIDE_APPEARANCE, args); + break; + case GAME_COMMAND_SET_RIDE_VEHICLES: + format_string(log_msg, 256, STR_LOG_RIDE_VEHICLES, args); + break; + case GAME_COMMAND_SET_RIDE_SETTING: + format_string(log_msg, 256, STR_LOG_RIDE_SETTINGS, args); + break; } network_append_server_log(log_msg); - } else if (command == GAME_COMMAND_SET_RIDE_STATUS) { + } + else if (command == GAME_COMMAND_SET_RIDE_STATUS) + { // Get ride name int ride_index = *edx & 0xFF; - Ride* ride = get_ride(ride_index); + Ride * ride = get_ride(ride_index); char ride_name[128]; format_string(ride_name, 128, ride->name, &ride->name_arguments); - char* args[2] = { + char * args[2] = { (char *) player_name, ride_name }; int status = *edx >> 8; - switch (status) { - case 0: format_string(log_msg, 256, STR_LOG_RIDE_STATUS_CLOSED, args); break; - case 1: format_string(log_msg, 256, STR_LOG_RIDE_STATUS_OPEN, args); break; - case 2: format_string(log_msg, 256, STR_LOG_RIDE_STATUS_TESTING, args); break; + switch (status) + { + case 0: + format_string(log_msg, 256, STR_LOG_RIDE_STATUS_CLOSED, args); + break; + case 1: + format_string(log_msg, 256, STR_LOG_RIDE_STATUS_OPEN, args); + break; + case 2: + format_string(log_msg, 256, STR_LOG_RIDE_STATUS_TESTING, args); + break; } network_append_server_log(log_msg); - } else if (command == GAME_COMMAND_SET_RIDE_PRICE) { + } + else if (command == GAME_COMMAND_SET_RIDE_PRICE) + { // Get ride name int ride_index = *edx & 0xFF; - Ride* ride = get_ride(ride_index); + Ride * ride = get_ride(ride_index); char ride_name[128]; format_string(ride_name, 128, ride->name, &ride->name_arguments); // Format price - int price_args[1] = {*edi}; + int price_args[1] = {*edi}; char price_str[16]; format_string(price_str, 16, STR_BOTTOM_TOOLBAR_CASH, price_args); // Log change in primary or secondary price - char* args[3] = { + char * args[3] = { (char *) player_name, ride_name, price_str }; - if (*edx >> 8 == 0) { + if (*edx >> 8 == 0) + { format_string(log_msg, 256, STR_LOG_RIDE_PRICE, args); - } else if (*edx >> 8 == 1) { + } + else if (*edx >> 8 == 1) + { format_string(log_msg, 256, STR_LOG_RIDE_SECONDARY_PRICE, args); } network_append_server_log(log_msg); - } else if (command == GAME_COMMAND_SET_PARK_OPEN) { + } + else if (command == GAME_COMMAND_SET_PARK_OPEN) + { // Log change in park open/close - char* args[1] = { + char * args[1] = { (char *) player_name }; - if (*edx >> 8 == 0) { + if (*edx >> 8 == 0) + { format_string(log_msg, 256, STR_LOG_PARK_OPEN, args); - } else if (*edx >> 8 == 1) { + } + else if (*edx >> 8 == 1) + { format_string(log_msg, 256, STR_LOG_PARK_CLOSED, args); } network_append_server_log(log_msg); - } else if (command == GAME_COMMAND_SET_PARK_ENTRANCE_FEE) { + } + else if (command == GAME_COMMAND_SET_PARK_ENTRANCE_FEE) + { // Format price - int price_args[1] = {*edi}; + int price_args[1] = {*edi}; char price_str[16]; format_string(price_str, 16, STR_BOTTOM_TOOLBAR_CASH, price_args); // Log change in park entrance fee - char* args[2] = { + char * args[2] = { (char *) player_name, price_str }; format_string(log_msg, 256, STR_LOG_PARK_ENTRANCE_FEE, args); network_append_server_log(log_msg); - } else if (command == GAME_COMMAND_PLACE_SCENERY || command == GAME_COMMAND_PLACE_WALL || - command == GAME_COMMAND_PLACE_LARGE_SCENERY || command == GAME_COMMAND_PLACE_BANNER) { + } + else if (command == GAME_COMMAND_PLACE_SCENERY || command == GAME_COMMAND_PLACE_WALL || + command == GAME_COMMAND_PLACE_LARGE_SCENERY || command == GAME_COMMAND_PLACE_BANNER) + { uint8 flags = *ebx & 0xFF; - if (flags & GAME_COMMAND_FLAG_GHOST) { + if (flags & GAME_COMMAND_FLAG_GHOST) + { // Don't log ghost previews being removed return; } // Log placing scenery - char* args[1] = { - (char *)player_name + char * args[1] = { + (char *) player_name }; format_string(log_msg, 256, STR_LOG_PLACE_SCENERY, args); network_append_server_log(log_msg); - } else if (command == GAME_COMMAND_REMOVE_SCENERY || command == GAME_COMMAND_REMOVE_WALL || - command == GAME_COMMAND_REMOVE_LARGE_SCENERY || command == GAME_COMMAND_REMOVE_BANNER) { + } + else if (command == GAME_COMMAND_REMOVE_SCENERY || command == GAME_COMMAND_REMOVE_WALL || + command == GAME_COMMAND_REMOVE_LARGE_SCENERY || command == GAME_COMMAND_REMOVE_BANNER) + { uint8 flags = *ebx & 0xFF; - if (flags & GAME_COMMAND_FLAG_GHOST) { + if (flags & GAME_COMMAND_FLAG_GHOST) + { // Don't log ghost previews being removed return; } // Log removing scenery - char* args[1] = { - (char *)player_name + char * args[1] = { + (char *) player_name }; format_string(log_msg, 256, STR_LOG_REMOVE_SCENERY, args); network_append_server_log(log_msg); - } else if (command == GAME_COMMAND_SET_SCENERY_COLOUR || command == GAME_COMMAND_SET_WALL_COLOUR || - command == GAME_COMMAND_SET_LARGE_SCENERY_COLOUR || command == GAME_COMMAND_SET_BANNER_COLOUR || - command == GAME_COMMAND_SET_BANNER_NAME || command == GAME_COMMAND_SET_SIGN_NAME || - command == GAME_COMMAND_SET_BANNER_STYLE || command == GAME_COMMAND_SET_SIGN_STYLE) { + } + else if (command == GAME_COMMAND_SET_SCENERY_COLOUR || command == GAME_COMMAND_SET_WALL_COLOUR || + command == GAME_COMMAND_SET_LARGE_SCENERY_COLOUR || command == GAME_COMMAND_SET_BANNER_COLOUR || + command == GAME_COMMAND_SET_BANNER_NAME || command == GAME_COMMAND_SET_SIGN_NAME || + command == GAME_COMMAND_SET_BANNER_STYLE || command == GAME_COMMAND_SET_SIGN_STYLE) + { // Log editing scenery - char* args[1] = { - (char *)player_name + char * args[1] = { + (char *) player_name }; format_string(log_msg, 256, STR_LOG_EDIT_SCENERY, args); network_append_server_log(log_msg); - if (command == GAME_COMMAND_SET_BANNER_NAME || command == GAME_COMMAND_SET_SIGN_NAME) { + if (command == GAME_COMMAND_SET_BANNER_NAME || command == GAME_COMMAND_SET_SIGN_NAME) + { static char banner_name[128]; memset(banner_name, ' ', sizeof(banner_name)); @@ -864,35 +960,39 @@ void game_log_multiplayer_command(int command, int *eax, int* ebx, int* ecx, int if (nameChunkOffset < 0) nameChunkOffset = 2; nameChunkOffset *= 12; - nameChunkOffset = Math::Min(nameChunkOffset, (sint32)(Util::CountOf(banner_name) - 12)); + nameChunkOffset = Math::Min(nameChunkOffset, (sint32) (Util::CountOf(banner_name) - 12)); memcpy(banner_name + nameChunkOffset + 0, edx, 4); memcpy(banner_name + nameChunkOffset + 4, ebp, 4); memcpy(banner_name + nameChunkOffset + 8, edi, 4); banner_name[sizeof(banner_name) - 1] = '\0'; - char* args_sign[2] = { - (char *)player_name, - (char *)banner_name + char * args_sign[2] = { + (char *) player_name, + (char *) banner_name }; format_string(log_msg, 256, STR_LOG_SET_SIGN_NAME, args_sign); network_append_server_log(log_msg); } - } else if (command == GAME_COMMAND_PLACE_TRACK) { + } + else if (command == GAME_COMMAND_PLACE_TRACK) + { // Get ride name int ride_index = *edx & 0xFF; - Ride* ride = get_ride(ride_index); + Ride * ride = get_ride(ride_index); char ride_name[128]; format_string(ride_name, 128, ride->name, &ride->name_arguments); - char* args[2] = { + char * args[2] = { (char *) player_name, ride_name }; format_string(log_msg, 256, STR_LOG_PLACE_TRACK, args); network_append_server_log(log_msg); - } else if (command == GAME_COMMAND_REMOVE_TRACK) { - char* args[1] = { + } + else if (command == GAME_COMMAND_REMOVE_TRACK) + { + char * args[1] = { (char *) player_name }; @@ -905,7 +1005,8 @@ void pause_toggle() { gGamePaused ^= GAME_PAUSED_NORMAL; window_invalidate_by_class(WC_TOP_TOOLBAR); - if (gGamePaused & GAME_PAUSED_NORMAL) { + if (gGamePaused & GAME_PAUSED_NORMAL) + { audio_stop_all_music_and_sounds(); } } @@ -924,7 +1025,7 @@ bool game_is_not_paused() * * rct2: 0x00667C15 */ -void game_pause_toggle(sint32 *eax, sint32 *ebx, sint32 *ecx, sint32 *edx, sint32 *esi, sint32 *edi, sint32 *ebp) +void game_pause_toggle(sint32 * eax, sint32 * ebx, sint32 * ecx, sint32 * edx, sint32 * esi, sint32 * edi, sint32 * ebp) { if (*ebx & GAME_COMMAND_FLAG_APPLY) pause_toggle(); @@ -936,10 +1037,12 @@ void game_pause_toggle(sint32 *eax, sint32 *ebx, sint32 *ecx, sint32 *edx, sint3 * * rct2: 0x0066DB5F */ -static void game_load_or_quit(sint32 *eax, sint32 *ebx, sint32 *ecx, sint32 *edx, sint32 *esi, sint32 *edi, sint32 *ebp) +static void game_load_or_quit(sint32 * eax, sint32 * ebx, sint32 * ecx, sint32 * edx, sint32 * esi, sint32 * edi, sint32 * ebp) { - if (*ebx & GAME_COMMAND_FLAG_APPLY) { - switch (*edx & 0xFF) { + if (*ebx & GAME_COMMAND_FLAG_APPLY) + { + switch (*edx & 0xFF) + { case 0: gSavePromptMode = *edi & 0xFF; context_open_window(WC_SAVE_PROMPT); @@ -967,38 +1070,48 @@ static void load_landscape() intent_release(intent); } -static void utf8_to_rct2_self(char *buffer, size_t length) +static void utf8_to_rct2_self(char * buffer, size_t length) { char tempBuffer[512]; utf8_to_rct2(tempBuffer, buffer); - size_t i = 0; - const char *src = tempBuffer; - char *dst = buffer; - while (*src != 0 && i < length - 1) { - if (*src == (char)(uint8)0xFF) { - if (i < length - 3) { + size_t i = 0; + const char * src = tempBuffer; + char * dst = buffer; + while (*src != 0 && i < length - 1) + { + if (*src == (char) (uint8) 0xFF) + { + if (i < length - 3) + { *dst++ = *src++; *dst++ = *src++; *dst++ = *src++; - } else { + } + else + { break; } i += 3; - } else { + } + else + { *dst++ = *src++; i++; } } - do { + do + { *dst++ = '\0'; i++; - } while (i < length); + } + while (i < length); } -static void rct2_to_utf8_self(char *buffer, size_t length) +static void rct2_to_utf8_self(char * buffer, size_t length) { - if (length > 0) { + if (length > 0) + { char tempBuffer[512]; rct2_to_utf8(tempBuffer, buffer); safe_strcpy(buffer, tempBuffer, length); @@ -1034,10 +1147,12 @@ void game_convert_strings_to_utf8() void game_convert_news_items_to_utf8() { - for (sint32 i = 0; i < MAX_NEWS_ITEMS; i++) { - NewsItem *newsItem = news_item_get(i); + for (sint32 i = 0; i < MAX_NEWS_ITEMS; i++) + { + NewsItem * newsItem = news_item_get(i); - if (!str_is_null_or_empty(newsItem->Text)) { + if (!str_is_null_or_empty(newsItem->Text)) + { rct2_to_utf8_self(newsItem->Text, sizeof(newsItem->Text)); } } @@ -1046,7 +1161,7 @@ void game_convert_news_items_to_utf8() /** * Converts all the user strings and news item strings to RCT2 encoding. */ -void game_convert_strings_to_rct2(rct_s6_data *s6) +void game_convert_strings_to_rct2(rct_s6_data * s6) { // Scenario details utf8_to_rct2_self(s6->scenario_completed_name, sizeof(s6->scenario_completed_name)); @@ -1065,10 +1180,12 @@ void game_convert_strings_to_rct2(rct_s6_data *s6) } // News items - for (sint32 i = 0; i < MAX_NEWS_ITEMS; i++) { - rct12_news_item *newsItem = &s6->news_items[i]; + for (sint32 i = 0; i < MAX_NEWS_ITEMS; i++) + { + rct12_news_item * newsItem = &s6->news_items[i]; - if (!str_is_null_or_empty(newsItem->Text)) { + if (!str_is_null_or_empty(newsItem->Text)) + { utf8_to_rct2_self(newsItem->Text, sizeof(newsItem->Text)); } } @@ -1079,13 +1196,14 @@ void game_convert_strings_to_rct2(rct_s6_data *s6) void game_fix_save_vars() { // Recalculates peep count after loading a save to fix corrupted files - rct_peep* peep; + rct_peep * peep; uint16 spriteIndex; uint16 peepCount = 0; - FOR_ALL_GUESTS(spriteIndex, peep) { - if(!peep->outside_of_park) - peepCount++; - } + FOR_ALL_GUESTS(spriteIndex, peep) + { + if (!peep->outside_of_park) + peepCount++; + } gNumGuestsInPark = peepCount; @@ -1093,15 +1211,18 @@ void game_fix_save_vars() // Fixes broken saves where a surface element could be null // and broken saves with incorrect invisible map border tiles - for (sint32 y = 0; y < 256; y++) { - for (sint32 x = 0; x < 256; x++) { - rct_tile_element *tileElement = map_get_surface_element_at(x, y); + for (sint32 y = 0; y < 256; y++) + { + for (sint32 x = 0; x < 256; x++) + { + rct_tile_element * tileElement = map_get_surface_element_at(x, y); if (tileElement == NULL) { log_error("Null map element at x = %d and y = %d. Fixing...", x, y); tileElement = tile_element_insert(x, y, 14, 0); - if (tileElement == NULL) { + if (tileElement == NULL) + { log_error("Unable to fix: Map element limit reached."); return; } @@ -1109,19 +1230,21 @@ void game_fix_save_vars() // Fix the invisible border tiles. // At this point, we can be sure that tileElement is not NULL. - if (x == 0 || x == gMapSize - 1 || y == 0 || y == gMapSize -1) + if (x == 0 || x == gMapSize - 1 || y == 0 || y == gMapSize - 1) { - tileElement->base_height = 2; - tileElement->clearance_height = 2; + tileElement->base_height = 2; + tileElement->clearance_height = 2; tileElement->properties.surface.slope = TILE_ELEMENT_SLOPE_FLAT; } } } // Fix invalid research items - for (sint32 i = 0; i < MAX_RESEARCH_ITEMS; i++) { - rct_research_item *researchItem = &gResearchItems[i]; - if (researchItem->entryIndex == RESEARCHED_ITEMS_SEPARATOR) continue; + for (sint32 i = 0; i < MAX_RESEARCH_ITEMS; i++) + { + rct_research_item * researchItem = &gResearchItems[i]; + if (researchItem->entryIndex == RESEARCHED_ITEMS_SEPARATOR) + continue; if (researchItem->entryIndex == RESEARCHED_ITEMS_END) { if (i == MAX_RESEARCH_ITEMS - 1) @@ -1131,18 +1254,24 @@ void game_fix_save_vars() (++researchItem)->entryIndex = RESEARCHED_ITEMS_END_2; break; } - if (researchItem->entryIndex == RESEARCHED_ITEMS_END_2) break; - if (researchItem->entryIndex & RESEARCH_ENTRY_RIDE_MASK) { - uint8 entryIndex = researchItem->entryIndex & 0xFF; - rct_ride_entry *rideEntry = get_ride_entry(entryIndex); - if (rideEntry == NULL) { + if (researchItem->entryIndex == RESEARCHED_ITEMS_END_2) + break; + if (researchItem->entryIndex & RESEARCH_ENTRY_RIDE_MASK) + { + uint8 entryIndex = researchItem->entryIndex & 0xFF; + rct_ride_entry * rideEntry = get_ride_entry(entryIndex); + if (rideEntry == NULL) + { research_remove(researchItem->entryIndex); i--; } - } else { - uint8 entryIndex = researchItem->entryIndex; - rct_scenery_group_entry *sceneryGroupEntry = get_scenery_group_entry(entryIndex); - if (sceneryGroupEntry == NULL) { + } + else + { + uint8 entryIndex = researchItem->entryIndex; + rct_scenery_group_entry * sceneryGroupEntry = get_scenery_group_entry(entryIndex); + if (sceneryGroupEntry == NULL) + { research_remove(researchItem->entryIndex); i--; } @@ -1168,7 +1297,8 @@ void handle_park_load_failure_with_title_opt(const ParkLoadResult * result, cons { // This option is used when loading parks from the command line // to ensure that the title sequence loads before the window - if (loadTitleFirst) { + if (loadTitleFirst) + { title_load(); } // The path needs to be duplicated as it's a const here @@ -1193,7 +1323,8 @@ void handle_park_load_failure_with_title_opt(const ParkLoadResult * result, cons context_show_error(STR_FAILED_TO_LOAD_IMCOMPATIBLE_RCTC_FLAG, STR_NONE); } - else if (ParkLoadResult_GetError(result) != PARK_LOAD_ERROR_OK) { + else if (ParkLoadResult_GetError(result) != PARK_LOAD_ERROR_OK) + { // If loading the SV6 or SV4 failed for a reason other than invalid objects // the current park state will be corrupted so just go back to the title screen. title_load(); @@ -1207,7 +1338,7 @@ void handle_park_load_failure(const ParkLoadResult * result, const utf8 * path) void game_load_init() { - rct_window *mainWindow; + rct_window * mainWindow; gScreenFlags = SCREEN_FLAGS_PLAYING; audio_stop_all_music_and_sounds(); @@ -1221,12 +1352,13 @@ void game_load_init() if (mainWindow != NULL) { mainWindow->viewport_target_sprite = SPRITE_INDEX_NULL; - mainWindow->saved_view_x = gSavedViewX; - mainWindow->saved_view_y = gSavedViewY; + mainWindow->saved_view_x = gSavedViewX; + mainWindow->saved_view_y = gSavedViewY; uint8 zoomDifference = gSavedViewZoom - mainWindow->viewport->zoom; mainWindow->viewport->zoom = gSavedViewZoom; gCurrentRotation = gSavedViewRotation; - if (zoomDifference != 0) { + if (zoomDifference != 0) + { mainWindow->viewport->view_width <<= zoomDifference; mainWindow->viewport->view_height <<= zoomDifference; } @@ -1254,7 +1386,8 @@ void game_load_init() load_palette(); - if (!gOpenRCT2Headless) { + if (!gOpenRCT2Headless) + { intent = intent_create(INTENT_ACTION_CLEAR_TILE_INSPECTOR_CLIPBOARD); context_broadcast_intent(intent); intent_release(intent); @@ -1272,9 +1405,11 @@ void game_load_init() */ void reset_all_sprite_quadrant_placements() { - for (size_t i = 0; i < MAX_SPRITES; i++) { - rct_sprite *spr = get_sprite(i); - if (spr->unknown.sprite_identifier != SPRITE_IDENTIFIER_NULL) { + for (size_t i = 0; i < MAX_SPRITES; i++) + { + rct_sprite * spr = get_sprite(i); + if (spr->unknown.sprite_identifier != SPRITE_IDENTIFIER_NULL) + { sprite_move(spr->unknown.x, spr->unknown.y, spr->unknown.z, spr); } } @@ -1282,9 +1417,11 @@ void reset_all_sprite_quadrant_placements() void save_game() { - if (!gFirstTimeSaving) { + if (!gFirstTimeSaving) + { log_verbose("Saving to %s", gScenarioSavePath); - if (scenario_save(gScenarioSavePath, 0x80000000 | (gConfigGeneral.save_plugin_data ? 1 : 0))) { + if (scenario_save(gScenarioSavePath, 0x80000000 | (gConfigGeneral.save_plugin_data ? 1 : 0))) + { log_verbose("Saved to %s", gScenarioSavePath); safe_strcpy(gCurrentLoadedPath, gScenarioSavePath, MAX_PATH); @@ -1292,7 +1429,9 @@ void save_game() // game shortly after saving. gScreenAge = 0; } - } else { + } + else + { save_game_as(); } } @@ -1317,30 +1456,34 @@ void save_game_as() intent_release(intent); } -static sint32 compare_autosave_file_paths (const void * a, const void * b ) { - return strcmp(*(char **)a, *(char **)b); +static sint32 compare_autosave_file_paths(const void * a, const void * b) +{ + return strcmp(*(char **) a, *(char **) b); } static void limit_autosave_count(const size_t numberOfFilesToKeep, bool processLandscapeFolder) { sint32 fileEnumHandle = 0; - size_t autosavesCount = 0; + size_t autosavesCount = 0; size_t numAutosavesToDelete = 0; file_info fileInfo; utf8 filter[MAX_PATH]; - utf8 **autosaveFiles = NULL; + utf8 ** autosaveFiles = NULL; - size_t i=0; + size_t i = 0; - if (processLandscapeFolder) { + if (processLandscapeFolder) + { platform_get_user_directory(filter, "landscape", sizeof(filter)); safe_strcat_path(filter, "autosave", sizeof(filter)); safe_strcat_path(filter, "autosave_*.sc6", sizeof(filter)); - } else { + } + else + { platform_get_user_directory(filter, "save", sizeof(filter)); safe_strcat_path(filter, "autosave", sizeof(filter)); safe_strcat_path(filter, "autosave_*.sv6", sizeof(filter)); @@ -1348,27 +1491,34 @@ static void limit_autosave_count(const size_t numberOfFilesToKeep, bool processL // At first, count how many autosaves there are fileEnumHandle = platform_enumerate_files_begin(filter); - while (platform_enumerate_files_next(fileEnumHandle, &fileInfo)) { + while (platform_enumerate_files_next(fileEnumHandle, &fileInfo)) + { autosavesCount++; } platform_enumerate_files_end(fileEnumHandle); // If there are fewer autosaves than the number of files to keep we don't need to delete anything - if(autosavesCount <= numberOfFilesToKeep) { + if (autosavesCount <= numberOfFilesToKeep) + { return; } - autosaveFiles = (utf8**) malloc(sizeof(utf8*) * autosavesCount); + autosaveFiles = (utf8 **) malloc(sizeof(utf8 *) * autosavesCount); fileEnumHandle = platform_enumerate_files_begin(filter); - for(i = 0; i < autosavesCount; i++) { - autosaveFiles[i] = (utf8*)malloc(sizeof(utf8) * MAX_PATH); + for (i = 0; i < autosavesCount; i++) + { + autosaveFiles[i] = (utf8 *) malloc(sizeof(utf8) * MAX_PATH); memset(autosaveFiles[i], 0, sizeof(utf8) * MAX_PATH); - if(platform_enumerate_files_next(fileEnumHandle, &fileInfo)) { - if (processLandscapeFolder) { + if (platform_enumerate_files_next(fileEnumHandle, &fileInfo)) + { + if (processLandscapeFolder) + { platform_get_user_directory(autosaveFiles[i], "landscape", sizeof(utf8) * MAX_PATH); - } else { + } + else + { platform_get_user_directory(autosaveFiles[i], "save", sizeof(utf8) * MAX_PATH); } safe_strcat_path(autosaveFiles[i], "autosave", sizeof(utf8) * MAX_PATH); @@ -1377,13 +1527,14 @@ static void limit_autosave_count(const size_t numberOfFilesToKeep, bool processL } platform_enumerate_files_end(fileEnumHandle); - qsort (autosaveFiles, autosavesCount, sizeof (char*), compare_autosave_file_paths); + qsort(autosaveFiles, autosavesCount, sizeof(char *), compare_autosave_file_paths); // Calculate how many saves we need to delete. numAutosavesToDelete = autosavesCount - numberOfFilesToKeep; - i=0; - while (numAutosavesToDelete > 0) { + i = 0; + while (numAutosavesToDelete > 0) + { platform_file_delete(autosaveFiles[i]); i++; @@ -1391,7 +1542,8 @@ static void limit_autosave_count(const size_t numberOfFilesToKeep, bool processL } - for(i = 0; i < autosavesCount; i++) { + for (i = 0; i < autosavesCount; i++) + { free(autosaveFiles[i]); } @@ -1400,11 +1552,12 @@ static void limit_autosave_count(const size_t numberOfFilesToKeep, bool processL void game_autosave() { - const char * subDirectory = "save"; + const char * subDirectory = "save"; const char * fileExtension = ".sv6"; uint32 saveFlags = 0x80000000; - if (gScreenFlags & SCREEN_FLAGS_EDITOR) { - subDirectory = "landscape"; + if (gScreenFlags & SCREEN_FLAGS_EDITOR) + { + subDirectory = "landscape"; fileExtension = ".sc6"; saveFlags |= 2; } @@ -1417,8 +1570,8 @@ void game_autosave() utf8 timeName[44]; snprintf(timeName, sizeof(timeName), "autosave_%04u-%02u-%02u_%02u-%02u-%02u%s", - currentDate.year, currentDate.month, currentDate.day, currentTime.hour, - currentTime.minute, currentTime.second, fileExtension); + currentDate.year, currentDate.month, currentDate.day, currentTime.hour, + currentTime.minute, currentTime.second, fileExtension); limit_autosave_count(NUMBER_OF_AUTOSAVES_TO_KEEP, (gScreenFlags & SCREEN_FLAGS_EDITOR)); @@ -1433,7 +1586,8 @@ void game_autosave() safe_strcat(backupPath, fileExtension, sizeof(backupPath)); safe_strcat(backupPath, ".bak", sizeof(backupPath)); - if (platform_file_exists(path)) { + if (platform_file_exists(path)) + { platform_file_copy(path, backupPath, true); } @@ -1444,7 +1598,8 @@ void game_autosave() * * rct2: 0x006E3838 */ -void rct2_exit_reason(rct_string_id title, rct_string_id body){ +void rct2_exit_reason(rct_string_id title, rct_string_id body) +{ // Before this would set a quit message char exit_title[255]; @@ -1471,7 +1626,8 @@ void rct2_exit() static void game_load_or_quit_no_save_prompt_callback(sint32 result, const utf8 * path) { - if (result == MODAL_RESULT_OK) { + if (result == MODAL_RESULT_OK) + { context_load_park_from_file(path); } } @@ -1482,13 +1638,17 @@ static void game_load_or_quit_no_save_prompt_callback(sint32 result, const utf8 */ void game_load_or_quit_no_save_prompt() { - switch (gSavePromptMode) { + switch (gSavePromptMode) + { case PM_SAVE_BEFORE_LOAD: game_do_command(0, 1, 0, 1, GAME_COMMAND_LOAD_OR_QUIT, 0, 0); tool_cancel(); - if (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) { + if (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) + { load_landscape(); - } else { + } + else + { Intent * intent = intent_create(WC_LOADSAVE); intent_set_uint(intent, INTENT_EXTRA_LOADSAVE_TYPE, LOADSAVETYPE_LOAD | LOADSAVETYPE_GAME); intent_set_pointer(intent, INTENT_EXTRA_CALLBACK, (void *) game_load_or_quit_no_save_prompt_callback); @@ -1499,10 +1659,11 @@ void game_load_or_quit_no_save_prompt() case PM_SAVE_BEFORE_QUIT: game_do_command(0, 1, 0, 1, GAME_COMMAND_LOAD_OR_QUIT, 0, 0); tool_cancel(); - if (input_test_flag(INPUT_FLAG_5)) { + if (input_test_flag(INPUT_FLAG_5)) + { input_set_flag(INPUT_FLAG_5, false); } - gGameSpeed = 1; + gGameSpeed = 1; gFirstTimeSaving = true; title_load(); break; @@ -1546,7 +1707,7 @@ void game_init_all(sint32 mapSize) load_palette(); } -GAME_COMMAND_POINTER* new_game_command_table[GAME_COMMAND_COUNT] = { +GAME_COMMAND_POINTER * new_game_command_table[GAME_COMMAND_COUNT] = { game_command_set_ride_appearance, game_command_set_land_height, game_pause_toggle, diff --git a/src/openrct2/Game.h b/src/openrct2/Game.h index e407aa2c8d..1f20147f3b 100644 --- a/src/openrct2/Game.h +++ b/src/openrct2/Game.h @@ -19,7 +19,8 @@ #include "common.h" #include "scenario/scenario.h" -enum GAME_COMMAND { +enum GAME_COMMAND +{ GAME_COMMAND_SET_RIDE_APPEARANCE, GAME_COMMAND_SET_LAND_HEIGHT, GAME_COMMAND_TOGGLE_PAUSE, @@ -95,30 +96,33 @@ enum GAME_COMMAND { GAME_COMMAND_COUNT }; -enum { - GAME_COMMAND_FLAG_APPLY = (1 << 0), // If this flag is set, the command is applied, otherwise only the cost is retrieved - GAME_COMMAND_FLAG_2 = (1 << 2), +enum +{ + GAME_COMMAND_FLAG_APPLY = (1 << 0), // If this flag is set, the command is applied, otherwise only the cost is retrieved + GAME_COMMAND_FLAG_2 = (1 << 2), GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED = (1 << 3), // Allow while paused - GAME_COMMAND_FLAG_4 = (1 << 4), - GAME_COMMAND_FLAG_5 = (1 << 5), - GAME_COMMAND_FLAG_GHOST = (1 << 6), - GAME_COMMAND_FLAG_PATH_SCENERY = (1 << 7), - GAME_COMMAND_FLAG_NETWORKED = (1u << 31) // Game command is coming from network + GAME_COMMAND_FLAG_4 = (1 << 4), + GAME_COMMAND_FLAG_5 = (1 << 5), + GAME_COMMAND_FLAG_GHOST = (1 << 6), + GAME_COMMAND_FLAG_PATH_SCENERY = (1 << 7), + GAME_COMMAND_FLAG_NETWORKED = (1u << 31) // Game command is coming from network }; -enum { - GAME_PAUSED_NORMAL = 1 << 0, - GAME_PAUSED_MODAL = 1 << 1, - GAME_PAUSED_SAVING_TRACK = 1 << 2, +enum +{ + GAME_PAUSED_NORMAL = 1 << 0, + GAME_PAUSED_MODAL = 1 << 1, + GAME_PAUSED_SAVING_TRACK = 1 << 2, }; -enum { - ERROR_TYPE_NONE = 0, - ERROR_TYPE_GENERIC = 254, +enum +{ + ERROR_TYPE_NONE = 0, + ERROR_TYPE_GENERIC = 254, ERROR_TYPE_FILE_LOAD = 255 }; -typedef void (GAME_COMMAND_POINTER)(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp); +typedef void (GAME_COMMAND_POINTER)(sint32 * eax, sint32 * ebx, sint32 * ecx, sint32 * edx, sint32 * esi, sint32 * edi, sint32 * ebp); typedef void (GAME_COMMAND_CALLBACK_POINTER)(sint32 eax, sint32 ebx, sint32 ecx, sint32 edx, sint32 esi, sint32 edi, sint32 ebp); @@ -126,29 +130,29 @@ typedef void (GAME_COMMAND_CALLBACK_POINTER)(sint32 eax, sint32 ebx, sint32 ecx, extern "C" { #endif -extern GAME_COMMAND_CALLBACK_POINTER* game_command_callback; -sint32 game_command_callback_get_index(GAME_COMMAND_CALLBACK_POINTER* callback); -GAME_COMMAND_CALLBACK_POINTER* game_command_callback_get_callback(sint32 index); +extern GAME_COMMAND_CALLBACK_POINTER * game_command_callback; +sint32 game_command_callback_get_index(GAME_COMMAND_CALLBACK_POINTER * callback); +GAME_COMMAND_CALLBACK_POINTER * game_command_callback_get_callback(sint32 index); extern sint32 game_command_playerid; extern rct_string_id gGameCommandErrorTitle; extern rct_string_id gGameCommandErrorText; -extern uint8 gErrorType; +extern uint8 gErrorType; extern rct_string_id gErrorStringId; -extern GAME_COMMAND_POINTER* new_game_command_table[GAME_COMMAND_COUNT]; +extern GAME_COMMAND_POINTER * new_game_command_table[GAME_COMMAND_COUNT]; extern uint32 gCurrentTicks; extern uint16 gTicksSinceLastUpdate; -extern uint8 gGamePaused; +extern uint8 gGamePaused; extern sint32 gGameSpeed; -extern float gDayNightCycle; -extern bool gInUpdateCode; -extern bool gInMapInitCode; +extern float gDayNightCycle; +extern bool gInUpdateCode; +extern bool gInMapInitCode; extern sint32 gGameCommandNestLevel; -extern bool gGameCommandIsNetworked; -extern char gCurrentLoadedPath[260]; +extern bool gGameCommandIsNetworked; +extern char gCurrentLoadedPath[260]; extern bool gLoadKeepWindowsOpen; @@ -167,14 +171,14 @@ void reset_all_sprite_quadrant_placements(); void update_palette_effects(); sint32 game_do_command(sint32 eax, sint32 ebx, sint32 ecx, sint32 edx, sint32 esi, sint32 edi, sint32 ebp); -sint32 game_do_command_p(sint32 command, sint32 *eax, sint32 *ebx, sint32 *ecx, sint32 *edx, sint32 *esi, sint32 *edi, sint32 *ebp); +sint32 game_do_command_p(sint32 command, sint32 * eax, sint32 * ebx, sint32 * ecx, sint32 * edx, sint32 * esi, sint32 * edi, sint32 * ebp); -void game_log_multiplayer_command(int command, int *eax, int* ebx, int* ecx, int* edx, int* edi, int* ebp); +void game_log_multiplayer_command(int command, int * eax, int * ebx, int * ecx, int * edx, int * edi, int * ebp); void game_load_or_quit_no_save_prompt(); ParkLoadResult * load_from_sv6(const char * path); void game_load_init(); -void game_pause_toggle(sint32 *eax, sint32 *ebx, sint32 *ecx, sint32 *edx, sint32 *esi, sint32 *edi, sint32 *ebp); +void game_pause_toggle(sint32 * eax, sint32 * ebx, sint32 * ecx, sint32 * edx, sint32 * esi, sint32 * edi, sint32 * ebp); void pause_toggle(); bool game_is_paused(); bool game_is_not_paused(); @@ -188,7 +192,7 @@ void rct2_exit_reason(rct_string_id title, rct_string_id body); void game_autosave(); void game_convert_strings_to_utf8(); void game_convert_news_items_to_utf8(); -void game_convert_strings_to_rct2(rct_s6_data *s6); +void game_convert_strings_to_rct2(rct_s6_data * s6); void game_fix_save_vars(); void game_init_all(sint32 mapSize);