GBAlatro
A Demake of Balatro for the GBA
Loading...
Searching...
No Matches
item.h
Go to the documentation of this file.
1
11#ifndef ITEM_H
12#define ITEM_H
13
14#include "mgba_logger.h"
15#include "random.h"
16#include "sprite.h"
17
18// TODO: Merge these with GBAL_RETURN_IF_NULL macros?
25#define ITEM_RETURN_IF_UNEXPECTED_TYPE_RET(item, expected_type, ret_val) \
26 do \
27 { \
28 if ((item)->type != expected_type) \
29 { \
30 MGBA_FUNC_ERROR("Unexpected %s->type != %s", #item, #expected_type); \
31 return (ret_val); \
32 } \
33 } while (0)
34
41#define ITEM_RETURN_IF_UNEXPECTED_TYPE_VOID(item, expected_type) \
42 do \
43 { \
44 if ((item)->type != expected_type) \
45 { \
46 MGBA_FUNC_ERROR("Unexpected %s->type != %s", #item, #expected_type); \
47 return; \
48 } \
49 } while (0)
50
51enum ItemType
52{
53 ITEM_TYPE_JOKER,
54 ITEM_TYPE_PLAYING_CARD,
55
56 // Future planned item types
57 // ITEM_TYPE_CONSUMABLE, // Expand to PLANET, TAROT, and SPECTRAL?
58 // ITEM_TYPE_VOUCHER,
59 // ITEM_TYPE_PACK
60
61 ITEM_NUM_TYPES
62};
63
75typedef struct Item
76{
83
87 enum ItemType type;
89
93typedef struct ItemFuncs
94{
99 Item* (*roll_new)(enum RngSequence key);
100 int (*get_buy_price)(Item* item);
101 bool (*can_acquire)(Item* item);
102 void (*acquire)(Item* item);
103 void (*dispose)(Item** item);
104 // TODO: void (*print_description)(Item* item); // or something of the form
105
106 // Optional implementation functions will be added here
108
121Item* item_roll_new(enum ItemType item_type, enum RngSequence key);
122
132int item_get_buy_price(Item* item);
133
146void item_acquire(Item* item);
147
157bool item_can_acquire(Item* item);
158
165void item_dispose(Item** item);
166
174
175#endif // ITEM_H
void item_dispose(Item **item)
Destroys an item, freeing underlying resources, and manages rollable items sets if needed....
Definition item.c:56
void item_print_buy_price_under(Item *item)
Prints the buy price under the item Relies on the fact item is a SpriteObject.
Definition item.c:67
Item * item_roll_new(enum ItemType item_type, enum RngSequence key)
Rolls a random item of type item_type and returns a newly created one. Manages rollable items set if ...
Definition item.c:9
bool item_can_acquire(Item *item)
Returns true if the item can be acquired, i.e. added to inventory. Does not check if the player has e...
Definition item.c:46
void item_acquire(Item *item)
Acquires the item, adding to inventory if applicable. Called when it is purchased from the shop,...
Definition item.c:35
int item_get_buy_price(Item *item)
Returns the buy price of the item.
Definition item.c:24
Interface to interact with the mgba logger.
Common functions to handle RNG manipulation. Using this interface has three goals:
RngSequence
Keys to different independent RNG sequences.
Definition random.h:19
Sprite system for Gbalatro.
The set of functions that each item type implements.
Definition item.h:94
A generic interface for all items that can appear in the shop or be in the inventory....
Definition item.h:76
SpriteObject
First member struct inheritance all items that can appear in the shop are SpriteObjects....
Definition item.h:82
enum ItemType type
The item type - used to dispatch the function implementations for inheriting types.
Definition item.h:87