From 6dddf8a3d589b79516ac682e76ef6c17180e6a91 Mon Sep 17 00:00:00 2001 From: Michael Papageorgiou Date: Tue, 13 Mar 2012 18:05:38 +0200 Subject: [PATCH] Pickup sounds for armors --- apps/openmw/mwclass/armor.cpp | 118 +++++++++++++++++++++++++++ apps/openmw/mwclass/armor.hpp | 16 ++++ apps/openmw/mwsound/soundmanager.cpp | 11 ++- apps/openmw/mwsound/soundmanager.hpp | 4 +- apps/openmw/mwworld/class.cpp | 15 ++++ apps/openmw/mwworld/class.hpp | 12 +++ 6 files changed, 170 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwclass/armor.cpp b/apps/openmw/mwclass/armor.cpp index 3cdf63119..25021b718 100644 --- a/apps/openmw/mwclass/armor.cpp +++ b/apps/openmw/mwclass/armor.cpp @@ -7,9 +7,12 @@ #include "../mwworld/ptr.hpp" #include "../mwworld/actiontake.hpp" +#include "../mwworld/environment.hpp" #include "../mwrender/objects.hpp" +#include "../mwsound/soundmanager.hpp" + namespace MWClass { void Armor::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const @@ -52,6 +55,8 @@ namespace MWClass boost::shared_ptr Armor::activate (const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const { + environment.mSoundManager->playSound3D (ptr, getUpSoundId(ptr), 1.0, 1.0, false, true); + return boost::shared_ptr ( new MWWorld::ActionTake (ptr)); } @@ -83,4 +88,117 @@ namespace MWClass registerClass (typeid (ESM::Armor).name(), instance); } + + std::string Armor::getUpSoundId (const MWWorld::Ptr& ptr) const + { + int wc = getWeightCategory(ptr); + if (wc == WC_Light) + return std::string("Item Armor Light Up"); + else if (wc == WC_Medium) + return std::string("Item Armor Medium Up"); + else + return std::string("Item Armor Heavy Up"); + } + + std::string Armor::getDownSoundId (const MWWorld::Ptr& ptr) const + { + int wc = getWeightCategory(ptr); + if (wc == WC_Light) + return std::string("Item Armor Light Down"); + else if (wc == WC_Medium) + return std::string("Item Armor Medium Down"); + else + return std::string("Item Armor Heavy Down"); + } + + int Armor::getWeightCategory (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + float weight = ref->base->data.weight; + int type = ref->base->data.type; + // Boots + if (type == 5) + { + if (weight <= 12.0) + { + return WC_Light; + } + else if (weight > 18.0) + { + return WC_Heavy; + } + else + { + return WC_Medium; + } + } + // Cuirass + if (type == 1) + { + if (weight <= 18.0) + { + return WC_Light; + } + else if (weight > 27.0) + { + return WC_Heavy; + } + else + { + return WC_Medium; + } + } + // Greaves, Shield + if (type == 4 || type == 8) + { + if (weight <= 9.0) + { + return WC_Light; + } + else if (weight > 13.5) + { + return WC_Heavy; + } + else + { + return WC_Medium; + } + } + // Bracer, Gauntlet, Helmet + if (type == 6 || type == 7 || type == 9 || type == 10 || type == 0) + { + if (weight <= 3.0) + { + return WC_Light; + } + else if (weight > 4.5) + { + return WC_Heavy; + } + else + { + return WC_Medium; + } + } + // Pauldrons + if (type == 2 || type == 3) + { + if (weight <= 6.0) + { + return WC_Light; + } + else if (weight > 9.0) + { + return WC_Heavy; + } + else + { + return WC_Medium; + } + } + + return WC_Light; + } } diff --git a/apps/openmw/mwclass/armor.hpp b/apps/openmw/mwclass/armor.hpp index 060bc364e..943fcaa0b 100644 --- a/apps/openmw/mwclass/armor.hpp +++ b/apps/openmw/mwclass/armor.hpp @@ -5,6 +5,13 @@ namespace MWClass { + enum WeightCategory + { + WC_Light = 0, + WC_Medium = 1, + WC_Heavy = 2 + }; + class Armor : public MWWorld::Class { public: @@ -32,6 +39,15 @@ namespace MWClass ///< Return name of the script attached to ptr static void registerSelf(); + + virtual std::string getUpSoundId (const MWWorld::Ptr& ptr) const; + ///< Return the pick up sound Id + + virtual std::string getDownSoundId (const MWWorld::Ptr& ptr) const; + ///< Return the put down sound Id + + virtual int getWeightCategory (const MWWorld::Ptr& ptr) const; + ///< Return the weight category of the armor light/medium/heavy }; } diff --git a/apps/openmw/mwsound/soundmanager.cpp b/apps/openmw/mwsound/soundmanager.cpp index 57bb0f56e..e8a65c230 100644 --- a/apps/openmw/mwsound/soundmanager.cpp +++ b/apps/openmw/mwsound/soundmanager.cpp @@ -145,7 +145,7 @@ namespace MWSound const std::string &id, float volume, float pitch, float min, float max, - bool loop) + bool loop, bool untracked) { try { @@ -157,7 +157,10 @@ namespace MWSound setPos(snd, ptr); snd->play(); - sounds[ptr][id] = WSoundPtr(snd); + if (!untracked) + { + sounds[ptr][id] = WSoundPtr(snd); + } } catch(...) { @@ -413,13 +416,13 @@ namespace MWSound } void SoundManager::playSound3D (MWWorld::Ptr ptr, const std::string& soundId, - float volume, float pitch, bool loop) + float volume, float pitch, bool loop, bool untracked) { // Look up the sound in the ESM data float min, max; const std::string &file = lookup(soundId, volume, min, max); if (file != "") - add(file, ptr, soundId, volume, pitch, min, max, loop); + add(file, ptr, soundId, volume, pitch, min, max, loop, untracked); } void SoundManager::stopSound3D (MWWorld::Ptr ptr, const std::string& soundId) diff --git a/apps/openmw/mwsound/soundmanager.hpp b/apps/openmw/mwsound/soundmanager.hpp index 03c19ce77..bd3b67679 100644 --- a/apps/openmw/mwsound/soundmanager.hpp +++ b/apps/openmw/mwsound/soundmanager.hpp @@ -87,7 +87,7 @@ namespace MWSound void add(const std::string &file, MWWorld::Ptr ptr, const std::string &id, float volume, float pitch, float min, float max, - bool loop); + bool loop, bool untracked=false); void clearAll(PtrMap::iterator& it); void remove(MWWorld::Ptr ptr, const std::string &id = ""); bool isPlaying(MWWorld::Ptr ptr, const std::string &id) const; @@ -136,7 +136,7 @@ namespace MWSound ///< Play a sound, independently of 3D-position void playSound3D (MWWorld::Ptr reference, const std::string& soundId, - float volume, float pitch, bool loop); + float volume, float pitch, bool loop, bool untracked=false); ///< Play a sound from an object void stopSound3D (MWWorld::Ptr reference, const std::string& soundId = ""); diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index 641da73e1..6dbde367e 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -141,4 +141,19 @@ namespace MWWorld { sClasses.insert (std::make_pair (key, instance)); } + + std::string Class::getUpSoundId (const Ptr& ptr) const + { + throw std::runtime_error ("class does not have an up sound"); + } + + std::string Class::getDownSoundId (const Ptr& ptr) const + { + throw std::runtime_error ("class does not have an down sound"); + } + + int Class::getWeightCategory (const MWWorld::Ptr& ptr) + { + throw std::runtime_error ("class does not have an weight"); + } } diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index 9b6acb3ce..3e0a91824 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -144,6 +144,18 @@ namespace MWWorld ///< If there is no class for this pointer, an exception is thrown. static void registerClass (const std::string& key, boost::shared_ptr instance); + + virtual std::string getUpSoundId (const Ptr& ptr) const; + ///< Return the up sound ID of \a ptr or throw an exception, if class does not support ID retrieval + /// (default implementation: throw an exception) + + virtual std::string getDownSoundId (const Ptr& ptr) const; + ///< Return the down sound ID of \a ptr or throw an exception, if class does not support ID retrieval + /// (default implementation: throw an exception) + + virtual int getWeightCategory (const MWWorld::Ptr& ptr); + ///< Return the weight category of armors light/medium/heavy + /// (default implementation: throw an exception) }; }