From 4466fbd930af4a7b32521936ca40220aaeb1dccc Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Wed, 3 Nov 2021 21:36:33 -0400 Subject: [PATCH 1/2] ai version of CanPoisonType, CanBePoisoned and IsAbilityOnSide --- include/battle_ai_util.h | 2 +- src/battle_ai_main.c | 2 +- src/battle_ai_util.c | 40 +++++++++++++++++++++++++++++++--------- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/include/battle_ai_util.h b/include/battle_ai_util.h index b8cd53c072..304a8149db 100644 --- a/include/battle_ai_util.h +++ b/include/battle_ai_util.h @@ -54,6 +54,7 @@ bool32 IsRecycleEncouragedItem(u16 item); bool32 CanKnockOffItem(u8 battler, u16 item); bool32 IsAbilityOfRating(u16 ability, s8 rating); s8 GetAbilityRating(u16 ability); +u32 AI_IsAbilityOnSide(u32 battlerId, u32 ability); // stat stage checks bool32 AnyStatIsRaised(u8 battlerId); @@ -120,7 +121,6 @@ bool32 IsSemiInvulnerable(u8 battlerDef, u16 move); // status checks bool32 AI_CanBeBurned(u8 battler, u16 ability); -bool32 AI_CanBePoisoned(u8 battler, u16 ability); bool32 AI_CanBeConfused(u8 battler, u16 ability); bool32 AI_CanSleep(u8 battler, u16 ability); bool32 IsBattlerIncapacitated(u8 battler, u16 ability); diff --git a/src/battle_ai_main.c b/src/battle_ai_main.c index 84fa7b6349..5263369472 100644 --- a/src/battle_ai_main.c +++ b/src/battle_ai_main.c @@ -3999,7 +3999,7 @@ static s16 AI_CheckViability(u8 battlerAtk, u8 battlerDef, u16 move, s16 score) score += 2; break; case HOLD_EFFECT_TOXIC_ORB: - if (!ShouldPoisonSelf(battlerAtk, AI_DATA->atkAbility) && AI_CanBePoisoned(battlerDef, AI_DATA->defAbility)) + if (!ShouldPoisonSelf(battlerAtk, AI_DATA->atkAbility)) score += 2; break; case HOLD_EFFECT_FLAME_ORB: diff --git a/src/battle_ai_util.c b/src/battle_ai_util.c index 9640df2b40..bf10666f60 100644 --- a/src/battle_ai_util.c +++ b/src/battle_ai_util.c @@ -1065,6 +1065,16 @@ bool32 CanTargetFaintAiWithMod(u8 battlerDef, u8 battlerAtk, s32 hpMod, s32 dmgM return FALSE; } +u32 AI_IsAbilityOnSide(u32 battlerId, u32 ability) +{ + if (IsBattlerAlive(battlerId) && AI_GetAbility(battlerId) == ability) + return battlerId + 1; + else if (IsBattlerAlive(BATTLE_PARTNER(battlerId)) && AI_GetAbility(BATTLE_PARTNER(battlerId)) == ability) + return BATTLE_PARTNER(battlerId) + 1; + else + return 0; +} + // does NOT include ability suppression checks s32 AI_GetAbility(u32 battlerId) { @@ -2613,20 +2623,32 @@ bool32 AI_CanPutToSleep(u8 battlerAtk, u8 battlerDef, u16 defAbility, u16 move, return TRUE; } -bool32 AI_CanBePoisoned(u8 battler, u16 ability) +static bool32 AI_CanPoisonType(u8 battlerAttacker, u8 battlerTarget) { - if (ability == ABILITY_IMMUNITY - || IsAbilityOnSide(battler, ABILITY_PASTEL_VEIL) - || gBattleMons[battler].status1 & STATUS1_ANY - || IsAbilityStatusProtected(battler) - || gSideStatuses[GetBattlerSide(battler)] & SIDE_STATUS_SAFEGUARD) + return ((AI_GetAbility(battlerAttacker) == ABILITY_CORROSION && gBattleMoves[gCurrentMove].split == SPLIT_STATUS) + || !(IS_BATTLER_OF_TYPE(battlerTarget, TYPE_POISON) || IS_BATTLER_OF_TYPE(battlerTarget, TYPE_STEEL))); +} + +static bool32 AI_CanBePoisoned(u8 battlerAtk, u8 battlerDef) +{ + u16 ability = AI_GetAbility(battlerDef); + + if (!(AI_CanPoisonType(battlerAtk, battlerDef)) + || gSideStatuses[GetBattlerSide(battlerDef)] & SIDE_STATUS_SAFEGUARD + || gBattleMons[battlerDef].status1 & STATUS1_ANY + || ability == ABILITY_IMMUNITY + || ability == ABILITY_COMATOSE + || AI_IsAbilityOnSide(battlerDef, ABILITY_PASTEL_VEIL) + || gBattleMons[battlerDef].status1 & STATUS1_ANY + || IsAbilityStatusProtected(battlerDef) + || AI_IsTerrainAffected(battlerDef, STATUS_FIELD_MISTY_TERRAIN)) return FALSE; return TRUE; } bool32 ShouldPoisonSelf(u8 battler, u16 ability) { - if (AI_CanBePoisoned(battler, ability) && ( + if (AI_CanBePoisoned(battler, battler) && ( ability == ABILITY_MARVEL_SCALE || ability == ABILITY_POISON_HEAL || ability == ABILITY_QUICK_FEET @@ -2641,7 +2663,7 @@ bool32 ShouldPoisonSelf(u8 battler, u16 ability) bool32 AI_CanPoison(u8 battlerAtk, u8 battlerDef, u16 defAbility, u16 move, u16 partnerMove) { - if (!AI_CanBePoisoned(battlerDef, defAbility) + if (!AI_CanBePoisoned(battlerAtk, battlerDef) || AI_GetMoveEffectiveness(move, battlerAtk, battlerDef) == AI_EFFECTIVENESS_x0 || DoesSubstituteBlockMove(battlerAtk, battlerDef, move) || PartnerMoveEffectIsStatusSameTarget(BATTLE_PARTNER(battlerAtk), battlerDef, partnerMove)) @@ -2744,7 +2766,7 @@ bool32 AI_CanBeInfatuated(u8 battlerAtk, u8 battlerDef, u16 defAbility, u8 atkGe || atkGender == defGender || atkGender == MON_GENDERLESS || defGender == MON_GENDERLESS - || IsAbilityOnSide(battlerDef, ABILITY_AROMA_VEIL)) + || AI_IsAbilityOnSide(battlerDef, ABILITY_AROMA_VEIL)) return FALSE; return TRUE; } From 6b10801ee8f511d5cd3ed413c8016274798c94c9 Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Thu, 4 Nov 2021 10:43:33 -0400 Subject: [PATCH 2/2] convert AI_IsabilityOnSide to bool --- include/battle_ai_util.h | 2 +- src/battle_ai_util.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/battle_ai_util.h b/include/battle_ai_util.h index 304a8149db..b6df2168ea 100644 --- a/include/battle_ai_util.h +++ b/include/battle_ai_util.h @@ -54,7 +54,7 @@ bool32 IsRecycleEncouragedItem(u16 item); bool32 CanKnockOffItem(u8 battler, u16 item); bool32 IsAbilityOfRating(u16 ability, s8 rating); s8 GetAbilityRating(u16 ability); -u32 AI_IsAbilityOnSide(u32 battlerId, u32 ability); +bool32 AI_IsAbilityOnSide(u32 battlerId, u32 ability); // stat stage checks bool32 AnyStatIsRaised(u8 battlerId); diff --git a/src/battle_ai_util.c b/src/battle_ai_util.c index bf10666f60..a080349799 100644 --- a/src/battle_ai_util.c +++ b/src/battle_ai_util.c @@ -1065,14 +1065,14 @@ bool32 CanTargetFaintAiWithMod(u8 battlerDef, u8 battlerAtk, s32 hpMod, s32 dmgM return FALSE; } -u32 AI_IsAbilityOnSide(u32 battlerId, u32 ability) +bool32 AI_IsAbilityOnSide(u32 battlerId, u32 ability) { if (IsBattlerAlive(battlerId) && AI_GetAbility(battlerId) == ability) - return battlerId + 1; + return TRUE; else if (IsBattlerAlive(BATTLE_PARTNER(battlerId)) && AI_GetAbility(BATTLE_PARTNER(battlerId)) == ability) - return BATTLE_PARTNER(battlerId) + 1; + return TRUE; else - return 0; + return FALSE; } // does NOT include ability suppression checks