1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 09:35:28 +00:00
fredzio c795e0bce6 Some actors are supposed to spawn on an object that belongs to an adjacent cell.
Since actors can be active in 3x3 grid around the player, we need to
first load all objects in a 5x5 grid around the player.

Split load and unloading in 2 phases. Add an mInactiveCells set into the
scene, which contains all cells inside the aforementioned 5x5 grid.
These cells contains only heightfields and non-animated physics objects.

Animated objects are tied to the scene graph, which doesn't exists yet
in these cells, so we skip them.
2021-06-28 09:36:04 +02:00

102 lines
3.4 KiB
C++

#include "actor.hpp"
#include <components/esm/loadmgef.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
#include "../mwbase/soundmanager.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/movement.hpp"
#include "../mwmechanics/magiceffects.hpp"
#include "../mwphysics/physicssystem.hpp"
#include "../mwworld/inventorystore.hpp"
namespace MWClass
{
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, osg::Quat rotation, MWPhysics::PhysicsSystem& physics, bool skipAnimated) const
{
if (!model.empty())
{
physics.addActor(ptr, model);
if (getCreatureStats(ptr).isDead() && getCreatureStats(ptr).isDeathAnimationFinished())
MWBase::Environment::get().getWorld()->enableActorCollision(ptr, false);
}
}
bool Actor::useAnim() const
{
return true;
}
void Actor::block(const MWWorld::Ptr &ptr) const
{
const MWWorld::InventoryStore& inv = getInventoryStore(ptr);
MWWorld::ConstContainerStoreIterator 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;
}
}
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();
if (ptr != MWMechanics::getPlayer() || !MWBase::Environment::get().getWorld()->getGodModeState())
weight += effects.get(MWMechanics::EffectKey(ESM::MagicEffect::Burden)).getMagnitude();
return (weight < 0) ? 0.0f : weight;
}
bool Actor::allowTelekinesis(const MWWorld::ConstPtr &ptr) const {
return false;
}
bool Actor::isActor() const
{
return true;
}
float Actor::getCurrentSpeed(const MWWorld::Ptr& ptr) const
{
const MWMechanics::Movement& movementSettings = ptr.getClass().getMovementSettings(ptr);
float moveSpeed = this->getMaxSpeed(ptr) * movementSettings.mSpeedFactor;
if (movementSettings.mIsStrafing)
moveSpeed *= 0.75f;
return moveSpeed;
}
}