]> git.localhorst.tv Git - l2e.git/blob - src/common/Inventory.h
5e21721d5d1a0804bd5186ef1d2952d2668a80d7
[l2e.git] / src / common / Inventory.h
1 #ifndef COMMON_INVENTORY_H_
2 #define COMMON_INVENTORY_H_
3
4 namespace common {
5         class Item;
6 }
7
8 #include <SDL.h>
9
10 namespace common {
11
12 class Inventory {
13
14 public:
15         Inventory();
16
17 public:
18         bool Add(const Item *, int count = 1);
19         void Remove(const Item *, int count = 1);
20         void RemoveAll(const Item *);
21
22         int MaxItems() const { return 96; }
23
24         bool AddScenarioItem(const Item *);
25         const Item *ScenarioItemAt(int offset) const { return scenario[offset]; }
26         int NumScenarioItems() const { return scenarioEnd; }
27         int MaxScenarioItems() const { return 64; }
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         const Item *scenario[64];
51         int scenarioEnd;
52
53 };
54
55 }
56
57 #endif /* COMMON_INVENTORY_H_ */