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 Item* item_roll_new_unimplemented(enum RngSequence key);
10static void item_acquire_unimplemented(Item* item);
11static bool item_always_can_acquire(Item* item);
12
13// clang-format off
14ItemFuncs item_func_table[] = {
15 [ITEM_TYPE_JOKER] = {
17 .get_buy_price = joker_object_get_buy_price,
19 .can_acquire = joker_object_can_acquire,
20 .dispose = joker_object_dispose
21 },
22
23 /* Currently playing cards have partial implementations since Magic Trick is not implemented
24 * and playing cards can't appear in the shop.
25 * If the Magic Trick voucher is implemented, these need to be completed.
26 * Playing cards must stay the only exception, the rest of the item types must implement
27 * all the basic functions to appear in the shop.
28 */
29 [ITEM_TYPE_PLAYING_CARD] = {
30 .roll_new = item_roll_new_unimplemented,
31 .get_buy_price = card_object_get_buy_price,
32 .acquire = item_acquire_unimplemented,
33 .can_acquire = item_always_can_acquire,
34 .dispose = card_object_dispose
35 }
36};
37// clang-format on
38
39ItemFuncs* get_item_type_funcs(enum ItemType type)
40{
41 if ((int)type < 0 || type >= NUM_ELEM_IN_ARR(item_func_table))
42 {
43 MGBA_FUNC_ERROR("Invalid type %d", type);
44 return NULL;
45 }
46
47 return &item_func_table[type];
48}
49
50static Item* item_roll_new_unimplemented(enum RngSequence key)
51{
52 MGBA_FUNC_ERROR("Unimplemented roll_new function called");
53 return NULL;
54}
55
56static void item_acquire_unimplemented(Item* item)
57{
59 MGBA_FUNC_ERROR("Unimplemented acquire function called for item type type %d", (item)->type);
60}
61
62static bool item_always_can_acquire(Item* item)
63{
64 return true;
65}
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:39
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:273
Item * joker_object_roll_new(enum RngSequence key)
Roll and create a new JokerObject item.
Definition joker.c:389
int joker_object_get_buy_price(Item *joker_object)
Returns the buy price of the joker object.
Definition joker.c:293
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:301
RngSequence
Keys to different independent RNG sequences.
Definition random.h:19
Shop state functions.
The set of functions that each item type implements.
Definition item.h:94
Item *(* roll_new)(enum RngSequence key)
Definition item.h:99
A generic interface for all items that can appear in the shop or be in the inventory....
Definition item.h:76
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:43
#define GBAL_RETURN_IF_NULL_VOID(param)
Checks if param is NULL and prints error message and returns in case it is. Useful for checking argum...
Definition util.h:76