Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
inventory.h File Reference

Go to the source code of this file.

Functions

s32 add_item (s32 itemID)
 Add itemID to player inventory and return inventory slot in which it was placed.
 
s32 remove_item (s32 itemID)
 Remove first instance of itemID found in player inventory.
 
b32 has_item (s32 itemID)
 Check whether player has itemID in their inventory.
 
s32 find_item (s32 itemID)
 Search player inventory for itemID and return first matching array index.
 
s32 count_item (s32 itemID)
 Search player inventory for itemID and count the number matches.
 
b32 is_badge_equipped (s32 itemID)
 
s32 get_consumables_count (void)
 
s32 get_consumables_empty (void)
 
s32 store_item (s32 itemID)
 Add itemID to player storage and return slot in which it was placed.
 
s32 get_stored_count (void)
 
s32 get_stored_empty (void)
 
s32 recover_hp (s32 amt)
 Recover player HP.
 
s32 recover_fp (s32 amt)
 Recover player FP.
 

Function Documentation

◆ add_item()

s32 add_item ( s32 itemID)

Add itemID to player inventory and return inventory slot in which it was placed.

Returns
the index of the new item in the player's inventory, or -1 if there was no room

Definition at line 151 of file inventory.c.

151 {
152 s32 idx;
153
154 // handle key items
155 if (item_is_key(itemID)) {
156 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.keyItems); idx++) {
158 break;
159 }
160 }
161
163 return -1;
164 }
165
166 gPlayerData.keyItems[idx] = itemID;
167 return idx;
168 }
169
170 // handle badges
171 if (item_is_badge(itemID)) {
172 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.badges); idx++) {
174 break;
175 }
176 }
177
179 return -1;
180 }
181
182 gPlayerData.badges[idx] = itemID;
183 return idx;
184 }
185
186 // handle consumables
188
189 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.invItems); idx++) {
191 break;
192 }
193 }
194
196 return -1;
197 }
198
199 gPlayerData.invItems[idx] = itemID;
200 return idx;
201}
BSS s32 PopupMenu_SelectedIndex
s16 badges[128]
s16 keyItems[32]
s16 invItems[10]
void sort_consumables(void)
Bubbles up player inventory items such that all ITEM_NONE values are at the bottom.
Definition inventory.c:409
#define ARRAY_COUNT(arr)
Definition macros.h:40
PlayerData gPlayerData
Definition 77480.c:39

Referenced by update_item_entity_pickup().

◆ remove_item()

s32 remove_item ( s32 itemID)

Remove first instance of itemID found in player inventory.

Returns
the index of the removed item in the player's inventory, or -1 none was found

Definition at line 203 of file inventory.c.

203 {
204 s32 idx;
205
206 // handle key items
207 if (item_is_key(itemID)) {
208 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.keyItems); idx++) {
209 if (gPlayerData.keyItems[idx] == itemID) {
210 break;
211 }
212 }
213
215 return -1;
216 }
217
219 return idx;
220 }
221
222 // handle badges
223 if (item_is_badge(itemID)) {
224 // unequip
226 if (gPlayerData.equippedBadges[idx] == itemID) {
228 }
229 }
230
231 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.badges); idx++) {
232 if (gPlayerData.badges[idx] == itemID) {
233 break;
234 }
235 }
236
238 return -1;
239 }
240
242 return idx;
243 }
244
245 // handle consumables
246 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.invItems); idx++) {
247 if (gPlayerData.invItems[idx] == itemID) {
248 break;
249 }
250 }
251
253 return -1;
254 }
255
258 return idx;
259}
s16 equippedBadges[64]

◆ has_item()

b32 has_item ( s32 itemID)

Check whether player has itemID in their inventory.

Returns
boolean 'does player have item?'

Definition at line 342 of file inventory.c.

342 {
343 s32 idx;
344
345 // handle key items
346 if (item_is_key(itemID)) {
347 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.keyItems); idx++) {
348 if (gPlayerData.keyItems[idx] == itemID) {
349 return TRUE;
350 }
351 }
352 return FALSE;
353 }
354
355 // handle badges
356 if (item_is_badge(itemID)) {
357 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.badges); idx++) {
358 if (gPlayerData.badges[idx] == itemID) {
359 return TRUE;
360 }
361 }
362 return FALSE;
363 }
364
365 // handle consumables
366 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.invItems); idx++) {
367 if (gPlayerData.invItems[idx] == itemID) {
368 return TRUE;
369 }
370 }
371 return FALSE;
372}

◆ find_item()

s32 find_item ( s32 itemID)

Search player inventory for itemID and return first matching array index.

Returns
the index of the given item in the player's inventory, or -1 if not found

Definition at line 263 of file inventory.c.

