mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-30 15:15:31 +00:00
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 "../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<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,
|
||||
const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const
|
||||
{
|
||||
|
|
|
@ -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<MWWorld::RefData>& getContainerStore (
|
||||
const MWWorld::Ptr& ptr) const;
|
||||
///< 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");
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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<MWMechanics::CreatureStats> mCreatureStats;
|
||||
boost::shared_ptr<MWMechanics::NpcStats> mNpcStats;
|
||||
|
||||
boost::shared_ptr<ContainerStore<RefData> > mContainerStore;
|
||||
|
||||
|
@ -98,6 +97,11 @@ namespace MWWorld
|
|||
return mCreatureStats;
|
||||
}
|
||||
|
||||
boost::shared_ptr<MWMechanics::NpcStats>& getNpcStats()
|
||||
{
|
||||
return mNpcStats;
|
||||
}
|
||||
|
||||
boost::shared_ptr<ContainerStore<RefData> >& getContainerStore()
|
||||
{
|
||||
return mContainerStore;
|
||||
|
|
Loading…
Reference in a new issue