From afdee8852afdb2fb0ed6da5222dc56c6e60c5b6c Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Tue, 26 Aug 2025 21:17:44 +0200 Subject: [PATCH] Move LoadOrQuit, Map, Maze, Network game actions --- src/openrct2-ui/input/Shortcuts.cpp | 2 +- src/openrct2-ui/windows/Map.cpp | 6 +- src/openrct2-ui/windows/MazeConstruction.cpp | 4 +- src/openrct2-ui/windows/Multiplayer.cpp | 17 +- src/openrct2-ui/windows/RideConstruction.cpp | 7 +- src/openrct2-ui/windows/TitleMenu.cpp | 2 +- src/openrct2-ui/windows/TopToolbar.cpp | 10 +- src/openrct2/Game.cpp | 6 +- src/openrct2/actions/LoadOrQuitAction.cpp | 99 ++-- src/openrct2/actions/LoadOrQuitAction.h | 39 +- src/openrct2/actions/MapChangeSizeAction.cpp | 145 +++-- src/openrct2/actions/MapChangeSizeAction.h | 31 +- src/openrct2/actions/MazePlaceTrackAction.cpp | 321 +++++----- src/openrct2/actions/MazePlaceTrackAction.h | 30 +- src/openrct2/actions/MazeSetTrackAction.cpp | 548 +++++++++--------- src/openrct2/actions/MazeSetTrackAction.h | 35 +- .../actions/NetworkModifyGroupAction.cpp | 72 +-- .../actions/NetworkModifyGroupAction.h | 71 +-- src/openrct2/actions/RideDemolishAction.cpp | 2 +- src/openrct2/network/Network.h | 10 +- src/openrct2/network/NetworkBase.cpp | 27 +- src/openrct2/ride/RideConstruction.cpp | 3 +- src/openrct2/ride/TrackDesign.cpp | 2 +- .../scripting/bindings/network/ScNetwork.cpp | 8 +- .../bindings/network/ScPlayerGroup.cpp | 10 +- 25 files changed, 767 insertions(+), 740 deletions(-) diff --git a/src/openrct2-ui/input/Shortcuts.cpp b/src/openrct2-ui/input/Shortcuts.cpp index aa65b1a1d3..07b454254a 100644 --- a/src/openrct2-ui/input/Shortcuts.cpp +++ b/src/openrct2-ui/input/Shortcuts.cpp @@ -429,7 +429,7 @@ static void ShortcutLoadGame() { if (!(isInTrackDesignerOrManager())) { - auto loadOrQuitAction = LoadOrQuitAction(LoadOrQuitModes::OpenSavePrompt); + auto loadOrQuitAction = GameActions::LoadOrQuitAction(GameActions::LoadOrQuitModes::OpenSavePrompt); GameActions::Execute(&loadOrQuitAction); } } diff --git a/src/openrct2-ui/windows/Map.cpp b/src/openrct2-ui/windows/Map.cpp index 25e0a10a2d..b8bf6db87a 100644 --- a/src/openrct2-ui/windows/Map.cpp +++ b/src/openrct2-ui/windows/Map.cpp @@ -515,7 +515,7 @@ namespace OpenRCT2::Ui::Windows if (_resizeDirection != ResizeDirection::Y) newMapSize.x = size; - auto mapChangeSizeAction = MapChangeSizeAction(newMapSize); + auto mapChangeSizeAction = GameActions::MapChangeSizeAction(newMapSize); GameActions::Execute(&mapChangeSizeAction); Invalidate(); } @@ -763,7 +763,7 @@ namespace OpenRCT2::Ui::Windows if (IsWidgetPressed(WIDX_MAP_SIZE_LINK) || _resizeDirection == ResizeDirection::X) newMapSize.x++; - auto increaseMapSizeAction = MapChangeSizeAction(newMapSize); + auto increaseMapSizeAction = GameActions::MapChangeSizeAction(newMapSize); GameActions::Execute(&increaseMapSizeAction); } @@ -775,7 +775,7 @@ namespace OpenRCT2::Ui::Windows if (IsWidgetPressed(WIDX_MAP_SIZE_LINK) || _resizeDirection == ResizeDirection::X) newMapSize.x--; - auto decreaseMapSizeAction = MapChangeSizeAction(newMapSize); + auto decreaseMapSizeAction = GameActions::MapChangeSizeAction(newMapSize); GameActions::Execute(&decreaseMapSizeAction); } diff --git a/src/openrct2-ui/windows/MazeConstruction.cpp b/src/openrct2-ui/windows/MazeConstruction.cpp index 39800afd1c..648ab56d4f 100644 --- a/src/openrct2-ui/windows/MazeConstruction.cpp +++ b/src/openrct2-ui/windows/MazeConstruction.cpp @@ -421,7 +421,7 @@ namespace OpenRCT2::Ui::Windows } const auto loc = CoordsXYZD{ x, y, z, static_cast(direction) }; - auto action = MazeSetTrackAction(loc, false, _currentRideIndex, mode); + auto action = GameActions::MazeSetTrackAction(loc, false, _currentRideIndex, mode); action.SetFlags(actionFlags); const auto res = GameActions::Execute(&action); if (res.Error != GameActions::Status::Ok) @@ -433,7 +433,7 @@ namespace OpenRCT2::Ui::Windows _currentTrackBegin.y = y; if (_rideConstructionState != RideConstructionState::MazeMove) { - OpenRCT2::Audio::Play3D(OpenRCT2::Audio::SoundId::PlaceItem, { x, y, z }); + Audio::Play3D(Audio::SoundId::PlaceItem, { x, y, z }); } } }; diff --git a/src/openrct2-ui/windows/Multiplayer.cpp b/src/openrct2-ui/windows/Multiplayer.cpp index c9bca100f3..43188d5727 100644 --- a/src/openrct2-ui/windows/Multiplayer.cpp +++ b/src/openrct2-ui/windows/Multiplayer.cpp @@ -250,13 +250,14 @@ namespace OpenRCT2::Ui::Windows { case WIDX_ADD_GROUP: { - auto networkModifyGroup = NetworkModifyGroupAction(ModifyGroupType::AddGroup); + auto networkModifyGroup = GameActions::NetworkModifyGroupAction(GameActions::ModifyGroupType::AddGroup); GameActions::Execute(&networkModifyGroup); break; } case WIDX_REMOVE_GROUP: { - auto networkModifyGroup = NetworkModifyGroupAction(ModifyGroupType::RemoveGroup, _selectedGroup); + auto networkModifyGroup = GameActions::NetworkModifyGroupAction( + GameActions::ModifyGroupType::RemoveGroup, _selectedGroup); GameActions::Execute(&networkModifyGroup); break; } @@ -480,8 +481,8 @@ namespace OpenRCT2::Ui::Windows { case WIDX_DEFAULT_GROUP_DROPDOWN: { - auto networkModifyGroup = NetworkModifyGroupAction( - ModifyGroupType::SetDefault, NetworkGetGroupID(selectedIndex)); + auto networkModifyGroup = GameActions::NetworkModifyGroupAction( + GameActions::ModifyGroupType::SetDefault, NetworkGetGroupID(selectedIndex)); GameActions::Execute(&networkModifyGroup); break; } @@ -509,7 +510,8 @@ namespace OpenRCT2::Ui::Windows if (text.empty()) return; - auto networkModifyGroup = NetworkModifyGroupAction(ModifyGroupType::SetName, _selectedGroup, std::string(text)); + auto networkModifyGroup = GameActions::NetworkModifyGroupAction( + GameActions::ModifyGroupType::SetName, _selectedGroup, std::string(text)); GameActions::Execute(&networkModifyGroup); break; } @@ -634,8 +636,9 @@ namespace OpenRCT2::Ui::Windows selected_list_item = index; Invalidate(); - auto networkModifyGroup = NetworkModifyGroupAction( - ModifyGroupType::SetPermissions, _selectedGroup, "", index, PermissionState::Toggle); + auto networkModifyGroup = GameActions::NetworkModifyGroupAction( + GameActions::ModifyGroupType::SetPermissions, _selectedGroup, "", index, + GameActions::PermissionState::Toggle); GameActions::Execute(&networkModifyGroup); break; } diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index ef9e2f75dc..90cb0399ae 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -3700,7 +3700,7 @@ namespace OpenRCT2::Ui::Windows gDisableErrorWindowSound = true; - auto gameAction = MazeSetTrackAction( + auto gameAction = GameActions::MazeSetTrackAction( CoordsXYZD{ _currentTrackBegin, 0 }, true, _currentRideIndex, GC_SET_MAZE_TRACK_BUILD); auto mazeSetTrackResult = GameActions::Execute(&gameAction); if (mazeSetTrackResult.Error == GameActions::Status::Ok) @@ -4760,7 +4760,8 @@ namespace OpenRCT2::Ui::Windows if (rtd.specialType == RtdSpecialType::maze) { int32_t flags = GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_NO_SPEND | GAME_COMMAND_FLAG_GHOST; - auto gameAction = MazeSetTrackAction(CoordsXYZD{ trackPos, 0 }, true, rideIndex, GC_SET_MAZE_TRACK_BUILD); + auto gameAction = GameActions::MazeSetTrackAction( + CoordsXYZD{ trackPos, 0 }, true, rideIndex, GC_SET_MAZE_TRACK_BUILD); gameAction.SetFlags(flags); auto result = GameActions::Execute(&gameAction); @@ -5148,7 +5149,7 @@ namespace OpenRCT2::Ui::Windows }; for (const auto& quadrant : quadrants) { - auto gameAction = MazeSetTrackAction(quadrant, false, rideIndex, GC_SET_MAZE_TRACK_FILL); + auto gameAction = GameActions::MazeSetTrackAction(quadrant, false, rideIndex, GC_SET_MAZE_TRACK_FILL); gameAction.SetFlags(flags); auto res = GameActions::Execute(&gameAction); } diff --git a/src/openrct2-ui/windows/TitleMenu.cpp b/src/openrct2-ui/windows/TitleMenu.cpp index fdb613b1e6..4335f535c9 100644 --- a/src/openrct2-ui/windows/TitleMenu.cpp +++ b/src/openrct2-ui/windows/TitleMenu.cpp @@ -147,7 +147,7 @@ namespace OpenRCT2::Ui::Windows { windowMgr->CloseByClass(WindowClass::ScenarioSelect); windowMgr->CloseByClass(WindowClass::ServerList); - auto loadOrQuitAction = LoadOrQuitAction(LoadOrQuitModes::OpenSavePrompt); + auto loadOrQuitAction = GameActions::LoadOrQuitAction(GameActions::LoadOrQuitModes::OpenSavePrompt); GameActions::Execute(&loadOrQuitAction); } break; diff --git a/src/openrct2-ui/windows/TopToolbar.cpp b/src/openrct2-ui/windows/TopToolbar.cpp index b2de30d6d4..fe86919f34 100644 --- a/src/openrct2-ui/windows/TopToolbar.cpp +++ b/src/openrct2-ui/windows/TopToolbar.cpp @@ -444,14 +444,14 @@ namespace OpenRCT2::Ui::Windows { case DDIDX_NEW_GAME: { - auto loadOrQuitAction = LoadOrQuitAction( - LoadOrQuitModes::OpenSavePrompt, PromptMode::saveBeforeNewGame); + auto loadOrQuitAction = GameActions::LoadOrQuitAction( + GameActions::LoadOrQuitModes::OpenSavePrompt, PromptMode::saveBeforeNewGame); GameActions::Execute(&loadOrQuitAction); break; } case DDIDX_LOAD_GAME: { - auto loadOrQuitAction = LoadOrQuitAction(LoadOrQuitModes::OpenSavePrompt); + auto loadOrQuitAction = GameActions::LoadOrQuitAction(GameActions::LoadOrQuitModes::OpenSavePrompt); GameActions::Execute(&loadOrQuitAction); break; } @@ -504,8 +504,8 @@ namespace OpenRCT2::Ui::Windows auto* windowMgr = Ui::GetWindowManager(); windowMgr->CloseByClass(WindowClass::ManageTrackDesign); windowMgr->CloseByClass(WindowClass::TrackDeletePrompt); - auto loadOrQuitAction = LoadOrQuitAction( - LoadOrQuitModes::OpenSavePrompt, PromptMode::saveBeforeQuit); + auto loadOrQuitAction = GameActions::LoadOrQuitAction( + GameActions::LoadOrQuitModes::OpenSavePrompt, PromptMode::saveBeforeQuit); GameActions::Execute(&loadOrQuitAction); break; } diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index d029fd5a4f..1966249527 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -655,7 +655,7 @@ void GameLoadOrQuitNoSavePrompt() { case PromptMode::saveBeforeLoad: { - auto loadOrQuitAction = LoadOrQuitAction(LoadOrQuitModes::CloseSavePrompt); + auto loadOrQuitAction = GameActions::LoadOrQuitAction(GameActions::LoadOrQuitModes::CloseSavePrompt); GameActions::Execute(&loadOrQuitAction); ToolCancel(); if (gLegacyScene == LegacyScene::scenarioEditor) @@ -674,7 +674,7 @@ void GameLoadOrQuitNoSavePrompt() } case PromptMode::saveBeforeQuit: { - auto loadOrQuitAction = LoadOrQuitAction(LoadOrQuitModes::CloseSavePrompt); + auto loadOrQuitAction = GameActions::LoadOrQuitAction(GameActions::LoadOrQuitModes::CloseSavePrompt); GameActions::Execute(&loadOrQuitAction); ToolCancel(); if (gInputFlags.has(InputFlag::unk5)) @@ -692,7 +692,7 @@ void GameLoadOrQuitNoSavePrompt() } case PromptMode::saveBeforeNewGame: { - auto loadOrQuitAction = LoadOrQuitAction(LoadOrQuitModes::CloseSavePrompt); + auto loadOrQuitAction = GameActions::LoadOrQuitAction(GameActions::LoadOrQuitModes::CloseSavePrompt); GameActions::Execute(&loadOrQuitAction); ToolCancel(); auto intent = Intent(WindowClass::ScenarioSelect); diff --git a/src/openrct2/actions/LoadOrQuitAction.cpp b/src/openrct2/actions/LoadOrQuitAction.cpp index e45fbdd81c..fe5ce0ac44 100644 --- a/src/openrct2/actions/LoadOrQuitAction.cpp +++ b/src/openrct2/actions/LoadOrQuitAction.cpp @@ -13,55 +13,56 @@ #include "../OpenRCT2.h" #include "../ui/WindowManager.h" -using namespace OpenRCT2; - -LoadOrQuitAction::LoadOrQuitAction(LoadOrQuitModes mode, PromptMode savePromptMode) - : _mode(mode) - , _savePromptMode(savePromptMode) +namespace OpenRCT2::GameActions { -} - -void LoadOrQuitAction::AcceptParameters(GameActionParameterVisitor& visitor) -{ - visitor.Visit("mode", _mode); - visitor.Visit("savePromptMode", _savePromptMode); -} - -uint16_t LoadOrQuitAction::GetActionFlags() const -{ - return GameAction::GetActionFlags() | GameActions::Flags::ClientOnly | GameActions::Flags::AllowWhilePaused; -} - -void LoadOrQuitAction::Serialise(DataSerialiser& stream) -{ - GameAction::Serialise(stream); - - stream << DS_TAG(_mode) << DS_TAG(_savePromptMode); -} - -GameActions::Result LoadOrQuitAction::Query() const -{ - return GameActions::Result(); -} - -GameActions::Result LoadOrQuitAction::Execute() const -{ - auto mode = static_cast(_mode); - switch (mode) + LoadOrQuitAction::LoadOrQuitAction(LoadOrQuitModes mode, PromptMode savePromptMode) + : _mode(mode) + , _savePromptMode(savePromptMode) { - case LoadOrQuitModes::OpenSavePrompt: - gSavePromptMode = _savePromptMode; - ContextOpenWindow(WindowClass::SavePrompt); - break; - case LoadOrQuitModes::CloseSavePrompt: - { - auto* windowMgr = Ui::GetWindowManager(); - windowMgr->CloseByClass(WindowClass::SavePrompt); - break; - } - default: - GameLoadOrQuitNoSavePrompt(); - break; } - return GameActions::Result(); -} + + void LoadOrQuitAction::AcceptParameters(GameActionParameterVisitor& visitor) + { + visitor.Visit("mode", _mode); + visitor.Visit("savePromptMode", _savePromptMode); + } + + uint16_t LoadOrQuitAction::GetActionFlags() const + { + return GameAction::GetActionFlags() | Flags::ClientOnly | Flags::AllowWhilePaused; + } + + void LoadOrQuitAction::Serialise(DataSerialiser& stream) + { + GameAction::Serialise(stream); + + stream << DS_TAG(_mode) << DS_TAG(_savePromptMode); + } + + Result LoadOrQuitAction::Query() const + { + return Result(); + } + + Result LoadOrQuitAction::Execute() const + { + auto mode = static_cast(_mode); + switch (mode) + { + case LoadOrQuitModes::OpenSavePrompt: + gSavePromptMode = _savePromptMode; + ContextOpenWindow(WindowClass::SavePrompt); + break; + case LoadOrQuitModes::CloseSavePrompt: + { + auto* windowMgr = Ui::GetWindowManager(); + windowMgr->CloseByClass(WindowClass::SavePrompt); + break; + } + default: + GameLoadOrQuitNoSavePrompt(); + break; + } + return Result(); + } +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/LoadOrQuitAction.h b/src/openrct2/actions/LoadOrQuitAction.h index 90bf913ff1..611cd9261e 100644 --- a/src/openrct2/actions/LoadOrQuitAction.h +++ b/src/openrct2/actions/LoadOrQuitAction.h @@ -12,27 +12,30 @@ #include "../interface/Window.h" #include "GameAction.h" -enum class LoadOrQuitModes : uint8_t +namespace OpenRCT2::GameActions { - OpenSavePrompt, - CloseSavePrompt -}; + enum class LoadOrQuitModes : uint8_t + { + OpenSavePrompt, + CloseSavePrompt + }; -class LoadOrQuitAction final : public GameActionBase -{ -private: - LoadOrQuitModes _mode{}; - PromptMode _savePromptMode{ PromptMode::saveBeforeLoad }; + class LoadOrQuitAction final : public GameActionBase + { + private: + LoadOrQuitModes _mode{}; + PromptMode _savePromptMode{ PromptMode::saveBeforeLoad }; -public: - LoadOrQuitAction() = default; - LoadOrQuitAction(LoadOrQuitModes mode, PromptMode savePromptMode = PromptMode::saveBeforeLoad); + public: + LoadOrQuitAction() = default; + LoadOrQuitAction(LoadOrQuitModes mode, PromptMode savePromptMode = PromptMode::saveBeforeLoad); - 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/MapChangeSizeAction.cpp b/src/openrct2/actions/MapChangeSizeAction.cpp index ed60cbf00a..8f26677725 100644 --- a/src/openrct2/actions/MapChangeSizeAction.cpp +++ b/src/openrct2/actions/MapChangeSizeAction.cpp @@ -17,85 +17,84 @@ #include "../windows/Intent.h" #include "../world/Park.h" -using namespace OpenRCT2; - -MapChangeSizeAction::MapChangeSizeAction(const TileCoordsXY& targetSize) - : MapChangeSizeAction(targetSize, TileCoordsXY()) +namespace OpenRCT2::GameActions { -} - -MapChangeSizeAction::MapChangeSizeAction(const TileCoordsXY& targetSize, const TileCoordsXY& shift) - : _targetSize(targetSize) - , _shift(shift) -{ -} - -uint16_t MapChangeSizeAction::GetActionFlags() const -{ - return GameAction::GetActionFlags() | GameActions::Flags::AllowWhilePaused; -} - -void MapChangeSizeAction::Serialise(DataSerialiser& stream) -{ - GameAction::Serialise(stream); - stream << DS_TAG(_targetSize); - stream << DS_TAG(_shift); -} - -GameActions::Result MapChangeSizeAction::Query() const -{ - if (_targetSize.x > kMaximumMapSizeTechnical || _targetSize.y > kMaximumMapSizeTechnical) + MapChangeSizeAction::MapChangeSizeAction(const TileCoordsXY& targetSize) + : MapChangeSizeAction(targetSize, TileCoordsXY()) { - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_INCREASE_MAP_SIZE_ANY_FURTHER, STR_ERR_VALUE_OUT_OF_RANGE); - } - if (_targetSize.x < kMinimumMapSizeTechnical || _targetSize.y < kMinimumMapSizeTechnical) - { - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_DECREASE_MAP_SIZE_ANY_FURTHER, STR_ERR_VALUE_OUT_OF_RANGE); - } - return GameActions::Result(); -} - -GameActions::Result MapChangeSizeAction::Execute() const -{ - auto& gameState = getGameState(); - // Expand map - while (_targetSize.x > gameState.mapSize.x) - { - gameState.mapSize.x++; - MapExtendBoundarySurfaceX(); - } - while (_targetSize.y > gameState.mapSize.y) - { - gameState.mapSize.y++; - MapExtendBoundarySurfaceY(); } - // Shift the map (allows increasing the map at the 0,0 position - ShiftMap(_shift); - - // Shrink map - if (_targetSize.x < gameState.mapSize.x || _targetSize.y < gameState.mapSize.y) + MapChangeSizeAction::MapChangeSizeAction(const TileCoordsXY& targetSize, const TileCoordsXY& shift) + : _targetSize(targetSize) + , _shift(shift) { - gameState.mapSize = _targetSize; - MapRemoveOutOfRangeElements(); } - auto* ctx = OpenRCT2::GetContext(); - auto& uiContext = ctx->GetUiContext(); - auto* windowManager = uiContext.GetWindowManager(); - OpenRCT2::Park::UpdateSize(gameState); + uint16_t MapChangeSizeAction::GetActionFlags() const + { + return GameAction::GetActionFlags() | Flags::AllowWhilePaused; + } - windowManager->BroadcastIntent(Intent(INTENT_ACTION_MAP)); - GfxInvalidateScreen(); - return GameActions::Result(); -} + void MapChangeSizeAction::Serialise(DataSerialiser& stream) + { + GameAction::Serialise(stream); + stream << DS_TAG(_targetSize); + stream << DS_TAG(_shift); + } -void MapChangeSizeAction::AcceptParameters(GameActionParameterVisitor& visitor) -{ - visitor.Visit("targetSizeX", _targetSize.x); - visitor.Visit("targetSizeY", _targetSize.y); - visitor.Visit("shiftX", _shift.x); - visitor.Visit("shiftY", _shift.y); -} + Result MapChangeSizeAction::Query() const + { + if (_targetSize.x > kMaximumMapSizeTechnical || _targetSize.y > kMaximumMapSizeTechnical) + { + return Result(Status::InvalidParameters, STR_CANT_INCREASE_MAP_SIZE_ANY_FURTHER, STR_ERR_VALUE_OUT_OF_RANGE); + } + if (_targetSize.x < kMinimumMapSizeTechnical || _targetSize.y < kMinimumMapSizeTechnical) + { + return Result(Status::InvalidParameters, STR_CANT_DECREASE_MAP_SIZE_ANY_FURTHER, STR_ERR_VALUE_OUT_OF_RANGE); + } + return Result(); + } + + Result MapChangeSizeAction::Execute() const + { + auto& gameState = getGameState(); + // Expand map + while (_targetSize.x > gameState.mapSize.x) + { + gameState.mapSize.x++; + MapExtendBoundarySurfaceX(); + } + while (_targetSize.y > gameState.mapSize.y) + { + gameState.mapSize.y++; + MapExtendBoundarySurfaceY(); + } + + // Shift the map (allows increasing the map at the 0,0 position + ShiftMap(_shift); + + // Shrink map + if (_targetSize.x < gameState.mapSize.x || _targetSize.y < gameState.mapSize.y) + { + gameState.mapSize = _targetSize; + MapRemoveOutOfRangeElements(); + } + + auto* ctx = OpenRCT2::GetContext(); + auto& uiContext = ctx->GetUiContext(); + auto* windowManager = uiContext.GetWindowManager(); + Park::UpdateSize(gameState); + + windowManager->BroadcastIntent(Intent(INTENT_ACTION_MAP)); + GfxInvalidateScreen(); + return Result(); + } + + void MapChangeSizeAction::AcceptParameters(GameActionParameterVisitor& visitor) + { + visitor.Visit("targetSizeX", _targetSize.x); + visitor.Visit("targetSizeY", _targetSize.y); + visitor.Visit("shiftX", _shift.x); + visitor.Visit("shiftY", _shift.y); + } +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/MapChangeSizeAction.h b/src/openrct2/actions/MapChangeSizeAction.h index 8c8d6a9944..5c8520c145 100644 --- a/src/openrct2/actions/MapChangeSizeAction.h +++ b/src/openrct2/actions/MapChangeSizeAction.h @@ -12,21 +12,24 @@ #include "../world/Map.h" #include "GameAction.h" -class MapChangeSizeAction final : public GameActionBase +namespace OpenRCT2::GameActions { -public: - MapChangeSizeAction() = default; - MapChangeSizeAction(const TileCoordsXY& targetSize); - MapChangeSizeAction(const TileCoordsXY& targetSize, const TileCoordsXY& shift); + class MapChangeSizeAction final : public GameActionBase + { + public: + MapChangeSizeAction() = default; + MapChangeSizeAction(const TileCoordsXY& targetSize); + MapChangeSizeAction(const TileCoordsXY& targetSize, const TileCoordsXY& shift); - void AcceptParameters(GameActionParameterVisitor& visitor) override; - uint16_t GetActionFlags() const override; + void AcceptParameters(GameActionParameterVisitor& visitor) override; + uint16_t GetActionFlags() const override; - void Serialise(DataSerialiser& stream) override; - OpenRCT2::GameActions::Result Query() const override; - OpenRCT2::GameActions::Result Execute() const override; + void Serialise(DataSerialiser& stream) override; + Result Query() const override; + Result Execute() const override; -private: - TileCoordsXY _targetSize; - TileCoordsXY _shift; -}; + private: + TileCoordsXY _targetSize; + TileCoordsXY _shift; + }; +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/MazePlaceTrackAction.cpp b/src/openrct2/actions/MazePlaceTrackAction.cpp index 3ee2f4638f..84d42a1a67 100644 --- a/src/openrct2/actions/MazePlaceTrackAction.cpp +++ b/src/openrct2/actions/MazePlaceTrackAction.cpp @@ -20,187 +20,188 @@ #include "../world/tile_element/SurfaceElement.h" #include "../world/tile_element/TrackElement.h" -using namespace OpenRCT2; - -using namespace OpenRCT2::TrackMetaData; - -MazePlaceTrackAction::MazePlaceTrackAction(const CoordsXYZ& location, RideId rideIndex, uint16_t mazeEntry) - : _loc(location) - , _rideIndex(rideIndex) - , _mazeEntry(mazeEntry) +namespace OpenRCT2::GameActions { -} + using namespace OpenRCT2::TrackMetaData; -void MazePlaceTrackAction::AcceptParameters(GameActionParameterVisitor& visitor) -{ - visitor.Visit(_loc); - visitor.Visit("ride", _rideIndex); - visitor.Visit("mazeEntry", _mazeEntry); -} - -void MazePlaceTrackAction::Serialise(DataSerialiser& stream) -{ - GameAction::Serialise(stream); - stream << DS_TAG(_loc) << DS_TAG(_rideIndex) << DS_TAG(_mazeEntry); -} - -GameActions::Result MazePlaceTrackAction::Query() const -{ - auto res = GameActions::Result(); - - res.Position = _loc + CoordsXYZ{ 8, 8, 0 }; - res.Expenditure = ExpenditureType::rideConstruction; - res.ErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE; - if ((_loc.z & 0xF) != 0) + MazePlaceTrackAction::MazePlaceTrackAction(const CoordsXYZ& location, RideId rideIndex, uint16_t mazeEntry) + : _loc(location) + , _rideIndex(rideIndex) + , _mazeEntry(mazeEntry) { - res.Error = GameActions::Status::Unknown; - res.ErrorMessage = STR_INVALID_HEIGHT; - return res; } - if (!LocationValid(_loc)) + void MazePlaceTrackAction::AcceptParameters(GameActionParameterVisitor& visitor) { - res.Error = GameActions::Status::InvalidParameters; - res.ErrorMessage = STR_OFF_EDGE_OF_MAP; - return res; - } - auto& gameState = getGameState(); - if (!MapIsLocationOwned(_loc) && !gameState.cheats.sandboxMode) - { - res.Error = GameActions::Status::NotOwned; - res.ErrorMessage = STR_LAND_NOT_OWNED_BY_PARK; - return res; + visitor.Visit(_loc); + visitor.Visit("ride", _rideIndex); + visitor.Visit("mazeEntry", _mazeEntry); } - if (!MapCheckCapacityAndReorganise(_loc)) + void MazePlaceTrackAction::Serialise(DataSerialiser& stream) { - res.Error = GameActions::Status::NoFreeElements; - res.ErrorMessage = STR_TILE_ELEMENT_LIMIT_REACHED; - return res; - } - auto surfaceElement = MapGetSurfaceElementAt(_loc); - if (surfaceElement == nullptr) - { - res.Error = GameActions::Status::Unknown; - res.ErrorMessage = STR_INVALID_SELECTION_OF_OBJECTS; - return res; + GameAction::Serialise(stream); + stream << DS_TAG(_loc) << DS_TAG(_rideIndex) << DS_TAG(_mazeEntry); } - auto baseHeight = _loc.z; - auto clearanceHeight = _loc.z + kMazeClearanceHeight; - - auto heightDifference = baseHeight - surfaceElement->GetBaseZ(); - if (heightDifference >= 0 && !gameState.cheats.disableSupportLimits) + Result MazePlaceTrackAction::Query() const { - heightDifference /= kCoordsZPerTinyZ; + auto res = Result(); - auto* ride = GetRide(_rideIndex); - const auto& rtd = ride->getRideTypeDescriptor(); - if (heightDifference > rtd.Heights.MaxHeight) + res.Position = _loc + CoordsXYZ{ 8, 8, 0 }; + res.Expenditure = ExpenditureType::rideConstruction; + res.ErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE; + if ((_loc.z & 0xF) != 0) { - res.Error = GameActions::Status::TooHigh; - res.ErrorMessage = STR_TOO_HIGH_FOR_SUPPORTS; + res.Error = Status::Unknown; + res.ErrorMessage = STR_INVALID_HEIGHT; return res; } - } - auto canBuild = MapCanConstructWithClearAt( - { _loc.ToTileStart(), baseHeight, clearanceHeight }, &MapPlaceNonSceneryClearFunc, { 0b1111, 0 }, GetFlags()); - if (canBuild.Error != GameActions::Status::Ok) - { - canBuild.ErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE; - return canBuild; - } + if (!LocationValid(_loc)) + { + res.Error = Status::InvalidParameters; + res.ErrorMessage = STR_OFF_EDGE_OF_MAP; + return res; + } + auto& gameState = getGameState(); + if (!MapIsLocationOwned(_loc) && !gameState.cheats.sandboxMode) + { + res.Error = Status::NotOwned; + res.ErrorMessage = STR_LAND_NOT_OWNED_BY_PARK; + return res; + } + + if (!MapCheckCapacityAndReorganise(_loc)) + { + res.Error = Status::NoFreeElements; + res.ErrorMessage = STR_TILE_ELEMENT_LIMIT_REACHED; + return res; + } + auto surfaceElement = MapGetSurfaceElementAt(_loc); + if (surfaceElement == nullptr) + { + res.Error = Status::Unknown; + res.ErrorMessage = STR_INVALID_SELECTION_OF_OBJECTS; + return res; + } + + auto baseHeight = _loc.z; + auto clearanceHeight = _loc.z + kMazeClearanceHeight; + + auto heightDifference = baseHeight - surfaceElement->GetBaseZ(); + if (heightDifference >= 0 && !gameState.cheats.disableSupportLimits) + { + heightDifference /= kCoordsZPerTinyZ; + + auto* ride = GetRide(_rideIndex); + const auto& rtd = ride->getRideTypeDescriptor(); + if (heightDifference > rtd.Heights.MaxHeight) + { + res.Error = Status::TooHigh; + res.ErrorMessage = STR_TOO_HIGH_FOR_SUPPORTS; + return res; + } + } + + auto canBuild = MapCanConstructWithClearAt( + { _loc.ToTileStart(), baseHeight, clearanceHeight }, &MapPlaceNonSceneryClearFunc, { 0b1111, 0 }, GetFlags()); + if (canBuild.Error != Status::Ok) + { + canBuild.ErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE; + return canBuild; + } + + const auto clearanceData = canBuild.GetData(); + if (clearanceData.GroundFlags & ELEMENT_IS_UNDERWATER) + { + res.Error = Status::NoClearance; + res.ErrorMessage = STR_RIDE_CANT_BUILD_THIS_UNDERWATER; + return res; + } + + if (clearanceData.GroundFlags & ELEMENT_IS_UNDERGROUND) + { + res.Error = Status::NoClearance; + res.ErrorMessage = STR_CAN_ONLY_BUILD_THIS_ABOVE_GROUND; + return res; + } + + auto ride = GetRide(_rideIndex); + if (ride == nullptr || ride->type == kRideTypeNull) + { + LOG_ERROR("Ride not found for rideIndex %u", _rideIndex); + res.Error = Status::InvalidParameters; + res.ErrorMessage = STR_ERR_RIDE_NOT_FOUND; + return res; + } + + res.Cost = MazeCalculateCost(canBuild.Cost, *ride, _loc); - const auto clearanceData = canBuild.GetData(); - if (clearanceData.GroundFlags & ELEMENT_IS_UNDERWATER) - { - res.Error = GameActions::Status::NoClearance; - res.ErrorMessage = STR_RIDE_CANT_BUILD_THIS_UNDERWATER; return res; } - if (clearanceData.GroundFlags & ELEMENT_IS_UNDERGROUND) + Result MazePlaceTrackAction::Execute() const { - res.Error = GameActions::Status::NoClearance; - res.ErrorMessage = STR_CAN_ONLY_BUILD_THIS_ABOVE_GROUND; + auto res = Result(); + + res.Position = _loc + CoordsXYZ{ 8, 8, 0 }; + res.Expenditure = ExpenditureType::rideConstruction; + res.ErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE; + + auto ride = GetRide(_rideIndex); + if (ride == nullptr) + { + LOG_ERROR("Ride not found for rideIndex %u", _rideIndex); + res.Error = Status::InvalidParameters; + res.ErrorMessage = STR_ERR_RIDE_NOT_FOUND; + return res; + } + + uint32_t flags = GetFlags(); + if (!(flags & GAME_COMMAND_FLAG_GHOST)) + { + FootpathRemoveLitter(_loc); + WallRemoveAt({ _loc.ToTileStart(), _loc.z, _loc.z + 32 }); + } + + auto baseHeight = _loc.z; + auto clearanceHeight = _loc.z + kMazeClearanceHeight; + + auto canBuild = MapCanConstructWithClearAt( + { _loc.ToTileStart(), baseHeight, clearanceHeight }, &MapPlaceNonSceneryClearFunc, { 0b1111, 0 }, + GetFlags() | GAME_COMMAND_FLAG_APPLY); + if (canBuild.Error != Status::Ok) + { + canBuild.ErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE; + return canBuild; + } + + res.Cost = MazeCalculateCost(canBuild.Cost, *ride, _loc); + + auto startLoc = _loc.ToTileStart(); + + auto* trackElement = TileElementInsert(_loc, 0b1111); + Guard::Assert(trackElement != nullptr); + + trackElement->SetClearanceZ(clearanceHeight); + trackElement->SetTrackType(TrackElemType::Maze); + trackElement->SetRideType(ride->type); + trackElement->SetRideIndex(_rideIndex); + trackElement->SetMazeEntry(_mazeEntry); + trackElement->SetGhost(flags & GAME_COMMAND_FLAG_GHOST); + + MapInvalidateTileFull(startLoc); + + ride->mazeTiles++; + ride->getStation().SetBaseZ(trackElement->GetBaseZ()); + ride->getStation().Start = { 0, 0 }; + + if (ride->mazeTiles == 1) + { + ride->overallView = startLoc; + } + return res; } - - auto ride = GetRide(_rideIndex); - if (ride == nullptr || ride->type == kRideTypeNull) - { - LOG_ERROR("Ride not found for rideIndex %u", _rideIndex); - res.Error = GameActions::Status::InvalidParameters; - res.ErrorMessage = STR_ERR_RIDE_NOT_FOUND; - return res; - } - - res.Cost = MazeCalculateCost(canBuild.Cost, *ride, _loc); - - return res; -} - -GameActions::Result MazePlaceTrackAction::Execute() const -{ - auto res = GameActions::Result(); - - res.Position = _loc + CoordsXYZ{ 8, 8, 0 }; - res.Expenditure = ExpenditureType::rideConstruction; - res.ErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE; - - auto ride = GetRide(_rideIndex); - if (ride == nullptr) - { - LOG_ERROR("Ride not found for rideIndex %u", _rideIndex); - res.Error = GameActions::Status::InvalidParameters; - res.ErrorMessage = STR_ERR_RIDE_NOT_FOUND; - return res; - } - - uint32_t flags = GetFlags(); - if (!(flags & GAME_COMMAND_FLAG_GHOST)) - { - FootpathRemoveLitter(_loc); - WallRemoveAt({ _loc.ToTileStart(), _loc.z, _loc.z + 32 }); - } - - auto baseHeight = _loc.z; - auto clearanceHeight = _loc.z + kMazeClearanceHeight; - - auto canBuild = MapCanConstructWithClearAt( - { _loc.ToTileStart(), baseHeight, clearanceHeight }, &MapPlaceNonSceneryClearFunc, { 0b1111, 0 }, - GetFlags() | GAME_COMMAND_FLAG_APPLY); - if (canBuild.Error != GameActions::Status::Ok) - { - canBuild.ErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE; - return canBuild; - } - - res.Cost = MazeCalculateCost(canBuild.Cost, *ride, _loc); - - auto startLoc = _loc.ToTileStart(); - - auto* trackElement = TileElementInsert(_loc, 0b1111); - Guard::Assert(trackElement != nullptr); - - trackElement->SetClearanceZ(clearanceHeight); - trackElement->SetTrackType(TrackElemType::Maze); - trackElement->SetRideType(ride->type); - trackElement->SetRideIndex(_rideIndex); - trackElement->SetMazeEntry(_mazeEntry); - trackElement->SetGhost(flags & GAME_COMMAND_FLAG_GHOST); - - MapInvalidateTileFull(startLoc); - - ride->mazeTiles++; - ride->getStation().SetBaseZ(trackElement->GetBaseZ()); - ride->getStation().Start = { 0, 0 }; - - if (ride->mazeTiles == 1) - { - ride->overallView = startLoc; - } - - return res; -} +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/MazePlaceTrackAction.h b/src/openrct2/actions/MazePlaceTrackAction.h index 0efbc3e634..b2bb6086c5 100644 --- a/src/openrct2/actions/MazePlaceTrackAction.h +++ b/src/openrct2/actions/MazePlaceTrackAction.h @@ -6,23 +6,27 @@ * * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ + #pragma once #include "GameAction.h" -class MazePlaceTrackAction final : public GameActionBase +namespace OpenRCT2::GameActions { -private: - CoordsXYZ _loc; - RideId _rideIndex{ RideId::GetNull() }; - uint16_t _mazeEntry{}; + class MazePlaceTrackAction final : public GameActionBase + { + private: + CoordsXYZ _loc; + RideId _rideIndex{ RideId::GetNull() }; + uint16_t _mazeEntry{}; -public: - MazePlaceTrackAction() = default; - MazePlaceTrackAction(const CoordsXYZ& location, RideId rideIndex, uint16_t mazeEntry); + public: + MazePlaceTrackAction() = default; + MazePlaceTrackAction(const CoordsXYZ& location, RideId rideIndex, uint16_t mazeEntry); - 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; + }; +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/MazeSetTrackAction.cpp b/src/openrct2/actions/MazeSetTrackAction.cpp index 0b82b3df99..ee29f25876 100644 --- a/src/openrct2/actions/MazeSetTrackAction.cpp +++ b/src/openrct2/actions/MazeSetTrackAction.cpp @@ -26,339 +26,341 @@ #include "../world/tile_element/SurfaceElement.h" #include "../world/tile_element/TrackElement.h" -using namespace OpenRCT2; - -using namespace OpenRCT2::TrackMetaData; - -// clang-format off -/** rct2: 0x00993CE9 */ -static constexpr uint8_t kByte993CE9[] = { - 0xFF, 0xE0, 0xFF, - 14, 0, 1, 2, - 6, 2, 4, 5, - 9, 10, 6, 8, - 12, 13, 14, 10, -}; - -/** rct2: 0x00993CFC */ -static constexpr uint8_t kByte993CFC[] = { - 5, 12, 0xFF, 0xFF, - 9, 0, 0xFF, 0xFF, - 13, 4, 0xFF, 0xFF, - 1, 8, 0xFF, 0xFF, -}; - -/** rct2: 0x00993D0C */ -static constexpr uint8_t kByte993D0C[] = { - 3, 0, 0xFF, 0xFF, - 0, 1, 0xFF, 0xFF, - 1, 2, 0xFF, 0xFF, - 2, 3, 0xFF, 0xFF, -}; -// clang-format on - -MazeSetTrackAction::MazeSetTrackAction(const CoordsXYZD& location, bool initialPlacement, RideId rideIndex, uint8_t mode) - : _loc(location) - , _initialPlacement(initialPlacement) - , _rideIndex(rideIndex) - , _mode(mode) +namespace OpenRCT2::GameActions { -} + using namespace OpenRCT2::TrackMetaData; -void MazeSetTrackAction::AcceptParameters(GameActionParameterVisitor& visitor) -{ - visitor.Visit(_loc); - visitor.Visit("ride", _rideIndex); - visitor.Visit("mode", _mode); - visitor.Visit("isInitialPlacement", _initialPlacement); -} + // clang-format off + /** rct2: 0x00993CE9 */ + static constexpr uint8_t kByte993CE9[] = { + 0xFF, 0xE0, 0xFF, + 14, 0, 1, 2, + 6, 2, 4, 5, + 9, 10, 6, 8, + 12, 13, 14, 10, + }; -void MazeSetTrackAction::Serialise(DataSerialiser& stream) -{ - GameAction::Serialise(stream); - stream << DS_TAG(_loc) << DS_TAG(_loc.direction) << DS_TAG(_initialPlacement) << DS_TAG(_rideIndex) << DS_TAG(_mode); -} + /** rct2: 0x00993CFC */ + static constexpr uint8_t kByte993CFC[] = { + 5, 12, 0xFF, 0xFF, + 9, 0, 0xFF, 0xFF, + 13, 4, 0xFF, 0xFF, + 1, 8, 0xFF, 0xFF, + }; -GameActions::Result MazeSetTrackAction::Query() const -{ - auto res = GameActions::Result(); + /** rct2: 0x00993D0C */ + static constexpr uint8_t kByte993D0C[] = { + 3, 0, 0xFF, 0xFF, + 0, 1, 0xFF, 0xFF, + 1, 2, 0xFF, 0xFF, + 2, 3, 0xFF, 0xFF, + }; + // clang-format on - res.Position = _loc + CoordsXYZ{ 8, 8, 0 }; - res.Expenditure = ExpenditureType::rideConstruction; - res.ErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE; - if ((_loc.z & 0xF) != 0 && _mode == GC_SET_MAZE_TRACK_BUILD) + MazeSetTrackAction::MazeSetTrackAction(const CoordsXYZD& location, bool initialPlacement, RideId rideIndex, uint8_t mode) + : _loc(location) + , _initialPlacement(initialPlacement) + , _rideIndex(rideIndex) + , _mode(mode) { - res.Error = GameActions::Status::Unknown; - res.ErrorMessage = STR_INVALID_HEIGHT; - return res; } - if (!LocationValid(_loc)) + void MazeSetTrackAction::AcceptParameters(GameActionParameterVisitor& visitor) { - res.Error = GameActions::Status::InvalidParameters; - res.ErrorMessage = STR_OFF_EDGE_OF_MAP; - return res; - } - auto& gameState = getGameState(); - if (!MapIsLocationOwned(_loc) && !gameState.cheats.sandboxMode) - { - res.Error = GameActions::Status::NotOwned; - res.ErrorMessage = STR_LAND_NOT_OWNED_BY_PARK; - return res; + visitor.Visit(_loc); + visitor.Visit("ride", _rideIndex); + visitor.Visit("mode", _mode); + visitor.Visit("isInitialPlacement", _initialPlacement); } - if (!MapCheckCapacityAndReorganise(_loc)) + void MazeSetTrackAction::Serialise(DataSerialiser& stream) { - res.Error = GameActions::Status::NoFreeElements; - res.ErrorMessage = STR_TILE_ELEMENT_LIMIT_REACHED; - return res; - } - auto surfaceElement = MapGetSurfaceElementAt(_loc); - if (surfaceElement == nullptr) - { - res.Error = GameActions::Status::Unknown; - res.ErrorMessage = STR_INVALID_SELECTION_OF_OBJECTS; - return res; + GameAction::Serialise(stream); + stream << DS_TAG(_loc) << DS_TAG(_loc.direction) << DS_TAG(_initialPlacement) << DS_TAG(_rideIndex) << DS_TAG(_mode); } - auto baseHeight = _loc.z; - auto clearanceHeight = _loc.z + 32; - - auto heightDifference = baseHeight - surfaceElement->GetBaseZ(); - if (heightDifference >= 0 && !gameState.cheats.disableSupportLimits) + Result MazeSetTrackAction::Query() const { - heightDifference /= kCoordsZPerTinyZ; + auto res = Result(); - auto* ride = GetRide(_rideIndex); - const auto& rtd = ride->getRideTypeDescriptor(); - if (heightDifference > rtd.Heights.MaxHeight) + res.Position = _loc + CoordsXYZ{ 8, 8, 0 }; + res.Expenditure = ExpenditureType::rideConstruction; + res.ErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE; + if ((_loc.z & 0xF) != 0 && _mode == GC_SET_MAZE_TRACK_BUILD) { - res.Error = GameActions::Status::TooHigh; - res.ErrorMessage = STR_TOO_HIGH_FOR_SUPPORTS; + res.Error = Status::Unknown; + res.ErrorMessage = STR_INVALID_HEIGHT; return res; } - } - TileElement* tileElement = MapGetTrackElementAtOfTypeFromRide(_loc, TrackElemType::Maze, _rideIndex); - if (tileElement == nullptr) - { - if (_mode != GC_SET_MAZE_TRACK_BUILD) + if (!LocationValid(_loc)) { - res.Error = GameActions::Status::Unknown; + res.Error = Status::InvalidParameters; + res.ErrorMessage = STR_OFF_EDGE_OF_MAP; + return res; + } + auto& gameState = getGameState(); + if (!MapIsLocationOwned(_loc) && !gameState.cheats.sandboxMode) + { + res.Error = Status::NotOwned; + res.ErrorMessage = STR_LAND_NOT_OWNED_BY_PARK; + return res; + } + + if (!MapCheckCapacityAndReorganise(_loc)) + { + res.Error = Status::NoFreeElements; + res.ErrorMessage = STR_TILE_ELEMENT_LIMIT_REACHED; + return res; + } + auto surfaceElement = MapGetSurfaceElementAt(_loc); + if (surfaceElement == nullptr) + { + res.Error = Status::Unknown; res.ErrorMessage = STR_INVALID_SELECTION_OF_OBJECTS; return res; } - auto constructResult = MapCanConstructAt({ _loc.ToTileStart(), baseHeight, clearanceHeight }, { 0b1111, 0 }); - if (constructResult.Error != GameActions::Status::Ok) + + auto baseHeight = _loc.z; + auto clearanceHeight = _loc.z + 32; + + auto heightDifference = baseHeight - surfaceElement->GetBaseZ(); + if (heightDifference >= 0 && !gameState.cheats.disableSupportLimits) { - constructResult.ErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE; - return constructResult; + heightDifference /= kCoordsZPerTinyZ; + + auto* ride = GetRide(_rideIndex); + const auto& rtd = ride->getRideTypeDescriptor(); + if (heightDifference > rtd.Heights.MaxHeight) + { + res.Error = Status::TooHigh; + res.ErrorMessage = STR_TOO_HIGH_FOR_SUPPORTS; + return res; + } } - const auto clearanceData = constructResult.GetData(); - if (clearanceData.GroundFlags & ELEMENT_IS_UNDERWATER) + TileElement* tileElement = MapGetTrackElementAtOfTypeFromRide(_loc, TrackElemType::Maze, _rideIndex); + if (tileElement == nullptr) { - res.Error = GameActions::Status::NoClearance; - res.ErrorMessage = STR_RIDE_CANT_BUILD_THIS_UNDERWATER; + if (_mode != GC_SET_MAZE_TRACK_BUILD) + { + res.Error = Status::Unknown; + res.ErrorMessage = STR_INVALID_SELECTION_OF_OBJECTS; + return res; + } + auto constructResult = MapCanConstructAt({ _loc.ToTileStart(), baseHeight, clearanceHeight }, { 0b1111, 0 }); + if (constructResult.Error != Status::Ok) + { + constructResult.ErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE; + return constructResult; + } + + const auto clearanceData = constructResult.GetData(); + if (clearanceData.GroundFlags & ELEMENT_IS_UNDERWATER) + { + res.Error = Status::NoClearance; + res.ErrorMessage = STR_RIDE_CANT_BUILD_THIS_UNDERWATER; + return res; + } + + if (clearanceData.GroundFlags & ELEMENT_IS_UNDERGROUND) + { + res.Error = Status::NoClearance; + res.ErrorMessage = STR_CAN_ONLY_BUILD_THIS_ABOVE_GROUND; + return res; + } + + auto ride = GetRide(_rideIndex); + if (ride == nullptr || !RideTypeIsValid(ride->type)) + { + LOG_ERROR("Ride not found for rideIndex %u", _rideIndex); + res.Error = Status::NoClearance; + res.ErrorMessage = STR_ERR_RIDE_NOT_FOUND; + return res; + } + + res.Cost = MazeCalculateCost(constructResult.Cost, *ride, _loc); + return res; } - if (clearanceData.GroundFlags & ELEMENT_IS_UNDERGROUND) - { - res.Error = GameActions::Status::NoClearance; - res.ErrorMessage = STR_CAN_ONLY_BUILD_THIS_ABOVE_GROUND; - return res; - } + return Result(); + } + + Result MazeSetTrackAction::Execute() const + { + auto res = Result(); + + res.Position = _loc + CoordsXYZ{ 8, 8, 0 }; + res.Expenditure = ExpenditureType::rideConstruction; + res.ErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE; auto ride = GetRide(_rideIndex); - if (ride == nullptr || !RideTypeIsValid(ride->type)) + if (ride == nullptr) { LOG_ERROR("Ride not found for rideIndex %u", _rideIndex); - res.Error = GameActions::Status::NoClearance; + res.Error = Status::InvalidParameters; res.ErrorMessage = STR_ERR_RIDE_NOT_FOUND; return res; } - res.Cost = MazeCalculateCost(constructResult.Cost, *ride, _loc); - - return res; - } - - return GameActions::Result(); -} - -GameActions::Result MazeSetTrackAction::Execute() const -{ - auto res = GameActions::Result(); - - res.Position = _loc + CoordsXYZ{ 8, 8, 0 }; - res.Expenditure = ExpenditureType::rideConstruction; - res.ErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE; - - auto ride = GetRide(_rideIndex); - if (ride == nullptr) - { - LOG_ERROR("Ride not found for rideIndex %u", _rideIndex); - res.Error = GameActions::Status::InvalidParameters; - res.ErrorMessage = STR_ERR_RIDE_NOT_FOUND; - return res; - } - - uint32_t flags = GetFlags(); - if (!(flags & GAME_COMMAND_FLAG_GHOST)) - { - FootpathRemoveLitter(_loc); - WallRemoveAt({ _loc.ToTileStart(), _loc.z, _loc.z + 32 }); - } - - auto tileElement = MapGetTrackElementAtOfTypeFromRide(_loc, TrackElemType::Maze, _rideIndex); - if (tileElement == nullptr) - { - res.Cost = MazeCalculateCost(0, *ride, _loc); - - auto startLoc = _loc.ToTileStart(); - - auto* trackElement = TileElementInsert(_loc, 0b1111); - Guard::Assert(trackElement != nullptr); - - trackElement->SetClearanceZ(_loc.z + kMazeClearanceHeight); - trackElement->SetTrackType(TrackElemType::Maze); - trackElement->SetRideType(ride->type); - trackElement->SetRideIndex(_rideIndex); - trackElement->SetMazeEntry(0xFFFF); - trackElement->SetGhost(flags & GAME_COMMAND_FLAG_GHOST); - - tileElement = trackElement->as(); - - MapInvalidateTileFull(startLoc); - - ride->mazeTiles++; - ride->getStation().SetBaseZ(tileElement->GetBaseZ()); - ride->getStation().Start = { 0, 0 }; - - if (_initialPlacement && !(flags & GAME_COMMAND_FLAG_GHOST)) + uint32_t flags = GetFlags(); + if (!(flags & GAME_COMMAND_FLAG_GHOST)) { - ride->overallView = startLoc; + FootpathRemoveLitter(_loc); + WallRemoveAt({ _loc.ToTileStart(), _loc.z, _loc.z + 32 }); } - } - switch (_mode) - { - case GC_SET_MAZE_TRACK_BUILD: + auto tileElement = MapGetTrackElementAtOfTypeFromRide(_loc, TrackElemType::Maze, _rideIndex); + if (tileElement == nullptr) { - uint8_t segmentOffset = MazeGetSegmentBit(_loc); + res.Cost = MazeCalculateCost(0, *ride, _loc); - tileElement->AsTrack()->MazeEntrySubtract(1 << segmentOffset); + auto startLoc = _loc.ToTileStart(); - if (!_initialPlacement) + auto* trackElement = TileElementInsert(_loc, 0b1111); + Guard::Assert(trackElement != nullptr); + + trackElement->SetClearanceZ(_loc.z + kMazeClearanceHeight); + trackElement->SetTrackType(TrackElemType::Maze); + trackElement->SetRideType(ride->type); + trackElement->SetRideIndex(_rideIndex); + trackElement->SetMazeEntry(0xFFFF); + trackElement->SetGhost(flags & GAME_COMMAND_FLAG_GHOST); + + tileElement = trackElement->as(); + + MapInvalidateTileFull(startLoc); + + ride->mazeTiles++; + ride->getStation().SetBaseZ(tileElement->GetBaseZ()); + ride->getStation().Start = { 0, 0 }; + + if (_initialPlacement && !(flags & GAME_COMMAND_FLAG_GHOST)) { - segmentOffset = kByte993CE9[(_loc.direction + segmentOffset)]; + ride->overallView = startLoc; + } + } + + switch (_mode) + { + case GC_SET_MAZE_TRACK_BUILD: + { + uint8_t segmentOffset = MazeGetSegmentBit(_loc); + tileElement->AsTrack()->MazeEntrySubtract(1 << segmentOffset); - uint8_t temp_edx = kByte993CFC[segmentOffset]; - if (temp_edx != 0xFF) + if (!_initialPlacement) { - auto previousElementLoc = CoordsXY{ _loc }.ToTileStart() - CoordsDirectionDelta[_loc.direction]; + segmentOffset = kByte993CE9[(_loc.direction + segmentOffset)]; + tileElement->AsTrack()->MazeEntrySubtract(1 << segmentOffset); - TileElement* previousTileElement = MapGetTrackElementAtOfTypeFromRide( - { previousElementLoc, _loc.z }, TrackElemType::Maze, _rideIndex); + uint8_t temp_edx = kByte993CFC[segmentOffset]; + if (temp_edx != 0xFF) + { + auto previousElementLoc = CoordsXY{ _loc }.ToTileStart() - CoordsDirectionDelta[_loc.direction]; - if (previousTileElement != nullptr) - { - previousTileElement->AsTrack()->MazeEntrySubtract(1 << temp_edx); - } - else - { - tileElement->AsTrack()->MazeEntryAdd(1 << segmentOffset); + TileElement* previousTileElement = MapGetTrackElementAtOfTypeFromRide( + { previousElementLoc, _loc.z }, TrackElemType::Maze, _rideIndex); + + if (previousTileElement != nullptr) + { + previousTileElement->AsTrack()->MazeEntrySubtract(1 << temp_edx); + } + else + { + tileElement->AsTrack()->MazeEntryAdd(1 << segmentOffset); + } } } + + break; } - break; + case GC_SET_MAZE_TRACK_MOVE: + break; + + case GC_SET_MAZE_TRACK_FILL: + if (!_initialPlacement) + { + auto previousSegment = CoordsXY{ _loc.x - CoordsDirectionDelta[_loc.direction].x / 2, + _loc.y - CoordsDirectionDelta[_loc.direction].y / 2 }; + + tileElement = MapGetTrackElementAtOfTypeFromRide( + { previousSegment, _loc.z }, TrackElemType::Maze, _rideIndex); + + MapInvalidateTileFull(previousSegment.ToTileStart()); + if (tileElement == nullptr) + { + LOG_ERROR("No surface found"); + res.Error = Status::Unknown; + res.ErrorMessage = STR_ERR_SURFACE_ELEMENT_NOT_FOUND; + return res; + } + + uint32_t segmentBit = MazeGetSegmentBit(previousSegment); + + tileElement->AsTrack()->MazeEntryAdd(1 << segmentBit); + segmentBit--; + tileElement->AsTrack()->MazeEntryAdd(1 << segmentBit); + segmentBit = (segmentBit - 4) & 0x0F; + tileElement->AsTrack()->MazeEntryAdd(1 << segmentBit); + segmentBit = (segmentBit + 3) & 0x0F; + + do + { + tileElement->AsTrack()->MazeEntryAdd(1 << segmentBit); + + uint32_t direction1 = kByte993D0C[segmentBit]; + auto nextElementLoc = previousSegment.ToTileStart() + CoordsDirectionDelta[direction1]; + + TileElement* tmp_tileElement = MapGetTrackElementAtOfTypeFromRide( + { nextElementLoc, _loc.z }, TrackElemType::Maze, _rideIndex); + + if (tmp_tileElement != nullptr) + { + uint8_t edx11 = kByte993CFC[segmentBit]; + tmp_tileElement->AsTrack()->MazeEntryAdd(1 << (edx11)); + } + + segmentBit--; + } while ((segmentBit & 0x3) != 0x3); + } + break; } - case GC_SET_MAZE_TRACK_MOVE: - break; + MapInvalidateTile({ _loc.ToTileStart(), tileElement->GetBaseZ(), tileElement->GetClearanceZ() }); - case GC_SET_MAZE_TRACK_FILL: - if (!_initialPlacement) - { - auto previousSegment = CoordsXY{ _loc.x - CoordsDirectionDelta[_loc.direction].x / 2, - _loc.y - CoordsDirectionDelta[_loc.direction].y / 2 }; + if ((tileElement->AsTrack()->GetMazeEntry() & 0x8888) == 0x8888) + { + TileElementRemove(tileElement); + ride->validateStations(); + ride->mazeTiles--; + } - tileElement = MapGetTrackElementAtOfTypeFromRide({ previousSegment, _loc.z }, TrackElemType::Maze, _rideIndex); - - MapInvalidateTileFull(previousSegment.ToTileStart()); - if (tileElement == nullptr) - { - LOG_ERROR("No surface found"); - res.Error = GameActions::Status::Unknown; - res.ErrorMessage = STR_ERR_SURFACE_ELEMENT_NOT_FOUND; - return res; - } - - uint32_t segmentBit = MazeGetSegmentBit(previousSegment); - - tileElement->AsTrack()->MazeEntryAdd(1 << segmentBit); - segmentBit--; - tileElement->AsTrack()->MazeEntryAdd(1 << segmentBit); - segmentBit = (segmentBit - 4) & 0x0F; - tileElement->AsTrack()->MazeEntryAdd(1 << segmentBit); - segmentBit = (segmentBit + 3) & 0x0F; - - do - { - tileElement->AsTrack()->MazeEntryAdd(1 << segmentBit); - - uint32_t direction1 = kByte993D0C[segmentBit]; - auto nextElementLoc = previousSegment.ToTileStart() + CoordsDirectionDelta[direction1]; - - TileElement* tmp_tileElement = MapGetTrackElementAtOfTypeFromRide( - { nextElementLoc, _loc.z }, TrackElemType::Maze, _rideIndex); - - if (tmp_tileElement != nullptr) - { - uint8_t edx11 = kByte993CFC[segmentBit]; - tmp_tileElement->AsTrack()->MazeEntryAdd(1 << (edx11)); - } - - segmentBit--; - } while ((segmentBit & 0x3) != 0x3); - } - break; + return res; } - MapInvalidateTile({ _loc.ToTileStart(), tileElement->GetBaseZ(), tileElement->GetClearanceZ() }); - - if ((tileElement->AsTrack()->GetMazeEntry() & 0x8888) == 0x8888) + uint8_t MazeSetTrackAction::MazeGetSegmentBit(const CoordsXY& coords) const { - TileElementRemove(tileElement); - ride->validateStations(); - ride->mazeTiles--; + uint8_t minorX = coords.x & 0x1F; + uint8_t minorY = coords.y & 0x1F; + + if (minorX == 0 && minorY == 0) + { + return 3; + } + + if (minorY == 16 && minorX == 16) + { + return 11; + } + + if (minorY == 0) + { + return 15; + } + + return 7; } - - return res; -} - -uint8_t MazeSetTrackAction::MazeGetSegmentBit(const CoordsXY& coords) const -{ - uint8_t minorX = coords.x & 0x1F; - uint8_t minorY = coords.y & 0x1F; - - if (minorX == 0 && minorY == 0) - { - return 3; - } - - if (minorY == 16 && minorX == 16) - { - return 11; - } - - if (minorY == 0) - { - return 15; - } - - return 7; -} +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/MazeSetTrackAction.h b/src/openrct2/actions/MazeSetTrackAction.h index ad2619323a..bbd70abf54 100644 --- a/src/openrct2/actions/MazeSetTrackAction.h +++ b/src/openrct2/actions/MazeSetTrackAction.h @@ -11,23 +11,26 @@ #include "GameAction.h" -class MazeSetTrackAction final : public GameActionBase +namespace OpenRCT2::GameActions { -private: - CoordsXYZD _loc; - bool _initialPlacement{}; - RideId _rideIndex{ RideId::GetNull() }; - uint8_t _mode{}; + class MazeSetTrackAction final : public GameActionBase + { + private: + CoordsXYZD _loc; + bool _initialPlacement{}; + RideId _rideIndex{ RideId::GetNull() }; + uint8_t _mode{}; -public: - MazeSetTrackAction() = default; - MazeSetTrackAction(const CoordsXYZD& location, bool initialPlacement, RideId rideIndex, uint8_t mode); + public: + MazeSetTrackAction() = default; + MazeSetTrackAction(const CoordsXYZD& location, bool initialPlacement, RideId rideIndex, uint8_t mode); - 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: - uint8_t MazeGetSegmentBit(const CoordsXY&) const; -}; + private: + uint8_t MazeGetSegmentBit(const CoordsXY&) const; + }; +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/NetworkModifyGroupAction.cpp b/src/openrct2/actions/NetworkModifyGroupAction.cpp index bda0261cb3..b8f00e5382 100644 --- a/src/openrct2/actions/NetworkModifyGroupAction.cpp +++ b/src/openrct2/actions/NetworkModifyGroupAction.cpp @@ -11,45 +11,47 @@ #include "../network/Network.h" -using namespace OpenRCT2; - -NetworkModifyGroupAction::NetworkModifyGroupAction( - ModifyGroupType type, uint8_t groupId, const std::string name, uint32_t permissionIndex, PermissionState permissionState) - : _type(type) - , _groupId(groupId) - , _name(name) - , _permissionIndex(permissionIndex) - , _permissionState(permissionState) +namespace OpenRCT2::GameActions { -} + NetworkModifyGroupAction::NetworkModifyGroupAction( + ModifyGroupType type, uint8_t groupId, const std::string name, uint32_t permissionIndex, + PermissionState permissionState) + : _type(type) + , _groupId(groupId) + , _name(name) + , _permissionIndex(permissionIndex) + , _permissionState(permissionState) + { + } -void NetworkModifyGroupAction::AcceptParameters(GameActionParameterVisitor& visitor) -{ - visitor.Visit("type", _type); - visitor.Visit("groupId", _groupId); - visitor.Visit("name", _name); - visitor.Visit("permissionIndex", _permissionIndex); - visitor.Visit("permissionState", _permissionState); -} + void NetworkModifyGroupAction::AcceptParameters(GameActionParameterVisitor& visitor) + { + visitor.Visit("type", _type); + visitor.Visit("groupId", _groupId); + visitor.Visit("name", _name); + visitor.Visit("permissionIndex", _permissionIndex); + visitor.Visit("permissionState", _permissionState); + } -uint16_t NetworkModifyGroupAction::GetActionFlags() const -{ - return GameAction::GetActionFlags() | GameActions::Flags::AllowWhilePaused; -} + uint16_t NetworkModifyGroupAction::GetActionFlags() const + { + return GameAction::GetActionFlags() | Flags::AllowWhilePaused; + } -void NetworkModifyGroupAction::Serialise(DataSerialiser& stream) -{ - GameAction::Serialise(stream); + void NetworkModifyGroupAction::Serialise(DataSerialiser& stream) + { + GameAction::Serialise(stream); - stream << DS_TAG(_type) << DS_TAG(_groupId) << DS_TAG(_name) << DS_TAG(_permissionIndex) << DS_TAG(_permissionState); -} + stream << DS_TAG(_type) << DS_TAG(_groupId) << DS_TAG(_name) << DS_TAG(_permissionIndex) << DS_TAG(_permissionState); + } -GameActions::Result NetworkModifyGroupAction::Query() const -{ - return NetworkModifyGroups(GetPlayer(), _type, _groupId, _name, _permissionIndex, _permissionState, false); -} + Result NetworkModifyGroupAction::Query() const + { + return NetworkModifyGroups(GetPlayer(), _type, _groupId, _name, _permissionIndex, _permissionState, false); + } -GameActions::Result NetworkModifyGroupAction::Execute() const -{ - return NetworkModifyGroups(GetPlayer(), _type, _groupId, _name, _permissionIndex, _permissionState, true); -} + Result NetworkModifyGroupAction::Execute() const + { + return NetworkModifyGroups(GetPlayer(), _type, _groupId, _name, _permissionIndex, _permissionState, true); + } +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/NetworkModifyGroupAction.h b/src/openrct2/actions/NetworkModifyGroupAction.h index ddd92af0f9..394c84780b 100644 --- a/src/openrct2/actions/NetworkModifyGroupAction.h +++ b/src/openrct2/actions/NetworkModifyGroupAction.h @@ -11,44 +11,47 @@ #include "GameAction.h" -enum class ModifyGroupType : uint8_t +namespace OpenRCT2::GameActions { - AddGroup, - RemoveGroup, - SetPermissions, - SetName, - SetDefault, - Count -}; + enum class ModifyGroupType : uint8_t + { + AddGroup, + RemoveGroup, + SetPermissions, + SetName, + SetDefault, + Count + }; -enum class PermissionState : uint8_t -{ - Toggle, - SetAll, - ClearAll, - Count -}; + enum class PermissionState : uint8_t + { + Toggle, + SetAll, + ClearAll, + Count + }; -class NetworkModifyGroupAction final : public GameActionBase -{ -private: - ModifyGroupType _type{ ModifyGroupType::Count }; - uint8_t _groupId{ std::numeric_limits::max() }; - std::string _name; - uint32_t _permissionIndex{ std::numeric_limits::max() }; - PermissionState _permissionState{ PermissionState::Count }; + class NetworkModifyGroupAction final : public GameActionBase + { + private: + ModifyGroupType _type{ ModifyGroupType::Count }; + uint8_t _groupId{ std::numeric_limits::max() }; + std::string _name; + uint32_t _permissionIndex{ std::numeric_limits::max() }; + PermissionState _permissionState{ PermissionState::Count }; -public: - NetworkModifyGroupAction() = default; - NetworkModifyGroupAction( - ModifyGroupType type, uint8_t groupId = std::numeric_limits::max(), const std::string name = "", - uint32_t permissionIndex = 0, PermissionState permissionState = PermissionState::Count); + public: + NetworkModifyGroupAction() = default; + NetworkModifyGroupAction( + ModifyGroupType type, uint8_t groupId = std::numeric_limits::max(), const std::string name = "", + uint32_t permissionIndex = 0, PermissionState permissionState = PermissionState::Count); - 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/RideDemolishAction.cpp b/src/openrct2/actions/RideDemolishAction.cpp index 0df74d5d62..1eb84b33da 100644 --- a/src/openrct2/actions/RideDemolishAction.cpp +++ b/src/openrct2/actions/RideDemolishAction.cpp @@ -177,7 +177,7 @@ GameActions::Result RideDemolishAction::DemolishRide(Ride& ride) const money64 RideDemolishAction::MazeRemoveTrack(const CoordsXYZD& coords) const { - auto setMazeTrack = MazeSetTrackAction(coords, false, _rideIndex, GC_SET_MAZE_TRACK_FILL); + auto setMazeTrack = GameActions::MazeSetTrackAction(coords, false, _rideIndex, GC_SET_MAZE_TRACK_FILL); setMazeTrack.SetFlags(GetFlags()); auto execRes = GameActions::ExecuteNested(&setMazeTrack); diff --git a/src/openrct2/network/Network.h b/src/openrct2/network/Network.h index af6f7ed59f..af0b191983 100644 --- a/src/openrct2/network/Network.h +++ b/src/openrct2/network/Network.h @@ -30,10 +30,10 @@ struct Peep; struct CoordsXYZ; namespace OpenRCT2::GameActions { + enum class ModifyGroupType : uint8_t; + enum class PermissionState : uint8_t; class Result; -} -enum class ModifyGroupType : uint8_t; -enum class PermissionState : uint8_t; +} // namespace OpenRCT2::GameActions enum class NetworkPermission : uint32_t; void NetworkReconnect(); @@ -82,8 +82,8 @@ void NetworkSetPlayerGroup(uint32_t index, uint32_t groupindex); [[nodiscard]] OpenRCT2::GameActions::Result NetworkSetPlayerGroup( NetworkPlayerId_t actionPlayerId, NetworkPlayerId_t playerId, uint8_t groupId, bool isExecuting); [[nodiscard]] OpenRCT2::GameActions::Result NetworkModifyGroups( - NetworkPlayerId_t actionPlayerId, ModifyGroupType type, uint8_t groupId, const std::string& name, uint32_t permissionIndex, - PermissionState permissionState, bool isExecuting); + NetworkPlayerId_t actionPlayerId, OpenRCT2::GameActions::ModifyGroupType type, uint8_t groupId, const std::string& name, + uint32_t permissionIndex, OpenRCT2::GameActions::PermissionState permissionState, bool isExecuting); [[nodiscard]] OpenRCT2::GameActions::Result NetworkKickPlayer(NetworkPlayerId_t playerId, bool isExecuting); [[nodiscard]] uint8_t NetworkGetDefaultGroup(); [[nodiscard]] int32_t NetworkGetNumActions(); diff --git a/src/openrct2/network/NetworkBase.cpp b/src/openrct2/network/NetworkBase.cpp index c8dfead369..ad3eb0519d 100644 --- a/src/openrct2/network/NetworkBase.cpp +++ b/src/openrct2/network/NetworkBase.cpp @@ -2827,7 +2827,8 @@ void NetworkBase::Client_Handle_MAP([[maybe_unused]] NetworkConnection& connecti else { // Something went wrong, game is not loaded. Return to main screen. - auto loadOrQuitAction = LoadOrQuitAction(LoadOrQuitModes::OpenSavePrompt, PromptMode::saveBeforeQuit); + auto loadOrQuitAction = GameActions::LoadOrQuitAction( + GameActions::LoadOrQuitModes::OpenSavePrompt, PromptMode::saveBeforeQuit); GameActions::Execute(&loadOrQuitAction); } if (has_to_free) @@ -3633,13 +3634,13 @@ GameActions::Result NetworkSetPlayerGroup( } GameActions::Result NetworkModifyGroups( - NetworkPlayerId_t actionPlayerId, ModifyGroupType type, uint8_t groupId, const std::string& name, uint32_t permissionIndex, - PermissionState permissionState, bool isExecuting) + NetworkPlayerId_t actionPlayerId, GameActions::ModifyGroupType type, uint8_t groupId, const std::string& name, + uint32_t permissionIndex, GameActions::PermissionState permissionState, bool isExecuting) { auto& network = OpenRCT2::GetContext()->GetNetwork(); switch (type) { - case ModifyGroupType::AddGroup: + case GameActions::ModifyGroupType::AddGroup: { if (isExecuting) { @@ -3651,7 +3652,7 @@ GameActions::Result NetworkModifyGroups( } } break; - case ModifyGroupType::RemoveGroup: + case GameActions::ModifyGroupType::RemoveGroup: { if (groupId == 0) { @@ -3671,7 +3672,7 @@ GameActions::Result NetworkModifyGroups( } } break; - case ModifyGroupType::SetPermissions: + case GameActions::ModifyGroupType::SetPermissions: { if (groupId == 0) { // can't change admin group permissions @@ -3680,7 +3681,7 @@ GameActions::Result NetworkModifyGroups( NetworkGroup* mygroup = nullptr; NetworkPlayer* player = network.GetPlayerByID(actionPlayerId); auto networkPermission = static_cast(permissionIndex); - if (player != nullptr && permissionState == PermissionState::Toggle) + if (player != nullptr && permissionState == GameActions::PermissionState::Toggle) { mygroup = network.GetGroupByID(player->Group); if (mygroup == nullptr || !mygroup->CanPerformAction(networkPermission)) @@ -3695,11 +3696,11 @@ GameActions::Result NetworkModifyGroups( NetworkGroup* group = network.GetGroupByID(groupId); if (group != nullptr) { - if (permissionState != PermissionState::Toggle) + if (permissionState != GameActions::PermissionState::Toggle) { if (mygroup != nullptr) { - if (permissionState == PermissionState::SetAll) + if (permissionState == GameActions::PermissionState::SetAll) { group->ActionsAllowed = mygroup->ActionsAllowed; } @@ -3717,7 +3718,7 @@ GameActions::Result NetworkModifyGroups( } } break; - case ModifyGroupType::SetName: + case GameActions::ModifyGroupType::SetName: { NetworkGroup* group = network.GetGroupByID(groupId); if (group == nullptr) @@ -3747,7 +3748,7 @@ GameActions::Result NetworkModifyGroups( } } break; - case ModifyGroupType::SetDefault: + case GameActions::ModifyGroupType::SetDefault: { if (groupId == 0) { @@ -4233,8 +4234,8 @@ GameActions::Result NetworkSetPlayerGroup( return GameActions::Result(); } GameActions::Result NetworkModifyGroups( - NetworkPlayerId_t actionPlayerId, ModifyGroupType type, uint8_t groupId, const std::string& name, uint32_t permissionIndex, - PermissionState permissionState, bool isExecuting) + NetworkPlayerId_t actionPlayerId, GameActions::ModifyGroupType type, uint8_t groupId, const std::string& name, + uint32_t permissionIndex, GameActions::PermissionState permissionState, bool isExecuting) { return GameActions::Result(); } diff --git a/src/openrct2/ride/RideConstruction.cpp b/src/openrct2/ride/RideConstruction.cpp index d73a9ab4c5..ceb8204429 100644 --- a/src/openrct2/ride/RideConstruction.cpp +++ b/src/openrct2/ride/RideConstruction.cpp @@ -12,11 +12,9 @@ #include "../Context.h" #include "../GameState.h" #include "../Input.h" -#include "../actions/MazeSetTrackAction.h" #include "../actions/RideEntranceExitRemoveAction.h" #include "../actions/RideSetSettingAction.h" #include "../actions/RideSetStatusAction.h" -#include "../actions/RideSetVehicleAction.h" #include "../actions/TrackRemoveAction.h" #include "../entity/EntityList.h" #include "../entity/EntityRegistry.h" @@ -37,6 +35,7 @@ #include "../world/TileElementsView.h" #include "../world/tile_element/EntranceElement.h" #include "../world/tile_element/PathElement.h" +#include "../world/tile_element/TileElement.h" #include "../world/tile_element/TrackElement.h" #include "Ride.h" #include "RideData.h" diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index 270f28b985..9c1c3d9a72 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -1475,7 +1475,7 @@ static GameActions::Result TrackDesignPlaceMaze( flags |= GAME_COMMAND_FLAG_REPLAY; } - auto mazePlace = MazePlaceTrackAction({ mapCoord, origin.z }, ride.id, mazeEntry); + auto mazePlace = GameActions::MazePlaceTrackAction({ mapCoord, origin.z }, ride.id, mazeEntry); mazePlace.SetFlags(flags); auto res = flags & GAME_COMMAND_FLAG_APPLY ? GameActions::ExecuteNested(&mazePlace) : GameActions::QueryNested(&mazePlace); diff --git a/src/openrct2/scripting/bindings/network/ScNetwork.cpp b/src/openrct2/scripting/bindings/network/ScNetwork.cpp index c1b68ef818..e25097e50e 100644 --- a/src/openrct2/scripting/bindings/network/ScNetwork.cpp +++ b/src/openrct2/scripting/bindings/network/ScNetwork.cpp @@ -68,7 +68,7 @@ namespace OpenRCT2::Scripting void ScNetwork::defaultGroup_set(int32_t value) { #ifndef DISABLE_NETWORK - auto action = NetworkModifyGroupAction(ModifyGroupType::SetDefault, value); + auto action = GameActions::NetworkModifyGroupAction(GameActions::ModifyGroupType::SetDefault, value); GameActions::Execute(&action); #endif } @@ -198,7 +198,7 @@ namespace OpenRCT2::Scripting void ScNetwork::addGroup() { #ifndef DISABLE_NETWORK - auto networkModifyGroup = NetworkModifyGroupAction(ModifyGroupType::AddGroup); + auto networkModifyGroup = GameActions::NetworkModifyGroupAction(GameActions::ModifyGroupType::AddGroup); GameActions::Execute(&networkModifyGroup); #endif } @@ -213,7 +213,7 @@ namespace OpenRCT2::Scripting if (index < numGroups) { auto groupId = NetworkGetGroupID(index); - auto networkAction = NetworkModifyGroupAction(ModifyGroupType::RemoveGroup, groupId); + auto networkAction = GameActions::NetworkModifyGroupAction(GameActions::ModifyGroupType::RemoveGroup, groupId); GameActions::Execute(&networkAction); } } @@ -222,7 +222,7 @@ namespace OpenRCT2::Scripting auto index = NetworkGetGroupIndex(id); if (index != -1) { - auto networkAction = NetworkModifyGroupAction(ModifyGroupType::RemoveGroup, id); + auto networkAction = GameActions::NetworkModifyGroupAction(GameActions::ModifyGroupType::RemoveGroup, id); GameActions::Execute(&networkAction); } } diff --git a/src/openrct2/scripting/bindings/network/ScPlayerGroup.cpp b/src/openrct2/scripting/bindings/network/ScPlayerGroup.cpp index 072d5a21cc..ddd297098d 100644 --- a/src/openrct2/scripting/bindings/network/ScPlayerGroup.cpp +++ b/src/openrct2/scripting/bindings/network/ScPlayerGroup.cpp @@ -46,7 +46,7 @@ namespace OpenRCT2::Scripting void ScPlayerGroup::name_set(std::string value) { #ifndef DISABLE_NETWORK - auto action = NetworkModifyGroupAction(ModifyGroupType::SetName, _id, value); + auto action = GameActions::NetworkModifyGroupAction(GameActions::ModifyGroupType::SetName, _id, value); GameActions::Execute(&action); #endif } @@ -100,7 +100,8 @@ namespace OpenRCT2::Scripting return; // First clear all permissions - auto networkAction = NetworkModifyGroupAction(ModifyGroupType::SetPermissions, _id, "", 0, PermissionState::ClearAll); + auto networkAction = GameActions::NetworkModifyGroupAction( + GameActions::ModifyGroupType::SetPermissions, _id, "", 0, GameActions::PermissionState::ClearAll); GameActions::Execute(&networkAction); std::vector enabledPermissions; @@ -126,8 +127,9 @@ namespace OpenRCT2::Scripting = (enabledPermissions[i] != (NetworkCanPerformAction(groupIndex, static_cast(i)) != 0)); if (toggle) { - auto networkAction2 = NetworkModifyGroupAction( - ModifyGroupType::SetPermissions, _id, "", static_cast(i), PermissionState::Toggle); + auto networkAction2 = GameActions::NetworkModifyGroupAction( + GameActions::ModifyGroupType::SetPermissions, _id, "", static_cast(i), + GameActions::PermissionState::Toggle); GameActions::Execute(&networkAction2); } }