#include "magiceffects.hpp" #include #include namespace MWMechanics { EffectKey::EffectKey() : mId (0), mArg (-1) {} EffectKey::EffectKey (const ESM::ENAMstruct& effect) { mId = effect.effectID; mArg = -1; if (effect.skill!=-1) mArg = effect.skill; if (effect.attribute!=-1) { if (mArg!=-1) throw std::runtime_error ( "magic effect can't have both a skill and an attribute argument"); mArg = effect.attribute; } } bool operator< (const EffectKey& left, const EffectKey& right) { if (left.mIdright.mId) return false; return left.mArgsecond += param; } } MagicEffects MagicEffects::diff (const MagicEffects& prev, const MagicEffects& now) { MagicEffects result; // adding/changing for (Collection::const_iterator iter (now.Begin()); iter!=now.End(); ++iter) { Collection::const_iterator other = prev.mCollection.find (iter->first); if (other==prev.End()) { // adding result.add (iter->first, iter->second); } else { // changing result.add (iter->first, iter->second - other->second); } } // removing for (Collection::const_iterator iter (prev.Begin()); iter!=prev.End(); ++iter) { Collection::const_iterator other = now.mCollection.find (iter->first); if (other==prev.End()) { result.add (iter->first, EffectParam() - iter->second); } } return result; } }