From d458894868dd5619fe30678fb29eadd119155db3 Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Thu, 18 Aug 2022 05:04:51 +0300 Subject: [PATCH] Make getWeaponDrawn return 1 only when the weapon is attached (bug #4816) --- CHANGELOG.md | 1 + apps/openmw/mwrender/animation.hpp | 1 + apps/openmw/mwrender/creatureanimation.hpp | 1 + apps/openmw/mwrender/npcanimation.hpp | 1 + apps/openmw/mwscript/miscextensions.cpp | 18 ++++++++++++++++-- 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7139f2ab6..1b99f77cae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ------ Bug #4127: Weapon animation looks choppy + Bug #4816: GetWeaponDrawn returns 1 before weapon is attached Bug #5057: Weapon swing sound plays at same pitch whether it hits or misses Bug #5129: Stuttering animation on Centurion Archer Bug #5977: Fatigueless NPCs' corpse underwater changes animation on game load diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index ff7be5e7ea..b3604dcaf1 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -465,6 +465,7 @@ public: const osg::Node* getNode(const std::string& name) const; virtual bool useShieldAnimations() const { return false; } + virtual bool getWeaponsShown() const { return false; } virtual void showWeapons(bool showWeapon) {} virtual bool getCarriedLeftShown() const { return false; } virtual void showCarriedLeft(bool show) {} diff --git a/apps/openmw/mwrender/creatureanimation.hpp b/apps/openmw/mwrender/creatureanimation.hpp index 9169e41024..8722539d6b 100644 --- a/apps/openmw/mwrender/creatureanimation.hpp +++ b/apps/openmw/mwrender/creatureanimation.hpp @@ -30,6 +30,7 @@ namespace MWRender void equipmentChanged() override { updateParts(); } + bool getWeaponsShown() const override { return mShowWeapons; } void showWeapons(bool showWeapon) override; bool getCarriedLeftShown() const override { return mShowCarriedLeft; } diff --git a/apps/openmw/mwrender/npcanimation.hpp b/apps/openmw/mwrender/npcanimation.hpp index d16b339ec6..15454ea794 100644 --- a/apps/openmw/mwrender/npcanimation.hpp +++ b/apps/openmw/mwrender/npcanimation.hpp @@ -135,6 +135,7 @@ public: /// to indicate the facing orientation of the character. void setPitchFactor(float factor) override { mPitchFactor = factor; } + bool getWeaponsShown() const override { return mShowWeapons; } void showWeapons(bool showWeapon) override; bool updateCarriedLeftVisible(const int weaptype) const override; diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 3f50d9158d..5ba808c217 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -47,6 +47,8 @@ #include "../mwmechanics/spellcasting.hpp" #include "../mwmechanics/actorutil.hpp" +#include "../mwrender/animation.hpp" + #include "interpretercontext.hpp" #include "ref.hpp" @@ -781,9 +783,21 @@ namespace MWScript void execute (Interpreter::Runtime& runtime) override { MWWorld::Ptr ptr = R()(runtime); + auto& cls = ptr.getClass(); + if (!cls.hasInventoryStore(ptr) && !cls.isBipedal(ptr)) + { + runtime.push(0); + return; + } + + if (cls.getCreatureStats(ptr).getDrawState () != MWMechanics::DrawState::Weapon) + { + runtime.push(0); + return; + } - runtime.push((ptr.getClass().hasInventoryStore(ptr) || ptr.getClass().isBipedal(ptr)) && - ptr.getClass().getCreatureStats (ptr).getDrawState () == MWMechanics::DrawState::Weapon); + MWRender::Animation* anim = MWBase::Environment::get().getWorld()->getAnimation(ptr); + runtime.push(anim && anim->getWeaponsShown()); } };