From a3d4db928737cc466b195a397c56954578af3002 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 14 Sep 2025 16:25:06 +0200 Subject: [PATCH 1/6] Pass entrance path type to game action Fixes a desync when placing a park entrance in multiplayer --- distribution/changelog.txt | 1 + src/openrct2-ui/windows/EditorParkEntrance.cpp | 8 ++++++-- src/openrct2/actions/ParkEntrancePlaceAction.cpp | 12 +++++++----- src/openrct2/actions/ParkEntrancePlaceAction.h | 4 +++- src/openrct2/network/NetworkBase.cpp | 2 +- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index e47a6b9a2b..f642ceeef7 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -8,6 +8,7 @@ - Fix: [#25147] The wooden support clearance heights for steep Log Flume track pieces are too low. - Fix: [#25160] The Go-Karts steep to flat track piece has incorrect wooden support clearance heights. - Fix: [#25163] Some of the Junior Roller Coaster flat to steep track wooden support clearance heights are different to RCT1. +- Fix: [#25173] Desync when placing a park entrance in multiplayer. 0.4.26 (2025-09-06) ------------------------------------------------------------------------ diff --git a/src/openrct2-ui/windows/EditorParkEntrance.cpp b/src/openrct2-ui/windows/EditorParkEntrance.cpp index e55ec3b66d..9efffac883 100644 --- a/src/openrct2-ui/windows/EditorParkEntrance.cpp +++ b/src/openrct2-ui/windows/EditorParkEntrance.cpp @@ -195,8 +195,10 @@ namespace OpenRCT2::Ui::Windows ParkEntranceRemoveGhost(); + bool isLegacyPath = (gFootpathSelection.LegacyPath != kObjectEntryIndexNull); + auto pathIndex = isLegacyPath ? gFootpathSelection.LegacyPath : gFootpathSelection.NormalSurface; auto gameAction = GameActions::ParkEntrancePlaceAction( - parkEntrancePosition, gFootpathSelectedId, _selectedEntranceType); + parkEntrancePosition, pathIndex, _selectedEntranceType, isLegacyPath); gameAction.SetFlags(GAME_COMMAND_FLAG_GHOST); auto result = GameActions::Execute(&gameAction, getGameState()); @@ -214,8 +216,10 @@ namespace OpenRCT2::Ui::Windows CoordsXYZD parkEntrancePosition = PlaceParkEntranceGetMapPosition(screenCoords); if (!parkEntrancePosition.IsNull()) { + bool isLegacyPath = (gFootpathSelection.LegacyPath != kObjectEntryIndexNull); + auto pathIndex = isLegacyPath ? gFootpathSelection.LegacyPath : gFootpathSelection.NormalSurface; auto gameAction = GameActions::ParkEntrancePlaceAction( - parkEntrancePosition, gFootpathSelectedId, _selectedEntranceType); + parkEntrancePosition, pathIndex, _selectedEntranceType, isLegacyPath); auto result = GameActions::Execute(&gameAction, getGameState()); if (result.Error == GameActions::Status::Ok) { diff --git a/src/openrct2/actions/ParkEntrancePlaceAction.cpp b/src/openrct2/actions/ParkEntrancePlaceAction.cpp index 7353caf01e..831f631bb3 100644 --- a/src/openrct2/actions/ParkEntrancePlaceAction.cpp +++ b/src/openrct2/actions/ParkEntrancePlaceAction.cpp @@ -27,7 +27,7 @@ namespace OpenRCT2::GameActions { ParkEntrancePlaceAction::ParkEntrancePlaceAction( - const CoordsXYZD& location, ObjectEntryIndex pathType, ObjectEntryIndex entranceType) + const CoordsXYZD& location, ObjectEntryIndex pathType, ObjectEntryIndex entranceType, bool pathTypeIsLegacy) : _loc(location) , _pathType(pathType) , _entranceType(entranceType) @@ -39,6 +39,7 @@ namespace OpenRCT2::GameActions visitor.Visit(_loc); visitor.Visit("footpathSurfaceObject", _pathType); visitor.Visit("entranceObject", _entranceType); + visitor.Visit("footpathTypeIsLegacy", _pathTypeIsLegacy); } uint16_t ParkEntrancePlaceAction::GetActionFlags() const @@ -53,6 +54,7 @@ namespace OpenRCT2::GameActions stream << DS_TAG(_loc); stream << DS_TAG(_pathType); stream << DS_TAG(_entranceType); + stream << DS_TAG(_pathTypeIsLegacy); } Result ParkEntrancePlaceAction::Query(GameState_t& gameState) const @@ -64,7 +66,7 @@ namespace OpenRCT2::GameActions auto res = Result(); res.Expenditure = ExpenditureType::landPurchase; - res.Position = { _loc.x, _loc.y, _loc.z }; + res.Position = _loc; auto mapSizeUnits = GetMapSizeUnits() - CoordsXY{ kCoordsXYStep, kCoordsXYStep }; if (!LocationValid(_loc) || _loc.x <= kCoordsXYStep || _loc.y <= kCoordsXYStep || _loc.x >= mapSizeUnits.x @@ -159,13 +161,13 @@ namespace OpenRCT2::GameActions entranceElement->SetSequenceIndex(index); entranceElement->SetEntranceType(ENTRANCE_TYPE_PARK_ENTRANCE); entranceElement->setEntryIndex(_entranceType); - if (gFootpathSelection.LegacyPath == kObjectEntryIndexNull) + if (!_pathTypeIsLegacy) { - entranceElement->SetSurfaceEntryIndex(gFootpathSelection.NormalSurface); + entranceElement->SetSurfaceEntryIndex(_pathType); } else { - entranceElement->SetLegacyPathEntryIndex(gFootpathSelection.LegacyPath); + entranceElement->SetLegacyPathEntryIndex(_pathType); } if (!entranceElement->IsGhost()) diff --git a/src/openrct2/actions/ParkEntrancePlaceAction.h b/src/openrct2/actions/ParkEntrancePlaceAction.h index 15b14bd881..7f642b6c2f 100644 --- a/src/openrct2/actions/ParkEntrancePlaceAction.h +++ b/src/openrct2/actions/ParkEntrancePlaceAction.h @@ -19,10 +19,12 @@ namespace OpenRCT2::GameActions CoordsXYZD _loc; ObjectEntryIndex _pathType; ObjectEntryIndex _entranceType; + bool _pathTypeIsLegacy; public: ParkEntrancePlaceAction() = default; - ParkEntrancePlaceAction(const CoordsXYZD& location, ObjectEntryIndex pathType, ObjectEntryIndex entranceType); + ParkEntrancePlaceAction( + const CoordsXYZD& location, ObjectEntryIndex pathType, ObjectEntryIndex entranceType, bool pathTypeIsLegacy); void AcceptParameters(GameActionParameterVisitor&) final; diff --git a/src/openrct2/network/NetworkBase.cpp b/src/openrct2/network/NetworkBase.cpp index 26b11a8aab..83363abfe4 100644 --- a/src/openrct2/network/NetworkBase.cpp +++ b/src/openrct2/network/NetworkBase.cpp @@ -47,7 +47,7 @@ // It is used for making sure only compatible builds get connected, even within // single OpenRCT2 version. -constexpr uint8_t kStreamVersion = 2; +constexpr uint8_t kStreamVersion = 3; const std::string kStreamID = std::string(kOpenRCT2Version) + "-" + std::to_string(kStreamVersion); From 121c2e08310bced063596fb26e120eb80bba0abe Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 14 Sep 2025 16:25:55 +0200 Subject: [PATCH 2/6] Remove unused gFootpathSelectedId --- src/openrct2/world/Footpath.cpp | 1 - src/openrct2/world/Footpath.h | 1 - 2 files changed, 2 deletions(-) diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 9d94f6ea93..2092c5f43f 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -52,7 +52,6 @@ using namespace OpenRCT2::TrackMetaData; void FootpathUpdateQueueEntranceBanner(const CoordsXY& footpathPos, TileElement* tileElement); FootpathSelection gFootpathSelection; -uint16_t gFootpathSelectedId; CoordsXYZ gFootpathConstructFromPosition; uint8_t gFootpathConstructSlope; uint8_t gFootpathGroundFlags; diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index 128a8f3e9b..813064c030 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -136,7 +136,6 @@ enum }; extern FootpathSelection gFootpathSelection; -extern uint16_t gFootpathSelectedId; extern CoordsXYZ gFootpathConstructFromPosition; extern uint8_t gFootpathConstructSlope; extern uint8_t gFootpathGroundFlags; From 4cf07f181d959eb0d2fac33d4f5da525e30ed20d Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 14 Sep 2025 16:35:27 +0200 Subject: [PATCH 3/6] Move two footpath globals into the window --- src/openrct2-ui/windows/Footpath.cpp | 62 ++++++++++++++-------------- src/openrct2/world/Footpath.cpp | 2 - src/openrct2/world/Footpath.h | 2 - 3 files changed, 32 insertions(+), 34 deletions(-) diff --git a/src/openrct2-ui/windows/Footpath.cpp b/src/openrct2-ui/windows/Footpath.cpp index 02883ec1db..1f5fcbe8aa 100644 --- a/src/openrct2-ui/windows/Footpath.cpp +++ b/src/openrct2-ui/windows/Footpath.cpp @@ -90,6 +90,8 @@ namespace OpenRCT2::Ui::Windows }; static ProvisionalFootpath _provisionalFootpath; + static CoordsXYZ _footpathConstructFromPosition; + static uint8_t _footpathConstructSlope; #pragma region Measurements @@ -463,11 +465,11 @@ namespace OpenRCT2::Ui::Windows // Get construction image uint8_t direction = (_footpathConstructDirection + GetCurrentRotation()) % 4; uint8_t slope = 0; - if (gFootpathConstructSlope == 2) + if (_footpathConstructSlope == 2) { slope = kTileSlopeNCornerUp; } - else if (gFootpathConstructSlope == 6) + else if (_footpathConstructSlope == 6) { slope = kTileSlopeECornerUp; } @@ -786,7 +788,7 @@ namespace OpenRCT2::Ui::Windows void WindowFootpathMousedownSlope(int32_t slope) { FootpathUpdateProvisional(); - gFootpathConstructSlope = slope; + _footpathConstructSlope = slope; _windowFootpathCost = kMoney64Undefined; WindowFootpathSetEnabledAndPressedWidgets(); } @@ -1151,10 +1153,10 @@ namespace OpenRCT2::Ui::Windows } ToolCancel(); - gFootpathConstructFromPosition = { mapCoords, z }; + _footpathConstructFromPosition = { mapCoords, z }; _footpathConstructDirection = direction; _provisionalFootpath.flags.clearAll(); - gFootpathConstructSlope = 0; + _footpathConstructSlope = 0; _footpathConstructionMode = PathConstructionMode::bridgeOrTunnel; _footpathConstructValidDirections = kInvalidDirection; WindowFootpathSetEnabledAndPressedWidgets(); @@ -1195,7 +1197,7 @@ namespace OpenRCT2::Ui::Windows if (result->Error == GameActions::Status::Ok) { - if (gFootpathConstructSlope == 0) + if (_footpathConstructSlope == 0) { self->_footpathConstructValidDirections = kInvalidDirection; } @@ -1209,13 +1211,13 @@ namespace OpenRCT2::Ui::Windows ViewportSetVisibility(ViewportVisibility::UndergroundViewOn); } - gFootpathConstructFromPosition = footpathLoc; + _footpathConstructFromPosition = footpathLoc; // If we have just built an upwards slope, the next path to construct is // a bit higher. Note that the z returned by footpath_get_next_path_info // already is lowered if we are building a downwards slope. - if (gFootpathConstructSlope == 2) + if (_footpathConstructSlope == 2) { - gFootpathConstructFromPosition.z += kPathHeightStep; + _footpathConstructFromPosition.z += kPathHeightStep; } } self->WindowFootpathSetEnabledAndPressedWidgets(); @@ -1259,15 +1261,15 @@ namespace OpenRCT2::Ui::Windows } } - gFootpathConstructFromPosition.z = tileElement->GetBaseZ(); - auto action = GameActions::FootpathRemoveAction(gFootpathConstructFromPosition); + _footpathConstructFromPosition.z = tileElement->GetBaseZ(); + auto action = GameActions::FootpathRemoveAction(_footpathConstructFromPosition); GameActions::Execute(&action, getGameState()); // Move selection edge = DirectionReverse(edge); - gFootpathConstructFromPosition.x -= CoordsDirectionDelta[edge].x; - gFootpathConstructFromPosition.y -= CoordsDirectionDelta[edge].y; - gFootpathConstructFromPosition.z = z; + _footpathConstructFromPosition.x -= CoordsDirectionDelta[edge].x; + _footpathConstructFromPosition.y -= CoordsDirectionDelta[edge].y; + _footpathConstructFromPosition.z = z; _footpathConstructDirection = edge; _footpathConstructValidDirections = kInvalidDirection; } @@ -1281,15 +1283,15 @@ namespace OpenRCT2::Ui::Windows TileElement* tileElement; int32_t z, zLow; - if (!MapIsLocationValid(gFootpathConstructFromPosition)) + if (!MapIsLocationValid(_footpathConstructFromPosition)) { return nullptr; } - z = std::min(255 * kCoordsZStep, gFootpathConstructFromPosition.z); + z = std::min(255 * kCoordsZStep, _footpathConstructFromPosition.z); zLow = z - kPathHeightStep; - tileElement = MapGetFirstElementAt(gFootpathConstructFromPosition); + tileElement = MapGetFirstElementAt(_footpathConstructFromPosition); do { if (tileElement == nullptr) @@ -1360,8 +1362,8 @@ namespace OpenRCT2::Ui::Windows int32_t direction = _footpathConstructDirection; gMapSelectionTiles.clear(); gMapSelectionTiles.push_back( - { gFootpathConstructFromPosition.x + CoordsDirectionDelta[direction].x, - gFootpathConstructFromPosition.y + CoordsDirectionDelta[direction].y }); + { _footpathConstructFromPosition.x + CoordsDirectionDelta[direction].x, + _footpathConstructFromPosition.y + CoordsDirectionDelta[direction].y }); MapInvalidateMapSelectionTiles(); } @@ -1377,7 +1379,7 @@ namespace OpenRCT2::Ui::Windows pressedWidgets |= (1LL << (WIDX_DIRECTION_NW + direction)); // Set pressed slope widget - int32_t slope = gFootpathConstructSlope; + int32_t slope = _footpathConstructSlope; if (slope == kTileSlopeSESideUp) { pressedWidgets |= (1uLL << WIDX_SLOPEDOWN); @@ -1423,18 +1425,18 @@ namespace OpenRCT2::Ui::Windows void FootpathGetNextPathInfo(ObjectEntryIndex* type, CoordsXYZ& footpathLoc, int32_t* slope) { auto direction = _footpathConstructDirection; - footpathLoc.x = gFootpathConstructFromPosition.x + CoordsDirectionDelta[direction].x; - footpathLoc.y = gFootpathConstructFromPosition.y + CoordsDirectionDelta[direction].y; - footpathLoc.z = gFootpathConstructFromPosition.z; + footpathLoc.x = _footpathConstructFromPosition.x + CoordsDirectionDelta[direction].x; + footpathLoc.y = _footpathConstructFromPosition.y + CoordsDirectionDelta[direction].y; + footpathLoc.z = _footpathConstructFromPosition.z; if (type != nullptr) { *type = gFootpathSelection.GetSelectedSurface(); } *slope = kTileSlopeFlat; - if (gFootpathConstructSlope != 0) + if (_footpathConstructSlope != 0) { *slope = _footpathConstructDirection | kTileSlopeSCornerUp; - if (gFootpathConstructSlope != 2) + if (_footpathConstructSlope != 2) { footpathLoc.z -= kPathHeightStep; *slope ^= kTileSlopeECornerUp; @@ -1491,7 +1493,7 @@ namespace OpenRCT2::Ui::Windows return; } - switch (gFootpathConstructSlope) + switch (_footpathConstructSlope) { case 0: OnMouseDown(WIDX_SLOPEDOWN); @@ -1513,7 +1515,7 @@ namespace OpenRCT2::Ui::Windows return; } - switch (gFootpathConstructSlope) + switch (_footpathConstructSlope) { case 6: OnMouseDown(WIDX_LEVEL); @@ -1530,7 +1532,7 @@ namespace OpenRCT2::Ui::Windows void KeyboardShortcutSlopeLevel() { if (IsWidgetDisabled(WIDX_SLOPEDOWN) || IsWidgetDisabled(WIDX_LEVEL) || IsWidgetDisabled(WIDX_SLOPEUP) - || widgets[WIDX_LEVEL].type == WidgetType::empty || gFootpathConstructSlope == 0) + || widgets[WIDX_LEVEL].type == WidgetType::empty || _footpathConstructSlope == 0) { return; } @@ -1730,7 +1732,7 @@ namespace OpenRCT2::Ui::Windows } else if ( _provisionalFootpath.slope == kTileSlopeFlat - || _provisionalFootpath.position.z < gFootpathConstructFromPosition.z) + || _provisionalFootpath.position.z < _footpathConstructFromPosition.z) { // Going either straight on, or down. VirtualFloorSetHeight(_provisionalFootpath.position.z); @@ -1772,7 +1774,7 @@ namespace OpenRCT2::Ui::Windows _provisionalFootpath.flags.unset(ProvisionalPathFlag::showArrow); gMapSelectFlags.unset(MapSelectFlag::enableArrow); - MapInvalidateTileFull(gFootpathConstructFromPosition); + MapInvalidateTileFull(_footpathConstructFromPosition); } FootpathRemoveProvisional(); } diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 2092c5f43f..e43ff777d9 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -52,8 +52,6 @@ using namespace OpenRCT2::TrackMetaData; void FootpathUpdateQueueEntranceBanner(const CoordsXY& footpathPos, TileElement* tileElement); FootpathSelection gFootpathSelection; -CoordsXYZ gFootpathConstructFromPosition; -uint8_t gFootpathConstructSlope; uint8_t gFootpathGroundFlags; static RideId* _footpathQueueChainNext; diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index 813064c030..b94b0aa2e3 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -136,8 +136,6 @@ enum }; extern FootpathSelection gFootpathSelection; -extern CoordsXYZ gFootpathConstructFromPosition; -extern uint8_t gFootpathConstructSlope; extern uint8_t gFootpathGroundFlags; // Given a direction, this will return how to increase/decrease the x and y coordinates. From 61db76f74b0541fa4c42af4b4b59977a6165a170 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 14 Sep 2025 16:52:58 +0200 Subject: [PATCH 4/6] Move FootpathGetDefaultSurface() into window --- src/openrct2-ui/windows/Footpath.cpp | 137 ++++++++++++++++++++++++++- src/openrct2-ui/windows/Map.cpp | 2 +- src/openrct2-ui/windows/Windows.h | 1 + src/openrct2/world/Footpath.cpp | 135 -------------------------- src/openrct2/world/Footpath.h | 1 - 5 files changed, 138 insertions(+), 138 deletions(-) diff --git a/src/openrct2-ui/windows/Footpath.cpp b/src/openrct2-ui/windows/Footpath.cpp index 1f5fcbe8aa..99d4382381 100644 --- a/src/openrct2-ui/windows/Footpath.cpp +++ b/src/openrct2-ui/windows/Footpath.cpp @@ -1570,7 +1570,7 @@ namespace OpenRCT2::Ui::Windows */ WindowBase* FootpathOpen() { - if (!FootpathSelectDefault()) + if (!WindowFootpathSelectDefault()) { // No path objects to select from, don't open window return nullptr; @@ -1803,4 +1803,139 @@ namespace OpenRCT2::Ui::Windows { _provisionalFootpath.flags.set(ProvisionalPathFlag::forceRecheck); } + + static ObjectEntryIndex FootpathGetDefaultSurface(bool queue) + { + bool showEditorPaths = (gLegacyScene == LegacyScene::scenarioEditor || getGameState().cheats.sandboxMode); + for (ObjectEntryIndex i = 0; i < kMaxFootpathSurfaceObjects; i++) + { + auto pathEntry = GetPathSurfaceEntry(i); + if (pathEntry != nullptr) + { + if (!showEditorPaths && (pathEntry->Flags & FOOTPATH_ENTRY_FLAG_SHOW_ONLY_IN_SCENARIO_EDITOR)) + { + continue; + } + if (queue == ((pathEntry->Flags & FOOTPATH_ENTRY_FLAG_IS_QUEUE) != 0)) + { + return i; + } + } + } + return kObjectEntryIndexNull; + } + + static bool FootpathIsSurfaceEntryOkay(ObjectEntryIndex index, bool queue) + { + auto pathEntry = GetPathSurfaceEntry(index); + if (pathEntry != nullptr) + { + bool showEditorPaths = (gLegacyScene == LegacyScene::scenarioEditor || getGameState().cheats.sandboxMode); + if (!showEditorPaths && (pathEntry->Flags & FOOTPATH_ENTRY_FLAG_SHOW_ONLY_IN_SCENARIO_EDITOR)) + { + return false; + } + if (queue == ((pathEntry->Flags & FOOTPATH_ENTRY_FLAG_IS_QUEUE) != 0)) + { + return true; + } + } + return false; + } + + static ObjectEntryIndex FootpathGetDefaultRailings() + { + for (ObjectEntryIndex i = 0; i < kMaxFootpathRailingsObjects; i++) + { + const auto* railingEntry = GetPathRailingsEntry(i); + if (railingEntry != nullptr) + { + return i; + } + } + return kObjectEntryIndexNull; + } + + static bool FootpathIsLegacyPathEntryOkay(ObjectEntryIndex index) + { + bool showEditorPaths = (gLegacyScene == LegacyScene::scenarioEditor || getGameState().cheats.sandboxMode); + auto& objManager = OpenRCT2::GetContext()->GetObjectManager(); + auto footpathObj = objManager.GetLoadedObject(index); + if (footpathObj != nullptr) + { + auto pathEntry = reinterpret_cast(footpathObj->GetLegacyData()); + return showEditorPaths || !(pathEntry->flags & FOOTPATH_ENTRY_FLAG_SHOW_ONLY_IN_SCENARIO_EDITOR); + } + return false; + } + + static ObjectEntryIndex FootpathGetDefaultLegacyPath() + { + for (ObjectEntryIndex i = 0; i < kMaxPathObjects; i++) + { + if (FootpathIsLegacyPathEntryOkay(i)) + { + return i; + } + } + return kObjectEntryIndexNull; + } + + bool WindowFootpathSelectDefault() + { + // Select default footpath + auto surfaceIndex = FootpathGetDefaultSurface(false); + if (FootpathIsSurfaceEntryOkay(gFootpathSelection.NormalSurface, false)) + { + surfaceIndex = gFootpathSelection.NormalSurface; + } + + // Select default queue + auto queueIndex = FootpathGetDefaultSurface(true); + if (FootpathIsSurfaceEntryOkay(gFootpathSelection.QueueSurface, true)) + { + queueIndex = gFootpathSelection.QueueSurface; + } + + // Select default railing + auto railingIndex = FootpathGetDefaultRailings(); + const auto* railingEntry = GetPathRailingsEntry(gFootpathSelection.Railings); + if (railingEntry != nullptr) + { + railingIndex = gFootpathSelection.Railings; + } + + // Select default legacy path + auto legacyPathIndex = FootpathGetDefaultLegacyPath(); + if (gFootpathSelection.LegacyPath != kObjectEntryIndexNull) + { + if (FootpathIsLegacyPathEntryOkay(gFootpathSelection.LegacyPath)) + { + // Keep legacy path selected + legacyPathIndex = gFootpathSelection.LegacyPath; + } + else + { + // Reset legacy path, we default to a surface (if there are any) + gFootpathSelection.LegacyPath = kObjectEntryIndexNull; + } + } + + if (surfaceIndex == kObjectEntryIndexNull) + { + if (legacyPathIndex == kObjectEntryIndexNull) + { + // No surfaces or legacy paths available + return false; + } + + // No surfaces available, so default to legacy path + gFootpathSelection.LegacyPath = legacyPathIndex; + } + + gFootpathSelection.NormalSurface = surfaceIndex; + gFootpathSelection.QueueSurface = queueIndex; + gFootpathSelection.Railings = railingIndex; + return true; + } } // namespace OpenRCT2::Ui::Windows diff --git a/src/openrct2-ui/windows/Map.cpp b/src/openrct2-ui/windows/Map.cpp index c412c9faf5..6522874910 100644 --- a/src/openrct2-ui/windows/Map.cpp +++ b/src/openrct2-ui/windows/Map.cpp @@ -252,7 +252,7 @@ namespace OpenRCT2::Ui::Windows InitMap(); gWindowSceneryRotation = 0; CentreMapOnViewPoint(); - FootpathSelectDefault(); + WindowFootpathSelectDefault(); auto& gameState = getGameState(); _mapWidthAndHeightLinked = gameState.mapSize.x == gameState.mapSize.y; diff --git a/src/openrct2-ui/windows/Windows.h b/src/openrct2-ui/windows/Windows.h index f08d5bfd55..079aab473b 100644 --- a/src/openrct2-ui/windows/Windows.h +++ b/src/openrct2-ui/windows/Windows.h @@ -110,6 +110,7 @@ namespace OpenRCT2::Ui::Windows void WindowFootpathKeyboardShortcutSlopeUp(); void WindowFootpathKeyboardShortcutBuildCurrent(); void WindowFootpathKeyboardShortcutDemolishCurrent(); + bool WindowFootpathSelectDefault(); // GameBottomToolbar extern uint8_t gToolbarDirtyFlags; diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index e43ff777d9..e1a2d430a9 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -1824,141 +1824,6 @@ void FootpathRemoveEdgesAt(const CoordsXY& footpathPos, TileElement* tileElement tileElement->AsPath()->SetEdgesAndCorners(0); } -static ObjectEntryIndex FootpathGetDefaultSurface(bool queue) -{ - bool showEditorPaths = (gLegacyScene == LegacyScene::scenarioEditor || getGameState().cheats.sandboxMode); - for (ObjectEntryIndex i = 0; i < kMaxFootpathSurfaceObjects; i++) - { - auto pathEntry = GetPathSurfaceEntry(i); - if (pathEntry != nullptr) - { - if (!showEditorPaths && (pathEntry->Flags & FOOTPATH_ENTRY_FLAG_SHOW_ONLY_IN_SCENARIO_EDITOR)) - { - continue; - } - if (queue == ((pathEntry->Flags & FOOTPATH_ENTRY_FLAG_IS_QUEUE) != 0)) - { - return i; - } - } - } - return kObjectEntryIndexNull; -} - -static bool FootpathIsSurfaceEntryOkay(ObjectEntryIndex index, bool queue) -{ - auto pathEntry = GetPathSurfaceEntry(index); - if (pathEntry != nullptr) - { - bool showEditorPaths = (gLegacyScene == LegacyScene::scenarioEditor || getGameState().cheats.sandboxMode); - if (!showEditorPaths && (pathEntry->Flags & FOOTPATH_ENTRY_FLAG_SHOW_ONLY_IN_SCENARIO_EDITOR)) - { - return false; - } - if (queue == ((pathEntry->Flags & FOOTPATH_ENTRY_FLAG_IS_QUEUE) != 0)) - { - return true; - } - } - return false; -} - -static ObjectEntryIndex FootpathGetDefaultRailings() -{ - for (ObjectEntryIndex i = 0; i < kMaxFootpathRailingsObjects; i++) - { - const auto* railingEntry = GetPathRailingsEntry(i); - if (railingEntry != nullptr) - { - return i; - } - } - return kObjectEntryIndexNull; -} - -static bool FootpathIsLegacyPathEntryOkay(ObjectEntryIndex index) -{ - bool showEditorPaths = (gLegacyScene == LegacyScene::scenarioEditor || getGameState().cheats.sandboxMode); - auto& objManager = OpenRCT2::GetContext()->GetObjectManager(); - auto footpathObj = objManager.GetLoadedObject(index); - if (footpathObj != nullptr) - { - auto pathEntry = reinterpret_cast(footpathObj->GetLegacyData()); - return showEditorPaths || !(pathEntry->flags & FOOTPATH_ENTRY_FLAG_SHOW_ONLY_IN_SCENARIO_EDITOR); - } - return false; -} - -static ObjectEntryIndex FootpathGetDefaultLegacyPath() -{ - for (ObjectEntryIndex i = 0; i < kMaxPathObjects; i++) - { - if (FootpathIsLegacyPathEntryOkay(i)) - { - return i; - } - } - return kObjectEntryIndexNull; -} - -bool FootpathSelectDefault() -{ - // Select default footpath - auto surfaceIndex = FootpathGetDefaultSurface(false); - if (FootpathIsSurfaceEntryOkay(gFootpathSelection.NormalSurface, false)) - { - surfaceIndex = gFootpathSelection.NormalSurface; - } - - // Select default queue - auto queueIndex = FootpathGetDefaultSurface(true); - if (FootpathIsSurfaceEntryOkay(gFootpathSelection.QueueSurface, true)) - { - queueIndex = gFootpathSelection.QueueSurface; - } - - // Select default railing - auto railingIndex = FootpathGetDefaultRailings(); - const auto* railingEntry = GetPathRailingsEntry(gFootpathSelection.Railings); - if (railingEntry != nullptr) - { - railingIndex = gFootpathSelection.Railings; - } - - // Select default legacy path - auto legacyPathIndex = FootpathGetDefaultLegacyPath(); - if (gFootpathSelection.LegacyPath != kObjectEntryIndexNull) - { - if (FootpathIsLegacyPathEntryOkay(gFootpathSelection.LegacyPath)) - { - // Keep legacy path selected - legacyPathIndex = gFootpathSelection.LegacyPath; - } - else - { - // Reset legacy path, we default to a surface (if there are any) - gFootpathSelection.LegacyPath = kObjectEntryIndexNull; - } - } - - if (surfaceIndex == kObjectEntryIndexNull) - { - if (legacyPathIndex == kObjectEntryIndexNull) - { - // No surfaces or legacy paths available - return false; - } - - // No surfaces available, so default to legacy path - gFootpathSelection.LegacyPath = legacyPathIndex; - } - - gFootpathSelection.NormalSurface = surfaceIndex; - gFootpathSelection.QueueSurface = queueIndex; - gFootpathSelection.Railings = railingIndex; - return true; -} - const FootpathObject* GetLegacyFootpathEntry(ObjectEntryIndex entryIndex) { auto& objMgr = OpenRCT2::GetContext()->GetObjectManager(); diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index b94b0aa2e3..c96f9b744f 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -158,7 +158,6 @@ bool FootpathIsBlockedByVehicle(const TileCoordsXYZ& position); int32_t FootpathIsConnectedToMapEdge(const CoordsXYZ& footpathPos, int32_t direction, int32_t flags); void FootpathRemoveEdgesAt(const CoordsXY& footpathPos, OpenRCT2::TileElement* tileElement); -bool FootpathSelectDefault(); const OpenRCT2::FootpathObject* GetLegacyFootpathEntry(OpenRCT2::ObjectEntryIndex entryIndex); const OpenRCT2::FootpathSurfaceObject* GetPathSurfaceEntry(OpenRCT2::ObjectEntryIndex entryIndex); const OpenRCT2::FootpathRailingsObject* GetPathRailingsEntry(OpenRCT2::ObjectEntryIndex entryIndex); From 5cc8ab4fa5127a5a9609723e6f28fb4e76186e6e Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 14 Sep 2025 17:01:16 +0200 Subject: [PATCH 5/6] Move WallInTheWay() to Wall.{cpp,h} --- src/openrct2/entity/Staff.cpp | 1 + src/openrct2/peep/GuestPathfinding.cpp | 1 + src/openrct2/world/Footpath.cpp | 34 +------------------------- src/openrct2/world/Footpath.h | 1 - src/openrct2/world/Wall.cpp | 33 +++++++++++++++++++++++++ src/openrct2/world/Wall.h | 2 ++ 6 files changed, 38 insertions(+), 34 deletions(-) diff --git a/src/openrct2/entity/Staff.cpp b/src/openrct2/entity/Staff.cpp index 0764208cd6..7415989291 100644 --- a/src/openrct2/entity/Staff.cpp +++ b/src/openrct2/entity/Staff.cpp @@ -46,6 +46,7 @@ #include "../world/Footpath.h" #include "../world/Map.h" #include "../world/Scenery.h" +#include "../world/Wall.h" #include "../world/tile_element/EntranceElement.h" #include "../world/tile_element/PathElement.h" #include "../world/tile_element/Slope.h" diff --git a/src/openrct2/peep/GuestPathfinding.cpp b/src/openrct2/peep/GuestPathfinding.cpp index 6c15746a21..e8c3e2c534 100644 --- a/src/openrct2/peep/GuestPathfinding.cpp +++ b/src/openrct2/peep/GuestPathfinding.cpp @@ -22,6 +22,7 @@ #include "../world/Entrance.h" #include "../world/Footpath.h" #include "../world/Map.h" +#include "../world/Wall.h" #include "../world/tile_element/BannerElement.h" #include "../world/tile_element/EntranceElement.h" #include "../world/tile_element/PathElement.h" diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index e1a2d430a9..34b51d2e9d 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -36,6 +36,7 @@ #include "Location.hpp" #include "Map.h" #include "MapAnimation.h" +#include "Wall.h" #include "tile_element/BannerElement.h" #include "tile_element/EntranceElement.h" #include "tile_element/PathElement.h" @@ -185,39 +186,6 @@ void FootpathInterruptPeeps(const CoordsXYZ& footpathPos) } } -/** - * Returns true if the edge of tile x, y specified by direction is occupied by a fence - * between heights z0 and z1. - * - * Note that there may still be a fence on the opposing tile. - * - * rct2: 0x006E59DC - */ -bool WallInTheWay(const CoordsXYRangedZ& fencePos, int32_t direction) -{ - TileElement* tileElement; - - tileElement = MapGetFirstElementAt(fencePos); - if (tileElement == nullptr) - return false; - do - { - if (tileElement->GetType() != TileElementType::Wall) - continue; - if (tileElement->IsGhost()) - continue; - if (fencePos.baseZ >= tileElement->GetClearanceZ()) - continue; - if (fencePos.clearanceZ <= tileElement->GetBaseZ()) - continue; - if ((tileElement->GetDirection()) != direction) - continue; - - return true; - } while (!(tileElement++)->IsLastForTile()); - return false; -} - static PathElement* FootpathConnectCornersGetNeighbour(const CoordsXYZ& footpathPos, int32_t requireEdges) { if (!MapIsLocationValid(footpathPos)) diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index c96f9b744f..9140d65399 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -148,7 +148,6 @@ void FootpathInterruptPeeps(const CoordsXYZ& footpathPos); void FootpathRemoveLitter(const CoordsXYZ& footpathPos); void FootpathConnectEdges(const CoordsXY& footpathPos, OpenRCT2::TileElement* tileElement, int32_t flags); void FootpathUpdateQueueChains(); -bool WallInTheWay(const CoordsXYRangedZ& fencePos, int32_t direction); void FootpathChainRideQueue( RideId rideIndex, StationIndex entranceIndex, const CoordsXY& footpathPos, OpenRCT2::TileElement* tileElement, int32_t direction); diff --git a/src/openrct2/world/Wall.cpp b/src/openrct2/world/Wall.cpp index a4723948fd..a37edc2405 100644 --- a/src/openrct2/world/Wall.cpp +++ b/src/openrct2/world/Wall.cpp @@ -114,3 +114,36 @@ uint8_t GetWallSlopeFromEdgeSlope(uint8_t Slope, uint8_t Edge) { return kLandSlopeToWallSlope[Slope][Edge]; } + +/** + * Returns true if the edge of tile x, y specified by direction is occupied by a fence + * between heights z0 and z1. + * + * Note that there may still be a fence on the opposing tile. + * + * rct2: 0x006E59DC + */ +bool WallInTheWay(const CoordsXYRangedZ& fencePos, int32_t direction) +{ + TileElement* tileElement; + + tileElement = MapGetFirstElementAt(fencePos); + if (tileElement == nullptr) + return false; + do + { + if (tileElement->GetType() != TileElementType::Wall) + continue; + if (tileElement->IsGhost()) + continue; + if (fencePos.baseZ >= tileElement->GetClearanceZ()) + continue; + if (fencePos.clearanceZ <= tileElement->GetBaseZ()) + continue; + if ((tileElement->GetDirection()) != direction) + continue; + + return true; + } while (!(tileElement++)->IsLastForTile()); + return false; +} diff --git a/src/openrct2/world/Wall.h b/src/openrct2/world/Wall.h index 688aa54be1..5043775331 100644 --- a/src/openrct2/world/Wall.h +++ b/src/openrct2/world/Wall.h @@ -26,3 +26,5 @@ void WallRemoveAtZ(const CoordsXYZ& wallPos); void WallRemoveIntersectingWalls(const CoordsXYRangedZ& wallPos, Direction direction); uint8_t GetWallSlopeFromEdgeSlope(uint8_t Slope, uint8_t Edge); + +bool WallInTheWay(const CoordsXYRangedZ& fencePos, int32_t direction); From 129c69927e2d8545144bbd3b9a67774f45c18b33 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 14 Sep 2025 17:06:27 +0200 Subject: [PATCH 6/6] Create FootpathGetPlacementFromScreenCoords() --- src/openrct2-ui/windows/Footpath.cpp | 49 ++++++++++++---------------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/src/openrct2-ui/windows/Footpath.cpp b/src/openrct2-ui/windows/Footpath.cpp index 99d4382381..ef48948e99 100644 --- a/src/openrct2-ui/windows/Footpath.cpp +++ b/src/openrct2-ui/windows/Footpath.cpp @@ -531,6 +531,17 @@ namespace OpenRCT2::Ui::Windows #pragma endregion private: + FootpathPlacementResult FootpathGetPlacementFromScreenCoords(const ScreenCoordsXY& screenCoords) + { + if (_footpathPlaceZ > 0) + return { _footpathPlaceZ, kTileSlopeFlat }; + + auto info = GetMapCoordinatesFromPos( + screenCoords, EnumsToFlags(ViewportInteractionItem::Terrain, ViewportInteractionItem::Footpath)); + + return FootpathGetPlacementFromInfo(info); + } + /** * * rct2: 0x006A7760 @@ -979,30 +990,19 @@ namespace OpenRCT2::Ui::Windows FootpathUpdateProvisional(); // Figure out what slope and height to use - int32_t slope = kTileSlopeFlat; - auto baseZ = _footpathPlaceZ; - if (baseZ == 0) + auto placement = FootpathGetPlacementFromScreenCoords(screenCoords); + if (!placement.isValid()) { - auto info = GetMapCoordinatesFromPos( - screenCoords, EnumsToFlags(ViewportInteractionItem::Terrain, ViewportInteractionItem::Footpath)); - - auto result = FootpathGetPlacementFromInfo(info); - if (!result.isValid()) - { - gMapSelectFlags.unset(MapSelectFlag::enable); - FootpathUpdateProvisional(); - return; - } - - baseZ = result.baseZ; - slope = result.slope; + gMapSelectFlags.unset(MapSelectFlag::enable); + FootpathUpdateProvisional(); + return; } // Set provisional path auto pathType = gFootpathSelection.GetSelectedSurface(); auto constructFlags = FootpathCreateConstructFlags(pathType); const auto footpathCost = FootpathProvisionalSet( - pathType, gFootpathSelection.Railings, { *mapPos, baseZ }, slope, constructFlags); + pathType, gFootpathSelection.Railings, { *mapPos, placement.baseZ }, placement.slope, constructFlags); if (_windowFootpathCost != footpathCost) { @@ -1070,24 +1070,15 @@ namespace OpenRCT2::Ui::Windows if (!mapPos) return; - auto slope = kTileSlopeFlat; - auto baseZ = _footpathPlaceZ; - if (baseZ == 0) - { - const auto info = GetMapCoordinatesFromPos( - screenCoords, EnumsToFlags(ViewportInteractionItem::Terrain, ViewportInteractionItem::Footpath)); - - auto result = FootpathGetPlacementFromInfo(info); - baseZ = result.baseZ; - slope = result.slope; - } + auto placement = FootpathGetPlacementFromScreenCoords(screenCoords); // Try and place path auto selectedType = gFootpathSelection.GetSelectedSurface(); PathConstructFlags constructFlags = FootpathCreateConstructFlags(selectedType); auto footpathPlaceAction = GameActions::FootpathPlaceAction( - { *mapPos, baseZ }, slope, selectedType, gFootpathSelection.Railings, kInvalidDirection, constructFlags); + { *mapPos, placement.baseZ }, placement.slope, selectedType, gFootpathSelection.Railings, kInvalidDirection, + constructFlags); footpathPlaceAction.SetCallback([this](const GameActions::GameAction* ga, const GameActions::Result* result) { if (result->Error == GameActions::Status::Ok) {