2010-08-03 11:03:08 +00:00
|
|
|
|
|
|
|
#include "npc.hpp"
|
|
|
|
|
|
|
|
#include <components/esm/loadnpc.hpp>
|
|
|
|
|
2010-08-03 11:32:37 +00:00
|
|
|
#include "../mwmechanics/creaturestats.hpp"
|
2010-08-19 10:49:13 +00:00
|
|
|
#include "../mwmechanics/npcstats.hpp"
|
2010-08-03 11:32:37 +00:00
|
|
|
|
2010-08-03 11:17:31 +00:00
|
|
|
#include "../mwworld/ptr.hpp"
|
2010-08-06 16:15:46 +00:00
|
|
|
#include "../mwworld/actiontalk.hpp"
|
2010-08-14 08:02:54 +00:00
|
|
|
#include "../mwworld/environment.hpp"
|
|
|
|
#include "../mwworld/world.hpp"
|
|
|
|
|
2010-08-14 09:27:13 +00:00
|
|
|
#include "../mwmechanics/mechanicsmanager.hpp"
|
2010-11-25 23:36:25 +00:00
|
|
|
#include <OgreSceneNode.h>
|
2010-08-03 11:03:08 +00:00
|
|
|
|
2011-01-18 09:45:29 +00:00
|
|
|
namespace
|
2011-01-10 23:13:32 +00:00
|
|
|
{
|
|
|
|
const Ogre::Radian kOgrePi (Ogre::Math::PI);
|
|
|
|
const Ogre::Radian kOgrePiOverTwo (Ogre::Math::PI / Ogre::Real(2.0));
|
|
|
|
}
|
|
|
|
|
2010-08-03 11:17:31 +00:00
|
|
|
namespace MWClass
|
2010-08-03 11:03:08 +00:00
|
|
|
{
|
2010-08-08 12:28:35 +00:00
|
|
|
std::string Npc::getId (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
ESMS::LiveCellRef<ESM::NPC, MWWorld::RefData> *ref =
|
|
|
|
ptr.get<ESM::NPC>();
|
|
|
|
|
|
|
|
return ref->base->mId;
|
|
|
|
}
|
|
|
|
|
2011-11-12 04:01:12 +00:00
|
|
|
void Npc::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
|
2010-08-14 08:02:54 +00:00
|
|
|
{
|
2011-11-17 22:10:27 +00:00
|
|
|
/*
|
2010-08-14 08:02:54 +00:00
|
|
|
ESMS::LiveCellRef<ESM::NPC, MWWorld::RefData> *ref =
|
|
|
|
ptr.get<ESM::NPC>();
|
2011-01-18 09:45:29 +00:00
|
|
|
|
2010-08-14 08:02:54 +00:00
|
|
|
assert (ref->base != NULL);
|
2011-11-12 04:01:12 +00:00
|
|
|
const std::string &model = ref->base->model;
|
|
|
|
|
|
|
|
if (!model.empty())
|
2011-01-05 21:18:21 +00:00
|
|
|
{
|
2011-11-19 06:01:19 +00:00
|
|
|
MWRender::Npcs& npcs = renderingInterface.getNPCs();
|
2011-11-12 20:58:22 +00:00
|
|
|
//npcs.insertBegin(ptr, ptr.getRefData().isEnabled(), false);
|
|
|
|
//npcs.insertMesh(ptr, "meshes\\" + model);
|
2011-11-17 22:10:27 +00:00
|
|
|
}*/
|
2011-11-12 04:01:12 +00:00
|
|
|
}
|
2010-12-22 02:45:54 +00:00
|
|
|
|
2011-11-12 04:01:12 +00:00
|
|
|
void Npc::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const
|
|
|
|
{
|
2011-11-17 22:10:27 +00:00
|
|
|
|
|
|
|
/*
|
2011-11-12 04:01:12 +00:00
|
|
|
ESMS::LiveCellRef<ESM::NPC, MWWorld::RefData> *ref =
|
|
|
|
ptr.get<ESM::NPC>();
|
2011-01-18 09:45:29 +00:00
|
|
|
|
2010-11-25 23:36:25 +00:00
|
|
|
|
2011-11-12 04:01:12 +00:00
|
|
|
const std::string &model = ref->base->model;
|
|
|
|
assert (ref->base != NULL);
|
|
|
|
if(!model.empty()){
|
2011-11-18 00:38:52 +00:00
|
|
|
physics.insertActorPhysics(ptr, "meshes\\" + model);
|
2011-11-17 22:10:27 +00:00
|
|
|
}*/
|
2011-01-29 16:33:48 +00:00
|
|
|
|
2011-01-05 21:18:21 +00:00
|
|
|
}
|
2010-08-14 08:02:54 +00:00
|
|
|
|
2010-08-14 09:27:13 +00:00
|
|
|
void Npc::enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const
|
|
|
|
{
|
|
|
|
environment.mMechanicsManager->addActor (ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Npc::disable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const
|
|
|
|
{
|
|
|
|
environment.mMechanicsManager->removeActor (ptr);
|
|
|
|
}
|
|
|
|
|
2010-08-03 15:11:41 +00:00
|
|
|
std::string Npc::getName (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
ESMS::LiveCellRef<ESM::NPC, MWWorld::RefData> *ref =
|
|
|
|
ptr.get<ESM::NPC>();
|
|
|
|
|
|
|
|
return ref->base->name;
|
|
|
|
}
|
|
|
|
|
2010-08-03 11:17:31 +00:00
|
|
|
MWMechanics::CreatureStats& Npc::getCreatureStats (const MWWorld::Ptr& ptr) const
|
2010-08-03 11:03:08 +00:00
|
|
|
{
|
|
|
|
if (!ptr.getRefData().getCreatureStats().get())
|
|
|
|
{
|
|
|
|
boost::shared_ptr<MWMechanics::CreatureStats> stats (
|
|
|
|
new MWMechanics::CreatureStats);
|
|
|
|
|
2010-08-03 11:17:31 +00:00
|
|
|
ESMS::LiveCellRef<ESM::NPC, MWWorld::RefData> *ref = ptr.get<ESM::NPC>();
|
2010-08-03 11:03:08 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2010-09-15 13:32:35 +00:00
|
|
|
stats->mLevel = ref->base->npdt52.level;
|
|
|
|
|
2010-08-03 11:03:08 +00:00
|
|
|
ptr.getRefData().getCreatureStats() = stats;
|
|
|
|
}
|
|
|
|
|
|
|
|
return *ptr.getRefData().getCreatureStats();
|
|
|
|
}
|
|
|
|
|
2010-08-19 10:49:13 +00:00
|
|
|
MWMechanics::NpcStats& Npc::getNpcStats (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
if (!ptr.getRefData().getNpcStats().get())
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-09-16 08:45:08 +00:00
|
|
|
for (int i=0; i<27; ++i)
|
|
|
|
stats->mSkill[i].setBase (ref->base->npdt52.skills[i]);
|
|
|
|
|
2010-08-19 10:49:13 +00:00
|
|
|
ptr.getRefData().getNpcStats() = stats;
|
|
|
|
}
|
|
|
|
|
|
|
|
return *ptr.getRefData().getNpcStats();
|
|
|
|
}
|
|
|
|
|
2010-08-06 16:15:46 +00:00
|
|
|
boost::shared_ptr<MWWorld::Action> Npc::activate (const MWWorld::Ptr& ptr,
|
|
|
|
const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const
|
|
|
|
{
|
|
|
|
return boost::shared_ptr<MWWorld::Action> (new MWWorld::ActionTalk (ptr));
|
2010-08-14 08:02:54 +00:00
|
|
|
}
|
2010-08-07 18:33:07 +00:00
|
|
|
|
2010-08-06 12:37:53 +00:00
|
|
|
MWWorld::ContainerStore<MWWorld::RefData>& Npc::getContainerStore (const MWWorld::Ptr& ptr)
|
|
|
|
const
|
2010-08-04 12:37:23 +00:00
|
|
|
{
|
|
|
|
if (!ptr.getRefData().getContainerStore().get())
|
|
|
|
{
|
|
|
|
boost::shared_ptr<MWWorld::ContainerStore<MWWorld::RefData> > store (
|
|
|
|
new MWWorld::ContainerStore<MWWorld::RefData>);
|
|
|
|
|
|
|
|
// TODO add initial content
|
|
|
|
|
|
|
|
ptr.getRefData().getContainerStore() = store;
|
|
|
|
}
|
|
|
|
|
|
|
|
return *ptr.getRefData().getContainerStore();
|
|
|
|
}
|
|
|
|
|
2010-08-05 13:40:03 +00:00
|
|
|
std::string Npc::getScript (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
ESMS::LiveCellRef<ESM::NPC, MWWorld::RefData> *ref =
|
|
|
|
ptr.get<ESM::NPC>();
|
|
|
|
|
|
|
|
return ref->base->script;
|
|
|
|
}
|
|
|
|
|
2011-01-18 09:45:29 +00:00
|
|
|
void Npc::setForceStance (const MWWorld::Ptr& ptr, Stance stance, bool force) const
|
|
|
|
{
|
|
|
|
MWMechanics::NpcStats& stats = getNpcStats (ptr);
|
|
|
|
|
|
|
|
switch (stance)
|
|
|
|
{
|
|
|
|
case Run:
|
|
|
|
|
|
|
|
stats.mForceRun = force;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Sneak:
|
|
|
|
|
|
|
|
stats.mForceSneak = force;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Combat:
|
|
|
|
|
|
|
|
throw std::runtime_error ("combat stance not enforcable for NPCs");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Npc::setStance (const MWWorld::Ptr& ptr, Stance stance, bool set) const
|
|
|
|
{
|
|
|
|
MWMechanics::NpcStats& stats = getNpcStats (ptr);
|
|
|
|
|
|
|
|
switch (stance)
|
|
|
|
{
|
|
|
|
case Run:
|
|
|
|
|
2011-02-10 10:08:25 +00:00
|
|
|
stats.mRun = set;
|
|
|
|
break;
|
2011-01-18 09:45:29 +00:00
|
|
|
|
|
|
|
case Sneak:
|
|
|
|
|
|
|
|
stats.mSneak = set;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Combat:
|
|
|
|
|
|
|
|
stats.mCombat = set;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Npc::getStance (const MWWorld::Ptr& ptr, Stance stance, bool ignoreForce) const
|
|
|
|
{
|
|
|
|
MWMechanics::NpcStats& stats = getNpcStats (ptr);
|
|
|
|
|
|
|
|
switch (stance)
|
|
|
|
{
|
|
|
|
case Run:
|
|
|
|
|
2011-02-10 10:08:25 +00:00
|
|
|
if (!ignoreForce && stats.mForceRun)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return stats.mRun;
|
2011-01-18 09:45:29 +00:00
|
|
|
|
|
|
|
case Sneak:
|
|
|
|
|
|
|
|
if (!ignoreForce && stats.mForceSneak)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return stats.mSneak;
|
|
|
|
|
|
|
|
case Combat:
|
|
|
|
|
|
|
|
return stats.mCombat;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
float Npc::getSpeed (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
return getStance (ptr, Run) ? 600 : 300; // TODO calculate these values from stats
|
|
|
|
}
|
|
|
|
|
2011-02-03 10:37:17 +00:00
|
|
|
MWMechanics::Movement& Npc::getMovementSettings (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
if (!ptr.getRefData().getMovement().get())
|
|
|
|
{
|
|
|
|
boost::shared_ptr<MWMechanics::Movement> movement (
|
|
|
|
new MWMechanics::Movement);
|
2011-02-03 11:16:20 +00:00
|
|
|
|
|
|
|
ptr.getRefData().getMovement() = movement;
|
2011-02-03 10:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return *ptr.getRefData().getMovement();
|
|
|
|
}
|
|
|
|
|
|
|
|
Ogre::Vector3 Npc::getMovementVector (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
Ogre::Vector3 vector (0, 0, 0);
|
|
|
|
|
|
|
|
if (ptr.getRefData().getMovement().get())
|
|
|
|
{
|
|
|
|
vector.x = - ptr.getRefData().getMovement()->mLeftRight * 200;
|
2011-03-11 18:39:45 +00:00
|
|
|
vector.y = ptr.getRefData().getMovement()->mForwardBackward * 200;
|
2011-02-03 10:37:17 +00:00
|
|
|
|
|
|
|
if (getStance (ptr, Run, false))
|
|
|
|
vector *= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return vector;
|
|
|
|
}
|
|
|
|
|
2010-08-03 11:03:08 +00:00
|
|
|
void Npc::registerSelf()
|
|
|
|
{
|
|
|
|
boost::shared_ptr<Class> instance (new Npc);
|
|
|
|
|
|
|
|
registerClass (typeid (ESM::NPC).name(), instance);
|
|
|
|
}
|
|
|
|
}
|