Merge pull request #2125 from DavidJCobb/battle-link-re

Battle link reverse-engineering
This commit is contained in:
GriffinR
2025-05-05 18:17:28 -04:00
committed by GitHub
17 changed files with 446 additions and 320 deletions

View File

@@ -23,7 +23,7 @@ static bool8 ShouldSwitchIfPerishSong(void)
&& gDisableStructs[gActiveBattler].perishSongTimer == 0)
{
*(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = PARTY_SIZE;
BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SWITCH, 0);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, B_ACTION_SWITCH, 0);
return TRUE;
}
else
@@ -107,7 +107,7 @@ static bool8 ShouldSwitchIfWonderGuard(void)
{
// We found a mon.
*(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = i;
BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SWITCH, 0);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, B_ACTION_SWITCH, 0);
return TRUE;
}
}
@@ -207,7 +207,7 @@ static bool8 FindMonThatAbsorbsOpponentsMove(void)
{
// we found a mon.
*(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = i;
BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SWITCH, 0);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, B_ACTION_SWITCH, 0);
return TRUE;
}
}
@@ -229,14 +229,14 @@ static bool8 ShouldSwitchIfNaturalCure(void)
&& Random() & 1)
{
*(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = PARTY_SIZE;
BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SWITCH, 0);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, B_ACTION_SWITCH, 0);
return TRUE;
}
else if (gBattleMoves[gLastLandedMoves[gActiveBattler]].power == 0
&& Random() & 1)
{
*(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = PARTY_SIZE;
BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SWITCH, 0);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, B_ACTION_SWITCH, 0);
return TRUE;
}
@@ -248,7 +248,7 @@ static bool8 ShouldSwitchIfNaturalCure(void)
if (Random() & 1)
{
*(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = PARTY_SIZE;
BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SWITCH, 0);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, B_ACTION_SWITCH, 0);
return TRUE;
}
@@ -416,7 +416,7 @@ static bool8 FindMonWithFlagsAndSuperEffective(u8 flags, u8 moduloPercent)
if (moveFlags & MOVE_RESULT_SUPER_EFFECTIVE && Random() % moduloPercent == 0)
{
*(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = i;
BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SWITCH, 0);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, B_ACTION_SWITCH, 0);
return TRUE;
}
}
@@ -599,7 +599,7 @@ void AI_TrySwitchOrUseItem(void)
}
}
BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_USE_MOVE, BATTLE_OPPOSITE(gActiveBattler) << 8);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, B_ACTION_USE_MOVE, BATTLE_OPPOSITE(gActiveBattler) << 8);
}
static void ModulateByTypeEffectiveness(u8 atkType, u8 defType1, u8 defType2, u8 *var)
@@ -933,7 +933,7 @@ static bool8 ShouldUseItem(void)
if (shouldUse)
{
BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_USE_ITEM, 0);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, B_ACTION_USE_ITEM, 0);
*(gBattleStruct->chosenItem + (gActiveBattler / 2) * 2) = item;
gBattleResources->battleHistory->trainerItems[i] = ITEM_NONE;
return shouldUse;

View File

@@ -518,7 +518,7 @@ static void LinkOpponentBufferExecCompleted(void)
{
u8 playerId = GetMultiplayerId();
PrepareBufferDataTransferLink(2, 4, &playerId);
PrepareBufferDataTransferLink(B_COMM_CONTROLLER_IS_DONE, 4, &playerId);
gBattleBufferA[gActiveBattler][0] = CONTROLLER_TERMINATOR_NOP;
}
else
@@ -548,7 +548,7 @@ static void LinkOpponentHandleGetMonData(void)
monToCheck >>= 1;
}
}
BtlController_EmitDataTransfer(BUFFER_B, size, monData);
BtlController_EmitDataTransfer(B_COMM_TO_ENGINE, size, monData);
LinkOpponentBufferExecCompleted();
}

View File

@@ -400,7 +400,7 @@ static void LinkPartnerBufferExecCompleted(void)
{
u8 playerId = GetMultiplayerId();
PrepareBufferDataTransferLink(2, 4, &playerId);
PrepareBufferDataTransferLink(B_COMM_CONTROLLER_IS_DONE, 4, &playerId);
gBattleBufferA[gActiveBattler][0] = CONTROLLER_TERMINATOR_NOP;
}
else
@@ -442,7 +442,7 @@ static void LinkPartnerHandleGetMonData(void)
monToCheck >>= 1;
}
}
BtlController_EmitDataTransfer(BUFFER_B, size, monData);
BtlController_EmitDataTransfer(B_COMM_TO_ENGINE, size, monData);
LinkPartnerBufferExecCompleted();
}

View File

@@ -531,7 +531,7 @@ static void OpponentBufferExecCompleted(void)
{
u8 playerId = GetMultiplayerId();
PrepareBufferDataTransferLink(2, 4, &playerId);
PrepareBufferDataTransferLink(B_COMM_CONTROLLER_IS_DONE, 4, &playerId);
gBattleBufferA[gActiveBattler][0] = CONTROLLER_TERMINATOR_NOP;
}
else
@@ -561,7 +561,7 @@ static void OpponentHandleGetMonData(void)
monToCheck >>= 1;
}
}
BtlController_EmitDataTransfer(BUFFER_B, size, monData);
BtlController_EmitDataTransfer(B_COMM_TO_ENGINE, size, monData);
OpponentBufferExecCompleted();
}
@@ -881,7 +881,7 @@ static void OpponentHandleGetRawMonData(void)
for (i = 0; i < gBattleBufferA[gActiveBattler][2]; i++)
dst[i] = src[i];
BtlController_EmitDataTransfer(BUFFER_B, gBattleBufferA[gActiveBattler][2], dst);
BtlController_EmitDataTransfer(B_COMM_TO_ENGINE, gBattleBufferA[gActiveBattler][2], dst);
OpponentBufferExecCompleted();
}
@@ -1552,7 +1552,7 @@ static void OpponentHandleChooseMove(void)
{
if (gBattleTypeFlags & BATTLE_TYPE_PALACE)
{
BtlController_EmitTwoReturnValues(BUFFER_B, 10, ChooseMoveAndTargetInBattlePalace());
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, 10, ChooseMoveAndTargetInBattlePalace());
OpponentBufferExecCompleted();
}
else
@@ -1569,13 +1569,13 @@ static void OpponentHandleChooseMove(void)
switch (chosenMoveId)
{
case AI_CHOICE_WATCH:
BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SAFARI_WATCH_CAREFULLY, 0);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, B_ACTION_SAFARI_WATCH_CAREFULLY, 0);
break;
case AI_CHOICE_FLEE:
BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_RUN, 0);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, B_ACTION_RUN, 0);
break;
case 6:
BtlController_EmitTwoReturnValues(BUFFER_B, 15, gBattlerTarget);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, 15, gBattlerTarget);
break;
default:
if (gBattleMoves[moveInfo->moves[chosenMoveId]].target & (MOVE_TARGET_USER_OR_SELECTED | MOVE_TARGET_USER))
@@ -1586,7 +1586,7 @@ static void OpponentHandleChooseMove(void)
if (gAbsentBattlerFlags & gBitTable[gBattlerTarget])
gBattlerTarget = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT);
}
BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (gBattlerTarget << 8));
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, 10, (chosenMoveId) | (gBattlerTarget << 8));
break;
}
OpponentBufferExecCompleted();
@@ -1601,11 +1601,11 @@ static void OpponentHandleChooseMove(void)
} while (move == MOVE_NONE);
if (gBattleMoves[move].target & (MOVE_TARGET_USER_OR_SELECTED | MOVE_TARGET_USER))
BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (gActiveBattler << 8));
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, 10, (chosenMoveId) | (gActiveBattler << 8));
else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE)
BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (GetBattlerAtPosition(Random() & 2) << 8));
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, 10, (chosenMoveId) | (GetBattlerAtPosition(Random() & 2) << 8));
else
BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (GetBattlerAtPosition(B_POSITION_PLAYER_LEFT) << 8));
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, 10, (chosenMoveId) | (GetBattlerAtPosition(B_POSITION_PLAYER_LEFT) << 8));
OpponentBufferExecCompleted();
}
@@ -1614,7 +1614,7 @@ static void OpponentHandleChooseMove(void)
static void OpponentHandleChooseItem(void)
{
BtlController_EmitOneReturnValue(BUFFER_B, *(gBattleStruct->chosenItem + (gActiveBattler / 2) * 2));
BtlController_EmitOneReturnValue(B_COMM_TO_ENGINE, *(gBattleStruct->chosenItem + (gActiveBattler / 2) * 2));
OpponentBufferExecCompleted();
}
@@ -1671,7 +1671,7 @@ static void OpponentHandleChoosePokemon(void)
*(gBattleStruct->monToSwitchIntoId + gActiveBattler) = chosenMonId;
BtlController_EmitChosenMonReturnValue(BUFFER_B, chosenMonId, NULL);
BtlController_EmitChosenMonReturnValue(B_COMM_TO_ENGINE, chosenMonId, NULL);
OpponentBufferExecCompleted();
}

View File

@@ -204,7 +204,7 @@ static void PlayerBufferExecCompleted(void)
{
u8 playerId = GetMultiplayerId();
PrepareBufferDataTransferLink(2, 4, &playerId);
PrepareBufferDataTransferLink(B_COMM_CONTROLLER_IS_DONE, 4, &playerId);
gBattleBufferA[gActiveBattler][0] = CONTROLLER_TERMINATOR_NOP;
}
else
@@ -249,16 +249,16 @@ static void HandleInputChooseAction(void)
switch (gActionSelectionCursor[gActiveBattler])
{
case 0: // Top left
BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_USE_MOVE, 0);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, B_ACTION_USE_MOVE, 0);
break;
case 1: // Top right
BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_USE_ITEM, 0);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, B_ACTION_USE_ITEM, 0);
break;
case 2: // Bottom left
BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SWITCH, 0);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, B_ACTION_SWITCH, 0);
break;
case 3: // Bottom right
BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_RUN, 0);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, B_ACTION_RUN, 0);
break;
}
PlayerBufferExecCompleted();
@@ -319,7 +319,7 @@ static void HandleInputChooseAction(void)
return;
}
PlaySE(SE_SELECT);
BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_CANCEL_PARTNER, 0);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, B_ACTION_CANCEL_PARTNER, 0);
PlayerBufferExecCompleted();
}
}
@@ -365,7 +365,7 @@ static void HandleInputChooseTarget(void)
{
PlaySE(SE_SELECT);
gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = SpriteCB_HideAsMoveTarget;
BtlController_EmitTwoReturnValues(BUFFER_B, 10, gMoveSelectionCursor[gActiveBattler] | (gMultiUsePlayerCursor << 8));
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, 10, gMoveSelectionCursor[gActiveBattler] | (gMultiUsePlayerCursor << 8));
EndBounceEffect(gMultiUsePlayerCursor, BOUNCE_HEALTHBOX);
PlayerBufferExecCompleted();
}
@@ -523,7 +523,7 @@ static void HandleInputChooseMove(void)
if (!canSelectTarget)
{
BtlController_EmitTwoReturnValues(BUFFER_B, 10, gMoveSelectionCursor[gActiveBattler] | (gMultiUsePlayerCursor << 8));
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, 10, gMoveSelectionCursor[gActiveBattler] | (gMultiUsePlayerCursor << 8));
PlayerBufferExecCompleted();
}
else
@@ -543,7 +543,7 @@ static void HandleInputChooseMove(void)
else if (JOY_NEW(B_BUTTON) || gPlayerDpadHoldFrames > 59)
{
PlaySE(SE_SELECT);
BtlController_EmitTwoReturnValues(BUFFER_B, 10, 0xFFFF);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, 10, 0xFFFF);
PlayerBufferExecCompleted();
}
else if (JOY_NEW(DPAD_LEFT))
@@ -1174,7 +1174,7 @@ static void Task_GiveExpToMon(u8 taskId)
gainedExp -= nextLvlExp - currExp;
savedActiveBattler = gActiveBattler;
gActiveBattler = battlerId;
BtlController_EmitTwoReturnValues(BUFFER_B, RET_VALUE_LEVELED_UP, gainedExp);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, RET_VALUE_LEVELED_UP, gainedExp);
gActiveBattler = savedActiveBattler;
if (IsDoubleBattle() == TRUE
@@ -1253,7 +1253,7 @@ static void Task_GiveExpWithExpBar(u8 taskId)
gainedExp -= expOnNextLvl - currExp;
savedActiveBattler = gActiveBattler;
gActiveBattler = battlerId;
BtlController_EmitTwoReturnValues(BUFFER_B, RET_VALUE_LEVELED_UP, gainedExp);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, RET_VALUE_LEVELED_UP, gainedExp);
gActiveBattler = savedActiveBattler;
gTasks[taskId].func = Task_LaunchLvlUpAnim;
}
@@ -1361,9 +1361,9 @@ static void WaitForMonSelection(void)
if (gMain.callback2 == BattleMainCB2 && !gPaletteFade.active)
{
if (gPartyMenuUseExitCallback == TRUE)
BtlController_EmitChosenMonReturnValue(BUFFER_B, gSelectedMonPartyId, gBattlePartyCurrentOrder);
BtlController_EmitChosenMonReturnValue(B_COMM_TO_ENGINE, gSelectedMonPartyId, gBattlePartyCurrentOrder);
else
BtlController_EmitChosenMonReturnValue(BUFFER_B, PARTY_SIZE, NULL);
BtlController_EmitChosenMonReturnValue(B_COMM_TO_ENGINE, PARTY_SIZE, NULL);
if ((gBattleBufferA[gActiveBattler][1] & 0xF) == 1)
PrintLinkStandbyMsg();
@@ -1387,7 +1387,7 @@ static void CompleteWhenChoseItem(void)
{
if (gMain.callback2 == BattleMainCB2 && !gPaletteFade.active)
{
BtlController_EmitOneReturnValue(BUFFER_B, gSpecialVar_ItemId);
BtlController_EmitOneReturnValue(B_COMM_TO_ENGINE, gSpecialVar_ItemId);
PlayerBufferExecCompleted();
}
}
@@ -1439,9 +1439,9 @@ static void PlayerHandleYesNoInput(void)
PlaySE(SE_SELECT);
if (gMultiUsePlayerCursor != 0)
BtlController_EmitTwoReturnValues(BUFFER_B, 0xE, 0);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, 0xE, 0);
else
BtlController_EmitTwoReturnValues(BUFFER_B, 0xD, 0);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, 0xD, 0);
PlayerBufferExecCompleted();
}
@@ -1600,7 +1600,7 @@ static void PlayerHandleGetMonData(void)
monToCheck >>= 1;
}
}
BtlController_EmitDataTransfer(BUFFER_B, size, monData);
BtlController_EmitDataTransfer(B_COMM_TO_ENGINE, size, monData);
PlayerBufferExecCompleted();
}
@@ -1920,7 +1920,7 @@ void PlayerHandleGetRawMonData(void)
for (i = 0; i < gBattleBufferA[gActiveBattler][2]; i++)
dst[i] = src[i];
BtlController_EmitDataTransfer(BUFFER_B, gBattleBufferA[gActiveBattler][2], dst);
BtlController_EmitDataTransfer(B_COMM_TO_ENGINE, gBattleBufferA[gActiveBattler][2], dst);
PlayerBufferExecCompleted();
}
@@ -2621,7 +2621,7 @@ static void PlayerChooseMoveInBattlePalace(void)
if (--*(gBattleStruct->arenaMindPoints + gActiveBattler) == 0)
{
gBattlePalaceMoveSelectionRngValue = gRngValue;
BtlController_EmitTwoReturnValues(BUFFER_B, 10, ChooseMoveAndTargetInBattlePalace());
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, 10, ChooseMoveAndTargetInBattlePalace());
PlayerBufferExecCompleted();
}
}
@@ -2671,7 +2671,7 @@ static void PlayerHandleChoosePokemon(void)
if (gBattleTypeFlags & BATTLE_TYPE_ARENA && (gBattleBufferA[gActiveBattler][1] & 0xF) != PARTY_ACTION_CANT_SWITCH)
{
BtlController_EmitChosenMonReturnValue(BUFFER_B, gBattlerPartyIndexes[gActiveBattler] + 1, gBattlePartyCurrentOrder);
BtlController_EmitChosenMonReturnValue(B_COMM_TO_ENGINE, gBattlerPartyIndexes[gActiveBattler] + 1, gBattlePartyCurrentOrder);
PlayerBufferExecCompleted();
}
else
@@ -2828,25 +2828,25 @@ static void PlayerHandleCmd32(void)
static void PlayerHandleTwoReturnValues(void)
{
BtlController_EmitTwoReturnValues(BUFFER_B, 0, 0);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, 0, 0);
PlayerBufferExecCompleted();
}
static void PlayerHandleChosenMonReturnValue(void)
{
BtlController_EmitChosenMonReturnValue(BUFFER_B, 0, NULL);
BtlController_EmitChosenMonReturnValue(B_COMM_TO_ENGINE, 0, NULL);
PlayerBufferExecCompleted();
}
static void PlayerHandleOneReturnValue(void)
{
BtlController_EmitOneReturnValue(BUFFER_B, 0);
BtlController_EmitOneReturnValue(B_COMM_TO_ENGINE, 0);
PlayerBufferExecCompleted();
}
static void PlayerHandleOneReturnValue_Duplicate(void)
{
BtlController_EmitOneReturnValue_Duplicate(BUFFER_B, 0);
BtlController_EmitOneReturnValue_Duplicate(B_COMM_TO_ENGINE, 0);
PlayerBufferExecCompleted();
}

