forked from rosebudai/OpenRCT2-Web
Rework more game actions into GameActions namespace
This commit is contained in:
1 parent
134f4ac43e
commit
e8ef3897df
33 files changed
+1552
-1545
No files matched your search
@@ -609,7 +609,7 @@ static void ShortcutDecreaseElementHeight()
|
||||
|
||||
static void ShortcutToggleClearanceChecks()
|
||||
{
|
||||
auto cheatSetAction = CheatSetAction(
|
||||
auto cheatSetAction = GameActions::CheatSetAction(
|
||||
CheatType::DisableClearanceChecks, getGameState().cheats.disableClearanceChecks ? 0 : 1);
|
||||
GameActions::Execute(&cheatSetAction);
|
||||
}
|
||||
|
||||
@@ -649,7 +649,7 @@ namespace OpenRCT2::Ui
|
||||
{
|
||||
if (tileElement2->GetType() == TileElementType::Path && tileElement2->GetBaseZ() == z)
|
||||
{
|
||||
auto action = FootpathRemoveAction({ mapCoords, z });
|
||||
auto action = GameActions::FootpathRemoveAction({ mapCoords, z });
|
||||
GameActions::Execute(&action);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
if (bannerElement == nullptr)
|
||||
break;
|
||||
|
||||
auto bannerRemoveAction = BannerRemoveAction(
|
||||
auto bannerRemoveAction = GameActions::BannerRemoveAction(
|
||||
{ banner->position.ToCoordsXY(), bannerElement->GetBaseZ(), bannerElement->GetPosition() });
|
||||
GameActions::Execute(&bannerRemoveAction);
|
||||
break;
|
||||
@@ -214,8 +214,8 @@ namespace OpenRCT2::Ui::Windows
|
||||
case WIDX_BANNER_NO_ENTRY:
|
||||
{
|
||||
TextinputCancel();
|
||||
auto bannerSetStyle = BannerSetStyleAction(
|
||||
BannerSetStyleType::NoEntry, GetBannerIndex(), !banner->flags.has(BannerFlag::noEntry));
|
||||
auto bannerSetStyle = GameActions::BannerSetStyleAction(
|
||||
GameActions::BannerSetStyleType::NoEntry, GetBannerIndex(), !banner->flags.has(BannerFlag::noEntry));
|
||||
GameActions::Execute(&bannerSetStyle);
|
||||
break;
|
||||
}
|
||||
@@ -231,8 +231,9 @@ namespace OpenRCT2::Ui::Windows
|
||||
if (dropdownIndex == -1)
|
||||
break;
|
||||
|
||||
auto bannerSetStyle = BannerSetStyleAction(
|
||||
BannerSetStyleType::PrimaryColour, GetBannerIndex(), ColourDropDownIndexToColour(dropdownIndex));
|
||||
auto bannerSetStyle = GameActions::BannerSetStyleAction(
|
||||
GameActions::BannerSetStyleType::PrimaryColour, GetBannerIndex(),
|
||||
ColourDropDownIndexToColour(dropdownIndex));
|
||||
GameActions::Execute(&bannerSetStyle);
|
||||
break;
|
||||
}
|
||||
@@ -240,8 +241,8 @@ namespace OpenRCT2::Ui::Windows
|
||||
{
|
||||
if (dropdownIndex == -1)
|
||||
break;
|
||||
auto bannerSetStyle = BannerSetStyleAction(
|
||||
BannerSetStyleType::TextColour, GetBannerIndex(), dropdownIndex + 1);
|
||||
auto bannerSetStyle = GameActions::BannerSetStyleAction(
|
||||
GameActions::BannerSetStyleType::TextColour, GetBannerIndex(), dropdownIndex + 1);
|
||||
GameActions::Execute(&bannerSetStyle);
|
||||
break;
|
||||
}
|
||||
@@ -252,7 +253,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
{
|
||||
if (widgetIndex == WIDX_BANNER_TEXT)
|
||||
{
|
||||
auto bannerSetNameAction = BannerSetNameAction(GetBannerIndex(), std::string(text));
|
||||
auto bannerSetNameAction = GameActions::BannerSetNameAction(GetBannerIndex(), std::string(text));
|
||||
GameActions::Execute(&bannerSetNameAction);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -965,7 +965,8 @@ static StringId window_cheats_page_titles[] = {
|
||||
InvalidateWidget(WIDX_PARK_RATING_SPINNER);
|
||||
if (Park::GetForcedRating() >= 0)
|
||||
{
|
||||
auto cheatSetAction = CheatSetAction(CheatType::SetForcedParkRating, _parkRatingSpinnerValue);
|
||||
auto cheatSetAction = GameActions::CheatSetAction(
|
||||
CheatType::SetForcedParkRating, _parkRatingSpinnerValue);
|
||||
GameActions::Execute(&cheatSetAction);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1320,7 +1320,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
}
|
||||
|
||||
gFootpathConstructFromPosition.z = tileElement->GetBaseZ();
|
||||
auto action = FootpathRemoveAction(gFootpathConstructFromPosition);
|
||||
auto action = GameActions::FootpathRemoveAction(gFootpathConstructFromPosition);
|
||||
GameActions::Execute(&action);
|
||||
|
||||
// Move selection
|
||||
@@ -1814,7 +1814,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
{
|
||||
_provisionalFootpath.flags.unset(ProvisionalPathFlag::placed);
|
||||
|
||||
auto action = FootpathRemoveAction(_provisionalFootpath.position);
|
||||
auto action = GameActions::FootpathRemoveAction(_provisionalFootpath.position);
|
||||
action.SetFlags(GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_NO_SPEND | GAME_COMMAND_FLAG_GHOST);
|
||||
GameActions::Execute(&action);
|
||||
}
|
||||
|
||||
@@ -2297,7 +2297,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
auto* bannerEntry = OpenRCT2::ObjectManager::GetObjectEntry<BannerSceneryEntry>(banner->type);
|
||||
if (bannerEntry->flags & BANNER_ENTRY_FLAG_HAS_PRIMARY_COLOUR)
|
||||
{
|
||||
auto repaintScenery = BannerSetColourAction(
|
||||
auto repaintScenery = GameActions::BannerSetColourAction(
|
||||
{ info.Loc, info.Element->GetBaseZ(), info.Element->AsBanner()->GetPosition() },
|
||||
_sceneryPrimaryColour);
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ void CheatsReset()
|
||||
|
||||
void CheatsSet(CheatType cheatType, int64_t param1 /* = 0*/, int64_t param2 /* = 0*/)
|
||||
{
|
||||
auto cheatSetAction = CheatSetAction(cheatType, param1, param2);
|
||||
auto cheatSetAction = GameActions::CheatSetAction(cheatType, param1, param2);
|
||||
GameActions::Execute(&cheatSetAction);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,30 +37,28 @@ namespace OpenRCT2::GameActions
|
||||
stream << DS_TAG(_spriteIndex);
|
||||
}
|
||||
|
||||
GameActions::Result BalloonPressAction::Query() const
|
||||
Result BalloonPressAction::Query() const
|
||||
{
|
||||
auto balloon = TryGetEntity<Balloon>(_spriteIndex);
|
||||
if (balloon == nullptr)
|
||||
{
|
||||
LOG_ERROR("Balloon not found for spriteIndex %u", _spriteIndex);
|
||||
return GameActions::Result(
|
||||
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_BALLOON_NOT_FOUND);
|
||||
return Result(Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_BALLOON_NOT_FOUND);
|
||||
}
|
||||
return GameActions::Result();
|
||||
return Result();
|
||||
}
|
||||
|
||||
GameActions::Result BalloonPressAction::Execute() const
|
||||
Result BalloonPressAction::Execute() const
|
||||
{
|
||||
auto balloon = TryGetEntity<Balloon>(_spriteIndex);
|
||||
if (balloon == nullptr)
|
||||
{
|
||||
LOG_ERROR("Balloon not found for spriteIndex %u", _spriteIndex);
|
||||
return GameActions::Result(
|
||||
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_BALLOON_NOT_FOUND);
|
||||
return Result(Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_BALLOON_NOT_FOUND);
|
||||
}
|
||||
|
||||
balloon->Press();
|
||||
|
||||
return GameActions::Result();
|
||||
return Result();
|
||||
}
|
||||
} // namespace OpenRCT2::GameActions
|
||||
@@ -27,7 +27,7 @@ namespace OpenRCT2::GameActions
|
||||
uint16_t GetActionFlags() const override;
|
||||
|
||||
void Serialise(DataSerialiser& stream) override;
|
||||
OpenRCT2::GameActions::Result Query() const override;
|
||||
OpenRCT2::GameActions::Result Execute() const override;
|
||||
Result Query() const override;
|
||||
Result Execute() const override;
|
||||
};
|
||||
} // namespace OpenRCT2::GameActions
|
||||
@@ -50,9 +50,9 @@ namespace OpenRCT2::GameActions
|
||||
stream << DS_TAG(_loc) << DS_TAG(_bannerType) << DS_TAG(_primaryColour);
|
||||
}
|
||||
|
||||
GameActions::Result BannerPlaceAction::Query() const
|
||||
Result BannerPlaceAction::Query() const
|
||||
{
|
||||
auto res = GameActions::Result();
|
||||
auto res = Result();
|
||||
res.Position.x = _loc.x + 16;
|
||||
res.Position.y = _loc.y + 16;
|
||||
res.Position.z = _loc.z;
|
||||
@@ -61,51 +61,45 @@ namespace OpenRCT2::GameActions
|
||||
|
||||
if (!LocationValid(_loc))
|
||||
{
|
||||
return GameActions::Result(
|
||||
GameActions::Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_OFF_EDGE_OF_MAP);
|
||||
return Result(Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_OFF_EDGE_OF_MAP);
|
||||
}
|
||||
|
||||
if (!MapCheckCapacityAndReorganise(_loc))
|
||||
{
|
||||
LOG_ERROR("No free map elements.");
|
||||
return GameActions::Result(
|
||||
GameActions::Status::NoFreeElements, STR_CANT_POSITION_THIS_HERE, STR_TILE_ELEMENT_LIMIT_REACHED);
|
||||
return Result(Status::NoFreeElements, STR_CANT_POSITION_THIS_HERE, STR_TILE_ELEMENT_LIMIT_REACHED);
|
||||
}
|
||||
|
||||
auto pathElement = GetValidPathElement();
|
||||
|
||||
if (pathElement == nullptr)
|
||||
{
|
||||
return GameActions::Result(
|
||||
GameActions::Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_CAN_ONLY_BE_BUILT_ACROSS_PATHS);
|
||||
return Result(Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_CAN_ONLY_BE_BUILT_ACROSS_PATHS);
|
||||
}
|
||||
|
||||
if (!MapCanBuildAt(_loc))
|
||||
{
|
||||
return GameActions::Result(GameActions::Status::NotOwned, STR_CANT_POSITION_THIS_HERE, STR_LAND_NOT_OWNED_BY_PARK);
|
||||
return Result(Status::NotOwned, STR_CANT_POSITION_THIS_HERE, STR_LAND_NOT_OWNED_BY_PARK);
|
||||
}
|
||||
|
||||
auto baseHeight = _loc.z + kPathHeightStep;
|
||||
BannerElement* existingBannerElement = MapGetBannerElementAt({ _loc.x, _loc.y, baseHeight }, _loc.direction);
|
||||
if (existingBannerElement != nullptr)
|
||||
{
|
||||
return GameActions::Result(
|
||||
GameActions::Status::ItemAlreadyPlaced, STR_CANT_POSITION_THIS_HERE, STR_BANNER_SIGN_IN_THE_WAY);
|
||||
return Result(Status::ItemAlreadyPlaced, STR_CANT_POSITION_THIS_HERE, STR_BANNER_SIGN_IN_THE_WAY);
|
||||
}
|
||||
|
||||
if (HasReachedBannerLimit())
|
||||
{
|
||||
LOG_ERROR("No free banners available");
|
||||
return GameActions::Result(
|
||||
GameActions::Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_TOO_MANY_BANNERS_IN_GAME);
|
||||
return Result(Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_TOO_MANY_BANNERS_IN_GAME);
|
||||
}
|
||||
|
||||
auto* bannerEntry = OpenRCT2::ObjectManager::GetObjectEntry<BannerSceneryEntry>(_bannerType);
|
||||
if (bannerEntry == nullptr)
|
||||
{
|
||||
LOG_ERROR("Banner entry not found for bannerType %u", _bannerType);
|
||||
return GameActions::Result(
|
||||
GameActions::Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_ERR_BANNER_ELEMENT_NOT_FOUND);
|
||||
return Result(Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_ERR_BANNER_ELEMENT_NOT_FOUND);
|
||||
}
|
||||
res.Cost = bannerEntry->price;
|
||||
res.SetData(BannerPlaceActionResult{});
|
||||
@@ -113,9 +107,9 @@ namespace OpenRCT2::GameActions
|
||||
return res;
|
||||
}
|
||||
|
||||
GameActions::Result BannerPlaceAction::Execute() const
|
||||
Result BannerPlaceAction::Execute() const
|
||||
{
|
||||
auto res = GameActions::Result();
|
||||
auto res = Result();
|
||||
res.Position.x = _loc.x + 16;
|
||||
res.Position.y = _loc.y + 16;
|
||||
res.Position.z = _loc.z;
|
||||
@@ -125,24 +119,21 @@ namespace OpenRCT2::GameActions
|
||||
if (!MapCheckCapacityAndReorganise(_loc))
|
||||
{
|
||||
LOG_ERROR("No free map elements.");
|
||||
return GameActions::Result(
|
||||
GameActions::Status::NoFreeElements, STR_CANT_POSITION_THIS_HERE, STR_TILE_ELEMENT_LIMIT_REACHED);
|
||||
return Result(Status::NoFreeElements, STR_CANT_POSITION_THIS_HERE, STR_TILE_ELEMENT_LIMIT_REACHED);
|
||||
}
|
||||
|
||||
auto* bannerEntry = OpenRCT2::ObjectManager::GetObjectEntry<BannerSceneryEntry>(_bannerType);
|
||||
if (bannerEntry == nullptr)
|
||||
{
|
||||
LOG_ERROR("Banner entry not found for bannerType %u", _bannerType);
|
||||
return GameActions::Result(
|
||||
GameActions::Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_ERR_BANNER_ELEMENT_NOT_FOUND);
|
||||
return Result(Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_ERR_BANNER_ELEMENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
auto banner = CreateBanner();
|
||||
if (banner == nullptr)
|
||||
{
|
||||
LOG_ERROR("No free banners available");
|
||||
return GameActions::Result(
|
||||
GameActions::Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_TOO_MANY_BANNERS_IN_GAME);
|
||||
return Result(Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_TOO_MANY_BANNERS_IN_GAME);
|
||||
}
|
||||
banner->flags = {};
|
||||
banner->text = {};
|
||||
|
||||
@@ -22,22 +22,22 @@ namespace OpenRCT2::GameActions
|
||||
{
|
||||
private:
|
||||
CoordsXYZD _loc;
|
||||
OpenRCT2::ObjectEntryIndex _bannerType{ kBannerNull };
|
||||
ObjectEntryIndex _bannerType{ kBannerNull };
|
||||
uint8_t _primaryColour{};
|
||||
|
||||
public:
|
||||
BannerPlaceAction() = default;
|
||||
BannerPlaceAction(const CoordsXYZD& loc, OpenRCT2::ObjectEntryIndex bannerType, colour_t primaryColour);
|
||||
BannerPlaceAction(const CoordsXYZD& loc, ObjectEntryIndex bannerType, colour_t primaryColour);
|
||||
|
||||
void AcceptParameters(GameActionParameterVisitor& visitor) override;
|
||||
|
||||
uint16_t GetActionFlags() const override;
|
||||
|
||||
void Serialise(DataSerialiser& stream) override;
|
||||
OpenRCT2::GameActions::Result Query() const override;
|
||||
OpenRCT2::GameActions::Result Execute() const override;
|
||||
Result Query() const override;
|
||||
Result Execute() const override;
|
||||
|
||||
private:
|
||||
OpenRCT2::PathElement* GetValidPathElement() const;
|
||||
PathElement* GetValidPathElement() const;
|
||||
};
|
||||
} // namespace OpenRCT2::GameActions
|
||||
@@ -19,135 +19,138 @@
|
||||
#include "../world/tile_element/BannerElement.h"
|
||||
#include "GameAction.h"
|
||||
|
||||
using namespace OpenRCT2;
|
||||
|
||||
BannerRemoveAction::BannerRemoveAction(const CoordsXYZD& loc)
|
||||
: _loc(loc)
|
||||
namespace OpenRCT2::GameActions
|
||||
{
|
||||
}
|
||||
|
||||
void BannerRemoveAction::AcceptParameters(GameActionParameterVisitor& visitor)
|
||||
{
|
||||
visitor.Visit(_loc);
|
||||
}
|
||||
|
||||
uint16_t BannerRemoveAction::GetActionFlags() const
|
||||
{
|
||||
return GameAction::GetActionFlags();
|
||||
}
|
||||
|
||||
void BannerRemoveAction::Serialise(DataSerialiser& stream)
|
||||
{
|
||||
GameAction::Serialise(stream);
|
||||
|
||||
stream << DS_TAG(_loc);
|
||||
}
|
||||
|
||||
GameActions::Result BannerRemoveAction::Query() const
|
||||
{
|
||||
auto res = GameActions::Result();
|
||||
res.Expenditure = ExpenditureType::landscaping;
|
||||
res.Position.x = _loc.x + 16;
|
||||
res.Position.y = _loc.y + 16;
|
||||
res.Position.z = _loc.z;
|
||||
res.ErrorTitle = STR_CANT_REMOVE_THIS;
|
||||
|
||||
if (!LocationValid(_loc))
|
||||
BannerRemoveAction::BannerRemoveAction(const CoordsXYZD& loc)
|
||||
: _loc(loc)
|
||||
{
|
||||
return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_OFF_EDGE_OF_MAP);
|
||||
}
|
||||
if (!MapCanBuildAt({ _loc.x, _loc.y, _loc.z - 16 }))
|
||||
{
|
||||
return GameActions::Result(GameActions::Status::NotOwned, STR_CANT_REMOVE_THIS, STR_LAND_NOT_OWNED_BY_PARK);
|
||||
}
|
||||
|
||||
BannerElement* bannerElement = GetBannerElementAt();
|
||||
if (bannerElement == nullptr)
|
||||
void BannerRemoveAction::AcceptParameters(GameActionParameterVisitor& visitor)
|
||||
{
|
||||
LOG_ERROR("Invalid banner location, x = %d, y = %d, z = %d, direction = %d", _loc.x, _loc.y, _loc.z, _loc.direction);
|
||||
return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, kStringIdNone);
|
||||
visitor.Visit(_loc);
|
||||
}
|
||||
|
||||
auto bannerIndex = bannerElement->GetIndex();
|
||||
if (bannerIndex == BannerIndex::GetNull())
|
||||
uint16_t BannerRemoveAction::GetActionFlags() const
|
||||
{
|
||||
LOG_ERROR("Invalid banner index %u", bannerIndex);
|
||||
return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, kStringIdNone);
|
||||
return GameAction::GetActionFlags();
|
||||
}
|
||||
|
||||
auto banner = bannerElement->GetBanner();
|
||||
if (banner == nullptr)
|
||||
void BannerRemoveAction::Serialise(DataSerialiser& stream)
|
||||
{
|
||||
LOG_ERROR("Invalid banner index %u", bannerIndex);
|
||||
return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, kStringIdNone);
|
||||
GameAction::Serialise(stream);
|
||||
|
||||
stream << DS_TAG(_loc);
|
||||
}
|
||||
|
||||
auto* bannerEntry = OpenRCT2::ObjectManager::GetObjectEntry<BannerSceneryEntry>(banner->type);
|
||||
if (bannerEntry != nullptr)
|
||||
Result BannerRemoveAction::Query() const
|
||||
{
|
||||
res.Cost = -((bannerEntry->price * 3) / 4);
|
||||
auto res = Result();
|
||||
res.Expenditure = ExpenditureType::landscaping;
|
||||
res.Position.x = _loc.x + 16;
|
||||
res.Position.y = _loc.y + 16;
|
||||
res.Position.z = _loc.z;
|
||||
res.ErrorTitle = STR_CANT_REMOVE_THIS;
|
||||
|
||||
if (!LocationValid(_loc))
|
||||
{
|
||||
return Result(Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_OFF_EDGE_OF_MAP);
|
||||
}
|
||||
if (!MapCanBuildAt({ _loc.x, _loc.y, _loc.z - 16 }))
|
||||
{
|
||||
return Result(Status::NotOwned, STR_CANT_REMOVE_THIS, STR_LAND_NOT_OWNED_BY_PARK);
|
||||
}
|
||||
|
||||
BannerElement* bannerElement = GetBannerElementAt();
|
||||
if (bannerElement == nullptr)
|
||||
{
|
||||
LOG_ERROR(
|
||||
"Invalid banner location, x = %d, y = %d, z = %d, direction = %d", _loc.x, _loc.y, _loc.z, _loc.direction);
|
||||
return Result(Status::InvalidParameters, STR_CANT_REMOVE_THIS, kStringIdNone);
|
||||
}
|
||||
|
||||
auto bannerIndex = bannerElement->GetIndex();
|
||||
if (bannerIndex == BannerIndex::GetNull())
|
||||
{
|
||||
LOG_ERROR("Invalid banner index %u", bannerIndex);
|
||||
return Result(Status::InvalidParameters, STR_CANT_REMOVE_THIS, kStringIdNone);
|
||||
}
|
||||
|
||||
auto banner = bannerElement->GetBanner();
|
||||
if (banner == nullptr)
|
||||
{
|
||||
LOG_ERROR("Invalid banner index %u", bannerIndex);
|
||||
return Result(Status::InvalidParameters, STR_CANT_REMOVE_THIS, kStringIdNone);
|
||||
}
|
||||
|
||||
auto* bannerEntry = ObjectManager::GetObjectEntry<BannerSceneryEntry>(banner->type);
|
||||
if (bannerEntry != nullptr)
|
||||
{
|
||||
res.Cost = -((bannerEntry->price * 3) / 4);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
GameActions::Result BannerRemoveAction::Execute() const
|
||||
{
|
||||
auto res = GameActions::Result();
|
||||
res.Expenditure = ExpenditureType::landscaping;
|
||||
res.Position.x = _loc.x + 16;
|
||||
res.Position.y = _loc.y + 16;
|
||||
res.Position.z = _loc.z;
|
||||
res.ErrorTitle = STR_CANT_REMOVE_THIS;
|
||||
|
||||
BannerElement* bannerElement = GetBannerElementAt();
|
||||
if (bannerElement == nullptr)
|
||||
Result BannerRemoveAction::Execute() const
|
||||
{
|
||||
LOG_ERROR("Invalid banner location, x = %d, y = %d, z = %d, direction = %d", _loc.x, _loc.y, _loc.z, _loc.direction);
|
||||
return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, kStringIdNone);
|
||||
auto res = Result();
|
||||
res.Expenditure = ExpenditureType::landscaping;
|
||||
res.Position.x = _loc.x + 16;
|
||||
res.Position.y = _loc.y + 16;
|
||||
res.Position.z = _loc.z;
|
||||
res.ErrorTitle = STR_CANT_REMOVE_THIS;
|
||||
|
||||
BannerElement* bannerElement = GetBannerElementAt();
|
||||
if (bannerElement == nullptr)
|
||||
{
|
||||
LOG_ERROR(
|
||||
"Invalid banner location, x = %d, y = %d, z = %d, direction = %d", _loc.x, _loc.y, _loc.z, _loc.direction);
|
||||
return Result(Status::InvalidParameters, STR_CANT_REMOVE_THIS, kStringIdNone);
|
||||
}
|
||||
|
||||
auto bannerIndex = bannerElement->GetIndex();
|
||||
if (bannerIndex == BannerIndex::GetNull())
|
||||
{
|
||||
LOG_ERROR("Invalid banner index %u", bannerIndex);
|
||||
return Result(Status::InvalidParameters, STR_CANT_REMOVE_THIS, kStringIdNone);
|
||||
}
|
||||
|
||||
auto banner = bannerElement->GetBanner();
|
||||
if (banner == nullptr)
|
||||
{
|
||||
LOG_ERROR("Invalid banner index %u", bannerIndex);
|
||||
return Result(Status::InvalidParameters, STR_CANT_REMOVE_THIS, kStringIdNone);
|
||||
}
|
||||
|
||||
auto* bannerEntry = ObjectManager::GetObjectEntry<BannerSceneryEntry>(banner->type);
|
||||
if (bannerEntry != nullptr)
|
||||
{
|
||||
res.Cost = -((bannerEntry->price * 3) / 4);
|
||||
}
|
||||
|
||||
reinterpret_cast<TileElement*>(bannerElement)->RemoveBannerEntry();
|
||||
MapInvalidateTileZoom1({ _loc, _loc.z, _loc.z + 32 });
|
||||
bannerElement->Remove();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
auto bannerIndex = bannerElement->GetIndex();
|
||||
if (bannerIndex == BannerIndex::GetNull())
|
||||
BannerElement* BannerRemoveAction::GetBannerElementAt() const
|
||||
{
|
||||
LOG_ERROR("Invalid banner index %u", bannerIndex);
|
||||
return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, kStringIdNone);
|
||||
// Find the banner element at known z and position
|
||||
for (auto* bannerElement : TileElementsView<BannerElement>(_loc))
|
||||
{
|
||||
if (bannerElement->GetBaseZ() != _loc.z)
|
||||
continue;
|
||||
if (bannerElement->IsGhost() && !(GetFlags() & GAME_COMMAND_FLAG_GHOST))
|
||||
continue;
|
||||
if (bannerElement->GetPosition() != _loc.direction)
|
||||
continue;
|
||||
|
||||
return bannerElement;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto banner = bannerElement->GetBanner();
|
||||
if (banner == nullptr)
|
||||
{
|
||||
LOG_ERROR("Invalid banner index %u", bannerIndex);
|
||||
return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, kStringIdNone);
|
||||
}
|
||||
|
||||
auto* bannerEntry = OpenRCT2::ObjectManager::GetObjectEntry<BannerSceneryEntry>(banner->type);
|
||||
if (bannerEntry != nullptr)
|
||||
{
|
||||
res.Cost = -((bannerEntry->price * 3) / 4);
|
||||
}
|
||||
|
||||
reinterpret_cast<TileElement*>(bannerElement)->RemoveBannerEntry();
|
||||
MapInvalidateTileZoom1({ _loc, _loc.z, _loc.z + 32 });
|
||||
bannerElement->Remove();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
BannerElement* BannerRemoveAction::GetBannerElementAt() const
|
||||
{
|
||||
// Find the banner element at known z and position
|
||||
for (auto* bannerElement : TileElementsView<BannerElement>(_loc))
|
||||
{
|
||||
if (bannerElement->GetBaseZ() != _loc.z)
|
||||
continue;
|
||||
if (bannerElement->IsGhost() && !(GetFlags() & GAME_COMMAND_FLAG_GHOST))
|
||||
continue;
|
||||
if (bannerElement->GetPosition() != _loc.direction)
|
||||
continue;
|
||||
|
||||
return bannerElement;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
} // namespace OpenRCT2::GameActions
|
||||
@@ -11,23 +11,26 @@
|
||||
|
||||
#include "GameAction.h"
|
||||
|
||||
class BannerRemoveAction final : public GameActionBase<GameCommand::RemoveBanner>
|
||||
namespace OpenRCT2::GameActions
|
||||
{
|
||||
private:
|
||||
CoordsXYZD _loc;
|
||||
class BannerRemoveAction final : public GameActionBase<GameCommand::RemoveBanner>
|
||||
{
|
||||
private:
|
||||
CoordsXYZD _loc;
|
||||
|
||||
public:
|
||||
BannerRemoveAction() = default;
|
||||
BannerRemoveAction(const CoordsXYZD& loc);
|
||||
public:
|
||||
BannerRemoveAction() = default;
|
||||
BannerRemoveAction(const CoordsXYZD& loc);
|
||||
|
||||
void AcceptParameters(GameActionParameterVisitor& visitor) override;
|
||||
void AcceptParameters(GameActionParameterVisitor& visitor) override;
|
||||
|
||||
uint16_t GetActionFlags() const override;
|
||||
uint16_t GetActionFlags() const override;
|
||||
|
||||
void Serialise(DataSerialiser& stream) override;
|
||||
OpenRCT2::GameActions::Result Query() const override;
|
||||
OpenRCT2::GameActions::Result Execute() const override;
|
||||
void Serialise(DataSerialiser& stream) override;
|
||||
Result Query() const override;
|
||||
Result Execute() const override;
|
||||
|
||||
private:
|
||||
OpenRCT2::BannerElement* GetBannerElementAt() const;
|
||||
};
|
||||
private:
|
||||
BannerElement* GetBannerElementAt() const;
|
||||
};
|
||||
} // namespace OpenRCT2::GameActions
|
||||
@@ -17,93 +17,94 @@
|
||||
#include "../world/tile_element/BannerElement.h"
|
||||
#include "GameAction.h"
|
||||
|
||||
using namespace OpenRCT2;
|
||||
|
||||
BannerSetColourAction::BannerSetColourAction(const CoordsXYZD& loc, uint8_t primaryColour)
|
||||
: _loc(loc)
|
||||
, _primaryColour(primaryColour)
|
||||
namespace OpenRCT2::GameActions
|
||||
{
|
||||
}
|
||||
|
||||
void BannerSetColourAction::AcceptParameters(GameActionParameterVisitor& visitor)
|
||||
{
|
||||
visitor.Visit(_loc);
|
||||
visitor.Visit("primaryColour", _primaryColour);
|
||||
}
|
||||
|
||||
uint16_t BannerSetColourAction::GetActionFlags() const
|
||||
{
|
||||
return GameAction::GetActionFlags() | GameActions::Flags::AllowWhilePaused;
|
||||
}
|
||||
|
||||
void BannerSetColourAction::Serialise(DataSerialiser& stream)
|
||||
{
|
||||
GameAction::Serialise(stream);
|
||||
|
||||
stream << DS_TAG(_loc) << DS_TAG(_primaryColour);
|
||||
}
|
||||
|
||||
GameActions::Result BannerSetColourAction::Query() const
|
||||
{
|
||||
return QueryExecute(false);
|
||||
}
|
||||
|
||||
GameActions::Result BannerSetColourAction::Execute() const
|
||||
{
|
||||
return QueryExecute(true);
|
||||
}
|
||||
|
||||
GameActions::Result BannerSetColourAction::QueryExecute(bool isExecuting) const
|
||||
{
|
||||
auto res = GameActions::Result();
|
||||
res.Expenditure = ExpenditureType::landscaping;
|
||||
res.Position.x = _loc.x + 16;
|
||||
res.Position.y = _loc.y + 16;
|
||||
res.Position.z = _loc.z;
|
||||
res.ErrorTitle = STR_CANT_REPAINT_THIS;
|
||||
|
||||
if (!LocationValid(_loc))
|
||||
BannerSetColourAction::BannerSetColourAction(const CoordsXYZD& loc, uint8_t primaryColour)
|
||||
: _loc(loc)
|
||||
, _primaryColour(primaryColour)
|
||||
{
|
||||
LOG_ERROR("Invalid x / y coordinates: x = %d, y = %d", _loc.x, _loc.y);
|
||||
return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_OFF_EDGE_OF_MAP);
|
||||
}
|
||||
|
||||
if (_primaryColour > 31)
|
||||
void BannerSetColourAction::AcceptParameters(GameActionParameterVisitor& visitor)
|
||||
{
|
||||
LOG_ERROR("Invalid primary colour %u", _primaryColour);
|
||||
return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_INVALID_COLOUR);
|
||||
visitor.Visit(_loc);
|
||||
visitor.Visit("primaryColour", _primaryColour);
|
||||
}
|
||||
|
||||
if (!MapCanBuildAt({ _loc.x, _loc.y, _loc.z - 16 }))
|
||||
uint16_t BannerSetColourAction::GetActionFlags() const
|
||||
{
|
||||
return GameActions::Result(GameActions::Status::NotOwned, STR_CANT_REPAINT_THIS, STR_LAND_NOT_OWNED_BY_PARK);
|
||||
return GameAction::GetActionFlags() | Flags::AllowWhilePaused;
|
||||
}
|
||||
|
||||
auto bannerElement = MapGetBannerElementAt(_loc, _loc.direction);
|
||||
|
||||
if (bannerElement == nullptr)
|
||||
void BannerSetColourAction::Serialise(DataSerialiser& stream)
|
||||
{
|
||||
LOG_ERROR("No banner at x = %d, y = %d, z = %d, direction = %u", _loc.x, _loc.y, _loc.z, _loc.direction);
|
||||
return GameActions::Result(GameActions::Status::Unknown, STR_CANT_REPAINT_THIS, STR_ERR_BANNER_ELEMENT_NOT_FOUND);
|
||||
GameAction::Serialise(stream);
|
||||
|
||||
stream << DS_TAG(_loc) << DS_TAG(_primaryColour);
|
||||
}
|
||||
|
||||
auto index = bannerElement->GetIndex();
|
||||
auto banner = GetBanner(index);
|
||||
if (banner == nullptr)
|
||||
Result BannerSetColourAction::Query() const
|
||||
{
|
||||
LOG_ERROR("Invalid banner index %u", index);
|
||||
return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, kStringIdNone);
|
||||
return QueryExecute(false);
|
||||
}
|
||||
|
||||
if (isExecuting)
|
||||
Result BannerSetColourAction::Execute() const
|
||||
{
|
||||
auto intent = Intent(INTENT_ACTION_UPDATE_BANNER);
|
||||
intent.PutExtra(INTENT_EXTRA_BANNER_INDEX, index);
|
||||
ContextBroadcastIntent(&intent);
|
||||
|
||||
banner->colour = _primaryColour;
|
||||
MapInvalidateTileZoom1({ _loc, _loc.z, _loc.z + 32 });
|
||||
return QueryExecute(true);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
Result BannerSetColourAction::QueryExecute(bool isExecuting) const
|
||||
{
|
||||
auto res = Result();
|
||||
res.Expenditure = ExpenditureType::landscaping;
|
||||
res.Position.x = _loc.x + 16;
|
||||
res.Position.y = _loc.y + 16;
|
||||
res.Position.z = _loc.z;
|
||||
res.ErrorTitle = STR_CANT_REPAINT_THIS;
|
||||
|
||||
if (!LocationValid(_loc))
|
||||
{
|
||||
LOG_ERROR("Invalid x / y coordinates: x = %d, y = %d", _loc.x, _loc.y);
|
||||
return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_OFF_EDGE_OF_MAP);
|
||||
}
|
||||
|
||||
if (_primaryColour > 31)
|
||||
{
|
||||
LOG_ERROR("Invalid primary colour %u", _primaryColour);
|
||||
return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_INVALID_COLOUR);
|
||||
}
|
||||
|
||||
if (!MapCanBuildAt({ _loc.x, _loc.y, _loc.z - 16 }))
|
||||
{
|
||||
return Result(Status::NotOwned, STR_CANT_REPAINT_THIS, STR_LAND_NOT_OWNED_BY_PARK);
|
||||
}
|
||||
|
||||
auto bannerElement = MapGetBannerElementAt(_loc, _loc.direction);
|
||||
|
||||
if (bannerElement == nullptr)
|
||||
{
|
||||
LOG_ERROR("No banner at x = %d, y = %d, z = %d, direction = %u", _loc.x, _loc.y, _loc.z, _loc.direction);
|
||||
return Result(Status::Unknown, STR_CANT_REPAINT_THIS, STR_ERR_BANNER_ELEMENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
auto index = bannerElement->GetIndex();
|
||||
auto banner = GetBanner(index);
|
||||
if (banner == nullptr)
|
||||
{
|
||||
LOG_ERROR("Invalid banner index %u", index);
|
||||
return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, kStringIdNone);
|
||||
}
|
||||
|
||||
if (isExecuting)
|
||||
{
|
||||
auto intent = Intent(INTENT_ACTION_UPDATE_BANNER);
|
||||
intent.PutExtra(INTENT_EXTRA_BANNER_INDEX, index);
|
||||
ContextBroadcastIntent(&intent);
|
||||
|
||||
banner->colour = _primaryColour;
|
||||
MapInvalidateTileZoom1({ _loc, _loc.z, _loc.z + 32 });
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
} // namespace OpenRCT2::GameActions
|
||||
@@ -11,24 +11,27 @@
|
||||
|
||||
#include "GameAction.h"
|
||||
|
||||
class BannerSetColourAction final : public GameActionBase<GameCommand::SetBannerColour>
|
||||
namespace OpenRCT2::GameActions
|
||||
{
|
||||
private:
|
||||
CoordsXYZD _loc;
|
||||
uint8_t _primaryColour{};
|
||||
class BannerSetColourAction final : public GameActionBase<GameCommand::SetBannerColour>
|
||||
{
|
||||
private:
|
||||
CoordsXYZD _loc;
|
||||
uint8_t _primaryColour{};
|
||||
|
||||
public:
|
||||
BannerSetColourAction() = default;
|
||||
BannerSetColourAction(const CoordsXYZD& loc, uint8_t primaryColour);
|
||||
public:
|
||||
BannerSetColourAction() = default;
|
||||
BannerSetColourAction(const CoordsXYZD& loc, uint8_t primaryColour);
|
||||
|
||||
void AcceptParameters(GameActionParameterVisitor& visitor) override;
|
||||
void AcceptParameters(GameActionParameterVisitor& visitor) override;
|
||||
|
||||
uint16_t GetActionFlags() const override;
|
||||
uint16_t GetActionFlags() const override;
|
||||
|
||||
void Serialise(DataSerialiser& stream) override;
|
||||
OpenRCT2::GameActions::Result Query() const override;
|
||||
OpenRCT2::GameActions::Result Execute() const override;
|
||||
void Serialise(DataSerialiser& stream) override;
|
||||
Result Query() const override;
|
||||
Result Execute() const override;
|
||||
|
||||
private:
|
||||
OpenRCT2::GameActions::Result QueryExecute(bool isExecuting) const;
|
||||
};
|
||||
private:
|
||||
Result QueryExecute(bool isExecuting) const;
|
||||
};
|
||||
} // namespace OpenRCT2::GameActions
|
||||
@@ -19,83 +19,81 @@
|
||||
#include "../world/tile_element/BannerElement.h"
|
||||
#include "GameAction.h"
|
||||
|
||||
using namespace OpenRCT2;
|
||||
|
||||
BannerSetNameAction::BannerSetNameAction(BannerIndex bannerIndex, const std::string& name)
|
||||
: _bannerIndex(bannerIndex)
|
||||
, _name(name)
|
||||
namespace OpenRCT2::GameActions
|
||||
{
|
||||
}
|
||||
|
||||
void BannerSetNameAction::AcceptParameters(GameActionParameterVisitor& visitor)
|
||||
{
|
||||
visitor.Visit("id", _bannerIndex);
|
||||
visitor.Visit("name", _name);
|
||||
}
|
||||
|
||||
uint16_t BannerSetNameAction::GetActionFlags() const
|
||||
{
|
||||
return GameAction::GetActionFlags() | GameActions::Flags::AllowWhilePaused;
|
||||
}
|
||||
|
||||
void BannerSetNameAction::Serialise(DataSerialiser& stream)
|
||||
{
|
||||
GameAction::Serialise(stream);
|
||||
stream << DS_TAG(_bannerIndex) << DS_TAG(_name);
|
||||
}
|
||||
|
||||
GameActions::Result BannerSetNameAction::Query() const
|
||||
{
|
||||
auto banner = GetBanner(_bannerIndex);
|
||||
if (banner == nullptr)
|
||||
BannerSetNameAction::BannerSetNameAction(BannerIndex bannerIndex, const std::string& name)
|
||||
: _bannerIndex(bannerIndex)
|
||||
, _name(name)
|
||||
{
|
||||
LOG_ERROR("Banner not found for bannerIndex %d", _bannerIndex);
|
||||
return GameActions::Result(
|
||||
GameActions::Status::InvalidParameters, STR_CANT_RENAME_BANNER, STR_ERR_BANNER_ELEMENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
TileElement* tileElement = BannerGetTileElement(_bannerIndex);
|
||||
|
||||
if (tileElement == nullptr)
|
||||
void BannerSetNameAction::AcceptParameters(GameActionParameterVisitor& visitor)
|
||||
{
|
||||
LOG_ERROR("Banner tile element not found for bannerIndex %d", _bannerIndex);
|
||||
return GameActions::Result(
|
||||
GameActions::Status::InvalidParameters, STR_CANT_RENAME_BANNER, STR_ERR_BANNER_ELEMENT_NOT_FOUND);
|
||||
visitor.Visit("id", _bannerIndex);
|
||||
visitor.Visit("name", _name);
|
||||
}
|
||||
|
||||
BannerElement* bannerElement = tileElement->AsBanner();
|
||||
CoordsXYZD loc = { banner->position.ToCoordsXY(), bannerElement->GetBaseZ(), bannerElement->GetPosition() };
|
||||
|
||||
if (!LocationValid(loc))
|
||||
uint16_t BannerSetNameAction::GetActionFlags() const
|
||||
{
|
||||
return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_RENAME_BANNER, STR_OFF_EDGE_OF_MAP);
|
||||
}
|
||||
if (!MapCanBuildAt({ loc.x, loc.y, loc.z - 16 }))
|
||||
{
|
||||
return GameActions::Result(GameActions::Status::NotOwned, STR_CANT_RENAME_BANNER, STR_LAND_NOT_OWNED_BY_PARK);
|
||||
return GameAction::GetActionFlags() | Flags::AllowWhilePaused;
|
||||
}
|
||||
|
||||
return GameActions::Result();
|
||||
}
|
||||
|
||||
GameActions::Result BannerSetNameAction::Execute() const
|
||||
{
|
||||
auto banner = GetBanner(_bannerIndex);
|
||||
if (banner == nullptr)
|
||||
void BannerSetNameAction::Serialise(DataSerialiser& stream)
|
||||
{
|
||||
LOG_ERROR("Banner not found for bannerIndex %d", _bannerIndex);
|
||||
return GameActions::Result(
|
||||
GameActions::Status::InvalidParameters, STR_CANT_RENAME_BANNER, STR_ERR_BANNER_ELEMENT_NOT_FOUND);
|
||||
GameAction::Serialise(stream);
|
||||
stream << DS_TAG(_bannerIndex) << DS_TAG(_name);
|
||||
}
|
||||
|
||||
banner->text = _name;
|
||||
Result BannerSetNameAction::Query() const
|
||||
{
|
||||
auto banner = GetBanner(_bannerIndex);
|
||||
if (banner == nullptr)
|
||||
{
|
||||
LOG_ERROR("Banner not found for bannerIndex %d", _bannerIndex);
|
||||
return Result(Status::InvalidParameters, STR_CANT_RENAME_BANNER, STR_ERR_BANNER_ELEMENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
auto intent = Intent(INTENT_ACTION_UPDATE_BANNER);
|
||||
intent.PutExtra(INTENT_EXTRA_BANNER_INDEX, _bannerIndex);
|
||||
ContextBroadcastIntent(&intent);
|
||||
TileElement* tileElement = BannerGetTileElement(_bannerIndex);
|
||||
|
||||
ScrollingTextInvalidate();
|
||||
GfxInvalidateScreen();
|
||||
if (tileElement == nullptr)
|
||||
{
|
||||
LOG_ERROR("Banner tile element not found for bannerIndex %d", _bannerIndex);
|
||||
return Result(Status::InvalidParameters, STR_CANT_RENAME_BANNER, STR_ERR_BANNER_ELEMENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
return GameActions::Result();
|
||||
}
|
||||
BannerElement* bannerElement = tileElement->AsBanner();
|
||||
CoordsXYZD loc = { banner->position.ToCoordsXY(), bannerElement->GetBaseZ(), bannerElement->GetPosition() };
|
||||
|
||||
if (!LocationValid(loc))
|
||||
{
|
||||
return Result(Status::InvalidParameters, STR_CANT_RENAME_BANNER, STR_OFF_EDGE_OF_MAP);
|
||||
}
|
||||
if (!MapCanBuildAt({ loc.x, loc.y, loc.z - 16 }))
|
||||
{
|
||||
return Result(Status::NotOwned, STR_CANT_RENAME_BANNER, STR_LAND_NOT_OWNED_BY_PARK);
|
||||
}
|
||||
|
||||
return Result();
|
||||
}
|
||||
|
||||
Result BannerSetNameAction::Execute() const
|
||||
{
|
||||
auto banner = GetBanner(_bannerIndex);
|
||||
if (banner == nullptr)
|
||||
{
|
||||
LOG_ERROR("Banner not found for bannerIndex %d", _bannerIndex);
|
||||
return Result(Status::InvalidParameters, STR_CANT_RENAME_BANNER, STR_ERR_BANNER_ELEMENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
banner->text = _name;
|
||||
|
||||
auto intent = Intent(INTENT_ACTION_UPDATE_BANNER);
|
||||
intent.PutExtra(INTENT_EXTRA_BANNER_INDEX, _bannerIndex);
|
||||
ContextBroadcastIntent(&intent);
|
||||
|
||||
ScrollingTextInvalidate();
|
||||
GfxInvalidateScreen();
|
||||
|
||||
return Result();
|
||||
}
|
||||
} // namespace OpenRCT2::GameActions
|
||||
@@ -11,21 +11,24 @@
|
||||
|
||||
#include "GameAction.h"
|
||||
|
||||
class BannerSetNameAction final : public GameActionBase<GameCommand::SetBannerName>
|
||||
namespace OpenRCT2::GameActions
|
||||
{
|
||||
private:
|
||||
BannerIndex _bannerIndex{ BannerIndex::GetNull() };
|
||||
std::string _name;
|
||||
class BannerSetNameAction final : public GameActionBase<GameCommand::SetBannerName>
|
||||
{
|
||||
private:
|
||||
BannerIndex _bannerIndex{ BannerIndex::GetNull() };
|
||||
std::string _name;
|
||||
|
||||
public:
|
||||
BannerSetNameAction() = default;
|
||||
BannerSetNameAction(BannerIndex bannerIndex, const std::string& name);
|
||||
public:
|
||||
BannerSetNameAction() = default;
|
||||
BannerSetNameAction(BannerIndex bannerIndex, const std::string& name);
|
||||
|
||||
void AcceptParameters(GameActionParameterVisitor& visitor) override;
|
||||
void AcceptParameters(GameActionParameterVisitor& visitor) override;
|
||||
|
||||
uint16_t GetActionFlags() const override;
|
||||
uint16_t GetActionFlags() const override;
|
||||
|
||||
void Serialise(DataSerialiser& stream) override;
|
||||
OpenRCT2::GameActions::Result Query() const override;
|
||||
OpenRCT2::GameActions::Result Execute() const override;
|
||||
};
|
||||
void Serialise(DataSerialiser& stream) override;
|
||||
Result Query() const override;
|
||||
Result Execute() const override;
|
||||
};
|
||||
} // namespace OpenRCT2::GameActions
|
||||
@@ -18,172 +18,167 @@
|
||||
#include "../world/tile_element/BannerElement.h"
|
||||
#include "GameAction.h"
|
||||
|
||||
using namespace OpenRCT2;
|
||||
|
||||
BannerSetStyleAction::BannerSetStyleAction(BannerSetStyleType type, BannerIndex bannerIndex, uint8_t parameter)
|
||||
: _type(type)
|
||||
, _bannerIndex(bannerIndex)
|
||||
, _parameter(parameter)
|
||||
namespace OpenRCT2::GameActions
|
||||
{
|
||||
}
|
||||
|
||||
void BannerSetStyleAction::AcceptParameters(GameActionParameterVisitor& visitor)
|
||||
{
|
||||
visitor.Visit("id", _bannerIndex);
|
||||
visitor.Visit("type", _type);
|
||||
visitor.Visit("parameter", _parameter);
|
||||
}
|
||||
|
||||
uint16_t BannerSetStyleAction::GetActionFlags() const
|
||||
{
|
||||
return GameAction::GetActionFlags() | GameActions::Flags::AllowWhilePaused;
|
||||
}
|
||||
|
||||
void BannerSetStyleAction::Serialise(DataSerialiser& stream)
|
||||
{
|
||||
GameAction::Serialise(stream);
|
||||
|
||||
stream << DS_TAG(_type) << DS_TAG(_bannerIndex) << DS_TAG(_parameter);
|
||||
}
|
||||
|
||||
GameActions::Result BannerSetStyleAction::Query() const
|
||||
{
|
||||
StringId errorTitle = STR_CANT_REPAINT_THIS;
|
||||
if (_type == BannerSetStyleType::NoEntry)
|
||||
BannerSetStyleAction::BannerSetStyleAction(BannerSetStyleType type, BannerIndex bannerIndex, uint8_t parameter)
|
||||
: _type(type)
|
||||
, _bannerIndex(bannerIndex)
|
||||
, _parameter(parameter)
|
||||
{
|
||||
errorTitle = STR_CANT_RENAME_BANNER;
|
||||
}
|
||||
|
||||
auto res = GameActions::Result();
|
||||
|
||||
auto banner = GetBanner(_bannerIndex);
|
||||
if (banner == nullptr)
|
||||
void BannerSetStyleAction::AcceptParameters(GameActionParameterVisitor& visitor)
|
||||
{
|
||||
LOG_ERROR("Banner not found for bannerIndex %d", _bannerIndex);
|
||||
return GameActions::Result(GameActions::Status::InvalidParameters, errorTitle, STR_ERR_BANNER_ELEMENT_NOT_FOUND);
|
||||
visitor.Visit("id", _bannerIndex);
|
||||
visitor.Visit("type", _type);
|
||||
visitor.Visit("parameter", _parameter);
|
||||
}
|
||||
|
||||
res.Expenditure = ExpenditureType::landscaping;
|
||||
auto location = banner->position.ToCoordsXY().ToTileCentre();
|
||||
res.Position = { location, TileElementHeight(location) };
|
||||
|
||||
TileElement* tileElement = BannerGetTileElement(_bannerIndex);
|
||||
|
||||
if (tileElement == nullptr)
|
||||
uint16_t BannerSetStyleAction::GetActionFlags() const
|
||||
{
|
||||
LOG_ERROR("Banner tile element not found for bannerIndex %d", _bannerIndex);
|
||||
return GameActions::Result(GameActions::Status::InvalidParameters, errorTitle, STR_ERR_BANNER_ELEMENT_NOT_FOUND);
|
||||
return GameAction::GetActionFlags() | Flags::AllowWhilePaused;
|
||||
}
|
||||
|
||||
BannerElement* bannerElement = tileElement->AsBanner();
|
||||
CoordsXYZ loc = { banner->position.ToCoordsXY(), bannerElement->GetBaseZ() };
|
||||
void BannerSetStyleAction::Serialise(DataSerialiser& stream)
|
||||
{
|
||||
GameAction::Serialise(stream);
|
||||
|
||||
if (!LocationValid(loc))
|
||||
{
|
||||
return GameActions::Result(GameActions::Status::InvalidParameters, errorTitle, STR_OFF_EDGE_OF_MAP);
|
||||
}
|
||||
if (!MapCanBuildAt({ loc.x, loc.y, loc.z - 16 }))
|
||||
{
|
||||
return GameActions::Result(GameActions::Status::NotOwned, errorTitle, STR_LAND_NOT_OWNED_BY_PARK);
|
||||
stream << DS_TAG(_type) << DS_TAG(_bannerIndex) << DS_TAG(_parameter);
|
||||
}
|
||||
|
||||
switch (_type)
|
||||
Result BannerSetStyleAction::Query() const
|
||||
{
|
||||
case BannerSetStyleType::PrimaryColour:
|
||||
if (_parameter > COLOUR_COUNT)
|
||||
{
|
||||
LOG_ERROR("Invalid primary colour %u", _parameter);
|
||||
return GameActions::Result(
|
||||
GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_INVALID_COLOUR);
|
||||
}
|
||||
break;
|
||||
|
||||
case BannerSetStyleType::TextColour:
|
||||
if (_parameter > 13)
|
||||
{
|
||||
LOG_ERROR("Invalid text colour %u", _parameter);
|
||||
return GameActions::Result(
|
||||
GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_INVALID_COLOUR);
|
||||
}
|
||||
break;
|
||||
case BannerSetStyleType::NoEntry:
|
||||
if (tileElement->AsBanner() == nullptr)
|
||||
{
|
||||
LOG_ERROR("Tile element was not a banner.");
|
||||
return GameActions::Result(GameActions::Status::Unknown, STR_CANT_RENAME_BANNER, kStringIdNone);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("Invalid banner style type %u", _type);
|
||||
return GameActions::Result(
|
||||
GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_VALUE_OUT_OF_RANGE);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
GameActions::Result BannerSetStyleAction::Execute() const
|
||||
{
|
||||
auto res = GameActions::Result();
|
||||
|
||||
auto banner = GetBanner(_bannerIndex);
|
||||
if (banner == nullptr)
|
||||
{
|
||||
LOG_ERROR("Banner not found for bannerIndex %d", _bannerIndex);
|
||||
return GameActions::Result(
|
||||
GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_BANNER_ELEMENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
res.Expenditure = ExpenditureType::landscaping;
|
||||
auto location = banner->position.ToCoordsXY().ToTileCentre();
|
||||
res.Position = { location, TileElementHeight(location) };
|
||||
|
||||
TileElement* tileElement = BannerGetTileElement(_bannerIndex);
|
||||
|
||||
if (tileElement == nullptr)
|
||||
{
|
||||
LOG_ERROR("Banner tile element not found for bannerIndex &u", _bannerIndex);
|
||||
return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, kStringIdNone);
|
||||
}
|
||||
|
||||
switch (_type)
|
||||
{
|
||||
case BannerSetStyleType::PrimaryColour:
|
||||
banner->colour = _parameter;
|
||||
break;
|
||||
case BannerSetStyleType::TextColour:
|
||||
banner->textColour = static_cast<TextColour>(_parameter);
|
||||
break;
|
||||
case BannerSetStyleType::NoEntry:
|
||||
StringId errorTitle = STR_CANT_REPAINT_THIS;
|
||||
if (_type == BannerSetStyleType::NoEntry)
|
||||
{
|
||||
BannerElement* bannerElement = tileElement->AsBanner();
|
||||
if (bannerElement == nullptr)
|
||||
{
|
||||
LOG_ERROR("Tile element was not a banner.");
|
||||
return GameActions::Result(
|
||||
GameActions::Status::Unknown, STR_CANT_REPAINT_THIS, STR_ERR_BANNER_ELEMENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
banner->flags.set(BannerFlag::noEntry, (_parameter != 0));
|
||||
uint8_t allowedEdges = 0xF;
|
||||
if (banner->flags.has(BannerFlag::noEntry))
|
||||
{
|
||||
allowedEdges &= ~(1 << bannerElement->GetPosition());
|
||||
}
|
||||
bannerElement->SetAllowedEdges(allowedEdges);
|
||||
break;
|
||||
errorTitle = STR_CANT_RENAME_BANNER;
|
||||
}
|
||||
default:
|
||||
LOG_ERROR("Invalid banner style type %u", _type);
|
||||
return GameActions::Result(
|
||||
GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_VALUE_OUT_OF_RANGE);
|
||||
|
||||
auto res = Result();
|
||||
|
||||
auto banner = GetBanner(_bannerIndex);
|
||||
if (banner == nullptr)
|
||||
{
|
||||
LOG_ERROR("Banner not found for bannerIndex %d", _bannerIndex);
|
||||
return Result(Status::InvalidParameters, errorTitle, STR_ERR_BANNER_ELEMENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
res.Expenditure = ExpenditureType::landscaping;
|
||||
auto location = banner->position.ToCoordsXY().ToTileCentre();
|
||||
res.Position = { location, TileElementHeight(location) };
|
||||
|
||||
TileElement* tileElement = BannerGetTileElement(_bannerIndex);
|
||||
|
||||
if (tileElement == nullptr)
|
||||
{
|
||||
LOG_ERROR("Banner tile element not found for bannerIndex %d", _bannerIndex);
|
||||
return Result(Status::InvalidParameters, errorTitle, STR_ERR_BANNER_ELEMENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
BannerElement* bannerElement = tileElement->AsBanner();
|
||||
CoordsXYZ loc = { banner->position.ToCoordsXY(), bannerElement->GetBaseZ() };
|
||||
|
||||
if (!LocationValid(loc))
|
||||
{
|
||||
return Result(Status::InvalidParameters, errorTitle, STR_OFF_EDGE_OF_MAP);
|
||||
}
|
||||
if (!MapCanBuildAt({ loc.x, loc.y, loc.z - 16 }))
|
||||
{
|
||||
return Result(Status::NotOwned, errorTitle, STR_LAND_NOT_OWNED_BY_PARK);
|
||||
}
|
||||
|
||||
switch (_type)
|
||||
{
|
||||
case BannerSetStyleType::PrimaryColour:
|
||||
if (_parameter > COLOUR_COUNT)
|
||||
{
|
||||
LOG_ERROR("Invalid primary colour %u", _parameter);
|
||||
return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_INVALID_COLOUR);
|
||||
}
|
||||
break;
|
||||
|
||||
case BannerSetStyleType::TextColour:
|
||||
if (_parameter > 13)
|
||||
{
|
||||
LOG_ERROR("Invalid text colour %u", _parameter);
|
||||
return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_INVALID_COLOUR);
|
||||
}
|
||||
break;
|
||||
case BannerSetStyleType::NoEntry:
|
||||
if (tileElement->AsBanner() == nullptr)
|
||||
{
|
||||
LOG_ERROR("Tile element was not a banner.");
|
||||
return Result(Status::Unknown, STR_CANT_RENAME_BANNER, kStringIdNone);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("Invalid banner style type %u", _type);
|
||||
return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_VALUE_OUT_OF_RANGE);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
auto intent = Intent(INTENT_ACTION_UPDATE_BANNER);
|
||||
intent.PutExtra(INTENT_EXTRA_BANNER_INDEX, _bannerIndex);
|
||||
ContextBroadcastIntent(&intent);
|
||||
Result BannerSetStyleAction::Execute() const
|
||||
{
|
||||
auto res = Result();
|
||||
|
||||
ScrollingTextInvalidate();
|
||||
GfxInvalidateScreen();
|
||||
auto banner = GetBanner(_bannerIndex);
|
||||
if (banner == nullptr)
|
||||
{
|
||||
LOG_ERROR("Banner not found for bannerIndex %d", _bannerIndex);
|
||||
return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_BANNER_ELEMENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
res.Expenditure = ExpenditureType::landscaping;
|
||||
auto location = banner->position.ToCoordsXY().ToTileCentre();
|
||||
res.Position = { location, TileElementHeight(location) };
|
||||
|
||||
TileElement* tileElement = BannerGetTileElement(_bannerIndex);
|
||||
|
||||
if (tileElement == nullptr)
|
||||
{
|
||||
LOG_ERROR("Banner tile element not found for bannerIndex &u", _bannerIndex);
|
||||
return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, kStringIdNone);
|
||||
}
|
||||
|
||||
switch (_type)
|
||||
{
|
||||
case BannerSetStyleType::PrimaryColour:
|
||||
banner->colour = _parameter;
|
||||
break;
|
||||
case BannerSetStyleType::TextColour:
|
||||
banner->textColour = static_cast<TextColour>(_parameter);
|
||||
break;
|
||||
case BannerSetStyleType::NoEntry:
|
||||
{
|
||||
BannerElement* bannerElement = tileElement->AsBanner();
|
||||
if (bannerElement == nullptr)
|
||||
{
|
||||
LOG_ERROR("Tile element was not a banner.");
|
||||
return Result(Status::Unknown, STR_CANT_REPAINT_THIS, STR_ERR_BANNER_ELEMENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
banner->flags.set(BannerFlag::noEntry, (_parameter != 0));
|
||||
uint8_t allowedEdges = 0xF;
|
||||
if (banner->flags.has(BannerFlag::noEntry))
|
||||
{
|
||||
allowedEdges &= ~(1 << bannerElement->GetPosition());
|
||||
}
|
||||
bannerElement->SetAllowedEdges(allowedEdges);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG_ERROR("Invalid banner style type %u", _type);
|
||||
return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_VALUE_OUT_OF_RANGE);
|
||||
}
|
||||
|
||||
auto intent = Intent(INTENT_ACTION_UPDATE_BANNER);
|
||||
intent.PutExtra(INTENT_EXTRA_BANNER_INDEX, _bannerIndex);
|
||||
ContextBroadcastIntent(&intent);
|
||||
|
||||
ScrollingTextInvalidate();
|
||||
GfxInvalidateScreen();
|
||||
|
||||
return res;
|
||||
}
|
||||
} // namespace OpenRCT2::GameActions
|
||||
@@ -11,32 +11,35 @@
|
||||
|
||||
#include "GameAction.h"
|
||||
|
||||
// There is also the BannerSetColourAction that sets primary colour but this action takes banner index rather than x, y, z,
|
||||
// direction
|
||||
enum class BannerSetStyleType : uint8_t
|
||||
namespace OpenRCT2::GameActions
|
||||
{
|
||||
PrimaryColour,
|
||||
TextColour,
|
||||
NoEntry,
|
||||
Count
|
||||
};
|
||||
// There is also the BannerSetColourAction that sets primary colour but this action takes banner index rather than x, y, z,
|
||||
// direction
|
||||
enum class BannerSetStyleType : uint8_t
|
||||
{
|
||||
PrimaryColour,
|
||||
TextColour,
|
||||
NoEntry,
|
||||
Count
|
||||
};
|
||||
|
||||
class BannerSetStyleAction final : public GameActionBase<GameCommand::SetBannerStyle>
|
||||
{
|
||||
private:
|
||||
BannerSetStyleType _type{ BannerSetStyleType::Count };
|
||||
BannerIndex _bannerIndex{ BannerIndex::GetNull() };
|
||||
uint8_t _parameter{};
|
||||
class BannerSetStyleAction final : public GameActionBase<GameCommand::SetBannerStyle>
|
||||
{
|
||||
private:
|
||||
BannerSetStyleType _type{ BannerSetStyleType::Count };
|
||||
BannerIndex _bannerIndex{ BannerIndex::GetNull() };
|
||||
uint8_t _parameter{};
|
||||
|
||||
public:
|
||||
BannerSetStyleAction() = default;
|
||||
BannerSetStyleAction(BannerSetStyleType type, BannerIndex bannerIndex, uint8_t parameter);
|
||||
public:
|
||||
BannerSetStyleAction() = default;
|
||||
BannerSetStyleAction(BannerSetStyleType type, BannerIndex bannerIndex, uint8_t parameter);
|
||||
|
||||
void AcceptParameters(GameActionParameterVisitor& visitor) override;
|
||||
void AcceptParameters(GameActionParameterVisitor& visitor) override;
|
||||
|
||||
uint16_t GetActionFlags() const override;
|
||||
uint16_t GetActionFlags() const override;
|
||||
|
||||
void Serialise(DataSerialiser& stream) override;
|
||||
OpenRCT2::GameActions::Result Query() const override;
|
||||
OpenRCT2::GameActions::Result Execute() const override;
|
||||
};
|
||||
void Serialise(DataSerialiser& stream) override;
|
||||
Result Query() const override;
|
||||
Result Execute() const override;
|
||||
};
|
||||
} // namespace OpenRCT2::GameActions
|
||||
File diff suppressed because it is too large.
Load diff
@@ -11,48 +11,51 @@
|
||||
|
||||
#include "GameAction.h"
|
||||
|
||||
class CheatSetAction final : public GameActionBase<GameCommand::Cheat>
|
||||
namespace OpenRCT2::GameActions
|
||||
{
|
||||
using ParametersRange = std::pair<std::pair<int64_t, int64_t>, std::pair<int64_t, int64_t>>;
|
||||
class CheatSetAction final : public GameActionBase<GameCommand::Cheat>
|
||||
{
|
||||
using ParametersRange = std::pair<std::pair<int64_t, int64_t>, std::pair<int64_t, int64_t>>;
|
||||
|
||||
private:
|
||||
NetworkCheatType_t _cheatType{ EnumValue(CheatType::Count) };
|
||||
int64_t _param1{};
|
||||
int64_t _param2{};
|
||||
private:
|
||||
NetworkCheatType_t _cheatType{ EnumValue(CheatType::Count) };
|
||||
int64_t _param1{};
|
||||
int64_t _param2{};
|
||||
|
||||
public:
|
||||
CheatSetAction() = default;
|
||||
CheatSetAction(CheatType cheatType, int64_t param1 = 0, int64_t param2 = 0);
|
||||
public:
|
||||
CheatSetAction() = default;
|
||||
CheatSetAction(CheatType cheatType, int64_t param1 = 0, int64_t param2 = 0);
|
||||
|
||||
void AcceptParameters(GameActionParameterVisitor& visitor) override;
|
||||
void AcceptParameters(GameActionParameterVisitor& visitor) override;
|
||||
|
||||
uint16_t GetActionFlags() const override;
|
||||
uint16_t GetActionFlags() const override;
|
||||
|
||||
void Serialise(DataSerialiser& stream) override;
|
||||
OpenRCT2::GameActions::Result Query() const override;
|
||||
OpenRCT2::GameActions::Result Execute() const override;
|
||||
void Serialise(DataSerialiser& stream) override;
|
||||
Result Query() const override;
|
||||
Result Execute() const override;
|
||||
|
||||
private:
|
||||
ParametersRange GetParameterRange(CheatType cheatType) const;
|
||||
void SetGrassLength(int32_t length) const;
|
||||
void WaterPlants() const;
|
||||
void FixVandalism() const;
|
||||
void RemoveLitter() const;
|
||||
void FixBrokenRides() const;
|
||||
void RenewRides() const;
|
||||
void ResetRideCrashStatus() const;
|
||||
void Set10MinuteInspection() const;
|
||||
void SetScenarioNoMoney(bool enabled) const;
|
||||
void SetMoney(money64 amount) const;
|
||||
void AddMoney(money64 amount) const;
|
||||
void ClearLoan() const;
|
||||
void GenerateGuests(int32_t count) const;
|
||||
void SetGuestParameter(int32_t parameter, int32_t value) const;
|
||||
void GiveObjectToGuests(int32_t object) const;
|
||||
void RemoveAllGuests() const;
|
||||
void SetStaffSpeed(uint8_t value) const;
|
||||
void OwnAllLand() const;
|
||||
void ParkSetOpen(bool isOpen) const;
|
||||
void CreateDucks(int count) const;
|
||||
void RemoveParkFences() const;
|
||||
};
|
||||
private:
|
||||
ParametersRange GetParameterRange(CheatType cheatType) const;
|
||||
void SetGrassLength(int32_t length) const;
|
||||
void WaterPlants() const;
|
||||
void FixVandalism() const;
|
||||
void RemoveLitter() const;
|
||||
void FixBrokenRides() const;
|
||||
void RenewRides() const;
|
||||
void ResetRideCrashStatus() const;
|
||||
void Set10MinuteInspection() const;
|
||||
void SetScenarioNoMoney(bool enabled) const;
|
||||
void SetMoney(money64 amount) const;
|
||||
void AddMoney(money64 amount) const;
|
||||
void ClearLoan() const;
|
||||
void GenerateGuests(int32_t count) const;
|
||||
void SetGuestParameter(int32_t parameter, int32_t value) const;
|
||||
void GiveObjectToGuests(int32_t object) const;
|
||||
void RemoveAllGuests() const;
|
||||
void SetStaffSpeed(uint8_t value) const;
|
||||
void OwnAllLand() const;
|
||||
void ParkSetOpen(bool isOpen) const;
|
||||
void CreateDucks(int count) const;
|
||||
void RemoveParkFences() const;
|
||||
};
|
||||
} // namespace OpenRCT2::GameActions
|
||||
@@ -143,7 +143,7 @@ money64 ClearAction::ClearSceneryFromTile(const CoordsXY& tilePos, bool executin
|
||||
case TileElementType::Path:
|
||||
if (_itemsToClear & CLEARABLE_ITEMS::kSceneryFootpath)
|
||||
{
|
||||
auto footpathRemoveAction = FootpathRemoveAction({ tilePos, tileElement->GetBaseZ() });
|
||||
auto footpathRemoveAction = GameActions::FootpathRemoveAction({ tilePos, tileElement->GetBaseZ() });
|
||||
footpathRemoveAction.SetFlags(GetFlags());
|
||||
|
||||
auto res = executing ? GameActions::ExecuteNested(&footpathRemoveAction)
|
||||
|
||||
@@ -22,172 +22,171 @@
|
||||
#include "../world/tile_element/PathElement.h"
|
||||
#include "BannerRemoveAction.h"
|
||||
|
||||
using namespace OpenRCT2;
|
||||
|
||||
FootpathRemoveAction::FootpathRemoveAction(const CoordsXYZ& location)
|
||||
: _loc(location)
|
||||
namespace OpenRCT2::GameActions
|
||||
{
|
||||
}
|
||||
|
||||
void FootpathRemoveAction::AcceptParameters(GameActionParameterVisitor& visitor)
|
||||
{
|
||||
visitor.Visit(_loc);
|
||||
}
|
||||
|
||||
uint16_t FootpathRemoveAction::GetActionFlags() const
|
||||
{
|
||||
return GameAction::GetActionFlags();
|
||||
}
|
||||
|
||||
void FootpathRemoveAction::Serialise(DataSerialiser& stream)
|
||||
{
|
||||
GameAction::Serialise(stream);
|
||||
|
||||
stream << DS_TAG(_loc);
|
||||
}
|
||||
|
||||
GameActions::Result FootpathRemoveAction::Query() const
|
||||
{
|
||||
auto res = GameActions::Result();
|
||||
res.Cost = 0;
|
||||
res.Expenditure = ExpenditureType::landscaping;
|
||||
res.Position = { _loc.x + 16, _loc.y + 16, _loc.z };
|
||||
|
||||
if (!LocationValid(_loc))
|
||||
FootpathRemoveAction::FootpathRemoveAction(const CoordsXYZ& location)
|
||||
: _loc(location)
|
||||
{
|
||||
return GameActions::Result(
|
||||
GameActions::Status::InvalidParameters, STR_CANT_REMOVE_FOOTPATH_FROM_HERE, STR_OFF_EDGE_OF_MAP);
|
||||
}
|
||||
|
||||
if (!(gLegacyScene == LegacyScene::scenarioEditor || getGameState().cheats.sandboxMode) && !MapIsLocationOwned(_loc))
|
||||
void FootpathRemoveAction::AcceptParameters(GameActionParameterVisitor& visitor)
|
||||
{
|
||||
return GameActions::Result(
|
||||
GameActions::Status::NotOwned, STR_CANT_REMOVE_FOOTPATH_FROM_HERE, STR_LAND_NOT_OWNED_BY_PARK);
|
||||
visitor.Visit(_loc);
|
||||
}
|
||||
|
||||
TileElement* footpathElement = GetFootpathElement();
|
||||
if (footpathElement == nullptr)
|
||||
uint16_t FootpathRemoveAction::GetActionFlags() const
|
||||
{
|
||||
return GameActions::Result(
|
||||
GameActions::Status::InvalidParameters, STR_CANT_REMOVE_FOOTPATH_FROM_HERE, STR_ERR_PATH_ELEMENT_NOT_FOUND);
|
||||
return GameAction::GetActionFlags();
|
||||
}
|
||||
|
||||
res.Cost = GetRefundPrice(footpathElement);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
GameActions::Result FootpathRemoveAction::Execute() const
|
||||
{
|
||||
auto res = GameActions::Result();
|
||||
res.Cost = 0;
|
||||
res.Expenditure = ExpenditureType::landscaping;
|
||||
res.Position = { _loc.x + 16, _loc.y + 16, _loc.z };
|
||||
|
||||
if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST))
|
||||
void FootpathRemoveAction::Serialise(DataSerialiser& stream)
|
||||
{
|
||||
FootpathInterruptPeeps(_loc);
|
||||
FootpathRemoveLitter(_loc);
|
||||
GameAction::Serialise(stream);
|
||||
|
||||
stream << DS_TAG(_loc);
|
||||
}
|
||||
|
||||
TileElement* footpathElement = GetFootpathElement();
|
||||
if (footpathElement != nullptr)
|
||||
Result FootpathRemoveAction::Query() const
|
||||
{
|
||||
FootpathQueueChainReset();
|
||||
auto bannerRes = RemoveBannersAtElement(_loc, footpathElement);
|
||||
if (bannerRes.Error == GameActions::Status::Ok)
|
||||
auto res = Result();
|
||||
res.Cost = 0;
|
||||
res.Expenditure = ExpenditureType::landscaping;
|
||||
res.Position = { _loc.x + 16, _loc.y + 16, _loc.z };
|
||||
|
||||
if (!LocationValid(_loc))
|
||||
{
|
||||
res.Cost += bannerRes.Cost;
|
||||
return Result(Status::InvalidParameters, STR_CANT_REMOVE_FOOTPATH_FROM_HERE, STR_OFF_EDGE_OF_MAP);
|
||||
}
|
||||
FootpathRemoveEdgesAt(_loc, footpathElement);
|
||||
MapInvalidateTileFull(_loc);
|
||||
TileElementRemove(footpathElement);
|
||||
FootpathUpdateQueueChains();
|
||||
|
||||
auto& gameState = getGameState();
|
||||
// Remove the spawn point (if there is one in the current tile)
|
||||
gameState.peepSpawns.erase(
|
||||
std::remove_if(
|
||||
gameState.peepSpawns.begin(), gameState.peepSpawns.end(),
|
||||
[this](const CoordsXYZ& spawn) {
|
||||
{
|
||||
return spawn.ToTileStart() == _loc.ToTileStart();
|
||||
}
|
||||
}),
|
||||
gameState.peepSpawns.end());
|
||||
}
|
||||
else
|
||||
{
|
||||
return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REMOVE_FOOTPATH_FROM_HERE, kStringIdNone);
|
||||
}
|
||||
|
||||
res.Cost += GetRefundPrice(footpathElement);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
TileElement* FootpathRemoveAction::GetFootpathElement() const
|
||||
{
|
||||
bool getGhostPath = GetFlags() & GAME_COMMAND_FLAG_GHOST;
|
||||
|
||||
// FIXME: This is a hack to get the footpath element. It should be done in a better way.
|
||||
TileElement* tileElement = MapGetFootpathElement(_loc)->as<TileElement>();
|
||||
TileElement* footpathElement = nullptr;
|
||||
if (tileElement != nullptr)
|
||||
{
|
||||
if (getGhostPath && !tileElement->IsGhost())
|
||||
if (!(gLegacyScene == LegacyScene::scenarioEditor || getGameState().cheats.sandboxMode) && !MapIsLocationOwned(_loc))
|
||||
{
|
||||
while (!(tileElement++)->IsLastForTile())
|
||||
return Result(Status::NotOwned, STR_CANT_REMOVE_FOOTPATH_FROM_HERE, STR_LAND_NOT_OWNED_BY_PARK);
|
||||
}
|
||||
|
||||
TileElement* footpathElement = GetFootpathElement();
|
||||
if (footpathElement == nullptr)
|
||||
{
|
||||
return Result(Status::InvalidParameters, STR_CANT_REMOVE_FOOTPATH_FROM_HERE, STR_ERR_PATH_ELEMENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
res.Cost = GetRefundPrice(footpathElement);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
Result FootpathRemoveAction::Execute() const
|
||||
{
|
||||
auto res = Result();
|
||||
res.Cost = 0;
|
||||
res.Expenditure = ExpenditureType::landscaping;
|
||||
res.Position = { _loc.x + 16, _loc.y + 16, _loc.z };
|
||||
|
||||
if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST))
|
||||
{
|
||||
FootpathInterruptPeeps(_loc);
|
||||
FootpathRemoveLitter(_loc);
|
||||
}
|
||||
|
||||
TileElement* footpathElement = GetFootpathElement();
|
||||
if (footpathElement != nullptr)
|
||||
{
|
||||
FootpathQueueChainReset();
|
||||
auto bannerRes = RemoveBannersAtElement(_loc, footpathElement);
|
||||
if (bannerRes.Error == Status::Ok)
|
||||
{
|
||||
if (tileElement->GetType() != TileElementType::Path && !tileElement->IsGhost())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
footpathElement = tileElement;
|
||||
break;
|
||||
res.Cost += bannerRes.Cost;
|
||||
}
|
||||
FootpathRemoveEdgesAt(_loc, footpathElement);
|
||||
MapInvalidateTileFull(_loc);
|
||||
TileElementRemove(footpathElement);
|
||||
FootpathUpdateQueueChains();
|
||||
|
||||
auto& gameState = getGameState();
|
||||
// Remove the spawn point (if there is one in the current tile)
|
||||
gameState.peepSpawns.erase(
|
||||
std::remove_if(
|
||||
gameState.peepSpawns.begin(), gameState.peepSpawns.end(),
|
||||
[this](const CoordsXYZ& spawn) {
|
||||
{
|
||||
return spawn.ToTileStart() == _loc.ToTileStart();
|
||||
}
|
||||
}),
|
||||
gameState.peepSpawns.end());
|
||||
}
|
||||
else
|
||||
{
|
||||
footpathElement = tileElement;
|
||||
return Result(Status::InvalidParameters, STR_CANT_REMOVE_FOOTPATH_FROM_HERE, kStringIdNone);
|
||||
}
|
||||
|
||||
res.Cost += GetRefundPrice(footpathElement);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
return footpathElement;
|
||||
}
|
||||
|
||||
money64 FootpathRemoveAction::GetRefundPrice(TileElement* footpathElement) const
|
||||
{
|
||||
money64 cost = -10.00_GBP;
|
||||
return cost;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* rct2: 0x006BA23E
|
||||
*/
|
||||
GameActions::Result FootpathRemoveAction::RemoveBannersAtElement(const CoordsXY& loc, TileElement* tileElement) const
|
||||
{
|
||||
auto result = GameActions::Result();
|
||||
while (!(tileElement++)->IsLastForTile())
|
||||
TileElement* FootpathRemoveAction::GetFootpathElement() const
|
||||
{
|
||||
if (tileElement->GetType() == TileElementType::Path)
|
||||
return result;
|
||||
bool getGhostPath = GetFlags() & GAME_COMMAND_FLAG_GHOST;
|
||||
|
||||
if (tileElement->GetType() != TileElementType::Banner)
|
||||
continue;
|
||||
|
||||
auto bannerRemoveAction = BannerRemoveAction({ loc, tileElement->GetBaseZ(), tileElement->AsBanner()->GetPosition() });
|
||||
bool isGhost = tileElement->IsGhost();
|
||||
auto bannerFlags = GetFlags() | (isGhost ? static_cast<uint32_t>(GAME_COMMAND_FLAG_GHOST) : 0);
|
||||
bannerRemoveAction.SetFlags(bannerFlags);
|
||||
auto res = GameActions::ExecuteNested(&bannerRemoveAction);
|
||||
// Ghost removal is free
|
||||
if (res.Error == GameActions::Status::Ok && !isGhost)
|
||||
// FIXME: This is a hack to get the footpath element. It should be done in a better way.
|
||||
TileElement* tileElement = MapGetFootpathElement(_loc)->as<TileElement>();
|
||||
TileElement* footpathElement = nullptr;
|
||||
if (tileElement != nullptr)
|
||||
{
|
||||
result.Cost += res.Cost;
|
||||
if (getGhostPath && !tileElement->IsGhost())
|
||||
{
|
||||
while (!(tileElement++)->IsLastForTile())
|
||||
{
|
||||
if (tileElement->GetType() != TileElementType::Path && !tileElement->IsGhost())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
footpathElement = tileElement;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
footpathElement = tileElement;
|
||||
}
|
||||
}
|
||||
tileElement--;
|
||||
|
||||
return footpathElement;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
money64 FootpathRemoveAction::GetRefundPrice(TileElement* footpathElement) const
|
||||
{
|
||||
money64 cost = -10.00_GBP;
|
||||
return cost;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* rct2: 0x006BA23E
|
||||
*/
|
||||
Result FootpathRemoveAction::RemoveBannersAtElement(const CoordsXY& loc, TileElement* tileElement) const
|
||||
{
|
||||
auto result = Result();
|
||||
while (!(tileElement++)->IsLastForTile())
|
||||
{
|
||||
if (tileElement->GetType() == TileElementType::Path)
|
||||
return result;
|
||||
|
||||
if (tileElement->GetType() != TileElementType::Banner)
|
||||
continue;
|
||||
|
||||
auto bannerRemoveAction = BannerRemoveAction(
|
||||
{ loc, tileElement->GetBaseZ(), tileElement->AsBanner()->GetPosition() });
|
||||
bool isGhost = tileElement->IsGhost();
|
||||
auto bannerFlags = GetFlags() | (isGhost ? static_cast<uint32_t>(GAME_COMMAND_FLAG_GHOST) : 0);
|
||||
bannerRemoveAction.SetFlags(bannerFlags);
|
||||
auto res = ExecuteNested(&bannerRemoveAction);
|
||||
// Ghost removal is free
|
||||
if (res.Error == Status::Ok && !isGhost)
|
||||
{
|
||||
result.Cost += res.Cost;
|
||||
}
|
||||
tileElement--;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
} // namespace OpenRCT2::GameActions
|
||||
@@ -12,25 +12,28 @@
|
||||
#include "../management/Finance.h"
|
||||
#include "GameAction.h"
|
||||
|
||||
class FootpathRemoveAction final : public GameActionBase<GameCommand::RemovePath>
|
||||
namespace OpenRCT2::GameActions
|
||||
{
|
||||
private:
|
||||
CoordsXYZ _loc;
|
||||
class FootpathRemoveAction final : public GameActionBase<GameCommand::RemovePath>
|
||||
{
|
||||
private:
|
||||
CoordsXYZ _loc;
|
||||
|
||||
public:
|
||||
FootpathRemoveAction() = default;
|
||||
FootpathRemoveAction(const CoordsXYZ& location);
|
||||
public:
|
||||
FootpathRemoveAction() = default;
|
||||
FootpathRemoveAction(const CoordsXYZ& location);
|
||||
|
||||
void AcceptParameters(GameActionParameterVisitor& visitor) override;
|
||||
void AcceptParameters(GameActionParameterVisitor& visitor) override;
|
||||
|
||||
uint16_t GetActionFlags() const override;
|
||||
uint16_t GetActionFlags() const override;
|
||||
|
||||
void Serialise(DataSerialiser& stream) override;
|
||||
OpenRCT2::GameActions::Result Query() const override;
|
||||
OpenRCT2::GameActions::Result Execute() const override;
|
||||
void Serialise(DataSerialiser& stream) override;
|
||||
Result Query() const override;
|
||||
Result Execute() const override;
|
||||
|
||||
private:
|
||||
OpenRCT2::TileElement* GetFootpathElement() const;
|
||||
money64 GetRefundPrice(OpenRCT2::TileElement* footpathElement) const;
|
||||
OpenRCT2::GameActions::Result RemoveBannersAtElement(const CoordsXY& loc, OpenRCT2::TileElement* tileElement) const;
|
||||
};
|
||||
private:
|
||||
TileElement* GetFootpathElement() const;
|
||||
money64 GetRefundPrice(TileElement* footpathElement) const;
|
||||
Result RemoveBannersAtElement(const CoordsXY& loc, TileElement* tileElement) const;
|
||||
};
|
||||
} // namespace OpenRCT2::GameActions
|
||||
@@ -31,8 +31,6 @@
|
||||
|
||||
#include <iterator>
|
||||
|
||||
using namespace OpenRCT2;
|
||||
|
||||
namespace OpenRCT2::GameActions
|
||||
{
|
||||
struct QueuedGameAction
|
||||
@@ -143,8 +141,8 @@ namespace OpenRCT2::GameActions
|
||||
|
||||
Guard::Assert(action != nullptr);
|
||||
|
||||
GameActions::Result result = Execute(action);
|
||||
if (result.Error == GameActions::Status::Ok && NetworkGetMode() == NETWORK_MODE_SERVER)
|
||||
Result result = Execute(action);
|
||||
if (result.Error == Status::Ok && NetworkGetMode() == NETWORK_MODE_SERVER)
|
||||
{
|
||||
// Relay this action to all other clients.
|
||||
NetworkSendGameAction(action);
|
||||
@@ -161,7 +159,7 @@ namespace OpenRCT2::GameActions
|
||||
|
||||
GameAction::Ptr Clone(const GameAction* action)
|
||||
{
|
||||
std::unique_ptr<GameAction> ga = GameActions::Create(action->GetType());
|
||||
std::unique_ptr<GameAction> ga = Create(action->GetType());
|
||||
ga->SetCallback(action->GetCallback());
|
||||
|
||||
// Serialise action data into stream.
|
||||
@@ -184,21 +182,21 @@ namespace OpenRCT2::GameActions
|
||||
return true;
|
||||
if (getGameState().cheats.buildInPauseMode)
|
||||
return true;
|
||||
if (actionFlags & GameActions::Flags::AllowWhilePaused)
|
||||
if (actionFlags & Flags::AllowWhilePaused)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static GameActions::Result QueryInternal(const GameAction* action, bool topLevel)
|
||||
static Result QueryInternal(const GameAction* action, bool topLevel)
|
||||
{
|
||||
Guard::ArgumentNotNull(action);
|
||||
|
||||
uint16_t actionFlags = action->GetActionFlags();
|
||||
if (topLevel && !CheckActionInPausedMode(actionFlags))
|
||||
{
|
||||
GameActions::Result result = GameActions::Result();
|
||||
Result result = Result();
|
||||
|
||||
result.Error = GameActions::Status::GamePaused;
|
||||
result.Error = Status::GamePaused;
|
||||
result.ErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE;
|
||||
result.ErrorMessage = STR_CONSTRUCTION_NOT_POSSIBLE_WHILE_GAME_IS_PAUSED;
|
||||
|
||||
@@ -207,11 +205,11 @@ namespace OpenRCT2::GameActions
|
||||
|
||||
auto result = action->Query();
|
||||
|
||||
if (result.Error == GameActions::Status::Ok)
|
||||
if (result.Error == Status::Ok)
|
||||
{
|
||||
if (!FinanceCheckAffordability(result.Cost, action->GetFlags()))
|
||||
{
|
||||
result.Error = GameActions::Status::InsufficientFunds;
|
||||
result.Error = Status::InsufficientFunds;
|
||||
result.ErrorTitle = STR_CANT_DO_THIS;
|
||||
result.ErrorMessage = STR_NOT_ENOUGH_CASH_REQUIRES;
|
||||
Formatter(result.ErrorMessageArgs.data()).Add<uint32_t>(result.Cost);
|
||||
@@ -220,12 +218,12 @@ namespace OpenRCT2::GameActions
|
||||
return result;
|
||||
}
|
||||
|
||||
GameActions::Result Query(const GameAction* action)
|
||||
Result Query(const GameAction* action)
|
||||
{
|
||||
return QueryInternal(action, true);
|
||||
}
|
||||
|
||||
GameActions::Result QueryNested(const GameAction* action)
|
||||
Result QueryNested(const GameAction* action)
|
||||
{
|
||||
return QueryInternal(action, false);
|
||||
}
|
||||
@@ -261,13 +259,13 @@ namespace OpenRCT2::GameActions
|
||||
action->Serialise(ds);
|
||||
}
|
||||
|
||||
static void LogActionFinish(ActionLogContext& ctx, const GameAction* action, const GameActions::Result& result)
|
||||
static void LogActionFinish(ActionLogContext& ctx, const GameAction* action, const Result& result)
|
||||
{
|
||||
MemoryStream& output = ctx.output;
|
||||
|
||||
char temp[128] = {};
|
||||
|
||||
if (result.Error != GameActions::Status::Ok)
|
||||
if (result.Error != Status::Ok)
|
||||
{
|
||||
snprintf(temp, sizeof(temp), ") Failed, %u", static_cast<uint32_t>(result.Error));
|
||||
}
|
||||
@@ -284,7 +282,7 @@ namespace OpenRCT2::GameActions
|
||||
NetworkAppendServerLog(text);
|
||||
}
|
||||
|
||||
static GameActions::Result ExecuteInternal(const GameAction* action, bool topLevel)
|
||||
static Result ExecuteInternal(const GameAction* action, bool topLevel)
|
||||
{
|
||||
Guard::ArgumentNotNull(action);
|
||||
|
||||
@@ -292,7 +290,7 @@ namespace OpenRCT2::GameActions
|
||||
uint32_t flags = action->GetFlags();
|
||||
|
||||
// Some actions are not recorded in the replay.
|
||||
const auto ignoreForReplays = (actionFlags & GameActions::Flags::IgnoreForReplays) != 0;
|
||||
const auto ignoreForReplays = (actionFlags & Flags::IgnoreForReplays) != 0;
|
||||
|
||||
auto* replayManager = OpenRCT2::GetContext()->GetReplayManager();
|
||||
if (replayManager != nullptr && (replayManager->IsReplaying() || replayManager->IsNormalising()))
|
||||
@@ -301,8 +299,8 @@ namespace OpenRCT2::GameActions
|
||||
if ((flags & GAME_COMMAND_FLAG_REPLAY) == 0 && !ignoreForReplays)
|
||||
{
|
||||
// TODO: Introduce proper error.
|
||||
auto result = GameActions::Result();
|
||||
result.Error = GameActions::Status::GamePaused;
|
||||
auto result = Result();
|
||||
result.Error = Status::GamePaused;
|
||||
result.ErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE;
|
||||
result.ErrorMessage = STR_CONSTRUCTION_NOT_POSSIBLE_WHILE_GAME_IS_PAUSED;
|
||||
|
||||
@@ -310,17 +308,16 @@ namespace OpenRCT2::GameActions
|
||||
}
|
||||
}
|
||||
|
||||
GameActions::Result result = QueryInternal(action, topLevel);
|
||||
Result result = QueryInternal(action, topLevel);
|
||||
#ifdef ENABLE_SCRIPTING
|
||||
if (result.Error == GameActions::Status::Ok
|
||||
&& ((NetworkGetMode() == NETWORK_MODE_NONE) || (flags & GAME_COMMAND_FLAG_NETWORKED)))
|
||||
if (result.Error == Status::Ok && ((NetworkGetMode() == NETWORK_MODE_NONE) || (flags & GAME_COMMAND_FLAG_NETWORKED)))
|
||||
{
|
||||
auto& scriptEngine = GetContext()->GetScriptEngine();
|
||||
scriptEngine.RunGameActionHooks(*action, result, false);
|
||||
// Script hooks may now have changed the game action result...
|
||||
}
|
||||
#endif
|
||||
if (result.Error == GameActions::Status::Ok)
|
||||
if (result.Error == Status::Ok)
|
||||
{
|
||||
if (topLevel)
|
||||
{
|
||||
@@ -328,7 +325,7 @@ namespace OpenRCT2::GameActions
|
||||
if (NetworkGetMode() == NETWORK_MODE_CLIENT)
|
||||
{
|
||||
// As a client we have to wait or send it first.
|
||||
if (!(actionFlags & GameActions::Flags::ClientOnly) && !(flags & GAME_COMMAND_FLAG_NETWORKED))
|
||||
if (!(actionFlags & Flags::ClientOnly) && !(flags & GAME_COMMAND_FLAG_NETWORKED))
|
||||
{
|
||||
LOG_VERBOSE("[%s] GameAction::Execute %s (Out)", GetRealm(), action->GetName());
|
||||
NetworkSendGameAction(action);
|
||||
@@ -341,7 +338,7 @@ namespace OpenRCT2::GameActions
|
||||
// If player is the server it would execute right away as where clients execute the commands
|
||||
// at the beginning of the frame, so we have to put them into the queue.
|
||||
// This is also the case when its executed from the UI update.
|
||||
if (!(actionFlags & GameActions::Flags::ClientOnly) && !(flags & GAME_COMMAND_FLAG_NETWORKED))
|
||||
if (!(actionFlags & Flags::ClientOnly) && !(flags & GAME_COMMAND_FLAG_NETWORKED))
|
||||
{
|
||||
LOG_VERBOSE("[%s] GameAction::Execute %s (Queue)", GetRealm(), action->GetName());
|
||||
Enqueue(action, getGameState().currentTicks);
|
||||
@@ -357,7 +354,7 @@ namespace OpenRCT2::GameActions
|
||||
// Execute the action, changing the game state
|
||||
result = action->Execute();
|
||||
#ifdef ENABLE_SCRIPTING
|
||||
if (result.Error == GameActions::Status::Ok)
|
||||
if (result.Error == Status::Ok)
|
||||
{
|
||||
auto& scriptEngine = GetContext()->GetScriptEngine();
|
||||
scriptEngine.RunGameActionHooks(*action, result, true);
|
||||
@@ -372,13 +369,13 @@ namespace OpenRCT2::GameActions
|
||||
return result;
|
||||
|
||||
// Update money balance
|
||||
if (result.Error == GameActions::Status::Ok && FinanceCheckMoneyRequired(flags) && result.Cost != 0)
|
||||
if (result.Error == Status::Ok && FinanceCheckMoneyRequired(flags) && result.Cost != 0)
|
||||
{
|
||||
FinancePayment(result.Cost, result.Expenditure);
|
||||
MoneyEffect::Create(result.Cost, result.Position);
|
||||
}
|
||||
|
||||
if (!(actionFlags & GameActions::Flags::ClientOnly) && result.Error == GameActions::Status::Ok)
|
||||
if (!(actionFlags & Flags::ClientOnly) && result.Error == Status::Ok)
|
||||
{
|
||||
if (NetworkGetMode() != NETWORK_MODE_NONE)
|
||||
{
|
||||
@@ -448,7 +445,7 @@ namespace OpenRCT2::GameActions
|
||||
}
|
||||
}
|
||||
|
||||
if (result.Error != GameActions::Status::Ok && shouldShowError)
|
||||
if (result.Error != Status::Ok && shouldShowError)
|
||||
{
|
||||
auto windowManager = Ui::GetWindowManager();
|
||||
windowManager->ShowError(result.GetErrorTitle(), result.GetErrorMessage());
|
||||
@@ -457,12 +454,12 @@ namespace OpenRCT2::GameActions
|
||||
return result;
|
||||
}
|
||||
|
||||
GameActions::Result Execute(const GameAction* action)
|
||||
Result Execute(const GameAction* action)
|
||||
{
|
||||
return ExecuteInternal(action, true);
|
||||
}
|
||||
|
||||
GameActions::Result ExecuteNested(const GameAction* action)
|
||||
Result ExecuteNested(const GameAction* action)
|
||||
{
|
||||
return ExecuteInternal(action, false);
|
||||
}
|
||||
@@ -470,7 +467,7 @@ namespace OpenRCT2::GameActions
|
||||
|
||||
const char* GameAction::GetName() const
|
||||
{
|
||||
return GameActions::GetName(_type);
|
||||
return OpenRCT2::GameActions::GetName(_type);
|
||||
}
|
||||
|
||||
bool GameAction::LocationValid(const CoordsXY& coords) const
|
||||
@@ -479,10 +476,10 @@ bool GameAction::LocationValid(const CoordsXY& coords) const
|
||||
if (!result)
|
||||
return false;
|
||||
#ifdef ENABLE_SCRIPTING
|
||||
auto& hookEngine = GetContext()->GetScriptEngine().GetHookEngine();
|
||||
auto& hookEngine = OpenRCT2::GetContext()->GetScriptEngine().GetHookEngine();
|
||||
if (hookEngine.HasSubscriptions(OpenRCT2::Scripting::HookType::actionLocation))
|
||||
{
|
||||
auto ctx = GetContext()->GetScriptEngine().GetContext();
|
||||
auto ctx = OpenRCT2::GetContext()->GetScriptEngine().GetContext();
|
||||
|
||||
// Create event args object
|
||||
auto obj = OpenRCT2::Scripting::DukObject(ctx);
|
||||
@@ -492,7 +489,7 @@ bool GameAction::LocationValid(const CoordsXY& coords) const
|
||||
obj.Set("type", EnumValue(_type));
|
||||
|
||||
auto flags = GetActionFlags();
|
||||
obj.Set("isClientOnly", (flags & GameActions::Flags::ClientOnly) != 0);
|
||||
obj.Set("isClientOnly", (flags & OpenRCT2::GameActions::Flags::ClientOnly) != 0);
|
||||
obj.Set("result", true);
|
||||
|
||||
// Call the subscriptions
|
||||
|
||||
@@ -288,11 +288,11 @@ namespace OpenRCT2::GameActions
|
||||
GameAction::Ptr Clone(const GameAction* action);
|
||||
|
||||
// This should be used if a round trip is to be expected.
|
||||
OpenRCT2::GameActions::Result Query(const GameAction* action);
|
||||
OpenRCT2::GameActions::Result Execute(const GameAction* action);
|
||||
Result Query(const GameAction* action);
|
||||
Result Execute(const GameAction* action);
|
||||
|
||||
// This should be used from within game actions.
|
||||
OpenRCT2::GameActions::Result QueryNested(const GameAction* action);
|
||||
OpenRCT2::GameActions::Result ExecuteNested(const GameAction* action);
|
||||
Result QueryNested(const GameAction* action);
|
||||
Result ExecuteNested(const GameAction* action);
|
||||
|
||||
} // namespace OpenRCT2::GameActions
|
||||
@@ -94,8 +94,6 @@
|
||||
|
||||
#include <array>
|
||||
|
||||
using namespace OpenRCT2;
|
||||
|
||||
namespace OpenRCT2::GameActions
|
||||
{
|
||||
struct GameActionEntry
|
||||
|
||||
@@ -8,7 +8,7 @@ using namespace OpenRCT2;
|
||||
|
||||
namespace OpenRCT2::GameActions
|
||||
{
|
||||
Result::Result(GameActions::Status error, StringId title, StringId message, uint8_t* args /*= nullptr*/)
|
||||
Result::Result(Status error, StringId title, StringId message, uint8_t* args /*= nullptr*/)
|
||||
: Error(error)
|
||||
, ErrorTitle(title)
|
||||
, ErrorMessage(message)
|
||||
@@ -33,12 +33,12 @@ namespace OpenRCT2::GameActions
|
||||
}
|
||||
};
|
||||
|
||||
std::string GameActions::Result::GetErrorTitle() const
|
||||
std::string Result::GetErrorTitle() const
|
||||
{
|
||||
return std::visit(StringVariantVisitor{ ErrorMessageArgs.data() }, ErrorTitle);
|
||||
}
|
||||
|
||||
std::string GameActions::Result::GetErrorMessage() const
|
||||
std::string Result::GetErrorMessage() const
|
||||
{
|
||||
return std::visit(StringVariantVisitor{ ErrorMessageArgs.data() }, ErrorMessage);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
*
|
||||
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
||||
*****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../management/Finance.h"
|
||||
@@ -56,7 +57,7 @@ namespace OpenRCT2::GameActions
|
||||
public:
|
||||
using StringVariant = std::variant<std::string, StringId>;
|
||||
|
||||
OpenRCT2::GameActions::Status Error = OpenRCT2::GameActions::Status::Ok;
|
||||
Status Error = Status::Ok;
|
||||
StringVariant ErrorTitle = kStringIdNone;
|
||||
StringVariant ErrorMessage = kStringIdNone;
|
||||
std::array<uint8_t, 32> ErrorMessageArgs{};
|
||||
@@ -74,7 +75,7 @@ namespace OpenRCT2::GameActions
|
||||
#endif
|
||||
|
||||
Result() = default;
|
||||
Result(OpenRCT2::GameActions::Status error, StringId title, StringId message, uint8_t* args = nullptr);
|
||||
Result(Status error, StringId title, StringId message, uint8_t* args = nullptr);
|
||||
|
||||
std::string GetErrorTitle() const;
|
||||
std::string GetErrorMessage() const;
|
||||
|
||||
@@ -790,7 +790,7 @@ static void ConsoleCommandSet(InteractiveConsole& console, const arguments_t& ar
|
||||
money64 money = ToMoney64FromGBP(double_val[0]);
|
||||
if (gameState.park.cash != money)
|
||||
{
|
||||
ConsoleSetVariableAction<CheatSetAction>(console, varName, CheatType::SetMoney, money);
|
||||
ConsoleSetVariableAction<GameActions::CheatSetAction>(console, varName, CheatType::SetMoney, money);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -876,7 +876,7 @@ static void ConsoleCommandSet(InteractiveConsole& console, const arguments_t& ar
|
||||
}
|
||||
else if (varName == "no_money" && InvalidArguments(&invalidArgs, int_valid[0]))
|
||||
{
|
||||
ConsoleSetVariableAction<CheatSetAction>(console, varName, CheatType::NoMoney, int_val[0] != 0);
|
||||
ConsoleSetVariableAction<GameActions::CheatSetAction>(console, varName, CheatType::NoMoney, int_val[0] != 0);
|
||||
}
|
||||
else if (varName == "difficult_park_rating" && InvalidArguments(&invalidArgs, int_valid[0]))
|
||||
{
|
||||
@@ -957,7 +957,8 @@ static void ConsoleCommandSet(InteractiveConsole& console, const arguments_t& ar
|
||||
{
|
||||
if (getGameState().cheats.sandboxMode != (int_val[0] != 0))
|
||||
{
|
||||
ConsoleSetVariableAction<CheatSetAction>(console, varName, CheatType::SandboxMode, int_val[0] != 0);
|
||||
ConsoleSetVariableAction<GameActions::CheatSetAction>(
|
||||
console, varName, CheatType::SandboxMode, int_val[0] != 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -968,7 +969,8 @@ static void ConsoleCommandSet(InteractiveConsole& console, const arguments_t& ar
|
||||
{
|
||||
if (getGameState().cheats.disableClearanceChecks != (int_val[0] != 0))
|
||||
{
|
||||
ConsoleSetVariableAction<CheatSetAction>(console, varName, CheatType::DisableClearanceChecks, int_val[0] != 0);
|
||||
ConsoleSetVariableAction<GameActions::CheatSetAction>(
|
||||
console, varName, CheatType::DisableClearanceChecks, int_val[0] != 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -979,7 +981,8 @@ static void ConsoleCommandSet(InteractiveConsole& console, const arguments_t& ar
|
||||
{
|
||||
if (getGameState().cheats.disableSupportLimits != (int_val[0] != 0))
|
||||
{
|
||||
ConsoleSetVariableAction<CheatSetAction>(console, varName, CheatType::DisableSupportLimits, int_val[0] != 0);
|
||||
ConsoleSetVariableAction<GameActions::CheatSetAction>(
|
||||
console, varName, CheatType::DisableSupportLimits, int_val[0] != 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -980,7 +980,7 @@ static GameActions::Result TrackDesignPlaceSceneryElementRemoveGhost(
|
||||
break;
|
||||
case ObjectType::paths:
|
||||
case ObjectType::footpathSurface:
|
||||
ga = std::make_unique<FootpathRemoveAction>(CoordsXYZ{ mapCoord.x, mapCoord.y, z });
|
||||
ga = std::make_unique<GameActions::FootpathRemoveAction>(CoordsXYZ{ mapCoord.x, mapCoord.y, z });
|
||||
break;
|
||||
default:
|
||||
return GameActions::Result();
|
||||
|
||||
@@ -1525,7 +1525,7 @@ void ClearElementAt(const CoordsXY& loc, TileElement** elementPtr)
|
||||
break;
|
||||
case TileElementType::Banner:
|
||||
{
|
||||
auto bannerRemoveAction = BannerRemoveAction(
|
||||
auto bannerRemoveAction = GameActions::BannerRemoveAction(
|
||||
{ loc.x, loc.y, element->GetBaseZ(), element->AsBanner()->GetPosition() });
|
||||
auto result = GameActions::ExecuteNested(&bannerRemoveAction);
|
||||
// If asking nicely did not work, forcibly remove this to avoid an infinite loop.
|
||||
|
||||
@@ -292,7 +292,7 @@ void SceneryRemoveGhostToolPlacement()
|
||||
{
|
||||
gSceneryGhostType &= ~SCENERY_GHOST_FLAG_4;
|
||||
|
||||
auto removeSceneryAction = BannerRemoveAction({ gSceneryGhostPosition, gSceneryPlaceRotation });
|
||||
auto removeSceneryAction = GameActions::BannerRemoveAction({ gSceneryGhostPosition, gSceneryPlaceRotation });
|
||||
removeSceneryAction.SetFlags(
|
||||
GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_NO_SPEND | GAME_COMMAND_FLAG_GHOST);
|
||||
GameActions::Execute(&removeSceneryAction);
|
||||
|
||||
Reference in new issue
Block a user