2020-12-09 23:39:10 -07:00
|
|
|
/*****************************************************************************
|
2023-01-01 04:58:01 -06:00
|
|
|
* Copyright (c) 2014-2023 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"
|
|
|
|
|
#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"
|
|
|
|
|
|
2020-12-13 12:10:26 -03:00
|
|
|
FootpathAdditionRemoveAction::FootpathAdditionRemoveAction(const CoordsXYZ& loc)
|
|
|
|
|
: _loc(loc)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-09 23:39:10 -07:00
|
|
|
void FootpathAdditionRemoveAction::AcceptParameters(GameActionParameterVisitor& visitor)
|
|
|
|
|
{
|
|
|
|
|
visitor.Visit(_loc);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-13 12:10:26 -03:00
|
|
|
uint16_t FootpathAdditionRemoveAction::GetActionFlags() const
|
|
|
|
|
{
|
|
|
|
|
return GameAction::GetActionFlags();
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-09 23:39:10 -07:00
|
|
|
void FootpathAdditionRemoveAction::Serialise(DataSerialiser& stream)
|
|
|
|
|
{
|
|
|
|
|
GameAction::Serialise(stream);
|
|
|
|
|
|
|
|
|
|
stream << DS_TAG(_loc);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-23 23:35:08 -08:00
|
|
|
GameActions::Result FootpathAdditionRemoveAction::Query() const
|
2020-12-09 23:39:10 -07:00
|
|
|
{
|
|
|
|
|
if (!LocationValid(_loc))
|
|
|
|
|
{
|
2021-11-23 23:35:08 -08:00
|
|
|
return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_OFF_EDGE_OF_MAP);
|
2020-12-09 23:39:10 -07:00
|
|
|
}
|
|
|
|
|
|
2022-10-12 06:35:20 +01:00
|
|
|
if (!((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || gCheatsSandboxMode) && !MapIsLocationOwned(_loc))
|
2020-12-09 23:39:10 -07:00
|
|
|
{
|
2021-11-23 23:35:08 -08:00
|
|
|
return GameActions::Result(GameActions::Status::Disallowed, STR_CANT_REMOVE_THIS, STR_LAND_NOT_OWNED_BY_PARK);
|
2020-12-09 23:39:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_loc.z < FootpathMinHeight)
|
|
|
|
|
{
|
2021-11-23 23:35:08 -08:00
|
|
|
return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_TOO_LOW);
|
2020-12-09 23:39:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_loc.z > FootpathMaxHeight)
|
|
|
|
|
{
|
2021-11-23 23:35:08 -08:00
|
|
|
return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_TOO_HIGH);
|
2020-12-09 23:39:10 -07:00
|
|
|
}
|
|
|
|
|
|
2022-10-04 07:51:27 +01:00
|
|
|
auto tileElement = MapGetFootpathElement(_loc);
|
2020-12-09 23:39:10 -07:00
|
|
|
if (tileElement == nullptr)
|
|
|
|
|
{
|
|
|
|
|
log_warning("Could not find path element.");
|
2021-11-23 23:35:08 -08:00
|
|
|
return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_NONE);
|
2020-12-09 23:39:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto pathElement = tileElement->AsPath();
|
|
|
|
|
if (pathElement == nullptr)
|
|
|
|
|
{
|
|
|
|
|
log_warning("Could not find path element.");
|
2021-11-23 23:35:08 -08:00
|
|
|
return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_NONE);
|
2020-12-09 23:39:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!pathElement->AdditionIsGhost() && (GetFlags() & GAME_COMMAND_FLAG_GHOST))
|
|
|
|
|
{
|
|
|
|
|
log_warning("Tried to remove non ghost during ghost removal.");
|
2021-11-23 23:35:08 -08:00
|
|
|
return GameActions::Result(GameActions::Status::Disallowed, STR_CANT_REMOVE_THIS, STR_NONE);
|
2020-12-09 23:39:10 -07:00
|
|
|
}
|
2021-11-23 23:35:08 -08:00
|
|
|
auto res = GameActions::Result();
|
|
|
|
|
res.Position = _loc;
|
2021-02-28 20:44:47 -07:00
|
|
|
res.Cost = 0.00_GBP;
|
2020-12-09 23:39:10 -07:00
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-23 23:35:08 -08:00
|
|
|
GameActions::Result FootpathAdditionRemoveAction::Execute() const
|
2020-12-09 23:39:10 -07:00
|
|
|
{
|
2022-10-04 07:51:27 +01:00
|
|
|
auto tileElement = MapGetFootpathElement(_loc);
|
2020-12-09 23:39:10 -07:00
|
|
|
auto pathElement = tileElement->AsPath();
|
|
|
|
|
|
|
|
|
|
if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST))
|
|
|
|
|
{
|
2022-10-04 07:51:27 +01:00
|
|
|
FootpathInterruptPeeps(_loc);
|
2020-12-09 23:39:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pathElement == nullptr)
|
|
|
|
|
{
|
|
|
|
|
log_error("Could not find path element.");
|
2021-11-23 23:35:08 -08:00
|
|
|
return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_NONE);
|
2020-12-09 23:39:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pathElement->SetAddition(0);
|
2022-10-12 13:14:45 +01:00
|
|
|
MapInvalidateTileFull(_loc);
|
2020-12-09 23:39:10 -07:00
|
|
|
|
2021-11-23 23:35:08 -08:00
|
|
|
auto res = GameActions::Result();
|
|
|
|
|
res.Position = _loc;
|
2021-02-28 20:44:47 -07:00
|
|
|
res.Cost = 0.00_GBP;
|
2020-12-09 23:39:10 -07:00
|
|
|
return res;
|
|
|
|
|
}
|