From 31aa7f045af25a0a946b6df8997d2a0927cfd73a Mon Sep 17 00:00:00 2001 From: Broxzier Date: Fri, 27 Jan 2017 19:12:25 +0100 Subject: [PATCH] Add path edges and corner toggle to MP --- src/openrct2/windows/tile_inspector.c | 34 ++++++++++++++++++++++----- src/openrct2/world/map.c | 7 ++++++ src/openrct2/world/tile_inspector.c | 20 ++++++++++++++++ src/openrct2/world/tile_inspector.h | 2 ++ 4 files changed, 57 insertions(+), 6 deletions(-) diff --git a/src/openrct2/windows/tile_inspector.c b/src/openrct2/windows/tile_inspector.c index 09af59c895..b7fcaa53b7 100644 --- a/src/openrct2/windows/tile_inspector.c +++ b/src/openrct2/windows/tile_inspector.c @@ -755,6 +755,20 @@ static void window_tile_inspector_surface_toggle_diagonal() ); } +static void window_tile_inspector_path_toggle_edge(sint32 element_index, sint32 corner_index) +{ + assert(corner_index >= 0 && corner_index < 8); + game_do_command( + TILE_INSPECTOR_PATH_TOGGLE_EDGE, + GAME_COMMAND_FLAG_APPLY, + windowTileInspectorTileX | (windowTileInspectorTileY << 8), + element_index, + GAME_COMMAND_MODIFY_TILE, + corner_index, + 0 + ); +} + // Copied from track.c (track_remove), and modified for raising/lowering // Not sure if this should be in this file, track.c, or maybe another one static void window_tile_inspector_track_block_height_offset(rct_map_element *mapElement, uint8 offset) @@ -1080,18 +1094,26 @@ static void window_tile_inspector_mouseup(rct_window *w, sint32 widgetIndex) case WIDX_PATH_CHECK_EDGE_S: case WIDX_PATH_CHECK_EDGE_W: case WIDX_PATH_CHECK_EDGE_N: - widget_set_checkbox_value(w, widgetIndex, !widget_is_pressed(w, widgetIndex)); - mapElement->properties.path.edges ^= (1 << (4 + (((widgetIndex - WIDX_PATH_CHECK_EDGE_E) / 2 - get_current_rotation()) & 3))) & 0xF0; - map_invalidate_tile_full(windowTileInspectorTileX << 5, windowTileInspectorTileY << 5); + { + // 0 = east/right, 1 = south/bottom, 2 = west/left, 3 = north/top + const sint32 eswn = (widgetIndex - WIDX_PATH_CHECK_EDGE_E) / 2; + // Transform to world orientation + const sint32 index = (4 + eswn - get_current_rotation()) & 3; + window_tile_inspector_path_toggle_edge(w->selected_list_item, index + 4); // The corners are stored in the 4 most significant bits, hence the + 4 break; + } case WIDX_PATH_CHECK_EDGE_NE: case WIDX_PATH_CHECK_EDGE_SE: case WIDX_PATH_CHECK_EDGE_SW: case WIDX_PATH_CHECK_EDGE_NW: - widget_set_checkbox_value(w, widgetIndex, !widget_is_pressed(w, widgetIndex)); - mapElement->properties.path.edges ^= (1 << (((widgetIndex - WIDX_PATH_CHECK_EDGE_NE) / 2 - get_current_rotation()) & 3)) & 0x0F; - map_invalidate_tile_full(windowTileInspectorTileX << 5, windowTileInspectorTileY << 5); + { + // 0 = NE, 1 = SE, 2 = SW, 3 = NW + const sint32 neseswnw = (widgetIndex - WIDX_PATH_CHECK_EDGE_NE) / 2; + // Transform to world orientation + const sint32 index = (4 + neseswnw - get_current_rotation()) & 3; + window_tile_inspector_path_toggle_edge(w->selected_list_item, index); break; + } } // switch widget index break; diff --git a/src/openrct2/world/map.c b/src/openrct2/world/map.c index 710a38f2c9..a2454ae9dd 100644 --- a/src/openrct2/world/map.c +++ b/src/openrct2/world/map.c @@ -5677,6 +5677,13 @@ void game_command_modify_tile(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx *ebx = tile_inspector_surface_toggle_diagonal(x, y, flags); return; } + case TILE_INSPECTOR_PATH_TOGGLE_EDGE: + { + const sint32 element_index = *edx; + const sint32 edge_index = *edi; + *ebx = tile_inspector_path_toggle_edge(x, y, element_index, edge_index, flags); + return; + } default: log_error("invalid instruction"); *ebx = MONEY32_UNDEFINED; diff --git a/src/openrct2/world/tile_inspector.c b/src/openrct2/world/tile_inspector.c index 69746c86a7..1d95c22371 100644 --- a/src/openrct2/world/tile_inspector.c +++ b/src/openrct2/world/tile_inspector.c @@ -464,3 +464,23 @@ sint32 tile_inspector_surface_toggle_diagonal(sint32 x, sint32 y, sint32 flags) return 0; } + +sint32 tile_inspector_path_toggle_edge(sint32 x, sint32 y, sint32 element_index, sint32 edge_index, sint32 flags) +{ + rct_map_element *const path_element = map_get_first_element_at(x, y) + element_index; + + if (flags & GAME_COMMAND_FLAG_APPLY) + { + path_element->properties.path.edges ^= 1 << edge_index; + + map_invalidate_tile_full(x << 5, y << 5); + + rct_window *const tile_inspector_window = window_find_by_class(WC_TILE_INSPECTOR); + if (tile_inspector_window != NULL && (uint32)x == windowTileInspectorTileX && (uint32)y == windowTileInspectorTileY) + { + window_invalidate(tile_inspector_window); + } + } + + return 0; +} diff --git a/src/openrct2/world/tile_inspector.h b/src/openrct2/world/tile_inspector.h index a181be6d7b..c1e2872fdc 100644 --- a/src/openrct2/world/tile_inspector.h +++ b/src/openrct2/world/tile_inspector.h @@ -43,6 +43,7 @@ typedef enum { TILE_INSPECTOR_SURFACE_SHOW_PARK_FENCES, TILE_INSPECTOR_SURFACE_TOGGLE_CORNER, TILE_INSPECTOR_SURFACE_TOGGLE_DIAGONAL, + TILE_INSPECTOR_PATH_TOGGLE_EDGE, } tile_inspector_instruction; sint32 tile_inspector_insert_corrupt_at(sint32 x, sint32 y, sint16 element_index, sint32 flags); @@ -55,3 +56,4 @@ sint32 tile_inspector_change_base_height_at(sint32 x, sint32 y, sint16 element_i sint32 tile_inspector_surface_show_park_fences(sint32 x, sint32 y, bool enabled, sint32 flags); sint32 tile_inspector_surface_toggle_corner(sint32 x, sint32 y, sint32 corner_index, sint32 flags); sint32 tile_inspector_surface_toggle_diagonal(sint32 x, sint32 y, sint32 flags); +sint32 tile_inspector_path_toggle_edge(sint32 x, sint32 y, sint32 element_index, sint32 corner_index, sint32 flags);