diff --git a/asm/battle_2.s b/asm/battle_2.s index d64ccb8845..8dafbd897e 100644 --- a/asm/battle_2.s +++ b/asm/battle_2.s @@ -5470,17 +5470,17 @@ sub_8039894: @ 8039894 adds r0, r2, 0 movs r2, 0 movs r3, 0x1 - bl sub_806ECEC + bl BattleAnimateFrontSprite _080398B0: pop {r0} bx r0 .pool thumb_func_end sub_8039894 - thumb_func_start nullsub_18 -nullsub_18: @ 80398B8 + thumb_func_start SpriteCallbackDummy_2 +SpriteCallbackDummy_2: @ 80398B8 bx lr - thumb_func_end nullsub_18 + thumb_func_end SpriteCallbackDummy_2 thumb_func_start sub_80398BC sub_80398BC: @ 80398BC @@ -5534,7 +5534,7 @@ sub_80398D0: @ 80398D0 ands r0, r1 mov r1, r12 strb r0, [r1] - ldr r0, =nullsub_18 + ldr r0, =SpriteCallbackDummy_2 str r0, [r3, 0x1C] ldr r0, =gUnknown_02022F88 str r2, [r0] @@ -5815,7 +5815,7 @@ sub_8039B2C: @ 8039B2C strb r1, [r2] movs r1, 0 strh r1, [r0, 0x36] - ldr r1, =nullsub_18 + ldr r1, =SpriteCallbackDummy_2 str r1, [r0, 0x1C] bx lr .pool @@ -5845,7 +5845,7 @@ sub_8039B58: @ 8039B58 beq _08039B94 _08039B80: ldrh r0, [r4, 0x32] - bl sub_806F0D4 + bl HasTwoFramesAnimation lsls r0, 24 cmp r0, 0 beq _08039B94 @@ -5857,7 +5857,7 @@ _08039B94: adds r0, r4, 0 movs r2, 0x1 movs r3, 0x1 - bl sub_806ECEC + bl BattleAnimateFrontSprite _08039BA0: pop {r4} pop {r0} @@ -6212,7 +6212,7 @@ sub_8039E44: @ 8039E44 beq _08039E5C ldrh r1, [r2, 0x32] adds r0, r2, 0 - bl sub_806EEB4 + bl BattleAnimateBackSprite _08039E5C: pop {r0} bx r0 diff --git a/asm/battle_controller_linkopponent.s b/asm/battle_controller_linkopponent.s index d064350976..cb2285c7ac 100644 --- a/asm/battle_controller_linkopponent.s +++ b/asm/battle_controller_linkopponent.s @@ -1230,7 +1230,7 @@ sub_8064DD0: @ 8064DD0 ldr r0, =SpriteCallbackDummy cmp r1, r0 beq _08064E1A - ldr r0, =nullsub_18 + ldr r0, =SpriteCallbackDummy_2 cmp r1, r0 bne _08064E2A _08064E1A: diff --git a/asm/battle_controller_opponent.s b/asm/battle_controller_opponent.s index 26b8c89ece..639ef0ce61 100644 --- a/asm/battle_controller_opponent.s +++ b/asm/battle_controller_opponent.s @@ -1324,7 +1324,7 @@ bx_803AEDC: @ 805FC80 ldr r0, =SpriteCallbackDummy cmp r1, r0 beq _0805FCCA - ldr r0, =nullsub_18 + ldr r0, =SpriteCallbackDummy_2 cmp r1, r0 bne _0805FCDA _0805FCCA: diff --git a/asm/battle_controller_recorded_opponent.s b/asm/battle_controller_recorded_opponent.s index af5110d9bf..dc7fe7de55 100644 --- a/asm/battle_controller_recorded_opponent.s +++ b/asm/battle_controller_recorded_opponent.s @@ -1211,7 +1211,7 @@ sub_8186F14: @ 8186F14 ldr r0, =SpriteCallbackDummy cmp r1, r0 beq _08186F5E - ldr r0, =nullsub_18 + ldr r0, =SpriteCallbackDummy_2 cmp r1, r0 bne _08186F6E _08186F5E: diff --git a/asm/egg_hatch.s b/asm/egg_hatch.s index e4a8e6cc2c..2ee5c5e5f6 100644 --- a/asm/egg_hatch.s +++ b/asm/egg_hatch.s @@ -937,7 +937,7 @@ _08071BBC: adds r1, r7, 0 movs r2, 0 movs r3, 0x1 - bl sub_806ED40 + bl DoMonFrontSpriteAnimation ldr r1, [r5] b _08071DC8 .pool diff --git a/asm/evolution_scene.s b/asm/evolution_scene.s index 01a522d40a..1fdaa37dea 100644 --- a/asm/evolution_scene.s +++ b/asm/evolution_scene.s @@ -272,7 +272,7 @@ evolution_cutscene: @ 813DA8C adds r6, r7, 0 adds r6, 0x1C adds r0, r1, r6 - ldr r2, =nullsub_18 + ldr r2, =SpriteCallbackDummy_2 str r2, [r0] adds r1, r7 ldrb r2, [r1, 0x5] @@ -325,7 +325,7 @@ evolution_cutscene: @ 813DA8C adds r1, r3 lsls r1, 2 adds r6, r1, r6 - ldr r2, =nullsub_18 + ldr r2, =SpriteCallbackDummy_2 str r2, [r6] adds r1, r7 ldrb r0, [r1, 0x5] @@ -528,7 +528,7 @@ sub_813DD7C: @ 813DD7C adds r0, r3, 0 adds r0, 0x1C adds r0, r1, r0 - ldr r2, =nullsub_18 + ldr r2, =SpriteCallbackDummy_2 str r2, [r0] adds r1, r3 ldrb r2, [r1, 0x5] @@ -736,7 +736,7 @@ _0813E0F0: adds r0, r3, 0 adds r0, 0x1C adds r0, r1, r0 - ldr r2, =nullsub_18 + ldr r2, =SpriteCallbackDummy_2 str r2, [r0] adds r1, r3 ldrb r2, [r1, 0x5] @@ -903,7 +903,7 @@ sub_813E1D4: @ 813E1D4 adds r0, r3, 0 adds r0, 0x1C adds r0, r1, r0 - ldr r2, =nullsub_18 + ldr r2, =SpriteCallbackDummy_2 str r2, [r0] adds r1, r3 ldrb r2, [r1, 0x5] @@ -4182,7 +4182,7 @@ sub_81401E0: @ 81401E0 adds r0, r2 movs r2, 0 movs r3, 0 - bl sub_806ED40 + bl DoMonFrontSpriteAnimation pop {r0} bx r0 .pool diff --git a/asm/hall_of_fame.s b/asm/hall_of_fame.s index 4dbea35d50..f8ba2f0be2 100644 --- a/asm/hall_of_fame.s +++ b/asm/hall_of_fame.s @@ -3214,14 +3214,14 @@ _08175176: adds r0, r2, 0 movs r2, 0x1 movs r3, 0x3 - bl sub_806ED40 + bl DoMonFrontSpriteAnimation b _0817519C _08175190: lsrs r1, 16 adds r0, r2, 0 movs r2, 0 movs r3, 0x3 - bl sub_806ED40 + bl DoMonFrontSpriteAnimation _0817519C: pop {r4} pop {r0} diff --git a/asm/pokemon_3.s b/asm/pokemon_3.s index 5fa9afda10..b65efdab68 100644 --- a/asm/pokemon_3.s +++ b/asm/pokemon_3.s @@ -5,289 +5,8 @@ .text - thumb_func_start sub_806ECAC -sub_806ECAC: @ 806ECAC - push {r4,lr} - lsls r0, 24 - lsrs r4, r0, 24 - ldr r1, =gTasks - lsls r0, r4, 2 - adds r0, r4 - lsls r0, 3 - adds r2, r0, r1 - ldrh r0, [r2, 0xE] - subs r0, 0x1 - strh r0, [r2, 0xE] - lsls r0, 16 - cmp r0, 0 - bne _0806ECE2 - ldrh r0, [r2, 0x8] - ldrh r1, [r2, 0xA] - lsls r1, 16 - orrs r0, r1 - ldrb r1, [r2, 0xC] - bl sub_817F578 - movs r0, 0xFF - bl sub_81C488C - adds r0, r4, 0 - bl DestroyTask -_0806ECE2: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_806ECAC - thumb_func_start sub_806ECEC -sub_806ECEC: @ 806ECEC - push {r4,r5,lr} - adds r5, r0, 0 - lsls r1, 16 - lsrs r4, r1, 16 - lsls r2, 24 - lsrs r2, 24 - lsls r3, 24 - lsrs r3, 24 - ldr r0, =gHitMarker - ldr r0, [r0] - movs r1, 0x80 - ands r0, r1 - cmp r0, 0 - beq _0806ED30 - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - ldr r1, =0x02000002 - ands r0, r1 - cmp r0, 0 - bne _0806ED30 - movs r0, 0x80 - orrs r3, r0 - adds r0, r5, 0 - adds r1, r4, 0 - bl sub_806ED40 - b _0806ED38 - .pool -_0806ED30: - adds r0, r5, 0 - adds r1, r4, 0 - bl sub_806ED40 -_0806ED38: - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end sub_806ECEC - thumb_func_start sub_806ED40 -sub_806ED40: @ 806ED40 - push {r4-r6,lr} - adds r5, r0, 0 - lsls r1, 16 - lsrs r4, r1, 16 - lsls r2, 24 - lsrs r2, 24 - lsls r3, 24 - lsrs r3, 24 - movs r0, 0x7F - ands r0, r3 - cmp r0, 0 - beq _0806ED60 - cmp r0, 0x1 - beq _0806ED64 - movs r1, 0 - b _0806ED66 -_0806ED60: - movs r1, 0xE7 - b _0806ED66 -_0806ED64: - movs r1, 0x19 -_0806ED66: - movs r0, 0x80 - ands r0, r3 - cmp r0, 0 - beq _0806ED84 - cmp r2, 0 - bne _0806ED7C - lsls r1, 24 - asrs r1, 24 - adds r0, r4, 0 - bl PlayCry1 -_0806ED7C: - ldr r0, =SpriteCallbackDummy - b _0806EDFA - .pool -_0806ED84: - cmp r2, 0 - bne _0806EDA6 - lsls r1, 24 - asrs r1, 24 - adds r0, r4, 0 - bl PlayCry1 - adds r0, r4, 0 - bl sub_806F0D4 - lsls r0, 24 - cmp r0, 0 - beq _0806EDA6 - adds r0, r5, 0 - movs r1, 0x1 - bl StartSpriteAnim -_0806EDA6: - ldr r0, =gUnknown_08329B87 - subs r4, 0x1 - adds r6, r4, r0 - ldrb r0, [r6] - cmp r0, 0 - beq _0806EDEC - ldr r0, =sub_806EC70 - movs r1, 0 - bl CreateTask - lsls r0, 24 - lsrs r0, 24 - ldr r2, =gTasks - lsls r1, r0, 2 - adds r1, r0 - lsls r1, 3 - adds r1, r2 - strh r5, [r1, 0x8] - lsrs r0, r5, 16 - strh r0, [r1, 0xA] - ldr r0, =gUnknown_083299EC - adds r0, r4, r0 - ldrb r0, [r0] - strh r0, [r1, 0xC] - ldrb r0, [r6] - strh r0, [r1, 0xE] - b _0806EDF8 - .pool -_0806EDEC: - ldr r0, =gUnknown_083299EC - adds r0, r4, r0 - ldrb r1, [r0] - adds r0, r5, 0 - bl sub_817F544 -_0806EDF8: - ldr r0, =nullsub_18 -_0806EDFA: - str r0, [r5, 0x1C] - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_806ED40 - - thumb_func_start sub_806EE0C -sub_806EE0C: @ 806EE0C - push {r4-r6,lr} - adds r5, r0, 0 - lsls r1, 16 - lsrs r4, r1, 16 - lsls r2, 24 - cmp r2, 0 - bne _0806EE2E - adds r0, r4, 0 - bl sub_806F0D4 - lsls r0, 24 - cmp r0, 0 - beq _0806EE2E - adds r0, r5, 0 - movs r1, 0x1 - bl StartSpriteAnim -_0806EE2E: - ldr r0, =gUnknown_08329B87 - subs r4, 0x1 - adds r6, r4, r0 - ldrb r0, [r6] - cmp r0, 0 - beq _0806EE80 - ldr r0, =sub_806ECAC - movs r1, 0 - bl CreateTask - lsls r0, 24 - lsrs r0, 24 - ldr r1, =gTasks - lsls r2, r0, 2 - adds r2, r0 - lsls r2, 3 - adds r2, r1 - strh r5, [r2, 0x8] - lsrs r1, r5, 16 - strh r1, [r2, 0xA] - ldr r1, =gUnknown_083299EC - adds r1, r4, r1 - ldrb r1, [r1] - strh r1, [r2, 0xC] - ldrb r1, [r6] - strh r1, [r2, 0xE] - bl sub_81C488C - adds r0, r5, 0 - bl sub_817F60C - b _0806EE8C - .pool -_0806EE80: - ldr r0, =gUnknown_083299EC - adds r0, r4, r0 - ldrb r1, [r0] - adds r0, r5, 0 - bl sub_817F578 -_0806EE8C: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_806EE0C - - thumb_func_start sub_806EE98 -sub_806EE98: @ 806EE98 - push {lr} - ldr r0, =sub_806ECAC - bl FindTaskIdByFunc - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0xFF - beq _0806EEAC - bl DestroyTask -_0806EEAC: - pop {r0} - bx r0 - .pool - thumb_func_end sub_806EE98 - - thumb_func_start sub_806EEB4 -sub_806EEB4: @ 806EEB4 - push {r4,lr} - adds r4, r0, 0 - lsls r1, 16 - lsrs r2, r1, 16 - ldr r0, =gHitMarker - ldr r0, [r0] - movs r1, 0x80 - ands r0, r1 - cmp r0, 0 - beq _0806EEE8 - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - ldr r1, =0x02000002 - ands r0, r1 - cmp r0, 0 - bne _0806EEE8 - ldr r0, =SpriteCallbackDummy - b _0806EEFC - .pool -_0806EEE8: - adds r0, r2, 0 - bl sub_817F474 - adds r1, r0, 0 - lsls r1, 24 - lsrs r1, 24 - adds r0, r4, 0 - bl sub_817F594 - ldr r0, =nullsub_18 -_0806EEFC: - str r0, [r4, 0x1C] - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_806EEB4 thumb_func_start sub_806EF08 sub_806EF08: @ 806EF08 @@ -543,8 +262,8 @@ _0806F0BE: .pool thumb_func_end sub_806F0B0 - thumb_func_start sub_806F0D4 -sub_806F0D4: @ 806F0D4 + thumb_func_start HasTwoFramesAnimation +HasTwoFramesAnimation: @ 806F0D4 push {lr} lsls r0, 16 lsrs r2, r0, 16 @@ -568,7 +287,7 @@ _0806F0F8: pop {r1} bx r1 .pool - thumb_func_end sub_806F0D4 + thumb_func_end HasTwoFramesAnimation thumb_func_start sub_806F104 sub_806F104: @ 806F104 diff --git a/asm/pokemon_animation.s b/asm/pokemon_animation.s index 1b0119424b..a29ecb7291 100644 --- a/asm/pokemon_animation.s +++ b/asm/pokemon_animation.s @@ -89,8 +89,8 @@ _0817F528: .pool thumb_func_end sub_817F498 - thumb_func_start sub_817F544 -sub_817F544: @ 817F544 + thumb_func_start LaunchAnimationTaskForFrontSprite +LaunchAnimationTaskForFrontSprite: @ 817F544 push {r4,r5,lr} adds r5, r0, 0 lsls r4, r1, 24 @@ -113,7 +113,7 @@ sub_817F544: @ 817F544 pop {r0} bx r0 .pool - thumb_func_end sub_817F544 + thumb_func_end LaunchAnimationTaskForFrontSprite thumb_func_start sub_817F578 sub_817F578: @ 817F578 @@ -130,8 +130,8 @@ sub_817F578: @ 817F578 .pool thumb_func_end sub_817F578 - thumb_func_start sub_817F594 -sub_817F594: @ 817F594 + thumb_func_start LaunchAnimationTaskForBackSprite +LaunchAnimationTaskForBackSprite: @ 817F594 push {r4-r6,lr} adds r5, r0, 0 lsls r6, r1, 24 @@ -178,7 +178,7 @@ sub_817F594: @ 817F594 pop {r0} bx r0 .pool - thumb_func_end sub_817F594 + thumb_func_end LaunchAnimationTaskForBackSprite thumb_func_start sub_817F60C sub_817F60C: @ 817F60C diff --git a/asm/rom_8072304.s b/asm/rom_8072304.s index 8107917aec..169b7ae559 100644 --- a/asm/rom_8072304.s +++ b/asm/rom_8072304.s @@ -8234,7 +8234,7 @@ _080766BA: adds r0, r2, 0 movs r2, 0x1 movs r3, 0 - bl sub_806ED40 + bl DoMonFrontSpriteAnimation b _08076708 .pool _080766FC: @@ -8242,7 +8242,7 @@ _080766FC: adds r0, r2, 0 movs r2, 0 movs r3, 0 - bl sub_806ED40 + bl DoMonFrontSpriteAnimation _08076708: adds r0, r4, 0 bl DestroySpriteAndFreeResources diff --git a/asm/rom_817C95C.s b/asm/rom_817C95C.s index 68963869a5..a08d34cadf 100644 --- a/asm/rom_817C95C.s +++ b/asm/rom_817C95C.s @@ -4959,8 +4959,8 @@ sub_817F3F0: @ 817F3F0 bx r0 thumb_func_end sub_817F3F0 - thumb_func_start sub_817F474 -sub_817F474: @ 817F474 + thumb_func_start GetSpeciesBackAnimId +GetSpeciesBackAnimId: @ 817F474 push {lr} lsls r0, 16 lsrs r0, 16 @@ -4979,6 +4979,6 @@ _0817F48C: _0817F492: pop {r1} bx r1 - thumb_func_end sub_817F474 + thumb_func_end GetSpeciesBackAnimId .align 2, 0 @ Don't pad with nop. diff --git a/asm/rom_81BE66C.s b/asm/rom_81BE66C.s index 05901c6721..c322baf2f2 100644 --- a/asm/rom_81BE66C.s +++ b/asm/rom_81BE66C.s @@ -11218,7 +11218,7 @@ sub_81C4844: @ 81C4844 ldrh r1, [r4, 0x2E] ldrb r2, [r5, 0x4] adds r0, r4, 0 - bl sub_806EE0C + bl PokemonSummaryDoMonAnimation _081C487E: pop {r4,r5} pop {r0} diff --git a/asm/script_pokemon_util_80F87D8.s b/asm/script_pokemon_util_80F87D8.s index ca0b04e630..46622169fd 100644 --- a/asm/script_pokemon_util_80F87D8.s +++ b/asm/script_pokemon_util_80F87D8.s @@ -776,7 +776,7 @@ _080F8DD8: adds r1, r6, 0 movs r2, 0 movs r3, 0 - bl sub_806ED40 + bl DoMonFrontSpriteAnimation b _080F8E6C .pool _080F8E58: @@ -788,7 +788,7 @@ _080F8E58: adds r1, r6, 0 movs r2, 0 movs r3, 0 - bl sub_806ED40 + bl DoMonFrontSpriteAnimation _080F8E6C: ldr r1, =gTasks lsls r0, r7, 2 diff --git a/data/data2c.s b/data/data2c.s index 92e26785df..26f237c1c1 100644 --- a/data/data2c.s +++ b/data/data2c.s @@ -53,10 +53,10 @@ @ 832937C .include "data/level_up_learnset_pointers.inc" -gUnknown_083299EC:: @ 83299EC +gMonFrontAnimIdsTable:: @ 83299EC .incbin "baserom.gba", 0x3299ec, 0x19b -gUnknown_08329B87:: @ 8329B87 +gMonAnimationDelayTable:: @ 8329B87 .incbin "baserom.gba", 0x329b87, 0x19b gUnknown_08329D22:: @ 8329D22 diff --git a/include/pokemon_animation.h b/include/pokemon_animation.h new file mode 100644 index 0000000000..42fc10809e --- /dev/null +++ b/include/pokemon_animation.h @@ -0,0 +1,7 @@ +#ifndef GUARD_POKEMON_ANIMATION_H +#define GUARD_POKEMON_ANIMATION_H + +void LaunchAnimationTaskForFrontSprite(struct Sprite* sprite, u8 frontAnimId); +void LaunchAnimationTaskForBackSprite(struct Sprite* sprite, u8 backAnimId); + +#endif // GUARD_POKEMON_ANIMATION_H diff --git a/src/pokemon_3.c b/src/pokemon_3.c index e85aa72a0c..224f21bdef 100644 --- a/src/pokemon_3.c +++ b/src/pokemon_3.c @@ -20,6 +20,7 @@ #include "sprite.h" #include "text.h" #include "abilities.h" +#include "pokemon_animation.h" extern struct BattlePokemon gBattleMons[4]; extern struct BattleEnigmaBerry gEnigmaBerries[4]; @@ -34,6 +35,7 @@ extern u8 gBattleMonForms[4]; extern u16 gBattlePartyID[4]; extern u8 gLastUsedAbility; extern u16 gPartnerTrainerId; +extern u32 gHitMarker; extern const u16 gSpeciesToHoennPokedexNum[]; extern const u16 gSpeciesToNationalPokedexNum[]; @@ -57,6 +59,8 @@ extern const struct CompressedSpritePalette gMonPaletteTable[]; extern const struct CompressedSpritePalette gMonShinyPaletteTable[]; extern const u16 gHMMoves[]; extern const s8 gPokeblockFlavorCompatibilityTable[]; +extern const u8 gMonAnimationDelayTable[]; +extern const u8 gMonFrontAnimIdsTable[]; extern bool8 InBattlePyramid(void); extern bool8 sub_81D5C18(void); @@ -68,6 +72,11 @@ extern u8 sav1_map_get_name(void); extern u8 GetFrontierOpponentClass(u16 trainerId); extern u8 pokemon_order_func(u8 bankPartyId); extern void GetFrontierTrainerName(u8* dest, u16 trainerId); +extern void sub_81C488C(u8); +extern void sub_817F578(struct Sprite*, u8 frontAnimId); +extern u8 GetSpeciesBackAnimId(u16 species); + +static void sub_806E6CC(u8 taskId); bool8 HealStatusConditions(struct Pokemon *mon, u32 battlePartyId, u32 healMask, u8 battleBank) { @@ -1203,8 +1212,6 @@ void PlayMapChosenOrBattleBGM(u16 songId) PlayNewMapMusic(GetBattleBGM()); } -static void sub_806E6CC(u8 taskId); - void sub_806E694(u16 songId) { u8 taskId; @@ -1233,10 +1240,10 @@ const u8 *pokemon_get_pal(struct Pokemon *mon) return species_and_otid_get_pal(species, otId, personality); } -//Extracts the upper 16 bits of a 32-bit number +// Extracts the upper 16 bits of a 32-bit number #define HIHALF(n) (((n) & 0xFFFF0000) >> 16) -//Extracts the lower 16 bits of a 32-bit number +// Extracts the lower 16 bits of a 32-bit number #define LOHALF(n) ((n) & 0xFFFF) const u8 *species_and_otid_get_pal(u16 species, u32 otId, u32 personality) @@ -1472,14 +1479,130 @@ const u8* GetTrainerPartnerName(void) } } -void sub_817F544(void (*spriteCallback)(struct Sprite*), u8); +#define READ_PTR_FROM_TASK(taskId, dataId) \ + (void*)( \ + ((u16)(gTasks[taskId].data[dataId]) | \ + ((u16)(gTasks[taskId].data[dataId + 1]) << 0x10))) -void sub_806EC70(u8 taskId) +#define STORE_PTR_IN_TASK(ptr, taskId, dataId) \ +{ \ + gTasks[taskId].data[dataId] = (u32)(ptr); \ + gTasks[taskId].data[dataId + 1] = (u32)(ptr) >> 0x10; \ +} + +static void Task_AnimateAfterDelay(u8 taskId) { if (--gTasks[taskId].data[3] == 0) { - void* ptr = (void*)((u16)(gTasks[taskId].data[0]) | ((u16)(gTasks[taskId].data[1]) << 0x10)); - sub_817F544(ptr, gTasks[taskId].data[2]); + LaunchAnimationTaskForFrontSprite(READ_PTR_FROM_TASK(taskId, 0), gTasks[taskId].data[2]); DestroyTask(taskId); } } + +static void Task_PokemonSummaryAnimateAfterDelay(u8 taskId) +{ + if (--gTasks[taskId].data[3] == 0) + { + sub_817F578(READ_PTR_FROM_TASK(taskId, 0), gTasks[taskId].data[2]); + sub_81C488C(0xFF); + DestroyTask(taskId); + } +} + +void DoMonFrontSpriteAnimation(struct Sprite* sprite, u16 species, bool8 noCry, u8 arg3); + +void BattleAnimateFrontSprite(struct Sprite* sprite, u16 species, bool8 noCry, u8 arg3) +{ + if (gHitMarker & HITMARKER_NO_ANIMATIONS && !(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000))) + DoMonFrontSpriteAnimation(sprite, species, noCry, arg3 | 0x80); + else + DoMonFrontSpriteAnimation(sprite, species, noCry, arg3); +} + +bool8 HasTwoFramesAnimation(u16 species); + +extern void SpriteCallbackDummy_2(struct Sprite*); +extern void sub_817F60C(struct Sprite*); + +void DoMonFrontSpriteAnimation(struct Sprite* sprite, u16 species, bool8 noCry, u8 arg3) +{ + s8 pan; + switch (arg3 & 0x7F) + { + case 0: + pan = -25; + break; + case 1: + pan = 25; + break; + default: + pan = 0; + break; + } + if (arg3 & 0x80) + { + if (!noCry) + PlayCry1(species, pan); + sprite->callback = SpriteCallbackDummy; + } + else + { + if (!noCry) + { + PlayCry1(species, pan); + if (HasTwoFramesAnimation(species)) + StartSpriteAnim(sprite, 1); + } + if (gMonAnimationDelayTable[species - 1] != 0) + { + u8 taskId = CreateTask(Task_AnimateAfterDelay, 0); + STORE_PTR_IN_TASK(sprite, taskId, 0); + gTasks[taskId].data[2] = gMonFrontAnimIdsTable[species - 1]; + gTasks[taskId].data[3] = gMonAnimationDelayTable[species - 1]; + } + else + { + LaunchAnimationTaskForFrontSprite(sprite, gMonFrontAnimIdsTable[species - 1]); + } + sprite->callback = SpriteCallbackDummy_2; + } +} + +void PokemonSummaryDoMonAnimation(struct Sprite* sprite, u16 species, bool8 oneFrame) +{ + if (!oneFrame && HasTwoFramesAnimation(species)) + StartSpriteAnim(sprite, 1); + if (gMonAnimationDelayTable[species - 1] != 0) + { + u8 taskId = CreateTask(Task_PokemonSummaryAnimateAfterDelay, 0); + STORE_PTR_IN_TASK(sprite, taskId, 0); + gTasks[taskId].data[2] = gMonFrontAnimIdsTable[species - 1]; + gTasks[taskId].data[3] = gMonAnimationDelayTable[species - 1]; + sub_81C488C(taskId); + sub_817F60C(sprite); + } + else + { + sub_817F578(sprite, gMonFrontAnimIdsTable[species - 1]); + } +} + +void sub_806EE98(void) +{ + u8 delayTaskId = FindTaskIdByFunc(Task_PokemonSummaryAnimateAfterDelay); + if (delayTaskId != 0xFF) + DestroyTask(delayTaskId); +} + +void BattleAnimateBackSprite(struct Sprite* sprite, u16 species) +{ + if (gHitMarker & HITMARKER_NO_ANIMATIONS && !(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000))) + { + sprite->callback = SpriteCallbackDummy; + } + else + { + LaunchAnimationTaskForBackSprite(sprite, GetSpeciesBackAnimId(species)); + sprite->callback = SpriteCallbackDummy_2; + } +}