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

@ -495,6 +495,11 @@
#define MAX_PC_ITEM_CAPACITY 999 #define MAX_PC_ITEM_CAPACITY 999
#define MAX_BERRY_CAPACITY 999 #define MAX_BERRY_CAPACITY 999
// Secondary IDs for rods
#define OLD_ROD 0
#define GOOD_ROD 1
#define SUPER_ROD 2
// Check if the item is one that can be used on a Pokemon. // Check if the item is one that can be used on a Pokemon.
#define ITEM_HAS_EFFECT(item) ((item) >= ITEM_POTION && (item) <= ITEM_0B2) #define ITEM_HAS_EFFECT(item) ((item) >= ITEM_POTION && (item) <= ITEM_0B2)

View file

@ -35,7 +35,7 @@ void sub_80EDC60(const u16 *words);
void sub_80EDA80(void); void sub_80EDA80(void);
void ReceivePokeNewsData(void *src, u32 size, u8 masterIdx); void ReceivePokeNewsData(void *src, u32 size, u8 masterIdx);
void sub_80F0BB8(void); void sub_80F0BB8(void);
void sub_80ED950(bool8 flag); void RecordFishingAttemptForTV(bool8 caughtFish);
void IncrementDailySlotsUses(void); void IncrementDailySlotsUses(void);
void IncrementDailyRouletteUses(void); void IncrementDailyRouletteUses(void);
void IncrementDailyWildBattles(void); void IncrementDailyWildBattles(void);

View file

@ -3426,7 +3426,7 @@ const struct Item gItems[] =
.pocket = POCKET_KEY_ITEMS, .pocket = POCKET_KEY_ITEMS,
.type = 2, .type = 2,
.fieldUseFunc = ItemUseOutOfBattle_Rod, .fieldUseFunc = ItemUseOutOfBattle_Rod,
.secondaryId = 0, .secondaryId = OLD_ROD,
}, },
[ITEM_GOOD_ROD] = [ITEM_GOOD_ROD] =
@ -3440,7 +3440,7 @@ const struct Item gItems[] =
.pocket = POCKET_KEY_ITEMS, .pocket = POCKET_KEY_ITEMS,
.type = 2, .type = 2,
.fieldUseFunc = ItemUseOutOfBattle_Rod, .fieldUseFunc = ItemUseOutOfBattle_Rod,
.secondaryId = 1, .secondaryId = GOOD_ROD,
}, },
[ITEM_SUPER_ROD] = [ITEM_SUPER_ROD] =
@ -3454,7 +3454,7 @@ const struct Item gItems[] =
.pocket = POCKET_KEY_ITEMS, .pocket = POCKET_KEY_ITEMS,
.type = 2, .type = 2,
.fieldUseFunc = ItemUseOutOfBattle_Rod, .fieldUseFunc = ItemUseOutOfBattle_Rod,
.secondaryId = 2, .secondaryId = SUPER_ROD,
}, },
[ITEM_SS_TICKET] = [ITEM_SS_TICKET] =

View file

