From c1149895fa8a7f611081b21f0693a3fa285e7f3f Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Wed, 21 Sep 2022 19:14:43 +0200 Subject: [PATCH 1/2] Close #17955: Make ratings setting networked and freeze them --- distribution/changelog.txt | 1 + src/openrct2/Game.h | 1 + src/openrct2/actions/GameActionRegistry.cpp | 2 + .../actions/RideFreezeRatingAction.cpp | 66 +++++++++++++++++++ src/openrct2/actions/RideFreezeRatingAction.h | 35 ++++++++++ src/openrct2/interface/InteractiveConsole.cpp | 19 ++++-- src/openrct2/libopenrct2.vcxproj | 2 + src/openrct2/network/NetworkAction.cpp | 1 + src/openrct2/scripting/ScriptEngine.cpp | 1 + 9 files changed, 122 insertions(+), 6 deletions(-) create mode 100644 src/openrct2/actions/RideFreezeRatingAction.cpp create mode 100644 src/openrct2/actions/RideFreezeRatingAction.h diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 8ca521e781..55c14c4d96 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -21,6 +21,7 @@ - Improved: [#17868] [Plugin] You can now change active tab of a custom window programmatically. - Improved: [#17909] Track elements that are not supported by any train are now hidden by default. - Improved: [#17924] Improved performance when loading JSON object images from a .DAT file. +- Improved: [#17955] Modifying ratings via in-game console is now multiplayer-safe and also freezes the ratings. - Change: [#9104] Calculate maze support costs. - Change: [#17319] Giant screenshots are now cropped to the horizontal view-clipping selection. - Change: [#17499] Update error text when using vehicle incompatible with TD6 and add error when using incompatible track elements. diff --git a/src/openrct2/Game.h b/src/openrct2/Game.h index c9fb86cfc7..7d95769640 100644 --- a/src/openrct2/Game.h +++ b/src/openrct2/Game.h @@ -102,6 +102,7 @@ enum class GameCommand : int32_t SetDate, // GA Custom, // GA ChangeMapSize, + FreezeRideRating, Count, }; diff --git a/src/openrct2/actions/GameActionRegistry.cpp b/src/openrct2/actions/GameActionRegistry.cpp index 409c6bcceb..85113792c9 100644 --- a/src/openrct2/actions/GameActionRegistry.cpp +++ b/src/openrct2/actions/GameActionRegistry.cpp @@ -55,6 +55,7 @@ #include "RideDemolishAction.h" #include "RideEntranceExitPlaceAction.h" #include "RideEntranceExitRemoveAction.h" +#include "RideFreezeRatingAction.h" #include "RideSetAppearanceAction.h" #include "RideSetColourSchemeAction.h" #include "RideSetNameAction.h" @@ -159,6 +160,7 @@ namespace GameActions REGISTER_ACTION(RideSetNameAction); REGISTER_ACTION(RideSetPriceAction); REGISTER_ACTION(RideSetStatusAction); + REGISTER_ACTION(RideFreezeRatingAction); REGISTER_ACTION(RideSetAppearanceAction); REGISTER_ACTION(RideSetVehicleAction); REGISTER_ACTION(RideSetSettingAction); diff --git a/src/openrct2/actions/RideFreezeRatingAction.cpp b/src/openrct2/actions/RideFreezeRatingAction.cpp new file mode 100644 index 0000000000..c01c28284e --- /dev/null +++ b/src/openrct2/actions/RideFreezeRatingAction.cpp @@ -0,0 +1,66 @@ +/***************************************************************************** + * Copyright (c) 2014-2022 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 "RideFreezeRatingAction.h" + +RideFreezeRatingAction::RideFreezeRatingAction(RideId rideIndex, RideRatingType type, ride_rating value) + : _rideIndex(rideIndex) + , _type(type) + , _value(value) +{ +} + +void RideFreezeRatingAction::Serialise(DataSerialiser& stream) +{ + GameAction::Serialise(stream); + stream << DS_TAG(_rideIndex) << DS_TAG(_type) << DS_TAG(_value); +} + +GameActions::Result RideFreezeRatingAction::Query() const +{ + auto ride = get_ride(_rideIndex); + if (ride == nullptr) + { + log_warning("Invalid game command, ride_id = %u", _rideIndex.ToUnderlying()); + return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE); + } + + if (_value <= 0) + { + log_warning("Rating value must be positive", _rideIndex.ToUnderlying()); + return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE); + } + + return GameActions::Result(); +} + +GameActions::Result RideFreezeRatingAction::Execute() const +{ + auto ride = get_ride(_rideIndex); + + switch (_type) + { + case RideRatingType::Excitement: + ride->excitement = _value; + break; + case RideRatingType::Intensity: + ride->intensity = _value; + break; + case RideRatingType::Nausea: + ride->nausea = _value; + break; + } + + ride->lifecycle_flags |= RIDE_LIFECYCLE_FIXED_RATINGS; + + window_invalidate_by_number(WindowClass::Ride, _rideIndex.ToUnderlying()); + + auto res = GameActions::Result(); + return res; +} diff --git a/src/openrct2/actions/RideFreezeRatingAction.h b/src/openrct2/actions/RideFreezeRatingAction.h new file mode 100644 index 0000000000..bde58fa53b --- /dev/null +++ b/src/openrct2/actions/RideFreezeRatingAction.h @@ -0,0 +1,35 @@ +/***************************************************************************** + * Copyright (c) 2014-2022 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 "GameAction.h" + +enum class RideRatingType : uint8_t +{ + Excitement, + Intensity, + Nausea, +}; +// +class RideFreezeRatingAction final : public GameActionBase +{ +private: + RideId _rideIndex{ RideId::GetNull() }; + RideRatingType _type{}; + ride_rating _value{}; + +public: + RideFreezeRatingAction() = default; + RideFreezeRatingAction(RideId rideIndex, RideRatingType type, ride_rating value); + + void Serialise(DataSerialiser& stream) override; + GameActions::Result Query() const override; + GameActions::Result Execute() const override; +}; diff --git a/src/openrct2/interface/InteractiveConsole.cpp b/src/openrct2/interface/InteractiveConsole.cpp index d5da15d427..c1b4d4cf63 100644 --- a/src/openrct2/interface/InteractiveConsole.cpp +++ b/src/openrct2/interface/InteractiveConsole.cpp @@ -18,6 +18,7 @@ #include "../Version.h" #include "../actions/ClimateSetAction.h" #include "../actions/ParkSetParameterAction.h" +#include "../actions/RideFreezeRatingAction.h" #include "../actions/RideSetPriceAction.h" #include "../actions/RideSetSettingAction.h" #include "../actions/ScenarioSetSettingAction.h" @@ -299,7 +300,8 @@ static int32_t cc_rides(InteractiveConsole& console, const arguments_t& argv) } else { - auto ride = get_ride(RideId::FromUnderlying(ride_index)); + auto rideIndex = RideId::FromUnderlying(ride_index); + auto ride = get_ride(rideIndex); if (excitement <= 0) { console.WriteFormatLine("Excitement value must be strictly positive"); @@ -310,7 +312,8 @@ static int32_t cc_rides(InteractiveConsole& console, const arguments_t& argv) } else { - ride->excitement = excitement; + auto rideAction = RideFreezeRatingAction(rideIndex, RideRatingType::Excitement, excitement); + GameActions::Execute(&rideAction); } } } @@ -330,7 +333,8 @@ static int32_t cc_rides(InteractiveConsole& console, const arguments_t& argv) } else { - auto ride = get_ride(RideId::FromUnderlying(ride_index)); + auto rideIndex = RideId::FromUnderlying(ride_index); + auto ride = get_ride(rideIndex); if (intensity <= 0) { console.WriteFormatLine("Intensity value must be strictly positive"); @@ -341,7 +345,8 @@ static int32_t cc_rides(InteractiveConsole& console, const arguments_t& argv) } else { - ride->intensity = intensity; + auto rideAction = RideFreezeRatingAction(rideIndex, RideRatingType::Intensity, intensity); + GameActions::Execute(&rideAction); } } } @@ -361,7 +366,8 @@ static int32_t cc_rides(InteractiveConsole& console, const arguments_t& argv) } else { - auto ride = get_ride(RideId::FromUnderlying(ride_index)); + auto rideIndex = RideId::FromUnderlying(ride_index); + auto ride = get_ride(rideIndex); if (nausea <= 0) { console.WriteFormatLine("Nausea value must be strictly positive"); @@ -372,7 +378,8 @@ static int32_t cc_rides(InteractiveConsole& console, const arguments_t& argv) } else { - ride->nausea = nausea; + auto rideAction = RideFreezeRatingAction(rideIndex, RideRatingType::Nausea, nausea); + GameActions::Execute(&rideAction); } } } diff --git a/src/openrct2/libopenrct2.vcxproj b/src/openrct2/libopenrct2.vcxproj index 30268a37a8..18e745f8cf 100644 --- a/src/openrct2/libopenrct2.vcxproj +++ b/src/openrct2/libopenrct2.vcxproj @@ -111,6 +111,7 @@ + @@ -606,6 +607,7 @@ + diff --git a/src/openrct2/network/NetworkAction.cpp b/src/openrct2/network/NetworkAction.cpp index 1646f13dd3..df0c2adb1b 100644 --- a/src/openrct2/network/NetworkAction.cpp +++ b/src/openrct2/network/NetworkAction.cpp @@ -237,6 +237,7 @@ const std::array(NetworkPermission::Count)> N { GameCommand::Cheat, GameCommand::SetDate, + GameCommand::FreezeRideRating, }, }, NetworkAction{ diff --git a/src/openrct2/scripting/ScriptEngine.cpp b/src/openrct2/scripting/ScriptEngine.cpp index 2e4cdea0bc..34a8d68548 100644 --- a/src/openrct2/scripting/ScriptEngine.cpp +++ b/src/openrct2/scripting/ScriptEngine.cpp @@ -1310,6 +1310,7 @@ const static EnumMap ActionNameToType = { { "ridedemolish", GameCommand::DemolishRide }, { "rideentranceexitplace", GameCommand::PlaceRideEntranceOrExit }, { "rideentranceexitremove", GameCommand::RemoveRideEntranceOrExit }, + { "ridefreezerating", GameCommand::FreezeRideRating }, { "ridesetappearance", GameCommand::SetRideAppearance }, { "ridesetcolourscheme", GameCommand::SetColourScheme }, { "ridesetname", GameCommand::SetRideName }, From 8c40223af34c66baae34001247c201dee2e34a14 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Wed, 21 Sep 2022 20:45:17 +0200 Subject: [PATCH 2/2] Bump network and plugin API versions --- src/openrct2/network/NetworkBase.cpp | 2 +- src/openrct2/scripting/ScriptEngine.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/openrct2/network/NetworkBase.cpp b/src/openrct2/network/NetworkBase.cpp index bf7fe484ca..607b31288e 100644 --- a/src/openrct2/network/NetworkBase.cpp +++ b/src/openrct2/network/NetworkBase.cpp @@ -42,7 +42,7 @@ // This string specifies which version of network stream current build uses. // It is used for making sure only compatible builds get connected, even within // single OpenRCT2 version. -#define NETWORK_STREAM_VERSION "14" +#define NETWORK_STREAM_VERSION "15" #define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION static Peep* _pickup_peep = nullptr; diff --git a/src/openrct2/scripting/ScriptEngine.h b/src/openrct2/scripting/ScriptEngine.h index f5cbe26a17..b11cabd1b7 100644 --- a/src/openrct2/scripting/ScriptEngine.h +++ b/src/openrct2/scripting/ScriptEngine.h @@ -46,7 +46,7 @@ namespace OpenRCT2 namespace OpenRCT2::Scripting { - static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 59; + static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 60; // Versions marking breaking changes. static constexpr int32_t API_VERSION_33_PEEP_DEPRECATION = 33;