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