2010-08-03 13:03:08 +02:00
|
|
|
|
|
|
|
#include "creature.hpp"
|
|
|
|
|
|
|
|
#include <components/esm/loadcrea.hpp>
|
|
|
|
|
|
|
|
#include "../mwmechanics/creaturestats.hpp"
|
2012-05-15 21:34:00 +02:00
|
|
|
#include "../mwmechanics/magiceffects.hpp"
|
2013-05-27 18:03:06 +02:00
|
|
|
#include "../mwmechanics/movement.hpp"
|
2010-08-03 13:03:08 +02:00
|
|
|
|
2012-04-23 15:27:03 +02:00
|
|
|
#include "../mwbase/environment.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"
|
2013-04-03 23:55:57 +02:00
|
|
|
#include "../mwbase/world.hpp"
|
2013-07-26 05:24:56 -07:00
|
|
|
#include "../mwbase/soundmanager.hpp"
|
2012-04-23 15:27:03 +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-01-26 11:35:47 +01:00
|
|
|
#include "../mwworld/customdata.hpp"
|
2012-01-27 14:55:58 +01:00
|
|
|
#include "../mwworld/containerstore.hpp"
|
2012-07-03 13:15:20 +02:00
|
|
|
#include "../mwworld/physicssystem.hpp"
|
|
|
|
|
|
|
|
#include "../mwrender/renderinginterface.hpp"
|
2013-01-05 21:12:08 -08:00
|
|
|
#include "../mwrender/actors.hpp"
|
2010-08-03 13:03:08 +02:00
|
|
|
|
2012-07-03 13:15:20 +02:00
|
|
|
#include "../mwgui/tooltips.hpp"
|
2012-04-16 22:58:16 +02:00
|
|
|
|
2012-01-26 11:35:47 +01:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
struct CustomData : public MWWorld::CustomData
|
|
|
|
{
|
|
|
|
MWMechanics::CreatureStats mCreatureStats;
|
2012-01-28 11:45:55 +01:00
|
|
|
MWWorld::ContainerStore mContainerStore;
|
2013-05-27 18:03:06 +02:00
|
|
|
MWMechanics::Movement mMovement;
|
2012-01-26 11:35:47 +01:00
|
|
|
|
|
|
|
virtual MWWorld::CustomData *clone() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
MWWorld::CustomData *CustomData::clone() const
|
|
|
|
{
|
|
|
|
return new CustomData (*this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-03 13:17:31 +02:00
|
|
|
namespace MWClass
|
2010-08-03 13:03:08 +02:00
|
|
|
{
|
2012-01-26 11:35:47 +01:00
|
|
|
void Creature::ensureCustomData (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
if (!ptr.getRefData().getCustomData())
|
|
|
|
{
|
|
|
|
std::auto_ptr<CustomData> data (new CustomData);
|
|
|
|
|
2013-05-27 18:03:06 +02:00
|
|
|
static bool inited = false;
|
|
|
|
if(!inited)
|
|
|
|
{
|
|
|
|
const MWBase::World *world = MWBase::Environment::get().getWorld();
|
|
|
|
const MWWorld::Store<ESM::GameSetting> &gmst = world->getStore().get<ESM::GameSetting>();
|
|
|
|
|
|
|
|
fMinWalkSpeedCreature = gmst.find("fMinWalkSpeedCreature");
|
|
|
|
fMaxWalkSpeedCreature = gmst.find("fMaxWalkSpeedCreature");
|
|
|
|
|
|
|
|
inited = true;
|
|
|
|
}
|
|
|
|
|
2012-06-29 18:54:23 +02:00
|
|
|
MWWorld::LiveCellRef<ESM::Creature> *ref = ptr.get<ESM::Creature>();
|
2012-01-26 11:35:47 +01:00
|
|
|
|
|
|
|
// creature stats
|
2012-11-05 16:07:59 +04: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);
|
|
|
|
|
2013-07-31 00:55:08 +02:00
|
|
|
data->mCreatureStats.getAiSequence().fill(ref->mBase->mAiPackage);
|
|
|
|
|
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-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-06-16 16:17:42 +02:00
|
|
|
|
2013-07-31 00:02:24 +02:00
|
|
|
// inventory
|
|
|
|
data->mContainerStore.fill(ref->mBase->mInventory, getId(ptr),
|
|
|
|
MWBase::Environment::get().getWorld()->getStore());
|
|
|
|
|
2012-01-26 11:35:47 +01:00
|
|
|
// store
|
|
|
|
ptr.getRefData().setCustomData (data.release());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-08 14:28:35 +02:00
|
|
|
std::string Creature::getId (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2012-06-29 18:54:23 +02:00
|
|
|
MWWorld::LiveCellRef<ESM::Creature> *ref =
|
2010-08-08 14:28:35 +02:00
|
|
|
ptr.get<ESM::Creature>();
|
|
|
|
|
2012-11-05 16:07:59 +04:00
|
|
|
return ref->mBase->mId;
|
2010-08-08 14:28:35 +02:00
|
|
|
}
|
|
|
|
|
2013-04-03 23:55:57 +02:00
|
|
|
void Creature::adjustPosition(const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
MWBase::Environment::get().getWorld()->adjustPosition(ptr);
|
|
|
|
}
|
|
|
|
|
2011-11-11 23:01:12 -05:00
|
|
|
void Creature::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
|
2010-08-14 10:02:54 +02:00
|
|
|
{
|
2012-01-27 14:55:58 +01:00
|
|
|
MWRender::Actors& actors = renderingInterface.getActors();
|
|
|
|
actors.insertCreature(ptr);
|
2010-08-14 10:02:54 +02:00
|
|
|
}
|
|
|
|
|
2012-04-23 15:27:03 +02:00
|
|
|
void Creature::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
|
2012-07-24 20:22:11 +04:00
|
|
|
{
|
|
|
|
const std::string model = getModel(ptr);
|
2012-11-05 18:40:02 +00:00
|
|
|
if(!model.empty())
|
|
|
|
physics.addActor(ptr);
|
2013-01-28 23:39:11 -08:00
|
|
|
MWBase::Environment::get().getMechanicsManager()->add(ptr);
|
2012-07-24 20:22:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string Creature::getModel(const MWWorld::Ptr &ptr) const
|
2011-11-11 23:01:12 -05:00
|
|
|
{
|
2012-06-29 18:54:23 +02:00
|
|
|
MWWorld::LiveCellRef<ESM::Creature> *ref =
|
2011-11-11 23:01:12 -05:00
|
|
|
ptr.get<ESM::Creature>();
|
2012-11-05 16:07:59 +04:00
|
|
|
assert (ref->mBase != NULL);
|
2011-11-11 23:01:12 -05:00
|
|
|
|
2012-11-05 16:07:59 +04:00
|
|
|
const std::string &model = ref->mBase->mModel;
|
2012-07-24 20:22:11 +04:00
|
|
|
if (!model.empty()) {
|
|
|
|
return "meshes\\" + model;
|
2011-11-24 23:13:34 -05:00
|
|
|
}
|
2012-08-11 17:30:55 +02:00
|
|
|
return "";
|
2010-08-14 11:27:13 +02:00
|
|
|
}
|
|
|
|
|
2010-08-03 17:11:41 +02:00
|
|
|
std::string Creature::getName (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2012-06-29 18:54:23 +02:00
|
|
|
MWWorld::LiveCellRef<ESM::Creature> *ref =
|
2010-08-03 17:11:41 +02:00
|
|
|
ptr.get<ESM::Creature>();
|
|
|
|
|
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& Creature::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
|
|
|
}
|
|
|
|
|
2013-07-24 02:51:42 -07:00
|
|
|
|
2013-07-25 00:30:01 -07:00
|
|
|
void Creature::hit(const MWWorld::Ptr& ptr, int type) const
|
2013-07-24 02:51:42 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-07-28 06:48:25 -07:00
|
|
|
void Creature::onHit(const MWWorld::Ptr &ptr, float damage, bool ishealth, const MWWorld::Ptr &object, const MWWorld::Ptr &attacker, bool successful) const
|
2013-07-24 02:51:42 -07:00
|
|
|
{
|
2013-07-26 05:24:56 -07:00
|
|
|
// NOTE: 'object' and/or 'attacker' may be empty.
|
2013-07-24 02:51:42 -07:00
|
|
|
|
2013-07-26 05:24:56 -07:00
|
|
|
if(!successful)
|
2013-07-24 02:51:42 -07:00
|
|
|
{
|
2013-07-26 05:24:56 -07:00
|
|
|
// TODO: Handle HitAttemptOnMe script function
|
|
|
|
|
|
|
|
// Missed
|
|
|
|
MWBase::Environment::get().getSoundManager()->playSound3D(ptr, "miss", 1.0f, 1.0f);
|
|
|
|
return;
|
2013-07-24 02:51:42 -07:00
|
|
|
}
|
|
|
|
|
2013-07-26 08:08:52 -07:00
|
|
|
if(!object.isEmpty())
|
|
|
|
getCreatureStats(ptr).setLastHitObject(MWWorld::Class::get(object).getId(object));
|
2013-07-26 07:04:36 -07:00
|
|
|
|
|
|
|
if(!attacker.isEmpty() && attacker.getRefData().getHandle() == "player")
|
|
|
|
{
|
|
|
|
const std::string &script = ptr.get<ESM::Creature>()->mBase->mScript;
|
|
|
|
/* Set the OnPCHitMe script variable. The script is responsible for clearing it. */
|
|
|
|
if(!script.empty())
|
|
|
|
ptr.getRefData().getLocals().setVarByInt(script, "onpchitme", 1);
|
|
|
|
}
|
2013-07-26 05:24:56 -07:00
|
|
|
|
2013-07-28 06:48:25 -07:00
|
|
|
if(ishealth)
|
2013-07-27 11:20:39 -07:00
|
|
|
{
|
2013-07-28 06:48:25 -07:00
|
|
|
if(damage > 0.0f)
|
|
|
|
MWBase::Environment::get().getSoundManager()->playSound3D(ptr, "Health Damage", 1.0f, 1.0f);
|
|
|
|
float health = getCreatureStats(ptr).getHealth().getCurrent() - damage;
|
|
|
|
setActorHealth(ptr, health, attacker);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MWMechanics::DynamicStat<float> fatigue(getCreatureStats(ptr).getFatigue());
|
|
|
|
fatigue.setCurrent(fatigue.getCurrent() - damage);
|
|
|
|
getCreatureStats(ptr).setFatigue(fatigue);
|
2013-07-27 11:20:39 -07:00
|
|
|
}
|
2013-07-26 05:24:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void Creature::setActorHealth(const MWWorld::Ptr& ptr, float health, const MWWorld::Ptr& attacker) const
|
|
|
|
{
|
|
|
|
MWMechanics::CreatureStats &crstats = getCreatureStats(ptr);
|
2013-07-24 02:51:42 -07:00
|
|
|
bool wasDead = crstats.isDead();
|
|
|
|
|
|
|
|
MWMechanics::DynamicStat<float> stat(crstats.getHealth());
|
|
|
|
stat.setCurrent(health);
|
|
|
|
crstats.setHealth(stat);
|
|
|
|
|
|
|
|
if(!wasDead && crstats.isDead())
|
|
|
|
{
|
|
|
|
// actor was just killed
|
|
|
|
}
|
|
|
|
else if(wasDead && !crstats.isDead())
|
|
|
|
{
|
|
|
|
// actor was just resurrected
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-06 18:15:46 +02:00
|
|
|
boost::shared_ptr<MWWorld::Action> Creature::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())
|
2013-03-07 14:00:13 +01:00
|
|
|
return boost::shared_ptr<MWWorld::Action> (new MWWorld::ActionOpen(ptr, true));
|
2012-10-28 16:04:33 +01:00
|
|
|
else
|
|
|
|
return boost::shared_ptr<MWWorld::Action> (new MWWorld::ActionTalk (ptr));
|
2011-01-05 22:18:21 +01:00
|
|
|
}
|
2010-08-07 20:33:07 +02:00
|
|
|
|
2012-01-28 11:45:55 +01:00
|
|
|
MWWorld::ContainerStore& Creature::getContainerStore (const MWWorld::Ptr& ptr)
|
2010-08-04 14:37:23 +02:00
|
|
|
const
|
|
|
|
{
|
2012-01-27 14:55:58 +01:00
|
|
|
ensureCustomData (ptr);
|
2010-08-04 14:37:23 +02:00
|
|
|
|
2012-01-27 14:55:58 +01:00
|
|
|
return dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mContainerStore;
|
2011-01-05 22:18:21 +01:00
|
|
|
}
|
2010-08-06 19:20:05 +02:00
|
|
|
|
2010-08-05 15:40:03 +02:00
|
|
|
std::string Creature::getScript (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2012-06-29 18:54:23 +02:00
|
|
|
MWWorld::LiveCellRef<ESM::Creature> *ref =
|
2010-08-05 15:40:03 +02:00
|
|
|
ptr.get<ESM::Creature>();
|
|
|
|
|
2012-11-05 16:07:59 +04:00
|
|
|
return ref->mBase->mScript;
|
2010-08-05 15:40:03 +02:00
|
|
|
}
|
|
|
|
|
2012-10-27 13:33:54 +02:00
|
|
|
bool Creature::isEssential (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
MWWorld::LiveCellRef<ESM::Creature> *ref =
|
|
|
|
ptr.get<ESM::Creature>();
|
|
|
|
|
2012-11-05 16:07:59 +04:00
|
|
|
return ref->mBase->mFlags & ESM::Creature::Essential;
|
2012-10-27 13:33:54 +02:00
|
|
|
}
|
|
|
|
|
2010-08-03 13:03:08 +02:00
|
|
|
void Creature::registerSelf()
|
|
|
|
{
|
|
|
|
boost::shared_ptr<Class> instance (new Creature);
|
|
|
|
|
|
|
|
registerClass (typeid (ESM::Creature).name(), instance);
|
|
|
|
}
|
2012-04-16 22:58:16 +02:00
|
|
|
|
|
|
|
bool Creature::hasToolTip (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
/// \todo We don't want tooltips for Creatures in combat mode.
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-05-27 18:03:06 +02:00
|
|
|
float Creature::getSpeed(const MWWorld::Ptr &ptr) const
|
|
|
|
{
|
|
|
|
MWMechanics::CreatureStats& stats = getCreatureStats(ptr);
|
|
|
|
float walkSpeed = fMinWalkSpeedCreature->getFloat() + 0.01 * stats.getAttribute(ESM::Attribute::Speed).getModified()
|
|
|
|
* (fMaxWalkSpeedCreature->getFloat() - fMinWalkSpeedCreature->getFloat());
|
|
|
|
/// \todo what about the rest?
|
|
|
|
return walkSpeed;
|
|
|
|
}
|
|
|
|
|
|
|
|
MWMechanics::Movement& Creature::getMovementSettings (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
ensureCustomData (ptr);
|
|
|
|
|
|
|
|
return dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mMovement;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ogre::Vector3 Creature::getMovementVector (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
MWMechanics::Movement &movement = getMovementSettings(ptr);
|
|
|
|
Ogre::Vector3 vec(movement.mPosition);
|
|
|
|
movement.mPosition[0] = 0.0f;
|
|
|
|
movement.mPosition[1] = 0.0f;
|
|
|
|
movement.mPosition[2] = 0.0f;
|
|
|
|
return vec;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ogre::Vector3 Creature::getRotationVector (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
MWMechanics::Movement &movement = getMovementSettings(ptr);
|
|
|
|
Ogre::Vector3 vec(movement.mRotation);
|
|
|
|
movement.mRotation[0] = 0.0f;
|
|
|
|
movement.mRotation[1] = 0.0f;
|
|
|
|
movement.mRotation[2] = 0.0f;
|
|
|
|
return vec;
|
|
|
|
}
|
|
|
|
|
2012-04-24 02:02:03 +02:00
|
|
|
MWGui::ToolTipInfo Creature::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::Creature> *ref =
|
2012-04-16 22:58:16 +02:00
|
|
|
ptr.get<ESM::Creature>();
|
|
|
|
|
|
|
|
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
|
|
|
|
2013-03-17 22:29:12 +01: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 22:31:52 +02:00
|
|
|
float Creature::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 Creature::getEncumbrance (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
float weight = getContainerStore (ptr).getWeight();
|
|
|
|
|
|
|
|
const MWMechanics::CreatureStats& stats = getCreatureStats (ptr);
|
|
|
|
|
2013-03-16 23:28:26 +01:00
|
|
|
weight -= stats.getMagicEffects().get (MWMechanics::EffectKey (ESM::MagicEffect::Feather)).mMagnitude;
|
2012-05-15 21:34:00 +02:00
|
|
|
|
2013-03-16 23:28:26 +01:00
|
|
|
weight += stats.getMagicEffects().get (MWMechanics::EffectKey (ESM::MagicEffect::Burden)).mMagnitude;
|
2012-05-15 21:34:00 +02:00
|
|
|
|
|
|
|
if (weight<0)
|
|
|
|
weight = 0;
|
|
|
|
|
|
|
|
return weight;
|
|
|
|
}
|
2012-07-25 17:18:17 +04:00
|
|
|
|
2013-05-11 18:38:27 +02:00
|
|
|
|
|
|
|
int Creature::getServices(const MWWorld::Ptr &actor) const
|
|
|
|
{
|
|
|
|
MWWorld::LiveCellRef<ESM::Creature>* ref = actor.get<ESM::Creature>();
|
|
|
|
if (ref->mBase->mHasAI)
|
|
|
|
return ref->mBase->mAiData.mServices;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-05-16 18:50:26 +02:00
|
|
|
bool Creature::isPersistent(const MWWorld::Ptr &actor) const
|
|
|
|
{
|
|
|
|
MWWorld::LiveCellRef<ESM::Creature>* ref = actor.get<ESM::Creature>();
|
|
|
|
return ref->mBase->mPersistent;
|
|
|
|
}
|
|
|
|
|
2013-07-17 23:58:21 -07:00
|
|
|
std::string Creature::getSoundIdFromSndGen(const MWWorld::Ptr &ptr, const std::string &name) const
|
|
|
|
{
|
|
|
|
const MWWorld::Store<ESM::SoundGenerator> &store = MWBase::Environment::get().getWorld()->getStore().get<ESM::SoundGenerator>();
|
|
|
|
|
|
|
|
int type = getSndGenTypeFromName(ptr, name);
|
|
|
|
if(type >= 0)
|
|
|
|
{
|
|
|
|
std::vector<const ESM::SoundGenerator*> sounds;
|
|
|
|
sounds.reserve(8);
|
|
|
|
|
|
|
|
std::string ptrid = Creature::getId(ptr);
|
|
|
|
MWWorld::Store<ESM::SoundGenerator>::iterator sound = store.begin();
|
|
|
|
while(sound != store.end())
|
|
|
|
{
|
2013-07-31 18:46:32 +02:00
|
|
|
if(type == sound->mType && !sound->mCreature.empty() &&
|
2013-07-17 23:58:21 -07:00
|
|
|
Misc::StringUtils::ciEqual(ptrid.substr(0, sound->mCreature.size()),
|
|
|
|
sound->mCreature))
|
|
|
|
sounds.push_back(&*sound);
|
2013-07-31 18:46:32 +02:00
|
|
|
++sound;
|
2013-07-17 23:58:21 -07:00
|
|
|
}
|
2013-07-31 18:46:32 +02:00
|
|
|
if(!sounds.empty())
|
2013-07-17 23:58:21 -07:00
|
|
|
return sounds[(int)(rand()/(RAND_MAX+1.0)*sounds.size())]->mSound;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2012-07-25 17:18:17 +04:00
|
|
|
MWWorld::Ptr
|
2012-07-26 16:14:11 +04:00
|
|
|
Creature::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
|
2012-07-25 17:18:17 +04:00
|
|
|
{
|
|
|
|
MWWorld::LiveCellRef<ESM::Creature> *ref =
|
|
|
|
ptr.get<ESM::Creature>();
|
|
|
|
|
2012-11-05 16:07:59 +04:00
|
|
|
return MWWorld::Ptr(&cell.mCreatures.insert(*ref), &cell);
|
2012-07-25 17:18:17 +04:00
|
|
|
}
|
2013-05-27 18:03:06 +02:00
|
|
|
|
2013-07-17 23:58:21 -07:00
|
|
|
int Creature::getSndGenTypeFromName(const MWWorld::Ptr &ptr, const std::string &name)
|
|
|
|
{
|
|
|
|
if(name == "left")
|
|
|
|
{
|
|
|
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
|
|
|
Ogre::Vector3 pos(ptr.getRefData().getPosition().pos);
|
|
|
|
if(world->isUnderwater(ptr.getCell(), pos))
|
|
|
|
return 2;
|
|
|
|
if(world->isOnGround(ptr))
|
|
|
|
return 0;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if(name == "right")
|
|
|
|
{
|
|
|
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
|
|
|
Ogre::Vector3 pos(ptr.getRefData().getPosition().pos);
|
|
|
|
if(world->isUnderwater(ptr.getCell(), pos))
|
|
|
|
return 3;
|
|
|
|
if(world->isOnGround(ptr))
|
|
|
|
return 1;
|
|
|
|
return -1;
|
|
|
|
}
|
2013-08-08 01:35:22 -07:00
|
|
|
if(name == "swimleft")
|
|
|
|
return 2;
|
|
|
|
if(name == "swimright")
|
|
|
|
return 3;
|
2013-07-17 23:58:21 -07:00
|
|
|
if(name == "moan")
|
|
|
|
return 4;
|
|
|
|
if(name == "roar")
|
|
|
|
return 5;
|
|
|
|
if(name == "scream")
|
|
|
|
return 6;
|
2013-07-24 10:36:04 -07:00
|
|
|
if(name == "land")
|
|
|
|
return 7;
|
2013-07-17 23:58:21 -07:00
|
|
|
|
|
|
|
throw std::runtime_error(std::string("Unexpected soundgen type: ")+name);
|
|
|
|
}
|
|
|
|
|
2013-05-27 18:03:06 +02:00
|
|
|
const ESM::GameSetting* Creature::fMinWalkSpeedCreature;
|
|
|
|
const ESM::GameSetting* Creature::fMaxWalkSpeedCreature;
|
2010-08-03 13:03:08 +02:00
|
|
|
}
|