Document link contest connection
This commit is contained in:
+71
-62
@@ -6,21 +6,31 @@
|
||||
#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);
|
||||
/*
|
||||
The functions in this file handle preliminary communication
|
||||
for Emerald-only link contests. If the link contest has an RS
|
||||
player linked, none of these functions are used.
|
||||
|
||||
The equivalent functions for RS-linked contests are spread
|
||||
between contest_link.c and contest_util.c, and are suffixed RS
|
||||
instead of Em
|
||||
*/
|
||||
|
||||
static void Task_LinkContest_CommunicateMonsEm(u8);
|
||||
static void Task_LinkContest_StartCommunicateRngEm(u8);
|
||||
static void Task_LinkContest_CommunicateRngEm(u8);
|
||||
static void Task_LinkContest_StartCommunicateLeaderIdsEm(u8);
|
||||
static void Task_LinkContest_CommunicateLeaderIdsEm(u8);
|
||||
static void Task_LinkContest_StartCommunicateCategoryEm(u8);
|
||||
static void Task_LinkContest_CommunicateCategoryEm(u8);
|
||||
static void Task_LinkContest_SetUpContestEm(u8);
|
||||
static void Task_LinkContest_CommunicateAIMonsEm(u8);
|
||||
static void Task_LinkContest_CalculateRound1Em(u8);
|
||||
static void Task_LinkContest_CalculateTurnOrderEm(u8);
|
||||
|
||||
#define tCategory data[9]
|
||||
|
||||
void sub_81D9DE4(u8 taskId)
|
||||
void Task_LinkContest_StartCommunicationEm(u8 taskId)
|
||||
{
|
||||
int gameCleared;
|
||||
|
||||
@@ -47,57 +57,51 @@ void sub_81D9DE4(u8 taskId)
|
||||
gContestMons[gContestPlayerMonIndex].highestRank = gHighestRibbonRank;
|
||||
gameCleared = FlagGet(FLAG_SYS_GAME_CLEAR) > 0;
|
||||
gContestMons[gContestPlayerMonIndex].gameCleared = gameCleared;
|
||||
SetTaskFuncWithFollowupFunc(taskId, sub_81DA160, sub_81D9F14);
|
||||
SetTaskFuncWithFollowupFunc(taskId, Task_LinkContest_CommunicateMonsEm, Task_LinkContest_StartCommunicateRngEm);
|
||||
}
|
||||
|
||||
static void sub_81D9F14(u8 taskId)
|
||||
static void Task_LinkContest_StartCommunicateRngEm(u8 taskId)
|
||||
{
|
||||
SetTaskFuncWithFollowupFunc(taskId, sub_81DA244, sub_81D9F30);
|
||||
SetTaskFuncWithFollowupFunc(taskId, Task_LinkContest_CommunicateRngEm, Task_LinkContest_StartCommunicateLeaderIdsEm);
|
||||
}
|
||||
|
||||
static void sub_81D9F30(u8 taskId)
|
||||
static void Task_LinkContest_StartCommunicateLeaderIdsEm(u8 taskId)
|
||||
{
|
||||
SetTaskFuncWithFollowupFunc(taskId, sub_81DA2E8, sub_81D9F4C);
|
||||
SetTaskFuncWithFollowupFunc(taskId, Task_LinkContest_CommunicateLeaderIdsEm, Task_LinkContest_StartCommunicateCategoryEm);
|
||||
}
|
||||
|
||||
static void sub_81D9F4C(u8 taskId)
|
||||
static void Task_LinkContest_StartCommunicateCategoryEm(u8 taskId)
|
||||
{
|
||||
SetTaskFuncWithFollowupFunc(taskId, sub_81DA3B8, sub_81D9F68);
|
||||
SetTaskFuncWithFollowupFunc(taskId, Task_LinkContest_CommunicateCategoryEm, Task_LinkContest_SetUpContestEm);
|
||||
}
|
||||
|
||||
static void sub_81D9F68(u8 taskId)
|
||||
static void Task_LinkContest_SetUpContestEm(u8 taskId)
|
||||
{
|
||||
u8 i;
|
||||
u8 rank;
|
||||
int gameCleared;
|
||||
u8 contestCategories[CONTESTANT_COUNT];
|
||||
u8 data2[CONTESTANT_COUNT];
|
||||
u8 categories[CONTESTANT_COUNT];
|
||||
u8 leaderIds[CONTESTANT_COUNT];
|
||||
|
||||
memset(contestCategories, 0, sizeof(contestCategories));
|
||||
memset(data2, 0, sizeof(data2));
|
||||
memset(categories, 0, sizeof(categories));
|
||||
memset(leaderIds, 0, sizeof(leaderIds));
|
||||
|
||||
for (i = 0; i < gNumLinkContestPlayers; i++)
|
||||
contestCategories[i] = gTasks[taskId].data[i + 1];
|
||||
categories[i] = gTasks[taskId].data[i + 1];
|
||||
|
||||
// Ensure all players are doing the same category
|
||||
i = 0;
|
||||
if (i < gNumLinkContestPlayers)
|
||||
{
|
||||
while (++i < gNumLinkContestPlayers)
|
||||
{
|
||||
if (contestCategories[0] != contestCategories[i])
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < gNumLinkContestPlayers && categories[0] == categories[i]; i++)
|
||||
;
|
||||
|
||||
if (i == gNumLinkContestPlayers)
|
||||
gSpecialVar_0x8004 = FALSE;
|
||||
gSpecialVar_0x8004 = FALSE; // Category choices the same
|
||||
else
|
||||
gSpecialVar_0x8004 = TRUE;
|
||||
gSpecialVar_0x8004 = TRUE; // Category choices differ
|
||||
|
||||
for (i = 0; i < gNumLinkContestPlayers; i++)
|
||||
data2[i] = gTasks[taskId].data[i + 5];
|
||||
leaderIds[i] = gTasks[taskId].data[i + 5];
|
||||
|
||||
// If < 4 players and player is leader, set AI contestants based on rank and game clear
|
||||
if (gNumLinkContestPlayers != CONTESTANT_COUNT && GetMultiplayerId() == 0)
|
||||
{
|
||||
rank = gContestMons[0].highestRank;
|
||||
@@ -110,43 +114,45 @@ static void sub_81D9F68(u8 taskId)
|
||||
if (rank)
|
||||
rank--;
|
||||
|
||||
gameCleared = 1;
|
||||
gameCleared = TRUE;
|
||||
for (i = 0; i < gNumLinkContestPlayers; i++)
|
||||
{
|
||||
if (!gContestMons[i].gameCleared)
|
||||
{
|
||||
gameCleared = 0;
|
||||
gameCleared = FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SetLinkAIContestants(contestCategories[0], rank, gameCleared);
|
||||
SetLinkAIContestants(categories[0], rank, gameCleared);
|
||||
}
|
||||
|
||||
gUnknown_02039F2B = sub_80F86E0(data2);
|
||||
// Assign link leader. After initial communication all players will read data only from them
|
||||
gContestLinkLeaderIndex = LinkContest_GetLeaderIndex(leaderIds);
|
||||
|
||||
if (gNumLinkContestPlayers < CONTESTANT_COUNT)
|
||||
SetTaskFuncWithFollowupFunc(taskId, sub_81DA488, sub_81DA10C);
|
||||
SetTaskFuncWithFollowupFunc(taskId, Task_LinkContest_CommunicateAIMonsEm, Task_LinkContest_CalculateRound1Em);
|
||||
else
|
||||
gTasks[taskId].func = sub_81DA10C;
|
||||
gTasks[taskId].func = Task_LinkContest_CalculateRound1Em;
|
||||
}
|
||||
|
||||
static void sub_81DA10C(u8 taskId)
|
||||
static void Task_LinkContest_CalculateRound1Em(u8 taskId)
|
||||
{
|
||||
sub_80DB09C(gSpecialVar_ContestCategory);
|
||||
SetTaskFuncWithFollowupFunc(taskId, Task_LinkContest_CommunicateRound1Points, sub_81DA138);
|
||||
CalculateRound1Points(gSpecialVar_ContestCategory);
|
||||
SetTaskFuncWithFollowupFunc(taskId, Task_LinkContest_CommunicateRound1Points, Task_LinkContest_CalculateTurnOrderEm);
|
||||
}
|
||||
|
||||
static void sub_81DA138(u8 taskId)
|
||||
static void Task_LinkContest_CalculateTurnOrderEm(u8 taskId)
|
||||
{
|
||||
SortContestants(FALSE);
|
||||
SetTaskFuncWithFollowupFunc(taskId, Task_LinkContest_CommunicateTurnOrder, sub_80F8714);
|
||||
SetTaskFuncWithFollowupFunc(taskId, Task_LinkContest_CommunicateTurnOrder, Task_LinkContest_FinalizeConnection);
|
||||
}
|
||||
|
||||
static void sub_81DA160(u8 taskId)
|
||||
static void Task_LinkContest_CommunicateMonsEm(u8 taskId)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!sub_80FC670(&gTasks[taskId].data[12]))
|
||||
if (!LinkContest_TryLinkStandby(&gTasks[taskId].data[12]))
|
||||
return;
|
||||
|
||||
switch (gTasks[taskId].data[0])
|
||||
@@ -178,9 +184,9 @@ static void sub_81DA160(u8 taskId)
|
||||
}
|
||||
}
|
||||
|
||||
static void sub_81DA244(u8 taskId)
|
||||
static void Task_LinkContest_CommunicateRngEm(u8 taskId)
|
||||
{
|
||||
if (!sub_80FC670(&gTasks[taskId].data[12]))
|
||||
if (!LinkContest_TryLinkStandby(&gTasks[taskId].data[12]))
|
||||
return;
|
||||
|
||||
switch (gTasks[taskId].data[0])
|
||||
@@ -193,6 +199,7 @@ static void sub_81DA244(u8 taskId)
|
||||
case 0:
|
||||
if (GetMultiplayerId() == 0)
|
||||
{
|
||||
// Only the leader sends the RNG seed
|
||||
if (!IsLinkTaskFinished())
|
||||
return;
|
||||
|
||||
@@ -201,10 +208,12 @@ static void sub_81DA244(u8 taskId)
|
||||
}
|
||||
else
|
||||
{
|
||||
// Other link members skip to waiting
|
||||
gTasks[taskId].data[0]++;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
// Wait to receive RNG data
|
||||
if (LinkContest_GetBlockReceived(0))
|
||||
{
|
||||
memcpy(&gRngValue, gBlockRecvBuffer[0], sizeof(gRngValue));
|
||||
@@ -215,13 +224,13 @@ static void sub_81DA244(u8 taskId)
|
||||
}
|
||||
}
|
||||
|
||||
static void sub_81DA2E8(u8 taskId)
|
||||
static void Task_LinkContest_CommunicateLeaderIdsEm(u8 taskId)
|
||||
{
|
||||
int i;
|
||||
u16 data[4];
|
||||
u16 var0;
|
||||
u16 data[CONTESTANT_COUNT];
|
||||
u16 leaderId;
|
||||
|
||||
if (!sub_80FC670(&gTasks[taskId].data[12]))
|
||||
if (!LinkContest_TryLinkStandby(&gTasks[taskId].data[12]))
|
||||
return;
|
||||
|
||||
switch (gTasks[taskId].data[0])
|
||||
@@ -234,8 +243,8 @@ static void sub_81DA2E8(u8 taskId)
|
||||
case 0:
|
||||
if (IsLinkTaskFinished())
|
||||
{
|
||||
var0 = 0x6E;
|
||||
if (LinkContest_SendBlock(&var0, sizeof(var0)) == 1)
|
||||
leaderId = 0x6E;
|
||||
if (LinkContest_SendBlock(&leaderId, sizeof(leaderId)) == 1)
|
||||
gTasks[taskId].data[0]++;
|
||||
}
|
||||
break;
|
||||
@@ -254,13 +263,13 @@ static void sub_81DA2E8(u8 taskId)
|
||||
}
|
||||
}
|
||||
|
||||
static void sub_81DA3B8(u8 taskId)
|
||||
static void Task_LinkContest_CommunicateCategoryEm(u8 taskId)
|
||||
{
|
||||
int i;
|
||||
u16 data[CONTESTANT_COUNT];
|
||||
u16 category;
|
||||
|
||||
if (!sub_80FC670(&gTasks[taskId].data[12]))
|
||||
if (!LinkContest_TryLinkStandby(&gTasks[taskId].data[12]))
|
||||
return;
|
||||
|
||||
switch (gTasks[taskId].data[0])
|
||||
@@ -293,11 +302,11 @@ static void sub_81DA3B8(u8 taskId)
|
||||
}
|
||||
}
|
||||
|
||||
static void sub_81DA488(u8 taskId)
|
||||
static void Task_LinkContest_CommunicateAIMonsEm(u8 taskId)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!sub_80FC670(&gTasks[taskId].data[12]))
|
||||
if (!LinkContest_TryLinkStandby(&gTasks[taskId].data[12]))
|
||||
return;
|
||||
|
||||
switch (gTasks[taskId].data[0])
|
||||
|
||||
Reference in New Issue
Block a user