Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ShouldPivot type cleanup #5441

Merged
merged 3 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion include/battle_ai_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ enum DamageRollType
DMG_ROLL_HIGHEST,
};

enum AIPivot
{
DONT_PIVOT,
CAN_TRY_PIVOT,
SHOULD_PIVOT,
};

bool32 AI_IsFaster(u32 battlerAi, u32 battlerDef, u32 move);
bool32 AI_IsSlower(u32 battlerAi, u32 battlerDef, u32 move);
bool32 AI_RandLessThan(u32 val);
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/battle_ai_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3662,12 +3662,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 SHOULD_PIVOT:
ADJUST_SCORE(BEST_EFFECT);
break;
}
Expand Down
43 changes: 19 additions & 24 deletions src/battle_ai_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -2696,12 +2696,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
u32 battlerToSwitch;
Expand All @@ -2718,7 +2713,7 @@ bool32 ShouldPivot(u32 battlerAtk, u32 battlerDef, u32 defAbility, u32 move, u32

//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
{
Expand All @@ -2728,32 +2723,32 @@ bool32 ShouldPivot(u32 battlerAtk, u32 battlerDef, u32 defAbility, u32 move, u32
{
// 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) && ((AI_DATA->shouldSwitch & (1u << battlerAtk))
|| (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)
{
if (!IS_MOVE_STATUS(move) && (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

if (AI_DATA->shouldSwitch & (1u << battlerAtk))
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)
{
Expand All @@ -2764,20 +2759,20 @@ bool32 ShouldPivot(u32 battlerAtk, u32 battlerDef, u32 defAbility, u32 move, u32
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;
}*/
}
}
Expand All @@ -2800,7 +2795,7 @@ bool32 ShouldPivot(u32 battlerAtk, u32 battlerDef, u32 defAbility, u32 move, u32
}
else // Can't KO the foe
{
return PIVOT;
return SHOULD_PIVOT;
}
}
else // Foe can 3HKO+ AI
Expand All @@ -2826,17 +2821,17 @@ bool32 ShouldPivot(u32 battlerAtk, u32 battlerDef, u32 defAbility, u32 move, u32
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)
{
Expand All @@ -2847,17 +2842,17 @@ bool32 ShouldPivot(u32 battlerAtk, u32 battlerDef, u32 defAbility, u32 move, u32
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;
}
}*/

Expand Down
Loading