Add some battle frontier constant usage

This commit is contained in:
GriffinR
2022-06-06 15:15:46 -04:00
parent 78b0c20738
commit 7143865f6f
21 changed files with 189 additions and 143 deletions
+36 -30
View File
@@ -27,6 +27,7 @@
#include "constants/battle_dome.h"
#include "constants/battle_frontier.h"
#include "constants/battle_frontier_mons.h"
#include "constants/battle_tent.h"
#include "constants/battle_tent_mons.h"
#include "constants/battle_tent_trainers.h"
#include "constants/battle_tower.h"
@@ -1060,7 +1061,7 @@ static void SetNextFacilityOpponent(void)
u16 id;
u32 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE);
u16 winStreak = GetCurrentFacilityWinStreak();
u32 challengeNum = winStreak / 7;
u32 challengeNum = winStreak / FRONTIER_STAGES_PER_CHALLENGE;
SetFacilityPtrsGetLevel();
if (battleMode == FRONTIER_MODE_MULTIS || battleMode == FRONTIER_MODE_LINK_MULTIS)
@@ -1095,7 +1096,7 @@ static void SetNextFacilityOpponent(void)
gTrainerBattleOpponent_A = id;
SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0);
if (gSaveBlock2Ptr->frontier.curChallengeBattleNum + 1 < 7)
if (gSaveBlock2Ptr->frontier.curChallengeBattleNum + 1 < FRONTIER_STAGES_PER_CHALLENGE)
gSaveBlock2Ptr->frontier.trainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = gTrainerBattleOpponent_A;
}
}
@@ -1107,7 +1108,7 @@ u16 GetRandomScaledFrontierTrainerId(u8 challengeNum, u8 battleNum)
if (challengeNum <= 7)
{
if (battleNum == 6)
if (battleNum == FRONTIER_STAGES_PER_CHALLENGE - 1)
{
// The last battle in each challenge has a jump in difficulty, pulls from a table with higher ranges
trainerId = (sFrontierTrainerIdRangesHard[challengeNum][1] - sFrontierTrainerIdRangesHard[challengeNum][0]) + 1;
@@ -1136,7 +1137,7 @@ static void GetRandomScaledFrontierTrainerIdRange(u8 challengeNum, u8 battleNum,
if (challengeNum <= 7)
{
if (battleNum == 6)
if (battleNum == FRONTIER_STAGES_PER_CHALLENGE - 1)
{
// The last battle in each challenge has a jump in difficulty, pulls from a table with higher ranges
range = (sFrontierTrainerIdRangesHard[challengeNum][1] - sFrontierTrainerIdRangesHard[challengeNum][0]) + 1;
@@ -1691,7 +1692,10 @@ static void FillTrainerParty(u16 trainerId, u8 firstMonId, u8 monCount)
while (i != monCount)
{
u16 monId = monSet[Random() % bfMonCount];
if ((level == 50 || level == 20) && monId > FRONTIER_MONS_HIGH_TIER)
// "High tier" pokemon are only allowed on open level mode
// 20 is not a possible value for level here
if ((level == FRONTIER_MAX_LEVEL_50 || level == 20) && monId > FRONTIER_MONS_HIGH_TIER)
continue;
// Ensure this pokemon species isn't a duplicate.
@@ -1767,9 +1771,9 @@ static void Unused_CreateApprenticeMons(u16 trainerId, u8 firstMonId)
fixedIV = 9;
if (gSaveBlock2Ptr->frontier.lvlMode != FRONTIER_LVL_50)
level = 100;
level = FRONTIER_MAX_LEVEL_OPEN;
else
level = 50;
level = FRONTIER_MAX_LEVEL_50;
for (i = 0; i != 3; i++)
{
@@ -1802,8 +1806,10 @@ u16 GetRandomFrontierMonFromSet(u16 trainerId)
do
{
// "High tier" pokemon are only allowed on open level mode
// 20 is not a possible value for level here
monId = monSet[Random() % numMons];
} while((level == 50 || level == 20) && monId > FRONTIER_MONS_HIGH_TIER);
} while((level == FRONTIER_MAX_LEVEL_50 || level == 20) && monId > FRONTIER_MONS_HIGH_TIER);
return monId;
}
@@ -1831,11 +1837,11 @@ static void FillFactoryFrontierTrainerParty(u16 trainerId, u8 firstMonId)
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;
u8 challengeNum = gSaveBlock2Ptr->frontier.factoryWinStreaks[battleMode][lvlMode] / FRONTIER_STAGES_PER_CHALLENGE;
#else
u8 challengeNum = gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][FRONTIER_LVL_50] / 7;
u8 challengeNum = gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][FRONTIER_LVL_50] / FRONTIER_STAGES_PER_CHALLENGE;
#endif
if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < 6)
if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < FRONTIER_STAGES_PER_CHALLENGE - 1)
fixedIV = GetFactoryMonFixedIV(challengeNum, FALSE);
else
fixedIV = GetFactoryMonFixedIV(challengeNum, TRUE); // Last trainer in challenge uses higher IVs
@@ -1882,7 +1888,7 @@ static void FillFactoryTentTrainerParty(u16 trainerId, u8 firstMonId)
{
u8 i, j;
u8 friendship;
u8 level = 30;
u8 level = TENT_MIN_LEVEL;
u8 fixedIV = 0;
u32 otID = T1_READ_32(gSaveBlock2Ptr->playerTrainerId);
@@ -2043,7 +2049,7 @@ void DoSpecialTrainerBattle(void)
break;
case SPECIAL_BATTLE_EREADER:
ZeroEnemyPartyMons();
for (i = 0; i < 3; i++)
for (i = 0; i < (int)ARRAY_COUNT(gSaveBlock2Ptr->frontier.ereaderTrainer.party); i++)
CreateBattleTowerMon(&gEnemyParty[i], &gSaveBlock2Ptr->frontier.ereaderTrainer.party[i]);
gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_EREADER_TRAINER;
gTrainerBattleOpponent_A = 0;
@@ -2189,7 +2195,7 @@ static void SaveTowerChallenge(void)
{
u16 lvlMode = gSaveBlock2Ptr->frontier.lvlMode;
u16 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE);
s32 challengeNum = (signed)(gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode] / 7);
s32 challengeNum = (signed)(gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode] / FRONTIER_STAGES_PER_CHALLENGE);
if (gSpecialVar_0x8005 == 0 && (challengeNum > 1 || gSaveBlock2Ptr->frontier.curChallengeBattleNum != 0))
SaveBattleTowerRecord();
@@ -2279,7 +2285,7 @@ static void LoadMultiPartnerCandidatesData(void)
objEventTemplates = gSaveBlock1Ptr->objectEventTemplates;
lvlMode = gSaveBlock2Ptr->frontier.lvlMode;
battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE);
challengeNum = gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode] / 7;
challengeNum = gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode] / FRONTIER_STAGES_PER_CHALLENGE;
species1 = GetMonData(&gPlayerParty[0], MON_DATA_SPECIES, NULL);
species2 = GetMonData(&gPlayerParty[1], MON_DATA_SPECIES, NULL);
level = SetFacilityPtrsGetLevel();
@@ -2338,7 +2344,7 @@ static void LoadMultiPartnerCandidatesData(void)
for (i = 0; i < APPRENTICE_COUNT; i++)
{
if (gSaveBlock2Ptr->apprentices[i].lvlMode != 0
&& sApprenticeChallengeThreshold[gSaveBlock2Ptr->apprentices[i].numQuestions] / 7 <= challengeNum
&& sApprenticeChallengeThreshold[gSaveBlock2Ptr->apprentices[i].numQuestions] / FRONTIER_STAGES_PER_CHALLENGE <= challengeNum
&& gSaveBlock2Ptr->apprentices[i].lvlMode - 1 == lvlMode)
{
k = 0;
@@ -2377,7 +2383,7 @@ static void LoadMultiPartnerCandidatesData(void)
checksum += record[j];
}
if (gSaveBlock2Ptr->frontier.towerRecords[i].winStreak / 7 <= challengeNum
if (gSaveBlock2Ptr->frontier.towerRecords[i].winStreak / FRONTIER_STAGES_PER_CHALLENGE <= challengeNum
&& gSaveBlock2Ptr->frontier.towerRecords[i].lvlMode == lvlMode
&& recordHasData
&& gSaveBlock2Ptr->frontier.towerRecords[i].checksum == checksum)
@@ -2458,7 +2464,7 @@ static void ShowPartnerCandidateMessage(void)
s32 monId;
s32 level = SetFacilityPtrsGetLevel();
u16 winStreak = GetCurrentFacilityWinStreak();
s32 challengeNum = winStreak / 7;
s32 challengeNum = winStreak / FRONTIER_STAGES_PER_CHALLENGE;
s32 k = gSpecialVar_LastTalked - 2;
s32 trainerId = gSaveBlock2Ptr->frontier.trainerIds[k];
@@ -2517,7 +2523,7 @@ static void ShowPartnerCandidateMessage(void)
gSaveBlock2Ptr->frontier.trainerIds[18] = gFrontierTempParty[0];
gSaveBlock2Ptr->frontier.trainerIds[19] = gFrontierTempParty[1];
}
for (k = 0; k < 14; k++)
for (k = 0; k < FRONTIER_STAGES_PER_CHALLENGE * 2; k++)
{
while (1)
{
@@ -2576,7 +2582,7 @@ static void LoadLinkMultiOpponentsData(void)
case 0:
if (battleMode == FRONTIER_MODE_LINK_MULTIS)
{
challengeNum = gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode] / 7;
challengeNum = gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode] / FRONTIER_STAGES_PER_CHALLENGE;
if (IsLinkTaskFinished())
{
SendBlock(BitmaskAllOtherLinkPlayers(), &challengeNum, sizeof(challengeNum));
@@ -2596,7 +2602,7 @@ static void LoadLinkMultiOpponentsData(void)
challengeNum = gBlockRecvBuffer[0][0];
else
challengeNum = gBlockRecvBuffer[1][0];
for (i = 0; i < 14; i++)
for (i = 0; i < FRONTIER_STAGES_PER_CHALLENGE * 2; i++)
{
do
{
@@ -2840,7 +2846,7 @@ static void FillEReaderTrainerWithPlayerData(void)
ereaderTrainer->winStreak = 1;
j = 7;
for (i = 0; i < 6; i++)
for (i = 0; i < EASY_CHAT_BATTLE_WORDS_COUNT; i++)
{
ereaderTrainer->greeting[i] = gSaveBlock1Ptr->easyChatBattleStart[i];
ereaderTrainer->farewellPlayerLost[i] = j;
@@ -2848,7 +2854,7 @@ static void FillEReaderTrainerWithPlayerData(void)
j++;
}
for (i = 0; i < 3; i++)
for (i = 0; i < (int)ARRAY_COUNT(ereaderTrainer->party); i++)
ConvertPokemonToBattleTowerPokemon(&gPlayerParty[i], &ereaderTrainer->party[i]);
SetEReaderTrainerChecksum(ereaderTrainer);
@@ -3246,12 +3252,12 @@ u8 GetFrontierEnemyMonLevel(u8 lvlMode)
{
default:
case FRONTIER_LVL_50:
level = 50;
level = FRONTIER_MAX_LEVEL_50;
break;
case FRONTIER_LVL_OPEN:
level = GetHighestLevelInPlayerParty();
if (level < 60)
level = 60;
if (level < FRONTIER_MIN_LEVEL_OPEN)
level = FRONTIER_MIN_LEVEL_OPEN;
break;
}
@@ -3321,7 +3327,7 @@ static u16 GetBattleTentTrainerId(void)
static u8 SetTentPtrsGetLevel(void)
{
u8 level = 30;
u8 level = TENT_MIN_LEVEL;
u32 facility = VarGet(VAR_FRONTIER_FACILITY);
if (facility == FRONTIER_FACILITY_FACTORY)
@@ -3346,8 +3352,8 @@ static u8 SetTentPtrsGetLevel(void)
}
level = GetHighestLevelInPlayerParty();
if (level < 30)
level = 30;
if (level < TENT_MIN_LEVEL)
level = TENT_MIN_LEVEL;
return level;
}
@@ -3369,7 +3375,7 @@ static void SetNextBattleTentOpponent(void)
gTrainerBattleOpponent_A = trainerId;
SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0);
if (gSaveBlock2Ptr->frontier.curChallengeBattleNum + 1 < 3)
if (gSaveBlock2Ptr->frontier.curChallengeBattleNum + 1 < TENT_STAGES_PER_CHALLENGE)
gSaveBlock2Ptr->frontier.trainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = gTrainerBattleOpponent_A;
}