OpenMW
apps/openmw/mwmechanics/activespells.hpp
Go to the documentation of this file.
00001 #ifndef GAME_MWMECHANICS_ACTIVESPELLS_H
00002 #define GAME_MWMECHANICS_ACTIVESPELLS_H
00003 
00004 #include <map>
00005 #include <vector>
00006 #include <string>
00007 
00008 #include "../mwworld/timestamp.hpp"
00009 
00010 #include "magiceffects.hpp"
00011 
00012 #include <components/esm/defs.hpp>
00013 
00014 namespace MWMechanics
00015 {
00020     class ActiveSpells
00021     {
00022         public:
00023 
00024             // Parameters of an effect concerning lasting effects.
00025             // Note we are not using ENAMstruct since the magnitude may be modified by magic resistance, etc.
00026             // It could also be a negative magnitude, in case of inversing an effect, e.g. Absorb spell causes damage on target, but heals the caster.
00027             struct Effect
00028             {
00029                 float mMagnitude;
00030                 EffectKey mKey;
00031                 float mDuration;
00032             };
00033 
00034             struct ActiveSpellParams
00035             {
00036                 std::vector<Effect> mEffects;
00037                 MWWorld::TimeStamp mTimeStamp;
00038                 std::string mDisplayName;
00039 
00040                 // TODO: To handle CASTER_LINKED flag (spell is purged when caster dies),
00041                 // we should probably store a handle to the caster here.
00042             };
00043 
00044             typedef std::multimap<std::string, ActiveSpellParams > TContainer;
00045             typedef TContainer::const_iterator TIterator;
00046 
00047         private:
00048 
00049             mutable TContainer mSpells;
00050             mutable MagicEffects mEffects;
00051             mutable bool mSpellsChanged;
00052             mutable MWWorld::TimeStamp mLastUpdate;
00053 
00054             void update() const;
00055             
00056             void rebuildEffects() const;
00057 
00058             double timeToExpire (const TIterator& iterator) const;
00061 
00062             const TContainer& getActiveSpells() const;
00063 
00064             TIterator begin() const;
00065 
00066             TIterator end() const;
00067 
00068         public:
00069 
00070             ActiveSpells();
00071 
00080             void addSpell (const std::string& id, bool stack, std::vector<Effect> effects, const std::string& displayName);
00081 
00083             void purgeEffect (short effectId);
00084 
00086             void purgeAll (float chance);
00087 
00088             bool isSpellActive (std::string id) const;
00090 
00091             const MagicEffects& getMagicEffects() const;
00092 
00093             void visitEffectSources (MWMechanics::EffectSourceVisitor& visitor) const;
00094 
00095     };
00096 }
00097 
00098 #endif