diff --git a/include/battle_util.h b/include/battle_util.h index 96ffc2fa16c0..b5ba5249ea2c 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -212,6 +212,8 @@ bool8 IsMoveAffectedByParentalBond(u16 move, u8 battlerId); void CopyMonLevelAndBaseStatsToBattleMon(u32 battler, struct Pokemon *mon); void CopyMonAbilityAndTypesToBattleMon(u32 battler, struct Pokemon *mon); void RecalcBattlerStats(u32 battler, struct Pokemon *mon); +void MulModifier(u16 *modifier, u16 val); + // Ability checks bool32 IsRolePlayBannedAbilityAtk(u16 ability); bool32 IsRolePlayBannedAbility(u16 ability); diff --git a/src/battle_ai_switch_items.c b/src/battle_ai_switch_items.c index d7fd062ba212..cd9c173a9573 100644 --- a/src/battle_ai_switch_items.c +++ b/src/battle_ai_switch_items.c @@ -822,7 +822,7 @@ static u32 GetBestMonTypeMatchup(struct Pokemon *party, int firstId, int lastId, while (bits != 0x3F) // All mons were checked. { - u32 bestResist = UQ_4_12(1.0); + u16 bestResist = UQ_4_12(1.0); int bestMonId = PARTY_SIZE; // Find the mon whose type is the most suitable defensively. for (i = firstId; i < lastId; i++) @@ -830,21 +830,21 @@ static u32 GetBestMonTypeMatchup(struct Pokemon *party, int firstId, int lastId, if (!(gBitTable[i] & invalidMons) && !(gBitTable[i] & bits)) { u16 species = GetMonData(&party[i], MON_DATA_SPECIES); - u32 typeEffectiveness = UQ_4_12(1.0); + u16 typeEffectiveness = UQ_4_12(1.0); u8 atkType1 = gBattleMons[opposingBattler].type1; u8 atkType2 = gBattleMons[opposingBattler].type2; u8 defType1 = gSpeciesInfo[species].types[0]; u8 defType2 = gSpeciesInfo[species].types[1]; - typeEffectiveness *= GetTypeModifier(atkType1, defType1); + MulModifier(&typeEffectiveness, (GetTypeModifier(atkType1, defType1))); if (atkType2 != atkType1) - typeEffectiveness *= GetTypeModifier(atkType2, defType1); + MulModifier(&typeEffectiveness, (GetTypeModifier(atkType2, defType1))); if (defType2 != defType1) { - typeEffectiveness *= GetTypeModifier(atkType1, defType2); + MulModifier(&typeEffectiveness, (GetTypeModifier(atkType1, defType2))); if (atkType2 != atkType1) - typeEffectiveness *= GetTypeModifier(atkType2, defType2); + MulModifier(&typeEffectiveness, (GetTypeModifier(atkType2, defType2))); } if (typeEffectiveness < bestResist) { diff --git a/src/battle_util.c b/src/battle_util.c index 93d02336302d..e608b0e51f78 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -8341,7 +8341,7 @@ u32 GetMoveTargetCount(u16 move, u8 battlerAtk, u8 battlerDef) } } -static void MulModifier(u16 *modifier, u16 val) +void MulModifier(u16 *modifier, u16 val) { *modifier = UQ_4_12_TO_INT((*modifier * val) + UQ_4_12_ROUND); }