2017-10-21 17:32:35 +02:00
# include "global.h"
# include "battle.h"
# include "battle_controllers.h"
# include "battle_message.h"
# include "battle_interface.h"
# include "battle_anim.h"
2017-12-31 16:28:57 +01:00
# include "constants/battle_anim.h"
2018-02-27 20:40:09 +01:00
# include "battle_tv.h"
2017-10-21 17:32:35 +02:00
# include "pokemon.h"
# include "link.h"
# include "util.h"
# include "main.h"
# include "item.h"
2017-12-05 18:55:48 +01:00
# include "constants/items.h"
2017-12-11 19:27:51 +01:00
# include "constants/songs.h"
2017-10-21 17:32:35 +02:00
# include "sound.h"
2017-12-11 19:27:51 +01:00
# include "constants/moves.h"
2017-10-21 17:32:35 +02:00
# include "window.h"
# include "m4a.h"
# include "palette.h"
# include "task.h"
# include "text.h"
# include "string_util.h"
# include "bg.h"
# include "reshow_battle_screen.h"
2017-12-05 19:27:33 +01:00
# include "random.h"
2017-10-22 18:43:15 +02:00
# include "pokeball.h"
2017-10-31 18:04:08 +01:00
# include "data2.h"
2018-02-08 00:00:25 +01:00
# include "battle_setup.h"
# include "item_use.h"
# include "recorded_battle.h"
2017-10-21 17:32:35 +02:00
2017-10-22 18:43:15 +02:00
extern u8 gUnknown_0203CEE8 ;
extern u8 gUnknown_0203CEE9 ;
extern u8 gUnknown_0203CF00 [ ] ;
extern u16 gBattle_BG0_X ;
extern u16 gBattle_BG0_Y ;
extern s32 gUnknown_0203CD70 ;
extern struct UnusedControllerStruct gUnknown_02022D0C ;
2018-02-08 00:00:25 +01:00
extern struct MusicPlayerInfo gMPlayInfo_BGM ;
extern struct SpriteTemplate gUnknown_0202499C ;
2017-10-21 17:32:35 +02:00
2017-10-22 18:43:15 +02:00
extern const struct CompressedSpritePalette gTrainerFrontPicPaletteTable [ ] ;
extern const struct CompressedSpritePalette gTrainerBackPicPaletteTable [ ] ;
2017-10-21 17:32:35 +02:00
2018-03-01 00:59:52 +01:00
extern void sub_8172EF0 ( u8 battlerId , struct Pokemon * mon ) ;
2017-10-22 18:43:15 +02:00
extern void sub_81B89AC ( u8 arg0 ) ;
extern void sub_81AABB0 ( void ) ;
extern void sub_806A068 ( u16 , u8 ) ;
2018-03-01 00:59:52 +01:00
extern void sub_81A57E4 ( u8 battlerId , u16 stringId ) ;
2017-10-22 18:43:15 +02:00
extern void sub_81851A8 ( u8 * ) ;
2017-10-21 17:32:35 +02:00
// this file's functions
2017-10-22 18:43:15 +02:00
static void PlayerHandleGetMonData ( void ) ;
2017-10-21 17:32:35 +02:00
void PlayerHandleGetRawMonData ( void ) ;
2017-10-22 18:43:15 +02:00
static void PlayerHandleSetMonData ( void ) ;
static void PlayerHandleSetRawMonData ( void ) ;
static void PlayerHandleLoadMonSprite ( void ) ;
static void PlayerHandleSwitchInAnim ( void ) ;
static void PlayerHandleReturnMonToBall ( void ) ;
static void PlayerHandleDrawTrainerPic ( void ) ;
static void PlayerHandleTrainerSlide ( void ) ;
static void PlayerHandleTrainerSlideBack ( void ) ;
static void PlayerHandleFaintAnimation ( void ) ;
static void PlayerHandlePaletteFade ( void ) ;
static void PlayerHandleSuccessBallThrowAnim ( void ) ;
static void PlayerHandleBallThrowAnim ( void ) ;
static void PlayerHandlePause ( void ) ;
static void PlayerHandleMoveAnimation ( void ) ;
static void PlayerHandlePrintString ( void ) ;
2017-11-25 18:42:31 +01:00
static void PlayerHandlePrintSelectionString ( void ) ;
2017-10-22 18:43:15 +02:00
static void PlayerHandleChooseAction ( void ) ;
static void PlayerHandleUnknownYesNoBox ( void ) ;
static void PlayerHandleChooseMove ( void ) ;
static void PlayerHandleChooseItem ( void ) ;
static void PlayerHandleChoosePokemon ( void ) ;
static void PlayerHandleCmd23 ( void ) ;
static void PlayerHandleHealthBarUpdate ( void ) ;
static void PlayerHandleExpUpdate ( void ) ;
static void PlayerHandleStatusIconUpdate ( void ) ;
static void PlayerHandleStatusAnimation ( void ) ;
static void PlayerHandleStatusXor ( void ) ;
static void PlayerHandleDataTransfer ( void ) ;
static void PlayerHandleDMA3Transfer ( void ) ;
static void PlayerHandlePlayBGM ( void ) ;
static void PlayerHandleCmd32 ( void ) ;
static void PlayerHandleTwoReturnValues ( void ) ;
static void PlayerHandleChosenMonReturnValue ( void ) ;
static void PlayerHandleOneReturnValue ( void ) ;
static void PlayerHandleOneReturnValue_Duplicate ( void ) ;
static void PlayerHandleCmd37 ( void ) ;
static void PlayerHandleCmd38 ( void ) ;
static void PlayerHandleCmd39 ( void ) ;
static void PlayerHandleCmd40 ( void ) ;
static void PlayerHandleHitAnimation ( void ) ;
static void PlayerHandleCmd42 ( void ) ;
2017-11-25 18:42:31 +01:00
static void PlayerHandlePlaySE ( void ) ;
2017-10-22 18:43:15 +02:00
static void PlayerHandlePlayFanfareOrBGM ( void ) ;
static void PlayerHandleFaintingCry ( void ) ;
static void PlayerHandleIntroSlide ( void ) ;
static void PlayerHandleIntroTrainerBallThrow ( void ) ;
static void PlayerHandleDrawPartyStatusSummary ( void ) ;
static void PlayerHandleCmd49 ( void ) ;
static void PlayerHandleCmd50 ( void ) ;
static void PlayerHandleSpriteInvisibility ( void ) ;
static void PlayerHandleBattleAnimation ( void ) ;
static void PlayerHandleLinkStandbyMsg ( void ) ;
static void PlayerHandleResetActionMoveSelection ( void ) ;
static void PlayerHandleCmd55 ( void ) ;
static void nullsub_22 ( void ) ;
static void PlayerBufferRunCommand ( void ) ;
static void HandleInputChooseTarget ( void ) ;
static void HandleInputChooseMove ( void ) ;
static void MoveSelectionCreateCursorAt ( u8 cursorPos , u8 arg1 ) ;
static void MoveSelectionDestroyCursorAt ( u8 cursorPos ) ;
static void MoveSelectionDisplayPpNumber ( void ) ;
static void MoveSelectionDisplayPpString ( void ) ;
static void MoveSelectionDisplayMoveType ( void ) ;
static void MoveSelectionDisplayMoveNames ( void ) ;
static void HandleMoveSwitchting ( void ) ;
static void sub_8058FC0 ( void ) ;
static void sub_8059828 ( void ) ;
2017-10-22 20:38:23 +02:00
static void CompleteWhenChoseItem ( void ) ;
2017-10-22 18:43:15 +02:00
static void sub_8059544 ( u8 taskId ) ;
static void Task_PrepareToGiveExpWithExpBar ( u8 taskId ) ;
static void DestroyExpTaskAndCompleteOnInactiveTextPrinter ( u8 taskId ) ;
static void sub_8059400 ( u8 taskId ) ;
static void sub_80595A4 ( u8 taskId ) ;
static void PrintLinkStandbyMsg ( void ) ;
static u32 CopyPlayerMonData ( u8 monId , u8 * dst ) ;
static void SetPlayerMonData ( u8 monId ) ;
2018-03-01 00:59:52 +01:00
static void sub_805B258 ( u8 battlerId , bool8 dontClearSubstituteBit ) ;
2017-10-22 18:43:15 +02:00
static void DoSwitchOutAnimation ( void ) ;
static void PlayerDoMoveAnimation ( void ) ;
static void task05_08033660 ( u8 taskId ) ;
static void sub_805CE38 ( void ) ;
2017-10-31 18:04:08 +01:00
static void ( * const sPlayerBufferCommands [ CONTROLLER_CMDS_COUNT ] ) ( void ) =
2017-10-21 17:32:35 +02:00
{
PlayerHandleGetMonData ,
PlayerHandleGetRawMonData ,
PlayerHandleSetMonData ,
PlayerHandleSetRawMonData ,
PlayerHandleLoadMonSprite ,
PlayerHandleSwitchInAnim ,
PlayerHandleReturnMonToBall ,
PlayerHandleDrawTrainerPic ,
PlayerHandleTrainerSlide ,
PlayerHandleTrainerSlideBack ,
PlayerHandleFaintAnimation ,
2017-10-22 01:04:02 +02:00
PlayerHandlePaletteFade ,
2017-10-22 18:43:15 +02:00
PlayerHandleSuccessBallThrowAnim ,
PlayerHandleBallThrowAnim ,
2017-10-21 17:32:35 +02:00
PlayerHandlePause ,
PlayerHandleMoveAnimation ,
PlayerHandlePrintString ,
2017-11-25 18:42:31 +01:00
PlayerHandlePrintSelectionString ,
2017-10-21 17:32:35 +02:00
PlayerHandleChooseAction ,
2017-10-22 18:43:15 +02:00
PlayerHandleUnknownYesNoBox ,
2017-10-21 17:32:35 +02:00
PlayerHandleChooseMove ,
2017-10-22 18:43:15 +02:00
PlayerHandleChooseItem ,
2017-10-21 17:32:35 +02:00
PlayerHandleChoosePokemon ,
PlayerHandleCmd23 ,
PlayerHandleHealthBarUpdate ,
PlayerHandleExpUpdate ,
PlayerHandleStatusIconUpdate ,
PlayerHandleStatusAnimation ,
PlayerHandleStatusXor ,
PlayerHandleDataTransfer ,
PlayerHandleDMA3Transfer ,
PlayerHandlePlayBGM ,
PlayerHandleCmd32 ,
2017-10-22 18:43:15 +02:00
PlayerHandleTwoReturnValues ,
PlayerHandleChosenMonReturnValue ,
PlayerHandleOneReturnValue ,
PlayerHandleOneReturnValue_Duplicate ,
2017-10-21 17:32:35 +02:00
PlayerHandleCmd37 ,
PlayerHandleCmd38 ,
PlayerHandleCmd39 ,
PlayerHandleCmd40 ,
PlayerHandleHitAnimation ,
PlayerHandleCmd42 ,
2017-11-25 18:42:31 +01:00
PlayerHandlePlaySE ,
2017-10-21 17:32:35 +02:00
PlayerHandlePlayFanfareOrBGM ,
PlayerHandleFaintingCry ,
PlayerHandleIntroSlide ,
PlayerHandleIntroTrainerBallThrow ,
PlayerHandleDrawPartyStatusSummary ,
PlayerHandleCmd49 ,
PlayerHandleCmd50 ,
PlayerHandleSpriteInvisibility ,
PlayerHandleBattleAnimation ,
PlayerHandleLinkStandbyMsg ,
PlayerHandleResetActionMoveSelection ,
PlayerHandleCmd55 ,
nullsub_22
} ;
2018-01-16 21:01:31 +01:00
static const u8 sTargetIdentities [ ] = { B_POSITION_PLAYER_LEFT , B_POSITION_PLAYER_RIGHT , B_POSITION_OPPONENT_RIGHT , B_POSITION_OPPONENT_LEFT } ;
2017-10-21 17:32:35 +02:00
// unknown unused data
2017-12-17 23:45:27 +01:00
static const u8 sUnknown_0831C5FC [ ] = { 0x48 , 0x48 , 0x20 , 0x5a , 0x50 , 0x50 , 0x50 , 0x58 } ;
2017-10-21 17:32:35 +02:00
void nullsub_21 ( void )
{
}
2017-10-26 23:12:48 +02:00
void SetControllerToPlayer ( void )
2017-10-21 17:32:35 +02:00
{
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = PlayerBufferRunCommand ;
2017-10-21 17:32:35 +02:00
gDoingBattleAnim = FALSE ;
2017-10-27 13:29:18 +02:00
gPlayerDpadHoldFrames = 0 ;
2017-10-21 17:32:35 +02:00
}
2017-10-22 18:43:15 +02:00
static void PlayerBufferExecCompleted ( void )
2017-10-21 17:32:35 +02:00
{
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = PlayerBufferRunCommand ;
2017-10-21 17:32:35 +02:00
if ( gBattleTypeFlags & BATTLE_TYPE_LINK )
{
u8 playerId = GetMultiplayerId ( ) ;
PrepareBufferDataTransferLink ( 2 , 4 , & playerId ) ;
2018-02-06 02:46:59 +01:00
gBattleBufferA [ gActiveBattler ] [ 0 ] = CONTROLLER_TERMINATOR_NOP ;
2017-10-21 17:32:35 +02:00
}
else
{
2018-02-06 20:48:02 +01:00
gBattleControllerExecFlags & = ~ gBitTable [ gActiveBattler ] ;
2017-10-21 17:32:35 +02:00
}
}
2017-10-22 18:43:15 +02:00
static void PlayerBufferRunCommand ( void )
2017-10-21 17:32:35 +02:00
{
2018-02-06 20:48:02 +01:00
if ( gBattleControllerExecFlags & gBitTable [ gActiveBattler ] )
2017-10-21 17:32:35 +02:00
{
2018-02-06 02:46:59 +01:00
if ( gBattleBufferA [ gActiveBattler ] [ 0 ] < ARRAY_COUNT ( sPlayerBufferCommands ) )
sPlayerBufferCommands [ gBattleBufferA [ gActiveBattler ] [ 0 ] ] ( ) ;
2017-10-21 17:32:35 +02:00
else
PlayerBufferExecCompleted ( ) ;
}
}
2017-10-22 18:43:15 +02:00
static void CompleteOnBankSpritePosX_0 ( void )
2017-10-21 17:32:35 +02:00
{
2018-02-06 20:48:02 +01:00
if ( gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . pos2 . x = = 0 )
2017-10-21 17:32:35 +02:00
PlayerBufferExecCompleted ( ) ;
}
2017-10-22 18:43:15 +02:00
static void HandleInputChooseAction ( void )
2017-10-21 17:32:35 +02:00
{
2018-02-06 02:46:59 +01:00
u16 itemId = gBattleBufferA [ gActiveBattler ] [ 2 ] | ( gBattleBufferA [ gActiveBattler ] [ 3 ] < < 8 ) ;
2017-10-21 17:32:35 +02:00
2018-02-06 02:46:59 +01:00
dp11b_obj_instanciate ( gActiveBattler , 1 , 7 , 1 ) ;
dp11b_obj_instanciate ( gActiveBattler , 0 , 7 , 1 ) ;
2017-10-21 17:32:35 +02:00
if ( gMain . newAndRepeatedKeys & DPAD_ANY & & gSaveBlock2Ptr - > optionsButtonMode = = 2 )
2017-10-27 13:29:18 +02:00
gPlayerDpadHoldFrames + + ;
2017-10-21 17:32:35 +02:00
else
2017-10-27 13:29:18 +02:00
gPlayerDpadHoldFrames = 0 ;
2017-10-21 17:32:35 +02:00
if ( gMain . newKeys & A_BUTTON )
{
PlaySE ( SE_SELECT ) ;
2018-02-06 02:46:59 +01:00
switch ( gActionSelectionCursor [ gActiveBattler ] )
2017-10-21 17:32:35 +02:00
{
2017-10-22 20:38:23 +02:00
case 0 :
2018-02-06 23:09:39 +01:00
BtlController_EmitTwoReturnValues ( 1 , B_ACTION_USE_MOVE , 0 ) ;
2017-10-21 17:32:35 +02:00
break ;
2017-10-22 20:38:23 +02:00
case 1 :
2018-02-06 23:09:39 +01:00
BtlController_EmitTwoReturnValues ( 1 , B_ACTION_USE_ITEM , 0 ) ;
2017-10-21 17:32:35 +02:00
break ;
2017-10-22 20:38:23 +02:00
case 2 :
2018-02-06 23:09:39 +01:00
BtlController_EmitTwoReturnValues ( 1 , B_ACTION_SWITCH , 0 ) ;
2017-10-21 17:32:35 +02:00
break ;
2017-10-22 20:38:23 +02:00
case 3 :
2018-02-06 23:09:39 +01:00
BtlController_EmitTwoReturnValues ( 1 , B_ACTION_RUN , 0 ) ;
2017-10-21 17:32:35 +02:00
break ;
}
PlayerBufferExecCompleted ( ) ;
}
else if ( gMain . newKeys & DPAD_LEFT )
{
2018-02-06 23:09:39 +01:00
if ( gActionSelectionCursor [ gActiveBattler ] & 1 ) // if is B_ACTION_USE_ITEM or B_ACTION_RUN
2017-10-21 17:32:35 +02:00
{
PlaySE ( SE_SELECT ) ;
2018-02-06 02:46:59 +01:00
ActionSelectionDestroyCursorAt ( gActionSelectionCursor [ gActiveBattler ] ) ;
gActionSelectionCursor [ gActiveBattler ] ^ = 1 ;
ActionSelectionCreateCursorAt ( gActionSelectionCursor [ gActiveBattler ] , 0 ) ;
2017-10-21 17:32:35 +02:00
}
}
else if ( gMain . newKeys & DPAD_RIGHT )
{
2018-02-06 23:09:39 +01:00
if ( ! ( gActionSelectionCursor [ gActiveBattler ] & 1 ) ) // if is B_ACTION_USE_MOVE or B_ACTION_SWITCH
2017-10-21 17:32:35 +02:00
{
PlaySE ( SE_SELECT ) ;
2018-02-06 02:46:59 +01:00
ActionSelectionDestroyCursorAt ( gActionSelectionCursor [ gActiveBattler ] ) ;
gActionSelectionCursor [ gActiveBattler ] ^ = 1 ;
ActionSelectionCreateCursorAt ( gActionSelectionCursor [ gActiveBattler ] , 0 ) ;
2017-10-21 17:32:35 +02:00
}
}
else if ( gMain . newKeys & DPAD_UP )
{
2018-02-06 23:09:39 +01:00
if ( gActionSelectionCursor [ gActiveBattler ] & 2 ) // if is B_ACTION_SWITCH or B_ACTION_RUN
2017-10-21 17:32:35 +02:00
{
PlaySE ( SE_SELECT ) ;
2018-02-06 02:46:59 +01:00
ActionSelectionDestroyCursorAt ( gActionSelectionCursor [ gActiveBattler ] ) ;
gActionSelectionCursor [ gActiveBattler ] ^ = 2 ;
ActionSelectionCreateCursorAt ( gActionSelectionCursor [ gActiveBattler ] , 0 ) ;
2017-10-21 17:32:35 +02:00
}
}
else if ( gMain . newKeys & DPAD_DOWN )
{
2018-02-06 23:09:39 +01:00
if ( ! ( gActionSelectionCursor [ gActiveBattler ] & 2 ) ) // if is B_ACTION_USE_MOVE or B_ACTION_USE_ITEM
2017-10-21 17:32:35 +02:00
{
PlaySE ( SE_SELECT ) ;
2018-02-06 02:46:59 +01:00
ActionSelectionDestroyCursorAt ( gActionSelectionCursor [ gActiveBattler ] ) ;
gActionSelectionCursor [ gActiveBattler ] ^ = 2 ;
ActionSelectionCreateCursorAt ( gActionSelectionCursor [ gActiveBattler ] , 0 ) ;
2017-10-21 17:32:35 +02:00
}
}
2017-10-27 13:29:18 +02:00
else if ( gMain . newKeys & B_BUTTON | | gPlayerDpadHoldFrames > 59 )
2017-10-21 17:32:35 +02:00
{
if ( ( gBattleTypeFlags & BATTLE_TYPE_DOUBLE )
2018-02-06 02:46:59 +01:00
& & GetBattlerPosition ( gActiveBattler ) = = B_POSITION_PLAYER_RIGHT
& & ! ( gAbsentBattlerFlags & gBitTable [ GetBattlerAtPosition ( B_POSITION_PLAYER_LEFT ) ] )
2017-10-21 17:32:35 +02:00
& & ! ( gBattleTypeFlags & BATTLE_TYPE_MULTI ) )
{
2018-02-06 23:09:39 +01:00
if ( gBattleBufferA [ gActiveBattler ] [ 1 ] = = B_ACTION_USE_ITEM )
2017-10-21 17:32:35 +02:00
{
// Add item to bag if it is a ball
if ( itemId < = ITEM_PREMIER_BALL )
AddBagItem ( itemId , 1 ) ;
else
return ;
}
PlaySE ( SE_SELECT ) ;
2018-02-06 23:09:39 +01:00
BtlController_EmitTwoReturnValues ( 1 , B_ACTION_CANCEL_PARTNER , 0 ) ;
2017-10-21 17:32:35 +02:00
PlayerBufferExecCompleted ( ) ;
}
}
else if ( gMain . newKeys & START_BUTTON )
{
SwapHpBarsWithHpText ( ) ;
}
}
2017-10-22 18:43:15 +02:00
static void sub_80577F0 ( void ) // unused
2017-10-21 17:32:35 +02:00
{
2018-02-06 02:46:59 +01:00
dp11b_obj_free ( gActiveBattler , 1 ) ;
dp11b_obj_free ( gActiveBattler , 0 ) ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = HandleInputChooseTarget ;
2017-10-21 17:32:35 +02:00
}
2017-10-22 18:43:15 +02:00
static void HandleInputChooseTarget ( void )
2017-10-21 17:32:35 +02:00
{
s32 i ;
u8 identities [ 4 ] ;
memcpy ( identities , sTargetIdentities , ARRAY_COUNT ( sTargetIdentities ) ) ;
dp11b_obj_instanciate ( gMultiUsePlayerCursor , 1 , 0xF , 1 ) ;
// what a weird loop
i = 0 ;
2018-02-06 02:46:59 +01:00
if ( gBattlersCount ! = 0 )
2017-10-21 17:32:35 +02:00
{
do
{
if ( i ! = gMultiUsePlayerCursor )
dp11b_obj_free ( i , 1 ) ;
i + + ;
2018-02-06 02:46:59 +01:00
} while ( i < gBattlersCount ) ;
2017-10-21 17:32:35 +02:00
}
if ( gMain . heldKeys & DPAD_ANY & & gSaveBlock2Ptr - > optionsButtonMode = = 2 )
2017-10-27 13:29:18 +02:00
gPlayerDpadHoldFrames + + ;
2017-10-21 17:32:35 +02:00
else
2017-10-27 13:29:18 +02:00
gPlayerDpadHoldFrames = 0 ;
2017-10-21 17:32:35 +02:00
if ( gMain . newKeys & A_BUTTON )
{
PlaySE ( SE_SELECT ) ;
2018-02-06 20:48:02 +01:00
gSprites [ gBattlerSpriteIds [ gMultiUsePlayerCursor ] ] . callback = sub_8039B2C ;
BtlController_EmitTwoReturnValues ( 1 , 10 , gMoveSelectionCursor [ gActiveBattler ] | ( gMultiUsePlayerCursor < < 8 ) ) ;
2017-10-21 17:32:35 +02:00
dp11b_obj_free ( gMultiUsePlayerCursor , 1 ) ;
PlayerBufferExecCompleted ( ) ;
}
2017-10-27 13:29:18 +02:00
else if ( gMain . newKeys & B_BUTTON | | gPlayerDpadHoldFrames > 59 )
2017-10-21 17:32:35 +02:00
{
PlaySE ( SE_SELECT ) ;
2018-02-06 20:48:02 +01:00
gSprites [ gBattlerSpriteIds [ gMultiUsePlayerCursor ] ] . callback = sub_8039B2C ;
gBattlerControllerFuncs [ gActiveBattler ] = HandleInputChooseMove ;
2018-02-06 02:46:59 +01:00
dp11b_obj_instanciate ( gActiveBattler , 1 , 7 , 1 ) ;
dp11b_obj_instanciate ( gActiveBattler , 0 , 7 , 1 ) ;
2017-10-21 17:32:35 +02:00
dp11b_obj_free ( gMultiUsePlayerCursor , 1 ) ;
}
else if ( gMain . newKeys & ( DPAD_LEFT | DPAD_UP ) )
{
PlaySE ( SE_SELECT ) ;
2018-02-06 20:48:02 +01:00
gSprites [ gBattlerSpriteIds [ gMultiUsePlayerCursor ] ] . callback = sub_8039B2C ;
2017-10-21 17:32:35 +02:00
do
{
2018-02-06 02:46:59 +01:00
u8 currSelIdentity = GetBattlerPosition ( gMultiUsePlayerCursor ) ;
2017-10-21 17:32:35 +02:00
2018-02-06 02:46:59 +01:00
for ( i = 0 ; i < MAX_BATTLERS_COUNT ; i + + )
2017-10-21 17:32:35 +02:00
{
if ( currSelIdentity = = identities [ i ] )
break ;
}
do
{
if ( - - i < 0 )
i = 4 ; // UB: array out of range
2018-02-06 02:46:59 +01:00
gMultiUsePlayerCursor = GetBattlerAtPosition ( identities [ i ] ) ;
} while ( gMultiUsePlayerCursor = = gBattlersCount ) ;
2017-10-21 17:32:35 +02:00
i = 0 ;
2018-02-06 02:46:59 +01:00
switch ( GetBattlerPosition ( gMultiUsePlayerCursor ) )
2017-10-21 17:32:35 +02:00
{
2018-01-16 21:01:31 +01:00
case B_POSITION_PLAYER_LEFT :
case B_POSITION_PLAYER_RIGHT :
2018-02-06 02:46:59 +01:00
if ( gActiveBattler ! = gMultiUsePlayerCursor )
2017-10-21 17:32:35 +02:00
i + + ;
2018-02-26 13:24:46 +01:00
else if ( gBattleMoves [ GetMonData ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , MON_DATA_MOVE1 + gMoveSelectionCursor [ gActiveBattler ] ) ] . target & MOVE_TARGET_USER_OR_SELECTED )
2017-10-21 17:32:35 +02:00
i + + ;
break ;
2018-01-16 21:01:31 +01:00
case B_POSITION_OPPONENT_LEFT :
case B_POSITION_OPPONENT_RIGHT :
2017-10-21 17:32:35 +02:00
i + + ;
break ;
}
2018-02-06 02:46:59 +01:00
if ( gAbsentBattlerFlags & gBitTable [ gMultiUsePlayerCursor ] )
2017-10-21 17:32:35 +02:00
i = 0 ;
} while ( i = = 0 ) ;
2018-02-06 20:48:02 +01:00
gSprites [ gBattlerSpriteIds [ gMultiUsePlayerCursor ] ] . callback = sub_8039AD8 ;
2017-10-21 17:32:35 +02:00
}
else if ( gMain . newKeys & ( DPAD_RIGHT | DPAD_DOWN ) )
{
PlaySE ( SE_SELECT ) ;
2018-02-06 20:48:02 +01:00
gSprites [ gBattlerSpriteIds [ gMultiUsePlayerCursor ] ] . callback = sub_8039B2C ;
2017-10-21 17:32:35 +02:00
do
{
2018-02-06 02:46:59 +01:00
u8 currSelIdentity = GetBattlerPosition ( gMultiUsePlayerCursor ) ;
2017-10-21 17:32:35 +02:00
2018-02-06 02:46:59 +01:00
for ( i = 0 ; i < MAX_BATTLERS_COUNT ; i + + )
2017-10-21 17:32:35 +02:00
{
if ( currSelIdentity = = identities [ i ] )
break ;
}
do
{
if ( + + i > 3 )
i = 0 ;
2018-02-06 02:46:59 +01:00
gMultiUsePlayerCursor = GetBattlerAtPosition ( identities [ i ] ) ;
} while ( gMultiUsePlayerCursor = = gBattlersCount ) ;
2017-10-21 17:32:35 +02:00
i = 0 ;
2018-02-06 02:46:59 +01:00
switch ( GetBattlerPosition ( gMultiUsePlayerCursor ) )
2017-10-21 17:32:35 +02:00
{
2018-01-16 21:01:31 +01:00
case B_POSITION_PLAYER_LEFT :
case B_POSITION_PLAYER_RIGHT :
2018-02-06 02:46:59 +01:00
if ( gActiveBattler ! = gMultiUsePlayerCursor )
2017-10-21 17:32:35 +02:00
i + + ;
2018-02-26 13:24:46 +01:00
else if ( gBattleMoves [ GetMonData ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , MON_DATA_MOVE1 + gMoveSelectionCursor [ gActiveBattler ] ) ] . target & MOVE_TARGET_USER_OR_SELECTED )
2017-10-21 17:32:35 +02:00
i + + ;
break ;
2018-01-16 21:01:31 +01:00
case B_POSITION_OPPONENT_LEFT :
case B_POSITION_OPPONENT_RIGHT :
2017-10-21 17:32:35 +02:00
i + + ;
break ;
}
2018-02-06 02:46:59 +01:00
if ( gAbsentBattlerFlags & gBitTable [ gMultiUsePlayerCursor ] )
2017-10-21 17:32:35 +02:00
i = 0 ;
} while ( i = = 0 ) ;
2018-02-06 20:48:02 +01:00
gSprites [ gBattlerSpriteIds [ gMultiUsePlayerCursor ] ] . callback = sub_8039AD8 ;
2017-10-21 17:32:35 +02:00
}
}
2017-10-22 18:43:15 +02:00
static void HandleInputChooseMove ( void )
2017-10-21 17:32:35 +02:00
{
bool32 canSelectTarget = FALSE ;
2018-02-06 02:46:59 +01:00
struct ChooseMoveStruct * moveInfo = ( struct ChooseMoveStruct * ) ( & gBattleBufferA [ gActiveBattler ] [ 4 ] ) ;
2017-10-21 17:32:35 +02:00
if ( gMain . heldKeys & DPAD_ANY & & gSaveBlock2Ptr - > optionsButtonMode = = 2 )
2017-10-27 13:29:18 +02:00
gPlayerDpadHoldFrames + + ;
2017-10-21 17:32:35 +02:00
else
2017-10-27 13:29:18 +02:00
gPlayerDpadHoldFrames = 0 ;
2017-10-21 17:32:35 +02:00
if ( gMain . newKeys & A_BUTTON )
{
u8 moveTarget ;
PlaySE ( SE_SELECT ) ;
2018-02-06 02:46:59 +01:00
if ( moveInfo - > moves [ gMoveSelectionCursor [ gActiveBattler ] ] = = MOVE_CURSE )
2017-10-21 17:32:35 +02:00
{
if ( moveInfo - > monType1 ! = TYPE_GHOST & & moveInfo - > monType2 ! = TYPE_GHOST )
2018-02-26 13:24:46 +01:00
moveTarget = MOVE_TARGET_USER ;
2017-10-21 17:32:35 +02:00
else
moveTarget = MOVE_TARGET_SELECTED ;
}
else
{
2018-02-06 02:46:59 +01:00
moveTarget = gBattleMoves [ moveInfo - > moves [ gMoveSelectionCursor [ gActiveBattler ] ] ] . target ;
2017-10-21 17:32:35 +02:00
}
2018-02-26 13:24:46 +01:00
if ( moveTarget & MOVE_TARGET_USER )
2018-02-06 02:46:59 +01:00
gMultiUsePlayerCursor = gActiveBattler ;
2017-10-21 17:32:35 +02:00
else
2018-02-06 02:46:59 +01:00
gMultiUsePlayerCursor = GetBattlerAtPosition ( ( GetBattlerPosition ( gActiveBattler ) & BIT_SIDE ) ^ BIT_SIDE ) ;
2017-10-21 17:32:35 +02:00
2018-02-06 02:46:59 +01:00
if ( ! gBattleBufferA [ gActiveBattler ] [ 1 ] ) // not a double battle
2017-10-21 17:32:35 +02:00
{
2018-02-26 13:24:46 +01:00
if ( moveTarget & MOVE_TARGET_USER_OR_SELECTED & & ! gBattleBufferA [ gActiveBattler ] [ 2 ] )
2017-10-21 17:32:35 +02:00
canSelectTarget + + ;
}
else // double battle
{
2018-02-26 13:24:46 +01:00
if ( ! ( moveTarget & ( MOVE_TARGET_RANDOM | MOVE_TARGET_BOTH | MOVE_TARGET_DEPENDS | MOVE_TARGET_FOES_AND_ALLY | MOVE_TARGET_OPPONENTS_FIELD | MOVE_TARGET_USER ) ) )
2017-10-21 17:32:35 +02:00
canSelectTarget + + ; // either selected or user
2018-02-06 02:46:59 +01:00
if ( moveInfo - > currentPp [ gMoveSelectionCursor [ gActiveBattler ] ] = = 0 )
2017-10-21 17:32:35 +02:00
{
canSelectTarget = FALSE ;
}
2018-02-26 13:24:46 +01:00
else if ( ! ( moveTarget & ( MOVE_TARGET_USER | MOVE_TARGET_USER_OR_SELECTED ) ) & & CountAliveMonsInBattle ( BATTLE_ALIVE_EXCEPT_ACTIVE ) < = 1 )
2017-10-21 17:32:35 +02:00
{
2018-02-06 02:46:59 +01:00
gMultiUsePlayerCursor = GetDefaultMoveTarget ( gActiveBattler ) ;
2017-10-21 17:32:35 +02:00
canSelectTarget = FALSE ;
}
}
if ( ! canSelectTarget )
{
2018-02-06 20:48:02 +01:00
BtlController_EmitTwoReturnValues ( 1 , 10 , gMoveSelectionCursor [ gActiveBattler ] | ( gMultiUsePlayerCursor < < 8 ) ) ;
2017-10-21 17:32:35 +02:00
PlayerBufferExecCompleted ( ) ;
}
else
{
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = HandleInputChooseTarget ;
2017-10-21 17:32:35 +02:00
2018-02-26 13:24:46 +01:00
if ( moveTarget & ( MOVE_TARGET_USER | MOVE_TARGET_USER_OR_SELECTED ) )
2018-02-06 02:46:59 +01:00
gMultiUsePlayerCursor = gActiveBattler ;
else if ( gAbsentBattlerFlags & gBitTable [ GetBattlerAtPosition ( B_POSITION_OPPONENT_LEFT ) ] )
gMultiUsePlayerCursor = GetBattlerAtPosition ( B_POSITION_OPPONENT_RIGHT ) ;
2017-10-21 17:32:35 +02:00
else
2018-02-06 02:46:59 +01:00
gMultiUsePlayerCursor = GetBattlerAtPosition ( B_POSITION_OPPONENT_LEFT ) ;
2017-10-21 17:32:35 +02:00
2018-02-06 20:48:02 +01:00
gSprites [ gBattlerSpriteIds [ gMultiUsePlayerCursor ] ] . callback = sub_8039AD8 ;
2017-10-21 17:32:35 +02:00
}
}
2017-10-27 13:29:18 +02:00
else if ( gMain . newKeys & B_BUTTON | | gPlayerDpadHoldFrames > 59 )
2017-10-21 17:32:35 +02:00
{
PlaySE ( SE_SELECT ) ;
2018-02-06 20:48:02 +01:00
BtlController_EmitTwoReturnValues ( 1 , 10 , 0xFFFF ) ;
2017-10-21 17:32:35 +02:00
PlayerBufferExecCompleted ( ) ;
}
else if ( gMain . newKeys & DPAD_LEFT )
{
2018-02-06 02:46:59 +01:00
if ( gMoveSelectionCursor [ gActiveBattler ] & 1 )
2017-10-21 17:32:35 +02:00
{
2018-02-06 02:46:59 +01:00
MoveSelectionDestroyCursorAt ( gMoveSelectionCursor [ gActiveBattler ] ) ;
gMoveSelectionCursor [ gActiveBattler ] ^ = 1 ;
2017-10-21 17:32:35 +02:00
PlaySE ( SE_SELECT ) ;
2018-02-06 02:46:59 +01:00
MoveSelectionCreateCursorAt ( gMoveSelectionCursor [ gActiveBattler ] , 0 ) ;
2017-10-21 17:32:35 +02:00
MoveSelectionDisplayPpNumber ( ) ;
MoveSelectionDisplayMoveType ( ) ;
}
}
else if ( gMain . newKeys & DPAD_RIGHT )
{
2018-02-06 02:46:59 +01:00
if ( ! ( gMoveSelectionCursor [ gActiveBattler ] & 1 )
& & ( gMoveSelectionCursor [ gActiveBattler ] ^ 1 ) < gNumberOfMovesToChoose )
2017-10-21 17:32:35 +02:00
{
2018-02-06 02:46:59 +01:00
MoveSelectionDestroyCursorAt ( gMoveSelectionCursor [ gActiveBattler ] ) ;
gMoveSelectionCursor [ gActiveBattler ] ^ = 1 ;
2017-10-21 17:32:35 +02:00
PlaySE ( SE_SELECT ) ;
2018-02-06 02:46:59 +01:00
MoveSelectionCreateCursorAt ( gMoveSelectionCursor [ gActiveBattler ] , 0 ) ;
2017-10-21 17:32:35 +02:00
MoveSelectionDisplayPpNumber ( ) ;
MoveSelectionDisplayMoveType ( ) ;
}
}
else if ( gMain . newKeys & DPAD_UP )
{
2018-02-06 02:46:59 +01:00
if ( gMoveSelectionCursor [ gActiveBattler ] & 2 )
2017-10-21 17:32:35 +02:00
{
2018-02-06 02:46:59 +01:00
MoveSelectionDestroyCursorAt ( gMoveSelectionCursor [ gActiveBattler ] ) ;
gMoveSelectionCursor [ gActiveBattler ] ^ = 2 ;
2017-10-21 17:32:35 +02:00
PlaySE ( SE_SELECT ) ;
2018-02-06 02:46:59 +01:00
MoveSelectionCreateCursorAt ( gMoveSelectionCursor [ gActiveBattler ] , 0 ) ;
2017-10-21 17:32:35 +02:00
MoveSelectionDisplayPpNumber ( ) ;
MoveSelectionDisplayMoveType ( ) ;
}
}
else if ( gMain . newKeys & DPAD_DOWN )
{
2018-02-06 02:46:59 +01:00
if ( ! ( gMoveSelectionCursor [ gActiveBattler ] & 2 )
& & ( gMoveSelectionCursor [ gActiveBattler ] ^ 2 ) < gNumberOfMovesToChoose )
2017-10-21 17:32:35 +02:00
{
2018-02-06 02:46:59 +01:00
MoveSelectionDestroyCursorAt ( gMoveSelectionCursor [ gActiveBattler ] ) ;
gMoveSelectionCursor [ gActiveBattler ] ^ = 2 ;
2017-10-21 17:32:35 +02:00
PlaySE ( SE_SELECT ) ;
2018-02-06 02:46:59 +01:00
MoveSelectionCreateCursorAt ( gMoveSelectionCursor [ gActiveBattler ] , 0 ) ;
2017-10-21 17:32:35 +02:00
MoveSelectionDisplayPpNumber ( ) ;
MoveSelectionDisplayMoveType ( ) ;
}
}
else if ( gMain . newKeys & SELECT_BUTTON )
{
if ( gNumberOfMovesToChoose > 1 & & ! ( gBattleTypeFlags & BATTLE_TYPE_LINK ) )
{
2018-02-06 02:46:59 +01:00
MoveSelectionCreateCursorAt ( gMoveSelectionCursor [ gActiveBattler ] , 29 ) ;
2017-10-21 17:32:35 +02:00
2018-02-06 02:46:59 +01:00
if ( gMoveSelectionCursor [ gActiveBattler ] ! = 0 )
2017-10-21 17:32:35 +02:00
gMultiUsePlayerCursor = 0 ;
else
2018-02-06 02:46:59 +01:00
gMultiUsePlayerCursor = gMoveSelectionCursor [ gActiveBattler ] + 1 ;
2017-10-21 17:32:35 +02:00
MoveSelectionCreateCursorAt ( gMultiUsePlayerCursor , 27 ) ;
2018-06-17 16:48:58 +02:00
BattlePutTextOnWindow ( gText_BattleSwitchWhich , 0xB ) ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = HandleMoveSwitchting ;
2017-10-21 17:32:35 +02:00
}
}
}
u32 sub_8057FBC ( void ) // unused
{
u32 var = 0 ;
if ( gMain . newKeys & A_BUTTON )
{
PlaySE ( SE_SELECT ) ;
var = 1 ;
}
if ( gMain . newKeys & B_BUTTON )
{
PlaySE ( SE_SELECT ) ;
gBattle_BG0_X = 0 ;
gBattle_BG0_Y = 0x140 ;
var = 0xFF ;
}
2018-02-06 02:46:59 +01:00
if ( gMain . newKeys & DPAD_LEFT & & gMoveSelectionCursor [ gActiveBattler ] & 1 )
2017-10-21 17:32:35 +02:00
{
2018-02-06 02:46:59 +01:00
MoveSelectionDestroyCursorAt ( gMoveSelectionCursor [ gActiveBattler ] ) ;
gMoveSelectionCursor [ gActiveBattler ] ^ = 1 ;
2017-10-21 17:32:35 +02:00
PlaySE ( SE_SELECT ) ;
2018-02-06 02:46:59 +01:00
MoveSelectionCreateCursorAt ( gMoveSelectionCursor [ gActiveBattler ] , 0 ) ;
2017-10-21 17:32:35 +02:00
}
2018-02-06 02:46:59 +01:00
if ( gMain . newKeys & DPAD_RIGHT & & ! ( gMoveSelectionCursor [ gActiveBattler ] & 1 )
& & ( gMoveSelectionCursor [ gActiveBattler ] ^ 1 ) < gNumberOfMovesToChoose )
2017-10-21 17:32:35 +02:00
{
2018-02-06 02:46:59 +01:00
MoveSelectionDestroyCursorAt ( gMoveSelectionCursor [ gActiveBattler ] ) ;
gMoveSelectionCursor [ gActiveBattler ] ^ = 1 ;
2017-10-21 17:32:35 +02:00
PlaySE ( SE_SELECT ) ;
2018-02-06 02:46:59 +01:00
MoveSelectionCreateCursorAt ( gMoveSelectionCursor [ gActiveBattler ] , 0 ) ;
2017-10-21 17:32:35 +02:00
}
2018-02-06 02:46:59 +01:00
if ( gMain . newKeys & DPAD_UP & & gMoveSelectionCursor [ gActiveBattler ] & 2 )
2017-10-21 17:32:35 +02:00
{
2018-02-06 02:46:59 +01:00
MoveSelectionDestroyCursorAt ( gMoveSelectionCursor [ gActiveBattler ] ) ;
gMoveSelectionCursor [ gActiveBattler ] ^ = 2 ;
2017-10-21 17:32:35 +02:00
PlaySE ( SE_SELECT ) ;
2018-02-06 02:46:59 +01:00
MoveSelectionCreateCursorAt ( gMoveSelectionCursor [ gActiveBattler ] , 0 ) ;
2017-10-21 17:32:35 +02:00
}
2018-02-06 02:46:59 +01:00
if ( gMain . newKeys & DPAD_DOWN & & ! ( gMoveSelectionCursor [ gActiveBattler ] & 2 )
& & ( gMoveSelectionCursor [ gActiveBattler ] ^ 2 ) < gNumberOfMovesToChoose )
2017-10-21 17:32:35 +02:00
{
2018-02-06 02:46:59 +01:00
MoveSelectionDestroyCursorAt ( gMoveSelectionCursor [ gActiveBattler ] ) ;
gMoveSelectionCursor [ gActiveBattler ] ^ = 2 ;
2017-10-21 17:32:35 +02:00
PlaySE ( SE_SELECT ) ;
2018-02-06 02:46:59 +01:00
MoveSelectionCreateCursorAt ( gMoveSelectionCursor [ gActiveBattler ] , 0 ) ;
2017-10-21 17:32:35 +02:00
}
return var ;
}
2017-10-22 18:43:15 +02:00
static void HandleMoveSwitchting ( void )
2017-10-21 17:32:35 +02:00
{
u8 perMovePPBonuses [ 4 ] ;
struct ChooseMoveStruct moveStruct ;
u8 totalPPBonuses ;
if ( gMain . newKeys & ( A_BUTTON | SELECT_BUTTON ) )
{
PlaySE ( SE_SELECT ) ;
2018-02-06 02:46:59 +01:00
if ( gMoveSelectionCursor [ gActiveBattler ] ! = gMultiUsePlayerCursor )
2017-10-21 17:32:35 +02:00
{
2018-02-06 02:46:59 +01:00
struct ChooseMoveStruct * moveInfo = ( struct ChooseMoveStruct * ) ( & gBattleBufferA [ gActiveBattler ] [ 4 ] ) ;
2017-10-21 17:32:35 +02:00
s32 i ;
// swap moves and pp
2018-02-06 02:46:59 +01:00
i = moveInfo - > moves [ gMoveSelectionCursor [ gActiveBattler ] ] ;
moveInfo - > moves [ gMoveSelectionCursor [ gActiveBattler ] ] = moveInfo - > moves [ gMultiUsePlayerCursor ] ;
2017-10-21 17:32:35 +02:00
moveInfo - > moves [ gMultiUsePlayerCursor ] = i ;
2018-02-06 02:46:59 +01:00
i = moveInfo - > currentPp [ gMoveSelectionCursor [ gActiveBattler ] ] ;
moveInfo - > currentPp [ gMoveSelectionCursor [ gActiveBattler ] ] = moveInfo - > currentPp [ gMultiUsePlayerCursor ] ;
2017-10-21 17:32:35 +02:00
moveInfo - > currentPp [ gMultiUsePlayerCursor ] = i ;
2018-02-06 02:46:59 +01:00
i = moveInfo - > maxPp [ gMoveSelectionCursor [ gActiveBattler ] ] ;
moveInfo - > maxPp [ gMoveSelectionCursor [ gActiveBattler ] ] = moveInfo - > maxPp [ gMultiUsePlayerCursor ] ;
2017-10-21 17:32:35 +02:00
moveInfo - > maxPp [ gMultiUsePlayerCursor ] = i ;
2018-02-06 02:46:59 +01:00
if ( gDisableStructs [ gActiveBattler ] . unk18_b & gBitTable [ gMoveSelectionCursor [ gActiveBattler ] ] )
2017-10-21 17:32:35 +02:00
{
2018-02-06 02:46:59 +01:00
gDisableStructs [ gActiveBattler ] . unk18_b & = ( ~ gBitTable [ gMoveSelectionCursor [ gActiveBattler ] ] ) ;
gDisableStructs [ gActiveBattler ] . unk18_b | = gBitTable [ gMultiUsePlayerCursor ] ;
2017-10-21 17:32:35 +02:00
}
MoveSelectionDisplayMoveNames ( ) ;
for ( i = 0 ; i < 4 ; i + + )
2018-02-06 02:46:59 +01:00
perMovePPBonuses [ i ] = ( gBattleMons [ gActiveBattler ] . ppBonuses & ( 3 < < ( i * 2 ) ) ) > > ( i * 2 ) ;
2017-10-21 17:32:35 +02:00
2018-02-06 02:46:59 +01:00
totalPPBonuses = perMovePPBonuses [ gMoveSelectionCursor [ gActiveBattler ] ] ;
perMovePPBonuses [ gMoveSelectionCursor [ gActiveBattler ] ] = perMovePPBonuses [ gMultiUsePlayerCursor ] ;
2017-10-21 17:32:35 +02:00
perMovePPBonuses [ gMultiUsePlayerCursor ] = totalPPBonuses ;
totalPPBonuses = 0 ;
for ( i = 0 ; i < 4 ; i + + )
totalPPBonuses | = perMovePPBonuses [ i ] < < ( i * 2 ) ;
2018-02-06 02:46:59 +01:00
gBattleMons [ gActiveBattler ] . ppBonuses = totalPPBonuses ;
2017-10-21 17:32:35 +02:00
for ( i = 0 ; i < 4 ; i + + )
{
2018-02-06 02:46:59 +01:00
gBattleMons [ gActiveBattler ] . moves [ i ] = moveInfo - > moves [ i ] ;
gBattleMons [ gActiveBattler ] . pp [ i ] = moveInfo - > currentPp [ i ] ;
2017-10-21 17:32:35 +02:00
}
2018-02-06 02:46:59 +01:00
if ( ! ( gBattleMons [ gActiveBattler ] . status2 & STATUS2_TRANSFORMED ) )
2017-10-21 17:32:35 +02:00
{
for ( i = 0 ; i < 4 ; i + + )
{
2018-02-06 20:48:02 +01:00
moveStruct . moves [ i ] = GetMonData ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , MON_DATA_MOVE1 + i ) ;
moveStruct . currentPp [ i ] = GetMonData ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , MON_DATA_PP1 + i ) ;
2017-10-21 17:32:35 +02:00
}
2018-02-06 20:48:02 +01:00
totalPPBonuses = GetMonData ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , MON_DATA_PP_BONUSES ) ;
2017-10-21 17:32:35 +02:00
for ( i = 0 ; i < 4 ; i + + )
perMovePPBonuses [ i ] = ( totalPPBonuses & ( 3 < < ( i * 2 ) ) ) > > ( i * 2 ) ;
2018-02-06 02:46:59 +01:00
i = moveStruct . moves [ gMoveSelectionCursor [ gActiveBattler ] ] ;
moveStruct . moves [ gMoveSelectionCursor [ gActiveBattler ] ] = moveStruct . moves [ gMultiUsePlayerCursor ] ;
2017-10-21 17:32:35 +02:00
moveStruct . moves [ gMultiUsePlayerCursor ] = i ;
2018-02-06 02:46:59 +01:00
i = moveStruct . currentPp [ gMoveSelectionCursor [ gActiveBattler ] ] ;
moveStruct . currentPp [ gMoveSelectionCursor [ gActiveBattler ] ] = moveStruct . currentPp [ gMultiUsePlayerCursor ] ;
2017-10-21 17:32:35 +02:00
moveStruct . currentPp [ gMultiUsePlayerCursor ] = i ;
2018-02-06 02:46:59 +01:00
totalPPBonuses = perMovePPBonuses [ gMoveSelectionCursor [ gActiveBattler ] ] ;
perMovePPBonuses [ gMoveSelectionCursor [ gActiveBattler ] ] = perMovePPBonuses [ gMultiUsePlayerCursor ] ;
2017-10-21 17:32:35 +02:00
perMovePPBonuses [ gMultiUsePlayerCursor ] = totalPPBonuses ;
totalPPBonuses = 0 ;
for ( i = 0 ; i < 4 ; i + + )
totalPPBonuses | = perMovePPBonuses [ i ] < < ( i * 2 ) ;
for ( i = 0 ; i < 4 ; i + + )
{
2018-02-06 20:48:02 +01:00
SetMonData ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , MON_DATA_MOVE1 + i , & moveStruct . moves [ i ] ) ;
SetMonData ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , MON_DATA_PP1 + i , & moveStruct . currentPp [ i ] ) ;
2017-10-21 17:32:35 +02:00
}
2018-02-06 20:48:02 +01:00
SetMonData ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , MON_DATA_PP_BONUSES , & totalPPBonuses ) ;
2017-10-21 17:32:35 +02:00
}
}
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = HandleInputChooseMove ;
2018-02-06 02:46:59 +01:00
gMoveSelectionCursor [ gActiveBattler ] = gMultiUsePlayerCursor ;
MoveSelectionCreateCursorAt ( gMoveSelectionCursor [ gActiveBattler ] , 0 ) ;
2017-10-21 17:32:35 +02:00
MoveSelectionDisplayPpString ( ) ;
MoveSelectionDisplayPpNumber ( ) ;
MoveSelectionDisplayMoveType ( ) ;
}
else if ( gMain . newKeys & ( B_BUTTON | SELECT_BUTTON ) )
{
PlaySE ( SE_SELECT ) ;
MoveSelectionDestroyCursorAt ( gMultiUsePlayerCursor ) ;
2018-02-06 02:46:59 +01:00
MoveSelectionCreateCursorAt ( gMoveSelectionCursor [ gActiveBattler ] , 0 ) ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = HandleInputChooseMove ;
2017-10-21 17:32:35 +02:00
MoveSelectionDisplayPpString ( ) ;
MoveSelectionDisplayPpNumber ( ) ;
MoveSelectionDisplayMoveType ( ) ;
}
else if ( gMain . newKeys & DPAD_LEFT )
{
if ( gMultiUsePlayerCursor & 1 )
{
2018-02-06 02:46:59 +01:00
if ( gMultiUsePlayerCursor = = gMoveSelectionCursor [ gActiveBattler ] )
MoveSelectionCreateCursorAt ( gMoveSelectionCursor [ gActiveBattler ] , 29 ) ;
2017-10-21 17:32:35 +02:00
else
MoveSelectionDestroyCursorAt ( gMultiUsePlayerCursor ) ;
gMultiUsePlayerCursor ^ = 1 ;
PlaySE ( SE_SELECT ) ;
2018-02-06 02:46:59 +01:00
if ( gMultiUsePlayerCursor = = gMoveSelectionCursor [ gActiveBattler ] )
2017-10-21 17:32:35 +02:00
MoveSelectionCreateCursorAt ( gMultiUsePlayerCursor , 0 ) ;
else
MoveSelectionCreateCursorAt ( gMultiUsePlayerCursor , 27 ) ;
}
}
else if ( gMain . newKeys & DPAD_RIGHT )
{
if ( ! ( gMultiUsePlayerCursor & 1 ) & & ( gMultiUsePlayerCursor ^ 1 ) < gNumberOfMovesToChoose )
{
2018-02-06 02:46:59 +01:00
if ( gMultiUsePlayerCursor = = gMoveSelectionCursor [ gActiveBattler ] )
MoveSelectionCreateCursorAt ( gMoveSelectionCursor [ gActiveBattler ] , 29 ) ;
2017-10-21 17:32:35 +02:00
else
MoveSelectionDestroyCursorAt ( gMultiUsePlayerCursor ) ;
gMultiUsePlayerCursor ^ = 1 ;
PlaySE ( SE_SELECT ) ;
2018-02-06 02:46:59 +01:00
if ( gMultiUsePlayerCursor = = gMoveSelectionCursor [ gActiveBattler ] )
2017-10-21 17:32:35 +02:00
MoveSelectionCreateCursorAt ( gMultiUsePlayerCursor , 0 ) ;
else
MoveSelectionCreateCursorAt ( gMultiUsePlayerCursor , 27 ) ;
}
}
else if ( gMain . newKeys & DPAD_UP )
{
if ( gMultiUsePlayerCursor & 2 )
{
2018-02-06 02:46:59 +01:00
if ( gMultiUsePlayerCursor = = gMoveSelectionCursor [ gActiveBattler ] )
MoveSelectionCreateCursorAt ( gMoveSelectionCursor [ gActiveBattler ] , 29 ) ;
2017-10-21 17:32:35 +02:00
else
MoveSelectionDestroyCursorAt ( gMultiUsePlayerCursor ) ;
gMultiUsePlayerCursor ^ = 2 ;
PlaySE ( SE_SELECT ) ;
2018-02-06 02:46:59 +01:00
if ( gMultiUsePlayerCursor = = gMoveSelectionCursor [ gActiveBattler ] )
2017-10-21 17:32:35 +02:00
MoveSelectionCreateCursorAt ( gMultiUsePlayerCursor , 0 ) ;
else
MoveSelectionCreateCursorAt ( gMultiUsePlayerCursor , 27 ) ;
}
}
else if ( gMain . newKeys & DPAD_DOWN )
{
if ( ! ( gMultiUsePlayerCursor & 2 ) & & ( gMultiUsePlayerCursor ^ 2 ) < gNumberOfMovesToChoose )
{
2018-02-06 02:46:59 +01:00
if ( gMultiUsePlayerCursor = = gMoveSelectionCursor [ gActiveBattler ] )
MoveSelectionCreateCursorAt ( gMoveSelectionCursor [ gActiveBattler ] , 29 ) ;
2017-10-21 17:32:35 +02:00
else
MoveSelectionDestroyCursorAt ( gMultiUsePlayerCursor ) ;
gMultiUsePlayerCursor ^ = 2 ;
PlaySE ( SE_SELECT ) ;
2018-02-06 02:46:59 +01:00
if ( gMultiUsePlayerCursor = = gMoveSelectionCursor [ gActiveBattler ] )
2017-10-21 17:32:35 +02:00
MoveSelectionCreateCursorAt ( gMultiUsePlayerCursor , 0 ) ;
else
MoveSelectionCreateCursorAt ( gMultiUsePlayerCursor , 27 ) ;
}
}
}
2017-10-22 18:43:15 +02:00
static void sub_80586F8 ( void )
2017-10-21 17:32:35 +02:00
{
2017-11-13 05:58:05 +01:00
if ( gWirelessCommType = = 0 )
2017-10-21 17:32:35 +02:00
{
if ( gReceivedRemoteLinkPlayers = = 0 )
{
m4aSongNumStop ( SE_HINSI ) ;
gMain . inBattle = 0 ;
gMain . callback1 = gPreBattleCallback1 ;
SetMainCallback2 ( sub_8038D64 ) ;
2018-01-16 22:12:38 +01:00
if ( gBattleOutcome = = B_OUTCOME_WON )
2018-02-27 20:40:09 +01:00
TryPutLinkBattleTvShowOnAir ( ) ;
2017-10-21 17:32:35 +02:00
FreeAllWindowBuffers ( ) ;
}
}
else
{
if ( sub_800A520 ( ) )
{
m4aSongNumStop ( SE_HINSI ) ;
gMain . inBattle = 0 ;
gMain . callback1 = gPreBattleCallback1 ;
SetMainCallback2 ( sub_8038D64 ) ;
2018-01-16 22:12:38 +01:00
if ( gBattleOutcome = = B_OUTCOME_WON )
2018-02-27 20:40:09 +01:00
TryPutLinkBattleTvShowOnAir ( ) ;
2017-10-21 17:32:35 +02:00
FreeAllWindowBuffers ( ) ;
}
}
}
void sub_80587B0 ( void )
{
if ( ! gPaletteFade . active )
{
if ( gBattleTypeFlags & BATTLE_TYPE_LINK )
{
if ( sub_800A520 ( ) )
{
2017-11-13 05:58:05 +01:00
if ( gWirelessCommType = = 0 )
2017-10-21 17:32:35 +02:00
sub_800AC34 ( ) ;
else
sub_800ADF8 ( ) ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = sub_80586F8 ;
2017-10-21 17:32:35 +02:00
}
}
else
{
m4aSongNumStop ( SE_HINSI ) ;
gMain . inBattle = 0 ;
gMain . callback1 = gPreBattleCallback1 ;
SetMainCallback2 ( gMain . savedCallback ) ;
}
}
}
2017-10-22 18:43:15 +02:00
static void CompleteOnBankSpriteCallbackDummy ( void )
2017-10-21 17:32:35 +02:00
{
2018-02-06 20:48:02 +01:00
if ( gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . callback = = SpriteCallbackDummy )
2017-10-21 17:32:35 +02:00
PlayerBufferExecCompleted ( ) ;
}
2017-10-22 18:43:15 +02:00
static void CompleteOnBankSpriteCallbackDummy2 ( void )
2017-10-21 17:32:35 +02:00
{
2018-02-06 20:48:02 +01:00
if ( gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . callback = = SpriteCallbackDummy )
2017-10-21 17:32:35 +02:00
PlayerBufferExecCompleted ( ) ;
}
2017-10-22 18:43:15 +02:00
static void sub_80588B4 ( void )
2017-10-21 17:32:35 +02:00
{
2018-02-06 20:48:02 +01:00
if ( gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . callback = = SpriteCallbackDummy )
2017-10-21 17:32:35 +02:00
{
nullsub_25 ( gSaveBlock2Ptr - > playerGender ) ;
2018-02-06 20:48:02 +01:00
FreeSpriteOamMatrix ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] ) ;
DestroySprite ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] ) ;
2017-10-21 17:32:35 +02:00
PlayerBufferExecCompleted ( ) ;
}
}
2017-10-22 18:43:15 +02:00
static void sub_8058924 ( void )
2017-10-21 17:32:35 +02:00
{
2018-02-06 02:46:59 +01:00
if ( - - gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . field_9 = = 0xFF )
2017-10-21 17:32:35 +02:00
{
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . field_9 = 0 ;
2017-10-21 17:32:35 +02:00
PlayerBufferExecCompleted ( ) ;
}
}
2017-10-22 18:43:15 +02:00
static void sub_805896C ( void )
2017-10-21 17:32:35 +02:00
{
bool8 var = FALSE ;
if ( ! IsDoubleBattle ( ) | | ( IsDoubleBattle ( ) & & ( gBattleTypeFlags & BATTLE_TYPE_MULTI ) ) )
{
2018-02-06 20:48:02 +01:00
if ( gSprites [ gHealthboxSpriteIds [ gActiveBattler ] ] . callback = = SpriteCallbackDummy )
2017-10-21 17:32:35 +02:00
var = 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-21 17:32:35 +02:00
var = TRUE ;
}
2018-02-06 02:46:59 +01:00
if ( var & & gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . field_1_x1
& & gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ^ BIT_FLANK ] . field_1_x1 )
2017-10-21 17:32:35 +02:00
{
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . flag_x80 = 0 ;
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . field_1_x1 = 0 ;
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ^ BIT_FLANK ] . flag_x80 = 0 ;
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ^ BIT_FLANK ] . field_1_x1 = 0 ;
2017-10-21 17:32:35 +02:00
FreeSpriteTilesByTag ( 0x27F9 ) ;
FreeSpritePaletteByTag ( 0x27F9 ) ;
2018-02-06 20:48:02 +01:00
HandleLowHpMusicChange ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , gActiveBattler ) ;
2017-10-21 17:32:35 +02:00
if ( IsDoubleBattle ( ) )
2018-02-06 20:48:02 +01:00
HandleLowHpMusicChange ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ^ BIT_FLANK ] ] , gActiveBattler ^ BIT_FLANK ) ;
2017-10-21 17:32:35 +02:00
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_8058924 ;
2017-10-21 17:32:35 +02:00
}
}
2017-10-22 18:43:15 +02:00
static void sub_8058B40 ( void )
2017-10-21 17:32:35 +02:00
{
bool32 r9 = FALSE ;
bool32 r8 = FALSE ;
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . flag_x80 & & ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . ballAnimActive )
2018-02-06 20:48:02 +01:00
sub_8172EF0 ( gActiveBattler , & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] ) ;
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ^ BIT_FLANK ] . flag_x80 & & ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ^ BIT_FLANK ] . ballAnimActive )
2018-02-06 20:48:02 +01:00
sub_8172EF0 ( gActiveBattler ^ BIT_FLANK , & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ^ BIT_FLANK ] ] ) ;
2017-10-21 17:32:35 +02:00
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . ballAnimActive & & ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ^ BIT_FLANK ] . ballAnimActive )
2017-10-21 17:32:35 +02:00
{
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . field_1_x80 )
2017-10-21 17:32:35 +02:00
{
if ( IsDoubleBattle ( ) & & ! ( gBattleTypeFlags & BATTLE_TYPE_MULTI ) )
{
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-21 17:32:35 +02:00
}
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-21 17:32:35 +02:00
}
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . field_1_x80 = 1 ;
2017-10-21 17:32:35 +02:00
}
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . field_1_x40
& & gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . field_1_x80
& & ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ^ BIT_FLANK ] . field_1_x40
2017-10-21 17:32:35 +02:00
& & ! IsCryPlayingOrClearCrySongs ( ) )
{
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . field_1_x20 )
2017-10-21 17:32:35 +02:00
{
if ( gBattleTypeFlags & BATTLE_TYPE_MULTI & & gBattleTypeFlags & BATTLE_TYPE_LINK )
2018-01-10 04:30:54 +01:00
m4aMPlayContinue ( & gMPlayInfo_BGM ) ;
2017-10-21 17:32:35 +02:00
else
2018-01-10 04:30:54 +01:00
m4aMPlayVolumeControl ( & gMPlayInfo_BGM , 0xFFFF , 0x100 ) ;
2017-10-21 17:32:35 +02:00
}
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . field_1_x20 = 1 ;
2017-10-21 17:32:35 +02:00
r9 = TRUE ;
}
if ( ! IsDoubleBattle ( ) | | ( IsDoubleBattle ( ) & & ( gBattleTypeFlags & BATTLE_TYPE_MULTI ) ) )
{
2018-02-06 02:46:59 +01:00
if ( gSprites [ gUnknown_03005D7C [ gActiveBattler ] ] . callback = = SpriteCallbackDummy
2018-02-06 20:48:02 +01:00
& & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . callback = = SpriteCallbackDummy )
2017-10-21 17:32:35 +02:00
{
r8 = TRUE ;
}
}
else
{
2018-02-06 02:46:59 +01:00
if ( 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
& & gSprites [ gUnknown_03005D7C [ gActiveBattler ^ BIT_FLANK ] ] . callback = = SpriteCallbackDummy
2018-02-06 20:48:02 +01:00
& & gSprites [ gBattlerSpriteIds [ gActiveBattler ^ BIT_FLANK ] ] . callback = = SpriteCallbackDummy )
2017-10-21 17:32:35 +02:00
{
r8 = TRUE ;
}
}
if ( r9 & & r8 )
{
if ( IsDoubleBattle ( ) & & ! ( gBattleTypeFlags & BATTLE_TYPE_MULTI ) )
2018-02-06 02:46:59 +01:00
DestroySprite ( & gSprites [ gUnknown_03005D7C [ gActiveBattler ^ BIT_FLANK ] ] ) ;
DestroySprite ( & gSprites [ gUnknown_03005D7C [ gActiveBattler ] ] ) ;
2017-10-21 17:32:35 +02:00
gBattleSpritesDataPtr - > animationData - > field_9_x1 = 0 ;
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . field_1_x20 = 0 ;
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . field_1_x80 = 0 ;
2017-10-21 17:32:35 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = sub_805896C ;
2017-10-21 17:32:35 +02:00
}
}
2017-10-22 18:43:15 +02:00
static void sub_8058EDC ( void )
2017-10-21 17:32:35 +02:00
{
2018-02-06 20:48:02 +01:00
if ( gSprites [ gHealthboxSpriteIds [ gActiveBattler ] ] . callback = = SpriteCallbackDummy
2018-02-06 02:46:59 +01:00
& & gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . field_1_x1
2018-02-06 20:48:02 +01:00
& & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . callback = = SpriteCallbackDummy )
2017-10-21 17:32:35 +02:00
{
2018-02-06 02:46:59 +01:00
CopyBattleSpriteInvisibility ( gActiveBattler ) ;
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . flag_x80 = 0 ;
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . field_1_x1 = 0 ;
2017-10-21 17:32:35 +02:00
FreeSpriteTilesByTag ( 0x27F9 ) ;
FreeSpritePaletteByTag ( 0x27F9 ) ;
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-21 17:32:35 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = sub_8058FC0 ;
2017-10-21 17:32:35 +02:00
}
}
2017-10-22 18:43:15 +02:00
static void sub_8058FC0 ( void )
2017-10-21 17:32:35 +02:00
{
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . specialAnimActive
2017-10-21 17:32:35 +02:00
& & ! IsCryPlayingOrClearCrySongs ( ) )
{
2018-01-10 04:30:54 +01:00
m4aMPlayVolumeControl ( & gMPlayInfo_BGM , 0xFFFF , 0x100 ) ;
2018-02-06 20:48:02 +01:00
HandleLowHpMusicChange ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , gActiveBattler ) ;
2017-10-21 17:32:35 +02:00
PlayerBufferExecCompleted ( ) ;
}
}
2017-10-22 18:43:15 +02:00
static void sub_805902C ( void )
2017-10-21 17:32:35 +02:00
{
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . flag_x80
& & ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . ballAnimActive )
2017-10-21 17:32:35 +02:00
{
2018-02-06 20:48:02 +01:00
sub_8172EF0 ( gActiveBattler , & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] ) ;
2017-10-21 17:32:35 +02:00
}
2018-02-06 02:46:59 +01:00
if ( gSprites [ gUnknown_03005D7C [ gActiveBattler ] ] . callback = = SpriteCallbackDummy
& & ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . ballAnimActive )
2017-10-21 17:32:35 +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 ] ) ;
gBattlerControllerFuncs [ gActiveBattler ] = sub_8058EDC ;
2017-10-21 17:32:35 +02:00
}
}
void c3_0802FDF4 ( u8 taskId )
{
if ( ! IsCryPlayingOrClearCrySongs ( ) )
{
2018-01-10 04:30:54 +01:00
m4aMPlayVolumeControl ( & gMPlayInfo_BGM , 0xFFFF , 0x100 ) ;
2017-10-21 17:32:35 +02:00
DestroyTask ( taskId ) ;
}
}
2017-10-22 18:43:15 +02:00
static void CompleteOnHealthbarDone ( void )
2017-10-21 17:32:35 +02:00
{
2018-06-19 00:43:15 +02:00
s16 hpValue = MoveBattleBar ( gActiveBattler , gHealthboxSpriteIds [ gActiveBattler ] , HEALTH_BAR , 0 ) ;
2017-10-21 17:32:35 +02:00
2018-02-06 20:48:02 +01:00
SetHealthboxSpriteVisible ( gHealthboxSpriteIds [ gActiveBattler ] ) ;
2017-10-21 17:32:35 +02:00
if ( hpValue ! = - 1 )
{
2018-02-06 20:48:02 +01:00
UpdateHpTextInHealthbox ( gHealthboxSpriteIds [ gActiveBattler ] , hpValue , HP_CURRENT ) ;
2017-10-21 17:32:35 +02:00
}
else
{
2018-02-06 20:48:02 +01:00
HandleLowHpMusicChange ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , gActiveBattler ) ;
2017-10-21 17:32:35 +02:00
PlayerBufferExecCompleted ( ) ;
}
}
2017-10-22 18:43:15 +02:00
static void CompleteOnInactiveTextPrinter ( void )
2017-10-21 17:32:35 +02:00
{
if ( ! IsTextPrinterActive ( 0 ) )
PlayerBufferExecCompleted ( ) ;
}
2017-10-22 18:43:15 +02:00
# 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 )
2017-10-21 17:32:35 +02:00
{
2017-10-22 18:43:15 +02:00
u32 monId = ( u8 ) ( gTasks [ taskId ] . tExpTask_monId ) ;
2018-03-01 00:59:52 +01:00
u8 battlerId = gTasks [ taskId ] . tExpTask_bank ;
2017-10-22 18:43:15 +02:00
s16 gainedExp = gTasks [ taskId ] . tExpTask_gainedExp ;
2017-10-21 17:32:35 +02:00
2018-03-01 00:59:52 +01:00
if ( IsDoubleBattle ( ) = = TRUE | | monId ! = gBattlerPartyIndexes [ battlerId ] ) // give exp without the expbar
2017-10-21 17:32:35 +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-02-06 20:48:02 +01:00
BtlController_EmitTwoReturnValues ( 1 , RET_VALUE_LEVELLED_UP , gainedExp ) ;
2018-02-06 02:46:59 +01:00
gActiveBattler = savedActiveBank ;
2017-10-21 17:32:35 +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-21 17:32:35 +02:00
gTasks [ taskId ] . func = sub_8059544 ;
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-21 17:32:35 +02:00
DestroyTask ( taskId ) ;
}
}
else
{
2017-10-22 18:43:15 +02:00
gTasks [ taskId ] . func = Task_PrepareToGiveExpWithExpBar ;
2017-10-21 17:32:35 +02:00
}
}
2017-10-22 18:43:15 +02:00
static void Task_PrepareToGiveExpWithExpBar ( u8 taskId )
2017-10-21 17:32:35 +02:00
{
2017-10-22 18:43:15 +02:00
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-21 17:32:35 +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-21 17:32:35 +02:00
PlaySE ( SE_EXP ) ;
gTasks [ taskId ] . func = sub_8059400 ;
}
2017-10-22 18:43:15 +02:00
static void sub_8059400 ( u8 taskId )
2017-10-21 17:32:35 +02:00
{
2017-10-22 18:43:15 +02:00
if ( gTasks [ taskId ] . tExpTask_frames < 13 )
2017-10-21 17:32:35 +02:00
{
2017-10-22 18:43:15 +02:00
gTasks [ taskId ] . tExpTask_frames + + ;
2017-10-21 17:32:35 +02:00
}
else
{
2017-10-22 18:43:15 +02:00
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-21 17:32:35 +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-21 17:32:35 +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-02-06 20:48:02 +01:00
BtlController_EmitTwoReturnValues ( 1 , RET_VALUE_LEVELLED_UP , gainedExp ) ;
2018-02-06 02:46:59 +01:00
gActiveBattler = savedActiveBank ;
2017-10-21 17:32:35 +02:00
gTasks [ taskId ] . func = sub_8059544 ;
}
else
{
currExp + = gainedExp ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_EXP , & currExp ) ;
2018-03-01 00:59:52 +01:00
gBattlerControllerFuncs [ battlerId ] = CompleteOnInactiveTextPrinter ;
2017-10-21 17:32:35 +02:00
DestroyTask ( taskId ) ;
}
}
}
}
2017-10-22 18:43:15 +02:00
static void sub_8059544 ( u8 taskId )
2017-10-21 17:32:35 +02:00
{
2018-03-01 00:59:52 +01:00
u8 battlerId = gTasks [ taskId ] . tExpTask_bank ;
2017-10-22 18:43:15 +02:00
u8 monIndex = gTasks [ taskId ] . tExpTask_monId ;
2017-10-21 17:32:35 +02:00
2018-03-01 00:59:52 +01:00
if ( IsDoubleBattle ( ) = = TRUE & & monIndex = = gBattlerPartyIndexes [ battlerId ^ BIT_FLANK ] )
battlerId ^ = BIT_FLANK ;
2017-10-21 17:32:35 +02:00
2018-03-01 00:59:52 +01:00
InitAndLaunchSpecialAnimation ( battlerId , battlerId , battlerId , B_ANIM_LVL_UP ) ;
2017-10-21 17:32:35 +02:00
gTasks [ taskId ] . func = sub_80595A4 ;
}
2017-10-22 18:43:15 +02:00
static void sub_80595A4 ( u8 taskId )
2017-10-21 17:32:35 +02:00
{
2018-03-01 00:59:52 +01:00
u8 battlerId = gTasks [ taskId ] . tExpTask_bank ;
2017-10-21 17:32:35 +02:00
2018-03-01 00:59:52 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ battlerId ] . specialAnimActive )
2017-10-21 17:32:35 +02:00
{
2017-10-22 18:43:15 +02:00
u8 monIndex = gTasks [ taskId ] . tExpTask_monId ;
2017-10-21 17:32:35 +02:00
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-21 17:32:35 +02:00
else
2018-03-01 00:59:52 +01:00
UpdateHealthboxAttribute ( gHealthboxSpriteIds [ battlerId ] , & gPlayerParty [ monIndex ] , HEALTHBOX_ALL ) ;
2017-10-21 17:32:35 +02:00
gTasks [ taskId ] . func = DestroyExpTaskAndCompleteOnInactiveTextPrinter ;
}
}
2017-10-22 18:43:15 +02:00
static void DestroyExpTaskAndCompleteOnInactiveTextPrinter ( u8 taskId )
2017-10-21 17:32:35 +02:00
{
u8 monIndex ;
2018-03-01 00:59:52 +01:00
u8 battlerId ;
2017-10-21 17:32:35 +02:00
2017-10-22 18:43:15 +02:00
monIndex = gTasks [ taskId ] . tExpTask_monId ;
2017-10-21 17:32:35 +02:00
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-21 17:32:35 +02:00
DestroyTask ( taskId ) ;
}
2017-10-22 18:43:15 +02:00
static void sub_80596A8 ( void )
2017-10-21 17:32:35 +02:00
{
2018-02-06 20:48:02 +01:00
if ( gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . pos1 . y + gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . pos2 . y > DISPLAY_HEIGHT )
2017-10-21 17:32:35 +02:00
{
2018-02-06 20:48:02 +01:00
u16 species = GetMonData ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , MON_DATA_SPECIES ) ;
2017-10-21 17:32:35 +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-21 17:32:35 +02:00
PlayerBufferExecCompleted ( ) ;
}
}
2017-10-22 18:43:15 +02:00
static void sub_8059744 ( void )
2017-10-21 17:32:35 +02:00
{
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . specialAnimActive )
2017-10-21 17:32:35 +02:00
{
2018-02-06 20:48:02 +01:00
FreeSpriteOamMatrix ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] ) ;
DestroySprite ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] ) ;
SetHealthboxSpriteInvisible ( gHealthboxSpriteIds [ gActiveBattler ] ) ;
2017-10-21 17:32:35 +02:00
PlayerBufferExecCompleted ( ) ;
}
}
2017-10-22 18:43:15 +02:00
static void CompleteOnInactiveTextPrinter2 ( void )
2017-10-21 17:32:35 +02:00
{
if ( ! IsTextPrinterActive ( 0 ) )
PlayerBufferExecCompleted ( ) ;
}
2017-10-22 18:43:15 +02:00
static void sub_80597CC ( void )
2017-10-21 17:32:35 +02:00
{
if ( ! gPaletteFade . active )
{
u8 r4 ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = sub_8059828 ;
2018-02-06 02:46:59 +01:00
r4 = gTasks [ gUnknown_03005D7C [ gActiveBattler ] ] . data [ 0 ] ;
DestroyTask ( gUnknown_03005D7C [ gActiveBattler ] ) ;
2017-10-21 17:32:35 +02:00
FreeAllWindowBuffers ( ) ;
sub_81B89AC ( r4 ) ;
}
}
2017-10-22 18:43:15 +02:00
static void sub_8059828 ( void )
2017-10-21 17:32:35 +02:00
{
if ( gMain . callback2 = = BattleMainCB2 & & ! gPaletteFade . active )
{
if ( gUnknown_0203CEE8 = = 1 )
2018-02-06 20:48:02 +01:00
BtlController_EmitChosenMonReturnValue ( 1 , gUnknown_0203CEE9 , gUnknown_0203CF00 ) ;
2017-10-21 17:32:35 +02:00
else
2018-02-06 20:48:02 +01:00
BtlController_EmitChosenMonReturnValue ( 1 , 6 , NULL ) ;
2017-10-21 17:32:35 +02:00
2018-02-06 02:46:59 +01:00
if ( ( gBattleBufferA [ gActiveBattler ] [ 1 ] & 0xF ) = = 1 )
2017-10-21 17:32:35 +02:00
PrintLinkStandbyMsg ( ) ;
PlayerBufferExecCompleted ( ) ;
}
}
2017-10-22 20:38:23 +02:00
static void OpenBagAndChooseItem ( void )
2017-10-21 17:32:35 +02:00
{
if ( ! gPaletteFade . active )
{
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = CompleteWhenChoseItem ;
2017-10-21 17:32:35 +02:00
nullsub_35 ( ) ;
FreeAllWindowBuffers ( ) ;
sub_81AABB0 ( ) ;
}
}
2017-10-22 20:38:23 +02:00
static void CompleteWhenChoseItem ( void )
2017-10-21 17:32:35 +02:00
{
if ( gMain . callback2 = = BattleMainCB2 & & ! gPaletteFade . active )
{
2018-02-06 20:48:02 +01:00
BtlController_EmitOneReturnValue ( 1 , gSpecialVar_ItemId ) ;
2017-10-21 17:32:35 +02:00
PlayerBufferExecCompleted ( ) ;
}
}
2017-10-22 18:43:15 +02:00
static void CompleteOnSpecialAnimDone ( void )
2017-10-21 17:32:35 +02:00
{
2018-02-06 02:46:59 +01:00
if ( ! gDoingBattleAnim | | ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . specialAnimActive )
2017-10-21 17:32:35 +02:00
PlayerBufferExecCompleted ( ) ;
}
2017-10-22 18:43:15 +02:00
static void DoHitAnimBlinkSpriteEffect ( void )
2017-10-21 17:32:35 +02:00
{
2018-02-06 20:48:02 +01:00
u8 spriteId = gBattlerSpriteIds [ gActiveBattler ] ;
2017-10-21 17:32:35 +02:00
2017-12-02 21:44:50 +01:00
if ( gSprites [ spriteId ] . data [ 1 ] = = 32 )
2017-10-21 17:32:35 +02:00
{
2017-12-02 21:44:50 +01:00
gSprites [ spriteId ] . data [ 1 ] = 0 ;
2017-10-21 17:32:35 +02:00
gSprites [ spriteId ] . invisible = 0 ;
gDoingBattleAnim = FALSE ;
PlayerBufferExecCompleted ( ) ;
}
else
{
2017-12-02 21:44:50 +01:00
if ( ( gSprites [ spriteId ] . data [ 1 ] % 4 ) = = 0 )
2017-10-21 17:32:35 +02:00
gSprites [ spriteId ] . invisible ^ = 1 ;
2017-12-02 21:44:50 +01:00
gSprites [ spriteId ] . data [ 1 ] + + ;
2017-10-21 17:32:35 +02:00
}
}
2017-10-22 18:43:15 +02:00
static void PlayerHandleUnknownYesNoInput ( void )
2017-10-21 17:32:35 +02:00
{
if ( gMain . newKeys & DPAD_UP & & gMultiUsePlayerCursor ! = 0 )
{
PlaySE ( SE_SELECT ) ;
BattleDestroyYesNoCursorAt ( gMultiUsePlayerCursor ) ;
gMultiUsePlayerCursor = 0 ;
BattleCreateYesNoCursorAt ( 0 ) ;
}
if ( gMain . newKeys & DPAD_DOWN & & gMultiUsePlayerCursor = = 0 )
{
PlaySE ( SE_SELECT ) ;
BattleDestroyYesNoCursorAt ( gMultiUsePlayerCursor ) ;
gMultiUsePlayerCursor = 1 ;
BattleCreateYesNoCursorAt ( 1 ) ;
}
if ( gMain . newKeys & A_BUTTON )
{
2017-10-22 01:04:02 +02:00
HandleBattleWindow ( 0x18 , 8 , 0x1D , 0xD , WINDOW_CLEAR ) ;
2017-10-21 17:32:35 +02:00
PlaySE ( SE_SELECT ) ;
if ( gMultiUsePlayerCursor ! = 0 )
2018-02-06 20:48:02 +01:00
BtlController_EmitTwoReturnValues ( 1 , 0xE , 0 ) ;
2017-10-21 17:32:35 +02:00
else
2018-02-06 20:48:02 +01:00
BtlController_EmitTwoReturnValues ( 1 , 0xD , 0 ) ;
2017-10-21 17:32:35 +02:00
PlayerBufferExecCompleted ( ) ;
}
if ( gMain . newKeys & B_BUTTON )
{
2017-10-22 01:04:02 +02:00
HandleBattleWindow ( 0x18 , 8 , 0x1D , 0xD , WINDOW_CLEAR ) ;
2017-10-21 17:32:35 +02:00
PlaySE ( SE_SELECT ) ;
PlayerBufferExecCompleted ( ) ;
}
}
2017-10-22 18:43:15 +02:00
static void MoveSelectionDisplayMoveNames ( void )
2017-10-21 17:32:35 +02:00
{
s32 i ;
2018-02-06 02:46:59 +01:00
struct ChooseMoveStruct * moveInfo = ( struct ChooseMoveStruct * ) ( & gBattleBufferA [ gActiveBattler ] [ 4 ] ) ;
2017-10-21 17:32:35 +02:00
gNumberOfMovesToChoose = 0 ;
for ( i = 0 ; i < 4 ; i + + )
{
MoveSelectionDestroyCursorAt ( i ) ;
StringCopy ( gDisplayedStringBattle , gMoveNames [ moveInfo - > moves [ i ] ] ) ;
2018-06-17 16:48:58 +02:00
BattlePutTextOnWindow ( gDisplayedStringBattle , i + 3 ) ;
2017-10-21 17:32:35 +02:00
if ( moveInfo - > moves [ i ] ! = MOVE_NONE )
gNumberOfMovesToChoose + + ;
}
}
2017-10-22 18:43:15 +02:00
static void MoveSelectionDisplayPpString ( void )
2017-10-21 17:32:35 +02:00
{
StringCopy ( gDisplayedStringBattle , gText_MoveInterfacePP ) ;
2018-06-17 16:48:58 +02:00
BattlePutTextOnWindow ( gDisplayedStringBattle , 7 ) ;
2017-10-21 17:32:35 +02:00
}
2017-10-22 18:43:15 +02:00
static void MoveSelectionDisplayPpNumber ( void )
2017-10-21 17:32:35 +02:00
{
u8 * txtPtr ;
struct ChooseMoveStruct * moveInfo ;
2018-02-06 02:46:59 +01:00
if ( gBattleBufferA [ gActiveBattler ] [ 2 ] = = TRUE ) // check if we didn't want to display pp number
2017-10-21 17:32:35 +02:00
return ;
SetPpNumbersPaletteInMoveSelection ( ) ;
2018-02-06 02:46:59 +01:00
moveInfo = ( struct ChooseMoveStruct * ) ( & gBattleBufferA [ gActiveBattler ] [ 4 ] ) ;
txtPtr = ConvertIntToDecimalStringN ( gDisplayedStringBattle , moveInfo - > currentPp [ gMoveSelectionCursor [ gActiveBattler ] ] , STR_CONV_MODE_RIGHT_ALIGN , 2 ) ;
2017-10-21 17:32:35 +02:00
txtPtr [ 0 ] = CHAR_SLASH ;
txtPtr + + ;
2018-02-06 02:46:59 +01:00
ConvertIntToDecimalStringN ( txtPtr , moveInfo - > maxPp [ gMoveSelectionCursor [ gActiveBattler ] ] , STR_CONV_MODE_RIGHT_ALIGN , 2 ) ;
2017-10-21 17:32:35 +02:00
2018-06-17 16:48:58 +02:00
BattlePutTextOnWindow ( gDisplayedStringBattle , 9 ) ;
2017-10-21 17:32:35 +02:00
}
2017-10-22 18:43:15 +02:00
static void MoveSelectionDisplayMoveType ( void )
2017-10-21 17:32:35 +02:00
{
u8 * txtPtr ;
2018-02-06 02:46:59 +01:00
struct ChooseMoveStruct * moveInfo = ( struct ChooseMoveStruct * ) ( & gBattleBufferA [ gActiveBattler ] [ 4 ] ) ;
2017-10-21 17:32:35 +02:00
txtPtr = StringCopy ( gDisplayedStringBattle , gText_MoveInterfaceType ) ;
txtPtr [ 0 ] = EXT_CTRL_CODE_BEGIN ;
txtPtr + + ;
txtPtr [ 0 ] = 6 ;
txtPtr + + ;
txtPtr [ 0 ] = 1 ;
txtPtr + + ;
2018-02-06 02:46:59 +01:00
StringCopy ( txtPtr , gTypeNames [ gBattleMoves [ moveInfo - > moves [ gMoveSelectionCursor [ gActiveBattler ] ] ] . type ] ) ;
2018-06-17 16:48:58 +02:00
BattlePutTextOnWindow ( gDisplayedStringBattle , 10 ) ;
2017-10-21 17:32:35 +02:00
}
2017-10-22 18:43:15 +02:00
static void MoveSelectionCreateCursorAt ( u8 cursorPosition , u8 arg1 )
2017-10-21 17:32:35 +02:00
{
u16 src [ 2 ] ;
src [ 0 ] = arg1 + 1 ;
src [ 1 ] = arg1 + 2 ;
CopyToBgTilemapBufferRect_ChangePalette ( 0 , src , 9 * ( cursorPosition & 1 ) + 1 , 55 + ( cursorPosition & 2 ) , 1 , 2 , 0x11 ) ;
CopyBgTilemapBufferToVram ( 0 ) ;
}
2017-10-22 18:43:15 +02:00
static void MoveSelectionDestroyCursorAt ( u8 cursorPosition )
2017-10-21 17:32:35 +02:00
{
u16 src [ 2 ] ;
src [ 0 ] = 0x1016 ;
src [ 1 ] = 0x1016 ;
CopyToBgTilemapBufferRect_ChangePalette ( 0 , src , 9 * ( cursorPosition & 1 ) + 1 , 55 + ( cursorPosition & 2 ) , 1 , 2 , 0x11 ) ;
CopyBgTilemapBufferToVram ( 0 ) ;
}
void ActionSelectionCreateCursorAt ( u8 cursorPosition , u8 arg1 )
{
u16 src [ 2 ] ;
src [ 0 ] = 1 ;
src [ 1 ] = 2 ;
CopyToBgTilemapBufferRect_ChangePalette ( 0 , src , 7 * ( cursorPosition & 1 ) + 16 , 35 + ( cursorPosition & 2 ) , 1 , 2 , 0x11 ) ;
CopyBgTilemapBufferToVram ( 0 ) ;
}
void ActionSelectionDestroyCursorAt ( u8 cursorPosition )
{
u16 src [ 2 ] ;
src [ 0 ] = 0x1016 ;
src [ 1 ] = 0x1016 ;
CopyToBgTilemapBufferRect_ChangePalette ( 0 , src , 7 * ( cursorPosition & 1 ) + 16 , 35 + ( cursorPosition & 2 ) , 1 , 2 , 0x11 ) ;
CopyBgTilemapBufferToVram ( 0 ) ;
}
void SetCB2ToReshowScreenAfterMenu ( void )
{
SetMainCallback2 ( ReshowBattleScreenAfterMenu ) ;
}
void SetCB2ToReshowScreenAfterMenu2 ( void )
{
SetMainCallback2 ( ReshowBattleScreenAfterMenu ) ;
}
2017-10-22 18:43:15 +02:00
static void CompleteOnFinishedStatusAnimation ( void )
2017-10-21 17:32:35 +02:00
{
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . statusAnimActive )
2017-10-21 17:32:35 +02:00
PlayerBufferExecCompleted ( ) ;
}
2017-10-22 18:43:15 +02:00
static void CompleteOnFinishedBattleAnimation ( void )
2017-10-21 17:32:35 +02:00
{
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animFromTableActive )
2017-10-21 17:32:35 +02:00
PlayerBufferExecCompleted ( ) ;
}
2017-10-22 18:43:15 +02:00
static void PrintLinkStandbyMsg ( void )
2017-10-21 17:32:35 +02:00
{
if ( gBattleTypeFlags & BATTLE_TYPE_LINK )
{
gBattle_BG0_X = 0 ;
gBattle_BG0_Y = 0 ;
2018-06-17 16:48:58 +02:00
BattlePutTextOnWindow ( gText_LinkStandby , 0 ) ;
2017-10-22 01:04:02 +02:00
}
}
2017-10-22 18:43:15 +02:00
static void PlayerHandleGetMonData ( void )
2017-10-22 01:04:02 +02:00
{
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-22 01:04:02 +02:00
s32 i ;
2018-02-06 02:46:59 +01:00
if ( gBattleBufferA [ gActiveBattler ] [ 2 ] = = 0 )
2017-10-22 01:04:02 +02:00
{
2018-02-06 20:48:02 +01:00
size + = CopyPlayerMonData ( gBattlerPartyIndexes [ gActiveBattler ] , monData ) ;
2017-10-22 01:04:02 +02:00
}
else
{
2018-02-06 02:46:59 +01:00
monToCheck = gBattleBufferA [ gActiveBattler ] [ 2 ] ;
2017-10-22 01:04:02 +02:00
for ( i = 0 ; i < 6 ; i + + )
{
2017-10-31 18:04:08 +01:00
if ( monToCheck & 1 )
2017-10-22 01:04:02 +02:00
size + = CopyPlayerMonData ( i , monData + size ) ;
2017-10-31 18:04:08 +01:00
monToCheck > > = 1 ;
2017-10-22 01:04:02 +02:00
}
}
2018-02-06 20:48:02 +01:00
BtlController_EmitDataTransfer ( 1 , size , monData ) ;
2017-10-22 01:04:02 +02:00
PlayerBufferExecCompleted ( ) ;
}
2017-10-22 18:43:15 +02:00
static u32 CopyPlayerMonData ( u8 monId , u8 * dst )
2017-10-22 01:04:02 +02:00
{
struct BattlePokemon battleMon ;
struct MovePpInfo moveData ;
u8 nickname [ 20 ] ;
u8 * src ;
s16 data16 ;
u32 data32 ;
s32 size = 0 ;
2018-02-06 02:46:59 +01:00
switch ( gBattleBufferA [ gActiveBattler ] [ 1 ] )
2017-10-22 01:04:02 +02:00
{
case REQUEST_ALL_BATTLE :
battleMon . species = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPECIES ) ;
battleMon . item = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_HELD_ITEM ) ;
for ( size = 0 ; size < 4 ; size + + )
{
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-22 01:04:02 +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-22 01:04:02 +02:00
battleMon . spAttack = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPATK ) ;
battleMon . spDefense = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPDEF ) ;
battleMon . isEgg = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_IS_EGG ) ;
battleMon . altAbility = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_ALT_ABILITY ) ;
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 :
for ( size = 0 ; size < 4 ; size + + )
{
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 :
2018-02-06 02:46:59 +01:00
data16 = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_MOVE1 + gBattleBufferA [ gActiveBattler ] [ 1 ] - REQUEST_MOVE1_BATTLE ) ;
2017-10-22 01:04:02 +02:00
dst [ 0 ] = data16 ;
dst [ 1 ] = data16 > > 8 ;
size = 2 ;
break ;
case REQUEST_PP_DATA_BATTLE :
for ( size = 0 ; size < 4 ; size + + )
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 :
2018-02-06 02:46:59 +01:00
dst [ 0 ] = GetMonData ( & gPlayerParty [ monId ] , MON_DATA_PP1 + gBattleBufferA [ gActiveBattler ] [ 1 ] - REQUEST_PPMOVE1_BATTLE ) ;
2017-10-22 01:04:02 +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-22 01:04:02 +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-22 01:04:02 +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-22 01:04:02 +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-22 01:04:02 +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 ;
}
void PlayerHandleGetRawMonData ( void )
{
struct BattlePokemon battleMon ;
2018-02-06 20:48:02 +01:00
u8 * src = ( u8 * ) & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] + gBattleBufferA [ gActiveBattler ] [ 1 ] ;
2018-02-06 02:46:59 +01:00
u8 * dst = ( u8 * ) & battleMon + gBattleBufferA [ gActiveBattler ] [ 1 ] ;
2017-10-22 01:04:02 +02:00
u8 i ;
2018-02-06 02:46:59 +01:00
for ( i = 0 ; i < gBattleBufferA [ gActiveBattler ] [ 2 ] ; i + + )
2017-10-22 01:04:02 +02:00
dst [ i ] = src [ i ] ;
2018-02-06 20:48:02 +01:00
BtlController_EmitDataTransfer ( 1 , gBattleBufferA [ gActiveBattler ] [ 2 ] , dst ) ;
2017-10-22 01:04:02 +02:00
PlayerBufferExecCompleted ( ) ;
}
2017-10-22 18:43:15 +02:00
static void PlayerHandleSetMonData ( void )
2017-10-22 01:04:02 +02:00
{
2017-10-31 18:04:08 +01:00
u8 monToCheck ;
2017-10-22 01:04:02 +02:00
u8 i ;
2018-02-06 02:46:59 +01:00
if ( gBattleBufferA [ gActiveBattler ] [ 2 ] = = 0 )
2017-10-22 01:04:02 +02:00
{
2018-02-06 20:48:02 +01:00
SetPlayerMonData ( gBattlerPartyIndexes [ gActiveBattler ] ) ;
2017-10-22 01:04:02 +02:00
}
else
{
2018-02-06 02:46:59 +01:00
monToCheck = gBattleBufferA [ gActiveBattler ] [ 2 ] ;
2017-10-22 01:04:02 +02:00
for ( i = 0 ; i < 6 ; i + + )
{
2017-10-31 18:04:08 +01:00
if ( monToCheck & 1 )
2017-10-22 01:04:02 +02:00
SetPlayerMonData ( i ) ;
2017-10-31 18:04:08 +01:00
monToCheck > > = 1 ;
2017-10-22 01:04:02 +02:00
}
}
PlayerBufferExecCompleted ( ) ;
}
2017-10-22 18:43:15 +02:00
static void SetPlayerMonData ( u8 monId )
2017-10-22 01:04:02 +02:00
{
2018-02-06 02:46:59 +01:00
struct BattlePokemon * battlePokemon = ( struct BattlePokemon * ) & gBattleBufferA [ gActiveBattler ] [ 3 ] ;
struct MovePpInfo * moveData = ( struct MovePpInfo * ) & gBattleBufferA [ gActiveBattler ] [ 3 ] ;
2017-10-22 01:04:02 +02:00
s32 i ;
2018-02-06 02:46:59 +01:00
switch ( gBattleBufferA [ gActiveBattler ] [ 1 ] )
2017-10-22 01:04:02 +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 ) ;
for ( i = 0 ; i < 4 ; i + + )
{
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-22 01:04:02 +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-22 01:04:02 +02:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPATK , & battlePokemon - > spAttack ) ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPDEF , & battlePokemon - > spDefense ) ;
}
break ;
case REQUEST_SPECIES_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPECIES , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_HELDITEM_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_HELD_ITEM , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_MOVES_PP_BATTLE :
for ( i = 0 ; i < 4 ; i + + )
{
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 :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_MOVE1 + gBattleBufferA [ gActiveBattler ] [ 1 ] - REQUEST_MOVE1_BATTLE , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_PP_DATA_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_PP1 , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_PP2 , & gBattleBufferA [ gActiveBattler ] [ 4 ] ) ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_PP3 , & gBattleBufferA [ gActiveBattler ] [ 5 ] ) ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_PP4 , & gBattleBufferA [ gActiveBattler ] [ 6 ] ) ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_PP_BONUSES , & gBattleBufferA [ gActiveBattler ] [ 7 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_PPMOVE1_BATTLE :
case REQUEST_PPMOVE2_BATTLE :
case REQUEST_PPMOVE3_BATTLE :
case REQUEST_PPMOVE4_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_PP1 + gBattleBufferA [ gActiveBattler ] [ 1 ] - REQUEST_PPMOVE1_BATTLE , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_OTID_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_OT_ID , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_EXP_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_EXP , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_HP_EV_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_HP_EV , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_ATK_EV_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_ATK_EV , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_DEF_EV_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_DEF_EV , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_SPEED_EV_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPEED_EV , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_SPATK_EV_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPATK_EV , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_SPDEF_EV_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPDEF_EV , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_FRIENDSHIP_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_FRIENDSHIP , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_POKERUS_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_POKERUS , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_MET_LOCATION_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_MET_LOCATION , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_MET_LEVEL_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_MET_LEVEL , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_MET_GAME_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_MET_GAME , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_POKEBALL_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_POKEBALL , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_ALL_IVS_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_HP_IV , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_ATK_IV , & gBattleBufferA [ gActiveBattler ] [ 4 ] ) ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_DEF_IV , & gBattleBufferA [ gActiveBattler ] [ 5 ] ) ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPEED_IV , & gBattleBufferA [ gActiveBattler ] [ 6 ] ) ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPATK_IV , & gBattleBufferA [ gActiveBattler ] [ 7 ] ) ;
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPDEF_IV , & gBattleBufferA [ gActiveBattler ] [ 8 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_HP_IV_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_HP_IV , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_ATK_IV_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_ATK_IV , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_DEF_IV_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_DEF_IV , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_SPEED_IV_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPEED_IV , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_SPATK_IV_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPATK_IV , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_SPDEF_IV_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPDEF_IV , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_PERSONALITY_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_PERSONALITY , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_CHECKSUM_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_CHECKSUM , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_STATUS_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_STATUS , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_LEVEL_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_LEVEL , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_HP_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_HP , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_MAX_HP_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_MAX_HP , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_ATK_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_ATK , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_DEF_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_DEF , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_SPEED_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPEED , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_SPATK_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPATK , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_SPDEF_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPDEF , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_COOL_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_COOL , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_BEAUTY_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_BEAUTY , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_CUTE_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_CUTE , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_SMART_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SMART , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_TOUGH_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_TOUGH , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_SHEEN_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SHEEN , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_COOL_RIBBON_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_COOL_RIBBON , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_BEAUTY_RIBBON_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_BEAUTY_RIBBON , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_CUTE_RIBBON_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_CUTE_RIBBON , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_SMART_RIBBON_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_SMART_RIBBON , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
case REQUEST_TOUGH_RIBBON_BATTLE :
2018-02-06 02:46:59 +01:00
SetMonData ( & gPlayerParty [ monId ] , MON_DATA_TOUGH_RIBBON , & gBattleBufferA [ gActiveBattler ] [ 3 ] ) ;
2017-10-22 01:04:02 +02:00
break ;
}
2018-02-06 20:48:02 +01:00
HandleLowHpMusicChange ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , gActiveBattler ) ;
2017-10-22 01:04:02 +02:00
}
2017-10-22 18:43:15 +02:00
static void PlayerHandleSetRawMonData ( void )
2017-10-22 01:04:02 +02:00
{
2018-02-06 20:48:02 +01:00
u8 * dst = ( u8 * ) & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] + gBattleBufferA [ gActiveBattler ] [ 1 ] ;
2017-10-22 01:04:02 +02:00
u8 i ;
2018-02-06 02:46:59 +01:00
for ( i = 0 ; i < gBattleBufferA [ gActiveBattler ] [ 2 ] ; i + + )
dst [ i ] = gBattleBufferA [ gActiveBattler ] [ 3 + i ] ;
2017-10-22 01:04:02 +02:00
PlayerBufferExecCompleted ( ) ;
}
2017-10-22 18:43:15 +02:00
static void PlayerHandleLoadMonSprite ( void )
2017-10-22 01:04:02 +02:00
{
2018-02-06 20:48:02 +01:00
BattleLoadPlayerMonSpriteGfx ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , gActiveBattler ) ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . oam . paletteNum = gActiveBattler ;
gBattlerControllerFuncs [ gActiveBattler ] = CompleteOnBankSpritePosX_0 ;
2017-10-22 01:04:02 +02:00
}
2017-10-22 18:43:15 +02:00
static void PlayerHandleSwitchInAnim ( void )
2017-10-22 01:04:02 +02:00
{
2018-02-06 02:46:59 +01:00
ClearTemporarySpeciesSpriteData ( gActiveBattler , gBattleBufferA [ gActiveBattler ] [ 2 ] ) ;
2018-02-06 20:48:02 +01:00
gBattlerPartyIndexes [ gActiveBattler ] = gBattleBufferA [ gActiveBattler ] [ 1 ] ;
BattleLoadPlayerMonSpriteGfx ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , gActiveBattler ) ;
2018-02-06 02:46:59 +01:00
gActionSelectionCursor [ gActiveBattler ] = 0 ;
gMoveSelectionCursor [ gActiveBattler ] = 0 ;
sub_805B258 ( gActiveBattler , gBattleBufferA [ gActiveBattler ] [ 2 ] ) ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = sub_805902C ;
2017-10-22 01:04:02 +02:00
}
2018-03-01 00:59:52 +01:00
static void sub_805B258 ( u8 battlerId , bool8 dontClearSubstituteBit )
2017-10-22 01:04:02 +02:00
{
u16 species ;
2018-03-01 00:59:52 +01:00
ClearTemporarySpeciesSpriteData ( battlerId , dontClearSubstituteBit ) ;
gBattlerPartyIndexes [ battlerId ] = gBattleBufferA [ battlerId ] [ 1 ] ;
species = GetMonData ( & gPlayerParty [ gBattlerPartyIndexes [ battlerId ] ] , MON_DATA_SPECIES ) ;
gUnknown_03005D7C [ battlerId ] = CreateInvisibleSpriteWithCallback ( sub_805D714 ) ;
sub_806A068 ( species , GetBattlerPosition ( battlerId ) ) ;
2017-10-22 01:04:02 +02:00
2018-03-01 00:59:52 +01:00
gBattlerSpriteIds [ battlerId ] = CreateSprite (
2017-10-22 01:04:02 +02:00
& gUnknown_0202499C ,
2018-03-01 00:59:52 +01:00
GetBattlerSpriteCoord ( battlerId , 2 ) ,
GetBattlerSpriteDefault_Y ( battlerId ) ,
sub_80A82E4 ( battlerId ) ) ;
2017-10-22 01:04:02 +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-22 01:04:02 +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-22 01:04:02 +02:00
2018-03-01 00:59:52 +01:00
StartSpriteAnim ( & gSprites [ gBattlerSpriteIds [ battlerId ] ] , gBattleMonForms [ battlerId ] ) ;
2017-10-22 01:04:02 +02:00
2018-03-01 00:59:52 +01:00
gSprites [ gBattlerSpriteIds [ battlerId ] ] . invisible = TRUE ;
gSprites [ gBattlerSpriteIds [ battlerId ] ] . callback = SpriteCallbackDummy ;
2017-10-22 01:04:02 +02:00
2018-03-01 00:59:52 +01:00
gSprites [ gUnknown_03005D7C [ battlerId ] ] . data [ 0 ] = DoPokeballSendOutAnimation ( 0 , POKEBALL_PLAYER_SENDOUT ) ;
2017-10-22 01:04:02 +02:00
}
2017-10-22 18:43:15 +02:00
static void PlayerHandleReturnMonToBall ( void )
2017-10-22 01:04:02 +02:00
{
2018-02-06 02:46:59 +01:00
if ( gBattleBufferA [ gActiveBattler ] [ 1 ] = = 0 )
2017-10-22 01:04:02 +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-22 01:04:02 +02:00
}
else
{
2018-02-06 20:48:02 +01:00
FreeSpriteOamMatrix ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] ) ;
DestroySprite ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] ) ;
SetHealthboxSpriteInvisible ( gHealthboxSpriteIds [ gActiveBattler ] ) ;
2017-10-22 01:04:02 +02:00
PlayerBufferExecCompleted ( ) ;
}
}
2017-10-22 18:43:15 +02:00
static void DoSwitchOutAnimation ( void )
2017-10-22 01:04:02 +02:00
{
2018-02-06 02:46:59 +01:00
switch ( gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState )
2017-10-22 01:04:02 +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-22 01:04:02 +02:00
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState = 1 ;
2017-10-22 01:04:02 +02:00
break ;
case 1 :
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . specialAnimActive )
2017-10-22 01:04:02 +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_8059744 ;
2017-10-22 01:04:02 +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
2017-10-22 18:43:15 +02:00
static void PlayerHandleDrawTrainerPic ( void )
2017-10-22 01:04:02 +02:00
{
s16 xPos , yPos ;
u32 trainerPicId ;
if ( gBattleTypeFlags & BATTLE_TYPE_LINK )
{
if ( ( gLinkPlayers [ GetMultiplayerId ( ) ] . version & 0xFF ) = = VERSION_FIRE_RED
| | ( gLinkPlayers [ GetMultiplayerId ( ) ] . version & 0xFF ) = = VERSION_LEAF_GREEN )
{
trainerPicId = gLinkPlayers [ GetMultiplayerId ( ) ] . gender + BACK_PIC_RED ;
}
else if ( ( gLinkPlayers [ GetMultiplayerId ( ) ] . version & 0xFF ) = = VERSION_RUBY
| | ( gLinkPlayers [ GetMultiplayerId ( ) ] . version & 0xFF ) = = VERSION_SAPPHIRE )
{
trainerPicId = gLinkPlayers [ GetMultiplayerId ( ) ] . gender + BACK_PIC_RS_BRENDAN ;
}
else
{
trainerPicId = gLinkPlayers [ GetMultiplayerId ( ) ] . gender ;
}
}
else
{
trainerPicId = gSaveBlock2Ptr - > playerGender ;
}
if ( gBattleTypeFlags & BATTLE_TYPE_MULTI )
{
2018-02-06 02:46:59 +01:00
if ( ( GetBattlerPosition ( gActiveBattler ) & BIT_FLANK ) ! = 0 ) // second mon
2017-10-22 01:04:02 +02:00
xPos = 90 ;
else // first mon
xPos = 32 ;
if ( gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER & & gPartnerTrainerId ! = STEVEN_PARTNER_ID )
{
xPos = 90 ;
yPos = ( 8 - gTrainerFrontPicCoords [ trainerPicId ] . coords ) * 4 + 80 ;
}
else
{
yPos = ( 8 - gTrainerBackPicCoords [ trainerPicId ] . coords ) * 4 + 80 ;
}
}
else
{
xPos = 80 ;
yPos = ( 8 - gTrainerBackPicCoords [ trainerPicId ] . coords ) * 4 + 80 ;
}
// Use front pic table for any tag battles unless your partner is Steven.
if ( gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER & & gPartnerTrainerId ! = STEVEN_PARTNER_ID )
{
trainerPicId = PlayerGenderToFrontTrainerPicId ( gSaveBlock2Ptr - > playerGender ) ;
2018-02-06 02:46:59 +01:00
DecompressTrainerFrontPic ( trainerPicId , gActiveBattler ) ;
sub_806A1C0 ( trainerPicId , GetBattlerPosition ( gActiveBattler ) ) ;
2018-02-06 20:48:02 +01:00
gBattlerSpriteIds [ gActiveBattler ] = CreateSprite ( & gUnknown_0202499C , xPos , yPos , sub_80A82E4 ( gActiveBattler ) ) ;
2018-02-06 02:46:59 +01:00
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 ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . oam . affineMode = 0 ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . hFlip = 1 ;
2017-10-22 01:04:02 +02:00
}
// use the back pic in any other scenario
else
{
2018-02-06 02:46:59 +01:00
DecompressTrainerBackPic ( trainerPicId , gActiveBattler ) ;
sub_806A12C ( trainerPicId , GetBattlerPosition ( gActiveBattler ) ) ;
2018-02-06 20:48:02 +01:00
gBattlerSpriteIds [ gActiveBattler ] = CreateSprite ( & gUnknown_0202499C , xPos , yPos , sub_80A82E4 ( gActiveBattler ) ) ;
2017-10-22 01:04:02 +02: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-22 01:04:02 +02:00
}
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = CompleteOnBankSpriteCallbackDummy ;
2017-10-22 01:04:02 +02:00
}
2017-10-22 18:43:15 +02:00
static void PlayerHandleTrainerSlide ( void )
2017-10-22 01:04:02 +02:00
{
u32 trainerPicId ;
if ( gBattleTypeFlags & BATTLE_TYPE_LINK )
{
if ( ( gLinkPlayers [ GetMultiplayerId ( ) ] . version & 0xFF ) = = VERSION_FIRE_RED
| | ( gLinkPlayers [ GetMultiplayerId ( ) ] . version & 0xFF ) = = VERSION_LEAF_GREEN )
{
trainerPicId = gLinkPlayers [ GetMultiplayerId ( ) ] . gender + BACK_PIC_RED ;
}
else if ( ( gLinkPlayers [ GetMultiplayerId ( ) ] . version & 0xFF ) = = VERSION_RUBY
| | ( gLinkPlayers [ GetMultiplayerId ( ) ] . version & 0xFF ) = = VERSION_SAPPHIRE )
{
trainerPicId = gLinkPlayers [ GetMultiplayerId ( ) ] . gender + BACK_PIC_RS_BRENDAN ;
}
else
{
trainerPicId = gLinkPlayers [ GetMultiplayerId ( ) ] . gender ;
}
}
else
{
trainerPicId = gSaveBlock2Ptr - > playerGender ;
}
2018-02-06 02:46:59 +01:00
DecompressTrainerBackPic ( trainerPicId , gActiveBattler ) ;
sub_806A12C ( trainerPicId , GetBattlerPosition ( gActiveBattler ) ) ;
2018-02-06 20:48:02 +01:00
gBattlerSpriteIds [ gActiveBattler ] = CreateSprite ( & gUnknown_0202499C , 80 , ( 8 - gTrainerBackPicCoords [ trainerPicId ] . coords ) * 4 + 80 , 30 ) ;
2017-10-22 01:04:02 +02:00
2018-02-06 20:48:02 +01:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . oam . paletteNum = gActiveBattler ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . pos2 . x = - 96 ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . data [ 0 ] = 2 ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . callback = sub_805D7AC ;
2017-10-22 01:04:02 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = CompleteOnBankSpriteCallbackDummy2 ;
2017-10-22 01:04:02 +02:00
}
2017-10-22 18:43:15 +02:00
static void PlayerHandleTrainerSlideBack ( void )
2017-10-22 01:04:02 +02:00
{
2018-02-06 20:48:02 +01:00
oamt_add_pos2_onto_pos1 ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] ) ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . data [ 0 ] = 50 ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . data [ 2 ] = - 40 ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . data [ 4 ] = gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . pos1 . y ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . callback = sub_80A6EEC ;
StoreSpriteCallbackInData6 ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] , SpriteCallbackDummy ) ;
StartSpriteAnim ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] , 1 ) ;
gBattlerControllerFuncs [ gActiveBattler ] = sub_80588B4 ;
2017-10-22 01:04:02 +02:00
}
2017-10-22 18:43:15 +02:00
static void PlayerHandleFaintAnimation ( void )
2017-10-22 01:04:02 +02:00
{
2018-02-06 02:46:59 +01:00
if ( gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState = = 0 )
2017-10-22 01:04:02 +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-22 01:04:02 +02:00
}
else
{
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . specialAnimActive )
2017-10-22 01:04:02 +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 ) ;
2017-10-24 15:25:20 +02:00
PlaySE12WithPanning ( SE_POKE_DEAD , PAN_SIDE_PLAYER ) ;
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_80596A8 ;
2017-10-22 01:04:02 +02:00
}
}
}
2017-10-22 18:43:15 +02:00
static void PlayerHandlePaletteFade ( void )
2017-10-22 01:04:02 +02:00
{
BeginNormalPaletteFade ( - 1 , 2 , 0 , 16 , 0 ) ;
PlayerBufferExecCompleted ( ) ;
}
2017-10-22 18:43:15 +02:00
static void PlayerHandleSuccessBallThrowAnim ( void )
2017-10-22 01:04:02 +02:00
{
2017-10-22 18:43:15 +02:00
gBattleSpritesDataPtr - > animationData - > ballThrowCaseId = BALL_3_SHAKES_SUCCESS ;
2017-10-22 01:04:02 +02:00
gDoingBattleAnim = TRUE ;
2018-02-06 02:46:59 +01:00
InitAndLaunchSpecialAnimation ( gActiveBattler , gActiveBattler , GetBattlerAtPosition ( B_POSITION_OPPONENT_LEFT ) , B_ANIM_BALL_THROW ) ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = CompleteOnSpecialAnimDone ;
2017-10-22 01:04:02 +02:00
}
2017-10-22 18:43:15 +02:00
static void PlayerHandleBallThrowAnim ( void )
2017-10-22 01:04:02 +02:00
{
2018-02-06 02:46:59 +01:00
u8 ballThrowCaseId = gBattleBufferA [ gActiveBattler ] [ 1 ] ;
2017-10-22 01:04:02 +02:00
2017-10-22 18:43:15 +02:00
gBattleSpritesDataPtr - > animationData - > ballThrowCaseId = ballThrowCaseId ;
2017-10-22 01:04:02 +02:00
gDoingBattleAnim = TRUE ;
2018-02-06 02:46:59 +01:00
InitAndLaunchSpecialAnimation ( gActiveBattler , gActiveBattler , GetBattlerAtPosition ( B_POSITION_OPPONENT_LEFT ) , B_ANIM_BALL_THROW ) ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = CompleteOnSpecialAnimDone ;
2017-10-22 01:04:02 +02:00
}
2017-10-22 18:43:15 +02:00
static void PlayerHandlePause ( void )
2017-10-22 01:04:02 +02:00
{
2018-02-06 02:46:59 +01:00
u8 var = gBattleBufferA [ gActiveBattler ] [ 1 ] ;
2017-10-22 01:04:02 +02:00
// WTF is this??
while ( var ! = 0 )
var - - ;
PlayerBufferExecCompleted ( ) ;
}
2017-10-22 18:43:15 +02:00
static void PlayerHandleMoveAnimation ( void )
2017-10-22 01:04:02 +02:00
{
2018-02-06 02:46:59 +01:00
if ( ! mplay_80342A4 ( gActiveBattler ) )
2017-10-22 01:04:02 +02:00
{
2018-02-06 02:46:59 +01:00
u16 move = gBattleBufferA [ gActiveBattler ] [ 1 ] | ( gBattleBufferA [ gActiveBattler ] [ 2 ] < < 8 ) ;
2017-10-22 01:04:02 +02:00
2018-02-06 02:46:59 +01:00
gAnimMoveTurn = gBattleBufferA [ gActiveBattler ] [ 3 ] ;
gAnimMovePower = gBattleBufferA [ gActiveBattler ] [ 4 ] | ( gBattleBufferA [ gActiveBattler ] [ 5 ] < < 8 ) ;
gAnimMoveDmg = gBattleBufferA [ gActiveBattler ] [ 6 ] | ( gBattleBufferA [ gActiveBattler ] [ 7 ] < < 8 ) | ( gBattleBufferA [ gActiveBattler ] [ 8 ] < < 16 ) | ( gBattleBufferA [ gActiveBattler ] [ 9 ] < < 24 ) ;
gAnimFriendship = gBattleBufferA [ gActiveBattler ] [ 10 ] ;
gWeatherMoveAnim = gBattleBufferA [ gActiveBattler ] [ 12 ] | ( gBattleBufferA [ gActiveBattler ] [ 13 ] < < 8 ) ;
gAnimDisableStructPtr = ( struct DisableStruct * ) & gBattleBufferA [ gActiveBattler ] [ 16 ] ;
gTransformedPersonalities [ gActiveBattler ] = gAnimDisableStructPtr - > transformedMonPersonality ;
2017-10-23 13:32:11 +02:00
if ( IsMoveWithoutAnimation ( move , gAnimMoveTurn ) ) // always returns FALSE
2017-10-22 01:04:02 +02:00
{
PlayerBufferExecCompleted ( ) ;
}
else
{
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState = 0 ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = PlayerDoMoveAnimation ;
2018-02-27 20:40:09 +01:00
BattleTv_SetDataBasedOnMove ( move , gWeatherMoveAnim , gAnimDisableStructPtr ) ;
2017-10-22 01:04:02 +02:00
}
}
}
2017-10-22 18:43:15 +02:00
static void PlayerDoMoveAnimation ( void )
2017-10-22 01:04:02 +02:00
{
2018-02-06 02:46:59 +01:00
u16 move = gBattleBufferA [ gActiveBattler ] [ 1 ] | ( gBattleBufferA [ gActiveBattler ] [ 2 ] < < 8 ) ;
u8 multihit = gBattleBufferA [ gActiveBattler ] [ 11 ] ;
2017-10-22 01:04:02 +02:00
2018-02-06 02:46:59 +01:00
switch ( gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState )
2017-10-22 01:04:02 +02:00
{
case 0 :
2018-02-06 23:09:39 +01:00
if ( gBattleSpritesDataPtr - > battlerData [ gActiveBattler ] . behindSubstitute
& & ! gBattleSpritesDataPtr - > battlerData [ gActiveBattler ] . flag_x8 )
2017-10-22 01:04:02 +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-22 01:04:02 +02:00
}
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState = 1 ;
2017-10-22 01:04:02 +02:00
break ;
case 1 :
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . specialAnimActive )
2017-10-22 01:04:02 +02:00
{
sub_805EB9C ( 0 ) ;
DoMoveAnim ( move ) ;
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState = 2 ;
2017-10-22 01:04:02 +02:00
}
break ;
case 2 :
gAnimScriptCallback ( ) ;
if ( ! gAnimScriptActive )
{
sub_805EB9C ( 1 ) ;
2018-02-06 23:09:39 +01:00
if ( gBattleSpritesDataPtr - > battlerData [ gActiveBattler ] . behindSubstitute & & multihit < 2 )
2017-10-22 01:04:02 +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-22 01:04:02 +02:00
}
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState = 3 ;
2017-10-22 01:04:02 +02:00
}
break ;
case 3 :
2018-02-06 02:46:59 +01:00
if ( ! gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . specialAnimActive )
2017-10-22 01:04:02 +02:00
{
2017-11-04 16:11:13 +01:00
CopyAllBattleSpritesInvisibilities ( ) ;
2018-02-06 02:46:59 +01:00
TrySetBehindSubstituteSpriteBit ( gActiveBattler , gBattleBufferA [ gActiveBattler ] [ 1 ] | ( gBattleBufferA [ gActiveBattler ] [ 2 ] < < 8 ) ) ;
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . animationState = 0 ;
2017-10-22 01:04:02 +02:00
PlayerBufferExecCompleted ( ) ;
}
break ;
}
}
2017-10-22 18:43:15 +02:00
static void PlayerHandlePrintString ( void )
2017-10-22 01:04:02 +02:00
{
u16 * stringId ;
gBattle_BG0_X = 0 ;
gBattle_BG0_Y = 0 ;
2018-02-06 02:46:59 +01:00
stringId = ( u16 * ) ( & gBattleBufferA [ gActiveBattler ] [ 2 ] ) ;
2017-10-22 01:04:02 +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 ;
2018-02-27 20:40:09 +01:00
BattleTv_SetDataBasedOnString ( * stringId ) ;
2018-02-06 02:46:59 +01:00
sub_81A57E4 ( gActiveBattler , * stringId ) ;
2017-10-22 01:04:02 +02:00
}
2017-11-25 18:42:31 +01:00
static void PlayerHandlePrintSelectionString ( void )
2017-10-22 01:04:02 +02:00
{
2018-02-06 02:46:59 +01:00
if ( GetBattlerSide ( gActiveBattler ) = = B_SIDE_PLAYER )
2017-10-22 01:04:02 +02:00
PlayerHandlePrintString ( ) ;
else
PlayerBufferExecCompleted ( ) ;
}
2017-10-22 18:43:15 +02:00
static void HandleChooseActionAfterDma3 ( void )
2017-10-22 01:04:02 +02:00
{
if ( ! IsDma3ManagerBusyWithBgCopy ( ) )
{
gBattle_BG0_X = 0 ;
gBattle_BG0_Y = 160 ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = HandleInputChooseAction ;
2017-10-22 01:04:02 +02:00
}
}
2017-10-22 18:43:15 +02:00
static void PlayerHandleChooseAction ( void )
2017-10-22 01:04:02 +02:00
{
s32 i ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = HandleChooseActionAfterDma3 ;
2018-02-27 20:40:09 +01:00
BattleTv_ClearExplosionFaintCause ( ) ;
2018-06-17 16:48:58 +02:00
BattlePutTextOnWindow ( gText_BattleMenu , 2 ) ;
2017-10-22 01:04:02 +02:00
for ( i = 0 ; i < 4 ; i + + )
ActionSelectionDestroyCursorAt ( i ) ;
2018-02-06 02:46:59 +01:00
ActionSelectionCreateCursorAt ( gActionSelectionCursor [ gActiveBattler ] , 0 ) ;
2017-10-22 01:04:02 +02:00
BattleStringExpandPlaceholdersToDisplayedString ( gText_WhatWillPkmnDo ) ;
2018-06-17 16:48:58 +02:00
BattlePutTextOnWindow ( gDisplayedStringBattle , 1 ) ;
2017-10-22 01:04:02 +02:00
}
2017-10-22 18:43:15 +02:00
static void PlayerHandleUnknownYesNoBox ( void )
2017-10-22 01:04:02 +02:00
{
2018-02-06 02:46:59 +01:00
if ( GetBattlerSide ( gActiveBattler ) = = B_SIDE_PLAYER )
2017-10-22 01:04:02 +02:00
{
HandleBattleWindow ( 0x18 , 8 , 0x1D , 0xD , 0 ) ;
2018-06-17 16:48:58 +02:00
BattlePutTextOnWindow ( gText_BattleYesNoChoice , 12 ) ;
2017-10-22 01:04:02 +02:00
gMultiUsePlayerCursor = 1 ;
BattleCreateYesNoCursorAt ( 1 ) ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = PlayerHandleUnknownYesNoInput ;
2017-10-22 18:43:15 +02:00
}
else
{
PlayerBufferExecCompleted ( ) ;
}
}
static void HandleChooseMoveAfterDma3 ( void )
{
if ( ! IsDma3ManagerBusyWithBgCopy ( ) )
{
gBattle_BG0_X = 0 ;
gBattle_BG0_Y = 320 ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = HandleInputChooseMove ;
2017-10-22 18:43:15 +02:00
}
}
static void PlayerChooseMoveInBattlePalace ( void )
{
2018-02-06 02:46:59 +01:00
if ( - - * ( gBattleStruct - > field_298 + gActiveBattler ) = = 0 )
2017-10-22 18:43:15 +02:00
{
gBattlePalaceMoveSelectionRngValue = gRngValue ;
2018-02-06 20:48:02 +01:00
BtlController_EmitTwoReturnValues ( 1 , 10 , ChooseMoveAndTargetInBattlePalace ( ) ) ;
2017-10-22 18:43:15 +02:00
PlayerBufferExecCompleted ( ) ;
}
}
static void PlayerHandleChooseMove ( void )
{
if ( gBattleTypeFlags & BATTLE_TYPE_PALACE )
{
2018-02-06 02:46:59 +01:00
* ( gBattleStruct - > field_298 + gActiveBattler ) = 8 ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = PlayerChooseMoveInBattlePalace ;
2017-10-22 18:43:15 +02:00
}
else
{
InitMoveSelectionsVarsAndStrings ( ) ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = HandleChooseMoveAfterDma3 ;
2017-10-22 18:43:15 +02:00
}
}
void InitMoveSelectionsVarsAndStrings ( void )
{
MoveSelectionDisplayMoveNames ( ) ;
gMultiUsePlayerCursor = 0xFF ;
2018-02-06 02:46:59 +01:00
MoveSelectionCreateCursorAt ( gMoveSelectionCursor [ gActiveBattler ] , 0 ) ;
2017-10-22 18:43:15 +02:00
MoveSelectionDisplayPpString ( ) ;
MoveSelectionDisplayPpNumber ( ) ;
MoveSelectionDisplayMoveType ( ) ;
}
static void PlayerHandleChooseItem ( void )
{
s32 i ;
BeginNormalPaletteFade ( - 1 , 0 , 0 , 0x10 , 0 ) ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = OpenBagAndChooseItem ;
2018-02-07 22:53:40 +01:00
gBattlerInMenuId = gActiveBattler ;
2017-10-22 18:43:15 +02:00
for ( i = 0 ; i < 3 ; i + + )
2018-02-06 02:46:59 +01:00
gUnknown_0203CF00 [ i ] = gBattleBufferA [ gActiveBattler ] [ 1 + i ] ;
2017-10-22 18:43:15 +02:00
}
static void PlayerHandleChoosePokemon ( void )
{
s32 i ;
for ( i = 0 ; i < 3 ; i + + )
2018-02-06 02:46:59 +01:00
gUnknown_0203CF00 [ i ] = gBattleBufferA [ gActiveBattler ] [ 4 + i ] ;
2017-10-22 18:43:15 +02:00
2018-02-06 02:46:59 +01:00
if ( gBattleTypeFlags & BATTLE_TYPE_ARENA & & ( gBattleBufferA [ gActiveBattler ] [ 1 ] & 0xF ) ! = 2 )
2017-10-22 18:43:15 +02:00
{
2018-02-06 20:48:02 +01:00
BtlController_EmitChosenMonReturnValue ( 1 , gBattlerPartyIndexes [ gActiveBattler ] + 1 , gUnknown_0203CF00 ) ;
2017-10-22 18:43:15 +02:00
PlayerBufferExecCompleted ( ) ;
}
else
{
2018-02-06 02:46:59 +01:00
gUnknown_03005D7C [ gActiveBattler ] = CreateTask ( TaskDummy , 0xFF ) ;
gTasks [ gUnknown_03005D7C [ gActiveBattler ] ] . data [ 0 ] = gBattleBufferA [ gActiveBattler ] [ 1 ] & 0xF ;
* ( & gBattleStruct - > field_49 ) = gBattleBufferA [ gActiveBattler ] [ 1 ] > > 4 ;
* ( & gBattleStruct - > field_8B ) = gBattleBufferA [ gActiveBattler ] [ 2 ] ;
* ( & gBattleStruct - > field_B0 ) = gBattleBufferA [ gActiveBattler ] [ 3 ] ;
2017-10-22 18:43:15 +02:00
BeginNormalPaletteFade ( - 1 , 0 , 0 , 16 , 0 ) ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = sub_80597CC ;
2018-02-07 22:53:40 +01:00
gBattlerInMenuId = gActiveBattler ;
2017-10-22 18:43:15 +02:00
}
}
static void PlayerHandleCmd23 ( void )
{
2017-11-04 16:11:13 +01:00
BattleStopLowHpSound ( ) ;
2017-10-22 18:43:15 +02:00
BeginNormalPaletteFade ( - 1 , 2 , 0 , 16 , 0 ) ;
PlayerBufferExecCompleted ( ) ;
}
static void PlayerHandleHealthBarUpdate ( void )
{
s16 hpVal ;
LoadBattleBarGfx ( 0 ) ;
2018-02-06 02:46:59 +01:00
hpVal = gBattleBufferA [ gActiveBattler ] [ 2 ] | ( gBattleBufferA [ gActiveBattler ] [ 3 ] < < 8 ) ;
2017-10-22 18:43:15 +02:00
if ( hpVal > 0 )
gUnknown_0203CD70 + = hpVal ;
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-22 18:43:15 +02:00
2018-02-06 20:48:02 +01:00
SetBattleBarStruct ( gActiveBattler , gHealthboxSpriteIds [ gActiveBattler ] , maxHP , curHP , hpVal ) ;
2017-10-22 18:43:15 +02:00
}
else
{
2018-02-06 20:48:02 +01:00
u32 maxHP = GetMonData ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , MON_DATA_MAX_HP ) ;
2017-10-22 18:43:15 +02:00
2018-02-06 20:48:02 +01:00
SetBattleBarStruct ( gActiveBattler , gHealthboxSpriteIds [ gActiveBattler ] , maxHP , 0 , hpVal ) ;
UpdateHpTextInHealthbox ( gHealthboxSpriteIds [ gActiveBattler ] , 0 , HP_CURRENT ) ;
2017-10-22 18:43:15 +02:00
}
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = CompleteOnHealthbarDone ;
2017-10-22 18:43:15 +02:00
}
static void PlayerHandleExpUpdate ( void )
{
2018-02-06 02:46:59 +01:00
u8 monId = gBattleBufferA [ gActiveBattler ] [ 1 ] ;
2017-10-22 18:43:15 +02:00
if ( GetMonData ( & gPlayerParty [ monId ] , MON_DATA_LEVEL ) > = MAX_MON_LEVEL )
{
PlayerBufferExecCompleted ( ) ;
}
else
{
s16 expPointsToGive ;
u8 taskId ;
LoadBattleBarGfx ( 1 ) ;
GetMonData ( & gPlayerParty [ monId ] , MON_DATA_SPECIES ) ; // unused return value
2018-02-06 02:46:59 +01:00
expPointsToGive = gBattleBufferA [ gActiveBattler ] [ 2 ] | ( gBattleBufferA [ gActiveBattler ] [ 3 ] < < 8 ) ;
2017-10-22 18:43:15 +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-22 18:43:15 +02:00
}
}
# undef tExpTask_monId
# undef tExpTask_gainedExp
# undef tExpTask_bank
# undef tExpTask_frames
static void PlayerHandleStatusIconUpdate ( void )
{
2018-02-06 02:46:59 +01:00
if ( ! mplay_80342A4 ( gActiveBattler ) )
2017-10-22 18:43:15 +02:00
{
2018-03-01 00:59:52 +01:00
u8 battlerId ;
2017-10-22 18:43:15 +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-22 18:43:15 +02:00
}
}
static void PlayerHandleStatusAnimation ( void )
{
2018-02-06 02:46:59 +01:00
if ( ! mplay_80342A4 ( gActiveBattler ) )
2017-10-22 18:43:15 +02:00
{
2018-02-06 02:46:59 +01:00
InitAndLaunchChosenStatusAnimation ( gBattleBufferA [ gActiveBattler ] [ 1 ] ,
gBattleBufferA [ gActiveBattler ] [ 2 ] | ( gBattleBufferA [ gActiveBattler ] [ 3 ] < < 8 ) | ( gBattleBufferA [ gActiveBattler ] [ 4 ] < < 16 ) | ( gBattleBufferA [ gActiveBattler ] [ 5 ] < < 24 ) ) ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = CompleteOnFinishedStatusAnimation ;
2017-10-22 18:43:15 +02:00
}
}
static void PlayerHandleStatusXor ( void )
{
2018-02-06 20:48:02 +01:00
u8 val = GetMonData ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , MON_DATA_STATUS ) ^ gBattleBufferA [ gActiveBattler ] [ 1 ] ;
2017-10-22 18:43:15 +02:00
2018-02-06 20:48:02 +01:00
SetMonData ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , MON_DATA_STATUS , & val ) ;
2017-10-22 18:43:15 +02:00
PlayerBufferExecCompleted ( ) ;
}
static void PlayerHandleDataTransfer ( void )
{
PlayerBufferExecCompleted ( ) ;
}
static void PlayerHandleDMA3Transfer ( void )
{
2018-02-06 02:46:59 +01:00
u32 dstArg = gBattleBufferA [ gActiveBattler ] [ 1 ]
| ( gBattleBufferA [ gActiveBattler ] [ 2 ] < < 8 )
| ( gBattleBufferA [ gActiveBattler ] [ 3 ] < < 16 )
| ( gBattleBufferA [ gActiveBattler ] [ 4 ] < < 24 ) ;
u16 sizeArg = gBattleBufferA [ gActiveBattler ] [ 5 ] | ( gBattleBufferA [ gActiveBattler ] [ 6 ] < < 8 ) ;
2017-10-22 18:43:15 +02:00
2018-02-06 02:46:59 +01:00
const u8 * src = & gBattleBufferA [ gActiveBattler ] [ 7 ] ;
2017-10-22 18:43:15 +02:00
u8 * dst = ( u8 * ) ( dstArg ) ;
u32 size = sizeArg ;
while ( 1 )
{
if ( size < = 0x1000 )
{
DmaCopy16 ( 3 , src , dst , size ) ;
break ;
}
DmaCopy16 ( 3 , src , dst , 0x1000 ) ;
src + = 0x1000 ;
dst + = 0x1000 ;
size - = 0x1000 ;
}
PlayerBufferExecCompleted ( ) ;
}
static void PlayerHandlePlayBGM ( void )
{
2018-02-06 02:46:59 +01:00
PlayBGM ( gBattleBufferA [ gActiveBattler ] [ 1 ] | ( gBattleBufferA [ gActiveBattler ] [ 2 ] < < 8 ) ) ;
2017-10-22 18:43:15 +02:00
PlayerBufferExecCompleted ( ) ;
}
static void PlayerHandleCmd32 ( void )
{
PlayerBufferExecCompleted ( ) ;
}
static void PlayerHandleTwoReturnValues ( void )
{
2018-02-06 20:48:02 +01:00
BtlController_EmitTwoReturnValues ( 1 , 0 , 0 ) ;
2017-10-22 18:43:15 +02:00
PlayerBufferExecCompleted ( ) ;
}
static void PlayerHandleChosenMonReturnValue ( void )
{
2018-02-06 20:48:02 +01:00
BtlController_EmitChosenMonReturnValue ( 1 , 0 , NULL ) ;
2017-10-22 18:43:15 +02:00
PlayerBufferExecCompleted ( ) ;
}
static void PlayerHandleOneReturnValue ( void )
{
2018-02-06 20:48:02 +01:00
BtlController_EmitOneReturnValue ( 1 , 0 ) ;
2017-10-22 18:43:15 +02:00
PlayerBufferExecCompleted ( ) ;
}
static void PlayerHandleOneReturnValue_Duplicate ( void )
{
2018-02-06 20:48:02 +01:00
BtlController_EmitOneReturnValue_Duplicate ( 1 , 0 ) ;
2017-10-22 18:43:15 +02:00
PlayerBufferExecCompleted ( ) ;
}
static void PlayerHandleCmd37 ( void )
{
gUnknown_02022D0C . field_0 = 0 ;
PlayerBufferExecCompleted ( ) ;
}
static void PlayerHandleCmd38 ( void )
{
2018-02-06 02:46:59 +01:00
gUnknown_02022D0C . field_0 = gBattleBufferA [ gActiveBattler ] [ 1 ] ;
2017-10-22 18:43:15 +02:00
PlayerBufferExecCompleted ( ) ;
}
static void PlayerHandleCmd39 ( void )
{
gUnknown_02022D0C . flag_x80 = 0 ;
PlayerBufferExecCompleted ( ) ;
}
static void PlayerHandleCmd40 ( void )
{
gUnknown_02022D0C . flag_x80 ^ = 1 ;
PlayerBufferExecCompleted ( ) ;
}
static void PlayerHandleHitAnimation ( void )
{
2018-02-06 20:48:02 +01:00
if ( gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . invisible = = TRUE )
2017-10-22 18:43:15 +02:00
{
PlayerBufferExecCompleted ( ) ;
}
else
{
2017-10-24 15:25:20 +02:00
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-22 18:43:15 +02:00
}
}
static void PlayerHandleCmd42 ( void )
{
PlayerBufferExecCompleted ( ) ;
}
2017-11-25 18:42:31 +01:00
static void PlayerHandlePlaySE ( void )
2017-10-22 18:43:15 +02:00
{
s8 pan ;
2018-02-06 02:46:59 +01:00
if ( GetBattlerSide ( gActiveBattler ) = = B_SIDE_PLAYER )
2017-10-22 18:43:15 +02:00
pan = PAN_SIDE_PLAYER ;
else
pan = PAN_SIDE_OPPONENT ;
2018-02-06 02:46:59 +01:00
PlaySE12WithPanning ( gBattleBufferA [ gActiveBattler ] [ 1 ] | ( gBattleBufferA [ gActiveBattler ] [ 2 ] < < 8 ) , pan ) ;
2017-10-22 18:43:15 +02:00
PlayerBufferExecCompleted ( ) ;
}
static void PlayerHandlePlayFanfareOrBGM ( void )
{
2018-02-06 02:46:59 +01:00
if ( gBattleBufferA [ gActiveBattler ] [ 3 ] )
2017-10-22 18:43:15 +02:00
{
2017-11-04 16:11:13 +01:00
BattleStopLowHpSound ( ) ;
2018-02-06 02:46:59 +01:00
PlayBGM ( gBattleBufferA [ gActiveBattler ] [ 1 ] | ( gBattleBufferA [ gActiveBattler ] [ 2 ] < < 8 ) ) ;
2017-10-22 18:43:15 +02:00
}
else
{
2018-02-06 02:46:59 +01:00
PlayFanfare ( gBattleBufferA [ gActiveBattler ] [ 1 ] | ( gBattleBufferA [ gActiveBattler ] [ 2 ] < < 8 ) ) ;
2017-10-22 18:43:15 +02:00
}
PlayerBufferExecCompleted ( ) ;
}
static void PlayerHandleFaintingCry ( void )
{
2018-02-06 20:48:02 +01:00
u16 species = GetMonData ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , MON_DATA_SPECIES ) ;
2017-10-22 18:43:15 +02:00
PlayCry3 ( species , - 25 , 5 ) ;
PlayerBufferExecCompleted ( ) ;
}
static void PlayerHandleIntroSlide ( void )
{
2018-02-06 02:46:59 +01:00
HandleIntroSlide ( gBattleBufferA [ gActiveBattler ] [ 1 ] ) ;
2018-02-08 11:17:41 +01:00
gIntroSlideFlags | = 1 ;
2017-10-22 18:43:15 +02:00
PlayerBufferExecCompleted ( ) ;
}
static void PlayerHandleIntroTrainerBallThrow ( void )
{
u8 paletteNum ;
u8 taskId ;
2018-02-06 20:48:02 +01:00
oamt_add_pos2_onto_pos1 ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] ) ;
2017-10-22 18:43:15 +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 ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . callback = sub_80A6EEC ;
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . data [ 5 ] = gActiveBattler ;
2017-10-22 18:43:15 +02:00
2018-02-06 20:48:02 +01:00
StoreSpriteCallbackInData6 ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] , sub_805CC00 ) ;
StartSpriteAnim ( & gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] , 1 ) ;
2017-10-22 18:43:15 +02:00
paletteNum = AllocSpritePalette ( 0xD6F8 ) ;
LoadCompressedPalette ( gTrainerBackPicPaletteTable [ gSaveBlock2Ptr - > playerGender ] . data , 0x100 + paletteNum * 16 , 32 ) ;
2018-02-06 20:48:02 +01:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . oam . paletteNum = paletteNum ;
2017-10-22 18:43:15 +02:00
taskId = CreateTask ( task05_08033660 , 5 ) ;
2018-02-06 02:46:59 +01:00
gTasks [ taskId ] . data [ 0 ] = gActiveBattler ;
2017-10-22 18:43:15 +02:00
2018-02-06 02:46:59 +01:00
if ( gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . flag_x1 )
2018-02-08 11:17:41 +01:00
gTasks [ gBattlerStatusSummaryTaskId [ gActiveBattler ] ] . func = sub_8073C30 ;
2017-10-22 18:43:15 +02:00
gBattleSpritesDataPtr - > animationData - > field_9_x1 = 1 ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = nullsub_21 ;
2017-10-22 18:43:15 +02:00
}
void sub_805CC00 ( struct Sprite * sprite )
{
2018-03-01 00:59:52 +01:00
u8 battlerId = sprite - > data [ 5 ] ;
2017-10-22 18:43:15 +02:00
FreeSpriteOamMatrix ( sprite ) ;
FreeSpritePaletteByTag ( GetSpritePaletteTagByPaletteNum ( sprite - > oam . paletteNum ) ) ;
DestroySprite ( sprite ) ;
2018-03-01 00:59:52 +01:00
BattleLoadPlayerMonSpriteGfx ( & gPlayerParty [ gBattlerPartyIndexes [ battlerId ] ] , battlerId ) ;
StartSpriteAnim ( & gSprites [ gBattlerSpriteIds [ battlerId ] ] , 0 ) ;
2017-10-22 18:43:15 +02:00
}
static void task05_08033660 ( u8 taskId )
{
if ( gTasks [ taskId ] . data [ 1 ] < 31 )
{
gTasks [ taskId ] . data [ 1 ] + + ;
2017-10-22 01:04:02 +02:00
}
else
2017-10-22 18:43:15 +02:00
{
2018-02-06 02:46:59 +01:00
u8 savedActiveBank = gActiveBattler ;
2017-10-22 18:43:15 +02:00
2018-02-06 02:46:59 +01:00
gActiveBattler = gTasks [ taskId ] . data [ 0 ] ;
2017-10-22 18:43:15 +02:00
if ( ! IsDoubleBattle ( ) | | ( gBattleTypeFlags & BATTLE_TYPE_MULTI ) )
{
2018-02-06 20:48:02 +01:00
gBattleBufferA [ gActiveBattler ] [ 1 ] = gBattlerPartyIndexes [ gActiveBattler ] ;
2018-02-06 02:46:59 +01:00
sub_805B258 ( gActiveBattler , FALSE ) ;
2017-10-22 18:43:15 +02:00
}
else
{
2018-02-06 20:48:02 +01:00
gBattleBufferA [ gActiveBattler ] [ 1 ] = gBattlerPartyIndexes [ gActiveBattler ] ;
2018-02-06 02:46:59 +01:00
sub_805B258 ( gActiveBattler , FALSE ) ;
gActiveBattler ^ = BIT_FLANK ;
2018-02-06 20:48:02 +01:00
gBattleBufferA [ gActiveBattler ] [ 1 ] = gBattlerPartyIndexes [ gActiveBattler ] ;
BattleLoadPlayerMonSpriteGfx ( & gPlayerParty [ gBattlerPartyIndexes [ gActiveBattler ] ] , gActiveBattler ) ;
2018-02-06 02:46:59 +01:00
sub_805B258 ( gActiveBattler , FALSE ) ;
gActiveBattler ^ = BIT_FLANK ;
2017-10-22 18:43:15 +02:00
}
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = sub_8058B40 ;
2018-02-06 02:46:59 +01:00
gActiveBattler = savedActiveBank ;
2017-10-22 18:43:15 +02:00
DestroyTask ( taskId ) ;
}
}
static void PlayerHandleDrawPartyStatusSummary ( void )
{
2018-02-06 02:46:59 +01:00
if ( gBattleBufferA [ gActiveBattler ] [ 1 ] ! = 0 & & GetBattlerSide ( gActiveBattler ) = = B_SIDE_PLAYER )
2017-10-22 01:04:02 +02:00
{
PlayerBufferExecCompleted ( ) ;
2017-10-21 17:32:35 +02:00
}
2017-10-22 18:43:15 +02:00
else
{
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . flag_x1 = 1 ;
2018-02-08 11:17:41 +01:00
gBattlerStatusSummaryTaskId [ gActiveBattler ] = CreatePartyStatusSummarySprites ( gActiveBattler , ( struct HpAndStatus * ) & gBattleBufferA [ gActiveBattler ] [ 4 ] , gBattleBufferA [ gActiveBattler ] [ 1 ] , gBattleBufferA [ gActiveBattler ] [ 2 ] ) ;
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . field_5 = 0 ;
2017-10-22 18:43:15 +02:00
2018-02-06 02:46:59 +01:00
if ( gBattleBufferA [ gActiveBattler ] [ 2 ] ! = 0 )
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . field_5 = 0x5D ;
2017-10-22 18:43:15 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = sub_805CE38 ;
2017-10-22 18:43:15 +02:00
}
}
static void sub_805CE38 ( void )
{
2018-02-06 02:46:59 +01:00
if ( gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . field_5 + + > 0x5C )
2017-10-22 18:43:15 +02:00
{
2018-02-06 02:46:59 +01:00
gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . field_5 = 0 ;
2017-10-22 18:43:15 +02:00
PlayerBufferExecCompleted ( ) ;
}
}
static void PlayerHandleCmd49 ( void )
{
2018-02-06 02:46:59 +01:00
if ( gBattleSpritesDataPtr - > healthBoxesData [ gActiveBattler ] . flag_x1 )
2018-02-08 11:17:41 +01:00
gTasks [ gBattlerStatusSummaryTaskId [ gActiveBattler ] ] . func = sub_8073C30 ;
2017-10-22 18:43:15 +02:00
PlayerBufferExecCompleted ( ) ;
}
static void PlayerHandleCmd50 ( void )
{
2018-02-06 02:46:59 +01:00
dp11b_obj_free ( gActiveBattler , 1 ) ;
dp11b_obj_free ( gActiveBattler , 0 ) ;
2017-10-22 18:43:15 +02:00
PlayerBufferExecCompleted ( ) ;
}
static void PlayerHandleSpriteInvisibility ( void )
{
2018-02-06 20:48:02 +01:00
if ( IsBattlerSpritePresent ( gActiveBattler ) )
2017-10-22 18:43:15 +02:00
{
2018-02-06 20:48:02 +01:00
gSprites [ gBattlerSpriteIds [ gActiveBattler ] ] . invisible = gBattleBufferA [ gActiveBattler ] [ 1 ] ;
2018-02-06 02:46:59 +01:00
CopyBattleSpriteInvisibility ( gActiveBattler ) ;
2017-10-22 18:43:15 +02:00
}
PlayerBufferExecCompleted ( ) ;
}
static void PlayerHandleBattleAnimation ( void )
{
2018-02-06 02:46:59 +01:00
if ( ! mplay_80342A4 ( gActiveBattler ) )
2017-10-22 18:43:15 +02:00
{
2018-02-06 02:46:59 +01:00
u8 animationId = gBattleBufferA [ gActiveBattler ] [ 1 ] ;
u16 argument = gBattleBufferA [ gActiveBattler ] [ 2 ] | ( gBattleBufferA [ gActiveBattler ] [ 3 ] < < 8 ) ;
2017-10-22 18:43:15 +02:00
2018-02-06 02:46:59 +01:00
if ( TryHandleLaunchBattleTableAnimation ( gActiveBattler , gActiveBattler , gActiveBattler , animationId , argument ) )
2017-10-22 18:43:15 +02:00
PlayerBufferExecCompleted ( ) ;
else
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = CompleteOnFinishedBattleAnimation ;
2017-10-22 18:43:15 +02:00
2018-02-27 20:40:09 +01:00
BattleTv_SetDataBasedOnAnimation ( animationId ) ;
2017-10-22 18:43:15 +02:00
}
}
static void PlayerHandleLinkStandbyMsg ( void )
{
2018-02-06 02:46:59 +01:00
sub_81851A8 ( & gBattleBufferA [ gActiveBattler ] [ 2 ] ) ;
switch ( gBattleBufferA [ gActiveBattler ] [ 1 ] )
2017-10-22 18:43:15 +02:00
{
case 0 :
PrintLinkStandbyMsg ( ) ;
// fall through
case 1 :
2018-02-06 02:46:59 +01:00
dp11b_obj_free ( gActiveBattler , 1 ) ;
dp11b_obj_free ( gActiveBattler , 0 ) ;
2017-10-22 18:43:15 +02:00
break ;
case 2 :
PrintLinkStandbyMsg ( ) ;
break ;
}
PlayerBufferExecCompleted ( ) ;
}
static void PlayerHandleResetActionMoveSelection ( void )
{
2018-02-06 02:46:59 +01:00
switch ( gBattleBufferA [ gActiveBattler ] [ 1 ] )
2017-10-22 18:43:15 +02:00
{
case RESET_ACTION_MOVE_SELECTION :
2018-02-06 02:46:59 +01:00
gActionSelectionCursor [ gActiveBattler ] = 0 ;
gMoveSelectionCursor [ gActiveBattler ] = 0 ;
2017-10-22 18:43:15 +02:00
break ;
case RESET_ACTION_SELECTION :
2018-02-06 02:46:59 +01:00
gActionSelectionCursor [ gActiveBattler ] = 0 ;
2017-10-22 18:43:15 +02:00
break ;
case RESET_MOVE_SELECTION :
2018-02-06 02:46:59 +01:00
gMoveSelectionCursor [ gActiveBattler ] = 0 ;
2017-10-22 18:43:15 +02:00
break ;
}
PlayerBufferExecCompleted ( ) ;
}
static void PlayerHandleCmd55 ( void )
{
2018-02-06 02:46:59 +01:00
sub_81851A8 ( & gBattleBufferA [ gActiveBattler ] [ 4 ] ) ;
gBattleOutcome = gBattleBufferA [ gActiveBattler ] [ 1 ] ;
gSaveBlock2Ptr - > field_CA9_b = gBattleBufferA [ gActiveBattler ] [ 2 ] ;
2017-10-22 18:43:15 +02:00
FadeOutMapMusic ( 5 ) ;
BeginFastPaletteFade ( 3 ) ;
PlayerBufferExecCompleted ( ) ;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs [ gActiveBattler ] = sub_80587B0 ;
2017-10-22 18:43:15 +02:00
}
static void nullsub_22 ( void )
{
2017-10-21 17:32:35 +02:00
}