aboutsummaryrefslogtreecommitdiffstats
path: root/include/inventory.h
blob: b035f91d6e693d69bc22a78715de7f332d4e3c20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#ifndef INVENTORY_H
#define INVENTORY_H

#include <common.h>
#include <string.h>

#define DEBUG

#define ID 			Item(
#define NAME 		,
#define TYPE 		,
#define WIDTH 		,
#define HEIGHT 		,
#define STACKSIZE 	,
#define TEX 		,
#define ENI 		),
#define STOP		)

/*
 * A list of all item IDs.
*/

enum ITEM_ID {
	DEBUG_ITEM = 0,
	TEST_ITEM = 1,
	PLAYER_BAG = 2,
	FLASHLIGHT = 3,
	SWORD_WOOD = 4
};

enum ITEM_TYPE{
	TOOL = 1,
	SWORD = 2,
	RANGED = 3,
	EQUIP = 4,
	FOOD = 5
};

class Item{
protected:
public:
	ITEM_ID id;				// ID of the item
	char *name;
	ITEM_TYPE type;			// What category the item falls under
	float width;
	float height;
	int maxStackSize;
	char* textureLoc;
	Texturec *tex;
	GLuint text;

	Item(ITEM_ID i, const char *n, ITEM_TYPE t, float w, float h, int m, const char *tl);
	GLuint rtex(){
		return tex->image[0];
	}
};

struct item_t{
	int count;
	ITEM_ID id;
} __attribute__((packed));

typedef struct {
	unsigned int size;
	int os;
	unsigned int sel;
} __attribute__ ((packed)) InventorySavePacket;

class Inventory {
private:
	unsigned int size;		// Size of 'item' array
	item_t *inv;
	int os = 0;
public:
	unsigned int sel;
	bool invOpen = false;
	bool invOpening = false;
	bool invHover = false;
	bool selected = false;
	bool mouseSel = false;
	bool usingi = false;

	Inventory(unsigned int s);	// Creates an inventory of size 's'
	~Inventory(void);			// Free's allocated memory
	
	int addItem(ITEM_ID id,unsigned char count);	// Add 'count' items with an id of 'id' to the inventory
	int takeItem(ITEM_ID id,unsigned char count);	// Take 'count' items with an id of 'id' from the inventory
	int useItem(void);
	bool detectCollision(vec2,vec2);
	
	void setSelection(unsigned int s);
	
	void draw(void);	// Draws a text list of items in this inventory (should only be called for the player for now)
	
	char *save(void){
		static InventorySavePacket *isp = new InventorySavePacket();
		isp->size = size;
		isp->os = os;
		isp->sel = sel;
		return (char *)isp;
	}
	void load(InventorySavePacket *isp){
		size = isp->size;
		os = isp->os;
		sel = isp->sel;
	}
};

void itemUse(void *p);
void initInventorySprites(void);
char *getItemTexturePath(ITEM_ID id);
int getItemWidth(ITEM_ID);
int getItemHeight(ITEM_ID);

#endif // INVENTORY_H