From 85ec80100ce607e0b510b2a452716fa4906298c8 Mon Sep 17 00:00:00 2001
From: scrawl <scrawl@baseoftrash.de>
Date: Fri, 27 Dec 2013 22:00:16 +0100
Subject: [PATCH] Bug #1005: Hide torches/shields during spellcasting and
 hand-to-hand combat

---
 apps/openmw/mwmechanics/character.cpp |  7 ++++---
 apps/openmw/mwrender/animation.hpp    |  2 +-
 apps/openmw/mwrender/npcanimation.cpp | 30 ++++++++++-----------------
 apps/openmw/mwrender/npcanimation.hpp |  4 ++--
 4 files changed, 18 insertions(+), 25 deletions(-)

diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp
index fdf09d2f85..87a7875f5d 100644
--- a/apps/openmw/mwmechanics/character.cpp
+++ b/apps/openmw/mwmechanics/character.cpp
@@ -425,10 +425,10 @@ bool CharacterController::updateNpcState(bool onground, bool inwater, bool isrun
     {
         forcestateupdate = true;
 
-        // Shields shouldn't be visible during spellcasting
+        // Shields/torches shouldn't be visible during spellcasting or hand-to-hand
         // There seems to be no text keys for this purpose, except maybe for "[un]equip start/stop",
         // but they are also present in weapon drawing animation.
-        mAnimation->showShield(weaptype != WeapType_Spell);
+        mAnimation->showCarriedLeft(weaptype != WeapType_Spell && weaptype != WeapType_HandToHand);
 
         std::string weapgroup;
         if(weaptype == WeapType_None)
@@ -719,7 +719,8 @@ bool CharacterController::updateNpcState(bool onground, bool inwater, bool isrun
 
 
     MWWorld::ContainerStoreIterator torch = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft);
-    if(torch != inv.end() && torch->getTypeName() == typeid(ESM::Light).name())
+    if(torch != inv.end() && torch->getTypeName() == typeid(ESM::Light).name()
+            && mWeaponType != WeapType_Spell && mWeaponType != WeapType_HandToHand)
     {
         if(!mAnimation->isPlaying("torch"))
             mAnimation->play("torch", Priority_Torch,
diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp
index 67d8baa3f9..72d1c100ef 100644
--- a/apps/openmw/mwrender/animation.hpp
+++ b/apps/openmw/mwrender/animation.hpp
@@ -279,7 +279,7 @@ public:
     virtual Ogre::Vector3 runAnimation(float duration);
 
     virtual void showWeapons(bool showWeapon);
-    virtual void showShield(bool show) {}
+    virtual void showCarriedLeft(bool show) {}
 
     void enableLights(bool enable);
 
diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp
index 8d2f1c7da0..ddbdde83a6 100644
--- a/apps/openmw/mwrender/npcanimation.cpp
+++ b/apps/openmw/mwrender/npcanimation.cpp
@@ -117,7 +117,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, Ogre::SceneNode* node, int v
     mListenerDisabled(disableListener),
     mViewMode(viewMode),
     mShowWeapons(false),
-    mShowShield(true),
+    mShowCarriedLeft(true),
     mFirstPersonOffset(0.f, 0.f, 0.f),
     mAlpha(1.f)
 {
@@ -319,7 +319,7 @@ void NpcAnimation::updateParts()
     }
 
     showWeapons(mShowWeapons);
-    showShield(mShowShield);
+    showCarriedLeft(mShowCarriedLeft);
 
     // Remember body parts so we only have to search through the store once for each race/gender/viewmode combination
     static std::map< std::pair<std::string,int>,std::vector<const ESM::BodyPart*> > sRaceMapping;
@@ -654,32 +654,24 @@ void NpcAnimation::showWeapons(bool showWeapon)
     mAlpha = 1.f;
 }
 
-void NpcAnimation::showShield(bool show)
+void NpcAnimation::showCarriedLeft(bool show)
 {
-    mShowShield = show;
+    mShowCarriedLeft = show;
     MWWorld::InventoryStore &inv = MWWorld::Class::get(mPtr).getInventoryStore(mPtr);
-    MWWorld::ContainerStoreIterator shield = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft);
+    MWWorld::ContainerStoreIterator iter = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft);
 
-    if (shield != inv.end() && shield->getTypeName() == typeid(ESM::Light).name())
+    if(show && iter != inv.end())
     {
-        // ... Except for lights, which are still shown during spellcasting since they
-        // have their own (one-handed) casting animations
-        show = true;
-    }
-    if(show && shield != inv.end())
-    {
-        Ogre::Vector3 glowColor = getEnchantmentColor(*shield);
-        std::string mesh = MWWorld::Class::get(*shield).getModel(*shield);
+        Ogre::Vector3 glowColor = getEnchantmentColor(*iter);
+        std::string mesh = MWWorld::Class::get(*iter).getModel(*iter);
         addOrReplaceIndividualPart(ESM::PRT_Shield, MWWorld::InventoryStore::Slot_CarriedLeft, 1,
-                                   mesh, !shield->getClass().getEnchantment(*shield).empty(), &glowColor);
+                                   mesh, !iter->getClass().getEnchantment(*iter).empty(), &glowColor);
 
-        if (shield->getTypeName() == typeid(ESM::Light).name())
-            addExtraLight(mInsert->getCreator(), mObjectParts[ESM::PRT_Shield], shield->get<ESM::Light>()->mBase);
+        if (iter->getTypeName() == typeid(ESM::Light).name())
+            addExtraLight(mInsert->getCreator(), mObjectParts[ESM::PRT_Shield], iter->get<ESM::Light>()->mBase);
     }
     else
-    {
         removeIndividualPart(ESM::PRT_Shield);
-    }
 }
 
 void NpcAnimation::permanentEffectAdded(const ESM::MagicEffect *magicEffect, bool isNew, bool playSound)
diff --git a/apps/openmw/mwrender/npcanimation.hpp b/apps/openmw/mwrender/npcanimation.hpp
index b6ed3f8575..28bb81dddf 100644
--- a/apps/openmw/mwrender/npcanimation.hpp
+++ b/apps/openmw/mwrender/npcanimation.hpp
@@ -53,7 +53,7 @@ private:
     std::string    mHairModel;
     ViewMode       mViewMode;
     bool mShowWeapons;
-    bool mShowShield;
+    bool mShowCarriedLeft;
 
     int mVisibilityFlags;
 
@@ -100,7 +100,7 @@ public:
     virtual Ogre::Vector3 runAnimation(float timepassed);
 
     virtual void showWeapons(bool showWeapon);
-    virtual void showShield(bool showShield);
+    virtual void showCarriedLeft(bool showa);
 
     void setViewMode(ViewMode viewMode);