From 40ba25dd3ef2a437f7a8cfdc25230952ce40b606 Mon Sep 17 00:00:00 2001 From: Eduardo Quezada Date: Sun, 5 Jan 2025 13:47:49 -0300 Subject: [PATCH] Converted 2 various to callnative (#5950) --- asm/macros/battle_script.inc | 4 +- include/constants/battle_script_commands.h | 2 - src/battle_script_commands.c | 76 +++++++++++----------- src/data/moves_info.h | 2 +- test/battle/move_effect/court_change.c | 66 ++++++++++++++++++- test/battle/move_effect/speed_swap.c | 58 +++++++++++++++++ 6 files changed, 162 insertions(+), 46 deletions(-) create mode 100644 test/battle/move_effect/speed_swap.c diff --git a/asm/macros/battle_script.inc b/asm/macros/battle_script.inc index 80e9b36789..730b184449 100644 --- a/asm/macros/battle_script.inc +++ b/asm/macros/battle_script.inc @@ -2337,11 +2337,11 @@ .endm .macro swapsidestatuses - various BS_ATTACKER, VARIOUS_SWAP_SIDE_STATUSES + callnative BS_CourtChangeSwapSideStatuses .endm .macro swapstats stat:req - various BS_ATTACKER, VARIOUS_SWAP_STATS + callnative BS_SwapStats .byte \stat .endm diff --git a/include/constants/battle_script_commands.h b/include/constants/battle_script_commands.h index bd1c61ec09..808ee406d2 100644 --- a/include/constants/battle_script_commands.h +++ b/include/constants/battle_script_commands.h @@ -216,8 +216,6 @@ enum CmdVarious VARIOUS_SAVE_BATTLER_ITEM, VARIOUS_RESTORE_BATTLER_ITEM, VARIOUS_BATTLER_ITEM_TO_LAST_USED_ITEM, - VARIOUS_SWAP_SIDE_STATUSES, - VARIOUS_SWAP_STATS, }; // Cmd_manipulatedamage diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 4fc74022c7..b08b53a044 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -9404,8 +9404,10 @@ static bool32 IsTeatimeAffected(u32 battler) sideTimerOpp->structField = BATTLE_OPPOSITE(temp); \ } \ -static void CourtChangeSwapSideStatuses(void) +void BS_CourtChangeSwapSideStatuses(void) { + NATIVE_ARGS(); + struct SideTimer *sideTimerPlayer = &gSideTimers[B_SIDE_PLAYER]; struct SideTimer *sideTimerOpp = &gSideTimers[B_SIDE_OPPONENT]; u32 temp; @@ -9446,6 +9448,8 @@ static void CourtChangeSwapSideStatuses(void) // Swap what type set the Gigantamax damage over time effect SWAP(sideTimerPlayer->damageNonTypesType, sideTimerOpp->damageNonTypesType, temp); + + gBattlescriptCurrInstr = cmd->nextInstr; } static void HandleScriptMegaPrimalBurst(u32 caseId, u32 battler, u32 type) @@ -11317,44 +11321,6 @@ static void Cmd_various(void) gBattleMons[battler].item = gLastUsedItem; break; } - case VARIOUS_SWAP_SIDE_STATUSES: - { - VARIOUS_ARGS(); - CourtChangeSwapSideStatuses(); - break; - } - case VARIOUS_SWAP_STATS: - { - VARIOUS_ARGS(u8 stat); - - u8 stat = cmd->stat; - u16 temp; - - switch (stat) - { - case STAT_HP: - SWAP(gBattleMons[gBattlerAttacker].hp, gBattleMons[gBattlerTarget].hp, temp); - break; - case STAT_ATK: - SWAP(gBattleMons[gBattlerAttacker].attack, gBattleMons[gBattlerTarget].attack, temp); - break; - case STAT_DEF: - SWAP(gBattleMons[gBattlerAttacker].defense, gBattleMons[gBattlerTarget].defense, temp); - break; - case STAT_SPEED: - SWAP(gBattleMons[gBattlerAttacker].speed, gBattleMons[gBattlerTarget].speed, temp); - break; - case STAT_SPATK: - SWAP(gBattleMons[gBattlerAttacker].spAttack, gBattleMons[gBattlerTarget].spAttack, temp); - break; - case STAT_SPDEF: - SWAP(gBattleMons[gBattlerAttacker].spDefense, gBattleMons[gBattlerTarget].spDefense, temp); - break; - } - PREPARE_STAT_BUFFER(gBattleTextBuff1, stat); - gBattlescriptCurrInstr = cmd->nextInstr; - return; - } } // End of switch (cmd->id) gBattlescriptCurrInstr = cmd->nextInstr; @@ -18025,3 +17991,35 @@ void BS_JumpIfCriticalHit(void) else gBattlescriptCurrInstr = cmd->nextInstr; } + +void BS_SwapStats(void) +{ + NATIVE_ARGS(u8 stat); + + u32 stat = cmd->stat; + u32 temp; + + switch (stat) + { + case STAT_HP: + SWAP(gBattleMons[gBattlerAttacker].hp, gBattleMons[gBattlerTarget].hp, temp); + break; + case STAT_ATK: + SWAP(gBattleMons[gBattlerAttacker].attack, gBattleMons[gBattlerTarget].attack, temp); + break; + case STAT_DEF: + SWAP(gBattleMons[gBattlerAttacker].defense, gBattleMons[gBattlerTarget].defense, temp); + break; + case STAT_SPEED: + SWAP(gBattleMons[gBattlerAttacker].speed, gBattleMons[gBattlerTarget].speed, temp); + break; + case STAT_SPATK: + SWAP(gBattleMons[gBattlerAttacker].spAttack, gBattleMons[gBattlerTarget].spAttack, temp); + break; + case STAT_SPDEF: + SWAP(gBattleMons[gBattlerAttacker].spDefense, gBattleMons[gBattlerTarget].spDefense, temp); + break; + } + PREPARE_STAT_BUFFER(gBattleTextBuff1, stat); + gBattlescriptCurrInstr = cmd->nextInstr; +} diff --git a/src/data/moves_info.h b/src/data/moves_info.h index 2c28621286..ec9e209dda 100644 --- a/src/data/moves_info.h +++ b/src/data/moves_info.h @@ -21567,7 +21567,7 @@ const struct MoveInfo gMovesInfo[MOVES_COUNT_DYNAMAX] = [MOVE_G_MAX_CANNONADE] = { - .name = COMPOUND_STRING("G-Max Canonade"), + .name = COMPOUND_STRING("G-Max Cannonade"), .description = sNullDescription, //ANIM TODO .effect = EFFECT_MAX_MOVE, .power = 10, diff --git a/test/battle/move_effect/court_change.c b/test/battle/move_effect/court_change.c index 0727baff5e..817ab134ca 100644 --- a/test/battle/move_effect/court_change.c +++ b/test/battle/move_effect/court_change.c @@ -106,7 +106,7 @@ DOUBLE_BATTLE_TEST("Court Change used by the player swaps Mist, Safeguard, Auror MESSAGE("The opposing Wobbuffet used Tailwind!"); MESSAGE("Wynaut used Court Change!"); MESSAGE("Wynaut swapped the battle effects affecting each side of the field!"); - // The effects now end for the player side. + // The effects now end for the player side. MESSAGE("Your team's Mist wore off!"); MESSAGE("Your team is no longer protected by Safeguard!"); MESSAGE("Your team's Reflect wore off!"); @@ -153,4 +153,66 @@ DOUBLE_BATTLE_TEST("Court Change used by the opponent swaps Mist, Safeguard, Aur } } -TO_DO_BATTLE_TEST("Court Change used by the player swaps G-Max Steelsurge, G-Max Vine Lash, G-Max Wildfire, G-Max Cannonade"); +DOUBLE_BATTLE_TEST("Court Change used by the player swaps G-Max Steelsurge") +{ + GIVEN { + PLAYER(SPECIES_COPPERAJAH) { GigantamaxFactor(TRUE); } + PLAYER(SPECIES_WOBBUFFET); + PLAYER(SPECIES_WOBBUFFET); + OPPONENT(SPECIES_WYNAUT); + OPPONENT(SPECIES_WYNAUT); + OPPONENT(SPECIES_WYNAUT); + } WHEN { + TURN { MOVE(playerLeft, MOVE_IRON_HEAD, target: opponentRight, gimmick: GIMMICK_DYNAMAX); } + TURN { MOVE(opponentLeft, MOVE_COURT_CHANGE); } + TURN { SWITCH(opponentLeft, 2); SWITCH(playerLeft, 2); } + } SCENE { + MESSAGE("Copperajah used G-Max Steelsurge!"); + SEND_IN_MESSAGE("Wobbuffet"); + MESSAGE("The sharp steel bit into Wobbuffet!"); + NONE_OF { + MESSAGE("The sharp steel bit into the opposing Wynaut!"); + } + } +} + +DOUBLE_BATTLE_TEST("Court Change used by the player swaps G-Max Vine Lash, G-Max Wildfire, G-Max Cannonade") +{ + u32 species, move; + PARAMETRIZE { species = SPECIES_VENUSAUR; move = MOVE_VINE_WHIP; } + PARAMETRIZE { species = SPECIES_CHARIZARD; move = MOVE_EMBER; } + PARAMETRIZE { species = SPECIES_BLASTOISE; move = MOVE_WATER_GUN; } + GIVEN { + PLAYER(species) { GigantamaxFactor(TRUE); } + PLAYER(SPECIES_WOBBUFFET); + PLAYER(SPECIES_WOBBUFFET); + OPPONENT(SPECIES_WYNAUT); + OPPONENT(SPECIES_WYNAUT); + OPPONENT(SPECIES_WYNAUT); + } WHEN { + TURN { + MOVE(playerLeft, move, target: opponentRight, gimmick: GIMMICK_DYNAMAX); + MOVE(opponentLeft, MOVE_COURT_CHANGE); + } + } SCENE { + switch (species) { + case SPECIES_VENUSAUR: + MESSAGE("Venusaur used G-Max Vine Lash!"); + MESSAGE("Wobbuffet is hurt by G-Max Vine Lash's ferocious beating!"); + break; + case SPECIES_CHARIZARD: + MESSAGE("Charizard used G-Max Wildfire!"); + MESSAGE("Wobbuffet is burning up within G-Max Wildfire's flames!"); + break; + case SPECIES_BLASTOISE: + MESSAGE("Blastoise used G-Max Cannonade!"); + MESSAGE("Wobbuffet is hurt by G-Max Cannonade's vortex!"); + break; + } + NONE_OF { + MESSAGE("The opposing Wynaut is hurt by G-Max Vine Lash's ferocious beating!"); + MESSAGE("The opposing Wynaut is burning up within G-Max Wildfire's flames!"); + MESSAGE("The opposing Wynaut is hurt by G-Max Cannonade's vortex!"); + } + } +} diff --git a/test/battle/move_effect/speed_swap.c b/test/battle/move_effect/speed_swap.c new file mode 100644 index 0000000000..0a87b26236 --- /dev/null +++ b/test/battle/move_effect/speed_swap.c @@ -0,0 +1,58 @@ +#include "global.h" +#include "test/battle.h" + +ASSUMPTIONS +{ + ASSUME(GetMoveEffect(MOVE_SPEED_SWAP) == EFFECT_SPEED_SWAP); +} + +SINGLE_BATTLE_TEST("Speed Swap swaps user and target's speed stats") +{ + GIVEN { + PLAYER(SPECIES_WOBBUFFET) { Speed(6); } + OPPONENT(SPECIES_WOBBUFFET) { Speed(10); } + }WHEN { + TURN { MOVE(opponent, MOVE_TACKLE); MOVE(player, MOVE_SPEED_SWAP); } + TURN { MOVE(opponent, MOVE_TACKLE); MOVE(player, MOVE_TACKLE); } + } SCENE { + // Turn 1 + ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponent); + ANIMATION(ANIM_TYPE_MOVE, MOVE_SPEED_SWAP, player); + // Turn 2 + ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, player); + ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponent); + } THEN { + EXPECT_EQ(player->speed, 10); + EXPECT_EQ(opponent->speed, 6); + } +} + +SINGLE_BATTLE_TEST("Speed Swap doesn't swap user and target's speed modifiers") +{ + u32 species, ability, move; + PARAMETRIZE { species = SPECIES_WOBBUFFET; ability = ABILITY_TELEPATHY; move = MOVE_ROCK_POLISH; } // x2.0 + PARAMETRIZE { species = SPECIES_PSYDUCK; ability = ABILITY_SWIFT_SWIM; move = MOVE_RAIN_DANCE; } // x2.0 + GIVEN { + ASSUME(GetMoveEffect(MOVE_ROCK_POLISH) == EFFECT_SPEED_UP_2); + ASSUME(GetMoveEffect(MOVE_RAIN_DANCE) == EFFECT_RAIN_DANCE); + PLAYER(SPECIES_WOBBUFFET) { Speed(8); } + OPPONENT(species) { Speed(10); Ability(ability); } + }WHEN { + TURN { MOVE(opponent, move); MOVE(player, MOVE_SPEED_SWAP); } + TURN { MOVE(opponent, MOVE_TACKLE); MOVE(player, MOVE_TACKLE); } + } SCENE { + // Turn 1 + ANIMATION(ANIM_TYPE_MOVE, move, opponent); + ANIMATION(ANIM_TYPE_MOVE, MOVE_SPEED_SWAP, player); + // Turn 2 + ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponent); // Opponent is still first + ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, player); + } THEN { + EXPECT_EQ(player->speed, 10); + EXPECT_EQ(opponent->speed, 8); + if (move == MOVE_ROCK_POLISH) { + EXPECT_EQ(player->statStages[STAT_SPEED], DEFAULT_STAT_STAGE); + EXPECT_EQ(opponent->statStages[STAT_SPEED], DEFAULT_STAT_STAGE + 2); + } + } +}