diff --git a/src/openrct2/actions/ClearAction.hpp b/src/openrct2/actions/ClearAction.hpp index 331e268f43..2f30df8a9f 100644 --- a/src/openrct2/actions/ClearAction.hpp +++ b/src/openrct2/actions/ClearAction.hpp @@ -155,8 +155,8 @@ private: auto footpathRemoveAction = FootpathRemoveAction(x * 32, y * 32, tileElement->base_height); footpathRemoveAction.SetFlags(GetFlags()); - auto res = executing ? GameActions::Execute(&footpathRemoveAction, false) - : GameActions::Query(&footpathRemoveAction, false); + auto res = executing ? GameActions::ExecuteNested(&footpathRemoveAction) + : GameActions::QueryNested(&footpathRemoveAction); if (res->Error != GA_ERROR::OK) return MONEY32_UNDEFINED; @@ -173,8 +173,8 @@ private: tileElement->AsSmallScenery()->GetEntryIndex()); removeSceneryAction.SetFlags(GetFlags()); - auto res = executing ? GameActions::Execute(&removeSceneryAction, false) - : GameActions::Query(&removeSceneryAction, false); + auto res = executing ? GameActions::ExecuteNested(&removeSceneryAction) + : GameActions::QueryNested(&removeSceneryAction); if (res->Error != GA_ERROR::OK) return MONEY32_UNDEFINED; @@ -190,8 +190,8 @@ private: auto wallRemoveAction = WallRemoveAction(wallLocation); wallRemoveAction.SetFlags(GetFlags()); - auto res = executing ? GameActions::Execute(&wallRemoveAction, false) - : GameActions::Query(&wallRemoveAction, false); + auto res = executing ? GameActions::ExecuteNested(&wallRemoveAction) + : GameActions::QueryNested(&wallRemoveAction); if (res->Error != GA_ERROR::OK) return MONEY32_UNDEFINED; @@ -208,8 +208,8 @@ private: tileElement->AsLargeScenery()->GetSequenceIndex()); removeSceneryAction.SetFlags(GetFlags() | GAME_COMMAND_FLAG_PATH_SCENERY); - auto res = executing ? GameActions::Execute(&removeSceneryAction, false) - : GameActions::Query(&removeSceneryAction, false); + auto res = executing ? GameActions::ExecuteNested(&removeSceneryAction) + : GameActions::QueryNested(&removeSceneryAction); if (res->Error != GA_ERROR::OK) return MONEY32_UNDEFINED; diff --git a/src/openrct2/actions/GameAction.cpp b/src/openrct2/actions/GameAction.cpp index b6ec252a75..b564891e0e 100644 --- a/src/openrct2/actions/GameAction.cpp +++ b/src/openrct2/actions/GameAction.cpp @@ -137,7 +137,7 @@ namespace GameActions return false; } - GameActionResult::Ptr Query(const GameAction* action, bool topLevel /* = true */) + static GameActionResult::Ptr QueryInternal(const GameAction* action, bool topLevel) { Guard::ArgumentNotNull(action); @@ -156,7 +156,7 @@ namespace GameActions auto result = action->Query(); // Only top level actions affect the command position. - if (topLevel == true) + if (topLevel) { gCommandPosition.x = result->Position.x; gCommandPosition.y = result->Position.y; @@ -175,6 +175,16 @@ namespace GameActions return result; } + GameActionResult::Ptr Query(const GameAction* action) + { + return QueryInternal(action, true); + } + + GameActionResult::Ptr QueryNested(const GameAction* action) + { + return QueryInternal(action, false); + } + static const char* GetRealm() { if (network_get_mode() == NETWORK_MODE_CLIENT) @@ -227,7 +237,7 @@ namespace GameActions network_append_server_log(text); } - GameActionResult::Ptr Execute(const GameAction* action, bool topLevel /* = true */) + static GameActionResult::Ptr ExecuteInternal(const GameAction* action, bool topLevel) { Guard::ArgumentNotNull(action); @@ -251,7 +261,7 @@ namespace GameActions } } - GameActionResult::Ptr result = Query(action, topLevel); + GameActionResult::Ptr result = Query(action); if (result->Error == GA_ERROR::OK) { if (topLevel) @@ -364,4 +374,14 @@ namespace GameActions return result; } + GameActionResult::Ptr Execute(const GameAction* action) + { + return ExecuteInternal(action, true); + } + + GameActionResult::Ptr ExecuteNested(const GameAction* action) + { + return ExecuteInternal(action, false); + } + } // namespace GameActions diff --git a/src/openrct2/actions/GameAction.h b/src/openrct2/actions/GameAction.h index ec2b166e6f..aebc20f36a 100644 --- a/src/openrct2/actions/GameAction.h +++ b/src/openrct2/actions/GameAction.h @@ -244,8 +244,15 @@ namespace GameActions bool IsValidId(uint32_t id); GameAction::Ptr Create(uint32_t id); GameAction::Ptr Clone(const GameAction* action); - GameActionResult::Ptr Query(const GameAction* action, bool topLevel = true); - GameActionResult::Ptr Execute(const GameAction* action, bool topLevel = true); + + // This should be used if a round trip is to be expected. + GameActionResult::Ptr Query(const GameAction* action); + GameActionResult::Ptr Execute(const GameAction* action); + + // This should be used from within game actions. + GameActionResult::Ptr QueryNested(const GameAction* action); + GameActionResult::Ptr ExecuteNested(const GameAction* action); + GameActionFactory Register(uint32_t id, GameActionFactory action); template static GameActionFactory Register() diff --git a/src/openrct2/actions/RideDemolishAction.hpp b/src/openrct2/actions/RideDemolishAction.hpp index 8e7ba79e45..feb63ec330 100644 --- a/src/openrct2/actions/RideDemolishAction.hpp +++ b/src/openrct2/actions/RideDemolishAction.hpp @@ -264,7 +264,7 @@ private: auto setMazeTrack = MazeSetTrackAction(x, y, z, false, direction, _rideIndex, GC_SET_MAZE_TRACK_FILL); setMazeTrack.SetFlags(GetFlags()); - auto execRes = GameActions::Execute(&setMazeTrack, false); + auto execRes = GameActions::ExecuteNested(&setMazeTrack); if (execRes->Error == GA_ERROR::OK) { return execRes->Cost; diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 46bf38e5aa..0c56bc9f1f 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -1330,8 +1330,8 @@ static money32 lower_land( auto landSetHeightAction = LandSetHeightAction({ x_coord, y_coord }, height, newSlope); landSetHeightAction.SetFlags(flags); - auto res = (flags & GAME_COMMAND_FLAG_APPLY) ? GameActions::Execute(&landSetHeightAction, false) - : GameActions::Query(&landSetHeightAction, false); + auto res = (flags & GAME_COMMAND_FLAG_APPLY) ? GameActions::ExecuteNested(&landSetHeightAction) + : GameActions::QueryNested(&landSetHeightAction); if (res->Error != GA_ERROR::OK) { return MONEY32_UNDEFINED; @@ -1583,8 +1583,8 @@ static money32 smooth_land_tile( auto landSetHeightAction = LandSetHeightAction({ x, y }, targetBaseZ, slope); landSetHeightAction.SetFlags(flags); - auto res = (flags & GAME_COMMAND_FLAG_APPLY) ? GameActions::Execute(&landSetHeightAction, false) - : GameActions::Query(&landSetHeightAction, false); + auto res = (flags & GAME_COMMAND_FLAG_APPLY) ? GameActions::ExecuteNested(&landSetHeightAction) + : GameActions::QueryNested(&landSetHeightAction); if (res->Error == GA_ERROR::OK) { @@ -1730,8 +1730,8 @@ static money32 smooth_land_row_by_edge( } auto landSetHeightAction = LandSetHeightAction({ x, y }, targetBaseZ, slope); landSetHeightAction.SetFlags(flags); - auto res = (flags & GAME_COMMAND_FLAG_APPLY) ? GameActions::Execute(&landSetHeightAction, false) - : GameActions::Query(&landSetHeightAction, false); + auto res = (flags & GAME_COMMAND_FLAG_APPLY) ? GameActions::ExecuteNested(&landSetHeightAction) + : GameActions::QueryNested(&landSetHeightAction); if (res->Error == GA_ERROR::OK) { totalCost += res->Cost;