From 1928bebe9857010ebe07c009eecbc9abded80b18 Mon Sep 17 00:00:00 2001 From: Capostrophic Date: Sat, 4 Apr 2020 19:20:52 +0300 Subject: [PATCH] Don't use up light duration if the held light is hidden (bug #5352) --- CHANGELOG.md | 1 + apps/openmw/mwmechanics/actors.cpp | 24 +++++++++++++--------- apps/openmw/mwrender/animation.hpp | 1 + apps/openmw/mwrender/creatureanimation.hpp | 2 ++ apps/openmw/mwrender/npcanimation.hpp | 2 ++ 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa838a3eb..5d765c1bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -211,6 +211,7 @@ Bug #5326: Formatting issues in the settings.cfg Bug #5328: Skills aren't properly reset for dead actors Bug #5345: Dopey Necromancy does not work due to a missing quote + Bug #5352: Light source items' duration is decremented while they aren't visible Feature #1774: Handle AvoidNode Feature #2229: Improve pathfinding AI Feature #3025: Analogue gamepad movement controls diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index 8ee248ee5..e81c9a119 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -1268,19 +1268,23 @@ namespace MWMechanics // Use time from the player's light if(isPlayer) { - float timeRemaining = heldIter->getClass().getRemainingUsageTime(*heldIter); - - // -1 is infinite light source. Other negative values are treated as 0. - if(timeRemaining != -1.0f) + // But avoid using it up if the light source is hidden + MWRender::Animation *anim = MWBase::Environment::get().getWorld()->getAnimation(ptr); + if (anim && anim->getCarriedLeftShown()) { - timeRemaining -= duration; + float timeRemaining = heldIter->getClass().getRemainingUsageTime(*heldIter); - if(timeRemaining > 0.0f) - heldIter->getClass().setRemainingUsageTime(*heldIter, timeRemaining); - else + // -1 is infinite light source. Other negative values are treated as 0. + if (timeRemaining != -1.0f) { - inventoryStore.remove(*heldIter, 1, ptr); // remove it - return; + timeRemaining -= duration; + if (timeRemaining <= 0.f) + { + inventoryStore.remove(*heldIter, 1, ptr); // remove it + return; + } + + heldIter->getClass().setRemainingUsageTime(*heldIter, timeRemaining); } } } diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index 17e13f047..7b1e1d3e9 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -459,6 +459,7 @@ public: virtual bool useShieldAnimations() const { return false; } virtual void showWeapons(bool showWeapon) {} + virtual bool getCarriedLeftShown() const { return false; } virtual void showCarriedLeft(bool show) {} virtual void setWeaponGroup(const std::string& group, bool relativeDuration) {} virtual void setVampire(bool vampire) {} diff --git a/apps/openmw/mwrender/creatureanimation.hpp b/apps/openmw/mwrender/creatureanimation.hpp index 524272584..cdcdafe24 100644 --- a/apps/openmw/mwrender/creatureanimation.hpp +++ b/apps/openmw/mwrender/creatureanimation.hpp @@ -31,6 +31,8 @@ namespace MWRender virtual void equipmentChanged() { updateParts(); } virtual void showWeapons(bool showWeapon); + + virtual bool getCarriedLeftShown() const { return mShowCarriedLeft; } virtual void showCarriedLeft(bool show); void updateParts(); diff --git a/apps/openmw/mwrender/npcanimation.hpp b/apps/openmw/mwrender/npcanimation.hpp index 2d6d3a05f..9e7969976 100644 --- a/apps/openmw/mwrender/npcanimation.hpp +++ b/apps/openmw/mwrender/npcanimation.hpp @@ -129,6 +129,8 @@ public: virtual void setPitchFactor(float factor) { mPitchFactor = factor; } virtual void showWeapons(bool showWeapon); + + virtual bool getCarriedLeftShown() const { return mShowCarriedLeft; } virtual void showCarriedLeft(bool show); virtual void attachArrow();