OpenMW
apps/openmw/mwmechanics/magiceffects.hpp
Go to the documentation of this file.
00001 #ifndef GAME_MWMECHANICS_MAGICEFFECTS_H
00002 #define GAME_MWMECHANICS_MAGICEFFECTS_H
00003 
00004 #include <map>
00005 #include <string>
00006 
00007 namespace ESM
00008 {
00009     struct ENAMstruct;
00010     struct EffectList;
00011 }
00012 
00013 namespace MWMechanics
00014 {
00015     struct EffectKey
00016     {
00017         int mId;
00018         int mArg; // skill or ability
00019 
00020         EffectKey();
00021 
00022         EffectKey (int id, int arg = -1) : mId (id), mArg (arg) {}
00023 
00024         EffectKey (const ESM::ENAMstruct& effect);
00025     };
00026 
00027     bool operator< (const EffectKey& left, const EffectKey& right);
00028 
00029     struct EffectParam
00030     {
00031         // Note usually this would be int, but applying partial resistance might introduce decimal point.
00032         float mMagnitude;
00033 
00034         EffectParam();
00035 
00036         EffectParam(float magnitude) : mMagnitude(magnitude) {}
00037 
00038         EffectParam& operator+= (const EffectParam& param);
00039 
00040         EffectParam& operator-= (const EffectParam& param);
00041     };
00042 
00043     inline EffectParam operator+ (const EffectParam& left, const EffectParam& right)
00044     {
00045         EffectParam param (left);
00046         return param += right;
00047     }
00048 
00049     inline EffectParam operator- (const EffectParam& left, const EffectParam& right)
00050     {
00051         EffectParam param (left);
00052         return param -= right;
00053     }
00054 
00055     // Used by effect management classes (ActiveSpells, InventoryStore, Spells) to list active effect sources for GUI display
00056     struct EffectSourceVisitor
00057     {
00058         virtual void visit (MWMechanics::EffectKey key,
00059                                  const std::string& sourceName, float magnitude, float remainingTime = -1) = 0;
00060     };
00061 
00063     class MagicEffects
00064     {
00065         public:
00066 
00067             typedef std::map<EffectKey, EffectParam> Collection;
00068 
00069         private:
00070 
00071             Collection mCollection;
00072 
00073         public:
00074 
00075             Collection::const_iterator begin() const { return mCollection.begin(); }
00076 
00077             Collection::const_iterator end() const { return mCollection.end(); }
00078 
00079             void add (const EffectKey& key, const EffectParam& param);
00080 
00081             MagicEffects& operator+= (const MagicEffects& effects);
00082 
00083             EffectParam get (const EffectKey& key) const;
00085 
00086             static MagicEffects diff (const MagicEffects& prev, const MagicEffects& now);
00088     };
00089 }
00090 
00091 #endif