From b068331db2a92b8354bb66e93d26e9598fa4fffd Mon Sep 17 00:00:00 2001 From: Ted John Date: Fri, 21 Jul 2017 18:08:45 +0100 Subject: [PATCH] Move contents of IGameAction.h into GameAction.h --- src/openrct2/actions/GameAction.h | 124 ++++++++++++++++++++++++- src/openrct2/actions/IGameAction.h | 140 ----------------------------- src/openrct2/network/network.h | 2 +- 3 files changed, 121 insertions(+), 145 deletions(-) delete mode 100644 src/openrct2/actions/IGameAction.h diff --git a/src/openrct2/actions/GameAction.h b/src/openrct2/actions/GameAction.h index 3d31fe6454..3c47a19b5c 100644 --- a/src/openrct2/actions/GameAction.h +++ b/src/openrct2/actions/GameAction.h @@ -16,12 +16,128 @@ #pragma once -extern "C" { -#include "../platform/platform.h" +#include +#include + +#include "../common.h" +#include "../core/DataSerialiser.h" +#include "../core/IStream.hpp" + +extern "C" +{ + #include "../game.h" + #include "../world/map.h" } -#include -#include "IGameAction.h" +/** + * Common error codes for game actions. + */ +enum class GA_ERROR : uint16 +{ + OK, + INVALID_PARAMETERS, + DISALLOWED, + GAME_PAUSED, + INSUFFICIENT_FUNDS, + NOT_IN_EDITOR_MODE, + + NOT_OWNED, + TOO_LOW, + TOO_HIGH, + NO_CLEARANCE, + ITEM_ALREADY_PLACED, + + NO_FREE_ELEMENTS, + + UNKNOWN = UINT16_MAX, +}; + +namespace GA_FLAGS +{ + constexpr uint16 ALLOW_WHILE_PAUSED = 1 << 0; + constexpr uint16 CLIENT_ONLY = 1 << 1; + constexpr uint16 EDITOR_ONLY = 1 << 2; +} + +/** + * Represents the result of a game action query or execution. + */ +struct GameActionResult +{ + typedef std::unique_ptr Ptr; + + GA_ERROR Error = GA_ERROR::OK; + rct_string_id ErrorTitle = (rct_string_id)-1; + rct_string_id ErrorMessage = (rct_string_id)-1; + uint8 ErrorMessageArgs[8] = { 0 }; + rct_xyz32 Position = { 0 }; + money32 Cost = 0; + uint16 ExpenditureType = 0; + + GameActionResult(); + GameActionResult(GA_ERROR error, rct_string_id message); + GameActionResult(const GameActionResult&) = delete; +}; + +typedef std::function GameActionCallback_t; + +/** + * Represents an action that changes the state of the game. Can be serialised and + * deserialised into a stream. + */ +struct IGameAction +{ +public: + typedef std::unique_ptr Ptr; + + /** + * Gets the GA_FLAGS flags that are enabled for this game action. + */ + virtual uint16 GetActionFlags() const abstract; + + /** + * Currently used for GAME_COMMAND_FLAGS, needs refactoring once everything is replaced. + */ + virtual uint32 GetFlags() const abstract; + virtual uint32 SetFlags(uint32 flags) abstract; + + virtual uint32 GetType() const abstract; + + /** + * Gets/Sets player who owns this action, 0 if server or local client. + */ + virtual void SetPlayer(uint32 playerId) abstract; + virtual uint32 GetPlayer() const abstract; + + virtual void SetCallback(const GameActionCallback_t& cb) abstract; + virtual const GameActionCallback_t& GetCallback() const abstract; + + virtual void SetNetworkId(uint32_t id) abstract; + virtual uint32 GetNetworkId() const abstract; + + /** + * Writes or reads the game action directly to the given stream. Used for + * sending across the network in multiplayer. + */ + virtual void Serialise(DataSerialiser& stream) abstract; + + // Helper function, allows const Objects to still serialize into DataSerialiser while being const. + void Serialise(DataSerialiser& stream) const + { + return const_cast(*this).Serialise(stream); + } + + /** + * Query the result of the game action without changing the game state. + */ + virtual GameActionResult::Ptr Query() const abstract; + + /** + * Apply the game action and change the game state. + */ + virtual ~IGameAction() {}; + virtual GameActionResult::Ptr Execute() const abstract; +}; typedef IGameAction *(*GameActionFactory)(); diff --git a/src/openrct2/actions/IGameAction.h b/src/openrct2/actions/IGameAction.h deleted file mode 100644 index 4840a22089..0000000000 --- a/src/openrct2/actions/IGameAction.h +++ /dev/null @@ -1,140 +0,0 @@ -#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers -/***************************************************************************** -* OpenRCT2, an open source clone of Roller Coaster Tycoon 2. -* -* OpenRCT2 is the work of many authors, a full list can be found in contributors.md -* For more information, visit https://github.com/OpenRCT2/OpenRCT2 -* -* OpenRCT2 is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* A full copy of the GNU General Public License can be found in licence.txt -*****************************************************************************/ -#pragma endregion - -#pragma once - -#include -#include - -#include "../common.h" -#include "../core/IStream.hpp" -#include "../core/DataSerialiser.h" - -extern "C" -{ -#include "../game.h" -#include "../world/map.h" -} - -/** -* Common error codes for game actions. -*/ -enum class GA_ERROR : uint16 -{ - OK, - INVALID_PARAMETERS, - DISALLOWED, - GAME_PAUSED, - INSUFFICIENT_FUNDS, - NOT_IN_EDITOR_MODE, - - NOT_OWNED, - TOO_LOW, - TOO_HIGH, - NO_CLEARANCE, - ITEM_ALREADY_PLACED, - - NO_FREE_ELEMENTS, - - UNKNOWN = UINT16_MAX, -}; - -namespace GA_FLAGS -{ -constexpr uint16 ALLOW_WHILE_PAUSED = 1 << 0; -constexpr uint16 CLIENT_ONLY = 1 << 1; -constexpr uint16 EDITOR_ONLY = 1 << 2; -} - -/** -* Represents the result of a game action query or execution. -*/ -struct GameActionResult -{ - typedef std::unique_ptr Ptr; - - GA_ERROR Error = GA_ERROR::OK; - rct_string_id ErrorTitle = (rct_string_id)-1; - rct_string_id ErrorMessage = (rct_string_id)-1; - uint8 ErrorMessageArgs[8] = { 0 }; - rct_xyz32 Position = { 0 }; - money32 Cost = 0; - uint16 ExpenditureType = 0; - - GameActionResult(); - GameActionResult(GA_ERROR error, rct_string_id message); - GameActionResult(const GameActionResult&) = delete; -}; - -typedef std::function GameActionCallback_t; - -/** -* Represents an action that changes the state of the game. Can be serialised and -* deserialised into a stream. -*/ -struct IGameAction -{ -public: - typedef std::unique_ptr Ptr; - - /** - * Gets the GA_FLAGS flags that are enabled for this game action. - */ - virtual uint16 GetActionFlags() const abstract; - - /** - * Currently used for GAME_COMMAND_FLAGS, needs refactoring once everything is replaced. - */ - virtual uint32 GetFlags() const abstract; - virtual uint32 SetFlags(uint32 flags) abstract; - - virtual uint32 GetType() const abstract; - - /** - * Gets/Sets player who owns this action, 0 if server or local client. - */ - virtual void SetPlayer(uint32 playerId) abstract; - virtual uint32 GetPlayer() const abstract; - - virtual void SetCallback(const GameActionCallback_t& cb) abstract; - virtual const GameActionCallback_t& GetCallback() const abstract; - - virtual void SetNetworkId(uint32_t id) abstract; - virtual uint32 GetNetworkId() const abstract; - - /** - * Writes or reads the game action directly to the given stream. Used for - * sending across the network in multiplayer. - */ - virtual void Serialise(DataSerialiser& stream) abstract; - - // Helper function, allows const Objects to still serialize into DataSerialiser while being const. - void Serialise(DataSerialiser& stream) const - { - return const_cast(*this).Serialise(stream); - } - - /** - * Query the result of the game action without changing the game state. - */ - virtual GameActionResult::Ptr Query() const abstract; - - /** - * Apply the game action and change the game state. - */ - virtual ~IGameAction() {}; - virtual GameActionResult::Ptr Execute() const abstract; -}; diff --git a/src/openrct2/network/network.h b/src/openrct2/network/network.h index bb185df37d..7fcaca8520 100644 --- a/src/openrct2/network/network.h +++ b/src/openrct2/network/network.h @@ -65,6 +65,7 @@ typedef struct IGameAction IGameAction; #include #include #include +#include "../actions/GameAction.h" #include "../core/Json.hpp" #include "../core/Nullable.hpp" #include "../core/MemoryStream.h" @@ -76,7 +77,6 @@ typedef struct IGameAction IGameAction; #include "NetworkServerAdvertiser.h" #include "NetworkUser.h" #include "TcpSocket.h" -#include "../actions/IGameAction.h" enum { NETWORK_TICK_FLAG_CHECKSUMS = 1 << 0,