Skip to content

Commit

Permalink
Fix fishing minigame (#5031)
Browse files Browse the repository at this point in the history
Fixed issue from #4343 where `GEN_3` minigame was not correctly working.
  • Loading branch information
pkmnsnfrn authored Jul 25, 2024
2 parents 062856c + 7ae6b1d commit c69107a
Showing 1 changed file with 81 additions and 81 deletions.
162 changes: 81 additions & 81 deletions src/field_player_avatar.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,24 @@ static void Task_StopSurfingInit(u8);
static void Task_WaitStopSurfing(u8);

static void Task_Fishing(u8);
static u8 Fishing_Init(struct Task *);
static u8 Fishing_GetRodOut(struct Task *);
static u8 Fishing_WaitBeforeDots(struct Task *);
static u8 Fishing_InitDots(struct Task *);
static u8 Fishing_ShowDots(struct Task *);
static u8 Fishing_CheckForBite(struct Task *);
static u8 Fishing_GotBite(struct Task *);
static u8 Fishing_ChangeMinigame(struct Task *);
static u8 Fishing_WaitForA(struct Task *);
static u8 Fishing_APressNoMinigame(struct Task *);
static u8 Fishing_CheckMoreDots(struct Task *);
static u8 Fishing_MonOnHook(struct Task *);
static u8 Fishing_StartEncounter(struct Task *);
static u8 Fishing_NotEvenNibble(struct Task *);
static u8 Fishing_GotAway(struct Task *);
static u8 Fishing_NoMon(struct Task *);
static u8 Fishing_PutRodAway(struct Task *);
static u8 Fishing_EndNoMon(struct Task *);
static bool32 Fishing_Init(struct Task *);
static bool32 Fishing_GetRodOut(struct Task *);
static bool32 Fishing_WaitBeforeDots(struct Task *);
static bool32 Fishing_InitDots(struct Task *);
static bool32 Fishing_ShowDots(struct Task *);
static bool32 Fishing_CheckForBite(struct Task *);
static bool32 Fishing_GotBite(struct Task *);
static bool32 Fishing_ChangeMinigame(struct Task *);
static bool32 Fishing_WaitForA(struct Task *);
static bool32 Fishing_APressNoMinigame(struct Task *);
static bool32 Fishing_CheckMoreDots(struct Task *);
static bool32 Fishing_MonOnHook(struct Task *);
static bool32 Fishing_StartEncounter(struct Task *);
static bool32 Fishing_NotEvenNibble(struct Task *);
static bool32 Fishing_GotAway(struct Task *);
static bool32 Fishing_NoMon(struct Task *);
static bool32 Fishing_PutRodAway(struct Task *);
static bool32 Fishing_EndNoMon(struct Task *);
static void AlignFishingAnimationFrames(void);
static bool32 DoesFishingMinigameAllowCancel(void);
static bool32 Fishing_DoesFirstMonInPartyHaveSuctionCupsOrStickyHold(void);
Expand Down Expand Up @@ -1687,43 +1687,43 @@ enum
FISHING_INIT,
FISHING_GET_ROD_OUT,
FISHING_WAIT_BEFORE_DOTS,
FISHING_START_ROUND,
FISHING_INIT_DOTS,
FISHING_SHOW_DOTS,
FISHING_CHECK_FOR_BITE,
FISHING_GOT_BITE,
FISHING_CHANGE_MINIGAME,
FISHING_WAIT_FOR_A,
FISHING_A_PRESS_NO_MINIGAME,
FISHING_CHECK_MORE_DOTS,
FISHING_ON_HOOK,
FISHING_MON_ON_HOOK,
FISHING_START_ENCOUNTER,
FISHING_NO_BITE,
FISHING_NOT_EVEN_NIBBLE,
FISHING_GOT_AWAY,
FISHING_SHOW_RESULT,
FISHING_NO_MON,
FISHING_PUT_ROD_AWAY,
FISHING_END_NO_MON,
};

