Merge pull request #6807 from ZehMatt/ga-removewall

Refactors GAME_COMMAND_REMOVE_WALL to a GameAction.
This commit is contained in:
Aaron van Geffen 2018-05-15 09:54:37 +02:00 committed by GitHub
commit 59e682a835
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 208 additions and 161 deletions

View File

@ -29,6 +29,7 @@
#include <openrct2/sprites.h>
#include <openrct2/world/Banner.h>
#include <openrct2/actions/SignSetNameAction.hpp>
#include <openrct2/actions/WallRemoveAction.hpp>
#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;

View File

@ -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,

View File

@ -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

View File

@ -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<GameAction>(result);
}

View File

@ -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)

View File

@ -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<SignSetNameAction>();
Register<ParkSetNameAction>();
Register<BannerSetNameAction>();
Register<WallRemoveAction>();
}
} // namespace GameActions

View File

@ -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<GAME_COMMAND_REMOVE_WALL, GameActionResult>
{
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<GameActionResult>();
res->Cost = 0;
res->ExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING;
if (!map_is_location_valid(_location.x << 5, _location.y << 5))
{
return std::make_unique<GameActionResult>(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<GameActionResult>(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<GameActionResult>(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<GameActionResult>();
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<GameActionResult>(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;
}
};

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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){

View File

@ -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

View File

@ -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);