From 3572c3f466fbfa382d13dad4d11bcb90a3c21eed Mon Sep 17 00:00:00 2001 From: Duncan Date: Tue, 14 Dec 2021 12:37:35 +0000 Subject: [PATCH] Fix #16201: Rides don't get properly deleted when you remove them (#16236) * Fix #16201. Remove all tracks on a tile when demolishing * Bump network version --- src/openrct2/actions/RideDemolishAction.cpp | 79 ++++++++++++--------- src/openrct2/network/NetworkBase.cpp | 2 +- 2 files changed, 45 insertions(+), 36 deletions(-) diff --git a/src/openrct2/actions/RideDemolishAction.cpp b/src/openrct2/actions/RideDemolishAction.cpp index 5e6a5ee9f0..b123814d14 100644 --- a/src/openrct2/actions/RideDemolishAction.cpp +++ b/src/openrct2/actions/RideDemolishAction.cpp @@ -200,48 +200,57 @@ money32 RideDemolishAction::DemolishTracks() const for (tilePos.y = 0; tilePos.y < gMapSize; ++tilePos.y) { const auto tileCoords = tilePos.ToCoordsXY(); - for (auto* trackElement : TileElementsView(tileCoords)) + // Keep retrying a tile coordinate until there are no more items to remove + bool itemRemoved = false; + do { - if (trackElement->GetRideIndex() != _rideIndex) - continue; - - const auto location = CoordsXYZD(tileCoords, trackElement->GetBaseZ(), trackElement->GetDirection()); - const auto type = trackElement->GetTrackType(); - - if (type != TrackElemType::Maze) + itemRemoved = false; + for (auto* trackElement : TileElementsView(tileCoords)) { - auto trackRemoveAction = TrackRemoveAction(type, trackElement->GetSequenceIndex(), location); - trackRemoveAction.SetFlags(GAME_COMMAND_FLAG_NO_SPEND); + if (trackElement->GetRideIndex() != _rideIndex) + continue; - auto removRes = GameActions::ExecuteNested(&trackRemoveAction); + const auto location = CoordsXYZD(tileCoords, trackElement->GetBaseZ(), trackElement->GetDirection()); + const auto type = trackElement->GetTrackType(); - if (removRes.Error != GameActions::Status::Ok) + if (type != TrackElemType::Maze) { - tile_element_remove(trackElement->as()); - } - else - { - refundPrice += removRes.Cost; - } - continue; - } + auto trackRemoveAction = TrackRemoveAction(type, trackElement->GetSequenceIndex(), location); + trackRemoveAction.SetFlags(GAME_COMMAND_FLAG_NO_SPEND); - static constexpr const CoordsXY DirOffsets[] = { - { 0, 0 }, - { 0, 16 }, - { 16, 16 }, - { 16, 0 }, - }; - for (Direction dir : ALL_DIRECTIONS) - { - const CoordsXYZ off = { DirOffsets[dir], 0 }; - money32 removePrice = MazeRemoveTrack({ location + off, dir }); - if (removePrice != MONEY32_UNDEFINED) - refundPrice += removePrice; - else - break; + auto removRes = GameActions::ExecuteNested(&trackRemoveAction); + itemRemoved = true; + if (removRes.Error != GameActions::Status::Ok) + { + tile_element_remove(trackElement->as()); + } + else + { + refundPrice += removRes.Cost; + } + continue; + } + + static constexpr const CoordsXY DirOffsets[] = { + { 0, 0 }, + { 0, 16 }, + { 16, 16 }, + { 16, 0 }, + }; + for (Direction dir : ALL_DIRECTIONS) + { + const CoordsXYZ off = { DirOffsets[dir], 0 }; + money32 removePrice = MazeRemoveTrack({ location + off, dir }); + if (removePrice != MONEY32_UNDEFINED) + { + refundPrice += removePrice; + itemRemoved = true; + } + else + break; + } } - } + } while (itemRemoved); } } diff --git a/src/openrct2/network/NetworkBase.cpp b/src/openrct2/network/NetworkBase.cpp index d2e8fc3181..e7351fa5b6 100644 --- a/src/openrct2/network/NetworkBase.cpp +++ b/src/openrct2/network/NetworkBase.cpp @@ -40,7 +40,7 @@ // This string specifies which version of network stream current build uses. // It is used for making sure only compatible builds get connected, even within // single OpenRCT2 version. -#define NETWORK_STREAM_VERSION "7" +#define NETWORK_STREAM_VERSION "8" #define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION static Peep* _pickup_peep = nullptr;