From 1a611bc5be1b078361fabf9fa6cddacb4f3b1f76 Mon Sep 17 00:00:00 2001 From: Broxzier Date: Thu, 2 Feb 2017 20:06:27 +0100 Subject: [PATCH] Add setting slope for fences to MP --- src/openrct2/windows/tile_inspector.c | 19 +++++++++++++++++-- src/openrct2/world/map.c | 7 +++++++ src/openrct2/world/tile_inspector.c | 27 +++++++++++++++++++++++++++ src/openrct2/world/tile_inspector.h | 2 ++ 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/openrct2/windows/tile_inspector.c b/src/openrct2/windows/tile_inspector.c index b7fcaa53b7..698435fd81 100644 --- a/src/openrct2/windows/tile_inspector.c +++ b/src/openrct2/windows/tile_inspector.c @@ -769,6 +769,22 @@ static void window_tile_inspector_path_toggle_edge(sint32 element_index, sint32 ); } +static void window_tile_inspector_fence_set_slope(sint32 element_index, sint32 slope_value) +{ + // Make sure only the correct bits are set + assert((slope_value & 0xC0) == slope_value); + + game_do_command( + TILE_INSPECTOR_FENCE_SET_SLOPE, + GAME_COMMAND_FLAG_APPLY, + windowTileInspectorTileX | (windowTileInspectorTileY << 8), + element_index, + GAME_COMMAND_MODIFY_TILE, + slope_value, + 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) @@ -1326,8 +1342,7 @@ static void window_tile_inspector_dropdown(rct_window *w, sint32 widgetIndex, si switch (widgetIndex) { case WIDX_FENCE_DROPDOWN_SLOPE_BUTTON: - mapElement->type &= ~0xC0; - mapElement->type |= dropdownIndex << 6; + window_tile_inspector_fence_set_slope(w->selected_list_item, dropdownIndex << 6); break; } break; diff --git a/src/openrct2/world/map.c b/src/openrct2/world/map.c index a2454ae9dd..2fe355297f 100644 --- a/src/openrct2/world/map.c +++ b/src/openrct2/world/map.c @@ -5684,6 +5684,13 @@ void game_command_modify_tile(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx *ebx = tile_inspector_path_toggle_edge(x, y, element_index, edge_index, flags); return; } + case TILE_INSPECTOR_FENCE_SET_SLOPE: + { + const sint32 element_index = *edx; + const sint32 slope_value = *edi; + *ebx = tile_inspector_fence_set_slope(x, y, element_index, slope_value, 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 1d95c22371..18172e96b1 100644 --- a/src/openrct2/world/tile_inspector.c +++ b/src/openrct2/world/tile_inspector.c @@ -484,3 +484,30 @@ sint32 tile_inspector_path_toggle_edge(sint32 x, sint32 y, sint32 element_index, return 0; } + +sint32 tile_inspector_fence_set_slope(sint32 x, sint32 y, sint32 element_index, sint32 slope_value, sint32 flags) +{ + rct_map_element *const fence_element = map_get_first_element_at(x, y) + element_index; + + if (!fence_element || map_element_get_type(fence_element) != MAP_ELEMENT_TYPE_FENCE) + { + return MONEY32_UNDEFINED; + } + + if (flags & GAME_COMMAND_FLAG_APPLY) + { + // Set new slope value + fence_element->type &= ~0xC0; + fence_element->type |= slope_value; + + 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 c1e2872fdc..af78c91c74 100644 --- a/src/openrct2/world/tile_inspector.h +++ b/src/openrct2/world/tile_inspector.h @@ -44,6 +44,7 @@ typedef enum { TILE_INSPECTOR_SURFACE_TOGGLE_CORNER, TILE_INSPECTOR_SURFACE_TOGGLE_DIAGONAL, TILE_INSPECTOR_PATH_TOGGLE_EDGE, + TILE_INSPECTOR_FENCE_SET_SLOPE, } tile_inspector_instruction; sint32 tile_inspector_insert_corrupt_at(sint32 x, sint32 y, sint16 element_index, sint32 flags); @@ -57,3 +58,4 @@ sint32 tile_inspector_surface_show_park_fences(sint32 x, sint32 y, bool enabled, 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); +sint32 tile_inspector_fence_set_slope(sint32 x, sint32 y, sint32 element_index, sint32 slope_value, sint32 flags);