From 5a8c1661be8d688c6fcd7bd6cb65c85dbbe7eee4 Mon Sep 17 00:00:00 2001 From: Glorf Date: Tue, 30 Apr 2013 20:42:02 +0200 Subject: [PATCH] Jump acrobatics working, started falling acrobatics implementation --- apps/openmw/mwclass/npc.cpp | 28 +++++++++++++++++++++++++++ apps/openmw/mwclass/npc.hpp | 3 +++ apps/openmw/mwmechanics/character.cpp | 25 +++++++++++++++++++++++- apps/openmw/mwmechanics/character.hpp | 3 ++- apps/openmw/mwworld/class.cpp | 5 +++++ apps/openmw/mwworld/class.hpp | 3 +++ 6 files changed, 65 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index ea49ae4a4..a90b85955 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -470,6 +470,34 @@ namespace MWClass return x; } + float Npc::getFallDamage(const MWWorld::Ptr &ptr, float fallHeight) const + { + const float fallDistanceMin = MWBase::Environment::get().getWorld()->getStore().get().find ("fFallDamageDistanceMin")->getFloat(); + + if(fallHeight>=fallDistanceMin) + { + const float acrobaticsSkill = MWWorld::Class::get(ptr).getNpcStats (ptr).getSkill (ESM::Skill::Acrobatics).getModified(); + const CustomData *npcdata = static_cast(ptr.getRefData().getCustomData()); + const float jumpSpellBonus = npcdata->mCreatureStats.getMagicEffects().get(MWMechanics::EffectKey(9/*jump*/)).mMagnitude; + const float fallAcroBase = MWBase::Environment::get().getWorld()->getStore().get().find ("fFallAcroBase")->getFloat(); + const float fallAcroMult = MWBase::Environment::get().getWorld()->getStore().get().find ("fFallAcroMult")->getFloat(); + const float fallDistanceBase = MWBase::Environment::get().getWorld()->getStore().get().find ("fFallDistanceBase")->getFloat(); + const float fallDistanceMult = MWBase::Environment::get().getWorld()->getStore().get().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 { ensureCustomData (ptr); diff --git a/apps/openmw/mwclass/npc.hpp b/apps/openmw/mwclass/npc.hpp index d1a9158fd..47d32d88f 100644 --- a/apps/openmw/mwclass/npc.hpp +++ b/apps/openmw/mwclass/npc.hpp @@ -91,6 +91,9 @@ namespace MWClass virtual float getJump(const MWWorld::Ptr &ptr) const; ///< 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; ///< Return desired movement. diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index c762e6d14..9a8e34bb7 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -31,6 +31,8 @@ #include "../mwworld/player.hpp" #include "../mwworld/class.hpp" +#include "../mwmechanics/stat.hpp" +#include "../mwmechanics/creaturestats.hpp" namespace MWMechanics { @@ -105,7 +107,7 @@ static void getStateInfo(CharacterState state, std::string *group) CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim, CharacterState state, bool loop) : mPtr(ptr), mAnimation(anim), mCharState(state), mSkipAnim(false), mMovingAnim(false), - mSecondsOfRunning(0), mSecondsOfSwimming(0), mSecondsOfFalling(0) + mSecondsOfRunning(0), mSecondsOfSwimming(0), mHighestPosition(0) { if(!mAnimation) return; @@ -200,8 +202,29 @@ void CharacterController::update(float duration, Movement &movement) movement.mPosition[2] += x * 0.707f * duration; } + //To calculate how much player will fall down + if(movement.mPosition[2] > mHighestPosition) + mHighestPosition = movement.mPosition[2]; + //decrease fatigue by fFatigueJumpBase + (1 - normalizedEncumbrance) * fFatigueJumpMult; } + else if(vec.z==0.0f && getState()==CharState_Jump) + { + float healthLost = cls.getFallDamage(mPtr, mHighestPosition); + + if(healthLost>0.0f) + { + DynamicStat health = cls.getCreatureStats(mPtr).getHealth(); + int fatigue = MWWorld::Class::get (mPtr).getCreatureStats (mPtr).getFatigue().getBase(); + int iHealth = health.getBase(); + health.setBase (iHealth-(healthLost * (1 - (0.25 * fatigue)))); + cls.getCreatureStats(mPtr).setHealth (health); + MWWorld::Class::get(mPtr).skillUsageSucceeded(mPtr, ESM::Skill::Acrobatics, 1); + } + + setState(CharState_Idle, true); + mHighestPosition=0; + } if(std::abs(vec.x/2.0f) > std::abs(vec.y) && speed > 0.0f) { diff --git a/apps/openmw/mwmechanics/character.hpp b/apps/openmw/mwmechanics/character.hpp index 7dfd5d004..460141880 100644 --- a/apps/openmw/mwmechanics/character.hpp +++ b/apps/openmw/mwmechanics/character.hpp @@ -82,7 +82,8 @@ class CharacterController // counted for skill increase float mSecondsOfSwimming; float mSecondsOfRunning; - float mSecondsOfFalling; + + float mHighestPosition; bool mMovingAnim; diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index 03a55c7f0..db798537e 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -132,6 +132,11 @@ namespace MWWorld return 0; } + float Class::getFallDamage(const MWWorld::Ptr &ptr, float fallHeight) const + { + return 0; + } + float Class::getEnchantmentPoints (const MWWorld::Ptr& ptr) const { throw std::runtime_error ("class does not support enchanting"); diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index e203fedc3..3901ea830 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -146,6 +146,9 @@ namespace MWWorld virtual float getJump(const MWWorld::Ptr &ptr) const; ///< 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; ///< Return desired movement.