From 34ba9b4e0d4f710f4f0961a7b73902266c06f38a Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Mon, 28 Nov 2022 14:36:19 -0500 Subject: [PATCH] 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 27c5a86c4..0fa221229 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 06a09fc17..e8f25f77f 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 b7551ab9e..770a5444a 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 2eccd82f5..e27304853 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; }