Implement FootpathRemoveAction as a GameAction (#7867)

This commit is contained in:
ζeh Matt authored and Aaron van Geffen committed 2018-08-12 10:31:00 +02:00
1 parent 8784dfbf41
commit b2005c3b9f
9 files changed
+179 -115

No files matched your search

@@ -488,7 +488,6 @@ static void viewport_interaction_remove_footpath(rct_tile_element* tileElement,
{
if (tileElement2->GetType() == TILE_ELEMENT_TYPE_PATH && tileElement2->base_height == z)
{
gGameCommandErrorTitle = STR_CANT_REMOVE_FOOTPATH_FROM_HERE;
footpath_remove(x, y, z, GAME_COMMAND_FLAG_APPLY);
break;
}
-1
View File
@@ -1030,7 +1030,6 @@ static void footpath_remove_tile_element(rct_tile_element* tileElement)
}
// Remove path
gGameCommandErrorTitle = STR_CANT_REMOVE_FOOTPATH_FROM_HERE;
footpath_remove(
gFootpathConstructFromPosition.x, gFootpathConstructFromPosition.y, tileElement->base_height, GAME_COMMAND_FLAG_APPLY);
+1 -1
View File
@@ -1406,7 +1406,7 @@ GAME_COMMAND_POINTER* new_game_command_table[GAME_COMMAND_COUNT] = {
game_command_set_water_height,
game_command_place_footpath,
game_command_place_footpath_from_track,
game_command_remove_footpath,
nullptr,
game_command_change_surface_style,
game_command_set_ride_price,
game_command_set_guest_name,
@@ -0,0 +1,144 @@
/*****************************************************************************
* Copyright (c) 2014-2018 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 "../Cheats.h"
#include "../OpenRCT2.h"
#include "../core/MemoryStream.h"
#include "../interface/Window.h"
#include "../localisation/StringIds.h"
#include "../management/Finance.h"
#include "../world/Footpath.h"
#include "../world/Location.hpp"
#include "../world/Park.h"
#include "../world/Wall.h"
#include "GameAction.h"
struct FootpathRemoveAction : public GameActionBase<GAME_COMMAND_REMOVE_PATH, GameActionResult>
{
private:
int32_t _x;
int32_t _y;
int32_t _z;
public:
FootpathRemoveAction() = default;
FootpathRemoveAction(int32_t x, int32_t y, int32_t z)
: _x(x)
, _y(y)
, _z(z)
{
}
uint16_t GetActionFlags() const override
{
return GameAction::GetActionFlags();
}
void Serialise(DataSerialiser& stream) override
{
GameAction::Serialise(stream);
stream << _x << _y << _z;
}
GameActionResult::Ptr Query() const override
{
GameActionResult::Ptr res = std::make_unique<GameActionResult>();
res->Cost = 0;
res->ExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING;
res->Position = { _x + 16, _y + 16, _z * 8 };
if (!((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || gCheatsSandboxMode) && !map_is_location_owned(_x, _y, _z * 8))
{
return MakeResult(GA_ERROR::NOT_OWNED, STR_CANT_REMOVE_FOOTPATH_FROM_HERE, STR_LAND_NOT_OWNED_BY_PARK);
}
rct_tile_element* footpathElement = GetFootpathElement();
res->Cost = GetRefundPrice(footpathElement);
return res;
}
GameActionResult::Ptr Execute() const override
{
GameActionResult::Ptr res = std::make_unique<GameActionResult>();
res->Cost = 0;
res->ExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING;
res->Position = { _x + 16, _y + 16, _z * 8 };
if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST))
{
footpath_interrupt_peeps(_x, _y, _z * 8);
footpath_remove_litter(_x, _y, _z * 8);
}
rct_tile_element* footpathElement = GetFootpathElement();
if (footpathElement != nullptr)
{
footpath_queue_chain_reset();
remove_banners_at_element(_x, _y, footpathElement);
footpath_remove_edges_at(_x, _y, footpathElement);
map_invalidate_tile_full(_x, _y);
tile_element_remove(footpathElement);
footpath_update_queue_chains();
}
res->Cost = GetRefundPrice(footpathElement);
return res;
}
private:
rct_tile_element* GetFootpathElement() const
{
bool getGhostPath = GetFlags() & GAME_COMMAND_FLAG_GHOST;
rct_tile_element* tileElement = map_get_footpath_element(_x / 32, _y / 32, _z);
rct_tile_element* footpathElement = nullptr;
if (tileElement != nullptr)
{
if (getGhostPath && tile_element_is_ghost(tileElement) == false)
{
while (!(tileElement++)->IsLastForTile())
{
if (tileElement->type != TILE_ELEMENT_TYPE_PATH && !tile_element_is_ghost(tileElement))
{
continue;
}
footpathElement = tileElement;
break;
}
}
else
{
footpathElement = tileElement;
}
}
return footpathElement;
}
money32 GetRefundPrice(rct_tile_element* footpathElement) const
{
money32 cost = -MONEY(10, 00);
bool isNotOwnedByPark = (GetFlags() & GAME_COMMAND_FLAG_5);
bool moneyDisabled = (gParkFlags & PARK_FLAGS_NO_MONEY);
bool isGhost = (footpathElement == nullptr) || (tile_element_is_ghost(footpathElement));
if (isNotOwnedByPark || moneyDisabled || isGhost)
{
cost = 0;
}
return cost;
}
};
@@ -8,6 +8,7 @@
*****************************************************************************/
#include "BannerSetNameAction.hpp"
#include "FootpathRemoveAction.hpp"
#include "GameAction.h"
#include "GuestSetNameAction.hpp"
#include "MazeSetTrackAction.hpp"
@@ -49,5 +50,6 @@ namespace GameActions
Register<ParkSetNameAction>();
Register<BannerSetNameAction>();
Register<WallRemoveAction>();
Register<FootpathRemoveAction>();
}
} // namespace GameActions
+1 -1
View File
@@ -27,7 +27,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 "4"
#define NETWORK_STREAM_VERSION "5"
#define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION
static rct_peep* _pickup_peep = nullptr;
+13 -96
View File
@@ -11,6 +11,7 @@
#include "../Context.h"
#include "../Game.h"
#include "../OpenRCT2.h"
#include "../actions/FootpathRemoveAction.hpp"
#include "../core/Guard.hpp"
#include "../core/Math.hpp"
#include "../core/Util.hpp"
@@ -30,7 +31,6 @@
#include "Sprite.h"
#include "Surface.h"
void footpath_interrupt_peeps(int32_t x, int32_t y, int32_t z);
void footpath_update_queue_entrance_banner(int32_t x, int32_t y, rct_tile_element* tileElement);
uint8_t gFootpathProvisionalFlags;
@@ -499,7 +499,7 @@ static money32 footpath_place_real(
*
* rct2: 0x006BA23E
*/
static void remove_banners_at_element(int32_t x, int32_t y, rct_tile_element* tileElement)
void remove_banners_at_element(int32_t x, int32_t y, rct_tile_element* tileElement)
{
while (!(tileElement++)->IsLastForTile())
{
@@ -514,87 +514,6 @@ static void remove_banners_at_element(int32_t x, int32_t y, rct_tile_element* ti
}
}
money32 footpath_remove_real(int32_t x, int32_t y, int32_t z, int32_t flags)
{
rct_tile_element* tileElement;
rct_tile_element* footpathElement = nullptr;
gCommandExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING;
gCommandPosition.x = x + 16;
gCommandPosition.y = y + 16;
gCommandPosition.z = z * 8;
if (!(flags & GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED) && game_is_paused() && !gCheatsBuildInPauseMode)
{
gGameCommandErrorText = STR_CONSTRUCTION_NOT_POSSIBLE_WHILE_GAME_IS_PAUSED;
return MONEY32_UNDEFINED;
}
if ((flags & GAME_COMMAND_FLAG_APPLY) && !(flags & GAME_COMMAND_FLAG_GHOST))
{
footpath_interrupt_peeps(x, y, z * 8);
footpath_remove_litter(x, y, z * 8);
}
if (!((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || gCheatsSandboxMode) && !map_is_location_owned(x, y, z * 8))
return MONEY32_UNDEFINED;
tileElement = map_get_footpath_element(x / 32, y / 32, z);
if (tileElement != nullptr && (flags & GAME_COMMAND_FLAG_APPLY))
{
if (gGameCommandNestLevel == 1 && !(flags & GAME_COMMAND_FLAG_GHOST))
{
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);
}
// If the ghost flag is present we have to make sure to only delete ghost footpaths as they may be
// at the same origin.
if ((flags & GAME_COMMAND_FLAG_GHOST) && tile_element_is_ghost(tileElement) == false)
{
while (!(tileElement++)->IsLastForTile())
{
if (tileElement->type != TILE_ELEMENT_TYPE_PATH && !tile_element_is_ghost(tileElement))
{
continue;
}
footpathElement = tileElement;
break;
}
}
else
{
footpathElement = tileElement;
}
if (footpathElement != nullptr)
{
footpath_queue_chain_reset();
remove_banners_at_element(x, y, footpathElement);
footpath_remove_edges_at(x, y, footpathElement);
map_invalidate_tile_full(x, y);
tile_element_remove(footpathElement);
footpath_update_queue_chains();
}
}
money32 cost = -MONEY(10, 00);
bool isNotOwnedByPark = (flags & GAME_COMMAND_FLAG_5);
bool moneyDisabled = (gParkFlags & PARK_FLAGS_NO_MONEY);
bool isGhost = (footpathElement == nullptr) || (tile_element_is_ghost(footpathElement));
if (isNotOwnedByPark || moneyDisabled || isGhost)
{
cost = 0;
}
return cost;
}
/**
*
* rct2: 0x006A61DE
@@ -758,17 +677,6 @@ void game_command_place_footpath_from_track(
(*ebx >> 8) & 0xF, *ebx & 0xFF);
}
/**
*
* rct2: 0x006A67C0
*/
void game_command_remove_footpath(
int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, [[maybe_unused]] int32_t* esi, [[maybe_unused]] int32_t* edi,
[[maybe_unused]] int32_t* ebp)
{
*ebx = footpath_remove_real((*eax & 0xFFFF), (*ecx & 0xFFFF), (*edx & 0xFF), (*ebx & 0xFF));
}
money32 footpath_place(int32_t type, int32_t x, int32_t y, int32_t z, int32_t slope, int32_t flags)
{
return game_do_command(x, (slope << 8) | flags, y, (type << 8) | z, GAME_COMMAND_PLACE_PATH, 0, 0);
@@ -781,9 +689,18 @@ money32 footpath_place_remove_intersecting(
x, (slope << 8) | flags, y, (type << 8) | z, GAME_COMMAND_PLACE_PATH, 0, FOOTPATH_CLEAR_DIRECTIONAL | direction);
}
void footpath_remove(int32_t x, int32_t y, int32_t z, int32_t flags)
money32 footpath_remove(int32_t x, int32_t y, int32_t z, int32_t flags)
{
game_do_command(x, flags, y, z, GAME_COMMAND_REMOVE_PATH, 0, 0);
auto action = FootpathRemoveAction(x, y, z);
action.SetFlags(flags);
if (flags & GAME_COMMAND_FLAG_APPLY)
{
auto res = GameActions::Execute(&action);
return res->Cost;
}
auto res = GameActions::Query(&action);
return res->Cost;
}
/**
+3 -2
View File
@@ -125,7 +125,7 @@ extern const LocationXY16 BinUseOffsets[4];
extern const LocationXY16 BenchUseOffsets[8];
rct_tile_element* map_get_footpath_element(int32_t x, int32_t y, int32_t z);
money32 footpath_remove_real(int32_t x, int32_t y, int32_t z, int32_t flags);
void footpath_interrupt_peeps(int32_t x, int32_t y, int32_t z);
void game_command_place_footpath(
int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp);
void game_command_place_footpath_from_track(
@@ -135,10 +135,11 @@ void game_command_remove_footpath(
money32 footpath_place(int32_t type, int32_t x, int32_t y, int32_t z, int32_t slope, int32_t flags);
money32 footpath_place_remove_intersecting(
int32_t type, int32_t x, int32_t y, int32_t z, int32_t slope, int32_t flags, int32_t direction);
void footpath_remove(int32_t x, int32_t y, int32_t z, int32_t flags);
money32 footpath_remove(int32_t x, int32_t y, int32_t z, int32_t flags);
money32 footpath_provisional_set(int32_t type, int32_t x, int32_t y, int32_t z, int32_t slope);
void footpath_provisional_remove();
void footpath_provisional_update();
void remove_banners_at_element(int32_t x, int32_t y, rct_tile_element* tileElement);
void footpath_get_coordinates_from_pos(
int32_t screenX, int32_t screenY, int32_t* x, int32_t* y, int32_t* direction, rct_tile_element** tileElement);
void footpath_bridge_get_info_from_pos(
+15 -13
View File
@@ -14,6 +14,7 @@
#include "../Game.h"
#include "../Input.h"
#include "../OpenRCT2.h"
#include "../actions/FootpathRemoveAction.hpp"
#include "../actions/WallRemoveAction.hpp"
#include "../audio/audio.h"
#include "../config/Config.h"
@@ -1073,19 +1074,20 @@ restart_from_beginning:
case TILE_ELEMENT_TYPE_PATH:
if (clear & (1 << 2))
{
int32_t eax = x * 32;
int32_t ebx = flags;
int32_t ecx = y * 32;
int32_t edx = tileElement->base_height;
int32_t edi = 0, ebp = 0;
cost = game_do_command(eax, ebx, ecx, edx, GAME_COMMAND_REMOVE_PATH, edi, ebp);
if (cost == MONEY32_UNDEFINED)
auto footpathRemoveAction = FootpathRemoveAction(x * 32, y * 32, tileElement->base_height);
footpathRemoveAction.SetFlags(flags);
auto res
= ((flags & GAME_COMMAND_FLAG_APPLY) ? footpathRemoveAction.Execute() : footpathRemoveAction.Query());
if (res->Error == GA_ERROR::OK)
{
totalCost += res->Cost;
}
else
{
return MONEY32_UNDEFINED;
}
totalCost += cost;
if (flags & 1)
if (flags & GAME_COMMAND_FLAG_APPLY)
goto restart_from_beginning;
}
break;
@@ -1104,7 +1106,7 @@ restart_from_beginning:
totalCost += cost;
if (flags & 1)
if (flags & GAME_COMMAND_FLAG_APPLY)
goto restart_from_beginning;
}
break;
@@ -1137,7 +1139,7 @@ restart_from_beginning:
totalCost += cost;
if (flags & 1)
if (flags & GAME_COMMAND_FLAG_APPLY)
goto restart_from_beginning;
}
break;