Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug due to variable overflow when AI chooses new Pokemon to send out #3068

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/battle_util.h
Original file line number Diff line number Diff line change
@@ -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);
12 changes: 6 additions & 6 deletions src/battle_ai_switch_items.c
Original file line number Diff line number Diff line change
@@ -822,29 +822,29 @@ 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++)
{
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)
{
2 changes: 1 addition & 1 deletion src/battle_util.c
Original file line number Diff line number Diff line change
@@ -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);
}