pokeemerald/src/fldeff_flash.c

366 lines
12 KiB
C
Raw Normal View History

2018-02-26 17:54:54 +05:30
#include "global.h"
2018-02-27 10:33:23 +05:30
#include "braille_puzzles.h"
2018-02-26 17:54:54 +05:30
#include "event_data.h"
#include "event_scripts.h"
#include "field_effect.h"
2018-12-24 21:59:05 +01:00
#include "fldeff.h"
2018-02-26 17:54:54 +05:30
#include "gpu_regs.h"
#include "main.h"
2018-11-14 00:01:50 +00:00
#include "overworld.h"
2018-02-26 17:54:54 +05:30
#include "palette.h"
#include "party_menu.h"
#include "script.h"
#include "sound.h"
#include "sprite.h"
#include "task.h"
2018-11-14 00:01:50 +00:00
#include "constants/songs.h"
2019-09-10 13:40:28 -04:00
#include "constants/map_types.h"
2018-02-26 17:54:54 +05:30
struct FlashStruct
{
2019-09-10 13:40:28 -04:00
u8 fromType;
u8 toType;
2019-09-29 16:33:13 -04:00
bool8 isEnter;
bool8 isExit;
2018-02-26 17:54:54 +05:30
void (*func)(void);
};
2019-10-22 17:28:05 -04:00
static void FieldCallback_Flash(void);
static void FldEff_UseFlash(void);
2019-09-29 16:33:13 -04:00
static bool8 TryDoMapTransition(void);
2019-09-10 13:40:28 -04:00
static void DoExitCaveTransition(void);
static void Task_ExitCaveTransition1(u8 taskId);
static void Task_ExitCaveTransition2(u8 taskId);
static void Task_ExitCaveTransition3(u8 taskId);
static void Task_ExitCaveTransition4(u8 taskId);
static void Task_ExitCaveTransition5(u8 taskId);
static void DoEnterCaveTransition(void);
static void Task_EnterCaveTransition1(u8 taskId);
static void Task_EnterCaveTransition2(u8 taskId);
static void Task_EnterCaveTransition3(u8 taskId);
static void Task_EnterCaveTransition4(u8 taskId);
2018-02-26 17:54:54 +05:30
2019-09-10 13:40:28 -04:00
static const struct FlashStruct sTransitionTypes[] =
2018-02-27 10:33:23 +05:30
{
2019-09-29 16:33:13 -04:00
{MAP_TYPE_TOWN, MAP_TYPE_UNDERGROUND, TRUE, FALSE, DoEnterCaveTransition},
{MAP_TYPE_CITY, MAP_TYPE_UNDERGROUND, TRUE, FALSE, DoEnterCaveTransition},
{MAP_TYPE_ROUTE, MAP_TYPE_UNDERGROUND, TRUE, FALSE, DoEnterCaveTransition},
{MAP_TYPE_UNDERWATER, MAP_TYPE_UNDERGROUND, TRUE, FALSE, DoEnterCaveTransition},
{MAP_TYPE_OCEAN_ROUTE, MAP_TYPE_UNDERGROUND, TRUE, FALSE, DoEnterCaveTransition},
2020-03-31 15:37:31 -04:00
{MAP_TYPE_UNKNOWN, MAP_TYPE_UNDERGROUND, TRUE, FALSE, DoEnterCaveTransition},
2019-09-29 16:33:13 -04:00
{MAP_TYPE_INDOOR, MAP_TYPE_UNDERGROUND, TRUE, FALSE, DoEnterCaveTransition},
{MAP_TYPE_SECRET_BASE, MAP_TYPE_UNDERGROUND, TRUE, FALSE, DoEnterCaveTransition},
{MAP_TYPE_UNDERGROUND, MAP_TYPE_TOWN, FALSE, TRUE, DoExitCaveTransition},
{MAP_TYPE_UNDERGROUND, MAP_TYPE_CITY, FALSE, TRUE, DoExitCaveTransition},
{MAP_TYPE_UNDERGROUND, MAP_TYPE_ROUTE, FALSE, TRUE, DoExitCaveTransition},
{MAP_TYPE_UNDERGROUND, MAP_TYPE_UNDERWATER, FALSE, TRUE, DoExitCaveTransition},
{MAP_TYPE_UNDERGROUND, MAP_TYPE_OCEAN_ROUTE, FALSE, TRUE, DoExitCaveTransition},
2020-03-31 15:37:31 -04:00
{MAP_TYPE_UNDERGROUND, MAP_TYPE_UNKNOWN, FALSE, TRUE, DoExitCaveTransition},
2019-09-29 16:33:13 -04:00
{MAP_TYPE_UNDERGROUND, MAP_TYPE_INDOOR, FALSE, TRUE, DoExitCaveTransition},
{MAP_TYPE_UNDERGROUND, MAP_TYPE_SECRET_BASE, FALSE, TRUE, DoExitCaveTransition},
{},
2018-02-27 10:33:23 +05:30
};
2018-02-26 17:54:54 +05:30
2022-01-14 12:29:30 -05:00
static const u16 sCaveTransitionPalette_White[] = INCBIN_U16("graphics/cave_transition/white.gbapal");
static const u16 sCaveTransitionPalette_Black[] = INCBIN_U16("graphics/cave_transition/black.gbapal");
2018-02-26 17:54:54 +05:30
2022-01-14 12:29:30 -05:00
static const u16 sCaveTransitionPalette_Enter[] = INCBIN_U16("graphics/cave_transition/enter.gbapal");
static const u16 sCaveTransitionPalette_Exit[] = INCBIN_U16("graphics/cave_transition/exit.gbapal");
static const u32 sCaveTransitionTilemap[] = INCBIN_U32("graphics/cave_transition/tilemap.bin.lz");
static const u32 sCaveTransitionTiles[] = INCBIN_U32("graphics/cave_transition/tiles.4bpp.lz");
2018-02-26 17:54:54 +05:30
bool8 SetUpFieldMove_Flash(void)
{
// In Ruby and Sapphire, Registeel's tomb is opened by using Fly. In Emerald,
// Flash is used instead.
if (ShouldDoBrailleRegisteelEffect())
2018-02-26 17:54:54 +05:30
{
gSpecialVar_Result = GetCursorSelectionMonId();
2018-06-16 00:45:48 +02:00
gFieldCallback2 = FieldCallback_PrepareFadeInFromMenu;
gPostMenuFieldCallback = SetUpPuzzleEffectRegisteel;
2018-02-26 17:54:54 +05:30
return TRUE;
}
else if (gMapHeader.cave == TRUE && !FlagGet(FLAG_SYS_USE_FLASH))
{
2018-06-16 00:45:48 +02:00
gFieldCallback2 = FieldCallback_PrepareFadeInFromMenu;
2019-10-22 17:28:05 -04:00
gPostMenuFieldCallback = FieldCallback_Flash;
2018-02-26 17:54:54 +05:30
return TRUE;
}
return FALSE;
}
2019-10-22 17:28:05 -04:00
static void FieldCallback_Flash(void)
2018-02-26 17:54:54 +05:30
{
u8 taskId = CreateFieldMoveTask();
2018-02-26 17:54:54 +05:30
gFieldEffectArguments[0] = GetCursorSelectionMonId();
2019-10-22 17:28:05 -04:00
gTasks[taskId].data[8] = (uintptr_t)FldEff_UseFlash >> 16;
gTasks[taskId].data[9] = (uintptr_t)FldEff_UseFlash;
2018-02-26 17:54:54 +05:30
}
2019-10-22 17:28:05 -04:00
static void FldEff_UseFlash(void)
2018-02-26 17:54:54 +05:30
{
2020-08-20 18:02:00 -04:00
PlaySE(SE_M_REFLECT);
2018-02-26 17:54:54 +05:30
FlagSet(FLAG_SYS_USE_FLASH);
ScriptContext_SetupScript(EventScript_UseFlash);
2018-02-26 17:54:54 +05:30
}
2019-09-10 13:40:28 -04:00
static void CB2_ChangeMapMain(void)
2018-02-26 17:54:54 +05:30
{
RunTasks();
AnimateSprites();
BuildOamBuffer();
UpdatePaletteFade();
}
2019-09-10 13:40:28 -04:00
static void VBC_ChangeMapVBlank(void)
2018-02-26 17:54:54 +05:30
{
LoadOam();
ProcessSpriteCopyRequests();
TransferPlttBuffer();
}
2019-09-10 13:40:28 -04:00
void CB2_DoChangeMap(void)
2018-02-26 17:54:54 +05:30
{
u16 ime;
SetVBlankCallback(NULL);
SetGpuReg(REG_OFFSET_DISPCNT, 0);
SetGpuReg(REG_OFFSET_BG2CNT, 0);
SetGpuReg(REG_OFFSET_BG1CNT, 0);
SetGpuReg(REG_OFFSET_BG0CNT, 0);
SetGpuReg(REG_OFFSET_BG2HOFS, 0);
SetGpuReg(REG_OFFSET_BG2VOFS, 0);
SetGpuReg(REG_OFFSET_BG1HOFS, 0);
SetGpuReg(REG_OFFSET_BG1VOFS, 0);
SetGpuReg(REG_OFFSET_BG0HOFS, 0);
SetGpuReg(REG_OFFSET_BG0VOFS, 0);
DmaFill16(3, 0, (void *)VRAM, VRAM_SIZE);
DmaFill32(3, 0, (void *)OAM, OAM_SIZE);
DmaFill16(3, 0, (void *)(PLTT + 2), PLTT_SIZE - 2);
ResetPaletteFade();
ResetTasks();
ResetSpriteData();
ime = REG_IME;
REG_IME = 0;
REG_IE |= INTR_FLAG_VBLANK;
REG_IME = ime;
2019-09-10 13:40:28 -04:00
SetVBlankCallback(VBC_ChangeMapVBlank);
SetMainCallback2(CB2_ChangeMapMain);
2019-09-29 16:33:13 -04:00
if (!TryDoMapTransition())
2018-02-26 17:54:54 +05:30
SetMainCallback2(gMain.savedCallback);
}
2019-09-29 16:33:13 -04:00
static bool8 TryDoMapTransition(void)
2018-02-26 17:54:54 +05:30
{
u8 i;
2019-09-10 13:40:28 -04:00
u8 fromType = GetLastUsedWarpMapType();
u8 toType = GetCurrentMapType();
2018-02-26 17:54:54 +05:30
2019-09-10 13:40:28 -04:00
for (i = 0; sTransitionTypes[i].fromType; i++)
2018-02-26 17:54:54 +05:30
{
2019-09-10 13:40:28 -04:00
if (sTransitionTypes[i].fromType == fromType && sTransitionTypes[i].toType == toType)
2018-02-26 17:54:54 +05:30
{
2019-09-10 13:40:28 -04:00
sTransitionTypes[i].func();
2018-02-26 17:54:54 +05:30
return TRUE;
}
}
return FALSE;
}
2019-09-10 13:40:28 -04:00
bool8 GetMapPairFadeToType(u8 _fromType, u8 _toType)
2018-02-26 17:54:54 +05:30
{
u8 i;
2019-09-10 13:40:28 -04:00
u8 fromType = _fromType;
u8 toType = _toType;
2018-02-26 17:54:54 +05:30
2019-09-10 13:40:28 -04:00
for (i = 0; sTransitionTypes[i].fromType; i++)
2018-02-26 17:54:54 +05:30
{
2019-09-10 13:40:28 -04:00
if (sTransitionTypes[i].fromType == fromType && sTransitionTypes[i].toType == toType)
2018-02-26 17:54:54 +05:30
{
2019-09-29 16:33:13 -04:00
return sTransitionTypes[i].isEnter;
2018-02-26 17:54:54 +05:30
}
}
return FALSE;
}
2019-09-10 13:40:28 -04:00
bool8 GetMapPairFadeFromType(u8 _fromType, u8 _toType)
2018-02-26 17:54:54 +05:30
{
u8 i;
2019-09-10 13:40:28 -04:00
u8 fromType = _fromType;
u8 toType = _toType;
2018-02-26 17:54:54 +05:30
2019-09-10 13:40:28 -04:00
for (i = 0; sTransitionTypes[i].fromType; i++)
2018-02-26 17:54:54 +05:30
{
2019-09-10 13:40:28 -04:00
if (sTransitionTypes[i].fromType == fromType && sTransitionTypes[i].toType == toType)
2018-02-26 17:54:54 +05:30
{
2019-09-29 16:33:13 -04:00
return sTransitionTypes[i].isExit;
2018-02-26 17:54:54 +05:30
}
}
return FALSE;
}
2019-09-10 13:40:28 -04:00
static void DoExitCaveTransition(void)
2018-02-26 17:54:54 +05:30
{
2019-09-10 13:40:28 -04:00
CreateTask(Task_ExitCaveTransition1, 0);
2018-02-26 17:54:54 +05:30
}
2019-09-10 13:40:28 -04:00
static void Task_ExitCaveTransition1(u8 taskId)
2018-02-26 17:54:54 +05:30
{
2019-09-10 13:40:28 -04:00
gTasks[taskId].func = Task_ExitCaveTransition2;
2018-02-26 17:54:54 +05:30
}
2019-09-10 13:40:28 -04:00
static void Task_ExitCaveTransition2(u8 taskId)
2018-02-26 17:54:54 +05:30
{
SetGpuReg(REG_OFFSET_DISPCNT, 0);
2021-03-21 01:22:42 -04:00
LZ77UnCompVram(sCaveTransitionTiles, (void *)(VRAM + 0xC000));
LZ77UnCompVram(sCaveTransitionTilemap, (void *)(VRAM + 0xF800));
2022-08-19 16:32:00 +01:00
LoadPalette(sCaveTransitionPalette_White, BG_PLTT_ID(14), PLTT_SIZE_4BPP);
LoadPalette(sCaveTransitionPalette_Exit, BG_PLTT_ID(14), PLTT_SIZEOF(8));
2018-02-26 17:54:54 +05:30
SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG0
| BLDCNT_EFFECT_BLEND
| BLDCNT_TGT2_BG1
| BLDCNT_TGT2_BG2
| BLDCNT_TGT2_BG3
| BLDCNT_TGT2_OBJ
| BLDCNT_TGT2_BD);
SetGpuReg(REG_OFFSET_BLDALPHA, 0);
SetGpuReg(REG_OFFSET_BLDY, 0);
SetGpuReg(REG_OFFSET_BG0CNT, BGCNT_PRIORITY(0)
| BGCNT_CHARBASE(3)
| BGCNT_SCREENBASE(31)
| BGCNT_16COLOR
| BGCNT_TXT256x256);
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0
| DISPCNT_OBJ_1D_MAP
| DISPCNT_BG0_ON
| DISPCNT_OBJ_ON);
2019-09-10 13:40:28 -04:00
gTasks[taskId].func = Task_ExitCaveTransition3;
2018-02-26 17:54:54 +05:30
gTasks[taskId].data[0] = 16;
gTasks[taskId].data[1] = 0;
}
2019-09-10 13:40:28 -04:00
static void Task_ExitCaveTransition3(u8 taskId)
2018-02-26 17:54:54 +05:30
{
u16 count = gTasks[taskId].data[1];
u16 blend = count + 0x1000;
SetGpuReg(REG_OFFSET_BLDALPHA, blend);
if (count <= 0x10)
{
gTasks[taskId].data[1]++;
}
else
{
gTasks[taskId].data[2] = 0;
2019-09-10 13:40:28 -04:00
gTasks[taskId].func = Task_ExitCaveTransition4;
2018-02-26 17:54:54 +05:30
}
}
2019-09-10 13:40:28 -04:00
static void Task_ExitCaveTransition4(u8 taskId)
2018-02-26 17:54:54 +05:30
{
u16 count;
2018-02-27 10:33:23 +05:30
SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(16, 16));
2018-02-26 17:54:54 +05:30
count = gTasks[taskId].data[2];
if (count < 8)
{
gTasks[taskId].data[2]++;
2023-05-23 13:16:18 -04:00
LoadPalette(&sCaveTransitionPalette_Exit[count], BG_PLTT_ID(14), sizeof(sCaveTransitionPalette_Exit) - PLTT_SIZEOF(count));
2018-02-26 17:54:54 +05:30
}
else
{
2022-08-19 16:32:00 +01:00
LoadPalette(sCaveTransitionPalette_White, BG_PLTT_ID(0), PLTT_SIZE_4BPP);
2019-09-10 13:40:28 -04:00
gTasks[taskId].func = Task_ExitCaveTransition5;
2018-02-26 17:54:54 +05:30
gTasks[taskId].data[2] = 8;
}
}
2019-09-10 13:40:28 -04:00
static void Task_ExitCaveTransition5(u8 taskId)
2018-02-26 17:54:54 +05:30
{
if (gTasks[taskId].data[2])
gTasks[taskId].data[2]--;
else
SetMainCallback2(gMain.savedCallback);
}
2019-09-10 13:40:28 -04:00
static void DoEnterCaveTransition(void)
2018-02-26 17:54:54 +05:30
{
2019-09-10 13:40:28 -04:00
CreateTask(Task_EnterCaveTransition1, 0);
2018-02-26 17:54:54 +05:30
}
2019-09-10 13:40:28 -04:00
static void Task_EnterCaveTransition1(u8 taskId)
2018-02-26 17:54:54 +05:30
{
2019-09-10 13:40:28 -04:00
gTasks[taskId].func = Task_EnterCaveTransition2;
2018-02-26 17:54:54 +05:30
}
2019-09-10 13:40:28 -04:00
static void Task_EnterCaveTransition2(u8 taskId)
2018-02-26 17:54:54 +05:30
{
SetGpuReg(REG_OFFSET_DISPCNT, 0);
2021-03-21 01:22:42 -04:00
LZ77UnCompVram(sCaveTransitionTiles, (void *)(VRAM + 0xC000));
LZ77UnCompVram(sCaveTransitionTilemap, (void *)(VRAM + 0xF800));
2018-02-26 17:54:54 +05:30
SetGpuReg(REG_OFFSET_BLDCNT, 0);
SetGpuReg(REG_OFFSET_BLDALPHA, 0);
SetGpuReg(REG_OFFSET_BLDY, 0);
SetGpuReg(REG_OFFSET_BG0CNT, BGCNT_PRIORITY(0)
| BGCNT_CHARBASE(3)
| BGCNT_SCREENBASE(31)
| BGCNT_16COLOR
| BGCNT_TXT256x256);
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0
| DISPCNT_OBJ_1D_MAP
| DISPCNT_BG0_ON
| DISPCNT_OBJ_ON);
2022-08-19 16:32:00 +01:00
LoadPalette(sCaveTransitionPalette_White, BG_PLTT_ID(14), PLTT_SIZE_4BPP);
LoadPalette(sCaveTransitionPalette_Black, BG_PLTT_ID(0), PLTT_SIZE_4BPP);
2019-09-10 13:40:28 -04:00
gTasks[taskId].func = Task_EnterCaveTransition3;
2018-02-26 17:54:54 +05:30
gTasks[taskId].data[0] = 16;
gTasks[taskId].data[1] = 0;
gTasks[taskId].data[2] = 0;
}
2019-09-10 13:40:28 -04:00
static void Task_EnterCaveTransition3(u8 taskId)
2018-02-26 17:54:54 +05:30
{
u16 count = gTasks[taskId].data[2];
if (count < 16)
{
gTasks[taskId].data[2]++;
gTasks[taskId].data[2]++;
2022-08-19 16:32:00 +01:00
LoadPalette(&sCaveTransitionPalette_Enter[15 - count], BG_PLTT_ID(14), PLTT_SIZEOF(count + 1));
2018-02-26 17:54:54 +05:30
}
else
{
SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(16, 16));
SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG0
| BLDCNT_EFFECT_BLEND
| BLDCNT_TGT2_BG1
| BLDCNT_TGT2_BG2
| BLDCNT_TGT2_BG3
| BLDCNT_TGT2_OBJ
| BLDCNT_TGT2_BD);
2019-09-10 13:40:28 -04:00
gTasks[taskId].func = Task_EnterCaveTransition4;
2018-02-26 17:54:54 +05:30
}
}
2019-09-10 13:40:28 -04:00
static void Task_EnterCaveTransition4(u8 taskId)
2018-02-26 17:54:54 +05:30
{
u16 count = 16 - gTasks[taskId].data[1];
u16 blend = count + 0x1000;
SetGpuReg(REG_OFFSET_BLDALPHA, blend);
if (count)
{
gTasks[taskId].data[1]++;
}
else
{
2022-08-19 16:32:00 +01:00
LoadPalette(sCaveTransitionPalette_Black, BG_PLTT_ID(0), PLTT_SIZE_4BPP);
2018-02-26 17:54:54 +05:30
SetMainCallback2(gMain.savedCallback);
}
}