From 5fd468f507dc1d6f18a3cfd76ca3217e5ba6bb14 Mon Sep 17 00:00:00 2001 From: ExpoSeed <43502820+ExpoSeed@users.noreply.github.com> Date: Tue, 22 Mar 2022 13:10:24 -0500 Subject: [PATCH] Review comments. Commented code removed, ShouldAIUseZMove moved to battle_ai_util and renamed to be consistent with other fns --- data/battle_scripts_1.s | 2 -- include/battle_ai_util.h | 1 + include/battle_z_move.h | 1 - src/battle_ai_util.c | 32 ++++++++++++++++++++++++++ src/battle_controller_opponent.c | 3 ++- src/battle_controller_player_partner.c | 3 ++- src/battle_z_move.c | 31 ------------------------- 7 files changed, 37 insertions(+), 36 deletions(-) diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 7d85134ed..bac1b83e7 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -9217,8 +9217,6 @@ BattleScript_ZMoveActivateStatus:: printstring STRINGID_ZPOWERSURROUNDS playanimation BS_ATTACKER, B_ANIM_ZMOVE_ACTIVATE, NULL setzeffect -@ printstring STRINGID_ZMOVEUNLEASHED -@ waitmessage 0x40 return BattleScript_ZEffectPrintString:: diff --git a/include/battle_ai_util.h b/include/battle_ai_util.h index 6665f78ca..726867c9e 100644 --- a/include/battle_ai_util.h +++ b/include/battle_ai_util.h @@ -60,6 +60,7 @@ bool32 IsAbilityOfRating(u16 ability, s8 rating); s8 GetAbilityRating(u16 ability); bool32 AI_IsAbilityOnSide(u32 battlerId, u32 ability); bool32 AI_MoveMakesContact(u32 ability, u32 holdEffect, u16 move); +bool32 ShouldUseZMove(u8 activeId, u8 targetId, u16 chosenMove); // stat stage checks bool32 AnyStatIsRaised(u8 battlerId); diff --git a/include/battle_z_move.h b/include/battle_z_move.h index ae2b38834..5d34e25a9 100644 --- a/include/battle_z_move.h +++ b/include/battle_z_move.h @@ -23,7 +23,6 @@ void DestroyZMoveTriggerSprite(void); bool32 MoveSelectionDisplayZMove(u16 zmove); const u8* GetZMoveName(u16 move); void SetZEffect(void); -bool32 ShouldAIUseZMove(u8 activeId, u8 targetId, u16 chosenMove); bool32 IsZMoveUsable(u8 battlerId, u16 moveIndex); void GetUsableZMoves(u8 battlerId, u16 *moves); diff --git a/src/battle_ai_util.c b/src/battle_ai_util.c index e819cfc34..740d3bf51 100644 --- a/src/battle_ai_util.c +++ b/src/battle_ai_util.c @@ -3636,3 +3636,35 @@ bool32 AI_MoveMakesContact(u32 ability, u32 holdEffect, u16 move) return TRUE; return FALSE; } + +//TODO - this could use some more sophisticated logic +bool32 ShouldUseZMove(u8 battlerAtk, u8 battlerDef, u16 chosenMove) +{ + // simple logic. just upgrades chosen move to z move if possible, unless regular move would kill opponent + if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE) && battlerDef == BATTLE_PARTNER(battlerAtk)) + return FALSE; //don't use z move on partner + if (gBattleStruct->zmove.used[battlerAtk]) + return FALSE; //cant use z move twice + + if (IsViableZMove(battlerAtk, chosenMove)) + { + #ifdef POKEMON_EXPANSION + if (gBattleMons[battlerDef].ability == ABILITY_DISGUISE && gBattleMons[battlerDef].species == SPECIES_MIMIKYU) + return FALSE; // Don't waste a Z-Move busting disguise + if (gBattleMons[battlerDef].ability == ABILITY_ICE_FACE && gBattleMons[battlerDef].species == SPECIES_EISCUE && IS_MOVE_PHYSICAL(chosenMove)) + return FALSE; // Don't waste a Z-Move busting Ice Face + #endif + + if (IS_MOVE_STATUS(chosenMove) && !IS_MOVE_STATUS(gBattleStruct->zmove.chosenZMove)) + return FALSE; + else if (!IS_MOVE_STATUS(chosenMove) && IS_MOVE_STATUS(gBattleStruct->zmove.chosenZMove)) + return FALSE; + + if (!IS_MOVE_STATUS(chosenMove) && AI_CalcDamage(chosenMove, battlerAtk, battlerDef, FALSE) >= gBattleMons[battlerDef].hp) + return FALSE; // don't waste damaging z move if can otherwise faint target + + return TRUE; + } + + return FALSE; +} diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index 963fd577a..11c6b50ac 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -1,6 +1,7 @@ #include "global.h" #include "battle.h" #include "battle_ai_main.h" +#include "battle_ai_util.h" #include "battle_anim.h" #include "battle_arena.h" #include "battle_controllers.h" @@ -1597,7 +1598,7 @@ static void OpponentHandleChooseMove(void) gBattlerTarget = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT); } - if (ShouldAIUseZMove(gActiveBattler, gBattlerTarget, chosenMove)) + if (ShouldUseZMove(gActiveBattler, gBattlerTarget, chosenMove)) QueueZMove(gActiveBattler, moveInfo->moves[chosenMoveId]); if (CanMegaEvolve(gActiveBattler)) // If opponent can mega evolve, do it. diff --git a/src/battle_controller_player_partner.c b/src/battle_controller_player_partner.c index 19e0c70ee..1703c2af1 100644 --- a/src/battle_controller_player_partner.c +++ b/src/battle_controller_player_partner.c @@ -1,6 +1,7 @@ #include "global.h" #include "battle.h" #include "battle_ai_main.h" +#include "battle_ai_util.h" #include "battle_anim.h" #include "battle_controllers.h" #include "battle_message.h" @@ -1535,7 +1536,7 @@ static void PlayerPartnerHandleChooseMove(void) gBattlerTarget = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT); } - if (ShouldAIUseZMove(gActiveBattler, gBattlerTarget, moveInfo->moves[chosenMoveId])) + if (ShouldUseZMove(gActiveBattler, gBattlerTarget, moveInfo->moves[chosenMoveId])) QueueZMove(gActiveBattler, moveInfo->moves[chosenMoveId]); // If partner can mega evolve, do it. diff --git a/src/battle_z_move.c b/src/battle_z_move.c index 785563ff1..674082698 100644 --- a/src/battle_z_move.c +++ b/src/battle_z_move.c @@ -697,34 +697,3 @@ static bool32 AreStatsMaxed(u8 battlerId, u8 n) return TRUE; } -//TODO - this could use some more sophisticated logic -bool32 ShouldAIUseZMove(u8 battlerAtk, u8 battlerDef, u16 chosenMove) -{ - // simple logic. just upgrades chosen move to z move if possible, unless regular move would kill opponent - if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE) && battlerDef == BATTLE_PARTNER(battlerAtk)) - return FALSE; //don't use z move on partner - if (gBattleStruct->zmove.used[battlerAtk]) - return FALSE; //cant use z move twice - - if (IsViableZMove(battlerAtk, chosenMove)) - { - #ifdef POKEMON_EXPANSION - if (gBattleMons[battlerDef].ability == ABILITY_DISGUISE && gBattleMons[battlerDef].species == SPECIES_MIMIKYU) - return FALSE; // Don't waste a Z-Move busting disguise - if (gBattleMons[battlerDef].ability == ABILITY_ICE_FACE && gBattleMons[battlerDef].species == SPECIES_EISCUE && IS_MOVE_PHYSICAL(chosenMove)) - return FALSE; // Don't waste a Z-Move busting Ice Face - #endif - - if (IS_MOVE_STATUS(chosenMove) && !IS_MOVE_STATUS(gBattleStruct->zmove.chosenZMove)) - return FALSE; - else if (!IS_MOVE_STATUS(chosenMove) && IS_MOVE_STATUS(gBattleStruct->zmove.chosenZMove)) - return FALSE; - - if (!IS_MOVE_STATUS(chosenMove) && AI_CalcDamage(chosenMove, battlerAtk, battlerDef, FALSE) >= gBattleMons[battlerDef].hp) - return FALSE; // don't waste damaging z move if can otherwise faint target - - return TRUE; - } - - return FALSE; -}