Skip to content

Commit

Permalink
Converted 2 various to callnative (#5950)
Browse files Browse the repository at this point in the history
  • Loading branch information
AsparagusEduardo authored Jan 5, 2025
1 parent 771156e commit 40ba25d
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 46 deletions.
4 changes: 2 additions & 2 deletions asm/macros/battle_script.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions include/constants/battle_script_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
76 changes: 37 additions & 39 deletions src/battle_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion src/data/moves_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
66 changes: 64 additions & 2 deletions test/battle/move_effect/court_change.c
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand Down Expand Up @@ -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!");
}
}
}
58 changes: 58 additions & 0 deletions test/battle/move_effect/speed_swap.c
Original file line number Diff line number Diff line change
@@ -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);
}
}
}

0 comments on commit 40ba25d

Please sign in to comment.