-
Notifications
You must be signed in to change notification settings - Fork 26
/
inventory.h
190 lines (154 loc) · 3.68 KB
/
inventory.h
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#pragma once
struct ItemProto;
struct Item;
extern const ItemProto* item_proto_lib;
Item* CreateItem();
void DestroyItem(Item* item);
struct Inventory
{
// max inventory dims as 4x4 cells blocks (incl. 1 border)
static const int width = 8; // fit upto 4 7x7 cells items - do not modify!!!
static const int height = 20; // fit upto 10 7x7 cells items
static const int max_items = width*height; // please clamp to 100 items
bool animate_scroll;
int scroll, smooth_scroll;
int focus;
// layout
int layout_width;
int layout_height;
int layout_max_height;
int layout_max_scroll;
int layout_reps[3];
int layout_x;
int layout_y;
int layout_frame[4];
// free space lookup accelerator
uint8_t bitmask[(max_items+7)/8];
struct MyItem
{
Item* item;
int xy[2];
int story_id;
bool in_use;
};
int my_items;
MyItem my_item[max_items];
void UpdateLayout(int width, int height, int scene_shift);
bool InsertItem(Item* item, int xy[2]);
bool RemoveItem(int index, float pos[3], float yaw);
void FocusNext(int dx, int dy);
void SetFocus(int index);
};
struct ItemProto // loaded from items.txt file
{
int kind; // 'W'eapon, 'S'hield, 'H'elmet, 'A'rmor, 'R'ing, ...
int sub_kind; // (ie: for kind=='W' sub_kind==1 is sword, for kind=='P' sub_kind==1 is hp_potion )
// use command:
// will check for kind=W/S/H/A and we have player-sprite with given sub_kind (currently only 0/1)
// other wearables like 'R'ing 'B'race 'N'ecklace are just accepted (no player-sprite is required)
// for consumables 'C' it will destroy item
int weight;
// pointer to pointer, so we can have const static ItemProto array and load sprites later
Sprite* sprite_3d;
Sprite* sprite_2d; // if null item cannot be picked up
const char* desc;
// extras ?
// ...
};
struct Item
{
const ItemProto* proto;
Inst* inst; // EDIT / WORLD : instance (OWNED has it NULL)
int count;
// item instances:
// - if process is editor: private items for editor (saved/loaded with a3d file)
// - items for players (just 1 clone from a3d items for all players execpt below)
// - items created for each player inventory individually (if a3d item has seed flag)
enum PURPOSE
{
// when created, item purpose is unspecified
UNSPECIFIED = 0,
// EDITOR / FILE only,
// render in editor only
// note: loding world by game (without editor) will switch it immediately to WORLD
// loading by editor will make this item clone (with WORLD , available to test-players)
// item must be attached to BHV (for editor)
EDIT = 1,
// game item, inside someone's inventory
// dont't render in game (owner's inventory only)
// item must be detached from BHV (travels with player) inst=0
OWNED = 2, // not savable
// game item, no owner, render it in game for all players
// item must be attached to BHV (for players)
WORLD = 3, // not savable
};
// note: changing purpose may need adjusting World::insts counter!
PURPOSE purpose;
};
enum PLAYER_WEAPON_INDEX
{
WEAPON_NONE = 0,
SWORD,
CROSSBOW,
// --------
MACE,
HAMMER, // big ace too
AXE, // only lumber
FLAIL,
};
enum PLAYER_SHIELD_INDEX
{
SHIELD_NONE = 0,
SHIELD_NORMAL,
};
enum PLAYER_HELMET_INDEX
{
HELMET_NONE = 0,
// -----------
HELMET_NORMAL,
};
enum PLAYER_ARMOR_INDEX
{
ARMOR_NONE = 0,
// -----------
ARMOR_NORMAL,
};
enum PLAYER_FOOD_INDEX
{
FOOD_NONE = 0,
MEAT,
EGG,
CHEESE,
BREAD,
BEET,
CUCUMBER,
CARROT,
APPLE,
CHERRY,
PLUM,
};
enum PLAYER_DRINK_INDEX
{
DRINK_NONE = 0,
MILK,
WATER,
WINE
};
enum PLAYER_POTION_INDEX
{
POTION_NONE = 0,
POTION_RED, // HP
POTION_BLUE, // MP
POTION_GREEN,
POTION_PINK,
POTION_CYAN,
POTION_GOLD,
POTION_GREY
};
enum PLAYER_RING_INDEX
{
RING_WHITE,
RING_CYAN,
RING_GOLD,
RING_PINK
};