mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-22 03:39:40 +00:00
Add fall damage for creatures (Fixes #2201)
This commit is contained in:
parent
e0c6f84546
commit
3c747195ae
5 changed files with 30 additions and 43 deletions
|
@ -1002,37 +1002,6 @@ namespace MWClass
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Npc::getFallDamage(const MWWorld::Ptr &ptr, float fallHeight) const
|
|
||||||
{
|
|
||||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
|
||||||
const MWWorld::Store<ESM::GameSetting> &store = world->getStore().get<ESM::GameSetting>();
|
|
||||||
|
|
||||||
const float fallDistanceMin = store.find("fFallDamageDistanceMin")->getFloat();
|
|
||||||
|
|
||||||
if (fallHeight >= fallDistanceMin)
|
|
||||||
{
|
|
||||||
const float acrobaticsSkill = ptr.getClass().getNpcStats (ptr).getSkill(ESM::Skill::Acrobatics).getModified();
|
|
||||||
const NpcCustomData *npcdata = static_cast<const NpcCustomData*>(ptr.getRefData().getCustomData());
|
|
||||||
const float jumpSpellBonus = npcdata->mNpcStats.getMagicEffects().get(ESM::MagicEffect::Jump).getMagnitude();
|
|
||||||
const float fallAcroBase = store.find("fFallAcroBase")->getFloat();
|
|
||||||
const float fallAcroMult = store.find("fFallAcroMult")->getFloat();
|
|
||||||
const float fallDistanceBase = store.find("fFallDistanceBase")->getFloat();
|
|
||||||
const float fallDistanceMult = store.find("fFallDistanceMult")->getFloat();
|
|
||||||
|
|
||||||
float x = fallHeight - fallDistanceMin;
|
|
||||||
x -= (1.5 * acrobaticsSkill) + jumpSpellBonus;
|
|
||||||
x = std::max(0.0f, x);
|
|
||||||
|
|
||||||
float a = fallAcroBase + fallAcroMult * (100 - acrobaticsSkill);
|
|
||||||
x = fallDistanceBase + fallDistanceMult * x;
|
|
||||||
x *= a;
|
|
||||||
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
MWMechanics::Movement& Npc::getMovementSettings (const MWWorld::Ptr& ptr) const
|
MWMechanics::Movement& Npc::getMovementSettings (const MWWorld::Ptr& ptr) const
|
||||||
{
|
{
|
||||||
ensureCustomData (ptr);
|
ensureCustomData (ptr);
|
||||||
|
|
|
@ -104,9 +104,6 @@ namespace MWClass
|
||||||
virtual float getJump(const MWWorld::Ptr &ptr) const;
|
virtual float getJump(const MWWorld::Ptr &ptr) const;
|
||||||
///< Return jump velocity (not accounting for movement)
|
///< Return jump velocity (not accounting for movement)
|
||||||
|
|
||||||
virtual float getFallDamage(const MWWorld::Ptr &ptr, float fallHeight) const;
|
|
||||||
///< Return amount of health points lost when falling
|
|
||||||
|
|
||||||
virtual MWMechanics::Movement& getMovementSettings (const MWWorld::Ptr& ptr) const;
|
virtual MWMechanics::Movement& getMovementSettings (const MWWorld::Ptr& ptr) const;
|
||||||
///< Return desired movement.
|
///< Return desired movement.
|
||||||
|
|
||||||
|
|
|
@ -92,6 +92,35 @@ MWMechanics::CharacterState runStateToWalkState (MWMechanics::CharacterState sta
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float getFallDamage(const MWWorld::Ptr& ptr, float fallHeight)
|
||||||
|
{
|
||||||
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||||
|
const MWWorld::Store<ESM::GameSetting> &store = world->getStore().get<ESM::GameSetting>();
|
||||||
|
|
||||||
|
const float fallDistanceMin = store.find("fFallDamageDistanceMin")->getFloat();
|
||||||
|
|
||||||
|
if (fallHeight >= fallDistanceMin)
|
||||||
|
{
|
||||||
|
const float acrobaticsSkill = ptr.getClass().getSkill(ptr, ESM::Skill::Acrobatics);
|
||||||
|
const float jumpSpellBonus = ptr.getClass().getCreatureStats(ptr).getMagicEffects().get(ESM::MagicEffect::Jump).getMagnitude();
|
||||||
|
const float fallAcroBase = store.find("fFallAcroBase")->getFloat();
|
||||||
|
const float fallAcroMult = store.find("fFallAcroMult")->getFloat();
|
||||||
|
const float fallDistanceBase = store.find("fFallDistanceBase")->getFloat();
|
||||||
|
const float fallDistanceMult = store.find("fFallDistanceMult")->getFloat();
|
||||||
|
|
||||||
|
float x = fallHeight - fallDistanceMin;
|
||||||
|
x -= (1.5 * acrobaticsSkill) + jumpSpellBonus;
|
||||||
|
x = std::max(0.0f, x);
|
||||||
|
|
||||||
|
float a = fallAcroBase + fallAcroMult * (100 - acrobaticsSkill);
|
||||||
|
x = fallDistanceBase + fallDistanceMult * x;
|
||||||
|
x *= a;
|
||||||
|
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
return 0.f;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace MWMechanics
|
namespace MWMechanics
|
||||||
|
@ -1449,7 +1478,7 @@ void CharacterController::update(float duration)
|
||||||
vec.z = 0.0f;
|
vec.z = 0.0f;
|
||||||
|
|
||||||
float height = cls.getCreatureStats(mPtr).land();
|
float height = cls.getCreatureStats(mPtr).land();
|
||||||
float healthLost = cls.getFallDamage(mPtr, height);
|
float healthLost = getFallDamage(mPtr, height);
|
||||||
if (healthLost > 0.0f)
|
if (healthLost > 0.0f)
|
||||||
{
|
{
|
||||||
const float fatigueTerm = cls.getCreatureStats(mPtr).getFatigueTerm();
|
const float fatigueTerm = cls.getCreatureStats(mPtr).getFatigueTerm();
|
||||||
|
|
|
@ -180,11 +180,6 @@ namespace MWWorld
|
||||||
throw std::runtime_error ("class does not support enchanting");
|
throw std::runtime_error ("class does not support enchanting");
|
||||||
}
|
}
|
||||||
|
|
||||||
float Class::getFallDamage(const MWWorld::Ptr &ptr, float fallHeight) const
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
MWMechanics::Movement& Class::getMovementSettings (const Ptr& ptr) const
|
MWMechanics::Movement& Class::getMovementSettings (const Ptr& ptr) const
|
||||||
{
|
{
|
||||||
throw std::runtime_error ("movement settings not supported by class");
|
throw std::runtime_error ("movement settings not supported by class");
|
||||||
|
|
|
@ -184,9 +184,6 @@ namespace MWWorld
|
||||||
virtual float getJump(const MWWorld::Ptr &ptr) const;
|
virtual float getJump(const MWWorld::Ptr &ptr) const;
|
||||||
///< Return jump velocity (not accounting for movement)
|
///< Return jump velocity (not accounting for movement)
|
||||||
|
|
||||||
virtual float getFallDamage(const MWWorld::Ptr &ptr, float fallHeight) const;
|
|
||||||
///< Return amount of health points lost when falling
|
|
||||||
|
|
||||||
virtual MWMechanics::Movement& getMovementSettings (const Ptr& ptr) const;
|
virtual MWMechanics::Movement& getMovementSettings (const Ptr& ptr) const;
|
||||||
///< Return desired movement.
|
///< Return desired movement.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue