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

146 {
147 s32 idx;
148
149 // handle key items
150 if (item_is_key(itemID)) {
151 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.keyItems); idx++) {
152 if (gPlayerData.keyItems[idx] == ITEM_NONE) {
153 break;
154 }
155 }
156
157 if (idx >= ARRAY_COUNT(gPlayerData.keyItems)) {
158 return -1;
159 }
160
161 gPlayerData.keyItems[idx] = itemID;
162 return idx;
163 }
164
165 // handle badges
166 if (item_is_badge(itemID)) {
167 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.badges); idx++) {
168 if (gPlayerData.badges[idx] == ITEM_NONE) {
169 break;
170 }
171 }
172
173 if (idx >= ARRAY_COUNT(gPlayerData.badges)) {
174 return -1;
175 }
176
177 gPlayerData.badges[idx] = itemID;
178 return idx;
179 }
180
181 // handle consumables
183
184 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.invItems); idx++) {
185 if (gPlayerData.invItems[idx] == ITEM_NONE) {
186 break;
187 }
188 }
189
190 if (idx == ARRAY_COUNT(gPlayerData.invItems)) {
191 return -1;
192 }
193
194 gPlayerData.invItems[idx] = itemID;
195 return idx;
196}
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:404
#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 198 of file inventory.c.

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

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

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

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

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

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

◆ is_badge_equipped()

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

Definition at line 387 of file inventory.c.

387 {
388 s32 idx;
389
390 if (!item_is_badge(itemID)) {
391 return FALSE;
392 }
393
394 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.equippedBadges); idx++) {
395 if (gPlayerData.equippedBadges[idx] == itemID) {
396 return TRUE;
397 }
398 }
399
400 return FALSE;
401}

◆ get_consumables_count()

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

Definition at line 423 of file inventory.c.

423 {
424 s32 idx;
425 s32 sum = 0;
426
427 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.invItems); idx++) {
428 if (gPlayerData.invItems[idx] != ITEM_NONE) {
429 sum++;
430 }
431 }
432
433 return sum;
434}

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

436 {
438}
s32 get_consumables_count(void)
Definition inventory.c:423

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

369 {
370 s32 idx;
371
372 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.storedItems); idx++) {
373 if (gPlayerData.storedItems[idx] == ITEM_NONE) {
374 break;
375 }
376 }
377
378 if (idx == ARRAY_COUNT(gPlayerData.storedItems)) {
379 return -1;
380 } else {
381 gPlayerData.storedItems[idx] = itemID;
382 }
383
384 return idx;
385}
s16 storedItems[32]

◆ get_stored_count()

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

Definition at line 440 of file inventory.c.

440 {
441 s32 idx;
442 s32 sum = 0;
443
444 for (idx = 0; idx < ARRAY_COUNT(gPlayerData.storedItems); idx++) {
445 if (gPlayerData.storedItems[idx] != ITEM_NONE) {
446 sum++;
447 }
448 }
449
450 return sum;
451}

Referenced by get_stored_empty().

◆ get_stored_empty()

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

Definition at line 453 of file inventory.c.

453 {
455}
s32 get_stored_count(void)
Definition inventory.c:440

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

2175 {
2176 if (amt == -2) {
2179 } else if (amt == -1) {
2181 } else {
2182 if (amt > 0) {
2183 gPlayerData.curHP += amt;
2184 }
2187 }
2188 }
2189 return gPlayerData.curHP;
2190}

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

2158 {
2159 if (amt == -2) {
2162 } else if (amt == -1) {
2164 } else {
2165 if (amt > 0) {
2166 gPlayerData.curFP += amt;
2167 }
2170 }
2171 }
2172 return gPlayerData.curFP;
2173}

Referenced by entity_HeartBlockContent__anim_heal().