From d7add0b9e679c1a7db6c2df0a288fc2bdafac083 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 28 Oct 2012 14:07:36 +0100 Subject: [PATCH] Issue #61: fixed alchemy skill --- apps/openmw/mwmechanics/alchemy.cpp | 62 +++++++---------------------- apps/openmw/mwmechanics/alchemy.hpp | 5 +-- 2 files changed, 15 insertions(+), 52 deletions(-) diff --git a/apps/openmw/mwmechanics/alchemy.cpp b/apps/openmw/mwmechanics/alchemy.cpp index df7c786b1e..962350472e 100644 --- a/apps/openmw/mwmechanics/alchemy.cpp +++ b/apps/openmw/mwmechanics/alchemy.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -28,7 +29,7 @@ std::set MWMechanics::Alchemy::listEffects() const { - std::set effects; + std::map effects; for (TIngredientsIterator iter (mIngredients.begin()); iter!=mIngredients.end(); ++iter) { @@ -38,57 +39,23 @@ std::set MWMechanics::Alchemy::listEffects() const for (int i=0; i<4; ++i) if (ingredient->base->mData.mEffectID[i]!=-1) - effects.insert (EffectKey ( + { + EffectKey key ( ingredient->base->mData.mEffectID[i], ingredient->base->mData.mSkills[i]!=-1 ? - ingredient->base->mData.mSkills[i] : ingredient->base->mData.mAttributes[i])); + ingredient->base->mData.mSkills[i] : ingredient->base->mData.mAttributes[i]); + + ++effects[key]; + } } } - return effects; -} - -void MWMechanics::Alchemy::filterEffects (std::set& effects) const -{ - std::set::iterator iter = effects.begin(); + std::set effects2; - while (iter!=effects.end()) - { - bool remove = false; - - const EffectKey& key = *iter; - - { // dodge pointless g++ warning - for (TIngredientsIterator iter (mIngredients.begin()); iter!=mIngredients.end(); ++iter) - { - bool found = false; - - if (iter->isEmpty()) - continue; - - const MWWorld::LiveCellRef *ingredient = iter->get(); - - for (int i=0; i<4; ++i) - if (key.mId==ingredient->base->mData.mEffectID[i] && - (key.mArg==ingredient->base->mData.mSkills[i] || - key.mArg==ingredient->base->mData.mAttributes[i])) - { - found = true; - break; - } - - if (!found) - { - remove = true; - break; - } - } - } - - if (remove) - effects.erase (iter++); - else - ++iter; - } + for (std::map::const_iterator iter (effects.begin()); iter!=effects.end(); ++iter) + if (iter->second>1) + effects2.insert (iter->first); + + return effects2; } void MWMechanics::Alchemy::applyTools (int flags, float& value) const @@ -159,7 +126,6 @@ void MWMechanics::Alchemy::updateEffects() // find effects std::set effects (listEffects()); - filterEffects (effects); // general alchemy factor float x = getChance(); diff --git a/apps/openmw/mwmechanics/alchemy.hpp b/apps/openmw/mwmechanics/alchemy.hpp index 7f3e2c0eaa..957e3122c7 100644 --- a/apps/openmw/mwmechanics/alchemy.hpp +++ b/apps/openmw/mwmechanics/alchemy.hpp @@ -46,10 +46,7 @@ namespace MWMechanics int mValue; std::set listEffects() const; - ///< List all effects of all used ingredients. - - void filterEffects (std::set& effects) const; - ///< Filter out effects not shared by all ingredients. + ///< List all effects shared by at least two ingredients. void applyTools (int flags, float& value) const;