forked from mirror/openmw-tes3mp
Merge remote-tracking branch 'dteviot/ExtractCommonCreatureDraft'
commit
a9f9a8d58e
@ -0,0 +1,87 @@
|
||||
#include "actor.hpp"
|
||||
|
||||
#include <components/esm/loadmgef.hpp>
|
||||
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/world.hpp"
|
||||
#include "../mwbase/mechanicsmanager.hpp"
|
||||
#include "../mwbase/soundmanager.hpp"
|
||||
|
||||
#include "../mwmechanics/creaturestats.hpp"
|
||||
#include "../mwmechanics/movement.hpp"
|
||||
#include "../mwmechanics/magiceffects.hpp"
|
||||
|
||||
#include "../mwphysics/physicssystem.hpp"
|
||||
|
||||
#include "../mwworld/inventorystore.hpp"
|
||||
|
||||
namespace MWClass
|
||||
{
|
||||
Actor::Actor() {}
|
||||
|
||||
Actor::~Actor() {}
|
||||
|
||||
void Actor::adjustPosition(const MWWorld::Ptr& ptr, bool force) const
|
||||
{
|
||||
MWBase::Environment::get().getWorld()->adjustPosition(ptr, force);
|
||||
}
|
||||
|
||||
void Actor::insertObject(const MWWorld::Ptr& ptr, const std::string& model, MWPhysics::PhysicsSystem& physics) const
|
||||
{
|
||||
if (!model.empty())
|
||||
{
|
||||
physics.addActor(ptr, model);
|
||||
if (getCreatureStats(ptr).isDead())
|
||||
MWBase::Environment::get().getWorld()->enableActorCollision(ptr, false);
|
||||
}
|
||||
MWBase::Environment::get().getMechanicsManager()->add(ptr);
|
||||
}
|
||||
|
||||
void Actor::block(const MWWorld::Ptr &ptr) const
|
||||
{
|
||||
MWWorld::InventoryStore& inv = getInventoryStore(ptr);
|
||||
MWWorld::ContainerStoreIterator shield = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft);
|
||||
if (shield == inv.end())
|
||||
return;
|
||||
|
||||
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager();
|
||||
switch (shield->getClass().getEquipmentSkill(*shield))
|
||||
{
|
||||
case ESM::Skill::LightArmor:
|
||||
sndMgr->playSound3D(ptr, "Light Armor Hit", 1.0f, 1.0f);
|
||||
break;
|
||||
case ESM::Skill::MediumArmor:
|
||||
sndMgr->playSound3D(ptr, "Medium Armor Hit", 1.0f, 1.0f);
|
||||
break;
|
||||
case ESM::Skill::HeavyArmor:
|
||||
sndMgr->playSound3D(ptr, "Heavy Armor Hit", 1.0f, 1.0f);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool Actor::hasToolTip(const MWWorld::Ptr& ptr) const
|
||||
{
|
||||
return !ptr.getClass().getCreatureStats(ptr).getAiSequence().isInCombat() || getCreatureStats(ptr).isDead();
|
||||
}
|
||||
|
||||
osg::Vec3f Actor::getRotationVector(const MWWorld::Ptr& ptr) const
|
||||
{
|
||||
MWMechanics::Movement &movement = getMovementSettings(ptr);
|
||||
osg::Vec3f vec(movement.mRotation[0], movement.mRotation[1], movement.mRotation[2]);
|
||||
movement.mRotation[0] = 0.0f;
|
||||
movement.mRotation[1] = 0.0f;
|
||||
movement.mRotation[2] = 0.0f;
|
||||
return vec;
|
||||
}
|
||||
|
||||
float Actor::getEncumbrance(const MWWorld::Ptr& ptr) const
|
||||
{
|
||||
float weight = getContainerStore(ptr).getWeight();
|
||||
const MWMechanics::MagicEffects& effects = getCreatureStats(ptr).getMagicEffects();
|
||||
weight -= effects.get(MWMechanics::EffectKey(ESM::MagicEffect::Feather)).getMagnitude();
|
||||
weight += effects.get(MWMechanics::EffectKey(ESM::MagicEffect::Burden)).getMagnitude();
|
||||
return (weight < 0) ? 0.0f : weight;
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
#ifndef GAME_MWCLASS_MOBILE_H
|
||||
#define GAME_MWCLASS_MOBILE_H
|
||||
|
||||
#include "../mwworld/class.hpp"
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
struct GameSetting;
|
||||
}
|
||||
|
||||
namespace MWClass
|
||||
{
|
||||
/// \brief Class holding functionality common to Creature and NPC
|
||||
class Actor : public MWWorld::Class
|
||||
{
|
||||
protected:
|
||||
|
||||
Actor();
|
||||
|
||||
public:
|
||||
virtual ~Actor();
|
||||
|
||||
virtual void adjustPosition(const MWWorld::Ptr& ptr, bool force) const;
|
||||
///< Adjust position to stand on ground. Must be called post model load
|
||||
/// @param force do this even if the ptr is flying
|
||||
|
||||
virtual void insertObject(const MWWorld::Ptr& ptr, const std::string& model, MWPhysics::PhysicsSystem& physics) const;
|
||||
|
||||
virtual void block(const MWWorld::Ptr &ptr) const;
|
||||
|
||||
virtual bool hasToolTip(const MWWorld::Ptr& ptr) const;
|
||||
///< @return true if this object has a tooltip when focused (default implementation: false)
|
||||
|
||||
virtual osg::Vec3f getRotationVector(const MWWorld::Ptr& ptr) const;
|
||||
///< Return desired rotations, as euler angles.
|
||||
|
||||
virtual float getEncumbrance(const MWWorld::Ptr& ptr) const;
|
||||
///< Returns total weight of objects inside this object (including modifications from magic
|
||||
/// effects). Throws an exception, if the object can't hold other objects.
|
||||
|
||||
// not implemented
|
||||
Actor(const Actor&);
|
||||
Actor& operator= (const Actor&);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue