From 5cd8541a1cfb6059a752610ab64b2b1bf296fec4 Mon Sep 17 00:00:00 2001 From: 0cufox0 Date: Sat, 6 Jul 2019 23:04:02 +0300 Subject: [PATCH] Refactor smalSceneryRemoveAction --- .../interface/ViewportInteraction.cpp | 5 ++-- src/openrct2-ui/windows/Sign.cpp | 2 +- src/openrct2/actions/ClearAction.hpp | 5 ++-- .../actions/SmallSceneryRemoveAction.hpp | 30 +++++++------------ src/openrct2/actions/WallRemoveAction.hpp | 2 +- src/openrct2/ride/TrackDesign.cpp | 4 +-- src/openrct2/world/Map.cpp | 2 +- src/openrct2/world/Scenery.cpp | 4 +-- 8 files changed, 24 insertions(+), 30 deletions(-) diff --git a/src/openrct2-ui/interface/ViewportInteraction.cpp b/src/openrct2-ui/interface/ViewportInteraction.cpp index 1d1a445b7a..9b8e9d6e9f 100644 --- a/src/openrct2-ui/interface/ViewportInteraction.cpp +++ b/src/openrct2-ui/interface/ViewportInteraction.cpp @@ -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); } diff --git a/src/openrct2-ui/windows/Sign.cpp b/src/openrct2-ui/windows/Sign.cpp index a61eb8da29..7e6d774ce4 100644 --- a/src/openrct2-ui/windows/Sign.cpp +++ b/src/openrct2-ui/windows/Sign.cpp @@ -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; diff --git a/src/openrct2/actions/ClearAction.hpp b/src/openrct2/actions/ClearAction.hpp index 75ad7b881f..686ec434bf 100644 --- a/src/openrct2/actions/ClearAction.hpp +++ b/src/openrct2/actions/ClearAction.hpp @@ -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()); diff --git a/src/openrct2/actions/SmallSceneryRemoveAction.hpp b/src/openrct2/actions/SmallSceneryRemoveAction.hpp index 60344bf39a..13bfe8415d 100644 --- a/src/openrct2/actions/SmallSceneryRemoveAction.hpp +++ b/src/openrct2/actions/SmallSceneryRemoveAction.hpp @@ -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(); - 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; diff --git a/src/openrct2/actions/WallRemoveAction.hpp b/src/openrct2/actions/WallRemoveAction.hpp index 0f6b6997cd..19adae0bb3 100644 --- a/src/openrct2/actions/WallRemoveAction.hpp +++ b/src/openrct2/actions/WallRemoveAction.hpp @@ -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; diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index 39c59154c8..9ccff3635d 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -776,14 +776,14 @@ static bool TrackDesignPlaceSceneryElementRemoveGhost( quadrant = 0; } - ga = std::make_unique(mapCoord.x, mapCoord.y, z, quadrant, entry_index); + ga = std::make_unique(CoordsXYZ{mapCoord.x, mapCoord.y, z * 8}, quadrant, entry_index); break; } case OBJECT_TYPE_LARGE_SCENERY: ga = std::make_unique(mapCoord.x, mapCoord.y, z, sceneryRotation, 0); break; case OBJECT_TYPE_WALLS: - ga = std::make_unique(CoordsXYZD{ mapCoord.x , mapCoord.y , z, sceneryRotation }); + ga = std::make_unique(CoordsXYZD{ mapCoord.x , mapCoord.y , z * 8, sceneryRotation }); break; case OBJECT_TYPE_PATHS: ga = std::make_unique(mapCoord.x, mapCoord.y, z); diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 7d40226360..be7f8a8e96 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -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); } diff --git a/src/openrct2/world/Scenery.cpp b/src/openrct2/world/Scenery.cpp index 26471abcb2..7476d30328 100644 --- a/src/openrct2/world/Scenery.cpp +++ b/src/openrct2/world/Scenery.cpp @@ -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();