From 6ed7fd461e51096e63b0475d95ebc9d794edd840 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Mon, 23 Dec 2024 12:21:04 +0100 Subject: [PATCH] Move isSlowWalking property to animation group level --- src/openrct2/actions/StaffHireNewAction.cpp | 2 +- .../actions/StaffSetCostumeAction.cpp | 2 +- src/openrct2/entity/Guest.cpp | 6 ++++-- src/openrct2/entity/Peep.cpp | 6 ------ src/openrct2/entity/Peep.h | 2 -- src/openrct2/entity/Staff.cpp | 6 +++++- src/openrct2/object/PeepAnimationsObject.cpp | 21 ++++++++----------- src/openrct2/object/PeepAnimationsObject.h | 6 +----- src/openrct2/peep/PeepAnimations.h | 1 + 9 files changed, 22 insertions(+), 30 deletions(-) diff --git a/src/openrct2/actions/StaffHireNewAction.cpp b/src/openrct2/actions/StaffHireNewAction.cpp index 6650975a38..8045c36c9e 100644 --- a/src/openrct2/actions/StaffHireNewAction.cpp +++ b/src/openrct2/actions/StaffHireNewAction.cpp @@ -162,7 +162,7 @@ GameActions::Result StaffHireNewAction::QueryExecute(bool execute) const auto* animObj = objManager.GetLoadedObject(animObjectIndex); newPeep->PeepFlags &= ~PEEP_FLAGS_SLOW_WALK; - if (animObj->IsSlowWalking()) + if (animObj->IsSlowWalking(PeepAnimationGroup::Normal)) newPeep->PeepFlags |= PEEP_FLAGS_SLOW_WALK; const auto& spriteBounds = animObj->GetSpriteBounds(newPeep->AnimationGroup); diff --git a/src/openrct2/actions/StaffSetCostumeAction.cpp b/src/openrct2/actions/StaffSetCostumeAction.cpp index 7eeb2f1c4e..42de88d8a9 100644 --- a/src/openrct2/actions/StaffSetCostumeAction.cpp +++ b/src/openrct2/actions/StaffSetCostumeAction.cpp @@ -89,7 +89,7 @@ GameActions::Result StaffSetCostumeAction::Execute() const auto* animObj = objManager.GetLoadedObject(_costume); staff->PeepFlags &= ~PEEP_FLAGS_SLOW_WALK; - if (animObj->IsSlowWalking()) + if (animObj->IsSlowWalking(PeepAnimationGroup::Normal)) staff->PeepFlags |= PEEP_FLAGS_SLOW_WALK; staff->AnimationFrameNum = 0; diff --git a/src/openrct2/entity/Guest.cpp b/src/openrct2/entity/Guest.cpp index 3be64bf0f7..9c14a2680b 100644 --- a/src/openrct2/entity/Guest.cpp +++ b/src/openrct2/entity/Guest.cpp @@ -6769,9 +6769,11 @@ void Guest::SetAnimationGroup(PeepAnimationGroup new_sprite_type) if (IsActionInterruptable()) Action = PeepActionType::Walking; + auto& objManager = GetContext()->GetObjectManager(); + auto* animObj = objManager.GetLoadedObject(AnimationObjectIndex); + PeepFlags &= ~PEEP_FLAGS_SLOW_WALK; - Guard::Assert(EnumValue(new_sprite_type) < std::size(gAnimationGroupToSlowWalkMap)); - if (gAnimationGroupToSlowWalkMap[EnumValue(new_sprite_type)]) + if (animObj->IsSlowWalking(new_sprite_type)) { PeepFlags |= PEEP_FLAGS_SLOW_WALK; } diff --git a/src/openrct2/entity/Peep.cpp b/src/openrct2/entity/Peep.cpp index 76d0c01e0a..2c2e98ec92 100644 --- a/src/openrct2/entity/Peep.cpp +++ b/src/openrct2/entity/Peep.cpp @@ -126,12 +126,6 @@ static PeepAnimationType PeepActionToAnimationGroupMap[] = { PeepAnimationType::WithdrawMoney, }; -const bool gAnimationGroupToSlowWalkMap[] = { - false, false, false, false, false, false, false, false, false, false, false, true, false, false, true, true, - true, true, true, false, true, false, true, true, true, false, false, true, true, false, false, true, - true, true, true, true, true, true, false, true, false, true, true, true, true, true, true, true, -}; - template<> bool EntityBase::Is() const { diff --git a/src/openrct2/entity/Peep.h b/src/openrct2/entity/Peep.h index cd003bcf9b..7ce0f3d0b8 100644 --- a/src/openrct2/entity/Peep.h +++ b/src/openrct2/entity/Peep.h @@ -422,8 +422,6 @@ enum PATHING_RIDE_ENTRANCE = 1 << 3, }; -extern const bool gAnimationGroupToSlowWalkMap[48]; - int32_t PeepGetStaffCount(); void PeepUpdateAll(); void PeepUpdateAllBoundingBoxes(); diff --git a/src/openrct2/entity/Staff.cpp b/src/openrct2/entity/Staff.cpp index b370821225..0aec15ce01 100644 --- a/src/openrct2/entity/Staff.cpp +++ b/src/openrct2/entity/Staff.cpp @@ -29,6 +29,7 @@ #include "../object/ObjectList.h" #include "../object/ObjectManager.h" #include "../object/PathAdditionEntry.h" +#include "../object/PeepAnimationsObject.h" #include "../object/SceneryGroupEntry.h" #include "../object/SmallSceneryEntry.h" #include "../object/TerrainSurfaceObject.h" @@ -1650,8 +1651,11 @@ void Staff::Tick128UpdateStaff() if (Action < PeepActionType::Idle) Action = PeepActionType::Walking; + auto& objManager = GetContext()->GetObjectManager(); + auto* animObj = objManager.GetLoadedObject(AnimationObjectIndex); + PeepFlags &= ~PEEP_FLAGS_SLOW_WALK; - if (gAnimationGroupToSlowWalkMap[EnumValue(newAnimationGroup)]) + if (animObj->IsSlowWalking(newAnimationGroup)) { PeepFlags |= PEEP_FLAGS_SLOW_WALK; } diff --git a/src/openrct2/object/PeepAnimationsObject.cpp b/src/openrct2/object/PeepAnimationsObject.cpp index be157a2664..f8488ef125 100644 --- a/src/openrct2/object/PeepAnimationsObject.cpp +++ b/src/openrct2/object/PeepAnimationsObject.cpp @@ -95,16 +95,12 @@ void PeepAnimationsObject::ReadJson(IReadObjectContext* context, json_t& root) group.legacyPosition = RCT12PeepAnimationGroup::Invalid; } + // Should we play back the walking animation more slowly? + group.isSlowWalking = Json::GetBoolean(groupJson["isSlowWalking"], false); + // Do we have a preferred way of addressing this object in scripts? - if (groupJson.contains("scriptName")) - { - group.scriptName = Json::GetString(groupJson["scriptName"]); - } // If not, just use the object identifier. - else - { - group.scriptName = GetIdentifier(); - } + group.scriptName = Json::GetString(groupJson["scriptName"], std::string(GetIdentifier())); _animationGroups.push_back(group); } @@ -159,10 +155,6 @@ void PeepAnimationsObject::ReadProperties(json_t& props) Guard::Assert(props["peepType"].is_string(), "PeepAnimationsObject::ReadProperties expects peepType to be a string"); _peepType = animationPeepTypeMap[Json::GetString(props["peepType"])]; - Guard::Assert( - props["isSlowWalking"].is_boolean(), "PeepAnimationsObject::ReadProperties expects isSlowWalking to be a boolean"); - _slowWalking = Json::GetBoolean(props["isSlowWalking"], false); - Guard::Assert( props["noRandomPlacement"].is_boolean(), "PeepAnimationsObject::ReadProperties expects noRandomPlacement to be a boolean"); @@ -209,6 +201,11 @@ std::string_view PeepAnimationsObject::GetScriptName(PeepAnimationGroup animGrou return _animationGroups[EnumValue(animGroup)].scriptName; } +bool PeepAnimationsObject::IsSlowWalking(PeepAnimationGroup animGroup) const +{ + return _animationGroups[EnumValue(animGroup)].isSlowWalking; +} + void PeepAnimationsObject::DrawPreview(DrawPixelInfo& dpi, int32_t width, int32_t height) const { auto centre = ScreenCoordsXY{ width / 2, height / 2 }; diff --git a/src/openrct2/object/PeepAnimationsObject.h b/src/openrct2/object/PeepAnimationsObject.h index b8e8c62ebf..a0ed6c6dee 100644 --- a/src/openrct2/object/PeepAnimationsObject.h +++ b/src/openrct2/object/PeepAnimationsObject.h @@ -24,7 +24,6 @@ private: ImageIndex _imageOffsetId; std::vector _animationGroups; OpenRCT2::AnimationPeepType _peepType; - bool _slowWalking; bool _noRandomPlacement; public: @@ -49,10 +48,7 @@ public: RCT12PeepAnimationGroup GetLegacyPosition(PeepAnimationGroup animGroup) const; std::string_view GetScriptName(PeepAnimationGroup animGroup) const; - bool IsSlowWalking() const - { - return _slowWalking; - }; + bool IsSlowWalking(PeepAnimationGroup animGroup) const; bool ShouldExcludeFromRandomPlacement() const { diff --git a/src/openrct2/peep/PeepAnimations.h b/src/openrct2/peep/PeepAnimations.h index b2f8de078a..a6ba242962 100644 --- a/src/openrct2/peep/PeepAnimations.h +++ b/src/openrct2/peep/PeepAnimations.h @@ -53,6 +53,7 @@ namespace OpenRCT2 struct PeepAnimations { public: + bool isSlowWalking = false; RCT12PeepAnimationGroup legacyPosition; std::string scriptName{};