forked from mirror/openmw-tes3mp
added NPC stats
This commit is contained in:
parent
38ad2d98f9
commit
3b49d6c826
6 changed files with 66 additions and 5 deletions
|
@ -4,6 +4,7 @@
|
||||||
#include <components/esm/loadnpc.hpp>
|
#include <components/esm/loadnpc.hpp>
|
||||||
|
|
||||||
#include "../mwmechanics/creaturestats.hpp"
|
#include "../mwmechanics/creaturestats.hpp"
|
||||||
|
#include "../mwmechanics/npcstats.hpp"
|
||||||
|
|
||||||
#include "../mwworld/ptr.hpp"
|
#include "../mwworld/ptr.hpp"
|
||||||
#include "../mwworld/actiontalk.hpp"
|
#include "../mwworld/actiontalk.hpp"
|
||||||
|
@ -98,6 +99,29 @@ namespace MWClass
|
||||||
return *ptr.getRefData().getCreatureStats();
|
return *ptr.getRefData().getCreatureStats();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MWMechanics::NpcStats& Npc::getNpcStats (const MWWorld::Ptr& ptr) const
|
||||||
|
{
|
||||||
|
if (!ptr.getRefData().getNpcStats().get())
|
||||||
|
{
|
||||||
|
// xxx
|
||||||
|
boost::shared_ptr<MWMechanics::NpcStats> stats (
|
||||||
|
new MWMechanics::NpcStats);
|
||||||
|
|
||||||
|
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.
|
||||||
|
stats->mFactionRank[ref->base->faction] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
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,
|
||||||
const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const
|
const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,6 +29,9 @@ namespace MWClass
|
||||||
virtual MWMechanics::CreatureStats& getCreatureStats (const MWWorld::Ptr& ptr) const;
|
virtual MWMechanics::CreatureStats& getCreatureStats (const MWWorld::Ptr& ptr) const;
|
||||||
///< Return creature stats
|
///< Return creature stats
|
||||||
|
|
||||||
|
virtual MWMechanics::NpcStats& getNpcStats (const MWWorld::Ptr& ptr) const;
|
||||||
|
///< Return NPC stats
|
||||||
|
|
||||||
virtual MWWorld::ContainerStore<MWWorld::RefData>& getContainerStore (
|
virtual MWWorld::ContainerStore<MWWorld::RefData>& getContainerStore (
|
||||||
const MWWorld::Ptr& ptr) const;
|
const MWWorld::Ptr& ptr) const;
|
||||||
///< Return container store
|
///< Return container store
|
||||||
|
|
20
apps/openmw/mwmechanics/npcstats.hpp
Normal file
20
apps/openmw/mwmechanics/npcstats.hpp
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#ifndef GAME_MWMECHANICS_NPCSTATS_H
|
||||||
|
#define GAME_MWMECHANICS_NPCSTATS_H
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
namespace MWMechanics
|
||||||
|
{
|
||||||
|
/// \brief Additional stats for NPCs
|
||||||
|
///
|
||||||
|
/// For non-NPC-specific stats, see the CreatureStats struct.
|
||||||
|
|
||||||
|
struct NpcStats
|
||||||
|
{
|
||||||
|
// NPCs other than the player can only have one faction. But for the sake of consistency
|
||||||
|
// we use the same data structure for the PC and the NPCs.
|
||||||
|
std::map<std::string, int> mFactionRank;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -40,6 +40,11 @@ namespace MWWorld
|
||||||
throw std::runtime_error ("class does not have creature stats");
|
throw std::runtime_error ("class does not have creature stats");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MWMechanics::NpcStats& Class::getNpcStats (const Ptr& ptr) const
|
||||||
|
{
|
||||||
|
throw std::runtime_error ("class does not have NPC stats");
|
||||||
|
}
|
||||||
|
|
||||||
bool Class::hasItemHealth (const Ptr& ptr) const
|
bool Class::hasItemHealth (const Ptr& ptr) const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -18,6 +18,7 @@ namespace MWRender
|
||||||
namespace MWMechanics
|
namespace MWMechanics
|
||||||
{
|
{
|
||||||
struct CreatureStats;
|
struct CreatureStats;
|
||||||
|
struct NpcStats;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace MWWorld
|
namespace MWWorld
|
||||||
|
@ -68,6 +69,10 @@ namespace MWWorld
|
||||||
///< Return creature stats or throw an exception, if class does not have creature stats
|
///< Return creature stats or throw an exception, if class does not have creature stats
|
||||||
/// (default implementation: throw an exceoption)
|
/// (default implementation: throw an exceoption)
|
||||||
|
|
||||||
|
virtual MWMechanics::NpcStats& getNpcStats (const Ptr& ptr) const;
|
||||||
|
///< Return NPC stats or throw an exception, if class does not have NPC stats
|
||||||
|
/// (default implementation: throw an exceoption)
|
||||||
|
|
||||||
virtual bool hasItemHealth (const Ptr& ptr) const;
|
virtual bool hasItemHealth (const Ptr& ptr) const;
|
||||||
///< \return Item health data available? (default implementation: false)
|
///< \return Item health data available? (default implementation: false)
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,9 @@
|
||||||
|
|
||||||
#include "../mwscript/locals.hpp"
|
#include "../mwscript/locals.hpp"
|
||||||
|
|
||||||
|
#include "../mwmechanics/creaturestats.hpp"
|
||||||
|
#include "../mwmechanics/npcstats.hpp"
|
||||||
|
|
||||||
#include "containerstore.hpp"
|
#include "containerstore.hpp"
|
||||||
|
|
||||||
namespace ESM
|
namespace ESM
|
||||||
|
@ -14,11 +17,6 @@ namespace ESM
|
||||||
class Script;
|
class Script;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace MWMechanics
|
|
||||||
{
|
|
||||||
struct CreatureStats;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace MWWorld
|
namespace MWWorld
|
||||||
{
|
{
|
||||||
class RefData
|
class RefData
|
||||||
|
@ -37,6 +35,7 @@ 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<ContainerStore<RefData> > mContainerStore;
|
boost::shared_ptr<ContainerStore<RefData> > mContainerStore;
|
||||||
|
|
||||||
|
@ -98,6 +97,11 @@ namespace MWWorld
|
||||||
return mCreatureStats;
|
return mCreatureStats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boost::shared_ptr<MWMechanics::NpcStats>& getNpcStats()
|
||||||
|
{
|
||||||
|
return mNpcStats;
|
||||||
|
}
|
||||||
|
|
||||||
boost::shared_ptr<ContainerStore<RefData> >& getContainerStore()
|
boost::shared_ptr<ContainerStore<RefData> >& getContainerStore()
|
||||||
{
|
{
|
||||||
return mContainerStore;
|
return mContainerStore;
|
||||||
|
|
Loading…
Reference in a new issue