2017-10-22 20:49:21 +02:00
# include "global.h"
# include "battle.h"
2018-11-14 01:01:50 +01:00
# include "battle_ai_script_commands.h"
# include "battle_anim.h"
2017-10-22 20:49:21 +02:00
# include "battle_controllers.h"
# include "battle_message.h"
# include "battle_interface.h"
2018-11-14 01:01:50 +01:00
# include "battle_setup.h"
2018-12-03 16:20:39 +01:00
# include "battle_tower.h"
2018-11-14 01:01:50 +01:00
# include "bg.h"
2019-04-04 23:53:06 +02:00
# include "data.h"
2018-11-14 01:01:50 +01:00
# include "item_use.h"
2017-10-22 20:49:21 +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"
# include "reshow_battle_screen.h"
# include "sound.h"
# include "string_util.h"
2017-10-22 20:49:21 +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"
2017-10-22 20:49:21 +02:00
// this file's functions
2017-10-23 11:07:36 +02:00
static void PlayerPartnerHandleGetMonData ( void ) ;
static void PlayerPartnerHandleGetRawMonData ( void ) ;
static void PlayerPartnerHandleSetMonData ( void ) ;
static void PlayerPartnerHandleSetRawMonData ( void ) ;
static void PlayerPartnerHandleLoadMonSprite ( void ) ;
static void PlayerPartnerHandleSwitchInAnim ( void ) ;
static void PlayerPartnerHandleReturnMonToBall ( void ) ;
static void PlayerPartnerHandleDrawTrainerPic ( void ) ;
static void PlayerPartnerHandleTrainerSlide ( void ) ;
static void PlayerPartnerHandleTrainerSlideBack ( void ) ;
static void PlayerPartnerHandleFaintAnimation ( void ) ;
static void PlayerPartnerHandlePaletteFade ( void ) ;
static void PlayerPartnerHandleSuccessBallThrowAnim ( void ) ;
static void PlayerPartnerHandleBallThrowAnim ( void ) ;
static void PlayerPartnerHandlePause ( void ) ;
static void PlayerPartnerHandleMoveAnimation ( void ) ;
static void PlayerPartnerHandlePrintString ( void ) ;
2017-11-25 18:42:31 +01:00
static void PlayerPartnerHandlePrintSelectionString ( void ) ;
2017-10-23 11:07:36 +02:00
static void PlayerPartnerHandleChooseAction ( void ) ;
static void PlayerPartnerHandleUnknownYesNoBox ( void ) ;
static void PlayerPartnerHandleChooseMove ( void ) ;
static void PlayerPartnerHandleChooseItem ( void ) ;
static void PlayerPartnerHandleChoosePokemon ( void ) ;
static void PlayerPartnerHandleCmd23 ( void ) ;
static void PlayerPartnerHandleHealthBarUpdate ( void ) ;
static void PlayerPartnerHandleExpUpdate ( void ) ;
static void PlayerPartnerHandleStatusIconUpdate ( void ) ;
static void PlayerPartnerHandleStatusAnimation ( void ) ;
static void PlayerPartnerHandleStatusXor ( void ) ;
static void PlayerPartnerHandleDataTransfer ( void ) ;
static void PlayerPartnerHandleDMA3Transfer ( void ) ;
static void PlayerPartnerHandlePlayBGM ( void ) ;
static void PlayerPartnerHandleCmd32 ( void ) ;
static void PlayerPartnerHandleTwoReturnValues ( void ) ;
static void PlayerPartnerHandleChosenMonReturnValue ( void ) ;
static void PlayerPartnerHandleOneReturnValue ( void ) ;
static void PlayerPartnerHandleOneReturnValue_Duplicate ( void ) ;
static void PlayerPartnerHandleCmd37 ( void ) ;
static void PlayerPartnerHandleCmd38 ( void ) ;
static void PlayerPartnerHandleCmd39 ( void ) ;
static void PlayerPartnerHandleCmd40 ( void ) ;
static void PlayerPartnerHandleHitAnimation ( void ) ;
static void PlayerPartnerHandleCmd42 ( void ) ;
2017-11-25 18:42:31 +01:00
static void PlayerPartnerHandlePlaySE ( void ) ;
2017-10-23 11:07:36 +02:00
static void PlayerPartnerHandlePlayFanfareOrBGM ( void ) ;
static void PlayerPartnerHandleFaintingCry ( void ) ;
static void PlayerPartnerHandleIntroSlide ( void ) ;
static void PlayerPartnerHandleIntroTrainerBallThrow ( void ) ;
static void PlayerPartnerHandleDrawPartyStatusSummary ( void ) ;
2018-06-28 21:06:32 +02:00
static void PlayerPartnerHandleHidePartyStatusSummary ( void ) ;
2018-06-20 23:07:51 +02:00
static void PlayerPartnerHandleEndBounceEffect ( void ) ;
2017-10-23 11:07:36 +02:00
static void PlayerPartnerHandleSpriteInvisibility ( void ) ;
static void PlayerPartnerHandleBattleAnimation ( void ) ;
static void PlayerPartnerHandleLinkStandbyMsg ( void ) ;
static void PlayerPartnerHandleResetActionMoveSelection ( void ) ;
static void PlayerPartnerHandleCmd55 ( void ) ;
2018-09-18 21:51:10 +02:00
static void PlayerPartnerHandleBattleDebug ( void ) ;
2019-03-05 20:07:59 +01:00
static void PlayerPartnerCmdEnd ( void ) ;
2017-10-23 11:07:36 +02:00
static void PlayerPartnerBufferRunCommand ( void ) ;
static void PlayerPartnerBufferExecCompleted ( void ) ;
static void sub_81BB628 ( u8 taskId ) ;
static void DestroyExpTaskAndCompleteOnInactiveTextPrinter ( u8 taskId ) ;
static void Task_PrepareToGiveExpWithExpBar ( u8 taskId ) ;
static void sub_81BB4E4 ( u8 taskId ) ;
static void sub_81BB628 ( u8 taskId ) ;
static void sub_81BB688 ( u8 taskId ) ;
static void sub_81BB9A0 ( void ) ;
static u32 CopyPlayerPartnerMonData ( u8 monId , u8 * dst ) ;
static void SetPlayerPartnerMonData ( u8 monId ) ;
2018-03-01 00:59:52 +01:00
static void sub_81BD0E4 ( u8 battlerId , bool8 dontClearSubstituteBit ) ;
2017-10-23 11:07:36 +02:00
static void DoSwitchOutAnimation ( void ) ;
static void PlayerPartnerDoMoveAnimation ( void ) ;
static void sub_81BE2C8 ( u8 taskId ) ;
static void sub_81BE498 ( void ) ;
2017-10-31 18:04:08 +01:00
static void ( * const sPlayerPartnerBufferCommands [ CONTROLLER_CMDS_COUNT ] ) ( void ) =
2017-10-22 20:49:21 +02:00
{
PlayerPartnerHandleGetMonData ,
PlayerPartnerHandleGetRawMonData ,
PlayerPartnerHandleSetMonData ,
PlayerPartnerHandleSetRawMonData ,
PlayerPartnerHandleLoadMonSprite ,
PlayerPartnerHandleSwitchInAnim ,
PlayerPartnerHandleReturnMonToBall ,
PlayerPartnerHandleDrawTrainerPic ,
PlayerPartnerHandleTrainerSlide ,
PlayerPartnerHandleTrainerSlideBack ,
PlayerPartnerHandleFaintAnimation ,
PlayerPartnerHandlePaletteFade ,
PlayerPartnerHandleSuccessBallThrowAnim ,
PlayerPartnerHandleBallThrowAnim ,
PlayerPartnerHandlePause ,
PlayerPartnerHandleMoveAnimation ,
PlayerPartnerHandlePrintString ,
2017-11-25 18:42:31 +01:00
PlayerPartnerHandlePrintSelectionString ,
2017-10-22 20:49:21 +02:00
PlayerPartnerHandleChooseAction ,
PlayerPartnerHandleUnknownYesNoBox ,
PlayerPartnerHandleChooseMove ,
PlayerPartnerHandleChooseItem ,
PlayerPartnerHandleChoosePokemon ,
PlayerPartnerHandleCmd23 ,
PlayerPartnerHandleHealthBarUpdate ,
PlayerPartnerHandleExpUpdate ,
PlayerPartnerHandleStatusIconUpdate ,
PlayerPartnerHandleStatusAnimation ,
PlayerPartnerHandleStatusXor ,
PlayerPartnerHandleDataTransfer ,
PlayerPartnerHandleDMA3Transfer ,
PlayerPartnerHandlePlayBGM ,
PlayerPartnerHandleCmd32 ,
PlayerPartnerHandleTwoReturnValues ,
PlayerPartnerHandleChosenMonReturnValue ,
PlayerPartnerHandleOneReturnValue ,
PlayerPartnerHandleOneReturnValue_Duplicate ,
PlayerPartnerHandleCmd37 ,
PlayerPartnerHandleCmd38 ,
PlayerPartnerHandleCmd39 ,
PlayerPartnerHandleCmd40 ,
PlayerPartnerHandleHitAnimation ,
PlayerPartnerHandleCmd42 ,
2017-11-25 18:42:31 +01:00
PlayerPartnerHandlePlaySE ,
2017-10-22 20:49:21 +02:00
PlayerPartnerHandlePlayFanfareOrBGM ,
PlayerPartnerHandleFaintingCry ,
PlayerPartnerHandleIntroSlide ,
PlayerPartnerHandleIntroTrainerBallThrow ,
PlayerPartnerHandleDrawPartyStatusSummary ,
2018-06-28 21:06:32 +02:00
PlayerPartnerHandleHidePartyStatusSummary ,
2018-06-20 23:07:51 +02:00
PlayerPartnerHandleEndBounceEffect ,
2017-10-22 20:49:21 +02:00
PlayerPartnerHandleSpriteInvisibility ,
PlayerPartnerHandleBattleAnimation ,
PlayerPartnerHandleLinkStandbyMsg ,
PlayerPartnerHandleResetActionMoveSelection ,
PlayerPartnerHandleCmd55 ,
2018-09-18 21:51:10 +02:00
PlayerPartnerHandleBattleDebug ,
2019-03-05 20:07:59 +01:00
PlayerPartnerCmdEnd
2017-10-22 20:49:21 +02:00
} ;
// unknown unused data
2017-12-17 23:45:27 +01:00
static const u8 sUnknown_08617254 [ ] =
2017-10-22 20:49:21 +02:00
{
0x83 , 0x4d , 0xf3 , 0x5f , 0x6f , 0x4f , 0xeb , 0x3e ,
0x67 , 0x2e , 0x10 , 0x46 , 0x8c , 0x3d , 0x28 , 0x35 ,
0xc5 , 0x2c , 0x15 , 0x7f , 0xb5 , 0x56 , 0x9d , 0x53 ,
0x3b , 0x43 , 0xda , 0x36 , 0x79 , 0x2a , 0x0e , 0x53 ,
} ;
2017-10-23 11:07:36 +02:00
static void nullsub_77 ( void )
2017-10-22 20:49:21 +02:00
{
}
2017-10-26 23:12:48 +02:00
void SetControllerToPlayerPartner ( void )
2017-10-22 20:49:21 +02:00
{
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = PlayerPartnerBufferRunCommand ;
2017-10-22 20:49:21 +02:00
}
2017-10-23 11:07:36 +02:00
static void PlayerPartnerBufferRunCommand ( void )
2017-10-22 20:49:21 +02:00
{
2018-02-06 20:48:02 +01:00
if ( gBattleControllerExecFlags & gBitTable [ gActiveBattler ] )
2017-10-22 20:49:21 +02:00
{
2019-01-05 16:00:57 +01:00
if ( gBattleResources - > bufferA [ gActiveBattler ] [ 0 ] < ARRAY_COUNT ( sPlayerPartnerBufferCommands ) )
sPlayerPartnerBufferCommands [ gBattleResources - > bufferA [ gActiveBattler ] [ 0 ] ] ( ) ;
2017-10-22 20:49:21 +02:00
else
PlayerPartnerBufferExecCompleted ( ) ;
}
}
2018-07-01 15:28:57 +02:00
static void CompleteOnBattlerSpriteCallbackDummy ( void )
2017-10-23 11:07:36 +02:00
{
2018-02-06 20:48:02 +01:00
if ( gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . callback = = SpriteCallbackDummy )
2017-10-23 11:07:36 +02:00
PlayerPartnerBufferExecCompleted ( ) ;
}
static void sub_81BAE98 ( void )
{
2018-02-06 20:48:02 +01:00
if ( gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . callback = = SpriteCallbackDummy )
2017-10-23 11:07:36 +02:00
{
nullsub_25 ( 0 ) ;
2018-02-06 20:48:02 +01:00
FreeSpriteOamMatrix ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] ) ;
DestroySprite ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] ) ;
2017-10-23 11:07:36 +02:00
PlayerPartnerBufferExecCompleted ( ) ;
}
}
static void sub_81BAF00 ( void )
{
2018-02-06 02:46:59 +01:00
if ( - - gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . field_9 = = 0xFF )
2017-10-23 11:07:36 +02:00
{
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . field_9 = 0 ;
2017-10-23 11:07:36 +02:00
PlayerPartnerBufferExecCompleted ( ) ;
}
}
static void sub_81BAF48 ( void )
{
bool32 r6 = FALSE ;
if ( ! IsDoubleBattle ( ) | | ( IsDoubleBattle ( ) & & ( gBattleTypeFlags & BATTLE_TYPE_MULTI ) ) )
{
2018-02-06 20:48:02 +01:00
if ( gSprites [ gHealthboxSpriteIds [ gActiveBattler ] ] . callback = = SpriteCallbackDummy )
2017-10-23 11:07:36 +02:00
r6 = TRUE ;
}
else
{
2018-02-06 20:48:02 +01:00
if ( gSprites [ gHealthboxSpriteIds [ gActiveBattler ] ] . callback = = SpriteCallbackDummy
& & gSprites [ gHealthboxSpriteIds [ gActiveBattler ^ BIT_FLANK ] ] . callback = = SpriteCallbackDummy )
2017-10-23 11:07:36 +02:00
{
r6 = TRUE ;
}
}
if ( IsCryPlayingOrClearCrySongs ( ) )
r6 = FALSE ;
if ( r6 )
{
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . field_9 = 3 ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = sub_81BAF00 ;
2017-10-23 11:07:36 +02:00
}
}
static void sub_81BB02C ( void )
{
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . ballAnimActive
& & ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ^ BIT_FLANK ] . ballAnimActive
& & gSprites [ gUnknown_03005D7C [ gActiveBattler ] ] . callback = = SpriteCallbackDummy
2018-02-06 20:48:02 +01:00
& & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . callback = = SpriteCallbackDummy
2018-02-06 02:46:59 +01:00
& & + + gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . field_9 ! = 1 )
2017-10-23 11:07:36 +02:00
{
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . field_9 = 0 ;
2017-10-23 11:07:36 +02:00
if ( IsDoubleBattle ( ) & & ! ( gBattleTypeFlags & BATTLE_TYPE_MULTI ) )
{
2018-02-06 02:46:59 +01:00
DestroySprite ( & gSprites [ gUnknown_03005D7C [ gActiveBattler ^ BIT_FLANK ] ] ) ;
2018-02-06 20:48:02 +01:00
UpdateHealthboxAttribute ( gHealthboxSpriteIds [ gActiveBattler ^ BIT_FLANK ] , & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ^ BIT_FLANK ] ] , HEALTHBOX_ALL ) ;
2018-02-06 02:46:59 +01:00
sub_8076918 ( gActiveBattler ^ BIT_FLANK ) ;
2018-02-06 20:48:02 +01:00
SetHealthboxSpriteVisible ( gHealthboxSpriteIds [ gActiveBattler ^ BIT_FLANK ] ) ;
2017-10-23 11:07:36 +02:00
}
2018-02-06 02:46:59 +01:00
DestroySprite ( & gSprites [ gUnknown_03005D7C [ gActiveBattler ] ] ) ;
2018-02-06 20:48:02 +01:00
UpdateHealthboxAttribute ( gHealthboxSpriteIds [ gActiveBattler ] , & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , HEALTHBOX_ALL ) ;
2018-02-06 02:46:59 +01:00
sub_8076918 ( gActiveBattler ) ;
2018-02-06 20:48:02 +01:00
SetHealthboxSpriteVisible ( gHealthboxSpriteIds [ gActiveBattler ] ) ;
2017-10-23 11:07:36 +02:00
gBattleSpritesDataPtr - > animationData - > field_9_x1 = 0 ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = sub_81BAF48 ;
2017-10-23 11:07:36 +02:00
}
}
static void sub_81BB1D4 ( void )
{
2018-02-06 20:48:02 +01:00
if ( gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . animEnded & & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . pos2 . x = = 0 )
2017-10-23 11:07:36 +02:00
PlayerPartnerBufferExecCompleted ( ) ;
}
static void CompleteOnHealthbarDone ( void )
{
2018-06-19 00:43:15 +02:00
s16 hpValue = MoveBattleBar ( gActiveBattler , gHealthboxSpriteIds [ gActiveBattler ] , HEALTH_BAR , 0 ) ;
2017-10-23 11:07:36 +02:00
2018-02-06 20:48:02 +01:00
SetHealthboxSpriteVisible ( gHealthboxSpriteIds [ gActiveBattler ] ) ;
2017-10-23 11:07:36 +02:00
if ( hpValue ! = - 1 )
{
2018-02-06 20:48:02 +01:00
UpdateHpTextInHealthbox ( gHealthboxSpriteIds [ gActiveBattler ] , hpValue , H P_CURRENT ) ;
2017-10-23 11:07:36 +02:00
}
else
{
2018-02-06 20:48:02 +01:00
HandleLowHpMusicChange ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , gActiveBattler ) ;
2017-10-23 11:07:36 +02:00
PlayerPartnerBufferExecCompleted ( ) ;
}
}
static void CompleteOnInactiveTextPrinter ( void )
{
if ( ! IsTextPrinterActive ( 0 ) )
PlayerPartnerBufferExecCompleted ( ) ;
}
// the whole exp task is copied&pasted from player controller
# define tExpTask_monId data[0]
# define tExpTask_gainedExp data[1]
# define tExpTask_bank data[2]
# define tExpTask_frames data[10]
static void Task_GiveExpToMon ( u8 taskId )
{
u32 monId = ( u8 ) ( gTasks [ taskId ] . tExpTask_monId ) ;
2018-03-01 00:59:52 +01:00
u8 battlerId = gTasks [ taskId ] . tExpTask_bank ;
2017-10-23 11:07:36 +02:00
s16 gainedExp = gTasks [ taskId ] . tExpTask_gainedExp ;
2018-03-01 00:59:52 +01:00
if ( IsDoubleBattle ( ) = = TRUE | | monId ! = gBattlerPartyIndexes [ battlerId ] ) // give exp without the expbar
2017-10-23 11:07:36 +02:00
{
struct Pokemon * mon = & gPlayerParty [ monId ] ;
u16 species = GetMonData ( mon , MON_DATA_SPECIES ) ;
u8 level = GetMonData ( mon , MON_DATA_LEVEL ) ;
u32 currExp = GetMonData ( mon , MON_DATA_EXP ) ;
u32 nextLvlExp = gExperienceTables [ gBaseStats [ species ] . growthRate ] [ level + 1 ] ;
if ( currExp + gainedExp > = nextLvlExp )
{
u8 savedActiveBank ;
SetMonData ( mon , MON_DATA_EXP , & nextLvlExp ) ;
CalculateMonStats ( mon ) ;
gainedExp - = nextLvlExp - currExp ;
2018-02-06 02:46:59 +01:00
savedActiveBank = gActiveBattler ;
2018-03-01 00:59:52 +01:00
gActiveBattler = battlerId ;
2018-07-16 20:47:30 +02:00
BtlController_EmitTwoReturnValues ( 1 , RET_VALUE_LEVELED_UP , gainedExp ) ;
2018-02-06 02:46:59 +01:00
gActiveBattler = savedActiveBank ;
2017-10-23 11:07:36 +02:00
if ( IsDoubleBattle ( ) = = TRUE
2018-03-01 00:59:52 +01:00
& & ( ( u16 ) ( monId ) = = gBattlerPartyIndexes [ battlerId ] | | ( u16 ) ( monId ) = = gBattlerPartyIndexes [ battlerId ^ BIT_FLANK ] ) )
2017-10-23 11:07:36 +02:00
gTasks [ taskId ] . func = sub_81BB628 ;
else
gTasks [ taskId ] . func = DestroyExpTaskAndCompleteOnInactiveTextPrinter ;
}
else
{
currExp + = gainedExp ;
SetMonData ( mon , MON_DATA_EXP , & currExp ) ;
2018-03-01 00:59:52 +01:00
gBattlerControllerFuncs [ battlerId ] = CompleteOnInactiveTextPrinter ;
2017-10-23 11:07:36 +02:00
DestroyTask ( taskId ) ;
}
}
else
{
gTasks [ taskId ] . func = Task_PrepareToGiveExpWithExpBar ;
}
}
static void Task_PrepareToGiveExpWithExpBar ( u8 taskId )
{
u8 monIndex = gTasks [ taskId ] . tExpTask_monId ;
s32 gainedExp = gTasks [ taskId ] . tExpTask_gainedExp ;
2018-03-01 00:59:52 +01:00
u8 battlerId = gTasks [ taskId ] . tExpTask_bank ;
2017-10-23 11:07:36 +02:00
struct Pokemon * mon = & gPlayerParty [ monIndex ] ;
u8 level = GetMonData ( mon , MON_DATA_LEVEL ) ;
u16 species = GetMonData ( mon , MON_DATA_SPECIES ) ;
u32 exp = GetMonData ( mon , MON_DATA_EXP ) ;
u32 currLvlExp = gExperienceTables [ gBaseStats [ species ] . growthRate ] [ level ] ;
u32 expToNextLvl ;
exp - = currLvlExp ;
expToNextLvl = gExperienceTables [ gBaseStats [ species ] . growthRate ] [ level + 1 ] - currLvlExp ;
2018-03-01 00:59:52 +01:00
SetBattleBarStruct ( battlerId , gHealthboxSpriteIds [ battlerId ] , expToNextLvl , exp , - gainedExp ) ;
2017-10-23 11:07:36 +02:00
PlaySE ( SE_EXP ) ;
gTasks [ taskId ] . func = sub_81BB4E4 ;
}
static void sub_81BB4E4 ( u8 taskId )
{
if ( gTasks [ taskId ] . tExpTask_frames < 13 )
{
gTasks [ taskId ] . tExpTask_frames + + ;
}
else
{
u8 monId = gTasks [ taskId ] . tExpTask_monId ;
s16 gainedExp = gTasks [ taskId ] . tExpTask_gainedExp ;
2018-03-01 00:59:52 +01:00
u8 battlerId = gTasks [ taskId ] . tExpTask_bank ;
2017-10-23 11:07:36 +02:00
s16 r4 ;
2018-06-19 00:43:15 +02:00
r4 = MoveBattleBar ( battlerId , gHealthboxSpriteIds [ battlerId ] , EXP_BAR , 0 ) ;
2018-03-01 00:59:52 +01:00
SetHealthboxSpriteVisible ( gHealthboxSpriteIds [ battlerId ] ) ;
2017-10-23 11:07:36 +02:00
if ( r4 = = - 1 )
{
u8 level ;
s32 currExp ;
u16 species ;
s32 expOnNextLvl ;
m4aSongNumStop ( SE_EXP ) ;
level = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_LEVEL ) ;
currExp = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_EXP ) ;
species = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPECIES ) ;
expOnNextLvl = gExperienceTables [ gBaseStats [ species ] . growthRate ] [ level + 1 ] ;
if ( currExp + gainedExp > = expOnNextLvl )
{
u8 savedActiveBank ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_EXP , & expOnNextLvl ) ;
CalculateMonStats ( & gPlayerParty [ monId ] ) ;
gainedExp - = expOnNextLvl - currExp ;
2018-02-06 02:46:59 +01:00
savedActiveBank = gActiveBattler ;
2018-03-01 00:59:52 +01:00
gActiveBattler = battlerId ;
2018-07-16 20:47:30 +02:00
BtlController_EmitTwoReturnValues ( 1 , RET_VALUE_LEVELED_UP , gainedExp ) ;
2018-02-06 02:46:59 +01:00
gActiveBattler = savedActiveBank ;
2017-10-23 11:07:36 +02:00
gTasks [ taskId ] . func = sub_81BB628 ;
}
else
{
currExp + = gainedExp ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_EXP , & currExp ) ;
2018-03-01 00:59:52 +01:00
gBattlerControllerFuncs [ battlerId ] = CompleteOnInactiveTextPrinter ;
2017-10-23 11:07:36 +02:00
DestroyTask ( taskId ) ;
}
}
}
}
static void sub_81BB628 ( u8 taskId )
{
2018-03-01 00:59:52 +01:00
u8 battlerId = gTasks [ taskId ] . tExpTask_bank ;
2017-10-23 11:07:36 +02:00
u8 monIndex = gTasks [ taskId ] . tExpTask_monId ;
2018-03-01 00:59:52 +01:00
if ( IsDoubleBattle ( ) = = TRUE & & monIndex = = gBattlerPartyIndexes [ battlerId ^ BIT_FLANK ] )
battlerId ^ = BIT_FLANK ;
2017-10-23 11:07:36 +02:00
2018-03-01 00:59:52 +01:00
InitAndLaunchSpecialAnimation ( battlerId , battlerId , battlerId , B_ANIM_LVL_UP ) ;
2017-10-23 11:07:36 +02:00
gTasks [ taskId ] . func = sub_81BB688 ;
}
static void sub_81BB688 ( u8 taskId )
{
2018-03-01 00:59:52 +01:00
u8 battlerId = gTasks [ taskId ] . tExpTask_bank ;
2017-10-23 11:07:36 +02:00
2018-03-01 00:59:52 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ battlerId ] . specialAnimActive )
2017-10-23 11:07:36 +02:00
{
u8 monIndex = gTasks [ taskId ] . tExpTask_monId ;
GetMonData ( & gPlayerParty [ monIndex ] , MON_DATA_LEVEL ) ; // Unused return value
2018-03-01 00:59:52 +01:00
if ( IsDoubleBattle ( ) = = TRUE & & monIndex = = gBattlerPartyIndexes [ battlerId ^ BIT_FLANK ] )
UpdateHealthboxAttribute ( gHealthboxSpriteIds [ battlerId ^ BIT_FLANK ] , & gPlayerParty [ monIndex ] , HEALTHBOX_ALL ) ;
2017-10-23 11:07:36 +02:00
else
2018-03-01 00:59:52 +01:00
UpdateHealthboxAttribute ( gHealthboxSpriteIds [ battlerId ] , & gPlayerParty [ monIndex ] , HEALTHBOX_ALL ) ;
2017-10-23 11:07:36 +02:00
gTasks [ taskId ] . func = DestroyExpTaskAndCompleteOnInactiveTextPrinter ;
}
}
static void DestroyExpTaskAndCompleteOnInactiveTextPrinter ( u8 taskId )
{
u8 monIndex ;
2018-03-01 00:59:52 +01:00
u8 battlerId ;
2017-10-23 11:07:36 +02:00
monIndex = gTasks [ taskId ] . tExpTask_monId ;
GetMonData ( & gPlayerParty [ monIndex ] , MON_DATA_LEVEL ) ; // Unused return value
2018-03-01 00:59:52 +01:00
battlerId = gTasks [ taskId ] . tExpTask_bank ;
gBattlerControllerFuncs [ battlerId ] = CompleteOnInactiveTextPrinter ;
2017-10-23 11:07:36 +02:00
DestroyTask ( taskId ) ;
}
static void sub_81BB78C ( void )
{
2018-02-06 20:48:02 +01:00
if ( gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . pos1 . y + gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . pos2 . y > DISPLAY_HEIGHT )
2017-10-23 11:07:36 +02:00
{
2018-02-06 20:48:02 +01:00
u16 species = GetMonData ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , MON_DATA_SPECIES ) ;
2017-10-23 11:07:36 +02:00
nullsub_24 ( species ) ;
2018-02-06 20:48:02 +01:00
FreeOamMatrix ( gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . oam . matrixNum ) ;
DestroySprite ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] ) ;
SetHealthboxSpriteInvisible ( gHealthboxSpriteIds [ gActiveBattler ] ) ;
2017-10-23 11:07:36 +02:00
PlayerPartnerBufferExecCompleted ( ) ;
}
}
static void sub_81BB828 ( void )
{
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . specialAnimActive )
2017-10-23 11:07:36 +02:00
{
2018-02-06 20:48:02 +01:00
FreeSpriteOamMatrix ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] ) ;
DestroySprite ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] ) ;
SetHealthboxSpriteInvisible ( gHealthboxSpriteIds [ gActiveBattler ] ) ;
2017-10-23 11:07:36 +02:00
PlayerPartnerBufferExecCompleted ( ) ;
}
}
static void CompleteOnInactiveTextPrinter2 ( void )
{
if ( ! IsTextPrinterActive ( 0 ) )
PlayerPartnerBufferExecCompleted ( ) ;
}
static void DoHitAnimBlinkSpriteEffect ( void )
{
2018-02-06 20:48:02 +01:00
u8 spriteId = gBattlerSpriteIds [ gActiveBattler ] ;
2017-10-23 11:07:36 +02:00
2017-12-02 21:44:50 +01:00
if ( gSprites [ spriteId ] . data [ 1 ] = = 32 )
2017-10-23 11:07:36 +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-23 11:07:36 +02:00
gDoingBattleAnim = FALSE ;
PlayerPartnerBufferExecCompleted ( ) ;
}
else
{
2017-12-02 21:44:50 +01:00
if ( ( gSprites [ spriteId ] . data [ 1 ] % 4 ) = = 0 )
2017-10-23 11:07:36 +02:00
gSprites [ spriteId ] . invisible ^ = 1 ;
2017-12-02 21:44:50 +01:00
gSprites [ spriteId ] . data [ 1 ] + + ;
2017-10-23 11:07:36 +02:00
}
}
static void sub_81BB92C ( void )
{
2018-02-06 20:48:02 +01:00
if ( gSprites [ gHealthboxSpriteIds [ gActiveBattler ] ] . callback = = SpriteCallbackDummy )
2017-10-23 11:07:36 +02:00
{
2018-02-06 02:46:59 +01:00
CopyBattleSpriteInvisibility ( gActiveBattler ) ;
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-23 11:07:36 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = sub_81BB9A0 ;
2017-10-23 11:07:36 +02:00
}
}
static void sub_81BB9A0 ( void )
{
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . specialAnimActive
2018-02-06 20:48:02 +01:00
& & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . callback = = SpriteCallbackDummy )
2017-10-23 11:07:36 +02:00
{
PlayerPartnerBufferExecCompleted ( ) ;
}
}
static void sub_81BB9F4 ( void )
{
2020-08-30 21:11:44 +02:00
if ( gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . finishedShinyMonAnim )
2017-10-23 11:07:36 +02:00
{
2020-08-30 21:11:44 +02:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . triedShinyMonAnim = FALSE ;
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . finishedShinyMonAnim = FALSE ;
2017-10-23 11:07:36 +02:00
FreeSpriteTilesByTag ( 0x27F9 ) ;
FreeSpritePaletteByTag ( 0x27F9 ) ;
CreateTask ( c3_0802FDF4 , 10 ) ;
2018-02-06 20:48:02 +01:00
HandleLowHpMusicChange ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , gActiveBattler ) ;
StartSpriteAnim ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] , 0 ) ;
UpdateHealthboxAttribute ( gHealthboxSpriteIds [ gActiveBattler ] , & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , HEALTHBOX_ALL ) ;
2018-02-06 02:46:59 +01:00
sub_8076918 ( gActiveBattler ) ;
2018-02-06 20:48:02 +01:00
SetHealthboxSpriteVisible ( gHealthboxSpriteIds [ gActiveBattler ] ) ;
2017-10-23 11:07:36 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = sub_81BB92C ;
2017-10-23 11:07:36 +02:00
}
}
static void sub_81BBAE8 ( void )
{
2020-08-30 21:11:44 +02:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . triedShinyMonAnim
2018-02-06 02:46:59 +01:00
& & ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . ballAnimActive )
2017-10-23 11:07:36 +02:00
{
2020-08-05 04:37:52 +02:00
TryShinyAnimation ( gActiveBattler , & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] ) ;
2017-10-23 11:07:36 +02:00
}
2018-02-06 02:46:59 +01:00
if ( gSprites [ gUnknown_03005D7C [ gActiveBattler ] ] . callback = = SpriteCallbackDummy
& & ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . ballAnimActive )
2017-10-23 11:07:36 +02:00
{
2018-02-06 02:46:59 +01:00
DestroySprite ( & gSprites [ gUnknown_03005D7C [ gActiveBattler ] ] ) ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = sub_81BB9F4 ;
2017-10-23 11:07:36 +02:00
}
}
static void PlayerPartnerBufferExecCompleted ( void )
{
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = PlayerPartnerBufferRunCommand ;
2017-10-23 11:07:36 +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-23 11:07:36 +02:00
}
else
{
2018-02-06 20:48:02 +01:00
gBattleControllerExecFlags & = ~ gBitTable [ gActiveBattler ] ;
2017-10-23 11:07:36 +02:00
}
}
static void CompleteOnFinishedStatusAnimation ( void )
{
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . statusAnimActive )
2017-10-23 11:07:36 +02:00
PlayerPartnerBufferExecCompleted ( ) ;
}
static void CompleteOnFinishedBattleAnimation ( void )
{
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animFromTableActive )
2017-10-23 11:07:36 +02:00
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleGetMonData ( 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-23 11:07:36 +02:00
s32 i ;
2019-01-05 16:00:57 +01:00
if ( gBattleResources - > bufferA [ gActiveBattler ] [ 2 ] = = 0 )
2017-10-23 11:07:36 +02:00
{
2018-02-06 20:48:02 +01:00
size + = CopyPlayerPartnerMonData ( gBattlerPartyIndexes [ gActiveBattler ] , monData ) ;
2017-10-23 11:07:36 +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-23 11:07:36 +02:00
{
2017-10-31 18:04:08 +01:00
if ( monToCheck & 1 )
2017-10-23 11:07:36 +02:00
size + = CopyPlayerPartnerMonData ( i , monData + size ) ;
2017-10-31 18:04:08 +01:00
monToCheck > > = 1 ;
2017-10-23 11:07:36 +02:00
}
}
2018-02-06 20:48:02 +01:00
BtlController_EmitDataTransfer ( 1 , size , monData ) ;
2017-10-23 11:07:36 +02:00
PlayerPartnerBufferExecCompleted ( ) ;
}
static u32 CopyPlayerPartnerMonData ( 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-23 11:07:36 +02:00
{
case REQUEST_ALL_BATTLE :
battleMon . species = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPECIES ) ;
battleMon . item = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_HELD_ITEM ) ;
2018-12-25 18:50:15 +01:00
for ( size = 0 ; size < MAX_MON_MOVES ; size + + )
2017-10-23 11:07:36 +02:00
{
battleMon . moves [ size ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_MOVE1 + size ) ;
battleMon . pp [ size ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_PP1 + size ) ;
}
battleMon . ppBonuses = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_PP_BONUSES ) ;
battleMon . friendship = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_FRIENDSHIP ) ;
battleMon . experience = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_EXP ) ;
battleMon . hpIV = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_HP_IV ) ;
battleMon . attackIV = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_ATK_IV ) ;
battleMon . defenseIV = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_DEF_IV ) ;
2017-10-24 15:35:36 +02:00
battleMon . speedIV = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPEED_IV ) ;
2017-10-23 11:07:36 +02:00
battleMon . spAttackIV = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPATK_IV ) ;
battleMon . spDefenseIV = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPDEF_IV ) ;
battleMon . personality = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_PERSONALITY ) ;
battleMon . status1 = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_STATUS ) ;
battleMon . level = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_LEVEL ) ;
battleMon . hp = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_HP ) ;
battleMon . maxHP = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_MAX_HP ) ;
battleMon . attack = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_ATK ) ;
battleMon . defense = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_DEF ) ;
2017-10-24 15:35:36 +02:00
battleMon . speed = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPEED ) ;
2017-10-23 11:07:36 +02:00
battleMon . spAttack = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPATK ) ;
battleMon . spDefense = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPDEF ) ;
2019-05-14 15:22:16 +02:00
battleMon . abilityNum = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_ABILITY_NUM ) ;
2017-10-23 11:07:36 +02:00
battleMon . otId = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_OT_ID ) ;
GetMonData ( & gPlayerParty [ monId ] , MON_DATA_NICKNAME , nickname ) ;
StringCopy10 ( battleMon . nickname , nickname ) ;
GetMonData ( & gPlayerParty [ 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 ( & gPlayerParty [ monId ] , MON_DATA_SPECIES ) ;
dst [ 0 ] = data16 ;
dst [ 1 ] = data16 > > 8 ;
size = 2 ;
break ;
case REQUEST_HELDITEM_BATTLE :
data16 = GetMonData ( & gPlayerParty [ 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-23 11:07:36 +02:00
{
moveData . moves [ size ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_MOVE1 + size ) ;
moveData . pp [ size ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_PP1 + size ) ;
}
moveData . ppBonuses = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_PP_BONUSES ) ;
src = ( u8 * ) ( & moveData ) ;
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 ( & gPlayerParty [ monId ] , MON_DATA_MOVE1 + gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] - REQUEST_MOVE1_BATTLE ) ;
2017-10-23 11:07:36 +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-23 11:07:36 +02:00
dst [ size ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_PP1 + size ) ;
dst [ size ] = GetMonData ( & gPlayerParty [ 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 ( & gPlayerParty [ monId ] , MON_DATA_PP1 + gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] - REQUEST_PPMOVE1_BATTLE ) ;
2017-10-23 11:07:36 +02:00
size = 1 ;
break ;
case REQUEST_OTID_BATTLE :
data32 = GetMonData ( & gPlayerParty [ 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 ( & gPlayerParty [ 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 ( & gPlayerParty [ monId ] , MON_DATA_HP_EV ) ;
size = 1 ;
break ;
case REQUEST_ATK_EV_BATTLE :
dst [ 0 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_ATK_EV ) ;
size = 1 ;
break ;
case REQUEST_DEF_EV_BATTLE :
dst [ 0 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_DEF_EV ) ;
size = 1 ;
break ;
case REQUEST_SPEED_EV_BATTLE :
2017-10-24 15:35:36 +02:00
dst [ 0 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPEED_EV ) ;
2017-10-23 11:07:36 +02:00
size = 1 ;
break ;
case REQUEST_SPATK_EV_BATTLE :
dst [ 0 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPATK_EV ) ;
size = 1 ;
break ;
case REQUEST_SPDEF_EV_BATTLE :
dst [ 0 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPDEF_EV ) ;
size = 1 ;
break ;
case REQUEST_FRIENDSHIP_BATTLE :
dst [ 0 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_FRIENDSHIP ) ;
size = 1 ;
break ;
case REQUEST_POKERUS_BATTLE :
dst [ 0 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_POKERUS ) ;
size = 1 ;
break ;
case REQUEST_MET_LOCATION_BATTLE :
dst [ 0 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_MET_LOCATION ) ;
size = 1 ;
break ;
case REQUEST_MET_LEVEL_BATTLE :
dst [ 0 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_MET_LEVEL ) ;
size = 1 ;
break ;
case REQUEST_MET_GAME_BATTLE :
dst [ 0 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_MET_GAME ) ;
size = 1 ;
break ;
case REQUEST_POKEBALL_BATTLE :
dst [ 0 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_POKEBALL ) ;
size = 1 ;
break ;
case REQUEST_ALL_IVS_BATTLE :
dst [ 0 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_HP_IV ) ;
dst [ 1 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_ATK_IV ) ;
dst [ 2 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_DEF_IV ) ;
2017-10-24 15:35:36 +02:00
dst [ 3 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPEED_IV ) ;
2017-10-23 11:07:36 +02:00
dst [ 4 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPATK_IV ) ;
dst [ 5 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPDEF_IV ) ;
size = 6 ;
break ;
case REQUEST_HP_IV_BATTLE :
dst [ 0 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_HP_IV ) ;
size = 1 ;
break ;
case REQUEST_ATK_IV_BATTLE :
dst [ 0 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_ATK_IV ) ;
size = 1 ;
break ;
case REQUEST_DEF_IV_BATTLE :
dst [ 0 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_DEF_IV ) ;
size = 1 ;
break ;
case REQUEST_SPEED_IV_BATTLE :
2017-10-24 15:35:36 +02:00
dst [ 0 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPEED_IV ) ;
2017-10-23 11:07:36 +02:00
size = 1 ;
break ;
case REQUEST_SPATK_IV_BATTLE :
dst [ 0 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPATK_IV ) ;
size = 1 ;
break ;
case REQUEST_SPDEF_IV_BATTLE :
dst [ 0 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPDEF_IV ) ;
size = 1 ;
break ;
case REQUEST_PERSONALITY_BATTLE :
data32 = GetMonData ( & gPlayerParty [ 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 ( & gPlayerParty [ monId ] , MON_DATA_CHECKSUM ) ;
dst [ 0 ] = data16 ;
dst [ 1 ] = data16 > > 8 ;
size = 2 ;
break ;
case REQUEST_STATUS_BATTLE :
data32 = GetMonData ( & gPlayerParty [ 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 ( & gPlayerParty [ monId ] , MON_DATA_LEVEL ) ;
size = 1 ;
break ;
case REQUEST_HP_BATTLE :
data16 = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_HP ) ;
dst [ 0 ] = data16 ;
dst [ 1 ] = data16 > > 8 ;
size = 2 ;
break ;
case REQUEST_MAX_HP_BATTLE :
data16 = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_MAX_HP ) ;
dst [ 0 ] = data16 ;
dst [ 1 ] = data16 > > 8 ;
size = 2 ;
break ;
case REQUEST_ATK_BATTLE :
data16 = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_ATK ) ;
dst [ 0 ] = data16 ;
dst [ 1 ] = data16 > > 8 ;
size = 2 ;
break ;
case REQUEST_DEF_BATTLE :
data16 = GetMonData ( & gPlayerParty [ 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 ( & gPlayerParty [ monId ] , MON_DATA_SPEED ) ;
2017-10-23 11:07:36 +02:00
dst [ 0 ] = data16 ;
dst [ 1 ] = data16 > > 8 ;
size = 2 ;
break ;
case REQUEST_SPATK_BATTLE :
data16 = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPATK ) ;
dst [ 0 ] = data16 ;
dst [ 1 ] = data16 > > 8 ;
size = 2 ;
break ;
case REQUEST_SPDEF_BATTLE :
data16 = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPDEF ) ;
dst [ 0 ] = data16 ;
dst [ 1 ] = data16 > > 8 ;
size = 2 ;
break ;
case REQUEST_COOL_BATTLE :
dst [ 0 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_COOL ) ;
size = 1 ;
break ;
case REQUEST_BEAUTY_BATTLE :
dst [ 0 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_BEAUTY ) ;
size = 1 ;
break ;
case REQUEST_CUTE_BATTLE :
dst [ 0 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_CUTE ) ;
size = 1 ;
break ;
case REQUEST_SMART_BATTLE :
dst [ 0 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_SMART ) ;
size = 1 ;
break ;
case REQUEST_TOUGH_BATTLE :
dst [ 0 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_TOUGH ) ;
size = 1 ;
break ;
case REQUEST_SHEEN_BATTLE :
dst [ 0 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_SHEEN ) ;
size = 1 ;
break ;
case REQUEST_COOL_RIBBON_BATTLE :
dst [ 0 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_COOL_RIBBON ) ;
size = 1 ;
break ;
case REQUEST_BEAUTY_RIBBON_BATTLE :
dst [ 0 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_BEAUTY_RIBBON ) ;
size = 1 ;
break ;
case REQUEST_CUTE_RIBBON_BATTLE :
dst [ 0 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_CUTE_RIBBON ) ;
size = 1 ;
break ;
case REQUEST_SMART_RIBBON_BATTLE :
dst [ 0 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_SMART_RIBBON ) ;
size = 1 ;
break ;
case REQUEST_TOUGH_RIBBON_BATTLE :
dst [ 0 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_TOUGH_RIBBON ) ;
size = 1 ;
break ;
}
return size ;
}
static void PlayerPartnerHandleGetRawMonData ( void )
{
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleSetMonData ( void )
{
2017-10-31 18:04:08 +01:00
u8 monToCheck ;
2017-10-23 11:07:36 +02:00
u8 i ;
2019-01-05 16:00:57 +01:00
if ( gBattleResources - > bufferA [ gActiveBattler ] [ 2 ] = = 0 )
2017-10-23 11:07:36 +02:00
{
2018-02-06 20:48:02 +01:00
SetPlayerPartnerMonData ( gBattlerPartyIndexes [ gActiveBattler ] ) ;
2017-10-23 11:07:36 +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-23 11:07:36 +02:00
{
2017-10-31 18:04:08 +01:00
if ( monToCheck & 1 )
2017-10-23 11:07:36 +02:00
SetPlayerPartnerMonData ( i ) ;
2017-10-31 18:04:08 +01:00
monToCheck > > = 1 ;
2017-10-23 11:07:36 +02:00
}
}
PlayerPartnerBufferExecCompleted ( ) ;
}
static void SetPlayerPartnerMonData ( 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-23 11:07:36 +02:00
s32 i ;
2019-01-05 16:00:57 +01:00
switch ( gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] )
2017-10-23 11:07:36 +02:00
{
case REQUEST_ALL_BATTLE :
{
u8 iv ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPECIES , & battlePokemon - > species ) ;
SetMonData ( & gPlayerParty [ 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-23 11:07:36 +02:00
{
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_MOVE1 + i , & battlePokemon - > moves [ i ] ) ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_PP1 + i , & battlePokemon - > pp [ i ] ) ;
}
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_PP_BONUSES , & battlePokemon - > ppBonuses ) ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_FRIENDSHIP , & battlePokemon - > friendship ) ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_EXP , & battlePokemon - > experience ) ;
iv = battlePokemon - > hpIV ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_HP_IV , & iv ) ;
iv = battlePokemon - > attackIV ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_ATK_IV , & iv ) ;
iv = battlePokemon - > defenseIV ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_DEF_IV , & iv ) ;
iv = battlePokemon - > speedIV ;
2017-10-24 15:35:36 +02:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPEED_IV , & iv ) ;
2017-10-23 11:07:36 +02:00
iv = battlePokemon - > spAttackIV ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPATK_IV , & iv ) ;
iv = battlePokemon - > spDefenseIV ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPDEF_IV , & iv ) ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_PERSONALITY , & battlePokemon - > personality ) ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_STATUS , & battlePokemon - > status1 ) ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_LEVEL , & battlePokemon - > level ) ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_HP , & battlePokemon - > hp ) ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_MAX_HP , & battlePokemon - > maxHP ) ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_ATK , & battlePokemon - > attack ) ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_DEF , & battlePokemon - > defense ) ;
2017-10-24 15:35:36 +02:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPEED , & battlePokemon - > speed ) ;
2017-10-23 11:07:36 +02:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPATK , & battlePokemon - > spAttack ) ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPDEF , & battlePokemon - > spDefense ) ;
}
break ;
case REQUEST_SPECIES_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPECIES , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_HELDITEM_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_HELD_ITEM , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +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-23 11:07:36 +02:00
{
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_MOVE1 + i , & moveData - > moves [ i ] ) ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_PP1 + i , & moveData - > pp [ i ] ) ;
}
SetMonData ( & gPlayerParty [ 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 ( & gPlayerParty [ monId ] , MON_DATA_MOVE1 + gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] - REQUEST_MOVE1_BATTLE , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_PP_DATA_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_PP1 , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_PP2 , & gBattleResources - > bufferA [ gActiveBattler ] [ 4 ] ) ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_PP3 , & gBattleResources - > bufferA [ gActiveBattler ] [ 5 ] ) ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_PP4 , & gBattleResources - > bufferA [ gActiveBattler ] [ 6 ] ) ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_PP_BONUSES , & gBattleResources - > bufferA [ gActiveBattler ] [ 7 ] ) ;
2017-10-23 11:07:36 +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 ( & gPlayerParty [ monId ] , MON_DATA_PP1 + gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] - REQUEST_PPMOVE1_BATTLE , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_OTID_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_OT_ID , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_EXP_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_EXP , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_HP_EV_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_HP_EV , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_ATK_EV_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_ATK_EV , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_DEF_EV_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_DEF_EV , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_SPEED_EV_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPEED_EV , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_SPATK_EV_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPATK_EV , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_SPDEF_EV_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPDEF_EV , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_FRIENDSHIP_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_FRIENDSHIP , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_POKERUS_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_POKERUS , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_MET_LOCATION_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_MET_LOCATION , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_MET_LEVEL_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_MET_LEVEL , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_MET_GAME_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_MET_GAME , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_POKEBALL_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_POKEBALL , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_ALL_IVS_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_HP_IV , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_ATK_IV , & gBattleResources - > bufferA [ gActiveBattler ] [ 4 ] ) ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_DEF_IV , & gBattleResources - > bufferA [ gActiveBattler ] [ 5 ] ) ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPEED_IV , & gBattleResources - > bufferA [ gActiveBattler ] [ 6 ] ) ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPATK_IV , & gBattleResources - > bufferA [ gActiveBattler ] [ 7 ] ) ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPDEF_IV , & gBattleResources - > bufferA [ gActiveBattler ] [ 8 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_HP_IV_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_HP_IV , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_ATK_IV_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_ATK_IV , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_DEF_IV_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_DEF_IV , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_SPEED_IV_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPEED_IV , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_SPATK_IV_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPATK_IV , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_SPDEF_IV_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPDEF_IV , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_PERSONALITY_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_PERSONALITY , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_CHECKSUM_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_CHECKSUM , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_STATUS_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_STATUS , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_LEVEL_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_LEVEL , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_HP_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_HP , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_MAX_HP_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_MAX_HP , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_ATK_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_ATK , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_DEF_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_DEF , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_SPEED_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPEED , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_SPATK_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPATK , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_SPDEF_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPDEF , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_COOL_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_COOL , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_BEAUTY_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_BEAUTY , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_CUTE_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_CUTE , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_SMART_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SMART , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_TOUGH_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_TOUGH , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_SHEEN_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SHEEN , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_COOL_RIBBON_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_COOL_RIBBON , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_BEAUTY_RIBBON_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_BEAUTY_RIBBON , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_CUTE_RIBBON_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_CUTE_RIBBON , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_SMART_RIBBON_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SMART_RIBBON , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
case REQUEST_TOUGH_RIBBON_BATTLE :
2019-01-05 16:00:57 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_TOUGH_RIBBON , & gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-23 11:07:36 +02:00
break ;
}
2018-02-06 20:48:02 +01:00
HandleLowHpMusicChange ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , gActiveBattler ) ;
2017-10-23 11:07:36 +02:00
}
static void PlayerPartnerHandleSetRawMonData ( void )
{
2019-01-05 16:00:57 +01:00
u8 * dst = ( u8 * ) & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] + gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] ;
2017-10-23 11:07:36 +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-23 11:07:36 +02:00
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleLoadMonSprite ( void )
{
u16 species ;
2018-02-06 20:48:02 +01:00
BattleLoadPlayerMonSpriteGfx ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , gActiveBattler ) ;
species = GetMonData ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , MON_DATA_SPECIES ) ;
2018-07-01 15:28:57 +02:00
SetMultiuseSpriteTemplateToPokemon ( species , GetBattlerPosition ( gActiveBattler ) ) ;
2017-10-23 11:07:36 +02:00
2018-07-01 15:28:57 +02:00
gBattlerSpriteIds [ gActiveBattler ] = CreateSprite ( & gMultiuseSpriteTemplate ,
2018-02-06 20:48:02 +01:00
GetBattlerSpriteCoord ( gActiveBattler , 2 ) ,
GetBattlerSpriteDefault_Y ( gActiveBattler ) ,
2018-12-18 05:08:08 +01:00
GetBattlerSpriteSubpriority ( gActiveBattler ) ) ;
2018-02-06 20:48:02 +01:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . pos2 . x = - 240 ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . data [ 0 ] = gActiveBattler ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . oam . paletteNum = gActiveBattler ;
StartSpriteAnim ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] , gBattleMonForms [ gActiveBattler ] ) ;
gBattlerControllerFuncs [ gActiveBattler ] = sub_81BB1D4 ;
2017-10-23 11:07:36 +02:00
}
static void PlayerPartnerHandleSwitchInAnim ( void )
{
2019-01-05 16:00:57 +01:00
ClearTemporarySpeciesSpriteData ( gActiveBattler , gBattleResources - > bufferA [ gActiveBattler ] [ 2 ] ) ;
gBattlerPartyIndexes [ gActiveBattler ] = gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] ;
2018-02-06 20:48:02 +01:00
BattleLoadPlayerMonSpriteGfx ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , gActiveBattler ) ;
2019-01-05 16:00:57 +01:00
sub_81BD0E4 ( gActiveBattler , gBattleResources - > bufferA [ gActiveBattler ] [ 2 ] ) ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = sub_81BBAE8 ;
2017-10-23 11:07:36 +02:00
}
2018-03-01 00:59:52 +01:00
static void sub_81BD0E4 ( u8 battlerId , bool8 dontClearSubstituteBit )
2017-10-23 11:07:36 +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 ( & gPlayerParty [ gBattlerPartyIndexes [ battlerId ] ] , MON_DATA_SPECIES ) ;
gUnknown_03005D7C [ battlerId ] = CreateInvisibleSpriteWithCallback ( sub_805D714 ) ;
2018-07-01 15:28:57 +02:00
SetMultiuseSpriteTemplateToPokemon ( species , GetBattlerPosition ( battlerId ) ) ;
2017-10-23 11:07:36 +02:00
2018-03-01 00:59:52 +01:00
gBattlerSpriteIds [ battlerId ] = CreateSprite (
2018-07-01 15:28:57 +02:00
& gMultiuseSpriteTemplate ,
2018-03-01 00:59:52 +01:00
GetBattlerSpriteCoord ( battlerId , 2 ) ,
GetBattlerSpriteDefault_Y ( battlerId ) ,
2018-12-18 05:08:08 +01:00
GetBattlerSpriteSubpriority ( battlerId ) ) ;
2017-10-23 11:07:36 +02:00
2018-03-01 00:59:52 +01:00
gSprites [ gUnknown_03005D7C [ battlerId ] ] . data [ 1 ] = gBattlerSpriteIds [ battlerId ] ;
gSprites [ gUnknown_03005D7C [ battlerId ] ] . data [ 2 ] = battlerId ;
2017-10-23 11:07:36 +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-23 11:07:36 +02:00
2018-03-01 00:59:52 +01:00
StartSpriteAnim ( & gSprites [ gBattlerSpriteIds [ battlerId ] ] , gBattleMonForms [ battlerId ] ) ;
2017-10-23 11:07:36 +02:00
2018-03-01 00:59:52 +01:00
gSprites [ gBattlerSpriteIds [ battlerId ] ] . invisible = TRUE ;
gSprites [ gBattlerSpriteIds [ battlerId ] ] . callback = SpriteCallbackDummy ;
2017-10-23 11:07:36 +02:00
2018-03-01 00:59:52 +01:00
gSprites [ gUnknown_03005D7C [ battlerId ] ] . data [ 0 ] = DoPokeballSendOutAnimation ( 0 , POKEBALL_PLAYER_SENDOUT ) ;
2017-10-23 11:07:36 +02:00
}
static void PlayerPartnerHandleReturnMonToBall ( void )
{
2019-01-05 16:00:57 +01:00
if ( gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] = = 0 )
2017-10-23 11:07:36 +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-23 11:07:36 +02:00
}
else
{
2018-02-06 20:48:02 +01:00
FreeSpriteOamMatrix ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] ) ;
DestroySprite ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] ) ;
SetHealthboxSpriteInvisible ( gHealthboxSpriteIds [ gActiveBattler ] ) ;
2017-10-23 11:07:36 +02:00
PlayerPartnerBufferExecCompleted ( ) ;
}
}
static void DoSwitchOutAnimation ( void )
{
2018-02-06 02:46:59 +01:00
switch ( gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState )
2017-10-23 11:07:36 +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-23 11:07:36 +02:00
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState = 1 ;
2017-10-23 11:07:36 +02:00
break ;
case 1 :
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . specialAnimActive )
2017-10-23 11:07:36 +02:00
{
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState = 0 ;
InitAndLaunchSpecialAnimation ( gActiveBattler , gActiveBattler , gActiveBattler , B_ANIM_SWITCH_OUT_PLAYER_MON ) ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = sub_81BB828 ;
2017-10-23 11:07:36 +02:00
}
break ;
}
}
// some explanation here
// in emerald it's possible to have a tag battle in the battle frontier facilities with AI
// which use the front sprite for both the player and the partner as opposed to any other battles (including the one with Steven) that use the back pic as well as animate it
static void PlayerPartnerHandleDrawTrainerPic ( void )
{
s16 xPos , yPos ;
u32 trainerPicId ;
2018-06-30 18:55:34 +02:00
if ( gPartnerTrainerId = = TRAINER_STEVEN_PARTNER )
2017-10-23 11:07:36 +02:00
{
2018-06-30 18:55:34 +02:00
trainerPicId = TRAINER_BACK_PIC_STEVEN ;
2017-10-23 11:07:36 +02:00
xPos = 90 ;
2019-01-04 18:17:55 +01:00
yPos = ( 8 - gTrainerBackPicCoords [ trainerPicId ] . size ) * 4 + 80 ;
2017-10-23 11:07:36 +02:00
}
2018-11-24 01:02:02 +01:00
else if ( gPartnerTrainerId > = TRAINER_CUSTOM_PARTNER )
{
trainerPicId = gPartnerSpriteId ;
xPos = 90 ;
2019-01-05 10:14:20 +01:00
yPos = ( 8 - gTrainerBackPicCoords [ trainerPicId ] . size ) * 4 + 80 ;
2018-11-24 01:02:02 +01:00
}
2017-10-23 11:07:36 +02:00
else
{
trainerPicId = GetFrontierTrainerFrontSpriteId ( gPartnerTrainerId ) ;
xPos = 32 ;
2019-01-04 18:17:55 +01:00
yPos = ( 8 - gTrainerFrontPicCoords [ trainerPicId ] . size ) * 4 + 80 ;
2017-10-23 11:07:36 +02:00
}
// Use back pic only if the partner is Steven
2018-11-24 01:02:02 +01:00
if ( gPartnerTrainerId = = TRAINER_STEVEN_PARTNER | | gPartnerTrainerId > = TRAINER_CUSTOM_PARTNER )
2017-10-23 11:07:36 +02:00
{
2018-02-06 02:46:59 +01:00
DecompressTrainerBackPic ( trainerPicId , gActiveBattler ) ;
2018-07-01 15:28:57 +02:00
SetMultiuseSpriteTemplateToTrainerBack ( trainerPicId , GetBattlerPosition ( gActiveBattler ) ) ;
2018-12-18 05:08:08 +01:00
gBattlerSpriteIds [ gActiveBattler ] = CreateSprite ( & gMultiuseSpriteTemplate , xPos , yPos , GetBattlerSpriteSubpriority ( gActiveBattler ) ) ;
2018-02-06 02:46:59 +01:00
2018-02-06 20:48:02 +01:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . oam . paletteNum = gActiveBattler ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . pos2 . x = 240 ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . data [ 0 ] = - 2 ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . callback = sub_805D7AC ;
2017-10-23 11:07:36 +02:00
}
else // otherwise use front sprite
{
2018-02-06 02:46:59 +01:00
DecompressTrainerFrontPic ( trainerPicId , gActiveBattler ) ;
2018-07-01 15:28:57 +02:00
SetMultiuseSpriteTemplateToTrainerFront ( trainerPicId , GetBattlerPosition ( gActiveBattler ) ) ;
2018-12-18 05:08:08 +01:00
gBattlerSpriteIds [ gActiveBattler ] = CreateSprite ( & gMultiuseSpriteTemplate , xPos , yPos , GetBattlerSpriteSubpriority ( gActiveBattler ) ) ;
2018-02-06 20:48:02 +01:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . oam . paletteNum = IndexOfSpritePaletteTag ( gTrainerFrontPicPaletteTable [ trainerPicId ] . tag ) ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . pos2 . x = 240 ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . pos2 . y = 48 ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . data [ 0 ] = - 2 ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . callback = sub_805D7AC ;
2019-12-05 03:00:45 +01:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . oam . affineMode = ST_OAM_AFFINE_OFF ;
2018-02-06 20:48:02 +01:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . hFlip = 1 ;
2017-10-23 11:07:36 +02:00
}
2018-07-01 15:28:57 +02:00
gBattlerControllerFuncs [ gActiveBattler ] = CompleteOnBattlerSpriteCallbackDummy ;
2017-10-23 11:07:36 +02:00
}
static void PlayerPartnerHandleTrainerSlide ( void )
{
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleTrainerSlideBack ( 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 ] = - 40 ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . data [ 4 ] = gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . pos1 . 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 ) ;
gBattlerControllerFuncs [ gActiveBattler ] = sub_81BAE98 ;
2017-10-23 11:07:36 +02:00
}
static void PlayerPartnerHandleFaintAnimation ( void )
{
2018-02-06 02:46:59 +01:00
if ( gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState = = 0 )
2017-10-23 11:07:36 +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-23 11:07:36 +02:00
}
else
{
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . specialAnimActive )
2017-10-23 11:07:36 +02:00
{
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState = 0 ;
2018-02-06 20:48:02 +01:00
HandleLowHpMusicChange ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , gActiveBattler ) ;
2020-08-21 00:02:00 +02:00
PlaySE12WithPanning ( SE_FAINT , SOUND_PAN_ATTACKER ) ;
2018-02-06 20:48:02 +01:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . data [ 1 ] = 0 ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . data [ 2 ] = 5 ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . callback = sub_8039C00 ;
gBattlerControllerFuncs [ gActiveBattler ] = sub_81BB78C ;
2017-10-23 11:07:36 +02:00
}
}
}
static void PlayerPartnerHandlePaletteFade ( void )
{
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleSuccessBallThrowAnim ( void )
{
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleBallThrowAnim ( void )
{
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandlePause ( void )
{
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleMoveAnimation ( void )
{
2018-02-06 02:46:59 +01:00
if ( ! mplay_80342A4 ( gActiveBattler ) )
2017-10-23 11:07:36 +02:00
{
2019-01-05 16:00:57 +01:00
u16 move = gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] | ( gBattleResources - > bufferA [ gActiveBattler ] [ 2 ] < < 8 ) ;
2018-02-06 02:46:59 +01:00
2019-01-05 16:00:57 +01:00
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 ;
2017-10-23 13:32:11 +02:00
if ( IsMoveWithoutAnimation ( move , gAnimMoveTurn ) ) // always returns FALSE
2017-10-23 11:07:36 +02:00
{
PlayerPartnerBufferExecCompleted ( ) ;
}
else
{
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState = 0 ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = PlayerPartnerDoMoveAnimation ;
2017-10-23 11:07:36 +02:00
}
}
}
static void PlayerPartnerDoMoveAnimation ( 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-23 11:07:36 +02:00
2018-02-06 02:46:59 +01:00
switch ( gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState )
2017-10-23 11:07:36 +02:00
{
case 0 :
2018-02-06 23:09:39 +01:00
if ( gBattleSpritesDataPtr - > battlerData [ gActiveBattler ] . behindSubstitute
& & ! gBattleSpritesDataPtr - > battlerData [ gActiveBattler ] . flag_x8 )
2017-10-23 11:07:36 +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-23 11:07:36 +02:00
}
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState = 1 ;
2017-10-23 11:07:36 +02:00
break ;
case 1 :
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . specialAnimActive )
2017-10-23 11:07:36 +02:00
{
2019-12-05 03:00:45 +01:00
sub_805EB9C ( ST_OAM_AFFINE_OFF ) ;
2017-10-23 11:07:36 +02:00
DoMoveAnim ( move ) ;
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState = 2 ;
2017-10-23 11:07:36 +02:00
}
break ;
case 2 :
gAnimScriptCallback ( ) ;
if ( ! gAnimScriptActive )
{
2019-12-05 03:00:45 +01:00
sub_805EB9C ( ST_OAM_AFFINE_NORMAL ) ;
2018-02-06 23:09:39 +01:00
if ( gBattleSpritesDataPtr - > battlerData [ gActiveBattler ] . behindSubstitute & & multihit < 2 )
2017-10-23 11:07:36 +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-23 11:07:36 +02:00
}
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState = 3 ;
2017-10-23 11:07:36 +02:00
}
break ;
case 3 :
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . specialAnimActive )
2017-10-23 11:07:36 +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-23 11:07:36 +02:00
PlayerPartnerBufferExecCompleted ( ) ;
}
break ;
}
}
static void PlayerPartnerHandlePrintString ( void )
{
u16 * stringId ;
gBattle_BG0_X = 0 ;
gBattle_BG0_Y = 0 ;
2019-01-05 16:00:57 +01:00
stringId = ( u16 * ) ( & gBattleResources - > bufferA [ gActiveBattler ] [ 2 ] ) ;
2017-10-23 11:07:36 +02:00
BufferStringBattle ( * stringId ) ;
2018-06-17 16:48:58 +02:00
BattlePutTextOnWindow ( gDisplayedStringBattle , 0 ) ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = CompleteOnInactiveTextPrinter2 ;
2017-10-23 11:07:36 +02:00
}
2017-11-25 18:42:31 +01:00
static void PlayerPartnerHandlePrintSelectionString ( void )
2017-10-23 11:07:36 +02:00
{
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleChooseAction ( void )
{
AI_TrySwitchOrUseItem ( ) ;
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleUnknownYesNoBox ( void )
{
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleChooseMove ( void )
{
u8 chosenMoveId ;
2019-01-05 16:00:57 +01:00
struct ChooseMoveStruct * moveInfo = ( struct ChooseMoveStruct * ) ( & gBattleResources - > bufferA [ gActiveBattler ] [ 4 ] ) ;
2017-10-23 11:07:36 +02:00
BattleAI_SetupAIData ( 0xF ) ;
chosenMoveId = BattleAI_ChooseMoveOrAction ( ) ;
2018-02-26 13:24:46 +01:00
if ( gBattleMoves [ moveInfo - > moves [ chosenMoveId ] ] . target & ( MOVE_TARGET_USER | MOVE_TARGET_USER_OR_SELECTED ) )
2018-02-06 23:09:39 +01:00
gBattlerTarget = gActiveBattler ;
2017-10-23 11:07:36 +02:00
if ( gBattleMoves [ moveInfo - > moves [ chosenMoveId ] ] . target & MOVE_TARGET_BOTH )
{
2018-02-06 23:09:39 +01:00
gBattlerTarget = GetBattlerAtPosition ( B_POSITION_OPPONENT_LEFT ) ;
if ( gAbsentBattlerFlags & gBitTable [ gBattlerTarget ] )
gBattlerTarget = GetBattlerAtPosition ( B_POSITION_OPPONENT_RIGHT ) ;
2017-10-23 11:07:36 +02:00
}
2018-02-06 23:09:39 +01:00
BtlController_EmitTwoReturnValues ( 1 , 10 , chosenMoveId | ( gBattlerTarget < < 8 ) ) ;
2017-10-23 11:07:36 +02:00
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleChooseItem ( void )
{
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleChoosePokemon ( void )
{
s32 chosenMonId = GetMostSuitableMonToSwitchInto ( ) ;
if ( chosenMonId = = 6 ) // just switch to the next mon
{
2018-02-06 02:46:59 +01:00
u8 playerMonIdentity = GetBattlerAtPosition ( B_POSITION_PLAYER_LEFT ) ;
u8 selfIdentity = GetBattlerAtPosition ( B_POSITION_PLAYER_RIGHT ) ;
2017-10-23 11:07:36 +02:00
for ( chosenMonId = 3 ; chosenMonId < 6 ; chosenMonId + + )
{
if ( GetMonData ( & gPlayerParty [ chosenMonId ] , MON_DATA_HP ) ! = 0
2018-02-06 20:48:02 +01:00
& & chosenMonId ! = gBattlerPartyIndexes [ playerMonIdentity ]
& & chosenMonId ! = gBattlerPartyIndexes [ selfIdentity ] )
2017-10-23 11:07:36 +02:00
{
break ;
}
}
}
2018-02-06 02:46:59 +01:00
* ( gBattleStruct - > monToSwitchIntoId + gActiveBattler ) = chosenMonId ;
2018-02-06 20:48:02 +01:00
BtlController_EmitChosenMonReturnValue ( 1 , chosenMonId , NULL ) ;
2017-10-23 11:07:36 +02:00
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleCmd23 ( void )
{
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleHealthBarUpdate ( 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-23 11:07:36 +02:00
if ( hpVal ! = INSTANT_HP_BAR_DROP )
{
2018-02-06 20:48:02 +01:00
u32 maxHP = GetMonData ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , MON_DATA_MAX_HP ) ;
u32 curHP = GetMonData ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , MON_DATA_HP ) ;
2017-10-23 11:07:36 +02:00
2018-02-06 20:48:02 +01:00
SetBattleBarStruct ( gActiveBattler , gHealthboxSpriteIds [ gActiveBattler ] , maxHP , curHP , hpVal ) ;
2017-10-23 11:07:36 +02:00
}
else
{
2018-02-06 20:48:02 +01:00
u32 maxHP = GetMonData ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , MON_DATA_MAX_HP ) ;
2017-10-23 11:07:36 +02:00
2018-02-06 20:48:02 +01:00
SetBattleBarStruct ( gActiveBattler , gHealthboxSpriteIds [ gActiveBattler ] , maxHP , 0 , hpVal ) ;
2017-10-23 11:07:36 +02:00
}
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = CompleteOnHealthbarDone ;
2017-10-23 11:07:36 +02:00
}
static void PlayerPartnerHandleExpUpdate ( void )
{
2019-01-05 16:00:57 +01:00
u8 monId = gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] ;
2017-10-23 11:07:36 +02:00
2018-10-17 04:47:08 +02:00
if ( GetMonData ( & gPlayerParty [ monId ] , MON_DATA_LEVEL ) > = MAX_LEVEL )
2017-10-23 11:07:36 +02:00
{
PlayerPartnerBufferExecCompleted ( ) ;
}
else
{
s16 expPointsToGive ;
u8 taskId ;
LoadBattleBarGfx ( 1 ) ;
GetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPECIES ) ; // unused return value
2019-01-05 16:00:57 +01:00
expPointsToGive = gBattleResources - > bufferA [ gActiveBattler ] [ 2 ] | ( gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] < < 8 ) ;
2017-10-23 11:07:36 +02:00
taskId = CreateTask ( Task_GiveExpToMon , 10 ) ;
gTasks [ taskId ] . tExpTask_monId = monId ;
gTasks [ taskId ] . tExpTask_gainedExp = expPointsToGive ;
2018-02-06 02:46:59 +01:00
gTasks [ taskId ] . tExpTask_bank = gActiveBattler ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = nullsub_21 ;
2017-10-23 11:07:36 +02:00
}
}
# undef tExpTask_monId
# undef tExpTask_gainedExp
# undef tExpTask_bank
# undef tExpTask_frames
static void PlayerPartnerHandleStatusIconUpdate ( void )
{
2018-02-06 02:46:59 +01:00
if ( ! mplay_80342A4 ( gActiveBattler ) )
2017-10-23 11:07:36 +02:00
{
2018-03-01 00:59:52 +01:00
u8 battlerId ;
2017-10-23 11:07:36 +02:00
2018-02-06 20:48:02 +01:00
UpdateHealthboxAttribute ( gHealthboxSpriteIds [ gActiveBattler ] , & gPlayerParty [ 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-23 11:07:36 +02:00
}
}
static void PlayerPartnerHandleStatusAnimation ( void )
{
2018-02-06 02:46:59 +01:00
if ( ! mplay_80342A4 ( gActiveBattler ) )
2017-10-23 11:07:36 +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-23 11:07:36 +02:00
}
}
static void PlayerPartnerHandleStatusXor ( void )
{
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleDataTransfer ( void )
{
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleDMA3Transfer ( void )
{
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandlePlayBGM ( void )
{
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleCmd32 ( void )
{
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleTwoReturnValues ( void )
{
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleChosenMonReturnValue ( void )
{
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleOneReturnValue ( void )
{
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleOneReturnValue_Duplicate ( void )
{
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleCmd37 ( void )
{
gUnknown_02022D0C . field_0 = 0 ;
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleCmd38 ( void )
{
2019-01-05 16:00:57 +01:00
gUnknown_02022D0C . field_0 = gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] ;
2017-10-23 11:07:36 +02:00
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleCmd39 ( void )
{
gUnknown_02022D0C . flag_x80 = 0 ;
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleCmd40 ( void )
{
gUnknown_02022D0C . flag_x80 ^ = 1 ;
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleHitAnimation ( void )
{
2018-02-06 20:48:02 +01:00
if ( gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . invisible = = TRUE )
2017-10-23 11:07:36 +02:00
{
PlayerPartnerBufferExecCompleted ( ) ;
}
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-23 11:07:36 +02:00
}
}
static void PlayerPartnerHandleCmd42 ( void )
{
PlayerPartnerBufferExecCompleted ( ) ;
}
2017-11-25 18:42:31 +01:00
static void PlayerPartnerHandlePlaySE ( void )
2017-10-23 11:07:36 +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-23 11:07:36 +02:00
else
2018-10-19 21:57:19 +02:00
pan = SOUND_PAN_TARGET ;
2017-10-23 11:07:36 +02:00
2019-01-05 16:00:57 +01:00
PlaySE12WithPanning ( gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] | ( gBattleResources - > bufferA [ gActiveBattler ] [ 2 ] < < 8 ) , pan ) ;
2017-10-23 11:07:36 +02:00
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandlePlayFanfareOrBGM ( void )
{
2019-01-05 16:00:57 +01:00
if ( gBattleResources - > bufferA [ gActiveBattler ] [ 3 ] )
2017-10-23 11:07:36 +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-23 11:07:36 +02:00
}
else
{
2019-01-05 16:00:57 +01:00
PlayFanfare ( gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] | ( gBattleResources - > bufferA [ gActiveBattler ] [ 2 ] < < 8 ) ) ;
2017-10-23 11:07:36 +02:00
}
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleFaintingCry ( void )
{
2018-02-06 20:48:02 +01:00
u16 species = GetMonData ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , MON_DATA_SPECIES ) ;
2017-10-23 11:07:36 +02:00
PlayCry3 ( species , - 25 , 5 ) ;
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleIntroSlide ( 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-23 11:07:36 +02:00
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleIntroTrainerBallThrow ( void )
{
u8 paletteNum ;
u8 taskId ;
2019-02-06 20:17:09 +01:00
SetSpritePrimaryCoordsFromSecondaryCoords ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] ) ;
2017-10-23 11:07:36 +02:00
2018-02-06 20:48:02 +01:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . data [ 0 ] = 50 ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . data [ 2 ] = - 40 ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . data [ 4 ] = gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . pos1 . y ;
2018-11-26 00:00:18 +01:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . callback = StartAnimLinearTranslation ;
2018-02-06 20:48:02 +01:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . data [ 5 ] = gActiveBattler ;
2017-10-23 11:07:36 +02:00
2018-02-06 20:48:02 +01:00
StoreSpriteCallbackInData6 ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] , sub_805CC00 ) ;
StartSpriteAnim ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] , 1 ) ;
2017-10-23 11:07:36 +02:00
paletteNum = AllocSpritePalette ( 0xD6F9 ) ;
2018-06-30 18:55:34 +02:00
if ( gPartnerTrainerId = = TRAINER_STEVEN_PARTNER )
2017-10-23 11:07:36 +02:00
{
2018-06-30 18:55:34 +02:00
u8 spriteId = TRAINER_BACK_PIC_STEVEN ;
2017-10-23 11:07:36 +02:00
LoadCompressedPalette ( gTrainerBackPicPaletteTable [ spriteId ] . data , 0x100 + paletteNum * 16 , 32 ) ;
}
2018-11-24 01:02:02 +01:00
else if ( gPartnerTrainerId > = TRAINER_CUSTOM_PARTNER )
{
u8 spriteId = gPartnerSpriteId ;
LoadCompressedPalette ( gTrainerBackPicPaletteTable [ spriteId ] . data , 0x100 + paletteNum * 16 , 32 ) ;
}
2017-10-23 11:07:36 +02:00
else
{
u8 spriteId = GetFrontierTrainerFrontSpriteId ( gPartnerTrainerId ) ;
LoadCompressedPalette ( gTrainerFrontPicPaletteTable [ spriteId ] . data , 0x100 + paletteNum * 16 , 32 ) ;
}
2018-02-06 20:48:02 +01:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . oam . paletteNum = paletteNum ;
2017-10-23 11:07:36 +02:00
taskId = CreateTask ( sub_81BE2C8 , 5 ) ;
2018-02-06 02:46:59 +01:00
gTasks [ taskId ] . data [ 0 ] = gActiveBattler ;
2017-10-23 11:07:36 +02:00
2018-06-28 21:06:32 +02:00
if ( gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . partyStatusSummaryShown )
gTasks [ gBattlerStatusSummaryTaskId [ gActiveBattler ] ] . func = Task_HidePartyStatusSummary ;
2017-10-23 11:07:36 +02:00
gBattleSpritesDataPtr - > animationData - > field_9_x1 = 1 ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = nullsub_77 ;
2017-10-23 11:07:36 +02:00
}
static void sub_81BE2C8 ( u8 taskId )
{
if ( gTasks [ taskId ] . data [ 1 ] < 24 )
{
gTasks [ taskId ] . data [ 1 ] + + ;
}
else
{
2018-02-06 02:46:59 +01:00
u8 savedActiveBank = gActiveBattler ;
2017-10-23 11:07:36 +02:00
2018-02-06 02:46:59 +01:00
gActiveBattler = gTasks [ taskId ] . data [ 0 ] ;
2017-10-23 11:07:36 +02:00
if ( ! IsDoubleBattle ( ) | | ( gBattleTypeFlags & BATTLE_TYPE_MULTI ) )
{
2019-01-05 16:00:57 +01:00
gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] = gBattlerPartyIndexes [ gActiveBattler ] ;
2018-02-06 02:46:59 +01:00
sub_81BD0E4 ( gActiveBattler , FALSE ) ;
2017-10-23 11:07:36 +02:00
}
else
{
2019-01-05 16:00:57 +01:00
gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] = gBattlerPartyIndexes [ gActiveBattler ] ;
2018-02-06 02:46:59 +01:00
sub_81BD0E4 ( gActiveBattler , FALSE ) ;
gActiveBattler ^ = BIT_FLANK ;
2019-01-05 16:00:57 +01:00
gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] = gBattlerPartyIndexes [ gActiveBattler ] ;
2018-02-06 20:48:02 +01:00
BattleLoadPlayerMonSpriteGfx ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , gActiveBattler ) ;
2018-02-06 02:46:59 +01:00
sub_81BD0E4 ( gActiveBattler , FALSE ) ;
gActiveBattler ^ = BIT_FLANK ;
2017-10-23 11:07:36 +02:00
}
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = sub_81BB02C ;
2018-02-06 02:46:59 +01:00
gActiveBattler = savedActiveBank ;
2017-10-23 11:07:36 +02:00
DestroyTask ( taskId ) ;
}
}
static void PlayerPartnerHandleDrawPartyStatusSummary ( void )
{
2019-01-05 16:00:57 +01:00
if ( gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] ! = 0 & & GetBattlerSide ( gActiveBattler ) = = B_SIDE_PLAYER )
2017-10-23 11:07:36 +02:00
{
PlayerPartnerBufferExecCompleted ( ) ;
}
else
{
2018-06-28 21:06:32 +02:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . partyStatusSummaryShown = 1 ;
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 ] ) ;
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . field_5 = 0 ;
2017-10-23 11:07:36 +02:00
2019-01-05 16:00:57 +01:00
if ( gBattleResources - > bufferA [ gActiveBattler ] [ 2 ] ! = 0 )
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . field_5 = 0x5D ;
2017-10-23 11:07:36 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = sub_81BE498 ;
2017-10-23 11:07:36 +02:00
}
}
static void sub_81BE498 ( void )
{
2018-02-06 02:46:59 +01:00
if ( gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . field_5 + + > 0x5C )
2017-10-23 11:07:36 +02:00
{
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . field_5 = 0 ;
2017-10-23 11:07:36 +02:00
PlayerPartnerBufferExecCompleted ( ) ;
}
}
2018-06-28 21:06:32 +02:00
static void PlayerPartnerHandleHidePartyStatusSummary ( void )
2017-10-23 11:07:36 +02:00
{
2018-06-28 21:06:32 +02:00
if ( gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . partyStatusSummaryShown )
gTasks [ gBattlerStatusSummaryTaskId [ gActiveBattler ] ] . func = Task_HidePartyStatusSummary ;
2017-10-23 11:07:36 +02:00
PlayerPartnerBufferExecCompleted ( ) ;
}
2018-06-20 23:07:51 +02:00
static void PlayerPartnerHandleEndBounceEffect ( void )
2017-10-23 11:07:36 +02:00
{
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleSpriteInvisibility ( void )
{
2018-02-06 20:48:02 +01:00
if ( IsBattlerSpritePresent ( gActiveBattler ) )
2017-10-23 11:07:36 +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-23 11:07:36 +02:00
}
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleBattleAnimation ( void )
{
2018-02-06 02:46:59 +01:00
if ( ! mplay_80342A4 ( gActiveBattler ) )
2017-10-23 11:07:36 +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-23 11:07:36 +02:00
2018-02-06 02:46:59 +01:00
if ( TryHandleLaunchBattleTableAnimation ( gActiveBattler , gActiveBattler , gActiveBattler , animationId , argument ) )
2017-10-23 11:07:36 +02:00
PlayerPartnerBufferExecCompleted ( ) ;
else
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = CompleteOnFinishedBattleAnimation ;
2017-10-23 11:07:36 +02:00
}
}
static void PlayerPartnerHandleLinkStandbyMsg ( void )
{
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleResetActionMoveSelection ( void )
{
PlayerPartnerBufferExecCompleted ( ) ;
}
static void PlayerPartnerHandleCmd55 ( void )
{
2019-01-05 16:00:57 +01:00
gBattleOutcome = gBattleResources - > bufferA [ gActiveBattler ] [ 1 ] ;
2017-10-23 11:07:36 +02:00
FadeOutMapMusic ( 5 ) ;
BeginFastPaletteFade ( 3 ) ;
PlayerPartnerBufferExecCompleted ( ) ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = sub_80587B0 ;
2017-10-23 11:07:36 +02:00
}
2018-09-18 21:51:10 +02:00
static void PlayerPartnerHandleBattleDebug ( void )
{
PlayerPartnerBufferExecCompleted ( ) ;
}
2019-03-05 20:07:59 +01:00
static void PlayerPartnerCmdEnd ( void )
2017-10-23 11:07:36 +02:00
{
}