Use TileCoordsXYZD for wall locations

This commit is contained in:
Hielke Morsink 2018-05-14 12:36:45 +02:00
parent cd0530d176
commit 9f0d820b7c
7 changed files with 43 additions and 45 deletions

View File

@ -501,9 +501,9 @@ static void window_sign_small_mouseup(rct_window *w, rct_widgetindex widgetIndex
break;
case WIDX_SIGN_DEMOLISH:
{
while (1)
while (true)
{
if (tile_element_get_type(tile_element) == TILE_ELEMENT_TYPE_WALL)
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)
@ -514,12 +514,14 @@ static void window_sign_small_mouseup(rct_window *w, rct_widgetindex widgetIndex
}
tile_element++;
}
auto wallRemoveAction = WallRemoveAction(x, y, tile_element->base_height, tile_element_get_direction(tile_element));
TileCoordsXYZD wallLocation = { x >> 5, y >> 5, tile_element->base_height, tile_element->GetDirection() };
auto wallRemoveAction = WallRemoveAction(wallLocation);
GameActions::Execute(&wallRemoveAction);
}
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

@ -88,12 +88,8 @@ namespace GameActions
{
result = factory();
}
else
{
log_error("Attempting to create unregistered gameaction: %u\n", id);
}
}
Guard::ArgumentNotNull(result);
Guard::ArgumentNotNull(result, "Attempting to create unregistered gameaction: %u", id);
return std::unique_ptr<GameAction>(result);
}
@ -231,8 +227,7 @@ namespace GameActions
if (result->Error != GA_ERROR::OK &&
!(flags & GAME_COMMAND_FLAG_GHOST) &&
!(flags & GAME_COMMAND_FLAG_5) &&
result->ErrorMessage != STR_NONE)
!(flags & GAME_COMMAND_FLAG_5))
{
// Show the error box
std::copy(result->ErrorMessageArgs.begin(), result->ErrorMessageArgs.end(), gCommonFormatArgs);

View File

@ -16,31 +16,25 @@
#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 "GameAction.h"
#include "../Cheats.h"
#include "../interface/Window.h"
#include "../world/Location.hpp"
#include "../world/Wall.h"
#include "GameAction.h"
struct WallRemoveAction : public GameActionBase<GAME_COMMAND_REMOVE_WALL, GameActionResult>
{
private:
sint32 _x;
sint32 _y;
uint8 _baseHeight;
uint8 _direction;
TileCoordsXYZD _location;
public:
WallRemoveAction() {}
WallRemoveAction(sint16 x, sint16 y, uint8 baseHeight, uint8 direction) :
_x(x),
_y(y),
_baseHeight(baseHeight),
_direction(direction)
WallRemoveAction() = default;
WallRemoveAction(const TileCoordsXYZD& location)
: _location(location)
{
}
@ -53,7 +47,7 @@ public:
{
GameAction::Serialise(stream);
stream << _x << _y << _baseHeight << _direction;
stream << _location.x << _location.y << _location.z << _location.direction;
}
GameActionResult::Ptr Query() const override
@ -62,7 +56,7 @@ public:
res->Cost = 0;
res->ExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING;
if (!map_is_location_valid(_x, _y))
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);
}
@ -71,12 +65,12 @@ public:
if (!isGhost &&
!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) &&
!gCheatsSandboxMode &&
!map_is_location_owned(_x, _y, _baseHeight * 8))
!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(_x, _y, _baseHeight, _direction, isGhost);
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);
@ -94,36 +88,38 @@ public:
const bool isGhost = GetFlags() & GAME_COMMAND_FLAG_GHOST;
rct_tile_element * wallElement = GetFirstWallElementAt(_x, _y, _baseHeight, _direction, isGhost);
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 = _x + 16;
res->Position.y = _y + 16;
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(_x, _y, wallElement->base_height * 8, (wallElement->base_height * 8) + 72);
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(sint32 x, sint32 y, uint8 baseZ, uint8 direction, bool isGhost) const
rct_tile_element* GetFirstWallElementAt(const TileCoordsXYZD& location, bool isGhost) const
{
rct_tile_element * tileElement = map_get_first_element_at(x / 32, y / 32);
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 != baseZ) continue;
if (tileElement->GetDirection() != direction) continue;
if (tileElement->IsGhost() != isGhost) 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

@ -518,7 +518,8 @@ static void viewport_interaction_remove_park_wall(rct_tile_element *tileElement,
}
else
{
auto wallRemoveAction = WallRemoveAction(x, y, tileElement->base_height, tile_element_get_direction(tileElement));
TileCoordsXYZD wallLocation = { x >> 5, y >> 5, tileElement->base_height, tileElement->GetDirection() };
auto wallRemoveAction = WallRemoveAction(wallLocation);
GameActions::Execute(&wallRemoveAction);
}
}

View File

@ -865,7 +865,8 @@ track_design_place_scenery(rct_td6_scenery_element * scenery_start, sint32 origi
uint8_t direction = (rotation + scenery->flags) & TILE_ELEMENT_DIRECTION_MASK;
auto wallRemoveAction = WallRemoveAction(mapCoord.x, mapCoord.y, z, direction);
TileCoordsXYZD wallLocation = { tile.x, tile.y, z, direction };
auto wallRemoveAction = WallRemoveAction(wallLocation);
wallRemoveAction.SetFlags(flags);
GameActions::Execute(&wallRemoveAction);

View File

@ -1127,7 +1127,8 @@ restart_from_beginning:
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));
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)
@ -3762,7 +3763,8 @@ static void clear_element_at(sint32 x, sint32 y, rct_tile_element **elementPtr)
break;
case TILE_ELEMENT_TYPE_WALL:
{
auto wallRemoveAction = WallRemoveAction(x, y, element->base_height, tile_element_get_direction(element));
TileCoordsXYZD wallLocation = { x >> 5, y >> 5, element->base_height, element->GetDirection() };
auto wallRemoveAction = WallRemoveAction(wallLocation);
GameActions::Execute(&wallRemoveAction);
}
break;

View File

@ -248,7 +248,8 @@ void scenery_remove_ghost_tool_placement(){
{
gSceneryGhostType &= ~SCENERY_ENTRY_FLAG_2;
auto wallRemoveAction = WallRemoveAction(x, y, z, gSceneryGhostWallRotation);
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();
}