Use TileElementsView for SmallSceneryRemoveAction

This commit is contained in:
Matt committed 2021-02-05 17:28:18 +02:00
1 parent 83221d51aa
commit ddd67db1d2
1 file changed
+11 -16
@@ -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<SmallSceneryElement>(_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<TileElement>();
}
return nullptr;
}