]> git.localhorst.tv Git - l2e.git/blob - src/common/Inventory.h
implemented inventory item swapping
[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
26         int MaxItems() const { return 96; }
27
28         const Item *ItemAt(int offset) const { return entries[offset].item; }
29         int ItemCountAt(int offset) const { return entries[offset].count; }
30
31         void Sort();
32         void SwapEntriesAt(int lhs, int rhs);
33
34 private:
35         struct Entry {
36                 Entry() : item(0), count(0) { }
37                 const Item *item;
38                 Uint8 count;
39                 static bool Less(const Entry &, const Entry &);
40         };
41
42 private:
43         Entry *FindItem(const Item *);
44         const Entry *FindItem(const Item *) const;
45         bool SloteFree(int offset) const;
46
47 private:
48         Entry entries[96];
49
50 };
51
52 }
53
54 #endif /* COMMON_INVENTORY_H_ */