2010-08-03 13:03:08 +02:00
|
|
|
|
|
|
|
#include "npc.hpp"
|
|
|
|
|
2012-01-25 16:56:49 +01:00
|
|
|
#include <memory>
|
|
|
|
|
2012-05-21 03:10:55 +02:00
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
|
2012-01-27 13:17:30 +01:00
|
|
|
#include <OgreSceneNode.h>
|
|
|
|
|
2010-08-03 13:03:08 +02:00
|
|
|
#include <components/esm/loadnpc.hpp>
|
|
|
|
|
2012-07-03 12:30:50 +02:00
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
#include "../mwbase/world.hpp"
|
2012-08-11 17:30:55 +02:00
|
|
|
#include "../mwbase/mechanicsmanager.hpp"
|
2012-08-12 18:11:09 +02:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
2012-07-03 12:30:50 +02:00
|
|
|
|
2010-08-03 13:32:37 +02:00
|
|
|
#include "../mwmechanics/creaturestats.hpp"
|
2010-08-19 12:49:13 +02:00
|
|
|
#include "../mwmechanics/npcstats.hpp"
|
2012-01-27 14:55:58 +01:00
|
|
|
#include "../mwmechanics/movement.hpp"
|
2010-08-03 13:32:37 +02:00
|
|
|
|
2010-08-03 13:17:31 +02:00
|
|
|
#include "../mwworld/ptr.hpp"
|
2010-08-06 18:15:46 +02:00
|
|
|
#include "../mwworld/actiontalk.hpp"
|
2012-10-28 16:04:33 +01:00
|
|
|
#include "../mwworld/actionopen.hpp"
|
2012-03-10 12:49:54 +01:00
|
|
|
#include "../mwworld/inventorystore.hpp"
|
2012-01-27 15:11:02 +01:00
|
|
|
#include "../mwworld/customdata.hpp"
|
2012-07-03 13:15:20 +02:00
|
|
|
#include "../mwworld/physicssystem.hpp"
|
2010-08-03 13:03:08 +02:00
|
|
|
|
2012-07-03 12:30:50 +02:00
|
|
|
#include "../mwrender/actors.hpp"
|
2012-07-03 13:15:20 +02:00
|
|
|
#include "../mwrender/renderinginterface.hpp"
|
2012-04-16 22:58:16 +02:00
|
|
|
|
2012-07-03 13:15:20 +02:00
|
|
|
#include "../mwgui/tooltips.hpp"
|
2012-04-23 15:27:03 +02:00
|
|
|
|
2011-01-18 10:45:29 +01:00
|
|
|
namespace
|
2011-01-10 16:13:32 -07:00
|
|
|
{
|
|
|
|
const Ogre::Radian kOgrePi (Ogre::Math::PI);
|
|
|
|
const Ogre::Radian kOgrePiOverTwo (Ogre::Math::PI / Ogre::Real(2.0));
|
2012-01-25 16:56:49 +01:00
|
|
|
|
|
|
|
struct CustomData : public MWWorld::CustomData
|
|
|
|
{
|
|
|
|
MWMechanics::NpcStats mNpcStats;
|
2012-01-26 11:35:47 +01:00
|
|
|
MWMechanics::CreatureStats mCreatureStats;
|
2012-01-27 13:17:30 +01:00
|
|
|
MWMechanics::Movement mMovement;
|
2012-03-10 12:49:54 +01:00
|
|
|
MWWorld::InventoryStore mInventoryStore;
|
2012-01-25 16:56:49 +01:00
|
|
|
|
|
|
|
virtual MWWorld::CustomData *clone() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
MWWorld::CustomData *CustomData::clone() const
|
|
|
|
{
|
|
|
|
return new CustomData (*this);
|
|
|
|
}
|
2011-01-10 16:13:32 -07:00
|
|
|
}
|
|
|
|
|
2010-08-03 13:17:31 +02:00
|
|
|
namespace MWClass
|
2010-08-03 13:03:08 +02:00
|
|
|
{
|
2012-01-25 16:56:49 +01:00
|
|
|
void Npc::ensureCustomData (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
if (!ptr.getRefData().getCustomData())
|
|
|
|
{
|
|
|
|
std::auto_ptr<CustomData> data (new CustomData);
|
|
|
|
|
2012-06-29 18:54:23 +02:00
|
|
|
MWWorld::LiveCellRef<ESM::NPC> *ref = ptr.get<ESM::NPC>();
|
2012-01-25 16:56:49 +01:00
|
|
|
|
2012-01-26 11:35:47 +01:00
|
|
|
// NPC stats
|
2012-11-05 16:07:59 +04:00
|
|
|
if (!ref->mBase->mFaction.empty())
|
2012-01-25 16:56:49 +01:00
|
|
|
{
|
2012-11-05 16:07:59 +04:00
|
|
|
std::string faction = ref->mBase->mFaction;
|
2012-05-21 03:10:55 +02:00
|
|
|
boost::algorithm::to_lower(faction);
|
2012-11-05 16:07:59 +04:00
|
|
|
if(ref->mBase->mNpdt52.mGold != -10)
|
2012-04-03 17:30:19 +02:00
|
|
|
{
|
2012-11-05 16:07:59 +04:00
|
|
|
data->mNpcStats.getFactionRanks()[faction] = (int)ref->mBase->mNpdt52.mRank;
|
2012-04-03 17:30:19 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-05 16:07:59 +04:00
|
|
|
data->mNpcStats.getFactionRanks()[faction] = (int)ref->mBase->mNpdt12.mRank;
|
2012-04-03 17:30:19 +02:00
|
|
|
}
|
2012-01-25 16:56:49 +01:00
|
|
|
}
|
|
|
|
|
2012-06-16 16:17:42 +02:00
|
|
|
// creature stats
|
2012-11-05 16:07:59 +04:00
|
|
|
if(ref->mBase->mNpdt52.mGold != -10)
|
2012-04-12 17:08:57 +02:00
|
|
|
{
|
|
|
|
for (int i=0; i<27; ++i)
|
2012-11-05 16:07:59 +04:00
|
|
|
data->mNpcStats.getSkill (i).setBase (ref->mBase->mNpdt52.mSkills[i]);
|
|
|
|
|
|
|
|
data->mCreatureStats.getAttribute(0).set (ref->mBase->mNpdt52.mStrength);
|
|
|
|
data->mCreatureStats.getAttribute(1).set (ref->mBase->mNpdt52.mIntelligence);
|
|
|
|
data->mCreatureStats.getAttribute(2).set (ref->mBase->mNpdt52.mWillpower);
|
|
|
|
data->mCreatureStats.getAttribute(3).set (ref->mBase->mNpdt52.mAgility);
|
|
|
|
data->mCreatureStats.getAttribute(4).set (ref->mBase->mNpdt52.mSpeed);
|
|
|
|
data->mCreatureStats.getAttribute(5).set (ref->mBase->mNpdt52.mEndurance);
|
|
|
|
data->mCreatureStats.getAttribute(6).set (ref->mBase->mNpdt52.mPersonality);
|
|
|
|
data->mCreatureStats.getAttribute(7).set (ref->mBase->mNpdt52.mLuck);
|
|
|
|
data->mCreatureStats.setHealth (ref->mBase->mNpdt52.mHealth);
|
|
|
|
data->mCreatureStats.setMagicka (ref->mBase->mNpdt52.mMana);
|
|
|
|
data->mCreatureStats.setFatigue (ref->mBase->mNpdt52.mFatigue);
|
|
|
|
|
|
|
|
data->mCreatureStats.setLevel(ref->mBase->mNpdt52.mLevel);
|
2012-11-08 23:16:40 +01:00
|
|
|
data->mNpcStats.setDisposition(ref->mBase->mNpdt52.mDisposition);
|
2012-04-12 17:08:57 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-17 11:37:50 +04:00
|
|
|
/// \todo do something with mNpdt12 maybe:p
|
2012-10-23 13:54:36 +02:00
|
|
|
for (int i=0; i<8; ++i)
|
|
|
|
data->mCreatureStats.getAttribute (i).set (10);
|
|
|
|
|
|
|
|
for (int i=0; i<3; ++i)
|
|
|
|
data->mCreatureStats.setDynamic (i, 10);
|
|
|
|
|
|
|
|
data->mCreatureStats.setLevel (1);
|
2012-04-12 17:08:57 +02:00
|
|
|
}
|
2012-01-26 11:35:47 +01:00
|
|
|
|
2012-11-10 11:38:37 +01:00
|
|
|
data->mCreatureStats.setAiSetting (0, ref->mBase->mAiData.mHello);
|
|
|
|
data->mCreatureStats.setAiSetting (1, ref->mBase->mAiData.mFight);
|
|
|
|
data->mCreatureStats.setAiSetting (2, ref->mBase->mAiData.mFlee);
|
|
|
|
data->mCreatureStats.setAiSetting (3, ref->mBase->mAiData.mAlarm);
|
2012-06-16 16:17:42 +02:00
|
|
|
|
2012-09-10 13:04:00 +02:00
|
|
|
// spells
|
2012-11-05 16:07:59 +04:00
|
|
|
for (std::vector<std::string>::const_iterator iter (ref->mBase->mSpells.mList.begin());
|
|
|
|
iter!=ref->mBase->mSpells.mList.end(); ++iter)
|
2012-09-10 13:04:00 +02:00
|
|
|
data->mCreatureStats.getSpells().add (*iter);
|
|
|
|
|
2012-01-26 11:35:47 +01:00
|
|
|
// store
|
2012-01-25 16:56:49 +01:00
|
|
|
ptr.getRefData().setCustomData (data.release());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-08 14:28:35 +02:00
|
|
|
std::string Npc::getId (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2012-06-29 18:54:23 +02:00
|
|
|
MWWorld::LiveCellRef<ESM::NPC> *ref =
|
2010-08-08 14:28:35 +02:00
|
|
|
ptr.get<ESM::NPC>();
|
|
|
|
|
2012-11-05 16:07:59 +04:00
|
|
|
return ref->mBase->mId;
|
2010-08-08 14:28:35 +02:00
|
|
|
}
|
|
|
|
|
2011-11-11 23:01:12 -05:00
|
|
|
void Npc::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
|
2010-08-14 10:02:54 +02:00
|
|
|
{
|
2012-04-07 22:02:20 -04:00
|
|
|
renderingInterface.getActors().insertNPC(ptr, getInventoryStore(ptr));
|
2011-11-11 23:01:12 -05:00
|
|
|
}
|
2010-12-21 21:45:54 -05:00
|
|
|
|
2012-04-23 15:27:03 +02:00
|
|
|
void Npc::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
|
2011-11-11 23:01:12 -05:00
|
|
|
{
|
2012-11-05 18:40:02 +00:00
|
|
|
physics.addActor(ptr);
|
2012-07-24 20:22:11 +04:00
|
|
|
MWBase::Environment::get().getMechanicsManager()->addActor(ptr);
|
|
|
|
}
|
2011-11-17 17:10:27 -05:00
|
|
|
|
2012-07-24 20:22:11 +04:00
|
|
|
std::string Npc::getModel(const MWWorld::Ptr &ptr) const
|
|
|
|
{
|
2012-06-29 18:54:23 +02:00
|
|
|
MWWorld::LiveCellRef<ESM::NPC> *ref =
|
2011-11-11 23:01:12 -05:00
|
|
|
ptr.get<ESM::NPC>();
|
2012-11-05 16:07:59 +04:00
|
|
|
assert(ref->mBase != NULL);
|
2011-12-25 01:52:57 -05:00
|
|
|
|
2012-11-05 16:07:59 +04:00
|
|
|
std::string headID = ref->mBase->mHead;
|
2011-01-29 17:33:48 +01:00
|
|
|
|
2012-07-24 20:22:11 +04:00
|
|
|
int end = headID.find_last_of("head_") - 4;
|
|
|
|
std::string bodyRaceID = headID.substr(0, end);
|
|
|
|
|
|
|
|
std::string model = "meshes\\base_anim.nif";
|
|
|
|
if (bodyRaceID == "b_n_khajiit_m_" ||
|
|
|
|
bodyRaceID == "b_n_khajiit_f_" ||
|
|
|
|
bodyRaceID == "b_n_argonian_m_" ||
|
|
|
|
bodyRaceID == "b_n_argonian_f_")
|
|
|
|
{
|
|
|
|
model = "meshes\\base_animkna.nif";
|
|
|
|
}
|
|
|
|
return model;
|
2010-08-14 11:27:13 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-08-03 17:11:41 +02:00
|
|
|
std::string Npc::getName (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2012-06-29 18:54:23 +02:00
|
|
|
MWWorld::LiveCellRef<ESM::NPC> *ref =
|
2010-08-03 17:11:41 +02:00
|
|
|
ptr.get<ESM::NPC>();
|
|
|
|
|
2012-11-05 16:07:59 +04:00
|
|
|
return ref->mBase->mName;
|
2010-08-03 17:11:41 +02:00
|
|
|
}
|
|
|
|
|
2010-08-03 13:17:31 +02:00
|
|
|
MWMechanics::CreatureStats& Npc::getCreatureStats (const MWWorld::Ptr& ptr) const
|
2010-08-03 13:03:08 +02:00
|
|
|
{
|
2012-01-26 11:35:47 +01:00
|
|
|
ensureCustomData (ptr);
|
2010-08-03 13:03:08 +02:00
|
|
|
|
2012-01-26 11:35:47 +01:00
|
|
|
return dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mCreatureStats;
|
2010-08-03 13:03:08 +02:00
|
|
|
}
|
|
|
|
|
2010-08-19 12:49:13 +02:00
|
|
|
MWMechanics::NpcStats& Npc::getNpcStats (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2012-01-25 16:56:49 +01:00
|
|
|
ensureCustomData (ptr);
|
2010-08-19 12:49:13 +02:00
|
|
|
|
2012-01-25 16:56:49 +01:00
|
|
|
return dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mNpcStats;
|
2010-08-19 12:49:13 +02:00
|
|
|
}
|
|
|
|
|
2010-08-06 18:15:46 +02:00
|
|
|
boost::shared_ptr<MWWorld::Action> Npc::activate (const MWWorld::Ptr& ptr,
|
2012-04-23 15:27:03 +02:00
|
|
|
const MWWorld::Ptr& actor) const
|
2010-08-06 18:15:46 +02:00
|
|
|
{
|
2012-10-28 16:04:33 +01:00
|
|
|
if (MWWorld::Class::get (ptr).getCreatureStats (ptr).isDead())
|
|
|
|
return boost::shared_ptr<MWWorld::Action> (new MWWorld::ActionOpen(ptr));
|
|
|
|
else
|
|
|
|
return boost::shared_ptr<MWWorld::Action> (new MWWorld::ActionTalk (ptr));
|
2010-08-14 10:02:54 +02:00
|
|
|
}
|
2010-08-07 20:33:07 +02:00
|
|
|
|
2012-01-28 11:45:55 +01:00
|
|
|
MWWorld::ContainerStore& Npc::getContainerStore (const MWWorld::Ptr& ptr)
|
2010-08-06 14:37:53 +02:00
|
|
|
const
|
2010-08-04 14:37:23 +02:00
|
|
|
{
|
2012-01-27 14:55:58 +01:00
|
|
|
ensureCustomData (ptr);
|
2010-08-04 14:37:23 +02:00
|
|
|
|
2012-03-10 12:49:54 +01:00
|
|
|
return dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mInventoryStore;
|
|
|
|
}
|
|
|
|
|
|
|
|
MWWorld::InventoryStore& Npc::getInventoryStore (const MWWorld::Ptr& ptr)
|
|
|
|
const
|
|
|
|
{
|
|
|
|
ensureCustomData (ptr);
|
|
|
|
|
|
|
|
return dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mInventoryStore;
|
2010-08-04 14:37:23 +02:00
|
|
|
}
|
|
|
|
|
2010-08-05 15:40:03 +02:00
|
|
|
std::string Npc::getScript (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2012-06-29 18:54:23 +02:00
|
|
|
MWWorld::LiveCellRef<ESM::NPC> *ref =
|
2010-08-05 15:40:03 +02:00
|
|
|
ptr.get<ESM::NPC>();
|
|
|
|
|
2012-11-05 16:07:59 +04:00
|
|
|
return ref->mBase->mScript;
|
2010-08-05 15:40:03 +02:00
|
|
|
}
|
|
|
|
|
2011-01-18 10:45:29 +01:00
|
|
|
void Npc::setForceStance (const MWWorld::Ptr& ptr, Stance stance, bool force) const
|
|
|
|
{
|
|
|
|
MWMechanics::NpcStats& stats = getNpcStats (ptr);
|
|
|
|
|
|
|
|
switch (stance)
|
|
|
|
{
|
|
|
|
case Run:
|
|
|
|
|
2012-07-06 18:23:48 +02:00
|
|
|
stats.setMovementFlag (MWMechanics::NpcStats::Flag_ForceRun, force);
|
2011-01-18 10:45:29 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Sneak:
|
|
|
|
|
2012-07-06 18:23:48 +02:00
|
|
|
stats.setMovementFlag (MWMechanics::NpcStats::Flag_ForceSneak, force);
|
2011-01-18 10:45:29 +01:00
|
|
|
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:
|
|
|
|
|
2012-07-06 18:23:48 +02:00
|
|
|
stats.setMovementFlag (MWMechanics::NpcStats::Flag_Run, set);
|
2011-02-10 11:08:25 +01:00
|
|
|
break;
|
2011-01-18 10:45:29 +01:00
|
|
|
|
|
|
|
case Sneak:
|
|
|
|
|
2012-07-06 18:23:48 +02:00
|
|
|
stats.setMovementFlag (MWMechanics::NpcStats::Flag_Sneak, set);
|
2011-01-18 10:45:29 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Combat:
|
|
|
|
|
2012-07-06 15:50:26 +02:00
|
|
|
// Combat stance ignored for now; need to be determined based on draw state instead of
|
|
|
|
// being maunally set.
|
2011-01-18 10:45:29 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Npc::getStance (const MWWorld::Ptr& ptr, Stance stance, bool ignoreForce) const
|
|
|
|
{
|
|
|
|
MWMechanics::NpcStats& stats = getNpcStats (ptr);
|
|
|
|
|
|
|
|
switch (stance)
|
|
|
|
{
|
|
|
|
case Run:
|
|
|
|
|
2012-07-06 18:23:48 +02:00
|
|
|
if (!ignoreForce && stats.getMovementFlag (MWMechanics::NpcStats::Flag_ForceRun))
|
2011-02-10 11:08:25 +01:00
|
|
|
return true;
|
|
|
|
|
2012-07-06 18:23:48 +02:00
|
|
|
return stats.getMovementFlag (MWMechanics::NpcStats::Flag_Run);
|
2011-01-18 10:45:29 +01:00
|
|
|
|
|
|
|
case Sneak:
|
|
|
|
|
2012-07-06 18:23:48 +02:00
|
|
|
if (!ignoreForce && stats.getMovementFlag (MWMechanics::NpcStats::Flag_ForceSneak))
|
2011-01-18 10:45:29 +01:00
|
|
|
return true;
|
|
|
|
|
2012-07-06 18:23:48 +02:00
|
|
|
return stats.getMovementFlag (MWMechanics::NpcStats::Flag_Sneak);
|
2011-01-18 10:45:29 +01:00
|
|
|
|
|
|
|
case Combat:
|
|
|
|
|
2012-07-06 15:50:26 +02:00
|
|
|
return false;
|
2011-01-18 10:45:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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 11:37:17 +01:00
|
|
|
MWMechanics::Movement& Npc::getMovementSettings (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2012-01-27 13:17:30 +01:00
|
|
|
ensureCustomData (ptr);
|
2011-02-03 11:37:17 +01:00
|
|
|
|
2012-01-27 13:17:30 +01:00
|
|
|
return dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mMovement;
|
2011-02-03 11:37:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Ogre::Vector3 Npc::getMovementVector (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
Ogre::Vector3 vector (0, 0, 0);
|
|
|
|
|
2012-09-05 17:44:11 -04:00
|
|
|
vector.x = getMovementSettings (ptr).mLeftRight * 127;
|
2012-03-24 22:03:08 -04:00
|
|
|
vector.y = getMovementSettings (ptr).mForwardBackward * 127;
|
2012-09-17 11:37:50 +04:00
|
|
|
vector.z = getMovementSettings(ptr).mUpDown * 127;
|
2011-02-03 11:37:17 +01:00
|
|
|
|
2012-03-27 20:17:54 -04:00
|
|
|
//if (getStance (ptr, Run, false))
|
|
|
|
// vector *= 2;
|
2011-02-03 11:37:17 +01:00
|
|
|
|
|
|
|
return vector;
|
|
|
|
}
|
2012-10-27 13:33:54 +02:00
|
|
|
|
|
|
|
bool Npc::isEssential (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
MWWorld::LiveCellRef<ESM::NPC> *ref =
|
|
|
|
ptr.get<ESM::NPC>();
|
2011-02-03 11:37:17 +01:00
|
|
|
|
2012-11-05 16:07:59 +04:00
|
|
|
return ref->mBase->mFlags & ESM::NPC::Essential;
|
2012-10-27 13:33:54 +02:00
|
|
|
}
|
|
|
|
|
2010-08-03 13:03:08 +02:00
|
|
|
void Npc::registerSelf()
|
|
|
|
{
|
|
|
|
boost::shared_ptr<Class> instance (new Npc);
|
|
|
|
registerClass (typeid (ESM::NPC).name(), instance);
|
|
|
|
}
|
2012-04-16 22:58:16 +02:00
|
|
|
|
|
|
|
bool Npc::hasToolTip (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
/// \todo We don't want tooltips for NPCs in combat mode.
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-04-24 02:02:03 +02:00
|
|
|
MWGui::ToolTipInfo Npc::getToolTipInfo (const MWWorld::Ptr& ptr) const
|
2012-04-16 22:58:16 +02:00
|
|
|
{
|
2012-06-29 18:54:23 +02:00
|
|
|
MWWorld::LiveCellRef<ESM::NPC> *ref =
|
2012-04-16 22:58:16 +02:00
|
|
|
ptr.get<ESM::NPC>();
|
|
|
|
|
|
|
|
MWGui::ToolTipInfo info;
|
2012-11-05 16:07:59 +04:00
|
|
|
info.caption = ref->mBase->mName;
|
2012-04-16 22:58:16 +02:00
|
|
|
|
|
|
|
std::string text;
|
2012-04-24 02:02:03 +02:00
|
|
|
if (MWBase::Environment::get().getWindowManager()->getFullHelp())
|
2012-11-05 16:07:59 +04:00
|
|
|
text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script");
|
2012-04-16 22:58:16 +02:00
|
|
|
info.text = text;
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
2012-05-15 21:17:00 +02:00
|
|
|
|
2012-05-15 22:31:52 +02:00
|
|
|
float Npc::getCapacity (const MWWorld::Ptr& ptr) const
|
2012-05-15 21:17:00 +02:00
|
|
|
{
|
|
|
|
const MWMechanics::CreatureStats& stats = getCreatureStats (ptr);
|
2012-07-22 18:29:54 +04:00
|
|
|
return stats.getAttribute(0).getModified()*5;
|
2012-05-15 21:17:00 +02:00
|
|
|
}
|
2012-05-15 21:34:00 +02:00
|
|
|
|
|
|
|
float Npc::getEncumbrance (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
float weight = getContainerStore (ptr).getWeight();
|
|
|
|
|
|
|
|
const MWMechanics::CreatureStats& stats = getCreatureStats (ptr);
|
|
|
|
|
2012-07-22 18:29:54 +04:00
|
|
|
weight -= stats.getMagicEffects().get (MWMechanics::EffectKey (8)).mMagnitude; // feather
|
2012-05-15 21:34:00 +02:00
|
|
|
|
2012-07-22 18:29:54 +04:00
|
|
|
weight += stats.getMagicEffects().get (MWMechanics::EffectKey (7)).mMagnitude; // burden
|
2012-05-15 21:34:00 +02:00
|
|
|
|
|
|
|
if (weight<0)
|
|
|
|
weight = 0;
|
|
|
|
|
|
|
|
return weight;
|
|
|
|
}
|
2012-07-13 09:16:27 +02:00
|
|
|
|
|
|
|
bool Npc::apply (const MWWorld::Ptr& ptr, const std::string& id,
|
|
|
|
const MWWorld::Ptr& actor) const
|
|
|
|
{
|
|
|
|
MWMechanics::CreatureStats& stats = getCreatureStats (ptr);
|
|
|
|
|
|
|
|
/// \todo consider instant effects
|
|
|
|
|
2012-09-13 11:30:59 +02:00
|
|
|
return stats.getActiveSpells().addSpell (id, actor);
|
2012-07-13 09:16:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Npc::skillUsageSucceeded (const MWWorld::Ptr& ptr, int skill, int usageType) const
|
|
|
|
{
|
|
|
|
MWMechanics::NpcStats& stats = getNpcStats (ptr);
|
|
|
|
|
|
|
|
MWWorld::LiveCellRef<ESM::NPC> *ref = ptr.get<ESM::NPC>();
|
|
|
|
|
2012-11-05 18:39:42 +04:00
|
|
|
const ESM::Class *class_ =
|
|
|
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::Class>().find (
|
|
|
|
ref->mBase->mClass
|
|
|
|
);
|
2012-07-13 09:16:27 +02:00
|
|
|
|
|
|
|
stats.useSkill (skill, *class_, usageType);
|
|
|
|
}
|
2012-07-17 10:32:18 +02:00
|
|
|
|
2012-07-10 11:15:46 +02:00
|
|
|
void Npc::adjustRotation(const MWWorld::Ptr& ptr,float& x,float& y,float& z) const
|
|
|
|
{
|
|
|
|
y = 0;
|
|
|
|
x = 0;
|
|
|
|
}
|
2012-07-25 17:18:17 +04:00
|
|
|
|
|
|
|
MWWorld::Ptr
|
2012-07-26 16:14:11 +04:00
|
|
|
Npc::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
|
2012-07-25 17:18:17 +04:00
|
|
|
{
|
|
|
|
MWWorld::LiveCellRef<ESM::NPC> *ref =
|
|
|
|
ptr.get<ESM::NPC>();
|
|
|
|
|
2012-11-05 16:07:59 +04:00
|
|
|
return MWWorld::Ptr(&cell.mNpcs.insert(*ref), &cell);
|
2012-07-25 17:18:17 +04:00
|
|
|
}
|
2010-08-03 13:03:08 +02:00
|
|
|
}
|