diff --git a/src/openrct2/windows/tile_inspector.c b/src/openrct2/windows/tile_inspector.c index 699a8580ee..f8265113df 100644 --- a/src/openrct2/windows/tile_inspector.c +++ b/src/openrct2/windows/tile_inspector.c @@ -442,15 +442,15 @@ static struct { { COR_GBDT, COR_GBDB, COR_GBPT, COR_GBPB, STR_TILE_INSPECTOR_GROUPBOX_CORRUPT_INFO } }; +uint32 windowTileInspectorTileX; +uint32 windowTileInspectorTileY; +sint32 windowTileInspectorElementCount = 0; static sint16 windowTileInspectorHighlightedIndex = -1; -static uint32 windowTileInspectorTileX; -static uint32 windowTileInspectorTileY; static bool windowTileInspectorTileSelected = false; static sint32 windowTileInspectorToolMouseX = 0; static sint32 windowTileInspectorToolMouseY = 0; static sint32 windowTileInspectorToolMapX = 0; static sint32 windowTileInspectorToolMapY = 0; -sint32 windowTileInspectorElementCount = 0; static bool windowTileInspectorApplyToAll = false; static bool windowTileInspectorElementCopied = false; static rct_map_element tileInspectorCopiedElement; @@ -459,7 +459,7 @@ static rct_map_element* window_tile_inspector_get_selected_element(rct_window *w static void window_tile_inspector_load_tile(rct_window* w); static void window_tile_inspector_insert_corrupt_element(sint32 element_index); static void window_tile_inspector_swap_elements(sint16 first, sint16 second); -static void window_tile_inspector_remove_element(sint32 index); +static void window_tile_inspector_remove_element(sint32 element_index); static void window_tile_inspector_rotate_element(sint32 index); static void window_tile_inspector_sort_elements(rct_window *w); static void window_tile_inspector_copy_element(rct_window *w); @@ -621,13 +621,14 @@ static void window_tile_inspector_insert_corrupt_element(sint32 element_index) ); } -static void window_tile_inspector_remove_element(sint32 index) +static void window_tile_inspector_remove_element(sint32 element_index) { + assert(element_index < windowTileInspectorElementCount); game_do_command( TILE_INSPECTOR_ELEMENT_ANY, GAME_COMMAND_FLAG_APPLY, windowTileInspectorTileX | (windowTileInspectorTileY << 8), - index, + element_index, GAME_COMMAND_MODIFY_TILE, 0, 0 diff --git a/src/openrct2/windows/tile_inspector.h b/src/openrct2/windows/tile_inspector.h index 76c59d9dce..e8b96b65ee 100644 --- a/src/openrct2/windows/tile_inspector.h +++ b/src/openrct2/windows/tile_inspector.h @@ -33,6 +33,8 @@ typedef enum tile_inspector_page PAGE_CORRUPT } tile_inspector_page; +extern uint32 windowTileInspectorTileX; +extern uint32 windowTileInspectorTileY; extern sint32 windowTileInspectorElementCount; void window_tile_inspector_set_page(rct_window *w, const tile_inspector_page page); diff --git a/src/openrct2/world/tile_inspector.c b/src/openrct2/world/tile_inspector.c index 34c0e561a4..09cdf44d53 100644 --- a/src/openrct2/world/tile_inspector.c +++ b/src/openrct2/world/tile_inspector.c @@ -90,7 +90,7 @@ sint32 tile_inspector_insert_corrupt_at(sint32 x, sint32 y, sint16 element_index // Update the tile inspector's list for everyone who has the tile selected rct_window *const tile_inspector_window = window_find_by_class(WC_TILE_INSPECTOR); - if (tile_inspector_window != NULL) + if (tile_inspector_window != NULL && (uint32)x == windowTileInspectorTileX && (uint32)y == windowTileInspectorTileY) { windowTileInspectorElementCount++; @@ -121,13 +121,14 @@ sint32 tile_inspector_remove_element_at(sint32 x, sint32 y, sint16 element_index // Forcefully the element rct_map_element *const mapElement = map_get_first_element_at(x, y) + element_index; map_element_remove(mapElement); - windowTileInspectorElementCount--; map_invalidate_tile_full(x << 5, y << 5); // Update the window rct_window *const tile_inspector_window = window_find_by_class(WC_TILE_INSPECTOR); - if (tile_inspector_window != NULL) + if (tile_inspector_window != NULL && (uint32)x == windowTileInspectorTileX && (uint32)y == windowTileInspectorTileY) { + windowTileInspectorElementCount--; + if (tile_inspector_window->selected_list_item > element_index) { tile_inspector_window->selected_list_item--;