2020-12-09 23:39:10 -07:00
|
|
|
/*****************************************************************************
|
2024-12-31 20:30:04 +01:00
|
|
|
* Copyright (c) 2014-2025 OpenRCT2 developers
|
2020-12-09 23:39:10 -07:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "FootpathAdditionRemoveAction.h"
|
|
|
|
|
|
|
|
|
|
#include "../Cheats.h"
|
2024-07-09 16:23:31 +02:00
|
|
|
#include "../Diagnostic.h"
|
2024-03-03 21:44:15 +00:00
|
|
|
#include "../GameState.h"
|
2020-12-09 23:39:10 -07:00
|
|
|
#include "../OpenRCT2.h"
|
|
|
|
|
#include "../core/MemoryStream.h"
|
|
|
|
|
#include "../localisation/StringIds.h"
|
|
|
|
|
#include "../management/Finance.h"
|
|
|
|
|
#include "../world/Footpath.h"
|
|
|
|
|
#include "../world/Location.hpp"
|
2025-09-04 21:57:41 +02:00
|
|
|
#include "../world/Map.h"
|
2020-12-09 23:39:10 -07:00
|
|
|
#include "../world/Park.h"
|
2024-10-15 22:02:31 +02:00
|
|
|
#include "../world/tile_element/PathElement.h"
|
2020-12-09 23:39:10 -07:00
|
|
|
|
2025-08-26 14:48:16 +02:00
|
|
|
namespace OpenRCT2::GameActions
|
2020-12-13 12:10:26 -03:00
|
|
|
{
|
2025-08-26 14:48:16 +02:00
|
|
|
FootpathAdditionRemoveAction::FootpathAdditionRemoveAction(const CoordsXYZ& loc)
|
|
|
|
|
: _loc(loc)
|
2020-12-09 23:39:10 -07:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-26 14:48:16 +02:00
|
|
|
void FootpathAdditionRemoveAction::AcceptParameters(GameActionParameterVisitor& visitor)
|
2020-12-09 23:39:10 -07:00
|
|
|
{
|
2025-08-26 14:48:16 +02:00
|
|
|
visitor.Visit(_loc);
|
2020-12-09 23:39:10 -07:00
|
|
|
}
|
|
|
|
|
|
2025-08-26 14:48:16 +02:00
|
|
|
uint16_t FootpathAdditionRemoveAction::GetActionFlags() const
|
2020-12-09 23:39:10 -07:00
|
|
|
{
|
2025-08-26 14:48:16 +02:00
|
|
|
return GameAction::GetActionFlags();
|
2020-12-09 23:39:10 -07:00
|
|
|
}
|
|
|
|
|
|
2025-08-26 14:48:16 +02:00
|
|
|
void FootpathAdditionRemoveAction::Serialise(DataSerialiser& stream)
|
2020-12-09 23:39:10 -07:00
|
|
|
{
|
2025-08-26 14:48:16 +02:00
|
|
|
GameAction::Serialise(stream);
|
|
|
|
|
|
|
|
|
|
stream << DS_TAG(_loc);
|
2020-12-09 23:39:10 -07:00
|
|
|
}
|
|
|
|
|
|
2025-09-08 16:21:29 +02:00
|
|
|
Result FootpathAdditionRemoveAction::Query(GameState_t& gameState) const
|
2020-12-09 23:39:10 -07:00
|
|
|
{
|
2025-08-26 14:48:16 +02:00
|
|
|
if (!LocationValid(_loc))
|
|
|
|
|
{
|
2025-12-12 11:41:49 +01:00
|
|
|
return Result(Status::invalidParameters, STR_CANT_REMOVE_THIS, STR_OFF_EDGE_OF_MAP);
|
2025-08-26 14:48:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!(gLegacyScene == LegacyScene::scenarioEditor || getGameState().cheats.sandboxMode) && !MapIsLocationOwned(_loc))
|
|
|
|
|
{
|
2025-12-12 11:41:49 +01:00
|
|
|
return Result(Status::disallowed, STR_CANT_REMOVE_THIS, STR_LAND_NOT_OWNED_BY_PARK);
|
2025-08-26 14:48:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_loc.z < kFootpathMinHeight)
|
|
|
|
|
{
|
2025-12-12 11:41:49 +01:00
|
|
|
return Result(Status::invalidParameters, STR_CANT_REMOVE_THIS, STR_TOO_LOW);
|
2025-08-26 14:48:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_loc.z > kFootpathMaxHeight)
|
|
|
|
|
{
|
2025-12-12 11:41:49 +01:00
|
|
|
return Result(Status::invalidParameters, STR_CANT_REMOVE_THIS, STR_TOO_HIGH);
|
2025-08-26 14:48:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto tileElement = MapGetFootpathElement(_loc);
|
|
|
|
|
if (tileElement == nullptr)
|
|
|
|
|
{
|
|
|
|
|
LOG_ERROR("No path element at x = %d, y = %d, z = %d", _loc.x, _loc.y, _loc.z);
|
2025-12-12 11:41:49 +01:00
|
|
|
return Result(Status::invalidParameters, STR_CANT_REMOVE_THIS, STR_ERR_PATH_ELEMENT_NOT_FOUND);
|
2025-08-26 14:48:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto pathElement = tileElement->AsPath();
|
|
|
|
|
if (pathElement == nullptr)
|
|
|
|
|
{
|
|
|
|
|
LOG_ERROR("No path element at x = %d, y = %d, z = %d", _loc.x, _loc.y, _loc.z);
|
2025-12-12 11:41:49 +01:00
|
|
|
return Result(Status::invalidParameters, STR_CANT_REMOVE_THIS, STR_ERR_PATH_ELEMENT_NOT_FOUND);
|
2025-08-26 14:48:16 +02:00
|
|
|
}
|
|
|
|
|
|
2025-12-11 00:12:21 +01:00
|
|
|
if (!pathElement->AdditionIsGhost() && (GetFlags().has(CommandFlag::ghost)))
|
2025-08-26 14:48:16 +02:00
|
|
|
{
|
|
|
|
|
LOG_WARNING("Tried to remove non ghost during ghost removal.");
|
2025-12-12 11:41:49 +01:00
|
|
|
return Result(Status::disallowed, STR_CANT_REMOVE_THIS, kStringIdNone);
|
2025-08-26 14:48:16 +02:00
|
|
|
}
|
|
|
|
|
auto res = Result();
|
|
|
|
|
res.Position = _loc;
|
|
|
|
|
res.Cost = 0.00_GBP;
|
|
|
|
|
return res;
|
2020-12-09 23:39:10 -07:00
|
|
|
}
|
|
|
|
|
|
2025-09-08 16:21:29 +02:00
|
|
|
Result FootpathAdditionRemoveAction::Execute(GameState_t& gameState) const
|
2020-12-09 23:39:10 -07:00
|
|
|
{
|
2025-08-26 14:48:16 +02:00
|
|
|
auto* pathElement = MapGetFootpathElement(_loc);
|
2025-12-11 00:12:21 +01:00
|
|
|
if (!(GetFlags().has(CommandFlag::ghost)))
|
2025-08-26 14:48:16 +02:00
|
|
|
{
|
|
|
|
|
FootpathInterruptPeeps(_loc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pathElement == nullptr)
|
|
|
|
|
{
|
|
|
|
|
LOG_ERROR("No path element at x = %d, y = %d, z = %d", _loc.x, _loc.y, _loc.z);
|
2025-12-12 11:41:49 +01:00
|
|
|
return Result(Status::invalidParameters, STR_CANT_REMOVE_THIS, STR_ERR_PATH_ELEMENT_NOT_FOUND);
|
2025-08-26 14:48:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pathElement->SetAddition(0);
|
|
|
|
|
MapInvalidateTileFull(_loc);
|
|
|
|
|
|
|
|
|
|
auto res = Result();
|
|
|
|
|
res.Position = _loc;
|
|
|
|
|
res.Cost = 0.00_GBP;
|
|
|
|
|
return res;
|
2020-12-09 23:39:10 -07:00
|
|
|
}
|
2025-08-26 14:48:16 +02:00
|
|
|
} // namespace OpenRCT2::GameActions
|