OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
inventorystore.hpp
Go to the documentation of this file.
1 #ifndef GAME_MWWORLD_INVENTORYSTORE_H
2 #define GAME_MWWORLD_INVENTORYSTORE_H
3 
4 #include "containerstore.hpp"
5 
6 #include "../mwmechanics/magiceffects.hpp"
7 
8 namespace ESM
9 {
10  struct MagicEffect;
11 }
12 
13 namespace MWMechanics
14 {
15  class NpcStats;
16 }
17 
18 namespace MWWorld
19 {
21  {
22  public:
26  virtual void equipmentChanged () {}
27 
35  virtual void permanentEffectAdded (const ESM::MagicEffect *magicEffect, bool isNew) {}
36 
37  };
38 
41  {
42  public:
43 
44  static const int Slot_Helmet = 0;
45  static const int Slot_Cuirass = 1;
46  static const int Slot_Greaves = 2;
47  static const int Slot_LeftPauldron = 3;
48  static const int Slot_RightPauldron = 4;
49  static const int Slot_LeftGauntlet = 5;
50  static const int Slot_RightGauntlet = 6;
51  static const int Slot_Boots = 7;
52  static const int Slot_Shirt = 8;
53  static const int Slot_Pants = 9;
54  static const int Slot_Skirt = 10;
55  static const int Slot_Robe = 11;
56  static const int Slot_LeftRing = 12;
57  static const int Slot_RightRing = 13;
58  static const int Slot_Amulet = 14;
59  static const int Slot_Belt = 15;
60  static const int Slot_CarriedRight = 16;
61  static const int Slot_CarriedLeft = 17;
62  static const int Slot_Ammunition = 18;
63 
64  static const int Slots = 19;
65 
66  static const int Slot_NoSlot = -1;
67 
68  private:
69 
71 
73 
74  // Enables updates of magic effects and actor model whenever items are equipped or unequipped.
75  // This is disabled during autoequip to avoid excessive updates
77 
79 
80  // Vanilla allows permanent effects with a random magnitude, so it needs to be stored here.
81  // We also need this to only play sounds and particle effects when the item is equipped, rather than on every update.
82  struct EffectParams
83  {
84  // Modifier to scale between min and max magnitude
85  float mRandom;
86  // Multiplier for when an effect was fully or partially resisted
87  float mMultiplier;
88  };
89 
90  typedef std::map<std::string, std::vector<EffectParams> > TEffectMagnitudes;
92 
93  typedef std::vector<ContainerStoreIterator> TSlots;
94 
96 
97  // selected magic item (for using enchantments of type "Cast once" or "Cast when used")
99 
100  // (item, max charge)
101  typedef std::vector<std::pair<ContainerStoreIterator, float> > TRechargingItems;
103 
105 
106  void copySlots (const InventoryStore& store);
107 
108  void initSlots (TSlots& slots_);
109 
110  void updateMagicEffects(const Ptr& actor);
111  void updateRechargingItems();
112 
113  void fireEquipmentChangedEvent(const Ptr& actor);
114 
115  virtual void storeEquipmentState (const MWWorld::LiveCellRefBase& ref, int index, ESM::InventoryState& inventory) const;
116  virtual void readEquipmentState (const MWWorld::ContainerStoreIterator& iter, int index, const ESM::InventoryState& inventory);
117 
118  bool canActorAutoEquip(const MWWorld::Ptr& actor, const MWWorld::Ptr& item);
119 
120  public:
121 
122  InventoryStore();
123 
124  InventoryStore (const InventoryStore& store);
125 
127 
128  virtual InventoryStore* clone() { return new InventoryStore(*this); }
129 
130  virtual ContainerStoreIterator add (const Ptr& itemPtr, int count, const Ptr& actorPtr, bool setOwner=false);
142 
143  void equip (int slot, const ContainerStoreIterator& iterator, const Ptr& actor);
145 
146  bool isEquipped(const MWWorld::ConstPtr& item);
148 
149  void setSelectedEnchantItem(const ContainerStoreIterator& iterator);
152 
156 
157  ContainerStoreIterator getSlot (int slot);
158 
159  void unequipAll(const MWWorld::Ptr& actor);
161 
162  void autoEquip (const MWWorld::Ptr& actor);
164 
165  void autoEquipShield(const MWWorld::Ptr& actor);
167 
170 
171  virtual void flagAsModified();
174 
175  virtual bool stacks (const ConstPtr& ptr1, const ConstPtr& ptr2);
177 
178  virtual int remove(const Ptr& item, int count, const Ptr& actor);
182 
183  ContainerStoreIterator unequipSlot(int slot, const Ptr& actor);
187 
188  ContainerStoreIterator unequipItem(const Ptr& item, const Ptr& actor);
195 
196  ContainerStoreIterator unequipItemQuantity(const Ptr& item, const Ptr& actor, int count);
204 
205  void setInvListener (InventoryStoreListener* listener, const Ptr& actor);
207 
209 
211 
212  void rechargeItems (float duration);
214 
215  void purgeEffect (short effectId);
217 
218  void purgeEffect (short effectId, const std::string& sourceId);
220 
221  virtual void clear();
223 
224  virtual void writeState (ESM::InventoryState& state) const;
225 
226  virtual void readState (const ESM::InventoryState& state);
227  };
228 }
229 
230 #endif
Definition: magiceffects.hpp:73
Iteration over a subset of objects in a ContainerStore.
Definition: containerstore.hpp:196
static const int Slot_RightPauldron
Definition: inventorystore.hpp:48
static const int Slot_LeftPauldron
Definition: inventorystore.hpp:47
static const int Slot_NoSlot
Definition: inventorystore.hpp:66
virtual void equipmentChanged()
Definition: inventorystore.hpp:26
Used to create pointers to hold any type of LiveCellRef<> object.
Definition: livecellref.hpp:22
std::vector< std::pair< ContainerStoreIterator, float > > TRechargingItems
Definition: inventorystore.hpp:101
static const int Slot_Amulet
Definition: inventorystore.hpp:58
void initSlots(TSlots &slots_)
Definition: inventorystore.cpp:51
Effects currently affecting a NPC or creature.
Definition: magiceffects.hpp:83
TRechargingItems mRechargingItems
Definition: inventorystore.hpp:102
virtual void flagAsModified()
Definition: inventorystore.cpp:604
static const int Slots
Definition: inventorystore.hpp:64
virtual void writeState(ESM::InventoryState &state) const
Definition: inventorystore.cpp:949
static const int Slot_Boots
Definition: inventorystore.hpp:51
static const int Slot_CarriedRight
Definition: inventorystore.hpp:60
static const int Slot_RightRing
Definition: inventorystore.hpp:57
static const int Slot_Ammunition
Definition: inventorystore.hpp:62
ContainerStoreIterator unequipItemQuantity(const Ptr &item, const Ptr &actor, int count)
Definition: inventorystore.cpp:734
TEffectMagnitudes mPermanentMagicEffectMagnitudes
Definition: inventorystore.hpp:91
Definition: inventorystore.hpp:40
void updateRechargingItems()
Definition: inventorystore.cpp:826
static const int Slot_Helmet
Definition: inventorystore.hpp:44
bool mFirstAutoEquip
Definition: inventorystore.hpp:78
Definition: inventorystore.hpp:82
static const int Slot_LeftRing
Definition: inventorystore.hpp:56
TSlots mSlots
Definition: inventorystore.hpp:95
static const int Slot_LeftGauntlet
Definition: inventorystore.hpp:49
const MWMechanics::MagicEffects & getMagicEffects() const
Return magic effects from worn items.
Definition: inventorystore.cpp:486
float mRandom
Definition: inventorystore.hpp:85
virtual void storeEquipmentState(const MWWorld::LiveCellRefBase &ref, int index, ESM::InventoryState &inventory) const
Definition: inventorystore.cpp:57
void autoEquipShield(const MWWorld::Ptr &actor)
Auto-equip the shield with most health.
Definition: inventorystore.cpp:442
std::map< std::string, std::vector< EffectParams > > TEffectMagnitudes
Definition: inventorystore.hpp:90
void rechargeItems(float duration)
Restore charge on enchanted items. Note this should only be done for the player.
Definition: inventorystore.cpp:849
ContainerStoreIterator unequipSlot(int slot, const Ptr &actor)
Definition: inventorystore.cpp:681
static const int Slot_Belt
Definition: inventorystore.hpp:59
void purgeEffect(short effectId)
Remove a magic effect.
Definition: inventorystore.cpp:877
virtual InventoryStore * clone()
Definition: inventorystore.hpp:128
static const int Slot_Cuirass
Definition: inventorystore.hpp:45
InventoryStore & operator=(const InventoryStore &store)
Definition: inventorystore.cpp:123
virtual bool stacks(const ConstPtr &ptr1, const ConstPtr &ptr2)
Definition: inventorystore.cpp:610
Variant of the ContainerStore for NPCs.
Definition: inventorystore.hpp:20
void fireEquipmentChangedEvent(const Ptr &actor)
Definition: inventorystore.cpp:772
ContainerStoreIterator getSelectedEnchantItem()
Definition: inventorystore.cpp:636
virtual void permanentEffectAdded(const ESM::MagicEffect *magicEffect, bool isNew)
Definition: inventorystore.hpp:35
void autoEquip(const MWWorld::Ptr &actor)
Auto equip items according to stats and item value.
Definition: inventorystore.cpp:238
MWMechanics::MagicEffects mMagicEffects
Definition: inventorystore.hpp:70
bool isEquipped(const MWWorld::ConstPtr &item)
Utility function, returns true if the given item is equipped in any slot.
Definition: inventorystore.cpp:939
static const int Slot_RightGauntlet
Definition: inventorystore.hpp:50
InventoryStoreListener * getInvListener()
Definition: inventorystore.cpp:761
ContainerStoreIterator unequipItem(const Ptr &item, const Ptr &actor)
Definition: inventorystore.cpp:722
static const int Slot_Greaves
Definition: inventorystore.hpp:46
Pointer to a const LiveCellRef.
Definition: ptr.hpp:90
Definition: loadmgef.hpp:13
State for inventories and containers.
Definition: inventorystate.hpp:16
Definition: containerstore.hpp:41
virtual void readEquipmentState(const MWWorld::ContainerStoreIterator &iter, int index, const ESM::InventoryState &inventory)
Definition: inventorystore.cpp:69
bool mRechargingItemsUpToDate
Definition: inventorystore.hpp:104
ContainerStoreIterator getSlot(int slot)
Definition: inventorystore.cpp:200
std::vector< ContainerStoreIterator > TSlots
Definition: inventorystore.hpp:93
void setInvListener(InventoryStoreListener *listener, const Ptr &actor)
Set a listener for various events, see InventoryStoreListener.
Definition: inventorystore.cpp:766
void equip(int slot, const ContainerStoreIterator &iterator, const Ptr &actor)
Definition: inventorystore.cpp:152
virtual void readState(const ESM::InventoryState &state)
Definition: inventorystore.cpp:965
virtual ContainerStoreIterator add(const Ptr &itemPtr, int count, const Ptr &actorPtr, bool setOwner=false)
Definition: inventorystore.cpp:136
static const int Slot_Skirt
Definition: inventorystore.hpp:54
void setSelectedEnchantItem(const ContainerStoreIterator &iterator)
Definition: inventorystore.cpp:631
InventoryStore()
Definition: inventorystore.cpp:100
static const int Slot_Robe
Definition: inventorystore.hpp:55
void unequipAll(const MWWorld::Ptr &actor)
Unequip all currently equipped items.
Definition: inventorystore.cpp:188
ContainerStoreIterator mSelectedEnchantItem
Definition: inventorystore.hpp:98
InventoryStoreListener * mListener
Definition: inventorystore.hpp:72
Pointer to a LiveCellRef.
Definition: ptr.hpp:19
void copySlots(const InventoryStore &store)
Definition: inventorystore.cpp:26
bool canActorAutoEquip(const MWWorld::Ptr &actor, const MWWorld::Ptr &item)
Definition: inventorystore.cpp:218
static const int Slot_Shirt
Definition: inventorystore.hpp:52
float mMultiplier
Definition: inventorystore.hpp:87
virtual void clear()
Empty container.
Definition: inventorystore.cpp:932
void updateMagicEffects(const Ptr &actor)
Definition: inventorystore.cpp:491
void visitEffectSources(MWMechanics::EffectSourceVisitor &visitor)
Definition: inventorystore.cpp:788
static const int Slot_CarriedLeft
Definition: inventorystore.hpp:61
int count(const std::string &id)
Definition: containerstore.cpp:130
bool mUpdatesEnabled
Definition: inventorystore.hpp:76
static const int Slot_Pants
Definition: inventorystore.hpp:53