Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Triforce Hunt counter out of CRT unsafe area and enable L button to switch to a permanent Triforce counter/Gold Skull token counter #2084

Open
wants to merge 3 commits into
base: Dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
796 changes: 400 additions & 396 deletions ASM/build/asm_symbols.txt

Large diffs are not rendered by default.

Binary file modified ASM/build/bundle.o
Binary file not shown.
742 changes: 371 additions & 371 deletions ASM/build/c_symbols.txt

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions ASM/c/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ void c_init() {
void before_game_state_update() {
handle_pending_items();
handle_dpad();
handle_lbutton_and_minimap_state();
update_misc_colors();
update_hud_colors();
process_extern_ctxt();
Expand All @@ -53,6 +54,7 @@ void after_game_state_update() {
// Else this will cause graphical and/or lag issues on some emulators when pausing.
if (R_PAUSE_BG_PRERENDER_STATE != PAUSE_BG_PRERENDER_PROCESS) {
draw_dungeon_info(&(z64_ctxt.gfx->overlay));
draw_skull_count(&(z64_ctxt.gfx->overlay));
draw_triforce_count(&(z64_ctxt.gfx->overlay));
draw_silver_rupee_count(&z64_game, &(z64_ctxt.gfx->overlay));
draw_illegal_model_text(&(z64_ctxt.gfx->overlay));
Expand Down
107 changes: 100 additions & 7 deletions ASM/c/triforce.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,126 @@ static uint32_t render_triforce_flag = 0;
#define TRIFORCE_FRAMES_VISIBLE 100 // 20 Frames seems to be about 1 second
#define TRIFORCE_FRAMES_FADE_AWAY 80
#define TRIFORCE_FRAMES_FADE_INTO 5
uint8_t minimap_triforce_state = 0;

void set_triforce_render() {
render_triforce_flag = 1;
frames = frames > TRIFORCE_FRAMES_FADE_INTO ? TRIFORCE_FRAMES_FADE_INTO : frames;
}

void handle_lbutton_and_minimap_state() {
switch (minimap_triforce_state) {
case MINIMAP_ON_SCREEN:
R_MINIMAP_DISABLED = render_triforce_flag == 1;
if (z64_game.common.input[0].pad_pressed.l) {
minimap_triforce_state++;
if (minimap_triforce_state > NONE_ON_SCREEN) {
minimap_triforce_state = MINIMAP_ON_SCREEN;
}
PlaySFX(0x4820); //NA_SE_SY_DUMMY_32 (Notification)
R_MINIMAP_DISABLED = 0;
}
break;
case TRIFORCE_OR_SKULL_ON_SCREEN:
R_MINIMAP_DISABLED = 1;
if (z64_game.common.input[0].pad_pressed.l) {
minimap_triforce_state++;
if (minimap_triforce_state > NONE_ON_SCREEN) {
minimap_triforce_state = MINIMAP_ON_SCREEN;
}
PlaySFX(0x4813); //NA_SE_SY_CAMERA_ZOOM_UP
R_MINIMAP_DISABLED = 1;
}
break;
case NONE_ON_SCREEN:
R_MINIMAP_DISABLED = 1;
if (z64_game.common.input[0].pad_pressed.l) {
minimap_triforce_state++;
if (minimap_triforce_state > NONE_ON_SCREEN) {
minimap_triforce_state = MINIMAP_ON_SCREEN;
}
PlaySFX(0x4814); //NA_SE_SY_CAMERA_ZOOM_DOWN
R_MINIMAP_DISABLED = 1;
}
break;
default:
break;
}
}

void draw_skull_count(z64_disp_buf_t* db) {

if (!CAN_DRAW_TRIFORCE || !(minimap_triforce_state == TRIFORCE_OR_SKULL_ON_SCREEN)) {
return;
}

int pieces = z64_file.gs_tokens;

int pieces_digits = 0;
int pieces_copy = pieces;
while(pieces_copy >= 1) {
pieces_digits++;
pieces_copy /= 10;
}
pieces_digits = pieces_digits == 0 ? 1 : pieces_digits;

// Setup draw location
int str_len = pieces_digits;
int total_w = str_len * font_sprite.tile_w + triforce_sprite.tile_w * 0.9;
// Draw the counter symmetric to the rupee icon at (left, top) = (26, 206)
int draw_x = (Z64_SCREEN_WIDTH - 26) - total_w - 1;
int draw_y_text = 206;
int draw_y_skull = 206;
// Above Triforce counter if there is one.
if (TRIFORCE_HUNT_ENABLED) {
draw_y_text -= font_sprite.tile_h + 1;
draw_y_skull -= font_sprite.tile_h + 1;
}

// Call setup display list
gSPDisplayList(db->p++, &setup_db);
gDPPipeSync(db->p++);

colorRGBA8_t color = { 0xFF, 0xFF, 0xFF, 0xFF};
draw_int(db, z64_file.gs_tokens, draw_x, draw_y_text, color);
draw_x += str_len * font_sprite.tile_w + 1;

gDPPipeSync(db->p++);
gDPSetCombineMode(db->p++, G_CC_MODULATEIA_PRIM, G_CC_MODULATEIA_PRIM);
sprite_load(db, &quest_items_sprite, 11, 1);
sprite_draw(db, &quest_items_sprite, 0, draw_x, draw_y_skull, triforce_sprite.tile_w * 0.9, triforce_sprite.tile_h * 0.9);
}

void draw_triforce_count(z64_disp_buf_t* db) {

// Must be triforce hunt and triforce should be drawable, and we should either be on the pause screen or the render triforce flag should be set
if (!(TRIFORCE_HUNT_ENABLED && CAN_DRAW_TRIFORCE && (render_triforce_flag == 1 || z64_game.pause_ctxt.state == 6))) {
if (!(TRIFORCE_HUNT_ENABLED && CAN_DRAW_TRIFORCE &&
(render_triforce_flag == 1 || z64_game.pause_ctxt.state == 6 || minimap_triforce_state == TRIFORCE_OR_SKULL_ON_SCREEN))) {
return;
}

uint8_t alpha;
// In the pause screen always draw
if (z64_game.pause_ctxt.state == 6) {
if (z64_game.pause_ctxt.state == 6 || minimap_triforce_state == TRIFORCE_OR_SKULL_ON_SCREEN) {
alpha = 255;
frames = frames % (TRIFORCE_SPRITE_FRAMES * FRAMES_PER_CYCLE);
} else {
// Do a fade in/out effect if not in pause screen
if ( frames <= TRIFORCE_FRAMES_FADE_INTO ) {
if (frames <= TRIFORCE_FRAMES_FADE_INTO) {
// Disable minimap until the counter is faded out.
if (minimap_triforce_state == MINIMAP_ON_SCREEN) {
R_MINIMAP_DISABLED = 1;
}
alpha = frames * 255 / TRIFORCE_FRAMES_FADE_INTO;
} else if (frames <= TRIFORCE_FRAMES_FADE_INTO + TRIFORCE_FRAMES_VISIBLE ) {
alpha = 255;
} else if (frames <= TRIFORCE_FRAMES_FADE_INTO + TRIFORCE_FRAMES_VISIBLE + TRIFORCE_FRAMES_FADE_AWAY) {
alpha = (frames - TRIFORCE_FRAMES_FADE_INTO - TRIFORCE_FRAMES_VISIBLE) * 255 / TRIFORCE_FRAMES_FADE_AWAY;
alpha = 255 - alpha;
} else {
if (minimap_triforce_state == MINIMAP_ON_SCREEN) {
R_MINIMAP_DISABLED = 0;
}
render_triforce_flag = 0;
frames = 0;
return;
Expand Down Expand Up @@ -65,9 +157,10 @@ void draw_triforce_count(z64_disp_buf_t* db) {
// Setup draw location
int str_len = required_digits + pieces_digits + 1;
int total_w = str_len * font_sprite.tile_w + triforce_sprite.tile_w;
int draw_x = Z64_SCREEN_WIDTH / 2 - total_w / 2;
int draw_y_text = Z64_SCREEN_HEIGHT - (font_sprite.tile_h * 1.5) + 1;
int draw_y_triforce = Z64_SCREEN_HEIGHT - (triforce_sprite.tile_h * 1.5) + 3 + 1;
// Draw the counter symmetric to the rupee icon at (left, top) = (26, 206)
int draw_x = (Z64_SCREEN_WIDTH - 26) - total_w;
int draw_y_text = 206;
int draw_y_triforce = 206;

// Create collected/required string
char text[str_len + 1];
Expand All @@ -90,7 +183,7 @@ void draw_triforce_count(z64_disp_buf_t* db) {
gDPSetCombineMode(db->p++, G_CC_MODULATEIA_PRIM, G_CC_MODULATEIA_PRIM);
gDPSetPrimColor(db->p++, 0, 0, 0xDA, 0xD3, 0x0B, alpha);

text_print(text , draw_x, draw_y_text);
text_print(text, draw_x, draw_y_text);
draw_x += str_len * font_sprite.tile_w;

gDPSetPrimColor(db->p++, 0, 0, 0xF4, 0xEC, 0x30, alpha);
Expand Down
9 changes: 9 additions & 0 deletions ASM/c/triforce.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ extern uint16_t TRIFORCE_HUNT_ENABLED;
extern uint16_t TRIFORCE_PIECES_REQUIRED;

void draw_triforce_count(z64_disp_buf_t* db);
void draw_skull_count(z64_disp_buf_t* db);
void set_triforce_render();
void handle_lbutton_and_minimap_state();

#define BLOCK_TRIFORCE (0x00000001 | \
0x00000002 | \
Expand All @@ -25,4 +27,11 @@ void set_triforce_render();
(z64_file.game_mode == 0) && \
((z64_event_state_1 & 0x20) == 0))

typedef enum
{
MINIMAP_ON_SCREEN,
TRIFORCE_OR_SKULL_ON_SCREEN,
NONE_ON_SCREEN,
} minimap_triforce_enum;

#endif
2 changes: 2 additions & 0 deletions ASM/c/z64.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
#define BASE_REG(n, r) REG_EDITOR_DATA[(n)*REGS_PER_GROUP + (r)]
#define REG(r) BASE_REG(0, (r))
#define SREG(r) BASE_REG(1, (r))
#define WREG(r) BASE_REG(18, (r))
#define R_PAUSE_BG_PRERENDER_STATE SREG(94)
#define R_MINIMAP_DISABLED WREG(31)

typedef struct {
/* index of z64_col_type in scene file */
Expand Down
27 changes: 27 additions & 0 deletions ASM/src/hacks.asm
Original file line number Diff line number Diff line change
Expand Up @@ -4066,6 +4066,33 @@ courtyard_guards_kill:
; sw t7, 0x1F24(at)
jal ocarina_buttons
nop
;===================================================================================================
; Remove the minimap L button press functions to make our custom one for triforce counter
;===================================================================================================

.orga 0xAE2D0C
; Replaces jal func_800C806C
nop

.orga 0xAE2D28
; Replaces jal func_800C806C
nop

.orga 0xAE2D48
; Replaces sh t7, 0x0DD2(v1)
nop

.orga 0xAE34A0
; Replaces jal func_800C806C
nop

.orga 0xAE34C0
; Replaces jal func_800C806C
nop

.orga 0xAE34D8
; Replaces sh t7, 0x0DD2(v1)
nop

;===================================================================================================
; Overrides the function that gives Fairy Ocarina on the Lost Woods Bridge
Expand Down
Loading
Loading