Skip to content

Commit

Permalink
convert a few various to callnatives (#2465)
Browse files Browse the repository at this point in the history
  • Loading branch information
AsparagusEduardo authored May 15, 2023
2 parents c42552a + eaa44cc commit 15b122b
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 94 deletions.
51 changes: 28 additions & 23 deletions asm/macros/battle_script.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,33 @@
.macro setsnow
callnative BS_SetSnow
.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
Expand Down Expand Up @@ -1835,10 +1862,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
Expand Down Expand Up @@ -2049,20 +2072,7 @@
.macro swapsidestatuses
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, jumpInstr:req
various BS_ATTACKER, VARIOUS_CHECK_PARENTAL_BOND_COUNTER
.byte \counter
.4byte \jumpInstr
.endm
.macro swapstats stat:req
various BS_ATTACKER, VARIOUS_SWAP_STATS
.byte \stat
Expand Down Expand Up @@ -2242,11 +2252,6 @@
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

@ Tries to increase or decrease a battler's stat's stat stage by a specified amount. If impossible, jumps to \script.
.macro modifybattlerstatstage battler:req, stat:req, mode:req, amount:req, script:req, animation:req, customString

Expand Down
37 changes: 16 additions & 21 deletions include/constants/battle_script_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,27 +241,22 @@
#define VARIOUS_BATTLER_ITEM_TO_LAST_USED_ITEM 149
#define VARIOUS_SET_BEAK_BLAST 150
#define VARIOUS_SWAP_SIDE_STATUSES 151
#define VARIOUS_SET_Z_EFFECT 152
#define VARIOUS_TRY_SYMBIOSIS 153
#define VARIOUS_CAN_TELEPORT 154
#define VARIOUS_GET_BATTLER_SIDE 155
#define VARIOUS_CHECK_PARENTAL_BOND_COUNTER 156
#define VARIOUS_SWAP_STATS 157
#define VARIOUS_JUMP_IF_ROD 158
#define VARIOUS_JUMP_IF_ABSORB 159
#define VARIOUS_JUMP_IF_MOTOR 160
#define VARIOUS_TEATIME_INVUL 161
#define VARIOUS_TEATIME_TARGETS 162
#define VARIOUS_TRY_WIND_RIDER_POWER 163
#define VARIOUS_ACTIVATE_WEATHER_CHANGE_ABILITIES 164
#define VARIOUS_ACTIVATE_TERRAIN_CHANGE_ABILITIES 165
#define VARIOUS_JUMP_IF_EMERGENCY_EXITED 166
#define VARIOUS_STORE_HEALING_WISH 167
#define VARIOUS_HIT_SWITCH_TARGET_FAILED 168
#define VARIOUS_JUMP_IF_SHELL_TRAP 169
#define VARIOUS_TRY_REVIVAL_BLESSING 170
#define VARIOUS_TRY_TRAINER_SLIDE_MSG_Z_MOVE 171
#define VARIOUS_TRY_TRAINER_SLIDE_MSG_MEGA_EVOLUTION 172
#define VARIOUS_SWAP_STATS 152
#define VARIOUS_JUMP_IF_ROD 153
#define VARIOUS_JUMP_IF_ABSORB 154
#define VARIOUS_JUMP_IF_MOTOR 155
#define VARIOUS_TEATIME_INVUL 156
#define VARIOUS_TEATIME_TARGETS 157
#define VARIOUS_TRY_WIND_RIDER_POWER 158
#define VARIOUS_ACTIVATE_WEATHER_CHANGE_ABILITIES 159
#define VARIOUS_ACTIVATE_TERRAIN_CHANGE_ABILITIES 160
#define VARIOUS_JUMP_IF_EMERGENCY_EXITED 161
#define VARIOUS_STORE_HEALING_WISH 162
#define VARIOUS_HIT_SWITCH_TARGET_FAILED 163
#define VARIOUS_JUMP_IF_SHELL_TRAP 164
#define VARIOUS_TRY_REVIVAL_BLESSING 165
#define VARIOUS_TRY_TRAINER_SLIDE_MSG_Z_MOVE 166
#define VARIOUS_TRY_TRAINER_SLIDE_MSG_MEGA_EVOLUTION 167

// Cmd_manipulatedamage
#define DMG_CHANGE_SIGN 0
Expand Down
97 changes: 49 additions & 48 deletions src/battle_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -10335,12 +10335,6 @@ static void Cmd_various(void)
}
return;
}
case VARIOUS_SET_Z_EFFECT:
{
VARIOUS_ARGS();
SetZEffect(); //handles battle script jumping internally
return;
}
case VARIOUS_MOVEEND_ITEM_EFFECTS:
{
VARIOUS_ARGS();
Expand Down Expand Up @@ -11019,48 +11013,6 @@ static void Cmd_various(void)
CourtChangeSwapSideStatuses();
break;
}
case VARIOUS_TRY_SYMBIOSIS: //called by Bestow, Fling, and Bug Bite, which don't work with Cmd_removeitem.
{
VARIOUS_ARGS();
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:
{
VARIOUS_ARGS();
gBattleCommunication[0] = CanTeleport(gActiveBattler);
break;
}
case VARIOUS_GET_BATTLER_SIDE:
{
VARIOUS_ARGS();
if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER)
gBattleCommunication[0] = B_SIDE_PLAYER;
else
gBattleCommunication[0] = B_SIDE_OPPONENT;
break;
}
case VARIOUS_CHECK_PARENTAL_BOND_COUNTER:
{
VARIOUS_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 = cmd->counter;
if (gSpecialStatuses[gBattlerAttacker].parentalBondState == counter && gBattleMons[gBattlerTarget].hp != 0)
gBattlescriptCurrInstr = cmd->jumpInstr;
else
gBattlescriptCurrInstr = cmd->nextInstr;
return;
}
case VARIOUS_SWAP_STATS:
{
VARIOUS_ARGS(u8 stat);
Expand Down Expand Up @@ -16362,6 +16314,55 @@ static bool8 IsFinalStrikeEffect(u16 move)
return FALSE;
}

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
if (gSpecialStatuses[gBattlerAttacker].parentalBondState == cmd->counter && gBattleMons[gBattlerTarget].hp != 0)
gBattlescriptCurrInstr = cmd->jumpInstr;
else
gBattlescriptCurrInstr = cmd->nextInstr;
}

