From 92072d968b65ec6fef32d0211aad45ff08dbef30 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Thu, 19 Dec 2013 21:11:07 +0100 Subject: [PATCH] Fixes #845: NPCs hold torches during the day Simplified a bit code which shows and hides light. Signed-off-by: Lukasz Gromanowski --- apps/openmw/mwmechanics/character.cpp | 27 +++++++++++++-------------- apps/openmw/mwrender/npcanimation.cpp | 14 +++++++------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index 4f7754951e..398eadf866 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -36,6 +36,8 @@ #include "../mwworld/player.hpp" #include "../mwworld/class.hpp" #include "../mwworld/inventorystore.hpp" +#include "../mwworld/actionequip.hpp" +#include "../mwworld/actiontake.hpp" namespace { @@ -709,27 +711,24 @@ bool CharacterController::updateNpcState(bool onground, bool inwater, bool isrun if (MWBase::Environment::get().getWorld()->isNight()) { - MWWorld::ContainerStoreIterator torch = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft); - if(torch != inv.end() && torch->getTypeName() == typeid(ESM::Light).name()) + MWWorld::ContainerStoreIterator item = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft); + if (item != inv.end() && item->getTypeName() == typeid(ESM::Light).name()) { mAnimation->showLights(true); - if(!mAnimation->isPlaying("torch")) - mAnimation->play("torch", Priority_Torch, - MWRender::Animation::Group_LeftArm, false, - 1.0f, "start", "stop", 0.0f, (~(size_t)0)); - } - else if (mAnimation->isPlaying("torch")) - { - mAnimation->disable("torch"); - mAnimation->showLights(false); - mAnimation->showShield(true); + if (!mAnimation->isPlaying("torch")) + { + mAnimation->play("torch", Priority_Torch, MWRender::Animation::Group_LeftArm, + false, 1.0f, "start", "stop", 0.0f, (~(size_t)0)); + } } } else { + if (mAnimation->isPlaying("torch")) + { mAnimation->disable("torch"); - mAnimation->showLights(false); - mAnimation->showShield(true); + } + mAnimation->showLights(false); } return forcestateupdate; diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 6e363ab886..2da45e8a19 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -677,17 +677,17 @@ void NpcAnimation::showShield(bool show) void NpcAnimation::showLights(bool show) { - mShowLights = show; MWWorld::InventoryStore &inv = MWWorld::Class::get(mPtr).getInventoryStore(mPtr); - MWWorld::ContainerStoreIterator shield = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft); + MWWorld::ContainerStoreIterator light = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft); - if(show && shield != inv.end() && shield->getTypeName() == typeid(ESM::Light).name()) + if(show && light != inv.end() && light->getTypeName() == typeid(ESM::Light).name()) { - Ogre::Vector3 glowColor = getEnchantmentColor(*shield); - std::string mesh = MWWorld::Class::get(*shield).getModel(*shield); + mShowLights = show; + Ogre::Vector3 glowColor = getEnchantmentColor(*light); + std::string mesh = MWWorld::Class::get(*light).getModel(*light); addOrReplaceIndividualPart(ESM::PRT_Shield, MWWorld::InventoryStore::Slot_CarriedLeft, 1, - mesh, !shield->getClass().getEnchantment(*shield).empty(), &glowColor); - addExtraLight(mInsert->getCreator(), mObjectParts[ESM::PRT_Shield], shield->get()->mBase); + mesh, !light->getClass().getEnchantment(*light).empty(), &glowColor); + addExtraLight(mInsert->getCreator(), mObjectParts[ESM::PRT_Shield], light->get()->mBase); } else {