From fca3b6750793529b3ea08de33aa78d8b051a8466 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 13 Sep 2012 09:30:47 +0200 Subject: [PATCH] Issue #356: basic support for ingredients in ActiveSpells (still using the wrong formula) --- apps/openmw/mwmechanics/activespells.cpp | 49 ++++++++++++++++++------ apps/openmw/mwmechanics/activespells.hpp | 2 +- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/apps/openmw/mwmechanics/activespells.cpp b/apps/openmw/mwmechanics/activespells.cpp index 94b98d3be..5361a52c8 100644 --- a/apps/openmw/mwmechanics/activespells.cpp +++ b/apps/openmw/mwmechanics/activespells.cpp @@ -5,6 +5,8 @@ #include #include +#include +#include #include @@ -46,13 +48,13 @@ namespace MWMechanics for (TIterator iter (begin()); iter!=end(); ++iter) { - const ESM::EffectList& effects = getEffectList (iter->first); + std::pair effects = getEffectList (iter->first); const MWWorld::TimeStamp& start = iter->second.first; float magnitude = iter->second.second; - for (std::vector::const_iterator iter (effects.list.begin()); - iter!=effects.list.end(); ++iter) + for (std::vector::const_iterator iter (effects.first.list.begin()); + iter!=effects.first.list.end(); ++iter) { if (iter->duration) { @@ -73,15 +75,38 @@ namespace MWMechanics } } - const ESM::EffectList& ActiveSpells::getEffectList (const std::string& id) const + std::pair ActiveSpells::getEffectList (const std::string& id) const { if (const ESM::Spell *spell = MWBase::Environment::get().getWorld()->getStore().spells.search (id)) - return spell->effects; + return std::make_pair (spell->effects, false); if (const ESM::Potion *potion = MWBase::Environment::get().getWorld()->getStore().potions.search (id)) - return potion->effects; + return std::make_pair (potion->effects, false); + + if (const ESM::Ingredient *ingredient = + MWBase::Environment::get().getWorld()->getStore().ingreds.search (id)) + { + const ESM::MagicEffect *magicEffect = + MWBase::Environment::get().getWorld()->getStore().magicEffects.find ( + ingredient->data.effectID[0]); + + ESM::ENAMstruct effect; + effect.effectID = ingredient->data.effectID[0]; + effect.skill = ingredient->data.skills[0]; + effect.attribute = ingredient->data.attributes[0]; + effect.range = 0; + effect.area = 0; + effect.duration = magicEffect->data.flags & ESM::MagicEffect::NoDuration ? 0 : 1; + effect.magnMin = 0; + effect.magnMax = 0; + + std::pair result; + + result.first.list.push_back (effect); + result.second = true; + } throw std::runtime_error ("ID " + id + " can not produce lasting effects"); } @@ -92,12 +117,12 @@ namespace MWMechanics bool ActiveSpells::addSpell (const std::string& id) { - const ESM::EffectList& effects = getEffectList (id); + std::pair effects = getEffectList (id); bool found = false; - for (std::vector::const_iterator iter (effects.list.begin()); - iter!=effects.list.end(); ++iter) + for (std::vector::const_iterator iter (effects.first.list.begin()); + iter!=effects.first.list.end(); ++iter) { if (iter->duration) { @@ -155,12 +180,12 @@ namespace MWMechanics double ActiveSpells::timeToExpire (const TIterator& iterator) const { - const ESM::EffectList& effects = getEffectList (iterator->first); + std::pair effects = getEffectList (iterator->first); int duration = 0; - for (std::vector::const_iterator iter (effects.list.begin()); - iter!=effects.list.end(); ++iter) + for (std::vector::const_iterator iter (effects.first.list.begin()); + iter!=effects.first.list.end(); ++iter) { if (iter->duration>duration) duration = iter->duration; diff --git a/apps/openmw/mwmechanics/activespells.hpp b/apps/openmw/mwmechanics/activespells.hpp index 2226cea84..6a1205bfb 100644 --- a/apps/openmw/mwmechanics/activespells.hpp +++ b/apps/openmw/mwmechanics/activespells.hpp @@ -37,7 +37,7 @@ namespace MWMechanics void update() const; - const ESM::EffectList& getEffectList (const std::string& id) const; + std::pair getEffectList (const std::string& id) const; public: