From 8cb76cd969a2cad833f38cf53ab59bb1f28bb184 Mon Sep 17 00:00:00 2001 From: ZehMatt Date: Sun, 11 Mar 2018 10:03:34 +0100 Subject: [PATCH] Use game action directly when used from different game command/action. --- src/openrct2/actions/WallRemoveAction.hpp | 19 ++++----------- src/openrct2/world/Map.cpp | 29 ++++++++++------------- src/openrct2/world/Scenery.cpp | 10 +++++--- 3 files changed, 25 insertions(+), 33 deletions(-) diff --git a/src/openrct2/actions/WallRemoveAction.hpp b/src/openrct2/actions/WallRemoveAction.hpp index 933c85feab..27d889a9fc 100644 --- a/src/openrct2/actions/WallRemoveAction.hpp +++ b/src/openrct2/actions/WallRemoveAction.hpp @@ -16,6 +16,7 @@ #pragma once +#include "../OpenRCT2.h" #include "../core/MemoryStream.h" #include "../localisation/StringIds.h" #include "GameAction.h" @@ -62,9 +63,7 @@ public: if (!map_is_location_valid(_x, _y)) { - res->Error = GA_ERROR::INVALID_PARAMETERS; - res->ErrorMessage = STR_INVALID_SELECTION_OF_OBJECTS; - return res; + return std::make_unique(GA_ERROR::INVALID_PARAMETERS, STR_CANT_REMOVE_THIS, STR_INVALID_SELECTION_OF_OBJECTS); } const bool isGhost = GetFlags() & GAME_COMMAND_FLAG_GHOST; @@ -73,19 +72,13 @@ public: !gCheatsSandboxMode && !map_is_location_owned(_x, _y, _baseHeight * 8)) { - res->Error = GA_ERROR::NOT_OWNED; - res->ErrorMessage = STR_CANT_REMOVE_THIS; - return res; + return std::make_unique(GA_ERROR::NOT_OWNED, STR_CANT_REMOVE_THIS, STR_LAND_NOT_OWNED_BY_PARK); } rct_tile_element * wallElement = GetFirstWallElementAt(_x, _y, _baseHeight, _direction, isGhost); if (wallElement == nullptr) { - // NOTE: There seems to be some oddities with calling code currently trying to - // delete the same thing multiple times. - res->Error = GA_ERROR::INVALID_PARAMETERS; - res->ErrorMessage = STR_NONE; - return res; + return std::make_unique(GA_ERROR::INVALID_PARAMETERS, STR_CANT_REMOVE_THIS, STR_INVALID_SELECTION_OF_OBJECTS); } res->Cost = 0; @@ -103,9 +96,7 @@ public: rct_tile_element * wallElement = GetFirstWallElementAt(_x, _y, _baseHeight, _direction, isGhost); if (wallElement == nullptr) { - res->Error = GA_ERROR::INVALID_PARAMETERS; - res->ErrorMessage = STR_INVALID_SELECTION_OF_OBJECTS; - return res; + return std::make_unique(GA_ERROR::INVALID_PARAMETERS, STR_CANT_REMOVE_THIS, STR_INVALID_SELECTION_OF_OBJECTS); } res->Position.x = _x + 16; diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index f1b254fd41..1eee6cfbdb 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -37,6 +37,7 @@ #include "../scenario/Scenario.h" #include "../util/Util.h" #include "../windows/Intent.h" +#include "../actions/WallRemoveAction.hpp" #include "Banner.h" #include "Climate.h" #include "Footpath.h" @@ -1123,22 +1124,18 @@ restart_from_beginning: } break; case TILE_ELEMENT_TYPE_WALL: - if (clear & (1 << 0)) { - cost = wall_remove(x * 32, y * 32, tileElement->base_height, tile_element_get_direction(tileElement), flags); - if (cost == MONEY32_UNDEFINED) - return MONEY32_UNDEFINED; - - totalCost += cost; - - // NOTE (12/10/2017): This will get us stuck in an infinite loop because game actions are queued - // it seems to be trying to remove the same thing over and over. - // Leaving this here for reference. - /* - if (flags & 1) - goto restart_from_beginning; - */ - - } break; + if (clear & (1 << 0)) + { + // NOTE: We execute the game action directly as this function is already called from such. + auto wallRemoveAction = WallRemoveAction(x * 32, y * 32, tileElement->base_height, tile_element_get_direction(tileElement)); + wallRemoveAction.SetFlags(flags); + auto res = ((flags & GAME_COMMAND_FLAG_APPLY) ? wallRemoveAction.Execute() : wallRemoveAction.Query()); + if (res->Error == GA_ERROR::OK) + { + totalCost += res->Cost; + } + } + break; case TILE_ELEMENT_TYPE_LARGE_SCENERY: if (clear & (1 << 1)) { sint32 eax = x * 32; diff --git a/src/openrct2/world/Scenery.cpp b/src/openrct2/world/Scenery.cpp index f8dbf8d8fe..742bf0a84e 100644 --- a/src/openrct2/world/Scenery.cpp +++ b/src/openrct2/world/Scenery.cpp @@ -23,6 +23,7 @@ #include "../object/ObjectList.h" #include "../object/ObjectManager.h" #include "../scenario/Scenario.h" +#include "../actions/WallRemoveAction.hpp" #include "Climate.h" #include "Footpath.h" #include "Fountain.h" @@ -243,10 +244,13 @@ void scenery_remove_ghost_tool_placement(){ } while (!tile_element_is_last_for_tile(tile_element++)); } - if (gSceneryGhostType & SCENERY_ENTRY_FLAG_2){ + if (gSceneryGhostType & SCENERY_ENTRY_FLAG_2) + { gSceneryGhostType &= ~SCENERY_ENTRY_FLAG_2; - const sint32 flags = GAME_COMMAND_FLAG_APPLY | GAME_COMMAND_FLAG_GHOST | GAME_COMMAND_FLAG_PATH_SCENERY; - wall_remove(x, y, gSceneryGhostWallRotation, z, flags); + + auto wallRemoveAction = WallRemoveAction(x, y, z, gSceneryGhostWallRotation); + wallRemoveAction.SetFlags(GAME_COMMAND_FLAG_APPLY | GAME_COMMAND_FLAG_GHOST | GAME_COMMAND_FLAG_PATH_SCENERY); + wallRemoveAction.Execute(); } if (gSceneryGhostType & SCENERY_ENTRY_FLAG_3){