Don't use attack strength as "hit ready" flag

This unbreaks follow animations' strength dependence
This commit is contained in:
Alexei Kotov 2025-03-11 00:30:56 +03:00
parent 73bb17009e
commit 5354a5f786
2 changed files with 10 additions and 7 deletions

View file

@ -1104,10 +1104,10 @@ namespace MWMechanics
attackType = ESM::Weapon::AT_Thrust; attackType = ESM::Weapon::AT_Thrust;
// We want to avoid hit keys that come out of nowhere (e.g. in the follow animation) // 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 // and processing multiple hit keys for a single attack
if (mAttackStrength != -1.f) if (mReadyToHit)
{ {
charClass.hit(mPtr, mAttackStrength, attackType, mAttackVictim, mAttackHitPos, mAttackSuccess); charClass.hit(mPtr, mAttackStrength, attackType, mAttackVictim, mAttackHitPos, mAttackSuccess);
mAttackStrength = -1.f; mReadyToHit = false;
} }
} }
else if (isRandomAttackAnimation(groupname) && action == "start") else if (isRandomAttackAnimation(groupname) && action == "start")
@ -1153,10 +1153,10 @@ namespace MWMechanics
else if (action == "shoot release") else if (action == "shoot release")
{ {
// See notes for melee release above // See notes for melee release above
if (mAttackStrength != -1.f) if (mReadyToHit)
{ {
mAnimation->releaseArrow(mAttackStrength); mAnimation->releaseArrow(mAttackStrength);
mAttackStrength = -1.f; mReadyToHit = false;
} }
} }
else if (action == "shoot follow attach") else if (action == "shoot follow attach")
@ -1246,7 +1246,7 @@ namespace MWMechanics
void CharacterController::prepareHit() void CharacterController::prepareHit()
{ {
if (mAttackStrength != -1.f) if (mReadyToHit)
return; return;
auto& prng = MWBase::Environment::get().getWorld()->getPrng(); auto& prng = MWBase::Environment::get().getWorld()->getPrng();
@ -1261,6 +1261,8 @@ namespace MWMechanics
mAttackStrength = 0.f; mAttackStrength = 0.f;
playSwishSound(); playSwishSound();
} }
mReadyToHit = true;
} }
bool CharacterController::updateWeaponState() bool CharacterController::updateWeaponState()
@ -1520,6 +1522,7 @@ namespace MWMechanics
&& (mHitState == CharState_None || mHitState == CharState_Block)) && (mHitState == CharState_None || mHitState == CharState_Block))
{ {
mAttackStrength = -1.f; mAttackStrength = -1.f;
mReadyToHit = false;
// Randomize attacks for non-bipedal creatures // Randomize attacks for non-bipedal creatures
if (!cls.isBipedal(mPtr) if (!cls.isBipedal(mPtr)
@ -1806,8 +1809,7 @@ namespace MWMechanics
stop = strength + ' ' + stop; stop = strength + ' ' + stop;
} }
// Reset attack strength to make extra sure hits that come out of nowhere aren't processed mReadyToHit = false;
mAttackStrength = -1.f;
if (animPlaying) if (animPlaying)
mAnimation->disable(mCurrentWeapon); mAnimation->disable(mCurrentWeapon);

View file

@ -172,6 +172,7 @@ namespace MWMechanics
std::string mCurrentWeapon; std::string mCurrentWeapon;
float mAttackStrength{ -1.f }; float mAttackStrength{ -1.f };
bool mReadyToHit{ false };
MWWorld::Ptr mAttackVictim; MWWorld::Ptr mAttackVictim;
osg::Vec3f mAttackHitPos; osg::Vec3f mAttackHitPos;
bool mAttackSuccess{ false }; bool mAttackSuccess{ false };