From 34ba9b4e0d4f710f4f0961a7b73902266c06f38a Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Mon, 28 Nov 2022 14:36:19 -0500 Subject: [PATCH 1/5] convert a few various to callnatives --- asm/macros/battle_script.inc | 50 ++++++------ include/constants/battle_script_commands.h | 5 -- src/battle_script_commands.c | 95 ++++++++++++++-------- src/battle_z_move.c | 4 +- 4 files changed, 88 insertions(+), 66 deletions(-) diff --git a/asm/macros/battle_script.inc b/asm/macros/battle_script.inc index 27c5a86c4166..0fa2212292cf 100644 --- a/asm/macros/battle_script.inc +++ b/asm/macros/battle_script.inc @@ -1310,6 +1310,33 @@ callnative BS_CalcMetalBurstDmg .4byte \ptr .endm + + .macro setzeffect + callnative BS_SetZEffect + .endm + + @ Used by effects that may proc Symbiosis but do not call removeitem. + .macro trysymbiosis + callnative BS_TrySymbiosis + .endm + + @ returns TRUE or FALSE to gBattleCommunication[0] + .macro canteleport battler:req + callnative BS_CanTeleport + .byte \battler + .endm + + @ returns B_SIDE_x to gBattleCommunication[0] + .macro getbattlerside battler:req + callnative BS_GetBattlerSide + .byte \battler + .endm + + .macro checkparentalbondcounter counter:req, ptr:req + callnative BS_CheckParentalBondCounter + .byte \counter + .4byte \ptr + .endm @ various command changed to more readable macros .macro cancelmultiturnmoves battler:req @@ -1791,10 +1818,6 @@ various \battler, VARIOUS_TRY_ACTIVATE_GRIM_NEIGH .endm - .macro setzeffect - various BS_ATTACKER, VARIOUS_SET_Z_EFFECT - .endm - .macro consumeberry battler:req, frombattler:req various \battler, VARIOUS_CONSUME_BERRY .byte \frombattler @@ -1986,20 +2009,6 @@ various BS_ATTACKER, VARIOUS_SWAP_SIDE_STATUSES .endm - .macro canteleport battler:req - various \battler, VARIOUS_CAN_TELEPORT - .endm - - .macro getbattlerside battler:req - various \battler, VARIOUS_GET_BATTLER_SIDE - .endm - - .macro checkparentalbondcounter counter:req, ptr:req - various BS_ATTACKER, VARIOUS_CHECK_PARENTAL_BOND_COUNTER - .byte \counter - .4byte \ptr - .endm - @ helpful macros .macro setstatchanger stat:req, stages:req, down:req setbyte sSTATCHANGER, \stat | \stages << 3 | \down << 7 @@ -2152,8 +2161,3 @@ .macro skydropyawn various 0, VARIOUS_SKY_DROP_YAWN .endm - - @ Used by effects that may proc Symbiosis but do not call removeitem. - .macro trysymbiosis - various BS_ATTACKER, VARIOUS_TRY_SYMBIOSIS - .endm diff --git a/include/constants/battle_script_commands.h b/include/constants/battle_script_commands.h index 06a09fc17970..e8f25f77f39c 100644 --- a/include/constants/battle_script_commands.h +++ b/include/constants/battle_script_commands.h @@ -241,11 +241,6 @@ #define VARIOUS_BATTLER_ITEM_TO_LAST_USED_ITEM 150 #define VARIOUS_SET_BEAK_BLAST 151 #define VARIOUS_SWAP_SIDE_STATUSES 152 -#define VARIOUS_SET_Z_EFFECT 153 -#define VARIOUS_TRY_SYMBIOSIS 154 -#define VARIOUS_CAN_TELEPORT 155 -#define VARIOUS_GET_BATTLER_SIDE 156 -#define VARIOUS_CHECK_PARENTAL_BOND_COUNTER 157 // Cmd_manipulatedamage #define DMG_CHANGE_SIGN 0 diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index b7551ab9eee4..770a5444a393 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -9434,9 +9434,6 @@ static void Cmd_various(void) gBattlescriptCurrInstr += 7; // exit if loop failed (failsafe) } return; - case VARIOUS_SET_Z_EFFECT: - SetZEffect(); //handles battle script jumping internally - return; case VARIOUS_MOVEEND_ITEM_EFFECTS: if (ItemBattleEffects(ITEMEFFECT_NORMAL, gActiveBattler, FALSE)) return; @@ -10035,39 +10032,6 @@ static void Cmd_various(void) case VARIOUS_SWAP_SIDE_STATUSES: CourtChangeSwapSideStatuses(); break; - case VARIOUS_TRY_SYMBIOSIS: //called by Bestow, Fling, and Bug Bite, which don't work with Cmd_removeitem. - if (SYMBIOSIS_CHECK(gActiveBattler, BATTLE_PARTNER(gActiveBattler))) - { - BestowItem(BATTLE_PARTNER(gActiveBattler), gActiveBattler); - gLastUsedAbility = gBattleMons[BATTLE_PARTNER(gActiveBattler)].ability; - gBattleScripting.battler = gBattlerAbility = BATTLE_PARTNER(gActiveBattler); - gBattlerAttacker = gActiveBattler; - BattleScriptPushCursor(); - gBattlescriptCurrInstr = BattleScript_SymbiosisActivates; - return; - } - break; - case VARIOUS_CAN_TELEPORT: - gBattleCommunication[0] = CanTeleport(gActiveBattler); - break; - case VARIOUS_GET_BATTLER_SIDE: - if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) - gBattleCommunication[0] = B_SIDE_PLAYER; - else - gBattleCommunication[0] = B_SIDE_OPPONENT; - break; - case VARIOUS_CHECK_PARENTAL_BOND_COUNTER: - { - // Some effects should only happen on the first or second strike of Parental Bond, - // so a way to check this in battle scripts is useful - u8 counter = T1_READ_8(gBattlescriptCurrInstr + 3); - if (gSpecialStatuses[gBattlerAttacker].parentalBondState == counter && gBattleMons[gBattlerTarget].hp != 0) - gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 4); - else - gBattlescriptCurrInstr += 8; - return; - } - break; } // End of switch (gBattlescriptCurrInstr[2]) gBattlescriptCurrInstr += 3; @@ -14861,3 +14825,62 @@ static bool8 IsFinalStrikeEffect(u16 move) } return FALSE; } + +// 10 bytes long (callnative(5) + counter(1) + ptr(4)) +void BS_CheckParentalBondCounter(void) +{ + // Some effects should only happen on the first or second strike of Parental Bond, + // so a way to check this in battle scripts is useful + u8 counter = T1_READ_8(gBattlescriptCurrInstr + 5); + if (gSpecialStatuses[gBattlerAttacker].parentalBondState == counter && gBattleMons[gBattlerTarget].hp != 0) + gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 6); + else + gBattlescriptCurrInstr += 10; +} + +// 6 bytes long (callnative(5) + battler(1)) +void BS_GetBattlerSide(void) +{ + u8 battler = gBattlescriptCurrInstr[5]; + if (GetBattlerSide(battler) == B_SIDE_PLAYER) + gBattleCommunication[0] = B_SIDE_PLAYER; + else + gBattleCommunication[0] = B_SIDE_OPPONENT; + + gBattlescriptCurrInstr += 6; +} + +// 6 bytes long (callnative(5) + battler(1)) +void BS_CanTeleport(void) +{ + u8 battler = gBattlescriptCurrInstr[5]; + gBattleCommunication[0] = CanTeleport(battler); + gBattlescriptCurrInstr += 6; +} + +// 5 bytes long +void BS_TrySymbiosis(void) +{ + //called by Bestow, Fling, and Bug Bite, which don't work with Cmd_removeitem. + gActiveBattler = gBattlerAttacker; + if (SYMBIOSIS_CHECK(gBattlerAttacker, BATTLE_PARTNER(gActiveBattler))) + { + BestowItem(BATTLE_PARTNER(gActiveBattler), gActiveBattler); + gLastUsedAbility = gBattleMons[BATTLE_PARTNER(gActiveBattler)].ability; + gBattleScripting.battler = gBattlerAbility = BATTLE_PARTNER(gActiveBattler); + gBattlerAttacker = gActiveBattler; + BattleScriptPushCursor(gBattlescriptCurrInstr + 5); + gBattlescriptCurrInstr = BattleScript_SymbiosisActivates; + } + else + { + gBattlescriptCurrInstr += 5; + } +} + +void BS_SetZEffect(void) +{ + SetZEffect(); // Handles battle script jumping internally +} + + diff --git a/src/battle_z_move.c b/src/battle_z_move.c index 2eccd82f5270..e27304853cf8 100644 --- a/src/battle_z_move.c +++ b/src/battle_z_move.c @@ -593,7 +593,7 @@ const u8 *GetZMoveName(u16 move) return gZMoveNames[0]; // Failsafe } -#define Z_EFFECT_BS_LENGTH 3 +#define Z_EFFECT_BS_LENGTH 5 // This function kinda cheats by setting a return battle script to after the setzeffect various command // and then jumping to a z effect script void SetZEffect(void) @@ -684,7 +684,7 @@ void SetZEffect(void) gBattlescriptCurrInstr = BattleScript_StatUpZMove; break; default: - gBattlescriptCurrInstr += 3; + gBattlescriptCurrInstr += Z_EFFECT_BS_LENGTH; break; } From cd7abea6fe50f9e75a4712ee5061b378707b4834 Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Mon, 28 Nov 2022 14:47:56 -0500 Subject: [PATCH 2/5] fix BS_TrySymbiosis --- src/battle_script_commands.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 770a5444a393..55487eab7634 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -14869,13 +14869,12 @@ void BS_TrySymbiosis(void) gLastUsedAbility = gBattleMons[BATTLE_PARTNER(gActiveBattler)].ability; gBattleScripting.battler = gBattlerAbility = BATTLE_PARTNER(gActiveBattler); gBattlerAttacker = gActiveBattler; - BattleScriptPushCursor(gBattlescriptCurrInstr + 5); + BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_SymbiosisActivates; + return; } - else - { - gBattlescriptCurrInstr += 5; - } + + gBattlescriptCurrInstr += 5; } void BS_SetZEffect(void) From 4b799f2571bc6ba49c190e1bf908566d99992d95 Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Mon, 28 Nov 2022 15:10:42 -0500 Subject: [PATCH 3/5] optimize BS_GetBattlerSide --- src/battle_script_commands.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 55487eab7634..7ad656737329 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -14841,12 +14841,7 @@ void BS_CheckParentalBondCounter(void) // 6 bytes long (callnative(5) + battler(1)) void BS_GetBattlerSide(void) { - u8 battler = gBattlescriptCurrInstr[5]; - if (GetBattlerSide(battler) == B_SIDE_PLAYER) - gBattleCommunication[0] = B_SIDE_PLAYER; - else - gBattleCommunication[0] = B_SIDE_OPPONENT; - + gBattleCommunication[0] = GetBattlerSide(gBattlescriptCurrInstr[5]); gBattlescriptCurrInstr += 6; } From 6458cab70a2533263518a877013a230512dacd39 Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Mon, 15 May 2023 15:07:09 -0400 Subject: [PATCH 4/5] use NATIVE_ARGS in various to callnative conversions --- src/battle_script_commands.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index eddf6d6e1942..896b57ffccba 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -8805,7 +8805,7 @@ static bool32 CanTeleport(u8 battlerId) { struct Pokemon *party = GetBattlerParty(battlerId); u32 species, count, i; - + for (i = 0; i < PARTY_SIZE; i++) { species = GetMonData(&party[i], MON_DATA_SPECIES_OR_EGG); @@ -16317,33 +16317,33 @@ static bool8 IsFinalStrikeEffect(u16 move) // 10 bytes long (callnative(5) + counter(1) + ptr(4)) void BS_CheckParentalBondCounter(void) { + NATIVE_ARGS(u8 counter, const u8 *jumpInstr); // Some effects should only happen on the first or second strike of Parental Bond, // so a way to check this in battle scripts is useful - u8 counter = T1_READ_8(gBattlescriptCurrInstr + 5); - if (gSpecialStatuses[gBattlerAttacker].parentalBondState == counter && gBattleMons[gBattlerTarget].hp != 0) - gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 6); + if (gSpecialStatuses[gBattlerAttacker].parentalBondState == cmd->counter && gBattleMons[gBattlerTarget].hp != 0) + gBattlescriptCurrInstr = cmd->jumpInstr; else - gBattlescriptCurrInstr += 10; + gBattlescriptCurrInstr = cmd->nextInstr; } // 6 bytes long (callnative(5) + battler(1)) void BS_GetBattlerSide(void) { - gBattleCommunication[0] = GetBattlerSide(gBattlescriptCurrInstr[5]); - gBattlescriptCurrInstr += 6; + NATIVE_ARGS(u8 battler); + gBattleCommunication[0] = GetBattlerSide(cmd->battler); + gBattlescriptCurrInstr = cmd->nextInstr; } -// 6 bytes long (callnative(5) + battler(1)) void BS_CanTeleport(void) { - u8 battler = gBattlescriptCurrInstr[5]; - gBattleCommunication[0] = CanTeleport(battler); - gBattlescriptCurrInstr += 6; + NATIVE_ARGS(u8 battler); + gBattleCommunication[0] = CanTeleport(cmd->battler); + gBattlescriptCurrInstr = cmd->nextInstr; } -// 5 bytes long void BS_TrySymbiosis(void) { + NATIVE_ARGS(); //called by Bestow, Fling, and Bug Bite, which don't work with Cmd_removeitem. gActiveBattler = gBattlerAttacker; if (SYMBIOSIS_CHECK(gBattlerAttacker, BATTLE_PARTNER(gActiveBattler))) @@ -16357,7 +16357,7 @@ void BS_TrySymbiosis(void) return; } - gBattlescriptCurrInstr += 5; + gBattlescriptCurrInstr = cmd->nextInstr; } void BS_SetZEffect(void) From eaa44cc8b5c62d70792868d8982ed1920f31f49e Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Mon, 15 May 2023 15:20:44 -0400 Subject: [PATCH 5/5] fix syntax --- src/battle_script_commands.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 896b57ffccba..88a76adff1cc 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -8805,7 +8805,7 @@ static bool32 CanTeleport(u8 battlerId) { struct Pokemon *party = GetBattlerParty(battlerId); u32 species, count, i; - + for (i = 0; i < PARTY_SIZE; i++) { species = GetMonData(&party[i], MON_DATA_SPECIES_OR_EGG); @@ -16314,7 +16314,6 @@ static bool8 IsFinalStrikeEffect(u16 move) return FALSE; } -// 10 bytes long (callnative(5) + counter(1) + ptr(4)) void BS_CheckParentalBondCounter(void) { NATIVE_ARGS(u8 counter, const u8 *jumpInstr); @@ -16326,7 +16325,6 @@ void BS_CheckParentalBondCounter(void) gBattlescriptCurrInstr = cmd->nextInstr; } -// 6 bytes long (callnative(5) + battler(1)) void BS_GetBattlerSide(void) { NATIVE_ARGS(u8 battler);