diff --git a/apps/openmw/mwclass/container.cpp b/apps/openmw/mwclass/container.cpp index 82a9212a2..34d6b6c60 100644 --- a/apps/openmw/mwclass/container.cpp +++ b/apps/openmw/mwclass/container.cpp @@ -184,4 +184,9 @@ namespace MWClass return ref->base->weight; } + + float Container::getEncumbrance (const MWWorld::Ptr& ptr) const + { + return getContainerStore (ptr).getWeight(); + } } diff --git a/apps/openmw/mwclass/container.hpp b/apps/openmw/mwclass/container.hpp index 0231ce26b..61a0d912b 100644 --- a/apps/openmw/mwclass/container.hpp +++ b/apps/openmw/mwclass/container.hpp @@ -37,7 +37,11 @@ namespace MWClass ///< Return name of the script attached to ptr 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. static void registerSelf(); diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index a16455430..a0b2225db 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -5,6 +5,7 @@ #include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/mechanicsmanager.hpp" +#include "../mwmechanics/magiceffects.hpp" #include "../mwbase/environment.hpp" @@ -172,4 +173,20 @@ namespace MWClass const MWMechanics::CreatureStats& stats = getCreatureStats (ptr); 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; + } } diff --git a/apps/openmw/mwclass/creature.hpp b/apps/openmw/mwclass/creature.hpp index c68d1995d..7224d3ee1 100644 --- a/apps/openmw/mwclass/creature.hpp +++ b/apps/openmw/mwclass/creature.hpp @@ -53,7 +53,11 @@ namespace MWClass ///< Return name of the script attached to ptr 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. static void registerSelf(); diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 3c1c0e29a..3bb4519c2 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -331,4 +331,20 @@ namespace MWClass const MWMechanics::CreatureStats& stats = getCreatureStats (ptr); 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; + } } diff --git a/apps/openmw/mwclass/npc.hpp b/apps/openmw/mwclass/npc.hpp index d2ecc7aa7..0cfad0347 100644 --- a/apps/openmw/mwclass/npc.hpp +++ b/apps/openmw/mwclass/npc.hpp @@ -75,7 +75,11 @@ namespace MWClass /// stance and stats). 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. static void registerSelf(); diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index 24d2d07f1..5fb503847 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -144,7 +144,12 @@ namespace MWWorld 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) diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index 34e61c54a..513dc942b 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -165,7 +165,12 @@ namespace MWWorld /// (default implementation: throws an exception) 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. /// (default implementation: throws an exception)