Pickup sounds for armors

actorid
Michael Papageorgiou 13 years ago
parent 703e484a92
commit 6dddf8a3d5

@ -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<MWWorld::Action> 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<MWWorld::Action> (
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<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;
}
}

@ -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
};
}

@ -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)

@ -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 = "");

@ -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");
}
}

@ -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<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)
};
}

Loading…
Cancel
Save