From 95fa0e34e02c090755d991c338949077cee6fcea Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Mon, 19 Jul 2021 14:57:32 +0200 Subject: [PATCH 1/4] Integrate loc_68BAE6 --- src/openrct2/world/Map.cpp | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 618ec14d36..7132d49164 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -1361,7 +1361,19 @@ std::unique_ptr MapCanConstructWithClearAt( res->GroundFlags |= ELEMENT_IS_UNDERWATER; if (water_height < pos.clearanceZ) { - goto loc_68BAE6; + if (clearFunc != nullptr) + { + if (!clearFunc(&tileElement, pos, flags, &res->Cost)) + { + goto loc_68B9B7; + } + } + if (tileElement != nullptr) + { + res->Error = GameActions::Status::NoClearance; + res->ErrorMessage = STR_CANNOT_BUILD_PARTLY_ABOVE_AND_PARTLY_BELOW_WATER; + } + return res; } } loc_68B9B7: @@ -1469,21 +1481,6 @@ std::unique_ptr MapCanConstructWithClearAt( res->Error = GameActions::Status::NoClearance; } return res; - - loc_68BAE6: - if (clearFunc != nullptr) - { - if (!clearFunc(&tileElement, pos, flags, &res->Cost)) - { - goto loc_68B9B7; - } - } - if (tileElement != nullptr) - { - res->Error = GameActions::Status::NoClearance; - res->ErrorMessage = STR_CANNOT_BUILD_PARTLY_ABOVE_AND_PARTLY_BELOW_WATER; - } - return res; } } } while (!(tileElement++)->IsLastForTile()); From 41e564d16c73764fb8a567ed3765207e5f79255c Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Mon, 19 Jul 2021 15:01:00 +0200 Subject: [PATCH 2/4] Integrate loc_68B9B7 --- src/openrct2/world/Map.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 7132d49164..9d15d4c4fc 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -1361,22 +1361,26 @@ std::unique_ptr MapCanConstructWithClearAt( res->GroundFlags |= ELEMENT_IS_UNDERWATER; if (water_height < pos.clearanceZ) { + bool returnError = true; if (clearFunc != nullptr) { if (!clearFunc(&tileElement, pos, flags, &res->Cost)) { - goto loc_68B9B7; + returnError = false; } } - if (tileElement != nullptr) + if (returnError) { - res->Error = GameActions::Status::NoClearance; - res->ErrorMessage = STR_CANNOT_BUILD_PARTLY_ABOVE_AND_PARTLY_BELOW_WATER; + if (tileElement != nullptr) + { + res->Error = GameActions::Status::NoClearance; + res->ErrorMessage = STR_CANNOT_BUILD_PARTLY_ABOVE_AND_PARTLY_BELOW_WATER; + } + return res; } - return res; } } - loc_68B9B7: + if (gParkFlags & PARK_FLAGS_FORBID_HIGH_CONSTRUCTION && !isTree) { auto heightFromGround = pos.clearanceZ - tileElement->GetBaseZ(); From f54b008ac3d11ba0ff4fd27a1db2638d9ecf8231 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Mon, 19 Jul 2021 15:13:19 +0200 Subject: [PATCH 3/4] Spin off MapLoc68BABCShouldContinue() --- src/openrct2/world/Map.cpp | 57 +++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 9d15d4c4fc..28c6075810 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -1302,6 +1302,39 @@ void map_obstruction_set_error_text(TileElement* tileElement, GameActions::Resul } } +static bool MapLoc68BABCShouldContinue( + TileElement* tileElement, const CoordsXYRangedZ& pos, CLEAR_FUNC clearFunc, uint8_t flags, money32& price, + uint8_t crossingMode, bool canBuildCrossing) +{ + if (clearFunc != nullptr) + { + if (!clearFunc(&tileElement, pos, flags, &price)) + { + return true; + } + } + + // Crossing mode 1: building track over path + if (crossingMode == 1 && canBuildCrossing && tileElement->GetType() == TILE_ELEMENT_TYPE_PATH + && tileElement->GetBaseZ() == pos.baseZ && !tileElement->AsPath()->IsQueue() && !tileElement->AsPath()->IsSloped()) + { + return true; + } + // Crossing mode 2: building path over track + else if ( + crossingMode == 2 && canBuildCrossing && tileElement->GetType() == TILE_ELEMENT_TYPE_TRACK + && tileElement->GetBaseZ() == pos.baseZ && tileElement->AsTrack()->GetTrackType() == TrackElemType::Flat) + { + auto ride = get_ride(tileElement->AsTrack()->GetRideIndex()); + if (ride != nullptr && ride->GetRideTypeDescriptor().HasFlag(RIDE_TYPE_FLAG_SUPPORTS_LEVEL_CROSSINGS)) + { + return true; + } + } + + return false; +} + /** * * rct2: 0x0068B932 @@ -1452,32 +1485,10 @@ std::unique_ptr MapCanConstructWithClearAt( } } loc_68BABC: - if (clearFunc != nullptr) - { - if (!clearFunc(&tileElement, pos, flags, &res->Cost)) - { - continue; - } - } - - // Crossing mode 1: building track over path - if (crossingMode == 1 && canBuildCrossing && tileElement->GetType() == TILE_ELEMENT_TYPE_PATH - && tileElement->GetBaseZ() == pos.baseZ && !tileElement->AsPath()->IsQueue() - && !tileElement->AsPath()->IsSloped()) + if (MapLoc68BABCShouldContinue(tileElement, pos, clearFunc, flags, res->Cost, crossingMode, canBuildCrossing)) { continue; } - // Crossing mode 2: building path over track - else if ( - crossingMode == 2 && canBuildCrossing && tileElement->GetType() == TILE_ELEMENT_TYPE_TRACK - && tileElement->GetBaseZ() == pos.baseZ && tileElement->AsTrack()->GetTrackType() == TrackElemType::Flat) - { - auto ride = get_ride(tileElement->AsTrack()->GetRideIndex()); - if (ride != nullptr && ride->GetRideTypeDescriptor().HasFlag(RIDE_TYPE_FLAG_SUPPORTS_LEVEL_CROSSINGS)) - { - continue; - } - } if (tileElement != nullptr) { From af0d4a0b632aa4754cef8040ed8ff1c88b457f62 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Mon, 19 Jul 2021 15:14:31 +0200 Subject: [PATCH 4/4] Integrate loc_68BABC --- src/openrct2/world/Map.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 28c6075810..875484769e 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -1383,7 +1383,18 @@ std::unique_ptr MapCanConstructWithClearAt( { if (tileElement->GetOccupiedQuadrants() & (quarterTile.GetBaseQuarterOccupied())) { - goto loc_68BABC; + if (MapLoc68BABCShouldContinue( + tileElement, pos, clearFunc, flags, res->Cost, crossingMode, canBuildCrossing)) + { + continue; + } + + if (tileElement != nullptr) + { + map_obstruction_set_error_text(tileElement, *res); + res->Error = GameActions::Status::NoClearance; + } + return res; } } continue; @@ -1484,7 +1495,7 @@ std::unique_ptr MapCanConstructWithClearAt( continue; } } - loc_68BABC: + if (MapLoc68BABCShouldContinue(tileElement, pos, clearFunc, flags, res->Cost, crossingMode, canBuildCrossing)) { continue;