From 3cc8aec6b9e633130a9f3885a3797bf2cc4963c1 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Thu, 5 Dec 2024 15:29:34 +0100 Subject: [PATCH] StaffHireNewAction: use peep anim objects; bump network version --- src/openrct2-ui/windows/StaffList.cpp | 19 ++++--- src/openrct2/actions/StaffHireNewAction.cpp | 58 +++++++++------------ src/openrct2/actions/StaffHireNewAction.h | 4 +- src/openrct2/network/NetworkBase.cpp | 2 +- 4 files changed, 38 insertions(+), 45 deletions(-) diff --git a/src/openrct2-ui/windows/StaffList.cpp b/src/openrct2-ui/windows/StaffList.cpp index 39d58a3f34..701e6d63a4 100644 --- a/src/openrct2-ui/windows/StaffList.cpp +++ b/src/openrct2-ui/windows/StaffList.cpp @@ -149,12 +149,7 @@ namespace OpenRCT2::Ui::Windows case WIDX_STAFF_LIST_HIRE_BUTTON: { auto staffType = GetSelectedStaffType(); - auto costume = EntertainerCostume::Count; - if (staffType == StaffType::Entertainer) - { - costume = GetRandomEntertainerCostume(); - } - HireNewMember(staffType, costume); + HireNewMember(staffType); break; } case WIDX_STAFF_LIST_SHOW_PATROL_AREA_BUTTON: @@ -531,7 +526,7 @@ namespace OpenRCT2::Ui::Windows /** * Hires a new staff member of the given type. */ - void HireNewMember(StaffType staffType, EntertainerCostume entertainerType) + void HireNewMember(StaffType staffType) { bool autoPosition = Config::Get().general.AutoStaffPlacement; if (GetInputManager().IsModifierKeyPressed(ModifierKey::shift)) @@ -554,7 +549,15 @@ namespace OpenRCT2::Ui::Windows staffOrders = STAFF_ORDERS_INSPECT_RIDES | STAFF_ORDERS_FIX_RIDES; } - auto hireStaffAction = StaffHireNewAction(autoPosition, staffType, entertainerType, staffOrders); + // Select a (random) costume for this staff member + auto animPeepType = AnimationPeepType(static_cast(staffType) + 1); + ObjectEntryIndex costume; + if (staffType == StaffType::Entertainer) + costume = findRandomPeepAnimationsIndexForType(animPeepType); + else + costume = findPeepAnimationsIndexForType(animPeepType); + + auto hireStaffAction = StaffHireNewAction(autoPosition, staffType, costume, staffOrders); hireStaffAction.SetCallback([=](const GameAction*, const GameActions::Result* res) -> void { if (res->Error != GameActions::Status::Ok) return; diff --git a/src/openrct2/actions/StaffHireNewAction.cpp b/src/openrct2/actions/StaffHireNewAction.cpp index 0ff35a6719..dda0647f06 100644 --- a/src/openrct2/actions/StaffHireNewAction.cpp +++ b/src/openrct2/actions/StaffHireNewAction.cpp @@ -20,7 +20,8 @@ #include "../interface/Window.h" #include "../localisation/StringIds.h" #include "../management/Finance.h" -#include "../peep/PeepAnimationData.h" +#include "../object/ObjectManager.h" +#include "../object/PeepAnimationsObject.h" #include "../ride/Ride.h" #include "../scenario/Scenario.h" #include "../ui/UiContext.h" @@ -32,19 +33,11 @@ using namespace OpenRCT2; -/* rct2: 0x009929FC */ -static constexpr PeepAnimationGroup spriteTypes[] = { - PeepAnimationGroup::Handyman, - PeepAnimationGroup::Mechanic, - PeepAnimationGroup::Security, - PeepAnimationGroup::EntertainerPanda, -}; - StaffHireNewAction::StaffHireNewAction( - bool autoPosition, StaffType staffType, EntertainerCostume entertainerType, uint32_t staffOrders) + bool autoPosition, StaffType staffType, ObjectEntryIndex costumeIndex, uint32_t staffOrders) : _autoPosition(autoPosition) , _staffType(static_cast(staffType)) - , _entertainerType(entertainerType) + , _costumeIndex(costumeIndex) , _staffOrders(staffOrders) { } @@ -53,7 +46,7 @@ void StaffHireNewAction::AcceptParameters(GameActionParameterVisitor& visitor) { visitor.Visit("autoPosition", _autoPosition); visitor.Visit("staffType", _staffType); - visitor.Visit("entertainerType", _entertainerType); + visitor.Visit("costumeIndex", _costumeIndex); visitor.Visit("staffOrders", _staffOrders); } @@ -66,7 +59,7 @@ void StaffHireNewAction::Serialise(DataSerialiser& stream) { GameAction::Serialise(stream); - stream << DS_TAG(_autoPosition) << DS_TAG(_staffType) << DS_TAG(_entertainerType) << DS_TAG(_staffOrders); + stream << DS_TAG(_autoPosition) << DS_TAG(_staffType) << DS_TAG(_costumeIndex) << DS_TAG(_staffOrders); } GameActions::Result StaffHireNewAction::Query() const @@ -97,17 +90,10 @@ GameActions::Result StaffHireNewAction::QueryExecute(bool execute) const if (_staffType == static_cast(StaffType::Entertainer)) { - if (static_cast(_entertainerType) >= static_cast(EntertainerCostume::Count)) + auto costumes = findAllPeepAnimationsIndexesForType(AnimationPeepType::Entertainer); + if (std::find(costumes.begin(), costumes.end(), _costumeIndex) == costumes.end()) { - LOG_ERROR("Invalid entertainer type %u", static_cast(_entertainerType)); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_HIRE_NEW_STAFF, STR_ERR_VALUE_OUT_OF_RANGE); - } - - uint32_t availableCostumes = StaffGetAvailableEntertainerCostumes(); - if (!(availableCostumes & (1 << static_cast(_entertainerType)))) - { - LOG_ERROR("Unavailable entertainer costume %u", static_cast(_entertainerType)); + LOG_ERROR("Unavailable entertainer costume %u", static_cast(_costumeIndex)); return GameActions::Result( GameActions::Status::InvalidParameters, STR_CANT_HIRE_NEW_STAFF, STR_ERR_VALUE_OUT_OF_RANGE); } @@ -163,18 +149,22 @@ GameActions::Result StaffHireNewAction::QueryExecute(bool execute) const newPeep->PeepId = newStaffId; newPeep->AssignedStaffType = static_cast(_staffType); - PeepAnimationGroup spriteType = spriteTypes[_staffType]; - if (_staffType == static_cast(StaffType::Entertainer)) - { - spriteType = EntertainerCostumeToSprite(_entertainerType); - } - newPeep->Name = nullptr; - newPeep->AnimationGroup = spriteType; + auto animPeepType = AnimationPeepType(static_cast(_staffType) + 1); + ObjectEntryIndex animObjectIndex = _costumeIndex; + if (animPeepType != AnimationPeepType::Entertainer) + animObjectIndex = findPeepAnimationsIndexForType(animPeepType); - const SpriteBounds* spriteBounds = &GetSpriteBounds(spriteType); - newPeep->SpriteData.Width = spriteBounds->sprite_width; - newPeep->SpriteData.HeightMin = spriteBounds->sprite_height_negative; - newPeep->SpriteData.HeightMax = spriteBounds->sprite_height_positive; + newPeep->Name = nullptr; + newPeep->AnimationObjectIndex = animObjectIndex; + newPeep->AnimationGroup = PeepAnimationGroup::Normal; + + auto& objManager = GetContext()->GetObjectManager(); + auto* animObj = objManager.GetLoadedObject(animObjectIndex); + + const auto& spriteBounds = animObj->GetSpriteBounds(newPeep->AnimationGroup); + newPeep->SpriteData.Width = spriteBounds.sprite_width; + newPeep->SpriteData.HeightMin = spriteBounds.sprite_height_negative; + newPeep->SpriteData.HeightMax = spriteBounds.sprite_height_positive; if (_autoPosition) { diff --git a/src/openrct2/actions/StaffHireNewAction.h b/src/openrct2/actions/StaffHireNewAction.h index d3b4e1ea59..26279e33e6 100644 --- a/src/openrct2/actions/StaffHireNewAction.h +++ b/src/openrct2/actions/StaffHireNewAction.h @@ -22,12 +22,12 @@ class StaffHireNewAction final : public GameActionBase