diff options
Diffstat (limited to 'src/field_effect.c')
-rw-r--r-- | src/field_effect.c | 2538 |
1 files changed, 1350 insertions, 1188 deletions
diff --git a/src/field_effect.c b/src/field_effect.c index bc1e6f134..582551a7e 100644 --- a/src/field_effect.c +++ b/src/field_effect.c @@ -39,195 +39,197 @@ EWRAM_DATA s32 gFieldEffectArguments[8] = {0}; // Static type declarations static void Task_PokecenterHeal(u8 taskId); -static void PokecenterHealEffect_0(struct Task *); -static void PokecenterHealEffect_1(struct Task *); -static void PokecenterHealEffect_2(struct Task *); -static void PokecenterHealEffect_3(struct Task *); +static void PokecenterHealEffect_Init(struct Task *); +static void PokecenterHealEffect_WaitForBallPlacement(struct Task *); +static void PokecenterHealEffect_WaitForBallFlashing(struct Task *); +static void PokecenterHealEffect_WaitForSoundAndEnd(struct Task *); +static u8 CreatePokecenterMonitorSprite(s16, s16); +static void SpriteCB_PokecenterMonitor(struct Sprite *); static void Task_HallOfFameRecord(u8 taskId); -static void HallOfFameRecordEffect_0(struct Task *); -static void HallOfFameRecordEffect_1(struct Task *); -static void HallOfFameRecordEffect_2(struct Task *); -static void HallOfFameRecordEffect_3(struct Task *); - -static u8 CreatePokeballGlowSprite(s16, s16, s16, u16); +static void HallOfFameRecordEffect_Init(struct Task *); +static void HallOfFameRecordEffect_WaitForBallPlacement(struct Task *); +static void HallOfFameRecordEffect_WaitForBallFlashing(struct Task *); +static void HallOfFameRecordEffect_WaitForSoundAndEnd(struct Task *); +static void CreateHofMonitorSprite(s16, s16, s16, bool8); +static void SpriteCB_HallOfFameMonitor(struct Sprite *); + +static u8 CreateGlowingPokeballsEffect(s16, s16, s16, bool16); static void SpriteCB_PokeballGlowEffect(struct Sprite *); -static void PokeballGlowEffect_0(struct Sprite *); -static void PokeballGlowEffect_1(struct Sprite *); -static void PokeballGlowEffect_2(struct Sprite *); -static void PokeballGlowEffect_3(struct Sprite *); -static void PokeballGlowEffect_4(struct Sprite *); -static void PokeballGlowEffect_5(struct Sprite *); -static void PokeballGlowEffect_6(struct Sprite *); -static void PokeballGlowEffect_7(struct Sprite *); - -static u8 PokecenterHealEffectHelper(s16, s16); -static void HallOfFameRecordEffectHelper(s16, s16, s16, u8); - -static void FieldCallback_Fly(void); -static void task00_8084310(u8); -static void mapldr_08084390(void); -static void c3_080843F8(u8); +static void PokeballGlowEffect_PlaceBalls(struct Sprite *); +static void PokeballGlowEffect_TryPlaySe(struct Sprite *); +static void PokeballGlowEffect_Flash1(struct Sprite *); +static void PokeballGlowEffect_Flash2(struct Sprite *); +static void PokeballGlowEffect_WaitAfterFlash(struct Sprite *); +static void PokeballGlowEffect_Dummy(struct Sprite *); +static void PokeballGlowEffect_WaitForSound(struct Sprite *); +static void PokeballGlowEffect_Idle(struct Sprite *); +static void SpriteCB_PokeballGlow(struct Sprite *); + +static void FieldCallback_UseFly(void); +static void Task_UseFly(u8); +static void FieldCallback_FlyIntoMap(void); +static void Task_FlyIntoMap(u8); static void Task_FallWarpFieldEffect(u8); -static bool8 FallWarpEffect_1(struct Task *); -static bool8 FallWarpEffect_2(struct Task *); -static bool8 FallWarpEffect_3(struct Task *); -static bool8 FallWarpEffect_4(struct Task *); -static bool8 FallWarpEffect_5(struct Task *); -static bool8 FallWarpEffect_6(struct Task *); -static bool8 FallWarpEffect_7(struct Task *); - -static void Task_EscalatorWarpFieldEffect(u8); -static bool8 EscalatorWarpEffect_1(struct Task *); -static bool8 EscalatorWarpEffect_2(struct Task *); -static bool8 EscalatorWarpEffect_3(struct Task *); -static bool8 EscalatorWarpEffect_4(struct Task *); -static bool8 EscalatorWarpEffect_5(struct Task *); -static bool8 EscalatorWarpEffect_6(struct Task *); - -static void sub_80B6FB8(struct Task *); -static void sub_80B7004(struct Task *); -static void sub_80B7050(void); -static void sub_80B7060(void); -static void sub_80B70B4(void); -static void sub_80B70DC(u8); - -static bool8 sub_80B7114(struct Task *); -static bool8 sub_80B7190(struct Task *); -static bool8 sub_80B71D0(struct Task *); -static bool8 sub_80B7230(struct Task *); -static bool8 sub_80B7270(struct Task *); -static bool8 sub_80B72D0(struct Task *); -static bool8 sub_80B72F4(struct Task *); - -static void sub_80B7384(u8); -static bool8 sub_80B73D0(struct Task *, struct ObjectEvent *); -static bool8 waterfall_1_do_anim_probably(struct Task *, struct ObjectEvent *); -static bool8 waterfall_2_wait_anim_finish_probably(struct Task *, struct ObjectEvent *); -static bool8 sub_80B7450(struct Task *, struct ObjectEvent *); -static bool8 sub_80B7478(struct Task *, struct ObjectEvent *); - -static void Task_Dive(u8); -static bool8 dive_1_lock(struct Task *); -static bool8 dive_2_unknown(struct Task *); -static bool8 dive_3_unknown(struct Task *); +static bool8 FallWarpEffect_Init(struct Task *); +static bool8 FallWarpEffect_WaitWeather(struct Task *); +static bool8 FallWarpEffect_StartFall(struct Task *); +static bool8 FallWarpEffect_Fall(struct Task *); +static bool8 FallWarpEffect_Land(struct Task *); +static bool8 FallWarpEffect_CameraShake(struct Task *); +static bool8 FallWarpEffect_End(struct Task *); + +static void Task_EscalatorWarpOut(u8); +static bool8 EscalatorWarpOut_Init(struct Task *); +static bool8 EscalatorWarpOut_WaitForPlayer(struct Task *); +static bool8 EscalatorWarpOut_Up_Ride(struct Task *); +static bool8 EscalatorWarpOut_Up_End(struct Task *); +static bool8 EscalatorWarpOut_Down_Ride(struct Task *); +static bool8 EscalatorWarpOut_Down_End(struct Task *); +static void RideUpEscalatorOut(struct Task *); +static void RideDownEscalatorOut(struct Task *); +static void FadeOutAtEndOfEscalator(void); +static void WarpAtEndOfEscalator(void); + +static void FieldCallback_EscalatorWarpIn(void); +static void Task_EscalatorWarpIn(u8); +static bool8 EscalatorWarpIn_Init(struct Task *); +static bool8 EscalatorWarpIn_Down_Init(struct Task *); +static bool8 EscalatorWarpIn_Down_Ride(struct Task *); +static bool8 EscalatorWarpIn_Up_Init(struct Task *); +static bool8 EscalatorWarpIn_Up_Ride(struct Task *); +static bool8 EscalatorWarpIn_WaitForMovement(struct Task *); +static bool8 EscalatorWarpIn_End(struct Task *); + +static void Task_UseWaterfall(u8); +static bool8 WaterfallFieldEffect_Init(struct Task *, struct ObjectEvent *); +static bool8 WaterfallFieldEffect_ShowMon(struct Task *, struct ObjectEvent *); +static bool8 WaterfallFieldEffect_WaitForShowMon(struct Task *, struct ObjectEvent *); +static bool8 WaterfallFieldEffect_RideUp(struct Task *, struct ObjectEvent *); +static bool8 WaterfallFieldEffect_ContinueRideOrEnd(struct Task *, struct ObjectEvent *); + +static void Task_UseDive(u8); +static bool8 DiveFieldEffect_Init(struct Task *); +static bool8 DiveFieldEffect_ShowMon(struct Task *); +static bool8 DiveFieldEffect_TryWarp(struct Task *); static void Task_LavaridgeGymB1FWarp(u8); -static bool8 LavaridgeGymB1FWarpEffect_1(struct Task *, struct ObjectEvent *, struct Sprite *); -static bool8 LavaridgeGymB1FWarpEffect_2(struct Task *, struct ObjectEvent *, struct Sprite *); -static bool8 LavaridgeGymB1FWarpEffect_3(struct Task *, struct ObjectEvent *, struct Sprite *); -static bool8 LavaridgeGymB1FWarpEffect_4(struct Task *, struct ObjectEvent *, struct Sprite *); -static bool8 LavaridgeGymB1FWarpEffect_5(struct Task *, struct ObjectEvent *, struct Sprite *); -static bool8 LavaridgeGymB1FWarpEffect_6(struct Task *, struct ObjectEvent *, struct Sprite *); +static bool8 LavaridgeGymB1FWarpEffect_Init(struct Task *, struct ObjectEvent *, struct Sprite *); +static bool8 LavaridgeGymB1FWarpEffect_CameraShake(struct Task *, struct ObjectEvent *, struct Sprite *); +static bool8 LavaridgeGymB1FWarpEffect_Launch(struct Task *, struct ObjectEvent *, struct Sprite *); +static bool8 LavaridgeGymB1FWarpEffect_Rise(struct Task *, struct ObjectEvent *, struct Sprite *); +static bool8 LavaridgeGymB1FWarpEffect_FadeOut(struct Task *, struct ObjectEvent *, struct Sprite *); +static bool8 LavaridgeGymB1FWarpEffect_Warp(struct Task *, struct ObjectEvent *, struct Sprite *); static void FieldCB_LavaridgeGymB1FWarpExit(void); static void Task_LavaridgeGymB1FWarpExit(u8); -static bool8 LavaridgeGymB1FWarpExitEffect_1(struct Task *, struct ObjectEvent *, struct Sprite *); -static bool8 LavaridgeGymB1FWarpExitEffect_2(struct Task *, struct ObjectEvent *, struct Sprite *); -static bool8 LavaridgeGymB1FWarpExitEffect_3(struct Task *, struct ObjectEvent *, struct Sprite *); -static bool8 LavaridgeGymB1FWarpExitEffect_4(struct Task *, struct ObjectEvent *, struct Sprite *); +static bool8 LavaridgeGymB1FWarpExitEffect_Init(struct Task *, struct ObjectEvent *, struct Sprite *); +static bool8 LavaridgeGymB1FWarpExitEffect_StartPopOut(struct Task *, struct ObjectEvent *, struct Sprite *); +static bool8 LavaridgeGymB1FWarpExitEffect_PopOut(struct Task *, struct ObjectEvent *, struct Sprite *); +static bool8 LavaridgeGymB1FWarpExitEffect_End(struct Task *, struct ObjectEvent *, struct Sprite *); static void Task_LavaridgeGym1FWarp(u8); -static bool8 LavaridgeGym1FWarpEffect_1(struct Task *, struct ObjectEvent *, struct Sprite *); -static bool8 LavaridgeGym1FWarpEffect_2(struct Task *, struct ObjectEvent *, struct Sprite *); -static bool8 LavaridgeGym1FWarpEffect_3(struct Task *, struct ObjectEvent *, struct Sprite *); -static bool8 LavaridgeGym1FWarpEffect_4(struct Task *, struct ObjectEvent *, struct Sprite *); -static bool8 LavaridgeGym1FWarpEffect_5(struct Task *, struct ObjectEvent *, struct Sprite *); - -static void DoEscapeRopeFieldEffect(u8); -static void EscapeRopeFieldEffect_Step0(struct Task *); -static void EscapeRopeFieldEffect_Step1(struct Task *); - -static void mapldr_080859D4(void); -static void sub_80B7E94(u8); - -static void sub_80B7EC4(struct Task *); -static void sub_80B7EE8(struct Task *); - -static void ExecuteTeleportFieldEffectTask(u8); -static void TeleportFieldEffectTask1(struct Task*); -static void TeleportFieldEffectTask2(struct Task*); -static void TeleportFieldEffectTask3(struct Task*); -static void TeleportFieldEffectTask4(struct Task*); - -static void mapldr_08085D88(void); -static void sub_80B8250(u8); - -static void sub_80B8280(struct Task *); -static void sub_80B830C(struct Task *); -static void sub_80B8410(struct Task *); - -static void sub_80B8554(u8); -static void sub_80B8584(struct Task *); -static void sub_80B85F8(struct Task *); -static void sub_80B8660(struct Task *); -static void sub_80B86EC(struct Task *); -static void sub_80B871C(struct Task *); -static void sub_80B8770(struct Task *); -static void overworld_bg_setup_2(struct Task *); - -static void sub_80B880C(void); -static void sub_80B8874(u16); - -static void sub_80B88B4(u8); -static void sub_80B88E4(struct Task *); -static void sub_80B8920(struct Task *); -static void sub_80B898C(struct Task *); -static void sub_80B89DC(struct Task *); -static void sub_80B8A0C(struct Task *); -static void sub_80B8A44(struct Task *); -static void sub_80B8A64(struct Task *); - -static void sub_80B8AE0(void); -static void sub_80B8B28(struct Task *); -static bool8 sub_80B8B38(struct Task *); -static bool8 sub_80B8BF0(struct Task *); - -static u8 sub_80B8C60(u32, u32, u32); -static void sub_80B8CC0(struct Sprite *); -static void sub_80B8D04(struct Sprite *); -static void sub_80B8D20(struct Sprite *); - -static void sub_80B8D84(u8); -static void sub_80B8DB4(struct Task *); -static void sub_80B8E14(struct Task *); -static void sub_80B8E60(struct Task *); -static void sub_80B8EA8(struct Task *); -static void sub_80B8F24(struct Task *); - -static void sub_80B9128(struct Sprite *); - -static void sub_80B91D4(u8); -static void sub_80B9204(struct Task *); -static void sub_80B925C(struct Task *); -static void sub_80B92A0(struct Task *); -static void sub_80B92F8(struct Task *); -static void sub_80B933C(struct Task *); -static void sub_80B9390(struct Task *); -static void sub_80B9418(struct Task *); -static void sub_80B9474(struct Task *); -static void sub_80B9494(struct Task *); - -static u8 sub_80B94C4(void); -static u8 sub_80B9508(u8); -static void sub_80B9524(u8); -static void sub_80B9560(u8, u8); -static void sub_80B957C(struct Sprite *); -static void sub_80B963C(struct Sprite *); - -static void sub_80B97D4(u8); -static void sub_80B9804(struct Task *); -static void sub_80B98B8(struct Task *); -static void sub_80B9924(struct Task *); -static void sub_80B9978(struct Task *); -static void sub_80B99F0(struct Task *); -static void sub_80B9A28(struct Task *); -static void sub_80B9A60(struct Task *); - -static void sub_80B9BE8(u8 taskId); -static void sub_80B9DB8(struct Sprite* sprite); -static void Fldeff_MoveDeoxysRock_Step(u8 taskId); +static bool8 LavaridgeGym1FWarpEffect_Init(struct Task *, struct ObjectEvent *, struct Sprite *); +static bool8 LavaridgeGym1FWarpEffect_AshPuff(struct Task *, struct ObjectEvent *, struct Sprite *); +static bool8 LavaridgeGym1FWarpEffect_Disappear(struct Task *, struct ObjectEvent *, struct Sprite *); +static bool8 LavaridgeGym1FWarpEffect_FadeOut(struct Task *, struct ObjectEvent *, struct Sprite *); +static bool8 LavaridgeGym1FWarpEffect_Warp(struct Task *, struct ObjectEvent *, struct Sprite *); + +static void Task_EscapeRopeWarpOut(u8); +static void EscapeRopeWarpOutEffect_Init(struct Task *); +static void EscapeRopeWarpOutEffect_Spin(struct Task *); + +static void FieldCallback_EscapeRopeWarpIn(void); +static void Task_EscapeRopeWarpIn(u8); +static void EscapeRopeWarpInEffect_Init(struct Task *); +static void EscapeRopeWarpInEffect_Spin(struct Task *); + +static void Task_TeleportWarpOut(u8); +static void TeleportWarpOutFieldEffect_Init(struct Task*); +static void TeleportWarpOutFieldEffect_SpinGround(struct Task*); +static void TeleportWarpOutFieldEffect_SpinExit(struct Task*); +static void TeleportWarpOutFieldEffect_End(struct Task*); + +static void FieldCallback_TeleportWarpIn(void); +static void Task_TeleportWarpIn(u8); +static void TeleportWarpInFieldEffect_Init(struct Task *); +static void TeleportWarpInFieldEffect_SpinEnter(struct Task *); +static void TeleportWarpInFieldEffect_SpinGround(struct Task *); + +static void Task_FieldMoveShowMonOutdoors(u8); +static void FieldMoveShowMonOutdoorsEffect_Init(struct Task *); +static void FieldMoveShowMonOutdoorsEffect_LoadGfx(struct Task *); +static void FieldMoveShowMonOutdoorsEffect_CreateBanner(struct Task *); +static void FieldMoveShowMonOutdoorsEffect_WaitForMon(struct Task *); +static void FieldMoveShowMonOutdoorsEffect_ShrinkBanner(struct Task *); +static void FieldMoveShowMonOutdoorsEffect_RestoreBg(struct Task *); +static void FieldMoveShowMonOutdoorsEffect_End(struct Task *); +static void VBlankCB_FieldMoveShowMonOutdoors(void); +static void LoadFieldMoveOutdoorStreaksTilemap(u16); + +static void Task_FieldMoveShowMonIndoors(u8); +static void FieldMoveShowMonIndoorsEffect_Init(struct Task *); +static void FieldMoveShowMonIndoorsEffect_LoadGfx(struct Task *); +static void FieldMoveShowMonIndoorsEffect_SlideBannerOn(struct Task *); +static void FieldMoveShowMonIndoorsEffect_WaitForMon(struct Task *); +static void FieldMoveShowMonIndoorsEffect_RestoreBg(struct Task *); +static void FieldMoveShowMonIndoorsEffect_SlideBannerOff(struct Task *); +static void FieldMoveShowMonIndoorsEffect_End(struct Task *); +static void VBlankCB_FieldMoveShowMonIndoors(void); +static void AnimateIndoorShowMonBg(struct Task *); +static bool8 SlideIndoorBannerOnscreen(struct Task *); +static bool8 SlideIndoorBannerOffscreen(struct Task *); + +static u8 InitFieldMoveMonSprite(u32, u32, u32); +static void SpriteCB_FieldMoveMonSlideOnscreen(struct Sprite *); +static void SpriteCB_FieldMoveMonWaitAfterCry(struct Sprite *); +static void SpriteCB_FieldMoveMonSlideOffscreen(struct Sprite *); + +static void Task_SurfFieldEffect(u8); +static void SurfFieldEffect_Init(struct Task *); +static void SurfFieldEffect_FieldMovePose(struct Task *); +static void SurfFieldEffect_ShowMon(struct Task *); +static void SurfFieldEffect_JumpOnSurfBlob(struct Task *); +static void SurfFieldEffect_End(struct Task *); + +static void SpriteCB_NPCFlyOut(struct Sprite *); + +static void Task_FlyOut(u8); +static void FlyOutFieldEffect_FieldMovePose(struct Task *); +static void FlyOutFieldEffect_ShowMon(struct Task *); +static void FlyOutFieldEffect_BirdLeaveBall(struct Task *); +static void FlyOutFieldEffect_WaitBirdLeave(struct Task *); +static void FlyOutFieldEffect_BirdSwoopDown(struct Task *); +static void FlyOutFieldEffect_JumpOnBird(struct Task *); +static void FlyOutFieldEffect_FlyOffWithBird(struct Task *); +static void FlyOutFieldEffect_WaitFlyOff(struct Task *); +static void FlyOutFieldEffect_End(struct Task *); + +static u8 CreateFlyBirdSprite(void); +static u8 GetFlyBirdAnimCompleted(u8); +static void StartFlyBirdSwoopDown(u8); +static void SetFlyBirdPlayerSpriteId(u8, u8); +static void SpriteCB_FlyBirdLeaveBall(struct Sprite *); +static void SpriteCB_FlyBirdSwoopDown(struct Sprite *); + +static void Task_FlyIn(u8); +static void FlyInFieldEffect_BirdSwoopDown(struct Task *); +static void FlyInFieldEffect_FlyInWithBird(struct Task *); +static void FlyInFieldEffect_JumpOffBird(struct Task *); +static void FlyInFieldEffect_FieldMovePose(struct Task *); +static void FlyInFieldEffect_BirdReturnToBall(struct Task *); +static void FlyInFieldEffect_WaitBirdReturn(struct Task *); +static void FlyInFieldEffect_End(struct Task *); + +static void Task_DestroyDeoxysRock(u8 taskId); +static void DestroyDeoxysRockEffect_CameraShake(s16*, u8); +static void DestroyDeoxysRockEffect_RockFragments(s16*, u8); +static void DestroyDeoxysRockEffect_WaitAndEnd(s16*, u8); +static void CreateDeoxysRockFragments(struct Sprite*); +static void SpriteCB_DeoxysRockFragment(struct Sprite* sprite); + +static void Task_MoveDeoxysRock(u8 taskId); // Static RAM declarations @@ -240,34 +242,33 @@ extern const struct CompressedSpriteSheet gTrainerFrontPicTable[]; extern u8 *gFieldEffectScriptPointers[]; extern const struct SpriteTemplate *const gFieldEffectObjectTemplatePointers[]; -// .rodata -const u32 gNewGameBirchPic[] = INCBIN_U32("graphics/birch_speech/birch.4bpp"); -const u32 gUnusedBirchBeauty[] = INCBIN_U32("graphics/unused/intro_birch_beauty.4bpp"); -const u16 gNewGameBirchPalette[16] = INCBIN_U16("graphics/birch_speech/birch.gbapal"); -const u32 gSpriteImage_855A970[] = INCBIN_U32("graphics/misc/pokeball_glow.4bpp"); -const u16 gFieldEffectObjectPalette4[16] = INCBIN_U16("graphics/field_effects/palettes/04.gbapal"); -const u32 gSpriteImage_855A9B0[] = INCBIN_U32("graphics/misc/pokecenter_monitor/0.4bpp"); -const u32 gSpriteImage_855AA70[] = INCBIN_U32("graphics/misc/pokecenter_monitor/1.4bpp"); -const u32 gSpriteImage_855AB30[] = INCBIN_U32("graphics/misc/big_hof_monitor.4bpp"); -const u8 gSpriteImage_855AD30[] = INCBIN_U8("graphics/misc/small_hof_monitor.4bpp"); -const u16 gFieldEffectObjectPalette5[16] = INCBIN_U16("graphics/field_effects/palettes/05.gbapal"); +static const u32 sNewGameBirch_Gfx[] = INCBIN_U32("graphics/birch_speech/birch.4bpp"); +static const u32 sUnusedBirchBeauty[] = INCBIN_U32("graphics/unused/intro_birch_beauty.4bpp"); +static const u16 sNewGameBirch_Pal[16] = INCBIN_U16("graphics/birch_speech/birch.gbapal"); +static const u32 sPokeballGlow_Gfx[] = INCBIN_U32("graphics/misc/pokeball_glow.4bpp"); +static const u16 sPokeballGlow_Pal[16] = INCBIN_U16("graphics/field_effects/palettes/pokeball_glow.gbapal"); +static const u32 sPokecenterMonitor0_Gfx[] = INCBIN_U32("graphics/misc/pokecenter_monitor/0.4bpp"); +static const u32 sPokecenterMonitor1_Gfx[] = INCBIN_U32("graphics/misc/pokecenter_monitor/1.4bpp"); +static const u32 sHofMonitorBig_Gfx[] = INCBIN_U32("graphics/misc/hof_monitor_big.4bpp"); +static const u8 sHofMonitorSmall_Gfx[] = INCBIN_U8("graphics/misc/hof_monitor_small.4bpp"); +static const u16 sHofMonitor_Pal[16] = INCBIN_U16("graphics/field_effects/palettes/hof_monitor.gbapal"); // Graphics for the lights streaking past your Pokemon when it uses a field move. -const u32 gFieldMoveStreaksTiles[] = INCBIN_U32("graphics/misc/field_move_streaks.4bpp"); -const u16 gFieldMoveStreaksPalette[16] = INCBIN_U16("graphics/misc/field_move_streaks.gbapal"); -const u16 gFieldMoveStreaksTilemap[] = INCBIN_U16("graphics/misc/field_move_streaks_map.bin"); - -// The following light streaks effect is used when the map is dark (e.g. a cave). -const u32 gDarknessFieldMoveStreaksTiles[] = INCBIN_U32("graphics/misc/darkness_field_move_streaks.4bpp"); -const u16 gDarknessFieldMoveStreaksPalette[16] = INCBIN_U16("graphics/misc/darkness_field_move_streaks.gbapal"); -const u16 gDarknessFieldMoveStreaksTilemap[] = INCBIN_U16("graphics/misc/darkness_field_move_streaks_map.bin"); - -const u16 gUnknown_0855B610[16] = INCBIN_U16("graphics/misc/spotlight.gbapal"); -const u8 gUnknown_0855B630[] = INCBIN_U8("graphics/misc/spotlight.4bpp"); -const u8 gUnknown_0855C170[] = INCBIN_U8("graphics/unknown/unknown_55C170.4bpp"); -const u8 gUnknown_0855C190[] = INCBIN_U8("graphics/unknown/unknown_55C190.4bpp"); -const u8 gUnknown_0855C1B0[] = INCBIN_U8("graphics/unknown/unknown_55C1B0.4bpp"); -const u8 gUnknown_0855C1D0[] = INCBIN_U8("graphics/unknown/unknown_55C1D0.4bpp"); +static const u32 sFieldMoveStreaksOutdoors_Gfx[] = INCBIN_U32("graphics/misc/field_move_streaks.4bpp"); +static const u16 sFieldMoveStreaksOutdoors_Pal[16] = INCBIN_U16("graphics/misc/field_move_streaks.gbapal"); +static const u16 sFieldMoveStreaksOutdoors_Tilemap[320] = INCBIN_U16("graphics/misc/field_move_streaks_map.bin"); + +// The following light streaks effect is used when the map is indoors +static const u32 sFieldMoveStreaksIndoors_Gfx[] = INCBIN_U32("graphics/misc/darkness_field_move_streaks.4bpp"); +static const u16 sFieldMoveStreaksIndoors_Pal[16] = INCBIN_U16("graphics/misc/darkness_field_move_streaks.gbapal"); +static const u16 sFieldMoveStreaksIndoors_Tilemap[320] = INCBIN_U16("graphics/misc/darkness_field_move_streaks_map.bin"); + +static const u16 sSpotlight_Pal[16] = INCBIN_U16("graphics/misc/spotlight.gbapal"); +static const u8 sSpotlight_Gfx[] = INCBIN_U8("graphics/misc/spotlight.4bpp"); +static const u8 sRockFragment_TopLeft[] = INCBIN_U8("graphics/misc/deoxys_rock_fragment_top_left.4bpp"); +static const u8 sRockFragment_TopRight[] = INCBIN_U8("graphics/misc/deoxys_rock_fragment_top_right.4bpp"); +static const u8 sRockFragment_BottomLeft[] = INCBIN_U8("graphics/misc/deoxys_rock_fragment_bottom_left.4bpp"); +static const u8 sRockFragment_BottomRight[] = INCBIN_U8("graphics/misc/deoxys_rock_fragment_bottom_right.4bpp"); bool8 (*const gFieldEffectScriptFuncs[])(u8 **, u32 *) = { @@ -281,7 +282,7 @@ bool8 (*const gFieldEffectScriptFuncs[])(u8 **, u32 *) = FieldEffectCmd_loadfadedpal_callnative, }; -const struct OamData gNewGameBirchOamAttributes = +static const struct OamData sOam_64x64 = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -295,7 +296,7 @@ const struct OamData gNewGameBirchOamAttributes = .paletteNum = 0, }; -const struct OamData gOamData_855C218 = +static const struct OamData sOam_8x8 = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -309,7 +310,7 @@ const struct OamData gOamData_855C218 = .paletteNum = 0, }; -const struct OamData gOamData_855C220 = +static const struct OamData sOam_16x16 = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -323,52 +324,52 @@ const struct OamData gOamData_855C220 = .paletteNum = 0, }; -const struct SpriteFrameImage gNewGameBirchPicTable[] = +static const struct SpriteFrameImage sPicTable_NewGameBirch[] = { - obj_frame_tiles(gNewGameBirchPic) + obj_frame_tiles(sNewGameBirch_Gfx) }; -const struct SpritePalette gNewGameBirchObjectPaletteInfo = +static const struct SpritePalette sSpritePalette_NewGameBirch = { - .data = gNewGameBirchPalette, + .data = sNewGameBirch_Pal, .tag = 0x1006 }; -const union AnimCmd gNewGameBirchImageAnim[] = +static const union AnimCmd sAnim_NewGameBirch[] = { ANIMCMD_FRAME(.imageValue = 0, .duration = 1), ANIMCMD_END }; -const union AnimCmd *const gNewGameBirchImageAnimTable[] = +static const union AnimCmd *const sAnimTable_NewGameBirch[] = { - gNewGameBirchImageAnim + sAnim_NewGameBirch }; -const struct SpriteTemplate gNewGameBirchObjectTemplate = +static const struct SpriteTemplate sSpriteTemplate_NewGameBirch = { .tileTag = 0xFFFF, - .paletteTag = 4102, - .oam = &gNewGameBirchOamAttributes, - .anims = gNewGameBirchImageAnimTable, - .images = gNewGameBirchPicTable, + .paletteTag = 0x1006, + .oam = &sOam_64x64, + .anims = sAnimTable_NewGameBirch, + .images = sPicTable_NewGameBirch, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy }; -const struct SpritePalette gFieldEffectObjectPaletteInfo4 = +const struct SpritePalette gSpritePalette_PokeballGlow = { - .data = gFieldEffectObjectPalette4, - .tag = 0x1007 + .data = sPokeballGlow_Pal, + .tag = FLDEFF_PAL_TAG_POKEBALL_GLOW }; -const struct SpritePalette gFieldEffectObjectPaletteInfo5 = +const struct SpritePalette gSpritePalette_HofMonitor = { - .data = gFieldEffectObjectPalette5, - .tag = 0x1010 + .data = sHofMonitor_Pal, + .tag = FLDEFF_PAL_TAG_HOF_MONITOR }; -const struct OamData gOamData_855C26C = +static const struct OamData sOam_32x16 = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -382,28 +383,28 @@ const struct OamData gOamData_855C26C = .paletteNum = 0, }; -const struct SpriteFrameImage gSpriteImageTable_855C274[] = +static const struct SpriteFrameImage sPicTable_PokeballGlow[] = { - obj_frame_tiles(gSpriteImage_855A970) + obj_frame_tiles(sPokeballGlow_Gfx) }; -const struct SpriteFrameImage gSpriteImageTable_855C27C[] = +static const struct SpriteFrameImage sPicTable_PokecenterMonitor[] = { - obj_frame_tiles(gSpriteImage_855A9B0), - obj_frame_tiles(gSpriteImage_855AA70) + obj_frame_tiles(sPokecenterMonitor0_Gfx), + obj_frame_tiles(sPokecenterMonitor1_Gfx) }; -const struct SpriteFrameImage gSpriteImageTable_855C28C[] = +static const struct SpriteFrameImage sPicTable_HofMonitorBig[] = { - obj_frame_tiles(gSpriteImage_855AB30) + obj_frame_tiles(sHofMonitorBig_Gfx) }; -const struct SpriteFrameImage gSpriteImageTable_855C294[] = +static const struct SpriteFrameImage sPicTable_HofMonitorSmall[] = { - {.data = gSpriteImage_855AD30, .size = 0x200} // the macro breaks down here + {.data = sHofMonitorSmall_Gfx, .size = 0x200} // the macro breaks down here }; -const struct Subsprite gSubspriteTable_855C29C[] = +static const struct Subsprite sSubsprites_PokecenterMonitor[] = { { .x = -12, @@ -439,9 +440,9 @@ const struct Subsprite gSubspriteTable_855C29C[] = } }; -const struct SubspriteTable gUnknown_0855C2AC = subsprite_table(gSubspriteTable_855C29C); +static const struct SubspriteTable sSubspriteTable_PokecenterMonitor = subsprite_table(sSubsprites_PokecenterMonitor); -const struct Subsprite gSubspriteTable_855C2B4[] = +static const struct Subsprite sSubsprites_HofMonitorBig[] = { { .x = -32, @@ -477,7 +478,7 @@ const struct Subsprite gSubspriteTable_855C2B4[] = } }; -const struct SubspriteTable gUnknown_0855C2C4 = subsprite_table(gSubspriteTable_855C2B4); +static const struct SubspriteTable sSubspriteTable_HofMonitorBig = subsprite_table(sSubsprites_HofMonitorBig); const union AnimCmd gSpriteAnim_855C2CC[] = { @@ -504,84 +505,84 @@ const union AnimCmd *const gSpriteAnimTable_855C2F8[] = gSpriteAnim_855C2D4 }; -const union AnimCmd *const gSpriteAnimTable_855C300[] = +static const union AnimCmd *const sAnimTable_HofMonitor[] = { gSpriteAnim_855C2CC }; -const struct SpriteTemplate gSpriteTemplate_855C304 = +static const struct SpriteTemplate sSpriteTemplate_PokeballGlow = { .tileTag = 0xFFFF, - .paletteTag = 4103, - .oam = &gOamData_855C218, + .paletteTag = FLDEFF_PAL_TAG_POKEBALL_GLOW, + .oam = &sOam_8x8, .anims = gSpriteAnimTable_855C2F8, - .images = gSpriteImageTable_855C274, + .images = sPicTable_PokeballGlow, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCB_PokeballGlow }; -const struct SpriteTemplate gSpriteTemplate_855C31C = +static const struct SpriteTemplate sSpriteTemplate_PokecenterMonitor = { .tileTag = 0xFFFF, - .paletteTag = 4100, - .oam = &gOamData_855C220, + .paletteTag = FLDEFF_PAL_TAG_GENERAL_0, + .oam = &sOam_16x16, .anims = gSpriteAnimTable_855C2F8, - .images = gSpriteImageTable_855C27C, + .images = sPicTable_PokecenterMonitor, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCB_PokecenterMonitor }; -const struct SpriteTemplate gSpriteTemplate_855C334 = +static const struct SpriteTemplate sSpriteTemplate_HofMonitorBig = { .tileTag = 0xFFFF, - .paletteTag = 4112, - .oam = &gOamData_855C220, - .anims = gSpriteAnimTable_855C300, - .images = gSpriteImageTable_855C28C, + .paletteTag = FLDEFF_PAL_TAG_HOF_MONITOR, + .oam = &sOam_16x16, + .anims = sAnimTable_HofMonitor, + .images = sPicTable_HofMonitorBig, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCB_HallOfFameMonitor }; -const struct SpriteTemplate gSpriteTemplate_855C34C = +static const struct SpriteTemplate sSpriteTemplate_HofMonitorSmall = { .tileTag = 0xFFFF, - .paletteTag = 4112, - .oam = &gOamData_855C26C, - .anims = gSpriteAnimTable_855C300, - .images = gSpriteImageTable_855C294, + .paletteTag = FLDEFF_PAL_TAG_HOF_MONITOR, + .oam = &sOam_32x16, + .anims = sAnimTable_HofMonitor, + .images = sPicTable_HofMonitorSmall, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCB_HallOfFameMonitor }; -void (*const gUnknown_0855C364[])(struct Task *) = +void (*const sPokecenterHealEffectFuncs[])(struct Task *) = { - PokecenterHealEffect_0, - PokecenterHealEffect_1, - PokecenterHealEffect_2, - PokecenterHealEffect_3 + PokecenterHealEffect_Init, + PokecenterHealEffect_WaitForBallPlacement, + PokecenterHealEffect_WaitForBallFlashing, + PokecenterHealEffect_WaitForSoundAndEnd }; -void (*const gUnknown_0855C374[])(struct Task *) = +void (*const sHallOfFameRecordEffectFuncs[])(struct Task *) = { - HallOfFameRecordEffect_0, - HallOfFameRecordEffect_1, - HallOfFameRecordEffect_2, - HallOfFameRecordEffect_3 + HallOfFameRecordEffect_Init, + HallOfFameRecordEffect_WaitForBallPlacement, + HallOfFameRecordEffect_WaitForBallFlashing, + HallOfFameRecordEffect_WaitForSoundAndEnd }; -void (*const gUnknown_0855C384[])(struct Sprite *) = +void (*const sPokeballGlowEffectFuncs[])(struct Sprite *) = { - PokeballGlowEffect_0, - PokeballGlowEffect_1, - PokeballGlowEffect_2, - PokeballGlowEffect_3, - PokeballGlowEffect_4, - PokeballGlowEffect_5, - PokeballGlowEffect_6, - PokeballGlowEffect_7 + PokeballGlowEffect_PlaceBalls, + PokeballGlowEffect_TryPlaySe, + PokeballGlowEffect_Flash1, + PokeballGlowEffect_Flash2, + PokeballGlowEffect_WaitAfterFlash, + PokeballGlowEffect_Dummy, + PokeballGlowEffect_WaitForSound, + PokeballGlowEffect_Idle }; -const struct Coords16 gUnknown_0855C3A4[] = +static const struct Coords16 sPokeballCoordOffsets[PARTY_SIZE] = { {.x = 0, .y = 0}, {.x = 6, .y = 0}, @@ -591,93 +592,91 @@ const struct Coords16 gUnknown_0855C3A4[] = {.x = 6, .y = 8} }; -const u8 gUnknown_0855C3BC[] = {16, 12, 8, 0}; -const u8 gUnknown_0855C3C0[] = {16, 12, 8, 0}; -const u8 gUnknown_0855C3C4[] = { 0, 0, 0, 0}; +static const u8 sPokeballGlowReds[] = {16, 12, 8, 0}; +static const u8 sPokeballGlowGreens[] = {16, 12, 8, 0}; +static const u8 sPokeballGlowBlues[] = { 0, 0, 0, 0}; bool8 (*const sFallWarpFieldEffectFuncs[])(struct Task *) = { - FallWarpEffect_1, - FallWarpEffect_2, - FallWarpEffect_3, - FallWarpEffect_4, - FallWarpEffect_5, - FallWarpEffect_6, - FallWarpEffect_7, + FallWarpEffect_Init, + FallWarpEffect_WaitWeather, + FallWarpEffect_StartFall, + FallWarpEffect_Fall, + FallWarpEffect_Land, + FallWarpEffect_CameraShake, + FallWarpEffect_End, }; -bool8 (*const sEscalatorWarpFieldEffectFuncs[])(struct Task *) = +bool8 (*const sEscalatorWarpOutFieldEffectFuncs[])(struct Task *) = { - EscalatorWarpEffect_1, - EscalatorWarpEffect_2, - EscalatorWarpEffect_3, - EscalatorWarpEffect_4, - EscalatorWarpEffect_5, - EscalatorWarpEffect_6, + EscalatorWarpOut_Init, + EscalatorWarpOut_WaitForPlayer, + EscalatorWarpOut_Up_Ride, + EscalatorWarpOut_Up_End, + EscalatorWarpOut_Down_Ride, + EscalatorWarpOut_Down_End, }; -bool8 (*const gUnknown_0855C3FC[])(struct Task *) = +bool8 (*const sEscalatorWarpInFieldEffectFuncs[])(struct Task *) = { - sub_80B7114, - sub_80B7190, - sub_80B71D0, - sub_80B7230, - sub_80B7270, - sub_80B72D0, - sub_80B72F4, + EscalatorWarpIn_Init, + EscalatorWarpIn_Down_Init, + EscalatorWarpIn_Down_Ride, + EscalatorWarpIn_Up_Init, + EscalatorWarpIn_Up_Ride, + EscalatorWarpIn_WaitForMovement, + EscalatorWarpIn_End, }; -bool8 (*const gUnknown_0855C418[])(struct Task *, struct ObjectEvent *) = +bool8 (*const sWaterfallFieldEffectFuncs[])(struct Task *, struct ObjectEvent *) = { - sub_80B73D0, - waterfall_1_do_anim_probably, - waterfall_2_wait_anim_finish_probably, - sub_80B7450, - sub_80B7478, + WaterfallFieldEffect_Init, + WaterfallFieldEffect_ShowMon, + WaterfallFieldEffect_WaitForShowMon, + WaterfallFieldEffect_RideUp, + WaterfallFieldEffect_ContinueRideOrEnd, }; -bool8 (*const gUnknown_0855C42C[])(struct Task *) = +bool8 (*const sDiveFieldEffectFuncs[])(struct Task *) = { - dive_1_lock, - dive_2_unknown, - dive_3_unknown, + DiveFieldEffect_Init, + DiveFieldEffect_ShowMon, + DiveFieldEffect_TryWarp, }; bool8 (*const sLavaridgeGymB1FWarpEffectFuncs[])(struct Task *, struct ObjectEvent *, struct Sprite *) = { - LavaridgeGymB1FWarpEffect_1, - LavaridgeGymB1FWarpEffect_2, - LavaridgeGymB1FWarpEffect_3, - LavaridgeGymB1FWarpEffect_4, - LavaridgeGymB1FWarpEffect_5, - LavaridgeGymB1FWarpEffect_6, + LavaridgeGymB1FWarpEffect_Init, + LavaridgeGymB1FWarpEffect_CameraShake, + LavaridgeGymB1FWarpEffect_Launch, + LavaridgeGymB1FWarpEffect_Rise, + LavaridgeGymB1FWarpEffect_FadeOut, + LavaridgeGymB1FWarpEffect_Warp, }; bool8 (*const sLavaridgeGymB1FWarpExitEffectFuncs[])(struct Task *, struct ObjectEvent *, struct Sprite *) = { - LavaridgeGymB1FWarpExitEffect_1, - LavaridgeGymB1FWarpExitEffect_2, - LavaridgeGymB1FWarpExitEffect_3, - LavaridgeGymB1FWarpExitEffect_4, + LavaridgeGymB1FWarpExitEffect_Init, + LavaridgeGymB1FWarpExitEffect_StartPopOut, + LavaridgeGymB1FWarpExitEffect_PopOut, + LavaridgeGymB1FWarpExitEffect_End, }; bool8 (*const sLavaridgeGym1FWarpEffectFuncs[])(struct Task *, struct ObjectEvent *, struct Sprite *) = { - LavaridgeGym1FWarpEffect_1, - LavaridgeGym1FWarpEffect_2, - LavaridgeGym1FWarpEffect_3, - LavaridgeGym1FWarpEffect_4, - LavaridgeGym1FWarpEffect_5, + LavaridgeGym1FWarpEffect_Init, + LavaridgeGym1FWarpEffect_AshPuff, + LavaridgeGym1FWarpEffect_Disappear, + LavaridgeGym1FWarpEffect_FadeOut, + LavaridgeGym1FWarpEffect_Warp, }; -void (*const gEscapeRopeFieldEffectFuncs[])(struct Task *) = +void (*const sEscapeRopeWarpOutEffectFuncs[])(struct Task *) = { - EscapeRopeFieldEffect_Step0, - EscapeRopeFieldEffect_Step1, + EscapeRopeWarpOutEffect_Init, + EscapeRopeWarpOutEffect_Spin, }; -// .text - u32 FieldEffectStart(u8 id) { u8 *script; @@ -881,7 +880,7 @@ u8 CreateTrainerSprite(u8 trainerSpriteID, s16 x, s16 y, u8 subpriority, u8 *buf LoadCompressedSpriteSheetOverrideBuffer(&gTrainerFrontPicTable[trainerSpriteID], buffer); spriteTemplate.tileTag = gTrainerFrontPicTable[trainerSpriteID].tag; spriteTemplate.paletteTag = gTrainerFrontPicPaletteTable[trainerSpriteID].tag; - spriteTemplate.oam = &gNewGameBirchOamAttributes; + spriteTemplate.oam = &sOam_64x64; spriteTemplate.anims = gDummySpriteAnimTable; spriteTemplate.images = NULL; spriteTemplate.affineAnims = gDummySpriteAffineAnimTable; @@ -897,8 +896,8 @@ void LoadTrainerGfx_TrainerCard(u8 gender, u16 palOffset, u8 *dest) u8 AddNewGameBirchObject(s16 x, s16 y, u8 subpriority) { - LoadSpritePalette(&gNewGameBirchObjectPaletteInfo); - return CreateSprite(&gNewGameBirchObjectTemplate, x, y, subpriority); + LoadSpritePalette(&sSpritePalette_NewGameBirch); + return CreateSprite(&sSpriteTemplate_NewGameBirch, x, y, subpriority); } u8 CreateMonSprite_PicBox(u16 species, s16 x, s16 y, u8 subpriority) @@ -911,10 +910,10 @@ u8 CreateMonSprite_PicBox(u16 species, s16 x, s16 y, u8 subpriority) return spriteId; } -u8 CreateMonSprite_FieldMove(u16 species, u32 d, u32 g, s16 x, s16 y, u8 subpriority) +u8 CreateMonSprite_FieldMove(u16 species, u32 otId, u32 personality, s16 x, s16 y, u8 subpriority) { - const struct CompressedSpritePalette *spritePalette = GetMonSpritePalStructFromOtIdPersonality(species, d, g); - u16 spriteId = CreateMonPicSprite_HandleDeoxys(species, d, g, 1, x, y, 0, spritePalette->tag); + const struct CompressedSpritePalette *spritePalette = GetMonSpritePalStructFromOtIdPersonality(species, otId, personality); + u16 spriteId = CreateMonPicSprite_HandleDeoxys(species, otId, personality, 1, x, y, 0, spritePalette->tag); PreservePaletteInWeather(IndexOfSpritePaletteTag(spritePalette->tag) + 0x10); if (spriteId == 0xFFFF) return MAX_SPRITES; @@ -974,6 +973,28 @@ void MultiplyPaletteRGBComponents(u16 i, u8 r, u8 g, u8 b) gPlttBufferFaded[i] = outPal; } +// Task data for Task_PokecenterHeal and Task_HallOfFameRecord +#define tState data[0] +#define tNumMons data[1] +#define tFirstBallX data[2] +#define tFirstBallY data[3] +#define tMonitorX data[4] +#define tMonitorY data[5] +#define tBallSpriteId data[6] +#define tMonitorSpriteId data[7] +#define tStartHofFlash data[15] + +// Sprite data for SpriteCB_PokeballGlowEffect +#define sState data[0] +#define sTimer data[1] +#define sCounter data[2] +#define sPlayHealSe data[5] +#define sNumMons data[6] +#define sSpriteId data[7] + +// Sprite data for SpriteCB_PokeballGlow +#define sEffectSpriteId data[0] + bool8 FldEff_PokecenterHeal(void) { u8 nPokemon; @@ -981,11 +1002,11 @@ bool8 FldEff_PokecenterHeal(void) nPokemon = CalculatePlayerPartyCount(); task = &gTasks[CreateTask(Task_PokecenterHeal, 0xff)]; - task->data[1] = nPokemon; - task->data[2] = 0x5d; - task->data[3] = 0x24; - task->data[4] = 0x7c; - task->data[5] = 0x18; + task->tNumMons = nPokemon; + task->tFirstBallX = 93; + task->tFirstBallY = 36; + task->tMonitorX = 124; + task->tMonitorY = 24; return FALSE; } @@ -993,38 +1014,38 @@ static void Task_PokecenterHeal(u8 taskId) { struct Task *task; task = &gTasks[taskId]; - gUnknown_0855C364[task->data[0]](task); + sPokecenterHealEffectFuncs[task->tState](task); } -static void PokecenterHealEffect_0(struct Task *task) +static void PokecenterHealEffect_Init(struct Task *task) { - task->data[0]++; - task->data[6] = CreatePokeballGlowSprite(task->data[1], task->data[2], task->data[3], 1); - task->data[7] = PokecenterHealEffectHelper(task->data[4], task->data[5]); + task->tState++; + task->tBallSpriteId = CreateGlowingPokeballsEffect(task->tNumMons, task->tFirstBallX, task->tFirstBallY, TRUE); + task->tMonitorSpriteId = CreatePokecenterMonitorSprite(task->tMonitorX, task->tMonitorY); } -static void PokecenterHealEffect_1(struct Task *task) +static void PokecenterHealEffect_WaitForBallPlacement(struct Task *task) { - if (gSprites[task->data[6]].data[0] > 1) + if (gSprites[task->tBallSpriteId].sState > 1) { - gSprites[task->data[7]].data[0]++; - task->data[0]++; + gSprites[task->tMonitorSpriteId].sState++; + task->tState++; } } -static void PokecenterHealEffect_2(struct Task *task) +static void PokecenterHealEffect_WaitForBallFlashing(struct Task *task) { - if (gSprites[task->data[6]].data[0] > 4) + if (gSprites[task->tBallSpriteId].sState > 4) { - task->data[0]++; + task->tState++; } } -static void PokecenterHealEffect_3(struct Task *task) +static void PokecenterHealEffect_WaitForSoundAndEnd(struct Task *task) { - if (gSprites[task->data[6]].data[0] > 6) + if (gSprites[task->tBallSpriteId].sState > 6) { - DestroySprite(&gSprites[task->data[6]]); + DestroySprite(&gSprites[task->tBallSpriteId]); FieldEffectActiveListRemove(FLDEFF_POKECENTER_HEAL); DestroyTask(FindTaskIdByFunc(Task_PokecenterHeal)); } @@ -1037,9 +1058,9 @@ bool8 FldEff_HallOfFameRecord(void) nPokemon = CalculatePlayerPartyCount(); task = &gTasks[CreateTask(Task_HallOfFameRecord, 0xff)]; - task->data[1] = nPokemon; - task->data[2] = 0x75; - task->data[3] = 0x34; + task->tNumMons = nPokemon; + task->tFirstBallX = 117; + task->tFirstBallY = 52; return FALSE; } @@ -1047,51 +1068,50 @@ static void Task_HallOfFameRecord(u8 taskId) { struct Task *task; task = &gTasks[taskId]; - gUnknown_0855C374[task->data[0]](task); + sHallOfFameRecordEffectFuncs[task->tState](task); } -static void HallOfFameRecordEffect_0(struct Task *task) +static void HallOfFameRecordEffect_Init(struct Task *task) { u8 taskId; - task->data[0]++; - task->data[6] = CreatePokeballGlowSprite(task->data[1], task->data[2], task->data[3], 0); + task->tState++; + task->tBallSpriteId = CreateGlowingPokeballsEffect(task->tNumMons, task->tFirstBallX, task->tFirstBallY, FALSE); taskId = FindTaskIdByFunc(Task_HallOfFameRecord); - HallOfFameRecordEffectHelper(taskId, 0x78, 0x18, 0); - HallOfFameRecordEffectHelper(taskId, 0x28, 0x08, 1); - HallOfFameRecordEffectHelper(taskId, 0x48, 0x08, 1); - HallOfFameRecordEffectHelper(taskId, 0xa8, 0x08, 1); - HallOfFameRecordEffectHelper(taskId, 0xc8, 0x08, 1); + CreateHofMonitorSprite(taskId, 120, 24, FALSE); + CreateHofMonitorSprite(taskId, 40, 8, TRUE); + CreateHofMonitorSprite(taskId, 72, 8, TRUE); + CreateHofMonitorSprite(taskId, 168, 8, TRUE); + CreateHofMonitorSprite(taskId, 200, 8, TRUE); } -static void HallOfFameRecordEffect_1(struct Task *task) +static void HallOfFameRecordEffect_WaitForBallPlacement(struct Task *task) { - if (gSprites[task->data[6]].data[0] > 1) + if (gSprites[task->tBallSpriteId].sState > 1) { - task->data[15]++; // was this ever initialized? is this ever used? - task->data[0]++; + task->tStartHofFlash++; + task->tState++; } } -static void HallOfFameRecordEffect_2(struct Task *task) +static void HallOfFameRecordEffect_WaitForBallFlashing(struct Task *task) { - if (gSprites[task->data[6]].data[0] > 4) + if (gSprites[task->tBallSpriteId].sState > 4) { - task->data[0]++; + task->tState++; } } -static void HallOfFameRecordEffect_3(struct Task *task) +static void HallOfFameRecordEffect_WaitForSoundAndEnd(struct Task *task) { - if (gSprites[task->data[6]].data[0] > 6) + if (gSprites[task->tBallSpriteId].sState > 6) { - DestroySprite(&gSprites[task->data[6]]); + DestroySprite(&gSprites[task->tBallSpriteId]); FieldEffectActiveListRemove(FLDEFF_HALL_OF_FAME_RECORD); DestroyTask(FindTaskIdByFunc(Task_HallOfFameRecord)); } } - -static u8 CreatePokeballGlowSprite(s16 data6, s16 x, s16 y, u16 data5) +static u8 CreateGlowingPokeballsEffect(s16 numMons, s16 x, s16 y, bool16 playHealSe) { u8 spriteId; struct Sprite *sprite; @@ -1099,150 +1119,150 @@ static u8 CreatePokeballGlowSprite(s16 data6, s16 x, s16 y, u16 data5) sprite = &gSprites[spriteId]; sprite->pos2.x = x; sprite->pos2.y = y; - sprite->data[5] = data5; - sprite->data[6] = data6; - sprite->data[7] = spriteId; + sprite->sPlayHealSe = playHealSe; + sprite->sNumMons = numMons; + sprite->sSpriteId = spriteId; return spriteId; } static void SpriteCB_PokeballGlowEffect(struct Sprite *sprite) { - gUnknown_0855C384[sprite->data[0]](sprite); + sPokeballGlowEffectFuncs[sprite->sState](sprite); } -static void PokeballGlowEffect_0(struct Sprite *sprite) +static void PokeballGlowEffect_PlaceBalls(struct Sprite *sprite) { - u8 endSpriteId; - if (sprite->data[1] == 0 || (--sprite->data[1]) == 0) - { - sprite->data[1] = 25; - endSpriteId = CreateSpriteAtEnd(&gSpriteTemplate_855C304, gUnknown_0855C3A4[sprite->data[2]].x + sprite->pos2.x, gUnknown_0855C3A4[sprite->data[2]].y + sprite->pos2.y, 0); - gSprites[endSpriteId].oam.priority = 2; - gSprites[endSpriteId].data[0] = sprite->data[7]; - sprite->data[2]++; - sprite->data[6]--; + u8 spriteId; + if (sprite->sTimer == 0 || (--sprite->sTimer) == 0) + { + sprite->sTimer = 25; + spriteId = CreateSpriteAtEnd(&sSpriteTemplate_PokeballGlow, sPokeballCoordOffsets[sprite->sCounter].x + sprite->pos2.x, sPokeballCoordOffsets[sprite->sCounter].y + sprite->pos2.y, 0); + gSprites[spriteId].oam.priority = 2; + gSprites[spriteId].sEffectSpriteId = sprite->sSpriteId; + sprite->sCounter++; + sprite->sNumMons--; PlaySE(SE_BOWA); } - if (sprite->data[6] == 0) + if (sprite->sNumMons == 0) { - sprite->data[1] = 32; - sprite->data[0]++; + sprite->sTimer = 32; + sprite->sState++; } } -static void PokeballGlowEffect_1(struct Sprite *sprite) +static void PokeballGlowEffect_TryPlaySe(struct Sprite *sprite) { - if ((--sprite->data[1]) == 0) + if ((--sprite->sTimer) == 0) { - sprite->data[0]++; - sprite->data[1] = 8; - sprite->data[2] = 0; + sprite->sState++; + sprite->sTimer = 8; + sprite->sCounter = 0; sprite->data[3] = 0; - if (sprite->data[5]) + if (sprite->sPlayHealSe) { PlayFanfare(MUS_ME_ASA); } } } -static void PokeballGlowEffect_2(struct Sprite *sprite) +static void PokeballGlowEffect_Flash1(struct Sprite *sprite) { u8 phase; - if ((--sprite->data[1]) == 0) + if ((--sprite->sTimer) == 0) { - sprite->data[1] = 8; - sprite->data[2]++; - sprite->data[2] &= 3; - if (sprite->data[2] == 0) - { + sprite->sTimer = 8; + sprite->sCounter++; + sprite->sCounter &= 3; + + if (sprite->sCounter == 0) sprite->data[3]++; - } } - phase = (sprite->data[2] + 3) & 3; - MultiplyInvertedPaletteRGBComponents((IndexOfSpritePaletteTag(0x1007) << 4) + 0x108, gUnknown_0855C3BC[phase], gUnknown_0855C3C0[phase], gUnknown_0855C3C4[phase]); - phase = (sprite->data[2] + 2) & 3; - MultiplyInvertedPaletteRGBComponents((IndexOfSpritePaletteTag(0x1007) << 4) + 0x106, gUnknown_0855C3BC[phase], gUnknown_0855C3C0[phase], gUnknown_0855C3C4[phase]); - phase = (sprite->data[2] + 1) & 3; - MultiplyInvertedPaletteRGBComponents((IndexOfSpritePaletteTag(0x1007) << 4) + 0x102, gUnknown_0855C3BC[phase], gUnknown_0855C3C0[phase], gUnknown_0855C3C4[phase]); - phase = sprite->data[2]; - MultiplyInvertedPaletteRGBComponents((IndexOfSpritePaletteTag(0x1007) << 4) + 0x105, gUnknown_0855C3BC[phase], gUnknown_0855C3C0[phase], gUnknown_0855C3C4[phase]); - MultiplyInvertedPaletteRGBComponents((IndexOfSpritePaletteTag(0x1007) << 4) + 0x103, gUnknown_0855C3BC[phase], gUnknown_0855C3C0[phase], gUnknown_0855C3C4[phase]); + phase = (sprite->sCounter + 3) & 3; + MultiplyInvertedPaletteRGBComponents((IndexOfSpritePaletteTag(FLDEFF_PAL_TAG_POKEBALL_GLOW) << 4) + 0x108, sPokeballGlowReds[phase], sPokeballGlowGreens[phase], sPokeballGlowBlues[phase]); + phase = (sprite->sCounter + 2) & 3; + MultiplyInvertedPaletteRGBComponents((IndexOfSpritePaletteTag(FLDEFF_PAL_TAG_POKEBALL_GLOW) << 4) + 0x106, sPokeballGlowReds[phase], sPokeballGlowGreens[phase], sPokeballGlowBlues[phase]); + phase = (sprite->sCounter + 1) & 3; + MultiplyInvertedPaletteRGBComponents((IndexOfSpritePaletteTag(FLDEFF_PAL_TAG_POKEBALL_GLOW) << 4) + 0x102, sPokeballGlowReds[phase], sPokeballGlowGreens[phase], sPokeballGlowBlues[phase]); + phase = sprite->sCounter; + MultiplyInvertedPaletteRGBComponents((IndexOfSpritePaletteTag(FLDEFF_PAL_TAG_POKEBALL_GLOW) << 4) + 0x105, sPokeballGlowReds[phase], sPokeballGlowGreens[phase], sPokeballGlowBlues[phase]); + MultiplyInvertedPaletteRGBComponents((IndexOfSpritePaletteTag(FLDEFF_PAL_TAG_POKEBALL_GLOW) << 4) + 0x103, sPokeballGlowReds[phase], sPokeballGlowGreens[phase], sPokeballGlowBlues[phase]); if (sprite->data[3] > 2) { - sprite->data[0]++; - sprite->data[1] = 8; - sprite->data[2] = 0; + sprite->sState++; + sprite->sTimer = 8; + sprite->sCounter = 0; } } -static void PokeballGlowEffect_3(struct Sprite *sprite) +static void PokeballGlowEffect_Flash2(struct Sprite *sprite) { u8 phase; - if ((--sprite->data[1]) == 0) + if ((--sprite->sTimer) == 0) { - sprite->data[1] = 8; - sprite->data[2]++; - sprite->data[2] &= 3; - if (sprite->data[2] == 3) + sprite->sTimer = 8; + sprite->sCounter++; + sprite->sCounter &= 3; + if (sprite->sCounter == 3) { - sprite->data[0]++; - sprite->data[1] = 30; + sprite->sState++; + sprite->sTimer = 30; } } - phase = sprite->data[2]; - MultiplyInvertedPaletteRGBComponents((IndexOfSpritePaletteTag(0x1007) << 4) + 0x108, gUnknown_0855C3BC[phase], gUnknown_0855C3C0[phase], gUnknown_0855C3C4[phase]); - MultiplyInvertedPaletteRGBComponents((IndexOfSpritePaletteTag(0x1007) << 4) + 0x106, gUnknown_0855C3BC[phase], gUnknown_0855C3C0[phase], gUnknown_0855C3C4[phase]); - MultiplyInvertedPaletteRGBComponents((IndexOfSpritePaletteTag(0x1007) << 4) + 0x102, gUnknown_0855C3BC[phase], gUnknown_0855C3C0[phase], gUnknown_0855C3C4[phase]); - MultiplyInvertedPaletteRGBComponents((IndexOfSpritePaletteTag(0x1007) << 4) + 0x105, gUnknown_0855C3BC[phase], gUnknown_0855C3C0[phase], gUnknown_0855C3C4[phase]); - MultiplyInvertedPaletteRGBComponents((IndexOfSpritePaletteTag(0x1007) << 4) + 0x103, gUnknown_0855C3BC[phase], gUnknown_0855C3C0[phase], gUnknown_0855C3C4[phase]); + phase = sprite->sCounter; + MultiplyInvertedPaletteRGBComponents((IndexOfSpritePaletteTag(FLDEFF_PAL_TAG_POKEBALL_GLOW) << 4) + 0x108, sPokeballGlowReds[phase], sPokeballGlowGreens[phase], sPokeballGlowBlues[phase]); + MultiplyInvertedPaletteRGBComponents((IndexOfSpritePaletteTag(FLDEFF_PAL_TAG_POKEBALL_GLOW) << 4) + 0x106, sPokeballGlowReds[phase], sPokeballGlowGreens[phase], sPokeballGlowBlues[phase]); + MultiplyInvertedPaletteRGBComponents((IndexOfSpritePaletteTag(FLDEFF_PAL_TAG_POKEBALL_GLOW) << 4) + 0x102, sPokeballGlowReds[phase], sPokeballGlowGreens[phase], sPokeballGlowBlues[phase]); + MultiplyInvertedPaletteRGBComponents((IndexOfSpritePaletteTag(FLDEFF_PAL_TAG_POKEBALL_GLOW) << 4) + 0x105, sPokeballGlowReds[phase], sPokeballGlowGreens[phase], sPokeballGlowBlues[phase]); + MultiplyInvertedPaletteRGBComponents((IndexOfSpritePaletteTag(FLDEFF_PAL_TAG_POKEBALL_GLOW) << 4) + 0x103, sPokeballGlowReds[phase], sPokeballGlowGreens[phase], sPokeballGlowBlues[phase]); } -static void PokeballGlowEffect_4(struct Sprite *sprite) +static void PokeballGlowEffect_WaitAfterFlash(struct Sprite *sprite) { - if ((--sprite->data[1]) == 0) + if ((--sprite->sTimer) == 0) { - sprite->data[0]++; + sprite->sState++; } } -static void PokeballGlowEffect_5(struct Sprite *sprite) +static void PokeballGlowEffect_Dummy(struct Sprite *sprite) { - sprite->data[0]++; + sprite->sState++; } -static void PokeballGlowEffect_6(struct Sprite *sprite) +static void PokeballGlowEffect_WaitForSound(struct Sprite *sprite) { - if (sprite->data[5] == 0 || IsFanfareTaskInactive()) + if (sprite->sPlayHealSe == FALSE || IsFanfareTaskInactive()) { - sprite->data[0]++; + sprite->sState++; } } -static void PokeballGlowEffect_7(struct Sprite *sprite) +static void PokeballGlowEffect_Idle(struct Sprite *sprite) { + // Idle until destroyed } -void SpriteCB_PokeballGlow(struct Sprite *sprite) +static void SpriteCB_PokeballGlow(struct Sprite *sprite) { - if (gSprites[sprite->data[0]].data[0] > 4) + if (gSprites[sprite->sEffectSpriteId].sState > 4) { FieldEffectFreeGraphicsResources(sprite); } } -static u8 PokecenterHealEffectHelper(s16 x, s16 y) +static u8 CreatePokecenterMonitorSprite(s16 x, s16 y) { - u8 spriteIdAtEnd; + u8 spriteId; struct Sprite *sprite; - spriteIdAtEnd = CreateSpriteAtEnd(&gSpriteTemplate_855C31C, x, y, 0); - sprite = &gSprites[spriteIdAtEnd]; + spriteId = CreateSpriteAtEnd(&sSpriteTemplate_PokecenterMonitor, x, y, 0); + sprite = &gSprites[spriteId]; sprite->oam.priority = 2; sprite->invisible = TRUE; - SetSubspriteTables(sprite, &gUnknown_0855C2AC); - return spriteIdAtEnd; + SetSubspriteTables(sprite, &sSubspriteTable_PokecenterMonitor); + return spriteId; } -void SpriteCB_PokecenterMonitor(struct Sprite *sprite) +static void SpriteCB_PokecenterMonitor(struct Sprite *sprite) { if (sprite->data[0] != 0) { @@ -1256,24 +1276,24 @@ void SpriteCB_PokecenterMonitor(struct Sprite *sprite) } } -static void HallOfFameRecordEffectHelper(s16 a0, s16 a1, s16 a2, u8 a3) +static void CreateHofMonitorSprite(s16 taskId, s16 x, s16 y, bool8 isSmallMonitor) { - u8 spriteIdAtEnd; - if (!a3) + u8 spriteId; + if (!isSmallMonitor) { - spriteIdAtEnd = CreateSpriteAtEnd(&gSpriteTemplate_855C334, a1, a2, 0); - SetSubspriteTables(&gSprites[spriteIdAtEnd], &gUnknown_0855C2C4); + spriteId = CreateSpriteAtEnd(&sSpriteTemplate_HofMonitorBig, x, y, 0); + SetSubspriteTables(&gSprites[spriteId], &sSubspriteTable_HofMonitorBig); } else { - spriteIdAtEnd = CreateSpriteAtEnd(&gSpriteTemplate_855C34C, a1, a2, 0); + spriteId = CreateSpriteAtEnd(&sSpriteTemplate_HofMonitorSmall, x, y, 0); } - gSprites[spriteIdAtEnd].invisible = TRUE; - gSprites[spriteIdAtEnd].data[0] = a0; + gSprites[spriteId].invisible = TRUE; + gSprites[spriteId].data[0] = taskId; } -void SpriteCB_HallOfFameMonitor(struct Sprite *sprite) +static void SpriteCB_HallOfFameMonitor(struct Sprite *sprite) { - if (gTasks[sprite->data[0]].data[15]) + if (gTasks[sprite->data[0]].tStartHofFlash) { if (sprite->data[1] == 0 || (--sprite->data[1]) == 0) { @@ -1288,37 +1308,51 @@ void SpriteCB_HallOfFameMonitor(struct Sprite *sprite) } } +#undef tState +#undef tNumMons +#undef tFirstBallX +#undef tFirstBallY +#undef tMonitorX +#undef tMonitorY +#undef tBallSpriteId +#undef tMonitorSpriteId +#undef tStartHofFlash +#undef sState +#undef sTimer +#undef sCounter +#undef sPlayHealSe +#undef sNumMons +#undef sSpriteId +#undef sEffectSpriteId void ReturnToFieldFromFlyMapSelect(void) { SetMainCallback2(CB2_ReturnToField); - gFieldCallback = FieldCallback_Fly; + gFieldCallback = FieldCallback_UseFly; } -static void FieldCallback_Fly(void) +static void FieldCallback_UseFly(void) { FadeInFromBlack(); - CreateTask(task00_8084310, 0); + CreateTask(Task_UseFly, 0); ScriptContext2_Enable(); FreezeObjectEvents(); gFieldCallback = NULL; } -static void task00_8084310(u8 taskId) +static void Task_UseFly(u8 taskId) { struct Task *task; task = &gTasks[taskId]; if (!task->data[0]) { if (!IsWeatherNotFadingIn()) - { return; - } + gFieldEffectArguments[0] = GetCursorSelectionMonId(); - if ((int)gFieldEffectArguments[0] > 5) - { + if ((int)gFieldEffectArguments[0] > PARTY_SIZE - 1) gFieldEffectArguments[0] = 0; - } + FieldEffectStart(FLDEFF_USE_FLY); task->data[0]++; } @@ -1327,18 +1361,18 @@ static void task00_8084310(u8 taskId) Overworld_ResetStateAfterFly(); WarpIntoMap(); SetMainCallback2(CB2_LoadMap); - gFieldCallback = mapldr_08084390; + gFieldCallback = FieldCallback_FlyIntoMap; DestroyTask(taskId); } } -static void mapldr_08084390(void) +static void FieldCallback_FlyIntoMap(void) { Overworld_PlaySpecialMapMusic(); FadeInFromBlack(); - CreateTask(c3_080843F8, 0); + CreateTask(Task_FlyIntoMap, 0); gObjectEvents[gPlayerAvatar.objectEventId].invisible = TRUE; - if (gPlayerAvatar.flags & 0x08) + if (gPlayerAvatar.flags & PLAYER_AVATAR_FLAG_SURFING) { ObjectEventTurn(&gObjectEvents[gPlayerAvatar.objectEventId], DIR_WEST); } @@ -1347,7 +1381,7 @@ static void mapldr_08084390(void) gFieldCallback = NULL; } -static void c3_080843F8(u8 taskId) +static void Task_FlyIntoMap(u8 taskId) { struct Task *task; task = &gTasks[taskId]; @@ -1368,6 +1402,15 @@ static void c3_080843F8(u8 taskId) } } +#define tState data[0] +#define tFallOffset data[1] +#define tTotalFall data[2] +#define tSetTrigger data[3] +#define tSubsprMode data[4] + +#define tVertShake data[1] // re-used +#define tNumShakes data[2] + void FieldCB_FallWarpExit(void) { Overworld_PlaySpecialMapMusic(); @@ -1382,10 +1425,10 @@ static void Task_FallWarpFieldEffect(u8 taskId) { struct Task *task; task = &gTasks[taskId]; - while (sFallWarpFieldEffectFuncs[task->data[0]](task)); // return code signifies whether to continue blocking here + while (sFallWarpFieldEffectFuncs[task->tState](task)); } -static bool8 FallWarpEffect_1(struct Task *task) +static bool8 FallWarpEffect_Init(struct Task *task) { struct ObjectEvent *playerObject; struct Sprite *playerSprite; @@ -1395,59 +1438,57 @@ static bool8 FallWarpEffect_1(struct Task *task) gObjectEvents[gPlayerAvatar.objectEventId].invisible = TRUE; gPlayerAvatar.preventStep = TRUE; ObjectEventSetHeldMovement(playerObject, GetFaceDirectionMovementAction(GetPlayerFacingDirection())); - task->data[4] = playerSprite->subspriteMode; + task->tSubsprMode = playerSprite->subspriteMode; playerObject->fixedPriority = 1; playerSprite->oam.priority = 1; playerSprite->subspriteMode = SUBSPRITES_IGNORE_PRIORITY; - task->data[0]++; + task->tState++; return TRUE; } -static bool8 FallWarpEffect_2(struct Task *task) +static bool8 FallWarpEffect_WaitWeather(struct Task *task) { if (IsWeatherNotFadingIn()) - { - task->data[0]++; - } + task->tState++; + return FALSE; } -static bool8 FallWarpEffect_3(struct Task *task) +static bool8 FallWarpEffect_StartFall(struct Task *task) { struct Sprite *sprite; s16 centerToCornerVecY; sprite = &gSprites[gPlayerAvatar.spriteId]; centerToCornerVecY = -(sprite->centerToCornerVecY << 1); sprite->pos2.y = -(sprite->pos1.y + sprite->centerToCornerVecY + gSpriteCoordOffsetY + centerToCornerVecY); - task->data[1] = 1; - task->data[2] = 0; + task->tFallOffset = 1; + task->tTotalFall = 0; gObjectEvents[gPlayerAvatar.objectEventId].invisible = FALSE; PlaySE(SE_RU_HYUU); - task->data[0]++; + task->tState++; return FALSE; } -static bool8 FallWarpEffect_4(struct Task *task) +static bool8 FallWarpEffect_Fall(struct Task *task) { struct ObjectEvent *objectEvent; struct Sprite *sprite; objectEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; sprite = &gSprites[gPlayerAvatar.spriteId]; - sprite->pos2.y += task->data[1]; - if (task->data[1] < 8) + sprite->pos2.y += task->tFallOffset; + if (task->tFallOffset < 8) { - task->data[2] += task->data[1]; - if (task->data[2] & 0xf) - { - task->data[1] <<= 1; - } + task->tTotalFall += task->tFallOffset; + + if (task->tTotalFall & 0xf) + task->tFallOffset <<= 1; } - if (task->data[3] == 0 && sprite->pos2.y >= -16) + if (task->tSetTrigger == FALSE && sprite->pos2.y >= -16) { - task->data[3]++; + task->tSetTrigger++; objectEvent->fixedPriority = 0; - sprite->subspriteMode = task->data[4]; + sprite->subspriteMode = task->tSubsprMode; objectEvent->triggerGroundEffectsOnMove = 1; } if (sprite->pos2.y >= 0) @@ -1456,37 +1497,36 @@ static bool8 FallWarpEffect_4(struct Task *task) objectEvent->triggerGroundEffectsOnStop = 1; objectEvent->landingJump = 1; sprite->pos2.y = 0; - task->data[0]++; + task->tState++; } return FALSE; } -static bool8 FallWarpEffect_5(struct Task *task) +static bool8 FallWarpEffect_Land(struct Task *task) { - task->data[0]++; - task->data[1] = 4; - task->data[2] = 0; + task->tState++; + task->tVertShake = 4; + task->tNumShakes = 0; SetCameraPanningCallback(NULL); return TRUE; } -static bool8 FallWarpEffect_6(struct Task *task) +static bool8 FallWarpEffect_CameraShake(struct Task *task) { - SetCameraPanning(0, task->data[1]); - task->data[1] = -task->data[1]; - task->data[2]++; - if ((task->data[2] & 3) == 0) - { - task->data[1] >>= 1; - } - if (task->data[1] == 0) - { - task->data[0]++; - } + SetCameraPanning(0, task->tVertShake); + task->tVertShake = -task->tVertShake; + task->tNumShakes++; + + if ((task->tNumShakes & 3) == 0) + task->tVertShake >>= 1; + + if (task->tVertShake == 0) + task->tState++; + return FALSE; } -static bool8 FallWarpEffect_7(struct Task *task) +static bool8 FallWarpEffect_End(struct Task *task) { gPlayerAvatar.preventStep = FALSE; ScriptContext2_Disable(); @@ -1497,89 +1537,100 @@ static bool8 FallWarpEffect_7(struct Task *task) return FALSE; } +#undef tState +#undef tFallOffset +#undef tTotalFall +#undef tSetTrigger +#undef tSubsprMode +#undef tVertShake +#undef tNumShakes + +#define tState data[0] +#define tGoingUp data[1] + void StartEscalatorWarp(u8 metatileBehavior, u8 priority) { u8 taskId; - taskId = CreateTask(Task_EscalatorWarpFieldEffect, priority); - gTasks[taskId].data[1] = 0; + taskId = CreateTask(Task_EscalatorWarpOut, priority); + gTasks[taskId].tGoingUp = FALSE; if (metatileBehavior == MB_UP_ESCALATOR) { - gTasks[taskId].data[1] = 1; + gTasks[taskId].tGoingUp = TRUE; } } -static void Task_EscalatorWarpFieldEffect(u8 taskId) +static void Task_EscalatorWarpOut(u8 taskId) { struct Task *task; task = &gTasks[taskId]; - while (sEscalatorWarpFieldEffectFuncs[task->data[0]](task)); + while (sEscalatorWarpOutFieldEffectFuncs[task->tState](task)); } -static bool8 EscalatorWarpEffect_1(struct Task *task) +static bool8 EscalatorWarpOut_Init(struct Task *task) { FreezeObjectEvents(); CameraObjectReset2(); - sub_80E1558(task->data[1]); - task->data[0]++; + StartEscalator(task->tGoingUp); + task->tState++; return FALSE; } -static bool8 EscalatorWarpEffect_2(struct Task *task) +static bool8 EscalatorWarpOut_WaitForPlayer(struct Task *task) { struct ObjectEvent *objectEvent; objectEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; if (!ObjectEventIsMovementOverridden(objectEvent) || ObjectEventClearHeldMovementIfFinished(objectEvent)) { ObjectEventSetHeldMovement(objectEvent, GetFaceDirectionMovementAction(GetPlayerFacingDirection())); - task->data[0]++; + task->tState++; task->data[2] = 0; task->data[3] = 0; - if ((u8)task->data[1] == 0) + if ((u8)task->tGoingUp == FALSE) { - task->data[0] = 4; + task->tState = 4; // jump to EscalatorWarpOut_Down_Ride } PlaySE(SE_ESUKA); } return FALSE; } -static bool8 EscalatorWarpEffect_3(struct Task *task) +static bool8 EscalatorWarpOut_Up_Ride(struct Task *task) { - sub_80B6FB8(task); + RideUpEscalatorOut(task); if (task->data[2] > 3) { - sub_80B7050(); - task->data[0]++; + FadeOutAtEndOfEscalator(); + task->tState++; } return FALSE; } -static bool8 EscalatorWarpEffect_4(struct Task *task) +static bool8 EscalatorWarpOut_Up_End(struct Task *task) { - sub_80B6FB8(task); - sub_80B7060(); + RideUpEscalatorOut(task); + WarpAtEndOfEscalator(); return FALSE; } -static bool8 EscalatorWarpEffect_5(struct Task *task) +static bool8 EscalatorWarpOut_Down_Ride(struct Task *task) { - sub_80B7004(task); + RideDownEscalatorOut(task); if (task->data[2] > 3) { - sub_80B7050(); - task->data[0]++; + FadeOutAtEndOfEscalator(); + task->tState++; } return FALSE; } -static bool8 EscalatorWarpEffect_6(struct Task *task) +static bool8 EscalatorWarpOut_Down_End(struct Task *task) { - sub_80B7004(task); - sub_80B7060(); + RideDownEscalatorOut(task); + WarpAtEndOfEscalator(); return FALSE; } -static void sub_80B6FB8(struct Task *task) +static void RideUpEscalatorOut(struct Task *task) { struct Sprite *sprite; sprite = &gSprites[gPlayerAvatar.spriteId]; @@ -1592,7 +1643,7 @@ static void sub_80B6FB8(struct Task *task) } } -static void sub_80B7004(struct Task *task) +static void RideDownEscalatorOut(struct Task *task) { struct Sprite *sprite; sprite = &gSprites[gPlayerAvatar.spriteId]; @@ -1605,41 +1656,46 @@ static void sub_80B7004(struct Task *task) } } -static void sub_80B7050(void) +static void FadeOutAtEndOfEscalator(void) { TryFadeOutOldMapMusic(); WarpFadeOutScreen(); } -static void sub_80B7060(void) +static void WarpAtEndOfEscalator(void) { if (!gPaletteFade.active && BGMusicStopped() == TRUE) { - sub_80E1570(); + StopEscalator(); WarpIntoMap(); - gFieldCallback = sub_80B70B4; + gFieldCallback = FieldCallback_EscalatorWarpIn; SetMainCallback2(CB2_LoadMap); - DestroyTask(FindTaskIdByFunc(Task_EscalatorWarpFieldEffect)); + DestroyTask(FindTaskIdByFunc(Task_EscalatorWarpOut)); } } -static void sub_80B70B4(void) +#undef tState +#undef tGoingUp + +static void FieldCallback_EscalatorWarpIn(void) { Overworld_PlaySpecialMapMusic(); WarpFadeInScreen(); ScriptContext2_Enable(); - CreateTask(sub_80B70DC, 0); + CreateTask(Task_EscalatorWarpIn, 0); gFieldCallback = NULL; } -static void sub_80B70DC(u8 taskId) +#define tState data[0] + +static void Task_EscalatorWarpIn(u8 taskId) { struct Task *task; task = &gTasks[taskId]; - while (gUnknown_0855C3FC[task->data[0]](task)); + while (sEscalatorWarpInFieldEffectFuncs[task->tState](task)); } -static bool8 sub_80B7114(struct Task *task) +static bool8 EscalatorWarpIn_Init(struct Task *task) { struct ObjectEvent *objectEvent; s16 x; @@ -1650,31 +1706,35 @@ static bool8 sub_80B7114(struct Task *task) ObjectEventSetHeldMovement(objectEvent, GetFaceDirectionMovementAction(DIR_EAST)); PlayerGetDestCoords(&x, &y); behavior = MapGridGetMetatileBehaviorAt(x, y); - task->data[0]++; + task->tState++; task->data[1] = 16; - if (behavior == 0x6b) + + if (behavior == MB_DOWN_ESCALATOR) { - behavior = 1; - task->data[0] = 3; - } else + // If dest is down escalator tile, player is riding up + behavior = TRUE; + task->tState = 3; // jump to EscalatorWarpIn_Up_Init + } + else // MB_UP_ESCALATOR { - behavior = 0; + // If dest is up escalator tile, player is riding down + behavior = FALSE; } - sub_80E1558(behavior); + StartEscalator(behavior); return TRUE; } -static bool8 sub_80B7190(struct Task *task) +static bool8 EscalatorWarpIn_Down_Init(struct Task *task) { struct Sprite *sprite; sprite = &gSprites[gPlayerAvatar.spriteId]; sprite->pos2.x = Cos(0x84, task->data[1]); sprite->pos2.y = Sin(0x94, task->data[1]); - task->data[0]++; + task->tState++; return FALSE; } -static bool8 sub_80B71D0(struct Task *task) +static bool8 EscalatorWarpIn_Down_Ride(struct Task *task) { struct Sprite *sprite; sprite = &gSprites[gPlayerAvatar.spriteId]; @@ -1689,22 +1749,22 @@ static bool8 sub_80B71D0(struct Task *task) { sprite->pos2.x = 0; sprite->pos2.y = 0; - task->data[0] = 5; + task->tState = 5; } return FALSE; } -static bool8 sub_80B7230(struct Task *task) +static bool8 EscalatorWarpIn_Up_Init(struct Task *task) { struct Sprite *sprite; sprite = &gSprites[gPlayerAvatar.spriteId]; sprite->pos2.x = Cos(0x7c, task->data[1]); sprite->pos2.y = Sin(0x76, task->data[1]); - task->data[0]++; + task->tState++; return FALSE; } -static bool8 sub_80B7270(struct Task *task) +static bool8 EscalatorWarpIn_Up_Ride(struct Task *task) { struct Sprite *sprite; sprite = &gSprites[gPlayerAvatar.spriteId]; @@ -1719,23 +1779,23 @@ static bool8 sub_80B7270(struct Task *task) { sprite->pos2.x = 0; sprite->pos2.y = 0; - task->data[0]++; + task->tState++; } return FALSE; } -static bool8 sub_80B72D0(struct Task *task) +static bool8 EscalatorWarpIn_WaitForMovement(struct Task *task) { - if (sub_80E1584()) + if (IsEscalatorMoving()) { return FALSE; } - sub_80E1570(); - task->data[0]++; + StopEscalator(); + task->tState++; return TRUE; } -static bool8 sub_80B72F4(struct Task *task) +static bool8 EscalatorWarpIn_End(struct Task *task) { struct ObjectEvent *objectEvent; objectEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; @@ -1744,104 +1804,113 @@ static bool8 sub_80B72F4(struct Task *task) CameraObjectReset1(); ScriptContext2_Disable(); ObjectEventSetHeldMovement(objectEvent, GetWalkNormalMovementAction(DIR_EAST)); - DestroyTask(FindTaskIdByFunc(sub_80B70DC)); + DestroyTask(FindTaskIdByFunc(Task_EscalatorWarpIn)); } return FALSE; } +#undef tState + +#define tState data[0] +#define tMonId data[1] + bool8 FldEff_UseWaterfall(void) { u8 taskId; - taskId = CreateTask(sub_80B7384, 0xff); - gTasks[taskId].data[1] = gFieldEffectArguments[0]; - sub_80B7384(taskId); + taskId = CreateTask(Task_UseWaterfall, 0xff); + gTasks[taskId].tMonId = gFieldEffectArguments[0]; + Task_UseWaterfall(taskId); return FALSE; } -static void sub_80B7384(u8 taskId) +static void Task_UseWaterfall(u8 taskId) { - while (gUnknown_0855C418[gTasks[taskId].data[0]](&gTasks[taskId], &gObjectEvents[gPlayerAvatar.objectEventId])); + while (sWaterfallFieldEffectFuncs[gTasks[taskId].tState](&gTasks[taskId], &gObjectEvents[gPlayerAvatar.objectEventId])); } -static bool8 sub_80B73D0(struct Task *task, struct ObjectEvent *objectEvent) +static bool8 WaterfallFieldEffect_Init(struct Task *task, struct ObjectEvent *objectEvent) { ScriptContext2_Enable(); gPlayerAvatar.preventStep = TRUE; - task->data[0]++; + task->tState++; return FALSE; } -static bool8 waterfall_1_do_anim_probably(struct Task *task, struct ObjectEvent *objectEvent) +static bool8 WaterfallFieldEffect_ShowMon(struct Task *task, struct ObjectEvent *objectEvent) { ScriptContext2_Enable(); if (!ObjectEventIsMovementOverridden(objectEvent)) { ObjectEventClearHeldMovementIfFinished(objectEvent); - gFieldEffectArguments[0] = task->data[1]; + gFieldEffectArguments[0] = task->tMonId; FieldEffectStart(FLDEFF_FIELD_MOVE_SHOW_MON_INIT); - task->data[0]++; + task->tState++; } return FALSE; } -static bool8 waterfall_2_wait_anim_finish_probably(struct Task *task, struct ObjectEvent *objectEvent) +static bool8 WaterfallFieldEffect_WaitForShowMon(struct Task *task, struct ObjectEvent *objectEvent) { if (FieldEffectActiveListContains(FLDEFF_FIELD_MOVE_SHOW_MON)) { return FALSE; } - task->data[0]++; + task->tState++; return TRUE; } -static bool8 sub_80B7450(struct Task *task, struct ObjectEvent *objectEvent) +static bool8 WaterfallFieldEffect_RideUp(struct Task *task, struct ObjectEvent *objectEvent) { ObjectEventSetHeldMovement(objectEvent, GetWalkSlowMovementAction(DIR_NORTH)); - task->data[0]++; + task->tState++; return FALSE; } -static bool8 sub_80B7478(struct Task *task, struct ObjectEvent *objectEvent) +static bool8 WaterfallFieldEffect_ContinueRideOrEnd(struct Task *task, struct ObjectEvent *objectEvent) { if (!ObjectEventClearHeldMovementIfFinished(objectEvent)) - { return FALSE; - } + if (MetatileBehavior_IsWaterfall(objectEvent->currentMetatileBehavior)) { - task->data[0] = 3; + // Still ascending waterfall, back to WaterfallFieldEffect_RideUp + task->tState = 3; return TRUE; } + ScriptContext2_Disable(); gPlayerAvatar.preventStep = FALSE; - DestroyTask(FindTaskIdByFunc(sub_80B7384)); + DestroyTask(FindTaskIdByFunc(Task_UseWaterfall)); FieldEffectActiveListRemove(FLDEFF_USE_WATERFALL); return FALSE; } +#undef tState +#undef tMonId + bool8 FldEff_UseDive(void) { u8 taskId; - taskId = CreateTask(Task_Dive, 0xff); + taskId = CreateTask(Task_UseDive, 0xff); gTasks[taskId].data[15] = gFieldEffectArguments[0]; gTasks[taskId].data[14] = gFieldEffectArguments[1]; - Task_Dive(taskId); + Task_UseDive(taskId); return FALSE; } -void Task_Dive(u8 taskId) +void Task_UseDive(u8 taskId) { - while (gUnknown_0855C42C[gTasks[taskId].data[0]](&gTasks[taskId])); + while (sDiveFieldEffectFuncs[gTasks[taskId].data[0]](&gTasks[taskId])); } -static bool8 dive_1_lock(struct Task *task) +static bool8 DiveFieldEffect_Init(struct Task *task) { gPlayerAvatar.preventStep = TRUE; task->data[0]++; return FALSE; } -static bool8 dive_2_unknown(struct Task *task) +static bool8 DiveFieldEffect_ShowMon(struct Task *task) { ScriptContext2_Enable(); gFieldEffectArguments[0] = task->data[15]; @@ -1850,14 +1919,16 @@ static bool8 dive_2_unknown(struct Task *task) return FALSE; } -static bool8 dive_3_unknown(struct Task *task) +static bool8 DiveFieldEffect_TryWarp(struct Task *task) { struct MapPosition mapPosition; PlayerGetDestCoords(&mapPosition.x, &mapPosition.y); + + // Wait for show mon first if (!FieldEffectActiveListContains(FLDEFF_FIELD_MOVE_SHOW_MON)) { - dive_warp(&mapPosition, gObjectEvents[gPlayerAvatar.objectEventId].currentMetatileBehavior); - DestroyTask(FindTaskIdByFunc(Task_Dive)); + TryDoDiveWarp(&mapPosition, gObjectEvents[gPlayerAvatar.objectEventId].currentMetatileBehavior); + DestroyTask(FindTaskIdByFunc(Task_UseDive)); FieldEffectActiveListRemove(FLDEFF_USE_DIVE); } return FALSE; @@ -1873,7 +1944,7 @@ static void Task_LavaridgeGymB1FWarp(u8 taskId) while (sLavaridgeGymB1FWarpEffectFuncs[gTasks[taskId].data[0]](&gTasks[taskId], &gObjectEvents[gPlayerAvatar.objectEventId], &gSprites[gPlayerAvatar.spriteId])); } -static bool8 LavaridgeGymB1FWarpEffect_1(struct Task *task, struct ObjectEvent *objectEvent, struct Sprite *sprite) +static bool8 LavaridgeGymB1FWarpEffect_Init(struct Task *task, struct ObjectEvent *objectEvent, struct Sprite *sprite) { FreezeObjectEvents(); CameraObjectReset2(); @@ -1885,7 +1956,7 @@ static bool8 LavaridgeGymB1FWarpEffect_1(struct Task *task, struct ObjectEvent * return TRUE; } -static bool8 LavaridgeGymB1FWarpEffect_2(struct Task *task, struct ObjectEvent *objectEvent, struct Sprite *sprite) +static bool8 LavaridgeGymB1FWarpEffect_CameraShake(struct Task *task, struct ObjectEvent *objectEvent, struct Sprite *sprite) { SetCameraPanning(0, task->data[1]); task->data[1] = -task->data[1]; @@ -1898,7 +1969,7 @@ static bool8 LavaridgeGymB1FWarpEffect_2(struct Task *task, struct ObjectEvent * return FALSE; } -static bool8 LavaridgeGymB1FWarpEffect_3(struct Task *task, struct ObjectEvent *objectEvent, struct Sprite *sprite) +static bool8 LavaridgeGymB1FWarpEffect_Launch(struct Task *task, struct ObjectEvent *objectEvent, struct Sprite *sprite) { sprite->pos2.y = 0; task->data[3] = 1; @@ -1906,13 +1977,13 @@ static bool8 LavaridgeGymB1FWarpEffect_3(struct Task *task, struct ObjectEvent * gFieldEffectArguments[1] = objectEvent->currentCoords.y; gFieldEffectArguments[2] = sprite->subpriority - 1; gFieldEffectArguments[3] = sprite->oam.priority; - FieldEffectStart(FLDEFF_LAVARIDGE_GYM_WARP); + FieldEffectStart(FLDEFF_ASH_LAUNCH); PlaySE(SE_W153); task->data[0]++; return TRUE; } -static bool8 LavaridgeGymB1FWarpEffect_4(struct Task *task, struct ObjectEvent *objectEvent, struct Sprite *sprite) +static bool8 LavaridgeGymB1FWarpEffect_Rise(struct Task *task, struct ObjectEvent *objectEvent, struct Sprite *sprite) { s16 centerToCornerVecY; SetCameraPanning(0, task->data[1]); @@ -1955,7 +2026,7 @@ static bool8 LavaridgeGymB1FWarpEffect_4(struct Task *task, struct ObjectEvent * return FALSE; } -static bool8 LavaridgeGymB1FWarpEffect_5(struct Task *task, struct ObjectEvent *objectEvent, struct Sprite *sprite) +static bool8 LavaridgeGymB1FWarpEffect_FadeOut(struct Task *task, struct ObjectEvent *objectEvent, struct Sprite *sprite) { TryFadeOutOldMapMusic(); WarpFadeOutScreen(); @@ -1963,7 +2034,7 @@ static bool8 LavaridgeGymB1FWarpEffect_5(struct Task *task, struct ObjectEvent * return FALSE; } -static bool8 LavaridgeGymB1FWarpEffect_6(struct Task *task, struct ObjectEvent *objectEvent, struct Sprite *sprite) +static bool8 LavaridgeGymB1FWarpEffect_Warp(struct Task *task, struct ObjectEvent *objectEvent, struct Sprite *sprite) { if (!gPaletteFade.active && BGMusicStopped() == TRUE) { @@ -1989,7 +2060,7 @@ static void Task_LavaridgeGymB1FWarpExit(u8 taskId) while (sLavaridgeGymB1FWarpExitEffectFuncs[gTasks[taskId].data[0]](&gTasks[taskId], &gObjectEvents[gPlayerAvatar.objectEventId], &gSprites[gPlayerAvatar.spriteId])); } -static bool8 LavaridgeGymB1FWarpExitEffect_1(struct Task *task, struct ObjectEvent *objectEvent, struct Sprite *sprite) +static bool8 LavaridgeGymB1FWarpExitEffect_Init(struct Task *task, struct ObjectEvent *objectEvent, struct Sprite *sprite) { CameraObjectReset2(); FreezeObjectEvents(); @@ -1999,7 +2070,7 @@ static bool8 LavaridgeGymB1FWarpExitEffect_1(struct Task *task, struct ObjectEve return FALSE; } -static bool8 LavaridgeGymB1FWarpExitEffect_2(struct Task *task, struct ObjectEvent *objectEvent, struct Sprite *sprite) +static bool8 LavaridgeGymB1FWarpExitEffect_StartPopOut(struct Task *task, struct ObjectEvent *objectEvent, struct Sprite *sprite) { if (IsWeatherNotFadingIn()) { @@ -2007,13 +2078,13 @@ static bool8 LavaridgeGymB1FWarpExitEffect_2(struct Task *task, struct ObjectEve gFieldEffectArguments[1] = objectEvent->currentCoords.y; gFieldEffectArguments[2] = sprite->subpriority - 1; gFieldEffectArguments[3] = sprite->oam.priority; - task->data[1] = FieldEffectStart(FLDEFF_POP_OUT_OF_ASH); + task->data[1] = FieldEffectStart(FLDEFF_ASH_PUFF); task->data[0]++; } return FALSE; } -static bool8 LavaridgeGymB1FWarpExitEffect_3(struct Task *task, struct ObjectEvent *objectEvent, struct Sprite *sprite) +static bool8 LavaridgeGymB1FWarpExitEffect_PopOut(struct Task *task, struct ObjectEvent *objectEvent, struct Sprite *sprite) { sprite = &gSprites[task->data[1]]; if (sprite->animCmdIndex > 1) @@ -2027,7 +2098,7 @@ static bool8 LavaridgeGymB1FWarpExitEffect_3(struct Task *task, struct ObjectEve return FALSE; } -static bool8 LavaridgeGymB1FWarpExitEffect_4(struct Task *task, struct ObjectEvent *objectEvent, struct Sprite *sprite) +static bool8 LavaridgeGymB1FWarpExitEffect_End(struct Task *task, struct ObjectEvent *objectEvent, struct Sprite *sprite) { if (ObjectEventClearHeldMovementIfFinished(objectEvent)) { @@ -2039,23 +2110,21 @@ static bool8 LavaridgeGymB1FWarpExitEffect_4(struct Task *task, struct ObjectEve return FALSE; } -// For the ash puff effect when warping off the B1F ash tiles -u8 FldEff_LavaridgeGymWarp(void) +// For the ash effect when jumping off the Lavaridge Gym B1F warp tiles +u8 FldEff_AshLaunch(void) { u8 spriteId; SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); - spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[33], gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); + spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_ASH_LAUNCH], gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); gSprites[spriteId].oam.priority = gFieldEffectArguments[3]; - gSprites[spriteId].coordOffsetEnabled = 1; + gSprites[spriteId].coordOffsetEnabled = TRUE; return spriteId; } -void SpriteCB_LavaridgeGymWarp(struct Sprite *sprite) +void SpriteCB_AshLaunch(struct Sprite *sprite) { if (sprite->animEnded) - { - FieldEffectStop(sprite, FLDEFF_LAVARIDGE_GYM_WARP); - } + FieldEffectStop(sprite, FLDEFF_ASH_LAUNCH); } void StartLavaridgeGym1FWarp(u8 priority) @@ -2068,7 +2137,7 @@ static void Task_LavaridgeGym1FWarp(u8 taskId) while(sLavaridgeGym1FWarpEffectFuncs[gTasks[taskId].data[0]](&gTasks[taskId], &gObjectEvents[gPlayerAvatar.objectEventId], &gSprites[gPlayerAvatar.spriteId])); } -static bool8 LavaridgeGym1FWarpEffect_1(struct Task *task, struct ObjectEvent *objectEvent, struct Sprite *sprite) +static bool8 LavaridgeGym1FWarpEffect_Init(struct Task *task, struct ObjectEvent *objectEvent, struct Sprite *sprite) { FreezeObjectEvents(); CameraObjectReset2(); @@ -2078,7 +2147,7 @@ static bool8 LavaridgeGym1FWarpEffect_1(struct Task *task, struct ObjectEvent *o return FALSE; } -static bool8 LavaridgeGym1FWarpEffect_2(struct Task *task, struct ObjectEvent *objectEvent, struct Sprite *sprite) +static bool8 LavaridgeGym1FWarpEffect_AshPuff(struct Task *task, struct ObjectEvent *objectEvent, struct Sprite *sprite) { if (ObjectEventClearHeldMovementIfFinished(objectEvent)) { @@ -2088,7 +2157,7 @@ static bool8 LavaridgeGym1FWarpEffect_2(struct Task *task, struct ObjectEvent *o gFieldEffectArguments[1] = objectEvent->currentCoords.y; gFieldEffectArguments[2] = sprite->subpriority - 1; gFieldEffectArguments[3] = sprite->oam.priority; - task->data[1] = FieldEffectStart(FLDEFF_POP_OUT_OF_ASH); + task->data[1] = FieldEffectStart(FLDEFF_ASH_PUFF); task->data[0]++; } else { @@ -2100,7 +2169,7 @@ static bool8 LavaridgeGym1FWarpEffect_2(struct Task *task, struct ObjectEvent *o return FALSE; } -static bool8 LavaridgeGym1FWarpEffect_3(struct Task *task, struct ObjectEvent *objectEvent, struct Sprite *sprite) +static bool8 LavaridgeGym1FWarpEffect_Disappear(struct Task *task, struct ObjectEvent *objectEvent, struct Sprite *sprite) { if (gSprites[task->data[1]].animCmdIndex == 2) { @@ -2110,9 +2179,9 @@ static bool8 LavaridgeGym1FWarpEffect_3(struct Task *task, struct ObjectEvent *o return FALSE; } -static bool8 LavaridgeGym1FWarpEffect_4(struct Task *task, struct ObjectEvent *objectEvent, struct Sprite *sprite) +static bool8 LavaridgeGym1FWarpEffect_FadeOut(struct Task *task, struct ObjectEvent *objectEvent, struct Sprite *sprite) { - if (!FieldEffectActiveListContains(FLDEFF_POP_OUT_OF_ASH)) + if (!FieldEffectActiveListContains(FLDEFF_ASH_PUFF)) { TryFadeOutOldMapMusic(); WarpFadeOutScreen(); @@ -2121,7 +2190,7 @@ static bool8 LavaridgeGym1FWarpEffect_4(struct Task *task, struct ObjectEvent *o return FALSE; } -static bool8 LavaridgeGym1FWarpEffect_5(struct Task *task, struct ObjectEvent *objectEvent, struct Sprite *sprite) +static bool8 LavaridgeGym1FWarpEffect_Warp(struct Task *task, struct ObjectEvent *objectEvent, struct Sprite *sprite) { if (!gPaletteFade.active && BGMusicStopped() == TRUE) { @@ -2133,48 +2202,53 @@ static bool8 LavaridgeGym1FWarpEffect_5(struct Task *task, struct ObjectEvent *o return FALSE; } -u8 FldEff_PopOutOfAsh(void) +// For the ash effect when a trainer pops out of ash, or when the player enters/exits a warp in Lavaridge Gym 1F +u8 FldEff_AshPuff(void) { u8 spriteId; SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); - spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[32], gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); + spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_ASH_PUFF], gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); gSprites[spriteId].oam.priority = gFieldEffectArguments[3]; - gSprites[spriteId].coordOffsetEnabled = 1; + gSprites[spriteId].coordOffsetEnabled = TRUE; return spriteId; } -void SpriteCB_PopOutOfAsh(struct Sprite *sprite) +void SpriteCB_AshPuff(struct Sprite *sprite) { if (sprite->animEnded) - { - FieldEffectStop(sprite, FLDEFF_POP_OUT_OF_ASH); - } + FieldEffectStop(sprite, FLDEFF_ASH_PUFF); } +#define tState data[0] +#define tSpinDelay data[1] +#define tNumTurns data[2] +#define tTimer data[14] +#define tStartDir data[15] + void StartEscapeRopeFieldEffect(void) { ScriptContext2_Enable(); FreezeObjectEvents(); - CreateTask(DoEscapeRopeFieldEffect, 0x50); + CreateTask(Task_EscapeRopeWarpOut, 80); } -static void DoEscapeRopeFieldEffect(u8 taskId) +static void Task_EscapeRopeWarpOut(u8 taskId) { - gEscapeRopeFieldEffectFuncs[gTasks[taskId].data[0]](&gTasks[taskId]); + sEscapeRopeWarpOutEffectFuncs[gTasks[taskId].tState](&gTasks[taskId]); } -static void EscapeRopeFieldEffect_Step0(struct Task *task) +static void EscapeRopeWarpOutEffect_Init(struct Task *task) { - task->data[0]++; - task->data[14] = 64; - task->data[15] = GetPlayerFacingDirection(); + task->tState++; + task->tTimer = 64; + task->tStartDir = GetPlayerFacingDirection(); } -static void EscapeRopeFieldEffect_Step1(struct Task *task) +static void EscapeRopeWarpOutEffect_Spin(struct Task *task) { struct ObjectEvent *objectEvent; u8 spinDirections[5] = {DIR_SOUTH, DIR_WEST, DIR_EAST, DIR_NORTH, DIR_SOUTH}; - if (task->data[14] != 0 && (--task->data[14]) == 0) + if (task->tTimer != 0 && (--task->tTimer) == 0) { TryFadeOutOldMapMusic(); WarpFadeOutScreen(); @@ -2182,32 +2256,31 @@ static void EscapeRopeFieldEffect_Step1(struct Task *task) objectEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; if (!ObjectEventIsMovementOverridden(objectEvent) || ObjectEventClearHeldMovementIfFinished(objectEvent)) { - if (task->data[14] == 0 && !gPaletteFade.active && BGMusicStopped() == TRUE) + if (task->tTimer == 0 && !gPaletteFade.active && BGMusicStopped() == TRUE) { - SetObjectEventDirection(objectEvent, task->data[15]); + SetObjectEventDirection(objectEvent, task->tStartDir); SetWarpDestinationToEscapeWarp(); WarpIntoMap(); - gFieldCallback = mapldr_080859D4; + gFieldCallback = FieldCallback_EscapeRopeWarpIn; SetMainCallback2(CB2_LoadMap); - DestroyTask(FindTaskIdByFunc(DoEscapeRopeFieldEffect)); - } else if (task->data[1] == 0 || (--task->data[1]) == 0) + DestroyTask(FindTaskIdByFunc(Task_EscapeRopeWarpOut)); + } + else if (task->tSpinDelay == 0 || (--task->tSpinDelay) == 0) { ObjectEventSetHeldMovement(objectEvent, GetFaceDirectionMovementAction(spinDirections[objectEvent->facingDirection])); - if (task->data[2] < 12) - { - task->data[2]++; - } - task->data[1] = 8 >> (task->data[2] >> 2); + if (task->tNumTurns < 12) + task->tNumTurns++; + task->tSpinDelay = 8 >> (task->tNumTurns >> 2); } } } -void (*const gUnknown_0855C484[])(struct Task *) = { - sub_80B7EC4, - sub_80B7EE8 +void (*const sEscapeRopeWarpInEffectFuncs[])(struct Task *) = { + EscapeRopeWarpInEffect_Init, + EscapeRopeWarpInEffect_Spin }; -static void mapldr_080859D4(void) +static void FieldCallback_EscapeRopeWarpIn(void) { Overworld_PlaySpecialMapMusic(); WarpFadeInScreen(); @@ -2215,78 +2288,84 @@ static void mapldr_080859D4(void) FreezeObjectEvents(); gFieldCallback = NULL; gObjectEvents[gPlayerAvatar.objectEventId].invisible = TRUE; - CreateTask(sub_80B7E94, 0); + CreateTask(Task_EscapeRopeWarpIn, 0); } -static void sub_80B7E94(u8 taskId) +static void Task_EscapeRopeWarpIn(u8 taskId) { - gUnknown_0855C484[gTasks[taskId].data[0]](&gTasks[taskId]); + sEscapeRopeWarpInEffectFuncs[gTasks[taskId].tState](&gTasks[taskId]); } -static void sub_80B7EC4(struct Task *task) +static void EscapeRopeWarpInEffect_Init(struct Task *task) { if (IsWeatherNotFadingIn()) { - task->data[0]++; - task->data[15] = GetPlayerFacingDirection(); + task->tState++; + task->tStartDir = GetPlayerFacingDirection(); } } -static void sub_80B7EE8(struct Task *task) +static void EscapeRopeWarpInEffect_Spin(struct Task *task) { - u8 spinDirections[5] = {1, 3, 4, 2, 1}; + u8 spinDirections[5] = {DIR_SOUTH, DIR_WEST, DIR_EAST, DIR_NORTH, DIR_SOUTH}; struct ObjectEvent *objectEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; - if (task->data[1] == 0 || (--task->data[1]) == 0) + if (task->tSpinDelay == 0 || (--task->tSpinDelay) == 0) { if (ObjectEventIsMovementOverridden(objectEvent) && !ObjectEventClearHeldMovementIfFinished(objectEvent)) { return; } - if (task->data[2] >= 32 && task->data[15] == GetPlayerFacingDirection()) + if (task->tNumTurns >= 32 && task->tStartDir == GetPlayerFacingDirection()) { objectEvent->invisible = FALSE; ScriptContext2_Disable(); UnfreezeObjectEvents(); - DestroyTask(FindTaskIdByFunc(sub_80B7E94)); + DestroyTask(FindTaskIdByFunc(Task_EscapeRopeWarpIn)); return; } ObjectEventSetHeldMovement(objectEvent, GetFaceDirectionMovementAction(spinDirections[objectEvent->facingDirection])); - if (task->data[2] < 32) - { - task->data[2]++; - } - task->data[1] = task->data[2] >> 2; + if (task->tNumTurns < 32) + task->tNumTurns++; + task->tSpinDelay = task->tNumTurns >> 2; } objectEvent->invisible ^= 1; } -void CreateTeleportFieldEffectTask(void) +#undef tState +#undef tSpinDelay +#undef tNumTurns +#undef tTimer +#undef tStartDir + +#define tState data[0] + +void FldEff_TeleportWarpOut(void) { - CreateTask(ExecuteTeleportFieldEffectTask, 0); + CreateTask(Task_TeleportWarpOut, 0); } -static void (*const sTeleportFieldEffectTasks[])(struct Task *) = { - TeleportFieldEffectTask1, - TeleportFieldEffectTask2, - TeleportFieldEffectTask3, - TeleportFieldEffectTask4 +static void (*const sTeleportWarpOutFieldEffectFuncs[])(struct Task *) = { + TeleportWarpOutFieldEffect_Init, + TeleportWarpOutFieldEffect_SpinGround, + TeleportWarpOutFieldEffect_SpinExit, + TeleportWarpOutFieldEffect_End }; -static void ExecuteTeleportFieldEffectTask(u8 taskId) +static void Task_TeleportWarpOut(u8 taskId) { - sTeleportFieldEffectTasks[gTasks[taskId].data[0]](&gTasks[taskId]); + sTeleportWarpOutFieldEffectFuncs[gTasks[taskId].tState](&gTasks[taskId]); } -static void TeleportFieldEffectTask1(struct Task *task) +static void TeleportWarpOutFieldEffect_Init(struct Task *task) { ScriptContext2_Enable(); FreezeObjectEvents(); CameraObjectReset2(); task->data[15] = GetPlayerFacingDirection(); - task->data[0]++; + task->tState++; } -static void TeleportFieldEffectTask2(struct Task *task) +static void TeleportWarpOutFieldEffect_SpinGround(struct Task *task) { u8 spinDirections[5] = {DIR_SOUTH, DIR_WEST, DIR_EAST, DIR_NORTH, DIR_SOUTH}; struct ObjectEvent *objectEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; @@ -2298,7 +2377,7 @@ static void TeleportFieldEffectTask2(struct Task *task) } if (task->data[2] > 7 && task->data[15] == objectEvent->facingDirection) { - task->data[0]++; + task->tState++; task->data[1] = 4; task->data[2] = 8; task->data[3] = 1; @@ -2306,7 +2385,7 @@ static void TeleportFieldEffectTask2(struct Task *task) } } -static void TeleportFieldEffectTask3(struct Task *task) +static void TeleportWarpOutFieldEffect_SpinExit(struct Task *task) { u8 spinDirections[5] = {DIR_SOUTH, DIR_WEST, DIR_EAST, DIR_NORTH, DIR_SOUTH}; struct ObjectEvent *objectEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; @@ -2328,13 +2407,13 @@ static void TeleportFieldEffectTask3(struct Task *task) } if (task->data[4] >= 0xa8) { - task->data[0]++; + task->tState++; TryFadeOutOldMapMusic(); WarpFadeOutScreen(); } } -static void TeleportFieldEffectTask4(struct Task *task) +static void TeleportWarpOutFieldEffect_End(struct Task *task) { if (!gPaletteFade.active) { @@ -2349,13 +2428,13 @@ static void TeleportFieldEffectTask4(struct Task *task) SetWarpDestinationToLastHealLocation(); WarpIntoMap(); SetMainCallback2(CB2_LoadMap); - gFieldCallback = mapldr_08085D88; - DestroyTask(FindTaskIdByFunc(ExecuteTeleportFieldEffectTask)); + gFieldCallback = FieldCallback_TeleportWarpIn; + DestroyTask(FindTaskIdByFunc(Task_TeleportWarpOut)); } } } -static void mapldr_08085D88(void) +static void FieldCallback_TeleportWarpIn(void) { Overworld_PlaySpecialMapMusic(); WarpFadeInScreen(); @@ -2364,21 +2443,21 @@ static void mapldr_08085D88(void) gFieldCallback = NULL; gObjectEvents[gPlayerAvatar.objectEventId].invisible = TRUE; CameraObjectReset2(); - CreateTask(sub_80B8250, 0); + CreateTask(Task_TeleportWarpIn, 0); } -void (*const gUnknown_0855C49C[])(struct Task *) = { - sub_80B8280, - sub_80B830C, - sub_80B8410 +void (*const sTeleportWarpInFieldEffectFuncs[])(struct Task *) = { + TeleportWarpInFieldEffect_Init, + TeleportWarpInFieldEffect_SpinEnter, + TeleportWarpInFieldEffect_SpinGround }; -static void sub_80B8250(u8 taskId) +static void Task_TeleportWarpIn(u8 taskId) { - gUnknown_0855C49C[gTasks[taskId].data[0]](&gTasks[taskId]); + sTeleportWarpInFieldEffectFuncs[gTasks[taskId].data[0]](&gTasks[taskId]); } -static void sub_80B8280(struct Task *task) +static void TeleportWarpInFieldEffect_Init(struct Task *task) { struct Sprite *sprite; s16 centerToCornerVecY; @@ -2397,9 +2476,9 @@ static void sub_80B8280(struct Task *task) } } -static void sub_80B830C(struct Task *task) +static void TeleportWarpInFieldEffect_SpinEnter(struct Task *task) { - u8 spinDirections[5] = {1, 3, 4, 2, 1}; + u8 spinDirections[5] = {DIR_SOUTH, DIR_WEST, DIR_EAST, DIR_NORTH, DIR_SOUTH}; struct ObjectEvent *objectEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; struct Sprite *sprite = &gSprites[gPlayerAvatar.spriteId]; if ((sprite->pos2.y += task->data[1]) >= -8) @@ -2436,9 +2515,9 @@ static void sub_80B830C(struct Task *task) } } -static void sub_80B8410(struct Task *task) +static void TeleportWarpInFieldEffect_SpinGround(struct Task *task) { - u8 spinDirections[5] = {1, 3, 4, 2, 1}; + u8 spinDirections[5] = {DIR_SOUTH, DIR_WEST, DIR_EAST, DIR_NORTH, DIR_SOUTH}; struct ObjectEvent *objectEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; if ((--task->data[1]) == 0) { @@ -2449,22 +2528,39 @@ static void sub_80B8410(struct Task *task) ScriptContext2_Disable(); CameraObjectReset1(); UnfreezeObjectEvents(); - DestroyTask(FindTaskIdByFunc(sub_80B8250)); + DestroyTask(FindTaskIdByFunc(Task_TeleportWarpIn)); } } } +// Task data for Task_FieldMoveShowMonOutDoors +#define tState data[0] +#define tWinHoriz data[1] +#define tWinVert data[2] +#define tWinIn data[3] +#define tWinOut data[4] +#define tBgHoriz data[5] +#define tBgVert data[6] +#define tMonSpriteId data[15] + +// Sprite data for field move mon sprite +#define sSpecies data[0] +#define sOnscreenTimer data[1] +#define sSlidOffscreen data[7] + +// There are two variants (outdoor/indoor) of the "show mon for a field move" effect +// Outdoor has a black background with thick white streaks and appears from the right by stretching vertically and horizontally +// Indoor has blue background with thin white streaks and appears from the left by stretching horizontally +// For both the background streaks move to the right, and the mon sprite enters from the right and exits left bool8 FldEff_FieldMoveShowMon(void) { u8 taskId; if (IsMapTypeOutdoors(GetCurrentMapType()) == TRUE) - { - taskId = CreateTask(sub_80B8554, 0xff); - } else - { - taskId = CreateTask(sub_80B88B4, 0xff); - } - gTasks[taskId].data[15] = sub_80B8C60(gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); + taskId = CreateTask(Task_FieldMoveShowMonOutdoors, 0xff); + else + taskId = CreateTask(Task_FieldMoveShowMonIndoors, 0xff); + + gTasks[taskId].tMonSpriteId = InitFieldMoveMonSprite(gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); return FALSE; } @@ -2482,240 +2578,248 @@ bool8 FldEff_FieldMoveShowMonInit(void) return FALSE; } -void (*const gUnknown_0855C4A8[])(struct Task *) = { - sub_80B8584, - sub_80B85F8, - sub_80B8660, - sub_80B86EC, - sub_80B871C, - sub_80B8770, - overworld_bg_setup_2, +void (*const sFieldMoveShowMonOutdoorsEffectFuncs[])(struct Task *) = { + FieldMoveShowMonOutdoorsEffect_Init, + FieldMoveShowMonOutdoorsEffect_LoadGfx, + FieldMoveShowMonOutdoorsEffect_CreateBanner, + FieldMoveShowMonOutdoorsEffect_WaitForMon, + FieldMoveShowMonOutdoorsEffect_ShrinkBanner, + FieldMoveShowMonOutdoorsEffect_RestoreBg, + FieldMoveShowMonOutdoorsEffect_End, }; -static void sub_80B8554(u8 taskId) +static void Task_FieldMoveShowMonOutdoors(u8 taskId) { - gUnknown_0855C4A8[gTasks[taskId].data[0]](&gTasks[taskId]); + sFieldMoveShowMonOutdoorsEffectFuncs[gTasks[taskId].tState](&gTasks[taskId]); } -static void sub_80B8584(struct Task *task) +static void FieldMoveShowMonOutdoorsEffect_Init(struct Task *task) { task->data[11] = REG_WININ; task->data[12] = REG_WINOUT; StoreWordInTwoHalfwords((u16 *)&task->data[13], (u32)gMain.vblankCallback); - task->data[1] = 0xf0f1; - task->data[2] = 0x5051; - task->data[3] = 0x3f; - task->data[4] = 0x3e; - SetGpuReg(REG_OFFSET_WIN0H, task->data[1]); - SetGpuReg(REG_OFFSET_WIN0V, task->data[2]); - SetGpuReg(REG_OFFSET_WININ, task->data[3]); - SetGpuReg(REG_OFFSET_WINOUT, task->data[4]); - SetVBlankCallback(sub_80B880C); - task->data[0]++; + task->tWinHoriz = WIN_RANGE(DISPLAY_WIDTH, DISPLAY_WIDTH + 1); + task->tWinVert = WIN_RANGE(DISPLAY_HEIGHT / 2, DISPLAY_HEIGHT / 2 + 1); + task->tWinIn = WININ_WIN0_BG_ALL | WININ_WIN0_OBJ | WININ_WIN0_CLR; + task->tWinOut = WINOUT_WIN01_BG1 | WINOUT_WIN01_BG2 | WINOUT_WIN01_BG3 | WINOUT_WIN01_OBJ | WINOUT_WIN01_CLR; + SetGpuReg(REG_OFFSET_WIN0H, task->tWinHoriz); + SetGpuReg(REG_OFFSET_WIN0V, task->tWinVert); + SetGpuReg(REG_OFFSET_WININ, task->tWinIn); + SetGpuReg(REG_OFFSET_WINOUT, task->tWinOut); + SetVBlankCallback(VBlankCB_FieldMoveShowMonOutdoors); + task->tState++; } -static void sub_80B85F8(struct Task *task) +static void FieldMoveShowMonOutdoorsEffect_LoadGfx(struct Task *task) { u16 offset = ((REG_BG0CNT >> 2) << 14); u16 delta = ((REG_BG0CNT >> 8) << 11); - CpuCopy16(gFieldMoveStreaksTiles, (void *)(VRAM + offset), 0x200); + CpuCopy16(sFieldMoveStreaksOutdoors_Gfx, (void *)(VRAM + offset), 0x200); CpuFill32(0, (void *)(VRAM + delta), 0x800); - LoadPalette(gFieldMoveStreaksPalette, 0xf0, 0x20); - sub_80B8874(delta); - task->data[0]++; + LoadPalette(sFieldMoveStreaksOutdoors_Pal, 0xf0, 0x20); + LoadFieldMoveOutdoorStreaksTilemap(delta); + task->tState++; } -static void sub_80B8660(struct Task *task) +static void FieldMoveShowMonOutdoorsEffect_CreateBanner(struct Task *task) { - s16 v0; - s16 v2; - s16 v3; - task->data[5] -= 16; - v0 = ((u16)task->data[1] >> 8); - v2 = ((u16)task->data[2] >> 8); - v3 = ((u16)task->data[2] & 0xff); - v0 -= 16; - v2 -= 2; - v3 += 2; - if (v0 < 0) - { - v0 = 0; - } - if (v2 < 0x28) - { - v2 = 0x28; - } - if (v3 > 0x78) - { - v3 = 0x78; - } - task->data[1] = (v0 << 8) | (task->data[1] & 0xff); - task->data[2] = (v2 << 8) | v3; - if (v0 == 0 && v2 == 0x28 && v3 == 0x78) + s16 horiz; + s16 vertHi; + s16 vertLo; + task->tBgHoriz -= 16; + horiz = ((u16)task->tWinHoriz >> 8); + vertHi = ((u16)task->tWinVert >> 8); + vertLo = ((u16)task->tWinVert & 0xff); + horiz -= 16; + vertHi -= 2; + vertLo += 2; + + if (horiz < 0) + horiz = 0; + + if (vertHi < DISPLAY_HEIGHT / 4) + vertHi = DISPLAY_HEIGHT / 4; + + if (vertLo > DISPLAY_WIDTH / 2) + vertLo = DISPLAY_WIDTH / 2; + + task->tWinHoriz = (horiz << 8) | (task->tWinHoriz & 0xff); + task->tWinVert = (vertHi << 8) | vertLo; + if (horiz == 0 && vertHi == DISPLAY_HEIGHT / 4 && vertLo == DISPLAY_WIDTH / 2) { - gSprites[task->data[15]].callback = sub_80B8CC0; - task->data[0]++; + gSprites[task->tMonSpriteId].callback = SpriteCB_FieldMoveMonSlideOnscreen; + task->tState++; } } -static void sub_80B86EC(struct Task *task) +static void FieldMoveShowMonOutdoorsEffect_WaitForMon(struct Task *task) { - task->data[5] -= 16; - if (gSprites[task->data[15]].data[7]) - { - task->data[0]++; - } + task->tBgHoriz -= 16; + + if (gSprites[task->tMonSpriteId].sSlidOffscreen) + task->tState++; } -static void sub_80B871C(struct Task *task) +static void FieldMoveShowMonOutdoorsEffect_ShrinkBanner(struct Task *task) { - s16 v2; - s16 v3; - task->data[5] -= 16; - v2 = (task->data[2] >> 8); - v3 = (task->data[2] & 0xff); - v2 += 6; - v3 -= 6; - if (v2 > 0x50) - { - v2 = 0x50; - } - if (v3 < 0x51) - { - v3 = 0x51; - } - task->data[2] = (v2 << 8) | v3; - if (v2 == 0x50 && v3 == 0x51) - { - task->data[0]++; - } + s16 vertHi; + s16 vertLo; + task->tBgHoriz -= 16; + vertHi = (task->tWinVert >> 8); + vertLo = (task->tWinVert & 0xFF); + vertHi += 6; + vertLo -= 6; + + if (vertHi > DISPLAY_HEIGHT / 2) + vertHi = DISPLAY_HEIGHT / 2; + + if (vertLo < DISPLAY_HEIGHT / 2 + 1) + vertLo = DISPLAY_HEIGHT / 2 + 1; + + task->tWinVert = (vertHi << 8) | vertLo; + + if (vertHi == DISPLAY_HEIGHT / 2 && vertLo == DISPLAY_HEIGHT / 2 + 1) + task->tState++; } -static void sub_80B8770(struct Task *task) +static void FieldMoveShowMonOutdoorsEffect_RestoreBg(struct Task *task) { u16 bg0cnt = (REG_BG0CNT >> 8) << 11; CpuFill32(0, (void *)VRAM + bg0cnt, 0x800); - task->data[1] = 0xf1; - task->data[2] = 0xa1; - task->data[3] = task->data[11]; - task->data[4] = task->data[12]; - task->data[0]++; + task->tWinHoriz = DISPLAY_WIDTH + 1; + task->tWinVert = DISPLAY_HEIGHT + 1; + task->tWinIn = task->data[11]; + task->tWinOut = task->data[12]; + task->tState++; } -static void overworld_bg_setup_2(struct Task *task) +static void FieldMoveShowMonOutdoorsEffect_End(struct Task *task) { IntrCallback callback; LoadWordFromTwoHalfwords((u16 *)&task->data[13], (u32 *)&callback); SetVBlankCallback(callback); - sub_8197200(); - FreeResourcesAndDestroySprite(&gSprites[task->data[15]], task->data[15]); + InitTextBoxGfxAndPrinters(); + FreeResourcesAndDestroySprite(&gSprites[task->tMonSpriteId], task->tMonSpriteId); FieldEffectActiveListRemove(FLDEFF_FIELD_MOVE_SHOW_MON); - DestroyTask(FindTaskIdByFunc(sub_80B8554)); + DestroyTask(FindTaskIdByFunc(Task_FieldMoveShowMonOutdoors)); } -static void sub_80B880C(void) +static void VBlankCB_FieldMoveShowMonOutdoors(void) { IntrCallback callback; - struct Task *task = &gTasks[FindTaskIdByFunc(sub_80B8554)]; + struct Task *task = &gTasks[FindTaskIdByFunc(Task_FieldMoveShowMonOutdoors)]; LoadWordFromTwoHalfwords((u16 *)&task->data[13], (u32 *)&callback); callback(); - SetGpuReg(REG_OFFSET_WIN0H, task->data[1]); - SetGpuReg(REG_OFFSET_WIN0V, task->data[2]); - SetGpuReg(REG_OFFSET_WININ, task->data[3]); - SetGpuReg(REG_OFFSET_WINOUT, task->data[4]); - SetGpuReg(REG_OFFSET_BG0HOFS, task->data[5]); - SetGpuReg(REG_OFFSET_BG0VOFS, task->data[6]); + SetGpuReg(REG_OFFSET_WIN0H, task->tWinHoriz); + SetGpuReg(REG_OFFSET_WIN0V, task->tWinVert); + SetGpuReg(REG_OFFSET_WININ, task->tWinIn); + SetGpuReg(REG_OFFSET_WINOUT, task->tWinOut); + SetGpuReg(REG_OFFSET_BG0HOFS, task->tBgHoriz); + SetGpuReg(REG_OFFSET_BG0VOFS, task->tBgVert); } -static void sub_80B8874(u16 offs) +static void LoadFieldMoveOutdoorStreaksTilemap(u16 offs) { u16 i; u16 *dest; - dest = (u16 *)(VRAM + 0x140 + offs); - for (i = 0; i < 0x140; i++, dest++) - { - *dest = gFieldMoveStreaksTilemap[i] | METATILE_ELEVATION_MASK; - } -} - -void (*const gUnknown_0855C4C4[])(struct Task *) = { - sub_80B88E4, - sub_80B8920, - sub_80B898C, - sub_80B89DC, - sub_80B8A0C, - sub_80B8A44, - sub_80B8A64, + dest = (u16 *)(VRAM + ARRAY_COUNT(sFieldMoveStreaksOutdoors_Tilemap) + offs); + for (i = 0; i < ARRAY_COUNT(sFieldMoveStreaksOutdoors_Tilemap); i++, dest++) + { + *dest = sFieldMoveStreaksOutdoors_Tilemap[i] | 0xF000; + } +} + +#undef tState +#undef tWinHoriz +#undef tWinVert +#undef tWinIn +#undef tWinOut +#undef tBgHoriz +#undef tBgVert +#undef tMonSpriteId + +// Task data for Task_FieldMoveShowMonIndoors +#define tState data[0] +#define tBgHoriz data[1] +#define tBgVert data[2] +#define tBgOffsetIdx data[3] +#define tBgOffset data[4] +#define tMonSpriteId data[15] + +void (*const sFieldMoveShowMonIndoorsEffectFuncs[])(struct Task *) = { + FieldMoveShowMonIndoorsEffect_Init, + FieldMoveShowMonIndoorsEffect_LoadGfx, + FieldMoveShowMonIndoorsEffect_SlideBannerOn, + FieldMoveShowMonIndoorsEffect_WaitForMon, + FieldMoveShowMonIndoorsEffect_RestoreBg, + FieldMoveShowMonIndoorsEffect_SlideBannerOff, + FieldMoveShowMonIndoorsEffect_End, }; -static void sub_80B88B4(u8 taskId) +static void Task_FieldMoveShowMonIndoors(u8 taskId) { - gUnknown_0855C4C4[gTasks[taskId].data[0]](&gTasks[taskId]); + sFieldMoveShowMonIndoorsEffectFuncs[gTasks[taskId].tState](&gTasks[taskId]); } -static void sub_80B88E4(struct Task *task) +static void FieldMoveShowMonIndoorsEffect_Init(struct Task *task) { - SetGpuReg(REG_OFFSET_BG0HOFS, task->data[1]); - SetGpuReg(REG_OFFSET_BG0VOFS, task->data[2]); + SetGpuReg(REG_OFFSET_BG0HOFS, task->tBgHoriz); + SetGpuReg(REG_OFFSET_BG0VOFS, task->tBgVert); StoreWordInTwoHalfwords((u16 *)&task->data[13], (u32)gMain.vblankCallback); - SetVBlankCallback(sub_80B8AE0); - task->data[0]++; + SetVBlankCallback(VBlankCB_FieldMoveShowMonIndoors); + task->tState++; } -static void sub_80B8920(struct Task *task) +static void FieldMoveShowMonIndoorsEffect_LoadGfx(struct Task *task) { u16 offset; u16 delta; offset = ((REG_BG0CNT >> 2) << 14); delta = ((REG_BG0CNT >> 8) << 11); task->data[12] = delta; - CpuCopy16(gDarknessFieldMoveStreaksTiles, (void *)(VRAM + offset), 0x80); + CpuCopy16(sFieldMoveStreaksIndoors_Gfx, (void *)(VRAM + offset), 0x80); CpuFill32(0, (void *)(VRAM + delta), 0x800); - LoadPalette(gDarknessFieldMoveStreaksPalette, 0xf0, 0x20); - task->data[0]++; + LoadPalette(sFieldMoveStreaksIndoors_Pal, 0xf0, 0x20); + task->tState++; } -static void sub_80B898C(struct Task *task) +static void FieldMoveShowMonIndoorsEffect_SlideBannerOn(struct Task *task) { - if (sub_80B8B38(task)) + if (SlideIndoorBannerOnscreen(task)) { - SetGpuReg(REG_OFFSET_WIN1H, 0x00f0); - SetGpuReg(REG_OFFSET_WIN1V, 0x2878); - gSprites[task->data[15]].callback = sub_80B8CC0; - task->data[0]++; + SetGpuReg(REG_OFFSET_WIN1H, WIN_RANGE(0, DISPLAY_WIDTH)); + SetGpuReg(REG_OFFSET_WIN1V, WIN_RANGE(DISPLAY_HEIGHT / 4, DISPLAY_HEIGHT - DISPLAY_HEIGHT / 4)); + gSprites[task->tMonSpriteId].callback = SpriteCB_FieldMoveMonSlideOnscreen; + task->tState++; } - sub_80B8B28(task); + AnimateIndoorShowMonBg(task); } -static void sub_80B89DC(struct Task *task) +static void FieldMoveShowMonIndoorsEffect_WaitForMon(struct Task *task) { - sub_80B8B28(task); - if (gSprites[task->data[15]].data[7]) - { - task->data[0]++; - } + AnimateIndoorShowMonBg(task); + if (gSprites[task->tMonSpriteId].sSlidOffscreen) + task->tState++; } -static void sub_80B8A0C(struct Task *task) +static void FieldMoveShowMonIndoorsEffect_RestoreBg(struct Task *task) { - sub_80B8B28(task); - task->data[3] = task->data[1] & 7; - task->data[4] = 0; - SetGpuReg(REG_OFFSET_WIN1H, 0xffff); - SetGpuReg(REG_OFFSET_WIN1V, 0xffff); - task->data[0]++; + AnimateIndoorShowMonBg(task); + task->tBgOffsetIdx = task->tBgHoriz & 7; + task->tBgOffset = 0; + SetGpuReg(REG_OFFSET_WIN1H, WIN_RANGE(0xFF, 0xFF)); + SetGpuReg(REG_OFFSET_WIN1V, WIN_RANGE(0xFF, 0xFF)); + task->tState++; } -static void sub_80B8A44(struct Task *task) +static void FieldMoveShowMonIndoorsEffect_SlideBannerOff(struct Task *task) { - sub_80B8B28(task); - if (sub_80B8BF0(task)) - { - task->data[0]++; - } + AnimateIndoorShowMonBg(task); + if (SlideIndoorBannerOffscreen(task)) + task->tState++; } -static void sub_80B8A64(struct Task *task) +static void FieldMoveShowMonIndoorsEffect_End(struct Task *task) { IntrCallback intrCallback; u16 bg0cnt; @@ -2723,231 +2827,248 @@ static void sub_80B8A64(struct Task *task) CpuFill32(0, (void *)VRAM + bg0cnt, 0x800); LoadWordFromTwoHalfwords((u16 *)&task->data[13], (u32 *)&intrCallback); SetVBlankCallback(intrCallback); - sub_8197200(); - FreeResourcesAndDestroySprite(&gSprites[task->data[15]], task->data[15]); + InitTextBoxGfxAndPrinters(); + FreeResourcesAndDestroySprite(&gSprites[task->tMonSpriteId], task->tMonSpriteId); FieldEffectActiveListRemove(FLDEFF_FIELD_MOVE_SHOW_MON); - DestroyTask(FindTaskIdByFunc(sub_80B88B4)); + DestroyTask(FindTaskIdByFunc(Task_FieldMoveShowMonIndoors)); } -static void sub_80B8AE0(void) +static void VBlankCB_FieldMoveShowMonIndoors(void) { IntrCallback intrCallback; struct Task *task; - task = &gTasks[FindTaskIdByFunc(sub_80B88B4)]; + task = &gTasks[FindTaskIdByFunc(Task_FieldMoveShowMonIndoors)]; LoadWordFromTwoHalfwords((u16 *)&task->data[13], (u32 *)&intrCallback); intrCallback(); - SetGpuReg(REG_OFFSET_BG0HOFS, task->data[1]); - SetGpuReg(REG_OFFSET_BG0VOFS, task->data[2]); + SetGpuReg(REG_OFFSET_BG0HOFS, task->tBgHoriz); + SetGpuReg(REG_OFFSET_BG0VOFS, task->tBgVert); } -static void sub_80B8B28(struct Task *task) +static void AnimateIndoorShowMonBg(struct Task *task) { - task->data[1] -= 16; - task->data[3] += 16; + task->tBgHoriz -= 16; + task->tBgOffsetIdx += 16; } -static bool8 sub_80B8B38(struct Task *task) +static bool8 SlideIndoorBannerOnscreen(struct Task *task) { u16 i; u16 srcOffs; u16 dstOffs; u16 *dest; - if (task->data[4] >= 32) - { + + if (task->tBgOffset >= 32) return TRUE; - } - dstOffs = (task->data[3] >> 3) & 0x1f; - if (dstOffs >= task->data[4]) + + dstOffs = (task->tBgOffsetIdx >> 3) & 0x1f; + if (dstOffs >= task->tBgOffset) { dstOffs = (32 - dstOffs) & 0x1f; - srcOffs = (32 - task->data[4]) & 0x1f; + srcOffs = (32 - task->tBgOffset) & 0x1f; dest = (u16 *)(VRAM + 0x140 + (u16)task->data[12]); for (i = 0; i < 10; i++) { - dest[dstOffs + i * 32] = gDarknessFieldMoveStreaksTilemap[srcOffs + i * 32]; + dest[dstOffs + i * 32] = sFieldMoveStreaksIndoors_Tilemap[srcOffs + i * 32]; dest[dstOffs + i * 32] |= 0xf000; - dest[((dstOffs + 1) & 0x1f) + i * 32] = gDarknessFieldMoveStreaksTilemap[((srcOffs + 1) & 0x1f) + i * 32] | 0xf000; + dest[((dstOffs + 1) & 0x1f) + i * 32] = sFieldMoveStreaksIndoors_Tilemap[((srcOffs + 1) & 0x1f) + i * 32] | 0xf000; dest[((dstOffs + 1) & 0x1f) + i * 32] |= 0xf000; } - task->data[4] += 2; + task->tBgOffset += 2; } return FALSE; } -static bool8 sub_80B8BF0(struct Task *task) +static bool8 SlideIndoorBannerOffscreen(struct Task *task) { u16 i; u16 dstOffs; u16 *dest; - if (task->data[4] >= 32) - { + + if (task->tBgOffset >= 32) return TRUE; - } - dstOffs = task->data[3] >> 3; - if (dstOffs >= task->data[4]) + + dstOffs = task->tBgOffsetIdx >> 3; + if (dstOffs >= task->tBgOffset) { - dstOffs = (task->data[1] >> 3) & 0x1f; + dstOffs = (task->tBgHoriz >> 3) & 0x1f; dest = (u16 *)(VRAM + 0x140 + (u16)task->data[12]); for (i = 0; i < 10; i++) { dest[dstOffs + i * 32] = 0xf000; dest[((dstOffs + 1) & 0x1f) + i * 32] = 0xf000; } - task->data[4] += 2; + task->tBgOffset += 2; } return FALSE; } -static u8 sub_80B8C60(u32 a0, u32 a1, u32 a2) +#undef tState +#undef tBgHoriz +#undef tBgVert +#undef tBgOffsetIdx +#undef tBgOffset +#undef tMonSpriteId + +static u8 InitFieldMoveMonSprite(u32 species, u32 otId, u32 personality) { u16 v0; u8 monSprite; struct Sprite *sprite; - v0 = (a0 & 0x80000000) >> 16; - a0 &= 0x7fffffff; - monSprite = CreateMonSprite_FieldMove(a0, a1, a2, 0x140, 0x50, 0); + v0 = (species & 0x80000000) >> 16; + species &= 0x7fffffff; + monSprite = CreateMonSprite_FieldMove(species, otId, personality, 320, 80, 0); sprite = &gSprites[monSprite]; sprite->callback = SpriteCallbackDummy; sprite->oam.priority = 0; - sprite->data[0] = a0; + sprite->sSpecies = species; sprite->data[6] = v0; return monSprite; } -static void sub_80B8CC0(struct Sprite *sprite) +static void SpriteCB_FieldMoveMonSlideOnscreen(struct Sprite *sprite) { - if ((sprite->pos1.x -= 20) <= 0x78) + if ((sprite->pos1.x -= 20) <= DISPLAY_WIDTH / 2) { - sprite->pos1.x = 0x78; - sprite->data[1] = 30; - sprite->callback = sub_80B8D04; + sprite->pos1.x = DISPLAY_WIDTH / 2; + sprite->sOnscreenTimer = 30; + sprite->callback = SpriteCB_FieldMoveMonWaitAfterCry; if (sprite->data[6]) { - PlayCry2(sprite->data[0], 0, 0x7d, 0xa); + PlayCry2(sprite->sSpecies, 0, 0x7d, 0xa); } else { - PlayCry1(sprite->data[0], 0); + PlayCry1(sprite->sSpecies, 0); } } } -static void sub_80B8D04(struct Sprite *sprite) +static void SpriteCB_FieldMoveMonWaitAfterCry(struct Sprite *sprite) { - if ((--sprite->data[1]) == 0) - { - sprite->callback = sub_80B8D20; - } + if ((--sprite->sOnscreenTimer) == 0) + sprite->callback = SpriteCB_FieldMoveMonSlideOffscreen; } -static void sub_80B8D20(struct Sprite *sprite) +static void SpriteCB_FieldMoveMonSlideOffscreen(struct Sprite *sprite) { - if (sprite->pos1.x < -0x40) - { - sprite->data[7] = 1; - } + if (sprite->pos1.x < -64) + sprite->sSlidOffscreen = TRUE; else - { sprite->pos1.x -= 20; - } } +#undef tState +#undef tMonSpriteId +#undef sSpecies +#undef sSlidOffscreen +#undef sOnscreenTimer + +#define tState data[0] +#define tDestX data[1] +#define tDestY data[2] +#define tMonId data[15] + u8 FldEff_UseSurf(void) { - u8 taskId = CreateTask(sub_80B8D84, 0xff); - gTasks[taskId].data[15] = gFieldEffectArguments[0]; + u8 taskId = CreateTask(Task_SurfFieldEffect, 0xff); + gTasks[taskId].tMonId = gFieldEffectArguments[0]; Overworld_ClearSavedMusic(); Overworld_ChangeMusicTo(MUS_NAMINORI); return FALSE; } -void (*const gUnknown_0855C4E0[])(struct Task *) = { - sub_80B8DB4, - sub_80B8E14, - sub_80B8E60, - sub_80B8EA8, - sub_80B8F24, +void (*const sSurfFieldEffectFuncs[])(struct Task *) = { + SurfFieldEffect_Init, + SurfFieldEffect_FieldMovePose, + SurfFieldEffect_ShowMon, + SurfFieldEffect_JumpOnSurfBlob, + SurfFieldEffect_End, }; -static void sub_80B8D84(u8 taskId) +static void Task_SurfFieldEffect(u8 taskId) { - gUnknown_0855C4E0[gTasks[taskId].data[0]](&gTasks[taskId]); + sSurfFieldEffectFuncs[gTasks[taskId].tState](&gTasks[taskId]); } -static void sub_80B8DB4(struct Task *task) +static void SurfFieldEffect_Init(struct Task *task) { ScriptContext2_Enable(); FreezeObjectEvents(); gPlayerAvatar.preventStep = TRUE; - SetPlayerAvatarStateMask(8); - PlayerGetDestCoords(&task->data[1], &task->data[2]); - MoveCoords(gObjectEvents[gPlayerAvatar.objectEventId].movementDirection, &task->data[1], &task->data[2]); - task->data[0]++; + SetPlayerAvatarStateMask(PLAYER_AVATAR_FLAG_SURFING); + PlayerGetDestCoords(&task->tDestX, &task->tDestY); + MoveCoords(gObjectEvents[gPlayerAvatar.objectEventId].movementDirection, &task->tDestX, &task->tDestY); + task->tState++; } -static void sub_80B8E14(struct Task *task) +static void SurfFieldEffect_FieldMovePose(struct Task *task) { struct ObjectEvent *objectEvent; objectEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; if (!ObjectEventIsMovementOverridden(objectEvent) || ObjectEventClearHeldMovementIfFinished(objectEvent)) { - sub_808C114(); + SetPlayerAvatarFieldMove(); ObjectEventSetHeldMovement(objectEvent, MOVEMENT_ACTION_START_ANIM_IN_DIRECTION); - task->data[0]++; + task->tState++; } } -static void sub_80B8E60(struct Task *task) +static void SurfFieldEffect_ShowMon(struct Task *task) { struct ObjectEvent *objectEvent; objectEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; if (ObjectEventCheckHeldMovementStatus(objectEvent)) { - gFieldEffectArguments[0] = task->data[15] | 0x80000000; + gFieldEffectArguments[0] = task->tMonId | 0x80000000; FieldEffectStart(FLDEFF_FIELD_MOVE_SHOW_MON_INIT); - task->data[0]++; + task->tState++; } } -static void sub_80B8EA8(struct Task *task) +static void SurfFieldEffect_JumpOnSurfBlob(struct Task *task) { struct ObjectEvent *objectEvent; if (!FieldEffectActiveListContains(FLDEFF_FIELD_MOVE_SHOW_MON)) { objectEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; - ObjectEventSetGraphicsId(objectEvent, GetPlayerAvatarGraphicsIdByStateId(3)); + ObjectEventSetGraphicsId(objectEvent, GetPlayerAvatarGraphicsIdByStateId(PLAYER_AVATAR_STATE_SURFING)); ObjectEventClearHeldMovementIfFinished(objectEvent); ObjectEventSetHeldMovement(objectEvent, GetJumpSpecialMovementAction(objectEvent->movementDirection)); - gFieldEffectArguments[0] = task->data[1]; - gFieldEffectArguments[1] = task->data[2]; + gFieldEffectArguments[0] = task->tDestX; + gFieldEffectArguments[1] = task->tDestY; gFieldEffectArguments[2] = gPlayerAvatar.objectEventId; objectEvent->fieldEffectSpriteId = FieldEffectStart(FLDEFF_SURF_BLOB); - task->data[0]++; + task->tState++; } } -static void sub_80B8F24(struct Task *task) +static void SurfFieldEffect_End(struct Task *task) { struct ObjectEvent *objectEvent; objectEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; if (ObjectEventClearHeldMovementIfFinished(objectEvent)) { gPlayerAvatar.preventStep = FALSE; - gPlayerAvatar.flags &= 0xdf; + gPlayerAvatar.flags &= ~PLAYER_AVATAR_FLAG_5; ObjectEventSetHeldMovement(objectEvent, GetFaceDirectionMovementAction(objectEvent->movementDirection)); - sub_81555AC(objectEvent->fieldEffectSpriteId, 1); + SetSurfBobState(objectEvent->fieldEffectSpriteId, 1); UnfreezeObjectEvents(); ScriptContext2_Disable(); FieldEffectActiveListRemove(FLDEFF_USE_SURF); - DestroyTask(FindTaskIdByFunc(sub_80B8D84)); + DestroyTask(FindTaskIdByFunc(Task_SurfFieldEffect)); } } -u8 sub_80B8F98(void) +#undef tState +#undef tDestX +#undef tDestY +#undef tMonId + +u8 FldEff_RayquazaSpotlight(void) { u8 i, j, k; - u8 spriteId = CreateSprite(gFieldEffectObjectTemplatePointers[36], 0x78, -0x18, 1); + u8 spriteId = CreateSprite(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_RAYQUAZA], 120, -24, 1); struct Sprite *sprite = &gSprites[spriteId]; sprite->oam.priority = 1; @@ -2961,7 +3082,7 @@ u8 sub_80B8F98(void) SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG0 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_BG1 | BLDCNT_TGT2_BG2 | BLDCNT_TGT2_BG3 | BLDCNT_TGT2_OBJ | BLDCNT_TGT2_BD); SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(14, 14)); SetGpuReg(REG_OFFSET_WININ, WININ_WIN0_BG_ALL | WININ_WIN0_OBJ | WININ_WIN0_CLR | WININ_WIN1_BG_ALL | WININ_WIN1_OBJ | WININ_WIN1_CLR); - LoadPalette(gUnknown_0855B610, 0xC0, sizeof(gUnknown_0855B610)); + LoadPalette(sSpotlight_Pal, 0xC0, sizeof(sSpotlight_Pal)); SetGpuReg(REG_OFFSET_BG0VOFS, 120); for (i = 3; i < 15; i++) { @@ -2974,8 +3095,8 @@ u8 sub_80B8F98(void) { for (i = 0; i < 8; i++) { - *(u16*)(BG_CHAR_ADDR(2) + (k + 1) * 32 + i * 4) = (gUnknown_0855B630[k * 32 + i * 4 + 1] << 8) + gUnknown_0855B630[k * 32 + i * 4]; - *(u16*)(BG_CHAR_ADDR(2) + (k + 1) * 32 + i * 4 + 2) = (gUnknown_0855B630[k * 32 + i * 4 + 3] << 8) + gUnknown_0855B630[k * 32 + i * 4 + 2]; + *(u16*)(BG_CHAR_ADDR(2) + (k + 1) * 32 + i * 4) = (sSpotlight_Gfx[k * 32 + i * 4 + 1] << 8) + sSpotlight_Gfx[k * 32 + i * 4]; + *(u16*)(BG_CHAR_ADDR(2) + (k + 1) * 32 + i * 4 + 2) = (sSpotlight_Gfx[k * 32 + i * 4 + 3] << 8) + sSpotlight_Gfx[k * 32 + i * 4 + 2]; } } return spriteId; @@ -2983,18 +3104,18 @@ u8 sub_80B8F98(void) u8 FldEff_NPCFlyOut(void) { - u8 spriteId = CreateSprite(gFieldEffectObjectTemplatePointers[26], 0x78, 0, 1); + u8 spriteId = CreateSprite(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_BIRD], 0x78, 0, 1); struct Sprite *sprite = &gSprites[spriteId]; sprite->oam.paletteNum = 0; sprite->oam.priority = 1; - sprite->callback = sub_80B9128; + sprite->callback = SpriteCB_NPCFlyOut; sprite->data[1] = gFieldEffectArguments[0]; PlaySE(SE_W019); return spriteId; } -static void sub_80B9128(struct Sprite *sprite) +static void SpriteCB_NPCFlyOut(struct Sprite *sprite) { struct Sprite *npcSprite; @@ -3004,214 +3125,224 @@ static void sub_80B9128(struct Sprite *sprite) if (sprite->data[0]) { npcSprite = &gSprites[sprite->data[1]]; - npcSprite->coordOffsetEnabled = 0; + npcSprite->coordOffsetEnabled = FALSE; npcSprite->pos1.x = sprite->pos1.x + sprite->pos2.x; npcSprite->pos1.y = sprite->pos1.y + sprite->pos2.y - 8; npcSprite->pos2.x = 0; npcSprite->pos2.y = 0; } + if (sprite->data[2] >= 0x80) - { FieldEffectStop(sprite, FLDEFF_NPCFLY_OUT); - } } +// Task data for Task_FlyOut/FlyIn +#define tState data[0] +#define tMonId data[1] +#define tBirdSpriteId data[1] //re-used +#define tTimer data[2] +#define tAvatarFlags data[15] + +// Sprite data for the fly bird +#define sPlayerSpriteId data[6] +#define sAnimCompleted data[7] + u8 FldEff_UseFly(void) { - u8 taskId = CreateTask(sub_80B91D4, 0xfe); - gTasks[taskId].data[1] = gFieldEffectArguments[0]; + u8 taskId = CreateTask(Task_FlyOut, 254); + gTasks[taskId].tMonId = gFieldEffectArguments[0]; return 0; } -void (*const gUnknown_0855C4F4[])(struct Task *) = { - sub_80B9204, - sub_80B925C, - sub_80B92A0, - sub_80B92F8, - sub_80B933C, - sub_80B9390, - sub_80B9418, - sub_80B9474, - sub_80B9494, +void (*const sFlyOutFieldEffectFuncs[])(struct Task *) = { + FlyOutFieldEffect_FieldMovePose, + FlyOutFieldEffect_ShowMon, + FlyOutFieldEffect_BirdLeaveBall, + FlyOutFieldEffect_WaitBirdLeave, + FlyOutFieldEffect_BirdSwoopDown, + FlyOutFieldEffect_JumpOnBird, + FlyOutFieldEffect_FlyOffWithBird, + FlyOutFieldEffect_WaitFlyOff, + FlyOutFieldEffect_End, }; -static void sub_80B91D4(u8 taskId) +static void Task_FlyOut(u8 taskId) { - gUnknown_0855C4F4[gTasks[taskId].data[0]](&gTasks[taskId]); + sFlyOutFieldEffectFuncs[gTasks[taskId].tState](&gTasks[taskId]); } -static void sub_80B9204(struct Task *task) +static void FlyOutFieldEffect_FieldMovePose(struct Task *task) { struct ObjectEvent *objectEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; if (!ObjectEventIsMovementOverridden(objectEvent) || ObjectEventClearHeldMovementIfFinished(objectEvent)) { - task->data[15] = gPlayerAvatar.flags; + task->tAvatarFlags = gPlayerAvatar.flags; gPlayerAvatar.preventStep = TRUE; - SetPlayerAvatarStateMask(1); - sub_808C114(); + SetPlayerAvatarStateMask(PLAYER_AVATAR_FLAG_ON_FOOT); + SetPlayerAvatarFieldMove(); ObjectEventSetHeldMovement(objectEvent, MOVEMENT_ACTION_START_ANIM_IN_DIRECTION); - task->data[0]++; + task->tState++; } } -static void sub_80B925C(struct Task *task) +static void FlyOutFieldEffect_ShowMon(struct Task *task) { struct ObjectEvent *objectEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; if (ObjectEventClearHeldMovementIfFinished(objectEvent)) { - task->data[0]++; - gFieldEffectArguments[0] = task->data[1]; + task->tState++; + gFieldEffectArguments[0] = task->tMonId; FieldEffectStart(FLDEFF_FIELD_MOVE_SHOW_MON_INIT); } } -static void sub_80B92A0(struct Task *task) +static void FlyOutFieldEffect_BirdLeaveBall(struct Task *task) { if (!FieldEffectActiveListContains(FLDEFF_FIELD_MOVE_SHOW_MON)) { struct ObjectEvent *objectEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; - if (task->data[15] & 0x08) + if (task->tAvatarFlags & PLAYER_AVATAR_FLAG_SURFING) { - sub_81555AC(objectEvent->fieldEffectSpriteId, 2); - sub_81555D8(objectEvent->fieldEffectSpriteId, 0); + SetSurfBobState(objectEvent->fieldEffectSpriteId, 2); + SetSurfBobWhileFlyingOutState(objectEvent->fieldEffectSpriteId, 0); } - task->data[1] = sub_80B94C4(); - task->data[0]++; + task->tBirdSpriteId = CreateFlyBirdSprite(); // Does "leave ball" animation by default + task->tState++; } } -static void sub_80B92F8(struct Task *task) +static void FlyOutFieldEffect_WaitBirdLeave(struct Task *task) { - if (sub_80B9508(task->data[1])) + if (GetFlyBirdAnimCompleted(task->tBirdSpriteId)) { - task->data[0]++; - task->data[2] = 16; + task->tState++; + task->tTimer = 16; SetPlayerAvatarTransitionFlags(PLAYER_AVATAR_FLAG_ON_FOOT); ObjectEventSetHeldMovement(&gObjectEvents[gPlayerAvatar.objectEventId], MOVEMENT_ACTION_FACE_LEFT); } } -static void sub_80B933C(struct Task *task) +static void FlyOutFieldEffect_BirdSwoopDown(struct Task *task) { struct ObjectEvent *objectEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; - if ((task->data[2] == 0 || (--task->data[2]) == 0) && ObjectEventClearHeldMovementIfFinished(objectEvent)) + if ((task->tTimer == 0 || (--task->tTimer) == 0) && ObjectEventClearHeldMovementIfFinished(objectEvent)) { - task->data[0]++; + task->tState++; PlaySE(SE_W019); - sub_80B9524(task->data[1]); + StartFlyBirdSwoopDown(task->tBirdSpriteId); } } -static void sub_80B9390(struct Task *task) +static void FlyOutFieldEffect_JumpOnBird(struct Task *task) { - if ((++task->data[2]) >= 8) + if ((++task->tTimer) >= 8) { struct ObjectEvent *objectEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; - ObjectEventSetGraphicsId(objectEvent, GetPlayerAvatarGraphicsIdByStateId(0x03)); + ObjectEventSetGraphicsId(objectEvent, GetPlayerAvatarGraphicsIdByStateId(PLAYER_AVATAR_STATE_SURFING)); StartSpriteAnim(&gSprites[objectEvent->spriteId], 0x16); - objectEvent->inanimate = 1; + objectEvent->inanimate = TRUE; ObjectEventSetHeldMovement(objectEvent, MOVEMENT_ACTION_JUMP_IN_PLACE_LEFT); - if (task->data[15] & 0x08) + if (task->tAvatarFlags & PLAYER_AVATAR_FLAG_SURFING) { DestroySprite(&gSprites[objectEvent->fieldEffectSpriteId]); } - task->data[0]++; - task->data[2] = 0; + task->tState++; + task->tTimer = 0; } } -static void sub_80B9418(struct Task *task) +static void FlyOutFieldEffect_FlyOffWithBird(struct Task *task) { - if ((++task->data[2]) >= 10) + if ((++task->tTimer) >= 10) { struct ObjectEvent *objectEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; ObjectEventClearHeldMovementIfActive(objectEvent); - objectEvent->inanimate = 0; - objectEvent->hasShadow = 0; - sub_80B9560(task->data[1], objectEvent->spriteId); + objectEvent->inanimate = FALSE; + objectEvent->hasShadow = FALSE; + SetFlyBirdPlayerSpriteId(task->tBirdSpriteId, objectEvent->spriteId); CameraObjectReset2(); - task->data[0]++; + task->tState++; } } -static void sub_80B9474(struct Task *task) +static void FlyOutFieldEffect_WaitFlyOff(struct Task *task) { - if (sub_80B9508(task->data[1])) + if (GetFlyBirdAnimCompleted(task->tBirdSpriteId)) { WarpFadeOutScreen(); - task->data[0]++; + task->tState++; } } -static void sub_80B9494(struct Task *task) +static void FlyOutFieldEffect_End(struct Task *task) { if (!gPaletteFade.active) { FieldEffectActiveListRemove(FLDEFF_USE_FLY); - DestroyTask(FindTaskIdByFunc(sub_80B91D4)); + DestroyTask(FindTaskIdByFunc(Task_FlyOut)); } } -static u8 sub_80B94C4(void) +static u8 CreateFlyBirdSprite(void) { u8 spriteId; struct Sprite *sprite; - spriteId = CreateSprite(gFieldEffectObjectTemplatePointers[26], 0xff, 0xb4, 0x1); + spriteId = CreateSprite(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_BIRD], 0xff, 0xb4, 0x1); sprite = &gSprites[spriteId]; sprite->oam.paletteNum = 0; sprite->oam.priority = 1; - sprite->callback = sub_80B957C; + sprite->callback = SpriteCB_FlyBirdLeaveBall; return spriteId; } -static u8 sub_80B9508(u8 spriteId) +static u8 GetFlyBirdAnimCompleted(u8 spriteId) { - return gSprites[spriteId].data[7]; + return gSprites[spriteId].sAnimCompleted; } -static void sub_80B9524(u8 spriteId) +static void StartFlyBirdSwoopDown(u8 spriteId) { struct Sprite *sprite; sprite = &gSprites[spriteId]; - sprite->callback = sub_80B963C; - sprite->pos1.x = 0x78; - sprite->pos1.y = 0x00; + sprite->callback = SpriteCB_FlyBirdSwoopDown; + sprite->pos1.x = DISPLAY_WIDTH / 2; + sprite->pos1.y = 0; sprite->pos2.x = 0; sprite->pos2.y = 0; memset(&sprite->data[0], 0, 8 * sizeof(u16) /* zero all data cells */); - sprite->data[6] = 0x40; + sprite->sPlayerSpriteId = MAX_SPRITES; } -static void sub_80B9560(u8 a0, u8 a1) +static void SetFlyBirdPlayerSpriteId(u8 birdSpriteId, u8 playerSpriteId) { - gSprites[a0].data[6] = a1; + gSprites[birdSpriteId].sPlayerSpriteId = playerSpriteId; } -const union AffineAnimCmd SpriteAffineAnim_855C518[] = { +static const union AffineAnimCmd sAffineAnim_FlyBirdLeaveBall[] = { AFFINEANIMCMD_FRAME(8, 8, -30, 0), AFFINEANIMCMD_FRAME(28, 28, 0, 30), AFFINEANIMCMD_END }; -const union AffineAnimCmd SpriteAffineAnim_855C530[] = { +static const union AffineAnimCmd sAffineAnim_FlyBirdReturnToBall[] = { AFFINEANIMCMD_FRAME(256, 256, 64, 0), AFFINEANIMCMD_FRAME(-10, -10, 0, 22), AFFINEANIMCMD_END }; -const union AffineAnimCmd *const gSpriteAffineAnimTable_0855C548[] = { - SpriteAffineAnim_855C518, - SpriteAffineAnim_855C530 +static const union AffineAnimCmd *const sAffineAnims_FlyBird[] = { + sAffineAnim_FlyBirdLeaveBall, + sAffineAnim_FlyBirdReturnToBall }; -static void sub_80B957C(struct Sprite *sprite) +static void SpriteCB_FlyBirdLeaveBall(struct Sprite *sprite) { - if (sprite->data[7] == 0) + if (sprite->sAnimCompleted == FALSE) { if (sprite->data[0] == 0) { sprite->oam.affineMode = ST_OAM_AFFINE_DOUBLE; - sprite->affineAnims = gSpriteAffineAnimTable_0855C548; + sprite->affineAnims = sAffineAnims_FlyBird; InitSpriteAffineAnim(sprite); StartSpriteAffineAnim(sprite, 0); sprite->pos1.x = 0x76; @@ -3229,7 +3360,7 @@ static void sub_80B957C(struct Sprite *sprite) } if (sprite->data[1] > 0x81) { - sprite->data[7]++; + sprite->sAnimCompleted++; sprite->oam.affineMode = ST_OAM_AFFINE_OFF; FreeOamMatrix(sprite->oam.matrixNum); CalcCenterToCornerVec(sprite, sprite->oam.shape, sprite->oam.size, ST_OAM_AFFINE_OFF); @@ -3237,15 +3368,15 @@ static void sub_80B957C(struct Sprite *sprite) } } -static void sub_80B963C(struct Sprite *sprite) +static void SpriteCB_FlyBirdSwoopDown(struct Sprite *sprite) { sprite->pos2.x = Cos(sprite->data[2], 0x8c); sprite->pos2.y = Sin(sprite->data[2], 0x48); sprite->data[2] = (sprite->data[2] + 4) & 0xff; - if (sprite->data[6] != MAX_SPRITES) + if (sprite->sPlayerSpriteId != MAX_SPRITES) { - struct Sprite *sprite1 = &gSprites[sprite->data[6]]; - sprite1->coordOffsetEnabled = 0; + struct Sprite *sprite1 = &gSprites[sprite->sPlayerSpriteId]; + sprite1->coordOffsetEnabled = FALSE; sprite1->pos1.x = sprite->pos1.x + sprite->pos2.x; sprite1->pos1.y = sprite->pos1.y + sprite->pos2.y - 8; sprite1->pos2.x = 0; @@ -3253,18 +3384,18 @@ static void sub_80B963C(struct Sprite *sprite) } if (sprite->data[2] >= 0x80) { - sprite->data[7] = 1; + sprite->sAnimCompleted = TRUE; } } -void sub_80B96B0(struct Sprite *sprite) +static void SpriteCB_FlyBirdReturnToBall(struct Sprite *sprite) { - if (sprite->data[7] == 0) + if (sprite->sAnimCompleted == FALSE) { if (sprite->data[0] == 0) { sprite->oam.affineMode = ST_OAM_AFFINE_DOUBLE; - sprite->affineAnims = gSpriteAffineAnimTable_0855C548; + sprite->affineAnims = sAffineAnims_FlyBird; InitSpriteAffineAnim(sprite); StartSpriteAffineAnim(sprite, 1); sprite->pos1.x = 0x5e; @@ -3293,7 +3424,7 @@ void sub_80B96B0(struct Sprite *sprite) } if (sprite->data[3] >= 60) { - sprite->data[7]++; + sprite->sAnimCompleted++; sprite->oam.affineMode = ST_OAM_AFFINE_OFF; FreeOamMatrix(sprite->oam.matrixNum); sprite->invisible = TRUE; @@ -3301,80 +3432,80 @@ void sub_80B96B0(struct Sprite *sprite) } } -void sub_80B9794(u8 spriteId) +static void StartFlyBirdReturnToBall(u8 spriteId) { - sub_80B9524(spriteId); - gSprites[spriteId].callback = sub_80B96B0; + StartFlyBirdSwoopDown(spriteId); // Set up is the same, but overrwrites the callback below + gSprites[spriteId].callback = SpriteCB_FlyBirdReturnToBall; } u8 FldEff_FlyIn(void) { - CreateTask(sub_80B97D4, 0xfe); + CreateTask(Task_FlyIn, 254); return 0; } -void (*const gUnknown_0855C550[])(struct Task *) = { - sub_80B9804, - sub_80B98B8, - sub_80B9924, - sub_80B9978, - sub_80B99F0, - sub_80B9A28, - sub_80B9A60, +void (*const sFlyInFieldEffectFuncs[])(struct Task *) = { + FlyInFieldEffect_BirdSwoopDown, + FlyInFieldEffect_FlyInWithBird, + FlyInFieldEffect_JumpOffBird, + FlyInFieldEffect_FieldMovePose, + FlyInFieldEffect_BirdReturnToBall, + FlyInFieldEffect_WaitBirdReturn, + FlyInFieldEffect_End, }; -static void sub_80B97D4(u8 taskId) +static void Task_FlyIn(u8 taskId) { - gUnknown_0855C550[gTasks[taskId].data[0]](&gTasks[taskId]); + sFlyInFieldEffectFuncs[gTasks[taskId].tState](&gTasks[taskId]); } -static void sub_80B9804(struct Task *task) +static void FlyInFieldEffect_BirdSwoopDown(struct Task *task) { struct ObjectEvent *objectEvent; objectEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; if (!ObjectEventIsMovementOverridden(objectEvent) || ObjectEventClearHeldMovementIfFinished(objectEvent)) { - task->data[0]++; - task->data[2] = 17; - task->data[15] = gPlayerAvatar.flags; + task->tState++; + task->tTimer = 17; + task->tAvatarFlags = gPlayerAvatar.flags; gPlayerAvatar.preventStep = TRUE; - SetPlayerAvatarStateMask(0x01); - if (task->data[15] & 0x08) + SetPlayerAvatarStateMask(PLAYER_AVATAR_FLAG_ON_FOOT); + if (task->tAvatarFlags & PLAYER_AVATAR_FLAG_SURFING) { - sub_81555AC(objectEvent->fieldEffectSpriteId, 0); + SetSurfBobState(objectEvent->fieldEffectSpriteId, 0); } - ObjectEventSetGraphicsId(objectEvent, GetPlayerAvatarGraphicsIdByStateId(0x3)); + ObjectEventSetGraphicsId(objectEvent, GetPlayerAvatarGraphicsIdByStateId(PLAYER_AVATAR_STATE_SURFING)); CameraObjectReset2(); ObjectEventTurn(objectEvent, DIR_WEST); StartSpriteAnim(&gSprites[objectEvent->spriteId], 0x16); objectEvent->invisible = FALSE; - task->data[1] = sub_80B94C4(); - sub_80B9524(task->data[1]); - sub_80B9560(task->data[1], objectEvent->spriteId); + task->tBirdSpriteId = CreateFlyBirdSprite(); + StartFlyBirdSwoopDown(task->tBirdSpriteId); + SetFlyBirdPlayerSpriteId(task->tBirdSpriteId, objectEvent->spriteId); } } -static void sub_80B98B8(struct Task *task) +static void FlyInFieldEffect_FlyInWithBird(struct Task *task) { struct ObjectEvent *objectEvent; struct Sprite *sprite; - if (task->data[2] == 0 || (--task->data[2]) == 0) + if (task->tTimer == 0 || (--task->tTimer) == 0) { objectEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; sprite = &gSprites[objectEvent->spriteId]; - sub_80B9560(task->data[1], 0x40); + SetFlyBirdPlayerSpriteId(task->tBirdSpriteId, MAX_SPRITES); sprite->pos1.x += sprite->pos2.x; sprite->pos1.y += sprite->pos2.y; sprite->pos2.x = 0; sprite->pos2.y = 0; - task->data[0]++; - task->data[2] = 0; + task->tState++; + task->tTimer = 0; } } -static void sub_80B9924(struct Task *task) +static void FlyInFieldEffect_JumpOffBird(struct Task *task) { - s16 unknown_0855C56C[18] = { + s16 sYPositions[18] = { -2, -4, -5, @@ -3395,227 +3526,257 @@ static void sub_80B9924(struct Task *task) 8 }; struct Sprite *sprite = &gSprites[gPlayerAvatar.spriteId]; - sprite->pos2.y = unknown_0855C56C[task->data[2]]; - if ((++task->data[2]) >= 18) - { - task->data[0]++; - } + sprite->pos2.y = sYPositions[task->tTimer]; + + if ((++task->tTimer) >= (int)ARRAY_COUNT(sYPositions)) + task->tState++; } -static void sub_80B9978(struct Task *task) +static void FlyInFieldEffect_FieldMovePose(struct Task *task) { struct ObjectEvent *objectEvent; struct Sprite *sprite; - if (sub_80B9508(task->data[1])) + if (GetFlyBirdAnimCompleted(task->tBirdSpriteId)) { objectEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; sprite = &gSprites[objectEvent->spriteId]; - objectEvent->inanimate = 0; + objectEvent->inanimate = FALSE; MoveObjectEventToMapCoords(objectEvent, objectEvent->currentCoords.x, objectEvent->currentCoords.y); sprite->pos2.x = 0; sprite->pos2.y = 0; - sprite->coordOffsetEnabled = 1; - sub_808C114(); + sprite->coordOffsetEnabled = TRUE; + SetPlayerAvatarFieldMove(); ObjectEventSetHeldMovement(objectEvent, MOVEMENT_ACTION_START_ANIM_IN_DIRECTION); - task->data[0]++; + task->tState++; } } -static void sub_80B99F0(struct Task *task) +static void FlyInFieldEffect_BirdReturnToBall(struct Task *task) { if (ObjectEventClearHeldMovementIfFinished(&gObjectEvents[gPlayerAvatar.objectEventId])) { - task->data[0]++; - sub_80B9794(task->data[1]); + task->tState++; + StartFlyBirdReturnToBall(task->tBirdSpriteId); } } -static void sub_80B9A28(struct Task *task) +static void FlyInFieldEffect_WaitBirdReturn(struct Task *task) { - if (sub_80B9508(task->data[1])) + if (GetFlyBirdAnimCompleted(task->tBirdSpriteId)) { - DestroySprite(&gSprites[task->data[1]]); - task->data[0]++; - task->data[1] = 0x10; + DestroySprite(&gSprites[task->tBirdSpriteId]); + task->tState++; + task->data[1] = 16; } } -static void sub_80B9A60(struct Task *task) +static void FlyInFieldEffect_End(struct Task *task) { u8 state; struct ObjectEvent *objectEvent; if ((--task->data[1]) == 0) { objectEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; - state = 0; - if (task->data[15] & 0x08) + state = PLAYER_AVATAR_STATE_NORMAL; + if (task->tAvatarFlags & PLAYER_AVATAR_FLAG_SURFING) { - state = 3; - sub_81555AC(objectEvent->fieldEffectSpriteId, 1); + state = PLAYER_AVATAR_STATE_SURFING; + SetSurfBobState(objectEvent->fieldEffectSpriteId, 1); } ObjectEventSetGraphicsId(objectEvent, GetPlayerAvatarGraphicsIdByStateId(state)); ObjectEventTurn(objectEvent, DIR_SOUTH); - gPlayerAvatar.flags = task->data[15]; + gPlayerAvatar.flags = task->tAvatarFlags; gPlayerAvatar.preventStep = FALSE; FieldEffectActiveListRemove(FLDEFF_FLY_IN); - DestroyTask(FindTaskIdByFunc(sub_80B97D4)); + DestroyTask(FindTaskIdByFunc(Task_FlyIn)); } } -bool8 sub_80B9ADC(void) +#undef tState +#undef tMonId +#undef tBirdSpriteId +#undef tTimer +#undef tAvatarFlags +#undef sPlayerSpriteId +#undef sAnimCompleted + +#define tState data[1] +#define tObjectEventId data[2] +#define tTimer data[3] +#define tCameraTaskId data[5] +#define tLocalId data[6] +#define tMapNum data[7] +#define tMapGroup data[8] + +bool8 FldEff_DestroyDeoxysRock(void) { u8 taskId; - u8 objectEventIdBuffer; - if (!TryGetObjectEventIdByLocalIdAndMap(gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2], &objectEventIdBuffer)) + u8 objectEventId; + if (!TryGetObjectEventIdByLocalIdAndMap(gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2], &objectEventId)) { - taskId = CreateTask(sub_80B9BE8, 0x50); - gTasks[taskId].data[2] = objectEventIdBuffer; - gTasks[taskId].data[6] = gFieldEffectArguments[0]; - gTasks[taskId].data[7] = gFieldEffectArguments[1]; - gTasks[taskId].data[8] = gFieldEffectArguments[2]; + taskId = CreateTask(Task_DestroyDeoxysRock, 80); + gTasks[taskId].tObjectEventId = objectEventId; + gTasks[taskId].tLocalId = gFieldEffectArguments[0]; + gTasks[taskId].tMapNum = gFieldEffectArguments[1]; + gTasks[taskId].tMapGroup = gFieldEffectArguments[2]; } else { - FieldEffectActiveListRemove(0x41); + FieldEffectActiveListRemove(FLDEFF_DESTROY_DEOXYS_ROCK); } return FALSE; } -void sub_80B9B3C(u8 taskId) +#define tShakeDelay data[0] +#define tShakeUp data[1] +#define tShake data[5] +#define tEndDelay data[6] +#define tEnding data[7] + +static void Task_DeoxysRockCameraShake(u8 taskId) { s16 *data = gTasks[taskId].data; - if (data[7] != 0) + if (tEnding) { - if (++data[6] > 20) + if (++tEndDelay > 20) { - data[6] = 0; - if (data[5] != 0) - data[5]--; + tEndDelay = 0; + if (tShake != 0) + tShake--; } } else { - data[5] = 4; + tShake = 4; } - if (++data[0] > 1) + if (++tShakeDelay > 1) { - data[0] = 0; - if (++data[1] & 1) - { - SetCameraPanning(0, -data[5]); - } + tShakeDelay = 0; + + if (++tShakeUp & 1) + SetCameraPanning(0, -tShake); else - { - SetCameraPanning(0, data[5]); - } + SetCameraPanning(0, tShake); } UpdateCameraPanning(); - if (data[5] == 0) + if (tShake == 0) DestroyTask(taskId); } -void sub_80B9BD0(u8 taskId) +static void StartEndingDeoxysRockCameraShake(u8 taskId) { - gTasks[taskId].data[7] = 1; + gTasks[taskId].tEnding = TRUE; } -void (*const gUnknown_0855C590[])(s16*, u8) = { - sub_80B9C28, - sub_80B9C54, - sub_80B9CDC, +#undef tShakeDelay +#undef tShakeUp +#undef tShake +#undef tEndDelay +#undef tEnding + +void (*const sDestroyDeoxysRockEffectFuncs[])(s16*, u8) = { + DestroyDeoxysRockEffect_CameraShake, + DestroyDeoxysRockEffect_RockFragments, + DestroyDeoxysRockEffect_WaitAndEnd, }; -static void sub_80B9BE8(u8 taskId) +static void Task_DestroyDeoxysRock(u8 taskId) { s16 *data = gTasks[taskId].data; InstallCameraPanAheadCallback(); SetCameraPanningCallback(0); - gUnknown_0855C590[data[1]](data, taskId); + sDestroyDeoxysRockEffectFuncs[tState](data, taskId); } -void sub_80B9C28(s16* data, u8 taskId) +static void DestroyDeoxysRockEffect_CameraShake(s16* data, u8 taskId) { - u8 newTaskId = CreateTask(sub_80B9B3C, 0x5A); + u8 newTaskId = CreateTask(Task_DeoxysRockCameraShake, 90); PlaySE(SE_T_KAMI2); - data[5] = newTaskId; - data[1]++; + tCameraTaskId = newTaskId; + tState++; } -void sub_80B9D24(struct Sprite*); - -void sub_80B9C54(s16* data, u8 taskId) +static void DestroyDeoxysRockEffect_RockFragments(s16* data, u8 taskId) { - if (++data[3] > 0x78) + if (++tTimer > 120) { - struct Sprite *sprite = &gSprites[gObjectEvents[data[2]].spriteId]; - gObjectEvents[data[2]].invisible = TRUE; + struct Sprite *sprite = &gSprites[gObjectEvents[tObjectEventId].spriteId]; + gObjectEvents[tObjectEventId].invisible = TRUE; BlendPalettes(0x0000FFFF, 0x10, RGB_WHITE); BeginNormalPaletteFade(0x0000FFFF, 0, 0x10, 0, RGB_WHITE); - sub_80B9D24(sprite); + CreateDeoxysRockFragments(sprite); PlaySE(SE_T_KAMI); - sub_80B9BD0(data[5]); - data[3] = 0; - data[1]++; + StartEndingDeoxysRockCameraShake(tCameraTaskId); + tTimer = 0; + tState++; } } -void sub_80B9CDC(s16* a0, u8 taskId) +static void DestroyDeoxysRockEffect_WaitAndEnd(s16* data, u8 taskId) { - if (!gPaletteFade.active && !FuncIsActiveTask(sub_80B9B3C)) + if (!gPaletteFade.active && !FuncIsActiveTask(Task_DeoxysRockCameraShake)) { InstallCameraPanAheadCallback(); - RemoveObjectEventByLocalIdAndMap(a0[6], a0[7], a0[8]); - FieldEffectActiveListRemove(0x41); + RemoveObjectEventByLocalIdAndMap(tLocalId, tMapNum, tMapGroup); + FieldEffectActiveListRemove(FLDEFF_DESTROY_DEOXYS_ROCK); DestroyTask(taskId); } } -const struct SpriteFrameImage gSpriteImageTable_855C59C[] = { - obj_frame_tiles(gUnknown_0855C170), - obj_frame_tiles(gUnknown_0855C190), - obj_frame_tiles(gUnknown_0855C1B0), - obj_frame_tiles(gUnknown_0855C1D0), +#undef tState +#undef tObjectEventId +#undef tTimer +#undef tCameraTaskId +#undef tLocalId +#undef tMapNum +#undef tMapGroup + +static const struct SpriteFrameImage sImages_DeoxysRockFragment[] = { + obj_frame_tiles(sRockFragment_TopLeft), + obj_frame_tiles(sRockFragment_TopRight), + obj_frame_tiles(sRockFragment_BottomLeft), + obj_frame_tiles(sRockFragment_BottomRight), }; -const union AnimCmd gSpriteAnim_855C5BC[] = { +static const union AnimCmd sAnim_RockFragment_TopLeft[] = { ANIMCMD_FRAME(.imageValue = 0), ANIMCMD_END }; -const union AnimCmd gSpriteAnim_855C5C4[] = { +static const union AnimCmd sAnim_RockFragment_TopRight[] = { ANIMCMD_FRAME(.imageValue = 1), ANIMCMD_END }; -const union AnimCmd gSpriteAnim_855C5CC[] = { +static const union AnimCmd sAnim_RockFragment_BottomLeft[] = { ANIMCMD_FRAME(.imageValue = 2), ANIMCMD_END }; -const union AnimCmd gSpriteAnim_855C5D4[] = { +static const union AnimCmd sAnim_RockFragment_BottomRight[] = { ANIMCMD_FRAME(.imageValue = 3), ANIMCMD_END }; -const union AnimCmd *const gSpriteAnimTable_855C5DC[] = { - gSpriteAnim_855C5BC, - gSpriteAnim_855C5C4, - gSpriteAnim_855C5CC, - gSpriteAnim_855C5D4, +static const union AnimCmd *const sAnims_DeoxysRockFragment[] = { + sAnim_RockFragment_TopLeft, + sAnim_RockFragment_TopRight, + sAnim_RockFragment_BottomLeft, + sAnim_RockFragment_BottomRight, }; -const struct SpriteTemplate gUnknown_0855C5EC = { +static const struct SpriteTemplate sSpriteTemplate_DeoxysRockFragment = { .tileTag = 0xFFFF, .paletteTag = 4378, - .oam = &gOamData_855C218, - .anims = gSpriteAnimTable_855C5DC, - .images = gSpriteImageTable_855C59C, + .oam = &sOam_8x8, + .anims = sAnims_DeoxysRockFragment, + .images = sImages_DeoxysRockFragment, .affineAnims = gDummySpriteAffineAnimTable, - .callback = sub_80B9DB8 + .callback = SpriteCB_DeoxysRockFragment }; -void sub_80B9D24(struct Sprite* sprite) +static void CreateDeoxysRockFragments(struct Sprite* sprite) { int i; int xPos = (s16)gTotalCameraPixelOffsetX + sprite->pos1.x + sprite->pos2.x; @@ -3623,7 +3784,7 @@ void sub_80B9D24(struct Sprite* sprite) for (i = 0; i < 4; i++) { - u8 spriteId = CreateSprite(&gUnknown_0855C5EC, xPos, yPos, 0); + u8 spriteId = CreateSprite(&sSpriteTemplate_DeoxysRockFragment, xPos, yPos, 0); if (spriteId != MAX_SPRITES) { StartSpriteAnim(&gSprites[spriteId], i); @@ -3633,8 +3794,9 @@ void sub_80B9D24(struct Sprite* sprite) } } -static void sub_80B9DB8(struct Sprite* sprite) +static void SpriteCB_DeoxysRockFragment(struct Sprite* sprite) { + // 1 case for each fragment, fly off in 4 different directions switch (sprite->data[0]) { case 0: @@ -3654,11 +3816,11 @@ static void sub_80B9DB8(struct Sprite* sprite) sprite->pos1.y += 12; break; } - if ((u16)(sprite->pos1.x + 4) > 0xF8 || sprite->pos1.y < -4 || sprite->pos1.y > 0xA4) + if ((u16)(sprite->pos1.x + 4) > DISPLAY_WIDTH + 8 || sprite->pos1.y < -4 || sprite->pos1.y > DISPLAY_HEIGHT + 4) DestroySprite(sprite); } -bool8 Fldeff_MoveDeoxysRock(struct Sprite* sprite) +bool8 FldEff_MoveDeoxysRock(struct Sprite* sprite) { u8 objectEventIdBuffer; if (!TryGetObjectEventIdByLocalIdAndMap(gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2], &objectEventIdBuffer)) @@ -3672,7 +3834,7 @@ bool8 Fldeff_MoveDeoxysRock(struct Sprite* sprite) xPos = (gFieldEffectArguments[3] - xPos) * 16; yPos = (gFieldEffectArguments[4] - yPos) * 16; ShiftObjectEventCoords(object, gFieldEffectArguments[3] + 7, gFieldEffectArguments[4] + 7); - taskId = CreateTask(Fldeff_MoveDeoxysRock_Step, 0x50); + taskId = CreateTask(Task_MoveDeoxysRock, 80); gTasks[taskId].data[1] = object->spriteId; gTasks[taskId].data[2] = gSprites[object->spriteId].pos1.x + xPos; gTasks[taskId].data[3] = gSprites[object->spriteId].pos1.y + yPos; @@ -3682,7 +3844,7 @@ bool8 Fldeff_MoveDeoxysRock(struct Sprite* sprite) return FALSE; } -static void Fldeff_MoveDeoxysRock_Step(u8 taskId) +static void Task_MoveDeoxysRock(u8 taskId) { // BUG: Possible divide by zero s16 *data = gTasks[taskId].data; @@ -3711,7 +3873,7 @@ static void Fldeff_MoveDeoxysRock_Step(u8 taskId) sprite->pos1.y = data[3]; ShiftStillObjectEventCoords(object); object->triggerGroundEffectsOnStop = TRUE; - FieldEffectActiveListRemove(0x42); + FieldEffectActiveListRemove(FLDEFF_MOVE_DEOXYS_ROCK); DestroyTask(taskId); } break; |