diff --git a/src/openrct2-ui/windows/Guest.cpp b/src/openrct2-ui/windows/Guest.cpp index a1d0139936..0913983a95 100644 --- a/src/openrct2-ui/windows/Guest.cpp +++ b/src/openrct2-ui/windows/Guest.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -636,8 +637,13 @@ void window_guest_overview_mouse_up(rct_window* w, rct_widgetindex widgetIndex) window_scroll_to_viewport(w); break; case WIDX_TRACK: - get_sprite(w->number)->peep.peep_flags ^= PEEP_FLAGS_TRACKING; - break; + { + uint32_t flags = peep->peep_flags ^ PEEP_FLAGS_TRACKING; + + auto guestSetFlagsAction = GuestSetFlagsAction(w->number, flags); + GameActions::Execute(&guestSetFlagsAction); + } + break; } } diff --git a/src/openrct2/Game.h b/src/openrct2/Game.h index 7a495fb1ab..f4ef202186 100644 --- a/src/openrct2/Game.h +++ b/src/openrct2/Game.h @@ -96,6 +96,7 @@ enum GAME_COMMAND GAME_COMMAND_SET_STAFF_COSTUME, // GA GAME_COMMAND_PLACE_FOOTPATH_SCENERY, // GA GAME_COMMAND_REMOVE_FOOTPATH_SCENERY, // GA + GAME_COMMAND_GUEST_SET_FLAGS, // GA GAME_COMMAND_COUNT, }; diff --git a/src/openrct2/actions/GameActionRegistration.cpp b/src/openrct2/actions/GameActionRegistration.cpp index 065612940d..656ff7c000 100644 --- a/src/openrct2/actions/GameActionRegistration.cpp +++ b/src/openrct2/actions/GameActionRegistration.cpp @@ -16,6 +16,7 @@ #include "FootpathSceneryPlaceAction.hpp" #include "FootpathSceneryRemoveAction.hpp" #include "GameAction.h" +#include "GuestSetFlagsAction.hpp" #include "GuestSetNameAction.hpp" #include "LandLowerAction.hpp" #include "LandRaiseAction.hpp" @@ -113,5 +114,6 @@ namespace GameActions Register(); Register(); Register(); + Register(); } } // namespace GameActions diff --git a/src/openrct2/actions/GuestSetFlagsAction.hpp b/src/openrct2/actions/GuestSetFlagsAction.hpp new file mode 100644 index 0000000000..56a1b86fb9 --- /dev/null +++ b/src/openrct2/actions/GuestSetFlagsAction.hpp @@ -0,0 +1,70 @@ +/***************************************************************************** + * Copyright (c) 2014-2019 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 "../Context.h" +#include "../OpenRCT2.h" +#include "../world/Sprite.h" +#include "GameAction.h" + +DEFINE_GAME_ACTION(GuestSetFlagsAction, GAME_COMMAND_GUEST_SET_FLAGS, GameActionResult) +{ +private: + uint16_t _peepId = SPRITE_INDEX_NULL; + uint32_t _newFlags = 0; + +public: + GuestSetFlagsAction() + { + } + + GuestSetFlagsAction(uint16_t peepId, uint32_t flags) + : _peepId(peepId) + , _newFlags(flags) + { + } + + uint16_t GetActionFlags() const override + { + return GameAction::GetActionFlags() | GA_FLAGS::ALLOW_WHILE_PAUSED; + } + + void Serialise(DataSerialiser & stream) override + { + GameAction::Serialise(stream); + + stream << DS_TAG(_peepId) << DS_TAG(_newFlags); + } + + GameActionResult::Ptr Query() const override + { + Peep* peep = GET_PEEP(_peepId); + if (peep == nullptr) + { + log_error("Used invalid sprite index for peep: %u", (uint32_t)_peepId); + return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_CANT_CHANGE_THIS); + } + return std::make_unique(); + } + + GameActionResult::Ptr Execute() const override + { + Peep* peep = GET_PEEP(_peepId); + if (peep == nullptr) + { + log_error("Used invalid sprite index for peep: %u", (uint32_t)_peepId); + return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_CANT_CHANGE_THIS); + } + + peep->peep_flags = _newFlags; + + return std::make_unique(); + } +}; diff --git a/src/openrct2/network/NetworkAction.cpp b/src/openrct2/network/NetworkAction.cpp index bb1d338994..531be704eb 100644 --- a/src/openrct2/network/NetworkAction.cpp +++ b/src/openrct2/network/NetworkAction.cpp @@ -171,6 +171,7 @@ const std::array NetworkActions::Action GAME_COMMAND_SET_GUEST_NAME, GAME_COMMAND_PICKUP_GUEST, GAME_COMMAND_BALLOON_PRESS, + GAME_COMMAND_GUEST_SET_FLAGS, }, }, NetworkAction{ diff --git a/src/openrct2/network/Twitch.cpp b/src/openrct2/network/Twitch.cpp index 7718d2df75..0d812807c4 100644 --- a/src/openrct2/network/Twitch.cpp +++ b/src/openrct2/network/Twitch.cpp @@ -24,6 +24,7 @@ void twitch_update() # include "../Context.h" # include "../Game.h" # include "../OpenRCT2.h" +# include "../actions/GuestSetFlagsAction.hpp" # include "../config/Config.h" # include "../core/Json.hpp" # include "../core/String.hpp" @@ -442,30 +443,41 @@ namespace Twitch if (member == nullptr) { // Member no longer peep name worthy - peep->peep_flags &= ~(PEEP_FLAGS_TRACKING | PEEP_FLAGS_TWITCH); + uint32_t flags = peep->peep_flags & ~(PEEP_FLAGS_TRACKING | PEEP_FLAGS_TWITCH); + + auto guestSetFlagsAction = GuestSetFlagsAction(peep->sprite_index, flags); + GameActions::Execute(&guestSetFlagsAction); // TODO set peep name back to number / real name } else { + uint32_t flags = peep->peep_flags; if (member->ShouldTrack) { - peep->peep_flags |= (PEEP_FLAGS_TRACKING); + flags |= (PEEP_FLAGS_TRACKING); } else if (!member->ShouldTrack) { - peep->peep_flags &= ~(PEEP_FLAGS_TRACKING); + flags &= ~(PEEP_FLAGS_TRACKING); + } + if (flags != peep->peep_flags) + { + auto guestSetFlagsAction = GuestSetFlagsAction(peep->sprite_index, flags); + GameActions::Execute(&guestSetFlagsAction); } } } else if (member != nullptr && !(peep->peep_flags & PEEP_FLAGS_LEAVING_PARK)) { // Peep with same name already exists but not twitch - peep->peep_flags |= PEEP_FLAGS_TWITCH; + uint32_t flags = peep->peep_flags | PEEP_FLAGS_TWITCH; if (member->ShouldTrack) { - peep->peep_flags |= PEEP_FLAGS_TRACKING; + flags |= PEEP_FLAGS_TRACKING; } + auto guestSetFlagsAction = GuestSetFlagsAction(peep->sprite_index, flags); + GameActions::Execute(&guestSetFlagsAction); } } } @@ -498,11 +510,15 @@ namespace Twitch if (newStringId != 0) { peep->name_string_idx = newStringId; - peep->peep_flags |= PEEP_FLAGS_TWITCH; + + uint32_t flags = peep->peep_flags | PEEP_FLAGS_TWITCH; if (member->ShouldTrack) { - peep->peep_flags |= PEEP_FLAGS_TRACKING; + flags |= PEEP_FLAGS_TRACKING; } + + auto guestSetFlagsAction = GuestSetFlagsAction(peep->sprite_index, flags); + GameActions::Execute(&guestSetFlagsAction); } } else