1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-17 03:53:07 +01:00

Refactor smalSceneryRemoveAction

This commit is contained in:
0cufox0
2019-07-06 23:04:02 +03:00
committed by duncanspumpkin
parent 0320f195e3
commit 5cd8541a1c
8 changed files with 24 additions and 30 deletions

View File

@@ -496,7 +496,8 @@ int32_t viewport_interaction_right_click(int32_t x, int32_t y)
static void viewport_interaction_remove_scenery(TileElement* tileElement, int32_t x, int32_t y)
{
auto removeSceneryAction = SmallSceneryRemoveAction(
x, y, tileElement->base_height, tileElement->AsSmallScenery()->GetSceneryQuadrant(),
{x, y, tileElement->base_height * 8},
tileElement->AsSmallScenery()->GetSceneryQuadrant(),
tileElement->AsSmallScenery()->GetEntryIndex());
GameActions::Execute(&removeSceneryAction);
@@ -574,7 +575,7 @@ static void viewport_interaction_remove_park_wall(TileElement* tileElement, int3
}
else
{
CoordsXYZD wallLocation = { x , y , tileElement->base_height , tileElement->GetDirection() };
CoordsXYZD wallLocation = { x, y, tileElement->base_height << 3, tileElement->GetDirection() };
auto wallRemoveAction = WallRemoveAction(wallLocation);
GameActions::Execute(&wallRemoveAction);
}

View File

@@ -474,7 +474,7 @@ static void window_sign_small_mouseup(rct_window* w, rct_widgetindex widgetIndex
}
tile_element++;
}
CoordsXYZD wallLocation = { x , y , tile_element->base_height, tile_element->GetDirection() };
CoordsXYZD wallLocation = { x , y , tile_element->base_height << 3, tile_element->GetDirection() };
auto wallRemoveAction = WallRemoveAction(wallLocation);
GameActions::Execute(&wallRemoveAction);
break;

View File

