GBAlatro
A Demake of Balatro for the GBA
Loading...
Searching...
No Matches
skip_tag.c File Reference

Implementation of functions related to the handling of Skip Tags. More...

#include "skip_tag.h"
#include "audio_utils.h"
#include "game/blind_select.h"
#include "game_variables.h"
#include "joker.h"
#include "mgba_logger.h"
#include "pool.h"
#include "skip_tags_gfx.h"
#include "soundbank.h"
#include "state_machine.h"
#include "timer.h"
#include "util.h"
#include <stdlib.h>
#include <tonc.h>

Go to the source code of this file.

Data Structures

struct  TagProcessInfo
 

Macros

#define MAX_NON_OVERLAPING_TAG_SPRITES   5
 
#define SKIP_TAG_HIDE_X_OFFSET   20
 
#define SKIP_TAG_GET_BOUNCE_STRENGTH   (float2fx(-0.3f))
 
#define SKIP_TAG_TRIGGER_BOUNCE_STRENGTH   (float2fx(-0.4f))
 
#define NB_ANTE1_SKIP_TAGS   7
 Number of implemented Skip Tags available from Ante 1.
 
#define NB_SKIP_TAG_TYPES   10
 Number of implemented Skip Tags.
 

Enumerations

enum  SkipTagProcessState { SKIP_TAG_PROCESS_STATE_SEARCH , SKIP_TAG_PROCESS_STATE_TRIGGER , SKIP_TAG_PROCESS_STATE_REMOVE , SKIP_TAG_PROCESS_STATE_MAX }
 

Functions

List * get_owned_skip_tags (void)
 Get the owned skip tags list.
 
SkipTag * skip_tag_new (enum SkipTagTypes tag_type)
 Create a new Skip Tag object for the given Tag ID and allocates space for it in the corresponding memory pool.
 
void skip_tag_set_sprite (SkipTag *tag, s16 layer)
 Set the sprite for the given SkipTag, according to its internal ID.
 
void skip_tag_destroy (SkipTag **tag)
 Destroy the given SkipTag, invalidate it in the corresponding memory pool and set the pointer provided to NULL.
 
void set_owned_skip_tags_moved_offscreen (bool move_offscreen)
 Show or hide the owned SkipTag sprites by moving them offscreen to the right.
 
SkipTag * roll_skip_tag (void)
 Create a new SkipTag with a random ID, picked by taking the Ante into account, as some Tags only appear from Ante 2 onwards.
 
static int get_skip_tag_sprites_spacing (void)
 
static void rearrange_skip_tag_sprites (int nb_owned_tags, int tag_spacing)
 
GBAL_UNUSED bool skip_tag_is_owned (enum SkipTagTypes tag_type)
 Checks if the given tag type is present in owned Tags list.
 
int skip_tag_count (enum SkipTagTypes tag_type)
 Counts how many tags of a certain type we own.
 
void add_skip_tag (SkipTag **blind_tag)
 Adds the SkipTag to the owned list, snaps it into position and sets the original pointer to NULL.
 
void remove_skip_tag (int tag_idx)
 Pops the Tag at index in owned list, destroys it and rearranges the remaining Tags' sprites.
 
void remove_all_skip_tags (void)
 Delete all owned Skip Tags.
 
static void skip_tag_search_for_event (void)
 
static void skip_tag_trigger_for_event (void)
 
static void skip_tag_remove_for_event (void)
 
enum SkipTagProcStage skip_tag_process_get_proc_stage (void)
 Recover the current stage of the Tag processing.
 
void skip_tag_process_start (enum SkipTagEvent checked_tag_event)
 Start Skip Tag processing for the specified event.
 
void skip_tag_process_pause (void)
 Suspend the processing of Skip Tags.
 
void skip_tag_process_resume (void)
 Resume the processing of Skip Tags.
 

Variables

static const BG_POINT OWNED_SKIP_TAGS_BASE_POS = {219, 97}
 
