From c1d700f770b5cdffebd004e25f77a02b7afdf45a Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Mon, 28 Mar 2022 11:40:46 +0000 Subject: [PATCH] Don't reset last hit object if the ID doesn't match --- CHANGELOG.md | 1 + apps/openmw/mwmechanics/creaturestats.cpp | 5 +++++ apps/openmw/mwmechanics/creaturestats.hpp | 1 + apps/openmw/mwscript/miscextensions.cpp | 7 ++++--- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67245dc1ff..2c665740ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -108,6 +108,7 @@ Bug #6655: Constant effect absorb attribute causes the game to break Bug #6670: Dialogue order is incorrect Bug #6680: object.cpp handles nodetree unsafely, memory access with dangling pointer + Bug #6682: HitOnMe doesn't fire as intended Feature #890: OpenMW-CS: Column filtering Feature #1465: "Reset" argument for AI functions Feature #2491: Ability to make OpenMW "portable" diff --git a/apps/openmw/mwmechanics/creaturestats.cpp b/apps/openmw/mwmechanics/creaturestats.cpp index a53caf1451..90817b1e2d 100644 --- a/apps/openmw/mwmechanics/creaturestats.cpp +++ b/apps/openmw/mwmechanics/creaturestats.cpp @@ -347,6 +347,11 @@ namespace MWMechanics mLastHitObject = objectid; } + void CreatureStats::clearLastHitObject() + { + mLastHitObject.clear(); + } + const std::string &CreatureStats::getLastHitObject() const { return mLastHitObject; diff --git a/apps/openmw/mwmechanics/creaturestats.hpp b/apps/openmw/mwmechanics/creaturestats.hpp index 2bcb452292..719b2ff65c 100644 --- a/apps/openmw/mwmechanics/creaturestats.hpp +++ b/apps/openmw/mwmechanics/creaturestats.hpp @@ -255,6 +255,7 @@ namespace MWMechanics bool getStance (Stance flag) const; void setLastHitObject(const std::string &objectid); + void clearLastHitObject(); const std::string &getLastHitObject() const; void setLastHitAttemptObject(const std::string &objectid); const std::string &getLastHitAttemptObject() const; diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 38da34201b..2b557fc9b6 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -977,9 +977,10 @@ namespace MWScript runtime.pop(); MWMechanics::CreatureStats &stats = ptr.getClass().getCreatureStats(ptr); - runtime.push(::Misc::StringUtils::ciEqual(objectID, stats.getLastHitObject())); - - stats.setLastHitObject(std::string()); + bool hit = ::Misc::StringUtils::ciEqual(objectID, stats.getLastHitObject()); + runtime.push(hit); + if(hit) + stats.clearLastHitObject(); } };