]> git.localhorst.tv Git - l2e.git/blob - src/common/Inventory.h
added Sort function to Inventory
[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
33 private:
34         struct Entry {
35                 Entry() : item(0), count(0) { }
36                 const Item *item;
37                 Uint8 count;
38                 static bool Less(const Entry &, const Entry &);
39         };
40
41 private:
42         Entry *FindItem(const Item *);
43         const Entry *FindItem(const Item *) const;
44         bool SloteFree(int offset) const;
45
46 private:
47         Entry entries[96];
48
49 };
50
51 }
52
53 #endif /* COMMON_INVENTORY_H_ */