]> git.localhorst.tv Git - l2e.git/blob - src/common/Inventory.h
implemented item dropping
[l2e.git] / src / common / Inventory.h
1 /*
2  * Inventory.h
3  *
4  *  Created on: Aug 9, 2012
5  *      Author: holy
6  */
7
8 #ifndef COMMON_INVENTORY_H_
9 #define COMMON_INVENTORY_H_
10
11 #include "fwd.h"
12
13 #include <SDL.h>
14
15 namespace common {
16
17 class Inventory {
18
19 public:
20         Inventory();
21
22 public:
23         bool Add(const Item *, int count = 1);
24         void Remove(const Item *, int count = 1);
25         void RemoveAll(const Item *);
26
27         int MaxItems() const { return 96; }
28
29         const Item *ItemAt(int offset) const { return entries[offset].item; }
30         int ItemCountAt(int offset) const { return entries[offset].count; }
31
32         void Sort();
33         void SwapEntriesAt(int lhs, int rhs);
34
35 private:
36         struct Entry {
37                 Entry() : item(0), count(0) { }
38                 const Item *item;
39                 Uint8 count;
40                 static bool Less(const Entry &, const Entry &);
41         };
42
43 private:
44         Entry *FindItem(const Item *);
45         const Entry *FindItem(const Item *) const;
46         bool SloteFree(int offset) const;
47
48 private:
49         Entry entries[96];
50
51 };
52
53 }
54
55 #endif /* COMMON_INVENTORY_H_ */