diff --git a/data/scenario_patches/2ca68df.parkpatch b/data/scenario_patches/2ca68df.parkpatch index 95ac8f1290..a20f090504 100644 --- a/data/scenario_patches/2ca68df.parkpatch +++ b/data/scenario_patches/2ca68df.parkpatch @@ -35,5 +35,20 @@ [ 47, 54 ], [ 47, 55 ], [ 47, 56 ], [ 47, 57 ] ] } + ], + "elements_to_delete": [ + { + "element_index": 1, + "coordinates": [ + [ 39, 51 ], + [ 40, 54 ], + [ 41, 52 ], [ 41, 53 ], + [ 42, 54 ], + [ 43, 55 ], + [ 44, 51 ], [ 44, 54 ], [ 44, 54 ], + [ 45, 55 ], [ 45, 56 ], + [ 46, 56 ], [ 46, 57 ] + ] + } ] } diff --git a/data/scenario_patches/47e5512.parkpatch b/data/scenario_patches/47e5512.parkpatch index 4c67385af3..bde28215cf 100644 --- a/data/scenario_patches/47e5512.parkpatch +++ b/data/scenario_patches/47e5512.parkpatch @@ -15,5 +15,14 @@ [ 86, 24 ], [ 86, 25 ], [ 87, 23 ], [ 87, 24 ], [ 87, 25 ], [ 88, 22 ], [ 88, 23 ], [ 88, 24 ], [ 89, 22 ], [ 89, 23 ] ] } + ], + "elements_to_delete": [ + { + "element_index": 1, + "coordinates": [ + [ 86, 25 ], + [ 87, 23 ], [ 87, 25 ] + ] + } ] } diff --git a/data/scenario_patches/aead175.parkpatch b/data/scenario_patches/aead175.parkpatch index 9b2445a306..ac26f2a643 100644 --- a/data/scenario_patches/aead175.parkpatch +++ b/data/scenario_patches/aead175.parkpatch @@ -35,5 +35,20 @@ [ 47, 54 ], [ 47, 55 ], [ 47, 56 ], [ 47, 57 ] ] } + ], + "elements_to_delete": [ + { + "element_index": 1, + "coordinates": [ + [ 39, 51 ], + [ 40, 54 ], + [ 41, 52 ], [ 41, 53 ], + [ 42, 54 ], + [ 43, 55 ], + [ 44, 51 ], [ 44, 54 ], [ 44, 54 ], + [ 45, 55 ], [ 45, 56 ], + [ 46, 56 ], [ 46, 57 ] + ] + } ] } diff --git a/data/scenario_patches/bfbd61f.parkpatch b/data/scenario_patches/bfbd61f.parkpatch index 0894d9bbe6..a585c79ff0 100644 --- a/data/scenario_patches/bfbd61f.parkpatch +++ b/data/scenario_patches/bfbd61f.parkpatch @@ -8,5 +8,14 @@ [ 81, 8 ], [ 82, 7 ], [ 82, 8 ], [ 82, 9 ], [ 83, 8 ], [ 83, 9 ] ] } + ], + "elements_to_delete": [ + { + "element_index": 1, + "coordinates": [ + [ 82, 7 ], [ 82, 8 ], + [ 83, 9 ] + ] + } ] } diff --git a/data/scenario_patches/ce24961.parkpatch b/data/scenario_patches/ce24961.parkpatch index 7a1ce0c8b4..ea659e9c7c 100644 --- a/data/scenario_patches/ce24961.parkpatch +++ b/data/scenario_patches/ce24961.parkpatch @@ -8,5 +8,14 @@ [ 81, 8 ], [ 82, 7 ], [ 82, 8 ], [ 82, 9 ], [ 83, 8 ], [ 83, 9 ] ] } + ], + "elements_to_delete": [ + { + "element_index": 1, + "coordinates": [ + [ 82, 7 ], [ 82, 8 ], + [ 83, 9 ] + ] + } ] } diff --git a/data/scenario_patches/fd4c6ee.parkpatch b/data/scenario_patches/fd4c6ee.parkpatch index cb971f7fb2..e9ed9ecbe3 100644 --- a/data/scenario_patches/fd4c6ee.parkpatch +++ b/data/scenario_patches/fd4c6ee.parkpatch @@ -20,5 +20,14 @@ [ 86, 24 ], [ 86, 25 ], [ 87, 23 ], [ 87, 24 ], [ 87, 25 ], [ 88, 22 ], [ 88, 23 ], [ 88, 24 ], [ 89, 22 ], [ 89, 23 ] ] } + ], + "elements_to_delete": [ + { + "element_index": 1, + "coordinates": [ + [ 86, 25 ], + [ 87, 23 ], [ 87, 25 ] + ] + } ] } diff --git a/distribution/changelog.txt b/distribution/changelog.txt index e6c53f1a6f..8101ec067f 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -9,6 +9,7 @@ - Fix: [#21959] “Save this before...?” message does not appear when selecting “New Game”. - Fix: [#22231] Invalid object version can cause a crash. - Fix: [#22653] Add several .parkpatch files for missing water tiles in RCT1 and RCT2 scenarios. +- Fix: [#22654] Improve several .parkpatch files to remove misplaced scenario elements in RCT1 and RCT2 scenarios. - Fix: [#22655] Fix surface style of Botany Breakers around missing water tiles. - Fix: [#22734] Support clearance above steep Side-Friction track is too low. diff --git a/src/openrct2/rct12/ScenarioPatcher.cpp b/src/openrct2/rct12/ScenarioPatcher.cpp index 2099249a6f..fd0189d231 100644 --- a/src/openrct2/rct12/ScenarioPatcher.cpp +++ b/src/openrct2/rct12/ScenarioPatcher.cpp @@ -62,6 +62,10 @@ static const std::string _typeKey = "type"; static const std::string _surfacesKey = "surfaces"; static const std::string _destinationSurface = "to_surface"; +// Elements to be removed keys +static const std::string _elementsToDelete = "elements_to_delete"; +static const std::string _element_index = "element_index"; + // Ride fix keys static const std::string _ridesKey = "rides"; static const std::string _rideIdKey = "id"; @@ -364,6 +368,56 @@ static void ApplySurfaceFixes(const json_t& scenarioPatch) } } +static void RemoveTileElements(const json_t& scenarioPatch) +{ + if (!scenarioPatch.contains(_elementsToDelete)) + { + return; + } + + if (!scenarioPatch[_elementsToDelete].is_array()) + { + OpenRCT2::Guard::Assert(0, "Elements to delete should be an array"); + return; + } + + auto elementsToDelete = OpenRCT2::Json::AsArray(scenarioPatch[_elementsToDelete]); + if (elementsToDelete.empty()) + { + OpenRCT2::Guard::Assert(0, "Elements to delete should not be empty"); + return; + } + + for (size_t i = 0; i < elementsToDelete.size(); ++i) + { + if (!elementsToDelete[i].contains(_element_index)) + { + OpenRCT2::Guard::Assert(0, "Elements to delete sub-array should set an element_index"); + return; + } + auto elementIndex = elementsToDelete[i][_element_index]; + auto coordinatesVector = getCoordinates(elementsToDelete[i]); + if (_dryRun) + { + return; + } + + for (const auto& tile : coordinatesVector) + { + auto tileElement = MapGetNthElementAt(tile.ToCoordsXY(), elementIndex); + if (tileElement == nullptr) + { + OpenRCT2::Guard::Assert(0, "Invalid Nth element at tile"); + return; + } + else + { + ClearElementAt(tile.ToCoordsXY(), &tileElement); + } + } + } +} + static void SwapRideEntranceAndExit(RideId rideId) { auto ride = GetRide(rideId); @@ -522,6 +576,7 @@ void OpenRCT2::RCT12::ApplyScenarioPatch(u8string_view scenarioPatchFile, u8stri ApplyWaterFixes(scenarioPatch); ApplyTileFixes(scenarioPatch); ApplySurfaceFixes(scenarioPatch); + RemoveTileElements(scenarioPatch); ApplyRideFixes(scenarioPatch); } diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 73e645dcbd..753e6633b5 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -1414,7 +1414,7 @@ void MapExtendBoundarySurfaceX() * Clears the provided element properly from a certain tile, and updates * the pointer (when needed) passed to this function to point to the next element. */ -static void ClearElementAt(const CoordsXY& loc, TileElement** elementPtr) +void ClearElementAt(const CoordsXY& loc, TileElement** elementPtr) { TileElement* element = *elementPtr; switch (element->GetType()) diff --git a/src/openrct2/world/Map.h b/src/openrct2/world/Map.h index c0ce1211b9..d05ac925d9 100644 --- a/src/openrct2/world/Map.h +++ b/src/openrct2/world/Map.h @@ -217,6 +217,7 @@ int32_t MapGetCornerHeight(int32_t z, int32_t slope, int32_t direction); int32_t TileElementGetCornerHeight(const SurfaceElement* surfaceElement, int32_t direction); void MapClearAllElements(); +void ClearElementAt(const CoordsXY& loc, TileElement** elementPtr); LargeSceneryElement* MapGetLargeScenerySegment(const CoordsXYZD& sceneryPos, int32_t sequence); std::optional MapLargeSceneryGetOrigin(