diff --git a/include/joker.h b/include/joker.h index 017fa65..9e387a0 100644 --- a/include/joker.h +++ b/include/joker.h @@ -25,7 +25,6 @@ #define RARE_JOKER 2 #define LEGENDARY_JOKER 3 -#define MAX_JOKERS 2 // The current maximum jokers added #define MAX_JOKER_OBJECTS 32 // The maximum number of joker objects that can be created at once #define DEFAULT_JOKER_ID 0 @@ -55,6 +54,15 @@ typedef struct // These jokers are triggered after the played hand has finished bool retrigger; // Retrigger played hand (e.g. "Dusk" joker, even though on the wiki it says "On Scored" it makes more sense to have it here) } JokerEffect; +typedef JokerEffect (*JokerEffectFunc)(Joker *joker, Card *scored_card); +typedef struct { + u8 rarity; + u8 base_value; + JokerEffectFunc effect; +} JokerInfo; +extern const JokerInfo joker_registry[]; +extern const size_t joker_registry_size; + void joker_init(); Joker *joker_new(u8 id); diff --git a/source/game.c b/source/game.c index fbcf9eb..9089327 100644 --- a/source/game.c +++ b/source/game.c @@ -1825,7 +1825,7 @@ static void game_shop_create_items(JokerObject *shop_jokers[], bool first_time) joker_object_destroy(&shop_jokers[i]); // Destroy the joker object if it exists } - u8 joker_id = random() % MAX_JOKERS; + u8 joker_id = random() % joker_registry_size; shop_jokers[i] = joker_object_new(joker_new(joker_id)); shop_jokers[i]->sprite_object->x = int2fx(120 + i * 32); diff --git a/source/joker.c b/source/joker.c index bad9168..2233405 100644 --- a/source/joker.c +++ b/source/joker.c @@ -12,13 +12,6 @@ #define JOKER_SCORE_TEXT_Y 48 -const static u8 joker_data_lut[MAX_JOKERS][2] = // Rarity, Value -{ - // TODO: Change to struct - {COMMON_JOKER, 2}, // Default Joker - {COMMON_JOKER, 5}, // Greedy Joker -}; - const static u8 edition_price_lut[MAX_EDITIONS] = { 0, // BASE_EDITION @@ -45,12 +38,15 @@ void joker_init() Joker *joker_new(u8 id) { - Joker *joker = malloc(sizeof(Joker)); + if (id >= joker_registry_size) return NULL; - joker->id = id; // TODO: Make this random later + Joker *joker = malloc(sizeof(Joker)); + const JokerInfo *jinfo = &joker_registry[id]; + + joker->id = id; joker->modifier = BASE_EDITION; // TODO: Make this random later - joker->value = joker_data_lut[id][1] + edition_price_lut[joker->modifier]; // Base value + edition price - joker->rarity = joker_data_lut[id][0]; + joker->value = jinfo->base_value + edition_price_lut[joker->modifier]; // Base value + edition price + joker->rarity = jinfo->rarity; joker->processed = false; return joker; @@ -65,25 +61,8 @@ void joker_destroy(Joker **joker) JokerEffect joker_get_score_effect(Joker *joker, Card *scored_card) { - JokerEffect effect = {0}; - - switch (joker->id) - { - case DEFAULT_JOKER_ID: // Default Joker - if (scored_card != NULL) break; // Joker is independent, no effect - effect.mult = 4; - break; - case GREEDY_JOKER_ID: // Greedy Joker - if (scored_card != NULL && scored_card->suit == DIAMONDS) // If the scored card is a diamond - { - effect.mult = 3; - } - break; - default: - break; - } - - return effect; + if (joker->id >= joker_registry_size) return (JokerEffect){0}; + return joker_registry[joker->id].effect(joker, scored_card); } // JokerObject methods diff --git a/source/joker_effects.c b/source/joker_effects.c new file mode 100644 index 0000000..367c654 --- /dev/null +++ b/source/joker_effects.c @@ -0,0 +1,45 @@ +#include "joker.h" + +static JokerEffect default_joker_effect(Joker *joker, Card *scored_card) { + JokerEffect effect = {0}; + if (scored_card == NULL) effect.mult = 4; + return effect; +} + +static JokerEffect greedy_joker_effect(Joker *joker, Card *scored_card) { + JokerEffect effect = {0}; + if (scored_card != NULL && scored_card->suit == DIAMONDS) + effect.mult = 3; + return effect; +} + +static JokerEffect lusty_joker_effect(Joker *joker, Card *scored_card) { + JokerEffect effect = {0}; + if (scored_card != NULL && scored_card->suit == HEARTS) + effect.mult = 3; + return effect; +} + +static JokerEffect wrathful_joker_effect(Joker *joker, Card *scored_card) { + JokerEffect effect = {0}; + if (scored_card != NULL && scored_card->suit == SPADES) + effect.mult = 3; + return effect; +} + +static JokerEffect gluttonous_joker_effect(Joker *joker, Card *scored_card) { + JokerEffect effect = {0}; + if (scored_card != NULL && scored_card->suit == CLUBS) + effect.mult = 3; + return effect; +} + +const JokerInfo joker_registry[] = { + { COMMON_JOKER, 2, default_joker_effect }, // DEFAULT_JOKER_ID = 0 + { COMMON_JOKER, 5, greedy_joker_effect }, // GREEDY_JOKER_ID = 1 + { COMMON_JOKER, 5, lusty_joker_effect }, // etc... + { COMMON_JOKER, 5, wrathful_joker_effect }, + { COMMON_JOKER, 5, gluttonous_joker_effect }, +}; + +const size_t joker_registry_size = sizeof(joker_registry) / sizeof(joker_registry[0]);