Support soundgen calls for activators (feature #4285)

pull/1969/head
Capostrophic 6 years ago
parent 53ccce1867
commit 19fd404b7b

@ -155,6 +155,7 @@
Feature #4012: Editor: Write a log file if OpenCS crashes
Feature #4222: 360° screenshots
Feature #4256: Implement ToggleBorders (TB) console command
Feature #4285: Support soundgen calls for activators
Feature #4324: Add CFBundleIdentifier in Info.plist to allow for macOS function key shortcuts
Feature #4345: Add equivalents for the command line commands to Launcher
Feature #4404: Editor: All EnumDelegate fields should have their items sorted alphabetically

@ -1,6 +1,7 @@
#include "activator.hpp"
#include <components/esm/loadacti.hpp>
#include <components/misc/rng.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/windowmanager.hpp"
@ -134,4 +135,73 @@ namespace MWClass
return MWWorld::Ptr(cell.insert(ref), &cell);
}
std::string Activator::getSoundIdFromSndGen(const MWWorld::Ptr &ptr, const std::string &name) const
{
std::string model = getModel(ptr);
if (model.empty())
return std::string();
const MWWorld::Store<ESM::Creature> &creaturestore = MWBase::Environment::get().getWorld()->getStore().get<ESM::Creature>();
std::string creatureId;
for (const ESM::Creature &iter : creaturestore)
{
if (iter.mModel.empty())
continue;
if (Misc::StringUtils::ciEqual(model, "meshes\\" + iter.mModel))
{
creatureId = !iter.mOriginal.empty() ? iter.mOriginal : iter.mId;
break;
}
}
if (creatureId.empty())
return std::string();
const MWWorld::Store<ESM::SoundGenerator> &store = MWBase::Environment::get().getWorld()->getStore().get<ESM::SoundGenerator>();
int type = getSndGenTypeFromName(name);
std::vector<const ESM::SoundGenerator*> sounds;
MWWorld::Store<ESM::SoundGenerator>::iterator sound = store.begin();
while (sound != store.end())
{
if (type == sound->mType && !sound->mCreature.empty() && (Misc::StringUtils::ciEqual(creatureId, sound->mCreature)))
sounds.push_back(&*sound);
++sound;
}
if (!sounds.empty())
return sounds[Misc::Rng::rollDice(sounds.size())]->mSound;
if (type == ESM::SoundGenerator::Land)
return "Body Fall Large";
return std::string();
}
int Activator::getSndGenTypeFromName(const std::string &name) const
{
if (name == "left")
return 0;
if (name == "right")
return 1;
if (name == "swimleft")
return 2;
if (name == "swimright")
return 3;
if (name == "moan")
return 4;
if (name == "roar")
return 5;
if (name == "scream")
return 6;
if (name == "land")
return 7;
throw std::runtime_error(std::string("Unexpected soundgen type: ")+name);
}
}

@ -44,6 +44,10 @@ namespace MWClass
///< Whether or not to use animated variant of model (default false)
virtual bool isActivator() const;
virtual std::string getSoundIdFromSndGen(const MWWorld::Ptr &ptr, const std::string &name) const;
virtual int getSndGenTypeFromName(const std::string &name) const;
};
}

Loading…
Cancel
Save