pokeemerald/src/battle_controllers.c

1539 lines
56 KiB
C
Raw Normal View History

2017-10-13 17:22:50 +02:00
#include "global.h"
#include "battle.h"
2018-11-14 01:01:50 +01:00
#include "battle_ai_script_commands.h"
#include "battle_anim.h"
2017-10-13 17:22:50 +02:00
#include "battle_controllers.h"
2018-11-14 01:01:50 +01:00
#include "battle_message.h"
2019-01-27 20:54:34 +01:00
#include "battle_setup.h"
2018-10-13 19:41:10 +02:00
#include "cable_club.h"
2017-10-13 17:22:50 +02:00
#include "link.h"
2018-12-24 00:02:29 +01:00
#include "party_menu.h"
2017-10-13 17:22:50 +02:00
#include "pokemon.h"
#include "recorded_battle.h"
2018-11-14 01:01:50 +01:00
#include "task.h"
2017-10-13 17:22:50 +02:00
#include "util.h"
2017-12-05 18:55:48 +01:00
#include "constants/abilities.h"
2018-11-14 01:01:50 +01:00
#include "constants/species.h"
2017-10-13 17:22:50 +02:00
static EWRAM_DATA u8 sLinkSendTaskId = 0;
static EWRAM_DATA u8 sLinkReceiveTaskId = 0;
static EWRAM_DATA u8 sUnknown_02022D0A = 0;
EWRAM_DATA struct UnusedControllerStruct gUnknown_02022D0C = {};
2017-11-11 02:27:02 +01:00
static EWRAM_DATA u8 sBattleBuffersTransferData[0x100] = {};
2017-10-13 17:22:50 +02:00
// this file's funcionts
2017-10-14 11:34:26 +02:00
static void CreateTasksForSendRecvLinkBuffers(void);
2018-02-06 20:48:02 +01:00
static void InitLinkBtlControllers(void);
static void InitSinglePlayerBtlControllers(void);
2017-10-14 11:34:26 +02:00
static void SetBattlePartyIds(void);
2017-10-13 17:22:50 +02:00
static void Task_HandleSendLinkBuffersData(u8 taskId);
static void Task_HandleCopyReceivedLinkBuffersData(u8 taskId);
void HandleLinkBattleSetup(void)
{
if (gBattleTypeFlags & BATTLE_TYPE_LINK)
{
2017-11-13 05:58:05 +01:00
if (gWirelessCommType)
2017-10-13 17:22:50 +02:00
sub_800B488();
if (!gReceivedRemoteLinkPlayers)
2017-11-11 06:05:44 +01:00
OpenLink();
2017-10-13 17:22:50 +02:00
CreateTask(task00_08081A90, 0);
2017-10-14 11:34:26 +02:00
CreateTasksForSendRecvLinkBuffers();
2017-10-13 17:22:50 +02:00
}
}
void SetUpBattleVarsAndBirchZigzagoon(void)
{
s32 i;
gBattleMainFunc = nullsub_20;
2018-02-06 02:46:59 +01:00
for (i = 0; i < MAX_BATTLERS_COUNT; i++)
2017-10-13 17:22:50 +02:00
{
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[i] = nullsub_21;
2018-02-06 02:46:59 +01:00
gBattlerPositions[i] = 0xFF;
2017-10-13 17:22:50 +02:00
gActionSelectionCursor[i] = 0;
gMoveSelectionCursor[i] = 0;
}
HandleLinkBattleSetup();
2018-02-06 20:48:02 +01:00
gBattleControllerExecFlags = 0;
2017-10-13 17:22:50 +02:00
ClearBattleAnimationVars();
ClearBattleMonForms();
BattleAI_SetupItems();
BattleAI_SetupFlags();
BattleAI_SetupAIData(0xF);
2017-10-13 17:22:50 +02:00
if (gBattleTypeFlags & BATTLE_TYPE_FIRST_BATTLE)
{
ZeroEnemyPartyMons();
CreateMon(&gEnemyParty[0], SPECIES_ZIGZAGOON, 2, 32, 0, 0, 0, 0);
i = 0;
SetMonData(&gEnemyParty[0], MON_DATA_HELD_ITEM, &i);
}
gUnknown_02022FF4 = 0;
gUnknown_0202428C = 0;
}
void sub_8032768(void)
{
s32 i;
if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED))
sub_8184DA4(1);
else
sub_8184DA4(2);
if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED))
2017-11-13 18:07:23 +01:00
RecordedBattle_SaveParties();
2017-10-13 17:22:50 +02:00
if (gBattleTypeFlags & BATTLE_TYPE_LINK)
2018-02-06 20:48:02 +01:00
InitLinkBtlControllers();
2017-10-13 17:22:50 +02:00
else
2018-02-06 20:48:02 +01:00
InitSinglePlayerBtlControllers();
2017-10-13 17:22:50 +02:00
2017-10-14 11:34:26 +02:00
SetBattlePartyIds();
2017-10-13 17:22:50 +02:00
if (!(gBattleTypeFlags & BATTLE_TYPE_MULTI))
{
2018-02-06 02:46:59 +01:00
for (i = 0; i < gBattlersCount; i++)
2017-10-13 17:22:50 +02:00
sub_81B8D64(i, 0);
}
2018-02-28 00:18:59 +01:00
for (i = 0; i < sizeof(gBattleStruct->tvMovePoints); i++)
*((u8*)(&gBattleStruct->tvMovePoints) + i) = 0;
2017-10-13 17:22:50 +02:00
2018-02-28 00:18:59 +01:00
for (i = 0; i < sizeof(gBattleStruct->tv); i++)
*((u8*)(&gBattleStruct->tv) + i) = 0;
2017-10-13 17:22:50 +02:00
}
2018-02-06 20:48:02 +01:00
static void InitSinglePlayerBtlControllers(void)
2017-10-13 17:22:50 +02:00
{
s32 i;
if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER)
{
gBattleMainFunc = BeginBattleIntro;
if (gBattleTypeFlags & BATTLE_TYPE_RECORDED)
{
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[0] = SetControllerToRecordedPlayer;
2018-02-06 02:46:59 +01:00
gBattlerPositions[0] = B_POSITION_PLAYER_LEFT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[1] = SetControllerToOpponent;
2018-02-06 02:46:59 +01:00
gBattlerPositions[1] = B_POSITION_OPPONENT_LEFT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[2] = SetControllerToPlayerPartner;
2018-02-06 02:46:59 +01:00
gBattlerPositions[2] = B_POSITION_PLAYER_RIGHT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[3] = SetControllerToOpponent;
2018-02-06 02:46:59 +01:00
gBattlerPositions[3] = B_POSITION_OPPONENT_RIGHT;
2017-10-13 17:22:50 +02:00
}
else
{
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[0] = SetControllerToPlayer;
2018-02-06 02:46:59 +01:00
gBattlerPositions[0] = B_POSITION_PLAYER_LEFT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[1] = SetControllerToOpponent;
2018-02-06 02:46:59 +01:00
gBattlerPositions[1] = B_POSITION_OPPONENT_LEFT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[2] = SetControllerToPlayerPartner;
2018-02-06 02:46:59 +01:00
gBattlerPositions[2] = B_POSITION_PLAYER_RIGHT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[3] = SetControllerToOpponent;
2018-02-06 02:46:59 +01:00
gBattlerPositions[3] = B_POSITION_OPPONENT_RIGHT;
2017-10-13 17:22:50 +02:00
}
gBattlersCount = MAX_BATTLERS_COUNT;
2017-10-13 17:22:50 +02:00
sub_81B8D64(0, 0);
sub_81B8D64(1, 0);
sub_81B8D64(2, 1);
sub_81B8D64(3, 1);
2018-02-06 20:48:02 +01:00
gBattlerPartyIndexes[0] = 0;
gBattlerPartyIndexes[1] = 0;
2019-01-27 20:54:34 +01:00
if (BATTLE_TWO_VS_ONE_OPPONENT)
{
gBattlerPartyIndexes[2] = 3;
gBattlerPartyIndexes[3] = 1;
}
else
{
gBattlerPartyIndexes[2] = 3;
gBattlerPartyIndexes[3] = 3;
}
2017-10-13 17:22:50 +02:00
}
else if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE))
{
gBattleMainFunc = BeginBattleIntro;
if (gBattleTypeFlags & BATTLE_TYPE_SAFARI)
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[0] = SetControllerToSafari;
2017-10-13 17:22:50 +02:00
else if (gBattleTypeFlags & BATTLE_TYPE_WALLY_TUTORIAL)
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[0] = SetControllerToWally;
2017-10-13 17:22:50 +02:00
else
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[0] = SetControllerToPlayer;
2017-10-13 17:22:50 +02:00
2018-02-06 02:46:59 +01:00
gBattlerPositions[0] = B_POSITION_PLAYER_LEFT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[1] = SetControllerToOpponent;
2018-02-06 02:46:59 +01:00
gBattlerPositions[1] = B_POSITION_OPPONENT_LEFT;
2017-10-13 17:22:50 +02:00
2018-02-06 02:46:59 +01:00
gBattlersCount = 2;
2017-10-13 17:22:50 +02:00
if (gBattleTypeFlags & BATTLE_TYPE_RECORDED)
{
if (gBattleTypeFlags & BATTLE_TYPE_x2000000)
{
if (gBattleTypeFlags & BATTLE_TYPE_x80000000)
{
gBattleMainFunc = BeginBattleIntro;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[0] = SetControllerToRecordedPlayer;
2018-02-06 02:46:59 +01:00
gBattlerPositions[0] = B_POSITION_PLAYER_LEFT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[1] = SetControllerToRecordedOpponent;
2018-02-06 02:46:59 +01:00
gBattlerPositions[1] = B_POSITION_OPPONENT_LEFT;
2017-10-13 17:22:50 +02:00
2018-02-06 02:46:59 +01:00
gBattlersCount = 2;
2017-10-13 17:22:50 +02:00
}
else // see how the banks are switched
{
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[1] = SetControllerToRecordedPlayer;
2018-02-06 02:46:59 +01:00
gBattlerPositions[1] = B_POSITION_PLAYER_LEFT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[0] = SetControllerToRecordedOpponent;
2018-02-06 02:46:59 +01:00
gBattlerPositions[0] = B_POSITION_OPPONENT_LEFT;
2017-10-13 17:22:50 +02:00
2018-02-06 02:46:59 +01:00
gBattlersCount = 2;
2017-10-13 17:22:50 +02:00
}
}
else
{
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[0] = SetControllerToRecordedPlayer;
2018-02-06 02:46:59 +01:00
gBattlerPositions[0] = B_POSITION_PLAYER_LEFT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[1] = SetControllerToOpponent;
2018-02-06 02:46:59 +01:00
gBattlerPositions[1] = B_POSITION_OPPONENT_LEFT;
2017-10-13 17:22:50 +02:00
}
}
}
else
{
gBattleMainFunc = BeginBattleIntro;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[0] = SetControllerToPlayer;
2018-02-06 02:46:59 +01:00
gBattlerPositions[0] = B_POSITION_PLAYER_LEFT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[1] = SetControllerToOpponent;
2018-02-06 02:46:59 +01:00
gBattlerPositions[1] = B_POSITION_OPPONENT_LEFT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[2] = SetControllerToPlayer;
2018-02-06 02:46:59 +01:00
gBattlerPositions[2] = B_POSITION_PLAYER_RIGHT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[3] = SetControllerToOpponent;
2018-02-06 02:46:59 +01:00
gBattlerPositions[3] = B_POSITION_OPPONENT_RIGHT;
2017-10-13 17:22:50 +02:00
gBattlersCount = MAX_BATTLERS_COUNT;
2017-10-13 17:22:50 +02:00
if (gBattleTypeFlags & BATTLE_TYPE_RECORDED)
{
if (gBattleTypeFlags & BATTLE_TYPE_MULTI && gBattleTypeFlags & BATTLE_TYPE_BATTLE_TOWER)
{
gBattleMainFunc = BeginBattleIntro;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[0] = SetControllerToRecordedPlayer;
2018-02-06 02:46:59 +01:00
gBattlerPositions[0] = 0;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[1] = SetControllerToOpponent;
2018-02-06 02:46:59 +01:00
gBattlerPositions[1] = 1;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[2] = SetControllerToRecordedPlayer;
2018-02-06 02:46:59 +01:00
gBattlerPositions[2] = 2;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[3] = SetControllerToOpponent;
2018-02-06 02:46:59 +01:00
gBattlerPositions[3] = 3;
2017-10-13 17:22:50 +02:00
gBattlersCount = MAX_BATTLERS_COUNT;
2017-10-13 17:22:50 +02:00
sub_81B8D64(0, 0);
sub_81B8D64(1, 0);
sub_81B8D64(2, 1);
sub_81B8D64(3, 1);
2018-02-06 20:48:02 +01:00
gBattlerPartyIndexes[0] = 0;
gBattlerPartyIndexes[1] = 0;
gBattlerPartyIndexes[2] = 3;
gBattlerPartyIndexes[3] = 3;
2017-10-13 17:22:50 +02:00
}
else if (gBattleTypeFlags & BATTLE_TYPE_MULTI)
{
u8 var; // multiplayer Id in a recorded battle?
2018-02-06 02:46:59 +01:00
for (var = gUnknown_0203C7B4, i = 0; i < MAX_BATTLERS_COUNT; i++)
2017-10-13 17:22:50 +02:00
{
2018-07-22 12:49:49 +02:00
switch (gLinkPlayers[i].id)
2017-10-13 17:22:50 +02:00
{
case 0:
case 3:
2018-07-22 12:49:49 +02:00
sub_81B8D64(gLinkPlayers[i].id, 0);
2017-10-13 17:22:50 +02:00
break;
case 1:
case 2:
2018-07-22 12:49:49 +02:00
sub_81B8D64(gLinkPlayers[i].id, 1);
2017-10-13 17:22:50 +02:00
break;
}
if (i == var)
{
2018-07-22 12:49:49 +02:00
gBattlerControllerFuncs[gLinkPlayers[i].id] = SetControllerToRecordedPlayer;
switch (gLinkPlayers[i].id)
2017-10-13 17:22:50 +02:00
{
case 0:
case 3:
2018-07-22 12:49:49 +02:00
gBattlerPositions[gLinkPlayers[i].id] = B_POSITION_PLAYER_LEFT;
gBattlerPartyIndexes[gLinkPlayers[i].id] = 0;
2017-10-13 17:22:50 +02:00
break;
case 1:
case 2:
2018-07-22 12:49:49 +02:00
gBattlerPositions[gLinkPlayers[i].id] = B_POSITION_PLAYER_RIGHT;
gBattlerPartyIndexes[gLinkPlayers[i].id] = 3;
2017-10-13 17:22:50 +02:00
break;
}
}
2018-07-22 12:49:49 +02:00
else if ((!(gLinkPlayers[i].id & 1) && !(gLinkPlayers[var].id & 1))
|| ((gLinkPlayers[i].id & 1) && (gLinkPlayers[var].id & 1)))
2017-10-13 17:22:50 +02:00
{
2018-07-22 12:49:49 +02:00
gBattlerControllerFuncs[gLinkPlayers[i].id] = SetControllerToRecordedPlayer;
switch (gLinkPlayers[i].id)
2017-10-13 17:22:50 +02:00
{
case 0:
case 3:
2018-07-22 12:49:49 +02:00
gBattlerPositions[gLinkPlayers[i].id] = B_POSITION_PLAYER_LEFT;
gBattlerPartyIndexes[gLinkPlayers[i].id] = 0;
2017-10-13 17:22:50 +02:00
break;
case 1:
case 2:
2018-07-22 12:49:49 +02:00
gBattlerPositions[gLinkPlayers[i].id] = B_POSITION_PLAYER_RIGHT;
gBattlerPartyIndexes[gLinkPlayers[i].id] = 3;
2017-10-13 17:22:50 +02:00
break;
}
}
else
{
2018-07-22 12:49:49 +02:00
gBattlerControllerFuncs[gLinkPlayers[i].id] = SetControllerToRecordedOpponent;
switch (gLinkPlayers[i].id)
2017-10-13 17:22:50 +02:00
{
case 0:
case 3:
2018-07-22 12:49:49 +02:00
gBattlerPositions[gLinkPlayers[i].id] = B_POSITION_OPPONENT_LEFT;
gBattlerPartyIndexes[gLinkPlayers[i].id] = 0;
2017-10-13 17:22:50 +02:00
break;
case 1:
case 2:
2018-07-22 12:49:49 +02:00
gBattlerPositions[gLinkPlayers[i].id] = B_POSITION_OPPONENT_RIGHT;
gBattlerPartyIndexes[gLinkPlayers[i].id] = 3;
2017-10-13 17:22:50 +02:00
break;
}
}
}
}
else if (gBattleTypeFlags & BATTLE_TYPE_IS_MASTER)
2017-10-13 17:22:50 +02:00
{
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[0] = SetControllerToRecordedPlayer;
2018-02-06 02:46:59 +01:00
gBattlerPositions[0] = B_POSITION_PLAYER_LEFT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[2] = SetControllerToRecordedPlayer;
2018-02-06 02:46:59 +01:00
gBattlerPositions[2] = B_POSITION_PLAYER_RIGHT;
2017-10-13 17:22:50 +02:00
if (gBattleTypeFlags & BATTLE_TYPE_x2000000)
{
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[1] = SetControllerToRecordedOpponent;
2018-02-06 02:46:59 +01:00
gBattlerPositions[1] = B_POSITION_OPPONENT_LEFT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[3] = SetControllerToRecordedOpponent;
2018-02-06 02:46:59 +01:00
gBattlerPositions[3] = B_POSITION_OPPONENT_RIGHT;
2017-10-13 17:22:50 +02:00
}
else
{
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[1] = SetControllerToOpponent;
2018-02-06 02:46:59 +01:00
gBattlerPositions[1] = B_POSITION_OPPONENT_LEFT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[3] = SetControllerToOpponent;
2018-02-06 02:46:59 +01:00
gBattlerPositions[3] = B_POSITION_OPPONENT_RIGHT;
2017-10-13 17:22:50 +02:00
}
}
else
{
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[1] = SetControllerToRecordedPlayer;
2018-02-06 02:46:59 +01:00
gBattlerPositions[1] = B_POSITION_PLAYER_LEFT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[3] = SetControllerToRecordedPlayer;
2018-02-06 02:46:59 +01:00
gBattlerPositions[3] = B_POSITION_PLAYER_RIGHT;
2017-10-13 17:22:50 +02:00
if (gBattleTypeFlags & BATTLE_TYPE_x2000000)
{
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[0] = SetControllerToRecordedOpponent;
2018-02-06 02:46:59 +01:00
gBattlerPositions[0] = B_POSITION_OPPONENT_LEFT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[2] = SetControllerToRecordedOpponent;
2018-02-06 02:46:59 +01:00
gBattlerPositions[2] = B_POSITION_OPPONENT_RIGHT;
2017-10-13 17:22:50 +02:00
}
else
{
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[0] = SetControllerToOpponent;
2018-02-06 02:46:59 +01:00
gBattlerPositions[0] = B_POSITION_OPPONENT_LEFT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[2] = SetControllerToOpponent;
2018-02-06 02:46:59 +01:00
gBattlerPositions[2] = B_POSITION_OPPONENT_RIGHT;
2017-10-13 17:22:50 +02:00
}
}
}
}
}
2018-02-06 20:48:02 +01:00
static void InitLinkBtlControllers(void)
2017-10-13 17:22:50 +02:00
{
s32 i;
u8 multiplayerId;
if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE))
{
if (gBattleTypeFlags & BATTLE_TYPE_IS_MASTER)
2017-10-13 17:22:50 +02:00
{
gBattleMainFunc = BeginBattleIntro;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[0] = SetControllerToPlayer;
2018-02-06 02:46:59 +01:00
gBattlerPositions[0] = B_POSITION_PLAYER_LEFT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[1] = SetControllerToLinkOpponent;
2018-02-06 02:46:59 +01:00
gBattlerPositions[1] = B_POSITION_OPPONENT_LEFT;
2017-10-13 17:22:50 +02:00
2018-02-06 02:46:59 +01:00
gBattlersCount = 2;
2017-10-13 17:22:50 +02:00
}
else
{
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[1] = SetControllerToPlayer;
2018-02-06 02:46:59 +01:00
gBattlerPositions[1] = B_POSITION_PLAYER_LEFT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[0] = SetControllerToLinkOpponent;
2018-02-06 02:46:59 +01:00
gBattlerPositions[0] = B_POSITION_OPPONENT_LEFT;
2017-10-13 17:22:50 +02:00
2018-02-06 02:46:59 +01:00
gBattlersCount = 2;
2017-10-13 17:22:50 +02:00
}
}
else if (!(gBattleTypeFlags & BATTLE_TYPE_MULTI) && gBattleTypeFlags & BATTLE_TYPE_DOUBLE)
{
if (gBattleTypeFlags & BATTLE_TYPE_IS_MASTER)
2017-10-13 17:22:50 +02:00
{
gBattleMainFunc = BeginBattleIntro;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[0] = SetControllerToPlayer;
2018-02-06 02:46:59 +01:00
gBattlerPositions[0] = B_POSITION_PLAYER_LEFT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[1] = SetControllerToLinkOpponent;
2018-02-06 02:46:59 +01:00
gBattlerPositions[1] = B_POSITION_OPPONENT_LEFT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[2] = SetControllerToPlayer;
2018-02-06 02:46:59 +01:00
gBattlerPositions[2] = B_POSITION_PLAYER_RIGHT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[3] = SetControllerToLinkOpponent;
2018-02-06 02:46:59 +01:00
gBattlerPositions[3] = B_POSITION_OPPONENT_RIGHT;
2017-10-13 17:22:50 +02:00
gBattlersCount = MAX_BATTLERS_COUNT;
2017-10-13 17:22:50 +02:00
}
else
{
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[1] = SetControllerToPlayer;
2018-02-06 02:46:59 +01:00
gBattlerPositions[1] = B_POSITION_PLAYER_LEFT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[0] = SetControllerToLinkOpponent;
2018-02-06 02:46:59 +01:00
gBattlerPositions[0] = B_POSITION_OPPONENT_LEFT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[3] = SetControllerToPlayer;
2018-02-06 02:46:59 +01:00
gBattlerPositions[3] = B_POSITION_PLAYER_RIGHT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[2] = SetControllerToLinkOpponent;
2018-02-06 02:46:59 +01:00
gBattlerPositions[2] = B_POSITION_OPPONENT_RIGHT;
2017-10-13 17:22:50 +02:00
gBattlersCount = MAX_BATTLERS_COUNT;
2017-10-13 17:22:50 +02:00
}
}
else if (gBattleTypeFlags & BATTLE_TYPE_BATTLE_TOWER)
{
if (gBattleTypeFlags & BATTLE_TYPE_IS_MASTER)
2017-10-13 17:22:50 +02:00
{
gBattleMainFunc = BeginBattleIntro;
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[0] = SetControllerToPlayer;
2018-02-06 02:46:59 +01:00
gBattlerPositions[0] = B_POSITION_PLAYER_LEFT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[1] = SetControllerToOpponent;
2018-02-06 02:46:59 +01:00
gBattlerPositions[1] = B_POSITION_OPPONENT_LEFT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[2] = SetControllerToLinkPartner;
2018-02-06 02:46:59 +01:00
gBattlerPositions[2] = B_POSITION_PLAYER_RIGHT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[3] = SetControllerToOpponent;
2018-02-06 02:46:59 +01:00
gBattlerPositions[3] = B_POSITION_OPPONENT_RIGHT;
2017-10-13 17:22:50 +02:00
gBattlersCount = MAX_BATTLERS_COUNT;
2017-10-13 17:22:50 +02:00
}
else
{
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[0] = SetControllerToLinkPartner;
2018-02-06 02:46:59 +01:00
gBattlerPositions[0] = B_POSITION_PLAYER_LEFT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[1] = SetControllerToLinkOpponent;
2018-02-06 02:46:59 +01:00
gBattlerPositions[1] = B_POSITION_OPPONENT_LEFT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[2] = SetControllerToPlayer;
2018-02-06 02:46:59 +01:00
gBattlerPositions[2] = B_POSITION_PLAYER_RIGHT;
2017-10-13 17:22:50 +02:00
2018-02-06 20:48:02 +01:00
gBattlerControllerFuncs[3] = SetControllerToLinkOpponent;
2018-02-06 02:46:59 +01:00
gBattlerPositions[3] = B_POSITION_OPPONENT_RIGHT;
2017-10-13 17:22:50 +02:00
gBattlersCount = MAX_BATTLERS_COUNT;
2017-10-13 17:22:50 +02:00
}
sub_81B8D64(0, 0);
sub_81B8D64(1, 0);
sub_81B8D64(2, 1);
sub_81B8D64(3, 1);
2018-02-06 20:48:02 +01:00
gBattlerPartyIndexes[0] = 0;
gBattlerPartyIndexes[1] = 0;
gBattlerPartyIndexes[2] = 3;
gBattlerPartyIndexes[3] = 3;
2017-10-13 17:22:50 +02:00
}
else
{
multiplayerId = GetMultiplayerId();
if (gBattleTypeFlags & BATTLE_TYPE_IS_MASTER)
2017-10-13 17:22:50 +02:00
gBattleMainFunc = BeginBattleIntro;
2018-02-06 02:46:59 +01:00
for (i = 0; i < MAX_BATTLERS_COUNT; i++)
2017-10-13 17:22:50 +02:00
{
2018-07-22 12:49:49 +02:00
switch (gLinkPlayers[i].id)
2017-10-13 17:22:50 +02:00
{
case 0:
case 3:
2018-07-22 12:49:49 +02:00
sub_81B8D64(gLinkPlayers[i].id, 0);
2017-10-13 17:22:50 +02:00
break;
case 1:
case 2:
2018-07-22 12:49:49 +02:00
sub_81B8D64(gLinkPlayers[i].id, 1);
2017-10-13 17:22:50 +02:00
break;
}
if (i == multiplayerId)
{
2018-07-22 12:49:49 +02:00
gBattlerControllerFuncs[gLinkPlayers[i].id] = SetControllerToPlayer;
switch (gLinkPlayers[i].id)
2017-10-13 17:22:50 +02:00
{
case 0:
case 3:
2018-07-22 12:49:49 +02:00
gBattlerPositions[gLinkPlayers[i].id] = 0;
gBattlerPartyIndexes[gLinkPlayers[i].id] = 0;
2017-10-13 17:22:50 +02:00
break;
case 1:
case 2:
2018-07-22 12:49:49 +02:00
gBattlerPositions[gLinkPlayers[i].id] = 2;
gBattlerPartyIndexes[gLinkPlayers[i].id] = 3;
2017-10-13 17:22:50 +02:00
break;
}
}
else
{
2018-07-22 12:49:49 +02:00
if ((!(gLinkPlayers[i].id & 1) && !(gLinkPlayers[multiplayerId].id & 1))
|| ((gLinkPlayers[i].id & 1) && (gLinkPlayers[multiplayerId].id & 1)))
2017-10-13 17:22:50 +02:00
{
2018-07-22 12:49:49 +02:00
gBattlerControllerFuncs[gLinkPlayers[i].id] = SetControllerToLinkPartner;
switch (gLinkPlayers[i].id)
2017-10-13 17:22:50 +02:00
{
case 0:
case 3:
2018-07-22 12:49:49 +02:00
gBattlerPositions[gLinkPlayers[i].id] = 0;
gBattlerPartyIndexes[gLinkPlayers[i].id] = 0;
2017-10-13 17:22:50 +02:00
break;
case 1:
case 2:
2018-07-22 12:49:49 +02:00
gBattlerPositions[gLinkPlayers[i].id] = 2;
gBattlerPartyIndexes[gLinkPlayers[i].id] = 3;
2017-10-13 17:22:50 +02:00
break;
}
}
else
{
2018-07-22 12:49:49 +02:00
gBattlerControllerFuncs[gLinkPlayers[i].id] = SetControllerToLinkOpponent;
switch (gLinkPlayers[i].id)
2017-10-13 17:22:50 +02:00
{
case 0:
case 3:
2018-07-22 12:49:49 +02:00
gBattlerPositions[gLinkPlayers[i].id] = 1;
gBattlerPartyIndexes[gLinkPlayers[i].id] = 0;
2017-10-13 17:22:50 +02:00
break;
case 1:
case 2:
2018-07-22 12:49:49 +02:00
gBattlerPositions[gLinkPlayers[i].id] = 3;
gBattlerPartyIndexes[gLinkPlayers[i].id] = 3;
2017-10-13 17:22:50 +02:00
break;
}
}
}
}
gBattlersCount = MAX_BATTLERS_COUNT;
2017-10-13 17:22:50 +02:00
}
}
2017-10-14 11:34:26 +02:00
static void SetBattlePartyIds(void)
2017-10-13 17:22:50 +02:00
{
s32 i, j;
if (!(gBattleTypeFlags & BATTLE_TYPE_MULTI))
{
2018-02-06 02:46:59 +01:00
for (i = 0; i < gBattlersCount; i++)
2017-10-13 17:22:50 +02:00
{
2018-06-19 00:43:15 +02:00
for (j = 0; j < PARTY_SIZE; j++)
2017-10-13 17:22:50 +02:00
{
if (i < 2)
{
2018-02-06 02:46:59 +01:00
if (GET_BATTLER_SIDE2(i) == B_SIDE_PLAYER)
2017-10-13 17:22:50 +02:00
{
if (GetMonData(&gPlayerParty[j], MON_DATA_HP) != 0
&& GetMonData(&gPlayerParty[j], MON_DATA_SPECIES2) != SPECIES_NONE
&& GetMonData(&gPlayerParty[j], MON_DATA_SPECIES2) != SPECIES_EGG
&& GetMonData(&gPlayerParty[j], MON_DATA_IS_EGG) == 0)
{
2018-02-06 20:48:02 +01:00
gBattlerPartyIndexes[i] = j;
2017-10-13 17:22:50 +02:00
break;
}
}
else
{
if (GetMonData(&gEnemyParty[j], MON_DATA_HP) != 0
&& GetMonData(&gEnemyParty[j], MON_DATA_SPECIES2) != SPECIES_NONE
&& GetMonData(&gEnemyParty[j], MON_DATA_SPECIES2) != SPECIES_EGG
&& GetMonData(&gEnemyParty[j], MON_DATA_IS_EGG) == 0)
{
2018-02-06 20:48:02 +01:00
gBattlerPartyIndexes[i] = j;
2017-10-13 17:22:50 +02:00
break;
}
}
}
else
{
2018-02-06 02:46:59 +01:00
if (GET_BATTLER_SIDE2(i) == B_SIDE_PLAYER)
2017-10-13 17:22:50 +02:00
{
if (GetMonData(&gPlayerParty[j], MON_DATA_HP) != 0
&& GetMonData(&gPlayerParty[j], MON_DATA_SPECIES) != SPECIES_NONE // Probably a typo by Game Freak. The rest use SPECIES2.
&& GetMonData(&gPlayerParty[j], MON_DATA_SPECIES2) != SPECIES_EGG
&& GetMonData(&gPlayerParty[j], MON_DATA_IS_EGG) == 0
2018-02-06 20:48:02 +01:00
&& gBattlerPartyIndexes[i - 2] != j)
2017-10-13 17:22:50 +02:00
{
2018-02-06 20:48:02 +01:00
gBattlerPartyIndexes[i] = j;
2017-10-13 17:22:50 +02:00
break;
}
}
else
{
if (GetMonData(&gEnemyParty[j], MON_DATA_HP) != 0
&& GetMonData(&gEnemyParty[j], MON_DATA_SPECIES2) != SPECIES_NONE
&& GetMonData(&gEnemyParty[j], MON_DATA_SPECIES2) != SPECIES_EGG
&& GetMonData(&gEnemyParty[j], MON_DATA_IS_EGG) == 0
2018-02-06 20:48:02 +01:00
&& gBattlerPartyIndexes[i - 2] != j)
2017-10-13 17:22:50 +02:00
{
2018-02-06 20:48:02 +01:00
gBattlerPartyIndexes[i] = j;
2017-10-13 17:22:50 +02:00
break;
}
}
}
}
}
if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS)
2018-02-06 20:48:02 +01:00
gBattlerPartyIndexes[1] = 0, gBattlerPartyIndexes[3] = 3;
2017-10-13 17:22:50 +02:00
}
}
2017-10-14 11:34:26 +02:00
static void PrepareBufferDataTransfer(u8 bufferId, u8 *data, u16 size)
2017-10-13 17:22:50 +02:00
{
s32 i;
if (gBattleTypeFlags & BATTLE_TYPE_LINK)
{
PrepareBufferDataTransferLink(bufferId, size, data);
}
else
{
switch (bufferId)
{
case 0:
for (i = 0; i < size; i++)
{
gBattleResources->bufferA[gActiveBattler][i] = *data;
2017-10-13 17:22:50 +02:00
data++;
}
break;
case 1:
for (i = 0; i < size; i++)
{
gBattleResources->bufferB[gActiveBattler][i] = *data;
2017-10-13 17:22:50 +02:00
data++;
}
break;
}
}
}
2017-10-14 11:34:26 +02:00
static void CreateTasksForSendRecvLinkBuffers(void)
2017-10-13 17:22:50 +02:00
{
sLinkSendTaskId = CreateTask(Task_HandleSendLinkBuffersData, 0);
gTasks[sLinkSendTaskId].data[11] = 0;
gTasks[sLinkSendTaskId].data[12] = 0;
gTasks[sLinkSendTaskId].data[13] = 0;
gTasks[sLinkSendTaskId].data[14] = 0;
gTasks[sLinkSendTaskId].data[15] = 0;
sLinkReceiveTaskId = CreateTask(Task_HandleCopyReceivedLinkBuffersData, 0);
gTasks[sLinkReceiveTaskId].data[12] = 0;
gTasks[sLinkReceiveTaskId].data[13] = 0;
gTasks[sLinkReceiveTaskId].data[14] = 0;
gTasks[sLinkReceiveTaskId].data[15] = 0;
sUnknown_02022D0A = 0;
2017-10-13 17:22:50 +02:00
}
enum
{
LINK_BUFF_BUFFER_ID,
LINK_BUFF_ACTIVE_BATTLER,
2017-10-13 17:22:50 +02:00
LINK_BUFF_ATTACKER,
LINK_BUFF_TARGET,
LINK_BUFF_SIZE_LO,
LINK_BUFF_SIZE_HI,
LINK_BUFF_ABSENT_BATTLER_FLAGS,
LINK_BUFF_EFFECT_BATTLER,
LINK_BUFF_DATA,
2017-10-13 17:22:50 +02:00
};
void PrepareBufferDataTransferLink(u8 bufferId, u16 size, u8 *data)
{
s32 alignedSize;
s32 i;
alignedSize = size - size % 4 + 4;
if (gTasks[sLinkSendTaskId].data[14] + alignedSize + LINK_BUFF_DATA + 1 > BATTLE_BUFFER_LINK_SIZE)
2017-10-13 17:22:50 +02:00
{
gTasks[sLinkSendTaskId].data[12] = gTasks[sLinkSendTaskId].data[14];
gTasks[sLinkSendTaskId].data[14] = 0;
2017-10-13 17:22:50 +02:00
}
gLinkBattleSendBuffer[gTasks[sLinkSendTaskId].data[14] + LINK_BUFF_BUFFER_ID] = bufferId;
gLinkBattleSendBuffer[gTasks[sLinkSendTaskId].data[14] + LINK_BUFF_ACTIVE_BATTLER] = gActiveBattler;
gLinkBattleSendBuffer[gTasks[sLinkSendTaskId].data[14] + LINK_BUFF_ATTACKER] = gBattlerAttacker;
gLinkBattleSendBuffer[gTasks[sLinkSendTaskId].data[14] + LINK_BUFF_TARGET] = gBattlerTarget;
gLinkBattleSendBuffer[gTasks[sLinkSendTaskId].data[14] + LINK_BUFF_SIZE_LO] = alignedSize;
gLinkBattleSendBuffer[gTasks[sLinkSendTaskId].data[14] + LINK_BUFF_SIZE_HI] = (alignedSize & 0x0000FF00) >> 8;
gLinkBattleSendBuffer[gTasks[sLinkSendTaskId].data[14] + LINK_BUFF_ABSENT_BATTLER_FLAGS] = gAbsentBattlerFlags;
gLinkBattleSendBuffer[gTasks[sLinkSendTaskId].data[14] + LINK_BUFF_EFFECT_BATTLER] = gEffectBattler;
2017-10-13 17:22:50 +02:00
for (i = 0; i < size; i++)
gLinkBattleSendBuffer[gTasks[sLinkSendTaskId].data[14] + LINK_BUFF_DATA + i] = data[i];
2017-10-13 17:22:50 +02:00
gTasks[sLinkSendTaskId].data[14] = gTasks[sLinkSendTaskId].data[14] + alignedSize + LINK_BUFF_DATA;
2017-10-13 17:22:50 +02:00
}
static void Task_HandleSendLinkBuffersData(u8 taskId)
{
u16 var;
u16 blockSize;
switch (gTasks[taskId].data[11])
{
case 0:
gTasks[taskId].data[10] = 100;
gTasks[taskId].data[11]++;
break;
case 1:
gTasks[taskId].data[10]--;
if (gTasks[taskId].data[10] == 0)
gTasks[taskId].data[11]++;
break;
case 2:
2017-11-13 05:58:05 +01:00
if (gWirelessCommType)
2017-10-13 17:22:50 +02:00
{
gTasks[taskId].data[11]++;
}
else
{
if (gBattleTypeFlags & BATTLE_TYPE_BATTLE_TOWER)
var = 2;
else
var = (gBattleTypeFlags & BATTLE_TYPE_MULTI) ? 4 : 2;
2017-11-13 03:31:08 +01:00
if (GetLinkPlayerCount_2() >= var)
2017-10-13 17:22:50 +02:00
{
2017-11-13 04:09:11 +01:00
if (IsLinkMaster())
2017-10-13 17:22:50 +02:00
{
CheckShouldAdvanceLinkState();
2017-10-13 17:22:50 +02:00
gTasks[taskId].data[11]++;
}
else
{
gTasks[taskId].data[11]++;
}
}
}
break;
case 3:
if (gTasks[taskId].data[15] != gTasks[taskId].data[14])
{
if (gTasks[taskId].data[13] == 0)
{
if (gTasks[taskId].data[15] > gTasks[taskId].data[14]
&& gTasks[taskId].data[15] == gTasks[taskId].data[12])
{
gTasks[taskId].data[12] = 0;
gTasks[taskId].data[15] = 0;
}
blockSize = (gLinkBattleSendBuffer[gTasks[taskId].data[15] + LINK_BUFF_SIZE_LO] | (gLinkBattleSendBuffer[gTasks[taskId].data[15] + LINK_BUFF_SIZE_HI] << 8)) + LINK_BUFF_DATA;
SendBlock(bitmask_all_link_players_but_self(), &gLinkBattleSendBuffer[gTasks[taskId].data[15]], blockSize);
gTasks[taskId].data[11]++;
}
else
{
gTasks[taskId].data[13]--;
break;
}
}
break;
case 4:
2018-12-31 09:22:21 +01:00
if (IsLinkTaskFinished())
2017-10-13 17:22:50 +02:00
{
blockSize = gLinkBattleSendBuffer[gTasks[taskId].data[15] + LINK_BUFF_SIZE_LO] | (gLinkBattleSendBuffer[gTasks[taskId].data[15] + LINK_BUFF_SIZE_HI] << 8);
gTasks[taskId].data[13] = 1;
gTasks[taskId].data[15] = gTasks[taskId].data[15] + blockSize + LINK_BUFF_DATA;
gTasks[taskId].data[11] = 3;
}
break;
case 5:
gTasks[taskId].data[13]--;
if (gTasks[taskId].data[13] == 0)
{
gTasks[taskId].data[13] = 1;
gTasks[taskId].data[11] = 3;
}
break;
}
}
// fix me
void sub_8033648(void)
{
u8 i;
s32 j;
u16 r6;
u8 *recvBuffer;
u8 *dest;
u8 *src;
if (gReceivedRemoteLinkPlayers != 0 && (gBattleTypeFlags & BATTLE_TYPE_20))
{
sub_8011BD0();
for (i = 0; i < GetLinkPlayerCount(); i++)
{
if (GetBlockReceivedStatus() & gBitTable[i])
{
ResetBlockReceivedFlag(i);
recvBuffer = (u8 *)gBlockRecvBuffer[i];
#ifndef NONMATCHING
asm("");
recvBuffer = (u8 *)&gBlockRecvBuffer[i];
#endif
r6 = gBlockRecvBuffer[i][2];
if (gTasks[sLinkReceiveTaskId].data[14] + 9 + r6 > 0x1000)
2017-10-13 17:22:50 +02:00
{
gTasks[sLinkReceiveTaskId].data[12] = gTasks[sLinkReceiveTaskId].data[14];
gTasks[sLinkReceiveTaskId].data[14] = 0;
2017-10-13 17:22:50 +02:00
}
dest = &gLinkBattleRecvBuffer[gTasks[sLinkReceiveTaskId].data[14]];
2017-10-13 17:22:50 +02:00
src = recvBuffer;
for (j = 0; j < r6 + 8; j++)
dest[j] = src[j];
gTasks[sLinkReceiveTaskId].data[14] = gTasks[sLinkReceiveTaskId].data[14] + r6 + 8;
2017-10-13 17:22:50 +02:00
}
}
}
}
static void Task_HandleCopyReceivedLinkBuffersData(u8 taskId)
{
u16 blockSize;
2018-03-01 00:59:52 +01:00
u8 battlerId;
2017-10-13 17:22:50 +02:00
u8 var;
if (gTasks[taskId].data[15] != gTasks[taskId].data[14])
{
if (gTasks[taskId].data[15] > gTasks[taskId].data[14]
&& gTasks[taskId].data[15] == gTasks[taskId].data[12])
{
gTasks[taskId].data[12] = 0;
gTasks[taskId].data[15] = 0;
}
battlerId = gLinkBattleRecvBuffer[gTasks[taskId].data[15] + LINK_BUFF_ACTIVE_BATTLER];
2017-10-13 17:22:50 +02:00
blockSize = gLinkBattleRecvBuffer[gTasks[taskId].data[15] + LINK_BUFF_SIZE_LO] | (gLinkBattleRecvBuffer[gTasks[taskId].data[15] + LINK_BUFF_SIZE_HI] << 8);
switch (gLinkBattleRecvBuffer[gTasks[taskId].data[15] + 0])
{
case 0:
2018-03-01 00:59:52 +01:00
if (gBattleControllerExecFlags & gBitTable[battlerId])
2017-10-13 17:22:50 +02:00
return;
memcpy(gBattleResources->bufferA[battlerId], &gLinkBattleRecvBuffer[gTasks[taskId].data[15] + LINK_BUFF_DATA], blockSize);
2018-03-01 00:59:52 +01:00
sub_803F850(battlerId);
2017-10-13 17:22:50 +02:00
if (!(gBattleTypeFlags & BATTLE_TYPE_IS_MASTER))
2017-10-13 17:22:50 +02:00
{
gBattlerAttacker = gLinkBattleRecvBuffer[gTasks[taskId].data[15] + LINK_BUFF_ATTACKER];
gBattlerTarget = gLinkBattleRecvBuffer[gTasks[taskId].data[15] + LINK_BUFF_TARGET];
gAbsentBattlerFlags = gLinkBattleRecvBuffer[gTasks[taskId].data[15] + LINK_BUFF_ABSENT_BATTLER_FLAGS];
gEffectBattler = gLinkBattleRecvBuffer[gTasks[taskId].data[15] + LINK_BUFF_EFFECT_BATTLER];
2017-10-13 17:22:50 +02:00
}
break;
case 1:
memcpy(gBattleResources->bufferB[battlerId], &gLinkBattleRecvBuffer[gTasks[taskId].data[15] + LINK_BUFF_DATA], blockSize);
2017-10-13 17:22:50 +02:00
break;
case 2:
var = gLinkBattleRecvBuffer[gTasks[taskId].data[15] + LINK_BUFF_DATA];
2018-03-01 00:59:52 +01:00
gBattleControllerExecFlags &= ~(gBitTable[battlerId] << (var * 4));
2017-10-13 17:22:50 +02:00
break;
}
gTasks[taskId].data[15] = gTasks[taskId].data[15] + blockSize + LINK_BUFF_DATA;
}
}
2017-10-13 19:46:27 +02:00
2018-02-06 20:48:02 +01:00
void BtlController_EmitGetMonData(u8 bufferId, u8 requestId, u8 monToCheck)
2017-10-13 19:46:27 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_GETMONDATA;
sBattleBuffersTransferData[1] = requestId;
sBattleBuffersTransferData[2] = monToCheck;
sBattleBuffersTransferData[3] = 0;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-13 19:46:27 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitGetRawMonData(u8 bufferId, u8 monId, u8 bytes)
2017-10-13 19:46:27 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_GETRAWMONDATA;
sBattleBuffersTransferData[1] = monId;
sBattleBuffersTransferData[2] = bytes;
sBattleBuffersTransferData[3] = 0;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-13 19:46:27 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitSetMonData(u8 bufferId, u8 requestId, u8 monToCheck, u8 bytes, void *data)
2017-10-13 19:46:27 +02:00
{
s32 i;
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_SETMONDATA;
sBattleBuffersTransferData[1] = requestId;
sBattleBuffersTransferData[2] = monToCheck;
2017-10-13 19:46:27 +02:00
for (i = 0; i < bytes; i++)
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[3 + i] = *(u8*)(data++);
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 3 + bytes);
2017-10-13 19:46:27 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitSetRawMonData(u8 bufferId, u8 monId, u8 bytes, void *data)
2017-10-13 19:46:27 +02:00
{
s32 i;
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_SETRAWMONDATA;
sBattleBuffersTransferData[1] = monId;
sBattleBuffersTransferData[2] = bytes;
2017-10-13 19:46:27 +02:00
for (i = 0; i < bytes; i++)
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[3 + i] = *(u8*)(data++);
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, bytes + 3);
2017-10-13 19:46:27 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitLoadMonSprite(u8 bufferId)
2017-10-13 19:46:27 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_LOADMONSPRITE;
sBattleBuffersTransferData[1] = CONTROLLER_LOADMONSPRITE;
sBattleBuffersTransferData[2] = CONTROLLER_LOADMONSPRITE;
sBattleBuffersTransferData[3] = CONTROLLER_LOADMONSPRITE;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-13 19:46:27 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitSwitchInAnim(u8 bufferId, u8 partyId, bool8 dontClearSubstituteBit)
2017-10-13 19:46:27 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_SWITCHINANIM;
sBattleBuffersTransferData[1] = partyId;
sBattleBuffersTransferData[2] = dontClearSubstituteBit;
sBattleBuffersTransferData[3] = 5;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-13 19:46:27 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitReturnMonToBall(u8 bufferId, u8 arg1)
2017-10-13 19:46:27 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_RETURNMONTOBALL;
sBattleBuffersTransferData[1] = arg1;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 2);
2017-10-13 19:46:27 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitDrawTrainerPic(u8 bufferId)
2017-10-13 19:46:27 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_DRAWTRAINERPIC;
sBattleBuffersTransferData[1] = CONTROLLER_DRAWTRAINERPIC;
sBattleBuffersTransferData[2] = CONTROLLER_DRAWTRAINERPIC;
sBattleBuffersTransferData[3] = CONTROLLER_DRAWTRAINERPIC;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-13 19:46:27 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitTrainerSlide(u8 bufferId)
2017-10-13 19:46:27 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_TRAINERSLIDE;
sBattleBuffersTransferData[1] = CONTROLLER_TRAINERSLIDE;
sBattleBuffersTransferData[2] = CONTROLLER_TRAINERSLIDE;
sBattleBuffersTransferData[3] = CONTROLLER_TRAINERSLIDE;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-13 19:46:27 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitTrainerSlideBack(u8 bufferId)
2017-10-13 19:46:27 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_TRAINERSLIDEBACK;
sBattleBuffersTransferData[1] = CONTROLLER_TRAINERSLIDEBACK;
sBattleBuffersTransferData[2] = CONTROLLER_TRAINERSLIDEBACK;
sBattleBuffersTransferData[3] = CONTROLLER_TRAINERSLIDEBACK;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-13 19:46:27 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitFaintAnimation(u8 bufferId)
2017-10-13 19:46:27 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_FAINTANIMATION;
sBattleBuffersTransferData[1] = CONTROLLER_FAINTANIMATION;
sBattleBuffersTransferData[2] = CONTROLLER_FAINTANIMATION;
sBattleBuffersTransferData[3] = CONTROLLER_FAINTANIMATION;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-13 19:46:27 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitPaletteFade(u8 bufferId)
2017-10-13 19:46:27 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_PALETTEFADE;
sBattleBuffersTransferData[1] = CONTROLLER_PALETTEFADE;
sBattleBuffersTransferData[2] = CONTROLLER_PALETTEFADE;
sBattleBuffersTransferData[3] = CONTROLLER_PALETTEFADE;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-13 19:46:27 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitSuccessBallThrowAnim(u8 bufferId)
2017-10-13 19:46:27 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_SUCCESSBALLTHROWANIM;
sBattleBuffersTransferData[1] = CONTROLLER_SUCCESSBALLTHROWANIM;
sBattleBuffersTransferData[2] = CONTROLLER_SUCCESSBALLTHROWANIM;
sBattleBuffersTransferData[3] = CONTROLLER_SUCCESSBALLTHROWANIM;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-13 19:46:27 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitBallThrowAnim(u8 bufferId, u8 caseId)
2017-10-13 19:46:27 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_BALLTHROWANIM;
sBattleBuffersTransferData[1] = caseId;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 2);
2017-10-13 19:46:27 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitPause(u8 bufferId, u8 toWait, void *data)
2017-10-13 19:46:27 +02:00
{
s32 i;
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_PAUSE;
sBattleBuffersTransferData[1] = toWait;
2017-10-13 19:46:27 +02:00
for (i = 0; i < toWait * 3; i++)
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[2 + i] = *(u8*)(data++);
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, toWait * 3 + 2);
2017-10-13 19:46:27 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitMoveAnimation(u8 bufferId, u16 move, u8 turnOfMove, u16 movePower, s32 dmg, u8 friendship, struct DisableStruct *disableStructPtr, u8 multihit)
2017-10-13 19:46:27 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_MOVEANIMATION;
sBattleBuffersTransferData[1] = move;
sBattleBuffersTransferData[2] = (move & 0xFF00) >> 8;
sBattleBuffersTransferData[3] = turnOfMove;
sBattleBuffersTransferData[4] = movePower;
sBattleBuffersTransferData[5] = (movePower & 0xFF00) >> 8;
sBattleBuffersTransferData[6] = dmg;
sBattleBuffersTransferData[7] = (dmg & 0x0000FF00) >> 8;
sBattleBuffersTransferData[8] = (dmg & 0x00FF0000) >> 16;
sBattleBuffersTransferData[9] = (dmg & 0xFF000000) >> 24;
sBattleBuffersTransferData[10] = friendship;
sBattleBuffersTransferData[11] = multihit;
2018-07-14 13:17:10 +02:00
if (WEATHER_HAS_EFFECT)
2017-10-13 19:46:27 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[12] = gBattleWeather;
sBattleBuffersTransferData[13] = (gBattleWeather & 0xFF00) >> 8;
2017-10-13 19:46:27 +02:00
}
else
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[12] = 0;
sBattleBuffersTransferData[13] = 0;
2017-10-13 19:46:27 +02:00
}
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[14] = 0;
sBattleBuffersTransferData[15] = 0;
memcpy(&sBattleBuffersTransferData[16], disableStructPtr, sizeof(struct DisableStruct));
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 16 + sizeof(struct DisableStruct));
2017-10-13 19:46:27 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitPrintString(u8 bufferId, u16 stringID)
2017-10-13 19:46:27 +02:00
{
s32 i;
2018-07-01 11:15:42 +02:00
struct BattleMsgData* stringInfo;
2017-10-13 19:46:27 +02:00
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_PRINTSTRING;
sBattleBuffersTransferData[1] = gBattleOutcome;
sBattleBuffersTransferData[2] = stringID;
sBattleBuffersTransferData[3] = (stringID & 0xFF00) >> 8;
2017-10-13 19:46:27 +02:00
2018-07-01 11:15:42 +02:00
stringInfo = (struct BattleMsgData*)(&sBattleBuffersTransferData[4]);
2017-10-13 19:46:27 +02:00
stringInfo->currentMove = gCurrentMove;
2017-11-26 18:07:00 +01:00
stringInfo->originallyUsedMove = gChosenMove;
2017-10-13 19:46:27 +02:00
stringInfo->lastItem = gLastUsedItem;
stringInfo->lastAbility = gLastUsedAbility;
2018-02-06 02:46:59 +01:00
stringInfo->scrActive = gBattleScripting.battler;
2017-10-13 19:46:27 +02:00
stringInfo->unk1605E = gBattleStruct->field_52;
stringInfo->hpScale = gBattleStruct->hpScale;
2018-07-01 11:15:42 +02:00
stringInfo->itemEffectBattler = gPotentialItemEffectBattler;
2017-10-13 19:46:27 +02:00
stringInfo->moveType = gBattleMoves[gCurrentMove].type;
2018-02-06 02:46:59 +01:00
for (i = 0; i < MAX_BATTLERS_COUNT; i++)
2017-10-13 19:46:27 +02:00
stringInfo->abilities[i] = gBattleMons[i].ability;
for (i = 0; i < TEXT_BUFF_ARRAY_COUNT; i++)
{
stringInfo->textBuffs[0][i] = gBattleTextBuff1[i];
stringInfo->textBuffs[1][i] = gBattleTextBuff2[i];
stringInfo->textBuffs[2][i] = gBattleTextBuff3[i];
}
2018-07-01 11:15:42 +02:00
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, sizeof(struct BattleMsgData) + 4);
2017-10-13 19:46:27 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitPrintSelectionString(u8 bufferId, u16 stringID)
2017-10-13 19:46:27 +02:00
{
s32 i;
2018-07-01 11:15:42 +02:00
struct BattleMsgData *stringInfo;
2017-10-13 19:46:27 +02:00
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_PRINTSTRINGPLAYERONLY;
sBattleBuffersTransferData[1] = CONTROLLER_PRINTSTRINGPLAYERONLY;
sBattleBuffersTransferData[2] = stringID;
sBattleBuffersTransferData[3] = (stringID & 0xFF00) >> 8;
2017-10-13 19:46:27 +02:00
2018-07-01 11:15:42 +02:00
stringInfo = (struct BattleMsgData*)(&sBattleBuffersTransferData[4]);
2017-10-13 19:46:27 +02:00
stringInfo->currentMove = gCurrentMove;
2017-11-26 18:07:00 +01:00
stringInfo->originallyUsedMove = gChosenMove;
2017-10-13 19:46:27 +02:00
stringInfo->lastItem = gLastUsedItem;
stringInfo->lastAbility = gLastUsedAbility;
2018-02-06 02:46:59 +01:00
stringInfo->scrActive = gBattleScripting.battler;
2017-10-13 19:46:27 +02:00
stringInfo->unk1605E = gBattleStruct->field_52;
2018-02-06 02:46:59 +01:00
for (i = 0; i < MAX_BATTLERS_COUNT; i++)
2017-10-13 19:46:27 +02:00
stringInfo->abilities[i] = gBattleMons[i].ability;
for (i = 0; i < TEXT_BUFF_ARRAY_COUNT; i++)
{
stringInfo->textBuffs[0][i] = gBattleTextBuff1[i];
stringInfo->textBuffs[1][i] = gBattleTextBuff2[i];
stringInfo->textBuffs[2][i] = gBattleTextBuff3[i];
}
2018-07-01 11:15:42 +02:00
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, sizeof(struct BattleMsgData) + 4);
2017-10-13 19:46:27 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitChooseAction(u8 bufferId, u8 arg1, u16 arg2)
2017-10-13 19:46:27 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_CHOOSEACTION;
sBattleBuffersTransferData[1] = arg1;
sBattleBuffersTransferData[2] = arg2;
sBattleBuffersTransferData[3] = (arg2 & 0xFF00) >> 8;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-13 19:46:27 +02:00
}
2017-10-14 11:34:26 +02:00
2018-02-06 20:48:02 +01:00
void BtlController_EmitUnknownYesNoBox(u8 bufferId)
2017-10-14 11:34:26 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_UNKNOWNYESNOBOX;
sBattleBuffersTransferData[1] = CONTROLLER_UNKNOWNYESNOBOX;
sBattleBuffersTransferData[2] = CONTROLLER_UNKNOWNYESNOBOX;
sBattleBuffersTransferData[3] = CONTROLLER_UNKNOWNYESNOBOX;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-14 11:34:26 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitChooseMove(u8 bufferId, bool8 isDoubleBattle, bool8 NoPpNumber, struct ChooseMoveStruct *movePpData)
2017-10-14 11:34:26 +02:00
{
s32 i;
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_CHOOSEMOVE;
sBattleBuffersTransferData[1] = isDoubleBattle;
sBattleBuffersTransferData[2] = NoPpNumber;
sBattleBuffersTransferData[3] = 0;
2017-10-14 11:34:26 +02:00
for (i = 0; i < sizeof(*movePpData); i++)
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[4 + i] = *((u8*)(movePpData) + i);
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, sizeof(*movePpData) + 4);
2017-10-14 11:34:26 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitChooseItem(u8 bufferId, u8 *arg1)
2017-10-14 11:34:26 +02:00
{
s32 i;
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_OPENBAG;
2017-10-14 11:34:26 +02:00
for (i = 0; i < 3; i++)
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[1 + i] = arg1[i];
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-14 11:34:26 +02:00
}
2018-07-07 19:57:09 +02:00
void BtlController_EmitChoosePokemon(u8 bufferId, u8 caseId, u8 arg2, u8 abilityId, u8 *arg4)
2017-10-14 11:34:26 +02:00
{
s32 i;
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_CHOOSEPOKEMON;
sBattleBuffersTransferData[1] = caseId;
sBattleBuffersTransferData[2] = arg2;
sBattleBuffersTransferData[3] = abilityId;
2017-10-14 11:34:26 +02:00
for (i = 0; i < 3; i++)
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[4 + i] = arg4[i];
2018-07-07 19:57:09 +02:00
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 8); // Only 7 bytes were written.
2017-10-14 11:34:26 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitCmd23(u8 bufferId)
2017-10-14 11:34:26 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_23;
sBattleBuffersTransferData[1] = CONTROLLER_23;
sBattleBuffersTransferData[2] = CONTROLLER_23;
sBattleBuffersTransferData[3] = CONTROLLER_23;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-14 11:34:26 +02:00
}
// why is the argument u16 if it's being cast to s16 anyway?
2018-02-06 20:48:02 +01:00
void BtlController_EmitHealthBarUpdate(u8 bufferId, u16 hpValue)
2017-10-14 11:34:26 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_HEALTHBARUPDATE;
sBattleBuffersTransferData[1] = 0;
sBattleBuffersTransferData[2] = (s16)hpValue;
sBattleBuffersTransferData[3] = ((s16)hpValue & 0xFF00) >> 8;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-14 11:34:26 +02:00
}
// why is the argument u16 if it's being cast to s16 anyway?
2018-02-06 20:48:02 +01:00
void BtlController_EmitExpUpdate(u8 bufferId, u8 partyId, u16 expPoints)
2017-10-14 11:34:26 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_EXPUPDATE;
sBattleBuffersTransferData[1] = partyId;
sBattleBuffersTransferData[2] = (s16)expPoints;
sBattleBuffersTransferData[3] = ((s16)expPoints & 0xFF00) >> 8;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-14 11:34:26 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitStatusIconUpdate(u8 bufferId, u32 status1, u32 status2)
2017-10-14 11:34:26 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_STATUSICONUPDATE;
sBattleBuffersTransferData[1] = status1;
sBattleBuffersTransferData[2] = (status1 & 0x0000FF00) >> 8;
sBattleBuffersTransferData[3] = (status1 & 0x00FF0000) >> 16;
sBattleBuffersTransferData[4] = (status1 & 0xFF000000) >> 24;
sBattleBuffersTransferData[5] = status2;
sBattleBuffersTransferData[6] = (status2 & 0x0000FF00) >> 8;
sBattleBuffersTransferData[7] = (status2 & 0x00FF0000) >> 16;
sBattleBuffersTransferData[8] = (status2 & 0xFF000000) >> 24;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 9);
2017-10-14 11:34:26 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitStatusAnimation(u8 bufferId, bool8 status2, u32 status)
2017-10-14 11:34:26 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_STATUSANIMATION;
sBattleBuffersTransferData[1] = status2;
sBattleBuffersTransferData[2] = status;
sBattleBuffersTransferData[3] = (status & 0x0000FF00) >> 8;
sBattleBuffersTransferData[4] = (status & 0x00FF0000) >> 16;
sBattleBuffersTransferData[5] = (status & 0xFF000000) >> 24;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 6);
2017-10-14 11:34:26 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitStatusXor(u8 bufferId, u8 b)
2017-10-14 11:34:26 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_STATUSXOR;
sBattleBuffersTransferData[1] = b;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 2);
2017-10-14 11:34:26 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitDataTransfer(u8 bufferId, u16 size, void *data)
2017-10-14 11:34:26 +02:00
{
s32 i;
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_DATATRANSFER;
sBattleBuffersTransferData[1] = CONTROLLER_DATATRANSFER;
sBattleBuffersTransferData[2] = size;
sBattleBuffersTransferData[3] = (size & 0xFF00) >> 8;
2017-10-14 11:34:26 +02:00
for (i = 0; i < size; i++)
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[4 + i] = *(u8*)(data++);
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, size + 4);
2017-10-14 11:34:26 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitDMA3Transfer(u8 bufferId, void *dst, u16 size, void *data)
2017-10-14 11:34:26 +02:00
{
s32 i;
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_DMA3TRANSFER;
sBattleBuffersTransferData[1] = (u32)(dst);
sBattleBuffersTransferData[2] = ((u32)(dst) & 0x0000FF00) >> 8;
sBattleBuffersTransferData[3] = ((u32)(dst) & 0x00FF0000) >> 16;
sBattleBuffersTransferData[4] = ((u32)(dst) & 0xFF000000) >> 24;
sBattleBuffersTransferData[5] = size;
sBattleBuffersTransferData[6] = (size & 0xFF00) >> 8;
2017-10-14 11:34:26 +02:00
for (i = 0; i < size; i++)
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[7 + i] = *(u8*)(data++);
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, size + 7);
2017-10-14 11:34:26 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitPlayBGM(u8 bufferId, u16 songId, void *unusedDumbDataParameter)
2017-10-14 11:34:26 +02:00
{
s32 i;
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_31;
sBattleBuffersTransferData[1] = songId;
sBattleBuffersTransferData[2] = (songId & 0xFF00) >> 8;
2017-10-14 11:34:26 +02:00
for (i = 0; i < songId; i++) // ????
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[3 + i] = *(u8*)(unusedDumbDataParameter++);
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, songId + 3);
2017-10-14 11:34:26 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitCmd32(u8 bufferId, u16 size, void *data)
2017-10-14 11:34:26 +02:00
{
s32 i;
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_32;
sBattleBuffersTransferData[1] = size;
sBattleBuffersTransferData[2] = (size & 0xFF00) >> 8;
2017-10-14 11:34:26 +02:00
for (i = 0; i < size; i++)
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[3 + i] = *(u8*)(data++);
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, size + 3);
2017-10-14 11:34:26 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitTwoReturnValues(u8 bufferId, u8 arg1, u16 arg2)
2017-10-14 11:34:26 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_TWORETURNVALUES;
sBattleBuffersTransferData[1] = arg1;
sBattleBuffersTransferData[2] = arg2;
sBattleBuffersTransferData[3] = (arg2 & 0xFF00) >> 8;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-14 11:34:26 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitChosenMonReturnValue(u8 bufferId, u8 b, u8 *c)
2017-10-14 11:34:26 +02:00
{
s32 i;
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_CHOSENMONRETURNVALUE;
sBattleBuffersTransferData[1] = b;
2017-10-14 11:34:26 +02:00
for (i = 0; i < 3; i++)
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[2 + i] = c[i];
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 5);
2017-10-14 11:34:26 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitOneReturnValue(u8 bufferId, u16 arg1)
2017-10-14 11:34:26 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_ONERETURNVALUE;
sBattleBuffersTransferData[1] = arg1;
sBattleBuffersTransferData[2] = (arg1 & 0xFF00) >> 8;
sBattleBuffersTransferData[3] = 0;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-14 11:34:26 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitOneReturnValue_Duplicate(u8 bufferId, u16 b)
2017-10-14 11:34:26 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_ONERETURNVALUE_DUPLICATE;
sBattleBuffersTransferData[1] = b;
sBattleBuffersTransferData[2] = (b & 0xFF00) >> 8;
sBattleBuffersTransferData[3] = 0;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-14 11:34:26 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitCmd37(u8 bufferId)
2017-10-14 11:34:26 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_37;
sBattleBuffersTransferData[1] = CONTROLLER_37;
sBattleBuffersTransferData[2] = CONTROLLER_37;
sBattleBuffersTransferData[3] = CONTROLLER_37;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-14 11:34:26 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitCmd38(u8 bufferId, u8 b)
2017-10-14 11:34:26 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_38;
sBattleBuffersTransferData[1] = b;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 2);
2017-10-14 11:34:26 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitCmd39(u8 bufferId)
2017-10-14 11:34:26 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_39;
sBattleBuffersTransferData[1] = CONTROLLER_39;
sBattleBuffersTransferData[2] = CONTROLLER_39;
sBattleBuffersTransferData[3] = CONTROLLER_39;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-14 11:34:26 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitCmd40(u8 bufferId)
2017-10-14 11:34:26 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_40;
sBattleBuffersTransferData[1] = CONTROLLER_40;
sBattleBuffersTransferData[2] = CONTROLLER_40;
sBattleBuffersTransferData[3] = CONTROLLER_40;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-14 11:34:26 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitHitAnimation(u8 bufferId)
2017-10-14 11:34:26 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_HITANIMATION;
sBattleBuffersTransferData[1] = CONTROLLER_HITANIMATION;
sBattleBuffersTransferData[2] = CONTROLLER_HITANIMATION;
sBattleBuffersTransferData[3] = CONTROLLER_HITANIMATION;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-14 11:34:26 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitCmd42(u8 bufferId)
2017-10-14 11:34:26 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_42;
sBattleBuffersTransferData[1] = CONTROLLER_42;
sBattleBuffersTransferData[2] = CONTROLLER_42;
sBattleBuffersTransferData[3] = CONTROLLER_42;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-14 11:34:26 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitPlaySE(u8 bufferId, u16 songId)
2017-10-14 11:34:26 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_EFFECTIVENESSSOUND;
sBattleBuffersTransferData[1] = songId;
sBattleBuffersTransferData[2] = (songId & 0xFF00) >> 8;
sBattleBuffersTransferData[3] = 0;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-14 11:34:26 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitPlayFanfareOrBGM(u8 bufferId, u16 songId, bool8 playBGM)
2017-10-14 11:34:26 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_PLAYFANFAREORBGM;
sBattleBuffersTransferData[1] = songId;
sBattleBuffersTransferData[2] = (songId & 0xFF00) >> 8;
sBattleBuffersTransferData[3] = playBGM;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-14 11:34:26 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitFaintingCry(u8 bufferId)
2017-10-14 11:34:26 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_FAINTINGCRY;
sBattleBuffersTransferData[1] = CONTROLLER_FAINTINGCRY;
sBattleBuffersTransferData[2] = CONTROLLER_FAINTINGCRY;
sBattleBuffersTransferData[3] = CONTROLLER_FAINTINGCRY;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-14 11:34:26 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitIntroSlide(u8 bufferId, u8 terrainId)
2017-10-14 11:34:26 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_INTROSLIDE;
sBattleBuffersTransferData[1] = terrainId;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 2);
2017-10-14 11:34:26 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitIntroTrainerBallThrow(u8 bufferId)
2017-10-14 11:34:26 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_INTROTRAINERBALLTHROW;
sBattleBuffersTransferData[1] = CONTROLLER_INTROTRAINERBALLTHROW;
sBattleBuffersTransferData[2] = CONTROLLER_INTROTRAINERBALLTHROW;
sBattleBuffersTransferData[3] = CONTROLLER_INTROTRAINERBALLTHROW;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-14 11:34:26 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitDrawPartyStatusSummary(u8 bufferId, struct HpAndStatus* hpAndStatus, u8 arg2)
2017-10-14 11:34:26 +02:00
{
s32 i;
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_DRAWPARTYSTATUSSUMMARY;
sBattleBuffersTransferData[1] = arg2 & 0x7F;
sBattleBuffersTransferData[2] = (arg2 & 0x80) >> 7;
sBattleBuffersTransferData[3] = CONTROLLER_DRAWPARTYSTATUSSUMMARY;
2018-06-28 21:06:32 +02:00
for (i = 0; i < (s32)(sizeof(struct HpAndStatus) * PARTY_SIZE); i++)
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[4 + i] = *(i + (u8*)(hpAndStatus));
2018-06-28 21:06:32 +02:00
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, sizeof(struct HpAndStatus) * PARTY_SIZE + 4);
2017-10-14 11:34:26 +02:00
}
2018-06-28 21:06:32 +02:00
void BtlController_EmitHidePartyStatusSummary(u8 bufferId)
2017-10-14 11:34:26 +02:00
{
2018-06-28 21:06:32 +02:00
sBattleBuffersTransferData[0] = CONTROLLER_HIDEPARTYSTATUSSUMMARY;
sBattleBuffersTransferData[1] = CONTROLLER_HIDEPARTYSTATUSSUMMARY;
sBattleBuffersTransferData[2] = CONTROLLER_HIDEPARTYSTATUSSUMMARY;
sBattleBuffersTransferData[3] = CONTROLLER_HIDEPARTYSTATUSSUMMARY;
2017-11-11 02:27:02 +01:00
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-14 11:34:26 +02:00
}
2018-06-20 23:07:51 +02:00
void BtlController_EmitEndBounceEffect(u8 bufferId)
2017-10-14 11:34:26 +02:00
{
2018-06-20 23:07:51 +02:00
sBattleBuffersTransferData[0] = CONTROLLER_ENDBOUNCE;
sBattleBuffersTransferData[1] = CONTROLLER_ENDBOUNCE;
sBattleBuffersTransferData[2] = CONTROLLER_ENDBOUNCE;
sBattleBuffersTransferData[3] = CONTROLLER_ENDBOUNCE;
2017-11-11 02:27:02 +01:00
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-14 11:34:26 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitSpriteInvisibility(u8 bufferId, bool8 isInvisible)
2017-10-14 11:34:26 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_SPRITEINVISIBILITY;
sBattleBuffersTransferData[1] = isInvisible;
sBattleBuffersTransferData[2] = CONTROLLER_SPRITEINVISIBILITY;
sBattleBuffersTransferData[3] = CONTROLLER_SPRITEINVISIBILITY;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-14 11:34:26 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitBattleAnimation(u8 bufferId, u8 animationId, u16 argument)
2017-10-14 11:34:26 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_BATTLEANIMATION;
sBattleBuffersTransferData[1] = animationId;
sBattleBuffersTransferData[2] = argument;
sBattleBuffersTransferData[3] = (argument & 0xFF00) >> 8;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4);
2017-10-14 11:34:26 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitLinkStandbyMsg(u8 bufferId, u8 arg1, bool32 arg2)
2017-10-14 11:34:26 +02:00
{
bool8 arg2_ = arg2;
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_LINKSTANDBYMSG;
sBattleBuffersTransferData[1] = arg1;
2017-10-14 11:34:26 +02:00
if (arg2_)
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[3] = sBattleBuffersTransferData[2] = sub_81850DC(&sBattleBuffersTransferData[4]);
2017-10-14 11:34:26 +02:00
else
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[3] = sBattleBuffersTransferData[2] = 0;
2017-10-14 11:34:26 +02:00
2017-11-11 02:27:02 +01:00
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, sBattleBuffersTransferData[2] + 4);
2017-10-14 11:34:26 +02:00
}
2018-02-06 20:48:02 +01:00
void BtlController_EmitResetActionMoveSelection(u8 bufferId, u8 caseId)
2017-10-14 11:34:26 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_RESETACTIONMOVESELECTION;
sBattleBuffersTransferData[1] = caseId;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 2);
2017-10-14 11:34:26 +02:00
}
2018-06-28 21:06:32 +02:00
void BtlController_EmitCmd55(u8 bufferId, u8 battleOutcome)
2017-10-14 11:34:26 +02:00
{
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[0] = CONTROLLER_55;
2018-06-28 21:06:32 +02:00
sBattleBuffersTransferData[1] = battleOutcome;
sBattleBuffersTransferData[2] = gSaveBlock2Ptr->frontier.field_CA9_b;
sBattleBuffersTransferData[3] = gSaveBlock2Ptr->frontier.field_CA9_b;
2017-11-11 02:27:02 +01:00
sBattleBuffersTransferData[5] = sBattleBuffersTransferData[4] = sub_81850DC(&sBattleBuffersTransferData[6]);
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, sBattleBuffersTransferData[4] + 6);
2017-10-14 11:34:26 +02:00
}
2018-07-13 23:00:56 +02:00
void BtlController_EmitDebugMenu(u8 bufferId)
{
sBattleBuffersTransferData[0] = CONTROLLER_DEBUGMENU;
PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 1);
}