2010-08-03 11:03:08 +00:00
|
|
|
|
|
|
|
#include "npc.hpp"
|
|
|
|
|
2012-01-25 15:56:49 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2012-05-21 01:10:55 +00:00
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
|
2012-01-27 12:17:30 +00:00
|
|
|
#include <OgreSceneNode.h>
|
|
|
|
|
2010-08-03 11:03:08 +00:00
|
|
|
#include <components/esm/loadnpc.hpp>
|
|
|
|
|
2012-07-03 10:30:50 +00:00
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
#include "../mwbase/world.hpp"
|
2012-08-11 15:30:55 +00:00
|
|
|
#include "../mwbase/mechanicsmanager.hpp"
|
2012-08-12 16:11:09 +00:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
2012-07-03 10:30:50 +00:00
|
|
|
|
2010-08-03 11:32:37 +00:00
|
|
|
#include "../mwmechanics/creaturestats.hpp"
|
2010-08-19 10:49:13 +00:00
|
|
|
#include "../mwmechanics/npcstats.hpp"
|
2012-01-27 13:55:58 +00:00
|
|
|
#include "../mwmechanics/movement.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"
|
2012-10-28 15:04:33 +00:00
|
|
|
#include "../mwworld/actionopen.hpp"
|
2012-03-10 11:49:54 +00:00
|
|
|
#include "../mwworld/inventorystore.hpp"
|
2012-01-27 14:11:02 +00:00
|
|
|
#include "../mwworld/customdata.hpp"
|
2012-07-03 11:15:20 +00:00
|
|
|
#include "../mwworld/physicssystem.hpp"
|
2010-08-03 11:03:08 +00:00
|
|
|
|
2012-07-03 10:30:50 +00:00
|
|
|
#include "../mwrender/actors.hpp"
|
2012-07-03 11:15:20 +00:00
|
|
|
#include "../mwrender/renderinginterface.hpp"
|
2012-04-16 20:58:16 +00:00
|
|
|
|
2012-07-03 11:15:20 +00:00
|
|
|
#include "../mwgui/tooltips.hpp"
|
2012-04-23 13:27:03 +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));
|
2012-01-25 15:56:49 +00:00
|
|
|
|
|
|
|
struct CustomData : public MWWorld::CustomData
|
|
|
|
{
|
|
|
|
MWMechanics::NpcStats mNpcStats;
|
2012-01-26 10:35:47 +00:00
|
|
|
MWMechanics::CreatureStats mCreatureStats;
|
2012-01-27 12:17:30 +00:00
|
|
|
MWMechanics::Movement mMovement;
|
2012-03-10 11:49:54 +00:00
|
|
|
MWWorld::InventoryStore mInventoryStore;
|
2012-01-25 15:56:49 +00:00
|
|
|
|
|
|
|
virtual MWWorld::CustomData *clone() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
MWWorld::CustomData *CustomData::clone() const
|
|
|
|
{
|
|
|
|
return new CustomData (*this);
|
|
|
|
}
|
2011-01-10 23:13:32 +00:00
|
|
|
}
|
|
|
|
|
2010-08-03 11:17:31 +00:00
|
|
|
namespace MWClass
|
2010-08-03 11:03:08 +00:00
|
|
|
{
|
2012-01-25 15:56:49 +00:00
|
|
|
void Npc::ensureCustomData (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
if (!ptr.getRefData().getCustomData())
|
|
|
|
{
|
|
|
|
std::auto_ptr<CustomData> data (new CustomData);
|
|
|
|
|
2012-06-29 16:54:23 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::NPC> *ref = ptr.get<ESM::NPC>();
|
2012-01-25 15:56:49 +00:00
|
|
|
|
2012-01-26 10:35:47 +00:00
|
|
|
// NPC stats
|
2012-11-05 12:07:59 +00:00
|
|
|
if (!ref->mBase->mFaction.empty())
|
2012-01-25 15:56:49 +00:00
|
|
|
{
|
2012-11-05 12:07:59 +00:00
|
|
|
std::string faction = ref->mBase->mFaction;
|
2013-01-09 19:51:52 +00:00
|
|
|
Misc::StringUtils::toLower(faction);
|
2012-11-05 12:07:59 +00:00
|
|
|
if(ref->mBase->mNpdt52.mGold != -10)
|
2012-04-03 15:30:19 +00:00
|
|
|
{
|
2012-11-05 12:07:59 +00:00
|
|
|
data->mNpcStats.getFactionRanks()[faction] = (int)ref->mBase->mNpdt52.mRank;
|
2012-04-03 15:30:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-05 12:07:59 +00:00
|
|
|
data->mNpcStats.getFactionRanks()[faction] = (int)ref->mBase->mNpdt12.mRank;
|
2012-04-03 15:30:19 +00:00
|
|
|
}
|
2012-01-25 15:56:49 +00:00
|
|
|
}
|
|
|
|
|
2012-06-16 14:17:42 +00:00
|
|
|
// creature stats
|
2012-11-05 12:07:59 +00:00
|
|
|
if(ref->mBase->mNpdt52.mGold != -10)
|
2012-04-12 15:08:57 +00:00
|
|
|
{
|
|
|
|
for (int i=0; i<27; ++i)
|
2012-11-05 12:07:59 +00: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-09 19:18:38 +00:00
|
|
|
data->mNpcStats.setBaseDisposition(ref->mBase->mNpdt52.mDisposition);
|
2012-11-09 23:29:36 +00:00
|
|
|
data->mNpcStats.setReputation(ref->mBase->mNpdt52.mReputation);
|
2012-04-12 15:08:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-23 11:54:36 +00: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);
|
|
|
|
|
2013-01-19 01:43:55 +00:00
|
|
|
data->mCreatureStats.setLevel(ref->mBase->mNpdt12.mLevel);
|
|
|
|
data->mNpcStats.setBaseDisposition(ref->mBase->mNpdt12.mDisposition);
|
|
|
|
data->mNpcStats.setReputation(ref->mBase->mNpdt12.mReputation);
|
2012-04-12 15:08:57 +00:00
|
|
|
}
|
2012-01-26 10:35:47 +00:00
|
|
|
|
2012-11-10 10:38:37 +00: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 14:17:42 +00:00
|
|
|
|
2012-09-10 11:04:00 +00:00
|
|
|
// spells
|
2012-11-05 12:07:59 +00:00
|
|
|
for (std::vector<std::string>::const_iterator iter (ref->mBase->mSpells.mList.begin());
|
|
|
|
iter!=ref->mBase->mSpells.mList.end(); ++iter)
|
2012-09-10 11:04:00 +00:00
|
|
|
data->mCreatureStats.getSpells().add (*iter);
|
|
|
|
|
2012-01-26 10:35:47 +00:00
|
|
|
// store
|
2012-01-25 15:56:49 +00:00
|
|
|
ptr.getRefData().setCustomData (data.release());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-08 12:28:35 +00:00
|
|
|
std::string Npc::getId (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2012-06-29 16:54:23 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::NPC> *ref =
|
2010-08-08 12:28:35 +00:00
|
|
|
ptr.get<ESM::NPC>();
|
|
|
|
|
2012-11-05 12:07:59 +00:00
|
|
|
return ref->mBase->mId;
|
2010-08-08 12:28:35 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2012-04-08 02:02:20 +00:00
|
|
|
renderingInterface.getActors().insertNPC(ptr, getInventoryStore(ptr));
|
2011-11-12 04:01:12 +00:00
|
|
|
}
|
2010-12-22 02:45:54 +00:00
|
|
|
|
2012-04-23 13:27:03 +00:00
|
|
|
void Npc::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
|
2011-11-12 04:01:12 +00:00
|
|
|
{
|
2012-11-05 18:40:02 +00:00
|
|
|
physics.addActor(ptr);
|
2012-07-24 16:22:11 +00:00
|
|
|
MWBase::Environment::get().getMechanicsManager()->addActor(ptr);
|
|
|
|
}
|
2011-11-17 22:10:27 +00:00
|
|
|
|
2012-07-24 16:22:11 +00:00
|
|
|
std::string Npc::getModel(const MWWorld::Ptr &ptr) const
|
|
|
|
{
|
2012-06-29 16:54:23 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::NPC> *ref =
|
2011-11-12 04:01:12 +00:00
|
|
|
ptr.get<ESM::NPC>();
|
2012-11-05 12:07:59 +00:00
|
|
|
assert(ref->mBase != NULL);
|
2011-12-25 06:52:57 +00:00
|
|
|
|
2012-11-05 12:07:59 +00:00
|
|
|
std::string headID = ref->mBase->mHead;
|
2011-01-29 16:33:48 +00:00
|
|
|
|
2012-07-24 16:22:11 +00: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 09:27:13 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-08-03 15:11:41 +00:00
|
|
|
std::string Npc::getName (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2012-06-29 16:54:23 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::NPC> *ref =
|
2010-08-03 15:11:41 +00:00
|
|
|
ptr.get<ESM::NPC>();
|
|
|
|
|
2012-11-05 12:07:59 +00:00
|
|
|
return ref->mBase->mName;
|
2010-08-03 15:11:41 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2012-01-26 10:35:47 +00:00
|
|
|
ensureCustomData (ptr);
|
2010-08-03 11:03:08 +00:00
|
|
|
|
2012-01-26 10:35:47 +00:00
|
|
|
return dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mCreatureStats;
|
2010-08-03 11:03:08 +00:00
|
|
|
}
|
|
|
|
|
2010-08-19 10:49:13 +00:00
|
|
|
MWMechanics::NpcStats& Npc::getNpcStats (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2012-01-25 15:56:49 +00:00
|
|
|
ensureCustomData (ptr);
|
2010-08-19 10:49:13 +00:00
|
|
|
|
2012-01-25 15:56:49 +00:00
|
|
|
return dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mNpcStats;
|
2010-08-19 10:49:13 +00:00
|
|
|
}
|
|
|
|
|
2010-08-06 16:15:46 +00:00
|
|
|
boost::shared_ptr<MWWorld::Action> Npc::activate (const MWWorld::Ptr& ptr,
|
2012-04-23 13:27:03 +00:00
|
|
|
const MWWorld::Ptr& actor) const
|
2010-08-06 16:15:46 +00:00
|
|
|
{
|
2012-10-28 15:04:33 +00: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 08:02:54 +00:00
|
|
|
}
|
2010-08-07 18:33:07 +00:00
|
|
|
|
2012-01-28 10:45:55 +00:00
|
|
|
MWWorld::ContainerStore& Npc::getContainerStore (const MWWorld::Ptr& ptr)
|
2010-08-06 12:37:53 +00:00
|
|
|
const
|
2010-08-04 12:37:23 +00:00
|
|
|
{
|
2012-01-27 13:55:58 +00:00
|
|
|
ensureCustomData (ptr);
|
2010-08-04 12:37:23 +00:00
|
|
|
|
2012-03-10 11:49:54 +00: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 12:37:23 +00:00
|
|
|
}
|
|
|
|
|
2010-08-05 13:40:03 +00:00
|
|
|
std::string Npc::getScript (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2012-06-29 16:54:23 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::NPC> *ref =
|
2010-08-05 13:40:03 +00:00
|
|
|
ptr.get<ESM::NPC>();
|
|
|
|
|
2012-11-05 12:07:59 +00:00
|
|
|
return ref->mBase->mScript;
|
2010-08-05 13:40:03 +00:00
|
|
|
}
|
|
|
|
|
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:
|
|
|
|
|
2012-07-06 16:23:48 +00:00
|
|
|
stats.setMovementFlag (MWMechanics::NpcStats::Flag_ForceRun, force);
|
2011-01-18 09:45:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Sneak:
|
|
|
|
|
2012-07-06 16:23:48 +00:00
|
|
|
stats.setMovementFlag (MWMechanics::NpcStats::Flag_ForceSneak, force);
|
2011-01-18 09:45:29 +00: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 16:23:48 +00:00
|
|
|
stats.setMovementFlag (MWMechanics::NpcStats::Flag_Run, set);
|
2011-02-10 10:08:25 +00:00
|
|
|
break;
|
2011-01-18 09:45:29 +00:00
|
|
|
|
|
|
|
case Sneak:
|
|
|
|
|
2012-07-06 16:23:48 +00:00
|
|
|
stats.setMovementFlag (MWMechanics::NpcStats::Flag_Sneak, set);
|
2011-01-18 09:45:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Combat:
|
|
|
|
|
2012-07-06 13:50:26 +00:00
|
|
|
// Combat stance ignored for now; need to be determined based on draw state instead of
|
|
|
|
// being maunally set.
|
2011-01-18 09:45:29 +00: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 16:23:48 +00:00
|
|
|
if (!ignoreForce && stats.getMovementFlag (MWMechanics::NpcStats::Flag_ForceRun))
|
2011-02-10 10:08:25 +00:00
|
|
|
return true;
|
|
|
|
|
2012-07-06 16:23:48 +00:00
|
|
|
return stats.getMovementFlag (MWMechanics::NpcStats::Flag_Run);
|
2011-01-18 09:45:29 +00:00
|
|
|
|
|
|
|
case Sneak:
|
|
|
|
|
2012-07-06 16:23:48 +00:00
|
|
|
if (!ignoreForce && stats.getMovementFlag (MWMechanics::NpcStats::Flag_ForceSneak))
|
2011-01-18 09:45:29 +00:00
|
|
|
return true;
|
|
|
|
|
2012-07-06 16:23:48 +00:00
|
|
|
return stats.getMovementFlag (MWMechanics::NpcStats::Flag_Sneak);
|
2011-01-18 09:45:29 +00:00
|
|
|
|
|
|
|
case Combat:
|
|
|
|
|
2012-07-06 13:50:26 +00:00
|
|
|
return false;
|
2011-01-18 09:45:29 +00: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 10:37:17 +00:00
|
|
|
MWMechanics::Movement& Npc::getMovementSettings (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2012-01-27 12:17:30 +00:00
|
|
|
ensureCustomData (ptr);
|
2011-02-03 10:37:17 +00:00
|
|
|
|
2012-01-27 12:17:30 +00:00
|
|
|
return dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mMovement;
|
2011-02-03 10:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Ogre::Vector3 Npc::getMovementVector (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
Ogre::Vector3 vector (0, 0, 0);
|
|
|
|
|
2012-09-05 21:44:11 +00:00
|
|
|
vector.x = getMovementSettings (ptr).mLeftRight * 127;
|
2012-03-25 02:03:08 +00:00
|
|
|
vector.y = getMovementSettings (ptr).mForwardBackward * 127;
|
2012-09-17 07:37:50 +00:00
|
|
|
vector.z = getMovementSettings(ptr).mUpDown * 127;
|
2011-02-03 10:37:17 +00:00
|
|
|
|
2012-03-28 00:17:54 +00:00
|
|
|
//if (getStance (ptr, Run, false))
|
|
|
|
// vector *= 2;
|
2011-02-03 10:37:17 +00:00
|
|
|
|
|
|
|
return vector;
|
|
|
|
}
|
2012-10-27 11:33:54 +00:00
|
|
|
|
|
|
|
bool Npc::isEssential (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
MWWorld::LiveCellRef<ESM::NPC> *ref =
|
|
|
|
ptr.get<ESM::NPC>();
|
2011-02-03 10:37:17 +00:00
|
|
|
|
2012-11-05 12:07:59 +00:00
|
|
|
return ref->mBase->mFlags & ESM::NPC::Essential;
|
2012-10-27 11:33:54 +00:00
|
|
|
}
|
|
|
|
|
2010-08-03 11:03:08 +00:00
|
|
|
void Npc::registerSelf()
|
|
|
|
{
|
|
|
|
boost::shared_ptr<Class> instance (new Npc);
|
|
|
|
registerClass (typeid (ESM::NPC).name(), instance);
|
|
|
|
}
|
2012-04-16 20:58:16 +00: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 00:02:03 +00:00
|
|
|
MWGui::ToolTipInfo Npc::getToolTipInfo (const MWWorld::Ptr& ptr) const
|
2012-04-16 20:58:16 +00:00
|
|
|
{
|
2012-06-29 16:54:23 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::NPC> *ref =
|
2012-04-16 20:58:16 +00:00
|
|
|
ptr.get<ESM::NPC>();
|
|
|
|
|
|
|
|
MWGui::ToolTipInfo info;
|
2012-11-05 12:07:59 +00:00
|
|
|
info.caption = ref->mBase->mName;
|
2012-04-16 20:58:16 +00:00
|
|
|
|
|
|
|
std::string text;
|
2012-04-24 00:02:03 +00:00
|
|
|
if (MWBase::Environment::get().getWindowManager()->getFullHelp())
|
2012-11-05 12:07:59 +00:00
|
|
|
text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script");
|
2012-04-16 20:58:16 +00:00
|
|
|
info.text = text;
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
2012-05-15 19:17:00 +00:00
|
|
|
|
2012-05-15 20:31:52 +00:00
|
|
|
float Npc::getCapacity (const MWWorld::Ptr& ptr) const
|
2012-05-15 19:17:00 +00:00
|
|
|
{
|
|
|
|
const MWMechanics::CreatureStats& stats = getCreatureStats (ptr);
|
2012-07-22 14:29:54 +00:00
|
|
|
return stats.getAttribute(0).getModified()*5;
|
2012-05-15 19:17:00 +00:00
|
|
|
}
|
2012-05-15 19:34:00 +00:00
|
|
|
|
|
|
|
float Npc::getEncumbrance (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
float weight = getContainerStore (ptr).getWeight();
|
|
|
|
|
|
|
|
const MWMechanics::CreatureStats& stats = getCreatureStats (ptr);
|
|
|
|
|
2012-07-22 14:29:54 +00:00
|
|
|
weight -= stats.getMagicEffects().get (MWMechanics::EffectKey (8)).mMagnitude; // feather
|
2012-05-15 19:34:00 +00:00
|
|
|
|
2012-07-22 14:29:54 +00:00
|
|
|
weight += stats.getMagicEffects().get (MWMechanics::EffectKey (7)).mMagnitude; // burden
|
2012-05-15 19:34:00 +00:00
|
|
|
|
|
|
|
if (weight<0)
|
|
|
|
weight = 0;
|
|
|
|
|
|
|
|
return weight;
|
|
|
|
}
|
2012-07-13 07:16:27 +00: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 09:30:59 +00:00
|
|
|
return stats.getActiveSpells().addSpell (id, actor);
|
2012-07-13 07:16:27 +00: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 14:39:42 +00:00
|
|
|
const ESM::Class *class_ =
|
|
|
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::Class>().find (
|
|
|
|
ref->mBase->mClass
|
|
|
|
);
|
2012-07-13 07:16:27 +00:00
|
|
|
|
|
|
|
stats.useSkill (skill, *class_, usageType);
|
|
|
|
}
|
2012-07-17 08:32:18 +00:00
|
|
|
|
2012-07-10 09:15:46 +00:00
|
|
|
void Npc::adjustRotation(const MWWorld::Ptr& ptr,float& x,float& y,float& z) const
|
|
|
|
{
|
|
|
|
y = 0;
|
|
|
|
x = 0;
|
|
|
|
}
|
2012-07-25 13:18:17 +00:00
|
|
|
|
|
|
|
MWWorld::Ptr
|
2012-07-26 12:14:11 +00:00
|
|
|
Npc::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
|
2012-07-25 13:18:17 +00:00
|
|
|
{
|
|
|
|
MWWorld::LiveCellRef<ESM::NPC> *ref =
|
|
|
|
ptr.get<ESM::NPC>();
|
|
|
|
|
2012-11-05 12:07:59 +00:00
|
|
|
return MWWorld::Ptr(&cell.mNpcs.insert(*ref), &cell);
|
2012-07-25 13:18:17 +00:00
|
|
|
}
|
2010-08-03 11:03:08 +00:00
|
|
|
}
|