From c81a985b5b76779c9419289dddb57ef047bfae70 Mon Sep 17 00:00:00 2001 From: Martin Griffin Date: Thu, 20 Apr 2023 21:45:16 +0100 Subject: [PATCH] Fix USE_ITEM explicit targets --- include/recorded_battle.h | 1 + src/battle_controller_recorded_opponent.c | 1 + src/battle_controller_recorded_player.c | 1 + test/test_runner_battle.c | 8 +++++--- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/recorded_battle.h b/include/recorded_battle.h index d04e89c36..ea66096d7 100644 --- a/include/recorded_battle.h +++ b/include/recorded_battle.h @@ -45,6 +45,7 @@ enum RECORDED_PARTY_INDEX, RECORDED_BATTLE_PALACE_ACTION, RECORDED_ITEM_ID, + RECORDED_ITEM_TARGET, }; extern u32 gRecordedBattleRngSeed; diff --git a/src/battle_controller_recorded_opponent.c b/src/battle_controller_recorded_opponent.c index e7fc6fd84..bb41b42d6 100644 --- a/src/battle_controller_recorded_opponent.c +++ b/src/battle_controller_recorded_opponent.c @@ -1441,6 +1441,7 @@ static void RecordedOpponentHandleChooseItem(void) u8 byte1 = RecordedBattle_GetBattlerAction(RECORDED_ITEM_ID, gActiveBattler); u8 byte2 = RecordedBattle_GetBattlerAction(RECORDED_ITEM_ID, gActiveBattler); gBattleStruct->chosenItem[gActiveBattler] = (byte1 << 8) | byte2; + gBattleStruct->itemPartyIndex[gActiveBattler] = RecordedBattle_GetBattlerAction(RECORDED_ITEM_TARGET, gActiveBattler); BtlController_EmitOneReturnValue(BUFFER_B, gBattleStruct->chosenItem[gActiveBattler]); RecordedOpponentBufferExecCompleted(); } diff --git a/src/battle_controller_recorded_player.c b/src/battle_controller_recorded_player.c index 87f575839..efbd60f18 100644 --- a/src/battle_controller_recorded_player.c +++ b/src/battle_controller_recorded_player.c @@ -1465,6 +1465,7 @@ static void RecordedPlayerHandleChooseItem(void) u8 byte1 = RecordedBattle_GetBattlerAction(RECORDED_ITEM_ID, gActiveBattler); u8 byte2 = RecordedBattle_GetBattlerAction(RECORDED_ITEM_ID, gActiveBattler); gBattleStruct->chosenItem[gActiveBattler] = (byte1 << 8) | byte2; + gBattleStruct->itemPartyIndex[gActiveBattler] = RecordedBattle_GetBattlerAction(RECORDED_ITEM_TARGET, gActiveBattler); BtlController_EmitOneReturnValue(BUFFER_B, gBattleStruct->chosenItem[gActiveBattler]); RecordedPlayerBufferExecCompleted(); } diff --git a/test/test_runner_battle.c b/test/test_runner_battle.c index 365120f13..2a44cc018 100644 --- a/test/test_runner_battle.c +++ b/test/test_runner_battle.c @@ -1540,9 +1540,11 @@ void UseItem(u32 sourceLine, struct BattlePokemon *battler, struct ItemContext c PushBattlerAction(sourceLine, battlerId, RECORDED_ITEM_ID, (ctx.itemId >> 8) & 0xFF); PushBattlerAction(sourceLine, battlerId, RECORDED_ITEM_ID, ctx.itemId & 0xFF); if (ctx.explicitPartyIndex) - gBattleStruct->itemPartyIndex[battlerId] = ctx.partyIndex; - if (ctx.explicitMove) - gBattleStruct->itemPartyIndex[battlerId] = i; + PushBattlerAction(sourceLine, battlerId, RECORDED_ITEM_TARGET, ctx.partyIndex); + else if (ctx.explicitMove) + PushBattlerAction(sourceLine, battlerId, RECORDED_ITEM_TARGET, i); + else + PushBattlerAction(sourceLine, battlerId, RECORDED_ITEM_TARGET, 0); DATA.actionBattlers |= 1 << battlerId; }