Issue #61: fixed alchemy skill

This commit is contained in:
Marc Zinnschlag 2012-10-28 14:07:36 +01:00
parent c635447cea
commit d7add0b9e6
2 changed files with 15 additions and 52 deletions

View file

@ -6,6 +6,7 @@
#include <algorithm> #include <algorithm>
#include <stdexcept> #include <stdexcept>
#include <map>
#include <components/esm/loadskil.hpp> #include <components/esm/loadskil.hpp>
#include <components/esm/loadappa.hpp> #include <components/esm/loadappa.hpp>
@ -28,7 +29,7 @@
std::set<MWMechanics::EffectKey> MWMechanics::Alchemy::listEffects() const std::set<MWMechanics::EffectKey> MWMechanics::Alchemy::listEffects() const
{ {
std::set<EffectKey> effects; std::map<EffectKey, int> effects;
for (TIngredientsIterator iter (mIngredients.begin()); iter!=mIngredients.end(); ++iter) for (TIngredientsIterator iter (mIngredients.begin()); iter!=mIngredients.end(); ++iter)
{ {
@ -38,57 +39,23 @@ std::set<MWMechanics::EffectKey> MWMechanics::Alchemy::listEffects() const
for (int i=0; i<4; ++i) for (int i=0; i<4; ++i)
if (ingredient->base->mData.mEffectID[i]!=-1) 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.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; std::set<EffectKey> effects2;
}
void MWMechanics::Alchemy::filterEffects (std::set<EffectKey>& effects) const
{
std::set<EffectKey>::iterator iter = effects.begin();
while (iter!=effects.end()) for (std::map<EffectKey, int>::const_iterator iter (effects.begin()); iter!=effects.end(); ++iter)
{ if (iter->second>1)
bool remove = false; effects2.insert (iter->first);
const EffectKey& key = *iter; return effects2;
{ // dodge pointless g++ warning
for (TIngredientsIterator iter (mIngredients.begin()); iter!=mIngredients.end(); ++iter)
{
bool found = false;
if (iter->isEmpty())
continue;
const MWWorld::LiveCellRef<ESM::Ingredient> *ingredient = iter->get<ESM::Ingredient>();
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;
}
} }
void MWMechanics::Alchemy::applyTools (int flags, float& value) const void MWMechanics::Alchemy::applyTools (int flags, float& value) const
@ -159,7 +126,6 @@ void MWMechanics::Alchemy::updateEffects()
// find effects // find effects
std::set<EffectKey> effects (listEffects()); std::set<EffectKey> effects (listEffects());
filterEffects (effects);
// general alchemy factor // general alchemy factor
float x = getChance(); float x = getChance();

View file

@ -46,10 +46,7 @@ namespace MWMechanics
int mValue; int mValue;
std::set<EffectKey> listEffects() const; std::set<EffectKey> listEffects() const;
///< List all effects of all used ingredients. ///< List all effects shared by at least two ingredients.
void filterEffects (std::set<EffectKey>& effects) const;
///< Filter out effects not shared by all ingredients.
void applyTools (int flags, float& value) const; void applyTools (int flags, float& value) const;