AI_IsTerrainAffected checks

This commit is contained in:
ghoulslash 2021-07-10 16:41:41 -06:00
parent 4d1c63e3d3
commit 59c16ff1cf
3 changed files with 17 additions and 8 deletions

View File

@ -36,6 +36,7 @@ u32 AI_GetMoveAccuracy(u8 battlerAtk, u8 battlerDef, u16 atkAbility, u16 defAbil
bool32 DoesBattlerIgnoreAbilityChecks(u16 atkAbility, u16 move);
bool32 AI_WeatherHasEffect(void);
bool32 CanAttackerFaintTarget(u8 battlerAtk, u8 battlerDef, u8 index, u8 numHits);
bool32 AI_IsTerrainAffected(u8 battlerId, u32 flags);
bool32 AI_IsBattlerGrounded(u8 battlerId);
bool32 HasDamagingMove(u8 battlerId);
bool32 HasDamagingMoveOfType(u8 battlerId, u8 type);

View File

@ -721,21 +721,20 @@ static s16 AI_CheckBadMove(u8 battlerAtk, u8 battlerDef, u16 move, s16 score)
#endif
// terrain & effect checks
if (gFieldStatuses & STATUS_FIELD_MISTY_TERRAIN)
if (AI_IsTerrainAffected(battlerDef, STATUS_FIELD_ELECTRIC_TERRAIN))
{
if (moveEffect == EFFECT_SLEEP || moveEffect == EFFECT_YAWN)
RETURN_SCORE_MINUS(20);
}
if (gFieldStatuses & STATUS_FIELD_ELECTRIC_TERRAIN)
if (AI_IsTerrainAffected(battlerDef, STATUS_FIELD_MISTY_TERRAIN))
{
if (IsNonVolatileStatusMoveEffect(moveEffect) || IsConfusionMoveEffect(moveEffect))
RETURN_SCORE_MINUS(20);
}
if (gFieldStatuses & STATUS_FIELD_PSYCHIC_TERRAIN)
if (AI_IsTerrainAffected(battlerAtk, STATUS_FIELD_PSYCHIC_TERRAIN) && atkPriority > 0)
{
if (atkPriority > 0)
RETURN_SCORE_MINUS(20);
}
} // end check MOVE_TARGET_USER
@ -1641,11 +1640,11 @@ static s16 AI_CheckBadMove(u8 battlerAtk, u8 battlerDef, u16 move, s16 score)
case EFFECT_TEETER_DANCE:
if (((gBattleMons[battlerDef].status2 & STATUS2_CONFUSION)
|| (!DoesBattlerIgnoreAbilityChecks(AI_DATA->atkAbility, move) && AI_DATA->defAbility == ABILITY_OWN_TEMPO)
|| (IsBattlerGrounded(battlerDef) && (gFieldStatuses & STATUS_FIELD_MISTY_TERRAIN))
|| (IsBattlerGrounded(battlerDef) && AI_IsTerrainAffected(battlerDef, STATUS_FIELD_MISTY_TERRAIN))
|| (DoesSubstituteBlockMove(battlerAtk, battlerDef, move)))
&& ((gBattleMons[AI_DATA->battlerDefPartner].status2 & STATUS2_CONFUSION)
|| (!DoesBattlerIgnoreAbilityChecks(AI_DATA->atkAbility, move) && AI_DATA->defPartnerAbility == ABILITY_OWN_TEMPO)
|| (IsBattlerGrounded(AI_DATA->battlerDefPartner) && (gFieldStatuses & STATUS_FIELD_MISTY_TERRAIN))
|| (IsBattlerGrounded(AI_DATA->battlerDefPartner) && AI_IsTerrainAffected(AI_DATA->battlerDefPartner, STATUS_FIELD_MISTY_TERRAIN))
|| (DoesSubstituteBlockMove(battlerAtk, AI_DATA->battlerDefPartner, move))))
{
score -= 10;
@ -3836,7 +3835,7 @@ static s16 AI_CheckViability(u8 battlerAtk, u8 battlerDef, u16 move, s16 score)
score++;
break;
case EFFECT_SAFEGUARD:
if (!(gFieldStatuses & STATUS_FIELD_MISTY_TERRAIN) || !IsBattlerGrounded(battlerAtk))
if (!AI_IsTerrainAffected(battlerAtk, STATUS_FIELD_MISTY_TERRAIN) || !IsBattlerGrounded(battlerAtk))
score++;
//if (CountUsablePartyMons(battlerDef) != 0)
//score += 8;

View File

@ -1110,6 +1110,15 @@ u16 AI_GetHoldEffect(u32 battlerId)
return holdEffect;
}
bool32 AI_IsTerrainAffected(u8 battlerId, u32 flags)
{
if (gStatuses3[battlerId] & STATUS3_SEMI_INVULNERABLE)
return FALSE;
else if (!(gFieldStatuses & flags))
return FALSE;
return AI_IsBattlerGrounded(battlerId);
}
// different from IsBattlerGrounded in that we don't always know battler's hold effect or ability
bool32 AI_IsBattlerGrounded(u8 battlerId)
{