Review comments. Commented code removed, ShouldAIUseZMove moved to battle_ai_util and renamed to be consistent with other fns

This commit is contained in:
ExpoSeed 2022-03-22 13:10:24 -05:00
parent f50a406b18
commit 5fd468f507
7 changed files with 37 additions and 36 deletions

View File

@ -9217,8 +9217,6 @@ BattleScript_ZMoveActivateStatus::
printstring STRINGID_ZPOWERSURROUNDS printstring STRINGID_ZPOWERSURROUNDS
playanimation BS_ATTACKER, B_ANIM_ZMOVE_ACTIVATE, NULL playanimation BS_ATTACKER, B_ANIM_ZMOVE_ACTIVATE, NULL
setzeffect setzeffect
@ printstring STRINGID_ZMOVEUNLEASHED
@ waitmessage 0x40
return return
BattleScript_ZEffectPrintString:: BattleScript_ZEffectPrintString::

View File

@ -60,6 +60,7 @@ bool32 IsAbilityOfRating(u16 ability, s8 rating);
s8 GetAbilityRating(u16 ability); s8 GetAbilityRating(u16 ability);
bool32 AI_IsAbilityOnSide(u32 battlerId, u32 ability); bool32 AI_IsAbilityOnSide(u32 battlerId, u32 ability);
bool32 AI_MoveMakesContact(u32 ability, u32 holdEffect, u16 move); bool32 AI_MoveMakesContact(u32 ability, u32 holdEffect, u16 move);
bool32 ShouldUseZMove(u8 activeId, u8 targetId, u16 chosenMove);
// stat stage checks // stat stage checks
bool32 AnyStatIsRaised(u8 battlerId); bool32 AnyStatIsRaised(u8 battlerId);

View File

@ -23,7 +23,6 @@ void DestroyZMoveTriggerSprite(void);
bool32 MoveSelectionDisplayZMove(u16 zmove); bool32 MoveSelectionDisplayZMove(u16 zmove);
const u8* GetZMoveName(u16 move); const u8* GetZMoveName(u16 move);
void SetZEffect(void); void SetZEffect(void);
bool32 ShouldAIUseZMove(u8 activeId, u8 targetId, u16 chosenMove);
bool32 IsZMoveUsable(u8 battlerId, u16 moveIndex); bool32 IsZMoveUsable(u8 battlerId, u16 moveIndex);
void GetUsableZMoves(u8 battlerId, u16 *moves); void GetUsableZMoves(u8 battlerId, u16 *moves);

View File

@ -3636,3 +3636,35 @@ bool32 AI_MoveMakesContact(u32 ability, u32 holdEffect, u16 move)
return TRUE; return TRUE;
return FALSE; 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;
}

View File

@ -1,6 +1,7 @@
#include "global.h" #include "global.h"
#include "battle.h" #include "battle.h"
#include "battle_ai_main.h" #include "battle_ai_main.h"
#include "battle_ai_util.h"
#include "battle_anim.h" #include "battle_anim.h"
#include "battle_arena.h" #include "battle_arena.h"
#include "battle_controllers.h" #include "battle_controllers.h"
@ -1597,7 +1598,7 @@ static void OpponentHandleChooseMove(void)
gBattlerTarget = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT); gBattlerTarget = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT);
} }
if (ShouldAIUseZMove(gActiveBattler, gBattlerTarget, chosenMove)) if (ShouldUseZMove(gActiveBattler, gBattlerTarget, chosenMove))
QueueZMove(gActiveBattler, moveInfo->moves[chosenMoveId]); QueueZMove(gActiveBattler, moveInfo->moves[chosenMoveId]);
if (CanMegaEvolve(gActiveBattler)) // If opponent can mega evolve, do it. if (CanMegaEvolve(gActiveBattler)) // If opponent can mega evolve, do it.

View File

@ -1,6 +1,7 @@
#include "global.h" #include "global.h"
#include "battle.h" #include "battle.h"
#include "battle_ai_main.h" #include "battle_ai_main.h"
#include "battle_ai_util.h"
#include "battle_anim.h" #include "battle_anim.h"
#include "battle_controllers.h" #include "battle_controllers.h"
#include "battle_message.h" #include "battle_message.h"
@ -1535,7 +1536,7 @@ static void PlayerPartnerHandleChooseMove(void)
gBattlerTarget = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT); 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]); QueueZMove(gActiveBattler, moveInfo->moves[chosenMoveId]);
// If partner can mega evolve, do it. // If partner can mega evolve, do it.

View File

@ -697,34 +697,3 @@ static bool32 AreStatsMaxed(u8 battlerId, u8 n)
return TRUE; 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;
}