diff --git a/src/openrct2-ui/windows/Sign.cpp b/src/openrct2-ui/windows/Sign.cpp index a423ebd77a..77dc7db00f 100644 --- a/src/openrct2-ui/windows/Sign.cpp +++ b/src/openrct2-ui/windows/Sign.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #define WW 113 #define WH 96 @@ -499,28 +500,28 @@ static void window_sign_small_mouseup(rct_window *w, rct_widgetindex widgetIndex window_close(w); break; case WIDX_SIGN_DEMOLISH: - while (1){ - if (tile_element->GetType() == TILE_ELEMENT_TYPE_WALL) { - rct_scenery_entry* scenery_entry = get_wall_entry(tile_element->properties.wall.type); - if (scenery_entry->wall.scrolling_mode != 0xFF){ - if (tile_element->properties.wall.banner_index == w->number) - break; + { + while (true) + { + if (tile_element->GetType() == TILE_ELEMENT_TYPE_WALL) + { + rct_scenery_entry* scenery_entry = get_wall_entry(tile_element->properties.wall.type); + if (scenery_entry->wall.scrolling_mode != 0xFF) + { + if (tile_element->properties.wall.banner_index == w->number) + break; + } } + tile_element++; } - tile_element++; + TileCoordsXYZD wallLocation = { x >> 5, y >> 5, tile_element->base_height, tile_element->GetDirection() }; + auto wallRemoveAction = WallRemoveAction(wallLocation); + GameActions::Execute(&wallRemoveAction); } - gGameCommandErrorTitle = STR_CANT_REMOVE_THIS; - game_do_command( - x, - 1 | (tile_element->GetDirection() << 8), - y, - (tile_element->base_height << 8) | tile_element->GetDirection(), - GAME_COMMAND_REMOVE_WALL, - 0, - 0); break; case WIDX_SIGN_TEXT: - if (banner->flags & BANNER_FLAG_LINKED_TO_RIDE){ + if (banner->flags & BANNER_FLAG_LINKED_TO_RIDE) + { Ride* ride = get_ride(banner->colour); set_format_arg(16, uint32, ride->name_arguments); string_id = ride->name; diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index c0eb7346f2..3d1a859832 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -1743,7 +1743,7 @@ GAME_COMMAND_POINTER * new_game_command_table[GAME_COMMAND_COUNT] = { game_command_set_park_entrance_fee, nullptr, game_command_place_wall, - game_command_remove_wall, + nullptr, game_command_place_large_scenery, game_command_remove_large_scenery, nullptr, diff --git a/src/openrct2/Game.h b/src/openrct2/Game.h index 660bde4902..a154e57767 100644 --- a/src/openrct2/Game.h +++ b/src/openrct2/Game.h @@ -66,7 +66,7 @@ enum GAME_COMMAND GAME_COMMAND_SET_PARK_ENTRANCE_FEE, // GA GAME_COMMAND_SET_STAFF_COLOUR, // GA GAME_COMMAND_PLACE_WALL, - GAME_COMMAND_REMOVE_WALL, + GAME_COMMAND_REMOVE_WALL, // GA GAME_COMMAND_PLACE_LARGE_SCENERY, GAME_COMMAND_REMOVE_LARGE_SCENERY, GAME_COMMAND_SET_CURRENT_LOAN, // GA diff --git a/src/openrct2/actions/GameAction.cpp b/src/openrct2/actions/GameAction.cpp index 7c31595c1b..83ccd1118b 100644 --- a/src/openrct2/actions/GameAction.cpp +++ b/src/openrct2/actions/GameAction.cpp @@ -89,7 +89,7 @@ namespace GameActions result = factory(); } } - Guard::ArgumentNotNull(result); + Guard::ArgumentNotNull(result, "Attempting to create unregistered gameaction: %u", id); return std::unique_ptr(result); } diff --git a/src/openrct2/actions/GameActionCompat.cpp b/src/openrct2/actions/GameActionCompat.cpp index 723a729e2a..ec0e948169 100644 --- a/src/openrct2/actions/GameActionCompat.cpp +++ b/src/openrct2/actions/GameActionCompat.cpp @@ -25,6 +25,7 @@ #include "RideDemolishAction.hpp" #include "PlacePeepSpawnAction.hpp" #include "MazeSetTrackAction.hpp" +#include "WallRemoveAction.hpp" #pragma region PlaceParkEntranceAction money32 place_park_entrance(sint16 x, sint16 y, sint16 z, uint8 direction) diff --git a/src/openrct2/actions/GameActionRegistration.cpp b/src/openrct2/actions/GameActionRegistration.cpp index 7d6f18fc57..cbdaf6673d 100644 --- a/src/openrct2/actions/GameActionRegistration.cpp +++ b/src/openrct2/actions/GameActionRegistration.cpp @@ -32,6 +32,7 @@ #include "SignSetNameAction.hpp" #include "ParkSetNameAction.hpp" #include "BannerSetNameAction.hpp" +#include "WallRemoveAction.hpp" namespace GameActions { @@ -54,5 +55,6 @@ namespace GameActions Register(); Register(); Register(); + Register(); } } // namespace GameActions diff --git a/src/openrct2/actions/WallRemoveAction.hpp b/src/openrct2/actions/WallRemoveAction.hpp new file mode 100644 index 0000000000..386e2ffee0 --- /dev/null +++ b/src/openrct2/actions/WallRemoveAction.hpp @@ -0,0 +1,127 @@ +#pragma region Copyright (c) 2014-2017 OpenRCT2 Developers +/***************************************************************************** +* OpenRCT2, an open source clone of Roller Coaster Tycoon 2. +* +* OpenRCT2 is the work of many authors, a full list can be found in contributors.md +* For more information, visit https://github.com/OpenRCT2/OpenRCT2 +* +* OpenRCT2 is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* A full copy of the GNU General Public License can be found in licence.txt +*****************************************************************************/ +#pragma endregion + +#pragma once + +#include "../Cheats.h" +#include "../OpenRCT2.h" +#include "../core/MemoryStream.h" +#include "../interface/Window.h" +#include "../localisation/StringIds.h" +#include "../management/Finance.h" +#include "../world/Location.hpp" +#include "../world/Wall.h" +#include "GameAction.h" + +struct WallRemoveAction : public GameActionBase +{ +private: + TileCoordsXYZD _location; + +public: + WallRemoveAction() = default; + WallRemoveAction(const TileCoordsXYZD& location) + : _location(location) + { + } + + uint16 GetActionFlags() const override + { + return GameAction::GetActionFlags(); + } + + void Serialise(DataSerialiser& stream) override + { + GameAction::Serialise(stream); + + stream << _location.x << _location.y << _location.z << _location.direction; + } + + GameActionResult::Ptr Query() const override + { + GameActionResult::Ptr res = std::make_unique(); + res->Cost = 0; + res->ExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING; + + if (!map_is_location_valid(_location.x << 5, _location.y << 5)) + { + 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; + if (!isGhost && + !(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && + !gCheatsSandboxMode && + !map_is_location_owned(_location.x << 5, _location.y << 5, _location.z << 3)) + { + return std::make_unique(GA_ERROR::NOT_OWNED, STR_CANT_REMOVE_THIS, STR_LAND_NOT_OWNED_BY_PARK); + } + + rct_tile_element* wallElement = GetFirstWallElementAt(_location, isGhost); + if (wallElement == nullptr) + { + return std::make_unique(GA_ERROR::INVALID_PARAMETERS, STR_CANT_REMOVE_THIS, STR_INVALID_SELECTION_OF_OBJECTS); + } + + res->Cost = 0; + return res; + } + + GameActionResult::Ptr Execute() const override + { + GameActionResult::Ptr res = std::make_unique(); + res->Cost = 0; + res->ExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING; + + const bool isGhost = GetFlags() & GAME_COMMAND_FLAG_GHOST; + + rct_tile_element * wallElement = GetFirstWallElementAt(_location, 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.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); + tile_element_remove(wallElement); + + return res; + } + +private: + rct_tile_element* GetFirstWallElementAt(const TileCoordsXYZD& location, bool isGhost) const + { + rct_tile_element* tileElement = map_get_first_element_at(location.x, location.y); + do + { + if (tileElement->GetType() != TILE_ELEMENT_TYPE_WALL) + continue; + if (tileElement->base_height != location.z) + continue; + if (tileElement->GetDirection() != location.direction) + continue; + if (tileElement->IsGhost() != isGhost) + continue; + + return tileElement; + } while (!tile_element_is_last_for_tile(tileElement++)); + return nullptr; + } +}; diff --git a/src/openrct2/interface/ViewportInteraction.cpp b/src/openrct2/interface/ViewportInteraction.cpp index 2e7408b92d..3a5ad71a7b 100644 --- a/src/openrct2/interface/ViewportInteraction.cpp +++ b/src/openrct2/interface/ViewportInteraction.cpp @@ -30,12 +30,14 @@ #include "../world/Map.h" #include "../world/Scenery.h" #include "../world/LargeScenery.h" +#include "../world/Park.h" #include "../world/Sprite.h" #include "../world/Surface.h" -#include "../world/Park.h" +#include "../world/Wall.h" #include "Viewport.h" #include "Window_internal.h" #include "../Context.h" +#include "../actions/WallRemoveAction.hpp" static void viewport_interaction_remove_scenery(rct_tile_element *tileElement, sint32 x, sint32 y); static void viewport_interaction_remove_footpath(rct_tile_element *tileElement, sint32 x, sint32 y); @@ -510,19 +512,15 @@ void viewport_interaction_remove_park_entrance(rct_tile_element *tileElement, si static void viewport_interaction_remove_park_wall(rct_tile_element *tileElement, sint32 x, sint32 y) { rct_scenery_entry *sceneryEntry = get_wall_entry(tileElement->properties.wall.type); - if (sceneryEntry->wall.scrolling_mode != 0xFF){ + if (sceneryEntry->wall.scrolling_mode != 0xFF) + { context_open_detail_window(WD_SIGN_SMALL, tileElement->properties.wall.banner_index); - } else { - gGameCommandErrorTitle = STR_CANT_REMOVE_THIS; - game_do_command( - x, - GAME_COMMAND_FLAG_APPLY, - y, - tile_element_get_direction(tileElement) | (tileElement->base_height << 8), - GAME_COMMAND_REMOVE_WALL, - 0, - 0 - ); + } + else + { + TileCoordsXYZD wallLocation = { x >> 5, y >> 5, tileElement->base_height, tileElement->GetDirection() }; + auto wallRemoveAction = WallRemoveAction(wallLocation); + GameActions::Execute(&wallRemoveAction); } } diff --git a/src/openrct2/network/Network.cpp b/src/openrct2/network/Network.cpp index 392f00ab8a..970ea19988 100644 --- a/src/openrct2/network/Network.cpp +++ b/src/openrct2/network/Network.cpp @@ -34,7 +34,7 @@ // This string specifies which version of network stream current build uses. // It is used for making sure only compatible builds get connected, even within // single OpenRCT2 version. -#define NETWORK_STREAM_VERSION "9" +#define NETWORK_STREAM_VERSION "10" #define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION static rct_peep* _pickup_peep = nullptr; diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index 0eb3006313..fdb1291d68 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -44,6 +44,8 @@ #include "../world/Scenery.h" #include "../world/SmallScenery.h" #include "../world/Surface.h" +#include "../world/Wall.h" +#include "../actions/WallRemoveAction.hpp" struct map_backup { @@ -858,15 +860,17 @@ track_design_place_scenery(rct_td6_scenery_element * scenery_start, sint32 origi 0); break; case OBJECT_TYPE_WALLS: - z = (scenery->z * 8 + originZ) / 8; - game_do_command( - mapCoord.x, - flags, - mapCoord.y, - (z << 8) | ((rotation + scenery->flags) & 0x3), - GAME_COMMAND_REMOVE_WALL, - 0, - 0); + { + z = (scenery->z * 8 + originZ) / 8; + + uint8_t direction = (rotation + scenery->flags) & TILE_ELEMENT_DIRECTION_MASK; + + TileCoordsXYZD wallLocation = { tile.x, tile.y, z, direction }; + auto wallRemoveAction = WallRemoveAction(wallLocation); + wallRemoveAction.SetFlags(flags); + + GameActions::Execute(&wallRemoveAction); + } break; case OBJECT_TYPE_PATHS: z = (scenery->z * 8 + originZ) / 8; diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 8a9edf1104..b3bf31cc44 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" @@ -1100,6 +1101,7 @@ restart_from_beginning: return MONEY32_UNDEFINED; totalCost += cost; + if (flags & 1) goto restart_from_beginning; } break; @@ -1116,27 +1118,25 @@ restart_from_beginning: return MONEY32_UNDEFINED; totalCost += cost; + if (flags & 1) goto restart_from_beginning; } break; case TILE_ELEMENT_TYPE_WALL: - if (clear & (1 << 0)) { - sint32 eax = x * 32; - sint32 ebx = flags; - sint32 ecx = y * 32; - sint32 edx = (tileElement->base_height << 8) | (tile_element_get_direction(tileElement)); - sint32 edi = 0, ebp = 0; - cost = game_do_command(eax, ebx, ecx, edx, GAME_COMMAND_REMOVE_WALL, edi, ebp); - - if (cost == MONEY32_UNDEFINED) - return MONEY32_UNDEFINED; - - totalCost += cost; - 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. + TileCoordsXYZD wallLocation = { x, y, tileElement->base_height, tileElement->GetDirection() }; + auto wallRemoveAction = WallRemoveAction(wallLocation); + 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; @@ -1150,6 +1150,7 @@ restart_from_beginning: return MONEY32_UNDEFINED; totalCost += cost; + if (flags & 1) goto restart_from_beginning; @@ -3761,16 +3762,11 @@ static void clear_element_at(sint32 x, sint32 y, rct_tile_element **elementPtr) viewport_interaction_remove_park_entrance(element, x, y); break; case TILE_ELEMENT_TYPE_WALL: - gGameCommandErrorTitle = STR_CANT_REMOVE_THIS; - game_do_command( - x, - GAME_COMMAND_FLAG_APPLY, - y, - tile_element_get_direction(element) | (element->base_height << 8), - GAME_COMMAND_REMOVE_WALL, - 0, - 0 - ); + { + TileCoordsXYZD wallLocation = { x >> 5, y >> 5, element->base_height, element->GetDirection() }; + auto wallRemoveAction = WallRemoveAction(wallLocation); + GameActions::Execute(&wallRemoveAction); + } break; case TILE_ELEMENT_TYPE_LARGE_SCENERY: gGameCommandErrorTitle = STR_CANT_REMOVE_THIS; diff --git a/src/openrct2/world/Map.h b/src/openrct2/world/Map.h index 853fd4b3d2..ad4617d2d3 100644 --- a/src/openrct2/world/Map.h +++ b/src/openrct2/world/Map.h @@ -199,7 +199,6 @@ void game_command_smooth_land(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx void game_command_raise_water(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp); void game_command_lower_water(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp); void game_command_set_water_height(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp); -void game_command_remove_wall(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp); void game_command_place_banner(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp); void game_command_place_scenery(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp); void game_command_place_wall(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp); diff --git a/src/openrct2/world/Scenery.cpp b/src/openrct2/world/Scenery.cpp index 572eda9071..18f452c3ce 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" @@ -30,6 +31,7 @@ #include "Park.h" #include "Scenery.h" #include "SmallScenery.h" +#include "Wall.h" uint8 gWindowSceneryActiveTabIndex; uint16 gWindowSceneryTabSelections[20]; @@ -242,16 +244,14 @@ 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; - game_do_command( - x, - 105 | (gSceneryTileElementType << 8), - y, - gSceneryGhostWallRotation |(z << 8), - GAME_COMMAND_REMOVE_WALL, - 0, - 0); + + TileCoordsXYZD wallLocation = { x >> 5, y >> 5, z, gSceneryGhostWallRotation }; + auto wallRemoveAction = WallRemoveAction(wallLocation); + wallRemoveAction.SetFlags(GAME_COMMAND_FLAG_APPLY | GAME_COMMAND_FLAG_GHOST | GAME_COMMAND_FLAG_PATH_SCENERY); + wallRemoveAction.Execute(); } if (gSceneryGhostType & SCENERY_ENTRY_FLAG_3){ diff --git a/src/openrct2/world/Wall.cpp b/src/openrct2/world/Wall.cpp index 0cc756c653..73d9243506 100644 --- a/src/openrct2/world/Wall.cpp +++ b/src/openrct2/world/Wall.cpp @@ -577,67 +577,6 @@ static money32 WallPlace(uint8 wallType, } } -static rct_tile_element * GetFirstWallElementAt(sint32 x, sint32 y, uint8 baseZ, uint8 direction, bool isGhost) -{ - rct_tile_element * tileElement = map_get_first_element_at(x / 32, y / 32); - do - { - if (tileElement->GetType() != TILE_ELEMENT_TYPE_WALL) continue; - if (tileElement->base_height != baseZ) continue; - if ((tile_element_get_direction(tileElement)) != direction) continue; - if (tile_element_is_ghost(tileElement) != isGhost) continue; - return tileElement; - } - while (!tile_element_is_last_for_tile(tileElement++)); - return nullptr; -} - -static money32 WallRemove(sint16 x, sint16 y, uint8 baseHeight, uint8 direction, uint8 flags) -{ - if (!map_is_location_valid(x, y)) - { - return MONEY32_UNDEFINED; - } - - gCommandExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING; - bool isGhost = (flags & GAME_COMMAND_FLAG_GHOST) != 0; - if (!isGhost && - game_is_paused() && - !gCheatsBuildInPauseMode) - { - gGameCommandErrorText = STR_CONSTRUCTION_NOT_POSSIBLE_WHILE_GAME_IS_PAUSED; - return MONEY32_UNDEFINED; - } - - if (!isGhost && - !(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && - !gCheatsSandboxMode && - !map_is_location_owned(x, y, baseHeight * 8)) - { - return MONEY32_UNDEFINED; - } - - rct_tile_element * wallElement = GetFirstWallElementAt(x, y, baseHeight, direction, isGhost); - if (!(flags & GAME_COMMAND_FLAG_APPLY) || (wallElement == nullptr)) - { - return 0; - } - - if (gGameCommandNestLevel == 1 && !isGhost) - { - LocationXYZ16 coord; - coord.x = x + 16; - coord.y = y + 16; - coord.z = tile_element_height(coord.x, coord.y); - network_set_player_last_action_coord(network_get_player_index(game_command_playerid), coord); - } - - tile_element_remove_banner_entry(wallElement); - map_invalidate_tile_zoom1(x, y, wallElement->base_height * 8, (wallElement->base_height * 8) + 72); - tile_element_remove(wallElement); - return 0; -} - static money32 WallSetColour(sint16 x, sint16 y, uint8 baseHeight, @@ -851,27 +790,6 @@ money32 wall_place(sint32 type, return ebx; } -/** - * - * rct2: 0x006E5597 - */ -void game_command_remove_wall(sint32 * eax, - sint32 * ebx, - sint32 * ecx, - sint32 * edx, - [[maybe_unused]] sint32 * esi, - [[maybe_unused]] sint32 * edi, - [[maybe_unused]] sint32 * ebp) -{ - *ebx = WallRemove( - *eax & 0xFFFF, - *ecx & 0xFFFF, - (*edx >> 8) & 0xFF, - *edx & 0xFF, - *ebx & 0xFF - ); -} - /** * * rct2: 0x006E56B5 diff --git a/src/openrct2/world/Wall.h b/src/openrct2/world/Wall.h index b7896a2a55..ce9f9e9fec 100644 --- a/src/openrct2/world/Wall.h +++ b/src/openrct2/world/Wall.h @@ -35,3 +35,4 @@ void wall_set_tertiary_colour(rct_tile_element * tileElement, colour_t colour); uint8 wall_get_animation_frame(const rct_tile_element * fenceElement); void wall_set_animation_frame(rct_tile_element * wallElement, uint8 frameNum); +money32 wall_remove(sint16 x, sint16 y, uint8 baseHeight, uint8 direction, uint8 flags);