diff --git a/include/berry_crush.h b/include/berry_crush.h index 8909ae821b..a08f1f6996 100755 --- a/include/berry_crush.h +++ b/include/berry_crush.h @@ -3,6 +3,6 @@ #include "main.h" -void sub_8020C70(MainCallback callback); +void StartBerryCrush(MainCallback callback); #endif // GUARD_BERRY_CRUSH_H diff --git a/include/cable_club.h b/include/cable_club.h index c2849ca3eb..72e344009b 100644 --- a/include/cable_club.h +++ b/include/cable_club.h @@ -11,7 +11,7 @@ void sub_80B37D4(TaskFunc taskFunc); u8 sub_80B3050(void); -void sub_80B360C(void); +void CB2_ReturnFromCableClubBattle(void); bool32 sub_80B2AF4(u16 *arg0, u16 *arg1); void sub_80B3AF8(u8 taskId); void task00_08081A90(u8 taskId); diff --git a/include/constants/union_room.h b/include/constants/union_room.h index 2314f85a09..9243ea15dc 100644 --- a/include/constants/union_room.h +++ b/include/constants/union_room.h @@ -1,6 +1,58 @@ #ifndef GUARD_CONSTANTS_UNION_ROOM_H #define GUARD_CONSTANTS_UNION_ROOM_H +#define UNION_ROOM_SPAWN_NONE 0 +#define UNION_ROOM_SPAWN_IN 1 +#define UNION_ROOM_SPAWN_OUT 2 + +#define ACTIVITY_NONE 0 +#define ACTIVITY_BATTLE_SINGLE 1 +#define ACTIVITY_BATTLE_DOUBLE 2 +#define ACTIVITY_BATTLE_MULTI 3 +#define ACTIVITY_TRADE 4 +#define ACTIVITY_CHAT 5 +#define ACTIVITY_WONDER_CARD 6 +#define ACTIVITY_WONDER_NEWS 7 +#define ACTIVITY_CARD 8 +#define ACTIVITY_POKEMON_JUMP 9 +#define ACTIVITY_BERRY_CRUSH 10 +#define ACTIVITY_BERRY_PICK 11 +#define ACTIVITY_SEARCH 12 +#define ACTIVITY_SPIN_TRADE 13 +#define ACTIVITY_BATTLE_TOWER_OPEN 14 +#define ACTIVITY_RECORD_CORNER 15 +#define ACTIVITY_BERRY_BLENDER 16 + +// Player response +#define ACTIVITY_ACCEPT 17 +#define ACTIVITY_DECLINE 18 + +#define ACTIVITY_NPCTALK 19 +#define ACTIVITY_PLYRTALK 20 + +// Duplicate IDs? +#define ACTIVITY_WONDER_CARD2 21 +#define ACTIVITY_WONDER_NEWS2 22 + +#define ACTIVITY_CONTEST_COOL 23 +#define ACTIVITY_CONTEST_BEAUTY 24 +#define ACTIVITY_CONTEST_CUTE 25 +#define ACTIVITY_CONTEST_SMART 26 +#define ACTIVITY_CONTEST_TOUGH 27 +#define ACTIVITY_BATTLE_TOWER 28 +#define ACTIVITY_29 29 + +#define IN_UNION_ROOM 0x40 + +// Used in UR_AddTextPrinterParameterized +#define UR_COLOR_DKE_WHT_LTE 0 +#define UR_COLOR_RED_WHT_LTR 1 +#define UR_COLOR_GRN_WHT_LTG 2 +#define UR_COLOR_WHT_WHT_LTE 3 +#define UR_COLOR_WHT_DKE_LTE 4 +#define UR_COLOR_GRN_DN6_LTB 5 +#define UR_COLOR_DN5_DN6_LTB 6 + #define LINK_GROUP_SINGLE_BATTLE 0 #define LINK_GROUP_DOUBLE_BATTLE 1 #define LINK_GROUP_MULTI_BATTLE 2 @@ -10,8 +62,8 @@ #define LINK_GROUP_BERRY_PICKING 6 #define LINK_GROUP_WONDER_CARD 7 #define LINK_GROUP_WONDER_NEWS 8 -#define LINK_GROUP_UNK_9 9 -#define LINK_GROUP_UNK_10 10 +#define LINK_GROUP_UNION_ROOM_RESUME 9 +#define LINK_GROUP_UNION_ROOM_INIT 10 #define LINK_GROUP_UNK_11 11 #define LINK_GROUP_RECORD_CORNER 12 #define LINK_GROUP_BERRY_BLENDER 13 @@ -25,4 +77,8 @@ #define LINK_GROUP_BATTLE_TOWER_OPEN 21 #define NUM_LINK_GROUP_TYPES 22 +#define UR_TRADE_MATCH 0 +#define UR_TRADE_NOTYPE 1 +#define UR_TRADE_NOEGG 2 + #endif //GUARD_CONSTANTS_UNION_ROOM_H diff --git a/include/dodrio_berry_picking.h b/include/dodrio_berry_picking.h index 9995decc24..5decbeccb9 100644 --- a/include/dodrio_berry_picking.h +++ b/include/dodrio_berry_picking.h @@ -1,7 +1,7 @@ #ifndef GUARD_DODRIO_BERRY_PICKING_H #define GUARD_DODRIO_BERRY_PICKING_H -void sub_802493C(u16 a0, void (*callback)(void)); +void StartDodrioBerryPicking(u16 a0, void (*callback)(void)); void IsDodrioInParty(void); void ShowDodrioBerryPickingRecords(void); diff --git a/include/event_object_lock.h b/include/event_object_lock.h index a3b350019d..0226eb632b 100644 --- a/include/event_object_lock.h +++ b/include/event_object_lock.h @@ -8,6 +8,6 @@ void LockSelectedObjectEvent(void); void sub_8098630(void); bool8 sub_8098734(void); void ScriptUnfreezeObjectEvents(void); -void sub_8098524(void); +void UnionRoom_UnlockPlayerAndChatPartner(void); #endif // GUARD_EVENT_OBJECT_LOCK_H diff --git a/include/link.h b/include/link.h index f41161d233..2818b3a7ce 100644 --- a/include/link.h +++ b/include/link.h @@ -274,7 +274,7 @@ void LoadWirelessStatusIndicatorSpriteGfx(void); bool8 IsLinkTaskFinished(void); void CreateWirelessStatusIndicatorSprite(u8, u8); void sub_800ADF8(void); -void sub_800B488(void); +void SetWirelessCommType1(void); void CheckShouldAdvanceLinkState(void); void sub_8011BD0(void); u8 IsLinkMaster(void); diff --git a/include/link_rfu.h b/include/link_rfu.h index 2d74e686ad..901b5deae1 100644 --- a/include/link_rfu.h +++ b/include/link_rfu.h @@ -204,7 +204,7 @@ extern u8 gWirelessStatusIndicatorSpriteId; // Exported ROM declarations void WipeTrainerNameRecords(void); void sub_800E700(void); -void sub_800EDD4(void); +void LinkRfu_Shutdown(void); void sub_800F6FC(u8 who); void sub_800F728(u8 who); bool32 IsSendingKeysToRfu(void); @@ -225,51 +225,51 @@ void sub_800E174(void); void sub_800E6D0(void); bool32 sub_8010EC0(void); bool32 sub_8010F1C(void); -bool32 sub_8011A80(void); +bool32 RfuIsErrorStatus1or2(void); bool32 IsRfuRecvQueueEmpty(void); u32 GetRfuRecvQueueLength(void); void RfuVSync(void); void sub_80111B0(bool32 a0); -u8 sub_8011A74(void); -struct GFtgtGname *sub_800F7DC(void); -void sub_8011068(u8 a0); +u8 RfuGetErrorStatus(void); +struct GFtgtGname *GetHostRFUtgtGname(void); +void UpdateGameData_GroupLockedIn(u8 a0); void sub_8011170(u32 a0); -void sub_8011A64(u8 a0, u16 a1); +void RfuSetErrorStatus(u8 a0, u16 a1); u8 sub_801048C(bool32 a0); -void sub_800DF90(struct GFtgtGname *buff1, u8 *buff2); -void sub_8010F84(u8 a0, u32 a1, u32 a2); -void sub_8011C10(u32 a0); +void LinkRfu3_SetGnameUnameFromStaticBuffers(struct GFtgtGname *buff1, u8 *buff2); +void SetHostRFUtgtGname(u8 a0, u32 a1, u32 a2); +void InitializeRfuLinkManager_LinkLeader(u32 a0); bool32 sub_8012240(void); -void sub_800EF38(void); +void LinkRfu_StopManagerAndFinalizeSlots(void); bool32 sub_80105EC(void); -bool32 sub_801064C(u16 a0, const u8 *a1); -void sub_8010688(u8 a0, u16 a1, const u8 *a2); -u32 sub_8010714(u16 a0, const u8 *a1); -void sub_8011DC0(const u8 *a0, u16 a1); -bool8 sub_800EF1C(void); -bool32 sub_800EF58(bool32 a0); +bool32 TrainerIdAndNameStillInPartnersList(u16 a0, const u8 *a1); +void SendByteToPartnerByIdAndName(u8 a0, u16 a1, const u8 *a2); +u32 WaitSendByteToPartnerByIdAndName(u16 a0, const u8 *a1); +void RequestDisconnectSlotByTrainerNameAndId(const u8 *a0, u16 a1); +bool8 LmanAcceptSlotFlagIsNotZero(void); +bool32 WaitRfuState(bool32 a0); void DestroyWirelessStatusIndicatorSprite(void); void sub_801103C(void); -void sub_8011C5C(void); -void sub_80106D4(void); +void InitializeRfuLinkManager_JoinGroup(void); +void LinkRfuNIsend8(void); void RecordMixTrainerNames(void); -void sub_800ED10(void); -void sub_800ED28(void); -void sub_8011090(u8 a0, u32 a1, u32 a2); -void sub_8011FC8(const u8 *src, u16 trainerId); -void sub_8010FA0(bool32 a0, bool32 a1); -void sub_8010F60(void); +void LinkRfu_CreateConnectionAsParent(void); +void LinkRfu_StopManagerBeforeEnteringChat(void); +void UpdateGameDataWithActivitySpriteGendersFlag(u8 a0, u32 a1, u32 a2); +void CreateTask_RfuReconnectWithParent(const u8 *src, u16 trainerId); +void SetGnameBufferWonderFlags(bool32 a0, bool32 a1); +void ClearAndInitHostRFUtgtGname(void); void sub_8010FCC(u32 a0, u32 a1, u32 a2); -void sub_8011C84(void); +void InitializeRfuLinkManager_EnterUnionRoom(void); void sub_8012188(const u8 *name, struct GFtgtGname *structPtr, u8 a2); -bool32 sub_8011B90(void); +bool32 IsUnionRoomListenTaskActive(void); void sub_800FE50(void *a0); -bool32 sub_800E540(u16 id, u8 *name); +bool32 PlayerHasMetTrainerBefore(u16 id, u8 *name); void sub_8011DE0(u32 arg0); u8 sub_801100C(s32 a0); void sub_800EF7C(void); -bool8 sub_800DE7C(struct GFtgtGname *buff1, u8 *buff2, u8 idx); -bool8 sub_800DF34(struct GFtgtGname *buff1, u8 *buff2, u8 idx); +bool8 LinkRfu_GetNameIfCompatible(struct GFtgtGname *buff1, u8 *buff2, u8 idx); +bool8 LinkRfu_GetNameIfSerial7F7D(struct GFtgtGname *buff1, u8 *buff2, u8 idx); s32 sub_800E87C(u8 idx); void sub_8011BA4(void); void sub_8010198(void); @@ -325,9 +325,6 @@ void PkmnStrToASCII(u8 *q1, const u8 *q2); void ASCIIToPkmnStr(u8 *q1, const u8 *q2); u8 sub_800DD1C(u8 maxFlags); void sub_800DD94(struct GFtgtGname *data, u8 r9, bool32 r2, s32 r3); -bool8 sub_800DE7C(struct GFtgtGname *buff1, u8 *buff2, u8 idx); -bool8 sub_800DF34(struct GFtgtGname *buff1, u8 *buff2, u8 idx); -void sub_800DF90(struct GFtgtGname *buff1, u8 *buff2); void CreateWirelessStatusIndicatorSprite(u8 x, u8 y); void DestroyWirelessStatusIndicatorSprite(void); void LoadWirelessStatusIndicatorSpriteGfx(void); @@ -337,7 +334,6 @@ void sub_800E174(void); void CopyTrainerRecord(struct TrainerNameRecord *dest, u32 trainerId, const u8 *name); bool32 NameIsNotEmpty(const u8 *name); void RecordMixTrainerNames(void); -bool32 sub_800E540(u16 id, u8 *name); void WipeTrainerNameRecords(void); #endif //GUARD_LINK_RFU_H diff --git a/include/menu.h b/include/menu.h index d4a0389201..4a19f55b0f 100644 --- a/include/menu.h +++ b/include/menu.h @@ -79,7 +79,7 @@ void sub_8198DBC(u8 windowId, u8 fontId, u8 left, u8 top, u8 a4, u8 itemCount, u u8 sub_8199944(u8 windowId, u8 optionWidth, u8 columns, u8 rows, u8 initialCursorPos); u8 sub_8199134(s8, s8); u8 GetStartMenuWindowId(void); -void sub_819A2BC(u8, u8); +void ListMenuLoadStdPalAt(u8, u8); u8 Menu_MoveCursor(s8 cursorDelta); u8 Menu_MoveCursorNoWrapAround(s8 cursorDelta); void DrawStdWindowFrame(u8 windowId, bool8 CopyToVram); diff --git a/include/mevent.h b/include/mevent.h index a34ca355c9..8c0ebbad7c 100755 --- a/include/mevent.h +++ b/include/mevent.h @@ -57,7 +57,7 @@ u32 sub_801B708(const u16 *a0, const struct MEventStruct_Unk1442CC *a1, const vo bool32 MEventStruct_Unk1442CC_CompareField_unk_16(const struct MEventStruct_Unk1442CC *a0, const u16 *a1); u16 MEventStruct_Unk1442CC_GetValueNFrom_unk_20(const struct MEventStruct_Unk1442CC *a0, u32 command); u16 mevent_081445C0(u32 command); -void sub_801B940(void); -bool32 sub_801B94C(u16 a0); +void ResetReceivedWonderCardFlag(void); +bool32 MEventHandleReceivedWonderCard(u16 a0); #endif //GUARD_MEVENT_H diff --git a/include/mystery_gift.h b/include/mystery_gift.h index 243895a673..fb0414ee06 100644 --- a/include/mystery_gift.h +++ b/include/mystery_gift.h @@ -12,5 +12,7 @@ bool32 MG_PrintTextOnWindow1AndWaitButton(u8 *textState, const u8 *str); void AddTextPrinterToWindow1(const u8 *src); void c2_ereader(void); void c2_mystery_gift(void); +void MG_DrawTextBorder(u8 windowId); +s8 mevent_message_print_and_prompt_yes_no(u8 *textState, u16 *windowId, bool8 yesNoBoxPlacement, const u8 *str); #endif //GUARD_MYSTERY_GIFT_H diff --git a/include/pokemon_jump.h b/include/pokemon_jump.h index 9cf65212f2..91733b3853 100644 --- a/include/pokemon_jump.h +++ b/include/pokemon_jump.h @@ -3,7 +3,7 @@ #include "main.h" -void sub_802A9A8(u16 monId, MainCallback callback); +void StartPokemonJump(u16 monId, MainCallback callback); bool32 IsSpeciesAllowedInPokemonJump(u16 species); void IsPokemonJumpSpeciesInParty(void); void ResetPokeJumpResults(void); diff --git a/include/union_room.h b/include/union_room.h index 4c4cb5a623..0f00753449 100644 --- a/include/union_room.h +++ b/include/union_room.h @@ -5,23 +5,23 @@ // Exported type declarations -struct UnkStruct_Shared +struct WirelessGnameUnamePair { - struct GFtgtGname field_0; + struct GFtgtGname gname; u8 ALIGNED(4) playerName[PLAYER_NAME_LENGTH + 1]; }; -struct UnkStruct_x1C +struct UnkStruct_x1C // WirelessLink_Member? { - struct UnkStruct_Shared unk0; - u8 unk18:1; + struct WirelessGnameUnamePair gname_uname; + u8 active:1; }; -struct UnkStruct_x20 +struct UnkStruct_x20 // WirelessLink_Member? { - struct UnkStruct_Shared unk; + struct WirelessGnameUnamePair gname_uname; u16 field_18; - u8 field_1A_0:2; + u8 groupScheduledAnim:2; u8 field_1A_1:1; u8 field_1B; u8 field_1D; @@ -44,29 +44,28 @@ struct UnkStruct_Main8 struct UnkStruct_x20 arr[5]; }; -struct UnkStruct_Leader +struct WirelessLink_Leader { struct UnkStruct_Main0 *field_0; struct UnkStruct_Main4 *field_4; struct UnkStruct_Main8 *field_8; u8 state; u8 textState; - u8 field_E; + u8 delayTimerAfterOk; u8 listWindowId; - u8 field_10; - u8 field_11; + u8 bButtonCancelWindowId; + u8 nPlayerModeWindowId; u8 listTaskId; - u8 field_13; - u8 field_14; - u8 field_15; + u8 playerCount; + u16 field_14; u8 field_16; - u8 field_17; - u8 field_18; + u8 listenTaskId; + u8 activity; u8 field_19; u16 field_1A; }; -struct UnkStruct_Group +struct WirelessLink_Group { struct UnkStruct_Main0 *field_0; struct UnkStruct_Main4 *field_4; @@ -74,16 +73,16 @@ struct UnkStruct_Group u8 textState; u8 field_A; u8 listWindowId; - u8 field_C; - u8 field_D; + u8 bButtonCancelWindowId; + u8 playerNameAndIdWindowId; u8 listTaskId; - u8 field_F; + u8 leaderId; u8 field_10; - u8 field_11; - u8 field_12; + u8 listenTaskId; + u8 isWonderNews; u8 field_13; - u8 field_14; - u8 field_15; + u8 refreshTimer; + u8 delayBeforePrint; }; struct UnkStruct_8019BA8 @@ -94,7 +93,7 @@ struct UnkStruct_8019BA8 u8 field_3; }; -struct UnkStruct_URoom +struct WirelessLink_URoom { struct UnkStruct_Main0 *field_0; struct UnkStruct_Main4 *field_4; @@ -109,30 +108,30 @@ struct UnkStruct_URoom u8 field_18; u8 field_19; u8 field_1A; - u8 field_1B; - u8 field_1C; - u8 field_1D; - u8 field_1E; + u8 topListMenuWindowId; + u8 topListMenuId; + u8 tradeBoardSelectWindowId; + u8 tradeBoardDetailsWindowId; u8 field_1F; u8 field_20; u8 spriteIds[40]; u8 field_49; u8 field_4A; - u16 field_4C[6]; - u8 field_58[0x98 - 0x58]; - u16 field_98; - u16 field_9A[3]; + u16 playerSendBuffer[6]; + u8 activityRequestStrbufs[4][16]; + u16 partnerYesNoResponse; + u16 recvActivityRequest[3]; struct UnkStruct_8019BA8 field_A0[8]; u8 field_C0[12][15]; u8 field_174[48]; u8 field_1A4[200]; }; -union UnkUnion_Main +union WirelessLink_Main { - struct UnkStruct_Leader *leader; - struct UnkStruct_Group *group; - struct UnkStruct_URoom *uRoom; + struct WirelessLink_Leader *leader; + struct WirelessLink_Group *group; + struct WirelessLink_URoom *uRoom; }; struct UnionRoomTrade @@ -152,20 +151,22 @@ struct UnionRoomTrade // Exported RAM declarations -extern u8 gUnknown_02022C2C; -extern union UnkUnion_Main gUnknown_02022C30; -extern struct GFtgtGnameSub gUnknown_02022C38; +extern u8 gPlayerCurrActivity; +extern union WirelessLink_Main gUnknown_02022C30; +extern struct GFtgtGnameSub gPartnerTgtGnameSub; extern u16 gUnionRoomOfferedSpecies; extern u8 gUnionRoomRequestedMonType; // Exported ROM declarations -u8 sub_8013F78(void); +u8 CreateTask_ReturnFromLinkTrade(void); void nullsub_89(u8 taskId); void var_800D_set_xB(void); void MEvent_CreateTask_CardOrNewsWithFriend(u32 arg0); void MEvent_CreateTask_CardOrNewsOverWireless(u32 arg0); void MEvent_CreateTask_Leader(u32 arg0); +u8 CreateTask_ListenToWireless(void); +void StartUnionRoomBattle(u16 battleFlags); #endif //GUARD_UNION_ROOM_H diff --git a/include/union_room_battle.h b/include/union_room_battle.h index 2f50860085..ffccf197f3 100644 --- a/include/union_room_battle.h +++ b/include/union_room_battle.h @@ -1,7 +1,6 @@ #ifndef GUARD_UNION_ROOM_BATTLE_H #define GUARD_UNION_ROOM_BATTLE_H -u8 sub_8013C40(void); -void sub_8014210(u16 battleFlags); +void CB2_UnionRoomBattle(void); #endif //GUARD_UNION_ROOM_BATTLE_H diff --git a/include/union_room_chat.h b/include/union_room_chat.h index e7ca9d46ec..3dd22743a1 100755 --- a/include/union_room_chat.h +++ b/include/union_room_chat.h @@ -12,7 +12,7 @@ enum #define UNION_ROOM_KB_ROW_COUNT 10 -void sub_801DD98(void); +void EnterUnionRoomChat(void); void copy_strings_to_sav1(void); #endif // GUARD_UNION_ROOM_CHAT_H diff --git a/include/union_room_player_avatar.h b/include/union_room_player_avatar.h index 9870d09811..698fc1693b 100644 --- a/include/union_room_player_avatar.h +++ b/include/union_room_player_avatar.h @@ -3,12 +3,12 @@ u8 sub_8019BA8(struct UnkStruct_8019BA8 * ptr); void sub_8019E3C(void); -void sub_8019E70(u8 *arg0, s32 arg1); -void sub_8019F04(u8 *spriteIds); +void CreateGroupMemberObjectsInvisible(u8 *arg0, s32 arg1); +void DestroyGroupMemberObjects(u8 *spriteIds); void sub_8019F2C(void); -void sub_801A274(struct UnkStruct_URoom *arg0); -void sub_801A284(struct UnkStruct_URoom *arg0); -bool32 sub_801A2A8(struct UnkStruct_Main0 *arg0, s16 *arg1, s16 *arg2, u8 *arg3); -void sub_801A3D0(u32 arg0, u32 arg1, struct UnkStruct_Main0 *arg2); +void ScheduleUnionRoomPlayerRefresh(struct WirelessLink_URoom *arg0); +void HandleUnionRoomPlayerRefresh(struct WirelessLink_URoom *arg0); +bool32 RfuUnionTool_GetGroupAndMemberInFrontOfPlayer(struct UnkStruct_Main0 *arg0, s16 *arg1, s16 *arg2, u8 *arg3); +void UpdateUnionGroupMemberFacing(u32 arg0, u32 arg1, struct UnkStruct_Main0 *arg2); #endif //GUARD_UNION_ROOM_PLAYER_AVATAR_H diff --git a/src/battle_controllers.c b/src/battle_controllers.c index b411c12f67..43bd9fce60 100644 --- a/src/battle_controllers.c +++ b/src/battle_controllers.c @@ -33,7 +33,7 @@ void HandleLinkBattleSetup(void) if (gBattleTypeFlags & BATTLE_TYPE_LINK) { if (gWirelessCommType) - sub_800B488(); + SetWirelessCommType1(); if (!gReceivedRemoteLinkPlayers) OpenLink(); CreateTask(task00_08081A90, 0); diff --git a/src/berry_crush.c b/src/berry_crush.c index 383d273c4f..3ff3156e6b 100755 --- a/src/berry_crush.c +++ b/src/berry_crush.c @@ -832,7 +832,7 @@ u32 sub_8020C0C(MainCallback callback) return 0; } -void sub_8020C70(MainCallback callback) +void StartBerryCrush(MainCallback callback) { u8 playerCount = 0; u8 multiplayerId; diff --git a/src/cable_club.c b/src/cable_club.c index c2ac728838..2a53c64b24 100644 --- a/src/cable_club.c +++ b/src/cable_club.c @@ -849,7 +849,7 @@ static void sub_80B32B4(u8 taskId) CleanupOverworldWindowsAndTilemaps(); gTrainerBattleOpponent_A = 0x800; SetMainCallback2(CB2_InitBattle); - gMain.savedCallback = sub_80B360C; + gMain.savedCallback = CB2_ReturnFromCableClubBattle; DestroyTask(taskId); break; } @@ -915,7 +915,7 @@ static void sub_80B33BC(u8 taskId) CleanupOverworldWindowsAndTilemaps(); gTrainerBattleOpponent_A = 0x800; SetMainCallback2(CB2_InitBattle); - gMain.savedCallback = sub_80B360C; + gMain.savedCallback = CB2_ReturnFromCableClubBattle; DestroyTask(taskId); break; } @@ -965,7 +965,7 @@ static void sub_80B3554(void) RunTasks(); } -void sub_80B360C(void) +void CB2_ReturnFromCableClubBattle(void) { gBattleTypeFlags &= ~BATTLE_TYPE_20; Overworld_ResetMapMusic(); @@ -1129,7 +1129,7 @@ static void sub_80B3894(u8 taskId) case 3: if (IsLinkTaskFinished()) { - sub_8013F78(); + CreateTask_ReturnFromLinkTrade(); DestroyTask(taskId); } break; diff --git a/src/data/union_room.h b/src/data/union_room.h index 8cb0bc8aa2..0433009126 100644 --- a/src/data/union_room.h +++ b/src/data/union_room.h @@ -50,27 +50,36 @@ const u8 sText_4PlayerMode[] = _("4-PLAYER\nMODE"); const u8 sText_5PlayerMode[] = _("5-PLAYER\nMODE"); static const u8 *const sPlayersNeededOrModeTexts[][5] = { + // 2 players required { sText_1PlayerNeeded, sText_2PlayerMode - }, { + }, + // 4 players required + { sText_3PlayersNeeded, sText_2PlayersNeeded, sText_1PlayerNeeded, sText_4PlayerMode - }, { + }, + // 2-5 players required + { sText_1PlayerNeeded, sText_2PlayerMode, sText_3PlayerMode, sText_4PlayerMode, sText_5PlayerMode - }, { + }, + // 3-5 players required + { sText_2PlayersNeeded, sText_1PlayerNeeded, sText_3PlayerMode, sText_4PlayerMode, sText_5PlayerMode - }, { + }, + // 2-4 players required + { sText_1PlayerNeeded, sText_2PlayerMode, sText_3PlayerMode, @@ -484,8 +493,8 @@ static const u8 *const sChooseTrainerTexts[NUM_LINK_GROUP_TYPES] = [LINK_GROUP_BERRY_PICKING] = sText_ChooseLeaderBerryPicking, [LINK_GROUP_WONDER_CARD] = sText_ChooseTrainerToShareWonderCards, [LINK_GROUP_WONDER_NEWS] = sText_ChooseTrainerToShareWonderNews, - [LINK_GROUP_UNK_9] = NULL, - [LINK_GROUP_UNK_10] = NULL, + [LINK_GROUP_UNION_ROOM_RESUME] = NULL, + [LINK_GROUP_UNION_ROOM_INIT] = NULL, [LINK_GROUP_UNK_11] = NULL, [LINK_GROUP_RECORD_CORNER] = sText_ChooseLeaderRecordCorner, [LINK_GROUP_BERRY_BLENDER] = sText_ChooseLeaderBerryBlender, @@ -599,7 +608,7 @@ const u8 *const sLinkGroupActivityTexts[] = { sText_BattleTowerLv50 }; -const struct WindowTemplate gUnknown_082F00BC = { +static const struct WindowTemplate sWindowTemplate_BButtonCancel = { .bg = 0x00, .tilemapLeft = 0x00, .tilemapTop = 0x00, @@ -609,29 +618,33 @@ const struct WindowTemplate gUnknown_082F00BC = { .baseBlock = 0x0008 }; -const u32 gUnknown_082F00C4[NUM_LINK_GROUP_TYPES] = { - 0x0201, - 0x0202, - 0x0403, - 0x0204, - 0x2509, - 0x250a, - 0x350b, - 0x0000, - 0x0000, - 0x0000, - 0x0000, - 0x0000, - 0x240f, - 0x2410, - 0x0000, - 0x2417, - 0x2418, - 0x2419, - 0x241a, - 0x241b, - 0x021c, - 0x020e +// Minimum and maximum number of players for a link group +// A minimum of 0 means the min and max are equal +#define LINK_GROUP_CAPACITY(min, max)(((min) << 12) | ((max) << 8)) + +static const u32 sLinkGroupToActivityAndCapacity[NUM_LINK_GROUP_TYPES] = { + [LINK_GROUP_SINGLE_BATTLE] = ACTIVITY_BATTLE_SINGLE | LINK_GROUP_CAPACITY(0, 2), + [LINK_GROUP_DOUBLE_BATTLE] = ACTIVITY_BATTLE_DOUBLE | LINK_GROUP_CAPACITY(0, 2), + [LINK_GROUP_MULTI_BATTLE] = ACTIVITY_BATTLE_MULTI | LINK_GROUP_CAPACITY(0, 4), + [LINK_GROUP_TRADE] = ACTIVITY_TRADE | LINK_GROUP_CAPACITY(0, 2), + [LINK_GROUP_POKEMON_JUMP] = ACTIVITY_POKEMON_JUMP | LINK_GROUP_CAPACITY(2, 5), + [LINK_GROUP_BERRY_CRUSH] = ACTIVITY_BERRY_CRUSH | LINK_GROUP_CAPACITY(2, 5), + [LINK_GROUP_BERRY_PICKING] = ACTIVITY_BERRY_PICK | LINK_GROUP_CAPACITY(3, 5), + [LINK_GROUP_WONDER_CARD] = ACTIVITY_NONE | LINK_GROUP_CAPACITY(0, 0), + [LINK_GROUP_WONDER_NEWS] = ACTIVITY_NONE | LINK_GROUP_CAPACITY(0, 0), + [LINK_GROUP_UNION_ROOM_RESUME] = ACTIVITY_NONE | LINK_GROUP_CAPACITY(0, 0), + [LINK_GROUP_UNION_ROOM_INIT] = ACTIVITY_NONE | LINK_GROUP_CAPACITY(0, 0), + [LINK_GROUP_UNK_11] = ACTIVITY_NONE | LINK_GROUP_CAPACITY(0, 0), + [LINK_GROUP_RECORD_CORNER] = ACTIVITY_RECORD_CORNER | LINK_GROUP_CAPACITY(2, 4), + [LINK_GROUP_BERRY_BLENDER] = ACTIVITY_BERRY_BLENDER | LINK_GROUP_CAPACITY(2, 4), + [LINK_GROUP_UNK_14] = ACTIVITY_NONE | LINK_GROUP_CAPACITY(0, 0), + [LINK_GROUP_COOL_CONTEST] = ACTIVITY_CONTEST_COOL | LINK_GROUP_CAPACITY(2, 4), + [LINK_GROUP_BEAUTY_CONTEST] = ACTIVITY_CONTEST_BEAUTY | LINK_GROUP_CAPACITY(2, 4), + [LINK_GROUP_CUTE_CONTEST] = ACTIVITY_CONTEST_CUTE | LINK_GROUP_CAPACITY(2, 4), + [LINK_GROUP_SMART_CONTEST] = ACTIVITY_CONTEST_SMART | LINK_GROUP_CAPACITY(2, 4), + [LINK_GROUP_TOUGH_CONTEST] = ACTIVITY_CONTEST_TOUGH | LINK_GROUP_CAPACITY(2, 4), + [LINK_GROUP_BATTLE_TOWER] = ACTIVITY_BATTLE_TOWER | LINK_GROUP_CAPACITY(0, 2), + [LINK_GROUP_BATTLE_TOWER_OPEN] = ACTIVITY_BATTLE_TOWER_OPEN | LINK_GROUP_CAPACITY(0, 2) }; const struct WindowTemplate gUnknown_082F011C = { @@ -654,7 +667,7 @@ const struct WindowTemplate gUnknown_082F0124 = { .baseBlock = 0x0044 }; -const struct WindowTemplate gUnknown_082F012C = { +static const struct WindowTemplate sWindowTemplate_NumPlayerMode = { .bg = 0x00, .tilemapLeft = 0x10, .tilemapTop = 0x03, @@ -672,11 +685,11 @@ const struct ListMenuItem gUnknown_082F0134[] = { { sText_EmptyString, 4 } }; -const struct ListMenuTemplate gUnknown_082F015C = { +static const struct ListMenuTemplate sListMenuTemplate_PossibleGroupMembers = { .items = gUnknown_082F0134, .moveCursorFunc = NULL, - .itemPrintFunc = sub_8013278, - .totalItems = 5, + .itemPrintFunc = ItemPrintFunc_PossibleGroupMembers, + .totalItems = ARRAY_COUNT(gUnknown_082F0134), .maxShowed = 5, .windowId = 0, .header_X = 0, @@ -732,11 +745,11 @@ const struct ListMenuItem gUnknown_082F0184[] = { { sText_EmptyString, 15 } }; -const struct ListMenuTemplate gUnknown_082F0204 = { +static const struct ListMenuTemplate sListMenuTemplate_UnionRoomGroups = { .items = gUnknown_082F0184, .moveCursorFunc = ListMenuDefaultCursorMoveFunc, - .itemPrintFunc = sub_8013DF4, - .totalItems = 16, + .itemPrintFunc = ListMenuItemPrintFunc_UnionRoomGroups, + .totalItems = ARRAY_COUNT(gUnknown_082F0184), .maxShowed = 5, .windowId = 0, .header_X = 0, @@ -753,7 +766,7 @@ const struct ListMenuTemplate gUnknown_082F0204 = { .cursorKind = 0 }; -const struct WindowTemplate gUnknown_082F021C = { +static const struct WindowTemplate sWindowTemplate_InviteToActivity = { .bg = 0x00, .tilemapLeft = 0x14, .tilemapTop = 0x05, @@ -770,11 +783,11 @@ const struct ListMenuItem gUnknown_082F0224[] = { { sText_Exit, 0x040 } }; -const struct ListMenuTemplate gUnknown_082F0244 = { +static const struct ListMenuTemplate sListMenuTemplate_InviteToActivity = { .items = gUnknown_082F0224, .moveCursorFunc = ListMenuDefaultCursorMoveFunc, .itemPrintFunc = NULL, - .totalItems = 4, + .totalItems = ARRAY_COUNT(gUnknown_082F0224), .maxShowed = 4, .windowId = 0, .header_X = 0, @@ -811,7 +824,7 @@ const struct ListMenuTemplate gUnknown_082F027C = { .items = gUnknown_082F0264, .moveCursorFunc = ListMenuDefaultCursorMoveFunc, .itemPrintFunc = NULL, - .totalItems = 3, + .totalItems = ARRAY_COUNT(gUnknown_082F0264), .maxShowed = 3, .windowId = 0, .header_X = 0, @@ -838,7 +851,7 @@ const struct WindowTemplate gUnknown_082F0294 = { .baseBlock = 0x0001 }; -static const struct ListMenuItem sTradingBoardTypes[] = { +static const struct ListMenuItem sTradingBoardTypes[NUMBER_OF_MON_TYPES] = { { gTypeNames[TYPE_NORMAL], TYPE_NORMAL }, { gTypeNames[TYPE_FIRE], TYPE_FIRE }, { gTypeNames[TYPE_WATER], TYPE_WATER }, @@ -856,14 +869,14 @@ static const struct ListMenuItem sTradingBoardTypes[] = { { gTypeNames[TYPE_DRAGON], TYPE_DRAGON }, { gTypeNames[TYPE_STEEL], TYPE_STEEL }, { gTypeNames[TYPE_DARK], TYPE_DARK }, - { sText_Exit, NUMBER_OF_MON_TYPES } + { sText_Exit, NUMBER_OF_MON_TYPES } }; const struct ListMenuTemplate sMenuTemplate_TradingBoardRequestType = { .items = sTradingBoardTypes, .moveCursorFunc = ListMenuDefaultCursorMoveFunc, .itemPrintFunc = NULL, - .totalItems = NUMBER_OF_MON_TYPES, + .totalItems = ARRAY_COUNT(sTradingBoardTypes), .maxShowed = 6, .windowId = 0, .header_X = 0, @@ -900,7 +913,7 @@ const struct WindowTemplate gUnknown_082F034C = { .baseBlock = 0x0039 }; -const struct ListMenuItem gUnknown_082F0354[] = { +static const struct ListMenuItem sTradeBoardListMenuItems[] = { { sText_EmptyString, -3 }, { sText_EmptyString, 0 }, { sText_EmptyString, 1 }, @@ -913,11 +926,11 @@ const struct ListMenuItem gUnknown_082F0354[] = { { sText_Exit2, 8 } }; -const struct ListMenuTemplate gUnknown_082F03A4 = { - .items = gUnknown_082F0354, +static const struct ListMenuTemplate sTradeBoardListMenuTemplate = { + .items = sTradeBoardListMenuItems, .moveCursorFunc = ListMenuDefaultCursorMoveFunc, - .itemPrintFunc = sub_8017BE8, - .totalItems = 10, + .itemPrintFunc = TradeBoardListMenuItemPrintFunc, + .totalItems = ARRAY_COUNT(sTradeBoardListMenuItems), .maxShowed = 6, .windowId = 0, .header_X = 0, @@ -944,7 +957,7 @@ const struct WindowTemplate UnrefWindowTemplate_082F03B4 = { .baseBlock = 0x0039 }; -const struct ListMenuItem gUnknown_082F03C4[] = { +static const struct ListMenuItem sEmptyListMenuItems[] = { { sText_EmptyString, 0 }, { sText_EmptyString, 1 }, { sText_EmptyString, 2 }, @@ -963,11 +976,12 @@ const struct ListMenuItem gUnknown_082F03C4[] = { { sText_EmptyString, 15 } }; -const struct ListMenuTemplate UnrefListMenuTemplate_082F0444 = { - .items = gUnknown_082F03C4, +// Unused +static const struct ListMenuTemplate sUnknownListMenuTemplate = { + .items = sEmptyListMenuItems, .moveCursorFunc = ListMenuDefaultCursorMoveFunc, .itemPrintFunc = nullsub_14, - .totalItems = 16, + .totalItems = ARRAY_COUNT(sEmptyListMenuItems), .maxShowed = 4, .windowId = 0, .header_X = 0, @@ -984,78 +998,100 @@ const struct ListMenuTemplate UnrefListMenuTemplate_082F0444 = { .cursorKind = 0 }; -const struct UnkStruct_Shared gUnknown_082F045C = {0}; +const struct WirelessGnameUnamePair sWirelessGnameUnamePair_Dummy = {0}; -ALIGNED(4) const u8 gUnknown_082F0474[] = {0x01, 0xff}; -ALIGNED(4) const u8 gUnknown_082F0478[] = {0x02, 0xff}; -ALIGNED(4) const u8 gUnknown_082F047C[] = {0x03, 0xff}; -ALIGNED(4) const u8 gUnknown_082F0480[] = {0x04, 0xff}; -ALIGNED(4) const u8 gUnknown_082F0484[] = {0x09, 0xff}; -ALIGNED(4) const u8 gUnknown_082F0488[] = {0x0a, 0xff}; -ALIGNED(4) const u8 gUnknown_082F048C[] = {0x0b, 0xff}; -ALIGNED(4) const u8 gUnknown_082F0490[] = {0x15, 0xff}; -ALIGNED(4) const u8 gUnknown_082F0494[] = {0x16, 0xff}; -ALIGNED(4) const u8 gUnknown_082F0498[] = {0x40, 0x41, 0x44, 0x45, 0x48, 0x51, 0x52, 0x53, 0x54, 0xff}; -ALIGNED(4) const u8 gUnknown_082F04A4[] = {0x0c, 0xff}; -ALIGNED(4) const u8 gUnknown_082F04A8[] = {0x01, 0x02, 0x03, 0x04, 0x09, 0x0a, 0x0b, 0x15, 0x16, 0x0d, 0xff}; -ALIGNED(4) const u8 gUnknown_082F04B4[] = {0x0f, 0xff}; -ALIGNED(4) const u8 gUnknown_082F04B8[] = {0x10, 0xff}; -ALIGNED(4) const u8 gUnknown_082F04BC[] = {0x17, 0xff}; -ALIGNED(4) const u8 gUnknown_082F04C0[] = {0x18, 0xff}; -ALIGNED(4) const u8 gUnknown_082F04C4[] = {0x19, 0xff}; -ALIGNED(4) const u8 gUnknown_082F04C8[] = {0x1a, 0xff}; -ALIGNED(4) const u8 gUnknown_082F04CC[] = {0x1b, 0xff}; -ALIGNED(4) const u8 gUnknown_082F04D0[] = {0x1c, 0xff}; -ALIGNED(4) const u8 gUnknown_082F04D4[] = {0x0e, 0xff}; +ALIGNED(4) const u8 sAcceptedActivityIds_SingleBattle[] = {ACTIVITY_BATTLE_SINGLE, 0xff}; +ALIGNED(4) const u8 sAcceptedActivityIds_DoubleBattle[] = {ACTIVITY_BATTLE_DOUBLE, 0xff}; +ALIGNED(4) const u8 sAcceptedActivityIds_MultiBattle[] = {ACTIVITY_BATTLE_MULTI, 0xff}; +ALIGNED(4) const u8 sAcceptedActivityIds_Trade[] = {ACTIVITY_TRADE, 0xff}; +ALIGNED(4) const u8 sAcceptedActivityIds_PokemonJump[] = {ACTIVITY_POKEMON_JUMP, 0xff}; +ALIGNED(4) const u8 sAcceptedActivityIds_BerryCrush[] = {ACTIVITY_BERRY_CRUSH, 0xff}; +ALIGNED(4) const u8 sAcceptedActivityIds_BerryPicking[] = {ACTIVITY_BERRY_PICK, 0xff}; +ALIGNED(4) const u8 sAcceptedActivityIds_WonderCard[] = {ACTIVITY_WONDER_CARD2, 0xff}; +ALIGNED(4) const u8 sAcceptedActivityIds_WonderNews[] = {ACTIVITY_WONDER_NEWS2, 0xff}; +ALIGNED(4) const u8 sAcceptedActivityIds_Resume[] = { + IN_UNION_ROOM | ACTIVITY_NONE, + IN_UNION_ROOM | ACTIVITY_BATTLE_SINGLE, + IN_UNION_ROOM | ACTIVITY_TRADE, + IN_UNION_ROOM | ACTIVITY_CHAT, + IN_UNION_ROOM | ACTIVITY_CARD, + IN_UNION_ROOM | ACTIVITY_ACCEPT, + IN_UNION_ROOM | ACTIVITY_DECLINE, + IN_UNION_ROOM | ACTIVITY_NPCTALK, + IN_UNION_ROOM | ACTIVITY_PLYRTALK, + 0xff +}; +ALIGNED(4) const u8 sAcceptedActivityIds_Init[] = {ACTIVITY_SEARCH, 0xff}; +ALIGNED(4) const u8 sAcceptedActivityIds_Unk11[] = { + ACTIVITY_BATTLE_SINGLE, + ACTIVITY_BATTLE_DOUBLE, + ACTIVITY_BATTLE_MULTI, + ACTIVITY_TRADE, + ACTIVITY_POKEMON_JUMP, + ACTIVITY_BERRY_CRUSH, + ACTIVITY_BERRY_PICK, + ACTIVITY_WONDER_CARD2, + ACTIVITY_WONDER_NEWS2, + ACTIVITY_SPIN_TRADE, + 0xff +}; +ALIGNED(4) const u8 sAcceptedActivityIds_RecordCorner[] = {ACTIVITY_RECORD_CORNER, 0xff}; +ALIGNED(4) const u8 sAcceptedActivityIds_BerryBlender[] = {ACTIVITY_BERRY_BLENDER, 0xff}; +ALIGNED(4) const u8 sAcceptedActivityIds_CoolContest[] = {ACTIVITY_CONTEST_COOL, 0xff}; +ALIGNED(4) const u8 sAcceptedActivityIds_BeautyContest[] = {ACTIVITY_CONTEST_BEAUTY, 0xff}; +ALIGNED(4) const u8 sAcceptedActivityIds_CuteContest[] = {ACTIVITY_CONTEST_CUTE, 0xff}; +ALIGNED(4) const u8 sAcceptedActivityIds_SmartContest[] = {ACTIVITY_CONTEST_SMART, 0xff}; +ALIGNED(4) const u8 sAcceptedActivityIds_ToughContest[] = {ACTIVITY_CONTEST_TOUGH, 0xff}; +ALIGNED(4) const u8 sAcceptedActivityIds_BattleTower[] = {ACTIVITY_BATTLE_TOWER, 0xff}; +ALIGNED(4) const u8 sAcceptedActivityIds_BattleTowerOpen[] = {ACTIVITY_BATTLE_TOWER_OPEN, 0xff}; -const u8 *const gUnknown_082F04D8[NUM_LINK_GROUP_TYPES] = { - gUnknown_082F0474, - gUnknown_082F0478, - gUnknown_082F047C, - gUnknown_082F0480, - gUnknown_082F0484, - gUnknown_082F0488, - gUnknown_082F048C, - gUnknown_082F0490, - gUnknown_082F0494, - gUnknown_082F0498, - gUnknown_082F04A4, - gUnknown_082F04A8, - gUnknown_082F04B4, - gUnknown_082F04B8, - NULL, - gUnknown_082F04BC, - gUnknown_082F04C0, - gUnknown_082F04C4, - gUnknown_082F04C8, - gUnknown_082F04CC, - gUnknown_082F04D0, - gUnknown_082F04D4 +const u8 *const sAcceptedActivityIds[NUM_LINK_GROUP_TYPES] = { + [LINK_GROUP_SINGLE_BATTLE] = sAcceptedActivityIds_SingleBattle, + [LINK_GROUP_DOUBLE_BATTLE] = sAcceptedActivityIds_DoubleBattle, + [LINK_GROUP_MULTI_BATTLE] = sAcceptedActivityIds_MultiBattle, + [LINK_GROUP_TRADE] = sAcceptedActivityIds_Trade, + [LINK_GROUP_POKEMON_JUMP] = sAcceptedActivityIds_PokemonJump, + [LINK_GROUP_BERRY_CRUSH] = sAcceptedActivityIds_BerryCrush, + [LINK_GROUP_BERRY_PICKING] = sAcceptedActivityIds_BerryPicking, + [LINK_GROUP_WONDER_CARD] = sAcceptedActivityIds_WonderCard, + [LINK_GROUP_WONDER_NEWS] = sAcceptedActivityIds_WonderNews, + [LINK_GROUP_UNION_ROOM_RESUME] = sAcceptedActivityIds_Resume, + [LINK_GROUP_UNION_ROOM_INIT] = sAcceptedActivityIds_Init, + [LINK_GROUP_UNK_11] = sAcceptedActivityIds_Unk11, + [LINK_GROUP_RECORD_CORNER] = sAcceptedActivityIds_RecordCorner, + [LINK_GROUP_BERRY_BLENDER] = sAcceptedActivityIds_BerryBlender, + [LINK_GROUP_UNK_14] = NULL, + [LINK_GROUP_COOL_CONTEST] = sAcceptedActivityIds_CoolContest, + [LINK_GROUP_BEAUTY_CONTEST] = sAcceptedActivityIds_BeautyContest, + [LINK_GROUP_CUTE_CONTEST] = sAcceptedActivityIds_CuteContest, + [LINK_GROUP_SMART_CONTEST] = sAcceptedActivityIds_SmartContest, + [LINK_GROUP_TOUGH_CONTEST] = sAcceptedActivityIds_ToughContest, + [LINK_GROUP_BATTLE_TOWER] = sAcceptedActivityIds_BattleTower, + [LINK_GROUP_BATTLE_TOWER_OPEN] = sAcceptedActivityIds_BattleTowerOpen }; -// Link group type to ID for gUnknown_02022C2C -const u8 gUnknown_082F0530[NUM_LINK_GROUP_TYPES + 2] = +static const u8 sLinkGroupToURoomActivity[NUM_LINK_GROUP_TYPES + 2] = { - 0x01, - 0x02, - 0x03, - 0x04, - 0x09, - 0x0a, - 0x0b, - 0x15, - 0x16, - 0x00, - 0x00, - 0x00, - 0x0f, - 0x10, - 0x00, - 0x17, - 0x18, - 0x19, - 0x1a, - 0x1b, - 0x1c, - 0x0e + [LINK_GROUP_SINGLE_BATTLE] = ACTIVITY_BATTLE_SINGLE, + [LINK_GROUP_DOUBLE_BATTLE] = ACTIVITY_BATTLE_DOUBLE, + [LINK_GROUP_MULTI_BATTLE] = ACTIVITY_BATTLE_MULTI, + [LINK_GROUP_TRADE] = ACTIVITY_TRADE, + [LINK_GROUP_POKEMON_JUMP] = ACTIVITY_POKEMON_JUMP, + [LINK_GROUP_BERRY_CRUSH] = ACTIVITY_BERRY_CRUSH, + [LINK_GROUP_BERRY_PICKING] = ACTIVITY_BERRY_PICK, + [LINK_GROUP_WONDER_CARD] = ACTIVITY_WONDER_CARD2, + [LINK_GROUP_WONDER_NEWS] = ACTIVITY_WONDER_NEWS2, + [LINK_GROUP_UNION_ROOM_RESUME] = ACTIVITY_NONE, + [LINK_GROUP_UNION_ROOM_INIT] = ACTIVITY_NONE, + [LINK_GROUP_UNK_11] = ACTIVITY_NONE, + [LINK_GROUP_RECORD_CORNER] = ACTIVITY_RECORD_CORNER, + [LINK_GROUP_BERRY_BLENDER] = ACTIVITY_BERRY_BLENDER, + [LINK_GROUP_UNK_14] = ACTIVITY_NONE, + [LINK_GROUP_COOL_CONTEST] = ACTIVITY_CONTEST_COOL, + [LINK_GROUP_BEAUTY_CONTEST] = ACTIVITY_CONTEST_BEAUTY, + [LINK_GROUP_CUTE_CONTEST] = ACTIVITY_CONTEST_CUTE, + [LINK_GROUP_SMART_CONTEST] = ACTIVITY_CONTEST_SMART, + [LINK_GROUP_TOUGH_CONTEST] = ACTIVITY_CONTEST_TOUGH, + [LINK_GROUP_BATTLE_TOWER] = ACTIVITY_BATTLE_TOWER, + [LINK_GROUP_BATTLE_TOWER_OPEN] = ACTIVITY_BATTLE_TOWER_OPEN }; diff --git a/src/dodrio_berry_picking.c b/src/dodrio_berry_picking.c index 936c1828fc..1eaedfd64d 100644 --- a/src/dodrio_berry_picking.c +++ b/src/dodrio_berry_picking.c @@ -450,7 +450,7 @@ static void (*const gUnknown_082F7AF4[])(void) = }; // code -void sub_802493C(u16 a0, void (*callback)(void)) +void StartDodrioBerryPicking(u16 a0, void (*callback)(void)) { gUnknown_03000DB0 = FALSE; diff --git a/src/event_object_lock.c b/src/event_object_lock.c index b728f7774a..67652a99b3 100644 --- a/src/event_object_lock.c +++ b/src/event_object_lock.c @@ -96,7 +96,7 @@ void ScriptUnfreezeObjectEvents(void) UnfreezeObjectEvents(); } -void sub_8098524(void) +void UnionRoom_UnlockPlayerAndChatPartner(void) { u8 playerObjectId; diff --git a/src/item_menu.c b/src/item_menu.c index fe381516c2..274b92147f 100755 --- a/src/item_menu.c +++ b/src/item_menu.c @@ -2290,7 +2290,7 @@ void SetupBagMenu_Textboxes(void) DeactivateAllTextPrinters(); LoadUserWindowBorderGfx(0, 1, 0xE0); LoadMessageBoxGfx(0, 10, 0xD0); - sub_819A2BC(0xC0, 1); + ListMenuLoadStdPalAt(0xC0, 1); LoadPalette(&gUnknown_0860F074, 0xF0, 0x20); for (i = 0; i < 3; i++) { diff --git a/src/link.c b/src/link.c index 34c9ee7ef5..abd9715dda 100644 --- a/src/link.c +++ b/src/link.c @@ -221,7 +221,7 @@ static const u8 sUnused_082ED224[] = {0x00, 0xff, 0xfe, 0xff, 0x00}; bool8 IsWirelessAdapterConnected(void) { - sub_800B488(); + SetWirelessCommType1(); sub_800E700(); if (rfu_LMAN_REQBN_softReset_and_checkID() == 0x8001) { @@ -389,7 +389,7 @@ void CloseLink(void) gReceivedRemoteLinkPlayers = FALSE; if (gWirelessCommType) { - sub_800EDD4(); + LinkRfu_Shutdown(); } gLinkOpen = FALSE; DisableSerial(); @@ -1860,7 +1860,7 @@ bool8 HandleLinkConnection(void) return FALSE; } -void sub_800B488(void) +void SetWirelessCommType1(void) { if (gReceivedRemoteLinkPlayers == 0) { diff --git a/src/link_rfu_2.c b/src/link_rfu_2.c index 3ee193ec64..e13e0d4e1a 100644 --- a/src/link_rfu_2.c +++ b/src/link_rfu_2.c @@ -375,11 +375,11 @@ void sub_800EAFC(void) void sub_800EB44(u8 taskId) { - if (sub_800F7DC()->activity == 0x54 && sub_8011A74() == 4) + if (GetHostRFUtgtGname()->activity == 0x54 && RfuGetErrorStatus() == 4) { rfu_REQ_disconnect(lman.acceptSlot_flag); rfu_waitREQComplete(); - sub_8011A64(0, 0); + RfuSetErrorStatus(0, 0); } switch (Rfu.unk_04) { @@ -421,7 +421,7 @@ void sub_800EB44(u8 taskId) case 16: Rfu.unk_cdb = 0; rfu_LMAN_setMSCCallback(sub_800EDBC); - sub_8011068(1); + UpdateGameData_GroupLockedIn(TRUE); sub_800EAB4(); sub_800EAFC(); Rfu.unk_04 = 20; @@ -434,12 +434,12 @@ void sub_800EB44(u8 taskId) } } -void sub_800ED10(void) +void LinkRfu_CreateConnectionAsParent(void) { rfu_LMAN_establishConnection(1, 0, 240, (u16 *)gUnknown_082ED6E0); } -void sub_800ED28(void) +void LinkRfu_StopManagerBeforeEnteringChat(void) { rfu_LMAN_stopManager(FALSE); } @@ -471,7 +471,7 @@ void sub_800EDBC(u16 unused) Rfu.unk_cdb = 1; } -void sub_800EDD4(void) +void LinkRfu_Shutdown(void) { u8 i; @@ -538,7 +538,7 @@ void sub_800EF00(void) Rfu.unk_67 = CreateTask(sub_800E94C, 1); } -bool8 sub_800EF1C(void) +bool8 LmanAcceptSlotFlagIsNotZero(void) { if (lman.acceptSlot_flag) { @@ -547,13 +547,13 @@ bool8 sub_800EF1C(void) return FALSE; } -void sub_800EF38(void) +void LinkRfu_StopManagerAndFinalizeSlots(void) { Rfu.unk_04 = 4; Rfu.unk_ce7 = lman.acceptSlot_flag; } -bool32 sub_800EF58(bool32 a0) +bool32 WaitRfuState(bool32 a0) { if (Rfu.unk_04 == 17 || a0) { @@ -676,13 +676,13 @@ bool32 sub_800F0F8(void) Rfu.unk_ce3 = 0; if (Rfu.unk_ce4 == 1) { - sub_8011A64(2, 0x8000); + RfuSetErrorStatus(2, 0x8000); sub_8011170(0x8000); return FALSE; } if (!lman.acceptSlot_flag) { - sub_800EDD4(); + LinkRfu_Shutdown(); gReceivedRemoteLinkPlayers = 0; return FALSE; } @@ -831,15 +831,15 @@ bool32 sub_800F4F0(void) { rfu_REQ_disconnect(gRfuLinkStatus->connSlotFlag | gRfuLinkStatus->linkLossSlotFlag); rfu_waitREQComplete(); - switchval = sub_8011A74(); + switchval = RfuGetErrorStatus(); if (switchval != 1 && switchval != 6 && switchval != 9) - sub_8011A64(2, 0x9000); + RfuSetErrorStatus(2, 0x9000); rfu_clearAllSlot(); gReceivedRemoteLinkPlayers = FALSE; Rfu.linkRfuCallback = NULL; if (Rfu.unk_ce4 == 1) { - sub_8011A64(2, 0x9000); + RfuSetErrorStatus(2, 0x9000); sub_8011170(0x9000); } lman.state = lman.next_state = 0; @@ -924,7 +924,7 @@ void rfu_func_080F97B8(void) } } -struct GFtgtGname *sub_800F7DC(void) +struct GFtgtGname *GetHostRFUtgtGname(void) { return &gUnknown_02022B14; } @@ -1000,7 +1000,7 @@ void sub_800F86C(u8 unused) { Rfu.unk_80[i].unk_12 = 2; sub_800F6FC(i); - if (sub_800F7DC()->activity == 0x45 && gReceivedRemoteLinkPlayers != 0 && Rfu.unk_0c == 0) + if (GetHostRFUtgtGname()->activity == 0x45 && gReceivedRemoteLinkPlayers != 0 && Rfu.unk_0c == 0) sub_8010A70(gBlockRecvBuffer); } } @@ -1164,7 +1164,7 @@ void sub_800FD14(u16 command) void sub_800FE50(void *a0) { - if (gSendCmd[0] == 0 && !sub_8011A80()) + if (gSendCmd[0] == 0 && !RfuIsErrorStatus1or2()) { memcpy(Rfu.unk_f2, a0, sizeof(Rfu.unk_f2)); sub_800FD14(0x2f00); @@ -1535,7 +1535,7 @@ bool32 sub_80105EC(void) return FALSE; } -bool32 sub_801064C(u16 a0, const u8 *a1) +bool32 TrainerIdAndNameStillInPartnersList(u16 a0, const u8 *a1) { u8 r1 = sub_8011CE4(a1, a0); if (r1 == 0xFF) @@ -1545,7 +1545,7 @@ bool32 sub_801064C(u16 a0, const u8 *a1) return FALSE; } -void sub_8010688(u8 a0, u16 a1, const u8 *a2) +void SendByteToPartnerByIdAndName(u8 a0, u16 a1, const u8 *a2) { u8 r4 = sub_8011CE4(a2, a1); Rfu.unk_cd1[r4] = a0; @@ -1553,14 +1553,14 @@ void sub_8010688(u8 a0, u16 a1, const u8 *a2) rfu_NI_setSendData(1 << r4, 8, Rfu.unk_cd1 + r4, 1); } -void sub_80106D4(void) +void LinkRfuNIsend8(void) { Rfu.unk_c85 = 8; rfu_clearSlot(4, Rfu.unk_c3e); rfu_NI_setSendData(1 << Rfu.unk_c3e, 8, &Rfu.unk_c85, 1); } -u32 sub_8010714(u16 a0, const u8 *a1) +u32 WaitSendByteToPartnerByIdAndName(u16 a0, const u8 *a1) { u8 r0 = sub_8011CE4(a1, a0); if (r0 == 0xFF) @@ -1597,7 +1597,7 @@ s32 sub_80107A0(void) if (gRfuSlotStatusNI[Rfu.unk_c3e]->recv.state == 0x46 || gRfuSlotStatusNI[Rfu.unk_c3e]->recv.state == 0x48) { rfu_clearSlot(8, Rfu.unk_c3e); - sub_8011A64(Rfu.unk_c86, 0); + RfuSetErrorStatus(Rfu.unk_c86, 0); retval = Rfu.unk_c86; } else if (gRfuSlotStatusNI[Rfu.unk_c3e]->recv.state == 0x47) @@ -1842,7 +1842,7 @@ void sub_8010DB4(void) gWirelessCommType = 2; SetMainCallback2(CB2_LinkError); gMain.savedCallback = CB2_LinkError; - sub_800AF18((Rfu.unk_0a << 16) | (Rfu.unk_10 << 8) | Rfu.unk_12, Rfu.unk_124.unk_8c2, Rfu.unk_9e8.unk_232, sub_8011A74() == 2); + sub_800AF18((Rfu.unk_0a << 16) | (Rfu.unk_10 << 8) | Rfu.unk_12, Rfu.unk_124.unk_8c2, Rfu.unk_9e8.unk_232, RfuGetErrorStatus() == 2); Rfu.unk_ee = 2; CloseLink(); } @@ -1850,7 +1850,7 @@ void sub_8010DB4(void) { if (lman.childClockSlave_flag) rfu_LMAN_requestChangeAgbClockMaster(); - sub_8011A64(1, 0x7000); + RfuSetErrorStatus(1, 0x7000); sub_8011170(0x7000); } } @@ -1905,18 +1905,18 @@ void sub_8010F48(void) StringCopy(gUnknown_02022B22, gSaveBlock2Ptr->playerName); } -void sub_8010F60(void) +void ClearAndInitHostRFUtgtGname(void) { memset(&gUnknown_02022B14, 0, 0xD); sub_800DD94(&gUnknown_02022B14, 0, 0, 0); } -void sub_8010F84(u8 a0, u32 a1, u32 a2) +void SetHostRFUtgtGname(u8 a0, u32 a1, u32 a2) { sub_800DD94(&gUnknown_02022B14, a0, a2, a1); } -void sub_8010FA0(bool32 a0, bool32 a1) +void SetGnameBufferWonderFlags(bool32 a0, bool32 a1) { gUnknown_02022B14.unk_00.hasNews = a0; gUnknown_02022B14.unk_00.hasCard = a1; @@ -1946,16 +1946,16 @@ void sub_801103C(void) r5->child_sprite_gender[i - 1] = sub_801100C(i); } -void sub_8011068(u8 a0) +void UpdateGameData_GroupLockedIn(u8 a0) { gUnknown_02022B14.started = a0; rfu_REQ_configGameData(0, 2, (const u8 *)&gUnknown_02022B14, gUnknown_02022B22); } -void sub_8011090(u8 a0, u32 a1, u32 a2) +void UpdateGameDataWithActivitySpriteGendersFlag(u8 a0, u32 a1, u32 a2) { if (a0) - sub_8010F84(a0, a1, a2); + SetHostRFUtgtGname(a0, a1, a2); rfu_REQ_configGameData(0, 2, (const u8 *)&gUnknown_02022B14, gUnknown_02022B22); } @@ -1966,7 +1966,7 @@ void sub_80110B8(u32 a0) u32 r7; s32 r8; - if (sub_800F7DC()->activity == 0x45) + if (GetHostRFUtgtGname()->activity == 0x45) { r5 = 0; r7 = 0; @@ -1981,7 +1981,7 @@ void sub_80110B8(u32 a0) break; } } - sub_8011090(0x45, r7, 0); + UpdateGameDataWithActivitySpriteGendersFlag(0x45, r7, 0); } } @@ -2038,7 +2038,7 @@ void sub_801120C(u8 a0, u8 unused1) if ((lman.param[0] >> i) & 1) { struct GFtgtGname *structPtr = (void *)gRfuLinkStatus->partner[i].gname; - if (structPtr->activity == sub_800F7DC()->activity) + if (structPtr->activity == GetHostRFUtgtGname()->activity) { Rfu.unk_cd1[i] = 0; Rfu.unk_cd5[i] = 0; @@ -2085,21 +2085,21 @@ void sub_801120C(u8 a0, u8 unused1) else sub_80111FC(); } - sub_8011A64(2, a0); + RfuSetErrorStatus(2, a0); break; case 0x34: break; case 0x42 ... 0x44: break; case 0xf3: - sub_8011A64(1, a0); + RfuSetErrorStatus(1, a0); sub_8011170(a0); Rfu.unk_ef = 1; break; case 0xf0 ... 0xf2: case 0xff: sub_8011170(a0); - sub_8011A64(1, a0); + RfuSetErrorStatus(1, a0); Rfu.unk_cdb = 1; break; } @@ -2121,7 +2121,7 @@ void sub_8011404(u8 a0, u8 unused1) Rfu.unk_c3e = lman.param[0]; break; case 0x23: - sub_8011A64(2, a0); + RfuSetErrorStatus(2, a0); break; case 0x24: Rfu.unk_04 = 11; @@ -2131,7 +2131,7 @@ void sub_8011404(u8 a0, u8 unused1) rfu_setRecvBuffer(0x10, Rfu.unk_c3e, Rfu.unk_c3f, 70); break; case 0x25: - sub_8011A64(2, 0x25); + RfuSetErrorStatus(2, 0x25); break; case 0x30: Rfu.unk_f0 = 2; @@ -2141,7 +2141,7 @@ void sub_8011404(u8 a0, u8 unused1) if (Rfu.unk_f0 != 2) Rfu.unk_f0 = 4; if (Rfu.unk_c86 != 9) - sub_8011A64(2, a0); + RfuSetErrorStatus(2, a0); nullsub_5(gUnknown_082ED7FC, 5, 5); if (gReceivedRemoteLinkPlayers == 1) sub_8011170(a0); @@ -2159,13 +2159,13 @@ void sub_8011404(u8 a0, u8 unused1) case 0x42 ... 0x44: break; case 0xF3: - sub_8011A64(1, a0); + RfuSetErrorStatus(1, a0); sub_8011170(a0); Rfu.unk_ef = 1; break; case 0xF0 ... 0xF2: case 0xFF: - sub_8011A64(1, a0); + RfuSetErrorStatus(1, a0); sub_8011170(a0); Rfu.unk_cdb = 1; break; @@ -2214,10 +2214,10 @@ void sub_8011674(u8 a0, u8 unused1) Rfu.unk_04 = 0x11; break; case 0x10: - sub_8011A64(4, 0); + RfuSetErrorStatus(4, 0); break; case 0x11: - if (sub_800F7DC()->activity == 0x45 && Rfu.unk_cd9 == 0) + if (GetHostRFUtgtGname()->activity == 0x45 && Rfu.unk_cd9 == 0) { u8 idx = sub_8011628(lman.param[0]); if (idx != 0) @@ -2240,7 +2240,7 @@ void sub_8011674(u8 a0, u8 unused1) Rfu.unk_ce4 = 2; } } - else if (sub_800F7DC()->activity == 0x54) + else if (GetHostRFUtgtGname()->activity == 0x54) { rfu_REQ_disconnect(lman.acceptSlot_flag); rfu_waitREQComplete(); @@ -2252,7 +2252,7 @@ void sub_8011674(u8 a0, u8 unused1) case 0x13: break; case 0x14: - if (sub_800F7DC()->activity != 0x45 && lman.acceptCount > 1) + if (GetHostRFUtgtGname()->activity != 0x45 && lman.acceptCount > 1) { r1 = 1 << sub_800E87C(lman.param[0]); rfu_REQ_disconnect(lman.acceptSlot_flag ^ r1); @@ -2279,16 +2279,16 @@ void sub_8011674(u8 a0, u8 unused1) } else { - sub_8011A64(2, a0); + RfuSetErrorStatus(2, a0); } break; case 0x24: Rfu.unk_04 = 0xD; - sub_8011A64(3, 0); + RfuSetErrorStatus(3, 0); rfu_setRecvBuffer(0x10, Rfu.unk_c3e, Rfu.unk_c3f, 70); break; case 0x25: - sub_8011A64(2, a0); + RfuSetErrorStatus(2, a0); break; case 0x31: if (lman.acceptSlot_flag & lman.param[0]) @@ -2324,7 +2324,7 @@ void sub_8011674(u8 a0, u8 unused1) if (gRfuLinkStatus->parentChild == 0xFF && lman.pcswitch_flag == 0 && FuncIsActiveTask(sub_800EB44) == TRUE) Rfu.unk_04 = 0x11; - sub_8011A64(2, a0); + RfuSetErrorStatus(2, a0); break; case 0x40: Rfu.unk_ce3 = 0; @@ -2332,14 +2332,14 @@ void sub_8011674(u8 a0, u8 unused1) case 0x42 ... 0x44: break; case 0xF3: - sub_8011A64(1, a0); + RfuSetErrorStatus(1, a0); sub_8011170(a0); Rfu.unk_ef = 1; break; case 0xF0 ... 0xF2: case 0xFF: sub_8011170(a0); - sub_8011A64(1, a0); + RfuSetErrorStatus(1, a0); Rfu.unk_cdb = 0; break; } @@ -2350,20 +2350,20 @@ void sub_8011A50(void) Rfu.unk_ce4 = 2; } -void sub_8011A64(u8 a0, u16 a1) +void RfuSetErrorStatus(u8 a0, u16 a1) { Rfu.unk_f1 = a0; Rfu.unk_0a = a1; } -u8 sub_8011A74(void) +u8 RfuGetErrorStatus(void) { return Rfu.unk_f1; } -bool32 sub_8011A80(void) +bool32 RfuIsErrorStatus1or2(void) { - u32 var = sub_8011A74() - 1; + u32 var = RfuGetErrorStatus() - 1; if (var < 2) return TRUE; else @@ -2409,7 +2409,7 @@ void sub_8011AFC(void) if (IsWirelessAdapterConnected()) { gLinkType = LINKTYPE_0x1111; - sub_800B488(); + SetWirelessCommType1(); OpenLink(); SeedRng(gMain.vblankCounter2); for (i = 0; i < 4; i++) @@ -2425,7 +2425,7 @@ void sub_8011AFC(void) } } -bool32 sub_8011B90(void) +bool32 IsUnionRoomListenTaskActive(void) { return FuncIsActiveTask(sub_800EB44); } @@ -2450,7 +2450,7 @@ void sub_8011BF8(void) UpdatePaletteFade(); } -void sub_8011C10(u32 a0) +void InitializeRfuLinkManager_LinkLeader(u32 a0) { Rfu.unk_0c = 1; sub_8010F48(); @@ -2460,7 +2460,7 @@ void sub_8011C10(u32 a0) sub_800EE78(); } -void sub_8011C5C(void) +void InitializeRfuLinkManager_JoinGroup(void) { Rfu.unk_0c = 0; sub_8010F48(); @@ -2468,7 +2468,7 @@ void sub_8011C5C(void) sub_800EF00(); } -void sub_8011C84(void) +void InitializeRfuLinkManager_EnterUnionRoom(void) { Rfu.unk_0c = 2; sub_8010F48(); @@ -2516,7 +2516,7 @@ void sub_8011D6C(u32 a0) Rfu.unk_cda = sub_800E87C(Rfu.unk_ce2); } -void sub_8011DC0(const u8 *ptr, u16 a1) +void RequestDisconnectSlotByTrainerNameAndId(const u8 *ptr, u16 a1) { u8 var = sub_8011CE4(ptr, a1); if (var != 0xFF) @@ -2584,13 +2584,13 @@ void sub_8011EF4(u8 taskId) if (sub_800EEBC()) DestroyTask(taskId); } - else if (sub_800F7DC()->activity == 0x15 || sub_800F7DC()->activity == 0x16) + else if (GetHostRFUtgtGname()->activity == 0x15 || GetHostRFUtgtGname()->activity == 0x16) { data[15]++; } else { - sub_8011A64(2, 0x7000); + RfuSetErrorStatus(2, 0x7000); DestroyTask(taskId); } } @@ -2607,12 +2607,12 @@ void sub_8011EF4(u8 taskId) if (data[15] > 240) { - sub_8011A64(2, 0x7000); + RfuSetErrorStatus(2, 0x7000); DestroyTask(taskId); } } -void sub_8011FC8(const u8 *src, u16 trainerId) +void CreateTask_RfuReconnectWithParent(const u8 *src, u16 trainerId) { u8 taskId; s16 *data; @@ -2626,7 +2626,7 @@ void sub_8011FC8(const u8 *src, u16 trainerId) bool32 sub_801200C(s16 a1, struct GFtgtGname *structPtr) { - if (sub_800F7DC()->activity == 0x45) + if (GetHostRFUtgtGname()->activity == 0x45) { if (structPtr->activity != 0x45) return TRUE; @@ -2663,7 +2663,7 @@ void sub_801209C(u8 taskId) if (++gTasks[taskId].data[0] > 300) { - sub_8011A64(2, 0x7000); + RfuSetErrorStatus(2, 0x7000); DestroyTask(taskId); } @@ -2683,7 +2683,7 @@ void sub_801209C(u8 taskId) } else { - sub_8011A64(2, 0x7000); + RfuSetErrorStatus(2, 0x7000); DestroyTask(taskId); } } diff --git a/src/link_rfu_3.c b/src/link_rfu_3.c index 535deeca68..b7d3e808cf 100644 --- a/src/link_rfu_3.c +++ b/src/link_rfu_3.c @@ -625,7 +625,7 @@ void sub_800DD94(struct GFtgtGname *data, u8 r9, bool32 r2, s32 r3) data->unk_00.gameClear = FlagGet(FLAG_SYS_GAME_CLEAR); } -bool8 sub_800DE7C(struct GFtgtGname *buff1, u8 *buff2, u8 idx) +bool8 LinkRfu_GetNameIfCompatible(struct GFtgtGname *buff1, u8 *buff2, u8 idx) { bool8 retVal; @@ -660,7 +660,7 @@ bool8 sub_800DE7C(struct GFtgtGname *buff1, u8 *buff2, u8 idx) return retVal; } -bool8 sub_800DF34(struct GFtgtGname *buff1, u8 *buff2, u8 idx) +bool8 LinkRfu_GetNameIfSerial7F7D(struct GFtgtGname *buff1, u8 *buff2, u8 idx) { bool8 retVal = FALSE; if (gRfuLinkStatus->partner[idx].serialNo == 0x7F7D) @@ -677,7 +677,7 @@ bool8 sub_800DF34(struct GFtgtGname *buff1, u8 *buff2, u8 idx) return retVal; } -void sub_800DF90(struct GFtgtGname *buff1, u8 *buff2) +void LinkRfu3_SetGnameUnameFromStaticBuffers(struct GFtgtGname *buff1, u8 *buff2) { memcpy(buff1, &gUnknown_02022B14, 0xD); memcpy(buff2, gUnknown_02022B22, 8); @@ -820,7 +820,7 @@ void sub_800E174(void) gMain.oamBuffer[125].paletteNum = sprite->oam.paletteNum; gMain.oamBuffer[125].tileNum = sprite->data[6] + sprite->anims[sprite->data[2]][sprite->data[4]].frame.imageValue; CpuCopy16(gMain.oamBuffer + 125, (struct OamData *)OAM + 125, sizeof(struct OamData)); - if (sub_8011A74() == 1) + if (RfuGetErrorStatus() == 1) { DestroyWirelessStatusIndicatorSprite(); } @@ -908,7 +908,7 @@ void RecordMixTrainerNames(void) } } -bool32 sub_800E540(u16 id, u8 *name) +bool32 PlayerHasMetTrainerBefore(u16 id, u8 *name) { s32 i; diff --git a/src/menu.c b/src/menu.c index 62387c3230..8bd85727e5 100644 --- a/src/menu.c +++ b/src/menu.c @@ -2107,7 +2107,7 @@ void sub_819A27C(u8 windowId, u16 speciesId, u32 personality, u16 x, u16 y) BlitBitmapToWindow(windowId, GetMonIconPtr(speciesId, personality, 1), x, y, 32, 32); } -void sub_819A2BC(u8 palOffset, u8 palId) +void ListMenuLoadStdPalAt(u8 palOffset, u8 palId) { const u16 *palette; diff --git a/src/mevent2.c b/src/mevent2.c index 2991ac27ca..3e524ce350 100755 --- a/src/mevent2.c +++ b/src/mevent2.c @@ -548,12 +548,12 @@ u16 mevent_081445C0(u32 command) return 0; } -void sub_801B940(void) +void ResetReceivedWonderCardFlag(void) { gUnknown_02022C70 = FALSE; } -bool32 sub_801B94C(u16 a0) +bool32 MEventHandleReceivedWonderCard(u16 a0) { gUnknown_02022C70 = FALSE; if (a0 == 0) diff --git a/src/party_menu.c b/src/party_menu.c index 4ed7ab1b24..a4d588cbcc 100755 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -3527,7 +3527,7 @@ static void CursorCb_Register(u8 taskId) u16 species = GetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_SPECIES); u8 obedience = GetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_OBEDIENCE); - switch (CanRegisterMonForTradingBoard(*(struct GFtgtGnameSub *)sub_800F7DC(), species2, species, obedience)) + switch (CanRegisterMonForTradingBoard(*(struct GFtgtGnameSub *)GetHostRFUtgtGname(), species2, species, obedience)) { case CANT_REGISTER_MON: StringExpandPlaceholders(gStringVar4, gText_PkmnCantBeTradedNow); @@ -3553,7 +3553,7 @@ static void CursorCb_Trade1(u8 taskId) u16 species2 = GetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_SPECIES2); u16 species = GetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_SPECIES); u8 obedience = GetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_OBEDIENCE); - u32 stringId = GetUnionRoomTradeMessageId(*(struct GFtgtGnameSub *)sub_800F7DC(), gUnknown_02022C38, species2, gUnionRoomOfferedSpecies, gUnionRoomRequestedMonType, species, obedience); + u32 stringId = GetUnionRoomTradeMessageId(*(struct GFtgtGnameSub *)GetHostRFUtgtGname(), gPartnerTgtGnameSub, species2, gUnionRoomOfferedSpecies, gUnionRoomRequestedMonType, species, obedience); if (stringId != UR_TRADE_MSG_NONE) { diff --git a/src/pokemon_jump.c b/src/pokemon_jump.c index f2f416c35d..da8695247c 100755 --- a/src/pokemon_jump.c +++ b/src/pokemon_jump.c @@ -400,7 +400,7 @@ static const struct PokemonJumpMons gPkmnJumpSpecies[] = { .species = SPECIES_BAGON, .unk2 = 1, }, }; -void sub_802A9A8(u16 partyIndex, MainCallback callback) +void StartPokemonJump(u16 partyIndex, MainCallback callback) { u8 taskId; diff --git a/src/trade.c b/src/trade.c index e22180ae97..c9fd7b1edc 100644 --- a/src/trade.c +++ b/src/trade.c @@ -52,6 +52,7 @@ #include "constants/rgb.h" #include "constants/species.h" #include "constants/songs.h" +#include "constants/union_room.h" #define Trade_SendData(ptr) (SendBlock(bitmask_all_link_players_but_self(), ptr->linkData, 20)) @@ -234,7 +235,7 @@ static void CB2_SaveAndEndWirelessTrade(void); static bool8 SendLinkData(const void *linkData, u32 size) { - if (gUnknown_02022C2C == 29) + if (gPlayerCurrActivity == ACTIVITY_29) { rfu_NI_setSendData(lman.acceptSlot_flag, 84, linkData, size); return TRUE; @@ -252,7 +253,7 @@ static void sub_80771AC(u8 a0) static bool32 sub_80771BC(void) { - if (gUnknown_02022C2C == 29) + if (gPlayerCurrActivity == ACTIVITY_29) { if (gRfuSlotStatusNI[sub_800E87C(lman.acceptSlot_flag)]->send.state == 0) return TRUE; @@ -288,7 +289,7 @@ static void TradeResetReceivedFlag(u32 who) static bool32 IsWirelessTrade(void) { - if (gWirelessCommType && gUnknown_02022C2C == 29) + if (gWirelessCommType && gPlayerCurrActivity == ACTIVITY_29) return TRUE; else return FALSE; @@ -393,7 +394,7 @@ static void CB2_CreateTradeMenu(void) if (gWirelessCommType) { - sub_800B488(); + SetWirelessCommType1(); OpenLink(); sub_8011BA4(); } diff --git a/src/union_room.c b/src/union_room.c index cd45907f50..28e1139dda 100644 --- a/src/union_room.c +++ b/src/union_room.c @@ -41,6 +41,7 @@ #include "trade.h" #include "trainer_card.h" #include "union_room.h" +#include "union_room_battle.h" #include "union_room_chat.h" #include "union_room_player_avatar.h" #include "window.h" @@ -54,156 +55,171 @@ #include "constants/species.h" #include "constants/union_room.h" -EWRAM_DATA u8 sUnionRoomPlayerName[12] = {}; -EWRAM_DATA u8 gUnknown_02022C2C = 0; -EWRAM_DATA u8 gUnknown_02022C2D = 0; -EWRAM_DATA union UnkUnion_Main gUnknown_02022C30 = {}; -EWRAM_DATA u32 gFiller_02022C34 = 0; -EWRAM_DATA struct GFtgtGnameSub gUnknown_02022C38 = {}; +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 = {}; EWRAM_DATA u16 gUnionRoomOfferedSpecies = 0; EWRAM_DATA u8 gUnionRoomRequestedMonType = 0; static EWRAM_DATA struct UnionRoomTrade sUnionRoomTrade = {}; // IWRAM vars -static struct UnkStruct_Leader *gUnknown_03000DA0; -static struct UnkStruct_Group *gUnknown_03000DA4; -static struct UnkStruct_URoom *gUnknown_03000DA8; +static struct WirelessLink_Leader *sLeader; +static struct WirelessLink_Group *sGroup; +static struct WirelessLink_URoom *sURoom; // this file's functions -void sub_80173E0(u8 windowId, u8 arg1, const u8 *str, u8 arg3, u8 arg4, u8 arg5); -u16 ReadAsU16(const u8 *ptr); -void sub_8012780(u8 taskId); -void sub_80134E8(u8 taskId); -void sub_8013C7C(u8 taskId); -void sub_8014A40(u8 taskId); -void sub_8014F48(u8 taskId); -void sub_80152F4(u8 taskId); -void sub_80156E0(u8 taskId); -void sub_80175EC(struct UnkStruct_Main4 *arg0, u8 count); -void sub_8017580(struct UnkStruct_x20 *arg0, u8 count); -u8 sub_8016FC0(struct UnkStruct_Main4 *arg0, u32 arg1); -u8 sub_8016FF0(struct UnkStruct_Main4 *arg0, u32 arg1); -bool8 PrintOnTextbox(u8 *textState, const u8 *str); -bool8 sub_801320C(struct UnkStruct_Leader *data, u32 arg1, u32 arg2); -u8 sub_8013398(struct UnkStruct_Main0 *arg0); -s8 sub_80170B8(u8 *arg0, bool32 arg1); -void sub_8018404(u8 *dest, struct UnkStruct_x20 *arg1); -void sub_8012F64(struct UnkStruct_Leader *data); -void sub_80149C4(void); -u8 sub_80132D4(struct UnkStruct_Main0 *arg0); -void sub_80178A0(u8 arg0, u8 arg1, u8 arg2, struct UnkStruct_x20 *arg3, u8 arg4, u8 id); -u32 sub_80176E4(struct UnkStruct_x20 *arg0, struct UnkStruct_x1C *arg1); -u8 sub_8017734(struct UnkStruct_x20 *arg0, struct UnkStruct_x1C *arg1, u8 arg2); -u8 sub_8013E44(void); -u32 sub_8013B8C(struct UnkStruct_Group *arg0, s32 id); -void sub_8013BD8(struct UnkStruct_Group *arg0, s32 id); -void sub_80173D4(void); -void sub_80177B8(u8 arg0, u8 arg1, u8 arg2, struct UnkStruct_x20 *arg3, u8 arg4, u8 id); -bool32 sub_8017678(struct UnkStruct_Shared *arg0, struct UnkStruct_Shared *arg1); +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); -void sub_801AC54(void); -void sub_80149D8(void); -void MG_DrawTextBorder(u8 windowId); -s8 mevent_message_print_and_prompt_yes_no(u8 *textState, u8 *arg1, u8 arg2, const u8 *str); -bool32 sub_8016F1C(struct GFtgtGname *arg0, s16 arg1); -u8 sub_8016DF0(struct UnkStruct_Main4 *arg0, struct UnkStruct_Main4 *arg1, u32 arg2); -void sub_8019F2C(void); +static void CreateTask_StartActivity(void); +static bool32 GetGnameWonderFlagByLinkGroup(struct GFtgtGname *arg0, s16 arg1); +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); -void sub_80181CC(void); -bool32 sub_8017940(void); -u8 sub_8016B00(void); -void sub_801A274(struct UnkStruct_URoom *arg0); -bool32 sub_8017FD8(struct UnkStruct_URoom *arg0); -void sub_801689C(struct UnkStruct_URoom *arg0); -u8 sub_80181DC(struct UnkStruct_URoom *arg0); -bool32 sub_80168DC(struct UnkStruct_URoom *arg0); -bool32 sub_801704C(void); -s32 sub_8017CF8(s32 arg1, struct UnkStruct_Main0 *arg0); -s32 sub_80179D4(struct UnkStruct_Main0 *arg0, u8 arg1, u8 arg2, u32 playerGender); -void sub_801818C(bool32 arg0); -s32 sub_8017178(u8 *arg0, u8 *arg1, u8 *arg2, const struct WindowTemplate *winTemplate, const struct ListMenuTemplate *menuTemplate); -s32 sub_80172A0(u8 *arg0, u8 *arg1, u8 *arg2, u8 *arg3, const struct WindowTemplate *winTemplate, const struct ListMenuTemplate *menuTemplate, struct UnkStruct_Main0 *arg6); -s32 sub_8017CB0(struct UnkStruct_x20 * arg, s32 arg1); -bool32 HasAtLeastTwoMonsOfLevel30OrLower(void); -u32 sub_8017984(s32 arg0); -void sub_8018220(u8 *unused, struct UnkStruct_URoom *arg1, bool8 arg2); -void sub_8017D9C(u8 *dst, s32 arg1, u32 playerGender); -u32 sub_80179AC(struct UnkStruct_x20 *arg0); -void sub_8017E00(u8 *dst, u8 arg1); -void sub_80173B0(void); -s32 sub_8017D04(u32 type, u32 species); -bool32 sub_8017020(const u8 *src); -u8 sub_8019BA8(struct UnkStruct_8019BA8 * ); -s32 sub_8017EA0(u8 *dst, u32 gender, u16 *arg2, struct UnkStruct_URoom *arg3); -void sub_801697C(u8 taskId); -bool8 sub_8017630(struct UnkStruct_Shared* arg0, const struct UnkStruct_Shared* arg1); -void sub_8013278(u8 windowId, s32 itemId, u8 y); -void sub_8013DF4(u8 windowId, s32 itemId, u8 y); -void sub_8017BE8(u8 windowId, s32 itemId, u8 y); -void nullsub_14(u8 windowId, s32 itemId, u8 y); +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); #include "data/union_room.h" // code -void sub_80124EC(u8 windowId, u8 arg1, u8 stringId) +static void PrintNumPlayersWaitingForMsg(u8 windowId, u8 capacityCode, u8 stringId) { FillWindowPixelBuffer(windowId, PIXEL_FILL(1)); - switch (arg1 << 8) + switch (capacityCode << 8) { - case 0x200: - sub_80173E0(windowId, 1, sPlayersNeededOrModeTexts[0][stringId - 1], 0, 1, 0); + case LINK_GROUP_CAPACITY(0, 2): + UR_AddTextPrinterParameterized(windowId, 1, sPlayersNeededOrModeTexts[0][stringId - 1], 0, 1, UR_COLOR_DKE_WHT_LTE); break; - case 0x400: - sub_80173E0(windowId, 1, sPlayersNeededOrModeTexts[1][stringId - 1], 0, 1, 0); + case LINK_GROUP_CAPACITY(0, 4): + UR_AddTextPrinterParameterized(windowId, 1, sPlayersNeededOrModeTexts[1][stringId - 1], 0, 1, UR_COLOR_DKE_WHT_LTE); break; - case 0x2500: - sub_80173E0(windowId, 1, sPlayersNeededOrModeTexts[2][stringId - 1], 0, 1, 0); + case LINK_GROUP_CAPACITY(2, 5): + UR_AddTextPrinterParameterized(windowId, 1, sPlayersNeededOrModeTexts[2][stringId - 1], 0, 1, UR_COLOR_DKE_WHT_LTE); break; - case 0x3500: - sub_80173E0(windowId, 1, sPlayersNeededOrModeTexts[3][stringId - 1], 0, 1, 0); + case LINK_GROUP_CAPACITY(3, 5): + UR_AddTextPrinterParameterized(windowId, 1, sPlayersNeededOrModeTexts[3][stringId - 1], 0, 1, UR_COLOR_DKE_WHT_LTE); break; - case 0x2400: - sub_80173E0(windowId, 1, sPlayersNeededOrModeTexts[4][stringId - 1], 0, 1, 0); + case LINK_GROUP_CAPACITY(2, 4): + UR_AddTextPrinterParameterized(windowId, 1, sPlayersNeededOrModeTexts[4][stringId - 1], 0, 1, UR_COLOR_DKE_WHT_LTE); break; } CopyWindowToVram(windowId, 2); } -void sub_80125BC(u8 windowId) +static void PrintPlayerNameAndIdOnWindow(u8 windowId) { u8 text[30]; u8 *txtPtr; - sub_80173E0(windowId, 1, gSaveBlock2Ptr->playerName, 0, 1, 0); + UR_AddTextPrinterParameterized(windowId, 1, gSaveBlock2Ptr->playerName, 0, 1, UR_COLOR_DKE_WHT_LTE); txtPtr = StringCopy(text, sText_ID); ConvertIntToDecimalStringN(txtPtr, ReadAsU16(gSaveBlock2Ptr->playerTrainerId), STR_CONV_MODE_LEADING_ZEROS, 5); - sub_80173E0(windowId, 1, text, 0, 0x11, 0); + UR_AddTextPrinterParameterized(windowId, 1, text, 0, 0x11, UR_COLOR_DKE_WHT_LTE); } -void sub_801262C(u8 *dst, u8 caseId) +static void StringExpandPlaceholders_AwaitingCommFromAnother(u8 *dst, u8 caseId) { switch (caseId) { - case 1 ... 4: - case 9 ... 11: - case 14 ... 16: - case 21 ... 28: + 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: // UB: argument *dst isn't used, instead it always prints to gStringVar4 StringExpandPlaceholders(gStringVar4, sText_AwaitingCommunication); break; } } -bool32 sub_80126CC(u32 caseId) +static bool32 IsActivityWithVariableGroupSize(u32 caseId) { switch (caseId) { - case 9 ... 11: - case 15 ... 16: - case 23 ... 27: + 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: return TRUE; default: return FALSE; @@ -213,49 +229,49 @@ bool32 sub_80126CC(u32 caseId) void TryBecomeLinkLeader(void) { u8 taskId; - struct UnkStruct_Leader *dataPtr; + struct WirelessLink_Leader *data; - taskId = CreateTask(sub_8012780, 0); - gUnknown_02022C30.leader = dataPtr = (void*)(gTasks[taskId].data); - gUnknown_03000DA0 = dataPtr; + taskId = CreateTask(Task_TryBecomeLinkLeader, 0); + sWirelessLinkMain.leader = data = (void*)(gTasks[taskId].data); + sLeader = data; - dataPtr->state = 0; - dataPtr->textState = 0; + data->state = 0; + data->textState = 0; gSpecialVar_Result = 0; } -void sub_8012780(u8 taskId) +static void Task_TryBecomeLinkLeader(u8 taskId) { u32 id, val; - struct UnkStruct_Leader *data = gUnknown_02022C30.leader; + struct WirelessLink_Leader *data = sWirelessLinkMain.leader; switch (data->state) { case 0: if (gSpecialVar_0x8004 == LINK_GROUP_BATTLE_TOWER && gSaveBlock2Ptr->frontier.lvlMode == FRONTIER_LVL_OPEN) gSpecialVar_0x8004++; - gUnknown_02022C2C = gUnknown_082F00C4[gSpecialVar_0x8004]; - gUnknown_02022C2D = gUnknown_082F00C4[gSpecialVar_0x8004] >> 8; - sub_8010F84(gUnknown_02022C2C, 0, 0); - sub_800B488(); + gPlayerCurrActivity = sLinkGroupToActivityAndCapacity[gSpecialVar_0x8004]; + sPlayerActivityGroupSize = sLinkGroupToActivityAndCapacity[gSpecialVar_0x8004] >> 8; + SetHostRFUtgtGname(gPlayerCurrActivity, 0, 0); + SetWirelessCommType1(); OpenLink(); - sub_8011C10(gUnknown_02022C2D & 0xF); + InitializeRfuLinkManager_LinkLeader(sPlayerActivityGroupSize & 0xF); data->state = 3; break; case 3: - data->field_4 = AllocZeroed(0x70); - data->field_0 = AllocZeroed(0xA0); - data->field_8 = AllocZeroed(0xA0); - sub_80175EC(data->field_4, 4); - sub_8017580(data->field_0->arr, 5); - sub_800DF90(&data->field_0->arr[0].unk.field_0, data->field_0->arr[0].unk.playerName); + 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); data->field_0->arr[0].field_18 = 0; - data->field_0->arr[0].field_1A_0 = 1; + data->field_0->arr[0].groupScheduledAnim = UNION_ROOM_SPAWN_IN; data->field_0->arr[0].field_1A_1 = 0; data->field_0->arr[0].field_1B = 0; - data->field_17 = sub_8016FC0(data->field_4, 0xFF); - data->field_10 = AddWindow(&gUnknown_082F00BC); - switch (gUnknown_02022C2D & 0xF) + data->listenTaskId = CreateTask_ListenForPartnersWithCompatibleSerialNos(data->field_4, 0xFF); + data->bButtonCancelWindowId = AddWindow(&sWindowTemplate_BButtonCancel); + switch (sPlayerActivityGroupSize & 0xF) { case 2: case 3: @@ -266,41 +282,41 @@ void sub_8012780(u8 taskId) data->listWindowId = AddWindow(&gUnknown_082F0124); break; } - data->field_11 = AddWindow(&gUnknown_082F012C); + data->nPlayerModeWindowId = AddWindow(&sWindowTemplate_NumPlayerMode); - FillWindowPixelBuffer(data->field_10, PIXEL_FILL(2)); - sub_80173E0(data->field_10, 0, sText_BButtonCancel, 8, 1, 4); - PutWindowTilemap(data->field_10); - CopyWindowToVram(data->field_10, 2); + FillWindowPixelBuffer(data->bButtonCancelWindowId, PIXEL_FILL(2)); + UR_AddTextPrinterParameterized(data->bButtonCancelWindowId, 0, sText_BButtonCancel, 8, 1, 4); + PutWindowTilemap(data->bButtonCancelWindowId); + CopyWindowToVram(data->bButtonCancelWindowId, 2); DrawStdWindowFrame(data->listWindowId, FALSE); - gMultiuseListMenuTemplate = gUnknown_082F015C; + gMultiuseListMenuTemplate = sListMenuTemplate_PossibleGroupMembers; gMultiuseListMenuTemplate.windowId = data->listWindowId; data->listTaskId = ListMenuInit(&gMultiuseListMenuTemplate, 0, 0); - DrawStdWindowFrame(data->field_11, FALSE); - PutWindowTilemap(data->field_11); - CopyWindowToVram(data->field_11, 2); + DrawStdWindowFrame(data->nPlayerModeWindowId, FALSE); + PutWindowTilemap(data->nPlayerModeWindowId); + CopyWindowToVram(data->nPlayerModeWindowId, 2); CopyBgTilemapBufferToVram(0); - data->field_13 = 1; + data->playerCount = 1; data->state = 4; break; case 4: - StringCopy(gStringVar1, sLinkGroupActivityTexts[gUnknown_02022C2C]); - if ((gUnknown_02022C2D >> 4) != 0) + StringCopy(gStringVar1, sLinkGroupActivityTexts[gPlayerCurrActivity]); + if ((sPlayerActivityGroupSize >> 4) != 0) { - if (data->field_13 > (gUnknown_02022C2D >> 4) - 1 && (gUnknown_02022C2D & 0xF) != 0) + if (data->playerCount > (sPlayerActivityGroupSize >> 4) - 1 && (sPlayerActivityGroupSize & 0xF) != 0) StringExpandPlaceholders(gStringVar4, sText_AwaitingLinkPressStart); else StringExpandPlaceholders(gStringVar4, sText_AwaitingCommunication); } else { - sub_801262C(gStringVar4, gUnknown_02022C2C); + StringExpandPlaceholders_AwaitingCommFromAnother(gStringVar4, gPlayerCurrActivity); } - sub_80124EC(data->field_11, gUnknown_02022C2D, data->field_13); + PrintNumPlayersWaitingForMsg(data->nPlayerModeWindowId, sPlayerActivityGroupSize, data->playerCount); data->state = 5; break; case 5: @@ -308,24 +324,24 @@ void sub_8012780(u8 taskId) data->state = 6; break; case 6: - sub_801320C(data, 7, 10); + Leader_SetStateIfMemberListChanged(data, 7, 10); if (gMain.newKeys & B_BUTTON) { - if (data->field_13 == 1) + if (data->playerCount == 1) data->state = 23; - else if ((gUnknown_02022C2D & 0xF0) != 0) + else if ((sPlayerActivityGroupSize & 0xF0) != 0) data->state = 30; else data->state = 19; } - if ((gUnknown_02022C2D >> 4) != 0 - && data->field_13 > (gUnknown_02022C2D >> 4) - 1 - && (gUnknown_02022C2D & 0xF) != 0 + if ((sPlayerActivityGroupSize >> 4) != 0 + && data->playerCount > (sPlayerActivityGroupSize >> 4) - 1 + && (sPlayerActivityGroupSize & 0xF) != 0 && sub_8012240() && gMain.newKeys & START_BUTTON) { data->state = 15; - sub_800EF38(); + LinkRfu_StopManagerAndFinalizeSlots(); } if (data->state == 6 && sub_80105EC()) { @@ -336,20 +352,21 @@ void sub_8012780(u8 taskId) if (!sub_80105EC()) { data->state = 6; - data->field_13 = sub_8013398(data->field_0); + data->playerCount = sub_8013398(data->field_0); } break; case 10: - id = ((gUnknown_02022C2C & 0xF) == 2) ? 1 : 0; + id = ((gPlayerCurrActivity & 0xF) == 2) ? 1 : 0; if (PrintOnTextbox(&data->textState, sPlayerUnavailableTexts[id])) { - data->field_13 = sub_8013398(data->field_0); + data->playerCount = sub_8013398(data->field_0); RedrawListMenu(data->listTaskId); data->state = 4; } break; case 29: - id = ((gUnknown_02022C2D & 0xF) == 2) ? 0 : 1; + // Other player canceled. + id = ((sPlayerActivityGroupSize & 0xF) == 2) ? 0 : 1; if (PrintOnTextbox(&data->textState, sPlayerUnavailableTexts[id])) { data->state = 21; @@ -362,19 +379,19 @@ void sub_8012780(u8 taskId) } break; case 11: - switch (sub_80170B8(&data->textState, sub_801064C(ReadAsU16(data->field_0->arr[data->field_13].unk.field_0.unk_00.playerTrainerId), data->field_0->arr[data->field_13].unk.playerName))) + 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))) { case 0: LoadWirelessStatusIndicatorSpriteGfx(); CreateWirelessStatusIndicatorSprite(0, 0); data->field_19 = 5; - sub_8010688(5, ReadAsU16(data->field_0->arr[data->field_13].unk.field_0.unk_00.playerTrainerId), data->field_0->arr[data->field_13].unk.playerName); + SendByteToPartnerByIdAndName(5, ReadAsU16(data->field_0->arr[data->playerCount].gname_uname.gname.unk_00.playerTrainerId), data->field_0->arr[data->playerCount].gname_uname.playerName); data->state = 12; break; case 1: case -1: data->field_19 = 6; - sub_8010688(6, ReadAsU16(data->field_0->arr[data->field_13].unk.field_0.unk_00.playerTrainerId), data->field_0->arr[data->field_13].unk.playerName); + SendByteToPartnerByIdAndName(6, ReadAsU16(data->field_0->arr[data->playerCount].gname_uname.gname.unk_00.playerTrainerId), data->field_0->arr[data->playerCount].gname_uname.playerName); data->state = 12; break; case -3: @@ -383,29 +400,29 @@ void sub_8012780(u8 taskId) } break; case 12: - val = sub_8010714(ReadAsU16(data->field_0->arr[data->field_13].unk.field_0.unk_00.playerTrainerId), data->field_0->arr[data->field_13].unk.playerName); + val = WaitSendByteToPartnerByIdAndName(ReadAsU16(data->field_0->arr[data->playerCount].gname_uname.gname.unk_00.playerTrainerId), data->field_0->arr[data->playerCount].gname_uname.playerName); if (val == 1) { if (data->field_19 == 5) { - data->field_0->arr[data->field_13].field_1B = 0; + data->field_0->arr[data->playerCount].field_1B = 0; RedrawListMenu(data->listTaskId); - data->field_13++; - if (data->field_13 == (gUnknown_02022C2D & 0xF)) + data->playerCount++; + if (data->playerCount == (sPlayerActivityGroupSize & 0xF)) { - if ((gUnknown_02022C2D & 0xF0) != 0 || data->field_13 == 4) + if ((sPlayerActivityGroupSize & 0xF0) != 0 || data->playerCount == 4) { data->state = 15; } else { - sub_8018404(gStringVar1, &data->field_0->arr[data->field_13 - 1]); + IntlConvPartnerUname7(gStringVar1, &data->field_0->arr[data->playerCount - 1]); StringExpandPlaceholders(gStringVar4, sText_AnOKWasSentToPlayer); data->state = 13; } - sub_800EF38(); - sub_80124EC(data->field_11, gUnknown_02022C2D, data->field_13); + LinkRfu_StopManagerAndFinalizeSlots(); + PrintNumPlayersWaitingForMsg(data->nPlayerModeWindowId, sPlayerActivityGroupSize, data->playerCount); } else { @@ -414,8 +431,8 @@ void sub_8012780(u8 taskId) } else { - sub_8011DC0(data->field_0->arr[data->field_13].unk.playerName, ReadAsU16(data->field_0->arr[data->field_13].unk.field_0.unk_00.playerTrainerId)); - data->field_0->arr[data->field_13].field_1A_0 = 0; + 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; sub_8013398(data->field_0); RedrawListMenu(data->listTaskId); data->state = 4; @@ -425,7 +442,7 @@ void sub_8012780(u8 taskId) } else if (val == 2) { - sub_8011A64(0, 0); + RfuSetErrorStatus(0, 0); data->state = 4; } break; @@ -434,7 +451,7 @@ void sub_8012780(u8 taskId) data->state = 14; break; case 14: - if (++data->field_E > 120) + if (++data->delayTimerAfterOk > 120) data->state = 17; break; case 15: @@ -442,14 +459,14 @@ void sub_8012780(u8 taskId) data->state = 16; break; case 16: - switch (sub_80170B8(&data->textState, FALSE)) + switch (UnionRoomHandleYesNo(&data->textState, FALSE)) { case 0: data->state = 17; break; case 1: case -1: - if ((gUnknown_02022C2D & 0xF0) != 0) + if ((sPlayerActivityGroupSize & 0xF0) != 0) data->state = 30; else data->state = 19; @@ -461,16 +478,16 @@ void sub_8012780(u8 taskId) data->state = 20; break; case 20: - switch (sub_80170B8(&data->textState, FALSE)) + switch (UnionRoomHandleYesNo(&data->textState, FALSE)) { case 0: data->state = 23; break; case 1: case -1: - if ((gUnknown_02022C2D & 0xF0) != 0) + if ((sPlayerActivityGroupSize & 0xF0) != 0) data->state = 15; - else if (data->field_13 == (gUnknown_02022C2D & 0xF)) + else if (data->playerCount == (sPlayerActivityGroupSize & 0xF)) data->state = 15; else data->state = 4; @@ -478,13 +495,13 @@ void sub_8012780(u8 taskId) } break; case 17: - if (!sub_801320C(data, 7, 29)) + if (!Leader_SetStateIfMemberListChanged(data, 7, 29)) data->state = 18; break; case 18: - if (sub_800EF1C()) + if (LmanAcceptSlotFlagIsNotZero()) { - if (sub_800EF58(FALSE)) + if (WaitRfuState(FALSE)) { data->state = 26; } @@ -510,8 +527,8 @@ void sub_8012780(u8 taskId) case 21: case 23: DestroyWirelessStatusIndicatorSprite(); - sub_800EDD4(); - sub_8012F64(data); + LinkRfu_Shutdown(); + Leader_DestroyResources(data); data->state++; break; case 24: @@ -525,7 +542,7 @@ void sub_8012780(u8 taskId) gSpecialVar_Result = 8; break; case 26: - if (sub_8011A80()) + if (RfuIsErrorStatus1or2()) { data->state = 29; } @@ -533,11 +550,11 @@ void sub_8012780(u8 taskId) { if (gReceivedRemoteLinkPlayers != 0) { - if (sub_80126CC(gUnknown_02022C2C)) + if (IsActivityWithVariableGroupSize(gPlayerCurrActivity)) sub_801103C(); - sub_8011068(1); - sub_80149C4(); - sub_8012F64(data); + UpdateGameData_GroupLockedIn(TRUE); + CreateTask_RunScriptAndFadeToActivity(); + Leader_DestroyResources(data); DestroyTask(taskId); } } @@ -545,212 +562,212 @@ void sub_8012780(u8 taskId) } } -void sub_8012F64(struct UnkStruct_Leader *data) +static void Leader_DestroyResources(struct WirelessLink_Leader *data) { - ClearWindowTilemap(data->field_11); - ClearStdWindowAndFrame(data->field_11, FALSE); + ClearWindowTilemap(data->nPlayerModeWindowId); + ClearStdWindowAndFrame(data->nPlayerModeWindowId, FALSE); DestroyListMenuTask(data->listTaskId, 0, 0); - ClearWindowTilemap(data->field_10); + ClearWindowTilemap(data->bButtonCancelWindowId); ClearStdWindowAndFrame(data->listWindowId, FALSE); CopyBgTilemapBufferToVram(0); - RemoveWindow(data->field_11); + RemoveWindow(data->nPlayerModeWindowId); RemoveWindow(data->listWindowId); - RemoveWindow(data->field_10); - DestroyTask(data->field_17); + RemoveWindow(data->bButtonCancelWindowId); + DestroyTask(data->listenTaskId); Free(data->field_8); Free(data->field_0); Free(data->field_4); } -void sub_8012FC4(u8 *dst, u8 caseId) +static void Leader_GetAcceptNewMemberPrompt(u8 *dst, u8 caseId) { switch (caseId) { - case 1: - case 2: - case 4: - case 14: - case 28: + case ACTIVITY_BATTLE_SINGLE: + case ACTIVITY_BATTLE_DOUBLE: + case ACTIVITY_TRADE: + case ACTIVITY_BATTLE_TOWER_OPEN: + case ACTIVITY_BATTLE_TOWER: StringExpandPlaceholders(dst, sText_PlayerContactedYouForXAccept); break; - case 21: - case 22: + case ACTIVITY_WONDER_CARD2: + case ACTIVITY_WONDER_NEWS2: StringExpandPlaceholders(dst, sText_PlayerContactedYouShareX); break; - case 3: - case 9: - case 10: - case 11: - case 15: - case 16: - case 23: - case 24: - case 25: - case 26: - case 27: + 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: StringExpandPlaceholders(dst, sText_PlayerContactedYouAddToMembers); break; } } -void sub_8013078(u8 *dst, u8 caseId) +static void GetYouDeclinedTheOfferMessage(u8 *dst, u8 caseId) { switch (caseId) { - case 65: - case 68: + case ACTIVITY_BATTLE_SINGLE | IN_UNION_ROOM: + case ACTIVITY_TRADE | IN_UNION_ROOM: StringExpandPlaceholders(dst, sText_OfferDeclined1); break; - case 69: - case 72: + case ACTIVITY_CHAT | IN_UNION_ROOM: + case ACTIVITY_CARD | IN_UNION_ROOM: StringExpandPlaceholders(dst, sText_OfferDeclined2); break; } } -void sub_80130B4(u8 *dst, u8 caseId) +static void GetYouAskedToJoinGroupPleaseWaitMessage(u8 *dst, u8 caseId) { switch (caseId) { - case 1: - case 2: - case 4: - case 14: - case 21: - case 22: - case 28: + 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: StringExpandPlaceholders(dst, sText_AwaitingPlayersResponse); break; - case 3: - case 9: - case 10: - case 11: - case 15: - case 16: - case 23: - case 24: - case 25: - case 26: - case 27: + 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: StringExpandPlaceholders(dst, sText_PlayerHasBeenAskedToRegisterYouPleaseWait); break; } } -void sub_8013160(u8 *dst, u8 caseId) +static void GetGroupLeaderSentAnOKMessage(u8 *dst, u8 caseId) { switch (caseId) { - case 1: - case 2: - case 4: - case 14: - case 21: - case 22: - case 28: + 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: StringExpandPlaceholders(dst, sText_PlayerSentBackOK); break; - case 3: - case 9: - case 10: - case 11: - case 15: - case 16: - case 23: - case 24: - case 25: - case 26: - case 27: + 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: StringExpandPlaceholders(dst, sText_PlayerOKdRegistration); break; } } -bool8 sub_801320C(struct UnkStruct_Leader *data, u32 arg1, u32 arg2) +static bool8 Leader_SetStateIfMemberListChanged(struct WirelessLink_Leader *data, u32 state1, u32 state2) { - switch (sub_80132D4(data->field_0)) + switch (LeaderUpdateGroupMembership(data->field_0)) { - case 1: + case UNION_ROOM_SPAWN_IN: PlaySE(SE_PC_LOGIN); RedrawListMenu(data->listTaskId); - sub_8018404(gStringVar2, &data->field_0->arr[data->field_13]); - sub_8012FC4(gStringVar4, gUnknown_02022C2C); - data->state = arg1; + IntlConvPartnerUname7(gStringVar2, &data->field_0->arr[data->playerCount]); + Leader_GetAcceptNewMemberPrompt(gStringVar4, gPlayerCurrActivity); + data->state = state1; break; - case 2: - sub_8011A64(0, 0); + case UNION_ROOM_SPAWN_OUT: + RfuSetErrorStatus(0, 0); RedrawListMenu(data->listTaskId); - data->state = arg2; + data->state = state2; return TRUE; } return FALSE; } -void sub_8013278(u8 arg0, s32 id, u8 arg2) +static void ItemPrintFunc_PossibleGroupMembers(u8 windowId, s32 id, u8 y) { - struct UnkStruct_Leader *data = gUnknown_02022C30.leader; + struct WirelessLink_Leader *data = sWirelessLinkMain.leader; u8 var = 0; - switch (data->field_0->arr[id].field_1A_0) + switch (data->field_0->arr[id].groupScheduledAnim) { - case 1: + case UNION_ROOM_SPAWN_IN: if (data->field_0->arr[id].field_1B != 0) var = 2; break; - case 2: + case UNION_ROOM_SPAWN_OUT: var = 1; break; } - sub_80178A0(arg0, 0, arg2, &data->field_0->arr[id], var, id); + PrintGroupMemberCandidateOnWindowWithColor(windowId, 0, y, &data->field_0->arr[id], var, id); } -u8 sub_80132D4(struct UnkStruct_Main0 *arg0) +static u8 LeaderUpdateGroupMembership(struct UnkStruct_Main0 *arg0) { - struct UnkStruct_Leader *data = gUnknown_02022C30.leader; - u8 ret = 0; + struct WirelessLink_Leader *data = sWirelessLinkMain.leader; + u8 ret = UNION_ROOM_SPAWN_NONE; u8 i; s32 id; for (i = 1; i < 5; i++) { - u16 var = data->field_0->arr[i].field_1A_0; - if (var == 1) + u16 var = data->field_0->arr[i].groupScheduledAnim; + if (var == UNION_ROOM_SPAWN_IN) { - id = sub_80176E4(&data->field_0->arr[i], data->field_4->arr); + id = Findx20Inx1CArray(&data->field_0->arr[i], data->field_4->arr); if (id != 0xFF) { - data->field_0->arr[i].unk = data->field_4->arr[id].unk0; - data->field_0->arr[i].field_18 = var; + data->field_0->arr[i].gname_uname = data->field_4->arr[id].gname_uname; + data->field_0->arr[i].field_18 = 1; } else { - data->field_0->arr[i].field_1A_0 = 2; - ret = 2; + data->field_0->arr[i].groupScheduledAnim = UNION_ROOM_SPAWN_OUT; + ret = UNION_ROOM_SPAWN_OUT; } } } - for (id = 0; id < 4; id++) - sub_8017734(data->field_0->arr, &data->field_4->arr[id], 5); + for (id = 0; id < RFU_CHILD_MAX; id++) + Appendx1Ctox20(data->field_0->arr, &data->field_4->arr[id], 5); - if (ret != 2) + if (ret != UNION_ROOM_SPAWN_OUT) { for (id = 0; id < 5; id++) { if (data->field_0->arr[id].field_1B != 0) - ret = 1; + ret = UNION_ROOM_SPAWN_IN; } } return ret; } -u8 sub_8013398(struct UnkStruct_Main0 *arg0) +static u8 sub_8013398(struct UnkStruct_Main0 *arg0) { - struct UnkStruct_Leader *data = gUnknown_02022C30.leader; + struct WirelessLink_Leader *data = sWirelessLinkMain.leader; u8 copiedCount; s32 i; u8 ret; @@ -761,7 +778,7 @@ u8 sub_8013398(struct UnkStruct_Main0 *arg0) copiedCount = 0; for (i = 0; i < 5; i++) { - if (data->field_8->arr[i].field_1A_0 == 1) + if (data->field_8->arr[i].groupScheduledAnim == UNION_ROOM_SPAWN_IN) { data->field_0->arr[copiedCount] = data->field_8->arr[i]; copiedCount++; @@ -771,16 +788,16 @@ u8 sub_8013398(struct UnkStruct_Main0 *arg0) ret = copiedCount; for (; copiedCount < 5; copiedCount++) { - data->field_0->arr[copiedCount].unk = gUnknown_082F045C; + data->field_0->arr[copiedCount].gname_uname = sWirelessGnameUnamePair_Dummy; data->field_0->arr[copiedCount].field_18 = 0; - data->field_0->arr[copiedCount].field_1A_0 = 0; + data->field_0->arr[copiedCount].groupScheduledAnim = UNION_ROOM_SPAWN_NONE; data->field_0->arr[copiedCount].field_1A_1 = 0; data->field_0->arr[copiedCount].field_1B = 0; } for (i = 0; i < 5; i++) { - if (data->field_0->arr[i].field_1A_0 != 1) + if (data->field_0->arr[i].groupScheduledAnim != UNION_ROOM_SPAWN_IN) continue; if (data->field_0->arr[i].field_1B != 0x40) continue; @@ -795,34 +812,34 @@ u8 sub_8013398(struct UnkStruct_Main0 *arg0) void TryJoinLinkGroup(void) { u8 taskId; - struct UnkStruct_Group *dataPtr; + struct WirelessLink_Group *data; - taskId = CreateTask(sub_80134E8, 0); - gUnknown_02022C30.group = dataPtr = (void*)(gTasks[taskId].data); - gUnknown_03000DA4 = dataPtr; + taskId = CreateTask(Task_TryJoinLinkGroup, 0); + sWirelessLinkMain.group = data = (void*)(gTasks[taskId].data); + sGroup = data; - dataPtr->state = 0; - dataPtr->textState = 0; + data->state = 0; + data->textState = 0; gSpecialVar_Result = 0; } -void sub_80134E8(u8 taskId) +static void Task_TryJoinLinkGroup(u8 taskId) { s32 id; - struct UnkStruct_Group *data = gUnknown_02022C30.group; + struct WirelessLink_Group *data = sWirelessLinkMain.group; switch (data->state) { case 0: if (gSpecialVar_0x8004 == LINK_GROUP_BATTLE_TOWER && gSaveBlock2Ptr->frontier.lvlMode == FRONTIER_LVL_OPEN) gSpecialVar_0x8004++; - gUnknown_02022C2C = gUnknown_082F0530[gSpecialVar_0x8004]; - sub_8010F84(gUnknown_02022C2C, 0, 0); - sub_800B488(); + gPlayerCurrActivity = sLinkGroupToURoomActivity[gSpecialVar_0x8004]; + SetHostRFUtgtGname(gPlayerCurrActivity, 0, 0); + SetWirelessCommType1(); OpenLink(); - sub_8011C5C(); - data->field_4 = AllocZeroed(0x70); - data->field_0 = AllocZeroed(0x200); + InitializeRfuLinkManager_JoinGroup(); + data->field_4 = AllocZeroed(4 * sizeof(struct UnkStruct_x1C)); + data->field_0 = AllocZeroed(16 * sizeof(struct UnkStruct_x20)); data->state = 1; break; case 1: @@ -830,34 +847,34 @@ void sub_80134E8(u8 taskId) data->state = 2; break; case 2: - sub_80175EC(data->field_4, 4); - sub_8017580(data->field_0->arr, 16); - data->field_11 = sub_8016FC0(data->field_4, gSpecialVar_0x8004); - data->field_C = AddWindow(&gUnknown_082F00BC); + 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); data->listWindowId = AddWindow(&gUnknown_082F0174); - data->field_D = AddWindow(&gUnknown_082F017C); + data->playerNameAndIdWindowId = AddWindow(&gUnknown_082F017C); - FillWindowPixelBuffer(data->field_C, PIXEL_FILL(2)); - sub_80173E0(data->field_C, 0, sText_ChooseJoinCancel, 8, 1, 4); - PutWindowTilemap(data->field_C); - CopyWindowToVram(data->field_C, 2); + FillWindowPixelBuffer(data->bButtonCancelWindowId, PIXEL_FILL(2)); + UR_AddTextPrinterParameterized(data->bButtonCancelWindowId, 0, sText_ChooseJoinCancel, 8, 1, 4); + PutWindowTilemap(data->bButtonCancelWindowId); + CopyWindowToVram(data->bButtonCancelWindowId, 2); DrawStdWindowFrame(data->listWindowId, FALSE); - gMultiuseListMenuTemplate = gUnknown_082F0204; + gMultiuseListMenuTemplate = sListMenuTemplate_UnionRoomGroups; gMultiuseListMenuTemplate.windowId = data->listWindowId; data->listTaskId = ListMenuInit(&gMultiuseListMenuTemplate, 0, 0); - DrawStdWindowFrame(data->field_D, FALSE); - PutWindowTilemap(data->field_D); - sub_80125BC(data->field_D); - CopyWindowToVram(data->field_D, 2); + DrawStdWindowFrame(data->playerNameAndIdWindowId, FALSE); + PutWindowTilemap(data->playerNameAndIdWindowId); + PrintPlayerNameAndIdOnWindow(data->playerNameAndIdWindowId); + CopyWindowToVram(data->playerNameAndIdWindowId, 2); CopyBgTilemapBufferToVram(0); - data->field_F = 0; + data->leaderId = 0; data->state = 3; break; case 3: - id = sub_8013E44(); + id = GetNewLeaderCandidate(); switch (id) { case 1: @@ -870,14 +887,14 @@ void sub_80134E8(u8 taskId) { // this unused variable along with the assignment is needed to match u32 unusedVar; - unusedVar = data->field_0->arr[id].unk.field_0.activity; + unusedVar = data->field_0->arr[id].gname_uname.gname.activity; - if (data->field_0->arr[id].field_1A_0 == 1 && !data->field_0->arr[id].unk.field_0.started) + if (data->field_0->arr[id].groupScheduledAnim == UNION_ROOM_SPAWN_IN && !data->field_0->arr[id].gname_uname.gname.started) { - u32 var = sub_8013B8C(data, id); + u32 var = IsTryingToTradeAcrossVersionTooSoon(data, id); if (var == 0) { - sub_8013BD8(data, id); + AskToJoinRfuGroup(data, id); data->state = 5; PlaySE(SE_PN_ON); } @@ -904,30 +921,46 @@ void sub_80134E8(u8 taskId) } break; case 5: - sub_80130B4(gStringVar4, gUnknown_02022C2C); + GetYouAskedToJoinGroupPleaseWaitMessage(gStringVar4, gPlayerCurrActivity); if (PrintOnTextbox(&data->textState, gStringVar4)) { - sub_8018404(gStringVar1, &data->field_0->arr[data->field_F]); + IntlConvPartnerUname7(gStringVar1, &data->field_0->arr[data->leaderId]); data->state = 6; } break; case 6: - if (gReceivedRemoteLinkPlayers != 0) + if (gReceivedRemoteLinkPlayers) { - gUnknown_02022C2C = data->field_0->arr[data->field_F].unk.field_0.activity; - sub_8011A64(0, 0); - switch (gUnknown_02022C2C) + gPlayerCurrActivity = data->field_0->arr[data->leaderId].gname_uname.gname.activity; + RfuSetErrorStatus(0, 0); + switch (gPlayerCurrActivity) { - case 1 ... 5: - case 9 ... 11: - case 13 ... 16: - case 21 ... 28: + 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: data->state = 20; return; } } - switch (sub_8011A74()) + switch (RfuGetErrorStatus()) { case 1: data->state = 12; @@ -938,49 +971,49 @@ void sub_80134E8(u8 taskId) data->state = 14; break; case 5: - sub_8013160(gStringVar4, gUnknown_02022C2C); + GetGroupLeaderSentAnOKMessage(gStringVar4, gPlayerCurrActivity); if (PrintOnTextbox(&data->textState, gStringVar4)) { - if (gUnknown_02022C2C == 28 || gUnknown_02022C2C == 14) + if (gPlayerCurrActivity == ACTIVITY_BATTLE_TOWER || gPlayerCurrActivity == ACTIVITY_BATTLE_TOWER_OPEN) { - sub_8011A64(12, 0); + RfuSetErrorStatus(12, 0); } else { - sub_8011A64(7, 0); - StringCopy(gStringVar1, sLinkGroupActivityTexts[gUnknown_02022C2C]); + RfuSetErrorStatus(7, 0); + StringCopy(gStringVar1, sLinkGroupActivityTexts[gPlayerCurrActivity]); StringExpandPlaceholders(gStringVar4, sText_AwaitingOtherMembers); } } break; case 7: - if (data->field_15 > 0xF0) + if (data->delayBeforePrint > 240) { if (PrintOnTextbox(&data->textState, gStringVar4)) { - sub_8011A64(12, 0); - data->field_15 = 0; + RfuSetErrorStatus(12, 0); + data->delayBeforePrint = 0; } } else { - switch (gUnknown_02022C2C) + switch (gPlayerCurrActivity) { - case 1: - case 2: - case 4: - case 14: - case 28: + case ACTIVITY_BATTLE_SINGLE: + case ACTIVITY_BATTLE_DOUBLE: + case ACTIVITY_TRADE: + case ACTIVITY_BATTLE_TOWER: + case ACTIVITY_BATTLE_TOWER_OPEN: break; default: - data->field_15++; + data->delayBeforePrint++; break; } } break; } - if (!sub_8011A74() && gMain.newKeys & B_BUTTON) + if (!RfuGetErrorStatus() && gMain.newKeys & B_BUTTON) data->state = 7; break; case 7: @@ -988,10 +1021,10 @@ void sub_80134E8(u8 taskId) data->state = 8; break; case 8: - switch (sub_80170B8(&data->textState, sub_8011A74())) + switch (UnionRoomHandleYesNo(&data->textState, RfuGetErrorStatus())) { case 0: - sub_80106D4(); + LinkRfuNIsend8(); data->state = 9; RedrawListMenu(data->listTaskId); break; @@ -1007,7 +1040,7 @@ void sub_80134E8(u8 taskId) } break; case 9: - if (sub_8011A74()) + if (RfuGetErrorStatus()) data->state = 6; break; case 10: @@ -1015,23 +1048,23 @@ void sub_80134E8(u8 taskId) case 14: case 18: case 20: - ClearWindowTilemap(data->field_D); - ClearStdWindowAndFrame(data->field_D, FALSE); + ClearWindowTilemap(data->playerNameAndIdWindowId); + ClearStdWindowAndFrame(data->playerNameAndIdWindowId, FALSE); DestroyListMenuTask(data->listTaskId, 0, 0); - ClearWindowTilemap(data->field_C); + ClearWindowTilemap(data->bButtonCancelWindowId); ClearStdWindowAndFrame(data->listWindowId, FALSE); CopyBgTilemapBufferToVram(0); - RemoveWindow(data->field_D); + RemoveWindow(data->playerNameAndIdWindowId); RemoveWindow(data->listWindowId); - RemoveWindow(data->field_C); - DestroyTask(data->field_11); + RemoveWindow(data->bButtonCancelWindowId); + DestroyTask(data->listenTaskId); Free(data->field_0); Free(data->field_4); data->state++; break; case 13: DestroyWirelessStatusIndicatorSprite(); - if (PrintOnTextbox(&data->textState, sPlayerDisconnectedTexts[sub_8011A74()])) + if (PrintOnTextbox(&data->textState, sPlayerDisconnectedTexts[RfuGetErrorStatus()])) { gSpecialVar_Result = 6; data->state = 23; @@ -1044,7 +1077,7 @@ void sub_80134E8(u8 taskId) break; case 15: DestroyWirelessStatusIndicatorSprite(); - if (PrintOnTextbox(&data->textState, sPlayerDisconnectedTexts[sub_8011A74()])) + if (PrintOnTextbox(&data->textState, sPlayerDisconnectedTexts[RfuGetErrorStatus()])) { gSpecialVar_Result = 8; data->state = 23; @@ -1059,25 +1092,25 @@ void sub_80134E8(u8 taskId) break; case 23: DestroyTask(taskId); - sub_80173D4(); - sub_800EDD4(); + JoinGroup_EnableScriptContexts(); + LinkRfu_Shutdown(); break; case 21: - sub_80149C4(); + CreateTask_RunScriptAndFadeToActivity(); DestroyTask(taskId); break; } } -u32 sub_8013B8C(struct UnkStruct_Group *arg0, s32 id) +static u32 IsTryingToTradeAcrossVersionTooSoon(struct WirelessLink_Group *data, s32 id) { - struct UnkStruct_x20 *structPtr = &arg0->field_0->arr[id]; + struct UnkStruct_x20 *structPtr = &data->field_0->arr[id]; - if (gUnknown_02022C2C == 4 && structPtr->unk.field_0.unk_00.version != VERSION_EMERALD) + if (gPlayerCurrActivity == ACTIVITY_TRADE && structPtr->gname_uname.gname.unk_00.version != VERSION_EMERALD) { if (!(gSaveBlock2Ptr->specialSaveWarpFlags & CHAMPION_SAVEWARP)) return 1; - else if (structPtr->unk.field_0.unk_00.isChampion) + else if (structPtr->gname_uname.gname.unk_00.isChampion) return 0; } else @@ -1088,88 +1121,88 @@ u32 sub_8013B8C(struct UnkStruct_Group *arg0, s32 id) return 2; } -void sub_8013BD8(struct UnkStruct_Group *data, s32 id) +static void AskToJoinRfuGroup(struct WirelessLink_Group *data, s32 id) { - data->field_F = id; + data->leaderId = id; LoadWirelessStatusIndicatorSpriteGfx(); CreateWirelessStatusIndicatorSprite(0, 0); RedrawListMenu(data->listTaskId); - sub_8018404(gStringVar1, &data->field_0->arr[data->field_F]); - sub_8011090(gUnknown_082F0530[gSpecialVar_0x8004], 0, 1); - sub_8011FC8(data->field_0->arr[data->field_F].unk.playerName, ReadAsU16(data->field_0->arr[data->field_F].unk.field_0.unk_00.playerTrainerId)); + 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)); } -u8 sub_8013C40(void) +u8 CreateTask_ListenToWireless(void) { u8 taskId; - struct UnkStruct_Group *dataPtr; + struct WirelessLink_Group *data; - taskId = CreateTask(sub_8013C7C, 0); - gUnknown_02022C30.group = dataPtr = (void*)(gTasks[taskId].data); + taskId = CreateTask(Task_ListenToWireless, 0); + sWirelessLinkMain.group = data = (void*)(gTasks[taskId].data); - dataPtr->state = 0; - dataPtr->textState = 0; + data->state = 0; + data->textState = 0; - gUnknown_03000DA4 = dataPtr; + sGroup = data; return taskId; } -void sub_8013C7C(u8 taskId) +static void Task_ListenToWireless(u8 taskId) { - struct UnkStruct_Group *data = gUnknown_02022C30.group; + struct WirelessLink_Group *data = sWirelessLinkMain.group; switch (data->state) { case 0: - sub_8010F84(0, 0, 0); - sub_800B488(); + SetHostRFUtgtGname(0, 0, 0); + SetWirelessCommType1(); OpenLink(); - sub_8011C5C(); + InitializeRfuLinkManager_JoinGroup(); sub_80111B0(TRUE); - data->field_4 = AllocZeroed(0x70); - data->field_0 = AllocZeroed(0x200); + data->field_4 = AllocZeroed(4 * sizeof(struct UnkStruct_x1C)); + data->field_0 = AllocZeroed(16 * sizeof(struct UnkStruct_x20)); data->state = 2; break; case 2: - sub_80175EC(data->field_4, 4); - sub_8017580(data->field_0->arr, 16); - data->field_11 = sub_8016FC0(data->field_4, 0xFF); - data->field_F = 0; + ClearUnkStruct_x1CArray(data->field_4, 4); + ClearUnkStruct_x20Array(data->field_0->arr, 16); + data->listenTaskId = CreateTask_ListenForPartnersWithCompatibleSerialNos(data->field_4, 0xFF); + data->leaderId = 0; data->state = 3; break; case 3: - if (sub_8013E44() == 1) + if (GetNewLeaderCandidate() == 1) PlaySE(SE_PC_LOGIN); if (gTasks[taskId].data[15] == 0xFF) data->state = 10; break; case 10: - DestroyTask(data->field_11); + DestroyTask(data->listenTaskId); Free(data->field_0); Free(data->field_4); - sub_800EDD4(); + LinkRfu_Shutdown(); data->state++; break; case 11: - sub_800EDD4(); + LinkRfu_Shutdown(); DestroyTask(taskId); break; } } -bool32 sub_8013D88(u32 arg0, u32 id) +static bool32 IsPartnerActivityAcceptable(u32 activity, u32 group) { - if (id == 0xFF) + if (group == 0xFF) return TRUE; - if (id <= ARRAY_COUNT(gUnknown_082F04D8)) // UB: <= may access data outside the array + if (group <= ARRAY_COUNT(sAcceptedActivityIds)) // UB: <= may access data outside the array { - const u8 *bytes = gUnknown_082F04D8[id]; + const u8 *bytes = sAcceptedActivityIds[group]; while ((*(bytes) != 0xFF)) { - if ((*bytes) == arg0) + if ((*bytes) == activity) return TRUE; bytes++; } @@ -1178,49 +1211,49 @@ bool32 sub_8013D88(u32 arg0, u32 id) return FALSE; } -u8 sub_8013DBC(struct UnkStruct_Group *data, u32 id) +static u8 URoomGroupListGetTextColor(struct WirelessLink_Group *data, u32 id) { - if (data->field_0->arr[id].field_1A_0 == 1) + if (data->field_0->arr[id].groupScheduledAnim == UNION_ROOM_SPAWN_IN) { - if (data->field_0->arr[id].unk.field_0.started) - return 3; + if (data->field_0->arr[id].gname_uname.gname.started) + return UR_COLOR_WHT_WHT_LTE; else if (data->field_0->arr[id].field_1A_1 != 0) - return 1; + return UR_COLOR_RED_WHT_LTR; else if (data->field_0->arr[id].field_1B != 0) - return 2; + return UR_COLOR_GRN_WHT_LTG; } - return 0; + return UR_COLOR_DKE_WHT_LTE; } -void sub_8013DF4(u8 arg0, s32 id, u8 arg2) +static void ListMenuItemPrintFunc_UnionRoomGroups(u8 windowId, s32 id, u8 y) { - struct UnkStruct_Group *data = gUnknown_02022C30.group; - u8 var = sub_8013DBC(data, id); + struct WirelessLink_Group *data = sWirelessLinkMain.group; + u8 colorId = URoomGroupListGetTextColor(data, id); - sub_80177B8(arg0, 8, arg2, &data->field_0->arr[id], var, id); + PrintUnionRoomGroupOnWindow(windowId, 8, y, &data->field_0->arr[id], colorId, id); } -u8 sub_8013E44(void) +static u8 GetNewLeaderCandidate(void) { - struct UnkStruct_Group *data = gUnknown_02022C30.group; + struct WirelessLink_Group *data = sWirelessLinkMain.group; u8 ret = 0; u8 i; s32 id; for (i = 0; i < 16; i++) { - if (data->field_0->arr[i].field_1A_0 != 0) + if (data->field_0->arr[i].groupScheduledAnim != UNION_ROOM_SPAWN_NONE) { - id = sub_80176E4(&data->field_0->arr[i], data->field_4->arr); + id = Findx20Inx1CArray(&data->field_0->arr[i], data->field_4->arr); if (id != 0xFF) { - if (data->field_0->arr[i].field_1A_0 == 1) + if (data->field_0->arr[i].groupScheduledAnim == UNION_ROOM_SPAWN_IN) { - if (sub_8017678(&data->field_0->arr[i].unk, &data->field_4->arr[id].unk0)) + if (AreUnionRoomPlayerGnamesDifferent(&data->field_0->arr[i].gname_uname, &data->field_4->arr[id].gname_uname)) { - data->field_0->arr[i].unk = data->field_4->arr[id].unk0; - data->field_0->arr[i].field_1B = 0x40; + data->field_0->arr[i].gname_uname = data->field_4->arr[id].gname_uname; + data->field_0->arr[i].field_1B = 64; ret = 1; } else @@ -1235,8 +1268,8 @@ u8 sub_8013E44(void) } else { - data->field_0->arr[i].field_1A_0 = 1; - data->field_0->arr[i].field_1B = 0x40; + data->field_0->arr[i].groupScheduledAnim = UNION_ROOM_SPAWN_IN; + data->field_0->arr[i].field_1B = 64; ret = 1; } @@ -1244,12 +1277,12 @@ u8 sub_8013E44(void) } else { - if (data->field_0->arr[i].field_1A_0 != 2) + if (data->field_0->arr[i].groupScheduledAnim != UNION_ROOM_SPAWN_OUT) { data->field_0->arr[i].field_18++; if (data->field_0->arr[i].field_18 >= 300) { - data->field_0->arr[i].field_1A_0 = 2; + data->field_0->arr[i].groupScheduledAnim = UNION_ROOM_SPAWN_OUT; ret = 2; } } @@ -1257,29 +1290,29 @@ u8 sub_8013E44(void) } } - for (id = 0; id < 4; id++) + for (id = 0; id < RFU_CHILD_MAX; id++) { - if (sub_8017734(data->field_0->arr, &data->field_4->arr[id], 16) != 0xFF) + if (Appendx1Ctox20(data->field_0->arr, &data->field_4->arr[id], 16) != 0xFF) ret = 1; } return ret; } -static void Task_CreateTradeMenu(u8 taskId) +static void Task_ReturnFromLinkTrade(u8 taskId) { CB2_StartCreateTradeMenu(); DestroyTask(taskId); } -u8 sub_8013F78(void) +u8 CreateTask_ReturnFromLinkTrade(void) { - u8 taskId = CreateTask(Task_CreateTradeMenu, 0); + u8 taskId = CreateTask(Task_ReturnFromLinkTrade, 0); return taskId; } -void sub_8013F90(u8 taskId) +static void Task_StartUnionRoomTrade(u8 taskId) { u32 monId = GetPartyPositionOfRegisteredMon(&sUnionRoomTrade, GetMultiplayerId()); @@ -1319,7 +1352,7 @@ void sub_8013F90(u8 taskId) } } -void sub_80140E0(u8 taskId) +static void Task_ExchangeCards(u8 taskId) { switch (gTasks[taskId].data[0]) { @@ -1343,11 +1376,11 @@ void sub_80140E0(u8 taskId) if (GetLinkPlayerCount() == 2) { recvBuff = gBlockRecvBuffer[GetMultiplayerId() ^ 1]; - sub_801B94C(recvBuff[48]); + MEventHandleReceivedWonderCard(recvBuff[48]); } else { - sub_801B940(); + ResetReceivedWonderCardFlag(); } ResetBlockReceivedFlags(); @@ -1357,16 +1390,16 @@ void sub_80140E0(u8 taskId) } } -void sub_80141A4(void) +static void CB2_ShowCard(void) { switch (gMain.state) { case 0: - CreateTask(sub_80140E0, 5); + CreateTask(Task_ExchangeCards, 5); gMain.state++; break; case 1: - if (!FuncIsActiveTask(sub_80140E0)) + if (!FuncIsActiveTask(Task_ExchangeCards)) ShowTrainerCardInLink(GetMultiplayerId() ^ 1, CB2_ReturnToField); break; } @@ -1377,7 +1410,7 @@ void sub_80141A4(void) BuildOamBuffer(); } -void sub_8014210(u16 battleFlags) +void StartUnionRoomBattle(u16 battleFlags) { HealPlayerParty(); SavePlayerParty(); @@ -1385,11 +1418,12 @@ void sub_8014210(u16 battleFlags) gLinkPlayers[0].linkType = LINKTYPE_BATTLE; gLinkPlayers[GetMultiplayerId()].id = GetMultiplayerId(); gLinkPlayers[GetMultiplayerId() ^ 1].id = GetMultiplayerId() ^ 1; - gMain.savedCallback = sub_80B360C; + gMain.savedCallback = CB2_ReturnFromCableClubBattle; gBattleTypeFlags = battleFlags; PlayBattleBGM(); } +// TODO: pokefirered bad name static void sub_8014290(u16 linkService, u16 x, u16 y) { VarSet(VAR_CABLE_CLUB_STATE, linkService); @@ -1398,7 +1432,8 @@ static void sub_8014290(u16 linkService, u16 x, u16 y) WarpIntoMap(); } -void sub_8014304(s8 mapGroup, s8 mapNum, s32 x, s32 y, u16 linkService) +// TODO: pokefirered bad name +static void sub_8014304(s8 mapGroup, s8 mapNum, s32 x, s32 y, u16 linkService) { gSpecialVar_0x8004 = linkService; VarSet(VAR_CABLE_CLUB_STATE, linkService); @@ -1409,16 +1444,16 @@ void sub_8014304(s8 mapGroup, s8 mapNum, s32 x, s32 y, u16 linkService) WarpIntoMap(); } -void sub_8014384(void) +static void CB2_TransitionToCableClub(void) { switch (gMain.state) { case 0: - CreateTask(sub_80140E0, 5); + CreateTask(Task_ExchangeCards, 5); gMain.state++; break; case 1: - if (!FuncIsActiveTask(sub_80140E0)) + if (!FuncIsActiveTask(Task_ExchangeCards)) SetMainCallback2(CB2_ReturnToFieldCableClub); break; } @@ -1429,120 +1464,125 @@ void sub_8014384(void) BuildOamBuffer(); } -void sub_80143E4(void *arg0, bool32 arg1) +static void CreateTrainerCardInBuffer(void *dest, bool32 setWonderCard) { - u16 *argAsU16Ptr = arg0; + u16 *argAsU16Ptr = dest; TrainerCard_GenerateCardForPlayer((struct TrainerCard *)argAsU16Ptr); - if (arg1) + if (setWonderCard) argAsU16Ptr[48] = GetWonderCardFlagID(); else argAsU16Ptr[48] = 0; } -void sub_801440C(u8 taskId) +static void Task_StartActivity(u8 taskId) { - sub_801B940(); - switch (gUnknown_02022C2C) + ResetReceivedWonderCardFlag(); + switch (gPlayerCurrActivity) { - case 1 ... 4: - case 9 ... 11: - case 13: - case 15: + 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(); break; } - switch (gUnknown_02022C2C) + switch (gPlayerCurrActivity) { - case 65: - case 81: + case ACTIVITY_BATTLE_SINGLE | IN_UNION_ROOM: + case ACTIVITY_ACCEPT | IN_UNION_ROOM: CleanupOverworldWindowsAndTilemaps(); - gMain.savedCallback = sub_801AC54; + gMain.savedCallback = CB2_UnionRoomBattle; InitChooseHalfPartyForBattle(3); break; - case 1: + case ACTIVITY_BATTLE_SINGLE: CleanupOverworldWindowsAndTilemaps(); - sub_80143E4(gBlockSendBuffer, TRUE); + CreateTrainerCardInBuffer(gBlockSendBuffer, TRUE); HealPlayerParty(); SavePlayerParty(); LoadPlayerBag(); sub_8014304(MAP_GROUP(BATTLE_COLOSSEUM_2P), MAP_NUM(BATTLE_COLOSSEUM_2P), 6, 8, USING_SINGLE_BATTLE); - SetMainCallback2(sub_8014384); + SetMainCallback2(CB2_TransitionToCableClub); break; - case 2: + case ACTIVITY_BATTLE_DOUBLE: CleanupOverworldWindowsAndTilemaps(); HealPlayerParty(); SavePlayerParty(); LoadPlayerBag(); - sub_80143E4(gBlockSendBuffer, TRUE); + CreateTrainerCardInBuffer(gBlockSendBuffer, TRUE); sub_8014304(MAP_GROUP(BATTLE_COLOSSEUM_2P), MAP_NUM(BATTLE_COLOSSEUM_2P), 6, 8, USING_DOUBLE_BATTLE); - SetMainCallback2(sub_8014384); + SetMainCallback2(CB2_TransitionToCableClub); break; - case 3: + case ACTIVITY_BATTLE_MULTI: CleanupOverworldWindowsAndTilemaps(); HealPlayerParty(); SavePlayerParty(); LoadPlayerBag(); - sub_80143E4(gBlockSendBuffer, TRUE); + CreateTrainerCardInBuffer(gBlockSendBuffer, TRUE); sub_8014304(MAP_GROUP(BATTLE_COLOSSEUM_4P), MAP_NUM(BATTLE_COLOSSEUM_4P), 5, 8, USING_MULTI_BATTLE); - SetMainCallback2(sub_8014384); + SetMainCallback2(CB2_TransitionToCableClub); break; - case 4: - sub_80143E4(gBlockSendBuffer, TRUE); + case ACTIVITY_TRADE: + CreateTrainerCardInBuffer(gBlockSendBuffer, TRUE); CleanupOverworldWindowsAndTilemaps(); sub_8014304(MAP_GROUP(TRADE_CENTER), MAP_NUM(TRADE_CENTER), 5, 8, USING_TRADE_CENTER); - SetMainCallback2(sub_8014384); + SetMainCallback2(CB2_TransitionToCableClub); break; - case 15: - sub_80143E4(gBlockSendBuffer, TRUE); + case ACTIVITY_RECORD_CORNER: + CreateTrainerCardInBuffer(gBlockSendBuffer, TRUE); CleanupOverworldWindowsAndTilemaps(); sub_8014304(MAP_GROUP(RECORD_CORNER), MAP_NUM(RECORD_CORNER), 8, 9, USING_RECORD_CORNER); - SetMainCallback2(sub_8014384); + SetMainCallback2(CB2_TransitionToCableClub); break; - case 68: + case ACTIVITY_TRADE | IN_UNION_ROOM: CleanupOverworldWindowsAndTilemaps(); - CreateTask(sub_8013F90, 0); + CreateTask(Task_StartUnionRoomTrade, 0); break; - case 5: - case 69: + case ACTIVITY_CHAT: + case ACTIVITY_CHAT | IN_UNION_ROOM: if (GetMultiplayerId() == 0) { - sub_800ED10(); + LinkRfu_CreateConnectionAsParent(); } else { - sub_800ED28(); - sub_8010F84(69, 0, 1); + LinkRfu_StopManagerBeforeEnteringChat(); + SetHostRFUtgtGname(69, 0, 1); } - sub_801DD98(); + EnterUnionRoomChat(); break; - case 8: - case 72: - sub_80143E4(gBlockSendBuffer, FALSE); - SetMainCallback2(sub_80141A4); + case ACTIVITY_CARD: + case ACTIVITY_CARD | IN_UNION_ROOM: + CreateTrainerCardInBuffer(gBlockSendBuffer, FALSE); + SetMainCallback2(CB2_ShowCard); break; - case 9: + case ACTIVITY_POKEMON_JUMP: sub_8014290(USING_MINIGAME, 5, 1); - sub_802A9A8(GetCursorSelectionMonId(), CB2_LoadMap); + StartPokemonJump(GetCursorSelectionMonId(), CB2_LoadMap); break; - case 10: + case ACTIVITY_BERRY_CRUSH: sub_8014290(USING_BERRY_CRUSH, 9, 1); - sub_8020C70(CB2_LoadMap); + StartBerryCrush(CB2_LoadMap); break; - case 11: + case ACTIVITY_BERRY_PICK: sub_8014290(USING_MINIGAME, 5, 1); - sub_802493C(GetCursorSelectionMonId(), CB2_LoadMap); + StartDodrioBerryPicking(GetCursorSelectionMonId(), CB2_LoadMap); break; } DestroyTask(taskId); gSpecialVar_Result = 1; - if (gUnknown_02022C2C != 68) + if (gPlayerCurrActivity != (ACTIVITY_TRADE | IN_UNION_ROOM)) ScriptContext2_Disable(); } -void sub_8014790(u8 taskId) +static void Task_RunScriptAndFadeToActivity(u8 taskId) { s16 *data = gTasks[taskId].data; u16 *sendBuff = (u16*)(gBlockSendBuffer); @@ -1551,10 +1591,10 @@ void sub_8014790(u8 taskId) { case 0: gSpecialVar_Result = 1; - switch (gUnknown_02022C2C) + switch (gPlayerCurrActivity) { - case 14: - case 28: + case ACTIVITY_BATTLE_TOWER: + case ACTIVITY_BATTLE_TOWER_OPEN: gLinkPlayers[0].linkType = LINKTYPE_BATTLE; gLinkPlayers[0].id = 0; gLinkPlayers[1].id = 2; @@ -1565,8 +1605,12 @@ void sub_8014790(u8 taskId) RecordMixTrainerNames(); ResetBlockReceivedFlags(); break; - case 16: - case 23 ... 27: + 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(); DestroyTask(taskId); default: @@ -1585,7 +1629,7 @@ void sub_8014790(u8 taskId) case 2: if (!gPaletteFade.active) { - if (gUnknown_02022C2C == 29) + if (gPlayerCurrActivity == 29) { DestroyTask(taskId); SetMainCallback2(CB2_StartCreateTradeMenu); @@ -1601,7 +1645,7 @@ void sub_8014790(u8 taskId) if (IsLinkTaskFinished()) { DestroyTask(taskId); - sub_80149D8(); + CreateTask_StartActivity(); } break; case 4: @@ -1642,78 +1686,78 @@ void sub_8014790(u8 taskId) } } -void sub_80149C4(void) +static void CreateTask_RunScriptAndFadeToActivity(void) { - CreateTask(sub_8014790, 0); + CreateTask(Task_RunScriptAndFadeToActivity, 0); } -void sub_80149D8(void) +static void CreateTask_StartActivity(void) { - u8 taskId = CreateTask(sub_801440C, 0); + u8 taskId = CreateTask(Task_StartActivity, 0); gTasks[taskId].data[0] = 0; } -void MEvent_CreateTask_Leader(u32 arg0) +void MEvent_CreateTask_Leader(u32 activity) { u8 taskId; - struct UnkStruct_Leader *dataPtr; + struct WirelessLink_Leader *data; - taskId = CreateTask(sub_8014A40, 0); - gUnknown_02022C30.leader = dataPtr = (void*)(gTasks[taskId].data); + taskId = CreateTask(Task_MEvent_Leader, 0); + sWirelessLinkMain.leader = data = (void*)(gTasks[taskId].data); - dataPtr->state = 0; - dataPtr->textState = 0; - dataPtr->field_18 = arg0; + data->state = 0; + data->textState = 0; + data->activity = activity; gSpecialVar_Result = 0; } -void sub_8014A40(u8 taskId) +static void Task_MEvent_Leader(u8 taskId) { - struct UnkStruct_Leader *data = gUnknown_02022C30.leader; + struct WirelessLink_Leader *data = sWirelessLinkMain.leader; struct WindowTemplate winTemplate; s32 val; switch (data->state) { case 0: - gUnknown_02022C2C = data->field_18; - gUnknown_02022C2D = 2; - sub_8010F84(data->field_18, 0, 0); - sub_8010FA0(FALSE, FALSE); - sub_800B488(); + gPlayerCurrActivity = data->activity; + sPlayerActivityGroupSize = 2; + SetHostRFUtgtGname(data->activity, 0, 0); + SetGnameBufferWonderFlags(FALSE, FALSE); + SetWirelessCommType1(); OpenLink(); - sub_8011C10(2); + InitializeRfuLinkManager_LinkLeader(2); data->state = 1; break; case 1: - data->field_4 = AllocZeroed(0x70); - data->field_0 = AllocZeroed(0xA0); - data->field_8 = AllocZeroed(0xA0); - sub_80175EC(data->field_4, 4); - sub_8017580(data->field_0->arr, 5); - sub_800DF90(&data->field_0->arr[0].unk.field_0, data->field_0->arr[0].unk.playerName); + 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); data->field_0->arr[0].field_18 = 0; - data->field_0->arr[0].field_1A_0 = 1; + data->field_0->arr[0].groupScheduledAnim = UNION_ROOM_SPAWN_IN; data->field_0->arr[0].field_1A_1 = 0; data->field_0->arr[0].field_1B = 0; - data->field_17 = sub_8016FC0(data->field_4, 0xFF); + data->listenTaskId = CreateTask_ListenForPartnersWithCompatibleSerialNos(data->field_4, 0xFF); winTemplate = gUnknown_082F011C; winTemplate.baseBlock = GetMysteryGiftBaseBlock(); winTemplate.paletteNum = 0xC; data->listWindowId = AddWindow(&winTemplate); MG_DrawTextBorder(data->listWindowId); - gMultiuseListMenuTemplate = gUnknown_082F015C; + gMultiuseListMenuTemplate = sListMenuTemplate_PossibleGroupMembers; gMultiuseListMenuTemplate.windowId = data->listWindowId; data->listTaskId = ListMenuInit(&gMultiuseListMenuTemplate, 0, 0); CopyBgTilemapBufferToVram(0); - data->field_13 = 1; + data->playerCount = 1; data->state = 2; break; case 2: - StringCopy(gStringVar1, sLinkGroupActivityTexts[gUnknown_02022C2C]); - sub_801262C(gStringVar4, gUnknown_02022C2C); + StringCopy(gStringVar1, sLinkGroupActivityTexts[gPlayerCurrActivity]); + StringExpandPlaceholders_AwaitingCommFromAnother(gStringVar4, gPlayerCurrActivity); data->state = 3; break; case 3: @@ -1721,7 +1765,7 @@ void sub_8014A40(u8 taskId) data->state = 4; break; case 4: - sub_801320C(data, 5, 6); + Leader_SetStateIfMemberListChanged(data, 5, 6); if (gMain.newKeys & B_BUTTON) { data->state = 13; @@ -1731,7 +1775,7 @@ void sub_8014A40(u8 taskId) case 6: if (MG_PrintTextOnWindow1AndWaitButton(&data->textState, sText_LinkWithFriendDropped)) { - data->field_13 = sub_8013398(data->field_0); + data->playerCount = sub_8013398(data->field_0); RedrawListMenu(data->listTaskId); data->state = 2; } @@ -1745,38 +1789,38 @@ void sub_8014A40(u8 taskId) case 0: LoadWirelessStatusIndicatorSpriteGfx(); CreateWirelessStatusIndicatorSprite(0, 0); - data->field_0->arr[data->field_13].field_1B = 0; + data->field_0->arr[data->playerCount].field_1B = 0; RedrawListMenu(data->listTaskId); data->field_19 = 5; - sub_8010688(5, ReadAsU16(data->field_0->arr[data->field_13].unk.field_0.unk_00.playerTrainerId), data->field_0->arr[data->field_13].unk.playerName); + SendByteToPartnerByIdAndName(5, ReadAsU16(data->field_0->arr[data->playerCount].gname_uname.gname.unk_00.playerTrainerId), data->field_0->arr[data->playerCount].gname_uname.playerName); data->state = 8; break; case 1: case -1: data->field_19 = 6; - sub_8010688(6, ReadAsU16(data->field_0->arr[data->field_13].unk.field_0.unk_00.playerTrainerId), data->field_0->arr[data->field_13].unk.playerName); + SendByteToPartnerByIdAndName(6, ReadAsU16(data->field_0->arr[data->playerCount].gname_uname.gname.unk_00.playerTrainerId), data->field_0->arr[data->playerCount].gname_uname.playerName); data->state = 8; break; } break; case 8: - val = sub_8010714(ReadAsU16(data->field_0->arr[data->field_13].unk.field_0.unk_00.playerTrainerId), data->field_0->arr[data->field_13].unk.playerName); + val = WaitSendByteToPartnerByIdAndName(ReadAsU16(data->field_0->arr[data->playerCount].gname_uname.gname.unk_00.playerTrainerId), data->field_0->arr[data->playerCount].gname_uname.playerName); if (val == 1) { if (data->field_19 == 5) { - data->field_0->arr[data->field_13].field_1B = 0; + data->field_0->arr[data->playerCount].field_1B = 0; RedrawListMenu(data->listTaskId); - data->field_13++; - sub_8018404(gStringVar1, &data->field_0->arr[data->field_13 - 1]); + data->playerCount++; + IntlConvPartnerUname7(gStringVar1, &data->field_0->arr[data->playerCount - 1]); StringExpandPlaceholders(gStringVar4, sText_AnOKWasSentToPlayer); data->state = 9; - sub_800EF38(); + LinkRfu_StopManagerAndFinalizeSlots(); } else { - sub_8011DC0(data->field_0->arr[data->field_13].unk.playerName, ReadAsU16(data->field_0->arr[data->field_13].unk.field_0.unk_00.playerTrainerId)); - data->field_0->arr[data->field_13].field_1A_0 = 0; + 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; sub_8013398(data->field_0); RedrawListMenu(data->listTaskId); data->state = 2; @@ -1786,7 +1830,7 @@ void sub_8014A40(u8 taskId) } else if (val == 2) { - sub_8011A64(0, 0); + RfuSetErrorStatus(0, 0); data->state = 2; } break; @@ -1795,17 +1839,17 @@ void sub_8014A40(u8 taskId) data->state = 10; break; case 10: - if (++data->field_E > 120) + if (++data->delayTimerAfterOk > 120) data->state = 11; break; case 11: - if (!sub_801320C(data, 5, 6)) + if (!Leader_SetStateIfMemberListChanged(data, 5, 6)) data->state = 12; break; case 12: - if (sub_800EF1C()) + if (LmanAcceptSlotFlagIsNotZero()) { - sub_800EF58(FALSE); + WaitRfuState(FALSE); data->state = 15; } else @@ -1815,11 +1859,11 @@ void sub_8014A40(u8 taskId) break; case 13: DestroyWirelessStatusIndicatorSprite(); - sub_800EDD4(); + LinkRfu_Shutdown(); DestroyListMenuTask(data->listTaskId, 0, 0); CopyBgTilemapBufferToVram(0); RemoveWindow(data->listWindowId); - DestroyTask(data->field_17); + DestroyTask(data->listenTaskId); Free(data->field_8); Free(data->field_0); Free(data->field_4); @@ -1833,13 +1877,13 @@ void sub_8014A40(u8 taskId) } break; case 15: - if (sub_8011A74() == 1 || sub_8011A74() == 2) + if (RfuGetErrorStatus() == 1 || RfuGetErrorStatus() == 2) { data->state = 13; } else if (gReceivedRemoteLinkPlayers != 0) { - sub_8011068(1); + UpdateGameData_GroupLockedIn(TRUE); data->state++; } break; @@ -1847,7 +1891,7 @@ void sub_8014A40(u8 taskId) DestroyListMenuTask(data->listTaskId, 0, 0); CopyBgTilemapBufferToVram(0); RemoveWindow(data->listWindowId); - DestroyTask(data->field_17); + DestroyTask(data->listenTaskId); Free(data->field_8); Free(data->field_0); Free(data->field_4); @@ -1861,36 +1905,36 @@ void sub_8014A40(u8 taskId) } } -void MEvent_CreateTask_CardOrNewsWithFriend(u32 arg0) +void MEvent_CreateTask_CardOrNewsWithFriend(u32 activity) { u8 taskId; - struct UnkStruct_Group *dataPtr; + struct WirelessLink_Group *data; - taskId = CreateTask(sub_8014F48, 0); - gUnknown_02022C30.group = dataPtr = (void*)(gTasks[taskId].data); - gUnknown_03000DA4 = dataPtr; + taskId = CreateTask(Task_CardOrNewsWithFriend, 0); + sWirelessLinkMain.group = data = (void*)(gTasks[taskId].data); + sGroup = data; - dataPtr->state = 0; - dataPtr->textState = 0; - dataPtr->field_12 = arg0 - 21; + data->state = 0; + data->textState = 0; + data->isWonderNews = activity - ACTIVITY_WONDER_CARD2; gSpecialVar_Result = 0; } -void sub_8014F48(u8 taskId) +static void Task_CardOrNewsWithFriend(u8 taskId) { s32 id; struct WindowTemplate winTemplate1, winTemplate2; - struct UnkStruct_Group *data = gUnknown_02022C30.group; + struct WirelessLink_Group *data = sWirelessLinkMain.group; switch (data->state) { case 0: - sub_8010F84(data->field_12 + 21, 0, 0); - sub_800B488(); + SetHostRFUtgtGname(data->isWonderNews + ACTIVITY_WONDER_CARD2, 0, 0); + SetWirelessCommType1(); OpenLink(); - sub_8011C5C(); - data->field_4 = AllocZeroed(0x70); - data->field_0 = AllocZeroed(0x200); + InitializeRfuLinkManager_JoinGroup(); + data->field_4 = AllocZeroed(4 * sizeof(struct UnkStruct_x1C)); + data->field_0 = AllocZeroed(16 * sizeof(struct UnkStruct_x20)); data->state = 1; break; case 1: @@ -1898,9 +1942,9 @@ void sub_8014F48(u8 taskId) data->state = 2; break; case 2: - sub_80175EC(data->field_4, 4); - sub_8017580(data->field_0->arr, 16); - data->field_11 = sub_8016FC0(data->field_4, data->field_12 + 7); + 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); winTemplate1 = gUnknown_082F0174; winTemplate1.baseBlock = GetMysteryGiftBaseBlock(); @@ -1909,25 +1953,25 @@ void sub_8014F48(u8 taskId) winTemplate2 = gUnknown_082F017C; winTemplate2.paletteNum = 0xC; - data->field_D = AddWindow(&winTemplate2); + data->playerNameAndIdWindowId = AddWindow(&winTemplate2); MG_DrawTextBorder(data->listWindowId); - gMultiuseListMenuTemplate = gUnknown_082F0204; + gMultiuseListMenuTemplate = sListMenuTemplate_UnionRoomGroups; gMultiuseListMenuTemplate.windowId = data->listWindowId; data->listTaskId = ListMenuInit(&gMultiuseListMenuTemplate, 0, 0); - MG_DrawTextBorder(data->field_D); - FillWindowPixelBuffer(data->field_D, PIXEL_FILL(1)); - PutWindowTilemap(data->field_D); - sub_80125BC(data->field_D); - CopyWindowToVram(data->field_D, 2); + MG_DrawTextBorder(data->playerNameAndIdWindowId); + FillWindowPixelBuffer(data->playerNameAndIdWindowId, PIXEL_FILL(1)); + PutWindowTilemap(data->playerNameAndIdWindowId); + PrintPlayerNameAndIdOnWindow(data->playerNameAndIdWindowId); + CopyWindowToVram(data->playerNameAndIdWindowId, 2); CopyBgTilemapBufferToVram(0); - data->field_F = 0; + data->leaderId = 0; data->state = 3; break; case 3: - id = sub_8013E44(); + id = GetNewLeaderCandidate(); switch (id) { case 1: @@ -1941,16 +1985,16 @@ void sub_8014F48(u8 taskId) { // this unused variable along with the assignment is needed to match u32 unusedVar; - unusedVar = data->field_0->arr[id].unk.field_0.activity; + unusedVar = data->field_0->arr[id].gname_uname.gname.activity; - if (data->field_0->arr[id].field_1A_0 == 1 && !data->field_0->arr[id].unk.field_0.started) + if (data->field_0->arr[id].groupScheduledAnim == UNION_ROOM_SPAWN_IN && !data->field_0->arr[id].gname_uname.gname.started) { - data->field_F = id; + data->leaderId = id; LoadWirelessStatusIndicatorSpriteGfx(); CreateWirelessStatusIndicatorSprite(0, 0); RedrawListMenu(data->listTaskId); - sub_8018404(gStringVar1, &data->field_0->arr[data->field_F]); - sub_8011FC8(data->field_0->arr[data->field_F].unk.playerName, ReadAsU16(data->field_0->arr[data->field_F].unk.field_0.unk_00.playerTrainerId)); + 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)); PlaySE(SE_PN_ON); data->state = 4; } @@ -1968,17 +2012,17 @@ void sub_8014F48(u8 taskId) break; case 4: AddTextPrinterToWindow1(sText_AwaitingPlayersResponse); - sub_8018404(gStringVar1, &data->field_0->arr[data->field_F]); + IntlConvPartnerUname7(gStringVar1, &data->field_0->arr[data->leaderId]); data->state = 5; break; case 5: - if (gReceivedRemoteLinkPlayers != 0) + if (gReceivedRemoteLinkPlayers) { - gUnknown_02022C2C = data->field_0->arr[data->field_F].unk.field_0.activity; + gPlayerCurrActivity = data->field_0->arr[data->leaderId].gname_uname.gname.activity; data->state = 10; } - switch (sub_8011A74()) + switch (RfuGetErrorStatus()) { case 1: case 2: @@ -1987,7 +2031,7 @@ void sub_8014F48(u8 taskId) break; case 5: AddTextPrinterToWindow1(sText_PlayerSentBackOK); - sub_8011A64(0, 0); + RfuSetErrorStatus(0, 0); break; } break; @@ -1996,19 +2040,19 @@ void sub_8014F48(u8 taskId) case 10: DestroyListMenuTask(data->listTaskId, 0, 0); CopyBgTilemapBufferToVram(0); - RemoveWindow(data->field_D); + RemoveWindow(data->playerNameAndIdWindowId); RemoveWindow(data->listWindowId); - DestroyTask(data->field_11); + DestroyTask(data->listenTaskId); Free(data->field_0); Free(data->field_4); data->state++; break; case 9: - if (MG_PrintTextOnWindow1AndWaitButton(&data->textState, sLinkDroppedTexts[sub_8011A74()])) + if (MG_PrintTextOnWindow1AndWaitButton(&data->textState, sLinkDroppedTexts[RfuGetErrorStatus()])) { DestroyWirelessStatusIndicatorSprite(); DestroyTask(taskId); - sub_800EDD4(); + LinkRfu_Shutdown(); gSpecialVar_Result = 5; } break; @@ -2016,7 +2060,7 @@ void sub_8014F48(u8 taskId) DestroyWirelessStatusIndicatorSprite(); AddTextPrinterToWindow1(sText_PleaseStartOver); DestroyTask(taskId); - sub_800EDD4(); + LinkRfu_Shutdown(); gSpecialVar_Result = 5; break; case 11: @@ -2030,36 +2074,36 @@ void sub_8014F48(u8 taskId) } } -void MEvent_CreateTask_CardOrNewsOverWireless(u32 arg0) +void MEvent_CreateTask_CardOrNewsOverWireless(u32 activity) { u8 taskId; - struct UnkStruct_Group *dataPtr; + struct WirelessLink_Group *data; - taskId = CreateTask(sub_80152F4, 0); - gUnknown_02022C30.group = dataPtr = (void*)(gTasks[taskId].data); - gUnknown_03000DA4 = dataPtr; + taskId = CreateTask(Task_CardOrNewsOverWireless, 0); + sWirelessLinkMain.group = data = (void*)(gTasks[taskId].data); + sGroup = data; - dataPtr->state = 0; - dataPtr->textState = 0; - dataPtr->field_12 = arg0 - 21; + data->state = 0; + data->textState = 0; + data->isWonderNews = activity - ACTIVITY_WONDER_CARD2; gSpecialVar_Result = 0; } -void sub_80152F4(u8 taskId) +static void Task_CardOrNewsOverWireless(u8 taskId) { s32 id; struct WindowTemplate winTemplate; - struct UnkStruct_Group *data = gUnknown_02022C30.group; + struct WirelessLink_Group *data = sWirelessLinkMain.group; switch (data->state) { case 0: - sub_8010F84(0, 0, 0); - sub_800B488(); + SetHostRFUtgtGname(0, 0, 0); + SetWirelessCommType1(); OpenLink(); - sub_8011C5C(); - data->field_4 = AllocZeroed(0x70); - data->field_0 = AllocZeroed(0x200); + InitializeRfuLinkManager_JoinGroup(); + data->field_4 = AllocZeroed(4 * sizeof(struct UnkStruct_x1C)); + data->field_0 = AllocZeroed(16 * sizeof(struct UnkStruct_x20)); data->state = 1; break; case 1: @@ -2067,9 +2111,9 @@ void sub_80152F4(u8 taskId) data->state = 2; break; case 2: - sub_80175EC(data->field_4, 4); - sub_8017580(data->field_0->arr, 16); - data->field_11 = sub_8016FF0(data->field_4, data->field_12 + 7); + 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); if (data->field_13 != 0) { @@ -2078,18 +2122,18 @@ void sub_80152F4(u8 taskId) data->listWindowId = AddWindow(&winTemplate); MG_DrawTextBorder(data->listWindowId); - gMultiuseListMenuTemplate = gUnknown_082F0204; + gMultiuseListMenuTemplate = sListMenuTemplate_UnionRoomGroups; gMultiuseListMenuTemplate.windowId = data->listWindowId; data->listTaskId = ListMenuInit(&gMultiuseListMenuTemplate, 0, 0); CopyBgTilemapBufferToVram(0); } - data->field_F = 0; + data->leaderId = 0; data->state = 3; break; case 3: - id = sub_8013E44(); + id = GetNewLeaderCandidate(); switch (id) { case 1: @@ -2101,17 +2145,17 @@ void sub_80152F4(u8 taskId) case 0: if (data->field_13 != 0) id = ListMenu_ProcessInput(data->listTaskId); - if (data->field_14 > 120) + if (data->refreshTimer > 120) { - if (data->field_0->arr[0].field_1A_0 == 1 && !data->field_0->arr[0].unk.field_0.started) + if (data->field_0->arr[0].groupScheduledAnim == UNION_ROOM_SPAWN_IN && !data->field_0->arr[0].gname_uname.gname.started) { - if (sub_8016F1C(&data->field_0->arr[0].unk.field_0, data->field_12 + 7)) + if (GetGnameWonderFlagByLinkGroup(&data->field_0->arr[0].gname_uname.gname, data->isWonderNews + LINK_GROUP_WONDER_CARD)) { - data->field_F = 0; - data->field_14 = 0; + data->leaderId = 0; + data->refreshTimer = 0; LoadWirelessStatusIndicatorSpriteGfx(); CreateWirelessStatusIndicatorSprite(0, 0); - sub_8011FC8(data->field_0->arr[0].unk.playerName, ReadAsU16(data->field_0->arr[0].unk.field_0.unk_00.playerTrainerId)); + CreateTask_RfuReconnectWithParent(data->field_0->arr[0].gname_uname.playerName, ReadAsU16(data->field_0->arr[0].gname_uname.gname.unk_00.playerTrainerId)); PlaySE(SE_PN_ON); data->state = 4; } @@ -2125,25 +2169,25 @@ void sub_80152F4(u8 taskId) else if (gMain.newKeys & B_BUTTON) { data->state = 6; - data->field_14 = 0; + data->refreshTimer = 0; } - data->field_14++; + data->refreshTimer++; break; } break; case 4: AddTextPrinterToWindow1(sText_AwaitingResponseFromWirelessSystem); - sub_8018404(gStringVar1, &data->field_0->arr[data->field_F]); + IntlConvPartnerUname7(gStringVar1, &data->field_0->arr[data->leaderId]); data->state = 5; break; case 5: - if (gReceivedRemoteLinkPlayers != 0) + if (gReceivedRemoteLinkPlayers) { - gUnknown_02022C2C = data->field_0->arr[data->field_F].unk.field_0.activity; + gPlayerCurrActivity = data->field_0->arr[data->leaderId].gname_uname.gname.activity; data->state = 12; } - switch (sub_8011A74()) + switch (RfuGetErrorStatus()) { case 1: case 2: @@ -2152,7 +2196,7 @@ void sub_80152F4(u8 taskId) break; case 5: AddTextPrinterToWindow1(sText_WirelessLinkEstablished); - sub_8011A64(0, 0); + RfuSetErrorStatus(0, 0); break; } break; @@ -2166,7 +2210,7 @@ void sub_80152F4(u8 taskId) CopyBgTilemapBufferToVram(0); RemoveWindow(data->listWindowId); } - DestroyTask(data->field_11); + DestroyTask(data->listenTaskId); Free(data->field_0); Free(data->field_4); data->state++; @@ -2176,7 +2220,7 @@ void sub_80152F4(u8 taskId) { DestroyWirelessStatusIndicatorSprite(); DestroyTask(taskId); - sub_800EDD4(); + LinkRfu_Shutdown(); gSpecialVar_Result = 5; } break; @@ -2185,16 +2229,16 @@ void sub_80152F4(u8 taskId) { DestroyWirelessStatusIndicatorSprite(); DestroyTask(taskId); - sub_800EDD4(); + LinkRfu_Shutdown(); gSpecialVar_Result = 5; } break; case 11: - if (MG_PrintTextOnWindow1AndWaitButton(&data->textState, sNoWonderSharedTexts[data->field_12])) + if (MG_PrintTextOnWindow1AndWaitButton(&data->textState, sNoWonderSharedTexts[data->isWonderNews])) { DestroyWirelessStatusIndicatorSprite(); DestroyTask(taskId); - sub_800EDD4(); + LinkRfu_Shutdown(); gSpecialVar_Result = 5; } break; @@ -2211,35 +2255,35 @@ void sub_80152F4(u8 taskId) void UnionRoomSpecial(void) { - struct UnkStruct_URoom *dataPtr; + struct WirelessLink_URoom *data; - sub_8010F60(); - CreateTask(sub_80156E0, 10); + ClearAndInitHostRFUtgtGname(); + CreateTask(Task_RunUnionRoom, 10); // dumb line needed to match - gUnknown_02022C30.uRoom = gUnknown_02022C30.uRoom; + sWirelessLinkMain.uRoom = sWirelessLinkMain.uRoom; - dataPtr = AllocZeroed(sizeof(*gUnknown_02022C30.uRoom)); - gUnknown_02022C30.uRoom = dataPtr; - gUnknown_03000DA8 = dataPtr; + data = AllocZeroed(sizeof(*sWirelessLinkMain.uRoom)); + sWirelessLinkMain.uRoom = data; + sURoom = data; - dataPtr->state = 0; - dataPtr->textState = 0; - dataPtr->field_10 = 0; - dataPtr->field_12 = 0; + data->state = 0; + data->textState = 0; + data->field_10 = 0; + data->field_12 = 0; gSpecialVar_Result = 0; - sub_819A2BC(0xD0, 1); + ListMenuLoadStdPalAt(0xD0, 1); } -u16 ReadAsU16(const u8 *ptr) +static u16 ReadAsU16(const u8 *ptr) { return (ptr[1] << 8) | (ptr[0]); } -void sub_8015664(u32 nextState, const u8 *src) +static void ScheduleFieldMessageWithFollowupState(u32 nextState, const u8 *src) { - struct UnkStruct_URoom *data = gUnknown_02022C30.uRoom; + struct WirelessLink_URoom *data = sWirelessLinkMain.uRoom; data->state = 8; data->stateAfterPrint = nextState; @@ -2247,83 +2291,83 @@ void sub_8015664(u32 nextState, const u8 *src) StringExpandPlaceholders(gStringVar4, src); } -void sub_801568C(const u8 *src) +static void ScheduleFieldMessageAndExit(const u8 *src) { - struct UnkStruct_URoom *data = gUnknown_02022C30.uRoom; + struct WirelessLink_URoom *data = sWirelessLinkMain.uRoom; data->state = 26; if (src != gStringVar4) StringExpandPlaceholders(gStringVar4, src); } -void sub_80156B0(struct UnkStruct_URoom *data) +static void sub_80156B0(struct WirelessLink_URoom *data) { memcpy(&gDecompressionBuffer[0x3F00], data->field_0, 0x100); } -void sub_80156C8(struct UnkStruct_URoom *data) +static void sub_80156C8(struct WirelessLink_URoom *data) { memcpy(data->field_0, &gDecompressionBuffer[0x3F00], 0x100); } -void sub_80156E0(u8 taskId) +static void Task_RunUnionRoom(u8 taskId) { u32 id = 0; s32 var5 = 0; - s32 playerGender = 0; - struct UnkStruct_URoom *data = gUnknown_02022C30.uRoom; + s32 playerGender = MALE; + struct WirelessLink_URoom *data = sWirelessLinkMain.uRoom; s16 *taskData = gTasks[taskId].data; switch (data->state) { case 0: - data->field_4 = AllocZeroed(0x70); - data->field_C = AllocZeroed(0x70); - data->field_0 = AllocZeroed(0x100); - data->field_8 = AllocZeroed(0x20); - sub_8017580(data->field_0->arr, 8); - gUnknown_02022C2C = 0x40; - data->field_20 = sub_8016DF0(data->field_C, data->field_4, 9); + 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)); + ClearUnkStruct_x20Array(data->field_0->arr, 8); + gPlayerCurrActivity = IN_UNION_ROOM; + data->field_20 = CreateTask_SearchForChildOrParent(data->field_C, data->field_4, LINK_GROUP_UNION_ROOM_RESUME); sub_8019BA8(data->field_A0); sub_8019F2C(); data->state = 1; break; case 1: - sub_8019E70(data->spriteIds, taskData[0]); + CreateGroupMemberObjectsInvisible(data->spriteIds, taskData[0]); if (++taskData[0] == 8) data->state = 2; break; case 2: - sub_8010F84(0x40, 0, 0); + SetHostRFUtgtGname(IN_UNION_ROOM, 0, 0); sub_8010FCC(sUnionRoomTrade.type, sUnionRoomTrade.playerSpecies, sUnionRoomTrade.playerLevel); - sub_800B488(); + SetWirelessCommType1(); OpenLink(); - sub_8011C84(); - sub_8017580(&data->field_8->arr[0], 1); - sub_80175EC(data->field_4, 4); - sub_80175EC(data->field_C, 4); + InitializeRfuLinkManager_EnterUnionRoom(); + ClearUnkStruct_x20Array(&data->field_8->arr[0], 1); + ClearUnkStruct_x1CArray(data->field_4, 4); + ClearUnkStruct_x1CArray(data->field_C, 4); gSpecialVar_Result = 0; data->state = 3; break; case 3: if ((GetPartyMenuType() == PARTY_MENU_TYPE_UNION_ROOM_REGISTER - || GetPartyMenuType() == PARTY_MENU_TYPE_UNION_ROOM_TRADE) + || GetPartyMenuType() == PARTY_MENU_TYPE_UNION_ROOM_TRADE) && sUnionRoomTrade.field_0 != 0) { id = GetCursorSelectionMonId(); switch (sUnionRoomTrade.field_0) { case 1: - sub_8011090(0x54, 0, 1); + UpdateGameDataWithActivitySpriteGendersFlag(ACTIVITY_PLYRTALK | IN_UNION_ROOM, 0, TRUE); if (id >= PARTY_SIZE) { ResetUnionRoomTrade(&sUnionRoomTrade); sub_8010FCC(0, 0, 0); - sub_801568C(sText_RegistrationCanceled); + ScheduleFieldMessageAndExit(sText_RegistrationCanceled); } else if (!RegisterTradeMonAndGetIsEgg(GetCursorSelectionMonId(), &sUnionRoomTrade)) { - sub_8015664(0x34, sText_ChooseRequestedMonType); + ScheduleFieldMessageWithFollowupState(52, sText_ChooseRequestedMonType); } else { @@ -2335,12 +2379,12 @@ void sub_80156E0(u8 taskId) taskData[1] = sUnionRoomTrade.field_8; if (id >= PARTY_SIZE) { - sub_801568C(sText_TradeCanceled); + ScheduleFieldMessageAndExit(sText_TradeCanceled); } else { - sub_8011090(0x54, 0, 1); - gUnknown_02022C2C = 0x44; + UpdateGameDataWithActivitySpriteGendersFlag(ACTIVITY_PLYRTALK | IN_UNION_ROOM, 0, TRUE); + gPlayerCurrActivity = ACTIVITY_TRADE | IN_UNION_ROOM; RegisterTradeMon(GetCursorSelectionMonId(), &sUnionRoomTrade); data->state = 51; } @@ -2358,7 +2402,7 @@ void sub_80156E0(u8 taskId) { if (gSpecialVar_Result == 9) { - sub_8011090(0x54, 0, 1); + UpdateGameDataWithActivitySpriteGendersFlag(ACTIVITY_PLYRTALK | IN_UNION_ROOM, 0, 1); PlaySE(SE_PC_LOGIN); StringCopy(gStringVar1, gSaveBlock2Ptr->playerName); data->state = 42; @@ -2366,7 +2410,7 @@ void sub_80156E0(u8 taskId) } else if (gSpecialVar_Result == 11) { - sub_8011090(0x54, 0, 1); + UpdateGameDataWithActivitySpriteGendersFlag(ACTIVITY_PLYRTALK | IN_UNION_ROOM, 0, 1); data->state = 23; gSpecialVar_Result = 0; } @@ -2382,146 +2426,146 @@ void sub_80156E0(u8 taskId) { if (gMain.newKeys & A_BUTTON) { - if (sub_801A2A8(data->field_0, &taskData[0], &taskData[1], data->spriteIds)) + if (RfuUnionTool_GetGroupAndMemberInFrontOfPlayer(data->field_0, &taskData[0], &taskData[1], data->spriteIds)) { PlaySE(SE_SELECT); - sub_80181CC(); + UR_EnableScriptContext2AndFreezeObjectEvents(); data->state = 24; break; } - else if (sub_8017940()) + else if (PlayerIsTalkingToUnionRoomAide()) { - sub_8011090(0x54, 0, 1); + UpdateGameDataWithActivitySpriteGendersFlag(ACTIVITY_PLYRTALK | IN_UNION_ROOM, 0, 1); PlaySE(SE_PC_LOGIN); - sub_80181CC(); + UR_EnableScriptContext2AndFreezeObjectEvents(); StringCopy(gStringVar1, gSaveBlock2Ptr->playerName); data->state = 45; break; } } - switch (sub_8016B00()) + switch (HandlePlayerListUpdate()) { case 1: PlaySE(SE_PC_LOGIN); case 2: - sub_801A274(data); + ScheduleUnionRoomPlayerRefresh(data); break; case 4: data->state = 11; - sub_80181CC(); + UR_EnableScriptContext2AndFreezeObjectEvents(); sub_8010FCC(0, 0, 0); - sub_8011090(0x53, sub_80181DC(data), 0); + UpdateGameDataWithActivitySpriteGendersFlag(ACTIVITY_NPCTALK | IN_UNION_ROOM, GetActivePartnerSpriteGenderParam(data), 0); break; } - sub_801A284(data); + HandleUnionRoomPlayerRefresh(data); } break; case 23: if (!FuncIsActiveTask(Task_ShowStartMenu)) { - sub_8011090(0x40, 0, 0); + UpdateGameDataWithActivitySpriteGendersFlag(IN_UNION_ROOM, 0, FALSE); data->state = 4; } break; case 24: - sub_801704C(); - playerGender = sub_8017CF8(taskData[1], data->field_0); - sub_8011090(0x54, 0, 1); - switch (sub_80179D4(data->field_0, taskData[0], taskData[1], playerGender)) + 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)) { case 0: data->state = 26; break; case 1: - sub_8012188(data->field_0->arr[taskData[1]].unk.playerName, &data->field_0->arr[taskData[1]].unk.field_0, gUnknown_02022C2C); + sub_8012188(data->field_0->arr[taskData[1]].gname_uname.playerName, &data->field_0->arr[taskData[1]].gname_uname.gname, gPlayerCurrActivity); data->field_12 = id; // Should be just 0, but won't match any other way. data->state = 25; break; case 2: - sub_8015664(0x13, gStringVar4); + ScheduleFieldMessageWithFollowupState(19, gStringVar4); break; } break; case 25: - sub_801704C(); - switch (sub_8011A74()) + UR_RunTextPrinters_CheckPrinter0Active(); + switch (RfuGetErrorStatus()) { case 4: - sub_801818C(TRUE); + HandleCancelTrade(TRUE); data->state = 4; break; case 1: case 2: - if (sub_8011B90() == TRUE) - sub_801568C(sText_TrainerAppearsBusy); + if (IsUnionRoomListenTaskActive() == TRUE) + ScheduleFieldMessageAndExit(sText_TrainerAppearsBusy); else - sub_8015664(30, sText_TrainerAppearsBusy); + ScheduleFieldMessageWithFollowupState(30, sText_TrainerAppearsBusy); - gUnknown_02022C2C = 0x40; + gPlayerCurrActivity = IN_UNION_ROOM; break; } - if (gReceivedRemoteLinkPlayers != 0) + if (gReceivedRemoteLinkPlayers) { - sub_80143E4(gBlockSendBuffer, TRUE); - CreateTask(sub_80140E0, 5); + CreateTrainerCardInBuffer(gBlockSendBuffer, TRUE); + CreateTask(Task_ExchangeCards, 5); data->state = 38; } break; case 38: - if (!FuncIsActiveTask(sub_80140E0)) + if (!FuncIsActiveTask(Task_ExchangeCards)) { - if (gUnknown_02022C2C == 0x44) - sub_8015664(31, sText_AwaitingPlayersResponseAboutTrade); + if (gPlayerCurrActivity == (ACTIVITY_TRADE | IN_UNION_ROOM)) + ScheduleFieldMessageWithFollowupState(31, sText_AwaitingPlayersResponseAboutTrade); else data->state = 5; } break; case 30: - if (gReceivedRemoteLinkPlayers == 0) + if (!gReceivedRemoteLinkPlayers) { - sub_801818C(FALSE); - sub_801A3D0(taskData[0], taskData[1], data->field_0); + HandleCancelTrade(FALSE); + UpdateUnionGroupMemberFacing(taskData[0], taskData[1], data->field_0); data->state = 2; } break; case 5: - id = sub_80179AC(&data->field_0->arr[taskData[1]]); - playerGender = sub_8017CF8(taskData[1], data->field_0); - sub_8015664(6, sHiDoSomethingTexts[id][playerGender]); + id = ConvPartnerUnameAndGetWhetherMetAlready(&data->field_0->arr[taskData[1]]); + playerGender = GetUnionRoomPlayerGender(taskData[1], data->field_0); + ScheduleFieldMessageWithFollowupState(6, sHiDoSomethingTexts[id][playerGender]); break; case 6: - var5 = sub_8017178(&data->textState, &data->field_1B, &data->field_1C, &gUnknown_082F021C, &gUnknown_082F0244); + var5 = ListMenuHandler_AllItemsAvailable(&data->textState, &data->topListMenuWindowId, &data->topListMenuId, &sWindowTemplate_InviteToActivity, &sListMenuTemplate_InviteToActivity); if (var5 != -1) { - if (gReceivedRemoteLinkPlayers == 0) + if (!gReceivedRemoteLinkPlayers) { data->state = 28; } else { - data->field_98 = 0; - playerGender = sub_8017CF8(taskData[1], data->field_0); - if (var5 == -2 || var5 == 0x40) + data->partnerYesNoResponse = 0; + playerGender = GetUnionRoomPlayerGender(taskData[1], data->field_0); + if (var5 == -2 || var5 == IN_UNION_ROOM) { - data->field_4C[0] = 0x40; - sub_800FE50(data->field_4C); + data->playerSendBuffer[0] = IN_UNION_ROOM; + sub_800FE50(data->playerSendBuffer); StringCopy(gStringVar4, sIfYouWantToDoSomethingTexts[gLinkPlayers[0].gender]); data->state = 32; } else { - gUnknown_02022C2C = var5; - gUnknown_02022C2D = (u32)(var5) >> 8; - if (gUnknown_02022C2C == 0x41 && !HasAtLeastTwoMonsOfLevel30OrLower()) + gPlayerCurrActivity = var5; + sPlayerActivityGroupSize = (u32)(var5) >> 8; + if (gPlayerCurrActivity == (ACTIVITY_BATTLE_SINGLE | IN_UNION_ROOM) && !HasAtLeastTwoMonsOfLevel30OrLower()) { - sub_8015664(5, sText_NeedTwoMonsOfLevel30OrLower1); + ScheduleFieldMessageWithFollowupState(5, sText_NeedTwoMonsOfLevel30OrLower1); } else { - data->field_4C[0] = gUnknown_02022C2C | 0x40; - sub_800FE50(data->field_4C); + data->playerSendBuffer[0] = gPlayerCurrActivity | 0x40; + sub_800FE50(data->playerSendBuffer); data->state = 27; } } @@ -2533,9 +2577,9 @@ void sub_80156E0(u8 taskId) data->state = 36; break; case 27: - sub_8017FD8(data); - playerGender = sub_8017CF8(taskData[1], data->field_0); - id = sub_8017984(data->field_4C[0] & 0x3F); + PollPartnerYesNoResponse(data); + playerGender = GetUnionRoomPlayerGender(taskData[1], data->field_0); + id = GetResponseIdx_InviteToURoomActivity(data->playerSendBuffer[0] & 0x3F); if (PrintOnTextbox(&data->textState, sText_WaitOrShowCardTexts[playerGender][id])) { taskData[3] = 0; @@ -2547,26 +2591,26 @@ void sub_80156E0(u8 taskId) data->state = 36; break; case 31: - data->field_4C[0] = 0x44; - data->field_4C[1] = sUnionRoomTrade.species; - data->field_4C[2] = sUnionRoomTrade.level; - sub_800FE50(data->field_4C); + data->playerSendBuffer[0] = ACTIVITY_TRADE | IN_UNION_ROOM; + data->playerSendBuffer[1] = sUnionRoomTrade.species; + data->playerSendBuffer[2] = sUnionRoomTrade.level; + sub_800FE50(data->playerSendBuffer); data->state = 29; break; case 29: - if (gReceivedRemoteLinkPlayers == 0) + if (!gReceivedRemoteLinkPlayers) { StringCopy(gStringVar4, sText_TrainerBattleBusy); data->state = 28; } else { - sub_8017FD8(data); - if (data->field_98 == 0x51) + PollPartnerYesNoResponse(data); + if (data->partnerYesNoResponse == (ACTIVITY_ACCEPT | IN_UNION_ROOM)) { - if (gUnknown_02022C2C == 8) + if (gPlayerCurrActivity == ACTIVITY_CARD) { - sub_8018220(gStringVar4, data, FALSE); + ViewURoomPartnerTrainerCard(gStringVar4, data, FALSE); data->state = 40; } else @@ -2574,27 +2618,27 @@ void sub_80156E0(u8 taskId) data->state = 13; } } - else if (data->field_98 == 0x52) + else if (data->partnerYesNoResponse == (ACTIVITY_DECLINE | IN_UNION_ROOM)) { data->state = 32; - sub_8017D9C(gStringVar4, gUnknown_02022C2C | 0x40, gLinkPlayers[0].gender); - gUnknown_02022C2C = 0; + GetURoomActivityRejectMsg(gStringVar4, gPlayerCurrActivity | IN_UNION_ROOM, gLinkPlayers[0].gender); + gPlayerCurrActivity = ACTIVITY_NONE; } } break; case 7: - id = sub_80179AC(&data->field_0->arr[taskData[1]]); - playerGender = sub_8017CF8(taskData[1], data->field_0); - sub_8015664(6, sHiDoSomethingTexts[id][playerGender]); + id = ConvPartnerUnameAndGetWhetherMetAlready(&data->field_0->arr[taskData[1]]); + playerGender = GetUnionRoomPlayerGender(taskData[1], data->field_0); + ScheduleFieldMessageWithFollowupState(6, sHiDoSomethingTexts[id][playerGender]); break; case 40: if (PrintOnTextbox(&data->textState, gStringVar4)) { data->state = 41; sub_800ADF8(); - data->field_98 = 0; - data->field_9A[0] = 0; + data->partnerYesNoResponse = 0; + data->recvActivityRequest[0] = 0; } break; case 41: @@ -2603,7 +2647,7 @@ void sub_80156E0(u8 taskId) if (GetMultiplayerId() == 0) { StringCopy(gStringVar1, gLinkPlayers[GetMultiplayerId() ^ 1].name); - id = sub_800E540(gLinkPlayers[1].trainerId, gLinkPlayers[1].name); + id = PlayerHasMetTrainerBefore(gLinkPlayers[1].trainerId, gLinkPlayers[1].name); StringExpandPlaceholders(gStringVar4, sAwaitingResponseTexts[id]); data->state = 33; } @@ -2614,21 +2658,21 @@ void sub_80156E0(u8 taskId) } break; case 19: - switch (sub_80170B8(&data->textState, FALSE)) + switch (UnionRoomHandleYesNo(&data->textState, FALSE)) { case 0: CopyBgTilemapBufferToVram(0); - gUnknown_02022C2C = 0x45; - sub_8011090(0x45, 0, 1); - sub_8012188(data->field_0->arr[taskData[1]].unk.playerName, &data->field_0->arr[taskData[1]].unk.field_0, gUnknown_02022C2C); + 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); data->field_12 = taskData[1]; data->state = 20; taskData[3] = 0; break; case 1: case -1: - playerGender = sub_8017CF8(taskData[1], data->field_0); - sub_801568C(sDeclineBattleTexts[playerGender]); + playerGender = GetUnionRoomPlayerGender(taskData[1], data->field_0); + ScheduleFieldMessageAndExit(sDeclineBattleTexts[playerGender]); break; } break; @@ -2640,20 +2684,20 @@ void sub_80156E0(u8 taskId) } break; case 21: - switch (sub_8011A74()) + switch (RfuGetErrorStatus()) { case 4: - sub_801818C(TRUE); + HandleCancelTrade(TRUE); data->state = 4; break; case 1: case 2: - playerGender = sub_8017CF8(taskData[1], data->field_0); - sub_8011090(0x54, 0, 1); - if (sub_8011B90() == TRUE) - sub_801568C(sChatDeclinedTexts[playerGender]); + playerGender = GetUnionRoomPlayerGender(taskData[1], data->field_0); + UpdateGameDataWithActivitySpriteGendersFlag(ACTIVITY_PLYRTALK | IN_UNION_ROOM, 0, 1); + if (IsUnionRoomListenTaskActive() == TRUE) + ScheduleFieldMessageAndExit(sChatDeclinedTexts[playerGender]); else - sub_8015664(30, sChatDeclinedTexts[playerGender]); + ScheduleFieldMessageWithFollowupState(30, sChatDeclinedTexts[playerGender]); break; case 3: data->state = 22; @@ -2662,55 +2706,55 @@ void sub_80156E0(u8 taskId) taskData[3]++; break; case 22: - if (sub_8011A80()) + if (RfuIsErrorStatus1or2()) { - playerGender = sub_8017CF8(taskData[1], data->field_0); - sub_8011090(0x54, 0, 1); - if (sub_8011B90() == TRUE) - sub_801568C(sChatDeclinedTexts[playerGender]); + playerGender = GetUnionRoomPlayerGender(taskData[1], data->field_0); + UpdateGameDataWithActivitySpriteGendersFlag(ACTIVITY_PLYRTALK | IN_UNION_ROOM, 0, 1); + if (IsUnionRoomListenTaskActive() == TRUE) + ScheduleFieldMessageAndExit(sChatDeclinedTexts[playerGender]); else - sub_8015664(30, sChatDeclinedTexts[playerGender]); + ScheduleFieldMessageWithFollowupState(30, sChatDeclinedTexts[playerGender]); } - if (gReceivedRemoteLinkPlayers != 0) + if (gReceivedRemoteLinkPlayers) data->state = 16; break; case 11: PlaySE(SE_PINPON); sub_800EF7C(); data->state = 12; - data->field_9A[0] = 0; + data->recvActivityRequest[0] = 0; break; case 12: - if (sub_8011A80()) + if (RfuIsErrorStatus1or2()) { - sub_801818C(FALSE); + HandleCancelTrade(FALSE); data->state = 2; } - else if (gReceivedRemoteLinkPlayers != 0) + else if (gReceivedRemoteLinkPlayers) { - sub_80143E4(gBlockSendBuffer, TRUE); - CreateTask(sub_80140E0, 5); + CreateTrainerCardInBuffer(gBlockSendBuffer, TRUE); + CreateTask(Task_ExchangeCards, 5); data->state = 39; } break; case 39: - sub_801689C(data); - if (!FuncIsActiveTask(sub_80140E0)) + ReceiveUnionRoomActivityPacket(data); + if (!FuncIsActiveTask(Task_ExchangeCards)) { data->state = 33; StringCopy(gStringVar1, gLinkPlayers[1].name); - id = sub_800E540(gLinkPlayers[1].trainerId, gLinkPlayers[1].name); + id = PlayerHasMetTrainerBefore(gLinkPlayers[1].trainerId, gLinkPlayers[1].name); StringExpandPlaceholders(gStringVar4, sPlayerContactedYouTexts[id]); } break; case 33: - sub_801689C(data); + ReceiveUnionRoomActivityPacket(data); if (PrintOnTextbox(&data->textState, gStringVar4)) data->state = 34; break; case 34: - sub_801689C(data); - if (sub_80168DC(data) && gMain.newKeys & B_BUTTON) + ReceiveUnionRoomActivityPacket(data); + if (UnionRoom_HandleContactFromOtherPlayer(data) && gMain.newKeys & B_BUTTON) { sub_8011DE0(1); StringCopy(gStringVar4, sText_ChatEnded); @@ -2718,53 +2762,53 @@ void sub_80156E0(u8 taskId) } break; case 35: - sub_8015664(9, gStringVar4); + ScheduleFieldMessageWithFollowupState(9, gStringVar4); break; case 9: - switch (sub_80170B8(&data->textState, FALSE)) + switch (UnionRoomHandleYesNo(&data->textState, FALSE)) { case 0: - data->field_4C[0] = 0x51; - if (gUnknown_02022C2C == 0x45) - sub_8011090(gUnknown_02022C2C | 0x40, sub_801100C(1), 0); + data->playerSendBuffer[0] = ACTIVITY_ACCEPT | IN_UNION_ROOM; + if (gPlayerCurrActivity == (ACTIVITY_CHAT | IN_UNION_ROOM)) + UpdateGameDataWithActivitySpriteGendersFlag(gPlayerCurrActivity | 0x40, sub_801100C(1), 0); else - sub_8011090(gUnknown_02022C2C | 0x40, sub_801100C(1), 1); + UpdateGameDataWithActivitySpriteGendersFlag(gPlayerCurrActivity | 0x40, sub_801100C(1), 1); data->field_8->arr[0].field_1B = 0; taskData[3] = 0; - if (gUnknown_02022C2C == 0x41) + if (gPlayerCurrActivity == (ACTIVITY_BATTLE_SINGLE | IN_UNION_ROOM)) { if (!HasAtLeastTwoMonsOfLevel30OrLower()) { - data->field_4C[0] = 0x52; - sub_800FE50(data->field_4C); + data->playerSendBuffer[0] = ACTIVITY_DECLINE | IN_UNION_ROOM; + sub_800FE50(data->playerSendBuffer); data->state = 10; StringCopy(gStringVar4, sText_NeedTwoMonsOfLevel30OrLower2); } else { - sub_800FE50(data->field_4C); + sub_800FE50(data->playerSendBuffer); data->state = 13; } } - else if (gUnknown_02022C2C == 0x48) + else if (gPlayerCurrActivity == (ACTIVITY_CARD | IN_UNION_ROOM)) { - sub_800FE50(data->field_4C); - sub_8018220(gStringVar4, data, 1); + sub_800FE50(data->playerSendBuffer); + ViewURoomPartnerTrainerCard(gStringVar4, data, TRUE); data->state = 40; } else { - sub_800FE50(data->field_4C); + sub_800FE50(data->playerSendBuffer); data->state = 13; } break; case 1: case -1: - data->field_4C[0] = 0x52; - sub_800FE50(data->field_4C); + data->playerSendBuffer[0] = ACTIVITY_DECLINE | IN_UNION_ROOM; + sub_800FE50(data->playerSendBuffer); data->state = 10; - sub_8013078(gStringVar4, gUnknown_02022C2C); + GetYouDeclinedTheOfferMessage(gStringVar4, gPlayerCurrActivity); break; } break; @@ -2773,22 +2817,22 @@ void sub_80156E0(u8 taskId) data->state = 36; break; case 36: - if (gReceivedRemoteLinkPlayers == 0) + if (!gReceivedRemoteLinkPlayers) { - gUnknown_02022C2C = 0x40; - sub_8015664(0x25, gStringVar4); - memset(data->field_4C, 0, sizeof(data->field_4C)); - data->field_9A[0] = 0; - data->field_98 = 0; + gPlayerCurrActivity = IN_UNION_ROOM; + ScheduleFieldMessageWithFollowupState(37, gStringVar4); + memset(data->playerSendBuffer, 0, sizeof(data->playerSendBuffer)); + data->recvActivityRequest[0] = 0; + data->partnerYesNoResponse = 0; } break; case 37: data->state = 2; - sub_801818C(FALSE); + HandleCancelTrade(FALSE); break; case 13: - sub_8017E00(gStringVar4, gUnknown_02022C2C | 0x40); - sub_8015664(14, gStringVar4); + GetURoomActivityStartMsg(gStringVar4, gPlayerCurrActivity | IN_UNION_ROOM); + ScheduleFieldMessageWithFollowupState(14, gStringVar4); break; case 14: sub_800ADF8(); @@ -2804,7 +2848,7 @@ void sub_80156E0(u8 taskId) Free(data->field_C); Free(data->field_4); DestroyTask(data->field_20); - sub_8019F04(data->spriteIds); + DestroyGroupMemberObjects(data->spriteIds); data->state = 17; break; case 17: @@ -2816,28 +2860,28 @@ void sub_80156E0(u8 taskId) { sub_8019E3C(); DestroyTask(taskId); - Free(gUnknown_02022C30.uRoom); - sub_80149D8(); + Free(sWirelessLinkMain.uRoom); + CreateTask_StartActivity(); } break; case 42: - if (sub_800F7DC()->species == SPECIES_NONE) + if (GetHostRFUtgtGname()->species == SPECIES_NONE) { data->state = 43; } else { - if (sub_800F7DC()->species == SPECIES_EGG) + if (GetHostRFUtgtGname()->species == SPECIES_EGG) { StringCopy(gStringVar4, sText_CancelRegistrationOfEgg); } else { - StringCopy(gStringVar1, gSpeciesNames[sub_800F7DC()->species]); - ConvertIntToDecimalStringN(gStringVar2, sub_800F7DC()->level, STR_CONV_MODE_LEFT_ALIGN, 3); + StringCopy(gStringVar1, gSpeciesNames[GetHostRFUtgtGname()->species]); + ConvertIntToDecimalStringN(gStringVar2, GetHostRFUtgtGname()->level, STR_CONV_MODE_LEFT_ALIGN, 3); StringExpandPlaceholders(gStringVar4, sText_CancelRegistrationOfMon); } - sub_8015664(44, gStringVar4); + ScheduleFieldMessageWithFollowupState(44, gStringVar4); } break; case 43: @@ -2845,23 +2889,23 @@ void sub_80156E0(u8 taskId) data->state = 47; break; case 47: - var5 = sub_8017178(&data->textState, &data->field_1D, &data->field_1E, &gUnknown_082F025C, &gUnknown_082F027C); + var5 = ListMenuHandler_AllItemsAvailable(&data->textState, &data->tradeBoardSelectWindowId, &data->tradeBoardDetailsWindowId, &gUnknown_082F025C, &gUnknown_082F027C); if (var5 != -1) { if (var5 == -2 || var5 == 3) { data->state = 4; - sub_801818C(TRUE); + HandleCancelTrade(TRUE); } else { switch (var5) { case 1: // REGISTER - sub_8015664(53, sText_WhichMonWillYouOffer); + ScheduleFieldMessageWithFollowupState(53, sText_WhichMonWillYouOffer); break; case 2: // INFO - sub_8015664(47, sText_TradingBoardInfo); + ScheduleFieldMessageWithFollowupState(47, sText_TradingBoardInfo); break; } } @@ -2880,7 +2924,7 @@ void sub_80156E0(u8 taskId) } break; case 52: - var5 = sub_8017178(&data->textState, &data->field_1D, &data->field_1E, &gUnknown_082F0294, &sMenuTemplate_TradingBoardRequestType); + var5 = ListMenuHandler_AllItemsAvailable(&data->textState, &data->tradeBoardSelectWindowId, &data->tradeBoardDetailsWindowId, &gUnknown_082F0294, &sMenuTemplate_TradingBoardRequestType); if (var5 != -1) { switch (var5) @@ -2889,7 +2933,7 @@ void sub_80156E0(u8 taskId) case 18: ResetUnionRoomTrade(&sUnionRoomTrade); sub_8010FCC(0, 0, 0); - sub_801568C(sText_RegistrationCanceled); + ScheduleFieldMessageAndExit(sText_RegistrationCanceled); break; default: sUnionRoomTrade.type = var5; @@ -2900,17 +2944,17 @@ void sub_80156E0(u8 taskId) break; case 55: sub_8010FCC(sUnionRoomTrade.type, sUnionRoomTrade.playerSpecies, sUnionRoomTrade.playerLevel); - sub_801568C(sText_RegistraionCompleted); + ScheduleFieldMessageAndExit(sText_RegistraionCompleted); break; case 44: - switch (sub_80170B8(&data->textState, FALSE)) + switch (UnionRoomHandleYesNo(&data->textState, FALSE)) { case 0: data->state = 56; break; case 1: case -1: - sub_801818C(TRUE); + HandleCancelTrade(TRUE); data->state = 4; break; } @@ -2920,7 +2964,7 @@ void sub_80156E0(u8 taskId) { sub_8010FCC(0, 0, 0); ResetUnionRoomTrade(&sUnionRoomTrade); - sub_801818C(TRUE); + HandleCancelTrade(TRUE); data->state = 4; } break; @@ -2929,38 +2973,38 @@ void sub_80156E0(u8 taskId) data->state = 46; break; case 46: - sub_80173B0(); + UR_ClearBg0(); data->state = 48; break; case 48: - var5 = sub_80172A0(&data->textState, &data->field_1D, &data->field_4A, &data->field_1E, &gUnknown_082F034C, &gUnknown_082F03A4, data->field_0); + var5 = TradeBoardMenuHandler(&data->textState, &data->tradeBoardSelectWindowId, &data->field_4A, &data->tradeBoardDetailsWindowId, &gUnknown_082F034C, &sTradeBoardListMenuTemplate, data->field_0); if (var5 != -1) { switch (var5) { case -2: case 8: - sub_801818C(TRUE); + HandleCancelTrade(TRUE); data->state = 4; break; default: - sub_80173B0(); - switch (sub_8017D04(data->field_0->arr[var5].unk.field_0.type, data->field_0->arr[var5].unk.field_0.species)) + UR_ClearBg0(); + switch (IsRequestedTypeOrEggInPlayerParty(data->field_0->arr[var5].gname_uname.gname.type, data->field_0->arr[var5].gname_uname.gname.species)) { - case 0: - sub_8018404(gStringVar1, &data->field_0->arr[var5]); - sub_8015664(49, sText_AskTrainerToMakeTrade); + case UR_TRADE_MATCH: + IntlConvPartnerUname7(gStringVar1, &data->field_0->arr[var5]); + ScheduleFieldMessageWithFollowupState(49, sText_AskTrainerToMakeTrade); taskData[1] = var5; break; - case 1: - sub_8018404(gStringVar1, &data->field_0->arr[var5]); - StringCopy(gStringVar2, gTypeNames[data->field_0->arr[var5].unk.field_0.type]); - sub_8015664(46, sText_DontHaveTypeTrainerWants); + 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); break; - case 2: - sub_8018404(gStringVar1, &data->field_0->arr[var5]); - StringCopy(gStringVar2, gTypeNames[data->field_0->arr[var5].unk.field_0.type]); - sub_8015664(46, sText_DontHaveEggTrainerWants); + 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); break; } break; @@ -2968,14 +3012,14 @@ void sub_80156E0(u8 taskId) } break; case 49: - switch (sub_80170B8(&data->textState, FALSE)) + switch (UnionRoomHandleYesNo(&data->textState, FALSE)) { case 0: data->state = 50; break; case -1: case 1: - sub_801818C(TRUE); + HandleCancelTrade(TRUE); data->state = 4; break; } @@ -2984,9 +3028,9 @@ void sub_80156E0(u8 taskId) if (PrintOnTextbox(&data->textState, sText_WhichMonWillYouOffer)) { sUnionRoomTrade.field_0 = 2; - memcpy(&gUnknown_02022C38, &data->field_0->arr[taskData[1]].unk.field_0.unk_00, sizeof(gUnknown_02022C38)); - gUnionRoomRequestedMonType = data->field_0->arr[taskData[1]].unk.field_0.type; - gUnionRoomOfferedSpecies = data->field_0->arr[taskData[1]].unk.field_0.species; + 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; gFieldCallback = FieldCB_ContinueScriptUnionRoom; ChooseMonForTradingBoard(PARTY_MENU_TYPE_UNION_ROOM_TRADE, CB2_ReturnToField); sub_80156B0(data); @@ -2994,17 +3038,17 @@ void sub_80156E0(u8 taskId) } break; case 51: - gUnknown_02022C2C = 0x44; - sub_8012188(data->field_0->arr[taskData[1]].unk.playerName, &data->field_0->arr[taskData[1]].unk.field_0, 0x44); - sub_8018404(gStringVar1, &data->field_0->arr[taskData[1]]); - sub_8017020(sCommunicatingWaitTexts[2]); + 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]); data->state = 25; break; case 26: if (PrintOnTextbox(&data->textState, gStringVar4)) { - sub_801818C(TRUE); - sub_801A3D0(taskData[0], taskData[1], data->field_0); + HandleCancelTrade(TRUE); + UpdateUnionGroupMemberFacing(taskData[0], taskData[1], data->field_0); data->state = 4; } break; @@ -3021,37 +3065,37 @@ void var_800D_set_xB(void) gSpecialVar_Result = 11; } -void sub_801689C(struct UnkStruct_URoom *arg0) +static void ReceiveUnionRoomActivityPacket(struct WirelessLink_URoom *data) { if (gRecvCmds[1][1] != 0 && (gRecvCmds[1][0] & 0xFF00) == 0x2F00) { - arg0->field_9A[0] = gRecvCmds[1][1]; - if (gRecvCmds[1][1] == 0x44) + data->recvActivityRequest[0] = gRecvCmds[1][1]; + if (gRecvCmds[1][1] == (ACTIVITY_TRADE | IN_UNION_ROOM)) { - arg0->field_9A[1] = gRecvCmds[1][2]; - arg0->field_9A[2] = gRecvCmds[1][3]; + data->recvActivityRequest[1] = gRecvCmds[1][2]; + data->recvActivityRequest[2] = gRecvCmds[1][3]; } } } -bool32 sub_80168DC(struct UnkStruct_URoom *arg0) +static bool32 UnionRoom_HandleContactFromOtherPlayer(struct WirelessLink_URoom *data) { - if (arg0->field_9A[0] != 0) + if (data->recvActivityRequest[0] != 0) { - s32 var = sub_8017EA0(gStringVar4, gLinkPlayers[1].gender, &arg0->field_9A[0], arg0); + s32 var = GetChatLeaderActionRequestMessage(gStringVar4, gLinkPlayers[1].gender, &data->recvActivityRequest[0], data); if (var == 0) { return TRUE; } else if (var == 1) { - arg0->state = 35; - gUnknown_02022C2C = arg0->field_9A[0]; + data->state = 35; + gPlayerCurrActivity = data->recvActivityRequest[0]; return FALSE; } else if (var == 2) { - arg0->state = 36; + data->state = 36; sub_800AC34(); return FALSE; } @@ -3062,53 +3106,53 @@ bool32 sub_80168DC(struct UnkStruct_URoom *arg0) void InitUnionRoom(void) { - struct UnkStruct_URoom *ptr; + struct WirelessLink_URoom *data; sUnionRoomPlayerName[0] = EOS; - CreateTask(sub_801697C, 0); - gUnknown_02022C30.uRoom = gUnknown_02022C30.uRoom; // Needed to match. - gUnknown_02022C30.uRoom = ptr = AllocZeroed(sizeof(struct UnkStruct_URoom)); - gUnknown_03000DA8 = gUnknown_02022C30.uRoom; - ptr->state = 0; - ptr->textState = 0; - ptr->field_10 = 0; - ptr->field_12 = 0; + 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; sUnionRoomPlayerName[0] = EOS; } -void sub_801697C(u8 taskId) +static void Task_InitUnionRoom(u8 taskId) { s32 i; u8 text[32]; - struct UnkStruct_URoom *structPtr = gUnknown_02022C30.uRoom; + struct WirelessLink_URoom *data = sWirelessLinkMain.uRoom; - switch (structPtr->state) + switch (data->state) { case 0: - structPtr->state = 1; + data->state = 1; break; case 1: - sub_8010F84(0xC, 0, 0); - sub_800B488(); + SetHostRFUtgtGname(ACTIVITY_SEARCH, 0, 0); + SetWirelessCommType1(); OpenLink(); - sub_8011C84(); - sub_80111B0(1); - structPtr->state = 2; + InitializeRfuLinkManager_EnterUnionRoom(); + sub_80111B0(TRUE); + data->state = 2; break; case 2: - structPtr->field_4 = AllocZeroed(0x70); - sub_80175EC(structPtr->field_4, 4); - structPtr->field_C = AllocZeroed(0x70); - sub_80175EC(structPtr->field_C, 4); - structPtr->field_0 = AllocZeroed(0x100); - sub_8017580(structPtr->field_0->arr, 8); - structPtr->field_8 = AllocZeroed(0x20); - sub_8017580(&structPtr->field_8->arr[0], 1); - structPtr->field_20 = sub_8016DF0(structPtr->field_C, structPtr->field_4, 10); - structPtr->state = 3; + 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; break; case 3: - switch (sub_8016B00()) + switch (HandlePlayerListUpdate()) { case 1: case 2: @@ -3116,10 +3160,10 @@ void sub_801697C(u8 taskId) { for (i = 0; i < PLAYER_NAME_LENGTH + 1; i++) { - if (structPtr->field_0->arr[i].field_1A_0 == 1) + if (data->field_0->arr[i].groupScheduledAnim == UNION_ROOM_SPAWN_IN) { - sub_8018404(text, &structPtr->field_0->arr[i]); - if (sub_800E540(ReadAsU16(structPtr->field_0->arr[i].unk.field_0.unk_00.playerTrainerId), text)) + IntlConvPartnerUname7(text, &data->field_0->arr[i]); + if (PlayerHasMetTrainerBefore(ReadAsU16(data->field_0->arr[i].gname_uname.gname.unk_00.playerTrainerId), text)) { StringCopy(sUnionRoomPlayerName, text); break; @@ -3133,13 +3177,13 @@ void sub_801697C(u8 taskId) } break; case 4: - free(structPtr->field_8); - free(structPtr->field_0); - free(structPtr->field_C); - free(structPtr->field_4); - DestroyTask(structPtr->field_20); - free(gUnknown_02022C30.uRoom); - sub_800EDD4(); + 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(); DestroyTask(taskId); break; } @@ -3159,158 +3203,158 @@ bool16 BufferUnionRoomPlayerName(void) } } -u8 sub_8016B00(void) +static u8 HandlePlayerListUpdate(void) { s32 i; u8 j; - struct UnkStruct_URoom *structPtr = gUnknown_02022C30.uRoom; + struct WirelessLink_URoom *data = sWirelessLinkMain.uRoom; s32 r7 = 0; - for (i = 0; i < 4; i++) + for (i = 0; i < RFU_CHILD_MAX; i++) { - if (sub_8017630(&structPtr->field_C->arr[i].unk0, &gUnknown_082F045C) == TRUE) + if (AreGnameUnameDifferent(&data->field_C->arr[i].gname_uname, &sWirelessGnameUnamePair_Dummy) == TRUE) { - structPtr->field_8->arr[0].unk = structPtr->field_C->arr[i].unk0; - structPtr->field_8->arr[0].field_18 = 0; - structPtr->field_8->arr[0].field_1A_0 = 1; - structPtr->field_8->arr[0].field_1B = 1; + 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; return 4; } } for (j = 0; j < 8; j++) { - if (structPtr->field_0->arr[j].field_1A_0 != 0) + if (data->field_0->arr[j].groupScheduledAnim != UNION_ROOM_SPAWN_NONE) { - i = sub_80176E4(&structPtr->field_0->arr[j], &structPtr->field_4->arr[0]); + i = Findx20Inx1CArray(&data->field_0->arr[j], &data->field_4->arr[0]); if (i != 0xFF) { - if (structPtr->field_0->arr[j].field_1A_0 == 1) + if (data->field_0->arr[j].groupScheduledAnim == UNION_ROOM_SPAWN_IN) { - if (sub_8017678(&structPtr->field_0->arr[j].unk, &structPtr->field_4->arr[i].unk0)) + if (AreUnionRoomPlayerGnamesDifferent(&data->field_0->arr[j].gname_uname, &data->field_4->arr[i].gname_uname)) { - structPtr->field_0->arr[j].unk = structPtr->field_4->arr[i].unk0; - structPtr->field_0->arr[j].field_1B = 0x40; + data->field_0->arr[j].gname_uname = data->field_4->arr[i].gname_uname; + data->field_0->arr[j].field_1B = 0x40; r7 = 1; } - else if (structPtr->field_0->arr[j].field_1B != 0) + else if (data->field_0->arr[j].field_1B != 0) { - structPtr->field_0->arr[j].field_1B--; - if (structPtr->field_0->arr[j].field_1B == 0) + data->field_0->arr[j].field_1B--; + if (data->field_0->arr[j].field_1B == 0) r7 = 2; } } else { - structPtr->field_0->arr[j].field_1A_0 = 1; - structPtr->field_0->arr[j].field_1B = 0; + data->field_0->arr[j].groupScheduledAnim = UNION_ROOM_SPAWN_IN; + data->field_0->arr[j].field_1B = 0; r7 = 2; } - structPtr->field_0->arr[j].field_18 = 0; + data->field_0->arr[j].field_18 = 0; } - else if (structPtr->field_0->arr[j].field_1A_0 != 2) + else if (data->field_0->arr[j].groupScheduledAnim != UNION_ROOM_SPAWN_OUT) { - structPtr->field_0->arr[j].field_18++; - if (structPtr->field_0->arr[j].field_18 >= 600) + data->field_0->arr[j].field_18++; + if (data->field_0->arr[j].field_18 >= 600) { - structPtr->field_0->arr[j].field_1A_0 = 2; + data->field_0->arr[j].groupScheduledAnim = UNION_ROOM_SPAWN_OUT; r7 = 2; } } - else if (structPtr->field_0->arr[j].field_1A_0 == 2) + else if (data->field_0->arr[j].groupScheduledAnim == UNION_ROOM_SPAWN_OUT) { - structPtr->field_0->arr[j].field_18++; - if (structPtr->field_0->arr[j].field_18 >= 900) + data->field_0->arr[j].field_18++; + if (data->field_0->arr[j].field_18 >= 900) { - sub_8017580(&structPtr->field_0->arr[j], 1); + ClearUnkStruct_x20Array(&data->field_0->arr[j], 1); } } } } - for (i = 0; i < 4; i++) + for (i = 0; i < RFU_CHILD_MAX; i++) { - if (sub_8017734(&structPtr->field_0->arr[0], &structPtr->field_4->arr[i], 8) != 0xFF) + if (Appendx1Ctox20(&data->field_0->arr[0], &data->field_4->arr[i], 8) != 0xFF) r7 = 1; } return r7; } -void sub_8016CA0(u8 taskId) +static void Task_SearchForChildOrParent(u8 taskId) { s32 i, j; - struct UnkStruct_Shared sp0; + struct WirelessGnameUnamePair gname_uname; struct UnkStruct_Main4 **ptr = (void*) gTasks[taskId].data; - bool8 r4; + bool8 isParent; - for (i = 0; i < 4; i++) + for (i = 0; i < RFU_CHILD_MAX; i++) { - r4 = sub_800DE7C(&sp0.field_0, sp0.playerName, i); - if (!sub_8013D88(sp0.field_0.activity, gTasks[taskId].data[4])) + isParent = LinkRfu_GetNameIfCompatible(&gname_uname.gname, gname_uname.playerName, i); + if (!IsPartnerActivityAcceptable(gname_uname.gname.activity, gTasks[taskId].data[4])) { - sp0 = gUnknown_082F045C; + gname_uname = sWirelessGnameUnamePair_Dummy; } - if (sp0.field_0.unk_00.language == 1) + if (gname_uname.gname.unk_00.language == LANGUAGE_JAPANESE) { - sp0 = gUnknown_082F045C; + gname_uname = sWirelessGnameUnamePair_Dummy; } - if (!r4) + if (!isParent) { for (j = 0; j < i; j++) { - if (!sub_8017630(&ptr[1]->arr[j].unk0, &sp0)) + if (!AreGnameUnameDifferent(&ptr[1]->arr[j].gname_uname, &gname_uname)) { - sp0 = gUnknown_082F045C; + gname_uname = sWirelessGnameUnamePair_Dummy; } } - ptr[1]->arr[i].unk0 = sp0; - ptr[1]->arr[i].unk18 = sub_8017630(&ptr[1]->arr[i].unk0, &gUnknown_082F045C); + ptr[1]->arr[i].gname_uname = gname_uname; + ptr[1]->arr[i].active = AreGnameUnameDifferent(&ptr[1]->arr[i].gname_uname, &sWirelessGnameUnamePair_Dummy); } else { - ptr[0]->arr[i].unk0 = sp0; - ptr[0]->arr[i].unk18 = sub_8017630(&ptr[0]->arr[i].unk0, &gUnknown_082F045C); + ptr[0]->arr[i].gname_uname = gname_uname; + ptr[0]->arr[i].active = AreGnameUnameDifferent(&ptr[0]->arr[i].gname_uname, &sWirelessGnameUnamePair_Dummy); } } } -u8 sub_8016DF0(struct UnkStruct_Main4 * a0, struct UnkStruct_Main4 * a1, u32 a2) +static u8 CreateTask_SearchForChildOrParent(struct UnkStruct_Main4 * main4_parent, struct UnkStruct_Main4 * main4_child, u32 linkGroup) { - u8 taskId = CreateTask(sub_8016CA0, 0); + u8 taskId = CreateTask(Task_SearchForChildOrParent, 0); struct UnkStruct_Main4 ** data = (void *)gTasks[taskId].data; - data[0] = a0; - data[1] = a1; - gTasks[taskId].data[4] = a2; + data[0] = main4_parent; + data[1] = main4_child; + gTasks[taskId].data[4] = linkGroup; return taskId; } -void sub_8016E24(u8 taskId) +static void Task_ListenForPartnersWithCompatibleSerialNos(u8 taskId) { s32 i, j; struct UnkStruct_Main4 **ptr = (void*) gTasks[taskId].data; - for (i = 0; i < 4; i++) + for (i = 0; i < RFU_CHILD_MAX; i++) { - sub_800DE7C(&ptr[0]->arr[i].unk0.field_0, ptr[0]->arr[i].unk0.playerName, i); - if (!sub_8013D88(ptr[0]->arr[i].unk0.field_0.activity, gTasks[taskId].data[2])) + 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])) { - ptr[0]->arr[i].unk0 = gUnknown_082F045C; + ptr[0]->arr[i].gname_uname = sWirelessGnameUnamePair_Dummy; } for (j = 0; j < i; j++) { - if (!sub_8017630(&ptr[0]->arr[j].unk0, &ptr[0]->arr[i].unk0)) + if (!AreGnameUnameDifferent(&ptr[0]->arr[j].gname_uname, &ptr[0]->arr[i].gname_uname)) { - ptr[0]->arr[i].unk0 = gUnknown_082F045C; + ptr[0]->arr[i].gname_uname = sWirelessGnameUnamePair_Dummy; } } - ptr[0]->arr[i].unk18 = sub_8017630(&ptr[0]->arr[i].unk0, &gUnknown_082F045C); + ptr[0]->arr[i].active = AreGnameUnameDifferent(&ptr[0]->arr[i].gname_uname, &sWirelessGnameUnamePair_Dummy); } } -bool32 sub_8016F1C(struct GFtgtGname *arg0, s16 arg1) +static bool32 GetGnameWonderFlagByLinkGroup(struct GFtgtGname *gname, s16 linkGroup) { - if (arg1 == 7) + if (linkGroup == LINK_GROUP_WONDER_CARD) { - if (!arg0->unk_00.hasCard) + if (!gname->unk_00.hasCard) { return FALSE; } @@ -3319,9 +3363,9 @@ bool32 sub_8016F1C(struct GFtgtGname *arg0, s16 arg1) return TRUE; } } - else if (arg1 == 8) + else if (linkGroup == LINK_GROUP_WONDER_NEWS) { - if (!arg0->unk_00.hasNews) + if (!gname->unk_00.hasNews) { return FALSE; } @@ -3336,40 +3380,40 @@ bool32 sub_8016F1C(struct GFtgtGname *arg0, s16 arg1) } } -void sub_8016F44(u8 taskId) +static void Task_ListenForPartnersWithSerial7F7D(u8 taskId) { s32 i; struct UnkStruct_Main4 **ptr = (void*) gTasks[taskId].data; - for (i = 0; i < 4; i++) + for (i = 0; i < RFU_CHILD_MAX; i++) { - if (sub_800DF34(&ptr[0]->arr[i].unk0.field_0, ptr[0]->arr[i].unk0.playerName, i)) + if (LinkRfu_GetNameIfSerial7F7D(&ptr[0]->arr[i].gname_uname.gname, ptr[0]->arr[i].gname_uname.playerName, i)) { - sub_8016F1C(&ptr[0]->arr[i].unk0.field_0, gTasks[taskId].data[2]); + GetGnameWonderFlagByLinkGroup(&ptr[0]->arr[i].gname_uname.gname, gTasks[taskId].data[2]); } - ptr[0]->arr[i].unk18 = sub_8017630(&ptr[0]->arr[i].unk0, &gUnknown_082F045C); + ptr[0]->arr[i].active = AreGnameUnameDifferent(&ptr[0]->arr[i].gname_uname, &sWirelessGnameUnamePair_Dummy); } } -u8 sub_8016FC0(struct UnkStruct_Main4 * a0, u32 a1) +static u8 CreateTask_ListenForPartnersWithCompatibleSerialNos(struct UnkStruct_Main4 * main4, u32 linkGroup) { - u8 taskId = CreateTask(sub_8016E24, 0); + u8 taskId = CreateTask(Task_ListenForPartnersWithCompatibleSerialNos, 0); struct UnkStruct_Main4 **ptr = (void*) gTasks[taskId].data; - ptr[0] = a0; - gTasks[taskId].data[2] = a1; + ptr[0] = main4; + gTasks[taskId].data[2] = linkGroup; return taskId; } -u8 sub_8016FF0(struct UnkStruct_Main4 * a0, u32 a1) +static u8 CreateTask_ListenForPartnersWithSerial7F7D(struct UnkStruct_Main4 * main4, u32 linkGroup) { - u8 taskId = CreateTask(sub_8016F44, 0); + u8 taskId = CreateTask(Task_ListenForPartnersWithSerial7F7D, 0); struct UnkStruct_Main4 **ptr = (void*) gTasks[taskId].data; - ptr[0] = a0; - gTasks[taskId].data[2] = a1; + ptr[0] = main4; + gTasks[taskId].data[2] = linkGroup; return taskId; } -bool32 sub_8017020(const u8 *src) +static bool32 UR_PrintFieldMessage(const u8 *src) { LoadMessageBoxAndBorderGfx(); DrawDialogueFrame(0, 1); @@ -3378,19 +3422,15 @@ bool32 sub_8017020(const u8 *src) return FALSE; } -bool32 sub_801704C(void) +static bool32 UR_RunTextPrinters_CheckPrinter0Active(void) { if (!RunTextPrintersAndIsPrinter0Active()) - { return TRUE; - } else - { return FALSE; - } } -bool8 PrintOnTextbox(u8 *textState, const u8 *str) +static bool8 PrintOnTextbox(u8 *textState, const u8 *str) { switch (*textState) { @@ -3412,31 +3452,31 @@ bool8 PrintOnTextbox(u8 *textState, const u8 *str) return FALSE; } -s8 sub_80170B8(u8 *arg0, bool32 arg1) +static s8 UnionRoomHandleYesNo(u8 *state, bool32 noDraw) { s8 r1; - switch (*arg0) + switch (*state) { case 0: - if (arg1) + if (noDraw) { return -3; } DisplayYesNoMenuDefaultYes(); - (*arg0)++; + (*state)++; break; case 1: - if (arg1) + if (noDraw) { sub_8198C78(); - *arg0 = 0; + *state = 0; return -3; } r1 = Menu_ProcessInputNoWrapClearOnChoose(); if (r1 == -1 || r1 == 0 || r1 == 1) { - *arg0 = 0; + *state = 0; return r1; } break; @@ -3444,64 +3484,64 @@ s8 sub_80170B8(u8 *arg0, bool32 arg1) return -2; } -u8 sub_8017118(const struct WindowTemplate * template) +static u8 CreateTradeBoardWindow(const struct WindowTemplate * template) { u8 windowId = AddWindow(template); DrawStdWindowFrame(windowId, FALSE); - FillWindowPixelBuffer(windowId, 0xFF); - sub_80173E0(windowId, 1, sText_NameWantedOfferLv, 8, 1, 6); + FillWindowPixelBuffer(windowId, PIXEL_FILL(15)); + UR_AddTextPrinterParameterized(windowId, 1, sText_NameWantedOfferLv, 8, 1, 6); CopyWindowToVram(windowId, 2); PutWindowTilemap(windowId); return windowId; } -void sub_8017168(u8 windowId) +static void DeleteTradeBoardWindow(u8 windowId) { RemoveWindow(windowId); } -s32 sub_8017178(u8 *arg0, u8 *arg1, u8 *arg2, const struct WindowTemplate *winTemplate, const struct ListMenuTemplate *menuTemplate) +static s32 ListMenuHandler_AllItemsAvailable(u8 *state, u8 *windowId, u8 *listMenuId, const struct WindowTemplate *winTemplate, const struct ListMenuTemplate *menuTemplate) { - s32 r1, r8; + s32 maxWidth, input; struct WindowTemplate winTemplateCopy; - switch (*arg0) + switch (*state) { case 0: winTemplateCopy = *winTemplate; - r1 = Intl_GetListMenuWidth(menuTemplate); - if (winTemplateCopy.width > r1) + maxWidth = Intl_GetListMenuWidth(menuTemplate); + if (winTemplateCopy.width > maxWidth) { - winTemplateCopy.width = r1; + winTemplateCopy.width = maxWidth; } if (winTemplateCopy.tilemapLeft + winTemplateCopy.width > 29) { winTemplateCopy.tilemapLeft = max(29 - winTemplateCopy.width, 0); } - *arg1 = AddWindow(&winTemplateCopy); - DrawStdWindowFrame(*arg1, FALSE); + *windowId = AddWindow(&winTemplateCopy); + DrawStdWindowFrame(*windowId, FALSE); gMultiuseListMenuTemplate = *menuTemplate; - gMultiuseListMenuTemplate.windowId = *arg1; - *arg2 = ListMenuInit(&gMultiuseListMenuTemplate, 0, 0); - CopyWindowToVram(*arg1, TRUE); - (*arg0)++; + gMultiuseListMenuTemplate.windowId = *windowId; + *listMenuId = ListMenuInit(&gMultiuseListMenuTemplate, 0, 0); + CopyWindowToVram(*windowId, TRUE); + (*state)++; break; case 1: - r8 = ListMenu_ProcessInput(*arg2); + input = ListMenu_ProcessInput(*listMenuId); if (({gMain.newKeys & A_BUTTON;})) { - DestroyListMenuTask(*arg2, NULL, NULL); - ClearStdWindowAndFrame(*arg1, TRUE); - RemoveWindow(*arg1); - *arg0 = 0; - return r8; + DestroyListMenuTask(*listMenuId, NULL, NULL); + ClearStdWindowAndFrame(*windowId, TRUE); + RemoveWindow(*windowId); + *state = 0; + return input; } else if (({gMain.newKeys & B_BUTTON;})) { - DestroyListMenuTask(*arg2, NULL, NULL); - ClearStdWindowAndFrame(*arg1, TRUE); - RemoveWindow(*arg1); - *arg0 = 0; + DestroyListMenuTask(*listMenuId, NULL, NULL); + ClearStdWindowAndFrame(*windowId, TRUE); + RemoveWindow(*windowId); + *state = 0; return -2; } break; @@ -3510,49 +3550,49 @@ s32 sub_8017178(u8 *arg0, u8 *arg1, u8 *arg2, const struct WindowTemplate *winTe return -1; } -s32 sub_80172A0(u8 *arg0, u8 *arg1, u8 *arg2, u8 *arg3, const struct WindowTemplate *winTemplate, const struct ListMenuTemplate *menuTemplate, struct UnkStruct_Main0 *arg6) +static s32 TradeBoardMenuHandler(u8 *state, u8 *windowId, u8 *listMenuId, u8 *tradeBoardWindowId, const struct WindowTemplate *winTemplate, const struct ListMenuTemplate *menuTemplate, struct UnkStruct_Main0 *traders) { s32 input; - s32 r4; + s32 idx; - switch (*arg0) + switch (*state) { case 0: - *arg3 = sub_8017118(&gUnknown_082F0344); - *arg1 = AddWindow(winTemplate); - DrawStdWindowFrame(*arg1, FALSE); + *tradeBoardWindowId = CreateTradeBoardWindow(&gUnknown_082F0344); + *windowId = AddWindow(winTemplate); + DrawStdWindowFrame(*windowId, FALSE); gMultiuseListMenuTemplate = *menuTemplate; - gMultiuseListMenuTemplate.windowId = *arg1; - *arg2 = ListMenuInit(&gMultiuseListMenuTemplate, 0, 1); - (*arg0)++; + gMultiuseListMenuTemplate.windowId = *windowId; + *listMenuId = ListMenuInit(&gMultiuseListMenuTemplate, 0, 1); + (*state)++; break; case 1: - CopyWindowToVram(*arg1, TRUE); - (*arg0)++; + CopyWindowToVram(*windowId, TRUE); + (*state)++; break; case 2: // Register swap r1 <---> r2 - input = ListMenu_ProcessInput(*arg2); + input = ListMenu_ProcessInput(*listMenuId); if (({gMain.newKeys & (A_BUTTON | B_BUTTON);})) { if (input == 8 || ({gMain.newKeys & B_BUTTON;})) { - DestroyListMenuTask(*arg2, NULL, NULL); - RemoveWindow(*arg1); - sub_8017168(*arg3); - *arg0 = 0; + DestroyListMenuTask(*listMenuId, NULL, NULL); + RemoveWindow(*windowId); + DeleteTradeBoardWindow(*tradeBoardWindowId); + *state = 0; return -2; } else { - r4 = sub_8017CB0(arg6->arr, input); - if (r4 >= 0) + idx = GetIndexOfNthTradeBoardOffer(traders->arr, input); + if (idx >= 0) { - DestroyListMenuTask(*arg2, NULL, NULL); - RemoveWindow(*arg1); - sub_8017168(*arg3); - *arg0 = 0; - return r4; + DestroyListMenuTask(*listMenuId, NULL, NULL); + RemoveWindow(*windowId); + DeleteTradeBoardWindow(*tradeBoardWindowId); + *state = 0; + return idx; } else { @@ -3565,127 +3605,128 @@ s32 sub_80172A0(u8 *arg0, u8 *arg1, u8 *arg2, u8 *arg3, const struct WindowTempl return -1; } -void sub_80173B0(void) + +static void UR_ClearBg0(void) { FillBgTilemapBufferRect(0, 0, 0, 0, 32, 32, 0); CopyBgTilemapBufferToVram(0); } -void sub_80173D4(void) +static void JoinGroup_EnableScriptContexts(void) { EnableBothScriptContexts(); } -void sub_80173E0(u8 windowId, u8 arg1, const u8 *str, u8 arg3, u8 arg4, u8 arg5) +static void UR_AddTextPrinterParameterized(u8 windowId, u8 fontId, const u8 *str, u8 x, u8 y, u8 colorIdx) { - struct TextPrinterTemplate sp0; + struct TextPrinterTemplate printerTemplate; - sp0.currentChar = str; - sp0.windowId = windowId; - sp0.fontId = arg1; - sp0.x = arg3; - sp0.y = arg4; - sp0.currentX = arg3; - sp0.currentY = arg4; - sp0.unk = 0; + printerTemplate.currentChar = str; + printerTemplate.windowId = windowId; + printerTemplate.fontId = fontId; + printerTemplate.x = x; + printerTemplate.y = y; + printerTemplate.currentX = x; + printerTemplate.currentY = y; + printerTemplate.unk = 0; gTextFlags.useAlternateDownArrow = FALSE; - switch (arg5) + switch (colorIdx) { - case 0: - sp0.letterSpacing = 0; - sp0.lineSpacing = 0; - sp0.fgColor = 2; - sp0.bgColor = 1; - sp0.shadowColor = 3; + 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 1: - sp0.letterSpacing = 0; - sp0.lineSpacing = 0; - sp0.fgColor = 4; - sp0.bgColor = 1; - sp0.shadowColor = 5; + 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 2: - sp0.letterSpacing = 0; - sp0.lineSpacing = 0; - sp0.fgColor = 6; - sp0.bgColor = 1; - sp0.shadowColor = 7; + 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 3: - sp0.letterSpacing = 0; - sp0.lineSpacing = 0; - sp0.fgColor = 1; - sp0.bgColor = 1; - sp0.shadowColor = 3; + 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 4: - sp0.letterSpacing = 0; - sp0.lineSpacing = 0; - sp0.fgColor = 1; - sp0.bgColor = 2; - sp0.shadowColor = 3; + 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 5: - sp0.letterSpacing = 0; - sp0.lineSpacing = 0; - sp0.fgColor = 7; - sp0.bgColor = 15; - sp0.shadowColor = 9; + 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 6: - sp0.letterSpacing = 0; - sp0.lineSpacing = 0; - sp0.fgColor = 14; - sp0.bgColor = 15; - sp0.shadowColor = 9; + 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; break; } - AddTextPrinter(&sp0, 0xFF, NULL); + AddTextPrinter(&printerTemplate, 0xFF, NULL); } -void sub_8017580(struct UnkStruct_x20 *arg0, u8 count) +static void ClearUnkStruct_x20Array(struct UnkStruct_x20 *arr, u8 count) { s32 i; for (i = 0; i < count; i++) { - arg0[i].unk = gUnknown_082F045C; - arg0[i].field_18 = 0xFF; - arg0[i].field_1A_0 = 0; - arg0[i].field_1A_1 = 0; - arg0[i].field_1B = 0; + 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; } } -void sub_80175EC(struct UnkStruct_Main4 *arg0, u8 count) +static void ClearUnkStruct_x1CArray(struct UnkStruct_Main4 *main4, u8 count) { s32 i; - for (i = 0; i < 4; i++) + for (i = 0; i < RFU_CHILD_MAX; i++) { - arg0->arr[i].unk0 = gUnknown_082F045C; - arg0->arr[i].unk18 = 0; + main4->arr[i].gname_uname = sWirelessGnameUnamePair_Dummy; + main4->arr[i].active = FALSE; } } -bool8 sub_8017630(struct UnkStruct_Shared* arg0, const struct UnkStruct_Shared* arg1) +static bool8 AreGnameUnameDifferent(struct WirelessGnameUnamePair* pair1, const struct WirelessGnameUnamePair* pair2) { s32 i; for (i = 0; i < 2; i++) { - if (arg0->field_0.unk_00.playerTrainerId[i] != arg1->field_0.unk_00.playerTrainerId[i]) + if (pair1->gname.unk_00.playerTrainerId[i] != pair2->gname.unk_00.playerTrainerId[i]) { return TRUE; } } - for (i = 0; i < 8; i++) + for (i = 0; i < PLAYER_NAME_LENGTH + 1; i++) { - if (arg0->playerName[i] != arg1->playerName[i]) + if (pair1->playerName[i] != pair2->playerName[i]) { return TRUE; } @@ -3694,34 +3735,34 @@ bool8 sub_8017630(struct UnkStruct_Shared* arg0, const struct UnkStruct_Shared* return FALSE; } -bool32 sub_8017678(struct UnkStruct_Shared *arg0, struct UnkStruct_Shared *arg1) +static bool32 AreUnionRoomPlayerGnamesDifferent(struct WirelessGnameUnamePair *pair1, struct WirelessGnameUnamePair *pair2) { s32 i; - if (arg0->field_0.activity != arg1->field_0.activity) + if (pair1->gname.activity != pair2->gname.activity) { return TRUE; } - if (arg0->field_0.started != arg1->field_0.started) + if (pair1->gname.started != pair2->gname.started) { return TRUE; } - for (i = 0; i < 4; i++) + for (i = 0; i < RFU_CHILD_MAX; i++) { - if (arg0->field_0.child_sprite_gender[i] != arg1->field_0.child_sprite_gender[i]) + if (pair1->gname.child_sprite_gender[i] != pair2->gname.child_sprite_gender[i]) { return TRUE; } } - if (arg0->field_0.species != arg1->field_0.species) + if (pair1->gname.species != pair2->gname.species) { return TRUE; } - if (arg0->field_0.type != arg1->field_0.type) + if (pair1->gname.type != pair2->gname.type) { return TRUE; } @@ -3729,38 +3770,38 @@ bool32 sub_8017678(struct UnkStruct_Shared *arg0, struct UnkStruct_Shared *arg1) return FALSE; } -u32 sub_80176E4(struct UnkStruct_x20 *arg0, struct UnkStruct_x1C *arg1) +static u32 Findx20Inx1CArray(struct UnkStruct_x20 *arg0, struct UnkStruct_x1C *arg1) { u8 result = 0xFF; s32 i; - for (i = 0; i < 4; i++) + for (i = 0; i < RFU_CHILD_MAX; i++) { - if (arg1[i].unk18 && !sub_8017630(&arg0->unk, &arg1[i].unk0)) + if (arg1[i].active && !AreGnameUnameDifferent(&arg0->gname_uname, &arg1[i].gname_uname)) { result = i; - arg1[i].unk18 = FALSE; + arg1[i].active = FALSE; } } return result; } -u8 sub_8017734(struct UnkStruct_x20 *arg0, struct UnkStruct_x1C *arg1, u8 arg2) +static u8 Appendx1Ctox20(struct UnkStruct_x20 *arg0, struct UnkStruct_x1C *arg1, u8 arg2) { s32 i; - if (arg1->unk18) + if (arg1->active) { for (i = 0; i < arg2; i++) { - if (arg0[i].field_1A_0 == 0) + if (arg0[i].groupScheduledAnim == UNION_ROOM_SPAWN_NONE) { - arg0[i].unk = arg1->unk0; + arg0[i].gname_uname = arg1->gname_uname; arg0[i].field_18 = 0; - arg0[i].field_1A_0 = 1; + arg0[i].groupScheduledAnim = UNION_ROOM_SPAWN_IN; arg0[i].field_1B = 64; - arg1->unk18 = FALSE; + arg1->active = FALSE; return i; } } @@ -3769,126 +3810,123 @@ u8 sub_8017734(struct UnkStruct_x20 *arg0, struct UnkStruct_x1C *arg1, u8 arg2) return 0xFF; } -void sub_80177B8(u8 arg0, u8 arg1, u8 arg2, struct UnkStruct_x20 *arg3, u8 arg4, u8 id) +static void PrintUnionRoomGroupOnWindow(u8 windowId, u8 x, u8 y, struct UnkStruct_x20 *group, u8 colorIdx, u8 id) { - u8 r2; - u8 sp0[6]; + u8 activity; + u8 trainerId[6]; ConvertIntToDecimalStringN(gStringVar4, id + 1, STR_CONV_MODE_LEADING_ZEROS, 2); StringAppend(gStringVar4, sText_Colon); - sub_80173E0(arg0, 1, gStringVar4, arg1, arg2, 0); - arg1 += 18; - r2 = arg3->unk.field_0.activity; - if (arg3->field_1A_0 == 1 && !(r2 & 0x40)) + 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)) { - sub_8018404(gStringVar4, arg3); - sub_80173E0(arg0, 1, gStringVar4, arg1, arg2, arg4); - ConvertIntToDecimalStringN(sp0, arg3->unk.field_0.unk_00.playerTrainerId[0] | (arg3->unk.field_0.unk_00.playerTrainerId[1] << 8), STR_CONV_MODE_LEADING_ZEROS, 5); + 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); StringCopy(gStringVar4, sText_ID); - StringAppend(gStringVar4, sp0); - sub_80173E0(arg0, 1, gStringVar4, GetStringRightAlignXOffset(1, gStringVar4, 0x88), arg2, arg4); + StringAppend(gStringVar4, trainerId); + UR_AddTextPrinterParameterized(windowId, 1, gStringVar4, GetStringRightAlignXOffset(1, gStringVar4, 0x88), y, colorIdx); } } -void sub_80178A0(u8 arg0, u8 arg1, u8 arg2, struct UnkStruct_x20 *arg3, u8 arg4, u8 id) +static void PrintGroupMemberCandidateOnWindowWithColor(u8 windowId, u8 x, u8 y, struct UnkStruct_x20 *group, u8 colorIdx, u8 id) { - u8 sp0[6]; + u8 trainerId[6]; - if (arg3->field_1A_0 == 1) + if (group->groupScheduledAnim == UNION_ROOM_SPAWN_IN) { - sub_8018404(gStringVar4, arg3); - sub_80173E0(arg0, 1, gStringVar4, arg1, arg2, arg4); - ConvertIntToDecimalStringN(sp0, arg3->unk.field_0.unk_00.playerTrainerId[0] | (arg3->unk.field_0.unk_00.playerTrainerId[1] << 8), STR_CONV_MODE_LEADING_ZEROS, 5); + 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); StringCopy(gStringVar4, sText_ID); - StringAppend(gStringVar4, sp0); - sub_80173E0(arg0, 1, gStringVar4, GetStringRightAlignXOffset(1, gStringVar4, 0x68), arg2, arg4); + StringAppend(gStringVar4, trainerId); + UR_AddTextPrinterParameterized(windowId, 1, gStringVar4, GetStringRightAlignXOffset(1, gStringVar4, 0x68), y, colorIdx); } } -bool32 sub_8017940(void) +static bool32 PlayerIsTalkingToUnionRoomAide(void) { s16 x, y; GetXYCoordsOneStepInFrontOfPlayer(&x, &y); + if (x != 9) - { return FALSE; - } + if (y != 8) - { return FALSE; - } + if (gPlayerAvatar.tileTransitionState == 2 || gPlayerAvatar.tileTransitionState == 0) - { return TRUE; - } return FALSE; } -u32 sub_8017984(s32 arg0) +static u32 GetResponseIdx_InviteToURoomActivity(s32 activity) { - switch (arg0) + switch (activity) { - case 5: + case ACTIVITY_CHAT: return 1; - case 4: + case ACTIVITY_TRADE: return 2; - case 8: + case ACTIVITY_CARD: return 3; - case 3: + case ACTIVITY_BATTLE_MULTI: default: return 0; } } -u32 sub_80179AC(struct UnkStruct_x20 *arg0) +static u32 ConvPartnerUnameAndGetWhetherMetAlready(struct UnkStruct_x20 *arg0) { - u8 sp0[30]; - sub_8018404(sp0, arg0); - return sub_800E540(ReadAsU16(arg0->unk.field_0.unk_00.playerTrainerId), sp0); + u8 name[30]; + IntlConvPartnerUname7(name, arg0); + return PlayerHasMetTrainerBefore(ReadAsU16(arg0->gname_uname.gname.unk_00.playerTrainerId), name); } -s32 sub_80179D4(struct UnkStruct_Main0 *arg0, u8 arg1, u8 arg2, u32 playerGender) +static s32 UnionRoomGetPlayerInteractionResponse(struct UnkStruct_Main0 *main0, bool8 overrideGender, u8 playerIdx, u32 playerGender) { - bool32 r2; + bool32 metBefore; - struct UnkStruct_x20 * r5 = &arg0->arr[arg2]; + struct UnkStruct_x20 * r5 = &main0->arr[playerIdx]; - if (!r5->unk.field_0.started && arg1 == 0) + if (!r5->gname_uname.gname.started && !overrideGender) { - sub_8018404(gStringVar1, r5); - r2 = sub_800E540(ReadAsU16(r5->unk.field_0.unk_00.playerTrainerId), gStringVar1); - if (r5->unk.field_0.activity == 0x45) + 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)) { - StringExpandPlaceholders(gStringVar4, sJoinChatTexts[r2][playerGender]); + StringExpandPlaceholders(gStringVar4, sJoinChatTexts[metBefore][playerGender]); return 2; } else { - sub_8017020(sCommunicatingWaitTexts[r2]); + UR_PrintFieldMessage(sCommunicatingWaitTexts[metBefore]); return 1; } } else { - sub_8018404(gStringVar1, r5); - if (arg1 != 0) + IntlConvPartnerUname7(gStringVar1, r5); + if (overrideGender) { - playerGender = (r5->unk.field_0.unk_00.playerTrainerId[arg1 + 1] >> 3) & 1; + playerGender = (r5->gname_uname.gname.unk_00.playerTrainerId[overrideGender + 1] >> 3) & 1; } - switch (r5->unk.field_0.activity & 0x3F) + switch (r5->gname_uname.gname.activity & 0x3F) { - case 1: - StringExpandPlaceholders(gStringVar4, sBattleReactionTexts[playerGender][Random() % 4]); + case ACTIVITY_BATTLE_SINGLE: + StringExpandPlaceholders(gStringVar4, sBattleReactionTexts[playerGender][Random() % ARRAY_COUNT(sBattleReactionTexts[0])]); break; - case 4: + case ACTIVITY_TRADE: StringExpandPlaceholders(gStringVar4, sTradeReactionTexts[playerGender][Random() % 2]); break; - case 5: - StringExpandPlaceholders(gStringVar4, sChatReactionTexts[playerGender][Random() % 4]); + case ACTIVITY_CHAT: + StringExpandPlaceholders(gStringVar4, sChatReactionTexts[playerGender][Random() % ARRAY_COUNT(sChatReactionTexts[0])]); break; - case 8: - StringExpandPlaceholders(gStringVar4, sTrainerCardReactionTexts[playerGender][Random() % 2]); + case ACTIVITY_CARD: + StringExpandPlaceholders(gStringVar4, sTrainerCardReactionTexts[playerGender][Random() % ARRAY_COUNT(sTrainerCardReactionTexts[0])]); break; default: StringExpandPlaceholders(gStringVar4, sText_TrainerAppearsBusy); @@ -3903,40 +3941,40 @@ void nullsub_14(u8 windowId, s32 itemId, u8 y) } -void sub_8017B3C(u8 arg0, u8 arg1, struct GFtgtGname * arg2, const u8 * str, u8 arg4) +static void TradeBoardPrintItemInfo(u8 windowId, u8 y, struct GFtgtGname * gname, const u8 * uname, u8 colorIdx) { - u8 sp8[4]; - u16 r8 = arg2->species; - u8 r7 = arg2->type; - u8 r9 = arg2->level; + u8 levelStr[4]; + u16 species = gname->species; + u8 type = gname->type; + u8 level = gname->level; - sub_80173E0(arg0, 1, str, 8, arg1, arg4); - if (r8 == SPECIES_EGG) + UR_AddTextPrinterParameterized(windowId, 1, uname, 8, y, colorIdx); + if (species == SPECIES_EGG) { - sub_80173E0(arg0, 1, sText_EggTrade, 0x44, arg1, arg4); + UR_AddTextPrinterParameterized(windowId, 1, sText_EggTrade, 0x44, y, colorIdx); } else { - blit_move_info_icon(arg0, r7 + 1, 0x44, arg1); - sub_80173E0(arg0, 1, gSpeciesNames[r8], 0x76, arg1, arg4); - ConvertIntToDecimalStringN(sp8, r9, STR_CONV_MODE_RIGHT_ALIGN, 3); - sub_80173E0(arg0, 1, sp8, 0xC6, arg1, arg4); + 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); } } -void sub_8017BE8(u8 windowId, s32 itemId, u8 y) +static void TradeBoardListMenuItemPrintFunc(u8 windowId, s32 itemId, u8 y) { - struct UnkStruct_Leader *leader = gUnknown_02022C30.leader; + struct WirelessLink_Leader *data = sWirelessLinkMain.leader; struct GFtgtGname *rfu; s32 i, j; - u8 sp4[11]; + u8 playerName[11]; - if (itemId == -3 && y == gUnknown_082F03A4.upText_Y) + if (itemId == -3 && y == sTradeBoardListMenuTemplate.upText_Y) { - rfu = sub_800F7DC(); + rfu = GetHostRFUtgtGname(); if (rfu->species != SPECIES_NONE) { - sub_8017B3C(windowId, y, rfu, gSaveBlock2Ptr->playerName, 5); + TradeBoardPrintItemInfo(windowId, y, rfu, gSaveBlock2Ptr->playerName, 5); } } else @@ -3944,32 +3982,32 @@ void sub_8017BE8(u8 windowId, s32 itemId, u8 y) j = 0; for (i = 0; i < 8; i++) { - if (leader->field_0->arr[i].field_1A_0 == 1 && leader->field_0->arr[i].unk.field_0.species != SPECIES_NONE) + if (data->field_0->arr[i].groupScheduledAnim == UNION_ROOM_SPAWN_IN && data->field_0->arr[i].gname_uname.gname.species != SPECIES_NONE) { j++; } if (j == itemId + 1) { - sub_8018404(sp4, &leader->field_0->arr[i]); - sub_8017B3C(windowId, y, &leader->field_0->arr[i].unk.field_0, sp4, 6); + IntlConvPartnerUname7(playerName, &data->field_0->arr[i]); + TradeBoardPrintItemInfo(windowId, y, &data->field_0->arr[i].gname_uname.gname, playerName, 6); break; } } } } -s32 sub_8017CB0(struct UnkStruct_x20 * arg, s32 arg1) +static s32 GetIndexOfNthTradeBoardOffer(struct UnkStruct_x20 * arg, s32 n) { s32 i; s32 j = 0; for (i = 0; i < 8; i++) { - if (arg[i].field_1A_0 == 1 && arg[i].unk.field_0.species != SPECIES_NONE) + if (arg[i].groupScheduledAnim == UNION_ROOM_SPAWN_IN && arg[i].gname_uname.gname.species != SPECIES_NONE) { j++; } - if (j == arg1 + 1) + if (j == n + 1) { return i; } @@ -3978,12 +4016,12 @@ s32 sub_8017CB0(struct UnkStruct_x20 * arg, s32 arg1) return -1; } -s32 sub_8017CF8(s32 arg1, struct UnkStruct_Main0 *arg0) +static s32 GetUnionRoomPlayerGender(s32 playerIdx, struct UnkStruct_Main0 *main0) { - return arg0->arr[arg1].unk.field_0.playerGender; + return main0->arr[playerIdx].gname_uname.gname.playerGender; } -s32 sub_8017D04(u32 type, u32 species) +static s32 IsRequestedTypeOrEggInPlayerParty(u32 type, u32 species) { s32 i; @@ -3994,10 +4032,10 @@ s32 sub_8017D04(u32 type, u32 species) species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2); if (species == SPECIES_EGG) { - return 0; + return UR_TRADE_MATCH; } } - return 2; + return UR_TRADE_NOEGG; } else { @@ -4006,77 +4044,77 @@ s32 sub_8017D04(u32 type, u32 species) species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2); if (gBaseStats[species].type1 == type || gBaseStats[species].type2 == type) { - return 0; + return UR_TRADE_MATCH; } } - return 1; + return UR_TRADE_NOTYPE; } } -void sub_8017D9C(u8 *dst, s32 arg1, u32 playerGender) +static void GetURoomActivityRejectMsg(u8 *dst, s32 acitivty, u32 playerGender) { - switch (arg1) + switch (acitivty) { - case 0x41: + case ACTIVITY_BATTLE_SINGLE | IN_UNION_ROOM: StringExpandPlaceholders(dst, sBattleDeclinedTexts[playerGender]); break; - case 0x45: + case ACTIVITY_CHAT | IN_UNION_ROOM: StringExpandPlaceholders(dst, sChatDeclinedTexts[playerGender]); break; - case 0x44: + case ACTIVITY_TRADE | IN_UNION_ROOM: StringExpandPlaceholders(dst, sText_TradeOfferRejected); break; - case 0x48: + case ACTIVITY_CARD | IN_UNION_ROOM: StringExpandPlaceholders(dst, sShowTrainerCardDeclinedTexts[playerGender]); break; } } -void sub_8017E00(u8 *dst, u8 arg1) +static void GetURoomActivityStartMsg(u8 *dst, u8 acitivty) { u8 mpId = GetMultiplayerId(); u8 gender = gLinkPlayers[mpId ^ 1].gender; - switch (arg1) + switch (acitivty) { - case 0x41: + case ACTIVITY_BATTLE_SINGLE | IN_UNION_ROOM: StringCopy(dst, sStartActivityTexts[mpId][gender][0]); break; - case 0x44: + case ACTIVITY_TRADE | IN_UNION_ROOM: StringCopy(dst, sStartActivityTexts[mpId][gender][2]); break; - case 0x45: + case ACTIVITY_CHAT | IN_UNION_ROOM: StringCopy(dst, sStartActivityTexts[mpId][gender][1]); break; } } -s32 sub_8017EA0(u8 *dst, u32 gender, u16 *arg2, struct UnkStruct_URoom *arg3) +static s32 GetChatLeaderActionRequestMessage(u8 *dst, u32 gender, u16 *activityData, struct WirelessLink_URoom *uroom) { s32 result = 0; u16 species = SPECIES_NONE; s32 i; - switch (arg2[0]) + switch (activityData[0]) { - case 0x41: + case ACTIVITY_BATTLE_SINGLE | IN_UNION_ROOM: StringExpandPlaceholders(dst, sText_BattleChallenge); result = 1; break; - case 0x45: + case ACTIVITY_CHAT | IN_UNION_ROOM: StringExpandPlaceholders(dst, sText_ChatInvitation); result = 1; break; - case 0x44: - ConvertIntToDecimalStringN(arg3->field_58 + 0x00, sUnionRoomTrade.playerLevel, STR_CONV_MODE_LEFT_ALIGN, 3); - StringCopy(arg3->field_58 + 0x10, gSpeciesNames[sUnionRoomTrade.playerSpecies]); - for (i = 0; i < 4; i++) + 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++) { if (gRfuLinkStatus->partner[i].serialNo == 2) { - ConvertIntToDecimalStringN(arg3->field_58 + 0x20, arg2[2], STR_CONV_MODE_LEFT_ALIGN, 3); - StringCopy(arg3->field_58 + 0x30, gSpeciesNames[arg2[1]]); - species = arg2[1]; + ConvertIntToDecimalStringN(uroom->activityRequestStrbufs[2], activityData[2], STR_CONV_MODE_LEFT_ALIGN, 3); + StringCopy(uroom->activityRequestStrbufs[3], gSpeciesNames[activityData[1]]); + species = activityData[1]; break; } } @@ -4086,19 +4124,19 @@ s32 sub_8017EA0(u8 *dst, u32 gender, u16 *arg2, struct UnkStruct_URoom *arg3) } else { - for (i = 0; i < 4; i++) + for (i = 0; i < RFU_CHILD_MAX; i++) { - DynamicPlaceholderTextUtil_SetPlaceholderPtr(i, arg3->field_58 + 0x10 * i); + DynamicPlaceholderTextUtil_SetPlaceholderPtr(i, uroom->activityRequestStrbufs[i]); } DynamicPlaceholderTextUtil_ExpandPlaceholders(dst, sText_OfferToTradeMon); } result = 1; break; - case 0x48: + case ACTIVITY_CARD | IN_UNION_ROOM: StringExpandPlaceholders(dst, sText_ShowTrainerCard); result = 1; break; - case 0x40: + case IN_UNION_ROOM: StringExpandPlaceholders(dst, sText_ChatDropped); result = 2; break; @@ -4107,18 +4145,18 @@ s32 sub_8017EA0(u8 *dst, u32 gender, u16 *arg2, struct UnkStruct_URoom *arg3) return result; } -bool32 sub_8017FD8(struct UnkStruct_URoom *arg0) +static bool32 PollPartnerYesNoResponse(struct WirelessLink_URoom *data) { if (gRecvCmds[0][1] != 0) { - if (gRecvCmds[0][1] == 0x51) + if (gRecvCmds[0][1] == (ACTIVITY_ACCEPT | IN_UNION_ROOM)) { - arg0->field_98 = 0x51; + data->partnerYesNoResponse = ACTIVITY_ACCEPT | IN_UNION_ROOM; return TRUE; } - else if (gRecvCmds[0][1] == 0x52) + else if (gRecvCmds[0][1] == (ACTIVITY_DECLINE | IN_UNION_ROOM)) { - arg0->field_98 = 0x52; + data->partnerYesNoResponse = ACTIVITY_DECLINE | IN_UNION_ROOM; return TRUE; } } @@ -4132,7 +4170,7 @@ bool32 InUnionRoom(void) ? TRUE : FALSE; } -bool32 HasAtLeastTwoMonsOfLevel30OrLower(void) +static bool32 HasAtLeastTwoMonsOfLevel30OrLower(void) { s32 i; s32 count = 0; @@ -4152,16 +4190,16 @@ bool32 HasAtLeastTwoMonsOfLevel30OrLower(void) return FALSE; } -static void ResetUnionRoomTrade(struct UnionRoomTrade *arg0) +static void ResetUnionRoomTrade(struct UnionRoomTrade *uroomTrade) { - arg0->field_0 = 0; - arg0->type = 0; - arg0->playerPersonality = 0; - arg0->playerSpecies = 0; - arg0->playerLevel = 0; - arg0->species = 0; - arg0->level = 0; - arg0->personality = 0; + 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; } void Script_ResetUnionRoomTrade(void) @@ -4228,36 +4266,36 @@ static u32 GetPartyPositionOfRegisteredMon(struct UnionRoomTrade *trade, u8 mult return response; } -void sub_801818C(bool32 arg0) +static void HandleCancelTrade(bool32 unlockObjs) { - sub_80173B0(); + UR_ClearBg0(); ScriptContext2_Disable(); - sub_8098524(); - gUnknown_02022C2C = 0; - if (arg0) + UnionRoom_UnlockPlayerAndChatPartner(); + gPlayerCurrActivity = 0; + if (unlockObjs) { sub_8010FCC(sUnionRoomTrade.type, sUnionRoomTrade.playerSpecies, sUnionRoomTrade.playerLevel); - sub_8011090(0x40, 0, 0); + UpdateGameDataWithActivitySpriteGendersFlag(IN_UNION_ROOM, 0, 0); } } -void sub_80181CC(void) +static void UR_EnableScriptContext2AndFreezeObjectEvents(void) { ScriptContext2_Enable(); ScriptFreezeObjectEvents(); } -u8 sub_80181DC(struct UnkStruct_URoom *arg0) +static u8 GetActivePartnerSpriteGenderParam(struct WirelessLink_URoom *data) { u8 retVal = 0x80; u8 i; - for (i = 0; i < 4; i++) + for (i = 0; i < RFU_CHILD_MAX; i++) { - if (arg0->field_C->arr[i].unk18) + if (data->field_C->arr[i].active) { - retVal |= arg0->field_C->arr[i].unk0.field_0.playerGender << 3; - retVal |= arg0->field_C->arr[i].unk0.field_0.unk_00.playerTrainerId[0] & 7; + 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; break; } } @@ -4265,7 +4303,7 @@ u8 sub_80181DC(struct UnkStruct_URoom *arg0) return retVal; } -void sub_8018220(u8 *unused, struct UnkStruct_URoom *arg1, bool8 arg2) +static void ViewURoomPartnerTrainerCard(u8 *unused, struct WirelessLink_URoom *data, bool8 isParent) { struct TrainerCard *trainerCard = &gTrainerCards[GetMultiplayerId() ^ 1]; s32 i; @@ -4273,67 +4311,67 @@ void sub_8018220(u8 *unused, struct UnkStruct_URoom *arg1, bool8 arg2) DynamicPlaceholderTextUtil_Reset(); - StringCopy(arg1->field_C0[0], gTrainerClassNames[sub_8068BB0()]); - DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, arg1->field_C0[0]); + StringCopy(data->field_C0[0], gTrainerClassNames[sub_8068BB0()]); + DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, data->field_C0[0]); DynamicPlaceholderTextUtil_SetPlaceholderPtr(1, trainerCard->playerName); - StringCopy(arg1->field_174, sCardColorTexts[trainerCard->stars]); - DynamicPlaceholderTextUtil_SetPlaceholderPtr(2, arg1->field_174); + StringCopy(data->field_174, sCardColorTexts[trainerCard->stars]); + DynamicPlaceholderTextUtil_SetPlaceholderPtr(2, data->field_174); - ConvertIntToDecimalStringN(arg1->field_C0[2], trainerCard->caughtMonsCount, STR_CONV_MODE_LEFT_ALIGN, 3); - DynamicPlaceholderTextUtil_SetPlaceholderPtr(3, arg1->field_C0[2]); + ConvertIntToDecimalStringN(data->field_C0[2], trainerCard->caughtMonsCount, STR_CONV_MODE_LEFT_ALIGN, 3); + DynamicPlaceholderTextUtil_SetPlaceholderPtr(3, data->field_C0[2]); - ConvertIntToDecimalStringN(arg1->field_C0[3], trainerCard->playTimeHours, STR_CONV_MODE_LEFT_ALIGN, 3); - ConvertIntToDecimalStringN(arg1->field_C0[4], trainerCard->playTimeMinutes, STR_CONV_MODE_LEADING_ZEROS, 2); - DynamicPlaceholderTextUtil_SetPlaceholderPtr(4, arg1->field_C0[3]); - DynamicPlaceholderTextUtil_SetPlaceholderPtr(5, arg1->field_C0[4]); + 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]); - DynamicPlaceholderTextUtil_ExpandPlaceholders(arg1->field_1A4, sText_TrainerCardInfoPage1); - StringCopy(gStringVar4, arg1->field_1A4); + DynamicPlaceholderTextUtil_ExpandPlaceholders(data->field_1A4, sText_TrainerCardInfoPage1); + StringCopy(gStringVar4, data->field_1A4); n = trainerCard->linkBattleWins; if (n > 9999) { n = 9999; } - ConvertIntToDecimalStringN(arg1->field_C0[0], n, STR_CONV_MODE_LEFT_ALIGN, 4); - DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, arg1->field_C0[0]); + ConvertIntToDecimalStringN(data->field_C0[0], n, STR_CONV_MODE_LEFT_ALIGN, 4); + DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, data->field_C0[0]); n = trainerCard->linkBattleLosses; if (n > 9999) { n = 9999; } - ConvertIntToDecimalStringN(arg1->field_C0[1], n, STR_CONV_MODE_LEFT_ALIGN, 4); - DynamicPlaceholderTextUtil_SetPlaceholderPtr(2, arg1->field_C0[1]); + ConvertIntToDecimalStringN(data->field_C0[1], n, STR_CONV_MODE_LEFT_ALIGN, 4); + DynamicPlaceholderTextUtil_SetPlaceholderPtr(2, data->field_C0[1]); - ConvertIntToDecimalStringN(arg1->field_C0[2], trainerCard->pokemonTrades, STR_CONV_MODE_LEFT_ALIGN, 5); - DynamicPlaceholderTextUtil_SetPlaceholderPtr(3, arg1->field_C0[2]); + ConvertIntToDecimalStringN(data->field_C0[2], trainerCard->pokemonTrades, STR_CONV_MODE_LEFT_ALIGN, 5); + DynamicPlaceholderTextUtil_SetPlaceholderPtr(3, data->field_C0[2]); for (i = 0; i < TRAINER_CARD_PROFILE_LENGTH; i++) { - CopyEasyChatWord(arg1->field_C0[i + 3], trainerCard->easyChatProfile[i]); - DynamicPlaceholderTextUtil_SetPlaceholderPtr(i + 4, arg1->field_C0[i + 3]); + CopyEasyChatWord(data->field_C0[i + 3], trainerCard->easyChatProfile[i]); + DynamicPlaceholderTextUtil_SetPlaceholderPtr(i + 4, data->field_C0[i + 3]); } - DynamicPlaceholderTextUtil_ExpandPlaceholders(arg1->field_1A4, sText_TrainerCardInfoPage2); - StringAppend(gStringVar4, arg1->field_1A4); + DynamicPlaceholderTextUtil_ExpandPlaceholders(data->field_1A4, sText_TrainerCardInfoPage2); + StringAppend(gStringVar4, data->field_1A4); - if (arg2 == TRUE) + if (isParent == TRUE) { - DynamicPlaceholderTextUtil_ExpandPlaceholders(arg1->field_1A4, sText_FinishedCheckingPlayersTrainerCard); - StringAppend(gStringVar4, arg1->field_1A4); + DynamicPlaceholderTextUtil_ExpandPlaceholders(data->field_1A4, sText_FinishedCheckingPlayersTrainerCard); + StringAppend(gStringVar4, data->field_1A4); } - else if (arg2 == FALSE) + else if (isParent == FALSE) { - DynamicPlaceholderTextUtil_ExpandPlaceholders(arg1->field_1A4, sGladToMeetYouTexts[trainerCard->gender]); - StringAppend(gStringVar4, arg1->field_1A4); + DynamicPlaceholderTextUtil_ExpandPlaceholders(data->field_1A4, sGladToMeetYouTexts[trainerCard->gender]); + StringAppend(gStringVar4, data->field_1A4); } } -void sub_8018404(u8 *dest, struct UnkStruct_x20 *arg1) +static void IntlConvPartnerUname7(u8 *dest, struct UnkStruct_x20 *arg1) { - StringCopy7(dest, arg1->unk.playerName); - ConvertInternationalString(dest, arg1->unk.field_0.unk_00.language); + StringCopy7(dest, arg1->gname_uname.playerName); + ConvertInternationalString(dest, arg1->gname_uname.gname.unk_00.language); } diff --git a/src/union_room_battle.c b/src/union_room_battle.c index 18dd7c3202..e73f9bd245 100644 --- a/src/union_room_battle.c +++ b/src/union_room_battle.c @@ -35,14 +35,14 @@ struct UnkStruct_3000DAC /*0x62*/ u8 filler_62[10]; }; -struct UnkStruct_2022C6C +struct UnionRoomBattleWork { - s16 a0; + s16 textState; }; static struct UnkStruct_3000DAC * gUnknown_03000DAC; -EWRAM_DATA struct UnkStruct_2022C6C * gUnknown_02022C6C = NULL; +EWRAM_DATA struct UnionRoomBattleWork * sWork = NULL; void sub_801A43C(void); void sub_801A6C0(u8 taskId); @@ -53,7 +53,7 @@ const u16 gWirelessInfoScreenPal[] = INCBIN_U16("graphics/interface/wireless_inf const u32 gWirelessInfoScreenGfx[] = INCBIN_U32("graphics/interface/wireless_info_screen.4bpp.lz"); const u32 gWirelessInfoScreenTilemap[] = INCBIN_U32("graphics/interface/wireless_info_screen.bin.lz"); -const struct BgTemplate gUnknown_082F0D34[] = { +static const struct BgTemplate sBgTemplates[] = { { .bg = 0, .charBaseIndex = 2, @@ -67,7 +67,7 @@ const struct BgTemplate gUnknown_082F0D34[] = { } }; -const struct WindowTemplate gUnknown_082F0D3C[] = { +const struct WindowTemplate sWindowTemplates[] = { { .bg = 0x00, .tilemapLeft = 0x03, @@ -191,12 +191,12 @@ void sub_801A43C(void) gUnknown_03000DAC = AllocZeroed(sizeof(struct UnkStruct_3000DAC)); SetVBlankCallback(NULL); ResetBgsAndClearDma3BusyFlags(0); - InitBgsFromTemplates(0, gUnknown_082F0D34, ARRAY_COUNT(gUnknown_082F0D34)); + InitBgsFromTemplates(0, sBgTemplates, ARRAY_COUNT(sBgTemplates)); SetBgTilemapBuffer(1, Alloc(0x800)); SetBgTilemapBuffer(0, Alloc(0x800)); DecompressAndLoadBgGfxUsingHeap(1, gWirelessInfoScreenGfx, 0, 0, 0); CopyToBgTilemapBuffer(1, gWirelessInfoScreenTilemap, 0, 0); - InitWindows(gUnknown_082F0D3C); + InitWindows(sWindowTemplates); DeactivateAllTextPrinters(); ResetPaletteFade(); ResetSpriteData(); @@ -205,7 +205,7 @@ void sub_801A43C(void) m4aSoundVSyncOn(); SetVBlankCallback(sub_801A418); gUnknown_03000DAC->taskId = CreateTask(sub_801A6C0, 0); - gUnknown_03000DAC->unk61 = sub_8013C40(); + gUnknown_03000DAC->unk61 = CreateTask_ListenToWireless(); gUnknown_03000DAC->unk10[3] = 1; ChangeBgX(0, 0, 0); ChangeBgY(0, 0, 0); @@ -369,7 +369,7 @@ static void sub_801A8B0(u8 windowId, u8 fontId, const u8 * str, u8 x, u8 y, u8 m u32 sub_801A960(struct UnkStruct_x20 * a0, u32 * a1) { s32 i, j, r2; - u32 result = a0->unk.field_0.activity; + u32 result = a0->gname_uname.gname.activity; for (i = 0; i < (unsigned)ARRAY_COUNT(gUnknown_082F0D70); i++) { @@ -377,7 +377,7 @@ u32 sub_801A960(struct UnkStruct_x20 * a0, u32 * a1) { continue; } - if (a0->field_1A_0 != 1) + if (a0->groupScheduledAnim != 1) { continue; } @@ -386,7 +386,7 @@ u32 sub_801A960(struct UnkStruct_x20 * a0, u32 * a1) r2 = 0; for (j = 0; j < 4; j++) { - if (a0->unk.field_0.child_sprite_gender[j] != 0) + if (a0->gname_uname.gname.child_sprite_gender[j] != 0) { r2++; } @@ -450,7 +450,7 @@ bool32 sub_801AA30(u32 * a0, u32 * a1, u32 * a2, u8 taskId) void sub_801AAD4(void) { s32 i; - sub_8014210(10); + StartUnionRoomBattle(10); for (i = 0; i < UNION_ROOM_PARTY_SIZE; i++) { gEnemyParty[i] = gPlayerParty[gSelectedOrderFromParty[i] - 1]; @@ -506,13 +506,13 @@ void sub_801AC40(void) TransferPlttBuffer(); } -void sub_801AC54(void) +void CB2_UnionRoomBattle(void) { switch (gMain.state) { case 0: SetGpuReg(REG_OFFSET_DISPCNT, 0x0000); - gUnknown_02022C6C = AllocZeroed(4); + sWork = AllocZeroed(4); ResetSpriteData(); FreeAllSpritePalettes(); ResetTasks(); @@ -535,7 +535,7 @@ void sub_801AC54(void) gMain.state++; break; case 1: - if (sub_801ABDC(&gUnknown_02022C6C->a0, gText_CommStandbyAwaitingOtherPlayer, 0)) + if (sub_801ABDC(&sWork->textState, gText_CommStandbyAwaitingOtherPlayer, 0)) { gMain.state++; } @@ -604,7 +604,7 @@ void sub_801AC54(void) } break; case 7: - if (sub_801ABDC(&gUnknown_02022C6C->a0, gText_RefusedBattle, 1)) + if (sub_801ABDC(&sWork->textState, gText_RefusedBattle, 1)) { SetMainCallback2(CB2_ReturnToField); } @@ -616,7 +616,7 @@ void sub_801AC54(void) } break; case 9: - if (sub_801ABDC(&gUnknown_02022C6C->a0, gText_BattleWasRefused, 1)) + if (sub_801ABDC(&sWork->textState, gText_BattleWasRefused, 1)) { SetMainCallback2(CB2_ReturnToField); } diff --git a/src/union_room_chat.c b/src/union_room_chat.c index f212c69a74..e50d7f1009 100755 --- a/src/union_room_chat.c +++ b/src/union_room_chat.c @@ -588,7 +588,7 @@ const struct SpriteTemplate gUnknown_082F3244 = { .callback = SpriteCallbackDummy }; -void sub_801DD98(void) +void EnterUnionRoomChat(void) { gUnknown_02022C84 = Alloc(sizeof(*gUnknown_02022C84)); sub_801DDD0(gUnknown_02022C84); diff --git a/src/union_room_player_avatar.c b/src/union_room_player_avatar.c index 8a09306c0d..36f3fb6531 100644 --- a/src/union_room_player_avatar.c +++ b/src/union_room_player_avatar.c @@ -17,28 +17,46 @@ static u8 sub_8019DF4(void); static u32 sub_8019F8C(u32 playerIdx, u32 arg1); static void sub_801A3B0(s32 arg0, s32 arg1, u8 arg2); -ALIGNED(4) const u8 gUnknown_082F072C[][10] = { - {0x21, 0x2c, 0x1f, 0x23, 0x25, 0x24, 0x41, 0x42}, - {0x22, 0x28, 0x20, 0x2f, 0x2f, 0x0e, 0x14, 0x2d} +static const u8 sUnionRoomObjGfxIds[GENDER_COUNT][10] = { + [MALE] = { + OBJ_EVENT_GFX_MAN_3, + OBJ_EVENT_GFX_BLACK_BELT, + OBJ_EVENT_GFX_CAMPER, + OBJ_EVENT_GFX_YOUNGSTER, + OBJ_EVENT_GFX_PSYCHIC_M, + OBJ_EVENT_GFX_BUG_CATCHER, + OBJ_EVENT_GFX_MAN_4, + OBJ_EVENT_GFX_MAN_5 + }, + [FEMALE] = { + OBJ_EVENT_GFX_WOMAN_5, + OBJ_EVENT_GFX_HEX_MANIAC, + OBJ_EVENT_GFX_PICNICKER, + OBJ_EVENT_GFX_LASS, + OBJ_EVENT_GFX_LASS, + OBJ_EVENT_GFX_GIRL_3, + OBJ_EVENT_GFX_WOMAN_2, + OBJ_EVENT_GFX_BEAUTY + } }; -static const s16 gUnknown_082F0740[][2] = { - {0x4, 0x6}, - {0xd, 0x8}, - {0xa, 0x6}, - {0x1, 0x8}, - {0xd, 0x4}, - {0x7, 0x4}, - {0x1, 0x4}, - {0x7, 0x8} +static const s16 sUnionPartnerCoords[][2] = { + { 4, 6}, + {13, 8}, + {10, 6}, + { 1, 8}, + {13, 4}, + { 7, 4}, + { 1, 4}, + { 7, 8} }; -static const s8 gUnknown_082F0760[][2] = { - { 0, 0}, - { 1, 0}, - { 0, -1}, - {-1, 0}, - { 0, 1} +static const s8 sFacingDirectionOffsets[][2] = { + [DIR_NONE] = { 0, 0}, + [DIR_SOUTH] = { 1, 0}, + [DIR_NORTH] = { 0, -1}, + [DIR_WEST] = {-1, 0}, + [DIR_EAST] = { 0, 1} }; static const u8 gUnknown_082F076A[] = { @@ -79,22 +97,22 @@ static bool32 is_walking_or_running(void) static u8 sub_8019978(u32 a0, u32 a1) { - return gUnknown_082F072C[a0][a1 % 8]; + return sUnionRoomObjGfxIds[a0][a1 % 8]; } static void sub_8019990(u32 a0, u32 a1, s32 * a2, s32 * a3) { - *a2 = gUnknown_082F0740[a0][0] + gUnknown_082F0760[a1][0] + 7; - *a3 = gUnknown_082F0740[a0][1] + gUnknown_082F0760[a1][1] + 7; + *a2 = sUnionPartnerCoords[a0][0] + sFacingDirectionOffsets[a1][0] + 7; + *a3 = sUnionPartnerCoords[a0][1] + sFacingDirectionOffsets[a1][1] + 7; } static bool32 sub_80199E0(u32 a0, u32 a1, s32 a2, s32 a3) { - if (gUnknown_082F0740[a0][0] + gUnknown_082F0760[a1][0] + 7 != a2) + if (sUnionPartnerCoords[a0][0] + sFacingDirectionOffsets[a1][0] + 7 != a2) { return FALSE; } - else if (gUnknown_082F0740[a0][1] + gUnknown_082F0760[a1][1] + 7 != a3) + else if (sUnionPartnerCoords[a0][1] + sFacingDirectionOffsets[a1][1] + 7 != a3) { return FALSE; } @@ -384,19 +402,19 @@ void sub_8019E3C(void) sub_8019E20(); } -void sub_8019E70(u8 * sp8, s32 r9) +void CreateGroupMemberObjectsInvisible(u8 * sp8, s32 r9) { s32 r7; for (r7 = 0; r7 < 5; r7++) { s32 r5 = 5 * r9 + r7; - sp8[r5] = sprite_new(OBJ_EVENT_GFX_MAN_4, r5 - 0x38, gUnknown_082F0740[r9][0] + gUnknown_082F0760[r7][0], gUnknown_082F0740[r9][1] + gUnknown_082F0760[r7][1], 3, 1); + sp8[r5] = sprite_new(OBJ_EVENT_GFX_MAN_4, r5 - 0x38, sUnionPartnerCoords[r9][0] + sFacingDirectionOffsets[r7][0], sUnionPartnerCoords[r9][1] + sFacingDirectionOffsets[r7][1], 3, 1); sub_8097C44(r5 - 0x38, TRUE); } } -void sub_8019F04(u8 * r5) +void DestroyGroupMemberObjects(u8 * r5) { s32 i; for (i = 0; i < 40; i++) @@ -526,30 +544,30 @@ static void sub_801A214(u32 r5, struct GFtgtGname * unused) } } -static void sub_801A234(struct UnkStruct_URoom *r0) +static void sub_801A234(struct WirelessLink_URoom *r0) { s32 i; struct UnkStruct_x20 * r4; gUnknown_02022C68 = 0; for (i = 0, r4 = r0->field_0->arr; i < 8; i++) { - if (r4[i].field_1A_0 == 1) + if (r4[i].groupScheduledAnim == 1) { - sub_801A16C(i, &r4[i].unk.field_0); + sub_801A16C(i, &r4[i].gname_uname.gname); } - else if (r4[i].field_1A_0 == 2) + else if (r4[i].groupScheduledAnim == 2) { - sub_801A214(i, &r4[i].unk.field_0); + sub_801A214(i, &r4[i].gname_uname.gname); } } } -void sub_801A274(struct UnkStruct_URoom *unused) +void ScheduleUnionRoomPlayerRefresh(struct WirelessLink_URoom *unused) { gUnknown_02022C68 = 300; } -void sub_801A284(struct UnkStruct_URoom *r2) +void HandleUnionRoomPlayerRefresh(struct WirelessLink_URoom *r2) { if (++gUnknown_02022C68 > 300) { @@ -557,7 +575,7 @@ void sub_801A284(struct UnkStruct_URoom *r2) } } -bool32 sub_801A2A8(struct UnkStruct_Main0 *arg0, s16 *arg1, s16 *arg2, u8 *arg3) +bool32 RfuUnionTool_GetGroupAndMemberInFrontOfPlayer(struct UnkStruct_Main0 *arg0, s16 *arg1, s16 *arg2, u8 *arg3) { s16 x, y; s32 i, j; @@ -572,11 +590,11 @@ bool32 sub_801A2A8(struct UnkStruct_Main0 *arg0, s16 *arg1, s16 *arg2, u8 *arg3) for (j = 0; j < 5; j++) { s32 r3 = 5 * i + j; - if (x != gUnknown_082F0740[i][0] + gUnknown_082F0760[j][0] + 7) + if (x != sUnionPartnerCoords[i][0] + sFacingDirectionOffsets[j][0] + 7) { continue; } - if (y != gUnknown_082F0740[i][1] + gUnknown_082F0760[j][1] + 7) + if (y != sUnionPartnerCoords[i][1] + sFacingDirectionOffsets[j][1] + 7) { continue; } @@ -588,7 +606,7 @@ bool32 sub_801A2A8(struct UnkStruct_Main0 *arg0, s16 *arg1, s16 *arg2, u8 *arg3) { continue; } - if (r4[i].field_1A_0 != 1) + if (r4[i].groupScheduledAnim != 1) { continue; } @@ -606,7 +624,7 @@ static void sub_801A3B0(s32 arg0, s32 arg1, u8 arg2) sub_8097B78(5 * arg1 - 0x38 + arg0, arg2); } -void sub_801A3D0(u32 arg0, u32 arg1, struct UnkStruct_Main0 *arg2) +void UpdateUnionGroupMemberFacing(u32 arg0, u32 arg1, struct UnkStruct_Main0 *arg2) { - return sub_801A3B0(arg0, arg1, sub_8019F64(arg0, arg1, &arg2->arr[arg1].unk.field_0)); + return sub_801A3B0(arg0, arg1, sub_8019F64(arg0, arg1, &arg2->arr[arg1].gname_uname.gname)); }