2020-12-09 23:39:10 -07:00
|
|
|
/*****************************************************************************
|
2024-12-31 20:30:04 +01:00
|
|
|
* Copyright (c) 2014-2025 OpenRCT2 developers
|
2020-12-09 23:39:10 -07:00
|
|
|
*
|
|
|
|
|
* 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 "StaffFireAction.h"
|
|
|
|
|
|
2024-07-09 16:23:31 +02:00
|
|
|
#include "../Diagnostic.h"
|
2025-08-31 14:29:36 +02:00
|
|
|
#include "../GameState.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"
|
2025-01-19 18:49:18 +01:00
|
|
|
#include "../ui/WindowManager.h"
|
2020-12-09 23:39:10 -07:00
|
|
|
|
2025-08-26 18:34:31 +02:00
|
|
|
namespace OpenRCT2::GameActions
|
2020-12-12 04:18:38 -03:00
|
|
|
{
|
2025-08-26 18:34:31 +02:00
|
|
|
StaffFireAction::StaffFireAction(EntityId spriteId)
|
|
|
|
|
: _spriteId(spriteId)
|
2020-12-09 23:39:10 -07:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-26 18:34:31 +02:00
|
|
|
void StaffFireAction::AcceptParameters(GameActionParameterVisitor& visitor)
|
2020-12-09 23:39:10 -07:00
|
|
|
{
|
2025-08-26 18:34:31 +02:00
|
|
|
visitor.Visit("id", _spriteId);
|
2020-12-09 23:39:10 -07:00
|
|
|
}
|
|
|
|
|
|
2025-08-26 18:34:31 +02:00
|
|
|
uint16_t StaffFireAction::GetActionFlags() const
|
2023-05-21 19:36:08 +03:00
|
|
|
{
|
2025-08-26 18:34:31 +02:00
|
|
|
return GameAction::GetActionFlags() | Flags::AllowWhilePaused;
|
2023-05-21 19:36:08 +03:00
|
|
|
}
|
|
|
|
|
|
2025-08-26 18:34:31 +02:00
|
|
|
void StaffFireAction::Serialise(DataSerialiser& stream)
|
2020-12-09 23:39:10 -07:00
|
|
|
{
|
2025-08-26 18:34:31 +02:00
|
|
|
GameAction::Serialise(stream);
|
|
|
|
|
stream << DS_TAG(_spriteId);
|
2020-12-09 23:39:10 -07:00
|
|
|
}
|
2025-01-19 18:49:18 +01:00
|
|
|
|
2025-09-08 16:21:29 +02:00
|
|
|
Result StaffFireAction::Query(GameState_t& gameState) const
|
2025-08-26 18:34:31 +02:00
|
|
|
{
|
|
|
|
|
if (_spriteId.ToUnderlying() >= kMaxEntities || _spriteId.IsNull())
|
|
|
|
|
{
|
|
|
|
|
LOG_ERROR("Invalid spriteId %u", _spriteId);
|
2025-12-12 11:41:49 +01:00
|
|
|
return Result(Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE);
|
2025-08-26 18:34:31 +02:00
|
|
|
}
|
2025-01-19 18:49:18 +01:00
|
|
|
|
2025-08-31 14:29:36 +02:00
|
|
|
auto staff = getGameState().entities.TryGetEntity<Staff>(_spriteId);
|
2025-08-26 18:34:31 +02:00
|
|
|
if (staff == nullptr)
|
|
|
|
|
{
|
|
|
|
|
LOG_ERROR("Staff entity not found for spriteId %u", _spriteId);
|
2025-12-12 11:41:49 +01:00
|
|
|
return Result(Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_STAFF_NOT_FOUND);
|
2025-08-26 18:34:31 +02:00
|
|
|
}
|
2025-01-19 18:49:18 +01:00
|
|
|
|
2025-10-05 01:28:55 +02:00
|
|
|
if (staff->State == PeepState::fixing)
|
2025-08-26 18:34:31 +02:00
|
|
|
{
|
2025-12-12 11:41:49 +01:00
|
|
|
return Result(Status::disallowed, STR_CANT_FIRE_STAFF_FIXING, kStringIdNone);
|
2025-08-26 18:34:31 +02:00
|
|
|
}
|
2025-10-05 01:28:55 +02:00
|
|
|
else if (staff->State == PeepState::inspecting)
|
2025-08-26 18:34:31 +02:00
|
|
|
{
|
2025-12-12 11:41:49 +01:00
|
|
|
return Result(Status::disallowed, STR_CANT_FIRE_STAFF_INSPECTING, kStringIdNone);
|
2025-08-26 18:34:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Result();
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-08 16:21:29 +02:00
|
|
|
Result StaffFireAction::Execute(GameState_t& gameState) const
|
2025-08-26 18:34:31 +02:00
|
|
|
{
|
2025-08-31 14:29:36 +02:00
|
|
|
auto staff = getGameState().entities.TryGetEntity<Staff>(_spriteId);
|
2025-08-26 18:34:31 +02:00
|
|
|
if (staff == nullptr)
|
|
|
|
|
{
|
|
|
|
|
LOG_ERROR("Staff entity not found for spriteId %u", _spriteId);
|
2025-12-12 11:41:49 +01:00
|
|
|
return Result(Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_STAFF_NOT_FOUND);
|
2025-08-26 18:34:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto* windowMgr = Ui::GetWindowManager();
|
2025-09-17 23:18:52 +02:00
|
|
|
windowMgr->CloseByClass(WindowClass::firePrompt);
|
2025-08-26 18:34:31 +02:00
|
|
|
|
|
|
|
|
PeepEntityRemove(staff);
|
|
|
|
|
// Due to patrol areas best to invalidate the whole screen on removal of staff
|
|
|
|
|
GfxInvalidateScreen();
|
|
|
|
|
|
|
|
|
|
return Result();
|
|
|
|
|
}
|
|
|
|
|
} // namespace OpenRCT2::GameActions
|