Files
OpenRCT2-Web/src/openrct2/actions/StaffSetNameAction.cpp
T

98 lines
3.1 KiB
C++
Raw Normal View History

/*****************************************************************************
2024-12-31 20:30:04 +01:00
* Copyright (c) 2014-2025 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 "StaffSetNameAction.h"
#include "../Cheats.h"
#include "../Context.h"
2024-07-09 16:23:31 +02:00
#include "../Diagnostic.h"
2025-08-31 14:29:36 +02:00
#include "../GameState.h"
#include "../core/MemoryStream.h"
#include "../drawing/Drawing.h"
2021-11-26 16:49:52 +02:00
#include "../entity/EntityRegistry.h"
2021-11-25 23:47:24 +02:00
#include "../entity/Staff.h"
#include "../localisation/StringIds.h"
#include "../windows/Intent.h"
#include "../world/Park.h"
namespace OpenRCT2::GameActions
{
StaffSetNameAction::StaffSetNameAction(EntityId spriteIndex, const std::string& name)
: _spriteIndex(spriteIndex)
, _name(name)
{
}
void StaffSetNameAction::AcceptParameters(GameActionParameterVisitor& visitor)
{
visitor.Visit("id", _spriteIndex);
visitor.Visit("name", _name);
}
uint16_t StaffSetNameAction::GetActionFlags() const
{
return GameAction::GetActionFlags() | Flags::AllowWhilePaused;
}
void StaffSetNameAction::Serialise(DataSerialiser& stream)
{
GameAction::Serialise(stream);
stream << DS_TAG(_spriteIndex) << DS_TAG(_name);
}
Result StaffSetNameAction::Query(GameState_t& gameState) const
{
if (_spriteIndex.ToUnderlying() >= kMaxEntities || _spriteIndex.IsNull())
{
LOG_ERROR("Invalid sprite index %u", _spriteIndex);
2025-12-12 11:41:49 +01:00
return Result(Status::invalidParameters, STR_STAFF_ERROR_CANT_NAME_STAFF_MEMBER, STR_ERR_VALUE_OUT_OF_RANGE);
}
2025-08-31 14:29:36 +02:00
auto staff = getGameState().entities.TryGetEntity<Staff>(_spriteIndex);
if (staff == nullptr)
{
LOG_ERROR("Staff entity not found for spriteIndex %u", _spriteIndex);
2025-12-12 11:41:49 +01:00
return Result(Status::invalidParameters, STR_STAFF_ERROR_CANT_NAME_STAFF_MEMBER, STR_ERR_STAFF_NOT_FOUND);
}
return Result();
}
Result StaffSetNameAction::Execute(GameState_t& gameState) const
{
2025-08-31 14:29:36 +02:00
auto staff = getGameState().entities.TryGetEntity<Staff>(_spriteIndex);
if (staff == nullptr)
{
LOG_ERROR("Staff entity not found for spriteIndex %u", _spriteIndex);
2025-12-12 11:41:49 +01:00
return Result(Status::invalidParameters, STR_STAFF_ERROR_CANT_NAME_STAFF_MEMBER, STR_ERR_STAFF_NOT_FOUND);
}
auto curName = staff->GetName();
if (curName == _name)
{
return Result();
}
if (!staff->SetName(_name))
{
2025-12-12 11:41:49 +01:00
return Result(Status::unknown, STR_CANT_NAME_GUEST, kStringIdNone);
}
2021-09-28 03:16:04 +03:00
GfxInvalidateScreen();
auto intent = Intent(INTENT_ACTION_REFRESH_STAFF_LIST);
ContextBroadcastIntent(&intent);
auto res = Result();
res.Position = staff->GetLocation();
return res;
}
} // namespace OpenRCT2::GameActions