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// This won't be more than the number of jokers in your current deck
18// plus the amount that can fit in the shop, 8 should be fine. For now...
19#define MAX_ACTIVE_JOKERS 8
20
21#define MAX_DEFINABLE_JOKERS 150
22
23#define JOKER_SPRITE_OFFSET 16 // Offset for the joker sprites
24#define JOKER_STARTING_LAYER 26
25// Tile ID for the starting index in the tile memory
26#define JOKER_TID (JOKER_STARTING_LAYER * JOKER_SPRITE_OFFSET)
27#define JOKER_BASE_PB 4 // The starting palette index for the jokers, after the boss blind tokens
28#define JOKER_LAST_PB (NUM_PALETTES - 1)
29// Currently allocating the rest of the palettes for the jokers.
30// This number needs to be decreased once we need to allocated palettes for other sprites
31// such as planet cards etc.
32
33#define BASE_EDITION 0
34#define FOIL_EDITION 1
35#define HOLO_EDITION 2
36#define POLY_EDITION 3
37#define NEGATIVE_EDITION 4
38
39#define MAX_EDITIONS 5
40
41#define COMMON_JOKER 0
42#define UNCOMMON_JOKER 1
43#define RARE_JOKER 2
44#define LEGENDARY_JOKER 3
45
46#define MAX_RARITIES (LEGENDARY_JOKER + 1)
47
48// Percent chance to get a joker of each rarity
49// Note that this deviates slightly from the Balatro wiki to allow legendary
50// jokers to appear without spectral cards implemented
51#define COMMON_JOKER_CHANCE 70
52#define UNCOMMON_JOKER_CHANCE 25
53#define RARE_JOKER_CHANCE 5
54#define LEGENDARY_JOKER_CHANCE 0
55
56// These are the common Joker Events. Special Joker behaviour will be checked on a
57// Joker per Joker basis (see if it's there, then do something, e.g. Pareidolia, Baseball Card)
58enum JokerEvent
59{
60 JOKER_EVENT_ON_JOKER_CREATED, // Triggers only once when the Joker is created, mainly used for
61 // data initialization
62 JOKER_EVENT_ON_HAND_PLAYED, // Triggers only once when the hand is played and before the cards
63 // are scored
64 JOKER_EVENT_ON_CARD_SCORED, // Triggers when a played card scores (e.g. Walkie Talkie,
65 // Fibonnacci...)
66 JOKER_EVENT_ON_CARD_SCORED_END, // Triggers after the card has finishd scoring (e.g. retrigger
67 // Jokers)
68 JOKER_EVENT_ON_CARD_HELD, // Triggers when going through held cards
69 JOKER_EVENT_INDEPENDENT, // Joker will trigger normally, when Jokers are scored (e.g. base
70 // Joker)
71 JOKER_EVENT_ON_HAND_SCORED_END, // Triggers when entire hand has finished scoring (e.g. food
72 // Jokers)
73 JOKER_EVENT_ON_HAND_DISCARDED, // Triggers when discarding a hand
74 JOKER_EVENT_ON_ROUND_END, // Triggers at the end of the round (e.g. Rocket)
75 JOKER_EVENT_ON_BLIND_SELECTED, // Triggers when selecting a blind (e.g. Dagger, Riff Raff,
76 // Madness..)
77};
78
79// These are flags that can be combined into a single u32 and returned by
80// JokerEffect functions to indicate which fields of the output JokerEffect are valid
81
82#define JOKER_EFFECT_FLAG_NONE 0
83#define JOKER_EFFECT_FLAG_CHIPS (1 << 0)
84#define JOKER_EFFECT_FLAG_MULT (1 << 1)
85#define JOKER_EFFECT_FLAG_XMULT (1 << 2)
86#define JOKER_EFFECT_FLAG_MONEY (1 << 3)
87#define JOKER_EFFECT_FLAG_RETRIGGER (1 << 4)
88#define JOKER_EFFECT_FLAG_EXPIRE (1 << 5)
89#define JOKER_EFFECT_FLAG_MESSAGE (1 << 6)
90
91#define MAX_JOKER_OBJECTS 32 // The maximum number of joker objects that can be created at once
92
93// Jokers in the game
94#define STENCIL_JOKER_ID 15
95#define SHORTCUT_JOKER_ID 48
96#define BRAINSTORM_JOKER_ID 41
97#define PAREIDOLIA_JOKER_ID 46
98#define FOUR_FINGERS_JOKER_ID 50
99#define BLUEPRINT_JOKER_ID 52
100
101typedef struct
102{
103 u8 id; // Unique ID for the joker, used to identify different jokers
104 u8 modifier; // base, foil, holo, poly, negative
105 u8 value;
106 u8 rarity;
107
108 // General purpose values that are interpreted differently for each Joker (scaling, last
109 // retriggered card, etc...)
110 s32 scoring_state;
111 s32 persistent_state;
112} Joker;
113
114typedef struct JokerObject
115{
116 Item; // First member struct inheritance
117 Joker* joker;
119
120typedef struct // These jokers are triggered after the played hand has finished scoring.
121{
122 u32 chips;
123 u32 mult;
124 u32 xmult;
125 int money;
126 bool retrigger; // Retrigger played hand (e.g. "Dusk" joker, even though on the wiki it says "On
127 // Scored" it makes more sense to have it here)
128 bool expire; // Will make the Joker expire/destry itself if true (i.e. Bananas and fully
129 // consumed Food Jokers)
130 char* message; // Used to send custom messages e.g. "Extinct!" or "Again!"
132
133// JokerEffectFuncs take in a joker that will be scored, a scored_card that is not NULL when related
134// to the given joker_event, and output a joker_effect storing the effects of the scored joker They
135// return a set of flags indicating what fields of the joker_effect are valid to access
136typedef u32 (*JokerEffectFunc)(
137 Joker* joker,
138 Card* scored_card,
139 enum JokerEvent joker_event,
140 JokerEffect** joker_effect
141);
142
143typedef int (*JokerDescFunc)(Joker* joker, Rect dest_rect);
144
145typedef struct
146{
147 const char* name;
148 u8 rarity;
149 u8 base_value;
150 bool is_desc_dynamic; // Is the little variable description at the bottom dynamic?
151 // Only used by the Misprint joker for now
152 JokerDescFunc joker_print_desc;
153 JokerEffectFunc joker_effect_func;
154} JokerInfo;
155const JokerInfo* get_joker_registry_entry(int joker_id);
156size_t get_joker_registry_size(void);
157
158void joker_init();
159
160Joker* joker_new(u8 id);
161void joker_destroy(Joker** joker);
162
163// Unique effects like "Four Fingers" or "Credit Card" will be hard coded into game.c with a
164// conditional check for the joker ID from the players owned jokers game.c should probably be
165// restructured so most of the variables in it are moved to some sort of global variable header file
166// so they can be easily accessed and modified for the jokers
167u32 joker_get_score_effect(
168 Joker* joker,
169 Card* scored_card,
170 enum JokerEvent joker_event,
171 JokerEffect** joker_effect
172);
173
174const char* joker_get_rarity_string(u8 rarity);
175
193u16 joker_get_rarity_color(u8 rarity, bool main_color);
194
195int joker_get_sell_value(const Joker* joker);
196
197JokerObject* joker_object_new(Joker* joker);
198void joker_object_destroy(JokerObject** joker_object);
199// This doesn't actually score anything, it just performs an animation and plays a sound effect
200void joker_object_shake(JokerObject* joker_object, mm_word sound_id);
201
209int joker_object_get_buy_price(Item* joker_object);
210
211// TODO: Move to an owned_jokers.c/.h file?
217void joker_object_add_to_owned(Item* joker_object);
218
224void joker_object_dispose(Item** joker_object);
225
232void joker_set_rollable(int joker_id, bool rollable);
233
238
247
248// This scores the joker and returns true if it was scored successfully
249// card_object = NULL means the joker_event does not concern a particular Card, i.e. Independend or
250// On_Blind_Selected as opposed to events that concern a particular card, i.e. On_Card_Scored or
251// On_Card_Held
252bool joker_object_score(
253 JokerObject* joker_object,
254 CardObject* card_object,
255 enum JokerEvent joker_event
256);
257
258Sprite* joker_object_get_sprite(JokerObject* joker_object);
259
260#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: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
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: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
Sprite struct for GBA hardware specifics.
Definition sprite.h:29