263 {
264 s32 idx;
265
266 // handle key items
267 if (item_is_key(itemID)) {
268 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.keyItems); idx++) {
269 if (gPlayerData.keyItems[idx] == itemID) {
270 break;
271 }
272 }
273
275 return -1;
276 }
277 return idx;
278 }
279
280 // handle badges
281 if (item_is_badge(itemID)) {
282 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.badges); idx++) {
283 if (gPlayerData.badges[idx] == itemID) {
284 break;
285 }
286 }
287
289 return -1;
290 }
291 return idx;
292 }
293
294 // handle consumables
295 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.invItems); idx++) {
296 if (gPlayerData.invItems[idx] == itemID) {
297 break;
298 }
299 }
300
302 return -1;
303 }
304 return idx;
305}

◆ count_item()

s32 count_item ( s32 itemID)

Search player inventory for itemID and count the number matches.

Returns
the number of items matching itemID

Definition at line 309 of file inventory.c.

309 {
310 s32 idx;
311 s32 sum = 0;
312
313 // handle key items
314 if (item_is_key(itemID)) {
315 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.keyItems); idx++) {
316 if (gPlayerData.keyItems[idx] == itemID) {
317 sum++;
318 }
319 }
320 return sum;
321 }
322
323 // handle badges
324 if (item_is_badge(itemID)) {
325 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.badges); idx++) {
326 if (gPlayerData.badges[idx] == itemID) {
327 sum++;
328 }
329 }
330 return sum;
331 }
332
333 // handle consumables
334 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.invItems); idx++) {
335 if (gPlayerData.invItems[idx] == itemID) {
336 sum++;
337 }
338 }
339 return sum;
340}

◆ is_badge_equipped()

b32 is_badge_equipped ( s32 itemID)
Returns
whether the player has itemID as an equipped badge

Definition at line 392 of file inventory.c.

392 {
393 s32 idx;
394
395 if (!item_is_badge(itemID)) {
396 return FALSE;
397 }
398
400 if (gPlayerData.equippedBadges[idx] == itemID) {
401 return TRUE;
402 }
403 }
404
405 return FALSE;
406}

◆ get_consumables_count()

s32 get_consumables_count ( void )
Returns
the number of consumables in player inventory

Definition at line 428 of file inventory.c.

428 {
429 s32 idx;
430 s32 sum = 0;
431
432 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.invItems); idx++) {
434 sum++;
435 }
436 }
437
438 return sum;
439}

Referenced by get_consumables_empty().

◆ get_consumables_empty()

s32 get_consumables_empty ( void )
Returns
the available room for consumables in player inventory

Definition at line 441 of file inventory.c.

441 {
443}
s32 get_consumables_count(void)
Definition inventory.c:428

◆ store_item()

s32 store_item ( s32 itemID)

Add itemID to player storage and return slot in which it was placed.

Returns
the index of the new item in player storage, or -1 if there was no room

Definition at line 374 of file inventory.c.

374 {
375 s32 idx;
376
377 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.storedItems); idx++) {
379 break;
380 }
381 }
382
384 return -1;
385 } else {
386 gPlayerData.storedItems[idx] = itemID;
387 }
388
389 return idx;
390}
s16 storedItems[32]

◆ get_stored_count()

s32 get_stored_count ( void )
Returns
the number of consumables in player storage

Definition at line 445 of file inventory.c.

445 {
446 s32 idx;
447 s32 sum = 0;
448
449 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.storedItems); idx++) {
451 sum++;
452 }
453 }
454
455 return sum;
456}

Referenced by get_stored_empty().

◆ get_stored_empty()

s32 get_stored_empty ( void )
Returns
the available room in player storage

Definition at line 458 of file inventory.c.

458 {
460}
s32 get_stored_count(void)
Definition inventory.c:445

◆ recover_hp()

s32 recover_hp ( s32 amt)

Recover player HP.

Parameters
amtthe amount to recover, -1 for full, -2 for full and increase max by 1 (unused)
Returns
the new HP value, after recovery has been applied

Definition at line 2186 of file inventory.c.

2186 {
2187 if (amt == -2) {
2190 } else if (amt == -1) {
2192 } else {
2193 if (amt > 0) {
2195 }
2198 }
2199 }
2200 return gPlayerData.curHP;
2201}

Referenced by entity_HeartBlockContent__anim_heal().

◆ recover_fp()

s32 recover_fp ( s32 amt)

Recover player FP.

Parameters
amtthe amount to recover, -1 for full, -2 for full and increase max by 1 (unused)
Returns
the new FP value, after recovery has been applied

Definition at line 2169 of file inventory.c.

2169 {
2170 if (amt == -2) {
2173 } else if (amt == -1) {
2175 } else {
2176 if (amt > 0) {
2178 }
2181 }
2182 }
2183 return gPlayerData.curFP;
2184}

Referenced by entity_HeartBlockContent__anim_heal().