mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 11:03:00 +01:00
Use TileElementsView for RideEntranceExitRemoveAction and cleanup
This commit is contained in:
@@ -12,6 +12,9 @@
|
||||
#include "../ride/Ride.h"
|
||||
#include "../ride/Station.h"
|
||||
#include "../world/Entrance.h"
|
||||
#include "../world/TileElementsView.h"
|
||||
|
||||
using namespace OpenRCT2;
|
||||
|
||||
RideEntranceExitRemoveAction::RideEntranceExitRemoveAction(
|
||||
const CoordsXY& loc, ride_id_t rideIndex, StationIndex stationNum, bool isExit)
|
||||
@@ -42,6 +45,28 @@ void RideEntranceExitRemoveAction::Serialise(DataSerialiser& stream)
|
||||
stream << DS_TAG(_loc) << DS_TAG(_rideIndex) << DS_TAG(_stationNum) << DS_TAG(_isExit);
|
||||
}
|
||||
|
||||
static TileElement* FindEntranceElement(
|
||||
const CoordsXY& loc, ride_id_t rideIndex, int32_t stationNum, int32_t entranceType, bool ghost)
|
||||
{
|
||||
for (auto* entranceElement : TileElementsView<EntranceElement>(loc))
|
||||
{
|
||||
if (entranceElement->IsGhost() != ghost)
|
||||
continue;
|
||||
|
||||
if (entranceElement->GetRideIndex() != rideIndex)
|
||||
continue;
|
||||
|
||||
if (entranceElement->GetStationIndex() != stationNum)
|
||||
continue;
|
||||
|
||||
if (entranceElement->GetEntranceType() != entranceType)
|
||||
continue;
|
||||
|
||||
return entranceElement->as<TileElement>();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GameActions::Result::Ptr RideEntranceExitRemoveAction::Query() const
|
||||
{
|
||||
auto ride = get_ride(_rideIndex);
|
||||
@@ -66,40 +91,12 @@ GameActions::Result::Ptr RideEntranceExitRemoveAction::Query() const
|
||||
return MakeResult(GameActions::Status::InvalidParameters, STR_LAND_NOT_OWNED_BY_PARK);
|
||||
}
|
||||
|
||||
bool found = false;
|
||||
TileElement* tileElement = map_get_first_element_at(_loc);
|
||||
const bool isGhost = GetFlags() & GAME_COMMAND_FLAG_GHOST;
|
||||
|
||||
do
|
||||
{
|
||||
if (tileElement == nullptr)
|
||||
break;
|
||||
auto* entranceElement = FindEntranceElement(
|
||||
_loc, _rideIndex, _stationNum, _isExit ? ENTRANCE_TYPE_RIDE_EXIT : ENTRANCE_TYPE_RIDE_ENTRANCE, isGhost);
|
||||
|
||||
if (tileElement->GetType() != TILE_ELEMENT_TYPE_ENTRANCE)
|
||||
continue;
|
||||
|
||||
if (tileElement->GetRideIndex() != _rideIndex)
|
||||
continue;
|
||||
|
||||
if (tileElement->AsEntrance()->GetStationIndex() != _stationNum)
|
||||
continue;
|
||||
|
||||
if ((GetFlags() & GAME_COMMAND_FLAG_GHOST) && !(tileElement->IsGhost()))
|
||||
continue;
|
||||
|
||||
if (tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_PARK_ENTRANCE)
|
||||
continue;
|
||||
|
||||
if (tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_RIDE_ENTRANCE && _isExit)
|
||||
continue;
|
||||
|
||||
if (tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_RIDE_EXIT && !_isExit)
|
||||
continue;
|
||||
|
||||
found = true;
|
||||
break;
|
||||
} while (!(tileElement++)->IsLastForTile());
|
||||
|
||||
if (!found)
|
||||
if (entranceElement == nullptr)
|
||||
{
|
||||
log_warning(
|
||||
"Track Element not found. x = %d, y = %d, ride = %d, station = %d", _loc.x, _loc.y,
|
||||
@@ -119,47 +116,18 @@ GameActions::Result::Ptr RideEntranceExitRemoveAction::Execute() const
|
||||
return std::make_unique<GameActions::Result>(GameActions::Status::InvalidParameters, STR_NONE);
|
||||
}
|
||||
|
||||
if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST))
|
||||
const bool isGhost = GetFlags() & GAME_COMMAND_FLAG_GHOST;
|
||||
if (!isGhost)
|
||||
{
|
||||
ride_clear_for_construction(ride);
|
||||
ride_remove_peeps(ride);
|
||||
invalidate_test_results(ride);
|
||||
}
|
||||
|
||||
bool found = false;
|
||||
TileElement* tileElement = map_get_first_element_at(_loc);
|
||||
auto* entranceElement = FindEntranceElement(
|
||||
_loc, _rideIndex, _stationNum, _isExit ? ENTRANCE_TYPE_RIDE_EXIT : ENTRANCE_TYPE_RIDE_ENTRANCE, isGhost);
|
||||
|
||||
do
|
||||
{
|
||||
if (tileElement == nullptr)
|
||||
break;
|
||||
|
||||
if (tileElement->GetType() != TILE_ELEMENT_TYPE_ENTRANCE)
|
||||
continue;
|
||||
|
||||
if (tileElement->GetRideIndex() != _rideIndex)
|
||||
continue;
|
||||
|
||||
if (tileElement->AsEntrance()->GetStationIndex() != _stationNum)
|
||||
continue;
|
||||
|
||||
if ((GetFlags() & GAME_COMMAND_FLAG_GHOST) && !tileElement->IsGhost())
|
||||
continue;
|
||||
|
||||
if (tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_PARK_ENTRANCE)
|
||||
continue;
|
||||
|
||||
if (tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_RIDE_ENTRANCE && _isExit)
|
||||
continue;
|
||||
|
||||
if (tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_RIDE_EXIT && !_isExit)
|
||||
continue;
|
||||
|
||||
found = true;
|
||||
break;
|
||||
} while (!(tileElement++)->IsLastForTile());
|
||||
|
||||
if (!found)
|
||||
if (entranceElement == nullptr)
|
||||
{
|
||||
log_warning(
|
||||
"Track Element not found. x = %d, y = %d, ride = %d, station = %d", _loc.x, _loc.y,
|
||||
@@ -173,10 +141,10 @@ GameActions::Result::Ptr RideEntranceExitRemoveAction::Execute() const
|
||||
res->Position.z = tile_element_height(res->Position);
|
||||
|
||||
footpath_queue_chain_reset();
|
||||
maze_entrance_hedge_replacement({ _loc, tileElement });
|
||||
footpath_remove_edges_at(_loc, tileElement);
|
||||
maze_entrance_hedge_replacement({ _loc, entranceElement });
|
||||
footpath_remove_edges_at(_loc, entranceElement);
|
||||
|
||||
tile_element_remove(tileElement);
|
||||
tile_element_remove(entranceElement);
|
||||
|
||||
if (_isExit)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user