mirror of https://github.com/OpenRCT2/OpenRCT2.git
Use TileElementsView for LargeSceneryRemoveAction and cleanup
This commit is contained in:
parent
5bd6ba25b7
commit
5e2e7143cd
|
@ -21,6 +21,9 @@
|
||||||
#include "../world/Park.h"
|
#include "../world/Park.h"
|
||||||
#include "../world/SmallScenery.h"
|
#include "../world/SmallScenery.h"
|
||||||
#include "../world/Sprite.h"
|
#include "../world/Sprite.h"
|
||||||
|
#include "../world/TileElementsView.h"
|
||||||
|
|
||||||
|
using namespace OpenRCT2;
|
||||||
|
|
||||||
LargeSceneryRemoveAction::LargeSceneryRemoveAction(const CoordsXYZD& location, uint16_t tileIndex)
|
LargeSceneryRemoveAction::LargeSceneryRemoveAction(const CoordsXYZD& location, uint16_t tileIndex)
|
||||||
: _loc(location)
|
: _loc(location)
|
||||||
|
@ -59,7 +62,7 @@ GameActions::Result::Ptr LargeSceneryRemoveAction::Query() const
|
||||||
res->Expenditure = ExpenditureType::Landscaping;
|
res->Expenditure = ExpenditureType::Landscaping;
|
||||||
res->Cost = 0;
|
res->Cost = 0;
|
||||||
|
|
||||||
TileElement* tileElement = FindLargeSceneryElement();
|
TileElement* tileElement = FindLargeSceneryElement(_loc, _tileIndex);
|
||||||
if (tileElement == nullptr)
|
if (tileElement == nullptr)
|
||||||
{
|
{
|
||||||
log_warning("Invalid game command for scenery removal, x = %d, y = %d", _loc.x, _loc.y);
|
log_warning("Invalid game command for scenery removal, x = %d, y = %d", _loc.x, _loc.y);
|
||||||
|
@ -132,7 +135,7 @@ GameActions::Result::Ptr LargeSceneryRemoveAction::Execute() const
|
||||||
res->Expenditure = ExpenditureType::Landscaping;
|
res->Expenditure = ExpenditureType::Landscaping;
|
||||||
res->Cost = 0;
|
res->Cost = 0;
|
||||||
|
|
||||||
TileElement* tileElement = FindLargeSceneryElement();
|
TileElement* tileElement = FindLargeSceneryElement(_loc, _tileIndex);
|
||||||
if (tileElement == nullptr)
|
if (tileElement == nullptr)
|
||||||
{
|
{
|
||||||
log_warning("Invalid game command for scenery removal, x = %d, y = %d", _loc.x, _loc.y);
|
log_warning("Invalid game command for scenery removal, x = %d, y = %d", _loc.x, _loc.y);
|
||||||
|
@ -171,37 +174,13 @@ GameActions::Result::Ptr LargeSceneryRemoveAction::Execute() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TileElement* sceneryElement = map_get_first_element_at(currentTile);
|
auto* sceneryElement = FindLargeSceneryElement(currentTile, i);
|
||||||
bool element_found = false;
|
|
||||||
if (sceneryElement != nullptr)
|
if (sceneryElement != nullptr)
|
||||||
{
|
{
|
||||||
do
|
map_invalidate_tile_full(currentTile);
|
||||||
{
|
tile_element_remove(sceneryElement);
|
||||||
if (sceneryElement->GetType() != TILE_ELEMENT_TYPE_LARGE_SCENERY)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (sceneryElement->GetDirection() != _loc.direction)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (sceneryElement->AsLargeScenery()->GetSequenceIndex() != i)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (sceneryElement->GetBaseZ() != currentTile.z)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// If we are removing ghost elements
|
|
||||||
if ((flags & GAME_COMMAND_FLAG_GHOST) && sceneryElement->IsGhost() == false)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
map_invalidate_tile_full(currentTile);
|
|
||||||
tile_element_remove(sceneryElement);
|
|
||||||
|
|
||||||
element_found = true;
|
|
||||||
break;
|
|
||||||
} while (!(sceneryElement++)->IsLastForTile());
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if (element_found == false)
|
|
||||||
{
|
{
|
||||||
log_error("Tile not found when trying to remove element!");
|
log_error("Tile not found when trying to remove element!");
|
||||||
}
|
}
|
||||||
|
@ -212,33 +191,25 @@ GameActions::Result::Ptr LargeSceneryRemoveAction::Execute() const
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
TileElement* LargeSceneryRemoveAction::FindLargeSceneryElement() const
|
TileElement* LargeSceneryRemoveAction::FindLargeSceneryElement(const CoordsXYZ& pos, int32_t sequenceIndex) const
|
||||||
{
|
{
|
||||||
TileElement* tileElement = map_get_first_element_at(_loc);
|
for (auto* sceneryElement : TileElementsView<LargeSceneryElement>(pos))
|
||||||
if (tileElement == nullptr)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
if (tileElement->GetType() != TILE_ELEMENT_TYPE_LARGE_SCENERY)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (tileElement->GetBaseZ() != _loc.z)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (tileElement->AsLargeScenery()->GetSequenceIndex() != _tileIndex)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (tileElement->GetDirection() != _loc.direction)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// If we are removing ghost elements
|
// If we are removing ghost elements
|
||||||
if ((GetFlags() & GAME_COMMAND_FLAG_GHOST) && tileElement->IsGhost() == false)
|
if ((GetFlags() & GAME_COMMAND_FLAG_GHOST) && sceneryElement->IsGhost() == false)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
return tileElement;
|
if (sceneryElement->GetDirection() != _loc.direction)
|
||||||
|
continue;
|
||||||
|
|
||||||
} while (!(tileElement++)->IsLastForTile());
|
if (sceneryElement->GetSequenceIndex() != sequenceIndex)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (sceneryElement->GetBaseZ() != pos.z)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
return sceneryElement->as<TileElement>();
|
||||||
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,5 +30,5 @@ public:
|
||||||
GameActions::Result::Ptr Execute() const override;
|
GameActions::Result::Ptr Execute() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TileElement* FindLargeSceneryElement() const;
|
TileElement* FindLargeSceneryElement(const CoordsXYZ& pos, int32_t sequenceIndex) const;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue