Skip to content

Commit

Permalink
Focus Punch score handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Pawkkie committed Jan 15, 2025
1 parent 7ed9666 commit d586627
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions include/battle_ai_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,6 @@ void IncreaseTidyUpScore(u32 battlerAtk, u32 battlerDef, u32 move, s32 *score);
bool32 AI_ShouldSpicyExtract(u32 battlerAtk, u32 battlerAtkPartner, u32 move, struct AiLogicData *aiData);
void IncreaseSubstituteMoveScore(u32 battlerAtk, u32 battlerDef, u32 move, s32 *score);
bool32 IsBattlerPredictedToSwitch(u32 battler);
s32 AdjustFocusPunchScore(u32 battlerAtk, u32 battlerDef, s32 score, s32 adjustment);

#endif //GUARD_BATTLE_AI_UTIL_H
14 changes: 3 additions & 11 deletions src/battle_ai_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1318,15 +1318,7 @@ static s32 AI_CheckBadMove(u32 battlerAtk, u32 battlerDef, u32 move, s32 score)
case EFFECT_PRESENT:
case EFFECT_FIXED_DAMAGE_ARG:
case EFFECT_FOCUS_PUNCH:
// AI_CBM_HighRiskForDamage
if (aiData->abilities[battlerDef] == ABILITY_WONDER_GUARD && effectiveness < AI_EFFECTIVENESS_x2)
ADJUST_SCORE(-10);
else if (HasDamagingMove(battlerDef) && !((gBattleMons[battlerAtk].status2 & STATUS2_SUBSTITUTE)
|| IsBattlerIncapacitated(battlerDef, aiData->abilities[battlerDef])
|| gBattleMons[battlerDef].status2 & (STATUS2_INFATUATION | STATUS2_CONFUSION)))
ADJUST_SCORE(-10);
else if (HasMoveEffect(battlerAtk, EFFECT_SUBSTITUTE) && !(gBattleMons[battlerAtk].status2 & STATUS2_SUBSTITUTE))
ADJUST_SCORE(-10);
score = AdjustFocusPunchScore(battlerAtk, battlerDef, score, -10);
break;
case EFFECT_COUNTER:
case EFFECT_MIRROR_COAT:
Expand Down Expand Up @@ -5279,9 +5271,9 @@ static s32 AI_PredictSwitch(u32 battlerAtk, u32 battlerDef, u32 move, s32 score)
break;

case EFFECT_FOCUS_PUNCH:
ADJUST_SCORE(DECENT_EFFECT);
if (AI_THINKING_STRUCT->aiFlags[battlerAtk] & AI_FLAG_CHECK_BAD_MOVE)
ADJUST_SCORE(10);
score = AdjustFocusPunchScore(battlerAtk, battlerDef, score, 10);
ADJUST_SCORE(DECENT_EFFECT);
break;

// Free setup (U-Turn etc. handled in Check Viability by ShouldPivot)
Expand Down
16 changes: 16 additions & 0 deletions src/battle_ai_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -4213,3 +4213,19 @@ void IncreaseSubstituteMoveScore(u32 battlerAtk, u32 battlerDef, u32 move, s32 *
if (AI_DATA->hpPercents[battlerAtk] > 70)
ADJUST_SCORE_PTR(WEAK_EFFECT);
}

s32 AdjustFocusPunchScore(u32 battlerAtk, u32 battlerDef, s32 score, s32 adjustment)
{
struct AiLogicData *aiData = AI_DATA;
u32 effectiveness = aiData->effectiveness[battlerAtk][battlerDef][AI_THINKING_STRUCT->movesetIndex];

if (aiData->abilities[battlerDef] == ABILITY_WONDER_GUARD && effectiveness < AI_EFFECTIVENESS_x2)
ADJUST_SCORE(adjustment);
else if (HasDamagingMove(battlerDef) && !((gBattleMons[battlerAtk].status2 & STATUS2_SUBSTITUTE)
|| IsBattlerIncapacitated(battlerDef, aiData->abilities[battlerDef])
|| gBattleMons[battlerDef].status2 & (STATUS2_INFATUATION | STATUS2_CONFUSION)))
ADJUST_SCORE(adjustment);
else if (HasMoveEffect(battlerAtk, EFFECT_SUBSTITUTE) && !(gBattleMons[battlerAtk].status2 & STATUS2_SUBSTITUTE))
ADJUST_SCORE(adjustment);
return score;
}

0 comments on commit d586627

Please sign in to comment.