From a976077697228148bd1a5f1bb438b5d6afaa4418 Mon Sep 17 00:00:00 2001 From: Sunk <69110309+Sunketchupm@users.noreply.github.com> Date: Fri, 18 Aug 2023 13:25:39 -0400 Subject: [PATCH] Fix not being able to talk to doors twice (#458) --- src/game/interaction.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/game/interaction.c b/src/game/interaction.c index f225d0b2..28db2776 100644 --- a/src/game/interaction.c +++ b/src/game/interaction.c @@ -119,6 +119,7 @@ static u32 sBackwardKnockbackActions[][3] = { }; static u8 sDisplayingDoorText = FALSE; +u8 sCanInteractDoor = TRUE; static u8 sJustTeleported = FALSE; u8 gPssSlideStarted = FALSE; extern u8 gLastCollectedStarOrKey; @@ -1088,16 +1089,7 @@ u32 interact_warp(struct MarioState *m, UNUSED u32 interactType, struct Object * u32 display_door_dialog(struct MarioState *m, u32 actionArg) { if (!m) { return FALSE; } if (m != &gMarioStates[0]) { return FALSE; } - // ugly hack: save the last place we opened a dialog to prevent dialog spam - static f32 lastDialogPosition[3] = { 0 }; - f32 dx = m->pos[0] - lastDialogPosition[0]; dx *= dx; - f32 dy = m->pos[1] - lastDialogPosition[1]; dy *= dy; - f32 dz = m->pos[2] - lastDialogPosition[2]; dz *= dz; - f32 dist = sqrt(dx + dy + dz); - if (dist < 300) { return FALSE; } - memcpy(lastDialogPosition, &m->pos[0], sizeof(f32) * 3); - - return set_mario_action(m, ACT_READING_AUTOMATIC_DIALOG, actionArg); + return sCanInteractDoor ? set_mario_action(m, ACT_READING_AUTOMATIC_DIALOG, actionArg) : FALSE; } u8 prevent_interact_door(struct MarioState* m, struct Object* o) { @@ -1131,6 +1123,7 @@ u32 interact_warp_door(struct MarioState *m, UNUSED u32 interactType, struct Obj if (!(saveFlags & SAVE_FLAG_HAVE_KEY_2)) { if (display_door_dialog(m, (saveFlags & SAVE_FLAG_HAVE_KEY_1) ? gBehaviorValues.dialogs.KeyDoor1HaveDialog : gBehaviorValues.dialogs.KeyDoor1DontHaveDialog)) { sDisplayingDoorText = TRUE; + sCanInteractDoor = FALSE; } return FALSE; } @@ -1142,6 +1135,7 @@ u32 interact_warp_door(struct MarioState *m, UNUSED u32 interactType, struct Obj if (!(saveFlags & SAVE_FLAG_HAVE_KEY_1)) { if (display_door_dialog(m, (saveFlags & SAVE_FLAG_HAVE_KEY_2) ? gBehaviorValues.dialogs.KeyDoor2HaveDialog : gBehaviorValues.dialogs.KeyDoor2DontHaveDialog)) { sDisplayingDoorText = TRUE; + sCanInteractDoor = FALSE; } return FALSE; } @@ -1279,6 +1273,7 @@ u32 interact_door(struct MarioState *m, UNUSED u32 interactType, struct Object * set_mario_action(m, ACT_ENTERING_STAR_DOOR, should_push_or_pull_door(m, o)); } sDisplayingDoorText = TRUE; + sCanInteractDoor = FALSE; return TRUE; } } @@ -2349,6 +2344,7 @@ void mario_process_interactions(struct MarioState *m) { if (!(m->marioObj->collidedObjInteractTypes & (INTERACT_WARP_DOOR | INTERACT_DOOR))) { sDisplayingDoorText = FALSE; + sCanInteractDoor = TRUE; } if (!(m->marioObj->collidedObjInteractTypes & INTERACT_WARP)) { if (m == &gMarioStates[0]) {