Merge pull request #1352 from huderlem/GetOpponentMostCommonMonType

Document GetOpponentMostCommonMonType and fix its fake matching
This commit is contained in:
GriffinR 2021-02-28 17:27:39 -05:00 committed by GitHub
commit 8bfd1370c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -592,39 +592,58 @@ static void GenerateInitialRentalMons(void)
} }
} }
// Determines if the upcoming opponent has a single most-common
// type in its party. If there are two different types that are
// tied, then the opponent is deemed to have no preferred type,
// and NUMBER_OF_MON_TYPES is the result.
static void GetOpponentMostCommonMonType(void) static void GetOpponentMostCommonMonType(void)
{ {
u8 i; u8 i;
u8 typesCount[NUMBER_OF_MON_TYPES]; u8 typeCounts[NUMBER_OF_MON_TYPES];
u8 usedType[2]; u8 mostCommonTypes[2];
gFacilityTrainerMons = gBattleFrontierMons; gFacilityTrainerMons = gBattleFrontierMons;
for (i = 0; i < NUMBER_OF_MON_TYPES; i++)
typesCount[i] = 0; // Count the number of times each type occurs in the opponent's party.
for (i = TYPE_NORMAL; i < NUMBER_OF_MON_TYPES; i++)
typeCounts[i] = 0;
for (i = 0; i < FRONTIER_PARTY_SIZE; i++) for (i = 0; i < FRONTIER_PARTY_SIZE; i++)
{ {
u32 species = gFacilityTrainerMons[gFrontierTempParty[i]].species; u32 species = gFacilityTrainerMons[gFrontierTempParty[i]].species;
typeCounts[gBaseStats[species].type1]++;
typesCount[gBaseStats[species].type1]++;
if (gBaseStats[species].type1 != gBaseStats[species].type2) if (gBaseStats[species].type1 != gBaseStats[species].type2)
typesCount[gBaseStats[species].type2]++; typeCounts[gBaseStats[species].type2]++;
} }
usedType[0] = 0; // Determine which are the two most-common types.
usedType[1] = 0; // The second most-common type is only updated if
for (i = 1; i < NUMBER_OF_MON_TYPES; i++) // its count is equal to the most-common type.
mostCommonTypes[0] = TYPE_NORMAL;
mostCommonTypes[1] = TYPE_NORMAL;
for (i = TYPE_FIGHTING; i < NUMBER_OF_MON_TYPES; i++)
{ {
if (typesCount[usedType[0]] < typesCount[i]) if (typeCounts[mostCommonTypes[0]] < typeCounts[i])
usedType[0] = i; mostCommonTypes[0] = i;
else if (typesCount[usedType[0]] == typesCount[i]) else if (typeCounts[mostCommonTypes[0]] == typeCounts[i])
usedType[1] = i; mostCommonTypes[1] = i;
} }
gSpecialVar_Result = gSpecialVar_Result; // Needed to match. Don't ask me why. if (typeCounts[mostCommonTypes[0]] != 0)
if (typesCount[usedType[0]] != 0 && (typesCount[usedType[0]] > typesCount[usedType[1]] || usedType[0] == usedType[1])) {
gSpecialVar_Result = usedType[0]; // The most-common type must be strictly greater than
// the second-most-common type, or the top two must be
// the same type.
if (typeCounts[mostCommonTypes[0]] > typeCounts[mostCommonTypes[1]])
gSpecialVar_Result = mostCommonTypes[0];
else if (mostCommonTypes[0] == mostCommonTypes[1])
gSpecialVar_Result = mostCommonTypes[0];
else
gSpecialVar_Result = NUMBER_OF_MON_TYPES;
}
else else
{
gSpecialVar_Result = NUMBER_OF_MON_TYPES; gSpecialVar_Result = NUMBER_OF_MON_TYPES;
}
} }
static void GetOpponentBattleStyle(void) static void GetOpponentBattleStyle(void)