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