Refactor blind into a map

This commit is contained in:
Rickey Fehr
2025-10-13 23:36:27 -07:00
parent f36fa5e998
commit 7ee07bb34c
2 changed files with 94 additions and 75 deletions
+27 -13
View File
@@ -5,15 +5,6 @@
#define MAX_ANTE 8 // The GBA's max uint value is around 4 billion, so we're going to not add endless mode for simplicity's sake #define MAX_ANTE 8 // The GBA's max uint value is around 4 billion, so we're going to not add endless mode for simplicity's sake
// +1 is added because we'll actually be indexing at 1, but if something causes you to go to ante 0, there will still be a value there.
static const int ante_lut[MAX_ANTE + 1] = {100, 300, 800, 2000, 5000, 11000, 20000, 35000, 50000};
#define MAX_BLINDS 3
#define SMALL_BLIND 0
#define BIG_BLIND 1
#define BOSS_BLIND 2
#define SMALL_BLIND_PB 1 #define SMALL_BLIND_PB 1
#define BIG_BLIND_PB 2 #define BIG_BLIND_PB 2
#define BOSS_BLIND_PB 3 #define BOSS_BLIND_PB 3
@@ -31,6 +22,14 @@ static const int ante_lut[MAX_ANTE + 1] = {100, 300, 800, 2000, 5000, 11000, 200
#define BLIND_BACKGROUND_SECONDARY_COLOR_INDEX 6 #define BLIND_BACKGROUND_SECONDARY_COLOR_INDEX 6
#define BLIND_BACKGROUND_SHADOW_COLOR_INDEX 7 #define BLIND_BACKGROUND_SHADOW_COLOR_INDEX 7
enum BlindType
{
SMALL_BLIND,
BIG_BLIND,
BOSS_BLIND,
MAX_BLINDS
};
enum BlindState enum BlindState
{ {
BLIND_CURRENT, BLIND_CURRENT,
@@ -39,12 +38,27 @@ enum BlindState
BLIND_SKIPPED BLIND_SKIPPED
}; };
// TODO: Move this to a common interface for other palettes
typedef struct {
const u16* palette;
u32 tid;
u32 pb;
} PaletteInfo;
typedef struct
{
enum BlindType type;
PaletteInfo pal_info;
FIXED multiplier;
s32 reward;
} Blind;
void blind_init(); void blind_init();
int blind_get_requirement(int type, int ante); int blind_get_requirement(enum BlindType type, int ante);
int blind_get_reward(int type); int blind_get_reward(enum BlindType type);
u16 blind_get_color(int type, int index); u16 blind_get_color(enum BlindType type, int index);
Sprite *blind_token_new(int type, int x, int y, int sprite_index); Sprite *blind_token_new(enum BlindType type, int x, int y, int sprite_index);
#endif // BLIND_H #endif // BLIND_H
+66 -61
View File
@@ -4,91 +4,96 @@
#include "blinds_gfx.h" #include "blinds_gfx.h"
#include "graphic_utils.h" #include "graphic_utils.h"
#define SMALL_BLIND_REWARD 3
#define BIG_BLIND_REWARD 4
#define BOSS_BLIND_REWARD 5
// +1 is added because we'll actually be indexing at 1, but if something causes you to go to ante 0, there will still be a value there.
static const int ante_lut[MAX_ANTE + 1] = {100, 300, 800, 2000, 5000, 11000, 20000, 35000, 50000};
// Palettes for the blinds (Transparency, Text Color, Shadow, Highlight, Main Color) Use this: http://www.budmelvin.com/dev/15bitconverter.html // Palettes for the blinds (Transparency, Text Color, Shadow, Highlight, Main Color) Use this: http://www.budmelvin.com/dev/15bitconverter.html
static const u16 small_blind_token_palette[PAL_ROW_LEN] = {0x0000, 0x7FFF, 0x34A1, 0x5DCB, 0x5104, 0x55A0, 0x2D01, 0x34E0}; static const u16 small_blind_token_palette[PAL_ROW_LEN] = {0x0000, 0x7FFF, 0x34A1, 0x5DCB, 0x5104, 0x55A0, 0x2D01, 0x34E0};
static const u16 big_blind_token_palette[PAL_ROW_LEN] = {0x0000, 0x2527, 0x15F5, 0x36FC, 0x1E9C, 0x01B4, 0x0D0A, 0x010E}; static const u16 big_blind_token_palette[PAL_ROW_LEN] = {0x0000, 0x2527, 0x15F5, 0x36FC, 0x1E9C, 0x01B4, 0x0D0A, 0x010E};
static const u16 boss_blind_token_palette[PAL_ROW_LEN] = {0x0000, 0x2CC9, 0x3D0D, 0x5E14, 0x5171, 0x4D0F, 0x2CC8, 0x3089}; // This variable is temporary, each boss blind will have its own unique palette static const u16 boss_blind_token_palette[PAL_ROW_LEN] = {0x0000, 0x2CC9, 0x3D0D, 0x5E14, 0x5171, 0x4D0F, 0x2CC8, 0x3089}; // This variable is temporary, each boss blind will have its own unique palette
static const Blind blindMap[MAX_BLINDS] =
{
{
.type = SMALL_BLIND,
.pal_info =
{
.palette = small_blind_token_palette,
.tid = SMALL_BLIND_TID,
.pb = SMALL_BLIND_PB,
},
.multiplier = FIX_ONE,
.reward = SMALL_BLIND_REWARD,
},
{
.type = BIG_BLIND,
.pal_info =
{
.palette = big_blind_token_palette,
.tid = BIG_BLIND_TID,
.pb = BIG_BLIND_PB,
},
.multiplier = (FIX_ONE * 3) / 2,
.reward = BIG_BLIND_REWARD,
},
{
.type = BOSS_BLIND,
.pal_info =
{
.palette = boss_blind_token_palette,
.tid = BOSS_BLIND_TID,
.pb = BOSS_BLIND_PB,
},
.multiplier = FIX_ONE * 2,
.reward = BOSS_BLIND_REWARD,
},
};
void blind_init() void blind_init()
{ {
// Blind graphics (fighting grit every step of the way as usual) // Blind graphics (fighting grit every step of the way as usual)
GRIT_CPY(&tile_mem[4][SMALL_BLIND_TID], blinds_gfxTiles); GRIT_CPY(&tile_mem[4][SMALL_BLIND_TID], blinds_gfxTiles);
memcpy16(&pal_obj_mem[PAL_ROW_LEN * SMALL_BLIND_PB], &small_blind_token_palette, sizeof(small_blind_token_palette) / 2); for(int i = 0; i < MAX_BLINDS; i++)
memcpy16(&pal_obj_mem[PAL_ROW_LEN * BIG_BLIND_PB], &big_blind_token_palette, sizeof(big_blind_token_palette) / 2); {
// Boss Blind (This is temporary. Each boss blind is unique and will have to have its own graphics and palette which will probably be stored in some huge array) const u16* pal = blindMap[i].pal_info.palette;
memcpy16(&pal_obj_mem[PAL_ROW_LEN * BOSS_BLIND_PB], &boss_blind_token_palette, sizeof(boss_blind_token_palette) / 2);
}
int blind_get_requirement(int type, int ante) u32 pb = blindMap[i].pal_info.pb;
{ u32 pal_offset = PAL_ROW_LEN * pb;
if (ante < 0 || ante > MAX_ANTE)
{
ante = 0; // Ensure ante is within valid range
}
switch (type) memcpy16(&pal_obj_mem[pal_offset], pal, PAL_ROW_LEN);
{
case SMALL_BLIND:
return ante_lut[ante];
case BIG_BLIND:
return (ante_lut[ante] * 3) / 2; // X1.5
case BOSS_BLIND:
return ante_lut[ante] * 2; // X2
default:
return 0; // Invalid type
} }
} }
int blind_get_reward(int type) int blind_get_requirement(enum BlindType type, int ante)
{ {
switch (type) if (ante < 0 || ante > MAX_ANTE) ante = 0; // Ensure ante is within valid range
{
case SMALL_BLIND: return fx2int(blindMap[type].multiplier * ante_lut[ante]);
return 3;
case BIG_BLIND:
return 4;
case BOSS_BLIND:
return 5;
default:
return 0; // Invalid type
}
} }
u16 blind_get_color(int type, int index) int blind_get_reward(enum BlindType type)
{ {
switch (type) return blindMap[type].reward;
{
case SMALL_BLIND:
return small_blind_token_palette[index];
case BIG_BLIND:
return big_blind_token_palette[index];
case BOSS_BLIND:
return boss_blind_token_palette[index];
default:
return 0; // Invalid type
}
} }
Sprite *blind_token_new(int type, int x, int y, int sprite_index) u16 blind_get_color(enum BlindType type, int index)
{ {
Sprite *sprite = NULL; return blindMap[type].pal_info.palette[index];
switch (type)
{
case SMALL_BLIND:
sprite = sprite_new(ATTR0_SQUARE | ATTR0_4BPP, ATTR1_SIZE_32x32, SMALL_BLIND_TID, SMALL_BLIND_PB, sprite_index);
break;
case BIG_BLIND:
sprite = sprite_new(ATTR0_SQUARE | ATTR0_4BPP, ATTR1_SIZE_32x32, BIG_BLIND_TID, BIG_BLIND_PB, sprite_index);
break;
case BOSS_BLIND:
sprite = sprite_new(ATTR0_SQUARE | ATTR0_4BPP, ATTR1_SIZE_32x32, BOSS_BLIND_TID, BOSS_BLIND_PB, sprite_index);
break;
default:
return NULL;
} }
Sprite *blind_token_new(enum BlindType type, int x, int y, int sprite_index)
{
u16 a0 = ATTR0_SQUARE | ATTR0_4BPP;
u16 a1 = ATTR1_SIZE_32x32;
u32 tid = blindMap[type].pal_info.tid, pb = blindMap[type].pal_info.pb;
Sprite* sprite = sprite_new(a0, a1, tid, pb, sprite_index);
sprite_position(sprite, x, y); sprite_position(sprite, x, y);
return sprite; return sprite;