Fixed stack top bugs in joker_effects.c - e.g. Blackboard activated if just the first card in hand was not spades/clubs

This commit is contained in:
MeirGavish
2025-08-08 00:01:36 +03:00
parent 4492176df2
commit 5e6d28c663
3 changed files with 15 additions and 11 deletions
+1
View File
@@ -77,6 +77,7 @@ typedef struct CardObject CardObject; // forward declaration, actually declared
typedef struct JokerObject JokerObject; typedef struct JokerObject JokerObject;
CardObject** get_hand_array(void); CardObject** get_hand_array(void);
int get_hand_top(void); int get_hand_top(void);
int hand_get_size(void);
CardObject** get_played_array(void); CardObject** get_played_array(void);
int get_played_top(void); int get_played_top(void);
JokerObject** get_jokers(void); JokerObject** get_jokers(void);
+5 -5
View File
@@ -148,6 +148,11 @@ int get_hand_top(void) {
return hand_top; return hand_top;
} }
int hand_get_size(void)
{
return hand_top + 1;
}
CardObject **get_played_array(void) { CardObject **get_played_array(void) {
return played; return played;
} }
@@ -853,11 +858,6 @@ void hand_change_sort()
sort_cards(); sort_cards();
} }
int hand_get_size()
{
return hand_top + 1;
}
int hand_get_max_size() int hand_get_max_size()
{ {
return hand_size; return hand_size;
+9 -6
View File
@@ -1,3 +1,4 @@
#include "game.h"
#include "joker.h" #include "joker.h"
#include "util.h" #include "util.h"
#include "hand_analysis.h" #include "hand_analysis.h"
@@ -178,7 +179,8 @@ static JokerEffect half_joker_effect(Joker *joker, Card *scored_card) {
if (scored_card != NULL) if (scored_card != NULL)
return effect; // if card != null, we are not at the end-phase of scoring yet return effect; // if card != null, we are not at the end-phase of scoring yet
if (get_played_top() + 1 <= 3) // game.c has hand_get_size() but it's not accesible here int played_size = get_played_top() + 1;
if (played_size <= 3)
effect.mult = 20; effect.mult = 20;
return effect; return effect;
@@ -190,12 +192,13 @@ static JokerEffect joker_stencil_effect(Joker *joker, Card *scored_card) {
return effect; // if card != null, we are not at the end-phase of scoring yet return effect; // if card != null, we are not at the end-phase of scoring yet
// +1 xmult per empty joker slot... // +1 xmult per empty joker slot...
int jokers_top = get_jokers_top(); int num_jokers = get_jokers_top() + 1;
effect.xmult = (MAX_JOKERS_HELD_SIZE-1) - jokers_top;
effect.xmult = (MAX_JOKERS_HELD_SIZE) - num_jokers;
// ...and also each stencil_joker adds +1 xmult // ...and also each stencil_joker adds +1 xmult
JokerObject** jokers = get_jokers(); JokerObject** jokers = get_jokers();
for (int i = 0; i < jokers_top; i++ ) for (int i = 0; i < num_jokers; i++ )
{ {
if (jokers[i]->joker->id == JOKER_STENCIL_ID) if (jokers[i]->joker->id == JOKER_STENCIL_ID)
effect.xmult++; effect.xmult++;
@@ -271,8 +274,8 @@ static JokerEffect blackboard_joker_effect(Joker *joker, Card *scored_card) {
bool all_cards_are_spades_or_clubs = true; bool all_cards_are_spades_or_clubs = true;
CardObject** hand = get_hand_array(); CardObject** hand = get_hand_array();
int hand_top = get_hand_top(); int hand_size = hand_get_size();
for (int i = 0; i < hand_top; i++ ) for (int i = 0; i < hand_size; i++ )
{ {
u8 suit = hand[i]->card->suit; u8 suit = hand[i]->card->suit;
if (suit == HEARTS || suit == DIAMONDS) { if (suit == HEARTS || suit == DIAMONDS) {