From 5236bcb557923406edf234dbb3c4bb3a3d39f46e Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Fri, 18 May 2012 15:12:11 +0200 Subject: [PATCH] Issue #256: added operator+= for MagicEffects --- apps/openmw/mwmechanics/magiceffects.cpp | 24 ++++++++++++++++++++++++ apps/openmw/mwmechanics/magiceffects.hpp | 2 ++ 2 files changed, 26 insertions(+) diff --git a/apps/openmw/mwmechanics/magiceffects.cpp b/apps/openmw/mwmechanics/magiceffects.cpp index 52811084f..41d898ca8 100644 --- a/apps/openmw/mwmechanics/magiceffects.cpp +++ b/apps/openmw/mwmechanics/magiceffects.cpp @@ -85,6 +85,30 @@ namespace MWMechanics } } + MagicEffects& MagicEffects::operator+= (const MagicEffects& effects) + { + if (this==&effects) + { + MagicEffects temp (effects); + *this += temp; + return *this; + } + + for (Collection::const_iterator iter (effects.Begin()); iter!=effects.End(); ++iter) + { + Collection::iterator result = mCollection.find (iter->first); + + if (result!=mCollection.end()) + { + result->second.mMagnitude += iter->second.mMagnitude; + } + else + mCollection.insert (*iter); + } + + return *this; + } + EffectParam MagicEffects::get (const EffectKey& key) const { Collection::const_iterator iter = mCollection.find (key); diff --git a/apps/openmw/mwmechanics/magiceffects.hpp b/apps/openmw/mwmechanics/magiceffects.hpp index d47101d45..26f78ec8a 100644 --- a/apps/openmw/mwmechanics/magiceffects.hpp +++ b/apps/openmw/mwmechanics/magiceffects.hpp @@ -69,6 +69,8 @@ namespace MWMechanics void add (const ESM::EffectList& list); + MagicEffects& operator+= (const MagicEffects& effects); + EffectParam get (const EffectKey& key) const; ///< This function can safely be used for keys that are not present.