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 "graphic_utils.h"
15#include "mgba_logger.h"
16#include "random.h"
17#include "sprite.h"
18#include "util.h"
19
20#include <stdint.h>
21
22enum ItemType
23{
24 ITEM_TYPE_JOKER,
25 ITEM_TYPE_PLAYING_CARD,
26
27 // Future planned item types
28 // ITEM_TYPE_CONSUMABLE, // Expand to PLANET, TAROT, and SPECTRAL?
29 // ITEM_TYPE_VOUCHER,
30 // ITEM_TYPE_PACK
31
32 ITEM_NUM_TYPES
33};
34
38#define ITEM_NAME_UNDEFINED "UNDEFINED"
39
43// clang-format off
44#define ITEM_SUBTYPE_INFO_DEFAULT {.main_color = 0, .shadow_color = 0, .name_str = ITEM_NAME_UNDEFINED}
45// clang-format on
46
64typedef struct ItemDescSubtypeInfo
65{
66 u16 main_color;
67 u16 shadow_color;
68 const char* name_str;
70
82typedef struct Item
83{
90
94 enum ItemType type;
95
102
106typedef struct ItemFuncs
107{
112 Item* (*roll_new)(enum RngSequence key);
113 int (*get_buy_price)(Item* item);
114 const char* (*get_name)(Item* item);
115 ItemDescSubtypeInfo (*get_subtype_info)(Item* item);
116 bool (*can_acquire)(Item* item);
117 void (*acquire)(Item* item);
118 void (*dispose)(Item** item);
119 int (*print_description)(Item* item, Rect dest_rect);
120
121 // Optional implementation functions - not required to appear in the shop
122 int (*get_sell_price)(Item* item);
124
137Item* item_roll_new(enum ItemType item_type, enum RngSequence key);
138
148int item_get_buy_price(Item* item);
149
159int item_get_sell_price(Item* item);
160
170const char* item_get_name(Item* item);
171
185
198void item_acquire(Item* item);
199
209bool item_can_acquire(Item* item);
210
219void item_dispose(Item** item);
220
231int item_print_description(Item* item, Rect dest_rect);
232
240bool item_is_owned(Item* item);
241
246void item_sell(Item* item);
247
255
256#endif // ITEM_H
Graphic utility functions.
bool item_is_owned(Item *item)
Returns whether or not the given Item is in the player's possession.
Definition item.c:179
int item_get_sell_price(Item *item)
Returns the sell price of the item.
Definition item.c:52
void item_dispose(Item **item)
Destroys an item, freeing underlying resources, and manages rollable items sets if needed....
Definition item.c:147
const char * item_get_name(Item *item)
Returns the name of the Item.
Definition item.c:70
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:203
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:11
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:133
ItemDescSubtypeInfo item_get_subtype_info(Item *item)
Returns the colors and name of the Item's subtype.
Definition item.c:89
void item_acquire(Item *item)
Acquires the item, adding to inventory if applicable. Called when it is purchased from the shop,...
Definition item.c:116
void item_sell(Item *item)
Performs the item sell transaction, gaining its sell value and discarding it.
Definition item.c:185
int item_print_description(Item *item, Rect dest_rect)
Prints the item's description inside the given rectangle.
Definition item.c:162
int item_get_buy_price(Item *item)
Returns the buy price of the item.
Definition item.c:34
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.
Structure containing the main and shadow colors, and the name string associated with an Item's subtyp...
Definition item.h:65
The set of functions that each item type implements.
Definition item.h:107
A generic interface for all items that can appear in the shop or be in the inventory....
Definition item.h:83
SpriteObject
First member struct inheritance all items that can appear in the shop are SpriteObjects....
Definition item.h:89
enum ItemType type
The item type - used to dispatch the function implementations for inheriting types.
Definition item.h:94
bool is_owned
Whether the item is currently held - used in cases where a behaviour needs to be different for Items ...
Definition item.h:100
Utilities relating around number string representation and protected arithmatic helper functions.