Commit aa87bd40 authored by Marc Zinnschlag's avatar Marc Zinnschlag

replaced creature stats in ref data with new custom data implementation

parent c6761e34
......@@ -8,12 +8,55 @@
#include "../mwworld/ptr.hpp"
#include "../mwworld/actiontalk.hpp"
#include "../mwworld/environment.hpp"
#include "../mwworld/customdata.hpp"
#include "../mwmechanics/mechanicsmanager.hpp"
namespace
{
struct CustomData : public MWWorld::CustomData
{
MWMechanics::CreatureStats mCreatureStats;
virtual MWWorld::CustomData *clone() const;
};
MWWorld::CustomData *CustomData::clone() const
{
return new CustomData (*this);
}
}
namespace MWClass
{
void Creature::ensureCustomData (const MWWorld::Ptr& ptr) const
{
if (!ptr.getRefData().getCustomData())
{
std::auto_ptr<CustomData> data (new CustomData);
ESMS::LiveCellRef<ESM::Creature, MWWorld::RefData> *ref = ptr.get<ESM::Creature>();
// creature stats
data->mCreatureStats.mAttributes[0].set (ref->base->data.strength);
data->mCreatureStats.mAttributes[1].set (ref->base->data.intelligence);
data->mCreatureStats.mAttributes[2].set (ref->base->data.willpower);
data->mCreatureStats.mAttributes[3].set (ref->base->data.agility);
data->mCreatureStats.mAttributes[4].set (ref->base->data.speed);
data->mCreatureStats.mAttributes[5].set (ref->base->data.endurance);
data->mCreatureStats.mAttributes[6].set (ref->base->data.personality);
data->mCreatureStats.mAttributes[7].set (ref->base->data.luck);
data->mCreatureStats.mDynamic[0].set (ref->base->data.health);
data->mCreatureStats.mDynamic[1].set (ref->base->data.mana);
data->mCreatureStats.mDynamic[2].set (ref->base->data.fatigue);
data->mCreatureStats.mLevel = ref->base->data.level;
// store
ptr.getRefData().setCustomData (data.release());
}
}
std::string Creature::getId (const MWWorld::Ptr& ptr) const
{
ESMS::LiveCellRef<ESM::Creature, MWWorld::RefData> *ref =
......@@ -24,18 +67,18 @@ namespace MWClass
void Creature::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
{
/*ESMS::LiveCellRef<ESM::Creature, MWWorld::RefData> *ref =
ptr.get<ESM::Creature>();
assert (ref->base != NULL);
const std::string &model = ref->base->model;
if (!model.empty())
{*/
MWRender::Actors& actors = renderingInterface.getActors();
actors.insertCreature(ptr);
}
void Creature::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const
......@@ -72,31 +115,9 @@ namespace MWClass
MWMechanics::CreatureStats& Creature::getCreatureStats (const MWWorld::Ptr& ptr) const
{
if (!ptr.getRefData().getCreatureStats().get())
{
boost::shared_ptr<MWMechanics::CreatureStats> stats (
new MWMechanics::CreatureStats);
ESMS::LiveCellRef<ESM::Creature, MWWorld::RefData> *ref = ptr.get<ESM::Creature>();
stats->mAttributes[0].set (ref->base->data.strength);
stats->mAttributes[1].set (ref->base->data.intelligence);
stats->mAttributes[2].set (ref->base->data.willpower);
stats->mAttributes[3].set (ref->base->data.agility);
stats->mAttributes[4].set (ref->base->data.speed);
stats->mAttributes[5].set (ref->base->data.endurance);
stats->mAttributes[6].set (ref->base->data.personality);
stats->mAttributes[7].set (ref->base->data.luck);
stats->mDynamic[0].set (ref->base->data.health);
stats->mDynamic[1].set (ref->base->data.mana);
stats->mDynamic[2].set (ref->base->data.fatigue);
stats->mLevel = ref->base->data.level;
ptr.getRefData().getCreatureStats() = stats;
}
ensureCustomData (ptr);
return *ptr.getRefData().getCreatureStats();
return dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mCreatureStats;
}
boost::shared_ptr<MWWorld::Action> Creature::activate (const MWWorld::Ptr& ptr,
......
......@@ -10,6 +10,8 @@ namespace MWClass
{
class Creature : public MWWorld::Class
{
void ensureCustomData (const MWWorld::Ptr& ptr) const;
public:
virtual std::string getId (const MWWorld::Ptr& ptr) const;
......
......@@ -24,6 +24,7 @@ namespace
struct CustomData : public MWWorld::CustomData
{
MWMechanics::NpcStats mNpcStats;
MWMechanics::CreatureStats mCreatureStats;
virtual MWWorld::CustomData *clone() const;
};
......@@ -44,6 +45,7 @@ namespace MWClass
ESMS::LiveCellRef<ESM::NPC, MWWorld::RefData> *ref = ptr.get<ESM::NPC>();
// NPC stats
if (!ref->base->faction.empty())
{
// TODO research how initial rank is stored. The information in loadnpc.hpp are at
......@@ -54,6 +56,22 @@ namespace MWClass
for (int i=0; i<27; ++i)
data->mNpcStats.mSkill[i].setBase (ref->base->npdt52.skills[i]);
// creature stats
data->mCreatureStats.mAttributes[0].set (ref->base->npdt52.strength);
data->mCreatureStats.mAttributes[1].set (ref->base->npdt52.intelligence);
data->mCreatureStats.mAttributes[2].set (ref->base->npdt52.willpower);
data->mCreatureStats.mAttributes[3].set (ref->base->npdt52.agility);
data->mCreatureStats.mAttributes[4].set (ref->base->npdt52.speed);
data->mCreatureStats.mAttributes[5].set (ref->base->npdt52.endurance);
data->mCreatureStats.mAttributes[6].set (ref->base->npdt52.personality);
data->mCreatureStats.mAttributes[7].set (ref->base->npdt52.luck);
data->mCreatureStats.mDynamic[0].set (ref->base->npdt52.health);
data->mCreatureStats.mDynamic[1].set (ref->base->npdt52.mana);
data->mCreatureStats.mDynamic[2].set (ref->base->npdt52.fatigue);
data->mCreatureStats.mLevel = ref->base->npdt52.level;
// store
ptr.getRefData().setCustomData (data.release());
}
}
......@@ -113,31 +131,9 @@ namespace MWClass
MWMechanics::CreatureStats& Npc::getCreatureStats (const MWWorld::Ptr& ptr) const
{
if (!ptr.getRefData().getCreatureStats().get())
{
boost::shared_ptr<MWMechanics::CreatureStats> stats (
new MWMechanics::CreatureStats);
ESMS::LiveCellRef<ESM::NPC, MWWorld::RefData> *ref = ptr.get<ESM::NPC>();
stats->mAttributes[0].set (ref->base->npdt52.strength);
stats->mAttributes[1].set (ref->base->npdt52.intelligence);
stats->mAttributes[2].set (ref->base->npdt52.willpower);
stats->mAttributes[3].set (ref->base->npdt52.agility);
stats->mAttributes[4].set (ref->base->npdt52.speed);
stats->mAttributes[5].set (ref->base->npdt52.endurance);
stats->mAttributes[6].set (ref->base->npdt52.personality);
stats->mAttributes[7].set (ref->base->npdt52.luck);
stats->mDynamic[0].set (ref->base->npdt52.health);
stats->mDynamic[1].set (ref->base->npdt52.mana);
stats->mDynamic[2].set (ref->base->npdt52.fatigue);
stats->mLevel = ref->base->npdt52.level;
ptr.getRefData().getCreatureStats() = stats;
}
ensureCustomData (ptr);
return *ptr.getRefData().getCreatureStats();
return dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mCreatureStats;
}
MWMechanics::NpcStats& Npc::getNpcStats (const MWWorld::Ptr& ptr) const
......
......@@ -14,7 +14,6 @@ namespace MWWorld
mCount = refData.mCount;
mPosition = refData.mPosition;
mCreatureStats = refData.mCreatureStats;
mMovement = refData.mMovement;
mContainerStore = refData.mContainerStore;
......@@ -128,11 +127,6 @@ namespace MWWorld
mEnabled = true;
}
boost::shared_ptr<MWMechanics::CreatureStats>& RefData::getCreatureStats()
{
return mCreatureStats;
}
boost::shared_ptr<MWMechanics::Movement>& RefData::getMovement()
{
return mMovement;
......
......@@ -9,7 +9,6 @@
#include "../mwscript/locals.hpp"
#include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/movement.hpp"
#include "containerstore.hpp"
......@@ -43,7 +42,6 @@ namespace MWWorld
// assignment operator and destructor. As a consequence though copying a RefData object
// manually will probably give unexcepted results. This is not a problem since RefData
// are never copied outside of container operations.
boost::shared_ptr<MWMechanics::CreatureStats> mCreatureStats;
boost::shared_ptr<MWMechanics::Movement> mMovement;
boost::shared_ptr<ContainerStore<RefData> > mContainerStore;
......@@ -88,8 +86,6 @@ namespace MWWorld
void disable();
boost::shared_ptr<MWMechanics::CreatureStats>& getCreatureStats();
boost::shared_ptr<MWMechanics::Movement>& getMovement();
boost::shared_ptr<ContainerStore<RefData> >& getContainerStore();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment