From 37f59e17dc9300cf5ab5475a237bd42ba26dd4bf Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 16 Sep 2018 16:17:35 +0200 Subject: [PATCH 1/9] 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)); From f9f233dbb146ab1e51c5edc26ea93e185e391a09 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 16 Sep 2018 16:32:06 +0200 Subject: [PATCH 2/9] Replace C-style function for HasQueueBanner() --- src/openrct2/paint/tile_element/Paint.Path.cpp | 2 +- src/openrct2/world/Footpath.cpp | 4 ++-- src/openrct2/world/Footpath.h | 1 - src/openrct2/world/MapAnimation.cpp | 2 +- src/openrct2/world/TileElement.h | 15 ++++++++------- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/openrct2/paint/tile_element/Paint.Path.cpp b/src/openrct2/paint/tile_element/Paint.Path.cpp index f56718fd41..6e95dd3b12 100644 --- a/src/openrct2/paint/tile_element/Paint.Path.cpp +++ b/src/openrct2/paint/tile_element/Paint.Path.cpp @@ -404,7 +404,7 @@ static void sub_6A4101( } } - if (!footpath_element_has_queue_banner(tile_element)) + if (!tile_element->AsPath()->HasQueueBanner()) { return; } diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index a10ffa6abf..deb1f217ba 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -1987,9 +1987,9 @@ void PathElement::SetIsQueue(bool isQueue) type |= FOOTPATH_ELEMENT_TYPE_FLAG_IS_QUEUE; } -bool footpath_element_has_queue_banner(const rct_tile_element* tileElement) +bool PathElement::HasQueueBanner() const { - return (tileElement->properties.path.type & FOOTPATH_PROPERTIES_FLAG_HAS_QUEUE_BANNER) != 0; + return (entryIndex & FOOTPATH_PROPERTIES_FLAG_HAS_QUEUE_BANNER) != 0; } bool footpath_element_is_wide(const rct_tile_element* tileElement) diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index 8061c1eb4e..3826fcfd3c 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -155,7 +155,6 @@ 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); 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); uint8_t footpath_element_get_type(const rct_tile_element* tileElement); void footpath_element_set_type(rct_tile_element* tileElement, uint8_t type); diff --git a/src/openrct2/world/MapAnimation.cpp b/src/openrct2/world/MapAnimation.cpp index bac8289399..bc0b7aa8a7 100644 --- a/src/openrct2/world/MapAnimation.cpp +++ b/src/openrct2/world/MapAnimation.cpp @@ -145,7 +145,7 @@ static bool map_animation_invalidate_queue_banner(int32_t x, int32_t y, int32_t continue; if (!(tileElement->flags & 1)) continue; - if (!footpath_element_has_queue_banner(tileElement)) + if (!tileElement->AsPath()->HasQueueBanner()) continue; int32_t direction = (footpath_element_get_direction(tileElement) + get_current_rotation()) & 3; diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index cc213a74f7..86ed9f697b 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -187,9 +187,9 @@ assert_struct_size(SurfaceElement, 8); struct PathElement : TileElementBase { 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 + 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 { uint8_t additionStatus; // 7 @@ -197,12 +197,13 @@ private: }; public: - bool IsQueue() const; - void SetIsQueue(bool isQueue); - bool IsSloped() const; void SetSloped(bool isSloped); - + + bool IsQueue() const; + void SetIsQueue(bool isQueue); + bool HasQueueBanner() const; + uint8_t GetRCT1PathType() const; }; assert_struct_size(PathElement, 8); From e159ac65a6c84364ac39619dd23707346b912d9b Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 16 Sep 2018 16:40:03 +0200 Subject: [PATCH 3/9] Replace C-style functions for IsWide() and SetWide() --- .../paint/tile_element/Paint.Path.cpp | 2 +- src/openrct2/peep/GuestPathfinding.cpp | 8 ++-- src/openrct2/peep/Staff.cpp | 2 +- src/openrct2/world/Footpath.cpp | 38 +++++++++---------- src/openrct2/world/Footpath.h | 2 - src/openrct2/world/TileElement.h | 3 ++ 6 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/openrct2/paint/tile_element/Paint.Path.cpp b/src/openrct2/paint/tile_element/Paint.Path.cpp index 6e95dd3b12..ffda208efe 100644 --- a/src/openrct2/paint/tile_element/Paint.Path.cpp +++ b/src/openrct2/paint/tile_element/Paint.Path.cpp @@ -835,7 +835,7 @@ void path_paint(paint_session* session, uint16_t height, const rct_tile_element* } // Draw wide flags as ghosts, leaving only the "walkable" paths to be drawn normally - if (gPaintWidePathsAsGhost && footpath_element_is_wide(tile_element)) + if (gPaintWidePathsAsGhost && tile_element->AsPath()->IsWide()) { imageFlags &= 0x7FFFF; imageFlags |= CONSTRUCTION_MARKER; diff --git a/src/openrct2/peep/GuestPathfinding.cpp b/src/openrct2/peep/GuestPathfinding.cpp index b97e36cfc4..8bc56238be 100644 --- a/src/openrct2/peep/GuestPathfinding.cpp +++ b/src/openrct2/peep/GuestPathfinding.cpp @@ -244,7 +244,7 @@ static uint8_t footpath_element_next_in_direction(TileCoordsXYZ loc, rct_tile_el continue; if (!is_valid_path_z_and_direction(nextTileElement, loc.z, chosenDirection)) continue; - if (footpath_element_is_wide(nextTileElement)) + if (nextTileElement->AsPath()->IsWide()) return PATH_SEARCH_WIDE; // Only queue tiles that are connected to a ride are returned as ride queues. if (nextTileElement->AsPath()->IsQueue() && nextTileElement->properties.path.ride_index != 0xFF) @@ -338,7 +338,7 @@ static uint8_t footpath_element_dest_in_dir( case TILE_ELEMENT_TYPE_PATH: if (!is_valid_path_z_and_direction(tileElement, loc.z, chosenDirection)) continue; - if (footpath_element_is_wide(tileElement)) + if (tileElement->AsPath()->IsWide()) return PATH_SEARCH_WIDE; uint8_t edges = path_get_permitted_edges(tileElement); @@ -589,7 +589,7 @@ static void peep_pathfind_heuristic_search( uint8_t searchResult = PATH_SEARCH_FAILED; bool currentElementIsWide - = (footpath_element_is_wide(currentTileElement) + = (currentTileElement->AsPath()->IsWide() && !staff_can_ignore_wide_flag(peep, loc.x * 32, loc.y * 32, loc.z, currentTileElement)); loc += TileDirectionDelta[test_edge]; @@ -725,7 +725,7 @@ static void peep_pathfind_heuristic_search( // Path may be sloped, so set z to path base height. loc.z = tileElement->base_height; - if (footpath_element_is_wide(tileElement)) + if (tileElement->AsPath()->IsWide()) { /* Check if staff can ignore this wide flag. */ if (!staff_can_ignore_wide_flag(peep, loc.x * 32, loc.y * 32, loc.z, tileElement)) diff --git a/src/openrct2/peep/Staff.cpp b/src/openrct2/peep/Staff.cpp index 31a3349ca1..03217490bf 100644 --- a/src/openrct2/peep/Staff.cpp +++ b/src/openrct2/peep/Staff.cpp @@ -737,7 +737,7 @@ bool staff_can_ignore_wide_flag(rct_peep* staff, int32_t x, int32_t y, uint8_t z pathcount++; } - if (footpath_element_is_wide(test_element)) + if (test_element->AsPath()->IsWide()) { if (!widefound) { diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index deb1f217ba..16fc19b1c7 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -1992,16 +1992,16 @@ bool PathElement::HasQueueBanner() const return (entryIndex & FOOTPATH_PROPERTIES_FLAG_HAS_QUEUE_BANNER) != 0; } -bool footpath_element_is_wide(const rct_tile_element* tileElement) +bool PathElement::IsWide() const { - return (tileElement->type & FOOTPATH_ELEMENT_TYPE_FLAG_IS_WIDE) != 0; + return (type & FOOTPATH_ELEMENT_TYPE_FLAG_IS_WIDE) != 0; } -void footpath_element_set_wide(rct_tile_element* tileElement, bool isWide) +void PathElement::SetWide(bool isWide) { - tileElement->type &= ~FOOTPATH_ELEMENT_TYPE_FLAG_IS_WIDE; + type &= ~FOOTPATH_ELEMENT_TYPE_FLAG_IS_WIDE; if (isWide) - tileElement->type |= FOOTPATH_ELEMENT_TYPE_FLAG_IS_WIDE; + type |= FOOTPATH_ELEMENT_TYPE_FLAG_IS_WIDE; } bool footpath_element_has_path_scenery(const rct_tile_element* tileElement) @@ -2074,7 +2074,7 @@ static void footpath_clear_wide(int32_t x, int32_t y) { if (tileElement->GetType() != TILE_ELEMENT_TYPE_PATH) continue; - footpath_element_set_wide(tileElement, false); + tileElement->AsPath()->SetWide(false); } while (!(tileElement++)->IsLastForTile()); } @@ -2183,7 +2183,7 @@ void footpath_update_path_wide_flags(int32_t x, int32_t y) F3EFA5 |= 0x80; if (pathList[7] != nullptr) { - if (footpath_element_is_wide(pathList[7])) + if ((pathList[7])->AsPath()->IsWide()) { F3EFA5 &= ~0x80; } @@ -2195,7 +2195,7 @@ void footpath_update_path_wide_flags(int32_t x, int32_t y) F3EFA5 |= 0x2; if (pathList[1] != nullptr) { - if (footpath_element_is_wide(pathList[1])) + if ((pathList[1])->AsPath()->IsWide()) { F3EFA5 &= ~0x2; } @@ -2232,11 +2232,11 @@ void footpath_update_path_wide_flags(int32_t x, int32_t y) //} } - if ((F3EFA5 & 0x80) && (pathList[7] != nullptr) && !(footpath_element_is_wide(pathList[7]))) + if ((F3EFA5 & 0x80) && (pathList[7] != nullptr) && !(pathList[7])->AsPath()->IsWide()) { - if ((F3EFA5 & 2) && (pathList[0] != nullptr) && (!footpath_element_is_wide(pathList[0])) + if ((F3EFA5 & 2) && (pathList[0] != nullptr) && !(pathList[0])->AsPath()->IsWide() && ((pathList[0]->properties.path.edges & 6) == 6) && // N E - (pathList[1] != nullptr) && (!footpath_element_is_wide(pathList[1]))) + (pathList[1] != nullptr) && !(pathList[1])->AsPath()->IsWide()) { F3EFA5 |= 0x1; } @@ -2246,9 +2246,9 @@ void footpath_update_path_wide_flags(int32_t x, int32_t y) * is always false due to the tile update order * in combination with reset tiles. * Short circuit the logic appropriately. */ - if ((F3EFA5 & 0x20) && (pathList[6] != nullptr) && (!footpath_element_is_wide(pathList[6])) + if ((F3EFA5 & 0x20) && (pathList[6] != nullptr) && !(pathList[6])->AsPath()->IsWide() && ((pathList[6]->properties.path.edges & 3) == 3) && // N W - (pathList[5] != nullptr) && (true || !footpath_element_is_wide(pathList[5]))) + (pathList[5] != nullptr) && (true || !(pathList[5])->AsPath()->IsWide())) { F3EFA5 |= 0x40; } @@ -2260,11 +2260,11 @@ void footpath_update_path_wide_flags(int32_t x, int32_t y) * are always false due to the tile update order * in combination with reset tiles. * Short circuit the logic appropriately. */ - if ((F3EFA5 & 0x8) && (pathList[3] != nullptr) && (true || !footpath_element_is_wide(pathList[3]))) + if ((F3EFA5 & 0x8) && (pathList[3] != nullptr) && (true || !(pathList[3])->AsPath()->IsWide())) { - if ((F3EFA5 & 2) && (pathList[2] != nullptr) && (true || !footpath_element_is_wide(pathList[2])) + if ((F3EFA5 & 2) && (pathList[2] != nullptr) && (true || !(pathList[2])->AsPath()->IsWide()) && ((pathList[2]->properties.path.edges & 0xC) == 0xC) && (pathList[1] != nullptr) - && (!footpath_element_is_wide(pathList[1]))) + && (!(pathList[1])->AsPath()->IsWide())) { F3EFA5 |= 0x4; } @@ -2275,9 +2275,9 @@ void footpath_update_path_wide_flags(int32_t x, int32_t y) * are always false due to the tile update order * in combination with reset tiles. * Short circuit the logic appropriately. */ - if ((F3EFA5 & 0x20) && (pathList[4] != nullptr) && (true || !footpath_element_is_wide(pathList[4])) + if ((F3EFA5 & 0x20) && (pathList[4] != nullptr) && (true || !(pathList[4])->AsPath()->IsWide()) && ((pathList[4]->properties.path.edges & 9) == 9) && (pathList[5] != nullptr) - && (true || !footpath_element_is_wide(pathList[5]))) + && (true || !(pathList[5])->AsPath()->IsWide())) { F3EFA5 |= 0x10; } @@ -2299,7 +2299,7 @@ void footpath_update_path_wide_flags(int32_t x, int32_t y) { uint8_t e = tileElement->properties.path.edges; if ((e != 0b10101111) && (e != 0b01011111) && (e != 0b11101111)) - footpath_element_set_wide(tileElement, true); + tileElement->AsPath()->SetWide(true); } } while (!(tileElement++)->IsLastForTile()); } diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index 3826fcfd3c..4c922ad778 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -155,12 +155,10 @@ 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); uint8_t footpath_element_get_slope_direction(const rct_tile_element* tileElement); -bool footpath_element_is_wide(const rct_tile_element* tileElement); uint8_t footpath_element_get_type(const rct_tile_element* tileElement); void footpath_element_set_type(rct_tile_element* tileElement, uint8_t type); uint8_t footpath_element_get_direction(const rct_tile_element* tileElement); void footpath_element_set_direction(rct_tile_element* tileElement, uint8_t direction); -void footpath_element_set_wide(rct_tile_element* tileElement, bool isWide); bool footpath_element_has_path_scenery(const rct_tile_element* tileElement); uint8_t footpath_element_get_path_scenery(const rct_tile_element* tileElement); void footpath_element_set_path_scenery(rct_tile_element* tileElement, uint8_t pathSceneryType); diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index 86ed9f697b..823aa89214 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -200,6 +200,9 @@ public: bool IsSloped() const; void SetSloped(bool isSloped); + bool IsWide() const; + void SetWide(bool isWide); + bool IsQueue() const; void SetIsQueue(bool isQueue); bool HasQueueBanner() const; From ee05438953580e846673b3be2fce47f2a9874cdb Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 16 Sep 2018 16:46:23 +0200 Subject: [PATCH 4/9] Replace C-style functions for checking path addition ghost status --- src/openrct2/paint/tile_element/Paint.Path.cpp | 2 +- src/openrct2/peep/Guest.cpp | 14 +++++++------- src/openrct2/peep/Staff.cpp | 4 ++-- src/openrct2/rct1/S4Importer.cpp | 2 +- src/openrct2/world/Footpath.cpp | 18 ++++++++---------- src/openrct2/world/Footpath.h | 2 -- src/openrct2/world/Fountain.cpp | 2 +- src/openrct2/world/Scenery.cpp | 2 +- src/openrct2/world/TileElement.h | 3 +++ 9 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/openrct2/paint/tile_element/Paint.Path.cpp b/src/openrct2/paint/tile_element/Paint.Path.cpp index ffda208efe..168993093f 100644 --- a/src/openrct2/paint/tile_element/Paint.Path.cpp +++ b/src/openrct2/paint/tile_element/Paint.Path.cpp @@ -817,7 +817,7 @@ void path_paint(paint_session* session, uint16_t height, const rct_tile_element* imageFlags = SPRITE_ID_PALETTE_COLOUR_1(PALETTE_46); } - if (footpath_element_path_scenery_is_ghost(tile_element)) + if (tile_element->AsPath()->AdditionIsGhost()) { sceneryImageFlags = CONSTRUCTION_MARKER; } diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index 6caa694228..65e2cea215 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -641,7 +641,7 @@ void rct_peep::Tick128UpdateGuest(int32_t index) // Check if the footpath has a queue line TV monitor on it if (footpath_element_has_path_scenery(tileElement) - && !footpath_element_path_scenery_is_ghost(tileElement)) + && !tileElement->AsPath()->AdditionIsGhost()) { uint8_t pathSceneryIndex = footpath_element_get_path_scenery_index(tileElement); rct_scenery_entry* sceneryEntry = get_footpath_item_entry(pathSceneryIndex); @@ -2726,7 +2726,7 @@ static uint8_t peep_assess_surroundings(int16_t centre_x, int16_t centre_y, int1 { return PEEP_THOUGHT_TYPE_NONE; } - if (footpath_element_path_scenery_is_ghost(tileElement)) + if (tileElement->AsPath()->AdditionIsGhost()) break; if (scenery->path_bit.flags @@ -5320,7 +5320,7 @@ void rct_peep::UpdateWalking() if (footpath_element_has_path_scenery(tileElement)) { - if (!footpath_element_path_scenery_is_ghost(tileElement)) + if (!tileElement->AsPath()->AdditionIsGhost()) { rct_scenery_entry* sceneryEntry = get_footpath_item_entry(footpath_element_get_path_scenery_index(tileElement)); if (sceneryEntry == nullptr) @@ -5772,7 +5772,7 @@ void rct_peep::UpdateUsingBin() return; } - if (footpath_element_path_scenery_is_ghost(tileElement)) + if (tileElement->AsPath()->AdditionIsGhost()) { StateReset(); return; @@ -5930,7 +5930,7 @@ bool rct_peep::UpdateWalkingFindBench() if (tileElement->flags & TILE_ELEMENT_FLAG_BROKEN) return false; - if (footpath_element_path_scenery_is_ghost(tileElement)) + if (tileElement->AsPath()->AdditionIsGhost()) return false; int32_t edges = (tileElement->properties.path.edges & 0xF) ^ 0xF; @@ -6029,7 +6029,7 @@ bool rct_peep::UpdateWalkingFindBin() if (tileElement->flags & TILE_ELEMENT_FLAG_BROKEN) return false; - if (footpath_element_path_scenery_is_ghost(tileElement)) + if (tileElement->AsPath()->AdditionIsGhost()) return false; int32_t edges = (tileElement->properties.path.edges & 0xF) ^ 0xF; @@ -6126,7 +6126,7 @@ static void peep_update_walking_break_scenery(rct_peep* peep) if (tileElement->flags & TILE_ELEMENT_FLAG_BROKEN) return; - if (footpath_element_path_scenery_is_ghost(tileElement)) + if (tileElement->AsPath()->AdditionIsGhost()) return; int32_t edges = tileElement->properties.path.edges & 0xF; diff --git a/src/openrct2/peep/Staff.cpp b/src/openrct2/peep/Staff.cpp index 03217490bf..0980ac8e0c 100644 --- a/src/openrct2/peep/Staff.cpp +++ b/src/openrct2/peep/Staff.cpp @@ -1818,7 +1818,7 @@ void rct_peep::UpdateEmptyingBin() rct_scenery_entry* scenery_entry = get_footpath_item_entry(footpath_element_get_path_scenery_index(tile_element)); if (!(scenery_entry->path_bit.flags & PATH_BIT_FLAG_IS_BIN) || tile_element->flags & (1 << 5) - || footpath_element_path_scenery_is_ghost(tile_element)) + || tile_element->AsPath()->AdditionIsGhost()) { StateReset(); return; @@ -2220,7 +2220,7 @@ static int32_t peep_update_patrolling_find_bin(rct_peep* peep) if (tileElement->flags & TILE_ELEMENT_FLAG_BROKEN) return 0; - if (footpath_element_path_scenery_is_ghost(tileElement)) + if (tileElement->AsPath()->AdditionIsGhost()) return 0; uint8_t bin_positions = tileElement->properties.path.edges & 0xF; diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 57a432060b..011357e4aa 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -2511,7 +2511,7 @@ private: tileElement->AsPath()->SetIsQueue(true); } - footpath_scenery_set_is_ghost(tileElement, false); + tileElement->AsPath()->SetAdditionIsGhost(false); // Additions uint8_t additionType = footpath_element_get_path_scenery(tileElement); diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 16fc19b1c7..3018998592 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -365,16 +365,16 @@ static money32 footpath_element_update( // There is nothing yet - check if we should place a ghost if (flags & GAME_COMMAND_FLAG_APPLY) - footpath_scenery_set_is_ghost(tileElement, true); + tileElement->AsPath()->SetAdditionIsGhost(true); } if (!(flags & GAME_COMMAND_FLAG_APPLY)) return gParkFlags & PARK_FLAGS_NO_MONEY ? 0 : gFootpathPrice; if ((pathItemType != 0 && !(flags & GAME_COMMAND_FLAG_GHOST)) - || (pathItemType == 0 && footpath_element_path_scenery_is_ghost(tileElement))) + || (pathItemType == 0 && tileElement->AsPath()->AdditionIsGhost())) { - footpath_scenery_set_is_ghost(tileElement, false); + tileElement->AsPath()->SetAdditionIsGhost(false); } footpath_element_set_path_scenery(tileElement, pathItemType); @@ -2025,18 +2025,16 @@ uint8_t footpath_element_get_path_scenery_index(const rct_tile_element* tileElem return footpath_element_get_path_scenery(tileElement) - 1; } -bool footpath_element_path_scenery_is_ghost(const rct_tile_element* tileElement) +bool PathElement::AdditionIsGhost() const { - return (tileElement->properties.path.additions & FOOTPATH_ADDITION_FLAG_IS_GHOST) != 0; + return (additions & FOOTPATH_ADDITION_FLAG_IS_GHOST) != 0; } -void footpath_scenery_set_is_ghost(rct_tile_element* tileElement, bool isGhost) +void PathElement::SetAdditionIsGhost(bool isGhost) { - // Remove ghost flag - tileElement->properties.path.additions &= ~FOOTPATH_ADDITION_FLAG_IS_GHOST; - // Set flag if it should be a ghost + additions &= ~FOOTPATH_ADDITION_FLAG_IS_GHOST; if (isGhost) - tileElement->properties.path.additions |= FOOTPATH_ADDITION_FLAG_IS_GHOST; + additions |= FOOTPATH_ADDITION_FLAG_IS_GHOST; } uint8_t footpath_element_get_type(const rct_tile_element* tileElement) diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index 4c922ad778..25dcd5e6a2 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -163,8 +163,6 @@ bool footpath_element_has_path_scenery(const rct_tile_element* tileElement); uint8_t footpath_element_get_path_scenery(const rct_tile_element* tileElement); void footpath_element_set_path_scenery(rct_tile_element* tileElement, uint8_t pathSceneryType); uint8_t footpath_element_get_path_scenery_index(const rct_tile_element* tileElement); -bool footpath_element_path_scenery_is_ghost(const rct_tile_element* tileElement); -void footpath_scenery_set_is_ghost(rct_tile_element* tileElement, bool isGhost); void footpath_remove_edges_at(int32_t x, int32_t y, rct_tile_element* tileElement); int32_t entrance_get_directions(const rct_tile_element* tileElement); diff --git a/src/openrct2/world/Fountain.cpp b/src/openrct2/world/Fountain.cpp index bc8422c4b3..357e197251 100644 --- a/src/openrct2/world/Fountain.cpp +++ b/src/openrct2/world/Fountain.cpp @@ -259,7 +259,7 @@ static bool is_jumping_fountain(int32_t type, int32_t x, int32_t y, int32_t z) continue; if (tileElement->base_height != z) continue; - if (footpath_element_path_scenery_is_ghost(tileElement)) + if (tileElement->AsPath()->AdditionIsGhost()) continue; if (!footpath_element_has_path_scenery(tileElement)) continue; diff --git a/src/openrct2/world/Scenery.cpp b/src/openrct2/world/Scenery.cpp index 697c8f201b..55ec2779e1 100644 --- a/src/openrct2/world/Scenery.cpp +++ b/src/openrct2/world/Scenery.cpp @@ -88,7 +88,7 @@ void scenery_update_tile(int32_t x, int32_t y) } else if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH) { - if (footpath_element_has_path_scenery(tileElement) && !footpath_element_path_scenery_is_ghost(tileElement)) + if (footpath_element_has_path_scenery(tileElement) && !tileElement->AsPath()->AdditionIsGhost()) { rct_scenery_entry* sceneryEntry = get_footpath_item_entry(footpath_element_get_path_scenery_index(tileElement)); if (sceneryEntry != nullptr) diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index 823aa89214..cc3bf86eba 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -207,6 +207,9 @@ public: void SetIsQueue(bool isQueue); bool HasQueueBanner() const; + bool AdditionIsGhost() const; + void SetAdditionIsGhost(bool isGhost); + uint8_t GetRCT1PathType() const; }; assert_struct_size(PathElement, 8); From ecd624746267117c68f044542ee63010ec6fd700 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 16 Sep 2018 17:08:15 +0200 Subject: [PATCH 5/9] Replace C-style functions for checking getting path additions --- .../interface/ViewportInteraction.cpp | 2 +- src/openrct2-ui/windows/TileInspector.cpp | 4 +-- src/openrct2-ui/windows/TopToolbar.cpp | 2 +- src/openrct2/Cheats.cpp | 6 ++-- src/openrct2/EditorObjectSelectionSession.cpp | 4 +-- .../paint/tile_element/Paint.Path.cpp | 9 +++--- src/openrct2/peep/Guest.cpp | 28 ++++++++--------- src/openrct2/peep/Peep.cpp | 2 +- src/openrct2/peep/Staff.cpp | 8 ++--- src/openrct2/rct1/S4Importer.cpp | 4 +-- src/openrct2/world/Footpath.cpp | 31 +++++++++++-------- src/openrct2/world/Footpath.h | 4 --- src/openrct2/world/Fountain.cpp | 4 +-- src/openrct2/world/Scenery.cpp | 4 +-- src/openrct2/world/TileElement.h | 8 ++++- 15 files changed, 63 insertions(+), 57 deletions(-) diff --git a/src/openrct2-ui/interface/ViewportInteraction.cpp b/src/openrct2-ui/interface/ViewportInteraction.cpp index 437938f21b..15a9ed8df5 100644 --- a/src/openrct2-ui/interface/ViewportInteraction.cpp +++ b/src/openrct2-ui/interface/ViewportInteraction.cpp @@ -362,7 +362,7 @@ int32_t viewport_interaction_get_item_right(int32_t x, int32_t y, viewport_inter return info->type; case VIEWPORT_INTERACTION_ITEM_FOOTPATH_ITEM: - sceneryEntry = get_footpath_item_entry(footpath_element_get_path_scenery_index(tileElement)); + sceneryEntry = tileElement->AsPath()->GetAdditionEntry(); set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE); if (tileElement->flags & TILE_ELEMENT_FLAG_BROKEN) { diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index a4aa0532a2..a6d5a49a60 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -1813,9 +1813,9 @@ static void window_tile_inspector_paint(rct_window* w, rct_drawpixelinfo* dpi) gfx_draw_string_left(dpi, STR_TILE_INSPECTOR_PATH_NAME, &pathNameId, COLOUR_DARK_GREEN, x, y); // Path addition - if (footpath_element_has_path_scenery(tileElement)) + if (tileElement->AsPath()->HasAddition()) { - const uint8_t pathAdditionType = footpath_element_get_path_scenery_index(tileElement); + const uint8_t pathAdditionType = tileElement->AsPath()->GetAdditionEntryIndex(); rct_string_id additionNameId = get_footpath_item_entry(pathAdditionType)->name; gfx_draw_string_left(dpi, STR_TILE_INSPECTOR_PATH_ADDITIONS, &additionNameId, COLOUR_DARK_GREEN, x, y + 11); } diff --git a/src/openrct2-ui/windows/TopToolbar.cpp b/src/openrct2-ui/windows/TopToolbar.cpp index 4bd76304e8..4f017c1fbd 100644 --- a/src/openrct2-ui/windows/TopToolbar.cpp +++ b/src/openrct2-ui/windows/TopToolbar.cpp @@ -1129,7 +1129,7 @@ static void scenery_eyedropper_tool_down(int16_t x, int16_t y, rct_widgetindex w } case VIEWPORT_INTERACTION_ITEM_FOOTPATH_ITEM: { - int32_t entryIndex = footpath_element_get_path_scenery_index(tileElement); + int32_t entryIndex = tileElement->AsPath()->GetAdditionEntryIndex(); rct_scenery_entry* sceneryEntry = get_footpath_item_entry(entryIndex); if (sceneryEntry != nullptr) { diff --git a/src/openrct2/Cheats.cpp b/src/openrct2/Cheats.cpp index 3d1b72d946..6e0c5a54d0 100644 --- a/src/openrct2/Cheats.cpp +++ b/src/openrct2/Cheats.cpp @@ -108,7 +108,7 @@ static void cheat_fix_vandalism() if (it.element->GetType() != TILE_ELEMENT_TYPE_PATH) continue; - if (!footpath_element_has_path_scenery(it.element)) + if (!(it.element)->AsPath()->HasAddition()) continue; it.element->flags &= ~TILE_ELEMENT_FLAG_BROKEN; @@ -138,10 +138,10 @@ static void cheat_remove_litter() if (it.element->GetType() != TILE_ELEMENT_TYPE_PATH) continue; - if (!footpath_element_has_path_scenery(it.element)) + if (!(it.element)->AsPath()->HasAddition()) continue; - sceneryEntry = get_footpath_item_entry(footpath_element_get_path_scenery_index(it.element)); + sceneryEntry = it.element->AsPath()->GetAdditionEntry(); if (sceneryEntry->path_bit.flags & PATH_BIT_FLAG_IS_BIN) it.element->properties.path.addition_status = 0xFF; diff --git a/src/openrct2/EditorObjectSelectionSession.cpp b/src/openrct2/EditorObjectSelectionSession.cpp index dbeff817b8..377006cd49 100644 --- a/src/openrct2/EditorObjectSelectionSession.cpp +++ b/src/openrct2/EditorObjectSelectionSession.cpp @@ -136,9 +136,9 @@ void setup_in_use_selection_flags() assert(type < object_entry_group_counts[OBJECT_TYPE_PATHS]); Editor::SetSelectedObject(OBJECT_TYPE_PATHS, type, OBJECT_SELECTION_FLAG_SELECTED); - if (footpath_element_has_path_scenery(iter.element)) + if (iter.element->AsPath()->HasAddition()) { - uint8_t path_additions = footpath_element_get_path_scenery_index(iter.element); + uint8_t path_additions = iter.element->AsPath()->GetAdditionEntryIndex(); Editor::SetSelectedObject(OBJECT_TYPE_PATH_BITS, path_additions, OBJECT_SELECTION_FLAG_SELECTED); } break; diff --git a/src/openrct2/paint/tile_element/Paint.Path.cpp b/src/openrct2/paint/tile_element/Paint.Path.cpp index 168993093f..d82d67ac24 100644 --- a/src/openrct2/paint/tile_element/Paint.Path.cpp +++ b/src/openrct2/paint/tile_element/Paint.Path.cpp @@ -682,7 +682,7 @@ static void sub_6A3F61( { if (!gTrackDesignSaveMode) { - if (footpath_element_has_path_scenery(tile_element)) + if (tile_element->AsPath()->HasAddition()) { session->InteractionType = VIEWPORT_INTERACTION_ITEM_FOOTPATH_ITEM; if (sceneryImageFlags != 0) @@ -691,8 +691,7 @@ static void sub_6A3F61( } // Draw additional path bits (bins, benches, lamps, queue screens) - rct_scenery_entry* sceneryEntry = get_footpath_item_entry( - footpath_element_get_path_scenery_index(tile_element)); + rct_scenery_entry* sceneryEntry = tile_element->AsPath()->GetAdditionEntry(); if ((gCurrentViewportFlags & VIEWPORT_FLAG_HIGHLIGHT_PATH_ISSUES) && !(tile_element->flags & TILE_ELEMENT_FLAG_BROKEN) @@ -939,9 +938,9 @@ void path_paint(paint_session* session, uint16_t height, const rct_tile_element* #ifdef __ENABLE_LIGHTFX__ if (lightfx_is_available()) { - if (footpath_element_has_path_scenery(tile_element) && !(tile_element->flags & TILE_ELEMENT_FLAG_BROKEN)) + if (tile_element->AsPath()->HasAddition() && !(tile_element->flags & TILE_ELEMENT_FLAG_BROKEN)) { - rct_scenery_entry* sceneryEntry = get_footpath_item_entry(footpath_element_get_path_scenery_index(tile_element)); + rct_scenery_entry* sceneryEntry = tile_element->AsPath()->GetAdditionEntry(); if (sceneryEntry->path_bit.flags & PATH_BIT_FLAG_LAMP) { if (!(tile_element->properties.path.edges & EDGE_NE)) diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index 65e2cea215..0cdfa2170d 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -640,10 +640,10 @@ void rct_peep::Tick128UpdateGuest(int32_t index) continue; // Check if the footpath has a queue line TV monitor on it - if (footpath_element_has_path_scenery(tileElement) + if (tileElement->AsPath()->HasAddition() && !tileElement->AsPath()->AdditionIsGhost()) { - uint8_t pathSceneryIndex = footpath_element_get_path_scenery_index(tileElement); + uint8_t pathSceneryIndex = tileElement->AsPath()->GetAdditionEntryIndex(); rct_scenery_entry* sceneryEntry = get_footpath_item_entry(pathSceneryIndex); if (sceneryEntry->path_bit.flags & PATH_BIT_FLAG_IS_QUEUE_SCREEN) { @@ -2718,10 +2718,10 @@ static uint8_t peep_assess_surroundings(int16_t centre_x, int16_t centre_y, int1 switch (tileElement->GetType()) { case TILE_ELEMENT_TYPE_PATH: - if (!footpath_element_has_path_scenery(tileElement)) + if (!tileElement->AsPath()->HasAddition()) break; - scenery = get_footpath_item_entry(footpath_element_get_path_scenery_index(tileElement)); + scenery = tileElement->AsPath()->GetAdditionEntry(); if (scenery == nullptr) { return PEEP_THOUGHT_TYPE_NONE; @@ -5318,11 +5318,11 @@ void rct_peep::UpdateWalking() int32_t positions_free = 15; - if (footpath_element_has_path_scenery(tileElement)) + if (tileElement->AsPath()->HasAddition()) { if (!tileElement->AsPath()->AdditionIsGhost()) { - rct_scenery_entry* sceneryEntry = get_footpath_item_entry(footpath_element_get_path_scenery_index(tileElement)); + rct_scenery_entry* sceneryEntry = tileElement->AsPath()->GetAdditionEntry(); if (sceneryEntry == nullptr) { return; @@ -5753,13 +5753,13 @@ void rct_peep::UpdateUsingBin() } } - if (!footpath_element_has_path_scenery(tileElement)) + if (!tileElement->AsPath()->HasAddition()) { StateReset(); return; } - rct_scenery_entry* sceneryEntry = get_footpath_item_entry(footpath_element_get_path_scenery_index(tileElement)); + rct_scenery_entry* sceneryEntry = tileElement->AsPath()->GetAdditionEntry(); if (!(sceneryEntry->path_bit.flags & PATH_BIT_FLAG_IS_BIN)) { StateReset(); @@ -5920,9 +5920,9 @@ bool rct_peep::UpdateWalkingFindBench() } } - if (!footpath_element_has_path_scenery(tileElement)) + if (!tileElement->AsPath()->HasAddition()) return false; - rct_scenery_entry* sceneryEntry = get_footpath_item_entry(footpath_element_get_path_scenery_index(tileElement)); + rct_scenery_entry* sceneryEntry = tileElement->AsPath()->GetAdditionEntry(); if (sceneryEntry == nullptr || !(sceneryEntry->path_bit.flags & PATH_BIT_FLAG_IS_BENCH)) return false; @@ -6015,9 +6015,9 @@ bool rct_peep::UpdateWalkingFindBin() } } - if (!footpath_element_has_path_scenery(tileElement)) + if (!tileElement->AsPath()->HasAddition()) return false; - rct_scenery_entry* sceneryEntry = get_footpath_item_entry(footpath_element_get_path_scenery_index(tileElement)); + rct_scenery_entry* sceneryEntry = tileElement->AsPath()->GetAdditionEntry(); if (sceneryEntry == nullptr) { return false; @@ -6116,9 +6116,9 @@ static void peep_update_walking_break_scenery(rct_peep* peep) } } - if (!footpath_element_has_path_scenery(tileElement)) + if (!tileElement->AsPath()->HasAddition()) return; - rct_scenery_entry* sceneryEntry = get_footpath_item_entry(footpath_element_get_path_scenery_index(tileElement)); + rct_scenery_entry* sceneryEntry = tileElement->AsPath()->GetAdditionEntry(); if (!(sceneryEntry->path_bit.flags & PATH_BIT_FLAG_BREAKABLE)) return; diff --git a/src/openrct2/peep/Peep.cpp b/src/openrct2/peep/Peep.cpp index 56630e49a6..ed9b00bc90 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -2878,7 +2878,7 @@ static void peep_interact_with_path(rct_peep* peep, int16_t x, int16_t y, rct_ti { // 0x00F1AEE2 bool vandalism_present = false; - if (footpath_element_has_path_scenery(tile_element) && (tile_element->flags & TILE_ELEMENT_FLAG_BROKEN) + if (tile_element->AsPath()->HasAddition() && (tile_element->flags & TILE_ELEMENT_FLAG_BROKEN) && (tile_element->properties.path.edges & 0xF) != 0xF) { vandalism_present = true; diff --git a/src/openrct2/peep/Staff.cpp b/src/openrct2/peep/Staff.cpp index 0980ac8e0c..9c65db1354 100644 --- a/src/openrct2/peep/Staff.cpp +++ b/src/openrct2/peep/Staff.cpp @@ -1810,13 +1810,13 @@ void rct_peep::UpdateEmptyingBin() } } - if (!footpath_element_has_path_scenery(tile_element)) + if (!tile_element->AsPath()->HasAddition()) { StateReset(); return; } - rct_scenery_entry* scenery_entry = get_footpath_item_entry(footpath_element_get_path_scenery_index(tile_element)); + rct_scenery_entry* scenery_entry = tile_element->AsPath()->GetAdditionEntry(); if (!(scenery_entry->path_bit.flags & PATH_BIT_FLAG_IS_BIN) || tile_element->flags & (1 << 5) || tile_element->AsPath()->AdditionIsGhost()) { @@ -2210,9 +2210,9 @@ static int32_t peep_update_patrolling_find_bin(rct_peep* peep) return 0; } - if (!footpath_element_has_path_scenery(tileElement)) + if (!tileElement->AsPath()->HasAddition()) return 0; - rct_scenery_entry* sceneryEntry = get_footpath_item_entry(footpath_element_get_path_scenery_index(tileElement)); + rct_scenery_entry* sceneryEntry = tileElement->AsPath()->GetAdditionEntry(); if (!(sceneryEntry->path_bit.flags & PATH_BIT_FLAG_IS_BIN)) return 0; diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 011357e4aa..9754e488a5 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -2514,7 +2514,7 @@ private: tileElement->AsPath()->SetAdditionIsGhost(false); // Additions - uint8_t additionType = footpath_element_get_path_scenery(tileElement); + uint8_t additionType = tileElement->AsPath()->GetAddition(); if (additionType != RCT1_PATH_ADDITION_NONE) { uint8_t normalisedType = RCT1::NormalisePathAddition(additionType); @@ -2523,7 +2523,7 @@ private: { tileElement->flags |= TILE_ELEMENT_FLAG_BROKEN; } - footpath_element_set_path_scenery(tileElement, entryIndex + 1); + tileElement->AsPath()->SetAddition(entryIndex + 1); } break; } diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 3018998592..734dbdb123 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -308,7 +308,7 @@ static money32 footpath_element_update( } else if (pathItemType != 0) { - if (!(flags & GAME_COMMAND_FLAG_GHOST) && footpath_element_get_path_scenery(tileElement) == pathItemType + if (!(flags & GAME_COMMAND_FLAG_GHOST) && tileElement->AsPath()->GetAddition() == pathItemType && !(tileElement->flags & TILE_ELEMENT_FLAG_BROKEN)) { if (flags & GAME_COMMAND_FLAG_4) @@ -357,7 +357,7 @@ static money32 footpath_element_update( if (flags & GAME_COMMAND_FLAG_GHOST) { // Check if there is something on the path already - if (footpath_element_has_path_scenery(tileElement)) + if (tileElement->AsPath()->HasAddition()) { gGameCommandErrorText = STR_NONE; return MONEY32_UNDEFINED; @@ -377,7 +377,7 @@ static money32 footpath_element_update( tileElement->AsPath()->SetAdditionIsGhost(false); } - footpath_element_set_path_scenery(tileElement, pathItemType); + tileElement->AsPath()->SetAddition(pathItemType); tileElement->flags &= ~TILE_ELEMENT_FLAG_BROKEN; if (pathItemType != 0) { @@ -404,7 +404,7 @@ static money32 footpath_element_update( footpath_element_set_type(tileElement, type); tileElement->type = (tileElement->type & 0xFE) | (type >> 7); - footpath_element_set_path_scenery(tileElement, pathItemType); + tileElement->AsPath()->SetAddition(pathItemType); tileElement->flags &= ~TILE_ELEMENT_FLAG_BROKEN; loc_6A6620(flags, x, y, tileElement); @@ -2004,25 +2004,30 @@ void PathElement::SetWide(bool isWide) type |= FOOTPATH_ELEMENT_TYPE_FLAG_IS_WIDE; } -bool footpath_element_has_path_scenery(const rct_tile_element* tileElement) +bool PathElement::HasAddition() const { - return footpath_element_get_path_scenery(tileElement) != 0; + return (additions & FOOTPATH_PROPERTIES_ADDITIONS_TYPE_MASK) != 0; } -uint8_t footpath_element_get_path_scenery(const rct_tile_element* tileElement) +uint8_t PathElement::GetAddition() const { - return tileElement->properties.path.additions & FOOTPATH_PROPERTIES_ADDITIONS_TYPE_MASK; + return additions & FOOTPATH_PROPERTIES_ADDITIONS_TYPE_MASK; } -void footpath_element_set_path_scenery(rct_tile_element* tileElement, uint8_t pathSceneryType) +uint8_t PathElement::GetAdditionEntryIndex() const { - tileElement->properties.path.additions &= ~FOOTPATH_PROPERTIES_ADDITIONS_TYPE_MASK; - tileElement->properties.path.additions |= pathSceneryType; + return GetAddition() - 1; } -uint8_t footpath_element_get_path_scenery_index(const rct_tile_element* tileElement) +rct_scenery_entry* PathElement::GetAdditionEntry() const { - return footpath_element_get_path_scenery(tileElement) - 1; + return get_footpath_item_entry(GetAdditionEntryIndex()); +} + +void PathElement::SetAddition(uint8_t newAddition) +{ + additions &= ~FOOTPATH_PROPERTIES_ADDITIONS_TYPE_MASK; + additions |= newAddition; } bool PathElement::AdditionIsGhost() const diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index 25dcd5e6a2..6c9bc421f1 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -159,10 +159,6 @@ uint8_t footpath_element_get_type(const rct_tile_element* tileElement); void footpath_element_set_type(rct_tile_element* tileElement, uint8_t type); uint8_t footpath_element_get_direction(const rct_tile_element* tileElement); void footpath_element_set_direction(rct_tile_element* tileElement, uint8_t direction); -bool footpath_element_has_path_scenery(const rct_tile_element* tileElement); -uint8_t footpath_element_get_path_scenery(const rct_tile_element* tileElement); -void footpath_element_set_path_scenery(rct_tile_element* tileElement, uint8_t pathSceneryType); -uint8_t footpath_element_get_path_scenery_index(const rct_tile_element* tileElement); void footpath_remove_edges_at(int32_t x, int32_t y, rct_tile_element* tileElement); int32_t entrance_get_directions(const rct_tile_element* tileElement); diff --git a/src/openrct2/world/Fountain.cpp b/src/openrct2/world/Fountain.cpp index 357e197251..8324cc4fdc 100644 --- a/src/openrct2/world/Fountain.cpp +++ b/src/openrct2/world/Fountain.cpp @@ -261,10 +261,10 @@ static bool is_jumping_fountain(int32_t type, int32_t x, int32_t y, int32_t z) continue; if (tileElement->AsPath()->AdditionIsGhost()) continue; - if (!footpath_element_has_path_scenery(tileElement)) + if (!tileElement->AsPath()->HasAddition()) continue; - uint8_t additionIndex = footpath_element_get_path_scenery_index(tileElement); + uint8_t additionIndex = tileElement->AsPath()->GetAdditionEntryIndex(); rct_scenery_entry* sceneryEntry = get_footpath_item_entry(additionIndex); if (sceneryEntry != reinterpret_cast(-1) && sceneryEntry->path_bit.flags & pathBitFlagMask) { diff --git a/src/openrct2/world/Scenery.cpp b/src/openrct2/world/Scenery.cpp index 55ec2779e1..2fa66c9a91 100644 --- a/src/openrct2/world/Scenery.cpp +++ b/src/openrct2/world/Scenery.cpp @@ -88,9 +88,9 @@ void scenery_update_tile(int32_t x, int32_t y) } else if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH) { - if (footpath_element_has_path_scenery(tileElement) && !tileElement->AsPath()->AdditionIsGhost()) + if (tileElement->AsPath()->HasAddition() && !tileElement->AsPath()->AdditionIsGhost()) { - rct_scenery_entry* sceneryEntry = get_footpath_item_entry(footpath_element_get_path_scenery_index(tileElement)); + rct_scenery_entry* sceneryEntry = tileElement->AsPath()->GetAdditionEntry(); if (sceneryEntry != nullptr) { if (sceneryEntry->path_bit.flags & PATH_BIT_FLAG_JUMPING_FOUNTAIN_WATER) diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index cc3bf86eba..eb410cdfbb 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -202,11 +202,17 @@ public: bool IsWide() const; void SetWide(bool isWide); - + bool IsQueue() const; void SetIsQueue(bool isQueue); bool HasQueueBanner() const; + bool HasAddition() const; + uint8_t GetAddition() const; + uint8_t GetAdditionEntryIndex() const; + rct_scenery_entry* GetAdditionEntry() const; + void SetAddition(uint8_t newAddition); + bool AdditionIsGhost() const; void SetAdditionIsGhost(bool isGhost); From 015ece94c6e16c64c4cb1b71a78eba88be82c685 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 16 Sep 2018 17:19:56 +0200 Subject: [PATCH 6/9] Replace C-style functions for getting path entries --- .../interface/ViewportInteraction.cpp | 2 +- src/openrct2-ui/windows/TileInspector.cpp | 2 +- src/openrct2-ui/windows/TopToolbar.cpp | 2 +- .../paint/tile_element/Paint.Path.cpp | 3 +-- src/openrct2/rct1/S4Importer.cpp | 2 +- src/openrct2/ride/RideRatings.cpp | 2 +- src/openrct2/world/Footpath.cpp | 21 ++++++++++++------- src/openrct2/world/Footpath.h | 2 -- src/openrct2/world/TileElement.h | 5 +++++ 9 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/openrct2-ui/interface/ViewportInteraction.cpp b/src/openrct2-ui/interface/ViewportInteraction.cpp index 15a9ed8df5..b4d9e3e58f 100644 --- a/src/openrct2-ui/interface/ViewportInteraction.cpp +++ b/src/openrct2-ui/interface/ViewportInteraction.cpp @@ -506,7 +506,7 @@ static void viewport_interaction_remove_footpath_item(rct_tile_element* tileElem { int32_t type; - type = footpath_element_get_type(tileElement); + type = tileElement->AsPath()->GetEntryIndex(); if (tileElement->AsPath()->IsQueue()) type |= 0x80; diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index a6d5a49a60..c0e85c73fc 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -1809,7 +1809,7 @@ static void window_tile_inspector_paint(rct_window* w, rct_drawpixelinfo* dpi) { // Details // Path name - rct_string_id pathNameId = get_footpath_entry(footpath_element_get_type(tileElement))->string_idx; + rct_string_id pathNameId = tileElement->AsPath()->GetEntry()->string_idx; gfx_draw_string_left(dpi, STR_TILE_INSPECTOR_PATH_NAME, &pathNameId, COLOUR_DARK_GREEN, x, y); // Path addition diff --git a/src/openrct2-ui/windows/TopToolbar.cpp b/src/openrct2-ui/windows/TopToolbar.cpp index 4f017c1fbd..eb7537ba3f 100644 --- a/src/openrct2-ui/windows/TopToolbar.cpp +++ b/src/openrct2-ui/windows/TopToolbar.cpp @@ -1454,7 +1454,7 @@ static void sub_6E1F34( & (FOOTPATH_PROPERTIES_FLAG_IS_SLOPED | FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK)) << 8; *parameter_2 = tile_element->base_height; - *parameter_2 |= ((footpath_element_get_type(tile_element)) << 8); + *parameter_2 |= (tile_element->AsPath()->GetEntryIndex() << 8); if (tile_element->AsPath()->IsQueue()) { *parameter_2 |= LOCATION_NULL; diff --git a/src/openrct2/paint/tile_element/Paint.Path.cpp b/src/openrct2/paint/tile_element/Paint.Path.cpp index d82d67ac24..3aabde25bb 100644 --- a/src/openrct2/paint/tile_element/Paint.Path.cpp +++ b/src/openrct2/paint/tile_element/Paint.Path.cpp @@ -920,8 +920,7 @@ void path_paint(paint_session* session, uint16_t height, const rct_tile_element* sub_98196C(session, imageId, 16, 16, 1, 1, 0, height2); } - uint8_t pathType = footpath_element_get_type(tile_element); - rct_footpath_entry* footpathEntry = get_footpath_entry(pathType); + rct_footpath_entry* footpathEntry = tile_element->AsPath()->GetEntry(); if (footpathEntry != nullptr) { diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 9754e488a5..33b07c5105 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -2505,7 +2505,7 @@ private: tileElement->SetDirection(0); tileElement->flags &= ~(TILE_ELEMENT_FLAG_BROKEN | TILE_ELEMENT_FLAG_INDESTRUCTIBLE_TRACK_PIECE); - footpath_element_set_type(tileElement, entryIndex); + tileElement->AsPath()->SetEntryIndex(entryIndex); if (RCT1::PathIsQueue(pathType)) { tileElement->AsPath()->SetIsQueue(true); diff --git a/src/openrct2/ride/RideRatings.cpp b/src/openrct2/ride/RideRatings.cpp index 9c073d8469..55f4be3f80 100644 --- a/src/openrct2/ride/RideRatings.cpp +++ b/src/openrct2/ride/RideRatings.cpp @@ -568,7 +568,7 @@ static void ride_ratings_score_close_proximity(rct_tile_element* inputTileElemen break; case TILE_ELEMENT_TYPE_PATH: // Bonus for normal path - if (footpath_element_get_type(tileElement) != 0) + if (tileElement->AsPath()->GetEntryIndex() != 0) { if (tileElement->clearance_height == inputTileElement->base_height) { diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 734dbdb123..1a33c55d86 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -267,7 +267,7 @@ static money32 footpath_element_insert( assert(tileElement != nullptr); tileElement->type = TILE_ELEMENT_TYPE_PATH; tileElement->clearance_height = z + 4 + ((slope & TILE_ELEMENT_SLOPE_NE_SIDE_UP) ? 2 : 0); - footpath_element_set_type(tileElement, type); + tileElement->AsPath()->SetEntryIndex(type); tileElement->properties.path.type |= (slope & TILE_ELEMENT_SLOPE_W_CORNER_DN); if (type & FOOTPATH_ELEMENT_INSERT_QUEUE) tileElement->AsPath()->SetIsQueue(true); @@ -302,7 +302,7 @@ static money32 footpath_element_update( const int32_t newFootpathType = (type & (FOOTPATH_PROPERTIES_TYPE_MASK >> 4)); const bool newPathIsQueue = ((type >> 7) == 1); - if (footpath_element_get_type(tileElement) != newFootpathType || tileElement->AsPath()->IsQueue() != newPathIsQueue) + if (tileElement->AsPath()->GetEntryIndex() != newFootpathType || tileElement->AsPath()->IsQueue() != newPathIsQueue) { gFootpathPrice += MONEY(6, 00); } @@ -401,7 +401,7 @@ static money32 footpath_element_update( if (!(flags & GAME_COMMAND_FLAG_PATH_SCENERY)) footpath_remove_edges_at(x, y, tileElement); - footpath_element_set_type(tileElement, type); + tileElement->AsPath()->SetEntryIndex(type); tileElement->type = (tileElement->type & 0xFE) | (type >> 7); tileElement->AsPath()->SetAddition(pathItemType); @@ -2042,15 +2042,20 @@ void PathElement::SetAdditionIsGhost(bool isGhost) additions |= FOOTPATH_ADDITION_FLAG_IS_GHOST; } -uint8_t footpath_element_get_type(const rct_tile_element* tileElement) +uint8_t PathElement::GetEntryIndex() const { - return (tileElement->properties.path.type & FOOTPATH_PROPERTIES_TYPE_MASK) >> 4; + return (entryIndex & FOOTPATH_PROPERTIES_TYPE_MASK) >> 4; } -void footpath_element_set_type(rct_tile_element* tileElement, uint8_t type) +rct_footpath_entry* PathElement::GetEntry() const { - tileElement->properties.path.type &= ~FOOTPATH_PROPERTIES_TYPE_MASK; - tileElement->properties.path.type |= (type << 4); + return get_footpath_entry(GetEntryIndex()); +} + +void PathElement::SetEntryIndex(uint8_t newEntryIndex) +{ + entryIndex &= ~FOOTPATH_PROPERTIES_TYPE_MASK; + entryIndex |= (newEntryIndex << 4); } uint8_t footpath_element_get_direction(const rct_tile_element* tileElement) diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index 6c9bc421f1..66410bd6c6 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -155,8 +155,6 @@ 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); uint8_t footpath_element_get_slope_direction(const rct_tile_element* tileElement); -uint8_t footpath_element_get_type(const rct_tile_element* tileElement); -void footpath_element_set_type(rct_tile_element* tileElement, uint8_t type); uint8_t footpath_element_get_direction(const rct_tile_element* tileElement); void footpath_element_set_direction(rct_tile_element* tileElement, uint8_t direction); void footpath_remove_edges_at(int32_t x, int32_t y, rct_tile_element* tileElement); diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index eb410cdfbb..b4dec9c650 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -13,6 +13,7 @@ #include "Location.hpp" struct rct_scenery_entry; +struct rct_footpath_entry; #pragma pack(push, 1) struct rct_tile_element_path_properties @@ -197,6 +198,10 @@ private: }; public: + uint8_t GetEntryIndex() const; + rct_footpath_entry* GetEntry() const; + void SetEntryIndex(uint8_t newIndex); + bool IsSloped() const; void SetSloped(bool isSloped); From a6885ea464b0e75308568d69e4edff6aa897edac Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 16 Sep 2018 17:24:49 +0200 Subject: [PATCH 7/9] Replace C-style functions for getting direction --- src/openrct2/paint/tile_element/Paint.Path.cpp | 2 +- src/openrct2/peep/Peep.cpp | 2 +- src/openrct2/world/Footpath.cpp | 13 ++++++------- src/openrct2/world/Footpath.h | 2 -- src/openrct2/world/MapAnimation.cpp | 2 +- src/openrct2/world/TileElement.h | 5 ++++- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/openrct2/paint/tile_element/Paint.Path.cpp b/src/openrct2/paint/tile_element/Paint.Path.cpp index 3aabde25bb..a51765d3be 100644 --- a/src/openrct2/paint/tile_element/Paint.Path.cpp +++ b/src/openrct2/paint/tile_element/Paint.Path.cpp @@ -409,7 +409,7 @@ static void sub_6A4101( return; } - uint8_t direction = footpath_element_get_direction(tile_element); + uint8_t direction = tile_element->AsPath()->GetQueueBannerDirection(); // Draw ride sign session->InteractionType = VIEWPORT_INTERACTION_ITEM_RIDE; if (tile_element->AsPath()->IsSloped()) diff --git a/src/openrct2/peep/Peep.cpp b/src/openrct2/peep/Peep.cpp index ed9b00bc90..d5d2ab6f8b 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -2929,7 +2929,7 @@ static void peep_interact_with_path(rct_peep* peep, int16_t x, int16_t y, rct_ti uint8_t stationNum = (tile_element->properties.path.additions & 0x70) >> 4; if ((tile_element->properties.path.type & (1 << 3)) // Queue has the ride sign on it - && (footpath_element_get_direction(tile_element) + && (tile_element->AsPath()->GetQueueBannerDirection() == ((peep->direction) ^ 2)) // Ride sign is facing the direction the peep is walking ) { diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 1a33c55d86..809e0b544a 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -1701,8 +1701,7 @@ void footpath_chain_ride_queue( if (lastPathElement->AsPath()->IsQueue()) { lastPathElement->properties.path.type |= FOOTPATH_PROPERTIES_FLAG_HAS_QUEUE_BANNER; - lastPathElement->type &= 0x3F; // Clear the ride sign direction - footpath_element_set_direction(lastPathElement, lastPathDirection); // set the ride sign direction + lastPathElement->AsPath()->SetQueueBannerDirection(lastPathDirection); // set the ride sign direction map_animation_create(MAP_ANIMATION_TYPE_QUEUE_BANNER, lastPathX, lastPathY, lastPathElement->base_height); } @@ -2058,15 +2057,15 @@ void PathElement::SetEntryIndex(uint8_t newEntryIndex) entryIndex |= (newEntryIndex << 4); } -uint8_t footpath_element_get_direction(const rct_tile_element* tileElement) +uint8_t PathElement::GetQueueBannerDirection() const { - return ((tileElement->type & FOOTPATH_ELEMENT_TYPE_DIRECTION_MASK) >> 6); + return ((type & FOOTPATH_ELEMENT_TYPE_DIRECTION_MASK) >> 6); } -void footpath_element_set_direction(rct_tile_element* tileElement, uint8_t direction) +void PathElement::SetQueueBannerDirection(uint8_t direction) { - tileElement->type &= ~FOOTPATH_ELEMENT_TYPE_DIRECTION_MASK; - tileElement->type |= (direction << 6); + type &= ~FOOTPATH_ELEMENT_TYPE_DIRECTION_MASK; + type |= (direction << 6); } /** diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index 66410bd6c6..fee894aef7 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -155,8 +155,6 @@ 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); uint8_t footpath_element_get_slope_direction(const rct_tile_element* tileElement); -uint8_t footpath_element_get_direction(const rct_tile_element* tileElement); -void footpath_element_set_direction(rct_tile_element* tileElement, uint8_t direction); void footpath_remove_edges_at(int32_t x, int32_t y, rct_tile_element* tileElement); int32_t entrance_get_directions(const rct_tile_element* tileElement); diff --git a/src/openrct2/world/MapAnimation.cpp b/src/openrct2/world/MapAnimation.cpp index bc0b7aa8a7..0a3a4294c3 100644 --- a/src/openrct2/world/MapAnimation.cpp +++ b/src/openrct2/world/MapAnimation.cpp @@ -148,7 +148,7 @@ static bool map_animation_invalidate_queue_banner(int32_t x, int32_t y, int32_t if (!tileElement->AsPath()->HasQueueBanner()) continue; - int32_t direction = (footpath_element_get_direction(tileElement) + get_current_rotation()) & 3; + int32_t direction = (tileElement->AsPath()->GetQueueBannerDirection() + get_current_rotation()) & 3; if (direction == TILE_ELEMENT_DIRECTION_NORTH || direction == TILE_ELEMENT_DIRECTION_EAST) { baseZ = tileElement->base_height * 8; diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index b4dec9c650..df596fd230 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -201,7 +201,10 @@ public: uint8_t GetEntryIndex() const; rct_footpath_entry* GetEntry() const; void SetEntryIndex(uint8_t newIndex); - + + uint8_t GetQueueBannerDirection() const; + void SetQueueBannerDirection(uint8_t direction); + bool IsSloped() const; void SetSloped(bool isSloped); From b1f737d985af478136fdd68171d40da6897b5818 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 16 Sep 2018 18:21:10 +0200 Subject: [PATCH 8/9] Remove remaining access to additions field --- src/openrct2/peep/Peep.cpp | 2 +- src/openrct2/rct1/S4Importer.cpp | 2 +- src/openrct2/world/Footpath.cpp | 18 ++++++++++++++---- src/openrct2/world/TileElement.h | 3 +++ 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/openrct2/peep/Peep.cpp b/src/openrct2/peep/Peep.cpp index d5d2ab6f8b..aa2801a4c9 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -2926,7 +2926,7 @@ static void peep_interact_with_path(rct_peep* peep, int16_t x, int16_t y, rct_ti // Peep is not queuing. peep->time_lost = 0; - uint8_t stationNum = (tile_element->properties.path.additions & 0x70) >> 4; + uint8_t stationNum = tile_element->AsPath()->GetStationIndex(); if ((tile_element->properties.path.type & (1 << 3)) // Queue has the ride sign on it && (tile_element->AsPath()->GetQueueBannerDirection() diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 33b07c5105..c5c4d4281b 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -479,7 +479,7 @@ private: case TILE_ELEMENT_TYPE_PATH: { uint8_t pathType = tileElement->AsPath()->GetRCT1PathType(); - uint8_t pathAdditionsType = tileElement->properties.path.additions & 0x0F; + uint8_t pathAdditionsType = tileElement->AsPath()->GetAddition(); AddEntryForPath(pathType); AddEntryForPathAddition(pathAdditionsType); diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 809e0b544a..3e6f6c5fa6 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -271,7 +271,7 @@ static money32 footpath_element_insert( tileElement->properties.path.type |= (slope & TILE_ELEMENT_SLOPE_W_CORNER_DN); if (type & FOOTPATH_ELEMENT_INSERT_QUEUE) tileElement->AsPath()->SetIsQueue(true); - tileElement->properties.path.additions = pathItemType; + tileElement->AsPath()->SetAddition(pathItemType); tileElement->properties.path.addition_status = 255; tileElement->flags &= ~TILE_ELEMENT_FLAG_BROKEN; if (flags & GAME_COMMAND_FLAG_GHOST) @@ -650,7 +650,7 @@ static money32 footpath_place_from_track( tileElement->clearance_height = z + 4 + ((slope & TILE_ELEMENT_SLOPE_S_CORNER_UP) ? 2 : 0); tileElement->properties.path.type = (type << 4) | (slope & TILE_ELEMENT_SLOPE_W_CORNER_DN); tileElement->type |= type >> 7; - tileElement->properties.path.additions = 0; + tileElement->AsPath()->SetAddition(0); tileElement->properties.path.addition_status = 255; tileElement->properties.path.edges = edges & FOOTPATH_PROPERTIES_EDGES_EDGES_MASK; tileElement->flags &= ~TILE_ELEMENT_FLAG_BROKEN; @@ -1672,8 +1672,7 @@ void footpath_chain_ride_queue( tileElement->properties.path.type &= ~FOOTPATH_PROPERTIES_FLAG_HAS_QUEUE_BANNER; tileElement->properties.path.edges |= (1 << (direction ^ 2)); tileElement->properties.path.ride_index = rideIndex; - tileElement->properties.path.additions &= ~FOOTPATH_PROPERTIES_ADDITIONS_STATION_INDEX_MASK; - tileElement->properties.path.additions |= (entranceIndex << 4) & FOOTPATH_PROPERTIES_ADDITIONS_STATION_INDEX_MASK; + tileElement->AsPath()->SetStationIndex(entranceIndex); map_invalidate_element(x, y, tileElement); @@ -1991,6 +1990,17 @@ bool PathElement::HasQueueBanner() const return (entryIndex & FOOTPATH_PROPERTIES_FLAG_HAS_QUEUE_BANNER) != 0; } +uint8_t PathElement::GetStationIndex() const +{ + return (additions & FOOTPATH_PROPERTIES_ADDITIONS_STATION_INDEX_MASK) >> 4; +} + +void PathElement::SetStationIndex(uint8_t newStationIndex) +{ + additions &= ~FOOTPATH_PROPERTIES_ADDITIONS_STATION_INDEX_MASK; + additions |= ((newStationIndex << 4) & FOOTPATH_PROPERTIES_ADDITIONS_STATION_INDEX_MASK); +} + bool PathElement::IsWide() const { return (type & FOOTPATH_ELEMENT_TYPE_FLAG_IS_WIDE) != 0; diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index df596fd230..8f1dc717ee 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -208,6 +208,9 @@ public: bool IsSloped() const; void SetSloped(bool isSloped); + uint8_t GetStationIndex() const; + void SetStationIndex(uint8_t newStationIndex); + bool IsWide() const; void SetWide(bool isWide); From 774d26306f791513300e6ddc5f10ec05a40a3fb1 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Wed, 3 Oct 2018 21:45:52 +0200 Subject: [PATCH 9/9] Fix formatting --- src/openrct2-ui/windows/TileInspector.cpp | 3 +-- src/openrct2/peep/Guest.cpp | 5 ++--- src/openrct2/peep/Peep.cpp | 5 +++-- src/openrct2/world/Footpath.cpp | 3 +-- src/openrct2/world/TileElement.h | 4 ++-- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index c0e85c73fc..ec3a33aa77 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -865,8 +865,7 @@ static void window_tile_inspector_mouseup(rct_window* w, rct_widgetindex widgetI switch (widgetIndex) { case WIDX_PATH_CHECK_SLOPED: - window_tile_inspector_path_set_sloped( - windowTileInspectorSelectedIndex, !tileElement->AsPath()->IsSloped()); + window_tile_inspector_path_set_sloped(windowTileInspectorSelectedIndex, !tileElement->AsPath()->IsSloped()); break; case WIDX_PATH_CHECK_EDGE_E: case WIDX_PATH_CHECK_EDGE_S: diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index 0cdfa2170d..e3e7c3249a 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -640,8 +640,7 @@ void rct_peep::Tick128UpdateGuest(int32_t index) continue; // Check if the footpath has a queue line TV monitor on it - if (tileElement->AsPath()->HasAddition() - && !tileElement->AsPath()->AdditionIsGhost()) + if (tileElement->AsPath()->HasAddition() && !tileElement->AsPath()->AdditionIsGhost()) { uint8_t pathSceneryIndex = tileElement->AsPath()->GetAdditionEntryIndex(); rct_scenery_entry* sceneryEntry = get_footpath_item_entry(pathSceneryIndex); @@ -4914,7 +4913,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, tileElement->AsPath()->IsSloped()); + 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/Peep.cpp b/src/openrct2/peep/Peep.cpp index aa2801a4c9..7e636f1f64 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -1021,7 +1021,8 @@ 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, tile_element->AsPath()->IsSloped()) + 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) @@ -3457,7 +3458,7 @@ int32_t rct_peep::GetZOnSlope(int32_t tile_x, int32_t tile_y) int32_t height = next_z * 8; uint8_t slope = GetNextDirection(); - return height + map_height_from_slope({tile_x, tile_y}, slope, GetNextIsSloped()); + return height + map_height_from_slope({ tile_x, tile_y }, slope, GetNextIsSloped()); } /** diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 3e6f6c5fa6..f7f6fab3eb 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -1343,8 +1343,7 @@ static void loc_6A6D7E( case TILE_ELEMENT_TYPE_PATH: if (z == tileElement->base_height) { - if (tileElement->AsPath()->IsSloped() - && footpath_element_get_slope_direction(tileElement) != direction) + if (tileElement->AsPath()->IsSloped() && footpath_element_get_slope_direction(tileElement) != direction) { return; } diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index 8f1dc717ee..a103a015cb 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -213,7 +213,7 @@ public: bool IsWide() const; void SetWide(bool isWide); - + bool IsQueue() const; void SetIsQueue(bool isQueue); bool HasQueueBanner() const; @@ -226,7 +226,7 @@ public: bool AdditionIsGhost() const; void SetAdditionIsGhost(bool isGhost); - + uint8_t GetRCT1PathType() const; }; assert_struct_size(PathElement, 8);