From 654cd3ab9bef7aad11a8c5e3a55a26d4100065cc Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 13 Jan 2013 14:52:55 +0100 Subject: [PATCH] Issue #479: Use magnitude specified when adding disease --- apps/openmw/mwmechanics/magiceffects.cpp | 10 +++++++--- apps/openmw/mwmechanics/magiceffects.hpp | 3 ++- apps/openmw/mwmechanics/spells.cpp | 13 +++++-------- apps/openmw/mwmechanics/spells.hpp | 4 +--- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/apps/openmw/mwmechanics/magiceffects.cpp b/apps/openmw/mwmechanics/magiceffects.cpp index 94363cb79..1a7b34817 100644 --- a/apps/openmw/mwmechanics/magiceffects.cpp +++ b/apps/openmw/mwmechanics/magiceffects.cpp @@ -68,7 +68,7 @@ namespace MWMechanics } } - void MagicEffects::add (const ESM::EffectList& list) + void MagicEffects::add (const ESM::EffectList& list, float magnitude) { for (std::vector::const_iterator iter (list.mList.begin()); iter!=list.mList.end(); ++iter) @@ -78,9 +78,13 @@ namespace MWMechanics if (iter->mMagnMin>=iter->mMagnMax) param.mMagnitude = iter->mMagnMin; else + { + if (magnitude==-1) + magnitude = static_cast (std::rand()) / RAND_MAX; + param.mMagnitude = static_cast ( - (iter->mMagnMax-iter->mMagnMin+1)* - (static_cast (std::rand()) / RAND_MAX) + iter->mMagnMin); + (iter->mMagnMax-iter->mMagnMin+1)*magnitude + iter->mMagnMin); + } add (*iter, param); } diff --git a/apps/openmw/mwmechanics/magiceffects.hpp b/apps/openmw/mwmechanics/magiceffects.hpp index 2f61d7eeb..b80b5a863 100644 --- a/apps/openmw/mwmechanics/magiceffects.hpp +++ b/apps/openmw/mwmechanics/magiceffects.hpp @@ -67,7 +67,8 @@ namespace MWMechanics void add (const EffectKey& key, const EffectParam& param); - void add (const ESM::EffectList& list); + void add (const ESM::EffectList& list, float magnitude = -1); + ///< \param magnitude normalised magnitude (-1: random) MagicEffects& operator+= (const MagicEffects& effects); diff --git a/apps/openmw/mwmechanics/spells.cpp b/apps/openmw/mwmechanics/spells.cpp index 32acca2f0..e2da7cdc8 100644 --- a/apps/openmw/mwmechanics/spells.cpp +++ b/apps/openmw/mwmechanics/spells.cpp @@ -1,22 +1,19 @@ #include "spells.hpp" -#include "../mwworld/esmstore.hpp" +#include #include #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" +#include "../mwworld/esmstore.hpp" + #include "magiceffects.hpp" namespace MWMechanics { - void Spells::addSpell (const ESM::Spell *spell, MagicEffects& effects) const - { - effects.add (spell->mEffects); - } - Spells::TIterator Spells::begin() const { return mSpells.begin(); @@ -30,7 +27,7 @@ namespace MWMechanics void Spells::add (const std::string& spellId) { if (mSpells.find (spellId)==mSpells.end()) - mSpells.insert (std::make_pair (spellId, -1)); + mSpells.insert (std::make_pair (spellId, static_cast (std::rand()) / RAND_MAX)); } void Spells::remove (const std::string& spellId) @@ -55,7 +52,7 @@ namespace MWMechanics if (spell->mData.mType==ESM::Spell::ST_Ability || spell->mData.mType==ESM::Spell::ST_Blight || spell->mData.mType==ESM::Spell::ST_Disease || spell->mData.mType==ESM::Spell::ST_Curse) - addSpell (spell, effects); + effects.add (spell->mEffects, iter->second); } return effects; diff --git a/apps/openmw/mwmechanics/spells.hpp b/apps/openmw/mwmechanics/spells.hpp index b4d058896..e00ac259f 100644 --- a/apps/openmw/mwmechanics/spells.hpp +++ b/apps/openmw/mwmechanics/spells.hpp @@ -21,7 +21,7 @@ namespace MWMechanics { public: - typedef std::map TContainer; // ID, magnitude + typedef std::map TContainer; // ID, normalised magnitude typedef TContainer::const_iterator TIterator; private: @@ -29,8 +29,6 @@ namespace MWMechanics TContainer mSpells; std::string mSelectedSpell; - void addSpell (const ESM::Spell *, MagicEffects& effects) const; - public: TIterator begin() const;