Create separate unit for GameActionRunner

This commit is contained in:
Aaron van Geffen committed 2026-02-09 16:06:56 +01:00
1 parent 506991962e
commit 773ba479cd
179 files changed
+854 -675

No files matched your search

+1
View File
@@ -24,6 +24,7 @@
#include <openrct2/Input.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/actions/CheatSetAction.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/LoadOrQuitAction.h>
#include <openrct2/actions/PauseToggleAction.h>
#include <openrct2/actions/TileModifyAction.h>
@@ -24,6 +24,7 @@
#include <openrct2/actions/BalloonPressAction.h>
#include <openrct2/actions/FootpathAdditionRemoveAction.h>
#include <openrct2/actions/FootpathRemoveAction.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/LargeSceneryRemoveAction.h>
#include <openrct2/actions/ParkEntranceRemoveAction.h>
#include <openrct2/actions/SmallSceneryRemoveAction.h>
+1
View File
@@ -12,6 +12,7 @@
#include "../interface/Viewport.h"
#include <openrct2/GameState.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/RideCreateAction.h>
#include <openrct2/config/Config.h>
#include <openrct2/ride/Ride.h>
+1
View File
@@ -19,6 +19,7 @@
#include <openrct2/actions/BannerRemoveAction.h>
#include <openrct2/actions/BannerSetNameAction.h>
#include <openrct2/actions/BannerSetStyleAction.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/config/Config.h>
#include <openrct2/drawing/TextColour.h>
#include <openrct2/object/BannerSceneryEntry.h>
+1
View File
@@ -19,6 +19,7 @@
#include <openrct2/OpenRCT2.h>
#include <openrct2/SpriteIds.h>
#include <openrct2/actions/CheatSetAction.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/ParkSetDateAction.h>
#include <openrct2/config/Config.h>
#include <openrct2/core/EnumUtils.hpp>
+1
View File
@@ -17,6 +17,7 @@
#include <openrct2/Input.h>
#include <openrct2/SpriteIds.h>
#include <openrct2/actions/ClearAction.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/localisation/Formatter.h>
#include <openrct2/ui/WindowManager.h>
@@ -11,6 +11,7 @@
#include <openrct2-ui/windows/Windows.h>
#include <openrct2/Game.h>
#include <openrct2/GameState.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/RideDemolishAction.h>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/localisation/Formatter.h>
@@ -15,6 +15,7 @@
#include <openrct2/GameState.h>
#include <openrct2/Input.h>
#include <openrct2/SpriteIds.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/ParkEntrancePlaceAction.h>
#include <openrct2/audio/Audio.h>
#include <openrct2/drawing/ColourMap.h>
@@ -19,6 +19,7 @@
#include <openrct2/GameState.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/SpriteIds.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/ParkSetNameAction.h>
#include <openrct2/actions/ScenarioSetSettingAction.h>
#include <openrct2/core/String.hpp>
+1
View File
@@ -13,6 +13,7 @@
#include <openrct2-ui/windows/Windows.h>
#include <openrct2/GameState.h>
#include <openrct2/SpriteIds.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/ParkSetLoanAction.h>
#include <openrct2/drawing/ColourMap.h>
#include <openrct2/drawing/Drawing.h>
+1
View File
@@ -26,6 +26,7 @@
#include <openrct2/SpriteIds.h>
#include <openrct2/actions/FootpathPlaceAction.h>
#include <openrct2/actions/FootpathRemoveAction.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/audio/Audio.h>
#include <openrct2/core/FlagHolder.hpp>
#include <openrct2/drawing/Drawing.h>
+1
View File
@@ -19,6 +19,7 @@
#include <openrct2/GameState.h>
#include <openrct2/Input.h>
#include <openrct2/SpriteIds.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/GuestSetFlagsAction.h>
#include <openrct2/actions/GuestSetNameAction.h>
#include <openrct2/actions/PeepPickupAction.h>
+1
View File
@@ -19,6 +19,7 @@
#include <openrct2/GameState.h>
#include <openrct2/Input.h>
#include <openrct2/SpriteIds.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/LandLowerAction.h>
#include <openrct2/actions/LandRaiseAction.h>
#include <openrct2/actions/LandSmoothAction.h>
+1
View File
@@ -18,6 +18,7 @@
#include <openrct2/Input.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/SpriteIds.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/LandBuyRightsAction.h>
#include <openrct2/actions/LandSetRightsAction.h>
#include <openrct2/core/String.hpp>
+1
View File
@@ -19,6 +19,7 @@
#include <openrct2/Input.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/SpriteIds.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/MapChangeSizeAction.h>
#include <openrct2/actions/PeepSpawnPlaceAction.h>
#include <openrct2/actions/SurfaceSetStyleAction.h>
@@ -17,6 +17,7 @@
#include <openrct2/GameState.h>
#include <openrct2/Input.h>
#include <openrct2/SpriteIds.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/MazeSetTrackAction.h>
#include <openrct2/actions/ResultWithMessage.h>
#include <openrct2/actions/RideDemolishAction.h>
+1
View File
@@ -14,6 +14,7 @@
#include <openrct2/Game.h>
#include <openrct2/GameState.h>
#include <openrct2/SpriteIds.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/NetworkModifyGroupAction.h>
#include <openrct2/config/Config.h>
#include <openrct2/core/String.hpp>
+1
View File
@@ -13,6 +13,7 @@
#include <openrct2-ui/windows/Windows.h>
#include <openrct2/Game.h>
#include <openrct2/GameState.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/ParkMarketingAction.h>
#include <openrct2/core/BitSet.hpp>
#include <openrct2/core/String.hpp>
+1
View File
@@ -22,6 +22,7 @@
#include <openrct2/GameState.h>
#include <openrct2/PlatformEnvironment.h>
#include <openrct2/SpriteIds.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/ScenarioSetSettingAction.h>
#include <openrct2/audio/Audio.h>
#include <openrct2/audio/AudioContext.h>
+1
View File
@@ -20,6 +20,7 @@
#include <openrct2/GameState.h>
#include <openrct2/Input.h>
#include <openrct2/SpriteIds.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/ParkSetEntranceFeeAction.h>
#include <openrct2/actions/ParkSetNameAction.h>
#include <openrct2/config/Config.h>
+1
View File
@@ -18,6 +18,7 @@
#include <openrct2/GameState.h>
#include <openrct2/Input.h>
#include <openrct2/SpriteIds.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/StaffSetPatrolAreaAction.h>
#include <openrct2/core/String.hpp>
#include <openrct2/drawing/Drawing.h>
+1
View File
@@ -15,6 +15,7 @@
#include <openrct2/GameState.h>
#include <openrct2/Input.h>
#include <openrct2/SpriteIds.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/PlayerKickAction.h>
#include <openrct2/actions/PlayerSetGroupAction.h>
#include <openrct2/drawing/Drawing.h>
@@ -11,6 +11,7 @@
#include <openrct2-ui/windows/Windows.h>
#include <openrct2/Game.h>
#include <openrct2/GameState.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/RideDemolishAction.h>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/ui/WindowManager.h>
+1
View File
@@ -14,6 +14,7 @@
#include <openrct2/Game.h>
#include <openrct2/GameState.h>
#include <openrct2/SpriteIds.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/ParkSetResearchFundingAction.h>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/localisation/Formatter.h>
+1 -1
View File
@@ -28,7 +28,7 @@
#include <openrct2/Limits.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/SpriteIds.h>
#include <openrct2/actions/GameAction.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/ParkSetParameterAction.h>
#include <openrct2/actions/ResultWithMessage.h>
#include <openrct2/actions/RideSetAppearanceAction.h>
@@ -24,6 +24,7 @@
#include <openrct2/GameState.h>
#include <openrct2/Input.h>
#include <openrct2/SpriteIds.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/MazeSetTrackAction.h>
#include <openrct2/actions/ResultWithMessage.h>
#include <openrct2/actions/RideDemolishAction.h>
+1
View File
@@ -16,6 +16,7 @@
#include <openrct2/Game.h>
#include <openrct2/GameState.h>
#include <openrct2/SpriteIds.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/RideDemolishAction.h>
#include <openrct2/actions/RideSetStatusAction.h>
#include <openrct2/core/String.hpp>
+1
View File
@@ -23,6 +23,7 @@
#include <openrct2/actions/BannerPlaceAction.h>
#include <openrct2/actions/BannerSetColourAction.h>
#include <openrct2/actions/FootpathAdditionPlaceAction.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/LargeSceneryPlaceAction.h>
#include <openrct2/actions/LargeScenerySetColourAction.h>
#include <openrct2/actions/ScenerySetRestrictedAction.h>
+1
View File
@@ -16,6 +16,7 @@
#include <openrct2/Game.h>
#include <openrct2/GameState.h>
#include <openrct2/SpriteIds.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/LargeSceneryRemoveAction.h>
#include <openrct2/actions/SignSetNameAction.h>
#include <openrct2/actions/SignSetStyleAction.h>
+1
View File
@@ -18,6 +18,7 @@
#include <openrct2/GameState.h>
#include <openrct2/Input.h>
#include <openrct2/SpriteIds.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/PeepPickupAction.h>
#include <openrct2/actions/StaffSetCostumeAction.h>
#include <openrct2/actions/StaffSetNameAction.h>
@@ -11,6 +11,7 @@
#include <openrct2-ui/windows/Windows.h>
#include <openrct2/Game.h>
#include <openrct2/GameState.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/StaffFireAction.h>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/entity/EntityRegistry.h>
+1
View File
@@ -20,6 +20,7 @@
#include <openrct2/GameState.h>
#include <openrct2/Input.h>
#include <openrct2/SpriteIds.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/PeepPickupAction.h>
#include <openrct2/actions/StaffFireAction.h>
#include <openrct2/actions/StaffHireNewAction.h>
@@ -19,6 +19,7 @@
#include <openrct2/GameState.h>
#include <openrct2/Input.h>
#include <openrct2/SpriteIds.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/TileModifyAction.h>
#include <openrct2/core/Guard.hpp>
#include <openrct2/drawing/ColourMap.h>
+1
View File
@@ -18,6 +18,7 @@
#include <openrct2/ParkImporter.h>
#include <openrct2/PlatformEnvironment.h>
#include <openrct2/SpriteIds.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/LoadOrQuitAction.h>
#include <openrct2/drawing/Rectangle.h>
#include <openrct2/interface/ColourWithFlags.h>
+1
View File
@@ -28,6 +28,7 @@
#include <openrct2/ParkImporter.h>
#include <openrct2/SpriteIds.h>
#include <openrct2/Version.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/GameSetSpeedAction.h>
#include <openrct2/actions/LoadOrQuitAction.h>
#include <openrct2/actions/PauseToggleAction.h>
@@ -19,6 +19,7 @@
#include <openrct2/GameState.h>
#include <openrct2/Input.h>
#include <openrct2/SpriteIds.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/TrackDesignAction.h>
#include <openrct2/audio/Audio.h>
#include <openrct2/config/Config.h>
+1
View File
@@ -16,6 +16,7 @@
#include <openrct2/GameState.h>
#include <openrct2/Input.h>
#include <openrct2/SpriteIds.h>
#include <openrct2/actions/GameActionRunner.h>
#include <openrct2/actions/WaterLowerAction.h>
#include <openrct2/actions/WaterRaiseAction.h>
#include <openrct2/drawing/Drawing.h>
+1
View File
@@ -11,6 +11,7 @@
#include "GameState.h"
#include "actions/CheatSetAction.h"
#include "actions/GameActionRunner.h"
#include "actions/ParkSetLoanAction.h"
#include "core/DataSerialiser.h"
#include "network/Network.h"
+1 -1
View File
@@ -25,7 +25,7 @@
#include "PlatformEnvironment.h"
#include "ReplayManager.h"
#include "Version.h"
#include "actions/GameAction.h"
#include "actions/GameActionRunner.h"
#include "audio/Audio.h"
#include "audio/AudioContext.h"
#include "config/Config.h"
+1
View File
@@ -16,6 +16,7 @@
#include "GameState.h"
#include "OpenRCT2.h"
#include "ParkImporter.h"
#include "actions/GameActionRunner.h"
#include "actions/LandBuyRightsAction.h"
#include "actions/LandSetRightsAction.h"
#include "actions/ResultWithMessage.h"
+1
View File
@@ -21,6 +21,7 @@
#include "ParkImporter.h"
#include "PlatformEnvironment.h"
#include "ReplayManager.h"
#include "actions/GameActionRunner.h"
#include "actions/GameSetSpeedAction.h"
#include "actions/LoadOrQuitAction.h"
#include "audio/Audio.h"
+1 -1
View File
@@ -14,7 +14,7 @@
#include "Input.h"
#include "OpenRCT2.h"
#include "ReplayManager.h"
#include "actions/GameAction.h"
#include "actions/GameActionRunner.h"
#include "config/Config.h"
#include "drawing/Drawing.h"
#include "entity/EntityTweener.h"
+1 -1
View File
@@ -19,7 +19,7 @@
#include "PlatformEnvironment.h"
#include "actions/CheatSetAction.h"
#include "actions/FootpathPlaceAction.h"
#include "actions/GameAction.h"
#include "actions/GameActionRunner.h"
#include "actions/RideEntranceExitPlaceAction.h"
#include "actions/TileModifyAction.h"
#include "actions/TrackPlaceAction.h"
+1 -1
View File
@@ -13,7 +13,7 @@
#include "../GameState.h"
#include "../entity/Balloon.h"
#include "../entity/EntityRegistry.h"
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
+1 -1
View File
@@ -10,7 +10,7 @@
#pragma once
#include "../Identifiers.h"
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
+1 -1
View File
@@ -22,7 +22,7 @@
#include "../world/TileElementsView.h"
#include "../world/tile_element/BannerElement.h"
#include "../world/tile_element/PathElement.h"
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
+1 -1
View File
@@ -9,7 +9,7 @@
#pragma once
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::Drawing
{
+1 -1
View File
@@ -18,7 +18,7 @@
#include "../world/Scenery.h"
#include "../world/TileElementsView.h"
#include "../world/tile_element/BannerElement.h"
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
+1 -1
View File
@@ -9,7 +9,7 @@
#pragma once
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
@@ -16,7 +16,7 @@
#include "../world/Banner.h"
#include "../world/Map.h"
#include "../world/tile_element/BannerElement.h"
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
+1 -1
View File
@@ -9,7 +9,7 @@
#pragma once
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::Drawing
{
+1 -1
View File
@@ -19,7 +19,7 @@
#include "../world/Banner.h"
#include "../world/Map.h"
#include "../world/tile_element/BannerElement.h"
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
+1 -1
View File
@@ -9,7 +9,7 @@
#pragma once
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
@@ -19,7 +19,7 @@
#include "../world/Banner.h"
#include "../world/Map.h"
#include "../world/tile_element/BannerElement.h"
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
+1 -1
View File
@@ -9,7 +9,7 @@
#pragma once
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
+1
View File
@@ -12,6 +12,7 @@
#include "../Cheats.h"
#include "../Diagnostic.h"
#include "../GameState.h"
#include "../actions/GameActionRunner.h"
#include "../config/Config.h"
#include "../core/EnumUtils.hpp"
#include "../core/Guard.hpp"
+1 -1
View File
@@ -9,7 +9,7 @@
#pragma once
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
+1
View File
@@ -21,6 +21,7 @@
#include "../world/tile_element/PathElement.h"
#include "../world/tile_element/SmallSceneryElement.h"
#include "FootpathRemoveAction.h"
#include "GameActionRunner.h"
#include "LargeSceneryRemoveAction.h"
#include "SmallSceneryRemoveAction.h"
#include "WallRemoveAction.h"
+1 -1
View File
@@ -11,7 +11,7 @@
#include "../OpenRCT2.h"
#include "../management/Finance.h"
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
+1 -1
View File
@@ -11,7 +11,7 @@
#ifdef ENABLE_SCRIPTING
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
@@ -9,7 +9,7 @@
#pragma once
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
@@ -9,7 +9,7 @@
#pragma once
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
@@ -10,7 +10,7 @@
#pragma once
#include "../world/Footpath.h"
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
+1 -1
View File
@@ -10,7 +10,7 @@
#pragma once
#include "../world/Footpath.h"
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
@@ -23,6 +23,7 @@
#include "../world/tile_element/BannerElement.h"
#include "../world/tile_element/PathElement.h"
#include "BannerRemoveAction.h"
#include "GameActionRunner.h"
namespace OpenRCT2::GameActions
{
+1 -1
View File
@@ -10,7 +10,7 @@
#pragma once
#include "../management/Finance.h"
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
+37 -451
View File
@@ -7,469 +7,21 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "GameAction.h"
#include "GameAction.hpp"
#include "../Context.h"
#include "../Diagnostic.h"
#include "../GameState.h"
#include "../ReplayManager.h"
#include "../core/Guard.hpp"
#include "../core/Memory.hpp"
#include "../core/MemoryStream.h"
#include "../entity/MoneyEffect.h"
#include "../localisation/Formatter.h"
#include "../network/Network.h"
#include "../platform/Platform.h"
#include "../profiling/Profiling.h"
#include "../scenario/Scenario.h"
#include "../scripting/Duktape.hpp"
#include "../scripting/HookEngine.h"
#include "../scripting/ScriptEngine.h"
#include "../ui/WindowManager.h"
#include "../world/Map.h"
#include "../world/Park.h"
#include "../world/Scenery.h"
#include "GameActionRegistry.h"
#include "GameActionRunner.h"
#include <iterator>
namespace OpenRCT2::GameActions
{
struct QueuedGameAction
{
uint32_t tick;
uint32_t uniqueId;
GameAction::Ptr action;
explicit QueuedGameAction(uint32_t t, std::unique_ptr<GameAction>&& ga, uint32_t id)
: tick(t)
, uniqueId(id)
, action(std::move(ga))
{
}
bool operator<(const QueuedGameAction& comp) const
{
// First sort by tick
if (tick < comp.tick)
return true;
if (tick > comp.tick)
return false;
// If the ticks are equal sort by commandIndex
return uniqueId < comp.uniqueId;
}
};
static std::multiset<QueuedGameAction> _actionQueue;
static uint32_t _nextUniqueId = 0;
static bool _suspended = false;
void SuspendQueue()
{
_suspended = true;
}
void ResumeQueue()
{
_suspended = false;
}
void Enqueue(const GameAction* ga, uint32_t tick)
{
auto action = Clone(ga);
Enqueue(std::move(action), tick);
}
void Enqueue(GameAction::Ptr&& ga, uint32_t tick)
{
if (ga->GetPlayer() == -1 && Network::GetMode() != Network::Mode::none)
{
// Server can directly invoke actions and will have no player id assigned
// as that normally happens when receiving them over network.
ga->SetPlayer(Network::GetCurrentPlayerId());
}
_actionQueue.emplace(tick, std::move(ga), _nextUniqueId++);
}
void ProcessQueue(GameState_t& gameState)
{
if (_suspended)
{
// Do nothing if suspended, this is usually the case between connect and map loads.
return;
}
const uint32_t currentTick = gameState.currentTicks;
while (_actionQueue.begin() != _actionQueue.end())
{
// run all the game commands at the current tick
const QueuedGameAction& queued = *_actionQueue.begin();
if (Network::GetMode() == Network::Mode::client)
{
if (queued.tick < currentTick)
{
// This should never happen.
Guard::Assert(
false,
"Discarding game action %s (%u) from tick behind current tick, ID: %08X, Action Tick: %08X, Current "
"Tick: "
"%08X\n",
queued.action->GetName(), queued.action->GetType(), queued.uniqueId, queued.tick, currentTick);
}
else if (queued.tick > currentTick)
{
return;
}
}
// Remove ghost scenery so it doesn't interfere with incoming network command
switch (queued.action->GetType())
{
case GameCommand::PlaceWall:
case GameCommand::PlaceLargeScenery:
case GameCommand::PlaceBanner:
case GameCommand::PlaceScenery:
SceneryRemoveGhostToolPlacement();
break;
default:
break;
}
GameAction* action = queued.action.get();
action->SetFlags(action->GetFlags().with(CommandFlag::networked));
Guard::Assert(action != nullptr);
Result result = Execute(action, gameState);
if (result.error == Status::ok && Network::GetMode() == Network::Mode::server)
{
// Relay this action to all other clients.
Network::SendGameAction(action);
}
_actionQueue.erase(_actionQueue.begin());
}
}
void ClearQueue()
{
_actionQueue.clear();
}
GameAction::Ptr Clone(const GameAction* action)
{
std::unique_ptr<GameAction> ga = Create(action->GetType());
ga->SetCallback(action->GetCallback());
// Serialise action data into stream.
DataSerialiser dsOut(true);
action->Serialise(dsOut);
// Serialise into new action.
IStream& stream = dsOut.GetStream();
stream.SetPosition(0);
DataSerialiser dsIn(false, stream);
ga->Serialise(dsIn);
return ga;
}
static bool CheckActionInPausedMode(const GameState_t& gameState, uint32_t actionFlags)
{
if (gGamePaused == 0)
return true;
if (gameState.cheats.buildInPauseMode)
return true;
if (actionFlags & Flags::AllowWhilePaused)
return true;
return false;
}
static Result QueryInternal(const GameAction* action, GameState_t& gameState, bool topLevel)
{
Guard::ArgumentNotNull(action);
uint16_t actionFlags = action->GetActionFlags();
if (topLevel && !CheckActionInPausedMode(gameState, actionFlags))
{
Result result = Result();
result.error = Status::gamePaused;
result.errorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE;
result.errorMessage = STR_CONSTRUCTION_NOT_POSSIBLE_WHILE_GAME_IS_PAUSED;
return result;
}
auto result = action->Query(gameState);
if (result.error == Status::ok)
{
if (!FinanceCheckAffordability(result.cost, action->GetFlags()))
{
result.error = Status::insufficientFunds;
result.errorTitle = STR_CANT_DO_THIS;
result.errorMessage = STR_NOT_ENOUGH_CASH_REQUIRES;
Formatter(result.errorMessageArgs.data()).Add<uint32_t>(result.cost);
}
}
return result;
}
Result Query(const GameAction* action, GameState_t& gameState)
{
return QueryInternal(action, gameState, true);
}
Result QueryNested(const GameAction* action, GameState_t& gameState)
{
return QueryInternal(action, gameState, false);
}
static const char* GetRealm()
{
if (Network::GetMode() == Network::Mode::client)
return "cl";
if (Network::GetMode() == Network::Mode::server)
return "sv";
return "sp";
}
struct ActionLogContext
{
MemoryStream output;
};
static void LogActionBegin(const GameState_t& gameState, ActionLogContext& ctx, const GameAction* action)
{
MemoryStream& output = ctx.output;
char temp[128] = {};
snprintf(
temp, sizeof(temp), "[%s] Tick: %u, GA: %s (%08X) (", GetRealm(), gameState.currentTicks, action->GetName(),
EnumValue(action->GetType()));
output.Write(temp, strlen(temp));
DataSerialiser ds(true, ctx.output, true); // Logging mode.
// Write all parameters into output as text.
action->Serialise(ds);
}
static void LogActionFinish(ActionLogContext& ctx, const GameAction* action, const Result& result)
{
MemoryStream& output = ctx.output;
char temp[128] = {};
if (result.error != Status::ok)
{
snprintf(temp, sizeof(temp), ") Failed, %u", static_cast<uint32_t>(result.error));
}
else
{
snprintf(temp, sizeof(temp), ") OK");
}
output.Write(temp, strlen(temp) + 1);
const char* text = static_cast<const char*>(output.GetData());
LOG_VERBOSE("%s", text);
Network::AppendServerLog(text);
}
static Result ExecuteInternal(const GameAction* action, GameState_t& gameState, bool topLevel)
{
Guard::ArgumentNotNull(action);
uint16_t actionFlags = action->GetActionFlags();
auto flags = action->GetFlags();
// Some actions are not recorded in the replay.
const auto ignoreForReplays = (actionFlags & Flags::IgnoreForReplays) != 0;
auto* replayManager = GetContext()->GetReplayManager();
if (replayManager != nullptr && (replayManager->IsReplaying() || replayManager->IsNormalising()))
{
// We only accept replay commands as long the replay is active.
if (!flags.has(CommandFlag::replay) && !ignoreForReplays)
{
// TODO: Introduce proper error.
auto result = Result();
result.error = Status::gamePaused;
result.errorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE;
result.errorMessage = STR_CONSTRUCTION_NOT_POSSIBLE_WHILE_GAME_IS_PAUSED;
return result;
}
}
Result result = QueryInternal(action, gameState, topLevel);
#ifdef ENABLE_SCRIPTING
if (result.error == Status::ok && ((Network::GetMode() == Network::Mode::none) || flags.has(CommandFlag::networked)))
{
auto& scriptEngine = GetContext()->GetScriptEngine();
scriptEngine.RunGameActionHooks(*action, result, false);
// Script hooks may now have changed the game action result...
}
#endif
if (result.error == Status::ok)
{
if (topLevel)
{
// Networked games send actions to the server to be run
if (Network::GetMode() == Network::Mode::client)
{
// As a client we have to wait or send it first.
if (!(actionFlags & Flags::ClientOnly) && !flags.has(CommandFlag::networked))
{
LOG_VERBOSE("[%s] GameAction::Execute %s (Out)", GetRealm(), action->GetName());
Network::SendGameAction(action);
return result;
}
}
else if (Network::GetMode() == Network::Mode::server || !gInUpdateCode)
{
// If player is the server it would execute right away as where clients execute the commands
// at the beginning of the frame, so we have to put them into the queue.
// This is also the case when its executed from the UI update.
if (!(actionFlags & Flags::ClientOnly) && !flags.has(CommandFlag::networked))
{
LOG_VERBOSE("[%s] GameAction::Execute %s (Queue)", GetRealm(), action->GetName());
Enqueue(action, gameState.currentTicks);
return result;
}
}
}
ActionLogContext logContext;
if (topLevel && !flags.has(CommandFlag::ghost))
{
LogActionBegin(gameState, logContext, action);
}
// Execute the action, changing the game state
result = action->Execute(gameState);
#ifdef ENABLE_SCRIPTING
if (result.error == Status::ok)
{
auto& scriptEngine = GetContext()->GetScriptEngine();
scriptEngine.RunGameActionHooks(*action, result, true);
// Script hooks may now have changed the game action result...
}
#endif
if (topLevel && !flags.has(CommandFlag::ghost))
{
LogActionFinish(logContext, action, result);
}
// If not top level just give away the result.
if (!topLevel)
return result;
// Update money balance
if (result.error == Status::ok && FinanceCheckMoneyRequired(flags) && result.cost != 0)
{
FinancePayment(result.cost, result.expenditure);
MoneyEffect::Create(result.cost, result.position);
}
if (!(actionFlags & Flags::ClientOnly) && result.error == Status::ok)
{
if (Network::GetMode() != Network::Mode::none)
{
Network::PlayerId_t playerId = action->GetPlayer();
int32_t playerIndex = Network::GetPlayerIndex(playerId.id);
Guard::Assert(
playerIndex != -1, "Unable to find player %u for game action %u", playerId, action->GetType());
Network::SetPlayerLastAction(playerIndex, action->GetType());
Network::IncrementPlayerNumCommands(playerIndex);
if (result.cost > 0)
{
Network::AddPlayerMoneySpent(playerIndex, result.cost);
}
if (!result.position.IsNull())
{
Network::SetPlayerLastActionCoord(playerIndex, result.position);
}
}
else
{
bool commandExecutes = !flags.hasAny(CommandFlag::ghost, CommandFlag::noSpend);
bool recordAction = false;
if (replayManager != nullptr && !ignoreForReplays)
{
if (replayManager->IsRecording() && commandExecutes)
recordAction = true;
else if (replayManager->IsNormalising() && flags.has(CommandFlag::replay))
recordAction = true; // In normalisation we only feed back actions issued by the replay manager.
}
if (recordAction)
{
replayManager->AddGameAction(gameState.currentTicks, action);
}
}
}
// Allow autosave to commence
if (gLastAutoSaveUpdate == kAutosavePause)
{
gLastAutoSaveUpdate = Platform::GetTicks();
}
}
// Call callback for asynchronous events
auto cb = action->GetCallback();
if (cb != nullptr)
{
cb(action, &result);
}
// Only show errors when its not a ghost and not a preview and also top level action.
bool shouldShowError = !flags.has(CommandFlag::ghost) && !flags.has(CommandFlag::noSpend) && topLevel;
// In network mode the error should be only shown to the issuer of the action.
if (Network::GetMode() != Network::Mode::none)
{
// If the action was never networked and query fails locally the player id is not assigned.
// So compare only if the action went into the queue otherwise show errors by default.
const bool isActionFromNetwork = action->GetFlags().has(CommandFlag::networked);
if (isActionFromNetwork && action->GetPlayer() != Network::GetCurrentPlayerId())
{
shouldShowError = false;
}
}
if (result.error != Status::ok && shouldShowError)
{
auto windowManager = Ui::GetWindowManager();
windowManager->ShowError(result.getErrorTitle(), result.getErrorMessage());
}
return result;
}
Result Execute(const GameAction* action, GameState_t& gameState)
{
return ExecuteInternal(action, gameState, true);
}
Result ExecuteNested(const GameAction* action, GameState_t& gameState)
{
return ExecuteInternal(action, gameState, false);
}
const char* GameAction::GetName() const
{
return GameActions::GetName(_type);
@@ -508,4 +60,38 @@ namespace OpenRCT2::GameActions
#endif
return true;
}
GameAction::Ptr Create(GameCommand id)
{
GameAction* result = nullptr;
auto factory = getFactory(id);
if (factory.has_value())
{
result = (*factory)();
}
Guard::ArgumentNotNull(result, "Attempting to create unregistered game action: %u", id);
return std::unique_ptr<GameAction>(result);
}
GameAction::Ptr Clone(const GameAction* action)
{
std::unique_ptr<GameAction> ga = Create(action->GetType());
ga->SetCallback(action->GetCallback());
// Serialise action data into stream.
DataSerialiser dsOut(true);
action->Serialise(dsOut);
// Serialise into new action.
IStream& stream = dsOut.GetStream();
stream.SetPosition(0);
DataSerialiser dsIn(false, stream);
ga->Serialise(dsIn);
return ga;
}
} // namespace OpenRCT2::GameActions
@@ -12,6 +12,7 @@
#include "../Game.h"
#include "../core/DataSerialiser.h"
#include "../core/Identifier.hpp"
#include "GameActionParameterVisitor.h"
#include "GameActionResult.h"
#include <functional>
@@ -39,76 +40,6 @@ namespace OpenRCT2::GameActions
#pragma GCC diagnostic ignored "-Wsuggest-final-types"
#endif
class GameActionParameterVisitor
{
public:
virtual ~GameActionParameterVisitor() = default;
virtual void Visit(std::string_view name, bool& param)
{
}
virtual void Visit(std::string_view name, int32_t& param)
{
}
virtual void Visit(std::string_view name, std::string& param)
{
}
void Visit(CoordsXY& param)
{
Visit("x", param.x);
Visit("y", param.y);
}
void Visit(CoordsXYZ& param)
{
Visit("x", param.x);
Visit("y", param.y);
Visit("z", param.z);
}
void Visit(CoordsXYZD& param)
{
Visit("x", param.x);
Visit("y", param.y);
Visit("z", param.z);
Visit("direction", param.direction);
}
void Visit(MapRange& param)
{
Visit("x1", param.Point1.x);
Visit("y1", param.Point1.y);
Visit("x2", param.Point2.x);
Visit("y2", param.Point2.y);
}
template<typename T>
void Visit(std::string_view name, T& param)
{
static_assert(std::is_arithmetic_v<T> || std::is_enum_v<T>, "Not an arithmetic type");
auto value = static_cast<int32_t>(param);
Visit(name, value);
param = static_cast<T>(value);
}
template<typename T, T TNull, typename TTag>
void Visit(std::string_view name, TIdentifier<T, TNull, TTag>& param)
{
auto value = param.ToUnderlying();
Visit(name, value);
param = TIdentifier<T, TNull, TTag>::FromUnderlying(value);
}
template<typename T, size_t _TypeID>
void Visit(std::string_view name, Network::NetworkObjectId<T, _TypeID>& param)
{
Visit(name, param.id);
}
};
class GameAction
{
public:
@@ -245,11 +176,6 @@ namespace OpenRCT2::GameActions
#pragma GCC diagnostic pop
#endif
template<GameCommand TId>
struct GameActionNameQuery
{
};
template<GameCommand TType>
struct GameActionBase : GameAction
{
@@ -262,33 +188,7 @@ namespace OpenRCT2::GameActions
}
};
using GameActionFactory = GameAction* (*)();
bool IsValidId(uint32_t id);
const char* GetName(GameCommand id);
// Halts the queue processing until ResumeQueue is called, any calls to ProcessQueue
// will have no effect during suspension. It has no effect of actions that will not
// cross the network.
void SuspendQueue();
// Resumes queue processing.
void ResumeQueue();
void Enqueue(const GameAction* ga, uint32_t tick);
void Enqueue(GameAction::Ptr&& ga, uint32_t tick);
void ProcessQueue(GameState_t& gameState);
void ClearQueue();
GameAction::Ptr Create(GameCommand id);
GameAction::Ptr Clone(const GameAction* action);
// This should be used if a round trip is to be expected.
Result Query(const GameAction* action, GameState_t& gameState);
Result Execute(const GameAction* action, GameState_t& gameState);
// This should be used from within game actions.
Result QueryNested(const GameAction* action, GameState_t& gameState);
Result ExecuteNested(const GameAction* action, GameState_t& gameState);
} // namespace OpenRCT2::GameActions
@@ -0,0 +1,102 @@
/*****************************************************************************
* Copyright (c) 2014-2026 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#pragma once
#include "../core/Identifier.hpp"
#include "../network/NetworkTypes.h"
#include "../world/Location.hpp"
#include <string>
#include <string_view>
namespace OpenRCT2::GameActions
{
// GCC 15.1 is overzealous with its 'final' warnings
#ifdef __WARN_SUGGEST_FINAL_METHODS__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
#pragma GCC diagnostic ignored "-Wsuggest-final-types"
#endif
class GameActionParameterVisitor
{
public:
virtual ~GameActionParameterVisitor() = default;
virtual void Visit(std::string_view name, bool& param)
{
}
virtual void Visit(std::string_view name, int32_t& param)
{
}
virtual void Visit(std::string_view name, std::string& param)
{
}
void Visit(CoordsXY& param)
{
Visit("x", param.x);
Visit("y", param.y);
}
void Visit(CoordsXYZ& param)
{
Visit("x", param.x);
Visit("y", param.y);
Visit("z", param.z);
}
void Visit(CoordsXYZD& param)
{
Visit("x", param.x);
Visit("y", param.y);
Visit("z", param.z);
Visit("direction", param.direction);
}
void Visit(MapRange& param)
{
Visit("x1", param.Point1.x);
Visit("y1", param.Point1.y);
Visit("x2", param.Point2.x);
Visit("y2", param.Point2.y);
}
template<typename T>
void Visit(std::string_view name, T& param)
{
static_assert(std::is_arithmetic_v<T> || std::is_enum_v<T>, "Not an arithmetic type");
auto value = static_cast<int32_t>(param);
Visit(name, value);
param = static_cast<T>(value);
}
template<typename T, T TNull, typename TTag>
void Visit(std::string_view name, TIdentifier<T, TNull, TTag>& param)
{
auto value = param.ToUnderlying();
Visit(name, value);
param = TIdentifier<T, TNull, TTag>::FromUnderlying(value);
}
template<typename T, size_t _TypeID>
void Visit(std::string_view name, Network::NetworkObjectId<T, _TypeID>& param)
{
Visit(name, param.id);
}
};
#ifdef __WARN_SUGGEST_FINAL_METHODS__
#pragma GCC diagnostic pop
#endif
} // namespace OpenRCT2::GameActions
+12 -18
View File
@@ -7,6 +7,8 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "GameActionRegistry.h"
#include "../core/Guard.hpp"
#include "BalloonPressAction.h"
#include "BannerPlaceAction.h"
@@ -22,7 +24,6 @@
#include "FootpathLayoutPlaceAction.h"
#include "FootpathPlaceAction.h"
#include "FootpathRemoveAction.h"
#include "GameAction.h"
#include "GameSetSpeedAction.h"
#include "GuestSetFlagsAction.h"
#include "GuestSetNameAction.h"
@@ -223,6 +224,16 @@ namespace OpenRCT2::GameActions
static constexpr GameActionRegistry _registry = BuildRegistry();
std::optional<GameActionFactory> getFactory(GameCommand id)
{
const auto idx = static_cast<size_t>(id);
if (idx < std::size(_registry))
{
return _registry[idx].factory;
}
return std::nullopt;
}
const char* GetName(GameCommand id)
{
const auto idx = static_cast<size_t>(id);
@@ -231,23 +242,6 @@ namespace OpenRCT2::GameActions
return _registry[idx].name;
}
std::unique_ptr<GameAction> Create(GameCommand id)
{
const auto idx = static_cast<size_t>(id);
GameAction* result = nullptr;
if (idx < std::size(_registry))
{
GameActionFactory factory = _registry[idx].factory;
if (factory != nullptr)
{
result = factory();
}
}
Guard::ArgumentNotNull(result, "Attempting to create unregistered game action: %u", id);
return std::unique_ptr<GameAction>(result);
}
bool IsValidId(uint32_t id)
{
if (id < std::size(_registry))
+27
View File
@@ -0,0 +1,27 @@
/*****************************************************************************
* Copyright (c) 2014-2026 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#pragma once
#include <cstdint>
#include <optional>
enum class GameCommand : int32_t;
namespace OpenRCT2::GameActions
{
class GameAction;
using GameActionFactory = GameAction* (*)();
std::optional<GameActionFactory> getFactory(GameCommand command);
const char* GetName(GameCommand id);
bool IsValidId(uint32_t id);
} // namespace OpenRCT2::GameActions
+455
View File
@@ -0,0 +1,455 @@
/*****************************************************************************
* Copyright (c) 2014-2026 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "GameActionRunner.h"
#include "../Context.h"
#include "../Diagnostic.h"
#include "../GameState.h"
#include "../ReplayManager.h"
#include "../core/Guard.hpp"
#include "../core/Memory.hpp"
#include "../core/MemoryStream.h"
#include "../entity/MoneyEffect.h"
#include "../localisation/Formatter.h"
#include "../network/Network.h"
#include "../platform/Platform.h"
#include "../profiling/Profiling.h"
#include "../scenario/Scenario.h"
#include "../scripting/Duktape.hpp"
#include "../scripting/HookEngine.h"
#include "../scripting/ScriptEngine.h"
#include "../ui/WindowManager.h"
#include "../world/Map.h"
#include "../world/Park.h"
#include "../world/Scenery.h"
#include "GameActionRegistry.h"
#include <iterator>
namespace OpenRCT2::GameActions
{
struct QueuedGameAction
{
uint32_t tick;
uint32_t uniqueId;
GameAction::Ptr action;
explicit QueuedGameAction(uint32_t t, std::unique_ptr<GameAction>&& ga, uint32_t id)
: tick(t)
, uniqueId(id)
, action(std::move(ga))
{
}
bool operator<(const QueuedGameAction& comp) const
{
// First sort by tick
if (tick < comp.tick)
return true;
if (tick > comp.tick)
return false;
// If the ticks are equal sort by commandIndex
return uniqueId < comp.uniqueId;
}
};
static std::multiset<QueuedGameAction> _actionQueue;
static uint32_t _nextUniqueId = 0;
static bool _suspended = false;
void SuspendQueue()
{
_suspended = true;
}
void ResumeQueue()
{
_suspended = false;
}
void Enqueue(const GameAction* ga, uint32_t tick)
{
auto action = Clone(ga);
Enqueue(std::move(action), tick);
}
void Enqueue(GameAction::Ptr&& ga, uint32_t tick)
{
if (ga->GetPlayer() == -1 && Network::GetMode() != Network::Mode::none)
{
// Server can directly invoke actions and will have no player id assigned
// as that normally happens when receiving them over network.
ga->SetPlayer(Network::GetCurrentPlayerId());
}
_actionQueue.emplace(tick, std::move(ga), _nextUniqueId++);
}
void ProcessQueue(GameState_t& gameState)
{
if (_suspended)
{
// Do nothing if suspended, this is usually the case between connect and map loads.
return;
}
const uint32_t currentTick = gameState.currentTicks;
while (_actionQueue.begin() != _actionQueue.end())
{
// run all the game commands at the current tick
const QueuedGameAction& queued = *_actionQueue.begin();
if (Network::GetMode() == Network::Mode::client)
{
if (queued.tick < currentTick)
{
// This should never happen.
Guard::Assert(
false,
"Discarding game action %s (%u) from tick behind current tick, ID: %08X, Action Tick: %08X, Current "
"Tick: "
"%08X\n",
queued.action->GetName(), queued.action->GetType(), queued.uniqueId, queued.tick, currentTick);
}
else if (queued.tick > currentTick)
{
return;
}
}
// Remove ghost scenery so it doesn't interfere with incoming network command
switch (queued.action->GetType())
{
case GameCommand::PlaceWall:
case GameCommand::PlaceLargeScenery:
case GameCommand::PlaceBanner:
case GameCommand::PlaceScenery:
SceneryRemoveGhostToolPlacement();
break;
default:
break;
}
GameAction* action = queued.action.get();
action->SetFlags(action->GetFlags().with(CommandFlag::networked));
Guard::Assert(action != nullptr);
Result result = Execute(action, gameState);
if (result.error == Status::ok && Network::GetMode() == Network::Mode::server)
{
// Relay this action to all other clients.
Network::SendGameAction(action);
}
_actionQueue.erase(_actionQueue.begin());
}
}
void ClearQueue()
{
_actionQueue.clear();
}
static bool CheckActionInPausedMode(const GameState_t& gameState, uint32_t actionFlags)
{
if (gGamePaused == 0)
return true;
if (gameState.cheats.buildInPauseMode)
return true;
if (actionFlags & Flags::AllowWhilePaused)
return true;
return false;
}
static Result QueryInternal(const GameAction* action, GameState_t& gameState, bool topLevel)
{
Guard::ArgumentNotNull(action);
uint16_t actionFlags = action->GetActionFlags();
if (topLevel && !CheckActionInPausedMode(gameState, actionFlags))
{
Result result = Result();
result.error = Status::gamePaused;
result.errorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE;
result.errorMessage = STR_CONSTRUCTION_NOT_POSSIBLE_WHILE_GAME_IS_PAUSED;
return result;
}
auto result = action->Query(gameState);
if (result.error == Status::ok)
{
if (!FinanceCheckAffordability(result.cost, action->GetFlags()))
{
result.error = Status::insufficientFunds;
result.errorTitle = STR_CANT_DO_THIS;
result.errorMessage = STR_NOT_ENOUGH_CASH_REQUIRES;
Formatter(result.errorMessageArgs.data()).Add<uint32_t>(result.cost);
}
}
return result;
}
Result Query(const GameAction* action, GameState_t& gameState)
{
return QueryInternal(action, gameState, true);
}
Result QueryNested(const GameAction* action, GameState_t& gameState)
{
return QueryInternal(action, gameState, false);
}
static const char* GetRealm()
{
if (Network::GetMode() == Network::Mode::client)
return "cl";
if (Network::GetMode() == Network::Mode::server)
return "sv";
return "sp";
}
struct ActionLogContext
{
MemoryStream output;
};
static void LogActionBegin(const GameState_t& gameState, ActionLogContext& ctx, const GameAction* action)
{
MemoryStream& output = ctx.output;
char temp[128] = {};
snprintf(
temp, sizeof(temp), "[%s] Tick: %u, GA: %s (%08X) (", GetRealm(), gameState.currentTicks, action->GetName(),
EnumValue(action->GetType()));
output.Write(temp, strlen(temp));
DataSerialiser ds(true, ctx.output, true); // Logging mode.
// Write all parameters into output as text.
action->Serialise(ds);
}
static void LogActionFinish(ActionLogContext& ctx, const GameAction* action, const Result& result)
{
MemoryStream& output = ctx.output;
char temp[128] = {};
if (result.error != Status::ok)
{
snprintf(temp, sizeof(temp), ") Failed, %u", static_cast<uint32_t>(result.error));
}
else
{
snprintf(temp, sizeof(temp), ") OK");
}
output.Write(temp, strlen(temp) + 1);
const char* text = static_cast<const char*>(output.GetData());
LOG_VERBOSE("%s", text);
Network::AppendServerLog(text);
}
static Result ExecuteInternal(const GameAction* action, GameState_t& gameState, bool topLevel)
{
Guard::ArgumentNotNull(action);
uint16_t actionFlags = action->GetActionFlags();
auto flags = action->GetFlags();
// Some actions are not recorded in the replay.
const auto ignoreForReplays = (actionFlags & Flags::IgnoreForReplays) != 0;
auto* replayManager = GetContext()->GetReplayManager();
if (replayManager != nullptr && (replayManager->IsReplaying() || replayManager->IsNormalising()))
{
// We only accept replay commands as long the replay is active.
if (!flags.has(CommandFlag::replay) && !ignoreForReplays)
{
// TODO: Introduce proper error.
auto result = Result();
result.error = Status::gamePaused;
result.errorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE;
result.errorMessage = STR_CONSTRUCTION_NOT_POSSIBLE_WHILE_GAME_IS_PAUSED;
return result;
}
}
Result result = QueryInternal(action, gameState, topLevel);
#ifdef ENABLE_SCRIPTING
if (result.error == Status::ok && ((Network::GetMode() == Network::Mode::none) || flags.has(CommandFlag::networked)))
{
auto& scriptEngine = GetContext()->GetScriptEngine();
scriptEngine.RunGameActionHooks(*action, result, false);
// Script hooks may now have changed the game action result...
}
#endif
if (result.error == Status::ok)
{
if (topLevel)
{
// Networked games send actions to the server to be run
if (Network::GetMode() == Network::Mode::client)
{
// As a client we have to wait or send it first.
if (!(actionFlags & Flags::ClientOnly) && !flags.has(CommandFlag::networked))
{
LOG_VERBOSE("[%s] GameAction::Execute %s (Out)", GetRealm(), action->GetName());
Network::SendGameAction(action);
return result;
}
}
else if (Network::GetMode() == Network::Mode::server || !gInUpdateCode)
{
// If player is the server it would execute right away as where clients execute the commands
// at the beginning of the frame, so we have to put them into the queue.
// This is also the case when its executed from the UI update.
if (!(actionFlags & Flags::ClientOnly) && !flags.has(CommandFlag::networked))
{
LOG_VERBOSE("[%s] GameAction::Execute %s (Queue)", GetRealm(), action->GetName());
Enqueue(action, gameState.currentTicks);
return result;
}
}
}
ActionLogContext logContext;
if (topLevel && !flags.has(CommandFlag::ghost))
{
LogActionBegin(gameState, logContext, action);
}
// Execute the action, changing the game state
result = action->Execute(gameState);
#ifdef ENABLE_SCRIPTING
if (result.error == Status::ok)
{
auto& scriptEngine = GetContext()->GetScriptEngine();
scriptEngine.RunGameActionHooks(*action, result, true);
// Script hooks may now have changed the game action result...
}
#endif
if (topLevel && !flags.has(CommandFlag::ghost))
{
LogActionFinish(logContext, action, result);
}
// If not top level just give away the result.
if (!topLevel)
return result;
// Update money balance
if (result.error == Status::ok && FinanceCheckMoneyRequired(flags) && result.cost != 0)
{
FinancePayment(result.cost, result.expenditure);
MoneyEffect::Create(result.cost, result.position);
}
if (!(actionFlags & Flags::ClientOnly) && result.error == Status::ok)
{
if (Network::GetMode() != Network::Mode::none)
{
Network::PlayerId_t playerId = action->GetPlayer();
int32_t playerIndex = Network::GetPlayerIndex(playerId.id);
Guard::Assert(
playerIndex != -1, "Unable to find player %u for game action %u", playerId, action->GetType());
Network::SetPlayerLastAction(playerIndex, action->GetType());
Network::IncrementPlayerNumCommands(playerIndex);
if (result.cost > 0)
{
Network::AddPlayerMoneySpent(playerIndex, result.cost);
}
if (!result.position.IsNull())
{
Network::SetPlayerLastActionCoord(playerIndex, result.position);
}
}
else
{
bool commandExecutes = !flags.hasAny(CommandFlag::ghost, CommandFlag::noSpend);
bool recordAction = false;
if (replayManager != nullptr && !ignoreForReplays)
{
if (replayManager->IsRecording() && commandExecutes)
recordAction = true;
else if (replayManager->IsNormalising() && flags.has(CommandFlag::replay))
recordAction = true; // In normalisation we only feed back actions issued by the replay manager.
}
if (recordAction)
{
replayManager->AddGameAction(gameState.currentTicks, action);
}
}
}
// Allow autosave to commence
if (gLastAutoSaveUpdate == kAutosavePause)
{
gLastAutoSaveUpdate = Platform::GetTicks();
}
}
// Call callback for asynchronous events
auto cb = action->GetCallback();
if (cb != nullptr)
{
cb(action, &result);
}
// Only show errors when its not a ghost and not a preview and also top level action.
bool shouldShowError = !flags.has(CommandFlag::ghost) && !flags.has(CommandFlag::noSpend) && topLevel;
// In network mode the error should be only shown to the issuer of the action.
if (Network::GetMode() != Network::Mode::none)
{
// If the action was never networked and query fails locally the player id is not assigned.
// So compare only if the action went into the queue otherwise show errors by default.
const bool isActionFromNetwork = action->GetFlags().has(CommandFlag::networked);
if (isActionFromNetwork && action->GetPlayer() != Network::GetCurrentPlayerId())
{
shouldShowError = false;
}
}
if (result.error != Status::ok && shouldShowError)
{
auto windowManager = Ui::GetWindowManager();
windowManager->ShowError(result.getErrorTitle(), result.getErrorMessage());
}
return result;
}
Result Execute(const GameAction* action, GameState_t& gameState)
{
return ExecuteInternal(action, gameState, true);
}
Result ExecuteNested(const GameAction* action, GameState_t& gameState)
{
return ExecuteInternal(action, gameState, false);
}
} // namespace OpenRCT2::GameActions
+42
View File
@@ -0,0 +1,42 @@
/*****************************************************************************
* Copyright (c) 2014-2026 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#pragma once
#include "../Game.h"
#include "GameAction.hpp"
namespace OpenRCT2
{
struct GameState_t;
}
namespace OpenRCT2::GameActions
{
// Halts the queue processing until ResumeQueue is called, any calls to ProcessQueue
// will have no effect during suspension. It has no effect of actions that will not
// cross the network.
void SuspendQueue();
// Resumes queue processing.
void ResumeQueue();
void Enqueue(const GameAction* ga, uint32_t tick);
void Enqueue(GameAction::Ptr&& ga, uint32_t tick);
void ProcessQueue(GameState_t& gameState);
void ClearQueue();
// This should be used if a round trip is to be expected.
Result Query(const GameAction* action, GameState_t& gameState);
Result Execute(const GameAction* action, GameState_t& gameState);
// This should be used from within game actions.
Result QueryNested(const GameAction* action, GameState_t& gameState);
Result ExecuteNested(const GameAction* action, GameState_t& gameState);
} // namespace OpenRCT2::GameActions
+1 -1
View File
@@ -9,7 +9,7 @@
#pragma once
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
+1 -1
View File
@@ -9,7 +9,7 @@
#pragma once
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
+1 -1
View File
@@ -9,7 +9,7 @@
#pragma once
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
+1 -1
View File
@@ -9,7 +9,7 @@
#pragma once
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
+1
View File
@@ -26,6 +26,7 @@
#include "../world/SurfaceData.h"
#include "../world/tile_element/Slope.h"
#include "../world/tile_element/SurfaceElement.h"
#include "GameActionRunner.h"
namespace OpenRCT2::GameActions
{
+1 -1
View File
@@ -9,7 +9,7 @@
#pragma once
#include "GameAction.h"
#include "GameAction.hpp"
enum class MapSelectType : uint8_t;
+1
View File
@@ -27,6 +27,7 @@
#include "../world/SurfaceData.h"
#include "../world/tile_element/Slope.h"
#include "../world/tile_element/SurfaceElement.h"
#include "GameActionRunner.h"
namespace OpenRCT2::GameActions
{
+1 -1
View File
@@ -9,7 +9,7 @@
#pragma once
#include "GameAction.h"
#include "GameAction.hpp"
enum class MapSelectType : uint8_t;
+1 -1
View File
@@ -9,7 +9,7 @@
#pragma once
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
+1 -1
View File
@@ -9,7 +9,7 @@
#pragma once
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
@@ -27,6 +27,7 @@
#include "../world/SurfaceData.h"
#include "../world/tile_element/Slope.h"
#include "../world/tile_element/SurfaceElement.h"
#include "GameActionRunner.h"
#include <algorithm>
+1 -1
View File
@@ -9,7 +9,7 @@
#pragma once
#include "GameAction.h"
#include "GameAction.hpp"
enum class MapSelectType : uint8_t;
@@ -9,7 +9,7 @@
#pragma once
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2
{
@@ -9,7 +9,7 @@
#pragma once
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
@@ -9,7 +9,7 @@
#pragma once
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
+1 -1
View File
@@ -10,7 +10,7 @@
#pragma once
#include "../interface/Window.h"
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
+1 -1
View File
@@ -10,7 +10,7 @@
#pragma once
#include "../world/Location.hpp"
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
+1 -1
View File
@@ -9,7 +9,7 @@
#pragma once
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
+1 -1
View File
@@ -9,7 +9,7 @@
#pragma once
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
@@ -9,7 +9,7 @@
#pragma once
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
@@ -9,7 +9,7 @@
#pragma once
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
@@ -9,7 +9,7 @@
#pragma once
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
+1 -1
View File
@@ -9,7 +9,7 @@
#pragma once
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
+1 -1
View File
@@ -9,7 +9,7 @@
#pragma once
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
@@ -9,7 +9,7 @@
#pragma once
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
+1 -1
View File
@@ -9,7 +9,7 @@
#pragma once
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
+1 -1
View File
@@ -9,7 +9,7 @@
#pragma once
#include "GameAction.h"
#include "GameAction.hpp"
namespace OpenRCT2::GameActions
{
Loaded 100 of 179 files, more files were not shown because too many files have changed in this diff. Show more