From 9809eef18e8587969a787f7e057157592fb8e963 Mon Sep 17 00:00:00 2001 From: Capostrophic Date: Sat, 20 Oct 2018 22:14:15 +0300 Subject: [PATCH] Utilize the default soundgen entries when necessary (bug #4689) --- CHANGELOG.md | 1 + apps/openmw/mwclass/activator.cpp | 38 +++++++++++++++++++++---------- apps/openmw/mwclass/creature.cpp | 12 ++++++---- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b707851de..150c294fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -144,6 +144,7 @@ Bug #4677: Crash in ESM reader when NPC record has DNAM record without DODT one Bug #4678: Crash in ESP parser when SCVR has no variable names Bug #4685: Missing sound causes an exception inside Say command + Bug #4689: Default creature soundgen entries are not used Feature #912: Editor: Add missing icons to UniversalId tables Feature #1221: Editor: Creature/NPC rendering Feature #1617: Editor: Enchantment effect record verifier diff --git a/apps/openmw/mwclass/activator.cpp b/apps/openmw/mwclass/activator.cpp index e0e201391..42ea99b00 100644 --- a/apps/openmw/mwclass/activator.cpp +++ b/apps/openmw/mwclass/activator.cpp @@ -138,7 +138,7 @@ namespace MWClass std::string Activator::getSoundIdFromSndGen(const MWWorld::Ptr &ptr, const std::string &name) const { - std::string model = getModel(ptr); // Assume it's not empty, since we wouldn't have gotten the soundgen otherwise + const std::string model = getModel(ptr); // Assume it's not empty, since we wouldn't have gotten the soundgen otherwise const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore(); std::string creatureId; @@ -151,21 +151,35 @@ namespace MWClass } } - if (creatureId.empty()) - return std::string(); - int type = getSndGenTypeFromName(name); - std::vector sounds; - for (auto sound = store.get().begin(); sound != store.get().end(); ++sound) - if (type == sound->mType && !sound->mCreature.empty() && (Misc::StringUtils::ciEqual(creatureId, sound->mCreature))) - sounds.push_back(&*sound); + std::vector fallbacksounds; + if (!creatureId.empty()) + { + std::vector sounds; + for (auto sound = store.get().begin(); sound != store.get().end(); ++sound) + { + if (type == sound->mType && !sound->mCreature.empty() && (Misc::StringUtils::ciEqual(creatureId, sound->mCreature))) + sounds.push_back(&*sound); + if (type == sound->mType && sound->mCreature.empty()) + fallbacksounds.push_back(&*sound); + } - if (!sounds.empty()) - return sounds[Misc::Rng::rollDice(sounds.size())]->mSound; + if (!sounds.empty()) + return sounds[Misc::Rng::rollDice(sounds.size())]->mSound; + if (!fallbacksounds.empty()) + return fallbacksounds[Misc::Rng::rollDice(fallbacksounds.size())]->mSound; + } + else + { + // The activator doesn't have a corresponding creature ID, but we can try to use the defaults + for (auto sound = store.get().begin(); sound != store.get().end(); ++sound) + if (type == sound->mType && sound->mCreature.empty()) + fallbacksounds.push_back(&*sound); - if (type == ESM::SoundGenerator::Land) - return "Body Fall Large"; + if (!fallbacksounds.empty()) + return fallbacksounds[Misc::Rng::rollDice(fallbacksounds.size())]->mSound; + } return std::string(); } diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 788e5cd68..e03635b0c 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -632,25 +632,27 @@ namespace MWClass if(type >= 0) { std::vector sounds; + std::vector fallbacksounds; MWWorld::LiveCellRef* ref = ptr.get(); const std::string& ourId = (ref->mBase->mOriginal.empty()) ? ptr.getCellRef().getRefId() : ref->mBase->mOriginal; MWWorld::Store::iterator sound = store.begin(); - while(sound != store.end()) + while (sound != store.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; } - if(!sounds.empty()) + if (!sounds.empty()) return sounds[Misc::Rng::rollDice(sounds.size())]->mSound; + if (!fallbacksounds.empty()) + return fallbacksounds[Misc::Rng::rollDice(fallbacksounds.size())]->mSound; } - if (type == ESM::SoundGenerator::Land) - return "Body Fall Large"; - return ""; }