static const int OWNED_SKIP_TAGS_STACK_HEIGHT = 64
 
static const int OWNED_SKIP_TAGS_SPACING = 12
 
static const u8 ante1_skip_tags_roll_table [NB_ANTE1_SKIP_TAGS]
 
static const u8 all_skip_tags_roll_table [NB_SKIP_TAG_TYPES]
 
static List s_owned_skip_tags
 
static StateInfo tag_process_state_fn [SKIP_TAG_PROCESS_STATE_MAX]
 
static StateMachine tag_process_sm
 
static TagProcessInfo s_tag_process_info
 
static SkipTag * s_consumed_tag = NULL
 
static int s_consumed_tag_idx = 0
 
static SkipTagCallback s_consumed_tag_effect_func = NULL
 

Detailed Description

Implementation of functions related to the handling of Skip Tags.

Definition in file skip_tag.c.

Macro Definition Documentation

◆ MAX_NON_OVERLAPING_TAG_SPRITES

#define MAX_NON_OVERLAPING_TAG_SPRITES   5

Definition at line 22 of file skip_tag.c.

◆ NB_ANTE1_SKIP_TAGS

#define NB_ANTE1_SKIP_TAGS   7

Number of implemented Skip Tags available from Ante 1.

Definition at line 40 of file skip_tag.c.

◆ NB_SKIP_TAG_TYPES

#define NB_SKIP_TAG_TYPES   10

Number of implemented Skip Tags.

Definition at line 46 of file skip_tag.c.

◆ SKIP_TAG_GET_BOUNCE_STRENGTH

#define SKIP_TAG_GET_BOUNCE_STRENGTH   (float2fx(-0.3f))

Definition at line 25 of file skip_tag.c.

◆ SKIP_TAG_HIDE_X_OFFSET

#define SKIP_TAG_HIDE_X_OFFSET   20

Definition at line 23 of file skip_tag.c.

◆ SKIP_TAG_TRIGGER_BOUNCE_STRENGTH

#define SKIP_TAG_TRIGGER_BOUNCE_STRENGTH   (float2fx(-0.4f))

Definition at line 26 of file skip_tag.c.

Enumeration Type Documentation

◆ SkipTagProcessState

enum SkipTagProcessState

Definition at line 302 of file skip_tag.c.

Function Documentation

◆ add_skip_tag()

void add_skip_tag ( SkipTag **  blind_tag)

Adds the SkipTag to the owned list, snaps it into position and sets the original pointer to NULL.

Parameters
blind_tag

Definition at line 230 of file skip_tag.c.

◆ get_owned_skip_tags()

List * get_owned_skip_tags ( void  )

Get the owned skip tags list.

Returns
List*

Definition at line 76 of file skip_tag.c.

◆ get_skip_tag_sprites_spacing()

static int get_skip_tag_sprites_spacing ( void  )
inlinestatic

Definition at line 169 of file skip_tag.c.

◆ rearrange_skip_tag_sprites()

static void rearrange_skip_tag_sprites ( int  nb_owned_tags,
int  tag_spacing 
)
static

Definition at line 177 of file skip_tag.c.

◆ remove_all_skip_tags()

void remove_all_skip_tags ( void  )

Delete all owned Skip Tags.

Definition at line 289 of file skip_tag.c.

◆ remove_skip_tag()

void remove_skip_tag ( int  tag_idx)

Pops the Tag at index in owned list, destroys it and rearranges the remaining Tags' sprites.

Parameters
tag_idxindex of the Tag to remove in owned list

Definition at line 279 of file skip_tag.c.

◆ roll_skip_tag()

SkipTag * roll_skip_tag ( void  )

Create a new SkipTag with a random ID, picked by taking the Ante into account, as some Tags only appear from Ante 2 onwards.

Returns
SkipTag pointer to the new SkipTag object
See also
skip_tag_new

Definition at line 154 of file skip_tag.c.

