From ab62d3505ac9f5133e87570b6a35d2a246e9fd34 Mon Sep 17 00:00:00 2001 From: Broxzier Date: Mon, 23 Jan 2017 23:38:02 +0100 Subject: [PATCH] Made rotate button work in MP --- src/openrct2/windows/tile_inspector.c | 49 +++++++-------------------- src/openrct2/world/map.c | 6 ++++ src/openrct2/world/tile_inspector.c | 46 +++++++++++++++++++++++++ src/openrct2/world/tile_inspector.h | 2 ++ 4 files changed, 66 insertions(+), 37 deletions(-) diff --git a/src/openrct2/windows/tile_inspector.c b/src/openrct2/windows/tile_inspector.c index 61a393f308..4756a01f7d 100644 --- a/src/openrct2/windows/tile_inspector.c +++ b/src/openrct2/windows/tile_inspector.c @@ -460,7 +460,7 @@ 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 element_index); -static void window_tile_inspector_rotate_element(sint32 index); +static void window_tile_inspector_rotate_element(sint32 element_index); static void window_tile_inspector_sort_elements(rct_window *w); static void window_tile_inspector_copy_element(rct_window *w); static void window_tile_inspector_paste_element(rct_window *w); @@ -635,42 +635,18 @@ static void window_tile_inspector_remove_element(sint32 element_index) ); } -static void window_tile_inspector_rotate_element(sint32 index) +static void window_tile_inspector_rotate_element(sint32 element_index) { - uint8 newRotation, pathEdges, pathCorners; - - assert(index < windowTileInspectorElementCount); - rct_map_element *const mapElement = map_get_first_element_at(windowTileInspectorTileX, windowTileInspectorTileY) + index; - switch (map_element_get_type(mapElement)) { - case MAP_ELEMENT_TYPE_PATH: - if (footpath_element_is_sloped(mapElement)) { - newRotation = (footpath_element_get_slope_direction(mapElement) + 1) & MAP_ELEMENT_DIRECTION_MASK; - mapElement->properties.path.type &= ~MAP_ELEMENT_DIRECTION_MASK; - mapElement->properties.path.type |= newRotation; - } - pathEdges = mapElement->properties.path.edges & 0x0F; - pathCorners = mapElement->properties.path.edges & 0xF0; - mapElement->properties.path.edges = 0; - mapElement->properties.path.edges |= ((pathEdges << 1) | (pathEdges >> 3)) & 0x0F; - mapElement->properties.path.edges |= ((pathCorners << 1) | (pathCorners >> 3)) & 0xF0; - break; - case MAP_ELEMENT_TYPE_TRACK: - case MAP_ELEMENT_TYPE_SCENERY: - case MAP_ELEMENT_TYPE_ENTRANCE: - case MAP_ELEMENT_TYPE_FENCE: - newRotation = (mapElement->type + 1) & MAP_ELEMENT_DIRECTION_MASK; - mapElement->type &= ~MAP_ELEMENT_DIRECTION_MASK; - mapElement->type |= newRotation; - break; - case MAP_ELEMENT_TYPE_BANNER: - mapElement->properties.banner.flags ^= 1 << mapElement->properties.banner.position; - mapElement->properties.banner.position++; - mapElement->properties.banner.position &= 3; - mapElement->properties.banner.flags ^= 1 << mapElement->properties.banner.position; - break; - } - - map_invalidate_tile_full(windowTileInspectorTileX << 5, windowTileInspectorTileY << 5); + assert(element_index < windowTileInspectorElementCount); + game_do_command( + TILE_INSPECTOR_ANY_ROTATE, + GAME_COMMAND_FLAG_APPLY, + windowTileInspectorTileX | (windowTileInspectorTileY << 8), + element_index, + GAME_COMMAND_MODIFY_TILE, + 0, + 0 + ); } // Swap element with its parent @@ -1026,7 +1002,6 @@ static void window_tile_inspector_mouseup(rct_window *w, sint32 widgetIndex) break; case WIDX_BUTTON_ROTATE: window_tile_inspector_rotate_element(w->selected_list_item); - window_invalidate(w); break; case WIDX_BUTTON_SORT: window_tile_inspector_sort_elements(w); diff --git a/src/openrct2/world/map.c b/src/openrct2/world/map.c index 77b6a1634e..73947f368e 100644 --- a/src/openrct2/world/map.c +++ b/src/openrct2/world/map.c @@ -5633,6 +5633,12 @@ void game_command_modify_tile(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx *ebx = tile_inspector_insert_corrupt_at(x, y, index, flags); return; } + case TILE_INSPECTOR_ANY_ROTATE: + { + const sint16 index = *edx; + *ebx = tile_inspector_rotate_element_at(x, y, 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 e4699584e1..61d8608817 100644 --- a/src/openrct2/world/tile_inspector.c +++ b/src/openrct2/world/tile_inspector.c @@ -17,6 +17,7 @@ #include "../game.h" #include "../interface/window.h" #include "../windows/tile_inspector.h" +#include "footpath.h" #include "map.h" #include "tile_inspector.h" @@ -176,3 +177,48 @@ sint32 tile_inspector_swap_elements(sint32 x, sint32 y, sint16 first, sint16 sec return 0; } + +sint32 tile_inspector_rotate_element_at(sint32 x, sint32 y, sint32 element_index, sint32 flags) +{ + if (flags & GAME_COMMAND_FLAG_APPLY) + { + uint8 newRotation, pathEdges, pathCorners; + + rct_map_element *const mapElement = map_get_first_element_at(x, y) + element_index; + switch (map_element_get_type(mapElement)) + { + case MAP_ELEMENT_TYPE_PATH: + if (footpath_element_is_sloped(mapElement)) + { + newRotation = (footpath_element_get_slope_direction(mapElement) + 1) & MAP_ELEMENT_DIRECTION_MASK; + mapElement->properties.path.type &= ~MAP_ELEMENT_DIRECTION_MASK; + mapElement->properties.path.type |= newRotation; + } + pathEdges = mapElement->properties.path.edges & 0x0F; + pathCorners = mapElement->properties.path.edges & 0xF0; + mapElement->properties.path.edges = 0; + mapElement->properties.path.edges |= ((pathEdges << 1) | (pathEdges >> 3)) & 0x0F; + mapElement->properties.path.edges |= ((pathCorners << 1) | (pathCorners >> 3)) & 0xF0; + break; + case MAP_ELEMENT_TYPE_TRACK: + case MAP_ELEMENT_TYPE_SCENERY: + case MAP_ELEMENT_TYPE_ENTRANCE: + case MAP_ELEMENT_TYPE_FENCE: + newRotation = (mapElement->type + 1) & MAP_ELEMENT_DIRECTION_MASK; + mapElement->type &= ~MAP_ELEMENT_DIRECTION_MASK; + mapElement->type |= newRotation; + break; + case MAP_ELEMENT_TYPE_BANNER: + mapElement->properties.banner.flags ^= 1 << mapElement->properties.banner.position; + mapElement->properties.banner.position++; + mapElement->properties.banner.position &= 3; + mapElement->properties.banner.flags ^= 1 << mapElement->properties.banner.position; + break; + } + + map_invalidate_tile_full(x << 5, y << 5); + window_invalidate_by_class(WC_TILE_INSPECTOR); + } + + return 0; +} diff --git a/src/openrct2/world/tile_inspector.h b/src/openrct2/world/tile_inspector.h index 16c11f599a..ffb8dd0ba5 100644 --- a/src/openrct2/world/tile_inspector.h +++ b/src/openrct2/world/tile_inspector.h @@ -35,8 +35,10 @@ typedef enum { TILE_INSPECTOR_ANY_REMOVE, TILE_INSPECTOR_ANY_SWAP, TILE_INSPECTOR_ANY_INSERT_CORRUPT, + TILE_INSPECTOR_ANY_ROTATE, } tile_inspector_instruction; sint32 tile_inspector_insert_corrupt_at(sint32 x, sint32 y, sint16 element_index, sint32 flags); sint32 tile_inspector_remove_element_at(sint32 x, sint32 y, sint16 element_index, sint32 flags); sint32 tile_inspector_swap_elements(sint32 x, sint32 y, sint16 first, sint16 second, sint32 flags); +sint32 tile_inspector_rotate_element_at(sint32 x, sint32 y, sint32 element_index, sint32 flags); \ No newline at end of file