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 152 of file inventory.c.

152 {
153 s32 idx;
154
155 // handle key items
156 if (item_is_key(itemID)) {
157 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.keyItems); idx++) {
158 if (gPlayerData.keyItems[idx] == ITEM_NONE) {
159 break;
160 }
161 }
162
163 if (idx >= ARRAY_COUNT(gPlayerData.keyItems)) {
164 return -1;
165 }
166
167 gPlayerData.keyItems[idx] = itemID;
168 return idx;
169 }
170
171 // handle badges
172 if (item_is_badge(itemID)) {
173 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.badges); idx++) {
174 if (gPlayerData.badges[idx] == ITEM_NONE) {
175 break;
176 }
177 }
178
179 if (idx >= ARRAY_COUNT(gPlayerData.badges)) {
180 return -1;
181 }
182
183 gPlayerData.badges[idx] = itemID;
184 return idx;
185 }
186
187 // handle consumables
189
190 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.invItems); idx++) {
191 if (gPlayerData.invItems[idx] == ITEM_NONE) {
192 break;
193 }
194 }
195
196 if (idx == ARRAY_COUNT(gPlayerData.invItems)) {
197 return -1;
198 }
199
200 gPlayerData.invItems[idx] = itemID;
201 return idx;
202}
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:410
#define ARRAY_COUNT(arr)
Definition macros.h:40
PlayerData gPlayerData
Definition 77480.c:40

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 204 of file inventory.c.

204 {
205 s32 idx;
206
207 // handle key items
208 if (item_is_key(itemID)) {
209 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.keyItems); idx++) {
210 if (gPlayerData.keyItems[idx] == itemID) {
211 break;
212 }
213 }
214
215 if (idx >= ARRAY_COUNT(gPlayerData.keyItems)) {
216 return -1;
217 }
218
219 gPlayerData.keyItems[idx] = ITEM_NONE;
220 return idx;
221 }
222
223 // handle badges
224 if (item_is_badge(itemID)) {
225 // unequip
226 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.equippedBadges); idx++) {
227 if (gPlayerData.equippedBadges[idx] == itemID) {
228 gPlayerData.equippedBadges[idx] = ITEM_NONE;
229 }
230 }
231
232 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.badges); idx++) {
233 if (gPlayerData.badges[idx] == itemID) {
234 break;
235 }
236 }
237
238 if (idx >= ARRAY_COUNT(gPlayerData.badges)) {
239 return -1;
240 }
241
242 gPlayerData.badges[idx] = ITEM_NONE;
243 return idx;
244 }
245
246 // handle consumables
247 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.invItems); idx++) {
248 if (gPlayerData.invItems[idx] == itemID) {
249 break;
250 }
251 }
252
253 if (idx == ARRAY_COUNT(gPlayerData.invItems)) {
254 return -1;
255 }
256
257 gPlayerData.invItems[idx] = ITEM_NONE;
259 return idx;
260}
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 343 of file inventory.c.

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

◆ 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 264 of file inventory.c.

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

◆ 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 310 of file inventory.c.

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

◆ is_badge_equipped()

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

Definition at line 393 of file inventory.c.

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

◆ get_consumables_count()

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

Definition at line 429 of file inventory.c.

429 {
430 s32 idx;
431 s32 sum = 0;
432
433 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.invItems); idx++) {
434 if (gPlayerData.invItems[idx] != ITEM_NONE) {
435 sum++;
436 }
437 }
438
439 return sum;
440}

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 442 of file inventory.c.

442 {
444}
s32 get_consumables_count(void)
Definition inventory.c:429

◆ 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 375 of file inventory.c.

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

◆ get_stored_count()

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

Definition at line 446 of file inventory.c.

446 {
447 s32 idx;
448 s32 sum = 0;
449
450 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.storedItems); idx++) {
451 if (gPlayerData.storedItems[idx] != ITEM_NONE) {
452 sum++;
453 }
454 }
455
456 return sum;
457}

Referenced by get_stored_empty().

◆ get_stored_empty()

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

Definition at line 459 of file inventory.c.

459 {
461}
s32 get_stored_count(void)
Definition inventory.c:446

◆ 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 2187 of file inventory.c.

2187 {
2188 if (amt == -2) {
2191 } else if (amt == -1) {
2193 } else {
2194 if (amt > 0) {
2195 gPlayerData.curHP += amt;
2196 }
2199 }
2200 }
2201 return gPlayerData.curHP;
2202}

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 2170 of file inventory.c.

2170 {
2171 if (amt == -2) {
2174 } else if (amt == -1) {
2176 } else {
2177 if (amt > 0) {
2178 gPlayerData.curFP += amt;
2179 }
2182 }
2183 }
2184 return gPlayerData.curFP;
2185}

Referenced by entity_HeartBlockContent__anim_heal().