From a6870a97d482f7a291ffc543fb713678c446a65e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Fri, 3 Dec 2021 17:37:39 +0200 Subject: [PATCH 1/3] Move staff hiring logic into StaffList --- src/openrct2-ui/windows/StaffList.cpp | 46 ++++++++++++++++++++++++++- src/openrct2/entity/Staff.cpp | 44 ------------------------- src/openrct2/entity/Staff.h | 1 - 3 files changed, 45 insertions(+), 46 deletions(-) diff --git a/src/openrct2-ui/windows/StaffList.cpp b/src/openrct2-ui/windows/StaffList.cpp index 1706923187..821981dbc0 100644 --- a/src/openrct2-ui/windows/StaffList.cpp +++ b/src/openrct2-ui/windows/StaffList.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -137,7 +138,7 @@ public: { costume = GetRandomEntertainerCostume(); } - staff_hire_new_member(staffType, costume); + HireNewMember(staffType, costume); break; } case WIDX_STAFF_LIST_SHOW_PATROL_AREA_BUTTON: @@ -498,6 +499,49 @@ public: } private: + /** + * Hires a new staff member of the given type. + */ + bool HireNewMember(StaffType staffType, EntertainerCostume entertainerType) + { + bool autoPosition = gConfigGeneral.auto_staff_placement; + if (gInputPlaceObjectModifier & PLACE_OBJECT_MODIFIER_SHIFT_Z) + { + autoPosition = autoPosition ^ 1; + } + + uint32_t staffOrders = 0; + + if (staffType == StaffType::Handyman) + { + staffOrders = STAFF_ORDERS_SWEEPING | STAFF_ORDERS_WATER_FLOWERS | STAFF_ORDERS_EMPTY_BINS; + if (gConfigGeneral.handymen_mow_default) + { + staffOrders |= STAFF_ORDERS_MOWING; + } + } + else if (staffType == StaffType::Mechanic) + { + staffOrders = STAFF_ORDERS_INSPECT_RIDES | STAFF_ORDERS_FIX_RIDES; + } + + auto hireStaffAction = StaffHireNewAction(autoPosition, staffType, entertainerType, staffOrders); + 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(actionResult.StaffEntityId); + auto intent = Intent(WC_PEEP); + intent.putExtra(INTENT_EXTRA_PEEP, staff); + context_open_intent(&intent); + }); + + auto res = GameActions::Execute(&hireStaffAction); + return res.Error == GameActions::Status::Ok; + } + StaffType GetSelectedStaffType() const { return static_cast(_selectedTab); diff --git a/src/openrct2/entity/Staff.cpp b/src/openrct2/entity/Staff.cpp index bc87fb4699..e8b8902b48 100644 --- a/src/openrct2/entity/Staff.cpp +++ b/src/openrct2/entity/Staff.cpp @@ -12,7 +12,6 @@ #include "../Context.h" #include "../Game.h" #include "../Input.h" -#include "../actions/StaffHireNewAction.h" #include "../actions/StaffSetOrdersAction.h" #include "../audio/audio.h" #include "../config/Config.h" @@ -91,49 +90,6 @@ void staff_reset_modes() staff_update_greyed_patrol_areas(); } -/** - * Hires a new staff member of the given type. - */ -bool staff_hire_new_member(StaffType staffType, EntertainerCostume entertainerType) -{ - bool autoPosition = gConfigGeneral.auto_staff_placement; - if (gInputPlaceObjectModifier & PLACE_OBJECT_MODIFIER_SHIFT_Z) - { - autoPosition = autoPosition ^ 1; - } - - uint32_t staffOrders = 0; - - if (staffType == StaffType::Handyman) - { - staffOrders = STAFF_ORDERS_SWEEPING | STAFF_ORDERS_WATER_FLOWERS | STAFF_ORDERS_EMPTY_BINS; - if (gConfigGeneral.handymen_mow_default) - { - staffOrders |= STAFF_ORDERS_MOWING; - } - } - else if (staffType == StaffType::Mechanic) - { - staffOrders = STAFF_ORDERS_INSPECT_RIDES | STAFF_ORDERS_FIX_RIDES; - } - - auto hireStaffAction = StaffHireNewAction(autoPosition, staffType, entertainerType, staffOrders); - 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(actionResult.StaffEntityId); - auto intent = Intent(WC_PEEP); - intent.putExtra(INTENT_EXTRA_PEEP, staff); - context_open_intent(&intent); - }); - - auto res = GameActions::Execute(&hireStaffAction); - return res.Error == GameActions::Status::Ok; -} - /** * * rct2: 0x006C0C3F diff --git a/src/openrct2/entity/Staff.h b/src/openrct2/entity/Staff.h index 9d29fa720c..75bdc61048 100644 --- a/src/openrct2/entity/Staff.h +++ b/src/openrct2/entity/Staff.h @@ -157,7 +157,6 @@ extern colour_t gStaffSecurityColour; void staff_reset_modes(); void staff_set_name(uint16_t spriteIndex, const char* name); -bool staff_hire_new_member(StaffType staffType, EntertainerCostume entertainerType); void staff_update_greyed_patrol_areas(); bool staff_is_patrol_area_set_for_type(StaffType type, const CoordsXY& coords); colour_t staff_get_colour(StaffType staffType); From a79e2a375a6a6fcaea3fed8805939ffdbc013733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Fri, 3 Dec 2021 17:40:27 +0200 Subject: [PATCH 2/3] Move staff_set_name to Staff --- src/openrct2-ui/windows/Staff.cpp | 5 ++++- src/openrct2/actions/GameActionCompat.cpp | 10 ---------- src/openrct2/entity/Staff.h | 1 - 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/openrct2-ui/windows/Staff.cpp b/src/openrct2-ui/windows/Staff.cpp index 3e7cc2e8f1..1d18b37490 100644 --- a/src/openrct2-ui/windows/Staff.cpp +++ b/src/openrct2-ui/windows/Staff.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -1320,7 +1321,9 @@ void WindowStaffOverviewTextInput(rct_window* w, rct_widgetindex widgetIndex, ch if (text == nullptr) return; - staff_set_name(w->number, text); + + auto gameAction = StaffSetNameAction(w->number, text); + GameActions::Execute(&gameAction); } /** diff --git a/src/openrct2/actions/GameActionCompat.cpp b/src/openrct2/actions/GameActionCompat.cpp index 5b29dc8842..86638b3de0 100644 --- a/src/openrct2/actions/GameActionCompat.cpp +++ b/src/openrct2/actions/GameActionCompat.cpp @@ -21,7 +21,6 @@ #include "RideSetNameAction.h" #include "RideSetStatusAction.h" #include "SetParkEntranceFeeAction.h" -#include "StaffSetNameAction.h" #include "WallRemoveAction.h" #pragma region PlaceParkEntranceAction @@ -118,15 +117,6 @@ void guest_set_name(uint16_t spriteIndex, const char* name) } #pragma endregion -#pragma region StaffSetName - -void staff_set_name(uint16_t spriteIndex, const char* name) -{ - auto gameAction = StaffSetNameAction(spriteIndex, name); - GameActions::Execute(&gameAction); -} -#pragma endregion - #pragma region MazeSetTrack money32 maze_set_track( uint16_t x, uint16_t y, uint16_t z, uint8_t flags, bool initialPlacement, uint8_t direction, ride_id_t rideIndex, diff --git a/src/openrct2/entity/Staff.h b/src/openrct2/entity/Staff.h index 75bdc61048..ee9a72b088 100644 --- a/src/openrct2/entity/Staff.h +++ b/src/openrct2/entity/Staff.h @@ -156,7 +156,6 @@ extern colour_t gStaffMechanicColour; extern colour_t gStaffSecurityColour; void staff_reset_modes(); -void staff_set_name(uint16_t spriteIndex, const char* name); void staff_update_greyed_patrol_areas(); bool staff_is_patrol_area_set_for_type(StaffType type, const CoordsXY& coords); colour_t staff_get_colour(StaffType staffType); From e9ccad157e664365798ab12a4c5cf61695c24ad1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Fri, 3 Dec 2021 20:47:48 +0200 Subject: [PATCH 3/3] Remove unused return value --- src/openrct2-ui/windows/StaffList.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/openrct2-ui/windows/StaffList.cpp b/src/openrct2-ui/windows/StaffList.cpp index 821981dbc0..74abd4f42a 100644 --- a/src/openrct2-ui/windows/StaffList.cpp +++ b/src/openrct2-ui/windows/StaffList.cpp @@ -502,7 +502,7 @@ private: /** * Hires a new staff member of the given type. */ - bool HireNewMember(StaffType staffType, EntertainerCostume entertainerType) + void HireNewMember(StaffType staffType, EntertainerCostume entertainerType) { bool autoPosition = gConfigGeneral.auto_staff_placement; if (gInputPlaceObjectModifier & PLACE_OBJECT_MODIFIER_SHIFT_Z) @@ -538,8 +538,7 @@ private: context_open_intent(&intent); }); - auto res = GameActions::Execute(&hireStaffAction); - return res.Error == GameActions::Status::Ok; + GameActions::Execute(&hireStaffAction); } StaffType GetSelectedStaffType() const