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