mirror of
https://github.com/rh-hideout/pokeemerald-expansion.git
synced 2026-04-26 02:14:22 -05:00
Small code deduplication in battle_ai_switch.c (#8790)
This commit is contained in:
commit
52455d2c59
|
|
@ -1074,9 +1074,9 @@ extern u8 gCategoryIconSpriteId;
|
|||
|
||||
static inline bool32 IsBattlerAlive(u32 battler)
|
||||
{
|
||||
if (gBattleMons[battler].hp == 0)
|
||||
if (battler >= gBattlersCount)
|
||||
return FALSE;
|
||||
else if (battler >= gBattlersCount)
|
||||
else if (gBattleMons[battler].hp == 0)
|
||||
return FALSE;
|
||||
else if (gAbsentBattlerFlags & (1u << battler))
|
||||
return FALSE;
|
||||
|
|
|
|||
|
|
@ -923,42 +923,35 @@ static bool32 ShouldSwitchIfAbilityBenefit(u32 battler)
|
|||
return SetSwitchinAndSwitch(battler, PARTY_SIZE);
|
||||
}
|
||||
|
||||
static bool32 CanUseSuperEffectiveMoveAgainstOpponents(u32 battler)
|
||||
static bool32 CanUseSuperEffectiveMoveAgainstOpponent(u32 battler, u32 opposingBattler)
|
||||
{
|
||||
enum Move move;
|
||||
|
||||
if (!IsBattlerAlive(opposingBattler))
|
||||
return FALSE;
|
||||
|
||||
for (u32 moveIndex = 0; moveIndex < MAX_MON_MOVES; moveIndex++)
|
||||
{
|
||||
move = gBattleMons[battler].moves[moveIndex];
|
||||
if (move == MOVE_NONE || AI_DoesChoiceEffectBlockMove(battler, move))
|
||||
continue;
|
||||
|
||||
if (gAiLogicData->effectiveness[battler][opposingBattler][moveIndex] >= UQ_4_12(2.0))
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static bool32 CanUseSuperEffectiveMoveAgainstOpponents(u32 battler)
|
||||
{
|
||||
u32 opposingPosition = BATTLE_OPPOSITE(GetBattlerPosition(battler));
|
||||
u32 opposingBattler = GetBattlerAtPosition(opposingPosition);
|
||||
|
||||
if (!(gAbsentBattlerFlags & (1u << opposingBattler)))
|
||||
{
|
||||
for (u32 moveIndex = 0; moveIndex < MAX_MON_MOVES; moveIndex++)
|
||||
{
|
||||
move = gBattleMons[battler].moves[moveIndex];
|
||||
if (move == MOVE_NONE || AI_DoesChoiceEffectBlockMove(battler, move))
|
||||
continue;
|
||||
if (CanUseSuperEffectiveMoveAgainstOpponent(battler, opposingBattler))
|
||||
return TRUE;
|
||||
|
||||
if (gAiLogicData->effectiveness[battler][opposingBattler][moveIndex] >= UQ_4_12(2.0))
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
if (!IsDoubleBattle())
|
||||
return FALSE;
|
||||
|
||||
opposingBattler = BATTLE_PARTNER(opposingPosition);
|
||||
|
||||
if (!(gAbsentBattlerFlags & (1u << opposingBattler)))
|
||||
{
|
||||
for (u32 moveIndex = 0; moveIndex < MAX_MON_MOVES; moveIndex++)
|
||||
{
|
||||
move = gBattleMons[battler].moves[moveIndex];
|
||||
if (move == MOVE_NONE || AI_DoesChoiceEffectBlockMove(battler, move))
|
||||
continue;
|
||||
|
||||
if (gAiLogicData->effectiveness[battler][opposingBattler][moveIndex] >= UQ_4_12(2.0))
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
if (IsDoubleBattle() && CanUseSuperEffectiveMoveAgainstOpponent(battler, BATTLE_PARTNER(opposingPosition)))
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user