pokeemerald/src/union_room.c

4369 lines
141 KiB
C
Raw Normal View History

2017-11-11 06:39:02 +01:00
#include "global.h"
#include "malloc.h"
2019-08-02 00:41:55 +02:00
#include "battle.h"
#include "berry_crush.h"
2018-06-01 23:08:25 +02:00
#include "bg.h"
2019-08-02 00:41:55 +02:00
#include "cable_club.h"
#include "data.h"
#include "decompress.h"
#include "dodrio_berry_picking.h"
#include "dynamic_placeholder_text_util.h"
#include "easy_chat.h"
2018-06-01 23:08:25 +02:00
#include "event_data.h"
#include "event_object_lock.h"
2019-08-02 00:41:55 +02:00
#include "field_control_avatar.h"
#include "field_player_avatar.h"
#include "field_screen_effect.h"
#include "field_weather.h"
#include "international_string_util.h"
#include "librfu.h"
2018-06-01 23:08:25 +02:00
#include "link.h"
#include "link_rfu.h"
#include "list_menu.h"
2019-08-02 00:41:55 +02:00
#include "load_save.h"
#include "menu.h"
2018-06-01 23:08:25 +02:00
#include "menu_helpers.h"
2019-08-02 00:41:55 +02:00
#include "mevent.h"
#include "mystery_gift.h"
2018-06-03 22:39:10 +02:00
#include "overworld.h"
2018-06-04 12:07:32 +02:00
#include "palette.h"
2019-08-02 00:41:55 +02:00
#include "party_menu.h"
#include "pokemon_jump.h"
#include "random.h"
2019-11-07 19:26:53 +01:00
#include "save_location.h"
2019-08-02 00:41:55 +02:00
#include "script.h"
2019-03-02 09:18:08 +01:00
#include "script_pokemon_util_80F87D8.h"
2019-08-02 00:41:55 +02:00
#include "sound.h"
#include "start_menu.h"
#include "string_util.h"
2019-03-29 16:57:03 +01:00
#include "strings.h"
2019-08-02 00:41:55 +02:00
#include "task.h"
#include "trade.h"
#include "trainer_card.h"
2019-03-30 19:36:52 +01:00
#include "union_room.h"
2020-05-30 10:09:21 +02:00
#include "union_room_battle.h"
2019-03-27 01:03:46 +01:00
#include "union_room_chat.h"
2019-04-01 20:20:34 +02:00
#include "union_room_player_avatar.h"
2019-08-02 00:41:55 +02:00
#include "window.h"
#include "constants/battle_frontier.h"
2019-10-11 10:14:09 +02:00
#include "constants/cable_club.h"
2019-08-02 00:41:55 +02:00
#include "constants/game_stat.h"
#include "constants/maps.h"
2019-10-18 01:22:03 +02:00
#include "constants/party_menu.h"
2019-08-02 00:41:55 +02:00
#include "constants/rgb.h"
#include "constants/songs.h"
#include "constants/species.h"
2019-03-29 20:50:04 +01:00
2020-05-30 10:09:21 +02:00
static EWRAM_DATA u8 sUnionRoomPlayerName[12] = {};
EWRAM_DATA u8 gPlayerCurrActivity = 0;
static EWRAM_DATA u8 sPlayerActivityGroupSize = 0;
static EWRAM_DATA union WirelessLink_Main sWirelessLinkMain = {};
static EWRAM_DATA u32 sUnused = 0;
EWRAM_DATA struct GFtgtGnameSub gPartnerTgtGnameSub = {};
2019-10-04 23:24:03 +02:00
EWRAM_DATA u16 gUnionRoomOfferedSpecies = 0;
EWRAM_DATA u8 gUnionRoomRequestedMonType = 0;
static EWRAM_DATA struct UnionRoomTrade sUnionRoomTrade = {};
2018-06-03 22:39:10 +02:00
2018-06-01 23:08:25 +02:00
// IWRAM vars
2020-05-30 10:09:21 +02:00
static struct WirelessLink_Leader *sLeader;
static struct WirelessLink_Group *sGroup;
static struct WirelessLink_URoom *sURoom;
2017-11-11 06:39:02 +01:00
2018-06-01 23:08:25 +02:00
// this file's functions
2020-05-30 10:09:21 +02:00
static void UR_AddTextPrinterParameterized(u8 windowId, u8 arg1, const u8 *str, u8 arg3, u8 arg4, u8 arg5);
static u16 ReadAsU16(const u8 *ptr);
static void Task_TryBecomeLinkLeader(u8 taskId);
static void Task_TryJoinLinkGroup(u8 taskId);
static void Task_ListenToWireless(u8 taskId);
static void Task_MEvent_Leader(u8 taskId);
static void Task_CardOrNewsWithFriend(u8 taskId);
static void Task_CardOrNewsOverWireless(u8 taskId);
static void Task_RunUnionRoom(u8 taskId);
static void ClearUnkStruct_x1CArray(struct UnkStruct_Main4 *arg0, u8 count);
static void ClearUnkStruct_x20Array(struct UnkStruct_x20 *arg0, u8 count);
static u8 CreateTask_ListenForPartnersWithCompatibleSerialNos(struct UnkStruct_Main4 *arg0, u32 arg1);
static u8 CreateTask_ListenForPartnersWithSerial7F7D(struct UnkStruct_Main4 *arg0, u32 arg1);
static bool8 PrintOnTextbox(u8 *textState, const u8 *str);
static bool8 Leader_SetStateIfMemberListChanged(struct WirelessLink_Leader *data, u32 arg1, u32 arg2);
static u8 sub_8013398(struct UnkStruct_Main0 *arg0);
static s8 UnionRoomHandleYesNo(u8 *arg0, bool32 arg1);
static void IntlConvPartnerUname7(u8 *dest, struct UnkStruct_x20 *arg1);
static void Leader_DestroyResources(struct WirelessLink_Leader *data);
static void CreateTask_RunScriptAndFadeToActivity(void);
static u8 LeaderUpdateGroupMembership(struct UnkStruct_Main0 *arg0);
static void PrintGroupMemberCandidateOnWindowWithColor(u8 arg0, u8 arg1, u8 arg2, struct UnkStruct_x20 *arg3, u8 arg4, u8 id);
static u32 Findx20Inx1CArray(struct UnkStruct_x20 *arg0, struct UnkStruct_x1C *arg1);
static u8 Appendx1Ctox20(struct UnkStruct_x20 *arg0, struct UnkStruct_x1C *arg1, u8 arg2);
static u8 GetNewLeaderCandidate(void);
static u32 IsTryingToTradeAcrossVersionTooSoon(struct WirelessLink_Group *data, s32 id);
static void AskToJoinRfuGroup(struct WirelessLink_Group *data, s32 id);
static void JoinGroup_EnableScriptContexts(void);
static void PrintUnionRoomGroupOnWindow(u8 arg0, u8 arg1, u8 arg2, struct UnkStruct_x20 *arg3, u8 arg4, u8 id);
static bool32 AreUnionRoomPlayerGnamesDifferent(struct WirelessGnameUnamePair *arg0, struct WirelessGnameUnamePair *arg1);
static u32 GetPartyPositionOfRegisteredMon(struct UnionRoomTrade *arg0, u8 multiplayerId);
static void ResetUnionRoomTrade(struct UnionRoomTrade *arg0);
2020-05-30 10:09:21 +02:00
static void CreateTask_StartActivity(void);
2020-06-01 16:23:12 +02:00
static bool32 HasWonderCardOrNewsByLinkGroup(struct GFtgtGname *arg0, s16 arg1);
2020-05-30 10:09:21 +02:00
static u8 CreateTask_SearchForChildOrParent(struct UnkStruct_Main4 *arg0, struct UnkStruct_Main4 *arg1, u32 arg2);
static bool32 RegisterTradeMonAndGetIsEgg(u32 monId, struct UnionRoomTrade *trade);
static void RegisterTradeMon(u32 monId, struct UnionRoomTrade *arg1);
2020-05-30 10:09:21 +02:00
static void UR_EnableScriptContext2AndFreezeObjectEvents(void);
static bool32 PlayerIsTalkingToUnionRoomAide(void);
static u8 HandlePlayerListUpdate(void);
static bool32 PollPartnerYesNoResponse(struct WirelessLink_URoom *data);
static void ReceiveUnionRoomActivityPacket(struct WirelessLink_URoom *data);
static u8 GetActivePartnerSpriteGenderParam(struct WirelessLink_URoom *data);
static bool32 UnionRoom_HandleContactFromOtherPlayer(struct WirelessLink_URoom *data);
static bool32 UR_RunTextPrinters_CheckPrinter0Active(void);
static s32 GetUnionRoomPlayerGender(s32 arg1, struct UnkStruct_Main0 *arg0);
static s32 UnionRoomGetPlayerInteractionResponse(struct UnkStruct_Main0 *arg0, u8 arg1, u8 arg2, u32 playerGender);
static void HandleCancelTrade(bool32 arg0);
static s32 ListMenuHandler_AllItemsAvailable(u8 *arg0, u8 *arg1, u8 *arg2, const struct WindowTemplate *winTemplate, const struct ListMenuTemplate *menuTemplate);
static s32 TradeBoardMenuHandler(u8 *arg0, u8 *arg1, u8 *arg2, u8 *arg3, const struct WindowTemplate *winTemplate, const struct ListMenuTemplate *menuTemplate, struct UnkStruct_Main0 *arg6);
static s32 GetIndexOfNthTradeBoardOffer(struct UnkStruct_x20 * arg, s32 arg1);
static bool32 HasAtLeastTwoMonsOfLevel30OrLower(void);
static u32 GetResponseIdx_InviteToURoomActivity(s32 arg0);
static void ViewURoomPartnerTrainerCard(u8 *unused, struct WirelessLink_URoom *data, bool8 arg2);
static void GetURoomActivityRejectMsg(u8 *dst, s32 arg1, u32 playerGender);
static u32 ConvPartnerUnameAndGetWhetherMetAlready(struct UnkStruct_x20 *arg0);
static void GetURoomActivityStartMsg(u8 *dst, u8 arg1);
static void UR_ClearBg0(void);
static s32 IsRequestedTypeOrEggInPlayerParty(u32 type, u32 species);
static bool32 UR_PrintFieldMessage(const u8 *src);
static s32 GetChatLeaderActionRequestMessage(u8 *dst, u32 gender, u16 *arg2, struct WirelessLink_URoom *data);
static void Task_InitUnionRoom(u8 taskId);
static bool8 AreGnameUnameDifferent(struct WirelessGnameUnamePair* arg0, const struct WirelessGnameUnamePair* arg1);
static void ItemPrintFunc_PossibleGroupMembers(u8 windowId, s32 itemId, u8 y);
static void ListMenuItemPrintFunc_UnionRoomGroups(u8 windowId, s32 itemId, u8 y);
static void TradeBoardListMenuItemPrintFunc(u8 windowId, s32 itemId, u8 y);
static void nullsub_14(u8 windowId, s32 itemId, u8 y);
2018-06-01 23:08:25 +02:00
2019-10-04 23:24:03 +02:00
#include "data/union_room.h"
2019-03-28 16:24:50 +01:00
2018-06-01 23:08:25 +02:00
// code
2020-05-30 10:09:21 +02:00
static void PrintNumPlayersWaitingForMsg(u8 windowId, u8 capacityCode, u8 stringId)
2018-06-01 23:08:25 +02:00
{
FillWindowPixelBuffer(windowId, PIXEL_FILL(1));
2020-05-30 10:09:21 +02:00
switch (capacityCode << 8)
2018-06-01 23:08:25 +02:00
{
2020-05-30 10:09:21 +02:00
case LINK_GROUP_CAPACITY(0, 2):
UR_AddTextPrinterParameterized(windowId, 1, sPlayersNeededOrModeTexts[0][stringId - 1], 0, 1, UR_COLOR_DKE_WHT_LTE);
2018-06-01 23:08:25 +02:00
break;
2020-05-30 10:09:21 +02:00
case LINK_GROUP_CAPACITY(0, 4):
UR_AddTextPrinterParameterized(windowId, 1, sPlayersNeededOrModeTexts[1][stringId - 1], 0, 1, UR_COLOR_DKE_WHT_LTE);
2018-06-01 23:08:25 +02:00
break;
2020-05-30 10:09:21 +02:00
case LINK_GROUP_CAPACITY(2, 5):
UR_AddTextPrinterParameterized(windowId, 1, sPlayersNeededOrModeTexts[2][stringId - 1], 0, 1, UR_COLOR_DKE_WHT_LTE);
2018-06-01 23:08:25 +02:00
break;
2020-05-30 10:09:21 +02:00
case LINK_GROUP_CAPACITY(3, 5):
UR_AddTextPrinterParameterized(windowId, 1, sPlayersNeededOrModeTexts[3][stringId - 1], 0, 1, UR_COLOR_DKE_WHT_LTE);
2018-06-01 23:08:25 +02:00
break;
2020-05-30 10:09:21 +02:00
case LINK_GROUP_CAPACITY(2, 4):
UR_AddTextPrinterParameterized(windowId, 1, sPlayersNeededOrModeTexts[4][stringId - 1], 0, 1, UR_COLOR_DKE_WHT_LTE);
2018-06-01 23:08:25 +02:00
break;
}
CopyWindowToVram(windowId, 2);
}
2020-05-30 10:09:21 +02:00
static void PrintPlayerNameAndIdOnWindow(u8 windowId)
2018-06-01 23:08:25 +02:00
{
u8 text[30];
u8 *txtPtr;
2020-05-30 10:09:21 +02:00
UR_AddTextPrinterParameterized(windowId, 1, gSaveBlock2Ptr->playerName, 0, 1, UR_COLOR_DKE_WHT_LTE);
2019-12-10 19:48:20 +01:00
txtPtr = StringCopy(text, sText_ID);
2018-06-01 23:08:25 +02:00
ConvertIntToDecimalStringN(txtPtr, ReadAsU16(gSaveBlock2Ptr->playerTrainerId), STR_CONV_MODE_LEADING_ZEROS, 5);
2020-05-30 10:09:21 +02:00
UR_AddTextPrinterParameterized(windowId, 1, text, 0, 0x11, UR_COLOR_DKE_WHT_LTE);
2018-06-01 23:08:25 +02:00
}
2020-05-30 10:09:21 +02:00
static void StringExpandPlaceholders_AwaitingCommFromAnother(u8 *dst, u8 caseId)
2018-06-01 23:08:25 +02:00
{
switch (caseId)
{
2020-05-30 10:09:21 +02:00
case ACTIVITY_BATTLE_SINGLE:
case ACTIVITY_BATTLE_DOUBLE:
case ACTIVITY_BATTLE_MULTI:
case ACTIVITY_TRADE:
case ACTIVITY_POKEMON_JUMP:
case ACTIVITY_BERRY_CRUSH:
case ACTIVITY_BERRY_PICK:
case ACTIVITY_BATTLE_TOWER:
case ACTIVITY_BATTLE_TOWER_OPEN:
case ACTIVITY_RECORD_CORNER:
case ACTIVITY_BERRY_BLENDER:
case ACTIVITY_WONDER_CARD2:
case ACTIVITY_WONDER_NEWS2:
case ACTIVITY_CONTEST_COOL:
case ACTIVITY_CONTEST_BEAUTY:
case ACTIVITY_CONTEST_CUTE:
case ACTIVITY_CONTEST_SMART:
case ACTIVITY_CONTEST_TOUGH:
2018-06-01 23:08:25 +02:00
// UB: argument *dst isn't used, instead it always prints to gStringVar4
2019-12-10 19:48:20 +01:00
StringExpandPlaceholders(gStringVar4, sText_AwaitingCommunication);
2018-06-01 23:08:25 +02:00
break;
}
}
2020-05-30 10:09:21 +02:00
static bool32 IsActivityWithVariableGroupSize(u32 caseId)
2018-06-01 23:08:25 +02:00
{
switch (caseId)
{
2020-05-30 10:09:21 +02:00
case ACTIVITY_POKEMON_JUMP:
case ACTIVITY_BERRY_CRUSH:
case ACTIVITY_BERRY_PICK:
case ACTIVITY_RECORD_CORNER:
case ACTIVITY_BERRY_BLENDER:
case ACTIVITY_CONTEST_COOL:
case ACTIVITY_CONTEST_BEAUTY:
case ACTIVITY_CONTEST_CUTE:
case ACTIVITY_CONTEST_SMART:
case ACTIVITY_CONTEST_TOUGH:
2018-06-01 23:08:25 +02:00
return TRUE;
default:
return FALSE;
}
}
2019-10-11 10:14:09 +02:00
void TryBecomeLinkLeader(void)
2018-06-01 23:08:25 +02:00
{
u8 taskId;
2020-05-30 10:09:21 +02:00
struct WirelessLink_Leader *data;
2018-06-01 23:08:25 +02:00
2020-05-30 10:09:21 +02:00
taskId = CreateTask(Task_TryBecomeLinkLeader, 0);
sWirelessLinkMain.leader = data = (void*)(gTasks[taskId].data);
sLeader = data;
2018-06-01 23:08:25 +02:00
2020-05-30 10:09:21 +02:00
data->state = 0;
data->textState = 0;
2018-06-01 23:08:25 +02:00
gSpecialVar_Result = 0;
}
2020-05-30 10:09:21 +02:00
static void Task_TryBecomeLinkLeader(u8 taskId)
2018-06-01 23:08:25 +02:00
{
2018-06-03 09:37:01 +02:00
u32 id, val;
2020-05-30 10:09:21 +02:00
struct WirelessLink_Leader *data = sWirelessLinkMain.leader;
2018-06-01 23:08:25 +02:00
2018-06-03 09:37:01 +02:00
switch (data->state)
2018-06-01 23:08:25 +02:00
{
case 0:
2019-11-11 03:54:00 +01:00
if (gSpecialVar_0x8004 == LINK_GROUP_BATTLE_TOWER && gSaveBlock2Ptr->frontier.lvlMode == FRONTIER_LVL_OPEN)
2018-06-01 23:08:25 +02:00
gSpecialVar_0x8004++;
2020-05-30 10:09:21 +02:00
gPlayerCurrActivity = sLinkGroupToActivityAndCapacity[gSpecialVar_0x8004];
sPlayerActivityGroupSize = sLinkGroupToActivityAndCapacity[gSpecialVar_0x8004] >> 8;
SetHostRFUtgtGname(gPlayerCurrActivity, 0, 0);
SetWirelessCommType1();
2018-06-01 23:08:25 +02:00
OpenLink();
2020-05-30 10:09:21 +02:00
InitializeRfuLinkManager_LinkLeader(sPlayerActivityGroupSize & 0xF);
2018-06-03 09:37:01 +02:00
data->state = 3;
2018-06-01 23:08:25 +02:00
break;
case 3:
2020-05-30 10:09:21 +02:00
data->field_4 = AllocZeroed(4 * sizeof(struct UnkStruct_x1C));
data->field_0 = AllocZeroed(5 * sizeof(struct UnkStruct_x20));
data->field_8 = AllocZeroed(5 * sizeof(struct UnkStruct_x20));
ClearUnkStruct_x1CArray(data->field_4, 4);
ClearUnkStruct_x20Array(data->field_0->arr, 5);
LinkRfu3_SetGnameUnameFromStaticBuffers(&data->field_0->arr[0].gname_uname.gname, data->field_0->arr[0].gname_uname.playerName);
2018-06-03 09:37:01 +02:00
data->field_0->arr[0].field_18 = 0;
2020-05-30 10:09:21 +02:00
data->field_0->arr[0].groupScheduledAnim = UNION_ROOM_SPAWN_IN;
2018-06-03 09:37:01 +02:00
data->field_0->arr[0].field_1A_1 = 0;
data->field_0->arr[0].field_1B = 0;
2020-05-30 10:09:21 +02:00
data->listenTaskId = CreateTask_ListenForPartnersWithCompatibleSerialNos(data->field_4, 0xFF);
data->bButtonCancelWindowId = AddWindow(&sWindowTemplate_BButtonCancel);
switch (sPlayerActivityGroupSize & 0xF)
2018-06-01 23:08:25 +02:00
{
case 2:
case 3:
case 4:
2018-06-04 12:07:32 +02:00
data->listWindowId = AddWindow(&gUnknown_082F011C);
2018-06-01 23:08:25 +02:00
break;
case 5:
2018-06-04 12:07:32 +02:00
data->listWindowId = AddWindow(&gUnknown_082F0124);
2018-06-01 23:08:25 +02:00
break;
}
2020-05-30 10:09:21 +02:00
data->nPlayerModeWindowId = AddWindow(&sWindowTemplate_NumPlayerMode);
2018-06-01 23:08:25 +02:00
2020-05-30 10:09:21 +02:00
FillWindowPixelBuffer(data->bButtonCancelWindowId, PIXEL_FILL(2));
UR_AddTextPrinterParameterized(data->bButtonCancelWindowId, 0, sText_BButtonCancel, 8, 1, 4);
PutWindowTilemap(data->bButtonCancelWindowId);
CopyWindowToVram(data->bButtonCancelWindowId, 2);
2018-06-01 23:08:25 +02:00
DrawStdWindowFrame(data->listWindowId, FALSE);
2020-05-30 10:09:21 +02:00
gMultiuseListMenuTemplate = sListMenuTemplate_PossibleGroupMembers;
2018-06-04 12:07:32 +02:00
gMultiuseListMenuTemplate.windowId = data->listWindowId;
2018-06-03 09:37:01 +02:00
data->listTaskId = ListMenuInit(&gMultiuseListMenuTemplate, 0, 0);
2018-06-01 23:08:25 +02:00
2020-05-30 10:09:21 +02:00
DrawStdWindowFrame(data->nPlayerModeWindowId, FALSE);
PutWindowTilemap(data->nPlayerModeWindowId);
CopyWindowToVram(data->nPlayerModeWindowId, 2);
2017-11-11 06:39:02 +01:00
2018-06-01 23:08:25 +02:00
CopyBgTilemapBufferToVram(0);
2020-05-30 10:09:21 +02:00
data->playerCount = 1;
2018-06-03 09:37:01 +02:00
data->state = 4;
2018-06-01 23:08:25 +02:00
break;
case 4:
2020-05-30 10:09:21 +02:00
StringCopy(gStringVar1, sLinkGroupActivityTexts[gPlayerCurrActivity]);
if ((sPlayerActivityGroupSize >> 4) != 0)
2018-06-01 23:08:25 +02:00
{
2020-05-30 10:09:21 +02:00
if (data->playerCount > (sPlayerActivityGroupSize >> 4) - 1 && (sPlayerActivityGroupSize & 0xF) != 0)
2019-12-10 19:48:20 +01:00
StringExpandPlaceholders(gStringVar4, sText_AwaitingLinkPressStart);
2018-06-01 23:08:25 +02:00
else
2019-12-10 19:48:20 +01:00
StringExpandPlaceholders(gStringVar4, sText_AwaitingCommunication);
2018-06-01 23:08:25 +02:00
}
else
{
2020-05-30 10:09:21 +02:00
StringExpandPlaceholders_AwaitingCommFromAnother(gStringVar4, gPlayerCurrActivity);
2018-06-01 23:08:25 +02:00
}
2017-11-11 06:39:02 +01:00
2020-05-30 10:09:21 +02:00
PrintNumPlayersWaitingForMsg(data->nPlayerModeWindowId, sPlayerActivityGroupSize, data->playerCount);
2018-06-03 09:37:01 +02:00
data->state = 5;
2018-06-01 23:08:25 +02:00
break;
case 5:
2018-06-03 09:37:01 +02:00
if (PrintOnTextbox(&data->textState, gStringVar4))
data->state = 6;
2018-06-01 23:08:25 +02:00
break;
case 6:
2020-05-30 10:09:21 +02:00
Leader_SetStateIfMemberListChanged(data, 7, 10);
2018-06-01 23:08:25 +02:00
if (gMain.newKeys & B_BUTTON)
{
2020-05-30 10:09:21 +02:00
if (data->playerCount == 1)
2018-06-03 09:37:01 +02:00
data->state = 23;
2020-05-30 10:09:21 +02:00
else if ((sPlayerActivityGroupSize & 0xF0) != 0)
2018-06-03 09:37:01 +02:00
data->state = 30;
else
data->state = 19;
}
2020-05-30 10:09:21 +02:00
if ((sPlayerActivityGroupSize >> 4) != 0
&& data->playerCount > (sPlayerActivityGroupSize >> 4) - 1
&& (sPlayerActivityGroupSize & 0xF) != 0
2018-06-03 09:37:01 +02:00
&& sub_8012240()
&& gMain.newKeys & START_BUTTON)
{
data->state = 15;
2020-05-30 10:09:21 +02:00
LinkRfu_StopManagerAndFinalizeSlots();
2018-06-03 09:37:01 +02:00
}
if (data->state == 6 && sub_80105EC())
{
data->state = 9;
}
break;
case 9:
if (!sub_80105EC())
{
data->state = 6;
2020-05-30 10:09:21 +02:00
data->playerCount = sub_8013398(data->field_0);
2018-06-03 09:37:01 +02:00
}
break;
case 10:
2020-05-30 10:09:21 +02:00
id = ((gPlayerCurrActivity & 0xF) == 2) ? 1 : 0;
2019-12-10 19:48:20 +01:00
if (PrintOnTextbox(&data->textState, sPlayerUnavailableTexts[id]))
2018-06-03 09:37:01 +02:00
{
2020-05-30 10:09:21 +02:00
data->playerCount = sub_8013398(data->field_0);
2018-07-22 13:14:58 +02:00
RedrawListMenu(data->listTaskId);
2018-06-03 09:37:01 +02:00
data->state = 4;
}
break;
case 29:
2020-05-30 10:09:21 +02:00
// Other player canceled.
id = ((sPlayerActivityGroupSize & 0xF) == 2) ? 0 : 1;
2019-12-10 19:48:20 +01:00
if (PrintOnTextbox(&data->textState, sPlayerUnavailableTexts[id]))
2018-06-03 09:37:01 +02:00
{
data->state = 21;
}
break;
case 7:
if (PrintOnTextbox(&data->textState, gStringVar4))
{
data->state = 11;
}
break;
case 11:
2020-05-30 10:09:21 +02:00
switch (UnionRoomHandleYesNo(&data->textState, TrainerIdAndNameStillInPartnersList(ReadAsU16(data->field_0->arr[data->playerCount].gname_uname.gname.unk_00.playerTrainerId), data->field_0->arr[data->playerCount].gname_uname.playerName)))
2018-06-03 09:37:01 +02:00
{
case 0:
2019-04-04 23:05:46 +02:00
LoadWirelessStatusIndicatorSpriteGfx();
2018-06-03 09:37:01 +02:00
CreateWirelessStatusIndicatorSprite(0, 0);
data->field_19 = 5;
2020-05-30 10:09:21 +02:00
SendByteToPartnerByIdAndName(5, ReadAsU16(data->field_0->arr[data->playerCount].gname_uname.gname.unk_00.playerTrainerId), data->field_0->arr[data->playerCount].gname_uname.playerName);
2018-06-03 09:37:01 +02:00
data->state = 12;
break;
case 1:
case -1:
data->field_19 = 6;
2020-05-30 10:09:21 +02:00
SendByteToPartnerByIdAndName(6, ReadAsU16(data->field_0->arr[data->playerCount].gname_uname.gname.unk_00.playerTrainerId), data->field_0->arr[data->playerCount].gname_uname.playerName);
2018-06-03 09:37:01 +02:00
data->state = 12;
break;
case -3:
data->state = 9;
break;
}
break;
case 12:
2020-05-30 10:09:21 +02:00
val = WaitSendByteToPartnerByIdAndName(ReadAsU16(data->field_0->arr[data->playerCount].gname_uname.gname.unk_00.playerTrainerId), data->field_0->arr[data->playerCount].gname_uname.playerName);
2018-06-03 09:37:01 +02:00
if (val == 1)
{
if (data->field_19 == 5)
{
2020-05-30 10:09:21 +02:00
data->field_0->arr[data->playerCount].field_1B = 0;
2018-07-22 13:14:58 +02:00
RedrawListMenu(data->listTaskId);
2020-05-30 10:09:21 +02:00
data->playerCount++;
if (data->playerCount == (sPlayerActivityGroupSize & 0xF))
2018-06-03 09:37:01 +02:00
{
2020-05-30 10:09:21 +02:00
if ((sPlayerActivityGroupSize & 0xF0) != 0 || data->playerCount == 4)
2018-06-03 09:37:01 +02:00
{
data->state = 15;
}
else
{
2020-05-30 10:09:21 +02:00
IntlConvPartnerUname7(gStringVar1, &data->field_0->arr[data->playerCount - 1]);
2019-12-10 19:48:20 +01:00
StringExpandPlaceholders(gStringVar4, sText_AnOKWasSentToPlayer);
2018-06-03 09:37:01 +02:00
data->state = 13;
}
2020-05-30 10:09:21 +02:00
LinkRfu_StopManagerAndFinalizeSlots();
PrintNumPlayersWaitingForMsg(data->nPlayerModeWindowId, sPlayerActivityGroupSize, data->playerCount);
2018-06-03 09:37:01 +02:00
}
else
{
data->state = 4;
}
}
else
{
2020-05-30 10:09:21 +02:00
RequestDisconnectSlotByTrainerNameAndId(data->field_0->arr[data->playerCount].gname_uname.playerName, ReadAsU16(data->field_0->arr[data->playerCount].gname_uname.gname.unk_00.playerTrainerId));
data->field_0->arr[data->playerCount].groupScheduledAnim = UNION_ROOM_SPAWN_NONE;
2018-06-03 09:37:01 +02:00
sub_8013398(data->field_0);
2018-07-22 13:14:58 +02:00
RedrawListMenu(data->listTaskId);
2018-06-03 09:37:01 +02:00
data->state = 4;
}
data->field_19 = 0;
2018-06-01 23:08:25 +02:00
}
2018-06-03 09:37:01 +02:00
else if (val == 2)
{
2020-05-30 10:09:21 +02:00
RfuSetErrorStatus(0, 0);
2018-06-03 09:37:01 +02:00
data->state = 4;
}
break;
case 13:
if (PrintOnTextbox(&data->textState, gStringVar4))
data->state = 14;
break;
case 14:
2020-05-30 10:09:21 +02:00
if (++data->delayTimerAfterOk > 120)
2018-06-03 09:37:01 +02:00
data->state = 17;
break;
case 15:
2019-12-10 19:48:20 +01:00
if (PrintOnTextbox(&data->textState, sText_AreTheseMembersOK))
2018-06-03 09:37:01 +02:00
data->state = 16;
break;
case 16:
2020-05-30 10:09:21 +02:00
switch (UnionRoomHandleYesNo(&data->textState, FALSE))
2018-06-03 09:37:01 +02:00
{
case 0:
data->state = 17;
break;
case 1:
case -1:
2020-05-30 10:09:21 +02:00
if ((sPlayerActivityGroupSize & 0xF0) != 0)
2018-06-03 09:37:01 +02:00
data->state = 30;
else
data->state = 19;
break;
}
break;
case 19:
2019-12-10 19:48:20 +01:00
if (PrintOnTextbox(&data->textState, sText_CancelModeWithTheseMembers))
2018-06-03 09:37:01 +02:00
data->state = 20;
break;
case 20:
2020-05-30 10:09:21 +02:00
switch (UnionRoomHandleYesNo(&data->textState, FALSE))
2018-06-03 09:37:01 +02:00
{
case 0:
data->state = 23;
break;
case 1:
case -1:
2020-05-30 10:09:21 +02:00
if ((sPlayerActivityGroupSize & 0xF0) != 0)
2018-06-03 09:37:01 +02:00
data->state = 15;
2020-05-30 10:09:21 +02:00
else if (data->playerCount == (sPlayerActivityGroupSize & 0xF))
2018-06-03 09:37:01 +02:00
data->state = 15;
else
data->state = 4;
break;
}
break;
case 17:
2020-05-30 10:09:21 +02:00
if (!Leader_SetStateIfMemberListChanged(data, 7, 29))
2018-06-03 09:37:01 +02:00
data->state = 18;
break;
case 18:
2020-05-30 10:09:21 +02:00
if (LmanAcceptSlotFlagIsNotZero())
2018-06-03 09:37:01 +02:00
{
2020-05-30 10:09:21 +02:00
if (WaitRfuState(FALSE))
2018-06-03 09:37:01 +02:00
{
data->state = 26;
}
else
{
if (++data->field_1A > 300)
{
data->state = 29;
data->textState = 0;
}
}
}
else
{
data->state = 29;
data->textState = 0;
}
break;
case 30:
2019-12-10 19:48:20 +01:00
if (PrintOnTextbox(&data->textState, sText_ModeWithTheseMembersWillBeCanceled))
2018-06-03 09:37:01 +02:00
data->state = 23;
break;
case 21:
case 23:
2019-04-01 00:59:52 +02:00
DestroyWirelessStatusIndicatorSprite();
2020-05-30 10:09:21 +02:00
LinkRfu_Shutdown();
Leader_DestroyResources(data);
2018-06-03 09:37:01 +02:00
data->state++;
break;
case 24:
EnableBothScriptContexts();
DestroyTask(taskId);
gSpecialVar_Result = 5;
break;
case 22:
EnableBothScriptContexts();
DestroyTask(taskId);
gSpecialVar_Result = 8;
break;
case 26:
2020-05-30 10:09:21 +02:00
if (RfuIsErrorStatus1or2())
2018-06-03 09:37:01 +02:00
{
data->state = 29;
}
else
{
if (gReceivedRemoteLinkPlayers != 0)
{
2020-05-30 10:09:21 +02:00
if (IsActivityWithVariableGroupSize(gPlayerCurrActivity))
2018-06-03 09:37:01 +02:00
sub_801103C();
2020-05-30 10:09:21 +02:00
UpdateGameData_GroupLockedIn(TRUE);
CreateTask_RunScriptAndFadeToActivity();
Leader_DestroyResources(data);
2018-06-03 09:37:01 +02:00
DestroyTask(taskId);
}
}
break;
}
}
2020-05-30 10:09:21 +02:00
static void Leader_DestroyResources(struct WirelessLink_Leader *data)
2018-06-03 09:37:01 +02:00
{
2020-05-30 10:09:21 +02:00
ClearWindowTilemap(data->nPlayerModeWindowId);
ClearStdWindowAndFrame(data->nPlayerModeWindowId, FALSE);
2018-06-03 09:37:01 +02:00
DestroyListMenuTask(data->listTaskId, 0, 0);
2020-05-30 10:09:21 +02:00
ClearWindowTilemap(data->bButtonCancelWindowId);
ClearStdWindowAndFrame(data->listWindowId, FALSE);
2018-06-03 09:37:01 +02:00
CopyBgTilemapBufferToVram(0);
2020-05-30 10:09:21 +02:00
RemoveWindow(data->nPlayerModeWindowId);
2018-06-04 12:07:32 +02:00
RemoveWindow(data->listWindowId);
2020-05-30 10:09:21 +02:00
RemoveWindow(data->bButtonCancelWindowId);
DestroyTask(data->listenTaskId);
2018-06-03 09:37:01 +02:00
Free(data->field_8);
Free(data->field_0);
Free(data->field_4);
}
2020-05-30 10:09:21 +02:00
static void Leader_GetAcceptNewMemberPrompt(u8 *dst, u8 caseId)
2018-06-03 09:37:01 +02:00
{
switch (caseId)
{
2020-05-30 10:09:21 +02:00
case ACTIVITY_BATTLE_SINGLE:
case ACTIVITY_BATTLE_DOUBLE:
case ACTIVITY_TRADE:
case ACTIVITY_BATTLE_TOWER_OPEN:
case ACTIVITY_BATTLE_TOWER:
2019-12-10 19:48:20 +01:00
StringExpandPlaceholders(dst, sText_PlayerContactedYouForXAccept);
2018-06-03 09:37:01 +02:00
break;
2020-05-30 10:09:21 +02:00
case ACTIVITY_WONDER_CARD2:
case ACTIVITY_WONDER_NEWS2:
2019-12-10 19:48:20 +01:00
StringExpandPlaceholders(dst, sText_PlayerContactedYouShareX);
2018-06-03 09:37:01 +02:00
break;
2020-05-30 10:09:21 +02:00
case ACTIVITY_BATTLE_MULTI:
case ACTIVITY_POKEMON_JUMP:
case ACTIVITY_BERRY_CRUSH:
case ACTIVITY_BERRY_PICK:
case ACTIVITY_RECORD_CORNER:
case ACTIVITY_BERRY_BLENDER:
case ACTIVITY_CONTEST_COOL:
case ACTIVITY_CONTEST_BEAUTY:
case ACTIVITY_CONTEST_CUTE:
case ACTIVITY_CONTEST_SMART:
case ACTIVITY_CONTEST_TOUGH:
2019-12-10 19:48:20 +01:00
StringExpandPlaceholders(dst, sText_PlayerContactedYouAddToMembers);
2018-06-03 09:37:01 +02:00
break;
}
}
2020-05-30 10:09:21 +02:00
static void GetYouDeclinedTheOfferMessage(u8 *dst, u8 caseId)
2018-06-03 09:37:01 +02:00
{
switch (caseId)
{
2020-05-30 10:09:21 +02:00
case ACTIVITY_BATTLE_SINGLE | IN_UNION_ROOM:
case ACTIVITY_TRADE | IN_UNION_ROOM:
StringExpandPlaceholders(dst, sText_OfferDeclined1);
2018-06-03 09:37:01 +02:00
break;
2020-05-30 10:09:21 +02:00
case ACTIVITY_CHAT | IN_UNION_ROOM:
case ACTIVITY_CARD | IN_UNION_ROOM:
StringExpandPlaceholders(dst, sText_OfferDeclined2);
2018-06-03 09:37:01 +02:00
break;
}
}
2020-05-30 10:09:21 +02:00
static void GetYouAskedToJoinGroupPleaseWaitMessage(u8 *dst, u8 caseId)
2018-06-03 09:37:01 +02:00
{
switch (caseId)
{
2020-05-30 10:09:21 +02:00
case ACTIVITY_BATTLE_SINGLE:
case ACTIVITY_BATTLE_DOUBLE:
case ACTIVITY_TRADE:
case ACTIVITY_BATTLE_TOWER:
case ACTIVITY_BATTLE_TOWER_OPEN:
case ACTIVITY_WONDER_CARD2:
case ACTIVITY_WONDER_NEWS2:
2019-12-10 19:48:20 +01:00
StringExpandPlaceholders(dst, sText_AwaitingPlayersResponse);
2018-06-03 09:37:01 +02:00
break;
2020-05-30 10:09:21 +02:00
case ACTIVITY_BATTLE_MULTI:
case ACTIVITY_POKEMON_JUMP:
case ACTIVITY_BERRY_CRUSH:
case ACTIVITY_BERRY_PICK:
case ACTIVITY_RECORD_CORNER:
case ACTIVITY_BERRY_BLENDER:
case ACTIVITY_CONTEST_COOL:
case ACTIVITY_CONTEST_BEAUTY:
case ACTIVITY_CONTEST_CUTE:
case ACTIVITY_CONTEST_SMART:
case ACTIVITY_CONTEST_TOUGH:
2019-12-10 19:48:20 +01:00
StringExpandPlaceholders(dst, sText_PlayerHasBeenAskedToRegisterYouPleaseWait);
2018-06-03 09:37:01 +02:00
break;
}
}
2020-05-30 10:09:21 +02:00
static void GetGroupLeaderSentAnOKMessage(u8 *dst, u8 caseId)
2018-06-03 09:37:01 +02:00
{
switch (caseId)
{
2020-05-30 10:09:21 +02:00
case ACTIVITY_BATTLE_SINGLE:
case ACTIVITY_BATTLE_DOUBLE:
case ACTIVITY_TRADE:
case ACTIVITY_BATTLE_TOWER:
case ACTIVITY_BATTLE_TOWER_OPEN:
case ACTIVITY_WONDER_CARD2:
case ACTIVITY_WONDER_NEWS2:
2019-12-10 19:48:20 +01:00
StringExpandPlaceholders(dst, sText_PlayerSentBackOK);
2018-06-03 09:37:01 +02:00
break;
2020-05-30 10:09:21 +02:00
case ACTIVITY_BATTLE_MULTI:
case ACTIVITY_POKEMON_JUMP:
case ACTIVITY_BERRY_CRUSH:
case ACTIVITY_BERRY_PICK:
case ACTIVITY_RECORD_CORNER:
case ACTIVITY_BERRY_BLENDER:
case ACTIVITY_CONTEST_COOL:
case ACTIVITY_CONTEST_BEAUTY:
case ACTIVITY_CONTEST_CUTE:
case ACTIVITY_CONTEST_SMART:
case ACTIVITY_CONTEST_TOUGH:
2019-12-10 19:48:20 +01:00
StringExpandPlaceholders(dst, sText_PlayerOKdRegistration);
2018-06-03 09:37:01 +02:00
break;
}
}
2020-05-30 10:09:21 +02:00
static bool8 Leader_SetStateIfMemberListChanged(struct WirelessLink_Leader *data, u32 state1, u32 state2)
2018-06-03 09:37:01 +02:00
{
2020-05-30 10:09:21 +02:00
switch (LeaderUpdateGroupMembership(data->field_0))
2018-06-03 09:37:01 +02:00
{
2020-05-30 10:09:21 +02:00
case UNION_ROOM_SPAWN_IN:
2018-06-03 09:37:01 +02:00
PlaySE(SE_PC_LOGIN);
2018-07-22 13:14:58 +02:00
RedrawListMenu(data->listTaskId);
2020-05-30 10:09:21 +02:00
IntlConvPartnerUname7(gStringVar2, &data->field_0->arr[data->playerCount]);
Leader_GetAcceptNewMemberPrompt(gStringVar4, gPlayerCurrActivity);
data->state = state1;
2018-06-03 09:37:01 +02:00
break;
2020-05-30 10:09:21 +02:00
case UNION_ROOM_SPAWN_OUT:
RfuSetErrorStatus(0, 0);
2018-07-22 13:14:58 +02:00
RedrawListMenu(data->listTaskId);
2020-05-30 10:09:21 +02:00
data->state = state2;
2018-06-03 09:37:01 +02:00
return TRUE;
}
return FALSE;
}
2020-05-30 10:09:21 +02:00
static void ItemPrintFunc_PossibleGroupMembers(u8 windowId, s32 id, u8 y)
2018-06-03 09:37:01 +02:00
{
2020-05-30 10:09:21 +02:00
struct WirelessLink_Leader *data = sWirelessLinkMain.leader;
2018-06-03 09:37:01 +02:00
u8 var = 0;
2020-05-30 10:09:21 +02:00
switch (data->field_0->arr[id].groupScheduledAnim)
2018-06-03 09:37:01 +02:00
{
2020-05-30 10:09:21 +02:00
case UNION_ROOM_SPAWN_IN:
2018-06-03 09:37:01 +02:00
if (data->field_0->arr[id].field_1B != 0)
var = 2;
break;
2020-05-30 10:09:21 +02:00
case UNION_ROOM_SPAWN_OUT:
2018-06-03 09:37:01 +02:00
var = 1;
break;
}
2020-05-30 10:09:21 +02:00
PrintGroupMemberCandidateOnWindowWithColor(windowId, 0, y, &data->field_0->arr[id], var, id);
2018-06-03 09:37:01 +02:00
}
2020-05-30 10:09:21 +02:00
static u8 LeaderUpdateGroupMembership(struct UnkStruct_Main0 *arg0)
2018-06-03 09:37:01 +02:00
{
2020-05-30 10:09:21 +02:00
struct WirelessLink_Leader *data = sWirelessLinkMain.leader;
u8 ret = UNION_ROOM_SPAWN_NONE;
2018-06-03 09:37:01 +02:00
u8 i;
s32 id;
for (i = 1; i < 5; i++)
{
2020-05-30 10:09:21 +02:00
u16 var = data->field_0->arr[i].groupScheduledAnim;
if (var == UNION_ROOM_SPAWN_IN)
2018-06-03 09:37:01 +02:00
{
2020-05-30 10:09:21 +02:00
id = Findx20Inx1CArray(&data->field_0->arr[i], data->field_4->arr);
2018-06-03 09:37:01 +02:00
if (id != 0xFF)
{
2020-05-30 10:09:21 +02:00
data->field_0->arr[i].gname_uname = data->field_4->arr[id].gname_uname;
data->field_0->arr[i].field_18 = 1;
2018-06-03 09:37:01 +02:00
}
else
{
2020-05-30 10:09:21 +02:00
data->field_0->arr[i].groupScheduledAnim = UNION_ROOM_SPAWN_OUT;
ret = UNION_ROOM_SPAWN_OUT;
2018-06-03 09:37:01 +02:00
}
}
}
2020-05-30 10:09:21 +02:00
for (id = 0; id < RFU_CHILD_MAX; id++)
Appendx1Ctox20(data->field_0->arr, &data->field_4->arr[id], 5);
2018-06-03 09:37:01 +02:00
2020-05-30 10:09:21 +02:00
if (ret != UNION_ROOM_SPAWN_OUT)
2018-06-03 09:37:01 +02:00
{
for (id = 0; id < 5; id++)
{
if (data->field_0->arr[id].field_1B != 0)
2020-05-30 10:09:21 +02:00
ret = UNION_ROOM_SPAWN_IN;
2018-06-03 09:37:01 +02:00
}
}
return ret;
}
2020-05-30 10:09:21 +02:00
static u8 sub_8013398(struct UnkStruct_Main0 *arg0)
2018-06-03 09:37:01 +02:00
{
2020-05-30 10:09:21 +02:00
struct WirelessLink_Leader *data = sWirelessLinkMain.leader;
2018-06-03 09:37:01 +02:00
u8 copiedCount;
s32 i;
u8 ret;
for (i = 0; i < 5; i++)
data->field_8->arr[i] = data->field_0->arr[i];
copiedCount = 0;
for (i = 0; i < 5; i++)
{
2020-05-30 10:09:21 +02:00
if (data->field_8->arr[i].groupScheduledAnim == UNION_ROOM_SPAWN_IN)
2018-06-03 09:37:01 +02:00
{
data->field_0->arr[copiedCount] = data->field_8->arr[i];
copiedCount++;
}
}
ret = copiedCount;
for (; copiedCount < 5; copiedCount++)
{
2020-05-30 10:09:21 +02:00
data->field_0->arr[copiedCount].gname_uname = sWirelessGnameUnamePair_Dummy;
2018-06-03 09:37:01 +02:00
data->field_0->arr[copiedCount].field_18 = 0;
2020-05-30 10:09:21 +02:00
data->field_0->arr[copiedCount].groupScheduledAnim = UNION_ROOM_SPAWN_NONE;
2018-06-03 09:37:01 +02:00
data->field_0->arr[copiedCount].field_1A_1 = 0;
data->field_0->arr[copiedCount].field_1B = 0;
}
for (i = 0; i < 5; i++)
{
2020-05-30 10:09:21 +02:00
if (data->field_0->arr[i].groupScheduledAnim != UNION_ROOM_SPAWN_IN)
2018-06-03 09:37:01 +02:00
continue;
if (data->field_0->arr[i].field_1B != 0x40)
continue;
ret = i;
break;
}
return ret;
}
2019-10-11 10:14:09 +02:00
void TryJoinLinkGroup(void)
2018-06-03 09:37:01 +02:00
{
u8 taskId;
2020-05-30 10:09:21 +02:00
struct WirelessLink_Group *data;
2018-06-03 09:37:01 +02:00
2020-05-30 10:09:21 +02:00
taskId = CreateTask(Task_TryJoinLinkGroup, 0);
sWirelessLinkMain.group = data = (void*)(gTasks[taskId].data);
sGroup = data;
2018-06-03 09:37:01 +02:00
2020-05-30 10:09:21 +02:00
data->state = 0;
data->textState = 0;
2018-06-03 09:37:01 +02:00
gSpecialVar_Result = 0;
}
2020-05-30 10:09:21 +02:00
static void Task_TryJoinLinkGroup(u8 taskId)
2018-06-03 09:37:01 +02:00
{
s32 id;
2020-05-30 10:09:21 +02:00
struct WirelessLink_Group *data = sWirelessLinkMain.group;
2018-06-03 09:37:01 +02:00
switch (data->state)
{
case 0:
2019-11-11 03:54:00 +01:00
if (gSpecialVar_0x8004 == LINK_GROUP_BATTLE_TOWER && gSaveBlock2Ptr->frontier.lvlMode == FRONTIER_LVL_OPEN)
2018-06-03 09:37:01 +02:00
gSpecialVar_0x8004++;
2020-05-30 10:09:21 +02:00
gPlayerCurrActivity = sLinkGroupToURoomActivity[gSpecialVar_0x8004];
SetHostRFUtgtGname(gPlayerCurrActivity, 0, 0);
SetWirelessCommType1();
2018-06-03 09:37:01 +02:00
OpenLink();
2020-05-30 10:09:21 +02:00
InitializeRfuLinkManager_JoinGroup();
data->field_4 = AllocZeroed(4 * sizeof(struct UnkStruct_x1C));
data->field_0 = AllocZeroed(16 * sizeof(struct UnkStruct_x20));
2018-06-03 09:37:01 +02:00
data->state = 1;
break;
case 1:
2019-11-11 03:54:00 +01:00
if (PrintOnTextbox(&data->textState, sChooseTrainerTexts[gSpecialVar_0x8004]))
2018-06-03 09:37:01 +02:00
data->state = 2;
break;
case 2:
2020-05-30 10:09:21 +02:00
ClearUnkStruct_x1CArray(data->field_4, 4);
ClearUnkStruct_x20Array(data->field_0->arr, 16);
data->listenTaskId = CreateTask_ListenForPartnersWithCompatibleSerialNos(data->field_4, gSpecialVar_0x8004);
data->bButtonCancelWindowId = AddWindow(&sWindowTemplate_BButtonCancel);
2018-06-04 23:32:28 +02:00
data->listWindowId = AddWindow(&gUnknown_082F0174);
2020-05-30 10:09:21 +02:00
data->playerNameAndIdWindowId = AddWindow(&gUnknown_082F017C);
2018-06-03 09:37:01 +02:00
2020-05-30 10:09:21 +02:00
FillWindowPixelBuffer(data->bButtonCancelWindowId, PIXEL_FILL(2));
UR_AddTextPrinterParameterized(data->bButtonCancelWindowId, 0, sText_ChooseJoinCancel, 8, 1, 4);
PutWindowTilemap(data->bButtonCancelWindowId);
CopyWindowToVram(data->bButtonCancelWindowId, 2);
2018-06-03 09:37:01 +02:00
DrawStdWindowFrame(data->listWindowId, FALSE);
2020-05-30 10:09:21 +02:00
gMultiuseListMenuTemplate = sListMenuTemplate_UnionRoomGroups;
2018-06-04 23:32:28 +02:00
gMultiuseListMenuTemplate.windowId = data->listWindowId;
2018-06-03 09:37:01 +02:00
data->listTaskId = ListMenuInit(&gMultiuseListMenuTemplate, 0, 0);
2020-05-30 10:09:21 +02:00
DrawStdWindowFrame(data->playerNameAndIdWindowId, FALSE);
PutWindowTilemap(data->playerNameAndIdWindowId);
PrintPlayerNameAndIdOnWindow(data->playerNameAndIdWindowId);
CopyWindowToVram(data->playerNameAndIdWindowId, 2);
2018-06-03 09:37:01 +02:00
CopyBgTilemapBufferToVram(0);
2020-05-30 10:09:21 +02:00
data->leaderId = 0;
2018-06-03 09:37:01 +02:00
data->state = 3;
break;
case 3:
2020-05-30 10:09:21 +02:00
id = GetNewLeaderCandidate();
2018-06-03 09:37:01 +02:00
switch (id)
{
case 1:
PlaySE(SE_PC_LOGIN);
2018-07-22 13:14:58 +02:00
RedrawListMenu(data->listTaskId);
2018-06-03 09:37:01 +02:00
break;
case 0:
2019-02-02 11:04:38 +01:00
id = ListMenu_ProcessInput(data->listTaskId);
2018-06-03 09:37:01 +02:00
if (gMain.newKeys & A_BUTTON && id != -1)
{
2018-06-03 22:39:10 +02:00
// this unused variable along with the assignment is needed to match
2018-06-03 09:37:01 +02:00
u32 unusedVar;
2020-05-30 10:09:21 +02:00
unusedVar = data->field_0->arr[id].gname_uname.gname.activity;
2018-06-03 09:37:01 +02:00
2020-05-30 10:09:21 +02:00
if (data->field_0->arr[id].groupScheduledAnim == UNION_ROOM_SPAWN_IN && !data->field_0->arr[id].gname_uname.gname.started)
2018-06-03 09:37:01 +02:00
{
2020-05-30 10:09:21 +02:00
u32 var = IsTryingToTradeAcrossVersionTooSoon(data, id);
2018-06-03 09:37:01 +02:00
if (var == 0)
{
2020-05-30 10:09:21 +02:00
AskToJoinRfuGroup(data, id);
2018-06-03 09:37:01 +02:00
data->state = 5;
PlaySE(SE_PN_ON);
}
else
{
2019-12-10 19:48:20 +01:00
StringCopy(gStringVar4, sCantTransmitToTrainerTexts[var - 1]);
2018-06-03 09:37:01 +02:00
data->state = 18;
PlaySE(SE_PN_ON);
}
}
else
{
PlaySE(SE_WALL_HIT);
}
}
else if (gMain.newKeys & B_BUTTON)
{
data->state = 10;
}
break;
default:
2018-07-22 13:14:58 +02:00
RedrawListMenu(data->listTaskId);
2018-06-03 09:37:01 +02:00
break;
}
break;
case 5:
2020-05-30 10:09:21 +02:00
GetYouAskedToJoinGroupPleaseWaitMessage(gStringVar4, gPlayerCurrActivity);
2018-06-03 09:37:01 +02:00
if (PrintOnTextbox(&data->textState, gStringVar4))
{
2020-05-30 10:09:21 +02:00
IntlConvPartnerUname7(gStringVar1, &data->field_0->arr[data->leaderId]);
2018-06-03 09:37:01 +02:00
data->state = 6;
}
break;
case 6:
2020-05-30 10:09:21 +02:00
if (gReceivedRemoteLinkPlayers)
2018-06-03 09:37:01 +02:00
{
2020-05-30 10:09:21 +02:00
gPlayerCurrActivity = data->field_0->arr[data->leaderId].gname_uname.gname.activity;
RfuSetErrorStatus(0, 0);
switch (gPlayerCurrActivity)
2018-06-03 09:37:01 +02:00
{
2020-05-30 10:09:21 +02:00
case ACTIVITY_BATTLE_SINGLE:
case ACTIVITY_BATTLE_DOUBLE:
case ACTIVITY_BATTLE_MULTI:
case ACTIVITY_TRADE:
case ACTIVITY_CHAT:
case ACTIVITY_POKEMON_JUMP:
case ACTIVITY_BERRY_CRUSH:
case ACTIVITY_BERRY_PICK:
case ACTIVITY_SPIN_TRADE:
case ACTIVITY_BATTLE_TOWER:
case ACTIVITY_BATTLE_TOWER_OPEN:
case ACTIVITY_RECORD_CORNER:
case ACTIVITY_BERRY_BLENDER:
case ACTIVITY_WONDER_CARD2:
case ACTIVITY_WONDER_NEWS2:
case ACTIVITY_CONTEST_COOL:
case ACTIVITY_CONTEST_BEAUTY:
case ACTIVITY_CONTEST_CUTE:
case ACTIVITY_CONTEST_SMART:
case ACTIVITY_CONTEST_TOUGH:
2018-06-03 09:37:01 +02:00
data->state = 20;
return;
}
}
2020-05-30 10:09:21 +02:00
switch (RfuGetErrorStatus())
2018-06-03 09:37:01 +02:00
{
case 1:
data->state = 12;
break;
case 2:
case 6:
case 9:
data->state = 14;
break;
case 5:
2020-05-30 10:09:21 +02:00
GetGroupLeaderSentAnOKMessage(gStringVar4, gPlayerCurrActivity);
2018-06-03 09:37:01 +02:00
if (PrintOnTextbox(&data->textState, gStringVar4))
{
2020-05-30 10:09:21 +02:00
if (gPlayerCurrActivity == ACTIVITY_BATTLE_TOWER || gPlayerCurrActivity == ACTIVITY_BATTLE_TOWER_OPEN)
2018-06-03 09:37:01 +02:00
{
2020-05-30 10:09:21 +02:00
RfuSetErrorStatus(12, 0);
2018-06-03 09:37:01 +02:00
}
else
{
2020-05-30 10:09:21 +02:00
RfuSetErrorStatus(7, 0);
StringCopy(gStringVar1, sLinkGroupActivityTexts[gPlayerCurrActivity]);
2019-12-10 19:48:20 +01:00
StringExpandPlaceholders(gStringVar4, sText_AwaitingOtherMembers);
2018-06-03 09:37:01 +02:00
}
}
break;
case 7:
2020-05-30 10:09:21 +02:00
if (data->delayBeforePrint > 240)
2018-06-03 09:37:01 +02:00
{
if (PrintOnTextbox(&data->textState, gStringVar4))
{
2020-05-30 10:09:21 +02:00
RfuSetErrorStatus(12, 0);
data->delayBeforePrint = 0;
2018-06-03 09:37:01 +02:00
}
}
else
{
2020-05-30 10:09:21 +02:00
switch (gPlayerCurrActivity)
2018-06-03 09:37:01 +02:00
{
2020-05-30 10:09:21 +02:00
case ACTIVITY_BATTLE_SINGLE:
case ACTIVITY_BATTLE_DOUBLE:
case ACTIVITY_TRADE:
case ACTIVITY_BATTLE_TOWER:
case ACTIVITY_BATTLE_TOWER_OPEN:
2018-06-03 09:37:01 +02:00
break;
default:
2020-05-30 10:09:21 +02:00
data->delayBeforePrint++;
2018-06-03 09:37:01 +02:00
break;
}
}
break;
}
2020-05-30 10:09:21 +02:00
if (!RfuGetErrorStatus() && gMain.newKeys & B_BUTTON)
2018-06-03 09:37:01 +02:00
data->state = 7;
break;
case 7:
2019-12-10 19:48:20 +01:00
if (PrintOnTextbox(&data->textState, sText_QuitBeingMember))
2018-06-03 09:37:01 +02:00
data->state = 8;
break;
case 8:
2020-05-30 10:09:21 +02:00
switch (UnionRoomHandleYesNo(&data->textState, RfuGetErrorStatus()))
2018-06-03 09:37:01 +02:00
{
case 0:
2020-05-30 10:09:21 +02:00
LinkRfuNIsend8();
2018-06-03 09:37:01 +02:00
data->state = 9;
2018-07-22 13:14:58 +02:00
RedrawListMenu(data->listTaskId);
2018-06-03 09:37:01 +02:00
break;
case 1:
case -1:
data->state = 5;
2018-07-22 13:14:58 +02:00
RedrawListMenu(data->listTaskId);
2018-06-03 09:37:01 +02:00
break;
case -3:
data->state = 6;
2018-07-22 13:14:58 +02:00
RedrawListMenu(data->listTaskId);
2018-06-03 09:37:01 +02:00
break;
}
break;
case 9:
2020-05-30 10:09:21 +02:00
if (RfuGetErrorStatus())
2018-06-03 09:37:01 +02:00
data->state = 6;
break;
case 10:
case 12:
case 14:
case 18:
case 20:
2020-05-30 10:09:21 +02:00
ClearWindowTilemap(data->playerNameAndIdWindowId);
ClearStdWindowAndFrame(data->playerNameAndIdWindowId, FALSE);
2018-06-03 09:37:01 +02:00
DestroyListMenuTask(data->listTaskId, 0, 0);
2020-05-30 10:09:21 +02:00
ClearWindowTilemap(data->bButtonCancelWindowId);
ClearStdWindowAndFrame(data->listWindowId, FALSE);
2018-06-03 09:37:01 +02:00
CopyBgTilemapBufferToVram(0);
2020-05-30 10:09:21 +02:00
RemoveWindow(data->playerNameAndIdWindowId);
2018-06-04 23:32:28 +02:00
RemoveWindow(data->listWindowId);
2020-05-30 10:09:21 +02:00
RemoveWindow(data->bButtonCancelWindowId);
DestroyTask(data->listenTaskId);
2018-06-03 09:37:01 +02:00
Free(data->field_0);
Free(data->field_4);
data->state++;
break;
case 13:
2019-04-01 00:59:52 +02:00
DestroyWirelessStatusIndicatorSprite();
2020-05-30 10:09:21 +02:00
if (PrintOnTextbox(&data->textState, sPlayerDisconnectedTexts[RfuGetErrorStatus()]))
2018-06-03 09:37:01 +02:00
{
gSpecialVar_Result = 6;
data->state = 23;
}
break;
case 11:
2019-04-01 00:59:52 +02:00
DestroyWirelessStatusIndicatorSprite();
2018-06-03 09:37:01 +02:00
gSpecialVar_Result = 5;
data->state = 23;
break;
case 15:
2019-04-01 00:59:52 +02:00
DestroyWirelessStatusIndicatorSprite();
2020-05-30 10:09:21 +02:00
if (PrintOnTextbox(&data->textState, sPlayerDisconnectedTexts[RfuGetErrorStatus()]))
2018-06-03 09:37:01 +02:00
{
gSpecialVar_Result = 8;
data->state = 23;
}
break;
case 19:
if (PrintOnTextbox(&data->textState, gStringVar4))
{
gSpecialVar_Result = 8;
data->state = 23;
}
break;
case 23:
DestroyTask(taskId);
2020-05-30 10:09:21 +02:00
JoinGroup_EnableScriptContexts();
LinkRfu_Shutdown();
2018-06-03 09:37:01 +02:00
break;
case 21:
2020-05-30 10:09:21 +02:00
CreateTask_RunScriptAndFadeToActivity();
2018-06-03 09:37:01 +02:00
DestroyTask(taskId);
2018-06-01 23:08:25 +02:00
break;
}
}
2018-06-03 22:39:10 +02:00
2020-05-30 10:09:21 +02:00
static u32 IsTryingToTradeAcrossVersionTooSoon(struct WirelessLink_Group *data, s32 id)
2018-06-03 22:39:10 +02:00
{
2020-05-30 10:09:21 +02:00
struct UnkStruct_x20 *structPtr = &data->field_0->arr[id];
2018-06-03 22:39:10 +02:00
2020-05-30 10:09:21 +02:00
if (gPlayerCurrActivity == ACTIVITY_TRADE && structPtr->gname_uname.gname.unk_00.version != VERSION_EMERALD)
2018-06-03 22:39:10 +02:00
{
2019-11-07 19:26:53 +01:00
if (!(gSaveBlock2Ptr->specialSaveWarpFlags & CHAMPION_SAVEWARP))
2018-06-03 22:39:10 +02:00
return 1;
2020-05-30 10:09:21 +02:00
else if (structPtr->gname_uname.gname.unk_00.isChampion)
2018-06-03 22:39:10 +02:00
return 0;
}
else
{
return 0;
}
return 2;
}
2020-05-30 10:09:21 +02:00
static void AskToJoinRfuGroup(struct WirelessLink_Group *data, s32 id)
2018-06-03 22:39:10 +02:00
{
2020-05-30 10:09:21 +02:00
data->leaderId = id;
2019-04-04 23:05:46 +02:00
LoadWirelessStatusIndicatorSpriteGfx();
2018-06-03 22:39:10 +02:00
CreateWirelessStatusIndicatorSprite(0, 0);
2018-07-22 13:14:58 +02:00
RedrawListMenu(data->listTaskId);
2020-05-30 10:09:21 +02:00
IntlConvPartnerUname7(gStringVar1, &data->field_0->arr[data->leaderId]);
UpdateGameDataWithActivitySpriteGendersFlag(sLinkGroupToURoomActivity[gSpecialVar_0x8004], 0, 1);
CreateTask_RfuReconnectWithParent(data->field_0->arr[data->leaderId].gname_uname.playerName, ReadAsU16(data->field_0->arr[data->leaderId].gname_uname.gname.unk_00.playerTrainerId));
2018-06-03 22:39:10 +02:00
}
2020-05-30 10:09:21 +02:00
u8 CreateTask_ListenToWireless(void)
2018-06-03 22:39:10 +02:00
{
u8 taskId;
2020-05-30 10:09:21 +02:00
struct WirelessLink_Group *data;
2018-06-03 22:39:10 +02:00
2020-05-30 10:09:21 +02:00
taskId = CreateTask(Task_ListenToWireless, 0);
sWirelessLinkMain.group = data = (void*)(gTasks[taskId].data);
2018-06-03 22:39:10 +02:00
2020-05-30 10:09:21 +02:00
data->state = 0;
data->textState = 0;
2018-06-03 22:39:10 +02:00
2020-05-30 10:09:21 +02:00
sGroup = data;
2018-06-03 22:39:10 +02:00
return taskId;
}
2020-05-30 10:09:21 +02:00
static void Task_ListenToWireless(u8 taskId)
2018-06-03 22:39:10 +02:00
{
2020-05-30 10:09:21 +02:00
struct WirelessLink_Group *data = sWirelessLinkMain.group;
2018-06-03 22:39:10 +02:00
switch (data->state)
{
case 0:
2020-05-30 10:09:21 +02:00
SetHostRFUtgtGname(0, 0, 0);
SetWirelessCommType1();
2018-06-03 22:39:10 +02:00
OpenLink();
2020-05-30 10:09:21 +02:00
InitializeRfuLinkManager_JoinGroup();
2018-06-03 22:39:10 +02:00
sub_80111B0(TRUE);
2020-05-30 10:09:21 +02:00
data->field_4 = AllocZeroed(4 * sizeof(struct UnkStruct_x1C));
data->field_0 = AllocZeroed(16 * sizeof(struct UnkStruct_x20));
2018-06-03 22:39:10 +02:00
data->state = 2;
break;
case 2:
2020-05-30 10:09:21 +02:00
ClearUnkStruct_x1CArray(data->field_4, 4);
ClearUnkStruct_x20Array(data->field_0->arr, 16);
data->listenTaskId = CreateTask_ListenForPartnersWithCompatibleSerialNos(data->field_4, 0xFF);
data->leaderId = 0;
2018-06-03 22:39:10 +02:00
data->state = 3;
break;
case 3:
2020-05-30 10:09:21 +02:00
if (GetNewLeaderCandidate() == 1)
2018-06-03 22:39:10 +02:00
PlaySE(SE_PC_LOGIN);
if (gTasks[taskId].data[15] == 0xFF)
data->state = 10;
break;
case 10:
2020-05-30 10:09:21 +02:00
DestroyTask(data->listenTaskId);
2018-06-03 22:39:10 +02:00
Free(data->field_0);
Free(data->field_4);
2020-05-30 10:09:21 +02:00
LinkRfu_Shutdown();
2018-06-03 22:39:10 +02:00
data->state++;
break;
case 11:
2020-05-30 10:09:21 +02:00
LinkRfu_Shutdown();
2018-06-03 22:39:10 +02:00
DestroyTask(taskId);
break;
}
}
2020-06-01 16:23:12 +02:00
static bool32 IsPartnerActivityAcceptable(u32 activity, u32 linkGroup)
2018-06-03 22:39:10 +02:00
{
2020-06-01 16:23:12 +02:00
if (linkGroup == 0xFF)
2018-06-03 22:39:10 +02:00
return TRUE;
2020-06-01 16:23:12 +02:00
if (linkGroup <= ARRAY_COUNT(sAcceptedActivityIds)) // UB: <= may access data outside the array
2018-06-03 22:39:10 +02:00
{
2020-06-01 16:23:12 +02:00
const u8 *bytes = sAcceptedActivityIds[linkGroup];
2018-06-03 22:39:10 +02:00
while ((*(bytes) != 0xFF))
{
2020-05-30 10:09:21 +02:00
if ((*bytes) == activity)
2018-06-03 22:39:10 +02:00
return TRUE;
bytes++;
}
}
return FALSE;
}
2020-05-30 10:09:21 +02:00
static u8 URoomGroupListGetTextColor(struct WirelessLink_Group *data, u32 id)
2018-06-03 22:39:10 +02:00
{
2020-05-30 10:09:21 +02:00
if (data->field_0->arr[id].groupScheduledAnim == UNION_ROOM_SPAWN_IN)
2018-06-03 22:39:10 +02:00
{
2020-05-30 10:09:21 +02:00
if (data->field_0->arr[id].gname_uname.gname.started)
return UR_COLOR_WHT_WHT_LTE;
2018-06-03 22:39:10 +02:00
else if (data->field_0->arr[id].field_1A_1 != 0)
2020-05-30 10:09:21 +02:00
return UR_COLOR_RED_WHT_LTR;
2018-06-03 22:39:10 +02:00
else if (data->field_0->arr[id].field_1B != 0)
2020-05-30 10:09:21 +02:00
return UR_COLOR_GRN_WHT_LTG;
2018-06-03 22:39:10 +02:00
}
2020-05-30 10:09:21 +02:00
return UR_COLOR_DKE_WHT_LTE;
2018-06-03 22:39:10 +02:00
}
2020-05-30 10:09:21 +02:00
static void ListMenuItemPrintFunc_UnionRoomGroups(u8 windowId, s32 id, u8 y)
2018-06-03 22:39:10 +02:00
{
2020-05-30 10:09:21 +02:00
struct WirelessLink_Group *data = sWirelessLinkMain.group;
u8 colorId = URoomGroupListGetTextColor(data, id);
2018-06-03 22:39:10 +02:00
2020-05-30 10:09:21 +02:00
PrintUnionRoomGroupOnWindow(windowId, 8, y, &data->field_0->arr[id], colorId, id);
2018-06-03 22:39:10 +02:00
}
2020-05-30 10:09:21 +02:00
static u8 GetNewLeaderCandidate(void)
2018-06-03 22:39:10 +02:00
{
2020-05-30 10:09:21 +02:00
struct WirelessLink_Group *data = sWirelessLinkMain.group;
2018-06-03 22:39:10 +02:00
u8 ret = 0;
u8 i;
s32 id;
for (i = 0; i < 16; i++)
{
2020-05-30 10:09:21 +02:00
if (data->field_0->arr[i].groupScheduledAnim != UNION_ROOM_SPAWN_NONE)
2018-06-03 22:39:10 +02:00
{
2020-05-30 10:09:21 +02:00
id = Findx20Inx1CArray(&data->field_0->arr[i], data->field_4->arr);
2018-06-03 22:39:10 +02:00
if (id != 0xFF)
{
2020-05-30 10:09:21 +02:00
if (data->field_0->arr[i].groupScheduledAnim == UNION_ROOM_SPAWN_IN)
2018-06-03 22:39:10 +02:00
{
2020-05-30 10:09:21 +02:00
if (AreUnionRoomPlayerGnamesDifferent(&data->field_0->arr[i].gname_uname, &data->field_4->arr[id].gname_uname))
2018-06-03 22:39:10 +02:00
{
2020-05-30 10:09:21 +02:00
data->field_0->arr[i].gname_uname = data->field_4->arr[id].gname_uname;
data->field_0->arr[i].field_1B = 64;
2018-06-03 22:39:10 +02:00
ret = 1;
}
else
{
if (data->field_0->arr[i].field_1B != 0)
{
data->field_0->arr[i].field_1B--;
if (data->field_0->arr[i].field_1B == 0)
ret = 2;
}
}
}
else
{
2020-05-30 10:09:21 +02:00
data->field_0->arr[i].groupScheduledAnim = UNION_ROOM_SPAWN_IN;
data->field_0->arr[i].field_1B = 64;
2018-06-03 22:39:10 +02:00
ret = 1;
}
data->field_0->arr[i].field_18 = 0;
}
else
{
2020-05-30 10:09:21 +02:00
if (data->field_0->arr[i].groupScheduledAnim != UNION_ROOM_SPAWN_OUT)
2018-06-03 22:39:10 +02:00
{
data->field_0->arr[i].field_18++;
if (data->field_0->arr[i].field_18 >= 300)
{
2020-05-30 10:09:21 +02:00
data->field_0->arr[i].groupScheduledAnim = UNION_ROOM_SPAWN_OUT;
2018-06-03 22:39:10 +02:00
ret = 2;
}
}
}
}
}
2020-05-30 10:09:21 +02:00
for (id = 0; id < RFU_CHILD_MAX; id++)
2018-06-03 22:39:10 +02:00
{
2020-05-30 10:09:21 +02:00
if (Appendx1Ctox20(data->field_0->arr, &data->field_4->arr[id], 16) != 0xFF)
2018-06-03 22:39:10 +02:00
ret = 1;
}
return ret;
}
2020-06-04 00:00:53 +02:00
static void Task_CreateTradeMenu(u8 taskId)
2018-06-03 22:39:10 +02:00
{
2019-10-09 11:56:44 +02:00
CB2_StartCreateTradeMenu();
2018-06-03 22:39:10 +02:00
DestroyTask(taskId);
}
2020-06-04 00:00:53 +02:00
u8 CreateTask_CreateTradeMenu(void)
2018-06-03 22:39:10 +02:00
{
2020-06-04 00:00:53 +02:00
u8 taskId = CreateTask(Task_CreateTradeMenu, 0);
2018-06-03 22:39:10 +02:00
return taskId;
}
2020-05-30 10:09:21 +02:00
static void Task_StartUnionRoomTrade(u8 taskId)
2018-06-03 22:39:10 +02:00
{
u32 monId = GetPartyPositionOfRegisteredMon(&sUnionRoomTrade, GetMultiplayerId());
2018-06-03 22:39:10 +02:00
switch (gTasks[taskId].data[0])
{
case 0:
gTasks[taskId].data[0]++;
SendBlock(0, &gPlayerParty[monId], sizeof(struct Pokemon));
break;
case 1:
if (GetBlockReceivedStatus() == 3)
{
gEnemyParty[0] = *(struct Pokemon*)(gBlockRecvBuffer[GetMultiplayerId() ^ 1]);
2019-04-02 04:30:30 +02:00
IncrementGameStat(GAME_STAT_NUM_UNION_ROOM_BATTLES);
2018-06-03 22:39:10 +02:00
ResetBlockReceivedFlags();
gTasks[taskId].data[0]++;
}
break;
case 2:
memcpy(gBlockSendBuffer, gSaveBlock1Ptr->mail, sizeof(struct MailStruct) * PARTY_SIZE + 4);
if (SendBlock(0, gBlockSendBuffer, sizeof(struct MailStruct) * PARTY_SIZE + 4))
gTasks[taskId].data[0]++;
break;
case 3:
if (GetBlockReceivedStatus() == 3)
{
2019-10-04 13:42:45 +02:00
memcpy(gTradeMail, gBlockRecvBuffer[GetMultiplayerId() ^ 1], sizeof(struct MailStruct) * PARTY_SIZE);
2018-06-03 22:39:10 +02:00
ResetBlockReceivedFlags();
2019-10-04 01:39:37 +02:00
gSelectedTradeMonPositions[TRADE_PLAYER] = monId;
gSelectedTradeMonPositions[TRADE_PARTNER] = PARTY_SIZE;
2018-06-03 22:39:10 +02:00
gMain.savedCallback = CB2_ReturnToField;
2019-10-05 16:41:37 +02:00
SetMainCallback2(CB2_LinkTrade);
ResetUnionRoomTrade(&sUnionRoomTrade);
2018-06-03 22:39:10 +02:00
DestroyTask(taskId);
}
break;
}
}
2020-05-30 10:09:21 +02:00
static void Task_ExchangeCards(u8 taskId)
2018-06-03 22:39:10 +02:00
{
switch (gTasks[taskId].data[0])
{
case 0:
if (GetMultiplayerId() == 0)
sub_800A4D8(2);
gTasks[taskId].data[0]++;
break;
case 1:
if (GetBlockReceivedStatus() == sub_800A9D8())
{
s32 i;
u16 *recvBuff;
for (i = 0; i < GetLinkPlayerCount(); i++)
{
recvBuff = gBlockRecvBuffer[i];
2019-01-20 18:24:35 +01:00
CopyTrainerCardData(&gTrainerCards[i], recvBuff, gLinkPlayers[i].version);
2018-06-03 22:39:10 +02:00
}
if (GetLinkPlayerCount() == 2)
{
recvBuff = gBlockRecvBuffer[GetMultiplayerId() ^ 1];
2020-05-30 10:09:21 +02:00
MEventHandleReceivedWonderCard(recvBuff[48]);
2018-06-03 22:39:10 +02:00
}
else
{
2020-05-30 10:09:21 +02:00
ResetReceivedWonderCardFlag();
2018-06-03 22:39:10 +02:00
}
ResetBlockReceivedFlags();
DestroyTask(taskId);
}
break;
}
}
2020-05-30 10:09:21 +02:00
static void CB2_ShowCard(void)
2018-06-03 22:39:10 +02:00
{
switch (gMain.state)
{
case 0:
2020-05-30 10:09:21 +02:00
CreateTask(Task_ExchangeCards, 5);
2018-06-03 22:39:10 +02:00
gMain.state++;
break;
case 1:
2020-05-30 10:09:21 +02:00
if (!FuncIsActiveTask(Task_ExchangeCards))
2019-01-20 18:24:35 +01:00
ShowTrainerCardInLink(GetMultiplayerId() ^ 1, CB2_ReturnToField);
2018-06-03 22:39:10 +02:00
break;
}
RunTasks();
RunTextPrinters();
AnimateSprites();
BuildOamBuffer();
}
2020-05-30 10:09:21 +02:00
void StartUnionRoomBattle(u16 battleFlags)
2018-06-03 22:39:10 +02:00
{
HealPlayerParty();
SavePlayerParty();
LoadPlayerBag();
2019-10-11 10:14:09 +02:00
gLinkPlayers[0].linkType = LINKTYPE_BATTLE;
2018-06-04 12:07:32 +02:00
gLinkPlayers[GetMultiplayerId()].id = GetMultiplayerId();
gLinkPlayers[GetMultiplayerId() ^ 1].id = GetMultiplayerId() ^ 1;
2020-05-30 10:09:21 +02:00
gMain.savedCallback = CB2_ReturnFromCableClubBattle;
2018-06-03 22:39:10 +02:00
gBattleTypeFlags = battleFlags;
PlayBattleBGM();
}
2020-05-30 10:09:21 +02:00
// TODO: pokefirered bad name
2019-10-11 10:14:09 +02:00
static void sub_8014290(u16 linkService, u16 x, u16 y)
2018-06-03 22:39:10 +02:00
{
2019-10-11 10:14:09 +02:00
VarSet(VAR_CABLE_CLUB_STATE, linkService);
2018-12-27 23:30:47 +01:00
SetWarpDestination(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1, x, y);
SetDynamicWarpWithCoords(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1, x, y);
WarpIntoMap();
2018-06-03 22:39:10 +02:00
}
2020-05-30 10:09:21 +02:00
// TODO: pokefirered bad name
static void sub_8014304(s8 mapGroup, s8 mapNum, s32 x, s32 y, u16 linkService)
2018-06-03 22:39:10 +02:00
{
2019-10-11 10:14:09 +02:00
gSpecialVar_0x8004 = linkService;
VarSet(VAR_CABLE_CLUB_STATE, linkService);
2018-06-03 22:39:10 +02:00
gFieldLinkPlayerCount = GetLinkPlayerCount();
2019-02-27 04:04:44 +01:00
gLocalLinkPlayerId = GetMultiplayerId();
2018-10-17 04:47:08 +02:00
SetCableClubWarp();
2018-12-27 23:30:47 +01:00
SetWarpDestination(mapGroup, mapNum, -1, x, y);
WarpIntoMap();
2018-06-03 22:39:10 +02:00
}
2018-06-04 12:07:32 +02:00
2020-05-30 10:09:21 +02:00
static void CB2_TransitionToCableClub(void)
2018-06-04 12:07:32 +02:00
{
switch (gMain.state)
{
case 0:
2020-05-30 10:09:21 +02:00
CreateTask(Task_ExchangeCards, 5);
2018-06-04 12:07:32 +02:00
gMain.state++;
break;
case 1:
2020-05-30 10:09:21 +02:00
if (!FuncIsActiveTask(Task_ExchangeCards))
2019-12-17 09:24:44 +01:00
SetMainCallback2(CB2_ReturnToFieldCableClub);
2018-06-04 12:07:32 +02:00
break;
}
RunTasks();
RunTextPrinters();
AnimateSprites();
BuildOamBuffer();
}
2020-05-30 10:09:21 +02:00
static void CreateTrainerCardInBuffer(void *dest, bool32 setWonderCard)
2018-06-04 12:07:32 +02:00
{
2020-05-30 10:09:21 +02:00
u16 *argAsU16Ptr = dest;
2018-06-04 12:07:32 +02:00
2018-10-13 19:41:10 +02:00
TrainerCard_GenerateCardForPlayer((struct TrainerCard *)argAsU16Ptr);
2020-05-30 10:09:21 +02:00
if (setWonderCard)
2019-04-01 00:59:52 +02:00
argAsU16Ptr[48] = GetWonderCardFlagID();
2018-06-04 12:07:32 +02:00
else
argAsU16Ptr[48] = 0;
}
2020-05-30 10:09:21 +02:00
static void Task_StartActivity(u8 taskId)
2018-06-04 12:07:32 +02:00
{
2020-05-30 10:09:21 +02:00
ResetReceivedWonderCardFlag();
switch (gPlayerCurrActivity)
2018-06-04 12:07:32 +02:00
{
2020-05-30 10:09:21 +02:00
case ACTIVITY_BATTLE_SINGLE:
case ACTIVITY_BATTLE_DOUBLE:
case ACTIVITY_BATTLE_MULTI:
case ACTIVITY_TRADE:
case ACTIVITY_POKEMON_JUMP:
case ACTIVITY_BERRY_CRUSH:
case ACTIVITY_BERRY_PICK:
case ACTIVITY_SPIN_TRADE:
case ACTIVITY_RECORD_CORNER:
RecordMixTrainerNames();
2018-06-04 12:07:32 +02:00
break;
}
2020-05-30 10:09:21 +02:00
switch (gPlayerCurrActivity)
2018-06-04 12:07:32 +02:00
{
2020-05-30 10:09:21 +02:00
case ACTIVITY_BATTLE_SINGLE | IN_UNION_ROOM:
case ACTIVITY_ACCEPT | IN_UNION_ROOM:
2018-12-27 23:30:47 +01:00
CleanupOverworldWindowsAndTilemaps();
2020-05-30 10:09:21 +02:00
gMain.savedCallback = CB2_UnionRoomBattle;
InitChooseHalfPartyForBattle(3);
2018-06-04 12:07:32 +02:00
break;
2020-05-30 10:09:21 +02:00
case ACTIVITY_BATTLE_SINGLE:
2018-12-27 23:30:47 +01:00
CleanupOverworldWindowsAndTilemaps();
2020-05-30 10:09:21 +02:00
CreateTrainerCardInBuffer(gBlockSendBuffer, TRUE);
2018-06-04 12:07:32 +02:00
HealPlayerParty();
SavePlayerParty();
LoadPlayerBag();
2019-11-07 18:37:11 +01:00
sub_8014304(MAP_GROUP(BATTLE_COLOSSEUM_2P), MAP_NUM(BATTLE_COLOSSEUM_2P), 6, 8, USING_SINGLE_BATTLE);
2020-05-30 10:09:21 +02:00
SetMainCallback2(CB2_TransitionToCableClub);
2018-06-04 12:07:32 +02:00
break;
2020-05-30 10:09:21 +02:00
case ACTIVITY_BATTLE_DOUBLE:
2018-12-27 23:30:47 +01:00
CleanupOverworldWindowsAndTilemaps();
2018-06-04 12:07:32 +02:00
HealPlayerParty();
SavePlayerParty();
LoadPlayerBag();
2020-05-30 10:09:21 +02:00
CreateTrainerCardInBuffer(gBlockSendBuffer, TRUE);
2019-11-07 18:37:11 +01:00
sub_8014304(MAP_GROUP(BATTLE_COLOSSEUM_2P), MAP_NUM(BATTLE_COLOSSEUM_2P), 6, 8, USING_DOUBLE_BATTLE);
2020-05-30 10:09:21 +02:00
SetMainCallback2(CB2_TransitionToCableClub);
2018-06-04 12:07:32 +02:00
break;
2020-05-30 10:09:21 +02:00
case ACTIVITY_BATTLE_MULTI:
2018-12-27 23:30:47 +01:00
CleanupOverworldWindowsAndTilemaps();
2018-06-04 12:07:32 +02:00
HealPlayerParty();
SavePlayerParty();
LoadPlayerBag();
2020-05-30 10:09:21 +02:00
CreateTrainerCardInBuffer(gBlockSendBuffer, TRUE);
2019-11-07 18:37:11 +01:00
sub_8014304(MAP_GROUP(BATTLE_COLOSSEUM_4P), MAP_NUM(BATTLE_COLOSSEUM_4P), 5, 8, USING_MULTI_BATTLE);
2020-05-30 10:09:21 +02:00
SetMainCallback2(CB2_TransitionToCableClub);
2018-06-04 12:07:32 +02:00
break;
2020-05-30 10:09:21 +02:00
case ACTIVITY_TRADE:
CreateTrainerCardInBuffer(gBlockSendBuffer, TRUE);
2018-12-27 23:30:47 +01:00
CleanupOverworldWindowsAndTilemaps();
2019-10-11 10:14:09 +02:00
sub_8014304(MAP_GROUP(TRADE_CENTER), MAP_NUM(TRADE_CENTER), 5, 8, USING_TRADE_CENTER);
2020-05-30 10:09:21 +02:00
SetMainCallback2(CB2_TransitionToCableClub);
2018-06-04 12:07:32 +02:00
break;
2020-05-30 10:09:21 +02:00
case ACTIVITY_RECORD_CORNER:
CreateTrainerCardInBuffer(gBlockSendBuffer, TRUE);
2018-12-27 23:30:47 +01:00
CleanupOverworldWindowsAndTilemaps();
2019-10-11 10:14:09 +02:00
sub_8014304(MAP_GROUP(RECORD_CORNER), MAP_NUM(RECORD_CORNER), 8, 9, USING_RECORD_CORNER);
2020-05-30 10:09:21 +02:00
SetMainCallback2(CB2_TransitionToCableClub);
2018-06-04 12:07:32 +02:00
break;
2020-05-30 10:09:21 +02:00
case ACTIVITY_TRADE | IN_UNION_ROOM:
2018-12-27 23:30:47 +01:00
CleanupOverworldWindowsAndTilemaps();
2020-05-30 10:09:21 +02:00
CreateTask(Task_StartUnionRoomTrade, 0);
2018-06-04 12:07:32 +02:00
break;
2020-05-30 10:09:21 +02:00
case ACTIVITY_CHAT:
case ACTIVITY_CHAT | IN_UNION_ROOM:
2018-06-04 12:07:32 +02:00
if (GetMultiplayerId() == 0)
{
2020-05-30 10:09:21 +02:00
LinkRfu_CreateConnectionAsParent();
2018-06-04 12:07:32 +02:00
}
else
{
2020-05-30 10:09:21 +02:00
LinkRfu_StopManagerBeforeEnteringChat();
SetHostRFUtgtGname(69, 0, 1);
2018-06-04 12:07:32 +02:00
}
2020-05-30 10:09:21 +02:00
EnterUnionRoomChat();
2018-06-04 12:07:32 +02:00
break;
2020-05-30 10:09:21 +02:00
case ACTIVITY_CARD:
case ACTIVITY_CARD | IN_UNION_ROOM:
CreateTrainerCardInBuffer(gBlockSendBuffer, FALSE);
SetMainCallback2(CB2_ShowCard);
2018-06-04 12:07:32 +02:00
break;
2020-05-30 10:09:21 +02:00
case ACTIVITY_POKEMON_JUMP:
2019-10-11 10:14:09 +02:00
sub_8014290(USING_MINIGAME, 5, 1);
2020-05-30 10:09:21 +02:00
StartPokemonJump(GetCursorSelectionMonId(), CB2_LoadMap);
2018-06-04 12:07:32 +02:00
break;
2020-05-30 10:09:21 +02:00
case ACTIVITY_BERRY_CRUSH:
2019-10-11 10:14:09 +02:00
sub_8014290(USING_BERRY_CRUSH, 9, 1);
2020-05-30 10:09:21 +02:00
StartBerryCrush(CB2_LoadMap);
2018-06-04 12:07:32 +02:00
break;
2020-05-30 10:09:21 +02:00
case ACTIVITY_BERRY_PICK:
2019-10-11 10:14:09 +02:00
sub_8014290(USING_MINIGAME, 5, 1);
2020-05-30 10:09:21 +02:00
StartDodrioBerryPicking(GetCursorSelectionMonId(), CB2_LoadMap);
2018-06-04 12:07:32 +02:00
break;
}
DestroyTask(taskId);
gSpecialVar_Result = 1;
2020-05-30 10:09:21 +02:00
if (gPlayerCurrActivity != (ACTIVITY_TRADE | IN_UNION_ROOM))
2018-06-04 12:07:32 +02:00
ScriptContext2_Disable();
}
2020-05-30 10:09:21 +02:00
static void Task_RunScriptAndFadeToActivity(u8 taskId)
2018-06-04 12:07:32 +02:00
{
s16 *data = gTasks[taskId].data;
u16 *sendBuff = (u16*)(gBlockSendBuffer);
switch (data[0])
{
case 0:
2020-06-04 00:00:53 +02:00
gSpecialVar_Result = LINKUP_SUCCESS;
2020-05-30 10:09:21 +02:00
switch (gPlayerCurrActivity)
2018-06-04 12:07:32 +02:00
{
2020-05-30 10:09:21 +02:00
case ACTIVITY_BATTLE_TOWER:
case ACTIVITY_BATTLE_TOWER_OPEN:
2019-10-11 10:14:09 +02:00
gLinkPlayers[0].linkType = LINKTYPE_BATTLE;
2018-06-04 12:07:32 +02:00
gLinkPlayers[0].id = 0;
gLinkPlayers[1].id = 2;
2018-11-25 22:50:54 +01:00
sendBuff[0] = GetMonData(&gPlayerParty[gSelectedOrderFromParty[0] - 1], MON_DATA_SPECIES);
sendBuff[1] = GetMonData(&gPlayerParty[gSelectedOrderFromParty[1] - 1], MON_DATA_SPECIES, NULL);
2018-06-04 12:07:32 +02:00
gMain.savedCallback = NULL;
data[0] = 4;
RecordMixTrainerNames();
2018-06-04 12:07:32 +02:00
ResetBlockReceivedFlags();
break;
2020-05-30 10:09:21 +02:00
case ACTIVITY_BERRY_BLENDER:
case ACTIVITY_CONTEST_COOL:
case ACTIVITY_CONTEST_BEAUTY:
case ACTIVITY_CONTEST_CUTE:
case ACTIVITY_CONTEST_SMART:
case ACTIVITY_CONTEST_TOUGH:
RecordMixTrainerNames();
2018-06-04 12:07:32 +02:00
DestroyTask(taskId);
default:
EnableBothScriptContexts();
data[0] = 1;
break;
}
break;
case 1:
if (!ScriptContext1_IsScriptSetUp())
{
2019-12-15 17:42:50 +01:00
FadeScreen(FADE_TO_BLACK, 0);
2018-06-04 12:07:32 +02:00
data[0] = 2;
}
break;
case 2:
if (!gPaletteFade.active)
{
2020-05-30 10:09:21 +02:00
if (gPlayerCurrActivity == 29)
2018-06-04 12:07:32 +02:00
{
DestroyTask(taskId);
2019-10-09 11:56:44 +02:00
SetMainCallback2(CB2_StartCreateTradeMenu);
2018-06-04 12:07:32 +02:00
}
else
{
sub_800ADF8();
data[0] = 3;
}
}
break;
case 3:
2018-12-31 09:22:21 +01:00
if (IsLinkTaskFinished())
2018-06-04 12:07:32 +02:00
{
DestroyTask(taskId);
2020-05-30 10:09:21 +02:00
CreateTask_StartActivity();
2018-06-04 12:07:32 +02:00
}
break;
case 4:
if (SendBlock(0, gBlockSendBuffer, 0xE))
data[0] = 5;
break;
case 5:
if (GetBlockReceivedStatus() == 3)
{
ResetBlockReceivedFlags();
2020-06-04 00:00:53 +02:00
if (AreBattleTowerLinkSpeciesSame(gBlockRecvBuffer[0], gBlockRecvBuffer[1]))
2018-06-04 12:07:32 +02:00
{
2020-06-04 00:00:53 +02:00
gSpecialVar_Result = LINKUP_FAILED_BATTLE_TOWER;
2018-06-04 12:07:32 +02:00
data[0] = 7;
}
else
{
data[0] = 6;
}
}
break;
case 6:
EnableBothScriptContexts();
DestroyTask(taskId);
break;
case 7:
sub_800AC34();
data[0] = 8;
break;
case 8:
if (gReceivedRemoteLinkPlayers == 0)
{
2019-04-01 00:59:52 +02:00
DestroyWirelessStatusIndicatorSprite();
2018-06-04 12:07:32 +02:00
EnableBothScriptContexts();
DestroyTask(taskId);
}
break;
}
}
2020-05-30 10:09:21 +02:00
static void CreateTask_RunScriptAndFadeToActivity(void)
2018-06-04 12:07:32 +02:00
{
2020-05-30 10:09:21 +02:00
CreateTask(Task_RunScriptAndFadeToActivity, 0);
2018-06-04 12:07:32 +02:00
}
2020-05-30 10:09:21 +02:00
static void CreateTask_StartActivity(void)
2018-06-04 12:07:32 +02:00
{
2020-05-30 10:09:21 +02:00
u8 taskId = CreateTask(Task_StartActivity, 0);
2018-06-04 12:07:32 +02:00
gTasks[taskId].data[0] = 0;
}
2020-05-30 10:09:21 +02:00
void MEvent_CreateTask_Leader(u32 activity)
2018-06-04 12:07:32 +02:00
{
u8 taskId;
2020-05-30 10:09:21 +02:00
struct WirelessLink_Leader *data;
2018-06-04 12:07:32 +02:00
2020-05-30 10:09:21 +02:00
taskId = CreateTask(Task_MEvent_Leader, 0);
sWirelessLinkMain.leader = data = (void*)(gTasks[taskId].data);
2018-06-04 12:07:32 +02:00
2020-05-30 10:09:21 +02:00
data->state = 0;
data->textState = 0;
data->activity = activity;
2018-06-04 12:07:32 +02:00
gSpecialVar_Result = 0;
}
2020-05-30 10:09:21 +02:00
static void Task_MEvent_Leader(u8 taskId)
2018-06-04 12:07:32 +02:00
{
2020-05-30 10:09:21 +02:00
struct WirelessLink_Leader *data = sWirelessLinkMain.leader;
2018-06-04 12:07:32 +02:00
struct WindowTemplate winTemplate;
s32 val;
switch (data->state)
{
case 0:
2020-05-30 10:09:21 +02:00
gPlayerCurrActivity = data->activity;
sPlayerActivityGroupSize = 2;
SetHostRFUtgtGname(data->activity, 0, 0);
SetGnameBufferWonderFlags(FALSE, FALSE);
SetWirelessCommType1();
2018-06-04 12:07:32 +02:00
OpenLink();
2020-05-30 10:09:21 +02:00
InitializeRfuLinkManager_LinkLeader(2);
2018-06-04 12:07:32 +02:00
data->state = 1;
break;
case 1:
2020-05-30 10:09:21 +02:00
data->field_4 = AllocZeroed(4 * sizeof(struct UnkStruct_x1C));
data->field_0 = AllocZeroed(5 * sizeof(struct UnkStruct_x20));
data->field_8 = AllocZeroed(5 * sizeof(struct UnkStruct_x20));
ClearUnkStruct_x1CArray(data->field_4, 4);
ClearUnkStruct_x20Array(data->field_0->arr, 5);
LinkRfu3_SetGnameUnameFromStaticBuffers(&data->field_0->arr[0].gname_uname.gname, data->field_0->arr[0].gname_uname.playerName);
2018-06-04 12:07:32 +02:00
data->field_0->arr[0].field_18 = 0;
2020-05-30 10:09:21 +02:00
data->field_0->arr[0].groupScheduledAnim = UNION_ROOM_SPAWN_IN;
2018-06-04 12:07:32 +02:00
data->field_0->arr[0].field_1A_1 = 0;
data->field_0->arr[0].field_1B = 0;
2020-05-30 10:09:21 +02:00
data->listenTaskId = CreateTask_ListenForPartnersWithCompatibleSerialNos(data->field_4, 0xFF);
2018-06-04 12:07:32 +02:00
winTemplate = gUnknown_082F011C;
2019-04-01 00:59:52 +02:00
winTemplate.baseBlock = GetMysteryGiftBaseBlock();
2018-06-04 12:07:32 +02:00
winTemplate.paletteNum = 0xC;
data->listWindowId = AddWindow(&winTemplate);
2019-04-01 00:59:52 +02:00
MG_DrawTextBorder(data->listWindowId);
2020-05-30 10:09:21 +02:00
gMultiuseListMenuTemplate = sListMenuTemplate_PossibleGroupMembers;
2018-06-04 12:07:32 +02:00
gMultiuseListMenuTemplate.windowId = data->listWindowId;
data->listTaskId = ListMenuInit(&gMultiuseListMenuTemplate, 0, 0);
CopyBgTilemapBufferToVram(0);
2020-05-30 10:09:21 +02:00
data->playerCount = 1;
2018-06-04 12:07:32 +02:00
data->state = 2;
break;
case 2:
2020-05-30 10:09:21 +02:00
StringCopy(gStringVar1, sLinkGroupActivityTexts[gPlayerCurrActivity]);
StringExpandPlaceholders_AwaitingCommFromAnother(gStringVar4, gPlayerCurrActivity);
2018-06-04 12:07:32 +02:00
data->state = 3;
break;
case 3:
2019-04-01 00:59:52 +02:00
AddTextPrinterToWindow1(gStringVar4);
2018-06-04 12:07:32 +02:00
data->state = 4;
break;
case 4:
2020-05-30 10:09:21 +02:00
Leader_SetStateIfMemberListChanged(data, 5, 6);
2018-06-04 12:07:32 +02:00
if (gMain.newKeys & B_BUTTON)
{
data->state = 13;
2019-04-01 00:59:52 +02:00
DestroyWirelessStatusIndicatorSprite();
2018-06-04 12:07:32 +02:00
}
break;
case 6:
2019-12-10 19:48:20 +01:00
if (MG_PrintTextOnWindow1AndWaitButton(&data->textState, sText_LinkWithFriendDropped))
2018-06-04 12:07:32 +02:00
{
2020-05-30 10:09:21 +02:00
data->playerCount = sub_8013398(data->field_0);
2018-07-22 13:14:58 +02:00
RedrawListMenu(data->listTaskId);
2018-06-04 12:07:32 +02:00
data->state = 2;
}
break;
case 5:
data->state = 7;
break;
case 7:
2019-04-01 00:59:52 +02:00
switch (mevent_message_print_and_prompt_yes_no(&data->textState, &data->field_14, 0, gStringVar4))
2018-06-04 12:07:32 +02:00
{
case 0:
2019-04-04 23:05:46 +02:00
LoadWirelessStatusIndicatorSpriteGfx();
2018-06-04 12:07:32 +02:00
CreateWirelessStatusIndicatorSprite(0, 0);
2020-05-30 10:09:21 +02:00
data->field_0->arr[data->playerCount].field_1B = 0;
2018-07-22 13:14:58 +02:00
RedrawListMenu(data->listTaskId);
2018-06-04 12:07:32 +02:00
data->field_19 = 5;
2020-05-30 10:09:21 +02:00
SendByteToPartnerByIdAndName(5, ReadAsU16(data->field_0->arr[data->playerCount].gname_uname.gname.unk_00.playerTrainerId), data->field_0->arr[data->playerCount].gname_uname.playerName);
2018-06-04 12:07:32 +02:00
data->state = 8;
break;
case 1:
case -1:
data->field_19 = 6;
2020-05-30 10:09:21 +02:00
SendByteToPartnerByIdAndName(6, ReadAsU16(data->field_0->arr[data->playerCount].gname_uname.gname.unk_00.playerTrainerId), data->field_0->arr[data->playerCount].gname_uname.playerName);
2018-06-04 12:07:32 +02:00
data->state = 8;
break;
}
break;
case 8:
2020-05-30 10:09:21 +02:00
val = WaitSendByteToPartnerByIdAndName(ReadAsU16(data->field_0->arr[data->playerCount].gname_uname.gname.unk_00.playerTrainerId), data->field_0->arr[data->playerCount].gname_uname.playerName);
2018-06-04 12:07:32 +02:00
if (val == 1)
{
if (data->field_19 == 5)
{
2020-05-30 10:09:21 +02:00
data->field_0->arr[data->playerCount].field_1B = 0;
2018-07-22 13:14:58 +02:00
RedrawListMenu(data->listTaskId);
2020-05-30 10:09:21 +02:00
data->playerCount++;
IntlConvPartnerUname7(gStringVar1, &data->field_0->arr[data->playerCount - 1]);
2019-12-10 19:48:20 +01:00
StringExpandPlaceholders(gStringVar4, sText_AnOKWasSentToPlayer);
2018-06-04 12:07:32 +02:00
data->state = 9;
2020-05-30 10:09:21 +02:00
LinkRfu_StopManagerAndFinalizeSlots();
2018-06-04 12:07:32 +02:00
}
else
{
2020-05-30 10:09:21 +02:00
RequestDisconnectSlotByTrainerNameAndId(data->field_0->arr[data->playerCount].gname_uname.playerName, ReadAsU16(data->field_0->arr[data->playerCount].gname_uname.gname.unk_00.playerTrainerId));
data->field_0->arr[data->playerCount].groupScheduledAnim = UNION_ROOM_SPAWN_NONE;
2018-06-04 12:07:32 +02:00
sub_8013398(data->field_0);
2018-07-22 13:14:58 +02:00
RedrawListMenu(data->listTaskId);
2018-06-04 12:07:32 +02:00
data->state = 2;
}
data->field_19 = 0;
}
else if (val == 2)
{
2020-05-30 10:09:21 +02:00
RfuSetErrorStatus(0, 0);
2018-06-04 12:07:32 +02:00
data->state = 2;
}
break;
case 9:
2019-04-01 00:59:52 +02:00
AddTextPrinterToWindow1(gStringVar4);
2018-06-04 12:07:32 +02:00
data->state = 10;
break;
case 10:
2020-05-30 10:09:21 +02:00
if (++data->delayTimerAfterOk > 120)
2018-06-04 12:07:32 +02:00
data->state = 11;
break;
case 11:
2020-05-30 10:09:21 +02:00
if (!Leader_SetStateIfMemberListChanged(data, 5, 6))
2018-06-04 12:07:32 +02:00
data->state = 12;
break;
case 12:
2020-05-30 10:09:21 +02:00
if (LmanAcceptSlotFlagIsNotZero())
2018-06-04 12:07:32 +02:00
{
2020-05-30 10:09:21 +02:00
WaitRfuState(FALSE);
2018-06-04 12:07:32 +02:00
data->state = 15;
}
else
{
data->state = 6;
}
break;
case 13:
2019-04-01 00:59:52 +02:00
DestroyWirelessStatusIndicatorSprite();
2020-05-30 10:09:21 +02:00
LinkRfu_Shutdown();
2018-06-04 12:07:32 +02:00
DestroyListMenuTask(data->listTaskId, 0, 0);
CopyBgTilemapBufferToVram(0);
RemoveWindow(data->listWindowId);
2020-05-30 10:09:21 +02:00
DestroyTask(data->listenTaskId);
2018-06-04 12:07:32 +02:00
Free(data->field_8);
Free(data->field_0);
Free(data->field_4);
data->state++;
break;
case 14:
2019-12-10 19:48:20 +01:00
if (MG_PrintTextOnWindow1AndWaitButton(&data->textState, sText_PleaseStartOver))
2018-06-04 12:07:32 +02:00
{
DestroyTask(taskId);
gSpecialVar_Result = 5;
}
break;
case 15:
2020-05-30 10:09:21 +02:00
if (RfuGetErrorStatus() == 1 || RfuGetErrorStatus() == 2)
2018-06-04 12:07:32 +02:00
{
data->state = 13;
}
else if (gReceivedRemoteLinkPlayers != 0)
{
2020-05-30 10:09:21 +02:00
UpdateGameData_GroupLockedIn(TRUE);
2018-06-04 12:07:32 +02:00
data->state++;
}
break;
case 16:
DestroyListMenuTask(data->listTaskId, 0, 0);
CopyBgTilemapBufferToVram(0);
RemoveWindow(data->listWindowId);
2020-05-30 10:09:21 +02:00
DestroyTask(data->listenTaskId);
2018-06-04 12:07:32 +02:00
Free(data->field_8);
Free(data->field_0);
Free(data->field_4);
sub_800ADF8();
data->state++;
break;
case 17:
2018-12-31 09:22:21 +01:00
if (IsLinkTaskFinished())
2018-06-04 12:07:32 +02:00
DestroyTask(taskId);
break;
}
}
2020-05-30 10:09:21 +02:00
void MEvent_CreateTask_CardOrNewsWithFriend(u32 activity)
2018-06-04 12:07:32 +02:00
{
u8 taskId;
2020-05-30 10:09:21 +02:00
struct WirelessLink_Group *data;
2018-06-04 12:07:32 +02:00
2020-05-30 10:09:21 +02:00
taskId = CreateTask(Task_CardOrNewsWithFriend, 0);
sWirelessLinkMain.group = data = (void*)(gTasks[taskId].data);
sGroup = data;
2018-06-04 12:07:32 +02:00
2020-05-30 10:09:21 +02:00
data->state = 0;
data->textState = 0;
data->isWonderNews = activity - ACTIVITY_WONDER_CARD2;
2018-06-04 12:07:32 +02:00
gSpecialVar_Result = 0;
}
2018-06-04 23:32:28 +02:00
2020-05-30 10:09:21 +02:00
static void Task_CardOrNewsWithFriend(u8 taskId)
2018-06-04 23:32:28 +02:00
{
s32 id;
struct WindowTemplate winTemplate1, winTemplate2;
2020-05-30 10:09:21 +02:00
struct WirelessLink_Group *data = sWirelessLinkMain.group;
2018-06-04 23:32:28 +02:00
switch (data->state)
{
case 0:
2020-05-30 10:09:21 +02:00
SetHostRFUtgtGname(data->isWonderNews + ACTIVITY_WONDER_CARD2, 0, 0);
SetWirelessCommType1();
2018-06-04 23:32:28 +02:00
OpenLink();
2020-05-30 10:09:21 +02:00
InitializeRfuLinkManager_JoinGroup();
data->field_4 = AllocZeroed(4 * sizeof(struct UnkStruct_x1C));
data->field_0 = AllocZeroed(16 * sizeof(struct UnkStruct_x20));
2018-06-04 23:32:28 +02:00
data->state = 1;
break;
case 1:
2019-11-11 03:54:00 +01:00
AddTextPrinterToWindow1(sText_ChooseTrainer);
2018-06-04 23:32:28 +02:00
data->state = 2;
break;
case 2:
2020-05-30 10:09:21 +02:00
ClearUnkStruct_x1CArray(data->field_4, 4);
ClearUnkStruct_x20Array(data->field_0->arr, 16);
data->listenTaskId = CreateTask_ListenForPartnersWithCompatibleSerialNos(data->field_4, data->isWonderNews + LINK_GROUP_WONDER_CARD);
2018-06-04 23:32:28 +02:00
winTemplate1 = gUnknown_082F0174;
2019-04-01 00:59:52 +02:00
winTemplate1.baseBlock = GetMysteryGiftBaseBlock();
2018-06-04 23:32:28 +02:00
winTemplate1.paletteNum = 0xC;
data->listWindowId = AddWindow(&winTemplate1);
winTemplate2 = gUnknown_082F017C;
winTemplate2.paletteNum = 0xC;
2020-05-30 10:09:21 +02:00
data->playerNameAndIdWindowId = AddWindow(&winTemplate2);
2018-06-04 23:32:28 +02:00
2019-04-01 00:59:52 +02:00
MG_DrawTextBorder(data->listWindowId);
2020-05-30 10:09:21 +02:00
gMultiuseListMenuTemplate = sListMenuTemplate_UnionRoomGroups;
2018-06-04 23:32:28 +02:00
gMultiuseListMenuTemplate.windowId = data->listWindowId;
data->listTaskId = ListMenuInit(&gMultiuseListMenuTemplate, 0, 0);
2020-05-30 10:09:21 +02:00
MG_DrawTextBorder(data->playerNameAndIdWindowId);
FillWindowPixelBuffer(data->playerNameAndIdWindowId, PIXEL_FILL(1));
PutWindowTilemap(data->playerNameAndIdWindowId);
PrintPlayerNameAndIdOnWindow(data->playerNameAndIdWindowId);
CopyWindowToVram(data->playerNameAndIdWindowId, 2);
2018-06-04 23:32:28 +02:00
CopyBgTilemapBufferToVram(0);
2020-05-30 10:09:21 +02:00
data->leaderId = 0;
2018-06-04 23:32:28 +02:00
data->state = 3;
break;
case 3:
2020-05-30 10:09:21 +02:00
id = GetNewLeaderCandidate();
2018-06-04 23:32:28 +02:00
switch (id)
{
case 1:
PlaySE(SE_PC_LOGIN);
default:
2018-07-22 13:14:58 +02:00
RedrawListMenu(data->listTaskId);
2018-06-04 23:32:28 +02:00
break;
case 0:
2019-02-02 11:04:38 +01:00
id = ListMenu_ProcessInput(data->listTaskId);
2018-06-04 23:32:28 +02:00
if (gMain.newKeys & A_BUTTON && id != -1)
{
// this unused variable along with the assignment is needed to match
u32 unusedVar;
2020-05-30 10:09:21 +02:00
unusedVar = data->field_0->arr[id].gname_uname.gname.activity;
2018-06-04 23:32:28 +02:00
2020-05-30 10:09:21 +02:00
if (data->field_0->arr[id].groupScheduledAnim == UNION_ROOM_SPAWN_IN && !data->field_0->arr[id].gname_uname.gname.started)
2018-06-04 23:32:28 +02:00
{
2020-05-30 10:09:21 +02:00
data->leaderId = id;
2019-04-04 23:05:46 +02:00
LoadWirelessStatusIndicatorSpriteGfx();
2018-06-04 23:32:28 +02:00
CreateWirelessStatusIndicatorSprite(0, 0);
2018-07-22 13:14:58 +02:00
RedrawListMenu(data->listTaskId);
2020-05-30 10:09:21 +02:00
IntlConvPartnerUname7(gStringVar1, &data->field_0->arr[data->leaderId]);
CreateTask_RfuReconnectWithParent(data->field_0->arr[data->leaderId].gname_uname.playerName, ReadAsU16(data->field_0->arr[data->leaderId].gname_uname.gname.unk_00.playerTrainerId));
2018-06-04 23:32:28 +02:00
PlaySE(SE_PN_ON);
data->state = 4;
}
else
{
PlaySE(SE_WALL_HIT);
}
}
else if (gMain.newKeys & B_BUTTON)
{
data->state = 6;
}
break;
}
break;
case 4:
2019-12-10 19:48:20 +01:00
AddTextPrinterToWindow1(sText_AwaitingPlayersResponse);
2020-05-30 10:09:21 +02:00
IntlConvPartnerUname7(gStringVar1, &data->field_0->arr[data->leaderId]);
2018-06-04 23:32:28 +02:00
data->state = 5;
break;
case 5:
2020-05-30 10:09:21 +02:00
if (gReceivedRemoteLinkPlayers)
2018-06-04 23:32:28 +02:00
{
2020-05-30 10:09:21 +02:00
gPlayerCurrActivity = data->field_0->arr[data->leaderId].gname_uname.gname.activity;
2018-06-04 23:32:28 +02:00
data->state = 10;
}
2020-05-30 10:09:21 +02:00
switch (RfuGetErrorStatus())
2018-06-04 23:32:28 +02:00
{
case 1:
case 2:
case 6:
data->state = 8;
break;
case 5:
2019-12-10 19:48:20 +01:00
AddTextPrinterToWindow1(sText_PlayerSentBackOK);
2020-05-30 10:09:21 +02:00
RfuSetErrorStatus(0, 0);
2018-06-04 23:32:28 +02:00
break;
}
break;
case 6:
case 8:
case 10:
DestroyListMenuTask(data->listTaskId, 0, 0);
CopyBgTilemapBufferToVram(0);
2020-05-30 10:09:21 +02:00
RemoveWindow(data->playerNameAndIdWindowId);
2018-06-04 23:32:28 +02:00
RemoveWindow(data->listWindowId);
2020-05-30 10:09:21 +02:00
DestroyTask(data->listenTaskId);
2018-06-04 23:32:28 +02:00
Free(data->field_0);
Free(data->field_4);
data->state++;
break;
case 9:
2020-05-30 10:09:21 +02:00
if (MG_PrintTextOnWindow1AndWaitButton(&data->textState, sLinkDroppedTexts[RfuGetErrorStatus()]))
2018-06-04 23:32:28 +02:00
{
2019-04-01 00:59:52 +02:00
DestroyWirelessStatusIndicatorSprite();
2018-06-04 23:32:28 +02:00
DestroyTask(taskId);
2020-05-30 10:09:21 +02:00
LinkRfu_Shutdown();
2018-06-04 23:32:28 +02:00
gSpecialVar_Result = 5;
}
break;
case 7:
2019-04-01 00:59:52 +02:00
DestroyWirelessStatusIndicatorSprite();
2019-12-10 19:48:20 +01:00
AddTextPrinterToWindow1(sText_PleaseStartOver);
2018-06-04 23:32:28 +02:00
DestroyTask(taskId);
2020-05-30 10:09:21 +02:00
LinkRfu_Shutdown();
2018-06-04 23:32:28 +02:00
gSpecialVar_Result = 5;
break;
case 11:
data->state++;
sub_800ADF8();
break;
case 12:
2018-12-31 09:22:21 +01:00
if (IsLinkTaskFinished())
2018-06-04 23:32:28 +02:00
DestroyTask(taskId);
break;
}
}
2020-05-30 10:09:21 +02:00
void MEvent_CreateTask_CardOrNewsOverWireless(u32 activity)
2018-06-04 23:32:28 +02:00
{
u8 taskId;
2020-05-30 10:09:21 +02:00
struct WirelessLink_Group *data;
2018-06-04 23:32:28 +02:00
2020-05-30 10:09:21 +02:00
taskId = CreateTask(Task_CardOrNewsOverWireless, 0);
sWirelessLinkMain.group = data = (void*)(gTasks[taskId].data);
sGroup = data;
2018-06-04 23:32:28 +02:00
2020-05-30 10:09:21 +02:00
data->state = 0;
data->textState = 0;
data->isWonderNews = activity - ACTIVITY_WONDER_CARD2;
2018-06-04 23:32:28 +02:00
gSpecialVar_Result = 0;
}
2020-05-30 10:09:21 +02:00
static void Task_CardOrNewsOverWireless(u8 taskId)
2018-06-04 23:32:28 +02:00
{
s32 id;
struct WindowTemplate winTemplate;
2020-05-30 10:09:21 +02:00
struct WirelessLink_Group *data = sWirelessLinkMain.group;
2018-06-04 23:32:28 +02:00
switch (data->state)
{
case 0:
2020-05-30 10:09:21 +02:00
SetHostRFUtgtGname(0, 0, 0);
SetWirelessCommType1();
2018-06-04 23:32:28 +02:00
OpenLink();
2020-05-30 10:09:21 +02:00
InitializeRfuLinkManager_JoinGroup();
data->field_4 = AllocZeroed(4 * sizeof(struct UnkStruct_x1C));
data->field_0 = AllocZeroed(16 * sizeof(struct UnkStruct_x20));
2018-06-04 23:32:28 +02:00
data->state = 1;
break;
case 1:
2019-12-10 19:48:20 +01:00
AddTextPrinterToWindow1(sText_SearchingForWirelessSystemWait);
2018-06-04 23:32:28 +02:00
data->state = 2;
break;
case 2:
2020-05-30 10:09:21 +02:00
ClearUnkStruct_x1CArray(data->field_4, 4);
ClearUnkStruct_x20Array(data->field_0->arr, 16);
data->listenTaskId = CreateTask_ListenForPartnersWithSerial7F7D(data->field_4, data->isWonderNews + LINK_GROUP_WONDER_CARD);
2018-06-04 23:32:28 +02:00
if (data->field_13 != 0)
{
winTemplate = gUnknown_082F0174;
2019-04-01 00:59:52 +02:00
winTemplate.baseBlock = GetMysteryGiftBaseBlock();
2018-06-04 23:32:28 +02:00
data->listWindowId = AddWindow(&winTemplate);
2019-04-01 00:59:52 +02:00
MG_DrawTextBorder(data->listWindowId);
2020-05-30 10:09:21 +02:00
gMultiuseListMenuTemplate = sListMenuTemplate_UnionRoomGroups;
2018-06-04 23:32:28 +02:00
gMultiuseListMenuTemplate.windowId = data->listWindowId;
data->listTaskId = ListMenuInit(&gMultiuseListMenuTemplate, 0, 0);
CopyBgTilemapBufferToVram(0);
}
2020-05-30 10:09:21 +02:00
data->leaderId = 0;
2018-06-04 23:32:28 +02:00
data->state = 3;
break;
case 3:
2020-05-30 10:09:21 +02:00
id = GetNewLeaderCandidate();
2018-06-04 23:32:28 +02:00
switch (id)
{
case 1:
PlaySE(SE_PC_LOGIN);
default:
if (data->field_13 != 0)
2018-07-22 13:14:58 +02:00
RedrawListMenu(data->listTaskId);
2018-06-04 23:32:28 +02:00
break;
case 0:
if (data->field_13 != 0)
2019-02-02 11:04:38 +01:00
id = ListMenu_ProcessInput(data->listTaskId);
2020-05-30 10:09:21 +02:00
if (data->refreshTimer > 120)
2018-06-04 23:32:28 +02:00
{
2020-05-30 10:09:21 +02:00
if (data->field_0->arr[0].groupScheduledAnim == UNION_ROOM_SPAWN_IN && !data->field_0->arr[0].gname_uname.gname.started)
2018-06-04 23:32:28 +02:00
{
2020-06-01 16:23:12 +02:00
if (HasWonderCardOrNewsByLinkGroup(&data->field_0->arr[0].gname_uname.gname, data->isWonderNews + LINK_GROUP_WONDER_CARD))
2018-06-04 23:32:28 +02:00
{
2020-05-30 10:09:21 +02:00
data->leaderId = 0;
data->refreshTimer = 0;
2019-04-04 23:05:46 +02:00
LoadWirelessStatusIndicatorSpriteGfx();
2018-06-04 23:32:28 +02:00
CreateWirelessStatusIndicatorSprite(0, 0);
2020-05-30 10:09:21 +02:00
CreateTask_RfuReconnectWithParent(data->field_0->arr[0].gname_uname.playerName, ReadAsU16(data->field_0->arr[0].gname_uname.gname.unk_00.playerTrainerId));
2018-06-04 23:32:28 +02:00
PlaySE(SE_PN_ON);
data->state = 4;
}
else
{
PlaySE(SE_BOO);
data->state = 10;
}
}
}
else if (gMain.newKeys & B_BUTTON)
{
data->state = 6;
2020-05-30 10:09:21 +02:00
data->refreshTimer = 0;
2018-06-04 23:32:28 +02:00
}
2020-05-30 10:09:21 +02:00
data->refreshTimer++;
2018-06-04 23:32:28 +02:00
break;
}
break;
case 4:
2019-12-10 19:48:20 +01:00
AddTextPrinterToWindow1(sText_AwaitingResponseFromWirelessSystem);
2020-05-30 10:09:21 +02:00
IntlConvPartnerUname7(gStringVar1, &data->field_0->arr[data->leaderId]);
2018-06-04 23:32:28 +02:00
data->state = 5;
break;
case 5:
2020-05-30 10:09:21 +02:00
if (gReceivedRemoteLinkPlayers)
2018-06-04 23:32:28 +02:00
{
2020-05-30 10:09:21 +02:00
gPlayerCurrActivity = data->field_0->arr[data->leaderId].gname_uname.gname.activity;
2018-06-04 23:32:28 +02:00
data->state = 12;
}
2020-05-30 10:09:21 +02:00
switch (RfuGetErrorStatus())
2018-06-04 23:32:28 +02:00
{
case 1:
case 2:
case 6:
data->state = 8;
break;
case 5:
2019-12-10 19:48:20 +01:00
AddTextPrinterToWindow1(sText_WirelessLinkEstablished);
2020-05-30 10:09:21 +02:00
RfuSetErrorStatus(0, 0);
2018-06-04 23:32:28 +02:00
break;
}
break;
case 6:
case 8:
case 10:
case 12:
if (data->field_13 != 0)
{
DestroyListMenuTask(data->listTaskId, 0, 0);
CopyBgTilemapBufferToVram(0);
RemoveWindow(data->listWindowId);
}
2020-05-30 10:09:21 +02:00
DestroyTask(data->listenTaskId);
2018-06-04 23:32:28 +02:00
Free(data->field_0);
Free(data->field_4);
data->state++;
break;
case 9:
2019-12-10 19:48:20 +01:00
if (MG_PrintTextOnWindow1AndWaitButton(&data->textState, sText_WirelessLinkDropped))
2018-06-04 23:32:28 +02:00
{
2019-04-01 00:59:52 +02:00
DestroyWirelessStatusIndicatorSprite();
2018-06-04 23:32:28 +02:00
DestroyTask(taskId);
2020-05-30 10:09:21 +02:00
LinkRfu_Shutdown();
2018-06-04 23:32:28 +02:00
gSpecialVar_Result = 5;
}
break;
case 7:
2019-12-10 19:48:20 +01:00
if (MG_PrintTextOnWindow1AndWaitButton(&data->textState, sText_WirelessSearchCanceled))
2018-06-04 23:32:28 +02:00
{
2019-04-01 00:59:52 +02:00
DestroyWirelessStatusIndicatorSprite();
2018-06-04 23:32:28 +02:00
DestroyTask(taskId);
2020-05-30 10:09:21 +02:00
LinkRfu_Shutdown();
2018-06-04 23:32:28 +02:00
gSpecialVar_Result = 5;
}
break;
case 11:
2020-05-30 10:09:21 +02:00
if (MG_PrintTextOnWindow1AndWaitButton(&data->textState, sNoWonderSharedTexts[data->isWonderNews]))
2018-06-04 23:32:28 +02:00
{
2019-04-01 00:59:52 +02:00
DestroyWirelessStatusIndicatorSprite();
2018-06-04 23:32:28 +02:00
DestroyTask(taskId);
2020-05-30 10:09:21 +02:00
LinkRfu_Shutdown();
2018-06-04 23:32:28 +02:00
gSpecialVar_Result = 5;
}
break;
case 13:
data->state++;
sub_800ADF8();
break;
case 14:
2018-12-31 09:22:21 +01:00
if (IsLinkTaskFinished())
2018-06-04 23:32:28 +02:00
DestroyTask(taskId);
break;
}
}
void UnionRoomSpecial(void)
{
2020-05-30 10:09:21 +02:00
struct WirelessLink_URoom *data;
2018-06-04 23:32:28 +02:00
2020-05-30 10:09:21 +02:00
ClearAndInitHostRFUtgtGname();
CreateTask(Task_RunUnionRoom, 10);
2018-06-04 23:32:28 +02:00
// dumb line needed to match
2020-05-30 10:09:21 +02:00
sWirelessLinkMain.uRoom = sWirelessLinkMain.uRoom;
2018-06-04 23:32:28 +02:00
2020-05-30 10:09:21 +02:00
data = AllocZeroed(sizeof(*sWirelessLinkMain.uRoom));
sWirelessLinkMain.uRoom = data;
sURoom = data;
2018-06-04 23:32:28 +02:00
2020-05-30 10:09:21 +02:00
data->state = 0;
data->textState = 0;
data->field_10 = 0;
data->field_12 = 0;
2018-06-04 23:32:28 +02:00
gSpecialVar_Result = 0;
2020-05-30 10:09:21 +02:00
ListMenuLoadStdPalAt(0xD0, 1);
2018-06-04 23:32:28 +02:00
}
2020-05-30 10:09:21 +02:00
static u16 ReadAsU16(const u8 *ptr)
2018-06-04 23:32:28 +02:00
{
return (ptr[1] << 8) | (ptr[0]);
}
2020-05-30 10:09:21 +02:00
static void ScheduleFieldMessageWithFollowupState(u32 nextState, const u8 *src)
2018-06-04 23:32:28 +02:00
{
2020-05-30 10:09:21 +02:00
struct WirelessLink_URoom *data = sWirelessLinkMain.uRoom;
2018-06-04 23:32:28 +02:00
2018-06-09 22:14:52 +02:00
data->state = 8;
data->stateAfterPrint = nextState;
2018-06-04 23:32:28 +02:00
if (src != gStringVar4)
StringExpandPlaceholders(gStringVar4, src);
}
2020-05-30 10:09:21 +02:00
static void ScheduleFieldMessageAndExit(const u8 *src)
2018-06-04 23:32:28 +02:00
{
2020-05-30 10:09:21 +02:00
struct WirelessLink_URoom *data = sWirelessLinkMain.uRoom;
2018-06-04 23:32:28 +02:00
2018-06-09 22:14:52 +02:00
data->state = 26;
2018-06-04 23:32:28 +02:00
if (src != gStringVar4)
StringExpandPlaceholders(gStringVar4, src);
}
2020-05-30 10:09:21 +02:00
static void sub_80156B0(struct WirelessLink_URoom *data)
2018-06-04 23:32:28 +02:00
{
memcpy(&gDecompressionBuffer[0x3F00], data->field_0, 0x100);
}
2020-05-30 10:09:21 +02:00
static void sub_80156C8(struct WirelessLink_URoom *data)
2018-06-04 23:32:28 +02:00
{
memcpy(data->field_0, &gDecompressionBuffer[0x3F00], 0x100);
}
2018-06-09 22:14:52 +02:00
2020-05-30 10:09:21 +02:00
static void Task_RunUnionRoom(u8 taskId)
2018-06-09 22:14:52 +02:00
{
2018-06-10 18:28:37 +02:00
u32 id = 0;
s32 var5 = 0;
2020-05-30 10:09:21 +02:00
s32 playerGender = MALE;
struct WirelessLink_URoom *data = sWirelessLinkMain.uRoom;
2018-06-09 22:14:52 +02:00
s16 *taskData = gTasks[taskId].data;
switch (data->state)
{
case 0:
2020-05-30 10:09:21 +02:00
data->field_4 = AllocZeroed(RFU_CHILD_MAX * sizeof(struct UnkStruct_x1C));
data->field_C = AllocZeroed(RFU_CHILD_MAX * sizeof(struct UnkStruct_x1C));
data->field_0 = AllocZeroed(8 * sizeof(struct UnkStruct_x20));
data->field_8 = AllocZeroed(sizeof(struct UnkStruct_x20));
2020-06-01 16:23:12 +02:00
ClearUnkStruct_x20Array(data->field_0->arr, ARRAY_COUNT(data->field_0->arr));
2020-05-30 10:09:21 +02:00
gPlayerCurrActivity = IN_UNION_ROOM;
data->field_20 = CreateTask_SearchForChildOrParent(data->field_C, data->field_4, LINK_GROUP_UNION_ROOM_RESUME);
2020-06-01 16:23:12 +02:00
InitUnionRoomPlayerObjects(data->objects);
SetTilesAroundUnionRoomPlayersPassable();
2018-06-09 22:14:52 +02:00
data->state = 1;
break;
case 1:
2020-06-01 16:23:12 +02:00
CreateGroupMemberSpritesInvisible(data->spriteIds, taskData[0]);
2018-06-10 18:28:37 +02:00
if (++taskData[0] == 8)
2018-06-09 22:14:52 +02:00
data->state = 2;
break;
case 2:
2020-05-30 10:09:21 +02:00
SetHostRFUtgtGname(IN_UNION_ROOM, 0, 0);
sub_8010FCC(sUnionRoomTrade.type, sUnionRoomTrade.playerSpecies, sUnionRoomTrade.playerLevel);
2020-05-30 10:09:21 +02:00
SetWirelessCommType1();
2018-06-09 22:14:52 +02:00
OpenLink();
2020-05-30 10:09:21 +02:00
InitializeRfuLinkManager_EnterUnionRoom();
ClearUnkStruct_x20Array(&data->field_8->arr[0], 1);
ClearUnkStruct_x1CArray(data->field_4, 4);
ClearUnkStruct_x1CArray(data->field_C, 4);
2018-06-09 22:14:52 +02:00
gSpecialVar_Result = 0;
data->state = 3;
break;
case 3:
2019-10-18 01:22:03 +02:00
if ((GetPartyMenuType() == PARTY_MENU_TYPE_UNION_ROOM_REGISTER
2020-05-30 10:09:21 +02:00
|| GetPartyMenuType() == PARTY_MENU_TYPE_UNION_ROOM_TRADE)
2019-10-18 01:22:03 +02:00
&& sUnionRoomTrade.field_0 != 0)
2018-06-09 22:14:52 +02:00
{
2018-06-10 18:28:37 +02:00
id = GetCursorSelectionMonId();
switch (sUnionRoomTrade.field_0)
2018-06-09 22:14:52 +02:00
{
case 1:
2020-05-30 10:09:21 +02:00
UpdateGameDataWithActivitySpriteGendersFlag(ACTIVITY_PLYRTALK | IN_UNION_ROOM, 0, TRUE);
2018-06-10 18:28:37 +02:00
if (id >= PARTY_SIZE)
2018-06-09 22:14:52 +02:00
{
ResetUnionRoomTrade(&sUnionRoomTrade);
2018-06-09 22:14:52 +02:00
sub_8010FCC(0, 0, 0);
2020-05-30 10:09:21 +02:00
ScheduleFieldMessageAndExit(sText_RegistrationCanceled);
2018-06-09 22:14:52 +02:00
}
else if (!RegisterTradeMonAndGetIsEgg(GetCursorSelectionMonId(), &sUnionRoomTrade))
2018-06-09 22:14:52 +02:00
{
2020-05-30 10:09:21 +02:00
ScheduleFieldMessageWithFollowupState(52, sText_ChooseRequestedMonType);
2018-06-09 22:14:52 +02:00
}
else
{
data->state = 55;
}
break;
case 2:
sub_80156C8(data);
taskData[1] = sUnionRoomTrade.field_8;
2018-06-10 18:28:37 +02:00
if (id >= PARTY_SIZE)
2018-06-09 22:14:52 +02:00
{
2020-05-30 10:09:21 +02:00
ScheduleFieldMessageAndExit(sText_TradeCanceled);
2018-06-09 22:14:52 +02:00
}
else
{
2020-05-30 10:09:21 +02:00
UpdateGameDataWithActivitySpriteGendersFlag(ACTIVITY_PLYRTALK | IN_UNION_ROOM, 0, TRUE);
gPlayerCurrActivity = ACTIVITY_TRADE | IN_UNION_ROOM;
RegisterTradeMon(GetCursorSelectionMonId(), &sUnionRoomTrade);
2018-06-09 22:14:52 +02:00
data->state = 51;
}
break;
}
sUnionRoomTrade.field_0 = 0;
2018-06-09 22:14:52 +02:00
}
else
{
data->state = 4;
}
break;
case 4:
if (gSpecialVar_Result != 0)
{
if (gSpecialVar_Result == 9)
{
2020-05-30 10:09:21 +02:00
UpdateGameDataWithActivitySpriteGendersFlag(ACTIVITY_PLYRTALK | IN_UNION_ROOM, 0, 1);
2018-06-09 22:14:52 +02:00
PlaySE(SE_PC_LOGIN);
StringCopy(gStringVar1, gSaveBlock2Ptr->playerName);
data->state = 42;
gSpecialVar_Result = 0;
}
else if (gSpecialVar_Result == 11)
{
2020-05-30 10:09:21 +02:00
UpdateGameDataWithActivitySpriteGendersFlag(ACTIVITY_PLYRTALK | IN_UNION_ROOM, 0, 1);
2018-06-09 22:14:52 +02:00
data->state = 23;
gSpecialVar_Result = 0;
}
else
{
taskData[0] = 0;
taskData[1] = gSpecialVar_Result - 1;
data->state = 24;
gSpecialVar_Result = 0;
}
}
2018-06-10 18:28:37 +02:00
else if (ScriptContext2_IsEnabled() != TRUE)
2018-06-09 22:14:52 +02:00
{
2018-06-10 18:28:37 +02:00
if (gMain.newKeys & A_BUTTON)
2018-06-09 22:14:52 +02:00
{
2020-06-01 16:23:12 +02:00
if (TrySetUnionRoomMemberFacePlayer(data->field_0, &taskData[0], &taskData[1], data->spriteIds))
2018-06-09 22:14:52 +02:00
{
PlaySE(SE_SELECT);
2020-05-30 10:09:21 +02:00
UR_EnableScriptContext2AndFreezeObjectEvents();
2018-06-09 22:14:52 +02:00
data->state = 24;
break;
}
2020-05-30 10:09:21 +02:00
else if (PlayerIsTalkingToUnionRoomAide())
2018-06-09 22:14:52 +02:00
{
2020-05-30 10:09:21 +02:00
UpdateGameDataWithActivitySpriteGendersFlag(ACTIVITY_PLYRTALK | IN_UNION_ROOM, 0, 1);
2018-06-09 22:14:52 +02:00
PlaySE(SE_PC_LOGIN);
2020-05-30 10:09:21 +02:00
UR_EnableScriptContext2AndFreezeObjectEvents();
2018-06-09 22:14:52 +02:00
StringCopy(gStringVar1, gSaveBlock2Ptr->playerName);
data->state = 45;
break;
}
}
2020-05-30 10:09:21 +02:00
switch (HandlePlayerListUpdate())
2018-06-09 22:14:52 +02:00
{
case 1:
PlaySE(SE_PC_LOGIN);
case 2:
2020-05-30 10:09:21 +02:00
ScheduleUnionRoomPlayerRefresh(data);
2018-06-09 22:14:52 +02:00
break;
case 4:
data->state = 11;
2020-05-30 10:09:21 +02:00
UR_EnableScriptContext2AndFreezeObjectEvents();
2018-06-09 22:14:52 +02:00
sub_8010FCC(0, 0, 0);
2020-05-30 10:09:21 +02:00
UpdateGameDataWithActivitySpriteGendersFlag(ACTIVITY_NPCTALK | IN_UNION_ROOM, GetActivePartnerSpriteGenderParam(data), 0);
2018-06-09 22:14:52 +02:00
break;
}
2020-05-30 10:09:21 +02:00
HandleUnionRoomPlayerRefresh(data);
2018-06-09 22:14:52 +02:00
}
break;
case 23:
2019-12-11 09:28:55 +01:00
if (!FuncIsActiveTask(Task_ShowStartMenu))
2018-06-09 22:14:52 +02:00
{
2020-05-30 10:09:21 +02:00
UpdateGameDataWithActivitySpriteGendersFlag(IN_UNION_ROOM, 0, FALSE);
2018-06-09 22:14:52 +02:00
data->state = 4;
}
break;
case 24:
2020-05-30 10:09:21 +02:00
UR_RunTextPrinters_CheckPrinter0Active();
playerGender = GetUnionRoomPlayerGender(taskData[1], data->field_0);
UpdateGameDataWithActivitySpriteGendersFlag(ACTIVITY_PLYRTALK | IN_UNION_ROOM, 0, 1);
switch (UnionRoomGetPlayerInteractionResponse(data->field_0, taskData[0], taskData[1], playerGender))
2018-06-09 22:14:52 +02:00
{
case 0:
data->state = 26;
break;
case 1:
2020-05-30 10:09:21 +02:00
sub_8012188(data->field_0->arr[taskData[1]].gname_uname.playerName, &data->field_0->arr[taskData[1]].gname_uname.gname, gPlayerCurrActivity);
2018-12-02 11:58:50 +01:00
data->field_12 = id; // Should be just 0, but won't match any other way.
2018-06-09 22:14:52 +02:00
data->state = 25;
break;
case 2:
2020-05-30 10:09:21 +02:00
ScheduleFieldMessageWithFollowupState(19, gStringVar4);
2018-06-09 22:14:52 +02:00
break;
}
break;
case 25:
2020-05-30 10:09:21 +02:00
UR_RunTextPrinters_CheckPrinter0Active();
switch (RfuGetErrorStatus())
2018-06-09 22:14:52 +02:00
{
case 4:
2020-05-30 10:09:21 +02:00
HandleCancelTrade(TRUE);
2018-06-09 22:14:52 +02:00
data->state = 4;
break;
case 1:
case 2:
2020-05-30 10:09:21 +02:00
if (IsUnionRoomListenTaskActive() == TRUE)
ScheduleFieldMessageAndExit(sText_TrainerAppearsBusy);
2018-06-09 22:14:52 +02:00
else
2020-05-30 10:09:21 +02:00
ScheduleFieldMessageWithFollowupState(30, sText_TrainerAppearsBusy);
2018-06-09 22:14:52 +02:00
2020-05-30 10:09:21 +02:00
gPlayerCurrActivity = IN_UNION_ROOM;
2018-06-09 22:14:52 +02:00
break;
}
2020-05-30 10:09:21 +02:00
if (gReceivedRemoteLinkPlayers)
2018-06-09 22:14:52 +02:00
{
2020-05-30 10:09:21 +02:00
CreateTrainerCardInBuffer(gBlockSendBuffer, TRUE);
CreateTask(Task_ExchangeCards, 5);
2018-06-09 22:14:52 +02:00
data->state = 38;
}
break;
case 38:
2020-05-30 10:09:21 +02:00
if (!FuncIsActiveTask(Task_ExchangeCards))
2018-06-09 22:14:52 +02:00
{
2020-05-30 10:09:21 +02:00
if (gPlayerCurrActivity == (ACTIVITY_TRADE | IN_UNION_ROOM))
ScheduleFieldMessageWithFollowupState(31, sText_AwaitingPlayersResponseAboutTrade);
2018-06-09 22:14:52 +02:00
else
data->state = 5;
}
break;
case 30:
2020-05-30 10:09:21 +02:00
if (!gReceivedRemoteLinkPlayers)
2018-06-09 22:14:52 +02:00
{
2020-05-30 10:09:21 +02:00
HandleCancelTrade(FALSE);
2020-06-01 16:23:12 +02:00
UpdateUnionRoomMemberFacing(taskData[0], taskData[1], data->field_0);
2018-06-09 22:14:52 +02:00
data->state = 2;
}
break;
2018-12-02 11:58:50 +01:00
case 5:
2020-05-30 10:09:21 +02:00
id = ConvPartnerUnameAndGetWhetherMetAlready(&data->field_0->arr[taskData[1]]);
playerGender = GetUnionRoomPlayerGender(taskData[1], data->field_0);
ScheduleFieldMessageWithFollowupState(6, sHiDoSomethingTexts[id][playerGender]);
2018-12-02 11:58:50 +01:00
break;
2018-06-09 22:14:52 +02:00
case 6:
2020-05-30 10:09:21 +02:00
var5 = ListMenuHandler_AllItemsAvailable(&data->textState, &data->topListMenuWindowId, &data->topListMenuId, &sWindowTemplate_InviteToActivity, &sListMenuTemplate_InviteToActivity);
2018-06-09 22:14:52 +02:00
if (var5 != -1)
{
2020-05-30 10:09:21 +02:00
if (!gReceivedRemoteLinkPlayers)
2018-06-09 22:14:52 +02:00
{
data->state = 28;
}
else
{
2020-05-30 10:09:21 +02:00
data->partnerYesNoResponse = 0;
playerGender = GetUnionRoomPlayerGender(taskData[1], data->field_0);
if (var5 == -2 || var5 == IN_UNION_ROOM)
2018-06-09 22:14:52 +02:00
{
2020-05-30 10:09:21 +02:00
data->playerSendBuffer[0] = IN_UNION_ROOM;
sub_800FE50(data->playerSendBuffer);
2019-12-10 19:48:20 +01:00
StringCopy(gStringVar4, sIfYouWantToDoSomethingTexts[gLinkPlayers[0].gender]);
2018-06-09 22:14:52 +02:00
data->state = 32;
2018-12-02 11:58:50 +01:00
}
else
{
2020-05-30 10:09:21 +02:00
gPlayerCurrActivity = var5;
sPlayerActivityGroupSize = (u32)(var5) >> 8;
if (gPlayerCurrActivity == (ACTIVITY_BATTLE_SINGLE | IN_UNION_ROOM) && !HasAtLeastTwoMonsOfLevel30OrLower())
2018-06-09 22:14:52 +02:00
{
2020-05-30 10:09:21 +02:00
ScheduleFieldMessageWithFollowupState(5, sText_NeedTwoMonsOfLevel30OrLower1);
2018-06-09 22:14:52 +02:00
}
else
{
2020-05-30 10:09:21 +02:00
data->playerSendBuffer[0] = gPlayerCurrActivity | 0x40;
sub_800FE50(data->playerSendBuffer);
2018-06-09 22:14:52 +02:00
data->state = 27;
}
}
}
}
break;
case 28:
StringCopy(gStringVar4, sText_TrainerBattleBusy);
2018-06-09 22:14:52 +02:00
data->state = 36;
break;
case 27:
2020-05-30 10:09:21 +02:00
PollPartnerYesNoResponse(data);
playerGender = GetUnionRoomPlayerGender(taskData[1], data->field_0);
id = GetResponseIdx_InviteToURoomActivity(data->playerSendBuffer[0] & 0x3F);
2019-12-10 19:48:20 +01:00
if (PrintOnTextbox(&data->textState, sText_WaitOrShowCardTexts[playerGender][id]))
2018-06-09 22:14:52 +02:00
{
taskData[3] = 0;
data->state = 29;
}
break;
case 32:
sub_800AC34();
data->state = 36;
break;
case 31:
2020-05-30 10:09:21 +02:00
data->playerSendBuffer[0] = ACTIVITY_TRADE | IN_UNION_ROOM;
data->playerSendBuffer[1] = sUnionRoomTrade.species;
data->playerSendBuffer[2] = sUnionRoomTrade.level;
sub_800FE50(data->playerSendBuffer);
2018-06-09 22:14:52 +02:00
data->state = 29;
break;
case 29:
2020-05-30 10:09:21 +02:00
if (!gReceivedRemoteLinkPlayers)
2018-06-09 22:14:52 +02:00
{
StringCopy(gStringVar4, sText_TrainerBattleBusy);
2018-06-09 22:14:52 +02:00
data->state = 28;
}
else
{
2020-05-30 10:09:21 +02:00
PollPartnerYesNoResponse(data);
if (data->partnerYesNoResponse == (ACTIVITY_ACCEPT | IN_UNION_ROOM))
2018-06-09 22:14:52 +02:00
{
2020-05-30 10:09:21 +02:00
if (gPlayerCurrActivity == ACTIVITY_CARD)
2018-06-09 22:14:52 +02:00
{
2020-05-30 10:09:21 +02:00
ViewURoomPartnerTrainerCard(gStringVar4, data, FALSE);
2018-06-09 22:14:52 +02:00
data->state = 40;
}
else
{
data->state = 13;
}
}
2020-05-30 10:09:21 +02:00
else if (data->partnerYesNoResponse == (ACTIVITY_DECLINE | IN_UNION_ROOM))
2018-06-09 22:14:52 +02:00
{
data->state = 32;
2020-05-30 10:09:21 +02:00
GetURoomActivityRejectMsg(gStringVar4, gPlayerCurrActivity | IN_UNION_ROOM, gLinkPlayers[0].gender);
gPlayerCurrActivity = ACTIVITY_NONE;
2018-06-09 22:14:52 +02:00
}
}
break;
2018-12-02 11:58:50 +01:00
2018-06-09 22:14:52 +02:00
case 7:
2020-05-30 10:09:21 +02:00
id = ConvPartnerUnameAndGetWhetherMetAlready(&data->field_0->arr[taskData[1]]);
playerGender = GetUnionRoomPlayerGender(taskData[1], data->field_0);
ScheduleFieldMessageWithFollowupState(6, sHiDoSomethingTexts[id][playerGender]);
2018-06-09 22:14:52 +02:00
break;
case 40:
if (PrintOnTextbox(&data->textState, gStringVar4))
{
data->state = 41;
sub_800ADF8();
2020-05-30 10:09:21 +02:00
data->partnerYesNoResponse = 0;
data->recvActivityRequest[0] = 0;
2018-06-09 22:14:52 +02:00
}
break;
case 41:
2018-12-31 09:22:21 +01:00
if (IsLinkTaskFinished())
2018-06-09 22:14:52 +02:00
{
if (GetMultiplayerId() == 0)
{
StringCopy(gStringVar1, gLinkPlayers[GetMultiplayerId() ^ 1].name);
2020-05-30 10:09:21 +02:00
id = PlayerHasMetTrainerBefore(gLinkPlayers[1].trainerId, gLinkPlayers[1].name);
2019-12-10 19:48:20 +01:00
StringExpandPlaceholders(gStringVar4, sAwaitingResponseTexts[id]);
2018-06-09 22:14:52 +02:00
data->state = 33;
}
else
{
data->state = 7;
}
}
break;
case 19:
2020-05-30 10:09:21 +02:00
switch (UnionRoomHandleYesNo(&data->textState, FALSE))
2018-06-09 22:14:52 +02:00
{
case 0:
CopyBgTilemapBufferToVram(0);
2020-05-30 10:09:21 +02:00
gPlayerCurrActivity = ACTIVITY_CHAT | IN_UNION_ROOM;
UpdateGameDataWithActivitySpriteGendersFlag(ACTIVITY_CHAT | IN_UNION_ROOM, 0, 1);
sub_8012188(data->field_0->arr[taskData[1]].gname_uname.playerName, &data->field_0->arr[taskData[1]].gname_uname.gname, gPlayerCurrActivity);
2018-06-09 22:14:52 +02:00
data->field_12 = taskData[1];
data->state = 20;
taskData[3] = 0;
break;
case 1:
case -1:
2020-05-30 10:09:21 +02:00
playerGender = GetUnionRoomPlayerGender(taskData[1], data->field_0);
ScheduleFieldMessageAndExit(sDeclineBattleTexts[playerGender]);
2018-06-09 22:14:52 +02:00
break;
}
break;
case 20:
2018-06-10 18:28:37 +02:00
if (++taskData[2] > 60)
2018-06-09 22:14:52 +02:00
{
data->state = 21;
taskData[2] = 0;
}
break;
case 21:
2020-05-30 10:09:21 +02:00
switch (RfuGetErrorStatus())
2018-06-09 22:14:52 +02:00
{
case 4:
2020-05-30 10:09:21 +02:00
HandleCancelTrade(TRUE);
2018-06-09 22:14:52 +02:00
data->state = 4;
break;
case 1:
case 2:
2020-05-30 10:09:21 +02:00
playerGender = GetUnionRoomPlayerGender(taskData[1], data->field_0);
UpdateGameDataWithActivitySpriteGendersFlag(ACTIVITY_PLYRTALK | IN_UNION_ROOM, 0, 1);
if (IsUnionRoomListenTaskActive() == TRUE)
ScheduleFieldMessageAndExit(sChatDeclinedTexts[playerGender]);
2018-06-09 22:14:52 +02:00
else
2020-05-30 10:09:21 +02:00
ScheduleFieldMessageWithFollowupState(30, sChatDeclinedTexts[playerGender]);
2018-06-09 22:14:52 +02:00
break;
case 3:
data->state = 22;
break;
}
taskData[3]++;
break;
case 22:
2020-05-30 10:09:21 +02:00
if (RfuIsErrorStatus1or2())
2018-06-09 22:14:52 +02:00
{
2020-05-30 10:09:21 +02:00
playerGender = GetUnionRoomPlayerGender(taskData[1], data->field_0);
UpdateGameDataWithActivitySpriteGendersFlag(ACTIVITY_PLYRTALK | IN_UNION_ROOM, 0, 1);
if (IsUnionRoomListenTaskActive() == TRUE)
ScheduleFieldMessageAndExit(sChatDeclinedTexts[playerGender]);
2018-06-09 22:14:52 +02:00
else
2020-05-30 10:09:21 +02:00
ScheduleFieldMessageWithFollowupState(30, sChatDeclinedTexts[playerGender]);
2018-06-09 22:14:52 +02:00
}
2020-05-30 10:09:21 +02:00
if (gReceivedRemoteLinkPlayers)
2018-06-09 22:14:52 +02:00
data->state = 16;
break;
case 11:
PlaySE(SE_PINPON);
2018-06-10 18:28:37 +02:00
sub_800EF7C();
2018-06-09 22:14:52 +02:00
data->state = 12;
2020-05-30 10:09:21 +02:00
data->recvActivityRequest[0] = 0;
2018-06-09 22:14:52 +02:00
break;
case 12:
2020-05-30 10:09:21 +02:00
if (RfuIsErrorStatus1or2())
2018-06-09 22:14:52 +02:00
{
2020-05-30 10:09:21 +02:00
HandleCancelTrade(FALSE);
2018-06-09 22:14:52 +02:00
data->state = 2;
}
2020-05-30 10:09:21 +02:00
else if (gReceivedRemoteLinkPlayers)
2018-06-09 22:14:52 +02:00
{
2020-05-30 10:09:21 +02:00
CreateTrainerCardInBuffer(gBlockSendBuffer, TRUE);
CreateTask(Task_ExchangeCards, 5);
2018-06-09 22:14:52 +02:00
data->state = 39;
}
break;
case 39:
2020-05-30 10:09:21 +02:00
ReceiveUnionRoomActivityPacket(data);
if (!FuncIsActiveTask(Task_ExchangeCards))
2018-06-09 22:14:52 +02:00
{
data->state = 33;
StringCopy(gStringVar1, gLinkPlayers[1].name);
2020-05-30 10:09:21 +02:00
id = PlayerHasMetTrainerBefore(gLinkPlayers[1].trainerId, gLinkPlayers[1].name);
2019-12-10 19:48:20 +01:00
StringExpandPlaceholders(gStringVar4, sPlayerContactedYouTexts[id]);
2018-06-09 22:14:52 +02:00
}
break;
case 33:
2020-05-30 10:09:21 +02:00
ReceiveUnionRoomActivityPacket(data);
2018-06-09 22:14:52 +02:00
if (PrintOnTextbox(&data->textState, gStringVar4))
data->state = 34;
break;
case 34:
2020-05-30 10:09:21 +02:00
ReceiveUnionRoomActivityPacket(data);
if (UnionRoom_HandleContactFromOtherPlayer(data) && gMain.newKeys & B_BUTTON)
2018-06-09 22:14:52 +02:00
{
sub_8011DE0(1);
StringCopy(gStringVar4, sText_ChatEnded);
2018-06-09 22:14:52 +02:00
data->state = 36;
}
break;
case 35:
2020-05-30 10:09:21 +02:00
ScheduleFieldMessageWithFollowupState(9, gStringVar4);
2018-06-09 22:14:52 +02:00
break;
case 9:
2020-05-30 10:09:21 +02:00
switch (UnionRoomHandleYesNo(&data->textState, FALSE))
2018-06-09 22:14:52 +02:00
{
case 0:
2020-05-30 10:09:21 +02:00
data->playerSendBuffer[0] = ACTIVITY_ACCEPT | IN_UNION_ROOM;
if (gPlayerCurrActivity == (ACTIVITY_CHAT | IN_UNION_ROOM))
UpdateGameDataWithActivitySpriteGendersFlag(gPlayerCurrActivity | 0x40, sub_801100C(1), 0);
2018-06-09 22:14:52 +02:00
else
2020-05-30 10:09:21 +02:00
UpdateGameDataWithActivitySpriteGendersFlag(gPlayerCurrActivity | 0x40, sub_801100C(1), 1);
2018-06-09 22:14:52 +02:00
data->field_8->arr[0].field_1B = 0;
taskData[3] = 0;
2020-05-30 10:09:21 +02:00
if (gPlayerCurrActivity == (ACTIVITY_BATTLE_SINGLE | IN_UNION_ROOM))
2018-06-09 22:14:52 +02:00
{
if (!HasAtLeastTwoMonsOfLevel30OrLower())
2018-06-09 22:14:52 +02:00
{
2020-05-30 10:09:21 +02:00
data->playerSendBuffer[0] = ACTIVITY_DECLINE | IN_UNION_ROOM;
sub_800FE50(data->playerSendBuffer);
2018-06-09 22:14:52 +02:00
data->state = 10;
StringCopy(gStringVar4, sText_NeedTwoMonsOfLevel30OrLower2);
2018-06-09 22:14:52 +02:00
}
else
{
2020-05-30 10:09:21 +02:00
sub_800FE50(data->playerSendBuffer);
2018-06-09 22:14:52 +02:00
data->state = 13;
}
}
2020-05-30 10:09:21 +02:00
else if (gPlayerCurrActivity == (ACTIVITY_CARD | IN_UNION_ROOM))
2018-06-09 22:14:52 +02:00
{
2020-05-30 10:09:21 +02:00
sub_800FE50(data->playerSendBuffer);
ViewURoomPartnerTrainerCard(gStringVar4, data, TRUE);
2018-06-09 22:14:52 +02:00
data->state = 40;
}
else
{
2020-05-30 10:09:21 +02:00
sub_800FE50(data->playerSendBuffer);
2018-06-09 22:14:52 +02:00
data->state = 13;
}
break;
case 1:
case -1:
2020-05-30 10:09:21 +02:00
data->playerSendBuffer[0] = ACTIVITY_DECLINE | IN_UNION_ROOM;
sub_800FE50(data->playerSendBuffer);
2018-06-09 22:14:52 +02:00
data->state = 10;
2020-05-30 10:09:21 +02:00
GetYouDeclinedTheOfferMessage(gStringVar4, gPlayerCurrActivity);
2018-06-09 22:14:52 +02:00
break;
}
break;
case 10:
sub_800AC34();
data->state = 36;
break;
case 36:
2020-05-30 10:09:21 +02:00
if (!gReceivedRemoteLinkPlayers)
2018-06-09 22:14:52 +02:00
{
2020-05-30 10:09:21 +02:00
gPlayerCurrActivity = IN_UNION_ROOM;
ScheduleFieldMessageWithFollowupState(37, gStringVar4);
memset(data->playerSendBuffer, 0, sizeof(data->playerSendBuffer));
data->recvActivityRequest[0] = 0;
data->partnerYesNoResponse = 0;
2018-06-09 22:14:52 +02:00
}
break;
case 37:
data->state = 2;
2020-05-30 10:09:21 +02:00
HandleCancelTrade(FALSE);
2018-06-09 22:14:52 +02:00
break;
case 13:
2020-05-30 10:09:21 +02:00
GetURoomActivityStartMsg(gStringVar4, gPlayerCurrActivity | IN_UNION_ROOM);
ScheduleFieldMessageWithFollowupState(14, gStringVar4);
2018-06-09 22:14:52 +02:00
break;
case 14:
sub_800ADF8();
data->state = 15;
break;
case 15:
2018-12-31 09:22:21 +01:00
if (IsLinkTaskFinished())
2018-06-09 22:14:52 +02:00
data->state = 16;
break;
case 16:
Free(data->field_8);
Free(data->field_0);
Free(data->field_C);
Free(data->field_4);
DestroyTask(data->field_20);
2020-06-01 16:23:12 +02:00
DestroyGroupMemberSprites(data->spriteIds);
2018-06-09 22:14:52 +02:00
data->state = 17;
break;
case 17:
BeginNormalPaletteFade(-1, 0, 0, 0x10, RGB_BLACK);
data->state = 18;
break;
case 18:
if (!UpdatePaletteFade())
{
2020-06-01 16:23:12 +02:00
DestroyUnionRoomPlayerObjects();
2018-06-09 22:14:52 +02:00
DestroyTask(taskId);
2020-05-30 10:09:21 +02:00
Free(sWirelessLinkMain.uRoom);
CreateTask_StartActivity();
2018-06-09 22:14:52 +02:00
}
break;
case 42:
2020-05-30 10:09:21 +02:00
if (GetHostRFUtgtGname()->species == SPECIES_NONE)
2018-06-09 22:14:52 +02:00
{
data->state = 43;
}
else
{
2020-05-30 10:09:21 +02:00
if (GetHostRFUtgtGname()->species == SPECIES_EGG)
2018-06-09 22:14:52 +02:00
{
StringCopy(gStringVar4, sText_CancelRegistrationOfEgg);
2018-06-09 22:14:52 +02:00
}
else
{
2020-05-30 10:09:21 +02:00
StringCopy(gStringVar1, gSpeciesNames[GetHostRFUtgtGname()->species]);
ConvertIntToDecimalStringN(gStringVar2, GetHostRFUtgtGname()->level, STR_CONV_MODE_LEFT_ALIGN, 3);
StringExpandPlaceholders(gStringVar4, sText_CancelRegistrationOfMon);
2018-06-09 22:14:52 +02:00
}
2020-05-30 10:09:21 +02:00
ScheduleFieldMessageWithFollowupState(44, gStringVar4);
2018-06-09 22:14:52 +02:00
}
break;
case 43:
if (PrintOnTextbox(&data->textState, sText_RegisterMonAtTradingBoard))
2018-06-09 22:14:52 +02:00
data->state = 47;
break;
case 47:
2020-05-30 10:09:21 +02:00
var5 = ListMenuHandler_AllItemsAvailable(&data->textState, &data->tradeBoardSelectWindowId, &data->tradeBoardDetailsWindowId, &gUnknown_082F025C, &gUnknown_082F027C);
2018-06-09 22:14:52 +02:00
if (var5 != -1)
{
2018-06-10 18:28:37 +02:00
if (var5 == -2 || var5 == 3)
2018-06-09 22:14:52 +02:00
{
data->state = 4;
2020-05-30 10:09:21 +02:00
HandleCancelTrade(TRUE);
2018-06-10 18:28:37 +02:00
}
else
{
switch (var5)
{
case 1: // REGISTER
2020-05-30 10:09:21 +02:00
ScheduleFieldMessageWithFollowupState(53, sText_WhichMonWillYouOffer);
2018-06-10 18:28:37 +02:00
break;
case 2: // INFO
2020-05-30 10:09:21 +02:00
ScheduleFieldMessageWithFollowupState(47, sText_TradingBoardInfo);
2018-06-10 18:28:37 +02:00
break;
}
2018-06-09 22:14:52 +02:00
}
}
break;
case 53:
2019-04-04 23:05:46 +02:00
BeginNormalPaletteFade(-1, 0, 0, 0x10, RGB_BLACK);
2018-06-09 22:14:52 +02:00
data->state = 54;
break;
case 54:
if (!gPaletteFade.active)
{
sUnionRoomTrade.field_0 = 1;
2019-12-17 09:24:44 +01:00
gFieldCallback = FieldCB_ContinueScriptUnionRoom;
2019-10-18 01:22:03 +02:00
ChooseMonForTradingBoard(PARTY_MENU_TYPE_UNION_ROOM_REGISTER, CB2_ReturnToField);
2018-06-09 22:14:52 +02:00
}
break;
case 52:
2020-05-30 10:09:21 +02:00
var5 = ListMenuHandler_AllItemsAvailable(&data->textState, &data->tradeBoardSelectWindowId, &data->tradeBoardDetailsWindowId, &gUnknown_082F0294, &sMenuTemplate_TradingBoardRequestType);
2018-06-09 22:14:52 +02:00
if (var5 != -1)
{
switch (var5)
{
case -2:
case 18:
ResetUnionRoomTrade(&sUnionRoomTrade);
2018-06-09 22:14:52 +02:00
sub_8010FCC(0, 0, 0);
2020-05-30 10:09:21 +02:00
ScheduleFieldMessageAndExit(sText_RegistrationCanceled);
2018-06-09 22:14:52 +02:00
break;
default:
sUnionRoomTrade.type = var5;
2018-06-09 22:14:52 +02:00
data->state = 55;
break;
}
}
break;
case 55:
sub_8010FCC(sUnionRoomTrade.type, sUnionRoomTrade.playerSpecies, sUnionRoomTrade.playerLevel);
2020-05-30 10:09:21 +02:00
ScheduleFieldMessageAndExit(sText_RegistraionCompleted);
2018-06-09 22:14:52 +02:00
break;
case 44:
2020-05-30 10:09:21 +02:00
switch (UnionRoomHandleYesNo(&data->textState, FALSE))
2018-06-09 22:14:52 +02:00
{
case 0:
data->state = 56;
break;
case 1:
case -1:
2020-05-30 10:09:21 +02:00
HandleCancelTrade(TRUE);
2018-06-09 22:14:52 +02:00
data->state = 4;
break;
}
break;
case 56:
if (PrintOnTextbox(&data->textState, sText_RegistrationCanceled2))
2018-06-09 22:14:52 +02:00
{
sub_8010FCC(0, 0, 0);
ResetUnionRoomTrade(&sUnionRoomTrade);
2020-05-30 10:09:21 +02:00
HandleCancelTrade(TRUE);
2018-06-09 22:14:52 +02:00
data->state = 4;
}
break;
case 45:
if (PrintOnTextbox(&data->textState, sText_XCheckedTradingBoard))
2018-06-09 22:14:52 +02:00
data->state = 46;
break;
case 46:
2020-05-30 10:09:21 +02:00
UR_ClearBg0();
2018-06-09 22:14:52 +02:00
data->state = 48;
break;
case 48:
2020-05-30 10:09:21 +02:00
var5 = TradeBoardMenuHandler(&data->textState, &data->tradeBoardSelectWindowId, &data->field_4A, &data->tradeBoardDetailsWindowId, &gUnknown_082F034C, &sTradeBoardListMenuTemplate, data->field_0);
2018-06-09 22:14:52 +02:00
if (var5 != -1)
{
switch (var5)
{
case -2:
case 8:
2020-05-30 10:09:21 +02:00
HandleCancelTrade(TRUE);
2018-06-09 22:14:52 +02:00
data->state = 4;
break;
default:
2020-05-30 10:09:21 +02:00
UR_ClearBg0();
switch (IsRequestedTypeOrEggInPlayerParty(data->field_0->arr[var5].gname_uname.gname.type, data->field_0->arr[var5].gname_uname.gname.species))
2018-06-09 22:14:52 +02:00
{
2020-05-30 10:09:21 +02:00
case UR_TRADE_MATCH:
IntlConvPartnerUname7(gStringVar1, &data->field_0->arr[var5]);
ScheduleFieldMessageWithFollowupState(49, sText_AskTrainerToMakeTrade);
2018-06-09 22:14:52 +02:00
taskData[1] = var5;
break;
2020-05-30 10:09:21 +02:00
case UR_TRADE_NOTYPE:
IntlConvPartnerUname7(gStringVar1, &data->field_0->arr[var5]);
StringCopy(gStringVar2, gTypeNames[data->field_0->arr[var5].gname_uname.gname.type]);
ScheduleFieldMessageWithFollowupState(46, sText_DontHaveTypeTrainerWants);
2018-06-10 18:28:37 +02:00
break;
2020-05-30 10:09:21 +02:00
case UR_TRADE_NOEGG:
IntlConvPartnerUname7(gStringVar1, &data->field_0->arr[var5]);
StringCopy(gStringVar2, gTypeNames[data->field_0->arr[var5].gname_uname.gname.type]);
ScheduleFieldMessageWithFollowupState(46, sText_DontHaveEggTrainerWants);
2018-06-09 22:14:52 +02:00
break;
}
break;
}
}
break;
2018-06-10 18:28:37 +02:00
case 49:
2020-05-30 10:09:21 +02:00
switch (UnionRoomHandleYesNo(&data->textState, FALSE))
2018-06-10 18:28:37 +02:00
{
case 0:
data->state = 50;
break;
case -1:
case 1:
2020-05-30 10:09:21 +02:00
HandleCancelTrade(TRUE);
2018-06-10 18:28:37 +02:00
data->state = 4;
break;
}
break;
case 50:
if (PrintOnTextbox(&data->textState, sText_WhichMonWillYouOffer))
2018-06-10 18:28:37 +02:00
{
sUnionRoomTrade.field_0 = 2;
2020-05-30 10:09:21 +02:00
memcpy(&gPartnerTgtGnameSub, &data->field_0->arr[taskData[1]].gname_uname.gname.unk_00, sizeof(gPartnerTgtGnameSub));
gUnionRoomRequestedMonType = data->field_0->arr[taskData[1]].gname_uname.gname.type;
gUnionRoomOfferedSpecies = data->field_0->arr[taskData[1]].gname_uname.gname.species;
2019-12-17 09:24:44 +01:00
gFieldCallback = FieldCB_ContinueScriptUnionRoom;
2019-10-18 01:22:03 +02:00
ChooseMonForTradingBoard(PARTY_MENU_TYPE_UNION_ROOM_TRADE, CB2_ReturnToField);
2018-06-10 18:28:37 +02:00
sub_80156B0(data);
sUnionRoomTrade.field_8 = taskData[1];
2018-06-10 18:28:37 +02:00
}
break;
case 51:
2020-05-30 10:09:21 +02:00
gPlayerCurrActivity = ACTIVITY_TRADE | IN_UNION_ROOM;
sub_8012188(data->field_0->arr[taskData[1]].gname_uname.playerName, &data->field_0->arr[taskData[1]].gname_uname.gname, 0x44);
IntlConvPartnerUname7(gStringVar1, &data->field_0->arr[taskData[1]]);
UR_PrintFieldMessage(sCommunicatingWaitTexts[2]);
2018-06-10 18:28:37 +02:00
data->state = 25;
break;
case 26:
if (PrintOnTextbox(&data->textState, gStringVar4))
{
2020-05-30 10:09:21 +02:00
HandleCancelTrade(TRUE);
2020-06-01 16:23:12 +02:00
UpdateUnionRoomMemberFacing(taskData[0], taskData[1], data->field_0);
2018-06-10 18:28:37 +02:00
data->state = 4;
}
break;
case 8:
if (PrintOnTextbox(&data->textState, gStringVar4))
data->state = data->stateAfterPrint;
break;
2018-06-09 22:14:52 +02:00
}
}
2018-06-10 18:28:37 +02:00
void var_800D_set_xB(void)
{
if (InUnionRoom() == TRUE)
gSpecialVar_Result = 11;
}
2018-12-02 13:59:55 +01:00
2020-05-30 10:09:21 +02:00
static void ReceiveUnionRoomActivityPacket(struct WirelessLink_URoom *data)
2018-12-02 13:59:55 +01:00
{
if (gRecvCmds[1][1] != 0 && (gRecvCmds[1][0] & 0xFF00) == 0x2F00)
{
2020-05-30 10:09:21 +02:00
data->recvActivityRequest[0] = gRecvCmds[1][1];
if (gRecvCmds[1][1] == (ACTIVITY_TRADE | IN_UNION_ROOM))
2018-12-02 13:59:55 +01:00
{
2020-05-30 10:09:21 +02:00
data->recvActivityRequest[1] = gRecvCmds[1][2];
data->recvActivityRequest[2] = gRecvCmds[1][3];
2018-12-02 13:59:55 +01:00
}
}
}
2020-05-30 10:09:21 +02:00
static bool32 UnionRoom_HandleContactFromOtherPlayer(struct WirelessLink_URoom *data)
2018-12-02 13:59:55 +01:00
{
2020-05-30 10:09:21 +02:00
if (data->recvActivityRequest[0] != 0)
2018-12-02 13:59:55 +01:00
{
2020-05-30 10:09:21 +02:00
s32 var = GetChatLeaderActionRequestMessage(gStringVar4, gLinkPlayers[1].gender, &data->recvActivityRequest[0], data);
2018-12-02 13:59:55 +01:00
if (var == 0)
{
return TRUE;
}
else if (var == 1)
{
2020-05-30 10:09:21 +02:00
data->state = 35;
gPlayerCurrActivity = data->recvActivityRequest[0];
2018-12-02 13:59:55 +01:00
return FALSE;
}
else if (var == 2)
{
2020-05-30 10:09:21 +02:00
data->state = 36;
2018-12-02 13:59:55 +01:00
sub_800AC34();
return FALSE;
}
}
return TRUE;
}
2019-10-11 10:14:09 +02:00
void InitUnionRoom(void)
2018-12-02 13:59:55 +01:00
{
2020-05-30 10:09:21 +02:00
struct WirelessLink_URoom *data;
2018-12-02 13:59:55 +01:00
2019-08-15 05:38:42 +02:00
sUnionRoomPlayerName[0] = EOS;
2020-05-30 10:09:21 +02:00
CreateTask(Task_InitUnionRoom, 0);
sWirelessLinkMain.uRoom = sWirelessLinkMain.uRoom; // Needed to match.
sWirelessLinkMain.uRoom = data = AllocZeroed(sizeof(struct WirelessLink_URoom));
sURoom = sWirelessLinkMain.uRoom;
data->state = 0;
data->textState = 0;
data->field_10 = 0;
data->field_12 = 0;
2019-08-15 05:38:42 +02:00
sUnionRoomPlayerName[0] = EOS;
2018-12-02 13:59:55 +01:00
}
2020-05-30 10:09:21 +02:00
static void Task_InitUnionRoom(u8 taskId)
2018-12-02 13:59:55 +01:00
{
s32 i;
u8 text[32];
2020-05-30 10:09:21 +02:00
struct WirelessLink_URoom *data = sWirelessLinkMain.uRoom;
2018-12-02 13:59:55 +01:00
2020-05-30 10:09:21 +02:00
switch (data->state)
2018-12-02 13:59:55 +01:00
{
case 0:
2020-05-30 10:09:21 +02:00
data->state = 1;
2018-12-02 13:59:55 +01:00
break;
case 1:
2020-05-30 10:09:21 +02:00
SetHostRFUtgtGname(ACTIVITY_SEARCH, 0, 0);
SetWirelessCommType1();
2018-12-02 13:59:55 +01:00
OpenLink();
2020-05-30 10:09:21 +02:00
InitializeRfuLinkManager_EnterUnionRoom();
sub_80111B0(TRUE);
data->state = 2;
2018-12-02 13:59:55 +01:00
break;
case 2:
2020-05-30 10:09:21 +02:00
data->field_4 = AllocZeroed(4 * sizeof(struct UnkStruct_x1C));
ClearUnkStruct_x1CArray(data->field_4, 4);
data->field_C = AllocZeroed(4 * sizeof(struct UnkStruct_x1C));
ClearUnkStruct_x1CArray(data->field_C, 4);
data->field_0 = AllocZeroed(8 * sizeof(struct UnkStruct_x20));
ClearUnkStruct_x20Array(data->field_0->arr, 8);
data->field_8 = AllocZeroed(sizeof(struct UnkStruct_x20));
ClearUnkStruct_x20Array(&data->field_8->arr[0], 1);
data->field_20 = CreateTask_SearchForChildOrParent(data->field_C, data->field_4, 10);
data->state = 3;
2018-12-02 13:59:55 +01:00
break;
case 3:
2020-05-30 10:09:21 +02:00
switch (HandlePlayerListUpdate())
2018-12-02 13:59:55 +01:00
{
case 1:
case 2:
2019-08-15 05:38:42 +02:00
if (sUnionRoomPlayerName[0] == EOS)
2018-12-02 13:59:55 +01:00
{
for (i = 0; i < PLAYER_NAME_LENGTH + 1; i++)
{
2020-05-30 10:09:21 +02:00
if (data->field_0->arr[i].groupScheduledAnim == UNION_ROOM_SPAWN_IN)
2018-12-02 13:59:55 +01:00
{
2020-05-30 10:09:21 +02:00
IntlConvPartnerUname7(text, &data->field_0->arr[i]);
if (PlayerHasMetTrainerBefore(ReadAsU16(data->field_0->arr[i].gname_uname.gname.unk_00.playerTrainerId), text))
2018-12-02 13:59:55 +01:00
{
2019-08-15 05:38:42 +02:00
StringCopy(sUnionRoomPlayerName, text);
2018-12-02 13:59:55 +01:00
break;
}
}
}
}
break;
case 3:
break;
}
break;
case 4:
2020-05-30 10:09:21 +02:00
free(data->field_8);
free(data->field_0);
free(data->field_C);
free(data->field_4);
DestroyTask(data->field_20);
free(sWirelessLinkMain.uRoom);
LinkRfu_Shutdown();
2018-12-02 13:59:55 +01:00
DestroyTask(taskId);
break;
}
}
2019-08-15 05:38:42 +02:00
bool16 BufferUnionRoomPlayerName(void)
2018-12-02 13:59:55 +01:00
{
2019-08-15 05:38:42 +02:00
if (sUnionRoomPlayerName[0] != EOS)
2018-12-02 13:59:55 +01:00
{
2019-08-15 05:38:42 +02:00
StringCopy(gStringVar1, sUnionRoomPlayerName);
sUnionRoomPlayerName[0] = EOS;
2018-12-02 13:59:55 +01:00
return TRUE;
}
else
{
return FALSE;
}
}
2020-05-30 10:09:21 +02:00
static u8 HandlePlayerListUpdate(void)
2018-12-02 13:59:55 +01:00
{
s32 i;
u8 j;
2020-05-30 10:09:21 +02:00
struct WirelessLink_URoom *data = sWirelessLinkMain.uRoom;
2018-12-02 13:59:55 +01:00
s32 r7 = 0;
2020-05-30 10:09:21 +02:00
for (i = 0; i < RFU_CHILD_MAX; i++)
2018-12-02 13:59:55 +01:00
{
2020-05-30 10:09:21 +02:00
if (AreGnameUnameDifferent(&data->field_C->arr[i].gname_uname, &sWirelessGnameUnamePair_Dummy) == TRUE)
2018-12-02 13:59:55 +01:00
{
2020-05-30 10:09:21 +02:00
data->field_8->arr[0].gname_uname = data->field_C->arr[i].gname_uname;
data->field_8->arr[0].field_18 = 0;
data->field_8->arr[0].groupScheduledAnim = UNION_ROOM_SPAWN_IN;
data->field_8->arr[0].field_1B = 1;
2018-12-02 13:59:55 +01:00
return 4;
}
}
2020-06-01 16:23:12 +02:00
for (j = 0; j < ARRAY_COUNT(data->field_0->arr); j++)
2018-12-02 13:59:55 +01:00
{
2020-05-30 10:09:21 +02:00
if (data->field_0->arr[j].groupScheduledAnim != UNION_ROOM_SPAWN_NONE)
2018-12-02 13:59:55 +01:00
{
2020-05-30 10:09:21 +02:00
i = Findx20Inx1CArray(&data->field_0->arr[j], &data->field_4->arr[0]);
2018-12-02 13:59:55 +01:00
if (i != 0xFF)
{
2020-05-30 10:09:21 +02:00
if (data->field_0->arr[j].groupScheduledAnim == UNION_ROOM_SPAWN_IN)
2018-12-02 13:59:55 +01:00
{
2020-05-30 10:09:21 +02:00
if (AreUnionRoomPlayerGnamesDifferent(&data->field_0->arr[j].gname_uname, &data->field_4->arr[i].gname_uname))
2018-12-02 13:59:55 +01:00
{
2020-05-30 10:09:21 +02:00
data->field_0->arr[j].gname_uname = data->field_4->arr[i].gname_uname;
data->field_0->arr[j].field_1B = 0x40;
2018-12-02 13:59:55 +01:00
r7 = 1;
}
2020-05-30 10:09:21 +02:00
else if (data->field_0->arr[j].field_1B != 0)
2018-12-02 13:59:55 +01:00
{
2020-05-30 10:09:21 +02:00
data->field_0->arr[j].field_1B--;
if (data->field_0->arr[j].field_1B == 0)
2018-12-02 13:59:55 +01:00
r7 = 2;
}
}
else
{
2020-05-30 10:09:21 +02:00
data->field_0->arr[j].groupScheduledAnim = UNION_ROOM_SPAWN_IN;
data->field_0->arr[j].field_1B = 0;
2018-12-02 13:59:55 +01:00
r7 = 2;
}
2020-05-30 10:09:21 +02:00
data->field_0->arr[j].field_18 = 0;
2018-12-02 13:59:55 +01:00
}
2020-05-30 10:09:21 +02:00
else if (data->field_0->arr[j].groupScheduledAnim != UNION_ROOM_SPAWN_OUT)
2018-12-02 13:59:55 +01:00
{
2020-05-30 10:09:21 +02:00
data->field_0->arr[j].field_18++;
if (data->field_0->arr[j].field_18 >= 600)
2018-12-02 13:59:55 +01:00
{
2020-05-30 10:09:21 +02:00
data->field_0->arr[j].groupScheduledAnim = UNION_ROOM_SPAWN_OUT;
2018-12-02 13:59:55 +01:00
r7 = 2;
}
}
2020-05-30 10:09:21 +02:00
else if (data->field_0->arr[j].groupScheduledAnim == UNION_ROOM_SPAWN_OUT)
2018-12-02 13:59:55 +01:00
{
2020-05-30 10:09:21 +02:00
data->field_0->arr[j].field_18++;
if (data->field_0->arr[j].field_18 >= 900)
2018-12-02 13:59:55 +01:00
{
2020-05-30 10:09:21 +02:00
ClearUnkStruct_x20Array(&data->field_0->arr[j], 1);
2018-12-02 13:59:55 +01:00
}
}
}
}
2020-05-30 10:09:21 +02:00
for (i = 0; i < RFU_CHILD_MAX; i++)
2018-12-02 13:59:55 +01:00
{
2020-05-30 10:09:21 +02:00
if (Appendx1Ctox20(&data->field_0->arr[0], &data->field_4->arr[i], 8) != 0xFF)
2018-12-02 13:59:55 +01:00
r7 = 1;
}
return r7;
}
2020-05-30 10:09:21 +02:00
static void Task_SearchForChildOrParent(u8 taskId)
2018-12-02 13:59:55 +01:00
{
s32 i, j;
2020-05-30 10:09:21 +02:00
struct WirelessGnameUnamePair gname_uname;
2019-03-27 14:54:19 +01:00
struct UnkStruct_Main4 **ptr = (void*) gTasks[taskId].data;
2020-05-30 10:09:21 +02:00
bool8 isParent;
2018-12-02 13:59:55 +01:00
2020-05-30 10:09:21 +02:00
for (i = 0; i < RFU_CHILD_MAX; i++)
2018-12-02 13:59:55 +01:00
{
2020-05-30 10:09:21 +02:00
isParent = LinkRfu_GetNameIfCompatible(&gname_uname.gname, gname_uname.playerName, i);
if (!IsPartnerActivityAcceptable(gname_uname.gname.activity, gTasks[taskId].data[4]))
2019-03-27 14:54:19 +01:00
{
2020-05-30 10:09:21 +02:00
gname_uname = sWirelessGnameUnamePair_Dummy;
2019-03-27 14:54:19 +01:00
}
2020-05-30 10:09:21 +02:00
if (gname_uname.gname.unk_00.language == LANGUAGE_JAPANESE)
2019-03-27 14:54:19 +01:00
{
2020-05-30 10:09:21 +02:00
gname_uname = sWirelessGnameUnamePair_Dummy;
2019-03-27 14:54:19 +01:00
}
2020-05-30 10:09:21 +02:00
if (!isParent)
2018-12-02 13:59:55 +01:00
{
for (j = 0; j < i; j++)
{
2020-05-30 10:09:21 +02:00
if (!AreGnameUnameDifferent(&ptr[1]->arr[j].gname_uname, &gname_uname))
2019-03-27 14:54:19 +01:00
{
2020-05-30 10:09:21 +02:00
gname_uname = sWirelessGnameUnamePair_Dummy;
2019-03-27 14:54:19 +01:00
}
2018-12-02 13:59:55 +01:00
}
2020-05-30 10:09:21 +02:00
ptr[1]->arr[i].gname_uname = gname_uname;
ptr[1]->arr[i].active = AreGnameUnameDifferent(&ptr[1]->arr[i].gname_uname, &sWirelessGnameUnamePair_Dummy);
2018-12-02 13:59:55 +01:00
}
else
{
2020-05-30 10:09:21 +02:00
ptr[0]->arr[i].gname_uname = gname_uname;
ptr[0]->arr[i].active = AreGnameUnameDifferent(&ptr[0]->arr[i].gname_uname, &sWirelessGnameUnamePair_Dummy);
2018-12-02 13:59:55 +01:00
}
}
}
2019-03-27 15:44:49 +01:00
2020-05-30 10:09:21 +02:00
static u8 CreateTask_SearchForChildOrParent(struct UnkStruct_Main4 * main4_parent, struct UnkStruct_Main4 * main4_child, u32 linkGroup)
2019-03-27 15:44:49 +01:00
{
2020-05-30 10:09:21 +02:00
u8 taskId = CreateTask(Task_SearchForChildOrParent, 0);
2019-03-27 15:44:49 +01:00
struct UnkStruct_Main4 ** data = (void *)gTasks[taskId].data;
2020-05-30 10:09:21 +02:00
data[0] = main4_parent;
data[1] = main4_child;
gTasks[taskId].data[4] = linkGroup;
2019-03-27 15:44:49 +01:00
return taskId;
}
2020-05-30 10:09:21 +02:00
static void Task_ListenForPartnersWithCompatibleSerialNos(u8 taskId)
2019-03-27 15:44:49 +01:00
{
s32 i, j;
struct UnkStruct_Main4 **ptr = (void*) gTasks[taskId].data;
2020-05-30 10:09:21 +02:00
for (i = 0; i < RFU_CHILD_MAX; i++)
2019-03-27 15:44:49 +01:00
{
2020-05-30 10:09:21 +02:00
LinkRfu_GetNameIfCompatible(&ptr[0]->arr[i].gname_uname.gname, ptr[0]->arr[i].gname_uname.playerName, i);
if (!IsPartnerActivityAcceptable(ptr[0]->arr[i].gname_uname.gname.activity, gTasks[taskId].data[2]))
2019-03-27 15:44:49 +01:00
{
2020-05-30 10:09:21 +02:00
ptr[0]->arr[i].gname_uname = sWirelessGnameUnamePair_Dummy;
2019-03-27 15:44:49 +01:00
}
for (j = 0; j < i; j++)
{
2020-05-30 10:09:21 +02:00
if (!AreGnameUnameDifferent(&ptr[0]->arr[j].gname_uname, &ptr[0]->arr[i].gname_uname))
2019-03-27 15:44:49 +01:00
{
2020-05-30 10:09:21 +02:00
ptr[0]->arr[i].gname_uname = sWirelessGnameUnamePair_Dummy;
2019-03-27 15:44:49 +01:00
}
}
2020-05-30 10:09:21 +02:00
ptr[0]->arr[i].active = AreGnameUnameDifferent(&ptr[0]->arr[i].gname_uname, &sWirelessGnameUnamePair_Dummy);
2019-03-27 15:44:49 +01:00
}
}
2020-06-01 16:23:12 +02:00
static bool32 HasWonderCardOrNewsByLinkGroup(struct GFtgtGname *gname, s16 linkGroup)
2019-03-27 15:44:49 +01:00
{
2020-05-30 10:09:21 +02:00
if (linkGroup == LINK_GROUP_WONDER_CARD)
2019-03-27 15:44:49 +01:00
{
2020-05-30 10:09:21 +02:00
if (!gname->unk_00.hasCard)
2019-03-27 15:44:49 +01:00
return FALSE;
else
return TRUE;
}
2020-05-30 10:09:21 +02:00
else if (linkGroup == LINK_GROUP_WONDER_NEWS)
2019-03-27 15:44:49 +01:00
{
2020-05-30 10:09:21 +02:00
if (!gname->unk_00.hasNews)
2019-03-27 15:44:49 +01:00
return FALSE;
else
return TRUE;
}
else
{
return FALSE;
}
}
2020-05-30 10:09:21 +02:00
static void Task_ListenForPartnersWithSerial7F7D(u8 taskId)
2019-03-27 15:44:49 +01:00
{
s32 i;
struct UnkStruct_Main4 **ptr = (void*) gTasks[taskId].data;
2020-05-30 10:09:21 +02:00
for (i = 0; i < RFU_CHILD_MAX; i++)
2019-03-27 15:44:49 +01:00
{
2020-05-30 10:09:21 +02:00
if (LinkRfu_GetNameIfSerial7F7D(&ptr[0]->arr[i].gname_uname.gname, ptr[0]->arr[i].gname_uname.playerName, i))
2019-03-27 15:44:49 +01:00
{
2020-06-01 16:23:12 +02:00
HasWonderCardOrNewsByLinkGroup(&ptr[0]->arr[i].gname_uname.gname, gTasks[taskId].data[2]);
2019-03-27 15:44:49 +01:00
}
2020-05-30 10:09:21 +02:00
ptr[0]->arr[i].active = AreGnameUnameDifferent(&ptr[0]->arr[i].gname_uname, &sWirelessGnameUnamePair_Dummy);
2019-03-27 15:44:49 +01:00
}
}
2020-05-30 10:09:21 +02:00
static u8 CreateTask_ListenForPartnersWithCompatibleSerialNos(struct UnkStruct_Main4 * main4, u32 linkGroup)
2019-03-27 15:44:49 +01:00
{
2020-05-30 10:09:21 +02:00
u8 taskId = CreateTask(Task_ListenForPartnersWithCompatibleSerialNos, 0);
2019-03-27 15:44:49 +01:00
struct UnkStruct_Main4 **ptr = (void*) gTasks[taskId].data;
2020-05-30 10:09:21 +02:00
ptr[0] = main4;
gTasks[taskId].data[2] = linkGroup;
2019-03-27 15:44:49 +01:00
return taskId;
}
2020-05-30 10:09:21 +02:00
static u8 CreateTask_ListenForPartnersWithSerial7F7D(struct UnkStruct_Main4 * main4, u32 linkGroup)
2019-03-27 15:44:49 +01:00
{
2020-05-30 10:09:21 +02:00
u8 taskId = CreateTask(Task_ListenForPartnersWithSerial7F7D, 0);
2019-03-27 15:44:49 +01:00
struct UnkStruct_Main4 **ptr = (void*) gTasks[taskId].data;
2020-05-30 10:09:21 +02:00
ptr[0] = main4;
gTasks[taskId].data[2] = linkGroup;
2019-03-27 15:44:49 +01:00
return taskId;
}
2020-05-30 10:09:21 +02:00
static bool32 UR_PrintFieldMessage(const u8 *src)
2019-03-27 15:44:49 +01:00
{
2020-02-07 18:48:47 +01:00
LoadMessageBoxAndBorderGfx();
2019-03-27 15:44:49 +01:00
DrawDialogueFrame(0, 1);
StringExpandPlaceholders(gStringVar4, src);
AddTextPrinterWithCustomSpeedForMessage(FALSE, 1);
return FALSE;
}
2020-05-30 10:09:21 +02:00
static bool32 UR_RunTextPrinters_CheckPrinter0Active(void)
2019-03-27 15:44:49 +01:00
{
if (!RunTextPrintersAndIsPrinter0Active())
return TRUE;
else
return FALSE;
}
2019-03-27 18:16:10 +01:00
2020-05-30 10:09:21 +02:00
static bool8 PrintOnTextbox(u8 *textState, const u8 *str)
2019-03-27 18:16:10 +01:00
{
switch (*textState)
{
case 0:
2020-02-07 18:48:47 +01:00
LoadMessageBoxAndBorderGfx();
2019-03-27 18:16:10 +01:00
DrawDialogueFrame(0, 1);
StringExpandPlaceholders(gStringVar4, str);
AddTextPrinterForMessage_2(TRUE);
(*textState)++;
break;
case 1:
if (!RunTextPrintersAndIsPrinter0Active())
{
*textState = 0;
return TRUE;
}
break;
}
return FALSE;
}
2020-05-30 10:09:21 +02:00
static s8 UnionRoomHandleYesNo(u8 *state, bool32 noDraw)
2019-03-27 18:16:10 +01:00
{
s8 r1;
2020-05-30 10:09:21 +02:00
switch (*state)
2019-03-27 18:16:10 +01:00
{
case 0:
2020-05-30 10:09:21 +02:00
if (noDraw)
2019-03-27 18:16:10 +01:00
{
return -3;
}
DisplayYesNoMenuDefaultYes();
2020-05-30 10:09:21 +02:00
(*state)++;
2019-03-27 18:16:10 +01:00
break;
case 1:
2020-05-30 10:09:21 +02:00
if (noDraw)
2019-03-27 18:16:10 +01:00
{
sub_8198C78();
2020-05-30 10:09:21 +02:00
*state = 0;
2019-03-27 18:16:10 +01:00
return -3;
}
r1 = Menu_ProcessInputNoWrapClearOnChoose();
if (r1 == -1 || r1 == 0 || r1 == 1)
{
2020-05-30 10:09:21 +02:00
*state = 0;
2019-03-27 18:16:10 +01:00
return r1;
}
break;
}
return -2;
}
2020-05-30 10:09:21 +02:00
static u8 CreateTradeBoardWindow(const struct WindowTemplate * template)
2019-03-27 18:16:10 +01:00
{
u8 windowId = AddWindow(template);
DrawStdWindowFrame(windowId, FALSE);
2020-05-30 10:09:21 +02:00
FillWindowPixelBuffer(windowId, PIXEL_FILL(15));
UR_AddTextPrinterParameterized(windowId, 1, sText_NameWantedOfferLv, 8, 1, 6);
2019-03-27 18:16:10 +01:00
CopyWindowToVram(windowId, 2);
PutWindowTilemap(windowId);
return windowId;
}
2020-05-30 10:09:21 +02:00
static void DeleteTradeBoardWindow(u8 windowId)
2019-03-27 18:16:10 +01:00
{
RemoveWindow(windowId);
}
2019-03-27 21:57:34 +01:00
2020-05-30 10:09:21 +02:00
static s32 ListMenuHandler_AllItemsAvailable(u8 *state, u8 *windowId, u8 *listMenuId, const struct WindowTemplate *winTemplate, const struct ListMenuTemplate *menuTemplate)
2019-03-27 21:57:34 +01:00
{
2020-05-30 10:09:21 +02:00
s32 maxWidth, input;
2019-03-27 21:57:34 +01:00
struct WindowTemplate winTemplateCopy;
2020-05-30 10:09:21 +02:00
switch (*state)
2019-03-27 21:57:34 +01:00
{
case 0:
winTemplateCopy = *winTemplate;
2020-05-30 10:09:21 +02:00
maxWidth = Intl_GetListMenuWidth(menuTemplate);
if (winTemplateCopy.width > maxWidth)
2019-03-27 21:57:34 +01:00
{
2020-05-30 10:09:21 +02:00
winTemplateCopy.width = maxWidth;
2019-03-27 21:57:34 +01:00
}
if (winTemplateCopy.tilemapLeft + winTemplateCopy.width > 29)
{
winTemplateCopy.tilemapLeft = max(29 - winTemplateCopy.width, 0);
}
2020-05-30 10:09:21 +02:00
*windowId = AddWindow(&winTemplateCopy);
DrawStdWindowFrame(*windowId, FALSE);
2019-03-27 21:57:34 +01:00
gMultiuseListMenuTemplate = *menuTemplate;
2020-05-30 10:09:21 +02:00
gMultiuseListMenuTemplate.windowId = *windowId;
*listMenuId = ListMenuInit(&gMultiuseListMenuTemplate, 0, 0);
CopyWindowToVram(*windowId, TRUE);
(*state)++;
2019-03-27 21:57:34 +01:00
break;
case 1:
2020-05-30 10:09:21 +02:00
input = ListMenu_ProcessInput(*listMenuId);
2019-03-27 21:57:34 +01:00
if (({gMain.newKeys & A_BUTTON;}))
{
2020-05-30 10:09:21 +02:00
DestroyListMenuTask(*listMenuId, NULL, NULL);
ClearStdWindowAndFrame(*windowId, TRUE);
RemoveWindow(*windowId);
*state = 0;
return input;
2019-03-27 21:57:34 +01:00
}
else if (({gMain.newKeys & B_BUTTON;}))
{
2020-05-30 10:09:21 +02:00
DestroyListMenuTask(*listMenuId, NULL, NULL);
ClearStdWindowAndFrame(*windowId, TRUE);
RemoveWindow(*windowId);
*state = 0;
2019-03-27 21:57:34 +01:00
return -2;
}
break;
}
return -1;
}
2020-05-30 10:09:21 +02:00
static s32 TradeBoardMenuHandler(u8 *state, u8 *windowId, u8 *listMenuId, u8 *tradeBoardWindowId, const struct WindowTemplate *winTemplate, const struct ListMenuTemplate *menuTemplate, struct UnkStruct_Main0 *traders)
2019-03-27 21:57:34 +01:00
{
s32 input;
2020-05-30 10:09:21 +02:00
s32 idx;
2019-03-27 21:57:34 +01:00
2020-05-30 10:09:21 +02:00
switch (*state)
2019-03-27 21:57:34 +01:00
{
case 0:
2020-05-30 10:09:21 +02:00
*tradeBoardWindowId = CreateTradeBoardWindow(&gUnknown_082F0344);
*windowId = AddWindow(winTemplate);
DrawStdWindowFrame(*windowId, FALSE);
2019-03-27 21:57:34 +01:00
gMultiuseListMenuTemplate = *menuTemplate;
2020-05-30 10:09:21 +02:00
gMultiuseListMenuTemplate.windowId = *windowId;
*listMenuId = ListMenuInit(&gMultiuseListMenuTemplate, 0, 1);
(*state)++;
2019-03-27 21:57:34 +01:00
break;
case 1:
2020-05-30 10:09:21 +02:00
CopyWindowToVram(*windowId, TRUE);
(*state)++;
2019-03-27 21:57:34 +01:00
break;
case 2:
// Register swap r1 <---> r2
2020-05-30 10:09:21 +02:00
input = ListMenu_ProcessInput(*listMenuId);
2019-03-27 21:57:34 +01:00
if (({gMain.newKeys & (A_BUTTON | B_BUTTON);}))
{
if (input == 8 || ({gMain.newKeys & B_BUTTON;}))
{
2020-05-30 10:09:21 +02:00
DestroyListMenuTask(*listMenuId, NULL, NULL);
RemoveWindow(*windowId);
DeleteTradeBoardWindow(*tradeBoardWindowId);
*state = 0;
2019-03-27 21:57:34 +01:00
return -2;
}
else
{
2020-05-30 10:09:21 +02:00
idx = GetIndexOfNthTradeBoardOffer(traders->arr, input);
if (idx >= 0)
2019-03-27 21:57:34 +01:00
{
2020-05-30 10:09:21 +02:00
DestroyListMenuTask(*listMenuId, NULL, NULL);
RemoveWindow(*windowId);
DeleteTradeBoardWindow(*tradeBoardWindowId);
*state = 0;
return idx;
2019-03-27 21:57:34 +01:00
}
else
{
PlaySE(SE_WALL_HIT);
}
}
}
break;
}
return -1;
}
2020-05-30 10:09:21 +02:00
static void UR_ClearBg0(void)
2019-03-28 13:42:35 +01:00
{
FillBgTilemapBufferRect(0, 0, 0, 0, 32, 32, 0);
CopyBgTilemapBufferToVram(0);
}
2020-05-30 10:09:21 +02:00
static void JoinGroup_EnableScriptContexts(void)
2019-03-28 13:42:35 +01:00
{
EnableBothScriptContexts();
}
2020-05-30 10:09:21 +02:00
static void UR_AddTextPrinterParameterized(u8 windowId, u8 fontId, const u8 *str, u8 x, u8 y, u8 colorIdx)
2019-03-28 13:42:35 +01:00
{
2020-05-30 10:09:21 +02:00
struct TextPrinterTemplate printerTemplate;
2019-03-28 13:42:35 +01:00
2020-05-30 10:09:21 +02:00
printerTemplate.currentChar = str;
printerTemplate.windowId = windowId;
printerTemplate.fontId = fontId;
printerTemplate.x = x;
printerTemplate.y = y;
printerTemplate.currentX = x;
printerTemplate.currentY = y;
printerTemplate.unk = 0;
2019-03-28 14:59:08 +01:00
gTextFlags.useAlternateDownArrow = FALSE;
2020-05-30 10:09:21 +02:00
switch (colorIdx)
2019-03-28 14:59:08 +01:00
{
2020-05-30 10:09:21 +02:00
case UR_COLOR_DKE_WHT_LTE:
printerTemplate.letterSpacing = 0;
printerTemplate.lineSpacing = 0;
printerTemplate.fgColor = TEXT_COLOR_DARK_GREY;
printerTemplate.bgColor = TEXT_COLOR_WHITE;
printerTemplate.shadowColor = TEXT_COLOR_LIGHT_GREY;
break;
case UR_COLOR_RED_WHT_LTR:
printerTemplate.letterSpacing = 0;
printerTemplate.lineSpacing = 0;
printerTemplate.fgColor = TEXT_COLOR_RED;
printerTemplate.bgColor = TEXT_COLOR_WHITE;
printerTemplate.shadowColor = TEXT_COLOR_LIGHT_RED;
break;
case UR_COLOR_GRN_WHT_LTG:
printerTemplate.letterSpacing = 0;
printerTemplate.lineSpacing = 0;
printerTemplate.fgColor = TEXT_COLOR_GREEN;
printerTemplate.bgColor = TEXT_COLOR_WHITE;
printerTemplate.shadowColor = TEXT_COLOR_LIGHT_GREEN;
break;
case UR_COLOR_WHT_WHT_LTE:
printerTemplate.letterSpacing = 0;
printerTemplate.lineSpacing = 0;
printerTemplate.fgColor = TEXT_COLOR_WHITE;
printerTemplate.bgColor = TEXT_COLOR_WHITE;
printerTemplate.shadowColor = TEXT_COLOR_LIGHT_GREY;
break;
case UR_COLOR_WHT_DKE_LTE:
printerTemplate.letterSpacing = 0;
printerTemplate.lineSpacing = 0;
printerTemplate.fgColor = TEXT_COLOR_WHITE;
printerTemplate.bgColor = TEXT_COLOR_DARK_GREY;
printerTemplate.shadowColor = TEXT_COLOR_LIGHT_GREY;
break;
case UR_COLOR_GRN_DN6_LTB:
printerTemplate.letterSpacing = 0;
printerTemplate.lineSpacing = 0;
printerTemplate.fgColor = TEXT_COLOR_LIGHT_GREEN;
printerTemplate.bgColor = TEXT_DYNAMIC_COLOR_6;
printerTemplate.shadowColor = TEXT_COLOR_LIGHT_BLUE;
break;
case UR_COLOR_DN5_DN6_LTB:
printerTemplate.letterSpacing = 0;
printerTemplate.lineSpacing = 0;
printerTemplate.fgColor = TEXT_DYNAMIC_COLOR_5;
printerTemplate.bgColor = TEXT_DYNAMIC_COLOR_6;
printerTemplate.shadowColor = TEXT_COLOR_LIGHT_BLUE;
2019-03-28 14:59:08 +01:00
break;
}
2020-05-30 10:09:21 +02:00
AddTextPrinter(&printerTemplate, 0xFF, NULL);
2019-03-28 13:42:35 +01:00
}
2019-03-28 15:24:31 +01:00
2020-05-30 10:09:21 +02:00
static void ClearUnkStruct_x20Array(struct UnkStruct_x20 *arr, u8 count)
2019-03-28 15:24:31 +01:00
{
s32 i;
for (i = 0; i < count; i++)
{
2020-05-30 10:09:21 +02:00
arr[i].gname_uname = sWirelessGnameUnamePair_Dummy;
arr[i].field_18 = 0xFF;
arr[i].groupScheduledAnim = UNION_ROOM_SPAWN_NONE;
arr[i].field_1A_1 = 0;
arr[i].field_1B = 0;
2019-03-28 15:24:31 +01:00
}
}
2020-05-30 10:09:21 +02:00
static void ClearUnkStruct_x1CArray(struct UnkStruct_Main4 *main4, u8 count)
2019-03-28 15:24:31 +01:00
{
s32 i;
2020-05-30 10:09:21 +02:00
for (i = 0; i < RFU_CHILD_MAX; i++)
2019-03-28 15:24:31 +01:00
{
2020-05-30 10:09:21 +02:00
main4->arr[i].gname_uname = sWirelessGnameUnamePair_Dummy;
main4->arr[i].active = FALSE;
2019-03-28 15:24:31 +01:00
}
}
2020-05-30 10:09:21 +02:00
static bool8 AreGnameUnameDifferent(struct WirelessGnameUnamePair* pair1, const struct WirelessGnameUnamePair* pair2)
2019-03-28 15:24:31 +01:00
{
s32 i;
for (i = 0; i < 2; i++)
{
2020-05-30 10:09:21 +02:00
if (pair1->gname.unk_00.playerTrainerId[i] != pair2->gname.unk_00.playerTrainerId[i])
2019-03-28 15:24:31 +01:00
{
return TRUE;
}
}
2020-05-30 10:09:21 +02:00
for (i = 0; i < PLAYER_NAME_LENGTH + 1; i++)
2019-03-28 15:24:31 +01:00
{
2020-05-30 10:09:21 +02:00
if (pair1->playerName[i] != pair2->playerName[i])
2019-03-28 15:24:31 +01:00
{
return TRUE;
}
}
return FALSE;
}
2020-05-30 10:09:21 +02:00
static bool32 AreUnionRoomPlayerGnamesDifferent(struct WirelessGnameUnamePair *pair1, struct WirelessGnameUnamePair *pair2)
2019-03-28 15:24:31 +01:00
{
s32 i;
2020-05-30 10:09:21 +02:00
if (pair1->gname.activity != pair2->gname.activity)
2019-03-28 15:24:31 +01:00
{
return TRUE;
}
2020-05-30 10:09:21 +02:00
if (pair1->gname.started != pair2->gname.started)
2019-03-28 15:24:31 +01:00
{
return TRUE;
}
2020-05-30 10:09:21 +02:00
for (i = 0; i < RFU_CHILD_MAX; i++)
2019-03-28 15:24:31 +01:00
{
2020-05-30 10:09:21 +02:00
if (pair1->gname.child_sprite_gender[i] != pair2->gname.child_sprite_gender[i])
2019-03-28 15:24:31 +01:00
{
return TRUE;
}
}
2020-05-30 10:09:21 +02:00
if (pair1->gname.species != pair2->gname.species)
2019-03-28 15:24:31 +01:00
{
return TRUE;
}
2020-05-30 10:09:21 +02:00
if (pair1->gname.type != pair2->gname.type)
2019-03-28 15:24:31 +01:00
{
return TRUE;
}
return FALSE;
}
2020-05-30 10:09:21 +02:00
static u32 Findx20Inx1CArray(struct UnkStruct_x20 *arg0, struct UnkStruct_x1C *arg1)
2019-03-28 15:24:31 +01:00
{
u8 result = 0xFF;
s32 i;
2020-05-30 10:09:21 +02:00
for (i = 0; i < RFU_CHILD_MAX; i++)
2019-03-28 15:24:31 +01:00
{
2020-05-30 10:09:21 +02:00
if (arg1[i].active && !AreGnameUnameDifferent(&arg0->gname_uname, &arg1[i].gname_uname))
2019-03-28 15:24:31 +01:00
{
result = i;
2020-05-30 10:09:21 +02:00
arg1[i].active = FALSE;
2019-03-28 15:24:31 +01:00
}
}
return result;
}
2019-03-28 16:24:50 +01:00
2020-05-30 10:09:21 +02:00
static u8 Appendx1Ctox20(struct UnkStruct_x20 *arg0, struct UnkStruct_x1C *arg1, u8 arg2)
2019-03-28 16:24:50 +01:00
{
s32 i;
2020-05-30 10:09:21 +02:00
if (arg1->active)
2019-03-28 16:24:50 +01:00
{
for (i = 0; i < arg2; i++)
{
2020-05-30 10:09:21 +02:00
if (arg0[i].groupScheduledAnim == UNION_ROOM_SPAWN_NONE)
2019-03-28 16:24:50 +01:00
{
2020-05-30 10:09:21 +02:00
arg0[i].gname_uname = arg1->gname_uname;
2019-03-28 16:24:50 +01:00
arg0[i].field_18 = 0;
2020-05-30 10:09:21 +02:00
arg0[i].groupScheduledAnim = UNION_ROOM_SPAWN_IN;
2019-03-28 16:24:50 +01:00
arg0[i].field_1B = 64;
2020-05-30 10:09:21 +02:00
arg1->active = FALSE;
2019-03-28 16:24:50 +01:00
return i;
}
}
}
return 0xFF;
}
2020-05-30 10:09:21 +02:00
static void PrintUnionRoomGroupOnWindow(u8 windowId, u8 x, u8 y, struct UnkStruct_x20 *group, u8 colorIdx, u8 id)
2019-03-28 16:24:50 +01:00
{
2020-05-30 10:09:21 +02:00
u8 activity;
u8 trainerId[6];
2019-03-28 16:24:50 +01:00
ConvertIntToDecimalStringN(gStringVar4, id + 1, STR_CONV_MODE_LEADING_ZEROS, 2);
2019-12-10 19:48:20 +01:00
StringAppend(gStringVar4, sText_Colon);
2020-05-30 10:09:21 +02:00
UR_AddTextPrinterParameterized(windowId, 1, gStringVar4, x, y, 0);
x += 18;
activity = group->gname_uname.gname.activity;
if (group->groupScheduledAnim == UNION_ROOM_SPAWN_IN && !(activity & IN_UNION_ROOM))
2019-03-28 16:24:50 +01:00
{
2020-05-30 10:09:21 +02:00
IntlConvPartnerUname7(gStringVar4, group);
UR_AddTextPrinterParameterized(windowId, 1, gStringVar4, x, y, colorIdx);
ConvertIntToDecimalStringN(trainerId, group->gname_uname.gname.unk_00.playerTrainerId[0] | (group->gname_uname.gname.unk_00.playerTrainerId[1] << 8), STR_CONV_MODE_LEADING_ZEROS, 5);
2019-12-10 19:48:20 +01:00
StringCopy(gStringVar4, sText_ID);
2020-05-30 10:09:21 +02:00
StringAppend(gStringVar4, trainerId);
UR_AddTextPrinterParameterized(windowId, 1, gStringVar4, GetStringRightAlignXOffset(1, gStringVar4, 0x88), y, colorIdx);
2019-03-28 16:24:50 +01:00
}
}
2020-05-30 10:09:21 +02:00
static void PrintGroupMemberCandidateOnWindowWithColor(u8 windowId, u8 x, u8 y, struct UnkStruct_x20 *group, u8 colorIdx, u8 id)
2019-03-28 16:24:50 +01:00
{
2020-05-30 10:09:21 +02:00
u8 trainerId[6];
2019-03-28 16:24:50 +01:00
2020-05-30 10:09:21 +02:00
if (group->groupScheduledAnim == UNION_ROOM_SPAWN_IN)
2019-03-28 16:24:50 +01:00
{
2020-05-30 10:09:21 +02:00
IntlConvPartnerUname7(gStringVar4, group);
UR_AddTextPrinterParameterized(windowId, 1, gStringVar4, x, y, colorIdx);
ConvertIntToDecimalStringN(trainerId, group->gname_uname.gname.unk_00.playerTrainerId[0] | (group->gname_uname.gname.unk_00.playerTrainerId[1] << 8), STR_CONV_MODE_LEADING_ZEROS, 5);
2019-12-10 19:48:20 +01:00
StringCopy(gStringVar4, sText_ID);
2020-05-30 10:09:21 +02:00
StringAppend(gStringVar4, trainerId);
UR_AddTextPrinterParameterized(windowId, 1, gStringVar4, GetStringRightAlignXOffset(1, gStringVar4, 0x68), y, colorIdx);
2019-03-28 16:24:50 +01:00
}
}
2020-05-30 10:09:21 +02:00
static bool32 PlayerIsTalkingToUnionRoomAide(void)
2019-03-28 16:24:50 +01:00
{
s16 x, y;
GetXYCoordsOneStepInFrontOfPlayer(&x, &y);
2020-05-30 10:09:21 +02:00
2019-03-28 16:24:50 +01:00
if (x != 9)
return FALSE;
2020-05-30 10:09:21 +02:00
2019-03-28 16:24:50 +01:00
if (y != 8)
return FALSE;
2020-05-30 10:09:21 +02:00
2019-03-28 16:24:50 +01:00
if (gPlayerAvatar.tileTransitionState == 2 || gPlayerAvatar.tileTransitionState == 0)
return TRUE;
return FALSE;
}
2020-05-30 10:09:21 +02:00
static u32 GetResponseIdx_InviteToURoomActivity(s32 activity)
2019-03-28 16:24:50 +01:00
{
2020-05-30 10:09:21 +02:00
switch (activity)
2019-03-28 16:24:50 +01:00
{
2020-05-30 10:09:21 +02:00
case ACTIVITY_CHAT:
2019-03-28 16:24:50 +01:00
return 1;
2020-05-30 10:09:21 +02:00
case ACTIVITY_TRADE:
2019-03-28 16:24:50 +01:00
return 2;
2020-05-30 10:09:21 +02:00
case ACTIVITY_CARD:
2019-03-28 16:24:50 +01:00
return 3;
2020-05-30 10:09:21 +02:00
case ACTIVITY_BATTLE_MULTI:
2019-03-28 16:24:50 +01:00
default:
return 0;
}
}
2020-05-30 10:09:21 +02:00
static u32 ConvPartnerUnameAndGetWhetherMetAlready(struct UnkStruct_x20 *arg0)
2019-03-28 16:24:50 +01:00
{
2020-05-30 10:09:21 +02:00
u8 name[30];
IntlConvPartnerUname7(name, arg0);
return PlayerHasMetTrainerBefore(ReadAsU16(arg0->gname_uname.gname.unk_00.playerTrainerId), name);
2019-03-28 16:24:50 +01:00
}
2019-03-29 16:57:03 +01:00
2020-05-30 10:09:21 +02:00
static s32 UnionRoomGetPlayerInteractionResponse(struct UnkStruct_Main0 *main0, bool8 overrideGender, u8 playerIdx, u32 playerGender)
2019-03-29 16:57:03 +01:00
{
2020-05-30 10:09:21 +02:00
bool32 metBefore;
2019-03-29 16:57:03 +01:00
2020-05-30 10:09:21 +02:00
struct UnkStruct_x20 * r5 = &main0->arr[playerIdx];
2019-03-29 16:57:03 +01:00
2020-05-30 10:09:21 +02:00
if (!r5->gname_uname.gname.started && !overrideGender)
2019-03-29 16:57:03 +01:00
{
2020-05-30 10:09:21 +02:00
IntlConvPartnerUname7(gStringVar1, r5);
metBefore = PlayerHasMetTrainerBefore(ReadAsU16(r5->gname_uname.gname.unk_00.playerTrainerId), gStringVar1);
if (r5->gname_uname.gname.activity == (ACTIVITY_CHAT | IN_UNION_ROOM))
2019-03-29 16:57:03 +01:00
{
2020-05-30 10:09:21 +02:00
StringExpandPlaceholders(gStringVar4, sJoinChatTexts[metBefore][playerGender]);
2019-03-29 16:57:03 +01:00
return 2;
}
else
{
2020-05-30 10:09:21 +02:00
UR_PrintFieldMessage(sCommunicatingWaitTexts[metBefore]);
2019-03-29 16:57:03 +01:00
return 1;
}
}
else
{
2020-05-30 10:09:21 +02:00
IntlConvPartnerUname7(gStringVar1, r5);
if (overrideGender)
2019-03-29 16:57:03 +01:00
{
2020-05-30 10:09:21 +02:00
playerGender = (r5->gname_uname.gname.unk_00.playerTrainerId[overrideGender + 1] >> 3) & 1;
2019-03-29 16:57:03 +01:00
}
2020-05-30 10:09:21 +02:00
switch (r5->gname_uname.gname.activity & 0x3F)
2019-03-29 16:57:03 +01:00
{
2020-05-30 10:09:21 +02:00
case ACTIVITY_BATTLE_SINGLE:
StringExpandPlaceholders(gStringVar4, sBattleReactionTexts[playerGender][Random() % ARRAY_COUNT(sBattleReactionTexts[0])]);
2019-03-29 16:57:03 +01:00
break;
2020-05-30 10:09:21 +02:00
case ACTIVITY_TRADE:
2019-12-10 19:48:20 +01:00
StringExpandPlaceholders(gStringVar4, sTradeReactionTexts[playerGender][Random() % 2]);
2019-03-29 16:57:03 +01:00
break;
2020-05-30 10:09:21 +02:00
case ACTIVITY_CHAT:
StringExpandPlaceholders(gStringVar4, sChatReactionTexts[playerGender][Random() % ARRAY_COUNT(sChatReactionTexts[0])]);
2019-03-29 16:57:03 +01:00
break;
2020-05-30 10:09:21 +02:00
case ACTIVITY_CARD:
StringExpandPlaceholders(gStringVar4, sTrainerCardReactionTexts[playerGender][Random() % ARRAY_COUNT(sTrainerCardReactionTexts[0])]);
2019-03-29 16:57:03 +01:00
break;
default:
StringExpandPlaceholders(gStringVar4, sText_TrainerAppearsBusy);
2019-03-29 16:57:03 +01:00
break;
}
return 0;
}
}
2019-03-29 20:50:04 +01:00
void nullsub_14(u8 windowId, s32 itemId, u8 y)
{
}
2020-05-30 10:09:21 +02:00
static void TradeBoardPrintItemInfo(u8 windowId, u8 y, struct GFtgtGname * gname, const u8 * uname, u8 colorIdx)
2019-03-29 20:50:04 +01:00
{
2020-05-30 10:09:21 +02:00
u8 levelStr[4];
u16 species = gname->species;
u8 type = gname->type;
u8 level = gname->level;
2019-03-29 20:50:04 +01:00
2020-05-30 10:09:21 +02:00
UR_AddTextPrinterParameterized(windowId, 1, uname, 8, y, colorIdx);
if (species == SPECIES_EGG)
2019-03-29 20:50:04 +01:00
{
2020-05-30 10:09:21 +02:00
UR_AddTextPrinterParameterized(windowId, 1, sText_EggTrade, 0x44, y, colorIdx);
2019-03-29 20:50:04 +01:00
}
else
{
2020-05-30 10:09:21 +02:00
blit_move_info_icon(windowId, type + 1, 0x44, y);
UR_AddTextPrinterParameterized(windowId, 1, gSpeciesNames[species], 0x76, y, colorIdx);
ConvertIntToDecimalStringN(levelStr, level, STR_CONV_MODE_RIGHT_ALIGN, 3);
UR_AddTextPrinterParameterized(windowId, 1, levelStr, 0xC6, y, colorIdx);
2019-03-29 20:50:04 +01:00
}
}
2020-05-30 10:09:21 +02:00
static void TradeBoardListMenuItemPrintFunc(u8 windowId, s32 itemId, u8 y)
2019-03-29 20:50:04 +01:00
{
2020-05-30 10:09:21 +02:00
struct WirelessLink_Leader *data = sWirelessLinkMain.leader;
2020-02-16 19:49:36 +01:00
struct GFtgtGname *rfu;
2019-03-29 20:50:04 +01:00
s32 i, j;
2020-05-30 10:09:21 +02:00
u8 playerName[11];
2019-03-29 20:50:04 +01:00
2020-05-30 10:09:21 +02:00
if (itemId == -3 && y == sTradeBoardListMenuTemplate.upText_Y)
2019-03-29 20:50:04 +01:00
{
2020-05-30 10:09:21 +02:00
rfu = GetHostRFUtgtGname();
2019-03-29 20:50:04 +01:00
if (rfu->species != SPECIES_NONE)
{
2020-05-30 10:09:21 +02:00
TradeBoardPrintItemInfo(windowId, y, rfu, gSaveBlock2Ptr->playerName, 5);
2019-03-29 20:50:04 +01:00
}
}
else
{
j = 0;
2020-06-01 16:23:12 +02:00
for (i = 0; i < (int)ARRAY_COUNT(data->field_0->arr); i++)
2019-03-29 20:50:04 +01:00
{
2020-05-30 10:09:21 +02:00
if (data->field_0->arr[i].groupScheduledAnim == UNION_ROOM_SPAWN_IN && data->field_0->arr[i].gname_uname.gname.species != SPECIES_NONE)
2019-03-29 20:50:04 +01:00
{
j++;
}
if (j == itemId + 1)
{
2020-05-30 10:09:21 +02:00
IntlConvPartnerUname7(playerName, &data->field_0->arr[i]);
TradeBoardPrintItemInfo(windowId, y, &data->field_0->arr[i].gname_uname.gname, playerName, 6);
2019-03-29 20:50:04 +01:00
break;
}
}
}
}
2020-05-30 10:09:21 +02:00
static s32 GetIndexOfNthTradeBoardOffer(struct UnkStruct_x20 * arg, s32 n)
2019-03-29 20:50:04 +01:00
{
s32 i;
s32 j = 0;
for (i = 0; i < 8; i++)
{
2020-05-30 10:09:21 +02:00
if (arg[i].groupScheduledAnim == UNION_ROOM_SPAWN_IN && arg[i].gname_uname.gname.species != SPECIES_NONE)
2019-03-29 20:50:04 +01:00
{
j++;
}
2020-05-30 10:09:21 +02:00
if (j == n + 1)
2019-03-29 20:50:04 +01:00
{
return i;
}
}
return -1;
}
2019-03-29 21:24:48 +01:00
2020-05-30 10:09:21 +02:00
static s32 GetUnionRoomPlayerGender(s32 playerIdx, struct UnkStruct_Main0 *main0)
2019-03-29 21:24:48 +01:00
{
2020-05-30 10:09:21 +02:00
return main0->arr[playerIdx].gname_uname.gname.playerGender;
2019-03-29 21:24:48 +01:00
}
2020-05-30 10:09:21 +02:00
static s32 IsRequestedTypeOrEggInPlayerParty(u32 type, u32 species)
2019-03-29 21:24:48 +01:00
{
s32 i;
if (species == SPECIES_EGG)
{
for (i = 0; i < gPlayerPartyCount; i++)
{
species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2);
if (species == SPECIES_EGG)
{
2020-05-30 10:09:21 +02:00
return UR_TRADE_MATCH;
2019-03-29 21:24:48 +01:00
}
}
2020-05-30 10:09:21 +02:00
return UR_TRADE_NOEGG;
2019-03-29 21:24:48 +01:00
}
else
{
for (i = 0; i < gPlayerPartyCount; i++)
{
species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2);
if (gBaseStats[species].type1 == type || gBaseStats[species].type2 == type)
{
2020-05-30 10:09:21 +02:00
return UR_TRADE_MATCH;
2019-03-29 21:24:48 +01:00
}
}
2020-05-30 10:09:21 +02:00
return UR_TRADE_NOTYPE;
2019-03-29 21:24:48 +01:00
}
}
2020-05-30 10:09:21 +02:00
static void GetURoomActivityRejectMsg(u8 *dst, s32 acitivty, u32 playerGender)
2019-03-29 21:24:48 +01:00
{
2020-05-30 10:09:21 +02:00
switch (acitivty)
2019-03-29 21:24:48 +01:00
{
2020-05-30 10:09:21 +02:00
case ACTIVITY_BATTLE_SINGLE | IN_UNION_ROOM:
2019-12-10 19:48:20 +01:00
StringExpandPlaceholders(dst, sBattleDeclinedTexts[playerGender]);
2019-03-29 21:24:48 +01:00
break;
2020-05-30 10:09:21 +02:00
case ACTIVITY_CHAT | IN_UNION_ROOM:
2019-12-10 19:48:20 +01:00
StringExpandPlaceholders(dst, sChatDeclinedTexts[playerGender]);
2019-03-29 21:24:48 +01:00
break;
2020-05-30 10:09:21 +02:00
case ACTIVITY_TRADE | IN_UNION_ROOM:
StringExpandPlaceholders(dst, sText_TradeOfferRejected);
2019-03-29 21:24:48 +01:00
break;
2020-05-30 10:09:21 +02:00
case ACTIVITY_CARD | IN_UNION_ROOM:
2019-12-10 19:48:20 +01:00
StringExpandPlaceholders(dst, sShowTrainerCardDeclinedTexts[playerGender]);
2019-03-29 21:24:48 +01:00
break;
}
}
2020-05-30 10:09:21 +02:00
static void GetURoomActivityStartMsg(u8 *dst, u8 acitivty)
2019-03-29 21:24:48 +01:00
{
u8 mpId = GetMultiplayerId();
u8 gender = gLinkPlayers[mpId ^ 1].gender;
2020-05-30 10:09:21 +02:00
switch (acitivty)
2019-03-29 21:24:48 +01:00
{
2020-05-30 10:09:21 +02:00
case ACTIVITY_BATTLE_SINGLE | IN_UNION_ROOM:
2019-12-10 19:48:20 +01:00
StringCopy(dst, sStartActivityTexts[mpId][gender][0]);
2019-03-29 21:24:48 +01:00
break;
2020-05-30 10:09:21 +02:00
case ACTIVITY_TRADE | IN_UNION_ROOM:
2019-12-10 19:48:20 +01:00
StringCopy(dst, sStartActivityTexts[mpId][gender][2]);
2019-03-29 21:24:48 +01:00
break;
2020-05-30 10:09:21 +02:00
case ACTIVITY_CHAT | IN_UNION_ROOM:
2019-12-10 19:48:20 +01:00
StringCopy(dst, sStartActivityTexts[mpId][gender][1]);
2019-03-29 21:24:48 +01:00
break;
}
}
2019-03-29 22:19:29 +01:00
2020-05-30 10:09:21 +02:00
static s32 GetChatLeaderActionRequestMessage(u8 *dst, u32 gender, u16 *activityData, struct WirelessLink_URoom *uroom)
2019-03-29 22:19:29 +01:00
{
s32 result = 0;
u16 species = SPECIES_NONE;
s32 i;
2020-05-30 10:09:21 +02:00
switch (activityData[0])
2019-03-29 22:19:29 +01:00
{
2020-05-30 10:09:21 +02:00
case ACTIVITY_BATTLE_SINGLE | IN_UNION_ROOM:
StringExpandPlaceholders(dst, sText_BattleChallenge);
2019-03-29 22:19:29 +01:00
result = 1;
break;
2020-05-30 10:09:21 +02:00
case ACTIVITY_CHAT | IN_UNION_ROOM:
StringExpandPlaceholders(dst, sText_ChatInvitation);
2019-03-29 22:19:29 +01:00
result = 1;
break;
2020-05-30 10:09:21 +02:00
case ACTIVITY_TRADE | IN_UNION_ROOM:
ConvertIntToDecimalStringN(uroom->activityRequestStrbufs[0], sUnionRoomTrade.playerLevel, STR_CONV_MODE_LEFT_ALIGN, 3);
StringCopy(uroom->activityRequestStrbufs[1], gSpeciesNames[sUnionRoomTrade.playerSpecies]);
for (i = 0; i < RFU_CHILD_MAX; i++)
2019-03-29 22:19:29 +01:00
{
2020-01-15 22:38:24 +01:00
if (gRfuLinkStatus->partner[i].serialNo == 2)
2019-03-29 22:19:29 +01:00
{
2020-05-30 10:09:21 +02:00
ConvertIntToDecimalStringN(uroom->activityRequestStrbufs[2], activityData[2], STR_CONV_MODE_LEFT_ALIGN, 3);
StringCopy(uroom->activityRequestStrbufs[3], gSpeciesNames[activityData[1]]);
species = activityData[1];
2019-03-29 22:19:29 +01:00
break;
}
}
if (species == SPECIES_EGG)
{
StringCopy(dst, sText_OfferToTradeEgg);
2019-03-29 22:19:29 +01:00
}
else
{
2020-05-30 10:09:21 +02:00
for (i = 0; i < RFU_CHILD_MAX; i++)
2019-03-29 22:19:29 +01:00
{
2020-05-30 10:09:21 +02:00
DynamicPlaceholderTextUtil_SetPlaceholderPtr(i, uroom->activityRequestStrbufs[i]);
2019-03-29 22:19:29 +01:00
}
DynamicPlaceholderTextUtil_ExpandPlaceholders(dst, sText_OfferToTradeMon);
2019-03-29 22:19:29 +01:00
}
result = 1;
break;
2020-05-30 10:09:21 +02:00
case ACTIVITY_CARD | IN_UNION_ROOM:
StringExpandPlaceholders(dst, sText_ShowTrainerCard);
2019-03-29 22:19:29 +01:00
result = 1;
break;
2020-05-30 10:09:21 +02:00
case IN_UNION_ROOM:
StringExpandPlaceholders(dst, sText_ChatDropped);
2019-03-29 22:19:29 +01:00
result = 2;
break;
}
return result;
}
2019-03-30 00:41:32 +01:00
2020-05-30 10:09:21 +02:00
static bool32 PollPartnerYesNoResponse(struct WirelessLink_URoom *data)
2019-03-30 00:41:32 +01:00
{
if (gRecvCmds[0][1] != 0)
{
2020-05-30 10:09:21 +02:00
if (gRecvCmds[0][1] == (ACTIVITY_ACCEPT | IN_UNION_ROOM))
2019-03-30 00:41:32 +01:00
{
2020-05-30 10:09:21 +02:00
data->partnerYesNoResponse = ACTIVITY_ACCEPT | IN_UNION_ROOM;
2019-03-30 00:41:32 +01:00
return TRUE;
}
2020-05-30 10:09:21 +02:00
else if (gRecvCmds[0][1] == (ACTIVITY_DECLINE | IN_UNION_ROOM))
2019-03-30 00:41:32 +01:00
{
2020-05-30 10:09:21 +02:00
data->partnerYesNoResponse = ACTIVITY_DECLINE | IN_UNION_ROOM;
2019-03-30 00:41:32 +01:00
return TRUE;
}
}
return FALSE;
}
bool32 InUnionRoom(void)
{
return gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(UNION_ROOM)
&& gSaveBlock1Ptr->location.mapNum == MAP_NUM(UNION_ROOM)
? TRUE : FALSE;
}
2020-05-30 10:09:21 +02:00
static bool32 HasAtLeastTwoMonsOfLevel30OrLower(void)
2019-03-30 00:41:32 +01:00
{
s32 i;
s32 count = 0;
for (i = 0; i < gPlayerPartyCount; i++)
{
if (GetMonData(&gPlayerParty[i], MON_DATA_LEVEL) <= 30
2019-03-30 00:41:32 +01:00
&& GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2) != SPECIES_EGG)
{
count++;
}
}
if (count > 1)
return TRUE;
else
return FALSE;
}
2020-05-30 10:09:21 +02:00
static void ResetUnionRoomTrade(struct UnionRoomTrade *uroomTrade)
2019-03-30 00:41:32 +01:00
{
2020-05-30 10:09:21 +02:00
uroomTrade->field_0 = 0;
uroomTrade->type = 0;
uroomTrade->playerPersonality = 0;
uroomTrade->playerSpecies = 0;
uroomTrade->playerLevel = 0;
uroomTrade->species = 0;
uroomTrade->level = 0;
uroomTrade->personality = 0;
2019-03-30 00:41:32 +01:00
}
void Script_ResetUnionRoomTrade(void)
2019-03-30 00:41:32 +01:00
{
ResetUnionRoomTrade(&sUnionRoomTrade);
2019-03-30 00:41:32 +01:00
}
static bool32 RegisterTradeMonAndGetIsEgg(u32 monId, struct UnionRoomTrade *trade)
2019-03-30 00:41:32 +01:00
{
trade->playerSpecies = GetMonData(&gPlayerParty[monId], MON_DATA_SPECIES2);
trade->playerLevel = GetMonData(&gPlayerParty[monId], MON_DATA_LEVEL);
trade->playerPersonality = GetMonData(&gPlayerParty[monId], MON_DATA_PERSONALITY);
if (trade->playerSpecies == SPECIES_EGG)
2019-03-30 00:41:32 +01:00
return TRUE;
else
return FALSE;
}
static void RegisterTradeMon(u32 monId, struct UnionRoomTrade *trade)
2019-03-30 00:41:32 +01:00
{
trade->species = GetMonData(&gPlayerParty[monId], MON_DATA_SPECIES2);
trade->level = GetMonData(&gPlayerParty[monId], MON_DATA_LEVEL);
trade->personality = GetMonData(&gPlayerParty[monId], MON_DATA_PERSONALITY);
2019-03-30 00:41:32 +01:00
}
2019-03-30 03:22:26 +01:00
static u32 GetPartyPositionOfRegisteredMon(struct UnionRoomTrade *trade, u8 multiplayerId)
2019-03-30 03:22:26 +01:00
{
u16 response = 0;
u16 species;
u32 personality;
u32 cur_personality;
u16 cur_species;
s32 i;
// player
2019-03-30 03:22:26 +01:00
if (multiplayerId == 0)
{
species = trade->playerSpecies;
personality = trade->playerPersonality;
2019-03-30 03:22:26 +01:00
}
// partner
2019-03-30 03:22:26 +01:00
else
{
species = trade->species;
personality = trade->personality;
2019-03-30 03:22:26 +01:00
}
for (i = 0; i < gPlayerPartyCount; i++)
{
cur_personality = GetMonData(&gPlayerParty[i], MON_DATA_PERSONALITY);
if (cur_personality != personality)
{
continue;
}
cur_species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2);
if (cur_species != species)
{
continue;
}
response = i;
break;
}
return response;
}
2020-05-30 10:09:21 +02:00
static void HandleCancelTrade(bool32 unlockObjs)
2019-03-30 03:22:26 +01:00
{
2020-05-30 10:09:21 +02:00
UR_ClearBg0();
2019-03-30 03:22:26 +01:00
ScriptContext2_Disable();
2020-05-30 10:09:21 +02:00
UnionRoom_UnlockPlayerAndChatPartner();
gPlayerCurrActivity = 0;
if (unlockObjs)
2019-03-30 03:22:26 +01:00
{
sub_8010FCC(sUnionRoomTrade.type, sUnionRoomTrade.playerSpecies, sUnionRoomTrade.playerLevel);
2020-05-30 10:09:21 +02:00
UpdateGameDataWithActivitySpriteGendersFlag(IN_UNION_ROOM, 0, 0);
2019-03-30 03:22:26 +01:00
}
}
2020-05-30 10:09:21 +02:00
static void UR_EnableScriptContext2AndFreezeObjectEvents(void)
2019-03-30 03:22:26 +01:00
{
ScriptContext2_Enable();
ScriptFreezeObjectEvents();
2019-03-30 03:22:26 +01:00
}
2020-05-30 10:09:21 +02:00
static u8 GetActivePartnerSpriteGenderParam(struct WirelessLink_URoom *data)
2019-03-30 03:22:26 +01:00
{
u8 retVal = 0x80;
u8 i;
2020-05-30 10:09:21 +02:00
for (i = 0; i < RFU_CHILD_MAX; i++)
2019-03-30 03:22:26 +01:00
{
2020-05-30 10:09:21 +02:00
if (data->field_C->arr[i].active)
2019-03-30 03:22:26 +01:00
{
2020-05-30 10:09:21 +02:00
retVal |= data->field_C->arr[i].gname_uname.gname.playerGender << 3;
retVal |= data->field_C->arr[i].gname_uname.gname.unk_00.playerTrainerId[0] & 7;
2019-03-30 03:22:26 +01:00
break;
}
}
return retVal;
}
2019-03-30 14:18:58 +01:00
2020-05-30 10:09:21 +02:00
static void ViewURoomPartnerTrainerCard(u8 *unused, struct WirelessLink_URoom *data, bool8 isParent)
2019-03-30 14:18:58 +01:00
{
struct TrainerCard *trainerCard = &gTrainerCards[GetMultiplayerId() ^ 1];
s32 i;
s32 n;
DynamicPlaceholderTextUtil_Reset();
2020-06-03 21:28:29 +02:00
StringCopy(data->field_C0[0], gTrainerClassNames[GetUnionRoomTrainerClass()]);
2020-05-30 10:09:21 +02:00
DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, data->field_C0[0]);
2019-03-30 14:18:58 +01:00
DynamicPlaceholderTextUtil_SetPlaceholderPtr(1, trainerCard->playerName);
2020-05-30 10:09:21 +02:00
StringCopy(data->field_174, sCardColorTexts[trainerCard->stars]);
DynamicPlaceholderTextUtil_SetPlaceholderPtr(2, data->field_174);
2019-03-30 14:18:58 +01:00
2020-05-30 10:09:21 +02:00
ConvertIntToDecimalStringN(data->field_C0[2], trainerCard->caughtMonsCount, STR_CONV_MODE_LEFT_ALIGN, 3);
DynamicPlaceholderTextUtil_SetPlaceholderPtr(3, data->field_C0[2]);
2019-03-30 14:18:58 +01:00
2020-05-30 10:09:21 +02:00
ConvertIntToDecimalStringN(data->field_C0[3], trainerCard->playTimeHours, STR_CONV_MODE_LEFT_ALIGN, 3);
ConvertIntToDecimalStringN(data->field_C0[4], trainerCard->playTimeMinutes, STR_CONV_MODE_LEADING_ZEROS, 2);
DynamicPlaceholderTextUtil_SetPlaceholderPtr(4, data->field_C0[3]);
DynamicPlaceholderTextUtil_SetPlaceholderPtr(5, data->field_C0[4]);
2019-03-30 14:18:58 +01:00
2020-05-30 10:09:21 +02:00
DynamicPlaceholderTextUtil_ExpandPlaceholders(data->field_1A4, sText_TrainerCardInfoPage1);
StringCopy(gStringVar4, data->field_1A4);
2019-03-30 14:18:58 +01:00
n = trainerCard->linkBattleWins;
if (n > 9999)
{
n = 9999;
}
2020-05-30 10:09:21 +02:00
ConvertIntToDecimalStringN(data->field_C0[0], n, STR_CONV_MODE_LEFT_ALIGN, 4);
DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, data->field_C0[0]);
2019-03-30 14:18:58 +01:00
n = trainerCard->linkBattleLosses;
if (n > 9999)
{
n = 9999;
}
2020-05-30 10:09:21 +02:00
ConvertIntToDecimalStringN(data->field_C0[1], n, STR_CONV_MODE_LEFT_ALIGN, 4);
DynamicPlaceholderTextUtil_SetPlaceholderPtr(2, data->field_C0[1]);
2019-03-30 14:18:58 +01:00
2020-05-30 10:09:21 +02:00
ConvertIntToDecimalStringN(data->field_C0[2], trainerCard->pokemonTrades, STR_CONV_MODE_LEFT_ALIGN, 5);
DynamicPlaceholderTextUtil_SetPlaceholderPtr(3, data->field_C0[2]);
2019-03-30 14:18:58 +01:00
2020-02-07 18:48:47 +01:00
for (i = 0; i < TRAINER_CARD_PROFILE_LENGTH; i++)
2019-03-30 14:18:58 +01:00
{
2020-05-30 10:09:21 +02:00
CopyEasyChatWord(data->field_C0[i + 3], trainerCard->easyChatProfile[i]);
DynamicPlaceholderTextUtil_SetPlaceholderPtr(i + 4, data->field_C0[i + 3]);
2019-03-30 14:18:58 +01:00
}
2020-05-30 10:09:21 +02:00
DynamicPlaceholderTextUtil_ExpandPlaceholders(data->field_1A4, sText_TrainerCardInfoPage2);
StringAppend(gStringVar4, data->field_1A4);
2019-03-30 14:18:58 +01:00
2020-05-30 10:09:21 +02:00
if (isParent == TRUE)
2019-03-30 14:18:58 +01:00
{
2020-05-30 10:09:21 +02:00
DynamicPlaceholderTextUtil_ExpandPlaceholders(data->field_1A4, sText_FinishedCheckingPlayersTrainerCard);
StringAppend(gStringVar4, data->field_1A4);
2019-03-30 14:18:58 +01:00
}
2020-05-30 10:09:21 +02:00
else if (isParent == FALSE)
2019-03-30 14:18:58 +01:00
{
2020-05-30 10:09:21 +02:00
DynamicPlaceholderTextUtil_ExpandPlaceholders(data->field_1A4, sGladToMeetYouTexts[trainerCard->gender]);
StringAppend(gStringVar4, data->field_1A4);
2019-03-30 14:18:58 +01:00
}
}
2019-03-30 14:23:47 +01:00
2020-05-30 10:09:21 +02:00
static void IntlConvPartnerUname7(u8 *dest, struct UnkStruct_x20 *arg1)
2019-03-30 14:23:47 +01:00
{
2020-05-30 10:09:21 +02:00
StringCopy7(dest, arg1->gname_uname.playerName);
ConvertInternationalString(dest, arg1->gname_uname.gname.unk_00.language);
2019-03-30 14:23:47 +01:00
}