2017-10-05 19:02:39 +02:00
# include "global.h"
# include "event_data.h"
2018-09-11 03:17:21 +02:00
# include "field_camera.h"
# include "field_effect.h"
2017-10-05 19:02:39 +02:00
# include "script.h"
2018-09-11 03:17:21 +02:00
# include "sound.h"
2017-10-05 19:02:39 +02:00
# include "task.h"
2018-11-13 15:19:04 +01:00
# include "constants/field_effects.h"
2018-09-11 03:17:21 +02:00
# include "constants/songs.h"
2019-06-12 01:50:50 +02:00
# include "constants/metatile_labels.h"
2019-02-16 00:24:55 +01:00
# include "fieldmap.h"
# include "party_menu.h"
# include "fldeff.h"
2017-10-05 19:02:39 +02:00
2021-10-30 17:59:14 +02:00
EWRAM_DATA static bool8 sIsRegisteelPuzzle = 0 ;
2018-06-30 15:35:54 +02:00
2021-10-30 17:59:14 +02:00
static const u8 sRegicePathCoords [ ] [ 2 ] =
2018-09-11 03:17:21 +02:00
{
2019-04-01 04:07:29 +02:00
{ 4 , 21 } ,
{ 5 , 21 } ,
{ 6 , 21 } ,
{ 7 , 21 } ,
{ 8 , 21 } ,
{ 9 , 21 } ,
{ 10 , 21 } ,
{ 11 , 21 } ,
{ 12 , 21 } ,
{ 12 , 22 } ,
{ 12 , 23 } ,
{ 13 , 23 } ,
{ 13 , 24 } ,
{ 13 , 25 } ,
{ 13 , 26 } ,
{ 13 , 27 } ,
{ 12 , 27 } ,
{ 12 , 28 } ,
{ 4 , 29 } ,
{ 5 , 29 } ,
{ 6 , 29 } ,
{ 7 , 29 } ,
{ 8 , 29 } ,
{ 9 , 29 } ,
{ 10 , 29 } ,
{ 11 , 29 } ,
{ 12 , 29 } ,
{ 4 , 28 } ,
{ 4 , 27 } ,
{ 3 , 27 } ,
{ 3 , 26 } ,
{ 3 , 25 } ,
{ 3 , 24 } ,
{ 3 , 23 } ,
{ 4 , 23 } ,
{ 4 , 22 } ,
2018-09-11 03:17:21 +02:00
} ;
2017-10-05 19:02:39 +02:00
2021-10-30 17:59:14 +02:00
static void Task_SealedChamberShakingEffect ( u8 ) ;
static void DoBrailleRegirockEffect ( void ) ;
static void DoBrailleRegisteelEffect ( void ) ;
2017-10-05 19:02:39 +02:00
bool8 ShouldDoBrailleDigEffect ( void )
{
2017-11-08 22:20:10 +01:00
if ( ! FlagGet ( FLAG_SYS_BRAILLE_DIG )
2019-02-18 08:02:20 +01:00
& & ( gSaveBlock1Ptr - > location . mapGroup = = MAP_GROUP ( SEALED_CHAMBER_OUTER_ROOM )
& & gSaveBlock1Ptr - > location . mapNum = = MAP_NUM ( SEALED_CHAMBER_OUTER_ROOM ) ) )
2017-10-05 19:02:39 +02:00
{
if ( gSaveBlock1Ptr - > pos . x = = 10 & & gSaveBlock1Ptr - > pos . y = = 3 )
return TRUE ;
if ( gSaveBlock1Ptr - > pos . x = = 9 & & gSaveBlock1Ptr - > pos . y = = 3 )
return TRUE ;
if ( gSaveBlock1Ptr - > pos . x = = 11 & & gSaveBlock1Ptr - > pos . y = = 3 )
return TRUE ;
}
return FALSE ;
}
void DoBrailleDigEffect ( void )
{
2021-10-09 18:12:18 +02:00
MapGridSetMetatileIdAt ( 9 + MAP_OFFSET , 1 + MAP_OFFSET , METATILE_Cave_SealedChamberEntrance_TopLeft ) ;
MapGridSetMetatileIdAt ( 10 + MAP_OFFSET , 1 + MAP_OFFSET , METATILE_Cave_SealedChamberEntrance_TopMid ) ;
MapGridSetMetatileIdAt ( 11 + MAP_OFFSET , 1 + MAP_OFFSET , METATILE_Cave_SealedChamberEntrance_TopRight ) ;
2022-01-19 16:15:32 +01:00
MapGridSetMetatileIdAt ( 9 + MAP_OFFSET , 2 + MAP_OFFSET , METATILE_Cave_SealedChamberEntrance_BottomLeft | MAPGRID_COLLISION_MASK ) ;
2021-10-09 18:12:18 +02:00
MapGridSetMetatileIdAt ( 10 + MAP_OFFSET , 2 + MAP_OFFSET , METATILE_Cave_SealedChamberEntrance_BottomMid ) ;
2022-01-19 16:15:32 +01:00
MapGridSetMetatileIdAt ( 11 + MAP_OFFSET , 2 + MAP_OFFSET , METATILE_Cave_SealedChamberEntrance_BottomRight | MAPGRID_COLLISION_MASK ) ;
2017-10-05 19:02:39 +02:00
DrawWholeMapView ( ) ;
2020-08-21 00:02:00 +02:00
PlaySE ( SE_BANG ) ;
2017-11-08 22:20:10 +01:00
FlagSet ( FLAG_SYS_BRAILLE_DIG ) ;
2022-08-15 21:18:12 +02:00
UnlockPlayerFieldControls ( ) ;
2017-10-05 19:02:39 +02:00
}
bool8 CheckRelicanthWailord ( void )
{
// Emerald change: why did they flip it?
// First comes Wailord
2023-02-24 11:53:02 +01:00
if ( GetMonData ( & gPlayerParty [ 0 ] , MON_DATA_SPECIES_OR_EGG , 0 ) = = SPECIES_WAILORD )
2017-10-05 19:02:39 +02:00
{
CalculatePlayerPartyCount ( ) ;
// Last comes Relicanth
2023-02-24 11:53:02 +01:00
if ( GetMonData ( & gPlayerParty [ gPlayerPartyCount - 1 ] , MON_DATA_SPECIES_OR_EGG , 0 ) = = SPECIES_RELICANTH )
2017-10-05 19:02:39 +02:00
return TRUE ;
}
return FALSE ;
}
// THEORY: this was caused by block commenting out all of the older R/S braille functions but leaving the call to it itself, which creates the nullsub.
2019-02-16 00:24:55 +01:00
void ShouldDoBrailleRegirockEffectOld ( void )
2017-10-05 19:02:39 +02:00
{
}
2021-10-30 17:59:14 +02:00
# define tDelayCounter data[1]
# define tShakeCounter data[2]
# define tVerticalPan data[4]
# define tDelay data[5]
# define tNumShakes data[6]
void DoSealedChamberShakingEffect_Long ( void )
2017-10-05 19:02:39 +02:00
{
2021-10-30 17:59:14 +02:00
u8 taskId = CreateTask ( Task_SealedChamberShakingEffect , 9 ) ;
2017-10-05 19:02:39 +02:00
2021-10-30 17:59:14 +02:00
gTasks [ taskId ] . tDelayCounter = 0 ;
gTasks [ taskId ] . tShakeCounter = 0 ;
gTasks [ taskId ] . tVerticalPan = 2 ;
gTasks [ taskId ] . tDelay = 5 ;
gTasks [ taskId ] . tNumShakes = 50 ;
2017-10-05 19:02:39 +02:00
SetCameraPanningCallback ( 0 ) ;
}
2021-10-30 17:59:14 +02:00
void DoSealedChamberShakingEffect_Short ( void )
2017-10-05 19:02:39 +02:00
{
2021-10-30 17:59:14 +02:00
u8 taskId = CreateTask ( Task_SealedChamberShakingEffect , 9 ) ;
2017-10-05 19:02:39 +02:00
2021-10-30 17:59:14 +02:00
gTasks [ taskId ] . tDelayCounter = 0 ;
gTasks [ taskId ] . tShakeCounter = 0 ;
gTasks [ taskId ] . tVerticalPan = 3 ;
gTasks [ taskId ] . tDelay = 5 ;
gTasks [ taskId ] . tNumShakes = 2 ;
2017-10-05 19:02:39 +02:00
SetCameraPanningCallback ( 0 ) ;
}
2021-10-30 17:59:14 +02:00
static void Task_SealedChamberShakingEffect ( u8 taskId )
2017-10-05 19:02:39 +02:00
{
struct Task * task = & gTasks [ taskId ] ;
2021-10-30 17:59:14 +02:00
task - > tDelayCounter + + ;
if ( task - > tDelayCounter % task - > tDelay = = 0 )
2017-10-05 19:02:39 +02:00
{
2021-10-30 17:59:14 +02:00
task - > tDelayCounter = 0 ;
task - > tShakeCounter + + ;
task - > tVerticalPan = - task - > tVerticalPan ;
SetCameraPanning ( 0 , task - > tVerticalPan ) ;
if ( task - > tShakeCounter = = task - > tNumShakes )
2017-10-05 19:02:39 +02:00
{
DestroyTask ( taskId ) ;
2022-08-15 21:18:12 +02:00
ScriptContext_Enable ( ) ;
2017-10-05 19:02:39 +02:00
InstallCameraPanAheadCallback ( ) ;
}
}
}
2021-10-30 17:59:14 +02:00
# undef tDelayCounter
# undef tShakeCounter
# undef tVerticalPan
# undef tDelay
# undef tNumShakes
2019-02-16 00:24:55 +01:00
bool8 ShouldDoBrailleRegirockEffect ( void )
2017-10-05 19:02:39 +02:00
{
2019-02-18 20:17:02 +01:00
if ( ! FlagGet ( FLAG_SYS_REGIROCK_PUZZLE_COMPLETED )
2018-07-16 20:47:30 +02:00
& & gSaveBlock1Ptr - > location . mapGroup = = MAP_GROUP ( DESERT_RUINS )
& & gSaveBlock1Ptr - > location . mapNum = = MAP_NUM ( DESERT_RUINS ) )
2017-10-05 19:02:39 +02:00
{
if ( gSaveBlock1Ptr - > pos . x = = 6 & & gSaveBlock1Ptr - > pos . y = = 23 )
2018-07-16 20:47:30 +02:00
{
2021-10-30 17:59:14 +02:00
sIsRegisteelPuzzle = FALSE ;
2018-07-16 20:47:30 +02:00
return TRUE ;
}
2017-10-05 19:02:39 +02:00
else if ( gSaveBlock1Ptr - > pos . x = = 5 & & gSaveBlock1Ptr - > pos . y = = 23 )
2018-07-16 20:47:30 +02:00
{
2021-10-30 17:59:14 +02:00
sIsRegisteelPuzzle = FALSE ;
2018-07-16 20:47:30 +02:00
return TRUE ;
}
2017-10-05 19:02:39 +02:00
else if ( gSaveBlock1Ptr - > pos . x = = 7 & & gSaveBlock1Ptr - > pos . y = = 23 )
2018-07-16 20:47:30 +02:00
{
2021-10-30 17:59:14 +02:00
sIsRegisteelPuzzle = FALSE ;
2018-07-16 20:47:30 +02:00
return TRUE ;
}
2017-10-05 19:02:39 +02:00
}
return FALSE ;
}
2019-02-16 00:24:55 +01:00
void SetUpPuzzleEffectRegirock ( void )
2017-10-05 19:02:39 +02:00
{
2017-11-14 20:23:25 +01:00
gFieldEffectArguments [ 0 ] = GetCursorSelectionMonId ( ) ;
2019-02-16 00:24:55 +01:00
FieldEffectStart ( FLDEFF_USE_TOMB_PUZZLE_EFFECT ) ;
2017-10-05 19:02:39 +02:00
}
2019-02-16 00:24:55 +01:00
void UseRegirockHm_Callback ( void )
2017-10-05 19:02:39 +02:00
{
2019-02-16 00:24:55 +01:00
FieldEffectActiveListRemove ( FLDEFF_USE_TOMB_PUZZLE_EFFECT ) ;
DoBrailleRegirockEffect ( ) ;
2017-10-05 19:02:39 +02:00
}
2021-10-30 17:59:14 +02:00
static void DoBrailleRegirockEffect ( void )
2017-10-05 19:02:39 +02:00
{
2021-10-09 18:12:18 +02:00
MapGridSetMetatileIdAt ( 7 + MAP_OFFSET , 19 + MAP_OFFSET , METATILE_Cave_SealedChamberEntrance_TopLeft ) ;
MapGridSetMetatileIdAt ( 8 + MAP_OFFSET , 19 + MAP_OFFSET , METATILE_Cave_SealedChamberEntrance_TopMid ) ;
MapGridSetMetatileIdAt ( 9 + MAP_OFFSET , 19 + MAP_OFFSET , METATILE_Cave_SealedChamberEntrance_TopRight ) ;
2022-01-19 16:15:32 +01:00
MapGridSetMetatileIdAt ( 7 + MAP_OFFSET , 20 + MAP_OFFSET , METATILE_Cave_SealedChamberEntrance_BottomLeft | MAPGRID_COLLISION_MASK ) ;
2021-10-09 18:12:18 +02:00
MapGridSetMetatileIdAt ( 8 + MAP_OFFSET , 20 + MAP_OFFSET , METATILE_Cave_SealedChamberEntrance_BottomMid ) ;
2022-01-19 16:15:32 +01:00
MapGridSetMetatileIdAt ( 9 + MAP_OFFSET , 20 + MAP_OFFSET , METATILE_Cave_SealedChamberEntrance_BottomRight | MAPGRID_COLLISION_MASK ) ;
2017-10-05 19:02:39 +02:00
DrawWholeMapView ( ) ;
2020-08-21 00:02:00 +02:00
PlaySE ( SE_BANG ) ;
2019-02-18 20:17:02 +01:00
FlagSet ( FLAG_SYS_REGIROCK_PUZZLE_COMPLETED ) ;
2022-08-15 21:18:12 +02:00
UnlockPlayerFieldControls ( ) ;
2017-10-05 19:02:39 +02:00
}
2019-02-16 00:24:55 +01:00
bool8 ShouldDoBrailleRegisteelEffect ( void )
2017-10-05 19:02:39 +02:00
{
2019-02-18 08:02:20 +01:00
if ( ! FlagGet ( FLAG_SYS_REGISTEEL_PUZZLE_COMPLETED ) & & ( gSaveBlock1Ptr - > location . mapGroup = = MAP_GROUP ( ANCIENT_TOMB ) & & gSaveBlock1Ptr - > location . mapNum = = MAP_NUM ( ANCIENT_TOMB ) ) )
2017-10-05 19:02:39 +02:00
{
2017-10-05 19:05:25 +02:00
if ( gSaveBlock1Ptr - > pos . x = = 8 & & gSaveBlock1Ptr - > pos . y = = 25 )
2019-02-16 00:24:55 +01:00
{
2021-10-30 17:59:14 +02:00
sIsRegisteelPuzzle = TRUE ;
2019-02-16 00:24:55 +01:00
return TRUE ;
}
2017-10-05 19:02:39 +02:00
}
return FALSE ;
}
2019-02-16 00:24:55 +01:00
void SetUpPuzzleEffectRegisteel ( void )
2017-10-05 19:02:39 +02:00
{
2017-11-14 20:23:25 +01:00
gFieldEffectArguments [ 0 ] = GetCursorSelectionMonId ( ) ;
2019-02-16 00:24:55 +01:00
FieldEffectStart ( FLDEFF_USE_TOMB_PUZZLE_EFFECT ) ;
2017-10-05 19:02:39 +02:00
}
2019-02-16 00:24:55 +01:00
void UseRegisteelHm_Callback ( void )
2017-10-05 19:02:39 +02:00
{
2019-02-16 00:24:55 +01:00
FieldEffectActiveListRemove ( FLDEFF_USE_TOMB_PUZZLE_EFFECT ) ;
DoBrailleRegisteelEffect ( ) ;
2017-10-05 19:02:39 +02:00
}
2021-10-30 17:59:14 +02:00
static void DoBrailleRegisteelEffect ( void )
2017-10-05 19:02:39 +02:00
{
2021-10-09 18:12:18 +02:00
MapGridSetMetatileIdAt ( 7 + MAP_OFFSET , 19 + MAP_OFFSET , METATILE_Cave_SealedChamberEntrance_TopLeft ) ;
MapGridSetMetatileIdAt ( 8 + MAP_OFFSET , 19 + MAP_OFFSET , METATILE_Cave_SealedChamberEntrance_TopMid ) ;
MapGridSetMetatileIdAt ( 9 + MAP_OFFSET , 19 + MAP_OFFSET , METATILE_Cave_SealedChamberEntrance_TopRight ) ;
2022-01-19 16:15:32 +01:00
MapGridSetMetatileIdAt ( 7 + MAP_OFFSET , 20 + MAP_OFFSET , METATILE_Cave_SealedChamberEntrance_BottomLeft | MAPGRID_COLLISION_MASK ) ;
2021-10-09 18:12:18 +02:00
MapGridSetMetatileIdAt ( 8 + MAP_OFFSET , 20 + MAP_OFFSET , METATILE_Cave_SealedChamberEntrance_BottomMid ) ;
2022-01-19 16:15:32 +01:00
MapGridSetMetatileIdAt ( 9 + MAP_OFFSET , 20 + MAP_OFFSET , METATILE_Cave_SealedChamberEntrance_BottomRight | MAPGRID_COLLISION_MASK ) ;
2017-10-05 19:02:39 +02:00
DrawWholeMapView ( ) ;
2020-08-21 00:02:00 +02:00
PlaySE ( SE_BANG ) ;
2019-02-18 08:02:20 +01:00
FlagSet ( FLAG_SYS_REGISTEEL_PUZZLE_COMPLETED ) ;
2022-08-15 21:18:12 +02:00
UnlockPlayerFieldControls ( ) ;
2017-10-05 19:02:39 +02:00
}
// theory: another commented out DoBrailleWait and Task_BrailleWait.
2021-10-30 17:59:14 +02:00
static void DoBrailleWait ( void )
2017-10-05 19:02:39 +02:00
{
}
// this used to be FldEff_UseFlyAncientTomb . why did GF merge the 2 functions?
bool8 FldEff_UsePuzzleEffect ( void )
{
2020-06-20 01:58:56 +02:00
u8 taskId = CreateFieldMoveTask ( ) ;
2017-10-05 19:02:39 +02:00
2021-10-30 17:59:14 +02:00
if ( sIsRegisteelPuzzle = = TRUE )
2017-10-05 19:02:39 +02:00
{
2019-02-16 00:24:55 +01:00
gTasks [ taskId ] . data [ 8 ] = ( u32 ) UseRegisteelHm_Callback > > 16 ;
gTasks [ taskId ] . data [ 9 ] = ( u32 ) UseRegisteelHm_Callback ;
2017-10-05 19:02:39 +02:00
}
else
{
2019-02-16 00:24:55 +01:00
gTasks [ taskId ] . data [ 8 ] = ( u32 ) UseRegirockHm_Callback > > 16 ;
gTasks [ taskId ] . data [ 9 ] = ( u32 ) UseRegirockHm_Callback ;
2017-10-05 19:02:39 +02:00
}
return FALSE ;
}
bool8 ShouldDoBrailleRegicePuzzle ( void )
{
u8 i ;
2019-02-18 08:02:20 +01:00
if ( gSaveBlock1Ptr - > location . mapGroup = = MAP_GROUP ( ISLAND_CAVE )
& & gSaveBlock1Ptr - > location . mapNum = = MAP_NUM ( ISLAND_CAVE ) )
2017-10-05 19:02:39 +02:00
{
2019-02-18 20:17:02 +01:00
if ( FlagGet ( FLAG_SYS_BRAILLE_REGICE_COMPLETED ) )
2017-10-05 19:02:39 +02:00
return FALSE ;
2018-10-17 18:25:12 +02:00
if ( FlagGet ( FLAG_TEMP_2 ) = = FALSE )
2017-10-05 19:02:39 +02:00
return FALSE ;
2018-10-17 18:25:12 +02:00
if ( FlagGet ( FLAG_TEMP_3 ) = = TRUE )
2017-10-05 19:02:39 +02:00
return FALSE ;
2021-10-30 17:59:14 +02:00
for ( i = 0 ; i < ARRAY_COUNT ( sRegicePathCoords ) ; i + + )
2017-10-05 19:02:39 +02:00
{
2021-10-30 17:59:14 +02:00
u8 xPos = sRegicePathCoords [ i ] [ 0 ] ;
u8 yPos = sRegicePathCoords [ i ] [ 1 ] ;
2018-02-18 19:12:09 +01:00
if ( gSaveBlock1Ptr - > pos . x = = xPos & & gSaveBlock1Ptr - > pos . y = = yPos )
2017-10-05 19:02:39 +02:00
{
2018-02-18 19:12:09 +01:00
u16 varValue ;
2017-10-05 19:05:25 +02:00
if ( i < 16 )
2018-02-18 19:12:09 +01:00
{
2019-02-16 00:24:55 +01:00
u16 val = VarGet ( VAR_REGICE_STEPS_1 ) ;
2018-02-18 19:12:09 +01:00
val | = 1 < < i ;
2019-02-16 00:24:55 +01:00
VarSet ( VAR_REGICE_STEPS_1 , val ) ;
2018-02-18 19:12:09 +01:00
}
2017-10-05 19:05:25 +02:00
else if ( i < 32 )
2018-02-18 19:12:09 +01:00
{
2019-02-16 00:24:55 +01:00
u16 val = VarGet ( VAR_REGICE_STEPS_2 ) ;
2018-02-18 19:12:09 +01:00
val | = 1 < < ( i - 16 ) ;
2019-02-16 00:24:55 +01:00
VarSet ( VAR_REGICE_STEPS_2 , val ) ;
2018-02-18 19:12:09 +01:00
}
2017-10-05 19:02:39 +02:00
else
2018-02-18 19:12:09 +01:00
{
2019-02-16 00:24:55 +01:00
u16 val = VarGet ( VAR_REGICE_STEPS_3 ) ;
2018-02-18 19:12:09 +01:00
val | = 1 < < ( i - 32 ) ;
2019-02-16 00:24:55 +01:00
VarSet ( VAR_REGICE_STEPS_3 , val ) ;
2018-02-18 19:12:09 +01:00
}
2019-02-16 00:24:55 +01:00
varValue = VarGet ( VAR_REGICE_STEPS_1 ) ;
2019-02-18 08:02:20 +01:00
if ( varValue ! = 0xFFFF | | VarGet ( VAR_REGICE_STEPS_2 ) ! = 0xFFFF | | VarGet ( VAR_REGICE_STEPS_3 ) ! = 0xF )
2017-10-05 19:02:39 +02:00
return FALSE ;
2019-02-16 00:24:55 +01:00
// This final check is redundant.
2017-10-05 19:05:25 +02:00
if ( gSaveBlock1Ptr - > pos . x = = 8 & & gSaveBlock1Ptr - > pos . y = = 21 )
2017-10-05 19:02:39 +02:00
return TRUE ;
else
return FALSE ;
}
}
2018-02-18 19:12:09 +01:00
2018-10-17 18:25:12 +02:00
FlagSet ( FLAG_TEMP_3 ) ;
FlagClear ( FLAG_TEMP_2 ) ;
2017-10-05 19:02:39 +02:00
}
2018-02-18 19:12:09 +01:00
2017-10-05 19:02:39 +02:00
return FALSE ;
}