pokeemerald/src/battle_transition.c

4776 lines
135 KiB
C
Raw Normal View History

2018-01-01 17:41:34 +01:00
#include "global.h"
#include "battle.h"
2018-01-01 17:41:34 +01:00
#include "battle_transition.h"
2020-07-02 21:45:37 +02:00
#include "battle_transition_frontier.h"
2018-11-13 15:19:04 +01:00
#include "bg.h"
#include "decompress.h"
2018-12-24 00:02:29 +01:00
#include "event_object_movement.h"
2018-11-13 15:19:04 +01:00
#include "field_camera.h"
#include "field_effect.h"
2018-12-24 00:02:29 +01:00
#include "field_weather.h"
2018-11-13 15:19:04 +01:00
#include "gpu_regs.h"
2018-01-01 17:41:34 +01:00
#include "main.h"
#include "malloc.h"
2018-01-01 17:41:34 +01:00
#include "overworld.h"
#include "palette.h"
#include "random.h"
2018-11-13 15:19:04 +01:00
#include "scanline_effect.h"
2018-01-01 17:41:34 +01:00
#include "sound.h"
2018-11-13 15:19:04 +01:00
#include "sprite.h"
#include "task.h"
#include "trig.h"
#include "util.h"
#include "constants/field_effects.h"
2018-01-01 17:41:34 +01:00
#include "constants/songs.h"
#include "constants/trainers.h"
2019-04-04 23:05:46 +02:00
#include "constants/rgb.h"
2018-01-01 17:41:34 +01:00
2021-10-25 16:42:08 +02:00
#define PALTAG_UNUSED_MUGSHOT 0x100A
#define B_TRANS_DMA_FLAGS (1 | ((DMA_SRC_INC | DMA_DEST_FIXED | DMA_REPEAT | DMA_16BIT | DMA_START_HBLANK | DMA_ENABLE) << 16))
2021-10-27 22:17:27 +02:00
// Used by each transition task to determine which of its functions to call
#define tState data[0]
// Below are data defines for InitBlackWipe and UpdateBlackWipe, for the TransitionData data array.
// These will be re-used by any transitions that use these functions.
#define tWipeStartX data[0]
#define tWipeStartY data[1]
#define tWipeCurrX data[2]
#define tWipeCurrY data[3]
#define tWipeEndX data[4]
#define tWipeEndY data[5]
#define tWipeXMove data[6]
#define tWipeYMove data[7]
#define tWipeXDist data[8]
#define tWipeYDist data[9]
#define tWipeTemp data[10]
#define SET_TILE(ptr, posY, posX, tile) \
{ \
u32 index = (posY) * 32 + posX; \
ptr[index] = tile | (0xF0 << 8); \
2021-10-25 16:42:08 +02:00
}
2018-01-01 17:41:34 +01:00
struct TransitionData
{
2018-01-16 21:37:46 +01:00
vu8 VBlank_DMA;
2018-01-01 17:41:34 +01:00
u16 WININ;
u16 WINOUT;
2018-01-16 21:37:46 +01:00
u16 WIN0H;
2018-01-01 17:41:34 +01:00
u16 WIN0V;
2021-10-25 16:42:08 +02:00
u16 unused1;
u16 unused2;
2018-01-01 17:41:34 +01:00
u16 BLDCNT;
u16 BLDALPHA;
u16 BLDY;
2021-10-25 16:42:08 +02:00
s16 cameraX;
s16 cameraY;
s16 BG0HOFS_Lower;
s16 BG0HOFS_Upper;
2018-01-16 21:37:46 +01:00
s16 BG0VOFS; // used but not set
2021-10-25 16:42:08 +02:00
s16 unused3;
2021-10-27 22:17:27 +02:00
s16 counter;
2021-10-25 16:42:08 +02:00
s16 unused4;
2018-01-01 17:41:34 +01:00
s16 data[11];
};
2021-10-27 22:17:27 +02:00
struct RectangularSpiralLine
2018-01-13 21:03:07 +01:00
{
2021-10-27 22:17:27 +02:00
u8 state;
s16 position;
u8 moveIdx;
2021-10-29 17:56:06 +02:00
s16 reboundPosition;
bool8 outward;
2018-01-13 21:03:07 +01:00
};
2018-01-02 20:38:33 +01:00
typedef bool8 (*TransitionStateFunc)(struct Task *task);
2018-01-01 17:41:34 +01:00
typedef bool8 (*TransitionSpriteCallback)(struct Sprite *sprite);
2021-10-30 00:43:27 +02:00
static bool8 Transition_StartIntro(struct Task *);
static bool8 Transition_WaitForIntro(struct Task *);
static bool8 Transition_StartMain(struct Task *);
static bool8 Transition_WaitForMain(struct Task *);
static void LaunchBattleTransitionTask(u8);
static void Task_BattleTransition(u8);
static void Task_Intro(u8);
static void Task_Blur(u8);
static void Task_Swirl(u8);
static void Task_Shuffle(u8);
static void Task_BigPokeball(u8);
static void Task_PokeballsTrail(u8);
static void Task_ClockwiseWipe(u8);
static void Task_Ripple(u8);
static void Task_Wave(u8);
static void Task_Slice(u8);
static void Task_WhiteBarsFade(u8);
static void Task_GridSquares(u8);
static void Task_AngledWipes(u8);
static void Task_Sidney(u8);
static void Task_Phoebe(u8);
static void Task_Glacia(u8);
static void Task_Drake(u8);
static void Task_Champion(u8);
static void Task_Aqua(u8);
static void Task_Magma(u8);
static void Task_Regice(u8);
static void Task_Registeel(u8);
static void Task_Regirock(u8);
static void Task_Kyogre(u8);
static void Task_Groudon(u8);
static void Task_Rayquaza(u8);
static void Task_ShredSplit(u8);
static void Task_Blackhole(u8);
static void Task_BlackholePulsate(u8);
static void Task_RectangularSpiral(u8);
static void Task_FrontierLogoWiggle(u8);
static void Task_FrontierLogoWave(u8);
static void Task_FrontierSquares(u8);
static void Task_FrontierSquaresScroll(u8);
static void Task_FrontierSquaresSpiral(u8);
2018-01-14 22:09:35 +01:00
static void VBlankCB_BattleTransition(void);
static void VBlankCB_Swirl(void);
static void HBlankCB_Swirl(void);
static void VBlankCB_Shuffle(void);
static void HBlankCB_Shuffle(void);
2021-10-25 16:42:08 +02:00
static void VBlankCB_PatternWeave(void);
2021-10-27 22:17:27 +02:00
static void VBlankCB_CircularMask(void);
static void VBlankCB_ClockwiseWipe(void);
static void VBlankCB_Ripple(void);
static void HBlankCB_Ripple(void);
2021-10-25 16:42:08 +02:00
static void VBlankCB_FrontierLogoWave(void);
static void HBlankCB_FrontierLogoWave(void);
static void VBlankCB_Wave(void);
static void VBlankCB_Slice(void);
static void HBlankCB_Slice(void);
2021-10-27 22:17:27 +02:00
static void VBlankCB_WhiteBarsFade(void);
static void VBlankCB_WhiteBarsFade_Blend(void);
static void HBlankCB_WhiteBarsFade(void);
static void VBlankCB_AngledWipes(void);
static void VBlankCB_Rayquaza(void);
2021-10-30 00:43:27 +02:00
static bool8 Blur_Init(struct Task *);
static bool8 Blur_Main(struct Task *);
static bool8 Blur_End(struct Task *);
static bool8 Swirl_Init(struct Task *);
static bool8 Swirl_End(struct Task *);
static bool8 Shuffle_Init(struct Task *);
static bool8 Shuffle_End(struct Task *);
static bool8 Aqua_Init(struct Task *);
static bool8 Aqua_SetGfx(struct Task *);
static bool8 Magma_Init(struct Task *);
static bool8 Magma_SetGfx(struct Task *);
static bool8 FramesCountdown(struct Task *);
static bool8 Regi_Init(struct Task *);
static bool8 Regice_SetGfx(struct Task *);
static bool8 Registeel_SetGfx(struct Task *);
static bool8 Regirock_SetGfx(struct Task *);
static bool8 WeatherTrio_BgFadeBlack(struct Task *);
static bool8 WeatherTrio_WaitFade(struct Task *);
static bool8 Kyogre_Init(struct Task *);
static bool8 Kyogre_PaletteFlash(struct Task *);
static bool8 Kyogre_PaletteBrighten(struct Task *);
static bool8 Groudon_Init(struct Task *);
static bool8 Groudon_PaletteFlash(struct Task *);
static bool8 Groudon_PaletteBrighten(struct Task *);
static bool8 WeatherDuo_FadeOut(struct Task *);
static bool8 WeatherDuo_End(struct Task *);
static bool8 BigPokeball_Init(struct Task *);
static bool8 BigPokeball_SetGfx(struct Task *);
static bool8 PatternWeave_Blend1(struct Task *);
static bool8 PatternWeave_Blend2(struct Task *);
static bool8 PatternWeave_FinishAppear(struct Task *);
static bool8 PatternWeave_CircularMask(struct Task *);
static bool8 PokeballsTrail_Init(struct Task *);
static bool8 PokeballsTrail_Main(struct Task *);
static bool8 PokeballsTrail_End(struct Task *);
static bool8 ClockwiseWipe_Init(struct Task *);
static bool8 ClockwiseWipe_TopRight(struct Task *);
static bool8 ClockwiseWipe_Right(struct Task *);
static bool8 ClockwiseWipe_Bottom(struct Task *);
static bool8 ClockwiseWipe_Left(struct Task *);
static bool8 ClockwiseWipe_TopLeft(struct Task *);
static bool8 ClockwiseWipe_End(struct Task *);
static bool8 Ripple_Init(struct Task *);
static bool8 Ripple_Main(struct Task *);
static bool8 Wave_Init(struct Task *);
static bool8 Wave_Main(struct Task *);
static bool8 Wave_End(struct Task *);
static bool8 Slice_Init(struct Task *);
static bool8 Slice_Main(struct Task *);
static bool8 Slice_End(struct Task *);
static bool8 WhiteBarsFade_Init(struct Task *);
static bool8 WhiteBarsFade_StartBars(struct Task *);
static bool8 WhiteBarsFade_WaitBars(struct Task *);
static bool8 WhiteBarsFade_BlendToBlack(struct Task *);
static bool8 WhiteBarsFade_End(struct Task *);
static bool8 GridSquares_Init(struct Task *);
static bool8 GridSquares_Main(struct Task *);
static bool8 GridSquares_End(struct Task *);
static bool8 AngledWipes_Init(struct Task *);
static bool8 AngledWipes_SetWipeData(struct Task *);
static bool8 AngledWipes_DoWipe(struct Task *);
static bool8 AngledWipes_TryEnd(struct Task *);
static bool8 AngledWipes_StartNext(struct Task *);
static bool8 ShredSplit_Init(struct Task *);
static bool8 ShredSplit_Main(struct Task *);
static bool8 ShredSplit_BrokenCheck(struct Task *);
static bool8 ShredSplit_End(struct Task *);
static bool8 Blackhole_Init(struct Task *);
static bool8 Blackhole_Vibrate(struct Task *);
static bool8 Blackhole_GrowEnd(struct Task *);
static bool8 BlackholePulsate_Main(struct Task *);
static bool8 RectangularSpiral_Init(struct Task *);
static bool8 RectangularSpiral_Main(struct Task *);
static bool8 RectangularSpiral_End(struct Task *);
static bool8 FrontierLogoWiggle_Init(struct Task *);
static bool8 FrontierLogoWiggle_SetGfx(struct Task *);
static bool8 FrontierLogoWave_Init(struct Task *);
static bool8 FrontierLogoWave_SetGfx(struct Task *);
static bool8 FrontierLogoWave_InitScanline(struct Task *);
static bool8 FrontierLogoWave_Main(struct Task *);
static bool8 Rayquaza_Init(struct Task *);
static bool8 Rayquaza_SetGfx(struct Task *);
static bool8 Rayquaza_PaletteFlash(struct Task *);
static bool8 Rayquaza_FadeToBlack(struct Task *);
static bool8 Rayquaza_WaitFade(struct Task *);
static bool8 Rayquaza_SetBlack(struct Task *);
static bool8 Rayquaza_TriRing(struct Task *);
static bool8 FrontierSquares_Init(struct Task *);
static bool8 FrontierSquares_Draw(struct Task *);
static bool8 FrontierSquares_Shrink(struct Task *);
static bool8 FrontierSquares_End(struct Task *);
static bool8 FrontierSquaresSpiral_Init(struct Task *);
static bool8 FrontierSquaresSpiral_Outward(struct Task *);
static bool8 FrontierSquaresSpiral_SetBlack(struct Task *);
static bool8 FrontierSquaresSpiral_Inward(struct Task *);
static bool8 FrontierSquaresScroll_Init(struct Task *);
static bool8 FrontierSquaresScroll_Draw(struct Task *);
static bool8 FrontierSquaresScroll_SetBlack(struct Task *);
static bool8 FrontierSquaresScroll_Erase(struct Task *);
static bool8 FrontierSquaresScroll_End(struct Task *);
static bool8 Mugshot_Init(struct Task *);
static bool8 Mugshot_SetGfx(struct Task *);
static bool8 Mugshot_ShowBanner(struct Task *);
static bool8 Mugshot_StartOpponentSlide(struct Task *);
static bool8 Mugshot_WaitStartPlayerSlide(struct Task *);
static bool8 Mugshot_WaitPlayerSlide(struct Task *);
static bool8 Mugshot_GradualWhiteFade(struct Task *);
static bool8 Mugshot_InitFadeWhiteToBlack(struct Task *);
static bool8 Mugshot_FadeToBlack(struct Task *);
static bool8 Mugshot_End(struct Task *);
static void DoMugshotTransition(u8);
static void Mugshots_CreateTrainerPics(struct Task *);
2021-10-27 22:17:27 +02:00
static void VBlankCB_Mugshots(void);
static void VBlankCB_MugshotsFadeOut(void);
static void HBlankCB_Mugshots(void);
2021-10-25 16:42:08 +02:00
static void InitTransitionData(void);
2020-06-01 16:17:25 +02:00
static void FadeScreenBlack(void);
2021-10-30 00:43:27 +02:00
static void CreateIntroTask(s16, s16, s16, s16, s16);
static void SetCircularMask(u16 *, s16, s16, s16);
static void SetSinWave(s16 *, s16, s16, s16, s16, s16);
static void GetBg0TilemapDst(u16 **);
static void InitBlackWipe(s16 *, s16, s16, s16, s16, s16, s16);
static bool8 UpdateBlackWipe(s16 *, bool8, bool8);
static void SetTrainerPicSlideDirection(s16, s16);
static void IncrementTrainerPicState(s16);
static s16 IsTrainerPicSlideDone(s16);
static bool8 TransitionIntro_FadeToGray(struct Task *);
static bool8 TransitionIntro_FadeFromGray(struct Task *);
static bool8 IsIntroTaskDone(void);
2021-10-30 00:43:27 +02:00
static bool16 UpdateRectangularSpiralLine(const s16 * const *, struct RectangularSpiralLine *);
static void SpriteCB_FldEffPokeballTrail(struct Sprite *);
static void SpriteCB_MugshotTrainerPic(struct Sprite *);
static void SpriteCB_WhiteBarFade(struct Sprite *);
static bool8 MugshotTrainerPic_Pause(struct Sprite *);
static bool8 MugshotTrainerPic_Init(struct Sprite *);
static bool8 MugshotTrainerPic_Slide(struct Sprite *);
static bool8 MugshotTrainerPic_SlideSlow(struct Sprite *);
static bool8 MugshotTrainerPic_SlideOffscreen(struct Sprite *);
2021-10-27 22:17:27 +02:00
static s16 sDebug_RectangularSpiralData;
static u8 sTestingTransitionId;
static u8 sTestingTransitionState;
2021-10-27 22:17:27 +02:00
static struct RectangularSpiralLine sRectangularSpiralLines[4];
2018-01-01 17:41:34 +01:00
2021-10-25 16:42:08 +02:00
EWRAM_DATA static struct TransitionData *sTransitionData = NULL;
2018-01-01 17:41:34 +01:00
2018-01-14 22:09:35 +01:00
static const u32 sBigPokeball_Tileset[] = INCBIN_U32("graphics/battle_transitions/big_pokeball.4bpp");
static const u32 sPokeballTrail_Tileset[] = INCBIN_U32("graphics/battle_transitions/pokeball_trail.4bpp");
2020-06-01 16:17:25 +02:00
static const u8 sPokeball_Gfx[] = INCBIN_U8("graphics/battle_transitions/pokeball.4bpp");
static const u32 sEliteFour_Tileset[] = INCBIN_U32("graphics/battle_transitions/elite_four_bg.4bpp");
static const u8 sUnusedBrendan_Gfx[] = INCBIN_U8("graphics/battle_transitions/unused_brendan.4bpp");
static const u8 sUnusedLass_Gfx[] = INCBIN_U8("graphics/battle_transitions/unused_lass.4bpp");
2018-01-14 22:09:35 +01:00
static const u32 sShrinkingBoxTileset[] = INCBIN_U32("graphics/battle_transitions/shrinking_box.4bpp");
2020-06-02 13:30:05 +02:00
static const u16 sEvilTeam_Palette[] = INCBIN_U16("graphics/battle_transitions/evil_team.gbapal");
2018-01-14 22:09:35 +01:00
static const u32 sTeamAqua_Tileset[] = INCBIN_U32("graphics/battle_transitions/team_aqua.4bpp.lz");
static const u32 sTeamAqua_Tilemap[] = INCBIN_U32("graphics/battle_transitions/team_aqua.bin.lz");
static const u32 sTeamMagma_Tileset[] = INCBIN_U32("graphics/battle_transitions/team_magma.4bpp.lz");
static const u32 sTeamMagma_Tilemap[] = INCBIN_U32("graphics/battle_transitions/team_magma.bin.lz");
2020-06-01 16:17:25 +02:00
static const u32 sRegis_Tileset[] = INCBIN_U32("graphics/battle_transitions/regis.4bpp");
2020-06-02 13:30:05 +02:00
static const u16 sRegice_Palette[] = INCBIN_U16("graphics/battle_transitions/regice.gbapal");
static const u16 sRegisteel_Palette[] = INCBIN_U16("graphics/battle_transitions/registeel.gbapal");
static const u16 sRegirock_Palette[] = INCBIN_U16("graphics/battle_transitions/regirock.gbapal");
2020-06-01 16:17:25 +02:00
static const u32 sRegice_Tilemap[] = INCBIN_U32("graphics/battle_transitions/regice.bin");
static const u32 sRegisteel_Tilemap[] = INCBIN_U32("graphics/battle_transitions/registeel.bin");
static const u32 sRegirock_Tilemap[] = INCBIN_U32("graphics/battle_transitions/regirock.bin");
2021-10-27 22:17:27 +02:00
static const u16 sUnused_Palette[] = INCBIN_U16("graphics/battle_transitions/unused.gbapal");
2020-06-01 16:17:25 +02:00
static const u32 sKyogre_Tileset[] = INCBIN_U32("graphics/battle_transitions/kyogre.4bpp.lz");
static const u32 sKyogre_Tilemap[] = INCBIN_U32("graphics/battle_transitions/kyogre.bin.lz");
static const u32 sGroudon_Tileset[] = INCBIN_U32("graphics/battle_transitions/groudon.4bpp.lz");
static const u32 sGroudon_Tilemap[] = INCBIN_U32("graphics/battle_transitions/groudon.bin.lz");
static const u16 sKyogre1_Palette[] = INCBIN_U16("graphics/battle_transitions/kyogre_pt1.gbapal");
static const u16 sKyogre2_Palette[] = INCBIN_U16("graphics/battle_transitions/kyogre_pt2.gbapal");
static const u16 sGroudon1_Palette[] = INCBIN_U16("graphics/battle_transitions/groudon_pt1.gbapal");
static const u16 sGroudon2_Palette[] = INCBIN_U16("graphics/battle_transitions/groudon_pt2.gbapal");
static const u16 sRayquaza_Palette[] = INCBIN_U16("graphics/battle_transitions/rayquaza.gbapal");
static const u32 sRayquaza_Tileset[] = INCBIN_U32("graphics/battle_transitions/rayquaza.4bpp");
static const u32 sRayquaza_Tilemap[] = INCBIN_U32("graphics/battle_transitions/rayquaza.bin");
2020-07-02 21:45:37 +02:00
static const u16 sFrontierLogo_Palette[] = INCBIN_U16("graphics/battle_transitions/frontier_logo.gbapal");
static const u32 sFrontierLogo_Tileset[] = INCBIN_U32("graphics/battle_transitions/frontier_logo.4bpp.lz");
static const u32 sFrontierLogo_Tilemap[] = INCBIN_U32("graphics/battle_transitions/frontier_logo.bin.lz");
static const u16 sFrontierSquares_Palette[] = INCBIN_U16("graphics/battle_transitions/frontier_squares_blanktiles.gbapal");
static const u32 sFrontierSquares_FilledBg_Tileset[] = INCBIN_U32("graphics/battle_transitions/frontier_square_1.4bpp.lz");
static const u32 sFrontierSquares_EmptyBg_Tileset[] = INCBIN_U32("graphics/battle_transitions/frontier_square_2.4bpp.lz");
static const u32 sFrontierSquares_Shrink1_Tileset[] = INCBIN_U32("graphics/battle_transitions/frontier_square_3.4bpp.lz");
static const u32 sFrontierSquares_Shrink2_Tileset[] = INCBIN_U32("graphics/battle_transitions/frontier_square_4.4bpp.lz");
static const u32 sFrontierSquares_Tilemap[] = INCBIN_U32("graphics/battle_transitions/frontier_squares.bin");
2018-01-14 22:09:35 +01:00
// All battle transitions use the same intro
static const TaskFunc sTasks_Intro[B_TRANSITION_COUNT] =
2018-01-01 17:41:34 +01:00
{
[0 ... B_TRANSITION_COUNT - 1] = &Task_Intro
2018-01-01 17:41:34 +01:00
};
2021-10-25 16:42:08 +02:00
// After the intro each transition has a unique main task.
// This task will call the functions that do the transition effects.
static const TaskFunc sTasks_Main[B_TRANSITION_COUNT] =
{
[B_TRANSITION_BLUR] = Task_Blur,
[B_TRANSITION_SWIRL] = Task_Swirl,
[B_TRANSITION_SHUFFLE] = Task_Shuffle,
[B_TRANSITION_BIG_POKEBALL] = Task_BigPokeball,
[B_TRANSITION_POKEBALLS_TRAIL] = Task_PokeballsTrail,
2021-10-27 22:17:27 +02:00
[B_TRANSITION_CLOCKWISE_WIPE] = Task_ClockwiseWipe,
[B_TRANSITION_RIPPLE] = Task_Ripple,
[B_TRANSITION_WAVE] = Task_Wave,
[B_TRANSITION_SLICE] = Task_Slice,
2021-10-27 22:17:27 +02:00
[B_TRANSITION_WHITE_BARS_FADE] = Task_WhiteBarsFade,
[B_TRANSITION_GRID_SQUARES] = Task_GridSquares,
2021-10-27 22:17:27 +02:00
[B_TRANSITION_ANGLED_WIPES] = Task_AngledWipes,
[B_TRANSITION_SIDNEY] = Task_Sidney,
[B_TRANSITION_PHOEBE] = Task_Phoebe,
[B_TRANSITION_GLACIA] = Task_Glacia,
[B_TRANSITION_DRAKE] = Task_Drake,
[B_TRANSITION_CHAMPION] = Task_Champion,
[B_TRANSITION_AQUA] = Task_Aqua,
[B_TRANSITION_MAGMA] = Task_Magma,
[B_TRANSITION_REGICE] = Task_Regice,
[B_TRANSITION_REGISTEEL] = Task_Registeel,
[B_TRANSITION_REGIROCK] = Task_Regirock,
[B_TRANSITION_KYOGRE] = Task_Kyogre,
[B_TRANSITION_GROUDON] = Task_Groudon,
[B_TRANSITION_RAYQUAZA] = Task_Rayquaza,
[B_TRANSITION_SHRED_SPLIT] = Task_ShredSplit,
2021-10-27 22:17:27 +02:00
[B_TRANSITION_BLACKHOLE] = Task_Blackhole,
[B_TRANSITION_BLACKHOLE_PULSATE] = Task_BlackholePulsate,
[B_TRANSITION_RECTANGULAR_SPIRAL] = Task_RectangularSpiral,
[B_TRANSITION_FRONTIER_LOGO_WIGGLE] = Task_FrontierLogoWiggle,
[B_TRANSITION_FRONTIER_LOGO_WAVE] = Task_FrontierLogoWave,
[B_TRANSITION_FRONTIER_SQUARES] = Task_FrontierSquares,
[B_TRANSITION_FRONTIER_SQUARES_SCROLL] = Task_FrontierSquaresScroll,
[B_TRANSITION_FRONTIER_SQUARES_SPIRAL] = Task_FrontierSquaresSpiral,
[B_TRANSITION_FRONTIER_CIRCLES_MEET] = Task_FrontierCirclesMeet,
[B_TRANSITION_FRONTIER_CIRCLES_CROSS] = Task_FrontierCirclesCross,
[B_TRANSITION_FRONTIER_CIRCLES_ASYMMETRIC_SPIRAL] = Task_FrontierCirclesAsymmetricSpiral,
[B_TRANSITION_FRONTIER_CIRCLES_SYMMETRIC_SPIRAL] = Task_FrontierCirclesSymmetricSpiral,
[B_TRANSITION_FRONTIER_CIRCLES_MEET_IN_SEQ] = Task_FrontierCirclesMeetInSeq,
[B_TRANSITION_FRONTIER_CIRCLES_CROSS_IN_SEQ] = Task_FrontierCirclesCrossInSeq,
[B_TRANSITION_FRONTIER_CIRCLES_ASYMMETRIC_SPIRAL_IN_SEQ] = Task_FrontierCirclesAsymmetricSpiralInSeq,
[B_TRANSITION_FRONTIER_CIRCLES_SYMMETRIC_SPIRAL_IN_SEQ] = Task_FrontierCirclesSymmetricSpiralInSeq,
2018-01-01 17:41:34 +01:00
};
static const TransitionStateFunc sTaskHandlers[] =
2018-01-01 17:41:34 +01:00
{
&Transition_StartIntro,
&Transition_WaitForIntro,
&Transition_StartMain,
&Transition_WaitForMain
2018-01-01 17:41:34 +01:00
};
static const TransitionStateFunc sBlur_Funcs[] =
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
Blur_Init,
Blur_Main,
Blur_End
2018-01-02 20:38:33 +01:00
};
static const TransitionStateFunc sSwirl_Funcs[] =
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
Swirl_Init,
Swirl_End,
2018-01-02 20:38:33 +01:00
};
static const TransitionStateFunc sShuffle_Funcs[] =
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
Shuffle_Init,
Shuffle_End,
2018-01-02 20:38:33 +01:00
};
static const TransitionStateFunc sAqua_Funcs[] =
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
Aqua_Init,
Aqua_SetGfx,
2021-10-27 22:17:27 +02:00
PatternWeave_Blend1,
PatternWeave_Blend2,
PatternWeave_FinishAppear,
FramesCountdown,
2021-10-27 22:17:27 +02:00
PatternWeave_CircularMask
2018-01-02 20:38:33 +01:00
};
static const TransitionStateFunc sMagma_Funcs[] =
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
Magma_Init,
Magma_SetGfx,
2021-10-27 22:17:27 +02:00
PatternWeave_Blend1,
PatternWeave_Blend2,
PatternWeave_FinishAppear,
FramesCountdown,
2021-10-27 22:17:27 +02:00
PatternWeave_CircularMask
2018-01-02 20:38:33 +01:00
};
static const TransitionStateFunc sBigPokeball_Funcs[] =
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
BigPokeball_Init,
BigPokeball_SetGfx,
2021-10-27 22:17:27 +02:00
PatternWeave_Blend1,
PatternWeave_Blend2,
PatternWeave_FinishAppear,
PatternWeave_CircularMask
2018-01-02 20:38:33 +01:00
};
static const TransitionStateFunc sRegice_Funcs[] =
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
Regi_Init,
Regice_SetGfx,
2021-10-27 22:17:27 +02:00
PatternWeave_Blend1,
PatternWeave_Blend2,
PatternWeave_FinishAppear,
PatternWeave_CircularMask
2018-01-02 20:38:33 +01:00
};
static const TransitionStateFunc sRegisteel_Funcs[] =
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
Regi_Init,
Registeel_SetGfx,
2021-10-27 22:17:27 +02:00
PatternWeave_Blend1,
PatternWeave_Blend2,
PatternWeave_FinishAppear,
PatternWeave_CircularMask
2018-01-02 20:38:33 +01:00
};
static const TransitionStateFunc sRegirock_Funcs[] =
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
Regi_Init,
Regirock_SetGfx,
2021-10-27 22:17:27 +02:00
PatternWeave_Blend1,
PatternWeave_Blend2,
PatternWeave_FinishAppear,
PatternWeave_CircularMask
2018-01-02 20:38:33 +01:00
};
static const TransitionStateFunc sKyogre_Funcs[] =
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
WeatherTrio_BgFadeBlack,
WeatherTrio_WaitFade,
Kyogre_Init,
2021-10-27 22:17:27 +02:00
Kyogre_PaletteFlash,
2021-10-25 16:42:08 +02:00
Kyogre_PaletteBrighten,
FramesCountdown,
2021-10-25 16:42:08 +02:00
WeatherDuo_FadeOut,
WeatherDuo_End
2018-01-02 20:38:33 +01:00
};
static const TransitionStateFunc sPokeballsTrail_Funcs[] =
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
PokeballsTrail_Init,
PokeballsTrail_Main,
PokeballsTrail_End
2018-01-02 20:38:33 +01:00
};
2021-10-27 22:17:27 +02:00
#define NUM_POKEBALL_TRAILS 5
static const s16 sPokeballsTrail_StartXCoords[2] = { -16, DISPLAY_WIDTH + 16 };
static const s16 sPokeballsTrail_Delays[NUM_POKEBALL_TRAILS] = {0, 32, 64, 18, 48};
static const s16 sPokeballsTrail_Speeds[2] = {8, -8};
2018-01-02 20:38:33 +01:00
2021-10-27 22:17:27 +02:00
static const TransitionStateFunc sClockwiseWipe_Funcs[] =
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
ClockwiseWipe_Init,
ClockwiseWipe_TopRight,
ClockwiseWipe_Right,
ClockwiseWipe_Bottom,
ClockwiseWipe_Left,
ClockwiseWipe_TopLeft,
ClockwiseWipe_End
2018-01-02 20:38:33 +01:00
};
static const TransitionStateFunc sRipple_Funcs[] =
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
Ripple_Init,
2021-10-27 22:17:27 +02:00
Ripple_Main
2018-01-02 20:38:33 +01:00
};
static const TransitionStateFunc sWave_Funcs[] =
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
Wave_Init,
2021-10-27 22:17:27 +02:00
Wave_Main,
2021-10-25 16:42:08 +02:00
Wave_End
2018-01-02 20:38:33 +01:00
};
static const TransitionStateFunc sMugshot_Funcs[] =
{
2021-10-25 16:42:08 +02:00
Mugshot_Init,
Mugshot_SetGfx,
Mugshot_ShowBanner,
Mugshot_StartOpponentSlide,
Mugshot_WaitStartPlayerSlide,
Mugshot_WaitPlayerSlide,
Mugshot_GradualWhiteFade,
Mugshot_InitFadeWhiteToBlack,
Mugshot_FadeToBlack,
Mugshot_End
2018-01-02 20:38:33 +01:00
};
2018-01-14 22:09:35 +01:00
static const u8 sMugshotsTrainerPicIDsTable[MUGSHOTS_COUNT] =
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
[MUGSHOT_SIDNEY] = TRAINER_PIC_ELITE_FOUR_SIDNEY,
[MUGSHOT_PHOEBE] = TRAINER_PIC_ELITE_FOUR_PHOEBE,
[MUGSHOT_GLACIA] = TRAINER_PIC_ELITE_FOUR_GLACIA,
[MUGSHOT_DRAKE] = TRAINER_PIC_ELITE_FOUR_DRAKE,
[MUGSHOT_CHAMPION] = TRAINER_PIC_CHAMPION_WALLACE,
2018-01-02 20:38:33 +01:00
};
2018-01-14 22:09:35 +01:00
static const s16 sMugshotsOpponentRotationScales[MUGSHOTS_COUNT][2] =
2018-01-02 20:38:33 +01:00
{
[MUGSHOT_SIDNEY] = {0x200, 0x200},
[MUGSHOT_PHOEBE] = {0x200, 0x200},
[MUGSHOT_GLACIA] = {0x1B0, 0x1B0},
[MUGSHOT_DRAKE] = {0x1A0, 0x1A0},
[MUGSHOT_CHAMPION] = {0x188, 0x188},
2018-01-02 20:38:33 +01:00
};
2018-01-14 22:09:35 +01:00
static const s16 sMugshotsOpponentCoords[MUGSHOTS_COUNT][2] =
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
[MUGSHOT_SIDNEY] = { 0, 0},
[MUGSHOT_PHOEBE] = { 0, 0},
[MUGSHOT_GLACIA] = {-4, 4},
[MUGSHOT_DRAKE] = { 0, 5},
[MUGSHOT_CHAMPION] = {-8, 7},
2018-01-02 20:38:33 +01:00
};
2021-10-25 16:42:08 +02:00
static const TransitionSpriteCallback sMugshotTrainerPicFuncs[] =
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
MugshotTrainerPic_Pause,
MugshotTrainerPic_Init,
MugshotTrainerPic_Slide,
MugshotTrainerPic_SlideSlow,
MugshotTrainerPic_Pause,
MugshotTrainerPic_SlideOffscreen,
MugshotTrainerPic_Pause
2018-01-02 20:38:33 +01:00
};
2021-10-27 22:17:27 +02:00
// One element per slide direction.
// Sign of acceleration is opposite speed, so slide decelerates.
static const s16 sTrainerPicSlideSpeeds[2] = {12, -12};
static const s16 sTrainerPicSlideAccels[2] = {-1, 1};
2018-01-02 20:38:33 +01:00
static const TransitionStateFunc sSlice_Funcs[] =
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
Slice_Init,
2021-10-27 22:17:27 +02:00
Slice_Main,
2021-10-25 16:42:08 +02:00
Slice_End
2018-01-02 20:38:33 +01:00
};
static const TransitionStateFunc sShredSplit_Funcs[] =
2018-01-13 21:03:07 +01:00
{
2021-10-25 16:42:08 +02:00
ShredSplit_Init,
2021-10-27 22:17:27 +02:00
ShredSplit_Main,
ShredSplit_BrokenCheck,
2021-10-25 16:42:08 +02:00
ShredSplit_End
2018-01-13 21:03:07 +01:00
};
2021-10-27 22:17:27 +02:00
static const u8 sShredSplit_SectionYCoords[] = {39, DISPLAY_HEIGHT - 41};
static const s16 sShredSplit_SectionMoveDirs[] = {1, -1};
2018-01-13 21:03:07 +01:00
2021-10-27 22:17:27 +02:00
static const TransitionStateFunc sBlackhole_Funcs[] =
2018-01-13 21:03:07 +01:00
{
2021-10-25 16:42:08 +02:00
Blackhole_Init,
2021-10-27 22:17:27 +02:00
Blackhole_Vibrate,
Blackhole_GrowEnd
2018-01-13 21:03:07 +01:00
};
2021-10-27 22:17:27 +02:00
static const TransitionStateFunc sBlackholePulsate_Funcs[] =
2018-01-13 21:03:07 +01:00
{
2021-10-25 16:42:08 +02:00
Blackhole_Init,
2021-10-27 22:17:27 +02:00
BlackholePulsate_Main
2018-01-13 21:03:07 +01:00
};
2021-10-27 22:17:27 +02:00
// Blackhole rapidly alternates adding these values to the radius,
// resulting in a vibrating shrink/grow effect.
static const s16 sBlackhole_Vibrations[] = {-6, 4};
2018-01-13 21:03:07 +01:00
static const TransitionStateFunc sRectangularSpiral_Funcs[] =
2018-01-13 21:03:07 +01:00
{
2021-10-25 16:42:08 +02:00
RectangularSpiral_Init,
2021-10-27 22:17:27 +02:00
RectangularSpiral_Main,
2021-10-25 16:42:08 +02:00
RectangularSpiral_End
2018-01-13 21:03:07 +01:00
};
2021-10-27 22:17:27 +02:00
#define SPIRAL_END (-1)
2021-10-29 17:56:06 +02:00
#define SPIRAL_REBOUND (-2)
// Note that the directions are inverted for the lines originating at the bottom.
// i.e. MOVE_RIGHT is a right move for the top lines and a left move for the inverted bottom lines.
enum {
MOVE_RIGHT = 1,
MOVE_LEFT,
MOVE_UP,
MOVE_DOWN,
};
// Offsets of the movement data for spiraling in either direction.
#define SPIRAL_INWARD_START 0
#define SPIRAL_INWARD_END 3
#define SPIRAL_OUTWARD_START 4
#define SPIRAL_OUTWARD_END 7
2021-10-27 22:17:27 +02:00
2021-10-29 17:56:06 +02:00
static const s16 sRectangularSpiral_Major_InwardRight[] = {MOVE_RIGHT, 27, 275, SPIRAL_END};
static const s16 sRectangularSpiral_Major_InwardLeft[] = {MOVE_LEFT, 486, SPIRAL_END};
static const s16 sRectangularSpiral_Major_InwardUp[] = {MOVE_UP, 262, SPIRAL_END};
static const s16 sRectangularSpiral_Major_InwardDown[] = {MOVE_DOWN, 507, SPIRAL_REBOUND};
2021-10-27 22:17:27 +02:00
2021-10-29 17:56:06 +02:00
static const s16 sRectangularSpiral_Minor_InwardRight[] = {MOVE_RIGHT, 213, SPIRAL_END};
static const s16 sRectangularSpiral_Minor_InwardLeft[] = {MOVE_LEFT, 548, SPIRAL_REBOUND};
static const s16 sRectangularSpiral_Minor_InwardUp[] = {MOVE_UP, 196, SPIRAL_END};
static const s16 sRectangularSpiral_Minor_InwardDown[] = {MOVE_DOWN, 573, 309, SPIRAL_END};
2021-10-27 22:17:27 +02:00
2021-10-29 17:56:06 +02:00
static const s16 sRectangularSpiral_Minor_OutwardRight[] = {MOVE_RIGHT, 474, SPIRAL_END};
static const s16 sRectangularSpiral_Minor_OutwardLeft[] = {MOVE_LEFT, 295, 32, SPIRAL_END};
static const s16 sRectangularSpiral_Minor_OutwardUp[] = {MOVE_UP, 58, SPIRAL_END};
static const s16 sRectangularSpiral_Minor_OutwardDown[] = {MOVE_DOWN, 455, SPIRAL_END};
2021-10-27 22:17:27 +02:00
2021-10-29 17:56:06 +02:00
static const s16 sRectangularSpiral_Major_OutwardRight[] = {MOVE_RIGHT, 540, SPIRAL_END};
static const s16 sRectangularSpiral_Major_OutwardLeft[] = {MOVE_LEFT, 229, SPIRAL_END};
static const s16 sRectangularSpiral_Major_OutwardUp[] = {MOVE_UP, 244, 28, SPIRAL_END};
static const s16 sRectangularSpiral_Major_OutwardDown[] = {MOVE_DOWN, 517, SPIRAL_END};
2021-10-27 22:17:27 +02:00
// Move data for spiral lines starting in the top left / bottom right
static const s16 *const sRectangularSpiral_MoveDataTable_MajorDiagonal[] =
2018-01-13 21:03:07 +01:00
{
2021-10-29 17:56:06 +02:00
[SPIRAL_INWARD_START] =
sRectangularSpiral_Major_InwardRight,
sRectangularSpiral_Major_InwardDown,
sRectangularSpiral_Major_InwardLeft,
sRectangularSpiral_Major_InwardUp,
[SPIRAL_OUTWARD_START] =
sRectangularSpiral_Major_OutwardUp,
sRectangularSpiral_Major_OutwardLeft,
sRectangularSpiral_Major_OutwardDown,
sRectangularSpiral_Major_OutwardRight
2018-01-13 21:03:07 +01:00
};
2021-10-27 22:17:27 +02:00
// Move data for spiral lines starting in the top right / bottom left
static const s16 *const sRectangularSpiral_MoveDataTable_MinorDiagonal[] =
2018-01-13 21:03:07 +01:00
{
2021-10-29 17:56:06 +02:00
[SPIRAL_INWARD_START] =
sRectangularSpiral_Minor_InwardDown,
sRectangularSpiral_Minor_InwardLeft,
sRectangularSpiral_Minor_InwardUp,
sRectangularSpiral_Minor_InwardRight,
[SPIRAL_OUTWARD_START] =
sRectangularSpiral_Minor_OutwardLeft,
sRectangularSpiral_Minor_OutwardDown,
sRectangularSpiral_Minor_OutwardRight,
sRectangularSpiral_Minor_OutwardUp
2018-01-13 21:03:07 +01:00
};
2021-10-27 22:17:27 +02:00
static const s16 *const *const sRectangularSpiral_MoveDataTables[] =
2018-01-13 21:03:07 +01:00
{
2021-10-27 22:17:27 +02:00
sRectangularSpiral_MoveDataTable_MajorDiagonal,
sRectangularSpiral_MoveDataTable_MinorDiagonal
2018-01-13 21:03:07 +01:00
};
static const TransitionStateFunc sGroudon_Funcs[] =
2018-01-13 21:03:07 +01:00
{
2021-10-25 16:42:08 +02:00
WeatherTrio_BgFadeBlack,
WeatherTrio_WaitFade,
Groudon_Init,
2021-10-27 22:17:27 +02:00
Groudon_PaletteFlash,
2021-10-25 16:42:08 +02:00
Groudon_PaletteBrighten,
FramesCountdown,
2021-10-25 16:42:08 +02:00
WeatherDuo_FadeOut,
WeatherDuo_End
2018-01-13 21:03:07 +01:00
};
static const TransitionStateFunc sRayquaza_Funcs[] =
{
2021-10-25 16:42:08 +02:00
WeatherTrio_BgFadeBlack,
WeatherTrio_WaitFade,
2021-10-27 22:17:27 +02:00
Rayquaza_Init,
Rayquaza_SetGfx,
Rayquaza_PaletteFlash,
Rayquaza_FadeToBlack,
Rayquaza_WaitFade,
Rayquaza_SetBlack,
Rayquaza_TriRing,
Blackhole_Vibrate,
Blackhole_GrowEnd
2018-01-14 20:45:44 +01:00
};
2021-10-27 22:17:27 +02:00
static const TransitionStateFunc sWhiteBarsFade_Funcs[] =
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
WhiteBarsFade_Init,
WhiteBarsFade_StartBars,
WhiteBarsFade_WaitBars,
WhiteBarsFade_BlendToBlack,
WhiteBarsFade_End
2018-01-14 20:45:44 +01:00
};
2021-10-27 22:17:27 +02:00
#define NUM_WHITE_BARS 8
static const s16 sWhiteBarsFade_StartDelays[NUM_WHITE_BARS] = {0, 20, 15, 40, 10, 25, 35, 5};
2018-01-14 20:45:44 +01:00
static const TransitionStateFunc sGridSquares_Funcs[] =
2018-01-14 20:45:44 +01:00
{
2021-10-25 16:42:08 +02:00
GridSquares_Init,
2021-10-27 22:17:27 +02:00
GridSquares_Main,
2021-10-25 16:42:08 +02:00
GridSquares_End
2018-01-14 20:45:44 +01:00
};
2021-10-27 22:17:27 +02:00
static const TransitionStateFunc sAngledWipes_Funcs[] =
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
AngledWipes_Init,
AngledWipes_SetWipeData,
AngledWipes_DoWipe,
AngledWipes_TryEnd,
AngledWipes_StartNext
2018-01-14 20:45:44 +01:00
};
2021-10-27 22:17:27 +02:00
#define NUM_ANGLED_WIPES 7
static const s16 sAngledWipes_MoveData[NUM_ANGLED_WIPES][5] =
2018-01-14 20:45:44 +01:00
{
2021-10-29 17:56:06 +02:00
// startX startY endX endY yDirection
2021-10-27 22:17:27 +02:00
{56, 0, 0, DISPLAY_HEIGHT, 0},
{104, DISPLAY_HEIGHT, DISPLAY_WIDTH, 88, 1},
{DISPLAY_WIDTH, 72, 56, 0, 1},
{0, 32, 144, DISPLAY_HEIGHT, 0},
{144, DISPLAY_HEIGHT, 184, 0, 1},
{56, 0, 168, DISPLAY_HEIGHT, 0},
{168, DISPLAY_HEIGHT, 48, 0, 1},
2018-01-14 20:45:44 +01:00
};
2021-10-27 22:17:27 +02:00
static const s16 sAngledWipes_EndDelays[NUM_ANGLED_WIPES] = {8, 4, 2, 1, 1, 1, 0};
2018-01-14 20:45:44 +01:00
static const TransitionStateFunc sTransitionIntroFuncs[] =
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
TransitionIntro_FadeToGray,
TransitionIntro_FadeFromGray
2018-01-14 20:45:44 +01:00
};
2020-06-01 16:17:25 +02:00
static const struct SpriteFrameImage sSpriteImage_Pokeball[] =
2018-01-14 20:45:44 +01:00
{
2020-06-01 16:17:25 +02:00
sPokeball_Gfx, sizeof(sPokeball_Gfx)
2018-01-14 20:45:44 +01:00
};
2020-06-01 16:17:25 +02:00
static const union AnimCmd sSpriteAnim_Pokeball[] =
2018-01-14 20:45:44 +01:00
{
ANIMCMD_FRAME(0, 1),
ANIMCMD_END
};
2020-06-01 16:17:25 +02:00
static const union AnimCmd *const sSpriteAnimTable_Pokeball[] =
2018-01-14 20:45:44 +01:00
{
2020-06-01 16:17:25 +02:00
sSpriteAnim_Pokeball
2018-01-14 20:45:44 +01:00
};
2020-06-01 16:17:25 +02:00
static const union AffineAnimCmd sSpriteAffineAnim_Pokeball1[] =
2018-01-14 20:45:44 +01:00
{
AFFINEANIMCMD_FRAME(0, 0, -4, 1),
AFFINEANIMCMD_JUMP(0)
};
2020-06-01 16:17:25 +02:00
static const union AffineAnimCmd sSpriteAffineAnim_Pokeball2[] =
2018-01-14 20:45:44 +01:00
{
AFFINEANIMCMD_FRAME(0, 0, 4, 1),
AFFINEANIMCMD_JUMP(0)
};
2020-06-01 16:17:25 +02:00
static const union AffineAnimCmd *const sSpriteAffineAnimTable_Pokeball[] =
2018-01-14 20:45:44 +01:00
{
2020-06-01 16:17:25 +02:00
sSpriteAffineAnim_Pokeball1,
sSpriteAffineAnim_Pokeball2
2018-01-14 20:45:44 +01:00
};
2020-06-01 16:17:25 +02:00
static const struct SpriteTemplate sSpriteTemplate_Pokeball =
2018-01-14 20:45:44 +01:00
{
2021-09-14 19:14:14 +02:00
.tileTag = TAG_NONE,
2021-10-27 22:17:27 +02:00
.paletteTag = FLDEFF_PAL_TAG_POKEBALL_TRAIL,
.oam = &gObjectEventBaseOam_32x32,
2020-06-01 16:17:25 +02:00
.anims = sSpriteAnimTable_Pokeball,
.images = sSpriteImage_Pokeball,
.affineAnims = sSpriteAffineAnimTable_Pokeball,
2021-10-27 22:17:27 +02:00
.callback = SpriteCB_FldEffPokeballTrail
2018-01-14 20:45:44 +01:00
};
2020-06-01 16:17:25 +02:00
static const struct OamData sOam_UnusedBrendanLass =
2018-01-14 20:45:44 +01:00
{
.y = 0,
.affineMode = ST_OAM_AFFINE_OFF,
.objMode = ST_OAM_OBJ_NORMAL,
2018-01-14 20:45:44 +01:00
.mosaic = 0,
.bpp = ST_OAM_4BPP,
.shape = SPRITE_SHAPE(64x64),
2018-01-14 20:45:44 +01:00
.x = 0,
.matrixNum = 0,
.size = SPRITE_SIZE(64x64),
2018-01-14 20:45:44 +01:00
.tileNum = 0,
.priority = 0,
.paletteNum = 0,
.affineParam = 0,
};
2020-06-01 16:17:25 +02:00
static const struct SpriteFrameImage sImageTable_UnusedBrendan[] =
2018-01-14 20:45:44 +01:00
{
2020-06-01 16:17:25 +02:00
sUnusedBrendan_Gfx, sizeof(sUnusedBrendan_Gfx)
2018-01-14 20:45:44 +01:00
};
2020-06-01 16:17:25 +02:00
static const struct SpriteFrameImage sImageTable_UnusedLass[] =
2018-01-14 20:45:44 +01:00
{
2020-06-01 16:17:25 +02:00
sUnusedLass_Gfx, sizeof(sUnusedLass_Gfx)
2018-01-14 20:45:44 +01:00
};
2020-06-01 16:17:25 +02:00
static const union AnimCmd sSpriteAnim_UnusedBrendanLass[] =
2018-01-14 20:45:44 +01:00
{
ANIMCMD_FRAME(0, 1),
ANIMCMD_END
};
2020-06-01 16:17:25 +02:00
static const union AnimCmd *const sSpriteAnimTable_UnusedBrendanLass[] =
2018-01-14 20:45:44 +01:00
{
2020-06-01 16:17:25 +02:00
sSpriteAnim_UnusedBrendanLass
2018-01-14 20:45:44 +01:00
};
2020-06-01 16:17:25 +02:00
static const struct SpriteTemplate sSpriteTemplate_UnusedBrendan =
2018-01-14 20:45:44 +01:00
{
2021-09-14 19:14:14 +02:00
.tileTag = TAG_NONE,
2021-10-25 16:42:08 +02:00
.paletteTag = PALTAG_UNUSED_MUGSHOT,
2020-06-01 16:17:25 +02:00
.oam = &sOam_UnusedBrendanLass,
.anims = sSpriteAnimTable_UnusedBrendanLass,
.images = sImageTable_UnusedBrendan,
2018-01-14 20:45:44 +01:00
.affineAnims = gDummySpriteAffineAnimTable,
2021-10-25 16:42:08 +02:00
.callback = SpriteCB_MugshotTrainerPic
2018-01-14 20:45:44 +01:00
};
2020-06-01 16:17:25 +02:00
static const struct SpriteTemplate sSpriteTemplate_UnusedLass =
2018-01-14 20:45:44 +01:00
{
2021-09-14 19:14:14 +02:00
.tileTag = TAG_NONE,
2021-10-25 16:42:08 +02:00
.paletteTag = PALTAG_UNUSED_MUGSHOT,
2020-06-01 16:17:25 +02:00
.oam = &sOam_UnusedBrendanLass,
.anims = sSpriteAnimTable_UnusedBrendanLass,
.images = sImageTable_UnusedLass,
2018-01-14 20:45:44 +01:00
.affineAnims = gDummySpriteAffineAnimTable,
2021-10-25 16:42:08 +02:00
.callback = SpriteCB_MugshotTrainerPic
2018-01-14 20:45:44 +01:00
};
2020-07-02 10:59:52 +02:00
static const u16 sFieldEffectPal_Pokeball[] = INCBIN_U16("graphics/field_effects/palettes/pokeball.gbapal");
2018-01-14 20:45:44 +01:00
2021-10-27 22:17:27 +02:00
const struct SpritePalette gSpritePalette_Pokeball = {sFieldEffectPal_Pokeball, FLDEFF_PAL_TAG_POKEBALL_TRAIL};
2018-01-14 20:45:44 +01:00
2019-04-16 16:40:32 +02:00
static const u16 sMugshotPal_Sidney[] = INCBIN_U16("graphics/battle_transitions/sidney_bg.gbapal");
2018-01-14 22:09:35 +01:00
static const u16 sMugshotPal_Phoebe[] = INCBIN_U16("graphics/battle_transitions/phoebe_bg.gbapal");
static const u16 sMugshotPal_Glacia[] = INCBIN_U16("graphics/battle_transitions/glacia_bg.gbapal");
static const u16 sMugshotPal_Drake[] = INCBIN_U16("graphics/battle_transitions/drake_bg.gbapal");
static const u16 sMugshotPal_Champion[] = INCBIN_U16("graphics/battle_transitions/wallace_bg.gbapal");
static const u16 sMugshotPal_Brendan[] = INCBIN_U16("graphics/battle_transitions/brendan_bg.gbapal");
static const u16 sMugshotPal_May[] = INCBIN_U16("graphics/battle_transitions/may_bg.gbapal");
2018-01-14 20:45:44 +01:00
2018-01-14 22:09:35 +01:00
static const u16 *const sOpponentMugshotsPals[MUGSHOTS_COUNT] =
2018-01-14 20:45:44 +01:00
{
[MUGSHOT_SIDNEY] = sMugshotPal_Sidney,
[MUGSHOT_PHOEBE] = sMugshotPal_Phoebe,
[MUGSHOT_GLACIA] = sMugshotPal_Glacia,
[MUGSHOT_DRAKE] = sMugshotPal_Drake,
[MUGSHOT_CHAMPION] = sMugshotPal_Champion
2018-01-14 20:45:44 +01:00
};
static const u16 *const sPlayerMugshotsPals[GENDER_COUNT] =
2018-01-14 20:45:44 +01:00
{
[MALE] = sMugshotPal_Brendan,
[FEMALE] = sMugshotPal_May
2018-01-14 20:45:44 +01:00
};
2018-01-14 22:09:35 +01:00
static const u16 sUnusedTrainerPalette[] = INCBIN_U16("graphics/battle_transitions/unused_trainer.gbapal");
2021-10-25 16:42:08 +02:00
static const struct SpritePalette sSpritePalette_UnusedTrainer = {sUnusedTrainerPalette, PALTAG_UNUSED_MUGSHOT};
2018-01-14 20:45:44 +01:00
2018-01-14 22:09:35 +01:00
static const u16 sBigPokeball_Tilemap[] = INCBIN_U16("graphics/battle_transitions/big_pokeball_map.bin");
static const u16 sMugshotsTilemap[] = INCBIN_U16("graphics/battle_transitions/elite_four_bg_map.bin");
2018-01-14 20:45:44 +01:00
static const TransitionStateFunc sFrontierLogoWiggle_Funcs[] =
2018-01-14 20:45:44 +01:00
{
2021-10-25 16:42:08 +02:00
FrontierLogoWiggle_Init,
FrontierLogoWiggle_SetGfx,
2021-10-27 22:17:27 +02:00
PatternWeave_Blend1,
PatternWeave_Blend2,
PatternWeave_FinishAppear,
PatternWeave_CircularMask
2018-01-14 20:45:44 +01:00
};
static const TransitionStateFunc sFrontierLogoWave_Funcs[] =
2018-01-14 20:45:44 +01:00
{
2021-10-25 16:42:08 +02:00
FrontierLogoWave_Init,
FrontierLogoWave_SetGfx,
2021-10-29 17:56:06 +02:00
FrontierLogoWave_InitScanline,
FrontierLogoWave_Main
2018-01-14 20:45:44 +01:00
};
static const TransitionStateFunc sFrontierSquares_Funcs[] =
2018-01-14 20:45:44 +01:00
{
2021-10-25 16:42:08 +02:00
FrontierSquares_Init,
2021-10-27 22:17:27 +02:00
FrontierSquares_Draw,
FrontierSquares_Shrink,
FrontierSquares_End
2018-01-14 20:45:44 +01:00
};
static const TransitionStateFunc sFrontierSquaresSpiral_Funcs[] =
2018-01-14 20:45:44 +01:00
{
2021-10-25 16:42:08 +02:00
FrontierSquaresSpiral_Init,
2021-10-29 17:56:06 +02:00
FrontierSquaresSpiral_Outward,
FrontierSquaresSpiral_SetBlack,
FrontierSquaresSpiral_Inward,
FrontierSquares_End
2018-01-14 20:45:44 +01:00
};
static const TransitionStateFunc sFrontierSquaresScroll_Funcs[] =
2018-01-14 20:45:44 +01:00
{
2021-10-25 16:42:08 +02:00
FrontierSquaresScroll_Init,
2021-10-29 17:56:06 +02:00
FrontierSquaresScroll_Draw,
FrontierSquaresScroll_SetBlack,
FrontierSquaresScroll_Erase,
2021-10-25 16:42:08 +02:00
FrontierSquaresScroll_End
2018-01-14 20:45:44 +01:00
};
2021-10-29 17:56:06 +02:00
#define SQUARE_SIZE 4
#define MARGIN_SIZE 1 // Squares do not fit evenly across the width, so there is a margin on either side.
#define NUM_SQUARES_PER_ROW ((DISPLAY_WIDTH - (MARGIN_SIZE * 8 * 2)) / (SQUARE_SIZE * 8))
#define NUM_SQUARES_PER_COL (DISPLAY_HEIGHT / (SQUARE_SIZE * 8))
#define NUM_SQUARES (NUM_SQUARES_PER_ROW * NUM_SQUARES_PER_COL)
// The order in which the squares should appear/disappear to create
// the spiral effect. Spiraling inward starts with the first element,
// and spiraling outward starts with the last. The positions are the
// squares numbered left-to-right top-to-bottom.
static const u8 sFrontierSquaresSpiral_Positions[NUM_SQUARES] = {
28, 29, 30, 31, 32, 33, 34,
27, 20, 13, 6, 5, 4, 3,
2, 1, 0, 7, 14, 21, 22,
23, 24, 25, 26, 19, 12, 11,
10, 9, 8, 15, 16, 17, 18
2021-10-25 16:42:08 +02:00
};
2021-10-29 17:56:06 +02:00
// In the scrolling version the squares appear/disappear in a "random" order
// dictated by the list below.
static const u8 sFrontierSquaresScroll_Positions[] = {
0, 16, 41, 22, 44, 2, 43, 21,
46, 27, 9, 48, 38, 5, 57, 59,
12, 63, 35, 28, 10, 53, 7, 49,
39, 23, 55, 1, 62, 17, 61, 30,
6, 34, 15, 51, 32, 58, 13, 45,
37, 52, 11, 24, 60, 19, 56, 33,
29, 50, 40, 54, 14, 3, 47, 20,
18, 25, 4, 36, 26, 42, 31, 8
2021-10-25 16:42:08 +02:00
};
//---------------------------
// Main transition functions
//---------------------------
2018-01-02 20:38:33 +01:00
2018-01-01 17:41:34 +01:00
static void CB2_TestBattleTransition(void)
{
switch (sTestingTransitionState)
{
case 0:
LaunchBattleTransitionTask(sTestingTransitionId);
sTestingTransitionState++;
break;
case 1:
if (IsBattleTransitionDone())
{
sTestingTransitionState = 0;
2018-02-14 00:58:22 +01:00
SetMainCallback2(CB2_ReturnToField);
2018-01-01 17:41:34 +01:00
}
break;
}
RunTasks();
AnimateSprites();
BuildOamBuffer();
UpdatePaletteFade();
}
// Unused
static void TestBattleTransition(u8 transitionId)
2018-01-01 17:41:34 +01:00
{
sTestingTransitionId = transitionId;
SetMainCallback2(CB2_TestBattleTransition);
}
void BattleTransition_StartOnField(u8 transitionId)
{
gMain.callback2 = CB2_OverworldBasic;
LaunchBattleTransitionTask(transitionId);
}
void BattleTransition_Start(u8 transitionId)
{
LaunchBattleTransitionTask(transitionId);
}
2018-01-14 20:45:44 +01:00
// main task that launches sub-tasks for phase1 and phase2
#define tTransitionId data[1]
2018-01-01 17:41:34 +01:00
#define tTransitionDone data[15]
bool8 IsBattleTransitionDone(void)
{
u8 taskId = FindTaskIdByFunc(Task_BattleTransition);
2018-01-01 17:41:34 +01:00
if (gTasks[taskId].tTransitionDone)
{
DestroyTask(taskId);
2021-10-25 16:42:08 +02:00
FREE_AND_SET_NULL(sTransitionData);
2018-01-01 17:41:34 +01:00
return TRUE;
}
else
{
return FALSE;
}
}
2018-01-14 22:09:35 +01:00
static void LaunchBattleTransitionTask(u8 transitionId)
2018-01-01 17:41:34 +01:00
{
u8 taskId = CreateTask(Task_BattleTransition, 2);
2018-01-14 20:45:44 +01:00
gTasks[taskId].tTransitionId = transitionId;
2021-10-25 16:42:08 +02:00
sTransitionData = AllocZeroed(sizeof(*sTransitionData));
2018-01-01 17:41:34 +01:00
}
static void Task_BattleTransition(u8 taskId)
2018-01-01 17:41:34 +01:00
{
while (sTaskHandlers[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-01 17:41:34 +01:00
}
static bool8 Transition_StartIntro(struct Task *task)
2018-01-01 17:41:34 +01:00
{
2018-12-08 19:05:03 +01:00
SetWeatherScreenFadeOut();
2021-10-29 17:56:06 +02:00
CpuCopy32(gPlttBufferFaded, gPlttBufferUnfaded, sizeof(gPlttBufferUnfaded));
if (sTasks_Intro[task->tTransitionId] != NULL)
2018-01-01 17:41:34 +01:00
{
CreateTask(sTasks_Intro[task->tTransitionId], 4);
2018-01-01 17:41:34 +01:00
task->tState++;
return FALSE;
}
else
{
task->tState = 2;
return TRUE;
}
}
2018-01-02 20:38:33 +01:00
static bool8 Transition_WaitForIntro(struct Task *task)
2018-01-02 20:38:33 +01:00
{
if (FindTaskIdByFunc(sTasks_Intro[task->tTransitionId]) == TASK_NONE)
2018-01-02 20:38:33 +01:00
{
task->tState++;
return TRUE;
}
else
{
return FALSE;
}
}
static bool8 Transition_StartMain(struct Task *task)
2018-01-02 20:38:33 +01:00
{
CreateTask(sTasks_Main[task->tTransitionId], 0);
2018-01-02 20:38:33 +01:00
task->tState++;
return FALSE;
}
static bool8 Transition_WaitForMain(struct Task *task)
2018-01-02 20:38:33 +01:00
{
task->tTransitionDone = FALSE;
if (FindTaskIdByFunc(sTasks_Main[task->tTransitionId]) == TASK_NONE)
2018-01-02 20:38:33 +01:00
task->tTransitionDone = TRUE;
return FALSE;
}
2018-01-14 20:45:44 +01:00
#undef tTransitionId
2018-01-02 20:38:33 +01:00
#undef tTransitionDone
static void Task_Intro(u8 taskId)
2018-01-02 20:38:33 +01:00
{
if (gTasks[taskId].tState == 0)
{
gTasks[taskId].tState++;
CreateIntroTask(0, 0, 3, 2, 2);
2018-01-02 20:38:33 +01:00
}
else if (IsIntroTaskDone())
2018-01-02 20:38:33 +01:00
{
DestroyTask(taskId);
}
}
2021-10-25 16:42:08 +02:00
//--------------------
// B_TRANSITION_BLUR
//--------------------
#define tDelay data[1]
#define tCounter data[2]
static void Task_Blur(u8 taskId)
2018-01-02 20:38:33 +01:00
{
while (sBlur_Funcs[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-02 20:38:33 +01:00
}
2021-10-25 16:42:08 +02:00
static bool8 Blur_Init(struct Task *task)
2018-01-02 20:38:33 +01:00
{
SetGpuReg(REG_OFFSET_MOSAIC, 0);
SetGpuRegBits(REG_OFFSET_BG1CNT, BGCNT_MOSAIC);
SetGpuRegBits(REG_OFFSET_BG2CNT, BGCNT_MOSAIC);
SetGpuRegBits(REG_OFFSET_BG3CNT, BGCNT_MOSAIC);
task->tState++;
return TRUE;
}
2021-10-25 16:42:08 +02:00
static bool8 Blur_Main(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
if (task->tDelay != 0)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
task->tDelay--;
2018-01-02 20:38:33 +01:00
}
else
{
2021-10-25 16:42:08 +02:00
task->tDelay = 4;
if (++task->tCounter == 10)
BeginNormalPaletteFade(PALETTES_ALL, -1, 0, 16, RGB_BLACK);
SetGpuReg(REG_OFFSET_MOSAIC, (task->tCounter & 15) * 17);
if (task->tCounter > 14)
2018-01-02 20:38:33 +01:00
task->tState++;
}
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 Blur_End(struct Task *task)
2018-01-02 20:38:33 +01:00
{
if (!gPaletteFade.active)
{
u8 taskId = FindTaskIdByFunc(Task_Blur);
2018-01-02 20:38:33 +01:00
DestroyTask(taskId);
}
return FALSE;
}
2021-10-25 16:42:08 +02:00
#undef tDelay
#undef tCounter
//--------------------
// B_TRANSITION_SWIRL
//--------------------
#define tSinIndex data[1]
#define tAmplitude data[2]
static void Task_Swirl(u8 taskId)
2018-01-02 20:38:33 +01:00
{
while (sSwirl_Funcs[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-02 20:38:33 +01:00
}
2021-10-25 16:42:08 +02:00
static bool8 Swirl_Init(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
InitTransitionData();
2018-01-29 17:47:12 +01:00
ScanlineEffect_Clear();
2021-10-25 16:42:08 +02:00
BeginNormalPaletteFade(PALETTES_ALL, 4, 0, 16, RGB_BLACK);
SetSinWave(gScanlineEffectRegBuffers[1], sTransitionData->cameraX, 0, 2, 0, DISPLAY_HEIGHT);
2018-01-02 20:38:33 +01:00
SetVBlankCallback(VBlankCB_Swirl);
SetHBlankCallback(HBlankCB_Swirl);
2018-01-02 20:38:33 +01:00
EnableInterrupts(INTR_FLAG_VBLANK | INTR_FLAG_HBLANK);
task->tState++;
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 Swirl_End(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA = FALSE;
task->tSinIndex += 4;
task->tAmplitude += 8;
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
SetSinWave(gScanlineEffectRegBuffers[0], sTransitionData->cameraX, task->tSinIndex, 2, task->tAmplitude, DISPLAY_HEIGHT);
2018-01-02 20:38:33 +01:00
if (!gPaletteFade.active)
{
u8 taskId = FindTaskIdByFunc(Task_Swirl);
2018-01-02 20:38:33 +01:00
DestroyTask(taskId);
}
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA++;
2018-01-02 20:38:33 +01:00
return FALSE;
}
static void VBlankCB_Swirl(void)
2018-01-02 20:38:33 +01:00
{
VBlankCB_BattleTransition();
2021-10-25 16:42:08 +02:00
if (sTransitionData->VBlank_DMA)
DmaCopy16(3, gScanlineEffectRegBuffers[0], gScanlineEffectRegBuffers[1], DISPLAY_HEIGHT * 2);
2018-01-02 20:38:33 +01:00
}
static void HBlankCB_Swirl(void)
2018-01-02 20:38:33 +01:00
{
2018-01-29 17:47:12 +01:00
u16 var = gScanlineEffectRegBuffers[1][REG_VCOUNT];
2018-01-02 20:38:33 +01:00
REG_BG1HOFS = var;
REG_BG2HOFS = var;
REG_BG3HOFS = var;
}
2021-10-25 16:42:08 +02:00
#undef tSinIndex
#undef tAmplitude
//----------------------
// B_TRANSITION_SHUFFLE
//----------------------
#define tSinVal data[1]
#define tAmplitude data[2]
static void Task_Shuffle(u8 taskId)
2018-01-02 20:38:33 +01:00
{
while (sShuffle_Funcs[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-02 20:38:33 +01:00
}
2021-10-25 16:42:08 +02:00
static bool8 Shuffle_Init(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
InitTransitionData();
2018-01-29 17:47:12 +01:00
ScanlineEffect_Clear();
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
BeginNormalPaletteFade(PALETTES_ALL, 4, 0, 16, RGB_BLACK);
memset(gScanlineEffectRegBuffers[1], sTransitionData->cameraY, DISPLAY_HEIGHT * 2);
2018-01-02 20:38:33 +01:00
SetVBlankCallback(VBlankCB_Shuffle);
SetHBlankCallback(HBlankCB_Shuffle);
2018-01-02 20:38:33 +01:00
EnableInterrupts(INTR_FLAG_VBLANK | INTR_FLAG_HBLANK);
task->tState++;
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 Shuffle_End(struct Task *task)
2018-01-02 20:38:33 +01:00
{
u8 i;
2021-10-25 16:42:08 +02:00
u16 amplitude, sinVal;
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA = FALSE;
sinVal = task->tSinVal;
amplitude = task->tAmplitude >> 8;
task->tSinVal += 4224;
task->tAmplitude += 384;
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
for (i = 0; i < DISPLAY_HEIGHT; i++, sinVal += 4224)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
u16 sinIndex = sinVal / 256;
gScanlineEffectRegBuffers[0][i] = sTransitionData->cameraY + Sin(sinIndex, amplitude);
2018-01-02 20:38:33 +01:00
}
if (!gPaletteFade.active)
DestroyTask(FindTaskIdByFunc(Task_Shuffle));
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA++;
2018-01-02 20:38:33 +01:00
return FALSE;
}
static void VBlankCB_Shuffle(void)
2018-01-02 20:38:33 +01:00
{
VBlankCB_BattleTransition();
2021-10-25 16:42:08 +02:00
if (sTransitionData->VBlank_DMA)
DmaCopy16(3, gScanlineEffectRegBuffers[0], gScanlineEffectRegBuffers[1], DISPLAY_HEIGHT * 2);
2018-01-02 20:38:33 +01:00
}
static void HBlankCB_Shuffle(void)
2018-01-02 20:38:33 +01:00
{
2018-01-29 17:47:12 +01:00
u16 var = gScanlineEffectRegBuffers[1][REG_VCOUNT];
2018-01-02 20:38:33 +01:00
REG_BG1VOFS = var;
REG_BG2VOFS = var;
REG_BG3VOFS = var;
}
2021-10-25 16:42:08 +02:00
#undef tSinVal
#undef tAmplitude
//------------------------------------------------------------------------
// B_TRANSITION_BIG_POKEBALL, B_TRANSITION_AQUA, B_TRANSITION_MAGMA,
// B_TRANSITION_REGICE, B_TRANSITION_REGISTEEL, B_TRANSITION_REGIROCK
// and B_TRANSITION_KYOGRE.
//
// With the exception of B_TRANSITION_KYOGRE, all of the above transitions
// use the same weave effect (see the PatternWeave functions).
// Unclear why Kyogre's was grouped here and not with Groudon/Rayquaza's.
//------------------------------------------------------------------------
#define tBlendTarget1 data[1]
#define tBlendTarget2 data[2]
#define tBlendDelay data[3]
2021-10-27 22:17:27 +02:00
// Data 1-3 change purpose for PatternWeave_CircularMask
#define tRadius data[1]
#define tRadiusDelta data[2]
#define tVBlankSet data[3]
2021-10-25 16:42:08 +02:00
#define tSinIndex data[4]
#define tAmplitude data[5]
#define tEndDelay data[8]
static void Task_BigPokeball(u8 taskId)
2018-01-02 20:38:33 +01:00
{
while (sBigPokeball_Funcs[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-02 20:38:33 +01:00
}
static void Task_Aqua(u8 taskId)
2018-01-02 20:38:33 +01:00
{
while (sAqua_Funcs[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-02 20:38:33 +01:00
}
static void Task_Magma(u8 taskId)
2018-01-02 20:38:33 +01:00
{
while (sMagma_Funcs[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-02 20:38:33 +01:00
}
static void Task_Regice(u8 taskId)
2018-01-02 20:38:33 +01:00
{
while (sRegice_Funcs[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-02 20:38:33 +01:00
}
static void Task_Registeel(u8 taskId)
2018-01-02 20:38:33 +01:00
{
while (sRegisteel_Funcs[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-02 20:38:33 +01:00
}
static void Task_Regirock(u8 taskId)
2018-01-02 20:38:33 +01:00
{
while (sRegirock_Funcs[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-02 20:38:33 +01:00
}
static void Task_Kyogre(u8 taskId)
2018-01-02 20:38:33 +01:00
{
while (sKyogre_Funcs[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-02 20:38:33 +01:00
}
2021-10-25 16:42:08 +02:00
static void InitPatternWeaveTransition(struct Task *task)
2018-01-02 20:38:33 +01:00
{
s32 i;
2021-10-25 16:42:08 +02:00
InitTransitionData();
2018-01-29 17:47:12 +01:00
ScanlineEffect_Clear();
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
task->tBlendTarget1 = 16;
task->tBlendTarget2 = 0;
task->tSinIndex = 0;
task->tAmplitude = 0x4000;
sTransitionData->WININ = WININ_WIN0_ALL;
sTransitionData->WINOUT = 0;
sTransitionData->WIN0H = DISPLAY_WIDTH;
sTransitionData->WIN0V = DISPLAY_HEIGHT;
sTransitionData->BLDCNT = BLDCNT_TGT1_BG0 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_ALL;
sTransitionData->BLDALPHA = BLDALPHA_BLEND(task->tBlendTarget2, task->tBlendTarget1);
for (i = 0; i < DISPLAY_HEIGHT; i++)
gScanlineEffectRegBuffers[1][i] = DISPLAY_WIDTH;
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
SetVBlankCallback(VBlankCB_PatternWeave);
2018-01-02 20:38:33 +01:00
}
2021-10-25 16:42:08 +02:00
static bool8 Aqua_Init(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2020-06-01 16:17:25 +02:00
u16 *tilemap, *tileset;
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
task->tEndDelay = 60;
InitPatternWeaveTransition(task);
2020-06-01 16:17:25 +02:00
GetBg0TilesDst(&tilemap, &tileset);
2021-10-25 16:42:08 +02:00
CpuFill16(0, tilemap, BG_SCREEN_SIZE);
2020-06-01 16:17:25 +02:00
LZ77UnCompVram(sTeamAqua_Tileset, tileset);
2021-10-25 16:42:08 +02:00
LoadPalette(sEvilTeam_Palette, 0xF0, sizeof(sEvilTeam_Palette));
2018-01-02 20:38:33 +01:00
task->tState++;
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 Magma_Init(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2020-06-01 16:17:25 +02:00
u16 *tilemap, *tileset;
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
task->tEndDelay = 60;
InitPatternWeaveTransition(task);
2020-06-01 16:17:25 +02:00
GetBg0TilesDst(&tilemap, &tileset);
2021-10-25 16:42:08 +02:00
CpuFill16(0, tilemap, BG_SCREEN_SIZE);
2020-06-01 16:17:25 +02:00
LZ77UnCompVram(sTeamMagma_Tileset, tileset);
2021-10-25 16:42:08 +02:00
LoadPalette(sEvilTeam_Palette, 0xF0, sizeof(sEvilTeam_Palette));
2018-01-02 20:38:33 +01:00
task->tState++;
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 Regi_Init(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2020-06-01 16:17:25 +02:00
u16 *tilemap, *tileset;
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
task->tEndDelay = 60;
InitPatternWeaveTransition(task);
2020-06-01 16:17:25 +02:00
GetBg0TilesDst(&tilemap, &tileset);
2021-10-25 16:42:08 +02:00
CpuFill16(0, tilemap, BG_SCREEN_SIZE);
2020-06-01 16:17:25 +02:00
CpuCopy16(sRegis_Tileset, tileset, 0x2000);
2018-01-02 20:38:33 +01:00
task->tState++;
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 BigPokeball_Init(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2020-06-01 16:17:25 +02:00
u16 *tilemap, *tileset;
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
InitPatternWeaveTransition(task);
2020-06-01 16:17:25 +02:00
GetBg0TilesDst(&tilemap, &tileset);
2021-10-25 16:42:08 +02:00
CpuFill16(0, tilemap, BG_SCREEN_SIZE);
CpuCopy16(sBigPokeball_Tileset, tileset, sizeof(sBigPokeball_Tileset));
LoadPalette(sFieldEffectPal_Pokeball, 0xF0, sizeof(sFieldEffectPal_Pokeball));
2018-01-02 20:38:33 +01:00
task->tState++;
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 BigPokeball_SetGfx(struct Task *task)
2018-01-02 20:38:33 +01:00
{
s16 i, j;
2020-06-01 16:17:25 +02:00
u16 *tilemap, *tileset;
2021-10-25 16:42:08 +02:00
const u16 *bigPokeballMap;
2018-01-02 20:38:33 +01:00
2020-06-01 16:17:25 +02:00
GetBg0TilesDst(&tilemap, &tileset);
2021-10-25 16:42:08 +02:00
bigPokeballMap = sBigPokeball_Tilemap;
2018-01-02 20:38:33 +01:00
for (i = 0; i < 20; i++)
{
2021-10-25 16:42:08 +02:00
for (j = 0; j < 30; j++, bigPokeballMap++)
2021-10-27 22:17:27 +02:00
SET_TILE(tilemap, i, j, *bigPokeballMap);
2018-01-02 20:38:33 +01:00
}
2021-10-25 16:42:08 +02:00
SetSinWave(gScanlineEffectRegBuffers[0], 0, task->tSinIndex, 132, task->tAmplitude, DISPLAY_HEIGHT);
2018-01-02 20:38:33 +01:00
task->tState++;
return TRUE;
}
2021-10-25 16:42:08 +02:00
static bool8 Aqua_SetGfx(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2020-06-01 16:17:25 +02:00
u16 *tilemap, *tileset;
2018-01-02 20:38:33 +01:00
2020-06-01 16:17:25 +02:00
GetBg0TilesDst(&tilemap, &tileset);
LZ77UnCompVram(sTeamAqua_Tilemap, tilemap);
2021-10-25 16:42:08 +02:00
SetSinWave(gScanlineEffectRegBuffers[0], 0, task->tSinIndex, 132, task->tAmplitude, DISPLAY_HEIGHT);
2018-01-02 20:38:33 +01:00
task->tState++;
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 Magma_SetGfx(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2020-06-01 16:17:25 +02:00
u16 *tilemap, *tileset;
2018-01-02 20:38:33 +01:00
2020-06-01 16:17:25 +02:00
GetBg0TilesDst(&tilemap, &tileset);
LZ77UnCompVram(sTeamMagma_Tilemap, tilemap);
2021-10-25 16:42:08 +02:00
SetSinWave(gScanlineEffectRegBuffers[0], 0, task->tSinIndex, 132, task->tAmplitude, DISPLAY_HEIGHT);
2018-01-02 20:38:33 +01:00
task->tState++;
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 Regice_SetGfx(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2020-06-01 16:17:25 +02:00
u16 *tilemap, *tileset;
2018-01-02 20:38:33 +01:00
2020-06-01 16:17:25 +02:00
GetBg0TilesDst(&tilemap, &tileset);
2021-10-25 16:42:08 +02:00
LoadPalette(sRegice_Palette, 0xF0, sizeof(sRegice_Palette));
2020-06-01 16:17:25 +02:00
CpuCopy16(sRegice_Tilemap, tilemap, 0x500);
2021-10-25 16:42:08 +02:00
SetSinWave(gScanlineEffectRegBuffers[0], 0, task->tSinIndex, 132, task->tAmplitude, DISPLAY_HEIGHT);
2018-01-02 20:38:33 +01:00
task->tState++;
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 Registeel_SetGfx(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2020-06-01 16:17:25 +02:00
u16 *tilemap, *tileset;
2018-01-02 20:38:33 +01:00
2020-06-01 16:17:25 +02:00
GetBg0TilesDst(&tilemap, &tileset);
2021-10-25 16:42:08 +02:00
LoadPalette(sRegisteel_Palette, 0xF0, sizeof(sRegisteel_Palette));
2020-06-01 16:17:25 +02:00
CpuCopy16(sRegisteel_Tilemap, tilemap, 0x500);
2021-10-25 16:42:08 +02:00
SetSinWave(gScanlineEffectRegBuffers[0], 0, task->tSinIndex, 132, task->tAmplitude, DISPLAY_HEIGHT);
2018-01-02 20:38:33 +01:00
task->tState++;
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 Regirock_SetGfx(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2020-06-01 16:17:25 +02:00
u16 *tilemap, *tileset;
2018-01-02 20:38:33 +01:00
2020-06-01 16:17:25 +02:00
GetBg0TilesDst(&tilemap, &tileset);
2021-10-25 16:42:08 +02:00
LoadPalette(sRegirock_Palette, 0xF0, sizeof(sRegirock_Palette));
2020-06-01 16:17:25 +02:00
CpuCopy16(sRegirock_Tilemap, tilemap, 0x500);
2021-10-25 16:42:08 +02:00
SetSinWave(gScanlineEffectRegBuffers[0], 0, task->tSinIndex, 132, task->tAmplitude, DISPLAY_HEIGHT);
2018-01-02 20:38:33 +01:00
task->tState++;
return FALSE;
}
2021-10-25 16:42:08 +02:00
#define tTimer data[1]
static bool8 Kyogre_Init(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2020-06-01 16:17:25 +02:00
u16 *tilemap, *tileset;
2018-01-02 20:38:33 +01:00
2020-06-01 16:17:25 +02:00
GetBg0TilesDst(&tilemap, &tileset);
2021-10-25 16:42:08 +02:00
CpuFill16(0, tilemap, BG_SCREEN_SIZE);
2020-06-01 16:17:25 +02:00
LZ77UnCompVram(sKyogre_Tileset, tileset);
LZ77UnCompVram(sKyogre_Tilemap, tilemap);
2018-01-02 20:38:33 +01:00
task->tState++;
return FALSE;
}
2021-10-27 22:17:27 +02:00
static bool8 Kyogre_PaletteFlash(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
if (task->tTimer % 3 == 0)
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
u16 offset = task->tTimer % 30;
offset /= 3;
LoadPalette(&sKyogre1_Palette[offset * 16], 0xF0, 0x20);
2018-01-02 20:38:33 +01:00
}
2021-10-25 16:42:08 +02:00
if (++task->tTimer > 58)
2018-01-02 20:38:33 +01:00
{
task->tState++;
2021-10-25 16:42:08 +02:00
task->tTimer = 0;
2018-01-02 20:38:33 +01:00
}
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 Kyogre_PaletteBrighten(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
if (task->tTimer % 5 == 0)
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
s16 offset = task->tTimer / 5;
LoadPalette(&sKyogre2_Palette[offset * 16], 0xF0, 0x20);
2018-01-02 20:38:33 +01:00
}
2021-10-25 16:42:08 +02:00
if (++task->tTimer > 68)
2018-01-02 20:38:33 +01:00
{
task->tState++;
2021-10-25 16:42:08 +02:00
task->tTimer = 0;
task->tEndDelay = 30;
2018-01-02 20:38:33 +01:00
}
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 WeatherDuo_FadeOut(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
BeginNormalPaletteFade(PALETTES_OBJECTS | (1 << 15), 1, 0, 16, RGB_BLACK);
2018-01-02 20:38:33 +01:00
task->tState++;
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 WeatherDuo_End(struct Task *task)
2018-01-02 20:38:33 +01:00
{
if (!gPaletteFade.active)
{
DmaStop(0);
2020-06-01 16:17:25 +02:00
FadeScreenBlack();
2018-01-02 20:38:33 +01:00
DestroyTask(FindTaskIdByFunc(task->func));
}
return FALSE;
}
2021-10-25 16:42:08 +02:00
#undef tTimer
// The PatternWeave_ functions are used by several different transitions.
// They create an effect where a pattern/image (such as the Magma emblem) is
// formed by a shimmering weave effect.
2021-10-27 22:17:27 +02:00
static bool8 PatternWeave_Blend1(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA = FALSE;
if (task->tBlendDelay == 0 || --task->tBlendDelay == 0)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
task->tBlendTarget2++;
task->tBlendDelay = 2;
2018-01-02 20:38:33 +01:00
}
2021-10-25 16:42:08 +02:00
sTransitionData->BLDALPHA = BLDALPHA_BLEND(task->tBlendTarget2, task->tBlendTarget1);
if (task->tBlendTarget2 > 15)
2018-01-02 20:38:33 +01:00
task->tState++;
2021-10-25 16:42:08 +02:00
task->tSinIndex += 8;
task->tAmplitude -= 256;
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
SetSinWave(gScanlineEffectRegBuffers[0], 0, task->tSinIndex, 132, task->tAmplitude >> 8, DISPLAY_HEIGHT);
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA++;
2018-01-02 20:38:33 +01:00
return FALSE;
}
2021-10-27 22:17:27 +02:00
static bool8 PatternWeave_Blend2(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA = FALSE;
if (task->tBlendDelay == 0 || --task->tBlendDelay == 0)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
task->tBlendTarget1--;
task->tBlendDelay = 2;
2018-01-02 20:38:33 +01:00
}
2021-10-25 16:42:08 +02:00
sTransitionData->BLDALPHA = BLDALPHA_BLEND(task->tBlendTarget2, task->tBlendTarget1);
if (task->tBlendTarget1 == 0)
2018-01-02 20:38:33 +01:00
task->tState++;
2021-10-25 16:42:08 +02:00
task->tSinIndex += 8;
task->tAmplitude -= 256;
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
SetSinWave(gScanlineEffectRegBuffers[0], 0, task->tSinIndex, 132, task->tAmplitude >> 8, DISPLAY_HEIGHT);
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA++;
2018-01-02 20:38:33 +01:00
return FALSE;
}
2021-10-27 22:17:27 +02:00
static bool8 PatternWeave_FinishAppear(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA = FALSE;
task->tSinIndex += 8;
task->tAmplitude -= 256;
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
SetSinWave(gScanlineEffectRegBuffers[0], 0, task->tSinIndex, 132, task->tAmplitude >> 8, DISPLAY_HEIGHT);
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
if (task->tAmplitude <= 0)
2018-01-02 20:38:33 +01:00
{
task->tState++;
2021-10-27 22:17:27 +02:00
task->tRadius = DISPLAY_HEIGHT;
task->tRadiusDelta = 1 << 8;
2021-10-25 16:42:08 +02:00
task->tVBlankSet = FALSE;
2018-01-02 20:38:33 +01:00
}
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA++;
2018-01-02 20:38:33 +01:00
return FALSE;
}
static bool8 FramesCountdown(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
if (--task->tEndDelay == 0)
2018-01-02 20:38:33 +01:00
task->tState++;
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 WeatherTrio_BgFadeBlack(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
BeginNormalPaletteFade(PALETTES_BG, 1, 0, 16, RGB_BLACK);
2018-01-02 20:38:33 +01:00
task->tState++;
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 WeatherTrio_WaitFade(struct Task *task)
2018-01-02 20:38:33 +01:00
{
if (!gPaletteFade.active)
task->tState++;
return FALSE;
}
2021-10-27 22:17:27 +02:00
// Do a shrinking circular mask to go to a black screen after the pattern appears.
static bool8 PatternWeave_CircularMask(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA = FALSE;
2021-10-27 22:17:27 +02:00
if (task->tRadiusDelta < (4 << 8))
task->tRadiusDelta += 128; // 256 is 1 unit of speed. Speed up every other frame (128 / 256)
if (task->tRadius != 0)
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
task->tRadius -= task->tRadiusDelta >> 8;
if (task->tRadius < 0)
task->tRadius = 0;
2018-01-02 20:38:33 +01:00
}
2021-10-27 22:17:27 +02:00
SetCircularMask(gScanlineEffectRegBuffers[0], DISPLAY_WIDTH / 2, DISPLAY_HEIGHT / 2, task->tRadius);
if (task->tRadius == 0)
2018-01-02 20:38:33 +01:00
{
SetVBlankCallback(NULL);
DmaStop(0);
2020-06-01 16:17:25 +02:00
FadeScreenBlack();
2018-01-02 20:38:33 +01:00
DestroyTask(FindTaskIdByFunc(task->func));
}
else
{
2021-10-25 16:42:08 +02:00
if (!task->tVBlankSet)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
task->tVBlankSet++;
2021-10-27 22:17:27 +02:00
SetVBlankCallback(VBlankCB_CircularMask);
2018-01-02 20:38:33 +01:00
}
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA++;
2018-01-02 20:38:33 +01:00
}
return FALSE;
}
2021-10-27 22:17:27 +02:00
static void VBlankCB_SetWinAndBlend(void)
2018-01-02 20:38:33 +01:00
{
DmaStop(0);
VBlankCB_BattleTransition();
2021-10-25 16:42:08 +02:00
if (sTransitionData->VBlank_DMA)
DmaCopy16(3, gScanlineEffectRegBuffers[0], gScanlineEffectRegBuffers[1], DISPLAY_HEIGHT * 2);
REG_WININ = sTransitionData->WININ;
REG_WINOUT = sTransitionData->WINOUT;
REG_WIN0V = sTransitionData->WIN0V;
REG_BLDCNT = sTransitionData->BLDCNT;
REG_BLDALPHA = sTransitionData->BLDALPHA;
2018-01-02 20:38:33 +01:00
}
2021-10-25 16:42:08 +02:00
static void VBlankCB_PatternWeave(void)
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
VBlankCB_SetWinAndBlend();
2021-10-25 16:42:08 +02:00
DmaSet(0, gScanlineEffectRegBuffers[1], &REG_BG0HOFS, B_TRANS_DMA_FLAGS);
2018-01-02 20:38:33 +01:00
}
2021-10-27 22:17:27 +02:00
static void VBlankCB_CircularMask(void)
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
VBlankCB_SetWinAndBlend();
2021-10-25 16:42:08 +02:00
DmaSet(0, gScanlineEffectRegBuffers[1], &REG_WIN0H, B_TRANS_DMA_FLAGS);
2018-01-02 20:38:33 +01:00
}
2021-10-25 16:42:08 +02:00
#undef tAmplitude
#undef tSinIndex
#undef tBlendTarget1
#undef tBlendTarget2
2021-10-27 22:17:27 +02:00
#undef tRadius
#undef tRadiusDelta
2021-10-25 16:42:08 +02:00
#undef tVBlankSet
2021-10-27 22:17:27 +02:00
//------------------------------
// B_TRANSITION_POKEBALLS_TRAIL
//------------------------------
#define sSide data[0]
#define sDelay data[1]
#define sPrevX data[2]
static void Task_PokeballsTrail(u8 taskId)
2018-01-02 20:38:33 +01:00
{
while (sPokeballsTrail_Funcs[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-02 20:38:33 +01:00
}
2021-10-25 16:42:08 +02:00
static bool8 PokeballsTrail_Init(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2020-06-01 16:17:25 +02:00
u16 *tilemap, *tileset;
2018-01-02 20:38:33 +01:00
2020-06-01 16:17:25 +02:00
GetBg0TilesDst(&tilemap, &tileset);
CpuSet(sPokeballTrail_Tileset, tileset, 0x20);
2021-10-25 16:42:08 +02:00
CpuFill32(0, tilemap, BG_SCREEN_SIZE);
LoadPalette(sFieldEffectPal_Pokeball, 0xF0, sizeof(sFieldEffectPal_Pokeball));
2018-01-02 20:38:33 +01:00
task->tState++;
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 PokeballsTrail_Main(struct Task *task)
2018-01-02 20:38:33 +01:00
{
s16 i;
2021-10-27 22:17:27 +02:00
s16 side;
s16 startX[ARRAY_COUNT(sPokeballsTrail_StartXCoords)];
s16 delays[ARRAY_COUNT(sPokeballsTrail_Delays)];
memcpy(startX, sPokeballsTrail_StartXCoords, sizeof(sPokeballsTrail_StartXCoords));
memcpy(delays, sPokeballsTrail_Delays, sizeof(sPokeballsTrail_Delays));
// Randomly pick which side the first ball should start on.
// The side is then flipped for each subsequent ball.
side = Random() & 1;
for (i = 0; i < NUM_POKEBALL_TRAILS; i++, side ^= 1)
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
gFieldEffectArguments[0] = startX[side]; // x
gFieldEffectArguments[1] = (i * 32) + 16; // y
gFieldEffectArguments[2] = side;
gFieldEffectArguments[3] = delays[i];
FieldEffectStart(FLDEFF_POKEBALL_TRAIL);
2018-01-02 20:38:33 +01:00
}
task->tState++;
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 PokeballsTrail_End(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
if (!FieldEffectActiveListContains(FLDEFF_POKEBALL_TRAIL))
2018-01-02 20:38:33 +01:00
{
2020-06-01 16:17:25 +02:00
FadeScreenBlack();
DestroyTask(FindTaskIdByFunc(Task_PokeballsTrail));
2018-01-02 20:38:33 +01:00
}
return FALSE;
}
2021-10-27 22:17:27 +02:00
bool8 FldEff_PokeballTrail(void)
2018-01-02 20:38:33 +01:00
{
2020-06-01 16:17:25 +02:00
u8 spriteId = CreateSpriteAtEnd(&sSpriteTemplate_Pokeball, gFieldEffectArguments[0], gFieldEffectArguments[1], 0);
2018-01-02 20:38:33 +01:00
gSprites[spriteId].oam.priority = 0;
gSprites[spriteId].oam.affineMode = ST_OAM_AFFINE_NORMAL;
2021-10-27 22:17:27 +02:00
gSprites[spriteId].sSide = gFieldEffectArguments[2];
gSprites[spriteId].sDelay = gFieldEffectArguments[3];
gSprites[spriteId].sPrevX = -1;
2018-01-02 20:38:33 +01:00
InitSpriteAffineAnim(&gSprites[spriteId]);
StartSpriteAffineAnim(&gSprites[spriteId], gFieldEffectArguments[2]);
return FALSE;
}
2021-10-27 22:17:27 +02:00
static void SpriteCB_FldEffPokeballTrail(struct Sprite *sprite)
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
s16 speeds[ARRAY_COUNT(sPokeballsTrail_Speeds)];
memcpy(speeds, sPokeballsTrail_Speeds, sizeof(sPokeballsTrail_Speeds));
2018-01-02 20:38:33 +01:00
2021-10-27 22:17:27 +02:00
if (sprite->sDelay != 0)
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
sprite->sDelay--;
2018-01-02 20:38:33 +01:00
}
else
{
2021-07-07 15:11:52 +02:00
if (sprite->x >= 0 && sprite->x <= DISPLAY_WIDTH)
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
// Set Pokéball position
2021-07-07 15:11:52 +02:00
s16 posX = sprite->x >> 3;
s16 posY = sprite->y >> 3;
2018-01-02 20:38:33 +01:00
2021-10-27 22:17:27 +02:00
// If Pokéball moved forward clear trail behind it
if (posX != sprite->sPrevX)
2018-01-02 20:38:33 +01:00
{
u32 var;
u16 *ptr;
2021-10-27 22:17:27 +02:00
sprite->sPrevX = posX;
var = ((REG_BG0CNT >> 8) & 0x1F) << 11;
ptr = (u16 *)(BG_VRAM + var);
2018-01-02 20:38:33 +01:00
2021-10-27 22:17:27 +02:00
SET_TILE(ptr, posY - 2, posX, 1);
SET_TILE(ptr, posY - 1, posX, 1);
SET_TILE(ptr, posY - 0, posX, 1);
SET_TILE(ptr, posY + 1, posX, 1);
2018-01-02 20:38:33 +01:00
}
}
2021-10-27 22:17:27 +02:00
sprite->x += speeds[sprite->sSide];
2021-10-25 16:42:08 +02:00
if (sprite->x < -15 || sprite->x > DISPLAY_WIDTH + 15)
2021-10-27 22:17:27 +02:00
FieldEffectStop(sprite, FLDEFF_POKEBALL_TRAIL);
2018-01-02 20:38:33 +01:00
}
}
2021-10-27 22:17:27 +02:00
#undef sSide
#undef sDelay
#undef sPrevX
//-----------------------------
// B_TRANSITION_CLOCKWISE_WIPE
//-----------------------------
2021-10-25 16:42:08 +02:00
2021-10-27 22:17:27 +02:00
static void Task_ClockwiseWipe(u8 taskId)
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
while (sClockwiseWipe_Funcs[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-02 20:38:33 +01:00
}
2021-10-27 22:17:27 +02:00
static bool8 ClockwiseWipe_Init(struct Task *task)
2018-01-02 20:38:33 +01:00
{
u16 i;
2021-10-25 16:42:08 +02:00
InitTransitionData();
2018-01-29 17:47:12 +01:00
ScanlineEffect_Clear();
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
sTransitionData->WININ = 0;
sTransitionData->WINOUT = WINOUT_WIN01_ALL;
sTransitionData->WIN0H = WIN_RANGE(DISPLAY_WIDTH, DISPLAY_WIDTH + 1);
sTransitionData->WIN0V = DISPLAY_HEIGHT;
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
for (i = 0; i < DISPLAY_HEIGHT; i++)
2021-10-27 22:17:27 +02:00
gScanlineEffectRegBuffers[1][i] = ((DISPLAY_WIDTH + 3) << 8) | (DISPLAY_WIDTH + 4);
2018-01-02 20:38:33 +01:00
2021-10-27 22:17:27 +02:00
SetVBlankCallback(VBlankCB_ClockwiseWipe);
sTransitionData->tWipeEndX = DISPLAY_WIDTH / 2;
2018-01-02 20:38:33 +01:00
task->tState++;
return TRUE;
}
2021-10-27 22:17:27 +02:00
static bool8 ClockwiseWipe_TopRight(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA = FALSE;
2018-01-02 20:38:33 +01:00
2021-10-27 22:17:27 +02:00
InitBlackWipe(sTransitionData->data, DISPLAY_WIDTH / 2, DISPLAY_HEIGHT / 2, sTransitionData->tWipeEndX, -1, 1, 1);
2018-01-02 20:38:33 +01:00
do
{
2021-10-27 22:17:27 +02:00
gScanlineEffectRegBuffers[0][sTransitionData->tWipeCurrY] = (sTransitionData->tWipeCurrX + 1) | ((DISPLAY_WIDTH / 2) << 8);
} while (!UpdateBlackWipe(sTransitionData->data, TRUE, TRUE));
2018-01-02 20:38:33 +01:00
2021-10-27 22:17:27 +02:00
sTransitionData->tWipeEndX += 16;
if (sTransitionData->tWipeEndX >= DISPLAY_WIDTH)
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
sTransitionData->tWipeEndY = 0;
2018-01-02 20:38:33 +01:00
task->tState++;
}
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA++;
2018-01-02 20:38:33 +01:00
return FALSE;
}
2021-10-27 22:17:27 +02:00
static bool8 ClockwiseWipe_Right(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
s16 start, end;
vu8 finished = FALSE;
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA = FALSE;
2018-01-02 20:38:33 +01:00
2021-10-27 22:17:27 +02:00
InitBlackWipe(sTransitionData->data, DISPLAY_WIDTH / 2, DISPLAY_HEIGHT / 2, DISPLAY_WIDTH, sTransitionData->tWipeEndY, 1, 1);
2018-01-02 20:38:33 +01:00
while (1)
{
2021-10-27 22:17:27 +02:00
start = DISPLAY_WIDTH / 2, end = sTransitionData->tWipeCurrX + 1;
if (sTransitionData->tWipeEndY >= DISPLAY_HEIGHT / 2)
start = sTransitionData->tWipeCurrX, end = DISPLAY_WIDTH;
gScanlineEffectRegBuffers[0][sTransitionData->tWipeCurrY] = end | (start << 8);
if (finished)
2018-01-02 20:38:33 +01:00
break;
2021-10-27 22:17:27 +02:00
finished = UpdateBlackWipe(sTransitionData->data, TRUE, TRUE);
2018-01-02 20:38:33 +01:00
}
2021-10-27 22:17:27 +02:00
sTransitionData->tWipeEndY += 8;
if (sTransitionData->tWipeEndY >= DISPLAY_HEIGHT)
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
sTransitionData->tWipeEndX = DISPLAY_WIDTH;
2018-01-02 20:38:33 +01:00
task->tState++;
}
else
{
2021-10-27 22:17:27 +02:00
while (sTransitionData->tWipeCurrY < sTransitionData->tWipeEndY)
gScanlineEffectRegBuffers[0][++sTransitionData->tWipeCurrY] = end | (start << 8);
2018-01-02 20:38:33 +01:00
}
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA++;
2018-01-02 20:38:33 +01:00
return FALSE;
}
2021-10-27 22:17:27 +02:00
static bool8 ClockwiseWipe_Bottom(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA = FALSE;
2018-01-02 20:38:33 +01:00
2021-10-27 22:17:27 +02:00
InitBlackWipe(sTransitionData->data, DISPLAY_WIDTH / 2, DISPLAY_HEIGHT / 2, sTransitionData->tWipeEndX, DISPLAY_HEIGHT, 1, 1);
2018-01-02 20:38:33 +01:00
do
{
2021-10-27 22:17:27 +02:00
gScanlineEffectRegBuffers[0][sTransitionData->tWipeCurrY] = (sTransitionData->tWipeCurrX << 8) | DISPLAY_WIDTH;
} while (!UpdateBlackWipe(sTransitionData->data, TRUE, TRUE));
2018-01-02 20:38:33 +01:00
2021-10-27 22:17:27 +02:00
sTransitionData->tWipeEndX -= 16;
if (sTransitionData->tWipeEndX <= 0)
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
sTransitionData->tWipeEndY = DISPLAY_HEIGHT;
2018-01-02 20:38:33 +01:00
task->tState++;
}
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA++;
2018-01-02 20:38:33 +01:00
return FALSE;
}
2021-10-27 22:17:27 +02:00
static bool8 ClockwiseWipe_Left(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
s16 end, start, temp;
vu8 finished = FALSE;
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA = FALSE;
2018-01-02 20:38:33 +01:00
2021-10-27 22:17:27 +02:00
InitBlackWipe(sTransitionData->data, DISPLAY_WIDTH / 2, DISPLAY_HEIGHT / 2, 0, sTransitionData->tWipeEndY, 1, 1);
2018-01-02 20:38:33 +01:00
while (1)
{
2021-10-27 22:17:27 +02:00
end = (gScanlineEffectRegBuffers[0][sTransitionData->tWipeCurrY]) & 0xFF;
start = sTransitionData->tWipeCurrX;
if (sTransitionData->tWipeEndY <= DISPLAY_HEIGHT / 2)
start = DISPLAY_WIDTH / 2, end = sTransitionData->tWipeCurrX;
temp = end | (start << 8);
gScanlineEffectRegBuffers[0][sTransitionData->tWipeCurrY] = temp;
if (finished)
2018-01-02 20:38:33 +01:00
break;
2021-10-27 22:17:27 +02:00
finished = UpdateBlackWipe(sTransitionData->data, TRUE, TRUE);
2018-01-02 20:38:33 +01:00
}
2021-10-27 22:17:27 +02:00
sTransitionData->tWipeEndY -= 8;
if (sTransitionData->tWipeEndY <= 0)
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
sTransitionData->tWipeEndX = 0;
2018-01-02 20:38:33 +01:00
task->tState++;
}
else
{
2021-10-27 22:17:27 +02:00
while (sTransitionData->tWipeCurrY > sTransitionData->tWipeEndY)
gScanlineEffectRegBuffers[0][--sTransitionData->tWipeCurrY] = end | (start << 8);
2018-01-02 20:38:33 +01:00
}
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA++;
2018-01-02 20:38:33 +01:00
return FALSE;
}
2021-10-27 22:17:27 +02:00
static bool8 ClockwiseWipe_TopLeft(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA = FALSE;
2018-01-02 20:38:33 +01:00
2021-10-27 22:17:27 +02:00
InitBlackWipe(sTransitionData->data, DISPLAY_WIDTH / 2, DISPLAY_HEIGHT / 2, sTransitionData->tWipeEndX, 0, 1, 1);
2018-01-02 20:38:33 +01:00
do
{
2021-10-27 22:17:27 +02:00
s16 start, end;
start = DISPLAY_WIDTH / 2, end = sTransitionData->tWipeCurrX;
if (sTransitionData->tWipeCurrX >= DISPLAY_WIDTH / 2)
start = 0, end = DISPLAY_WIDTH;
gScanlineEffectRegBuffers[0][sTransitionData->tWipeCurrY] = end | (start << 8);
} while (!UpdateBlackWipe(sTransitionData->data, TRUE, TRUE));
sTransitionData->tWipeEndX += 16;
if (sTransitionData->tWipeCurrX > DISPLAY_WIDTH / 2)
2018-01-02 20:38:33 +01:00
task->tState++;
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA++;
2018-01-02 20:38:33 +01:00
return FALSE;
}
2021-10-27 22:17:27 +02:00
static bool8 ClockwiseWipe_End(struct Task *task)
2018-01-02 20:38:33 +01:00
{
DmaStop(0);
2020-06-01 16:17:25 +02:00
FadeScreenBlack();
2021-10-27 22:17:27 +02:00
DestroyTask(FindTaskIdByFunc(Task_ClockwiseWipe));
2018-01-02 20:38:33 +01:00
return FALSE;
}
2021-10-27 22:17:27 +02:00
static void VBlankCB_ClockwiseWipe(void)
2018-01-02 20:38:33 +01:00
{
DmaStop(0);
VBlankCB_BattleTransition();
2021-10-25 16:42:08 +02:00
if (sTransitionData->VBlank_DMA != 0)
DmaCopy16(3, gScanlineEffectRegBuffers[0], gScanlineEffectRegBuffers[1], DISPLAY_HEIGHT * 2);
REG_WININ = sTransitionData->WININ;
REG_WINOUT = sTransitionData->WINOUT;
REG_WIN0V = sTransitionData->WIN0V;
2018-01-29 17:47:12 +01:00
REG_WIN0H = gScanlineEffectRegBuffers[1][0];
2021-10-25 16:42:08 +02:00
DmaSet(0, gScanlineEffectRegBuffers[1], &REG_WIN0H, B_TRANS_DMA_FLAGS);
2018-01-02 20:38:33 +01:00
}
2021-10-27 22:17:27 +02:00
//---------------------
// B_TRANSITION_RIPPLE
//---------------------
#define tSinVal data[1]
#define tAmplitudeVal data[2]
#define tTimer data[3]
#define tFadeStarted data[4]
static void Task_Ripple(u8 taskId)
2018-01-02 20:38:33 +01:00
{
while (sRipple_Funcs[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-02 20:38:33 +01:00
}
2021-10-25 16:42:08 +02:00
static bool8 Ripple_Init(struct Task *task)
2018-01-02 20:38:33 +01:00
{
u8 i;
2021-10-25 16:42:08 +02:00
InitTransitionData();
2018-01-29 17:47:12 +01:00
ScanlineEffect_Clear();
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
for (i = 0; i < DISPLAY_HEIGHT; i++)
gScanlineEffectRegBuffers[1][i] = sTransitionData->cameraY;
2018-01-02 20:38:33 +01:00
SetVBlankCallback(VBlankCB_Ripple);
SetHBlankCallback(HBlankCB_Ripple);
2018-01-02 20:38:33 +01:00
EnableInterrupts(INTR_FLAG_HBLANK);
task->tState++;
return TRUE;
}
2021-10-27 22:17:27 +02:00
static bool8 Ripple_Main(struct Task *task)
2018-01-02 20:38:33 +01:00
{
u8 i;
2021-10-27 22:17:27 +02:00
s16 amplitude;
u16 sinVal, speed;
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA = FALSE;
2018-01-02 20:38:33 +01:00
2021-10-27 22:17:27 +02:00
amplitude = task->tAmplitudeVal >> 8;
sinVal = task->tSinVal;
speed = 0x180;
task->tSinVal += 0x400;
if (task->tAmplitudeVal <= 0x1FFF)
task->tAmplitudeVal += 0x180;
2018-01-02 20:38:33 +01:00
2021-10-27 22:17:27 +02:00
for (i = 0; i < DISPLAY_HEIGHT; i++, sinVal += speed)
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
s16 sinIndex = sinVal >> 8;
gScanlineEffectRegBuffers[0][i] = sTransitionData->cameraY + Sin(sinIndex & 0xffff, amplitude);
2018-01-02 20:38:33 +01:00
}
2021-10-27 22:17:27 +02:00
if (++task->tTimer == 81)
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
task->tFadeStarted++;
2021-10-25 16:42:08 +02:00
BeginNormalPaletteFade(PALETTES_ALL, -2, 0, 16, RGB_BLACK);
2018-01-02 20:38:33 +01:00
}
2021-10-27 22:17:27 +02:00
if (task->tFadeStarted && !gPaletteFade.active)
DestroyTask(FindTaskIdByFunc(Task_Ripple));
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA++;
2018-01-02 20:38:33 +01:00
return FALSE;
}
static void VBlankCB_Ripple(void)
2018-01-02 20:38:33 +01:00
{
VBlankCB_BattleTransition();
2021-10-25 16:42:08 +02:00
if (sTransitionData->VBlank_DMA)
DmaCopy16(3, gScanlineEffectRegBuffers[0], gScanlineEffectRegBuffers[1], DISPLAY_HEIGHT * 2);
2018-01-02 20:38:33 +01:00
}
static void HBlankCB_Ripple(void)
2018-01-02 20:38:33 +01:00
{
2018-01-29 17:47:12 +01:00
u16 var = gScanlineEffectRegBuffers[1][REG_VCOUNT];
2018-01-02 20:38:33 +01:00
REG_BG1VOFS = var;
REG_BG2VOFS = var;
REG_BG3VOFS = var;
}
2021-10-27 22:17:27 +02:00
#undef tSinVal
#undef tAmplitudeVal
#undef tTimer
#undef tFadeStarted
//-------------------
2021-10-25 16:42:08 +02:00
// B_TRANSITION_WAVE
2021-10-27 22:17:27 +02:00
//-------------------
#define tX data[1]
#define tSinIndex data[2]
static void Task_Wave(u8 taskId)
2018-01-02 20:38:33 +01:00
{
while (sWave_Funcs[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-02 20:38:33 +01:00
}
2021-10-25 16:42:08 +02:00
static bool8 Wave_Init(struct Task *task)
2018-01-02 20:38:33 +01:00
{
u8 i;
2021-10-25 16:42:08 +02:00
InitTransitionData();
2018-01-29 17:47:12 +01:00
ScanlineEffect_Clear();
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
sTransitionData->WININ = WININ_WIN0_ALL;
sTransitionData->WINOUT = 0;
sTransitionData->WIN0H = DISPLAY_WIDTH;
sTransitionData->WIN0V = DISPLAY_HEIGHT;
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
for (i = 0; i < DISPLAY_HEIGHT; i++)
gScanlineEffectRegBuffers[1][i] = DISPLAY_WIDTH + 2;
2018-01-02 20:38:33 +01:00
SetVBlankCallback(VBlankCB_Wave);
2018-01-02 20:38:33 +01:00
task->tState++;
return TRUE;
}
2021-10-27 22:17:27 +02:00
static bool8 Wave_Main(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
u8 i, sinIndex;
2018-01-02 20:38:33 +01:00
u16* toStore;
2021-10-27 22:17:27 +02:00
bool8 finished;
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA = FALSE;
2018-01-29 17:47:12 +01:00
toStore = gScanlineEffectRegBuffers[0];
2021-10-27 22:17:27 +02:00
sinIndex = task->tSinIndex;
task->tSinIndex += 16;
task->tX += 8;
2018-01-02 20:38:33 +01:00
2021-10-27 22:17:27 +02:00
for (i = 0, finished = TRUE; i < DISPLAY_HEIGHT; i++, sinIndex += 4, toStore++)
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
s16 x = task->tX + Sin(sinIndex, 40);
if (x < 0)
x = 0;
if (x > DISPLAY_WIDTH)
x = DISPLAY_WIDTH;
*toStore = (x << 8) | (DISPLAY_WIDTH + 1);
if (x < DISPLAY_WIDTH)
finished = FALSE;
2018-01-02 20:38:33 +01:00
}
2021-10-27 22:17:27 +02:00
if (finished)
2018-01-02 20:38:33 +01:00
task->tState++;
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA++;
2018-01-02 20:38:33 +01:00
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 Wave_End(struct Task *task)
2018-01-02 20:38:33 +01:00
{
DmaStop(0);
2020-06-01 16:17:25 +02:00
FadeScreenBlack();
DestroyTask(FindTaskIdByFunc(Task_Wave));
2018-01-02 20:38:33 +01:00
return FALSE;
}
static void VBlankCB_Wave(void)
2018-01-02 20:38:33 +01:00
{
DmaStop(0);
VBlankCB_BattleTransition();
2021-10-25 16:42:08 +02:00
if (sTransitionData->VBlank_DMA != 0)
DmaCopy16(3, gScanlineEffectRegBuffers[0], gScanlineEffectRegBuffers[1], DISPLAY_HEIGHT * 2);
REG_WININ = sTransitionData->WININ;
REG_WINOUT = sTransitionData->WINOUT;
REG_WIN0V = sTransitionData->WIN0V;
DmaSet(0, gScanlineEffectRegBuffers[1], &REG_WIN0H, B_TRANS_DMA_FLAGS);
2018-01-02 20:38:33 +01:00
}
2021-10-27 22:17:27 +02:00
#undef tX
#undef tSinIndex
//----------------------------------------------------------------
// B_TRANSITION_SIDNEY, B_TRANSITION_PHOEBE, B_TRANSITION_GLACIA,
// B_TRANSITION_DRAKE, and B_TRANSITION_CHAMPION
//
// These are all the "mugshot" transitions, where a banner shows
// the trainer pic of the player and their opponent.
//----------------------------------------------------------------
#define tSinIndex data[1]
#define tTopBannerX data[2]
#define tBottomBannerX data[3]
#define tTimer data[3] // Re-used
#define tFadeSpread data[4]
#define tOpponentSpriteId data[13]
#define tPlayerSpriteId data[14]
#define tMugshotId data[15]
// Sprite data for trainer sprites in mugshots
#define sState data[0]
#define sSlideSpeed data[1]
#define sSlideAccel data[2]
#define sDone data[6]
#define sSlideDir data[7]
static void Task_Sidney(u8 taskId)
2018-01-02 20:38:33 +01:00
{
2019-04-16 16:40:32 +02:00
gTasks[taskId].tMugshotId = MUGSHOT_SIDNEY;
2021-10-25 16:42:08 +02:00
DoMugshotTransition(taskId);
2018-01-02 20:38:33 +01:00
}
static void Task_Phoebe(u8 taskId)
2018-01-02 20:38:33 +01:00
{
gTasks[taskId].tMugshotId = MUGSHOT_PHOEBE;
2021-10-25 16:42:08 +02:00
DoMugshotTransition(taskId);
2018-01-02 20:38:33 +01:00
}
static void Task_Glacia(u8 taskId)
2018-01-02 20:38:33 +01:00
{
gTasks[taskId].tMugshotId = MUGSHOT_GLACIA;
2021-10-25 16:42:08 +02:00
DoMugshotTransition(taskId);
2018-01-02 20:38:33 +01:00
}
static void Task_Drake(u8 taskId)
2018-01-02 20:38:33 +01:00
{
gTasks[taskId].tMugshotId = MUGSHOT_DRAKE;
2021-10-25 16:42:08 +02:00
DoMugshotTransition(taskId);
2018-01-02 20:38:33 +01:00
}
static void Task_Champion(u8 taskId)
2018-01-02 20:38:33 +01:00
{
gTasks[taskId].tMugshotId = MUGSHOT_CHAMPION;
2021-10-25 16:42:08 +02:00
DoMugshotTransition(taskId);
2018-01-02 20:38:33 +01:00
}
2021-10-25 16:42:08 +02:00
static void DoMugshotTransition(u8 taskId)
2018-01-02 20:38:33 +01:00
{
while (sMugshot_Funcs[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-02 20:38:33 +01:00
}
2021-10-25 16:42:08 +02:00
static bool8 Mugshot_Init(struct Task *task)
2018-01-02 20:38:33 +01:00
{
u8 i;
2021-10-25 16:42:08 +02:00
InitTransitionData();
2018-01-29 17:47:12 +01:00
ScanlineEffect_Clear();
2021-10-25 16:42:08 +02:00
Mugshots_CreateTrainerPics(task);
2018-01-02 20:38:33 +01:00
2021-10-27 22:17:27 +02:00
task->tSinIndex = 0;
task->tTopBannerX = 1;
task->tBottomBannerX = DISPLAY_WIDTH - 1;
2021-10-25 16:42:08 +02:00
sTransitionData->WININ = WININ_WIN0_ALL;
sTransitionData->WINOUT = WINOUT_WIN01_BG1 | WINOUT_WIN01_BG2 | WINOUT_WIN01_BG3 | WINOUT_WIN01_OBJ | WINOUT_WIN01_CLR;
sTransitionData->WIN0V = DISPLAY_HEIGHT;
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
for (i = 0; i < DISPLAY_HEIGHT; i++)
2021-10-27 22:17:27 +02:00
gScanlineEffectRegBuffers[1][i] = (DISPLAY_WIDTH << 8) | (DISPLAY_WIDTH + 1);
2018-01-02 20:38:33 +01:00
2021-10-27 22:17:27 +02:00
SetVBlankCallback(VBlankCB_Mugshots);
2018-01-02 20:38:33 +01:00
task->tState++;
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 Mugshot_SetGfx(struct Task *task)
2018-01-02 20:38:33 +01:00
{
s16 i, j;
2020-06-01 16:17:25 +02:00
u16 *tilemap, *tileset;
const u16 *mugshotsMap;
2018-01-02 20:38:33 +01:00
2020-06-01 16:17:25 +02:00
mugshotsMap = sMugshotsTilemap;
GetBg0TilesDst(&tilemap, &tileset);
CpuSet(sEliteFour_Tileset, tileset, 0xF0);
2018-01-02 20:38:33 +01:00
LoadPalette(sOpponentMugshotsPals[task->tMugshotId], 0xF0, 0x20);
LoadPalette(sPlayerMugshotsPals[gSaveBlock2Ptr->playerGender], 0xFA, 0xC);
for (i = 0; i < 20; i++)
{
2020-06-01 16:17:25 +02:00
for (j = 0; j < 32; j++, mugshotsMap++)
2021-10-27 22:17:27 +02:00
SET_TILE(tilemap, i, j, *mugshotsMap);
2018-01-02 20:38:33 +01:00
}
EnableInterrupts(INTR_FLAG_HBLANK);
SetHBlankCallback(HBlankCB_Mugshots);
2018-01-02 20:38:33 +01:00
task->tState++;
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 Mugshot_ShowBanner(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
u8 i, sinIndex;
2018-01-02 20:38:33 +01:00
u16* toStore;
2021-10-27 22:17:27 +02:00
s16 x;
2018-01-02 20:38:33 +01:00
s32 mergedValue;
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA = FALSE;
2018-01-02 20:38:33 +01:00
2018-01-29 17:47:12 +01:00
toStore = gScanlineEffectRegBuffers[0];
2021-10-27 22:17:27 +02:00
sinIndex = task->tSinIndex;
task->tSinIndex += 16;
2018-01-02 20:38:33 +01:00
2021-10-27 22:17:27 +02:00
// Update top banner
for (i = 0; i < DISPLAY_HEIGHT / 2; i++, toStore++, sinIndex += 16)
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
x = task->tTopBannerX + Sin(sinIndex, 16);
if (x < 0)
x = 1;
if (x > DISPLAY_WIDTH)
x = DISPLAY_WIDTH;
*toStore = x;
2018-01-02 20:38:33 +01:00
}
2021-10-27 22:17:27 +02:00
// Update bottom banner
for (; i < DISPLAY_HEIGHT; i++, toStore++, sinIndex += 16)
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
x = task->tBottomBannerX - Sin(sinIndex, 16);
if (x < 0)
x = 0;
if (x > DISPLAY_WIDTH - 1)
x = DISPLAY_WIDTH - 1;
*toStore = (x << 8) | DISPLAY_WIDTH;
2018-01-02 20:38:33 +01:00
}
2021-10-27 22:17:27 +02:00
// Slide banners across screen
task->tTopBannerX += 8;
task->tBottomBannerX -= 8;
if (task->tTopBannerX > DISPLAY_WIDTH)
task->tTopBannerX = DISPLAY_WIDTH;
if (task->tBottomBannerX < 0)
task->tBottomBannerX = 0;
mergedValue = *(s32*)(&task->tTopBannerX);
2021-10-25 16:42:08 +02:00
if (mergedValue == DISPLAY_WIDTH)
2018-01-02 20:38:33 +01:00
task->tState++;
2021-10-25 16:42:08 +02:00
sTransitionData->BG0HOFS_Lower -= 8;
sTransitionData->BG0HOFS_Upper += 8;
sTransitionData->VBlank_DMA++;
2018-01-02 20:38:33 +01:00
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 Mugshot_StartOpponentSlide(struct Task *task)
2018-01-02 20:38:33 +01:00
{
u8 i;
u16* toStore;
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA = FALSE;
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
for (i = 0, toStore = gScanlineEffectRegBuffers[0]; i < DISPLAY_HEIGHT; i++, toStore++)
*toStore = DISPLAY_WIDTH;
2018-01-02 20:38:33 +01:00
task->tState++;
2021-10-27 22:17:27 +02:00
// Clear old data
task->tSinIndex = 0;
task->tTopBannerX = 0;
task->tBottomBannerX = 0;
2021-10-25 16:42:08 +02:00
sTransitionData->BG0HOFS_Lower -= 8;
sTransitionData->BG0HOFS_Upper += 8;
2018-01-02 20:38:33 +01:00
2021-10-27 22:17:27 +02:00
SetTrainerPicSlideDirection(task->tOpponentSpriteId, 0);
SetTrainerPicSlideDirection(task->tPlayerSpriteId, 1);
// Start opponent slide
2020-06-01 16:17:25 +02:00
IncrementTrainerPicState(task->tOpponentSpriteId);
2018-01-02 20:38:33 +01:00
2020-08-21 00:02:00 +02:00
PlaySE(SE_MUGSHOT);
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA++;
2018-01-02 20:38:33 +01:00
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 Mugshot_WaitStartPlayerSlide(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
sTransitionData->BG0HOFS_Lower -= 8;
sTransitionData->BG0HOFS_Upper += 8;
2021-10-27 22:17:27 +02:00
// Start player's slide in once the opponent is finished
2020-06-01 16:17:25 +02:00
if (IsTrainerPicSlideDone(task->tOpponentSpriteId))
2018-01-02 20:38:33 +01:00
{
task->tState++;
2020-06-01 16:17:25 +02:00
IncrementTrainerPicState(task->tPlayerSpriteId);
2018-01-02 20:38:33 +01:00
}
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 Mugshot_WaitPlayerSlide(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
sTransitionData->BG0HOFS_Lower -= 8;
sTransitionData->BG0HOFS_Upper += 8;
2020-06-01 16:17:25 +02:00
if (IsTrainerPicSlideDone(task->tPlayerSpriteId))
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA = FALSE;
2018-01-02 20:38:33 +01:00
SetVBlankCallback(NULL);
DmaStop(0);
2021-10-25 16:42:08 +02:00
memset(gScanlineEffectRegBuffers[0], 0, DISPLAY_HEIGHT * 2);
memset(gScanlineEffectRegBuffers[1], 0, DISPLAY_HEIGHT * 2);
2021-04-15 08:04:01 +02:00
SetGpuReg(REG_OFFSET_WIN0H, DISPLAY_WIDTH);
2018-01-02 20:38:33 +01:00
SetGpuReg(REG_OFFSET_BLDY, 0);
task->tState++;
2021-10-27 22:17:27 +02:00
task->tTimer = 0;
task->tFadeSpread = 0;
2021-10-25 16:42:08 +02:00
sTransitionData->BLDCNT = BLDCNT_TGT1_ALL | BLDCNT_EFFECT_LIGHTEN;
2021-10-27 22:17:27 +02:00
SetVBlankCallback(VBlankCB_MugshotsFadeOut);
2018-01-02 20:38:33 +01:00
}
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 Mugshot_GradualWhiteFade(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
bool32 active;
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA = FALSE;
active = TRUE;
sTransitionData->BG0HOFS_Lower -= 8;
sTransitionData->BG0HOFS_Upper += 8;
2018-01-02 20:38:33 +01:00
2021-10-27 22:17:27 +02:00
if (task->tFadeSpread < DISPLAY_HEIGHT / 2)
task->tFadeSpread += 2;
if (task->tFadeSpread > DISPLAY_HEIGHT / 2)
task->tFadeSpread = DISPLAY_HEIGHT / 2;
2018-01-02 20:38:33 +01:00
2021-10-27 22:17:27 +02:00
if (++task->tTimer & 1)
2018-01-02 20:38:33 +01:00
{
s16 i;
2021-10-27 22:17:27 +02:00
for (i = 0, active = FALSE; i <= task->tFadeSpread; i++)
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
// Fade starts in middle of screen and
// spreads outwards in both directions.
2021-10-25 16:42:08 +02:00
s16 index1 = DISPLAY_HEIGHT / 2 - i;
s16 index2 = DISPLAY_HEIGHT / 2 + i;
2018-01-29 17:47:12 +01:00
if (gScanlineEffectRegBuffers[0][index1] <= 15)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
active = TRUE;
2018-01-29 17:47:12 +01:00
gScanlineEffectRegBuffers[0][index1]++;
2018-01-02 20:38:33 +01:00
}
2018-01-29 17:47:12 +01:00
if (gScanlineEffectRegBuffers[0][index2] <= 15)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
active = TRUE;
2018-01-29 17:47:12 +01:00
gScanlineEffectRegBuffers[0][index2]++;
2018-01-02 20:38:33 +01:00
}
}
}
2021-10-27 22:17:27 +02:00
if (task->tFadeSpread == DISPLAY_HEIGHT / 2 && !active)
2018-01-02 20:38:33 +01:00
task->tState++;
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA++;
2018-01-02 20:38:33 +01:00
return FALSE;
}
2021-10-27 22:17:27 +02:00
// Set palette to white to replace the scanline white fade
// before the screen fades to black.
2021-10-25 16:42:08 +02:00
static bool8 Mugshot_InitFadeWhiteToBlack(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA = FALSE;
BlendPalettes(PALETTES_ALL, 16, RGB_WHITE);
sTransitionData->BLDCNT = 0xFF;
2021-10-27 22:17:27 +02:00
task->tTimer = 0;
2018-01-02 20:38:33 +01:00
task->tState++;
return TRUE;
}
2021-10-25 16:42:08 +02:00
static bool8 Mugshot_FadeToBlack(struct Task *task)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA = FALSE;
2018-01-02 20:38:33 +01:00
2021-10-27 22:17:27 +02:00
task->tTimer++;
memset(gScanlineEffectRegBuffers[0], task->tTimer, DISPLAY_HEIGHT * 2);
if (task->tTimer > 15)
2018-01-02 20:38:33 +01:00
task->tState++;
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA++;
2018-01-02 20:38:33 +01:00
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 Mugshot_End(struct Task *task)
2018-01-02 20:38:33 +01:00
{
DmaStop(0);
2020-06-01 16:17:25 +02:00
FadeScreenBlack();
2018-01-02 20:38:33 +01:00
DestroyTask(FindTaskIdByFunc(task->func));
return FALSE;
}
2021-10-27 22:17:27 +02:00
static void VBlankCB_Mugshots(void)
2018-01-02 20:38:33 +01:00
{
DmaStop(0);
VBlankCB_BattleTransition();
2021-10-25 16:42:08 +02:00
if (sTransitionData->VBlank_DMA != 0)
DmaCopy16(3, gScanlineEffectRegBuffers[0], gScanlineEffectRegBuffers[1], DISPLAY_HEIGHT * 2);
REG_BG0VOFS = sTransitionData->BG0VOFS;
REG_WININ = sTransitionData->WININ;
REG_WINOUT = sTransitionData->WINOUT;
REG_WIN0V = sTransitionData->WIN0V;
DmaSet(0, gScanlineEffectRegBuffers[1], &REG_WIN0H, B_TRANS_DMA_FLAGS);
2018-01-02 20:38:33 +01:00
}
2021-10-27 22:17:27 +02:00
static void VBlankCB_MugshotsFadeOut(void)
2018-01-02 20:38:33 +01:00
{
DmaStop(0);
VBlankCB_BattleTransition();
2021-10-25 16:42:08 +02:00
if (sTransitionData->VBlank_DMA != 0)
DmaCopy16(3, gScanlineEffectRegBuffers[0], gScanlineEffectRegBuffers[1], DISPLAY_HEIGHT * 2);
REG_BLDCNT = sTransitionData->BLDCNT;
DmaSet(0, gScanlineEffectRegBuffers[1], &REG_BLDY, B_TRANS_DMA_FLAGS);
2018-01-02 20:38:33 +01:00
}
static void HBlankCB_Mugshots(void)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
if (REG_VCOUNT < DISPLAY_HEIGHT / 2)
REG_BG0HOFS = sTransitionData->BG0HOFS_Lower;
2018-01-02 20:38:33 +01:00
else
2021-10-25 16:42:08 +02:00
REG_BG0HOFS = sTransitionData->BG0HOFS_Upper;
2018-01-02 20:38:33 +01:00
}
2021-10-25 16:42:08 +02:00
static void Mugshots_CreateTrainerPics(struct Task *task)
2018-01-02 20:38:33 +01:00
{
struct Sprite *opponentSprite, *playerSprite;
s16 mugshotId = task->tMugshotId;
task->tOpponentSpriteId = CreateTrainerSprite(sMugshotsTrainerPicIDsTable[mugshotId],
2021-10-27 22:17:27 +02:00
sMugshotsOpponentCoords[mugshotId][0] - 32,
sMugshotsOpponentCoords[mugshotId][1] + 42,
0, gDecompressionBuffer);
2021-10-25 16:42:08 +02:00
task->tPlayerSpriteId = CreateTrainerSprite(PlayerGenderToFrontTrainerPicId(gSaveBlock2Ptr->playerGender),
2021-10-27 22:17:27 +02:00
DISPLAY_WIDTH + 32,
106,
0, gDecompressionBuffer);
2018-01-02 20:38:33 +01:00
opponentSprite = &gSprites[task->tOpponentSpriteId];
playerSprite = &gSprites[task->tPlayerSpriteId];
2021-10-25 16:42:08 +02:00
opponentSprite->callback = SpriteCB_MugshotTrainerPic;
playerSprite->callback = SpriteCB_MugshotTrainerPic;
2018-01-02 20:38:33 +01:00
opponentSprite->oam.affineMode = ST_OAM_AFFINE_DOUBLE;
playerSprite->oam.affineMode = ST_OAM_AFFINE_DOUBLE;
2018-01-02 20:38:33 +01:00
opponentSprite->oam.matrixNum = AllocOamMatrix();
playerSprite->oam.matrixNum = AllocOamMatrix();
opponentSprite->oam.shape = SPRITE_SHAPE(64x32);
playerSprite->oam.shape = SPRITE_SHAPE(64x32);
2018-01-02 20:38:33 +01:00
opponentSprite->oam.size = SPRITE_SIZE(64x32);
playerSprite->oam.size = SPRITE_SIZE(64x32);
2018-01-02 20:38:33 +01:00
CalcCenterToCornerVec(opponentSprite, SPRITE_SHAPE(64x32), SPRITE_SIZE(64x32), ST_OAM_AFFINE_DOUBLE);
CalcCenterToCornerVec(playerSprite, SPRITE_SHAPE(64x32), SPRITE_SIZE(64x32), ST_OAM_AFFINE_DOUBLE);
2018-01-02 20:38:33 +01:00
SetOamMatrixRotationScaling(opponentSprite->oam.matrixNum, sMugshotsOpponentRotationScales[mugshotId][0], sMugshotsOpponentRotationScales[mugshotId][1], 0);
SetOamMatrixRotationScaling(playerSprite->oam.matrixNum, -512, 512, 0);
}
2021-10-25 16:42:08 +02:00
static void SpriteCB_MugshotTrainerPic(struct Sprite *sprite)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
while (sMugshotTrainerPicFuncs[sprite->sState](sprite));
2018-01-02 20:38:33 +01:00
}
2021-10-27 22:17:27 +02:00
// Wait until IncrementTrainerPicState is called
static bool8 MugshotTrainerPic_Pause(struct Sprite *sprite)
2018-01-02 20:38:33 +01:00
{
return FALSE;
}
2021-10-27 22:17:27 +02:00
static bool8 MugshotTrainerPic_Init(struct Sprite *sprite)
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
s16 speeds[ARRAY_COUNT(sTrainerPicSlideSpeeds)];
s16 accels[ARRAY_COUNT(sTrainerPicSlideAccels)];
2018-01-02 20:38:33 +01:00
2021-10-27 22:17:27 +02:00
memcpy(speeds, sTrainerPicSlideSpeeds, sizeof(sTrainerPicSlideSpeeds));
memcpy(accels, sTrainerPicSlideAccels, sizeof(sTrainerPicSlideAccels));
2018-01-02 20:38:33 +01:00
2020-06-01 16:17:25 +02:00
sprite->sState++;
2021-10-27 22:17:27 +02:00
sprite->sSlideSpeed = speeds[sprite->sSlideDir];
sprite->sSlideAccel = accels[sprite->sSlideDir];
2018-01-02 20:38:33 +01:00
return TRUE;
}
2021-10-27 22:17:27 +02:00
static bool8 MugshotTrainerPic_Slide(struct Sprite *sprite)
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
sprite->x += sprite->sSlideSpeed;
// Advance state when pic passes ~40% of screen
if (sprite->sSlideDir && sprite->x < DISPLAY_WIDTH - 107)
2020-06-01 16:17:25 +02:00
sprite->sState++;
2021-10-27 22:17:27 +02:00
else if (!sprite->sSlideDir && sprite->x > 103)
2020-06-01 16:17:25 +02:00
sprite->sState++;
2018-01-02 20:38:33 +01:00
return FALSE;
}
2021-10-27 22:17:27 +02:00
static bool8 MugshotTrainerPic_SlideSlow(struct Sprite *sprite)
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
// Add acceleration value to speed, then add speed.
// For both sides acceleration is opposite speed, so slide slows down.
sprite->sSlideSpeed += sprite->sSlideAccel;
sprite->x += sprite->sSlideSpeed;
// Advance state when slide comes to a stop
if (sprite->sSlideSpeed == 0)
2018-01-02 20:38:33 +01:00
{
2020-06-01 16:17:25 +02:00
sprite->sState++;
2021-10-27 22:17:27 +02:00
sprite->sSlideAccel = -sprite->sSlideAccel;
2020-06-01 16:17:25 +02:00
sprite->sDone = TRUE;
2018-01-02 20:38:33 +01:00
}
return FALSE;
}
2021-10-27 22:17:27 +02:00
// Slides trainer pic offscreen. This is never reached, because it's preceded
// by a second MugshotTrainerPic_Pause, and IncrementTrainerPicState is
// only called once per trainer pic.
static bool8 MugshotTrainerPic_SlideOffscreen(struct Sprite *sprite)
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
sprite->sSlideSpeed += sprite->sSlideAccel;
sprite->x += sprite->sSlideSpeed;
2021-10-25 16:42:08 +02:00
if (sprite->x < -31 || sprite->x > DISPLAY_WIDTH + 31)
2020-06-01 16:17:25 +02:00
sprite->sState++;
2018-01-02 20:38:33 +01:00
return FALSE;
}
2021-10-27 22:17:27 +02:00
static void SetTrainerPicSlideDirection(s16 spriteId, s16 dirId)
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
gSprites[spriteId].sSlideDir = dirId;
2018-01-02 20:38:33 +01:00
}
2020-06-01 16:17:25 +02:00
static void IncrementTrainerPicState(s16 spriteId)
2018-01-02 20:38:33 +01:00
{
2020-06-01 16:17:25 +02:00
gSprites[spriteId].sState++;
2018-01-02 20:38:33 +01:00
}
2020-06-01 16:17:25 +02:00
static s16 IsTrainerPicSlideDone(s16 spriteId)
2018-01-02 20:38:33 +01:00
{
2020-06-01 16:17:25 +02:00
return gSprites[spriteId].sDone;
2018-01-02 20:38:33 +01:00
}
2020-06-01 16:17:25 +02:00
#undef sState
2021-10-27 22:17:27 +02:00
#undef sSlideSpeed
#undef sSlideAccel
2020-06-01 16:17:25 +02:00
#undef sDone
2021-10-27 22:17:27 +02:00
#undef sSlideDir
#undef tSinIndex
#undef tTopBannerX
#undef tBottomBannerX
#undef tTimer
#undef tFadeSpread
#undef tOpponentSpriteId
#undef tPlayerSpriteId
#undef tMugshotId
//--------------------
// B_TRANSITION_SLICE
//--------------------
#define tEffectX data[1]
#define tSpeed data[2]
#define tAccel data[3]
2020-06-01 16:17:25 +02:00
static void Task_Slice(u8 taskId)
2018-01-02 20:38:33 +01:00
{
while (sSlice_Funcs[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-02 20:38:33 +01:00
}
2021-10-25 16:42:08 +02:00
static bool8 Slice_Init(struct Task *task)
2018-01-02 20:38:33 +01:00
{
u16 i;
2021-10-25 16:42:08 +02:00
InitTransitionData();
2018-01-29 17:47:12 +01:00
ScanlineEffect_Clear();
2018-01-02 20:38:33 +01:00
2021-10-27 22:17:27 +02:00
task->tSpeed = 1 << 8;
task->tAccel = 1;
2021-10-25 16:42:08 +02:00
sTransitionData->WININ = WININ_WIN0_ALL;
sTransitionData->WINOUT = 0;
sTransitionData->WIN0V = DISPLAY_HEIGHT;
sTransitionData->VBlank_DMA = FALSE;
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
for (i = 0; i < DISPLAY_HEIGHT; i++)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
gScanlineEffectRegBuffers[1][i] = sTransitionData->cameraX;
gScanlineEffectRegBuffers[1][DISPLAY_HEIGHT + i] = DISPLAY_WIDTH;
2018-01-02 20:38:33 +01:00
}
EnableInterrupts(INTR_FLAG_HBLANK);
SetGpuRegBits(REG_OFFSET_DISPSTAT, DISPSTAT_HBLANK_INTR);
SetVBlankCallback(VBlankCB_Slice);
SetHBlankCallback(HBlankCB_Slice);
2018-01-02 20:38:33 +01:00
task->tState++;
return TRUE;
}
2021-10-27 22:17:27 +02:00
static bool8 Slice_Main(struct Task *task)
2018-01-02 20:38:33 +01:00
{
u16 i;
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA = FALSE;
2018-01-02 20:38:33 +01:00
2021-10-27 22:17:27 +02:00
task->tEffectX += (task->tSpeed >> 8);
if (task->tEffectX > DISPLAY_WIDTH)
task->tEffectX = DISPLAY_WIDTH;
if (task->tSpeed <= 0xFFF)
task->tSpeed += task->tAccel;
if (task->tAccel < 128)
task->tAccel <<= 1; // multiplying by two
2018-01-02 20:38:33 +01:00
2021-10-25 16:42:08 +02:00
for (i = 0; i < DISPLAY_HEIGHT; i++)
2018-01-02 20:38:33 +01:00
{
2018-01-29 17:47:12 +01:00
u16 *storeLoc1 = &gScanlineEffectRegBuffers[0][i];
2021-10-25 16:42:08 +02:00
u16 *storeLoc2 = &gScanlineEffectRegBuffers[0][i + DISPLAY_HEIGHT];
2021-10-27 22:17:27 +02:00
// Alternate rows
if (i % 2)
2018-01-02 20:38:33 +01:00
{
2021-10-27 22:17:27 +02:00
*storeLoc1 = sTransitionData->cameraX + task->tEffectX;
*storeLoc2 = DISPLAY_WIDTH - task->tEffectX;
2018-01-02 20:38:33 +01:00
}
else
{
2021-10-27 22:17:27 +02:00
*storeLoc1 = sTransitionData->cameraX - task->tEffectX;
*storeLoc2 = (task->tEffectX << 8) | (DISPLAY_WIDTH + 1);
2018-01-02 20:38:33 +01:00
}
}
2021-10-27 22:17:27 +02:00
if (task->tEffectX >= DISPLAY_WIDTH)
2018-01-02 20:38:33 +01:00
task->tState++;
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA++;
2018-01-02 20:38:33 +01:00
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 Slice_End(struct Task *task)
2018-01-02 20:38:33 +01:00
{
DmaStop(0);
2020-06-01 16:17:25 +02:00
FadeScreenBlack();
DestroyTask(FindTaskIdByFunc(Task_Slice));
2018-01-02 20:38:33 +01:00
return FALSE;
}
static void VBlankCB_Slice(void)
2018-01-02 20:38:33 +01:00
{
DmaStop(0);
VBlankCB_BattleTransition();
2021-10-25 16:42:08 +02:00
REG_WININ = sTransitionData->WININ;
REG_WINOUT = sTransitionData->WINOUT;
REG_WIN0V = sTransitionData->WIN0V;
if (sTransitionData->VBlank_DMA)
DmaCopy16(3, gScanlineEffectRegBuffers[0], gScanlineEffectRegBuffers[1], DISPLAY_HEIGHT * 4);
DmaSet(0, &gScanlineEffectRegBuffers[1][DISPLAY_HEIGHT], &REG_WIN0H, B_TRANS_DMA_FLAGS);
2018-01-02 20:38:33 +01:00
}
static void HBlankCB_Slice(void)
2018-01-02 20:38:33 +01:00
{
2021-10-25 16:42:08 +02:00
if (REG_VCOUNT < DISPLAY_HEIGHT)
2018-01-02 20:38:33 +01:00
{
2018-01-29 17:47:12 +01:00
u16 var = gScanlineEffectRegBuffers[1][REG_VCOUNT];
2018-01-02 20:38:33 +01:00
REG_BG1HOFS = var;
REG_BG2HOFS = var;
REG_BG3HOFS = var;
}
}
2018-01-13 21:03:07 +01:00
2021-10-27 22:17:27 +02:00
#undef tEffectX
#undef tSpeed
#undef tAccel
//--------------------------
// B_TRANSITION_SHRED_SPLIT
//--------------------------
// Data starts at 4. Possible it shared data
// with Slice above, which ends at 3.
#define tDelayTimer data[4]
#define tExtent data[5]
#define tDelay data[6]
static void Task_ShredSplit(u8 taskId)
2018-01-13 21:03:07 +01:00
{
while (sShredSplit_Funcs[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-13 21:03:07 +01:00
}
2021-10-25 16:42:08 +02:00
static bool8 ShredSplit_Init(struct Task *task)
2018-01-13 21:03:07 +01:00
{
u16 i;
2021-10-25 16:42:08 +02:00
InitTransitionData();
2018-01-29 17:47:12 +01:00
ScanlineEffect_Clear();
2018-01-13 21:03:07 +01:00
2021-10-25 16:42:08 +02:00
sTransitionData->WININ = WININ_WIN0_ALL;
sTransitionData->WINOUT = 0;
sTransitionData->WIN0V = DISPLAY_HEIGHT;
2018-01-13 21:03:07 +01:00
2021-10-25 16:42:08 +02:00
for (i = 0; i < DISPLAY_HEIGHT; i++)
2018-01-13 21:03:07 +01:00
{
2021-10-25 16:42:08 +02:00
gScanlineEffectRegBuffers[1][i] = sTransitionData->cameraX;
gScanlineEffectRegBuffers[1][DISPLAY_HEIGHT + i] = DISPLAY_WIDTH;
gScanlineEffectRegBuffers[0][i] = sTransitionData->cameraX;
gScanlineEffectRegBuffers[0][DISPLAY_HEIGHT + i] = DISPLAY_WIDTH;
gScanlineEffectRegBuffers[0][DISPLAY_HEIGHT * 2 + i] = 0;
gScanlineEffectRegBuffers[0][DISPLAY_HEIGHT * 3 + i] = 256;
gScanlineEffectRegBuffers[0][DISPLAY_HEIGHT * 4 + i] = 1;
2018-01-13 21:03:07 +01:00
}
2021-10-27 22:17:27 +02:00
task->tDelayTimer = 0;
task->tExtent = 0;
task->tDelay = 7;
2018-01-13 21:03:07 +01:00
EnableInterrupts(INTR_FLAG_HBLANK);
SetVBlankCallback(VBlankCB_Slice);
SetHBlankCallback(HBlankCB_Slice);
2018-01-13 21:03:07 +01:00
task->tState++;
return TRUE;
}
2021-10-27 22:17:27 +02:00
static bool8 ShredSplit_Main(struct Task *task)
2018-01-13 21:03:07 +01:00
{
u16 i, j, k;
2021-10-27 22:17:27 +02:00
u8 baseY[ARRAY_COUNT(sShredSplit_SectionYCoords)];
s16 moveDirs[ARRAY_COUNT(sShredSplit_SectionMoveDirs)];
u8 linesFinished;
2018-01-13 21:03:07 +01:00
u16 *ptr4, *ptr3, *ptr1, *ptr2;
2021-10-27 22:17:27 +02:00
s16 y;
2018-01-13 21:03:07 +01:00
2021-10-27 22:17:27 +02:00
memcpy(baseY, sShredSplit_SectionYCoords, sizeof(baseY));
memcpy(moveDirs, sShredSplit_SectionMoveDirs, sizeof(moveDirs));
2018-01-13 21:03:07 +01:00
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA = FALSE;
2021-10-27 22:17:27 +02:00
linesFinished = 0;
2018-01-13 21:03:07 +01:00
2021-10-27 22:17:27 +02:00
for (i = 0; i <= task->tExtent; i++)
2018-01-13 21:03:07 +01:00
{
2021-10-27 22:17:27 +02:00
// Slide half of the pixel rows (alternating) right
2018-01-13 21:03:07 +01:00
for (j = 0; j < 2; j++)
{
for (k = 0; k < 2; k++)
{
2021-10-27 22:17:27 +02:00
y = baseY[j] + (moveDirs[k] * -i * 2);
if (y >= 0 && (y != DISPLAY_HEIGHT / 2 - 1 || j != 1))
2018-01-13 21:03:07 +01:00
{
2021-10-27 22:17:27 +02:00
ptr4 = &gScanlineEffectRegBuffers[0][y + DISPLAY_HEIGHT * 2];
ptr3 = &gScanlineEffectRegBuffers[0][y + DISPLAY_HEIGHT * 3];
ptr1 = &gScanlineEffectRegBuffers[0][y + DISPLAY_HEIGHT * 4];
2021-10-25 16:42:08 +02:00
if (*ptr4 >= DISPLAY_WIDTH)
2018-01-13 21:03:07 +01:00
{
2021-10-25 16:42:08 +02:00
*ptr4 = DISPLAY_WIDTH;
2021-10-27 22:17:27 +02:00
linesFinished++;
2018-01-13 21:03:07 +01:00
}
else
{
*ptr4 += (*ptr3 >> 8);
if (*ptr1 <= 0x7F)
*ptr1 *= 2;
if (*ptr3 <= 0xFFF)
*ptr3 += *ptr1;
}
2021-10-27 22:17:27 +02:00
ptr2 = &gScanlineEffectRegBuffers[0][y];
ptr3 = &gScanlineEffectRegBuffers[0][y + DISPLAY_HEIGHT];
2021-10-25 16:42:08 +02:00
*ptr2 = sTransitionData->cameraX + *ptr4;
*ptr3 = DISPLAY_WIDTH - *ptr4;
2018-01-13 21:03:07 +01:00
if (i == 0)
break;
}
}
}
2021-10-27 22:17:27 +02:00
// Slide the other half of the rows left
2018-01-13 21:03:07 +01:00
for (j = 0; j < 2; j++)
{
for (k = 0; k < 2; k++)
{
2021-10-27 22:17:27 +02:00
y = baseY[j] + 1 + (moveDirs[k] * -i * 2);
if (y <= DISPLAY_HEIGHT && (y != DISPLAY_HEIGHT / 2 || j != 1))
2018-01-13 21:03:07 +01:00
{
2021-10-27 22:17:27 +02:00
ptr4 = &gScanlineEffectRegBuffers[0][y + DISPLAY_HEIGHT * 2];
ptr3 = &gScanlineEffectRegBuffers[0][y + DISPLAY_HEIGHT * 3];
ptr1 = &gScanlineEffectRegBuffers[0][y + DISPLAY_HEIGHT * 4];
2021-10-25 16:42:08 +02:00
if (*ptr4 >= DISPLAY_WIDTH)
2018-01-13 21:03:07 +01:00
{
2021-10-25 16:42:08 +02:00
*ptr4 = DISPLAY_WIDTH;
2021-10-27 22:17:27 +02:00
linesFinished++;
2018-01-13 21:03:07 +01:00
}
else
{
*ptr4 += (*ptr3 >> 8);
if (*ptr1 <= 0x7F)
*ptr1 *= 2;
if (*ptr3 <= 0xFFF)
*ptr3 += *ptr1;
}
2021-10-27 22:17:27 +02:00
ptr2 = &gScanlineEffectRegBuffers[0][y];
ptr3 = &gScanlineEffectRegBuffers[0][y + DISPLAY_HEIGHT];
2021-10-25 16:42:08 +02:00
*ptr2 = sTransitionData->cameraX - *ptr4;
*ptr3 = (*ptr4 << 8) | (DISPLAY_WIDTH + 1);
2018-01-13 21:03:07 +01:00
if (i == 0)
break;
}
}
}
}
2021-10-27 22:17:27 +02:00
// Count down to next move
if (--task->tDelayTimer < 0)
task->tDelayTimer = 0;
// Try increase effect's extent
if (task->tDelayTimer <= 0 && task->tExtent + 1 <= DISPLAY_HEIGHT / 8)
{
task->tDelayTimer = task->tDelay;
task->tExtent++;
}
// All lines have reached screen width, move on.
if (linesFinished >= DISPLAY_HEIGHT)
2018-01-13 21:03:07 +01:00
task->tState++;
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA++;
2018-01-13 21:03:07 +01:00
return FALSE;
}
// This function never increments the state counter, because the loop condition
// is always false, resulting in the game being stuck in an infinite loop.
2018-01-29 17:47:12 +01:00
// It's possible this transition is only partially
// done and the second part was left out.
2021-10-27 22:17:27 +02:00
// In any case removing or bypassing this state allows the transition to finish.
static bool8 ShredSplit_BrokenCheck(struct Task *task)
2018-01-13 21:03:07 +01:00
{
u16 i;
bool32 done = TRUE;
u16 checkVar2 = 0xFF10;
2021-10-25 16:42:08 +02:00
for (i = 0; i < DISPLAY_HEIGHT; i++)
2018-01-13 21:03:07 +01:00
{
2021-10-25 16:42:08 +02:00
if (gScanlineEffectRegBuffers[1][i] != DISPLAY_WIDTH && gScanlineEffectRegBuffers[1][i] != checkVar2)
2021-10-27 22:17:27 +02:00
done = FALSE;
2018-01-13 21:03:07 +01:00
}
if (done == TRUE)
task->tState++;
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 ShredSplit_End(struct Task *task)
2018-01-13 21:03:07 +01:00
{
DmaStop(0);
2020-06-01 16:17:25 +02:00
FadeScreenBlack();
DestroyTask(FindTaskIdByFunc(Task_ShredSplit));
2018-01-13 21:03:07 +01:00
return FALSE;
}
2021-10-27 22:17:27 +02:00
#undef tDelayTimer
#undef tExtent
#undef tDelay
//-----------------------------------------------------------
// B_TRANSITION_BLACKHOLE and B_TRANSITION_BLACKHOLE_PULSATE
//-----------------------------------------------------------
#define tRadius data[1]
#define tGrowSpeed data[2]
#define tSinIndex data[5]
#define tVibrateId data[6]
#define tAmplitude data[6] // Used differently by the two transitions
#define tFlag data[7] // Used generally to indicate an action has taken place.
static void Task_Blackhole(u8 taskId)
2018-01-13 21:03:07 +01:00
{
2021-10-27 22:17:27 +02:00
while (sBlackhole_Funcs[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-13 21:03:07 +01:00
}
2021-10-27 22:17:27 +02:00
static void Task_BlackholePulsate(u8 taskId)
2018-01-13 21:03:07 +01:00
{
2021-10-27 22:17:27 +02:00
while (sBlackholePulsate_Funcs[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-13 21:03:07 +01:00
}
2021-10-27 22:17:27 +02:00
// Init is shared by both transitions
2021-10-25 16:42:08 +02:00
static bool8 Blackhole_Init(struct Task *task)
2018-01-13 21:03:07 +01:00
{
s32 i;
2021-10-25 16:42:08 +02:00
InitTransitionData();
2018-01-29 17:47:12 +01:00
ScanlineEffect_Clear();
2018-01-13 21:03:07 +01:00
2021-10-25 16:42:08 +02:00
sTransitionData->WININ = 0;
sTransitionData->WINOUT = WINOUT_WIN01_ALL;
sTransitionData->WIN0H = DISPLAY_WIDTH;
sTransitionData->WIN0V = DISPLAY_HEIGHT;
2018-01-13 21:03:07 +01:00
2021-10-25 16:42:08 +02:00
for (i = 0; i < DISPLAY_HEIGHT; i++)
2018-01-29 17:47:12 +01:00
gScanlineEffectRegBuffers[1][i] = 0;
2018-01-13 21:03:07 +01:00
2021-10-27 22:17:27 +02:00
SetVBlankCallback(VBlankCB_CircularMask);
2018-01-13 21:03:07 +01:00
task->tState++;
2021-10-27 22:17:27 +02:00
task->tRadius = 1;
task->tGrowSpeed = 1 << 8;
task->tFlag = FALSE;
2018-01-13 21:03:07 +01:00
return FALSE;
}
2021-10-27 22:17:27 +02:00
static bool8 Blackhole_GrowEnd(struct Task *task)
2018-01-13 21:03:07 +01:00
{
2021-10-27 22:17:27 +02:00
if (task->tFlag == TRUE)
2018-01-13 21:03:07 +01:00
{
DmaStop(0);
SetVBlankCallback(NULL);
DestroyTask(FindTaskIdByFunc(task->func));
}
else
{
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA = FALSE;
2021-10-27 22:17:27 +02:00
if (task->tGrowSpeed < 1024)
task->tGrowSpeed += 128;
if (task->tRadius < DISPLAY_HEIGHT)
task->tRadius += task->tGrowSpeed >> 8;
if (task->tRadius > DISPLAY_HEIGHT)
task->tRadius = DISPLAY_HEIGHT;
SetCircularMask(gScanlineEffectRegBuffers[0], DISPLAY_WIDTH / 2, DISPLAY_HEIGHT / 2, task->tRadius);
if (task->tRadius == DISPLAY_HEIGHT)
2018-01-13 21:03:07 +01:00
{
2021-10-27 22:17:27 +02:00
task->tFlag = TRUE;
2020-06-01 16:17:25 +02:00
FadeScreenBlack();
2018-01-13 21:03:07 +01:00
}
else
{
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA++;
2018-01-13 21:03:07 +01:00
}
}
return FALSE;
}
2021-10-27 22:17:27 +02:00
static bool8 Blackhole_Vibrate(struct Task *task)
2018-01-13 21:03:07 +01:00
{
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA = FALSE;
2021-10-27 22:17:27 +02:00
if (task->tFlag == FALSE)
2018-01-13 21:03:07 +01:00
{
2021-10-27 22:17:27 +02:00
task->tFlag++;
task->tRadius = 48;
task->tVibrateId = 0;
2018-01-13 21:03:07 +01:00
}
2021-10-27 22:17:27 +02:00
task->tRadius += sBlackhole_Vibrations[task->tVibrateId];
task->tVibrateId = (task->tVibrateId + 1) % (int)ARRAY_COUNT(sBlackhole_Vibrations);
SetCircularMask(gScanlineEffectRegBuffers[0], DISPLAY_WIDTH / 2, DISPLAY_HEIGHT / 2, task->tRadius);
if (task->tRadius < 9)
2018-01-13 21:03:07 +01:00
{
task->tState++;
2021-10-27 22:17:27 +02:00
task->tFlag = FALSE;
2018-01-13 21:03:07 +01:00
}
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA++;
2018-01-13 21:03:07 +01:00
return FALSE;
}
2021-10-27 22:17:27 +02:00
static bool8 BlackholePulsate_Main(struct Task *task)
2018-01-13 21:03:07 +01:00
{
u16 index; // should be s16 I think
s16 amplitude;
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA = FALSE;
2021-10-27 22:17:27 +02:00
if (task->tFlag == FALSE)
2018-01-13 21:03:07 +01:00
{
2021-10-27 22:17:27 +02:00
task->tFlag++;
task->tSinIndex = 2;
task->tAmplitude = 2;
2018-01-13 21:03:07 +01:00
}
2021-10-27 22:17:27 +02:00
if (task->tRadius > DISPLAY_HEIGHT)
task->tRadius = DISPLAY_HEIGHT;
SetCircularMask(gScanlineEffectRegBuffers[0], DISPLAY_WIDTH / 2, DISPLAY_HEIGHT / 2, task->tRadius);
if (task->tRadius == DISPLAY_HEIGHT)
2018-01-13 21:03:07 +01:00
{
DmaStop(0);
2020-06-01 16:17:25 +02:00
FadeScreenBlack();
2018-01-13 21:03:07 +01:00
DestroyTask(FindTaskIdByFunc(task->func));
}
2021-10-27 22:17:27 +02:00
index = task->tSinIndex;
if ((task->tSinIndex & 0xFF) <= 128)
2018-01-13 21:03:07 +01:00
{
2021-10-27 22:17:27 +02:00
amplitude = task->tAmplitude;
task->tSinIndex += 8;
2018-01-13 21:03:07 +01:00
}
else
{
2021-10-27 22:17:27 +02:00
amplitude = task->tAmplitude - 1;
task->tSinIndex += 16;
2018-01-13 21:03:07 +01:00
}
2021-10-27 22:17:27 +02:00
task->tRadius += Sin(index & 0xFF, amplitude);
2018-01-13 21:03:07 +01:00
2021-10-27 22:17:27 +02:00
if (task->tRadius <= 0)
task->tRadius = 1;
if (task->tSinIndex >= 0xFF)
{
task->tSinIndex >>= 8;
task->tAmplitude++;
}
2018-01-13 21:03:07 +01:00
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA++;
2018-01-13 21:03:07 +01:00
return FALSE;
}
2021-10-27 22:17:27 +02:00
#undef tRadius
#undef tGrowSpeed
#undef tSinIndex
#undef tVibrateId
#undef tAmplitude
#undef tFlag
//---------------------------------
// B_TRANSITION_RECTANGULAR_SPIRAL
//---------------------------------
static void Task_RectangularSpiral(u8 taskId)
2018-01-13 21:03:07 +01:00
{
while (sRectangularSpiral_Funcs[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-13 21:03:07 +01:00
}
2021-10-25 16:42:08 +02:00
static bool8 RectangularSpiral_Init(struct Task *task)
2018-01-13 21:03:07 +01:00
{
2020-06-01 16:17:25 +02:00
u16 *tilemap, *tileset;
2018-01-13 21:03:07 +01:00
2020-06-01 16:17:25 +02:00
GetBg0TilesDst(&tilemap, &tileset);
CpuCopy16(sShrinkingBoxTileset, tileset, 0x20);
2021-10-29 17:56:06 +02:00
CpuCopy16(&sShrinkingBoxTileset[0x70], &tileset[0x20], 0x20);
2021-10-27 22:17:27 +02:00
CpuFill16(0xF0 << 8, tilemap, BG_SCREEN_SIZE);
2021-10-25 16:42:08 +02:00
LoadPalette(sFieldEffectPal_Pokeball, 0xF0, sizeof(sFieldEffectPal_Pokeball));
2018-01-13 21:03:07 +01:00
2021-10-25 16:42:08 +02:00
task->data[3] = 1;
2018-01-13 21:03:07 +01:00
task->tState++;
2021-10-29 17:56:06 +02:00
// Line starting in top left
sRectangularSpiralLines[0].state = SPIRAL_INWARD_START;
2021-10-27 22:17:27 +02:00
sRectangularSpiralLines[0].position = -1;
sRectangularSpiralLines[0].moveIdx = 1;
2021-10-29 17:56:06 +02:00
sRectangularSpiralLines[0].reboundPosition = 308;
sRectangularSpiralLines[0].outward = FALSE;
2021-10-27 22:17:27 +02:00
2021-10-29 17:56:06 +02:00
// Line starting in bottom right
sRectangularSpiralLines[1].state = SPIRAL_INWARD_START;
2021-10-27 22:17:27 +02:00
sRectangularSpiralLines[1].position = -1;
sRectangularSpiralLines[1].moveIdx = 1;
2021-10-29 17:56:06 +02:00
sRectangularSpiralLines[1].reboundPosition = 308;
sRectangularSpiralLines[1].outward = FALSE;
2021-10-27 22:17:27 +02:00
2021-10-29 17:56:06 +02:00
// Line starting in top right
sRectangularSpiralLines[2].state = SPIRAL_INWARD_START;
2021-10-27 22:17:27 +02:00
sRectangularSpiralLines[2].position = -3;
sRectangularSpiralLines[2].moveIdx = 1;
2021-10-29 17:56:06 +02:00
sRectangularSpiralLines[2].reboundPosition = 307;
sRectangularSpiralLines[2].outward = FALSE;
2021-10-27 22:17:27 +02:00
2021-10-29 17:56:06 +02:00
// Line starting in bottom left
sRectangularSpiralLines[3].state = SPIRAL_INWARD_START;
2021-10-27 22:17:27 +02:00
sRectangularSpiralLines[3].position = -3;
sRectangularSpiralLines[3].moveIdx = 1;
2021-10-29 17:56:06 +02:00
sRectangularSpiralLines[3].reboundPosition = 307;
sRectangularSpiralLines[3].outward = FALSE;
2018-01-13 21:03:07 +01:00
return FALSE;
}
2021-10-27 22:17:27 +02:00
static bool8 RectangularSpiral_Main(struct Task *task)
2018-01-13 21:03:07 +01:00
{
2020-06-01 16:17:25 +02:00
u16 *tilemap, *tileset;
2018-01-13 21:03:07 +01:00
u8 i;
u16 j;
bool32 done = TRUE;
2020-06-01 16:17:25 +02:00
GetBg0TilesDst(&tilemap, &tileset);
2018-01-13 21:03:07 +01:00
2021-10-27 22:17:27 +02:00
// Draw 2 tiles at a time for each spiral line
2018-01-13 21:03:07 +01:00
for (i = 0; i < 2; i++)
{
2021-10-27 22:17:27 +02:00
for (j = 0; j < ARRAY_COUNT(sRectangularSpiralLines); j++)
2018-01-13 21:03:07 +01:00
{
2021-10-27 22:17:27 +02:00
s16 position = 0;
s16 x = 0, y = 0;
2018-01-13 21:03:07 +01:00
2021-10-27 22:17:27 +02:00
if (UpdateRectangularSpiralLine(sRectangularSpiral_MoveDataTables[j / 2], &sRectangularSpiralLines[j]))
2018-01-13 21:03:07 +01:00
{
2021-10-27 22:17:27 +02:00
// The line moved to a new position, draw the tile.
2018-01-13 21:03:07 +01:00
done = FALSE;
2021-10-27 22:17:27 +02:00
position = sRectangularSpiralLines[j].position;
2021-10-29 17:56:06 +02:00
// Invert position for the two lines that start at the bottom.
if ((j % 2) == 1)
2021-10-27 22:17:27 +02:00
position = 637 - position;
2018-01-13 21:03:07 +01:00
2021-10-27 22:17:27 +02:00
x = position % 32;
y = position / 32;
2018-01-13 21:03:07 +01:00
2021-10-27 22:17:27 +02:00
SET_TILE(tilemap, y, x, 2);
2018-01-13 21:03:07 +01:00
}
}
}
if (done == TRUE)
task->tState++;
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 RectangularSpiral_End(struct Task *task)
2018-01-13 21:03:07 +01:00
{
DmaStop(0);
2020-06-01 16:17:25 +02:00
FadeScreenBlack();
2018-01-13 21:03:07 +01:00
DestroyTask(FindTaskIdByFunc(task->func));
return FALSE;
}
2021-10-27 22:17:27 +02:00
// Returns TRUE if a tile should be drawn, FALSE otherwise
static bool16 UpdateRectangularSpiralLine(const s16 * const *moveDataTable, struct RectangularSpiralLine *line)
2018-01-13 21:03:07 +01:00
{
2021-10-27 22:17:27 +02:00
const s16 *moveData = moveDataTable[line->state];
2021-10-29 17:56:06 +02:00
// Has spiral finished?
// Note that most move data arrays endsin SPIRAL_END but it is
// only ever reached on the final array of spiraling outward.
2021-10-27 22:17:27 +02:00
if (moveData[line->moveIdx] == SPIRAL_END)
2018-01-13 21:03:07 +01:00
return FALSE;
2021-10-27 22:17:27 +02:00
// Presumably saving data for debug.
sDebug_RectangularSpiralData = moveData[0];
sDebug_RectangularSpiralData = moveData[1];
sDebug_RectangularSpiralData = moveData[2];
sDebug_RectangularSpiralData = moveData[3];
2018-01-13 21:03:07 +01:00
2021-10-29 17:56:06 +02:00
// Note that for the two lines originating at the bottom the
// position is inverted, so the directions are flipped.
// i.e. position += 1 is right for the top lines and left
// for their inverted partners on the bottom.
2021-10-27 22:17:27 +02:00
switch (moveData[0])
2018-01-13 21:03:07 +01:00
{
2021-10-29 17:56:06 +02:00
case MOVE_RIGHT:
2021-10-27 22:17:27 +02:00
line->position += 1;
2018-01-13 21:03:07 +01:00
break;
2021-10-29 17:56:06 +02:00
case MOVE_LEFT:
2021-10-27 22:17:27 +02:00
line->position -= 1;
2018-01-13 21:03:07 +01:00
break;
2021-10-29 17:56:06 +02:00
case MOVE_UP:
2021-10-27 22:17:27 +02:00
line->position -= 32;
2018-01-13 21:03:07 +01:00
break;
2021-10-29 17:56:06 +02:00
case MOVE_DOWN:
2021-10-27 22:17:27 +02:00
line->position += 32;
2018-01-13 21:03:07 +01:00
break;
}
2021-10-27 22:17:27 +02:00
// Below check is never true.
// SPIRAL_END was already checked, and position is never >= 640
if (line->position >= 640 || moveData[line->moveIdx] == SPIRAL_END)
2018-01-13 21:03:07 +01:00
return FALSE;
2021-10-29 17:56:06 +02:00
if (!line->outward && moveData[line->moveIdx] == SPIRAL_REBOUND)
2018-01-13 21:03:07 +01:00
{
2021-10-29 17:56:06 +02:00
// Line has reached the final point of spiraling inward.
// Time to flip and start spiraling outward.
line->outward = TRUE;
2021-10-27 22:17:27 +02:00
line->moveIdx = 1;
2021-10-29 17:56:06 +02:00
line->position = line->reboundPosition;
line->state = SPIRAL_OUTWARD_START;
2018-01-13 21:03:07 +01:00
}
2021-10-29 17:56:06 +02:00
// Reached move target, advance to next movement.
2021-10-27 22:17:27 +02:00
if (line->position == moveData[line->moveIdx])
2018-01-13 21:03:07 +01:00
{
2021-10-27 22:17:27 +02:00
line->state++;
2021-10-29 17:56:06 +02:00
if (line->outward == TRUE)
2018-01-13 21:03:07 +01:00
{
2021-10-29 17:56:06 +02:00
if (line->state > SPIRAL_OUTWARD_END)
2018-01-13 21:03:07 +01:00
{
2021-10-29 17:56:06 +02:00
// Still spiraling outward, loop back to the first state
// but use the second set of move targets.
// For example, the 28 in sRectangularSpiral_Major_OutwardUp
2021-10-27 22:17:27 +02:00
line->moveIdx++;
2021-10-29 17:56:06 +02:00
line->state = SPIRAL_OUTWARD_START;
2018-01-13 21:03:07 +01:00
}
}
else
{
2021-10-29 17:56:06 +02:00
if (line->state > SPIRAL_INWARD_END)
2018-01-13 21:03:07 +01:00
{
2021-10-29 17:56:06 +02:00
// Still spiraling inward, loop back to the first state
// but use the second set of move targets.
// For example, the 275 in sRectangularSpiral_Major_InwardRight
2021-10-27 22:17:27 +02:00
line->moveIdx++;
2021-10-29 17:56:06 +02:00
line->state = SPIRAL_INWARD_START;
2018-01-13 21:03:07 +01:00
}
}
}
return TRUE;
}
2021-10-27 22:17:27 +02:00
//----------------------
// B_TRANSITION_GROUDON
//----------------------
#define tTimer data[1]
static void Task_Groudon(u8 taskId)
2018-01-13 21:03:07 +01:00
{
while (sGroudon_Funcs[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-13 21:03:07 +01:00
}
2021-10-25 16:42:08 +02:00
static bool8 Groudon_Init(struct Task *task)
2018-01-13 21:03:07 +01:00
{
2020-06-01 16:17:25 +02:00
u16 *tilemap, *tileset;
2018-01-13 21:03:07 +01:00
2020-06-01 16:17:25 +02:00
GetBg0TilesDst(&tilemap, &tileset);
2021-10-25 16:42:08 +02:00
CpuFill16(0, tilemap, BG_SCREEN_SIZE);
2020-06-01 16:17:25 +02:00
LZ77UnCompVram(sGroudon_Tileset, tileset);
LZ77UnCompVram(sGroudon_Tilemap, tilemap);
2018-01-13 21:03:07 +01:00
task->tState++;
2021-10-27 22:17:27 +02:00
task->tTimer = 0;
2018-01-13 21:03:07 +01:00
return FALSE;
}
2021-10-27 22:17:27 +02:00
static bool8 Groudon_PaletteFlash(struct Task *task)
2018-01-13 21:03:07 +01:00
{
2021-10-27 22:17:27 +02:00
if (task->tTimer % 3 == 0)
2018-01-13 21:03:07 +01:00
{
2021-10-27 22:17:27 +02:00
u16 offset = (task->tTimer % 30) / 3;
LoadPalette(&sGroudon1_Palette[offset * 16], 0xF0, 0x20);
2018-01-13 21:03:07 +01:00
}
2021-10-27 22:17:27 +02:00
if (++task->tTimer > 58)
2018-01-13 21:03:07 +01:00
{
task->tState++;
2021-10-27 22:17:27 +02:00
task->tTimer = 0;
2018-01-13 21:03:07 +01:00
}
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 Groudon_PaletteBrighten(struct Task *task)
2018-01-13 21:03:07 +01:00
{
2021-10-27 22:17:27 +02:00
if (task->tTimer % 5 == 0)
2018-01-13 21:03:07 +01:00
{
2021-10-27 22:17:27 +02:00
s16 offset = task->tTimer / 5;
LoadPalette(&sGroudon2_Palette[offset * 16], 0xF0, 0x20);
2018-01-13 21:03:07 +01:00
}
2021-10-27 22:17:27 +02:00
if (++task->tTimer > 68)
2018-01-13 21:03:07 +01:00
{
task->tState++;
2021-10-27 22:17:27 +02:00
task->tTimer = 0;
2021-10-25 16:42:08 +02:00
task->tEndDelay = 30;
2018-01-13 21:03:07 +01:00
}
return FALSE;
}
2021-10-27 22:17:27 +02:00
#undef tTimer
2021-10-25 16:42:08 +02:00
#undef tEndDelay
2021-10-27 22:17:27 +02:00
//-----------------------
// B_TRANSITION_RAYQUAZA
//-----------------------
#define tTimer data[1]
#define tGrowSpeed data[2] // Shared from B_TRANSITION_BLACKHOLE
#define tFlag data[7] // Shared from B_TRANSITION_BLACKHOLE
static void Task_Rayquaza(u8 taskId)
2018-01-14 20:45:44 +01:00
{
while (sRayquaza_Funcs[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-14 20:45:44 +01:00
}
2021-10-27 22:17:27 +02:00
static bool8 Rayquaza_Init(struct Task *task)
2018-01-14 20:45:44 +01:00
{
2020-06-01 16:17:25 +02:00
u16 *tilemap, *tileset;
2018-01-14 20:45:44 +01:00
u16 i;
2021-10-25 16:42:08 +02:00
InitTransitionData();
2018-01-29 17:47:12 +01:00
ScanlineEffect_Clear();
2018-01-14 20:45:44 +01:00
2021-04-15 09:00:01 +02:00
SetGpuReg(REG_OFFSET_BG0CNT, BGCNT_CHARBASE(2) | BGCNT_SCREENBASE(26) | BGCNT_TXT256x512);
2020-06-01 16:17:25 +02:00
GetBg0TilesDst(&tilemap, &tileset);
2021-10-25 16:42:08 +02:00
CpuFill16(0, tilemap, BG_SCREEN_SIZE);
2020-06-01 16:17:25 +02:00
CpuCopy16(sRayquaza_Tileset, tileset, 0x2000);
2018-01-14 20:45:44 +01:00
2021-10-27 22:17:27 +02:00
sTransitionData->counter = 0;
2018-01-14 20:45:44 +01:00
task->tState++;
2021-10-27 22:17:27 +02:00
LoadPalette(&sRayquaza_Palette[0x50], 0xF0, 0x20);
2018-01-14 20:45:44 +01:00
2021-10-25 16:42:08 +02:00
for (i = 0; i < DISPLAY_HEIGHT; i++)
2018-01-14 20:45:44 +01:00
{
2018-01-29 17:47:12 +01:00
gScanlineEffectRegBuffers[0][i] = 0;
gScanlineEffectRegBuffers[1][i] = 0x100;
2018-01-14 20:45:44 +01:00
}
SetVBlankCallback(VBlankCB_Rayquaza);
2018-01-14 20:45:44 +01:00
return FALSE;
}
2021-10-27 22:17:27 +02:00
static bool8 Rayquaza_SetGfx(struct Task *task)
2018-01-14 20:45:44 +01:00
{
2020-06-01 16:17:25 +02:00
u16 *tilemap, *tileset;
2018-01-14 20:45:44 +01:00
2020-06-01 16:17:25 +02:00
GetBg0TilesDst(&tilemap, &tileset);
2021-10-25 16:42:08 +02:00
CpuCopy16(sRayquaza_Tilemap, tilemap, sizeof(sRayquaza_Tilemap));
2018-01-14 20:45:44 +01:00
task->tState++;
return FALSE;
}
2021-10-27 22:17:27 +02:00
static bool8 Rayquaza_PaletteFlash(struct Task *task)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
if ((task->tTimer % 4) == 0)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
u16 value = task->tTimer / 4;
2020-06-01 16:17:25 +02:00
const u16 *palPtr = &sRayquaza_Palette[(value + 5) * 16];
2018-01-14 20:45:44 +01:00
LoadPalette(palPtr, 0xF0, 0x20);
}
2021-10-27 22:17:27 +02:00
if (++task->tTimer > 40)
2018-01-14 20:45:44 +01:00
{
task->tState++;
2021-10-27 22:17:27 +02:00
task->tTimer = 0;
2018-01-14 20:45:44 +01:00
}
return FALSE;
}
2021-10-27 22:17:27 +02:00
static bool8 Rayquaza_FadeToBlack(struct Task *task)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
if (++task->tTimer > 20)
2018-01-14 20:45:44 +01:00
{
task->tState++;
2021-10-27 22:17:27 +02:00
task->tTimer = 0;
2021-10-25 16:42:08 +02:00
BeginNormalPaletteFade(PALETTES_OBJECTS | (1 << 15), 2, 0, 16, RGB_BLACK);
2018-01-14 20:45:44 +01:00
}
return FALSE;
}
2021-10-27 22:17:27 +02:00
static bool8 Rayquaza_WaitFade(struct Task *task)
2018-01-14 20:45:44 +01:00
{
if (!gPaletteFade.active)
{
2021-10-27 22:17:27 +02:00
sTransitionData->counter = 1;
2018-01-14 20:45:44 +01:00
task->tState++;
}
return FALSE;
}
2021-10-27 22:17:27 +02:00
static bool8 Rayquaza_SetBlack(struct Task *task)
2018-01-14 20:45:44 +01:00
{
2021-10-25 16:42:08 +02:00
BlendPalettes(PALETTES_BG & ~(1 << 15), 8, RGB_BLACK);
BlendPalettes(PALETTES_OBJECTS | (1 << 15), 0, RGB_BLACK);
2018-01-14 20:45:44 +01:00
task->tState++;
return FALSE;
}
2021-10-27 22:17:27 +02:00
static bool8 Rayquaza_TriRing(struct Task *task)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
if ((task->tTimer % 3) == 0)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
u16 value = task->tTimer / 3;
2020-06-01 16:17:25 +02:00
const u16 *palPtr = &sRayquaza_Palette[(value + 0) * 16];
2018-01-14 20:45:44 +01:00
LoadPalette(palPtr, 0xF0, 0x20);
}
2021-10-27 22:17:27 +02:00
if (++task->tTimer >= 40)
2018-01-14 20:45:44 +01:00
{
u16 i;
2021-10-25 16:42:08 +02:00
sTransitionData->WININ = 0;
sTransitionData->WINOUT = WINOUT_WIN01_ALL;
sTransitionData->WIN0H = DISPLAY_WIDTH;
sTransitionData->WIN0V = DISPLAY_HEIGHT;
2018-01-14 20:45:44 +01:00
2021-10-25 16:42:08 +02:00
for (i = 0; i < DISPLAY_HEIGHT; i++)
2018-01-29 17:47:12 +01:00
gScanlineEffectRegBuffers[1][i] = 0;
2018-01-14 20:45:44 +01:00
2021-10-27 22:17:27 +02:00
SetVBlankCallback(VBlankCB_CircularMask);
2018-01-14 20:45:44 +01:00
task->tState++;
2021-10-27 22:17:27 +02:00
task->tGrowSpeed = 1 << 8;
task->tFlag = FALSE;
2018-01-14 20:45:44 +01:00
ClearGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_BG0_ON);
}
return FALSE;
}
static void VBlankCB_Rayquaza(void)
2018-01-14 20:45:44 +01:00
{
void *dmaSrc;
DmaStop(0);
VBlankCB_BattleTransition();
2021-10-27 22:17:27 +02:00
if (sTransitionData->counter == 0)
2018-01-29 17:47:12 +01:00
dmaSrc = gScanlineEffectRegBuffers[0];
2021-10-27 22:17:27 +02:00
else if (sTransitionData->counter == 1)
2018-01-29 17:47:12 +01:00
dmaSrc = gScanlineEffectRegBuffers[1];
2018-01-14 20:45:44 +01:00
else
2018-01-29 17:47:12 +01:00
dmaSrc = gScanlineEffectRegBuffers[0];
2018-01-14 20:45:44 +01:00
2021-10-25 16:42:08 +02:00
DmaSet(0, dmaSrc, &REG_BG0VOFS, B_TRANS_DMA_FLAGS);
2018-01-14 20:45:44 +01:00
}
2021-10-27 22:17:27 +02:00
#undef tTimer
#undef tGrowSpeed
#undef tFlag
//------------------------------
// B_TRANSITION_WHITE_BARS_FADE
//------------------------------
#define sFade data[0]
#define sFinished data[1]
#define sDestroyAttempts data[2]
#define sDelay data[5]
#define sIsMainSprite data[6]
#define FADE_TARGET (16 << 8)
static void Task_WhiteBarsFade(u8 taskId)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
while (sWhiteBarsFade_Funcs[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-14 20:45:44 +01:00
}
2021-10-27 22:17:27 +02:00
static bool8 WhiteBarsFade_Init(struct Task *task)
2018-01-14 20:45:44 +01:00
{
u16 i;
2021-10-25 16:42:08 +02:00
InitTransitionData();
2018-01-29 17:47:12 +01:00
ScanlineEffect_Clear();
2018-01-14 20:45:44 +01:00
2021-10-25 16:42:08 +02:00
sTransitionData->BLDCNT = BLDCNT_TGT1_ALL | BLDCNT_EFFECT_LIGHTEN;
sTransitionData->BLDY = 0;
sTransitionData->WININ = WININ_WIN0_BG1 | WININ_WIN0_BG2 | WININ_WIN0_BG3 | WININ_WIN0_OBJ;
sTransitionData->WINOUT = WINOUT_WIN01_ALL;
sTransitionData->WIN0V = DISPLAY_HEIGHT;
2018-01-14 20:45:44 +01:00
2021-10-25 16:42:08 +02:00
for (i = 0; i < DISPLAY_HEIGHT; i++)
2018-01-14 20:45:44 +01:00
{
2018-01-29 17:47:12 +01:00
gScanlineEffectRegBuffers[1][i] = 0;
2021-10-25 16:42:08 +02:00
gScanlineEffectRegBuffers[1][i + DISPLAY_HEIGHT] = DISPLAY_WIDTH;
2018-01-14 20:45:44 +01:00
}
EnableInterrupts(INTR_FLAG_HBLANK);
2021-10-27 22:17:27 +02:00
SetHBlankCallback(HBlankCB_WhiteBarsFade);
SetVBlankCallback(VBlankCB_WhiteBarsFade);
2018-01-14 20:45:44 +01:00
task->tState++;
return FALSE;
}
2021-10-27 22:17:27 +02:00
static bool8 WhiteBarsFade_StartBars(struct Task *task)
2018-01-14 20:45:44 +01:00
{
s16 i, posY;
2021-10-27 22:17:27 +02:00
s16 delays[ARRAY_COUNT(sWhiteBarsFade_StartDelays)];
2018-01-14 20:45:44 +01:00
struct Sprite *sprite;
2021-10-27 22:17:27 +02:00
memcpy(delays, sWhiteBarsFade_StartDelays, sizeof(sWhiteBarsFade_StartDelays));
2018-01-14 20:45:44 +01:00
2021-10-27 22:17:27 +02:00
for (i = 0, posY = 0; i < NUM_WHITE_BARS; i++, posY += DISPLAY_HEIGHT / NUM_WHITE_BARS)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
sprite = &gSprites[CreateInvisibleSprite(SpriteCB_WhiteBarFade)];
2021-10-25 16:42:08 +02:00
sprite->x = DISPLAY_WIDTH;
2021-07-07 15:11:52 +02:00
sprite->y = posY;
2021-10-27 22:17:27 +02:00
sprite->sDelay = delays[i];
2018-01-14 20:45:44 +01:00
}
2021-10-27 22:17:27 +02:00
// Set on one sprite only. This one will enable the DMA
// copy in VBlank and wait for the others to destroy.
sprite->sIsMainSprite++;
2018-01-14 20:45:44 +01:00
task->tState++;
return FALSE;
}
2021-10-27 22:17:27 +02:00
static bool8 WhiteBarsFade_WaitBars(struct Task *task)
2018-01-14 20:45:44 +01:00
{
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA = 0;
2021-10-27 22:17:27 +02:00
if (sTransitionData->counter >= NUM_WHITE_BARS)
2018-01-14 20:45:44 +01:00
{
2021-10-25 16:42:08 +02:00
BlendPalettes(PALETTES_ALL, 16, RGB_WHITE);
2018-01-14 20:45:44 +01:00
task->tState++;
}
return FALSE;
}
2021-10-27 22:17:27 +02:00
static bool8 WhiteBarsFade_BlendToBlack(struct Task *task)
2018-01-14 20:45:44 +01:00
{
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA = 0;
2018-01-14 20:45:44 +01:00
DmaStop(0);
SetVBlankCallback(0);
SetHBlankCallback(0);
2021-10-25 16:42:08 +02:00
sTransitionData->WIN0H = DISPLAY_WIDTH;
sTransitionData->BLDY = 0;
sTransitionData->BLDCNT = 0xFF;
sTransitionData->WININ = WININ_WIN0_ALL;
2018-01-14 20:45:44 +01:00
2021-10-27 22:17:27 +02:00
SetVBlankCallback(VBlankCB_WhiteBarsFade_Blend);
2018-01-14 20:45:44 +01:00
task->tState++;
return FALSE;
}
2021-10-27 22:17:27 +02:00
static bool8 WhiteBarsFade_End(struct Task *task)
2018-01-14 20:45:44 +01:00
{
2021-10-25 16:42:08 +02:00
if (++sTransitionData->BLDY > 16)
2018-01-14 20:45:44 +01:00
{
2020-06-01 16:17:25 +02:00
FadeScreenBlack();
2021-10-27 22:17:27 +02:00
DestroyTask(FindTaskIdByFunc(Task_WhiteBarsFade));
2018-01-14 20:45:44 +01:00
}
return FALSE;
}
2021-10-27 22:17:27 +02:00
static void VBlankCB_WhiteBarsFade(void)
2018-01-14 20:45:44 +01:00
{
DmaStop(0);
VBlankCB_BattleTransition();
2021-10-25 16:42:08 +02:00
REG_BLDCNT = sTransitionData->BLDCNT;
REG_WININ = sTransitionData->WININ;
REG_WINOUT = sTransitionData->WINOUT;
REG_WIN0V = sTransitionData->WIN0V;
if (sTransitionData->VBlank_DMA)
DmaCopy16(3, gScanlineEffectRegBuffers[0], gScanlineEffectRegBuffers[1], DISPLAY_HEIGHT * 4);
DmaSet(0, &gScanlineEffectRegBuffers[1][DISPLAY_HEIGHT], &REG_WIN0H, B_TRANS_DMA_FLAGS);
2018-01-14 20:45:44 +01:00
}
2021-10-27 22:17:27 +02:00
static void VBlankCB_WhiteBarsFade_Blend(void)
2018-01-14 20:45:44 +01:00
{
VBlankCB_BattleTransition();
2021-10-25 16:42:08 +02:00
REG_BLDY = sTransitionData->BLDY;
REG_BLDCNT = sTransitionData->BLDCNT;
REG_WININ = sTransitionData->WININ;
REG_WINOUT = sTransitionData->WINOUT;
REG_WIN0H = sTransitionData->WIN0H;
REG_WIN0V = sTransitionData->WIN0V;
2018-01-14 20:45:44 +01:00
}
2021-10-27 22:17:27 +02:00
static void HBlankCB_WhiteBarsFade(void)
2018-01-14 20:45:44 +01:00
{
2018-01-29 17:47:12 +01:00
REG_BLDY = gScanlineEffectRegBuffers[1][REG_VCOUNT];
2018-01-14 20:45:44 +01:00
}
2021-10-27 22:17:27 +02:00
static void SpriteCB_WhiteBarFade(struct Sprite *sprite)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
if (sprite->sDelay)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
sprite->sDelay--;
if (sprite->sIsMainSprite)
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA = 1;
2018-01-14 20:45:44 +01:00
}
else
{
u16 i;
2021-07-07 15:11:52 +02:00
u16* ptr1 = &gScanlineEffectRegBuffers[0][sprite->y];
2021-10-25 16:42:08 +02:00
u16* ptr2 = &gScanlineEffectRegBuffers[0][sprite->y + DISPLAY_HEIGHT];
2021-10-27 22:17:27 +02:00
for (i = 0; i < DISPLAY_HEIGHT / NUM_WHITE_BARS; i++)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
ptr1[i] = sprite->sFade >> 8;
ptr2[i] = (u8)sprite->x;
2018-01-14 20:45:44 +01:00
}
2021-10-27 22:17:27 +02:00
if (sprite->x == 0 && sprite->sFade == FADE_TARGET)
sprite->sFinished = TRUE;
2018-01-14 20:45:44 +01:00
2021-07-07 15:11:52 +02:00
sprite->x -= 16;
2021-10-27 22:17:27 +02:00
sprite->sFade += FADE_TARGET / 32;
2018-01-14 20:45:44 +01:00
2021-07-07 15:11:52 +02:00
if (sprite->x < 0)
sprite->x = 0;
2021-10-27 22:17:27 +02:00
if (sprite->sFade > FADE_TARGET)
sprite->sFade = FADE_TARGET;
2018-01-14 20:45:44 +01:00
2021-10-27 22:17:27 +02:00
if (sprite->sIsMainSprite)
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA = 1;
2018-01-14 20:45:44 +01:00
2021-10-27 22:17:27 +02:00
if (sprite->sFinished)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
// If not the main sprite, destroy self. Otherwise, wait until the
// others have destroyed themselves, or until enough time has elapsed.
if (!sprite->sIsMainSprite || (sTransitionData->counter >= NUM_WHITE_BARS - 1 && sprite->sDestroyAttempts++ > 7))
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
sTransitionData->counter++;
2018-01-14 20:45:44 +01:00
DestroySprite(sprite);
}
}
}
}
2021-10-27 22:17:27 +02:00
#undef sFade
#undef sFinished
#undef sDestroyAttempts
#undef sDelay
#undef sIsMainSprite
//---------------------------
// B_TRANSITION_GRID_SQUARES
//---------------------------
#define tDelay data[1]
#define tShrinkStage data[2]
static void Task_GridSquares(u8 taskId)
2018-01-14 20:45:44 +01:00
{
while (sGridSquares_Funcs[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-14 20:45:44 +01:00
}
2021-10-25 16:42:08 +02:00
static bool8 GridSquares_Init(struct Task *task)
2018-01-14 20:45:44 +01:00
{
2020-06-01 16:17:25 +02:00
u16 *tilemap, *tileset;
2018-01-14 20:45:44 +01:00
2020-06-01 16:17:25 +02:00
GetBg0TilesDst(&tilemap, &tileset);
2021-10-25 16:42:08 +02:00
CpuSet(sShrinkingBoxTileset, tileset, 16);
2021-10-27 22:17:27 +02:00
CpuFill16(0xF0 << 8, tilemap, BG_SCREEN_SIZE);
2021-10-25 16:42:08 +02:00
LoadPalette(sFieldEffectPal_Pokeball, 0xF0, sizeof(sFieldEffectPal_Pokeball));
2018-01-14 20:45:44 +01:00
task->tState++;
return FALSE;
}
2021-10-27 22:17:27 +02:00
static bool8 GridSquares_Main(struct Task *task)
2018-01-14 20:45:44 +01:00
{
2020-06-01 16:17:25 +02:00
u16* tileset;
2018-01-14 20:45:44 +01:00
2021-10-27 22:17:27 +02:00
if (task->tDelay == 0)
2018-01-14 20:45:44 +01:00
{
2020-06-01 16:17:25 +02:00
GetBg0TilemapDst(&tileset);
2021-10-27 22:17:27 +02:00
task->tDelay = 3;
task->tShrinkStage++;
CpuSet(&sShrinkingBoxTileset[task->tShrinkStage * 8], tileset, 16);
if (task->tShrinkStage > 13)
2018-01-14 20:45:44 +01:00
{
task->tState++;
2021-10-27 22:17:27 +02:00
task->tDelay = 16;
2018-01-14 20:45:44 +01:00
}
}
2021-10-27 22:17:27 +02:00
task->tDelay--;
2018-01-14 20:45:44 +01:00
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 GridSquares_End(struct Task *task)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
if (--task->tDelay == 0)
2018-01-14 20:45:44 +01:00
{
2020-06-01 16:17:25 +02:00
FadeScreenBlack();
DestroyTask(FindTaskIdByFunc(Task_GridSquares));
2018-01-14 20:45:44 +01:00
}
return FALSE;
}
2021-10-27 22:17:27 +02:00
#undef tDelay
#undef tShrinkStage
//---------------------------
// B_TRANSITION_ANGLED_WIPES
//---------------------------
#define tWipeId data[1]
#define tDir data[2]
#define tDelay data[3]
static void Task_AngledWipes(u8 taskId)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
while (sAngledWipes_Funcs[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-14 20:45:44 +01:00
}
2021-10-27 22:17:27 +02:00
static bool8 AngledWipes_Init(struct Task *task)
2018-01-14 20:45:44 +01:00
{
u16 i;
2021-10-25 16:42:08 +02:00
InitTransitionData();
2018-01-29 17:47:12 +01:00
ScanlineEffect_Clear();
2018-01-14 20:45:44 +01:00
2021-10-25 16:42:08 +02:00
sTransitionData->WININ = WININ_WIN0_ALL;
sTransitionData->WINOUT = 0;
sTransitionData->WIN0V = DISPLAY_HEIGHT;
2018-01-14 20:45:44 +01:00
2021-10-25 16:42:08 +02:00
for (i = 0; i < DISPLAY_HEIGHT; i++)
gScanlineEffectRegBuffers[0][i] = DISPLAY_WIDTH;
2018-01-14 20:45:44 +01:00
2021-10-25 16:42:08 +02:00
CpuSet(gScanlineEffectRegBuffers[0], gScanlineEffectRegBuffers[1], DISPLAY_HEIGHT);
2021-10-27 22:17:27 +02:00
SetVBlankCallback(VBlankCB_AngledWipes);
2018-01-14 20:45:44 +01:00
task->tState++;
return TRUE;
}
2021-10-27 22:17:27 +02:00
static bool8 AngledWipes_SetWipeData(struct Task *task)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
InitBlackWipe(sTransitionData->data,
sAngledWipes_MoveData[task->tWipeId][0],
sAngledWipes_MoveData[task->tWipeId][1],
sAngledWipes_MoveData[task->tWipeId][2],
sAngledWipes_MoveData[task->tWipeId][3],
1, 1);
task->tDir = sAngledWipes_MoveData[task->tWipeId][4];
2018-01-14 20:45:44 +01:00
task->tState++;
return TRUE;
}
2021-10-27 22:17:27 +02:00
static bool8 AngledWipes_DoWipe(struct Task *task)
2018-01-14 20:45:44 +01:00
{
s16 i;
2021-10-27 22:17:27 +02:00
bool8 finished;
2018-01-14 20:45:44 +01:00
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA = 0;
2018-01-14 20:45:44 +01:00
2021-10-27 22:17:27 +02:00
for (i = 0, finished = FALSE; i < 16; i++)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
s16 r3 = gScanlineEffectRegBuffers[0][sTransitionData->tWipeCurrY] >> 8;
s16 r4 = gScanlineEffectRegBuffers[0][sTransitionData->tWipeCurrY] & 0xFF;
if (task->tDir == 0)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
// Moving down
if (r3 < sTransitionData->tWipeCurrX)
r3 = sTransitionData->tWipeCurrX;
2018-01-14 20:45:44 +01:00
if (r3 > r4)
r3 = r4;
}
else
{
2021-10-27 22:17:27 +02:00
// Moving up
if (r4 > sTransitionData->tWipeCurrX)
r4 = sTransitionData->tWipeCurrX;
2018-01-14 20:45:44 +01:00
if (r4 <= r3)
r4 = r3;
}
2021-10-27 22:17:27 +02:00
gScanlineEffectRegBuffers[0][sTransitionData->tWipeCurrY] = (r4) | (r3 << 8);
if (finished)
2018-01-14 20:45:44 +01:00
{
task->tState++;
break;
}
2021-10-27 22:17:27 +02:00
finished = UpdateBlackWipe(sTransitionData->data, TRUE, TRUE);
2018-01-14 20:45:44 +01:00
}
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA++;
2018-01-14 20:45:44 +01:00
return FALSE;
}
2021-10-27 22:17:27 +02:00
static bool8 AngledWipes_TryEnd(struct Task *task)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
if (++task->tWipeId < NUM_ANGLED_WIPES)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
// Continue with next wipe
2018-01-14 20:45:44 +01:00
task->tState++;
2021-10-27 22:17:27 +02:00
task->tDelay = sAngledWipes_EndDelays[task->tWipeId - 1];
2018-01-14 20:45:44 +01:00
return TRUE;
}
else
{
2021-10-27 22:17:27 +02:00
// End transition
2018-01-14 20:45:44 +01:00
DmaStop(0);
2020-06-01 16:17:25 +02:00
FadeScreenBlack();
2021-10-27 22:17:27 +02:00
DestroyTask(FindTaskIdByFunc(Task_AngledWipes));
2018-01-14 20:45:44 +01:00
return FALSE;
}
}
2021-10-27 22:17:27 +02:00
static bool8 AngledWipes_StartNext(struct Task *task)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
if (--task->tDelay == 0)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
// Return to AngledWipes_SetWipeData
2018-01-14 20:45:44 +01:00
task->tState = 1;
return TRUE;
}
2020-06-01 16:17:25 +02:00
return FALSE;
2018-01-14 20:45:44 +01:00
}
2021-10-27 22:17:27 +02:00
static void VBlankCB_AngledWipes(void)
2018-01-14 20:45:44 +01:00
{
DmaStop(0);
VBlankCB_BattleTransition();
2021-10-25 16:42:08 +02:00
if (sTransitionData->VBlank_DMA)
DmaCopy16(3, gScanlineEffectRegBuffers[0], gScanlineEffectRegBuffers[1], DISPLAY_HEIGHT * 2);
REG_WININ = sTransitionData->WININ;
REG_WINOUT = sTransitionData->WINOUT;
REG_WIN0V = sTransitionData->WIN0V;
2018-01-29 17:47:12 +01:00
REG_WIN0H = gScanlineEffectRegBuffers[1][0];
2021-10-25 16:42:08 +02:00
DmaSet(0, gScanlineEffectRegBuffers[1], &REG_WIN0H, B_TRANS_DMA_FLAGS);
2018-01-14 20:45:44 +01:00
}
2021-10-27 22:17:27 +02:00
#undef tWipeId
#undef tDir
#undef tDelay
//-----------------------------------
// Transition intro
//-----------------------------------
2018-01-14 20:45:44 +01:00
2021-10-27 22:17:27 +02:00
#define tFadeToGrayDelay data[1]
#define tFadeFromGrayDelay data[2]
#define tNumFades data[3]
#define tFadeToGrayIncrement data[4]
#define tFadeFromGrayIncrement data[5]
#define tDelayTimer data[6]
#define tBlend data[7]
static void CreateIntroTask(s16 fadeToGrayDelay, s16 fadeFromGrayDelay, s16 numFades, s16 fadeToGrayIncrement, s16 fadeFromGrayIncrement)
2018-01-14 20:45:44 +01:00
{
u8 taskId = CreateTask(Task_BattleTransition_Intro, 3);
2021-10-27 22:17:27 +02:00
gTasks[taskId].tFadeToGrayDelay = fadeToGrayDelay;
gTasks[taskId].tFadeFromGrayDelay = fadeFromGrayDelay;
gTasks[taskId].tNumFades = numFades;
gTasks[taskId].tFadeToGrayIncrement = fadeToGrayIncrement;
gTasks[taskId].tFadeFromGrayIncrement = fadeFromGrayIncrement;
gTasks[taskId].tDelayTimer = fadeToGrayDelay;
2018-01-14 20:45:44 +01:00
}
static bool8 IsIntroTaskDone(void)
2018-01-14 20:45:44 +01:00
{
if (FindTaskIdByFunc(Task_BattleTransition_Intro) == TASK_NONE)
2018-01-14 20:45:44 +01:00
return TRUE;
else
return FALSE;
}
void Task_BattleTransition_Intro(u8 taskId)
2018-01-14 20:45:44 +01:00
{
while (sTransitionIntroFuncs[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-14 20:45:44 +01:00
}
2021-10-27 22:17:27 +02:00
static bool8 TransitionIntro_FadeToGray(struct Task *task)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
if (task->tDelayTimer == 0 || --task->tDelayTimer == 0)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
task->tDelayTimer = task->tFadeToGrayDelay;
task->tBlend += task->tFadeToGrayIncrement;
if (task->tBlend > 16)
task->tBlend = 16;
BlendPalettes(PALETTES_ALL, task->tBlend, RGB(11, 11, 11));
2018-01-14 20:45:44 +01:00
}
2021-10-27 22:17:27 +02:00
if (task->tBlend >= 16)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
// Fade to gray complete, start fade back
2018-01-14 20:45:44 +01:00
task->tState++;
2021-10-27 22:17:27 +02:00
task->tDelayTimer = task->tFadeFromGrayDelay;
2018-01-14 20:45:44 +01:00
}
return FALSE;
}
2021-10-27 22:17:27 +02:00
static bool8 TransitionIntro_FadeFromGray(struct Task *task)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
if (task->tDelayTimer == 0 || --task->tDelayTimer == 0)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
task->tDelayTimer = task->tFadeFromGrayDelay;
task->tBlend -= task->tFadeFromGrayIncrement;
if (task->tBlend < 0)
task->tBlend = 0;
BlendPalettes(PALETTES_ALL, task->tBlend, RGB(11, 11, 11));
2018-01-14 20:45:44 +01:00
}
2021-10-27 22:17:27 +02:00
if (task->tBlend == 0)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
if (--task->tNumFades == 0)
{
// All fades done, end intro
DestroyTask(FindTaskIdByFunc(Task_BattleTransition_Intro));
2021-10-27 22:17:27 +02:00
}
2018-01-14 20:45:44 +01:00
else
{
2021-10-27 22:17:27 +02:00
// Fade from gray complete, start new fade
task->tDelayTimer = task->tFadeToGrayDelay;
2018-01-14 20:45:44 +01:00
task->tState = 0;
}
}
return FALSE;
}
2021-10-27 22:17:27 +02:00
#undef tFadeToGrayDelay
#undef tFadeFromGrayDelay
#undef tNumFades
#undef tFadeToGrayIncrement
#undef tFadeFromGrayIncrement
#undef tDelayTimer
#undef tBlend
//-----------------------------------
// General transition functions
//-----------------------------------
2021-10-25 16:42:08 +02:00
static void InitTransitionData(void)
2018-01-14 20:45:44 +01:00
{
2021-10-25 16:42:08 +02:00
memset(sTransitionData, 0, sizeof(*sTransitionData));
GetCameraOffsetWithPan(&sTransitionData->cameraX, &sTransitionData->cameraY);
2018-01-14 20:45:44 +01:00
}
2018-01-14 22:09:35 +01:00
static void VBlankCB_BattleTransition(void)
2018-01-14 20:45:44 +01:00
{
LoadOam();
ProcessSpriteCopyRequests();
TransferPlttBuffer();
}
2020-06-01 16:17:25 +02:00
static void GetBg0TilemapDst(u16 **tileset)
2018-01-14 20:45:44 +01:00
{
2020-06-01 16:17:25 +02:00
u16 charBase = REG_BG0CNT >> 2;
2021-10-25 16:42:08 +02:00
charBase <<= 14;
2021-10-27 22:17:27 +02:00
*tileset = (u16*)(BG_VRAM + charBase);
2018-01-14 20:45:44 +01:00
}
2020-06-01 16:17:25 +02:00
void GetBg0TilesDst(u16 **tilemap, u16 **tileset)
2018-01-14 20:45:44 +01:00
{
2020-06-01 16:17:25 +02:00
u16 screenBase = REG_BG0CNT >> 8;
u16 charBase = REG_BG0CNT >> 2;
2018-01-14 20:45:44 +01:00
2021-10-25 16:42:08 +02:00
screenBase <<= 11;
charBase <<= 14;
2018-01-14 20:45:44 +01:00
2021-10-27 22:17:27 +02:00
*tilemap = (u16*)(BG_VRAM + screenBase);
*tileset = (u16*)(BG_VRAM + charBase);
2018-01-14 20:45:44 +01:00
}
2020-06-01 16:17:25 +02:00
static void FadeScreenBlack(void)
2018-01-14 20:45:44 +01:00
{
2021-02-24 17:01:02 +01:00
BlendPalettes(PALETTES_ALL, 16, RGB_BLACK);
2018-01-14 20:45:44 +01:00
}
2021-10-25 16:42:08 +02:00
static void SetSinWave(s16 *array, s16 sinAdd, s16 index, s16 indexIncrementer, s16 amplitude, s16 arrSize)
2018-01-14 20:45:44 +01:00
{
u8 i;
for (i = 0; arrSize > 0; arrSize--, i++, index += indexIncrementer)
2021-10-25 16:42:08 +02:00
array[i] = sinAdd + Sin(index & 0xFF, amplitude);
2018-01-14 20:45:44 +01:00
}
2021-10-27 22:17:27 +02:00
static void SetCircularMask(u16 *buffer, s16 centerX, s16 centerY, s16 radius)
2018-01-14 20:45:44 +01:00
{
s16 i;
2021-10-27 22:17:27 +02:00
memset(buffer, 10, DISPLAY_HEIGHT * sizeof(u16));
2018-01-14 20:45:44 +01:00
for (i = 0; i < 64; i++)
{
s16 sinResult, cosResult;
2021-10-27 22:17:27 +02:00
s16 drawXLeft, drawYBottNext, drawYTopNext, drawX, drawYTop, drawYBott;
sinResult = Sin(i, radius);
cosResult = Cos(i, radius);
drawXLeft = centerX - sinResult;
drawX = centerX + sinResult;
drawYTop = centerY - cosResult;
drawYBott = centerY + cosResult;
if (drawXLeft < 0)
drawXLeft = 0;
if (drawX > DISPLAY_WIDTH)
drawX = DISPLAY_WIDTH;
if (drawYTop < 0)
drawYTop = 0;
if (drawYBott > DISPLAY_HEIGHT - 1)
drawYBott = DISPLAY_HEIGHT - 1;
drawX |= (drawXLeft << 8);
buffer[drawYTop] = drawX;
buffer[drawYBott] = drawX;
cosResult = Cos(i + 1, radius);
drawYTopNext = centerY - cosResult;
drawYBottNext = centerY + cosResult;
if (drawYTopNext < 0)
drawYTopNext = 0;
if (drawYBottNext > DISPLAY_HEIGHT - 1)
drawYBottNext = DISPLAY_HEIGHT - 1;
while (drawYTop > drawYTopNext)
buffer[--drawYTop] = drawX;
while (drawYTop < drawYTopNext)
buffer[++drawYTop] = drawX;
while (drawYBott > drawYBottNext)
buffer[--drawYBott] = drawX;
while (drawYBott < drawYBottNext)
buffer[++drawYBott] = drawX;
2018-01-14 20:45:44 +01:00
}
}
2021-10-27 22:17:27 +02:00
static void InitBlackWipe(s16 *data, s16 startX, s16 startY, s16 endX, s16 endY, s16 xMove, s16 yMove)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
tWipeStartX = startX;
tWipeStartY = startY;
tWipeCurrX = startX;
tWipeCurrY = startY;
tWipeEndX = endX;
tWipeEndY = endY;
tWipeXMove = xMove;
tWipeYMove = yMove;
tWipeXDist = endX - startX;
if (tWipeXDist < 0)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
// If end was less than start, reverse direction
tWipeXDist = -tWipeXDist;
tWipeXMove = -xMove;
2018-01-14 20:45:44 +01:00
}
2021-10-27 22:17:27 +02:00
tWipeYDist = endY - startY;
if (tWipeYDist < 0)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
// If end was less than start, reverse direction
tWipeYDist = -tWipeYDist;
tWipeYMove = -yMove;
2018-01-14 20:45:44 +01:00
}
2021-10-27 22:17:27 +02:00
tWipeTemp = 0;
2018-01-14 20:45:44 +01:00
}
2021-10-27 22:17:27 +02:00
static bool8 UpdateBlackWipe(s16 *data, bool8 xExact, bool8 yExact)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
u8 numFinished;
if (tWipeXDist > tWipeYDist)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
// X has further to move, move it first
tWipeCurrX += tWipeXMove;
// If it has been far enough since Y's
// last move then move it too
tWipeTemp += tWipeYDist;
if (tWipeTemp > tWipeXDist)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
tWipeCurrY += tWipeYMove;
tWipeTemp -= tWipeXDist;
2018-01-14 20:45:44 +01:00
}
}
else
{
2021-10-27 22:17:27 +02:00
// Y has further to move, move it first
tWipeCurrY += tWipeYMove;
// If it has been far enough since X's
// last move then move it too
tWipeTemp += tWipeXDist;
if (tWipeTemp > tWipeYDist)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
tWipeCurrX += tWipeXMove;
tWipeTemp -= tWipeYDist;
2018-01-14 20:45:44 +01:00
}
}
2021-10-27 22:17:27 +02:00
numFinished = 0;
// Has X coord reached end?
if ((tWipeXMove > 0 && tWipeCurrX >= tWipeEndX)
|| (tWipeXMove < 0 && tWipeCurrX <= tWipeEndX))
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
numFinished++;
if (xExact)
tWipeCurrX = tWipeEndX;
2018-01-14 20:45:44 +01:00
}
2021-10-27 22:17:27 +02:00
// Has Y coord reached end?
if ((tWipeYMove > 0 && tWipeCurrY >= tWipeEndY)
|| (tWipeYMove < 0 && tWipeCurrY <= tWipeEndY))
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
numFinished++;
if (yExact)
tWipeCurrY = tWipeEndY;
2018-01-14 20:45:44 +01:00
}
2021-10-27 22:17:27 +02:00
// Return TRUE if both coords have reached end
if (numFinished == 2)
2018-01-14 20:45:44 +01:00
return TRUE;
else
return FALSE;
}
2021-10-27 22:17:27 +02:00
//-----------------------------------
// B_TRANSITION_FRONTIER_LOGO_WIGGLE
//-----------------------------------
2021-10-29 17:56:06 +02:00
#define tSinIndex data[4]
2021-10-27 22:17:27 +02:00
#define tAmplitude data[5]
2021-10-25 16:42:08 +02:00
static bool8 FrontierLogoWiggle_Init(struct Task *task)
2018-01-14 20:45:44 +01:00
{
2020-06-01 16:17:25 +02:00
u16 *tilemap, *tileset;
2018-01-14 20:45:44 +01:00
2021-10-25 16:42:08 +02:00
InitPatternWeaveTransition(task);
2020-06-01 16:17:25 +02:00
GetBg0TilesDst(&tilemap, &tileset);
2021-10-25 16:42:08 +02:00
CpuFill16(0, tilemap, BG_SCREEN_SIZE);
2020-07-02 21:45:37 +02:00
LZ77UnCompVram(sFrontierLogo_Tileset, tileset);
2021-10-25 16:42:08 +02:00
LoadPalette(sFrontierLogo_Palette, 0xF0, sizeof(sFrontierLogo_Palette));
2018-01-14 20:45:44 +01:00
task->tState++;
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 FrontierLogoWiggle_SetGfx(struct Task *task)
2018-01-14 20:45:44 +01:00
{
2020-06-01 16:17:25 +02:00
u16 *tilemap, *tileset;
2018-01-14 20:45:44 +01:00
2020-06-01 16:17:25 +02:00
GetBg0TilesDst(&tilemap, &tileset);
2020-07-02 21:45:37 +02:00
LZ77UnCompVram(sFrontierLogo_Tilemap, tilemap);
2021-10-29 17:56:06 +02:00
SetSinWave(gScanlineEffectRegBuffers[0], 0, task->tSinIndex, 132, task->tAmplitude, DISPLAY_HEIGHT);
2018-01-14 20:45:44 +01:00
task->tState++;
return TRUE;
}
static void Task_FrontierLogoWiggle(u8 taskId)
2018-01-14 20:45:44 +01:00
{
while (sFrontierLogoWiggle_Funcs[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-14 20:45:44 +01:00
}
2021-10-29 17:56:06 +02:00
#undef tSinIndex
2021-10-27 22:17:27 +02:00
#undef tAmplitude
//---------------------------------
// B_TRANSITION_FRONTIER_LOGO_WAVE
//---------------------------------
#define tSinVal data[1]
#define tAmplitudeVal data[2]
#define tTimer data[3]
#define tStartedFade data[4]
#define tBlendTarget2 data[5]
#define tBlendTarget1 data[6]
#define tSinDecrement data[7]
static void Task_FrontierLogoWave(u8 taskId)
2018-01-14 20:45:44 +01:00
{
while (sFrontierLogoWave_Funcs[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-14 20:45:44 +01:00
}
2021-10-25 16:42:08 +02:00
static bool8 FrontierLogoWave_Init(struct Task *task)
2018-01-14 20:45:44 +01:00
{
2020-06-01 16:17:25 +02:00
u16 *tilemap, *tileset;
2018-01-14 20:45:44 +01:00
2021-10-25 16:42:08 +02:00
InitTransitionData();
2018-01-29 17:47:12 +01:00
ScanlineEffect_Clear();
2018-01-14 20:45:44 +01:00
ClearGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON | DISPCNT_WIN1_ON);
2021-10-27 22:17:27 +02:00
task->tAmplitudeVal = 32 << 8;
task->tSinVal = 0x7FFF;
task->tBlendTarget2 = 0;
task->tBlendTarget1 = 16;
task->tSinDecrement = 2560;
2021-10-25 16:42:08 +02:00
sTransitionData->BLDCNT = BLDCNT_TGT1_BG0 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_ALL;
2021-10-27 22:17:27 +02:00
sTransitionData->BLDALPHA = BLDALPHA_BLEND(task->tBlendTarget2, task->tBlendTarget1);
2021-10-25 16:42:08 +02:00
REG_BLDCNT = sTransitionData->BLDCNT;
REG_BLDALPHA = sTransitionData->BLDALPHA;
2020-06-01 16:17:25 +02:00
GetBg0TilesDst(&tilemap, &tileset);
2021-10-25 16:42:08 +02:00
CpuFill16(0, tilemap, BG_SCREEN_SIZE);
2020-07-02 21:45:37 +02:00
LZ77UnCompVram(sFrontierLogo_Tileset, tileset);
2021-10-25 16:42:08 +02:00
LoadPalette(sFrontierLogo_Palette, 0xF0, sizeof(sFrontierLogo_Palette));
sTransitionData->cameraY = 0;
2018-01-14 20:45:44 +01:00
task->tState++;
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 FrontierLogoWave_SetGfx(struct Task *task)
2018-01-14 20:45:44 +01:00
{
2020-06-01 16:17:25 +02:00
u16 *tilemap, *tileset;
2018-01-14 20:45:44 +01:00
2020-06-01 16:17:25 +02:00
GetBg0TilesDst(&tilemap, &tileset);
2020-07-02 21:45:37 +02:00
LZ77UnCompVram(sFrontierLogo_Tilemap, tilemap);
2018-01-14 20:45:44 +01:00
task->tState++;
return TRUE;
}
2021-10-29 17:56:06 +02:00
static bool8 FrontierLogoWave_InitScanline(struct Task *task)
2018-01-14 20:45:44 +01:00
{
u8 i;
2021-10-25 16:42:08 +02:00
for (i = 0; i < DISPLAY_HEIGHT; i++)
gScanlineEffectRegBuffers[1][i] = sTransitionData->cameraY;
2018-01-14 20:45:44 +01:00
2021-10-25 16:42:08 +02:00
SetVBlankCallback(VBlankCB_FrontierLogoWave);
SetHBlankCallback(HBlankCB_FrontierLogoWave);
2018-01-14 20:45:44 +01:00
EnableInterrupts(INTR_FLAG_HBLANK);
task->tState++;
return TRUE;
}
2021-10-29 17:56:06 +02:00
static bool8 FrontierLogoWave_Main(struct Task *task)
2018-01-14 20:45:44 +01:00
{
u8 i;
2021-10-27 22:17:27 +02:00
u16 sinVal, amplitude, sinSpread;
2018-01-14 20:45:44 +01:00
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA = FALSE;
2018-01-14 20:45:44 +01:00
2021-10-27 22:17:27 +02:00
amplitude = task->tAmplitudeVal >> 8;
sinVal = task->tSinVal;
sinSpread = 384;
2018-01-14 20:45:44 +01:00
2021-10-27 22:17:27 +02:00
task->tSinVal -= task->tSinDecrement;
2018-01-14 20:45:44 +01:00
2021-10-27 22:17:27 +02:00
if (task->tTimer >= 70)
2018-01-14 20:45:44 +01:00
{
2021-10-29 17:56:06 +02:00
// Decrease amount of logo movement and distortion
// until it rests normally in the middle of the screen.
2021-10-27 22:17:27 +02:00
if (task->tAmplitudeVal - 384 >= 0)
task->tAmplitudeVal -= 384;
2018-01-14 20:45:44 +01:00
else
2021-10-27 22:17:27 +02:00
task->tAmplitudeVal = 0;
2018-01-14 20:45:44 +01:00
}
2021-10-27 22:17:27 +02:00
if (task->tTimer >= 0 && task->tTimer % 3 == 0)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
// Blend logo into view
if (task->tBlendTarget2 < 16)
task->tBlendTarget2++;
else if (task->tBlendTarget1 > 0)
task->tBlendTarget1--;
2018-01-14 20:45:44 +01:00
2021-10-27 22:17:27 +02:00
sTransitionData->BLDALPHA = BLDALPHA_BLEND(task->tBlendTarget2, task->tBlendTarget1);
2018-01-14 20:45:44 +01:00
}
2021-10-29 17:56:06 +02:00
// Move logo up and down and distort it
2021-10-27 22:17:27 +02:00
for (i = 0; i < DISPLAY_HEIGHT; i++, sinVal += sinSpread)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
s16 index = sinVal / 256;
2021-10-25 16:42:08 +02:00
gScanlineEffectRegBuffers[0][i] = sTransitionData->cameraY + Sin(index & 0xff, amplitude);
2018-01-14 20:45:44 +01:00
}
2021-10-27 22:17:27 +02:00
if (++task->tTimer == 101)
2018-01-14 20:45:44 +01:00
{
2021-10-27 22:17:27 +02:00
task->tStartedFade++;
2021-10-25 16:42:08 +02:00
BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK);
2018-01-14 20:45:44 +01:00
}
2021-10-27 22:17:27 +02:00
if (task->tStartedFade && !gPaletteFade.active)
DestroyTask(FindTaskIdByFunc(Task_FrontierLogoWave));
2018-01-14 20:45:44 +01:00
2021-10-27 22:17:27 +02:00
task->tSinDecrement -= 17;
2021-10-25 16:42:08 +02:00
sTransitionData->VBlank_DMA++;
2018-01-14 20:45:44 +01:00
return FALSE;
}
2021-10-25 16:42:08 +02:00
static void VBlankCB_FrontierLogoWave(void)
2018-01-14 20:45:44 +01:00
{
VBlankCB_BattleTransition();
2021-10-25 16:42:08 +02:00
REG_BLDCNT = sTransitionData->BLDCNT;
REG_BLDALPHA = sTransitionData->BLDALPHA;
2018-01-14 20:45:44 +01:00
2021-10-25 16:42:08 +02:00
if (sTransitionData->VBlank_DMA)
DmaCopy16(3, gScanlineEffectRegBuffers[0], gScanlineEffectRegBuffers[1], DISPLAY_HEIGHT * 2);
2018-01-14 20:45:44 +01:00
}
2021-10-25 16:42:08 +02:00
static void HBlankCB_FrontierLogoWave(void)
2018-01-14 20:45:44 +01:00
{
2018-01-29 17:47:12 +01:00
u16 var = gScanlineEffectRegBuffers[1][REG_VCOUNT];
2018-01-14 20:45:44 +01:00
REG_BG0VOFS = var;
}
2021-10-27 22:17:27 +02:00
#undef tSinVal
#undef tAmplitudeVal
#undef tTimer
#undef tStartedFade
#undef tBlendTarget2
#undef tBlendTarget1
#undef tSinDecrement
//----------------------------------------------------------------------
// B_TRANSITION_FRONTIER_SQUARES, B_TRANSITION_FRONTIER_SQUARES_SCROLL,
// and B_TRANSITION_FRONTIER_SQUARES_SPIRAL
//----------------------------------------------------------------------
#define tPosX data[2]
#define tPosY data[3]
#define tRowPos data[4]
#define tShrinkState data[5]
#define tShrinkDelayTimer data[6]
#define tShrinkDelay data[7]
static void Task_FrontierSquares(u8 taskId)
2018-01-14 20:45:44 +01:00
{
while (sFrontierSquares_Funcs[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-14 20:45:44 +01:00
}
static void Task_FrontierSquaresSpiral(u8 taskId)
2018-01-14 20:45:44 +01:00
{
while (sFrontierSquaresSpiral_Funcs[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-14 20:45:44 +01:00
}
static void Task_FrontierSquaresScroll(u8 taskId)
2018-01-14 20:45:44 +01:00
{
while (sFrontierSquaresScroll_Funcs[gTasks[taskId].tState](&gTasks[taskId]));
2018-01-14 20:45:44 +01:00
}
2021-10-25 16:42:08 +02:00
static bool8 FrontierSquares_Init(struct Task *task)
2018-01-14 22:09:35 +01:00
{
2020-06-01 16:17:25 +02:00
u16 *tilemap, *tileset;
2018-01-14 22:09:35 +01:00
2020-06-01 16:17:25 +02:00
GetBg0TilesDst(&tilemap, &tileset);
2020-07-02 21:45:37 +02:00
LZ77UnCompVram(sFrontierSquares_FilledBg_Tileset, tileset);
2018-01-14 22:09:35 +01:00
2021-10-29 17:56:06 +02:00
FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 32, 32);
FillBgTilemapBufferRect(0, 1, 0, 0, MARGIN_SIZE, 32, 15);
FillBgTilemapBufferRect(0, 1, 30 - MARGIN_SIZE, 0, MARGIN_SIZE, 32, 15);
2018-01-14 22:09:35 +01:00
CopyBgTilemapBufferToVram(0);
2021-10-25 16:42:08 +02:00
LoadPalette(sFrontierSquares_Palette, 0xF0, sizeof(sFrontierSquares_Palette));
2018-01-14 22:09:35 +01:00
2021-10-29 17:56:06 +02:00
task->tPosX = MARGIN_SIZE;
2021-10-27 22:17:27 +02:00
task->tPosY = 0;
task->tRowPos = 0;
task->tShrinkDelay = 10;
2018-01-14 22:09:35 +01:00
task->tState++;
return FALSE;
}
2021-10-27 22:17:27 +02:00
static bool8 FrontierSquares_Draw(struct Task *task)
2018-01-14 22:09:35 +01:00
{
2021-10-27 22:17:27 +02:00
CopyRectToBgTilemapBufferRect(0, sFrontierSquares_Tilemap, 0, 0,
SQUARE_SIZE, SQUARE_SIZE,
task->tPosX, task->tPosY,
SQUARE_SIZE, SQUARE_SIZE,
15, 0, 0);
2018-01-14 22:09:35 +01:00
CopyBgTilemapBufferToVram(0);
2021-10-27 22:17:27 +02:00
task->tPosX += SQUARE_SIZE;
if (++task->tRowPos == NUM_SQUARES_PER_ROW)
2018-01-14 22:09:35 +01:00
{
2021-10-29 17:56:06 +02:00
task->tPosX = MARGIN_SIZE;
2021-10-27 22:17:27 +02:00
task->tPosY += SQUARE_SIZE;
task->tRowPos = 0;
if (task->tPosY >= NUM_SQUARES_PER_COL * SQUARE_SIZE)
2018-01-14 22:09:35 +01:00
task->tState++;
}
return FALSE;
}
2021-10-27 22:17:27 +02:00
static bool8 FrontierSquares_Shrink(struct Task *task)
2018-01-14 22:09:35 +01:00
{
u8 i;
2020-06-01 16:17:25 +02:00
u16 *tilemap, *tileset;
2018-01-14 22:09:35 +01:00
2020-06-01 16:17:25 +02:00
GetBg0TilesDst(&tilemap, &tileset);
2021-10-27 22:17:27 +02:00
if (task->tShrinkDelayTimer++ >= task->tShrinkDelay)
2018-01-14 22:09:35 +01:00
{
2021-10-27 22:17:27 +02:00
switch (task->tShrinkState)
2018-01-14 22:09:35 +01:00
{
case 0:
for (i = 250; i < 255; i++)
{
2021-10-29 17:56:06 +02:00
gPlttBufferUnfaded[i] = RGB_BLACK;
gPlttBufferFaded[i] = RGB_BLACK;
2018-01-14 22:09:35 +01:00
}
break;
case 1:
2021-10-25 16:42:08 +02:00
BlendPalettes(PALETTES_ALL & ~(1 << 15), 16, RGB_BLACK);
2020-07-02 21:45:37 +02:00
LZ77UnCompVram(sFrontierSquares_EmptyBg_Tileset, tileset);
2018-01-14 22:09:35 +01:00
break;
case 2:
2020-07-02 21:45:37 +02:00
LZ77UnCompVram(sFrontierSquares_Shrink1_Tileset, tileset);
2018-01-14 22:09:35 +01:00
break;
case 3:
2020-07-02 21:45:37 +02:00
LZ77UnCompVram(sFrontierSquares_Shrink2_Tileset, tileset);
2018-01-14 22:09:35 +01:00
break;
default:
2021-10-29 17:56:06 +02:00
FillBgTilemapBufferRect_Palette0(0, 1, 0, 0, 32, 32);
2018-01-14 22:09:35 +01:00
CopyBgTilemapBufferToVram(0);
task->tState++;
return FALSE;
}
2021-10-27 22:17:27 +02:00
task->tShrinkDelayTimer = 0;
task->tShrinkState++;
2018-01-14 22:09:35 +01:00
}
return FALSE;
}
2021-10-27 22:17:27 +02:00
#undef tPosX
#undef tPosY
#undef tRowPos
#undef tShrinkState
#undef tShrinkDelayTimer
#undef tShrinkDelay
2021-10-29 17:56:06 +02:00
#define tSquareNum data[2]
#define tFadeFlag data[3]
2021-10-25 16:42:08 +02:00
static bool8 FrontierSquaresSpiral_Init(struct Task *task)
2018-01-14 22:09:35 +01:00
{
2020-06-01 16:17:25 +02:00
u16 *tilemap, *tileset;
2018-01-14 22:09:35 +01:00
2020-06-01 16:17:25 +02:00
GetBg0TilesDst(&tilemap, &tileset);
2020-07-02 21:45:37 +02:00
LZ77UnCompVram(sFrontierSquares_FilledBg_Tileset, tileset);
2018-01-14 22:09:35 +01:00
2021-10-29 17:56:06 +02:00
FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 32, 32);
FillBgTilemapBufferRect(0, 1, 0, 0, MARGIN_SIZE, 32, 15);
FillBgTilemapBufferRect(0, 1, 30 - MARGIN_SIZE, 0, MARGIN_SIZE, 32, 15);
2018-01-14 22:09:35 +01:00
CopyBgTilemapBufferToVram(0);
2021-10-25 16:42:08 +02:00
LoadPalette(sFrontierSquares_Palette, 0xE0, sizeof(sFrontierSquares_Palette));
LoadPalette(sFrontierSquares_Palette, 0xF0, sizeof(sFrontierSquares_Palette));
2021-10-29 17:56:06 +02:00
BlendPalette(0xE0, 16, 8, RGB_BLACK);
2018-01-14 22:09:35 +01:00
2021-10-29 17:56:06 +02:00
task->tSquareNum = NUM_SQUARES - 1;
task->tFadeFlag = 0;
2018-01-14 22:09:35 +01:00
task->tState++;
return FALSE;
}
2021-10-29 17:56:06 +02:00
static bool8 FrontierSquaresSpiral_Outward(struct Task *task)
2018-01-14 22:09:35 +01:00
{
2021-10-29 17:56:06 +02:00
u8 pos = sFrontierSquaresSpiral_Positions[task->tSquareNum];
u8 x = pos % NUM_SQUARES_PER_ROW;
u8 y = pos / NUM_SQUARES_PER_ROW;
CopyRectToBgTilemapBufferRect(0, sFrontierSquares_Tilemap, 0, 0,
SQUARE_SIZE, SQUARE_SIZE,
SQUARE_SIZE * x + MARGIN_SIZE, SQUARE_SIZE * y,
SQUARE_SIZE, SQUARE_SIZE,
15, 0, 0);
2018-01-14 22:09:35 +01:00
CopyBgTilemapBufferToVram(0);
2021-10-29 17:56:06 +02:00
if (--task->tSquareNum < 0)
2018-01-14 22:09:35 +01:00
task->tState++;
return FALSE;
}
2021-10-29 17:56:06 +02:00
// Now that the overworld is completely covered by the squares,
// set it to black so it's not revealed when the squares are removed.
static bool8 FrontierSquaresSpiral_SetBlack(struct Task *task)
2018-01-14 22:09:35 +01:00
{
2021-10-29 17:56:06 +02:00
BlendPalette(0xE0, 16, 3, RGB_BLACK);
2021-10-25 16:42:08 +02:00
BlendPalettes(PALETTES_ALL & ~(1 << 15 | 1 << 14), 16, RGB_BLACK);
2018-01-14 22:09:35 +01:00
2021-10-29 17:56:06 +02:00
task->tSquareNum = 0;
task->tFadeFlag = 0;
2018-01-14 22:09:35 +01:00
task->tState++;
return FALSE;
}
2021-10-29 17:56:06 +02:00
// Spiral inward erasing the squares
static bool8 FrontierSquaresSpiral_Inward(struct Task *task)
2018-01-14 22:09:35 +01:00
{
2021-10-29 17:56:06 +02:00
// Each square is faded first, then the one that was faded last move is erased.
if (task->tFadeFlag ^= 1)
2018-01-14 22:09:35 +01:00
{
2021-10-29 17:56:06 +02:00
// Shade square
CopyRectToBgTilemapBufferRect(0, sFrontierSquares_Tilemap, 0, 0,
SQUARE_SIZE, SQUARE_SIZE,
SQUARE_SIZE * (sFrontierSquaresSpiral_Positions[task->tSquareNum] % NUM_SQUARES_PER_ROW) + MARGIN_SIZE,
SQUARE_SIZE * (sFrontierSquaresSpiral_Positions[task->tSquareNum] / NUM_SQUARES_PER_ROW),
SQUARE_SIZE, SQUARE_SIZE,
14, 0, 0);
2018-01-14 22:09:35 +01:00
}
else
{
2021-10-29 17:56:06 +02:00
if (task->tSquareNum > 0)
2018-01-14 22:09:35 +01:00
{
2021-10-29 17:56:06 +02:00
// Erase square
FillBgTilemapBufferRect(0, 1,
SQUARE_SIZE * (sFrontierSquaresSpiral_Positions[task->tSquareNum - 1] % NUM_SQUARES_PER_ROW) + MARGIN_SIZE,
SQUARE_SIZE * (sFrontierSquaresSpiral_Positions[task->tSquareNum - 1] / NUM_SQUARES_PER_ROW),
SQUARE_SIZE, SQUARE_SIZE,
15);
2018-01-14 22:09:35 +01:00
}
2021-10-29 17:56:06 +02:00
task->tSquareNum++;
2018-01-14 22:09:35 +01:00
}
2021-10-29 17:56:06 +02:00
if (task->tSquareNum >= NUM_SQUARES)
2018-01-14 22:09:35 +01:00
task->tState++;
CopyBgTilemapBufferToVram(0);
return FALSE;
}
static bool8 FrontierSquares_End(struct Task *task)
2018-01-14 22:09:35 +01:00
{
2021-10-29 17:56:06 +02:00
FillBgTilemapBufferRect_Palette0(0, 1, 0, 0, 32, 32);
2018-01-14 22:09:35 +01:00
CopyBgTilemapBufferToVram(0);
2021-10-25 16:42:08 +02:00
BlendPalettes(PALETTES_ALL, 16, RGB_BLACK);
2018-01-14 22:09:35 +01:00
DestroyTask(FindTaskIdByFunc(task->func));
return FALSE;
}
2021-10-29 17:56:06 +02:00
#undef tSquareNum
#undef tFadeFlag
#define tScrollXDir data[0]
#define tScrollYDir data[1]
#define tScrollUpdateFlag data[2]
2018-01-14 22:09:35 +01:00
2021-10-29 17:56:06 +02:00
#define tSquareNum data[2]
static void Task_ScrollBg(u8 taskId)
2018-01-14 22:09:35 +01:00
{
2021-10-29 17:56:06 +02:00
if (!(gTasks[taskId].tScrollUpdateFlag ^= 1))
2018-01-14 22:09:35 +01:00
{
SetGpuReg(REG_OFFSET_BG0VOFS, gBattle_BG0_X);
SetGpuReg(REG_OFFSET_BG0HOFS, gBattle_BG0_Y);
2021-10-29 17:56:06 +02:00
gBattle_BG0_X += gTasks[taskId].tScrollXDir;
gBattle_BG0_Y += gTasks[taskId].tScrollYDir;
2018-01-14 22:09:35 +01:00
}
}
2021-10-25 16:42:08 +02:00
static bool8 FrontierSquaresScroll_Init(struct Task *task)
2018-01-14 22:09:35 +01:00
{
u8 taskId = 0;
2020-06-01 16:17:25 +02:00
u16 *tilemap, *tileset;
2018-01-14 22:09:35 +01:00
2020-06-01 16:17:25 +02:00
GetBg0TilesDst(&tilemap, &tileset);
2020-07-02 21:45:37 +02:00
LZ77UnCompVram(sFrontierSquares_FilledBg_Tileset, tileset);
2021-10-29 17:56:06 +02:00
FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 32, 32);
2018-01-14 22:09:35 +01:00
CopyBgTilemapBufferToVram(0);
2021-10-25 16:42:08 +02:00
LoadPalette(sFrontierSquares_Palette, 0xF0, sizeof(sFrontierSquares_Palette));
2018-01-14 22:09:35 +01:00
gBattle_BG0_X = 0;
gBattle_BG0_Y = 0;
SetGpuReg(REG_OFFSET_BG0VOFS, gBattle_BG0_X);
SetGpuReg(REG_OFFSET_BG0HOFS, gBattle_BG0_Y);
2021-10-29 17:56:06 +02:00
task->tSquareNum = 0;
// Start scrolling bg in a random direction.
taskId = CreateTask(Task_ScrollBg, 1);
2018-01-14 22:09:35 +01:00
switch (Random() % 4)
{
2021-10-29 17:56:06 +02:00
case 0: // Down/right
gTasks[taskId].tScrollXDir = 1;
gTasks[taskId].tScrollYDir = 1;
2018-01-14 22:09:35 +01:00
break;
2021-10-29 17:56:06 +02:00
case 1: // Up/left
gTasks[taskId].tScrollXDir = -1;
gTasks[taskId].tScrollYDir = -1;
2018-01-14 22:09:35 +01:00
break;
2021-10-29 17:56:06 +02:00
case 2: // Up/right
gTasks[taskId].tScrollXDir = 1;
gTasks[taskId].tScrollYDir = -1;
2018-01-14 22:09:35 +01:00
break;
2021-10-29 17:56:06 +02:00
default: // Down/left
gTasks[taskId].tScrollXDir = -1;
gTasks[taskId].tScrollYDir = 1;
2018-01-14 22:09:35 +01:00
break;
}
task->tState++;
return FALSE;
}
2021-10-29 17:56:06 +02:00
static bool8 FrontierSquaresScroll_Draw(struct Task *task)
{
u8 pos = sFrontierSquaresScroll_Positions[task->tSquareNum];
u8 x = pos / (NUM_SQUARES_PER_ROW + 1); // +1 because during scroll an additional column covers the margin.
u8 y = pos % (NUM_SQUARES_PER_ROW + 1);
CopyRectToBgTilemapBufferRect(0, &sFrontierSquares_Tilemap, 0, 0,
SQUARE_SIZE, SQUARE_SIZE,
SQUARE_SIZE * x + MARGIN_SIZE, SQUARE_SIZE * y,
SQUARE_SIZE, SQUARE_SIZE,
15, 0, 0);
2018-01-14 22:09:35 +01:00
CopyBgTilemapBufferToVram(0);
2021-10-29 17:56:06 +02:00
if (++task->tSquareNum >= (int)ARRAY_COUNT(sFrontierSquaresScroll_Positions))
2018-01-14 22:09:35 +01:00
task->tState++;
return 0;
}
2021-10-29 17:56:06 +02:00
// Now that the overworld is completely covered by the squares,
// set it to black so it's not revealed when the squares are removed.
static bool8 FrontierSquaresScroll_SetBlack(struct Task *task)
2018-01-14 22:09:35 +01:00
{
2021-10-25 16:42:08 +02:00
BlendPalettes(PALETTES_ALL & ~(1 << 15), 16, RGB_BLACK);
2018-01-14 22:09:35 +01:00
2021-10-29 17:56:06 +02:00
task->tSquareNum = 0;
2018-01-14 22:09:35 +01:00
task->tState++;
return FALSE;
}
2021-10-29 17:56:06 +02:00
static bool8 FrontierSquaresScroll_Erase(struct Task *task)
2018-01-14 22:09:35 +01:00
{
2021-10-29 17:56:06 +02:00
u8 pos = sFrontierSquaresScroll_Positions[task->tSquareNum];
u8 x = pos / (NUM_SQUARES_PER_ROW + 1);
u8 y = pos % (NUM_SQUARES_PER_ROW + 1);
2018-01-14 22:09:35 +01:00
2021-10-29 17:56:06 +02:00
FillBgTilemapBufferRect(0, 1,
SQUARE_SIZE * x + MARGIN_SIZE, SQUARE_SIZE * y,
SQUARE_SIZE, SQUARE_SIZE,
15);
2018-01-14 22:09:35 +01:00
CopyBgTilemapBufferToVram(0);
2021-10-29 17:56:06 +02:00
if (++task->tSquareNum >= (int)ARRAY_COUNT(sFrontierSquaresScroll_Positions))
2018-01-14 22:09:35 +01:00
{
2021-10-29 17:56:06 +02:00
DestroyTask(FindTaskIdByFunc(Task_ScrollBg));
2018-01-14 22:09:35 +01:00
task->tState++;
}
return FALSE;
}
2021-10-25 16:42:08 +02:00
static bool8 FrontierSquaresScroll_End(struct Task *task)
2018-01-14 22:09:35 +01:00
{
gBattle_BG0_X = 0;
gBattle_BG0_Y = 0;
SetGpuReg(REG_OFFSET_BG0VOFS, 0);
SetGpuReg(REG_OFFSET_BG0HOFS, gBattle_BG0_Y);
2021-10-29 17:56:06 +02:00
FillBgTilemapBufferRect_Palette0(0, 1, 0, 0, 32, 32);
2018-01-14 22:09:35 +01:00
CopyBgTilemapBufferToVram(0);
2021-10-25 16:42:08 +02:00
BlendPalettes(PALETTES_ALL, 16, RGB_BLACK);
2018-01-14 22:09:35 +01:00
DestroyTask(FindTaskIdByFunc(task->func));
#ifndef UBFIX
2018-01-14 22:09:35 +01:00
task->tState++; // UB: changing value of a destroyed task
#endif
2018-01-14 22:09:35 +01:00
return FALSE;
}
2021-10-29 17:56:06 +02:00
#undef tScrollXDir
#undef tScrollYDir
#undef tScrollUpdateFlag
#undef tSquareNum