From 6c2ddc635d7e25f586210a19edd1cc6756958781 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Sun, 4 Feb 2024 21:41:03 +0100 Subject: [PATCH] Reset friendly hits at the end of combat and don't count hits while in combat --- CHANGELOG.md | 1 + apps/openmw/mwmechanics/aisequence.cpp | 10 ++++++++++ apps/openmw/mwmechanics/aisequence.hpp | 1 + apps/openmw/mwmechanics/combat.cpp | 2 ++ apps/openmw/mwmechanics/creaturestats.cpp | 5 +++++ apps/openmw/mwmechanics/creaturestats.hpp | 4 +++- apps/openmw/mwmechanics/mechanicsmanagerimp.cpp | 2 ++ 7 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a87cf7a80..7c4efcc2f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ Bug #5280: Unskinned shapes in skinned equipment are rendered in the wrong place Bug #5371: Keyframe animation tracks are used for any file that begins with an X Bug #5714: Touch spells cast using ExplodeSpell don't always explode + Bug #5755: Reset friendly hit counter Bug #5849: Paralysis breaks landing Bug #5870: Disposing of actors who were selected in the console doesn't deselect them like vanilla Bug #5883: Immobile creatures don't cause water ripples diff --git a/apps/openmw/mwmechanics/aisequence.cpp b/apps/openmw/mwmechanics/aisequence.cpp index 5d6f25ecb8..f5bb0be62f 100644 --- a/apps/openmw/mwmechanics/aisequence.cpp +++ b/apps/openmw/mwmechanics/aisequence.cpp @@ -82,7 +82,11 @@ namespace MWMechanics void AiSequence::onPackageRemoved(const AiPackage& package) { if (package.getTypeId() == AiPackageTypeId::Combat) + { mNumCombatPackages--; + if (mNumCombatPackages == 0) + mResetFriendlyHits = true; + } else if (package.getTypeId() == AiPackageTypeId::Pursue) mNumPursuitPackages--; @@ -246,6 +250,12 @@ namespace MWMechanics return; } + if (mResetFriendlyHits) + { + actor.getClass().getCreatureStats(actor).resetFriendlyHits(); + mResetFriendlyHits = false; + } + if (mPackages.empty()) { mLastAiPackage = AiPackageTypeId::None; diff --git a/apps/openmw/mwmechanics/aisequence.hpp b/apps/openmw/mwmechanics/aisequence.hpp index 92c1724ea6..dd2f0cbf77 100644 --- a/apps/openmw/mwmechanics/aisequence.hpp +++ b/apps/openmw/mwmechanics/aisequence.hpp @@ -39,6 +39,7 @@ namespace MWMechanics /// Finished with top AIPackage, set for one frame bool mDone{}; + bool mResetFriendlyHits{}; int mNumCombatPackages{}; int mNumPursuitPackages{}; diff --git a/apps/openmw/mwmechanics/combat.cpp b/apps/openmw/mwmechanics/combat.cpp index 3208ea2293..06de3b64f4 100644 --- a/apps/openmw/mwmechanics/combat.cpp +++ b/apps/openmw/mwmechanics/combat.cpp @@ -674,6 +674,8 @@ namespace MWMechanics return false; MWMechanics::CreatureStats& statsTarget = target.getClass().getCreatureStats(target); + if (statsTarget.getAiSequence().isInCombat()) + return true; statsTarget.friendlyHit(); if (statsTarget.getFriendlyHits() >= 4) return false; diff --git a/apps/openmw/mwmechanics/creaturestats.cpp b/apps/openmw/mwmechanics/creaturestats.cpp index 757bdf7c49..e20045791c 100644 --- a/apps/openmw/mwmechanics/creaturestats.cpp +++ b/apps/openmw/mwmechanics/creaturestats.cpp @@ -319,6 +319,11 @@ namespace MWMechanics ++mFriendlyHits; } + void CreatureStats::resetFriendlyHits() + { + mFriendlyHits = 0; + } + bool CreatureStats::hasTalkedToPlayer() const { return mTalkedTo; diff --git a/apps/openmw/mwmechanics/creaturestats.hpp b/apps/openmw/mwmechanics/creaturestats.hpp index f0a834bd33..7989357634 100644 --- a/apps/openmw/mwmechanics/creaturestats.hpp +++ b/apps/openmw/mwmechanics/creaturestats.hpp @@ -200,6 +200,8 @@ namespace MWMechanics void friendlyHit(); ///< Increase number of friendly hits by one. + void resetFriendlyHits(); + bool hasTalkedToPlayer() const; ///< Has this creature talked with the player before? @@ -294,7 +296,7 @@ namespace MWMechanics bool wasTeleported() const { return mTeleported; } void setTeleported(bool v) { mTeleported = v; } - const std::map getAttributes() const { return mAttributes; } + const std::map& getAttributes() const { return mAttributes; } }; } diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index 9fd1b3ff8d..c68a8db43c 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -1701,6 +1701,8 @@ namespace MWMechanics // We don't care about dialogue filters since the target is invalid. // We still want to play the combat taunt. MWBase::Environment::get().getDialogueManager()->say(ptr, ESM::RefId::stringRefId("attack")); + if (!stats.getAiSequence().isInCombat()) + stats.resetFriendlyHits(); return; }