2019-01-04 00:31:12 +01:00
|
|
|
#include "global.h"
|
|
|
|
#include "contest.h"
|
|
|
|
#include "decompress.h"
|
|
|
|
#include "event_data.h"
|
|
|
|
#include "link.h"
|
|
|
|
#include "pokemon.h"
|
|
|
|
#include "random.h"
|
|
|
|
#include "task.h"
|
2020-06-19 00:01:32 +02:00
|
|
|
#include "contest_link.h"
|
2019-01-04 00:31:12 +01:00
|
|
|
|
2020-08-13 09:09:47 +02:00
|
|
|
static void Task_LinkContest_StartInitFlags(u8);
|
|
|
|
static void Task_LinkContest_InitFlags(u8);
|
2019-01-04 00:31:12 +01:00
|
|
|
|
2020-08-15 20:33:08 +02:00
|
|
|
#define tState data[0]
|
|
|
|
#define tDelayTimer data[1]
|
|
|
|
#define tCategories(i) data[(i) + 1]
|
|
|
|
#define tLeaderIds(i) data[(i) + 5]
|
|
|
|
#define tCategory data[9]
|
|
|
|
#define tTimer data[11]
|
|
|
|
#define tStandbyState data[12]
|
2020-07-12 02:25:56 +02:00
|
|
|
|
|
|
|
bool32 LinkContest_SendBlock(void *src, u16 size)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
|
|
|
memcpy(gDecompressionBuffer, src, size);
|
2021-08-15 22:11:30 +02:00
|
|
|
if (SendBlock(BitmaskAllOtherLinkPlayers(), gDecompressionBuffer, size))
|
2019-01-04 00:31:12 +01:00
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-07-12 02:25:56 +02:00
|
|
|
bool8 LinkContest_GetBlockReceived(u8 flag)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
2020-07-12 02:25:56 +02:00
|
|
|
u8 mask = (1 << flag);
|
2019-01-04 00:31:12 +01:00
|
|
|
if (!(GetBlockReceivedStatus() & mask))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-12 02:25:56 +02:00
|
|
|
ResetBlockReceivedFlag(flag);
|
2019-01-04 00:31:12 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-12 02:25:56 +02:00
|
|
|
bool8 LinkContest_GetBlockReceivedFromAllPlayers(void)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
2020-06-08 06:45:06 +02:00
|
|
|
if (GetBlockReceivedStatus() == GetLinkPlayerCountAsBitFlags())
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
|
|
|
ResetBlockReceivedFlags();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-13 09:09:47 +02:00
|
|
|
void Task_LinkContest_Init(u8 taskId)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
|
2020-07-12 02:25:56 +02:00
|
|
|
for (i = 0; i < CONTESTANT_COUNT; i++)
|
2019-01-04 00:31:12 +01:00
|
|
|
gBlockRecvBuffer[i][0] = 0xFF;
|
2021-08-25 00:59:32 +02:00
|
|
|
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState = 0;
|
2020-08-13 09:09:47 +02:00
|
|
|
gTasks[taskId].func = Task_LinkContest_StartInitFlags;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
|
2020-08-13 09:09:47 +02:00
|
|
|
static void Task_LinkContest_StartInitFlags(u8 taskId)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
2020-08-13 09:09:47 +02:00
|
|
|
gTasks[taskId].func = Task_LinkContest_InitFlags;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
|
2020-08-13 09:09:47 +02:00
|
|
|
static void Task_LinkContest_InitFlags(u8 taskId)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!gReceivedRemoteLinkPlayers)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gContestPlayerMonIndex = GetMultiplayerId();
|
|
|
|
gNumLinkContestPlayers = GetLinkPlayerCount();
|
2019-04-03 23:24:32 +02:00
|
|
|
gLinkContestFlags = LINK_CONTEST_FLAG_IS_LINK;
|
2019-01-04 00:31:12 +01:00
|
|
|
if (gWirelessCommType == 1)
|
2019-04-03 23:24:32 +02:00
|
|
|
gLinkContestFlags = LINK_CONTEST_FLAG_IS_LINK | LINK_CONTEST_FLAG_IS_WIRELESS;
|
2019-01-04 00:31:12 +01:00
|
|
|
|
2020-07-12 02:25:56 +02:00
|
|
|
// Get number of players using Emerald/FRLG
|
2019-01-04 00:31:12 +01:00
|
|
|
for (i = 0; i < gNumLinkContestPlayers && (u32)(gLinkPlayers[i].version & 0xFF) - 1 > VERSION_RUBY - 1; i++)
|
|
|
|
;
|
|
|
|
|
|
|
|
if (i < gNumLinkContestPlayers)
|
2019-04-03 23:24:32 +02:00
|
|
|
gLinkContestFlags |= LINK_CONTEST_FLAG_HAS_RS_PLAYER;
|
2019-01-04 00:31:12 +01:00
|
|
|
|
|
|
|
SwitchTaskToFollowupFunc(taskId);
|
|
|
|
}
|
|
|
|
|
2020-08-13 09:09:47 +02:00
|
|
|
bool32 LinkContest_TryLinkStandby(s16 *state)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
2020-08-13 09:09:47 +02:00
|
|
|
// Skip standby for RS cabled links
|
2019-04-03 23:24:32 +02:00
|
|
|
if (gLinkContestFlags & LINK_CONTEST_FLAG_HAS_RS_PLAYER)
|
2019-01-04 00:31:12 +01:00
|
|
|
return TRUE;
|
2021-08-25 00:59:32 +02:00
|
|
|
|
2020-07-12 02:25:56 +02:00
|
|
|
switch (*state)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
if (IsLinkTaskFinished())
|
|
|
|
{
|
2020-08-13 09:09:47 +02:00
|
|
|
SetLinkStandbyCallback();
|
2020-07-12 02:25:56 +02:00
|
|
|
(*state)++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
case 1:
|
2020-07-12 02:25:56 +02:00
|
|
|
(*state)++;
|
2019-01-04 00:31:12 +01:00
|
|
|
return FALSE;
|
|
|
|
default:
|
|
|
|
if (IsLinkTaskFinished() != TRUE)
|
|
|
|
return FALSE;
|
|
|
|
else
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-13 09:09:47 +02:00
|
|
|
void Task_LinkContest_CommunicateMonsRS(u8 taskId)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2020-08-15 20:33:08 +02:00
|
|
|
if (!LinkContest_TryLinkStandby(&gTasks[taskId].tStandbyState))
|
2019-01-04 00:31:12 +01:00
|
|
|
return;
|
|
|
|
|
2020-07-12 02:25:56 +02:00
|
|
|
switch (gTasks[taskId].tState)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
|
|
|
case 0:
|
2020-08-13 09:09:47 +02:00
|
|
|
// Send players mon
|
2019-01-04 00:31:12 +01:00
|
|
|
if (GetMultiplayerId() == 0)
|
|
|
|
{
|
|
|
|
if (IsLinkTaskFinished())
|
|
|
|
{
|
|
|
|
memcpy(gBlockSendBuffer, &gContestMons[gContestPlayerMonIndex], sizeof(struct ContestPokemon));
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState = 10;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memcpy(gBlockSendBuffer, &gContestMons[gContestPlayerMonIndex], sizeof(struct ContestPokemon));
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState = 1;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
2020-08-13 09:09:47 +02:00
|
|
|
// Wait for other players data
|
2020-07-12 02:25:56 +02:00
|
|
|
if (LinkContest_GetBlockReceivedFromAllPlayers())
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
|
|
|
for (i = 0; i < gNumLinkContestPlayers; i++)
|
|
|
|
{
|
|
|
|
memcpy(&gContestMons[i], gBlockRecvBuffer[i], sizeof(struct ContestPokemon));
|
2020-07-12 02:25:56 +02:00
|
|
|
StripPlayerAndMonNamesForLinkContest(&gContestMons[i], gLinkPlayers[i].language);
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 10:
|
2020-08-13 09:09:47 +02:00
|
|
|
// Only if leader. Request other players data
|
2020-07-12 02:25:56 +02:00
|
|
|
if (++gTasks[taskId].tTimer > 300)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
2021-08-15 22:11:30 +02:00
|
|
|
SendBlockRequest(BLOCK_REQ_SIZE_100);
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState = 1;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState = 0;
|
|
|
|
gTasks[taskId].tTimer = 0;
|
2020-08-15 20:33:08 +02:00
|
|
|
gTasks[taskId].tStandbyState = 0;
|
2019-01-04 00:31:12 +01:00
|
|
|
SwitchTaskToFollowupFunc(taskId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-13 09:09:47 +02:00
|
|
|
void Task_LinkContest_CommunicateRngRS(u8 taskId)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
2020-07-12 02:25:56 +02:00
|
|
|
switch (gTasks[taskId].tState)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
if (GetMultiplayerId() == 0)
|
|
|
|
{
|
2020-07-12 02:25:56 +02:00
|
|
|
if (IsLinkTaskFinished() && LinkContest_SendBlock(&gRngValue, sizeof(gRngValue)) == TRUE)
|
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
2020-07-12 02:25:56 +02:00
|
|
|
if (LinkContest_GetBlockReceived(0))
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
|
|
|
memcpy(&gRngValue, gBlockRecvBuffer[0], sizeof(gRngValue));
|
|
|
|
memcpy(&gContestRngValue, gBlockRecvBuffer[0], sizeof(gContestRngValue));
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState = 0;
|
2019-01-04 00:31:12 +01:00
|
|
|
SwitchTaskToFollowupFunc(taskId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-13 09:09:47 +02:00
|
|
|
void Task_LinkContest_CommunicateCategoryRS(u8 taskId)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2020-08-15 20:33:08 +02:00
|
|
|
if (!LinkContest_TryLinkStandby(&gTasks[taskId].tStandbyState))
|
2019-01-04 00:31:12 +01:00
|
|
|
return;
|
|
|
|
|
2020-07-12 02:25:56 +02:00
|
|
|
switch (gTasks[taskId].tState)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
|
|
|
case 0:
|
2020-07-12 02:25:56 +02:00
|
|
|
gBlockSendBuffer[0] = gTasks[taskId].tCategory;
|
2019-01-04 00:31:12 +01:00
|
|
|
if (GetMultiplayerId() == 0)
|
|
|
|
{
|
|
|
|
if (IsLinkTaskFinished())
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState = 10;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
2020-07-12 02:25:56 +02:00
|
|
|
if (LinkContest_GetBlockReceivedFromAllPlayers())
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
|
|
|
for (i = 0; i < gNumLinkContestPlayers; i++)
|
2020-08-15 20:33:08 +02:00
|
|
|
gTasks[taskId].tCategories(i) = gBlockRecvBuffer[i][0];
|
2019-01-04 00:31:12 +01:00
|
|
|
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 10:
|
2020-07-12 02:25:56 +02:00
|
|
|
if (++gTasks[taskId].tTimer > 10)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
2021-08-15 22:11:30 +02:00
|
|
|
SendBlockRequest(BLOCK_REQ_SIZE_100);
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState = 1;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState = 0;
|
|
|
|
gTasks[taskId].tTimer = 0;
|
2020-08-15 20:33:08 +02:00
|
|
|
gTasks[taskId].tStandbyState = 0;
|
2019-01-04 00:31:12 +01:00
|
|
|
SwitchTaskToFollowupFunc(taskId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-12 02:25:56 +02:00
|
|
|
void Task_LinkContest_CommunicateMonIdxs(u8 taskId)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
2020-07-12 02:25:56 +02:00
|
|
|
switch (gTasks[taskId].tState)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
if (IsLinkTaskFinished())
|
|
|
|
{
|
2020-07-12 02:25:56 +02:00
|
|
|
if (LinkContest_SendBlock(&gContestPlayerMonIndex, sizeof(gContestPlayerMonIndex)) == TRUE)
|
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
2020-07-12 02:25:56 +02:00
|
|
|
if (LinkContest_GetBlockReceivedFromAllPlayers())
|
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
break;
|
|
|
|
default:
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState = 0;
|
2019-01-04 00:31:12 +01:00
|
|
|
SwitchTaskToFollowupFunc(taskId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-12 02:25:56 +02:00
|
|
|
void Task_LinkContest_CommunicateMoveSelections(u8 taskId)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2020-07-12 02:25:56 +02:00
|
|
|
switch (gTasks[taskId].tState)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
if (IsLinkTaskFinished())
|
|
|
|
{
|
2020-07-12 02:25:56 +02:00
|
|
|
// Send player's move selection
|
|
|
|
if (LinkContest_SendBlock(&eContestantStatus[gContestPlayerMonIndex].currMove, sizeof(eContestantStatus[gContestPlayerMonIndex].currMove)) == TRUE)
|
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
2020-07-12 02:25:56 +02:00
|
|
|
if (LinkContest_GetBlockReceivedFromAllPlayers())
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
2020-07-12 02:25:56 +02:00
|
|
|
// Receive partners' move selections
|
2019-01-04 00:31:12 +01:00
|
|
|
for (i = 0; i < gNumLinkContestPlayers; i++)
|
2019-04-03 02:00:05 +02:00
|
|
|
eContestantStatus[i].currMove = gBlockRecvBuffer[i][0];
|
2019-01-04 00:31:12 +01:00
|
|
|
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState = 0;
|
2019-01-04 00:31:12 +01:00
|
|
|
SwitchTaskToFollowupFunc(taskId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-24 06:14:53 +02:00
|
|
|
void Task_LinkContest_CommunicateFinalStandings(u8 taskId)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
2020-07-12 02:25:56 +02:00
|
|
|
switch (gTasks[taskId].tState)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
if (IsLinkTaskFinished())
|
|
|
|
{
|
2020-07-12 02:25:56 +02:00
|
|
|
if (LinkContest_SendBlock(gContestMonTotalPoints, sizeof(gContestMonTotalPoints)) == 1)
|
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
2020-07-12 02:25:56 +02:00
|
|
|
if (LinkContest_GetBlockReceivedFromAllPlayers())
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
2020-08-13 09:09:47 +02:00
|
|
|
memcpy(gContestMonTotalPoints, gBlockRecvBuffer[gContestLinkLeaderIndex], sizeof(gContestMonTotalPoints));
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
case 5:
|
|
|
|
case 8:
|
|
|
|
case 11:
|
2020-08-15 20:33:08 +02:00
|
|
|
if (gTasks[taskId].tDelayTimer++ > 10)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
2020-08-15 20:33:08 +02:00
|
|
|
gTasks[taskId].tDelayTimer = 0;
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (IsLinkTaskFinished())
|
|
|
|
{
|
2020-07-24 06:14:53 +02:00
|
|
|
if (LinkContest_SendBlock(gContestMonAppealPointTotals, sizeof(gContestMonAppealPointTotals)) == 1)
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
2020-07-12 02:25:56 +02:00
|
|
|
if (LinkContest_GetBlockReceivedFromAllPlayers())
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
2020-08-13 09:09:47 +02:00
|
|
|
memcpy(gContestMonAppealPointTotals, gBlockRecvBuffer[gContestLinkLeaderIndex], sizeof(gContestMonAppealPointTotals));
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
if (IsLinkTaskFinished())
|
|
|
|
{
|
2020-07-12 02:25:56 +02:00
|
|
|
if (LinkContest_SendBlock(gContestMonRound2Points, sizeof(gContestMonRound2Points)) == 1)
|
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 7:
|
2020-07-12 02:25:56 +02:00
|
|
|
if (LinkContest_GetBlockReceivedFromAllPlayers())
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
2020-08-13 09:09:47 +02:00
|
|
|
memcpy(gContestMonRound2Points, gBlockRecvBuffer[gContestLinkLeaderIndex], sizeof(gContestMonRound2Points));
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
if (IsLinkTaskFinished())
|
|
|
|
{
|
2020-07-12 02:25:56 +02:00
|
|
|
if (LinkContest_SendBlock(gContestFinalStandings, sizeof(gContestFinalStandings)) == 1)
|
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 10:
|
2020-07-12 02:25:56 +02:00
|
|
|
if (LinkContest_GetBlockReceivedFromAllPlayers())
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
2020-08-13 09:09:47 +02:00
|
|
|
memcpy(gContestFinalStandings, gBlockRecvBuffer[gContestLinkLeaderIndex], sizeof(gContestFinalStandings));
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState = 0;
|
2019-01-04 00:31:12 +01:00
|
|
|
SwitchTaskToFollowupFunc(taskId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-15 20:33:08 +02:00
|
|
|
void Task_LinkContest_CommunicateAppealsState(u8 taskId)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
2020-07-12 02:25:56 +02:00
|
|
|
switch (gTasks[taskId].tState)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
if (IsLinkTaskFinished())
|
|
|
|
{
|
2020-07-24 06:14:53 +02:00
|
|
|
if (LinkContest_SendBlock(eContestantStatus, CONTESTANT_COUNT * sizeof(struct ContestantStatus)) == 1)
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
2020-07-12 02:25:56 +02:00
|
|
|
if (LinkContest_GetBlockReceivedFromAllPlayers())
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
2020-08-13 09:09:47 +02:00
|
|
|
memcpy(eContestantStatus, gBlockRecvBuffer[gContestLinkLeaderIndex], CONTESTANT_COUNT * sizeof(struct ContestantStatus));
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
case 5:
|
|
|
|
case 8:
|
|
|
|
case 11:
|
2020-08-15 20:33:08 +02:00
|
|
|
if (gTasks[taskId].tDelayTimer++ > 10)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
2020-08-15 20:33:08 +02:00
|
|
|
gTasks[taskId].tDelayTimer = 0;
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (IsLinkTaskFinished())
|
|
|
|
{
|
2020-08-15 20:33:08 +02:00
|
|
|
if (LinkContest_SendBlock(gContestResources->appealResults, sizeof(struct ContestAppealMoveResults)) == 1)
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
2020-07-12 02:25:56 +02:00
|
|
|
if (LinkContest_GetBlockReceivedFromAllPlayers())
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
2020-08-15 20:33:08 +02:00
|
|
|
memcpy(gContestResources->appealResults, gBlockRecvBuffer[gContestLinkLeaderIndex], sizeof(struct ContestAppealMoveResults));
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
if (IsLinkTaskFinished())
|
|
|
|
{
|
2020-08-15 20:33:08 +02:00
|
|
|
if (LinkContest_SendBlock(gContestResources->excitement, sizeof(struct ContestExcitement)) == 1)
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 7:
|
2020-07-12 02:25:56 +02:00
|
|
|
if (LinkContest_GetBlockReceivedFromAllPlayers())
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
2020-08-15 20:33:08 +02:00
|
|
|
memcpy(gContestResources->excitement, gBlockRecvBuffer[gContestLinkLeaderIndex], sizeof(struct ContestExcitement));
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
if (IsLinkTaskFinished())
|
|
|
|
{
|
2020-07-12 02:25:56 +02:00
|
|
|
if (LinkContest_SendBlock(gContestantTurnOrder, sizeof(gContestantTurnOrder)) == 1)
|
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 10:
|
2020-07-12 02:25:56 +02:00
|
|
|
if (LinkContest_GetBlockReceivedFromAllPlayers())
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
2020-08-13 09:09:47 +02:00
|
|
|
memcpy(gContestantTurnOrder, gBlockRecvBuffer[gContestLinkLeaderIndex], sizeof(gContestantTurnOrder));
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState = 0;
|
2019-01-04 00:31:12 +01:00
|
|
|
SwitchTaskToFollowupFunc(taskId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-13 09:09:47 +02:00
|
|
|
void Task_LinkContest_CommunicateLeaderIdsRS(u8 taskId)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2020-08-15 20:33:08 +02:00
|
|
|
if (!LinkContest_TryLinkStandby(&gTasks[taskId].tStandbyState))
|
2019-01-04 00:31:12 +01:00
|
|
|
return;
|
|
|
|
|
2020-07-12 02:25:56 +02:00
|
|
|
switch (gTasks[taskId].tState)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
gBlockSendBuffer[0] = 0x6E;
|
|
|
|
if (GetMultiplayerId() == 0)
|
|
|
|
{
|
|
|
|
if (IsLinkTaskFinished())
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState = 10;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
2020-07-12 02:25:56 +02:00
|
|
|
if (LinkContest_GetBlockReceivedFromAllPlayers())
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
2020-07-12 02:25:56 +02:00
|
|
|
for (i = 0; i < CONTESTANT_COUNT; i++)
|
2020-08-15 20:33:08 +02:00
|
|
|
gTasks[taskId].tLeaderIds(i) = gBlockRecvBuffer[i][0];
|
2019-01-04 00:31:12 +01:00
|
|
|
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 10:
|
2020-07-12 02:25:56 +02:00
|
|
|
if (++gTasks[taskId].tTimer > 10)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
2021-08-15 22:11:30 +02:00
|
|
|
SendBlockRequest(BLOCK_REQ_SIZE_100);
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState = 1;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState = 0;
|
|
|
|
gTasks[taskId].tTimer = 0;
|
2020-08-15 20:33:08 +02:00
|
|
|
gTasks[taskId].tStandbyState = 0;
|
2019-01-04 00:31:12 +01:00
|
|
|
SwitchTaskToFollowupFunc(taskId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-24 06:14:53 +02:00
|
|
|
void Task_LinkContest_CommunicateRound1Points(u8 taskId)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
2020-08-15 20:33:08 +02:00
|
|
|
if (!LinkContest_TryLinkStandby(&gTasks[taskId].tStandbyState))
|
2019-01-04 00:31:12 +01:00
|
|
|
return;
|
|
|
|
|
2020-07-12 02:25:56 +02:00
|
|
|
switch (gTasks[taskId].tState)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
if (IsLinkTaskFinished())
|
|
|
|
{
|
2020-07-24 06:14:53 +02:00
|
|
|
if (LinkContest_SendBlock(gContestMonRound1Points, sizeof(gContestMonRound1Points)) == 1)
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
2020-07-12 02:25:56 +02:00
|
|
|
if (LinkContest_GetBlockReceivedFromAllPlayers())
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
2020-08-13 09:09:47 +02:00
|
|
|
memcpy(gContestMonRound1Points, gBlockRecvBuffer[gContestLinkLeaderIndex], sizeof(gContestMonRound1Points));
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState = 0;
|
2020-08-15 20:33:08 +02:00
|
|
|
gTasks[taskId].tStandbyState = 0;
|
2019-01-04 00:31:12 +01:00
|
|
|
SwitchTaskToFollowupFunc(taskId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-24 06:14:53 +02:00
|
|
|
void Task_LinkContest_CommunicateTurnOrder(u8 taskId)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
2020-08-15 20:33:08 +02:00
|
|
|
if (!LinkContest_TryLinkStandby(&gTasks[taskId].tStandbyState))
|
2019-01-04 00:31:12 +01:00
|
|
|
return;
|
|
|
|
|
2020-07-12 02:25:56 +02:00
|
|
|
switch (gTasks[taskId].tState)
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
if (IsLinkTaskFinished())
|
|
|
|
{
|
2020-07-12 02:25:56 +02:00
|
|
|
if (LinkContest_SendBlock(gContestantTurnOrder, sizeof(gContestantTurnOrder)) == 1)
|
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
2020-07-12 02:25:56 +02:00
|
|
|
if (LinkContest_GetBlockReceivedFromAllPlayers())
|
2019-01-04 00:31:12 +01:00
|
|
|
{
|
2020-08-13 09:09:47 +02:00
|
|
|
memcpy(gContestantTurnOrder, gBlockRecvBuffer[gContestLinkLeaderIndex], sizeof(gContestantTurnOrder));
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState++;
|
2019-01-04 00:31:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2020-07-12 02:25:56 +02:00
|
|
|
gTasks[taskId].tState = 0;
|
2020-08-15 20:33:08 +02:00
|
|
|
gTasks[taskId].tStandbyState = 0;
|
2019-01-04 00:31:12 +01:00
|
|
|
SwitchTaskToFollowupFunc(taskId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|