◆ set_owned_skip_tags_moved_offscreen()

void set_owned_skip_tags_moved_offscreen ( bool  move_offscreen)

Show or hide the owned SkipTag sprites by moving them offscreen to the right.

Parameters
move_offscreentrue to move the sprites offscreen, false to return them onscreen

Definition at line 141 of file skip_tag.c.

◆ skip_tag_count()

int skip_tag_count ( enum SkipTagTypes  tag_type)

Counts how many tags of a certain type we own.

Parameters
tag_typeSkipTagType to count
Returns
int

Definition at line 213 of file skip_tag.c.

◆ skip_tag_destroy()

void skip_tag_destroy ( SkipTag **  tag)

Destroy the given SkipTag, invalidate it in the corresponding memory pool and set the pointer provided to NULL.

Parameters
tagpointer of pointer to the SkipTag we want to destroy

Definition at line 128 of file skip_tag.c.

◆ skip_tag_is_owned()

GBAL_UNUSED bool skip_tag_is_owned ( enum SkipTagTypes  tag_type)

Checks if the given tag type is present in owned Tags list.

Parameters
tag_typeSkipTagType to check
Returns
true if tag type is present, false otherwise

Definition at line 197 of file skip_tag.c.

◆ skip_tag_new()

SkipTag * skip_tag_new ( enum SkipTagTypes  tag_type)

Create a new Skip Tag object for the given Tag ID and allocates space for it in the corresponding memory pool.

Parameters
tag_typethe ID of the Tag we want
Returns
a pointer to a new SkipTag object
See also
SkipTagTypes, SkipTag

Definition at line 83 of file skip_tag.c.

◆ skip_tag_process_get_proc_stage()

enum SkipTagProcStage skip_tag_process_get_proc_stage ( void  )

Recover the current stage of the Tag processing.

Returns
enum SkipTagProcStage

Definition at line 339 of file skip_tag.c.

◆ skip_tag_process_pause()

void skip_tag_process_pause ( void  )

Suspend the processing of Skip Tags.

This is called automatically when Tags have finished processing for the current SkipTagEvent, but it can be invoked by a game state to temporarily pause the processing while doing some other thing, like showing an animation. Call skip_tag_process_resume to pick up processing where it was left.

See also
skip_tag_process_resume

Definition at line 357 of file skip_tag.c.

◆ skip_tag_process_resume()

void skip_tag_process_resume ( void  )

Resume the processing of Skip Tags.

After skip_tag_process_pause was called, use this function to resume Tag processing.

See also
skip_tag_process_pause

Definition at line 366 of file skip_tag.c.

◆ skip_tag_process_start()

void skip_tag_process_start ( enum SkipTagEvent  checked_tag_event)

Start Skip Tag processing for the specified event.

The "processing" of a Tag refers to the selection of the triggered Tag, the triggering of the associated effect itself, the little bounce animation that comes with it and finally the removal of the Tag.

Processing will occur in its own state machine and will run independently until it either completes, or is paused/resumed with the associated functions.

During this time, skip_tag_process_get_proc_stage may be called on every frame so that the calling state machine can stay up to date with the Tags processing stage and wait for it to finish or perform relevant actions.

Parameters
checked_tag_eventthe event for which the owned Tags will be evaluated
See also
skip_tag_process_pause, skip_tag_process_resume, skip_tag_process_get_proc_stage

Definition at line 344 of file skip_tag.c.

◆ skip_tag_remove_for_event()

static void skip_tag_remove_for_event ( void  )
static

Definition at line 452 of file skip_tag.c.

◆ skip_tag_search_for_event()

static void skip_tag_search_for_event ( void  )
static

Definition at line 386 of file skip_tag.c.

◆ skip_tag_set_sprite()

void skip_tag_set_sprite ( SkipTag *  tag,
s16  layer 
)

Set the sprite for the given SkipTag, according to its internal ID.

