Add bugfix for Battle Factory trainer IVs

This commit is contained in:
GriffinR 2022-03-30 09:37:03 -04:00
parent 5160520639
commit 66cbe29c14
3 changed files with 25 additions and 12 deletions

View File

@ -3,7 +3,7 @@
void CallBattleFactoryFunction(void);
bool8 InBattleFactory(void);
u8 GetFactoryMonFixedIV(u8 arg0, u8 arg1);
u8 GetFactoryMonFixedIV(u8 challengeNum, bool8 isLastBattle);
void FillFactoryBrainParty(void);
u8 GetNumPastRentalsRank(u8 battleMode, u8 lvlMode);
u32 GetAiScriptsInBattleFactory(void);

View File

@ -720,17 +720,25 @@ static void RestorePlayerPartyHeldItems(void)
}
}
u8 GetFactoryMonFixedIV(u8 arg0, u8 arg1)
// Get the IV to use for the opponent's pokémon.
// The IVs get higher for each subsequent challenge and for
// the last trainer in each challenge. Noland is an exception
// to this, as he uses the IVs that would be used by the regular
// trainers 2 challenges ahead of the current one.
// Due to a mistake in FillFactoryFrontierTrainerParty, the
// challenge number used to determine the IVs for regular trainers
// is Battle Tower's instead of Battle Factory's.
u8 GetFactoryMonFixedIV(u8 challengeNum, bool8 isLastBattle)
{
u8 a1;
u8 a2 = (arg1 != 0) ? 1 : 0;
u8 ivSet;
bool8 useHigherIV = isLastBattle ? TRUE : FALSE;
if (arg0 > 8)
a1 = 7;
if (challengeNum > 8)
ivSet = 7;
else
a1 = arg0;
ivSet = challengeNum;
return sFixedIVTable[a1][a2];
return sFixedIVTable[ivSet][useHigherIV];
}
void FillFactoryBrainParty(void)
@ -746,7 +754,7 @@ void FillFactoryBrainParty(void)
u8 lvlMode = gSaveBlock2Ptr->frontier.lvlMode;
u8 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE);
u8 challengeNum = gSaveBlock2Ptr->frontier.factoryWinStreaks[battleMode][lvlMode] / 7;
fixedIV = GetFactoryMonFixedIV(challengeNum + 2, 0);
fixedIV = GetFactoryMonFixedIV(challengeNum + 2, FALSE);
monLevel = SetFacilityPtrsGetLevel();
i = 0;
otId = T1_READ_32(gSaveBlock2Ptr->playerTrainerId);

View File

@ -1827,13 +1827,18 @@ static void FillFactoryFrontierTrainerParty(u16 trainerId, u8 firstMonId)
if (trainerId < FRONTIER_TRAINERS_COUNT)
{
u8 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; // Unused variable.
u8 lvlMode = gSaveBlock2Ptr->frontier.lvlMode;
u8 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE);
// By mistake Battle Tower's Level 50 challenge number is used to determine the IVs for Battle Factory.
#ifdef BUGFIX
u8 challengeNum = gSaveBlock2Ptr->frontier.factoryWinStreaks[battleMode][lvlMode] / 7;
#else
u8 challengeNum = gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][FRONTIER_LVL_50] / 7;
#endif
if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < 6)
fixedIV = GetFactoryMonFixedIV(challengeNum, 0);
fixedIV = GetFactoryMonFixedIV(challengeNum, FALSE);
else
fixedIV = GetFactoryMonFixedIV(challengeNum, 1);
fixedIV = GetFactoryMonFixedIV(challengeNum, TRUE); // Last trainer in challenge uses higher IVs
}
else if (trainerId == TRAINER_EREADER)
{