GBAlatro
A Demake of Balatro for the GBA
Loading...
Searching...
No Matches
joker.c
1#include "joker.h"
2
3#include "card.h"
4#include "game/round.h"
5#include "game_variables.h"
6#include "graphic_utils.h"
7#include "layout.h"
8#include "mgba_logger.h"
9#include "pool.h"
10#include "random.h"
11#include "soundbank.h"
12#include "util.h"
13
14// Tiles and palettes
15#include "card_rarity_pal_gfx.h"
16#include "item.h"
17#include "joker_gfx.h"
18
19#include <maxmod.h>
20#include <stdlib.h>
21#include <string.h>
22#include <tonc.h>
23
24#define JOKER_SCORE_TEXT_Y 48
25#define HELD_CARD_SCORE_TEXT_Y 108
26#define MAX_CARD_SCORE_STR_LEN 2
27// what it was before (MAX_DEFINEABLE_JOKERS / JOKERS_PER_SPRITESHEET)
28#define MAX_NUM_JOKERS_SPRITESHEETS 75
29
30static const unsigned int* joker_gfxTiles[] = {
31#define DEF_JOKER_GFX(idx) joker_gfx##idx##Tiles,
32#include "../include/def_joker_gfx_table.h"
33#undef DEF_JOKER_GFX
34};
35static const unsigned short* joker_gfxPal[] = {
36#define DEF_JOKER_GFX(idx) joker_gfx##idx##Pal,
37#include "def_joker_gfx_table.h"
38#undef DEF_JOKER_GFX
39};
40
41// TODO: Removed unplanned editions...
42const static u8 EDITION_PRICE_LUT[MAX_EDITIONS] = {
43 0, // BASE_EDITION
44 2, // FOIL_EDITION
45 3, // HOLO_EDITION
46 5, // POLY_EDITION
47 5, // NEGATIVE_EDITION
48};
49
50/* So for the card objects, I needed them to be properly sorted
51 which is why they let you specify the layer index when creating a new card object.
52 Since the cards would overlap a lot in your hand, If they weren't sorted properly, it would look
53 like a mess. The joker objects are functionally identical to card objects, so they use the same
54 logic. But I'm going to use a simpler approach for the joker objects since I'm lazy and sorting
55 them wouldn't look good enough to warrant the effort.
56*/
57static bool s_used_layers[MAX_JOKER_OBJECTS] = {false}; // Track used layers for joker sprites
58// TODO: Refactor sorting into SpriteObject?
59
60// Maps the spritesheet index to the palette bank index allocated to it.
61// Spritesheets that were not allocated are
62static int s_joker_spritesheet_pb_map[MAX_NUM_JOKERS_SPRITESHEETS];
63static int s_joker_pb_num_sprite_users[JOKER_LAST_PB - JOKER_BASE_PB + 1] = {0};
64
65BITSET_DEFINE(s_rollable_jokers_bitset, MAX_DEFINABLE_JOKERS)
66
67// See linked issue for context of maps
68// https://github.com/GBALATRO/balatro-gba/issues/274#issue-3685075538
69
70// clang-format off
71// Map of Joker ID -> Spritesheet idx
72static const int JOKER_ID_TO_SPRITE_MAP[] = {
73 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
74 1, 1,
75 2, 2,
76 3, 3, 3, 3, 3,
77 4, 4, 4, 4, 4,
78 5, 5, 5, 5,
79 6, 6, 6, 6,
80 7, 7,
81 8, 8,
82 9,
83 10,
84 11,
85 12,
86 13,
87 14,
88 15,
89 16,
90 17,
91};
92
93// Map of Spritesheet idx -> first Joker ID in sheet
94// This is used to determine the sprite index of a Joker's sprite
95// within its spritesheet by substracting its ID to this starting ID.
96// Notice how spritesheets with only one Joker have sequential starting IDs.
97static const int SPRITESHEET_IDX_TO_STARTING_JOKER_ID[] = {
98 0, 18, 20, 22, 27, 32, 36, 40, 42, 44,
99 45, 46, 47, 48, 49, 50, 51, 52
100};
101
102// Lookup table of Joker Rarity strings. Used to display at the bottom of the description screen.
103static const char* JOKER_RARITY_STRINGS_LUT[MAX_RARITIES] = {
104 "Common", "Uncommon", "Rare", "Legendary"
105};
106// clang-format on
107
108static int s_get_num_spritesheets(void);
109static int s_joker_get_spritesheet_idx(u8 joker_id);
110static int s_joker_get_sprite_idx_in_sheet(u8 joker_id, int spritesheet_idx);
111static void s_joker_pb_add_sprite_user(int pb);
112static void s_joker_pb_remove_sprite_user(int pb);
113static int s_joker_pb_get_num_sprite_users(int joker_pb);
114static int s_get_unused_joker_pb(void);
115static int s_allocate_pb_if_needed(u8 joker_id);
116static int joker_get_random_rarity(enum RngSequence key);
117
118void joker_init()
119{
120 // This should init once only so no need to free
121 int num_spritesheets = s_get_num_spritesheets();
122
123 for (int i = 0; i < num_spritesheets; i++)
124 {
125 s_joker_spritesheet_pb_map[i] = UNDEFINED;
126 }
127}
128
129Joker* joker_new(u8 id)
130{
131 if (id >= get_joker_registry_size())
132 return NULL;
133
134 Joker* joker = POOL_GET(Joker);
135 const JokerInfo* jinfo = get_joker_registry_entry(id);
136
137 joker->id = id;
138 joker->modifier = BASE_EDITION; // TODO: Make this a parameter
139 joker->value = jinfo->base_value + EDITION_PRICE_LUT[joker->modifier];
140 joker->rarity = jinfo->rarity;
141 joker->scoring_state = 0;
142 joker->persistent_state = 0;
143
144 // initialize persistent Joker data if needed
145 JokerEffect* joker_effect = NULL;
146 jinfo->joker_effect_func(joker, NULL, JOKER_EVENT_ON_JOKER_CREATED, &joker_effect);
147
148 return joker;
149}
150
151void joker_destroy(Joker** joker)
152{
153 POOL_FREE(Joker, *joker);
154 *joker = NULL;
155}
156
157u32 joker_get_score_effect(
158 Joker* joker,
159 Card* scored_card,
160 enum JokerEvent joker_event,
161 JokerEffect** joker_effect
162)
163{
164 const JokerInfo* jinfo = get_joker_registry_entry(joker->id);
165 if (!jinfo)
166 return JOKER_EFFECT_FLAG_NONE;
167
168 return jinfo->joker_effect_func(joker, scored_card, joker_event, joker_effect);
169}
170
171const char* joker_get_rarity_string(u8 rarity)
172{
173 if (rarity >= MAX_RARITIES)
174 return NULL;
175
176 return JOKER_RARITY_STRINGS_LUT[rarity];
177}
178
179u16 joker_get_rarity_color(u8 rarity, bool main_color)
180{
181 if (rarity >= MAX_RARITIES)
182 return 0x0;
183
184 // +1 to account for the transparency
185 // odd indices are the main colors, even ones are the shadows
186 return card_rarity_pal_gfxPal[1 + 2 * rarity + (main_color ? 0 : 1)];
187}
188
189int joker_get_buy_price(const Joker* joker)
190{
191 GBAL_RETURN_IF_NULL_RET(joker, UNDEFINED);
192
193 return joker->value;
194}
195
196int joker_get_sell_value(const Joker* joker)
197{
198 GBAL_RETURN_IF_NULL_RET(joker, UNDEFINED);
199
200 return joker->value / 2;
201}
202
203// JokerObject methods
204JokerObject* joker_object_new(Joker* joker)
205{
206 JokerObject* joker_object = POOL_GET(JokerObject);
207
208 sprite_object_init((SpriteObject*)joker_object);
209
210 int layer = 0;
211 for (int i = 0; i < MAX_JOKER_OBJECTS; i++)
212 {
213 if (!s_used_layers[i])
214 {
215 layer = i;
216 s_used_layers[i] = true; // Mark this layer as used
217 break;
218 }
219 }
220
221 joker_object->joker = joker;
222
223 joker_object->type = ITEM_TYPE_JOKER;
224
225 int tile_index = JOKER_TID + layer * JOKER_SPRITE_OFFSET;
226
227 int joker_spritesheet_idx = s_joker_get_spritesheet_idx(joker->id);
228 int joker_idx = s_joker_get_sprite_idx_in_sheet(joker->id, joker_spritesheet_idx);
229 int joker_pb = s_allocate_pb_if_needed(joker->id);
230 s_joker_pb_add_sprite_user(joker_pb);
231
232 memcpy32(
233 &tile_mem[TILE_MEM_OBJ_CHARBLOCK0_IDX][tile_index],
234 &joker_gfxTiles[joker_spritesheet_idx][joker_idx * TILE_SIZE * JOKER_SPRITE_OFFSET],
235 TILE_SIZE * JOKER_SPRITE_OFFSET
236 );
237
239 (SpriteObject*)joker_object,
241 ATTR0_SQUARE | ATTR0_4BPP | ATTR0_AFF,
242 ATTR1_SIZE_32,
243 tile_index,
244 joker_pb,
245 JOKER_STARTING_LAYER + layer
246 )
247 );
248
249 return joker_object;
250}
251
252void joker_object_destroy(JokerObject** joker_object)
253{
254 if (joker_object == NULL || *joker_object == NULL)
255 return;
256
257 s16 layer = sprite_get_layer(joker_object_get_sprite(*joker_object)) - JOKER_STARTING_LAYER;
258 s_used_layers[layer] = false;
259 s_joker_pb_remove_sprite_user(sprite_get_pb(joker_object_get_sprite(*joker_object)));
260 if (s_joker_pb_get_num_sprite_users((sprite_get_pb(joker_object_get_sprite(*joker_object)))) ==
261 0)
262 {
263 s_joker_spritesheet_pb_map[s_joker_get_spritesheet_idx((*joker_object)->joker->id)] =
264 UNDEFINED;
265 }
266
267 sprite_object_destroy((SpriteObject*)(*joker_object));
268 joker_destroy(&(*joker_object)->joker);
269 POOL_FREE(JokerObject, *joker_object);
270 *joker_object = NULL;
271}
272
273void joker_object_dispose(Item** joker_object_item)
274{
275 GBAL_RETURN_IF_NULL_VOID(joker_object_item);
276 GBAL_RETURN_IF_NULL_VOID(*joker_object_item);
277 ITEM_RETURN_IF_UNEXPECTED_TYPE_VOID(*joker_object_item, ITEM_TYPE_JOKER);
278
279 JokerObject* joker_object = (JokerObject*)(*joker_object_item);
280 GBAL_RETURN_IF_NULL_VOID(joker_object->joker);
281
282 joker_set_rollable(joker_object->joker->id, true);
283
284 joker_object_destroy(&joker_object);
285 *joker_object_item = NULL;
286}
287
288void joker_object_shake(JokerObject* joker_object, mm_word sound_id)
289{
290 sprite_object_shake((SpriteObject*)joker_object, sound_id);
291}
292
294{
295 GBAL_RETURN_IF_NULL_RET(joker_object, UNDEFINED);
296 ITEM_RETURN_IF_UNEXPECTED_TYPE_RET(joker_object, ITEM_TYPE_JOKER, UNDEFINED);
297
298 return ((JokerObject*)joker_object)->joker->value;
299}
300
302{
303 GBAL_RETURN_IF_NULL_VOID(joker_object);
304 ITEM_RETURN_IF_UNEXPECTED_TYPE_VOID(joker_object, ITEM_TYPE_JOKER);
305
306 joker_object->ty = int2fx(HELD_JOKERS_POS.y);
307 add_joker((JokerObject*)joker_object);
308}
309
310void joker_set_rollable(int joker_id, bool rollable)
311{
312 bitset_set_idx(&s_rollable_jokers_bitset, joker_id, rollable);
313}
314
319static inline int get_num_rollable_jokers(void)
320{
321 return bitset_num_set_bits(&s_rollable_jokers_bitset);
322}
323
327static inline bool no_rollable_jokers(void)
328{
329 return bitset_is_empty(&s_rollable_jokers_bitset);
330}
331
333static inline bool joker_is_rollable(int joker_id)
334{
335 return bitset_get_idx(&s_rollable_jokers_bitset, joker_id);
336}
337
339{
340 int num_jokers = get_joker_registry_size();
341
342 bitset_clear(&s_rollable_jokers_bitset);
343 for (int i = 0; i < num_jokers; i++)
344 {
345 bitset_set_idx(&s_rollable_jokers_bitset, i, true);
346 }
347}
348
352static int joker_roll_id(enum RngSequence key)
353{
354 // Now determine how many jokers are available based on the rarity
355 int jokers_avail_size = get_num_rollable_jokers();
356
357 if (jokers_avail_size == 0)
358 return UNDEFINED;
359
360 // Roll for what rarity the joker will be
361 int joker_rarity = joker_get_random_rarity(key);
362
363 int matching_joker_ids[jokers_avail_size];
364 int fallback_random_idx = rng_get_u32(key) % jokers_avail_size;
365 int fallback_random_joker_id = UNDEFINED;
366 int match_count = 0;
367
368 BitsetItr itr = bitset_itr_create(&s_rollable_jokers_bitset);
369
370 int i = 0;
371 int joker_id = UNDEFINED;
372 while ((joker_id = bitset_itr_next(&itr)) != UNDEFINED)
373 {
374 if (i++ == fallback_random_idx)
375 fallback_random_joker_id = joker_id;
376 const JokerInfo* info = get_joker_registry_entry(joker_id);
377 if (info->rarity == joker_rarity)
378 {
379 matching_joker_ids[match_count++] = joker_id;
380 }
381 }
382
383 int selected_joker_id = (match_count > 0) ? matching_joker_ids[rng_get_u32(key) % match_count]
384 : fallback_random_joker_id;
385
386 return selected_joker_id;
387}
388
390{
391 if (no_rollable_jokers())
392 return NULL;
393
394 int joker_id = 0;
395#ifdef TEST_JOKER_ID0 // Allow defining an ID for a joker to always appear in shop and be tested
396 if (joker_is_rollable(TEST_JOKER_ID0))
397 {
398 joker_id = TEST_JOKER_ID0;
399 }
400 else
401#endif
402#ifdef TEST_JOKER_ID1
403 if (joker_is_rollable(TEST_JOKER_ID1))
404 {
405 joker_id = TEST_JOKER_ID1;
406 }
407 else
408#endif
409 {
410 joker_id = joker_roll_id(key);
411 }
412
413 // If for some reason only no joker is left, don't make another
414 if (joker_id == UNDEFINED)
415 return NULL;
416
417 joker_set_rollable(joker_id, false);
418
419 return (Item*)joker_object_new(joker_new(joker_id));
420}
421
428static inline int joker_get_random_rarity(enum RngSequence key)
429{
430 int joker_rarity = 0;
431 int rarity_roll = rng_get_u32(key) % 100;
432 if (rarity_roll < COMMON_JOKER_CHANCE)
433 {
434 joker_rarity = COMMON_JOKER;
435 }
436 else if (rarity_roll < COMMON_JOKER_CHANCE + UNCOMMON_JOKER_CHANCE)
437 {
438 joker_rarity = UNCOMMON_JOKER;
439 }
440 else if (rarity_roll < COMMON_JOKER_CHANCE + UNCOMMON_JOKER_CHANCE + RARE_JOKER_CHANCE)
441 {
442 joker_rarity = RARE_JOKER;
443 }
444 else if (rarity_roll < COMMON_JOKER_CHANCE + UNCOMMON_JOKER_CHANCE + RARE_JOKER_CHANCE +
445 LEGENDARY_JOKER_CHANCE)
446 {
447 joker_rarity = LEGENDARY_JOKER;
448 }
449
450 return joker_rarity;
451}
452
453static void set_and_shift_text(char* str, int* cursor_pos_x, int* cursor_pos_y, int color_pb)
454{
455 tte_set_pos(*cursor_pos_x, *cursor_pos_y);
456 tte_set_special(color_pb * TTE_SPECIAL_PB_MULT_OFFSET);
457 tte_write(str);
458
459 // + 1 For space
460 const int joker_score_display_offset_px = (MAX_CARD_SCORE_STR_LEN + 1) * TTE_CHAR_SIZE;
461 *cursor_pos_x += joker_score_display_offset_px;
462}
463
464bool joker_object_score(
465 JokerObject* joker_object,
466 CardObject* card_object,
467 enum JokerEvent joker_event
468)
469{
470 if (joker_object == NULL)
471 {
472 return false;
473 }
474
475 JokerEffect* joker_effect = NULL;
476 u32 effect_flags_ret =
477 joker_get_score_effect(joker_object->joker, card_object->card, joker_event, &joker_effect);
478
479 if (effect_flags_ret == JOKER_EFFECT_FLAG_NONE)
480 {
481 return false;
482 }
483
484 if (effect_flags_ret & JOKER_EFFECT_FLAG_RETRIGGER)
485 {
486 set_retrigger(joker_effect->retrigger);
487 }
488
489 // joker_effect.message will have been set if the Joker had anything custom to say
490
491 int cursorPosX = TILE_SIZE; // Offset of one tile to better center the text on the card
492 int cursorPosY = 0;
493 if (joker_event == JOKER_EVENT_ON_CARD_HELD)
494 {
495 // display the text on top of the card instead of below the Joker for Held Cards effects
496 // scored_card cannot be NULL here because of the joker event
497 cursorPosX += fx2int(card_object->x);
498 cursorPosY = HELD_CARD_SCORE_TEXT_Y;
499 }
500 else
501 {
502 cursorPosX += fx2int(joker_object->x);
503 cursorPosY = JOKER_SCORE_TEXT_Y;
504 }
505
506 mm_word sfx_id;
507 if (effect_flags_ret & JOKER_EFFECT_FLAG_CHIPS)
508 {
509 g_game_vars.chips = u32_protected_add(g_game_vars.chips, joker_effect->chips);
510 char score_buffer[INT_MAX_DIGITS + 2]; // For '+' and null terminator
511 snprintf(score_buffer, sizeof(score_buffer), "+%lu", joker_effect->chips);
512 set_and_shift_text(score_buffer, &cursorPosX, &cursorPosY, TTE_BLUE_PB);
513 sfx_id = SFX_CHIPS_GENERIC; // The joker chips effect is "generic"
514 }
515 if (effect_flags_ret & JOKER_EFFECT_FLAG_MULT)
516 {
517 g_game_vars.mult = u32_protected_add(g_game_vars.mult, joker_effect->mult);
518 char score_buffer[INT_MAX_DIGITS + 2];
519 snprintf(score_buffer, sizeof(score_buffer), "+%lu", joker_effect->mult);
520 set_and_shift_text(score_buffer, &cursorPosX, &cursorPosY, TTE_RED_PB);
521 sfx_id = SFX_MULT;
522 }
523 // if xmult is zero, DO NOT multiply by it
524 if (effect_flags_ret & JOKER_EFFECT_FLAG_XMULT && joker_effect->xmult > 0)
525 {
526 g_game_vars.mult = u32_protected_mult(g_game_vars.mult, joker_effect->xmult);
527 char score_buffer[INT_MAX_DIGITS + 2];
528 snprintf(score_buffer, sizeof(score_buffer), "X%lu", joker_effect->xmult);
529 set_and_shift_text(score_buffer, &cursorPosX, &cursorPosY, TTE_RED_PB);
530 sfx_id = SFX_XMULT;
531 }
532 if (effect_flags_ret & JOKER_EFFECT_FLAG_MONEY)
533 {
534 g_game_vars.money += joker_effect->money;
535 char score_buffer[INT_MAX_DIGITS + 2];
536 snprintf(score_buffer, sizeof(score_buffer), "%d$", joker_effect->money);
537 set_and_shift_text(score_buffer, &cursorPosX, &cursorPosY, TTE_YELLOW_PB);
538 // TODO: Money sound effect
539 }
540 // custom message for Jokers (including retriggers where Jokers will say "Again!")
541 // joker_effect->message will have been set if the Joker had anything custom to say
542 if (effect_flags_ret & JOKER_EFFECT_FLAG_MESSAGE)
543 {
544 set_and_shift_text(joker_effect->message, &cursorPosX, &cursorPosY, TTE_WHITE_PB);
545 }
546 // this will start the Joker expire animation
547 if (effect_flags_ret & JOKER_EFFECT_FLAG_EXPIRE && joker_effect->expire)
548 {
549 joker_object_shake(joker_object, UNDEFINED);
550 list_push_back(get_expired_jokers_list(), joker_object);
551 }
552
553 // Update displays
554 display_chips();
555 display_mult();
556 display_money();
557
558 joker_object_shake(joker_object, sfx_id);
559
560 return true;
561}
562
563Sprite* joker_object_get_sprite(JokerObject* joker_object)
564{
565 if (joker_object == NULL)
566 return NULL;
567 return sprite_object_get_sprite((SpriteObject*)joker_object);
568}
569
570static int s_get_num_spritesheets()
571{
572 return MAX_NUM_JOKERS_SPRITESHEETS;
573}
574
575static int s_joker_get_spritesheet_idx(u8 joker_id)
576{
577 return JOKER_ID_TO_SPRITE_MAP[joker_id];
578}
579
580static int s_joker_get_sprite_idx_in_sheet(u8 joker_id, int spritesheet_idx)
581{
582 return joker_id - SPRITESHEET_IDX_TO_STARTING_JOKER_ID[JOKER_ID_TO_SPRITE_MAP[joker_id]];
583}
584
585static void s_joker_pb_add_sprite_user(int pb)
586{
587 s_joker_pb_num_sprite_users[pb - JOKER_BASE_PB]++;
588}
589
590static void s_joker_pb_remove_sprite_user(int pb)
591{
592 int num_sprite_users = s_joker_pb_num_sprite_users[pb - JOKER_BASE_PB];
593 s_joker_pb_num_sprite_users[pb - JOKER_BASE_PB] = max(0, num_sprite_users - 1);
594}
595
596static int s_joker_pb_get_num_sprite_users(int joker_pb)
597{
598 return s_joker_pb_num_sprite_users[joker_pb - JOKER_BASE_PB];
599}
600
601static int s_get_unused_joker_pb()
602{
603 for (int i = 0; i < NUM_ELEM_IN_ARR(s_joker_pb_num_sprite_users); i++)
604 {
605 if (s_joker_pb_num_sprite_users[i] == 0)
606 {
607 return (i + JOKER_BASE_PB);
608 }
609 }
610
611 return UNDEFINED;
612}
613
614static int s_allocate_pb_if_needed(u8 joker_id)
615{
616 int joker_spritesheet_idx = s_joker_get_spritesheet_idx(joker_id);
617 int joker_pb = s_joker_spritesheet_pb_map[joker_spritesheet_idx];
618 if (joker_pb != UNDEFINED)
619 {
620 // Already allocated
621 return joker_pb;
622 }
623
624 // Allocate a new palette
625 joker_pb = s_get_unused_joker_pb();
626
627 if (joker_pb == UNDEFINED)
628 {
629 // Ran out of palettes, default to base and pray
630 joker_pb = JOKER_BASE_PB;
631 }
632 else
633 {
634 s_joker_spritesheet_pb_map[joker_spritesheet_idx] = joker_pb;
635 memcpy16(
636 &pal_obj_mem[PAL_ROW_LEN * joker_pb],
637 joker_gfxPal[joker_spritesheet_idx],
638 NUM_ELEM_IN_ARR(joker_gfx0Pal)
639 );
640 }
641
642 return joker_pb;
643}
bool bitset_get_idx(Bitset *bitset, int idx)
Get the value of a flag.
Definition bitset.c:72
bool bitset_is_empty(Bitset *bitset)
Check if a bitset is empty (all 0's)
Definition bitset.c:62
void bitset_clear(Bitset *bitset)
Clear the bitset, all to 0.
Definition bitset.c:54
int bitset_num_set_bits(Bitset *bitset)
Count how many bits are set to 1 in a bitset.
Definition bitset.c:80
#define BITSET_DEFINE(name, capacity)
Make a standard bitset.
Definition bitset.h:198
BitsetItr bitset_itr_create(const Bitset *bitset)
Declare a BitsetItr.
Definition bitset.c:128
int bitset_itr_next(BitsetItr *itr)
Get the index of the next set bit in the bitset from a BitsetItr.
Definition bitset.c:140
void bitset_set_idx(Bitset *bitset, int idx, bool on)
Set a flag in a bitset to a value.
Definition bitset.c:5
Game global game variables struct definition.
Graphic utility functions.
#define TILE_SIZE
Tile size in pixels, both height and width as tiles are square.
#define TILE_MEM_OBJ_CHARBLOCK0_IDX
The index for the first charblock of the object memory in tonc's tile_mem.
#define TTE_CHAR_SIZE
By default TTE characters occupy a single tile.
The core structure for items in the shop and inventory. Provides a common API for the shop and invent...
#define ITEM_RETURN_IF_UNEXPECTED_TYPE_RET(item, expected_type, ret_val)
Checks if item is of type expected_type - logs error message and returns otherwise.
Definition item.h:25
#define ITEM_RETURN_IF_UNEXPECTED_TYPE_VOID(item, expected_type)
Checks if item is of type expected_type - logs error message and returns otherwise.
Definition item.h:41
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
u16 joker_get_rarity_color(u8 rarity, bool main_color)
Get Joker rarity panel color.
Definition joker.c:179
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
void joker_reset_rollable_jokers(void)
Reset rollable jokers to include all jokers in the registry.
Definition joker.c:338
void joker_set_rollable(int joker_id, bool rollable)
Set whether a Joker is available to be rolled for the shop, packs, etc.
Definition joker.c:310
Header of shared rects and points needed for ui.
void list_push_back(List *list, void *data)
Definition list.c:89
Interface to interact with the mgba logger.
Common functions to handle RNG manipulation. Using this interface has three goals:
u32 rng_get_u32(enum RngSequence key)
Get the next "randomly" generated number in the sequence corresponding to the given type.
Definition random.c:56
RngSequence
Keys to different independent RNG sequences.
Definition random.h:19
API relative to the Rounds we play.
void set_retrigger(bool new_retrigger)
Set whether the current card should get triggered again.
Definition round.c:301
void sprite_object_init(SpriteObject *sprite_object)
Initialize a SpriteObject to a default state. Must be called only once per SpriteObject when it is cr...
Definition sprite.c:186
void sprite_object_destroy(SpriteObject *sprite_object)
Destroy SpriteObject.
Definition sprite.c:197
s16 sprite_get_layer(Sprite *sprite)
Get index of Sprite in the GBA object buffer.
Definition sprite.c:116
int sprite_get_pb(const Sprite *sprite)
Get the palette bank of a Sprite.
Definition sprite.c:164
void sprite_object_set_sprite(SpriteObject *sprite_object, Sprite *sprite)
Register a Sprite to an associated SpriteObject.
Definition sprite.c:205
void sprite_object_shake(SpriteObject *sprite_object, mm_word sound_id)
Shake SpriteObject on screen and play a sound.
Definition sprite.c:350
Sprite * sprite_new(u16 a0, u16 a1, u32 tid, u32 pb, s16 sprite_index)
Allocate and retrieve a pointer to a valid Sprite.
Definition sprite.c:36
Sprite * sprite_object_get_sprite(SpriteObject *sprite_object)
Get a SpriteObject's registered Sprite.
Definition sprite.c:363
An iterator into a Bitset.
Definition bitset.h:73
Definition card.h:50
A generic interface for all items that can appear in the shop or be in the inventory....
Definition item.h:76
Definition joker.h:102
A sprite object is a sprite that is focusable and movable in animation.
Definition sprite.h:61
Sprite struct for GBA hardware specifics.
Definition sprite.h:29
Utilities relating around number string representation and protected arithmatic helper functions.
uint32_t u32_protected_add(uint32_t a, uint32_t b)
Avoid overflow when adding two u32 integers.
Definition util.c:175
#define NUM_ELEM_IN_ARR(arr)
Get the number of elements in an array.
Definition util.h:43
#define GBAL_RETURN_IF_NULL_RET(param, ret_val)
Checks if param is equal to NULL and prints error message and returns in case it is....
Definition util.h:95
#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
#define GBAL_UNUSED
A friendly wrapper around the not so friendly looking attribute syntax for ((unused))
Definition util.h:19
uint32_t u32_protected_mult(uint32_t a, uint32_t b)
Avoid overflow when multiplying two u32 integers.
Definition util.c:185