diff --git a/include/battle_util.h b/include/battle_util.h index 7df18d98dee..4fde2ea341f 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -248,6 +248,7 @@ uq4_12_t CalcTypeEffectivenessMultiplier(u32 move, u32 moveType, u32 battlerAtk, uq4_12_t CalcPartyMonTypeEffectivenessMultiplier(u16 move, u16 speciesDef, u16 abilityDef); uq4_12_t GetTypeModifier(u32 atkType, u32 defType); uq4_12_t GetOverworldTypeEffectiveness(struct Pokemon *mon, u8 moveType); +void UpdateMoveResultFlags(uq4_12_t modifier, u16 *resultFlags); s32 GetStealthHazardDamage(enum TypeSideHazard hazardType, u32 battler); s32 GetStealthHazardDamageByTypesAndHP(enum TypeSideHazard hazardType, u8 type1, u8 type2, u32 maxHp); bool32 CanMegaEvolve(u32 battler); diff --git a/src/battle_ai_switch_items.c b/src/battle_ai_switch_items.c index 7522c7ec05a..24c8d34699e 100644 --- a/src/battle_ai_switch_items.c +++ b/src/battle_ai_switch_items.c @@ -727,6 +727,8 @@ static bool32 FindMonWithFlagsAndSuperEffective(u32 battler, u16 flags, u32 perc for (i = firstId; i < lastId; i++) { u16 species, monAbility; + uq4_12_t typeMultiplier; + u16 moveFlags = 0; if (!IsValidForBattle(&party[i])) continue; @@ -743,8 +745,9 @@ static bool32 FindMonWithFlagsAndSuperEffective(u32 battler, u16 flags, u32 perc species = GetMonData(&party[i], MON_DATA_SPECIES_OR_EGG); monAbility = GetMonAbility(&party[i]); - CalcPartyMonTypeEffectivenessMultiplier(gLastLandedMoves[battler], species, monAbility); - if (gBattleStruct->moveResultFlags[BATTLE_OPPOSITE(battler)] & flags) + typeMultiplier = CalcPartyMonTypeEffectivenessMultiplier(gLastLandedMoves[battler], species, monAbility); + UpdateMoveResultFlags(typeMultiplier, &moveFlags); + if (moveFlags & flags) { battlerIn1 = gLastHitBy[battler]; diff --git a/src/battle_util.c b/src/battle_util.c index 0c71240d53d..a6bf58b5326 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -10654,27 +10654,27 @@ static inline void TryNoticeIllusionInTypeEffectiveness(u32 move, u32 moveType, RecordAbilityBattle(battlerDef, ABILITY_ILLUSION); } -static void UpdateMoveResultFlags(uq4_12_t modifier, u32 battler) +void UpdateMoveResultFlags(uq4_12_t modifier, u16 *resultFlags) { if (modifier == UQ_4_12(0.0)) { - gBattleStruct->moveResultFlags[battler] |= MOVE_RESULT_DOESNT_AFFECT_FOE; - gBattleStruct->moveResultFlags[battler] &= ~(MOVE_RESULT_NOT_VERY_EFFECTIVE | MOVE_RESULT_SUPER_EFFECTIVE); + *resultFlags |= MOVE_RESULT_DOESNT_AFFECT_FOE; + *resultFlags &= ~(MOVE_RESULT_NOT_VERY_EFFECTIVE | MOVE_RESULT_SUPER_EFFECTIVE); gBattleStruct->blunderPolicy = FALSE; // Don't activate if missed } else if (modifier == UQ_4_12(1.0)) { - gBattleStruct->moveResultFlags[battler] &= ~(MOVE_RESULT_NOT_VERY_EFFECTIVE | MOVE_RESULT_SUPER_EFFECTIVE | MOVE_RESULT_DOESNT_AFFECT_FOE); + *resultFlags &= ~(MOVE_RESULT_NOT_VERY_EFFECTIVE | MOVE_RESULT_SUPER_EFFECTIVE | MOVE_RESULT_DOESNT_AFFECT_FOE); } else if (modifier > UQ_4_12(1.0)) { - gBattleStruct->moveResultFlags[battler] |= MOVE_RESULT_SUPER_EFFECTIVE; - gBattleStruct->moveResultFlags[battler] &= ~(MOVE_RESULT_NOT_VERY_EFFECTIVE | MOVE_RESULT_DOESNT_AFFECT_FOE); + *resultFlags |= MOVE_RESULT_SUPER_EFFECTIVE; + *resultFlags &= ~(MOVE_RESULT_NOT_VERY_EFFECTIVE | MOVE_RESULT_DOESNT_AFFECT_FOE); } else //if (modifier < UQ_4_12(1.0)) { - gBattleStruct->moveResultFlags[battler] |= MOVE_RESULT_NOT_VERY_EFFECTIVE; - gBattleStruct->moveResultFlags[battler] &= ~(MOVE_RESULT_SUPER_EFFECTIVE | MOVE_RESULT_DOESNT_AFFECT_FOE); + *resultFlags |= MOVE_RESULT_NOT_VERY_EFFECTIVE; + *resultFlags &= ~(MOVE_RESULT_SUPER_EFFECTIVE | MOVE_RESULT_DOESNT_AFFECT_FOE); } } @@ -10760,7 +10760,7 @@ uq4_12_t CalcTypeEffectivenessMultiplier(u32 move, u32 moveType, u32 battlerAtk, } if (recordAbilities) - UpdateMoveResultFlags(modifier, battlerDef); + UpdateMoveResultFlags(modifier, &gBattleStruct->moveResultFlags[battlerDef]); return modifier; } @@ -10781,7 +10781,6 @@ uq4_12_t CalcPartyMonTypeEffectivenessMultiplier(u16 move, u16 speciesDef, u16 a modifier = UQ_4_12(0.0); } - UpdateMoveResultFlags(modifier, speciesDef); return modifier; }