Fix #8900: Implement GuestSetFlagsAction.

This commit is contained in:
Matt 2019-03-16 22:25:56 +01:00
parent 8bf693983a
commit 57283a4e2b
6 changed files with 105 additions and 9 deletions

View File

@ -13,6 +13,7 @@
#include <openrct2/Context.h>
#include <openrct2/Game.h>
#include <openrct2/Input.h>
#include <openrct2/actions/GuestSetFlagsAction.hpp>
#include <openrct2/config/Config.h>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/management/Marketing.h>
@ -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;
}
}

View File

@ -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,
};

View File

@ -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<WaterSetHeightAction>();
Register<WaterLowerAction>();
Register<WaterRaiseAction>();
Register<GuestSetFlagsAction>();
}
} // namespace GameActions

View File

@ -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>();
}
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<GameActionResult>();
}
};

View File

@ -171,6 +171,7 @@ const std::array<NetworkAction, NETWORK_PERMISSION_COUNT> NetworkActions::Action
GAME_COMMAND_SET_GUEST_NAME,
GAME_COMMAND_PICKUP_GUEST,
GAME_COMMAND_BALLOON_PRESS,
GAME_COMMAND_GUEST_SET_FLAGS,
},
},
NetworkAction{

View File

@ -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