summaryrefslogtreecommitdiff
path: root/src/contest.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/contest.c')
-rw-r--r--src/contest.c60
1 files changed, 37 insertions, 23 deletions
diff --git a/src/contest.c b/src/contest.c
index 246fc1e50..59f50fcfc 100644
--- a/src/contest.c
+++ b/src/contest.c
@@ -350,8 +350,8 @@ EWRAM_DATA u8 gHighestRibbonRank = 0;
EWRAM_DATA struct ContestResources *gContestResources = NULL;
EWRAM_DATA u8 sContestBgCopyFlags = 0;
EWRAM_DATA struct ContestWinner gCurContestWinner = {0};
-EWRAM_DATA bool8 gUnknown_02039F5C = 0;
-EWRAM_DATA u8 gUnknown_02039F5D = 0;
+EWRAM_DATA bool8 gCurContestWinnerIsForArtist = 0;
+EWRAM_DATA u8 gCurContestWinnerSaveIdx = 0;
// IWRAM common vars.
u32 gContestRngValue;
@@ -5516,40 +5516,47 @@ void ResetContestLinkResults(void)
gSaveBlock2Ptr->contestLinkResults[i][j] = 0;
}
-bool8 sub_80DEDA8(u8 rank)
+bool8 SaveContestWinner(u8 rank)
{
s32 i;
- u8 r7 = Random() % 3;
+ u8 captionId = Random() % NUM_PAINTING_CAPTIONS;
+ // Get the index of the winner among the contestants
for (i = 0; i < CONTESTANT_COUNT - 1; i++)
- {
if (gContestFinalStandings[i] == 0)
break;
- }
- if (rank == 0xFF && i != gContestPlayerMonIndex)
+
+ // Exit if attempting to save a Pokémon other than the player's to the museum
+ if (rank == CONTEST_SAVE_FOR_MUSEUM && i != gContestPlayerMonIndex)
return FALSE;
+
+
+ // Adjust the random painting caption depending on the category
switch (gSpecialVar_ContestCategory)
{
case CONTEST_CATEGORY_COOL:
- r7 += 0;
+ captionId += NUM_PAINTING_CAPTIONS * CONTEST_CATEGORY_COOL;
break;
case CONTEST_CATEGORY_BEAUTY:
- r7 += 3;
+ captionId += NUM_PAINTING_CAPTIONS * CONTEST_CATEGORY_BEAUTY;
break;
case CONTEST_CATEGORY_CUTE:
- r7 += 6;
+ captionId += NUM_PAINTING_CAPTIONS * CONTEST_CATEGORY_CUTE;
break;
case CONTEST_CATEGORY_SMART:
- r7 += 9;
+ captionId += NUM_PAINTING_CAPTIONS * CONTEST_CATEGORY_SMART;
break;
case CONTEST_CATEGORY_TOUGH:
- r7 += 12;
+ captionId += NUM_PAINTING_CAPTIONS * CONTEST_CATEGORY_TOUGH;
break;
}
- if (rank != 0xFE)
- {
- u8 id = sub_80DEFA8(rank, 1);
+ if (rank != CONTEST_SAVE_FOR_ARTIST)
+ {
+ // Save winner in the saveblock
+ // Used to save any winner for the Contest Hall or the Museum
+ // but excludes the temporary save used by the artist
+ u8 id = GetContestWinnerSaveIdx(rank, TRUE);
gSaveBlock1Ptr->contestWinners[id].personality = gContestMons[i].personality;
gSaveBlock1Ptr->contestWinners[id].species = gContestMons[i].species;
gSaveBlock1Ptr->contestWinners[id].trainerId = gContestMons[i].otId;
@@ -5560,24 +5567,29 @@ bool8 sub_80DEDA8(u8 rank)
else
gSaveBlock1Ptr->contestWinners[id].contestRank = gSpecialVar_ContestRank;
- if (rank != 0xFF)
+ if (rank != CONTEST_SAVE_FOR_MUSEUM)
gSaveBlock1Ptr->contestWinners[id].contestCategory = gSpecialVar_ContestCategory;
else
- gSaveBlock1Ptr->contestWinners[id].contestCategory = r7;
+ gSaveBlock1Ptr->contestWinners[id].contestCategory = captionId;
}
else
{
+ // Set the most recent winner so the artist can show the player their painting
gCurContestWinner.personality = gContestMons[i].personality;
gCurContestWinner.trainerId = gContestMons[i].otId;
gCurContestWinner.species = gContestMons[i].species;
StringCopy(gCurContestWinner.monName, gContestMons[i].nickname);
StringCopy(gCurContestWinner.trainerName, gContestMons[i].trainerName);
- gCurContestWinner.contestCategory = r7;
+ gCurContestWinner.contestCategory = captionId;
}
return TRUE;
}
-u8 sub_80DEFA8(u8 rank, u8 b)
+// Rank is either a regular contest rank (for saving winners to show in the Contest Hall)
+// Or one of two special IDs listed below (for saving winners to show in Museum, or from the artist)
+// If just retrieving the index where the winner *would* go, shift is FALSE
+// If actually preparing to insert the winner into the saveblock, shift is TRUE
+u8 GetContestWinnerSaveIdx(u8 rank, bool8 shift)
{
s32 i;
@@ -5587,13 +5599,15 @@ u8 sub_80DEFA8(u8 rank, u8 b)
case CONTEST_RANK_SUPER:
case CONTEST_RANK_HYPER:
case CONTEST_RANK_MASTER:
- if (b != 0)
+ if (shift)
{
- for (i = NUM_CONTEST_HALL_WINNERS - 1; i >= 1; i--)
+ for (i = NUM_CONTEST_HALL_WINNERS - 1; i > 0; i--)
memcpy(&gSaveBlock1Ptr->contestWinners[i], &gSaveBlock1Ptr->contestWinners[i - 1], sizeof(struct ContestWinner));
}
- return 0;
+ return CONTEST_WINNER_HALL_1 - 1;
default:
+// case CONTEST_SAVE_FOR_MUSEUM:
+// case CONTEST_SAVE_FOR_ARTIST:
switch (gSpecialVar_ContestCategory)
{
case CONTEST_CATEGORY_COOL:
@@ -5615,7 +5629,7 @@ void ClearContestWinnerPicsInContestHall(void)
{
s32 i;
- for (i = 0; i < 8; i++)
+ for (i = 0; i < MUSEUM_CONTEST_WINNERS_START; i++)
gSaveBlock1Ptr->contestWinners[i] = gDefaultContestWinners[i];
}