From 57a40c0657e8a7ed1aa2fc2721f5da3b12f9137a Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Wed, 4 Mar 2020 18:43:09 +0100 Subject: [PATCH] Extend PathElement --- src/openrct2-ui/windows/TileInspector.cpp | 2 +- src/openrct2-ui/windows/TopToolbar.cpp | 2 +- src/openrct2/EditorObjectSelectionSession.cpp | 2 +- src/openrct2/actions/FootpathPlaceAction.hpp | 10 +-- .../actions/FootpathPlaceFromTrackAction.hpp | 2 +- .../paint/tile_element/Paint.Path.cpp | 2 +- src/openrct2/rct1/S4Importer.cpp | 2 +- src/openrct2/rct12/RCT12.cpp | 40 ++++----- src/openrct2/rct12/RCT12.h | 18 ++++ src/openrct2/rct2/S6Exporter.cpp | 2 +- src/openrct2/rct2/S6Importer.cpp | 2 +- src/openrct2/ride/RideRatings.cpp | 2 +- src/openrct2/ride/Station.h | 6 +- src/openrct2/ride/TrackDesignSave.cpp | 4 +- src/openrct2/world/Entrance.cpp | 8 +- src/openrct2/world/Footpath.cpp | 82 +++++++++---------- src/openrct2/world/Footpath.h | 33 +++----- src/openrct2/world/Map.cpp | 4 +- src/openrct2/world/Map.h | 2 +- src/openrct2/world/TileElement.h | 39 +++++---- 20 files changed, 139 insertions(+), 125 deletions(-) diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index 044f154eaf..976ba9cbc3 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -1832,7 +1832,7 @@ static void window_tile_inspector_paint(rct_window* w, rct_drawpixelinfo* dpi) { // Details // Path name - rct_string_id pathNameId = tileElement->AsPath()->GetPathEntry()->string_idx; + rct_string_id pathNameId = tileElement->AsPath()->GetSurfaceEntry()->string_idx; gfx_draw_string_left(dpi, STR_TILE_INSPECTOR_PATH_NAME, &pathNameId, COLOUR_WHITE, x, y); // Path addition diff --git a/src/openrct2-ui/windows/TopToolbar.cpp b/src/openrct2-ui/windows/TopToolbar.cpp index 11e94e6d8b..7796cc9e0d 100644 --- a/src/openrct2-ui/windows/TopToolbar.cpp +++ b/src/openrct2-ui/windows/TopToolbar.cpp @@ -1526,7 +1526,7 @@ static void sub_6E1F34( if (tile_element->AsPath()->IsSloped()) *parameter_1 |= FOOTPATH_PROPERTIES_FLAG_IS_SLOPED << 8; *parameter_2 = tile_element->base_height; - *parameter_2 |= (tile_element->AsPath()->GetPathEntryIndex() << 8); + *parameter_2 |= (tile_element->AsPath()->GetSurfaceEntryIndex() << 8); if (tile_element->AsPath()->IsQueue()) { *parameter_2 |= LOCATION_NULL; diff --git a/src/openrct2/EditorObjectSelectionSession.cpp b/src/openrct2/EditorObjectSelectionSession.cpp index 14a4bf90ba..d2852cd084 100644 --- a/src/openrct2/EditorObjectSelectionSession.cpp +++ b/src/openrct2/EditorObjectSelectionSession.cpp @@ -133,7 +133,7 @@ void setup_in_use_selection_flags() case TILE_ELEMENT_TYPE_TRACK: break; case TILE_ELEMENT_TYPE_PATH: - type = iter.element->AsPath()->GetPathEntryIndex(); + type = iter.element->AsPath()->GetSurfaceEntryIndex(); assert(type < object_entry_group_counts[OBJECT_TYPE_PATHS]); Editor::SetSelectedObject(OBJECT_TYPE_PATHS, type, OBJECT_SELECTION_FLAG_SELECTED); diff --git a/src/openrct2/actions/FootpathPlaceAction.hpp b/src/openrct2/actions/FootpathPlaceAction.hpp index 475cf1d947..f9821a473d 100644 --- a/src/openrct2/actions/FootpathPlaceAction.hpp +++ b/src/openrct2/actions/FootpathPlaceAction.hpp @@ -157,7 +157,7 @@ private: { const int32_t newFootpathType = (_type & (FOOTPATH_PROPERTIES_TYPE_MASK >> 4)); const bool newPathIsQueue = ((_type >> 7) == 1); - if (pathElement->GetPathEntryIndex() != newFootpathType || pathElement->IsQueue() != newPathIsQueue) + if (pathElement->GetSurfaceEntryIndex() != newFootpathType || pathElement->IsQueue() != newPathIsQueue) { res->Cost += MONEY(6, 00); } @@ -173,7 +173,7 @@ private: { const int32_t newFootpathType = (_type & (FOOTPATH_PROPERTIES_TYPE_MASK >> 4)); const bool newPathIsQueue = ((_type >> 7) == 1); - if (pathElement->GetPathEntryIndex() != newFootpathType || pathElement->IsQueue() != newPathIsQueue) + if (pathElement->GetSurfaceEntryIndex() != newFootpathType || pathElement->IsQueue() != newPathIsQueue) { res->Cost += MONEY(6, 00); } @@ -185,8 +185,8 @@ private: footpath_remove_edges_at(_loc, reinterpret_cast(pathElement)); } - pathElement->SetPathEntryIndex(_type); - if (_type & (1 << 7)) + pathElement->SetSurfaceEntryIndex(_type & ~FOOTPATH_ELEMENT_INSERT_QUEUE); + if (_type & FOOTPATH_ELEMENT_INSERT_QUEUE) { pathElement->SetIsQueue(true); } @@ -336,7 +336,7 @@ private: tileElement->SetType(TILE_ELEMENT_TYPE_PATH); PathElement* pathElement = tileElement->AsPath(); pathElement->clearance_height = zHigh; - pathElement->SetPathEntryIndex(_type); + pathElement->SetSurfaceEntryIndex(_type & ~FOOTPATH_ELEMENT_INSERT_QUEUE); pathElement->SetSlopeDirection(_slope & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK); if (_slope & FOOTPATH_PROPERTIES_FLAG_IS_SLOPED) { diff --git a/src/openrct2/actions/FootpathPlaceFromTrackAction.hpp b/src/openrct2/actions/FootpathPlaceFromTrackAction.hpp index 6c6f05a755..d0581bf530 100644 --- a/src/openrct2/actions/FootpathPlaceFromTrackAction.hpp +++ b/src/openrct2/actions/FootpathPlaceFromTrackAction.hpp @@ -250,7 +250,7 @@ private: tileElement->SetType(TILE_ELEMENT_TYPE_PATH); PathElement* pathElement = tileElement->AsPath(); pathElement->clearance_height = zHigh; - pathElement->SetPathEntryIndex(_type); + pathElement->SetSurfaceEntryIndex(_type & ~FOOTPATH_ELEMENT_INSERT_QUEUE); pathElement->SetSlopeDirection(_slope & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK); if (_slope & FOOTPATH_PROPERTIES_FLAG_IS_SLOPED) { diff --git a/src/openrct2/paint/tile_element/Paint.Path.cpp b/src/openrct2/paint/tile_element/Paint.Path.cpp index c4b98c3a0c..20cbca549e 100644 --- a/src/openrct2/paint/tile_element/Paint.Path.cpp +++ b/src/openrct2/paint/tile_element/Paint.Path.cpp @@ -930,7 +930,7 @@ void path_paint(paint_session* session, uint16_t height, const TileElement* tile sub_98196C(session, imageId, 16, 16, 1, 1, 0, heightMarkerBaseZ); } - PathSurfaceEntry* footpathEntry = tile_element->AsPath()->GetPathEntry(); + PathSurfaceEntry* footpathEntry = tile_element->AsPath()->GetSurfaceEntry(); PathRailingsEntry* railingEntry = tile_element->AsPath()->GetRailingEntry(); if (footpathEntry != nullptr && railingEntry != nullptr) diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 60a62b308a..af927e087c 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -2036,7 +2036,7 @@ private: dst2->SetIsBroken(false); dst2->SetIsBlockedByVehicle(false); - dst2->SetPathEntryIndex(entryIndex); + dst2->SetSurfaceEntryIndex(entryIndex); dst2->SetShouldDrawPathOverSupports(true); if (RCT1::PathIsQueue(pathType)) { diff --git a/src/openrct2/rct12/RCT12.cpp b/src/openrct2/rct12/RCT12.cpp index 0c0ae9b498..755b207ec7 100644 --- a/src/openrct2/rct12/RCT12.cpp +++ b/src/openrct2/rct12/RCT12.cpp @@ -87,7 +87,7 @@ bool RCT12SurfaceElement::HasTrackThatNeedsWater() const uint8_t RCT12PathElement::GetEntryIndex() const { - return (entryIndex & FOOTPATH_PROPERTIES_TYPE_MASK) >> 4; + return (entryIndex & RCT12_FOOTPATH_PROPERTIES_TYPE_MASK) >> 4; } uint8_t RCT12PathElement::GetQueueBannerDirection() const @@ -97,12 +97,12 @@ uint8_t RCT12PathElement::GetQueueBannerDirection() const bool RCT12PathElement::IsSloped() const { - return (entryIndex & FOOTPATH_PROPERTIES_FLAG_IS_SLOPED) != 0; + return (entryIndex & RCT12_FOOTPATH_PROPERTIES_FLAG_IS_SLOPED) != 0; } uint8_t RCT12PathElement::GetSlopeDirection() const { - return entryIndex & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK; + return entryIndex & RCT12_FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK; } uint8_t RCT12PathElement::GetRideIndex() const @@ -112,7 +112,7 @@ uint8_t RCT12PathElement::GetRideIndex() const uint8_t RCT12PathElement::GetStationIndex() const { - return (additions & FOOTPATH_PROPERTIES_ADDITIONS_STATION_INDEX_MASK) >> 4; + return (additions & RCT12_FOOTPATH_PROPERTIES_ADDITIONS_STATION_INDEX_MASK) >> 4; } bool RCT12PathElement::IsWide() const @@ -127,7 +127,7 @@ bool RCT12PathElement::IsQueue() const bool RCT12PathElement::HasQueueBanner() const { - return (entryIndex & FOOTPATH_PROPERTIES_FLAG_HAS_QUEUE_BANNER) != 0; + return (entryIndex & RCT12_FOOTPATH_PROPERTIES_FLAG_HAS_QUEUE_BANNER) != 0; } uint8_t RCT12PathElement::GetEdges() const { @@ -141,12 +141,12 @@ uint8_t RCT12PathElement::GetCorners() const uint8_t RCT12PathElement::GetAddition() const { - return additions & FOOTPATH_PROPERTIES_ADDITIONS_TYPE_MASK; + return additions & RCT12_FOOTPATH_PROPERTIES_ADDITIONS_TYPE_MASK; } bool RCT12PathElement::AdditionIsGhost() const { - return (additions & FOOTPATH_ADDITION_FLAG_IS_GHOST) != 0; + return (additions & RCT12_FOOTPATH_PROPERTIES_ADDITIONS_FLAG_GHOST) != 0; } uint8_t RCT12PathElement::GetAdditionStatus() const @@ -157,7 +157,7 @@ uint8_t RCT12PathElement::GetAdditionStatus() const uint8_t RCT12PathElement::GetRCT1PathType() const { uint8_t pathColour = type & 3; - uint8_t pathType2 = (entryIndex & FOOTPATH_PROPERTIES_TYPE_MASK) >> 2; + uint8_t pathType2 = (entryIndex & RCT12_FOOTPATH_PROPERTIES_TYPE_MASK) >> 2; pathType2 = pathType2 | pathColour; return pathType2; @@ -610,7 +610,7 @@ void RCT12SurfaceElement::SetHasTrackThatNeedsWater(bool on) void RCT12PathElement::SetPathEntryIndex(uint8_t newEntryIndex) { - entryIndex &= ~FOOTPATH_PROPERTIES_TYPE_MASK; + entryIndex &= ~RCT12_FOOTPATH_PROPERTIES_TYPE_MASK; entryIndex |= (newEntryIndex << 4); } @@ -644,21 +644,21 @@ void RCT12PathElement::SetCorners(uint8_t newCorners) void RCT12PathElement::SetSloped(bool isSloped) { - entryIndex &= ~FOOTPATH_PROPERTIES_FLAG_IS_SLOPED; + entryIndex &= ~RCT12_FOOTPATH_PROPERTIES_FLAG_IS_SLOPED; if (isSloped) - entryIndex |= FOOTPATH_PROPERTIES_FLAG_IS_SLOPED; + entryIndex |= RCT12_FOOTPATH_PROPERTIES_FLAG_IS_SLOPED; } void RCT12PathElement::SetSlopeDirection(uint8_t newSlope) { - entryIndex &= ~FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK; - entryIndex |= newSlope & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK; + entryIndex &= ~RCT12_FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK; + entryIndex |= newSlope & RCT12_FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK; } void RCT12PathElement::SetStationIndex(uint8_t newStationIndex) { - additions &= ~FOOTPATH_PROPERTIES_ADDITIONS_STATION_INDEX_MASK; - additions |= ((newStationIndex << 4) & FOOTPATH_PROPERTIES_ADDITIONS_STATION_INDEX_MASK); + additions &= ~RCT12_FOOTPATH_PROPERTIES_ADDITIONS_STATION_INDEX_MASK; + additions |= ((newStationIndex << 4) & RCT12_FOOTPATH_PROPERTIES_ADDITIONS_STATION_INDEX_MASK); } void RCT12PathElement::SetWide(bool isWide) @@ -677,22 +677,22 @@ void RCT12PathElement::SetIsQueue(bool isQueue) void RCT12PathElement::SetHasQueueBanner(bool hasQueueBanner) { - entryIndex &= ~FOOTPATH_PROPERTIES_FLAG_HAS_QUEUE_BANNER; + entryIndex &= ~RCT12_FOOTPATH_PROPERTIES_FLAG_HAS_QUEUE_BANNER; if (hasQueueBanner) - entryIndex |= FOOTPATH_PROPERTIES_FLAG_HAS_QUEUE_BANNER; + entryIndex |= RCT12_FOOTPATH_PROPERTIES_FLAG_HAS_QUEUE_BANNER; } void RCT12PathElement::SetAddition(uint8_t newAddition) { - additions &= ~FOOTPATH_PROPERTIES_ADDITIONS_TYPE_MASK; + additions &= ~RCT12_FOOTPATH_PROPERTIES_ADDITIONS_TYPE_MASK; additions |= newAddition; } void RCT12PathElement::SetAdditionIsGhost(bool isGhost) { - additions &= ~FOOTPATH_ADDITION_FLAG_IS_GHOST; + additions &= ~RCT12_FOOTPATH_PROPERTIES_ADDITIONS_FLAG_GHOST; if (isGhost) - additions |= FOOTPATH_ADDITION_FLAG_IS_GHOST; + additions |= RCT12_FOOTPATH_PROPERTIES_ADDITIONS_FLAG_GHOST; } void RCT12TrackElement::SetTrackType(uint8_t newType) diff --git a/src/openrct2/rct12/RCT12.h b/src/openrct2/rct12/RCT12.h index 8667884633..e2f6b6282f 100644 --- a/src/openrct2/rct12/RCT12.h +++ b/src/openrct2/rct12/RCT12.h @@ -94,6 +94,24 @@ enum RCT12_TRACK_ELEMENT_DOOR_B_MASK = 0b11100000, }; +// Masks and flags for values stored in TileElement.properties.path.type +enum +{ + RCT12_FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK = (1 << 0) | (1 << 1), + RCT12_FOOTPATH_PROPERTIES_FLAG_IS_SLOPED = (1 << 2), + RCT12_FOOTPATH_PROPERTIES_FLAG_HAS_QUEUE_BANNER = (1 << 3), + RCT12_FOOTPATH_PROPERTIES_TYPE_MASK = (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7), +}; + +// Masks and flags for values stored in in RCT12TileElement.properties.path.additions +enum +{ + RCT12_FOOTPATH_PROPERTIES_ADDITIONS_TYPE_MASK = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3), + // The most significant bit in this mask will always be zero, since rides can only have 4 stations + RCT12_FOOTPATH_PROPERTIES_ADDITIONS_STATION_INDEX_MASK = (1 << 4) | (1 << 5) | (1 << 6), + RCT12_FOOTPATH_PROPERTIES_ADDITIONS_FLAG_GHOST = (1 << 7), +}; + #pragma pack(push, 1) struct RCT12xy8 diff --git a/src/openrct2/rct2/S6Exporter.cpp b/src/openrct2/rct2/S6Exporter.cpp index 8877f8cf14..4e5055b2bc 100644 --- a/src/openrct2/rct2/S6Exporter.cpp +++ b/src/openrct2/rct2/S6Exporter.cpp @@ -1450,7 +1450,7 @@ void S6Exporter::ExportTileElement(RCT12TileElement* dst, TileElement* src) auto dst2 = dst->AsPath(); auto src2 = src->AsPath(); - dst2->SetPathEntryIndex(src2->GetPathEntryIndex()); + dst2->SetPathEntryIndex(src2->GetSurfaceEntryIndex()); dst2->SetQueueBannerDirection(src2->GetQueueBannerDirection()); dst2->SetSloped(src2->IsSloped()); dst2->SetSlopeDirection(src2->GetSlopeDirection()); diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index b7dc1c06db..398ea5ac16 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -1052,7 +1052,7 @@ public: auto dst2 = dst->AsPath(); auto src2 = src->AsPath(); - dst2->SetPathEntryIndex(src2->GetEntryIndex()); + dst2->SetSurfaceEntryIndex(src2->GetEntryIndex()); dst2->SetQueueBannerDirection(src2->GetQueueBannerDirection()); dst2->SetSloped(src2->IsSloped()); dst2->SetSlopeDirection(src2->GetSlopeDirection()); diff --git a/src/openrct2/ride/RideRatings.cpp b/src/openrct2/ride/RideRatings.cpp index 3c31e85888..c6f5e455b7 100644 --- a/src/openrct2/ride/RideRatings.cpp +++ b/src/openrct2/ride/RideRatings.cpp @@ -613,7 +613,7 @@ static void ride_ratings_score_close_proximity(TileElement* inputTileElement) break; case TILE_ELEMENT_TYPE_PATH: // Bonus for normal path - if (tileElement->AsPath()->GetPathEntryIndex() != 0) + if (tileElement->AsPath()->GetSurfaceEntryIndex() != 0) { if (tileElement->clearance_height == inputTileElement->base_height) { diff --git a/src/openrct2/ride/Station.h b/src/openrct2/ride/Station.h index 6d95d84179..3ba6b08eeb 100644 --- a/src/openrct2/ride/Station.h +++ b/src/openrct2/ride/Station.h @@ -10,7 +10,11 @@ #pragma once #include "../common.h" -#include "Ride.h" +#include "../world/Location.hpp" + +struct Ride; + +using StationIndex = uint8_t; void ride_update_station(Ride* ride, int32_t stationIndex); int8_t ride_get_first_valid_station_exit(Ride* ride); diff --git a/src/openrct2/ride/TrackDesignSave.cpp b/src/openrct2/ride/TrackDesignSave.cpp index a2edeebfa5..126dc155b8 100644 --- a/src/openrct2/ride/TrackDesignSave.cpp +++ b/src/openrct2/ride/TrackDesignSave.cpp @@ -285,7 +285,7 @@ static void track_design_save_add_wall(const CoordsXY& loc, WallElement* wallEle static void track_design_save_add_footpath(const CoordsXY& loc, PathElement* pathElement) { - int32_t entryType = pathElement->GetPathEntryIndex(); + int32_t entryType = pathElement->GetSurfaceEntryIndex(); auto entry = object_entry_get_entry(OBJECT_TYPE_PATHS, entryType); uint8_t flags = 0; @@ -454,7 +454,7 @@ static void track_design_save_remove_wall(const CoordsXY& loc, WallElement* wall static void track_design_save_remove_footpath(const CoordsXY& loc, PathElement* pathElement) { - int32_t entryType = pathElement->GetPathEntryIndex(); + int32_t entryType = pathElement->GetSurfaceEntryIndex(); auto entry = object_entry_get_entry(OBJECT_TYPE_PATHS, entryType); uint8_t flags = 0; diff --git a/src/openrct2/world/Entrance.cpp b/src/openrct2/world/Entrance.cpp index 77d454d226..9c1da3815f 100644 --- a/src/openrct2/world/Entrance.cpp +++ b/src/openrct2/world/Entrance.cpp @@ -255,12 +255,12 @@ void EntranceElement::SetSequenceIndex(uint8_t newSequenceIndex) SequenceIndex |= (newSequenceIndex & 0xF); } -uint8_t EntranceElement::GetPathType() const +PathSurfaceIndex EntranceElement::GetPathType() const { - return pathType; + return PathType; } -void EntranceElement::SetPathType(uint8_t newPathType) +void EntranceElement::SetPathType(PathSurfaceIndex newPathType) { - pathType = newPathType; + PathType = newPathType; } diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 14dfbc37db..2d7f22f32a 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -1424,25 +1424,24 @@ int32_t footpath_is_connected_to_map_edge(const CoordsXYZ& footpathPos, int32_t bool PathElement::IsSloped() const { - return (entryIndex & FOOTPATH_PROPERTIES_FLAG_IS_SLOPED) != 0; + return (Flags2 & FOOTPATH_ELEMENT_FLAGS2_IS_SLOPED) != 0; } void PathElement::SetSloped(bool isSloped) { - entryIndex &= ~FOOTPATH_PROPERTIES_FLAG_IS_SLOPED; + Flags2 &= ~FOOTPATH_ELEMENT_FLAGS2_IS_SLOPED; if (isSloped) - entryIndex |= FOOTPATH_PROPERTIES_FLAG_IS_SLOPED; + Flags2 |= FOOTPATH_ELEMENT_FLAGS2_IS_SLOPED; } Direction PathElement::GetSlopeDirection() const { - return static_cast(entryIndex & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK); + return SlopeDirection; } void PathElement::SetSlopeDirection(Direction newSlope) { - entryIndex &= ~FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK; - entryIndex |= static_cast(newSlope) & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK; + SlopeDirection = newSlope; } bool PathElement::IsQueue() const @@ -1459,14 +1458,14 @@ void PathElement::SetIsQueue(bool isQueue) bool PathElement::HasQueueBanner() const { - return (entryIndex & FOOTPATH_PROPERTIES_FLAG_HAS_QUEUE_BANNER) != 0; + return (Flags2 & FOOTPATH_ELEMENT_FLAGS2_HAS_QUEUE_BANNER) != 0; } void PathElement::SetHasQueueBanner(bool hasQueueBanner) { - entryIndex &= ~FOOTPATH_PROPERTIES_FLAG_HAS_QUEUE_BANNER; + Flags2 &= ~FOOTPATH_ELEMENT_FLAGS2_HAS_QUEUE_BANNER; if (hasQueueBanner) - entryIndex |= FOOTPATH_PROPERTIES_FLAG_HAS_QUEUE_BANNER; + Flags2 |= FOOTPATH_ELEMENT_FLAGS2_HAS_QUEUE_BANNER; } bool PathElement::IsBroken() const @@ -1505,13 +1504,12 @@ void PathElement::SetIsBlockedByVehicle(bool isBlocked) uint8_t PathElement::GetStationIndex() const { - return (additions & FOOTPATH_PROPERTIES_ADDITIONS_STATION_INDEX_MASK) >> 4; + return StationIndex; } -void PathElement::SetStationIndex(uint8_t newStationIndex) +void PathElement::SetStationIndex(::StationIndex newStationIndex) { - additions &= ~FOOTPATH_PROPERTIES_ADDITIONS_STATION_INDEX_MASK; - additions |= ((newStationIndex << 4) & FOOTPATH_PROPERTIES_ADDITIONS_STATION_INDEX_MASK); + StationIndex = newStationIndex; } bool PathElement::IsWide() const @@ -1528,12 +1526,12 @@ void PathElement::SetWide(bool isWide) bool PathElement::HasAddition() const { - return (additions & FOOTPATH_PROPERTIES_ADDITIONS_TYPE_MASK) != 0; + return Additions != 0; } uint8_t PathElement::GetAddition() const { - return additions & FOOTPATH_PROPERTIES_ADDITIONS_TYPE_MASK; + return Additions; } uint8_t PathElement::GetAdditionEntryIndex() const @@ -1548,38 +1546,37 @@ rct_scenery_entry* PathElement::GetAdditionEntry() const void PathElement::SetAddition(uint8_t newAddition) { - additions &= ~FOOTPATH_PROPERTIES_ADDITIONS_TYPE_MASK; - additions |= newAddition; + Additions = newAddition; } bool PathElement::AdditionIsGhost() const { - return (additions & FOOTPATH_ADDITION_FLAG_IS_GHOST) != 0; + return (Flags2 & FOOTPATH_ELEMENT_FLAGS2_ADDITION_IS_GHOST) != 0; } void PathElement::SetAdditionIsGhost(bool isGhost) { - additions &= ~FOOTPATH_ADDITION_FLAG_IS_GHOST; + Flags2 &= ~FOOTPATH_ELEMENT_FLAGS2_ADDITION_IS_GHOST; if (isGhost) - additions |= FOOTPATH_ADDITION_FLAG_IS_GHOST; + Flags2 |= FOOTPATH_ELEMENT_FLAGS2_ADDITION_IS_GHOST; } -uint8_t PathElement::GetPathEntryIndex() const +PathSurfaceIndex PathElement::GetSurfaceEntryIndex() const { - return (entryIndex & FOOTPATH_PROPERTIES_TYPE_MASK) >> 4; + return (SurfaceIndex & RCT12_FOOTPATH_PROPERTIES_TYPE_MASK) >> 4; } -uint8_t PathElement::GetRailingEntryIndex() const +PathRailingsIndex PathElement::GetRailingEntryIndex() const { - return GetPathEntryIndex(); + return GetSurfaceEntryIndex(); } -PathSurfaceEntry* PathElement::GetPathEntry() const +PathSurfaceEntry* PathElement::GetSurfaceEntry() const { if (!IsQueue()) - return get_path_surface_entry(GetPathEntryIndex()); + return get_path_surface_entry(GetSurfaceEntryIndex()); else - return get_path_surface_entry(GetPathEntryIndex() + MAX_PATH_OBJECTS); + return get_path_surface_entry(GetSurfaceEntryIndex() + MAX_PATH_OBJECTS); } PathRailingsEntry* PathElement::GetRailingEntry() const @@ -1587,13 +1584,12 @@ PathRailingsEntry* PathElement::GetRailingEntry() const return get_path_railings_entry(GetRailingEntryIndex()); } -void PathElement::SetPathEntryIndex(uint8_t newEntryIndex) +void PathElement::SetSurfaceEntryIndex(PathSurfaceIndex newIndex) { - entryIndex &= ~FOOTPATH_PROPERTIES_TYPE_MASK; - entryIndex |= (newEntryIndex << 4); + SurfaceIndex = newIndex & ~FOOTPATH_ELEMENT_INSERT_QUEUE; } -void PathElement::SetRailingEntryIndex(uint8_t newEntryIndex) +void PathElement::SetRailingEntryIndex(PathRailingsIndex newEntryIndex) { log_verbose("Setting railing entry index to %d", newEntryIndex); } @@ -2164,7 +2160,7 @@ void footpath_remove_edges_at(const CoordsXY& footpathPos, TileElement* tileElem tileElement->AsPath()->SetEdgesAndCorners(0); } -PathSurfaceEntry* get_path_surface_entry(int32_t entryIndex) +PathSurfaceEntry* get_path_surface_entry(PathSurfaceIndex entryIndex) { PathSurfaceEntry* result = nullptr; auto& objMgr = OpenRCT2::GetContext()->GetObjectManager(); @@ -2180,7 +2176,7 @@ PathSurfaceEntry* get_path_surface_entry(int32_t entryIndex) return result; } -PathRailingsEntry* get_path_railings_entry(int32_t entryIndex) +PathRailingsEntry* get_path_railings_entry(PathRailingsIndex entryIndex) { PathRailingsEntry* result = nullptr; auto& objMgr = OpenRCT2::GetContext()->GetObjectManager(); @@ -2204,44 +2200,44 @@ void PathElement::SetRideIndex(ride_id_t newRideIndex) uint8_t PathElement::GetAdditionStatus() const { - return additionStatus; + return AdditionStatus; } void PathElement::SetAdditionStatus(uint8_t newStatus) { - additionStatus = newStatus; + AdditionStatus = newStatus; } uint8_t PathElement::GetEdges() const { - return edges & FOOTPATH_PROPERTIES_EDGES_EDGES_MASK; + return Edges & FOOTPATH_PROPERTIES_EDGES_EDGES_MASK; } void PathElement::SetEdges(uint8_t newEdges) { - edges &= ~FOOTPATH_PROPERTIES_EDGES_EDGES_MASK; - edges |= (newEdges & FOOTPATH_PROPERTIES_EDGES_EDGES_MASK); + Edges &= ~FOOTPATH_PROPERTIES_EDGES_EDGES_MASK; + Edges |= (newEdges & FOOTPATH_PROPERTIES_EDGES_EDGES_MASK); } uint8_t PathElement::GetCorners() const { - return edges >> 4; + return Edges >> 4; } void PathElement::SetCorners(uint8_t newCorners) { - edges &= ~FOOTPATH_PROPERTIES_EDGES_CORNERS_MASK; - edges |= (newCorners << 4); + Edges &= ~FOOTPATH_PROPERTIES_EDGES_CORNERS_MASK; + Edges |= (newCorners << 4); } uint8_t PathElement::GetEdgesAndCorners() const { - return edges; + return Edges; } void PathElement::SetEdgesAndCorners(uint8_t newEdgesAndCorners) { - edges = newEdgesAndCorners; + Edges = newEdgesAndCorners; } bool PathElement::IsLevelCrossing(const CoordsXY& coords) const diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index d843ad75dc..1f7178f43c 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -7,8 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ -#ifndef _WORLD_FOOTPATH_H_ -#define _WORLD_FOOTPATH_H_ +#pragma once #include "../common.h" #include "../interface/Viewport.h" @@ -28,6 +27,12 @@ constexpr auto PATH_HEIGHT = 4 * COORDS_Z_STEP; #define FOOTPATH_ELEMENT_INSERT_QUEUE 0x80 +using PathSurfaceIndex = uint16_t; +constexpr PathSurfaceIndex PATH_SURFACE_INDEX_NULL = (PathSurfaceIndex)-1; + +using PathRailingsIndex = uint8_t; +constexpr PathRailingsIndex PATH_RAILINGS_INDEX_NULL = (PathRailingsIndex)-1; + enum class RailingEntrySupportType : uint8_t { Box = 0, @@ -91,13 +96,11 @@ enum FOOTPATH_PROPERTIES_EDGES_CORNERS_MASK = (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7), }; -// Masks and flags for values stored in in TileElement.properties.path.additions enum { - FOOTPATH_PROPERTIES_ADDITIONS_TYPE_MASK = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3), - // The most significant bit in this mask will always be zero, since rides can only have 4 stations - FOOTPATH_PROPERTIES_ADDITIONS_STATION_INDEX_MASK = (1 << 4) | (1 << 5) | (1 << 6), - FOOTPATH_PROPERTIES_ADDITIONS_FLAG_GHOST = (1 << 7), + FOOTPATH_ELEMENT_FLAGS2_IS_SLOPED = 1 << 0, + FOOTPATH_ELEMENT_FLAGS2_HAS_QUEUE_BANNER = (1 << 1), + FOOTPATH_ELEMENT_FLAGS2_ADDITION_IS_GHOST = (1 << 2), }; enum @@ -120,16 +123,6 @@ enum FOOTPATH_SEARCH_TOO_COMPLEX }; -enum -{ - FOOTPATH_ADDITION_FLAG_IS_GHOST = (1 << 7), -}; - -enum -{ - FOOTPATH_CLEAR_DIRECTIONAL = (1 << 8), // Flag set when direction is used. -}; - enum { SLOPE_IS_IRREGULAR_FLAG = (1 << 3), // Flag set in `DefaultPathSlope[]` and checked in `footpath_place_real` @@ -198,10 +191,8 @@ int32_t footpath_is_connected_to_map_edge(const CoordsXYZ& footpathPos, int32_t void footpath_remove_edges_at(const CoordsXY& footpathPos, TileElement* tileElement); int32_t entrance_get_directions(const TileElement* tileElement); -PathSurfaceEntry* get_path_surface_entry(int32_t entryIndex); -PathRailingsEntry* get_path_railings_entry(int32_t entryIndex); +PathSurfaceEntry* get_path_surface_entry(PathSurfaceIndex entryIndex); +PathRailingsEntry* get_path_railings_entry(PathRailingsIndex entryIndex); void footpath_queue_chain_reset(); void footpath_queue_chain_push(ride_id_t rideIndex); - -#endif diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index a0e58a95b3..4374aee813 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -655,12 +655,12 @@ void map_update_path_wide_flags() * * rct2: 0x006A7B84 */ -int32_t map_height_from_slope(const CoordsXY& coords, int32_t slope, bool isSloped) +int32_t map_height_from_slope(const CoordsXY& coords, int32_t slopeDirection, bool isSloped) { if (!isSloped) return 0; - switch (slope & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK) + switch (slopeDirection % NumOrthogonalDirections) { case TILE_ELEMENT_DIRECTION_WEST: return (31 - (coords.x & 31)) / 2; diff --git a/src/openrct2/world/Map.h b/src/openrct2/world/Map.h index 96810bd641..1dc371dc3f 100644 --- a/src/openrct2/world/Map.h +++ b/src/openrct2/world/Map.h @@ -153,7 +153,7 @@ void map_update_tile_pointers(); TileElement* map_get_first_element_at(const CoordsXY& elementPos); TileElement* map_get_nth_element_at(const CoordsXY& coords, int32_t n); void map_set_tile_element(const TileCoordsXY& tilePos, TileElement* elements); -int32_t map_height_from_slope(const CoordsXY& coords, int32_t slope, bool isSloped); +int32_t map_height_from_slope(const CoordsXY& coords, int32_t slopeDirection, bool isSloped); BannerElement* map_get_banner_element_at(const CoordsXYZ& bannerPos, uint8_t direction); SurfaceElement* map_get_surface_element_at(const CoordsXY& coords); PathElement* map_get_path_element_at(const TileCoordsXYZ& loc); diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index 14a5724f99..27045e3094 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -11,6 +11,7 @@ #include "../common.h" #include "../ride/RideTypes.h" +#include "../ride/Station.h" #include "Banner.h" #include "Footpath.h" #include "Location.hpp" @@ -183,27 +184,31 @@ assert_struct_size(SurfaceElement, 16); struct PathElement : TileElementBase { private: - uint8_t entryIndex; // 4, 0xF0 Path type, 0x08 Ride sign, 0x04 Set when path is sloped, 0x03 Rotation - uint8_t additions; // 5, 0bGSSSAAAA: G = Ghost, S = station index, A = addition (0 means no addition) - uint8_t edges; // 6 + PathSurfaceIndex SurfaceIndex; // 4 + PathRailingsIndex RailingsIndex; // 6 + uint8_t Additions; // 7 (0 means no addition) + uint8_t Edges; // 8 + uint8_t Flags2; // 9 + uint8_t SlopeDirection; // 10 union { - uint8_t additionStatus; // 7 - uint8_t rideIndex; + uint8_t AdditionStatus; // 11, only used for litter bins + ride_id_t rideIndex; // 11 }; + ::StationIndex StationIndex; // 13 #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-private-field" - uint8_t pad_08[8]; + uint8_t pad_0E[2]; #pragma clang diagnostic pop public: - uint8_t GetPathEntryIndex() const; - PathSurfaceEntry* GetPathEntry() const; - void SetPathEntryIndex(uint8_t newIndex); + PathSurfaceIndex GetSurfaceEntryIndex() const; + PathSurfaceEntry* GetSurfaceEntry() const; + void SetSurfaceEntryIndex(PathSurfaceIndex newIndex); - uint8_t GetRailingEntryIndex() const; + PathRailingsIndex GetRailingEntryIndex() const; PathRailingsEntry* GetRailingEntry() const; - void SetRailingEntryIndex(uint8_t newIndex); + void SetRailingEntryIndex(PathRailingsIndex newIndex); uint8_t GetQueueBannerDirection() const; void SetQueueBannerDirection(uint8_t direction); @@ -217,8 +222,8 @@ public: ride_id_t GetRideIndex() const; void SetRideIndex(ride_id_t newRideIndex); - uint8_t GetStationIndex() const; - void SetStationIndex(uint8_t newStationIndex); + ::StationIndex GetStationIndex() const; + void SetStationIndex(::StationIndex newStationIndex); bool IsWide() const; void SetWide(bool isWide); @@ -474,11 +479,11 @@ private: uint8_t entranceType; // 4 uint8_t SequenceIndex; // 5. Only uses the lower nibble. uint8_t StationIndex; // 6 - uint8_t pathType; // 7 + PathSurfaceIndex PathType; // 7 ride_id_t rideIndex; // 8 #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-private-field" - uint8_t pad_0A[6]; + uint8_t pad_0B[5]; #pragma clang diagnostic pop public: @@ -494,8 +499,8 @@ public: uint8_t GetSequenceIndex() const; void SetSequenceIndex(uint8_t newSequenceIndex); - uint8_t GetPathType() const; - void SetPathType(uint8_t newPathType); + PathSurfaceIndex GetPathType() const; + void SetPathType(PathSurfaceIndex newPathType); }; assert_struct_size(EntranceElement, 16);