forked from teamnwah/openmw-tes3coop
replaced NPC stats in ref data with new custom data implementation
This commit is contained in:
parent
baf9cff21d
commit
c6761e3470
5 changed files with 42 additions and 31 deletions
|
@ -1,6 +1,8 @@
|
||||||
|
|
||||||
#include "npc.hpp"
|
#include "npc.hpp"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <components/esm/loadnpc.hpp>
|
#include <components/esm/loadnpc.hpp>
|
||||||
|
|
||||||
#include "../mwmechanics/creaturestats.hpp"
|
#include "../mwmechanics/creaturestats.hpp"
|
||||||
|
@ -18,10 +20,44 @@ namespace
|
||||||
{
|
{
|
||||||
const Ogre::Radian kOgrePi (Ogre::Math::PI);
|
const Ogre::Radian kOgrePi (Ogre::Math::PI);
|
||||||
const Ogre::Radian kOgrePiOverTwo (Ogre::Math::PI / Ogre::Real(2.0));
|
const Ogre::Radian kOgrePiOverTwo (Ogre::Math::PI / Ogre::Real(2.0));
|
||||||
|
|
||||||
|
struct CustomData : public MWWorld::CustomData
|
||||||
|
{
|
||||||
|
MWMechanics::NpcStats mNpcStats;
|
||||||
|
|
||||||
|
virtual MWWorld::CustomData *clone() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
MWWorld::CustomData *CustomData::clone() const
|
||||||
|
{
|
||||||
|
return new CustomData (*this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace MWClass
|
namespace MWClass
|
||||||
{
|
{
|
||||||
|
void Npc::ensureCustomData (const MWWorld::Ptr& ptr) const
|
||||||
|
{
|
||||||
|
if (!ptr.getRefData().getCustomData())
|
||||||
|
{
|
||||||
|
std::auto_ptr<CustomData> data (new CustomData);
|
||||||
|
|
||||||
|
ESMS::LiveCellRef<ESM::NPC, MWWorld::RefData> *ref = ptr.get<ESM::NPC>();
|
||||||
|
|
||||||
|
if (!ref->base->faction.empty())
|
||||||
|
{
|
||||||
|
// TODO research how initial rank is stored. The information in loadnpc.hpp are at
|
||||||
|
// best very unclear.
|
||||||
|
data->mNpcStats.mFactionRank[ref->base->faction] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i=0; i<27; ++i)
|
||||||
|
data->mNpcStats.mSkill[i].setBase (ref->base->npdt52.skills[i]);
|
||||||
|
|
||||||
|
ptr.getRefData().setCustomData (data.release());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::string Npc::getId (const MWWorld::Ptr& ptr) const
|
std::string Npc::getId (const MWWorld::Ptr& ptr) const
|
||||||
{
|
{
|
||||||
ESMS::LiveCellRef<ESM::NPC, MWWorld::RefData> *ref =
|
ESMS::LiveCellRef<ESM::NPC, MWWorld::RefData> *ref =
|
||||||
|
@ -106,27 +142,9 @@ namespace MWClass
|
||||||
|
|
||||||
MWMechanics::NpcStats& Npc::getNpcStats (const MWWorld::Ptr& ptr) const
|
MWMechanics::NpcStats& Npc::getNpcStats (const MWWorld::Ptr& ptr) const
|
||||||
{
|
{
|
||||||
if (!ptr.getRefData().getNpcStats().get())
|
ensureCustomData (ptr);
|
||||||
{
|
|
||||||
boost::shared_ptr<MWMechanics::NpcStats> stats (
|
|
||||||
new MWMechanics::NpcStats);
|
|
||||||
|
|
||||||
ESMS::LiveCellRef<ESM::NPC, MWWorld::RefData> *ref = ptr.get<ESM::NPC>();
|
return dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mNpcStats;
|
||||||
|
|
||||||
if (!ref->base->faction.empty())
|
|
||||||
{
|
|
||||||
// TODO research how initial rank is stored. The information in loadnpc.hpp are at
|
|
||||||
// best very unclear.
|
|
||||||
stats->mFactionRank[ref->base->faction] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i=0; i<27; ++i)
|
|
||||||
stats->mSkill[i].setBase (ref->base->npdt52.skills[i]);
|
|
||||||
|
|
||||||
ptr.getRefData().getNpcStats() = stats;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *ptr.getRefData().getNpcStats();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::shared_ptr<MWWorld::Action> Npc::activate (const MWWorld::Ptr& ptr,
|
boost::shared_ptr<MWWorld::Action> Npc::activate (const MWWorld::Ptr& ptr,
|
||||||
|
|
|
@ -2,12 +2,14 @@
|
||||||
#define GAME_MWCLASS_NPC_H
|
#define GAME_MWCLASS_NPC_H
|
||||||
|
|
||||||
#include "../mwworld/class.hpp"
|
#include "../mwworld/class.hpp"
|
||||||
|
#include "../mwworld/customdata.hpp"
|
||||||
|
|
||||||
namespace MWClass
|
namespace MWClass
|
||||||
{
|
{
|
||||||
class Npc : public MWWorld::Class
|
class Npc : public MWWorld::Class
|
||||||
{
|
{
|
||||||
|
void ensureCustomData (const MWWorld::Ptr& ptr) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual std::string getId (const MWWorld::Ptr& ptr) const;
|
virtual std::string getId (const MWWorld::Ptr& ptr) const;
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "../mwworld/class.hpp"
|
#include "../mwworld/class.hpp"
|
||||||
|
|
||||||
#include "../mwmechanics/creaturestats.hpp"
|
#include "../mwmechanics/creaturestats.hpp"
|
||||||
|
#include "../mwmechanics/npcstats.hpp"
|
||||||
|
|
||||||
#include "interpretercontext.hpp"
|
#include "interpretercontext.hpp"
|
||||||
#include "ref.hpp"
|
#include "ref.hpp"
|
||||||
|
|
|
@ -15,7 +15,6 @@ namespace MWWorld
|
||||||
mPosition = refData.mPosition;
|
mPosition = refData.mPosition;
|
||||||
|
|
||||||
mCreatureStats = refData.mCreatureStats;
|
mCreatureStats = refData.mCreatureStats;
|
||||||
mNpcStats = refData.mNpcStats;
|
|
||||||
mMovement = refData.mMovement;
|
mMovement = refData.mMovement;
|
||||||
mContainerStore = refData.mContainerStore;
|
mContainerStore = refData.mContainerStore;
|
||||||
|
|
||||||
|
@ -134,11 +133,6 @@ namespace MWWorld
|
||||||
return mCreatureStats;
|
return mCreatureStats;
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::shared_ptr<MWMechanics::NpcStats>& RefData::getNpcStats()
|
|
||||||
{
|
|
||||||
return mNpcStats;
|
|
||||||
}
|
|
||||||
|
|
||||||
boost::shared_ptr<MWMechanics::Movement>& RefData::getMovement()
|
boost::shared_ptr<MWMechanics::Movement>& RefData::getMovement()
|
||||||
{
|
{
|
||||||
return mMovement;
|
return mMovement;
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
#include "../mwscript/locals.hpp"
|
#include "../mwscript/locals.hpp"
|
||||||
|
|
||||||
#include "../mwmechanics/creaturestats.hpp"
|
#include "../mwmechanics/creaturestats.hpp"
|
||||||
#include "../mwmechanics/npcstats.hpp"
|
|
||||||
#include "../mwmechanics/movement.hpp"
|
#include "../mwmechanics/movement.hpp"
|
||||||
|
|
||||||
#include "containerstore.hpp"
|
#include "containerstore.hpp"
|
||||||
|
@ -45,7 +44,6 @@ namespace MWWorld
|
||||||
// manually will probably give unexcepted results. This is not a problem since RefData
|
// manually will probably give unexcepted results. This is not a problem since RefData
|
||||||
// are never copied outside of container operations.
|
// are never copied outside of container operations.
|
||||||
boost::shared_ptr<MWMechanics::CreatureStats> mCreatureStats;
|
boost::shared_ptr<MWMechanics::CreatureStats> mCreatureStats;
|
||||||
boost::shared_ptr<MWMechanics::NpcStats> mNpcStats;
|
|
||||||
boost::shared_ptr<MWMechanics::Movement> mMovement;
|
boost::shared_ptr<MWMechanics::Movement> mMovement;
|
||||||
|
|
||||||
boost::shared_ptr<ContainerStore<RefData> > mContainerStore;
|
boost::shared_ptr<ContainerStore<RefData> > mContainerStore;
|
||||||
|
@ -92,8 +90,6 @@ namespace MWWorld
|
||||||
|
|
||||||
boost::shared_ptr<MWMechanics::CreatureStats>& getCreatureStats();
|
boost::shared_ptr<MWMechanics::CreatureStats>& getCreatureStats();
|
||||||
|
|
||||||
boost::shared_ptr<MWMechanics::NpcStats>& getNpcStats();
|
|
||||||
|
|
||||||
boost::shared_ptr<MWMechanics::Movement>& getMovement();
|
boost::shared_ptr<MWMechanics::Movement>& getMovement();
|
||||||
|
|
||||||
boost::shared_ptr<ContainerStore<RefData> >& getContainerStore();
|
boost::shared_ptr<ContainerStore<RefData> >& getContainerStore();
|
||||||
|
|
Loading…
Reference in a new issue