2019-01-03 17:54:22 +00:00
|
|
|
#include "global.h"
|
|
|
|
#include "contest.h"
|
2020-07-12 01:25:56 +01:00
|
|
|
#include "contest_link.h"
|
2019-01-03 17:54:22 +00:00
|
|
|
#include "event_data.h"
|
|
|
|
#include "link.h"
|
|
|
|
#include "random.h"
|
|
|
|
#include "task.h"
|
|
|
|
|
|
|
|
static void sub_81D9F14(u8);
|
|
|
|
static void sub_81D9F30(u8);
|
|
|
|
static void sub_81D9F4C(u8);
|
|
|
|
static void sub_81D9F68(u8);
|
|
|
|
static void sub_81DA10C(u8);
|
|
|
|
static void sub_81DA138(u8);
|
|
|
|
static void sub_81DA160(u8);
|
|
|
|
static void sub_81DA244(u8);
|
|
|
|
static void sub_81DA2E8(u8);
|
|
|
|
static void sub_81DA3B8(u8);
|
|
|
|
static void sub_81DA488(u8);
|
|
|
|
|
2020-07-12 01:25:56 +01:00
|
|
|
#define tCategory data[9]
|
|
|
|
|
2019-01-03 17:54:22 +00:00
|
|
|
void sub_81D9DE4(u8 taskId)
|
|
|
|
{
|
|
|
|
int gameCleared;
|
|
|
|
|
2020-07-12 01:25:56 +01:00
|
|
|
switch (gTasks[taskId].tCategory)
|
2019-01-03 17:54:22 +00:00
|
|
|
{
|
2020-07-12 01:25:56 +01:00
|
|
|
case CONTEST_CATEGORY_COOL:
|
2019-01-03 17:54:22 +00:00
|
|
|
gHighestRibbonRank = GetMonData(&gPlayerParty[gContestMonPartyIndex], MON_DATA_COOL_RIBBON);
|
|
|
|
break;
|
2020-07-12 01:25:56 +01:00
|
|
|
case CONTEST_CATEGORY_BEAUTY:
|
2019-01-03 17:54:22 +00:00
|
|
|
gHighestRibbonRank = GetMonData(&gPlayerParty[gContestMonPartyIndex], MON_DATA_BEAUTY_RIBBON);
|
|
|
|
break;
|
2020-07-12 01:25:56 +01:00
|
|
|
case CONTEST_CATEGORY_CUTE:
|
2019-01-03 17:54:22 +00:00
|
|
|
gHighestRibbonRank = GetMonData(&gPlayerParty[gContestMonPartyIndex], MON_DATA_CUTE_RIBBON);
|
|
|
|
break;
|
2020-07-12 01:25:56 +01:00
|
|
|
case CONTEST_CATEGORY_SMART:
|
2019-01-03 17:54:22 +00:00
|
|
|
gHighestRibbonRank = GetMonData(&gPlayerParty[gContestMonPartyIndex], MON_DATA_SMART_RIBBON);
|
|
|
|
break;
|
2020-07-12 01:25:56 +01:00
|
|
|
case CONTEST_CATEGORY_TOUGH:
|
2019-01-03 17:54:22 +00:00
|
|
|
default:
|
|
|
|
gHighestRibbonRank = GetMonData(&gPlayerParty[gContestMonPartyIndex], MON_DATA_TOUGH_RIBBON);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-07-12 01:25:56 +01:00
|
|
|
gContestMons[gContestPlayerMonIndex].highestRank = gHighestRibbonRank;
|
2019-01-03 17:54:22 +00:00
|
|
|
gameCleared = FlagGet(FLAG_SYS_GAME_CLEAR) > 0;
|
2020-07-12 01:25:56 +01:00
|
|
|
gContestMons[gContestPlayerMonIndex].gameCleared = gameCleared;
|
2019-01-03 17:54:22 +00:00
|
|
|
SetTaskFuncWithFollowupFunc(taskId, sub_81DA160, sub_81D9F14);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sub_81D9F14(u8 taskId)
|
|
|
|
{
|
|
|
|
SetTaskFuncWithFollowupFunc(taskId, sub_81DA244, sub_81D9F30);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sub_81D9F30(u8 taskId)
|
|
|
|
{
|
|
|
|
SetTaskFuncWithFollowupFunc(taskId, sub_81DA2E8, sub_81D9F4C);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sub_81D9F4C(u8 taskId)
|
|
|
|
{
|
|
|
|
SetTaskFuncWithFollowupFunc(taskId, sub_81DA3B8, sub_81D9F68);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sub_81D9F68(u8 taskId)
|
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
u8 rank;
|
|
|
|
int gameCleared;
|
|
|
|
u8 data1[4];
|
|
|
|
u8 data2[4];
|
|
|
|
|
|
|
|
memset(data1, 0, sizeof(data1));
|
|
|
|
memset(data2, 0, sizeof(data2));
|
|
|
|
|
|
|
|
for (i = 0; i < gNumLinkContestPlayers; i++)
|
|
|
|
data1[i] = gTasks[taskId].data[i + 1];
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
if (i < gNumLinkContestPlayers)
|
|
|
|
{
|
|
|
|
while (++i < gNumLinkContestPlayers)
|
|
|
|
{
|
|
|
|
if (data1[0] != data1[i])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == gNumLinkContestPlayers)
|
|
|
|
gSpecialVar_0x8004 = 0;
|
|
|
|
else
|
|
|
|
gSpecialVar_0x8004 = 1;
|
|
|
|
|
|
|
|
for (i = 0; i < gNumLinkContestPlayers; i++)
|
|
|
|
data2[i] = gTasks[taskId].data[i + 5];
|
|
|
|
|
2020-07-12 01:25:56 +01:00
|
|
|
if (gNumLinkContestPlayers != CONTESTANT_COUNT && GetMultiplayerId() == 0)
|
2019-01-03 17:54:22 +00:00
|
|
|
{
|
2020-07-12 01:25:56 +01:00
|
|
|
rank = gContestMons[0].highestRank;
|
2019-01-03 17:54:22 +00:00
|
|
|
for (i = 1; i < gNumLinkContestPlayers; i++)
|
|
|
|
{
|
2020-07-12 01:25:56 +01:00
|
|
|
if (rank < gContestMons[i].highestRank)
|
|
|
|
rank = gContestMons[i].highestRank;
|
2019-01-03 17:54:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rank)
|
|
|
|
rank--;
|
|
|
|
|
|
|
|
gameCleared = 1;
|
|
|
|
for (i = 0; i < gNumLinkContestPlayers; i++)
|
|
|
|
{
|
2020-07-12 01:25:56 +01:00
|
|
|
if (!gContestMons[i].gameCleared)
|
2019-01-03 17:54:22 +00:00
|
|
|
{
|
|
|
|
gameCleared = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub_80DACBC(data1[0], rank, gameCleared);
|
|
|
|
}
|
|
|
|
|
|
|
|
gUnknown_02039F2B = sub_80F86E0(data2);
|
2020-07-12 01:25:56 +01:00
|
|
|
if (gNumLinkContestPlayers < CONTESTANT_COUNT)
|
2019-01-03 17:54:22 +00:00
|
|
|
SetTaskFuncWithFollowupFunc(taskId, sub_81DA488, sub_81DA10C);
|
|
|
|
else
|
|
|
|
gTasks[taskId].func = sub_81DA10C;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sub_81DA10C(u8 taskId)
|
|
|
|
{
|
|
|
|
sub_80DB09C(gSpecialVar_ContestCategory);
|
|
|
|
SetTaskFuncWithFollowupFunc(taskId, sub_80FCF40, sub_81DA138);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sub_81DA138(u8 taskId)
|
|
|
|
{
|
2019-04-03 01:00:05 +01:00
|
|
|
SortContestants(FALSE);
|
2019-01-03 17:54:22 +00:00
|
|
|
SetTaskFuncWithFollowupFunc(taskId, sub_80FCFD0, sub_80F8714);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sub_81DA160(u8 taskId)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!sub_80FC670(&gTasks[taskId].data[12]))
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (gTasks[taskId].data[0])
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
gTasks[taskId].data[0] = 0;
|
|
|
|
gTasks[taskId].data[12] = 0;
|
|
|
|
SwitchTaskToFollowupFunc(taskId);
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
if (IsLinkTaskFinished())
|
|
|
|
{
|
2020-07-12 01:25:56 +01:00
|
|
|
if (LinkContest_SendBlock(&gContestMons[gContestPlayerMonIndex], sizeof(struct ContestPokemon)) == 1)
|
2019-01-03 17:54:22 +00:00
|
|
|
gTasks[taskId].data[0]++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
2020-07-12 01:25:56 +01:00
|
|
|
if (LinkContest_GetBlockReceivedFromAllPlayers())
|
2019-01-03 17:54:22 +00:00
|
|
|
{
|
|
|
|
for (i = 0; i < gNumLinkContestPlayers; i++)
|
|
|
|
{
|
|
|
|
memcpy(&gContestMons[i], gBlockRecvBuffer[i], sizeof(struct ContestPokemon));
|
2020-07-12 01:25:56 +01:00
|
|
|
StripPlayerAndMonNamesForLinkContest(&gContestMons[i], gLinkPlayers[i].language);
|
2019-01-03 17:54:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gTasks[taskId].data[0]++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sub_81DA244(u8 taskId)
|
|
|
|
{
|
|
|
|
if (!sub_80FC670(&gTasks[taskId].data[12]))
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (gTasks[taskId].data[0])
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
gTasks[taskId].data[0] = 0;
|
|
|
|
gTasks[taskId].data[12] = 0;
|
|
|
|
SwitchTaskToFollowupFunc(taskId);
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
if (GetMultiplayerId() == 0)
|
|
|
|
{
|
|
|
|
if (!IsLinkTaskFinished())
|
|
|
|
return;
|
|
|
|
|
2020-07-12 01:25:56 +01:00
|
|
|
if (LinkContest_SendBlock(&gRngValue, sizeof(gRngValue)) == 1)
|
2019-01-03 17:54:22 +00:00
|
|
|
gTasks[taskId].data[0]++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gTasks[taskId].data[0]++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
2020-07-12 01:25:56 +01:00
|
|
|
if (LinkContest_GetBlockReceived(0))
|
2019-01-03 17:54:22 +00:00
|
|
|
{
|
|
|
|
memcpy(&gRngValue, gBlockRecvBuffer[0], sizeof(gRngValue));
|
|
|
|
memcpy(&gContestRngValue, gBlockRecvBuffer[0], sizeof(gContestRngValue));
|
|
|
|
gTasks[taskId].data[0]++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sub_81DA2E8(u8 taskId)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
u16 data[4];
|
|
|
|
u16 var0;
|
|
|
|
|
|
|
|
if (!sub_80FC670(&gTasks[taskId].data[12]))
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (gTasks[taskId].data[0])
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
gTasks[taskId].data[0] = 0;
|
|
|
|
gTasks[taskId].data[12] = 0;
|
|
|
|
SwitchTaskToFollowupFunc(taskId);
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
if (IsLinkTaskFinished())
|
|
|
|
{
|
|
|
|
var0 = 0x6E;
|
2020-07-12 01:25:56 +01:00
|
|
|
if (LinkContest_SendBlock(&var0, sizeof(var0)) == 1)
|
2019-01-03 17:54:22 +00:00
|
|
|
gTasks[taskId].data[0]++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
2020-07-12 01:25:56 +01:00
|
|
|
if (LinkContest_GetBlockReceivedFromAllPlayers())
|
2019-01-03 17:54:22 +00:00
|
|
|
{
|
|
|
|
for (i = 0; i < gNumLinkContestPlayers; i++)
|
|
|
|
{
|
|
|
|
data[i] = gBlockRecvBuffer[i][0];
|
|
|
|
gTasks[taskId].data[i + 5] = data[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
gTasks[taskId].data[0]++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sub_81DA3B8(u8 taskId)
|
|
|
|
{
|
|
|
|
int i;
|
2020-07-12 01:25:56 +01:00
|
|
|
u16 data[CONTESTANT_COUNT];
|
|
|
|
u16 category;
|
2019-01-03 17:54:22 +00:00
|
|
|
|
|
|
|
if (!sub_80FC670(&gTasks[taskId].data[12]))
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (gTasks[taskId].data[0])
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
gTasks[taskId].data[0] = 0;
|
|
|
|
gTasks[taskId].data[12] = 0;
|
|
|
|
SwitchTaskToFollowupFunc(taskId);
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
if (IsLinkTaskFinished())
|
|
|
|
{
|
2020-07-12 01:25:56 +01:00
|
|
|
category = gTasks[taskId].tCategory;
|
|
|
|
if (LinkContest_SendBlock(&category, sizeof(category)) == 1)
|
2019-01-03 17:54:22 +00:00
|
|
|
gTasks[taskId].data[0]++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
2020-07-12 01:25:56 +01:00
|
|
|
if (LinkContest_GetBlockReceivedFromAllPlayers())
|
2019-01-03 17:54:22 +00:00
|
|
|
{
|
|
|
|
for (i = 0; i < gNumLinkContestPlayers; i++)
|
|
|
|
{
|
|
|
|
data[i] = gBlockRecvBuffer[i][0];
|
|
|
|
gTasks[taskId].data[i + 1] = data[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
gTasks[taskId].data[0]++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sub_81DA488(u8 taskId)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!sub_80FC670(&gTasks[taskId].data[12]))
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (gTasks[taskId].data[0])
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
gTasks[taskId].data[0] = 0;
|
|
|
|
gTasks[taskId].data[12] = 0;
|
|
|
|
SwitchTaskToFollowupFunc(taskId);
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
if (GetMultiplayerId() == 0)
|
|
|
|
{
|
|
|
|
if (!IsLinkTaskFinished())
|
|
|
|
return;
|
|
|
|
|
2020-07-12 01:25:56 +01:00
|
|
|
if (LinkContest_SendBlock(&gContestMons[gNumLinkContestPlayers], (CONTESTANT_COUNT - gNumLinkContestPlayers) * sizeof(struct ContestPokemon)) == 1)
|
2019-01-03 17:54:22 +00:00
|
|
|
gTasks[taskId].data[0]++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gTasks[taskId].data[0]++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
2020-07-12 01:25:56 +01:00
|
|
|
if (LinkContest_GetBlockReceived(0))
|
2019-01-03 17:54:22 +00:00
|
|
|
{
|
2020-07-12 01:25:56 +01:00
|
|
|
memcpy(&gContestMons[gNumLinkContestPlayers], gBlockRecvBuffer[0], (CONTESTANT_COUNT - gNumLinkContestPlayers) * sizeof(struct ContestPokemon));
|
|
|
|
for (i = gNumLinkContestPlayers; i < CONTESTANT_COUNT; i++)
|
|
|
|
StripPlayerAndMonNamesForLinkContest(&gContestMons[i], gLinkPlayers[0].language);
|
2019-01-03 17:54:22 +00:00
|
|
|
|
|
|
|
gTasks[taskId].data[0]++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|