diff --git a/src/openrct2/object/PeepAnimationsObject.cpp b/src/openrct2/object/PeepAnimationsObject.cpp index e30ed8fcbe..f58c7a8833 100644 --- a/src/openrct2/object/PeepAnimationsObject.cpp +++ b/src/openrct2/object/PeepAnimationsObject.cpp @@ -58,11 +58,8 @@ void PeepAnimationsObject::ReadJson(IReadObjectContext* context, json_t& root) Guard::Assert(root.is_object(), "PeepAnimationsObject::ReadJson expects parameter root to be an object"); PopulateTablesFromJson(context, root); - Guard::Assert(root["peepType"].is_string(), "PeepAnimationsObject::ReadJson expects peepType to be a string"); - _peepType = animationPeepTypeMap[Json::GetString(root["peepType"])]; - - Guard::Assert(root["isSlowWalking"].is_boolean(), "PeepAnimationsObject::ReadJson expects isSlowWalking to be a boolean"); - _slowWalking = Json::GetBoolean(root["isSlowWalking"]); + Guard::Assert(root["properties"].is_object(), "PeepAnimationsObject::ReadJson expects properties to be an object"); + ReadProperties(root["properties"]); auto& requiredAnimationMap = getAnimationsByPeepType(_peepType); _animationGroups.clear(); @@ -147,6 +144,21 @@ PeepAnimations PeepAnimationsObject::ReadAnimations(const EnumMap _animationGroups; OpenRCT2::AnimationPeepType _peepType; bool _slowWalking; - std::vector _animationGroups; + bool _noRandomPlacement; public: static constexpr ObjectType kObjectType = ObjectType::PeepAnimations; void ReadJson(IReadObjectContext* context, json_t& root) override; OpenRCT2::PeepAnimations ReadAnimations(const EnumMap& requiredAnimationMap, json_t& animations); + void ReadProperties(json_t& properties); void Load() override; void Unload() override; @@ -47,11 +49,16 @@ public: RCT12PeepAnimationGroup GetLegacyPosition(PeepAnimationGroup animGroup) const; std::string_view GetScriptName(PeepAnimationGroup animGroup) const; - bool IsSlowWalking() + bool IsSlowWalking() const { return _slowWalking; }; + bool ShouldExcludeFromRandomPlacement() const + { + return _noRandomPlacement; + } + void DrawPreview(DrawPixelInfo& dpi, int32_t width, int32_t height) const override; void SetRepositoryItem(ObjectRepositoryItem* item) const override; }; diff --git a/src/openrct2/peep/PeepAnimations.cpp b/src/openrct2/peep/PeepAnimations.cpp index 7cf9bb78b1..3ec83aa508 100644 --- a/src/openrct2/peep/PeepAnimations.cpp +++ b/src/openrct2/peep/PeepAnimations.cpp @@ -133,35 +133,45 @@ namespace OpenRCT2 return nullptr; } - std::vector findAllPeepAnimationsIndexesForType(const AnimationPeepType type) + std::vector findAllPeepAnimationsIndexesForType(const AnimationPeepType type, bool randomOnly) { std::vector output{}; auto& objManager = GetContext()->GetObjectManager(); for (auto i = 0u; i < kMaxPeepAnimationsObjects; i++) { auto* animObj = objManager.GetLoadedObject(i); - if (animObj != nullptr && animObj->GetPeepType() == type) - output.push_back(i); + if (animObj == nullptr || animObj->GetPeepType() != type) + continue; + + if (randomOnly && animObj->ShouldExcludeFromRandomPlacement()) + continue; + + output.push_back(i); } return output; } - std::vector findAllPeepAnimationsObjectForType(const AnimationPeepType type) + std::vector findAllPeepAnimationsObjectForType(const AnimationPeepType type, bool randomOnly) { std::vector output{}; auto& objManager = GetContext()->GetObjectManager(); for (auto i = 0u; i < kMaxPeepAnimationsObjects; i++) { auto* animObj = objManager.GetLoadedObject(i); - if (animObj != nullptr && animObj->GetPeepType() == type) - output.push_back(animObj); + if (animObj == nullptr || animObj->GetPeepType() != type) + continue; + + if (randomOnly && animObj->ShouldExcludeFromRandomPlacement()) + continue; + + output.push_back(animObj); } return output; } ObjectEntryIndex findRandomPeepAnimationsIndexForType(const AnimationPeepType type) { - auto costumes = findAllPeepAnimationsIndexesForType(type); + auto costumes = findAllPeepAnimationsIndexesForType(type, true); if (costumes.empty()) return OBJECT_ENTRY_INDEX_NULL; diff --git a/src/openrct2/peep/PeepAnimations.h b/src/openrct2/peep/PeepAnimations.h index e78af95f88..07b7b0e30d 100644 --- a/src/openrct2/peep/PeepAnimations.h +++ b/src/openrct2/peep/PeepAnimations.h @@ -70,8 +70,9 @@ namespace OpenRCT2 ObjectEntryIndex findPeepAnimationsIndexForType(const AnimationPeepType type); PeepAnimationsObject* findPeepAnimationsObjectForType(const AnimationPeepType type); - std::vector findAllPeepAnimationsIndexesForType(const AnimationPeepType type); - std::vector findAllPeepAnimationsObjectForType(const AnimationPeepType type); + std::vector findAllPeepAnimationsIndexesForType(const AnimationPeepType type, bool randomOnly = false); + std::vector findAllPeepAnimationsObjectForType( + const AnimationPeepType type, bool randomOnly = false); ObjectEntryIndex findRandomPeepAnimationsIndexForType(const AnimationPeepType type);