From b145d183aef7e980c025c192593332e36db6c6f3 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 19 Sep 2014 09:10:46 +0200 Subject: [PATCH] Fix incorrect alchemy failure handling when an effect has a zero magnitude/duration (Fixes #1922) --- apps/openmw/mwgui/alchemywindow.cpp | 24 +++++++++++++++++------- apps/openmw/mwmechanics/alchemy.cpp | 5 ++++- apps/openmw/mwmechanics/alchemy.hpp | 16 ++++++++-------- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/apps/openmw/mwgui/alchemywindow.cpp b/apps/openmw/mwgui/alchemywindow.cpp index 0b3e3c168..427e5bdd7 100644 --- a/apps/openmw/mwgui/alchemywindow.cpp +++ b/apps/openmw/mwgui/alchemywindow.cpp @@ -8,6 +8,8 @@ #include "../mwbase/soundmanager.hpp" #include "../mwbase/windowmanager.hpp" +#include "../mwmechanics/magiceffects.hpp" + #include "../mwworld/class.hpp" #include "inventoryitemmodel.hpp" @@ -211,12 +213,21 @@ namespace MWGui mItemView->update(); - std::vector effects; - ESM::EffectList list; - list.mList = effects; - for (MWMechanics::Alchemy::TEffectsIterator it = mAlchemy.beginEffects (); it != mAlchemy.endEffects (); ++it) + std::set effectIds = mAlchemy.listEffects(); + Widgets::SpellEffectList list; + for (std::set::iterator it = effectIds.begin(); it != effectIds.end(); ++it) { - list.mList.push_back(*it); + Widgets::SpellEffectParams params; + params.mEffectID = it->mId; + const ESM::MagicEffect* magicEffect = MWBase::Environment::get().getWorld()->getStore().get().find(it->mId); + if (magicEffect->mData.mFlags & ESM::MagicEffect::TargetSkill) + params.mSkill = it->mArg; + else if (magicEffect->mData.mFlags & ESM::MagicEffect::TargetAttribute) + params.mAttribute = it->mArg; + params.mIsConstant = true; + params.mNoTarget = true; + + list.push_back(params); } while (mEffectsBox->getChildCount()) @@ -226,8 +237,7 @@ namespace MWGui Widgets::MWEffectListPtr effectsWidget = mEffectsBox->createWidget ("MW_StatName", coord, MyGUI::Align::Left | MyGUI::Align::Top); - Widgets::SpellEffectList _list = Widgets::MWEffectList::effectListFromESM(&list); - effectsWidget->setEffectList(_list); + effectsWidget->setEffectList(list); std::vector effectItems; effectsWidget->createEffectWidgets(effectItems, mEffectsBox, coord, false, 0); diff --git a/apps/openmw/mwmechanics/alchemy.cpp b/apps/openmw/mwmechanics/alchemy.cpp index a097446a0..5b81dff61 100644 --- a/apps/openmw/mwmechanics/alchemy.cpp +++ b/apps/openmw/mwmechanics/alchemy.cpp @@ -306,6 +306,9 @@ float MWMechanics::Alchemy::getChance() const const CreatureStats& creatureStats = mAlchemist.getClass().getCreatureStats (mAlchemist); const NpcStats& npcStats = mAlchemist.getClass().getNpcStats (mAlchemist); + if (beginEffects() == endEffects()) + return 0.f; + return (npcStats.getSkill (ESM::Skill::Alchemy).getModified() + 0.1 * creatureStats.getAttribute (1).getModified() @@ -450,7 +453,7 @@ MWMechanics::Alchemy::Result MWMechanics::Alchemy::create (const std::string& na if (name.empty() && getPotionName().empty()) return Result_NoName; - if (beginEffects()==endEffects()) + if (listEffects().empty()) return Result_NoEffects; if (getChance() (RAND_MAX)*100) diff --git a/apps/openmw/mwmechanics/alchemy.hpp b/apps/openmw/mwmechanics/alchemy.hpp index 31cafa4dc..91e024574 100644 --- a/apps/openmw/mwmechanics/alchemy.hpp +++ b/apps/openmw/mwmechanics/alchemy.hpp @@ -50,15 +50,12 @@ namespace MWMechanics TEffectsContainer mEffects; int mValue; - std::set listEffects() const; - ///< List all effects shared by at least two ingredients. - void applyTools (int flags, float& value) const; void updateEffects(); const ESM::Potion *getRecord() const; - ///< Return existing recrod for created potion (may return 0) + ///< Return existing record for created potion (may return 0) void removeIngredients(); ///< Remove selected ingredients from alchemist's inventory, cleanup selected ingredients and @@ -75,6 +72,10 @@ namespace MWMechanics int countIngredients() const; + TEffectsIterator beginEffects() const; + + TEffectsIterator endEffects() const; + public: void setAlchemist (const MWWorld::Ptr& npc); @@ -94,6 +95,9 @@ namespace MWMechanics void clear(); ///< Remove alchemist, tools and ingredients. + std::set listEffects() const; + ///< List all effects shared by at least two ingredients. + int addIngredient (const MWWorld::Ptr& ingredient); ///< Add ingredient into the next free slot. /// @@ -103,10 +107,6 @@ namespace MWMechanics void removeIngredient (int index); ///< Remove ingredient from slot (calling this function on an empty slot is a no-op). - TEffectsIterator beginEffects() const; - - TEffectsIterator endEffects() const; - std::string getPotionName() const; ///< Return the name of the potion that would be created when calling create (if a record for such /// a potion already exists) or return an empty string.