1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-26 00:04:43 +01:00
Files
OpenRCT2/src/openrct2/actions/GuestSetFlagsAction.cpp
Duncan 0a47d2157a Use more specific types where appropriate (#14388)
It takes marginally more time to get a Peep than a Guest/Staff so may as well go straight to the correct type
2021-03-25 08:44:25 +00:00

64 lines
1.9 KiB
C++

/*****************************************************************************
* Copyright (c) 2014-2020 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 "GuestSetFlagsAction.h"
#include "../Context.h"
#include "../OpenRCT2.h"
#include "../world/Entity.h"
GuestSetFlagsAction::GuestSetFlagsAction(uint16_t peepId, uint32_t flags)
: _peepId(peepId)
, _newFlags(flags)
{
}
void GuestSetFlagsAction::AcceptParameters(GameActionParameterVisitor& visitor)
{
visitor.Visit("peep", _peepId);
visitor.Visit("flags", _newFlags);
}
uint16_t GuestSetFlagsAction::GetActionFlags() const
{
return GameAction::GetActionFlags() | GameActions::Flags::AllowWhilePaused;
}
void GuestSetFlagsAction::Serialise(DataSerialiser& stream)
{
GameAction::Serialise(stream);
stream << DS_TAG(_peepId) << DS_TAG(_newFlags);
}
GameActions::Result::Ptr GuestSetFlagsAction::Query() const
{
auto* peep = TryGetEntity<Guest>(_peepId);
if (peep == nullptr)
{
log_error("Used invalid sprite index for peep: %u", static_cast<uint32_t>(_peepId));
return MakeResult(GameActions::Status::InvalidParameters, STR_CANT_CHANGE_THIS);
}
return std::make_unique<GameActions::Result>();
}
GameActions::Result::Ptr GuestSetFlagsAction::Execute() const
{
auto* peep = TryGetEntity<Guest>(_peepId);
if (peep == nullptr)
{
log_error("Used invalid sprite index for peep: %u", static_cast<uint32_t>(_peepId));
return MakeResult(GameActions::Status::InvalidParameters, STR_CANT_CHANGE_THIS);
}
peep->PeepFlags = _newFlags;
return std::make_unique<GameActions::Result>();
}