From bebc13b5a1a08141d044f4da969c12b9152de989 Mon Sep 17 00:00:00 2001 From: Alex <93446519+AlexOn1ine@users.noreply.github.com> Date: Fri, 31 May 2024 12:22:18 +0200 Subject: [PATCH] Adjust Ate-Ability code a bit to make it more readable (#4640) * Adjust Ate-Ability code a bit to make it more readable * stupid oversight * fixed * pull normal type move check out of function * unused var * switch and tests * oversight * Apply suggestions from code review --------- Co-authored-by: Bassoonian --- src/battle_main.c | 74 ++++++++++++++++++------- test/battle/ability/ate_abilities.c | 85 +++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+), 19 deletions(-) create mode 100644 test/battle/ability/ate_abilities.c diff --git a/src/battle_main.c b/src/battle_main.c index 16551254d9..88dbb94f8b 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -5976,9 +5976,59 @@ void RunBattleScriptCommands(void) gBattleScriptingCommandsTable[gBattlescriptCurrInstr[0]](); } +bool32 TrySetAteType(u32 move, u32 battlerAtk, u32 attackerAbility) +{ + u32 ateType; + + switch (gMovesInfo[move].effect) + { + case EFFECT_TERA_BLAST: + if (IsTerastallized(battlerAtk)) + return FALSE; + break; + case EFFECT_TERA_STARSTORM: + if (gBattleMons[battlerAtk].species == SPECIES_TERAPAGOS_STELLAR) + return FALSE; + break; + case EFFECT_HIDDEN_POWER: + case EFFECT_WEATHER_BALL: + case EFFECT_CHANGE_TYPE_ON_ITEM: + case EFFECT_NATURAL_GIFT: + return FALSE; + } + + ateType = TYPE_NONE; + switch (attackerAbility) + { + case ABILITY_PIXILATE: + ateType = TYPE_FAIRY; + break; + case ABILITY_REFRIGERATE: + ateType = TYPE_ICE; + break; + case ABILITY_AERILATE: + ateType = TYPE_FLYING; + break; + case ABILITY_GALVANIZE: + ateType = TYPE_ELECTRIC; + break; + default: + ateType = TYPE_NONE; + break; + } + + if (ateType != TYPE_NONE) + { + gBattleStruct->dynamicMoveType = ateType | F_DYNAMIC_TYPE_SET; + return TRUE; + } + + return FALSE; +} + void SetTypeBeforeUsingMove(u32 move, u32 battlerAtk) { - u32 moveType, ateType, attackerAbility; + u32 moveType, attackerAbility; u16 holdEffect = GetBattlerHoldEffect(battlerAtk, TRUE); if (move == MOVE_STRUGGLE) @@ -6080,29 +6130,15 @@ void SetTypeBeforeUsingMove(u32 move, u32 battlerAtk) } attackerAbility = GetBattlerAbility(battlerAtk); - - if (gMovesInfo[move].type == TYPE_NORMAL - && gMovesInfo[move].effect != EFFECT_HIDDEN_POWER - && gMovesInfo[move].effect != EFFECT_WEATHER_BALL - && gMovesInfo[move].effect != EFFECT_CHANGE_TYPE_ON_ITEM - && gMovesInfo[move].effect != EFFECT_NATURAL_GIFT - && !(gMovesInfo[move].effect == EFFECT_TERA_BLAST && IsTerastallized(battlerAtk)) - && !(gMovesInfo[move].effect == EFFECT_TERA_STARSTORM && gBattleMons[battlerAtk].species == SPECIES_TERAPAGOS_STELLAR) - && ((attackerAbility == ABILITY_PIXILATE && (ateType = TYPE_FAIRY)) - || (attackerAbility == ABILITY_REFRIGERATE && (ateType = TYPE_ICE)) - || (attackerAbility == ABILITY_AERILATE && (ateType = TYPE_FLYING)) - || ((attackerAbility == ABILITY_GALVANIZE) && (ateType = TYPE_ELECTRIC)) - ) - ) + if (gMovesInfo[move].type == TYPE_NORMAL && TrySetAteType(move, battlerAtk, attackerAbility)) { - gBattleStruct->dynamicMoveType = ateType | F_DYNAMIC_TYPE_SET; if (!IsDynamaxed(battlerAtk)) gBattleStruct->ateBoost[battlerAtk] = 1; } else if (gMovesInfo[move].type != TYPE_NORMAL - && gMovesInfo[move].effect != EFFECT_HIDDEN_POWER - && gMovesInfo[move].effect != EFFECT_WEATHER_BALL - && attackerAbility == ABILITY_NORMALIZE) + && gMovesInfo[move].effect != EFFECT_HIDDEN_POWER + && gMovesInfo[move].effect != EFFECT_WEATHER_BALL + && attackerAbility == ABILITY_NORMALIZE) { gBattleStruct->dynamicMoveType = TYPE_NORMAL | F_DYNAMIC_TYPE_SET; if (!IsDynamaxed(battlerAtk)) diff --git a/test/battle/ability/ate_abilities.c b/test/battle/ability/ate_abilities.c new file mode 100644 index 0000000000..12ee75722a --- /dev/null +++ b/test/battle/ability/ate_abilities.c @@ -0,0 +1,85 @@ +#include "global.h" +#include "test/battle.h" + +ASSUMPTIONS +{ + ASSUME(gMovesInfo[MOVE_TACKLE].type == TYPE_NORMAL); + ASSUME(gMovesInfo[MOVE_TACKLE].power > 0); +} + +SINGLE_BATTLE_TEST("Galvanize can not turn certain moves into Electric type moves") +{ + u32 move; + + PARAMETRIZE { move = MOVE_HIDDEN_POWER; } + PARAMETRIZE { move = MOVE_WEATHER_BALL; } + PARAMETRIZE { move = MOVE_MULTI_ATTACK; } + + ASSUME(gMovesInfo[MOVE_HIDDEN_POWER].effect == EFFECT_HIDDEN_POWER); + ASSUME(gMovesInfo[MOVE_WEATHER_BALL].effect == EFFECT_WEATHER_BALL); + ASSUME(gMovesInfo[MOVE_MULTI_ATTACK].effect == EFFECT_CHANGE_TYPE_ON_ITEM); + GIVEN { + PLAYER(SPECIES_KRABBY); + OPPONENT(SPECIES_GEODUDE_ALOLAN) { Ability(ABILITY_GALVANIZE); } + } WHEN { + TURN { MOVE(opponent, move); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, move, opponent); + NOT MESSAGE("It's super effective!"); + } +} + +SINGLE_BATTLE_TEST("Galvanize turns a normal type move into Electric") +{ + GIVEN { + PLAYER(SPECIES_KRABBY); + OPPONENT(SPECIES_GEODUDE_ALOLAN) { Ability(ABILITY_GALVANIZE); } + } WHEN { + TURN { MOVE(opponent, MOVE_TACKLE); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponent); + MESSAGE("It's super effective!"); + } +} + +SINGLE_BATTLE_TEST("Pixilate turns a normal type move into Fairy") +{ + GIVEN { + PLAYER(SPECIES_DRAGONITE); + OPPONENT(SPECIES_ALTARIA) { Item(ITEM_ALTARIANITE); } + } WHEN { + TURN { MOVE(opponent, MOVE_TACKLE, megaEvolve: TRUE); } + } SCENE { + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_MEGA_EVOLUTION, opponent); + ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponent); + MESSAGE("It's super effective!"); + } +} + +SINGLE_BATTLE_TEST("Refrigerate turns a normal type move into Ice") +{ + GIVEN { + PLAYER(SPECIES_MEGANIUM); + OPPONENT(SPECIES_AMAURA) { Ability(ABILITY_REFRIGERATE); } + } WHEN { + TURN { MOVE(opponent, MOVE_TACKLE, megaEvolve: TRUE); } + } SCENE { + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_MEGA_EVOLUTION, opponent); + ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponent); + MESSAGE("It's super effective!"); + } +} + +SINGLE_BATTLE_TEST("Aerilate turns a normal type move into Flying") +{ + GIVEN { + PLAYER(SPECIES_MEGANIUM); + OPPONENT(SPECIES_SALAMENCE) { Item(ITEM_SALAMENCITE); } + } WHEN { + TURN { MOVE(opponent, MOVE_TACKLE, megaEvolve: TRUE); } + } SCENE { + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_MEGA_EVOLUTION, opponent); + ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponent); + MESSAGE("It's super effective!"); + } +}