mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-06 06:32:56 +01:00
Introduce functions to get a (random) peep anim object by type
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include "../entity/Peep.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <random>
|
||||
|
||||
namespace OpenRCT2
|
||||
{
|
||||
@@ -104,6 +105,67 @@ namespace OpenRCT2
|
||||
}
|
||||
}
|
||||
|
||||
ObjectEntryIndex findPeepAnimationsIndexForType(const AnimationPeepType type)
|
||||
{
|
||||
auto& objManager = GetContext()->GetObjectManager();
|
||||
for (auto i = 0u; i < kMaxPeepAnimationsObjects; i++)
|
||||
{
|
||||
auto* animObj = objManager.GetLoadedObject<PeepAnimationsObject>(i);
|
||||
if (animObj != nullptr && animObj->GetPeepType() == type)
|
||||
return i;
|
||||
}
|
||||
return OBJECT_ENTRY_INDEX_NULL;
|
||||
}
|
||||
|
||||
PeepAnimationsObject* findPeepAnimationsObjectForType(const AnimationPeepType type)
|
||||
{
|
||||
auto& objManager = GetContext()->GetObjectManager();
|
||||
for (auto i = 0u; i < kMaxPeepAnimationsObjects; i++)
|
||||
{
|
||||
auto* animObj = objManager.GetLoadedObject<PeepAnimationsObject>(i);
|
||||
if (animObj != nullptr && animObj->GetPeepType() == type)
|
||||
return animObj;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<ObjectEntryIndex> findAllPeepAnimationsIndexesForType(const AnimationPeepType type)
|
||||
{
|
||||
std::vector<ObjectEntryIndex> output{};
|
||||
auto& objManager = GetContext()->GetObjectManager();
|
||||
for (auto i = 0u; i < kMaxPeepAnimationsObjects; i++)
|
||||
{
|
||||
auto* animObj = objManager.GetLoadedObject<PeepAnimationsObject>(i);
|
||||
if (animObj != nullptr && animObj->GetPeepType() == type)
|
||||
output.push_back(i);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
std::vector<PeepAnimationsObject*> findAllPeepAnimationsObjectForType(const AnimationPeepType type)
|
||||
{
|
||||
std::vector<PeepAnimationsObject*> output{};
|
||||
auto& objManager = GetContext()->GetObjectManager();
|
||||
for (auto i = 0u; i < kMaxPeepAnimationsObjects; i++)
|
||||
{
|
||||
auto* animObj = objManager.GetLoadedObject<PeepAnimationsObject>(i);
|
||||
if (animObj != nullptr && animObj->GetPeepType() == type)
|
||||
output.push_back(animObj);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
ObjectEntryIndex findRandomPeepAnimationsIndexForType(const AnimationPeepType type)
|
||||
{
|
||||
auto costumes = findAllPeepAnimationsIndexesForType(type);
|
||||
if (costumes.empty())
|
||||
return OBJECT_ENTRY_INDEX_NULL;
|
||||
|
||||
std::vector<ObjectEntryIndex> out{};
|
||||
std::sample(costumes.begin(), costumes.end(), std::back_inserter(out), 1, std::mt19937{ std::random_device{}() });
|
||||
return !out.empty() ? out[0] : OBJECT_ENTRY_INDEX_NULL;
|
||||
}
|
||||
|
||||
// Adapted from CarEntry.cpp
|
||||
SpriteBounds inferMaxAnimationDimensions(const PeepAnimation& anim)
|
||||
{
|
||||
|
||||
@@ -71,5 +71,13 @@ namespace OpenRCT2
|
||||
PeepAnimation animations[37]{};
|
||||
};
|
||||
|
||||
ObjectEntryIndex findPeepAnimationsIndexForType(const AnimationPeepType type);
|
||||
PeepAnimationsObject* findPeepAnimationsObjectForType(const AnimationPeepType type);
|
||||
|
||||
std::vector<ObjectEntryIndex> findAllPeepAnimationsIndexesForType(const AnimationPeepType type);
|
||||
std::vector<PeepAnimationsObject*> findAllPeepAnimationsObjectForType(const AnimationPeepType type);
|
||||
|
||||
ObjectEntryIndex findRandomPeepAnimationsIndexForType(const AnimationPeepType type);
|
||||
|
||||
SpriteBounds inferMaxAnimationDimensions(const PeepAnimation& anim);
|
||||
} // namespace OpenRCT2
|
||||
|
||||
Reference in New Issue
Block a user