OpenRCT2/src/openrct2/world/TileInspector.cpp

1074 lines
41 KiB
C++
Raw Normal View History

/*****************************************************************************
* 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.
*****************************************************************************/
2018-06-22 23:17:03 +02:00
#include "TileInspector.h"
2017-11-23 00:42:12 +01:00
#include "../Context.h"
2017-11-30 18:17:06 +01:00
#include "../Game.h"
#include "../actions/GameAction.h"
2019-05-18 10:23:33 +02:00
#include "../common.h"
#include "../core/Guard.hpp"
2018-01-06 01:05:16 +01:00
#include "../interface/Window.h"
#include "../localisation/Localisation.h"
2018-06-22 23:17:03 +02:00
#include "../ride/Station.h"
2017-10-17 13:51:47 +02:00
#include "../ride/Track.h"
2017-11-23 00:42:12 +01:00
#include "../windows/Intent.h"
#include "../windows/tile_inspector.h"
2018-06-22 23:17:03 +02:00
#include "Banner.h"
2018-01-11 10:59:26 +01:00
#include "Footpath.h"
#include "LargeScenery.h"
2018-01-03 14:56:08 +01:00
#include "Map.h"
2018-06-22 23:17:03 +02:00
#include "Park.h"
#include "Scenery.h"
2018-05-01 16:33:16 +02:00
#include "Surface.h"
using namespace OpenRCT2;
uint32_t windowTileInspectorTileX;
uint32_t windowTileInspectorTileY;
int32_t windowTileInspectorElementCount = 0;
int32_t windowTileInspectorSelectedIndex;
2017-11-23 00:42:12 +01:00
2019-05-18 10:23:33 +02:00
static bool map_swap_elements_at(CoordsXY loc, int16_t first, int16_t second)
{
2019-05-18 10:23:33 +02:00
TileElement* const firstElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, first);
TileElement* const secondElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, second);
2017-11-20 11:37:15 +01:00
if (firstElement == nullptr)
{
log_error("First element is out of range for the tile");
return false;
}
2017-11-20 11:37:15 +01:00
if (secondElement == nullptr)
{
log_error("Second element is out of range for the tile");
return false;
}
2017-11-20 11:37:15 +01:00
if (firstElement == secondElement)
{
log_error("Can't swap the element with itself");
return false;
}
// Swap their memory
2018-11-01 13:53:50 +01:00
TileElement temp = *firstElement;
2018-06-22 23:17:03 +02:00
*firstElement = *secondElement;
*secondElement = temp;
// Swap the 'last map element for tile' flag if either one of them was last
if ((firstElement)->IsLastForTile() || (secondElement)->IsLastForTile())
{
2017-10-31 12:57:40 +01:00
firstElement->flags ^= TILE_ELEMENT_FLAG_LAST_TILE;
secondElement->flags ^= TILE_ELEMENT_FLAG_LAST_TILE;
}
return true;
}
/**
* Inserts a corrupt element under a given element on a given tile
* @param x The x coordinate of the tile
* @param y The y coordinate of the tile
* @param elementIndex The nth element on this tile
* Returns 0 on success, MONEY_UNDEFINED otherwise.
*/
2019-05-18 10:23:33 +02:00
GameActionResult::Ptr tile_inspector_insert_corrupt_at(CoordsXY loc, int16_t elementIndex, bool isExecuting)
{
// Make sure there is enough space for the new element
if (!map_check_free_elements_and_reorganise(1))
return std::make_unique<GameActionResult>(GA_ERROR::NO_FREE_ELEMENTS, STR_NONE);
if (isExecuting)
{
// Create new corrupt element
2019-05-18 10:23:33 +02:00
TileElement* corruptElement = tile_element_insert(
loc.x / 32, loc.y / 32, -1, 0); // Ugly hack: -1 guarantees this to be placed first
2017-11-20 11:37:15 +01:00
if (corruptElement == nullptr)
{
log_warning("Failed to insert corrupt element.");
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_NONE);
}
corruptElement->SetType(TILE_ELEMENT_TYPE_CORRUPT);
// Set the base height to be the same as the selected element
2019-05-18 10:23:33 +02:00
TileElement* const selectedElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex + 1);
2017-11-20 11:37:15 +01:00
if (!selectedElement)
{
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_NONE);
}
corruptElement->base_height = corruptElement->clearance_height = selectedElement->base_height;
// Move the corrupt element up until the selected list item is reached
// this way it's placed under the selected element, even when there are multiple elements with the same base height
for (int16_t i = 0; i < elementIndex; i++)
{
2019-05-18 10:23:33 +02:00
if (!map_swap_elements_at(loc, i, i + 1))
2017-11-20 11:37:15 +01:00
{
// don't return error here, we've already inserted an element
// and moved it as far as we could, the only sensible thing left
// to do is to invalidate the window.
break;
}
}
2019-05-18 10:23:33 +02:00
map_invalidate_tile_full(loc.x, loc.y);
// Update the tile inspector's list for everyone who has the tile selected
2018-06-22 23:17:03 +02:00
rct_window* const tileInspectorWindow = window_find_by_class(WC_TILE_INSPECTOR);
2019-05-18 10:23:33 +02:00
if (tileInspectorWindow != nullptr && (uint32_t)(loc.x / 32) == windowTileInspectorTileX
&& (uint32_t)(loc.y / 32) == windowTileInspectorTileY)
{
windowTileInspectorElementCount++;
// Keep other elements (that are not being hidden) selected
if (windowTileInspectorSelectedIndex > elementIndex)
{
windowTileInspectorSelectedIndex++;
}
window_invalidate(tileInspectorWindow);
}
}
// Nothing went wrong
return std::make_unique<GameActionResult>();
}
2017-01-23 17:46:36 +01:00
/**
* Forcefully removes an element for a given tile
* @param x The x coordinate of the tile
* @param y The y coordinate of the tile
* @param elementIndex The nth element on this tile
*/
2019-05-18 10:23:33 +02:00
GameActionResult::Ptr tile_inspector_remove_element_at(CoordsXY loc, int16_t elementIndex, bool isExecuting)
{
if (isExecuting)
{
// Forcefully remove the element
2019-05-18 10:23:33 +02:00
TileElement* const tileElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex);
2017-11-20 11:37:15 +01:00
if (!tileElement)
{
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_NONE);
}
2017-10-31 14:03:45 +01:00
tile_element_remove(tileElement);
2019-05-18 10:23:33 +02:00
map_invalidate_tile_full(loc.x, loc.y);
// Update the window
2018-06-22 23:17:03 +02:00
rct_window* const tileInspectorWindow = window_find_by_class(WC_TILE_INSPECTOR);
2019-05-18 10:23:33 +02:00
if (tileInspectorWindow != nullptr && (uint32_t)(loc.x / 32) == windowTileInspectorTileX
&& (uint32_t)(loc.y / 32) == windowTileInspectorTileY)
{
windowTileInspectorElementCount--;
if (windowTileInspectorSelectedIndex > elementIndex)
{
windowTileInspectorSelectedIndex--;
}
else if (windowTileInspectorSelectedIndex == elementIndex)
{
windowTileInspectorSelectedIndex = -1;
}
window_invalidate(tileInspectorWindow);
}
}
return std::make_unique<GameActionResult>();
}
2019-05-18 10:23:33 +02:00
GameActionResult::Ptr tile_inspector_swap_elements_at(CoordsXY loc, int16_t first, int16_t second, bool isExecuting)
{
if (isExecuting)
{
2019-05-18 10:23:33 +02:00
if (!map_swap_elements_at(loc, first, second))
2017-11-20 11:37:15 +01:00
{
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_NONE);
}
2019-05-18 10:23:33 +02:00
map_invalidate_tile_full(loc.x, loc.y);
// Update the window
2018-06-22 23:17:03 +02:00
rct_window* const tileInspectorWindow = window_find_by_class(WC_TILE_INSPECTOR);
2019-05-18 10:23:33 +02:00
if (tileInspectorWindow != nullptr && (uint32_t)(loc.x / 32) == windowTileInspectorTileX
&& (uint32_t)(loc.y / 32) == windowTileInspectorTileY)
{
// If one of them was selected, update selected list item
if (windowTileInspectorSelectedIndex == first)
windowTileInspectorSelectedIndex = second;
else if (windowTileInspectorSelectedIndex == second)
windowTileInspectorSelectedIndex = first;
window_invalidate(tileInspectorWindow);
}
}
return std::make_unique<GameActionResult>();
}
2017-01-23 23:38:02 +01:00
2019-05-18 10:23:33 +02:00
GameActionResult::Ptr tile_inspector_rotate_element_at(CoordsXY loc, int32_t elementIndex, bool isExecuting)
2017-01-23 23:38:02 +01:00
{
if (isExecuting)
{
uint8_t newRotation, pathEdges, pathCorners;
2019-05-18 10:23:33 +02:00
TileElement* const tileElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex);
2017-11-20 11:37:15 +01:00
if (!tileElement)
{
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_NONE);
}
switch (tileElement->GetType())
{
2018-06-22 23:17:03 +02:00
case TILE_ELEMENT_TYPE_PATH:
2018-09-16 16:17:35 +02:00
if (tileElement->AsPath()->IsSloped())
2018-06-22 23:17:03 +02:00
{
newRotation = (tileElement->AsPath()->GetSlopeDirection() + 1) & TILE_ELEMENT_DIRECTION_MASK;
tileElement->AsPath()->SetSlopeDirection(newRotation);
2018-06-22 23:17:03 +02:00
}
pathEdges = tileElement->AsPath()->GetEdges();
pathCorners = tileElement->AsPath()->GetCorners();
tileElement->AsPath()->SetEdges((pathEdges << 1) | (pathEdges >> 3));
tileElement->AsPath()->SetCorners((pathCorners << 1) | (pathCorners >> 3));
2018-06-22 23:17:03 +02:00
break;
case TILE_ELEMENT_TYPE_ENTRANCE:
{
2018-06-22 23:17:03 +02:00
// Update element rotation
newRotation = tileElement->GetDirectionWithOffset(1);
tileElement->SetDirection(newRotation);
2018-06-22 23:17:03 +02:00
// Update ride's known entrance/exit rotation
2018-09-26 12:30:27 +02:00
Ride* ride = get_ride(tileElement->AsEntrance()->GetRideIndex());
uint8_t stationIndex = tileElement->AsEntrance()->GetStationIndex();
2018-06-22 23:17:03 +02:00
auto entrance = ride_get_entrance_location(ride, stationIndex);
auto exit = ride_get_exit_location(ride, stationIndex);
2018-09-26 12:13:44 +02:00
uint8_t entranceType = tileElement->AsEntrance()->GetEntranceType();
2018-06-22 23:17:03 +02:00
uint8_t z = tileElement->base_height;
// Make sure this is the correct entrance or exit
2019-05-18 10:23:33 +02:00
if (entranceType == ENTRANCE_TYPE_RIDE_ENTRANCE && entrance.x == loc.x / 32 && entrance.y == loc.y / 32
&& entrance.z == z)
2018-06-22 23:17:03 +02:00
{
ride_set_entrance_location(ride, stationIndex, { entrance.x, entrance.y, entrance.z, newRotation });
}
2019-05-18 10:23:33 +02:00
else if (entranceType == ENTRANCE_TYPE_RIDE_EXIT && exit.x == loc.x / 32 && exit.y == loc.y / 32 && exit.z == z)
2018-06-22 23:17:03 +02:00
{
ride_set_exit_location(ride, stationIndex, { exit.x, exit.y, exit.z, newRotation });
}
break;
}
2018-06-22 23:17:03 +02:00
case TILE_ELEMENT_TYPE_TRACK:
case TILE_ELEMENT_TYPE_SMALL_SCENERY:
case TILE_ELEMENT_TYPE_WALL:
newRotation = tileElement->GetDirectionWithOffset(1);
tileElement->SetDirection(newRotation);
2018-06-22 23:17:03 +02:00
break;
case TILE_ELEMENT_TYPE_BANNER:
{
2018-09-26 14:52:16 +02:00
uint8_t unblockedEdges = tileElement->AsBanner()->GetAllowedEdges();
2018-06-22 23:17:03 +02:00
unblockedEdges = (unblockedEdges << 1 | unblockedEdges >> 3) & 0xF;
2018-09-26 14:52:16 +02:00
tileElement->AsBanner()->SetAllowedEdges(unblockedEdges);
tileElement->AsBanner()->SetPosition((tileElement->AsBanner()->GetPosition() + 1) & 3);
2018-06-22 23:17:03 +02:00
break;
}
}
2019-05-18 10:23:33 +02:00
map_invalidate_tile_full(loc.x, loc.y);
2019-05-18 10:23:33 +02:00
if ((uint32_t)(loc.x / 32) == windowTileInspectorTileX && (uint32_t)(loc.y / 32) == windowTileInspectorTileY)
{
window_invalidate_by_class(WC_TILE_INSPECTOR);
}
}
return std::make_unique<GameActionResult>();
}
2019-05-18 10:23:33 +02:00
GameActionResult::Ptr tile_inspector_paste_element_at(CoordsXY loc, TileElement element, bool isExecuting)
{
// Make sure there is enough space for the new element
if (!map_check_free_elements_and_reorganise(1))
{
return std::make_unique<GameActionResult>(GA_ERROR::NO_FREE_ELEMENTS, STR_NONE);
}
if (isExecuting)
{
// Check if the element to be pasted refers to a banner index
BannerIndex bannerIndex = tile_element_get_banner_index(&element);
2018-03-10 00:57:45 +01:00
if (bannerIndex != BANNER_INDEX_NULL)
{
// The element to be pasted refers to a banner index - make a copy of it
BannerIndex newBannerIndex = create_new_banner(GAME_COMMAND_FLAG_APPLY);
if (newBannerIndex == BANNER_INDEX_NULL)
{
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_NONE);
}
2019-07-26 18:24:19 +02:00
auto& newBanner = *GetBanner(newBannerIndex);
newBanner = *GetBanner(bannerIndex);
2019-07-25 23:31:49 +02:00
newBanner.position = TileCoordsXY(loc);
// Use the new banner index
2018-03-09 19:16:43 +01:00
tile_element_set_banner_index(&element, newBannerIndex);
}
2019-05-18 10:23:33 +02:00
TileElement* const pastedElement = tile_element_insert(loc.x / 32, loc.y / 32, element.base_height, 0);
bool lastForTile = pastedElement->IsLastForTile();
2018-06-22 23:17:03 +02:00
*pastedElement = element;
2017-10-31 12:57:40 +01:00
pastedElement->flags &= ~TILE_ELEMENT_FLAG_LAST_TILE;
if (lastForTile)
{
2017-10-31 12:57:40 +01:00
pastedElement->flags |= TILE_ELEMENT_FLAG_LAST_TILE;
}
2019-05-18 10:23:33 +02:00
map_invalidate_tile_full(loc.x, loc.y);
2018-06-22 23:17:03 +02:00
rct_window* const tileInspectorWindow = window_find_by_class(WC_TILE_INSPECTOR);
2019-05-18 10:23:33 +02:00
if (tileInspectorWindow != nullptr && (uint32_t)(loc.x / 32) == windowTileInspectorTileX
&& (uint32_t)(loc.y / 32) == windowTileInspectorTileY)
{
windowTileInspectorElementCount++;
// Select new element if there was none selected already
2019-05-18 10:23:33 +02:00
int16_t newIndex = (int16_t)(pastedElement - map_get_first_element_at(loc.x / 32, loc.y / 32));
if (windowTileInspectorSelectedIndex == -1)
windowTileInspectorSelectedIndex = newIndex;
else if (windowTileInspectorSelectedIndex >= newIndex)
windowTileInspectorSelectedIndex++;
window_invalidate(tileInspectorWindow);
}
}
return std::make_unique<GameActionResult>();
2017-01-23 23:38:02 +01:00
}
2017-01-25 13:42:04 +01:00
2019-05-18 10:23:33 +02:00
GameActionResult::Ptr tile_inspector_sort_elements_at(CoordsXY loc, bool isExecuting)
2017-01-25 13:42:04 +01:00
{
if (isExecuting)
{
2019-05-18 10:23:33 +02:00
const TileElement* const firstElement = map_get_first_element_at(loc.x / 32, loc.y / 32);
// Count elements on tile
2018-06-22 23:17:03 +02:00
int32_t numElement = 0;
2018-11-01 13:53:50 +01:00
const TileElement* elementIterator = firstElement;
do
{
numElement++;
} while (!(elementIterator++)->IsLastForTile());
// Bubble sort
for (int32_t loopStart = 1; loopStart < numElement; loopStart++)
{
2018-06-22 23:17:03 +02:00
int32_t currentId = loopStart;
2018-11-01 13:53:50 +01:00
const TileElement* currentElement = firstElement + currentId;
const TileElement* otherElement = currentElement - 1;
// While current element's base height is lower, or (when their baseheight is the same) the other map element's
// clearance height is lower...
2018-06-22 23:17:03 +02:00
while (currentId > 0
&& (otherElement->base_height > currentElement->base_height
|| (otherElement->base_height == currentElement->base_height
&& otherElement->clearance_height > currentElement->clearance_height)))
{
2019-05-18 10:23:33 +02:00
if (!map_swap_elements_at(loc, currentId - 1, currentId))
2017-11-20 11:37:15 +01:00
{
// don't return error here, we've already ran some actions
// and moved things as far as we could, the only sensible
// thing left to do is to invalidate the window.
loopStart = numElement;
break;
}
currentId--;
currentElement--;
otherElement--;
}
}
2019-05-18 10:23:33 +02:00
map_invalidate_tile_full(loc.x, loc.y);
// Deselect tile for clients who had it selected
2018-06-22 23:17:03 +02:00
rct_window* const tileInspectorWindow = window_find_by_class(WC_TILE_INSPECTOR);
2019-05-18 10:23:33 +02:00
if (tileInspectorWindow != nullptr && (uint32_t)(loc.x / 32) == windowTileInspectorTileX
&& (uint32_t)(loc.y / 32) == windowTileInspectorTileY)
{
windowTileInspectorSelectedIndex = -1;
window_invalidate(tileInspectorWindow);
}
}
return std::make_unique<GameActionResult>();
2017-01-25 13:42:04 +01:00
}
2017-01-25 14:22:33 +01:00
2019-05-18 10:23:33 +02:00
GameActionResult::Ptr tile_inspector_any_base_height_offset(
CoordsXY loc, int16_t elementIndex, int8_t heightOffset, bool isExecuting)
2017-01-25 14:22:33 +01:00
{
2019-05-18 10:23:33 +02:00
TileElement* const tileElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex);
if (tileElement == nullptr)
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_NONE);
2018-06-22 23:17:03 +02:00
int16_t newBaseHeight = (int16_t)tileElement->base_height + heightOffset;
int16_t newClearanceHeight = (int16_t)tileElement->clearance_height + heightOffset;
if (newBaseHeight < 0 || newBaseHeight > 0xff || newClearanceHeight < 0 || newClearanceHeight > 0xff)
{
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_NONE);
}
if (isExecuting)
{
if (tileElement->GetType() == TILE_ELEMENT_TYPE_ENTRANCE)
{
2018-09-26 12:13:44 +02:00
uint8_t entranceType = tileElement->AsEntrance()->GetEntranceType();
if (entranceType != ENTRANCE_TYPE_PARK_ENTRANCE)
{
// Update the ride's known entrance or exit height
2018-09-26 12:30:27 +02:00
Ride* ride = get_ride(tileElement->AsEntrance()->GetRideIndex());
uint8_t entranceIndex = tileElement->AsEntrance()->GetStationIndex();
2018-06-22 23:17:03 +02:00
auto entrance = ride_get_entrance_location(ride, entranceIndex);
auto exit = ride_get_exit_location(ride, entranceIndex);
uint8_t z = tileElement->base_height;
// Make sure this is the correct entrance or exit
2019-05-18 10:23:33 +02:00
if (entranceType == ENTRANCE_TYPE_RIDE_ENTRANCE && entrance.x == loc.x / 32 && entrance.y == loc.y / 32
&& entrance.z == z)
ride_set_entrance_location(
ride, entranceIndex, { entrance.x, entrance.y, z + heightOffset, entrance.direction });
2019-05-18 10:23:33 +02:00
else if (entranceType == ENTRANCE_TYPE_RIDE_EXIT && exit.x == loc.x / 32 && exit.y == loc.y / 32 && exit.z == z)
2018-06-22 23:17:03 +02:00
ride_set_exit_location(ride, entranceIndex, { exit.x, exit.y, z + heightOffset, exit.direction });
}
}
2017-10-31 14:03:45 +01:00
tileElement->base_height += heightOffset;
tileElement->clearance_height += heightOffset;
2019-05-18 10:23:33 +02:00
map_invalidate_tile_full(loc.x, loc.y);
2018-06-22 23:17:03 +02:00
rct_window* const tileInspectorWindow = window_find_by_class(WC_TILE_INSPECTOR);
2019-05-18 10:23:33 +02:00
if (tileInspectorWindow != nullptr && (uint32_t)(loc.x / 32) == windowTileInspectorTileX
&& (uint32_t)(loc.y / 32) == windowTileInspectorTileY)
{
window_invalidate(tileInspectorWindow);
}
}
return std::make_unique<GameActionResult>();
2017-01-25 14:22:33 +01:00
}
2017-01-27 13:30:09 +01:00
2019-05-18 10:23:33 +02:00
GameActionResult::Ptr tile_inspector_surface_show_park_fences(CoordsXY loc, bool showFences, bool isExecuting)
2017-01-27 13:30:09 +01:00
{
2019-05-18 10:23:33 +02:00
TileElement* const surfaceelement = map_get_surface_element_at(loc);
2017-01-27 13:30:09 +01:00
// No surface element on tile
2017-11-20 11:37:15 +01:00
if (surfaceelement == nullptr)
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_NONE);
2017-01-27 13:30:09 +01:00
if (isExecuting)
{
if (!showFences)
2018-09-14 14:54:12 +02:00
surfaceelement->AsSurface()->SetParkFences(0);
else
2019-05-18 10:23:33 +02:00
update_park_fences(loc);
2017-01-27 13:30:09 +01:00
2019-05-18 10:23:33 +02:00
map_invalidate_tile_full(loc.x, loc.y);
2017-01-27 14:19:23 +01:00
2018-06-22 23:17:03 +02:00
rct_window* const tileInspectorWindow = window_find_by_class(WC_TILE_INSPECTOR);
2019-05-18 10:23:33 +02:00
if (tileInspectorWindow != nullptr && (uint32_t)(loc.x / 32) == windowTileInspectorTileX
&& (uint32_t)(loc.y / 32) == windowTileInspectorTileY)
{
window_invalidate(tileInspectorWindow);
}
}
2017-01-27 13:30:09 +01:00
return std::make_unique<GameActionResult>();
2017-01-27 13:30:09 +01:00
}
2017-01-27 14:02:17 +01:00
2019-05-18 10:23:33 +02:00
GameActionResult::Ptr tile_inspector_surface_toggle_corner(CoordsXY loc, int32_t cornerIndex, bool isExecuting)
2017-01-27 14:02:17 +01:00
{
2019-05-18 10:23:33 +02:00
TileElement* const surfaceElement = map_get_surface_element_at(loc);
// No surface element on tile
2017-11-20 11:37:15 +01:00
if (surfaceElement == nullptr)
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_NONE);
if (isExecuting)
{
2018-09-14 14:54:12 +02:00
const uint8_t originalSlope = surfaceElement->AsSurface()->GetSlope();
2018-06-22 23:17:03 +02:00
const bool diagonal = (originalSlope & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT) >> 4;
uint8_t newSlope = surfaceElement->AsSurface()->GetSlope() ^ (1 << cornerIndex);
surfaceElement->AsSurface()->SetSlope(newSlope);
2018-09-14 14:54:12 +02:00
if (surfaceElement->AsSurface()->GetSlope() & TILE_ELEMENT_SLOPE_ALL_CORNERS_UP)
{
surfaceElement->clearance_height = surfaceElement->base_height + 2;
}
else
{
surfaceElement->clearance_height = surfaceElement->base_height;
}
// All corners are raised
2018-09-14 14:54:12 +02:00
if ((surfaceElement->AsSurface()->GetSlope() & TILE_ELEMENT_SLOPE_ALL_CORNERS_UP) == TILE_ELEMENT_SLOPE_ALL_CORNERS_UP)
{
2018-09-14 14:54:12 +02:00
uint8_t slope = TILE_ELEMENT_SLOPE_FLAT;
if (diagonal)
{
switch (originalSlope & TILE_ELEMENT_SLOPE_ALL_CORNERS_UP)
{
2018-06-22 23:17:03 +02:00
case TILE_ELEMENT_SLOPE_S_CORNER_DN:
2018-09-14 14:54:12 +02:00
slope |= TILE_ELEMENT_SLOPE_N_CORNER_UP;
2018-06-22 23:17:03 +02:00
break;
case TILE_ELEMENT_SLOPE_W_CORNER_DN:
2018-09-14 14:54:12 +02:00
slope |= TILE_ELEMENT_SLOPE_E_CORNER_UP;
2018-06-22 23:17:03 +02:00
break;
case TILE_ELEMENT_SLOPE_N_CORNER_DN:
2018-09-14 14:54:12 +02:00
slope |= TILE_ELEMENT_SLOPE_S_CORNER_UP;
2018-06-22 23:17:03 +02:00
break;
case TILE_ELEMENT_SLOPE_E_CORNER_DN:
2018-09-14 14:54:12 +02:00
slope |= TILE_ELEMENT_SLOPE_W_CORNER_UP;
2018-06-22 23:17:03 +02:00
break;
}
}
2018-09-14 14:54:12 +02:00
surfaceElement->AsSurface()->SetSlope(slope);
// Update base and clearance heights
surfaceElement->base_height += 2;
surfaceElement->clearance_height = surfaceElement->base_height + (diagonal ? 2 : 0);
}
2019-05-18 10:23:33 +02:00
map_invalidate_tile_full(loc.x, loc.y);
2018-06-22 23:17:03 +02:00
rct_window* const tileInspectorWindow = window_find_by_class(WC_TILE_INSPECTOR);
2019-05-18 10:23:33 +02:00
if (tileInspectorWindow != nullptr && (uint32_t)(loc.x / 32) == windowTileInspectorTileX
&& (uint32_t)(loc.y / 32) == windowTileInspectorTileY)
{
window_invalidate(tileInspectorWindow);
}
}
return std::make_unique<GameActionResult>();
2017-01-27 14:19:23 +01:00
}
2019-05-18 10:23:33 +02:00
GameActionResult::Ptr tile_inspector_surface_toggle_diagonal(CoordsXY loc, bool isExecuting)
2017-01-27 14:19:23 +01:00
{
2019-05-18 10:23:33 +02:00
TileElement* const surfaceElement = map_get_surface_element_at(loc);
// No surface element on tile
2017-11-20 11:37:15 +01:00
if (surfaceElement == nullptr)
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_NONE);
if (isExecuting)
{
uint8_t newSlope = surfaceElement->AsSurface()->GetSlope() ^ TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT;
surfaceElement->AsSurface()->SetSlope(newSlope);
2018-09-14 14:54:12 +02:00
if (surfaceElement->AsSurface()->GetSlope() & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)
{
surfaceElement->clearance_height = surfaceElement->base_height + 4;
}
2018-09-14 14:54:12 +02:00
else if (surfaceElement->AsSurface()->GetSlope() & TILE_ELEMENT_SLOPE_ALL_CORNERS_UP)
{
surfaceElement->clearance_height = surfaceElement->base_height + 2;
}
else
{
surfaceElement->clearance_height = surfaceElement->base_height;
}
2019-05-18 10:23:33 +02:00
map_invalidate_tile_full(loc.x, loc.y);
2018-06-22 23:17:03 +02:00
rct_window* const tileInspectorWindow = window_find_by_class(WC_TILE_INSPECTOR);
2019-05-18 10:23:33 +02:00
if (tileInspectorWindow != nullptr && (uint32_t)(loc.x / 32) == windowTileInspectorTileX
&& (uint32_t)(loc.y / 32) == windowTileInspectorTileY)
{
window_invalidate(tileInspectorWindow);
}
}
return std::make_unique<GameActionResult>();
2017-01-27 14:02:17 +01:00
}
2017-01-27 19:12:25 +01:00
2019-05-18 10:23:33 +02:00
GameActionResult::Ptr tile_inspector_path_set_sloped(CoordsXY loc, int32_t elementIndex, bool sloped, bool isExecuting)
2017-02-06 14:51:45 +01:00
{
2019-05-18 10:23:33 +02:00
TileElement* const pathElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex);
if (pathElement == nullptr || pathElement->GetType() != TILE_ELEMENT_TYPE_PATH)
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_NONE);
if (isExecuting)
{
pathElement->AsPath()->SetSloped(sloped);
2019-05-18 10:23:33 +02:00
map_invalidate_tile_full(loc.x, loc.y);
2018-06-22 23:17:03 +02:00
rct_window* const tileInspectorWindow = window_find_by_class(WC_TILE_INSPECTOR);
2019-05-18 10:23:33 +02:00
if (tileInspectorWindow != nullptr && (uint32_t)(loc.x / 32) == windowTileInspectorTileX
&& (uint32_t)(loc.y / 32) == windowTileInspectorTileY)
{
window_invalidate(tileInspectorWindow);
}
}
return std::make_unique<GameActionResult>();
2017-02-06 14:51:45 +01:00
}
2019-05-18 10:23:33 +02:00
GameActionResult::Ptr tile_inspector_path_set_broken(CoordsXY loc, int32_t elementIndex, bool broken, bool isExecuting)
{
2019-05-18 10:23:33 +02:00
TileElement* const pathElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex);
if (pathElement == nullptr || pathElement->GetType() != TILE_ELEMENT_TYPE_PATH)
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_NONE);
if (isExecuting)
{
pathElement->AsPath()->SetIsBroken(broken);
2019-05-18 10:23:33 +02:00
map_invalidate_tile_full(loc.x, loc.y);
rct_window* const tileInspectorWindow = window_find_by_class(WC_TILE_INSPECTOR);
2019-05-18 10:23:33 +02:00
if (tileInspectorWindow != nullptr && (uint32_t)(loc.x / 32) == windowTileInspectorTileX
&& (uint32_t)(loc.y / 32) == windowTileInspectorTileY)
{
window_invalidate(tileInspectorWindow);
}
}
return std::make_unique<GameActionResult>();
}
2019-05-18 10:23:33 +02:00
GameActionResult::Ptr tile_inspector_path_toggle_edge(CoordsXY loc, int32_t elementIndex, int32_t edgeIndex, bool isExecuting)
2017-01-27 19:12:25 +01:00
{
2019-05-18 10:23:33 +02:00
TileElement* const pathElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex);
2017-02-12 23:32:00 +01:00
if (pathElement == nullptr || pathElement->GetType() != TILE_ELEMENT_TYPE_PATH)
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_NONE);
2017-01-27 19:12:25 +01:00
if (isExecuting)
{
uint8_t newEdges = pathElement->AsPath()->GetEdgesAndCorners() ^ (1 << edgeIndex);
pathElement->AsPath()->SetEdgesAndCorners(newEdges);
2017-01-27 19:12:25 +01:00
2019-05-18 10:23:33 +02:00
map_invalidate_tile_full(loc.x, loc.y);
2017-01-27 19:12:25 +01:00
2018-06-22 23:17:03 +02:00
rct_window* const tileInspectorWindow = window_find_by_class(WC_TILE_INSPECTOR);
2019-05-18 10:23:33 +02:00
if (tileInspectorWindow != nullptr && (uint32_t)(loc.x / 32) == windowTileInspectorTileX
&& (uint32_t)(loc.y / 32) == windowTileInspectorTileY)
{
window_invalidate(tileInspectorWindow);
}
}
2017-01-27 19:12:25 +01:00
return std::make_unique<GameActionResult>();
2017-01-27 19:12:25 +01:00
}
2017-02-02 20:06:27 +01:00
2019-05-18 10:23:33 +02:00
GameActionResult::Ptr tile_inspector_entrance_make_usable(CoordsXY loc, int32_t elementIndex, bool isExecuting)
{
2019-05-18 10:23:33 +02:00
TileElement* const entranceElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex);
if (entranceElement == nullptr || entranceElement->GetType() != TILE_ELEMENT_TYPE_ENTRANCE)
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_NONE);
2018-09-26 12:30:27 +02:00
Ride* ride = get_ride(entranceElement->AsEntrance()->GetRideIndex());
if (ride == nullptr)
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_NONE);
if (isExecuting)
{
uint8_t stationIndex = entranceElement->AsEntrance()->GetStationIndex();
2018-09-26 12:13:44 +02:00
switch (entranceElement->AsEntrance()->GetEntranceType())
{
2018-06-22 23:17:03 +02:00
case ENTRANCE_TYPE_RIDE_ENTRANCE:
ride_set_entrance_location(
2019-05-18 10:23:33 +02:00
ride, stationIndex,
{ loc.x / 32, loc.y / 32, entranceElement->base_height, (uint8_t)entranceElement->GetDirection() });
2018-06-22 23:17:03 +02:00
break;
case ENTRANCE_TYPE_RIDE_EXIT:
ride_set_exit_location(
2019-05-18 10:23:33 +02:00
ride, stationIndex,
{ loc.x / 32, loc.y / 32, entranceElement->base_height, (uint8_t)entranceElement->GetDirection() });
2018-06-22 23:17:03 +02:00
break;
}
2018-06-22 23:17:03 +02:00
rct_window* const tileInspectorWindow = window_find_by_class(WC_TILE_INSPECTOR);
2019-05-18 10:23:33 +02:00
if (tileInspectorWindow != nullptr && (uint32_t)(loc.x / 32) == windowTileInspectorTileX
&& (uint32_t)(loc.y / 32) == windowTileInspectorTileY)
{
window_invalidate(tileInspectorWindow);
}
}
return std::make_unique<GameActionResult>();
}
2019-05-18 10:23:33 +02:00
GameActionResult::Ptr tile_inspector_wall_set_slope(CoordsXY loc, int32_t elementIndex, int32_t slopeValue, bool isExecuting)
2017-02-02 20:06:27 +01:00
{
2019-05-18 10:23:33 +02:00
TileElement* const wallElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex);
2017-02-02 20:06:27 +01:00
if (wallElement == nullptr || wallElement->GetType() != TILE_ELEMENT_TYPE_WALL)
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_NONE);
2017-02-02 20:06:27 +01:00
if (isExecuting)
{
// Set new slope value
wallElement->AsWall()->SetSlope(slopeValue);
2017-02-02 20:06:27 +01:00
2019-05-18 10:23:33 +02:00
map_invalidate_tile_full(loc.x, loc.y);
2017-02-02 20:06:27 +01:00
2018-06-22 23:17:03 +02:00
rct_window* const tileInspectorWindow = window_find_by_class(WC_TILE_INSPECTOR);
2019-05-18 10:23:33 +02:00
if (tileInspectorWindow != nullptr && (uint32_t)(loc.x / 32) == windowTileInspectorTileX
&& (uint32_t)(loc.y / 32) == windowTileInspectorTileY)
{
window_invalidate(tileInspectorWindow);
}
}
2017-02-02 20:06:27 +01:00
return std::make_unique<GameActionResult>();
2017-02-02 20:06:27 +01:00
}
// Changes the height of all track elements that belong to the same track piece
// Broxzier: Copied from track_remove and stripped of unneeded code, but I think this should be smaller
2019-05-18 10:23:33 +02:00
GameActionResult::Ptr tile_inspector_track_base_height_offset(
CoordsXY loc, int32_t elementIndex, int8_t offset, bool isExecuting)
{
2019-05-18 10:23:33 +02:00
TileElement* const trackElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex);
if (offset == 0)
return std::make_unique<GameActionResult>();
if (trackElement == nullptr || trackElement->GetType() != TILE_ELEMENT_TYPE_TRACK)
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_NONE);
if (isExecuting)
{
uint8_t type = trackElement->AsTrack()->GetTrackType();
2019-05-18 10:23:33 +02:00
int16_t originX = loc.x;
int16_t originY = loc.y;
2018-06-22 23:17:03 +02:00
int16_t originZ = trackElement->base_height * 8;
uint8_t rotation = trackElement->GetDirection();
2019-01-12 11:11:55 +01:00
ride_id_t rideIndex = trackElement->AsTrack()->GetRideIndex();
2018-06-22 23:17:03 +02:00
Ride* ride = get_ride(rideIndex);
const rct_preview_track* trackBlock = get_track_def_from_ride(ride, type);
trackBlock += trackElement->AsTrack()->GetSequenceIndex();
uint8_t originDirection = trackElement->GetDirection();
CoordsXY offsets = { trackBlock->x, trackBlock->y };
CoordsXY coords = { originX, originY };
coords += offsets.Rotate(direction_reverse(originDirection));
originX = (int16_t)coords.x;
originY = (int16_t)coords.y;
originZ -= trackBlock->z;
trackBlock = get_track_def_from_ride(ride, type);
for (; trackBlock->index != 255; trackBlock++)
{
CoordsXY elem = { originX, originY };
int16_t elemZ = originZ;
offsets.x = trackBlock->x;
offsets.y = trackBlock->y;
elem += offsets.Rotate(originDirection);
elemZ += trackBlock->z;
map_invalidate_tile_full(elem.x, elem.y);
2018-06-22 23:17:03 +02:00
bool found = false;
TileElement* tileElement = map_get_first_element_at(elem.x >> 5, elem.y >> 5);
do
{
2017-10-31 14:03:45 +01:00
if (tileElement->base_height != elemZ / 8)
continue;
if (tileElement->GetType() != TILE_ELEMENT_TYPE_TRACK)
continue;
if (tileElement->GetDirection() != rotation)
continue;
if (tileElement->AsTrack()->GetSequenceIndex() != trackBlock->index)
continue;
if (tileElement->AsTrack()->GetTrackType() != type)
continue;
found = true;
break;
} while (!(tileElement++)->IsLastForTile());
if (!found)
{
log_error("Track map element part not found!");
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_NONE);
}
// track_remove returns here on failure, not sure when this would ever be hit. Only thing I can think of is for when
// you decrease the map size.
openrct2_assert(map_get_surface_element_at(elem) != nullptr, "No surface at %d,%d", elem.x >> 5, elem.y >> 5);
// Keep?
2019-01-18 11:46:18 +01:00
// invalidate_test_results(ride);
2017-10-31 14:03:45 +01:00
tileElement->base_height += offset;
tileElement->clearance_height += offset;
}
}
// TODO: Only invalidate when one of the affected tiles is selected
window_invalidate_by_class(WC_TILE_INSPECTOR);
return std::make_unique<GameActionResult>();
}
// Sets chainlift, optionally for an entire track block
// Broxzier: Basically a copy of the above function, with just two different lines... should probably be combined somehow
GameActionResult::Ptr tile_inspector_track_set_chain(
2019-05-18 10:23:33 +02:00
CoordsXY loc, int32_t elementIndex, bool entireTrackBlock, bool setChain, bool isExecuting)
{
2019-05-18 10:23:33 +02:00
TileElement* const trackElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex);
if (trackElement == nullptr || trackElement->GetType() != TILE_ELEMENT_TYPE_TRACK)
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_NONE);
if (isExecuting)
{
if (!entireTrackBlock)
{
// Set chain for only the selected piece
2018-09-18 13:01:09 +02:00
if (trackElement->AsTrack()->HasChain() != setChain)
{
2018-09-18 13:01:09 +02:00
trackElement->AsTrack()->SetHasChain(setChain);
}
return std::make_unique<GameActionResult>();
}
uint8_t type = trackElement->AsTrack()->GetTrackType();
2019-05-18 10:23:33 +02:00
int16_t originX = loc.x;
int16_t originY = loc.y;
2018-06-22 23:17:03 +02:00
int16_t originZ = trackElement->base_height * 8;
uint8_t rotation = trackElement->GetDirection();
2019-01-12 11:11:55 +01:00
ride_id_t rideIndex = trackElement->AsTrack()->GetRideIndex();
2018-06-22 23:17:03 +02:00
Ride* ride = get_ride(rideIndex);
const rct_preview_track* trackBlock = get_track_def_from_ride(ride, type);
trackBlock += trackElement->AsTrack()->GetSequenceIndex();
uint8_t originDirection = trackElement->GetDirection();
CoordsXY offsets = { trackBlock->x, trackBlock->y };
CoordsXY coords = { originX, originY };
coords += offsets.Rotate(direction_reverse(originDirection));
originX = (int16_t)coords.x;
originY = (int16_t)coords.y;
originZ -= trackBlock->z;
trackBlock = get_track_def_from_ride(ride, type);
for (; trackBlock->index != 255; trackBlock++)
{
CoordsXY elem = { originX, originY };
int16_t elemZ = originZ;
offsets.x = trackBlock->x;
offsets.y = trackBlock->y;
elem += offsets.Rotate(originDirection);
elemZ += trackBlock->z;
map_invalidate_tile_full(elem.x, elem.y);
2018-06-22 23:17:03 +02:00
bool found = false;
TileElement* tileElement = map_get_first_element_at(elem.x >> 5, elem.y >> 5);
do
{
2017-10-31 14:03:45 +01:00
if (tileElement->base_height != elemZ / 8)
continue;
if (tileElement->GetType() != TILE_ELEMENT_TYPE_TRACK)
continue;
if (tileElement->GetDirection() != rotation)
continue;
if (tileElement->AsTrack()->GetSequenceIndex() != trackBlock->index)
continue;
if (tileElement->AsTrack()->GetTrackType() != type)
continue;
found = true;
break;
} while (!(tileElement++)->IsLastForTile());
if (!found)
{
log_error("Track map element part not found!");
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_NONE);
}
// track_remove returns here on failure, not sure when this would ever be hit. Only thing I can think of is for when
// you decrease the map size.
openrct2_assert(map_get_surface_element_at(elem) != nullptr, "No surface at %d,%d", elem.x >> 5, elem.y >> 5);
// Keep?
2019-01-18 11:46:18 +01:00
// invalidate_test_results(ride);
2018-09-18 13:01:09 +02:00
if (tileElement->AsTrack()->HasChain() != setChain)
{
tileElement->AsTrack()->SetHasChain(setChain);
}
}
}
// TODO: Only invalidate when one of the affected tiles is selected
window_invalidate_by_class(WC_TILE_INSPECTOR);
return std::make_unique<GameActionResult>();
}
2019-05-18 10:23:33 +02:00
GameActionResult::Ptr tile_inspector_track_set_block_brake(
CoordsXY loc, int32_t elementIndex, bool blockBrake, bool isExecuting)
{
2019-05-18 10:23:33 +02:00
TileElement* const trackElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex);
if (trackElement == nullptr || trackElement->GetType() != TILE_ELEMENT_TYPE_TRACK)
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_NONE);
if (isExecuting)
{
trackElement->AsTrack()->SetBlockBrakeClosed(blockBrake);
2019-05-18 10:23:33 +02:00
map_invalidate_tile_full(loc.x, loc.y);
rct_window* const tileInspectorWindow = window_find_by_class(WC_TILE_INSPECTOR);
2019-05-18 10:23:33 +02:00
if (tileInspectorWindow != nullptr && (uint32_t)(loc.x / 32) == windowTileInspectorTileX
&& (uint32_t)(loc.y / 32) == windowTileInspectorTileY)
{
window_invalidate(tileInspectorWindow);
}
}
return std::make_unique<GameActionResult>();
}
GameActionResult::Ptr tile_inspector_track_set_indestructible(
2019-05-18 10:23:33 +02:00
CoordsXY loc, int32_t elementIndex, bool isIndestructible, bool isExecuting)
{
2019-05-18 10:23:33 +02:00
TileElement* const trackElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex);
if (trackElement == nullptr || trackElement->GetType() != TILE_ELEMENT_TYPE_TRACK)
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_NONE);
if (isExecuting)
{
trackElement->AsTrack()->SetIsIndestructible(isIndestructible);
2019-05-18 10:23:33 +02:00
map_invalidate_tile_full(loc.x, loc.y);
rct_window* const tileInspectorWindow = window_find_by_class(WC_TILE_INSPECTOR);
2019-05-18 10:23:33 +02:00
if (tileInspectorWindow != nullptr && (uint32_t)(loc.x / 32) == windowTileInspectorTileX
&& (uint32_t)(loc.y / 32) == windowTileInspectorTileY)
{
window_invalidate(tileInspectorWindow);
}
}
return std::make_unique<GameActionResult>();
}
GameActionResult::Ptr tile_inspector_scenery_set_quarter_location(
2019-05-18 10:23:33 +02:00
CoordsXY loc, int32_t elementIndex, int32_t quarterIndex, bool isExecuting)
{
2019-05-18 10:23:33 +02:00
TileElement* const tileElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex);
if (tileElement == nullptr || tileElement->GetType() != TILE_ELEMENT_TYPE_SMALL_SCENERY)
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_NONE);
if (isExecuting)
{
// Set quadrant index
tileElement->AsSmallScenery()->SetSceneryQuadrant(quarterIndex);
// Update collision
2017-10-31 14:03:45 +01:00
tileElement->flags &= 0xF0;
tileElement->flags |= 1 << ((quarterIndex + 2) & 3);
2019-05-18 10:23:33 +02:00
map_invalidate_tile_full(loc.x, loc.y);
if ((uint32_t)(loc.x / 32) == windowTileInspectorTileX && (uint32_t)(loc.y / 32) == windowTileInspectorTileY)
{
window_invalidate_by_class(WC_TILE_INSPECTOR);
}
}
return std::make_unique<GameActionResult>();
}
GameActionResult::Ptr tile_inspector_scenery_set_quarter_collision(
2019-05-18 10:23:33 +02:00
CoordsXY loc, int32_t elementIndex, int32_t quarterIndex, bool isExecuting)
{
2019-05-18 10:23:33 +02:00
TileElement* const tileElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex);
if (tileElement == nullptr || tileElement->GetType() != TILE_ELEMENT_TYPE_SMALL_SCENERY)
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_NONE);
if (isExecuting)
{
2017-10-31 14:03:45 +01:00
tileElement->flags ^= 1 << quarterIndex;
2019-05-18 10:23:33 +02:00
map_invalidate_tile_full(loc.x, loc.y);
if ((uint32_t)(loc.x / 32) == windowTileInspectorTileX && (uint32_t)(loc.y / 32) == windowTileInspectorTileY)
{
window_invalidate_by_class(WC_TILE_INSPECTOR);
}
}
return std::make_unique<GameActionResult>();
}
2017-02-07 15:39:07 +01:00
2019-05-18 10:23:33 +02:00
GameActionResult::Ptr tile_inspector_banner_toggle_blocking_edge(
CoordsXY loc, int32_t elementIndex, int32_t edgeIndex, bool isExecuting)
{
2019-05-18 10:23:33 +02:00
TileElement* const bannerElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex);
2018-09-27 22:51:56 +02:00
if (bannerElement == nullptr || bannerElement->GetType() != TILE_ELEMENT_TYPE_BANNER)
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_NONE);
if (isExecuting)
{
2018-09-27 22:51:56 +02:00
uint8_t edges = bannerElement->AsBanner()->GetAllowedEdges();
2018-09-26 14:52:16 +02:00
edges ^= (1 << edgeIndex);
2018-09-27 22:51:56 +02:00
bannerElement->AsBanner()->SetAllowedEdges(edges);
2019-05-18 10:23:33 +02:00
if ((uint32_t)(loc.x / 32) == windowTileInspectorTileX && (uint32_t)(loc.y / 32) == windowTileInspectorTileY)
{
window_invalidate_by_class(WC_TILE_INSPECTOR);
}
}
return std::make_unique<GameActionResult>();
}
2019-05-18 10:23:33 +02:00
GameActionResult::Ptr tile_inspector_corrupt_clamp(CoordsXY loc, int32_t elementIndex, bool isExecuting)
2017-02-07 15:39:07 +01:00
{
2019-05-18 10:23:33 +02:00
TileElement* const corruptElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex);
if (corruptElement == nullptr || corruptElement->GetType() != TILE_ELEMENT_TYPE_CORRUPT)
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_NONE);
if (corruptElement->IsLastForTile())
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_NONE);
if (isExecuting)
{
2018-11-01 13:53:50 +01:00
TileElement* const nextElement = corruptElement + 1;
corruptElement->base_height = corruptElement->clearance_height = nextElement->base_height;
2019-05-18 10:23:33 +02:00
if ((uint32_t)(loc.x / 32) == windowTileInspectorTileX && (uint32_t)(loc.y / 32) == windowTileInspectorTileY)
{
window_invalidate_by_class(WC_TILE_INSPECTOR);
}
}
return std::make_unique<GameActionResult>();
2017-02-07 15:39:07 +01:00
}