ShouldPivot type cleanup (#5441)

* Cleanup ShouldPivot type

* PIVOT to SHOULD_PIVOT
This commit is contained in:
Pawkkie 2024-10-10 06:54:35 -04:00 committed by GitHub
parent 806321f3c8
commit 2afc7f6138
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 30 additions and 28 deletions

View file

@ -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);
@ -65,7 +72,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);

View file

@ -3634,12 +3634,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;
}

View file

@ -2685,12 +2685,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;
@ -2707,7 +2702,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
{
@ -2717,14 +2712,14 @@ 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)
{
@ -2732,17 +2727,17 @@ bool32 ShouldPivot(u32 battlerAtk, u32 battlerDef, u32 defAbility, u32 move, u32
|| (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)
{
@ -2753,20 +2748,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;
}*/
}
}
@ -2789,7 +2784,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
@ -2815,17 +2810,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)
{
@ -2836,17 +2831,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;
}
}*/