added getEncumbrance function

This commit is contained in:
Marc Zinnschlag 2012-05-15 21:34:00 +02:00
parent c6493fb133
commit 7e00fea18b
8 changed files with 65 additions and 5 deletions

View file

@ -184,4 +184,9 @@ namespace MWClass
return ref->base->weight; return ref->base->weight;
} }
float Container::getEncumbrance (const MWWorld::Ptr& ptr) const
{
return getContainerStore (ptr).getWeight();
}
} }

View file

@ -37,7 +37,11 @@ namespace MWClass
///< Return name of the script attached to ptr ///< Return name of the script attached to ptr
virtual float getCapactiy (const MWWorld::Ptr& ptr) const; virtual float getCapactiy (const MWWorld::Ptr& ptr) const;
///< Return total weight that fits into the object (including modifications from magic ///< Return total weight that fits into the object. Throws an exception, if the object can't
/// hold other objects.
virtual float getEncumbrance (const MWWorld::Ptr& ptr) const;
///< Returns total weight of objects inside this object (including modifications from magic
/// effects). Throws an exception, if the object can't hold other objects. /// effects). Throws an exception, if the object can't hold other objects.
static void registerSelf(); static void registerSelf();

View file

@ -5,6 +5,7 @@
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/mechanicsmanager.hpp" #include "../mwmechanics/mechanicsmanager.hpp"
#include "../mwmechanics/magiceffects.hpp"
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
@ -172,4 +173,20 @@ namespace MWClass
const MWMechanics::CreatureStats& stats = getCreatureStats (ptr); const MWMechanics::CreatureStats& stats = getCreatureStats (ptr);
return stats.mAttributes[0].getModified()*5; return stats.mAttributes[0].getModified()*5;
} }
float Creature::getEncumbrance (const MWWorld::Ptr& ptr) const
{
float weight = getContainerStore (ptr).getWeight();
const MWMechanics::CreatureStats& stats = getCreatureStats (ptr);
weight -= stats.mMagicEffects.get (MWMechanics::EffectKey (8)).mMagnitude; // feather
weight += stats.mMagicEffects.get (MWMechanics::EffectKey (7)).mMagnitude; // burden
if (weight<0)
weight = 0;
return weight;
}
} }

View file

@ -53,7 +53,11 @@ namespace MWClass
///< Return name of the script attached to ptr ///< Return name of the script attached to ptr
virtual float getCapactiy (const MWWorld::Ptr& ptr) const; virtual float getCapactiy (const MWWorld::Ptr& ptr) const;
///< Return total weight that fits into the object (including modifications from magic ///< Return total weight that fits into the object. Throws an exception, if the object can't
/// hold other objects.
virtual float getEncumbrance (const MWWorld::Ptr& ptr) const;
///< Returns total weight of objects inside this object (including modifications from magic
/// effects). Throws an exception, if the object can't hold other objects. /// effects). Throws an exception, if the object can't hold other objects.
static void registerSelf(); static void registerSelf();

View file

@ -331,4 +331,20 @@ namespace MWClass
const MWMechanics::CreatureStats& stats = getCreatureStats (ptr); const MWMechanics::CreatureStats& stats = getCreatureStats (ptr);
return stats.mAttributes[0].getModified()*5; return stats.mAttributes[0].getModified()*5;
} }
float Npc::getEncumbrance (const MWWorld::Ptr& ptr) const
{
float weight = getContainerStore (ptr).getWeight();
const MWMechanics::CreatureStats& stats = getCreatureStats (ptr);
weight -= stats.mMagicEffects.get (MWMechanics::EffectKey (8)).mMagnitude; // feather
weight += stats.mMagicEffects.get (MWMechanics::EffectKey (7)).mMagnitude; // burden
if (weight<0)
weight = 0;
return weight;
}
} }

View file

@ -75,7 +75,11 @@ namespace MWClass
/// stance and stats). /// stance and stats).
virtual float getCapactiy (const MWWorld::Ptr& ptr) const; virtual float getCapactiy (const MWWorld::Ptr& ptr) const;
///< Return total weight that fits into the object (including modifications from magic ///< Return total weight that fits into the object. Throws an exception, if the object can't
/// hold other objects.
virtual float getEncumbrance (const MWWorld::Ptr& ptr) const;
///< Returns total weight of objects inside this object (including modifications from magic
/// effects). Throws an exception, if the object can't hold other objects. /// effects). Throws an exception, if the object can't hold other objects.
static void registerSelf(); static void registerSelf();

View file

@ -144,7 +144,12 @@ namespace MWWorld
float Class::getCapactiy (const MWWorld::Ptr& ptr) const float Class::getCapactiy (const MWWorld::Ptr& ptr) const
{ {
throw std::runtime_error ("capacity not supported by class"); throw std::runtime_error ("capacity not supported by this class");
}
float Class::getEncumbrance (const MWWorld::Ptr& ptr) const
{
throw std::runtime_error ("encumbrance not supported by class");
} }
const Class& Class::get (const std::string& key) const Class& Class::get (const std::string& key)

View file

@ -165,7 +165,12 @@ namespace MWWorld
/// (default implementation: throws an exception) /// (default implementation: throws an exception)
virtual float getCapactiy (const MWWorld::Ptr& ptr) const; virtual float getCapactiy (const MWWorld::Ptr& ptr) const;
///< Return total weight that fits into the object (including modifications from magic ///< Return total weight that fits into the object. Throws an exception, if the object can't
/// hold other objects.
/// (default implementation: throws an exception)
virtual float getEncumbrance (const MWWorld::Ptr& ptr) const;
///< Returns total weight of objects inside this object (including modifications from magic
/// effects). Throws an exception, if the object can't hold other objects. /// effects). Throws an exception, if the object can't hold other objects.
/// (default implementation: throws an exception) /// (default implementation: throws an exception)