1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 16:49:55 +00:00
openmw-tes3mp/apps/openmw/mwclass/creature.cpp

237 lines
7.5 KiB
C++
Raw Normal View History

2010-08-03 11:03:08 +00:00
#include "creature.hpp"
#include <components/esm/loadcrea.hpp>
#include "../mwmechanics/creaturestats.hpp"
2012-05-15 19:34:00 +00:00
#include "../mwmechanics/magiceffects.hpp"
2010-08-03 11:03:08 +00:00
#include "../mwbase/environment.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwbase/windowmanager.hpp"
#include "../mwbase/world.hpp"
#include "../mwworld/ptr.hpp"
#include "../mwworld/actiontalk.hpp"
2012-10-28 15:04:33 +00:00
#include "../mwworld/actionopen.hpp"
#include "../mwworld/customdata.hpp"
#include "../mwworld/containerstore.hpp"
#include "../mwworld/physicssystem.hpp"
#include "../mwrender/renderinginterface.hpp"
#include "../mwrender/actors.hpp"
2010-08-03 11:03:08 +00:00
#include "../mwgui/tooltips.hpp"
namespace
{
struct CustomData : public MWWorld::CustomData
{
MWMechanics::CreatureStats mCreatureStats;
MWWorld::ContainerStore mContainerStore;
virtual MWWorld::CustomData *clone() const;
};
MWWorld::CustomData *CustomData::clone() const
{
return new CustomData (*this);
}
}
namespace MWClass
2010-08-03 11:03:08 +00:00
{
void Creature::ensureCustomData (const MWWorld::Ptr& ptr) const
{
if (!ptr.getRefData().getCustomData())
{
std::auto_ptr<CustomData> data (new CustomData);
MWWorld::LiveCellRef<ESM::Creature> *ref = ptr.get<ESM::Creature>();
// creature stats
2012-11-05 12:07:59 +00:00
data->mCreatureStats.getAttribute(0).set (ref->mBase->mData.mStrength);
data->mCreatureStats.getAttribute(1).set (ref->mBase->mData.mIntelligence);
data->mCreatureStats.getAttribute(2).set (ref->mBase->mData.mWillpower);
data->mCreatureStats.getAttribute(3).set (ref->mBase->mData.mAgility);
data->mCreatureStats.getAttribute(4).set (ref->mBase->mData.mSpeed);
data->mCreatureStats.getAttribute(5).set (ref->mBase->mData.mEndurance);
data->mCreatureStats.getAttribute(6).set (ref->mBase->mData.mPersonality);
data->mCreatureStats.getAttribute(7).set (ref->mBase->mData.mLuck);
data->mCreatureStats.setHealth (ref->mBase->mData.mHealth);
data->mCreatureStats.setMagicka (ref->mBase->mData.mMana);
data->mCreatureStats.setFatigue (ref->mBase->mData.mFatigue);
data->mCreatureStats.setLevel(ref->mBase->mData.mLevel);
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);
// 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)
data->mCreatureStats.getSpells().add (*iter);
// store
ptr.getRefData().setCustomData (data.release());
}
}
2010-08-08 12:28:35 +00:00
std::string Creature::getId (const MWWorld::Ptr& ptr) const
{
MWWorld::LiveCellRef<ESM::Creature> *ref =
2010-08-08 12:28:35 +00:00
ptr.get<ESM::Creature>();
2012-11-05 12:07:59 +00:00
return ref->mBase->mId;
2010-08-08 12:28:35 +00:00
}
void Creature::adjustPosition(const MWWorld::Ptr& ptr) const
{
MWBase::Environment::get().getWorld()->adjustPosition(ptr);
}
2011-11-12 04:01:12 +00:00
void Creature::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
{
MWRender::Actors& actors = renderingInterface.getActors();
actors.insertCreature(ptr);
}
void Creature::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
2012-07-24 16:22:11 +00:00
{
const std::string model = getModel(ptr);
if(!model.empty())
physics.addActor(ptr);
MWBase::Environment::get().getMechanicsManager()->add(ptr);
2012-07-24 16:22:11 +00:00
}
std::string Creature::getModel(const MWWorld::Ptr &ptr) const
2011-11-12 04:01:12 +00:00
{
MWWorld::LiveCellRef<ESM::Creature> *ref =
2011-11-12 04:01:12 +00:00
ptr.get<ESM::Creature>();
2012-11-05 12:07:59 +00:00
assert (ref->mBase != NULL);
2011-11-12 04:01:12 +00:00
2012-11-05 12:07:59 +00:00
const std::string &model = ref->mBase->mModel;
2012-07-24 16:22:11 +00:00
if (!model.empty()) {
return "meshes\\" + model;
2011-11-25 04:13:34 +00:00
}
return "";
}
2010-08-03 15:11:41 +00:00
std::string Creature::getName (const MWWorld::Ptr& ptr) const
{
MWWorld::LiveCellRef<ESM::Creature> *ref =
2010-08-03 15:11:41 +00:00
ptr.get<ESM::Creature>();
2012-11-05 12:07:59 +00:00
return ref->mBase->mName;
2010-08-03 15:11:41 +00:00
}
MWMechanics::CreatureStats& Creature::getCreatureStats (const MWWorld::Ptr& ptr) const
2010-08-03 11:03:08 +00:00
{
ensureCustomData (ptr);
2010-08-03 11:03:08 +00:00
return dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mCreatureStats;
2010-08-03 11:03:08 +00:00
}
boost::shared_ptr<MWWorld::Action> Creature::activate (const MWWorld::Ptr& ptr,
const MWWorld::Ptr& actor) const
{
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, true));
2012-10-28 15:04:33 +00:00
else
return boost::shared_ptr<MWWorld::Action> (new MWWorld::ActionTalk (ptr));
2011-01-05 21:18:21 +00:00
}
MWWorld::ContainerStore& Creature::getContainerStore (const MWWorld::Ptr& ptr)
2010-08-04 12:37:23 +00:00
const
{
ensureCustomData (ptr);
2010-08-04 12:37:23 +00:00
return dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mContainerStore;
2011-01-05 21:18:21 +00:00
}
std::string Creature::getScript (const MWWorld::Ptr& ptr) const
{
MWWorld::LiveCellRef<ESM::Creature> *ref =
ptr.get<ESM::Creature>();
2012-11-05 12:07:59 +00:00
return ref->mBase->mScript;
}
2012-10-27 11:33:54 +00:00
bool Creature::isEssential (const MWWorld::Ptr& ptr) const
{
MWWorld::LiveCellRef<ESM::Creature> *ref =
ptr.get<ESM::Creature>();
2012-11-05 12:07:59 +00:00
return ref->mBase->mFlags & ESM::Creature::Essential;
2012-10-27 11:33:54 +00:00
}
2010-08-03 11:03:08 +00:00
void Creature::registerSelf()
{
boost::shared_ptr<Class> instance (new Creature);
registerClass (typeid (ESM::Creature).name(), instance);
}
bool Creature::hasToolTip (const MWWorld::Ptr& ptr) const
{
/// \todo We don't want tooltips for Creatures in combat mode.
return true;
}
MWGui::ToolTipInfo Creature::getToolTipInfo (const MWWorld::Ptr& ptr) const
{
MWWorld::LiveCellRef<ESM::Creature> *ref =
ptr.get<ESM::Creature>();
MWGui::ToolTipInfo info;
2012-11-05 12:07:59 +00:00
info.caption = ref->mBase->mName;
std::string text;
if (MWBase::Environment::get().getWindowManager()->getFullHelp())
2012-11-05 12:07:59 +00:00
text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script");
info.text = text;
return info;
}
2012-05-15 19:17:00 +00:00
2013-03-17 21:29:12 +00:00
float Creature::getArmorRating (const MWWorld::Ptr& ptr) const
{
/// \todo add Shield magic effect magnitude here, controlled by a GMST (Vanilla vs MCP behaviour)
return 0.f;
}
2012-05-15 20:31:52 +00:00
float Creature::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 Creature::getEncumbrance (const MWWorld::Ptr& ptr) const
{
float weight = getContainerStore (ptr).getWeight();
const MWMechanics::CreatureStats& stats = getCreatureStats (ptr);
weight -= stats.getMagicEffects().get (MWMechanics::EffectKey (ESM::MagicEffect::Feather)).mMagnitude;
2012-05-15 19:34:00 +00:00
weight += stats.getMagicEffects().get (MWMechanics::EffectKey (ESM::MagicEffect::Burden)).mMagnitude;
2012-05-15 19:34:00 +00:00
if (weight<0)
weight = 0;
return weight;
}
MWWorld::Ptr
Creature::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
{
MWWorld::LiveCellRef<ESM::Creature> *ref =
ptr.get<ESM::Creature>();
2012-11-05 12:07:59 +00:00
return MWWorld::Ptr(&cell.mCreatures.insert(*ref), &cell);
}
2010-08-03 11:03:08 +00:00
}