@@ -169,7 +169,8 @@ private:
if (_itemsToClear & CLEARABLE_ITEMS::SCENERY_SMALL)
{
auto removeSceneryAction = SmallSceneryRemoveAction(
x * 32, y * 32, tileElement->base_height, tileElement->AsSmallScenery()->GetSceneryQuadrant(),
{x * 32, y * 32, tileElement->base_height * 8},
tileElement->AsSmallScenery()->GetSceneryQuadrant(),
tileElement->AsSmallScenery()->GetEntryIndex());
removeSceneryAction.SetFlags(GetFlags());
@@ -186,7 +187,7 @@ private:
case TILE_ELEMENT_TYPE_WALL:
if (_itemsToClear & CLEARABLE_ITEMS::SCENERY_SMALL)
{
CoordsXYZD wallLocation = { x<<5, y<<5, tileElement->base_height, tileElement->GetDirection() };
CoordsXYZD wallLocation = { x<<5, y<<5, tileElement->base_height << 3, tileElement->GetDirection() };
auto wallRemoveAction = WallRemoveAction(wallLocation);
wallRemoveAction.SetFlags(GetFlags());

View File

@@ -26,19 +26,15 @@
DEFINE_GAME_ACTION(SmallSceneryRemoveAction, GAME_COMMAND_REMOVE_SCENERY, GameActionResult)
{
private:
int16_t _x;
int16_t _y;
uint8_t _baseHeight;
CoordsXYZ _loc;
uint8_t _quadrant;
uint8_t _sceneryType;
public:
SmallSceneryRemoveAction() = default;
SmallSceneryRemoveAction(int16_t x, int16_t y, uint8_t baseHeight, uint8_t quadrant, uint8_t sceneryType)
: _x(x)
, _y(y)
, _baseHeight(baseHeight)
SmallSceneryRemoveAction(CoordsXYZ location, uint8_t quadrant, uint8_t sceneryType)
: _loc(location)
, _quadrant(quadrant)
, _sceneryType(sceneryType)
{
@@ -53,14 +49,14 @@ public:
{
GameAction::Serialise(stream);
stream << DS_TAG(_x) << DS_TAG(_y) << DS_TAG(_baseHeight) << DS_TAG(_quadrant) << DS_TAG(_sceneryType);
stream << DS_TAG(_loc) << DS_TAG(_quadrant) << DS_TAG(_sceneryType);
}
GameActionResult::Ptr Query() const override
{
GameActionResult::Ptr res = std::make_unique<GameActionResult>();
if (!map_is_location_valid({ _x, _y }))
if (!map_is_location_valid({ _loc.x, _loc.y }))
{
return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_CANT_REMOVE_THIS, STR_LAND_NOT_OWNED_BY_PARK);
}
@@ -73,9 +69,7 @@ public:
res->Cost = entry->small_scenery.removal_price * 10;
res->ExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING;
res->Position.x = _x;
res->Position.y = _y;
res->Position.z = _baseHeight * 8;
res->Position = _loc;
if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !(GetFlags() & GAME_COMMAND_FLAG_GHOST) && !gCheatsSandboxMode)
{
@@ -92,7 +86,7 @@ public:
}
// Check if the land is owned
if (!map_is_location_owned(_x, _y, _baseHeight * 8))
if (!map_is_location_owned(_loc.x, _loc.y, _loc.z))
{
res->Error = GA_ERROR::NO_CLEARANCE;
res->ErrorTitle = STR_CANT_REMOVE_THIS;
@@ -122,9 +116,7 @@ public:
res->Cost = entry->small_scenery.removal_price * 10;
res->ExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING;
res->Position.x = _x;
res->Position.y = _y;
res->Position.z = _baseHeight * 8;
res->Position = _loc;
TileElement* tileElement = FindSceneryElement();
if (tileElement == nullptr)
@@ -134,7 +126,7 @@ public:
res->Position.z = tile_element_height(res->Position.x, res->Position.y);
map_invalidate_tile_full(_x, _y);
map_invalidate_tile_full(_loc.x, _loc.y);
tile_element_remove(tileElement);
return res;
@@ -143,7 +135,7 @@ public:
private:
TileElement* FindSceneryElement() const
{
TileElement* tileElement = map_get_first_element_at(_x / 32, _y / 32);
TileElement* tileElement = map_get_first_element_at(_loc.x / 32, _loc.y / 32);
if (!tileElement)
return nullptr;
@@ -153,7 +145,7 @@ private:
continue;
if ((tileElement->AsSmallScenery()->GetSceneryQuadrant()) != _quadrant)
continue;
if (tileElement->base_height != _baseHeight)
if (tileElement->base_height != _loc.z >> 3)
continue;
if (tileElement->AsSmallScenery()->GetEntryIndex() != _sceneryType)
continue;

View File

@@ -106,7 +106,7 @@ private:
{
if (tileElement->GetType() != TILE_ELEMENT_TYPE_WALL)
continue;
if (tileElement->base_height != location.z)
if (tileElement->base_height != location.z >> 3)
continue;
if (tileElement->GetDirection() != location.direction)
continue;

View File

@@ -776,14 +776,14 @@ static bool TrackDesignPlaceSceneryElementRemoveGhost(
quadrant = 0;
}
ga = std::make_unique<SmallSceneryRemoveAction>(mapCoord.x, mapCoord.y, z, quadrant, entry_index);
ga = std::make_unique<SmallSceneryRemoveAction>(CoordsXYZ{mapCoord.x, mapCoord.y, z * 8}, quadrant, entry_index);
break;
}
case OBJECT_TYPE_LARGE_SCENERY:
ga = std::make_unique<LargeSceneryRemoveAction>(mapCoord.x, mapCoord.y, z, sceneryRotation, 0);
break;
case OBJECT_TYPE_WALLS:
ga = std::make_unique<WallRemoveAction>(CoordsXYZD{ mapCoord.x , mapCoord.y , z, sceneryRotation });
ga = std::make_unique<WallRemoveAction>(CoordsXYZD{ mapCoord.x , mapCoord.y , z * 8, sceneryRotation });
break;
case OBJECT_TYPE_PATHS:
ga = std::make_unique<FootpathRemoveAction>(mapCoord.x, mapCoord.y, z);

View File

@@ -1755,7 +1755,7 @@ static void clear_element_at(int32_t x, int32_t y, TileElement** elementPtr)
}
case TILE_ELEMENT_TYPE_WALL:
{
CoordsXYZD wallLocation = { x, y, element->base_height, element->GetDirection() };
CoordsXYZD wallLocation = { x, y, element->base_height << 3, element->GetDirection() };
auto wallRemoveAction = WallRemoveAction(wallLocation);
GameActions::Execute(&wallRemoveAction);
}

View File

@@ -186,7 +186,7 @@ void scenery_remove_ghost_tool_placement()
{
gSceneryGhostType &= ~SCENERY_GHOST_FLAG_0;
auto removeSceneryAction = SmallSceneryRemoveAction(x, y, z, gSceneryQuadrant, gSceneryPlaceObject);
auto removeSceneryAction = SmallSceneryRemoveAction({x, y, z * 8}, gSceneryQuadrant, gSceneryPlaceObject);
removeSceneryAction.SetFlags(
GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_NO_SPEND | GAME_COMMAND_FLAG_GHOST);
removeSceneryAction.Execute();
@@ -216,7 +216,7 @@ void scenery_remove_ghost_tool_placement()
{
gSceneryGhostType &= ~SCENERY_GHOST_FLAG_2;
CoordsXYZD wallLocation = { x , y , z, gSceneryGhostWallRotation };
CoordsXYZD wallLocation = { x , y , z * 8, gSceneryGhostWallRotation };
auto wallRemoveAction = WallRemoveAction(wallLocation);
wallRemoveAction.SetFlags(GAME_COMMAND_FLAG_APPLY | GAME_COMMAND_FLAG_GHOST | GAME_COMMAND_FLAG_PATH_SCENERY);
wallRemoveAction.Execute();