From b1b056ec522fc84f87a8aeaed2bb06b35d6ca3c6 Mon Sep 17 00:00:00 2001 From: mdbckrtn Date: Fri, 27 Jan 2023 03:20:59 -0500 Subject: [PATCH] Fix #18839: New staff members now picked up correctly (#18956) * Fix #18839: New staff members now picked up correctly When "Automatically place staff" is disabled, new staff members were not automatically placed into the "picked" state as is the case with vanilla RCT. This change ensures that new staff members are automatically placed into the picker and that, in scenarios where multiple new staff members are queued up without having first placed one, the most recently created staff member will be the actively picked up peep (also the case with vanilla). * Fix #18839: Address networking issues * Fix #18839: Add else to pickup action intent. --- src/openrct2-ui/windows/StaffList.cpp | 36 ++++++++++++++++++++--- src/openrct2/actions/PeepPickupAction.cpp | 1 - 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/openrct2-ui/windows/StaffList.cpp b/src/openrct2-ui/windows/StaffList.cpp index 7027cbc8a4..8c343ddc0d 100644 --- a/src/openrct2-ui/windows/StaffList.cpp +++ b/src/openrct2-ui/windows/StaffList.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -526,11 +527,38 @@ private: return; auto actionResult = res->GetData(); - // Open window for new staff. auto* staff = GetEntity(actionResult.StaffEntityId); - auto intent = Intent(WindowClass::Peep); - intent.PutExtra(INTENT_EXTRA_PEEP, staff); - ContextOpenIntent(&intent); + + // If autoposition of staff is disabled, pickup peep and then open the staff window + if (staff->State == PeepState::Picked) + { + picked_peep_old_x = staff->x; + CoordsXYZ nullLoc{}; + nullLoc.SetNull(); + + PeepPickupAction pickupAction{ PeepPickupType::Pickup, staff->sprite_index, nullLoc, + NetworkGetCurrentPlayerId() }; + pickupAction.SetCallback([&staff](const GameAction* ga, const GameActions::Result* result) { + if (result->Error != GameActions::Status::Ok) + return; + + auto intent = Intent(WindowClass::Peep); + intent.PutExtra(INTENT_EXTRA_PEEP, staff); + auto* wind = ContextOpenIntent(&intent); + if (wind != nullptr) + { + ToolSet(*wind, WC_STAFF__WIDX_PICKUP, Tool::Picker); + } + }); + GameActions::Execute(&pickupAction); + } + else + { + // Open window for new staff. + auto intent = Intent(WindowClass::Peep); + intent.PutExtra(INTENT_EXTRA_PEEP, staff); + ContextOpenIntent(&intent); + } }); GameActions::Execute(&hireStaffAction); diff --git a/src/openrct2/actions/PeepPickupAction.cpp b/src/openrct2/actions/PeepPickupAction.cpp index b0f0c630aa..c883734ea2 100644 --- a/src/openrct2/actions/PeepPickupAction.cpp +++ b/src/openrct2/actions/PeepPickupAction.cpp @@ -163,7 +163,6 @@ GameActions::Result PeepPickupAction::Execute() const { pickedUpPeep->PickupAbort(_loc.x); } - NetworkSetPickupPeep(_owner, nullptr); } break;