OpenMW
apps/openmw/mwworld/inventorystore.hpp
Go to the documentation of this file.
00001 #ifndef GAME_MWWORLD_INVENTORYSTORE_H
00002 #define GAME_MWWORLD_INVENTORYSTORE_H
00003 
00004 #include "containerstore.hpp"
00005 
00006 #include "../mwmechanics/magiceffects.hpp"
00007 
00008 namespace MWMechanics
00009 {
00010     class NpcStats;
00011 }
00012 
00013 namespace MWWorld
00014 {
00015     class InventoryStoreListener
00016     {
00017     public:
00021         virtual void equipmentChanged () {}
00022 
00030         virtual void permanentEffectAdded (const ESM::MagicEffect *magicEffect, bool isNew, bool playSound) {}
00031 
00032     };
00033 
00035     class InventoryStore : public ContainerStore
00036     {
00037         public:
00038 
00039             static const int Slot_Helmet = 0;
00040             static const int Slot_Cuirass = 1;
00041             static const int Slot_Greaves = 2;
00042             static const int Slot_LeftPauldron = 3;
00043             static const int Slot_RightPauldron = 4;
00044             static const int Slot_LeftGauntlet = 5;
00045             static const int Slot_RightGauntlet = 6;
00046             static const int Slot_Boots = 7;
00047             static const int Slot_Shirt = 8;
00048             static const int Slot_Pants = 9;
00049             static const int Slot_Skirt = 10;
00050             static const int Slot_Robe = 11;
00051             static const int Slot_LeftRing = 12;
00052             static const int Slot_RightRing = 13;
00053             static const int Slot_Amulet = 14;
00054             static const int Slot_Belt = 15;
00055             static const int Slot_CarriedRight = 16;
00056             static const int Slot_CarriedLeft = 17;
00057             static const int Slot_Ammunition = 18;
00058 
00059             static const int Slots = 19;
00060 
00061             static const int Slot_NoSlot = -1;
00062 
00063         private:
00064 
00065             MWMechanics::MagicEffects mMagicEffects;
00066 
00067             InventoryStoreListener* mListener;
00068 
00069             // Enables updates of magic effects and actor model whenever items are equipped or unequipped.
00070             // This is disabled during autoequip to avoid excessive updates
00071             bool mUpdatesEnabled;
00072 
00073             bool mFirstAutoEquip;
00074 
00075             // Vanilla allows permanent effects with a random magnitude, so it needs to be stored here.
00076             // We also need this to only play sounds and particle effects when the item is equipped, rather than on every update.
00077             struct EffectParams
00078             {
00079                 // Modifier to scale between min and max magnitude
00080                 float mRandom;
00081                 // Multiplier for when an effect was fully or partially resisted
00082                 float mMultiplier;
00083             };
00084 
00085             typedef std::map<std::string, std::vector<EffectParams> > TEffectMagnitudes;
00086             TEffectMagnitudes mPermanentMagicEffectMagnitudes;
00087 
00088             typedef std::vector<ContainerStoreIterator> TSlots;
00089 
00090             TSlots mSlots;
00091 
00092             // selected magic item (for using enchantments of type "Cast once" or "Cast when used")
00093             ContainerStoreIterator mSelectedEnchantItem;
00094 
00095             // (item, max charge)
00096             typedef std::vector<std::pair<ContainerStoreIterator, float> > TRechargingItems;
00097             TRechargingItems mRechargingItems;
00098 
00099             void copySlots (const InventoryStore& store);
00100 
00101             void initSlots (TSlots& slots_);
00102 
00103             void updateMagicEffects(const Ptr& actor);
00104             void updateRechargingItems();
00105 
00106             void fireEquipmentChangedEvent();
00107 
00108         public:
00109 
00110             InventoryStore();
00111 
00112             InventoryStore (const InventoryStore& store);
00113 
00114             InventoryStore& operator= (const InventoryStore& store);
00115 
00116             virtual ContainerStoreIterator add (const Ptr& itemPtr, const Ptr& actorPtr);
00126 
00127             void equip (int slot, const ContainerStoreIterator& iterator, const Ptr& actor);
00129 
00130             void setSelectedEnchantItem(const ContainerStoreIterator& iterator);
00133 
00134             ContainerStoreIterator getSelectedEnchantItem();
00137 
00138             ContainerStoreIterator getSlot (int slot);
00139 
00140             void unequipAll(const MWWorld::Ptr& actor);
00142 
00143             void autoEquip (const MWWorld::Ptr& actor);
00145 
00146             const MWMechanics::MagicEffects& getMagicEffects() const;
00148 
00149             virtual void flagAsModified();
00152 
00153             virtual bool stacks (const Ptr& ptr1, const Ptr& ptr2);
00155 
00156             virtual int remove(const Ptr& item, int count, const Ptr& actor);
00160 
00161             ContainerStoreIterator unequipSlot(int slot, const Ptr& actor, bool restack = true);
00167 
00168             ContainerStoreIterator unequipItem(const Ptr& item, const Ptr& actor);
00175 
00176             void setListener (InventoryStoreListener* listener, const Ptr& actor);
00178 
00179             void visitEffectSources (MWMechanics::EffectSourceVisitor& visitor);
00180 
00181             void rechargeItems (float duration);
00183 
00184             void purgeEffect (short effectId);
00186     };
00187 }
00188 
00189 #endif