1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-01 16:45:35 +00:00

Pickup sounds for armors

This commit is contained in:
Michael Papageorgiou 2012-03-13 18:05:38 +02:00
parent 703e484a92
commit 6dddf8a3d5
6 changed files with 170 additions and 6 deletions

View file

@ -7,9 +7,12 @@
#include "../mwworld/ptr.hpp" #include "../mwworld/ptr.hpp"
#include "../mwworld/actiontake.hpp" #include "../mwworld/actiontake.hpp"
#include "../mwworld/environment.hpp"
#include "../mwrender/objects.hpp" #include "../mwrender/objects.hpp"
#include "../mwsound/soundmanager.hpp"
namespace MWClass namespace MWClass
{ {
void Armor::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const void Armor::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
@ -52,6 +55,8 @@ namespace MWClass
boost::shared_ptr<MWWorld::Action> Armor::activate (const MWWorld::Ptr& ptr, boost::shared_ptr<MWWorld::Action> Armor::activate (const MWWorld::Ptr& ptr,
const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const 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<MWWorld::Action> ( return boost::shared_ptr<MWWorld::Action> (
new MWWorld::ActionTake (ptr)); new MWWorld::ActionTake (ptr));
} }
@ -83,4 +88,117 @@ namespace MWClass
registerClass (typeid (ESM::Armor).name(), instance); 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<ESM::Armor, MWWorld::RefData> *ref =
ptr.get<ESM::Armor>();
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;
}
} }

View file

@ -5,6 +5,13 @@
namespace MWClass namespace MWClass
{ {
enum WeightCategory
{
WC_Light = 0,
WC_Medium = 1,
WC_Heavy = 2
};
class Armor : public MWWorld::Class class Armor : public MWWorld::Class
{ {
public: public:
@ -32,6 +39,15 @@ namespace MWClass
///< Return name of the script attached to ptr ///< Return name of the script attached to ptr
static void registerSelf(); 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
}; };
} }

View file

@ -145,7 +145,7 @@ namespace MWSound
const std::string &id, const std::string &id,
float volume, float pitch, float volume, float pitch,
float min, float max, float min, float max,
bool loop) bool loop, bool untracked)
{ {
try try
{ {
@ -157,7 +157,10 @@ namespace MWSound
setPos(snd, ptr); setPos(snd, ptr);
snd->play(); snd->play();
sounds[ptr][id] = WSoundPtr(snd); if (!untracked)
{
sounds[ptr][id] = WSoundPtr(snd);
}
} }
catch(...) catch(...)
{ {
@ -413,13 +416,13 @@ namespace MWSound
} }
void SoundManager::playSound3D (MWWorld::Ptr ptr, const std::string& soundId, 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 // Look up the sound in the ESM data
float min, max; float min, max;
const std::string &file = lookup(soundId, volume, min, max); const std::string &file = lookup(soundId, volume, min, max);
if (file != "") 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) void SoundManager::stopSound3D (MWWorld::Ptr ptr, const std::string& soundId)

View file

@ -87,7 +87,7 @@ namespace MWSound
void add(const std::string &file, void add(const std::string &file,
MWWorld::Ptr ptr, const std::string &id, MWWorld::Ptr ptr, const std::string &id,
float volume, float pitch, float min, float max, float volume, float pitch, float min, float max,
bool loop); bool loop, bool untracked=false);
void clearAll(PtrMap::iterator& it); void clearAll(PtrMap::iterator& it);
void remove(MWWorld::Ptr ptr, const std::string &id = ""); void remove(MWWorld::Ptr ptr, const std::string &id = "");
bool isPlaying(MWWorld::Ptr ptr, const std::string &id) const; bool isPlaying(MWWorld::Ptr ptr, const std::string &id) const;
@ -136,7 +136,7 @@ namespace MWSound
///< Play a sound, independently of 3D-position ///< Play a sound, independently of 3D-position
void playSound3D (MWWorld::Ptr reference, const std::string& soundId, 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 ///< Play a sound from an object
void stopSound3D (MWWorld::Ptr reference, const std::string& soundId = ""); void stopSound3D (MWWorld::Ptr reference, const std::string& soundId = "");

View file

@ -141,4 +141,19 @@ namespace MWWorld
{ {
sClasses.insert (std::make_pair (key, instance)); 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");
}
} }

View file

@ -144,6 +144,18 @@ namespace MWWorld
///< If there is no class for this pointer, an exception is thrown. ///< If there is no class for this pointer, an exception is thrown.
static void registerClass (const std::string& key, boost::shared_ptr<Class> instance); static void registerClass (const std::string& key, boost::shared_ptr<Class> 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)
}; };
} }