2017-10-24 15:25:20 +02:00
# include "global.h"
# include "battle.h"
2020-12-20 22:47:20 +01:00
# include "battle_ai_main.h"
2018-11-14 01:01:50 +01:00
# include "battle_anim.h"
2017-10-24 15:25:20 +02:00
# include "battle_controllers.h"
# include "battle_interface.h"
2018-11-14 01:01:50 +01:00
# include "battle_message.h"
# include "battle_setup.h"
2018-12-24 00:02:29 +01:00
# include "battle_tower.h"
2018-02-27 20:40:09 +01:00
# include "battle_tv.h"
2018-11-14 01:01:50 +01:00
# include "bg.h"
2019-04-04 23:53:06 +02:00
# include "data.h"
2017-10-24 15:25:20 +02:00
# include "link.h"
# include "main.h"
# include "m4a.h"
# include "palette.h"
2018-11-14 01:01:50 +01:00
# include "pokeball.h"
# include "pokemon.h"
2019-03-05 20:07:59 +01:00
# include "recorded_battle.h"
2018-11-14 01:01:50 +01:00
# include "reshow_battle_screen.h"
# include "sound.h"
# include "string_util.h"
2017-10-24 15:25:20 +02:00
# include "task.h"
# include "text.h"
2018-11-14 01:01:50 +01:00
# include "util.h"
# include "window.h"
# include "constants/battle_anim.h"
# include "constants/songs.h"
# include "constants/trainers.h"
2019-03-02 04:32:50 +01:00
# include "recorded_battle.h"
2017-10-24 15:25:20 +02:00
static void LinkOpponentHandleGetMonData ( void ) ;
static void LinkOpponentHandleGetRawMonData ( void ) ;
static void LinkOpponentHandleSetMonData ( void ) ;
static void LinkOpponentHandleSetRawMonData ( void ) ;
static void LinkOpponentHandleLoadMonSprite ( void ) ;
static void LinkOpponentHandleSwitchInAnim ( void ) ;
static void LinkOpponentHandleReturnMonToBall ( void ) ;
static void LinkOpponentHandleDrawTrainerPic ( void ) ;
static void LinkOpponentHandleTrainerSlide ( void ) ;
static void LinkOpponentHandleTrainerSlideBack ( void ) ;
static void LinkOpponentHandleFaintAnimation ( void ) ;
static void LinkOpponentHandlePaletteFade ( void ) ;
static void LinkOpponentHandleSuccessBallThrowAnim ( void ) ;
static void LinkOpponentHandleBallThrowAnim ( void ) ;
static void LinkOpponentHandlePause ( void ) ;
static void LinkOpponentHandleMoveAnimation ( void ) ;
static void LinkOpponentHandlePrintString ( void ) ;
2017-11-25 18:42:31 +01:00
static void LinkOpponentHandlePrintSelectionString ( void ) ;
2017-10-24 15:25:20 +02:00
static void LinkOpponentHandleChooseAction ( void ) ;
2021-01-22 08:48:22 +01:00
static void LinkOpponentHandleYesNoBox ( void ) ;
2017-10-24 15:25:20 +02:00
static void LinkOpponentHandleChooseMove ( void ) ;
static void LinkOpponentHandleChooseItem ( void ) ;
static void LinkOpponentHandleChoosePokemon ( void ) ;
static void LinkOpponentHandleCmd23 ( void ) ;
static void LinkOpponentHandleHealthBarUpdate ( void ) ;
static void LinkOpponentHandleExpUpdate ( void ) ;
static void LinkOpponentHandleStatusIconUpdate ( void ) ;
static void LinkOpponentHandleStatusAnimation ( void ) ;
static void LinkOpponentHandleStatusXor ( void ) ;
static void LinkOpponentHandleDataTransfer ( void ) ;
static void LinkOpponentHandleDMA3Transfer ( void ) ;
static void LinkOpponentHandlePlayBGM ( void ) ;
static void LinkOpponentHandleCmd32 ( void ) ;
static void LinkOpponentHandleTwoReturnValues ( void ) ;
static void LinkOpponentHandleChosenMonReturnValue ( void ) ;
static void LinkOpponentHandleOneReturnValue ( void ) ;
static void LinkOpponentHandleOneReturnValue_Duplicate ( void ) ;
2020-12-29 22:51:44 +01:00
static void LinkOpponentHandleClearUnkVar ( void ) ;
static void LinkOpponentHandleSetUnkVar ( void ) ;
static void LinkOpponentHandleClearUnkFlag ( void ) ;
static void LinkOpponentHandleToggleUnkFlag ( void ) ;
2017-10-24 15:25:20 +02:00
static void LinkOpponentHandleHitAnimation ( void ) ;
2021-04-03 18:38:07 +02:00
static void LinkOpponentHandleCantSwitch ( void ) ;
2017-11-25 18:42:31 +01:00
static void LinkOpponentHandlePlaySE ( void ) ;
2017-10-24 15:25:20 +02:00
static void LinkOpponentHandlePlayFanfareOrBGM ( void ) ;
static void LinkOpponentHandleFaintingCry ( void ) ;
static void LinkOpponentHandleIntroSlide ( void ) ;
static void LinkOpponentHandleIntroTrainerBallThrow ( void ) ;
static void LinkOpponentHandleDrawPartyStatusSummary ( void ) ;
2018-06-28 21:06:32 +02:00
static void LinkOpponentHandleHidePartyStatusSummary ( void ) ;
2018-06-20 23:07:51 +02:00
static void LinkOpponentHandleEndBounceEffect ( void ) ;
2017-10-24 15:25:20 +02:00
static void LinkOpponentHandleSpriteInvisibility ( void ) ;
static void LinkOpponentHandleBattleAnimation ( void ) ;
static void LinkOpponentHandleLinkStandbyMsg ( void ) ;
static void LinkOpponentHandleResetActionMoveSelection ( void ) ;
2021-01-22 08:48:22 +01:00
static void LinkOpponentHandleEndLinkBattle ( void ) ;
2018-09-18 21:51:10 +02:00
static void LinkOpponentHandleBattleDebug ( void ) ;
2019-03-05 20:07:59 +01:00
static void LinkOpponentCmdEnd ( void ) ;
2017-10-24 15:25:20 +02:00
static void LinkOpponentBufferRunCommand ( void ) ;
static void LinkOpponentBufferExecCompleted ( void ) ;
2021-01-23 03:47:00 +01:00
static void SwitchIn_HandleSoundAndEnd ( void ) ;
2017-10-24 15:25:20 +02:00
static u32 CopyLinkOpponentMonData ( u8 monId , u8 * dst ) ;
static void SetLinkOpponentMonData ( u8 monId ) ;
2021-01-23 03:47:00 +01:00
static void StartSendOutAnim ( u8 battlerId , bool8 dontClearSubstituteBit ) ;
2017-10-24 15:25:20 +02:00
static void DoSwitchOutAnimation ( void ) ;
static void LinkOpponentDoMoveAnimation ( void ) ;
2021-01-23 03:47:00 +01:00
static void Task_StartSendOutAnim ( u8 taskId ) ;
static void SpriteCB_FreeOpponentSprite ( struct Sprite * sprite ) ;
2021-01-23 02:03:21 +01:00
static void EndDrawPartyStatusSummary ( void ) ;
2017-10-24 15:25:20 +02:00
2017-10-31 18:04:08 +01:00
static void ( * const sLinkOpponentBufferCommands [ CONTROLLER_CMDS_COUNT ] ) ( void ) =
2017-10-24 15:25:20 +02:00
{
2020-12-29 22:51:44 +01:00
[ CONTROLLER_GETMONDATA ] = LinkOpponentHandleGetMonData ,
[ CONTROLLER_GETRAWMONDATA ] = LinkOpponentHandleGetRawMonData ,
[ CONTROLLER_SETMONDATA ] = LinkOpponentHandleSetMonData ,
[ CONTROLLER_SETRAWMONDATA ] = LinkOpponentHandleSetRawMonData ,
[ CONTROLLER_LOADMONSPRITE ] = LinkOpponentHandleLoadMonSprite ,
[ CONTROLLER_SWITCHINANIM ] = LinkOpponentHandleSwitchInAnim ,
[ CONTROLLER_RETURNMONTOBALL ] = LinkOpponentHandleReturnMonToBall ,
[ CONTROLLER_DRAWTRAINERPIC ] = LinkOpponentHandleDrawTrainerPic ,
[ CONTROLLER_TRAINERSLIDE ] = LinkOpponentHandleTrainerSlide ,
[ CONTROLLER_TRAINERSLIDEBACK ] = LinkOpponentHandleTrainerSlideBack ,
[ CONTROLLER_FAINTANIMATION ] = LinkOpponentHandleFaintAnimation ,
[ CONTROLLER_PALETTEFADE ] = LinkOpponentHandlePaletteFade ,
[ CONTROLLER_SUCCESSBALLTHROWANIM ] = LinkOpponentHandleSuccessBallThrowAnim ,
[ CONTROLLER_BALLTHROWANIM ] = LinkOpponentHandleBallThrowAnim ,
[ CONTROLLER_PAUSE ] = LinkOpponentHandlePause ,
[ CONTROLLER_MOVEANIMATION ] = LinkOpponentHandleMoveAnimation ,
[ CONTROLLER_PRINTSTRING ] = LinkOpponentHandlePrintString ,
[ CONTROLLER_PRINTSTRINGPLAYERONLY ] = LinkOpponentHandlePrintSelectionString ,
[ CONTROLLER_CHOOSEACTION ] = LinkOpponentHandleChooseAction ,
2021-01-22 08:48:22 +01:00
[ CONTROLLER_YESNOBOX ] = LinkOpponentHandleYesNoBox ,
2020-12-29 22:51:44 +01:00
[ CONTROLLER_CHOOSEMOVE ] = LinkOpponentHandleChooseMove ,
[ CONTROLLER_OPENBAG ] = LinkOpponentHandleChooseItem ,
[ CONTROLLER_CHOOSEPOKEMON ] = LinkOpponentHandleChoosePokemon ,
[ CONTROLLER_23 ] = LinkOpponentHandleCmd23 ,
[ CONTROLLER_HEALTHBARUPDATE ] = LinkOpponentHandleHealthBarUpdate ,
[ CONTROLLER_EXPUPDATE ] = LinkOpponentHandleExpUpdate ,
[ CONTROLLER_STATUSICONUPDATE ] = LinkOpponentHandleStatusIconUpdate ,
[ CONTROLLER_STATUSANIMATION ] = LinkOpponentHandleStatusAnimation ,
[ CONTROLLER_STATUSXOR ] = LinkOpponentHandleStatusXor ,
[ CONTROLLER_DATATRANSFER ] = LinkOpponentHandleDataTransfer ,
[ CONTROLLER_DMA3TRANSFER ] = LinkOpponentHandleDMA3Transfer ,
[ CONTROLLER_PLAYBGM ] = LinkOpponentHandlePlayBGM ,
[ CONTROLLER_32 ] = LinkOpponentHandleCmd32 ,
[ CONTROLLER_TWORETURNVALUES ] = LinkOpponentHandleTwoReturnValues ,
[ CONTROLLER_CHOSENMONRETURNVALUE ] = LinkOpponentHandleChosenMonReturnValue ,
[ CONTROLLER_ONERETURNVALUE ] = LinkOpponentHandleOneReturnValue ,
[ CONTROLLER_ONERETURNVALUE_DUPLICATE ] = LinkOpponentHandleOneReturnValue_Duplicate ,
[ CONTROLLER_CLEARUNKVAR ] = LinkOpponentHandleClearUnkVar ,
[ CONTROLLER_SETUNKVAR ] = LinkOpponentHandleSetUnkVar ,
[ CONTROLLER_CLEARUNKFLAG ] = LinkOpponentHandleClearUnkFlag ,
[ CONTROLLER_TOGGLEUNKFLAG ] = LinkOpponentHandleToggleUnkFlag ,
[ CONTROLLER_HITANIMATION ] = LinkOpponentHandleHitAnimation ,
2021-04-03 18:38:07 +02:00
[ CONTROLLER_CANTSWITCH ] = LinkOpponentHandleCantSwitch ,
2020-12-29 22:51:44 +01:00
[ CONTROLLER_PLAYSE ] = LinkOpponentHandlePlaySE ,
[ CONTROLLER_PLAYFANFAREORBGM ] = LinkOpponentHandlePlayFanfareOrBGM ,
[ CONTROLLER_FAINTINGCRY ] = LinkOpponentHandleFaintingCry ,
[ CONTROLLER_INTROSLIDE ] = LinkOpponentHandleIntroSlide ,
[ CONTROLLER_INTROTRAINERBALLTHROW ] = LinkOpponentHandleIntroTrainerBallThrow ,
[ CONTROLLER_DRAWPARTYSTATUSSUMMARY ] = LinkOpponentHandleDrawPartyStatusSummary ,
[ CONTROLLER_HIDEPARTYSTATUSSUMMARY ] = LinkOpponentHandleHidePartyStatusSummary ,
[ CONTROLLER_ENDBOUNCE ] = LinkOpponentHandleEndBounceEffect ,
[ CONTROLLER_SPRITEINVISIBILITY ] = LinkOpponentHandleSpriteInvisibility ,
[ CONTROLLER_BATTLEANIMATION ] = LinkOpponentHandleBattleAnimation ,
[ CONTROLLER_LINKSTANDBYMSG ] = LinkOpponentHandleLinkStandbyMsg ,
[ CONTROLLER_RESETACTIONMOVESELECTION ] = LinkOpponentHandleResetActionMoveSelection ,
2021-01-22 08:48:22 +01:00
[ CONTROLLER_ENDLINKBATTLE ] = LinkOpponentHandleEndLinkBattle ,
2021-01-29 07:45:58 +01:00
[ CONTROLLER_DEBUGMENU ] = LinkOpponentHandleBattleDebug ,
2020-12-29 22:51:44 +01:00
[ CONTROLLER_TERMINATOR_NOP ] = LinkOpponentCmdEnd
2017-10-24 15:25:20 +02:00
} ;
2021-01-23 03:47:00 +01:00
static void LinkOpponentDummy ( void )
2017-10-24 15:25:20 +02:00
{
}
2017-10-26 23:12:48 +02:00
void SetControllerToLinkOpponent ( void )
2017-10-24 15:25:20 +02:00
{
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = LinkOpponentBufferRunCommand ;
2017-10-24 15:25:20 +02:00
}
static void LinkOpponentBufferRunCommand ( void )
{
2018-02-06 20:48:02 +01:00
if ( gBattleControllerExecFlags & gBitTable [ gActiveBattler ] )
2017-10-24 15:25:20 +02:00
{
2019-01-05 16:00:57 +01:00
if ( gBattleResources - > bufferA [ gActiveBattler ] [ 0 ] < ARRAY_COUNT ( sLinkOpponentBufferCommands ) )
sLinkOpponentBufferCommands [ gBattleResources - > bufferA [ gActiveBattler ] [ 0 ] ] ( ) ;
2017-10-24 15:25:20 +02:00
else
LinkOpponentBufferExecCompleted ( ) ;
}
}
2018-07-01 15:28:57 +02:00
static void CompleteOnBattlerSpriteCallbackDummy ( void )
2017-10-24 15:25:20 +02:00
{
2018-02-06 20:48:02 +01:00
if ( gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . callback = = SpriteCallbackDummy )
2017-10-24 15:25:20 +02:00
LinkOpponentBufferExecCompleted ( ) ;
}
static void CompleteOnBankSpriteCallbackDummy2 ( void )
{
2018-02-06 20:48:02 +01:00
if ( gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . callback = = SpriteCallbackDummy )
2017-10-24 15:25:20 +02:00
LinkOpponentBufferExecCompleted ( ) ;
}
2021-01-23 03:47:00 +01:00
static void FreeTrainerSpriteAfterSlide ( void )
2017-10-24 15:25:20 +02:00
{
2018-02-06 20:48:02 +01:00
if ( gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . callback = = SpriteCallbackDummy )
2017-10-24 15:25:20 +02:00
{
2018-02-06 20:48:02 +01:00
FreeTrainerFrontPicPalette ( gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . oam . affineParam ) ;
FreeSpriteOamMatrix ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] ) ;
DestroySprite ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] ) ;
2017-10-24 15:25:20 +02:00
LinkOpponentBufferExecCompleted ( ) ;
}
}
2021-01-23 03:47:00 +01:00
static void Intro_DelayAndEnd ( void )
2017-10-24 15:25:20 +02:00
{
2021-01-23 02:03:21 +01:00
if ( - - gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . introEndDelay = = ( u8 ) - 1 )
2017-10-24 15:25:20 +02:00
{
2021-01-23 02:03:21 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . introEndDelay = 0 ;
2017-10-24 15:25:20 +02:00
LinkOpponentBufferExecCompleted ( ) ;
}
}
2021-01-23 03:47:00 +01:00
static void Intro_WaitForShinyAnimAndHealthbox ( void )
2017-10-24 15:25:20 +02:00
{
2021-01-23 03:47:00 +01:00
bool32 healthboxAnimDone = FALSE ;
bool32 twoMons = FALSE ;
2017-10-24 15:25:20 +02:00
if ( ! IsDoubleBattle ( ) | | ( IsDoubleBattle ( ) & & ( gBattleTypeFlags & BATTLE_TYPE_MULTI ) ) )
{
2018-02-06 20:48:02 +01:00
if ( gSprites [ gHealthboxSpriteIds [ gActiveBattler ] ] . callback = = SpriteCallbackDummy )
2021-01-23 03:47:00 +01:00
healthboxAnimDone = TRUE ;
2017-10-24 15:25:20 +02:00
}
else
{
2018-02-06 20:48:02 +01:00
if ( gSprites [ gHealthboxSpriteIds [ gActiveBattler ] ] . callback = = SpriteCallbackDummy
2018-02-06 23:09:39 +01:00
& & gSprites [ gHealthboxSpriteIds [ BATTLE_PARTNER ( gActiveBattler ) ] ] . callback = = SpriteCallbackDummy )
2017-10-24 15:25:20 +02:00
{
2021-01-23 03:47:00 +01:00
healthboxAnimDone = TRUE ;
2017-10-24 15:25:20 +02:00
}
2021-01-23 03:47:00 +01:00
twoMons = TRUE ;
2017-10-24 15:25:20 +02:00
}
2021-01-23 03:47:00 +01:00
if ( healthboxAnimDone )
2017-10-24 15:25:20 +02:00
{
2021-01-23 03:47:00 +01:00
if ( twoMons | | ! IsBattlerSpriteVisible ( BATTLE_PARTNER ( gActiveBattler ) ) )
2017-10-24 15:25:20 +02:00
{
2020-08-30 21:11:44 +02:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . finishedShinyMonAnim )
2017-10-24 15:25:20 +02:00
return ;
2020-08-30 21:11:44 +02:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ BATTLE_PARTNER ( gActiveBattler ) ] . finishedShinyMonAnim )
2017-10-24 15:25:20 +02:00
return ;
2020-08-30 21:11:44 +02:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . triedShinyMonAnim = FALSE ;
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . finishedShinyMonAnim = FALSE ;
2017-10-24 15:25:20 +02:00
2020-08-30 21:11:44 +02:00
gBattleSpritesDataPtr - > healthBoxesData [ BATTLE_PARTNER ( gActiveBattler ) ] . triedShinyMonAnim = FALSE ;
gBattleSpritesDataPtr - > healthBoxesData [ BATTLE_PARTNER ( gActiveBattler ) ] . finishedShinyMonAnim = FALSE ;
2017-10-24 15:25:20 +02:00
2021-01-23 02:03:21 +01:00
FreeSpriteTilesByTag ( ANIM_TAG_GOLD_STARS ) ;
FreeSpritePaletteByTag ( ANIM_TAG_GOLD_STARS ) ;
2017-10-24 15:25:20 +02:00
}
else
{
2020-08-30 21:11:44 +02:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . finishedShinyMonAnim )
2017-10-24 15:25:20 +02:00
return ;
2020-08-30 21:11:44 +02:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . triedShinyMonAnim = FALSE ;
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . finishedShinyMonAnim = FALSE ;
2017-10-24 15:25:20 +02:00
2018-02-06 02:46:59 +01:00
if ( GetBattlerPosition ( gActiveBattler ) = = B_POSITION_OPPONENT_RIGHT )
2017-10-24 15:25:20 +02:00
{
2021-01-23 02:03:21 +01:00
FreeSpriteTilesByTag ( ANIM_TAG_GOLD_STARS ) ;
FreeSpritePaletteByTag ( ANIM_TAG_GOLD_STARS ) ;
2017-10-24 15:25:20 +02:00
}
}
2021-01-23 02:03:21 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . introEndDelay = 3 ;
2021-01-23 03:47:00 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = Intro_DelayAndEnd ;
2017-10-24 15:25:20 +02:00
}
}
2021-01-23 03:47:00 +01:00
static void Intro_TryShinyAnimShowHealthbox ( void )
2017-10-24 15:25:20 +02:00
{
2021-01-23 03:47:00 +01:00
bool32 bgmRestored = FALSE ;
2017-10-24 15:25:20 +02:00
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . ballAnimActive
2020-08-30 21:11:44 +02:00
& & ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . triedShinyMonAnim
& & ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . finishedShinyMonAnim )
2017-10-24 15:25:20 +02:00
{
2020-08-05 04:37:52 +02:00
TryShinyAnimation ( gActiveBattler , & gEnemyParty [ gBattlerPartyIndexes [ gActiveBattler ] ] ) ;
2017-10-24 15:25:20 +02:00
}
if ( ! ( gBattleTypeFlags & BATTLE_TYPE_MULTI )
2018-02-06 23:09:39 +01:00
& & ! gBattleSpritesDataPtr - > healthBoxesData [ BATTLE_PARTNER ( gActiveBattler ) ] . ballAnimActive
2020-08-30 21:11:44 +02:00
& & ! gBattleSpritesDataPtr - > healthBoxesData [ BATTLE_PARTNER ( gActiveBattler ) ] . triedShinyMonAnim
& & ! gBattleSpritesDataPtr - > healthBoxesData [ BATTLE_PARTNER ( gActiveBattler ) ] . finishedShinyMonAnim )
2017-10-24 15:25:20 +02:00
{
2020-08-05 04:37:52 +02:00
TryShinyAnimation ( BATTLE_PARTNER ( gActiveBattler ) , & gEnemyParty [ gBattlerPartyIndexes [ BATTLE_PARTNER ( gActiveBattler ) ] ] ) ;
2017-10-24 15:25:20 +02:00
}
2018-02-06 23:09:39 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . ballAnimActive & & ! gBattleSpritesDataPtr - > healthBoxesData [ BATTLE_PARTNER ( gActiveBattler ) ] . ballAnimActive )
2017-10-24 15:25:20 +02:00
{
2021-01-23 02:03:21 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . healthboxSlideInStarted )
2017-10-24 15:25:20 +02:00
{
if ( IsDoubleBattle ( ) & & ! ( gBattleTypeFlags & BATTLE_TYPE_MULTI ) )
{
2018-02-06 23:09:39 +01:00
UpdateHealthboxAttribute ( gHealthboxSpriteIds [ BATTLE_PARTNER ( gActiveBattler ) ] , & gEnemyParty [ gBattlerPartyIndexes [ BATTLE_PARTNER ( gActiveBattler ) ] ] , HEALTHBOX_ALL ) ;
2021-01-23 02:03:21 +01:00
StartHealthboxSlideIn ( BATTLE_PARTNER ( gActiveBattler ) ) ;
2018-02-06 23:09:39 +01:00
SetHealthboxSpriteVisible ( gHealthboxSpriteIds [ BATTLE_PARTNER ( gActiveBattler ) ] ) ;
2017-10-24 15:25:20 +02:00
}
2018-02-06 20:48:02 +01:00
UpdateHealthboxAttribute ( gHealthboxSpriteIds [ gActiveBattler ] , & gEnemyParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , HEALTHBOX_ALL ) ;
2021-01-23 02:03:21 +01:00
StartHealthboxSlideIn ( gActiveBattler ) ;
2018-02-06 20:48:02 +01:00
SetHealthboxSpriteVisible ( gHealthboxSpriteIds [ gActiveBattler ] ) ;
2017-10-24 15:25:20 +02:00
}
2021-01-23 02:03:21 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . healthboxSlideInStarted = TRUE ;
2017-10-24 15:25:20 +02:00
}
2021-01-23 02:03:21 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . waitForCry
& & gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . healthboxSlideInStarted
& & ! gBattleSpritesDataPtr - > healthBoxesData [ BATTLE_PARTNER ( gActiveBattler ) ] . waitForCry
2017-10-24 15:25:20 +02:00
& & ! IsCryPlayingOrClearCrySongs ( ) )
{
2021-01-23 02:03:21 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . bgmRestored )
2017-10-24 15:25:20 +02:00
{
if ( gBattleTypeFlags & BATTLE_TYPE_MULTI & & gBattleTypeFlags & BATTLE_TYPE_LINK )
{
2018-02-06 02:46:59 +01:00
if ( GetBattlerPosition ( gActiveBattler ) = = B_POSITION_OPPONENT_LEFT )
2018-01-10 04:30:54 +01:00
m4aMPlayContinue ( & gMPlayInfo_BGM ) ;
2017-10-24 15:25:20 +02:00
}
else
{
2021-10-09 17:33:37 +02:00
m4aMPlayVolumeControl ( & gMPlayInfo_BGM , TRACKS_ALL , 0x100 ) ;
2017-10-24 15:25:20 +02:00
}
}
2021-01-23 02:03:21 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . bgmRestored = TRUE ;
2021-01-23 03:47:00 +01:00
bgmRestored = TRUE ;
2017-10-24 15:25:20 +02:00
}
2021-01-23 03:47:00 +01:00
if ( bgmRestored )
2017-10-24 15:25:20 +02:00
{
2021-01-23 02:03:21 +01:00
if ( gSprites [ gBattleControllerData [ gActiveBattler ] ] . callback = = SpriteCallbackDummy
2018-02-06 20:48:02 +01:00
& & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . callback = = SpriteCallbackDummy )
2017-10-24 15:25:20 +02:00
{
2018-02-06 02:46:59 +01:00
if ( gBattleTypeFlags & BATTLE_TYPE_MULTI & & GetBattlerPosition ( gActiveBattler ) = = B_POSITION_OPPONENT_RIGHT )
2017-10-24 15:25:20 +02:00
{
2021-01-23 02:03:21 +01:00
if ( + + gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . introEndDelay = = 1 )
2017-10-24 15:25:20 +02:00
return ;
2021-01-23 02:03:21 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . introEndDelay = 0 ;
2017-10-24 15:25:20 +02:00
}
if ( IsDoubleBattle ( ) & & ! ( gBattleTypeFlags & BATTLE_TYPE_MULTI ) )
{
2021-01-23 02:03:21 +01:00
DestroySprite ( & gSprites [ gBattleControllerData [ BATTLE_PARTNER ( gActiveBattler ) ] ] ) ;
2018-02-06 23:09:39 +01:00
SetBattlerShadowSpriteCallback ( BATTLE_PARTNER ( gActiveBattler ) , GetMonData ( & gEnemyParty [ gBattlerPartyIndexes [ BATTLE_PARTNER ( gActiveBattler ) ] ] , MON_DATA_SPECIES ) ) ;
2017-10-24 15:25:20 +02:00
}
2021-01-23 02:03:21 +01:00
DestroySprite ( & gSprites [ gBattleControllerData [ gActiveBattler ] ] ) ;
2018-02-06 20:48:02 +01:00
SetBattlerShadowSpriteCallback ( gActiveBattler , GetMonData ( & gEnemyParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , MON_DATA_SPECIES ) ) ;
2017-10-24 15:25:20 +02:00
2021-01-23 02:03:21 +01:00
gBattleSpritesDataPtr - > animationData - > introAnimActive = FALSE ;
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . bgmRestored = FALSE ;
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . healthboxSlideInStarted = FALSE ;
2017-10-24 15:25:20 +02:00
2021-01-23 03:47:00 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = Intro_WaitForShinyAnimAndHealthbox ;
2017-10-24 15:25:20 +02:00
}
}
}
2021-01-23 03:47:00 +01:00
static void TryShinyAnimAfterMonAnim ( void )
2017-10-24 15:25:20 +02:00
{
2018-02-06 20:48:02 +01:00
if ( gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . callback = = SpriteCallbackDummy
2021-07-07 15:11:52 +02:00
& & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . x2 = = 0 )
2017-10-24 15:25:20 +02:00
{
2020-08-30 21:11:44 +02:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . triedShinyMonAnim )
2017-10-24 15:25:20 +02:00
{
2020-08-05 04:37:52 +02:00
TryShinyAnimation ( gActiveBattler , & gEnemyParty [ gBattlerPartyIndexes [ gActiveBattler ] ] ) ;
2017-10-24 15:25:20 +02:00
}
2022-08-18 20:23:45 +02:00
else if ( gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . finishedShinyMonAnim )
2017-10-24 15:25:20 +02:00
{
2022-08-18 20:23:45 +02:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . triedShinyMonAnim = FALSE ;
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . finishedShinyMonAnim = FALSE ;
FreeSpriteTilesByTag ( ANIM_TAG_GOLD_STARS ) ;
FreeSpritePaletteByTag ( ANIM_TAG_GOLD_STARS ) ;
LinkOpponentBufferExecCompleted ( ) ;
2017-10-24 15:25:20 +02:00
}
}
}
static void CompleteOnHealthbarDone ( void )
{
2018-06-19 00:43:15 +02:00
s16 hpValue = MoveBattleBar ( gActiveBattler , gHealthboxSpriteIds [ gActiveBattler ] , HEALTH_BAR , 0 ) ;
2017-10-24 15:25:20 +02:00
2018-02-06 20:48:02 +01:00
SetHealthboxSpriteVisible ( gHealthboxSpriteIds [ gActiveBattler ] ) ;
2017-10-24 15:25:20 +02:00
if ( hpValue ! = - 1 )
2022-08-25 17:37:47 +02:00
UpdateHpTextInHealthbox ( gHealthboxSpriteIds [ gActiveBattler ] , HP_CURRENT , hpValue , gBattleMons [ gActiveBattler ] . maxHP ) ;
2017-10-24 15:25:20 +02:00
else
LinkOpponentBufferExecCompleted ( ) ;
}
2021-01-23 03:47:00 +01:00
static void HideHealthboxAfterMonFaint ( void )
2017-10-24 15:25:20 +02:00
{
2018-02-06 20:48:02 +01:00
if ( ! gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . inUse )
2017-10-24 15:25:20 +02:00
{
2018-02-06 20:48:02 +01:00
SetHealthboxSpriteInvisible ( gHealthboxSpriteIds [ gActiveBattler ] ) ;
2017-10-24 15:25:20 +02:00
LinkOpponentBufferExecCompleted ( ) ;
}
}
2021-01-23 03:47:00 +01:00
static void FreeMonSpriteAfterSwitchOutAnim ( void )
2017-10-24 15:25:20 +02:00
{
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . specialAnimActive )
2017-10-24 15:25:20 +02:00
{
2018-02-06 20:48:02 +01:00
FreeSpriteOamMatrix ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] ) ;
DestroySprite ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] ) ;
HideBattlerShadowSprite ( gActiveBattler ) ;
SetHealthboxSpriteInvisible ( gHealthboxSpriteIds [ gActiveBattler ] ) ;
2017-10-24 15:25:20 +02:00
LinkOpponentBufferExecCompleted ( ) ;
}
}
static void CompleteOnInactiveTextPrinter ( void )
{
2021-10-08 22:50:52 +02:00
if ( ! IsTextPrinterActive ( B_WIN_MSG ) )
2017-10-24 15:25:20 +02:00
LinkOpponentBufferExecCompleted ( ) ;
}
static void DoHitAnimBlinkSpriteEffect ( void )
{
2018-02-06 20:48:02 +01:00
u8 spriteId = gBattlerSpriteIds [ gActiveBattler ] ;
2017-10-24 15:25:20 +02:00
2017-12-02 21:44:50 +01:00
if ( gSprites [ spriteId ] . data [ 1 ] = = 32 )
2017-10-24 15:25:20 +02:00
{
2017-12-02 21:44:50 +01:00
gSprites [ spriteId ] . data [ 1 ] = 0 ;
2018-09-10 17:25:58 +02:00
gSprites [ spriteId ] . invisible = FALSE ;
2017-10-24 15:25:20 +02:00
gDoingBattleAnim = FALSE ;
LinkOpponentBufferExecCompleted ( ) ;
}
else
{
2017-12-02 21:44:50 +01:00
if ( ( gSprites [ spriteId ] . data [ 1 ] % 4 ) = = 0 )
2017-10-24 15:25:20 +02:00
gSprites [ spriteId ] . invisible ^ = 1 ;
2017-12-02 21:44:50 +01:00
gSprites [ spriteId ] . data [ 1 ] + + ;
2017-10-24 15:25:20 +02:00
}
}
2021-01-23 03:47:00 +01:00
static void SwitchIn_ShowSubstitute ( void )
2017-10-24 15:25:20 +02:00
{
2018-02-06 20:48:02 +01:00
if ( gSprites [ gHealthboxSpriteIds [ gActiveBattler ] ] . callback = = SpriteCallbackDummy )
2017-10-24 15:25:20 +02:00
{
2018-02-06 23:09:39 +01:00
if ( gBattleSpritesDataPtr - > battlerData [ gActiveBattler ] . behindSubstitute )
2018-02-06 02:46:59 +01:00
InitAndLaunchSpecialAnimation ( gActiveBattler , gActiveBattler , gActiveBattler , B_ANIM_MON_TO_SUBSTITUTE ) ;
2017-10-24 15:25:20 +02:00
2021-01-23 03:47:00 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = SwitchIn_HandleSoundAndEnd ;
2017-10-24 15:25:20 +02:00
}
}
2021-01-23 03:47:00 +01:00
static void SwitchIn_HandleSoundAndEnd ( void )
2017-10-24 15:25:20 +02:00
{
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . specialAnimActive & & ! IsCryPlayingOrClearCrySongs ( ) )
2017-10-24 15:25:20 +02:00
{
2018-02-06 20:48:02 +01:00
if ( gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . callback = = SpriteCallbackDummy
| | gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . callback = = SpriteCallbackDummy_2 )
2017-10-24 15:25:20 +02:00
{
2021-10-09 17:33:37 +02:00
m4aMPlayVolumeControl ( & gMPlayInfo_BGM , TRACKS_ALL , 0x100 ) ;
2017-10-24 15:25:20 +02:00
LinkOpponentBufferExecCompleted ( ) ;
}
}
}
2021-01-23 03:47:00 +01:00
static void SwitchIn_ShowHealthbox ( void )
2017-10-24 15:25:20 +02:00
{
2020-08-30 21:11:44 +02:00
if ( gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . finishedShinyMonAnim
2018-02-06 20:48:02 +01:00
& & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . callback = = SpriteCallbackDummy )
2017-10-24 15:25:20 +02:00
{
2020-08-30 21:11:44 +02:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . triedShinyMonAnim = FALSE ;
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . finishedShinyMonAnim = FALSE ;
2017-10-24 15:25:20 +02:00
2021-01-23 02:03:21 +01:00
FreeSpriteTilesByTag ( ANIM_TAG_GOLD_STARS ) ;
FreeSpritePaletteByTag ( ANIM_TAG_GOLD_STARS ) ;
2017-10-24 15:25:20 +02:00
2018-02-06 20:48:02 +01:00
StartSpriteAnim ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] , 0 ) ;
2017-10-24 15:25:20 +02:00
2018-02-06 20:48:02 +01:00
UpdateHealthboxAttribute ( gHealthboxSpriteIds [ gActiveBattler ] , & gEnemyParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , HEALTHBOX_ALL ) ;
2021-01-23 02:03:21 +01:00
StartHealthboxSlideIn ( gActiveBattler ) ;
2018-02-06 20:48:02 +01:00
SetHealthboxSpriteVisible ( gHealthboxSpriteIds [ gActiveBattler ] ) ;
2018-02-06 02:46:59 +01:00
CopyBattleSpriteInvisibility ( gActiveBattler ) ;
2021-01-23 03:47:00 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = SwitchIn_ShowSubstitute ;
2017-10-24 15:25:20 +02:00
}
}
2021-01-23 03:47:00 +01:00
static void SwitchIn_TryShinyAnim ( void )
2017-10-24 15:25:20 +02:00
{
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . ballAnimActive
2020-08-30 21:11:44 +02:00
& & ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . triedShinyMonAnim )
2017-10-24 15:25:20 +02:00
{
2020-08-05 04:37:52 +02:00
TryShinyAnimation ( gActiveBattler , & gEnemyParty [ gBattlerPartyIndexes [ gActiveBattler ] ] ) ;
2017-10-24 15:25:20 +02:00
}
2021-01-23 02:03:21 +01:00
if ( gSprites [ gBattleControllerData [ gActiveBattler ] ] . callback = = SpriteCallbackDummy
2018-02-06 02:46:59 +01:00
& & ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . ballAnimActive )
2017-10-24 15:25:20 +02:00
{
2021-01-23 02:03:21 +01:00
DestroySprite ( & gSprites [ gBattleControllerData [ gActiveBattler ] ] ) ;
2018-02-06 20:48:02 +01:00
SetBattlerShadowSpriteCallback ( gActiveBattler , GetMonData ( & gEnemyParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , MON_DATA_SPECIES ) ) ;
2021-01-23 03:47:00 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = SwitchIn_ShowHealthbox ;
2017-10-24 15:25:20 +02:00
}
}
static void CompleteOnFinishedStatusAnimation ( void )
{
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . statusAnimActive )
2017-10-24 15:25:20 +02:00
LinkOpponentBufferExecCompleted ( ) ;
}
static void CompleteOnFinishedBattleAnimation ( void )
{
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animFromTableActive )
2017-10-24 15:25:20 +02:00
LinkOpponentBufferExecCompleted ( ) ;
}
static void LinkOpponentBufferExecCompleted ( void )
{
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = LinkOpponentBufferRunCommand ;
2017-10-24 15:25:20 +02:00
if ( gBattleTypeFlags & BATTLE_TYPE_LINK )
{
u8 playerId = GetMultiplayerId ( ) ;
PrepareBufferDataTransferLink ( 2 , 4 , & playerId ) ;
2019-01-05 16:00:57 +01:00
gBattleResources - > bufferA [ gActiveBattler ] [ 0 ] = CONTROLLER_TERMINATOR_NOP ;
2017-10-24 15:25:20 +02:00
}
else
{
2018-02-06 20:48:02 +01:00
gBattleControllerExecFlags & = ~ gBitTable [ gActiveBattler ] ;
2017-10-24 15:25:20 +02:00
}
}
static void LinkOpponentHandleGetMonData ( void )
{
u8 monData [ sizeof ( struct Pokemon ) * 2 + 56 ] ; // this allows to get full data of two pokemon, trying to get more will result in overwriting data
u32 size = 0 ;
2017-10-31 18:04:08 +01:00
u8 monToCheck ;
2017-10-24 15:25:20 +02:00
s32 i ;
2019-01-05 16:00:57 +01:00
if ( gBattleResources - > bufferA [ gActiveBattler ] [ 2 ] = = 0 )
2017-10-24 15:25:20 +02:00
{
2018-02-06 20:48:02 +01:00
size + = CopyLinkOpponentMonData ( gBattlerPartyIndexes [ gActiveBattler ] , monData ) ;
2017-10-24 15:25:20 +02:00
}
else
{
2019-01-05 16:00:57 +01:00
monToCheck = gBattleResources - > bufferA [ gActiveBattler ] [ 2 ] ;
2018-11-18 20:00:36 +01:00
for ( i = 0 ; i < PARTY_SIZE ; i + + )
2017-10-24 15:25:20 +02:00
{
2017-10-31 18:04:08 +01:00
if ( monToCheck & 1 )
2017-10-24 15:25:20 +02:00
size + = CopyLinkOpponentMonData ( i , monData + size ) ;
2017-10-31 18:04:08 +01:00
monToCheck > > = 1 ;
2017-10-24 15:25:20 +02:00
}
}
2021-10-13 01:50:32 +02:00
BtlController_EmitDataTransfer ( BUFFER_B , size , monData ) ;
2017-10-24 15:25:20 +02:00
LinkOpponentBufferExecCompleted ( ) ;
}
static u32 CopyLinkOpponentMonData ( u8 monId , u8 * dst )
{
struct BattlePokemon battleMon ;
struct MovePpInfo moveData ;
u8 nickname [ 20 ] ;
u8 * src ;
s16 data16 ;
u32 data32 ;
s32 size = 0 ;
2019-01-05 16:00:57 +01:00
switch ( gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] )
2017-10-24 15:25:20 +02:00
{
case REQUEST_ALL_BATTLE :
battleMon . species = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPECIES ) ;
battleMon . item = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_HELD_ITEM ) ;
2018-12-25 18:50:15 +01:00
for ( size = 0 ; size < MAX_MON_MOVES ; size + + )
2017-10-24 15:25:20 +02:00
{
battleMon . moves [ size ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_MOVE1 + size ) ;
battleMon . pp [ size ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_PP1 + size ) ;
}
battleMon . ppBonuses = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_PP_BONUSES ) ;
battleMon . friendship = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_FRIENDSHIP ) ;
battleMon . experience = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_EXP ) ;
battleMon . hpIV = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_HP_IV ) ;
battleMon . attackIV = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_ATK_IV ) ;
battleMon . defenseIV = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_DEF_IV ) ;
2017-10-24 15:35:36 +02:00
battleMon . speedIV = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPEED_IV ) ;
2017-10-24 15:25:20 +02:00
battleMon . spAttackIV = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPATK_IV ) ;
battleMon . spDefenseIV = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPDEF_IV ) ;
battleMon . personality = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_PERSONALITY ) ;
battleMon . status1 = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_STATUS ) ;
battleMon . level = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_LEVEL ) ;
battleMon . hp = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_HP ) ;
battleMon . maxHP = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_MAX_HP ) ;
battleMon . attack = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_ATK ) ;
battleMon . defense = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_DEF ) ;
2017-10-24 15:35:36 +02:00
battleMon . speed = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPEED ) ;
2017-10-24 15:25:20 +02:00
battleMon . spAttack = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPATK ) ;
battleMon . spDefense = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPDEF ) ;
2019-05-14 15:22:16 +02:00
battleMon . abilityNum = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_ABILITY_NUM ) ;
2017-10-24 15:25:20 +02:00
battleMon . otId = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_OT_ID ) ;
GetMonData ( & gEnemyParty [ monId ] , MON_DATA_NICKNAME , nickname ) ;
2021-11-18 04:11:03 +01:00
StringCopy_Nickname ( battleMon . nickname , nickname ) ;
2017-10-24 15:25:20 +02:00
GetMonData ( & gEnemyParty [ monId ] , MON_DATA_OT_NAME , battleMon . otName ) ;
src = ( u8 * ) & battleMon ;
for ( size = 0 ; size < sizeof ( battleMon ) ; size + + )
dst [ size ] = src [ size ] ;
break ;
case REQUEST_SPECIES_BATTLE :
data16 = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPECIES ) ;
dst [ 0 ] = data16 ;
dst [ 1 ] = data16 > > 8 ;
size = 2 ;
break ;
case REQUEST_HELDITEM_BATTLE :
data16 = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_HELD_ITEM ) ;
dst [ 0 ] = data16 ;
dst [ 1 ] = data16 > > 8 ;
size = 2 ;
break ;
case REQUEST_MOVES_PP_BATTLE :
2018-12-25 18:50:15 +01:00
for ( size = 0 ; size < MAX_MON_MOVES ; size + + )
2017-10-24 15:25:20 +02:00
{
moveData . moves [ size ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_MOVE1 + size ) ;
moveData . pp [ size ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_PP1 + size ) ;
}
moveData . ppBonuses = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_PP_BONUSES ) ;
2022-07-29 16:17:58 +02:00
src = ( u8 * ) ( & moveData ) ;
2017-10-24 15:25:20 +02:00
for ( size = 0 ; size < sizeof ( moveData ) ; size + + )
dst [ size ] = src [ size ] ;
break ;
case REQUEST_MOVE1_BATTLE :
case REQUEST_MOVE2_BATTLE :
case REQUEST_MOVE3_BATTLE :
case REQUEST_MOVE4_BATTLE :
2019-01-05 16:00:57 +01:00
data16 = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_MOVE1 + gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] - REQUEST_MOVE1_BATTLE ) ;
2017-10-24 15:25:20 +02:00
dst [ 0 ] = data16 ;
dst [ 1 ] = data16 > > 8 ;
size = 2 ;
break ;
case REQUEST_PP_DATA_BATTLE :
2018-12-25 18:50:15 +01:00
for ( size = 0 ; size < MAX_MON_MOVES ; size + + )
2017-10-24 15:25:20 +02:00
dst [ size ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_PP1 + size ) ;
dst [ size ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_PP_BONUSES ) ;
size + + ;
break ;
case REQUEST_PPMOVE1_BATTLE :
case REQUEST_PPMOVE2_BATTLE :
case REQUEST_PPMOVE3_BATTLE :
case REQUEST_PPMOVE4_BATTLE :
2019-01-05 16:00:57 +01:00
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_PP1 + gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] - REQUEST_PPMOVE1_BATTLE ) ;
2017-10-24 15:25:20 +02:00
size = 1 ;
break ;
case REQUEST_OTID_BATTLE :
data32 = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_OT_ID ) ;
dst [ 0 ] = ( data32 & 0x000000FF ) ;
dst [ 1 ] = ( data32 & 0x0000FF00 ) > > 8 ;
dst [ 2 ] = ( data32 & 0x00FF0000 ) > > 16 ;
size = 3 ;
break ;
case REQUEST_EXP_BATTLE :
data32 = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_EXP ) ;
dst [ 0 ] = ( data32 & 0x000000FF ) ;
dst [ 1 ] = ( data32 & 0x0000FF00 ) > > 8 ;
dst [ 2 ] = ( data32 & 0x00FF0000 ) > > 16 ;
size = 3 ;
break ;
case REQUEST_HP_EV_BATTLE :
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_HP_EV ) ;
size = 1 ;
break ;
case REQUEST_ATK_EV_BATTLE :
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_ATK_EV ) ;
size = 1 ;
break ;
case REQUEST_DEF_EV_BATTLE :
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_DEF_EV ) ;
size = 1 ;
break ;
case REQUEST_SPEED_EV_BATTLE :
2017-10-24 15:35:36 +02:00
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPEED_EV ) ;
2017-10-24 15:25:20 +02:00
size = 1 ;
break ;
case REQUEST_SPATK_EV_BATTLE :
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPATK_EV ) ;
size = 1 ;
break ;
case REQUEST_SPDEF_EV_BATTLE :
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPDEF_EV ) ;
size = 1 ;
break ;
case REQUEST_FRIENDSHIP_BATTLE :
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_FRIENDSHIP ) ;
size = 1 ;
break ;
case REQUEST_POKERUS_BATTLE :
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_POKERUS ) ;
size = 1 ;
break ;
case REQUEST_MET_LOCATION_BATTLE :
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_MET_LOCATION ) ;
size = 1 ;
break ;
case REQUEST_MET_LEVEL_BATTLE :
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_MET_LEVEL ) ;
size = 1 ;
break ;
case REQUEST_MET_GAME_BATTLE :
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_MET_GAME ) ;
size = 1 ;
break ;
case REQUEST_POKEBALL_BATTLE :
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_POKEBALL ) ;
size = 1 ;
break ;
case REQUEST_ALL_IVS_BATTLE :
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_HP_IV ) ;
dst [ 1 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_ATK_IV ) ;
dst [ 2 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_DEF_IV ) ;
2017-10-24 15:35:36 +02:00
dst [ 3 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPEED_IV ) ;
2017-10-24 15:25:20 +02:00
dst [ 4 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPATK_IV ) ;
dst [ 5 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPDEF_IV ) ;
size = 6 ;
break ;
case REQUEST_HP_IV_BATTLE :
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_HP_IV ) ;
size = 1 ;
break ;
case REQUEST_ATK_IV_BATTLE :
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_ATK_IV ) ;
size = 1 ;
break ;
case REQUEST_DEF_IV_BATTLE :
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_DEF_IV ) ;
size = 1 ;
break ;
case REQUEST_SPEED_IV_BATTLE :
2017-10-24 15:35:36 +02:00
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPEED_IV ) ;
2017-10-24 15:25:20 +02:00
size = 1 ;
break ;
case REQUEST_SPATK_IV_BATTLE :
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPATK_IV ) ;
size = 1 ;
break ;
case REQUEST_SPDEF_IV_BATTLE :
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPDEF_IV ) ;
size = 1 ;
break ;
case REQUEST_PERSONALITY_BATTLE :
data32 = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_PERSONALITY ) ;
dst [ 0 ] = ( data32 & 0x000000FF ) ;
dst [ 1 ] = ( data32 & 0x0000FF00 ) > > 8 ;
dst [ 2 ] = ( data32 & 0x00FF0000 ) > > 16 ;
dst [ 3 ] = ( data32 & 0xFF000000 ) > > 24 ;
size = 4 ;
break ;
case REQUEST_CHECKSUM_BATTLE :
data16 = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_CHECKSUM ) ;
dst [ 0 ] = data16 ;
dst [ 1 ] = data16 > > 8 ;
size = 2 ;
break ;
case REQUEST_STATUS_BATTLE :
data32 = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_STATUS ) ;
dst [ 0 ] = ( data32 & 0x000000FF ) ;
dst [ 1 ] = ( data32 & 0x0000FF00 ) > > 8 ;
dst [ 2 ] = ( data32 & 0x00FF0000 ) > > 16 ;
dst [ 3 ] = ( data32 & 0xFF000000 ) > > 24 ;
size = 4 ;
break ;
case REQUEST_LEVEL_BATTLE :
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_LEVEL ) ;
size = 1 ;
break ;
case REQUEST_HP_BATTLE :
data16 = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_HP ) ;
dst [ 0 ] = data16 ;
dst [ 1 ] = data16 > > 8 ;
size = 2 ;
break ;
case REQUEST_MAX_HP_BATTLE :
data16 = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_MAX_HP ) ;
dst [ 0 ] = data16 ;
dst [ 1 ] = data16 > > 8 ;
size = 2 ;
break ;
case REQUEST_ATK_BATTLE :
data16 = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_ATK ) ;
dst [ 0 ] = data16 ;
dst [ 1 ] = data16 > > 8 ;
size = 2 ;
break ;
case REQUEST_DEF_BATTLE :
data16 = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_DEF ) ;
dst [ 0 ] = data16 ;
dst [ 1 ] = data16 > > 8 ;
size = 2 ;
break ;
case REQUEST_SPEED_BATTLE :
2017-10-24 15:35:36 +02:00
data16 = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPEED ) ;
2017-10-24 15:25:20 +02:00
dst [ 0 ] = data16 ;
dst [ 1 ] = data16 > > 8 ;
size = 2 ;
break ;
case REQUEST_SPATK_BATTLE :
data16 = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPATK ) ;
dst [ 0 ] = data16 ;
dst [ 1 ] = data16 > > 8 ;
size = 2 ;
break ;
case REQUEST_SPDEF_BATTLE :
data16 = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPDEF ) ;
dst [ 0 ] = data16 ;
dst [ 1 ] = data16 > > 8 ;
size = 2 ;
break ;
case REQUEST_COOL_BATTLE :
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_COOL ) ;
size = 1 ;
break ;
case REQUEST_BEAUTY_BATTLE :
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_BEAUTY ) ;
size = 1 ;
break ;
case REQUEST_CUTE_BATTLE :
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_CUTE ) ;
size = 1 ;
break ;
case REQUEST_SMART_BATTLE :
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_SMART ) ;
size = 1 ;
break ;
case REQUEST_TOUGH_BATTLE :
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_TOUGH ) ;
size = 1 ;
break ;
case REQUEST_SHEEN_BATTLE :
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_SHEEN ) ;
size = 1 ;
break ;
case REQUEST_COOL_RIBBON_BATTLE :
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_COOL_RIBBON ) ;
size = 1 ;
break ;
case REQUEST_BEAUTY_RIBBON_BATTLE :
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_BEAUTY_RIBBON ) ;
size = 1 ;
break ;
case REQUEST_CUTE_RIBBON_BATTLE :
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_CUTE_RIBBON ) ;
size = 1 ;
break ;
case REQUEST_SMART_RIBBON_BATTLE :
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_SMART_RIBBON ) ;
size = 1 ;
break ;
case REQUEST_TOUGH_RIBBON_BATTLE :
dst [ 0 ] = GetMonData ( & gEnemyParty [ monId ] , MON_DATA_TOUGH_RIBBON ) ;
size = 1 ;
break ;
}
return size ;
}
static void LinkOpponentHandleGetRawMonData ( void )
{
LinkOpponentBufferExecCompleted ( ) ;
}
static void LinkOpponentHandleSetMonData ( void )
{
2017-10-31 18:04:08 +01:00
u8 monToCheck ;
2017-10-24 15:25:20 +02:00
u8 i ;
2019-01-05 16:00:57 +01:00
if ( gBattleResources - > bufferA [ gActiveBattler ] [ 2 ] = = 0 )
2017-10-24 15:25:20 +02:00
{
2018-02-06 20:48:02 +01:00
SetLinkOpponentMonData ( gBattlerPartyIndexes [ gActiveBattler ] ) ;
2017-10-24 15:25:20 +02:00
}
else
{
2019-01-05 16:00:57 +01:00
monToCheck = gBattleResources - > bufferA [ gActiveBattler ] [ 2 ] ;
2018-11-18 20:00:36 +01:00
for ( i = 0 ; i < PARTY_SIZE ; i + + )
2017-10-24 15:25:20 +02:00
{
2017-10-31 18:04:08 +01:00
if ( monToCheck & 1 )
2017-10-24 15:25:20 +02:00
SetLinkOpponentMonData ( i ) ;
2017-10-31 18:04:08 +01:00
monToCheck > > = 1 ;
2017-10-24 15:25:20 +02:00
}
}
LinkOpponentBufferExecCompleted ( ) ;
}
static void SetLinkOpponentMonData ( u8 monId )
{
2019-01-05 16:00:57 +01:00
struct BattlePokemon * battlePokemon = ( struct BattlePokemon * ) & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ;
struct MovePpInfo * moveData = ( struct MovePpInfo * ) & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ;
2017-10-24 15:25:20 +02:00
s32 i ;
2019-01-05 16:00:57 +01:00
switch ( gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] )
2017-10-24 15:25:20 +02:00
{
case REQUEST_ALL_BATTLE :
{
u8 iv ;
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPECIES , & battlePokemon - > species ) ;
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_HELD_ITEM , & battlePokemon - > item ) ;
2018-12-25 18:50:15 +01:00
for ( i = 0 ; i < MAX_MON_MOVES ; i + + )
2017-10-24 15:25:20 +02:00
{
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_MOVE1 + i , & battlePokemon - > moves [ i ] ) ;
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_PP1 + i , & battlePokemon - > pp [ i ] ) ;
}
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_PP_BONUSES , & battlePokemon - > ppBonuses ) ;
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_FRIENDSHIP , & battlePokemon - > friendship ) ;
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_EXP , & battlePokemon - > experience ) ;
iv = battlePokemon - > hpIV ;
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_HP_IV , & iv ) ;
iv = battlePokemon - > attackIV ;
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_ATK_IV , & iv ) ;
iv = battlePokemon - > defenseIV ;
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_DEF_IV , & iv ) ;
iv = battlePokemon - > speedIV ;
2017-10-24 15:35:36 +02:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPEED_IV , & iv ) ;
2017-10-24 15:25:20 +02:00
iv = battlePokemon - > spAttackIV ;
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPATK_IV , & iv ) ;
iv = battlePokemon - > spDefenseIV ;
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPDEF_IV , & iv ) ;
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_PERSONALITY , & battlePokemon - > personality ) ;
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_STATUS , & battlePokemon - > status1 ) ;
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_LEVEL , & battlePokemon - > level ) ;
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_HP , & battlePokemon - > hp ) ;
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_MAX_HP , & battlePokemon - > maxHP ) ;
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_ATK , & battlePokemon - > attack ) ;
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_DEF , & battlePokemon - > defense ) ;
2017-10-24 15:35:36 +02:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPEED , & battlePokemon - > speed ) ;
2017-10-24 15:25:20 +02:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPATK , & battlePokemon - > spAttack ) ;
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPDEF , & battlePokemon - > spDefense ) ;
}
break ;
case REQUEST_SPECIES_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPECIES , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_HELDITEM_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_HELD_ITEM , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_MOVES_PP_BATTLE :
2018-12-25 18:50:15 +01:00
for ( i = 0 ; i < MAX_MON_MOVES ; i + + )
2017-10-24 15:25:20 +02:00
{
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_MOVE1 + i , & moveData - > moves [ i ] ) ;
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_PP1 + i , & moveData - > pp [ i ] ) ;
}
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_PP_BONUSES , & moveData - > ppBonuses ) ;
break ;
case REQUEST_MOVE1_BATTLE :
case REQUEST_MOVE2_BATTLE :
case REQUEST_MOVE3_BATTLE :
case REQUEST_MOVE4_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_MOVE1 + gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] - REQUEST_MOVE1_BATTLE , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_PP_DATA_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_PP1 , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_PP2 , & gBattleResources - > bufferA [ gActiveBattler ] [ 4 ] ) ;
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_PP3 , & gBattleResources - > bufferA [ gActiveBattler ] [ 5 ] ) ;
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_PP4 , & gBattleResources - > bufferA [ gActiveBattler ] [ 6 ] ) ;
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_PP_BONUSES , & gBattleResources - > bufferA [ gActiveBattler ] [ 7 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_PPMOVE1_BATTLE :
case REQUEST_PPMOVE2_BATTLE :
case REQUEST_PPMOVE3_BATTLE :
case REQUEST_PPMOVE4_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_PP1 + gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] - REQUEST_PPMOVE1_BATTLE , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_OTID_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_OT_ID , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_EXP_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_EXP , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_HP_EV_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_HP_EV , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_ATK_EV_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_ATK_EV , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_DEF_EV_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_DEF_EV , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_SPEED_EV_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPEED_EV , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_SPATK_EV_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPATK_EV , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_SPDEF_EV_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPDEF_EV , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_FRIENDSHIP_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_FRIENDSHIP , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_POKERUS_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_POKERUS , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_MET_LOCATION_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_MET_LOCATION , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_MET_LEVEL_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_MET_LEVEL , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_MET_GAME_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_MET_GAME , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_POKEBALL_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_POKEBALL , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_ALL_IVS_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_HP_IV , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_ATK_IV , & gBattleResources - > bufferA [ gActiveBattler ] [ 4 ] ) ;
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_DEF_IV , & gBattleResources - > bufferA [ gActiveBattler ] [ 5 ] ) ;
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPEED_IV , & gBattleResources - > bufferA [ gActiveBattler ] [ 6 ] ) ;
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPATK_IV , & gBattleResources - > bufferA [ gActiveBattler ] [ 7 ] ) ;
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPDEF_IV , & gBattleResources - > bufferA [ gActiveBattler ] [ 8 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_HP_IV_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_HP_IV , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_ATK_IV_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_ATK_IV , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_DEF_IV_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_DEF_IV , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_SPEED_IV_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPEED_IV , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_SPATK_IV_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPATK_IV , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_SPDEF_IV_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPDEF_IV , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_PERSONALITY_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_PERSONALITY , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_CHECKSUM_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_CHECKSUM , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_STATUS_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_STATUS , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_LEVEL_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_LEVEL , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_HP_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_HP , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_MAX_HP_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_MAX_HP , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_ATK_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_ATK , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_DEF_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_DEF , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_SPEED_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPEED , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_SPATK_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPATK , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_SPDEF_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_SPDEF , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_COOL_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_COOL , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_BEAUTY_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_BEAUTY , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_CUTE_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_CUTE , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_SMART_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_SMART , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_TOUGH_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_TOUGH , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_SHEEN_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_SHEEN , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_COOL_RIBBON_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_COOL_RIBBON , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_BEAUTY_RIBBON_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_BEAUTY_RIBBON , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_CUTE_RIBBON_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_CUTE_RIBBON , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_SMART_RIBBON_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_SMART_RIBBON , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
case REQUEST_TOUGH_RIBBON_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gEnemyParty [ monId ] , MON_DATA_TOUGH_RIBBON , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-24 15:25:20 +02:00
break ;
}
}
static void LinkOpponentHandleSetRawMonData ( void )
{
2019-01-05 16:00:57 +01:00
u8 * dst = ( u8 * ) & gEnemyParty [ gBattlerPartyIndexes [ gActiveBattler ] ] + gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] ;
2017-10-24 15:25:20 +02:00
u8 i ;
2019-01-05 16:00:57 +01:00
for ( i = 0 ; i < gBattleResources - > bufferA [ gActiveBattler ] [ 2 ] ; i + + )
dst [ i ] = gBattleResources - > bufferA [ gActiveBattler ] [ 3 + i ] ;
2017-10-24 15:25:20 +02:00
LinkOpponentBufferExecCompleted ( ) ;
}
static void LinkOpponentHandleLoadMonSprite ( void )
{
2018-02-06 20:48:02 +01:00
u16 species = GetMonData ( & gEnemyParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , MON_DATA_SPECIES ) ;
2017-10-24 15:25:20 +02:00
2018-02-06 20:48:02 +01:00
BattleLoadOpponentMonSpriteGfx ( & gEnemyParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , gActiveBattler ) ;
2018-07-01 15:28:57 +02:00
SetMultiuseSpriteTemplateToPokemon ( species , GetBattlerPosition ( gActiveBattler ) ) ;
2017-10-24 15:25:20 +02:00
2018-07-01 15:28:57 +02:00
gBattlerSpriteIds [ gActiveBattler ] = CreateSprite ( & gMultiuseSpriteTemplate ,
2021-11-08 19:18:58 +01:00
GetBattlerSpriteCoord ( gActiveBattler , BATTLER_COORD_X_2 ) ,
2018-02-06 20:48:02 +01:00
GetBattlerSpriteDefault_Y ( gActiveBattler ) ,
2018-12-18 05:08:08 +01:00
GetBattlerSpriteSubpriority ( gActiveBattler ) ) ;
2017-10-24 15:25:20 +02:00
2021-07-07 15:11:52 +02:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . x2 = - DISPLAY_WIDTH ;
2018-02-06 20:48:02 +01:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . data [ 0 ] = gActiveBattler ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . oam . paletteNum = gActiveBattler ;
StartSpriteAnim ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] , gBattleMonForms [ gActiveBattler ] ) ;
2017-10-24 15:25:20 +02:00
2018-02-06 20:48:02 +01:00
SetBattlerShadowSpriteCallback ( gActiveBattler , GetMonData ( & gEnemyParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , MON_DATA_SPECIES ) ) ;
2017-10-24 15:25:20 +02:00
2021-01-23 03:47:00 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = TryShinyAnimAfterMonAnim ;
2017-10-24 15:25:20 +02:00
}
static void LinkOpponentHandleSwitchInAnim ( void )
{
2019-01-05 16:00:57 +01:00
gBattlerPartyIndexes [ gActiveBattler ] = gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] ;
2021-03-23 07:08:19 +01:00
StartSendOutAnim ( gActiveBattler , gBattleResources - > bufferA [ gActiveBattler ] [ 2 ] ) ;
2021-01-23 03:47:00 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = SwitchIn_TryShinyAnim ;
2017-10-24 15:25:20 +02:00
}
2021-01-23 03:47:00 +01:00
static void StartSendOutAnim ( u8 battlerId , bool8 dontClearSubstituteBit )
2017-10-24 15:25:20 +02:00
{
u16 species ;
2018-03-01 00:59:52 +01:00
ClearTemporarySpeciesSpriteData ( battlerId , dontClearSubstituteBit ) ;
2019-01-05 16:00:57 +01:00
gBattlerPartyIndexes [ battlerId ] = gBattleResources - > bufferA [ battlerId ] [ 1 ] ;
2018-03-01 00:59:52 +01:00
species = GetMonData ( & gEnemyParty [ gBattlerPartyIndexes [ battlerId ] ] , MON_DATA_SPECIES ) ;
2021-01-23 02:03:21 +01:00
gBattleControllerData [ battlerId ] = CreateInvisibleSpriteWithCallback ( SpriteCB_WaitForBattlerBallReleaseAnim ) ;
2018-03-01 00:59:52 +01:00
BattleLoadOpponentMonSpriteGfx ( & gEnemyParty [ gBattlerPartyIndexes [ battlerId ] ] , battlerId ) ;
2018-07-01 15:28:57 +02:00
SetMultiuseSpriteTemplateToPokemon ( species , GetBattlerPosition ( battlerId ) ) ;
2017-10-24 15:25:20 +02:00
2018-03-01 00:59:52 +01:00
gBattlerSpriteIds [ battlerId ] = CreateSprite (
2018-07-01 15:28:57 +02:00
& gMultiuseSpriteTemplate ,
2021-11-08 19:18:58 +01:00
GetBattlerSpriteCoord ( battlerId , BATTLER_COORD_X_2 ) ,
2018-03-01 00:59:52 +01:00
GetBattlerSpriteDefault_Y ( battlerId ) ,
2018-12-18 05:08:08 +01:00
GetBattlerSpriteSubpriority ( battlerId ) ) ;
2017-10-24 15:25:20 +02:00
2021-01-23 02:03:21 +01:00
gSprites [ gBattleControllerData [ battlerId ] ] . data [ 1 ] = gBattlerSpriteIds [ battlerId ] ;
gSprites [ gBattleControllerData [ battlerId ] ] . data [ 2 ] = battlerId ;
2017-10-24 15:25:20 +02:00
2018-03-01 00:59:52 +01:00
gSprites [ gBattlerSpriteIds [ battlerId ] ] . data [ 0 ] = battlerId ;
gSprites [ gBattlerSpriteIds [ battlerId ] ] . data [ 2 ] = species ;
gSprites [ gBattlerSpriteIds [ battlerId ] ] . oam . paletteNum = battlerId ;
2017-10-24 15:25:20 +02:00
2018-03-01 00:59:52 +01:00
StartSpriteAnim ( & gSprites [ gBattlerSpriteIds [ battlerId ] ] , gBattleMonForms [ battlerId ] ) ;
2017-10-24 15:25:20 +02:00
2018-03-01 00:59:52 +01:00
gSprites [ gBattlerSpriteIds [ battlerId ] ] . invisible = TRUE ;
gSprites [ gBattlerSpriteIds [ battlerId ] ] . callback = SpriteCallbackDummy ;
2017-10-24 15:25:20 +02:00
2021-01-23 02:03:21 +01:00
gSprites [ gBattleControllerData [ battlerId ] ] . data [ 0 ] = DoPokeballSendOutAnimation ( 0 , POKEBALL_OPPONENT_SENDOUT ) ;
2017-10-24 15:25:20 +02:00
}
static void LinkOpponentHandleReturnMonToBall ( void )
{
2019-01-05 16:00:57 +01:00
if ( gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] = = 0 )
2017-10-24 15:25:20 +02:00
{
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState = 0 ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = DoSwitchOutAnimation ;
2017-10-24 15:25:20 +02:00
}
else
{
2018-02-06 20:48:02 +01:00
FreeSpriteOamMatrix ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] ) ;
DestroySprite ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] ) ;
HideBattlerShadowSprite ( gActiveBattler ) ;
SetHealthboxSpriteInvisible ( gHealthboxSpriteIds [ gActiveBattler ] ) ;
2017-10-24 15:25:20 +02:00
LinkOpponentBufferExecCompleted ( ) ;
}
}
static void DoSwitchOutAnimation ( void )
{
2018-02-06 02:46:59 +01:00
switch ( gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState )
2017-10-24 15:25:20 +02:00
{
case 0 :
2018-02-06 23:09:39 +01:00
if ( gBattleSpritesDataPtr - > battlerData [ gActiveBattler ] . behindSubstitute )
2018-02-06 02:46:59 +01:00
InitAndLaunchSpecialAnimation ( gActiveBattler , gActiveBattler , gActiveBattler , B_ANIM_SUBSTITUTE_TO_MON ) ;
2017-10-24 15:25:20 +02:00
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState = 1 ;
2017-10-24 15:25:20 +02:00
break ;
case 1 :
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . specialAnimActive )
2017-10-24 15:25:20 +02:00
{
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState = 0 ;
InitAndLaunchSpecialAnimation ( gActiveBattler , gActiveBattler , gActiveBattler , B_ANIM_SWITCH_OUT_OPPONENT_MON ) ;
2021-01-23 03:47:00 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = FreeMonSpriteAfterSwitchOutAnim ;
2017-10-24 15:25:20 +02:00
}
break ;
}
}
2021-01-23 02:03:21 +01:00
# define sSpeedX data[0]
2017-10-24 15:25:20 +02:00
static void LinkOpponentHandleDrawTrainerPic ( void )
{
s16 xPos ;
u32 trainerPicId ;
if ( gBattleTypeFlags & BATTLE_TYPE_MULTI )
{
2018-02-06 02:46:59 +01:00
if ( ( GetBattlerPosition ( gActiveBattler ) & BIT_FLANK ) ! = 0 ) // second mon
2017-10-24 15:25:20 +02:00
xPos = 152 ;
else // first mon
xPos = 200 ;
if ( gBattleTypeFlags & BATTLE_TYPE_BATTLE_TOWER )
{
2018-02-12 00:11:10 +01:00
if ( gActiveBattler = = B_POSITION_OPPONENT_LEFT )
2017-10-24 15:25:20 +02:00
trainerPicId = GetFrontierTrainerFrontSpriteId ( gTrainerBattleOpponent_A ) ;
else
trainerPicId = GetFrontierTrainerFrontSpriteId ( gTrainerBattleOpponent_B ) ;
}
else
{
2018-02-06 20:48:02 +01:00
if ( ( gLinkPlayers [ GetBattlerMultiplayerId ( gActiveBattler ) ] . version & 0xFF ) = = VERSION_FIRE_RED
| | ( gLinkPlayers [ GetBattlerMultiplayerId ( gActiveBattler ) ] . version & 0xFF ) = = VERSION_LEAF_GREEN )
2017-10-24 15:25:20 +02:00
{
2018-02-12 00:11:10 +01:00
if ( gLinkPlayers [ GetBattlerMultiplayerId ( gActiveBattler ) ] . gender ! = MALE )
2018-12-03 04:35:11 +01:00
trainerPicId = gFacilityClassToPicIndex [ FACILITY_CLASS_LEAF ] ;
2017-10-24 15:25:20 +02:00
else
2018-12-03 04:35:11 +01:00
trainerPicId = gFacilityClassToPicIndex [ FACILITY_CLASS_RED ] ;
2017-10-24 15:25:20 +02:00
}
2018-02-06 20:48:02 +01:00
else if ( ( gLinkPlayers [ GetBattlerMultiplayerId ( gActiveBattler ) ] . version & 0xFF ) = = VERSION_RUBY
| | ( gLinkPlayers [ GetBattlerMultiplayerId ( gActiveBattler ) ] . version & 0xFF ) = = VERSION_SAPPHIRE )
2017-10-24 15:25:20 +02:00
{
2018-02-12 00:11:10 +01:00
if ( gLinkPlayers [ GetBattlerMultiplayerId ( gActiveBattler ) ] . gender ! = MALE )
2018-12-03 04:35:11 +01:00
trainerPicId = gFacilityClassToPicIndex [ FACILITY_CLASS_RS_MAY ] ;
2017-10-24 15:25:20 +02:00
else
2018-12-03 04:35:11 +01:00
trainerPicId = gFacilityClassToPicIndex [ FACILITY_CLASS_RS_BRENDAN ] ;
2017-10-24 15:25:20 +02:00
}
else
{
2018-02-06 20:48:02 +01:00
trainerPicId = PlayerGenderToFrontTrainerPicId ( gLinkPlayers [ GetBattlerMultiplayerId ( gActiveBattler ) ] . gender ) ;
2017-10-24 15:25:20 +02:00
}
}
}
else
{
xPos = 176 ;
2020-06-03 21:28:29 +02:00
if ( gTrainerBattleOpponent_A = = TRAINER_UNION_ROOM )
2017-10-24 15:25:20 +02:00
{
2020-06-03 21:28:29 +02:00
trainerPicId = GetUnionRoomTrainerPic ( ) ;
2017-10-24 15:25:20 +02:00
}
else if ( ( gLinkPlayers [ GetMultiplayerId ( ) ^ BIT_SIDE ] . version & 0xFF ) = = VERSION_FIRE_RED
| | ( gLinkPlayers [ GetMultiplayerId ( ) ^ BIT_SIDE ] . version & 0xFF ) = = VERSION_LEAF_GREEN )
{
2019-02-02 22:53:47 +01:00
if ( gLinkPlayers [ GetMultiplayerId ( ) ^ BIT_SIDE ] . gender ! = MALE )
2018-12-03 04:35:11 +01:00
trainerPicId = gFacilityClassToPicIndex [ FACILITY_CLASS_LEAF ] ;
2017-10-24 15:25:20 +02:00
else
2018-12-03 04:35:11 +01:00
trainerPicId = gFacilityClassToPicIndex [ FACILITY_CLASS_RED ] ;
2017-10-24 15:25:20 +02:00
}
else if ( ( gLinkPlayers [ GetMultiplayerId ( ) ^ BIT_SIDE ] . version & 0xFF ) = = VERSION_RUBY
| | ( gLinkPlayers [ GetMultiplayerId ( ) ^ BIT_SIDE ] . version & 0xFF ) = = VERSION_SAPPHIRE )
{
2019-02-02 22:53:47 +01:00
if ( gLinkPlayers [ GetMultiplayerId ( ) ^ BIT_SIDE ] . gender ! = MALE )
2018-12-03 04:35:11 +01:00
trainerPicId = gFacilityClassToPicIndex [ FACILITY_CLASS_RS_MAY ] ;
2017-10-24 15:25:20 +02:00
else
2018-12-03 04:35:11 +01:00
trainerPicId = gFacilityClassToPicIndex [ FACILITY_CLASS_RS_BRENDAN ] ;
2017-10-24 15:25:20 +02:00
}
else
{
trainerPicId = PlayerGenderToFrontTrainerPicId ( gLinkPlayers [ GetMultiplayerId ( ) ^ BIT_SIDE ] . gender ) ;
}
}
2018-02-06 02:46:59 +01:00
DecompressTrainerFrontPic ( trainerPicId , gActiveBattler ) ;
2018-07-01 15:28:57 +02:00
SetMultiuseSpriteTemplateToTrainerBack ( trainerPicId , GetBattlerPosition ( gActiveBattler ) ) ;
gBattlerSpriteIds [ gActiveBattler ] = CreateSprite ( & gMultiuseSpriteTemplate ,
2017-10-24 15:25:20 +02:00
xPos ,
2019-01-04 18:17:55 +01:00
( 8 - gTrainerFrontPicCoords [ trainerPicId ] . size ) * 4 + 40 ,
2018-12-18 05:08:08 +01:00
GetBattlerSpriteSubpriority ( gActiveBattler ) ) ;
2017-10-24 15:25:20 +02:00
2021-07-07 15:11:52 +02:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . x2 = - DISPLAY_WIDTH ;
2021-01-23 02:03:21 +01:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . sSpeedX = 2 ;
2018-02-06 20:48:02 +01:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . oam . paletteNum = IndexOfSpritePaletteTag ( gTrainerFrontPicPaletteTable [ trainerPicId ] . tag ) ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . oam . affineParam = trainerPicId ;
2021-01-23 02:03:21 +01:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . callback = SpriteCB_TrainerSlideIn ;
2017-10-24 15:25:20 +02:00
2018-07-01 15:28:57 +02:00
gBattlerControllerFuncs [ gActiveBattler ] = CompleteOnBattlerSpriteCallbackDummy ;
2017-10-24 15:25:20 +02:00
}
static void LinkOpponentHandleTrainerSlide ( void )
{
u32 trainerPicId ;
2018-02-06 02:46:59 +01:00
if ( gActiveBattler = = 1 )
2017-10-24 15:25:20 +02:00
trainerPicId = GetFrontierTrainerFrontSpriteId ( gTrainerBattleOpponent_A ) ;
else
trainerPicId = GetFrontierTrainerFrontSpriteId ( gTrainerBattleOpponent_B ) ;
2018-02-06 02:46:59 +01:00
DecompressTrainerFrontPic ( trainerPicId , gActiveBattler ) ;
2018-07-01 15:28:57 +02:00
SetMultiuseSpriteTemplateToTrainerBack ( trainerPicId , GetBattlerPosition ( gActiveBattler ) ) ;
2019-01-04 18:17:55 +01:00
gBattlerSpriteIds [ gActiveBattler ] = CreateSprite ( & gMultiuseSpriteTemplate , 176 , ( 8 - gTrainerFrontPicCoords [ trainerPicId ] . size ) * 4 + 40 , 0x1E ) ;
2017-10-24 15:25:20 +02:00
2021-07-07 15:11:52 +02:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . x2 = 96 ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . x + = 32 ;
2021-01-23 02:03:21 +01:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . sSpeedX = - 2 ;
2018-02-06 20:48:02 +01:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . oam . paletteNum = IndexOfSpritePaletteTag ( gTrainerFrontPicPaletteTable [ trainerPicId ] . tag ) ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . oam . affineParam = trainerPicId ;
2021-01-23 02:03:21 +01:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . callback = SpriteCB_TrainerSlideIn ;
2017-10-24 15:25:20 +02:00
2018-03-01 00:59:52 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = CompleteOnBankSpriteCallbackDummy2 ; // this line is redundant, because LinkOpponentBufferExecCompleted changes the battle battlerId function
2017-10-24 15:25:20 +02:00
LinkOpponentBufferExecCompleted ( ) ;
}
2021-01-23 02:03:21 +01:00
# undef sSpeedX
2017-10-24 15:25:20 +02:00
static void LinkOpponentHandleTrainerSlideBack ( void )
{
2019-02-06 20:17:09 +01:00
SetSpritePrimaryCoordsFromSecondaryCoords ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] ) ;
2018-02-06 20:48:02 +01:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . data [ 0 ] = 35 ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . data [ 2 ] = 280 ;
2021-07-07 15:11:52 +02:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . data [ 4 ] = gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . y ;
2018-11-26 00:00:18 +01:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . callback = StartAnimLinearTranslation ;
2018-02-06 20:48:02 +01:00
StoreSpriteCallbackInData6 ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] , SpriteCallbackDummy ) ;
2021-01-23 03:47:00 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = FreeTrainerSpriteAfterSlide ;
2017-10-24 15:25:20 +02:00
}
static void LinkOpponentHandleFaintAnimation ( void )
{
2018-02-06 02:46:59 +01:00
if ( gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState = = 0 )
2017-10-24 15:25:20 +02:00
{
2018-02-06 23:09:39 +01:00
if ( gBattleSpritesDataPtr - > battlerData [ gActiveBattler ] . behindSubstitute )
2018-02-06 02:46:59 +01:00
InitAndLaunchSpecialAnimation ( gActiveBattler , gActiveBattler , gActiveBattler , B_ANIM_SUBSTITUTE_TO_MON ) ;
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState + + ;
2017-10-24 15:25:20 +02:00
}
else
{
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . specialAnimActive )
2017-10-24 15:25:20 +02:00
{
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState = 0 ;
2020-08-21 00:02:00 +02:00
PlaySE12WithPanning ( SE_FAINT , SOUND_PAN_TARGET ) ;
2018-06-20 23:07:51 +02:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . callback = SpriteCB_FaintOpponentMon ;
2021-01-23 03:47:00 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = HideHealthboxAfterMonFaint ;
2017-10-24 15:25:20 +02:00
}
}
}
static void LinkOpponentHandlePaletteFade ( void )
{
LinkOpponentBufferExecCompleted ( ) ;
}
static void LinkOpponentHandleSuccessBallThrowAnim ( void )
{
LinkOpponentBufferExecCompleted ( ) ;
}
static void LinkOpponentHandleBallThrowAnim ( void )
{
LinkOpponentBufferExecCompleted ( ) ;
}
static void LinkOpponentHandlePause ( void )
{
LinkOpponentBufferExecCompleted ( ) ;
}
static void LinkOpponentHandleMoveAnimation ( void )
{
2021-01-23 02:03:21 +01:00
if ( ! IsBattleSEPlaying ( gActiveBattler ) )
2017-10-24 15:25:20 +02:00
{
2019-01-05 16:00:57 +01:00
u16 move = gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] | ( gBattleResources - > bufferA [ gActiveBattler ] [ 2 ] < < 8 ) ;
gAnimMoveTurn = gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ;
gAnimMovePower = gBattleResources - > bufferA [ gActiveBattler ] [ 4 ] | ( gBattleResources - > bufferA [ gActiveBattler ] [ 5 ] < < 8 ) ;
gAnimMoveDmg = gBattleResources - > bufferA [ gActiveBattler ] [ 6 ] | ( gBattleResources - > bufferA [ gActiveBattler ] [ 7 ] < < 8 ) | ( gBattleResources - > bufferA [ gActiveBattler ] [ 8 ] < < 16 ) | ( gBattleResources - > bufferA [ gActiveBattler ] [ 9 ] < < 24 ) ;
gAnimFriendship = gBattleResources - > bufferA [ gActiveBattler ] [ 10 ] ;
gWeatherMoveAnim = gBattleResources - > bufferA [ gActiveBattler ] [ 12 ] | ( gBattleResources - > bufferA [ gActiveBattler ] [ 13 ] < < 8 ) ;
gAnimDisableStructPtr = ( struct DisableStruct * ) & gBattleResources - > bufferA [ gActiveBattler ] [ 16 ] ;
2018-02-06 02:46:59 +01:00
gTransformedPersonalities [ gActiveBattler ] = gAnimDisableStructPtr - > transformedMonPersonality ;
2022-06-03 16:24:57 +02:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState = 0 ;
gBattlerControllerFuncs [ gActiveBattler ] = LinkOpponentDoMoveAnimation ;
BattleTv_SetDataBasedOnMove ( move , gWeatherMoveAnim , gAnimDisableStructPtr ) ;
2017-10-24 15:25:20 +02:00
}
}
static void LinkOpponentDoMoveAnimation ( void )
{
2019-01-05 16:00:57 +01:00
u16 move = gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] | ( gBattleResources - > bufferA [ gActiveBattler ] [ 2 ] < < 8 ) ;
u8 multihit = gBattleResources - > bufferA [ gActiveBattler ] [ 11 ] ;
2017-10-24 15:25:20 +02:00
2018-02-06 02:46:59 +01:00
switch ( gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState )
2017-10-24 15:25:20 +02:00
{
case 0 :
2018-02-06 23:09:39 +01:00
if ( gBattleSpritesDataPtr - > battlerData [ gActiveBattler ] . behindSubstitute
& & ! gBattleSpritesDataPtr - > battlerData [ gActiveBattler ] . flag_x8 )
2017-10-24 15:25:20 +02:00
{
2018-02-06 23:09:39 +01:00
gBattleSpritesDataPtr - > battlerData [ gActiveBattler ] . flag_x8 = 1 ;
2018-02-06 02:46:59 +01:00
InitAndLaunchSpecialAnimation ( gActiveBattler , gActiveBattler , gActiveBattler , B_ANIM_SUBSTITUTE_TO_MON ) ;
2017-10-24 15:25:20 +02:00
}
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState = 1 ;
2017-10-24 15:25:20 +02:00
break ;
case 1 :
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . specialAnimActive )
2017-10-24 15:25:20 +02:00
{
2021-01-23 02:03:21 +01:00
SetBattlerSpriteAffineMode ( ST_OAM_AFFINE_OFF ) ;
2017-10-24 15:25:20 +02:00
DoMoveAnim ( move ) ;
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState = 2 ;
2017-10-24 15:25:20 +02:00
}
break ;
case 2 :
gAnimScriptCallback ( ) ;
if ( ! gAnimScriptActive )
{
2021-01-23 02:03:21 +01:00
SetBattlerSpriteAffineMode ( ST_OAM_AFFINE_NORMAL ) ;
2018-02-06 23:09:39 +01:00
if ( gBattleSpritesDataPtr - > battlerData [ gActiveBattler ] . behindSubstitute & & multihit < 2 )
2017-10-24 15:25:20 +02:00
{
2018-02-06 02:46:59 +01:00
InitAndLaunchSpecialAnimation ( gActiveBattler , gActiveBattler , gActiveBattler , B_ANIM_MON_TO_SUBSTITUTE ) ;
2018-02-06 23:09:39 +01:00
gBattleSpritesDataPtr - > battlerData [ gActiveBattler ] . flag_x8 = 0 ;
2017-10-24 15:25:20 +02:00
}
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState = 3 ;
2017-10-24 15:25:20 +02:00
}
break ;
case 3 :
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . specialAnimActive )
2017-10-24 15:25:20 +02:00
{
2017-11-04 16:11:13 +01:00
CopyAllBattleSpritesInvisibilities ( ) ;
2019-01-05 16:00:57 +01:00
TrySetBehindSubstituteSpriteBit ( gActiveBattler , gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] | ( gBattleResources - > bufferA [ gActiveBattler ] [ 2 ] < < 8 ) ) ;
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState = 0 ;
2017-10-24 15:25:20 +02:00
LinkOpponentBufferExecCompleted ( ) ;
}
break ;
}
}
static void LinkOpponentHandlePrintString ( void )
{
u16 * stringId ;
gBattle_BG0_X = 0 ;
gBattle_BG0_Y = 0 ;
2022-08-23 02:30:45 +02:00
stringId = ( u16 * ) ( & gBattleResources - > bufferA [ gActiveBattler ] [ 2 ] ) ;
2017-10-24 15:25:20 +02:00
BufferStringBattle ( * stringId ) ;
2021-10-08 22:50:52 +02:00
BattlePutTextOnWindow ( gDisplayedStringBattle , B_WIN_MSG ) ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = CompleteOnInactiveTextPrinter ;
2018-02-27 20:40:09 +01:00
BattleTv_SetDataBasedOnString ( * stringId ) ;
2017-10-24 15:25:20 +02:00
}
2017-11-25 18:42:31 +01:00
static void LinkOpponentHandlePrintSelectionString ( void )
2017-10-24 15:25:20 +02:00
{
LinkOpponentBufferExecCompleted ( ) ;
}
static void LinkOpponentHandleChooseAction ( void )
{
LinkOpponentBufferExecCompleted ( ) ;
}
2021-01-22 08:48:22 +01:00
static void LinkOpponentHandleYesNoBox ( void )
2017-10-24 15:25:20 +02:00
{
LinkOpponentBufferExecCompleted ( ) ;
}
static void LinkOpponentHandleChooseMove ( void )
{
LinkOpponentBufferExecCompleted ( ) ;
}
static void LinkOpponentHandleChooseItem ( void )
{
LinkOpponentBufferExecCompleted ( ) ;
}
static void LinkOpponentHandleChoosePokemon ( void )
{
LinkOpponentBufferExecCompleted ( ) ;
}
static void LinkOpponentHandleCmd23 ( void )
{
LinkOpponentBufferExecCompleted ( ) ;
}
static void LinkOpponentHandleHealthBarUpdate ( void )
{
s16 hpVal ;
LoadBattleBarGfx ( 0 ) ;
2019-01-05 16:00:57 +01:00
hpVal = gBattleResources - > bufferA [ gActiveBattler ] [ 2 ] | ( gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] < < 8 ) ;
2017-10-24 15:25:20 +02:00
if ( hpVal ! = INSTANT_HP_BAR_DROP )
{
2018-02-06 20:48:02 +01:00
u32 maxHP = GetMonData ( & gEnemyParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , MON_DATA_MAX_HP ) ;
u32 curHP = GetMonData ( & gEnemyParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , MON_DATA_HP ) ;
2017-10-24 15:25:20 +02:00
2018-02-06 20:48:02 +01:00
SetBattleBarStruct ( gActiveBattler , gHealthboxSpriteIds [ gActiveBattler ] , maxHP , curHP , hpVal ) ;
2017-10-24 15:25:20 +02:00
}
else
{
2018-02-06 20:48:02 +01:00
u32 maxHP = GetMonData ( & gEnemyParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , MON_DATA_MAX_HP ) ;
2017-10-24 15:25:20 +02:00
2018-02-06 20:48:02 +01:00
SetBattleBarStruct ( gActiveBattler , gHealthboxSpriteIds [ gActiveBattler ] , maxHP , 0 , hpVal ) ;
2017-10-24 15:25:20 +02:00
}
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = CompleteOnHealthbarDone ;
2017-10-24 15:25:20 +02:00
}
static void LinkOpponentHandleExpUpdate ( void )
{
LinkOpponentBufferExecCompleted ( ) ;
}
static void LinkOpponentHandleStatusIconUpdate ( void )
{
2021-01-23 02:03:21 +01:00
if ( ! IsBattleSEPlaying ( gActiveBattler ) )
2017-10-24 15:25:20 +02:00
{
2018-03-01 00:59:52 +01:00
u8 battlerId ;
2017-10-24 15:25:20 +02:00
2018-02-06 20:48:02 +01:00
UpdateHealthboxAttribute ( gHealthboxSpriteIds [ gActiveBattler ] , & gEnemyParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , HEALTHBOX_STATUS_ICON ) ;
2018-03-01 00:59:52 +01:00
battlerId = gActiveBattler ;
gBattleSpritesDataPtr - > healthBoxesData [ battlerId ] . statusAnimActive = 0 ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = CompleteOnFinishedStatusAnimation ;
2017-10-24 15:25:20 +02:00
}
}
static void LinkOpponentHandleStatusAnimation ( void )
{
2021-01-23 02:03:21 +01:00
if ( ! IsBattleSEPlaying ( gActiveBattler ) )
2017-10-24 15:25:20 +02:00
{
2019-01-05 16:00:57 +01:00
InitAndLaunchChosenStatusAnimation ( gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] ,
gBattleResources - > bufferA [ gActiveBattler ] [ 2 ] | ( gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] < < 8 ) | ( gBattleResources - > bufferA [ gActiveBattler ] [ 4 ] < < 16 ) | ( gBattleResources - > bufferA [ gActiveBattler ] [ 5 ] < < 24 ) ) ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = CompleteOnFinishedStatusAnimation ;
2017-10-24 15:25:20 +02:00
}
}
static void LinkOpponentHandleStatusXor ( void )
{
LinkOpponentBufferExecCompleted ( ) ;
}
static void LinkOpponentHandleDataTransfer ( void )
{
LinkOpponentBufferExecCompleted ( ) ;
}
static void LinkOpponentHandleDMA3Transfer ( void )
{
LinkOpponentBufferExecCompleted ( ) ;
}
static void LinkOpponentHandlePlayBGM ( void )
{
LinkOpponentBufferExecCompleted ( ) ;
}
static void LinkOpponentHandleCmd32 ( void )
{
LinkOpponentBufferExecCompleted ( ) ;
}
static void LinkOpponentHandleTwoReturnValues ( void )
{
LinkOpponentBufferExecCompleted ( ) ;
}
static void LinkOpponentHandleChosenMonReturnValue ( void )
{
LinkOpponentBufferExecCompleted ( ) ;
}
static void LinkOpponentHandleOneReturnValue ( void )
{
LinkOpponentBufferExecCompleted ( ) ;
}
static void LinkOpponentHandleOneReturnValue_Duplicate ( void )
{
LinkOpponentBufferExecCompleted ( ) ;
}
2020-12-29 22:51:44 +01:00
static void LinkOpponentHandleClearUnkVar ( void )
2017-10-24 15:25:20 +02:00
{
2020-12-29 22:51:44 +01:00
gUnusedControllerStruct . unk = 0 ;
2017-10-24 15:25:20 +02:00
LinkOpponentBufferExecCompleted ( ) ;
}
2020-12-29 22:51:44 +01:00
static void LinkOpponentHandleSetUnkVar ( void )
2017-10-24 15:25:20 +02:00
{
2021-01-29 07:45:58 +01:00
gUnusedControllerStruct . unk = gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] ;
2017-10-24 15:25:20 +02:00
LinkOpponentBufferExecCompleted ( ) ;
}
2020-12-29 22:51:44 +01:00
static void LinkOpponentHandleClearUnkFlag ( void )
2017-10-24 15:25:20 +02:00
{
2020-12-29 22:51:44 +01:00
gUnusedControllerStruct . flag = 0 ;
2017-10-24 15:25:20 +02:00
LinkOpponentBufferExecCompleted ( ) ;
}
2020-12-29 22:51:44 +01:00
static void LinkOpponentHandleToggleUnkFlag ( void )
2017-10-24 15:25:20 +02:00
{
2020-12-29 22:51:44 +01:00
gUnusedControllerStruct . flag ^ = 1 ;
2017-10-24 15:25:20 +02:00
LinkOpponentBufferExecCompleted ( ) ;
}
static void LinkOpponentHandleHitAnimation ( void )
{
2018-02-06 20:48:02 +01:00
if ( gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . invisible = = TRUE )
2017-10-24 15:25:20 +02:00
{
LinkOpponentBufferExecCompleted ( ) ;
}
else
{
gDoingBattleAnim = TRUE ;
2018-02-06 20:48:02 +01:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . data [ 1 ] = 0 ;
2018-02-06 02:46:59 +01:00
DoHitAnimHealthboxEffect ( gActiveBattler ) ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = DoHitAnimBlinkSpriteEffect ;
2017-10-24 15:25:20 +02:00
}
}
2021-04-03 18:38:07 +02:00
static void LinkOpponentHandleCantSwitch ( void )
2017-10-24 15:25:20 +02:00
{
LinkOpponentBufferExecCompleted ( ) ;
}
2017-11-25 18:42:31 +01:00
static void LinkOpponentHandlePlaySE ( void )
2017-10-24 15:25:20 +02:00
{
s8 pan ;
2018-02-06 02:46:59 +01:00
if ( GetBattlerSide ( gActiveBattler ) = = B_SIDE_PLAYER )
2018-10-19 21:57:19 +02:00
pan = SOUND_PAN_ATTACKER ;
2017-10-24 15:25:20 +02:00
else
2018-10-19 21:57:19 +02:00
pan = SOUND_PAN_TARGET ;
2017-10-24 15:25:20 +02:00
2019-01-05 16:00:57 +01:00
PlaySE12WithPanning ( gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] | ( gBattleResources - > bufferA [ gActiveBattler ] [ 2 ] < < 8 ) , pan ) ;
2017-10-24 15:25:20 +02:00
LinkOpponentBufferExecCompleted ( ) ;
}
static void LinkOpponentHandlePlayFanfareOrBGM ( void )
{
2019-01-05 16:00:57 +01:00
if ( gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] )
2017-10-24 15:25:20 +02:00
{
2017-11-04 16:11:13 +01:00
BattleStopLowHpSound ( ) ;
2019-01-05 16:00:57 +01:00
PlayBGM ( gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] | ( gBattleResources - > bufferA [ gActiveBattler ] [ 2 ] < < 8 ) ) ;
2017-10-24 15:25:20 +02:00
}
else
{
2019-01-05 16:00:57 +01:00
PlayFanfare ( gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] | ( gBattleResources - > bufferA [ gActiveBattler ] [ 2 ] < < 8 ) ) ;
2017-10-24 15:25:20 +02:00
}
LinkOpponentBufferExecCompleted ( ) ;
}
static void LinkOpponentHandleFaintingCry ( void )
{
2018-02-06 20:48:02 +01:00
u16 species = GetMonData ( & gEnemyParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , MON_DATA_SPECIES ) ;
2017-10-24 15:25:20 +02:00
2021-11-07 19:54:44 +01:00
PlayCry_ByMode ( species , 25 , CRY_MODE_FAINT ) ;
2017-10-24 15:25:20 +02:00
LinkOpponentBufferExecCompleted ( ) ;
}
static void LinkOpponentHandleIntroSlide ( void )
{
2019-01-05 16:00:57 +01:00
HandleIntroSlide ( gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] ) ;
2018-02-08 11:17:41 +01:00
gIntroSlideFlags | = 1 ;
2017-10-24 15:25:20 +02:00
LinkOpponentBufferExecCompleted ( ) ;
}
static void LinkOpponentHandleIntroTrainerBallThrow ( void )
{
u8 taskId ;
2019-02-06 20:17:09 +01:00
SetSpritePrimaryCoordsFromSecondaryCoords ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] ) ;
2017-10-24 15:25:20 +02:00
2018-02-06 20:48:02 +01:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . data [ 0 ] = 35 ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . data [ 2 ] = 280 ;
2021-07-07 15:11:52 +02:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . data [ 4 ] = gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . y ;
2018-11-26 00:00:18 +01:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . callback = StartAnimLinearTranslation ;
2017-10-24 15:25:20 +02:00
2021-01-23 03:47:00 +01:00
StoreSpriteCallbackInData6 ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] , SpriteCB_FreeOpponentSprite ) ;
2017-10-24 15:25:20 +02:00
2021-01-23 03:47:00 +01:00
taskId = CreateTask ( Task_StartSendOutAnim , 5 ) ;
2018-02-06 02:46:59 +01:00
gTasks [ taskId ] . data [ 0 ] = gActiveBattler ;
2017-10-24 15:25:20 +02:00
2018-06-28 21:06:32 +02:00
if ( gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . partyStatusSummaryShown )
gTasks [ gBattlerStatusSummaryTaskId [ gActiveBattler ] ] . func = Task_HidePartyStatusSummary ;
2017-10-24 15:25:20 +02:00
2021-01-23 02:03:21 +01:00
gBattleSpritesDataPtr - > animationData - > introAnimActive = TRUE ;
2021-01-23 03:47:00 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = LinkOpponentDummy ;
2017-10-24 15:25:20 +02:00
}
2021-01-23 03:47:00 +01:00
static void Task_StartSendOutAnim ( u8 taskId )
2017-10-24 15:25:20 +02:00
{
2018-02-06 02:46:59 +01:00
u8 savedActiveBank = gActiveBattler ;
2017-10-24 15:25:20 +02:00
2018-02-06 02:46:59 +01:00
gActiveBattler = gTasks [ taskId ] . data [ 0 ] ;
2017-10-24 15:25:20 +02:00
if ( ! IsDoubleBattle ( ) | | ( gBattleTypeFlags & BATTLE_TYPE_MULTI ) )
{
2019-01-05 16:00:57 +01:00
gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] = gBattlerPartyIndexes [ gActiveBattler ] ;
2021-01-23 03:47:00 +01:00
StartSendOutAnim ( gActiveBattler , FALSE ) ;
2017-10-24 15:25:20 +02:00
}
else
{
2019-01-05 16:00:57 +01:00
gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] = gBattlerPartyIndexes [ gActiveBattler ] ;
2021-01-23 03:47:00 +01:00
StartSendOutAnim ( gActiveBattler , FALSE ) ;
2018-02-06 23:09:39 +01:00
gActiveBattler = BATTLE_PARTNER ( gActiveBattler ) ;
2019-01-05 16:00:57 +01:00
gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] = gBattlerPartyIndexes [ gActiveBattler ] ;
2021-01-23 03:47:00 +01:00
StartSendOutAnim ( gActiveBattler , FALSE ) ;
2018-02-06 23:09:39 +01:00
gActiveBattler = BATTLE_PARTNER ( gActiveBattler ) ;
2017-10-24 15:25:20 +02:00
}
2021-01-23 03:47:00 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = Intro_TryShinyAnimShowHealthbox ;
2018-02-06 02:46:59 +01:00
gActiveBattler = savedActiveBank ;
2017-10-24 15:25:20 +02:00
DestroyTask ( taskId ) ;
}
2021-01-23 03:47:00 +01:00
static void SpriteCB_FreeOpponentSprite ( struct Sprite * sprite )
2017-10-24 15:25:20 +02:00
{
FreeTrainerFrontPicPalette ( sprite - > oam . affineParam ) ;
FreeSpriteOamMatrix ( sprite ) ;
DestroySprite ( sprite ) ;
}
static void LinkOpponentHandleDrawPartyStatusSummary ( void )
{
2019-01-05 16:00:57 +01:00
if ( gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] ! = 0 & & GetBattlerSide ( gActiveBattler ) = = B_SIDE_PLAYER )
2017-10-24 15:25:20 +02:00
{
LinkOpponentBufferExecCompleted ( ) ;
}
else
{
2018-06-28 21:06:32 +02:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . partyStatusSummaryShown = 1 ;
2017-10-24 15:25:20 +02:00
2019-01-05 16:00:57 +01:00
if ( gBattleResources - > bufferA [ gActiveBattler ] [ 2 ] ! = 0 )
2017-10-24 15:25:20 +02:00
{
2022-08-18 20:23:45 +02:00
if ( gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . opponentDrawPartyStatusSummaryDelay < 2 )
2017-10-24 15:25:20 +02:00
{
2022-08-18 20:23:45 +02:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . opponentDrawPartyStatusSummaryDelay + + ;
2017-10-24 15:25:20 +02:00
return ;
}
else
{
2022-08-18 20:23:45 +02:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . opponentDrawPartyStatusSummaryDelay = 0 ;
2017-10-24 15:25:20 +02:00
}
}
2019-01-05 16:00:57 +01:00
gBattlerStatusSummaryTaskId [ gActiveBattler ] = CreatePartyStatusSummarySprites ( gActiveBattler , ( struct HpAndStatus * ) & gBattleResources - > bufferA [ gActiveBattler ] [ 4 ] , gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] , gBattleResources - > bufferA [ gActiveBattler ] [ 2 ] ) ;
2021-01-23 02:03:21 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . partyStatusDelayTimer = 0 ;
2017-10-24 15:25:20 +02:00
2019-01-05 16:00:57 +01:00
if ( gBattleResources - > bufferA [ gActiveBattler ] [ 2 ] ! = 0 )
2021-01-23 02:03:21 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . partyStatusDelayTimer = 93 ;
2017-10-24 15:25:20 +02:00
2021-01-23 02:03:21 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = EndDrawPartyStatusSummary ;
2017-10-24 15:25:20 +02:00
}
}
2021-01-23 02:03:21 +01:00
static void EndDrawPartyStatusSummary ( void )
2017-10-24 15:25:20 +02:00
{
2021-01-23 02:03:21 +01:00
if ( gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . partyStatusDelayTimer + + > 92 )
2017-10-24 15:25:20 +02:00
{
2021-01-23 02:03:21 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . partyStatusDelayTimer = 0 ;
2017-10-24 15:25:20 +02:00
LinkOpponentBufferExecCompleted ( ) ;
}
}
2018-06-28 21:06:32 +02:00
static void LinkOpponentHandleHidePartyStatusSummary ( void )
2017-10-24 15:25:20 +02:00
{
2018-06-28 21:06:32 +02:00
if ( gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . partyStatusSummaryShown )
gTasks [ gBattlerStatusSummaryTaskId [ gActiveBattler ] ] . func = Task_HidePartyStatusSummary ;
2017-10-24 15:25:20 +02:00
LinkOpponentBufferExecCompleted ( ) ;
}
2018-06-20 23:07:51 +02:00
static void LinkOpponentHandleEndBounceEffect ( void )
2017-10-24 15:25:20 +02:00
{
LinkOpponentBufferExecCompleted ( ) ;
}
static void LinkOpponentHandleSpriteInvisibility ( void )
{
2018-02-06 20:48:02 +01:00
if ( IsBattlerSpritePresent ( gActiveBattler ) )
2017-10-24 15:25:20 +02:00
{
2019-01-05 16:00:57 +01:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . invisible = gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] ;
2018-02-06 02:46:59 +01:00
CopyBattleSpriteInvisibility ( gActiveBattler ) ;
2017-10-24 15:25:20 +02:00
}
LinkOpponentBufferExecCompleted ( ) ;
}
static void LinkOpponentHandleBattleAnimation ( void )
{
2021-01-23 02:03:21 +01:00
if ( ! IsBattleSEPlaying ( gActiveBattler ) )
2017-10-24 15:25:20 +02:00
{
2019-01-05 16:00:57 +01:00
u8 animationId = gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] ;
u16 argument = gBattleResources - > bufferA [ gActiveBattler ] [ 2 ] | ( gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] < < 8 ) ;
2017-10-24 15:25:20 +02:00
2018-02-06 02:46:59 +01:00
if ( TryHandleLaunchBattleTableAnimation ( gActiveBattler , gActiveBattler , gActiveBattler , animationId , argument ) )
2017-10-24 15:25:20 +02:00
LinkOpponentBufferExecCompleted ( ) ;
else
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = CompleteOnFinishedBattleAnimation ;
2017-10-24 15:25:20 +02:00
2018-02-27 20:40:09 +01:00
BattleTv_SetDataBasedOnAnimation ( animationId ) ;
2017-10-24 15:25:20 +02:00
}
}
static void LinkOpponentHandleLinkStandbyMsg ( void )
{
2021-03-23 07:08:19 +01:00
RecordedBattle_RecordAllBattlerData ( & gBattleResources - > bufferA [ gActiveBattler ] [ 2 ] ) ;
2017-10-24 15:25:20 +02:00
LinkOpponentBufferExecCompleted ( ) ;
}
static void LinkOpponentHandleResetActionMoveSelection ( void )
{
LinkOpponentBufferExecCompleted ( ) ;
}
2021-01-22 08:48:22 +01:00
static void LinkOpponentHandleEndLinkBattle ( void )
2017-10-24 15:25:20 +02:00
{
2021-03-23 07:08:19 +01:00
RecordedBattle_RecordAllBattlerData ( & gBattleResources - > bufferA [ gActiveBattler ] [ 4 ] ) ;
2017-10-24 15:25:20 +02:00
2019-01-05 16:00:57 +01:00
if ( gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] = = B_OUTCOME_DREW )
gBattleOutcome = gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] ;
2017-10-24 15:25:20 +02:00
else
2019-01-05 16:00:57 +01:00
gBattleOutcome = gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] ^ B_OUTCOME_DREW ;
2017-10-24 15:25:20 +02:00
2019-12-30 18:52:23 +01:00
gSaveBlock2Ptr - > frontier . disableRecordBattle = gBattleResources - > bufferA [ gActiveBattler ] [ 2 ] ;
2017-10-24 15:25:20 +02:00
FadeOutMapMusic ( 5 ) ;
BeginFastPaletteFade ( 3 ) ;
LinkOpponentBufferExecCompleted ( ) ;
2021-01-23 02:03:21 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = SetBattleEndCallbacks ;
2017-10-24 15:25:20 +02:00
}
2018-09-18 21:51:10 +02:00
static void LinkOpponentHandleBattleDebug ( void )
{
LinkOpponentBufferExecCompleted ( ) ;
}
2019-03-05 20:07:59 +01:00
static void LinkOpponentCmdEnd ( void )
2017-10-24 15:25:20 +02:00
{
}