GBAlatro
A Demake of Balatro for the GBA
Loading...
Searching...
No Matches
item_funcs.c
1#include "item_funcs.h"
2
3#include "card.h"
4#include "game.h"
5#include "game/shop.h"
6#include "joker.h"
7#include "util.h"
8
9static bool item_always_can_acquire(Item* item);
10
11// clang-format off
12ItemFuncs item_func_table[] = {
13 [ITEM_TYPE_JOKER] = {
15 .get_buy_price = joker_object_get_buy_price,
16 .get_sell_price = joker_object_get_sell_price,
17 .get_name = joker_object_get_name,
18 .get_subtype_info = joker_object_get_rarity_info,
20 .can_acquire = joker_object_can_acquire,
21 .dispose = joker_object_dispose,
22 .print_description = joker_object_print_description
23 },
24
25 /* Currently playing cards have partial implementations since Magic Trick is not implemented
26 * and playing cards can't appear in the shop.
27 * If the Magic Trick voucher is implemented, these need to be completed.
28 * Playing cards must stay the only exception, the rest of the item types must implement
29 * all the basic functions to appear in the shop.
30 */
31 [ITEM_TYPE_PLAYING_CARD] = {
32 .roll_new = NULL,
33 .get_buy_price = card_object_get_buy_price,
34 .get_sell_price = NULL,
35 .get_name = NULL,
36 .get_subtype_info = NULL,
37 .acquire = NULL,
38 .can_acquire = item_always_can_acquire,
39 .dispose = card_object_dispose,
40 .print_description = NULL
41 }
42};
43// clang-format on
44
45ItemFuncs* get_item_type_funcs(enum ItemType type)
46{
47 if ((int)type < 0 || type >= NUM_ELEM_IN_ARR(item_func_table))
48 {
49 MGBA_FUNC_ERROR("Invalid type %d", type);
50 return NULL;
51 }
52
53 return &item_func_table[type];
54}
55
56static bool item_always_can_acquire(Item* item)
57{
58 return true;
59}
An API for the item functions defined in item.h Separated module from item.c/.h so item_funcs....
ItemFuncs * get_item_type_funcs(enum ItemType type)
Returns the function table for a given item type.
Definition item_funcs.c:45
Functions relative to the handling of Jokers.
void joker_object_dispose(Item **joker_object)
Destroy a JokerObject item, free its resources, and make it available to be rolled.
Definition joker.c:286
Item * joker_object_roll_new(enum RngSequence key)
Roll and create a new JokerObject item.
Definition joker.c:418
int joker_object_print_description(Item *joker_object, Rect dest_rect)
Print the description of the requested Joker centered within the specified Rect.
Definition joker.c:301
int joker_object_get_buy_price(Item *joker_object)
Returns the buy price of the joker object.
Definition joker.c:321
const char * joker_object_get_name(Item *joker_object)
Get Joker name.
Definition joker.c:158
void joker_object_add_to_owned(Item *joker_object)
Add a Joker to the list of owned Jokers and place it in the joker row.
Definition joker.c:337
ItemDescSubtypeInfo joker_object_get_rarity_info(Item *joker_object)
Get Joker rarity name and associated panel color.
Definition joker.c:168
int joker_object_get_sell_price(Item *joker_object)
Returns the sell price of the joker object.
Definition joker.c:329
Shop state functions.
The set of functions that each item type implements.
Definition item.h:107
Item *(* roll_new)(enum RngSequence key)
Definition item.h:112
A generic interface for all items that can appear in the shop or be in the inventory....
Definition item.h:83
Utilities relating around number string representation and protected arithmatic helper functions.
#define NUM_ELEM_IN_ARR(arr)
Get the number of elements in an array.
Definition util.h:55