AI chooses most resistant mon

This commit is contained in:
sneed 2022-06-18 19:00:33 +03:00
parent 15fe85902f
commit f43d54af89

View File

@ -602,39 +602,39 @@ static u32 GetBestMonBatonPass(struct Pokemon *party, int firstId, int lastId, u
return PARTY_SIZE;
}
static u32 GestBestMonOffensive(struct Pokemon *party, int firstId, int lastId, u8 invalidMons, u32 opposingBattler)
static u32 GestBestMonTypeMatchup(struct Pokemon *party, int firstId, int lastId, u8 invalidMons, u32 opposingBattler)
{
int i, bits = 0;
while (bits != 0x3F) // All mons were checked.
{
int bestDmg = 0;
u32 bestResist = UQ_4_12(1.0);
int bestMonId = PARTY_SIZE;
// Find the mon whose type is the most suitable offensively.
// 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 typeDmg = UQ_4_12(1.0);
u32 typeEffectiveness = UQ_4_12(1.0);
u8 atkType1 = gBaseStats[species].type1;
u8 atkType2 = gBaseStats[species].type2;
u8 defType1 = gBattleMons[opposingBattler].type1;
u8 defType2 = gBattleMons[opposingBattler].type2;
u8 atkType1 = gBattleMons[opposingBattler].type1;
u8 atkType2 = gBattleMons[opposingBattler].type2;
u8 defType1 = gBaseStats[species].type1;
u8 defType2 = gBaseStats[species].type2;
typeDmg *= GetTypeModifier(atkType1, defType1);
typeEffectiveness *= GetTypeModifier(atkType1, defType1);
if (atkType2 != atkType1)
typeDmg *= GetTypeModifier(atkType2, defType1);
typeEffectiveness *= GetTypeModifier(atkType2, defType1);
if (defType2 != defType1)
{
typeDmg *= GetTypeModifier(atkType1, defType2);
typeEffectiveness *= GetTypeModifier(atkType1, defType2);
if (atkType2 != atkType1)
typeDmg *= GetTypeModifier(atkType2, defType2);
typeEffectiveness *= GetTypeModifier(atkType2, defType2);
}
if (bestDmg < typeDmg)
if (typeEffectiveness < bestResist)
{
bestDmg = typeDmg;
bestResist = typeEffectiveness;
bestMonId = i;
}
}
@ -698,7 +698,6 @@ static u32 GetBestMonDmg(struct Pokemon *party, int firstId, int lastId, u8 inva
u8 GetMostSuitableMonToSwitchInto(void)
{
u32 opposingBattler = 0;
u32 bestDmg = 0;
u32 bestMonId = 0;
u8 battlerIn1 = 0, battlerIn2 = 0;
s32 firstId = 0;
@ -757,7 +756,7 @@ u8 GetMostSuitableMonToSwitchInto(void)
if (bestMonId != PARTY_SIZE)
return bestMonId;
bestMonId = GestBestMonOffensive(party, firstId, lastId, invalidMons, opposingBattler);
bestMonId = GestBestMonTypeMatchup(party, firstId, lastId, invalidMons, opposingBattler);
if (bestMonId != PARTY_SIZE)
return bestMonId;