diff --git a/include/battle_ai_util.h b/include/battle_ai_util.h index 700527dbeb61..36ce1cdda50e 100644 --- a/include/battle_ai_util.h +++ b/include/battle_ai_util.h @@ -4,8 +4,8 @@ #define FOE(battler) ((BATTLE_OPPOSITE(battler)) & BIT_SIDE) // Roll boundaries used by AI when scoring. Doesn't affect actual damage dealt. -#define MAX_ROLL_PERCENTAGE 100 -#define MIN_ROLL_PERCENTAGE 85 +#define MAX_ROLL_PERCENTAGE DMG_ROLL_PERCENT_HI +#define MIN_ROLL_PERCENTAGE DMG_ROLL_PERCENT_LO enum { diff --git a/include/battle_util.h b/include/battle_util.h index 2bfc9cba9e3c..9638cf1a77e0 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -66,6 +66,10 @@ enum { #define IS_WHOLE_SIDE_ALIVE(battler) ((IsBattlerAlive(battler) && IsBattlerAlive(BATTLE_PARTNER(battler)))) #define IS_ALIVE_AND_PRESENT(battler) (IsBattlerAlive(battler) && IsBattlerSpritePresent(battler)) +// Lowest and highest percentages used for damage roll calculations +#define DMG_ROLL_PERCENT_LO 85 +#define DMG_ROLL_PERCENT_HI 100 + // for Natural Gift and Fling struct TypePower { diff --git a/src/battle_ai_util.c b/src/battle_ai_util.c index 7a39d15c69f5..d3645bfdefd8 100644 --- a/src/battle_ai_util.c +++ b/src/battle_ai_util.c @@ -391,9 +391,9 @@ static inline s32 HighestRollDmg(s32 dmg) return dmg; } -static inline s32 AverageRollDmg(s32 dmg) +static inline s32 AverageDmg(s32 dmg) { - dmg = ((HighestRollDmg(dmg) + LowestRollDmg(dmg)) * 100) / 2; + dmg = (dmg * (MIN_ROLL_PERCENTAGE + MAX_ROLL_PERCENTAGE)) / 2; dmg /= 100; return dmg; } @@ -559,7 +559,7 @@ s32 AI_CalcDamage(u32 move, u32 battlerAtk, u32 battlerDef, u8 *typeEffectivenes u32 critChance = GetCritHitChance(critChanceIndex); // With critChance getting closer to 1, dmg gets closer to critDmg. if (dmgRoll == DMG_ROLL_AVERAGE) - dmg = AverageRollDmg((critDmg + normalDmg * (critChance - 1)) / (critChance)); + dmg = AverageDmg((critDmg + normalDmg * (critChance - 1)) / (critChance)); else if (dmgRoll == DMG_ROLL_HIGHEST) dmg = HighestRollDmg((critDmg + normalDmg * (critChance - 1)) / (critChance)); else @@ -568,7 +568,7 @@ s32 AI_CalcDamage(u32 move, u32 battlerAtk, u32 battlerDef, u8 *typeEffectivenes else { if (dmgRoll == DMG_ROLL_AVERAGE) - dmg = AverageRollDmg(normalDmg); + dmg = AverageDmg(normalDmg); else if (dmgRoll == DMG_ROLL_HIGHEST) dmg = HighestRollDmg(normalDmg); else diff --git a/src/battle_util.c b/src/battle_util.c index b7aab2411331..1c16baa2fdfd 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -9994,7 +9994,7 @@ static inline s32 DoMoveDamageCalcVars(u32 move, u32 battlerAtk, u32 battlerDef, if (randomFactor) { - dmg *= 100 - RandomUniform(RNG_DAMAGE_MODIFIER, 0, 15); + dmg *= DMG_ROLL_PERCENT_HI - RandomUniform(RNG_DAMAGE_MODIFIER, 0, DMG_ROLL_PERCENT_HI - DMG_ROLL_PERCENT_LO); dmg /= 100; } @@ -10055,7 +10055,7 @@ static inline s32 DoFutureSightAttackDamageCalcVars(u32 move, u32 battlerAtk, u3 if (randomFactor) { - dmg *= 100 - RandomUniform(RNG_DAMAGE_MODIFIER, 0, 15); + dmg *= DMG_ROLL_PERCENT_HI - RandomUniform(RNG_DAMAGE_MODIFIER, 0, DMG_ROLL_PERCENT_HI - DMG_ROLL_PERCENT_LO); dmg /= 100; }