Parameters
tagpointer to the SkipTag object
layersprite layer for the new Sprite, as an offset to the starting layer for the SKIP_TAG sprite type

Definition at line 94 of file skip_tag.c.

◆ skip_tag_trigger_for_event()

static void skip_tag_trigger_for_event ( void  )
static

Definition at line 421 of file skip_tag.c.

Variable Documentation

◆ all_skip_tags_roll_table

const u8 all_skip_tags_roll_table[NB_SKIP_TAG_TYPES]
static
Initial value:
= {
SKIP_TAG_TYPE_INVESTMENT,
SKIP_TAG_TYPE_BOSS,
SKIP_TAG_TYPE_HANDY,
SKIP_TAG_TYPE_GARBAGE,
SKIP_TAG_TYPE_DOUBLE,
SKIP_TAG_TYPE_JUGGLE,
SKIP_TAG_TYPE_D6,
SKIP_TAG_TYPE_TOP_UP,
SKIP_TAG_TYPE_SPEED,
SKIP_TAG_TYPE_ECONOMY
}

Definition at line 61 of file skip_tag.c.

◆ ante1_skip_tags_roll_table

const u8 ante1_skip_tags_roll_table[NB_ANTE1_SKIP_TAGS]
static
Initial value:
= {
SKIP_TAG_TYPE_INVESTMENT,
SKIP_TAG_TYPE_BOSS,
SKIP_TAG_TYPE_DOUBLE,
SKIP_TAG_TYPE_JUGGLE,
SKIP_TAG_TYPE_D6,
SKIP_TAG_TYPE_SPEED,
SKIP_TAG_TYPE_ECONOMY
}

Definition at line 50 of file skip_tag.c.

◆ OWNED_SKIP_TAGS_BASE_POS

const BG_POINT OWNED_SKIP_TAGS_BASE_POS = {219, 97}
static

Definition at line 30 of file skip_tag.c.

◆ OWNED_SKIP_TAGS_SPACING

const int OWNED_SKIP_TAGS_SPACING = 12
static

Definition at line 33 of file skip_tag.c.

◆ OWNED_SKIP_TAGS_STACK_HEIGHT

const int OWNED_SKIP_TAGS_STACK_HEIGHT = 64
static

Definition at line 32 of file skip_tag.c.

◆ s_consumed_tag

SkipTag* s_consumed_tag = NULL
static

Definition at line 382 of file skip_tag.c.

◆ s_consumed_tag_effect_func

SkipTagCallback s_consumed_tag_effect_func = NULL
static

Definition at line 384 of file skip_tag.c.

◆ s_consumed_tag_idx

int s_consumed_tag_idx = 0
static

Definition at line 383 of file skip_tag.c.

◆ s_owned_skip_tags

List s_owned_skip_tags
static

Definition at line 74 of file skip_tag.c.

◆ s_tag_process_info

TagProcessInfo s_tag_process_info
static
Initial value:
= {
.tags_timer = TM_ZERO,
.tag_process_state = SKIP_TAG_PROCESS_STATE_MAX,
.tag_event = SKIP_TAG_EVENT_NONE,
.tag_proc_stage = SKIP_TAG_PROCESS_STAGE_NONE,
}

Definition at line 332 of file skip_tag.c.

◆ tag_process_sm

StateMachine tag_process_sm
static
Initial value:
=
STATE_MACHINE_DEFINE(tag_process_state_fn, SKIP_TAG_PROCESS_STATE_MAX)

Definition at line 320 of file skip_tag.c.

◆ tag_process_state_fn

StateInfo tag_process_state_fn[SKIP_TAG_PROCESS_STATE_MAX]
static
Initial value:
= {
STATE_INFO_UPDATE_FN_ONLY(skip_tag_search_for_event),
STATE_INFO_UPDATE_FN_ONLY(skip_tag_trigger_for_event),
}

Definition at line 314 of file skip_tag.c.