Merge branch 'master' into inventoryGUI

This commit is contained in:
scrawl 2012-05-15 21:48:05 +02:00
commit 0063387979
8 changed files with 103 additions and 5 deletions

View file

@ -179,4 +179,17 @@ namespace MWClass
return info;
}
float Container::getCapactiy (const MWWorld::Ptr& ptr) const
{
ESMS::LiveCellRef<ESM::Container, MWWorld::RefData> *ref =
ptr.get<ESM::Container>();
return ref->base->weight;
}
float Container::getEncumbrance (const MWWorld::Ptr& ptr) const
{
return getContainerStore (ptr).getWeight();
}
}

View file

@ -36,6 +36,14 @@ namespace MWClass
virtual std::string getScript (const MWWorld::Ptr& ptr) const;
///< Return name of the script attached to ptr
virtual float getCapactiy (const MWWorld::Ptr& ptr) const;
///< 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();
};
}

View file

@ -5,6 +5,7 @@
#include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/mechanicsmanager.hpp"
#include "../mwmechanics/magiceffects.hpp"
#include "../mwbase/environment.hpp"
@ -56,8 +57,6 @@ namespace MWClass
data->mCreatureStats.mLevel = ref->base->data.level;
// \todo add initial container content
// store
ptr.getRefData().setCustomData (data.release());
}
@ -166,4 +165,26 @@ namespace MWClass
return info;
}
float Creature::getCapactiy (const MWWorld::Ptr& ptr) const
{
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;
}
}

View file

@ -52,6 +52,14 @@ namespace MWClass
virtual std::string getScript (const MWWorld::Ptr& ptr) const;
///< Return name of the script attached to ptr
virtual float getCapactiy (const MWWorld::Ptr& ptr) const;
///< 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();
};
}

View file

@ -88,11 +88,9 @@ namespace MWClass
}
else
{
//TODO: do something with npdt12 maybe:p
/// \todo do something with npdt12 maybe:p
}
// \todo add initial container content
// store
ptr.getRefData().setCustomData (data.release());
}
@ -325,4 +323,26 @@ namespace MWClass
return info;
}
float Npc::getCapactiy (const MWWorld::Ptr& ptr) const
{
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;
}
}

View file

@ -74,6 +74,14 @@ namespace MWClass
///< Return desired movement vector (determined based on movement settings,
/// stance and stats).
virtual float getCapactiy (const MWWorld::Ptr& ptr) const;
///< 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();
};
}

View file

@ -142,6 +142,16 @@ namespace MWWorld
throw std::logic_error ("value not supported by this class");
}
float Class::getCapactiy (const MWWorld::Ptr& ptr) const
{
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)
{
std::map<std::string, boost::shared_ptr<Class> >::const_iterator iter = sClasses.find (key);

View file

@ -164,6 +164,16 @@ namespace MWWorld
///< Return trade value of the object. Throws an exception, if the object can't be traded.
/// (default implementation: throws an exception)
virtual float getCapactiy (const MWWorld::Ptr& ptr) const;
///< 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)
static const Class& get (const std::string& key);
///< If there is no class for this \a key, an exception is thrown.