From 37f59e17dc9300cf5ab5475a237bd42ba26dd4bf Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 16 Sep 2018 16:17:35 +0200 Subject: [PATCH] Replace C-style isSloped() function --- src/openrct2-ui/windows/Footpath.cpp | 15 +++-- src/openrct2-ui/windows/RideConstruction.cpp | 4 +- src/openrct2-ui/windows/TileInspector.cpp | 4 +- .../paint/tile_element/Paint.Path.cpp | 34 +++++----- src/openrct2/peep/Guest.cpp | 2 +- src/openrct2/peep/GuestPathfinding.cpp | 16 ++--- src/openrct2/peep/Peep.cpp | 9 ++- src/openrct2/peep/Staff.cpp | 2 +- src/openrct2/rct1/S4Importer.cpp | 2 +- src/openrct2/ride/TrackDesignSave.cpp | 3 +- src/openrct2/world/Footpath.cpp | 62 +++++++++---------- src/openrct2/world/Footpath.h | 2 - src/openrct2/world/Map.cpp | 16 ++--- src/openrct2/world/Map.h | 2 +- src/openrct2/world/TileElement.h | 6 +- src/openrct2/world/TileInspector.cpp | 2 +- test/tests/TileElements.cpp | 2 +- 17 files changed, 94 insertions(+), 89 deletions(-) diff --git a/src/openrct2-ui/windows/Footpath.cpp b/src/openrct2-ui/windows/Footpath.cpp index d7fb758cfe..6e64b61454 100644 --- a/src/openrct2-ui/windows/Footpath.cpp +++ b/src/openrct2-ui/windows/Footpath.cpp @@ -824,7 +824,7 @@ static void window_footpath_set_selection_start_bridge_at_point(int32_t screenX, */ static void window_footpath_place_path_at_point(int32_t x, int32_t y) { - int32_t interactionType, presentType, selectedType, z, cost; + int32_t interactionType, currentType, selectedType, z, cost; rct_tile_element* tileElement; if (_footpathErrorOccured) @@ -847,15 +847,18 @@ static void window_footpath_place_path_at_point(int32_t x, int32_t y) } // Set path - presentType = 0; + currentType = 0; switch (interactionType) { case VIEWPORT_INTERACTION_ITEM_TERRAIN: - presentType = DefaultPathSlope[tileElement->AsSurface()->GetSlope() & TILE_ELEMENT_SURFACE_RAISED_CORNERS_MASK]; + currentType = DefaultPathSlope[tileElement->AsSurface()->GetSlope() & TILE_ELEMENT_SURFACE_RAISED_CORNERS_MASK]; break; case VIEWPORT_INTERACTION_ITEM_FOOTPATH: - presentType = tileElement->properties.path.type - & (FOOTPATH_PROPERTIES_FLAG_IS_SLOPED | FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK); + currentType = tileElement->properties.path.type & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK; + if (tileElement->AsPath()->IsSloped()) + { + currentType |= FOOTPATH_PROPERTIES_FLAG_IS_SLOPED; + } break; } z = tileElement->base_height; @@ -863,7 +866,7 @@ static void window_footpath_place_path_at_point(int32_t x, int32_t y) // Try and place path gGameCommandErrorTitle = STR_CANT_BUILD_FOOTPATH_HERE; - cost = footpath_place(selectedType, x, y, z, presentType, GAME_COMMAND_FLAG_APPLY); + cost = footpath_place(selectedType, x, y, z, currentType, GAME_COMMAND_FLAG_APPLY); if (cost == MONEY32_UNDEFINED) { diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index 85b34e7930..15b31d934a 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -3601,7 +3601,7 @@ void ride_construction_toolupdate_construct(int32_t screenX, int32_t screenY) { pathsByDir[i] = map_get_footpath_element((x >> 5) + DirOffsets[i].x, (y >> 5) + DirOffsets[i].y, z >> 3); - if (pathsByDir[i] && footpath_element_is_sloped(pathsByDir[i]) + if (pathsByDir[i] && (pathsByDir[i])->AsPath()->IsSloped() && footpath_element_get_slope_direction(pathsByDir[i]) != i) { pathsByDir[i] = nullptr; @@ -3613,7 +3613,7 @@ void ride_construction_toolupdate_construct(int32_t screenX, int32_t screenY) pathsByDir[i] = map_get_footpath_element((x >> 5) + DirOffsets[i].x, (y >> 5) + DirOffsets[i].y, (z >> 3) - 2); if (pathsByDir[i] - && (!footpath_element_is_sloped(pathsByDir[i]) + && (!(pathsByDir[i])->AsPath()->IsSloped() || footpath_element_get_slope_direction(pathsByDir[i]) != (i ^ 2))) { pathsByDir[i] = nullptr; diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index 9bacba3479..a4aa0532a2 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -866,7 +866,7 @@ static void window_tile_inspector_mouseup(rct_window* w, rct_widgetindex widgetI { case WIDX_PATH_CHECK_SLOPED: window_tile_inspector_path_set_sloped( - windowTileInspectorSelectedIndex, !footpath_element_is_sloped(tileElement)); + windowTileInspectorSelectedIndex, !tileElement->AsPath()->IsSloped()); break; case WIDX_PATH_CHECK_EDGE_E: case WIDX_PATH_CHECK_EDGE_S: @@ -1514,7 +1514,7 @@ static void window_tile_inspector_invalidate(rct_window* w) w->widgets[WIDX_PATH_CHECK_EDGE_W].bottom = w->widgets[WIDX_PATH_CHECK_EDGE_W].top + 13; w->widgets[WIDX_PATH_CHECK_EDGE_NW].top = GBBT(propertiesAnchor, 2) + 7 * 1; w->widgets[WIDX_PATH_CHECK_EDGE_NW].bottom = w->widgets[WIDX_PATH_CHECK_EDGE_NW].top + 13; - widget_set_checkbox_value(w, WIDX_PATH_CHECK_SLOPED, footpath_element_is_sloped(tileElement)); + widget_set_checkbox_value(w, WIDX_PATH_CHECK_SLOPED, tileElement->AsPath()->IsSloped()); widget_set_checkbox_value( w, WIDX_PATH_CHECK_EDGE_NE, tileElement->properties.path.edges & (1 << ((0 - get_current_rotation()) & 3))); widget_set_checkbox_value( diff --git a/src/openrct2/paint/tile_element/Paint.Path.cpp b/src/openrct2/paint/tile_element/Paint.Path.cpp index 463ab79a16..f56718fd41 100644 --- a/src/openrct2/paint/tile_element/Paint.Path.cpp +++ b/src/openrct2/paint/tile_element/Paint.Path.cpp @@ -89,7 +89,7 @@ static void path_bit_lights_paint( paint_session* session, rct_scenery_entry* pathBitEntry, const rct_tile_element* tileElement, int32_t height, uint8_t edges, uint32_t pathBitImageFlags) { - if (footpath_element_is_sloped(tileElement)) + if (tileElement->AsPath()->IsSloped()) height += 8; uint32_t imageId; @@ -147,7 +147,7 @@ static void path_bit_bins_paint( paint_session* session, rct_scenery_entry* pathBitEntry, const rct_tile_element* tileElement, int32_t height, uint8_t edges, uint32_t pathBitImageFlags) { - if (footpath_element_is_sloped(tileElement)) + if (tileElement->AsPath()->IsSloped()) height += 8; uint32_t imageId; @@ -323,7 +323,7 @@ static void sub_6A4101( if (tile_element->AsPath()->IsQueue()) { uint8_t local_ebp = ebp & 0x0F; - if (footpath_element_is_sloped(tile_element)) + if (tile_element->AsPath()->IsSloped()) { switch ((footpath_element_get_slope_direction(tile_element) + session->CurrentRotation) & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK) @@ -412,7 +412,7 @@ static void sub_6A4101( uint8_t direction = footpath_element_get_direction(tile_element); // Draw ride sign session->InteractionType = VIEWPORT_INTERACTION_ITEM_RIDE; - if (footpath_element_is_sloped(tile_element)) + if (tile_element->AsPath()->IsSloped()) { if (footpath_element_get_slope_direction(tile_element) == direction) height += 16; @@ -487,7 +487,7 @@ static void sub_6A4101( dword_F3EF80 &= 0x0F; } - if (footpath_element_is_sloped(tile_element)) + if (tile_element->AsPath()->IsSloped()) { switch ((footpath_element_get_slope_direction(tile_element) + session->CurrentRotation) & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK) @@ -739,7 +739,7 @@ static void sub_6A3F61( // This is about tunnel drawing uint8_t direction = (footpath_element_get_slope_direction(tile_element) + session->CurrentRotation) & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK; - bool sloped = footpath_element_is_sloped(tile_element); + bool sloped = tile_element->AsPath()->IsSloped(); if (connectedEdges & EDGE_SE) { @@ -856,7 +856,7 @@ void path_paint(paint_session* session, uint16_t height, const rct_tile_element* } else { - if (footpath_element_is_sloped(tile_element)) + if (tile_element->AsPath()->IsSloped()) { // Diagonal path @@ -898,7 +898,7 @@ void path_paint(paint_session* session, uint16_t height, const rct_tile_element* { uint32_t imageId = 2618; int32_t height2 = tile_element->base_height * 8; - if (footpath_element_is_sloped(tile_element)) + if (tile_element->AsPath()->IsSloped()) { imageId = 2619 + ((footpath_element_get_slope_direction(tile_element) + session->CurrentRotation) & 3); height2 += 16; @@ -911,7 +911,7 @@ void path_paint(paint_session* session, uint16_t height, const rct_tile_element* if (gCurrentViewportFlags & VIEWPORT_FLAG_PATH_HEIGHTS) { uint16_t height2 = 3 + tile_element->base_height * 8; - if (footpath_element_is_sloped(tile_element)) + if (tile_element->AsPath()->IsSloped()) { height2 += 8; } @@ -989,7 +989,7 @@ void path_paint_box_support( uint16_t edi = edges | (corners << 4); uint32_t imageId; - if (footpath_element_is_sloped(tileElement)) + if (tileElement->AsPath()->IsSloped()) { imageId = ((footpath_element_get_slope_direction(tileElement) + session->CurrentRotation) & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK) @@ -1036,7 +1036,7 @@ void path_paint_box_support( else { uint32_t image_id; - if (footpath_element_is_sloped(tileElement)) + if (tileElement->AsPath()->IsSloped()) { image_id = ((footpath_element_get_slope_direction(tileElement) + session->CurrentRotation) & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK) @@ -1066,7 +1066,7 @@ void path_paint_box_support( sub_6A3F61(session, tileElement, edi, height, footpathEntry, imageFlags, sceneryImageFlags, hasFences); uint16_t ax = 0; - if (footpath_element_is_sloped(tileElement)) + if (tileElement->AsPath()->IsSloped()) { ax = ((footpath_element_get_slope_direction(tileElement) + session->CurrentRotation) & 0x3) + 1; } @@ -1081,7 +1081,7 @@ void path_paint_box_support( } height += 32; - if (footpath_element_is_sloped(tileElement)) + if (tileElement->AsPath()->IsSloped()) { height += 16; } @@ -1143,7 +1143,7 @@ void path_paint_pole_support( uint16_t edi = edges | (corners << 4); uint32_t imageId; - if (footpath_element_is_sloped(tileElement)) + if (tileElement->AsPath()->IsSloped()) { imageId = ((footpath_element_get_slope_direction(tileElement) + session->CurrentRotation) & 3) + 16; } @@ -1189,7 +1189,7 @@ void path_paint_pole_support( else { uint32_t bridgeImage; - if (footpath_element_is_sloped(tileElement)) + if (tileElement->AsPath()->IsSloped()) { bridgeImage = ((footpath_element_get_slope_direction(tileElement) + session->CurrentRotation) & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK) @@ -1216,7 +1216,7 @@ void path_paint_pole_support( sub_6A3F61(session, tileElement, edi, height, footpathEntry, imageFlags, sceneryImageFlags, hasFences); // TODO: arguments uint16_t ax = 0; - if (footpath_element_is_sloped(tileElement)) + if (tileElement->AsPath()->IsSloped()) { ax = 8; } @@ -1237,7 +1237,7 @@ void path_paint_pole_support( } height += 32; - if (footpath_element_is_sloped(tileElement)) + if (tileElement->AsPath()->IsSloped()) { height += 16; } diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index 45cd9f2249..6caa694228 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -4914,7 +4914,7 @@ void rct_peep::UpdateRideLeaveExit() if (tileElement->GetType() != TILE_ELEMENT_TYPE_PATH) continue; - int16_t height = map_height_from_slope(x, y, tileElement->properties.path.type); + int16_t height = map_height_from_slope({x, y}, tileElement->properties.path.type, tileElement->AsPath()->IsSloped()); height += tileElement->base_height * 8; int16_t z_diff = z - height; diff --git a/src/openrct2/peep/GuestPathfinding.cpp b/src/openrct2/peep/GuestPathfinding.cpp index 323bf710e3..b97e36cfc4 100644 --- a/src/openrct2/peep/GuestPathfinding.cpp +++ b/src/openrct2/peep/GuestPathfinding.cpp @@ -226,7 +226,7 @@ static uint8_t footpath_element_next_in_direction(TileCoordsXYZ loc, rct_tile_el { rct_tile_element* nextTileElement; - if (footpath_element_is_sloped(tileElement)) + if (tileElement->AsPath()->IsSloped()) { if (footpath_element_get_slope_direction(tileElement) == chosenDirection) { @@ -354,7 +354,7 @@ static uint8_t footpath_element_dest_in_dir( if (edges != 0) return PATH_SEARCH_JUNCTION; - if (footpath_element_is_sloped(tileElement)) + if (tileElement->AsPath()->IsSloped()) { if (footpath_element_get_slope_direction(tileElement) == direction) { @@ -396,7 +396,7 @@ static uint8_t footpath_element_dest_in_dir( static uint8_t footpath_element_destination_in_direction( TileCoordsXYZ loc, rct_tile_element* inputTileElement, uint8_t chosenDirection, uint8_t* outRideIndex) { - if (footpath_element_is_sloped(inputTileElement)) + if (inputTileElement->AsPath()->IsSloped()) { if (footpath_element_get_slope_direction(inputTileElement) == chosenDirection) { @@ -1087,7 +1087,7 @@ static void peep_pathfind_heuristic_search( uint8_t savedNumJunctions = _peepPathFindNumJunctions; uint8_t height = loc.z; - if (footpath_element_is_sloped(tileElement) && footpath_element_get_slope_direction(tileElement) == next_test_edge) + if (tileElement->AsPath()->IsSloped() && footpath_element_get_slope_direction(tileElement) == next_test_edge) { height += 2; } @@ -1353,7 +1353,7 @@ int32_t peep_pathfind_choose_direction(TileCoordsXYZ loc, rct_peep* peep) edges &= ~(1 << test_edge); uint8_t height = loc.z; - if (footpath_element_is_sloped(first_tile_element) + if (first_tile_element->AsPath()->IsSloped() && footpath_element_get_slope_direction(first_tile_element) == test_edge) { height += 0x2; @@ -1764,7 +1764,7 @@ static void get_ride_queue_end(TileCoordsXYZ& loc) // Update the current queue end queueEnd = nextTile; // queueEnd.direction = direction; - if (footpath_element_is_sloped(tileElement)) + if (tileElement->AsPath()->IsSloped()) { if (footpath_element_get_slope_direction(tileElement) == direction) { @@ -1786,7 +1786,7 @@ static void get_ride_queue_end(TileCoordsXYZ& loc) if (baseZ == tileElement->base_height) { - if (footpath_element_is_sloped(tileElement)) + if (tileElement->AsPath()->IsSloped()) { if (footpath_element_get_slope_direction(tileElement) != direction) { @@ -1799,7 +1799,7 @@ static void get_ride_queue_end(TileCoordsXYZ& loc) if (baseZ - 2 == tileElement->base_height) { - if (!footpath_element_is_sloped(tileElement)) + if (!tileElement->AsPath()->IsSloped()) break; if (footpath_element_get_slope_direction(tileElement) != (direction ^ 2)) diff --git a/src/openrct2/peep/Peep.cpp b/src/openrct2/peep/Peep.cpp index 0919e594d0..56630e49a6 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -1021,7 +1021,7 @@ void rct_peep::UpdateFalling() // If a path check if we are on it if (tile_element->GetType() == TILE_ELEMENT_TYPE_PATH) { - int32_t height = map_height_from_slope(x, y, tile_element->properties.path.type) + int32_t height = map_height_from_slope({x, y}, tile_element->properties.path.type, tile_element->AsPath()->IsSloped()) + tile_element->base_height * 8; if (height < z - 1 || height > z + 4) @@ -2634,7 +2634,7 @@ static void peep_interact_with_entrance( if (nextTileElement->AsPath()->IsQueue()) continue; - if (footpath_element_is_sloped(nextTileElement)) + if (nextTileElement->AsPath()->IsSloped()) { uint8_t slopeDirection = footpath_element_get_slope_direction(nextTileElement); if (slopeDirection == entranceDirection) @@ -3093,7 +3093,7 @@ static bool peep_interact_with_shop(rct_peep* peep, int16_t x, int16_t y, rct_ti bool is_valid_path_z_and_direction(rct_tile_element* tileElement, int32_t currentZ, int32_t currentDirection) { - if (footpath_element_is_sloped(tileElement)) + if (tileElement->AsPath()->IsSloped()) { int32_t slopeDirection = footpath_element_get_slope_direction(tileElement); if (slopeDirection == currentDirection) @@ -3457,8 +3457,7 @@ int32_t rct_peep::GetZOnSlope(int32_t tile_x, int32_t tile_y) int32_t height = next_z * 8; uint8_t slope = GetNextDirection(); - slope |= GetNextIsSloped() ? (1 << 2) : 0; - return height + map_height_from_slope(tile_x, tile_y, slope); + return height + map_height_from_slope({tile_x, tile_y}, slope, GetNextIsSloped()); } /** diff --git a/src/openrct2/peep/Staff.cpp b/src/openrct2/peep/Staff.cpp index bcb08f6649..31a3349ca1 100644 --- a/src/openrct2/peep/Staff.cpp +++ b/src/openrct2/peep/Staff.cpp @@ -707,7 +707,7 @@ bool staff_can_ignore_wide_flag(rct_peep* staff, int32_t x, int32_t y, uint8_t z continue; } - if (footpath_element_is_sloped(path)) + if (path->AsPath()->IsSloped()) { if (footpath_element_get_slope_direction(path) == adjac_dir) { diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 69b12232d6..57a432060b 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -2881,7 +2881,7 @@ void load_from_sc4(const utf8* path) uint8_t PathElement::GetRCT1PathType() const { uint8_t pathColour = type & 3; - uint8_t pathType2 = (pathType & FOOTPATH_PROPERTIES_TYPE_MASK) >> 2; + uint8_t pathType2 = (entryIndex & FOOTPATH_PROPERTIES_TYPE_MASK) >> 2; pathType2 = pathType2 | pathColour; return pathType2; diff --git a/src/openrct2/ride/TrackDesignSave.cpp b/src/openrct2/ride/TrackDesignSave.cpp index 05f4bf46ff..b9369fe377 100644 --- a/src/openrct2/ride/TrackDesignSave.cpp +++ b/src/openrct2/ride/TrackDesignSave.cpp @@ -375,8 +375,9 @@ static void track_design_save_add_footpath(int32_t x, int32_t y, rct_tile_elemen uint8_t flags = 0; flags |= tileElement->properties.path.edges & FOOTPATH_PROPERTIES_EDGES_EDGES_MASK; - flags |= (tileElement->properties.path.type & FOOTPATH_PROPERTIES_FLAG_IS_SLOPED) << 2; flags |= (tileElement->properties.path.type & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK) << 5; + if (tileElement->AsPath()->IsSloped()) + flags |= 0b00010000; if (tileElement->AsPath()->IsQueue()) flags |= 1 << 7; diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 1b6a04eab9..a10ffa6abf 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -172,7 +172,7 @@ static rct_tile_element* map_get_footpath_element_slope(int32_t x, int32_t y, in static void loc_6A6620(int32_t flags, int32_t x, int32_t y, rct_tile_element* tileElement) { - if (footpath_element_is_sloped(tileElement) && !(flags & GAME_COMMAND_FLAG_GHOST)) + if (tileElement->AsPath()->IsSloped() && !(flags & GAME_COMMAND_FLAG_GHOST)) { int32_t direction = footpath_element_get_slope_direction(tileElement); int32_t z = tileElement->base_height; @@ -322,7 +322,7 @@ static money32 footpath_element_update( rct_scenery_entry* scenery_entry = get_footpath_item_entry(pathItemType - 1); uint16_t unk6 = scenery_entry->path_bit.flags; - if ((unk6 & PATH_BIT_FLAG_DONT_ALLOW_ON_SLOPE) && footpath_element_is_sloped(tileElement)) + if ((unk6 & PATH_BIT_FLAG_DONT_ALLOW_ON_SLOPE) && tileElement->AsPath()->IsSloped()) { gGameCommandErrorText = STR_CANT_BUILD_THIS_ON_SLOPED_FOOTPATH; return MONEY32_UNDEFINED; @@ -846,7 +846,7 @@ void footpath_get_coordinates_from_pos( if (interactionType == VIEWPORT_INTERACTION_ITEM_FOOTPATH) { z = myTileElement->base_height * 8; - if (footpath_element_is_sloped(myTileElement)) + if (myTileElement->AsPath()->IsSloped()) { z += 8; } @@ -1083,7 +1083,7 @@ static void footpath_connect_corners(int32_t initialX, int32_t initialY, rct_til if (initialTileElement->AsPath()->IsQueue()) return; - if (footpath_element_is_sloped(initialTileElement)) + if (initialTileElement->AsPath()->IsSloped()) return; tileElement[0] = initialTileElement; @@ -1229,7 +1229,7 @@ static rct_tile_element* footpath_get_element(int32_t x, int32_t y, int32_t z0, if (z1 == tileElement->base_height) { - if (footpath_element_is_sloped(tileElement)) + if (tileElement->AsPath()->IsSloped()) { slope = footpath_element_get_slope_direction(tileElement); if (slope != direction) @@ -1239,7 +1239,7 @@ static rct_tile_element* footpath_get_element(int32_t x, int32_t y, int32_t z0, } if (z0 == tileElement->base_height) { - if (!footpath_element_is_sloped(tileElement)) + if (!tileElement->AsPath()->IsSloped()) break; slope = footpath_element_get_slope_direction(tileElement) ^ 2; @@ -1291,7 +1291,7 @@ static bool footpath_disconnect_queue_from_path(int32_t x, int32_t y, rct_tile_e if (!tileElement->AsPath()->IsQueue()) return false; - if (footpath_element_is_sloped(tileElement)) + if (tileElement->AsPath()->IsSloped()) return false; uint8_t c = connected_path_count[tileElement->properties.path.edges & FOOTPATH_PROPERTIES_EDGES_EDGES_MASK]; @@ -1343,7 +1343,7 @@ static void loc_6A6D7E( case TILE_ELEMENT_TYPE_PATH: if (z == tileElement->base_height) { - if (footpath_element_is_sloped(tileElement) + if (tileElement->AsPath()->IsSloped() && footpath_element_get_slope_direction(tileElement) != direction) { return; @@ -1355,7 +1355,7 @@ static void loc_6A6D7E( } if (z - 2 == tileElement->base_height) { - if (!footpath_element_is_sloped(tileElement) + if (!tileElement->AsPath()->IsSloped() || footpath_element_get_slope_direction(tileElement) != (direction ^ 2)) { return; @@ -1514,7 +1514,7 @@ static void loc_6A6C85( int32_t z = tileElement->base_height; if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH) { - if (footpath_element_is_sloped(tileElement)) + if (tileElement->AsPath()->IsSloped()) { if ((footpath_element_get_slope_direction(tileElement) - direction) & 1) { @@ -1612,7 +1612,7 @@ void footpath_chain_ride_queue( lastPathX = x; lastPathY = y; lastPathDirection = direction; - if (footpath_element_is_sloped(tileElement)) + if (tileElement->AsPath()->IsSloped()) { if (footpath_element_get_slope_direction(tileElement) == direction) { @@ -1632,7 +1632,7 @@ void footpath_chain_ride_queue( continue; if (tileElement->base_height == z) { - if (footpath_element_is_sloped(tileElement)) + if (tileElement->AsPath()->IsSloped()) { if (footpath_element_get_slope_direction(tileElement) != direction) break; @@ -1641,7 +1641,7 @@ void footpath_chain_ride_queue( } if (tileElement->base_height == z - 2) { - if (!footpath_element_is_sloped(tileElement)) + if (!tileElement->AsPath()->IsSloped()) break; if ((footpath_element_get_slope_direction(tileElement) ^ 2) != direction) @@ -1843,7 +1843,7 @@ static int32_t footpath_is_connected_to_map_edge_recurse( if (tileElement->GetType() != TILE_ELEMENT_TYPE_PATH) continue; - if (footpath_element_is_sloped(tileElement) + if (tileElement->AsPath()->IsSloped() && (slopeDirection = footpath_element_get_slope_direction(tileElement)) != direction) { if ((slopeDirection ^ 2) != direction) @@ -1914,7 +1914,7 @@ searchFromFootpath: if (edges == 0) { // Only possible direction to go - if (footpath_element_is_sloped(tileElement) && footpath_element_get_slope_direction(tileElement) == direction) + if (tileElement->AsPath()->IsSloped() && footpath_element_get_slope_direction(tileElement) == direction) { z += 2; } @@ -1937,7 +1937,7 @@ searchFromFootpath: do { edges &= ~(1 << direction); - if (footpath_element_is_sloped(tileElement) && footpath_element_get_slope_direction(tileElement) == direction) + if (tileElement->AsPath()->IsSloped() && footpath_element_get_slope_direction(tileElement) == direction) { z += 2; } @@ -1958,16 +1958,16 @@ int32_t footpath_is_connected_to_map_edge(int32_t x, int32_t y, int32_t z, int32 return footpath_is_connected_to_map_edge_recurse(x, y, z, direction, flags, 0, 0, 16); } -bool footpath_element_is_sloped(const rct_tile_element* tileElement) +bool PathElement::IsSloped() const { - return (tileElement->properties.path.type & FOOTPATH_PROPERTIES_FLAG_IS_SLOPED) != 0; + return (entryIndex & FOOTPATH_PROPERTIES_FLAG_IS_SLOPED) != 0; } -void footpath_element_set_sloped(rct_tile_element* tileElement, bool isSloped) +void PathElement::SetSloped(bool isSloped) { - tileElement->properties.path.type &= ~FOOTPATH_PROPERTIES_FLAG_IS_SLOPED; + entryIndex &= ~FOOTPATH_PROPERTIES_FLAG_IS_SLOPED; if (isSloped) - tileElement->properties.path.type |= FOOTPATH_PROPERTIES_FLAG_IS_SLOPED; + entryIndex |= FOOTPATH_PROPERTIES_FLAG_IS_SLOPED; } uint8_t footpath_element_get_slope_direction(const rct_tile_element* tileElement) @@ -2095,7 +2095,7 @@ static rct_tile_element* footpath_can_be_wide(int32_t x, int32_t y, uint8_t heig continue; if (tileElement->AsPath()->IsQueue()) continue; - if (footpath_element_is_sloped(tileElement)) + if (tileElement->AsPath()->IsSloped()) continue; return tileElement; } while (!(tileElement++)->IsLastForTile()); @@ -2146,7 +2146,7 @@ void footpath_update_path_wide_flags(int32_t x, int32_t y) if (tileElement->AsPath()->IsQueue()) continue; - if (footpath_element_is_sloped(tileElement)) + if (tileElement->AsPath()->IsSloped()) continue; if ((tileElement->properties.path.edges & FOOTPATH_PROPERTIES_EDGES_EDGES_MASK) == 0) @@ -2380,7 +2380,7 @@ static void footpath_remove_edges_towards_here( if (tileElement->base_height != z) continue; - if (footpath_element_is_sloped(tileElement)) + if (tileElement->AsPath()->IsSloped()) break; d = ((direction + 1) & 3) + 4; @@ -2409,7 +2409,7 @@ static void footpath_remove_edges_towards(int32_t x, int32_t y, int32_t z0, int3 if (z1 == tileElement->base_height) { - if (footpath_element_is_sloped(tileElement)) + if (tileElement->AsPath()->IsSloped()) { uint8_t slope = footpath_element_get_slope_direction(tileElement); if (slope != direction) @@ -2421,7 +2421,7 @@ static void footpath_remove_edges_towards(int32_t x, int32_t y, int32_t z0, int3 if (z0 == tileElement->base_height) { - if (!footpath_element_is_sloped(tileElement)) + if (!tileElement->AsPath()->IsSloped()) break; uint8_t slope = footpath_element_get_slope_direction(tileElement) ^ 2; @@ -2450,7 +2450,7 @@ bool tile_element_wants_path_connection_towards(TileCoordsXYZD coords, const rct case TILE_ELEMENT_TYPE_PATH: if (tileElement->base_height == coords.z) { - if (!footpath_element_is_sloped(tileElement)) + if (!tileElement->AsPath()->IsSloped()) // The footpath is flat, it can be connected to from any direction return true; else if (footpath_element_get_slope_direction(tileElement) == (coords.direction ^ 2)) @@ -2459,7 +2459,7 @@ bool tile_element_wants_path_connection_towards(TileCoordsXYZD coords, const rct } else if (tileElement->base_height + 2 == coords.z) { - if (footpath_element_is_sloped(tileElement) + if (tileElement->AsPath()->IsSloped() && footpath_element_get_slope_direction(tileElement) == coords.direction) // The footpath is sloped and its higher point matches the edge connection return true; @@ -2514,7 +2514,7 @@ static void footpath_fix_corners_around(int32_t x, int32_t y, rct_tile_element* }; // Sloped paths don't create filled corners, so no need to remove any - if (footpath_element_is_sloped(pathElement)) + if (pathElement->AsPath()->IsSloped()) return; for (int32_t xOffset = -1; xOffset <= 1; xOffset++) @@ -2530,7 +2530,7 @@ static void footpath_fix_corners_around(int32_t x, int32_t y, rct_tile_element* { if (tileElement->GetType() != TILE_ELEMENT_TYPE_PATH) continue; - if (footpath_element_is_sloped(tileElement)) + if (tileElement->AsPath()->IsSloped()) continue; if (tileElement->base_height != pathElement->base_height) continue; @@ -2567,7 +2567,7 @@ void footpath_remove_edges_at(int32_t x, int32_t y, rct_tile_element* tileElemen int32_t z1 = tileElement->base_height; if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH) { - if (footpath_element_is_sloped(tileElement)) + if (tileElement->AsPath()->IsSloped()) { int32_t slope = footpath_element_get_slope_direction(tileElement); // Sloped footpaths don't connect sideways diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index 24afdede33..8061c1eb4e 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -154,8 +154,6 @@ void footpath_update_path_wide_flags(int32_t x, int32_t y); bool footpath_is_blocked_by_vehicle(const TileCoordsXYZ& position); int32_t footpath_is_connected_to_map_edge(int32_t x, int32_t y, int32_t z, int32_t direction, int32_t flags); -bool footpath_element_is_sloped(const rct_tile_element* tileElement); -void footpath_element_set_sloped(rct_tile_element* tileElement, bool isSloped); uint8_t footpath_element_get_slope_direction(const rct_tile_element* tileElement); bool footpath_element_has_queue_banner(const rct_tile_element* tileElement); bool footpath_element_is_wide(const rct_tile_element* tileElement); diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index f8a3f5e4dc..90262adea1 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -632,7 +632,7 @@ bool map_coord_is_connected(int32_t x, int32_t y, int32_t z, uint8_t faceDirecti rct_tile_element_path_properties props = tileElement->properties.path; uint8_t pathDirection = props.type & 3; - if (footpath_element_is_sloped(tileElement)) + if (tileElement->AsPath()->IsSloped()) { if (pathDirection == faceDirection) { @@ -694,21 +694,21 @@ void map_update_path_wide_flags() * * rct2: 0x006A7B84 */ -int32_t map_height_from_slope(int32_t x, int32_t y, int32_t slope) +int32_t map_height_from_slope(const CoordsXY coords, int32_t slope, bool isSloped) { - if (!(slope & FOOTPATH_PROPERTIES_FLAG_IS_SLOPED)) + if (!isSloped) return 0; switch (slope & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK) { case TILE_ELEMENT_DIRECTION_WEST: - return (31 - (x & 31)) / 2; + return (31 - (coords.x & 31)) / 2; case TILE_ELEMENT_DIRECTION_NORTH: - return (y & 31) / 2; + return (coords.y & 31) / 2; case TILE_ELEMENT_DIRECTION_EAST: - return (x & 31) / 2; + return (coords.x & 31) / 2; case TILE_ELEMENT_DIRECTION_SOUTH: - return (31 - (y & 31)) / 2; + return (31 - (coords.y & 31)) / 2; } return 0; } @@ -3587,7 +3587,7 @@ bool map_can_construct_with_clear_at( // Crossing mode 1: building track over path if (crossingMode == 1 && canBuildCrossing && tileElement->GetType() == TILE_ELEMENT_TYPE_PATH && tileElement->base_height == zLow && !tileElement->AsPath()->IsQueue() - && !footpath_element_is_sloped(tileElement)) + && !tileElement->AsPath()->IsSloped()) { continue; } diff --git a/src/openrct2/world/Map.h b/src/openrct2/world/Map.h index cb55ae47e8..0e14b37244 100644 --- a/src/openrct2/world/Map.h +++ b/src/openrct2/world/Map.h @@ -134,7 +134,7 @@ void map_update_tile_pointers(); rct_tile_element* map_get_first_element_at(int32_t x, int32_t y); rct_tile_element* map_get_nth_element_at(int32_t x, int32_t y, int32_t n); void map_set_tile_elements(int32_t x, int32_t y, rct_tile_element* elements); -int32_t map_height_from_slope(int32_t x, int32_t y, int32_t slope); +int32_t map_height_from_slope(CoordsXY coords, int32_t slope, bool isSloped); BannerElement* map_get_banner_element_at(int32_t x, int32_t y, int32_t z, uint8_t direction); rct_tile_element* map_get_surface_element_at(int32_t x, int32_t y); rct_tile_element* map_get_surface_element_at(CoordsXY coords); diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index 6787d37d36..cc213a74f7 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -186,7 +186,8 @@ assert_struct_size(SurfaceElement, 8); struct PathElement : TileElementBase { - uint8_t pathType; // 4 0xF0 Path type, 0x08 Ride sign, 0x04 Set when path is diagonal, 0x03 Rotation +private: + uint8_t entryIndex; // 4 0xF0 Path type, 0x08 Ride sign, 0x04 Set when path is diagonal, 0x03 Rotation uint8_t additions; // 5 uint8_t edges; // 6 union @@ -199,6 +200,9 @@ public: bool IsQueue() const; void SetIsQueue(bool isQueue); + bool IsSloped() const; + void SetSloped(bool isSloped); + uint8_t GetRCT1PathType() const; }; assert_struct_size(PathElement, 8); diff --git a/src/openrct2/world/TileInspector.cpp b/src/openrct2/world/TileInspector.cpp index c078f027cb..6ba5a19486 100644 --- a/src/openrct2/world/TileInspector.cpp +++ b/src/openrct2/world/TileInspector.cpp @@ -222,7 +222,7 @@ int32_t tile_inspector_rotate_element_at(int32_t x, int32_t y, int32_t elementIn switch (tileElement->GetType()) { case TILE_ELEMENT_TYPE_PATH: - if (footpath_element_is_sloped(tileElement)) + if (tileElement->AsPath()->IsSloped()) { newRotation = (footpath_element_get_slope_direction(tileElement) + 1) & TILE_ELEMENT_DIRECTION_MASK; tileElement->properties.path.type &= ~TILE_ELEMENT_DIRECTION_MASK; diff --git a/test/tests/TileElements.cpp b/test/tests/TileElements.cpp index a0e0e7a655..182ada1d68 100644 --- a/test/tests/TileElements.cpp +++ b/test/tests/TileElements.cpp @@ -59,7 +59,7 @@ TEST_F(TileElementWantsFootpathConnection, SlopedPath) // Sloped paths only want to connect in two directions, of which is one at a higher offset const rct_tile_element* const slopedPathElement = map_get_footpath_element(18, 18, 14); ASSERT_NE(slopedPathElement, nullptr); - ASSERT_TRUE(footpath_element_is_sloped(slopedPathElement)); + ASSERT_TRUE(slopedPathElement->AsPath()->IsSloped()); // Bottom and top of sloped path want a path connection EXPECT_TRUE(tile_element_wants_path_connection_towards({ 18, 18, 14, 2 }, nullptr)); EXPECT_TRUE(tile_element_wants_path_connection_towards({ 18, 18, 16, 0 }, nullptr));