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
|
|
|
|
2012-04-23 13:27:03 +00:00
|
|
|
#include "../mwbase/environment.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-04-23 13:27:03 +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-01-26 10:35:47 +00:00
|
|
|
#include "../mwworld/customdata.hpp"
|
2012-01-27 13:55:58 +00:00
|
|
|
#include "../mwworld/containerstore.hpp"
|
2012-07-03 11:15:20 +00:00
|
|
|
#include "../mwworld/physicssystem.hpp"
|
|
|
|
|
|
|
|
#include "../mwrender/renderinginterface.hpp"
|
2010-08-03 11:03:08 +00:00
|
|
|
|
2012-07-03 11:15:20 +00:00
|
|
|
#include "../mwgui/tooltips.hpp"
|
2012-04-16 20:58:16 +00:00
|
|
|
|
2012-01-26 10:35:47 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
struct CustomData : public MWWorld::CustomData
|
|
|
|
{
|
|
|
|
MWMechanics::CreatureStats mCreatureStats;
|
2012-01-28 10:45:55 +00:00
|
|
|
MWWorld::ContainerStore mContainerStore;
|
2012-01-26 10:35:47 +00:00
|
|
|
|
|
|
|
virtual MWWorld::CustomData *clone() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
MWWorld::CustomData *CustomData::clone() const
|
|
|
|
{
|
|
|
|
return new CustomData (*this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-03 11:17:31 +00:00
|
|
|
namespace MWClass
|
2010-08-03 11:03:08 +00:00
|
|
|
{
|
2012-01-26 10:35:47 +00:00
|
|
|
void Creature::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::Creature> *ref = ptr.get<ESM::Creature>();
|
2012-01-26 10:35:47 +00:00
|
|
|
|
|
|
|
// creature stats
|
2012-07-22 14:29:54 +00:00
|
|
|
data->mCreatureStats.getAttribute(0).set (ref->base->data.strength);
|
|
|
|
data->mCreatureStats.getAttribute(1).set (ref->base->data.intelligence);
|
|
|
|
data->mCreatureStats.getAttribute(2).set (ref->base->data.willpower);
|
|
|
|
data->mCreatureStats.getAttribute(3).set (ref->base->data.agility);
|
|
|
|
data->mCreatureStats.getAttribute(4).set (ref->base->data.speed);
|
|
|
|
data->mCreatureStats.getAttribute(5).set (ref->base->data.endurance);
|
|
|
|
data->mCreatureStats.getAttribute(6).set (ref->base->data.personality);
|
|
|
|
data->mCreatureStats.getAttribute(7).set (ref->base->data.luck);
|
|
|
|
data->mCreatureStats.getHealth().set (ref->base->data.health);
|
|
|
|
data->mCreatureStats.getMagicka().set (ref->base->data.mana);
|
|
|
|
data->mCreatureStats.getFatigue().set (ref->base->data.fatigue);
|
|
|
|
|
|
|
|
data->mCreatureStats.setLevel(ref->base->data.level);
|
|
|
|
|
2012-08-29 17:35:06 +00:00
|
|
|
data->mCreatureStats.setHello(ref->base->mAiData.mHello);
|
|
|
|
data->mCreatureStats.setFight(ref->base->mAiData.mFight);
|
|
|
|
data->mCreatureStats.setFlee(ref->base->mAiData.mFlee);
|
|
|
|
data->mCreatureStats.setAlarm(ref->base->mAiData.mAlarm);
|
2012-09-10 11:04:00 +00:00
|
|
|
|
|
|
|
// spells
|
|
|
|
for (std::vector<std::string>::const_iterator iter (ref->base->mSpells.list.begin());
|
|
|
|
iter!=ref->base->mSpells.list.end(); ++iter)
|
|
|
|
data->mCreatureStats.getSpells().add (*iter);
|
2012-06-16 14:17:42 +00:00
|
|
|
|
2012-01-26 10:35:47 +00:00
|
|
|
// store
|
|
|
|
ptr.getRefData().setCustomData (data.release());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-08 12:28:35 +00:00
|
|
|
std::string Creature::getId (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2012-06-29 16:54:23 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::Creature> *ref =
|
2010-08-08 12:28:35 +00:00
|
|
|
ptr.get<ESM::Creature>();
|
|
|
|
|
|
|
|
return ref->base->mId;
|
|
|
|
}
|
|
|
|
|
2011-11-12 04:01:12 +00:00
|
|
|
void Creature::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
|
2010-08-14 08:02:54 +00:00
|
|
|
{
|
2012-01-27 13:55:58 +00:00
|
|
|
MWRender::Actors& actors = renderingInterface.getActors();
|
|
|
|
actors.insertCreature(ptr);
|
2010-08-14 08:02:54 +00:00
|
|
|
}
|
|
|
|
|
2012-04-23 13:27:03 +00:00
|
|
|
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.insertActorPhysics(ptr, model);
|
|
|
|
}
|
|
|
|
MWBase::Environment::get().getMechanicsManager()->addActor (ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Creature::getModel(const MWWorld::Ptr &ptr) const
|
2011-11-12 04:01:12 +00:00
|
|
|
{
|
2012-06-29 16:54:23 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::Creature> *ref =
|
2011-11-12 04:01:12 +00:00
|
|
|
ptr.get<ESM::Creature>();
|
2012-07-24 16:22:11 +00:00
|
|
|
assert (ref->base != NULL);
|
2011-11-12 04:01:12 +00:00
|
|
|
|
|
|
|
const std::string &model = ref->base->model;
|
2012-07-24 16:22:11 +00:00
|
|
|
if (!model.empty()) {
|
|
|
|
return "meshes\\" + model;
|
2011-11-25 04:13:34 +00:00
|
|
|
}
|
2012-08-11 15:30:55 +00:00
|
|
|
return "";
|
2010-08-14 09:27:13 +00:00
|
|
|
}
|
|
|
|
|
2010-08-03 15:11:41 +00:00
|
|
|
std::string Creature::getName (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2012-06-29 16:54:23 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::Creature> *ref =
|
2010-08-03 15:11:41 +00:00
|
|
|
ptr.get<ESM::Creature>();
|
|
|
|
|
|
|
|
return ref->base->name;
|
|
|
|
}
|
|
|
|
|
2010-08-03 11:17:31 +00:00
|
|
|
MWMechanics::CreatureStats& Creature::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-06 16:15:46 +00:00
|
|
|
boost::shared_ptr<MWWorld::Action> Creature::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
|
|
|
{
|
|
|
|
return boost::shared_ptr<MWWorld::Action> (new MWWorld::ActionTalk (ptr));
|
2011-01-05 21:18:21 +00:00
|
|
|
}
|
2010-08-07 18:33:07 +00:00
|
|
|
|
2012-01-28 10:45:55 +00:00
|
|
|
MWWorld::ContainerStore& Creature::getContainerStore (const MWWorld::Ptr& ptr)
|
2010-08-04 12:37:23 +00:00
|
|
|
const
|
|
|
|
{
|
2012-01-27 13:55:58 +00:00
|
|
|
ensureCustomData (ptr);
|
2010-08-04 12:37:23 +00:00
|
|
|
|
2012-01-27 13:55:58 +00:00
|
|
|
return dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mContainerStore;
|
2011-01-05 21:18:21 +00:00
|
|
|
}
|
2010-08-06 17:20:05 +00:00
|
|
|
|
2010-08-05 13:40:03 +00:00
|
|
|
std::string Creature::getScript (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2012-06-29 16:54:23 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::Creature> *ref =
|
2010-08-05 13:40:03 +00:00
|
|
|
ptr.get<ESM::Creature>();
|
|
|
|
|
|
|
|
return ref->base->script;
|
|
|
|
}
|
|
|
|
|
2010-08-03 11:03:08 +00:00
|
|
|
void Creature::registerSelf()
|
|
|
|
{
|
|
|
|
boost::shared_ptr<Class> instance (new Creature);
|
|
|
|
|
|
|
|
registerClass (typeid (ESM::Creature).name(), instance);
|
|
|
|
}
|
2012-04-16 20:58:16 +00:00
|
|
|
|
|
|
|
bool Creature::hasToolTip (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
/// \todo We don't want tooltips for Creatures in combat mode.
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-04-24 00:02:03 +00:00
|
|
|
MWGui::ToolTipInfo Creature::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::Creature> *ref =
|
2012-04-16 20:58:16 +00:00
|
|
|
ptr.get<ESM::Creature>();
|
|
|
|
|
|
|
|
MWGui::ToolTipInfo info;
|
|
|
|
info.caption = ref->base->name;
|
|
|
|
|
|
|
|
std::string text;
|
2012-04-24 00:02:03 +00:00
|
|
|
if (MWBase::Environment::get().getWindowManager()->getFullHelp())
|
2012-04-16 20:58:16 +00:00
|
|
|
text += MWGui::ToolTips::getMiscString(ref->base->script, "Script");
|
|
|
|
info.text = text;
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
2012-05-15 19:17:00 +00:00
|
|
|
|
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);
|
|
|
|
|
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-25 13:18:17 +00:00
|
|
|
|
|
|
|
MWWorld::Ptr
|
2012-07-26 12:14:11 +00:00
|
|
|
Creature::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
|
2012-07-25 13:18:17 +00:00
|
|
|
{
|
|
|
|
MWWorld::LiveCellRef<ESM::Creature> *ref =
|
|
|
|
ptr.get<ESM::Creature>();
|
|
|
|
|
|
|
|
return MWWorld::Ptr(&cell.creatures.insert(*ref), &cell);
|
|
|
|
}
|
2010-08-03 11:03:08 +00:00
|
|
|
}
|