diff --git a/src/openrct2/actions/StaffHireNewAction.cpp b/src/openrct2/actions/StaffHireNewAction.cpp index de91f58366..5615118635 100644 --- a/src/openrct2/actions/StaffHireNewAction.cpp +++ b/src/openrct2/actions/StaffHireNewAction.cpp @@ -34,16 +34,6 @@ static constexpr const PeepSpriteType spriteTypes[] = { PeepSpriteType::EntertainerPanda, }; -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) -{ -} - StaffHireNewAction::StaffHireNewAction( bool autoPosition, StaffType staffType, EntertainerCostume entertainerType, uint32_t staffOrders) : _autoPosition(autoPosition) @@ -85,8 +75,7 @@ GameActions::Result::Ptr StaffHireNewAction::Execute() const GameActions::Result::Ptr StaffHireNewAction::QueryExecute(bool execute) const { - auto res = std::make_unique(); - + auto res = MakeResult(); res->Expenditure = ExpenditureType::Wages; if (_staffType >= static_cast(StaffType::Count)) @@ -94,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(_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(StaffType::Entertainer)) @@ -109,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(_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(); @@ -118,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(_entertainerType)); - return MakeResult(GameActions::Status::InvalidParameters, STR_NONE); + return MakeResult(GameActions::Status::InvalidParameters, STR_CANT_HIRE_NEW_STAFF, STR_NONE); } } @@ -133,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(); 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 { @@ -240,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; diff --git a/src/openrct2/actions/StaffHireNewAction.h b/src/openrct2/actions/StaffHireNewAction.h index bd4d94dc65..5b06979fa6 100644 --- a/src/openrct2/actions/StaffHireNewAction.h +++ b/src/openrct2/actions/StaffHireNewAction.h @@ -12,16 +12,12 @@ #include "../peep/Staff.h" #include "GameAction.h" -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{}; diff --git a/src/openrct2/peep/Staff.cpp b/src/openrct2/peep/Staff.cpp index 41e1829500..7b927b487d 100644 --- a/src/openrct2/peep/Staff.cpp +++ b/src/openrct2/peep/Staff.cpp @@ -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(); // Open window for new staff. - auto* staff = GetEntity(res->peepSriteIndex); + auto* staff = GetEntity(actionResult.StaffEntityId); auto intent = Intent(WC_PEEP); intent.putExtra(INTENT_EXTRA_PEEP, staff); context_open_intent(&intent); diff --git a/src/openrct2/scripting/ScriptEngine.cpp b/src/openrct2/scripting/ScriptEngine.cpp index 1208beeb0c..c90c4583e7 100644 --- a/src/openrct2/scripting/ScriptEngine.cpp +++ b/src/openrct2/scripting/ScriptEngine.cpp @@ -892,10 +892,13 @@ DukValue ScriptEngine::GameActionResultToDuk(const GameAction& action, const std } else if (action.GetType() == GameCommand::HireNewStaffMember) { - auto& staffHireResult = static_cast(*result.get()); - if (staffHireResult.peepSriteIndex != SPRITE_INDEX_NULL) + if (result->Error == GameActions::Status::Ok) { - obj.Set("peep", staffHireResult.peepSriteIndex); + const auto actionResult = result->GetData(); + if (actionResult.StaffEntityId != SPRITE_INDEX_NULL) + { + obj.Set("peep", actionResult.StaffEntityId); + } } }