mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 06:53:53 +00:00
Play randomized werewolf sounds
This commit is contained in:
parent
00d6690b4d
commit
6fd4cdb5fb
8 changed files with 114 additions and 22 deletions
|
@ -63,9 +63,12 @@ namespace MWClass
|
||||||
{
|
{
|
||||||
if(get(actor).isNpc() && get(actor).getNpcStats(actor).isWerewolf())
|
if(get(actor).isNpc() && get(actor).getNpcStats(actor).isWerewolf())
|
||||||
{
|
{
|
||||||
|
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore();
|
||||||
|
const ESM::Sound *sound = store.get<ESM::Sound>().searchRandom("WolfItem");
|
||||||
|
|
||||||
boost::shared_ptr<MWWorld::Action> action(new MWWorld::FailedAction("#{sWerewolfRefusal}"));
|
boost::shared_ptr<MWWorld::Action> action(new MWWorld::FailedAction("#{sWerewolfRefusal}"));
|
||||||
// FIXME: Randomize using all WolfItem* sound records
|
if(sound) action->setSound(sound->mId);
|
||||||
action->setSound("WolfItem1");
|
|
||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,9 +95,12 @@ namespace MWClass
|
||||||
|
|
||||||
if(get(actor).isNpc() && get(actor).getNpcStats(actor).isWerewolf())
|
if(get(actor).isNpc() && get(actor).getNpcStats(actor).isWerewolf())
|
||||||
{
|
{
|
||||||
|
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore();
|
||||||
|
const ESM::Sound *sound = store.get<ESM::Sound>().searchRandom("WolfContainer");
|
||||||
|
|
||||||
boost::shared_ptr<MWWorld::Action> action(new MWWorld::FailedAction("#{sWerewolfRefusal}"));
|
boost::shared_ptr<MWWorld::Action> action(new MWWorld::FailedAction("#{sWerewolfRefusal}"));
|
||||||
// FIXME: Randomize using all WolfContainer* sound records
|
if(sound) action->setSound(sound->mId);
|
||||||
action->setSound("WolfContainer1");
|
|
||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -227,9 +227,12 @@ namespace MWClass
|
||||||
{
|
{
|
||||||
if(get(actor).isNpc() && get(actor).getNpcStats(actor).isWerewolf())
|
if(get(actor).isNpc() && get(actor).getNpcStats(actor).isWerewolf())
|
||||||
{
|
{
|
||||||
|
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore();
|
||||||
|
const ESM::Sound *sound = store.get<ESM::Sound>().searchRandom("WolfCreature");
|
||||||
|
|
||||||
boost::shared_ptr<MWWorld::Action> action(new MWWorld::FailedAction("#{sWerewolfRefusal}"));
|
boost::shared_ptr<MWWorld::Action> action(new MWWorld::FailedAction("#{sWerewolfRefusal}"));
|
||||||
// FIXME: Randomize using all WolfCreature* sound records
|
if(sound) action->setSound(sound->mId);
|
||||||
action->setSound("WolfCreature1");
|
|
||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -431,8 +431,9 @@ namespace MWClass
|
||||||
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager();
|
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager();
|
||||||
if(stats.isWerewolf())
|
if(stats.isWerewolf())
|
||||||
{
|
{
|
||||||
// Randomize from WolfHit* records
|
const ESM::Sound *sound = world->getStore().get<ESM::Sound>().searchRandom("WolfHit");
|
||||||
sndMgr->playSound3D(victim, "WolfHit1", 1.0f, 1.0f);
|
if(sound)
|
||||||
|
sndMgr->playSound3D(victim, sound->mId, 1.0f, 1.0f);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
sndMgr->playSound3D(victim, "Hand To Hand Hit", 1.0f, 1.0f);
|
sndMgr->playSound3D(victim, "Hand To Hand Hit", 1.0f, 1.0f);
|
||||||
|
@ -571,9 +572,12 @@ namespace MWClass
|
||||||
{
|
{
|
||||||
if(get(actor).isNpc() && get(actor).getNpcStats(actor).isWerewolf())
|
if(get(actor).isNpc() && get(actor).getNpcStats(actor).isWerewolf())
|
||||||
{
|
{
|
||||||
|
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore();
|
||||||
|
const ESM::Sound *sound = store.get<ESM::Sound>().searchRandom("WolfNPC");
|
||||||
|
|
||||||
boost::shared_ptr<MWWorld::Action> action(new MWWorld::FailedAction("#{sWerewolfRefusal}"));
|
boost::shared_ptr<MWWorld::Action> action(new MWWorld::FailedAction("#{sWerewolfRefusal}"));
|
||||||
// FIXME: Randomize using all WolfNPC* sound records
|
if(sound) action->setSound(sound->mId);
|
||||||
action->setSound("WolfNPC1");
|
|
||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
if(getCreatureStats(ptr).isDead())
|
if(getCreatureStats(ptr).isDead())
|
||||||
|
|
|
@ -404,10 +404,14 @@ bool CharacterController::updateNpcState(bool onground, bool inwater, bool isrun
|
||||||
1.0f, "equip start", "equip stop", 0.0f, 0);
|
1.0f, "equip start", "equip stop", 0.0f, 0);
|
||||||
mUpperBodyState = UpperCharState_EquipingWeap;
|
mUpperBodyState = UpperCharState_EquipingWeap;
|
||||||
if(isWerewolf)
|
if(isWerewolf)
|
||||||
|
{
|
||||||
|
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore();
|
||||||
|
const ESM::Sound *sound = store.get<ESM::Sound>().searchRandom("WolfEquip");
|
||||||
|
if(sound)
|
||||||
{
|
{
|
||||||
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager();
|
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager();
|
||||||
// TODO: Randomize from all WolfEquip* records
|
sndMgr->playSound3D(mPtr, sound->mId, 1.0f, 1.0f);
|
||||||
sndMgr->playSound3D(mPtr, "WolfEquip1", 1.0f, 1.0f);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -554,8 +558,17 @@ bool CharacterController::updateNpcState(bool onground, bool inwater, bool isrun
|
||||||
if(mAttackType != "shoot")
|
if(mAttackType != "shoot")
|
||||||
{
|
{
|
||||||
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager();
|
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager();
|
||||||
// TODO: Randomize from WolfSwing* records
|
|
||||||
std::string sound = (!isWerewolf ? "SwishM" : "WolfSwing");
|
if(isWerewolf)
|
||||||
|
{
|
||||||
|
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore();
|
||||||
|
const ESM::Sound *sound = store.get<ESM::Sound>().searchRandom("WolfSwing");
|
||||||
|
if(sound)
|
||||||
|
sndMgr->playSound3D(mPtr, sound->mId, 1.0f, 1.0f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::string sound = "SwishM";
|
||||||
if(complete < 0.5f)
|
if(complete < 0.5f)
|
||||||
sndMgr->playSound3D(mPtr, sound, 1.0f, 0.8f); //Weak attack
|
sndMgr->playSound3D(mPtr, sound, 1.0f, 0.8f); //Weak attack
|
||||||
else if(complete < 1.0f)
|
else if(complete < 1.0f)
|
||||||
|
@ -563,6 +576,7 @@ bool CharacterController::updateNpcState(bool onground, bool inwater, bool isrun
|
||||||
else
|
else
|
||||||
sndMgr->playSound3D(mPtr, sound, 1.0f, 1.2f); //Strong attack
|
sndMgr->playSound3D(mPtr, sound, 1.0f, 1.2f); //Strong attack
|
||||||
}
|
}
|
||||||
|
}
|
||||||
stats.setAttackStrength(complete);
|
stats.setAttackStrength(complete);
|
||||||
|
|
||||||
mAnimation->disable(mCurrentWeapon);
|
mAnimation->disable(mCurrentWeapon);
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
#include "../mwbase/windowmanager.hpp"
|
#include "../mwbase/windowmanager.hpp"
|
||||||
|
#include "../mwbase/world.hpp"
|
||||||
|
|
||||||
#include "ptr.hpp"
|
#include "ptr.hpp"
|
||||||
#include "refdata.hpp"
|
#include "refdata.hpp"
|
||||||
|
@ -318,9 +319,12 @@ namespace MWWorld
|
||||||
|
|
||||||
if(get(actor).isNpc() && get(actor).getNpcStats(actor).isWerewolf())
|
if(get(actor).isNpc() && get(actor).getNpcStats(actor).isWerewolf())
|
||||||
{
|
{
|
||||||
|
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore();
|
||||||
|
const ESM::Sound *sound = store.get<ESM::Sound>().searchRandom("WolfItem");
|
||||||
|
|
||||||
boost::shared_ptr<MWWorld::Action> action(new MWWorld::FailedAction("#{sWerewolfRefusal}"));
|
boost::shared_ptr<MWWorld::Action> action(new MWWorld::FailedAction("#{sWerewolfRefusal}"));
|
||||||
// FIXME: Randomize using all WolfItem* sound records
|
if(sound) action->setSound(sound->mId);
|
||||||
action->setSound("WolfItem1");
|
|
||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,23 @@ namespace MWWorld
|
||||||
typedef std::map<std::string, T> Dynamic;
|
typedef std::map<std::string, T> Dynamic;
|
||||||
typedef std::map<std::string, T> Static;
|
typedef std::map<std::string, T> Static;
|
||||||
|
|
||||||
|
class GetRecords {
|
||||||
|
const std::string mFind;
|
||||||
|
std::vector<const T*> *mRecords;
|
||||||
|
|
||||||
|
public:
|
||||||
|
GetRecords(const std::string &str, std::vector<const T*> *records)
|
||||||
|
: mFind(Misc::StringUtils::lowerCase(str)), mRecords(records)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
void operator()(const T *item)
|
||||||
|
{
|
||||||
|
if(Misc::StringUtils::ciCompareLen(mFind, item->mId, mFind.size()) == 0)
|
||||||
|
mRecords->push_back(item);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
friend class ESMStore;
|
friend class ESMStore;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -132,6 +149,16 @@ namespace MWWorld
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns a random record that starts with the named ID, or NULL if not found. */
|
||||||
|
const T *searchRandom(const std::string &id) const
|
||||||
|
{
|
||||||
|
std::vector<const T*> results;
|
||||||
|
std::for_each(mShared.begin(), mShared.end(), GetRecords(id, &results));
|
||||||
|
if(!results.empty())
|
||||||
|
return results[int(std::rand()/((double)RAND_MAX+1)*results.size())];
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
const T *find(const std::string &id) const {
|
const T *find(const std::string &id) const {
|
||||||
const T *ptr = search(id);
|
const T *ptr = search(id);
|
||||||
if (ptr == 0) {
|
if (ptr == 0) {
|
||||||
|
@ -142,6 +169,20 @@ namespace MWWorld
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns a random record that starts with the named ID. An exception is thrown if none
|
||||||
|
* are found. */
|
||||||
|
const T *findRandom(const std::string &id) const
|
||||||
|
{
|
||||||
|
const T *ptr = searchRandom(id);
|
||||||
|
if(ptr == 0)
|
||||||
|
{
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << "Object starting with '"<<id<<"' not found (const)";
|
||||||
|
throw std::runtime_error(msg.str());
|
||||||
|
}
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
void load(ESM::ESMReader &esm, const std::string &id) {
|
void load(ESM::ESMReader &esm, const std::string &id) {
|
||||||
std::string idLower = Misc::StringUtils::lowerCase(id);
|
std::string idLower = Misc::StringUtils::lowerCase(id);
|
||||||
mStatic[idLower] = T();
|
mStatic[idLower] = T();
|
||||||
|
|
|
@ -35,6 +35,26 @@ public:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int ciCompareLen(const std::string &x, const std::string &y, size_t len)
|
||||||
|
{
|
||||||
|
std::string::const_iterator xit = x.begin();
|
||||||
|
std::string::const_iterator yit = y.begin();
|
||||||
|
for(;xit != x.end() && yit != y.end() && len > 0;++xit,++yit,--len)
|
||||||
|
{
|
||||||
|
int res = *xit - *yit;
|
||||||
|
if(res != 0 && std::tolower(*xit) != std::tolower(*yit))
|
||||||
|
return (res > 0) ? 1 : -1;
|
||||||
|
}
|
||||||
|
if(len > 0)
|
||||||
|
{
|
||||||
|
if(xit != x.end())
|
||||||
|
return 1;
|
||||||
|
if(yit != y.end())
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/// Transforms input string to lower case w/o copy
|
/// Transforms input string to lower case w/o copy
|
||||||
static std::string &toLower(std::string &inout) {
|
static std::string &toLower(std::string &inout) {
|
||||||
std::transform(
|
std::transform(
|
||||||
|
|
Loading…
Reference in a new issue