void BS_GetBattlerSide(void)
{
NATIVE_ARGS(u8 battler);
gBattleCommunication[0] = GetBattlerSide(cmd->battler);
gBattlescriptCurrInstr = cmd->nextInstr;
}

void BS_CanTeleport(void)
{
NATIVE_ARGS(u8 battler);
gBattleCommunication[0] = CanTeleport(cmd->battler);
gBattlescriptCurrInstr = cmd->nextInstr;
}

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)))
{
BestowItem(BATTLE_PARTNER(gActiveBattler), gActiveBattler);
gLastUsedAbility = gBattleMons[BATTLE_PARTNER(gActiveBattler)].ability;
gBattleScripting.battler = gBattlerAbility = BATTLE_PARTNER(gActiveBattler);
gBattlerAttacker = gActiveBattler;
BattleScriptPushCursor();
gBattlescriptCurrInstr = BattleScript_SymbiosisActivates;
return;
}

gBattlescriptCurrInstr = cmd->nextInstr;
}

void BS_SetZEffect(void)
{
SetZEffect(); // Handles battle script jumping internally
}

static void TryUpdateRoundTurnOrder(void)
{
if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE)
Expand Down
4 changes: 2 additions & 2 deletions src/battle_z_move.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,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)
Expand Down Expand Up @@ -676,7 +676,7 @@ void SetZEffect(void)
gBattlescriptCurrInstr = BattleScript_StatUpZMove;
break;
default:
gBattlescriptCurrInstr += 3;
gBattlescriptCurrInstr += Z_EFFECT_BS_LENGTH;
break;
}

Expand Down

0 comments on commit 15b122b

Please sign in to comment.