From ff5a042f5b091f8b99f78541ad28a8b4a2148fd5 Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Mon, 15 Aug 2022 02:58:44 +0300 Subject: [PATCH] Remove cooldown for ranged back up (bug #5129) --- CHANGELOG.md | 1 + apps/openmw/mwmechanics/aicombat.cpp | 50 +++++++++++++++------------- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e1916bd14..03dc98ae36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Bug #4127: Weapon animation looks choppy Bug #5057: Weapon swing sound plays at same pitch whether it hits or misses + Bug #5129: Stuttering animation on Centurion Archer 0.48.0 ------ diff --git a/apps/openmw/mwmechanics/aicombat.cpp b/apps/openmw/mwmechanics/aicombat.cpp index f4fe7fffc1..84221537bb 100644 --- a/apps/openmw/mwmechanics/aicombat.cpp +++ b/apps/openmw/mwmechanics/aicombat.cpp @@ -515,13 +515,35 @@ namespace MWMechanics bool targetUsesRanged = false; float rangeAttackOfTarget = ActionWeapon(targetWeapon).getCombatRange(targetUsesRanged); - - if (mMovement.mPosition[0] || mMovement.mPosition[1]) + + if (mMovement.mPosition[0]) { mTimerCombatMove = 0.1f + 0.1f * Misc::Rng::rollClosedProbability(prng); mCombatMove = true; } - else if (isDistantCombat) + // dodge movements (for NPCs and bipedal creatures) + // Note: do not use for ranged combat yet since in couple with back up behaviour can move actor out of cliff + else if (actor.getClass().isBipedal(actor) && !isDistantCombat) + { + float moveDuration = 0; + float angleToTarget = Misc::normalizeAngle(mMovement.mRotation[2] - actor.getRefData().getPosition().rot[2]); + // Apply a big side step if enemy tries to get around and come from behind. + // Otherwise apply a random side step (kind of dodging) with some probability + // if actor is within range of target's weapon. + if (std::abs(angleToTarget) > osg::PI / 4) + moveDuration = 0.2f; + else if (distToTarget <= rangeAttackOfTarget && Misc::Rng::rollClosedProbability(prng) < 0.25) + moveDuration = 0.1f + 0.1f * Misc::Rng::rollClosedProbability(prng); + if (moveDuration > 0) + { + mMovement.mPosition[0] = Misc::Rng::rollProbability(prng) < 0.5 ? 1.0f : -1.0f; // to the left/right + mTimerCombatMove = moveDuration; + mCombatMove = true; + } + } + + mMovement.mPosition[1] = 0; + if (isDistantCombat) { // Backing up behaviour // Actor backs up slightly further away than opponent's weapon range @@ -561,26 +583,6 @@ namespace MWMechanics mMovement.mPosition[1] = -1; } - // dodge movements (for NPCs and bipedal creatures) - // Note: do not use for ranged combat yet since in couple with back up behaviour can move actor out of cliff - else if (actor.getClass().isBipedal(actor)) - { - float moveDuration = 0; - float angleToTarget = Misc::normalizeAngle(mMovement.mRotation[2] - actor.getRefData().getPosition().rot[2]); - // Apply a big side step if enemy tries to get around and come from behind. - // Otherwise apply a random side step (kind of dodging) with some probability - // if actor is within range of target's weapon. - if (std::abs(angleToTarget) > osg::PI / 4) - moveDuration = 0.2f; - else if (distToTarget <= rangeAttackOfTarget && Misc::Rng::rollClosedProbability(prng) < 0.25) - moveDuration = 0.1f + 0.1f * Misc::Rng::rollClosedProbability(prng); - if (moveDuration > 0) - { - mMovement.mPosition[0] = Misc::Rng::rollProbability(prng) < 0.5 ? 1.0f : -1.0f; // to the left/right - mTimerCombatMove = moveDuration; - mCombatMove = true; - } - } } void AiCombatStorage::updateCombatMove(float duration) @@ -598,7 +600,7 @@ namespace MWMechanics void AiCombatStorage::stopCombatMove() { mTimerCombatMove = 0; - mMovement.mPosition[1] = mMovement.mPosition[0] = 0; + mMovement.mPosition[0] = 0; mCombatMove = false; }