@ -1423,7 +1423,7 @@ void UpdateRayquazaSpotlightEffect(struct Sprite *sprite)
switch (sprite->sState) switch (sprite->sState)
{ {
case 0: case 0:
SetGpuReg(REG_OFFSET_BG0VOFS, 120 - (sprite->sTimer / 3)); SetGpuReg(REG_OFFSET_BG0VOFS, DISPLAY_WIDTH / 2 - (sprite->sTimer / 3));
if (sprite->sTimer == 96) if (sprite->sTimer == 96)
{ {
for (i = 0; i < 3; i++) for (i = 0; i < 3; i++)

View file

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

View file

@ -979,7 +979,7 @@ void AnimateFlash(u8 flashLevel)
u8 value = 0; u8 value = 0;
if (!flashLevel) if (!flashLevel)
value = 1; value = 1;
sub_80AFFDC(120, 80, sFlashLevelPixelRadii[curFlashLevel], sFlashLevelPixelRadii[flashLevel], value, 1); sub_80AFFDC(DISPLAY_WIDTH / 2, DISPLAY_HEIGHT / 2, sFlashLevelPixelRadii[curFlashLevel], sFlashLevelPixelRadii[flashLevel], value, 1);
sub_80AFFB8(); sub_80AFFB8();
ScriptContext2_Enable(); ScriptContext2_Enable();
} }
@ -988,14 +988,14 @@ void WriteFlashScanlineEffectBuffer(u8 flashLevel)
{ {
if (flashLevel) if (flashLevel)
{ {
SetFlashScanlineEffectWindowBoundaries(&gScanlineEffectRegBuffers[0][0], 120, 80, sFlashLevelPixelRadii[flashLevel]); SetFlashScanlineEffectWindowBoundaries(&gScanlineEffectRegBuffers[0][0], DISPLAY_WIDTH / 2, DISPLAY_HEIGHT / 2, sFlashLevelPixelRadii[flashLevel]);
CpuFastSet(&gScanlineEffectRegBuffers[0], &gScanlineEffectRegBuffers[1], 480); CpuFastSet(&gScanlineEffectRegBuffers[0], &gScanlineEffectRegBuffers[1], 480);
} }
} }
void WriteBattlePyramidViewScanlineEffectBuffer(void) void WriteBattlePyramidViewScanlineEffectBuffer(void)
{ {
SetFlashScanlineEffectWindowBoundaries(&gScanlineEffectRegBuffers[0][0], 120, 80, gSaveBlock2Ptr->frontier.pyramidLightRadius); SetFlashScanlineEffectWindowBoundaries(&gScanlineEffectRegBuffers[0][0], DISPLAY_WIDTH / 2, DISPLAY_HEIGHT / 2, gSaveBlock2Ptr->frontier.pyramidLightRadius);
CpuFastSet(&gScanlineEffectRegBuffers[0], &gScanlineEffectRegBuffers[1], 480); CpuFastSet(&gScanlineEffectRegBuffers[0], &gScanlineEffectRegBuffers[1], 480);
} }

View file

@ -1836,32 +1836,26 @@ static void TryEndMassOutbreak(u16 days)
gSaveBlock1Ptr->outbreakDaysLeft -= days; gSaveBlock1Ptr->outbreakDaysLeft -= days;
} }
void sub_80ED950(bool8 flag) void RecordFishingAttemptForTV(bool8 caughtFish)
{ {
if (flag) if (caughtFish)
{ {
if (sPokemonAnglerAttemptCounters >> 8 > 4) if (sPokemonAnglerAttemptCounters >> 8 > 4)
{
PutFishingAdviceShowOnTheAir(); PutFishingAdviceShowOnTheAir();
}
sPokemonAnglerAttemptCounters &= 0xFF; sPokemonAnglerAttemptCounters &= 0xFF;
if (sPokemonAnglerAttemptCounters != 0xFF) if (sPokemonAnglerAttemptCounters != 0xFF)
{
sPokemonAnglerAttemptCounters += 0x01; sPokemonAnglerAttemptCounters += 0x01;
} }
}
else else
{ {
if ((u8)sPokemonAnglerAttemptCounters > 4) if ((u8)sPokemonAnglerAttemptCounters > 4)
{
PutFishingAdviceShowOnTheAir(); PutFishingAdviceShowOnTheAir();
}
sPokemonAnglerAttemptCounters &= 0xFF00; sPokemonAnglerAttemptCounters &= 0xFF00;
if (sPokemonAnglerAttemptCounters >> 8 != 0xFF) if (sPokemonAnglerAttemptCounters >> 8 != 0xFF)
{
sPokemonAnglerAttemptCounters += 0x0100; sPokemonAnglerAttemptCounters += 0x0100;
} }
}
} }
void PutFishingAdviceShowOnTheAir(void) void PutFishingAdviceShowOnTheAir(void)

View file

@ -185,13 +185,6 @@ static u8 ChooseWildMonIndex_WaterRock(void)
return 4; return 4;
} }
enum
{
OLD_ROD,
GOOD_ROD,
SUPER_ROD
};
static u8 ChooseWildMonIndex_Fishing(u8 rod) static u8 ChooseWildMonIndex_Fishing(u8 rod)
{ {
u8 wildMonIndex = 0; u8 wildMonIndex = 0;