From db53fd3f7f1aa07549db5f509973fc57a2c4a92f Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Fri, 14 Aug 2026 21:55:52 +0200 Subject: [PATCH] Introduce SurfaceElement::hasOwnership() --- src/openrct2-ui/windows/Map.cpp | 4 ++-- src/openrct2-ui/windows/TileInspector.cpp | 8 ++++---- src/openrct2/actions/cheats/CheatSetAction.cpp | 4 ++-- src/openrct2/actions/park/LandBuyRightsAction.cpp | 6 +++--- src/openrct2/paint/tile_element/Paint.Surface.cpp | 10 +++++----- src/openrct2/park/ParkPreview.cpp | 2 +- .../scripting/bindings/world/ScTileElement.cpp | 2 +- src/openrct2/world/Map.cpp | 10 +++++----- src/openrct2/world/Park.cpp | 2 +- src/openrct2/world/tile_element/SurfaceElement.cpp | 5 +++++ src/openrct2/world/tile_element/SurfaceElement.h | 1 + 11 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/openrct2-ui/windows/Map.cpp b/src/openrct2-ui/windows/Map.cpp index 716673d88a..b9ae5c451e 100644 --- a/src/openrct2-ui/windows/Map.cpp +++ b/src/openrct2-ui/windows/Map.cpp @@ -858,7 +858,7 @@ namespace OpenRCT2::Ui::Windows if (surfaceElement->getWaterHeight() > 0) colour = kWaterColour; - if (!(surfaceElement->getOwnership().has(OwnershipFlag::owned))) + if (!(surfaceElement->hasOwnership(OwnershipFlag::owned))) colour = MapColourUnowned(colour); const int32_t maxSupportedTileElementType = static_cast(std::size(kElementTypeOverwriteColour)); @@ -914,7 +914,7 @@ namespace OpenRCT2::Ui::Windows if (tileElement->asSurface()->getWaterHeight() > 0) // Why is this a different water colour as above (195)? colourB = ColourPair(PaletteIndex::pi194); - if (!(tileElement->asSurface()->getOwnership().has(OwnershipFlag::owned))) + if (!(tileElement->asSurface()->hasOwnership(OwnershipFlag::owned))) colourB = MapColourUnowned(colourB); break; case TileElementType::path: diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index 1326358eeb..38da77c0ae 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -1156,13 +1156,13 @@ namespace OpenRCT2::Ui::Windows // Land ownership StringId landOwnership; - if (surfaceEl.getOwnership().has(OwnershipFlag::owned)) + if (surfaceEl.hasOwnership(OwnershipFlag::owned)) landOwnership = STR_LAND_OWNED; - else if (surfaceEl.getOwnership().has(OwnershipFlag::forSale)) + else if (surfaceEl.hasOwnership(OwnershipFlag::forSale)) landOwnership = STR_LAND_SALE; - else if (surfaceEl.getOwnership().has(OwnershipFlag::constructionRightsOwned)) + else if (surfaceEl.hasOwnership(OwnershipFlag::constructionRightsOwned)) landOwnership = STR_CONSTRUCTION_RIGHTS_OWNED; - else if (surfaceEl.getOwnership().has(OwnershipFlag::constructionRightsAvailable)) + else if (surfaceEl.hasOwnership(OwnershipFlag::constructionRightsAvailable)) landOwnership = STR_CONSTRUCTION_RIGHTS_SALE; else landOwnership = STR_TILE_INSPECTOR_LAND_NOT_OWNED_AND_NOT_AVAILABLE; diff --git a/src/openrct2/actions/cheats/CheatSetAction.cpp b/src/openrct2/actions/cheats/CheatSetAction.cpp index e9a4d651e0..c2b772f509 100644 --- a/src/openrct2/actions/cheats/CheatSetAction.cpp +++ b/src/openrct2/actions/cheats/CheatSetAction.cpp @@ -448,7 +448,7 @@ namespace OpenRCT2::GameActions if (surfaceElement == nullptr) continue; - if (surfaceElement != nullptr && (surfaceElement->getOwnership().has(OwnershipFlag::owned)) + if (surfaceElement != nullptr && (surfaceElement->hasOwnership(OwnershipFlag::owned)) && surfaceElement->getWaterHeight() == 0 && surfaceElement->canGrassGrow()) { surfaceElement->setGrassLength(length); @@ -791,7 +791,7 @@ namespace OpenRCT2::GameActions continue; // Ignore already owned tiles. - if (surfaceElement->getOwnership().has(OwnershipFlag::owned)) + if (surfaceElement->hasOwnership(OwnershipFlag::owned)) continue; int32_t baseZ = surfaceElement->getBaseZ(); diff --git a/src/openrct2/actions/park/LandBuyRightsAction.cpp b/src/openrct2/actions/park/LandBuyRightsAction.cpp index 0159527b5a..324ccfcdca 100644 --- a/src/openrct2/actions/park/LandBuyRightsAction.cpp +++ b/src/openrct2/actions/park/LandBuyRightsAction.cpp @@ -122,12 +122,12 @@ namespace OpenRCT2::GameActions switch (_setting) { case LandBuyRightSetting::buyLand: // 0 - if (surfaceElement->getOwnership().has(OwnershipFlag::owned)) + if (surfaceElement->hasOwnership(OwnershipFlag::owned)) { // If the land is already owned return res; } - if (gLegacyScene == LegacyScene::scenarioEditor || !surfaceElement->getOwnership().has(OwnershipFlag::forSale)) + if (gLegacyScene == LegacyScene::scenarioEditor || !surfaceElement->hasOwnership(OwnershipFlag::forSale)) { return Result(Status::notOwned, kErrorTitles[EnumValue(_setting)], STR_LAND_NOT_FOR_SALE); } @@ -146,7 +146,7 @@ namespace OpenRCT2::GameActions } if (gLegacyScene == LegacyScene::scenarioEditor - || !surfaceElement->getOwnership().has(OwnershipFlag::constructionRightsAvailable)) + || !surfaceElement->hasOwnership(OwnershipFlag::constructionRightsAvailable)) { return Result(Status::notOwned, kErrorTitles[EnumValue(_setting)], STR_CONSTRUCTION_RIGHTS_NOT_FOR_SALE); } diff --git a/src/openrct2/paint/tile_element/Paint.Surface.cpp b/src/openrct2/paint/tile_element/Paint.Surface.cpp index ec28ddf8e0..5c32587859 100644 --- a/src/openrct2/paint/tile_element/Paint.Surface.cpp +++ b/src/openrct2/paint/tile_element/Paint.Surface.cpp @@ -859,7 +859,7 @@ static void PaintSurfaceLandOwnership( auto [aboveWaterHeight, aboveWaterSurfaceShape] = SurfaceGetHeightAboveWater(tileElement, height, surfaceShape); // Loc660E9A: - if (tileElement.getOwnership().has(OwnershipFlag::owned)) + if (tileElement.hasOwnership(OwnershipFlag::owned)) { assert(static_cast(surfaceShape) < std::size(Byte97B444)); assert(static_cast(aboveWaterSurfaceShape) < std::size(Byte97B444)); @@ -877,7 +877,7 @@ static void PaintSurfaceLandOwnership( session.LastPS = backup; } } - else if (tileElement.getOwnership().has(OwnershipFlag::forSale)) + else if (tileElement.hasOwnership(OwnershipFlag::forSale)) { const auto pos = CoordsXYZ(session.MapPosition.x + 16, session.MapPosition.y + 16, aboveWaterHeight); const auto height2 = TileElementHeight(pos, aboveWaterSurfaceShape) + ForSaleSignZOffset; @@ -893,7 +893,7 @@ static void PaintSurfaceConstructionRights( { auto [aboveWaterHeight, aboveWaterSurfaceShape] = SurfaceGetHeightAboveWater(tileElement, height, surfaceShape); - if (tileElement.getOwnership().has(OwnershipFlag::constructionRightsOwned)) + if (tileElement.hasOwnership(OwnershipFlag::constructionRightsOwned)) { assert(static_cast(surfaceShape) < std::size(Byte97B444)); assert(static_cast(aboveWaterSurfaceShape) < std::size(Byte97B444)); @@ -911,7 +911,7 @@ static void PaintSurfaceConstructionRights( session.LastPS = backup; } } - else if (tileElement.getOwnership().has(OwnershipFlag::constructionRightsAvailable)) + else if (tileElement.hasOwnership(OwnershipFlag::constructionRightsAvailable)) { const auto pos = CoordsXYZ(session.MapPosition.x + 16, session.MapPosition.y + 16, aboveWaterHeight); const auto height2 = TileElementHeight(pos, aboveWaterSurfaceShape) + ForSaleSignZOffset; @@ -1080,7 +1080,7 @@ void PaintSurface(PaintSession& session, uint8_t direction, uint16_t height, con PaintSurfaceLandOwnership(session, tileElement, height, surfaceShape); } - if (session.ViewFlags & VIEWPORT_FLAG_CONSTRUCTION_RIGHTS && !(tileElement.getOwnership().has(OwnershipFlag::owned))) + if (session.ViewFlags & VIEWPORT_FLAG_CONSTRUCTION_RIGHTS && !(tileElement.hasOwnership(OwnershipFlag::owned))) { PaintSurfaceConstructionRights(session, tileElement, height, surfaceShape); } diff --git a/src/openrct2/park/ParkPreview.cpp b/src/openrct2/park/ParkPreview.cpp index bd0964b5ab..163646b575 100644 --- a/src/openrct2/park/ParkPreview.cpp +++ b/src/openrct2/park/ParkPreview.cpp @@ -95,7 +95,7 @@ namespace OpenRCT2 } } - isOutsidePark |= !(surfaceElement->getOwnership().has(OwnershipFlag::owned)); + isOutsidePark |= !(surfaceElement->hasOwnership(OwnershipFlag::owned)); break; } diff --git a/src/openrct2/scripting/bindings/world/ScTileElement.cpp b/src/openrct2/scripting/bindings/world/ScTileElement.cpp index b2414e6857..1a838cd2b1 100644 --- a/src/openrct2/scripting/bindings/world/ScTileElement.cpp +++ b/src/openrct2/scripting/bindings/world/ScTileElement.cpp @@ -362,7 +362,7 @@ namespace OpenRCT2::Scripting auto* el = data->element->asSurface(); if (el != nullptr) { - return JS_NewBool(ctx, el->getOwnership().has(OwnershipFlag::owned)); + return JS_NewBool(ctx, el->hasOwnership(OwnershipFlag::owned)); } else { diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index e1427e4a96..8bd4dd6ae1 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -820,10 +820,10 @@ namespace OpenRCT2 auto* surfaceElement = MapGetSurfaceElementAt(loc); if (surfaceElement != nullptr) { - if (surfaceElement->getOwnership().has(OwnershipFlag::owned)) + if (surfaceElement->hasOwnership(OwnershipFlag::owned)) return true; - if (surfaceElement->getOwnership().has(OwnershipFlag::constructionRightsOwned)) + if (surfaceElement->hasOwnership(OwnershipFlag::constructionRightsOwned)) { if (loc.z < surfaceElement->getBaseZ() || loc.z >= surfaceElement->getBaseZ() + kConstructionRightsClearanceBig) @@ -845,7 +845,7 @@ namespace OpenRCT2 auto surfaceElement = MapGetSurfaceElementAt(coords); if (surfaceElement == nullptr) return false; - if (surfaceElement->getOwnership().has(OwnershipFlag::owned)) + if (surfaceElement->hasOwnership(OwnershipFlag::owned)) return true; } return false; @@ -860,9 +860,9 @@ namespace OpenRCT2 { return false; } - if (surfaceElement->getOwnership().has(OwnershipFlag::owned)) + if (surfaceElement->hasOwnership(OwnershipFlag::owned)) return true; - if (surfaceElement->getOwnership().has(OwnershipFlag::constructionRightsOwned)) + if (surfaceElement->hasOwnership(OwnershipFlag::constructionRightsOwned)) return true; } return false; diff --git a/src/openrct2/world/Park.cpp b/src/openrct2/world/Park.cpp index 9cf116d261..c35501c0fc 100644 --- a/src/openrct2/world/Park.cpp +++ b/src/openrct2/world/Park.cpp @@ -641,7 +641,7 @@ namespace OpenRCT2::Park return; uint8_t newFences = 0; - if (!surfaceElement->getOwnership().has(OwnershipFlag::owned)) + if (!surfaceElement->hasOwnership(OwnershipFlag::owned)) { bool fenceRequired = true; diff --git a/src/openrct2/world/tile_element/SurfaceElement.cpp b/src/openrct2/world/tile_element/SurfaceElement.cpp index 0bc10fdc47..3ca83e5f5e 100644 --- a/src/openrct2/world/tile_element/SurfaceElement.cpp +++ b/src/openrct2/world/tile_element/SurfaceElement.cpp @@ -204,6 +204,11 @@ namespace OpenRCT2 ownership |= (((newOwnership.holder) << 4) & kTileElementSurfaceOwnershipMask); } + bool SurfaceElement::hasOwnership(OwnershipFlag flag) const + { + return getOwnership().has(flag); + } + uint8_t SurfaceElement::getParkFences() const { return (ownership & kTileElementSurfaceParkFenceMask); diff --git a/src/openrct2/world/tile_element/SurfaceElement.h b/src/openrct2/world/tile_element/SurfaceElement.h index a413e5af90..bcca6b6545 100644 --- a/src/openrct2/world/tile_element/SurfaceElement.h +++ b/src/openrct2/world/tile_element/SurfaceElement.h @@ -74,6 +74,7 @@ namespace OpenRCT2 OwnershipFlags getOwnership() const; void setOwnership(OwnershipFlags newOwnership); + bool hasOwnership(OwnershipFlag flag) const; int32_t getWaterHeight() const; void setWaterHeight(int32_t newWaterHeight);