Use more constants in Battle Tower code

This commit is contained in:
kageru 2020-11-17 17:21:34 +01:00
parent de153a67cf
commit 6f91f7e0e3
No known key found for this signature in database
GPG Key ID: 8282A2BEA4ADA3D2
2 changed files with 13 additions and 12 deletions

View File

@ -328,11 +328,12 @@ struct BattleDomeTrainer
};
#define DOME_TOURNAMENT_TRAINERS_COUNT 16
#define BATTLE_TOWER_RECORD_COUNT 5
struct BattleFrontier
{
/*0x64C*/ struct EmeraldBattleTowerRecord towerPlayer;
/*0x738*/ struct EmeraldBattleTowerRecord towerRecords[5]; // From record mixing.
/*0x738*/ struct EmeraldBattleTowerRecord towerRecords[BATTLE_TOWER_RECORD_COUNT]; // From record mixing.
/*0xBEB*/ struct BattleTowerInterview towerInterview;
/*0xBEC*/ struct BattleTowerEReaderTrainer ereaderTrainer;
/*0xCA8*/ u8 challengeStatus;

View File

@ -999,7 +999,7 @@ static bool8 ChooseSpecialBattleTowerTrainer(void)
return FALSE;
winStreak = GetCurrentBattleTowerWinStreak(lvlMode, battleMode);
for (i = 0; i < 5; i++)
for (i = 0; i < BATTLE_TOWER_RECORD_COUNT; i++)
{
u32 *record = (u32*)(&gSaveBlock2Ptr->frontier.towerRecords[i]);
u32 recordHasData = 0;
@ -1010,7 +1010,7 @@ static bool8 ChooseSpecialBattleTowerTrainer(void)
checksum += record[j];
}
validMons = 0;
for (j = 0; j < 4; j++)
for (j = 0; j < MAX_FRONTIER_PARTY_SIZE; j++)
{
if (gSaveBlock2Ptr->frontier.towerRecords[i].party[j].species != 0
&& gSaveBlock2Ptr->frontier.towerRecords[i].party[j].level <= GetFrontierEnemyMonLevel(lvlMode))
@ -1324,7 +1324,7 @@ void PutNewBattleTowerRecord(struct EmeraldBattleTowerRecord *newRecordEm)
struct EmeraldBattleTowerRecord *newRecord = newRecordEm; // Needed to match.
// Find a record slot of the same player and replace it.
for (i = 0; i < 5; i++)
for (i = 0; i < BATTLE_TOWER_RECORD_COUNT; i++)
{
k = 0;
for (j = 0; j < TRAINER_ID_LENGTH; j++)
@ -1350,19 +1350,19 @@ void PutNewBattleTowerRecord(struct EmeraldBattleTowerRecord *newRecordEm)
if (k == PLAYER_NAME_LENGTH)
break;
}
if (i < 5)
if (i < BATTLE_TOWER_RECORD_COUNT)
{
gSaveBlock2Ptr->frontier.towerRecords[i] = *newRecord;
return;
}
// Find an empty record slot.
for (i = 0; i < 5; i++)
for (i = 0; i < BATTLE_TOWER_RECORD_COUNT; i++)
{
if (gSaveBlock2Ptr->frontier.towerRecords[i].winStreak == 0)
break;
}
if (i < 5)
if (i < BATTLE_TOWER_RECORD_COUNT)
{
gSaveBlock2Ptr->frontier.towerRecords[i] = *newRecord;
return;
@ -1373,7 +1373,7 @@ void PutNewBattleTowerRecord(struct EmeraldBattleTowerRecord *newRecordEm)
slotIds[0] = 0;
slotsCount++;
for (i = 1; i < 5; i++)
for (i = 1; i < BATTLE_TOWER_RECORD_COUNT; i++)
{
for (j = 0; j < slotsCount; j++)
{
@ -2240,7 +2240,7 @@ static void GetRecordMixFriendMultiPartnerParty(u16 trainerId)
u16 species2 = GetMonData(&gPlayerParty[1], MON_DATA_SPECIES, NULL);
count = 0;
for (i = 0; i < 4; i++)
for (i = 0; i < MAX_FRONTIER_PARTY_SIZE; i++)
{
if (gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].party[i].species != species1
&& gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].party[i].species != species2
@ -2362,7 +2362,7 @@ static void LoadMultiPartnerCandidatesData(void)
}
r10 = 0;
for (i = 0; i < 5; i++)
for (i = 0; i < BATTLE_TOWER_RECORD_COUNT; i++)
{
u32 *record = (u32*)(&gSaveBlock2Ptr->frontier.towerRecords[i]);
u32 recordHasData = 0;
@ -2379,7 +2379,7 @@ static void LoadMultiPartnerCandidatesData(void)
&& gSaveBlock2Ptr->frontier.towerRecords[i].checksum == checksum)
{
k = 0;
for (j = 0; j < 4; j++)
for (j = 0; j < MAX_FRONTIER_PARTY_SIZE; j++)
{
if (species1 != gSaveBlock2Ptr->frontier.towerRecords[i].party[j].species
&& species2 != gSaveBlock2Ptr->frontier.towerRecords[i].party[j].species
@ -2682,7 +2682,7 @@ static void ValidateBattleTowerRecordChecksums(void)
if (gSaveBlock2Ptr->frontier.towerPlayer.checksum != checksum)
ClearBattleTowerRecord(&gSaveBlock2Ptr->frontier.towerPlayer);
for (i = 0; i < 5; i++)
for (i = 0; i < BATTLE_TOWER_RECORD_COUNT; i++)
{
record = (u32*)(&gSaveBlock2Ptr->frontier.towerRecords[i]);
checksum = 0;