From 0320f195e3071c82fbef0987f974b8e30ff2ca9d Mon Sep 17 00:00:00 2001 From: 0cufox0 Date: Sat, 6 Jul 2019 21:26:58 +0300 Subject: [PATCH] refactor wallRemoveAction --- .../interface/ViewportInteraction.cpp | 2 +- src/openrct2-ui/windows/Sign.cpp | 2 +- src/openrct2/actions/ClearAction.hpp | 2 +- src/openrct2/actions/WallRemoveAction.hpp | 26 +++++++++---------- src/openrct2/ride/TrackDesign.cpp | 2 +- src/openrct2/world/Map.cpp | 2 +- src/openrct2/world/Scenery.cpp | 2 +- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/openrct2-ui/interface/ViewportInteraction.cpp b/src/openrct2-ui/interface/ViewportInteraction.cpp index 1f151c2918..1d1a445b7a 100644 --- a/src/openrct2-ui/interface/ViewportInteraction.cpp +++ b/src/openrct2-ui/interface/ViewportInteraction.cpp @@ -574,7 +574,7 @@ static void viewport_interaction_remove_park_wall(TileElement* tileElement, int3 } else { - TileCoordsXYZD wallLocation = { x >> 5, y >> 5, tileElement->base_height, tileElement->GetDirection() }; + CoordsXYZD wallLocation = { x , y , tileElement->base_height , 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 e9b08834ba..a61eb8da29 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++; } - TileCoordsXYZD wallLocation = { x >> 5, y >> 5, tile_element->base_height, tile_element->GetDirection() }; + CoordsXYZD wallLocation = { x , y , tile_element->base_height, 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 1615734a6d..75ad7b881f 100644 --- a/src/openrct2/actions/ClearAction.hpp +++ b/src/openrct2/actions/ClearAction.hpp @@ -186,7 +186,7 @@ private: case TILE_ELEMENT_TYPE_WALL: if (_itemsToClear & CLEARABLE_ITEMS::SCENERY_SMALL) { - TileCoordsXYZD wallLocation = { x, y, tileElement->base_height, tileElement->GetDirection() }; + CoordsXYZD wallLocation = { x<<5, y<<5, tileElement->base_height, tileElement->GetDirection() }; auto wallRemoveAction = WallRemoveAction(wallLocation); wallRemoveAction.SetFlags(GetFlags()); diff --git a/src/openrct2/actions/WallRemoveAction.hpp b/src/openrct2/actions/WallRemoveAction.hpp index b11059b920..0f6b6997cd 100644 --- a/src/openrct2/actions/WallRemoveAction.hpp +++ b/src/openrct2/actions/WallRemoveAction.hpp @@ -22,12 +22,12 @@ DEFINE_GAME_ACTION(WallRemoveAction, GAME_COMMAND_REMOVE_WALL, GameActionResult) { private: - TileCoordsXYZD _location; + CoordsXYZD _loc; public: WallRemoveAction() = default; - WallRemoveAction(const TileCoordsXYZD& location) - : _location(location) + WallRemoveAction(const CoordsXYZD& loc) + : _loc(loc) { } @@ -35,7 +35,7 @@ public: { GameAction::Serialise(stream); - stream << DS_TAG(_location.x) << DS_TAG(_location.y) << DS_TAG(_location.z) << DS_TAG(_location.direction); + stream << DS_TAG(_loc); } GameActionResult::Ptr Query() const override @@ -44,7 +44,7 @@ public: res->Cost = 0; res->ExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING; - if (!map_is_location_valid({ _location.x << 5, _location.y << 5 })) + if (!map_is_location_valid({ _loc.x , _loc.y })) { return std::make_unique( GA_ERROR::INVALID_PARAMETERS, STR_CANT_REMOVE_THIS, STR_INVALID_SELECTION_OF_OBJECTS); @@ -52,12 +52,12 @@ public: const bool isGhost = GetFlags() & GAME_COMMAND_FLAG_GHOST; if (!isGhost && !(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gCheatsSandboxMode - && !map_is_location_owned(_location.x << 5, _location.y << 5, _location.z << 3)) + && !map_is_location_owned(_loc.x , _loc.y , _loc.z )) { return std::make_unique(GA_ERROR::NOT_OWNED, STR_CANT_REMOVE_THIS, STR_LAND_NOT_OWNED_BY_PARK); } - TileElement* wallElement = GetFirstWallElementAt(_location, isGhost); + TileElement* wallElement = GetFirstWallElementAt(_loc, isGhost); if (wallElement == nullptr) { return std::make_unique( @@ -76,29 +76,29 @@ public: const bool isGhost = GetFlags() & GAME_COMMAND_FLAG_GHOST; - TileElement* wallElement = GetFirstWallElementAt(_location, isGhost); + TileElement* wallElement = GetFirstWallElementAt(_loc, isGhost); if (wallElement == nullptr) { return std::make_unique( GA_ERROR::INVALID_PARAMETERS, STR_CANT_REMOVE_THIS, STR_INVALID_SELECTION_OF_OBJECTS); } - res->Position.x = (_location.x << 5) + 16; - res->Position.y = (_location.y << 5) + 16; + res->Position.x = _loc.x + 16; + res->Position.y = _loc.y + 16; res->Position.z = tile_element_height(res->Position.x, res->Position.y); tile_element_remove_banner_entry(wallElement); map_invalidate_tile_zoom1( - _location.x << 5, _location.y << 5, wallElement->base_height * 8, (wallElement->base_height * 8) + 72); + _loc.x, _loc.y , wallElement->base_height , wallElement->base_height + 72); tile_element_remove(wallElement); return res; } private: - TileElement* GetFirstWallElementAt(const TileCoordsXYZD& location, bool isGhost) const + TileElement* GetFirstWallElementAt(const CoordsXYZD& location, bool isGhost) const { - TileElement* tileElement = map_get_first_element_at(location.x, location.y); + TileElement* tileElement = map_get_first_element_at(location.x >> 5 , location.y >> 5 ); if (!tileElement) return nullptr; diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index 47f8d22f6b..39c59154c8 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -783,7 +783,7 @@ static bool TrackDesignPlaceSceneryElementRemoveGhost( ga = std::make_unique(mapCoord.x, mapCoord.y, z, sceneryRotation, 0); break; case OBJECT_TYPE_WALLS: - ga = std::make_unique(TileCoordsXYZD{ mapCoord.x / 32, mapCoord.y / 32, z, sceneryRotation }); + ga = std::make_unique(CoordsXYZD{ mapCoord.x , mapCoord.y , z, 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 082765883c..7d40226360 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: { - TileCoordsXYZD wallLocation = { x >> 5, y >> 5, element->base_height, element->GetDirection() }; + CoordsXYZD wallLocation = { x, y, element->base_height, element->GetDirection() }; auto wallRemoveAction = WallRemoveAction(wallLocation); GameActions::Execute(&wallRemoveAction); } diff --git a/src/openrct2/world/Scenery.cpp b/src/openrct2/world/Scenery.cpp index 90882fd81d..26471abcb2 100644 --- a/src/openrct2/world/Scenery.cpp +++ b/src/openrct2/world/Scenery.cpp @@ -216,7 +216,7 @@ void scenery_remove_ghost_tool_placement() { gSceneryGhostType &= ~SCENERY_GHOST_FLAG_2; - TileCoordsXYZD wallLocation = { x >> 5, y >> 5, z, gSceneryGhostWallRotation }; + CoordsXYZD wallLocation = { x , y , z, gSceneryGhostWallRotation }; auto wallRemoveAction = WallRemoveAction(wallLocation); wallRemoveAction.SetFlags(GAME_COMMAND_FLAG_APPLY | GAME_COMMAND_FLAG_GHOST | GAME_COMMAND_FLAG_PATH_SCENERY); wallRemoveAction.Execute();