From d20341646a2ddf40ec4f8bfde235ba442093abb0 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 1 Nov 2021 12:41:21 -0400 Subject: [PATCH] Start battle_anim_mons doc --- include/battle_anim.h | 8 +- src/battle_anim_effects_1.c | 6 +- src/battle_anim_effects_2.c | 4 +- src/battle_anim_effects_3.c | 4 +- src/battle_anim_ghost.c | 4 +- src/battle_anim_ice.c | 4 +- src/battle_anim_mon_movement.c | 12 +- src/battle_anim_mons.c | 208 ++++++++++++++++++++------------ src/battle_anim_psychic.c | 2 +- src/battle_anim_utility_funcs.c | 2 +- src/pokemon_icon.c | 2 +- 11 files changed, 154 insertions(+), 102 deletions(-) diff --git a/include/battle_anim.h b/include/battle_anim.h index 3f73f1daf6..01931125fc 100644 --- a/include/battle_anim.h +++ b/include/battle_anim.h @@ -113,7 +113,7 @@ void GetBattleAnimBgData(struct BattleAnimBgData*, u32 arg1); u8 GetBattlerSpriteSubpriority(u8 battlerId); bool8 TranslateAnimHorizontalArc(struct Sprite *sprite); void sub_80A6630(struct Sprite *sprite); -void TranslateMonSpriteLinearFixedPoint(struct Sprite *sprite); +void TranslateSpriteLinearByIdFixedPoint(struct Sprite *sprite); void ResetSpriteRotScale(u8 spriteId); void SetSpriteRotScale(u8 spriteId, s16 xScale, s16 yScale, u16 rotation); void InitSpriteDataForLinearTranslation(struct Sprite *sprite); @@ -123,7 +123,7 @@ u32 GetBattleBgPalettesMask(u8 battleBackground, u8 attacker, u8 target, u8 atta u32 GetBattleMonSpritePalettesMask(u8 playerLeft, u8 playerRight, u8 opponentLeft, u8 opponentRight); u8 AnimDummyReturnArg(u8 battler); s16 CloneBattlerSpriteWithBlend(u8); -void obj_delete_but_dont_free_vram(struct Sprite*); +void DestroySpriteWithActiveSheet(struct Sprite*); u8 CreateInvisibleSpriteCopy(int, u8, int); void AnimLoadCompressedBgTilemapHandleContest(struct BattleAnimBgData*, const void*, bool32); void AnimLoadCompressedBgGfx(u32, const u32*, u32); @@ -138,7 +138,7 @@ void AnimLoadCompressedBgTilemap(u32 bgId, const void *src); void InitAnimFastLinearTranslationWithSpeed(struct Sprite *sprite); bool8 AnimFastTranslateLinear(struct Sprite *sprite); void InitAndRunAnimFastLinearTranslation(struct Sprite *sprite); -void TranslateMonSpriteLinear(struct Sprite *sprite); +void TranslateSpriteLinearById(struct Sprite *sprite); void TranslateSpriteLinear(struct Sprite *sprite); void AnimSpriteOnMonPos(struct Sprite *sprite); void InitAnimLinearTranslationWithSpeedAndPos(struct Sprite *sprite); @@ -157,7 +157,7 @@ void SetBattlerSpriteYOffsetFromOtherYScale(u8 spriteId, u8 otherSpriteId); u8 GetBattlerSide(u8 battler); u8 GetBattlerPosition(u8 battler); u8 GetBattlerAtPosition(u8 position); -void sub_80A64EC(struct Sprite *sprite); +void ConvertPosDataToTranslateLinearData(struct Sprite *sprite); void InitAnimFastLinearTranslationWithSpeedAndPos(struct Sprite *sprite); enum diff --git a/src/battle_anim_effects_1.c b/src/battle_anim_effects_1.c index f54ebfbf7e..1966250ad6 100644 --- a/src/battle_anim_effects_1.c +++ b/src/battle_anim_effects_1.c @@ -4442,7 +4442,7 @@ static void AnimBowMon_Step1(struct Sprite* sprite) sprite->data[2] = 0; sprite->data[3] = gBattlerSpriteIds[gBattleAnimAttacker]; StoreSpriteCallbackInData6(sprite, AnimBowMon_Step1_Callback); - sprite->callback = TranslateMonSpriteLinear; + sprite->callback = TranslateSpriteLinearById; } static void AnimBowMon_Step1_Callback(struct Sprite* sprite) @@ -4472,7 +4472,7 @@ static void AnimBowMon_Step2(struct Sprite* sprite) sprite->data[2] = 0; sprite->data[3] = gBattlerSpriteIds[gBattleAnimAttacker]; StoreSpriteCallbackInData6(sprite, AnimBowMon_Step4); - sprite->callback = TranslateMonSpriteLinear; + sprite->callback = TranslateSpriteLinearById; } static void AnimBowMon_Step3(struct Sprite* sprite) @@ -5226,7 +5226,7 @@ static void AnimDoubleTeam(struct Sprite* sprite) if (sprite->data[0] > 64) { gTasks[sprite->data[2]].data[3]--; - obj_delete_but_dont_free_vram(sprite); + DestroySpriteWithActiveSheet(sprite); } else { diff --git a/src/battle_anim_effects_2.c b/src/battle_anim_effects_2.c index 27149873d6..e25c71007f 100755 --- a/src/battle_anim_effects_2.c +++ b/src/battle_anim_effects_2.c @@ -2113,7 +2113,7 @@ static void CreateMinimizeSprite(struct Task* task, u8 taskId) { if ((matrixNum = AllocOamMatrix()) == 0xFF) { - obj_delete_but_dont_free_vram(&gSprites[spriteId]); + DestroySpriteWithActiveSheet(&gSprites[spriteId]); } else { @@ -2141,7 +2141,7 @@ static void ClonedMinizeSprite_Step(struct Sprite *sprite) { gTasks[sprite->data[1]].data[sprite->data[2]]--; FreeOamMatrix(sprite->oam.matrixNum); - obj_delete_but_dont_free_vram(sprite); + DestroySpriteWithActiveSheet(sprite); } } diff --git a/src/battle_anim_effects_3.c b/src/battle_anim_effects_3.c index 85dee52871..6bf53c5d6e 100755 --- a/src/battle_anim_effects_3.c +++ b/src/battle_anim_effects_3.c @@ -4896,7 +4896,7 @@ void AnimTask_OdorSleuthMovement(u8 taskId) spriteId2 = CloneBattlerSpriteWithBlend(ANIM_TARGET); if (spriteId2 < 0) { - obj_delete_but_dont_free_vram(&gSprites[spriteId1]); + DestroySpriteWithActiveSheet(&gSprites[spriteId1]); DestroyAnimVisualTask(taskId); return; } @@ -4974,7 +4974,7 @@ static void MoveOdorSleuthClone(struct Sprite *sprite) if (sprite->data[5] < 0) { gTasks[sprite->data[6]].data[sprite->data[7]]--; - obj_delete_but_dont_free_vram(sprite); + DestroySpriteWithActiveSheet(sprite); } } break; diff --git a/src/battle_anim_ghost.c b/src/battle_anim_ghost.c index 03a003c604..16daa42196 100644 --- a/src/battle_anim_ghost.c +++ b/src/battle_anim_ghost.c @@ -567,7 +567,7 @@ static void AnimTask_NightmareClone_Step(u8 taskId) break; if (task->data[1] <= 80) break; - obj_delete_but_dont_free_vram(&gSprites[task->data[0]]); + DestroySpriteWithActiveSheet(&gSprites[task->data[0]]); task->data[4] = 1; break; case 1: @@ -723,7 +723,7 @@ static void AnimTask_SpiteTargetShadow_Step3(u8 taskId) break; case 2: gSprites[task->data[14]].invisible = TRUE; - obj_delete_but_dont_free_vram(&gSprites[task->data[0]]); + DestroySpriteWithActiveSheet(&gSprites[task->data[0]]); FreeSpritePaletteByTag(ANIM_TAG_BENT_SPOON); SetGpuReg(REG_OFFSET_BLDCNT, 0); SetGpuReg(REG_OFFSET_BLDALPHA, 0); diff --git a/src/battle_anim_ice.c b/src/battle_anim_ice.c index 95c64f7cad..1d65d9570c 100644 --- a/src/battle_anim_ice.c +++ b/src/battle_anim_ice.c @@ -538,7 +538,7 @@ static void AnimUnusedIceCrystalThrow(struct Sprite *sprite) sprite->data[2] = gBattleAnimArgs[2] + targetX; sprite->data[3] = gBattleAnimArgs[1] + attackerY; sprite->data[4] = gBattleAnimArgs[3] + targetY; - sub_80A64EC(sprite); + ConvertPosDataToTranslateLinearData(sprite); for (;(targetX >= -32 && targetX <= DISPLAY_WIDTH + 32) && (targetY >= -32 && targetY <= DISPLAY_HEIGHT + 32); targetX += sprite->data[1], targetY += sprite->data[2]) @@ -557,7 +557,7 @@ static void AnimUnusedIceCrystalThrow(struct Sprite *sprite) sprite->data[2] = targetX; sprite->data[3] = attackerY; sprite->data[4] = targetY; - sub_80A64EC(sprite); + ConvertPosDataToTranslateLinearData(sprite); sprite->data[3] = gBattleAnimArgs[5]; sprite->data[4] = gBattleAnimArgs[6]; sprite->callback = AnimUnusedIceCrystalThrow_Step; diff --git a/src/battle_anim_mon_movement.c b/src/battle_anim_mon_movement.c index 31857c4dcc..ba2cbe29ac 100644 --- a/src/battle_anim_mon_movement.c +++ b/src/battle_anim_mon_movement.c @@ -441,14 +441,14 @@ static void DoHorizontalLunge(struct Sprite *sprite) sprite->data[3] = gBattlerSpriteIds[gBattleAnimAttacker]; sprite->data[4] = gBattleAnimArgs[0]; StoreSpriteCallbackInData6(sprite, ReverseHorizontalLungeDirection); - sprite->callback = TranslateMonSpriteLinear; + sprite->callback = TranslateSpriteLinearById; } static void ReverseHorizontalLungeDirection(struct Sprite *sprite) { sprite->data[0] = sprite->data[4]; sprite->data[1] = -sprite->data[1]; - sprite->callback = TranslateMonSpriteLinear; + sprite->callback = TranslateSpriteLinearById; StoreSpriteCallbackInData6(sprite, DestroyAnimSprite); } @@ -468,14 +468,14 @@ static void DoVerticalDip(struct Sprite *sprite) sprite->data[3] = spriteId; sprite->data[4] = gBattleAnimArgs[0]; StoreSpriteCallbackInData6(sprite, ReverseVerticalDipDirection); - sprite->callback = TranslateMonSpriteLinear; + sprite->callback = TranslateSpriteLinearById; } static void ReverseVerticalDipDirection(struct Sprite *sprite) { sprite->data[0] = sprite->data[4]; sprite->data[2] = -sprite->data[2]; - sprite->callback = TranslateMonSpriteLinear; + sprite->callback = TranslateSpriteLinearById; StoreSpriteCallbackInData6(sprite, DestroyAnimSprite); } @@ -581,7 +581,7 @@ static void SlideMonToOffset(struct Sprite *sprite) sprite->data[5] = monSpriteId; sprite->invisible = TRUE; StoreSpriteCallbackInData6(sprite, DestroyAnimSprite); - sprite->callback = TranslateMonSpriteLinearFixedPoint; + sprite->callback = TranslateSpriteLinearByIdFixedPoint; } static void SlideMonToOffsetAndBack(struct Sprite *sprite) @@ -622,7 +622,7 @@ static void SlideMonToOffsetAndBack(struct Sprite *sprite) { StoreSpriteCallbackInData6(sprite, SlideMonToOffsetAndBack_End); } - sprite->callback = TranslateMonSpriteLinearFixedPoint; + sprite->callback = TranslateSpriteLinearByIdFixedPoint; } diff --git a/src/battle_anim_mons.c b/src/battle_anim_mons.c index 5c170adf22..75e1dadf7e 100644 --- a/src/battle_anim_mons.c +++ b/src/battle_anim_mons.c @@ -23,15 +23,15 @@ extern const struct OamData gOamData_AffineNormal_ObjNormal_64x64; static void sub_80A6FB4(struct Sprite *sprite); static void AnimFastTranslateLinearWaitEnd(struct Sprite *sprite); static void AnimThrowProjectile_Step(struct Sprite *sprite); -static void sub_80A8DFC(struct Sprite *sprite); +static void AnimBattlerTrace(struct Sprite *sprite); static void AnimWeatherBallUp_Step(struct Sprite *sprite); static u16 GetBattlerYDeltaFromSpriteId(u8 spriteId); static void AnimTask_BlendPalInAndOutSetup(struct Task *task); static void AnimTask_AlphaFadeIn_Step(u8 taskId); static void AnimTask_AttackerPunchWithTrace_Step(u8 taskId); static void AnimTask_BlendMonInAndOut_Step(u8 taskId); -static bool8 sub_80A7238(void); -static void sub_80A8D78(struct Task *task, u8 taskId); +static bool8 ShouldRotScaleSpeciesBeFlipped(void); +static void CreateBattlerTrace(struct Task *task, u8 taskId); EWRAM_DATA static union AffineAnimCmd *sAnimTaskAffineAnim = NULL; @@ -285,8 +285,8 @@ u8 GetBattlerSpriteFinal_Y(u8 battlerId, u16 species, bool8 a3) { if (GetBattlerSide(battlerId) == B_SIDE_PLAYER) y += 8; - if (y > 104) - y = 104; + if (y > DISPLAY_HEIGHT - MON_PIC_HEIGHT + 8) + y = DISPLAY_HEIGHT - MON_PIC_HEIGHT + 8; } return y; } @@ -465,7 +465,8 @@ void TranslateSpriteInGrowingCircleOverDuration(struct Sprite *sprite) } } -void sub_80A63C8(struct Sprite *sprite) +// Unused +static void sub_80A63C8(struct Sprite *sprite) { if (sprite->data[3]) { @@ -519,34 +520,47 @@ void WaitAnimForDuration(struct Sprite *sprite) SetCallbackToStoredInData6(sprite); } -static void sub_80A64D0(struct Sprite *sprite) +// Sprite data for ConvertPosDataToTranslateLinearData +#define sStepsX data[0] +#define sStartX data[1] +#define sTargetX data[2] +#define sStartY data[3] +#define sTargetY data[4] + +// Sprite data for TranslateSpriteLinear +#define sMoveSteps data[0] +#define sSpeedX data[1] +#define sSpeedY data[2] + +// Functionally unused +static void AnimPosToTranslateLinear(struct Sprite *sprite) { - sub_80A64EC(sprite); + ConvertPosDataToTranslateLinearData(sprite); sprite->callback = TranslateSpriteLinear; sprite->callback(sprite); } -void sub_80A64EC(struct Sprite *sprite) +void ConvertPosDataToTranslateLinearData(struct Sprite *sprite) { s16 old; int xDiff; - if (sprite->data[1] > sprite->data[2]) - sprite->data[0] = -sprite->data[0]; - xDiff = sprite->data[2] - sprite->data[1]; - old = sprite->data[0]; - sprite->data[0] = abs(xDiff / sprite->data[0]); - sprite->data[2] = (sprite->data[4] - sprite->data[3]) / sprite->data[0]; - sprite->data[1] = old; + if (sprite->sStartX > sprite->sTargetX) + sprite->sStepsX = -sprite->sStepsX; + xDiff = sprite->sTargetX - sprite->sStartX; + old = sprite->sStepsX; + sprite->sMoveSteps = abs(xDiff / sprite->sStepsX); + sprite->sSpeedY = (sprite->sTargetY - sprite->sStartY) / sprite->sMoveSteps; + sprite->sSpeedX = old; } void TranslateSpriteLinear(struct Sprite *sprite) { - if (sprite->data[0] > 0) + if (sprite->sMoveSteps > 0) { - sprite->data[0]--; - sprite->x2 += sprite->data[1]; - sprite->y2 += sprite->data[2]; + sprite->sMoveSteps--; + sprite->x2 += sprite->sSpeedX; + sprite->y2 += sprite->sSpeedY; } else { @@ -588,16 +602,18 @@ static void TranslateSpriteLinearFixedPointIconFrame(struct Sprite *sprite) UpdateMonIconFrame(sprite); } -void sub_80A65EC(struct Sprite *sprite) +// Unused +static void TranslateSpriteToBattleTargetPos(struct Sprite *sprite) { - sprite->data[1] = sprite->x + sprite->x2; - sprite->data[3] = sprite->y + sprite->y2; - sprite->data[2] = GetBattlerSpriteCoord(gBattleAnimTarget, BATTLER_COORD_X_2); - sprite->data[4] = GetBattlerSpriteCoord(gBattleAnimTarget, BATTLER_COORD_Y_PIC_OFFSET); - sprite->callback = sub_80A64D0; + sprite->sStartX = sprite->x + sprite->x2; + sprite->sStartY = sprite->y + sprite->y2; + sprite->sTargetX = GetBattlerSpriteCoord(gBattleAnimTarget, BATTLER_COORD_X_2); + sprite->sTargetY = GetBattlerSpriteCoord(gBattleAnimTarget, BATTLER_COORD_Y_PIC_OFFSET); + sprite->callback = AnimPosToTranslateLinear; } -void TranslateMonSpriteLinear(struct Sprite *sprite) +// Same as TranslateSpriteLinear but takes an id to specify which sprite to move +void TranslateSpriteLinearById(struct Sprite *sprite) { if (sprite->data[0] > 0) { @@ -611,7 +627,7 @@ void TranslateMonSpriteLinear(struct Sprite *sprite) } } -void TranslateMonSpriteLinearFixedPoint(struct Sprite *sprite) +void TranslateSpriteLinearByIdFixedPoint(struct Sprite *sprite) { if (sprite->data[0] > 0) { @@ -654,16 +670,18 @@ void DestroySpriteAndMatrix(struct Sprite *sprite) DestroyAnimSprite(sprite); } -void sub_80A6760(struct Sprite *sprite) +// Unused +static void TranslateSpriteToBattleAttackerPos(struct Sprite *sprite) { - sprite->data[1] = sprite->x + sprite->x2; - sprite->data[3] = sprite->y + sprite->y2; - sprite->data[2] = GetBattlerSpriteCoord(gBattleAnimAttacker, BATTLER_COORD_X_2); - sprite->data[4] = GetBattlerSpriteCoord(gBattleAnimAttacker, BATTLER_COORD_Y_PIC_OFFSET); - sprite->callback = sub_80A64D0; + sprite->sStartX = sprite->x + sprite->x2; + sprite->sStartY = sprite->y + sprite->y2; + sprite->sTargetX = GetBattlerSpriteCoord(gBattleAnimAttacker, BATTLER_COORD_X_2); + sprite->sTargetY = GetBattlerSpriteCoord(gBattleAnimAttacker, BATTLER_COORD_Y_PIC_OFFSET); + sprite->callback = AnimPosToTranslateLinear; } -void sub_80A67A4(struct Sprite *sprite) +// Unused +static void sub_80A67A4(struct Sprite *sprite) { ResetPaletteStructByUid(sprite->data[5]); DestroySpriteAndMatrix(sprite); @@ -1038,7 +1056,8 @@ void StartAnimLinearTranslation(struct Sprite *sprite) sprite->callback(sprite); } -void sub_80A6F14(struct Sprite *sprite) +// Unused +static void sub_80A6F14(struct Sprite *sprite) { sprite->data[1] = sprite->x; sprite->data[3] = sprite->y; @@ -1083,6 +1102,7 @@ void AnimTranslateLinear_WaitEnd(struct Sprite *sprite) SetCallbackToStoredInData6(sprite); } +// Functionally unused static void sub_80A6FB4(struct Sprite *sprite) { sub_8039E9C(sprite); @@ -1204,7 +1224,7 @@ void SetSpriteRotScale(u8 spriteId, s16 xScale, s16 yScale, u16 rotation) src.xScale = xScale; src.yScale = yScale; src.rotation = rotation; - if (sub_80A7238()) + if (ShouldRotScaleSpeciesBeFlipped()) src.xScale = -src.xScale; i = gSprites[spriteId].oam.matrixNum; ObjAffineSet(&src, &matrix, 1, 2); @@ -1214,7 +1234,8 @@ void SetSpriteRotScale(u8 spriteId, s16 xScale, s16 yScale, u16 rotation) gOamMatrices[i].d = matrix.d; } -static bool8 sub_80A7238(void) +// Pokémon in Contests (except Unown) should be flipped. +static bool8 ShouldRotScaleSpeciesBeFlipped(void) { if (IsContest()) { @@ -1279,7 +1300,7 @@ void TrySetSpriteRotScale(struct Sprite *sprite, bool8 recalcCenterVector, s16 x src.xScale = xScale; src.yScale = yScale; src.rotation = rotation; - if (sub_80A7238()) + if (ShouldRotScaleSpeciesBeFlipped()) src.xScale = -src.xScale; i = sprite->oam.matrixNum; ObjAffineSet(&src, &matrix, 1, 2); @@ -1583,7 +1604,7 @@ s16 CloneBattlerSpriteWithBlend(u8 animBattler) return -1; } -void obj_delete_but_dont_free_vram(struct Sprite *sprite) +void DestroySpriteWithActiveSheet(struct Sprite *sprite) { sprite->usingSheet = TRUE; DestroySprite(sprite); @@ -2329,6 +2350,19 @@ void AnimSpinningSparkle(struct Sprite *sprite) StoreSpriteCallbackInData6(sprite, DestroyAnimSprite); } +// Task and sprite data for AnimTask_AttackerPunchWithTrace +#define tBattlerSpriteId data[0] +#define tMoveSpeed data[1] +#define tState data[2] +#define tCounter data[3] +#define tPaletteNum data[4] +#define tNumTracesActive data[5] +#define tPriority data[6] + +#define sActiveTime data[0] +#define sTaskId data[1] +#define sSpriteId data[2] + // Slides attacker to right and back with a cloned trace of the specified color // arg0: Trace palette blend color // arg1: Trace palette blend coeff @@ -2338,21 +2372,24 @@ void AnimTask_AttackerPunchWithTrace(u8 taskId) u16 dest; struct Task *task = &gTasks[taskId]; - task->data[0] = GetAnimBattlerSpriteId(ANIM_ATTACKER); - task->data[1] = ((GetBattlerSide(gBattleAnimAttacker)) != B_SIDE_PLAYER) ? -8 : 8; - task->data[2] = 0; - task->data[3] = 0; - gSprites[task->data[0]].x2 -= task->data[0]; - task->data[4] = AllocSpritePalette(ANIM_TAG_BENT_SPOON); - task->data[5] = 0; + task->tBattlerSpriteId = GetAnimBattlerSpriteId(ANIM_ATTACKER); + task->tMoveSpeed = (GetBattlerSide(gBattleAnimAttacker) != B_SIDE_PLAYER) ? -8 : 8; + task->tState = 0; + task->tCounter = 0; + gSprites[task->tBattlerSpriteId].x2 -= task->tBattlerSpriteId; + task->tPaletteNum = AllocSpritePalette(ANIM_TAG_BENT_SPOON); + task->tNumTracesActive = 0; - dest = (task->data[4] + 0x10) * 0x10; - src = (gSprites[task->data[0]].oam.paletteNum + 0x10) * 0x10; - task->data[6] = GetBattlerSpriteSubpriority(gBattleAnimAttacker); - if (task->data[6] == 20 || task->data[6] == 40) - task->data[6] = 2; + dest = (task->tPaletteNum + 16) * 16; + src = (gSprites[task->tBattlerSpriteId].oam.paletteNum + 0x10) * 0x10; + + // Set trace's priority based on battler's subpriority + task->tPriority = GetBattlerSpriteSubpriority(gBattleAnimAttacker); + if (task->tPriority == 20 || task->tPriority == 40) + task->tPriority = 2; else - task->data[6] = 3; + task->tPriority = 3; + CpuCopy32(&gPlttBufferUnfaded[src], &gPlttBufferFaded[dest], 0x20); BlendPalette(dest, 16, gBattleAnimArgs[1], gBattleAnimArgs[0]); task->func = AnimTask_AttackerPunchWithTrace_Step; @@ -2361,28 +2398,30 @@ void AnimTask_AttackerPunchWithTrace(u8 taskId) static void AnimTask_AttackerPunchWithTrace_Step(u8 taskId) { struct Task *task = &gTasks[taskId]; - switch (task->data[2]) + switch (task->tState) { case 0: - sub_80A8D78(task, taskId); - gSprites[task->data[0]].x2 += task->data[1]; - if (++task->data[3] == 5) + // Move forward + CreateBattlerTrace(task, taskId); + gSprites[task->tBattlerSpriteId].x2 += task->tMoveSpeed; + if (++task->tCounter == 5) { - task->data[3]--; - task->data[2]++; + task->tCounter--; + task->tState++; } break; case 1: - sub_80A8D78(task, taskId); - gSprites[task->data[0]].x2 -= task->data[1]; - if (--task->data[3] == 0) + // Move back (do same number of traces as before) + CreateBattlerTrace(task, taskId); + gSprites[task->tBattlerSpriteId].x2 -= task->tMoveSpeed; + if (--task->tCounter == 0) { - gSprites[task->data[0]].x2 = 0; - task->data[2]++; + gSprites[task->tBattlerSpriteId].x2 = 0; + task->tState++; } break; case 2: - if (!task->data[5]) + if (task->tNumTracesActive == 0) { FreeSpritePaletteByTag(ANIM_TAG_BENT_SPOON); DestroyAnimVisualTask(taskId); @@ -2391,31 +2430,44 @@ static void AnimTask_AttackerPunchWithTrace_Step(u8 taskId) } } -static void sub_80A8D78(struct Task *task, u8 taskId) +static void CreateBattlerTrace(struct Task *task, u8 taskId) { s16 spriteId = CloneBattlerSpriteWithBlend(0); if (spriteId >= 0) { - gSprites[spriteId].oam.priority = task->data[6]; - gSprites[spriteId].oam.paletteNum = task->data[4]; - gSprites[spriteId].data[0] = 8; - gSprites[spriteId].data[1] = taskId; - gSprites[spriteId].data[2] = spriteId; - gSprites[spriteId].x2 = gSprites[task->data[0]].x2; - gSprites[spriteId].callback = sub_80A8DFC; - task->data[5]++; + gSprites[spriteId].oam.priority = task->tPriority; + gSprites[spriteId].oam.paletteNum = task->tPaletteNum; + gSprites[spriteId].sActiveTime = 8; + gSprites[spriteId].sTaskId = taskId; + gSprites[spriteId].sSpriteId = spriteId; + gSprites[spriteId].x2 = gSprites[task->tBattlerSpriteId].x2; + gSprites[spriteId].callback = AnimBattlerTrace; + task->tNumTracesActive++; } } -static void sub_80A8DFC(struct Sprite *sprite) +// Just waits until destroyed +static void AnimBattlerTrace(struct Sprite *sprite) { - if (--sprite->data[0] == 0) + if (--sprite->sActiveTime == 0) { - gTasks[sprite->data[1]].data[5]--; - obj_delete_but_dont_free_vram(sprite); + gTasks[sprite->sTaskId].tNumTracesActive--; + DestroySpriteWithActiveSheet(sprite); } } +#undef tBattlerSpriteId +#undef tMoveSpeed +#undef tState +#undef tCounter +#undef tPaletteNum +#undef tNumTracesActive +#undef tPriority + +#undef sActiveTime +#undef sTaskId +#undef sSpriteId + void AnimWeatherBallUp(struct Sprite *sprite) { sprite->x = GetBattlerSpriteCoord(gBattleAnimAttacker, BATTLER_COORD_X_2); diff --git a/src/battle_anim_psychic.c b/src/battle_anim_psychic.c index b3c7b4ce8e..c98f311bd1 100644 --- a/src/battle_anim_psychic.c +++ b/src/battle_anim_psychic.c @@ -1108,7 +1108,7 @@ static void AnimTask_TransparentCloneGrowAndShrink_Step(u8 taskId) task->data[0]++; break; case 2: - obj_delete_but_dont_free_vram(&gSprites[task->data[15]]); + DestroySpriteWithActiveSheet(&gSprites[task->data[15]]); task->data[0]++; break; case 3: diff --git a/src/battle_anim_utility_funcs.c b/src/battle_anim_utility_funcs.c index b0eab5b743..e2c674c57f 100644 --- a/src/battle_anim_utility_funcs.c +++ b/src/battle_anim_utility_funcs.c @@ -267,7 +267,7 @@ static void AnimMonTrace(struct Sprite *sprite) else { gTasks[sprite->data[1]].data[sprite->data[2]]--; - obj_delete_but_dont_free_vram(sprite); + DestroySpriteWithActiveSheet(sprite); } } diff --git a/src/pokemon_icon.c b/src/pokemon_icon.c index 58d0b34200..2c010f35e6 100644 --- a/src/pokemon_icon.c +++ b/src/pokemon_icon.c @@ -1116,7 +1116,7 @@ u16 GetIconSpeciesNoPersonality(u16 species) } else { - if (species > (SPECIES_UNOWN_B - 1)) + if (species > NUM_SPECIES) species = INVALID_ICON_SPECIES; return GetIconSpecies(species, 0); }