diff options
author | GriffinR <griffin.g.richards@gmail.com> | 2022-03-31 22:26:03 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-31 22:26:03 -0400 |
commit | 44b44d3e77bb02b3a66aef4689861ee51f38407c (patch) | |
tree | 29cb5386a021ba29d0d70d5c863d52bb1e5618d9 | |
parent | 5160520639f913c45a336e6a8117fb8522fb9c4c (diff) | |
parent | 66cbe29c1408feef07772ba0b8a5b89995fa3056 (diff) |
Merge pull request #1648 from GriffinRichards/factory-bugfix
Add bugfix for Battle Factory trainer IVs
-rw-r--r-- | include/battle_factory.h | 2 | ||||
-rw-r--r-- | src/battle_factory.c | 28 | ||||
-rw-r--r-- | src/battle_tower.c | 11 |
3 files changed, 27 insertions, 14 deletions
diff --git a/include/battle_factory.h b/include/battle_factory.h index 5606d60d1..d414bdb3b 100644 --- a/include/battle_factory.h +++ b/include/battle_factory.h @@ -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); diff --git a/src/battle_factory.c b/src/battle_factory.c index 23fa664f3..d88ed37f9 100644 --- a/src/battle_factory.c +++ b/src/battle_factory.c @@ -720,17 +720,25 @@ static void RestorePlayerPartyHeldItems(void) } } -u8 GetFactoryMonFixedIV(u8 arg0, u8 arg1) -{ - u8 a1; - u8 a2 = (arg1 != 0) ? 1 : 0; - - if (arg0 > 8) - a1 = 7; +// 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 ivSet; + bool8 useHigherIV = isLastBattle ? TRUE : FALSE; + + 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); diff --git a/src/battle_tower.c b/src/battle_tower.c index b747a3dc0..989412e9e 100644 --- a/src/battle_tower.c +++ b/src/battle_tower.c @@ -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) { |