From 5354a5f78650f9b06e8118ecbe46a2b84c30263e Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Tue, 11 Mar 2025 00:30:56 +0300 Subject: [PATCH] Don't use attack strength as "hit ready" flag This unbreaks follow animations' strength dependence --- apps/openmw/mwmechanics/character.cpp | 16 +++++++++------- apps/openmw/mwmechanics/character.hpp | 1 + 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index c22308bce4..d13f3c9926 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -1104,10 +1104,10 @@ namespace MWMechanics attackType = ESM::Weapon::AT_Thrust; // We want to avoid hit keys that come out of nowhere (e.g. in the follow animation) // and processing multiple hit keys for a single attack - if (mAttackStrength != -1.f) + if (mReadyToHit) { charClass.hit(mPtr, mAttackStrength, attackType, mAttackVictim, mAttackHitPos, mAttackSuccess); - mAttackStrength = -1.f; + mReadyToHit = false; } } else if (isRandomAttackAnimation(groupname) && action == "start") @@ -1153,10 +1153,10 @@ namespace MWMechanics else if (action == "shoot release") { // See notes for melee release above - if (mAttackStrength != -1.f) + if (mReadyToHit) { mAnimation->releaseArrow(mAttackStrength); - mAttackStrength = -1.f; + mReadyToHit = false; } } else if (action == "shoot follow attach") @@ -1246,7 +1246,7 @@ namespace MWMechanics void CharacterController::prepareHit() { - if (mAttackStrength != -1.f) + if (mReadyToHit) return; auto& prng = MWBase::Environment::get().getWorld()->getPrng(); @@ -1261,6 +1261,8 @@ namespace MWMechanics mAttackStrength = 0.f; playSwishSound(); } + + mReadyToHit = true; } bool CharacterController::updateWeaponState() @@ -1520,6 +1522,7 @@ namespace MWMechanics && (mHitState == CharState_None || mHitState == CharState_Block)) { mAttackStrength = -1.f; + mReadyToHit = false; // Randomize attacks for non-bipedal creatures if (!cls.isBipedal(mPtr) @@ -1806,8 +1809,7 @@ namespace MWMechanics stop = strength + ' ' + stop; } - // Reset attack strength to make extra sure hits that come out of nowhere aren't processed - mAttackStrength = -1.f; + mReadyToHit = false; if (animPlaying) mAnimation->disable(mCurrentWeapon); diff --git a/apps/openmw/mwmechanics/character.hpp b/apps/openmw/mwmechanics/character.hpp index f043419a81..d5c642c883 100644 --- a/apps/openmw/mwmechanics/character.hpp +++ b/apps/openmw/mwmechanics/character.hpp @@ -172,6 +172,7 @@ namespace MWMechanics std::string mCurrentWeapon; float mAttackStrength{ -1.f }; + bool mReadyToHit{ false }; MWWorld::Ptr mAttackVictim; osg::Vec3f mAttackHitPos; bool mAttackSuccess{ false };