View File

@@ -332,7 +332,7 @@ static void Task_GiveExpToMon(u8 taskId)
gainedExp -= nextLvlExp - currExp;
savedActiveBank = gActiveBattler;
gActiveBattler = battlerId;
BtlController_EmitTwoReturnValues(BUFFER_B, RET_VALUE_LEVELED_UP, gainedExp);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, RET_VALUE_LEVELED_UP, gainedExp);
gActiveBattler = savedActiveBank;
if (IsDoubleBattle() == TRUE
@@ -411,7 +411,7 @@ static void Task_GiveExpWithExpBar(u8 taskId)
gainedExp -= expOnNextLvl - currExp;
savedActiveBank = gActiveBattler;
gActiveBattler = battlerId;
BtlController_EmitTwoReturnValues(BUFFER_B, RET_VALUE_LEVELED_UP, gainedExp);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, RET_VALUE_LEVELED_UP, gainedExp);
gActiveBattler = savedActiveBank;
gTasks[taskId].func = Task_LaunchLvlUpAnim;
}
@@ -584,7 +584,7 @@ static void PlayerPartnerBufferExecCompleted(void)
{
u8 playerId = GetMultiplayerId();
PrepareBufferDataTransferLink(2, 4, &playerId);
PrepareBufferDataTransferLink(B_COMM_CONTROLLER_IS_DONE, 4, &playerId);
gBattleBufferA[gActiveBattler][0] = CONTROLLER_TERMINATOR_NOP;
}
else
@@ -626,7 +626,7 @@ static void PlayerPartnerHandleGetMonData(void)
monToCheck >>= 1;
}
}
BtlController_EmitDataTransfer(BUFFER_B, size, monData);
BtlController_EmitDataTransfer(B_COMM_TO_ENGINE, size, monData);
PlayerPartnerBufferExecCompleted();
}
@@ -1527,7 +1527,7 @@ static void PlayerPartnerHandleChooseMove(void)
gBattlerTarget = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT);
}
BtlController_EmitTwoReturnValues(BUFFER_B, 10, chosenMoveId | (gBattlerTarget << 8));
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, 10, chosenMoveId | (gBattlerTarget << 8));
PlayerPartnerBufferExecCompleted();
}
@@ -1557,7 +1557,7 @@ static void PlayerPartnerHandleChoosePokemon(void)
}
*(gBattleStruct->monToSwitchIntoId + gActiveBattler) = chosenMonId;
BtlController_EmitChosenMonReturnValue(BUFFER_B, chosenMonId, NULL);
BtlController_EmitChosenMonReturnValue(B_COMM_TO_ENGINE, chosenMonId, NULL);
PlayerPartnerBufferExecCompleted();
}

View File

@@ -504,7 +504,7 @@ static void RecordedOpponentBufferExecCompleted(void)
{
u8 playerId = GetMultiplayerId();
PrepareBufferDataTransferLink(2, 4, &playerId);
PrepareBufferDataTransferLink(B_COMM_CONTROLLER_IS_DONE, 4, &playerId);
gBattleBufferA[gActiveBattler][0] = CONTROLLER_TERMINATOR_NOP;
}
else
@@ -534,7 +534,7 @@ static void RecordedOpponentHandleGetMonData(void)
monToCheck >>= 1;
}
}
BtlController_EmitDataTransfer(BUFFER_B, size, monData);
BtlController_EmitDataTransfer(B_COMM_TO_ENGINE, size, monData);
RecordedOpponentBufferExecCompleted();
}
@@ -1402,7 +1402,7 @@ static void RecordedOpponentHandlePrintSelectionString(void)
static void RecordedOpponentHandleChooseAction(void)
{
BtlController_EmitTwoReturnValues(BUFFER_B, RecordedBattle_GetBattlerAction(gActiveBattler), 0);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, RecordedBattle_GetBattlerAction(gActiveBattler), 0);
RecordedOpponentBufferExecCompleted();
}
@@ -1415,13 +1415,13 @@ static void RecordedOpponentHandleChooseMove(void)
{
if (gBattleTypeFlags & BATTLE_TYPE_PALACE)
{
BtlController_EmitTwoReturnValues(BUFFER_B, 10, ChooseMoveAndTargetInBattlePalace());
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, 10, ChooseMoveAndTargetInBattlePalace());
}
else
{
u8 moveId = RecordedBattle_GetBattlerAction(gActiveBattler);
u8 target = RecordedBattle_GetBattlerAction(gActiveBattler);
BtlController_EmitTwoReturnValues(BUFFER_B, 10, moveId | (target << 8));
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, 10, moveId | (target << 8));
}
RecordedOpponentBufferExecCompleted();
@@ -1435,7 +1435,7 @@ static void RecordedOpponentHandleChooseItem(void)
static void RecordedOpponentHandleChoosePokemon(void)
{
*(gBattleStruct->monToSwitchIntoId + gActiveBattler) = RecordedBattle_GetBattlerAction(gActiveBattler);
BtlController_EmitChosenMonReturnValue(BUFFER_B, *(gBattleStruct->monToSwitchIntoId + gActiveBattler), NULL);
BtlController_EmitChosenMonReturnValue(B_COMM_TO_ENGINE, *(gBattleStruct->monToSwitchIntoId + gActiveBattler), NULL);
RecordedOpponentBufferExecCompleted();
}

View File

@@ -475,7 +475,7 @@ static void RecordedPlayerBufferExecCompleted(void)
{
u8 playerId = GetMultiplayerId();
PrepareBufferDataTransferLink(2, 4, &playerId);
PrepareBufferDataTransferLink(B_COMM_CONTROLLER_IS_DONE, 4, &playerId);
gBattleBufferA[gActiveBattler][0] = CONTROLLER_TERMINATOR_NOP;
}
else
@@ -517,7 +517,7 @@ static void RecordedPlayerHandleGetMonData(void)
monToCheck >>= 1;
}
}
BtlController_EmitDataTransfer(BUFFER_B, size, monData);
BtlController_EmitDataTransfer(B_COMM_TO_ENGINE, size, monData);
RecordedPlayerBufferExecCompleted();
}
@@ -1414,7 +1414,7 @@ static void ChooseActionInBattlePalace(void)
{
if (gBattleCommunication[4] >= gBattlersCount / 2)
{
BtlController_EmitTwoReturnValues(BUFFER_B, RecordedBattle_GetBattlerAction(gActiveBattler), 0);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, RecordedBattle_GetBattlerAction(gActiveBattler), 0);
RecordedPlayerBufferExecCompleted();
}
}
@@ -1427,7 +1427,7 @@ static void RecordedPlayerHandleChooseAction(void)
}
else
{
BtlController_EmitTwoReturnValues(BUFFER_B, RecordedBattle_GetBattlerAction(gActiveBattler), 0);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, RecordedBattle_GetBattlerAction(gActiveBattler), 0);
RecordedPlayerBufferExecCompleted();
}
}
@@ -1441,13 +1441,13 @@ static void RecordedPlayerHandleChooseMove(void)
{
if (gBattleTypeFlags & BATTLE_TYPE_PALACE)
{
BtlController_EmitTwoReturnValues(BUFFER_B, 10, ChooseMoveAndTargetInBattlePalace());
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, 10, ChooseMoveAndTargetInBattlePalace());
}
else
{
u8 moveId = RecordedBattle_GetBattlerAction(gActiveBattler);
u8 target = RecordedBattle_GetBattlerAction(gActiveBattler);
BtlController_EmitTwoReturnValues(BUFFER_B, 10, moveId | (target << 8));
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, 10, moveId | (target << 8));
}
RecordedPlayerBufferExecCompleted();
@@ -1461,7 +1461,7 @@ static void RecordedPlayerHandleChooseItem(void)
static void RecordedPlayerHandleChoosePokemon(void)
{
*(gBattleStruct->monToSwitchIntoId + gActiveBattler) = RecordedBattle_GetBattlerAction(gActiveBattler);
BtlController_EmitChosenMonReturnValue(BUFFER_B, *(gBattleStruct->monToSwitchIntoId + gActiveBattler), NULL);
BtlController_EmitChosenMonReturnValue(B_COMM_TO_ENGINE, *(gBattleStruct->monToSwitchIntoId + gActiveBattler), NULL);
RecordedPlayerBufferExecCompleted();
}

View File

@@ -176,16 +176,16 @@ static void HandleInputChooseAction(void)
switch (gActionSelectionCursor[gActiveBattler])
{
case 0:
BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SAFARI_BALL, 0);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, B_ACTION_SAFARI_BALL, 0);
break;
case 1:
BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SAFARI_POKEBLOCK, 0);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, B_ACTION_SAFARI_POKEBLOCK, 0);
break;
case 2:
BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SAFARI_GO_NEAR, 0);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, B_ACTION_SAFARI_GO_NEAR, 0);
break;
case 3:
BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SAFARI_RUN, 0);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, B_ACTION_SAFARI_RUN, 0);
break;
}
SafariBufferExecCompleted();
@@ -280,7 +280,7 @@ static void CompleteWhenChosePokeblock(void)
{
if (gMain.callback2 == BattleMainCB2 && !gPaletteFade.active)
{
BtlController_EmitOneReturnValue(BUFFER_B, gSpecialVar_ItemId);
BtlController_EmitOneReturnValue(B_COMM_TO_ENGINE, gSpecialVar_ItemId);
SafariBufferExecCompleted();
}
}
@@ -298,7 +298,7 @@ static void SafariBufferExecCompleted(void)
{
u8 playerId = GetMultiplayerId();
PrepareBufferDataTransferLink(2, 4, &playerId);
PrepareBufferDataTransferLink(B_COMM_CONTROLLER_IS_DONE, 4, &playerId);
gBattleBufferA[gActiveBattler][0] = CONTROLLER_TERMINATOR_NOP;
}
else

View File

@@ -196,7 +196,7 @@ static void WallyHandleActions(void)
if (--gBattleStruct->wallyWaitFrames == 0)
{
PlaySE(SE_SELECT);
BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_USE_MOVE, 0);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, B_ACTION_USE_MOVE, 0);
WallyBufferExecCompleted();
gBattleStruct->wallyBattleState++;
gBattleStruct->wallyMovesState = 0;
@@ -207,7 +207,7 @@ static void WallyHandleActions(void)
if (--gBattleStruct->wallyWaitFrames == 0)
{
PlaySE(SE_SELECT);
BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_USE_MOVE, 0);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, B_ACTION_USE_MOVE, 0);
WallyBufferExecCompleted();
gBattleStruct->wallyBattleState++;
gBattleStruct->wallyMovesState = 0;
@@ -217,7 +217,7 @@ static void WallyHandleActions(void)
case 3:
if (--gBattleStruct->wallyWaitFrames == 0)
{
BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_WALLY_THROW, 0);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, B_ACTION_WALLY_THROW, 0);
WallyBufferExecCompleted();
gBattleStruct->wallyBattleState++;
gBattleStruct->wallyMovesState = 0;
@@ -238,7 +238,7 @@ static void WallyHandleActions(void)
if (--gBattleStruct->wallyWaitFrames == 0)
{
PlaySE(SE_SELECT);
BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_USE_ITEM, 0);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, B_ACTION_USE_ITEM, 0);
WallyBufferExecCompleted();
}
break;
@@ -278,7 +278,7 @@ static void CompleteOnChosenItem(void)
{
if (gMain.callback2 == BattleMainCB2 && !gPaletteFade.active)
{
BtlController_EmitOneReturnValue(BUFFER_B, gSpecialVar_ItemId);
BtlController_EmitOneReturnValue(B_COMM_TO_ENGINE, gSpecialVar_ItemId);
WallyBufferExecCompleted();
}
}
@@ -408,7 +408,7 @@ static void WallyBufferExecCompleted(void)
{
u8 playerId = GetMultiplayerId();
PrepareBufferDataTransferLink(2, 4, &playerId);
PrepareBufferDataTransferLink(B_COMM_CONTROLLER_IS_DONE, 4, &playerId);
gBattleBufferA[gActiveBattler][0] = CONTROLLER_TERMINATOR_NOP;
}
else
@@ -444,7 +444,7 @@ static void WallyHandleGetMonData(void)
monToCheck >>= 1;
}
}
BtlController_EmitDataTransfer(BUFFER_B, size, monData);
BtlController_EmitDataTransfer(B_COMM_TO_ENGINE, size, monData);
WallyBufferExecCompleted();
}
@@ -1241,7 +1241,7 @@ static void WallyHandleChooseMove(void)
if (--gBattleStruct->wallyMoveFrames == 0)
{
PlaySE(SE_SELECT);
BtlController_EmitTwoReturnValues(BUFFER_B, 10, 0x100);
BtlController_EmitTwoReturnValues(B_COMM_TO_ENGINE, 10, 0x100);
WallyBufferExecCompleted();
}
break;

