Label fishing effect functions

This commit is contained in:
GriffinR
2020-06-29 16:53:38 -04:00
parent eb80012757
commit abdf7cbf02
8 changed files with 94 additions and 102 deletions

View File

@@ -26,6 +26,7 @@
#include "constants/event_object_movement.h"
#include "constants/field_effects.h"
#include "constants/flags.h"
#include "constants/items.h"
#include "constants/maps.h"
#include "constants/moves.h"
#include "constants/songs.h"
@@ -121,22 +122,22 @@ static void Task_StopSurfingInit(u8 taskId);
static void Task_WaitStopSurfing(u8 taskId);
static void Task_Fishing(u8 taskId);
static u8 Fishing1(struct Task *task);
static u8 Fishing2(struct Task *task);
static u8 Fishing3(struct Task *task);
static u8 Fishing4(struct Task *task);
static u8 Fishing5(struct Task *task);
static u8 Fishing6(struct Task *task);
static u8 Fishing7(struct Task *task);
static u8 Fishing8(struct Task *task);
static u8 Fishing9(struct Task *task);
static u8 Fishing10(struct Task *task);
static u8 Fishing11(struct Task *task);
static u8 Fishing12(struct Task *task);
static u8 Fishing13(struct Task *task);
static u8 Fishing14(struct Task *task);
static u8 Fishing15(struct Task *task);
static u8 Fishing16(struct Task *task);
static u8 Fishing_Init(struct Task *task);
static u8 Fishing_GetRodOut(struct Task *task);
static u8 Fishing_WaitBeforeDots(struct Task *task);
static u8 Fishing_InitDots(struct Task *task);
static u8 Fishing_ShowDots(struct Task *task);
static u8 Fishing_CheckForBite(struct Task *task);
static u8 Fishing_GotBite(struct Task *task);
static u8 Fishing_WaitForA(struct Task *task);
static u8 Fishing_CheckMoreDots(struct Task *task);
static u8 Fishing_MonOnHook(struct Task *task);
static u8 Fishing_StartEncounter(struct Task *task);
static u8 Fishing_NotEvenNibble(struct Task *task);
static u8 Fishing_GotAway(struct Task *task);
static u8 Fishing_NoMon(struct Task *task);
static u8 Fishing_PutRodAway(struct Task *task);
static u8 Fishing_EndNoMon(struct Task *task);
static void AlignFishingAnimationFrames(void);
static u8 sub_808D38C(struct ObjectEvent *object, s16 *a1);
@@ -1670,26 +1671,6 @@ static void Task_WaitStopSurfing(u8 taskId)
}
}
static bool8 (*const sFishingStateFuncs[])(struct Task *) =
{
Fishing1,
Fishing2,
Fishing3,
Fishing4,
Fishing5,
Fishing6,
Fishing7,
Fishing8,
Fishing9,
Fishing10,
Fishing11,
Fishing12,
Fishing13,
Fishing14,
Fishing15,
Fishing16,
};
#define tStep data[0]
#define tFrameCounter data[1]
#define tNumDots data[2]
@@ -1699,6 +1680,7 @@ static bool8 (*const sFishingStateFuncs[])(struct Task *) =
#define tPlayerGfxId data[14]
#define tFishingRod data[15]
// Some states are jumped to directly, labeled below
#define FISHING_START_ROUND 3
#define FISHING_GOT_BITE 6
#define FISHING_ON_HOOK 9
@@ -1706,6 +1688,26 @@ static bool8 (*const sFishingStateFuncs[])(struct Task *) =
#define FISHING_GOT_AWAY 12
#define FISHING_SHOW_RESULT 13
static bool8 (*const sFishingStateFuncs[])(struct Task *) =
{
Fishing_Init,
Fishing_GetRodOut,
Fishing_WaitBeforeDots,
Fishing_InitDots, // FISHING_START_ROUND
Fishing_ShowDots,
Fishing_CheckForBite,
Fishing_GotBite, // FISHING_GOT_BITE
Fishing_WaitForA,
Fishing_CheckMoreDots,
Fishing_MonOnHook, // FISHING_ON_HOOK
Fishing_StartEncounter,
Fishing_NotEvenNibble, // FISHING_NO_BITE
Fishing_GotAway, // FISHING_GOT_AWAY
Fishing_NoMon, // FISHING_SHOW_RESULT
Fishing_PutRodAway,
Fishing_EndNoMon,
};
void StartFishing(u8 rod)
{
u8 taskId = CreateTask(Task_Fishing, 0xFF);
@@ -1720,7 +1722,7 @@ static void Task_Fishing(u8 taskId)
;
}
static bool8 Fishing1(struct Task *task)
static bool8 Fishing_Init(struct Task *task)
{
ScriptContext2_Enable();
gPlayerAvatar.preventStep = TRUE;
@@ -1728,14 +1730,22 @@ static bool8 Fishing1(struct Task *task)
return FALSE;
}
static bool8 Fishing2(struct Task *task)
static bool8 Fishing_GetRodOut(struct Task *task)
{
struct ObjectEvent *playerObjEvent;
const s16 arr1[] = {1, 1, 1};
const s16 arr2[] = {1, 3, 6};
const s16 minRounds1[] = {
[OLD_ROD] = 1,
[GOOD_ROD] = 1,
[SUPER_ROD] = 1
};
const s16 minRounds2[] = {
[OLD_ROD] = 1,
[GOOD_ROD] = 3,
[SUPER_ROD] = 6
};
task->tRoundsPlayed = 0;
task->tMinRoundsRequired = arr1[task->tFishingRod] + (Random() % arr2[task->tFishingRod]);
task->tMinRoundsRequired = minRounds1[task->tFishingRod] + (Random() % minRounds2[task->tFishingRod]);
task->tPlayerGfxId = gObjectEvents[gPlayerAvatar.objectEventId].graphicsId;
playerObjEvent = &gObjectEvents[gPlayerAvatar.objectEventId];
ObjectEventClearHeldMovementIfActive(playerObjEvent);
@@ -1745,7 +1755,7 @@ static bool8 Fishing2(struct Task *task)
return FALSE;
}
static bool8 Fishing3(struct Task *task)
static bool8 Fishing_WaitBeforeDots(struct Task *task)
{
AlignFishingAnimationFrames();
@@ -1756,7 +1766,7 @@ static bool8 Fishing3(struct Task *task)
return FALSE;
}
static bool8 Fishing4(struct Task *task)
static bool8 Fishing_InitDots(struct Task *task)
{
u32 randVal;
@@ -1774,8 +1784,7 @@ static bool8 Fishing4(struct Task *task)
return TRUE;
}
// Play a round of the dot game
static bool8 Fishing5(struct Task *task)
static bool8 Fishing_ShowDots(struct Task *task)
{
const u8 dot[] = _("·");
@@ -1810,8 +1819,7 @@ static bool8 Fishing5(struct Task *task)
}
}
// Determine if fish bites
static bool8 Fishing6(struct Task *task)
static bool8 Fishing_CheckForBite(struct Task *task)
{
bool8 bite;
@@ -1831,34 +1839,25 @@ static bool8 Fishing6(struct Task *task)
if (ability == ABILITY_SUCTION_CUPS || ability == ABILITY_STICKY_HOLD)
{
if (Random() % 100 > 14)
{
bite = TRUE;
}
}
}
if (!bite)
{
if (Random() & 1)
{
task->tStep = FISHING_NO_BITE;
}
else
{
bite = TRUE;
}
}
if (bite == TRUE)
{
StartSpriteAnim(&gSprites[gPlayerAvatar.spriteId], GetFishingBiteDirectionAnimNum(GetPlayerFacingDirection()));
}
}
return TRUE;
}
// Oh! A Bite!
static bool8 Fishing7(struct Task *task)
static bool8 Fishing_GotBite(struct Task *task)
{
AlignFishingAnimationFrames();
AddTextPrinterParameterized(0, 1, gText_OhABite, 0, 17, 0, NULL);
@@ -1868,9 +1867,13 @@ static bool8 Fishing7(struct Task *task)
}
// We have a bite. Now, wait for the player to press A, or the timer to expire.
static bool8 Fishing8(struct Task *task)
static bool8 Fishing_WaitForA(struct Task *task)
{
const s16 reelTimeouts[3] = {36, 33, 30};
const s16 reelTimeouts[3] = {
[OLD_ROD] = 36,
[GOOD_ROD] = 33,
[SUPER_ROD] = 30
};
AlignFishingAnimationFrames();
task->tFrameCounter++;
@@ -1882,13 +1885,13 @@ static bool8 Fishing8(struct Task *task)
}
// Determine if we're going to play the dot game again
static bool8 Fishing9(struct Task *task)
static bool8 Fishing_CheckMoreDots(struct Task *task)
{
const s16 arr[][2] =
const s16 moreDotsChance[][2] =
{
{0, 0},
{40, 10},
{70, 30}
[OLD_ROD] = {0, 0},
[GOOD_ROD] = {40, 10},
[SUPER_ROD] = {70, 30}
};
AlignFishingAnimationFrames();
@@ -1902,13 +1905,13 @@ static bool8 Fishing9(struct Task *task)
// probability of having to play another round
s16 probability = Random() % 100;
if (arr[task->tFishingRod][task->tRoundsPlayed] > probability)
if (moreDotsChance[task->tFishingRod][task->tRoundsPlayed] > probability)
task->tStep = FISHING_START_ROUND;
}
return FALSE;
}
static bool8 Fishing10(struct Task *task)
static bool8 Fishing_MonOnHook(struct Task *task)
{
AlignFishingAnimationFrames();
FillWindowPixelBuffer(0, PIXEL_FILL(1));
@@ -1918,7 +1921,7 @@ static bool8 Fishing10(struct Task *task)
return FALSE;
}
static bool8 Fishing11(struct Task *task)
static bool8 Fishing_StartEncounter(struct Task *task)
{
if (task->tFrameCounter == 0)
AlignFishingAnimationFrames();
@@ -1948,14 +1951,13 @@ static bool8 Fishing11(struct Task *task)
gPlayerAvatar.preventStep = FALSE;
ScriptContext2_Disable();
FishingWildEncounter(task->tFishingRod);
sub_80ED950(1);
RecordFishingAttemptForTV(TRUE);
DestroyTask(FindTaskIdByFunc(Task_Fishing));
}
return FALSE;
}
// Not even a nibble
static bool8 Fishing12(struct Task *task)
static bool8 Fishing_NotEvenNibble(struct Task *task)
{
AlignFishingAnimationFrames();
StartSpriteAnim(&gSprites[gPlayerAvatar.spriteId], GetFishingNoCatchDirectionAnimNum(GetPlayerFacingDirection()));
@@ -1965,8 +1967,7 @@ static bool8 Fishing12(struct Task *task)
return TRUE;
}
// It got away
static bool8 Fishing13(struct Task *task)
static bool8 Fishing_GotAway(struct Task *task)
{
AlignFishingAnimationFrames();
StartSpriteAnim(&gSprites[gPlayerAvatar.spriteId], GetFishingNoCatchDirectionAnimNum(GetPlayerFacingDirection()));
@@ -1976,15 +1977,14 @@ static bool8 Fishing13(struct Task *task)
return TRUE;
}
// Wait one second
static bool8 Fishing14(struct Task *task)
static bool8 Fishing_NoMon(struct Task *task)
{
AlignFishingAnimationFrames();
task->tStep++;
return FALSE;
}
static bool8 Fishing15(struct Task *task)
static bool8 Fishing_PutRodAway(struct Task *task)
{
AlignFishingAnimationFrames();
if (gSprites[gPlayerAvatar.spriteId].animEnded)
@@ -2002,7 +2002,7 @@ static bool8 Fishing15(struct Task *task)
return FALSE;
}
static bool8 Fishing16(struct Task *task)
static bool8 Fishing_EndNoMon(struct Task *task)
{
RunTextPrinters();
if (!IsTextPrinterActive(0))
@@ -2011,7 +2011,7 @@ static bool8 Fishing16(struct Task *task)
ScriptContext2_Disable();
UnfreezeObjectEvents();
ClearDialogWindowAndFrame(0, TRUE);
sub_80ED950(0);
RecordFishingAttemptForTV(FALSE);
DestroyTask(FindTaskIdByFunc(Task_Fishing));
}
return FALSE;