From 3a59a83662acdb14ed5502633b506528b11c92ff Mon Sep 17 00:00:00 2001 From: Pawkkie Date: Sun, 29 Sep 2024 08:49:57 -0400 Subject: [PATCH 1/2] Cleanup ShouldPivot type --- include/battle_ai_util.h | 9 ++++++++- src/battle_ai_main.c | 6 +++--- src/battle_ai_util.c | 7 +------ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/include/battle_ai_util.h b/include/battle_ai_util.h index 5fecdd5f47e8..d4998b74e9b0 100644 --- a/include/battle_ai_util.h +++ b/include/battle_ai_util.h @@ -15,6 +15,13 @@ enum DamageRollType DMG_ROLL_HIGHEST, }; +enum AIPivot +{ + DONT_PIVOT, + CAN_TRY_PIVOT, + PIVOT, +}; + bool32 AI_IsFaster(u32 battlerAi, u32 battlerDef, u32 move); bool32 AI_IsSlower(u32 battlerAi, u32 battlerDef, u32 move); bool32 AI_RandLessThan(u32 val); @@ -64,7 +71,7 @@ u32 GetBattlerSideSpeedAverage(u32 battler); bool32 ShouldAbsorb(u32 battlerAtk, u32 battlerDef, u32 move, s32 damage); bool32 ShouldRecover(u32 battlerAtk, u32 battlerDef, u32 move, u32 healPercent); bool32 ShouldSetScreen(u32 battlerAtk, u32 battlerDef, u32 moveEffect); -bool32 ShouldPivot(u32 battlerAtk, u32 battlerDef, u32 defAbility, u32 move, u32 moveIndex); +enum AIPivot ShouldPivot(u32 battlerAtk, u32 battlerDef, u32 defAbility, u32 move, u32 moveIndex); bool32 IsRecycleEncouragedItem(u32 item); bool32 ShouldRestoreHpBerry(u32 battlerAtk, u32 item); bool32 IsStatBoostingBerry(u32 item); diff --git a/src/battle_ai_main.c b/src/battle_ai_main.c index af6557e967fa..52ba382af87e 100644 --- a/src/battle_ai_main.c +++ b/src/battle_ai_main.c @@ -3659,12 +3659,12 @@ static u32 AI_CalcMoveEffectScore(u32 battlerAtk, u32 battlerDef, u32 move) { switch (ShouldPivot(battlerAtk, battlerDef, aiData->abilities[battlerDef], move, movesetIndex)) { - case 0: // no + case DONT_PIVOT: ADJUST_SCORE(-10); // technically should go in CheckBadMove, but this is easier/less computationally demanding break; - case 1: // maybe + case CAN_TRY_PIVOT: break; - case 2: // yes + case PIVOT: ADJUST_SCORE(BEST_EFFECT); break; } diff --git a/src/battle_ai_util.c b/src/battle_ai_util.c index 3f08ace39321..7f1546149bae 100644 --- a/src/battle_ai_util.c +++ b/src/battle_ai_util.c @@ -2691,12 +2691,7 @@ static bool32 PartyBattlerShouldAvoidHazards(u32 currBattler, u32 switchBattler) return FALSE; } -enum { - DONT_PIVOT, - CAN_TRY_PIVOT, - PIVOT, -}; -bool32 ShouldPivot(u32 battlerAtk, u32 battlerDef, u32 defAbility, u32 move, u32 moveIndex) +enum AIPivot ShouldPivot(u32 battlerAtk, u32 battlerDef, u32 defAbility, u32 move, u32 moveIndex) { bool32 hasStatBoost = AnyUsefulStatIsRaised(battlerAtk) || gBattleMons[battlerDef].statStages[STAT_EVASION] >= 9; //Significant boost in evasion for any class bool32 shouldSwitch; From de87942668070907a96b905793f85e94c30f2e87 Mon Sep 17 00:00:00 2001 From: Pawkkie Date: Tue, 1 Oct 2024 09:01:14 -0400 Subject: [PATCH 2/2] PIVOT to SHOULD_PIVOT --- include/battle_ai_util.h | 2 +- src/battle_ai_main.c | 2 +- src/battle_ai_util.c | 36 ++++++++++++++++++------------------ 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/include/battle_ai_util.h b/include/battle_ai_util.h index d4998b74e9b0..2e36e851e571 100644 --- a/include/battle_ai_util.h +++ b/include/battle_ai_util.h @@ -19,7 +19,7 @@ enum AIPivot { DONT_PIVOT, CAN_TRY_PIVOT, - PIVOT, + SHOULD_PIVOT, }; bool32 AI_IsFaster(u32 battlerAi, u32 battlerDef, u32 move); diff --git a/src/battle_ai_main.c b/src/battle_ai_main.c index 52ba382af87e..75bd7d2d1127 100644 --- a/src/battle_ai_main.c +++ b/src/battle_ai_main.c @@ -3664,7 +3664,7 @@ static u32 AI_CalcMoveEffectScore(u32 battlerAtk, u32 battlerDef, u32 move) break; case CAN_TRY_PIVOT: break; - case PIVOT: + case SHOULD_PIVOT: ADJUST_SCORE(BEST_EFFECT); break; } diff --git a/src/battle_ai_util.c b/src/battle_ai_util.c index 7f1546149bae..e0cd5c645fce 100644 --- a/src/battle_ai_util.c +++ b/src/battle_ai_util.c @@ -2710,7 +2710,7 @@ enum AIPivot ShouldPivot(u32 battlerAtk, u32 battlerDef, u32 defAbility, u32 mov //TODO - predict opponent switching /*if (IsPredictedToSwitch(battlerDef, battlerAtk) && !hasStatBoost) - return PIVOT; // Try pivoting so you can switch to a better matchup to counter your new opponent*/ + return SHOULD_PIVOT; // Try pivoting so you can switch to a better matchup to counter your new opponent*/ if (AI_IsFaster(battlerAtk, battlerDef, move)) // Attacker goes first { @@ -2720,14 +2720,14 @@ enum AIPivot ShouldPivot(u32 battlerAtk, u32 battlerDef, u32 defAbility, u32 mov { // attacker can kill target in two hits (theoretically) if (CanTargetFaintAi(battlerDef, battlerAtk)) - return PIVOT; // Won't get the two turns, pivot + return SHOULD_PIVOT; // Won't get the two turns, pivot if (!IS_MOVE_STATUS(move) && (shouldSwitch || (AtMaxHp(battlerDef) && (AI_DATA->holdEffects[battlerDef] == HOLD_EFFECT_FOCUS_SASH || (B_STURDY >= GEN_5 && defAbility == ABILITY_STURDY) || defAbility == ABILITY_MULTISCALE || defAbility == ABILITY_SHADOW_SHIELD)))) - return PIVOT; // pivot to break sash/sturdy/multiscale + return SHOULD_PIVOT; // pivot to break sash/sturdy/multiscale } else if (!hasStatBoost) { @@ -2735,17 +2735,17 @@ enum AIPivot ShouldPivot(u32 battlerAtk, u32 battlerDef, u32 defAbility, u32 mov || (B_STURDY >= GEN_5 && defAbility == ABILITY_STURDY) || defAbility == ABILITY_MULTISCALE || defAbility == ABILITY_SHADOW_SHIELD))) - return PIVOT; // pivot to break sash/sturdy/multiscale + return SHOULD_PIVOT; // pivot to break sash/sturdy/multiscale if (shouldSwitch) - return PIVOT; + return SHOULD_PIVOT; /* TODO - check if switchable mon unafffected by/will remove hazards if (gSideStatuses[battlerAtk] & SIDE_STATUS_SPIKES && switchScore >= SWITCHING_INCREASE_CAN_REMOVE_HAZARDS) - return PIVOT;*/ + return SHOULD_PIVOT;*/ /*if (BattlerWillFaintFromSecondaryDamage(battlerAtk, AI_DATA->abilities[battlerAtk]) && switchScore >= SWITCHING_INCREASE_WALLS_FOE) - return PIVOT;*/ + return SHOULD_PIVOT;*/ /*if (IsClassDamager(class) && switchScore >= SWITCHING_INCREASE_HAS_SUPER_EFFECTIVE_MOVE) { @@ -2756,20 +2756,20 @@ enum AIPivot ShouldPivot(u32 battlerAtk, u32 battlerDef, u32 defAbility, u32 mov if (physMoveInMoveset && !specMoveInMoveset) { if (STAT_STAGE_ATK < 6) - return PIVOT; + return SHOULD_PIVOT; } else if (!physMoveInMoveset && specMoveInMoveset) { if (STAT_STAGE_SPATK < 6) - return PIVOT; + return SHOULD_PIVOT; } else if (physMoveInMoveset && specMoveInMoveset) { if (STAT_STAGE_ATK < 6 && STAT_STAGE_SPATK < 6) - return PIVOT; + return SHOULD_PIVOT; } - return CAN_TRY_PIVOT; + return SHOULD_PIVOT; }*/ } } @@ -2792,7 +2792,7 @@ enum AIPivot ShouldPivot(u32 battlerAtk, u32 battlerDef, u32 defAbility, u32 mov } else // Can't KO the foe { - return PIVOT; + return SHOULD_PIVOT; } } else // Foe can 3HKO+ AI @@ -2818,17 +2818,17 @@ enum AIPivot ShouldPivot(u32 battlerAtk, u32 battlerDef, u32 defAbility, u32 mov else { //if (IsClassDamager(class) && switchScore >= SWITCHING_INCREASE_KO_FOE) - //return PIVOT; //Only switch if way better matchup + //return SHOULD_PIVOT; //Only switch if way better matchup if (!hasStatBoost) { // TODO - check if switching prevents/removes hazards //if (gSideStatuses[battlerAtk] & SIDE_STATUS_SPIKES && switchScore >= SWITCHING_INCREASE_CAN_REMOVE_HAZARDS) - //return PIVOT; + //return SHOULD_PIVOT; // TODO - not always a good idea //if (BattlerWillFaintFromSecondaryDamage(battlerAtk) && switchScore >= SWITCHING_INCREASE_HAS_SUPER_EFFECTIVE_MOVE) - //return PIVOT; + //return SHOULD_PIVOT; /*if (IsClassDamager(class) && switchScore >= SWITCHING_INCREASE_HAS_SUPER_EFFECTIVE_MOVE) { @@ -2839,17 +2839,17 @@ enum AIPivot ShouldPivot(u32 battlerAtk, u32 battlerDef, u32 defAbility, u32 mov if (physMoveInMoveset && !specMoveInMoveset) { if (STAT_STAGE_ATK < 6) - return PIVOT; + return SHOULD_PIVOT; } else if (!physMoveInMoveset && specMoveInMoveset) { if (STAT_STAGE_SPATK < 6) - return PIVOT; + return SHOULD_PIVOT; } else if (physMoveInMoveset && specMoveInMoveset) { if (STAT_STAGE_ATK < 6 && STAT_STAGE_SPATK < 6) - return PIVOT; + return SHOULD_PIVOT; } }*/