static bool8 (*const sFishingStateFuncs[])(struct Task *) =
{
Fishing_Init, // FISHING_INIT,
Fishing_GetRodOut, // FISHING_GET_ROD_OUT,
Fishing_WaitBeforeDots, // FISHING_WAIT_BEFORE_DOTS,
Fishing_InitDots, // FISHING_START_ROUND,
Fishing_ShowDots, // FISHING_SHOW_DOTS,
Fishing_CheckForBite, // FISHING_CHECK_FOR_BITE,
Fishing_GotBite, // FISHING_GOT_BITE,
Fishing_ChangeMinigame, // FISHING_CHANGE_MINIGAME,
Fishing_WaitForA, // FISHING_WAIT_FOR_A,
Fishing_APressNoMinigame, // FISHING_A_PRESS_NO_MINIGAME,
Fishing_CheckMoreDots, // FISHING_CHECK_MORE_DOTS,
Fishing_MonOnHook, // FISHING_ON_HOOK,
Fishing_StartEncounter, // FISHING_START_ENCOUNTER,
Fishing_NotEvenNibble, // FISHING_NO_BITE,
Fishing_GotAway, // FISHING_GOT_AWAY,
Fishing_NoMon, // FISHING_SHOW_RESULT,
Fishing_PutRodAway, // FISHING_PUT_ROD_AWAY,
Fishing_EndNoMon, // FISHING_END_NO_MON,
static bool32 (*const sFishingStateFuncs[])(struct Task *) =
{
[FISHING_INIT] = Fishing_Init,
[FISHING_GET_ROD_OUT] = Fishing_GetRodOut,
[FISHING_WAIT_BEFORE_DOTS] = Fishing_WaitBeforeDots,
[FISHING_INIT_DOTS] = Fishing_InitDots,
[FISHING_SHOW_DOTS] = Fishing_ShowDots,
[FISHING_CHECK_FOR_BITE] = Fishing_CheckForBite,
[FISHING_GOT_BITE] = Fishing_GotBite,
[FISHING_CHANGE_MINIGAME] = Fishing_ChangeMinigame,
[FISHING_WAIT_FOR_A] = Fishing_WaitForA,
[FISHING_A_PRESS_NO_MINIGAME] = Fishing_APressNoMinigame,
[FISHING_CHECK_MORE_DOTS] = Fishing_CheckMoreDots,
[FISHING_MON_ON_HOOK] = Fishing_MonOnHook,
[FISHING_START_ENCOUNTER] = Fishing_StartEncounter,
[FISHING_NOT_EVEN_NIBBLE] = Fishing_NotEvenNibble,
[FISHING_GOT_AWAY] = Fishing_GotAway,
[FISHING_NO_MON] = Fishing_NoMon,
[FISHING_PUT_ROD_AWAY] = Fishing_PutRodAway,
[FISHING_END_NO_MON] = Fishing_EndNoMon,
};

void StartFishing(u8 rod)
Expand All @@ -1740,15 +1740,15 @@ static void Task_Fishing(u8 taskId)
;
}

static bool8 Fishing_Init(struct Task *task)
static bool32 Fishing_Init(struct Task *task)
{
LockPlayerFieldControls();
gPlayerAvatar.preventStep = TRUE;
task->tStep++;
task->tStep = FISHING_GET_ROD_OUT;
return FALSE;
}

static bool8 Fishing_GetRodOut(struct Task *task)
static bool32 Fishing_GetRodOut(struct Task *task)
{
struct ObjectEvent *playerObjEvent;
const s16 minRounds1[] = {
Expand All @@ -1769,27 +1769,27 @@ static bool8 Fishing_GetRodOut(struct Task *task)
ObjectEventClearHeldMovementIfActive(playerObjEvent);
playerObjEvent->enableAnim = TRUE;
SetPlayerAvatarFishing(playerObjEvent->facingDirection);
task->tStep++;
task->tStep = FISHING_WAIT_BEFORE_DOTS;
return FALSE;
}

static bool8 Fishing_WaitBeforeDots(struct Task *task)
static bool32 Fishing_WaitBeforeDots(struct Task *task)
{
AlignFishingAnimationFrames();

// Wait one second
task->tFrameCounter++;
if (task->tFrameCounter >= 60)
task->tStep++;
task->tStep = FISHING_INIT_DOTS;
return FALSE;
}

static bool8 Fishing_InitDots(struct Task *task)
static bool32 Fishing_InitDots(struct Task *task)
{
u32 randVal;

LoadMessageBoxAndFrameGfx(0, TRUE);
task->tStep++;
task->tStep = FISHING_SHOW_DOTS;
task->tFrameCounter = 0;
task->tNumDots = 0;
randVal = Random();
Expand All @@ -1802,7 +1802,7 @@ static bool8 Fishing_InitDots(struct Task *task)
return TRUE;
}

static bool8 Fishing_ShowDots(struct Task *task)
static bool32 Fishing_ShowDots(struct Task *task)
{
const u8 dot[] = _("·");

Expand All @@ -1813,7 +1813,7 @@ static bool8 Fishing_ShowDots(struct Task *task)
if (!DoesFishingMinigameAllowCancel())
return FALSE;

task->tStep = FISHING_NO_BITE;
task->tStep = FISHING_NOT_EVEN_NIBBLE;
if (task->tRoundsPlayed != 0)
task->tStep = FISHING_GOT_AWAY;
return TRUE;
Expand All @@ -1825,9 +1825,9 @@ static bool8 Fishing_ShowDots(struct Task *task)
task->tFrameCounter = 0;
if (task->tNumDots >= task->tDotsRequired)
{
task->tStep++;
task->tStep = FISHING_CHECK_FOR_BITE;
if (task->tRoundsPlayed != 0)
task->tStep++;
task->tStep = FISHING_GOT_BITE;
task->tRoundsPlayed++;
}
else
Expand All @@ -1840,17 +1840,17 @@ static bool8 Fishing_ShowDots(struct Task *task)
}
}

