|
|
|
@ -625,34 +625,59 @@ namespace MWClass
|
|
|
|
|
|
|
|
|
|
std::string Creature::getSoundIdFromSndGen(const MWWorld::Ptr &ptr, const std::string &name) const
|
|
|
|
|
{
|
|
|
|
|
const MWWorld::Store<ESM::SoundGenerator> &store = MWBase::Environment::get().getWorld()->getStore().get<ESM::SoundGenerator>();
|
|
|
|
|
|
|
|
|
|
int type = getSndGenTypeFromName(ptr, name);
|
|
|
|
|
if(type >= 0)
|
|
|
|
|
{
|
|
|
|
|
std::vector<const ESM::SoundGenerator*> sounds;
|
|
|
|
|
std::vector<const ESM::SoundGenerator*> fallbacksounds;
|
|
|
|
|
if (type < 0)
|
|
|
|
|
return std::string();
|
|
|
|
|
|
|
|
|
|
std::vector<const ESM::SoundGenerator*> sounds;
|
|
|
|
|
std::vector<const ESM::SoundGenerator*> fallbacksounds;
|
|
|
|
|
|
|
|
|
|
MWWorld::LiveCellRef<ESM::Creature>* ref = ptr.get<ESM::Creature>();
|
|
|
|
|
MWWorld::LiveCellRef<ESM::Creature>* ref = ptr.get<ESM::Creature>();
|
|
|
|
|
|
|
|
|
|
const std::string& ourId = (ref->mBase->mOriginal.empty()) ? ptr.getCellRef().getRefId() : ref->mBase->mOriginal;
|
|
|
|
|
const std::string& ourId = (ref->mBase->mOriginal.empty()) ? ptr.getCellRef().getRefId() : ref->mBase->mOriginal;
|
|
|
|
|
|
|
|
|
|
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore();
|
|
|
|
|
auto sound = store.get<ESM::SoundGenerator>().begin();
|
|
|
|
|
while (sound != store.get<ESM::SoundGenerator>().end())
|
|
|
|
|
{
|
|
|
|
|
if (type == sound->mType && !sound->mCreature.empty() && Misc::StringUtils::ciEqual(ourId, sound->mCreature))
|
|
|
|
|
sounds.push_back(&*sound);
|
|
|
|
|
if (type == sound->mType && sound->mCreature.empty())
|
|
|
|
|
fallbacksounds.push_back(&*sound);
|
|
|
|
|
++sound;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MWWorld::Store<ESM::SoundGenerator>::iterator sound = store.begin();
|
|
|
|
|
while (sound != store.end())
|
|
|
|
|
if (sounds.empty())
|
|
|
|
|
{
|
|
|
|
|
const std::string model = getModel(ptr);
|
|
|
|
|
if (!model.empty())
|
|
|
|
|
{
|
|
|
|
|
if (type == sound->mType && !sound->mCreature.empty() && (Misc::StringUtils::ciEqual(ourId, sound->mCreature)))
|
|
|
|
|
sounds.push_back(&*sound);
|
|
|
|
|
if (type == sound->mType && sound->mCreature.empty())
|
|
|
|
|
fallbacksounds.push_back(&*sound);
|
|
|
|
|
++sound;
|
|
|
|
|
for (const ESM::Creature &creature : store.get<ESM::Creature>())
|
|
|
|
|
{
|
|
|
|
|
if (creature.mId != ourId && creature.mOriginal != ourId && !creature.mModel.empty()
|
|
|
|
|
&& Misc::StringUtils::ciEqual(model, "meshes\\" + creature.mModel))
|
|
|
|
|
{
|
|
|
|
|
const std::string& fallbackId = !creature.mOriginal.empty() ? creature.mOriginal : creature.mId;
|
|
|
|
|
sound = store.get<ESM::SoundGenerator>().begin();
|
|
|
|
|
while (sound != store.get<ESM::SoundGenerator>().end())
|
|
|
|
|
{
|
|
|
|
|
if (type == sound->mType && !sound->mCreature.empty()
|
|
|
|
|
&& Misc::StringUtils::ciEqual(fallbackId, sound->mCreature))
|
|
|
|
|
sounds.push_back(&*sound);
|
|
|
|
|
++sound;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!sounds.empty())
|
|
|
|
|
return sounds[Misc::Rng::rollDice(sounds.size())]->mSound;
|
|
|
|
|
if (!fallbacksounds.empty())
|
|
|
|
|
return fallbacksounds[Misc::Rng::rollDice(fallbacksounds.size())]->mSound;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "";
|
|
|
|
|
if (!sounds.empty())
|
|
|
|
|
return sounds[Misc::Rng::rollDice(sounds.size())]->mSound;
|
|
|
|
|
if (!fallbacksounds.empty())
|
|
|
|
|
return fallbacksounds[Misc::Rng::rollDice(fallbacksounds.size())]->mSound;
|
|
|
|
|
|
|
|
|
|
return std::string();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MWWorld::Ptr Creature::copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const
|
|
|
|
|