mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-16 19:43:06 +01:00
Merge pull request #15528 from ZehMatt/refactor/staffhireaction-result
Refactor action result passing for StaffHireNewAction
This commit is contained in:
@@ -26,15 +26,13 @@
|
||||
#include "../world/Park.h"
|
||||
#include "../world/Sprite.h"
|
||||
|
||||
StaffHireNewActionResult::StaffHireNewActionResult()
|
||||
: GameActions::Result(GameActions::Status::Ok, STR_CANT_HIRE_NEW_STAFF)
|
||||
{
|
||||
}
|
||||
|
||||
StaffHireNewActionResult::StaffHireNewActionResult(GameActions::Status error, rct_string_id message)
|
||||
: GameActions::Result(error, STR_CANT_HIRE_NEW_STAFF, message)
|
||||
{
|
||||
}
|
||||
/* rct2: 0x009929FC */
|
||||
static constexpr const PeepSpriteType spriteTypes[] = {
|
||||
PeepSpriteType::Handyman,
|
||||
PeepSpriteType::Mechanic,
|
||||
PeepSpriteType::Security,
|
||||
PeepSpriteType::EntertainerPanda,
|
||||
};
|
||||
|
||||
StaffHireNewAction::StaffHireNewAction(
|
||||
bool autoPosition, StaffType staffType, EntertainerCostume entertainerType, uint32_t staffOrders)
|
||||
@@ -77,8 +75,7 @@ GameActions::Result::Ptr StaffHireNewAction::Execute() const
|
||||
|
||||
GameActions::Result::Ptr StaffHireNewAction::QueryExecute(bool execute) const
|
||||
{
|
||||
auto res = std::make_unique<StaffHireNewActionResult>();
|
||||
|
||||
auto res = MakeResult();
|
||||
res->Expenditure = ExpenditureType::Wages;
|
||||
|
||||
if (_staffType >= static_cast<uint8_t>(StaffType::Count))
|
||||
@@ -86,12 +83,12 @@ GameActions::Result::Ptr StaffHireNewAction::QueryExecute(bool execute) const
|
||||
// Invalid staff type.
|
||||
log_error("Tried to use invalid staff type: %u", static_cast<uint32_t>(_staffType));
|
||||
|
||||
return MakeResult(GameActions::Status::InvalidParameters, STR_NONE);
|
||||
return MakeResult(GameActions::Status::InvalidParameters, STR_CANT_HIRE_NEW_STAFF, STR_NONE);
|
||||
}
|
||||
|
||||
if (GetNumFreeEntities() < 400)
|
||||
{
|
||||
return MakeResult(GameActions::Status::NoFreeElements, STR_TOO_MANY_PEOPLE_IN_GAME);
|
||||
return MakeResult(GameActions::Status::NoFreeElements, STR_CANT_HIRE_NEW_STAFF, STR_TOO_MANY_PEOPLE_IN_GAME);
|
||||
}
|
||||
|
||||
if (_staffType == static_cast<uint8_t>(StaffType::Entertainer))
|
||||
@@ -101,7 +98,7 @@ GameActions::Result::Ptr StaffHireNewAction::QueryExecute(bool execute) const
|
||||
// Invalid entertainer costume
|
||||
log_error("Tried to use invalid entertainer type: %u", static_cast<uint32_t>(_entertainerType));
|
||||
|
||||
return MakeResult(GameActions::Status::InvalidParameters, STR_NONE);
|
||||
return MakeResult(GameActions::Status::InvalidParameters, STR_CANT_HIRE_NEW_STAFF, STR_NONE);
|
||||
}
|
||||
|
||||
uint32_t availableCostumes = staff_get_available_entertainer_costumes();
|
||||
@@ -110,7 +107,7 @@ GameActions::Result::Ptr StaffHireNewAction::QueryExecute(bool execute) const
|
||||
// Entertainer costume unavailable
|
||||
log_error("Tried to use unavailable entertainer type: %u", static_cast<uint32_t>(_entertainerType));
|
||||
|
||||
return MakeResult(GameActions::Status::InvalidParameters, STR_NONE);
|
||||
return MakeResult(GameActions::Status::InvalidParameters, STR_CANT_HIRE_NEW_STAFF, STR_NONE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,20 +122,22 @@ GameActions::Result::Ptr StaffHireNewAction::QueryExecute(bool execute) const
|
||||
if (staffIndex == STAFF_MAX_COUNT)
|
||||
{
|
||||
// Too many staff members exist already.
|
||||
return MakeResult(GameActions::Status::NoFreeElements, STR_TOO_MANY_STAFF_IN_GAME);
|
||||
return MakeResult(GameActions::Status::NoFreeElements, STR_CANT_HIRE_NEW_STAFF, STR_TOO_MANY_STAFF_IN_GAME);
|
||||
}
|
||||
|
||||
Staff* newPeep = CreateEntity<Staff>();
|
||||
if (newPeep == nullptr)
|
||||
{
|
||||
// Too many peeps exist already.
|
||||
return MakeResult(GameActions::Status::NoFreeElements, STR_TOO_MANY_PEOPLE_IN_GAME);
|
||||
return MakeResult(GameActions::Status::NoFreeElements, STR_CANT_HIRE_NEW_STAFF, STR_TOO_MANY_PEOPLE_IN_GAME);
|
||||
}
|
||||
|
||||
if (execute == false)
|
||||
{
|
||||
// In query we just want to see if we can obtain a sprite slot.
|
||||
sprite_remove(newPeep);
|
||||
|
||||
res->SetData(StaffHireNewActionResult{ SPRITE_INDEX_NULL });
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -232,7 +231,7 @@ GameActions::Result::Ptr StaffHireNewAction::QueryExecute(bool execute) const
|
||||
gStaffPatrolAreas[staffIndex * STAFF_PATROL_AREA_SIZE + i] = 0;
|
||||
}
|
||||
|
||||
res->peepSriteIndex = newPeep->sprite_index;
|
||||
res->SetData(StaffHireNewActionResult{ newPeep->sprite_index });
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
@@ -12,24 +12,12 @@
|
||||
#include "../peep/Staff.h"
|
||||
#include "GameAction.h"
|
||||
|
||||
/* rct2: 0x009929FC */
|
||||
static constexpr const PeepSpriteType spriteTypes[] = {
|
||||
PeepSpriteType::Handyman,
|
||||
PeepSpriteType::Mechanic,
|
||||
PeepSpriteType::Security,
|
||||
PeepSpriteType::EntertainerPanda,
|
||||
};
|
||||
|
||||
class StaffHireNewActionResult final : public GameActions::Result
|
||||
struct StaffHireNewActionResult
|
||||
{
|
||||
public:
|
||||
StaffHireNewActionResult();
|
||||
StaffHireNewActionResult(GameActions::Status error, rct_string_id message);
|
||||
|
||||
uint32_t peepSriteIndex = SPRITE_INDEX_NULL;
|
||||
uint16_t StaffEntityId = SPRITE_INDEX_NULL;
|
||||
};
|
||||
|
||||
DEFINE_GAME_ACTION(StaffHireNewAction, GameCommand::HireNewStaffMember, StaffHireNewActionResult)
|
||||
DEFINE_GAME_ACTION(StaffHireNewAction, GameCommand::HireNewStaffMember, GameActions::Result)
|
||||
{
|
||||
private:
|
||||
bool _autoPosition{};
|
||||
|
||||
@@ -120,12 +120,13 @@ bool staff_hire_new_member(StaffType staffType, EntertainerCostume entertainerTy
|
||||
}
|
||||
|
||||
auto hireStaffAction = StaffHireNewAction(autoPosition, staffType, entertainerType, staffOrders);
|
||||
hireStaffAction.SetCallback([=](const GameAction*, const StaffHireNewActionResult* res) -> void {
|
||||
hireStaffAction.SetCallback([=](const GameAction*, const GameActions::Result* res) -> void {
|
||||
if (res->Error != GameActions::Status::Ok)
|
||||
return;
|
||||
|
||||
auto actionResult = res->GetData<StaffHireNewActionResult>();
|
||||
// Open window for new staff.
|
||||
auto* staff = GetEntity<Staff>(res->peepSriteIndex);
|
||||
auto* staff = GetEntity<Staff>(actionResult.StaffEntityId);
|
||||
auto intent = Intent(WC_PEEP);
|
||||
intent.putExtra(INTENT_EXTRA_PEEP, staff);
|
||||
context_open_intent(&intent);
|
||||
|
||||
@@ -892,10 +892,13 @@ DukValue ScriptEngine::GameActionResultToDuk(const GameAction& action, const std
|
||||
}
|
||||
else if (action.GetType() == GameCommand::HireNewStaffMember)
|
||||
{
|
||||
auto& staffHireResult = static_cast<StaffHireNewActionResult&>(*result.get());
|
||||
if (staffHireResult.peepSriteIndex != SPRITE_INDEX_NULL)
|
||||
if (result->Error == GameActions::Status::Ok)
|
||||
{
|
||||
obj.Set("peep", staffHireResult.peepSriteIndex);
|
||||
const auto actionResult = result->GetData<StaffHireNewActionResult>();
|
||||
if (actionResult.StaffEntityId != SPRITE_INDEX_NULL)
|
||||
{
|
||||
obj.Set("peep", actionResult.StaffEntityId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user