static bool8 Fishing_CheckForBite(struct Task *task)
static bool32 Fishing_CheckForBite(struct Task *task)
{
bool32 bite, firstMonHasSuctionOrSticky;

AlignFishingAnimationFrames();
task->tStep++;
task->tStep = FISHING_GOT_BITE;
bite = FALSE;

if (!DoesCurrentMapHaveFishingMons())
{
task->tStep = FISHING_NO_BITE;
task->tStep = FISHING_NOT_EVEN_NIBBLE;
return TRUE;
}

Expand All @@ -1863,24 +1863,24 @@ static bool8 Fishing_CheckForBite(struct Task *task)
bite = Fishing_RollForBite(FALSE);

if (!bite)
task->tStep = FISHING_NO_BITE;
task->tStep = FISHING_NOT_EVEN_NIBBLE;

if (bite)
StartSpriteAnim(&gSprites[gPlayerAvatar.spriteId], GetFishingBiteDirectionAnimNum(GetPlayerFacingDirection()));

return TRUE;
}

static bool8 Fishing_GotBite(struct Task *task)
static bool32 Fishing_GotBite(struct Task *task)
{
AlignFishingAnimationFrames();
AddTextPrinterParameterized(0, FONT_NORMAL, gText_OhABite, 0, 17, 0, NULL);
task->tStep++;
task->tStep = FISHING_CHANGE_MINIGAME;
task->tFrameCounter = 0;
return FALSE;
}

