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);