From fbd7d88e4f0b1499d0b611c25f45be5fc562caa5 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 15 Dec 2023 16:54:10 +0100 Subject: [PATCH 1/3] Fix regression introduced for Eject Button --- src/battle_script_commands.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index cfa2959f75..0a77522df0 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -5853,7 +5853,8 @@ static void Cmd_moveend(void) if (IsBattlerAlive(battler) && gBattlerAttacker != battler && GetBattlerHoldEffect(battler, TRUE) == HOLD_EFFECT_EJECT_BUTTON - && TARGET_TURN_DAMAGED + && !DoesSubstituteBlockMove(gBattlerAttacker, battler, gCurrentMove) + && (gSpecialStatuses[battler].physicalDmg != 0 || gSpecialStatuses[battler].specialDmg != 0 || gBattleStruct->enduredDamage & gBitTable[battler]) && CountUsablePartyMons(battler) > 0) // Has mon to switch into { gBattleScripting.battler = battler; From cdeb43228d95d31df2223711129c23c16ba45470 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 16 Dec 2023 09:33:45 +0100 Subject: [PATCH 2/3] Use battler turn damaged --- include/battle.h | 2 +- src/battle_script_commands.c | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/include/battle.h b/include/battle.h index f7241c3455..77b86591f9 100644 --- a/include/battle.h +++ b/include/battle.h @@ -773,7 +773,7 @@ STATIC_ASSERT(sizeof(((struct BattleStruct *)0)->palaceFlags) * 8 >= MAX_BATTLER #define BATTLER_MAX_HP(battlerId)(gBattleMons[battlerId].hp == gBattleMons[battlerId].maxHP) #define TARGET_TURN_DAMAGED ((gSpecialStatuses[gBattlerTarget].physicalDmg != 0 || gSpecialStatuses[gBattlerTarget].specialDmg != 0) || (gBattleStruct->enduredDamage & gBitTable[gBattlerTarget])) -#define BATTLER_DAMAGED(battlerId) ((gSpecialStatuses[battlerId].physicalDmg != 0 || gSpecialStatuses[battlerId].specialDmg != 0)) +#define BATTLER_TURN_DAMAGED(battlerId) ((gSpecialStatuses[battlerId].physicalDmg != 0 || gSpecialStatuses[battlerId].specialDmg != 0) || (gBattleStruct->enduredDamage & gBitTable[battler])) #define IS_BATTLER_OF_TYPE(battlerId, type)((GetBattlerType(battlerId, 0) == type || GetBattlerType(battlerId, 1) == type || (GetBattlerType(battlerId, 2) != TYPE_MYSTERY && GetBattlerType(battlerId, 2) == type))) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 0a77522df0..519dc51577 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -5853,8 +5853,7 @@ static void Cmd_moveend(void) if (IsBattlerAlive(battler) && gBattlerAttacker != battler && GetBattlerHoldEffect(battler, TRUE) == HOLD_EFFECT_EJECT_BUTTON - && !DoesSubstituteBlockMove(gBattlerAttacker, battler, gCurrentMove) - && (gSpecialStatuses[battler].physicalDmg != 0 || gSpecialStatuses[battler].specialDmg != 0 || gBattleStruct->enduredDamage & gBitTable[battler]) + && BATTLER_TURN_DAMAGED(battler) && CountUsablePartyMons(battler) > 0) // Has mon to switch into { gBattleScripting.battler = battler; @@ -5889,7 +5888,7 @@ static void Cmd_moveend(void) && IsBattlerAlive(battler) && !DoesSubstituteBlockMove(gBattlerAttacker, battler, gCurrentMove) && GetBattlerHoldEffect(battler, TRUE) == HOLD_EFFECT_RED_CARD - && (gSpecialStatuses[battler].physicalDmg != 0 || gSpecialStatuses[battler].specialDmg != 0) + && BATTLER_TURN_DAMAGED(battler) && CanBattlerSwitch(gBattlerAttacker)) { gLastUsedItem = gBattleMons[battler].item; @@ -5953,7 +5952,7 @@ static void Cmd_moveend(void) // Attacker is mon who made contact, battler is mon with pickpocket if (battler != gBattlerAttacker // Cannot pickpocket yourself && GetBattlerAbility(battler) == ABILITY_PICKPOCKET // Target must have pickpocket ability - && BATTLER_DAMAGED(battler) // Target needs to have been damaged + && BATTLER_TURN_DAMAGED(battler) // Target needs to have been damaged && !DoesSubstituteBlockMove(gBattlerAttacker, battler, gCurrentMove) // Subsitute unaffected && IsBattlerAlive(battler) // Battler must be alive to pickpocket && gBattleMons[battler].item == ITEM_NONE // Pickpocketer can't have an item already From 65bfab1a3818d81a62c23f8ddcc412ff2a085dc0 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 16 Dec 2023 09:48:41 +0100 Subject: [PATCH 3/3] rename Cmd_jumpifaffectedbyprotect --- asm/macros/battle_script.inc | 5 ----- src/battle_script_commands.c | 6 +++--- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/asm/macros/battle_script.inc b/asm/macros/battle_script.inc index a29b5f62e8..de509588bc 100644 --- a/asm/macros/battle_script.inc +++ b/asm/macros/battle_script.inc @@ -362,11 +362,6 @@ .byte 0x3f .endm - .macro jumpifaffectedbyprotect failInstr:req - .byte 0x40 - .4byte \failInstr - .endm - .macro call instr:req .byte 0x41 .4byte \instr diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 519dc51577..a82825ff06 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -418,7 +418,7 @@ static void Cmd_return(void); static void Cmd_end(void); static void Cmd_end2(void); static void Cmd_end3(void); -static void Cmd_jumpifaffectedbyprotect(void); +static void Cmd_unused5(void); static void Cmd_call(void); static void Cmd_setroost(void); static void Cmd_jumpifabilitypresent(void); @@ -677,7 +677,7 @@ void (* const gBattleScriptingCommandsTable[])(void) = Cmd_end, //0x3D Cmd_end2, //0x3E Cmd_end3, //0x3F - Cmd_jumpifaffectedbyprotect, //0x40 + Cmd_unused5, //0x40 Cmd_call, //0x41 Cmd_setroost, //0x42 Cmd_jumpifabilitypresent, //0x43 @@ -1507,7 +1507,7 @@ static bool32 JumpIfMoveFailed(u8 adder, u16 move) return FALSE; } -static void Cmd_jumpifaffectedbyprotect(void) +static void Cmd_unused5(void) { CMD_ARGS(const u8 *failInstr);