Document record mixing hall records

This commit is contained in:
GriffinR 2021-10-24 15:49:45 -04:00
parent 7f3c529935
commit 7a89ad98c3
3 changed files with 77 additions and 60 deletions

View File

@ -59,6 +59,7 @@
// 7 facilities for single mode + tower double mode + tower multi mode. // 7 facilities for single mode + tower double mode + tower multi mode.
// Excludes link modes. See RANKING_HALL_* in include/constants/battle_frontier.h // Excludes link modes. See RANKING_HALL_* in include/constants/battle_frontier.h
#define HALL_FACILITIES_COUNT 9 #define HALL_FACILITIES_COUNT 9
// Received via record mixing, 1 for each player other than yourself
#define HALL_RECORDS_COUNT 3 #define HALL_RECORDS_COUNT 3
// Battle Frontier level modes. // Battle Frontier level modes.

View File

@ -2303,20 +2303,20 @@ static void Fill1PRecords(struct RankingHall1P *dst, s32 hallFacilityId, s32 lvl
static void Fill2PRecords(struct RankingHall2P *dst, s32 lvlMode) static void Fill2PRecords(struct RankingHall2P *dst, s32 lvlMode)
{ {
s32 i, j; s32 i, j;
struct RankingHall2P record2P[4]; struct RankingHall2P record2P[HALL_RECORDS_COUNT + 1];
struct PlayerHallRecords *playerHallRecords = calloc(1, sizeof(struct PlayerHallRecords)); struct PlayerHallRecords *playerHallRecords = calloc(1, sizeof(struct PlayerHallRecords));
GetPlayerHallRecords(playerHallRecords); GetPlayerHallRecords(playerHallRecords);
for (i = 0; i < 3; i++) for (i = 0; i < HALL_RECORDS_COUNT; i++)
record2P[i] = gSaveBlock2Ptr->hallRecords2P[lvlMode][i]; record2P[i] = gSaveBlock2Ptr->hallRecords2P[lvlMode][i];
record2P[3] = playerHallRecords->twoPlayers[lvlMode]; record2P[HALL_RECORDS_COUNT] = playerHallRecords->twoPlayers[lvlMode];
for (i = 0; i < 3; i++) for (i = 0; i < HALL_RECORDS_COUNT; i++)
{ {
s32 highestWinStreak = 0; s32 highestWinStreak = 0;
s32 highestId = 0; s32 highestId = 0;
for (j = 0; j < 3; j++) for (j = 0; j < HALL_RECORDS_COUNT; j++)
{ {
if (record2P[j].winStreak > highestWinStreak) if (record2P[j].winStreak > highestWinStreak)
{ {
@ -2324,8 +2324,8 @@ static void Fill2PRecords(struct RankingHall2P *dst, s32 lvlMode)
highestWinStreak = record2P[j].winStreak; highestWinStreak = record2P[j].winStreak;
} }
} }
if (record2P[3].winStreak >= highestWinStreak) if (record2P[HALL_RECORDS_COUNT].winStreak >= highestWinStreak)
highestId = 3; highestId = HALL_RECORDS_COUNT;
dst[i] = record2P[highestId]; dst[i] = record2P[highestId];
record2P[highestId].winStreak = 0; record2P[highestId].winStreak = 0;
@ -2338,8 +2338,8 @@ static void PrintHallRecords(s32 hallFacilityId, s32 lvlMode)
{ {
s32 i; s32 i;
s32 x; s32 x;
struct RankingHall1P records1P[3]; struct RankingHall1P records1P[HALL_RECORDS_COUNT];
struct RankingHall2P records2P[3]; struct RankingHall2P records2P[HALL_RECORDS_COUNT];
StringCopy(gStringVar1, sRecordsWindowChallengeTexts[hallFacilityId][0]); StringCopy(gStringVar1, sRecordsWindowChallengeTexts[hallFacilityId][0]);
StringExpandPlaceholders(gStringVar4, sRecordsWindowChallengeTexts[hallFacilityId][1]); StringExpandPlaceholders(gStringVar4, sRecordsWindowChallengeTexts[hallFacilityId][1]);
@ -2351,13 +2351,13 @@ static void PrintHallRecords(s32 hallFacilityId, s32 lvlMode)
gSaveBlock2Ptr->frontier.opponentNames[0][PLAYER_NAME_LENGTH] = EOS; gSaveBlock2Ptr->frontier.opponentNames[0][PLAYER_NAME_LENGTH] = EOS;
gSaveBlock2Ptr->frontier.opponentNames[1][PLAYER_NAME_LENGTH] = EOS; gSaveBlock2Ptr->frontier.opponentNames[1][PLAYER_NAME_LENGTH] = EOS;
Fill2PRecords(records2P, lvlMode); Fill2PRecords(records2P, lvlMode);
for (i = 0; i < 3; i++) for (i = 0; i < HALL_RECORDS_COUNT; i++)
Print2PRecord(i, 1, 4, &records2P[i]); Print2PRecord(i, 1, 4, &records2P[i]);
} }
else else
{ {
Fill1PRecords(records1P, hallFacilityId, lvlMode); Fill1PRecords(records1P, hallFacilityId, lvlMode);
for (i = 0; i < 3; i++) for (i = 0; i < HALL_RECORDS_COUNT; i++)
Print1PRecord(i, 1, 4, &records1P[i], hallFacilityId); Print1PRecord(i, 1, 4, &records1P[i], hallFacilityId);
} }
} }

View File

@ -97,7 +97,7 @@ static void *sApprenticesSave;
static void *sBattleTowerSave_Duplicate; static void *sBattleTowerSave_Duplicate;
static u32 sRecordStructSize; static u32 sRecordStructSize;
static u8 sDaycareMailRandSum; static u8 sDaycareMailRandSum;
static struct PlayerHallRecords *gUnknown_03001168[3]; static struct PlayerHallRecords *sPartnerHallRecords[HALL_RECORDS_COUNT];
static EWRAM_DATA struct RecordMixingDaycareMail sRecordMixMail = {0}; static EWRAM_DATA struct RecordMixingDaycareMail sRecordMixMail = {0};
static EWRAM_DATA union PlayerRecord *sReceivedRecords = NULL; static EWRAM_DATA union PlayerRecord *sReceivedRecords = NULL;
@ -278,8 +278,8 @@ static void ReceiveExchangePacket(u32 multiplayerId)
ReceiveBattleTowerData(&sReceivedRecords->emerald.battleTowerRecord, sizeof(sReceivedRecords->emerald), multiplayerId); ReceiveBattleTowerData(&sReceivedRecords->emerald.battleTowerRecord, sizeof(sReceivedRecords->emerald), multiplayerId);
ReceiveGiftItem(&sReceivedRecords->emerald.giftItem, multiplayerId); ReceiveGiftItem(&sReceivedRecords->emerald.giftItem, multiplayerId);
ReceiveLilycoveLadyData(&sReceivedRecords->emerald.lilycoveLady, sizeof(sReceivedRecords->emerald), multiplayerId); ReceiveLilycoveLadyData(&sReceivedRecords->emerald.lilycoveLady, sizeof(sReceivedRecords->emerald), multiplayerId);
ReceiveApprenticeData(sReceivedRecords->emerald.apprentices, sizeof(sReceivedRecords->emerald), (u8) multiplayerId); ReceiveApprenticeData(sReceivedRecords->emerald.apprentices, sizeof(sReceivedRecords->emerald), (u8)multiplayerId);
ReceiveRankingHallRecords(&sReceivedRecords->emerald.hallRecords, sizeof(sReceivedRecords->emerald), (u8) multiplayerId); ReceiveRankingHallRecords(&sReceivedRecords->emerald.hallRecords, sizeof(sReceivedRecords->emerald), (u8)multiplayerId);
} }
} }
@ -1204,145 +1204,161 @@ static void ReceiveApprenticeData(struct Apprentice *records, size_t recordSize,
} }
} }
static void sub_80E8578(struct RecordMixingHallRecords *dst, void *hallRecords, size_t recordSize, u32 arg3, s32 linkPlayerCount) static void GetNewHallRecords(struct RecordMixingHallRecords *dst, void *records, size_t recordSize, u32 multiplayerId, s32 linkPlayerCount)
{ {
s32 i, j, k, l; s32 i, j, k, l;
s32 var_68; s32 repeatTrainers;
// Load sPartnerHallRecords with link partners' hall records
k = 0; k = 0;
i = 0; for (i = 0; i < linkPlayerCount; i++)
while (1)
{ {
if (i >= linkPlayerCount) if (i != multiplayerId)
sPartnerHallRecords[k++] = records;
if (k == HALL_RECORDS_COUNT)
break; break;
if (i != arg3) records += recordSize;
gUnknown_03001168[k++] = hallRecords;
if (k == 3)
break;
hallRecords += recordSize;
i++;
} }
// Get improved 1P hall records
for (i = 0; i < HALL_FACILITIES_COUNT; i++) for (i = 0; i < HALL_FACILITIES_COUNT; i++)
{ {
for (j = 0; j < FRONTIER_LVL_MODE_COUNT; j++) for (j = 0; j < FRONTIER_LVL_MODE_COUNT; j++)
{ {
// First get the existing saved records
for (k = 0; k < HALL_RECORDS_COUNT; k++) for (k = 0; k < HALL_RECORDS_COUNT; k++)
dst->hallRecords1P[i][j][k] = gSaveBlock2Ptr->hallRecords1P[i][j][k]; dst->hallRecords1P[i][j][k] = gSaveBlock2Ptr->hallRecords1P[i][j][k];
// Then read the new mixed records
for (k = 0; k < linkPlayerCount - 1; k++) for (k = 0; k < linkPlayerCount - 1; k++)
{ {
var_68 = 0; repeatTrainers = 0;
for (l = 0; l < HALL_RECORDS_COUNT; l++) for (l = 0; l < HALL_RECORDS_COUNT; l++)
{ {
if (GetTrainerId(dst->hallRecords1P[i][j][l].id) == GetTrainerId(gUnknown_03001168[k]->onePlayer[i][j].id)) // If the new trainer is already in the existing saved records, only
// use the new one if the win streak is better
if (GetTrainerId(dst->hallRecords1P[i][j][l].id) == GetTrainerId(sPartnerHallRecords[k]->onePlayer[i][j].id))
{ {
var_68++; repeatTrainers++;
if (dst->hallRecords1P[i][j][l].winStreak < gUnknown_03001168[k]->onePlayer[i][j].winStreak) if (dst->hallRecords1P[i][j][l].winStreak < sPartnerHallRecords[k]->onePlayer[i][j].winStreak)
dst->hallRecords1P[i][j][l] = gUnknown_03001168[k]->onePlayer[i][j]; dst->hallRecords1P[i][j][l] = sPartnerHallRecords[k]->onePlayer[i][j];
} }
} }
if (var_68 == 0)
dst->hallRecords1P[i][j][k + HALL_RECORDS_COUNT] = gUnknown_03001168[k]->onePlayer[i][j]; // If all of the mixed records are new trainers, just save them
if (repeatTrainers == 0)
dst->hallRecords1P[i][j][k + HALL_RECORDS_COUNT] = sPartnerHallRecords[k]->onePlayer[i][j];
} }
} }
} }
// Get improved 2P hall records
for (j = 0; j < FRONTIER_LVL_MODE_COUNT; j++) for (j = 0; j < FRONTIER_LVL_MODE_COUNT; j++)
{ {
// First get the existing saved records
for (k = 0; k < HALL_RECORDS_COUNT; k++) for (k = 0; k < HALL_RECORDS_COUNT; k++)
dst->hallRecords2P[j][k] = gSaveBlock2Ptr->hallRecords2P[j][k]; dst->hallRecords2P[j][k] = gSaveBlock2Ptr->hallRecords2P[j][k];
// Then read the new mixed records
for (k = 0; k < linkPlayerCount - 1; k++) for (k = 0; k < linkPlayerCount - 1; k++)
{ {
var_68 = 0; repeatTrainers = 0;
for (l = 0; l < HALL_RECORDS_COUNT; l++) for (l = 0; l < HALL_RECORDS_COUNT; l++)
{ {
if (GetTrainerId(dst->hallRecords2P[j][l].id1) == GetTrainerId(gUnknown_03001168[k]->twoPlayers[j].id1) // If the new trainer pair is already in the existing saved records, only
&& GetTrainerId(dst->hallRecords2P[j][l].id2) == GetTrainerId(gUnknown_03001168[k]->twoPlayers[j].id2)) // use the new pair if the win streak is better
if (GetTrainerId(dst->hallRecords2P[j][l].id1) == GetTrainerId(sPartnerHallRecords[k]->twoPlayers[j].id1)
&& GetTrainerId(dst->hallRecords2P[j][l].id2) == GetTrainerId(sPartnerHallRecords[k]->twoPlayers[j].id2))
{ {
var_68++; repeatTrainers++;
if (dst->hallRecords2P[j][l].winStreak < gUnknown_03001168[k]->twoPlayers[j].winStreak) if (dst->hallRecords2P[j][l].winStreak < sPartnerHallRecords[k]->twoPlayers[j].winStreak)
dst->hallRecords2P[j][l] = gUnknown_03001168[k]->twoPlayers[j]; dst->hallRecords2P[j][l] = sPartnerHallRecords[k]->twoPlayers[j];
} }
} }
if (var_68 == 0)
dst->hallRecords2P[j][k + HALL_RECORDS_COUNT] = gUnknown_03001168[k]->twoPlayers[j]; // If all of the mixed records are new trainer pairs, just save them
if (repeatTrainers == 0)
dst->hallRecords2P[j][k + HALL_RECORDS_COUNT] = sPartnerHallRecords[k]->twoPlayers[j];
} }
} }
} }
static void sub_80E8880(struct RankingHall1P *arg0, struct RankingHall1P *arg1) static void FillWinStreakRecords1P(struct RankingHall1P *playerRecords, struct RankingHall1P *mixRecords)
{ {
s32 i, j; s32 i, j;
// Fill the player's 1P records with the highest win streaks from the mixed records
for (i = 0; i < HALL_RECORDS_COUNT; i++) for (i = 0; i < HALL_RECORDS_COUNT; i++)
{ {
// Get the highest remaining win streak in the mixed hall records
s32 highestWinStreak = 0; s32 highestWinStreak = 0;
s32 highestId = -1; s32 highestId = -1;
for (j = 0; j < 6; j++) for (j = 0; j < HALL_RECORDS_COUNT * 2; j++)
{ {
if (arg1[j].winStreak > highestWinStreak) if (mixRecords[j].winStreak > highestWinStreak)
{ {
highestId = j; highestId = j;
highestWinStreak = arg1[j].winStreak; highestWinStreak = mixRecords[j].winStreak;
} }
} }
// Save the win streak to the player's records, then clear it from the mixed records
if (highestId >= 0) if (highestId >= 0)
{ {
arg0[i] = arg1[highestId]; playerRecords[i] = mixRecords[highestId];
arg1[highestId].winStreak = 0; mixRecords[highestId].winStreak = 0;
} }
} }
} }
static void sub_80E88CC(struct RankingHall2P *arg0, struct RankingHall2P *arg1) static void FillWinStreakRecords2P(struct RankingHall2P *playerRecords, struct RankingHall2P *mixRecords)
{ {
s32 i, j; s32 i, j;
for (i = 0; i < 3; i++) // Fill the player's 2P records with the highest win streaks from the mixed records
for (i = 0; i < HALL_RECORDS_COUNT; i++)
{ {
// Get the highest remaining win streak in the mixed hall records
s32 highestWinStreak = 0; s32 highestWinStreak = 0;
s32 highestId = -1; s32 highestId = -1;
for (j = 0; j < 6; j++) for (j = 0; j < HALL_RECORDS_COUNT * 2; j++)
{ {
if (arg1[j].winStreak > highestWinStreak) if (mixRecords[j].winStreak > highestWinStreak)
{ {
highestId = j; highestId = j;
highestWinStreak = arg1[j].winStreak; highestWinStreak = mixRecords[j].winStreak;
} }
} }
// Save the win streak to the player's records, then clear it from the mixed records
if (highestId >= 0) if (highestId >= 0)
{ {
arg0[i] = arg1[highestId]; playerRecords[i] = mixRecords[highestId];
arg1[highestId].winStreak = 0; mixRecords[highestId].winStreak = 0;
} }
} }
} }
static void sub_80E8924(struct RecordMixingHallRecords *mixHallRecords) static void SaveHighestWinStreakRecords(struct RecordMixingHallRecords *mixHallRecords)
{ {
s32 i, j; s32 i, j;
for (i = 0; i < HALL_FACILITIES_COUNT; i++) for (i = 0; i < HALL_FACILITIES_COUNT; i++)
{ {
for (j = 0; j < FRONTIER_LVL_MODE_COUNT; j++) for (j = 0; j < FRONTIER_LVL_MODE_COUNT; j++)
sub_80E8880(gSaveBlock2Ptr->hallRecords1P[i][j], mixHallRecords->hallRecords1P[i][j]); FillWinStreakRecords1P(gSaveBlock2Ptr->hallRecords1P[i][j], mixHallRecords->hallRecords1P[i][j]);
} }
for (j = 0; j < FRONTIER_LVL_MODE_COUNT; j++) for (j = 0; j < FRONTIER_LVL_MODE_COUNT; j++)
sub_80E88CC(gSaveBlock2Ptr->hallRecords2P[j], mixHallRecords->hallRecords2P[j]); FillWinStreakRecords2P(gSaveBlock2Ptr->hallRecords2P[j], mixHallRecords->hallRecords2P[j]);
} }
static void ReceiveRankingHallRecords(struct PlayerHallRecords *hallRecords, size_t recordSize, u32 arg2) static void ReceiveRankingHallRecords(struct PlayerHallRecords *records, size_t recordSize, u32 multiplayerId)
{ {
u8 linkPlayerCount = GetLinkPlayerCount(); u8 linkPlayerCount = GetLinkPlayerCount();
struct RecordMixingHallRecords *mixHallRecords = AllocZeroed(sizeof(*mixHallRecords)); struct RecordMixingHallRecords *mixHallRecords = AllocZeroed(sizeof(*mixHallRecords));
sub_80E8578(mixHallRecords, hallRecords, recordSize, arg2, linkPlayerCount); GetNewHallRecords(mixHallRecords, records, recordSize, multiplayerId, linkPlayerCount);
sub_80E8924(mixHallRecords); SaveHighestWinStreakRecords(mixHallRecords);
Free(mixHallRecords); Free(mixHallRecords);
} }