From 5e3df2241423109ac637dc6c13f5be4e84bc6e87 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sun, 28 Jun 2015 13:31:46 +0100 Subject: [PATCH 1/3] Implemented map element remove. Small tidy of functions in game.c. --- src/game.c | 4 ++-- src/world/map.c | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/game.c b/src/game.c index cfd8ba82b1..d5b3ddfe3d 100644 --- a/src/game.c +++ b/src/game.c @@ -870,7 +870,7 @@ void rct2_exit_reason(rct_string_id title, rct_string_id body){ */ void rct2_exit() { - RCT2_CALLPROC_EBPSAFE(0x006E3879); + audio_close(); //Post quit message does not work in 0x6e3879 as its windows only. openrct2_finish(); } @@ -892,7 +892,7 @@ void game_load_or_quit_no_save_prompt() game_do_command(0, 1, 0, 1, GAME_COMMAND_LOAD_OR_QUIT, 0, 0); tool_cancel(); if (RCT2_GLOBAL(RCT2_ADDRESS_INPUT_FLAGS, uint32) & INPUT_FLAG_5) { - RCT2_CALLPROC_EBPSAFE(0x0040705E); + // RCT2_CALLPROC_EBPSAFE(0x0040705E); Function not required resets cursor position. RCT2_GLOBAL(RCT2_ADDRESS_INPUT_FLAGS, uint32) &= ~INPUT_FLAG_5; } gGameSpeed = 1; diff --git a/src/world/map.c b/src/world/map.c index 602be3f4ee..4fa4596e64 100644 --- a/src/world/map.c +++ b/src/world/map.c @@ -2637,7 +2637,17 @@ int map_get_station(rct_map_element *mapElement) */ void map_element_remove(rct_map_element *mapElement) { - RCT2_CALLPROC_X(0x0068B280, 0, 0, 0, 0, (int)mapElement, 0, 0); + if (!map_element_is_last_for_tile(mapElement)){ + do{ + *mapElement = *(mapElement + 1); + } while (!map_element_is_last_for_tile(++mapElement)); + } + (mapElement - 1)->flags |= MAP_ELEMENT_FLAG_LAST_TILE; + mapElement->base_height = 0xFF; + + if ((mapElement + 1) == RCT2_GLOBAL(0x00140E9A4, rct_map_element*)){ + RCT2_GLOBAL(0x00140E9A4, rct_map_element*)--; + } } /** From 8167c24526b1d357fb621c5dce66b49a5ec9101d Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sun, 28 Jun 2015 13:53:24 +0100 Subject: [PATCH 2/3] Implemented sub_68B044 some sort of check to make sure there is space for new element. If there isn't then it will try reorganise the elements to make room. --- src/addresses.h | 1 + src/world/map.c | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/addresses.h b/src/addresses.h index 224a5966f4..c9311354d7 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -354,6 +354,7 @@ #define RCT2_ADDRESS_SCENARIO_SRAND_0 0x00F663B0 #define RCT2_ADDRESS_SCENARIO_SRAND_1 0x00F663B4 #define RCT2_ADDRESS_MAP_ELEMENTS 0x00F663B8 +#define RCT2_ADDRESS_MAP_ELEMENTS_END 0x010E53B8 #define RCT2_ADDRESS_SPRITE_LIST 0x010E63BC #define RCT2_ADDRESS_SPRITES_NEXT_INDEX 0x013573BC diff --git a/src/world/map.c b/src/world/map.c index 4fa4596e64..1f6fe730d6 100644 --- a/src/world/map.c +++ b/src/world/map.c @@ -2744,7 +2744,23 @@ void map_reorganise_elements() */ int sub_68B044() { - return (RCT2_CALLPROC_X(0x0068B044, 0, 0, 0, 0, 0, 0, 0) & 0x100) == 0; + if (RCT2_GLOBAL(0x00140E9A4, rct_map_element*) <= RCT2_ADDRESS(RCT2_ADDRESS_MAP_ELEMENTS_END, rct_map_element)) + return 1; + + for (int i = 1000; i != 0; --i) + sub_68B089(); + + if (RCT2_GLOBAL(0x00140E9A4, rct_map_element*) <= RCT2_ADDRESS(RCT2_ADDRESS_MAP_ELEMENTS_END, rct_map_element)) + return 1; + + map_reorganise_elements(); + + if (RCT2_GLOBAL(0x00140E9A4, rct_map_element*) <= RCT2_ADDRESS(RCT2_ADDRESS_MAP_ELEMENTS_END, rct_map_element)) + return 1; + else{ + RCT2_GLOBAL(0x00141E9AC, rct_string_id) = 894; + return 0; + } } /** From 33c4698e0642d9ec7f3961356a86c58f452e9c12 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sun, 28 Jun 2015 16:50:21 +0100 Subject: [PATCH 3/3] Implemented map_reorganise_elements. Fixed a potential issue that would cause cursors to become stuck. --- src/platform/shared.c | 1 + src/world/map.c | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/platform/shared.c b/src/platform/shared.c index a0a929c8b4..77418e2137 100644 --- a/src/platform/shared.c +++ b/src/platform/shared.c @@ -646,6 +646,7 @@ void platform_set_fullscreen_mode(int mode) */ void platform_set_cursor(char cursor) { + RCT2_GLOBAL(RCT2_ADDRESS_CURENT_CURSOR, uint8) = cursor; SDL_SetCursor(_cursors[cursor]); } /** diff --git a/src/world/map.c b/src/world/map.c index 1f6fe730d6..46e4a2f95f 100644 --- a/src/world/map.c +++ b/src/world/map.c @@ -35,6 +35,7 @@ #include "scenery.h" #include "../cheats.h" #include "../config.h" +#include "../cursors.h" const rct_xy16 TileDirectionDelta[] = { { -32, 0 }, @@ -2735,7 +2736,36 @@ void map_invalidate_selection_rect() */ void map_reorganise_elements() { - RCT2_CALLPROC_EBPSAFE(0x0068B111); + platform_set_cursor(CURSOR_ZZZ); + + rct_map_element* new_map_elements = rct2_malloc(0x30000 * sizeof(rct_map_element)); + rct_map_element* new_elements_pointer = new_map_elements; + + if (new_map_elements == NULL || new_map_elements == (rct_map_element*)-1){ + error_string_quit(4370, 0xFFFF); + return; + } + + rct_map_element **tile = RCT2_ADDRESS(RCT2_ADDRESS_TILE_MAP_ELEMENT_POINTERS, rct_map_element*); + for (int i = 0; i < 0x10000;){ + for (int j = 0; j < 256; ++j, ++i){ + rct_map_element* startElement = tile[i]; + rct_map_element* endElement = startElement; + while (!map_element_is_last_for_tile(endElement++)); + + uint8 num_bytes = endElement - startElement; + memcpy(new_elements_pointer, startElement, num_bytes); + new_elements_pointer += num_bytes / sizeof(rct_map_element); + } + } + + uint32 num_elements = (new_elements_pointer - new_map_elements) / sizeof(rct_map_element); + memcpy(RCT2_ADDRESS(RCT2_ADDRESS_MAP_ELEMENTS, rct_map_element), new_map_elements, num_elements * sizeof(rct_map_element)); + memset(new_map_elements + num_elements, 0, (0x30000 - num_elements) * sizeof(rct_map_element)); + + rct2_free(new_map_elements); + + map_update_tile_pointers(); } /**