View File

@@ -659,11 +659,11 @@ static void PrepareBufferDataTransfer(u8 bufferId, u8 *data, u16 size)
{
switch (bufferId)
{
case BUFFER_A:
case B_COMM_TO_CONTROLLER:
for (i = 0; i < size; data++, i++)
gBattleBufferA[gActiveBattler][i] = *data;
break;
case BUFFER_B:
case B_COMM_TO_ENGINE:
for (i = 0; i < size; data++, i++)
gBattleBufferB[gActiveBattler][i] = *data;
break;
@@ -671,20 +671,41 @@ static void PrepareBufferDataTransfer(u8 bufferId, u8 *data, u16 size)
}
}
#define tInitialDelayTimer data[10]
#define tState data[11]
#define tCurrentBlock_WrapFrom data[12]
#define tBlockSendDelayTimer data[13]
#define tCurrentBlock_End data[14]
#define tCurrentBlock_Start data[15]
//
// Inbound communications are stored in one buffer; outbound communications
// in another. Both buffers work pretty similarly: the next message will be
// written into the buffer after the previous message (with 4-byte alignment),
// unless we're too close to the end of the buffer, in which case we jump back
// to the start.
//
// Regarding the task variable names above: these variables are altered in-
// place, so the precise operational definition of "current" depends on when
// the variables are being accessed. When data is present in the send and
// receive buffers, "current" refers to the most recently received message;
// but when a message is actually being placed in the buffers, "current"
// refers to the previous message, until such time that we finish updating it
// to refer to the new message.
static void CreateTasksForSendRecvLinkBuffers(void)
{
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;
gTasks[sLinkSendTaskId].tState = 0;
gTasks[sLinkSendTaskId].tCurrentBlock_WrapFrom = 0;
gTasks[sLinkSendTaskId].tBlockSendDelayTimer = 0;
gTasks[sLinkSendTaskId].tCurrentBlock_End = 0;
gTasks[sLinkSendTaskId].tCurrentBlock_Start = 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;
gTasks[sLinkReceiveTaskId].tCurrentBlock_WrapFrom = 0;
gTasks[sLinkReceiveTaskId].tBlockSendDelayTimer = 0; // not used by "receive" task
gTasks[sLinkReceiveTaskId].tCurrentBlock_End = 0;
gTasks[sLinkReceiveTaskId].tCurrentBlock_Start = 0;
sUnused = 0;
}
@@ -702,52 +723,72 @@ enum
LINK_BUFF_DATA,
};
// We want to send a message. Place it into the "send" buffer.
// First argument is a BATTLELINKCOMMTYPE_...
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)
if (gTasks[sLinkSendTaskId].tCurrentBlock_End + alignedSize + LINK_BUFF_DATA + 1 > BATTLE_BUFFER_LINK_SIZE)
{
gTasks[sLinkSendTaskId].data[12] = gTasks[sLinkSendTaskId].data[14];
gTasks[sLinkSendTaskId].data[14] = 0;
gTasks[sLinkSendTaskId].tCurrentBlock_WrapFrom = gTasks[sLinkSendTaskId].tCurrentBlock_End;
gTasks[sLinkSendTaskId].tCurrentBlock_End = 0;
}
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;
#define BYTE_TO_SEND(offset) \
gLinkBattleSendBuffer[gTasks[sLinkSendTaskId].tCurrentBlock_End + offset]
BYTE_TO_SEND(LINK_BUFF_BUFFER_ID) = bufferId;
BYTE_TO_SEND(LINK_BUFF_ACTIVE_BATTLER) = gActiveBattler;
BYTE_TO_SEND(LINK_BUFF_ATTACKER) = gBattlerAttacker;
BYTE_TO_SEND(LINK_BUFF_TARGET) = gBattlerTarget;
BYTE_TO_SEND(LINK_BUFF_SIZE_LO) = alignedSize;
BYTE_TO_SEND(LINK_BUFF_SIZE_HI) = (alignedSize & 0x0000FF00) >> 8;
BYTE_TO_SEND(LINK_BUFF_ABSENT_BATTLER_FLAGS) = gAbsentBattlerFlags;
BYTE_TO_SEND(LINK_BUFF_EFFECT_BATTLER) = gEffectBattler;
for (i = 0; i < size; i++)
gLinkBattleSendBuffer[gTasks[sLinkSendTaskId].data[14] + LINK_BUFF_DATA + i] = data[i];
BYTE_TO_SEND(LINK_BUFF_DATA + i) = data[i];
gTasks[sLinkSendTaskId].data[14] = gTasks[sLinkSendTaskId].data[14] + alignedSize + LINK_BUFF_DATA;
#undef BYTE_TO_SEND
gTasks[sLinkSendTaskId].tCurrentBlock_End = gTasks[sLinkSendTaskId].tCurrentBlock_End + alignedSize + LINK_BUFF_DATA;
}
enum {
SENDTASK_STATE_INITIALIZE = 0,
SENDTASK_STATE_INITIAL_DELAY = 1,
SENDTASK_STATE_COUNT_PLAYERS = 2,
SENDTASK_STATE_BEGIN_SEND_BLOCK = 3,
SENDTASK_STATE_FINISH_SEND_BLOCK = 4,
SENDTASK_STATE_UNUSED_STATE = 5,
};
static void Task_HandleSendLinkBuffersData(u8 taskId)
{
u16 numPlayers;
u16 blockSize;
#define BYTE_TO_SEND(offset) \
gLinkBattleSendBuffer[gTasks[taskId].tCurrentBlock_Start + offset]
switch (gTasks[taskId].data[11])
switch (gTasks[taskId].tState)
{
case 0:
gTasks[taskId].data[10] = 100;
gTasks[taskId].data[11]++;
case SENDTASK_STATE_INITIALIZE:
gTasks[taskId].tInitialDelayTimer = 100;
gTasks[taskId].tState++;
break;
case 1:
gTasks[taskId].data[10]--;
if (gTasks[taskId].data[10] == 0)
gTasks[taskId].data[11]++;
case SENDTASK_STATE_INITIAL_DELAY:
gTasks[taskId].tInitialDelayTimer--;
if (gTasks[taskId].tInitialDelayTimer == 0)
gTasks[taskId].tState++;
break;
case 2:
case SENDTASK_STATE_COUNT_PLAYERS:
if (gWirelessCommType)
{
gTasks[taskId].data[11]++;
gTasks[taskId].tState++;
}
else
{
@@ -761,56 +802,66 @@ static void Task_HandleSendLinkBuffersData(u8 taskId)
if (IsLinkMaster())
{
CheckShouldAdvanceLinkState();
gTasks[taskId].data[11]++;
gTasks[taskId].tState++;
}
else
{
gTasks[taskId].data[11]++;
gTasks[taskId].tState++;
}
}
}
break;
case 3:
if (gTasks[taskId].data[15] != gTasks[taskId].data[14])
case SENDTASK_STATE_BEGIN_SEND_BLOCK:
if (gTasks[taskId].tCurrentBlock_Start != gTasks[taskId].tCurrentBlock_End)
{
if (gTasks[taskId].data[13] == 0)
if (gTasks[taskId].tBlockSendDelayTimer == 0)
{
if (gTasks[taskId].data[15] > gTasks[taskId].data[14]
&& gTasks[taskId].data[15] == gTasks[taskId].data[12])
if (gTasks[taskId].tCurrentBlock_Start > gTasks[taskId].tCurrentBlock_End
&& gTasks[taskId].tCurrentBlock_Start == gTasks[taskId].tCurrentBlock_WrapFrom)
{
gTasks[taskId].data[12] = 0;
gTasks[taskId].data[15] = 0;
gTasks[taskId].tCurrentBlock_WrapFrom = 0;
gTasks[taskId].tCurrentBlock_Start = 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(BitmaskAllOtherLinkPlayers(), &gLinkBattleSendBuffer[gTasks[taskId].data[15]], blockSize);
gTasks[taskId].data[11]++;
blockSize = (BYTE_TO_SEND(LINK_BUFF_SIZE_LO) | (BYTE_TO_SEND(LINK_BUFF_SIZE_HI) << 8)) + LINK_BUFF_DATA;
SendBlock(BitmaskAllOtherLinkPlayers(), &BYTE_TO_SEND(0), blockSize);
gTasks[taskId].tState++;
}
else
{
gTasks[taskId].data[13]--;
gTasks[taskId].tBlockSendDelayTimer--;
break;
}
}
break;
case 4:
case SENDTASK_STATE_FINISH_SEND_BLOCK:
if (IsLinkTaskFinished())
{
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;
blockSize = BYTE_TO_SEND(LINK_BUFF_SIZE_LO) | (BYTE_TO_SEND(LINK_BUFF_SIZE_HI) << 8);
gTasks[taskId].tBlockSendDelayTimer = 1;
gTasks[taskId].tCurrentBlock_Start = gTasks[taskId].tCurrentBlock_Start + blockSize + LINK_BUFF_DATA;
gTasks[taskId].tState = SENDTASK_STATE_BEGIN_SEND_BLOCK;
}
break;
case 5:
if (--gTasks[taskId].data[13] == 0)
case SENDTASK_STATE_UNUSED_STATE:
if (--gTasks[taskId].tBlockSendDelayTimer == 0)
{
gTasks[taskId].data[13] = 1;
gTasks[taskId].data[11] = 3;
gTasks[taskId].tBlockSendDelayTimer = 1;
gTasks[taskId].tState = SENDTASK_STATE_BEGIN_SEND_BLOCK;
}
break;
}
#undef BYTE_TO_SEND
}
// We have received a message. Place it into the "receive" buffer.
//
// Counterintuitively, we also "receive" the outbound messages that
// we send to other players. The GBA basically stores communicated
// data for all four players, so inbound and outbound data can be
// handled uniformly unless a game specifically decides to do
// otherwise. Pokemon, evidently, did not specifically decide to do
// otherwise.
void TryReceiveLinkBattleData(void)
{
u8 i;
@@ -830,19 +881,19 @@ void TryReceiveLinkBattleData(void)
u8 *dest, *src;
u16 dataSize = gBlockRecvBuffer[i][2];
if (gTasks[sLinkReceiveTaskId].data[14] + 9 + dataSize > 0x1000)
if (gTasks[sLinkReceiveTaskId].tCurrentBlock_End + 9 + dataSize > 0x1000)
{
gTasks[sLinkReceiveTaskId].data[12] = gTasks[sLinkReceiveTaskId].data[14];
gTasks[sLinkReceiveTaskId].data[14] = 0;
gTasks[sLinkReceiveTaskId].tCurrentBlock_WrapFrom = gTasks[sLinkReceiveTaskId].tCurrentBlock_End;
gTasks[sLinkReceiveTaskId].tCurrentBlock_End = 0;
}
dest = &gLinkBattleRecvBuffer[gTasks[sLinkReceiveTaskId].data[14]];
dest = &gLinkBattleRecvBuffer[gTasks[sLinkReceiveTaskId].tCurrentBlock_End];
src = recvBuffer;
for (j = 0; j < dataSize + 8; j++)
dest[j] = src[j];
gTasks[sLinkReceiveTaskId].data[14] = gTasks[sLinkReceiveTaskId].data[14] + dataSize + 8;
gTasks[sLinkReceiveTaskId].tCurrentBlock_End = gTasks[sLinkReceiveTaskId].tCurrentBlock_End + dataSize + 8;
}
}
}
@@ -853,49 +904,61 @@ static void Task_HandleCopyReceivedLinkBuffersData(u8 taskId)
{
u16 blockSize;
u8 battlerId;
u8 var;
u8 playerId;
#define BYTE_TO_RECEIVE(offset) \
gLinkBattleRecvBuffer[gTasks[taskId].tCurrentBlock_Start + offset]
if (gTasks[taskId].data[15] != gTasks[taskId].data[14])
if (gTasks[taskId].tCurrentBlock_Start != gTasks[taskId].tCurrentBlock_End)
{
if (gTasks[taskId].data[15] > gTasks[taskId].data[14]
&& gTasks[taskId].data[15] == gTasks[taskId].data[12])
if (gTasks[taskId].tCurrentBlock_Start > gTasks[taskId].tCurrentBlock_End
&& gTasks[taskId].tCurrentBlock_Start == gTasks[taskId].tCurrentBlock_WrapFrom)
{
gTasks[taskId].data[12] = 0;
gTasks[taskId].data[15] = 0;
gTasks[taskId].tCurrentBlock_WrapFrom = 0;
gTasks[taskId].tCurrentBlock_Start = 0;
}
battlerId = gLinkBattleRecvBuffer[gTasks[taskId].data[15] + LINK_BUFF_ACTIVE_BATTLER];
blockSize = gLinkBattleRecvBuffer[gTasks[taskId].data[15] + LINK_BUFF_SIZE_LO] | (gLinkBattleRecvBuffer[gTasks[taskId].data[15] + LINK_BUFF_SIZE_HI] << 8);
battlerId = BYTE_TO_RECEIVE(LINK_BUFF_ACTIVE_BATTLER);
blockSize = BYTE_TO_RECEIVE(LINK_BUFF_SIZE_LO) | (BYTE_TO_RECEIVE(LINK_BUFF_SIZE_HI) << 8);
switch (gLinkBattleRecvBuffer[gTasks[taskId].data[15] + 0])
switch (BYTE_TO_RECEIVE(0))
{
case 0:
if (gBattleControllerExecFlags & gBitTable[battlerId])
case B_COMM_TO_CONTROLLER:
if (IS_BATTLE_CONTROLLER_ACTIVE_ON_LOCAL(battlerId))
return;
memcpy(gBattleBufferA[battlerId], &gLinkBattleRecvBuffer[gTasks[taskId].data[15] + LINK_BUFF_DATA], blockSize);
memcpy(gBattleBufferA[battlerId], &BYTE_TO_RECEIVE(LINK_BUFF_DATA), blockSize);
MarkBattlerReceivedLinkData(battlerId);
if (!(gBattleTypeFlags & BATTLE_TYPE_IS_MASTER))
{
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];
gBattlerAttacker = BYTE_TO_RECEIVE(LINK_BUFF_ATTACKER);
gBattlerTarget = BYTE_TO_RECEIVE(LINK_BUFF_TARGET);
gAbsentBattlerFlags = BYTE_TO_RECEIVE(LINK_BUFF_ABSENT_BATTLER_FLAGS);
gEffectBattler = BYTE_TO_RECEIVE(LINK_BUFF_EFFECT_BATTLER);
}
break;
case 1:
memcpy(gBattleBufferB[battlerId], &gLinkBattleRecvBuffer[gTasks[taskId].data[15] + LINK_BUFF_DATA], blockSize);
case B_COMM_TO_ENGINE:
memcpy(gBattleBufferB[battlerId], &gLinkBattleRecvBuffer[gTasks[taskId].tCurrentBlock_Start + LINK_BUFF_DATA], blockSize);
break;
case 2:
var = gLinkBattleRecvBuffer[gTasks[taskId].data[15] + LINK_BUFF_DATA];
gBattleControllerExecFlags &= ~(gBitTable[battlerId] << (var * 4));
case B_COMM_CONTROLLER_IS_DONE:
playerId = BYTE_TO_RECEIVE(LINK_BUFF_DATA);
MARK_BATTLE_CONTROLLER_IDLE_FOR_PLAYER(battlerId, playerId);
break;
}
gTasks[taskId].data[15] = gTasks[taskId].data[15] + blockSize + LINK_BUFF_DATA;
gTasks[taskId].tCurrentBlock_Start = gTasks[taskId].tCurrentBlock_Start + blockSize + LINK_BUFF_DATA;
}
#undef BYTE_TO_RECEIVE
}
#undef tInitialDelayTimer
#undef tState
#undef tCurrentBlock_WrapFrom
#undef tBlockSendDelayTimer
#undef tCurrentBlock_End
#undef tCurrentBlock_Start
void BtlController_EmitGetMonData(u8 bufferId, u8 requestId, u8 monToCheck)
{
sBattleBuffersTransferData[0] = CONTROLLER_GETMONDATA;

View File

@@ -3360,7 +3360,7 @@ static void BattleIntroGetMonsData(void)
{
case 0:
gActiveBattler = gBattleCommunication[1];
BtlController_EmitGetMonData(BUFFER_A, REQUEST_ALL_BATTLE, 0);
BtlController_EmitGetMonData(B_COMM_TO_CONTROLLER, REQUEST_ALL_BATTLE, 0);
MarkBattlerForControllerExec(gActiveBattler);
gBattleCommunication[MULTIUSE_STATE]++;
break;
@@ -3382,7 +3382,7 @@ static void BattleIntroPrepareBackgroundSlide(void)
if (gBattleControllerExecFlags == 0)
{
gActiveBattler = GetBattlerAtPosition(0);
BtlController_EmitIntroSlide(BUFFER_A, gBattleEnvironment);
BtlController_EmitIntroSlide(B_COMM_TO_CONTROLLER, gBattleEnvironment);
MarkBattlerForControllerExec(gActiveBattler);
gBattleMainFunc = BattleIntroDrawTrainersOrMonsSprites;
gBattleCommunication[MULTIUSE_STATE] = 0;
@@ -3427,7 +3427,7 @@ static void BattleIntroDrawTrainersOrMonsSprites(void)
if (GetBattlerPosition(gActiveBattler) == B_POSITION_PLAYER_LEFT)
{
BtlController_EmitDrawTrainerPic(BUFFER_A);
BtlController_EmitDrawTrainerPic(B_COMM_TO_CONTROLLER);
MarkBattlerForControllerExec(gActiveBattler);
}
@@ -3435,7 +3435,7 @@ static void BattleIntroDrawTrainersOrMonsSprites(void)
{
if (GetBattlerPosition(gActiveBattler) == B_POSITION_OPPONENT_LEFT)
{
BtlController_EmitDrawTrainerPic(BUFFER_A);
BtlController_EmitDrawTrainerPic(B_COMM_TO_CONTROLLER);
MarkBattlerForControllerExec(gActiveBattler);
}
if (GetBattlerSide(gActiveBattler) == B_SIDE_OPPONENT
@@ -3460,7 +3460,7 @@ static void BattleIntroDrawTrainersOrMonsSprites(void)
{
HandleSetPokedexFlag(SpeciesToNationalPokedexNum(gBattleMons[gActiveBattler].species), FLAG_SET_SEEN, gBattleMons[gActiveBattler].personality);
}
BtlController_EmitLoadMonSprite(BUFFER_A);
BtlController_EmitLoadMonSprite(B_COMM_TO_CONTROLLER);
MarkBattlerForControllerExec(gActiveBattler);
gBattleResults.lastOpponentSpecies = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_SPECIES, NULL);
}
@@ -3471,14 +3471,14 @@ static void BattleIntroDrawTrainersOrMonsSprites(void)
if (GetBattlerPosition(gActiveBattler) == B_POSITION_PLAYER_RIGHT
|| GetBattlerPosition(gActiveBattler) == B_POSITION_OPPONENT_RIGHT)
{
BtlController_EmitDrawTrainerPic(BUFFER_A);
BtlController_EmitDrawTrainerPic(B_COMM_TO_CONTROLLER);
MarkBattlerForControllerExec(gActiveBattler);
}
}
if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS && GetBattlerPosition(gActiveBattler) == B_POSITION_OPPONENT_RIGHT)
{
BtlController_EmitDrawTrainerPic(BUFFER_A);
BtlController_EmitDrawTrainerPic(B_COMM_TO_CONTROLLER);
MarkBattlerForControllerExec(gActiveBattler);
}
@@ -3513,7 +3513,7 @@ static void BattleIntroDrawPartySummaryScreens(void)
}
}
gActiveBattler = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT);
BtlController_EmitDrawPartyStatusSummary(BUFFER_A, hpStatus, PARTY_SUMM_SKIP_DRAW_DELAY);
BtlController_EmitDrawPartyStatusSummary(B_COMM_TO_CONTROLLER, hpStatus, PARTY_SUMM_SKIP_DRAW_DELAY);
MarkBattlerForControllerExec(gActiveBattler);
for (i = 0; i < PARTY_SIZE; i++)
@@ -3531,7 +3531,7 @@ static void BattleIntroDrawPartySummaryScreens(void)
}
}
gActiveBattler = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT);
BtlController_EmitDrawPartyStatusSummary(BUFFER_A, hpStatus, PARTY_SUMM_SKIP_DRAW_DELAY);
BtlController_EmitDrawPartyStatusSummary(B_COMM_TO_CONTROLLER, hpStatus, PARTY_SUMM_SKIP_DRAW_DELAY);
MarkBattlerForControllerExec(gActiveBattler);
gBattleMainFunc = BattleIntroPrintTrainerWantsToBattle;
@@ -3631,7 +3631,7 @@ static void BattleIntroOpponent2SendsOutMonAnimation(void)
{
if (GetBattlerPosition(gActiveBattler) == position)
{
BtlController_EmitIntroTrainerBallThrow(BUFFER_A);
BtlController_EmitIntroTrainerBallThrow(B_COMM_TO_CONTROLLER);
MarkBattlerForControllerExec(gActiveBattler);
}
}
@@ -3669,7 +3669,7 @@ static void BattleIntroOpponent1SendsOutMonAnimation(void)
{
if (GetBattlerPosition(gActiveBattler) == position)
{
BtlController_EmitIntroTrainerBallThrow(BUFFER_A);
BtlController_EmitIntroTrainerBallThrow(B_COMM_TO_CONTROLLER);
MarkBattlerForControllerExec(gActiveBattler);
if (gBattleTypeFlags & (BATTLE_TYPE_MULTI | BATTLE_TYPE_TWO_OPPONENTS))
{
@@ -3761,7 +3761,7 @@ static void BattleIntroPlayer2SendsOutMonAnimation(void)
{
if (GetBattlerPosition(gActiveBattler) == position)
{
BtlController_EmitIntroTrainerBallThrow(BUFFER_A);
BtlController_EmitIntroTrainerBallThrow(B_COMM_TO_CONTROLLER);
MarkBattlerForControllerExec(gActiveBattler);
}
}
@@ -3800,7 +3800,7 @@ static void BattleIntroPlayer1SendsOutMonAnimation(void)
{
if (GetBattlerPosition(gActiveBattler) == position)
{
BtlController_EmitIntroTrainerBallThrow(BUFFER_A);
BtlController_EmitIntroTrainerBallThrow(B_COMM_TO_CONTROLLER);
MarkBattlerForControllerExec(gActiveBattler);
if (gBattleTypeFlags & (BATTLE_TYPE_MULTI))
{
@@ -3825,7 +3825,7 @@ static void UNUSED BattleIntroSwitchInPlayerMons(void)
{
if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER)
{
BtlController_EmitSwitchInAnim(BUFFER_A, gBattlerPartyIndexes[gActiveBattler], FALSE);
BtlController_EmitSwitchInAnim(B_COMM_TO_CONTROLLER, gBattlerPartyIndexes[gActiveBattler], FALSE);
MarkBattlerForControllerExec(gActiveBattler);
}
}
@@ -4165,7 +4165,7 @@ static void HandleTurnActionSelectionState(void)
}
else
{
BtlController_EmitChooseAction(BUFFER_A, gChosenActionByBattler[0], gBattleBufferB[0][1] | (gBattleBufferB[0][2] << 8));
BtlController_EmitChooseAction(B_COMM_TO_CONTROLLER, gChosenActionByBattler[0], gBattleBufferB[0][1] | (gBattleBufferB[0][2] << 8));
MarkBattlerForControllerExec(gActiveBattler);
gBattleCommunication[gActiveBattler]++;
}
@@ -4173,7 +4173,7 @@ static void HandleTurnActionSelectionState(void)
}
break;
case STATE_WAIT_ACTION_CHOSEN: // Try to perform an action.
if (!(gBattleControllerExecFlags & ((gBitTable[gActiveBattler]) | (0xF << 28) | (gBitTable[gActiveBattler] << 4) | (gBitTable[gActiveBattler] << 8) | (gBitTable[gActiveBattler] << 12))))
if (!IS_BATTLE_CONTROLLER_ACTIVE_OR_PENDING_SYNC_ANYWHERE(gActiveBattler))
{
RecordedBattle_SetBattlerAction(gActiveBattler, gBattleBufferB[gActiveBattler][1]);
gChosenActionByBattler[gActiveBattler] = gBattleBufferB[gActiveBattler][1];
@@ -4214,7 +4214,7 @@ static void HandleTurnActionSelectionState(void)
i);
}
BtlController_EmitChooseMove(BUFFER_A, (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) != 0, FALSE, &moveInfo);
BtlController_EmitChooseMove(B_COMM_TO_CONTROLLER, (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) != 0, FALSE, &moveInfo);
MarkBattlerForControllerExec(gActiveBattler);
}
break;
@@ -4233,7 +4233,7 @@ static void HandleTurnActionSelectionState(void)
}
else
{
BtlController_EmitChooseItem(BUFFER_A, gBattleStruct->battlerPartyOrders[gActiveBattler]);
BtlController_EmitChooseItem(B_COMM_TO_CONTROLLER, gBattleStruct->battlerPartyOrders[gActiveBattler]);
MarkBattlerForControllerExec(gActiveBattler);
}
break;
@@ -4243,7 +4243,7 @@ static void HandleTurnActionSelectionState(void)
|| gBattleTypeFlags & BATTLE_TYPE_ARENA
|| gStatuses3[gActiveBattler] & STATUS3_ROOTED)
{
BtlController_EmitChoosePokemon(BUFFER_A, PARTY_ACTION_CANT_SWITCH, PARTY_SIZE, ABILITY_NONE, gBattleStruct->battlerPartyOrders[gActiveBattler]);
BtlController_EmitChoosePokemon(B_COMM_TO_CONTROLLER, PARTY_ACTION_CANT_SWITCH, PARTY_SIZE, ABILITY_NONE, gBattleStruct->battlerPartyOrders[gActiveBattler]);
}
else if ((i = ABILITY_ON_OPPOSING_FIELD(gActiveBattler, ABILITY_SHADOW_TAG))
|| ((i = ABILITY_ON_OPPOSING_FIELD(gActiveBattler, ABILITY_ARENA_TRAP))
@@ -4252,16 +4252,16 @@ static void HandleTurnActionSelectionState(void)
|| ((i = AbilityBattleEffects(ABILITYEFFECT_CHECK_FIELD_EXCEPT_BATTLER, gActiveBattler, ABILITY_MAGNET_PULL, 0, 0))
&& IS_BATTLER_OF_TYPE(gActiveBattler, TYPE_STEEL)))
{
BtlController_EmitChoosePokemon(BUFFER_A, ((i - 1) << 4) | PARTY_ACTION_ABILITY_PREVENTS, PARTY_SIZE, gLastUsedAbility, gBattleStruct->battlerPartyOrders[gActiveBattler]);
BtlController_EmitChoosePokemon(B_COMM_TO_CONTROLLER, ((i - 1) << 4) | PARTY_ACTION_ABILITY_PREVENTS, PARTY_SIZE, gLastUsedAbility, gBattleStruct->battlerPartyOrders[gActiveBattler]);
}
else
{
if (gActiveBattler == 2 && gChosenActionByBattler[0] == B_ACTION_SWITCH)
BtlController_EmitChoosePokemon(BUFFER_A, PARTY_ACTION_CHOOSE_MON, *(gBattleStruct->monToSwitchIntoId + 0), ABILITY_NONE, gBattleStruct->battlerPartyOrders[gActiveBattler]);
BtlController_EmitChoosePokemon(B_COMM_TO_CONTROLLER, PARTY_ACTION_CHOOSE_MON, *(gBattleStruct->monToSwitchIntoId + 0), ABILITY_NONE, gBattleStruct->battlerPartyOrders[gActiveBattler]);
else if (gActiveBattler == 3 && gChosenActionByBattler[1] == B_ACTION_SWITCH)
BtlController_EmitChoosePokemon(BUFFER_A, PARTY_ACTION_CHOOSE_MON, *(gBattleStruct->monToSwitchIntoId + 1), ABILITY_NONE, gBattleStruct->battlerPartyOrders[gActiveBattler]);
BtlController_EmitChoosePokemon(B_COMM_TO_CONTROLLER, PARTY_ACTION_CHOOSE_MON, *(gBattleStruct->monToSwitchIntoId + 1), ABILITY_NONE, gBattleStruct->battlerPartyOrders[gActiveBattler]);
else
BtlController_EmitChoosePokemon(BUFFER_A, PARTY_ACTION_CHOOSE_MON, PARTY_SIZE, ABILITY_NONE, gBattleStruct->battlerPartyOrders[gActiveBattler]);
BtlController_EmitChoosePokemon(B_COMM_TO_CONTROLLER, PARTY_ACTION_CHOOSE_MON, PARTY_SIZE, ABILITY_NONE, gBattleStruct->battlerPartyOrders[gActiveBattler]);
}
MarkBattlerForControllerExec(gActiveBattler);
break;
@@ -4276,7 +4276,7 @@ static void HandleTurnActionSelectionState(void)
}
break;
case B_ACTION_SAFARI_POKEBLOCK:
BtlController_EmitChooseItem(BUFFER_A, gBattleStruct->battlerPartyOrders[gActiveBattler]);
BtlController_EmitChooseItem(B_COMM_TO_CONTROLLER, gBattleStruct->battlerPartyOrders[gActiveBattler]);
MarkBattlerForControllerExec(gActiveBattler);
break;
case B_ACTION_CANCEL_PARTNER:
@@ -4286,7 +4286,7 @@ static void HandleTurnActionSelectionState(void)
if (gBattleMons[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))].status2 & STATUS2_MULTIPLETURNS
|| gBattleMons[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))].status2 & STATUS2_RECHARGE)
{
BtlController_EmitEndBounceEffect(BUFFER_A);
BtlController_EmitEndBounceEffect(B_COMM_TO_CONTROLLER);
MarkBattlerForControllerExec(gActiveBattler);
return;
}
@@ -4314,7 +4314,7 @@ static void HandleTurnActionSelectionState(void)
{
RecordedBattle_ClearBattlerAction(GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler))), 3);
}
BtlController_EmitEndBounceEffect(BUFFER_A);
BtlController_EmitEndBounceEffect(B_COMM_TO_CONTROLLER);
MarkBattlerForControllerExec(gActiveBattler);
return;
}
@@ -4352,7 +4352,7 @@ static void HandleTurnActionSelectionState(void)
}
break;
case STATE_WAIT_ACTION_CASE_CHOSEN:
if (!(gBattleControllerExecFlags & ((gBitTable[gActiveBattler]) | (0xF << 28) | (gBitTable[gActiveBattler] << 4) | (gBitTable[gActiveBattler] << 8) | (gBitTable[gActiveBattler] << 12))))
if (!IS_BATTLE_CONTROLLER_ACTIVE_OR_PENDING_SYNC_ANYWHERE(gActiveBattler))
{
switch (gChosenActionByBattler[gActiveBattler])
{
@@ -4456,11 +4456,7 @@ static void HandleTurnActionSelectionState(void)
}
break;
case STATE_WAIT_ACTION_CONFIRMED_STANDBY:
if (!(gBattleControllerExecFlags & ((gBitTable[gActiveBattler])
| (0xF << 28)
| (gBitTable[gActiveBattler] << 4)
| (gBitTable[gActiveBattler] << 8)
| (gBitTable[gActiveBattler] << 12))))
if (!IS_BATTLE_CONTROLLER_ACTIVE_OR_PENDING_SYNC_ANYWHERE(gActiveBattler))
{
if (AllAtActionConfirmed())
i = TRUE;
@@ -4471,18 +4467,18 @@ static void HandleTurnActionSelectionState(void)
|| (position & BIT_FLANK) != B_FLANK_LEFT
|| (*(&gBattleStruct->absentBattlerFlags) & gBitTable[GetBattlerAtPosition(BATTLE_PARTNER(position))]))
{
BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_STOP_BOUNCE, i);
BtlController_EmitLinkStandbyMsg(B_COMM_TO_CONTROLLER, LINK_STANDBY_MSG_STOP_BOUNCE, i);
}
else
{
BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_STOP_BOUNCE_ONLY, i);
BtlController_EmitLinkStandbyMsg(B_COMM_TO_CONTROLLER, LINK_STANDBY_STOP_BOUNCE_ONLY, i);
}
MarkBattlerForControllerExec(gActiveBattler);
gBattleCommunication[gActiveBattler]++;
}
break;
case STATE_WAIT_ACTION_CONFIRMED:
if (!(gBattleControllerExecFlags & ((gBitTable[gActiveBattler]) | (0xF << 28) | (gBitTable[gActiveBattler] << 4) | (gBitTable[gActiveBattler] << 8) | (gBitTable[gActiveBattler] << 12))))
if (!IS_BATTLE_CONTROLLER_ACTIVE_OR_PENDING_SYNC_ANYWHERE(gActiveBattler))
{
gBattleCommunication[ACTIONS_CONFIRMED_COUNT]++;
}
@@ -4496,7 +4492,7 @@ static void HandleTurnActionSelectionState(void)
{
gBattlerAttacker = gActiveBattler;
gBattlescriptCurrInstr = gSelectionBattleScripts[gActiveBattler];
if (!(gBattleControllerExecFlags & ((gBitTable[gActiveBattler]) | (0xF << 28) | (gBitTable[gActiveBattler] << 4) | (gBitTable[gActiveBattler] << 8) | (gBitTable[gActiveBattler] << 12))))
if (!IS_BATTLE_CONTROLLER_ACTIVE_OR_PENDING_SYNC_ANYWHERE(gActiveBattler))
{
gBattleScriptingCommandsTable[gBattlescriptCurrInstr[0]]();
}
@@ -4504,7 +4500,7 @@ static void HandleTurnActionSelectionState(void)
}
break;
case STATE_WAIT_SET_BEFORE_ACTION:
if (!(gBattleControllerExecFlags & ((gBitTable[gActiveBattler]) | (0xF << 28) | (gBitTable[gActiveBattler] << 4) | (gBitTable[gActiveBattler] << 8) | (gBitTable[gActiveBattler] << 12))))
if (!IS_BATTLE_CONTROLLER_ACTIVE_OR_PENDING_SYNC_ANYWHERE(gActiveBattler))
{
gBattleCommunication[gActiveBattler] = STATE_BEFORE_ACTION_CHOSEN;
}
@@ -4528,7 +4524,7 @@ static void HandleTurnActionSelectionState(void)
{
gBattlerAttacker = gActiveBattler;
gBattlescriptCurrInstr = gSelectionBattleScripts[gActiveBattler];
if (!(gBattleControllerExecFlags & ((gBitTable[gActiveBattler]) | (0xF << 28) | (gBitTable[gActiveBattler] << 4) | (gBitTable[gActiveBattler] << 8) | (gBitTable[gActiveBattler] << 12))))
if (!IS_BATTLE_CONTROLLER_ACTIVE_OR_PENDING_SYNC_ANYWHERE(gActiveBattler))
{
gBattleScriptingCommandsTable[gBattlescriptCurrInstr[0]]();
}

View File

@@ -1239,7 +1239,7 @@ static void Cmd_ppreduce(void)
if (MOVE_IS_PERMANENT(gBattlerAttacker, gCurrMovePos))
{
gActiveBattler = gBattlerAttacker;
BtlController_EmitSetMonData(BUFFER_A, REQUEST_PPMOVE1_BATTLE + gCurrMovePos, 0,
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, REQUEST_PPMOVE1_BATTLE + gCurrMovePos, 0,
sizeof(gBattleMons[gBattlerAttacker].pp[gCurrMovePos]),
&gBattleMons[gBattlerAttacker].pp[gCurrMovePos]);
MarkBattlerForControllerExec(gBattlerAttacker);
@@ -1784,7 +1784,7 @@ static void Cmd_attackanimation(void)
multihit = gMultiHitCounter;
}
BtlController_EmitMoveAnimation(BUFFER_A, gCurrentMove, gBattleScripting.animTurn, gBattleMovePower, gBattleMoveDamage, gBattleMons[gBattlerAttacker].friendship, &gDisableStructs[gBattlerAttacker], multihit);
BtlController_EmitMoveAnimation(B_COMM_TO_CONTROLLER, gCurrentMove, gBattleScripting.animTurn, gBattleMovePower, gBattleMoveDamage, gBattleMons[gBattlerAttacker].friendship, &gDisableStructs[gBattlerAttacker], multihit);
gBattleScripting.animTurn++;
gBattleScripting.animTargetsHit++;
MarkBattlerForControllerExec(gBattlerAttacker);
@@ -1829,7 +1829,7 @@ static void Cmd_healthbarupdate(void)
else
healthValue = maxPossibleDmgValue;
BtlController_EmitHealthBarUpdate(BUFFER_A, healthValue);
BtlController_EmitHealthBarUpdate(B_COMM_TO_CONTROLLER, healthValue);
MarkBattlerForControllerExec(gActiveBattler);
if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER && gBattleMoveDamage > 0)
@@ -1971,7 +1971,7 @@ static void Cmd_datahpupdate(void)
gHitMarker &= ~HITMARKER_PASSIVE_DAMAGE;
// Send updated HP
BtlController_EmitSetMonData(BUFFER_A, REQUEST_HP_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].hp), &gBattleMons[gActiveBattler].hp);
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, REQUEST_HP_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].hp), &gBattleMons[gActiveBattler].hp);
MarkBattlerForControllerExec(gActiveBattler);
}
}
@@ -2009,11 +2009,11 @@ static void Cmd_effectivenesssound(void)
switch (gMoveResultFlags & (u8)(~MOVE_RESULT_MISSED))
{
case MOVE_RESULT_SUPER_EFFECTIVE:
BtlController_EmitPlaySE(BUFFER_A, SE_SUPER_EFFECTIVE);
BtlController_EmitPlaySE(B_COMM_TO_CONTROLLER, SE_SUPER_EFFECTIVE);
MarkBattlerForControllerExec(gActiveBattler);
break;
case MOVE_RESULT_NOT_VERY_EFFECTIVE:
BtlController_EmitPlaySE(BUFFER_A, SE_NOT_EFFECTIVE);
BtlController_EmitPlaySE(B_COMM_TO_CONTROLLER, SE_NOT_EFFECTIVE);
MarkBattlerForControllerExec(gActiveBattler);
break;
case MOVE_RESULT_DOESNT_AFFECT_FOE:
@@ -2026,17 +2026,17 @@ static void Cmd_effectivenesssound(void)
default:
if (gMoveResultFlags & MOVE_RESULT_SUPER_EFFECTIVE)
{
BtlController_EmitPlaySE(BUFFER_A, SE_SUPER_EFFECTIVE);
BtlController_EmitPlaySE(B_COMM_TO_CONTROLLER, SE_SUPER_EFFECTIVE);
MarkBattlerForControllerExec(gActiveBattler);
}
else if (gMoveResultFlags & MOVE_RESULT_NOT_VERY_EFFECTIVE)
{
BtlController_EmitPlaySE(BUFFER_A, SE_NOT_EFFECTIVE);
BtlController_EmitPlaySE(B_COMM_TO_CONTROLLER, SE_NOT_EFFECTIVE);
MarkBattlerForControllerExec(gActiveBattler);
}
else if (!(gMoveResultFlags & (MOVE_RESULT_DOESNT_AFFECT_FOE | MOVE_RESULT_FAILED)))
{
BtlController_EmitPlaySE(BUFFER_A, SE_EFFECTIVE);
BtlController_EmitPlaySE(B_COMM_TO_CONTROLLER, SE_EFFECTIVE);
MarkBattlerForControllerExec(gActiveBattler);
}
break;
@@ -2149,7 +2149,7 @@ static void Cmd_printselectionstring(void)
{
gActiveBattler = gBattlerAttacker;
BtlController_EmitPrintSelectionString(BUFFER_A, T2_READ_16(gBattlescriptCurrInstr + 1));
BtlController_EmitPrintSelectionString(B_COMM_TO_CONTROLLER, T2_READ_16(gBattlescriptCurrInstr + 1));
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr += 3;
@@ -2199,7 +2199,7 @@ static void Cmd_printselectionstringfromtable(void)
ptr += gBattleCommunication[MULTISTRING_CHOOSER];
gActiveBattler = gBattlerAttacker;
BtlController_EmitPrintSelectionString(BUFFER_A, *ptr);
BtlController_EmitPrintSelectionString(B_COMM_TO_CONTROLLER, *ptr);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr += 5;
@@ -2485,7 +2485,7 @@ void SetMoveEffect(bool8 primary, u8 certain)
gBattlescriptCurrInstr = sMoveEffectBS_Ptrs[gBattleCommunication[MOVE_EFFECT_BYTE]];
gActiveBattler = gEffectBattler;
BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gEffectBattler].status1), &gBattleMons[gEffectBattler].status1);
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gEffectBattler].status1), &gBattleMons[gEffectBattler].status1);
MarkBattlerForControllerExec(gActiveBattler);
if (gHitMarker & HITMARKER_STATUS_ABILITY_EFFECT)
@@ -2787,11 +2787,11 @@ void SetMoveEffect(bool8 primary, u8 certain)
gBattleMons[gBattlerTarget].item = ITEM_NONE;
gActiveBattler = gBattlerAttacker;
BtlController_EmitSetMonData(BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gLastUsedItem), &gLastUsedItem);
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, REQUEST_HELDITEM_BATTLE, 0, sizeof(gLastUsedItem), &gLastUsedItem);
MarkBattlerForControllerExec(gBattlerAttacker);
gActiveBattler = gBattlerTarget;
BtlController_EmitSetMonData(BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[gBattlerTarget].item), &gBattleMons[gBattlerTarget].item);
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[gBattlerTarget].item), &gBattleMons[gBattlerTarget].item);
MarkBattlerForControllerExec(gBattlerTarget);
BattleScriptPush(gBattlescriptCurrInstr + 1);
@@ -2829,7 +2829,7 @@ void SetMoveEffect(bool8 primary, u8 certain)
gBattleMons[gBattlerTarget].status1 &= ~STATUS1_PARALYSIS;
gActiveBattler = gBattlerTarget;
BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].status1), &gBattleMons[gActiveBattler].status1);
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].status1), &gBattleMons[gActiveBattler].status1);
MarkBattlerForControllerExec(gActiveBattler);
BattleScriptPush(gBattlescriptCurrInstr + 1);
@@ -3036,7 +3036,7 @@ static void Cmd_tryfaintmon(void)
BattleScriptPush(gBattlescriptCurrInstr);
gBattlescriptCurrInstr = BattleScript_GrudgeTakesPp;
gActiveBattler = gBattlerAttacker;
BtlController_EmitSetMonData(BUFFER_A, moveIndex + REQUEST_PPMOVE1_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].pp[moveIndex]), &gBattleMons[gActiveBattler].pp[moveIndex]);
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, moveIndex + REQUEST_PPMOVE1_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].pp[moveIndex]), &gBattleMons[gActiveBattler].pp[moveIndex]);
MarkBattlerForControllerExec(gActiveBattler);
PREPARE_MOVE_BUFFER(gBattleTextBuff1, gBattleMons[gBattlerAttacker].moves[moveIndex])
@@ -3054,7 +3054,7 @@ static void Cmd_dofaintanimation(void)
if (gBattleControllerExecFlags == 0)
{
gActiveBattler = GetBattlerForBattleScript(gBattlescriptCurrInstr[1]);
BtlController_EmitFaintAnimation(BUFFER_A);
BtlController_EmitFaintAnimation(B_COMM_TO_CONTROLLER);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr += 2;
}
@@ -3069,7 +3069,7 @@ static void Cmd_cleareffectsonfaint(void)
if (!(gBattleTypeFlags & BATTLE_TYPE_ARENA) || gBattleMons[gActiveBattler].hp == 0)
{
gBattleMons[gActiveBattler].status1 = 0;
BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].status1), &gBattleMons[gActiveBattler].status1);
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].status1), &gBattleMons[gActiveBattler].status1);
MarkBattlerForControllerExec(gActiveBattler);
}
@@ -3438,7 +3438,7 @@ static void Cmd_getexp(void)
gBattleResources->beforeLvlUp->stats[STAT_SPDEF] = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_SPDEF);
gActiveBattler = gBattleStruct->expGetterBattlerId;
BtlController_EmitExpUpdate(BUFFER_A, gBattleStruct->expGetterMonId, gBattleMoveDamage);
BtlController_EmitExpUpdate(B_COMM_TO_CONTROLLER, gBattleStruct->expGetterMonId, gBattleMoveDamage);
MarkBattlerForControllerExec(gActiveBattler);
}
gBattleScripting.getexpState++;
@@ -3937,7 +3937,7 @@ static void Cmd_healthbar_update(void)
else
gActiveBattler = gBattlerAttacker;
BtlController_EmitHealthBarUpdate(BUFFER_A, gBattleMoveDamage);
BtlController_EmitHealthBarUpdate(B_COMM_TO_CONTROLLER, gBattleMoveDamage);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr += 2;
}
@@ -4012,7 +4012,7 @@ static void Cmd_playanimation(void)
|| gBattlescriptCurrInstr[2] == B_ANIM_SNATCH_MOVE
|| gBattlescriptCurrInstr[2] == B_ANIM_SUBSTITUTE_FADE)
{
BtlController_EmitBattleAnimation(BUFFER_A, gBattlescriptCurrInstr[2], *argumentPtr);
BtlController_EmitBattleAnimation(B_COMM_TO_CONTROLLER, gBattlescriptCurrInstr[2], *argumentPtr);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr += 7;
}
@@ -4026,7 +4026,7 @@ static void Cmd_playanimation(void)
|| gBattlescriptCurrInstr[2] == B_ANIM_SANDSTORM_CONTINUES
|| gBattlescriptCurrInstr[2] == B_ANIM_HAIL_CONTINUES)
{
BtlController_EmitBattleAnimation(BUFFER_A, gBattlescriptCurrInstr[2], *argumentPtr);
BtlController_EmitBattleAnimation(B_COMM_TO_CONTROLLER, gBattlescriptCurrInstr[2], *argumentPtr);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr += 7;
}
@@ -4036,7 +4036,7 @@ static void Cmd_playanimation(void)
}
else
{
BtlController_EmitBattleAnimation(BUFFER_A, gBattlescriptCurrInstr[2], *argumentPtr);
BtlController_EmitBattleAnimation(B_COMM_TO_CONTROLLER, gBattlescriptCurrInstr[2], *argumentPtr);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr += 7;
}
@@ -4056,7 +4056,7 @@ static void Cmd_playanimation_var(void)
|| *animationIdPtr == B_ANIM_SNATCH_MOVE
|| *animationIdPtr == B_ANIM_SUBSTITUTE_FADE)
{
BtlController_EmitBattleAnimation(BUFFER_A, *animationIdPtr, *argumentPtr);
BtlController_EmitBattleAnimation(B_COMM_TO_CONTROLLER, *animationIdPtr, *argumentPtr);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr += 10;
}
@@ -4069,7 +4069,7 @@ static void Cmd_playanimation_var(void)
|| *animationIdPtr == B_ANIM_SANDSTORM_CONTINUES
|| *animationIdPtr == B_ANIM_HAIL_CONTINUES)
{
BtlController_EmitBattleAnimation(BUFFER_A, *animationIdPtr, *argumentPtr);
BtlController_EmitBattleAnimation(B_COMM_TO_CONTROLLER, *animationIdPtr, *argumentPtr);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr += 10;
}
@@ -4079,7 +4079,7 @@ static void Cmd_playanimation_var(void)
}
else
{
BtlController_EmitBattleAnimation(BUFFER_A, *animationIdPtr, *argumentPtr);
BtlController_EmitBattleAnimation(B_COMM_TO_CONTROLLER, *animationIdPtr, *argumentPtr);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr += 10;
}
@@ -4195,7 +4195,7 @@ static void Cmd_playstatchangeanimation(void)
}
else if (changeableStatsCount != 0 && !gBattleScripting.statAnimPlayed)
{
BtlController_EmitBattleAnimation(BUFFER_A, B_ANIM_STATS_CHANGE, statAnimId);
BtlController_EmitBattleAnimation(B_COMM_TO_CONTROLLER, B_ANIM_STATS_CHANGE, statAnimId);
MarkBattlerForControllerExec(gActiveBattler);
if (gBattlescriptCurrInstr[3] & STAT_CHANGE_MULTIPLE_STATS && changeableStatsCount > 1)
gBattleScripting.statAnimPlayed = TRUE;
@@ -4264,7 +4264,7 @@ static void Cmd_moveend(void)
{
gBattleMons[gBattlerTarget].status1 &= ~STATUS1_FREEZE;
gActiveBattler = gBattlerTarget;
BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gBattlerTarget].status1), &gBattleMons[gBattlerTarget].status1);
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gBattlerTarget].status1), &gBattleMons[gBattlerTarget].status1);
MarkBattlerForControllerExec(gActiveBattler);
BattleScriptPushCursor();
gBattlescriptCurrInstr = BattleScript_DefrostedViaFireMove;
@@ -4343,7 +4343,7 @@ static void Cmd_moveend(void)
&& gHitMarker & HITMARKER_NO_ANIMATIONS)
{
gActiveBattler = gBattlerAttacker;
BtlController_EmitSpriteInvisibility(BUFFER_A, TRUE);
BtlController_EmitSpriteInvisibility(B_COMM_TO_CONTROLLER, TRUE);
MarkBattlerForControllerExec(gActiveBattler);
gBattleScripting.moveendState++;
return;
@@ -4356,7 +4356,7 @@ static void Cmd_moveend(void)
|| WasUnableToUseMove(gBattlerAttacker))
{
gActiveBattler = gBattlerAttacker;
BtlController_EmitSpriteInvisibility(BUFFER_A, FALSE);
BtlController_EmitSpriteInvisibility(B_COMM_TO_CONTROLLER, FALSE);
MarkBattlerForControllerExec(gActiveBattler);
gStatuses3[gBattlerAttacker] &= ~STATUS3_SEMI_INVULNERABLE;
gSpecialStatuses[gBattlerAttacker].restoredBattlerSprite = 1;
@@ -4370,7 +4370,7 @@ static void Cmd_moveend(void)
&& !(gStatuses3[gBattlerTarget] & STATUS3_SEMI_INVULNERABLE))
{
gActiveBattler = gBattlerTarget;
BtlController_EmitSpriteInvisibility(BUFFER_A, FALSE);
BtlController_EmitSpriteInvisibility(B_COMM_TO_CONTROLLER, FALSE);
MarkBattlerForControllerExec(gActiveBattler);
gStatuses3[gBattlerTarget] &= ~STATUS3_SEMI_INVULNERABLE;
gBattleScripting.moveendState++;
@@ -4597,7 +4597,7 @@ static void Cmd_returnatktoball(void)
gActiveBattler = gBattlerAttacker;
if (!(gHitMarker & HITMARKER_FAINTED(gActiveBattler)))
{
BtlController_EmitReturnMonToBall(BUFFER_A, FALSE);
BtlController_EmitReturnMonToBall(B_COMM_TO_CONTROLLER, FALSE);
MarkBattlerForControllerExec(gActiveBattler);
}
gBattlescriptCurrInstr++;
@@ -4612,7 +4612,7 @@ static void Cmd_getswitchedmondata(void)
gBattlerPartyIndexes[gActiveBattler] = *(gBattleStruct->monToSwitchIntoId + gActiveBattler);
BtlController_EmitGetMonData(BUFFER_A, REQUEST_ALL_BATTLE, gBitTable[gBattlerPartyIndexes[gActiveBattler]]);
BtlController_EmitGetMonData(B_COMM_TO_CONTROLLER, REQUEST_ALL_BATTLE, gBitTable[gBattlerPartyIndexes[gActiveBattler]]);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr += 2;
@@ -4688,7 +4688,7 @@ static void Cmd_switchinanim(void)
gAbsentBattlerFlags &= ~(gBitTable[gActiveBattler]);
BtlController_EmitSwitchInAnim(BUFFER_A, gBattlerPartyIndexes[gActiveBattler], gBattlescriptCurrInstr[2]);
BtlController_EmitSwitchInAnim(B_COMM_TO_CONTROLLER, gBattlerPartyIndexes[gActiveBattler], gBattlescriptCurrInstr[2]);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr += 3;
@@ -4858,7 +4858,7 @@ static void ChooseMonToSendOut(u8 slotId)
*(gBattleStruct->monToSwitchIntoId + gActiveBattler) = PARTY_SIZE;
gBattleStruct->field_93 &= ~(gBitTable[gActiveBattler]);
BtlController_EmitChoosePokemon(BUFFER_A, PARTY_ACTION_SEND_OUT, slotId, ABILITY_NONE, gBattleStruct->battlerPartyOrders[gActiveBattler]);
BtlController_EmitChoosePokemon(B_COMM_TO_CONTROLLER, PARTY_ACTION_SEND_OUT, slotId, ABILITY_NONE, gBattleStruct->battlerPartyOrders[gActiveBattler]);
MarkBattlerForControllerExec(gActiveBattler);
}
@@ -4885,7 +4885,7 @@ static void Cmd_openpartyscreen(void)
{
gAbsentBattlerFlags |= gBitTable[gActiveBattler];
gHitMarker &= ~HITMARKER_FAINTED(gActiveBattler);
BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE);
BtlController_EmitLinkStandbyMsg(B_COMM_TO_CONTROLLER, LINK_STANDBY_MSG_ONLY, FALSE);
MarkBattlerForControllerExec(gActiveBattler);
}
else if (!gSpecialStatuses[gActiveBattler].faintedHasReplacement)
@@ -4896,7 +4896,7 @@ static void Cmd_openpartyscreen(void)
}
else
{
BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE);
BtlController_EmitLinkStandbyMsg(B_COMM_TO_CONTROLLER, LINK_STANDBY_MSG_ONLY, FALSE);
MarkBattlerForControllerExec(gActiveBattler);
}
}
@@ -4914,7 +4914,7 @@ static void Cmd_openpartyscreen(void)
{
gAbsentBattlerFlags |= gBitTable[gActiveBattler];
gHitMarker &= ~HITMARKER_FAINTED(gActiveBattler);
BtlController_EmitCantSwitch(BUFFER_A);
BtlController_EmitCantSwitch(B_COMM_TO_CONTROLLER);
MarkBattlerForControllerExec(gActiveBattler);
}
else if (!gSpecialStatuses[gActiveBattler].faintedHasReplacement)
@@ -4924,7 +4924,7 @@ static void Cmd_openpartyscreen(void)
}
else
{
BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE);
BtlController_EmitLinkStandbyMsg(B_COMM_TO_CONTROLLER, LINK_STANDBY_MSG_ONLY, FALSE);
MarkBattlerForControllerExec(gActiveBattler);
flags |= 1;
}
@@ -4936,7 +4936,7 @@ static void Cmd_openpartyscreen(void)
{
gAbsentBattlerFlags |= gBitTable[gActiveBattler];
gHitMarker &= ~HITMARKER_FAINTED(gActiveBattler);
BtlController_EmitCantSwitch(BUFFER_A);
BtlController_EmitCantSwitch(B_COMM_TO_CONTROLLER);
MarkBattlerForControllerExec(gActiveBattler);
}
else if (!gSpecialStatuses[gActiveBattler].faintedHasReplacement)
@@ -4946,7 +4946,7 @@ static void Cmd_openpartyscreen(void)
}
else if (!(flags & 1))
{
BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE);
BtlController_EmitLinkStandbyMsg(B_COMM_TO_CONTROLLER, LINK_STANDBY_MSG_ONLY, FALSE);
MarkBattlerForControllerExec(gActiveBattler);
}
}
@@ -4957,7 +4957,7 @@ static void Cmd_openpartyscreen(void)
{
gAbsentBattlerFlags |= gBitTable[gActiveBattler];
gHitMarker &= ~HITMARKER_FAINTED(gActiveBattler);
BtlController_EmitCantSwitch(BUFFER_A);
BtlController_EmitCantSwitch(B_COMM_TO_CONTROLLER);
MarkBattlerForControllerExec(gActiveBattler);
}
else if (!gSpecialStatuses[gActiveBattler].faintedHasReplacement)
@@ -4967,7 +4967,7 @@ static void Cmd_openpartyscreen(void)
}
else
{
BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE);
BtlController_EmitLinkStandbyMsg(B_COMM_TO_CONTROLLER, LINK_STANDBY_MSG_ONLY, FALSE);
MarkBattlerForControllerExec(gActiveBattler);
flags |= 2;
}
@@ -4979,7 +4979,7 @@ static void Cmd_openpartyscreen(void)
{
gAbsentBattlerFlags |= gBitTable[gActiveBattler];
gHitMarker &= ~HITMARKER_FAINTED(gActiveBattler);
BtlController_EmitCantSwitch(BUFFER_A);
BtlController_EmitCantSwitch(B_COMM_TO_CONTROLLER);
MarkBattlerForControllerExec(gActiveBattler);
}
else if (!gSpecialStatuses[gActiveBattler].faintedHasReplacement)
@@ -4989,7 +4989,7 @@ static void Cmd_openpartyscreen(void)
}
else if (!(flags & 2))
{
BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE);
BtlController_EmitLinkStandbyMsg(B_COMM_TO_CONTROLLER, LINK_STANDBY_MSG_ONLY, FALSE);
MarkBattlerForControllerExec(gActiveBattler);
}
}
@@ -5005,7 +5005,7 @@ static void Cmd_openpartyscreen(void)
else
gActiveBattler = 0;
BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE);
BtlController_EmitLinkStandbyMsg(B_COMM_TO_CONTROLLER, LINK_STANDBY_MSG_ONLY, FALSE);
MarkBattlerForControllerExec(gActiveBattler);
}
@@ -5021,7 +5021,7 @@ static void Cmd_openpartyscreen(void)
else
gActiveBattler = 1;
BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE);
BtlController_EmitLinkStandbyMsg(B_COMM_TO_CONTROLLER, LINK_STANDBY_MSG_ONLY, FALSE);
MarkBattlerForControllerExec(gActiveBattler);
}
}
@@ -5042,7 +5042,7 @@ static void Cmd_openpartyscreen(void)
{
gAbsentBattlerFlags |= gBitTable[gActiveBattler];
gHitMarker &= ~HITMARKER_FAINTED(gActiveBattler);
BtlController_EmitCantSwitch(BUFFER_A);
BtlController_EmitCantSwitch(B_COMM_TO_CONTROLLER);
MarkBattlerForControllerExec(gActiveBattler);
}
else if (!gSpecialStatuses[gActiveBattler].faintedHasReplacement)
@@ -5058,7 +5058,7 @@ static void Cmd_openpartyscreen(void)
{
gAbsentBattlerFlags |= gBitTable[gActiveBattler];
gHitMarker &= ~HITMARKER_FAINTED(gActiveBattler);
BtlController_EmitCantSwitch(BUFFER_A);
BtlController_EmitCantSwitch(B_COMM_TO_CONTROLLER);
MarkBattlerForControllerExec(gActiveBattler);
}
else if (!gSpecialStatuses[gActiveBattler].faintedHasReplacement)
@@ -5117,7 +5117,7 @@ static void Cmd_openpartyscreen(void)
*(gBattleStruct->monToSwitchIntoId + gActiveBattler) = PARTY_SIZE;
gBattleStruct->field_93 &= ~(gBitTable[gActiveBattler]);
BtlController_EmitChoosePokemon(BUFFER_A, hitmarkerFaintBits, *(gBattleStruct->monToSwitchIntoId + BATTLE_PARTNER(gActiveBattler)), ABILITY_NONE, gBattleStruct->battlerPartyOrders[gActiveBattler]);
BtlController_EmitChoosePokemon(B_COMM_TO_CONTROLLER, hitmarkerFaintBits, *(gBattleStruct->monToSwitchIntoId + BATTLE_PARTNER(gActiveBattler)), ABILITY_NONE, gBattleStruct->battlerPartyOrders[gActiveBattler]);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr += 6;
@@ -5131,7 +5131,7 @@ static void Cmd_openpartyscreen(void)
{
if (gActiveBattler != battlerId)
{
BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE);
BtlController_EmitLinkStandbyMsg(B_COMM_TO_CONTROLLER, LINK_STANDBY_MSG_ONLY, FALSE);
MarkBattlerForControllerExec(gActiveBattler);
}
}
@@ -5142,7 +5142,7 @@ static void Cmd_openpartyscreen(void)
if (gAbsentBattlerFlags & gBitTable[gActiveBattler])
gActiveBattler ^= BIT_FLANK;
BtlController_EmitLinkStandbyMsg(BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE);
BtlController_EmitLinkStandbyMsg(B_COMM_TO_CONTROLLER, LINK_STANDBY_MSG_ONLY, FALSE);
MarkBattlerForControllerExec(gActiveBattler);
}
}
@@ -5301,7 +5301,7 @@ static void Cmd_switchineffects(void)
static void Cmd_trainerslidein(void)
{
gActiveBattler = GetBattlerAtPosition(gBattlescriptCurrInstr[1]);
BtlController_EmitTrainerSlide(BUFFER_A);
BtlController_EmitTrainerSlide(B_COMM_TO_CONTROLLER);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr += 2;
@@ -5310,7 +5310,7 @@ static void Cmd_trainerslidein(void)
static void Cmd_playse(void)
{
gActiveBattler = gBattlerAttacker;
BtlController_EmitPlaySE(BUFFER_A, T2_READ_16(gBattlescriptCurrInstr + 1));
BtlController_EmitPlaySE(B_COMM_TO_CONTROLLER, T2_READ_16(gBattlescriptCurrInstr + 1));
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr += 3;
@@ -5319,7 +5319,7 @@ static void Cmd_playse(void)
static void Cmd_fanfare(void)
{
gActiveBattler = gBattlerAttacker;
BtlController_EmitPlayFanfareOrBGM(BUFFER_A, T2_READ_16(gBattlescriptCurrInstr + 1), FALSE);
BtlController_EmitPlayFanfareOrBGM(B_COMM_TO_CONTROLLER, T2_READ_16(gBattlescriptCurrInstr + 1), FALSE);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr += 3;
@@ -5328,7 +5328,7 @@ static void Cmd_fanfare(void)
static void Cmd_playfaintcry(void)
{
gActiveBattler = GetBattlerForBattleScript(gBattlescriptCurrInstr[1]);
BtlController_EmitFaintingCry(BUFFER_A);
BtlController_EmitFaintingCry(B_COMM_TO_CONTROLLER);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr += 2;
@@ -5337,7 +5337,7 @@ static void Cmd_playfaintcry(void)
static void Cmd_endlinkbattle(void)
{
gActiveBattler = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT);
BtlController_EmitEndLinkBattle(BUFFER_A, gBattleOutcome);
BtlController_EmitEndLinkBattle(B_COMM_TO_CONTROLLER, gBattleOutcome);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr += 1;
@@ -5346,7 +5346,7 @@ static void Cmd_endlinkbattle(void)
static void Cmd_returntoball(void)
{
gActiveBattler = GetBattlerForBattleScript(gBattlescriptCurrInstr[1]);
BtlController_EmitReturnMonToBall(BUFFER_A, TRUE);
BtlController_EmitReturnMonToBall(B_COMM_TO_CONTROLLER, TRUE);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr += 2;
@@ -5565,7 +5565,7 @@ static void Cmd_hitanimation(void)
}
else if (!(gHitMarker & HITMARKER_IGNORE_SUBSTITUTE) || !(gBattleMons[gActiveBattler].status2 & STATUS2_SUBSTITUTE) || gDisableStructs[gActiveBattler].substituteHP == 0)
{
BtlController_EmitHitAnimation(BUFFER_A);
BtlController_EmitHitAnimation(B_COMM_TO_CONTROLLER);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr += 2;
}
@@ -5652,7 +5652,7 @@ static void Cmd_updatebattlermoves(void)
switch (gBattleCommunication[0])
{
case 0:
BtlController_EmitGetMonData(BUFFER_A, REQUEST_ALL_BATTLE, 0);
BtlController_EmitGetMonData(B_COMM_TO_CONTROLLER, REQUEST_ALL_BATTLE, 0);
MarkBattlerForControllerExec(gActiveBattler);
gBattleCommunication[0]++;
break;
@@ -5725,7 +5725,7 @@ static void Cmd_drawpartystatussummary(void)
}
}
BtlController_EmitDrawPartyStatusSummary(BUFFER_A, hpStatuses, 1);
BtlController_EmitDrawPartyStatusSummary(B_COMM_TO_CONTROLLER, hpStatuses, 1);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr += 2;
@@ -5734,7 +5734,7 @@ static void Cmd_drawpartystatussummary(void)
static void Cmd_hidepartystatussummary(void)
{
gActiveBattler = GetBattlerForBattleScript(gBattlescriptCurrInstr[1]);
BtlController_EmitHidePartyStatusSummary(BUFFER_A);
BtlController_EmitHidePartyStatusSummary(B_COMM_TO_CONTROLLER);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr += 2;
@@ -5759,7 +5759,7 @@ static void Cmd_statusanimation(void)
&& gDisableStructs[gActiveBattler].substituteHP == 0
&& !(gHitMarker & HITMARKER_NO_ANIMATIONS))
{
BtlController_EmitStatusAnimation(BUFFER_A, FALSE, gBattleMons[gActiveBattler].status1);
BtlController_EmitStatusAnimation(B_COMM_TO_CONTROLLER, FALSE, gBattleMons[gActiveBattler].status1);
MarkBattlerForControllerExec(gActiveBattler);
}
gBattlescriptCurrInstr += 2;
@@ -5778,7 +5778,7 @@ static void Cmd_status2animation(void)
&& gDisableStructs[gActiveBattler].substituteHP == 0
&& !(gHitMarker & HITMARKER_NO_ANIMATIONS))
{
BtlController_EmitStatusAnimation(BUFFER_A, TRUE, gBattleMons[gActiveBattler].status2 & wantedToAnimate);
BtlController_EmitStatusAnimation(B_COMM_TO_CONTROLLER, TRUE, gBattleMons[gActiveBattler].status2 & wantedToAnimate);
MarkBattlerForControllerExec(gActiveBattler);
}
gBattlescriptCurrInstr += 6;
@@ -5797,7 +5797,7 @@ static void Cmd_chosenstatusanimation(void)
&& gDisableStructs[gActiveBattler].substituteHP == 0
&& !(gHitMarker & HITMARKER_NO_ANIMATIONS))
{
BtlController_EmitStatusAnimation(BUFFER_A, gBattlescriptCurrInstr[2], wantedStatus);
BtlController_EmitStatusAnimation(B_COMM_TO_CONTROLLER, gBattlescriptCurrInstr[2], wantedStatus);
MarkBattlerForControllerExec(gActiveBattler);
}
gBattlescriptCurrInstr += 7;
@@ -5908,7 +5908,7 @@ static void Cmd_removeitem(void)
*usedHeldItem = gBattleMons[gActiveBattler].item;
gBattleMons[gActiveBattler].item = ITEM_NONE;
BtlController_EmitSetMonData(BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].item), &gBattleMons[gActiveBattler].item);
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].item), &gBattleMons[gActiveBattler].item);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr += 2;
@@ -6217,7 +6217,7 @@ static void Cmd_setatktoplayer0(void)
static void Cmd_makevisible(void)
{
gActiveBattler = GetBattlerForBattleScript(gBattlescriptCurrInstr[1]);
BtlController_EmitSpriteInvisibility(BUFFER_A, FALSE);
BtlController_EmitSpriteInvisibility(B_COMM_TO_CONTROLLER, FALSE);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr += 2;
@@ -6431,7 +6431,7 @@ static void Cmd_various(void)
gDisableStructs[1].truantSwitchInHack = 1;
break;
case VARIOUS_EMIT_YESNOBOX:
BtlController_EmitYesNoBox(BUFFER_A);
BtlController_EmitYesNoBox(B_COMM_TO_CONTROLLER);
MarkBattlerForControllerExec(gActiveBattler);
break;
case VARIOUS_DRAW_ARENA_REF_TEXT_BOX:
@@ -6456,7 +6456,7 @@ static void Cmd_various(void)
gActiveBattler = 1;
if (gBattleMons[gActiveBattler].hp != 0)
{
BtlController_EmitReturnMonToBall(BUFFER_A, FALSE);
BtlController_EmitReturnMonToBall(B_COMM_TO_CONTROLLER, FALSE);
MarkBattlerForControllerExec(gActiveBattler);
}
break;
@@ -6466,7 +6466,7 @@ static void Cmd_various(void)
gActiveBattler = 3;
if (gBattleMons[gActiveBattler].hp != 0)
{
BtlController_EmitReturnMonToBall(BUFFER_A, FALSE);
BtlController_EmitReturnMonToBall(B_COMM_TO_CONTROLLER, FALSE);
MarkBattlerForControllerExec(gActiveBattler);
}
}
@@ -6491,7 +6491,7 @@ static void Cmd_various(void)
gBattleOutcome = B_OUTCOME_MON_TELEPORTED;
break;
case VARIOUS_PLAY_TRAINER_DEFEATED_MUSIC:
BtlController_EmitPlayFanfareOrBGM(BUFFER_A, MUS_VICTORY_TRAINER, TRUE);
BtlController_EmitPlayFanfareOrBGM(B_COMM_TO_CONTROLLER, MUS_VICTORY_TRAINER, TRUE);
MarkBattlerForControllerExec(gActiveBattler);
break;
}
@@ -6552,7 +6552,7 @@ static void Cmd_tryexplosion(void)
// Success, no battlers with Damp. Drop user's HP bar to 0
gActiveBattler = gBattlerAttacker;
gBattleMoveDamage = gBattleMons[gActiveBattler].hp;
BtlController_EmitHealthBarUpdate(BUFFER_A, INSTANT_HP_BAR_DROP);
BtlController_EmitHealthBarUpdate(B_COMM_TO_CONTROLLER, INSTANT_HP_BAR_DROP);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr++;
@@ -6581,7 +6581,7 @@ static void Cmd_setatkhptozero(void)
gActiveBattler = gBattlerAttacker;
gBattleMons[gActiveBattler].hp = 0;
BtlController_EmitSetMonData(BUFFER_A, REQUEST_HP_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].hp), &gBattleMons[gActiveBattler].hp);
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, REQUEST_HP_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].hp), &gBattleMons[gActiveBattler].hp);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr++;
@@ -6777,7 +6777,7 @@ static void Cmd_trysetrest(void)
gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_REST;
gBattleMons[gBattlerTarget].status1 = STATUS1_SLEEP_TURN(3);
BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].status1), &gBattleMons[gActiveBattler].status1);
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].status1), &gBattleMons[gActiveBattler].status1);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr += 5;
}
@@ -7727,7 +7727,7 @@ static void Cmd_updatestatusicon(void)
if (gBattlescriptCurrInstr[1] != BS_ATTACKER_WITH_PARTNER)
{
gActiveBattler = GetBattlerForBattleScript(gBattlescriptCurrInstr[1]);
BtlController_EmitStatusIconUpdate(BUFFER_A, gBattleMons[gActiveBattler].status1, gBattleMons[gActiveBattler].status2);
BtlController_EmitStatusIconUpdate(B_COMM_TO_CONTROLLER, gBattleMons[gActiveBattler].status1, gBattleMons[gActiveBattler].status2);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr += 2;
}
@@ -7736,7 +7736,7 @@ static void Cmd_updatestatusicon(void)
gActiveBattler = gBattlerAttacker;
if (!(gAbsentBattlerFlags & gBitTable[gActiveBattler]))
{
BtlController_EmitStatusIconUpdate(BUFFER_A, gBattleMons[gActiveBattler].status1, gBattleMons[gActiveBattler].status2);
BtlController_EmitStatusIconUpdate(B_COMM_TO_CONTROLLER, gBattleMons[gActiveBattler].status1, gBattleMons[gActiveBattler].status2);
MarkBattlerForControllerExec(gActiveBattler);
}
if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE))
@@ -7744,7 +7744,7 @@ static void Cmd_updatestatusicon(void)
gActiveBattler = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gBattlerAttacker)));
if (!(gAbsentBattlerFlags & gBitTable[gActiveBattler]))
{
BtlController_EmitStatusIconUpdate(BUFFER_A, gBattleMons[gActiveBattler].status1, gBattleMons[gActiveBattler].status2);
BtlController_EmitStatusIconUpdate(B_COMM_TO_CONTROLLER, gBattleMons[gActiveBattler].status1, gBattleMons[gActiveBattler].status2);
MarkBattlerForControllerExec(gActiveBattler);
}
}
@@ -7822,7 +7822,7 @@ static void Cmd_transformdataexecution(void)
}
gActiveBattler = gBattlerAttacker;
BtlController_EmitResetActionMoveSelection(BUFFER_A, RESET_MOVE_SELECTION);
BtlController_EmitResetActionMoveSelection(B_COMM_TO_CONTROLLER, RESET_MOVE_SELECTION);
MarkBattlerForControllerExec(gActiveBattler);
gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_TRANSFORMED;
}
@@ -8202,7 +8202,7 @@ static void Cmd_copymovepermanently(void)
}
movePpData.ppBonuses = gBattleMons[gBattlerAttacker].ppBonuses;
BtlController_EmitSetMonData(BUFFER_A, REQUEST_MOVES_PP_BATTLE, 0, sizeof(movePpData), &movePpData);
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, REQUEST_MOVES_PP_BATTLE, 0, sizeof(movePpData), &movePpData);
MarkBattlerForControllerExec(gActiveBattler);
PREPARE_MOVE_BUFFER(gBattleTextBuff1, gLastPrintedMoves[gBattlerTarget])
@@ -8370,7 +8370,7 @@ static void Cmd_tryspiteppreduce(void)
if (!(gDisableStructs[gActiveBattler].mimickedMoves & gBitTable[i])
&& !(gBattleMons[gActiveBattler].status2 & STATUS2_TRANSFORMED))
{
BtlController_EmitSetMonData(BUFFER_A, REQUEST_PPMOVE1_BATTLE + i, 0, sizeof(gBattleMons[gActiveBattler].pp[i]), &gBattleMons[gActiveBattler].pp[i]);
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, REQUEST_PPMOVE1_BATTLE + i, 0, sizeof(gBattleMons[gActiveBattler].pp[i]), &gBattleMons[gActiveBattler].pp[i]);
MarkBattlerForControllerExec(gActiveBattler);
}
@@ -8481,7 +8481,7 @@ static void Cmd_healpartystatus(void)
if (toHeal)
{
gActiveBattler = gBattlerAttacker;
BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, toHeal, sizeof(zero), &zero);
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, REQUEST_STATUS_BATTLE, toHeal, sizeof(zero), &zero);
MarkBattlerForControllerExec(gActiveBattler);
}
@@ -9106,7 +9106,7 @@ static void Cmd_trymemento(void)
// Success, drop user's HP bar to 0
gActiveBattler = gBattlerAttacker;
gBattleMoveDamage = gBattleMons[gActiveBattler].hp;
BtlController_EmitHealthBarUpdate(BUFFER_A, INSTANT_HP_BAR_DROP);
BtlController_EmitHealthBarUpdate(B_COMM_TO_CONTROLLER, INSTANT_HP_BAR_DROP);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr += 5;
}
@@ -9146,7 +9146,7 @@ static void Cmd_cureifburnedparalysedorpoisoned(void)
gBattleMons[gBattlerAttacker].status1 = 0;
gBattlescriptCurrInstr += 5;
gActiveBattler = gBattlerAttacker;
BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].status1), &gBattleMons[gActiveBattler].status1);
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].status1), &gBattleMons[gActiveBattler].status1);
MarkBattlerForControllerExec(gActiveBattler);
}
else
@@ -9268,11 +9268,11 @@ static void Cmd_tryswapitems(void)
gBattleMons[gBattlerTarget].item = oldItemAtk;
gActiveBattler = gBattlerAttacker;
BtlController_EmitSetMonData(BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(*newItemAtk), newItemAtk);
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, REQUEST_HELDITEM_BATTLE, 0, sizeof(*newItemAtk), newItemAtk);
MarkBattlerForControllerExec(gBattlerAttacker);
gActiveBattler = gBattlerTarget;
BtlController_EmitSetMonData(BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[gBattlerTarget].item), &gBattleMons[gBattlerTarget].item);
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[gBattlerTarget].item), &gBattleMons[gBattlerTarget].item);
MarkBattlerForControllerExec(gBattlerTarget);
*(u8 *)((u8 *)(&gBattleStruct->choicedMove[gBattlerTarget]) + 0) = 0;
@@ -9618,7 +9618,7 @@ static void Cmd_switchoutabilities(void)
{
case ABILITY_NATURAL_CURE:
gBattleMons[gActiveBattler].status1 = 0;
BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE,
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, REQUEST_STATUS_BATTLE,
gBitTable[*(gBattleStruct->battlerPartyIndexes + gActiveBattler)],
sizeof(gBattleMons[gActiveBattler].status1),
&gBattleMons[gActiveBattler].status1);
@@ -9758,7 +9758,7 @@ static void Cmd_docastformchangeanimation(void)
if (gBattleMons[gActiveBattler].status2 & STATUS2_SUBSTITUTE)
*(&gBattleStruct->formToChangeInto) |= CASTFORM_SUBSTITUTE;
BtlController_EmitBattleAnimation(BUFFER_A, B_ANIM_CASTFORM_CHANGE, gBattleStruct->formToChangeInto);
BtlController_EmitBattleAnimation(B_COMM_TO_CONTROLLER, B_ANIM_CASTFORM_CHANGE, gBattleStruct->formToChangeInto);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr++;
@@ -9840,7 +9840,7 @@ static void Cmd_tryrecycleitem(void)
*usedHeldItem = ITEM_NONE;
gBattleMons[gActiveBattler].item = gLastUsedItem;
BtlController_EmitSetMonData(BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].item), &gBattleMons[gActiveBattler].item);
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[gActiveBattler].item), &gBattleMons[gActiveBattler].item);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr += 5;
@@ -9937,13 +9937,13 @@ static void Cmd_handleballthrow(void)
if (gBattleTypeFlags & BATTLE_TYPE_TRAINER)
{
BtlController_EmitBallThrowAnim(BUFFER_A, BALL_TRAINER_BLOCK);
BtlController_EmitBallThrowAnim(B_COMM_TO_CONTROLLER, BALL_TRAINER_BLOCK);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr = BattleScript_TrainerBallBlock;
}
else if (gBattleTypeFlags & BATTLE_TYPE_WALLY_TUTORIAL)
{
BtlController_EmitBallThrowAnim(BUFFER_A, BALL_3_SHAKES_SUCCESS);
BtlController_EmitBallThrowAnim(B_COMM_TO_CONTROLLER, BALL_3_SHAKES_SUCCESS);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr = BattleScript_WallyBallThrow;
}
@@ -10031,7 +10031,7 @@ static void Cmd_handleballthrow(void)
if (odds > 254) // mon caught
{
BtlController_EmitBallThrowAnim(BUFFER_A, BALL_3_SHAKES_SUCCESS);
BtlController_EmitBallThrowAnim(B_COMM_TO_CONTROLLER, BALL_3_SHAKES_SUCCESS);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr = BattleScript_SuccessBallThrow;
SetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerTarget]], MON_DATA_POKEBALL, &gLastUsedItem);
@@ -10053,7 +10053,7 @@ static void Cmd_handleballthrow(void)
if (gLastUsedItem == ITEM_MASTER_BALL)
shakes = BALL_3_SHAKES_SUCCESS; // why calculate the shakes before that check?
BtlController_EmitBallThrowAnim(BUFFER_A, shakes);
BtlController_EmitBallThrowAnim(B_COMM_TO_CONTROLLER, shakes);
MarkBattlerForControllerExec(gActiveBattler);
if (shakes == BALL_3_SHAKES_SUCCESS) // mon caught, copy of the code above
@@ -10342,7 +10342,7 @@ static void Cmd_finishturn(void)
static void Cmd_trainerslideout(void)
{
gActiveBattler = GetBattlerAtPosition(gBattlescriptCurrInstr[1]);
BtlController_EmitTrainerSlideBack(BUFFER_A);
BtlController_EmitTrainerSlideBack(B_COMM_TO_CONTROLLER);
MarkBattlerForControllerExec(gActiveBattler);
gBattlescriptCurrInstr += 2;

View File

@@ -759,7 +759,7 @@ void PressurePPLose(u8 target, u8 attacker, u16 move)
if (MOVE_IS_PERMANENT(attacker, moveIndex))
{
gActiveBattler = attacker;
BtlController_EmitSetMonData(BUFFER_A, REQUEST_PPMOVE1_BATTLE + moveIndex, 0, 1, &gBattleMons[gActiveBattler].pp[moveIndex]);
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, REQUEST_PPMOVE1_BATTLE + moveIndex, 0, 1, &gBattleMons[gActiveBattler].pp[moveIndex]);
MarkBattlerForControllerExec(gActiveBattler);
}
}
@@ -791,7 +791,7 @@ void PressurePPLoseOnUsingImprison(u8 attacker)
if (imprisonPos != MAX_MON_MOVES && MOVE_IS_PERMANENT(attacker, imprisonPos))
{
gActiveBattler = attacker;
BtlController_EmitSetMonData(BUFFER_A, REQUEST_PPMOVE1_BATTLE + imprisonPos, 0, 1, &gBattleMons[gActiveBattler].pp[imprisonPos]);
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, REQUEST_PPMOVE1_BATTLE + imprisonPos, 0, 1, &gBattleMons[gActiveBattler].pp[imprisonPos]);
MarkBattlerForControllerExec(gActiveBattler);
}
}
@@ -822,11 +822,12 @@ void PressurePPLoseOnUsingPerishSong(u8 attacker)
if (perishSongPos != MAX_MON_MOVES && MOVE_IS_PERMANENT(attacker, perishSongPos))
{
gActiveBattler = attacker;
BtlController_EmitSetMonData(BUFFER_A, REQUEST_PPMOVE1_BATTLE + perishSongPos, 0, 1, &gBattleMons[gActiveBattler].pp[perishSongPos]);
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, REQUEST_PPMOVE1_BATTLE + perishSongPos, 0, 1, &gBattleMons[gActiveBattler].pp[perishSongPos]);
MarkBattlerForControllerExec(gActiveBattler);
}
}
// See comments for MarkBattlerForControllerExec.
static void UNUSED MarkAllBattlersForControllerExec(void)
{
int i;
@@ -834,31 +835,43 @@ static void UNUSED MarkAllBattlersForControllerExec(void)
if (gBattleTypeFlags & BATTLE_TYPE_LINK)
{
for (i = 0; i < gBattlersCount; i++)
gBattleControllerExecFlags |= gBitTable[i] << (32 - MAX_BATTLERS_COUNT);
MARK_BATTLE_CONTROLLER_MESSAGE_OUTBOUND_OVER_LINK(i);
}
else
{
for (i = 0; i < gBattlersCount; i++)
gBattleControllerExecFlags |= gBitTable[i];
MARK_BATTLE_CONTROLLER_ACTIVE_ON_LOCAL(i);
}
}
// Called when the battle engine dispatches a message to a battle controller.
//
// During a singleplayer battle, we just immediately mark the controller as
// active. During a multiplayer link, we do things a little differently. We
// set a bit indicating that we're sending a message over the link. That
// message will be received by all other players... *and* by us, the player
// sending it, at which point we'll invoke MarkBattlerReceivedLinkData,
// below, to clear the "we're sending a message" bit and set the "controller
// is now active" bit.
void MarkBattlerForControllerExec(u8 battlerId)
{
if (gBattleTypeFlags & BATTLE_TYPE_LINK)
gBattleControllerExecFlags |= gBitTable[battlerId] << (32 - MAX_BATTLERS_COUNT);
MARK_BATTLE_CONTROLLER_MESSAGE_OUTBOUND_OVER_LINK(battlerId);
else
gBattleControllerExecFlags |= gBitTable[battlerId];
MARK_BATTLE_CONTROLLER_ACTIVE_ON_LOCAL(battlerId);
}
// Called when a message dispatched from the battle engine to a battle
// controller is received over link communications. All players assume
// that if they've received the message, everyone else has as well.
void MarkBattlerReceivedLinkData(u8 battlerId)
{
s32 i;
for (i = 0; i < GetLinkPlayerCount(); i++)
gBattleControllerExecFlags |= gBitTable[battlerId] << (i << 2);
MARK_BATTLE_CONTROLLER_ACTIVE_FOR_PLAYER(battlerId, i);
gBattleControllerExecFlags &= ~((1 << 28) << battlerId);
MARK_BATTLE_CONTROLLER_MESSAGE_SYNCHRONIZED_OVER_LINK(battlerId);
}
void CancelMultiTurnMoves(u8 battler)
@@ -893,7 +906,7 @@ bool8 WasUnableToUseMove(u8 battler)
void PrepareStringBattle(u16 stringId, u8 battler)
{
gActiveBattler = battler;
BtlController_EmitPrintString(BUFFER_A, stringId);
BtlController_EmitPrintString(B_COMM_TO_CONTROLLER, stringId);
MarkBattlerForControllerExec(gActiveBattler);
}
@@ -1622,7 +1635,7 @@ u8 DoBattlerEndTurnEffects(void)
gBattleCommunication[MULTISTRING_CHOOSER] = 1;
BattleScriptExecute(BattleScript_MonWokeUpInUproar);
gActiveBattler = gBattlerAttacker;
BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1);
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1);
MarkBattlerForControllerExec(gActiveBattler);
break;
}
@@ -1747,7 +1760,7 @@ u8 DoBattlerEndTurnEffects(void)
{
CancelMultiTurnMoves(gActiveBattler);
gBattleMons[gActiveBattler].status1 |= STATUS1_SLEEP_TURN((Random() & 3) + 2); // 2-5 turns of sleep
BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1);
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1);
MarkBattlerForControllerExec(gActiveBattler);
gEffectBattler = gActiveBattler;
BattleScriptExecute(BattleScript_YawnMakesAsleep);
@@ -2257,7 +2270,7 @@ u8 AtkCanceller_UnableToUseMove(void)
if (effect == 2)
{
gActiveBattler = gBattlerAttacker;
BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1);
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1);
MarkBattlerForControllerExec(gActiveBattler);
}
return effect;
@@ -2621,7 +2634,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u8 ability, u8 special, u16 moveA
gBattleMons[battler].status2 &= ~STATUS2_NIGHTMARE; // fix nightmare glitch
gBattleScripting.battler = gActiveBattler = battler;
BattleScriptPushCursorAndCallback(BattleScript_ShedSkinActivates);
BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[battler].status1);
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[battler].status1);
MarkBattlerForControllerExec(gActiveBattler);
effect++;
}
@@ -2933,7 +2946,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u8 ability, u8 special, u16 moveA
gBattlescriptCurrInstr = BattleScript_AbilityCuredStatus;
gBattleScripting.battler = battler;
gActiveBattler = battler;
BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1);
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1);
MarkBattlerForControllerExec(gActiveBattler);
return effect;
}
@@ -3361,7 +3374,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn)
PREPARE_MOVE_BUFFER(gBattleTextBuff1, move);
BattleScriptExecute(BattleScript_BerryPPHealEnd2);
BtlController_EmitSetMonData(BUFFER_A, i + REQUEST_PPMOVE1_BATTLE, 0, 1, &changedPP);
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, i + REQUEST_PPMOVE1_BATTLE, 0, 1, &changedPP);
MarkBattlerForControllerExec(gActiveBattler);
effect = ITEM_PP_CHANGE;
}
@@ -3596,7 +3609,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn)
switch (effect)
{
case ITEM_STATUS_CHANGE:
BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[battlerId].status1);
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[battlerId].status1);
MarkBattlerForControllerExec(gActiveBattler);
break;
case ITEM_PP_CHANGE:
@@ -3747,7 +3760,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn)
gBattleScripting.battler = battlerId;
gPotentialItemEffectBattler = battlerId;
gActiveBattler = battlerId;
BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1);
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1);
MarkBattlerForControllerExec(gActiveBattler);
break;
}

View File

@@ -204,7 +204,7 @@ u32 BattlePalace_TryEscapeStatus(u8 battlerId)
if (effect == 2)
{
gActiveBattler = battlerId;
BtlController_EmitSetMonData(BUFFER_A, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1);
BtlController_EmitSetMonData(B_COMM_TO_CONTROLLER, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1);
MarkBattlerForControllerExec(gActiveBattler);
}

View File

@@ -5074,7 +5074,7 @@ bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 mov
temp2 = gActiveBattler;
gActiveBattler = battlerId;
BtlController_EmitGetMonData(BUFFER_A, REQUEST_ALL_BATTLE, 0);
BtlController_EmitGetMonData(B_COMM_TO_CONTROLLER, REQUEST_ALL_BATTLE, 0);
MarkBattlerForControllerExec(gActiveBattler);
gActiveBattler = temp2;
}