sovereignx/src/fldeff_sweetscent.c

100 lines
2.8 KiB
C
Raw Normal View History

2018-02-14 11:54:31 +00:00
#include "global.h"
#include "event_data.h"
#include "event_scripts.h"
#include "field_effect.h"
#include "field_player_avatar.h"
2018-12-08 21:12:44 +00:00
#include "field_screen_effect.h"
2018-12-08 18:05:03 +00:00
#include "field_weather.h"
2018-12-24 20:59:05 +00:00
#include "fldeff.h"
#include "mirage_tower.h"
2018-02-14 11:54:31 +00:00
#include "palette.h"
#include "party_menu.h"
#include "script.h"
#include "sound.h"
#include "sprite.h"
#include "task.h"
#include "wild_encounter.h"
2018-11-13 14:19:04 +00:00
#include "constants/field_effects.h"
2018-10-17 13:52:26 +01:00
#include "constants/rgb.h"
#include "constants/songs.h"
2018-02-14 11:54:31 +00:00
2018-10-17 13:52:26 +01:00
static void FieldCallback_SweetScent(void);
static void TrySweetScentEncounter(u8 taskId);
static void FailSweetScentEncounter(u8 taskId);
2018-02-14 11:54:31 +00:00
bool8 SetUpFieldMove_SweetScent(void)
{
2018-06-15 23:45:48 +01:00
gFieldCallback2 = FieldCallback_PrepareFadeInFromMenu;
2018-10-17 13:52:26 +01:00
gPostMenuFieldCallback = FieldCallback_SweetScent;
2018-02-14 11:54:31 +00:00
return TRUE;
}
2018-10-17 13:52:26 +01:00
static void FieldCallback_SweetScent(void)
2018-02-14 11:54:31 +00:00
{
FieldEffectStart(FLDEFF_SWEET_SCENT);
gFieldEffectArguments[0] = GetCursorSelectionMonId();
}
bool8 FldEff_SweetScent(void)
2018-02-14 11:54:31 +00:00
{
u8 taskId;
2018-12-08 18:05:03 +00:00
SetWeatherScreenFadeOut();
taskId = CreateFieldMoveTask();
2018-10-17 13:52:26 +01:00
gTasks[taskId].data[8] = (u32)StartSweetScentFieldEffect >> 16;
gTasks[taskId].data[9] = (u32)StartSweetScentFieldEffect;
2018-02-14 11:54:31 +00:00
return FALSE;
}
void StartSweetScentFieldEffect(void)
2018-02-14 11:54:31 +00:00
{
u8 taskId;
u32 palettes = ~(1 << (gSprites[GetPlayerAvatarSpriteId()].oam.paletteNum + 16) | (1 << 13) | (1 << 14) | (1 << 15));
2018-02-14 11:54:31 +00:00
2020-08-20 23:02:00 +01:00
PlaySE(SE_M_SWEET_SCENT);
2023-05-23 18:16:18 +01:00
CpuFastCopy(gPlttBufferUnfaded, gPaletteDecompressionBuffer, PLTT_SIZE);
CpuFastCopy(gPlttBufferFaded, gPlttBufferUnfaded, PLTT_SIZE);
BeginNormalPaletteFade(palettes, 4, 0, 8, RGB_RED);
2018-10-17 13:52:26 +01:00
taskId = CreateTask(TrySweetScentEncounter, 0);
2018-02-14 11:54:31 +00:00
gTasks[taskId].data[0] = 0;
FieldEffectActiveListRemove(FLDEFF_SWEET_SCENT);
}
2018-10-17 13:52:26 +01:00
static void TrySweetScentEncounter(u8 taskId)
2018-02-14 11:54:31 +00:00
{
if (!gPaletteFade.active)
{
ClearMirageTowerPulseBlendEffect();
2018-02-15 04:17:42 +00:00
BlendPalettes(0x00000040, 8, RGB_RED);
2018-02-14 11:54:31 +00:00
if (gTasks[taskId].data[0] == 64)
{
gTasks[taskId].data[0] = 0;
if (SweetScentWildEncounter() == TRUE)
{
DestroyTask(taskId);
}
else
{
2018-10-17 13:52:26 +01:00
gTasks[taskId].func = FailSweetScentEncounter;
2021-04-06 10:05:33 +01:00
BeginNormalPaletteFade(~(1 << (gSprites[GetPlayerAvatarSpriteId()].oam.paletteNum + 16)), 4, 8, 0, RGB_RED);
TryStartMirageTowerPulseBlendEffect();
2018-02-14 11:54:31 +00:00
}
}
else
{
gTasks[taskId].data[0]++;
}
}
}
2018-10-17 13:52:26 +01:00
static void FailSweetScentEncounter(u8 taskId)
2018-02-14 11:54:31 +00:00
{
if (!gPaletteFade.active)
{
2023-05-23 18:16:18 +01:00
CpuFastCopy(gPaletteDecompressionBuffer, gPlttBufferUnfaded, PLTT_SIZE);
2021-04-04 22:52:07 +01:00
SetWeatherPalStateIdle();
ScriptContext_SetupScript(EventScript_FailSweetScent);
2018-02-14 11:54:31 +00:00
DestroyTask(taskId);
}
}