From 3b49d6c82655463699f064a7346e6e9bed141fe8 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 19 Aug 2010 12:49:13 +0200 Subject: [PATCH] added NPC stats --- apps/openmw/mwclass/npc.cpp | 24 ++++++++++++++++++++++++ apps/openmw/mwclass/npc.hpp | 3 +++ apps/openmw/mwmechanics/npcstats.hpp | 20 ++++++++++++++++++++ apps/openmw/mwworld/class.cpp | 5 +++++ apps/openmw/mwworld/class.hpp | 5 +++++ apps/openmw/mwworld/refdata.hpp | 14 +++++++++----- 6 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 apps/openmw/mwmechanics/npcstats.hpp diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 3bc005b06..0fdc77963 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -4,6 +4,7 @@ #include #include "../mwmechanics/creaturestats.hpp" +#include "../mwmechanics/npcstats.hpp" #include "../mwworld/ptr.hpp" #include "../mwworld/actiontalk.hpp" @@ -98,6 +99,29 @@ namespace MWClass return *ptr.getRefData().getCreatureStats(); } + MWMechanics::NpcStats& Npc::getNpcStats (const MWWorld::Ptr& ptr) const + { + if (!ptr.getRefData().getNpcStats().get()) + { + // xxx + boost::shared_ptr stats ( + new MWMechanics::NpcStats); + + ESMS::LiveCellRef *ref = ptr.get(); + + 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 Npc::activate (const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const { diff --git a/apps/openmw/mwclass/npc.hpp b/apps/openmw/mwclass/npc.hpp index dd54806bd..ab52f76c4 100644 --- a/apps/openmw/mwclass/npc.hpp +++ b/apps/openmw/mwclass/npc.hpp @@ -29,6 +29,9 @@ namespace MWClass virtual MWMechanics::CreatureStats& getCreatureStats (const MWWorld::Ptr& ptr) const; ///< Return creature stats + virtual MWMechanics::NpcStats& getNpcStats (const MWWorld::Ptr& ptr) const; + ///< Return NPC stats + virtual MWWorld::ContainerStore& getContainerStore ( const MWWorld::Ptr& ptr) const; ///< Return container store diff --git a/apps/openmw/mwmechanics/npcstats.hpp b/apps/openmw/mwmechanics/npcstats.hpp new file mode 100644 index 000000000..25f698bca --- /dev/null +++ b/apps/openmw/mwmechanics/npcstats.hpp @@ -0,0 +1,20 @@ +#ifndef GAME_MWMECHANICS_NPCSTATS_H +#define GAME_MWMECHANICS_NPCSTATS_H + +#include + +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 mFactionRank; + }; +} + +#endif diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index bc36944e6..e21e4908c 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -40,6 +40,11 @@ namespace MWWorld 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 { return false; diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index 4b6644e96..c3f4bff14 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -18,6 +18,7 @@ namespace MWRender namespace MWMechanics { struct CreatureStats; + struct NpcStats; } namespace MWWorld @@ -68,6 +69,10 @@ namespace MWWorld ///< Return creature stats or throw an exception, if class does not have creature stats /// (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; ///< \return Item health data available? (default implementation: false) diff --git a/apps/openmw/mwworld/refdata.hpp b/apps/openmw/mwworld/refdata.hpp index b041a06cb..a8cf3aed8 100644 --- a/apps/openmw/mwworld/refdata.hpp +++ b/apps/openmw/mwworld/refdata.hpp @@ -7,6 +7,9 @@ #include "../mwscript/locals.hpp" +#include "../mwmechanics/creaturestats.hpp" +#include "../mwmechanics/npcstats.hpp" + #include "containerstore.hpp" namespace ESM @@ -14,11 +17,6 @@ namespace ESM class Script; } -namespace MWMechanics -{ - struct CreatureStats; -} - namespace MWWorld { class RefData @@ -37,6 +35,7 @@ namespace MWWorld // manually will probably give unexcepted results. This is not a problem since RefData // are never copied outside of container operations. boost::shared_ptr mCreatureStats; + boost::shared_ptr mNpcStats; boost::shared_ptr > mContainerStore; @@ -98,6 +97,11 @@ namespace MWWorld return mCreatureStats; } + boost::shared_ptr& getNpcStats() + { + return mNpcStats; + } + boost::shared_ptr >& getContainerStore() { return mContainerStore;