Modify blueprint and brainstorm implementation to fix retrigger bug (#244)
--------- Co-authored-by: MathisMartin31 <mathis.martin31@gmail.com>
This commit is contained in:
+7
-11
@@ -66,10 +66,11 @@ enum JokerEvent
|
||||
// Jokers in the game
|
||||
#define DEFAULT_JOKER_ID 0
|
||||
#define GREEDY_JOKER_ID 1
|
||||
#define JOKER_STENCIL_ID 16
|
||||
#define STENCIL_JOKER_ID 16
|
||||
#define SHORTCUT_JOKER_ID 26
|
||||
#define PAREIDOLIA_JOKER_ID 30
|
||||
#define JOKER_BRAINSTORM_ID 40
|
||||
#define SHORTCUT_JOKER_ID 26
|
||||
#define BLUEPRINT_JOKER_ID 39
|
||||
#define BRAINSTORM_JOKER_ID 40
|
||||
#define FOUR_FINGERS_JOKER_ID 48
|
||||
|
||||
typedef struct
|
||||
@@ -78,15 +79,10 @@ typedef struct
|
||||
u8 modifier; // base, foil, holo, poly, negative
|
||||
u8 value;
|
||||
u8 rarity;
|
||||
|
||||
// General purpose values that are interpreted differently for each Joker (scaling, last retriggered card, etc...)
|
||||
union
|
||||
{
|
||||
s32 data;
|
||||
struct {
|
||||
s16 data0;
|
||||
s16 data1;
|
||||
} halves;
|
||||
};
|
||||
s32 scoring_state;
|
||||
s32 persistent_state;
|
||||
} Joker;
|
||||
|
||||
typedef struct JokerObject
|
||||
|
||||
+2
-1
@@ -145,7 +145,8 @@ Joker *joker_new(u8 id)
|
||||
joker->modifier = BASE_EDITION; // TODO: Make this a parameter
|
||||
joker->value = jinfo->base_value + edition_price_lut[joker->modifier];
|
||||
joker->rarity = jinfo->rarity;
|
||||
joker->data = 0;
|
||||
joker->scoring_state = 0;
|
||||
joker->persistent_state = 0;
|
||||
|
||||
// initialize persistent Joker data if needed
|
||||
jinfo->joker_effect(joker, NULL, JOKER_EVENT_ON_JOKER_CREATED);
|
||||
|
||||
+141
-107
@@ -285,7 +285,7 @@ static JokerEffect joker_stencil_effect(Joker *joker, Card *scored_card, enum Jo
|
||||
|
||||
while((joker_object = list_itr_next(&itr)))
|
||||
{
|
||||
if (joker_object->joker->id == JOKER_STENCIL_ID) effect.xmult++;
|
||||
if (joker_object->joker->id == STENCIL_JOKER_ID) effect.xmult++;
|
||||
}
|
||||
|
||||
return effect;
|
||||
@@ -405,7 +405,7 @@ static JokerEffect raised_fist_joker_effect(Joker *joker, Card *scored_card, enu
|
||||
{
|
||||
JokerEffect effect = {0};
|
||||
|
||||
s32* p_lowest_value_index = &(joker->data);
|
||||
s32* p_lowest_value_index = &(joker->scoring_state);
|
||||
|
||||
switch (joker_event)
|
||||
{
|
||||
@@ -596,7 +596,7 @@ static JokerEffect acrobat_joker_effect(Joker *joker, Card *scored_card, enum Jo
|
||||
static JokerEffect hanging_chad_joker_effect(Joker *joker, Card *scored_card, enum JokerEvent joker_event)
|
||||
{
|
||||
JokerEffect effect = {0};
|
||||
s32* p_remaining_retriggers = &(joker->data);
|
||||
s32* p_remaining_retriggers = &(joker->scoring_state);
|
||||
|
||||
switch (joker_event)
|
||||
{
|
||||
@@ -609,9 +609,9 @@ static JokerEffect hanging_chad_joker_effect(Joker *joker, Card *scored_card, en
|
||||
// will be false and scoring will go onto the next card
|
||||
case JOKER_EVENT_ON_CARD_SCORED_END:
|
||||
effect.retrigger = (*p_remaining_retriggers > 0);
|
||||
*p_remaining_retriggers -= 1;
|
||||
if (effect.retrigger)
|
||||
{
|
||||
(*p_remaining_retriggers)--;
|
||||
effect.message = "Again!";
|
||||
}
|
||||
break;
|
||||
@@ -756,7 +756,7 @@ __attribute__((unused))
|
||||
static JokerEffect photograph_joker_effect(Joker *joker, Card *scored_card, enum JokerEvent joker_event)
|
||||
{
|
||||
JokerEffect effect = {0};
|
||||
s32* p_first_face_index = &(joker->data);
|
||||
s32* p_first_face_index = &(joker->scoring_state);
|
||||
|
||||
switch (joker_event)
|
||||
{
|
||||
@@ -808,11 +808,12 @@ static JokerEffect triboulet_joker_effect(Joker *joker, Card *scored_card, enum
|
||||
static JokerEffect dusk_joker_effect(Joker *joker, Card *scored_card, enum JokerEvent joker_event)
|
||||
{
|
||||
JokerEffect effect = {0};
|
||||
s32* p_last_retriggered_index = &(joker->data);
|
||||
s32* p_last_retriggered_index = &(joker->scoring_state);
|
||||
|
||||
switch (joker_event)
|
||||
{
|
||||
case JOKER_EVENT_ON_HAND_PLAYED:
|
||||
// start at -1 so that a first index of 0 can satisfy the retrigger condition below
|
||||
*p_last_retriggered_index = UNDEFINED;
|
||||
break;
|
||||
|
||||
@@ -838,48 +839,81 @@ static JokerEffect dusk_joker_effect(Joker *joker, Card *scored_card, enum Joker
|
||||
}
|
||||
|
||||
|
||||
static JokerEffect blueprint_joker_effect(Joker *joker, Card *scored_card, enum JokerEvent joker_event)
|
||||
static JokerEffect blueprint_brainstorm_joker_effect(Joker *joker, Card *scored_card, enum JokerEvent joker_event)
|
||||
{
|
||||
JokerEffect effect = {0};
|
||||
List* jokers = get_jokers_list();
|
||||
|
||||
ListItr itr = list_itr_create(jokers);
|
||||
JokerObject* curr_joker_object;
|
||||
|
||||
while((curr_joker_object = list_itr_next(&itr)))
|
||||
{
|
||||
if (curr_joker_object->joker == joker)
|
||||
{
|
||||
JokerObject* next_joker_object = list_itr_next(&itr);
|
||||
effect = joker_get_score_effect(next_joker_object->joker, scored_card, joker_event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return effect;
|
||||
}
|
||||
|
||||
|
||||
static JokerEffect brainstorm_joker_effect(Joker *joker, Card *scored_card, enum JokerEvent joker_event)
|
||||
{
|
||||
JokerEffect effect = {0};
|
||||
static bool in_brainstorm = false;
|
||||
if (in_brainstorm)
|
||||
// No need for this kind of init since these Jokers
|
||||
// will have their data copied when needed
|
||||
if (joker_event == JOKER_EVENT_ON_JOKER_CREATED || joker_event == JOKER_EVENT_ON_ROUND_END)
|
||||
{
|
||||
return effect;
|
||||
}
|
||||
|
||||
// find ourselves in the Jokers list
|
||||
List* jokers = get_jokers_list();
|
||||
JokerObject* first_joker = list_get_at_idx(jokers, 0);
|
||||
|
||||
if (first_joker != NULL && first_joker->joker->id != JOKER_BRAINSTORM_ID)
|
||||
ListItr itr = list_itr_create(jokers);
|
||||
JokerObject* copied_joker_object;
|
||||
while((copied_joker_object = list_itr_next(&itr)))
|
||||
{
|
||||
// Static var to avoid infinite blueprint + brainstorm loops
|
||||
in_brainstorm = true;
|
||||
effect = joker_get_score_effect(first_joker->joker, scored_card, joker_event);
|
||||
in_brainstorm = false;
|
||||
if (copied_joker_object->joker == joker)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// This shouldn't happen since if we are a scoring Joker, we should always
|
||||
// be part of the Jokers list, but being extra careful doesn't cost much
|
||||
if (copied_joker_object == NULL)
|
||||
{
|
||||
return effect;
|
||||
}
|
||||
|
||||
// find the copied Joker, may need to bounce around Blueprints and a Brainstorm
|
||||
// If we encounter NULL, we have a Blueprint at the end of the list that can't copy anything.
|
||||
// If we go through a Brainstorms twice, we will be in a loop and need to exit
|
||||
u8 brainstorm_counter = 0;
|
||||
do
|
||||
{
|
||||
switch (copied_joker_object->joker->id)
|
||||
{
|
||||
// get the next Joker for Blueprint
|
||||
case BLUEPRINT_JOKER_ID:
|
||||
copied_joker_object = list_itr_next(&itr);
|
||||
break;
|
||||
|
||||
// Get the first (leftmost) Joker for Brainstorm
|
||||
case BRAINSTORM_JOKER_ID:
|
||||
brainstorm_counter++;
|
||||
itr = list_itr_create(jokers);
|
||||
copied_joker_object = list_itr_next(&itr);
|
||||
break;
|
||||
|
||||
// We encountered a Joker that isn't a Copying Joker and copy it now
|
||||
// but how we copy it depends on this Joker's ID because they don't
|
||||
// all handle data the same way.
|
||||
default:
|
||||
u8 copied_joker_id = copied_joker_object->joker->id;
|
||||
const JokerInfo* copied_joker_info = get_joker_registry_entry(copied_joker_id);
|
||||
|
||||
// Copy the persistent data
|
||||
joker->persistent_state = copied_joker_object->joker->persistent_state;
|
||||
|
||||
// Then regardless of if we copied the data above, apply the
|
||||
// copied JokerEffect function to the local data
|
||||
effect = copied_joker_info->joker_effect(joker, scored_card, joker_event);
|
||||
|
||||
// make also sure we don't expire
|
||||
effect.expire = false;
|
||||
|
||||
// exit the loop
|
||||
copied_joker_object = NULL;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
while(copied_joker_object != NULL && brainstorm_counter < 2);
|
||||
|
||||
return effect;
|
||||
}
|
||||
|
||||
@@ -887,7 +921,7 @@ static JokerEffect brainstorm_joker_effect(Joker *joker, Card *scored_card, enum
|
||||
static JokerEffect hack_joker_effect(Joker *joker, Card *scored_card, enum JokerEvent joker_event)
|
||||
{
|
||||
JokerEffect effect = {0};
|
||||
s32* p_last_retriggered_index = &(joker->data);
|
||||
s32* p_last_retriggered_index = &(joker->scoring_state);
|
||||
|
||||
switch (joker_event)
|
||||
{
|
||||
@@ -926,8 +960,8 @@ __attribute__((unused))
|
||||
static JokerEffect seltzer_joker_effect(Joker *joker, Card *scored_card, enum JokerEvent joker_event)
|
||||
{
|
||||
JokerEffect effect = {0};
|
||||
s16* p_last_retriggered_idx = &(joker->halves.data0);
|
||||
s16* p_hands_left_until_exp = &(joker->halves.data1);
|
||||
s32* p_last_retriggered_idx = &(joker->scoring_state);
|
||||
s32* p_hands_left_until_exp = &(joker->persistent_state);
|
||||
|
||||
switch (joker_event)
|
||||
{
|
||||
@@ -938,22 +972,9 @@ static JokerEffect seltzer_joker_effect(Joker *joker, Card *scored_card, enum Jo
|
||||
case JOKER_EVENT_ON_HAND_PLAYED:
|
||||
*p_last_retriggered_idx = UNDEFINED;
|
||||
break;
|
||||
|
||||
case JOKER_EVENT_ON_HAND_SCORED_END:
|
||||
*p_hands_left_until_exp -= 1;
|
||||
if (*p_hands_left_until_exp <= 0)
|
||||
{
|
||||
effect.expire = true;
|
||||
effect.message = "Drank!";
|
||||
}
|
||||
else
|
||||
{
|
||||
effect.message = "-1";
|
||||
}
|
||||
break;
|
||||
|
||||
case JOKER_EVENT_ON_CARD_SCORED_END:
|
||||
// Works the same way as Dusk, but if it can still trigger
|
||||
// Works the same way as Dusk, but checks if it can still trigger
|
||||
if (*p_hands_left_until_exp > 0)
|
||||
{
|
||||
effect.retrigger = (*p_last_retriggered_idx < get_scored_card_index());
|
||||
@@ -965,6 +986,19 @@ static JokerEffect seltzer_joker_effect(Joker *joker, Card *scored_card, enum Jo
|
||||
}
|
||||
break;
|
||||
|
||||
case JOKER_EVENT_ON_HAND_SCORED_END:
|
||||
if (*p_hands_left_until_exp > 0)
|
||||
{
|
||||
(*p_hands_left_until_exp)--;
|
||||
effect.message = "-1";
|
||||
}
|
||||
else
|
||||
{
|
||||
effect.expire = true;
|
||||
effect.message = "Drank!";
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -976,7 +1010,7 @@ static JokerEffect seltzer_joker_effect(Joker *joker, Card *scored_card, enum Jo
|
||||
static JokerEffect sock_and_buskin_joker_effect(Joker *joker, Card *scored_card, enum JokerEvent joker_event)
|
||||
{
|
||||
JokerEffect effect = {0};
|
||||
s32* p_last_retriggered_face_index = &(joker->data);
|
||||
s32* p_last_retriggered_face_index = &(joker->scoring_state);
|
||||
|
||||
switch (joker_event)
|
||||
{
|
||||
@@ -986,7 +1020,7 @@ static JokerEffect sock_and_buskin_joker_effect(Joker *joker, Card *scored_card,
|
||||
|
||||
case JOKER_EVENT_ON_CARD_SCORED_END:
|
||||
// Works the same way as Dusk, but for face cards
|
||||
effect.retrigger = (*p_last_retriggered_face_index < get_scored_card_index() && card_is_face(scored_card));
|
||||
effect.retrigger = ((*p_last_retriggered_face_index < get_scored_card_index()) && card_is_face(scored_card));
|
||||
if (effect.retrigger)
|
||||
{
|
||||
*p_last_retriggered_face_index = get_scored_card_index();
|
||||
@@ -1013,57 +1047,57 @@ static JokerEffect sock_and_buskin_joker_effect(Joker *joker, Card *scored_card,
|
||||
*/
|
||||
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... 2
|
||||
{ COMMON_JOKER, 5, wrathful_joker_effect }, // 3
|
||||
{ COMMON_JOKER, 5, gluttonous_joker_effect }, // 4
|
||||
{ COMMON_JOKER, 3, jolly_joker_effect }, // 5
|
||||
{ COMMON_JOKER, 4, zany_joker_effect }, // 6
|
||||
{ COMMON_JOKER, 4, mad_joker_effect }, // 7
|
||||
{ COMMON_JOKER, 4, crazy_joker_effect }, // 8
|
||||
{ COMMON_JOKER, 4, droll_joker_effect }, // 9
|
||||
{ COMMON_JOKER, 3, sly_joker_effect }, // 10
|
||||
{ COMMON_JOKER, 4, wily_joker_effect }, // 11
|
||||
{ COMMON_JOKER, 4, clever_joker_effect }, // 12
|
||||
{ COMMON_JOKER, 4, devious_joker_effect }, // 13
|
||||
{ COMMON_JOKER, 4, crafty_joker_effect }, // 14
|
||||
{ COMMON_JOKER, 5, half_joker_effect }, // 15
|
||||
{ UNCOMMON_JOKER, 8, joker_stencil_effect }, // 16
|
||||
{ COMMON_JOKER, 5, photograph_joker_effect, }, // 17
|
||||
{ COMMON_JOKER, 4, walkie_talkie_joker_effect }, // 18
|
||||
{ COMMON_JOKER, 5, banner_joker_effect }, // 19
|
||||
{ UNCOMMON_JOKER, 6, blackboard_joker_effect }, // 20
|
||||
{ COMMON_JOKER, 5, mystic_summit_joker_effect }, // 21
|
||||
{ COMMON_JOKER, 4, misprint_joker_effect }, // 22
|
||||
{ COMMON_JOKER, 4, even_steven_joker_effect }, // 23
|
||||
{ COMMON_JOKER, 5, blue_joker_effect }, // 24
|
||||
{ COMMON_JOKER, 4, odd_todd_joker_effect }, // 25
|
||||
{ UNCOMMON_JOKER, 7, joker_effect_noop, }, // 26 Shortcut
|
||||
{ COMMON_JOKER, 4, business_card_joker_effect }, // 27
|
||||
{ COMMON_JOKER, 4, scary_face_joker_effect }, // 28
|
||||
{ UNCOMMON_JOKER, 7, bootstraps_joker_effect }, // 29
|
||||
{ UNCOMMON_JOKER, 5, joker_effect_noop }, // 30 Pareidolia
|
||||
{ COMMON_JOKER, 6, reserved_parking_joker_effect }, // 31
|
||||
{ COMMON_JOKER, 4, abstract_joker_effect }, // 32
|
||||
{ UNCOMMON_JOKER, 6, bull_joker_effect }, // 33
|
||||
{ RARE_JOKER, 8, the_duo_joker_effect }, // 34
|
||||
{ RARE_JOKER, 8, the_trio_joker_effect }, // 35
|
||||
{ RARE_JOKER, 8, the_family_joker_effect }, // 36
|
||||
{ RARE_JOKER, 8, the_order_joker_effect }, // 37
|
||||
{ RARE_JOKER, 8, the_tribe_joker_effect }, // 38
|
||||
{ RARE_JOKER, 10, blueprint_joker_effect }, // 39
|
||||
{ RARE_JOKER, 10, brainstorm_joker_effect }, // 40
|
||||
{ COMMON_JOKER, 5, raised_fist_joker_effect }, // 41
|
||||
{ COMMON_JOKER, 4, smiley_face_joker_effect }, // 42
|
||||
{ UNCOMMON_JOKER, 6, acrobat_joker_effect }, // 43
|
||||
{ UNCOMMON_JOKER, 5, dusk_joker_effect }, // 44
|
||||
{ UNCOMMON_JOKER, 6, sock_and_buskin_joker_effect }, // 45
|
||||
{ UNCOMMON_JOKER, 6, hack_joker_effect }, // 46
|
||||
{ COMMON_JOKER, 4, hanging_chad_joker_effect }, // 47
|
||||
{ UNCOMMON_JOKER, 7, joker_effect_noop, }, // 48 Four Fingers
|
||||
{ COMMON_JOKER, 4, scholar_joker_effect }, // 49
|
||||
{ UNCOMMON_JOKER, 8, fibonnaci_joker_effect }, // 50
|
||||
{ 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... 2
|
||||
{ COMMON_JOKER, 5, wrathful_joker_effect }, // 3
|
||||
{ COMMON_JOKER, 5, gluttonous_joker_effect }, // 4
|
||||
{ COMMON_JOKER, 3, jolly_joker_effect }, // 5
|
||||
{ COMMON_JOKER, 4, zany_joker_effect }, // 6
|
||||
{ COMMON_JOKER, 4, mad_joker_effect }, // 7
|
||||
{ COMMON_JOKER, 4, crazy_joker_effect }, // 8
|
||||
{ COMMON_JOKER, 4, droll_joker_effect }, // 9
|
||||
{ COMMON_JOKER, 3, sly_joker_effect }, // 10
|
||||
{ COMMON_JOKER, 4, wily_joker_effect }, // 11
|
||||
{ COMMON_JOKER, 4, clever_joker_effect }, // 12
|
||||
{ COMMON_JOKER, 4, devious_joker_effect }, // 13
|
||||
{ COMMON_JOKER, 4, crafty_joker_effect }, // 14
|
||||
{ COMMON_JOKER, 5, half_joker_effect }, // 15
|
||||
{ UNCOMMON_JOKER, 8, joker_stencil_effect }, // 16
|
||||
{ COMMON_JOKER, 5, photograph_joker_effect, }, // 17
|
||||
{ COMMON_JOKER, 4, walkie_talkie_joker_effect }, // 18
|
||||
{ COMMON_JOKER, 5, banner_joker_effect }, // 19
|
||||
{ UNCOMMON_JOKER, 6, blackboard_joker_effect }, // 20
|
||||
{ COMMON_JOKER, 5, mystic_summit_joker_effect }, // 21
|
||||
{ COMMON_JOKER, 4, misprint_joker_effect }, // 22
|
||||
{ COMMON_JOKER, 4, even_steven_joker_effect }, // 23
|
||||
{ COMMON_JOKER, 5, blue_joker_effect }, // 24
|
||||
{ COMMON_JOKER, 4, odd_todd_joker_effect }, // 25
|
||||
{ UNCOMMON_JOKER, 7, joker_effect_noop, }, // 26 Shortcut
|
||||
{ COMMON_JOKER, 4, business_card_joker_effect }, // 27
|
||||
{ COMMON_JOKER, 4, scary_face_joker_effect }, // 28
|
||||
{ UNCOMMON_JOKER, 7, bootstraps_joker_effect }, // 29
|
||||
{ UNCOMMON_JOKER, 5, joker_effect_noop }, // 30 Pareidolia
|
||||
{ COMMON_JOKER, 6, reserved_parking_joker_effect }, // 31
|
||||
{ COMMON_JOKER, 4, abstract_joker_effect }, // 32
|
||||
{ UNCOMMON_JOKER, 6, bull_joker_effect }, // 33
|
||||
{ RARE_JOKER, 8, the_duo_joker_effect }, // 34
|
||||
{ RARE_JOKER, 8, the_trio_joker_effect }, // 35
|
||||
{ RARE_JOKER, 8, the_family_joker_effect }, // 36
|
||||
{ RARE_JOKER, 8, the_order_joker_effect }, // 37
|
||||
{ RARE_JOKER, 8, the_tribe_joker_effect }, // 38
|
||||
{ RARE_JOKER, 10, blueprint_brainstorm_joker_effect }, // 39 Blueprint
|
||||
{ RARE_JOKER, 10, blueprint_brainstorm_joker_effect }, // 40 Brainstorm
|
||||
{ COMMON_JOKER, 5, raised_fist_joker_effect }, // 41
|
||||
{ COMMON_JOKER, 4, smiley_face_joker_effect }, // 42
|
||||
{ UNCOMMON_JOKER, 6, acrobat_joker_effect }, // 43
|
||||
{ UNCOMMON_JOKER, 5, dusk_joker_effect }, // 44
|
||||
{ UNCOMMON_JOKER, 6, sock_and_buskin_joker_effect }, // 45
|
||||
{ UNCOMMON_JOKER, 6, hack_joker_effect }, // 46
|
||||
{ COMMON_JOKER, 4, hanging_chad_joker_effect }, // 47
|
||||
{ UNCOMMON_JOKER, 7, joker_effect_noop, }, // 48 Four Fingers
|
||||
{ COMMON_JOKER, 4, scholar_joker_effect }, // 49
|
||||
{ UNCOMMON_JOKER, 8, fibonnaci_joker_effect }, // 50
|
||||
|
||||
// The following jokers don't have sprites yet,
|
||||
// uncomment them when their sprites are added.
|
||||
|
||||
Reference in New Issue
Block a user