static u8 Fishing_ChangeMinigame(struct Task *task)
static bool32 Fishing_ChangeMinigame(struct Task *task)
{
switch (I_FISHING_MINIGAME)
{
Expand All @@ -1897,7 +1897,7 @@ static u8 Fishing_ChangeMinigame(struct Task *task)
}

// We have a bite. Now, wait for the player to press A, or the timer to expire.
static bool8 Fishing_WaitForA(struct Task *task)
static bool32 Fishing_WaitForA(struct Task *task)
{
const s16 reelTimeouts[3] = {
[OLD_ROD] = 36,
Expand All @@ -1910,20 +1910,20 @@ static bool8 Fishing_WaitForA(struct Task *task)
if (task->tFrameCounter >= reelTimeouts[task->tFishingRod])
task->tStep = FISHING_GOT_AWAY;
else if (JOY_NEW(A_BUTTON))
task->tStep++;
task->tStep = FISHING_CHECK_MORE_DOTS;
return FALSE;
}

static bool8 Fishing_APressNoMinigame(struct Task *task)
static bool32 Fishing_APressNoMinigame(struct Task *task)
{
AlignFishingAnimationFrames();
if (JOY_NEW(A_BUTTON))
task->tStep = FISHING_ON_HOOK;
task->tStep = FISHING_MON_ON_HOOK;
return FALSE;
}

// Determine if we're going to play the dot game again
static bool8 Fishing_CheckMoreDots(struct Task *task)
static bool32 Fishing_CheckMoreDots(struct Task *task)
{
const s16 moreDotsChance[][2] =
{
Expand All @@ -1933,33 +1933,33 @@ static bool8 Fishing_CheckMoreDots(struct Task *task)
};

AlignFishingAnimationFrames();
task->tStep++;
task->tStep = FISHING_MON_ON_HOOK;
if (task->tRoundsPlayed < task->tMinRoundsRequired)
{
task->tStep = FISHING_START_ROUND;
task->tStep = FISHING_INIT_DOTS;
}
else if (task->tRoundsPlayed < 2)
{
// probability of having to play another round
s16 probability = Random() % 100;

if (moreDotsChance[task->tFishingRod][task->tRoundsPlayed] > probability)
task->tStep = FISHING_START_ROUND;
task->tStep = FISHING_INIT_DOTS;
}
return FALSE;
}

static bool8 Fishing_MonOnHook(struct Task *task)
static bool32 Fishing_MonOnHook(struct Task *task)
{
AlignFishingAnimationFrames();
FillWindowPixelBuffer(0, PIXEL_FILL(1));
AddTextPrinterParameterized2(0, FONT_NORMAL, gText_PokemonOnHook, 1, 0, TEXT_COLOR_DARK_GRAY, TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GRAY);
task->tStep++;
task->tStep = FISHING_START_ENCOUNTER;
task->tFrameCounter = 0;
return FALSE;
}

static bool8 Fishing_StartEncounter(struct Task *task)
static bool32 Fishing_StartEncounter(struct Task *task)
{
if (task->tFrameCounter == 0)
AlignFishingAnimationFrames();
Expand Down Expand Up @@ -1995,36 +1995,36 @@ static bool8 Fishing_StartEncounter(struct Task *task)
return FALSE;
}

static bool8 Fishing_NotEvenNibble(struct Task *task)
static bool32 Fishing_NotEvenNibble(struct Task *task)
{
gChainFishingDexNavStreak = 0;
AlignFishingAnimationFrames();
StartSpriteAnim(&gSprites[gPlayerAvatar.spriteId], GetFishingNoCatchDirectionAnimNum(GetPlayerFacingDirection()));
FillWindowPixelBuffer(0, PIXEL_FILL(1));
AddTextPrinterParameterized2(0, FONT_NORMAL, gText_NotEvenANibble, 1, 0, TEXT_COLOR_DARK_GRAY, TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GRAY);
task->tStep = FISHING_SHOW_RESULT;
task->tStep = FISHING_NO_MON;
return TRUE;
}

static bool8 Fishing_GotAway(struct Task *task)
static bool32 Fishing_GotAway(struct Task *task)
{
gChainFishingDexNavStreak = 0;
AlignFishingAnimationFrames();
StartSpriteAnim(&gSprites[gPlayerAvatar.spriteId], GetFishingNoCatchDirectionAnimNum(GetPlayerFacingDirection()));
FillWindowPixelBuffer(0, PIXEL_FILL(1));
AddTextPrinterParameterized2(0, FONT_NORMAL, gText_ItGotAway, 1, 0, TEXT_COLOR_DARK_GRAY, TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GRAY);
task->tStep++;
task->tStep = FISHING_NO_MON;
return TRUE;
}

static bool8 Fishing_NoMon(struct Task *task)
static bool32 Fishing_NoMon(struct Task *task)
{
AlignFishingAnimationFrames();
task->tStep++;
task->tStep = FISHING_PUT_ROD_AWAY;
return FALSE;
}

static bool8 Fishing_PutRodAway(struct Task *task)
static bool32 Fishing_PutRodAway(struct Task *task)
{
AlignFishingAnimationFrames();
if (gSprites[gPlayerAvatar.spriteId].animEnded)
Expand All @@ -2037,12 +2037,12 @@ static bool8 Fishing_PutRodAway(struct Task *task)
SetSurfBlob_PlayerOffset(gObjectEvents[gPlayerAvatar.objectEventId].fieldEffectSpriteId, FALSE, 0);
gSprites[gPlayerAvatar.spriteId].x2 = 0;
gSprites[gPlayerAvatar.spriteId].y2 = 0;
task->tStep++;
task->tStep = FISHING_END_NO_MON;
}
return FALSE;
}

static bool8 Fishing_EndNoMon(struct Task *task)
static bool32 Fishing_EndNoMon(struct Task *task)
{
RunTextPrinters();
if (!IsTextPrinterActive(0))
Expand Down

0 comments on commit c69107a

Please sign in to comment.