ManaPlus
inventory.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef RESOURCES_INVENTORY_INVENTORY_H
25 #define RESOURCES_INVENTORY_INVENTORY_H
26 
27 #include "enums/inventorytype.h"
28 
30 
38 
39 #include "enums/being/gender.h"
40 
41 #include "utils/intmap.h"
42 
43 #include <list>
44 #include <string>
45 
46 #include "localconsts.h"
47 
48 class InventoryListener;
49 class Item;
50 
51 struct ItemOptionsList;
52 
54 {
55  public:
57 
58  static const int NO_SLOT_INDEX = -1;
65  Inventory(const InventoryTypeT type,
66  const int size);
67 
71  virtual ~Inventory();
72 
76  unsigned getSize() const noexcept2 A_WARN_UNUSED
77  { return mSize; }
78 
82  Item *getItem(const int index) const A_WARN_UNUSED;
83 
91  Item *findItem(const int itemId,
92  const ItemColor color) const A_WARN_UNUSED;
93 
97  int addItem(const int id,
98  const ItemTypeT type,
99  const int quantity,
100  const uint8_t refine,
101  const ItemColor color,
102  const Identified identified,
103  const Damaged damaged,
104  const Favorite favorite,
105  const Equipm equipment,
106  const Equipped equipped);
107 
111  virtual void setItem(const int index,
112  const int id,
113  const ItemTypeT type,
114  const int quantity,
115  const uint8_t refine,
116  const ItemColor color,
117  const Identified identified,
118  const Damaged damaged,
119  const Favorite favorite,
120  const Equipm equipment,
121  const Equipped equipped);
122 
123  void setCards(const int index,
124  const int *const cards,
125  const int size) const;
126 
127  void setOptions(const int index,
128  const ItemOptionsList *const options);
129 
130  void setTag(const int index,
131  const int tag);
132 
133  void moveItem(const int index1,
134  const int index2);
135 
139  void removeItem(const int id);
140 
144  void removeItemAt(const int index);
145 
149  bool contains(const Item *const item) const A_WARN_UNUSED;
150 
154  int getFreeSlot() const A_WARN_UNUSED;
155 
159  void clear();
160 
165  { return mUsed; }
166 
170  int getLastUsedSlot() const A_WARN_UNUSED;
171 
173 
175 
177  { return mType; }
178 
180  { return mType == InventoryType::Inventory; }
181 
182  const Item *findItemBySprite(std::string spritePath,
183  const GenderT gender,
184  const BeingTypeId race)
185  const A_WARN_UNUSED;
186 
187  std::string getName() const A_WARN_UNUSED;
188 
189  void resize(const unsigned int newSize);
190 
191  int findIndexByTag(const int tag) const;
192 
193  Item *findItemByTag(const int tag) const;
194 
195  virtual bool addVirtualItem(const Item *const item,
196  int index,
197  const int amount);
198 
199  void virtualRemove(Item *const item,
200  const int amount);
201 
202  void virtualRestore(const Item *const item,
203  const int amount);
204 
205  void restoreVirtuals();
206 
207  protected:
210 
212 
215  unsigned mSize;
217  int mUsed;
218 };
219 
220 #endif // RESOURCES_INVENTORY_INVENTORY_H
int BeingTypeId
Definition: beingtypeid.h:30
void virtualRemove(Item *const item, const int amount)
Definition: inventory.cpp:485
unsigned mSize
Definition: inventory.h:215
void setCards(const int index, const int *const cards, const int size) const
Definition: inventory.cpp:194
int findIndexByTag(const int tag) const
Definition: inventory.cpp:412
void clear()
Definition: inventory.cpp:238
void removeItemAt(const int index)
Definition: inventory.cpp:254
Item * getItem(const int index) const
Definition: inventory.cpp:83
unsigned getSize() const
Definition: inventory.h:76
bool isMainInventory() const
Definition: inventory.h:179
void setTag(const int index, const int tag)
Definition: inventory.cpp:224
virtual bool addVirtualItem(const Item *const item, int index, const int amount)
Definition: inventory.cpp:439
int mUsed
Definition: inventory.h:217
void distributeSlotsChangedEvent()
Definition: inventory.cpp:312
const Item * findItemBySprite(std::string spritePath, const GenderT gender, const BeingTypeId race) const
Definition: inventory.cpp:318
Item * findItemByTag(const int tag) const
Definition: inventory.cpp:424
bool contains(const Item *const item) const
Definition: inventory.cpp:266
void setOptions(const int index, const ItemOptionsList *const options)
Definition: inventory.cpp:210
void moveItem(const int index1, const int index2)
Definition: inventory.cpp:537
Item * findItem(const int itemId, const ItemColor color) const
Definition: inventory.cpp:94
int getLastUsedSlot() const
Definition: inventory.cpp:291
void restoreVirtuals()
Definition: inventory.cpp:500
std::string getName() const
Definition: inventory.cpp:351
IntMap mVirtualRemove
Definition: inventory.h:213
static const int NO_SLOT_INDEX
Definition: inventory.h:58
int addItem(const int id, const ItemTypeT type, const int quantity, const uint8_t refine, const ItemColor color, const Identified identified, const Damaged damaged, const Favorite favorite, const Equipm equipment, const Equipped equipped)
Definition: inventory.cpp:115
InventoryTypeT getType() const
Definition: inventory.h:176
InventoryTypeT mType
Definition: inventory.h:214
InventoryListenerList mInventoryListeners
Definition: inventory.h:209
virtual void setItem(const int index, const int id, const ItemTypeT type, const int quantity, const uint8_t refine, const ItemColor color, const Identified identified, const Damaged damaged, const Favorite favorite, const Equipm equipment, const Equipped equipped)
Definition: inventory.cpp:141
Item ** mItems
Definition: inventory.h:216
void removeInventoyListener(InventoryListener *const listener)
Definition: inventory.cpp:307
void resize(const unsigned int newSize)
Definition: inventory.cpp:397
void virtualRestore(const Item *const item, const int amount)
Definition: inventory.cpp:517
std::list< InventoryListener * > InventoryListenerList
Definition: inventory.h:208
int getFreeSlot() const
Definition: inventory.cpp:282
void removeItem(const int id)
Definition: inventory.cpp:244
void addInventoyListener(InventoryListener *const listener)
Definition: inventory.cpp:302
int getNumberOfSlotsUsed() const
Definition: inventory.h:164
Definition: item.h:50
bool Damaged
Definition: damaged.h:30
bool Equipm
Definition: equipm.h:30
bool Equipped
Definition: equipped.h:30
bool Favorite
Definition: favorite.h:30
Gender ::T GenderT
Definition: gender.h:35
bool Identified
Definition: identified.h:30
std::map< int, int > IntMap
Definition: intmap.h:27
InventoryType ::T InventoryTypeT
Definition: inventorytype.h:42
uint16_t ItemColor
Definition: itemcolor.h:30
ItemType ::T ItemTypeT
Definition: itemtype.h:43
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define notfinal
Definition: localconsts.h:261
#define noexcept2
Definition: localconsts.h:50
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
int size()
Definition: emotedb.cpp:306