From ddd67db1d25e2793ed25ddcba2fde4bca13dce00 Mon Sep 17 00:00:00 2001 From: Matt Date: Fri, 5 Feb 2021 17:28:18 +0200 Subject: [PATCH] Use TileElementsView for SmallSceneryRemoveAction --- .../actions/SmallSceneryRemoveAction.cpp | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/openrct2/actions/SmallSceneryRemoveAction.cpp b/src/openrct2/actions/SmallSceneryRemoveAction.cpp index 98915933f9..2c479700ff 100644 --- a/src/openrct2/actions/SmallSceneryRemoveAction.cpp +++ b/src/openrct2/actions/SmallSceneryRemoveAction.cpp @@ -21,9 +21,12 @@ #include "../world/Park.h" #include "../world/SmallScenery.h" #include "../world/Sprite.h" +#include "../world/TileElementsView.h" #include "GameAction.h" #include "SmallSceneryPlaceAction.h" +using namespace OpenRCT2; + SmallSceneryRemoveAction::SmallSceneryRemoveAction(const CoordsXYZ& location, uint8_t quadrant, ObjectEntryIndex sceneryType) : _loc(location) , _quadrant(quadrant) @@ -132,26 +135,18 @@ GameActions::Result::Ptr SmallSceneryRemoveAction::Execute() const TileElement* SmallSceneryRemoveAction::FindSceneryElement() const { - TileElement* tileElement = map_get_first_element_at(_loc); - if (!tileElement) - return nullptr; - - do + const bool isGhost = GetFlags() & GAME_COMMAND_FLAG_GHOST; + for (auto* sceneryElement : TileElementsView(_loc)) { - if (tileElement->GetType() != TILE_ELEMENT_TYPE_SMALL_SCENERY) + if (sceneryElement->IsGhost() != isGhost) continue; - if ((tileElement->AsSmallScenery()->GetSceneryQuadrant()) != _quadrant) + if (sceneryElement->GetSceneryQuadrant() != _quadrant) continue; - if (tileElement->GetBaseZ() != _loc.z) + if (sceneryElement->GetBaseZ() != _loc.z) continue; - if (tileElement->AsSmallScenery()->GetEntryIndex() != _sceneryType) + if (sceneryElement->GetEntryIndex() != _sceneryType) continue; - if ((GetFlags() & GAME_COMMAND_FLAG_GHOST) && tileElement->IsGhost() == false) - continue; - - return tileElement; - - } while (!(tileElement++)->IsLastForTile()); - + return sceneryElement->as(); + } return nullptr; }