From 238b3979684f9948c2acf98f3009d3284216a0b5 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Tue, 26 Aug 2025 15:55:26 +0200 Subject: [PATCH] Move scenery game actions into GameActions namespace --- .../interface/ViewportInteraction.cpp | 6 +- src/openrct2-ui/windows/Scenery.cpp | 137 ++- src/openrct2-ui/windows/Sign.cpp | 12 +- src/openrct2/actions/ClearAction.cpp | 6 +- .../actions/LargeSceneryPlaceAction.cpp | 605 ++++++----- .../actions/LargeSceneryPlaceAction.h | 61 +- .../actions/LargeSceneryRemoveAction.cpp | 323 +++--- .../actions/LargeSceneryRemoveAction.h | 33 +- .../actions/LargeScenerySetColourAction.cpp | 225 ++-- .../actions/LargeScenerySetColourAction.h | 41 +- .../actions/ScenerySetRestrictedAction.cpp | 77 +- .../actions/ScenerySetRestrictedAction.h | 29 +- src/openrct2/actions/SignSetNameAction.cpp | 140 +-- src/openrct2/actions/SignSetNameAction.h | 29 +- src/openrct2/actions/SignSetStyleAction.cpp | 198 ++-- src/openrct2/actions/SignSetStyleAction.h | 33 +- .../actions/SmallSceneryPlaceAction.cpp | 760 +++++++------- .../actions/SmallSceneryPlaceAction.h | 55 +- .../actions/SmallSceneryRemoveAction.cpp | 222 ++-- .../actions/SmallSceneryRemoveAction.h | 35 +- .../actions/SmallScenerySetColourAction.cpp | 163 +-- .../actions/SmallScenerySetColourAction.h | 45 +- src/openrct2/actions/WallPlaceAction.cpp | 976 +++++++++--------- src/openrct2/actions/WallPlaceAction.h | 88 +- src/openrct2/actions/WallRemoveAction.cpp | 145 ++- src/openrct2/actions/WallRemoveAction.h | 29 +- src/openrct2/actions/WallSetColourAction.cpp | 226 ++-- src/openrct2/actions/WallSetColourAction.h | 33 +- src/openrct2/ride/TrackDesign.cpp | 16 +- src/openrct2/scripting/ScriptEngine.cpp | 4 +- src/openrct2/world/Map.cpp | 4 +- src/openrct2/world/Scenery.cpp | 6 +- 32 files changed, 2386 insertions(+), 2376 deletions(-) diff --git a/src/openrct2-ui/interface/ViewportInteraction.cpp b/src/openrct2-ui/interface/ViewportInteraction.cpp index cd2521f76b..cd15a06030 100644 --- a/src/openrct2-ui/interface/ViewportInteraction.cpp +++ b/src/openrct2-ui/interface/ViewportInteraction.cpp @@ -622,7 +622,7 @@ namespace OpenRCT2::Ui */ static void ViewportInteractionRemoveScenery(const SmallSceneryElement& smallSceneryElement, const CoordsXY& mapCoords) { - auto removeSceneryAction = SmallSceneryRemoveAction( + auto removeSceneryAction = GameActions::SmallSceneryRemoveAction( { mapCoords.x, mapCoords.y, smallSceneryElement.GetBaseZ() }, smallSceneryElement.GetSceneryQuadrant(), smallSceneryElement.GetEntryIndex()); @@ -701,7 +701,7 @@ namespace OpenRCT2::Ui else { CoordsXYZD wallLocation = { mapCoords.x, mapCoords.y, wallElement.GetBaseZ(), wallElement.GetDirection() }; - auto wallRemoveAction = WallRemoveAction(wallLocation); + auto wallRemoveAction = GameActions::WallRemoveAction(wallLocation); GameActions::Execute(&wallRemoveAction); } } @@ -721,7 +721,7 @@ namespace OpenRCT2::Ui } else { - auto removeSceneryAction = LargeSceneryRemoveAction( + auto removeSceneryAction = GameActions::LargeSceneryRemoveAction( { mapCoords.x, mapCoords.y, largeSceneryElement.GetBaseZ(), largeSceneryElement.GetDirection() }, largeSceneryElement.GetSequenceIndex()); GameActions::Execute(&removeSceneryAction); diff --git a/src/openrct2-ui/windows/Scenery.cpp b/src/openrct2-ui/windows/Scenery.cpp index 178c44b69c..ac4fe463ac 100644 --- a/src/openrct2-ui/windows/Scenery.cpp +++ b/src/openrct2-ui/windows/Scenery.cpp @@ -62,7 +62,7 @@ #include #include -using namespace OpenRCT2::Numerics; +using namespace Numerics; namespace OpenRCT2::Ui::Windows { @@ -199,7 +199,7 @@ namespace OpenRCT2::Ui::Windows const SceneryGroupEntry* GetSceneryGroupEntry() const { - return OpenRCT2::ObjectManager::GetObjectEntry(SceneryGroupIndex); + return ObjectManager::GetObjectEntry(SceneryGroupIndex); } }; @@ -329,7 +329,8 @@ namespace OpenRCT2::Ui::Windows { const auto newStatus = !IsSceneryItemRestricted(tabSelectedScenery); const auto objectType = GetObjectTypeFromSceneryType(tabSelectedScenery.SceneryType); - auto action = ScenerySetRestrictedAction(objectType, tabSelectedScenery.EntryIndex, newStatus); + auto action = GameActions::ScenerySetRestrictedAction( + objectType, tabSelectedScenery.EntryIndex, newStatus); GameActions::Execute(&action); } break; @@ -554,22 +555,22 @@ namespace OpenRCT2::Ui::Windows else if (tabSelectedScenery.SceneryType == SCENERY_TYPE_LARGE) { gCurrentToolId = static_cast( - OpenRCT2::ObjectManager::GetObjectEntry(tabSelectedScenery.EntryIndex)->tool_id); + ObjectManager::GetObjectEntry(tabSelectedScenery.EntryIndex)->tool_id); } else if (tabSelectedScenery.SceneryType == SCENERY_TYPE_WALL) { gCurrentToolId = static_cast( - OpenRCT2::ObjectManager::GetObjectEntry(tabSelectedScenery.EntryIndex)->tool_id); + ObjectManager::GetObjectEntry(tabSelectedScenery.EntryIndex)->tool_id); } else if (tabSelectedScenery.SceneryType == SCENERY_TYPE_PATH_ITEM) { gCurrentToolId = static_cast( - OpenRCT2::ObjectManager::GetObjectEntry(tabSelectedScenery.EntryIndex)->tool_id); + ObjectManager::GetObjectEntry(tabSelectedScenery.EntryIndex)->tool_id); } else { // small scenery gCurrentToolId = static_cast( - OpenRCT2::ObjectManager::GetObjectEntry(tabSelectedScenery.EntryIndex)->tool_id); + ObjectManager::GetObjectEntry(tabSelectedScenery.EntryIndex)->tool_id); } } else @@ -699,8 +700,7 @@ namespace OpenRCT2::Ui::Windows { widgets[WIDX_SCENERY_BUILD_CLUSTER_BUTTON].type = WidgetType::flatBtn; - auto* sceneryEntry = OpenRCT2::ObjectManager::GetObjectEntry( - tabSelectedScenery.EntryIndex); + auto* sceneryEntry = ObjectManager::GetObjectEntry(tabSelectedScenery.EntryIndex); if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_ROTATABLE)) { widgets[WIDX_SCENERY_ROTATE_OBJECTS_BUTTON].type = WidgetType::flatBtn; @@ -739,8 +739,7 @@ namespace OpenRCT2::Ui::Windows { if (tabSelectedScenery.SceneryType == SCENERY_TYPE_BANNER) { - auto* bannerEntry = OpenRCT2::ObjectManager::GetObjectEntry( - tabSelectedScenery.EntryIndex); + auto* bannerEntry = ObjectManager::GetObjectEntry(tabSelectedScenery.EntryIndex); if (bannerEntry->flags & BANNER_ENTRY_FLAG_HAS_PRIMARY_COLOUR) { widgets[WIDX_SCENERY_PRIMARY_COLOUR_BUTTON].type = WidgetType::colourBtn; @@ -748,8 +747,7 @@ namespace OpenRCT2::Ui::Windows } else if (tabSelectedScenery.SceneryType == SCENERY_TYPE_LARGE) { - auto* sceneryEntry = OpenRCT2::ObjectManager::GetObjectEntry( - tabSelectedScenery.EntryIndex); + auto* sceneryEntry = ObjectManager::GetObjectEntry(tabSelectedScenery.EntryIndex); if (sceneryEntry->flags & LARGE_SCENERY_FLAG_HAS_PRIMARY_COLOUR && !(sceneryEntry->flags & LARGE_SCENERY_FLAG_HIDE_PRIMARY_REMAP_BUTTON)) @@ -762,7 +760,7 @@ namespace OpenRCT2::Ui::Windows } else if (tabSelectedScenery.SceneryType == SCENERY_TYPE_WALL) { - auto* wallEntry = OpenRCT2::ObjectManager::GetObjectEntry(tabSelectedScenery.EntryIndex); + auto* wallEntry = ObjectManager::GetObjectEntry(tabSelectedScenery.EntryIndex); if (wallEntry->flags & (WALL_SCENERY_HAS_PRIMARY_COLOUR | WALL_SCENERY_HAS_GLASS)) { widgets[WIDX_SCENERY_PRIMARY_COLOUR_BUTTON].type = WidgetType::colourBtn; @@ -780,8 +778,7 @@ namespace OpenRCT2::Ui::Windows } else if (tabSelectedScenery.SceneryType == SCENERY_TYPE_SMALL) { - auto* sceneryEntry = OpenRCT2::ObjectManager::GetObjectEntry( - tabSelectedScenery.EntryIndex); + auto* sceneryEntry = ObjectManager::GetObjectEntry(tabSelectedScenery.EntryIndex); if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_HAS_PRIMARY_COLOUR | SMALL_SCENERY_FLAG_HAS_GLASS)) { @@ -978,7 +975,7 @@ namespace OpenRCT2::Ui::Windows gWindowSceneryRotation = rotation.value(); } gWindowSceneryEyedropperEnabled = false; - OpenRCT2::Audio::Play(OpenRCT2::Audio::SoundId::Click1, 0, ContextGetWidth() / 2); + Audio::Play(Audio::SoundId::Click1, 0, ContextGetWidth() / 2); _hoverCounter = -16; gSceneryPlaceCost = kMoney64Undefined; Invalidate(); @@ -1007,7 +1004,7 @@ namespace OpenRCT2::Ui::Windows for (ObjectEntryIndex scenerySetIndex = 0; scenerySetIndex < kMaxTabs - kReservedTabCount; scenerySetIndex++) { - const auto* sceneryGroupEntry = OpenRCT2::ObjectManager::GetObjectEntry(scenerySetIndex); + const auto* sceneryGroupEntry = ObjectManager::GetObjectEntry(scenerySetIndex); if (sceneryGroupEntry != nullptr && SceneryGroupIsInvented(scenerySetIndex)) { SceneryTabInfo tabInfo; @@ -1036,7 +1033,7 @@ namespace OpenRCT2::Ui::Windows // small scenery for (ObjectEntryIndex sceneryId = 0; sceneryId < kMaxSmallSceneryObjects; sceneryId++) { - const auto* sceneryEntry = OpenRCT2::ObjectManager::GetObjectEntry(sceneryId); + const auto* sceneryEntry = ObjectManager::GetObjectEntry(sceneryId); if (sceneryEntry != nullptr) { InitSceneryEntry({ SCENERY_TYPE_SMALL, sceneryId }, sceneryEntry->scenery_tab_id); @@ -1046,7 +1043,7 @@ namespace OpenRCT2::Ui::Windows // large scenery for (ObjectEntryIndex sceneryId = 0; sceneryId < kMaxLargeSceneryObjects; sceneryId++) { - const auto* sceneryEntry = OpenRCT2::ObjectManager::GetObjectEntry(sceneryId); + const auto* sceneryEntry = ObjectManager::GetObjectEntry(sceneryId); if (sceneryEntry != nullptr) { InitSceneryEntry({ SCENERY_TYPE_LARGE, sceneryId }, sceneryEntry->scenery_tab_id); @@ -1056,7 +1053,7 @@ namespace OpenRCT2::Ui::Windows // walls for (ObjectEntryIndex sceneryId = 0; sceneryId < kMaxWallSceneryObjects; sceneryId++) { - const auto* sceneryEntry = OpenRCT2::ObjectManager::GetObjectEntry(sceneryId); + const auto* sceneryEntry = ObjectManager::GetObjectEntry(sceneryId); if (sceneryEntry != nullptr) { InitSceneryEntry({ SCENERY_TYPE_WALL, sceneryId }, sceneryEntry->scenery_tab_id); @@ -1066,7 +1063,7 @@ namespace OpenRCT2::Ui::Windows // banners for (ObjectEntryIndex sceneryId = 0; sceneryId < kMaxBannerObjects; sceneryId++) { - const auto* sceneryEntry = OpenRCT2::ObjectManager::GetObjectEntry(sceneryId); + const auto* sceneryEntry = ObjectManager::GetObjectEntry(sceneryId); if (sceneryEntry != nullptr) { InitSceneryEntry({ SCENERY_TYPE_BANNER, sceneryId }, sceneryEntry->scenery_tab_id); @@ -1075,7 +1072,7 @@ namespace OpenRCT2::Ui::Windows for (ObjectEntryIndex sceneryId = 0; sceneryId < kMaxPathAdditionObjects; sceneryId++) { - const auto* sceneryEntry = OpenRCT2::ObjectManager::GetObjectEntry(sceneryId); + const auto* sceneryEntry = ObjectManager::GetObjectEntry(sceneryId); if (sceneryEntry != nullptr) { InitSceneryEntry({ SCENERY_TYPE_PATH_ITEM, sceneryId }, sceneryEntry->scenery_tab_id); @@ -1514,7 +1511,7 @@ namespace OpenRCT2::Ui::Windows _sceneryPaintEnabled = false; gWindowSceneryEyedropperEnabled = false; - OpenRCT2::Audio::Play(OpenRCT2::Audio::SoundId::Click1, 0, windowPos.x + (width / 2)); + Audio::Play(Audio::SoundId::Click1, 0, windowPos.x + (width / 2)); _hoverCounter = -16; gSceneryPlaceCost = kMoney64Undefined; Invalidate(); @@ -1544,8 +1541,7 @@ namespace OpenRCT2::Ui::Windows { case SCENERY_TYPE_SMALL: { - auto* sceneryEntry = OpenRCT2::ObjectManager::GetObjectEntry( - selectedScenery.EntryIndex); + auto* sceneryEntry = ObjectManager::GetObjectEntry(selectedScenery.EntryIndex); if (sceneryEntry != nullptr) { price = sceneryEntry->price; @@ -1555,8 +1551,7 @@ namespace OpenRCT2::Ui::Windows } case SCENERY_TYPE_PATH_ITEM: { - auto* sceneryEntry = OpenRCT2::ObjectManager::GetObjectEntry( - selectedScenery.EntryIndex); + auto* sceneryEntry = ObjectManager::GetObjectEntry(selectedScenery.EntryIndex); if (sceneryEntry != nullptr) { price = sceneryEntry->price; @@ -1566,8 +1561,7 @@ namespace OpenRCT2::Ui::Windows } case SCENERY_TYPE_WALL: { - auto* sceneryEntry = OpenRCT2::ObjectManager::GetObjectEntry( - selectedScenery.EntryIndex); + auto* sceneryEntry = ObjectManager::GetObjectEntry(selectedScenery.EntryIndex); if (sceneryEntry != nullptr) { price = sceneryEntry->price; @@ -1577,8 +1571,7 @@ namespace OpenRCT2::Ui::Windows } case SCENERY_TYPE_LARGE: { - auto* sceneryEntry = OpenRCT2::ObjectManager::GetObjectEntry( - selectedScenery.EntryIndex); + auto* sceneryEntry = ObjectManager::GetObjectEntry(selectedScenery.EntryIndex); if (sceneryEntry != nullptr) { price = sceneryEntry->price; @@ -1588,8 +1581,7 @@ namespace OpenRCT2::Ui::Windows } case SCENERY_TYPE_BANNER: { - auto* sceneryEntry = OpenRCT2::ObjectManager::GetObjectEntry( - selectedScenery.EntryIndex); + auto* sceneryEntry = ObjectManager::GetObjectEntry(selectedScenery.EntryIndex); if (sceneryEntry != nullptr) { price = sceneryEntry->price; @@ -1621,14 +1613,14 @@ namespace OpenRCT2::Ui::Windows { if (scenerySelection.SceneryType == SCENERY_TYPE_BANNER) { - auto bannerEntry = OpenRCT2::ObjectManager::GetObjectEntry(scenerySelection.EntryIndex); + auto bannerEntry = ObjectManager::GetObjectEntry(scenerySelection.EntryIndex); auto imageId = ImageId(bannerEntry->image + gWindowSceneryRotation * 2, _sceneryPrimaryColour); GfxDrawSprite(rt, imageId, { 33, 40 }); GfxDrawSprite(rt, imageId.WithIndexOffset(1), { 33, 40 }); } else if (scenerySelection.SceneryType == SCENERY_TYPE_LARGE) { - auto sceneryEntry = OpenRCT2::ObjectManager::GetObjectEntry(scenerySelection.EntryIndex); + auto sceneryEntry = ObjectManager::GetObjectEntry(scenerySelection.EntryIndex); auto imageId = ImageId(sceneryEntry->image + gWindowSceneryRotation); if (sceneryEntry->flags & LARGE_SCENERY_FLAG_HAS_PRIMARY_COLOUR) imageId = imageId.WithPrimary(_sceneryPrimaryColour); @@ -1640,7 +1632,7 @@ namespace OpenRCT2::Ui::Windows } else if (scenerySelection.SceneryType == SCENERY_TYPE_WALL) { - auto wallEntry = OpenRCT2::ObjectManager::GetObjectEntry(scenerySelection.EntryIndex); + auto wallEntry = ObjectManager::GetObjectEntry(scenerySelection.EntryIndex); auto imageId = ImageId(wallEntry->image); auto spriteTop = (wallEntry->height * 2) + 0x32; if (wallEntry->flags & WALL_SCENERY_HAS_GLASS) @@ -1676,14 +1668,13 @@ namespace OpenRCT2::Ui::Windows } else if (scenerySelection.SceneryType == SCENERY_TYPE_PATH_ITEM) { - auto* pathAdditionEntry = OpenRCT2::ObjectManager::GetObjectEntry( - scenerySelection.EntryIndex); + auto* pathAdditionEntry = ObjectManager::GetObjectEntry(scenerySelection.EntryIndex); auto imageId = ImageId(pathAdditionEntry->image); GfxDrawSprite(rt, imageId, { 11, 16 }); } else { - auto sceneryEntry = OpenRCT2::ObjectManager::GetObjectEntry(scenerySelection.EntryIndex); + auto sceneryEntry = ObjectManager::GetObjectEntry(scenerySelection.EntryIndex); auto imageId = ImageId(sceneryEntry->image + gWindowSceneryRotation); if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_HAS_PRIMARY_COLOUR)) { @@ -1844,7 +1835,7 @@ namespace OpenRCT2::Ui::Windows gMapSelectPositionB.y = mapTile.y; } - auto* sceneryEntry = OpenRCT2::ObjectManager::GetObjectEntry(selection.EntryIndex); + auto* sceneryEntry = ObjectManager::GetObjectEntry(selection.EntryIndex); gMapSelectType = MAP_SELECT_TYPE_FULL; if (!sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_FULL_TILE) && !gWindowSceneryScatterEnabled) @@ -1991,7 +1982,7 @@ namespace OpenRCT2::Ui::Windows return; } - auto* sceneryEntry = OpenRCT2::ObjectManager::GetObjectEntry(selection.EntryIndex); + auto* sceneryEntry = ObjectManager::GetObjectEntry(selection.EntryIndex); gMapSelectionTiles.clear(); for (auto& tile : sceneryEntry->tiles) @@ -2096,14 +2087,14 @@ namespace OpenRCT2::Ui::Windows SceneryRemoveGhostToolPlacement(); // 6e252b - auto smallSceneryPlaceAction = SmallSceneryPlaceAction( + auto smallSceneryPlaceAction = GameActions::SmallSceneryPlaceAction( loc, quadrant, entryIndex, primaryColour, secondaryColour, tertiaryColour); smallSceneryPlaceAction.SetFlags(GAME_COMMAND_FLAG_GHOST | GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED); auto res = GameActions::Execute(&smallSceneryPlaceAction); if (res.Error != GameActions::Status::Ok) return kMoney64Undefined; - const auto placementData = res.GetData(); + const auto placementData = res.GetData(); gSceneryPlaceRotation = loc.direction; gSceneryPlaceObject.SceneryType = SCENERY_TYPE_SMALL; @@ -2155,14 +2146,15 @@ namespace OpenRCT2::Ui::Windows SceneryRemoveGhostToolPlacement(); // 6e26b0 - auto wallPlaceAction = WallPlaceAction(entryIndex, loc, edge, primaryColour, secondaryColour, tertiaryColour); + auto wallPlaceAction = GameActions::WallPlaceAction( + entryIndex, loc, edge, primaryColour, secondaryColour, tertiaryColour); wallPlaceAction.SetFlags( GAME_COMMAND_FLAG_GHOST | GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_NO_SPEND); wallPlaceAction.SetCallback([=](const GameAction* ga, const GameActions::Result* result) { if (result->Error != GameActions::Status::Ok) return; - const auto placementData = result->GetData(); + const auto placementData = result->GetData(); gSceneryGhostPosition = { loc, placementData.BaseHeight }; gSceneryGhostWallRotation = edge; @@ -2183,14 +2175,15 @@ namespace OpenRCT2::Ui::Windows SceneryRemoveGhostToolPlacement(); // 6e25a7 - auto sceneryPlaceAction = LargeSceneryPlaceAction(loc, entryIndex, primaryColour, secondaryColour, tertiaryColour); + auto sceneryPlaceAction = GameActions::LargeSceneryPlaceAction( + loc, entryIndex, primaryColour, secondaryColour, tertiaryColour); sceneryPlaceAction.SetFlags( GAME_COMMAND_FLAG_GHOST | GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_NO_SPEND); auto res = GameActions::Execute(&sceneryPlaceAction); if (res.Error != GameActions::Status::Ok) return kMoney64Undefined; - const auto placementData = res.GetData(); + const auto placementData = res.GetData(); gSceneryPlaceRotation = loc.direction; @@ -2251,7 +2244,7 @@ namespace OpenRCT2::Ui::Windows return; uint8_t quadrant = info.Element->AsSmallScenery()->GetSceneryQuadrant(); - auto repaintScenery = SmallScenerySetColourAction( + auto repaintScenery = GameActions::SmallScenerySetColourAction( { info.Loc, info.Element->GetBaseZ() }, quadrant, info.Element->AsSmallScenery()->GetEntryIndex(), _sceneryPrimaryColour, _scenerySecondaryColour, _sceneryTertiaryColour); @@ -2266,7 +2259,7 @@ namespace OpenRCT2::Ui::Windows if (!(scenery_entry->flags & (WALL_SCENERY_HAS_PRIMARY_COLOUR | WALL_SCENERY_HAS_GLASS))) return; - auto repaintScenery = WallSetColourAction( + auto repaintScenery = GameActions::WallSetColourAction( { info.Loc, info.Element->GetBaseZ(), info.Element->GetDirection() }, _sceneryPrimaryColour, _scenerySecondaryColour, _sceneryTertiaryColour); @@ -2281,7 +2274,7 @@ namespace OpenRCT2::Ui::Windows if (!(sceneryEntry->flags & LARGE_SCENERY_FLAG_HAS_PRIMARY_COLOUR)) return; - auto repaintScenery = LargeScenerySetColourAction( + auto repaintScenery = GameActions::LargeScenerySetColourAction( { info.Loc, info.Element->GetBaseZ(), info.Element->GetDirection() }, info.Element->AsLargeScenery()->GetSequenceIndex(), _sceneryPrimaryColour, _scenerySecondaryColour, _sceneryTertiaryColour); @@ -2294,7 +2287,7 @@ namespace OpenRCT2::Ui::Windows auto banner = info.Element->AsBanner()->GetBanner(); if (banner != nullptr) { - auto* bannerEntry = OpenRCT2::ObjectManager::GetObjectEntry(banner->type); + auto* bannerEntry = ObjectManager::GetObjectEntry(banner->type); if (bannerEntry->flags & BANNER_ENTRY_FLAG_HAS_PRIMARY_COLOUR) { auto repaintScenery = GameActions::BannerSetColourAction( @@ -2323,7 +2316,7 @@ namespace OpenRCT2::Ui::Windows { SmallSceneryElement* sceneryElement = info.Element->AsSmallScenery(); auto entryIndex = sceneryElement->GetEntryIndex(); - auto* sceneryEntry = OpenRCT2::ObjectManager::GetObjectEntry(entryIndex); + auto* sceneryEntry = ObjectManager::GetObjectEntry(entryIndex); if (sceneryEntry != nullptr) { WindowScenerySetSelectedItem( @@ -2336,7 +2329,7 @@ namespace OpenRCT2::Ui::Windows case ViewportInteractionItem::Wall: { auto entryIndex = info.Element->AsWall()->GetEntryIndex(); - auto* sceneryEntry = OpenRCT2::ObjectManager::GetObjectEntry(entryIndex); + auto* sceneryEntry = ObjectManager::GetObjectEntry(entryIndex); if (sceneryEntry != nullptr) { WindowScenerySetSelectedItem( @@ -2349,7 +2342,7 @@ namespace OpenRCT2::Ui::Windows case ViewportInteractionItem::LargeScenery: { auto entryIndex = info.Element->AsLargeScenery()->GetEntryIndex(); - auto* sceneryEntry = OpenRCT2::ObjectManager::GetObjectEntry(entryIndex); + auto* sceneryEntry = ObjectManager::GetObjectEntry(entryIndex); if (sceneryEntry != nullptr) { WindowScenerySetSelectedItem( @@ -2364,7 +2357,7 @@ namespace OpenRCT2::Ui::Windows auto banner = info.Element->AsBanner()->GetBanner(); if (banner != nullptr) { - auto sceneryEntry = OpenRCT2::ObjectManager::GetObjectEntry(banner->type); + auto sceneryEntry = ObjectManager::GetObjectEntry(banner->type); if (sceneryEntry != nullptr) { WindowScenerySetSelectedItem( @@ -2376,7 +2369,7 @@ namespace OpenRCT2::Ui::Windows case ViewportInteractionItem::PathAddition: { auto entryIndex = info.Element->AsPath()->GetAdditionEntryIndex(); - auto* pathAdditionEntry = OpenRCT2::ObjectManager::GetObjectEntry(entryIndex); + auto* pathAdditionEntry = ObjectManager::GetObjectEntry(entryIndex); if (pathAdditionEntry != nullptr) { WindowScenerySetSelectedItem( @@ -2481,7 +2474,7 @@ namespace OpenRCT2::Ui::Windows std::numeric_limits::max() - 32); bool can_raise_item = false; - const auto* sceneryEntry = OpenRCT2::ObjectManager::GetObjectEntry(sceneryIndex); + const auto* sceneryEntry = ObjectManager::GetObjectEntry(sceneryIndex); if (sceneryEntry == nullptr) { gridPos.SetNull(); @@ -2712,7 +2705,7 @@ namespace OpenRCT2::Ui::Windows uint16_t maxPossibleHeight = ZoomLevel::max().ApplyTo( std::numeric_limits::max() - 32); - auto* wallEntry = OpenRCT2::ObjectManager::GetObjectEntry(sceneryIndex); + auto* wallEntry = ObjectManager::GetObjectEntry(sceneryIndex); if (wallEntry != nullptr) { maxPossibleHeight -= wallEntry->height; @@ -2803,7 +2796,7 @@ namespace OpenRCT2::Ui::Windows uint16_t maxPossibleHeight = ZoomLevel::max().ApplyTo( std::numeric_limits::max() - 32); - auto* sceneryEntry = OpenRCT2::ObjectManager::GetObjectEntry(sceneryIndex); + auto* sceneryEntry = ObjectManager::GetObjectEntry(sceneryIndex); if (sceneryEntry) { int16_t maxClearZ = 0; @@ -3000,7 +2993,7 @@ namespace OpenRCT2::Ui::Windows for (int32_t q = 0; q < quantity; q++) { int32_t zCoordinate = gSceneryPlaceZ; - auto* sceneryEntry = OpenRCT2::ObjectManager::GetObjectEntry(selectedScenery); + auto* sceneryEntry = ObjectManager::GetObjectEntry(selectedScenery); int16_t cur_grid_x = gridPos.x; int16_t cur_grid_y = gridPos.y; @@ -3038,7 +3031,7 @@ namespace OpenRCT2::Ui::Windows // Try find a valid z coordinate for (; zAttemptRange != 0; zAttemptRange--) { - auto smallSceneryPlaceAction = SmallSceneryPlaceAction( + auto smallSceneryPlaceAction = GameActions::SmallSceneryPlaceAction( { cur_grid_x, cur_grid_y, gSceneryPlaceZ, gSceneryPlaceRotation }, quadrant, selectedScenery, _sceneryPrimaryColour, _scenerySecondaryColour, _sceneryTertiaryColour); auto res = GameActions::Query(&smallSceneryPlaceAction); @@ -3061,14 +3054,14 @@ namespace OpenRCT2::Ui::Windows // Actually place if (success == GameActions::Status::Ok || ((q + 1 == quantity) && forceError)) { - auto smallSceneryPlaceAction = SmallSceneryPlaceAction( + auto smallSceneryPlaceAction = GameActions::SmallSceneryPlaceAction( { cur_grid_x, cur_grid_y, gSceneryPlaceZ, gSceneryPlaceRotation }, quadrant, selectedScenery, _sceneryPrimaryColour, _scenerySecondaryColour, _sceneryTertiaryColour); smallSceneryPlaceAction.SetCallback([=](const GameAction* ga, const GameActions::Result* result) { if (result->Error == GameActions::Status::Ok) { - OpenRCT2::Audio::Play3D(OpenRCT2::Audio::SoundId::PlaceItem, result->Position); + Audio::Play3D(Audio::SoundId::PlaceItem, result->Position); } }); auto res = GameActions::Execute(&smallSceneryPlaceAction); @@ -3101,7 +3094,7 @@ namespace OpenRCT2::Ui::Windows { return; } - OpenRCT2::Audio::Play3D(OpenRCT2::Audio::SoundId::PlaceItem, result->Position); + Audio::Play3D(Audio::SoundId::PlaceItem, result->Position); }); auto res = GameActions::Execute(&footpathAdditionPlaceAction); break; @@ -3121,7 +3114,7 @@ namespace OpenRCT2::Ui::Windows for (; zAttemptRange != 0; zAttemptRange--) { - auto wallPlaceAction = WallPlaceAction( + auto wallPlaceAction = GameActions::WallPlaceAction( selectedScenery, { gridPos, gSceneryPlaceZ }, edges, _sceneryPrimaryColour, _scenerySecondaryColour, _sceneryTertiaryColour); @@ -3145,14 +3138,14 @@ namespace OpenRCT2::Ui::Windows } } - auto wallPlaceAction = WallPlaceAction( + auto wallPlaceAction = GameActions::WallPlaceAction( selectedScenery, { gridPos, gSceneryPlaceZ }, edges, _sceneryPrimaryColour, _scenerySecondaryColour, _sceneryTertiaryColour); wallPlaceAction.SetCallback([](const GameAction* ga, const GameActions::Result* result) { if (result->Error == GameActions::Status::Ok) { - OpenRCT2::Audio::Play3D(OpenRCT2::Audio::SoundId::PlaceItem, result->Position); + Audio::Play3D(Audio::SoundId::PlaceItem, result->Position); } }); auto res = GameActions::Execute(&wallPlaceAction); @@ -3175,7 +3168,7 @@ namespace OpenRCT2::Ui::Windows { CoordsXYZD loc = { gridPos, gSceneryPlaceZ, direction }; - auto sceneryPlaceAction = LargeSceneryPlaceAction( + auto sceneryPlaceAction = GameActions::LargeSceneryPlaceAction( loc, selectedScenery, _sceneryPrimaryColour, _scenerySecondaryColour, _sceneryTertiaryColour); auto res = GameActions::Query(&sceneryPlaceAction); @@ -3200,16 +3193,16 @@ namespace OpenRCT2::Ui::Windows CoordsXYZD loc = { gridPos, gSceneryPlaceZ, direction }; - auto sceneryPlaceAction = LargeSceneryPlaceAction( + auto sceneryPlaceAction = GameActions::LargeSceneryPlaceAction( loc, selectedScenery, _sceneryPrimaryColour, _scenerySecondaryColour, _sceneryTertiaryColour); sceneryPlaceAction.SetCallback([=](const GameAction* ga, const GameActions::Result* result) { if (result->Error == GameActions::Status::Ok) { - OpenRCT2::Audio::Play3D(OpenRCT2::Audio::SoundId::PlaceItem, result->Position); + Audio::Play3D(Audio::SoundId::PlaceItem, result->Position); } else { - OpenRCT2::Audio::Play3D(OpenRCT2::Audio::SoundId::Error, { loc.x, loc.y, gSceneryPlaceZ }); + Audio::Play3D(Audio::SoundId::Error, { loc.x, loc.y, gSceneryPlaceZ }); } }); auto res = GameActions::Execute(&sceneryPlaceAction); diff --git a/src/openrct2-ui/windows/Sign.cpp b/src/openrct2-ui/windows/Sign.cpp index 55aed77149..6902554722 100644 --- a/src/openrct2-ui/windows/Sign.cpp +++ b/src/openrct2-ui/windows/Sign.cpp @@ -172,12 +172,12 @@ namespace OpenRCT2::Ui::Windows if (_isSmall) { CoordsXYZD wallLocation = { bannerCoords, tileElement->GetBaseZ(), tileElement->GetDirection() }; - auto wallRemoveAction = WallRemoveAction(wallLocation); + auto wallRemoveAction = GameActions::WallRemoveAction(wallLocation); GameActions::Execute(&wallRemoveAction); } else { - auto sceneryRemoveAction = LargeSceneryRemoveAction( + auto sceneryRemoveAction = GameActions::LargeSceneryRemoveAction( { bannerCoords, tileElement->GetBaseZ(), tileElement->GetDirection() }, tileElement->AsLargeScenery()->GetSequenceIndex()); GameActions::Execute(&sceneryRemoveAction); @@ -213,7 +213,8 @@ namespace OpenRCT2::Ui::Windows if (dropdownIndex == -1) return; _mainColour = ColourDropDownIndexToColour(dropdownIndex); - auto signSetStyleAction = SignSetStyleAction(GetBannerIndex(), _mainColour, _textColour, !_isSmall); + auto signSetStyleAction = GameActions::SignSetStyleAction( + GetBannerIndex(), _mainColour, _textColour, !_isSmall); GameActions::Execute(&signSetStyleAction); break; } @@ -222,7 +223,8 @@ namespace OpenRCT2::Ui::Windows if (dropdownIndex == -1) return; _textColour = ColourDropDownIndexToColour(dropdownIndex); - auto signSetStyleAction = SignSetStyleAction(GetBannerIndex(), _mainColour, _textColour, !_isSmall); + auto signSetStyleAction = GameActions::SignSetStyleAction( + GetBannerIndex(), _mainColour, _textColour, !_isSmall); GameActions::Execute(&signSetStyleAction); break; } @@ -237,7 +239,7 @@ namespace OpenRCT2::Ui::Windows { if (widgetIndex == WIDX_SIGN_TEXT && !text.empty()) { - auto signSetNameAction = SignSetNameAction(GetBannerIndex(), std::string(text)); + auto signSetNameAction = GameActions::SignSetNameAction(GetBannerIndex(), std::string(text)); GameActions::Execute(&signSetNameAction); } } diff --git a/src/openrct2/actions/ClearAction.cpp b/src/openrct2/actions/ClearAction.cpp index 4c754f39f3..c49bd3c490 100644 --- a/src/openrct2/actions/ClearAction.cpp +++ b/src/openrct2/actions/ClearAction.cpp @@ -159,7 +159,7 @@ money64 ClearAction::ClearSceneryFromTile(const CoordsXY& tilePos, bool executin case TileElementType::SmallScenery: if (_itemsToClear & CLEARABLE_ITEMS::kScenerySmall) { - auto removeSceneryAction = SmallSceneryRemoveAction( + auto removeSceneryAction = GameActions::SmallSceneryRemoveAction( { tilePos, tileElement->GetBaseZ() }, tileElement->AsSmallScenery()->GetSceneryQuadrant(), tileElement->AsSmallScenery()->GetEntryIndex()); removeSceneryAction.SetFlags(GetFlags()); @@ -178,7 +178,7 @@ money64 ClearAction::ClearSceneryFromTile(const CoordsXY& tilePos, bool executin if (_itemsToClear & CLEARABLE_ITEMS::kScenerySmall) { CoordsXYZD wallLocation = { tilePos, tileElement->GetBaseZ(), tileElement->GetDirection() }; - auto wallRemoveAction = WallRemoveAction(wallLocation); + auto wallRemoveAction = GameActions::WallRemoveAction(wallLocation); wallRemoveAction.SetFlags(GetFlags()); auto res = executing ? GameActions::ExecuteNested(&wallRemoveAction) @@ -194,7 +194,7 @@ money64 ClearAction::ClearSceneryFromTile(const CoordsXY& tilePos, bool executin case TileElementType::LargeScenery: if (_itemsToClear & CLEARABLE_ITEMS::kSceneryLarge) { - auto removeSceneryAction = LargeSceneryRemoveAction( + auto removeSceneryAction = GameActions::LargeSceneryRemoveAction( { tilePos, tileElement->GetBaseZ(), tileElement->GetDirection() }, tileElement->AsLargeScenery()->GetSequenceIndex()); removeSceneryAction.SetFlags(GetFlags() | GAME_COMMAND_FLAG_TRACK_DESIGN); diff --git a/src/openrct2/actions/LargeSceneryPlaceAction.cpp b/src/openrct2/actions/LargeSceneryPlaceAction.cpp index 9b93bdf47d..273bad98c0 100644 --- a/src/openrct2/actions/LargeSceneryPlaceAction.cpp +++ b/src/openrct2/actions/LargeSceneryPlaceAction.cpp @@ -28,376 +28,369 @@ #include "../world/tile_element/Slope.h" #include "../world/tile_element/SurfaceElement.h" -using namespace OpenRCT2; - -LargeSceneryPlaceAction::LargeSceneryPlaceAction( - const CoordsXYZD& loc, ObjectEntryIndex sceneryType, uint8_t primaryColour, uint8_t secondaryColour, uint8_t tertiaryColour) - : _loc(loc) - , _sceneryType(sceneryType) - , _primaryColour(primaryColour) - , _secondaryColour(secondaryColour) - , _tertiaryColour(tertiaryColour) +namespace OpenRCT2::GameActions { -} - -void LargeSceneryPlaceAction::AcceptParameters(GameActionParameterVisitor& visitor) -{ - visitor.Visit(_loc); - visitor.Visit("object", _sceneryType); - visitor.Visit("primaryColour", _primaryColour); - visitor.Visit("secondaryColour", _secondaryColour); - visitor.Visit("tertiaryColour", _tertiaryColour); -} - -uint16_t LargeSceneryPlaceAction::GetActionFlags() const -{ - return GameAction::GetActionFlags(); -} - -void LargeSceneryPlaceAction::Serialise(DataSerialiser& stream) -{ - GameAction::Serialise(stream); - - stream << DS_TAG(_loc) << DS_TAG(_sceneryType) << DS_TAG(_primaryColour) << DS_TAG(_secondaryColour) - << DS_TAG(_tertiaryColour); -} - -GameActions::Result LargeSceneryPlaceAction::Query() const -{ - auto res = GameActions::Result(); - res.ErrorTitle = STR_CANT_POSITION_THIS_HERE; - res.Expenditure = ExpenditureType::landscaping; - int16_t surfaceHeight = TileElementHeight(_loc); - res.Position.x = _loc.x + 16; - res.Position.y = _loc.y + 16; - res.Position.z = surfaceHeight; - - auto resultData = LargeSceneryPlaceActionResult{}; - - auto& gameState = getGameState(); - - money64 supportsCost = 0; - - if (_primaryColour >= COLOUR_COUNT) + LargeSceneryPlaceAction::LargeSceneryPlaceAction( + const CoordsXYZD& loc, ObjectEntryIndex sceneryType, uint8_t primaryColour, uint8_t secondaryColour, + uint8_t tertiaryColour) + : _loc(loc) + , _sceneryType(sceneryType) + , _primaryColour(primaryColour) + , _secondaryColour(secondaryColour) + , _tertiaryColour(tertiaryColour) { - LOG_ERROR("Invalid primary colour %u", _primaryColour); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_ERR_INVALID_COLOUR); - } - else if (_secondaryColour >= COLOUR_COUNT) - { - LOG_ERROR("Invalid secondary colour %u", _secondaryColour); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_ERR_INVALID_COLOUR); - } - else if (_tertiaryColour >= COLOUR_COUNT) - { - LOG_ERROR("Invalid tertiary colour %u", _tertiaryColour); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_ERR_INVALID_COLOUR); - } - else if (_sceneryType >= kMaxLargeSceneryObjects) - { - LOG_ERROR("Invalid sceneryType %u", _sceneryType); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_ERR_VALUE_OUT_OF_RANGE); } - auto* sceneryEntry = ObjectManager::GetObjectEntry(_sceneryType); - if (sceneryEntry == nullptr) + void LargeSceneryPlaceAction::AcceptParameters(GameActionParameterVisitor& visitor) { - LOG_ERROR("Large scenery entry not found for sceneryType %u", _sceneryType); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_UNKNOWN_OBJECT_TYPE); + visitor.Visit(_loc); + visitor.Visit("object", _sceneryType); + visitor.Visit("primaryColour", _primaryColour); + visitor.Visit("secondaryColour", _secondaryColour); + visitor.Visit("tertiaryColour", _tertiaryColour); } - const auto totalNumTiles = sceneryEntry->tiles.size(); - int16_t maxHeight = GetMaxSurfaceHeight(sceneryEntry->tiles); - - if (_loc.z != 0) + uint16_t LargeSceneryPlaceAction::GetActionFlags() const { - maxHeight = _loc.z; + return GameAction::GetActionFlags(); } - res.Position.z = maxHeight; - - if (sceneryEntry->scrolling_mode != kScrollingModeNone) + void LargeSceneryPlaceAction::Serialise(DataSerialiser& stream) { - if (HasReachedBannerLimit()) + GameAction::Serialise(stream); + + stream << DS_TAG(_loc) << DS_TAG(_sceneryType) << DS_TAG(_primaryColour) << DS_TAG(_secondaryColour) + << DS_TAG(_tertiaryColour); + } + + Result LargeSceneryPlaceAction::Query() const + { + auto res = Result(); + res.ErrorTitle = STR_CANT_POSITION_THIS_HERE; + res.Expenditure = ExpenditureType::landscaping; + int16_t surfaceHeight = TileElementHeight(_loc); + res.Position.x = _loc.x + 16; + res.Position.y = _loc.y + 16; + res.Position.z = surfaceHeight; + + auto resultData = LargeSceneryPlaceActionResult{}; + + auto& gameState = getGameState(); + + money64 supportsCost = 0; + + if (_primaryColour >= COLOUR_COUNT) { - LOG_ERROR("No free banners available"); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_TOO_MANY_BANNERS_IN_GAME); + LOG_ERROR("Invalid primary colour %u", _primaryColour); + return Result(Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_ERR_INVALID_COLOUR); } - } - - for (auto& tile : sceneryEntry->tiles) - { - auto curTile = CoordsXY{ tile.offset }.Rotate(_loc.direction); - - curTile.x += _loc.x; - curTile.y += _loc.y; - - int32_t zLow = tile.offset.z + maxHeight; - int32_t zHigh = tile.zClearance + zLow; - - QuarterTile quarterTile = QuarterTile{ tile.corners, 0 }.Rotate(_loc.direction); - const auto isTree = (sceneryEntry->flags & LARGE_SCENERY_FLAG_IS_TREE) != 0; - auto canBuild = MapCanConstructWithClearAt( - { curTile, zLow, zHigh }, &MapPlaceSceneryClearFunc, quarterTile, GetFlags(), CreateCrossingMode::none, isTree); - if (canBuild.Error != GameActions::Status::Ok) + else if (_secondaryColour >= COLOUR_COUNT) { - canBuild.ErrorTitle = STR_CANT_POSITION_THIS_HERE; - return canBuild; + LOG_ERROR("Invalid secondary colour %u", _secondaryColour); + return Result(Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_ERR_INVALID_COLOUR); + } + else if (_tertiaryColour >= COLOUR_COUNT) + { + LOG_ERROR("Invalid tertiary colour %u", _tertiaryColour); + return Result(Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_ERR_INVALID_COLOUR); + } + else if (_sceneryType >= kMaxLargeSceneryObjects) + { + LOG_ERROR("Invalid sceneryType %u", _sceneryType); + return Result(Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_ERR_VALUE_OUT_OF_RANGE); } - supportsCost += canBuild.Cost; - - const auto clearanceData = canBuild.GetData(); - int32_t tempSceneryGroundFlags = clearanceData.GroundFlags & (ELEMENT_IS_ABOVE_GROUND | ELEMENT_IS_UNDERGROUND); - if (!gameState.cheats.disableClearanceChecks) + auto* sceneryEntry = ObjectManager::GetObjectEntry(_sceneryType); + if (sceneryEntry == nullptr) { - if ((clearanceData.GroundFlags & ELEMENT_IS_UNDERWATER) || (clearanceData.GroundFlags & ELEMENT_IS_UNDERGROUND)) + LOG_ERROR("Large scenery entry not found for sceneryType %u", _sceneryType); + return Result(Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_UNKNOWN_OBJECT_TYPE); + } + + const auto totalNumTiles = sceneryEntry->tiles.size(); + int16_t maxHeight = GetMaxSurfaceHeight(sceneryEntry->tiles); + + if (_loc.z != 0) + { + maxHeight = _loc.z; + } + + res.Position.z = maxHeight; + + if (sceneryEntry->scrolling_mode != kScrollingModeNone) + { + if (HasReachedBannerLimit()) { - return GameActions::Result( - GameActions::Status::Disallowed, STR_CANT_POSITION_THIS_HERE, STR_CANT_BUILD_THIS_UNDERWATER); - } - if (resultData.GroundFlags && !(resultData.GroundFlags & tempSceneryGroundFlags)) - { - return GameActions::Result( - GameActions::Status::Disallowed, STR_CANT_POSITION_THIS_HERE, - STR_CANT_BUILD_PARTLY_ABOVE_AND_PARTLY_BELOW_GROUND); + LOG_ERROR("No free banners available"); + return Result(Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_TOO_MANY_BANNERS_IN_GAME); } } - resultData.GroundFlags = tempSceneryGroundFlags; - - if (!LocationValid(curTile) || MapIsEdge(curTile)) + for (auto& tile : sceneryEntry->tiles) { - return GameActions::Result(GameActions::Status::Disallowed, STR_CANT_POSITION_THIS_HERE, STR_OFF_EDGE_OF_MAP); + auto curTile = CoordsXY{ tile.offset }.Rotate(_loc.direction); + + curTile.x += _loc.x; + curTile.y += _loc.y; + + int32_t zLow = tile.offset.z + maxHeight; + int32_t zHigh = tile.zClearance + zLow; + + QuarterTile quarterTile = QuarterTile{ tile.corners, 0 }.Rotate(_loc.direction); + const auto isTree = (sceneryEntry->flags & LARGE_SCENERY_FLAG_IS_TREE) != 0; + auto canBuild = MapCanConstructWithClearAt( + { curTile, zLow, zHigh }, &MapPlaceSceneryClearFunc, quarterTile, GetFlags(), CreateCrossingMode::none, isTree); + if (canBuild.Error != Status::Ok) + { + canBuild.ErrorTitle = STR_CANT_POSITION_THIS_HERE; + return canBuild; + } + + supportsCost += canBuild.Cost; + + const auto clearanceData = canBuild.GetData(); + int32_t tempSceneryGroundFlags = clearanceData.GroundFlags & (ELEMENT_IS_ABOVE_GROUND | ELEMENT_IS_UNDERGROUND); + if (!gameState.cheats.disableClearanceChecks) + { + if ((clearanceData.GroundFlags & ELEMENT_IS_UNDERWATER) || (clearanceData.GroundFlags & ELEMENT_IS_UNDERGROUND)) + { + return Result(Status::Disallowed, STR_CANT_POSITION_THIS_HERE, STR_CANT_BUILD_THIS_UNDERWATER); + } + if (resultData.GroundFlags && !(resultData.GroundFlags & tempSceneryGroundFlags)) + { + return Result( + Status::Disallowed, STR_CANT_POSITION_THIS_HERE, STR_CANT_BUILD_PARTLY_ABOVE_AND_PARTLY_BELOW_GROUND); + } + } + + resultData.GroundFlags = tempSceneryGroundFlags; + + if (!LocationValid(curTile) || MapIsEdge(curTile)) + { + return Result(Status::Disallowed, STR_CANT_POSITION_THIS_HERE, STR_OFF_EDGE_OF_MAP); + } + + if (gLegacyScene != LegacyScene::scenarioEditor && !MapIsLocationOwned({ curTile, zLow }) + && !gameState.cheats.sandboxMode) + { + return Result(Status::Disallowed, STR_CANT_POSITION_THIS_HERE, STR_LAND_NOT_OWNED_BY_PARK); + } } - if (gLegacyScene != LegacyScene::scenarioEditor && !MapIsLocationOwned({ curTile, zLow }) - && !gameState.cheats.sandboxMode) + if (!CheckMapCapacity(sceneryEntry->tiles, totalNumTiles)) { - return GameActions::Result( - GameActions::Status::Disallowed, STR_CANT_POSITION_THIS_HERE, STR_LAND_NOT_OWNED_BY_PARK); - } - } - - if (!CheckMapCapacity(sceneryEntry->tiles, totalNumTiles)) - { - LOG_ERROR("No free map elements available"); - return GameActions::Result( - GameActions::Status::NoFreeElements, STR_CANT_POSITION_THIS_HERE, STR_TILE_ELEMENT_LIMIT_REACHED); - } - - // Force ride construction to recheck area - _currentTrackSelectionFlags.set(TrackSelectionFlag::recheck); - - res.Cost = sceneryEntry->price + supportsCost; - res.SetData(std::move(resultData)); - - return res; -} - -GameActions::Result LargeSceneryPlaceAction::Execute() const -{ - auto res = GameActions::Result(); - res.ErrorTitle = STR_CANT_POSITION_THIS_HERE; - res.Expenditure = ExpenditureType::landscaping; - - int16_t surfaceHeight = TileElementHeight(_loc); - res.Position.x = _loc.x + 16; - res.Position.y = _loc.y + 16; - res.Position.z = surfaceHeight; - - auto resultData = LargeSceneryPlaceActionResult{}; - - money64 supportsCost = 0; - - auto* sceneryEntry = ObjectManager::GetObjectEntry(_sceneryType); - if (sceneryEntry == nullptr) - { - LOG_ERROR("Large scenery entry not found for sceneryType = %u", _sceneryType); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_UNKNOWN_OBJECT_TYPE); - } - - if (sceneryEntry->tiles.empty()) - { - LOG_ERROR("Invalid large scenery object, sceneryType = %u", _sceneryType); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, kStringIdNone); - } - - int16_t maxHeight = GetMaxSurfaceHeight(sceneryEntry->tiles); - - if (_loc.z != 0) - { - maxHeight = _loc.z; - } - - res.Position.z = maxHeight; - - // Allocate banner - Banner* banner = nullptr; - if (sceneryEntry->scrolling_mode != kScrollingModeNone) - { - 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); + LOG_ERROR("No free map elements available"); + return Result(Status::NoFreeElements, STR_CANT_POSITION_THIS_HERE, STR_TILE_ELEMENT_LIMIT_REACHED); } - banner->text = {}; - banner->colour = 2; - banner->textColour = TextColour::white; - banner->flags = { BannerFlag::isLargeScenery }; - banner->type = 0; - banner->position = TileCoordsXY(_loc); + // Force ride construction to recheck area + _currentTrackSelectionFlags.set(TrackSelectionFlag::recheck); - RideId rideIndex = BannerGetClosestRideIndex({ _loc, maxHeight }); - if (!rideIndex.IsNull()) - { - banner->rideIndex = rideIndex; - banner->flags.set(BannerFlag::linkedToRide); - } + res.Cost = sceneryEntry->price + supportsCost; + res.SetData(std::move(resultData)); - resultData.bannerId = banner->id; + return res; } - for (auto& tile : sceneryEntry->tiles) + Result LargeSceneryPlaceAction::Execute() const { - auto curTile = CoordsXY{ tile.offset }.Rotate(_loc.direction); + auto res = Result(); + res.ErrorTitle = STR_CANT_POSITION_THIS_HERE; + res.Expenditure = ExpenditureType::landscaping; - curTile.x += _loc.x; - curTile.y += _loc.y; + int16_t surfaceHeight = TileElementHeight(_loc); + res.Position.x = _loc.x + 16; + res.Position.y = _loc.y + 16; + res.Position.z = surfaceHeight; - int32_t zLow = tile.offset.z + maxHeight; - int32_t zHigh = tile.zClearance + zLow; + auto resultData = LargeSceneryPlaceActionResult{}; - QuarterTile quarterTile = QuarterTile{ tile.corners, 0 }.Rotate(_loc.direction); - const auto isTree = (sceneryEntry->flags & LARGE_SCENERY_FLAG_IS_TREE) != 0; - auto canBuild = MapCanConstructWithClearAt( - { curTile, zLow, zHigh }, &MapPlaceSceneryClearFunc, quarterTile, GetFlags(), CreateCrossingMode::none, isTree); - if (canBuild.Error != GameActions::Status::Ok) + money64 supportsCost = 0; + + auto* sceneryEntry = ObjectManager::GetObjectEntry(_sceneryType); + if (sceneryEntry == nullptr) { + LOG_ERROR("Large scenery entry not found for sceneryType = %u", _sceneryType); + return Result(Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_UNKNOWN_OBJECT_TYPE); + } + + if (sceneryEntry->tiles.empty()) + { + LOG_ERROR("Invalid large scenery object, sceneryType = %u", _sceneryType); + return Result(Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, kStringIdNone); + } + + int16_t maxHeight = GetMaxSurfaceHeight(sceneryEntry->tiles); + + if (_loc.z != 0) + { + maxHeight = _loc.z; + } + + res.Position.z = maxHeight; + + // Allocate banner + Banner* banner = nullptr; + if (sceneryEntry->scrolling_mode != kScrollingModeNone) + { + banner = CreateBanner(); + if (banner == nullptr) + { + LOG_ERROR("No free banners available"); + return Result(Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_TOO_MANY_BANNERS_IN_GAME); + } + + banner->text = {}; + banner->colour = 2; + banner->textColour = TextColour::white; + banner->flags = { BannerFlag::isLargeScenery }; + banner->type = 0; + banner->position = TileCoordsXY(_loc); + + RideId rideIndex = BannerGetClosestRideIndex({ _loc, maxHeight }); + if (!rideIndex.IsNull()) + { + banner->rideIndex = rideIndex; + banner->flags.set(BannerFlag::linkedToRide); + } + + resultData.bannerId = banner->id; + } + + for (auto& tile : sceneryEntry->tiles) + { + auto curTile = CoordsXY{ tile.offset }.Rotate(_loc.direction); + + curTile.x += _loc.x; + curTile.y += _loc.y; + + int32_t zLow = tile.offset.z + maxHeight; + int32_t zHigh = tile.zClearance + zLow; + + QuarterTile quarterTile = QuarterTile{ tile.corners, 0 }.Rotate(_loc.direction); + const auto isTree = (sceneryEntry->flags & LARGE_SCENERY_FLAG_IS_TREE) != 0; + auto canBuild = MapCanConstructWithClearAt( + { curTile, zLow, zHigh }, &MapPlaceSceneryClearFunc, quarterTile, GetFlags(), CreateCrossingMode::none, isTree); + if (canBuild.Error != Status::Ok) + { + if (banner != nullptr) + { + DeleteBanner(banner->id); + } + canBuild.ErrorTitle = STR_CANT_POSITION_THIS_HERE; + return canBuild; + } + + supportsCost += canBuild.Cost; + + const auto clearanceData = canBuild.GetData(); + resultData.GroundFlags = clearanceData.GroundFlags & (ELEMENT_IS_ABOVE_GROUND | ELEMENT_IS_UNDERGROUND); + + if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST)) + { + FootpathRemoveLitter({ curTile, zLow }); + if (!getGameState().cheats.disableClearanceChecks) + { + WallRemoveAt({ curTile, zLow, zHigh }); + } + } + + auto* newSceneryElement = TileElementInsert( + CoordsXYZ{ curTile.x, curTile.y, zLow }, quarterTile.GetBaseQuarterOccupied()); + Guard::Assert(newSceneryElement != nullptr); + newSceneryElement->SetClearanceZ(zHigh); + + SetNewLargeSceneryElement(*newSceneryElement, tile.index); if (banner != nullptr) { - DeleteBanner(banner->id); + newSceneryElement->SetBannerIndex(banner->id); } - canBuild.ErrorTitle = STR_CANT_POSITION_THIS_HERE; - return canBuild; - } - supportsCost += canBuild.Cost; + MapAnimations::MarkTileForInvalidation(TileCoordsXY(curTile)); + MapInvalidateTileFull(curTile); - const auto clearanceData = canBuild.GetData(); - resultData.GroundFlags = clearanceData.GroundFlags & (ELEMENT_IS_ABOVE_GROUND | ELEMENT_IS_UNDERGROUND); - - if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST)) - { - FootpathRemoveLitter({ curTile, zLow }); - if (!getGameState().cheats.disableClearanceChecks) + if (tile.index == 0) { - WallRemoveAt({ curTile, zLow, zHigh }); + resultData.firstTileHeight = zLow; } } - auto* newSceneryElement = TileElementInsert( - CoordsXYZ{ curTile.x, curTile.y, zLow }, quarterTile.GetBaseQuarterOccupied()); - Guard::Assert(newSceneryElement != nullptr); - newSceneryElement->SetClearanceZ(zHigh); + // Force ride construction to recheck area + _currentTrackSelectionFlags.set(TrackSelectionFlag::recheck); - SetNewLargeSceneryElement(*newSceneryElement, tile.index); - if (banner != nullptr) - { - newSceneryElement->SetBannerIndex(banner->id); - } + res.Cost = sceneryEntry->price + supportsCost; + res.SetData(std::move(resultData)); - MapAnimations::MarkTileForInvalidation(TileCoordsXY(curTile)); - MapInvalidateTileFull(curTile); - - if (tile.index == 0) - { - resultData.firstTileHeight = zLow; - } + return res; } - // Force ride construction to recheck area - _currentTrackSelectionFlags.set(TrackSelectionFlag::recheck); - - res.Cost = sceneryEntry->price + supportsCost; - res.SetData(std::move(resultData)); - - return res; -} - -bool LargeSceneryPlaceAction::CheckMapCapacity(std::span tiles, size_t numTiles) const -{ - for (auto& tile : tiles) + bool LargeSceneryPlaceAction::CheckMapCapacity(std::span tiles, size_t numTiles) const { - auto curTile = CoordsXY{ tile.offset }.Rotate(_loc.direction); - - curTile.x += _loc.x; - curTile.y += _loc.y; - if (!MapCheckCapacityAndReorganise(curTile, numTiles)) + for (auto& tile : tiles) { - return false; + auto curTile = CoordsXY{ tile.offset }.Rotate(_loc.direction); + + curTile.x += _loc.x; + curTile.y += _loc.y; + if (!MapCheckCapacityAndReorganise(curTile, numTiles)) + { + return false; + } } + return true; } - return true; -} -int16_t LargeSceneryPlaceAction::GetMaxSurfaceHeight(std::span tiles) const -{ - int16_t maxHeight = -1; - for (auto& tile : tiles) + int16_t LargeSceneryPlaceAction::GetMaxSurfaceHeight(std::span tiles) const { - auto curTile = CoordsXY{ tile.offset }.Rotate(_loc.direction); - - curTile.x += _loc.x; - curTile.y += _loc.y; - - if (!MapIsLocationValid(curTile)) + int16_t maxHeight = -1; + for (auto& tile : tiles) { - continue; - } + auto curTile = CoordsXY{ tile.offset }.Rotate(_loc.direction); - auto* surfaceElement = MapGetSurfaceElementAt(curTile); - if (surfaceElement == nullptr) - continue; + curTile.x += _loc.x; + curTile.y += _loc.y; - int32_t baseZ = surfaceElement->GetBaseZ(); - int32_t slope = surfaceElement->GetSlope(); + if (!MapIsLocationValid(curTile)) + { + continue; + } - if ((slope & kTileSlopeRaisedCornersMask) != kTileSlopeFlat) - { - baseZ += kLandHeightStep; - if (slope & kTileSlopeDiagonalFlag) + auto* surfaceElement = MapGetSurfaceElementAt(curTile); + if (surfaceElement == nullptr) + continue; + + int32_t baseZ = surfaceElement->GetBaseZ(); + int32_t slope = surfaceElement->GetSlope(); + + if ((slope & kTileSlopeRaisedCornersMask) != kTileSlopeFlat) { baseZ += kLandHeightStep; + if (slope & kTileSlopeDiagonalFlag) + { + baseZ += kLandHeightStep; + } + } + + if (baseZ > maxHeight) + { + maxHeight = baseZ; } } + return maxHeight; + } - if (baseZ > maxHeight) + void LargeSceneryPlaceAction::SetNewLargeSceneryElement(LargeSceneryElement& sceneryElement, uint8_t tileNum) const + { + sceneryElement.SetDirection(_loc.direction); + sceneryElement.SetEntryIndex(_sceneryType); + sceneryElement.SetSequenceIndex(tileNum); + sceneryElement.SetPrimaryColour(_primaryColour); + sceneryElement.SetSecondaryColour(_secondaryColour); + sceneryElement.SetTertiaryColour(_tertiaryColour); + + if (GetFlags() & GAME_COMMAND_FLAG_GHOST) { - maxHeight = baseZ; + sceneryElement.SetGhost(true); } } - return maxHeight; -} - -void LargeSceneryPlaceAction::SetNewLargeSceneryElement(LargeSceneryElement& sceneryElement, uint8_t tileNum) const -{ - sceneryElement.SetDirection(_loc.direction); - sceneryElement.SetEntryIndex(_sceneryType); - sceneryElement.SetSequenceIndex(tileNum); - sceneryElement.SetPrimaryColour(_primaryColour); - sceneryElement.SetSecondaryColour(_secondaryColour); - sceneryElement.SetTertiaryColour(_tertiaryColour); - - if (GetFlags() & GAME_COMMAND_FLAG_GHOST) - { - sceneryElement.SetGhost(true); - } -} +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/LargeSceneryPlaceAction.h b/src/openrct2/actions/LargeSceneryPlaceAction.h index ed6f494fdb..730061f82f 100644 --- a/src/openrct2/actions/LargeSceneryPlaceAction.h +++ b/src/openrct2/actions/LargeSceneryPlaceAction.h @@ -11,45 +11,48 @@ #include "GameAction.h" -struct LargeSceneryPlaceActionResult -{ - uint8_t GroundFlags{ 0 }; - int32_t firstTileHeight{ 0 }; - BannerIndex bannerId = BannerIndex::GetNull(); -}; - namespace OpenRCT2 { struct LargeSceneryTile; struct LargeSceneryElement; } // namespace OpenRCT2 -class LargeSceneryPlaceAction final : public GameActionBase +namespace OpenRCT2::GameActions { -private: - CoordsXYZD _loc; - OpenRCT2::ObjectEntryIndex _sceneryType{ OpenRCT2::kObjectEntryIndexNull }; - uint8_t _primaryColour{}; - uint8_t _secondaryColour{}; - uint8_t _tertiaryColour{}; + struct LargeSceneryPlaceActionResult + { + uint8_t GroundFlags{ 0 }; + int32_t firstTileHeight{ 0 }; + BannerIndex bannerId = BannerIndex::GetNull(); + }; -public: - LargeSceneryPlaceAction() = default; + class LargeSceneryPlaceAction final : public GameActionBase + { + private: + CoordsXYZD _loc; + ObjectEntryIndex _sceneryType{ kObjectEntryIndexNull }; + uint8_t _primaryColour{}; + uint8_t _secondaryColour{}; + uint8_t _tertiaryColour{}; - LargeSceneryPlaceAction( - const CoordsXYZD& loc, OpenRCT2::ObjectEntryIndex sceneryType, uint8_t primaryColour, uint8_t secondaryColour, - uint8_t tertiaryColour); + public: + LargeSceneryPlaceAction() = default; - void AcceptParameters(GameActionParameterVisitor& visitor) override; + LargeSceneryPlaceAction( + const CoordsXYZD& loc, ObjectEntryIndex sceneryType, uint8_t primaryColour, uint8_t secondaryColour, + uint8_t tertiaryColour); - uint16_t GetActionFlags() const override; + void AcceptParameters(GameActionParameterVisitor& visitor) override; - void Serialise(DataSerialiser& stream) override; - OpenRCT2::GameActions::Result Query() const override; - OpenRCT2::GameActions::Result Execute() const override; + uint16_t GetActionFlags() const override; -private: - bool CheckMapCapacity(std::span tiles, size_t numTiles) const; - int16_t GetMaxSurfaceHeight(std::span tiles) const; - void SetNewLargeSceneryElement(OpenRCT2::LargeSceneryElement& sceneryElement, uint8_t tileNum) const; -}; + void Serialise(DataSerialiser& stream) override; + Result Query() const override; + Result Execute() const override; + + private: + bool CheckMapCapacity(std::span tiles, size_t numTiles) const; + int16_t GetMaxSurfaceHeight(std::span tiles) const; + void SetNewLargeSceneryElement(LargeSceneryElement& sceneryElement, uint8_t tileNum) const; + }; +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/LargeSceneryRemoveAction.cpp b/src/openrct2/actions/LargeSceneryRemoveAction.cpp index aa33d6d92a..6244b7e71d 100644 --- a/src/openrct2/actions/LargeSceneryRemoveAction.cpp +++ b/src/openrct2/actions/LargeSceneryRemoveAction.cpp @@ -22,197 +22,196 @@ #include "../world/TileElementsView.h" #include "../world/tile_element/LargeSceneryElement.h" -using namespace OpenRCT2; - -LargeSceneryRemoveAction::LargeSceneryRemoveAction(const CoordsXYZD& location, uint16_t tileIndex) - : _loc(location) - , _tileIndex(tileIndex) +namespace OpenRCT2::GameActions { -} - -void LargeSceneryRemoveAction::AcceptParameters(GameActionParameterVisitor& visitor) -{ - visitor.Visit(_loc); - visitor.Visit("tileIndex", _tileIndex); -} - -uint16_t LargeSceneryRemoveAction::GetActionFlags() const -{ - return GameAction::GetActionFlags(); -} - -void LargeSceneryRemoveAction::Serialise(DataSerialiser& stream) -{ - GameAction::Serialise(stream); - - stream << DS_TAG(_loc) << DS_TAG(_tileIndex); -} - -GameActions::Result LargeSceneryRemoveAction::Query() const -{ - auto res = GameActions::Result(); - - const uint32_t flags = GetFlags(); - - res.Position.x = _loc.x + 16; - res.Position.y = _loc.y + 16; - res.Position.z = _loc.z; - res.Expenditure = ExpenditureType::landscaping; - res.Cost = 0; - - TileElement* tileElement = FindLargeSceneryElement(_loc, _tileIndex); - if (tileElement == nullptr) + LargeSceneryRemoveAction::LargeSceneryRemoveAction(const CoordsXYZD& location, uint16_t tileIndex) + : _loc(location) + , _tileIndex(tileIndex) { - LOG_ERROR("No large scenery element to remove at x = %d, y = %d", _loc.x, _loc.y); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_INVALID_SELECTION_OF_OBJECTS); } - auto* sceneryEntry = tileElement->AsLargeScenery()->GetEntry(); - // If we have a bugged scenery entry, do not touch the tile element. - if (sceneryEntry == nullptr) + void LargeSceneryRemoveAction::AcceptParameters(GameActionParameterVisitor& visitor) { - LOG_WARNING("Scenery entry at x = %d, y = %d not removed because it is an unknown object type", _loc.x, _loc.y); - return GameActions::Result(GameActions::Status::Unknown, STR_CANT_REMOVE_THIS, STR_UNKNOWN_OBJECT_TYPE); + visitor.Visit(_loc); + visitor.Visit("tileIndex", _tileIndex); } - auto rotatedOffsets = CoordsXYZ{ CoordsXY{ sceneryEntry->tiles[_tileIndex].offset }.Rotate(_loc.direction), - sceneryEntry->tiles[_tileIndex].offset.z }; - - auto firstTile = CoordsXYZ{ _loc.x, _loc.y, _loc.z } - rotatedOffsets; - - bool calculate_cost = true; - for (auto& tile : sceneryEntry->tiles) + uint16_t LargeSceneryRemoveAction::GetActionFlags() const { - auto currentTileRotatedOffset = CoordsXYZ{ CoordsXY{ tile.offset }.Rotate(_loc.direction), tile.offset.z }; + return GameAction::GetActionFlags(); + } - auto currentTile = CoordsXYZ{ firstTile.x, firstTile.y, firstTile.z } + currentTileRotatedOffset; + void LargeSceneryRemoveAction::Serialise(DataSerialiser& stream) + { + GameAction::Serialise(stream); - if (gLegacyScene != LegacyScene::scenarioEditor && !getGameState().cheats.sandboxMode) + stream << DS_TAG(_loc) << DS_TAG(_tileIndex); + } + + Result LargeSceneryRemoveAction::Query() const + { + auto res = Result(); + + const uint32_t flags = GetFlags(); + + res.Position.x = _loc.x + 16; + res.Position.y = _loc.y + 16; + res.Position.z = _loc.z; + res.Expenditure = ExpenditureType::landscaping; + res.Cost = 0; + + TileElement* tileElement = FindLargeSceneryElement(_loc, _tileIndex); + if (tileElement == nullptr) { - if (getGameState().park.flags & PARK_FLAGS_FORBID_TREE_REMOVAL) + LOG_ERROR("No large scenery element to remove at x = %d, y = %d", _loc.x, _loc.y); + return Result(Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_INVALID_SELECTION_OF_OBJECTS); + } + + auto* sceneryEntry = tileElement->AsLargeScenery()->GetEntry(); + // If we have a bugged scenery entry, do not touch the tile element. + if (sceneryEntry == nullptr) + { + LOG_WARNING("Scenery entry at x = %d, y = %d not removed because it is an unknown object type", _loc.x, _loc.y); + return Result(Status::Unknown, STR_CANT_REMOVE_THIS, STR_UNKNOWN_OBJECT_TYPE); + } + + auto rotatedOffsets = CoordsXYZ{ CoordsXY{ sceneryEntry->tiles[_tileIndex].offset }.Rotate(_loc.direction), + sceneryEntry->tiles[_tileIndex].offset.z }; + + auto firstTile = CoordsXYZ{ _loc.x, _loc.y, _loc.z } - rotatedOffsets; + + bool calculate_cost = true; + for (auto& tile : sceneryEntry->tiles) + { + auto currentTileRotatedOffset = CoordsXYZ{ CoordsXY{ tile.offset }.Rotate(_loc.direction), tile.offset.z }; + + auto currentTile = CoordsXYZ{ firstTile.x, firstTile.y, firstTile.z } + currentTileRotatedOffset; + + if (gLegacyScene != LegacyScene::scenarioEditor && !getGameState().cheats.sandboxMode) { - if (sceneryEntry->HasFlag(LARGE_SCENERY_FLAG_IS_TREE)) + if (getGameState().park.flags & PARK_FLAGS_FORBID_TREE_REMOVAL) { - res.Error = GameActions::Status::NoClearance; - res.ErrorTitle = STR_CANT_REMOVE_THIS; - res.ErrorMessage = STR_FORBIDDEN_BY_THE_LOCAL_AUTHORITY; - return res; + if (sceneryEntry->HasFlag(LARGE_SCENERY_FLAG_IS_TREE)) + { + res.Error = Status::NoClearance; + res.ErrorTitle = STR_CANT_REMOVE_THIS; + res.ErrorMessage = STR_FORBIDDEN_BY_THE_LOCAL_AUTHORITY; + return res; + } + } + + if (!MapIsLocationOwned({ currentTile.x, currentTile.y, currentTile.z })) + { + return Result(Status::NoClearance, STR_CANT_REMOVE_THIS, STR_LAND_NOT_OWNED_BY_PARK); } } - if (!MapIsLocationOwned({ currentTile.x, currentTile.y, currentTile.z })) + if (!LocationValid(currentTile)) { - return GameActions::Result(GameActions::Status::NoClearance, STR_CANT_REMOVE_THIS, STR_LAND_NOT_OWNED_BY_PARK); + return Result(Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_OFF_EDGE_OF_MAP); + } + // Prevent duplicate costs when using the clear scenery tool that overlaps multiple large + // scenery tile elements. + if (flags & GAME_COMMAND_FLAG_TRACK_DESIGN) + { + if (tileElement->AsLargeScenery()->IsAccounted()) + calculate_cost = false; + + // Sets the flag to prevent this being counted in additional calls + tileElement->AsLargeScenery()->SetIsAccounted(true); } } - if (!LocationValid(currentTile)) - { - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_OFF_EDGE_OF_MAP); - } - // Prevent duplicate costs when using the clear scenery tool that overlaps multiple large - // scenery tile elements. - if (flags & GAME_COMMAND_FLAG_TRACK_DESIGN) - { - if (tileElement->AsLargeScenery()->IsAccounted()) - calculate_cost = false; + if (calculate_cost) + res.Cost = sceneryEntry->removal_price; - // Sets the flag to prevent this being counted in additional calls - tileElement->AsLargeScenery()->SetIsAccounted(true); - } + return res; } - if (calculate_cost) + Result LargeSceneryRemoveAction::Execute() const + { + auto res = Result(); + + res.Position.x = _loc.x + 16; + res.Position.y = _loc.y + 16; + res.Position.z = _loc.z; + res.Expenditure = ExpenditureType::landscaping; + res.Cost = 0; + + TileElement* tileElement = FindLargeSceneryElement(_loc, _tileIndex); + if (tileElement == nullptr) + { + LOG_ERROR("No large scenery element to remove at %d, y = %d", _loc.x, _loc.y); + return Result(Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_INVALID_SELECTION_OF_OBJECTS); + } + + auto* sceneryEntry = tileElement->AsLargeScenery()->GetEntry(); + // If we have a bugged scenery entry, do not touch the tile element. + if (sceneryEntry == nullptr) + { + LOG_WARNING("Scenery entry at x = %d, y = %d not removed because it is an unknown object type", _loc.x, _loc.y); + return Result(Status::Unknown, STR_CANT_REMOVE_THIS, kStringIdNone); + } + + tileElement->RemoveBannerEntry(); + + auto rotatedFirstTile = CoordsXYZ{ CoordsXY{ sceneryEntry->tiles[_tileIndex].offset }.Rotate(_loc.direction), + sceneryEntry->tiles[_tileIndex].offset.z }; + + auto firstTile = CoordsXYZ{ _loc.x, _loc.y, _loc.z } - rotatedFirstTile; + + for (auto& tile : sceneryEntry->tiles) + { + auto rotatedCurrentTile = CoordsXYZ{ CoordsXY{ tile.offset }.Rotate(_loc.direction), tile.offset.z }; + + auto currentTile = CoordsXYZ{ firstTile.x, firstTile.y, firstTile.z } + rotatedCurrentTile; + + if (gLegacyScene != LegacyScene::scenarioEditor && !getGameState().cheats.sandboxMode) + { + if (!MapIsLocationOwned({ currentTile.x, currentTile.y, currentTile.z })) + { + return Result(Status::NoClearance, STR_CANT_REMOVE_THIS, STR_LAND_NOT_OWNED_BY_PARK); + } + } + + auto* sceneryElement = FindLargeSceneryElement(currentTile, tile.index); + if (sceneryElement == nullptr) + { + LOG_ERROR("Tile not found when trying to remove element!"); + } + else + { + MapInvalidateTileFull(currentTile); + TileElementRemove(sceneryElement); + } + } + res.Cost = sceneryEntry->removal_price; - return res; -} - -GameActions::Result LargeSceneryRemoveAction::Execute() const -{ - auto res = GameActions::Result(); - - res.Position.x = _loc.x + 16; - res.Position.y = _loc.y + 16; - res.Position.z = _loc.z; - res.Expenditure = ExpenditureType::landscaping; - res.Cost = 0; - - TileElement* tileElement = FindLargeSceneryElement(_loc, _tileIndex); - if (tileElement == nullptr) - { - LOG_ERROR("No large scenery element to remove at %d, y = %d", _loc.x, _loc.y); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_INVALID_SELECTION_OF_OBJECTS); + return res; } - auto* sceneryEntry = tileElement->AsLargeScenery()->GetEntry(); - // If we have a bugged scenery entry, do not touch the tile element. - if (sceneryEntry == nullptr) + TileElement* LargeSceneryRemoveAction::FindLargeSceneryElement(const CoordsXYZ& pos, int32_t sequenceIndex) const { - LOG_WARNING("Scenery entry at x = %d, y = %d not removed because it is an unknown object type", _loc.x, _loc.y); - return GameActions::Result(GameActions::Status::Unknown, STR_CANT_REMOVE_THIS, kStringIdNone); - } - - tileElement->RemoveBannerEntry(); - - auto rotatedFirstTile = CoordsXYZ{ CoordsXY{ sceneryEntry->tiles[_tileIndex].offset }.Rotate(_loc.direction), - sceneryEntry->tiles[_tileIndex].offset.z }; - - auto firstTile = CoordsXYZ{ _loc.x, _loc.y, _loc.z } - rotatedFirstTile; - - for (auto& tile : sceneryEntry->tiles) - { - auto rotatedCurrentTile = CoordsXYZ{ CoordsXY{ tile.offset }.Rotate(_loc.direction), tile.offset.z }; - - auto currentTile = CoordsXYZ{ firstTile.x, firstTile.y, firstTile.z } + rotatedCurrentTile; - - if (gLegacyScene != LegacyScene::scenarioEditor && !getGameState().cheats.sandboxMode) + const bool isGhost = GetFlags() & GAME_COMMAND_FLAG_GHOST; + for (auto* sceneryElement : TileElementsView(pos)) { - if (!MapIsLocationOwned({ currentTile.x, currentTile.y, currentTile.z })) - { - return GameActions::Result(GameActions::Status::NoClearance, STR_CANT_REMOVE_THIS, STR_LAND_NOT_OWNED_BY_PARK); - } + // If we are removing ghost elements + if (isGhost && sceneryElement->IsGhost() == false) + continue; + + if (sceneryElement->GetDirection() != _loc.direction) + continue; + + if (sceneryElement->GetSequenceIndex() != sequenceIndex) + continue; + + if (sceneryElement->GetBaseZ() != pos.z) + continue; + + return sceneryElement->as(); } - auto* sceneryElement = FindLargeSceneryElement(currentTile, tile.index); - if (sceneryElement == nullptr) - { - LOG_ERROR("Tile not found when trying to remove element!"); - } - else - { - MapInvalidateTileFull(currentTile); - TileElementRemove(sceneryElement); - } + return nullptr; } - - res.Cost = sceneryEntry->removal_price; - - return res; -} - -TileElement* LargeSceneryRemoveAction::FindLargeSceneryElement(const CoordsXYZ& pos, int32_t sequenceIndex) const -{ - const bool isGhost = GetFlags() & GAME_COMMAND_FLAG_GHOST; - for (auto* sceneryElement : TileElementsView(pos)) - { - // If we are removing ghost elements - if (isGhost && sceneryElement->IsGhost() == false) - continue; - - if (sceneryElement->GetDirection() != _loc.direction) - continue; - - if (sceneryElement->GetSequenceIndex() != sequenceIndex) - continue; - - if (sceneryElement->GetBaseZ() != pos.z) - continue; - - return sceneryElement->as(); - } - - return nullptr; -} +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/LargeSceneryRemoveAction.h b/src/openrct2/actions/LargeSceneryRemoveAction.h index ac68c1a2f4..6b6e5e0b79 100644 --- a/src/openrct2/actions/LargeSceneryRemoveAction.h +++ b/src/openrct2/actions/LargeSceneryRemoveAction.h @@ -11,24 +11,27 @@ #include "GameAction.h" -class LargeSceneryRemoveAction final : public GameActionBase +namespace OpenRCT2::GameActions { -private: - CoordsXYZD _loc; - uint16_t _tileIndex{}; + class LargeSceneryRemoveAction final : public GameActionBase + { + private: + CoordsXYZD _loc; + uint16_t _tileIndex{}; -public: - LargeSceneryRemoveAction() = default; - LargeSceneryRemoveAction(const CoordsXYZD& location, uint16_t tileIndex); + public: + LargeSceneryRemoveAction() = default; + LargeSceneryRemoveAction(const CoordsXYZD& location, uint16_t tileIndex); - 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* FindLargeSceneryElement(const CoordsXYZ& pos, int32_t sequenceIndex) const; -}; + private: + TileElement* FindLargeSceneryElement(const CoordsXYZ& pos, int32_t sequenceIndex) const; + }; +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/LargeScenerySetColourAction.cpp b/src/openrct2/actions/LargeScenerySetColourAction.cpp index 4664aa7cc2..03fad8e6ef 100644 --- a/src/openrct2/actions/LargeScenerySetColourAction.cpp +++ b/src/openrct2/actions/LargeScenerySetColourAction.cpp @@ -17,146 +17,147 @@ #include "../world/Scenery.h" #include "../world/tile_element/LargeSceneryElement.h" -using namespace OpenRCT2; - -LargeScenerySetColourAction::LargeScenerySetColourAction( - const CoordsXYZD& loc, uint8_t tileIndex, uint8_t primaryColour, uint8_t secondaryColour, uint8_t tertiaryColour) - : _loc(loc) - , _tileIndex(tileIndex) - , _primaryColour(primaryColour) - , _secondaryColour(secondaryColour) - , _tertiaryColour(tertiaryColour) +namespace OpenRCT2::GameActions { -} - -void LargeScenerySetColourAction::AcceptParameters(GameActionParameterVisitor& visitor) -{ - visitor.Visit(_loc); - visitor.Visit("tileIndex", _tileIndex); - visitor.Visit("primaryColour", _primaryColour); - visitor.Visit("secondaryColour", _secondaryColour); - visitor.Visit("tertiaryColour", _tertiaryColour); -} - -uint16_t LargeScenerySetColourAction::GetActionFlags() const -{ - return GameAction::GetActionFlags() | GameActions::Flags::AllowWhilePaused; -} - -void LargeScenerySetColourAction::Serialise(DataSerialiser& stream) -{ - GameAction::Serialise(stream); - - stream << DS_TAG(_loc) << DS_TAG(_tileIndex) << DS_TAG(_primaryColour) << DS_TAG(_secondaryColour) - << DS_TAG(_tertiaryColour); -} - -GameActions::Result LargeScenerySetColourAction::Query() const -{ - return QueryExecute(false); -} - -GameActions::Result LargeScenerySetColourAction::Execute() const -{ - return QueryExecute(true); -} - -GameActions::Result LargeScenerySetColourAction::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 = TileElementHeight(_loc); - res.ErrorTitle = STR_CANT_REPAINT_THIS; - - auto mapSizeMax = GetMapSizeMaxXY(); - if (_loc.x < 0 || _loc.y < 0 || _loc.x > mapSizeMax.x || _loc.y > mapSizeMax.y) + LargeScenerySetColourAction::LargeScenerySetColourAction( + const CoordsXYZD& loc, uint8_t tileIndex, uint8_t primaryColour, uint8_t secondaryColour, uint8_t tertiaryColour) + : _loc(loc) + , _tileIndex(tileIndex) + , _primaryColour(primaryColour) + , _secondaryColour(secondaryColour) + , _tertiaryColour(tertiaryColour) { - 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_ERR_VALUE_OUT_OF_RANGE); } - if (_primaryColour >= COLOUR_COUNT) + void LargeScenerySetColourAction::AcceptParameters(GameActionParameterVisitor& visitor) { - LOG_ERROR("Invalid primary colour %u", _primaryColour); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_INVALID_COLOUR); - } - else if (_secondaryColour >= COLOUR_COUNT) - { - LOG_ERROR("Invalid secondary colour %u", _secondaryColour); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_INVALID_COLOUR); - } - else if (_tertiaryColour >= COLOUR_COUNT) - { - LOG_ERROR("Invalid tertiary colour %u", _tertiaryColour); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_INVALID_COLOUR); + visitor.Visit(_loc); + visitor.Visit("tileIndex", _tileIndex); + visitor.Visit("primaryColour", _primaryColour); + visitor.Visit("secondaryColour", _secondaryColour); + visitor.Visit("tertiaryColour", _tertiaryColour); } - auto largeElement = MapGetLargeScenerySegment(_loc, _tileIndex); - - if (largeElement == nullptr) + uint16_t LargeScenerySetColourAction::GetActionFlags() const { - LOG_ERROR( - "Could not find large scenery at: x = %d, y = %d, z = %d, direction = %d, tileIndex = %u", _loc.x, _loc.y, _loc.z, - _loc.direction, _tileIndex); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, kStringIdNone); + return GameAction::GetActionFlags() | Flags::AllowWhilePaused; } - if ((GetFlags() & GAME_COMMAND_FLAG_GHOST) && !(largeElement->IsGhost())) + void LargeScenerySetColourAction::Serialise(DataSerialiser& stream) { - return res; + GameAction::Serialise(stream); + + stream << DS_TAG(_loc) << DS_TAG(_tileIndex) << DS_TAG(_primaryColour) << DS_TAG(_secondaryColour) + << DS_TAG(_tertiaryColour); } - auto* sceneryEntry = largeElement->GetEntry(); - - if (sceneryEntry == nullptr) + Result LargeScenerySetColourAction::Query() const { - LOG_ERROR("Scenery element doesn't have scenery entry"); - return GameActions::Result(GameActions::Status::Unknown, STR_CANT_REPAINT_THIS, kStringIdNone); + return QueryExecute(false); } - // Work out the base tile coordinates (Tile with index 0) - auto rotatedBaseCoordsOffset = CoordsXYZ{ CoordsXY{ sceneryEntry->tiles[_tileIndex].offset }.Rotate(_loc.direction), - sceneryEntry->tiles[_tileIndex].offset.z }; - auto baseTile = CoordsXYZ{ _loc.x, _loc.y, _loc.z } - rotatedBaseCoordsOffset; - - for (auto& tile : sceneryEntry->tiles) + Result LargeScenerySetColourAction::Execute() const { - // Work out the current tile coordinates - auto rotatedTileCoords = CoordsXYZ{ CoordsXY{ tile.offset }.Rotate(_loc.direction), tile.offset.z }; - auto currentTile = CoordsXYZ{ baseTile.x, baseTile.y, baseTile.z } + rotatedTileCoords; + return QueryExecute(true); + } - if (gLegacyScene != LegacyScene::scenarioEditor && !getGameState().cheats.sandboxMode) + Result LargeScenerySetColourAction::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 = TileElementHeight(_loc); + res.ErrorTitle = STR_CANT_REPAINT_THIS; + + auto mapSizeMax = GetMapSizeMaxXY(); + if (_loc.x < 0 || _loc.y < 0 || _loc.x > mapSizeMax.x || _loc.y > mapSizeMax.y) { - if (!MapIsLocationOwned(currentTile)) - { - return GameActions::Result(GameActions::Status::NotOwned, STR_CANT_REPAINT_THIS, STR_LAND_NOT_OWNED_BY_PARK); - } + LOG_ERROR("Invalid x / y coordinates: x = %d, y = %d", _loc.x, _loc.y); + return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_VALUE_OUT_OF_RANGE); } - if (!LocationValid(currentTile)) + if (_primaryColour >= COLOUR_COUNT) { - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_OFF_EDGE_OF_MAP); + LOG_ERROR("Invalid primary colour %u", _primaryColour); + return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_INVALID_COLOUR); + } + else if (_secondaryColour >= COLOUR_COUNT) + { + LOG_ERROR("Invalid secondary colour %u", _secondaryColour); + return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_INVALID_COLOUR); + } + else if (_tertiaryColour >= COLOUR_COUNT) + { + LOG_ERROR("Invalid tertiary colour %u", _tertiaryColour); + return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_INVALID_COLOUR); } - auto tileElement = MapGetLargeScenerySegment({ currentTile.x, currentTile.y, _loc.z, _loc.direction }, tile.index); + auto largeElement = MapGetLargeScenerySegment(_loc, _tileIndex); - if (tileElement == nullptr) + if (largeElement == nullptr) { LOG_ERROR( - "Large scenery element not found at: x = %d, y = %d, z = %d, direction = %d", _loc.x, _loc.y, _loc.z, - _loc.direction); - return GameActions::Result(GameActions::Status::Unknown, STR_CANT_REPAINT_THIS, kStringIdNone); + "Could not find large scenery at: x = %d, y = %d, z = %d, direction = %d, tileIndex = %u", _loc.x, _loc.y, + _loc.z, _loc.direction, _tileIndex); + return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, kStringIdNone); } - if (isExecuting) - { - tileElement->SetPrimaryColour(_primaryColour); - tileElement->SetSecondaryColour(_secondaryColour); - tileElement->SetTertiaryColour(_tertiaryColour); - MapInvalidateTileFull(currentTile); + if ((GetFlags() & GAME_COMMAND_FLAG_GHOST) && !(largeElement->IsGhost())) + { + return res; } + + auto* sceneryEntry = largeElement->GetEntry(); + + if (sceneryEntry == nullptr) + { + LOG_ERROR("Scenery element doesn't have scenery entry"); + return Result(Status::Unknown, STR_CANT_REPAINT_THIS, kStringIdNone); + } + // Work out the base tile coordinates (Tile with index 0) + auto rotatedBaseCoordsOffset = CoordsXYZ{ CoordsXY{ sceneryEntry->tiles[_tileIndex].offset }.Rotate(_loc.direction), + sceneryEntry->tiles[_tileIndex].offset.z }; + + auto baseTile = CoordsXYZ{ _loc.x, _loc.y, _loc.z } - rotatedBaseCoordsOffset; + + for (auto& tile : sceneryEntry->tiles) + { + // Work out the current tile coordinates + auto rotatedTileCoords = CoordsXYZ{ CoordsXY{ tile.offset }.Rotate(_loc.direction), tile.offset.z }; + auto currentTile = CoordsXYZ{ baseTile.x, baseTile.y, baseTile.z } + rotatedTileCoords; + + if (gLegacyScene != LegacyScene::scenarioEditor && !getGameState().cheats.sandboxMode) + { + if (!MapIsLocationOwned(currentTile)) + { + return Result(Status::NotOwned, STR_CANT_REPAINT_THIS, STR_LAND_NOT_OWNED_BY_PARK); + } + } + + if (!LocationValid(currentTile)) + { + return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_OFF_EDGE_OF_MAP); + } + + auto tileElement = MapGetLargeScenerySegment({ currentTile.x, currentTile.y, _loc.z, _loc.direction }, tile.index); + + if (tileElement == nullptr) + { + LOG_ERROR( + "Large scenery element not found at: x = %d, y = %d, z = %d, direction = %d", _loc.x, _loc.y, _loc.z, + _loc.direction); + return Result(Status::Unknown, STR_CANT_REPAINT_THIS, kStringIdNone); + } + if (isExecuting) + { + tileElement->SetPrimaryColour(_primaryColour); + tileElement->SetSecondaryColour(_secondaryColour); + tileElement->SetTertiaryColour(_tertiaryColour); + + MapInvalidateTileFull(currentTile); + } + } + return res; } - return res; -} +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/LargeScenerySetColourAction.h b/src/openrct2/actions/LargeScenerySetColourAction.h index 2889f2cf48..f0a56d7dcb 100644 --- a/src/openrct2/actions/LargeScenerySetColourAction.h +++ b/src/openrct2/actions/LargeScenerySetColourAction.h @@ -11,28 +11,31 @@ #include "GameAction.h" -class LargeScenerySetColourAction final : public GameActionBase +namespace OpenRCT2::GameActions { -private: - CoordsXYZD _loc; - uint8_t _tileIndex{}; - uint8_t _primaryColour{}; - uint8_t _secondaryColour{}; - uint8_t _tertiaryColour{}; + class LargeScenerySetColourAction final : public GameActionBase + { + private: + CoordsXYZD _loc; + uint8_t _tileIndex{}; + uint8_t _primaryColour{}; + uint8_t _secondaryColour{}; + uint8_t _tertiaryColour{}; -public: - LargeScenerySetColourAction() = default; - LargeScenerySetColourAction( - const CoordsXYZD& loc, uint8_t tileIndex, uint8_t primaryColour, uint8_t secondaryColour, uint8_t tertiaryColour); + public: + LargeScenerySetColourAction() = default; + LargeScenerySetColourAction( + const CoordsXYZD& loc, uint8_t tileIndex, uint8_t primaryColour, uint8_t secondaryColour, uint8_t tertiaryColour); - 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 diff --git a/src/openrct2/actions/ScenerySetRestrictedAction.cpp b/src/openrct2/actions/ScenerySetRestrictedAction.cpp index 18c4af81b6..2270091068 100644 --- a/src/openrct2/actions/ScenerySetRestrictedAction.cpp +++ b/src/openrct2/actions/ScenerySetRestrictedAction.cpp @@ -12,47 +12,48 @@ #include "../object/SceneryGroupObject.h" #include "../world/Scenery.h" -using namespace OpenRCT2; - -ScenerySetRestrictedAction::ScenerySetRestrictedAction(ObjectType objectType, ObjectEntryIndex entryIndex, bool isRestricted) - : _objectType(objectType) - , _objectIndex(entryIndex) - , _isRestricted(isRestricted) +namespace OpenRCT2::GameActions { -} - -void ScenerySetRestrictedAction::Serialise(DataSerialiser& stream) -{ - GameAction::Serialise(stream); - - stream << DS_TAG(_objectType) << DS_TAG(_objectIndex) << DS_TAG(_isRestricted); -} - -uint16_t ScenerySetRestrictedAction::GetActionFlags() const -{ - return GameAction::GetActionFlags() | GameActions::Flags::AllowWhilePaused; -} - -GameActions::Result ScenerySetRestrictedAction::Query() const -{ - if (!ObjectTypeCanBeRestricted(_objectType)) + ScenerySetRestrictedAction::ScenerySetRestrictedAction( + ObjectType objectType, ObjectEntryIndex entryIndex, bool isRestricted) + : _objectType(objectType) + , _objectIndex(entryIndex) + , _isRestricted(isRestricted) { - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_RESTRICT_OBJECT, STR_OBJECT_TYPE_CANNOT_BE_RESTRICTED); - } - const auto* loadedObject = ObjectEntryGetObject(_objectType, _objectIndex); - if (loadedObject == nullptr) - { - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_RESTRICT_OBJECT, STR_OBJECT_NOT_FOUND); } - return GameActions::Result(); -} + void ScenerySetRestrictedAction::Serialise(DataSerialiser& stream) + { + GameAction::Serialise(stream); -GameActions::Result ScenerySetRestrictedAction::Execute() const -{ - auto sceneryType = GetSceneryTypeFromObjectType(_objectType); - SetSceneryItemRestricted({ sceneryType, _objectIndex }, _isRestricted); + stream << DS_TAG(_objectType) << DS_TAG(_objectIndex) << DS_TAG(_isRestricted); + } - return GameActions::Result(); -} + uint16_t ScenerySetRestrictedAction::GetActionFlags() const + { + return GameAction::GetActionFlags() | Flags::AllowWhilePaused; + } + + Result ScenerySetRestrictedAction::Query() const + { + if (!ObjectTypeCanBeRestricted(_objectType)) + { + return Result(Status::InvalidParameters, STR_CANT_RESTRICT_OBJECT, STR_OBJECT_TYPE_CANNOT_BE_RESTRICTED); + } + const auto* loadedObject = ObjectEntryGetObject(_objectType, _objectIndex); + if (loadedObject == nullptr) + { + return Result(Status::InvalidParameters, STR_CANT_RESTRICT_OBJECT, STR_OBJECT_NOT_FOUND); + } + + return Result(); + } + + Result ScenerySetRestrictedAction::Execute() const + { + auto sceneryType = GetSceneryTypeFromObjectType(_objectType); + SetSceneryItemRestricted({ sceneryType, _objectIndex }, _isRestricted); + + return Result(); + } +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/ScenerySetRestrictedAction.h b/src/openrct2/actions/ScenerySetRestrictedAction.h index 523e140620..cbaec7bb53 100644 --- a/src/openrct2/actions/ScenerySetRestrictedAction.h +++ b/src/openrct2/actions/ScenerySetRestrictedAction.h @@ -11,20 +11,23 @@ #include "GameAction.h" -class ScenerySetRestrictedAction final : public GameActionBase +namespace OpenRCT2::GameActions { -private: - OpenRCT2::ObjectType _objectType; - OpenRCT2::ObjectEntryIndex _objectIndex; - bool _isRestricted; + class ScenerySetRestrictedAction final : public GameActionBase + { + private: + ObjectType _objectType; + ObjectEntryIndex _objectIndex; + bool _isRestricted; -public: - ScenerySetRestrictedAction() = default; - ScenerySetRestrictedAction(OpenRCT2::ObjectType objectType, OpenRCT2::ObjectEntryIndex entryIndex, bool isRestricted); + public: + ScenerySetRestrictedAction() = default; + ScenerySetRestrictedAction(ObjectType objectType, ObjectEntryIndex entryIndex, bool isRestricted); - 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 diff --git a/src/openrct2/actions/SignSetNameAction.cpp b/src/openrct2/actions/SignSetNameAction.cpp index d6b680c11d..dbb209d848 100644 --- a/src/openrct2/actions/SignSetNameAction.cpp +++ b/src/openrct2/actions/SignSetNameAction.cpp @@ -18,97 +18,97 @@ #include -using namespace OpenRCT2; - -SignSetNameAction::SignSetNameAction(BannerIndex bannerIndex, const std::string& name) - : _bannerIndex(bannerIndex) - , _name(name) +namespace OpenRCT2::GameActions { -} - -void SignSetNameAction::AcceptParameters(GameActionParameterVisitor& visitor) -{ - visitor.Visit("id", _bannerIndex); - visitor.Visit("name", _name); -} - -uint16_t SignSetNameAction::GetActionFlags() const -{ - return GameAction::GetActionFlags() | GameActions::Flags::AllowWhilePaused; -} - -void SignSetNameAction::Serialise(DataSerialiser& stream) -{ - GameAction::Serialise(stream); - stream << DS_TAG(_bannerIndex) << DS_TAG(_name); -} - -GameActions::Result SignSetNameAction::Query() const -{ - auto banner = GetBanner(_bannerIndex); - if (banner == nullptr) + SignSetNameAction::SignSetNameAction(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_SIGN, kStringIdNone); } - TileElement* tileElement = BannerGetTileElement(_bannerIndex); - - if (tileElement == nullptr) + void SignSetNameAction::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); } - CoordsXYZ loc = { banner->position.ToCoordsXY(), tileElement->GetBaseZ() }; - - if (!LocationValid(loc)) + uint16_t SignSetNameAction::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 SignSetNameAction::Execute() const -{ - auto banner = GetBanner(_bannerIndex); - if (banner == nullptr) + void SignSetNameAction::Serialise(DataSerialiser& stream) { - LOG_ERROR("Banner not found for bannerIndex %d", _bannerIndex); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_RENAME_SIGN, kStringIdNone); + GameAction::Serialise(stream); + stream << DS_TAG(_bannerIndex) << DS_TAG(_name); } - if (!_name.empty()) + Result SignSetNameAction::Query() const { - banner->flags.unset(BannerFlag::linkedToRide); - banner->rideIndex = RideId::GetNull(); - banner->text = _name; + auto banner = GetBanner(_bannerIndex); + if (banner == nullptr) + { + LOG_ERROR("Banner not found for bannerIndex %d", _bannerIndex); + return Result(Status::InvalidParameters, STR_CANT_RENAME_SIGN, kStringIdNone); + } + + TileElement* tileElement = BannerGetTileElement(_bannerIndex); + + 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); + } + + CoordsXYZ loc = { banner->position.ToCoordsXY(), tileElement->GetBaseZ() }; + + 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(); } - else + + Result SignSetNameAction::Execute() const { - // If empty name take closest ride name. - RideId rideIndex = BannerGetClosestRideIndex({ banner->position.ToCoordsXY(), 16 }); - if (rideIndex.IsNull()) + auto banner = GetBanner(_bannerIndex); + if (banner == nullptr) + { + LOG_ERROR("Banner not found for bannerIndex %d", _bannerIndex); + return Result(Status::InvalidParameters, STR_CANT_RENAME_SIGN, kStringIdNone); + } + + if (!_name.empty()) { banner->flags.unset(BannerFlag::linkedToRide); banner->rideIndex = RideId::GetNull(); - banner->text = {}; + banner->text = _name; } else { - banner->flags.set(BannerFlag::linkedToRide); - banner->rideIndex = rideIndex; - banner->text = {}; + // If empty name take closest ride name. + RideId rideIndex = BannerGetClosestRideIndex({ banner->position.ToCoordsXY(), 16 }); + if (rideIndex.IsNull()) + { + banner->flags.unset(BannerFlag::linkedToRide); + banner->rideIndex = RideId::GetNull(); + banner->text = {}; + } + else + { + banner->flags.set(BannerFlag::linkedToRide); + banner->rideIndex = rideIndex; + banner->text = {}; + } } - } - ScrollingTextInvalidate(); - GfxInvalidateScreen(); - return GameActions::Result(); -} + ScrollingTextInvalidate(); + GfxInvalidateScreen(); + return Result(); + } +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/SignSetNameAction.h b/src/openrct2/actions/SignSetNameAction.h index 73cbfccc9e..6965b4b7b5 100644 --- a/src/openrct2/actions/SignSetNameAction.h +++ b/src/openrct2/actions/SignSetNameAction.h @@ -11,21 +11,24 @@ #include "GameAction.h" -class SignSetNameAction final : public GameActionBase +namespace OpenRCT2::GameActions { -private: - BannerIndex _bannerIndex{ BannerIndex::GetNull() }; - std::string _name; + class SignSetNameAction final : public GameActionBase + { + private: + BannerIndex _bannerIndex{ BannerIndex::GetNull() }; + std::string _name; -public: - SignSetNameAction() = default; - SignSetNameAction(BannerIndex bannerIndex, const std::string& name); + public: + SignSetNameAction() = default; + SignSetNameAction(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 diff --git a/src/openrct2/actions/SignSetStyleAction.cpp b/src/openrct2/actions/SignSetStyleAction.cpp index a97d50db5b..103bd72451 100644 --- a/src/openrct2/actions/SignSetStyleAction.cpp +++ b/src/openrct2/actions/SignSetStyleAction.cpp @@ -20,119 +20,121 @@ #include "../world/tile_element/LargeSceneryElement.h" #include "../world/tile_element/WallElement.h" -using namespace OpenRCT2; - -SignSetStyleAction::SignSetStyleAction(BannerIndex bannerIndex, uint8_t mainColour, uint8_t textColour, bool isLarge) - : _bannerIndex(bannerIndex) - , _mainColour(mainColour) - , _textColour(textColour) - , _isLarge(isLarge) +namespace OpenRCT2::GameActions { -} - -void SignSetStyleAction::AcceptParameters(GameActionParameterVisitor& visitor) -{ - visitor.Visit("id", _bannerIndex); - visitor.Visit("mainColour", _mainColour); - visitor.Visit("textColour", _textColour); - visitor.Visit("isLarge", _isLarge); -} - -uint16_t SignSetStyleAction::GetActionFlags() const -{ - return GameAction::GetActionFlags() | GameActions::Flags::AllowWhilePaused; -} - -void SignSetStyleAction::Serialise(DataSerialiser& stream) -{ - GameAction::Serialise(stream); - stream << DS_TAG(_bannerIndex) << DS_TAG(_mainColour) << DS_TAG(_textColour) << DS_TAG(_isLarge); -} - -GameActions::Result SignSetStyleAction::Query() const -{ - auto banner = GetBanner(_bannerIndex); - if (banner == nullptr) + SignSetStyleAction::SignSetStyleAction(BannerIndex bannerIndex, uint8_t mainColour, uint8_t textColour, bool isLarge) + : _bannerIndex(bannerIndex) + , _mainColour(mainColour) + , _textColour(textColour) + , _isLarge(isLarge) { - LOG_ERROR("Banner not found for bannerIndex %u", _bannerIndex); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, kStringIdNone); } - CoordsXYZ loc; - - if (_isLarge) + void SignSetStyleAction::AcceptParameters(GameActionParameterVisitor& visitor) { - TileElement* tileElement = BannerGetTileElement(_bannerIndex); - if (tileElement == nullptr) + visitor.Visit("id", _bannerIndex); + visitor.Visit("mainColour", _mainColour); + visitor.Visit("textColour", _textColour); + visitor.Visit("isLarge", _isLarge); + } + + uint16_t SignSetStyleAction::GetActionFlags() const + { + return GameAction::GetActionFlags() | Flags::AllowWhilePaused; + } + + void SignSetStyleAction::Serialise(DataSerialiser& stream) + { + GameAction::Serialise(stream); + stream << DS_TAG(_bannerIndex) << DS_TAG(_mainColour) << DS_TAG(_textColour) << DS_TAG(_isLarge); + } + + Result SignSetStyleAction::Query() const + { + auto banner = GetBanner(_bannerIndex); + if (banner == nullptr) { - LOG_ERROR("Banner tile element not found for bannerIndex %u", _bannerIndex); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, kStringIdNone); + LOG_ERROR("Banner not found for bannerIndex %u", _bannerIndex); + return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, kStringIdNone); } - if (tileElement->GetType() != TileElementType::LargeScenery) + + CoordsXYZ loc; + + if (_isLarge) { - LOG_ERROR( - "Tile element has type %u, expected %d (LargeScenery)", tileElement->GetType(), TileElementType::LargeScenery); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, kStringIdNone); + 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); + } + if (tileElement->GetType() != TileElementType::LargeScenery) + { + LOG_ERROR( + "Tile element has type %u, expected %d (LargeScenery)", tileElement->GetType(), + TileElementType::LargeScenery); + return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, kStringIdNone); + } + loc = { banner->position.ToCoordsXY(), tileElement->GetBaseZ() }; } - loc = { banner->position.ToCoordsXY(), tileElement->GetBaseZ() }; - } - else - { - WallElement* wallElement = BannerGetScrollingWallTileElement(_bannerIndex); - - if (wallElement == nullptr) + else { - LOG_ERROR("Wall element not found for bannerIndex", _bannerIndex); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, kStringIdNone); + WallElement* wallElement = BannerGetScrollingWallTileElement(_bannerIndex); + + if (wallElement == nullptr) + { + LOG_ERROR("Wall element not found for bannerIndex", _bannerIndex); + return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, kStringIdNone); + } + loc = { banner->position.ToCoordsXY(), wallElement->GetBaseZ() }; } - loc = { banner->position.ToCoordsXY(), wallElement->GetBaseZ() }; - } - if (!LocationValid(loc)) - { - 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 GameActions::Result(); -} - -GameActions::Result SignSetStyleAction::Execute() const -{ - auto banner = GetBanner(_bannerIndex); - if (banner == nullptr) - { - LOG_ERROR("Invalid banner id %u", _bannerIndex); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, kStringIdNone); - } - - CoordsXY coords = banner->position.ToCoordsXY(); - - if (_isLarge) - { - TileElement* tileElement = BannerGetTileElement(_bannerIndex); - if (!MapLargeScenerySignSetColour( - { coords, tileElement->GetBaseZ(), tileElement->GetDirection() }, - tileElement->AsLargeScenery()->GetSequenceIndex(), _mainColour, _textColour)) + if (!LocationValid(loc)) { - return GameActions::Result(GameActions::Status::Unknown, STR_CANT_REPAINT_THIS, kStringIdNone); + 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(); } - else + + Result SignSetStyleAction::Execute() const { - WallElement* wallElement = BannerGetScrollingWallTileElement(_bannerIndex); + auto banner = GetBanner(_bannerIndex); + if (banner == nullptr) + { + LOG_ERROR("Invalid banner id %u", _bannerIndex); + return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, kStringIdNone); + } - wallElement->SetPrimaryColour(_mainColour); - wallElement->SetSecondaryColour(_textColour); - MapInvalidateTile({ coords, wallElement->GetBaseZ(), wallElement->GetClearanceZ() }); + CoordsXY coords = banner->position.ToCoordsXY(); + + if (_isLarge) + { + TileElement* tileElement = BannerGetTileElement(_bannerIndex); + if (!MapLargeScenerySignSetColour( + { coords, tileElement->GetBaseZ(), tileElement->GetDirection() }, + tileElement->AsLargeScenery()->GetSequenceIndex(), _mainColour, _textColour)) + { + return Result(Status::Unknown, STR_CANT_REPAINT_THIS, kStringIdNone); + } + } + else + { + WallElement* wallElement = BannerGetScrollingWallTileElement(_bannerIndex); + + wallElement->SetPrimaryColour(_mainColour); + wallElement->SetSecondaryColour(_textColour); + MapInvalidateTile({ coords, wallElement->GetBaseZ(), wallElement->GetClearanceZ() }); + } + + auto intent = Intent(INTENT_ACTION_UPDATE_BANNER); + intent.PutExtra(INTENT_EXTRA_BANNER_INDEX, _bannerIndex); + ContextBroadcastIntent(&intent); + + return Result(); } - - auto intent = Intent(INTENT_ACTION_UPDATE_BANNER); - intent.PutExtra(INTENT_EXTRA_BANNER_INDEX, _bannerIndex); - ContextBroadcastIntent(&intent); - - return GameActions::Result(); -} +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/SignSetStyleAction.h b/src/openrct2/actions/SignSetStyleAction.h index ccc5bceaf9..95502dd978 100644 --- a/src/openrct2/actions/SignSetStyleAction.h +++ b/src/openrct2/actions/SignSetStyleAction.h @@ -11,23 +11,26 @@ #include "GameAction.h" -class SignSetStyleAction final : public GameActionBase +namespace OpenRCT2::GameActions { -private: - BannerIndex _bannerIndex{ BannerIndex::GetNull() }; - uint8_t _mainColour{}; - uint8_t _textColour{}; - bool _isLarge{}; + class SignSetStyleAction final : public GameActionBase + { + private: + BannerIndex _bannerIndex{ BannerIndex::GetNull() }; + uint8_t _mainColour{}; + uint8_t _textColour{}; + bool _isLarge{}; -public: - SignSetStyleAction() = default; - SignSetStyleAction(BannerIndex bannerIndex, uint8_t mainColour, uint8_t textColour, bool isLarge); + public: + SignSetStyleAction() = default; + SignSetStyleAction(BannerIndex bannerIndex, uint8_t mainColour, uint8_t textColour, bool isLarge); - 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 diff --git a/src/openrct2/actions/SmallSceneryPlaceAction.cpp b/src/openrct2/actions/SmallSceneryPlaceAction.cpp index b71e3cf5f4..cdc1ebe5f3 100644 --- a/src/openrct2/actions/SmallSceneryPlaceAction.cpp +++ b/src/openrct2/actions/SmallSceneryPlaceAction.cpp @@ -33,431 +33,425 @@ #include "GameAction.h" #include "SmallSceneryRemoveAction.h" -using namespace OpenRCT2; -using namespace OpenRCT2::Numerics; - -SmallSceneryPlaceAction::SmallSceneryPlaceAction( - const CoordsXYZD& loc, uint8_t quadrant, ObjectEntryIndex sceneryType, uint8_t primaryColour, uint8_t secondaryColour, - uint8_t tertiaryColour) - : _loc(loc) - , _quadrant(quadrant) - , _sceneryType(sceneryType) - , _primaryColour(primaryColour) - , _secondaryColour(secondaryColour) - , _tertiaryColour(tertiaryColour) +namespace OpenRCT2::GameActions { -} + using namespace OpenRCT2::Numerics; -void SmallSceneryPlaceAction::AcceptParameters(GameActionParameterVisitor& visitor) -{ - visitor.Visit(_loc); - visitor.Visit("quadrant", _quadrant); - visitor.Visit("object", _sceneryType); - visitor.Visit("primaryColour", _primaryColour); - visitor.Visit("secondaryColour", _secondaryColour); - visitor.Visit("tertiaryColour", _tertiaryColour); -} - -uint32_t SmallSceneryPlaceAction::GetCooldownTime() const -{ - return 20; -} - -uint16_t SmallSceneryPlaceAction::GetActionFlags() const -{ - return GameAction::GetActionFlags(); -} - -void SmallSceneryPlaceAction::Serialise(DataSerialiser& stream) -{ - GameAction::Serialise(stream); - - stream << DS_TAG(_loc) << DS_TAG(_quadrant) << DS_TAG(_sceneryType) << DS_TAG(_primaryColour) << DS_TAG(_secondaryColour) - << DS_TAG(_tertiaryColour); -} - -GameActions::Result SmallSceneryPlaceAction::Query() const -{ - bool isOnWater = false; - bool supportsRequired = false; - if (_loc.z != 0) + SmallSceneryPlaceAction::SmallSceneryPlaceAction( + const CoordsXYZD& loc, uint8_t quadrant, ObjectEntryIndex sceneryType, uint8_t primaryColour, uint8_t secondaryColour, + uint8_t tertiaryColour) + : _loc(loc) + , _quadrant(quadrant) + , _sceneryType(sceneryType) + , _primaryColour(primaryColour) + , _secondaryColour(secondaryColour) + , _tertiaryColour(tertiaryColour) { - supportsRequired = true; } - int32_t landHeight = TileElementHeight(_loc); - int16_t waterHeight = TileElementWaterHeight(_loc); - int32_t surfaceHeight = landHeight; - // If on water - if (waterHeight > 0) + void SmallSceneryPlaceAction::AcceptParameters(GameActionParameterVisitor& visitor) { - surfaceHeight = waterHeight; + visitor.Visit(_loc); + visitor.Visit("quadrant", _quadrant); + visitor.Visit("object", _sceneryType); + visitor.Visit("primaryColour", _primaryColour); + visitor.Visit("secondaryColour", _secondaryColour); + visitor.Visit("tertiaryColour", _tertiaryColour); } - auto res = GameActions::Result(); - auto centre = _loc.ToTileCentre(); - res.Position.x = centre.x; - res.Position.y = centre.y; - res.Position.z = surfaceHeight; - if (_loc.z != 0) + + uint32_t SmallSceneryPlaceAction::GetCooldownTime() const { - surfaceHeight = _loc.z; + return 20; + } + + uint16_t SmallSceneryPlaceAction::GetActionFlags() const + { + return GameAction::GetActionFlags(); + } + + void SmallSceneryPlaceAction::Serialise(DataSerialiser& stream) + { + GameAction::Serialise(stream); + + stream << DS_TAG(_loc) << DS_TAG(_quadrant) << DS_TAG(_sceneryType) << DS_TAG(_primaryColour) + << DS_TAG(_secondaryColour) << DS_TAG(_tertiaryColour); + } + + Result SmallSceneryPlaceAction::Query() const + { + bool isOnWater = false; + bool supportsRequired = false; + if (_loc.z != 0) + { + supportsRequired = true; + } + int32_t landHeight = TileElementHeight(_loc); + int16_t waterHeight = TileElementWaterHeight(_loc); + + int32_t surfaceHeight = landHeight; + // If on water + if (waterHeight > 0) + { + surfaceHeight = waterHeight; + } + auto res = Result(); + auto centre = _loc.ToTileCentre(); + res.Position.x = centre.x; + res.Position.y = centre.y; res.Position.z = surfaceHeight; - } - - if (!LocationValid(_loc)) - { - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_OFF_EDGE_OF_MAP); - } - - if (!MapCheckCapacityAndReorganise(_loc)) - { - return GameActions::Result( - GameActions::Status::NoFreeElements, STR_CANT_POSITION_THIS_HERE, STR_TILE_ELEMENT_LIMIT_REACHED); - } - - auto maxSizeMax = GetMapSizeMaxXY(); - if (!_trackDesignDrawingPreview && (_loc.x > maxSizeMax.x || _loc.y > maxSizeMax.y)) - { - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_ERR_VALUE_OUT_OF_RANGE); - } - - auto* sceneryEntry = ObjectManager::GetObjectEntry(_sceneryType); - if (sceneryEntry == nullptr) - { - LOG_ERROR("Small scenery object entry not found for sceneryType %u", _sceneryType); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_UNKNOWN_OBJECT_TYPE); - } - - auto quadrant = _quadrant; - if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_FULL_TILE) || !sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_DIAGONAL)) - { - if (sceneryEntry->HasFlag( - SMALL_SCENERY_FLAG_DIAGONAL | SMALL_SCENERY_FLAG_HALF_SPACE | SMALL_SCENERY_FLAG_THREE_QUARTERS)) + if (_loc.z != 0) { - quadrant = 0; - } - } - - // Check if sub tile height is any different compared to actual surface tile height - auto loc2 = _loc; - if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_FULL_TILE)) - { - loc2 = loc2.ToTileCentre(); - } - else - { - loc2.x += SceneryQuadrantOffsets[quadrant & 3].x; - loc2.y += SceneryQuadrantOffsets[quadrant & 3].y; - } - landHeight = TileElementHeight(loc2); - waterHeight = TileElementWaterHeight(loc2); - - surfaceHeight = landHeight; - // If on water - if (waterHeight > 0) - { - // BaseHeight2 is now the water height - surfaceHeight = waterHeight; - if (_loc.z == 0) - { - isOnWater = true; - } - } - auto targetHeight = _loc.z; - if (_loc.z == 0) - { - targetHeight = surfaceHeight; - } - - auto& gameState = getGameState(); - if (gLegacyScene != LegacyScene::scenarioEditor && !gameState.cheats.sandboxMode - && !MapIsLocationOwned({ _loc.x, _loc.y, targetHeight })) - { - return GameActions::Result(GameActions::Status::NotOwned, STR_CANT_POSITION_THIS_HERE, STR_LAND_NOT_OWNED_BY_PARK); - } - - auto* surfaceElement = MapGetSurfaceElementAt(_loc); - - if (surfaceElement != nullptr && !gameState.cheats.disableClearanceChecks && surfaceElement->GetWaterHeight() > 0) - { - int32_t water_height = surfaceElement->GetWaterHeight() - 1; - if (water_height > targetHeight) - { - return GameActions::Result( - GameActions::Status::Disallowed, STR_CANT_POSITION_THIS_HERE, STR_CANT_BUILD_THIS_UNDERWATER); - } - } - - if (!gameState.cheats.disableClearanceChecks && !(sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_STACKABLE))) - { - if (isOnWater) - { - return GameActions::Result( - GameActions::Status::Disallowed, STR_CANT_POSITION_THIS_HERE, STR_CAN_ONLY_BUILD_THIS_ON_LAND); + surfaceHeight = _loc.z; + res.Position.z = surfaceHeight; } - if (surfaceElement != nullptr && surfaceElement->GetWaterHeight() > 0) + if (!LocationValid(_loc)) { - if (surfaceElement->GetWaterHeight() > targetHeight) + return Result(Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_OFF_EDGE_OF_MAP); + } + + if (!MapCheckCapacityAndReorganise(_loc)) + { + return Result(Status::NoFreeElements, STR_CANT_POSITION_THIS_HERE, STR_TILE_ELEMENT_LIMIT_REACHED); + } + + auto maxSizeMax = GetMapSizeMaxXY(); + if (!_trackDesignDrawingPreview && (_loc.x > maxSizeMax.x || _loc.y > maxSizeMax.y)) + { + return Result(Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_ERR_VALUE_OUT_OF_RANGE); + } + + auto* sceneryEntry = ObjectManager::GetObjectEntry(_sceneryType); + if (sceneryEntry == nullptr) + { + LOG_ERROR("Small scenery object entry not found for sceneryType %u", _sceneryType); + return Result(Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_UNKNOWN_OBJECT_TYPE); + } + + auto quadrant = _quadrant; + if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_FULL_TILE) || !sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_DIAGONAL)) + { + if (sceneryEntry->HasFlag( + SMALL_SCENERY_FLAG_DIAGONAL | SMALL_SCENERY_FLAG_HALF_SPACE | SMALL_SCENERY_FLAG_THREE_QUARTERS)) { - return GameActions::Result( - GameActions::Status::Disallowed, STR_CANT_POSITION_THIS_HERE, STR_CAN_ONLY_BUILD_THIS_ON_LAND); + quadrant = 0; } } - } - if (!gameState.cheats.disableClearanceChecks && (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_REQUIRE_FLAT_SURFACE)) - && !supportsRequired && !isOnWater && surfaceElement != nullptr && (surfaceElement->GetSlope() != kTileSlopeFlat)) - { - return GameActions::Result(GameActions::Status::Disallowed, STR_CANT_POSITION_THIS_HERE, STR_LEVEL_LAND_REQUIRED); - } - - if (!gameState.cheats.disableSupportLimits && !(sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_STACKABLE)) && supportsRequired) - { - if (!isOnWater) + // Check if sub tile height is any different compared to actual surface tile height + auto loc2 = _loc; + if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_FULL_TILE)) { - if (surfaceElement != nullptr) + loc2 = loc2.ToTileCentre(); + } + else + { + loc2.x += SceneryQuadrantOffsets[quadrant & 3].x; + loc2.y += SceneryQuadrantOffsets[quadrant & 3].y; + } + landHeight = TileElementHeight(loc2); + waterHeight = TileElementWaterHeight(loc2); + + surfaceHeight = landHeight; + // If on water + if (waterHeight > 0) + { + // BaseHeight2 is now the water height + surfaceHeight = waterHeight; + if (_loc.z == 0) { - if (surfaceElement->GetWaterHeight() > 0 || (surfaceElement->GetBaseZ()) != targetHeight) + isOnWater = true; + } + } + auto targetHeight = _loc.z; + if (_loc.z == 0) + { + targetHeight = surfaceHeight; + } + + auto& gameState = getGameState(); + if (gLegacyScene != LegacyScene::scenarioEditor && !gameState.cheats.sandboxMode + && !MapIsLocationOwned({ _loc.x, _loc.y, targetHeight })) + { + return Result(Status::NotOwned, STR_CANT_POSITION_THIS_HERE, STR_LAND_NOT_OWNED_BY_PARK); + } + + auto* surfaceElement = MapGetSurfaceElementAt(_loc); + + if (surfaceElement != nullptr && !gameState.cheats.disableClearanceChecks && surfaceElement->GetWaterHeight() > 0) + { + int32_t water_height = surfaceElement->GetWaterHeight() - 1; + if (water_height > targetHeight) + { + return Result(Status::Disallowed, STR_CANT_POSITION_THIS_HERE, STR_CANT_BUILD_THIS_UNDERWATER); + } + } + + if (!gameState.cheats.disableClearanceChecks && !(sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_STACKABLE))) + { + if (isOnWater) + { + return Result(Status::Disallowed, STR_CANT_POSITION_THIS_HERE, STR_CAN_ONLY_BUILD_THIS_ON_LAND); + } + + if (surfaceElement != nullptr && surfaceElement->GetWaterHeight() > 0) + { + if (surfaceElement->GetWaterHeight() > targetHeight) { - return GameActions::Result( - GameActions::Status::Disallowed, STR_CANT_POSITION_THIS_HERE, STR_LEVEL_LAND_REQUIRED); + return Result(Status::Disallowed, STR_CANT_POSITION_THIS_HERE, STR_CAN_ONLY_BUILD_THIS_ON_LAND); + } + } + } + + if (!gameState.cheats.disableClearanceChecks && (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_REQUIRE_FLAT_SURFACE)) + && !supportsRequired && !isOnWater && surfaceElement != nullptr && (surfaceElement->GetSlope() != kTileSlopeFlat)) + { + return Result(Status::Disallowed, STR_CANT_POSITION_THIS_HERE, STR_LEVEL_LAND_REQUIRED); + } + + if (!gameState.cheats.disableSupportLimits && !(sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_STACKABLE)) + && supportsRequired) + { + if (!isOnWater) + { + if (surfaceElement != nullptr) + { + if (surfaceElement->GetWaterHeight() > 0 || (surfaceElement->GetBaseZ()) != targetHeight) + { + return Result(Status::Disallowed, STR_CANT_POSITION_THIS_HERE, STR_LEVEL_LAND_REQUIRED); + } + } + } + else + { + return Result(Status::Disallowed, STR_CANT_POSITION_THIS_HERE, STR_CAN_ONLY_BUILD_THIS_ON_LAND); + } + } + + int32_t zLow = targetHeight; + int32_t zHigh = zLow + ceil2(sceneryEntry->height, kCoordsZStep); + uint8_t collisionQuadrants = 0b1111; + auto quadRotation{ 0 }; + if (!(sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_FULL_TILE))) + { + quadRotation = (quadrant ^ 2); + collisionQuadrants = 0b0001; + } + if (!(sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_HALF_SPACE))) + { + if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_DIAGONAL) && sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_FULL_TILE)) + { + if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_THREE_QUARTERS)) + { + quadRotation = ((quadrant ^ 2) + _loc.direction) & 3; + collisionQuadrants = 0b1011; + } + else + { + quadRotation = (quadrant + _loc.direction) & 1; + collisionQuadrants = 0b1010; } } } else { - return GameActions::Result( - GameActions::Status::Disallowed, STR_CANT_POSITION_THIS_HERE, STR_CAN_ONLY_BUILD_THIS_ON_LAND); + quadRotation = ((quadrant ^ 2) + _loc.direction) & 3; + collisionQuadrants = 0b0011; } - } - - int32_t zLow = targetHeight; - int32_t zHigh = zLow + ceil2(sceneryEntry->height, kCoordsZStep); - uint8_t collisionQuadrants = 0b1111; - auto quadRotation{ 0 }; - if (!(sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_FULL_TILE))) - { - quadRotation = (quadrant ^ 2); - collisionQuadrants = 0b0001; - } - if (!(sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_HALF_SPACE))) - { - if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_DIAGONAL) && sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_FULL_TILE)) + uint8_t supports = 0; + if (!supportsRequired) { - if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_THREE_QUARTERS)) - { - quadRotation = ((quadrant ^ 2) + _loc.direction) & 3; - collisionQuadrants = 0b1011; - } - else - { - quadRotation = (quadrant + _loc.direction) & 1; - collisionQuadrants = 0b1010; - } + supports = 0b1111; } - } - else - { - quadRotation = ((quadrant ^ 2) + _loc.direction) & 3; - collisionQuadrants = 0b0011; - } - uint8_t supports = 0; - if (!supportsRequired) - { - supports = 0b1111; + + QuarterTile quarterTile = QuarterTile{ collisionQuadrants, supports }.Rotate(quadRotation); + const auto isTree = sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_IS_TREE); + auto canBuild = MapCanConstructWithClearAt( + { _loc, zLow, zHigh }, &MapPlaceSceneryClearFunc, quarterTile, GetFlags(), CreateCrossingMode::none, isTree); + if (canBuild.Error != Status::Ok) + { + canBuild.ErrorTitle = STR_CANT_POSITION_THIS_HERE; + return canBuild; + } + + const auto clearanceData = canBuild.GetData(); + const uint8_t groundFlags = clearanceData.GroundFlags & (ELEMENT_IS_ABOVE_GROUND | ELEMENT_IS_UNDERGROUND); + res.SetData(SmallSceneryPlaceActionResult{ groundFlags, 0, 0 }); + + res.Expenditure = ExpenditureType::landscaping; + res.Cost = sceneryEntry->price + canBuild.Cost; + + return res; } - QuarterTile quarterTile = QuarterTile{ collisionQuadrants, supports }.Rotate(quadRotation); - const auto isTree = sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_IS_TREE); - auto canBuild = MapCanConstructWithClearAt( - { _loc, zLow, zHigh }, &MapPlaceSceneryClearFunc, quarterTile, GetFlags(), CreateCrossingMode::none, isTree); - if (canBuild.Error != GameActions::Status::Ok) + Result SmallSceneryPlaceAction::Execute() const { - canBuild.ErrorTitle = STR_CANT_POSITION_THIS_HERE; - return canBuild; - } + bool supportsRequired = false; + if (_loc.z != 0) + { + supportsRequired = true; + } + int32_t landHeight = TileElementHeight(_loc); + int16_t waterHeight = TileElementWaterHeight(_loc); - const auto clearanceData = canBuild.GetData(); - const uint8_t groundFlags = clearanceData.GroundFlags & (ELEMENT_IS_ABOVE_GROUND | ELEMENT_IS_UNDERGROUND); - res.SetData(SmallSceneryPlaceActionResult{ groundFlags, 0, 0 }); - - res.Expenditure = ExpenditureType::landscaping; - res.Cost = sceneryEntry->price + canBuild.Cost; - - return res; -} - -GameActions::Result SmallSceneryPlaceAction::Execute() const -{ - bool supportsRequired = false; - if (_loc.z != 0) - { - supportsRequired = true; - } - int32_t landHeight = TileElementHeight(_loc); - int16_t waterHeight = TileElementWaterHeight(_loc); - - int32_t surfaceHeight = landHeight; - // If on water - if (waterHeight > 0) - { - surfaceHeight = waterHeight; - } - auto res = GameActions::Result(); - auto centre = _loc.ToTileCentre(); - res.Position.x = centre.x; - res.Position.y = centre.y; - res.Position.z = surfaceHeight; - if (_loc.z != 0) - { - surfaceHeight = _loc.z; + int32_t surfaceHeight = landHeight; + // If on water + if (waterHeight > 0) + { + surfaceHeight = waterHeight; + } + auto res = Result(); + auto centre = _loc.ToTileCentre(); + res.Position.x = centre.x; + res.Position.y = centre.y; res.Position.z = surfaceHeight; - } - - auto* sceneryEntry = ObjectManager::GetObjectEntry(_sceneryType); - if (sceneryEntry == nullptr) - { - LOG_ERROR("Small scenery object entry not found for sceneryType %u", _sceneryType); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_UNKNOWN_OBJECT_TYPE); - } - - auto quadrant = _quadrant; - if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_FULL_TILE) || !sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_DIAGONAL)) - { - if (sceneryEntry->HasFlag( - SMALL_SCENERY_FLAG_DIAGONAL | SMALL_SCENERY_FLAG_HALF_SPACE | SMALL_SCENERY_FLAG_THREE_QUARTERS)) + if (_loc.z != 0) { - quadrant = 0; + surfaceHeight = _loc.z; + res.Position.z = surfaceHeight; } - } - // Check if sub tile height is any different compared to actual surface tile height - int32_t x2 = _loc.x; - int32_t y2 = _loc.y; - if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_FULL_TILE)) - { - x2 += 16; - y2 += 16; - } - else - { - x2 += SceneryQuadrantOffsets[quadrant & 3].x; - y2 += SceneryQuadrantOffsets[quadrant & 3].y; - } - landHeight = TileElementHeight({ x2, y2 }); - waterHeight = TileElementWaterHeight({ x2, y2 }); - - surfaceHeight = landHeight; - // If on water - if (waterHeight > 0) - { - // BaseHeight2 is now the water height - surfaceHeight = waterHeight; - } - auto targetHeight = _loc.z; - if (_loc.z == 0) - { - targetHeight = surfaceHeight; - } - - if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST)) - { - FootpathRemoveLitter({ _loc, targetHeight }); - if (!getGameState().cheats.disableClearanceChecks && (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_NO_WALLS))) + auto* sceneryEntry = ObjectManager::GetObjectEntry(_sceneryType); + if (sceneryEntry == nullptr) { - WallRemoveAt({ _loc, targetHeight, targetHeight + sceneryEntry->height }); + LOG_ERROR("Small scenery object entry not found for sceneryType %u", _sceneryType); + return Result(Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_UNKNOWN_OBJECT_TYPE); } - } - int32_t zLow = targetHeight; - int32_t zHigh = zLow + ceil2(sceneryEntry->height, 8); - uint8_t collisionQuadrants = 0b1111; - auto quadRotation{ 0 }; - if (!(sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_FULL_TILE))) - { - quadRotation = (quadrant ^ 2); - collisionQuadrants = 0b0001; - } - if (!(sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_HALF_SPACE))) - { - if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_DIAGONAL) && sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_FULL_TILE)) + auto quadrant = _quadrant; + if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_FULL_TILE) || !sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_DIAGONAL)) { - if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_THREE_QUARTERS)) + if (sceneryEntry->HasFlag( + SMALL_SCENERY_FLAG_DIAGONAL | SMALL_SCENERY_FLAG_HALF_SPACE | SMALL_SCENERY_FLAG_THREE_QUARTERS)) { - quadRotation = ((quadrant ^ 2) + _loc.direction) & 3; - collisionQuadrants = 0b1011; - } - else - { - quadRotation = (quadrant + _loc.direction) & 1; - collisionQuadrants = 0b1010; + quadrant = 0; } } - } - else - { - quadRotation = ((quadrant ^ 2) + _loc.direction) & 3; - collisionQuadrants = 0b0011; - } - uint8_t supports = 0; - if (!supportsRequired) - { - supports = 0b1111; - } - QuarterTile quarterTile = QuarterTile{ collisionQuadrants, supports }.Rotate(quadRotation); - const auto isTree = sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_IS_TREE); - auto canBuild = MapCanConstructWithClearAt( - { _loc, zLow, zHigh }, &MapPlaceSceneryClearFunc, quarterTile, GetFlags() | GAME_COMMAND_FLAG_APPLY, - CreateCrossingMode::none, isTree); - if (canBuild.Error != GameActions::Status::Ok) - { - canBuild.ErrorTitle = STR_CANT_POSITION_THIS_HERE; - return canBuild; + // Check if sub tile height is any different compared to actual surface tile height + int32_t x2 = _loc.x; + int32_t y2 = _loc.y; + if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_FULL_TILE)) + { + x2 += 16; + y2 += 16; + } + else + { + x2 += SceneryQuadrantOffsets[quadrant & 3].x; + y2 += SceneryQuadrantOffsets[quadrant & 3].y; + } + landHeight = TileElementHeight({ x2, y2 }); + waterHeight = TileElementWaterHeight({ x2, y2 }); + + surfaceHeight = landHeight; + // If on water + if (waterHeight > 0) + { + // BaseHeight2 is now the water height + surfaceHeight = waterHeight; + } + auto targetHeight = _loc.z; + if (_loc.z == 0) + { + targetHeight = surfaceHeight; + } + + if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST)) + { + FootpathRemoveLitter({ _loc, targetHeight }); + if (!getGameState().cheats.disableClearanceChecks && (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_NO_WALLS))) + { + WallRemoveAt({ _loc, targetHeight, targetHeight + sceneryEntry->height }); + } + } + + int32_t zLow = targetHeight; + int32_t zHigh = zLow + ceil2(sceneryEntry->height, 8); + uint8_t collisionQuadrants = 0b1111; + auto quadRotation{ 0 }; + if (!(sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_FULL_TILE))) + { + quadRotation = (quadrant ^ 2); + collisionQuadrants = 0b0001; + } + if (!(sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_HALF_SPACE))) + { + if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_DIAGONAL) && sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_FULL_TILE)) + { + if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_THREE_QUARTERS)) + { + quadRotation = ((quadrant ^ 2) + _loc.direction) & 3; + collisionQuadrants = 0b1011; + } + else + { + quadRotation = (quadrant + _loc.direction) & 1; + collisionQuadrants = 0b1010; + } + } + } + else + { + quadRotation = ((quadrant ^ 2) + _loc.direction) & 3; + collisionQuadrants = 0b0011; + } + uint8_t supports = 0; + if (!supportsRequired) + { + supports = 0b1111; + } + + QuarterTile quarterTile = QuarterTile{ collisionQuadrants, supports }.Rotate(quadRotation); + const auto isTree = sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_IS_TREE); + auto canBuild = MapCanConstructWithClearAt( + { _loc, zLow, zHigh }, &MapPlaceSceneryClearFunc, quarterTile, GetFlags() | GAME_COMMAND_FLAG_APPLY, + CreateCrossingMode::none, isTree); + if (canBuild.Error != Status::Ok) + { + canBuild.ErrorTitle = STR_CANT_POSITION_THIS_HERE; + return canBuild; + } + + res.Expenditure = ExpenditureType::landscaping; + res.Cost = sceneryEntry->price + canBuild.Cost; + + auto* sceneryElement = TileElementInsert( + CoordsXYZ{ _loc, zLow }, quarterTile.GetBaseQuarterOccupied()); + if (sceneryElement == nullptr) + { + return Result(Status::NoFreeElements, STR_CANT_POSITION_THIS_HERE, STR_TILE_ELEMENT_LIMIT_REACHED); + } + + sceneryElement->SetDirection(_loc.direction); + sceneryElement->SetSceneryQuadrant(quadrant); + sceneryElement->SetEntryIndex(_sceneryType); + sceneryElement->SetAge(0); + sceneryElement->SetPrimaryColour(_primaryColour); + sceneryElement->SetSecondaryColour(_secondaryColour); + sceneryElement->SetTertiaryColour(_tertiaryColour); + sceneryElement->SetClearanceZ(sceneryElement->GetBaseZ() + sceneryEntry->height + 7); + sceneryElement->SetGhost(GetFlags() & GAME_COMMAND_FLAG_GHOST); + if (supportsRequired) + { + sceneryElement->SetNeedsSupports(); + } + + const auto clearanceData = canBuild.GetData(); + const uint8_t groundFlags = clearanceData.GroundFlags & (ELEMENT_IS_ABOVE_GROUND | ELEMENT_IS_UNDERGROUND); + res.SetData( + SmallSceneryPlaceActionResult{ groundFlags, sceneryElement->GetBaseZ(), sceneryElement->GetSceneryQuadrant() }); + + MapInvalidateTileFull(_loc); + if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_IS_CLOCK)) + { + MapAnimations::MarkTileForUpdate(TileCoordsXY(_loc)); + } + else if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_ANIMATED)) + { + MapAnimations::MarkTileForInvalidation(TileCoordsXY(_loc)); + } + + return res; } - - res.Expenditure = ExpenditureType::landscaping; - res.Cost = sceneryEntry->price + canBuild.Cost; - - auto* sceneryElement = TileElementInsert( - CoordsXYZ{ _loc, zLow }, quarterTile.GetBaseQuarterOccupied()); - if (sceneryElement == nullptr) - { - return GameActions::Result( - GameActions::Status::NoFreeElements, STR_CANT_POSITION_THIS_HERE, STR_TILE_ELEMENT_LIMIT_REACHED); - } - - sceneryElement->SetDirection(_loc.direction); - sceneryElement->SetSceneryQuadrant(quadrant); - sceneryElement->SetEntryIndex(_sceneryType); - sceneryElement->SetAge(0); - sceneryElement->SetPrimaryColour(_primaryColour); - sceneryElement->SetSecondaryColour(_secondaryColour); - sceneryElement->SetTertiaryColour(_tertiaryColour); - sceneryElement->SetClearanceZ(sceneryElement->GetBaseZ() + sceneryEntry->height + 7); - sceneryElement->SetGhost(GetFlags() & GAME_COMMAND_FLAG_GHOST); - if (supportsRequired) - { - sceneryElement->SetNeedsSupports(); - } - - const auto clearanceData = canBuild.GetData(); - const uint8_t groundFlags = clearanceData.GroundFlags & (ELEMENT_IS_ABOVE_GROUND | ELEMENT_IS_UNDERGROUND); - res.SetData(SmallSceneryPlaceActionResult{ groundFlags, sceneryElement->GetBaseZ(), sceneryElement->GetSceneryQuadrant() }); - - MapInvalidateTileFull(_loc); - if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_IS_CLOCK)) - { - MapAnimations::MarkTileForUpdate(TileCoordsXY(_loc)); - } - else if (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_ANIMATED)) - { - MapAnimations::MarkTileForInvalidation(TileCoordsXY(_loc)); - } - - return res; -} +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/SmallSceneryPlaceAction.h b/src/openrct2/actions/SmallSceneryPlaceAction.h index a55cd96830..acb4f7e6e6 100644 --- a/src/openrct2/actions/SmallSceneryPlaceAction.h +++ b/src/openrct2/actions/SmallSceneryPlaceAction.h @@ -11,35 +11,38 @@ #include "GameAction.h" -struct SmallSceneryPlaceActionResult +namespace OpenRCT2::GameActions { - uint8_t GroundFlags{}; - int32_t BaseHeight{}; - uint8_t SceneryQuadrant{}; -}; + struct SmallSceneryPlaceActionResult + { + uint8_t GroundFlags{}; + int32_t BaseHeight{}; + uint8_t SceneryQuadrant{}; + }; -class SmallSceneryPlaceAction final : public GameActionBase -{ -private: - CoordsXYZD _loc; - uint8_t _quadrant{}; - OpenRCT2::ObjectEntryIndex _sceneryType{}; - uint8_t _primaryColour{}; - uint8_t _secondaryColour{}; - uint8_t _tertiaryColour{}; + class SmallSceneryPlaceAction final : public GameActionBase + { + private: + CoordsXYZD _loc; + uint8_t _quadrant{}; + ObjectEntryIndex _sceneryType{}; + uint8_t _primaryColour{}; + uint8_t _secondaryColour{}; + uint8_t _tertiaryColour{}; -public: - SmallSceneryPlaceAction() = default; - SmallSceneryPlaceAction( - const CoordsXYZD& loc, uint8_t quadrant, OpenRCT2::ObjectEntryIndex sceneryType, uint8_t primaryColour, - uint8_t secondaryColour, uint8_t tertiaryColour); + public: + SmallSceneryPlaceAction() = default; + SmallSceneryPlaceAction( + const CoordsXYZD& loc, uint8_t quadrant, ObjectEntryIndex sceneryType, uint8_t primaryColour, + uint8_t secondaryColour, uint8_t tertiaryColour); - void AcceptParameters(GameActionParameterVisitor& visitor) override; + void AcceptParameters(GameActionParameterVisitor& visitor) override; - uint32_t GetCooldownTime() const override; - uint16_t GetActionFlags() const override; + uint32_t GetCooldownTime() 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 diff --git a/src/openrct2/actions/SmallSceneryRemoveAction.cpp b/src/openrct2/actions/SmallSceneryRemoveAction.cpp index b241f99610..b425bcbb6c 100644 --- a/src/openrct2/actions/SmallSceneryRemoveAction.cpp +++ b/src/openrct2/actions/SmallSceneryRemoveAction.cpp @@ -25,139 +25,137 @@ #include "GameAction.h" #include "SmallSceneryPlaceAction.h" -using namespace OpenRCT2; - -SmallSceneryRemoveAction::SmallSceneryRemoveAction(const CoordsXYZ& location, uint8_t quadrant, ObjectEntryIndex sceneryType) - : _loc(location) - , _quadrant(quadrant) - , _sceneryType(sceneryType) +namespace OpenRCT2::GameActions { -} - -void SmallSceneryRemoveAction::AcceptParameters(GameActionParameterVisitor& visitor) -{ - visitor.Visit(_loc); - visitor.Visit("object", _sceneryType); - visitor.Visit("quadrant", _quadrant); -} - -uint16_t SmallSceneryRemoveAction::GetActionFlags() const -{ - return GameAction::GetActionFlags(); -} - -void SmallSceneryRemoveAction::Serialise(DataSerialiser& stream) -{ - GameAction::Serialise(stream); - - stream << DS_TAG(_loc) << DS_TAG(_quadrant) << DS_TAG(_sceneryType); -} - -GameActions::Result SmallSceneryRemoveAction::Query() const -{ - GameActions::Result res = GameActions::Result(); - - if (!LocationValid(_loc)) + SmallSceneryRemoveAction::SmallSceneryRemoveAction( + const CoordsXYZ& location, uint8_t quadrant, ObjectEntryIndex sceneryType) + : _loc(location) + , _quadrant(quadrant) + , _sceneryType(sceneryType) { - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_OFF_EDGE_OF_MAP); } - auto* entry = OpenRCT2::ObjectManager::GetObjectEntry(_sceneryType); - if (entry == nullptr) + void SmallSceneryRemoveAction::AcceptParameters(GameActionParameterVisitor& visitor) { - LOG_ERROR("Invalid small scenery type %u", _sceneryType); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_INVALID_SELECTION_OF_OBJECTS); + visitor.Visit(_loc); + visitor.Visit("object", _sceneryType); + visitor.Visit("quadrant", _quadrant); } - res.Cost = entry->removal_price; - res.Expenditure = ExpenditureType::landscaping; - res.Position = _loc; - - if (gLegacyScene != LegacyScene::scenarioEditor && !(GetFlags() & GAME_COMMAND_FLAG_GHOST) - && !getGameState().cheats.sandboxMode) + uint16_t SmallSceneryRemoveAction::GetActionFlags() const { - // Check if allowed to remove item - if (getGameState().park.flags & PARK_FLAGS_FORBID_TREE_REMOVAL) + return GameAction::GetActionFlags(); + } + + void SmallSceneryRemoveAction::Serialise(DataSerialiser& stream) + { + GameAction::Serialise(stream); + + stream << DS_TAG(_loc) << DS_TAG(_quadrant) << DS_TAG(_sceneryType); + } + + Result SmallSceneryRemoveAction::Query() const + { + Result res = Result(); + + if (!LocationValid(_loc)) { - if (entry->HasFlag(SMALL_SCENERY_FLAG_IS_TREE)) + return Result(Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_OFF_EDGE_OF_MAP); + } + + auto* entry = OpenRCT2::ObjectManager::GetObjectEntry(_sceneryType); + if (entry == nullptr) + { + LOG_ERROR("Invalid small scenery type %u", _sceneryType); + return Result(Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_INVALID_SELECTION_OF_OBJECTS); + } + + res.Cost = entry->removal_price; + res.Expenditure = ExpenditureType::landscaping; + res.Position = _loc; + + if (gLegacyScene != LegacyScene::scenarioEditor && !(GetFlags() & GAME_COMMAND_FLAG_GHOST) + && !getGameState().cheats.sandboxMode) + { + // Check if allowed to remove item + if (getGameState().park.flags & PARK_FLAGS_FORBID_TREE_REMOVAL) { - res.Error = GameActions::Status::NoClearance; + if (entry->HasFlag(SMALL_SCENERY_FLAG_IS_TREE)) + { + res.Error = Status::NoClearance; + res.ErrorTitle = STR_CANT_REMOVE_THIS; + res.ErrorMessage = STR_FORBIDDEN_BY_THE_LOCAL_AUTHORITY; + return res; + } + } + + // Check if the land is owned + if (!MapIsLocationOwned(_loc)) + { + res.Error = Status::NoClearance; res.ErrorTitle = STR_CANT_REMOVE_THIS; - res.ErrorMessage = STR_FORBIDDEN_BY_THE_LOCAL_AUTHORITY; + res.ErrorMessage = STR_LAND_NOT_OWNED_BY_PARK; return res; } } - // Check if the land is owned - if (!MapIsLocationOwned(_loc)) + TileElement* tileElement = FindSceneryElement(); + if (tileElement == nullptr) { - res.Error = GameActions::Status::NoClearance; - res.ErrorTitle = STR_CANT_REMOVE_THIS; - res.ErrorMessage = STR_LAND_NOT_OWNED_BY_PARK; - return res; + LOG_ERROR("Small scenery of type %u not found at x = %d, y = %d, z = &d", _sceneryType, _loc.x, _loc.y, _loc.z); + return Result(Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_INVALID_SELECTION_OF_OBJECTS); } + + return res; } - TileElement* tileElement = FindSceneryElement(); - if (tileElement == nullptr) + Result SmallSceneryRemoveAction::Execute() const { - LOG_ERROR("Small scenery of type %u not found at x = %d, y = %d, z = &d", _sceneryType, _loc.x, _loc.y, _loc.z); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_INVALID_SELECTION_OF_OBJECTS); + Result res = Result(); + + auto* entry = OpenRCT2::ObjectManager::GetObjectEntry(_sceneryType); + if (entry == nullptr) + { + LOG_ERROR("Invalid small scenery type %u", _sceneryType); + return Result(Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_INVALID_SELECTION_OF_OBJECTS); + } + + res.Cost = entry->removal_price; + res.Expenditure = ExpenditureType::landscaping; + res.Position = _loc; + + TileElement* tileElement = FindSceneryElement(); + if (tileElement == nullptr) + { + return Result(Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_INVALID_SELECTION_OF_OBJECTS); + } + + MapInvalidateTileFull(_loc); + TileElementRemove(tileElement); + + return res; } - return res; -} - -GameActions::Result SmallSceneryRemoveAction::Execute() const -{ - GameActions::Result res = GameActions::Result(); - - auto* entry = OpenRCT2::ObjectManager::GetObjectEntry(_sceneryType); - if (entry == nullptr) + TileElement* SmallSceneryRemoveAction::FindSceneryElement() const { - LOG_ERROR("Invalid small scenery type %u", _sceneryType); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_INVALID_SELECTION_OF_OBJECTS); + const bool isGhost = GetFlags() & GAME_COMMAND_FLAG_GHOST; + for (auto* sceneryElement : TileElementsView(_loc)) + { + // If we are removing ghost elements + if (isGhost && sceneryElement->IsGhost() == false) + continue; + + if (sceneryElement->GetSceneryQuadrant() != _quadrant) + continue; + + if (sceneryElement->GetBaseZ() != _loc.z) + continue; + + if (sceneryElement->GetEntryIndex() != _sceneryType) + continue; + + return sceneryElement->as(); + } + return nullptr; } - - res.Cost = entry->removal_price; - res.Expenditure = ExpenditureType::landscaping; - res.Position = _loc; - - TileElement* tileElement = FindSceneryElement(); - if (tileElement == nullptr) - { - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_INVALID_SELECTION_OF_OBJECTS); - } - - MapInvalidateTileFull(_loc); - TileElementRemove(tileElement); - - return res; -} - -TileElement* SmallSceneryRemoveAction::FindSceneryElement() const -{ - const bool isGhost = GetFlags() & GAME_COMMAND_FLAG_GHOST; - for (auto* sceneryElement : TileElementsView(_loc)) - { - // If we are removing ghost elements - if (isGhost && sceneryElement->IsGhost() == false) - continue; - - if (sceneryElement->GetSceneryQuadrant() != _quadrant) - continue; - - if (sceneryElement->GetBaseZ() != _loc.z) - continue; - - if (sceneryElement->GetEntryIndex() != _sceneryType) - continue; - - return sceneryElement->as(); - } - return nullptr; -} +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/SmallSceneryRemoveAction.h b/src/openrct2/actions/SmallSceneryRemoveAction.h index 4dc377cde0..3636599d1e 100644 --- a/src/openrct2/actions/SmallSceneryRemoveAction.h +++ b/src/openrct2/actions/SmallSceneryRemoveAction.h @@ -11,25 +11,28 @@ #include "GameAction.h" -class SmallSceneryRemoveAction final : public GameActionBase +namespace OpenRCT2::GameActions { -private: - CoordsXYZ _loc; - uint8_t _quadrant{}; - OpenRCT2::ObjectEntryIndex _sceneryType{}; + class SmallSceneryRemoveAction final : public GameActionBase + { + private: + CoordsXYZ _loc; + uint8_t _quadrant{}; + ObjectEntryIndex _sceneryType{}; -public: - SmallSceneryRemoveAction() = default; - SmallSceneryRemoveAction(const CoordsXYZ& location, uint8_t quadrant, OpenRCT2::ObjectEntryIndex sceneryType); + public: + SmallSceneryRemoveAction() = default; + SmallSceneryRemoveAction(const CoordsXYZ& location, uint8_t quadrant, ObjectEntryIndex sceneryType); - 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* FindSceneryElement() const; -}; + private: + TileElement* FindSceneryElement() const; + }; +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/SmallScenerySetColourAction.cpp b/src/openrct2/actions/SmallScenerySetColourAction.cpp index 40ac2a47e3..2b35c05754 100644 --- a/src/openrct2/actions/SmallScenerySetColourAction.cpp +++ b/src/openrct2/actions/SmallScenerySetColourAction.cpp @@ -21,96 +21,97 @@ #include "../world/Park.h" #include "../world/tile_element/SmallSceneryElement.h" -using namespace OpenRCT2; - -SmallScenerySetColourAction::SmallScenerySetColourAction( - const CoordsXYZ& loc, uint8_t quadrant, ObjectEntryIndex sceneryType, uint8_t primaryColour, uint8_t secondaryColour, - uint8_t tertiaryColour) - : _loc(loc) - , _quadrant(quadrant) - , _sceneryType(sceneryType) - , _primaryColour(primaryColour) - , _secondaryColour(secondaryColour) - , _tertiaryColour(tertiaryColour) +namespace OpenRCT2::GameActions { -} - -void SmallScenerySetColourAction::AcceptParameters(GameActionParameterVisitor& visitor) -{ - visitor.Visit(_loc); - visitor.Visit("quadrant", _quadrant); - visitor.Visit("sceneryType", _sceneryType); - visitor.Visit("primaryColour", _primaryColour); - visitor.Visit("secondaryColour", _secondaryColour); - visitor.Visit("tertiaryColour", _tertiaryColour); -} - -uint16_t SmallScenerySetColourAction::GetActionFlags() const -{ - return GameAction::GetActionFlags() | GameActions::Flags::AllowWhilePaused; -} - -void SmallScenerySetColourAction::Serialise(DataSerialiser& stream) -{ - GameAction::Serialise(stream); - - stream << DS_TAG(_loc) << DS_TAG(_quadrant) << DS_TAG(_sceneryType) << DS_TAG(_primaryColour) << DS_TAG(_secondaryColour) - << DS_TAG(_tertiaryColour); -} - -GameActions::Result SmallScenerySetColourAction::Query() const -{ - return QueryExecute(false); -} - -GameActions::Result SmallScenerySetColourAction::Execute() const -{ - return QueryExecute(true); -} - -GameActions::Result SmallScenerySetColourAction::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)) + SmallScenerySetColourAction::SmallScenerySetColourAction( + const CoordsXYZ& loc, uint8_t quadrant, ObjectEntryIndex sceneryType, uint8_t primaryColour, uint8_t secondaryColour, + uint8_t tertiaryColour) + : _loc(loc) + , _quadrant(quadrant) + , _sceneryType(sceneryType) + , _primaryColour(primaryColour) + , _secondaryColour(secondaryColour) + , _tertiaryColour(tertiaryColour) { - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_OFF_EDGE_OF_MAP); } - if (gLegacyScene != LegacyScene::scenarioEditor && !getGameState().cheats.sandboxMode) + void SmallScenerySetColourAction::AcceptParameters(GameActionParameterVisitor& visitor) { - if (!MapIsLocationOwned(_loc)) + visitor.Visit(_loc); + visitor.Visit("quadrant", _quadrant); + visitor.Visit("sceneryType", _sceneryType); + visitor.Visit("primaryColour", _primaryColour); + visitor.Visit("secondaryColour", _secondaryColour); + visitor.Visit("tertiaryColour", _tertiaryColour); + } + + uint16_t SmallScenerySetColourAction::GetActionFlags() const + { + return GameAction::GetActionFlags() | Flags::AllowWhilePaused; + } + + void SmallScenerySetColourAction::Serialise(DataSerialiser& stream) + { + GameAction::Serialise(stream); + + stream << DS_TAG(_loc) << DS_TAG(_quadrant) << DS_TAG(_sceneryType) << DS_TAG(_primaryColour) + << DS_TAG(_secondaryColour) << DS_TAG(_tertiaryColour); + } + + Result SmallScenerySetColourAction::Query() const + { + return QueryExecute(false); + } + + Result SmallScenerySetColourAction::Execute() const + { + return QueryExecute(true); + } + + Result SmallScenerySetColourAction::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)) { - return GameActions::Result(GameActions::Status::NotOwned, STR_CANT_REPAINT_THIS, STR_LAND_NOT_OWNED_BY_PARK); + return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_OFF_EDGE_OF_MAP); } - } - auto sceneryElement = MapGetSmallSceneryElementAt(_loc, _sceneryType, _quadrant); + if (gLegacyScene != LegacyScene::scenarioEditor && !getGameState().cheats.sandboxMode) + { + if (!MapIsLocationOwned(_loc)) + { + return Result(Status::NotOwned, STR_CANT_REPAINT_THIS, STR_LAND_NOT_OWNED_BY_PARK); + } + } - if (sceneryElement == nullptr) - { - LOG_ERROR("Small scenery not found at: x = %d, y = %d, z = %d", _loc.x, _loc.y, _loc.z); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, kStringIdNone); - } + auto sceneryElement = MapGetSmallSceneryElementAt(_loc, _sceneryType, _quadrant); + + if (sceneryElement == nullptr) + { + LOG_ERROR("Small scenery not found at: x = %d, y = %d, z = %d", _loc.x, _loc.y, _loc.z); + return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, kStringIdNone); + } + + if ((GetFlags() & GAME_COMMAND_FLAG_GHOST) && !(sceneryElement->IsGhost())) + { + return res; + } + + if (isExecuting) + { + sceneryElement->SetPrimaryColour(_primaryColour); + sceneryElement->SetSecondaryColour(_secondaryColour); + sceneryElement->SetTertiaryColour(_tertiaryColour); + + MapInvalidateTileFull(_loc); + } - if ((GetFlags() & GAME_COMMAND_FLAG_GHOST) && !(sceneryElement->IsGhost())) - { return res; } - - if (isExecuting) - { - sceneryElement->SetPrimaryColour(_primaryColour); - sceneryElement->SetSecondaryColour(_secondaryColour); - sceneryElement->SetTertiaryColour(_tertiaryColour); - - MapInvalidateTileFull(_loc); - } - - return res; -} +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/SmallScenerySetColourAction.h b/src/openrct2/actions/SmallScenerySetColourAction.h index fc7249fa93..292e641eab 100644 --- a/src/openrct2/actions/SmallScenerySetColourAction.h +++ b/src/openrct2/actions/SmallScenerySetColourAction.h @@ -11,30 +11,33 @@ #include "GameAction.h" -class SmallScenerySetColourAction final : public GameActionBase +namespace OpenRCT2::GameActions { -private: - CoordsXYZ _loc; - uint8_t _quadrant{}; - OpenRCT2::ObjectEntryIndex _sceneryType{}; - uint8_t _primaryColour{}; - uint8_t _secondaryColour{}; - uint8_t _tertiaryColour{}; + class SmallScenerySetColourAction final : public GameActionBase + { + private: + CoordsXYZ _loc; + uint8_t _quadrant{}; + ObjectEntryIndex _sceneryType{}; + uint8_t _primaryColour{}; + uint8_t _secondaryColour{}; + uint8_t _tertiaryColour{}; -public: - SmallScenerySetColourAction() = default; - SmallScenerySetColourAction( - const CoordsXYZ& loc, uint8_t quadrant, OpenRCT2::ObjectEntryIndex sceneryType, uint8_t primaryColour, - uint8_t secondaryColour, uint8_t tertiaryColour); + public: + SmallScenerySetColourAction() = default; + SmallScenerySetColourAction( + const CoordsXYZ& loc, uint8_t quadrant, ObjectEntryIndex sceneryType, uint8_t primaryColour, + uint8_t secondaryColour, uint8_t tertiaryColour); - 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 diff --git a/src/openrct2/actions/WallPlaceAction.cpp b/src/openrct2/actions/WallPlaceAction.cpp index a59eac5376..295abf18d8 100644 --- a/src/openrct2/actions/WallPlaceAction.cpp +++ b/src/openrct2/actions/WallPlaceAction.cpp @@ -31,587 +31,575 @@ #include "../world/tile_element/TrackElement.h" #include "../world/tile_element/WallElement.h" -using namespace OpenRCT2; -using namespace OpenRCT2::TrackMetaData; - -WallPlaceAction::WallPlaceAction( - ObjectEntryIndex wallType, const CoordsXYZ& loc, uint8_t edge, int32_t primaryColour, int32_t secondaryColour, - int32_t tertiaryColour) - : _wallType(wallType) - , _loc(loc) - , _edge(edge) - , _primaryColour(primaryColour) - , _secondaryColour(secondaryColour) - , _tertiaryColour(tertiaryColour) +namespace OpenRCT2::GameActions { -} + using namespace OpenRCT2::TrackMetaData; -void WallPlaceAction::AcceptParameters(GameActionParameterVisitor& visitor) -{ - visitor.Visit(_loc); - visitor.Visit("object", _wallType); - visitor.Visit("edge", _edge); - visitor.Visit("primaryColour", _primaryColour); - visitor.Visit("secondaryColour", _secondaryColour); - visitor.Visit("tertiaryColour", _tertiaryColour); -} - -uint16_t WallPlaceAction::GetActionFlags() const -{ - return GameAction::GetActionFlags(); -} - -void WallPlaceAction::Serialise(DataSerialiser& stream) -{ - GameAction::Serialise(stream); - - stream << DS_TAG(_wallType) << DS_TAG(_loc) << DS_TAG(_edge) << DS_TAG(_primaryColour) << DS_TAG(_secondaryColour) - << DS_TAG(_tertiaryColour); -} - -GameActions::Result WallPlaceAction::Query() const -{ - auto res = GameActions::Result(); - res.ErrorTitle = STR_CANT_BUILD_THIS_HERE; - res.Position = _loc; - - res.Expenditure = ExpenditureType::landscaping; - res.Position.x += 16; - res.Position.y += 16; - - if (_loc.z == 0) + WallPlaceAction::WallPlaceAction( + ObjectEntryIndex wallType, const CoordsXYZ& loc, uint8_t edge, int32_t primaryColour, int32_t secondaryColour, + int32_t tertiaryColour) + : _wallType(wallType) + , _loc(loc) + , _edge(edge) + , _primaryColour(primaryColour) + , _secondaryColour(secondaryColour) + , _tertiaryColour(tertiaryColour) { - res.Position.z = TileElementHeight(res.Position); } - if (!LocationValid(_loc)) + void WallPlaceAction::AcceptParameters(GameActionParameterVisitor& visitor) { - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_BUILD_THIS_HERE, STR_OFF_EDGE_OF_MAP); + visitor.Visit(_loc); + visitor.Visit("object", _wallType); + visitor.Visit("edge", _edge); + visitor.Visit("primaryColour", _primaryColour); + visitor.Visit("secondaryColour", _secondaryColour); + visitor.Visit("tertiaryColour", _tertiaryColour); } - auto& gameState = getGameState(); - auto mapSizeMax = GetMapSizeMaxXY(); - if (gLegacyScene != LegacyScene::scenarioEditor && !(GetFlags() & GAME_COMMAND_FLAG_TRACK_DESIGN) - && !gameState.cheats.sandboxMode) + uint16_t WallPlaceAction::GetActionFlags() const { + return GameAction::GetActionFlags(); + } + + void WallPlaceAction::Serialise(DataSerialiser& stream) + { + GameAction::Serialise(stream); + + stream << DS_TAG(_wallType) << DS_TAG(_loc) << DS_TAG(_edge) << DS_TAG(_primaryColour) << DS_TAG(_secondaryColour) + << DS_TAG(_tertiaryColour); + } + + Result WallPlaceAction::Query() const + { + auto res = Result(); + res.ErrorTitle = STR_CANT_BUILD_THIS_HERE; + res.Position = _loc; + + res.Expenditure = ExpenditureType::landscaping; + res.Position.x += 16; + res.Position.y += 16; + if (_loc.z == 0) { - if (!MapIsLocationInPark(_loc)) + res.Position.z = TileElementHeight(res.Position); + } + + if (!LocationValid(_loc)) + { + return Result(Status::InvalidParameters, STR_CANT_BUILD_THIS_HERE, STR_OFF_EDGE_OF_MAP); + } + + auto& gameState = getGameState(); + auto mapSizeMax = GetMapSizeMaxXY(); + if (gLegacyScene != LegacyScene::scenarioEditor && !(GetFlags() & GAME_COMMAND_FLAG_TRACK_DESIGN) + && !gameState.cheats.sandboxMode) + { + if (_loc.z == 0) { - return GameActions::Result(GameActions::Status::NotOwned, STR_CANT_BUILD_THIS_HERE, STR_LAND_NOT_OWNED_BY_PARK); + if (!MapIsLocationInPark(_loc)) + { + return Result(Status::NotOwned, STR_CANT_BUILD_THIS_HERE, STR_LAND_NOT_OWNED_BY_PARK); + } + } + else if (!MapIsLocationOwned(_loc)) + { + return Result(Status::NotOwned, STR_CANT_BUILD_THIS_HERE, STR_LAND_NOT_OWNED_BY_PARK); } } - else if (!MapIsLocationOwned(_loc)) + else if (!_trackDesignDrawingPreview && (_loc.x > mapSizeMax.x || _loc.y > mapSizeMax.y)) { - return GameActions::Result(GameActions::Status::NotOwned, STR_CANT_BUILD_THIS_HERE, STR_LAND_NOT_OWNED_BY_PARK); + LOG_ERROR("Invalid x/y coordinates. x = %d y = %d", _loc.x, _loc.y); + return Result(Status::InvalidParameters, STR_CANT_BUILD_THIS_HERE, STR_OFF_EDGE_OF_MAP); } - } - else if (!_trackDesignDrawingPreview && (_loc.x > mapSizeMax.x || _loc.y > mapSizeMax.y)) - { - LOG_ERROR("Invalid x/y coordinates. x = %d y = %d", _loc.x, _loc.y); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_BUILD_THIS_HERE, STR_OFF_EDGE_OF_MAP); - } - if (_edge > 3) - { - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_BUILD_THIS_HERE, kStringIdNone); - } + if (_edge > 3) + { + return Result(Status::InvalidParameters, STR_CANT_BUILD_THIS_HERE, kStringIdNone); + } + + uint8_t edgeSlope = 0; + auto targetHeight = _loc.z; + if (targetHeight == 0) + { + auto* surfaceElement = MapGetSurfaceElementAt(_loc); + if (surfaceElement == nullptr) + { + LOG_ERROR("Surface element not found at %d, %d.", _loc.x, _loc.y); + return Result(Status::InvalidParameters, STR_CANT_BUILD_THIS_HERE, STR_ERR_SURFACE_ELEMENT_NOT_FOUND); + } + targetHeight = surfaceElement->GetBaseZ(); + + uint8_t slope = surfaceElement->GetSlope(); + edgeSlope = GetWallSlopeFromEdgeSlope(slope, _edge & 3); + if (edgeSlope & EDGE_SLOPE_ELEVATED) + { + targetHeight += 16; + edgeSlope &= ~EDGE_SLOPE_ELEVATED; + } + } - uint8_t edgeSlope = 0; - auto targetHeight = _loc.z; - if (targetHeight == 0) - { auto* surfaceElement = MapGetSurfaceElementAt(_loc); if (surfaceElement == nullptr) { LOG_ERROR("Surface element not found at %d, %d.", _loc.x, _loc.y); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_BUILD_THIS_HERE, STR_ERR_SURFACE_ELEMENT_NOT_FOUND); + return Result(Status::InvalidParameters, STR_CANT_BUILD_THIS_HERE, STR_ERR_SURFACE_ELEMENT_NOT_FOUND); } - targetHeight = surfaceElement->GetBaseZ(); - uint8_t slope = surfaceElement->GetSlope(); - edgeSlope = GetWallSlopeFromEdgeSlope(slope, _edge & 3); - if (edgeSlope & EDGE_SLOPE_ELEVATED) + if (surfaceElement->GetWaterHeight() > 0) { - targetHeight += 16; - edgeSlope &= ~EDGE_SLOPE_ELEVATED; - } - } + uint16_t waterHeight = surfaceElement->GetWaterHeight(); - auto* surfaceElement = MapGetSurfaceElementAt(_loc); - if (surfaceElement == nullptr) - { - LOG_ERROR("Surface element not found at %d, %d.", _loc.x, _loc.y); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_BUILD_THIS_HERE, STR_ERR_SURFACE_ELEMENT_NOT_FOUND); - } - - if (surfaceElement->GetWaterHeight() > 0) - { - uint16_t waterHeight = surfaceElement->GetWaterHeight(); - - if (targetHeight < waterHeight && !gameState.cheats.disableClearanceChecks) - { - return GameActions::Result( - GameActions::Status::Disallowed, STR_CANT_BUILD_THIS_HERE, STR_CANT_BUILD_THIS_UNDERWATER); - } - } - - if (targetHeight < surfaceElement->GetBaseZ() && !gameState.cheats.disableClearanceChecks) - { - return GameActions::Result( - GameActions::Status::Disallowed, STR_CANT_BUILD_THIS_HERE, STR_CAN_ONLY_BUILD_THIS_ABOVE_GROUND); - } - - if (!(edgeSlope & (EDGE_SLOPE_UPWARDS | EDGE_SLOPE_DOWNWARDS))) - { - uint8_t newEdge = (_edge + 2) & 3; - uint8_t newBaseHeight = surfaceElement->BaseHeight; - newBaseHeight += 2; - if (surfaceElement->GetSlope() & (1 << newEdge)) - { - if (targetHeight / 8 < newBaseHeight && !gameState.cheats.disableClearanceChecks) + if (targetHeight < waterHeight && !gameState.cheats.disableClearanceChecks) { - return GameActions::Result( - GameActions::Status::Disallowed, STR_CANT_BUILD_THIS_HERE, STR_CAN_ONLY_BUILD_THIS_ABOVE_GROUND); + return Result(Status::Disallowed, STR_CANT_BUILD_THIS_HERE, STR_CANT_BUILD_THIS_UNDERWATER); } + } - if (surfaceElement->GetSlope() & kTileSlopeDiagonalFlag) + if (targetHeight < surfaceElement->GetBaseZ() && !gameState.cheats.disableClearanceChecks) + { + return Result(Status::Disallowed, STR_CANT_BUILD_THIS_HERE, STR_CAN_ONLY_BUILD_THIS_ABOVE_GROUND); + } + + if (!(edgeSlope & (EDGE_SLOPE_UPWARDS | EDGE_SLOPE_DOWNWARDS))) + { + uint8_t newEdge = (_edge + 2) & 3; + uint8_t newBaseHeight = surfaceElement->BaseHeight; + newBaseHeight += 2; + if (surfaceElement->GetSlope() & (1 << newEdge)) { - newEdge = (newEdge - 1) & 3; - - if (surfaceElement->GetSlope() & (1 << newEdge)) + if (targetHeight / 8 < newBaseHeight && !gameState.cheats.disableClearanceChecks) { - newEdge = (newEdge + 2) & 3; + return Result(Status::Disallowed, STR_CANT_BUILD_THIS_HERE, STR_CAN_ONLY_BUILD_THIS_ABOVE_GROUND); + } + + if (surfaceElement->GetSlope() & kTileSlopeDiagonalFlag) + { + newEdge = (newEdge - 1) & 3; + if (surfaceElement->GetSlope() & (1 << newEdge)) { - newBaseHeight += 2; - if (targetHeight / 8 < newBaseHeight && !gameState.cheats.disableClearanceChecks) + newEdge = (newEdge + 2) & 3; + if (surfaceElement->GetSlope() & (1 << newEdge)) { - return GameActions::Result( - GameActions::Status::Disallowed, STR_CANT_BUILD_THIS_HERE, - STR_CAN_ONLY_BUILD_THIS_ABOVE_GROUND); + newBaseHeight += 2; + if (targetHeight / 8 < newBaseHeight && !gameState.cheats.disableClearanceChecks) + { + return Result( + Status::Disallowed, STR_CANT_BUILD_THIS_HERE, STR_CAN_ONLY_BUILD_THIS_ABOVE_GROUND); + } + newBaseHeight -= 2; } - newBaseHeight -= 2; } } } - } - newEdge = (_edge + 3) & 3; - if (surfaceElement->GetSlope() & (1 << newEdge)) - { - if (targetHeight / 8 < newBaseHeight && !gameState.cheats.disableClearanceChecks) + newEdge = (_edge + 3) & 3; + if (surfaceElement->GetSlope() & (1 << newEdge)) { - return GameActions::Result( - GameActions::Status::Disallowed, STR_CANT_BUILD_THIS_HERE, STR_CAN_ONLY_BUILD_THIS_ABOVE_GROUND); - } - - if (surfaceElement->GetSlope() & kTileSlopeDiagonalFlag) - { - newEdge = (newEdge - 1) & 3; - - if (surfaceElement->GetSlope() & (1 << newEdge)) + if (targetHeight / 8 < newBaseHeight && !gameState.cheats.disableClearanceChecks) { - newEdge = (newEdge + 2) & 3; + return Result(Status::Disallowed, STR_CANT_BUILD_THIS_HERE, STR_CAN_ONLY_BUILD_THIS_ABOVE_GROUND); + } + + if (surfaceElement->GetSlope() & kTileSlopeDiagonalFlag) + { + newEdge = (newEdge - 1) & 3; + if (surfaceElement->GetSlope() & (1 << newEdge)) { - newBaseHeight += 2; - if (targetHeight / 8 < newBaseHeight && !gameState.cheats.disableClearanceChecks) + newEdge = (newEdge + 2) & 3; + if (surfaceElement->GetSlope() & (1 << newEdge)) { - return GameActions::Result( - GameActions::Status::Disallowed, STR_CANT_BUILD_THIS_HERE, - STR_CAN_ONLY_BUILD_THIS_ABOVE_GROUND); + newBaseHeight += 2; + if (targetHeight / 8 < newBaseHeight && !gameState.cheats.disableClearanceChecks) + { + return Result( + Status::Disallowed, STR_CANT_BUILD_THIS_HERE, STR_CAN_ONLY_BUILD_THIS_ABOVE_GROUND); + } } } } } } - } - auto* wallEntry = ObjectManager::GetObjectEntry(_wallType); + auto* wallEntry = ObjectManager::GetObjectEntry(_wallType); - if (wallEntry == nullptr) - { - LOG_ERROR("Wall Type not found %d", _wallType); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_BUILD_THIS_HERE, STR_UNKNOWN_OBJECT_TYPE); - } - - if (wallEntry->scrolling_mode != kScrollingModeNone) - { - if (HasReachedBannerLimit()) + if (wallEntry == nullptr) { - LOG_ERROR("No free banners available"); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_BUILD_THIS_HERE, STR_TOO_MANY_BANNERS_IN_GAME); - } - } - - uint8_t clearanceHeight = targetHeight / 8; - if (edgeSlope & (EDGE_SLOPE_UPWARDS | EDGE_SLOPE_DOWNWARDS)) - { - if (wallEntry->flags & WALL_SCENERY_CANT_BUILD_ON_SLOPE) - { - return GameActions::Result( - GameActions::Status::Disallowed, STR_CANT_BUILD_THIS_HERE, STR_ERR_UNABLE_TO_BUILD_THIS_ON_SLOPE); - } - clearanceHeight += 2; - } - clearanceHeight += wallEntry->height; - - bool wallAcrossTrack = false; - if (!(GetFlags() & GAME_COMMAND_FLAG_TRACK_DESIGN) && !gameState.cheats.disableClearanceChecks) - { - auto result = WallCheckObstruction(wallEntry, targetHeight / 8, clearanceHeight, &wallAcrossTrack); - if (result.Error != GameActions::Status::Ok) - { - return result; - } - } - - if (!MapCheckCapacityAndReorganise(_loc)) - { - return GameActions::Result( - GameActions::Status::NoFreeElements, STR_CANT_BUILD_THIS_HERE, STR_TILE_ELEMENT_LIMIT_REACHED); - } - - res.Cost = wallEntry->price; - - res.SetData(WallPlaceActionResult{}); - - return res; -} - -GameActions::Result WallPlaceAction::Execute() const -{ - auto res = GameActions::Result(); - auto& gameState = getGameState(); - - res.ErrorTitle = STR_CANT_BUILD_THIS_HERE; - res.Position = _loc; - - res.Expenditure = ExpenditureType::landscaping; - res.Position.x += 16; - res.Position.y += 16; - - if (res.Position.z == 0) - { - res.Position.z = TileElementHeight(res.Position); - } - - uint8_t edgeSlope = 0; - auto targetHeight = _loc.z; - if (targetHeight == 0) - { - auto* surfaceElement = MapGetSurfaceElementAt(_loc); - if (surfaceElement == nullptr) - { - LOG_ERROR("Surface element not found at %d, %d.", _loc.x, _loc.y); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_BUILD_THIS_HERE, STR_ERR_SURFACE_ELEMENT_NOT_FOUND); - } - targetHeight = surfaceElement->GetBaseZ(); - - uint8_t slope = surfaceElement->GetSlope(); - edgeSlope = GetWallSlopeFromEdgeSlope(slope, _edge & 3); - if (edgeSlope & EDGE_SLOPE_ELEVATED) - { - targetHeight += 16; - edgeSlope &= ~EDGE_SLOPE_ELEVATED; - } - } - auto targetLoc = CoordsXYZ(_loc, targetHeight); - - auto* wallEntry = ObjectManager::GetObjectEntry(_wallType); - - if (wallEntry == nullptr) - { - LOG_ERROR("Wall Type not found %d", _wallType); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_BUILD_THIS_HERE, STR_UNKNOWN_OBJECT_TYPE); - } - - uint8_t clearanceHeight = targetHeight / kCoordsZStep; - if (edgeSlope & (EDGE_SLOPE_UPWARDS | EDGE_SLOPE_DOWNWARDS)) - { - clearanceHeight += 2; - } - clearanceHeight += wallEntry->height; - - bool wallAcrossTrack = false; - if (!(GetFlags() & GAME_COMMAND_FLAG_TRACK_DESIGN) && !gameState.cheats.disableClearanceChecks) - { - auto result = WallCheckObstruction(wallEntry, targetHeight / kCoordsZStep, clearanceHeight, &wallAcrossTrack); - if (result.Error != GameActions::Status::Ok) - { - return result; - } - } - - Banner* banner = nullptr; - if (wallEntry->scrolling_mode != kScrollingModeNone) - { - banner = CreateBanner(); - if (banner == nullptr) - { - LOG_ERROR("No free banners available"); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_BUILD_THIS_HERE, STR_TOO_MANY_BANNERS_IN_GAME); + LOG_ERROR("Wall Type not found %d", _wallType); + return Result(Status::InvalidParameters, STR_CANT_BUILD_THIS_HERE, STR_UNKNOWN_OBJECT_TYPE); } - banner->text = {}; - banner->colour = COLOUR_WHITE; - banner->textColour = TextColour::white; - banner->flags = { BannerFlag::isWall }; - banner->type = 0; // Banner must be deleted after this point in an early return - banner->position = TileCoordsXY(_loc); - - RideId rideIndex = BannerGetClosestRideIndex(targetLoc); - if (!rideIndex.IsNull()) + if (wallEntry->scrolling_mode != kScrollingModeNone) { - banner->rideIndex = rideIndex; - banner->flags.set(BannerFlag::linkedToRide); + if (HasReachedBannerLimit()) + { + LOG_ERROR("No free banners available"); + return Result(Status::InvalidParameters, STR_CANT_BUILD_THIS_HERE, STR_TOO_MANY_BANNERS_IN_GAME); + } } + + uint8_t clearanceHeight = targetHeight / 8; + if (edgeSlope & (EDGE_SLOPE_UPWARDS | EDGE_SLOPE_DOWNWARDS)) + { + if (wallEntry->flags & WALL_SCENERY_CANT_BUILD_ON_SLOPE) + { + return Result(Status::Disallowed, STR_CANT_BUILD_THIS_HERE, STR_ERR_UNABLE_TO_BUILD_THIS_ON_SLOPE); + } + clearanceHeight += 2; + } + clearanceHeight += wallEntry->height; + + bool wallAcrossTrack = false; + if (!(GetFlags() & GAME_COMMAND_FLAG_TRACK_DESIGN) && !gameState.cheats.disableClearanceChecks) + { + auto result = WallCheckObstruction(wallEntry, targetHeight / 8, clearanceHeight, &wallAcrossTrack); + if (result.Error != Status::Ok) + { + return result; + } + } + + if (!MapCheckCapacityAndReorganise(_loc)) + { + return Result(Status::NoFreeElements, STR_CANT_BUILD_THIS_HERE, STR_TILE_ELEMENT_LIMIT_REACHED); + } + + res.Cost = wallEntry->price; + + res.SetData(WallPlaceActionResult{}); + + return res; } - auto* wallElement = TileElementInsert(targetLoc, 0b0000); - if (wallElement == nullptr) + Result WallPlaceAction::Execute() const { - return GameActions::Result( - GameActions::Status::NoFreeElements, STR_CANT_POSITION_THIS_HERE, STR_TILE_ELEMENT_LIMIT_REACHED); + auto res = Result(); + auto& gameState = getGameState(); + + res.ErrorTitle = STR_CANT_BUILD_THIS_HERE; + res.Position = _loc; + + res.Expenditure = ExpenditureType::landscaping; + res.Position.x += 16; + res.Position.y += 16; + + if (res.Position.z == 0) + { + res.Position.z = TileElementHeight(res.Position); + } + + uint8_t edgeSlope = 0; + auto targetHeight = _loc.z; + if (targetHeight == 0) + { + auto* surfaceElement = MapGetSurfaceElementAt(_loc); + if (surfaceElement == nullptr) + { + LOG_ERROR("Surface element not found at %d, %d.", _loc.x, _loc.y); + return Result(Status::InvalidParameters, STR_CANT_BUILD_THIS_HERE, STR_ERR_SURFACE_ELEMENT_NOT_FOUND); + } + targetHeight = surfaceElement->GetBaseZ(); + + uint8_t slope = surfaceElement->GetSlope(); + edgeSlope = GetWallSlopeFromEdgeSlope(slope, _edge & 3); + if (edgeSlope & EDGE_SLOPE_ELEVATED) + { + targetHeight += 16; + edgeSlope &= ~EDGE_SLOPE_ELEVATED; + } + } + auto targetLoc = CoordsXYZ(_loc, targetHeight); + + auto* wallEntry = ObjectManager::GetObjectEntry(_wallType); + + if (wallEntry == nullptr) + { + LOG_ERROR("Wall Type not found %d", _wallType); + return Result(Status::InvalidParameters, STR_CANT_BUILD_THIS_HERE, STR_UNKNOWN_OBJECT_TYPE); + } + + uint8_t clearanceHeight = targetHeight / kCoordsZStep; + if (edgeSlope & (EDGE_SLOPE_UPWARDS | EDGE_SLOPE_DOWNWARDS)) + { + clearanceHeight += 2; + } + clearanceHeight += wallEntry->height; + + bool wallAcrossTrack = false; + if (!(GetFlags() & GAME_COMMAND_FLAG_TRACK_DESIGN) && !gameState.cheats.disableClearanceChecks) + { + auto result = WallCheckObstruction(wallEntry, targetHeight / kCoordsZStep, clearanceHeight, &wallAcrossTrack); + if (result.Error != Status::Ok) + { + return result; + } + } + + Banner* banner = nullptr; + if (wallEntry->scrolling_mode != kScrollingModeNone) + { + banner = CreateBanner(); + if (banner == nullptr) + { + LOG_ERROR("No free banners available"); + return Result(Status::InvalidParameters, STR_CANT_BUILD_THIS_HERE, STR_TOO_MANY_BANNERS_IN_GAME); + } + + banner->text = {}; + banner->colour = COLOUR_WHITE; + banner->textColour = TextColour::white; + banner->flags = { BannerFlag::isWall }; + banner->type = 0; // Banner must be deleted after this point in an early return + banner->position = TileCoordsXY(_loc); + + RideId rideIndex = BannerGetClosestRideIndex(targetLoc); + if (!rideIndex.IsNull()) + { + banner->rideIndex = rideIndex; + banner->flags.set(BannerFlag::linkedToRide); + } + } + + auto* wallElement = TileElementInsert(targetLoc, 0b0000); + if (wallElement == nullptr) + { + return Result(Status::NoFreeElements, STR_CANT_POSITION_THIS_HERE, STR_TILE_ELEMENT_LIMIT_REACHED); + } + + wallElement->ClearanceHeight = clearanceHeight; + wallElement->SetDirection(_edge); + wallElement->SetSlope(edgeSlope); + + wallElement->SetPrimaryColour(_primaryColour); + wallElement->SetSecondaryColour(_secondaryColour); + wallElement->SetAcrossTrack(wallAcrossTrack); + + wallElement->SetEntryIndex(_wallType); + wallElement->SetBannerIndex(banner != nullptr ? banner->id : BannerIndex::GetNull()); + + if (wallEntry->flags & WALL_SCENERY_HAS_TERTIARY_COLOUR) + { + wallElement->SetTertiaryColour(_tertiaryColour); + } + + wallElement->SetGhost(GetFlags() & GAME_COMMAND_FLAG_GHOST); + + MapAnimations::MarkTileForInvalidation(TileCoordsXY(targetLoc)); + MapInvalidateTileZoom1({ _loc, wallElement->GetBaseZ(), wallElement->GetBaseZ() + 72 }); + + res.Cost = wallEntry->price; + + const auto bannerId = banner != nullptr ? banner->id : BannerIndex::GetNull(); + res.SetData(WallPlaceActionResult{ wallElement->GetBaseZ(), bannerId }); + + return res; } - wallElement->ClearanceHeight = clearanceHeight; - wallElement->SetDirection(_edge); - wallElement->SetSlope(edgeSlope); - - wallElement->SetPrimaryColour(_primaryColour); - wallElement->SetSecondaryColour(_secondaryColour); - wallElement->SetAcrossTrack(wallAcrossTrack); - - wallElement->SetEntryIndex(_wallType); - wallElement->SetBannerIndex(banner != nullptr ? banner->id : BannerIndex::GetNull()); - - if (wallEntry->flags & WALL_SCENERY_HAS_TERTIARY_COLOUR) + /** + * + * rct2: 0x006E5CBA + */ + bool WallPlaceAction::WallCheckObstructionWithTrack( + const WallSceneryEntry* wall, int32_t z0, TrackElement* trackElement, bool* wallAcrossTrack) const { - wallElement->SetTertiaryColour(_tertiaryColour); - } + OpenRCT2::TrackElemType trackType = trackElement->GetTrackType(); - wallElement->SetGhost(GetFlags() & GAME_COMMAND_FLAG_GHOST); - - MapAnimations::MarkTileForInvalidation(TileCoordsXY(targetLoc)); - MapInvalidateTileZoom1({ _loc, wallElement->GetBaseZ(), wallElement->GetBaseZ() + 72 }); - - res.Cost = wallEntry->price; - - const auto bannerId = banner != nullptr ? banner->id : BannerIndex::GetNull(); - res.SetData(WallPlaceActionResult{ wallElement->GetBaseZ(), bannerId }); - - return res; -} - -/** - * - * rct2: 0x006E5CBA - */ -bool WallPlaceAction::WallCheckObstructionWithTrack( - const WallSceneryEntry* wall, int32_t z0, TrackElement* trackElement, bool* wallAcrossTrack) const -{ - OpenRCT2::TrackElemType trackType = trackElement->GetTrackType(); - - using namespace OpenRCT2::TrackMetaData; - const auto& ted = GetTrackElementDescriptor(trackType); - int32_t sequence = trackElement->GetSequenceIndex(); - int32_t direction = (_edge - trackElement->GetDirection()) & kTileElementDirectionMask; - auto ride = GetRide(trackElement->GetRideIndex()); - if (ride == nullptr) - { - return false; - } - - if (TrackIsAllowedWallEdges(ride->type, trackType, sequence, direction)) - { - return true; - } - - if (!(wall->flags & WALL_SCENERY_IS_DOOR)) - { - return false; - } - - if (!ride->getRideTypeDescriptor().HasFlag(RtdFlag::allowDoorsOnTrack)) - { - return false; - } - - *wallAcrossTrack = true; - if (z0 & 1) - { - return false; - } - - int32_t z; - if (sequence == 0) - { - if (ted.sequences[0].flags & TRACK_SEQUENCE_FLAG_DISALLOW_DOORS) + using namespace OpenRCT2::TrackMetaData; + const auto& ted = GetTrackElementDescriptor(trackType); + int32_t sequence = trackElement->GetSequenceIndex(); + int32_t direction = (_edge - trackElement->GetDirection()) & kTileElementDirectionMask; + auto ride = GetRide(trackElement->GetRideIndex()); + if (ride == nullptr) { return false; } - if (ted.definition.rollStart == TrackRoll::None) + if (TrackIsAllowedWallEdges(ride->type, trackType, sequence, direction)) { - if (!(ted.coordinates.rotationBegin & 4)) + return true; + } + + if (!(wall->flags & WALL_SCENERY_IS_DOOR)) + { + return false; + } + + if (!ride->getRideTypeDescriptor().HasFlag(RtdFlag::allowDoorsOnTrack)) + { + return false; + } + + *wallAcrossTrack = true; + if (z0 & 1) + { + return false; + } + + int32_t z; + if (sequence == 0) + { + if (ted.sequences[0].flags & TRACK_SEQUENCE_FLAG_DISALLOW_DOORS) { - direction = DirectionReverse(trackElement->GetDirection()); - if (direction == _edge) + return false; + } + + if (ted.definition.rollStart == TrackRoll::None) + { + if (!(ted.coordinates.rotationBegin & 4)) { - z = ted.coordinates.zBegin; - z = trackElement->BaseHeight + ((z - ted.sequences[sequence].clearance.z) * 8); - if (z == z0) + direction = DirectionReverse(trackElement->GetDirection()); + if (direction == _edge) { - return true; + z = ted.coordinates.zBegin; + z = trackElement->BaseHeight + ((z - ted.sequences[sequence].clearance.z) * 8); + if (z == z0) + { + return true; + } } } } } - } - bool isLastInSequence = (sequence + 1) == ted.numSequences; - if (!isLastInSequence) - { - return false; - } - - if (ted.definition.rollEnd != TrackRoll::None) - { - return false; - } - - direction = ted.coordinates.rotationEnd; - if (direction & 4) - { - return false; - } - - direction = (trackElement->GetDirection() + ted.coordinates.rotationEnd) & kTileElementDirectionMask; - if (direction != _edge) - { - return false; - } - - z = ted.coordinates.zEnd; - z = trackElement->BaseHeight + ((z - ted.sequences[sequence].clearance.z) * kCoordsZStep); - return z == z0; -} - -/** - * - * rct2: 0x006E5C1A - */ -GameActions::Result WallPlaceAction::WallCheckObstruction( - const WallSceneryEntry* wall, int32_t z0, int32_t z1, bool* wallAcrossTrack) const -{ - *wallAcrossTrack = false; - if (MapIsLocationAtEdge(_loc)) - { - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_BUILD_THIS_HERE, STR_OFF_EDGE_OF_MAP); - } - - TileElement* tileElement = MapGetFirstElementAt(_loc); - do - { - if (tileElement == nullptr) - break; - auto elementType = tileElement->GetType(); - if (elementType == TileElementType::Surface) - continue; - if (tileElement->IsGhost()) - continue; - if (z0 >= tileElement->ClearanceHeight) - continue; - if (z1 <= tileElement->BaseHeight) - continue; - if (elementType == TileElementType::Wall) + bool isLastInSequence = (sequence + 1) == ted.numSequences; + if (!isLastInSequence) { - int32_t direction = tileElement->GetDirection(); - if (_edge == direction) - { - auto res = GameActions::Result(GameActions::Status::NoClearance, STR_CANT_BUILD_THIS_HERE, kStringIdNone); - MapGetObstructionErrorText(tileElement, res); - return res; - } - continue; + return false; } - if (tileElement->GetOccupiedQuadrants() == 0) - continue; - auto res = GameActions::Result(GameActions::Status::NoClearance, STR_CANT_BUILD_THIS_HERE, kStringIdNone); - switch (elementType) + + if (ted.definition.rollEnd != TrackRoll::None) { - case TileElementType::Entrance: - MapGetObstructionErrorText(tileElement, res); - return res; - case TileElementType::Path: - if (tileElement->AsPath()->GetEdges() & (1 << _edge)) + return false; + } + + direction = ted.coordinates.rotationEnd; + if (direction & 4) + { + return false; + } + + direction = (trackElement->GetDirection() + ted.coordinates.rotationEnd) & kTileElementDirectionMask; + if (direction != _edge) + { + return false; + } + + z = ted.coordinates.zEnd; + z = trackElement->BaseHeight + ((z - ted.sequences[sequence].clearance.z) * kCoordsZStep); + return z == z0; + } + + /** + * + * rct2: 0x006E5C1A + */ + Result WallPlaceAction::WallCheckObstruction( + const WallSceneryEntry* wall, int32_t z0, int32_t z1, bool* wallAcrossTrack) const + { + *wallAcrossTrack = false; + if (MapIsLocationAtEdge(_loc)) + { + return Result(Status::InvalidParameters, STR_CANT_BUILD_THIS_HERE, STR_OFF_EDGE_OF_MAP); + } + + TileElement* tileElement = MapGetFirstElementAt(_loc); + do + { + if (tileElement == nullptr) + break; + auto elementType = tileElement->GetType(); + if (elementType == TileElementType::Surface) + continue; + if (tileElement->IsGhost()) + continue; + if (z0 >= tileElement->ClearanceHeight) + continue; + if (z1 <= tileElement->BaseHeight) + continue; + if (elementType == TileElementType::Wall) + { + int32_t direction = tileElement->GetDirection(); + if (_edge == direction) { + auto res = Result(Status::NoClearance, STR_CANT_BUILD_THIS_HERE, kStringIdNone); MapGetObstructionErrorText(tileElement, res); return res; } - break; - case TileElementType::LargeScenery: + continue; + } + if (tileElement->GetOccupiedQuadrants() == 0) + continue; + auto res = Result(Status::NoClearance, STR_CANT_BUILD_THIS_HERE, kStringIdNone); + switch (elementType) { - const auto* largeSceneryElement = tileElement->AsLargeScenery(); - const auto* sceneryEntry = largeSceneryElement->GetEntry(); - - // If there is no entry, assume the object is not in the way. - if (sceneryEntry == nullptr) + case TileElementType::Entrance: + MapGetObstructionErrorText(tileElement, res); + return res; + case TileElementType::Path: + if (tileElement->AsPath()->GetEdges() & (1 << _edge)) + { + MapGetObstructionErrorText(tileElement, res); + return res; + } break; - - auto sequence = largeSceneryElement->GetSequenceIndex(); - const LargeSceneryTile& tile = sceneryEntry->tiles[sequence]; - - int32_t direction = ((_edge - tileElement->GetDirection()) & kTileElementDirectionMask); - if (!(tile.walls & (1 << direction))) + case TileElementType::LargeScenery: { - MapGetObstructionErrorText(tileElement, res); - return res; + const auto* largeSceneryElement = tileElement->AsLargeScenery(); + const auto* sceneryEntry = largeSceneryElement->GetEntry(); + + // If there is no entry, assume the object is not in the way. + if (sceneryEntry == nullptr) + break; + + auto sequence = largeSceneryElement->GetSequenceIndex(); + const LargeSceneryTile& tile = sceneryEntry->tiles[sequence]; + + int32_t direction = ((_edge - tileElement->GetDirection()) & kTileElementDirectionMask); + if (!(tile.walls & (1 << direction))) + { + MapGetObstructionErrorText(tileElement, res); + return res; + } + break; } - break; + case TileElementType::SmallScenery: + { + auto sceneryEntry = tileElement->AsSmallScenery()->GetEntry(); + if (sceneryEntry != nullptr && sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_NO_WALLS)) + { + MapGetObstructionErrorText(tileElement, res); + return res; + } + break; + } + case TileElementType::Track: + if (!WallCheckObstructionWithTrack(wall, z0, tileElement->AsTrack(), wallAcrossTrack)) + { + MapGetObstructionErrorText(tileElement, res); + return res; + } + break; + default: + break; } - case TileElementType::SmallScenery: - { - auto sceneryEntry = tileElement->AsSmallScenery()->GetEntry(); - if (sceneryEntry != nullptr && sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_NO_WALLS)) - { - MapGetObstructionErrorText(tileElement, res); - return res; - } - break; - } - case TileElementType::Track: - if (!WallCheckObstructionWithTrack(wall, z0, tileElement->AsTrack(), wallAcrossTrack)) - { - MapGetObstructionErrorText(tileElement, res); - return res; - } - break; - default: - break; - } - } while (!(tileElement++)->IsLastForTile()); + } while (!(tileElement++)->IsLastForTile()); - return GameActions::Result(); -} - -bool WallPlaceAction::TrackIsAllowedWallEdges( - ride_type_t rideType, OpenRCT2::TrackElemType trackType, uint8_t trackSequence, uint8_t direction) -{ - if (!GetRideTypeDescriptor(rideType).HasFlag(RtdFlag::noWallsAroundTrack)) - { - const auto& ted = GetTrackElementDescriptor(trackType); - if (ted.sequences[trackSequence].allowedWallEdges & (1 << direction)) - { - return true; - } + return Result(); } - return false; -} + + bool WallPlaceAction::TrackIsAllowedWallEdges( + ride_type_t rideType, OpenRCT2::TrackElemType trackType, uint8_t trackSequence, uint8_t direction) + { + if (!GetRideTypeDescriptor(rideType).HasFlag(RtdFlag::noWallsAroundTrack)) + { + const auto& ted = GetTrackElementDescriptor(trackType); + if (ted.sequences[trackSequence].allowedWallEdges & (1 << direction)) + { + return true; + } + } + return false; + } +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/WallPlaceAction.h b/src/openrct2/actions/WallPlaceAction.h index 9e23ce7c24..19a2ab1d4e 100644 --- a/src/openrct2/actions/WallPlaceAction.h +++ b/src/openrct2/actions/WallPlaceAction.h @@ -20,54 +20,56 @@ namespace OpenRCT2 struct WallSceneryEntry; } -struct WallPlaceActionResult +namespace OpenRCT2::GameActions { - int32_t BaseHeight{}; - BannerIndex BannerId = BannerIndex::GetNull(); -}; + struct WallPlaceActionResult + { + int32_t BaseHeight{}; + BannerIndex BannerId = BannerIndex::GetNull(); + }; -class WallPlaceAction final : public GameActionBase -{ -private: - OpenRCT2::ObjectEntryIndex _wallType{ OpenRCT2::kObjectEntryIndexNull }; - CoordsXYZ _loc; - Direction _edge{ kInvalidDirection }; - int32_t _primaryColour{ COLOUR_BLACK }; - int32_t _secondaryColour{ COLOUR_BLACK }; - int32_t _tertiaryColour{ COLOUR_BLACK }; + class WallPlaceAction final : public GameActionBase + { + private: + ObjectEntryIndex _wallType{ kObjectEntryIndexNull }; + CoordsXYZ _loc; + Direction _edge{ kInvalidDirection }; + int32_t _primaryColour{ COLOUR_BLACK }; + int32_t _secondaryColour{ COLOUR_BLACK }; + int32_t _tertiaryColour{ COLOUR_BLACK }; -public: - WallPlaceAction() = default; - WallPlaceAction( - OpenRCT2::ObjectEntryIndex wallType, const CoordsXYZ& loc, uint8_t edge, int32_t primaryColour, int32_t secondaryColour, - int32_t tertiaryColour); + public: + WallPlaceAction() = default; + WallPlaceAction( + ObjectEntryIndex wallType, const CoordsXYZ& loc, uint8_t edge, int32_t primaryColour, int32_t secondaryColour, + int32_t tertiaryColour); - void AcceptParameters(GameActionParameterVisitor& visitor) override; + void AcceptParameters(GameActionParameterVisitor& visitor) override; - uint16_t GetActionFlags() const override final; + uint16_t GetActionFlags() const override final; - 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: - /** - * - * rct2: 0x006E5CBA - */ - bool WallCheckObstructionWithTrack( - const WallSceneryEntry* wall, int32_t z0, TrackElement* trackElement, bool* wallAcrossTrack) const; - /** - * - * rct2: 0x006E5C1A - */ - OpenRCT2::GameActions::Result WallCheckObstruction( - const WallSceneryEntry* wall, int32_t z0, int32_t z1, bool* wallAcrossTrack) const; + private: + /** + * + * rct2: 0x006E5CBA + */ + bool WallCheckObstructionWithTrack( + const WallSceneryEntry* wall, int32_t z0, TrackElement* trackElement, bool* wallAcrossTrack) const; + /** + * + * rct2: 0x006E5C1A + */ + Result WallCheckObstruction(const WallSceneryEntry* wall, int32_t z0, int32_t z1, bool* wallAcrossTrack) const; - /** - * Gets whether the given track type can have a wall placed on the edge of the given direction. - * Some thin tracks for example are allowed to have walls either side of the track, but wider tracks can not. - */ - static bool TrackIsAllowedWallEdges( - ride_type_t rideType, OpenRCT2::TrackElemType trackType, uint8_t trackSequence, uint8_t direction); -}; + /** + * Gets whether the given track type can have a wall placed on the edge of the given direction. + * Some thin tracks for example are allowed to have walls either side of the track, but wider tracks can not. + */ + static bool TrackIsAllowedWallEdges( + ride_type_t rideType, OpenRCT2::TrackElemType trackType, uint8_t trackSequence, uint8_t direction); + }; +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/WallRemoveAction.cpp b/src/openrct2/actions/WallRemoveAction.cpp index a5f911319d..323e5ed467 100644 --- a/src/openrct2/actions/WallRemoveAction.cpp +++ b/src/openrct2/actions/WallRemoveAction.cpp @@ -19,92 +19,91 @@ #include "../world/TileElementsView.h" #include "../world/tile_element/WallElement.h" -using namespace OpenRCT2; - -WallRemoveAction::WallRemoveAction(const CoordsXYZD& loc) - : _loc(loc) +namespace OpenRCT2::GameActions { -} - -void WallRemoveAction::AcceptParameters(GameActionParameterVisitor& visitor) -{ - visitor.Visit(_loc); -} - -void WallRemoveAction::Serialise(DataSerialiser& stream) -{ - GameAction::Serialise(stream); - - stream << DS_TAG(_loc); -} - -GameActions::Result WallRemoveAction::Query() const -{ - GameActions::Result res = GameActions::Result(); - res.Cost = 0; - res.Expenditure = ExpenditureType::landscaping; - - if (!LocationValid(_loc)) + WallRemoveAction::WallRemoveAction(const CoordsXYZD& loc) + : _loc(loc) { - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_OFF_EDGE_OF_MAP); } - const bool isGhost = GetFlags() & GAME_COMMAND_FLAG_GHOST; - if (!isGhost && gLegacyScene != LegacyScene::scenarioEditor && !getGameState().cheats.sandboxMode - && !MapIsLocationOwned(_loc)) + void WallRemoveAction::AcceptParameters(GameActionParameterVisitor& visitor) { - return GameActions::Result(GameActions::Status::NotOwned, STR_CANT_REMOVE_THIS, STR_LAND_NOT_OWNED_BY_PARK); + visitor.Visit(_loc); } - TileElement* wallElement = GetFirstWallElementAt(_loc, isGhost); - if (wallElement == nullptr) + void WallRemoveAction::Serialise(DataSerialiser& stream) { - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_INVALID_SELECTION_OF_OBJECTS); + GameAction::Serialise(stream); + + stream << DS_TAG(_loc); } - res.Cost = 0; - return res; -} - -GameActions::Result WallRemoveAction::Execute() const -{ - GameActions::Result res = GameActions::Result(); - res.Cost = 0; - res.Expenditure = ExpenditureType::landscaping; - - const bool isGhost = GetFlags() & GAME_COMMAND_FLAG_GHOST; - - TileElement* wallElement = GetFirstWallElementAt(_loc, isGhost); - if (wallElement == nullptr) + Result WallRemoveAction::Query() const { - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_INVALID_SELECTION_OF_OBJECTS); + Result res = Result(); + res.Cost = 0; + res.Expenditure = ExpenditureType::landscaping; + + if (!LocationValid(_loc)) + { + return Result(Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_OFF_EDGE_OF_MAP); + } + + const bool isGhost = GetFlags() & GAME_COMMAND_FLAG_GHOST; + if (!isGhost && gLegacyScene != LegacyScene::scenarioEditor && !getGameState().cheats.sandboxMode + && !MapIsLocationOwned(_loc)) + { + return Result(Status::NotOwned, STR_CANT_REMOVE_THIS, STR_LAND_NOT_OWNED_BY_PARK); + } + + TileElement* wallElement = GetFirstWallElementAt(_loc, isGhost); + if (wallElement == nullptr) + { + return Result(Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_INVALID_SELECTION_OF_OBJECTS); + } + + res.Cost = 0; + return res; } - res.Position.x = _loc.x + 16; - res.Position.y = _loc.y + 16; - res.Position.z = _loc.z; - - wallElement->RemoveBannerEntry(); - MapInvalidateTileZoom1({ _loc, wallElement->GetBaseZ(), (wallElement->GetBaseZ()) + 72 }); - TileElementRemove(wallElement); - - return res; -} - -TileElement* WallRemoveAction::GetFirstWallElementAt(const CoordsXYZD& location, bool isGhost) const -{ - for (auto* wallElement : TileElementsView(location)) + Result WallRemoveAction::Execute() const { - if (wallElement->GetBaseZ() != location.z) - continue; - if (wallElement->GetDirection() != location.direction) - continue; - if (wallElement->IsGhost() != isGhost) - continue; + Result res = Result(); + res.Cost = 0; + res.Expenditure = ExpenditureType::landscaping; - return wallElement->as(); + const bool isGhost = GetFlags() & GAME_COMMAND_FLAG_GHOST; + + TileElement* wallElement = GetFirstWallElementAt(_loc, isGhost); + if (wallElement == nullptr) + { + return Result(Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_INVALID_SELECTION_OF_OBJECTS); + } + + res.Position.x = _loc.x + 16; + res.Position.y = _loc.y + 16; + res.Position.z = _loc.z; + + wallElement->RemoveBannerEntry(); + MapInvalidateTileZoom1({ _loc, wallElement->GetBaseZ(), (wallElement->GetBaseZ()) + 72 }); + TileElementRemove(wallElement); + + return res; } - return nullptr; -} + + TileElement* WallRemoveAction::GetFirstWallElementAt(const CoordsXYZD& location, bool isGhost) const + { + for (auto* wallElement : TileElementsView(location)) + { + if (wallElement->GetBaseZ() != location.z) + continue; + if (wallElement->GetDirection() != location.direction) + continue; + if (wallElement->IsGhost() != isGhost) + continue; + + return wallElement->as(); + } + return nullptr; + } +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/WallRemoveAction.h b/src/openrct2/actions/WallRemoveAction.h index 2fb39e0628..6ac00ca752 100644 --- a/src/openrct2/actions/WallRemoveAction.h +++ b/src/openrct2/actions/WallRemoveAction.h @@ -11,20 +11,23 @@ #include "GameAction.h" -class WallRemoveAction final : public GameActionBase +namespace OpenRCT2::GameActions { -private: - CoordsXYZD _loc; + class WallRemoveAction final : public GameActionBase + { + private: + CoordsXYZD _loc; -public: - WallRemoveAction() = default; - WallRemoveAction(const CoordsXYZD& loc); + public: + WallRemoveAction() = default; + WallRemoveAction(const CoordsXYZD& loc); - void AcceptParameters(GameActionParameterVisitor& visitor) override; - void Serialise(DataSerialiser& stream) override; - OpenRCT2::GameActions::Result Query() const override; - OpenRCT2::GameActions::Result Execute() const override; + void AcceptParameters(GameActionParameterVisitor& visitor) override; + void Serialise(DataSerialiser& stream) override; + Result Query() const override; + Result Execute() const override; -private: - OpenRCT2::TileElement* GetFirstWallElementAt(const CoordsXYZD& location, bool isGhost) const; -}; + private: + TileElement* GetFirstWallElementAt(const CoordsXYZD& location, bool isGhost) const; + }; +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/WallSetColourAction.cpp b/src/openrct2/actions/WallSetColourAction.cpp index fe5808004c..754de2971f 100644 --- a/src/openrct2/actions/WallSetColourAction.cpp +++ b/src/openrct2/actions/WallSetColourAction.cpp @@ -20,140 +20,142 @@ #include "../world/Scenery.h" #include "../world/tile_element/WallElement.h" -using namespace OpenRCT2; - -WallSetColourAction::WallSetColourAction( - const CoordsXYZD& loc, int32_t primaryColour, int32_t secondaryColour, int32_t tertiaryColour) - : _loc(loc) - , _primaryColour(primaryColour) - , _secondaryColour(secondaryColour) - , _tertiaryColour(tertiaryColour) +namespace OpenRCT2::GameActions { -} - -void WallSetColourAction::AcceptParameters(GameActionParameterVisitor& visitor) -{ - visitor.Visit(_loc); - visitor.Visit("primaryColour", _primaryColour); - visitor.Visit("secondaryColour", _secondaryColour); - visitor.Visit("tertiaryColour", _tertiaryColour); -} - -uint16_t WallSetColourAction::GetActionFlags() const -{ - return GameAction::GetActionFlags() | GameActions::Flags::AllowWhilePaused; -} - -void WallSetColourAction::Serialise(DataSerialiser& stream) -{ - GameAction::Serialise(stream); - - stream << DS_TAG(_loc) << DS_TAG(_primaryColour) << DS_TAG(_secondaryColour) << DS_TAG(_tertiaryColour); -} - -GameActions::Result WallSetColourAction::Query() const -{ - auto res = GameActions::Result(); - res.ErrorTitle = STR_CANT_REPAINT_THIS; - res.Position.x = _loc.x + 16; - res.Position.y = _loc.y + 16; - res.Position.z = _loc.z; - - res.Expenditure = ExpenditureType::landscaping; - - if (!LocationValid(_loc)) + WallSetColourAction::WallSetColourAction( + const CoordsXYZD& loc, int32_t primaryColour, int32_t secondaryColour, int32_t tertiaryColour) + : _loc(loc) + , _primaryColour(primaryColour) + , _secondaryColour(secondaryColour) + , _tertiaryColour(tertiaryColour) { - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_OFF_EDGE_OF_MAP); } - if (gLegacyScene != LegacyScene::scenarioEditor && !MapIsLocationInPark(_loc) && !getGameState().cheats.sandboxMode) + void WallSetColourAction::AcceptParameters(GameActionParameterVisitor& visitor) { - return GameActions::Result(GameActions::Status::NotOwned, STR_CANT_REPAINT_THIS, STR_LAND_NOT_OWNED_BY_PARK); + visitor.Visit(_loc); + visitor.Visit("primaryColour", _primaryColour); + visitor.Visit("secondaryColour", _secondaryColour); + visitor.Visit("tertiaryColour", _tertiaryColour); } - auto wallElement = MapGetWallElementAt(_loc); - if (wallElement == nullptr) + uint16_t WallSetColourAction::GetActionFlags() const { - LOG_ERROR( - "Could not find wall element at: x = %d, y = %d, z = %d, direction = %u", _loc.x, _loc.y, _loc.z, _loc.direction); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_WALL_ELEMENT_NOT_FOUND); + return GameAction::GetActionFlags() | Flags::AllowWhilePaused; } - if ((GetFlags() & GAME_COMMAND_FLAG_GHOST) && !(wallElement->IsGhost())) + void WallSetColourAction::Serialise(DataSerialiser& stream) { - return res; + GameAction::Serialise(stream); + + stream << DS_TAG(_loc) << DS_TAG(_primaryColour) << DS_TAG(_secondaryColour) << DS_TAG(_tertiaryColour); } - auto* wallEntry = wallElement->GetEntry(); - if (wallEntry == nullptr) + Result WallSetColourAction::Query() const { - LOG_ERROR( - "Wall element does not have wall entry 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, kStringIdNone); - } + auto res = Result(); + res.ErrorTitle = STR_CANT_REPAINT_THIS; + res.Position.x = _loc.x + 16; + res.Position.y = _loc.y + 16; + res.Position.z = _loc.z; - if (_primaryColour >= COLOUR_COUNT) - { - LOG_ERROR("Primary colour invalid: colour = %d", _primaryColour); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_INVALID_COLOUR); - } - else if (_secondaryColour >= COLOUR_COUNT) - { - LOG_ERROR("Secondary colour invalid: colour = %d", _secondaryColour); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_INVALID_COLOUR); - } - else if (wallEntry->flags & WALL_SCENERY_HAS_TERTIARY_COLOUR) - { - if (_tertiaryColour >= COLOUR_COUNT) + res.Expenditure = ExpenditureType::landscaping; + + if (!LocationValid(_loc)) { - LOG_ERROR("Tertiary colour invalid: colour = %d", _tertiaryColour); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, kStringIdNone); + return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_OFF_EDGE_OF_MAP); } - } - return res; -} -GameActions::Result WallSetColourAction::Execute() const -{ - auto res = GameActions::Result(); - res.ErrorTitle = STR_CANT_REPAINT_THIS; - res.Position.x = _loc.x + 16; - res.Position.y = _loc.y + 16; - res.Position.z = _loc.z; - res.Expenditure = ExpenditureType::landscaping; + if (gLegacyScene != LegacyScene::scenarioEditor && !MapIsLocationInPark(_loc) && !getGameState().cheats.sandboxMode) + { + return Result(Status::NotOwned, STR_CANT_REPAINT_THIS, STR_LAND_NOT_OWNED_BY_PARK); + } - auto wallElement = MapGetWallElementAt(_loc); - if (wallElement == nullptr) - { - LOG_ERROR( - "Could not find wall element at: x = %d, y = %d, z = %d, direction = %u", _loc.x, _loc.y, _loc.z, _loc.direction); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, kStringIdNone); - } + auto wallElement = MapGetWallElementAt(_loc); + if (wallElement == nullptr) + { + LOG_ERROR( + "Could not find wall element at: x = %d, y = %d, z = %d, direction = %u", _loc.x, _loc.y, _loc.z, + _loc.direction); + return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_WALL_ELEMENT_NOT_FOUND); + } - if ((GetFlags() & GAME_COMMAND_FLAG_GHOST) && !(wallElement->IsGhost())) - { + if ((GetFlags() & GAME_COMMAND_FLAG_GHOST) && !(wallElement->IsGhost())) + { + return res; + } + + auto* wallEntry = wallElement->GetEntry(); + if (wallEntry == nullptr) + { + LOG_ERROR( + "Wall element does not have wall entry 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, kStringIdNone); + } + + if (_primaryColour >= COLOUR_COUNT) + { + LOG_ERROR("Primary colour invalid: colour = %d", _primaryColour); + return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_INVALID_COLOUR); + } + else if (_secondaryColour >= COLOUR_COUNT) + { + LOG_ERROR("Secondary colour invalid: colour = %d", _secondaryColour); + return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_INVALID_COLOUR); + } + else if (wallEntry->flags & WALL_SCENERY_HAS_TERTIARY_COLOUR) + { + if (_tertiaryColour >= COLOUR_COUNT) + { + LOG_ERROR("Tertiary colour invalid: colour = %d", _tertiaryColour); + return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, kStringIdNone); + } + } return res; } - auto* wallEntry = wallElement->GetEntry(); - if (wallEntry == nullptr) + Result WallSetColourAction::Execute() const { - LOG_ERROR( - "Wall element does not have wall entry 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, kStringIdNone); + auto res = Result(); + res.ErrorTitle = STR_CANT_REPAINT_THIS; + res.Position.x = _loc.x + 16; + res.Position.y = _loc.y + 16; + res.Position.z = _loc.z; + res.Expenditure = ExpenditureType::landscaping; + + auto wallElement = MapGetWallElementAt(_loc); + if (wallElement == nullptr) + { + LOG_ERROR( + "Could not find wall element at: x = %d, y = %d, z = %d, direction = %u", _loc.x, _loc.y, _loc.z, + _loc.direction); + return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, kStringIdNone); + } + + if ((GetFlags() & GAME_COMMAND_FLAG_GHOST) && !(wallElement->IsGhost())) + { + return res; + } + + auto* wallEntry = wallElement->GetEntry(); + if (wallEntry == nullptr) + { + LOG_ERROR( + "Wall element does not have wall entry 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, kStringIdNone); + } + + wallElement->SetPrimaryColour(_primaryColour); + wallElement->SetSecondaryColour(_secondaryColour); + + if (wallEntry->flags & WALL_SCENERY_HAS_TERTIARY_COLOUR) + { + wallElement->SetTertiaryColour(_tertiaryColour); + } + MapInvalidateTileZoom1({ _loc, _loc.z, _loc.z + 72 }); + + return res; } - - wallElement->SetPrimaryColour(_primaryColour); - wallElement->SetSecondaryColour(_secondaryColour); - - if (wallEntry->flags & WALL_SCENERY_HAS_TERTIARY_COLOUR) - { - wallElement->SetTertiaryColour(_tertiaryColour); - } - MapInvalidateTileZoom1({ _loc, _loc.z, _loc.z + 72 }); - - return res; -} +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/WallSetColourAction.h b/src/openrct2/actions/WallSetColourAction.h index d44ceb5b2c..89259d4137 100644 --- a/src/openrct2/actions/WallSetColourAction.h +++ b/src/openrct2/actions/WallSetColourAction.h @@ -11,23 +11,26 @@ #include "GameAction.h" -class WallSetColourAction final : public GameActionBase +namespace OpenRCT2::GameActions { -private: - CoordsXYZD _loc; - int32_t _primaryColour{}; - int32_t _secondaryColour{}; - int32_t _tertiaryColour{}; + class WallSetColourAction final : public GameActionBase + { + private: + CoordsXYZD _loc; + int32_t _primaryColour{}; + int32_t _secondaryColour{}; + int32_t _tertiaryColour{}; -public: - WallSetColourAction() = default; - WallSetColourAction(const CoordsXYZD& loc, int32_t primaryColour, int32_t secondaryColour, int32_t tertiaryColour); + public: + WallSetColourAction() = default; + WallSetColourAction(const CoordsXYZD& loc, int32_t primaryColour, int32_t secondaryColour, int32_t tertiaryColour); - 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 diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index d0e2abf33c..270f28b985 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -961,7 +961,7 @@ static GameActions::Result TrackDesignPlaceSceneryElementRemoveGhost( uint8_t quadrant = scenery.getQuadrant() + _currentTrackPieceDirection; quadrant &= 3; - auto* sceneryEntry = OpenRCT2::ObjectManager::GetObjectEntry(entryInfo->Index); + auto* sceneryEntry = ObjectManager::GetObjectEntry(entryInfo->Index); if (!(!sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_FULL_TILE) && sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_DIAGONAL)) && sceneryEntry->HasFlag( SMALL_SCENERY_FLAG_DIAGONAL | SMALL_SCENERY_FLAG_HALF_SPACE | SMALL_SCENERY_FLAG_THREE_QUARTERS)) @@ -969,14 +969,16 @@ static GameActions::Result TrackDesignPlaceSceneryElementRemoveGhost( quadrant = 0; } - ga = std::make_unique(CoordsXYZ{ mapCoord.x, mapCoord.y, z }, quadrant, entryInfo->Index); + ga = std::make_unique( + CoordsXYZ{ mapCoord.x, mapCoord.y, z }, quadrant, entryInfo->Index); break; } case ObjectType::largeScenery: - ga = std::make_unique(CoordsXYZD{ mapCoord.x, mapCoord.y, z, sceneryRotation }, 0); + ga = std::make_unique( + CoordsXYZD{ mapCoord.x, mapCoord.y, z, sceneryRotation }, 0); break; case ObjectType::walls: - ga = std::make_unique(CoordsXYZD{ mapCoord.x, mapCoord.y, z, sceneryRotation }); + ga = std::make_unique(CoordsXYZD{ mapCoord.x, mapCoord.y, z, sceneryRotation }); break; case ObjectType::paths: case ObjectType::footpathSurface: @@ -1075,7 +1077,7 @@ static GameActions::Result TrackDesignPlaceSceneryElement( flags |= GAME_COMMAND_FLAG_REPLAY; } - auto smallSceneryPlace = SmallSceneryPlaceAction( + auto smallSceneryPlace = GameActions::SmallSceneryPlaceAction( { mapCoord.x, mapCoord.y, z, rotation }, quadrant, entryInfo->Index, scenery.primaryColour, scenery.secondaryColour, scenery.tertiaryColour); @@ -1117,7 +1119,7 @@ static GameActions::Result TrackDesignPlaceSceneryElement( { flags |= GAME_COMMAND_FLAG_REPLAY; } - auto sceneryPlaceAction = LargeSceneryPlaceAction( + auto sceneryPlaceAction = GameActions::LargeSceneryPlaceAction( { mapCoord.x, mapCoord.y, z, rotation }, entryInfo->Index, scenery.primaryColour, scenery.secondaryColour, scenery.tertiaryColour); sceneryPlaceAction.SetFlags(flags); @@ -1157,7 +1159,7 @@ static GameActions::Result TrackDesignPlaceSceneryElement( { flags |= GAME_COMMAND_FLAG_REPLAY; } - auto wallPlaceAction = WallPlaceAction( + auto wallPlaceAction = GameActions::WallPlaceAction( entryInfo->Index, { mapCoord.x, mapCoord.y, z }, rotation, scenery.primaryColour, scenery.secondaryColour, scenery.tertiaryColour); wallPlaceAction.SetFlags(flags); diff --git a/src/openrct2/scripting/ScriptEngine.cpp b/src/openrct2/scripting/ScriptEngine.cpp index 353f720adf..091a75149c 100644 --- a/src/openrct2/scripting/ScriptEngine.cpp +++ b/src/openrct2/scripting/ScriptEngine.cpp @@ -1249,10 +1249,10 @@ DukValue ScriptEngine::GameActionResultToDuk(const GameAction& action, const Gam bannerId = result.GetData().bannerId; break; case GameCommand::PlaceLargeScenery: - bannerId = result.GetData().bannerId; + bannerId = result.GetData().bannerId; break; case GameCommand::PlaceWall: - bannerId = result.GetData().BannerId; + bannerId = result.GetData().BannerId; break; default: break; diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index a8034fca4f..b0e5868cb7 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -1502,7 +1502,7 @@ void ClearElementAt(const CoordsXY& loc, TileElement** elementPtr) case TileElementType::Wall: { CoordsXYZD wallLocation = { loc.x, loc.y, element->GetBaseZ(), element->GetDirection() }; - auto wallRemoveAction = WallRemoveAction(wallLocation); + auto wallRemoveAction = GameActions::WallRemoveAction(wallLocation); auto result = GameActions::ExecuteNested(&wallRemoveAction); // If asking nicely did not work, forcibly remove this to avoid an infinite loop. if (result.Error != GameActions::Status::Ok) @@ -1513,7 +1513,7 @@ void ClearElementAt(const CoordsXY& loc, TileElement** elementPtr) break; case TileElementType::LargeScenery: { - auto removeSceneryAction = LargeSceneryRemoveAction( + auto removeSceneryAction = GameActions::LargeSceneryRemoveAction( { loc.x, loc.y, element->GetBaseZ(), element->GetDirection() }, element->AsLargeScenery()->GetSequenceIndex()); auto result = GameActions::ExecuteNested(&removeSceneryAction); // If asking nicely did not work, forcibly remove this to avoid an infinite loop. diff --git a/src/openrct2/world/Scenery.cpp b/src/openrct2/world/Scenery.cpp index 43400bf304..a119595d34 100644 --- a/src/openrct2/world/Scenery.cpp +++ b/src/openrct2/world/Scenery.cpp @@ -237,7 +237,7 @@ void SceneryRemoveGhostToolPlacement() { gSceneryGhostType &= ~SCENERY_GHOST_FLAG_0; - auto removeSceneryAction = SmallSceneryRemoveAction( + auto removeSceneryAction = GameActions::SmallSceneryRemoveAction( gSceneryGhostPosition, gSceneryQuadrant, gSceneryPlaceObject.EntryIndex); removeSceneryAction.SetFlags( GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_NO_SPEND | GAME_COMMAND_FLAG_GHOST); @@ -273,7 +273,7 @@ void SceneryRemoveGhostToolPlacement() gSceneryGhostType &= ~SCENERY_GHOST_FLAG_2; CoordsXYZD wallLocation = { gSceneryGhostPosition, gSceneryGhostWallRotation }; - auto wallRemoveAction = WallRemoveAction(wallLocation); + auto wallRemoveAction = GameActions::WallRemoveAction(wallLocation); wallRemoveAction.SetFlags(GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_NO_SPEND | GAME_COMMAND_FLAG_GHOST); wallRemoveAction.Execute(); } @@ -282,7 +282,7 @@ void SceneryRemoveGhostToolPlacement() { gSceneryGhostType &= ~SCENERY_GHOST_FLAG_3; - auto removeSceneryAction = LargeSceneryRemoveAction({ gSceneryGhostPosition, gSceneryPlaceRotation }, 0); + auto removeSceneryAction = GameActions::LargeSceneryRemoveAction({ gSceneryGhostPosition, gSceneryPlaceRotation }, 0); removeSceneryAction.SetFlags( GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_NO_SPEND | GAME_COMMAND_FLAG_GHOST); removeSceneryAction.Execute();