GBAlatro
A Demake of Balatro for the GBA
Loading...
Searching...
No Matches
joker.h
Go to the documentation of this file.
1
6#ifndef JOKER_H
7#define JOKER_H
8
9#include "card.h"
10#include "game.h"
11#include "graphic_utils.h"
12#include "item.h"
13#include "random.h"
14
15#include <maxmod.h>
16
17#define MAX_DEFINABLE_JOKERS 150
18
19// Pack the enum into a u8 so that the Joker struct uses as little memory as possible
20enum JokerRarity : u8
21{
22 COMMON_JOKER,
23 UNCOMMON_JOKER,
24 RARE_JOKER,
25 LEGENDARY_JOKER,
26 MAX_RARITIES
27};
28
29// Percent chance to get a joker of each rarity
30// Note that this deviates slightly from the Balatro wiki to allow legendary
31// jokers to appear without spectral cards implemented
32#define COMMON_JOKER_CHANCE 70
33#define UNCOMMON_JOKER_CHANCE 25
34#define RARE_JOKER_CHANCE 5
35#define LEGENDARY_JOKER_CHANCE 0
36
37// These are the common Joker Events. Special Joker behaviour will be checked on a
38// Joker per Joker basis (see if it's there, then do something, e.g. Pareidolia, Baseball Card)
39enum JokerEvent
40{
41 JOKER_EVENT_ON_JOKER_CREATED, // Triggers only once when the Joker is created, mainly used for
42 // data initialization
43 JOKER_EVENT_ON_HAND_PLAYED, // Triggers only once when the hand is played and before the cards
44 // are scored
45 JOKER_EVENT_ON_CARD_SCORED, // Triggers when a played card scores (e.g. Walkie Talkie,
46 // Fibonnacci...)
47 JOKER_EVENT_ON_CARD_SCORED_END, // Triggers after the card has finishd scoring (e.g. retrigger
48 // Jokers)
49 JOKER_EVENT_ON_CARD_HELD, // Triggers when going through held cards
50 JOKER_EVENT_INDEPENDENT, // Joker will trigger normally, when Jokers are scored (e.g. base
51 // Joker)
52 JOKER_EVENT_ON_HAND_SCORED_END, // Triggers when entire hand has finished scoring (e.g. food
53 // Jokers)
54 JOKER_EVENT_ON_HAND_DISCARDED, // Triggers when discarding a hand
55 JOKER_EVENT_ON_ROUND_END, // Triggers at the end of the round (e.g. Rocket)
56 JOKER_EVENT_ON_BLIND_SELECTED, // Triggers when selecting a blind (e.g. Dagger, Riff Raff,
57 // Madness..)
58};
59
60// These are flags that can be combined into a single u32 and returned by
61// JokerEffect functions to indicate which fields of the output JokerEffect are valid
62
63#define JOKER_EFFECT_FLAG_NONE 0
64#define JOKER_EFFECT_FLAG_CHIPS (1 << 0)
65#define JOKER_EFFECT_FLAG_MULT (1 << 1)
66#define JOKER_EFFECT_FLAG_XMULT (1 << 2)
67#define JOKER_EFFECT_FLAG_MONEY (1 << 3)
68#define JOKER_EFFECT_FLAG_RETRIGGER (1 << 4)
69#define JOKER_EFFECT_FLAG_EXPIRE (1 << 5)
70#define JOKER_EFFECT_FLAG_MESSAGE (1 << 6)
71
72#define MAX_JOKER_OBJECTS 32 // The maximum number of joker objects that can be created at once
73
74// Jokers in the game
75#define STENCIL_JOKER_ID 15
76#define SHORTCUT_JOKER_ID 48
77#define BRAINSTORM_JOKER_ID 41
78#define PAREIDOLIA_JOKER_ID 46
79#define FOUR_FINGERS_JOKER_ID 50
80#define BLUEPRINT_JOKER_ID 52
81
82typedef struct
83{
84 u8 id; // Unique ID for the joker, used to identify different jokers
85 u8 value;
86 enum JokerRarity rarity;
87
88 // General purpose values that are interpreted differently for each Joker (scaling, last
89 // retriggered card, etc...)
90 s32 scoring_state;
91 s32 persistent_state;
92} Joker;
93
94typedef struct JokerObject
95{
96 Item; // First member struct inheritance
97 Joker* joker;
99
100typedef struct // These jokers are triggered after the played hand has finished scoring.
101{
102 u32 chips;
103 u32 mult;
104 u32 xmult;
105 int money;
106 bool retrigger; // Retrigger played hand (e.g. "Dusk" joker, even though on the wiki it says "On
107 // Scored" it makes more sense to have it here)
108 bool expire; // Will make the Joker expire/destry itself if true (i.e. Bananas and fully
109 // consumed Food Jokers)
110 char* message; // Used to send custom messages e.g. "Extinct!" or "Again!"
112
113// JokerEffectFuncs take in a joker that will be scored, a scored_card that is not NULL when related
114// to the given joker_event, and output a joker_effect storing the effects of the scored joker They
115// return a set of flags indicating what fields of the joker_effect are valid to access
116typedef u32 (*JokerEffectFunc)(
117 Joker* joker,
118 Card* scored_card,
119 enum JokerEvent joker_event,
120 JokerEffect** joker_effect
121);
122
123typedef int (*JokerDescFunc)(Joker* joker, Rect dest_rect);
124
125typedef struct
126{
127 const char* name;
128 enum JokerRarity rarity;
129 u8 base_value;
130 bool is_desc_dynamic; // Is the little variable description at the bottom dynamic?
131 // Only used by the Misprint joker for now
132 JokerDescFunc joker_print_desc;
133 JokerEffectFunc joker_effect_func;
134} JokerInfo;
135const JokerInfo* get_joker_registry_entry(int joker_id);
136size_t get_joker_registry_size(void);
137
138void joker_init();
139
140Joker* joker_new(u8 id);
141void joker_destroy(Joker** joker);
142
143// Unique effects like "Four Fingers" or "Credit Card" will be hard coded into game.c with a
144// conditional check for the joker ID from the players owned jokers game.c should probably be
145// restructured so most of the variables in it are moved to some sort of global variable header file
146// so they can be easily accessed and modified for the jokers
147u32 joker_get_score_effect(
148 Joker* joker,
149 Card* scored_card,
150 enum JokerEvent joker_event,
151 JokerEffect** joker_effect
152);
153
159int joker_get_sell_value(const Joker* joker);
160
166int joker_get_buy_price(const Joker* joker);
167
174const char* joker_object_get_name(Item* joker_object);
175
185
186JokerObject* joker_object_new(Joker* joker);
187void joker_object_destroy(JokerObject** joker_object);
188// This doesn't actually score anything, it just performs an animation and plays a sound effect
189void joker_object_shake(JokerObject* joker_object, mm_word sound_id);
190
198int joker_object_get_buy_price(Item* joker_object);
199
207int joker_object_get_sell_price(Item* joker_object);
208
209// TODO: Move to an owned_jokers.c/.h file?
215void joker_object_add_to_owned(Item* joker_object);
216
222void joker_object_dispose(Item** joker_object);
223
233int joker_object_print_description(Item* joker_object, Rect dest_rect);
234
242int joker_roll_id_with_rarity(int joker_rarity);
243
252int joker_roll_id(enum JokerRarity joker_rarity, enum RngSequence key);
253
260void joker_set_rollable(int joker_id, bool rollable);
261
266
275
276Sprite* joker_object_get_sprite(JokerObject* joker_object);
277
278#endif // JOKER_H
Graphic utility functions.
The core structure for items in the shop and inventory. Provides a common API for the shop and invent...
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
int joker_get_buy_price(const Joker *joker)
Returns the buy price of the joker.
Definition joker.c:201
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
int joker_roll_id(enum JokerRarity joker_rarity, enum RngSequence key)
Rolls a random Joker among the available ones of a certain rarity.
Definition joker.c:384
ItemDescSubtypeInfo joker_object_get_rarity_info(Item *joker_object)
Get Joker rarity name and associated panel color.
Definition joker.c:168
void joker_reset_rollable_jokers(void)
Reset rollable jokers to include all jokers in the registry.
Definition joker.c:373
int joker_roll_id_with_rarity(int joker_rarity)
Rolls a random Joker among the available ones of a certain rarity.
int joker_get_sell_value(const Joker *joker)
Returns the sell value of the joker.
Definition joker.c:208
int joker_object_get_sell_price(Item *joker_object)
Returns the sell price of the joker object.
Definition joker.c:329
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:345
Common functions to handle RNG manipulation. Using this interface has three goals:
RngSequence
Keys to different independent RNG sequences.
Definition random.h:19
Definition card.h:46
Structure containing the main and shadow colors, and the name string associated with an Item's subtyp...
Definition item.h:65
A generic interface for all items that can appear in the shop or be in the inventory....
Definition item.h:83
Definition joker.h:83
Sprite struct for GBA hardware specifics.
Definition sprite.h:54