From 8ef5afe2ced8acf65eb290aaf7212303c31ae342 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sat, 6 Apr 2019 19:36:44 +0100 Subject: [PATCH] Implement wall set colour action --- src/openrct2-ui/windows/TopToolbar.cpp | 11 +- src/openrct2/Game.cpp | 6 +- src/openrct2/Game.h | 2 +- .../actions/GameActionRegistration.cpp | 2 + src/openrct2/actions/WallSetColourAction.hpp | 161 ++++++++++++++++++ src/openrct2/world/Map.h | 2 - src/openrct2/world/Wall.cpp | 56 ------ 7 files changed, 173 insertions(+), 67 deletions(-) create mode 100644 src/openrct2/actions/WallSetColourAction.hpp diff --git a/src/openrct2-ui/windows/TopToolbar.cpp b/src/openrct2-ui/windows/TopToolbar.cpp index d36b17e501..2dff172b21 100644 --- a/src/openrct2-ui/windows/TopToolbar.cpp +++ b/src/openrct2-ui/windows/TopToolbar.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -1026,11 +1027,11 @@ static void repaint_scenery_tool_down(int16_t x, int16_t y, rct_widgetindex widg if (!(scenery_entry->wall.flags & (WALL_SCENERY_HAS_PRIMARY_COLOUR | WALL_SCENERY_HAS_GLASS))) return; - gGameCommandErrorTitle = STR_CANT_REPAINT_THIS; - game_do_command( - grid_x, 1 | (gWindowSceneryPrimaryColour << 8), grid_y, - tile_element->GetDirection() | (tile_element->base_height << 8), GAME_COMMAND_SET_WALL_COLOUR, 0, - gWindowScenerySecondaryColour | (gWindowSceneryTertiaryColour << 8)); + auto repaintScenery = WallSetColourAction( + { grid_x, grid_y, tile_element->base_height * 8, tile_element->GetDirection() }, gWindowSceneryPrimaryColour, + gWindowScenerySecondaryColour, gWindowSceneryTertiaryColour); + + GameActions::Execute(&repaintScenery); break; } case VIEWPORT_INTERACTION_ITEM_LARGE_SCENERY: diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index 80ce37e882..ff27d0acda 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -644,8 +644,8 @@ void game_log_multiplayer_command(int command, const int* eax, const int* ebx, c network_append_server_log(log_msg); } else if ( - command == GAME_COMMAND_SET_WALL_COLOUR || command == GAME_COMMAND_SET_LARGE_SCENERY_COLOUR - || command == GAME_COMMAND_SET_BANNER_COLOUR || command == GAME_COMMAND_SET_BANNER_STYLE) + command == GAME_COMMAND_SET_LARGE_SCENERY_COLOUR || command == GAME_COMMAND_SET_BANNER_COLOUR + || command == GAME_COMMAND_SET_BANNER_STYLE) { // Log editing scenery char* args[1] = { @@ -1292,7 +1292,7 @@ GAME_COMMAND_POINTER* new_game_command_table[GAME_COMMAND_COUNT] = { game_command_place_banner, game_command_remove_banner, nullptr, - game_command_set_wall_colour, + nullptr, game_command_set_large_scenery_colour, game_command_set_banner_colour, game_command_set_land_ownership, diff --git a/src/openrct2/Game.h b/src/openrct2/Game.h index ed90316eb2..c64e65b6ab 100644 --- a/src/openrct2/Game.h +++ b/src/openrct2/Game.h @@ -72,7 +72,7 @@ enum GAME_COMMAND GAME_COMMAND_PLACE_BANNER, GAME_COMMAND_REMOVE_BANNER, GAME_COMMAND_SET_SCENERY_COLOUR, // GA - GAME_COMMAND_SET_WALL_COLOUR, + GAME_COMMAND_SET_WALL_COLOUR, // GA GAME_COMMAND_SET_LARGE_SCENERY_COLOUR, GAME_COMMAND_SET_BANNER_COLOUR, GAME_COMMAND_SET_LAND_OWNERSHIP, diff --git a/src/openrct2/actions/GameActionRegistration.cpp b/src/openrct2/actions/GameActionRegistration.cpp index ccb7ea18c8..a3f8bb8b59 100644 --- a/src/openrct2/actions/GameActionRegistration.cpp +++ b/src/openrct2/actions/GameActionRegistration.cpp @@ -65,6 +65,7 @@ #include "TrackSetBrakeSpeedAction.hpp" #include "WallPlaceAction.hpp" #include "WallRemoveAction.hpp" +#include "WallSetColourAction.hpp" #include "WaterLowerAction.hpp" #include "WaterRaiseAction.hpp" #include "WaterSetHeightAction.hpp" @@ -114,6 +115,7 @@ namespace GameActions Register(); Register(); Register(); + Register(); Register(); Register(); Register(); diff --git a/src/openrct2/actions/WallSetColourAction.hpp b/src/openrct2/actions/WallSetColourAction.hpp new file mode 100644 index 0000000000..0589114ac1 --- /dev/null +++ b/src/openrct2/actions/WallSetColourAction.hpp @@ -0,0 +1,161 @@ +/***************************************************************************** + * Copyright (c) 2014-2019 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#pragma once + +#include "../OpenRCT2.h" +#include "../management/Finance.h" +#include "../ride/RideGroupManager.h" +#include "../ride/Track.h" +#include "../ride/TrackData.h" +#include "../world/Banner.h" +#include "../world/LargeScenery.h" +#include "../world/MapAnimation.h" +#include "../world/Scenery.h" +#include "../world/SmallScenery.h" +#include "../world/Surface.h" +#include "GameAction.h" + +DEFINE_GAME_ACTION(WallSetColourAction, GAME_COMMAND_SET_WALL_COLOUR, GameActionResult) +{ +private: + CoordsXYZD _loc; + int32_t _primaryColour; + int32_t _secondaryColour; + int32_t _tertiaryColour; + +public: + WallSetColourAction() + { + } + + WallSetColourAction(CoordsXYZD loc, int32_t primaryColour, int32_t secondaryColour, int32_t tertiaryColour) + : _loc(loc) + , _primaryColour(primaryColour) + , _secondaryColour(secondaryColour) + , _tertiaryColour(tertiaryColour) + { + } + + uint16_t GetActionFlags() const override + { + return GameAction::GetActionFlags() | GA_FLAGS::ALLOW_WHILE_PAUSED; + } + + void Serialise(DataSerialiser & stream) override + { + GameAction::Serialise(stream); + + stream << DS_TAG(_loc) << DS_TAG(_primaryColour) << DS_TAG(_secondaryColour) << DS_TAG(_tertiaryColour); + } + + GameActionResult::Ptr Query() const override + { + auto res = MakeResult(); + res->ErrorTitle = STR_CANT_REPAINT_THIS; + res->Position.x = _loc.x + 16; + res->Position.y = _loc.y + 16; + res->Position.z = _loc.z; + + res->ExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING; + + if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !map_is_location_in_park({ _loc.x, _loc.y }) + && !gCheatsSandboxMode) + { + return MakeResult(GA_ERROR::NOT_OWNED, STR_CANT_REPAINT_THIS, STR_LAND_NOT_OWNED_BY_PARK); + } + + auto wallElement = map_get_wall_element_at(_loc.x, _loc.y, _loc.z / 8, _loc.direction); + if (wallElement == nullptr) + { + log_error( + "Could not find wall element at: x = %d, y = %d, z = %d, direction = %u", _loc.x, _loc.y, _loc.z, + _loc.direction); + return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_CANT_REPAINT_THIS); + } + + if ((GetFlags() & GAME_COMMAND_FLAG_GHOST) && !(wallElement->IsGhost())) + { + return res; + } + + rct_scenery_entry* sceneryEntry = wallElement->GetEntry(); + if (sceneryEntry == nullptr) + { + log_error("Could not find wall object"); + return MakeResult(GA_ERROR::UNKNOWN, STR_CANT_REPAINT_THIS); + } + + if (_primaryColour > 31) + { + log_error("Primary colour invalid: colour = %d", _primaryColour); + return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_CANT_REPAINT_THIS); + } + + if (_secondaryColour > 31) + { + log_error("Secondary colour invalid: colour = %d", _secondaryColour); + return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_CANT_REPAINT_THIS); + } + + if (sceneryEntry->wall.flags & WALL_SCENERY_HAS_TERNARY_COLOUR) + { + if (_tertiaryColour > 31) + { + log_error("Tertiary colour invalid: colour = %d", _tertiaryColour); + return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_CANT_REPAINT_THIS); + } + } + return res; + } + + GameActionResult::Ptr Execute() const override + { + auto res = MakeResult(); + res->ErrorTitle = STR_CANT_REPAINT_THIS; + res->Position.x = _loc.x + 16; + res->Position.y = _loc.y + 16; + res->Position.z = _loc.z; + res->ExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING; + + auto wallElement = map_get_wall_element_at(_loc.x, _loc.y, _loc.z / 8, _loc.direction); + if (wallElement == nullptr) + { + log_error( + "Could not find wall element at: x = %d, y = %d, z = %d, direction = %u", _loc.x, _loc.y, _loc.z, + _loc.direction); + return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_CANT_REPAINT_THIS); + } + + if ((GetFlags() & GAME_COMMAND_FLAG_GHOST) && !(wallElement->IsGhost())) + { + return res; + } + + rct_scenery_entry* sceneryEntry = wallElement->GetEntry(); + if (sceneryEntry == nullptr) + { + log_error("Could not find wall object"); + return MakeResult(GA_ERROR::UNKNOWN, STR_CANT_REPAINT_THIS); + } + + wallElement->SetPrimaryColour(_primaryColour); + wallElement->SetSecondaryColour(_secondaryColour); + + if (sceneryEntry->wall.flags & WALL_SCENERY_HAS_TERNARY_COLOUR) + { + wallElement->SetTertiaryColour(_tertiaryColour); + } + map_invalidate_tile_zoom1(_loc.x, _loc.y, _loc.z, _loc.z + 72); + + return res; + } + +private: +}; diff --git a/src/openrct2/world/Map.h b/src/openrct2/world/Map.h index 734330b4b7..d009c5677b 100644 --- a/src/openrct2/world/Map.h +++ b/src/openrct2/world/Map.h @@ -191,8 +191,6 @@ void game_command_set_land_ownership( int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp); void game_command_remove_banner( int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp); -void game_command_set_wall_colour( - int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp); void game_command_set_large_scenery_colour( int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp); void game_command_set_banner_colour( diff --git a/src/openrct2/world/Wall.cpp b/src/openrct2/world/Wall.cpp index 137c26ca9e..d238a49a10 100644 --- a/src/openrct2/world/Wall.cpp +++ b/src/openrct2/world/Wall.cpp @@ -29,49 +29,6 @@ #include "Surface.h" #include "Wall.h" -static money32 WallSetColour( - int16_t x, int16_t y, uint8_t baseHeight, uint8_t direction, uint8_t primaryColour, uint8_t secondaryColour, - uint8_t tertiaryColour, uint8_t flags) -{ - gCommandExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING; - int32_t z = baseHeight * 8; - - gCommandPosition.x = x + 16; - gCommandPosition.y = y + 16; - gCommandPosition.z = z; - - if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !map_is_location_in_park({ x, y }) && !gCheatsSandboxMode) - { - return MONEY32_UNDEFINED; - } - - auto wallElement = map_get_wall_element_at(x, y, baseHeight, direction); - if (wallElement == nullptr) - { - return 0; - } - - if ((flags & GAME_COMMAND_FLAG_GHOST) && !(wallElement->IsGhost())) - { - return 0; - } - - if (flags & GAME_COMMAND_FLAG_APPLY) - { - rct_scenery_entry* scenery_entry = wallElement->GetEntry(); - wallElement->SetPrimaryColour(primaryColour); - wallElement->SetSecondaryColour(secondaryColour); - - if (scenery_entry->wall.flags & WALL_SCENERY_HAS_TERNARY_COLOUR) - { - wallElement->SetTertiaryColour(tertiaryColour); - } - map_invalidate_tile_zoom1(x, y, z, z + 72); - } - - return 0; -} - /** * * rct2: 0x006E588E @@ -136,19 +93,6 @@ void wall_remove_intersecting_walls(int32_t x, int32_t y, int32_t z0, int32_t z1 } while (!(tileElement++)->IsLastForTile()); } -/** - * - * rct2: 0x006E56B5 - */ -void game_command_set_wall_colour( - int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, [[maybe_unused]] int32_t* esi, [[maybe_unused]] int32_t* edi, - int32_t* ebp) -{ - *ebx = WallSetColour( - *eax & 0xFFFF, *ecx & 0xFFFF, (*edx >> 8) & 0xFF, *edx & 0xFF, (*ebx >> 8) & 0xFF, *ebp & 0xFF, (*ebp >> 8) & 0xFF, - *ebx & 0xFF); -} - uint8_t WallElement::GetSlope() const { return (type & TILE_ELEMENT_QUADRANT_MASK) >> 6;