From 6aaf50ee27c175c8e54c7299fdc86d90b0b29187 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Tue, 5 Oct 2021 23:38:36 -0400 Subject: [PATCH] Rename GF Gname, Rfu, finish bulk of Union Room, more link doc --- common_syms/link_rfu_2.txt | 4 +- include/constants/union_room.h | 24 +- include/link_rfu.h | 97 +- include/trade.h | 4 +- include/union_room.h | 98 +- include/union_room_player_avatar.h | 8 +- src/berry_crush.c | 12 +- src/data/union_room.h | 695 +++++----- src/field_player_avatar.c | 32 +- src/librfu_rfu.c | 8 + src/link_rfu_2.c | 1365 ++++++++++---------- src/link_rfu_3.c | 178 ++- src/mystery_gift.c | 52 +- src/overworld.c | 2 +- src/party_menu.c | 4 +- src/pokemon_jump.c | 2 +- src/trade.c | 60 +- src/union_room.c | 1190 +++++++++-------- src/union_room_player_avatar.c | 369 +++--- src/wireless_communication_status_screen.c | 22 +- 20 files changed, 2092 insertions(+), 2134 deletions(-) diff --git a/common_syms/link_rfu_2.txt b/common_syms/link_rfu_2.txt index ac292845e..4b8f02bad 100644 --- a/common_syms/link_rfu_2.txt +++ b/common_syms/link_rfu_2.txt @@ -1,2 +1,2 @@ -gf_rfu_REQ_api -Rfu +gRfuAPIBuffer +gRfu diff --git a/include/constants/union_room.h b/include/constants/union_room.h index d867fb340..6e08c9ebb 100644 --- a/include/constants/union_room.h +++ b/include/constants/union_room.h @@ -1,7 +1,11 @@ #ifndef GUARD_CONSTANTS_UNION_ROOM_H #define GUARD_CONSTANTS_UNION_ROOM_H -#define MAX_UNION_ROOM_PLAYERS 8 +// The number of possible group leaders visible in the Union Room. +// Note that this is different than the number of people actively +// connected as children via the Wireless Adapter, which cannot +// exceed RFU_CHILD_MAX (4), for a total of 5 including the player. +#define MAX_UNION_ROOM_LEADERS 8 #define UNION_ROOM_SPAWN_NONE 0 #define UNION_ROOM_SPAWN_IN 1 @@ -13,8 +17,8 @@ #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_WONDER_CARD_DUP 6 // Duplicates of later WONDER constants +#define ACTIVITY_WONDER_NEWS_DUP 7 // #define ACTIVITY_CARD 8 #define ACTIVITY_POKEMON_JUMP 9 #define ACTIVITY_BERRY_CRUSH 10 @@ -32,9 +36,8 @@ #define ACTIVITY_NPCTALK 19 #define ACTIVITY_PLYRTALK 20 -// Duplicate IDs? -#define ACTIVITY_WONDER_CARD2 21 -#define ACTIVITY_WONDER_NEWS2 22 +#define ACTIVITY_WONDER_CARD 21 +#define ACTIVITY_WONDER_NEWS 22 #define ACTIVITY_CONTEST_COOL 23 #define ACTIVITY_CONTEST_BEAUTY 24 @@ -46,15 +49,6 @@ #define IN_UNION_ROOM (1 << 6) -// 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 diff --git a/include/link_rfu.h b/include/link_rfu.h index 04f1b7f9a..eb071618e 100644 --- a/include/link_rfu.h +++ b/include/link_rfu.h @@ -20,10 +20,10 @@ #define RFUCMD_DISCONNECT 0xED00 #define RFUCMD_DISCONNECT_PARENT 0xEE00 -#define RFU_SERIAL_A 0x0002 -#define RFU_SERIAL_B 0x7F7D -#define RFU_SERIAL_C 0x0000 -#define RFU_SERIAL_END 0xFFFF +#define RFU_SERIAL_GAME 0x0002 // Serial number for Pokémon game (FRLG or Emerald) +#define RFU_SERIAL_WONDER_DISTRIBUTOR 0x7F7D // Serial number for distributing Wonder Cards / News +#define RFU_SERIAL_UNKNOWN 0x0000 // Unreferenced acceptable serial number. Gamecube? +#define RFU_SERIAL_END 0xFFFF #define RECV_QUEUE_NUM_SLOTS 32 #define RECV_QUEUE_SLOT_LENGTH (14 * MAX_RFU_PLAYERS) @@ -68,8 +68,7 @@ enum { RFU_ERROR_STATE_IGNORE, }; -// RfuTgtData.gname is read as these structs. -struct GFtgtGnameSub +struct RfuGameCompatibilityData { u16 language:4; u16 hasNews:1; @@ -79,24 +78,41 @@ struct GFtgtGnameSub u16 hasNationalDex:1; u16 gameClear:1; u16 version:4; + u16 unused:2; u8 playerTrainerId[2]; }; -struct __attribute__((packed, aligned(2))) GFtgtGname +// This struct is sent via the Wireless Adapter as the game name or "gname" data. +// Gname is only applicable during Wireless Single Game Pak Multiplay, when the +// adapter needs this data for connection. Per the RFU manual, during "normal" +// wireless play (the kind the Pokémon games use) the gname data can be used for +// anything the developers want. This struct is what GF decided to use it for. +// It can be up to 13 bytes in size (RFU_GAME_NAME_LENGTH). +// The player's name is sent separately as the username ("uname"), and does not +// use a struct (gHostRfuUsername). +struct __attribute__((packed, aligned(2))) RfuGameData { - struct GFtgtGnameSub unk_00; - u8 child_sprite_gender[RFU_CHILD_MAX]; // u8 sprite_idx:3; - // u8 gender:1; - // u8 unk_4:3 - // u8 active:1 - u16 species:10; - u16 type:6; + struct RfuGameCompatibilityData compatibility; + u8 partnerInfo[RFU_CHILD_MAX]; + u16 tradeSpecies:10; + u16 tradeType:6; u8 activity:7; - u8 started:1; + u8 startedActivity:1; u8 playerGender:1; - u8 level:7; + u8 tradeLevel:7; u8 padding; -}; // size: RFU_GNAME_SIZE +}; + +// Constants for getting/setting information in 'partnerInfo' of RfuGameData. +// This data is used to determine what the link partners look like from +// the host's perspective. +// Bits 0-2 are a shortened trainerId +// Bit 3 is the player's gender +// Bits 4-6 are unknown/unused +// Bit 7 is an 'active' flag +#define PINFO_TID_MASK 0x7 +#define PINFO_GENDER_SHIFT 3 +#define PINFO_ACTIVE_FLAG (1 << 7) struct RfuBlockSend { @@ -136,7 +152,8 @@ struct RfuBackupQueue /* 0x1e */ vu8 count; }; -struct GFRfuManager +// Stores data needed for the RFU on GF's end +struct RfuManager { /* 0x000 */ void (*callback)(void); /* 0x004 */ u16 state; @@ -151,7 +168,7 @@ struct GFRfuManager /* 0x014 */ u8 childRecvBuffer[RFU_CHILD_MAX][CHILD_DATA_LENGTH]; /* 0x04c */ u8 childSendBuffer[CHILD_DATA_LENGTH]; /* 0x05a */ u8 blockRequestType; - /* 0x05b */ u8 unk_5b; + /* 0x05b */ u8 blockSendAttempts; /* 0x05c */ bool8 blockReceived[MAX_RFU_PLAYERS]; /* 0x061 */ bool8 numBlocksReceived[MAX_RFU_PLAYERS]; /* 0x066 */ u8 idleTaskId; @@ -170,9 +187,9 @@ struct GFRfuManager /* 0x100 */ u16 allReadyNum; /* 0x102 */ u8 unk_102; /* 0x103 */ u8 filler_103[7]; - /* 0x10A */ struct GFtgtGname unk_10A; + /* 0x10A */ struct RfuGameData parent; u8 filler_; - u8 playerName[PLAYER_NAME_LENGTH + 1]; + u8 parentName[RFU_USER_NAME_LENGTH]; /* 0x124 */ struct RfuRecvQueue recvQueue; /* 0x9e8 */ struct RfuSendQueue sendQueue; /* 0xc1c */ struct RfuBackupQueue backupQueue; @@ -180,7 +197,7 @@ struct GFRfuManager /* 0xc3d */ u8 unk_c3d; /* 0xc3e */ vu8 childSlot; /* 0xc3f */ u8 unk_c3f[70]; - /* 0xc85 */ u8 unk_c85; + /* 0xc85 */ u8 leaveGroupStatus; /* 0xc86 */ u8 recvStatus; /* 0xc87 */ u8 recvCmds[5][7][2]; /* 0xccd */ u8 parentId; @@ -198,18 +215,18 @@ struct GFRfuManager /* 0xce2 */ u8 unk_ce2; /* 0xce2 */ u8 disconnectSlots; /* 0xce4 */ u8 disconnectMode; - /* 0xce5 */ u8 unk_ce5; - /* 0xce5 */ u8 unk_ce6; + /* 0xce5 */ u8 nextChildBits; + /* 0xce5 */ u8 newChildQueue; /* 0xce7 */ u8 acceptSlot_flag; /* 0xce8 */ bool8 unk_ce8; - /* 0xce9 */ u8 unk_ce9; + /* 0xce9 */ u8 incomingChild; /* 0xcea */ u8 unk_cea[4]; /* 0xcee */ u8 unk_cee[4]; }; // size = 0xcf4 -extern struct GFtgtGname gHostRFUtgtGnameBuffer; -extern u8 gHostRFUtgtUnameBuffer[]; -extern struct GFRfuManager Rfu; +extern struct RfuGameData gHostRfuGameData; +extern u8 gHostRfuUsername[]; +extern struct RfuManager gRfu; extern u8 gWirelessStatusIndicatorSpriteId; void WipeTrainerNameRecords(void); @@ -241,13 +258,13 @@ u32 GetRfuRecvQueueLength(void); void RfuVSync(void); void RfuSetIgnoreError(bool32 enable); u8 RfuGetStatus(void); -struct GFtgtGname *GetHostRFUtgtGname(void); -void UpdateGameData_GroupLockedIn(u8 started); +struct RfuGameData *GetHostRfuGameData(void); +void UpdateGameData_GroupLockedIn(u8 startedActivity); void GetLinkmanErrorParams(u32 msg); void RfuSetStatus(u8 status, u16 msg); u8 Rfu_SetLinkRecovery(bool32 enable); -void LinkRfu3_SetGnameUnameFromStaticBuffers(struct GFtgtGname *buff1, u8 *buff2); -void SetHostRFUtgtGname(u8 activity, u32 child_sprite_genders, bool32 started); +void CopyHostRfuGameDataAndUsername(struct RfuGameData *buff1, u8 *buff2); +void SetHostRfuGameData(u8 activity, u32 partnerInfo, bool32 startedActivity); void InitializeRfuLinkManager_LinkLeader(u32 a0); bool32 IsRfuCommunicatingWithAllChildren(void); void LinkRfu_StopManagerAndFinalizeSlots(void); @@ -264,22 +281,22 @@ void SendLeaveGroupNotice(void); void RecordMixTrainerNames(void); void LinkRfu_CreateConnectionAsParent(void); void LinkRfu_StopManagerBeforeEnteringChat(void); -void UpdateGameData_SetActivity(u8 activity, u32 flags, bool32 started); +void UpdateGameData_SetActivity(u8 activity, u32 flags, bool32 startedActivity); void CreateTask_RfuReconnectWithParent(const u8 *src, u16 trainerId); -void SetGnameBufferWonderFlags(bool32 hasNews, bool32 hasCard); -void ClearAndInitHostRFUtgtGname(void); +void SetHostRfuWonderFlags(bool32 hasNews, bool32 hasCard); +void ResetHostRfuGameData(void); void SetTradeBoardRegisteredMonInfo(u32 type, u32 species, u32 level); void InitializeRfuLinkManager_EnterUnionRoom(void); -void sub_8012188(const u8 *name, struct GFtgtGname *structPtr, u8 a2); +void TryConnectToUnionRoomParent(const u8 *name, struct RfuGameData *structPtr, u8 a2); bool32 IsUnionRoomListenTaskActive(void); void Rfu_SendPacket(void *data); bool32 PlayerHasMetTrainerBefore(u16 id, u8 *name); void Rfu_DisconnectPlayerById(u32 playerIdx); u8 GetLinkPlayerInfoFlags(s32 playerId); void sub_800EF7C(void); -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); +bool8 Rfu_GetCompatiblePlayerData(struct RfuGameData *player, u8 *username, u8 idx); +bool8 Rfu_GetWonderDistributorPlayerData(struct RfuGameData *player, u8 *username, u8 idx); +s32 Rfu_GetIndexOfNewestChild(u8 bits); void CreateTask_RfuIdle(void); void DestroyTask_RfuIdle(void); void ClearRecvCommands(void); @@ -298,7 +315,7 @@ bool8 RfuRecvQueue_Dequeue(struct RfuRecvQueue *queue, u8 *dest); bool8 RfuSendQueue_Dequeue(struct RfuSendQueue *queue, u8 *dest); void RfuBackupQueue_Enqueue(struct RfuBackupQueue *queue, const u8 *q2); bool8 RfuBackupQueue_Dequeue(struct RfuBackupQueue *queue, u8 *q2); -void InitHostRFUtgtGname(struct GFtgtGname *data, u8 activity, bool32 started, s32 child_sprite_genders); +void InitHostRfuGameData(struct RfuGameData *data, u8 activity, bool32 startedActivity, s32 partnerInfo); void CreateWirelessStatusIndicatorSprite(u8 x, u8 y); void DestroyWirelessStatusIndicatorSprite(void); void LoadWirelessStatusIndicatorSpriteGfx(void); diff --git a/include/trade.h b/include/trade.h index bd8ef8f63..05a905ab3 100644 --- a/include/trade.h +++ b/include/trade.h @@ -16,8 +16,8 @@ extern const struct WindowTemplate gTradeEvolutionSceneYesNoWindowTemplate; s32 GetGameProgressForLinkTrade(void); void CB2_StartCreateTradeMenu(void); void CB2_LinkTrade(void); -int CanRegisterMonForTradingBoard(struct GFtgtGnameSub a0, u16, u16, u8); -int GetUnionRoomTradeMessageId(struct GFtgtGnameSub a0, struct GFtgtGnameSub a1, u16 a2, u16 a3, u8 a4, u16 a5, u8 a6); +int CanRegisterMonForTradingBoard(struct RfuGameCompatibilityData a0, u16, u16, u8); +int GetUnionRoomTradeMessageId(struct RfuGameCompatibilityData a0, struct RfuGameCompatibilityData a1, u16 a2, u16 a3, u8 a4, u16 a5, u8 a6); int CanSpinTradeMon(struct Pokemon*, u16); void InitTradeSequenceBgGpuRegs(void); void LinkTradeDrawWindow(void); diff --git a/include/union_room.h b/include/union_room.h index 563a048d3..11dbccf70 100644 --- a/include/union_room.h +++ b/include/union_room.h @@ -5,23 +5,30 @@ #include "link.h" #include "constants/union_room.h" -// Exported type declarations +// In the Union Room the player is only ever connected to ≤ 4 other players. +// However, there can be up to MAX_UNION_ROOM_LEADERS (8) object events to +// represent leaders of recently discovered link groups, and each of those groups +// may have up to MAX_RFU_PLAYERS (5) players in it including the leader. +// These players are represented on-screen by NPC sprites drawn around the leader. +// Thus there can be 40 sprites of other players on-screen, in 8 groups of 5. +#define NUM_UNION_ROOM_SPRITES (MAX_UNION_ROOM_LEADERS * MAX_RFU_PLAYERS) -struct WirelessGnameUnamePair +// The maximum number of recently connected players that can be tracked. +// Note that this is significantly less than NUM_UNION_ROOM_SPRITES, i.e. not +// every player that can be shown in the Union Room can be tracked at once. +// Information such as a group member's gender can instead be read from partnerInfo +// of the leader's RfuGameData by tracking at least all of the group leaders. +#define MAX_RFU_PLAYER_LIST_SIZE 16 + +struct RfuPlayerData { - struct GFtgtGname gname; - u8 ALIGNED(4) playerName[PLAYER_NAME_LENGTH + 1]; + struct RfuGameData data; + u8 ALIGNED(4) name[RFU_USER_NAME_LENGTH]; }; -struct UnkStruct_x1C +struct RfuPlayer { - struct WirelessGnameUnamePair gname_uname; - u8 active:1; -}; - -struct UnkStruct_x20 -{ - struct WirelessGnameUnamePair gname_uname; + struct RfuPlayerData rfu; u16 timeoutCounter; u8 groupScheduledAnim:2; bool8 useRedText:1; // Never set @@ -29,26 +36,27 @@ struct UnkStruct_x20 u8 filler[3]; }; -struct UnkStruct_Main0 +struct RfuPlayerList { - struct UnkStruct_x20 arr[MAX_UNION_ROOM_PLAYERS]; + struct RfuPlayer players[MAX_RFU_PLAYER_LIST_SIZE]; }; -struct UnkStruct_Main4 +struct RfuIncomingPlayer { - struct UnkStruct_x1C arr[MAX_RFU_PLAYERS]; + struct RfuPlayerData rfu; + bool8 active:1; }; -struct UnkStruct_Main8 +struct RfuIncomingPlayerList { - struct UnkStruct_x20 arr[MAX_RFU_PLAYERS]; + struct RfuIncomingPlayer players[MAX_RFU_PLAYERS]; }; struct WirelessLink_Leader { - struct UnkStruct_Main0 *field_0; - struct UnkStruct_Main4 *field_4; - struct UnkStruct_Main8 *field_8; + struct RfuPlayerList *playerList; + struct RfuIncomingPlayerList *incomingPlayerList; + struct RfuPlayerList *playerListBackup; u8 state; u8 textState; u8 delayTimerAfterOk; @@ -57,8 +65,8 @@ struct WirelessLink_Leader u8 nPlayerModeWindowId; u8 listTaskId; u8 playerCount; - u16 field_14; - u8 field_16; + u16 yesNoWindowId; + u8 unused; u8 listenTaskId; u8 activity; u8 joinRequestAnswer; @@ -67,20 +75,20 @@ struct WirelessLink_Leader struct WirelessLink_Group { - struct UnkStruct_Main0 *field_0; - struct UnkStruct_Main4 *field_4; + struct RfuPlayerList *playerList; + struct RfuIncomingPlayerList *incomingPlayerList; u8 state; u8 textState; - u8 field_A; + u8 delayTimerAfterOk; // Unused u8 listWindowId; u8 bButtonCancelWindowId; u8 playerNameAndIdWindowId; u8 listTaskId; u8 leaderId; - u8 field_10; + u8 unused; u8 listenTaskId; - u8 isWonderNews; - u8 field_13; + bool8 isWonderNews; + bool8 showListMenu; // Never set u8 refreshTimer; u8 delayBeforePrint; }; @@ -95,10 +103,10 @@ struct UnionRoomObject struct WirelessLink_URoom { - struct UnkStruct_Main0 *field_0; - struct UnkStruct_Main4 *field_4; - struct UnkStruct_Main0 *field_8; - struct UnkStruct_Main4 *field_C; + struct RfuPlayerList *playerList; + struct RfuIncomingPlayerList *incomingChildList; + struct RfuPlayerList *spawnPlayer; + struct RfuIncomingPlayerList *incomingParentList; u16 unknown; // Never read u16 field_12; u8 state; @@ -107,56 +115,42 @@ struct WirelessLink_URoom u8 filler[4]; u8 topListMenuWindowId; u8 topListMenuId; - u8 tradeBoardSelectWindowId; - u8 tradeBoardDetailsWindowId; + u8 tradeBoardMainWindowId; + u8 tradeBoardHeaderWindowId; u8 unused1; u8 searchTaskId; - u8 spriteIds[40]; + u8 spriteIds[NUM_UNION_ROOM_SPRITES]; u8 unused2; u8 tradeBoardListMenuId; u16 playerSendBuffer[6]; u8 activityRequestStrbufs[4][16]; u16 partnerYesNoResponse; u16 recvActivityRequest[3]; - struct UnionRoomObject objects[MAX_UNION_ROOM_PLAYERS]; + struct UnionRoomObject objects[MAX_UNION_ROOM_LEADERS]; u8 trainerCardStrBuffer[12][15]; u8 trainerCardColorStrBuffer[48]; u8 trainerCardMsgStrBuffer[200]; }; -union WirelessLink_Main -{ - struct WirelessLink_Leader *leader; - struct WirelessLink_Group *group; - struct WirelessLink_URoom *uRoom; -}; - struct UnionRoomTrade { u16 state; u16 type; u32 playerPersonality; u8 offerPlayerId; - u8 filler1; u16 playerSpecies; u16 playerLevel; u16 species; u16 level; - u16 filler2; u32 personality; }; -// Exported RAM declarations - extern u8 gPlayerCurrActivity; -extern union WirelessLink_Main gUnknown_02022C30; -extern struct GFtgtGnameSub gPartnerTgtGnameSub; +extern struct RfuGameCompatibilityData gRfuPartnerCompatibilityData; extern u16 gUnionRoomOfferedSpecies; extern u8 gUnionRoomRequestedMonType; -// Exported ROM declarations - u8 CreateTask_CreateTradeMenu(void); void SetUsingUnionRoomStartMenu(void); void MEvent_CreateTask_CardOrNewsWithFriend(u32 arg0); diff --git a/include/union_room_player_avatar.h b/include/union_room_player_avatar.h index c7add758a..e6526739f 100644 --- a/include/union_room_player_avatar.h +++ b/include/union_room_player_avatar.h @@ -3,12 +3,12 @@ u8 InitUnionRoomPlayerObjects(struct UnionRoomObject *players); void DestroyUnionRoomPlayerObjects(void); -void CreateGroupMemberSpritesInvisible(u8 *spriteIds, s32 playerIdx); -void DestroyGroupMemberSprites(u8 *spriteIds); +void CreateUnionRoomPlayerSprites(u8 *spriteIds, s32 playerIdx); +void DestroyUnionRoomPlayerSprites(u8 *spriteIds); void SetTilesAroundUnionRoomPlayersPassable(void); void ScheduleUnionRoomPlayerRefresh(struct WirelessLink_URoom *uroom); void HandleUnionRoomPlayerRefresh(struct WirelessLink_URoom *uroom); -bool32 TryInteractWithUnionRoomMember(struct UnkStruct_Main0 *main0, s16 *directionPtr, s16 *playerIdxPtr, u8 *spriteIds); -void UpdateUnionRoomMemberFacing(u32 currDirection, u32 playerIdx, struct UnkStruct_Main0 *main0); +bool32 TryInteractWithUnionRoomMember(struct RfuPlayerList *main0, s16 *directionPtr, s16 *playerIdxPtr, u8 *spriteIds); +void UpdateUnionRoomMemberFacing(u32 currDirection, u32 playerIdx, struct RfuPlayerList *main0); #endif //GUARD_UNION_ROOM_PLAYER_AVATAR_H diff --git a/src/berry_crush.c b/src/berry_crush.c index fd0d86c7e..a9818016e 100755 --- a/src/berry_crush.c +++ b/src/berry_crush.c @@ -984,12 +984,12 @@ static u32 QuitBerryCrush(MainCallback exitCallback) return 0; } -#define ERROR_EXIT(exitCallback) \ - { \ - SetMainCallback2(exitCallback); \ - Rfu.unk_10 = 0; \ - Rfu.unk_12 = 0; \ - Rfu.errorState = RFU_ERROR_STATE_1; \ +#define ERROR_EXIT(exitCallback) \ + { \ + SetMainCallback2(exitCallback); \ + gRfu.unk_10 = 0; \ + gRfu.unk_12 = 0; \ + gRfu.errorState = RFU_ERROR_STATE_1; \ } void StartBerryCrush(MainCallback exitCallback) diff --git a/src/data/union_room.h b/src/data/union_room.h index a13068146..80d1e517c 100644 --- a/src/data/union_room.h +++ b/src/data/union_room.h @@ -1,29 +1,27 @@ -// const rom data - ALIGNED(4) static const u8 sText_EmptyString[] = _(""); -ALIGNED(4) const u8 sText_Colon[] = _(":"); -ALIGNED(4) const u8 sText_ID[] = _("{ID}"); -ALIGNED(4) const u8 sText_PleaseStartOver[] = _("Please start over from the beginning."); -ALIGNED(4) const u8 sText_WirelessSearchCanceled[] = _("The WIRELESS COMMUNICATION\nSYSTEM search has been canceled."); -ALIGNED(4) const u8 sText_AwaitingCommunucation2[] = _("Awaiting communication\nfrom another player."); // Unused -ALIGNED(4) const u8 sText_AwaitingCommunication[] = _("{STR_VAR_1}! Awaiting\ncommunication from another player."); -ALIGNED(4) const u8 sText_AwaitingLinkPressStart[] = _("{STR_VAR_1}! Awaiting link!\nPress START when everyone's ready."); -ALIGNED(4) const u8 sJPText_SingleBattle[] = _("シングルバトルを かいさいする"); -ALIGNED(4) const u8 sJPText_DoubleBattle[] = _("ダブルバトルを かいさいする"); -ALIGNED(4) const u8 sJPText_MultiBattle[] = _("マルチバトルを かいさいする"); -ALIGNED(4) const u8 sJPText_TradePokemon[] = _("ポケモンこうかんを かいさいする"); -ALIGNED(4) const u8 sJPText_Chat[] = _("チャットを かいさいする"); -ALIGNED(4) const u8 sJPText_DistWonderCard[] = _("ふしぎなカードをくばる"); -ALIGNED(4) const u8 sJPText_DistWonderNews[] = _("ふしぎなニュースをくばる"); -ALIGNED(4) const u8 sJPText_DistMysteryEvent[] = _("ふしぎなできごとを かいさいする"); // Unused -ALIGNED(4) const u8 sJPText_HoldPokemonJump[] = _("なわとびを かいさいする"); -ALIGNED(4) const u8 sJPText_HoldBerryCrush[] = _("きのみマッシャーを かいさいする"); -ALIGNED(4) const u8 sJPText_HoldBerryPicking[] = _("きのみどりを かいさいする"); -ALIGNED(4) const u8 sJPText_HoldSpinTrade[] = _("ぐるぐるこうかんを かいさいする"); -ALIGNED(4) const u8 sJPText_HoldSpinShop[] = _("ぐるぐるショップを かいさいする"); +ALIGNED(4) static const u8 sText_Colon[] = _(":"); +ALIGNED(4) static const u8 sText_ID[] = _("{ID}"); +ALIGNED(4) static const u8 sText_PleaseStartOver[] = _("Please start over from the beginning."); +ALIGNED(4) static const u8 sText_WirelessSearchCanceled[] = _("The WIRELESS COMMUNICATION\nSYSTEM search has been canceled."); +ALIGNED(4) static const u8 sText_AwaitingCommunucation2[] = _("Awaiting communication\nfrom another player."); // Unused +ALIGNED(4) static const u8 sText_AwaitingCommunication[] = _("{STR_VAR_1}! Awaiting\ncommunication from another player."); +ALIGNED(4) static const u8 sText_AwaitingLinkPressStart[] = _("{STR_VAR_1}! Awaiting link!\nPress START when everyone's ready."); +ALIGNED(4) static const u8 sJPText_SingleBattle[] = _("シングルバトルを かいさいする"); +ALIGNED(4) static const u8 sJPText_DoubleBattle[] = _("ダブルバトルを かいさいする"); +ALIGNED(4) static const u8 sJPText_MultiBattle[] = _("マルチバトルを かいさいする"); +ALIGNED(4) static const u8 sJPText_TradePokemon[] = _("ポケモンこうかんを かいさいする"); +ALIGNED(4) static const u8 sJPText_Chat[] = _("チャットを かいさいする"); +ALIGNED(4) static const u8 sJPText_DistWonderCard[] = _("ふしぎなカードをくばる"); +ALIGNED(4) static const u8 sJPText_DistWonderNews[] = _("ふしぎなニュースをくばる"); +ALIGNED(4) static const u8 sJPText_DistMysteryEvent[] = _("ふしぎなできごとを かいさいする"); // Unused +ALIGNED(4) static const u8 sJPText_HoldPokemonJump[] = _("なわとびを かいさいする"); +ALIGNED(4) static const u8 sJPText_HoldBerryCrush[] = _("きのみマッシャーを かいさいする"); +ALIGNED(4) static const u8 sJPText_HoldBerryPicking[] = _("きのみどりを かいさいする"); +ALIGNED(4) static const u8 sJPText_HoldSpinTrade[] = _("ぐるぐるこうかんを かいさいする"); +ALIGNED(4) static const u8 sJPText_HoldSpinShop[] = _("ぐるぐるショップを かいさいする"); // Unused -const u8 *const sJPLinkGroupActionTexts[] = { +static const u8 *const sJPLinkGroupActionTexts[] = { sJPText_SingleBattle, sJPText_DoubleBattle, sJPText_MultiBattle, @@ -40,14 +38,14 @@ const u8 *const sJPLinkGroupActionTexts[] = { sJPText_HoldSpinShop }; -const u8 sText_1PlayerNeeded[] = _("1 player\nneeded."); -const u8 sText_2PlayersNeeded[] = _("2 players\nneeded."); -const u8 sText_3PlayersNeeded[] = _("3 players\nneeded."); -const u8 sText_4PlayersNeeded[] = _("4 players\nneeded."); -const u8 sText_2PlayerMode[] = _("2-PLAYER\nMODE"); -const u8 sText_3PlayerMode[] = _("3-PLAYER\nMODE"); -const u8 sText_4PlayerMode[] = _("4-PLAYER\nMODE"); -const u8 sText_5PlayerMode[] = _("5-PLAYER\nMODE"); +static const u8 sText_1PlayerNeeded[] = _("1 player\nneeded."); +static const u8 sText_2PlayersNeeded[] = _("2 players\nneeded."); +static const u8 sText_3PlayersNeeded[] = _("3 players\nneeded."); +static const u8 sText_4PlayersNeeded[] = _("4 players\nneeded."); +static const u8 sText_2PlayerMode[] = _("2-PLAYER\nMODE"); +static const u8 sText_3PlayerMode[] = _("3-PLAYER\nMODE"); +static const u8 sText_4PlayerMode[] = _("4-PLAYER\nMODE"); +static const u8 sText_5PlayerMode[] = _("5-PLAYER\nMODE"); static const u8 *const sPlayersNeededOrModeTexts[][5] = { // 2 players required @@ -87,38 +85,38 @@ static const u8 *const sPlayersNeededOrModeTexts[][5] = { } }; -ALIGNED(4) const u8 sText_BButtonCancel[] = _("{B_BUTTON}CANCEL"); -ALIGNED(4) const u8 sJPText_SearchingForParticipants[] = _("ため\nさんかしゃ ぼしゅうちゅう です!"); // Unused, may have been cut off -ALIGNED(4) const u8 sText_PlayerContactedYouForXAccept[] = _("{STR_VAR_2} contacted you for\n{STR_VAR_1}. Accept?"); -ALIGNED(4) const u8 sText_PlayerContactedYouShareX[] = _("{STR_VAR_2} contacted you.\nWill you share {STR_VAR_1}?"); -ALIGNED(4) const u8 sText_PlayerContactedYouAddToMembers[] = _("{STR_VAR_2} contacted you.\nAdd to the members?"); -ALIGNED(4) const u8 sText_AreTheseMembersOK[] = _("{STR_VAR_1}!\nAre these members OK?"); -ALIGNED(4) const u8 sText_CancelModeWithTheseMembers[] = _("Cancel {STR_VAR_1} MODE\nwith these members?"); -ALIGNED(4) const u8 sText_AnOKWasSentToPlayer[] = _("An “OK” was sent\nto {STR_VAR_1}."); -ALIGNED(4) const u8 sText_OtherTrainerUnavailableNow[] = _("The other TRAINER doesn't appear\nto be available now…\p"); -ALIGNED(4) const u8 sText_CantTransmitTrainerTooFar[] = _("You can't transmit with a TRAINER\nwho is too far away.\p"); -ALIGNED(4) const u8 sText_TrainersNotReadyYet[] = _("The other TRAINER(S) is/are not\nready yet.\p"); +ALIGNED(4) static const u8 sText_BButtonCancel[] = _("{B_BUTTON}CANCEL"); +ALIGNED(4) static const u8 sJPText_SearchingForParticipants[] = _("ため\nさんかしゃ ぼしゅうちゅう です!"); // Unused, may have been cut off +ALIGNED(4) static const u8 sText_PlayerContactedYouForXAccept[] = _("{STR_VAR_2} contacted you for\n{STR_VAR_1}. Accept?"); +ALIGNED(4) static const u8 sText_PlayerContactedYouShareX[] = _("{STR_VAR_2} contacted you.\nWill you share {STR_VAR_1}?"); +ALIGNED(4) static const u8 sText_PlayerContactedYouAddToMembers[] = _("{STR_VAR_2} contacted you.\nAdd to the members?"); +ALIGNED(4) static const u8 sText_AreTheseMembersOK[] = _("{STR_VAR_1}!\nAre these members OK?"); +ALIGNED(4) static const u8 sText_CancelModeWithTheseMembers[] = _("Cancel {STR_VAR_1} MODE\nwith these members?"); +ALIGNED(4) static const u8 sText_AnOKWasSentToPlayer[] = _("An “OK” was sent\nto {STR_VAR_1}."); +ALIGNED(4) static const u8 sText_OtherTrainerUnavailableNow[] = _("The other TRAINER doesn't appear\nto be available now…\p"); +ALIGNED(4) static const u8 sText_CantTransmitTrainerTooFar[] = _("You can't transmit with a TRAINER\nwho is too far away.\p"); +ALIGNED(4) static const u8 sText_TrainersNotReadyYet[] = _("The other TRAINER(S) is/are not\nready yet.\p"); static const u8 *const sCantTransmitToTrainerTexts[] = { [UR_TRADE_PLAYER_NOT_READY - 1] = sText_CantTransmitTrainerTooFar, [UR_TRADE_PARTNER_NOT_READY - 1] = sText_TrainersNotReadyYet }; -ALIGNED(4) const u8 sText_ModeWithTheseMembersWillBeCanceled[] = _("The {STR_VAR_1} MODE with\nthese members will be canceled.{PAUSE 60}"); -ALIGNED(4) const u8 sText_MemberNoLongerAvailable[] = _("There is a member who can no\nlonger remain available.\p"); +ALIGNED(4) static const u8 sText_ModeWithTheseMembersWillBeCanceled[] = _("The {STR_VAR_1} MODE with\nthese members will be canceled.{PAUSE 60}"); +ALIGNED(4) static const u8 sText_MemberNoLongerAvailable[] = _("There is a member who can no\nlonger remain available.\p"); static const u8 *const sPlayerUnavailableTexts[] = { sText_OtherTrainerUnavailableNow, sText_MemberNoLongerAvailable }; -ALIGNED(4) const u8 sText_TrainerAppearsUnavailable[] = _("The other TRAINER appears\nunavailable…\p"); -ALIGNED(4) const u8 sText_PlayerSentBackOK[] = _("{STR_VAR_1} sent back an “OK”!"); -ALIGNED(4) const u8 sText_PlayerOKdRegistration[] = _("{STR_VAR_1} OK'd your registration as\na member."); -ALIGNED(4) const u8 sText_PlayerRepliedNo[] = _("{STR_VAR_1} replied, “No…”\p"); -ALIGNED(4) const u8 sText_AwaitingOtherMembers[] = _("{STR_VAR_1}!\nAwaiting other members!"); -ALIGNED(4) const u8 sText_QuitBeingMember[] = _("Quit being a member?"); -ALIGNED(4) const u8 sText_StoppedBeingMember[] = _("You stopped being a member.\p"); +ALIGNED(4) static const u8 sText_TrainerAppearsUnavailable[] = _("The other TRAINER appears\nunavailable…\p"); +ALIGNED(4) static const u8 sText_PlayerSentBackOK[] = _("{STR_VAR_1} sent back an “OK”!"); +ALIGNED(4) static const u8 sText_PlayerOKdRegistration[] = _("{STR_VAR_1} OK'd your registration as\na member."); +ALIGNED(4) static const u8 sText_PlayerRepliedNo[] = _("{STR_VAR_1} replied, “No…”\p"); +ALIGNED(4) static const u8 sText_AwaitingOtherMembers[] = _("{STR_VAR_1}!\nAwaiting other members!"); +ALIGNED(4) static const u8 sText_QuitBeingMember[] = _("Quit being a member?"); +ALIGNED(4) static const u8 sText_StoppedBeingMember[] = _("You stopped being a member.\p"); static const u8 *const sPlayerDisconnectedTexts[] = { [RFU_STATUS_OK] = NULL, @@ -133,12 +131,12 @@ static const u8 *const sPlayerDisconnectedTexts[] = { [RFU_STATUS_LEAVE_GROUP] = sText_StoppedBeingMember }; -ALIGNED(4) const u8 sText_WirelessLinkEstablished[] = _("The WIRELESS COMMUNICATION\nSYSTEM link has been established."); -ALIGNED(4) const u8 sText_WirelessLinkDropped[] = _("The WIRELESS COMMUNICATION\nSYSTEM link has been dropped…"); -ALIGNED(4) const u8 sText_LinkWithFriendDropped[] = _("The link with your friend has been\ndropped…"); -ALIGNED(4) const u8 sText_PlayerRepliedNo2[] = _("{STR_VAR_1} replied, “No…”"); +ALIGNED(4) static const u8 sText_WirelessLinkEstablished[] = _("The WIRELESS COMMUNICATION\nSYSTEM link has been established."); +ALIGNED(4) static const u8 sText_WirelessLinkDropped[] = _("The WIRELESS COMMUNICATION\nSYSTEM link has been dropped…"); +ALIGNED(4) static const u8 sText_LinkWithFriendDropped[] = _("The link with your friend has been\ndropped…"); +ALIGNED(4) static const u8 sText_PlayerRepliedNo2[] = _("{STR_VAR_1} replied, “No…”"); -const u8 *const sLinkDroppedTexts[] = { +static const u8 *const sLinkDroppedTexts[] = { [RFU_STATUS_OK] = NULL, [RFU_STATUS_FATAL_ERROR] = sText_LinkWithFriendDropped, [RFU_STATUS_CONNECTION_ERROR] = sText_LinkWithFriendDropped, @@ -151,8 +149,8 @@ const u8 *const sLinkDroppedTexts[] = { [RFU_STATUS_LEAVE_GROUP] = NULL }; -ALIGNED(4) const u8 sText_DoYouWantXMode[] = _("Do you want the {STR_VAR_2}\nMODE?"); -ALIGNED(4) const u8 sText_DoYouWantXMode2[] = _("Do you want the {STR_VAR_2}\nMODE?"); +ALIGNED(4) static const u8 sText_DoYouWantXMode[] = _("Do you want the {STR_VAR_2}\nMODE?"); +ALIGNED(4) static const u8 sText_DoYouWantXMode2[] = _("Do you want the {STR_VAR_2}\nMODE?"); // Unused static const u8 *const sDoYouWantModeTexts[] = { @@ -160,11 +158,14 @@ static const u8 *const sDoYouWantModeTexts[] = { sText_DoYouWantXMode2 }; -ALIGNED(4) const u8 sText_CommunicatingPleaseWait[] = _("Communicating…\nPlease wait."); // Unused -ALIGNED(4) const u8 sText_AwaitingPlayersResponseAboutTrade[] = _("Awaiting {STR_VAR_1}'s response about\nthe trade…"); -ALIGNED(4) const u8 sText_Communicating[] = _("Communicating{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.\n{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}."); -ALIGNED(4) const u8 sText_CommunicatingWithPlayer[] = _("Communicating with {STR_VAR_1}{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.\n{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}."); -ALIGNED(4) const u8 sText_PleaseWaitAWhile[] = _("Please wait a while{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.\n{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}."); +ALIGNED(4) static const u8 sText_CommunicatingPleaseWait[] = _("Communicating…\nPlease wait."); // Unused +ALIGNED(4) static const u8 sText_AwaitingPlayersResponseAboutTrade[] = _("Awaiting {STR_VAR_1}'s response about\nthe trade…"); +ALIGNED(4) static const u8 sText_Communicating[] = _("Communicating{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.\n" + "{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}."); +ALIGNED(4) static const u8 sText_CommunicatingWithPlayer[] = _("Communicating with {STR_VAR_1}{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.\n" + "{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}."); +ALIGNED(4) static const u8 sText_PleaseWaitAWhile[] = _("Please wait a while{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.\n" + "{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}.{PAUSE 15}."); static const u8 *const sCommunicatingWaitTexts[] = { sText_Communicating, @@ -172,10 +173,10 @@ static const u8 *const sCommunicatingWaitTexts[] = { sText_PleaseWaitAWhile }; -ALIGNED(4) const u8 sText_HiDoSomethingMale[] = _("Hiya! Is there something that you\nwanted to do?"); -ALIGNED(4) const u8 sText_HiDoSomethingFemale[] = _("Hello!\nWould you like to do something?"); -ALIGNED(4) const u8 sText_HiDoSomethingAgainMale[] = _("{STR_VAR_1}: Hiya, we meet again!\nWhat are you up for this time?"); -ALIGNED(4) const u8 sText_HiDoSomethingAgainFemale[] = _("{STR_VAR_1}: Oh! {PLAYER}, hello!\nWould you like to do something?"); +ALIGNED(4) static const u8 sText_HiDoSomethingMale[] = _("Hiya! Is there something that you\nwanted to do?"); +ALIGNED(4) static const u8 sText_HiDoSomethingFemale[] = _("Hello!\nWould you like to do something?"); +ALIGNED(4) static const u8 sText_HiDoSomethingAgainMale[] = _("{STR_VAR_1}: Hiya, we meet again!\nWhat are you up for this time?"); +ALIGNED(4) static const u8 sText_HiDoSomethingAgainFemale[] = _("{STR_VAR_1}: Oh! {PLAYER}, hello!\nWould you like to do something?"); static const u8 *const sHiDoSomethingTexts[][GENDER_COUNT] = { { @@ -187,10 +188,10 @@ static const u8 *const sHiDoSomethingTexts[][GENDER_COUNT] = { } }; -ALIGNED(4) const u8 sText_DoSomethingMale[] = _("Want to do something?"); -ALIGNED(4) const u8 sText_DoSomethingFemale[] = _("Would you like to do something?"); -ALIGNED(4) const u8 sText_DoSomethingAgainMale[] = _("{STR_VAR_1}: What would you like to\ndo now?"); -ALIGNED(4) const u8 sText_DoSomethingAgainFemale[] = _("{STR_VAR_1}: Want to do anything else?"); // Unused +ALIGNED(4) static const u8 sText_DoSomethingMale[] = _("Want to do something?"); +ALIGNED(4) static const u8 sText_DoSomethingFemale[] = _("Would you like to do something?"); +ALIGNED(4) static const u8 sText_DoSomethingAgainMale[] = _("{STR_VAR_1}: What would you like to\ndo now?"); +ALIGNED(4) static const u8 sText_DoSomethingAgainFemale[] = _("{STR_VAR_1}: Want to do anything else?"); // Unused // Unused static const u8 *const sDoSomethingTexts[][GENDER_COUNT] = { @@ -203,31 +204,31 @@ static const u8 *const sDoSomethingTexts[][GENDER_COUNT] = { } }; -ALIGNED(4) const u8 sText_SomebodyHasContactedYou[] = _("Somebody has contacted you.{PAUSE 60}"); -ALIGNED(4) const u8 sText_PlayerHasContactedYou[] = _("{STR_VAR_1} has contacted you.{PAUSE 60}"); +ALIGNED(4) static const u8 sText_SomebodyHasContactedYou[] = _("Somebody has contacted you.{PAUSE 60}"); +ALIGNED(4) static const u8 sText_PlayerHasContactedYou[] = _("{STR_VAR_1} has contacted you.{PAUSE 60}"); static const u8 *const sPlayerContactedYouTexts[] = { sText_SomebodyHasContactedYou, sText_PlayerHasContactedYou }; -ALIGNED(4) const u8 sText_AwaitingResponseFromTrainer[] = _("Awaiting a response from\nthe other TRAINER…"); -ALIGNED(4) const u8 sText_AwaitingResponseFromPlayer[] = _("Awaiting a response from\n{STR_VAR_1}…"); +ALIGNED(4) static const u8 sText_AwaitingResponseFromTrainer[] = _("Awaiting a response from\nthe other TRAINER…"); +ALIGNED(4) static const u8 sText_AwaitingResponseFromPlayer[] = _("Awaiting a response from\n{STR_VAR_1}…"); static const u8 *const sAwaitingResponseTexts[] = { sText_AwaitingResponseFromTrainer, sText_AwaitingResponseFromPlayer }; -ALIGNED(4) const u8 sText_ShowTrainerCard[] = _("The other TRAINER showed\nyou their TRAINER CARD.\pWould you like to show your\nTRAINER CARD?"); -ALIGNED(4) const u8 sText_BattleChallenge[] = _("The other TRAINER challenges you\nto battle.\pWill you accept the battle\nchallenge?"); -ALIGNED(4) const u8 sText_ChatInvitation[] = _("The other TRAINER invites you\nto chat.\pWill you accept the chat\ninvitation?"); -ALIGNED(4) const u8 sText_OfferToTradeMon[] = _("There is an offer to trade your\nregistered Lv. {DYNAMIC 0} {DYNAMIC 1}\pin exchange for a\nLv. {DYNAMIC 2} {DYNAMIC 3}.\pWill you accept this trade\noffer?"); -ALIGNED(4) const u8 sText_OfferToTradeEgg[] = _("There is an offer to trade your\nregistered EGG.\lWill you accept this trade offer?"); -ALIGNED(4) const u8 sText_ChatDropped[] = _("The chat has been dropped.\p"); -ALIGNED(4) const u8 sText_OfferDeclined1[] = _("You declined the offer.\p"); -ALIGNED(4) const u8 sText_OfferDeclined2[] = _("You declined the offer.\p"); -ALIGNED(4) const u8 sText_ChatEnded[] = _("The chat was ended.\p"); +ALIGNED(4) static const u8 sText_ShowTrainerCard[] = _("The other TRAINER showed\nyou their TRAINER CARD.\pWould you like to show your\nTRAINER CARD?"); +ALIGNED(4) static const u8 sText_BattleChallenge[] = _("The other TRAINER challenges you\nto battle.\pWill you accept the battle\nchallenge?"); +ALIGNED(4) static const u8 sText_ChatInvitation[] = _("The other TRAINER invites you\nto chat.\pWill you accept the chat\ninvitation?"); +ALIGNED(4) static const u8 sText_OfferToTradeMon[] = _("There is an offer to trade your\nregistered Lv. {DYNAMIC 0} {DYNAMIC 1}\pin exchange for a\nLv. {DYNAMIC 2} {DYNAMIC 3}.\pWill you accept this trade\noffer?"); +ALIGNED(4) static const u8 sText_OfferToTradeEgg[] = _("There is an offer to trade your\nregistered EGG.\lWill you accept this trade offer?"); +ALIGNED(4) static const u8 sText_ChatDropped[] = _("The chat has been dropped.\p"); +ALIGNED(4) static const u8 sText_OfferDeclined1[] = _("You declined the offer.\p"); +ALIGNED(4) static const u8 sText_OfferDeclined2[] = _("You declined the offer.\p"); +ALIGNED(4) static const u8 sText_ChatEnded[] = _("The chat was ended.\p"); // Unused static const u8 *const sInvitationTexts[] = { @@ -237,10 +238,10 @@ static const u8 *const sInvitationTexts[] = { sText_OfferToTradeMon }; -ALIGNED(4) const u8 sText_JoinChatMale[] = _("Oh, hey! We're in a chat right now.\nWant to join us?"); -ALIGNED(4) const u8 sText_PlayerJoinChatMale[] = _("{STR_VAR_1}: Hey, {PLAYER}!\nWe're having a chat right now.\lWant to join us?"); -ALIGNED(4) const u8 sText_JoinChatFemale[] = _("Oh, hi! We're having a chat now.\nWould you like to join us?"); -ALIGNED(4) const u8 sText_PlayerJoinChatFemale[] = _("{STR_VAR_1}: Oh, hi, {PLAYER}!\nWe're having a chat now.\lWould you like to join us?"); +ALIGNED(4) static const u8 sText_JoinChatMale[] = _("Oh, hey! We're in a chat right now.\nWant to join us?"); +ALIGNED(4) static const u8 sText_PlayerJoinChatMale[] = _("{STR_VAR_1}: Hey, {PLAYER}!\nWe're having a chat right now.\lWant to join us?"); +ALIGNED(4) static const u8 sText_JoinChatFemale[] = _("Oh, hi! We're having a chat now.\nWould you like to join us?"); +ALIGNED(4) static const u8 sText_PlayerJoinChatFemale[] = _("{STR_VAR_1}: Oh, hi, {PLAYER}!\nWe're having a chat now.\lWould you like to join us?"); static const u8 *const sJoinChatTexts[][GENDER_COUNT] = { { @@ -252,13 +253,13 @@ static const u8 *const sJoinChatTexts[][GENDER_COUNT] = { } }; -ALIGNED(4) const u8 sText_TrainerAppearsBusy[] = _("……\nThe TRAINER appears to be busy…\p"); -ALIGNED(4) const u8 sText_WaitForBattleMale[] = _("A battle, huh?\nAll right, just give me some time."); -ALIGNED(4) const u8 sText_WaitForChatMale[] = _("You want to chat, huh?\nSure, just wait a little."); -ALIGNED(4) const u8 sText_ShowTrainerCardMale[] = _("Sure thing! As my “Greetings,”\nhere's my TRAINER CARD."); -ALIGNED(4) const u8 sText_WaitForBattleFemale[] = _("A battle? Of course, but I need\ntime to get ready."); -ALIGNED(4) const u8 sText_WaitForChatFemale[] = _("Did you want to chat?\nOkay, but please wait a moment."); -ALIGNED(4) const u8 sText_ShowTrainerCardFemale[] = _("As my introduction, I'll show you\nmy TRAINER CARD."); +ALIGNED(4) static const u8 sText_TrainerAppearsBusy[] = _("……\nThe TRAINER appears to be busy…\p"); +ALIGNED(4) static const u8 sText_WaitForBattleMale[] = _("A battle, huh?\nAll right, just give me some time."); +ALIGNED(4) static const u8 sText_WaitForChatMale[] = _("You want to chat, huh?\nSure, just wait a little."); +ALIGNED(4) static const u8 sText_ShowTrainerCardMale[] = _("Sure thing! As my “Greetings,”\nhere's my TRAINER CARD."); +ALIGNED(4) static const u8 sText_WaitForBattleFemale[] = _("A battle? Of course, but I need\ntime to get ready."); +ALIGNED(4) static const u8 sText_WaitForChatFemale[] = _("Did you want to chat?\nOkay, but please wait a moment."); +ALIGNED(4) static const u8 sText_ShowTrainerCardFemale[] = _("As my introduction, I'll show you\nmy TRAINER CARD."); static const u8 *const sText_WaitOrShowCardTexts[GENDER_COUNT][4] = { { @@ -274,14 +275,14 @@ static const u8 *const sText_WaitOrShowCardTexts[GENDER_COUNT][4] = { } }; -ALIGNED(4) const u8 sText_WaitForChatMale2[] = _("You want to chat, huh?\nSure, just wait a little."); // Unused -ALIGNED(4) const u8 sText_DoneWaitingBattleMale[] = _("Thanks for waiting!\nLet's get our battle started!{PAUSE 60}"); -ALIGNED(4) const u8 sText_DoneWaitingChatMale[] = _("All right!\nLet's chat!{PAUSE 60}"); -ALIGNED(4) const u8 sText_DoneWaitingBattleFemale[] = _("Sorry I made you wait!\nLet's get started!{PAUSE 60}"); -ALIGNED(4) const u8 sText_DoneWaitingChatFemale[] = _("Sorry I made you wait!\nLet's chat.{PAUSE 60}"); -ALIGNED(4) const u8 sText_TradeWillBeStarted[] = _("The trade will be started.{PAUSE 60}"); -ALIGNED(4) const u8 sText_BattleWillBeStarted[] = _("The battle will be started.{PAUSE 60}"); -ALIGNED(4) const u8 sText_EnteringChat[] = _("Entering the chat…{PAUSE 60}"); +ALIGNED(4) static const u8 sText_WaitForChatMale2[] = _("You want to chat, huh?\nSure, just wait a little."); // Unused +ALIGNED(4) static const u8 sText_DoneWaitingBattleMale[] = _("Thanks for waiting!\nLet's get our battle started!{PAUSE 60}"); +ALIGNED(4) static const u8 sText_DoneWaitingChatMale[] = _("All right!\nLet's chat!{PAUSE 60}"); +ALIGNED(4) static const u8 sText_DoneWaitingBattleFemale[] = _("Sorry I made you wait!\nLet's get started!{PAUSE 60}"); +ALIGNED(4) static const u8 sText_DoneWaitingChatFemale[] = _("Sorry I made you wait!\nLet's chat.{PAUSE 60}"); +ALIGNED(4) static const u8 sText_TradeWillBeStarted[] = _("The trade will be started.{PAUSE 60}"); +ALIGNED(4) static const u8 sText_BattleWillBeStarted[] = _("The battle will be started.{PAUSE 60}"); +ALIGNED(4) static const u8 sText_EnteringChat[] = _("Entering the chat…{PAUSE 60}"); static const u8 *const sStartActivityTexts[][GENDER_COUNT][3] = { { @@ -307,36 +308,36 @@ static const u8 *const sStartActivityTexts[][GENDER_COUNT][3] = { } }; -ALIGNED(4) const u8 sText_BattleDeclinedMale[] = _("Sorry! My POKéMON don't seem to\nbe feeling too well right now.\lLet me battle you another time.\p"); -ALIGNED(4) const u8 sText_BattleDeclinedFemale[] = _("I'm terribly sorry, but my POKéMON\naren't feeling well…\pLet's battle another time.\p"); +ALIGNED(4) static const u8 sText_BattleDeclinedMale[] = _("Sorry! My POKéMON don't seem to\nbe feeling too well right now.\lLet me battle you another time.\p"); +ALIGNED(4) static const u8 sText_BattleDeclinedFemale[] = _("I'm terribly sorry, but my POKéMON\naren't feeling well…\pLet's battle another time.\p"); -const u8 *const sBattleDeclinedTexts[GENDER_COUNT] = { +static const u8 *const sBattleDeclinedTexts[GENDER_COUNT] = { sText_BattleDeclinedMale, sText_BattleDeclinedFemale }; -ALIGNED(4) const u8 sText_ShowTrainerCardDeclinedMale[] = _("Huh? My TRAINER CARD…\nWhere'd it go now?\lSorry! I'll show you another time!\p"); -ALIGNED(4) const u8 sText_ShowTrainerCardDeclinedFemale[] = _("Oh? Now where did I put my\nTRAINER CARD?…\lSorry! I'll show you later!\p"); +ALIGNED(4) static const u8 sText_ShowTrainerCardDeclinedMale[] = _("Huh? My TRAINER CARD…\nWhere'd it go now?\lSorry! I'll show you another time!\p"); +ALIGNED(4) static const u8 sText_ShowTrainerCardDeclinedFemale[] = _("Oh? Now where did I put my\nTRAINER CARD?…\lSorry! I'll show you later!\p"); -const u8 *const sShowTrainerCardDeclinedTexts[GENDER_COUNT] = { +static const u8 *const sShowTrainerCardDeclinedTexts[GENDER_COUNT] = { sText_ShowTrainerCardDeclinedMale, sText_ShowTrainerCardDeclinedFemale }; -ALIGNED(4) const u8 sText_IfYouWantToDoSomethingMale[] = _("If you want to do something with\nme, just give me a shout!\p"); -ALIGNED(4) const u8 sText_IfYouWantToDoSomethingFemale[] = _("If you want to do something with\nme, don't be shy.\p"); +ALIGNED(4) static const u8 sText_IfYouWantToDoSomethingMale[] = _("If you want to do something with\nme, just give me a shout!\p"); +ALIGNED(4) static const u8 sText_IfYouWantToDoSomethingFemale[] = _("If you want to do something with\nme, don't be shy.\p"); -const u8 *const sIfYouWantToDoSomethingTexts[GENDER_COUNT] = { +static const u8 *const sIfYouWantToDoSomethingTexts[GENDER_COUNT] = { sText_IfYouWantToDoSomethingMale, sText_IfYouWantToDoSomethingFemale }; -ALIGNED(4) const u8 sText_TrainerBattleBusy[] = _("Whoops! Sorry, but I have to do\nsomething else.\lAnother time, okay?\p"); -ALIGNED(4) const u8 sText_NeedTwoMonsOfLevel30OrLower1[] = _("If you want to battle, you need\ntwo POKéMON that are below\lLv. 30.\p"); -ALIGNED(4) const u8 sText_NeedTwoMonsOfLevel30OrLower2[] = _("For a battle, you need two\nPOKéMON that are below Lv. 30.\p"); +ALIGNED(4) static const u8 sText_TrainerBattleBusy[] = _("Whoops! Sorry, but I have to do\nsomething else.\lAnother time, okay?\p"); +ALIGNED(4) static const u8 sText_NeedTwoMonsOfLevel30OrLower1[] = _("If you want to battle, you need\ntwo POKéMON that are below\lLv. 30.\p"); +ALIGNED(4) static const u8 sText_NeedTwoMonsOfLevel30OrLower2[] = _("For a battle, you need two\nPOKéMON that are below Lv. 30.\p"); -ALIGNED(4) const u8 sText_DeclineChatMale[] = _("Oh, all right.\nCome see me anytime, okay?\p"); -ALIGNED(4) const u8 stext_DeclineChatFemale[] = _("Oh…\nPlease come by anytime.\p"); +ALIGNED(4) static const u8 sText_DeclineChatMale[] = _("Oh, all right.\nCome see me anytime, okay?\p"); +ALIGNED(4) static const u8 stext_DeclineChatFemale[] = _("Oh…\nPlease come by anytime.\p"); // Response from partner when player declines chat static const u8 *const sDeclineChatTexts[GENDER_COUNT] = { @@ -344,8 +345,8 @@ static const u8 *const sDeclineChatTexts[GENDER_COUNT] = { stext_DeclineChatFemale }; -ALIGNED(4) const u8 sText_ChatDeclinedMale[] = _("Oh, sorry!\nI just can't right this instant.\lLet's chat another time.\p"); -ALIGNED(4) const u8 sText_ChatDeclinedFemale[] = _("Oh, I'm sorry.\nI have too much to do right now.\lLet's chat some other time.\p"); +ALIGNED(4) static const u8 sText_ChatDeclinedMale[] = _("Oh, sorry!\nI just can't right this instant.\lLet's chat another time.\p"); +ALIGNED(4) static const u8 sText_ChatDeclinedFemale[] = _("Oh, I'm sorry.\nI have too much to do right now.\lLet's chat some other time.\p"); // Response from partner when they decline chat static const u8 *const sChatDeclinedTexts[GENDER_COUNT] = { @@ -353,16 +354,16 @@ static const u8 *const sChatDeclinedTexts[GENDER_COUNT] = { sText_ChatDeclinedFemale }; -ALIGNED(4) const u8 sText_YoureToughMale[] = _("Whoa!\nI can tell you're pretty tough!\p"); -ALIGNED(4) const u8 sText_UsedGoodMoveMale[] = _("You used that move?\nThat's good strategy!\p"); -ALIGNED(4) const u8 sText_BattleSurpriseMale[] = _("Way to go!\nThat was an eye-opener!\p"); -ALIGNED(4) const u8 sText_SwitchedMonsMale[] = _("Oh! How could you use that\nPOKéMON in that situation?\p"); -ALIGNED(4) const u8 sText_YoureToughFemale[] = _("That POKéMON…\nIt's been raised really well!\p"); -ALIGNED(4) const u8 sText_UsedGoodMoveFemale[] = _("That's it!\nThis is the right move now!\p"); -ALIGNED(4) const u8 sText_BattleSurpriseFemale[] = _("That's awesome!\nYou can battle that way?\p"); -ALIGNED(4) const u8 sText_SwitchedMonsFemale[] = _("You have exquisite timing for\nswitching POKéMON!\p"); +ALIGNED(4) static const u8 sText_YoureToughMale[] = _("Whoa!\nI can tell you're pretty tough!\p"); +ALIGNED(4) static const u8 sText_UsedGoodMoveMale[] = _("You used that move?\nThat's good strategy!\p"); +ALIGNED(4) static const u8 sText_BattleSurpriseMale[] = _("Way to go!\nThat was an eye-opener!\p"); +ALIGNED(4) static const u8 sText_SwitchedMonsMale[] = _("Oh! How could you use that\nPOKéMON in that situation?\p"); +ALIGNED(4) static const u8 sText_YoureToughFemale[] = _("That POKéMON…\nIt's been raised really well!\p"); +ALIGNED(4) static const u8 sText_UsedGoodMoveFemale[] = _("That's it!\nThis is the right move now!\p"); +ALIGNED(4) static const u8 sText_BattleSurpriseFemale[] = _("That's awesome!\nYou can battle that way?\p"); +ALIGNED(4) static const u8 sText_SwitchedMonsFemale[] = _("You have exquisite timing for\nswitching POKéMON!\p"); -const u8 *const sBattleReactionTexts[GENDER_COUNT][4] = { +static const u8 *const sBattleReactionTexts[GENDER_COUNT][4] = { { sText_YoureToughMale, sText_UsedGoodMoveMale, @@ -377,16 +378,16 @@ const u8 *const sBattleReactionTexts[GENDER_COUNT][4] = { } }; -ALIGNED(4) const u8 sText_LearnedSomethingMale[] = _("Oh, I see!\nThis is educational!\p"); -ALIGNED(4) const u8 sText_ThatsFunnyMale[] = _("Don't say anything funny anymore!\nI'm sore from laughing!\p"); -ALIGNED(4) const u8 sText_RandomChatMale1[] = _("Oh?\nSomething like that happened.\p"); -ALIGNED(4) const u8 sText_RandomChatMale2[] = _("Hmhm… What?\nSo is this what you're saying?\p"); -ALIGNED(4) const u8 sText_LearnedSomethingFemale[] = _("Is that right?\nI didn't know that.\p"); -ALIGNED(4) const u8 sText_ThatsFunnyFemale[] = _("Ahaha!\nWhat is that about?\p"); -ALIGNED(4) const u8 sText_RandomChatFemale1[] = _("Yes, that's exactly it!\nThat's what I meant.\p"); -ALIGNED(4) const u8 sText_RandomChatFemale2[] = _("In other words…\nYes! That's right!\p"); +ALIGNED(4) static const u8 sText_LearnedSomethingMale[] = _("Oh, I see!\nThis is educational!\p"); +ALIGNED(4) static const u8 sText_ThatsFunnyMale[] = _("Don't say anything funny anymore!\nI'm sore from laughing!\p"); +ALIGNED(4) static const u8 sText_RandomChatMale1[] = _("Oh?\nSomething like that happened.\p"); +ALIGNED(4) static const u8 sText_RandomChatMale2[] = _("Hmhm… What?\nSo is this what you're saying?\p"); +ALIGNED(4) static const u8 sText_LearnedSomethingFemale[] = _("Is that right?\nI didn't know that.\p"); +ALIGNED(4) static const u8 sText_ThatsFunnyFemale[] = _("Ahaha!\nWhat is that about?\p"); +ALIGNED(4) static const u8 sText_RandomChatFemale1[] = _("Yes, that's exactly it!\nThat's what I meant.\p"); +ALIGNED(4) static const u8 sText_RandomChatFemale2[] = _("In other words…\nYes! That's right!\p"); -const u8 *const sChatReactionTexts[GENDER_COUNT][4] = { +static const u8 *const sChatReactionTexts[GENDER_COUNT][4] = { { sText_LearnedSomethingMale, sText_ThatsFunnyMale, @@ -401,12 +402,12 @@ const u8 *const sChatReactionTexts[GENDER_COUNT][4] = { } }; -ALIGNED(4) const u8 sText_ShowedTrainerCardMale1[] = _("I'm just showing my TRAINER CARD\nas my way of greeting.\p"); -ALIGNED(4) const u8 sText_ShowedTrainerCardMale2[] = _("I hope I get to know you better!\p"); -ALIGNED(4) const u8 sText_ShowedTrainerCardFemale1[] = _("We're showing each other our\nTRAINER CARDS to get acquainted.\p"); -ALIGNED(4) const u8 sText_ShowedTrainerCardFemale2[] = _("Glad to meet you.\nPlease don't be a stranger!\p"); +ALIGNED(4) static const u8 sText_ShowedTrainerCardMale1[] = _("I'm just showing my TRAINER CARD\nas my way of greeting.\p"); +ALIGNED(4) static const u8 sText_ShowedTrainerCardMale2[] = _("I hope I get to know you better!\p"); +ALIGNED(4) static const u8 sText_ShowedTrainerCardFemale1[] = _("We're showing each other our\nTRAINER CARDS to get acquainted.\p"); +ALIGNED(4) static const u8 sText_ShowedTrainerCardFemale2[] = _("Glad to meet you.\nPlease don't be a stranger!\p"); -const u8 *const sTrainerCardReactionTexts[GENDER_COUNT][2] = { +static const u8 *const sTrainerCardReactionTexts[GENDER_COUNT][2] = { { sText_ShowedTrainerCardMale1, sText_ShowedTrainerCardMale2 @@ -417,12 +418,12 @@ const u8 *const sTrainerCardReactionTexts[GENDER_COUNT][2] = { } }; -ALIGNED(4) const u8 sText_MaleTraded1[] = _("Yeahah!\nI really wanted this POKéMON!\p"); -ALIGNED(4) const u8 sText_MaleTraded2[] = _("Finally, a trade got me that\nPOKéMON I'd wanted a long time.\p"); -ALIGNED(4) const u8 sText_FemaleTraded1[] = _("I'm trading POKéMON right now.\p"); -ALIGNED(4) const u8 sText_FemaleTraded2[] = _("I finally got that POKéMON I\nwanted in a trade!\p"); +ALIGNED(4) static const u8 sText_MaleTraded1[] = _("Yeahah!\nI really wanted this POKéMON!\p"); +ALIGNED(4) static const u8 sText_MaleTraded2[] = _("Finally, a trade got me that\nPOKéMON I'd wanted a long time.\p"); +ALIGNED(4) static const u8 sText_FemaleTraded1[] = _("I'm trading POKéMON right now.\p"); +ALIGNED(4) static const u8 sText_FemaleTraded2[] = _("I finally got that POKéMON I\nwanted in a trade!\p"); -const u8 *const sTradeReactionTexts[GENDER_COUNT][4] = { +static const u8 *const sTradeReactionTexts[GENDER_COUNT][4] = { { sText_MaleTraded1, sText_MaleTraded2 @@ -433,57 +434,66 @@ const u8 *const sTradeReactionTexts[GENDER_COUNT][4] = { } }; -ALIGNED(4) const u8 sText_XCheckedTradingBoard[] = _("{STR_VAR_1} checked the\nTRADING BOARD.\p"); -ALIGNED(4) const u8 sText_RegisterMonAtTradingBoard[] = _("Welcome to the TRADING BOARD.\pYou may register your POKéMON\nand offer it up for a trade.\pWould you like to register one of\nyour POKéMON?"); -ALIGNED(4) const u8 sText_TradingBoardInfo[] = _("This TRADING BOARD is used for\noffering a POKéMON for a trade.\pAll you need to do is register a\nPOKéMON for a trade.\pAnother TRAINER may offer a party\nPOKéMON in return for the trade.\pWe hope you will register POKéMON\nand trade them with many, many\lother TRAINERS.\pWould you like to register one of\nyour POKéMON?"); -ALIGNED(4) const u8 sText_ThankYouForRegistering[] = _("We have registered your POKéMON for\ntrade on the TRADING BOARD.\pThank you for using this service!\p"); // unused -ALIGNED(4) const u8 sText_NobodyHasRegistered[] = _("Nobody has registered any POKéMON\nfor trade on the TRADING BOARD.\p\n"); // unused -ALIGNED(4) const u8 sText_ChooseRequestedMonType[] = _("Please choose the type of POKéMON\nthat you would like in the trade.\n"); -ALIGNED(4) const u8 sText_WhichMonWillYouOffer[] = _("Which of your party POKéMON will\nyou offer in trade?\p"); -ALIGNED(4) const u8 sText_RegistrationCanceled[] = _("Registration has been canceled.\p"); -ALIGNED(4) const u8 sText_RegistraionCompleted[] = _("Registration has been completed.\p"); -ALIGNED(4) const u8 sText_TradeCanceled[] = _("The trade has been canceled.\p"); -ALIGNED(4) const u8 sText_CancelRegistrationOfMon[] = _("Cancel the registration of your\nLv. {STR_VAR_2} {STR_VAR_1}?"); -ALIGNED(4) const u8 sText_CancelRegistrationOfEgg[] = _("Cancel the registration of your\nEGG?"); -ALIGNED(4) const u8 sText_RegistrationCanceled2[] = _("The registration has been canceled.\p"); -ALIGNED(4) const u8 sText_TradeTrainersWillBeListed[] = _("TRAINERS wishing to make a trade\nwill be listed."); // unused -ALIGNED(4) const u8 sText_ChooseTrainerToTradeWith2[] = _("Please choose the TRAINER with whom\nyou would like to trade POKéMON."); // unused -ALIGNED(4) const u8 sText_AskTrainerToMakeTrade[] = _("Would you like to ask {STR_VAR_1} to\nmake a trade?"); -ALIGNED(4) const u8 sText_AwaitingResponseFromTrainer2[] = _("Awaiting a response from\nthe other TRAINER…"); // unused -ALIGNED(4) const u8 sText_NotRegisteredAMonForTrade[] = _("You have not registered a POKéMON\nfor trading.\p"); // unused -ALIGNED(4) const u8 sText_DontHaveTypeTrainerWants[] = _("You don't have a {STR_VAR_2}-type\nPOKéMON that {STR_VAR_1} wants.\p"); -ALIGNED(4) const u8 sText_DontHaveEggTrainerWants[] = _("You don't have an EGG that\n{STR_VAR_1} wants.\p"); -ALIGNED(4) const u8 sText_PlayerCantTradeForYourMon[] = _("{STR_VAR_1} can't make a trade for\nyour POKéMON right now.\p"); -ALIGNED(4) const u8 sText_CantTradeForPartnersMon[] = _("You can't make a trade for\n{STR_VAR_1}'s POKéMON right now.\p"); +ALIGNED(4) static const u8 sText_XCheckedTradingBoard[] = _("{STR_VAR_1} checked the\nTRADING BOARD.\p"); +ALIGNED(4) static const u8 sText_RegisterMonAtTradingBoard[] = _("Welcome to the TRADING BOARD.\pYou may register your POKéMON\nand offer it up for a trade.\pWould you like to register one of\nyour POKéMON?"); +ALIGNED(4) static const u8 sText_TradingBoardInfo[] = _("This TRADING BOARD is used for\n" + "offering a POKéMON for a trade.\p" + "All you need to do is register a\n" + "POKéMON for a trade.\p" + "Another TRAINER may offer a party\n" + "POKéMON in return for the trade.\p" + "We hope you will register POKéMON\n" + "and trade them with many, many\l" + "other TRAINERS.\p" + "Would you like to register one of\nyour POKéMON?"); +ALIGNED(4) static const u8 sText_ThankYouForRegistering[] = _("We have registered your POKéMON for\ntrade on the TRADING BOARD.\pThank you for using this service!\p"); // unused +ALIGNED(4) static const u8 sText_NobodyHasRegistered[] = _("Nobody has registered any POKéMON\nfor trade on the TRADING BOARD.\p\n"); // unused +ALIGNED(4) static const u8 sText_ChooseRequestedMonType[] = _("Please choose the type of POKéMON\nthat you would like in the trade.\n"); +ALIGNED(4) static const u8 sText_WhichMonWillYouOffer[] = _("Which of your party POKéMON will\nyou offer in trade?\p"); +ALIGNED(4) static const u8 sText_RegistrationCanceled[] = _("Registration has been canceled.\p"); +ALIGNED(4) static const u8 sText_RegistraionCompleted[] = _("Registration has been completed.\p"); +ALIGNED(4) static const u8 sText_TradeCanceled[] = _("The trade has been canceled.\p"); +ALIGNED(4) static const u8 sText_CancelRegistrationOfMon[] = _("Cancel the registration of your\nLv. {STR_VAR_2} {STR_VAR_1}?"); +ALIGNED(4) static const u8 sText_CancelRegistrationOfEgg[] = _("Cancel the registration of your\nEGG?"); +ALIGNED(4) static const u8 sText_RegistrationCanceled2[] = _("The registration has been canceled.\p"); +ALIGNED(4) static const u8 sText_TradeTrainersWillBeListed[] = _("TRAINERS wishing to make a trade\nwill be listed."); // unused +ALIGNED(4) static const u8 sText_ChooseTrainerToTradeWith2[] = _("Please choose the TRAINER with whom\nyou would like to trade POKéMON."); // unused +ALIGNED(4) static const u8 sText_AskTrainerToMakeTrade[] = _("Would you like to ask {STR_VAR_1} to\nmake a trade?"); +ALIGNED(4) static const u8 sText_AwaitingResponseFromTrainer2[] = _("Awaiting a response from\nthe other TRAINER…"); // unused +ALIGNED(4) static const u8 sText_NotRegisteredAMonForTrade[] = _("You have not registered a POKéMON\nfor trading.\p"); // unused +ALIGNED(4) static const u8 sText_DontHaveTypeTrainerWants[] = _("You don't have a {STR_VAR_2}-type\nPOKéMON that {STR_VAR_1} wants.\p"); +ALIGNED(4) static const u8 sText_DontHaveEggTrainerWants[] = _("You don't have an EGG that\n{STR_VAR_1} wants.\p"); +ALIGNED(4) static const u8 sText_PlayerCantTradeForYourMon[] = _("{STR_VAR_1} can't make a trade for\nyour POKéMON right now.\p"); +ALIGNED(4) static const u8 sText_CantTradeForPartnersMon[] = _("You can't make a trade for\n{STR_VAR_1}'s POKéMON right now.\p"); // Unused -const u8 *const sCantTradeMonTexts[] = { +static const u8 *const sCantTradeMonTexts[] = { sText_PlayerCantTradeForYourMon, sText_CantTradeForPartnersMon }; -ALIGNED(4) const u8 sText_TradeOfferRejected[] = _("Your trade offer was rejected.\p"); -ALIGNED(4) const u8 sText_EggTrade[] = _("EGG TRADE"); -ALIGNED(4) const u8 sText_ChooseJoinCancel[] = _("{DPAD_UPDOWN}CHOOSE {A_BUTTON}JOIN {B_BUTTON}CANCEL"); -ALIGNED(4) const u8 sText_ChooseTrainer[] = _("Please choose a TRAINER."); -ALIGNED(4) const u8 sText_ChooseTrainerSingleBattle[] = _("Please choose a TRAINER for\na SINGLE BATTLE."); -ALIGNED(4) const u8 sText_ChooseTrainerDoubleBattle[] = _("Please choose a TRAINER for\na DOUBLE BATTLE."); -ALIGNED(4) const u8 sText_ChooseLeaderMultiBattle[] = _("Please choose the LEADER\nfor a MULTI BATTLE."); -ALIGNED(4) const u8 sText_ChooseTrainerToTradeWith[] = _("Please choose the TRAINER to\ntrade with."); -ALIGNED(4) const u8 sText_ChooseTrainerToShareWonderCards[] = _("Please choose the TRAINER who is\nsharing WONDER CARDS."); -ALIGNED(4) const u8 sText_ChooseTrainerToShareWonderNews[] = _("Please choose the TRAINER who is\nsharing WONDER NEWS."); -ALIGNED(4) const u8 sText_ChooseLeaderPokemonJump[] = _("Jump with mini POKéMON!\nPlease choose the LEADER."); -ALIGNED(4) const u8 sText_ChooseLeaderBerryCrush[] = _("BERRY CRUSH!\nPlease choose the LEADER."); -ALIGNED(4) const u8 sText_ChooseLeaderBerryPicking[] = _("DODRIO BERRY-PICKING!\nPlease choose the LEADER."); -ALIGNED(4) const u8 sText_ChooseLeaderBerryBlender[] = _("BERRY BLENDER!\nPlease choose the LEADER."); -ALIGNED(4) const u8 sText_ChooseLeaderRecordCorner[] = _("RECORD CORNER!\nPlease choose the LEADER."); -ALIGNED(4) const u8 sText_ChooseLeaderCoolContest[] = _("COOLNESS CONTEST!\nPlease choose the LEADER."); -ALIGNED(4) const u8 sText_ChooseLeaderBeautyContest[] = _("BEAUTY CONTEST!\nPlease choose the LEADER."); -ALIGNED(4) const u8 sText_ChooseLeaderCuteContest[] = _("CUTENESS CONTEST!\nPlease choose the LEADER."); -ALIGNED(4) const u8 sText_ChooseLeaderSmartContest[] = _("SMARTNESS CONTEST!\nPlease choose the LEADER."); -ALIGNED(4) const u8 sText_ChooseLeaderToughContest[] = _("TOUGHNESS CONTEST!\nPlease choose the LEADER."); -ALIGNED(4) const u8 sText_ChooseLeaderBattleTowerLv50[] = _("BATTLE TOWER LEVEL 50!\nPlease choose the LEADER."); -ALIGNED(4) const u8 sText_ChooseLeaderBattleTowerOpenLv[] = _("BATTLE TOWER OPEN LEVEL!\nPlease choose the LEADER."); +ALIGNED(4) static const u8 sText_TradeOfferRejected[] = _("Your trade offer was rejected.\p"); +ALIGNED(4) static const u8 sText_EggTrade[] = _("EGG TRADE"); +ALIGNED(4) static const u8 sText_ChooseJoinCancel[] = _("{DPAD_UPDOWN}CHOOSE {A_BUTTON}JOIN {B_BUTTON}CANCEL"); +ALIGNED(4) static const u8 sText_ChooseTrainer[] = _("Please choose a TRAINER."); +ALIGNED(4) static const u8 sText_ChooseTrainerSingleBattle[] = _("Please choose a TRAINER for\na SINGLE BATTLE."); +ALIGNED(4) static const u8 sText_ChooseTrainerDoubleBattle[] = _("Please choose a TRAINER for\na DOUBLE BATTLE."); +ALIGNED(4) static const u8 sText_ChooseLeaderMultiBattle[] = _("Please choose the LEADER\nfor a MULTI BATTLE."); +ALIGNED(4) static const u8 sText_ChooseTrainerToTradeWith[] = _("Please choose the TRAINER to\ntrade with."); +ALIGNED(4) static const u8 sText_ChooseTrainerToShareWonderCards[] = _("Please choose the TRAINER who is\nsharing WONDER CARDS."); +ALIGNED(4) static const u8 sText_ChooseTrainerToShareWonderNews[] = _("Please choose the TRAINER who is\nsharing WONDER NEWS."); +ALIGNED(4) static const u8 sText_ChooseLeaderPokemonJump[] = _("Jump with mini POKéMON!\nPlease choose the LEADER."); +ALIGNED(4) static const u8 sText_ChooseLeaderBerryCrush[] = _("BERRY CRUSH!\nPlease choose the LEADER."); +ALIGNED(4) static const u8 sText_ChooseLeaderBerryPicking[] = _("DODRIO BERRY-PICKING!\nPlease choose the LEADER."); +ALIGNED(4) static const u8 sText_ChooseLeaderBerryBlender[] = _("BERRY BLENDER!\nPlease choose the LEADER."); +ALIGNED(4) static const u8 sText_ChooseLeaderRecordCorner[] = _("RECORD CORNER!\nPlease choose the LEADER."); +ALIGNED(4) static const u8 sText_ChooseLeaderCoolContest[] = _("COOLNESS CONTEST!\nPlease choose the LEADER."); +ALIGNED(4) static const u8 sText_ChooseLeaderBeautyContest[] = _("BEAUTY CONTEST!\nPlease choose the LEADER."); +ALIGNED(4) static const u8 sText_ChooseLeaderCuteContest[] = _("CUTENESS CONTEST!\nPlease choose the LEADER."); +ALIGNED(4) static const u8 sText_ChooseLeaderSmartContest[] = _("SMARTNESS CONTEST!\nPlease choose the LEADER."); +ALIGNED(4) static const u8 sText_ChooseLeaderToughContest[] = _("TOUGHNESS CONTEST!\nPlease choose the LEADER."); +ALIGNED(4) static const u8 sText_ChooseLeaderBattleTowerLv50[] = _("BATTLE TOWER LEVEL 50!\nPlease choose the LEADER."); +ALIGNED(4) static const u8 sText_ChooseLeaderBattleTowerOpenLv[] = _("BATTLE TOWER OPEN LEVEL!\nPlease choose the LEADER."); static const u8 *const sChooseTrainerTexts[NUM_LINK_GROUP_TYPES] = { @@ -511,53 +521,53 @@ static const u8 *const sChooseTrainerTexts[NUM_LINK_GROUP_TYPES] = [LINK_GROUP_BATTLE_TOWER_OPEN] = sText_ChooseLeaderBattleTowerOpenLv }; -ALIGNED(4) const u8 sText_SearchingForWirelessSystemWait[] = _("Searching for a WIRELESS\nCOMMUNICATION SYSTEM. Wait..."); -ALIGNED(4) const u8 sText_MustHaveTwoMonsForDoubleBattle[] = _("For a DOUBLE BATTLE, you must have\nat least two POKéMON.\p"); // Unused -ALIGNED(4) const u8 sText_AwaitingPlayersResponse[] = _("Awaiting {STR_VAR_1}'s response…"); -ALIGNED(4) const u8 sText_PlayerHasBeenAskedToRegisterYouPleaseWait[] = _("{STR_VAR_1} has been asked to register\nyou as a member. Please wait."); -ALIGNED(4) const u8 sText_AwaitingResponseFromWirelessSystem[] = _("Awaiting a response from the\nWIRELESS COMMUNICATION SYSTEM."); -ALIGNED(4) const u8 sText_PleaseWaitForOtherTrainersToGather[] = _("Please wait for other TRAINERS to\ngather and get ready."); // Unused -ALIGNED(4) const u8 sText_NoCardsSharedRightNow[] = _("No CARDS appear to be shared \nright now."); -ALIGNED(4) const u8 sText_NoNewsSharedRightNow[] = _("No NEWS appears to be shared\nright now."); +ALIGNED(4) static const u8 sText_SearchingForWirelessSystemWait[] = _("Searching for a WIRELESS\nCOMMUNICATION SYSTEM. Wait..."); +ALIGNED(4) static const u8 sText_MustHaveTwoMonsForDoubleBattle[] = _("For a DOUBLE BATTLE, you must have\nat least two POKéMON.\p"); // Unused +ALIGNED(4) static const u8 sText_AwaitingPlayersResponse[] = _("Awaiting {STR_VAR_1}'s response…"); +ALIGNED(4) static const u8 sText_PlayerHasBeenAskedToRegisterYouPleaseWait[] = _("{STR_VAR_1} has been asked to register\nyou as a member. Please wait."); +ALIGNED(4) static const u8 sText_AwaitingResponseFromWirelessSystem[] = _("Awaiting a response from the\nWIRELESS COMMUNICATION SYSTEM."); +ALIGNED(4) static const u8 sText_PleaseWaitForOtherTrainersToGather[] = _("Please wait for other TRAINERS to\ngather and get ready."); // Unused +ALIGNED(4) static const u8 sText_NoCardsSharedRightNow[] = _("No CARDS appear to be shared \nright now."); +ALIGNED(4) static const u8 sText_NoNewsSharedRightNow[] = _("No NEWS appears to be shared\nright now."); -const u8 *const sNoWonderSharedTexts[] = { +static const u8 *const sNoWonderSharedTexts[] = { sText_NoCardsSharedRightNow, sText_NoNewsSharedRightNow }; -ALIGNED(4) const u8 sText_Battle[] = _("BATTLE"); -ALIGNED(4) const u8 sText_Chat2[] = _("CHAT"); -ALIGNED(4) const u8 sText_Greetings[] = _("GREETINGS"); -ALIGNED(4) const u8 sText_Exit[] = _("EXIT"); -ALIGNED(4) const u8 sText_Exit2[] = _("EXIT"); -ALIGNED(4) const u8 sText_Info[] = _("INFO"); -ALIGNED(4) const u8 sText_NameWantedOfferLv[] = _("NAME{CLEAR_TO 0x3C}WANTED{CLEAR_TO 0x6E}OFFER{CLEAR_TO 0xC6}LV."); -ALIGNED(4) const u8 sText_SingleBattle[] = _("SINGLE BATTLE"); -ALIGNED(4) const u8 sText_DoubleBattle[] = _("DOUBLE BATTLE"); -ALIGNED(4) const u8 sText_MultiBattle[] = _("MULTI BATTLE"); -ALIGNED(4) const u8 sText_PokemonTrades[] = _("POKéMON TRADES"); -ALIGNED(4) const u8 sText_Chat[] = _("CHAT"); -ALIGNED(4) const u8 sText_Cards[] = _("CARDS"); -ALIGNED(4) const u8 sText_WonderCards[] = _("WONDER CARDS"); -ALIGNED(4) const u8 sText_WonderNews[] = _("WONDER NEWS"); -ALIGNED(4) const u8 sText_PokemonJump[] = _("POKéMON JUMP"); -ALIGNED(4) const u8 sText_BerryCrush[] = _("BERRY CRUSH"); -ALIGNED(4) const u8 sText_BerryPicking[] = _("BERRY-PICKING"); -ALIGNED(4) const u8 sText_Search[] = _("SEARCH"); -ALIGNED(4) const u8 sText_BerryBlender[] = _("BERRY BLENDER"); -ALIGNED(4) const u8 sText_RecordCorner[] = _("RECORD CORNER"); -ALIGNED(4) const u8 sText_CoolContest[] = _("COOL CONTEST"); -ALIGNED(4) const u8 sText_BeautyContest[] = _("BEAUTY CONTEST"); -ALIGNED(4) const u8 sText_CuteContest[] = _("CUTE CONTEST"); -ALIGNED(4) const u8 sText_SmartContest[] = _("SMART CONTEST"); -ALIGNED(4) const u8 sText_ToughContest[] = _("TOUGH CONTEST"); -ALIGNED(4) const u8 sText_BattleTowerLv50[] = _("BATTLE TOWER LV. 50"); -ALIGNED(4) const u8 sText_BattleTowerOpenLv[] = _("BATTLE TOWER OPEN LEVEL"); -ALIGNED(4) const u8 sText_ItsNormalCard[] = _("It's a NORMAL CARD."); -ALIGNED(4) const u8 sText_ItsBronzeCard[] = _("It's a BRONZE CARD!"); -ALIGNED(4) const u8 sText_ItsCopperCard[] = _("It's a COPPER CARD!"); -ALIGNED(4) const u8 sText_ItsSilverCard[] = _("It's a SILVER CARD!"); -ALIGNED(4) const u8 sText_ItsGoldCard[] = _("It's a GOLD CARD!"); +ALIGNED(4) static const u8 sText_Battle[] = _("BATTLE"); +ALIGNED(4) static const u8 sText_Chat2[] = _("CHAT"); +ALIGNED(4) static const u8 sText_Greetings[] = _("GREETINGS"); +ALIGNED(4) static const u8 sText_Exit[] = _("EXIT"); +ALIGNED(4) static const u8 sText_Exit2[] = _("EXIT"); +ALIGNED(4) static const u8 sText_Info[] = _("INFO"); +ALIGNED(4) static const u8 sText_NameWantedOfferLv[] = _("NAME{CLEAR_TO 60}WANTED{CLEAR_TO 110}OFFER{CLEAR_TO 198}LV."); +ALIGNED(4) static const u8 sText_SingleBattle[] = _("SINGLE BATTLE"); +ALIGNED(4) static const u8 sText_DoubleBattle[] = _("DOUBLE BATTLE"); +ALIGNED(4) static const u8 sText_MultiBattle[] = _("MULTI BATTLE"); +ALIGNED(4) static const u8 sText_PokemonTrades[] = _("POKéMON TRADES"); +ALIGNED(4) static const u8 sText_Chat[] = _("CHAT"); +ALIGNED(4) static const u8 sText_Cards[] = _("CARDS"); +ALIGNED(4) static const u8 sText_WonderCards[] = _("WONDER CARDS"); +ALIGNED(4) static const u8 sText_WonderNews[] = _("WONDER NEWS"); +ALIGNED(4) static const u8 sText_PokemonJump[] = _("POKéMON JUMP"); +ALIGNED(4) static const u8 sText_BerryCrush[] = _("BERRY CRUSH"); +ALIGNED(4) static const u8 sText_BerryPicking[] = _("BERRY-PICKING"); +ALIGNED(4) static const u8 sText_Search[] = _("SEARCH"); +ALIGNED(4) static const u8 sText_BerryBlender[] = _("BERRY BLENDER"); +ALIGNED(4) static const u8 sText_RecordCorner[] = _("RECORD CORNER"); +ALIGNED(4) static const u8 sText_CoolContest[] = _("COOL CONTEST"); +ALIGNED(4) static const u8 sText_BeautyContest[] = _("BEAUTY CONTEST"); +ALIGNED(4) static const u8 sText_CuteContest[] = _("CUTE CONTEST"); +ALIGNED(4) static const u8 sText_SmartContest[] = _("SMART CONTEST"); +ALIGNED(4) static const u8 sText_ToughContest[] = _("TOUGH CONTEST"); +ALIGNED(4) static const u8 sText_BattleTowerLv50[] = _("BATTLE TOWER LV. 50"); +ALIGNED(4) static const u8 sText_BattleTowerOpenLv[] = _("BATTLE TOWER OPEN LEVEL"); +ALIGNED(4) static const u8 sText_ItsNormalCard[] = _("It's a NORMAL CARD."); +ALIGNED(4) static const u8 sText_ItsBronzeCard[] = _("It's a BRONZE CARD!"); +ALIGNED(4) static const u8 sText_ItsCopperCard[] = _("It's a COPPER CARD!"); +ALIGNED(4) static const u8 sText_ItsSilverCard[] = _("It's a SILVER CARD!"); +ALIGNED(4) static const u8 sText_ItsGoldCard[] = _("It's a GOLD CARD!"); static const u8 *const sCardColorTexts[] = { sText_ItsNormalCard, @@ -567,17 +577,17 @@ static const u8 *const sCardColorTexts[] = { sText_ItsGoldCard }; -ALIGNED(4) const u8 sText_TrainerCardInfoPage1[] = _("This is {DYNAMIC 0} {DYNAMIC 1}'s\nTRAINER CARD…\l{DYNAMIC 2}\pPOKéDEX: {DYNAMIC 3}\nTIME: {DYNAMIC 4}:{DYNAMIC 5}\p"); -ALIGNED(4) const u8 sText_TrainerCardInfoPage2[] = _("BATTLES: WINS: {DYNAMIC 0} LOSSES: {DYNAMIC 2}\nTRADES: {DYNAMIC 3}\p“{DYNAMIC 4} {DYNAMIC 5}\n{DYNAMIC 6} {DYNAMIC 7}”\p"); -ALIGNED(4) const u8 sText_GladToMeetYouMale[] = _("{DYNAMIC 1}: Glad to have met you!{PAUSE 60}"); -ALIGNED(4) const u8 sText_GladToMeetYouFemale[] = _("{DYNAMIC 1}: Glad to meet you!{PAUSE 60}"); +ALIGNED(4) static const u8 sText_TrainerCardInfoPage1[] = _("This is {DYNAMIC 0} {DYNAMIC 1}'s\nTRAINER CARD…\l{DYNAMIC 2}\pPOKéDEX: {DYNAMIC 3}\nTIME: {DYNAMIC 4}:{DYNAMIC 5}\p"); +ALIGNED(4) static const u8 sText_TrainerCardInfoPage2[] = _("BATTLES: WINS: {DYNAMIC 0} LOSSES: {DYNAMIC 2}\nTRADES: {DYNAMIC 3}\p“{DYNAMIC 4} {DYNAMIC 5}\n{DYNAMIC 6} {DYNAMIC 7}”\p"); +ALIGNED(4) static const u8 sText_GladToMeetYouMale[] = _("{DYNAMIC 1}: Glad to have met you!{PAUSE 60}"); +ALIGNED(4) static const u8 sText_GladToMeetYouFemale[] = _("{DYNAMIC 1}: Glad to meet you!{PAUSE 60}"); -const u8 *const sGladToMeetYouTexts[GENDER_COUNT] = { +static const u8 *const sGladToMeetYouTexts[GENDER_COUNT] = { sText_GladToMeetYouMale, sText_GladToMeetYouFemale }; -ALIGNED(4) const u8 sText_FinishedCheckingPlayersTrainerCard[] = _("Finished checking {DYNAMIC 1}'s\nTRAINER CARD.{PAUSE 60}"); +ALIGNED(4) static const u8 sText_FinishedCheckingPlayersTrainerCard[] = _("Finished checking {DYNAMIC 1}'s\nTRAINER CARD.{PAUSE 60}"); static const u8 *const sLinkGroupActivityNameTexts[] = { [ACTIVITY_NONE] = sText_EmptyString, @@ -586,8 +596,8 @@ static const u8 *const sLinkGroupActivityNameTexts[] = { [ACTIVITY_BATTLE_MULTI] = sText_MultiBattle, [ACTIVITY_TRADE] = sText_PokemonTrades, [ACTIVITY_CHAT] = sText_Chat, - [ACTIVITY_WONDER_CARD] = sText_WonderCards, - [ACTIVITY_WONDER_NEWS] = sText_WonderNews, + [ACTIVITY_WONDER_CARD_DUP] = sText_WonderCards, + [ACTIVITY_WONDER_NEWS_DUP] = sText_WonderNews, [ACTIVITY_CARD] = sText_Cards, [ACTIVITY_POKEMON_JUMP] = sText_PokemonJump, [ACTIVITY_BERRY_CRUSH] = sText_BerryCrush, @@ -601,8 +611,8 @@ static const u8 *const sLinkGroupActivityNameTexts[] = { [ACTIVITY_DECLINE] = sText_EmptyString, [ACTIVITY_NPCTALK] = sText_EmptyString, [ACTIVITY_PLYRTALK] = sText_EmptyString, - [ACTIVITY_WONDER_CARD2] = sText_WonderCards, - [ACTIVITY_WONDER_NEWS2] = sText_WonderNews, + [ACTIVITY_WONDER_CARD] = sText_WonderCards, + [ACTIVITY_WONDER_NEWS] = sText_WonderNews, [ACTIVITY_CONTEST_COOL] = sText_CoolContest, [ACTIVITY_CONTEST_BEAUTY] = sText_BeautyContest, [ACTIVITY_CONTEST_CUTE] = sText_CuteContest, @@ -612,12 +622,12 @@ static const u8 *const sLinkGroupActivityNameTexts[] = { }; static const struct WindowTemplate sWindowTemplate_BButtonCancel = { - .bg = 0x00, - .tilemapLeft = 0x00, - .tilemapTop = 0x00, - .width = 0x1E, - .height = 0x02, - .paletteNum = 0x0F, + .bg = 0, + .tilemapLeft = 0, + .tilemapTop = 0, + .width = 30, + .height = 2, + .paletteNum = 15, .baseBlock = 0x0008 }; @@ -712,27 +722,27 @@ static const struct ListMenuTemplate sListMenuTemplate_PossibleGroupMembers = { .cursorKind = 1 }; -const struct WindowTemplate gUnknown_082F0174 = { - .bg = 0x00, - .tilemapLeft = 0x01, - .tilemapTop = 0x03, - .width = 0x11, - .height = 0x0a, - .paletteNum = 0x0f, +static const struct WindowTemplate sWindowTemplate_GroupList = { + .bg = 0, + .tilemapLeft = 1, + .tilemapTop = 3, + .width = 17, + .height = 10, + .paletteNum = 15, .baseBlock = 0x0044 }; -const struct WindowTemplate gUnknown_082F017C = { - .bg = 0x00, - .tilemapLeft = 0x14, - .tilemapTop = 0x03, - .width = 0x07, - .height = 0x04, - .paletteNum = 0x0f, +static const struct WindowTemplate sWindowTemplate_PlayerNameAndId = { + .bg = 0, + .tilemapLeft = 20, + .tilemapTop = 3, + .width = 7, + .height = 4, + .paletteNum = 15, .baseBlock = 0x00ee }; -const struct ListMenuItem gUnknown_082F0184[] = { +static const struct ListMenuItem sUnionRoomGroupsMenuItems[] = { { sText_EmptyString, 0 }, { sText_EmptyString, 1 }, { sText_EmptyString, 2 }, @@ -752,10 +762,10 @@ const struct ListMenuItem gUnknown_082F0184[] = { }; static const struct ListMenuTemplate sListMenuTemplate_UnionRoomGroups = { - .items = gUnknown_082F0184, + .items = sUnionRoomGroupsMenuItems, .moveCursorFunc = ListMenuDefaultCursorMoveFunc, .itemPrintFunc = ListMenuItemPrintFunc_UnionRoomGroups, - .totalItems = ARRAY_COUNT(gUnknown_082F0184), + .totalItems = ARRAY_COUNT(sUnionRoomGroupsMenuItems), .maxShowed = 5, .windowId = 0, .header_X = 0, @@ -773,27 +783,27 @@ static const struct ListMenuTemplate sListMenuTemplate_UnionRoomGroups = { }; static const struct WindowTemplate sWindowTemplate_InviteToActivity = { - .bg = 0x00, - .tilemapLeft = 0x14, - .tilemapTop = 0x05, - .width = 0x10, - .height = 0x08, - .paletteNum = 0x0f, + .bg = 0, + .tilemapLeft = 20, + .tilemapTop = 5, + .width = 16, + .height = 8, + .paletteNum = 15, .baseBlock = 0x0001 }; -const struct ListMenuItem gUnknown_082F0224[] = { - { sText_Greetings, 0x208 }, - { sText_Battle, 0x241 }, - { sText_Chat2, 0x245 }, - { sText_Exit, 0x040 } +static const struct ListMenuItem sInviteToActivityMenuItems[] = { + { sText_Greetings, ACTIVITY_CARD | LINK_GROUP_CAPACITY(0, 2)}, + { sText_Battle, ACTIVITY_BATTLE_SINGLE | IN_UNION_ROOM | LINK_GROUP_CAPACITY(0, 2)}, + { sText_Chat2, ACTIVITY_CHAT | IN_UNION_ROOM | LINK_GROUP_CAPACITY(0, 2)}, + { sText_Exit, ACTIVITY_NONE | IN_UNION_ROOM } }; static const struct ListMenuTemplate sListMenuTemplate_InviteToActivity = { - .items = gUnknown_082F0224, + .items = sInviteToActivityMenuItems, .moveCursorFunc = ListMenuDefaultCursorMoveFunc, .itemPrintFunc = NULL, - .totalItems = ARRAY_COUNT(gUnknown_082F0224), + .totalItems = ARRAY_COUNT(sInviteToActivityMenuItems), .maxShowed = 4, .windowId = 0, .header_X = 0, @@ -811,12 +821,12 @@ static const struct ListMenuTemplate sListMenuTemplate_InviteToActivity = { }; static const struct WindowTemplate sWindowTemplate_RegisterForTrade = { - .bg = 0x00, - .tilemapLeft = 0x12, - .tilemapTop = 0x07, - .width = 0x10, - .height = 0x06, - .paletteNum = 0x0f, + .bg = 0, + .tilemapLeft = 18, + .tilemapTop = 7, + .width = 16, + .height = 6, + .paletteNum = 15, .baseBlock = 0x0001 }; @@ -847,13 +857,13 @@ static const struct ListMenuTemplate sListMenuTemplate_RegisterForTrade = { .cursorKind = 0 }; -const struct WindowTemplate gUnknown_082F0294 = { - .bg = 0x00, - .tilemapLeft = 0x14, - .tilemapTop = 0x01, - .width = 0x10, - .height = 0x0c, - .paletteNum = 0x0f, +static const struct WindowTemplate sWindowTemplate_TradingBoardRequestType = { + .bg = 0, + .tilemapLeft = 20, + .tilemapTop = 1, + .width = 16, + .height = 12, + .paletteNum = 15, .baseBlock = 0x0001 }; @@ -899,23 +909,23 @@ static const struct ListMenuTemplate sMenuTemplate_TradingBoardRequestType = { .cursorKind = 0 }; -static const struct WindowTemplate sWindowTemplate_TradingBoard = { - .bg = 0x00, - .tilemapLeft = 0x01, - .tilemapTop = 0x01, - .width = 0x1c, - .height = 0x02, - .paletteNum = 0x0d, +static const struct WindowTemplate sWindowTemplate_TradingBoardHeader = { + .bg = 0, + .tilemapLeft = 1, + .tilemapTop = 1, + .width = 28, + .height = 2, + .paletteNum = 13, .baseBlock = 0x0001 }; -const struct WindowTemplate gUnknown_082F034C = { - .bg = 0x00, - .tilemapLeft = 0x01, - .tilemapTop = 0x05, - .width = 0x1c, - .height = 0x0c, - .paletteNum = 0x0d, +static const struct WindowTemplate sWindowTemplate_TradingBoardMain = { + .bg = 0, + .tilemapLeft = 1, + .tilemapTop = 5, + .width = 28, + .height = 12, + .paletteNum = 13, .baseBlock = 0x0039 }; @@ -953,13 +963,14 @@ static const struct ListMenuTemplate sTradeBoardListMenuTemplate = { .cursorKind = 0 }; -const struct WindowTemplate UnrefWindowTemplate_082F03B4 = { - .bg = 0x00, - .tilemapLeft = 0x01, - .tilemapTop = 0x05, - .width = 0x1c, - .height = 0x0c, - .paletteNum = 0x0d, +// Unused +static const struct WindowTemplate sWindowTemplate_Unused = { + .bg = 0, + .tilemapLeft = 1, + .tilemapTop = 5, + .width = 28, + .height = 12, + .paletteNum = 13, .baseBlock = 0x0039 }; @@ -983,7 +994,7 @@ static const struct ListMenuItem sEmptyListMenuItems[] = { }; // Unused -static const struct ListMenuTemplate sUnknownListMenuTemplate = { +static const struct ListMenuTemplate sEmptyListMenuTemplate = { .items = sEmptyListMenuItems, .moveCursorFunc = ListMenuDefaultCursorMoveFunc, .itemPrintFunc = ItemPrintFunc_EmptyList, @@ -1004,18 +1015,18 @@ static const struct ListMenuTemplate sUnknownListMenuTemplate = { .cursorKind = 0 }; -const struct WirelessGnameUnamePair sWirelessGnameUnamePair_Dummy = {0}; +static const struct RfuPlayerData sUnionRoomPlayer_DummyRfu = {0}; -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[] = { +ALIGNED(4) static const u8 sAcceptedActivityIds_SingleBattle[] = {ACTIVITY_BATTLE_SINGLE, 0xff}; +ALIGNED(4) static const u8 sAcceptedActivityIds_DoubleBattle[] = {ACTIVITY_BATTLE_DOUBLE, 0xff}; +ALIGNED(4) static const u8 sAcceptedActivityIds_MultiBattle[] = {ACTIVITY_BATTLE_MULTI, 0xff}; +ALIGNED(4) static const u8 sAcceptedActivityIds_Trade[] = {ACTIVITY_TRADE, 0xff}; +ALIGNED(4) static const u8 sAcceptedActivityIds_PokemonJump[] = {ACTIVITY_POKEMON_JUMP, 0xff}; +ALIGNED(4) static const u8 sAcceptedActivityIds_BerryCrush[] = {ACTIVITY_BERRY_CRUSH, 0xff}; +ALIGNED(4) static const u8 sAcceptedActivityIds_BerryPicking[] = {ACTIVITY_BERRY_PICK, 0xff}; +ALIGNED(4) static const u8 sAcceptedActivityIds_WonderCard[] = {ACTIVITY_WONDER_CARD, 0xff}; +ALIGNED(4) static const u8 sAcceptedActivityIds_WonderNews[] = {ACTIVITY_WONDER_NEWS, 0xff}; +ALIGNED(4) static const u8 sAcceptedActivityIds_Resume[] = { IN_UNION_ROOM | ACTIVITY_NONE, IN_UNION_ROOM | ACTIVITY_BATTLE_SINGLE, IN_UNION_ROOM | ACTIVITY_TRADE, @@ -1027,8 +1038,8 @@ ALIGNED(4) const u8 sAcceptedActivityIds_Resume[] = { IN_UNION_ROOM | ACTIVITY_PLYRTALK, 0xff }; -ALIGNED(4) const u8 sAcceptedActivityIds_Init[] = {ACTIVITY_SEARCH, 0xff}; -ALIGNED(4) const u8 sAcceptedActivityIds_Unk11[] = { +ALIGNED(4) static const u8 sAcceptedActivityIds_Init[] = {ACTIVITY_SEARCH, 0xff}; +ALIGNED(4) static const u8 sAcceptedActivityIds_Unk11[] = { ACTIVITY_BATTLE_SINGLE, ACTIVITY_BATTLE_DOUBLE, ACTIVITY_BATTLE_MULTI, @@ -1036,22 +1047,22 @@ ALIGNED(4) const u8 sAcceptedActivityIds_Unk11[] = { ACTIVITY_POKEMON_JUMP, ACTIVITY_BERRY_CRUSH, ACTIVITY_BERRY_PICK, - ACTIVITY_WONDER_CARD2, - ACTIVITY_WONDER_NEWS2, + ACTIVITY_WONDER_CARD, + ACTIVITY_WONDER_NEWS, 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}; +ALIGNED(4) static const u8 sAcceptedActivityIds_RecordCorner[] = {ACTIVITY_RECORD_CORNER, 0xff}; +ALIGNED(4) static const u8 sAcceptedActivityIds_BerryBlender[] = {ACTIVITY_BERRY_BLENDER, 0xff}; +ALIGNED(4) static const u8 sAcceptedActivityIds_CoolContest[] = {ACTIVITY_CONTEST_COOL, 0xff}; +ALIGNED(4) static const u8 sAcceptedActivityIds_BeautyContest[] = {ACTIVITY_CONTEST_BEAUTY, 0xff}; +ALIGNED(4) static const u8 sAcceptedActivityIds_CuteContest[] = {ACTIVITY_CONTEST_CUTE, 0xff}; +ALIGNED(4) static const u8 sAcceptedActivityIds_SmartContest[] = {ACTIVITY_CONTEST_SMART, 0xff}; +ALIGNED(4) static const u8 sAcceptedActivityIds_ToughContest[] = {ACTIVITY_CONTEST_TOUGH, 0xff}; +ALIGNED(4) static const u8 sAcceptedActivityIds_BattleTower[] = {ACTIVITY_BATTLE_TOWER, 0xff}; +ALIGNED(4) static const u8 sAcceptedActivityIds_BattleTowerOpen[] = {ACTIVITY_BATTLE_TOWER_OPEN, 0xff}; -const u8 *const sAcceptedActivityIds[NUM_LINK_GROUP_TYPES] = { +static 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, @@ -1085,8 +1096,8 @@ static const u8 sLinkGroupToURoomActivity[NUM_LINK_GROUP_TYPES + 2] = [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_WONDER_CARD] = ACTIVITY_WONDER_CARD, + [LINK_GROUP_WONDER_NEWS] = ACTIVITY_WONDER_NEWS, [LINK_GROUP_UNION_ROOM_RESUME] = ACTIVITY_NONE, [LINK_GROUP_UNION_ROOM_INIT] = ACTIVITY_NONE, [LINK_GROUP_UNK_11] = ACTIVITY_NONE, diff --git a/src/field_player_avatar.c b/src/field_player_avatar.c index 9b1f4ceb6..970899369 100644 --- a/src/field_player_avatar.c +++ b/src/field_player_avatar.c @@ -1138,22 +1138,22 @@ u8 player_get_pos_including_state_based_drift(s16 *x, s16 *y) switch (object->movementActionId) { - case MOVEMENT_ACTION_WALK_NORMAL_DOWN: - case MOVEMENT_ACTION_PLAYER_RUN_DOWN: - (*y)++; - return TRUE; - case MOVEMENT_ACTION_WALK_NORMAL_UP: - case MOVEMENT_ACTION_PLAYER_RUN_UP: - (*y)--; - return TRUE; - case MOVEMENT_ACTION_WALK_NORMAL_LEFT: - case MOVEMENT_ACTION_PLAYER_RUN_LEFT: - (*x)--; - return TRUE; - case MOVEMENT_ACTION_WALK_NORMAL_RIGHT: - case MOVEMENT_ACTION_PLAYER_RUN_RIGHT: - (*x)++; - return TRUE; + case MOVEMENT_ACTION_WALK_NORMAL_DOWN: + case MOVEMENT_ACTION_PLAYER_RUN_DOWN: + (*y)++; + return TRUE; + case MOVEMENT_ACTION_WALK_NORMAL_UP: + case MOVEMENT_ACTION_PLAYER_RUN_UP: + (*y)--; + return TRUE; + case MOVEMENT_ACTION_WALK_NORMAL_LEFT: + case MOVEMENT_ACTION_PLAYER_RUN_LEFT: + (*x)--; + return TRUE; + case MOVEMENT_ACTION_WALK_NORMAL_RIGHT: + case MOVEMENT_ACTION_PLAYER_RUN_RIGHT: + (*x)++; + return TRUE; } } diff --git a/src/librfu_rfu.c b/src/librfu_rfu.c index 309fc4ead..55c80580e 100644 --- a/src/librfu_rfu.c +++ b/src/librfu_rfu.c @@ -1,6 +1,14 @@ #include #include "librfu.h" +// If expanding the length of the player name and wireless link functionality is +// desired, ensure that the name string is limited in size when it's copied from the +// saveblock to any Rfu-related fields (e.g. in SetHostRfuUsername). +// If wireless link functionality is not desired ignore or delete this warning. +#if RFU_USER_NAME_LENGTH < (PLAYER_NAME_LENGTH + 1) +#warning "The Wireless Adapter hardware expects a username of no more than 8 bytes." +#endif + struct LLSFStruct { u8 frameSize; diff --git a/src/link_rfu_2.c b/src/link_rfu_2.c index b1e2c698f..a080630c1 100644 --- a/src/link_rfu_2.c +++ b/src/link_rfu_2.c @@ -29,17 +29,17 @@ enum { RFUSTATE_CHILD_CONNECT_END, RFUSTATE_8, // Unused RFUSTATE_RECONNECTED, - RFUSTATE_10, + RFUSTATE_CONNECTED, RFUSTATE_CHILD_TRY_JOIN, RFUSTATE_CHILD_JOINED, - RFUSTATE_13, + RFUSTATE_UR_PLAYER_EXCHANGE, RFUSTATE_14, RFUSTATE_15, RFUSTATE_UR_FINALIZE, }; // These states are re-used for different purposes #define RFUSTATE_17 17 -#define RFUSTATE_18 18 +#define RFUSTATE_PARENT_RECONNECT 18 #define RFUSTATE_PARENT_FINALIZE_START 17 #define RFUSTATE_PARENT_FINALIZE 18 @@ -47,15 +47,24 @@ enum { #define RFUSTATE_UR_CONNECT_END 18 #define RFUSTATE_FINALIZED 20 +// States for the 'receiving' field of RfuBlockSend +enum { + RECV_STATE_READY, + RECV_STATE_RECEIVING, + RECV_STATE_FINISHED, +}; + struct SioInfo { - char magic[15]; // PokemonSioInfo + char magic[sizeof("PokemonSioInfo")]; u8 playerCount; u8 linkPlayerIdx[RFU_CHILD_MAX]; struct LinkPlayer linkPlayers[MAX_RFU_PLAYERS]; u8 filler[92]; }; +// Struct is mostly empty, presumably because usage of +// its fields was largely removed before release struct RfuDebug { u8 filler0[6]; @@ -64,31 +73,33 @@ struct RfuDebug vu8 unk_0e; u8 childJoinCount; u8 filler2[84]; - u16 unk_64; + u16 blockSendFailures; u8 filler3[29]; u8 blockSendTime; u8 filler4[88]; }; -u32 gf_rfu_REQ_api[RFU_API_BUFF_SIZE_RAM / 4]; -struct GFRfuManager Rfu; +u32 gRfuAPIBuffer[RFU_API_BUFF_SIZE_RAM / 4]; +struct RfuManager gRfu; static u8 sHeldKeyCount; -static u8 sResendBlock8[16]; -static u16 sResendBlock16[8]; +static u8 sResendBlock8[CMD_LENGTH * 2]; +static u16 sResendBlock16[CMD_LENGTH]; -EWRAM_DATA struct GFtgtGname gHostRFUtgtGnameBuffer = {}; -EWRAM_DATA u8 gHostRFUtgtUnameBuffer[PLAYER_NAME_LENGTH + 1] = {}; +EWRAM_DATA struct RfuGameData gHostRfuGameData = {}; +EWRAM_DATA u8 gHostRfuUsername[RFU_USER_NAME_LENGTH] = {}; static EWRAM_DATA INIT_PARAM sRfuReqConfig = {}; static EWRAM_DATA struct RfuDebug sRfuDebug = {}; static void ResetSendDataManager(struct RfuBlockSend *); static void InitChildRecvBuffers(void); static void sub_800EAFC(void); -static void sub_800ED34(u16); +static void LinkManagerCB_MSC(u16); static void sub_800EDBC(u16); static void UpdateBackupQueue(void); -static void Task_ExchangeLinkPlayers(u8); +static void Task_PlayerExchange(u8); +static void Task_PlayerExchangeUpdate(u8); +static void Task_PlayerExchangeChat(u8); static void RfuHandleReceiveCommand(u8); static void CallRfuFunc(void); static void RfuPrepareSendBuffer(u16); @@ -97,16 +108,14 @@ static void SendNextBlock(void); static void SendLastBlock(void); static u8 GetPartnerIndexByNameAndTrainerID(const u8 *, u16); static void UpdateChildStatuses(void); -static s32 sub_80107A0(void); -static void sub_801084C(u8); +static s32 GetJoinGroupStatus(void); static void ClearSelectedLinkPlayerIds(u16); static void ValidateAndReceivePokemonSioInfo(void *); -static void sub_8010D0C(u8); static void sub_80115EC(s32); -static void sub_8011BF8(void); +static void CB2_RfuIdle(void); static void RfuReqDisconnectSlot(u32); static void SendDisconnectCommand(u32, u32); -static void sub_801209C(u8); +static void Task_TryConnectToUnionRoomParent(u8); static void Debug_PrintEmpty(void); static void Task_Idle(u8); @@ -115,13 +124,13 @@ static const INIT_PARAM sRfuReqConfigTemplate = { .MC_TimerCount = 32, .availSlot_flag = 0, .mboot_flag = 0, - .serialNo = 2, - .gameName = (void *)&gHostRFUtgtGnameBuffer, - .userName = gHostRFUtgtUnameBuffer, + .serialNo = RFU_SERIAL_GAME, + .gameName = (void *)&gHostRfuGameData, + .userName = gHostRfuUsername, .fastSearchParent_flag = TRUE, .linkRecovery_enable = FALSE, .linkRecovery_period = 600, - .NI_failCounter_limit = 0x12c + .NI_failCounter_limit = 300 }; static const u8 sAvailSlots[] = { @@ -131,33 +140,35 @@ static const u8 sAvailSlots[] = { [4] = AVAIL_SLOT4 }; +#define BLOCK_MASK(bitNum)((1 << (bitNum)) - 1) static const u32 sAllBlocksReceived[] = { - 0x000000, - 0x000001, - 0x000003, - 0x000007, - 0x00000f, - 0x00001f, - 0x00003f, - 0x00007f, - 0x0000ff, - 0x0001ff, - 0x0003ff, - 0x0007ff, - 0x000fff, - 0x001fff, - 0x003fff, - 0x007fff, - 0x00ffff, - 0x01ffff, - 0x03ffff, - 0x07ffff, - 0x0fffff, - 0x1fffff, - 0x3fffff, - 0x7fffff, - 0xffffff + BLOCK_MASK(0), + BLOCK_MASK(1), + BLOCK_MASK(2), + BLOCK_MASK(3), + BLOCK_MASK(4), + BLOCK_MASK(5), + BLOCK_MASK(6), + BLOCK_MASK(7), + BLOCK_MASK(8), + BLOCK_MASK(9), + BLOCK_MASK(10), + BLOCK_MASK(11), + BLOCK_MASK(12), + BLOCK_MASK(13), + BLOCK_MASK(14), + BLOCK_MASK(15), + BLOCK_MASK(16), + BLOCK_MASK(17), + BLOCK_MASK(18), + BLOCK_MASK(19), + BLOCK_MASK(20), + BLOCK_MASK(21), + BLOCK_MASK(22), + BLOCK_MASK(23), + BLOCK_MASK(24), }; +#undef BLOCK_MASK static const u8 sUnknown_082ED68C[] = { 0, 0, 1, @@ -186,23 +197,25 @@ static const u8 sPlayerBitsToCount[1 << (MAX_RFU_PLAYERS - 1)] = { 4 // 1111 }; -static const u8 sUnknown_082ED6A5[1 << (MAX_RFU_PLAYERS - 1)] = { - 0, - 0, - 1, - 0, - 2, - 0, - 1, - 0, - 3, - 0, - 1, - 0, - 2, - 0, - 1, - 0 +// If the 4 bits representing child slots were an array, this table +// would return the index of the most recently set bit +static const u8 sPlayerBitsToNewChildIdx[1 << (MAX_RFU_PLAYERS - 1)] = { + 0, // 0000 + 0, // 0001 + 1, // 0010 + 0, // 0011 + 2, // 0100 + 0, // 0101 + 1, // 0110 + 0, // 0111 + 3, // 1000 + 0, // 1001 + 1, // 1010 + 0, // 1011 + 2, // 1100 + 0, // 1101 + 1, // 1110 + 0 // 1111 }; static const struct BlockRequest sBlockRequests[] = { @@ -214,9 +227,9 @@ static const struct BlockRequest sBlockRequests[] = { }; static const u16 sAcceptedSerialNos[] = { - RFU_SERIAL_A, - RFU_SERIAL_B, - RFU_SERIAL_C, + RFU_SERIAL_GAME, + RFU_SERIAL_WONDER_DISTRIBUTOR, + RFU_SERIAL_UNKNOWN, RFU_SERIAL_END }; @@ -244,9 +257,9 @@ static const char sASCII_RecoverCmds[][16] = { // List of additional tasks to destroy (if active) when the RFU shuts down static const TaskFunc sShutdownTasks[] = { - sub_801084C, - Task_ExchangeLinkPlayers, - sub_8010D0C + Task_PlayerExchange, + Task_PlayerExchangeUpdate, + Task_PlayerExchangeChat }; static const char sASCII_PokemonSioInfo[] = "PokemonSioInfo"; @@ -286,17 +299,17 @@ static void Debug_PrintNum(u16 num, u8 x, u8 y, u8 numDigits) void ResetLinkRfuGFLayer(void) { s32 i; - u8 errorState = Rfu.errorState; - CpuFill16(0, &Rfu, sizeof Rfu); - Rfu.errorState = errorState; - Rfu.parentChild = 0xFF; - if (Rfu.errorState != RFU_ERROR_STATE_IGNORE) - Rfu.errorState = RFU_ERROR_STATE_NONE; + u8 errorState = gRfu.errorState; + CpuFill16(0, &gRfu, sizeof(gRfu)); + gRfu.errorState = errorState; + gRfu.parentChild = 0xFF; + if (gRfu.errorState != RFU_ERROR_STATE_IGNORE) + gRfu.errorState = RFU_ERROR_STATE_NONE; for (i = 0; i < MAX_RFU_PLAYERS; i++) - ResetSendDataManager(&Rfu.recvBlock[i]); - ResetSendDataManager(&Rfu.sendBlock); - RfuRecvQueue_Reset(&Rfu.recvQueue); - RfuSendQueue_Reset(&Rfu.sendQueue); + ResetSendDataManager(&gRfu.recvBlock[i]); + ResetSendDataManager(&gRfu.sendBlock); + RfuRecvQueue_Reset(&gRfu.recvQueue); + RfuSendQueue_Reset(&gRfu.sendQueue); CpuFill16(0, gSendCmd, sizeof gSendCmd); CpuFill16(0, gRecvCmds, sizeof gRecvCmds); CpuFill16(0, gLinkPlayers, sizeof gLinkPlayers); @@ -317,7 +330,7 @@ void InitRFU(void) void InitRFUAPI(void) { - if (!rfu_initializeAPI((void *)gf_rfu_REQ_api, sizeof gf_rfu_REQ_api, &gIntrTable[1], TRUE)) + if (!rfu_initializeAPI((void *)gRfuAPIBuffer, sizeof(gRfuAPIBuffer), &gIntrTable[1], TRUE)) { gLinkType = 0; ClearSavedLinkPlayers(); @@ -327,47 +340,47 @@ void InitRFUAPI(void) } } -static void Task_LinkLeaderSearchForChildren(u8 taskId) +static void Task_ParentSearchForChildren(u8 taskId) { UpdateChildStatuses(); - switch (Rfu.state) + switch (gRfu.state) { case RFUSTATE_INIT: rfu_LMAN_initializeRFU(&sRfuReqConfig); - Rfu.state = RFUSTATE_INIT_END; + gRfu.state = RFUSTATE_INIT_END; gTasks[taskId].data[1] = 1; break; case RFUSTATE_INIT_END: break; case RFUSTATE_PARENT_CONNECT: - rfu_LMAN_establishConnection(Rfu.parentChild, 0, 240, (u16 *)sAcceptedSerialNos); - Rfu.state = RFUSTATE_PARENT_CONNECT_END; + rfu_LMAN_establishConnection(gRfu.parentChild, 0, 240, (u16 *)sAcceptedSerialNos); + gRfu.state = RFUSTATE_PARENT_CONNECT_END; gTasks[taskId].data[1] = 6; break; case RFUSTATE_PARENT_CONNECT_END: break; case RFUSTATE_STOP_MANAGER: rfu_LMAN_stopManager(FALSE); - Rfu.state = RFUSTATE_STOP_MANAGER_END; + gRfu.state = RFUSTATE_STOP_MANAGER_END; break; case RFUSTATE_STOP_MANAGER_END: break; case RFUSTATE_PARENT_FINALIZE: - Rfu.unk_cdb = FALSE; + gRfu.unk_cdb = FALSE; rfu_LMAN_setMSCCallback(sub_800EDBC); InitChildRecvBuffers(); sub_800EAFC(); - Rfu.state = RFUSTATE_FINALIZED; + gRfu.state = RFUSTATE_FINALIZED; gTasks[taskId].data[1] = 8; - CreateTask(sub_801084C, 5); + CreateTask(Task_PlayerExchange, 5); DestroyTask(taskId); break; } } -s32 sub_800E87C(u8 slot) +s32 Rfu_GetIndexOfNewestChild(u8 bits) { - return sUnknown_082ED6A5[slot]; + return sPlayerBitsToNewChildIdx[bits]; } void sub_800E88C(s32 r2, s32 r5) @@ -382,7 +395,7 @@ void sub_800E88C(s32 r2, s32 r5) { if (r2 & 1) { - Rfu.linkPlayerIdx[i] = r4; + gRfu.linkPlayerIdx[i] = r4; r4++; } } @@ -392,36 +405,36 @@ void sub_800E88C(s32 r2, s32 r5) for (i = 0; i < RFU_CHILD_MAX; r1 >>= 1, i++) { if (!(r1 & 1)) - Rfu.linkPlayerIdx[i] = 0; + gRfu.linkPlayerIdx[i] = 0; } for (r4 = RFU_CHILD_MAX; r4 != 0; r4--) { - for (i = 0; i < RFU_CHILD_MAX && Rfu.linkPlayerIdx[i] != r4; i++); + for (i = 0; i < RFU_CHILD_MAX && gRfu.linkPlayerIdx[i] != r4; i++); if (i == RFU_CHILD_MAX) r6 = r4; } for (r5 &= ~r2, i = 0; i < RFU_CHILD_MAX; r5 >>= 1, i++) { if (r5 & 1) - Rfu.linkPlayerIdx[i] = r6++; + gRfu.linkPlayerIdx[i] = r6++; } } } -static void Task_JoinGroupSearchForParent(u8 taskId) +static void Task_ChildSearchForParent(u8 taskId) { - switch (Rfu.state) + switch (gRfu.state) { case RFUSTATE_INIT: rfu_LMAN_initializeRFU((INIT_PARAM *)&sRfuReqConfigTemplate); - Rfu.state = RFUSTATE_INIT_END; + gRfu.state = RFUSTATE_INIT_END; gTasks[taskId].data[1] = 1; break; case RFUSTATE_INIT_END: break; case RFUSTATE_CHILD_CONNECT: - rfu_LMAN_establishConnection(Rfu.parentChild, 0, 240, (u16 *)sAcceptedSerialNos); - Rfu.state = RFUSTATE_CHILD_CONNECT_END; + rfu_LMAN_establishConnection(gRfu.parentChild, 0, 240, (u16 *)sAcceptedSerialNos); + gRfu.state = RFUSTATE_CHILD_CONNECT_END; gTasks[taskId].data[1] = 7; break; case RFUSTATE_CHILD_CONNECT_END: @@ -430,25 +443,25 @@ static void Task_JoinGroupSearchForParent(u8 taskId) gTasks[taskId].data[1] = 10; break; case RFUSTATE_CHILD_TRY_JOIN: - switch (sub_80107A0()) + switch (GetJoinGroupStatus()) { case RFU_STATUS_JOIN_GROUP_OK: - Rfu.state = RFUSTATE_CHILD_JOINED; + gRfu.state = RFUSTATE_CHILD_JOINED; break; case RFU_STATUS_JOIN_GROUP_NO: case RFU_STATUS_LEAVE_GROUP: rfu_LMAN_requestChangeAgbClockMaster(); - Rfu.disconnectMode = RFU_DISCONNECT_NORMAL; + gRfu.disconnectMode = RFU_DISCONNECT_NORMAL; DestroyTask(taskId); break; } break; case RFUSTATE_CHILD_JOINED: { - u8 bmChildSlot = 1 << Rfu.childSlot; - rfu_clearSlot(TYPE_NI_SEND | TYPE_NI_RECV, Rfu.childSlot); - rfu_setRecvBuffer(TYPE_UNI, Rfu.childSlot, Rfu.unk_c3f, sizeof(Rfu.unk_c3f)); - rfu_UNI_setSendData(bmChildSlot, Rfu.childSendBuffer, sizeof(Rfu.childSendBuffer)); + u8 bmChildSlot = 1 << gRfu.childSlot; + rfu_clearSlot(TYPE_NI_SEND | TYPE_NI_RECV, gRfu.childSlot); + rfu_setRecvBuffer(TYPE_UNI, gRfu.childSlot, gRfu.unk_c3f, sizeof(gRfu.unk_c3f)); + rfu_UNI_setSendData(bmChildSlot, gRfu.childSendBuffer, sizeof(gRfu.childSendBuffer)); gTasks[taskId].data[1] = 8; DestroyTask(taskId); if (sRfuDebug.childJoinCount == 0) @@ -456,7 +469,7 @@ static void Task_JoinGroupSearchForParent(u8 taskId) Debug_PrintEmpty(); sRfuDebug.childJoinCount++; } - CreateTask(sub_801084C, 5); + CreateTask(Task_PlayerExchange, 5); break; } } @@ -470,7 +483,7 @@ static void InitChildRecvBuffers(void) { if (acceptSlot & 1) { - rfu_setRecvBuffer(TYPE_UNI, i, Rfu.childRecvBuffer[i], sizeof(Rfu.childRecvBuffer[0])); + rfu_setRecvBuffer(TYPE_UNI, i, gRfu.childRecvBuffer[i], sizeof(gRfu.childRecvBuffer[0])); rfu_clearSlot(TYPE_UNI_SEND | TYPE_UNI_RECV, i); } acceptSlot >>= 1; @@ -480,67 +493,67 @@ static void InitChildRecvBuffers(void) static void sub_800EAFC(void) { u8 acceptSlot = lman.acceptSlot_flag; - rfu_UNI_setSendData(acceptSlot, Rfu.recvCmds, 70); - Rfu.unk_cda = sub_800E87C(acceptSlot); - Rfu.unk_ce2 = acceptSlot; + rfu_UNI_setSendData(acceptSlot, gRfu.recvCmds, 70); + gRfu.unk_cda = Rfu_GetIndexOfNewestChild(acceptSlot); + gRfu.unk_ce2 = acceptSlot; sub_800E88C(acceptSlot, -1); - Rfu.parentChild = MODE_PARENT; + gRfu.parentChild = MODE_PARENT; } -#define tData7 data[7] // sub_ +#define tConnectingForChat data[7] -static void Task_LinkRfu_UnionRoomListen(u8 taskId) +static void Task_UnionRoomListen(u8 taskId) { - if (GetHostRFUtgtGname()->activity == (ACTIVITY_PLYRTALK | IN_UNION_ROOM) && RfuGetStatus() == RFU_STATUS_NEW_CHILD_DETECTED) + if (GetHostRfuGameData()->activity == (ACTIVITY_PLYRTALK | IN_UNION_ROOM) && RfuGetStatus() == RFU_STATUS_NEW_CHILD_DETECTED) { rfu_REQ_disconnect(lman.acceptSlot_flag); rfu_waitREQComplete(); RfuSetStatus(RFU_STATUS_OK, 0); } - switch (Rfu.state) + switch (gRfu.state) { case RFUSTATE_INIT: rfu_LMAN_initializeRFU(&sRfuReqConfig); - Rfu.state = RFUSTATE_INIT_END; + gRfu.state = RFUSTATE_INIT_END; gTasks[taskId].data[1] = 1; break; case RFUSTATE_INIT_END: break; case RFUSTATE_UR_CONNECT: rfu_LMAN_establishConnection(MODE_P_C_SWITCH, 0, 240, (u16 *)sAcceptedSerialNos); - rfu_LMAN_setMSCCallback(sub_800ED34); - Rfu.state = RFUSTATE_UR_CONNECT_END; + rfu_LMAN_setMSCCallback(LinkManagerCB_MSC); + gRfu.state = RFUSTATE_UR_CONNECT_END; break; case RFUSTATE_UR_CONNECT_END: break; - case RFUSTATE_13: - if (rfu_UNI_setSendData(1 << Rfu.childSlot, Rfu.childSendBuffer, sizeof(Rfu.childSendBuffer)) == 0) + case RFUSTATE_UR_PLAYER_EXCHANGE: + if (rfu_UNI_setSendData(1 << gRfu.childSlot, gRfu.childSendBuffer, sizeof(gRfu.childSendBuffer)) == 0) { - Rfu.parentChild = MODE_CHILD; + gRfu.parentChild = MODE_CHILD; DestroyTask(taskId); - if (gTasks[taskId].tData7) - CreateTask(sub_8010D0C, 1); + if (gTasks[taskId].tConnectingForChat) + CreateTask(Task_PlayerExchangeChat, 1); else - CreateTask(sub_801084C, 5); + CreateTask(Task_PlayerExchange, 5); } break; case RFUSTATE_14: rfu_LMAN_stopManager(0); - Rfu.state = RFUSTATE_15; + gRfu.state = RFUSTATE_15; break; case RFUSTATE_15: break; case RFUSTATE_UR_FINALIZE: - Rfu.unk_cdb = FALSE; + gRfu.unk_cdb = FALSE; rfu_LMAN_setMSCCallback(sub_800EDBC); UpdateGameData_GroupLockedIn(TRUE); InitChildRecvBuffers(); sub_800EAFC(); - Rfu.state = RFUSTATE_FINALIZED; + gRfu.state = RFUSTATE_FINALIZED; gTasks[taskId].data[1] = 8; - Rfu.parentChild = MODE_PARENT; - CreateTask(sub_801084C, 5); - Rfu.unk_ce8 = TRUE; + gRfu.parentChild = MODE_PARENT; + CreateTask(Task_PlayerExchange, 5); + gRfu.unk_ce8 = TRUE; DestroyTask(taskId); break; } @@ -556,30 +569,30 @@ void LinkRfu_StopManagerBeforeEnteringChat(void) rfu_LMAN_stopManager(FALSE); } -static void sub_800ED34(u16 unused) +static void LinkManagerCB_MSC(u16 unused) { s32 i; for (i = 0; i < CHILD_DATA_LENGTH; i++) - Rfu.childSendBuffer[i] = 0; + gRfu.childSendBuffer[i] = 0; rfu_REQ_recvData(); rfu_waitREQComplete(); - if (gRfuSlotStatusUNI[Rfu.childSlot]->recv.newDataFlag) + if (gRfuSlotStatusUNI[gRfu.childSlot]->recv.newDataFlag) { - Rfu.childSendCount++; - RfuRecvQueue_Enqueue(&Rfu.recvQueue, Rfu.unk_c3f); + gRfu.childSendCount++; + RfuRecvQueue_Enqueue(&gRfu.recvQueue, gRfu.unk_c3f); sRfuDebug.unk_06++; UpdateBackupQueue(); - rfu_UNI_readySendData(Rfu.childSlot); - rfu_UNI_clearRecvNewDataFlag(Rfu.childSlot); + rfu_UNI_readySendData(gRfu.childSlot); + rfu_UNI_clearRecvNewDataFlag(gRfu.childSlot); } rfu_LMAN_REQ_sendData(TRUE); } static void sub_800EDBC(u16 unused) { - Rfu.unk_cdb = TRUE; + gRfu.unk_cdb = TRUE; } void LinkRfu_Shutdown(void) @@ -587,30 +600,30 @@ void LinkRfu_Shutdown(void) u8 i; rfu_LMAN_powerDownRFU(); - if (Rfu.parentChild == MODE_PARENT) + if (gRfu.parentChild == MODE_PARENT) { // Stop parent searching for children - if (FuncIsActiveTask(Task_LinkLeaderSearchForChildren) == TRUE) + if (FuncIsActiveTask(Task_ParentSearchForChildren) == TRUE) { - DestroyTask(Rfu.searchTaskId); + DestroyTask(gRfu.searchTaskId); ResetLinkRfuGFLayer(); } } - else if (Rfu.parentChild == MODE_CHILD) + else if (gRfu.parentChild == MODE_CHILD) { // Stop child searching for parent - if (FuncIsActiveTask(Task_JoinGroupSearchForParent) == TRUE) + if (FuncIsActiveTask(Task_ChildSearchForParent) == TRUE) { - DestroyTask(Rfu.searchTaskId); + DestroyTask(gRfu.searchTaskId); ResetLinkRfuGFLayer(); } } - else if (Rfu.parentChild == MODE_P_C_SWITCH) + else if (gRfu.parentChild == MODE_P_C_SWITCH) { // Stop parent-child switching mode (union room) - if (FuncIsActiveTask(Task_LinkRfu_UnionRoomListen) == TRUE) + if (FuncIsActiveTask(Task_UnionRoomListen) == TRUE) { - DestroyTask(Rfu.searchTaskId); + DestroyTask(gRfu.searchTaskId); ResetLinkRfuGFLayer(); } } @@ -623,32 +636,32 @@ void LinkRfu_Shutdown(void) } } -static void CreateTask_LinkLeaderSearchForChildren(void) +static void CreateTask_ParentSearchForChildren(void) { - Rfu.searchTaskId = CreateTask(Task_LinkLeaderSearchForChildren, 1); + gRfu.searchTaskId = CreateTask(Task_ParentSearchForChildren, 1); } // If no parent ID (or if child connection not ready) can't reconnect with parent yet static bool8 CanTryReconnectParent(void) { - if (Rfu.state == RFUSTATE_CHILD_CONNECT_END && Rfu.parentId) + if (gRfu.state == RFUSTATE_CHILD_CONNECT_END && gRfu.parentId) return TRUE; return FALSE; } static bool32 TryReconnectParent(void) { - if (Rfu.state == RFUSTATE_CHILD_CONNECT_END && !rfu_LMAN_CHILD_connectParent(gRfuLinkStatus->partner[Rfu.unk_c3d].id, 240)) + if (gRfu.state == RFUSTATE_CHILD_CONNECT_END && !rfu_LMAN_CHILD_connectParent(gRfuLinkStatus->partner[gRfu.unk_c3d].id, 240)) { - Rfu.state = RFUSTATE_RECONNECTED; + gRfu.state = RFUSTATE_RECONNECTED; return TRUE; } return FALSE; } -static void CreateTask_JoinGroupSearchForParent(void) +static void CreateTask_ChildSearchForParent(void) { - Rfu.searchTaskId = CreateTask(Task_JoinGroupSearchForParent, 1); + gRfu.searchTaskId = CreateTask(Task_ChildSearchForParent, 1); } bool8 LmanAcceptSlotFlagIsNotZero(void) @@ -660,15 +673,15 @@ bool8 LmanAcceptSlotFlagIsNotZero(void) void LinkRfu_StopManagerAndFinalizeSlots(void) { - Rfu.state = RFUSTATE_STOP_MANAGER; - Rfu.acceptSlot_flag = lman.acceptSlot_flag; + gRfu.state = RFUSTATE_STOP_MANAGER; + gRfu.acceptSlot_flag = lman.acceptSlot_flag; } bool32 WaitRfuState(bool32 force) { - if (Rfu.state == RFUSTATE_PARENT_FINALIZE_START || force) + if (gRfu.state == RFUSTATE_PARENT_FINALIZE_START || force) { - Rfu.state = RFUSTATE_PARENT_FINALIZE; + gRfu.state = RFUSTATE_PARENT_FINALIZE; return TRUE; } return FALSE; @@ -676,7 +689,7 @@ bool32 WaitRfuState(bool32 force) void sub_800EF7C(void) { - Rfu.state = RFUSTATE_14; + gRfu.state = RFUSTATE_14; } // Unused @@ -699,13 +712,13 @@ static void sub_800EFB0(void) { s32 i, j; - for (i = 0; i < 5; i++) + for (i = 0; i < MAX_RFU_PLAYERS; i++) { - struct GFRfuManager *ptr = &Rfu; - for (j = 0; j < 7; j++) + struct RfuManager *rfu = &gRfu; + for (j = 0; j < CMD_LENGTH - 1; j++) { - ptr->recvCmds[i][j][1] = gRecvCmds[i][j] >> 8; - ptr->recvCmds[i][j][0] = gRecvCmds[i][j]; + rfu->recvCmds[i][j][1] = gRecvCmds[i][j] >> 8; + rfu->recvCmds[i][j][0] = gRecvCmds[i][j]; } } CpuFill16(0, gRecvCmds, sizeof gRecvCmds); @@ -723,20 +736,20 @@ static void MoveSendCmdToRecv(void) static void UpdateBackupQueue(void) { - if (Rfu.linkRecovered) + if (gRfu.linkRecovered) { - bool8 backupEmpty = RfuBackupQueue_Dequeue(&Rfu.backupQueue, Rfu.childSendBuffer); + bool8 backupEmpty = RfuBackupQueue_Dequeue(&gRfu.backupQueue, gRfu.childSendBuffer); - if (Rfu.backupQueue.count == 0) - Rfu.linkRecovered = FALSE; + if (gRfu.backupQueue.count == 0) + gRfu.linkRecovered = FALSE; if (backupEmpty) return; } - if (!Rfu.linkRecovered) + if (!gRfu.linkRecovered) { - RfuSendQueue_Dequeue(&Rfu.sendQueue, Rfu.childSendBuffer); - RfuBackupQueue_Enqueue(&Rfu.backupQueue, Rfu.childSendBuffer); + RfuSendQueue_Dequeue(&gRfu.sendQueue, gRfu.childSendBuffer); + RfuBackupQueue_Enqueue(&gRfu.backupQueue, gRfu.childSendBuffer); } } @@ -745,26 +758,20 @@ bool32 IsRfuRecvQueueEmpty(void) s32 i; s32 j; - if (gRfuLinkStatus->sendSlotUNIFlag == 0) - { + if (!gRfuLinkStatus->sendSlotUNIFlag) return FALSE; - } + for (i = 0; i < MAX_RFU_PLAYERS; i++) - { for (j = 0; j < CMD_LENGTH - 1; j++) - { if (gRecvCmds[i][j] != 0) - { return FALSE; - } - } - } + return TRUE; } static bool32 RfuMain1_Parent(void) { - if (Rfu.state < RFUSTATE_FINALIZED) + if (gRfu.state < RFUSTATE_FINALIZED) { rfu_REQ_recvData(); rfu_waitREQComplete(); @@ -772,16 +779,16 @@ static bool32 RfuMain1_Parent(void) } else { - Rfu.unk_cdb = FALSE; - if ((Rfu.unk_ce2 & gRfuLinkStatus->connSlotFlag) == Rfu.unk_ce2 && (Rfu.unk_ce2 & gRfuLinkStatus->connSlotFlag)) + gRfu.unk_cdb = FALSE; + if ((gRfu.unk_ce2 & gRfuLinkStatus->connSlotFlag) == gRfu.unk_ce2 && (gRfu.unk_ce2 & gRfuLinkStatus->connSlotFlag)) { - if (!Rfu.unk_cdc) + if (!gRfu.unk_cdc) { - if (Rfu.disconnectSlots) + if (gRfu.disconnectSlots) { - RfuReqDisconnectSlot(Rfu.disconnectSlots); - Rfu.disconnectSlots = 0; - if (Rfu.disconnectMode == RFU_DISCONNECT_ERROR) + RfuReqDisconnectSlot(gRfu.disconnectSlots); + gRfu.disconnectSlots = 0; + if (gRfu.disconnectMode == RFU_DISCONNECT_ERROR) { RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, 0x8000); GetLinkmanErrorParams(0x8000); @@ -795,14 +802,14 @@ static bool32 RfuMain1_Parent(void) } } sub_800EFB0(); - rfu_UNI_readySendData(Rfu.unk_cda); + rfu_UNI_readySendData(gRfu.unk_cda); rfu_LMAN_REQ_sendData(TRUE); } else { rfu_REQ_PARENT_resumeRetransmitAndChange(); } - Rfu.unk_0e = TRUE; + gRfu.unk_0e = TRUE; } } return FALSE; @@ -816,43 +823,43 @@ static bool32 RfuMain2_Parent(void) u16 j; u8 retval; - if (Rfu.state >= RFUSTATE_FINALIZED && Rfu.unk_0e == TRUE) + if (gRfu.state >= RFUSTATE_FINALIZED && gRfu.unk_0e == TRUE) { rfu_waitREQComplete(); - while (Rfu.unk_cdb == FALSE) + while (gRfu.unk_cdb == FALSE) { - if (Rfu.errorState != RFU_ERROR_STATE_NONE) + if (gRfu.errorState != RFU_ERROR_STATE_NONE) return FALSE; } rfu_REQ_recvData(); rfu_waitREQComplete(); - if ((lman.parentAck_flag & Rfu.unk_ce2) == Rfu.unk_ce2) + if ((lman.parentAck_flag & gRfu.unk_ce2) == gRfu.unk_ce2) { - Rfu.unk_cdc = FALSE; + gRfu.unk_cdc = FALSE; sRfuDebug.unk_06++; flags = lman.acceptSlot_flag; for (i = 0; i < RFU_CHILD_MAX; i++) { if (flags & 1) { - if (Rfu.childRecvBuffer[i][1]) + if (gRfu.childRecvBuffer[i][1]) { - if (Rfu.unk_cee[i] != 0xFF && (Rfu.childRecvBuffer[i][0] >> 5) != ((Rfu.unk_cee[i] + 1) & 7)) + if (gRfu.unk_cee[i] != 0xFF && (gRfu.childRecvBuffer[i][0] >> 5) != ((gRfu.unk_cee[i] + 1) & 7)) { - if (++Rfu.unk_cea[i] > 4) + if (++gRfu.unk_cea[i] > 4) GetLinkmanErrorParams(0x8000 | 0x100); } else { - Rfu.unk_cee[i] = Rfu.childRecvBuffer[i][0] / 32; - Rfu.unk_cea[i] = 0; - Rfu.childRecvBuffer[i][0] &= 0x1f; - r0 = Rfu.linkPlayerIdx[i]; - for (j = 0; j < 7; j++) + gRfu.unk_cee[i] = gRfu.childRecvBuffer[i][0] / 32; + gRfu.unk_cea[i] = 0; + gRfu.childRecvBuffer[i][0] &= 0x1f; + r0 = gRfu.linkPlayerIdx[i]; + for (j = 0; j < CMD_LENGTH - 1; j++) { - gRecvCmds[r0][j] = (Rfu.childRecvBuffer[i][(j << 1) + 1] << 8) | Rfu.childRecvBuffer[i][(j << 1) + 0]; - Rfu.childRecvBuffer[i][(j << 1) + 1] = 0; - Rfu.childRecvBuffer[i][(j << 1) + 0] = 0; + gRecvCmds[r0][j] = (gRfu.childRecvBuffer[i][(j << 1) + 1] << 8) | gRfu.childRecvBuffer[i][(j << 1) + 0]; + gRfu.childRecvBuffer[i][(j << 1) + 1] = 0; + gRfu.childRecvBuffer[i][(j << 1) + 0] = 0; } } } @@ -863,53 +870,53 @@ static bool32 RfuMain2_Parent(void) MoveSendCmdToRecv(); RfuHandleReceiveCommand(0); CallRfuFunc(); - if (Rfu.unk_ce5 && !Rfu.stopNewConnections) + if (gRfu.nextChildBits && !gRfu.stopNewConnections) { sRfuDebug.unk_0e = FALSE; - rfu_clearSlot(TYPE_UNI_SEND | TYPE_UNI_RECV, Rfu.unk_cda); + rfu_clearSlot(TYPE_UNI_SEND | TYPE_UNI_RECV, gRfu.unk_cda); for (i = 0; i < RFU_CHILD_MAX; i++) { - if ((Rfu.unk_ce5 >> i) & 1) - rfu_setRecvBuffer(TYPE_UNI, i, Rfu.childRecvBuffer[i], sizeof(Rfu.childRecvBuffer[0])); + if ((gRfu.nextChildBits >> i) & 1) + rfu_setRecvBuffer(TYPE_UNI, i, gRfu.childRecvBuffer[i], sizeof(gRfu.childRecvBuffer[0])); } - sub_800E88C(Rfu.unk_ce2, Rfu.unk_ce2 | Rfu.unk_ce5); - Rfu.unk_ce9 = Rfu.unk_ce5; - Rfu.unk_ce2 |= Rfu.unk_ce5; - Rfu.unk_ce5 = 0; - rfu_UNI_setSendData(Rfu.unk_ce2, Rfu.recvCmds, 70); - Rfu.unk_cda = sub_800E87C(Rfu.unk_ce2); - CreateTask(Task_ExchangeLinkPlayers, 0); + sub_800E88C(gRfu.unk_ce2, gRfu.unk_ce2 | gRfu.nextChildBits); + gRfu.incomingChild = gRfu.nextChildBits; + gRfu.unk_ce2 |= gRfu.nextChildBits; + gRfu.nextChildBits = 0; + rfu_UNI_setSendData(gRfu.unk_ce2, gRfu.recvCmds, 70); + gRfu.unk_cda = Rfu_GetIndexOfNewestChild(gRfu.unk_ce2); + CreateTask(Task_PlayerExchangeUpdate, 0); } } else { - Rfu.unk_cdc = TRUE; - Rfu.unk_0e = FALSE; + gRfu.unk_cdc = TRUE; + gRfu.unk_0e = FALSE; } - Rfu.unk_0e = FALSE; + gRfu.unk_0e = FALSE; } - retval = Rfu.unk_cdc; + retval = gRfu.unk_cdc; return gRfuLinkStatus->sendSlotUNIFlag ? retval & 1 : FALSE; } -static void sub_800F498(u16 *a0, u8 *a1) +static void sub_800F498(u16 *sendCmd, u8 *buffer) { s32 i; - if (a0[0]) + if (sendCmd[0]) { - a0[0] |= (Rfu.unk_102 << 5); - Rfu.unk_102 = (Rfu.unk_102 + 1) & 7; - for (i = 0; i < 7; i++) + sendCmd[0] |= (gRfu.unk_102 << 5); + gRfu.unk_102 = (gRfu.unk_102 + 1) & 7; + for (i = 0; i < CMD_LENGTH - 1; i++) { - a1[2 * i + 1] = a0[i] >> 8; - a1[2 * i + 0] = a0[i]; + buffer[2 * i + 1] = sendCmd[i] >> 8; + buffer[2 * i + 0] = sendCmd[i]; } } else { - for (i = 0; i < 14; i++) - a1[i] = 0; + for (i = 0; i < SEND_QUEUE_SLOT_LENGTH; i++) + buffer[i] = 0; } } @@ -921,14 +928,15 @@ static bool32 RfuMain1_Child(void) u8 send[2 * (CMD_LENGTH - 1)]; u8 status; - RfuRecvQueue_Dequeue(&Rfu.recvQueue, recv); + RfuRecvQueue_Dequeue(&gRfu.recvQueue, recv); for (i = 0; i < MAX_RFU_PLAYERS; i++) { for (j = 0; j < CMD_LENGTH - 1; j++) - gRecvCmds[i][j] = (recv[i * 14 + (j << 1) + 1] << 8) | recv[i * 14 + (j << 1) + 0]; + gRecvCmds[i][j] = (recv[i * SEND_QUEUE_SLOT_LENGTH + (j * 2) + 1] << 8) + | recv[i * SEND_QUEUE_SLOT_LENGTH + (j * 2) + 0]; } RfuHandleReceiveCommand(0); - if (lman.childClockSlave_flag == 0 && Rfu.disconnectMode != RFU_DISCONNECT_NONE) + if (lman.childClockSlave_flag == 0 && gRfu.disconnectMode != RFU_DISCONNECT_NONE) { rfu_REQ_disconnect(gRfuLinkStatus->connSlotFlag | gRfuLinkStatus->linkLossSlotFlag); rfu_waitREQComplete(); @@ -937,21 +945,21 @@ static bool32 RfuMain1_Child(void) RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, 0x9000); rfu_clearAllSlot(); gReceivedRemoteLinkPlayers = FALSE; - Rfu.callback = NULL; - if (Rfu.disconnectMode == RFU_DISCONNECT_ERROR) + gRfu.callback = NULL; + if (gRfu.disconnectMode == RFU_DISCONNECT_ERROR) { RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, 0x9000); GetLinkmanErrorParams(0x9000); } lman.state = lman.next_state = 0; - Rfu.disconnectMode = RFU_DISCONNECT_NONE; + gRfu.disconnectMode = RFU_DISCONNECT_NONE; } - if (Rfu.childSendCount) + if (gRfu.childSendCount) { - Rfu.childSendCount--; + gRfu.childSendCount--; CallRfuFunc(); sub_800F498(gSendCmd, send); - RfuSendQueue_Enqueue(&Rfu.sendQueue, send); + RfuSendQueue_Enqueue(&gRfu.sendQueue, send); for (i = 0; i < CMD_LENGTH - 1; i++) gSendCmd[i] = 0; } @@ -962,25 +970,26 @@ static void HandleSendFailure(u8 unused, u32 flags) { s32 i, j, temp; - const u8 *r10 = Rfu.sendBlock.payload; - for (i = 0; i < Rfu.sendBlock.count; i++) + const u8 *payload = gRfu.sendBlock.payload; + for (i = 0; i < gRfu.sendBlock.count; i++) { if (!(flags & 1)) { sResendBlock16[0] = RFUCMD_SEND_BLOCK | i; - for (j = 0; j < 7; j++) + for (j = 0; j < CMD_LENGTH - 1; j++) { - temp = j << 1; - sResendBlock16[j + 1] = (r10[12 * i + temp + 1] << 8) | r10[12 * i + temp + 0]; + temp = j * 2; + sResendBlock16[j + 1] = (payload[(SEND_QUEUE_SLOT_LENGTH - 2) * i + temp + 1] << 8) + | payload[(SEND_QUEUE_SLOT_LENGTH - 2) * i + temp + 0]; } - for (j = 0; j < 7; j++) + for (j = 0; j < CMD_LENGTH - 1; j++) { - temp = j << 1; + temp = j * 2; sResendBlock8[temp + 1] = sResendBlock16[j] >> 8; sResendBlock8[temp + 0] = sResendBlock16[j]; } - RfuSendQueue_Enqueue(&Rfu.sendQueue, sResendBlock8); - Rfu.sendBlock.failedFlags |= (1 << i); + RfuSendQueue_Enqueue(&gRfu.sendQueue, sResendBlock8); + gRfu.sendBlock.failedFlags |= (1 << i); } flags >>= 1; } @@ -988,30 +997,30 @@ static void HandleSendFailure(u8 unused, u32 flags) void Rfu_SetBlockReceivedFlag(u8 linkPlayerId) { - if (Rfu.parentChild == MODE_PARENT && linkPlayerId) - Rfu.numBlocksReceived[linkPlayerId] = 1; + if (gRfu.parentChild == MODE_PARENT && linkPlayerId) + gRfu.numBlocksReceived[linkPlayerId] = 1; else - Rfu.blockReceived[linkPlayerId] = TRUE; + gRfu.blockReceived[linkPlayerId] = TRUE; } void Rfu_ResetBlockReceivedFlag(u8 linkPlayerId) { - Rfu.blockReceived[linkPlayerId] = FALSE; - Rfu.recvBlock[linkPlayerId].receiving = 0; + gRfu.blockReceived[linkPlayerId] = FALSE; + gRfu.recvBlock[linkPlayerId].receiving = RECV_STATE_READY; } static u8 LoadLinkPlayerIds(const u8 *ids) { u8 i; - if (Rfu.parentChild == MODE_PARENT) + if (gRfu.parentChild == MODE_PARENT) return FALSE; for (i = 0; i < RFU_CHILD_MAX; i++) - Rfu.linkPlayerIdx[i] = ids[i]; + gRfu.linkPlayerIdx[i] = ids[i]; - return ids[Rfu.childSlot]; + return ids[gRfu.childSlot]; } -static void RfuFunc_SendKeysToRfu(void) +static void SendKeysToRfu(void) { if (gReceivedRemoteLinkPlayers && gHeldKeyCodeToSend != LINK_KEY_CODE_NULL @@ -1023,24 +1032,24 @@ static void RfuFunc_SendKeysToRfu(void) } } -struct GFtgtGname *GetHostRFUtgtGname(void) +struct RfuGameData *GetHostRfuGameData(void) { - return &gHostRFUtgtGnameBuffer; + return &gHostRfuGameData; } bool32 IsSendingKeysToRfu(void) { - return Rfu.callback == RfuFunc_SendKeysToRfu; + return gRfu.callback == SendKeysToRfu; } void StartSendingKeysToRfu(void) { - Rfu.callback = RfuFunc_SendKeysToRfu; + gRfu.callback = SendKeysToRfu; } void ClearLinkRfuCallback(void) { - Rfu.callback = NULL; + gRfu.callback = NULL; } static void Rfu_BerryBlenderSendHeldKeys(void) @@ -1053,8 +1062,8 @@ static void Rfu_BerryBlenderSendHeldKeys(void) void Rfu_SetBerryBlenderLinkCallback(void) { - if (Rfu.callback == NULL) - Rfu.callback = Rfu_BerryBlenderSendHeldKeys; + if (gRfu.callback == NULL) + gRfu.callback = Rfu_BerryBlenderSendHeldKeys; } static void RfuHandleReceiveCommand(u8 unused) @@ -1067,39 +1076,39 @@ static void RfuHandleReceiveCommand(u8 unused) switch (gRecvCmds[i][0] & RFUCMD_MASK) { case RFUCMD_SEND_PLAYER_IDS_NEW: - if (Rfu.parentChild == MODE_CHILD && gReceivedRemoteLinkPlayers) + if (gRfu.parentChild == MODE_CHILD && gReceivedRemoteLinkPlayers) return; // fallthrough case RFUCMD_SEND_PLAYER_IDS: if (gRfuLinkStatus->parentChild == MODE_CHILD) { - Rfu.playerCount = gRecvCmds[i][1]; - Rfu.multiplayerId = LoadLinkPlayerIds((u8 *)(gRecvCmds[i] + 2)); + gRfu.playerCount = gRecvCmds[i][1]; + gRfu.multiplayerId = LoadLinkPlayerIds((u8 *)(gRecvCmds[i] + 2)); } break; case RFUCMD_SEND_BLOCK_INIT: - if (Rfu.recvBlock[i].receiving == 0) + if (gRfu.recvBlock[i].receiving == RECV_STATE_READY) { - Rfu.recvBlock[i].next = 0; - Rfu.recvBlock[i].count = gRecvCmds[i][1]; - Rfu.recvBlock[i].owner = gRecvCmds[i][2]; - Rfu.recvBlock[i].receivedFlags = 0; - Rfu.recvBlock[i].receiving = 1; - Rfu.blockReceived[i] = FALSE; + gRfu.recvBlock[i].next = 0; + gRfu.recvBlock[i].count = gRecvCmds[i][1]; + gRfu.recvBlock[i].owner = gRecvCmds[i][2]; + gRfu.recvBlock[i].receivedFlags = 0; + gRfu.recvBlock[i].receiving = RECV_STATE_RECEIVING; + gRfu.blockReceived[i] = FALSE; } break; case RFUCMD_SEND_BLOCK: - if (Rfu.recvBlock[i].receiving == 1) + if (gRfu.recvBlock[i].receiving == RECV_STATE_RECEIVING) { - Rfu.recvBlock[i].next = gRecvCmds[i][0] & 0xff; - Rfu.recvBlock[i].receivedFlags |= (1 << Rfu.recvBlock[i].next); + gRfu.recvBlock[i].next = gRecvCmds[i][0] & 0xff; + gRfu.recvBlock[i].receivedFlags |= (1 << gRfu.recvBlock[i].next); for (j = 0; j < 6; j++) - gBlockRecvBuffer[i][Rfu.recvBlock[i].next * 6 + j] = gRecvCmds[i][j + 1]; - if (Rfu.recvBlock[i].receivedFlags == sAllBlocksReceived[Rfu.recvBlock[i].count]) + gBlockRecvBuffer[i][gRfu.recvBlock[i].next * 6 + j] = gRecvCmds[i][j + 1]; + if (gRfu.recvBlock[i].receivedFlags == sAllBlocksReceived[gRfu.recvBlock[i].count]) { - Rfu.recvBlock[i].receiving = 2; + gRfu.recvBlock[i].receiving = RECV_STATE_FINISHED; Rfu_SetBlockReceivedFlag(i); - if (GetHostRFUtgtGname()->activity == (ACTIVITY_CHAT | IN_UNION_ROOM) && gReceivedRemoteLinkPlayers != 0 && Rfu.parentChild == MODE_CHILD) + if (GetHostRfuGameData()->activity == (ACTIVITY_CHAT | IN_UNION_ROOM) && gReceivedRemoteLinkPlayers != 0 && gRfu.parentChild == MODE_CHILD) ValidateAndReceivePokemonSioInfo(gBlockRecvBuffer); } } @@ -1108,14 +1117,14 @@ static void RfuHandleReceiveCommand(u8 unused) Rfu_InitBlockSend(sBlockRequests[gRecvCmds[i][1]].address, (u16)sBlockRequests[gRecvCmds[i][1]].size); break; case RFUCMD_READY_CLOSE_LINK: - Rfu.readyCloseLink[i] = TRUE; + gRfu.readyCloseLink[i] = TRUE; break; case RFUCMD_READY_EXIT_STANDBY: - if (Rfu.allReadyNum == gRecvCmds[i][1]) - Rfu.readyExitStandby[i] = TRUE; + if (gRfu.allReadyNum == gRecvCmds[i][1]) + gRfu.readyExitStandby[i] = TRUE; break; case RFUCMD_DISCONNECT: - if (Rfu.parentChild == MODE_CHILD) + if (gRfu.parentChild == MODE_CHILD) { // Disconnect child if (gReceivedRemoteLinkPlayers) @@ -1124,9 +1133,9 @@ static void RfuHandleReceiveCommand(u8 unused) { gReceivedRemoteLinkPlayers = 0; rfu_LMAN_requestChangeAgbClockMaster(); - Rfu.disconnectMode = gRecvCmds[i][2]; + gRfu.disconnectMode = gRecvCmds[i][2]; } - Rfu.playerCount = gRecvCmds[i][3]; + gRfu.playerCount = gRecvCmds[i][3]; ClearSelectedLinkPlayerIds(gRecvCmds[i][1]); } } @@ -1140,10 +1149,10 @@ static void RfuHandleReceiveCommand(u8 unused) } break; case RFUCMD_DISCONNECT_PARENT: - if (Rfu.parentChild == MODE_PARENT) + if (gRfu.parentChild == MODE_PARENT) { - Rfu.disconnectSlots |= gRecvCmds[i][1]; - Rfu.disconnectMode = gRecvCmds[i][2]; + gRfu.disconnectSlots |= gRecvCmds[i][1]; + gRfu.disconnectMode = gRecvCmds[i][2]; ClearSelectedLinkPlayerIds(gRecvCmds[i][1]); } break; @@ -1152,38 +1161,38 @@ static void RfuHandleReceiveCommand(u8 unused) gLinkPartnersHeldKeys[i] = gRecvCmds[i][1]; break; } - if (Rfu.parentChild == MODE_PARENT && Rfu.numBlocksReceived[i]) + if (gRfu.parentChild == MODE_PARENT && gRfu.numBlocksReceived[i]) { - if (Rfu.numBlocksReceived[i] == 4) + if (gRfu.numBlocksReceived[i] == 4) { - Rfu.blockReceived[i] = TRUE; - Rfu.numBlocksReceived[i] = 0; + gRfu.blockReceived[i] = TRUE; + gRfu.numBlocksReceived[i] = 0; } else - Rfu.numBlocksReceived[i]++; + gRfu.numBlocksReceived[i]++; } } } -static bool8 AreNoPlayersReceiving(void) +static bool8 AreAllPlayersReadyToReceive(void) { s32 i; for (i = 0; i < MAX_RFU_PLAYERS; i++) { - if (Rfu.recvBlock[i].receiving) + if (gRfu.recvBlock[i].receiving != RECV_STATE_READY) return FALSE; } return TRUE; } -static bool8 sub_800FC88(void) +static bool8 AreAllPlayersFinishedReceiving(void) { s32 i; - for (i = 0; i < Rfu.playerCount; i++) + for (i = 0; i < gRfu.playerCount; i++) { - if (Rfu.recvBlock[i].receiving != 2 || Rfu.blockReceived[i] != TRUE) + if (gRfu.recvBlock[i].receiving != RECV_STATE_FINISHED || gRfu.blockReceived[i] != TRUE) return FALSE; } return TRUE; @@ -1197,7 +1206,7 @@ static void ResetSendDataManager(struct RfuBlockSend *data) data->receivedFlags = 0; data->sending = FALSE; data->owner = 0; - data->receiving = 0; + data->receiving = RECV_STATE_READY; } u8 Rfu_GetBlockReceivedStatus(void) @@ -1207,7 +1216,7 @@ u8 Rfu_GetBlockReceivedStatus(void) for (i = 0; i < MAX_RFU_PLAYERS; i++) { - if (Rfu.recvBlock[i].receiving == 2 && Rfu.blockReceived[i] == TRUE) + if (gRfu.recvBlock[i].receiving == RECV_STATE_FINISHED && gRfu.blockReceived[i] == TRUE) flags |= (1 << i); } return flags; @@ -1223,25 +1232,25 @@ static void RfuPrepareSendBuffer(u16 command) switch (command) { case RFUCMD_SEND_BLOCK_INIT: - gSendCmd[1] = Rfu.sendBlock.count; - gSendCmd[2] = Rfu.sendBlock.owner + 0x80; + gSendCmd[1] = gRfu.sendBlock.count; + gSendCmd[2] = gRfu.sendBlock.owner + 0x80; break; case RFUCMD_SEND_BLOCK_REQ: - if (AreNoPlayersReceiving()) - gSendCmd[1] = Rfu.blockRequestType; + if (AreAllPlayersReadyToReceive()) + gSendCmd[1] = gRfu.blockRequestType; break; case RFUCMD_SEND_PLAYER_IDS: case RFUCMD_SEND_PLAYER_IDS_NEW: - tmp = Rfu.unk_ce2 ^ Rfu.disconnectSlots; - Rfu.playerCount = sPlayerBitsToCount[tmp] + 1; - gSendCmd[1] = Rfu.playerCount; + tmp = gRfu.unk_ce2 ^ gRfu.disconnectSlots; + gRfu.playerCount = sPlayerBitsToCount[tmp] + 1; + gSendCmd[1] = gRfu.playerCount; buff = (u8 *)&gSendCmd[2]; for (i = 0; i < RFU_CHILD_MAX; i++) - buff[i] = Rfu.linkPlayerIdx[i]; + buff[i] = gRfu.linkPlayerIdx[i]; break; case RFUCMD_READY_EXIT_STANDBY: case RFUCMD_READY_CLOSE_LINK: - gSendCmd[1] = Rfu.allReadyNum; + gSendCmd[1] = gRfu.allReadyNum; break; case RFUCMD_BLENDER_SEND_KEYS: gSendCmd[0] = command; @@ -1249,7 +1258,7 @@ static void RfuPrepareSendBuffer(u16 command) break; case RFUCMD_SEND_PACKET: for (i = 0; i < RFU_PACKET_SIZE; i++) - gSendCmd[1 + i] = Rfu.packet[i]; + gSendCmd[1 + i] = gRfu.packet[i]; break; case RFUCMD_SEND_HELD_KEYS: gSendCmd[1] = gHeldKeyCodeToSend; @@ -1264,7 +1273,7 @@ void Rfu_SendPacket(void *data) { if (gSendCmd[0] == 0 && !RfuHasErrored()) { - memcpy(Rfu.packet, data, sizeof(Rfu.packet)); + memcpy(gRfu.packet, data, sizeof(gRfu.packet)); RfuPrepareSendBuffer(RFUCMD_SEND_PACKET); } } @@ -1272,31 +1281,31 @@ void Rfu_SendPacket(void *data) bool32 Rfu_InitBlockSend(const u8 *src, size_t size) { bool8 r4; - if (Rfu.callback != NULL) + if (gRfu.callback != NULL) return FALSE; if (gSendCmd[0] != 0) return FALSE; - if (Rfu.sendBlock.sending) + if (gRfu.sendBlock.sending) { sRfuDebug.blockSendTime++; return FALSE; } r4 = (size % 12) != 0; - Rfu.sendBlock.owner = GetMultiplayerId(); - Rfu.sendBlock.sending = TRUE; - Rfu.sendBlock.count = (size / 12) + r4; - Rfu.sendBlock.next = 0; + gRfu.sendBlock.owner = GetMultiplayerId(); + gRfu.sendBlock.sending = TRUE; + gRfu.sendBlock.count = (size / 12) + r4; + gRfu.sendBlock.next = 0; if (size > BLOCK_BUFFER_SIZE) - Rfu.sendBlock.payload = src; + gRfu.sendBlock.payload = src; else { if (src != gBlockSendBuffer) memcpy(gBlockSendBuffer, src, size); - Rfu.sendBlock.payload = gBlockSendBuffer; + gRfu.sendBlock.payload = gBlockSendBuffer; } RfuPrepareSendBuffer(RFUCMD_SEND_BLOCK_INIT); - Rfu.callback = HandleBlockSend; - Rfu.unk_5b = 0; + gRfu.callback = HandleBlockSend; + gRfu.blockSendAttempts = 0; return TRUE; } @@ -1305,15 +1314,15 @@ static void HandleBlockSend(void) if (gSendCmd[0] == 0) { RfuPrepareSendBuffer(RFUCMD_SEND_BLOCK_INIT); - if (Rfu.parentChild == MODE_PARENT) + if (gRfu.parentChild == MODE_PARENT) { - if (++Rfu.unk_5b > 2) - Rfu.callback = SendNextBlock; + if (++gRfu.blockSendAttempts > 2) + gRfu.callback = SendNextBlock; } else { if ((gRecvCmds[GetMultiplayerId()][0] & RFUCMD_MASK) == RFUCMD_SEND_BLOCK_INIT) - Rfu.callback = SendNextBlock; + gRfu.callback = SendNextBlock; } } } @@ -1321,50 +1330,50 @@ static void HandleBlockSend(void) static void SendNextBlock(void) { s32 i; - const u8 *src = Rfu.sendBlock.payload; - gSendCmd[0] = RFUCMD_SEND_BLOCK | Rfu.sendBlock.next; + const u8 *src = gRfu.sendBlock.payload; + gSendCmd[0] = RFUCMD_SEND_BLOCK | gRfu.sendBlock.next; for (i = 0; i < CMD_LENGTH - 1; i++) - gSendCmd[i + 1] = (src[(i << 1) + Rfu.sendBlock.next * 12 + 1] << 8) | src[(i << 1) + Rfu.sendBlock.next * 12 + 0]; - Rfu.sendBlock.next++; - if (Rfu.sendBlock.count <= Rfu.sendBlock.next) + gSendCmd[i + 1] = (src[(i << 1) + gRfu.sendBlock.next * 12 + 1] << 8) | src[(i << 1) + gRfu.sendBlock.next * 12 + 0]; + gRfu.sendBlock.next++; + if (gRfu.sendBlock.count <= gRfu.sendBlock.next) { - Rfu.sendBlock.sending = FALSE; - Rfu.callback = SendLastBlock; + gRfu.sendBlock.sending = FALSE; + gRfu.callback = SendLastBlock; } } static void SendLastBlock(void) { - const u8 *src = Rfu.sendBlock.payload; + const u8 *src = gRfu.sendBlock.payload; u8 mpId = GetMultiplayerId(); s32 i; - if (Rfu.parentChild == MODE_CHILD) + if (gRfu.parentChild == MODE_CHILD) { - gSendCmd[0] = RFUCMD_SEND_BLOCK | (Rfu.sendBlock.count - 1); + gSendCmd[0] = RFUCMD_SEND_BLOCK | (gRfu.sendBlock.count - 1); for (i = 0; i < CMD_LENGTH - 1; i++) - gSendCmd[i + 1] = (src[(i << 1) + (Rfu.sendBlock.count - 1) * 12 + 1] << 8) | src[(i << 1) + (Rfu.sendBlock.count - 1) * 12 + 0]; - if ((u8)gRecvCmds[mpId][0] == Rfu.sendBlock.count - 1) + gSendCmd[i + 1] = (src[(i << 1) + (gRfu.sendBlock.count - 1) * 12 + 1] << 8) | src[(i << 1) + (gRfu.sendBlock.count - 1) * 12 + 0]; + if ((u8)gRecvCmds[mpId][0] == gRfu.sendBlock.count - 1) { - if (Rfu.recvBlock[mpId].receivedFlags != sAllBlocksReceived[Rfu.recvBlock[mpId].count]) + if (gRfu.recvBlock[mpId].receivedFlags != sAllBlocksReceived[gRfu.recvBlock[mpId].count]) { - HandleSendFailure(mpId, Rfu.recvBlock[mpId].receivedFlags); - sRfuDebug.unk_64++; + HandleSendFailure(mpId, gRfu.recvBlock[mpId].receivedFlags); + sRfuDebug.blockSendFailures++; } else { - Rfu.callback = NULL; + gRfu.callback = NULL; } } } else { - Rfu.callback = NULL; + gRfu.callback = NULL; } } bool8 Rfu_SendBlockRequest(u8 type) { - Rfu.blockRequestType = type; + gRfu.blockRequestType = type; RfuPrepareSendBuffer(RFUCMD_SEND_BLOCK_REQ); return TRUE; } @@ -1374,8 +1383,8 @@ static void RfuShutdownAfterDisconnect(void) rfu_clearAllSlot(); rfu_LMAN_powerDownRFU(); gReceivedRemoteLinkPlayers = 0; - Rfu.isShuttingDown = TRUE; - Rfu.callback = NULL; + gRfu.isShuttingDown = TRUE; + gRfu.callback = NULL; } static void DisconnectRfu(void) @@ -1387,68 +1396,68 @@ static void DisconnectRfu(void) static void TryDisconnectRfu(void) { - if (Rfu.parentChild == MODE_CHILD) + if (gRfu.parentChild == MODE_CHILD) { rfu_LMAN_requestChangeAgbClockMaster(); - Rfu.disconnectMode = RFU_DISCONNECT_NORMAL; + gRfu.disconnectMode = RFU_DISCONNECT_NORMAL; } else { - Rfu.callback = DisconnectRfu; + gRfu.callback = DisconnectRfu; } } void LinkRfu_FatalError(void) { rfu_LMAN_requestChangeAgbClockMaster(); - Rfu.disconnectMode = RFU_DISCONNECT_ERROR; - Rfu.disconnectSlots = gRfuLinkStatus->connSlotFlag | gRfuLinkStatus->linkLossSlotFlag; + gRfu.disconnectMode = RFU_DISCONNECT_ERROR; + gRfu.disconnectSlots = gRfuLinkStatus->connSlotFlag | gRfuLinkStatus->linkLossSlotFlag; } // RFU equivalent of LinkCB_WaitCloseLink static void WaitAllReadyToCloseLink(void) { s32 i; - u8 playerCount = Rfu.playerCount; + u8 playerCount = gRfu.playerCount; s32 count = 0; // Wait for all players to be ready for (i = 0; i < MAX_RFU_PLAYERS; i++) { - if (Rfu.readyCloseLink[i]) + if (gRfu.readyCloseLink[i]) count++; } if (count == playerCount) { // All ready, close link gBattleTypeFlags &= ~BATTLE_TYPE_LINK_IN_BATTLE; - if (Rfu.parentChild == MODE_CHILD) + if (gRfu.parentChild == MODE_CHILD) { - Rfu.errorState = RFU_ERROR_STATE_3; + gRfu.errorState = RFU_ERROR_STATE_3; TryDisconnectRfu(); } else { - Rfu.callback = TryDisconnectRfu; + gRfu.callback = TryDisconnectRfu; } } } static void SendReadyCloseLink(void) { - if (gSendCmd[0] == 0 && !Rfu.unk_ce8) + if (gSendCmd[0] == 0 && !gRfu.unk_ce8) { RfuPrepareSendBuffer(RFUCMD_READY_CLOSE_LINK); - Rfu.callback = WaitAllReadyToCloseLink; + gRfu.callback = WaitAllReadyToCloseLink; } } static void Task_TryReadyCloseLink(u8 taskId) { - if (Rfu.callback == NULL) + if (gRfu.callback == NULL) { - Rfu.stopNewConnections = TRUE; - Rfu.callback = SendReadyCloseLink; + gRfu.stopNewConnections = TRUE; + gRfu.callback = SendReadyCloseLink; DestroyTask(taskId); } } @@ -1466,34 +1475,34 @@ static void SendReadyExitStandbyUntilAllReady(void) if (GetMultiplayerId() != 0) { - if (Rfu.recvQueue.count == 0 && Rfu.resendExitStandbyTimer > 60) + if (gRfu.recvQueue.count == 0 && gRfu.resendExitStandbyTimer > 60) { RfuPrepareSendBuffer(RFUCMD_READY_EXIT_STANDBY); - Rfu.resendExitStandbyTimer = 0; + gRfu.resendExitStandbyTimer = 0; } } playerCount = GetLinkPlayerCount(); for (i = 0; i < playerCount; i++) { - if (!Rfu.readyExitStandby[i]) + if (!gRfu.readyExitStandby[i]) break; } if (i == playerCount) { for (i = 0; i < MAX_RFU_PLAYERS; i++) - Rfu.readyExitStandby[i] = FALSE; - Rfu.allReadyNum++; - Rfu.callback = NULL; + gRfu.readyExitStandby[i] = FALSE; + gRfu.allReadyNum++; + gRfu.callback = NULL; } - Rfu.resendExitStandbyTimer++; + gRfu.resendExitStandbyTimer++; } static void LinkLeaderReadyToExitStandby(void) { - if (Rfu.recvQueue.count == 0 && gSendCmd[0] == 0) + if (gRfu.recvQueue.count == 0 && gSendCmd[0] == 0) { RfuPrepareSendBuffer(RFUCMD_READY_EXIT_STANDBY); - Rfu.callback = SendReadyExitStandbyUntilAllReady; + gRfu.callback = SendReadyExitStandbyUntilAllReady; } } @@ -1506,10 +1515,10 @@ static void Rfu_LinkStandby(void) if (GetMultiplayerId() != 0) { // Not link leader, send exit standby when ready - if (Rfu.recvQueue.count == 0 && gSendCmd[0] == 0) + if (gRfu.recvQueue.count == 0 && gSendCmd[0] == 0) { RfuPrepareSendBuffer(RFUCMD_READY_EXIT_STANDBY); - Rfu.callback = SendReadyExitStandbyUntilAllReady; + gRfu.callback = SendReadyExitStandbyUntilAllReady; } } else @@ -1518,15 +1527,15 @@ static void Rfu_LinkStandby(void) playerCount = GetLinkPlayerCount(); for (i = 1; i < playerCount; i++) { - if (!Rfu.readyExitStandby[i]) + if (!gRfu.readyExitStandby[i]) break; } if (i == playerCount) { - if (Rfu.recvQueue.count == 0 && gSendCmd[0] == 0) + if (gRfu.recvQueue.count == 0 && gSendCmd[0] == 0) { RfuPrepareSendBuffer(RFUCMD_READY_EXIT_STANDBY); - Rfu.callback = LinkLeaderReadyToExitStandby; + gRfu.callback = LinkLeaderReadyToExitStandby; } } } @@ -1534,10 +1543,10 @@ static void Rfu_LinkStandby(void) void Rfu_SetLinkStandbyCallback(void) { - if (Rfu.callback == NULL) + if (gRfu.callback == NULL) { - Rfu.callback = Rfu_LinkStandby; - Rfu.resendExitStandbyTimer = 0; + gRfu.callback = Rfu_LinkStandby; + gRfu.resendExitStandbyTimer = 0; } } @@ -1562,33 +1571,33 @@ u8 Rfu_SetLinkRecovery(bool32 enable) void Rfu_StopPartnerSearch(void) { - Rfu.stopNewConnections = TRUE; + gRfu.stopNewConnections = TRUE; rfu_LMAN_stopManager(FALSE); } u8 Rfu_GetMultiplayerId(void) { - if (Rfu.parentChild == MODE_PARENT) + if (gRfu.parentChild == MODE_PARENT) return 0; - return Rfu.multiplayerId; + return gRfu.multiplayerId; } u8 Rfu_GetLinkPlayerCount(void) { - return Rfu.playerCount; + return gRfu.playerCount; } bool8 IsLinkRfuTaskFinished(void) { - if (Rfu.status == RFU_STATUS_CONNECTION_ERROR) + if (gRfu.status == RFU_STATUS_CONNECTION_ERROR) return FALSE; - return Rfu.callback ? FALSE : TRUE; + return gRfu.callback ? FALSE : TRUE; } static void CallRfuFunc(void) { - if (Rfu.callback) - Rfu.callback(); + if (gRfu.callback) + gRfu.callback(); } static bool8 CheckForLeavingGroupMembers(void) @@ -1597,23 +1606,23 @@ static bool8 CheckForLeavingGroupMembers(void) bool8 memberLeft = FALSE; for (i = 0; i < RFU_CHILD_MAX; i++) { - if (Rfu.partnerSendStatuses[i] < RFU_STATUS_JOIN_GROUP_OK - || Rfu.partnerSendStatuses[i] > RFU_STATUS_JOIN_GROUP_NO) + if (gRfu.partnerSendStatuses[i] < RFU_STATUS_JOIN_GROUP_OK + || gRfu.partnerSendStatuses[i] > RFU_STATUS_JOIN_GROUP_NO) { if (gRfuSlotStatusNI[i]->recv.state == SLOT_STATE_RECV_SUCCESS || gRfuSlotStatusNI[i]->recv.state == SLOT_STATE_RECV_SUCCESS_AND_SENDSIDE_UNKNOWN) { - if (Rfu.partnerRecvStatuses[i] == RFU_STATUS_LEAVE_GROUP_NOTICE) + if (gRfu.partnerRecvStatuses[i] == RFU_STATUS_LEAVE_GROUP_NOTICE) { - Rfu.partnerSendStatuses[i] = RFU_STATUS_LEAVE_GROUP; - Rfu.partnerRecvStatuses[i] = RFU_STATUS_CHILD_LEAVE_READY; + gRfu.partnerSendStatuses[i] = RFU_STATUS_LEAVE_GROUP; + gRfu.partnerRecvStatuses[i] = RFU_STATUS_CHILD_LEAVE_READY; rfu_clearSlot(TYPE_NI_RECV, i); - rfu_NI_setSendData(1 << i, 8, &Rfu.partnerSendStatuses[i], 1); + rfu_NI_setSendData(1 << i, 8, &gRfu.partnerSendStatuses[i], 1); memberLeft = TRUE; } } - else if (gRfuSlotStatusNI[Rfu.childSlot]->recv.state == SLOT_STATE_RECV_FAILED) + else if (gRfuSlotStatusNI[gRfu.childSlot]->recv.state == SLOT_STATE_RECV_FAILED) rfu_clearSlot(TYPE_NI_RECV, i); { @@ -1631,10 +1640,10 @@ bool32 RfuTryDisconnectLeavingChildren(void) // Check all children, get those waiting to be disconnected for (i = 0; i < RFU_CHILD_MAX; i++) { - if (Rfu.partnerRecvStatuses[i] == RFU_STATUS_CHILD_LEAVE) + if (gRfu.partnerRecvStatuses[i] == RFU_STATUS_CHILD_LEAVE) { childrenLeaving |= (1 << i); - Rfu.partnerRecvStatuses[i] = RFU_STATUS_OK; + gRfu.partnerRecvStatuses[i] = RFU_STATUS_OK; } } @@ -1648,8 +1657,8 @@ bool32 RfuTryDisconnectLeavingChildren(void) // Return true if any children have left or are still waiting to leave for (i = 0; i < RFU_CHILD_MAX; i++) { - if (Rfu.partnerRecvStatuses[i] == RFU_STATUS_CHILD_LEAVE_READY - || Rfu.partnerRecvStatuses[i] == RFU_STATUS_CHILD_LEAVE) + if (gRfu.partnerRecvStatuses[i] == RFU_STATUS_CHILD_LEAVE_READY + || gRfu.partnerRecvStatuses[i] == RFU_STATUS_CHILD_LEAVE) return TRUE; } return FALSE; @@ -1660,7 +1669,7 @@ bool32 HasTrainerLeftPartnersList(u16 trainerId, const u8 *name) u8 idx = GetPartnerIndexByNameAndTrainerID(name, trainerId); if (idx == 0xFF) return TRUE; - if (Rfu.partnerSendStatuses[idx] == RFU_STATUS_LEAVE_GROUP) + if (gRfu.partnerSendStatuses[idx] == RFU_STATUS_LEAVE_GROUP) return TRUE; return FALSE; } @@ -1668,16 +1677,16 @@ bool32 HasTrainerLeftPartnersList(u16 trainerId, const u8 *name) void SendRfuStatusToPartner(u8 status, u16 trainerId, const u8 *name) { u8 idx = GetPartnerIndexByNameAndTrainerID(name, trainerId); - Rfu.partnerSendStatuses[idx] = status; + gRfu.partnerSendStatuses[idx] = status; rfu_clearSlot(TYPE_NI_SEND, idx); - rfu_NI_setSendData(1 << idx, 8, &Rfu.partnerSendStatuses[idx], 1); + rfu_NI_setSendData(1 << idx, 8, &gRfu.partnerSendStatuses[idx], 1); } void SendLeaveGroupNotice(void) { - Rfu.unk_c85 = RFU_STATUS_LEAVE_GROUP_NOTICE; - rfu_clearSlot(TYPE_NI_SEND, Rfu.childSlot); - rfu_NI_setSendData(1 << Rfu.childSlot, 8, &Rfu.unk_c85, 1); + gRfu.leaveGroupStatus = RFU_STATUS_LEAVE_GROUP_NOTICE; + rfu_clearSlot(TYPE_NI_SEND, gRfu.childSlot); + rfu_NI_setSendData(1 << gRfu.childSlot, 8, &gRfu.leaveGroupStatus, 1); } u32 WaitSendRfuStatusToPartner(u16 trainerId, const u8 *name) @@ -1700,32 +1709,32 @@ static void UpdateChildStatuses(void) if (gRfuSlotStatusNI[i]->send.state == SLOT_STATE_SEND_SUCCESS || gRfuSlotStatusNI[i]->send.state == SLOT_STATE_SEND_FAILED) { - if (Rfu.partnerRecvStatuses[i] == RFU_STATUS_CHILD_LEAVE_READY) - Rfu.partnerRecvStatuses[i] = RFU_STATUS_CHILD_LEAVE; + if (gRfu.partnerRecvStatuses[i] == RFU_STATUS_CHILD_LEAVE_READY) + gRfu.partnerRecvStatuses[i] = RFU_STATUS_CHILD_LEAVE; rfu_clearSlot(TYPE_NI_SEND, i); } } } -static s32 sub_80107A0(void) +static s32 GetJoinGroupStatus(void) { s32 status = RFU_STATUS_OK; - if (Rfu.unk_c85 == RFU_STATUS_LEAVE_GROUP_NOTICE) + if (gRfu.leaveGroupStatus == RFU_STATUS_LEAVE_GROUP_NOTICE) { - if (gRfuSlotStatusNI[Rfu.childSlot]->send.state == SLOT_STATE_SEND_SUCCESS - || gRfuSlotStatusNI[Rfu.childSlot]->send.state == SLOT_STATE_SEND_FAILED) - rfu_clearSlot(TYPE_NI_SEND, Rfu.childSlot); + if (gRfuSlotStatusNI[gRfu.childSlot]->send.state == SLOT_STATE_SEND_SUCCESS + || gRfuSlotStatusNI[gRfu.childSlot]->send.state == SLOT_STATE_SEND_FAILED) + rfu_clearSlot(TYPE_NI_SEND, gRfu.childSlot); } - if (gRfuSlotStatusNI[Rfu.childSlot]->recv.state == SLOT_STATE_RECV_SUCCESS - || gRfuSlotStatusNI[Rfu.childSlot]->recv.state == SLOT_STATE_RECV_SUCCESS_AND_SENDSIDE_UNKNOWN) + if (gRfuSlotStatusNI[gRfu.childSlot]->recv.state == SLOT_STATE_RECV_SUCCESS + || gRfuSlotStatusNI[gRfu.childSlot]->recv.state == SLOT_STATE_RECV_SUCCESS_AND_SENDSIDE_UNKNOWN) { - rfu_clearSlot(TYPE_NI_RECV, Rfu.childSlot); - RfuSetStatus(Rfu.recvStatus, 0); - status = Rfu.recvStatus; + rfu_clearSlot(TYPE_NI_RECV, gRfu.childSlot); + RfuSetStatus(gRfu.recvStatus, 0); + status = gRfu.recvStatus; } - else if (gRfuSlotStatusNI[Rfu.childSlot]->recv.state == SLOT_STATE_RECV_FAILED) + else if (gRfuSlotStatusNI[gRfu.childSlot]->recv.state == SLOT_STATE_RECV_FAILED) { - rfu_clearSlot(TYPE_NI_RECV, Rfu.childSlot); + rfu_clearSlot(TYPE_NI_RECV, gRfu.childSlot); status = RFU_STATUS_JOIN_GROUP_NO; } return status; @@ -1733,19 +1742,19 @@ static s32 sub_80107A0(void) #define tState data[0] -static void sub_801084C(u8 taskId) +static void Task_PlayerExchange(u8 taskId) { s32 i; - if (Rfu.status == RFU_STATUS_FATAL_ERROR || Rfu.status == RFU_STATUS_CONNECTION_ERROR) + if (gRfu.status == RFU_STATUS_FATAL_ERROR || gRfu.status == RFU_STATUS_CONNECTION_ERROR) { - Rfu.unk_ce8 = FALSE; + gRfu.unk_ce8 = FALSE; DestroyTask(taskId); } switch (gTasks[taskId].tState) { case 0: - if (AreNoPlayersReceiving()) + if (AreAllPlayersReadyToReceive()) { ResetBlockReceivedFlags(); LocalLinkPlayerToBlock(); @@ -1753,7 +1762,7 @@ static void sub_801084C(u8 taskId) } break; case 1: - if (Rfu.parentChild == MODE_PARENT) + if (gRfu.parentChild == MODE_PARENT) { if (gReceivedRemoteLinkPlayers) RfuPrepareSendBuffer(RFUCMD_SEND_PLAYER_IDS_NEW); @@ -1769,15 +1778,15 @@ static void sub_801084C(u8 taskId) gTasks[taskId].tState = 2; break; case 2: - if (Rfu.playerCount) + if (gRfu.playerCount) gTasks[taskId].tState++; break; case 3: - if (Rfu.parentChild == MODE_PARENT) + if (gRfu.parentChild == MODE_PARENT) { - if (AreNoPlayersReceiving()) + if (AreAllPlayersReadyToReceive()) { - Rfu.blockRequestType = BLOCK_REQ_SIZE_NONE; + gRfu.blockRequestType = BLOCK_REQ_SIZE_NONE; RfuPrepareSendBuffer(RFUCMD_SEND_BLOCK_REQ); gTasks[taskId].tState++; } @@ -1786,11 +1795,11 @@ static void sub_801084C(u8 taskId) gTasks[taskId].tState++; break; case 4: - if (sub_800FC88()) + if (AreAllPlayersFinishedReceiving()) gTasks[taskId].tState++; break; case 5: - for (i = 0; i < Rfu.playerCount; i++) + for (i = 0; i < gRfu.playerCount; i++) { LinkPlayerFromBlock(i); Rfu_ResetBlockReceivedFlag(i); @@ -1800,16 +1809,16 @@ static void sub_801084C(u8 taskId) case 6: DestroyTask(taskId); gReceivedRemoteLinkPlayers = TRUE; - Rfu.unk_ce8 = FALSE; + gRfu.unk_ce8 = FALSE; rfu_LMAN_setLinkRecovery(1, 600); - if (Rfu.unk_ce6) + if (gRfu.newChildQueue) { for (i = 0; i < RFU_CHILD_MAX; i++) { - if ((Rfu.unk_ce6 >> i) & 1) + if ((gRfu.newChildQueue >> i) & 1) { - Rfu.unk_ce5 = 1 << i; - Rfu.unk_ce6 ^= (1 << i); + gRfu.nextChildBits = 1 << i; + gRfu.newChildQueue ^= (1 << i); } } } @@ -1824,16 +1833,16 @@ static void ClearSelectedLinkPlayerIds(u16 selected) for (i = 0; i < RFU_CHILD_MAX; i++) { if ((selected >> i) & 1) - Rfu.linkPlayerIdx[i] = 0; + gRfu.linkPlayerIdx[i] = 0; } } static void ReceiveRfuLinkPlayers(const struct SioInfo *sioInfo) { s32 i; - Rfu.playerCount = sioInfo->playerCount; + gRfu.playerCount = sioInfo->playerCount; for (i = 0; i < RFU_CHILD_MAX; i++) - Rfu.linkPlayerIdx[i] = sioInfo->linkPlayerIdx[i]; + gRfu.linkPlayerIdx[i] = sioInfo->linkPlayerIdx[i]; for (i = 0; i < MAX_RFU_PLAYERS; i++) { gLinkPlayers[i] = sioInfo->linkPlayers[i]; @@ -1851,15 +1860,16 @@ static void ValidateAndReceivePokemonSioInfo(void *recvBuffer) } } -static void Task_ExchangeLinkPlayers(u8 taskId) +// Equivalent to Task_PlayerExchange, but for when new children arrive after the first exchange +static void Task_PlayerExchangeUpdate(u8 taskId) { s32 i; struct LinkPlayerBlock *playerBlock; struct SioInfo *sio; - u8 playerId = Rfu.linkPlayerIdx[sUnknown_082ED68C[Rfu.unk_ce9]]; - if (Rfu.status == RFU_STATUS_FATAL_ERROR || Rfu.status == RFU_STATUS_CONNECTION_ERROR) + u8 playerId = gRfu.linkPlayerIdx[sUnknown_082ED68C[gRfu.incomingChild]]; + if (gRfu.status == RFU_STATUS_FATAL_ERROR || gRfu.status == RFU_STATUS_CONNECTION_ERROR) { - Rfu.unk_ce8 = FALSE; + gRfu.unk_ce8 = FALSE; DestroyTask(taskId); } switch (gTasks[taskId].tState) @@ -1889,17 +1899,17 @@ static void Task_ExchangeLinkPlayers(u8 taskId) case 3: sio = (struct SioInfo *)gBlockSendBuffer; memcpy(sio->magic, sASCII_PokemonSioInfo, sizeof sASCII_PokemonSioInfo); - sio->playerCount = Rfu.playerCount; + sio->playerCount = gRfu.playerCount; for (i = 0; i < RFU_CHILD_MAX; i++) - sio->linkPlayerIdx[i] = Rfu.linkPlayerIdx[i]; + sio->linkPlayerIdx[i] = gRfu.linkPlayerIdx[i]; memcpy(sio->linkPlayers, gLinkPlayers, sizeof gLinkPlayers); gTasks[taskId].tState++; // fallthrough case 4: sio = (struct SioInfo *)gBlockSendBuffer; - sio->playerCount = Rfu.playerCount; + sio->playerCount = gRfu.playerCount; for (i = 0; i < RFU_CHILD_MAX; i++) - sio->linkPlayerIdx[i] = Rfu.linkPlayerIdx[i]; + sio->linkPlayerIdx[i] = gRfu.linkPlayerIdx[i]; memcpy(sio->linkPlayers, gLinkPlayers, sizeof(gLinkPlayers)); if (SendBlock(0, gBlockSendBuffer, 0xa0)) gTasks[taskId].tState++; @@ -1909,16 +1919,16 @@ static void Task_ExchangeLinkPlayers(u8 taskId) { CpuFill16(0, gBlockRecvBuffer, sizeof(struct SioInfo)); ResetBlockReceivedFlag(0); - Rfu.unk_ce8 = FALSE; - if (Rfu.unk_ce6) + gRfu.unk_ce8 = FALSE; + if (gRfu.newChildQueue) { - for (i = 0; i < 4; i++) + for (i = 0; i < RFU_CHILD_MAX; i++) { - if ((Rfu.unk_ce6 >> i) & 1) + if ((gRfu.newChildQueue >> i) & 1) { - Rfu.unk_ce5 = 1 << i; - Rfu.unk_ce6 ^= (1 << i); - Rfu.unk_ce8 = TRUE; + gRfu.nextChildBits = 1 << i; + gRfu.newChildQueue ^= (1 << i); + gRfu.unk_ce8 = TRUE; break; } } @@ -1929,14 +1939,15 @@ static void Task_ExchangeLinkPlayers(u8 taskId) } } -static void sub_8010D0C(u8 taskId) +// Equivalent to Task_PlayerExchange but for chatting with a Union Room partner +static void Task_PlayerExchangeChat(u8 taskId) { - if (Rfu.status == RFU_STATUS_FATAL_ERROR || Rfu.status == RFU_STATUS_CONNECTION_ERROR) + if (gRfu.status == RFU_STATUS_FATAL_ERROR || gRfu.status == RFU_STATUS_CONNECTION_ERROR) DestroyTask(taskId); switch (gTasks[taskId].tState) { case 0: - if (Rfu.playerCount) + if (gRfu.playerCount) { LocalLinkPlayerToBlock(); SendBlock(0, gBlockSendBuffer, sizeof(struct LinkPlayerBlock)); @@ -1961,17 +1972,17 @@ static void sub_8010D0C(u8 taskId) static void RfuCheckErrorStatus(void) { - if (Rfu.errorState == RFU_ERROR_STATE_1 && lman.childClockSlave_flag == 0) + if (gRfu.errorState == RFU_ERROR_STATE_1 && lman.childClockSlave_flag == 0) { if (gMain.callback2 == c2_mystery_gift_e_reader_run || lman.init_param->mboot_flag) gWirelessCommType = 2; SetMainCallback2(CB2_LinkError); gMain.savedCallback = CB2_LinkError; - BufferLinkErrorInfo((Rfu.linkmanMsg << 16) | (Rfu.unk_10 << 8) | Rfu.unk_12, Rfu.recvQueue.count, Rfu.sendQueue.count, RfuGetStatus() == RFU_STATUS_CONNECTION_ERROR); - Rfu.errorState = RFU_ERROR_STATE_2; + BufferLinkErrorInfo((gRfu.linkmanMsg << 16) | (gRfu.unk_10 << 8) | gRfu.unk_12, gRfu.recvQueue.count, gRfu.sendQueue.count, RfuGetStatus() == RFU_STATUS_CONNECTION_ERROR); + gRfu.errorState = RFU_ERROR_STATE_2; CloseLink(); } - else if (Rfu.sendQueue.full == TRUE || Rfu.recvQueue.full == TRUE) + else if (gRfu.sendQueue.full == TRUE || gRfu.recvQueue.full == TRUE) { if (lman.childClockSlave_flag) rfu_LMAN_requestChangeAgbClockMaster(); @@ -1994,11 +2005,11 @@ static void RfuMain1_UnionRoom(void) bool32 RfuMain1(void) { bool32 retval = FALSE; - Rfu.parentId = 0; + gRfu.parentId = 0; rfu_LMAN_manager_entity(Random2()); - if (!Rfu.isShuttingDown) + if (!gRfu.isShuttingDown) { - switch (Rfu.parentChild) + switch (gRfu.parentChild) { case MODE_PARENT: RfuMain1_Parent(); @@ -2018,143 +2029,147 @@ bool32 RfuMain1(void) bool32 RfuMain2(void) { bool32 retval = FALSE; - if (!Rfu.isShuttingDown) + if (!gRfu.isShuttingDown) { - if (Rfu.parentChild == MODE_PARENT) + if (gRfu.parentChild == MODE_PARENT) retval = RfuMain2_Parent(); RfuCheckErrorStatus(); } return retval; } -static void CopyPlayerNameToUnameBuffer(void) +static void SetHostRfuUsername(void) { - StringCopy(gHostRFUtgtUnameBuffer, gSaveBlock2Ptr->playerName); + StringCopy(gHostRfuUsername, gSaveBlock2Ptr->playerName); } -void ClearAndInitHostRFUtgtGname(void) +void ResetHostRfuGameData(void) { - memset(&gHostRFUtgtGnameBuffer, 0, RFU_GAME_NAME_LENGTH); - InitHostRFUtgtGname(&gHostRFUtgtGnameBuffer, ACTIVITY_NONE, FALSE, 0); + memset(&gHostRfuGameData, 0, RFU_GAME_NAME_LENGTH); + InitHostRfuGameData(&gHostRfuGameData, ACTIVITY_NONE, FALSE, 0); } -void SetHostRFUtgtGname(u8 activity, u32 child_sprite_genders, bool32 started) +void SetHostRfuGameData(u8 activity, u32 partnerInfo, bool32 startedActivity) { - InitHostRFUtgtGname(&gHostRFUtgtGnameBuffer, activity, started, child_sprite_genders); + InitHostRfuGameData(&gHostRfuGameData, activity, startedActivity, partnerInfo); } -void SetGnameBufferWonderFlags(bool32 hasNews, bool32 hasCard) +void SetHostRfuWonderFlags(bool32 hasNews, bool32 hasCard) { - gHostRFUtgtGnameBuffer.unk_00.hasNews = hasNews; - gHostRFUtgtGnameBuffer.unk_00.hasCard = hasCard; + gHostRfuGameData.compatibility.hasNews = hasNews; + gHostRfuGameData.compatibility.hasCard = hasCard; } void SetTradeBoardRegisteredMonInfo(u32 type, u32 species, u32 level) { - gHostRFUtgtGnameBuffer.type = type; - gHostRFUtgtGnameBuffer.species = species; - gHostRFUtgtGnameBuffer.level = level; + gHostRfuGameData.tradeType = type; + gHostRfuGameData.tradeSpecies = species; + gHostRfuGameData.tradeLevel = level; } u8 GetLinkPlayerInfoFlags(s32 playerId) { - u8 retval = 0x80; - retval |= (gLinkPlayers[playerId].gender << 3); - retval |= (gLinkPlayers[playerId].trainerId & 7); + u8 retval = PINFO_ACTIVE_FLAG; + retval |= (gLinkPlayers[playerId].gender << PINFO_GENDER_SHIFT); + retval |= (gLinkPlayers[playerId].trainerId & PINFO_TID_MASK); return retval; } void GetOtherPlayersInfoFlags(void) { - struct GFtgtGname *gname = &gHostRFUtgtGnameBuffer; + struct RfuGameData *data = &gHostRfuGameData; s32 i; for (i = 1; i < GetLinkPlayerCount(); i++) - gname->child_sprite_gender[i - 1] = GetLinkPlayerInfoFlags(i); + data->partnerInfo[i - 1] = GetLinkPlayerInfoFlags(i); } -void UpdateGameData_GroupLockedIn(bool8 started) +void UpdateGameData_GroupLockedIn(bool8 startedActivity) { - gHostRFUtgtGnameBuffer.started = started; - rfu_REQ_configGameData(0, RFU_SERIAL_A, (void *)&gHostRFUtgtGnameBuffer, gHostRFUtgtUnameBuffer); + gHostRfuGameData.startedActivity = startedActivity; + rfu_REQ_configGameData(0, RFU_SERIAL_GAME, (void *)&gHostRfuGameData, gHostRfuUsername); } -void UpdateGameData_SetActivity(u8 activity, u32 flags, bool32 started) +void UpdateGameData_SetActivity(u8 activity, u32 flags, bool32 startedActivity) { if (activity != ACTIVITY_NONE) - SetHostRFUtgtGname(activity, flags, started); - rfu_REQ_configGameData(0, RFU_SERIAL_A, (void *)&gHostRFUtgtGnameBuffer, gHostRFUtgtUnameBuffer); + SetHostRfuGameData(activity, flags, startedActivity); + rfu_REQ_configGameData(0, RFU_SERIAL_GAME, (void *)&gHostRfuGameData, gHostRfuUsername); } void SetUnionRoomChatPlayerData(u32 numPlayers) { s32 i; u32 numConnectedChildren; - u32 child_sprite_genders; + u32 partnerInfo; s32 slots; - if (GetHostRFUtgtGname()->activity == (ACTIVITY_CHAT | IN_UNION_ROOM)) + if (GetHostRfuGameData()->activity == (ACTIVITY_CHAT | IN_UNION_ROOM)) { numConnectedChildren = 0; - child_sprite_genders = 0; - slots = Rfu.unk_ce2 ^ Rfu.disconnectSlots; - for (i = 0; i < 4; i++) + partnerInfo = 0; + slots = gRfu.unk_ce2 ^ gRfu.disconnectSlots; + for (i = 0; i < RFU_CHILD_MAX; i++) { if ((slots >> i) & 1) { - child_sprite_genders |= ((0x80 | ((gLinkPlayers[Rfu.linkPlayerIdx[i]].gender & 1) << 3) | (gLinkPlayers[Rfu.linkPlayerIdx[i]].trainerId & 7)) << (numConnectedChildren << 3)); + // Only trainerId is shifted by the number of children, so the active flag and gender + // are only ever set for the first child + partnerInfo |= ((PINFO_ACTIVE_FLAG + | ((gLinkPlayers[gRfu.linkPlayerIdx[i]].gender & 1) << PINFO_GENDER_SHIFT) + | (gLinkPlayers[gRfu.linkPlayerIdx[i]].trainerId & PINFO_TID_MASK)) << (numConnectedChildren * 8)); numConnectedChildren++; if (numConnectedChildren == numPlayers - 1) break; } } - UpdateGameData_SetActivity(ACTIVITY_CHAT | IN_UNION_ROOM, child_sprite_genders, FALSE); + UpdateGameData_SetActivity(ACTIVITY_CHAT | IN_UNION_ROOM, partnerInfo, FALSE); } } void GetLinkmanErrorParams(u32 msg) { - if (Rfu.errorState == RFU_ERROR_STATE_NONE) + if (gRfu.errorState == RFU_ERROR_STATE_NONE) { - Rfu.unk_10 = lman.param[0]; - Rfu.unk_12 = lman.param[1]; - Rfu.linkmanMsg = msg; - Rfu.errorState = RFU_ERROR_STATE_1; + gRfu.unk_10 = lman.param[0]; + gRfu.unk_12 = lman.param[1]; + gRfu.linkmanMsg = msg; + gRfu.errorState = RFU_ERROR_STATE_1; } } static void ResetErrorState(void) { - Rfu.errorState = RFU_ERROR_STATE_NONE; + gRfu.errorState = RFU_ERROR_STATE_NONE; } void RfuSetIgnoreError(bool32 enable) { if (!enable) - Rfu.errorState = RFU_ERROR_STATE_NONE; + gRfu.errorState = RFU_ERROR_STATE_NONE; else - Rfu.errorState = RFU_ERROR_STATE_IGNORE; + gRfu.errorState = RFU_ERROR_STATE_IGNORE; } static void DisconnectNewChild(void) { SendDisconnectCommand(lman.acceptSlot_flag, RFU_DISCONNECT_ERROR); - Rfu.callback = NULL; + gRfu.callback = NULL; } static void StartDisconnectNewChild(void) { - Rfu.callback = DisconnectNewChild; + gRfu.callback = DisconnectNewChild; } -static void sub_801120C(u8 msg, u8 paramCount) +static void LinkManagerCB_Parent(u8 msg, u8 paramCount) { u8 i; u8 disconnectFlag = 0; switch (msg) { case LMAN_MSG_INITIALIZE_COMPLETED: - Rfu.state = RFUSTATE_PARENT_CONNECT; + gRfu.state = RFUSTATE_PARENT_CONNECT; break; case LMAN_MSG_NEW_CHILD_CONNECT_DETECTED: break; @@ -2164,12 +2179,12 @@ static void sub_801120C(u8 msg, u8 paramCount) { if ((lman.param[0] >> i) & 1) { - struct GFtgtGname *structPtr = (void *)gRfuLinkStatus->partner[i].gname; - if (structPtr->activity == GetHostRFUtgtGname()->activity) + struct RfuGameData *data = (void *)gRfuLinkStatus->partner[i].gname; + if (data->activity == GetHostRfuGameData()->activity) { - Rfu.partnerSendStatuses[i] = RFU_STATUS_OK; - Rfu.partnerRecvStatuses[i] = RFU_STATUS_OK; - rfu_setRecvBuffer(TYPE_NI, i, &Rfu.partnerRecvStatuses[i], sizeof(Rfu.partnerRecvStatuses[0])); + gRfu.partnerSendStatuses[i] = RFU_STATUS_OK; + gRfu.partnerRecvStatuses[i] = RFU_STATUS_OK; + rfu_setRecvBuffer(TYPE_NI, i, &gRfu.partnerRecvStatuses[i], sizeof(gRfu.partnerRecvStatuses[0])); } else { @@ -2188,26 +2203,26 @@ static void sub_801120C(u8 msg, u8 paramCount) case LMAN_MSG_SEARCH_CHILD_PERIOD_EXPIRED: break; case LMAN_MSG_END_WAIT_CHILD_NAME: - if (Rfu.acceptSlot_flag != lman.acceptSlot_flag) + if (gRfu.acceptSlot_flag != lman.acceptSlot_flag) { - rfu_REQ_disconnect(Rfu.acceptSlot_flag ^ lman.acceptSlot_flag); + rfu_REQ_disconnect(gRfu.acceptSlot_flag ^ lman.acceptSlot_flag); rfu_waitREQComplete(); } - Rfu.state = RFUSTATE_PARENT_FINALIZE_START; + gRfu.state = RFUSTATE_PARENT_FINALIZE_START; break; case LMAN_MSG_LINK_LOSS_DETECTED_AND_START_RECOVERY: - Rfu.linkLossRecoveryState = 1; + gRfu.linkLossRecoveryState = 1; break; case LMAN_MSG_LINK_RECOVERY_SUCCESSED: - Rfu.linkLossRecoveryState = 3; + gRfu.linkLossRecoveryState = 3; break; case LMAN_MSG_LINK_LOSS_DETECTED_AND_DISCONNECTED: case LMAN_MSG_LINK_RECOVERY_FAILED_AND_DISCONNECTED: - Rfu.linkLossRecoveryState = 4; - Rfu.unk_ce2 &= ~lman.param[0]; + gRfu.linkLossRecoveryState = 4; + gRfu.unk_ce2 &= ~lman.param[0]; if (gReceivedRemoteLinkPlayers == 1) { - if (Rfu.unk_ce2 == 0) + if (gRfu.unk_ce2 == 0) GetLinkmanErrorParams(msg); else StartDisconnectNewChild(); @@ -2222,7 +2237,7 @@ static void sub_801120C(u8 msg, u8 paramCount) case LMAN_MSG_LMAN_API_ERROR_RETURN: RfuSetStatus(RFU_STATUS_FATAL_ERROR, msg); GetLinkmanErrorParams(msg); - Rfu.isShuttingDown = TRUE; + gRfu.isShuttingDown = TRUE; break; case LMAN_MSG_REQ_API_ERROR: case LMAN_MSG_WATCH_DOG_TIMER_ERROR: @@ -2230,59 +2245,59 @@ static void sub_801120C(u8 msg, u8 paramCount) case LMAN_MSG_RFU_FATAL_ERROR: GetLinkmanErrorParams(msg); RfuSetStatus(RFU_STATUS_FATAL_ERROR, msg); - Rfu.unk_cdb = TRUE; + gRfu.unk_cdb = TRUE; break; } } -void sub_8011404(u8 msg, u8 unused1) +static void LinkManagerCB_Child(u8 msg, u8 unused1) { switch (msg) { case LMAN_MSG_INITIALIZE_COMPLETED: - Rfu.state = RFUSTATE_CHILD_CONNECT; + gRfu.state = RFUSTATE_CHILD_CONNECT; break; case LMAN_MSG_PARENT_FOUND: - Rfu.parentId = lman.param[0]; + gRfu.parentId = lman.param[0]; break; case LMAN_MSG_SEARCH_PARENT_PERIOD_EXPIRED: break; case LMAN_MSG_CONNECT_PARENT_SUCCESSED: - Rfu.childSlot = lman.param[0]; + gRfu.childSlot = lman.param[0]; break; case LMAN_MSG_CONNECT_PARENT_FAILED: RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, msg); break; case LMAN_MSG_CHILD_NAME_SEND_COMPLETED: - Rfu.state = RFUSTATE_CHILD_TRY_JOIN; - Rfu.unk_c85 = RFU_STATUS_OK; - Rfu.recvStatus = RFU_STATUS_OK; - rfu_setRecvBuffer(TYPE_NI, Rfu.childSlot, &Rfu.recvStatus, sizeof(Rfu.recvStatus)); - rfu_setRecvBuffer(TYPE_UNI, Rfu.childSlot, Rfu.unk_c3f, sizeof(Rfu.unk_c3f)); + gRfu.state = RFUSTATE_CHILD_TRY_JOIN; + gRfu.leaveGroupStatus = RFU_STATUS_OK; + gRfu.recvStatus = RFU_STATUS_OK; + rfu_setRecvBuffer(TYPE_NI, gRfu.childSlot, &gRfu.recvStatus, sizeof(gRfu.recvStatus)); + rfu_setRecvBuffer(TYPE_UNI, gRfu.childSlot, gRfu.unk_c3f, sizeof(gRfu.unk_c3f)); break; case LMAN_MSG_CHILD_NAME_SEND_FAILED_AND_DISCONNECTED: RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, msg); break; case LMAN_MSG_LINK_LOSS_DETECTED_AND_DISCONNECTED: - Rfu.linkLossRecoveryState = 2; - if (Rfu.recvStatus == RFU_STATUS_JOIN_GROUP_NO) + gRfu.linkLossRecoveryState = 2; + if (gRfu.recvStatus == RFU_STATUS_JOIN_GROUP_NO) break; case LMAN_MSG_LINK_RECOVERY_FAILED_AND_DISCONNECTED: - if (Rfu.linkLossRecoveryState != 2) - Rfu.linkLossRecoveryState = 4; - if (Rfu.recvStatus != RFU_STATUS_LEAVE_GROUP) + if (gRfu.linkLossRecoveryState != 2) + gRfu.linkLossRecoveryState = 4; + if (gRfu.recvStatus != RFU_STATUS_LEAVE_GROUP) RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, msg); Debug_PrintString(sASCII_LinkLossDisconnect, 5, 5); if (gReceivedRemoteLinkPlayers == 1) GetLinkmanErrorParams(msg); break; case LMAN_MSG_LINK_LOSS_DETECTED_AND_START_RECOVERY: - Rfu.linkLossRecoveryState = 1; + gRfu.linkLossRecoveryState = 1; Debug_PrintString(sASCII_LinkLossRecoveryNow, 5, 5); break; case LMAN_MSG_LINK_RECOVERY_SUCCESSED: - Rfu.linkLossRecoveryState = 3; - Rfu.linkRecovered = TRUE; + gRfu.linkLossRecoveryState = 3; + gRfu.linkRecovered = TRUE; break; case 0x34: // ? Not a valid LMAN_MSG value break; @@ -2293,7 +2308,7 @@ void sub_8011404(u8 msg, u8 unused1) case LMAN_MSG_LMAN_API_ERROR_RETURN: RfuSetStatus(RFU_STATUS_FATAL_ERROR, msg); GetLinkmanErrorParams(msg); - Rfu.isShuttingDown = TRUE; + gRfu.isShuttingDown = TRUE; break; case LMAN_MSG_REQ_API_ERROR: case LMAN_MSG_WATCH_DOG_TIMER_ERROR: @@ -2301,7 +2316,7 @@ void sub_8011404(u8 msg, u8 unused1) case LMAN_MSG_RFU_FATAL_ERROR: RfuSetStatus(RFU_STATUS_FATAL_ERROR, msg); GetLinkmanErrorParams(msg); - Rfu.unk_cdb = TRUE; + gRfu.unk_cdb = TRUE; break; } } @@ -2314,23 +2329,23 @@ static void sub_80115EC(s32 a0) { if ((a0 >> i) & 1) { - Rfu.unk_cea[i] = 0; - Rfu.unk_cee[i] = 0xFF; + gRfu.unk_cea[i] = 0; + gRfu.unk_cee[i] = 0xFF; } } } -static u8 GetNewChildrenInUnionRoomChat(s32 a0) +static u8 GetNewChildrenInUnionRoomChat(s32 emptySlotMask) { u8 ret = 0; u8 i; for (i = 0; i < RFU_CHILD_MAX; i++) { - if ((a0 >> i) & 1) + if ((emptySlotMask >> i) & 1) { - struct GFtgtGname *structPtr = (void *)gRfuLinkStatus->partner[i].gname; - if (structPtr->activity == (ACTIVITY_CHAT | IN_UNION_ROOM)) + struct RfuGameData *data = (void *)gRfuLinkStatus->partner[i].gname; + if (data->activity == (ACTIVITY_CHAT | IN_UNION_ROOM)) ret |= (1 << i); } } @@ -2338,43 +2353,43 @@ static u8 GetNewChildrenInUnionRoomChat(s32 a0) return ret; } -static void sub_8011674(u8 msg, u8 paramCount) +static void LinkManagerCB_UnionRoom(u8 msg, u8 paramCount) { - u8 r1; + u8 acceptSlot; switch (msg) { case LMAN_MSG_INITIALIZE_COMPLETED: - Rfu.state = RFUSTATE_17; + gRfu.state = RFUSTATE_17; break; case LMAN_MSG_NEW_CHILD_CONNECT_DETECTED: RfuSetStatus(RFU_STATUS_NEW_CHILD_DETECTED, 0); break; case LMAN_MSG_NEW_CHILD_CONNECT_ACCEPTED: - if (GetHostRFUtgtGname()->activity == (ACTIVITY_CHAT | IN_UNION_ROOM) && !Rfu.stopNewConnections) + if (GetHostRfuGameData()->activity == (ACTIVITY_CHAT | IN_UNION_ROOM) && !gRfu.stopNewConnections) { - u8 idx = GetNewChildrenInUnionRoomChat(lman.param[0]); - if (idx != 0) + u8 newChildren = GetNewChildrenInUnionRoomChat(lman.param[0]); + if (newChildren != 0) { - r1 = 1 << sub_800E87C(idx); - if (Rfu.unk_ce6 == 0 && !Rfu.unk_ce8) + acceptSlot = 1 << Rfu_GetIndexOfNewestChild(newChildren); + if (gRfu.newChildQueue == 0 && !gRfu.unk_ce8) { - Rfu.unk_ce5 = r1; - Rfu.unk_ce6 |= (r1 ^ idx); - Rfu.unk_ce8 = TRUE; + gRfu.nextChildBits = acceptSlot; + gRfu.newChildQueue |= (acceptSlot ^ newChildren); + gRfu.unk_ce8 = TRUE; } else { - Rfu.unk_ce6 |= idx; + gRfu.newChildQueue |= newChildren; } } - if (idx != lman.param[0]) + if (newChildren != lman.param[0]) { - Rfu.disconnectSlots |= (idx ^ lman.param[0]); - Rfu.disconnectMode = RFU_DISCONNECT_NORMAL; + gRfu.disconnectSlots |= (newChildren ^ lman.param[0]); + gRfu.disconnectMode = RFU_DISCONNECT_NORMAL; } } - else if (GetHostRFUtgtGname()->activity == (ACTIVITY_PLYRTALK | IN_UNION_ROOM)) + else if (GetHostRfuGameData()->activity == (ACTIVITY_PLYRTALK | IN_UNION_ROOM)) { rfu_REQ_disconnect(lman.acceptSlot_flag); rfu_waitREQComplete(); @@ -2386,30 +2401,30 @@ static void sub_8011674(u8 msg, u8 paramCount) case LMAN_MSG_SEARCH_CHILD_PERIOD_EXPIRED: break; case LMAN_MSG_END_WAIT_CHILD_NAME: - if (GetHostRFUtgtGname()->activity != (ACTIVITY_CHAT | IN_UNION_ROOM) && lman.acceptCount > 1) + if (GetHostRfuGameData()->activity != (ACTIVITY_CHAT | IN_UNION_ROOM) && lman.acceptCount > 1) { - r1 = 1 << sub_800E87C(lman.param[0]); - rfu_REQ_disconnect(lman.acceptSlot_flag ^ r1); + acceptSlot = 1 << Rfu_GetIndexOfNewestChild(lman.param[0]); + rfu_REQ_disconnect(lman.acceptSlot_flag ^ acceptSlot); rfu_waitREQComplete(); } - if (Rfu.state == RFUSTATE_15) - Rfu.state = RFUSTATE_UR_FINALIZE; + if (gRfu.state == RFUSTATE_15) + gRfu.state = RFUSTATE_UR_FINALIZE; break; break; case LMAN_MSG_PARENT_FOUND: - Rfu.parentId = lman.param[0]; + gRfu.parentId = lman.param[0]; break; case LMAN_MSG_SEARCH_PARENT_PERIOD_EXPIRED: break; case LMAN_MSG_CONNECT_PARENT_SUCCESSED: - Rfu.childSlot = lman.param[0]; + gRfu.childSlot = lman.param[0]; break; case LMAN_MSG_CONNECT_PARENT_FAILED: - Rfu.state = RFUSTATE_18; - if (Rfu.connectParentFailures < 2) + gRfu.state = RFUSTATE_PARENT_RECONNECT; + if (gRfu.connectParentFailures < 2) { - Rfu.connectParentFailures++; - CreateTask(sub_801209C, 2); + gRfu.connectParentFailures++; + CreateTask(Task_TryConnectToUnionRoomParent, 2); } else { @@ -2417,39 +2432,39 @@ static void sub_8011674(u8 msg, u8 paramCount) } break; case LMAN_MSG_CHILD_NAME_SEND_COMPLETED: - Rfu.state = RFUSTATE_13; + gRfu.state = RFUSTATE_UR_PLAYER_EXCHANGE; RfuSetStatus(RFU_STATUS_CHILD_SEND_COMPLETE, 0); - rfu_setRecvBuffer(TYPE_UNI, Rfu.childSlot, Rfu.unk_c3f, sizeof(Rfu.unk_c3f)); + rfu_setRecvBuffer(TYPE_UNI, gRfu.childSlot, gRfu.unk_c3f, sizeof(gRfu.unk_c3f)); break; case LMAN_MSG_CHILD_NAME_SEND_FAILED_AND_DISCONNECTED: RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, msg); break; case LMAN_MSG_LINK_LOSS_DETECTED_AND_START_RECOVERY: if (lman.acceptSlot_flag & lman.param[0]) - Rfu.linkLossRecoveryState = 1; + gRfu.linkLossRecoveryState = 1; break; case LMAN_MSG_LINK_RECOVERY_SUCCESSED: - Rfu.linkLossRecoveryState = 3; + gRfu.linkLossRecoveryState = 3; if (gRfuLinkStatus->parentChild == MODE_CHILD) - Rfu.linkRecovered = TRUE; + gRfu.linkRecovered = TRUE; break; case LMAN_MSG_LINK_LOSS_DETECTED_AND_DISCONNECTED: - Rfu.linkLossRecoveryState = 2; + gRfu.linkLossRecoveryState = 2; case LMAN_MSG_LINK_RECOVERY_FAILED_AND_DISCONNECTED: - if (Rfu.linkLossRecoveryState != 2) - Rfu.linkLossRecoveryState = 4; - if (Rfu.parentChild == MODE_PARENT) + if (gRfu.linkLossRecoveryState != 2) + gRfu.linkLossRecoveryState = 4; + if (gRfu.parentChild == MODE_PARENT) { if (gReceivedRemoteLinkPlayers == 1) { - Rfu.unk_ce2 &= ~(lman.param[0]); - if (Rfu.unk_ce2 == 0) + gRfu.unk_ce2 &= ~(lman.param[0]); + if (gRfu.unk_ce2 == 0) GetLinkmanErrorParams(msg); else StartDisconnectNewChild(); } } - else if (Rfu.disconnectMode != RFU_DISCONNECT_NORMAL && gReceivedRemoteLinkPlayers == 1) + else if (gRfu.disconnectMode != RFU_DISCONNECT_NORMAL && gReceivedRemoteLinkPlayers == 1) { GetLinkmanErrorParams(msg); rfu_LMAN_stopManager(0); @@ -2457,13 +2472,13 @@ static void sub_8011674(u8 msg, u8 paramCount) if (gRfuLinkStatus->parentChild == MODE_NEUTRAL && lman.pcswitch_flag == 0 - && FuncIsActiveTask(Task_LinkRfu_UnionRoomListen) == TRUE) - Rfu.state = RFUSTATE_17; + && FuncIsActiveTask(Task_UnionRoomListen) == TRUE) + gRfu.state = RFUSTATE_17; RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, msg); break; case LMAN_MSG_LINK_DISCONNECTED_BY_USER: - Rfu.disconnectSlots = 0; + gRfu.disconnectSlots = 0; break; case LMAN_MSG_RFU_POWER_DOWN: case LMAN_MSG_MANAGER_STOPPED: @@ -2472,7 +2487,7 @@ static void sub_8011674(u8 msg, u8 paramCount) case LMAN_MSG_LMAN_API_ERROR_RETURN: RfuSetStatus(RFU_STATUS_FATAL_ERROR, msg); GetLinkmanErrorParams(msg); - Rfu.isShuttingDown = TRUE; + gRfu.isShuttingDown = TRUE; break; case LMAN_MSG_REQ_API_ERROR: case LMAN_MSG_WATCH_DOG_TIMER_ERROR: @@ -2480,25 +2495,25 @@ static void sub_8011674(u8 msg, u8 paramCount) case LMAN_MSG_RFU_FATAL_ERROR: GetLinkmanErrorParams(msg); RfuSetStatus(RFU_STATUS_FATAL_ERROR, msg); - Rfu.unk_cdb = FALSE; + gRfu.unk_cdb = FALSE; break; } } void RfuSetNormalDisconnectMode(void) { - Rfu.disconnectMode = RFU_DISCONNECT_NORMAL; + gRfu.disconnectMode = RFU_DISCONNECT_NORMAL; } void RfuSetStatus(u8 status, u16 msg) { - Rfu.status = status; - Rfu.linkmanMsg = msg; + gRfu.status = status; + gRfu.linkmanMsg = msg; } u8 RfuGetStatus(void) { - return Rfu.status; + return gRfu.status; } bool32 RfuHasErrored(void) @@ -2513,12 +2528,12 @@ bool32 RfuHasErrored(void) bool32 sub_8011A9C(void) { - return Rfu.unk_ce8; + return gRfu.unk_ce8; } bool8 Rfu_IsMaster(void) { - return Rfu.parentChild; + return gRfu.parentChild; } void RfuVSync(void) @@ -2531,14 +2546,15 @@ void ClearRecvCommands(void) CpuFill32(0, gRecvCmds, sizeof(gRecvCmds)); } -static void sub_8011AE8(void) +static void VBlank_RfuIdle(void) { LoadOam(); ProcessSpriteCopyRequests(); TransferPlttBuffer(); } -static void sub_8011AFC(void) +// Unused +static void Debug_RfuIdle(void) { s32 i; @@ -2546,14 +2562,14 @@ static void sub_8011AFC(void) FreeAllSpritePalettes(); ResetTasks(); ResetPaletteFade(); - SetVBlankCallback(sub_8011AE8); + SetVBlankCallback(VBlank_RfuIdle); if (IsWirelessAdapterConnected()) { gLinkType = LINKTYPE_TRADE; SetWirelessCommType1(); OpenLink(); SeedRng(gMain.vblankCounter2); - for (i = 0; i < 4; i++) + for (i = 0; i < TRAINER_ID_LENGTH; i++) gSaveBlock2Ptr->playerTrainerId[i] = Random() % 256; SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_BG0_ON | DISPCNT_BG2_ON | DISPCNT_OBJ_1D_MAP); @@ -2562,28 +2578,28 @@ static void sub_8011AFC(void) BuildOamBuffer(); UpdatePaletteFade(); CreateTask_RfuIdle(); - SetMainCallback2(sub_8011BF8); + SetMainCallback2(CB2_RfuIdle); } } bool32 IsUnionRoomListenTaskActive(void) { - return FuncIsActiveTask(Task_LinkRfu_UnionRoomListen); + return FuncIsActiveTask(Task_UnionRoomListen); } void CreateTask_RfuIdle(void) { if (!FuncIsActiveTask(Task_Idle)) - Rfu.idleTaskId = CreateTask(Task_Idle, 0); + gRfu.idleTaskId = CreateTask(Task_Idle, 0); } void DestroyTask_RfuIdle(void) { if (FuncIsActiveTask(Task_Idle) == TRUE) - DestroyTask(Rfu.idleTaskId); + DestroyTask(gRfu.idleTaskId); } -static void sub_8011BF8(void) +static void CB2_RfuIdle(void) { RunTasks(); AnimateSprites(); @@ -2593,31 +2609,31 @@ static void sub_8011BF8(void) void InitializeRfuLinkManager_LinkLeader(u32 a0) { - Rfu.parentChild = MODE_PARENT; - CopyPlayerNameToUnameBuffer(); - rfu_LMAN_initializeManager(sub_801120C, NULL); + gRfu.parentChild = MODE_PARENT; + SetHostRfuUsername(); + rfu_LMAN_initializeManager(LinkManagerCB_Parent, NULL); sRfuReqConfig = sRfuReqConfigTemplate; sRfuReqConfig.availSlot_flag = sAvailSlots[a0 - 1]; - CreateTask_LinkLeaderSearchForChildren(); + CreateTask_ParentSearchForChildren(); } void InitializeRfuLinkManager_JoinGroup(void) { - Rfu.parentChild = MODE_CHILD; - CopyPlayerNameToUnameBuffer(); - rfu_LMAN_initializeManager(sub_8011404, sub_800ED34); - CreateTask_JoinGroupSearchForParent(); + gRfu.parentChild = MODE_CHILD; + SetHostRfuUsername(); + rfu_LMAN_initializeManager(LinkManagerCB_Child, LinkManagerCB_MSC); + CreateTask_ChildSearchForParent(); } void InitializeRfuLinkManager_EnterUnionRoom(void) { - Rfu.parentChild = MODE_P_C_SWITCH; - CopyPlayerNameToUnameBuffer(); - rfu_LMAN_initializeManager(sub_8011674, NULL); + gRfu.parentChild = MODE_P_C_SWITCH; + SetHostRfuUsername(); + rfu_LMAN_initializeManager(LinkManagerCB_UnionRoom, NULL); sRfuReqConfig = sRfuReqConfigTemplate; sRfuReqConfig.linkRecovery_enable = 0; sRfuReqConfig.linkRecovery_period = 600; - Rfu.searchTaskId = CreateTask(Task_LinkRfu_UnionRoomListen, 1); + gRfu.searchTaskId = CreateTask(Task_UnionRoomListen, 1); } static u16 ReadU16(const void *ptr) @@ -2651,10 +2667,10 @@ static void RfuReqDisconnectSlot(u32 slot) { rfu_REQ_disconnect(slot); rfu_waitREQComplete(); - Rfu.unk_ce2 &= ~(slot); - rfu_clearSlot(1, Rfu.unk_cda); - rfu_UNI_setSendData(Rfu.unk_ce2, Rfu.recvCmds, 70); - Rfu.unk_cda = sub_800E87C(Rfu.unk_ce2); + gRfu.unk_ce2 &= ~slot; + rfu_clearSlot(1, gRfu.unk_cda); + rfu_UNI_setSendData(gRfu.unk_ce2, gRfu.recvCmds, 70); + gRfu.unk_cda = Rfu_GetIndexOfNewestChild(gRfu.unk_ce2); } void RequestDisconnectSlotByTrainerNameAndId(const u8 *name, u16 id) @@ -2673,7 +2689,7 @@ void Rfu_DisconnectPlayerById(u32 playerIdx) for (i = 0; i < RFU_CHILD_MAX; i++) { - if (Rfu.linkPlayerIdx[i] == playerIdx && (Rfu.unk_ce2 >> i) & 1) + if (gRfu.linkPlayerIdx[i] == playerIdx && (gRfu.unk_ce2 >> i) & 1) toDisconnect |= 1 << i; } if (toDisconnect) @@ -2686,13 +2702,13 @@ void Rfu_DisconnectPlayerById(u32 playerIdx) static void Task_SendDisconnectCommand(u8 taskId) { - if (gSendCmd[0] == 0 && !Rfu.unk_ce8) + if (gSendCmd[0] == 0 && !gRfu.unk_ce8) { RfuPrepareSendBuffer(RFUCMD_DISCONNECT); gSendCmd[1] = gTasks[taskId].tDisconnectPlayers; gSendCmd[2] = gTasks[taskId].tDisconnectMode; - Rfu.playerCount -= sPlayerBitsToCount[gTasks[taskId].tDisconnectPlayers]; - gSendCmd[3] = Rfu.playerCount; + gRfu.playerCount -= sPlayerBitsToCount[gTasks[taskId].tDisconnectPlayers]; + gSendCmd[3] = gRfu.playerCount; DestroyTask(taskId); } } @@ -2729,12 +2745,12 @@ static void Task_RfuReconnectWithParent(u8 taskId) { if (gRfuLinkStatus->partner[id].slot != 0xFF) { - Rfu.unk_c3d = id; + gRfu.unk_c3d = id; if (TryReconnectParent()) DestroyTask(taskId); } - else if (GetHostRFUtgtGname()->activity == ACTIVITY_WONDER_CARD2 - || GetHostRFUtgtGname()->activity == ACTIVITY_WONDER_NEWS2) + else if (GetHostRfuGameData()->activity == ACTIVITY_WONDER_CARD + || GetHostRfuGameData()->activity == ACTIVITY_WONDER_NEWS) { tTime++; } @@ -2748,7 +2764,7 @@ static void Task_RfuReconnectWithParent(u8 taskId) else { tTime++; - Rfu.unk_c3d = id; + gRfu.unk_c3d = id; } } else @@ -2771,40 +2787,40 @@ void CreateTask_RfuReconnectWithParent(const u8 *name, u16 trainerId) u8 taskId; s16 *data; - Rfu.status = RFU_STATUS_OK; + gRfu.status = RFU_STATUS_OK; taskId = CreateTask(Task_RfuReconnectWithParent, 3); data = gTasks[taskId].data; StringCopy((u8*)(data), name); data[8] = trainerId; } -static bool32 IsPartnerActivityIncompatible(s16 activity, struct GFtgtGname *partnerGname) +static bool32 IsPartnerActivityIncompatible(s16 activity, struct RfuGameData *partner) { - if (GetHostRFUtgtGname()->activity == (ACTIVITY_CHAT | IN_UNION_ROOM)) + if (GetHostRfuGameData()->activity == (ACTIVITY_CHAT | IN_UNION_ROOM)) { // Host trying to chat, but partner isn't - if (partnerGname->activity != (ACTIVITY_CHAT | IN_UNION_ROOM)) + if (partner->activity != (ACTIVITY_CHAT | IN_UNION_ROOM)) return TRUE; } - else if (partnerGname->activity != IN_UNION_ROOM) + else if (partner->activity != IN_UNION_ROOM) { // Partner not in union room return TRUE; } else if (activity == (ACTIVITY_TRADE | IN_UNION_ROOM)) { - // Trying to trade, make sure trade matches request - struct GFtgtGname *tradeGname = &Rfu.unk_10A; - if (tradeGname->species == SPECIES_EGG) + // Verify that the trade offered hasn't changed + struct RfuGameData *original = &gRfu.parent; + if (original->tradeSpecies == SPECIES_EGG) { - if (partnerGname->species == tradeGname->species) + if (partner->tradeSpecies == original->tradeSpecies) return FALSE; else return TRUE; } - else if (partnerGname->species != tradeGname->species - || partnerGname->level != tradeGname->level - || partnerGname->type != tradeGname->type) + else if (partner->tradeSpecies != original->tradeSpecies + || partner->tradeLevel != original->tradeLevel + || partner->tradeType != original->tradeType) { return TRUE; } @@ -2816,9 +2832,10 @@ static bool32 IsPartnerActivityIncompatible(s16 activity, struct GFtgtGname *par #define tTime data[0] #define tActivity data[1] -static void sub_801209C(u8 taskId) +static void Task_TryConnectToUnionRoomParent(u8 taskId) { - if (Rfu.status == RFU_STATUS_NEW_CHILD_DETECTED) + // Stop task if player is the new parent + if (gRfu.status == RFU_STATUS_NEW_CHILD_DETECTED) DestroyTask(taskId); if (++gTasks[taskId].tTime > 300) @@ -2828,17 +2845,21 @@ static void sub_801209C(u8 taskId) DestroyTask(taskId); } - if (Rfu.parentId != 0 && lman.parent_child == MODE_CHILD) + // Check if parent should be searched for + if (gRfu.parentId != 0 && lman.parent_child == MODE_CHILD) { - u16 trainerId = ReadU16(Rfu.unk_10A.unk_00.playerTrainerId); - u8 id = GetPartnerIndexByNameAndTrainerID(Rfu.playerName, trainerId); + // Search for parent + u16 trainerId = ReadU16(gRfu.parent.compatibility.playerTrainerId); + u8 id = GetPartnerIndexByNameAndTrainerID(gRfu.parentName, trainerId); if (id != 0xFF) { + // Parent found, try to connect if (!IsPartnerActivityIncompatible(gTasks[taskId].tActivity, (void *)gRfuLinkStatus->partner[id].gname)) { if (gRfuLinkStatus->partner[id].slot != 0xFF && !rfu_LMAN_CHILD_connectParent(gRfuLinkStatus->partner[id].id, 90)) { - Rfu.state = RFUSTATE_10; + // Succesfully connected to parent + gRfu.state = RFUSTATE_CONNECTED; DestroyTask(taskId); } } @@ -2852,33 +2873,33 @@ static void sub_801209C(u8 taskId) } } -void sub_8012188(const u8 *name, struct GFtgtGname *gname, u8 activity) +void TryConnectToUnionRoomParent(const u8 *name, struct RfuGameData *parent, u8 activity) { - u8 taskId, taskId2; + u8 taskId, listenTaskId; - Rfu.connectParentFailures = 0; - Rfu.status = RFU_STATUS_OK; - StringCopy(Rfu.playerName, name); - memcpy(&Rfu.unk_10A, gname, RFU_GAME_NAME_LENGTH); + gRfu.connectParentFailures = 0; + gRfu.status = RFU_STATUS_OK; + StringCopy(gRfu.parentName, name); + memcpy(&gRfu.parent, parent, RFU_GAME_NAME_LENGTH); rfu_LMAN_forceChangeSP(); - taskId = CreateTask(sub_801209C, 2); + taskId = CreateTask(Task_TryConnectToUnionRoomParent, 2); gTasks[taskId].tActivity = activity; - taskId2 = FindTaskIdByFunc(Task_LinkRfu_UnionRoomListen); + listenTaskId = FindTaskIdByFunc(Task_UnionRoomListen); if (activity == (ACTIVITY_CHAT | IN_UNION_ROOM)) { - if (taskId2 != TASK_NONE) - gTasks[taskId2].tData7 = TRUE; + if (listenTaskId != TASK_NONE) + gTasks[listenTaskId].tConnectingForChat = TRUE; } else { - if (taskId2 != TASK_NONE) - gTasks[taskId2].tData7 = FALSE; + if (listenTaskId != TASK_NONE) + gTasks[listenTaskId].tConnectingForChat = FALSE; } } bool8 IsRfuRecoveringFromLinkLoss(void) { - if (Rfu.linkLossRecoveryState == 1) + if (gRfu.linkLossRecoveryState == 1) return TRUE; else return FALSE; @@ -2892,7 +2913,7 @@ bool32 IsRfuCommunicatingWithAllChildren(void) // RFU_STATUS_OK is the default status. // If any connected child is receiving a status other // than OK, then the parent is communicating with them - if ((lman.acceptSlot_flag >> i) & 1 && Rfu.partnerSendStatuses[i] == RFU_STATUS_OK) + if ((lman.acceptSlot_flag >> i) & 1 && gRfu.partnerSendStatuses[i] == RFU_STATUS_OK) return FALSE; } @@ -2912,7 +2933,7 @@ static void Debug_PrintStatus(void) Debug_PrintNum(GetBlockReceivedStatus(), 28, 19, 2); Debug_PrintNum(gRfuLinkStatus->connSlotFlag, 20, 1, 1); Debug_PrintNum(gRfuLinkStatus->linkLossSlotFlag, 23, 1, 1); - if (Rfu.parentChild == MODE_PARENT) + if (gRfu.parentChild == MODE_PARENT) { for (i = 0; i < RFU_CHILD_MAX; i++) { @@ -2926,7 +2947,7 @@ static void Debug_PrintStatus(void) for (i = 0; i < RFU_CHILD_MAX; i++) { for (j = 0; j < CHILD_DATA_LENGTH; j++) - Debug_PrintNum(Rfu.childRecvBuffer[i][j], j * 2, i + 11, 2); + Debug_PrintNum(gRfu.childRecvBuffer[i][j], j * 2, i + 11, 2); } Debug_PrintString(sASCII_NowSlot, 1, 15); } @@ -2938,9 +2959,9 @@ static void Debug_PrintStatus(void) Debug_PrintString(sASCII_15Spaces, 6, i + 3); Debug_PrintString(sASCII_8Spaces, 22, i + 3); } - Debug_PrintNum(gRfuLinkStatus->partner[Rfu.childSlot].serialNo, 1, 3, 4); - Debug_PrintString((void*)gRfuLinkStatus->partner[Rfu.childSlot].gname, 6, 3); - Debug_PrintString(gRfuLinkStatus->partner[Rfu.childSlot].uname, 22, 3); + Debug_PrintNum(gRfuLinkStatus->partner[gRfu.childSlot].serialNo, 1, 3, 4); + Debug_PrintString((void*)gRfuLinkStatus->partner[gRfu.childSlot].gname, 6, 3); + Debug_PrintString(gRfuLinkStatus->partner[gRfu.childSlot].uname, 22, 3); } else { @@ -2964,12 +2985,12 @@ static void Debug_PrintStatus(void) static u32 GetRfuSendQueueLength(void) { - return Rfu.sendQueue.count; + return gRfu.sendQueue.count; } u32 GetRfuRecvQueueLength(void) { - return Rfu.recvQueue.count; + return gRfu.recvQueue.count; } static void Task_Idle(u8 taskId) diff --git a/src/link_rfu_3.c b/src/link_rfu_3.c index 08678c40f..acac57d35 100644 --- a/src/link_rfu_3.c +++ b/src/link_rfu_3.c @@ -15,6 +15,9 @@ enum { WIRELESS_STATUS_ANIM_ERROR, }; +#define TAG_GFX_STATUS_INDICATOR 0xD431 +#define TAG_PAL_STATUS_INDICATOR 0xD432 + #define UNUSED_QUEUE_NUM_SLOTS 2 #define UNUSED_QUEUE_SLOT_LENGTH 256 @@ -29,7 +32,7 @@ struct RfuUnusedQueue EWRAM_DATA u8 gWirelessStatusIndicatorSpriteId = 0; -static u8 sUnknown_03000D74; +static u8 sSequenceArrayValOffset; static const u16 sWirelessLinkIconPalette[] = INCBIN_U16("graphics/interface/wireless_link_icon.gbapal"); static const u32 sWirelessLinkIconPic[] = INCBIN_U32("graphics/interface/wireless_link_icon.4bpp.lz"); @@ -290,16 +293,16 @@ static const union AnimCmd *const sWirelessStatusIndicatorAnims[] = { }; static const struct CompressedSpriteSheet sWirelessStatusIndicatorSpriteSheet = { - sWirelessLinkIconPic, 0x0380, 0xD431 + sWirelessLinkIconPic, 0x0380, TAG_GFX_STATUS_INDICATOR }; static const struct SpritePalette sWirelessStatusIndicatorSpritePalette = { - sWirelessLinkIconPalette, 0xD432 + sWirelessLinkIconPalette, TAG_PAL_STATUS_INDICATOR }; static const struct SpriteTemplate sWirelessStatusIndicatorSpriteTemplate = { - .tileTag = 0xD431, - .paletteTag = 0xD432, + .tileTag = TAG_GFX_STATUS_INDICATOR, + .paletteTag = TAG_PAL_STATUS_INDICATOR, .oam = &sWirelessStatusIndicatorOamData, .anims = sWirelessStatusIndicatorAnims, .images = NULL, @@ -333,9 +336,7 @@ void RfuSendQueue_Reset(struct RfuSendQueue *queue) for (i = 0; i < SEND_QUEUE_NUM_SLOTS; i++) { for (j = 0; j < SEND_QUEUE_SLOT_LENGTH; j++) - { queue->slots[i][j] = 0; - } } queue->sendSlot = 0; queue->recvSlot = 0; @@ -351,9 +352,7 @@ static void RfuUnusedQueue_Reset(struct RfuUnusedQueue *queue) for (i = 0; i < UNUSED_QUEUE_NUM_SLOTS; i++) { for (j = 0; j < UNUSED_QUEUE_SLOT_LENGTH; j++) - { queue->slots[i][j] = 0; - } } queue->sendSlot = 0; queue->recvSlot = 0; @@ -555,46 +554,57 @@ static bool8 RfuUnusedQueue_Dequeue(struct RfuUnusedQueue *queue, u8 *dest) } // Unused -static void sub_800DBF8(u8 *q1, u8 mode) +// Populates an array with a sequence of numbers (which numbers depends on the mode) +// and sets the final element to the total of the other elements +#define SEQ_ARRAY_MAX_SIZE 200 +static void PopulateArrayWithSequence(u8 *arr, u8 mode) { s32 i; u8 rval; - u16 r5 = 0; + u16 total = 0; switch (mode) { case 0: - for (i = 0; i < 200; i++) + // Populate with numbers 1-200 + // Total will be 20100 + for (i = 0; i < SEQ_ARRAY_MAX_SIZE; i++) { - q1[i] = i + 1; - r5 += i + 1; + arr[i] = i + 1; + total += i + 1; } - *((u16 *)(q1 + i)) = r5; + *((u16 *)(arr + i)) = total; break; case 1: + // Populate with numbers 1-100 + // Total will be 5050 for (i = 0; i < 100; i++) { - q1[i] = i + 1; - r5 += i + 1; + arr[i] = i + 1; + total += i + 1; } - *((u16 *)(q1 + 200)) = r5; + *((u16 *)(arr + SEQ_ARRAY_MAX_SIZE)) = total; break; case 2: - for (i = 0; i < 200; i++) + // Populate with random numbers 0-255 + // Total will be a number 0-51000 + for (i = 0; i < SEQ_ARRAY_MAX_SIZE; i++) { rval = Random(); - q1[i] = rval; - r5 += rval; + arr[i] = rval; + total += rval; } - *((u16 *)(q1 + i)) = r5; + *((u16 *)(arr + i)) = total; break; case 3: - for (i = 0; i < 200; i++) + // Populate with numbers 1-200 + sSequenceArrayValOffset + // Total will be a number 20100-51000 + for (i = 0; i < SEQ_ARRAY_MAX_SIZE; i++) { - q1[i] = i + 1 + sUnknown_03000D74; - r5 += (i + 1 + sUnknown_03000D74) & 0xFF; + arr[i] = i + 1 + sSequenceArrayValOffset; + total += (i + 1 + sSequenceArrayValOffset) & 0xFF; } - *((u16 *)(q1 + i)) = r5; - sUnknown_03000D74++; + *((u16 *)(arr + i)) = total; + sSequenceArrayValOffset++; break; } } @@ -606,9 +616,7 @@ static void PkmnStrToASCII(u8 *asciiStr, const u8 *pkmnStr) s32 i; for (i = 0; pkmnStr[i] != EOS; i++) - { asciiStr[i] = sWireless_RSEtoASCIITable[pkmnStr[i]]; - } asciiStr[i] = 0; } @@ -617,9 +625,7 @@ static void ASCIIToPkmnStr(u8 *pkmnStr, const u8 *asciiStr) s32 i; for (i = 0; asciiStr[i] != 0; i++) - { pkmnStr[i] = sWireless_ASCIItoRSETable[asciiStr[i]]; - } pkmnStr[i] = EOS; } @@ -655,33 +661,32 @@ static u8 GetConnectedChildStrength(u8 maxFlags) return 0; } -void InitHostRFUtgtGname(struct GFtgtGname *data, u8 activity, bool32 started, s32 child_sprite_genders) +void InitHostRfuGameData(struct RfuGameData *data, u8 activity, bool32 startedActivity, s32 partnerInfo) { s32 i; - for (i = 0; i < 2; i++) - { - data->unk_00.playerTrainerId[i] = gSaveBlock2Ptr->playerTrainerId[i]; - } + for (i = 0; i < (s32)ARRAY_COUNT(data->compatibility.playerTrainerId); i++) + data->compatibility.playerTrainerId[i] = gSaveBlock2Ptr->playerTrainerId[i]; + for (i = 0; i < RFU_CHILD_MAX; i++) { - data->child_sprite_gender[i] = child_sprite_genders; - child_sprite_genders >>= 8; + data->partnerInfo[i] = partnerInfo; + partnerInfo >>= 8; // Each element is 1 byte } data->playerGender = gSaveBlock2Ptr->playerGender; data->activity = activity; - data->started = started; - data->unk_00.language = GAME_LANGUAGE; - data->unk_00.version = GAME_VERSION; - data->unk_00.hasNews = FALSE; - data->unk_00.hasCard = FALSE; - data->unk_00.unknown = FALSE; - data->unk_00.isChampion = FlagGet(FLAG_IS_CHAMPION); - data->unk_00.hasNationalDex = IsNationalPokedexEnabled(); - data->unk_00.gameClear = FlagGet(FLAG_SYS_GAME_CLEAR); + data->startedActivity = startedActivity; + data->compatibility.language = GAME_LANGUAGE; + data->compatibility.version = GAME_VERSION; + data->compatibility.hasNews = FALSE; + data->compatibility.hasCard = FALSE; + data->compatibility.unknown = FALSE; + data->compatibility.isChampion = FlagGet(FLAG_IS_CHAMPION); + data->compatibility.hasNationalDex = IsNationalPokedexEnabled(); + data->compatibility.gameClear = FlagGet(FLAG_SYS_GAME_CLEAR); } -bool8 LinkRfu_GetNameIfCompatible(struct GFtgtGname *buff1, u8 *buff2, u8 idx) +bool8 Rfu_GetCompatiblePlayerData(struct RfuGameData *gameData, u8 *username, u8 idx) { bool8 retVal; @@ -690,13 +695,13 @@ bool8 LinkRfu_GetNameIfCompatible(struct GFtgtGname *buff1, u8 *buff2, u8 idx) retVal = TRUE; if (IsRfuSerialNumberValid(gRfuLinkStatus->partner[idx].serialNo) && ((gRfuLinkStatus->getNameFlag >> idx) & 1)) { - memcpy(buff1, gRfuLinkStatus->partner[idx].gname, RFU_GAME_NAME_LENGTH); - memcpy(buff2, gRfuLinkStatus->partner[idx].uname, PLAYER_NAME_LENGTH + 1); + memcpy(gameData, gRfuLinkStatus->partner[idx].gname, RFU_GAME_NAME_LENGTH); + memcpy(username, gRfuLinkStatus->partner[idx].uname, RFU_USER_NAME_LENGTH); } else { - memset(buff1, 0, RFU_GAME_NAME_LENGTH); - memset(buff2, 0, PLAYER_NAME_LENGTH + 1); + memset(gameData, 0, RFU_GAME_NAME_LENGTH); + memset(username, 0, RFU_USER_NAME_LENGTH); } } else @@ -704,39 +709,39 @@ bool8 LinkRfu_GetNameIfCompatible(struct GFtgtGname *buff1, u8 *buff2, u8 idx) retVal = FALSE; if (IsRfuSerialNumberValid(gRfuLinkStatus->partner[idx].serialNo)) { - memcpy(buff1, gRfuLinkStatus->partner[idx].gname, RFU_GAME_NAME_LENGTH); - memcpy(buff2, gRfuLinkStatus->partner[idx].uname, PLAYER_NAME_LENGTH + 1); + memcpy(gameData, gRfuLinkStatus->partner[idx].gname, RFU_GAME_NAME_LENGTH); + memcpy(username, gRfuLinkStatus->partner[idx].uname, RFU_USER_NAME_LENGTH); } else { - memset(buff1, 0, RFU_GAME_NAME_LENGTH); - memset(buff2, 0, PLAYER_NAME_LENGTH + 1); + memset(gameData, 0, RFU_GAME_NAME_LENGTH); + memset(username, 0, RFU_USER_NAME_LENGTH); } } return retVal; } -bool8 LinkRfu_GetNameIfSerial7F7D(struct GFtgtGname *buff1, u8 *buff2, u8 idx) +bool8 Rfu_GetWonderDistributorPlayerData(struct RfuGameData *gameData, u8 *username, u8 idx) { bool8 retVal = FALSE; - if (gRfuLinkStatus->partner[idx].serialNo == RFU_SERIAL_B) + if (gRfuLinkStatus->partner[idx].serialNo == RFU_SERIAL_WONDER_DISTRIBUTOR) { - memcpy(buff1, gRfuLinkStatus->partner[idx].gname, RFU_GAME_NAME_LENGTH); - memcpy(buff2, gRfuLinkStatus->partner[idx].uname, PLAYER_NAME_LENGTH + 1); + memcpy(gameData, gRfuLinkStatus->partner[idx].gname, RFU_GAME_NAME_LENGTH); + memcpy(username, gRfuLinkStatus->partner[idx].uname, RFU_USER_NAME_LENGTH); retVal = TRUE; } else { - memset(buff1, 0, RFU_GAME_NAME_LENGTH); - memset(buff2, 0, PLAYER_NAME_LENGTH + 1); + memset(gameData, 0, RFU_GAME_NAME_LENGTH); + memset(username, 0, RFU_USER_NAME_LENGTH); } return retVal; } -void LinkRfu3_SetGnameUnameFromStaticBuffers(struct GFtgtGname *buff1, u8 *buff2) +void CopyHostRfuGameDataAndUsername(struct RfuGameData *gameData, u8 *username) { - memcpy(buff1, &gHostRFUtgtGnameBuffer, RFU_GAME_NAME_LENGTH); - memcpy(buff2, gHostRFUtgtUnameBuffer, PLAYER_NAME_LENGTH + 1); + memcpy(gameData, &gHostRfuGameData, RFU_GAME_NAME_LENGTH); + memcpy(username, gHostRfuUsername, RFU_USER_NAME_LENGTH); } #define sNextAnimNum data[0] @@ -754,8 +759,8 @@ void CreateWirelessStatusIndicatorSprite(u8 x, u8 y) if (x == 0 && y == 0) { - x = 0xE7; - y = 0x08; + x = 231; + y = 8; } if (gRfuLinkStatus->parentChild == MODE_PARENT) { @@ -788,9 +793,7 @@ void DestroyWirelessStatusIndicatorSprite(void) void LoadWirelessStatusIndicatorSpriteGfx(void) { if (GetSpriteTileStartByTag(sWirelessStatusIndicatorSpriteSheet.tag) == 0xFFFF) - { LoadCompressedSpriteSheet(&sWirelessStatusIndicatorSpriteSheet); - } LoadSpritePalette(&sWirelessStatusIndicatorSpritePalette); gWirelessStatusIndicatorSpriteId = SPRITE_NONE; } @@ -802,9 +805,7 @@ static u8 GetParentSignalStrength(void) for (i = 0; i < RFU_CHILD_MAX; i++) { if (flags & 1) - { return gRfuLinkStatus->strength[i]; - } flags >>= 1; } return 0; @@ -827,40 +828,33 @@ void UpdateWirelessStatusIndicatorSprite(void) struct Sprite *sprite = &gSprites[gWirelessStatusIndicatorSpriteId]; u8 signalStrength = RFU_LINK_ICON_LEVEL4_MAX; u8 i = 0; + + // Get weakest signal strength if (gRfuLinkStatus->parentChild == MODE_PARENT) { for (i = 0; i < GetLinkPlayerCount() - 1; i++) { if (signalStrength >= GetConnectedChildStrength(i + 1)) - { signalStrength = GetConnectedChildStrength(i + 1); - } } } else { signalStrength = GetParentSignalStrength(); } + + // Set signal strength sprite anim number if (IsRfuRecoveringFromLinkLoss() == TRUE) - { sprite->sNextAnimNum = WIRELESS_STATUS_ANIM_ERROR; - } else if (signalStrength <= RFU_LINK_ICON_LEVEL1_MAX) - { sprite->sNextAnimNum = WIRELESS_STATUS_ANIM_SEARCHING; - } else if (signalStrength >= RFU_LINK_ICON_LEVEL2_MIN && signalStrength <= RFU_LINK_ICON_LEVEL2_MAX) - { sprite->sNextAnimNum = WIRELESS_STATUS_ANIM_1_BAR; - } else if (signalStrength >= RFU_LINK_ICON_LEVEL3_MIN && signalStrength <= RFU_LINK_ICON_LEVEL3_MAX) - { sprite->sNextAnimNum = WIRELESS_STATUS_ANIM_2_BARS; - } else if (signalStrength >= RFU_LINK_ICON_LEVEL4_MIN) - { sprite->sNextAnimNum = WIRELESS_STATUS_ANIM_3_BARS; - } + if (sprite->sNextAnimNum != sprite->sSavedAnimNum) { SetWirelessStatusIndicatorAnim(sprite, sprite->sNextAnimNum); @@ -871,9 +865,7 @@ void UpdateWirelessStatusIndicatorSprite(void) sprite->sFrameIdx++; sprite->sFrameDelay = 0; if (sprite->anims[sprite->sCurrAnimNum][sprite->sFrameIdx].type == -2) - { sprite->sFrameIdx = 0; - } } else { @@ -884,11 +876,9 @@ void UpdateWirelessStatusIndicatorSprite(void) gMain.oamBuffer[125].y = sprite->pos1.y + sprite->centerToCornerVecY; gMain.oamBuffer[125].paletteNum = sprite->oam.paletteNum; gMain.oamBuffer[125].tileNum = sprite->sTileStart + sprite->anims[sprite->sCurrAnimNum][sprite->sFrameIdx].frame.imageValue; - CpuCopy16(gMain.oamBuffer + 125, (struct OamData *)OAM + 125, sizeof(struct OamData)); + CpuCopy16(&gMain.oamBuffer[125], (struct OamData *)OAM + 125, sizeof(struct OamData)); if (RfuGetStatus() == RFU_STATUS_FATAL_ERROR) - { DestroyWirelessStatusIndicatorSprite(); - } } } @@ -926,7 +916,7 @@ void RecordMixTrainerNames(void) s32 i; s32 j; s32 nextSpace; - s32 connectedTrainerRecordIndices[5]; + s32 connectedTrainerRecordIndices[MAX_RFU_PLAYERS]; struct TrainerNameRecord *newRecords = calloc(ARRAY_COUNT(gSaveBlock1Ptr->trainerNameRecords), sizeof(struct TrainerNameRecord)); // Check if we already have a record saved for connected trainers. @@ -936,9 +926,7 @@ void RecordMixTrainerNames(void) for (j = 0; j < (int)ARRAY_COUNT(gSaveBlock1Ptr->trainerNameRecords); j++) { if ((u16)gLinkPlayers[i].trainerId == gSaveBlock1Ptr->trainerNameRecords[j].trainerId && StringCompare(gLinkPlayers[i].name, gSaveBlock1Ptr->trainerNameRecords[j].trainerName) == 0) - { connectedTrainerRecordIndices[i] = j; - } } } @@ -952,9 +940,7 @@ void RecordMixTrainerNames(void) // If we already had a record for this trainer, wipe it so that the next step doesn't duplicate it. if (connectedTrainerRecordIndices[i] >= 0) - { - memset(gSaveBlock1Ptr->trainerNameRecords[connectedTrainerRecordIndices[i]].trainerName, 0, 8); - } + memset(gSaveBlock1Ptr->trainerNameRecords[connectedTrainerRecordIndices[i]].trainerName, 0, PLAYER_NAME_LENGTH + 1); nextSpace++; } } @@ -967,9 +953,7 @@ void RecordMixTrainerNames(void) { CopyTrainerRecord(&newRecords[nextSpace], gSaveBlock1Ptr->trainerNameRecords[i].trainerId, gSaveBlock1Ptr->trainerNameRecords[i].trainerName); if (++nextSpace >= (int)ARRAY_COUNT(gSaveBlock1Ptr->trainerNameRecords)) - { break; - } } } @@ -1001,6 +985,6 @@ void WipeTrainerNameRecords(void) for (i = 0; i < (int)ARRAY_COUNT(gSaveBlock1Ptr->trainerNameRecords); i++) { gSaveBlock1Ptr->trainerNameRecords[i].trainerId = 0; - CpuFill16(0, gSaveBlock1Ptr->trainerNameRecords[i].trainerName, 8); + CpuFill16(0, gSaveBlock1Ptr->trainerNameRecords[i].trainerName, PLAYER_NAME_LENGTH + 1); } } diff --git a/src/mystery_gift.c b/src/mystery_gift.c index afbe50e4d..6ae6a9534 100644 --- a/src/mystery_gift.c +++ b/src/mystery_gift.c @@ -510,13 +510,9 @@ void MG_DrawCheckerboardPattern(u32 bg) for (j = 0; j < 32; j++) { if ((i & 1) != (j & 1)) - { FillBgTilemapBufferRect(bg, 1, j, i + 2, 1, 1, 0x11); - } else - { FillBgTilemapBufferRect(bg, 2, j, i + 2, 1, 1, 0x11); - } } } } @@ -593,10 +589,8 @@ bool32 unref_HideDownArrowAndWaitButton(u8 * textState) { case 0: HideDownArrow(); - if (({JOY_NEW(A_BUTTON | B_BUTTON);})) - { + if (JOY_NEW(A_BUTTON | B_BUTTON)) (*textState)++; - } break; case 1: ShowDownArrow(); @@ -609,9 +603,8 @@ bool32 unref_HideDownArrowAndWaitButton(u8 * textState) static bool32 PrintStringAndWait2Seconds(u8 * counter, const u8 * str) { if (*counter == 0) - { AddTextPrinterToWindow1(str); - } + if (++(*counter) > 120) { *counter = 0; @@ -632,27 +625,20 @@ static u32 MysteryGift_HandleThreeOptionMenu(u8 * unused0, u16 * unused1, u8 whi s32 response; if (whichMenu == 0) - { listMenuTemplate.items = sListMenuItems_CardsOrNews; - } else - { listMenuTemplate.items = sListMenuItems_WirelessOrFriend; - } + width = Intl_GetListMenuWidth(&listMenuTemplate); if (width & 1) - { width++; - } + windowTemplate.width = width; if (width < 30) - { windowTemplate.tilemapLeft = (30 - width) / 2; - } else - { windowTemplate.tilemapLeft = 0; - } + response = DoMysteryGiftListMenu(&windowTemplate, &listMenuTemplate, 1, 0x00A, 0xE0); if (response != -1) { @@ -672,13 +658,9 @@ s8 mevent_message_print_and_prompt_yes_no(u8 * textState, u16 * windowId, bool8 case 0: StringExpandPlaceholders(gStringVar4, str); if (yesNoBoxPlacement == 0) - { *windowId = AddWindow(&sWindowTemplate_PromptYesOrNo_Width28); - } else - { *windowId = AddWindow(&sWindowTemplate_PromptYesOrNo_Width20); - } FillWindowPixelBuffer(*windowId, 0x11); AddTextPrinterParameterized4(*windowId, 1, 0, 1, 0, 0, sMG_Ereader_TextColor_2, 0, gStringVar4); DrawTextBorderOuter(*windowId, 0x001, 0x0F); @@ -689,19 +671,15 @@ s8 mevent_message_print_and_prompt_yes_no(u8 * textState, u16 * windowId, bool8 case 1: windowTemplate = sWindowTemplate_YesNoBox; if (yesNoBoxPlacement == 0) - { windowTemplate.tilemapTop = 9; - } else - { windowTemplate.tilemapTop = 15; - } CreateYesNoMenu(&windowTemplate, 10, 14, 0); (*textState)++; break; case 2: input = Menu_ProcessInputNoWrapClearOnChoose(); - if (input == -1 || input == 0 || input == 1) + if (input == MENU_B_PRESSED || input == 0 || input == 1) { *textState = 0; rbox_fill_rectangle(*windowId); @@ -711,16 +689,16 @@ s8 mevent_message_print_and_prompt_yes_no(u8 * textState, u16 * windowId, bool8 return input; } break; - case 0xFF: + case (u8)MENU_B_PRESSED: *textState = 0; rbox_fill_rectangle(*windowId); ClearWindowTilemap(*windowId); CopyWindowToVram(*windowId, 1); RemoveWindow(*windowId); - return -1; + return MENU_B_PRESSED; } - return -2; + return MENU_NOTHING_CHOSEN; } static s32 HandleMysteryGiftListMenu(u8 * textState, u16 * windowId, bool32 cannotToss, bool32 cannotSend) @@ -1237,21 +1215,21 @@ void task00_mystery_gift(u8 taskId) case 0: if (data->source == 1) { - MEvent_CreateTask_CardOrNewsWithFriend(ACTIVITY_WONDER_CARD2); + MEvent_CreateTask_CardOrNewsWithFriend(ACTIVITY_WONDER_CARD); } else if (data->source == 0) { - MEvent_CreateTask_CardOrNewsOverWireless(ACTIVITY_WONDER_CARD2); + MEvent_CreateTask_CardOrNewsOverWireless(ACTIVITY_WONDER_CARD); } break; case 1: if (data->source == 1) { - MEvent_CreateTask_CardOrNewsWithFriend(ACTIVITY_WONDER_NEWS2); + MEvent_CreateTask_CardOrNewsWithFriend(ACTIVITY_WONDER_NEWS); } else if (data->source == 0) { - MEvent_CreateTask_CardOrNewsOverWireless(ACTIVITY_WONDER_NEWS2); + MEvent_CreateTask_CardOrNewsOverWireless(ACTIVITY_WONDER_NEWS); } break; } @@ -1594,10 +1572,10 @@ void task00_mystery_gift(u8 taskId) switch (data->IsCardOrNews) { case 0: - MEvent_CreateTask_Leader(ACTIVITY_WONDER_CARD2); + MEvent_CreateTask_Leader(ACTIVITY_WONDER_CARD); break; case 1: - MEvent_CreateTask_Leader(ACTIVITY_WONDER_NEWS2); + MEvent_CreateTask_Leader(ACTIVITY_WONDER_NEWS); break; } data->source = 1; diff --git a/src/overworld.c b/src/overworld.c index 979ebb74c..154ece042 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -2898,7 +2898,7 @@ bool32 IsSendingKeysOverCable(void) static u32 GetLinkSendQueueLength(void) { if (gWirelessCommType != 0) - return Rfu.sendQueue.count; + return gRfu.sendQueue.count; else return gLink.sendQueue.count; } diff --git a/src/party_menu.c b/src/party_menu.c index 681dc5f93..e657dcf7d 100755 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -3522,7 +3522,7 @@ static void CursorCb_Register(u8 taskId) u16 species = GetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_SPECIES); u8 isEventLegal = GetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_EVENT_LEGAL); - switch (CanRegisterMonForTradingBoard(*(struct GFtgtGnameSub *)GetHostRFUtgtGname(), species2, species, isEventLegal)) + switch (CanRegisterMonForTradingBoard(*(struct RfuGameCompatibilityData *)GetHostRfuGameData(), species2, species, isEventLegal)) { case CANT_REGISTER_MON: StringExpandPlaceholders(gStringVar4, gText_PkmnCantBeTradedNow); @@ -3548,7 +3548,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 isEventLegal = GetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_EVENT_LEGAL); - u32 stringId = GetUnionRoomTradeMessageId(*(struct GFtgtGnameSub *)GetHostRFUtgtGname(), gPartnerTgtGnameSub, species2, gUnionRoomOfferedSpecies, gUnionRoomRequestedMonType, species, isEventLegal); + u32 stringId = GetUnionRoomTradeMessageId(*(struct RfuGameCompatibilityData *)GetHostRfuGameData(), gRfuPartnerCompatibilityData, species2, gUnionRoomOfferedSpecies, gUnionRoomRequestedMonType, species, isEventLegal); if (stringId != UR_TRADE_MSG_NONE) { diff --git a/src/pokemon_jump.c b/src/pokemon_jump.c index 777939f08..361dc278b 100755 --- a/src/pokemon_jump.c +++ b/src/pokemon_jump.c @@ -2202,7 +2202,7 @@ static int GetPlayersAtJumpPeak(void) static bool32 AreLinkQueuesEmpty(void) { - return !Rfu.recvQueue.count && !Rfu.sendQueue.count; + return !gRfu.recvQueue.count && !gRfu.sendQueue.count; } static int GetNumPlayersForBonus(u8 *arg0) diff --git a/src/trade.c b/src/trade.c index f0a31b5cb..0899a6e21 100644 --- a/src/trade.c +++ b/src/trade.c @@ -274,7 +274,7 @@ static bool32 IsLinkTradeTaskFinished(void) { if (gPlayerCurrActivity == ACTIVITY_29) { - if (gRfuSlotStatusNI[sub_800E87C(lman.acceptSlot_flag)]->send.state == 0) + if (gRfuSlotStatusNI[Rfu_GetIndexOfNewestChild(lman.acceptSlot_flag)]->send.state == 0) return TRUE; else return FALSE; @@ -2438,80 +2438,70 @@ static bool32 IsDeoxysOrMewUntradable(u16 species, bool8 isEventLegal) return FALSE; } -int GetUnionRoomTradeMessageId(struct GFtgtGnameSub rfuPlayer, struct GFtgtGnameSub rfuPartner, u16 playerSpecies2, u16 partnerSpecies, u8 requestedType, u16 playerSpecies, u8 isEventLegal) +int GetUnionRoomTradeMessageId(struct RfuGameCompatibilityData player, struct RfuGameCompatibilityData partner, u16 playerSpecies2, u16 partnerSpecies, u8 requestedType, u16 playerSpecies, u8 isEventLegal) { - bool8 playerHasNationalDex = rfuPlayer.hasNationalDex; - bool8 playerIsChampion = rfuPlayer.isChampion; - bool8 partnerHasNationalDex = rfuPartner.hasNationalDex; - bool8 partnerIsChampion = rfuPartner.isChampion; - u8 r1 = rfuPartner.version; + bool8 playerHasNationalDex = player.hasNationalDex; + bool8 playerIsChampion = player.isChampion; + bool8 partnerHasNationalDex = partner.hasNationalDex; + bool8 partnerIsChampion = partner.isChampion; + u8 partnerVersion = partner.version; - if (r1 != VERSION_EMERALD) + // If partner is not using Emerald, both players must be champion + if (partnerVersion != VERSION_EMERALD) { if (!playerIsChampion) - { return UR_TRADE_MSG_CANT_TRADE_WITH_PARTNER_1; - } else if (!partnerIsChampion) - { return UR_TRADE_MSG_CANT_TRADE_WITH_PARTNER_2; - } } + // Cannot trade illegitimate Deoxys/Mew if (IsDeoxysOrMewUntradable(playerSpecies, isEventLegal)) - { return UR_TRADE_MSG_MON_CANT_BE_TRADED_2; - } if (partnerSpecies == SPECIES_EGG) { + // If partner is trading an Egg then the player must also be trading an Egg if (playerSpecies2 != partnerSpecies) - { return UR_TRADE_MSG_NOT_EGG; - } } else { - if (gBaseStats[playerSpecies2].type1 != requestedType && gBaseStats[playerSpecies2].type2 != requestedType) - { + // Player's Pokémon must be of the type the partner requested + if (gBaseStats[playerSpecies2].type1 != requestedType + && gBaseStats[playerSpecies2].type2 != requestedType) return UR_TRADE_MSG_NOT_MON_PARTNER_WANTS; - } } + // If the player is trading an Egg then the partner must also be trading an Egg + // Odd that this wasn't checked earlier, as by this point we know either the partner doesn't have an Egg or that both do. if (playerSpecies2 == SPECIES_EGG && playerSpecies2 != partnerSpecies) - { return UR_TRADE_MSG_MON_CANT_BE_TRADED_1; - } + // If the player doesn't have the National Dex then Eggs and non-Hoenn Pokémon can't be traded if (!playerHasNationalDex) { if (playerSpecies2 == SPECIES_EGG) - { return UR_TRADE_MSG_EGG_CANT_BE_TRADED; - } if (!IsSpeciesInHoennDex(playerSpecies2)) - { return UR_TRADE_MSG_MON_CANT_BE_TRADED_2; - } if (!IsSpeciesInHoennDex(partnerSpecies)) - { return UR_TRADE_MSG_PARTNERS_MON_CANT_BE_TRADED; - } } + // If the partner doesn't have the National Dex then the player's offer has to be a Hoenn Pokémon if (!partnerHasNationalDex && !IsSpeciesInHoennDex(playerSpecies2)) - { return UR_TRADE_MSG_PARTNER_CANT_ACCEPT_MON; - } + // Trade is allowed return UR_TRADE_MSG_NONE; } -int CanRegisterMonForTradingBoard(struct GFtgtGnameSub rfuPlayer, u16 species2, u16 species, u8 isEventLegal) +int CanRegisterMonForTradingBoard(struct RfuGameCompatibilityData player, u16 species2, u16 species, u8 isEventLegal) { - bool8 hasNationalDex = rfuPlayer.hasNationalDex; + bool8 hasNationalDex = player.hasNationalDex; if (IsDeoxysOrMewUntradable(species, isEventLegal)) return CANT_REGISTER_MON; @@ -2541,9 +2531,7 @@ int CanSpinTradeMon(struct Pokemon *mon, u16 monIdx) { speciesArray[i] = GetMonData(&mon[i], MON_DATA_SPECIES2); if (speciesArray[i] == SPECIES_EGG) - { speciesArray[i] = SPECIES_NONE; - } } versions = 0; @@ -2553,13 +2541,9 @@ int CanSpinTradeMon(struct Pokemon *mon, u16 monIdx) version = gLinkPlayers[i].version & 0xFF; if (version == VERSION_FIRE_RED || version == VERSION_LEAF_GREEN) - { versions = 0; - } else - { versions |= 1; - } } for (i = 0; i < GetLinkPlayerCount(); i++) @@ -2590,9 +2574,7 @@ int CanSpinTradeMon(struct Pokemon *mon, u16 monIdx) for (i = 0; i < gPlayerPartyCount; i++) { if (monIdx != i) - { numMonsLeft += speciesArray[i]; - } } if (!numMonsLeft) diff --git a/src/union_room.c b/src/union_room.c index 46957db5e..eae754513 100644 --- a/src/union_room.c +++ b/src/union_room.c @@ -174,12 +174,37 @@ enum { LG_STATE_SHUTDOWN = 23, }; +// Color types for PrintUnionRoomText +enum { + UR_COLOR_DEFAULT, + UR_COLOR_RED, + UR_COLOR_GREEN, + UR_COLOR_WHITE, + UR_COLOR_CANCEL, + UR_COLOR_TRADE_BOARD_SELF, + UR_COLOR_TRADE_BOARD_OTHER, +}; + +// Return values for HandlePlayerListUpdate +enum { + PLIST_0, + PLIST_1, + PLIST_2, + PLIST_3, + PLIST_4, +}; + 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 union +{ + struct WirelessLink_Leader *leader; + struct WirelessLink_Group *group; + struct WirelessLink_URoom *uRoom; +} sWirelessLinkMain = {}; static EWRAM_DATA u32 sUnused = 0; -EWRAM_DATA struct GFtgtGnameSub gPartnerTgtGnameSub = {}; +EWRAM_DATA struct RfuGameCompatibilityData gRfuPartnerCompatibilityData = {}; EWRAM_DATA u16 gUnionRoomOfferedSpecies = 0; EWRAM_DATA u8 gUnionRoomRequestedMonType = 0; static EWRAM_DATA struct UnionRoomTrade sUnionRoomTrade = {}; @@ -188,7 +213,7 @@ static struct WirelessLink_Leader *sLeader; static struct WirelessLink_Group *sGroup; static struct WirelessLink_URoom *sURoom; -static void UR_AddTextPrinterParameterized(u8, u8, const u8 *, u8, u8, u8); +static void PrintUnionRoomText(u8, u8, const u8 *, u8, u8, u8); static u16 ReadAsU16(const u8 *); static void Task_TryBecomeLinkLeader(u8); static void Task_TryJoinLinkGroup(u8); @@ -197,64 +222,64 @@ static void Task_MEvent_Leader(u8); static void Task_CardOrNewsWithFriend(u8); static void Task_CardOrNewsOverWireless(u8); static void Task_RunUnionRoom(u8); -static void ClearUnkStruct_x1CArray(struct UnkStruct_Main4 *, u8); -static void ClearUnkStruct_x20Array(struct UnkStruct_x20 *, u8); -static u8 CreateTask_ListenForPartnersWithCompatibleSerialNos(struct UnkStruct_Main4 *, u32); -static u8 CreateTask_ListenForPartnersWithSerial7F7D(struct UnkStruct_Main4 *, u32 ); +static void ClearIncomingPlayerList(struct RfuIncomingPlayerList *, u8); +static void ClearRfuPlayerList(struct RfuPlayer *, u8); +static u8 CreateTask_ListenForCompatiblePartners(struct RfuIncomingPlayerList *, u32); +static u8 CreateTask_ListenForWonderDistributor(struct RfuIncomingPlayerList *, u32 ); static bool8 PrintOnTextbox(u8 *, const u8 *); static bool8 Leader_SetStateIfMemberListChanged(struct WirelessLink_Leader *, u32, u32); -static u8 sub_8013398(struct UnkStruct_Main0 *); +static u8 LeaderPrunePlayerList(struct RfuPlayerList *); static s8 UnionRoomHandleYesNo(u8 *, bool32); -static void IntlConvPartnerUname7(u8 *, struct UnkStruct_x20 *); +static void CopyAndTranslatePlayerName(u8 *, struct RfuPlayer *); static void Leader_DestroyResources(struct WirelessLink_Leader *); static void CreateTask_RunScriptAndFadeToActivity(void); -static u8 LeaderUpdateGroupMembership(struct UnkStruct_Main0 *); -static void PrintGroupMemberCandidateOnWindowWithColor(u8, u8, u8, struct UnkStruct_x20 *, u8, u8 ); -static u32 Findx20Inx1CArray(struct UnkStruct_x20 *, struct UnkStruct_x1C *); -static u8 Appendx1Ctox20(struct UnkStruct_x20 *, struct UnkStruct_x1C *, u8); +static u8 LeaderUpdateGroupMembership(struct RfuPlayerList *); +static void PrintGroupCandidateOnWindow(u8, u8, u8, struct RfuPlayer *, u8, u8 ); +static u32 GetNewIncomingPlayerId(struct RfuPlayer *, struct RfuIncomingPlayer *); +static u8 TryAddIncomingPlayerToList(struct RfuPlayer *, struct RfuIncomingPlayer *, u8); static u8 GetNewLeaderCandidate(void); static u32 IsTryingToTradeAcrossVersionTooSoon(struct WirelessLink_Group *, s32); static void AskToJoinRfuGroup(struct WirelessLink_Group *, s32); static void JoinGroup_EnableScriptContexts(void); -static void PrintUnionRoomGroupOnWindow(u8, u8, u8, struct UnkStruct_x20 *, u8, u8); -static bool32 AreUnionRoomPlayerGnamesDifferent(struct WirelessGnameUnamePair *, struct WirelessGnameUnamePair *); +static void PrintGroupMemberOnWindow(u8, u8, u8, struct RfuPlayer *, u8, u8); +static bool32 ArePlayerDataDifferent(struct RfuPlayerData *, struct RfuPlayerData *); static u32 GetPartyPositionOfRegisteredMon(struct UnionRoomTrade *, u8); static void ResetUnionRoomTrade(struct UnionRoomTrade *); static void CreateTask_StartActivity(void); -static bool32 HasWonderCardOrNewsByLinkGroup(struct GFtgtGname *, s16); -static u8 CreateTask_SearchForChildOrParent(struct UnkStruct_Main4 *, struct UnkStruct_Main4 *, u32); +static bool32 HasWonderCardOrNewsByLinkGroup(struct RfuGameData *, s16); +static u8 CreateTask_SearchForChildOrParent(struct RfuIncomingPlayerList *, struct RfuIncomingPlayerList *, u32); static bool32 RegisterTradeMonAndGetIsEgg(u32, struct UnionRoomTrade *); static void RegisterTradeMon(u32, struct UnionRoomTrade *); -static void UR_EnableScriptContext2AndFreezeObjectEvents(void); +static void StartScriptInteraction(void); static bool32 IsPlayerFacingTradingBoard(void); static u8 HandlePlayerListUpdate(void); static bool32 PollPartnerYesNoResponse(struct WirelessLink_URoom *); static void ReceiveUnionRoomActivityPacket(struct WirelessLink_URoom *); -static u8 GetActivePartnerSpriteGenderParam(struct WirelessLink_URoom *); -static bool32 UnionRoom_HandleContactFromOtherPlayer(struct WirelessLink_URoom *); -static bool32 UR_RunTextPrinters_CheckPrinter0Active(void); -static s32 GetUnionRoomPlayerGender(s32, struct UnkStruct_Main0 *); -static s32 UnionRoomGetPlayerInteractionResponse(struct UnkStruct_Main0 *, u8, u8, u32); +static u8 GetActivePartnersInfo(struct WirelessLink_URoom *); +static bool32 HandleContactFromOtherPlayer(struct WirelessLink_URoom *); +static bool32 UR_RunTextPrinters(void); +static s32 GetUnionRoomPlayerGender(s32, struct RfuPlayerList *); +static s32 UnionRoomGetPlayerInteractionResponse(struct RfuPlayerList *, u8, u8, u32); static void HandleCancelActivity(bool32); static s32 ListMenuHandler_AllItemsAvailable(u8 *, u8 *, u8 *, const struct WindowTemplate *, const struct ListMenuTemplate *); -static s32 TradeBoardMenuHandler(u8 *, u8 *, u8 *, u8 *, const struct WindowTemplate *, const struct ListMenuTemplate *, struct UnkStruct_Main0 *); -static s32 GetIndexOfNthTradeBoardOffer(struct UnkStruct_x20 *, s32); +static s32 TradeBoardMenuHandler(u8 *, u8 *, u8 *, u8 *, const struct WindowTemplate *, const struct ListMenuTemplate *, struct RfuPlayerList *); +static s32 GetIndexOfNthTradeBoardOffer(struct RfuPlayer *, s32); static bool32 HasAtLeastTwoMonsOfLevel30OrLower(void); static u32 GetResponseIdx_InviteToURoomActivity(s32); static void ViewURoomPartnerTrainerCard(u8 *, struct WirelessLink_URoom *, bool8); static void GetURoomActivityRejectMsg(u8 *, s32, u32); -static u32 ConvPartnerUnameAndGetWhetherMetAlready(struct UnkStruct_x20 *); +static u32 ConvPartnerUnameAndGetWhetherMetAlready(struct RfuPlayer *); static void GetURoomActivityStartMsg(u8 *, u8); static void UR_ClearBg0(void); static s32 IsRequestedTypeOrEggInPlayerParty(u32, u32); static bool32 UR_PrintFieldMessage(const u8 *); static s32 GetChatLeaderActionRequestMessage(u8 *, u32, u16 *, struct WirelessLink_URoom *); static void Task_InitUnionRoom(u8 taskId); -static bool8 AreGnameUnameDifferent(struct WirelessGnameUnamePair*, const struct WirelessGnameUnamePair*); -static void ItemPrintFunc_PossibleGroupMembers(u8 windowId, u32 id, u8 y); -static void ListMenuItemPrintFunc_UnionRoomGroups(u8 windowId, u32 id, u8 y); -static void TradeBoardListMenuItemPrintFunc(u8 windowId, u32 id, u8 y); -static void ItemPrintFunc_EmptyList(u8 windowId, u32 id, u8 y); +static bool8 ArePlayersDifferent(struct RfuPlayerData*, const struct RfuPlayerData*); +static void ItemPrintFunc_PossibleGroupMembers(u8, u32, u8); +static void ListMenuItemPrintFunc_UnionRoomGroups(u8, u32, u8); +static void TradeBoardListMenuItemPrintFunc(u8, u32, u8); +static void ItemPrintFunc_EmptyList(u8, u32, u8); #include "data/union_room.h" @@ -264,19 +289,19 @@ static void PrintNumPlayersWaitingForMsg(u8 windowId, u8 capacityCode, u8 string switch (capacityCode << 8) { case LINK_GROUP_CAPACITY(0, 2): - UR_AddTextPrinterParameterized(windowId, 1, sPlayersNeededOrModeTexts[0][stringId - 1], 0, 1, UR_COLOR_DKE_WHT_LTE); + PrintUnionRoomText(windowId, 1, sPlayersNeededOrModeTexts[0][stringId - 1], 0, 1, UR_COLOR_DEFAULT); break; case LINK_GROUP_CAPACITY(0, 4): - UR_AddTextPrinterParameterized(windowId, 1, sPlayersNeededOrModeTexts[1][stringId - 1], 0, 1, UR_COLOR_DKE_WHT_LTE); + PrintUnionRoomText(windowId, 1, sPlayersNeededOrModeTexts[1][stringId - 1], 0, 1, UR_COLOR_DEFAULT); break; case LINK_GROUP_CAPACITY(2, 5): - UR_AddTextPrinterParameterized(windowId, 1, sPlayersNeededOrModeTexts[2][stringId - 1], 0, 1, UR_COLOR_DKE_WHT_LTE); + PrintUnionRoomText(windowId, 1, sPlayersNeededOrModeTexts[2][stringId - 1], 0, 1, UR_COLOR_DEFAULT); break; case LINK_GROUP_CAPACITY(3, 5): - UR_AddTextPrinterParameterized(windowId, 1, sPlayersNeededOrModeTexts[3][stringId - 1], 0, 1, UR_COLOR_DKE_WHT_LTE); + PrintUnionRoomText(windowId, 1, sPlayersNeededOrModeTexts[3][stringId - 1], 0, 1, UR_COLOR_DEFAULT); break; case LINK_GROUP_CAPACITY(2, 4): - UR_AddTextPrinterParameterized(windowId, 1, sPlayersNeededOrModeTexts[4][stringId - 1], 0, 1, UR_COLOR_DKE_WHT_LTE); + PrintUnionRoomText(windowId, 1, sPlayersNeededOrModeTexts[4][stringId - 1], 0, 1, UR_COLOR_DEFAULT); break; } @@ -288,13 +313,13 @@ static void PrintPlayerNameAndIdOnWindow(u8 windowId) u8 text[30]; u8 *txtPtr; - UR_AddTextPrinterParameterized(windowId, 1, gSaveBlock2Ptr->playerName, 0, 1, UR_COLOR_DKE_WHT_LTE); + PrintUnionRoomText(windowId, 1, gSaveBlock2Ptr->playerName, 0, 1, UR_COLOR_DEFAULT); txtPtr = StringCopy(text, sText_ID); ConvertIntToDecimalStringN(txtPtr, ReadAsU16(gSaveBlock2Ptr->playerTrainerId), STR_CONV_MODE_LEADING_ZEROS, 5); - UR_AddTextPrinterParameterized(windowId, 1, text, 0, 0x11, UR_COLOR_DKE_WHT_LTE); + PrintUnionRoomText(windowId, 1, text, 0, 17, UR_COLOR_DEFAULT); } -static void StringExpandPlaceholders_AwaitingCommFromAnother(u8 *dst, u8 caseId) +static void GetAwaitingCommunicationText(u8 *dst, u8 caseId) { switch (caseId) { @@ -309,8 +334,8 @@ static void StringExpandPlaceholders_AwaitingCommFromAnother(u8 *dst, u8 caseId) case ACTIVITY_BATTLE_TOWER_OPEN: case ACTIVITY_RECORD_CORNER: case ACTIVITY_BERRY_BLENDER: - case ACTIVITY_WONDER_CARD2: - case ACTIVITY_WONDER_NEWS2: + case ACTIVITY_WONDER_CARD: + case ACTIVITY_WONDER_NEWS: case ACTIVITY_CONTEST_COOL: case ACTIVITY_CONTEST_BEAUTY: case ACTIVITY_CONTEST_CUTE: @@ -373,24 +398,24 @@ static void Task_TryBecomeLinkLeader(u8 taskId) gSpecialVar_0x8004++; gPlayerCurrActivity = sLinkGroupToActivityAndCapacity[gSpecialVar_0x8004]; sPlayerActivityGroupSize = sLinkGroupToActivityAndCapacity[gSpecialVar_0x8004] >> 8; - SetHostRFUtgtGname(gPlayerCurrActivity, 0, 0); + SetHostRfuGameData(gPlayerCurrActivity, 0, FALSE); SetWirelessCommType1(); OpenLink(); InitializeRfuLinkManager_LinkLeader(GROUP_MAX(sPlayerActivityGroupSize)); data->state = LL_STATE_INIT2; break; case LL_STATE_INIT2: - 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].timeoutCounter = 0; - data->field_0->arr[0].groupScheduledAnim = UNION_ROOM_SPAWN_IN; - data->field_0->arr[0].useRedText = FALSE; - data->field_0->arr[0].field_1B = 0; - data->listenTaskId = CreateTask_ListenForPartnersWithCompatibleSerialNos(data->field_4, 0xFF); + data->incomingPlayerList = AllocZeroed(RFU_CHILD_MAX * sizeof(struct RfuIncomingPlayer)); + data->playerList = AllocZeroed(MAX_RFU_PLAYERS * sizeof(struct RfuPlayer)); + data->playerListBackup = AllocZeroed(MAX_RFU_PLAYERS * sizeof(struct RfuPlayer)); + ClearIncomingPlayerList(data->incomingPlayerList, RFU_CHILD_MAX); + ClearRfuPlayerList(data->playerList->players, MAX_RFU_PLAYERS); + CopyHostRfuGameDataAndUsername(&data->playerList->players[0].rfu.data, data->playerList->players[0].rfu.name); + data->playerList->players[0].timeoutCounter = 0; + data->playerList->players[0].groupScheduledAnim = UNION_ROOM_SPAWN_IN; + data->playerList->players[0].useRedText = FALSE; + data->playerList->players[0].field_1B = 0; + data->listenTaskId = CreateTask_ListenForCompatiblePartners(data->incomingPlayerList, 0xFF); data->bButtonCancelWindowId = AddWindow(&sWindowTemplate_BButtonCancel); switch (GROUP_MAX(sPlayerActivityGroupSize)) { @@ -406,7 +431,7 @@ static void Task_TryBecomeLinkLeader(u8 taskId) data->nPlayerModeWindowId = AddWindow(&sWindowTemplate_NumPlayerMode); FillWindowPixelBuffer(data->bButtonCancelWindowId, PIXEL_FILL(2)); - UR_AddTextPrinterParameterized(data->bButtonCancelWindowId, 0, sText_BButtonCancel, 8, 1, 4); + PrintUnionRoomText(data->bButtonCancelWindowId, 0, sText_BButtonCancel, 8, 1, UR_COLOR_CANCEL); PutWindowTilemap(data->bButtonCancelWindowId); CopyWindowToVram(data->bButtonCancelWindowId, 2); @@ -434,7 +459,7 @@ static void Task_TryBecomeLinkLeader(u8 taskId) } else { - StringExpandPlaceholders_AwaitingCommFromAnother(gStringVar4, gPlayerCurrActivity); + GetAwaitingCommunicationText(gStringVar4, gPlayerCurrActivity); } PrintNumPlayersWaitingForMsg(data->nPlayerModeWindowId, sPlayerActivityGroupSize, data->playerCount); @@ -475,7 +500,7 @@ static void Task_TryBecomeLinkLeader(u8 taskId) if (!RfuTryDisconnectLeavingChildren()) { data->state = LL_STATE_AWAIT_PLAYERS; - data->playerCount = sub_8013398(data->field_0); + data->playerCount = LeaderPrunePlayerList(data->playerList); } break; case LL_STATE_MEMBER_LEFT: @@ -489,7 +514,7 @@ static void Task_TryBecomeLinkLeader(u8 taskId) #endif if (PrintOnTextbox(&data->textState, sPlayerUnavailableTexts[id])) { - data->playerCount = sub_8013398(data->field_0); + data->playerCount = LeaderPrunePlayerList(data->playerList); RedrawListMenu(data->listTaskId); data->state = LL_STATE_GET_AWAITING_PLAYERS_TEXT; } @@ -508,19 +533,19 @@ static void Task_TryBecomeLinkLeader(u8 taskId) } break; case LL_STATE_ACCEPT_NEW_MEMBER_PROMPT_HANDLE_INPUT: - switch (UnionRoomHandleYesNo(&data->textState, HasTrainerLeftPartnersList(ReadAsU16(data->field_0->arr[data->playerCount].gname_uname.gname.unk_00.playerTrainerId), data->field_0->arr[data->playerCount].gname_uname.playerName))) + switch (UnionRoomHandleYesNo(&data->textState, HasTrainerLeftPartnersList(ReadAsU16(data->playerList->players[data->playerCount].rfu.data.compatibility.playerTrainerId), data->playerList->players[data->playerCount].rfu.name))) { case 0: // YES LoadWirelessStatusIndicatorSpriteGfx(); CreateWirelessStatusIndicatorSprite(0, 0); data->joinRequestAnswer = RFU_STATUS_JOIN_GROUP_OK; - SendRfuStatusToPartner(data->joinRequestAnswer, ReadAsU16(data->field_0->arr[data->playerCount].gname_uname.gname.unk_00.playerTrainerId), data->field_0->arr[data->playerCount].gname_uname.playerName); + SendRfuStatusToPartner(data->joinRequestAnswer, ReadAsU16(data->playerList->players[data->playerCount].rfu.data.compatibility.playerTrainerId), data->playerList->players[data->playerCount].rfu.name); data->state = LL_STATE_UPDATE_AFTER_JOIN_REQUEST; break; case 1: // NO - case -1: + case MENU_B_PRESSED: data->joinRequestAnswer = RFU_STATUS_JOIN_GROUP_NO; - SendRfuStatusToPartner(data->joinRequestAnswer, ReadAsU16(data->field_0->arr[data->playerCount].gname_uname.gname.unk_00.playerTrainerId), data->field_0->arr[data->playerCount].gname_uname.playerName); + SendRfuStatusToPartner(data->joinRequestAnswer, ReadAsU16(data->playerList->players[data->playerCount].rfu.data.compatibility.playerTrainerId), data->playerList->players[data->playerCount].rfu.name); data->state = LL_STATE_UPDATE_AFTER_JOIN_REQUEST; break; case -3: @@ -529,23 +554,23 @@ static void Task_TryBecomeLinkLeader(u8 taskId) } break; case LL_STATE_UPDATE_AFTER_JOIN_REQUEST: - val = WaitSendRfuStatusToPartner(ReadAsU16(data->field_0->arr[data->playerCount].gname_uname.gname.unk_00.playerTrainerId), data->field_0->arr[data->playerCount].gname_uname.playerName); + val = WaitSendRfuStatusToPartner(ReadAsU16(data->playerList->players[data->playerCount].rfu.data.compatibility.playerTrainerId), data->playerList->players[data->playerCount].rfu.name); if (val == 1) // Send complete { if (data->joinRequestAnswer == RFU_STATUS_JOIN_GROUP_OK) { - data->field_0->arr[data->playerCount].field_1B = 0; + data->playerList->players[data->playerCount].field_1B = 0; RedrawListMenu(data->listTaskId); data->playerCount++; if (data->playerCount == GROUP_MAX(sPlayerActivityGroupSize)) { - if (GROUP_MIN2(sPlayerActivityGroupSize) != 0 || data->playerCount == 4) + if (GROUP_MIN2(sPlayerActivityGroupSize) != 0 || data->playerCount == RFU_CHILD_MAX) { data->state = LL_STATE_MEMBERS_OK_PROMPT; } else { - IntlConvPartnerUname7(gStringVar1, &data->field_0->arr[data->playerCount - 1]); + CopyAndTranslatePlayerName(gStringVar1, &data->playerList->players[data->playerCount - 1]); StringExpandPlaceholders(gStringVar4, sText_AnOKWasSentToPlayer); data->state = LL_STATE_ACCEPTED_FINAL_MEMBER; } @@ -560,9 +585,9 @@ static void Task_TryBecomeLinkLeader(u8 taskId) } else // Member disconnected { - 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); + RequestDisconnectSlotByTrainerNameAndId(data->playerList->players[data->playerCount].rfu.name, ReadAsU16(data->playerList->players[data->playerCount].rfu.data.compatibility.playerTrainerId)); + data->playerList->players[data->playerCount].groupScheduledAnim = UNION_ROOM_SPAWN_NONE; + LeaderPrunePlayerList(data->playerList); RedrawListMenu(data->listTaskId); data->state = LL_STATE_GET_AWAITING_PLAYERS_TEXT; } @@ -594,7 +619,7 @@ static void Task_TryBecomeLinkLeader(u8 taskId) data->state = LL_STATE_CONFIRMED_MEMBERS; break; case 1: // NO - case -1: + case MENU_B_PRESSED: if (GROUP_MIN2(sPlayerActivityGroupSize) != 0) data->state = LL_STATE_CANCEL_WITH_MSG; else @@ -613,7 +638,7 @@ static void Task_TryBecomeLinkLeader(u8 taskId) data->state = LL_STATE_SHUTDOWN_AND_FAIL; break; case 1: // NO - case -1: + case MENU_B_PRESSED: if (GROUP_MIN2(sPlayerActivityGroupSize) != 0) data->state = LL_STATE_MEMBERS_OK_PROMPT; else if (data->playerCount == GROUP_MAX(sPlayerActivityGroupSize)) @@ -704,9 +729,9 @@ static void Leader_DestroyResources(struct WirelessLink_Leader *data) RemoveWindow(data->bButtonCancelWindowId); DestroyTask(data->listenTaskId); - Free(data->field_8); - Free(data->field_0); - Free(data->field_4); + Free(data->playerListBackup); + Free(data->playerList); + Free(data->incomingPlayerList); } static void Leader_GetAcceptNewMemberPrompt(u8 *dst, u8 caseId) @@ -720,8 +745,8 @@ static void Leader_GetAcceptNewMemberPrompt(u8 *dst, u8 caseId) case ACTIVITY_BATTLE_TOWER: StringExpandPlaceholders(dst, sText_PlayerContactedYouForXAccept); break; - case ACTIVITY_WONDER_CARD2: - case ACTIVITY_WONDER_NEWS2: + case ACTIVITY_WONDER_CARD: + case ACTIVITY_WONDER_NEWS: StringExpandPlaceholders(dst, sText_PlayerContactedYouShareX); break; case ACTIVITY_BATTLE_MULTI: @@ -764,8 +789,8 @@ static void GetYouAskedToJoinGroupPleaseWaitMessage(u8 *dst, u8 caseId) case ACTIVITY_TRADE: case ACTIVITY_BATTLE_TOWER: case ACTIVITY_BATTLE_TOWER_OPEN: - case ACTIVITY_WONDER_CARD2: - case ACTIVITY_WONDER_NEWS2: + case ACTIVITY_WONDER_CARD: + case ACTIVITY_WONDER_NEWS: StringExpandPlaceholders(dst, sText_AwaitingPlayersResponse); break; case ACTIVITY_BATTLE_MULTI: @@ -793,8 +818,8 @@ static void GetGroupLeaderSentAnOKMessage(u8 *dst, u8 caseId) case ACTIVITY_TRADE: case ACTIVITY_BATTLE_TOWER: case ACTIVITY_BATTLE_TOWER_OPEN: - case ACTIVITY_WONDER_CARD2: - case ACTIVITY_WONDER_NEWS2: + case ACTIVITY_WONDER_CARD: + case ACTIVITY_WONDER_NEWS: StringExpandPlaceholders(dst, sText_PlayerSentBackOK); break; case ACTIVITY_BATTLE_MULTI: @@ -815,12 +840,12 @@ static void GetGroupLeaderSentAnOKMessage(u8 *dst, u8 caseId) static bool8 Leader_SetStateIfMemberListChanged(struct WirelessLink_Leader *data, u32 joinedState, u32 droppedState) { - switch (LeaderUpdateGroupMembership(data->field_0)) + switch (LeaderUpdateGroupMembership(data->playerList)) { case UNION_ROOM_SPAWN_IN: PlaySE(SE_PC_LOGIN); RedrawListMenu(data->listTaskId); - IntlConvPartnerUname7(gStringVar2, &data->field_0->arr[data->playerCount]); + CopyAndTranslatePlayerName(gStringVar2, &data->playerList->players[data->playerCount]); Leader_GetAcceptNewMemberPrompt(gStringVar4, gPlayerCurrActivity); data->state = joinedState; break; @@ -837,23 +862,23 @@ static bool8 Leader_SetStateIfMemberListChanged(struct WirelessLink_Leader *data static void ItemPrintFunc_PossibleGroupMembers(u8 windowId, u32 id, u8 y) { struct WirelessLink_Leader *data = sWirelessLinkMain.leader; - u8 colorIdx = UR_COLOR_DKE_WHT_LTE; + u8 colorIdx = UR_COLOR_DEFAULT; - switch (data->field_0->arr[id].groupScheduledAnim) + switch (data->playerList->players[id].groupScheduledAnim) { case UNION_ROOM_SPAWN_IN: - if (data->field_0->arr[id].field_1B != 0) - colorIdx = UR_COLOR_GRN_WHT_LTG; + if (data->playerList->players[id].field_1B != 0) + colorIdx = UR_COLOR_GREEN; break; case UNION_ROOM_SPAWN_OUT: - colorIdx = UR_COLOR_RED_WHT_LTR; + colorIdx = UR_COLOR_RED; break; } - PrintGroupMemberCandidateOnWindowWithColor(windowId, 0, y, &data->field_0->arr[id], colorIdx, id); + PrintGroupCandidateOnWindow(windowId, 0, y, &data->playerList->players[id], colorIdx, id); } -static u8 LeaderUpdateGroupMembership(struct UnkStruct_Main0 *arg0) +static u8 LeaderUpdateGroupMembership(struct RfuPlayerList *list) { struct WirelessLink_Leader *data = sWirelessLinkMain.leader; u8 ret = UNION_ROOM_SPAWN_NONE; @@ -862,31 +887,33 @@ static u8 LeaderUpdateGroupMembership(struct UnkStruct_Main0 *arg0) for (i = 1; i < MAX_RFU_PLAYERS; i++) { - u16 var = data->field_0->arr[i].groupScheduledAnim; + u16 var = data->playerList->players[i].groupScheduledAnim; if (var == UNION_ROOM_SPAWN_IN) { - id = Findx20Inx1CArray(&data->field_0->arr[i], data->field_4->arr); + id = GetNewIncomingPlayerId(&data->playerList->players[i], data->incomingPlayerList->players); if (id != 0xFF) { - data->field_0->arr[i].gname_uname = data->field_4->arr[id].gname_uname; - data->field_0->arr[i].timeoutCounter = 1; + // New incoming player + data->playerList->players[i].rfu = data->incomingPlayerList->players[id].rfu; + data->playerList->players[i].timeoutCounter = 1; } else { - data->field_0->arr[i].groupScheduledAnim = UNION_ROOM_SPAWN_OUT; + // No new incoming player + data->playerList->players[i].groupScheduledAnim = UNION_ROOM_SPAWN_OUT; ret = UNION_ROOM_SPAWN_OUT; } } } for (id = 0; id < RFU_CHILD_MAX; id++) - Appendx1Ctox20(data->field_0->arr, &data->field_4->arr[id], MAX_RFU_PLAYERS); + TryAddIncomingPlayerToList(data->playerList->players, &data->incomingPlayerList->players[id], MAX_RFU_PLAYERS); if (ret != UNION_ROOM_SPAWN_OUT) { for (id = 0; id < MAX_RFU_PLAYERS; id++) { - if (data->field_0->arr[id].field_1B != 0) + if (data->playerList->players[id].field_1B != 0) ret = UNION_ROOM_SPAWN_IN; } } @@ -894,7 +921,7 @@ static u8 LeaderUpdateGroupMembership(struct UnkStruct_Main0 *arg0) return ret; } -static u8 sub_8013398(struct UnkStruct_Main0 *arg0) +static u8 LeaderPrunePlayerList(struct RfuPlayerList *list) { struct WirelessLink_Leader *data = sWirelessLinkMain.leader; u8 copiedCount; @@ -902,14 +929,14 @@ static u8 sub_8013398(struct UnkStruct_Main0 *arg0) u8 playerCount; for (i = 0; i < MAX_RFU_PLAYERS; i++) - data->field_8->arr[i] = data->field_0->arr[i]; + data->playerListBackup->players[i] = data->playerList->players[i]; copiedCount = 0; for (i = 0; i < MAX_RFU_PLAYERS; i++) { - if (data->field_8->arr[i].groupScheduledAnim == UNION_ROOM_SPAWN_IN) + if (data->playerListBackup->players[i].groupScheduledAnim == UNION_ROOM_SPAWN_IN) { - data->field_0->arr[copiedCount] = data->field_8->arr[i]; + data->playerList->players[copiedCount] = data->playerListBackup->players[i]; copiedCount++; } } @@ -917,18 +944,18 @@ static u8 sub_8013398(struct UnkStruct_Main0 *arg0) playerCount = copiedCount; for (; copiedCount < MAX_RFU_PLAYERS; copiedCount++) { - data->field_0->arr[copiedCount].gname_uname = sWirelessGnameUnamePair_Dummy; - data->field_0->arr[copiedCount].timeoutCounter = 0; - data->field_0->arr[copiedCount].groupScheduledAnim = UNION_ROOM_SPAWN_NONE; - data->field_0->arr[copiedCount].useRedText = FALSE; - data->field_0->arr[copiedCount].field_1B = 0; + data->playerList->players[copiedCount].rfu = sUnionRoomPlayer_DummyRfu; + data->playerList->players[copiedCount].timeoutCounter = 0; + data->playerList->players[copiedCount].groupScheduledAnim = UNION_ROOM_SPAWN_NONE; + data->playerList->players[copiedCount].useRedText = FALSE; + data->playerList->players[copiedCount].field_1B = 0; } for (i = 0; i < MAX_RFU_PLAYERS; i++) { - if (data->field_0->arr[i].groupScheduledAnim != UNION_ROOM_SPAWN_IN) + if (data->playerList->players[i].groupScheduledAnim != UNION_ROOM_SPAWN_IN) continue; - if (data->field_0->arr[i].field_1B != 64) + if (data->playerList->players[i].field_1B != 64) continue; playerCount = i; @@ -963,12 +990,12 @@ static void Task_TryJoinLinkGroup(u8 taskId) if (gSpecialVar_0x8004 == LINK_GROUP_BATTLE_TOWER && gSaveBlock2Ptr->frontier.lvlMode == FRONTIER_LVL_OPEN) gSpecialVar_0x8004++; gPlayerCurrActivity = sLinkGroupToURoomActivity[gSpecialVar_0x8004]; - SetHostRFUtgtGname(gPlayerCurrActivity, 0, 0); + SetHostRfuGameData(gPlayerCurrActivity, 0, FALSE); SetWirelessCommType1(); OpenLink(); InitializeRfuLinkManager_JoinGroup(); - data->field_4 = AllocZeroed(4 * sizeof(struct UnkStruct_x1C)); - data->field_0 = AllocZeroed(16 * sizeof(struct UnkStruct_x20)); + data->incomingPlayerList = AllocZeroed(RFU_CHILD_MAX * sizeof(struct RfuIncomingPlayer)); + data->playerList = AllocZeroed(MAX_RFU_PLAYER_LIST_SIZE * sizeof(struct RfuPlayer)); data->state = LG_STATE_CHOOSE_LEADER_MSG; break; case LG_STATE_CHOOSE_LEADER_MSG: @@ -976,15 +1003,15 @@ static void Task_TryJoinLinkGroup(u8 taskId) data->state = LG_STATE_INIT_WINDOWS; break; case LG_STATE_INIT_WINDOWS: - ClearUnkStruct_x1CArray(data->field_4, 4); - ClearUnkStruct_x20Array(data->field_0->arr, 16); - data->listenTaskId = CreateTask_ListenForPartnersWithCompatibleSerialNos(data->field_4, gSpecialVar_0x8004); + ClearIncomingPlayerList(data->incomingPlayerList, RFU_CHILD_MAX); + ClearRfuPlayerList(data->playerList->players, MAX_RFU_PLAYER_LIST_SIZE); + data->listenTaskId = CreateTask_ListenForCompatiblePartners(data->incomingPlayerList, gSpecialVar_0x8004); data->bButtonCancelWindowId = AddWindow(&sWindowTemplate_BButtonCancel); - data->listWindowId = AddWindow(&gUnknown_082F0174); - data->playerNameAndIdWindowId = AddWindow(&gUnknown_082F017C); + data->listWindowId = AddWindow(&sWindowTemplate_GroupList); + data->playerNameAndIdWindowId = AddWindow(&sWindowTemplate_PlayerNameAndId); FillWindowPixelBuffer(data->bButtonCancelWindowId, PIXEL_FILL(2)); - UR_AddTextPrinterParameterized(data->bButtonCancelWindowId, 0, sText_ChooseJoinCancel, 8, 1, 4); + PrintUnionRoomText(data->bButtonCancelWindowId, 0, sText_ChooseJoinCancel, 8, 1, UR_COLOR_CANCEL); PutWindowTilemap(data->bButtonCancelWindowId); CopyWindowToVram(data->bButtonCancelWindowId, 2); @@ -1012,12 +1039,12 @@ static void Task_TryJoinLinkGroup(u8 taskId) break; case 0: id = ListMenu_ProcessInput(data->listTaskId); - if (JOY_NEW(A_BUTTON) && id != -1) + if (JOY_NEW(A_BUTTON) && id != MENU_B_PRESSED) { // this unused variable along with the assignment is needed to match - u32 activity = data->field_0->arr[id].gname_uname.gname.activity; + u32 activity = data->playerList->players[id].rfu.data.activity; - if (data->field_0->arr[id].groupScheduledAnim == UNION_ROOM_SPAWN_IN && !data->field_0->arr[id].gname_uname.gname.started) + if (data->playerList->players[id].groupScheduledAnim == UNION_ROOM_SPAWN_IN && !data->playerList->players[id].rfu.data.startedActivity) { u32 readyStatus = IsTryingToTradeAcrossVersionTooSoon(data, id); if (readyStatus == UR_TRADE_READY) @@ -1053,14 +1080,14 @@ static void Task_TryJoinLinkGroup(u8 taskId) GetYouAskedToJoinGroupPleaseWaitMessage(gStringVar4, gPlayerCurrActivity); if (PrintOnTextbox(&data->textState, gStringVar4)) { - IntlConvPartnerUname7(gStringVar1, &data->field_0->arr[data->leaderId]); + CopyAndTranslatePlayerName(gStringVar1, &data->playerList->players[data->leaderId]); data->state = LG_STATE_MAIN; } break; case LG_STATE_MAIN: if (gReceivedRemoteLinkPlayers) { - gPlayerCurrActivity = data->field_0->arr[data->leaderId].gname_uname.gname.activity; + gPlayerCurrActivity = data->playerList->players[data->leaderId].rfu.data.activity; RfuSetStatus(RFU_STATUS_OK, 0); switch (gPlayerCurrActivity) { @@ -1077,8 +1104,8 @@ static void Task_TryJoinLinkGroup(u8 taskId) case ACTIVITY_BATTLE_TOWER_OPEN: case ACTIVITY_RECORD_CORNER: case ACTIVITY_BERRY_BLENDER: - case ACTIVITY_WONDER_CARD2: - case ACTIVITY_WONDER_NEWS2: + case ACTIVITY_WONDER_CARD: + case ACTIVITY_WONDER_NEWS: case ACTIVITY_CONTEST_COOL: case ACTIVITY_CONTEST_BEAUTY: case ACTIVITY_CONTEST_CUTE: @@ -1158,7 +1185,7 @@ static void Task_TryJoinLinkGroup(u8 taskId) RedrawListMenu(data->listTaskId); break; case 1: // NO - case -1: + case MENU_B_PRESSED: data->state = LG_STATE_ASK_JOIN_GROUP; RedrawListMenu(data->listTaskId); break; @@ -1187,8 +1214,8 @@ static void Task_TryJoinLinkGroup(u8 taskId) RemoveWindow(data->listWindowId); RemoveWindow(data->bButtonCancelWindowId); DestroyTask(data->listenTaskId); - Free(data->field_0); - Free(data->field_4); + Free(data->playerList); + Free(data->incomingPlayerList); data->state++; break; case LG_STATE_RFU_ERROR_SHUTDOWN: @@ -1236,13 +1263,13 @@ static void Task_TryJoinLinkGroup(u8 taskId) static u32 IsTryingToTradeAcrossVersionTooSoon(struct WirelessLink_Group *data, s32 id) { - struct UnkStruct_x20 *structPtr = &data->field_0->arr[id]; + struct RfuPlayer *partner = &data->playerList->players[id]; - if (gPlayerCurrActivity == ACTIVITY_TRADE && structPtr->gname_uname.gname.unk_00.version != VERSION_EMERALD) + if (gPlayerCurrActivity == ACTIVITY_TRADE && partner->rfu.data.compatibility.version != VERSION_EMERALD) { if (!(gSaveBlock2Ptr->specialSaveWarpFlags & CHAMPION_SAVEWARP)) return UR_TRADE_PLAYER_NOT_READY; - else if (structPtr->gname_uname.gname.unk_00.isChampion) + else if (partner->rfu.data.compatibility.isChampion) return UR_TRADE_READY; } else @@ -1259,9 +1286,9 @@ static void AskToJoinRfuGroup(struct WirelessLink_Group *data, s32 id) LoadWirelessStatusIndicatorSpriteGfx(); CreateWirelessStatusIndicatorSprite(0, 0); RedrawListMenu(data->listTaskId); - IntlConvPartnerUname7(gStringVar1, &data->field_0->arr[data->leaderId]); + CopyAndTranslatePlayerName(gStringVar1, &data->playerList->players[data->leaderId]); UpdateGameData_SetActivity(sLinkGroupToURoomActivity[gSpecialVar_0x8004], 0, TRUE); - CreateTask_RfuReconnectWithParent(data->field_0->arr[data->leaderId].gname_uname.playerName, ReadAsU16(data->field_0->arr[data->leaderId].gname_uname.gname.unk_00.playerTrainerId)); + CreateTask_RfuReconnectWithParent(data->playerList->players[data->leaderId].rfu.name, ReadAsU16(data->playerList->players[data->leaderId].rfu.data.compatibility.playerTrainerId)); } u8 CreateTask_ListenToWireless(void) @@ -1287,19 +1314,19 @@ static void Task_ListenToWireless(u8 taskId) switch (data->state) { case 0: - SetHostRFUtgtGname(0, 0, 0); + SetHostRfuGameData(ACTIVITY_NONE, 0, FALSE); SetWirelessCommType1(); OpenLink(); InitializeRfuLinkManager_JoinGroup(); RfuSetIgnoreError(TRUE); - data->field_4 = AllocZeroed(4 * sizeof(struct UnkStruct_x1C)); - data->field_0 = AllocZeroed(16 * sizeof(struct UnkStruct_x20)); + data->incomingPlayerList = AllocZeroed(RFU_CHILD_MAX * sizeof(struct RfuIncomingPlayer)); + data->playerList = AllocZeroed(MAX_RFU_PLAYER_LIST_SIZE * sizeof(struct RfuPlayer)); data->state = 2; break; case 2: - ClearUnkStruct_x1CArray(data->field_4, 4); - ClearUnkStruct_x20Array(data->field_0->arr, 16); - data->listenTaskId = CreateTask_ListenForPartnersWithCompatibleSerialNos(data->field_4, 0xFF); + ClearIncomingPlayerList(data->incomingPlayerList, RFU_CHILD_MAX); + ClearRfuPlayerList(data->playerList->players, MAX_RFU_PLAYER_LIST_SIZE); + data->listenTaskId = CreateTask_ListenForCompatiblePartners(data->incomingPlayerList, 0xFF); data->leaderId = 0; data->state = 3; break; @@ -1311,8 +1338,8 @@ static void Task_ListenToWireless(u8 taskId) break; case 10: DestroyTask(data->listenTaskId); - Free(data->field_0); - Free(data->field_4); + Free(data->playerList); + Free(data->incomingPlayerList); LinkRfu_Shutdown(); data->state++; break; @@ -1347,27 +1374,26 @@ static bool32 IsPartnerActivityAcceptable(u32 activity, u32 linkGroup) return FALSE; } -static u8 URoomGroupListGetTextColor(struct WirelessLink_Group *data, u32 id) +static u8 GetGroupListTextColor(struct WirelessLink_Group *data, u32 id) { - if (data->field_0->arr[id].groupScheduledAnim == UNION_ROOM_SPAWN_IN) + if (data->playerList->players[id].groupScheduledAnim == UNION_ROOM_SPAWN_IN) { - if (data->field_0->arr[id].gname_uname.gname.started) - return UR_COLOR_WHT_WHT_LTE; - else if (data->field_0->arr[id].useRedText) - return UR_COLOR_RED_WHT_LTR; - else if (data->field_0->arr[id].field_1B != 0) - return UR_COLOR_GRN_WHT_LTG; + if (data->playerList->players[id].rfu.data.startedActivity) + return UR_COLOR_WHITE; + else if (data->playerList->players[id].useRedText) + return UR_COLOR_RED; + else if (data->playerList->players[id].field_1B != 0) + return UR_COLOR_GREEN; } - - return UR_COLOR_DKE_WHT_LTE; + return UR_COLOR_DEFAULT; } static void ListMenuItemPrintFunc_UnionRoomGroups(u8 windowId, u32 id, u8 y) { struct WirelessLink_Group *data = sWirelessLinkMain.group; - u8 colorId = URoomGroupListGetTextColor(data, id); + u8 colorId = GetGroupListTextColor(data, id); - PrintUnionRoomGroupOnWindow(windowId, 8, y, &data->field_0->arr[id], colorId, id); + PrintGroupMemberOnWindow(windowId, 8, y, &data->playerList->players[id], colorId, id); } static u8 GetNewLeaderCandidate(void) @@ -1377,48 +1403,48 @@ static u8 GetNewLeaderCandidate(void) u8 i; s32 id; - for (i = 0; i < 16; i++) + for (i = 0; i < MAX_RFU_PLAYER_LIST_SIZE; i++) { - if (data->field_0->arr[i].groupScheduledAnim != UNION_ROOM_SPAWN_NONE) + if (data->playerList->players[i].groupScheduledAnim != UNION_ROOM_SPAWN_NONE) { - id = Findx20Inx1CArray(&data->field_0->arr[i], data->field_4->arr); + id = GetNewIncomingPlayerId(&data->playerList->players[i], data->incomingPlayerList->players); if (id != 0xFF) { - if (data->field_0->arr[i].groupScheduledAnim == UNION_ROOM_SPAWN_IN) + if (data->playerList->players[i].groupScheduledAnim == UNION_ROOM_SPAWN_IN) { - if (AreUnionRoomPlayerGnamesDifferent(&data->field_0->arr[i].gname_uname, &data->field_4->arr[id].gname_uname)) + if (ArePlayerDataDifferent(&data->playerList->players[i].rfu, &data->incomingPlayerList->players[id].rfu)) { - data->field_0->arr[i].gname_uname = data->field_4->arr[id].gname_uname; - data->field_0->arr[i].field_1B = 64; + data->playerList->players[i].rfu = data->incomingPlayerList->players[id].rfu; + data->playerList->players[i].field_1B = 64; ret = 1; } else { - if (data->field_0->arr[i].field_1B != 0) + if (data->playerList->players[i].field_1B != 0) { - data->field_0->arr[i].field_1B--; - if (data->field_0->arr[i].field_1B == 0) + data->playerList->players[i].field_1B--; + if (data->playerList->players[i].field_1B == 0) ret = 2; } } } else { - data->field_0->arr[i].groupScheduledAnim = UNION_ROOM_SPAWN_IN; - data->field_0->arr[i].field_1B = 64; + data->playerList->players[i].groupScheduledAnim = UNION_ROOM_SPAWN_IN; + data->playerList->players[i].field_1B = 64; ret = 1; } - data->field_0->arr[i].timeoutCounter = 0; + data->playerList->players[i].timeoutCounter = 0; } else { - if (data->field_0->arr[i].groupScheduledAnim != UNION_ROOM_SPAWN_OUT) + if (data->playerList->players[i].groupScheduledAnim != UNION_ROOM_SPAWN_OUT) { - data->field_0->arr[i].timeoutCounter++; - if (data->field_0->arr[i].timeoutCounter >= 300) + data->playerList->players[i].timeoutCounter++; + if (data->playerList->players[i].timeoutCounter >= 300) { - data->field_0->arr[i].groupScheduledAnim = UNION_ROOM_SPAWN_OUT; + data->playerList->players[i].groupScheduledAnim = UNION_ROOM_SPAWN_OUT; ret = 2; } } @@ -1428,7 +1454,7 @@ static u8 GetNewLeaderCandidate(void) for (id = 0; id < RFU_CHILD_MAX; id++) { - if (Appendx1Ctox20(data->field_0->arr, &data->field_4->arr[id], 16) != 0xFF) + if (TryAddIncomingPlayerToList(data->playerList->players, &data->incomingPlayerList->players[id], MAX_RFU_PLAYER_LIST_SIZE) != 0xFF) ret = 1; } @@ -1687,7 +1713,7 @@ static void Task_StartActivity(u8 taskId) else { LinkRfu_StopManagerBeforeEnteringChat(); - SetHostRFUtgtGname(69, 0, 1); + SetHostRfuGameData(ACTIVITY_CHAT | IN_UNION_ROOM, 0, TRUE); } EnterUnionRoomChat(); break; @@ -1856,29 +1882,29 @@ static void Task_MEvent_Leader(u8 taskId) case 0: gPlayerCurrActivity = data->activity; sPlayerActivityGroupSize = 2; - SetHostRFUtgtGname(data->activity, 0, 0); - SetGnameBufferWonderFlags(FALSE, FALSE); + SetHostRfuGameData(data->activity, 0, FALSE); + SetHostRfuWonderFlags(FALSE, FALSE); SetWirelessCommType1(); OpenLink(); InitializeRfuLinkManager_LinkLeader(2); data->state = 1; break; case 1: - 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].timeoutCounter = 0; - data->field_0->arr[0].groupScheduledAnim = UNION_ROOM_SPAWN_IN; - data->field_0->arr[0].useRedText = FALSE; - data->field_0->arr[0].field_1B = 0; - data->listenTaskId = CreateTask_ListenForPartnersWithCompatibleSerialNos(data->field_4, 0xFF); + data->incomingPlayerList = AllocZeroed(RFU_CHILD_MAX * sizeof(struct RfuIncomingPlayer)); + data->playerList = AllocZeroed(MAX_RFU_PLAYERS * sizeof(struct RfuPlayer)); + data->playerListBackup = AllocZeroed(MAX_RFU_PLAYERS * sizeof(struct RfuPlayer)); + ClearIncomingPlayerList(data->incomingPlayerList, RFU_CHILD_MAX); + ClearRfuPlayerList(data->playerList->players, MAX_RFU_PLAYERS); + CopyHostRfuGameDataAndUsername(&data->playerList->players[0].rfu.data, data->playerList->players[0].rfu.name); + data->playerList->players[0].timeoutCounter = 0; + data->playerList->players[0].groupScheduledAnim = UNION_ROOM_SPAWN_IN; + data->playerList->players[0].useRedText = FALSE; + data->playerList->players[0].field_1B = 0; + data->listenTaskId = CreateTask_ListenForCompatiblePartners(data->incomingPlayerList, 0xFF); winTemplate = sWindowTemplate_PlayerList; winTemplate.baseBlock = GetMysteryGiftBaseBlock(); - winTemplate.paletteNum = 0xC; + winTemplate.paletteNum = 12; data->listWindowId = AddWindow(&winTemplate); MG_DrawTextBorder(data->listWindowId); gMultiuseListMenuTemplate = sListMenuTemplate_PossibleGroupMembers; @@ -1891,7 +1917,7 @@ static void Task_MEvent_Leader(u8 taskId) break; case 2: StringCopy(gStringVar1, sLinkGroupActivityNameTexts[gPlayerCurrActivity]); - StringExpandPlaceholders_AwaitingCommFromAnother(gStringVar4, gPlayerCurrActivity); + GetAwaitingCommunicationText(gStringVar4, gPlayerCurrActivity); data->state = 3; break; case 3: @@ -1909,7 +1935,7 @@ static void Task_MEvent_Leader(u8 taskId) case 6: if (MG_PrintTextOnWindow1AndWaitButton(&data->textState, sText_LinkWithFriendDropped)) { - data->playerCount = sub_8013398(data->field_0); + data->playerCount = LeaderPrunePlayerList(data->playerList); RedrawListMenu(data->listTaskId); data->state = 2; } @@ -1918,44 +1944,44 @@ static void Task_MEvent_Leader(u8 taskId) data->state = 7; break; case 7: - switch (mevent_message_print_and_prompt_yes_no(&data->textState, &data->field_14, 0, gStringVar4)) + switch (mevent_message_print_and_prompt_yes_no(&data->textState, &data->yesNoWindowId, 0, gStringVar4)) { case 0: LoadWirelessStatusIndicatorSpriteGfx(); CreateWirelessStatusIndicatorSprite(0, 0); - data->field_0->arr[data->playerCount].field_1B = 0; + data->playerList->players[data->playerCount].field_1B = 0; RedrawListMenu(data->listTaskId); data->joinRequestAnswer = RFU_STATUS_JOIN_GROUP_OK; - SendRfuStatusToPartner(data->joinRequestAnswer, ReadAsU16(data->field_0->arr[data->playerCount].gname_uname.gname.unk_00.playerTrainerId), data->field_0->arr[data->playerCount].gname_uname.playerName); + SendRfuStatusToPartner(data->joinRequestAnswer, ReadAsU16(data->playerList->players[data->playerCount].rfu.data.compatibility.playerTrainerId), data->playerList->players[data->playerCount].rfu.name); data->state = 8; break; case 1: - case -1: + case MENU_B_PRESSED: data->joinRequestAnswer = RFU_STATUS_JOIN_GROUP_NO; - SendRfuStatusToPartner(data->joinRequestAnswer, ReadAsU16(data->field_0->arr[data->playerCount].gname_uname.gname.unk_00.playerTrainerId), data->field_0->arr[data->playerCount].gname_uname.playerName); + SendRfuStatusToPartner(data->joinRequestAnswer, ReadAsU16(data->playerList->players[data->playerCount].rfu.data.compatibility.playerTrainerId), data->playerList->players[data->playerCount].rfu.name); data->state = 8; break; } break; case 8: - val = WaitSendRfuStatusToPartner(ReadAsU16(data->field_0->arr[data->playerCount].gname_uname.gname.unk_00.playerTrainerId), data->field_0->arr[data->playerCount].gname_uname.playerName); + val = WaitSendRfuStatusToPartner(ReadAsU16(data->playerList->players[data->playerCount].rfu.data.compatibility.playerTrainerId), data->playerList->players[data->playerCount].rfu.name); if (val == 1) // Send complete { if (data->joinRequestAnswer == RFU_STATUS_JOIN_GROUP_OK) { - data->field_0->arr[data->playerCount].field_1B = 0; + data->playerList->players[data->playerCount].field_1B = 0; RedrawListMenu(data->listTaskId); data->playerCount++; - IntlConvPartnerUname7(gStringVar1, &data->field_0->arr[data->playerCount - 1]); + CopyAndTranslatePlayerName(gStringVar1, &data->playerList->players[data->playerCount - 1]); StringExpandPlaceholders(gStringVar4, sText_AnOKWasSentToPlayer); data->state = 9; LinkRfu_StopManagerAndFinalizeSlots(); } else { - 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); + RequestDisconnectSlotByTrainerNameAndId(data->playerList->players[data->playerCount].rfu.name, ReadAsU16(data->playerList->players[data->playerCount].rfu.data.compatibility.playerTrainerId)); + data->playerList->players[data->playerCount].groupScheduledAnim = UNION_ROOM_SPAWN_NONE; + LeaderPrunePlayerList(data->playerList); RedrawListMenu(data->listTaskId); data->state = 2; } @@ -1998,9 +2024,9 @@ static void Task_MEvent_Leader(u8 taskId) CopyBgTilemapBufferToVram(0); RemoveWindow(data->listWindowId); DestroyTask(data->listenTaskId); - Free(data->field_8); - Free(data->field_0); - Free(data->field_4); + Free(data->playerListBackup); + Free(data->playerList); + Free(data->incomingPlayerList); data->state++; break; case 14: @@ -2026,9 +2052,9 @@ static void Task_MEvent_Leader(u8 taskId) CopyBgTilemapBufferToVram(0); RemoveWindow(data->listWindowId); DestroyTask(data->listenTaskId); - Free(data->field_8); - Free(data->field_0); - Free(data->field_4); + Free(data->playerListBackup); + Free(data->playerList); + Free(data->incomingPlayerList); SetLinkStandbyCallback(); data->state++; break; @@ -2050,25 +2076,25 @@ void MEvent_CreateTask_CardOrNewsWithFriend(u32 activity) data->state = 0; data->textState = 0; - data->isWonderNews = activity - ACTIVITY_WONDER_CARD2; + data->isWonderNews = activity - ACTIVITY_WONDER_CARD; gSpecialVar_Result = LINKUP_ONGOING; } static void Task_CardOrNewsWithFriend(u8 taskId) { s32 id; - struct WindowTemplate winTemplate1, winTemplate2; + struct WindowTemplate listWinTemplate, playerNameWinTemplate; struct WirelessLink_Group *data = sWirelessLinkMain.group; switch (data->state) { case 0: - SetHostRFUtgtGname(data->isWonderNews + ACTIVITY_WONDER_CARD2, 0, 0); + SetHostRfuGameData(data->isWonderNews + ACTIVITY_WONDER_CARD, 0, FALSE); SetWirelessCommType1(); OpenLink(); InitializeRfuLinkManager_JoinGroup(); - data->field_4 = AllocZeroed(4 * sizeof(struct UnkStruct_x1C)); - data->field_0 = AllocZeroed(16 * sizeof(struct UnkStruct_x20)); + data->incomingPlayerList = AllocZeroed(RFU_CHILD_MAX * sizeof(struct RfuIncomingPlayer)); + data->playerList = AllocZeroed(MAX_RFU_PLAYER_LIST_SIZE * sizeof(struct RfuPlayer)); data->state = 1; break; case 1: @@ -2076,18 +2102,18 @@ static void Task_CardOrNewsWithFriend(u8 taskId) data->state = 2; break; case 2: - 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); + ClearIncomingPlayerList(data->incomingPlayerList, RFU_CHILD_MAX); + ClearRfuPlayerList(data->playerList->players, MAX_RFU_PLAYER_LIST_SIZE); + data->listenTaskId = CreateTask_ListenForCompatiblePartners(data->incomingPlayerList, data->isWonderNews + LINK_GROUP_WONDER_CARD); - winTemplate1 = gUnknown_082F0174; - winTemplate1.baseBlock = GetMysteryGiftBaseBlock(); - winTemplate1.paletteNum = 0xC; - data->listWindowId = AddWindow(&winTemplate1); + listWinTemplate = sWindowTemplate_GroupList; + listWinTemplate.baseBlock = GetMysteryGiftBaseBlock(); + listWinTemplate.paletteNum = 12; + data->listWindowId = AddWindow(&listWinTemplate); - winTemplate2 = gUnknown_082F017C; - winTemplate2.paletteNum = 0xC; - data->playerNameAndIdWindowId = AddWindow(&winTemplate2); + playerNameWinTemplate = sWindowTemplate_PlayerNameAndId; + playerNameWinTemplate.paletteNum = 12; + data->playerNameAndIdWindowId = AddWindow(&playerNameWinTemplate); MG_DrawTextBorder(data->listWindowId); gMultiuseListMenuTemplate = sListMenuTemplate_UnionRoomGroups; @@ -2119,16 +2145,16 @@ static void Task_CardOrNewsWithFriend(u8 taskId) { // this unused variable along with the assignment is needed to match u32 unusedVar; - unusedVar = data->field_0->arr[id].gname_uname.gname.activity; + unusedVar = data->playerList->players[id].rfu.data.activity; - if (data->field_0->arr[id].groupScheduledAnim == UNION_ROOM_SPAWN_IN && !data->field_0->arr[id].gname_uname.gname.started) + if (data->playerList->players[id].groupScheduledAnim == UNION_ROOM_SPAWN_IN && !data->playerList->players[id].rfu.data.startedActivity) { data->leaderId = id; LoadWirelessStatusIndicatorSpriteGfx(); CreateWirelessStatusIndicatorSprite(0, 0); RedrawListMenu(data->listTaskId); - 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)); + CopyAndTranslatePlayerName(gStringVar1, &data->playerList->players[data->leaderId]); + CreateTask_RfuReconnectWithParent(data->playerList->players[data->leaderId].rfu.name, ReadAsU16(data->playerList->players[data->leaderId].rfu.data.compatibility.playerTrainerId)); PlaySE(SE_POKENAV_ON); data->state = 4; } @@ -2146,13 +2172,13 @@ static void Task_CardOrNewsWithFriend(u8 taskId) break; case 4: AddTextPrinterToWindow1(sText_AwaitingPlayersResponse); - IntlConvPartnerUname7(gStringVar1, &data->field_0->arr[data->leaderId]); + CopyAndTranslatePlayerName(gStringVar1, &data->playerList->players[data->leaderId]); data->state = 5; break; case 5: if (gReceivedRemoteLinkPlayers) { - gPlayerCurrActivity = data->field_0->arr[data->leaderId].gname_uname.gname.activity; + gPlayerCurrActivity = data->playerList->players[data->leaderId].rfu.data.activity; data->state = 10; } @@ -2177,8 +2203,8 @@ static void Task_CardOrNewsWithFriend(u8 taskId) RemoveWindow(data->playerNameAndIdWindowId); RemoveWindow(data->listWindowId); DestroyTask(data->listenTaskId); - Free(data->field_0); - Free(data->field_4); + Free(data->playerList); + Free(data->incomingPlayerList); data->state++; break; case 9: @@ -2219,7 +2245,7 @@ void MEvent_CreateTask_CardOrNewsOverWireless(u32 activity) data->state = 0; data->textState = 0; - data->isWonderNews = activity - ACTIVITY_WONDER_CARD2; + data->isWonderNews = activity - ACTIVITY_WONDER_CARD; gSpecialVar_Result = LINKUP_ONGOING; } @@ -2232,12 +2258,12 @@ static void Task_CardOrNewsOverWireless(u8 taskId) switch (data->state) { case 0: - SetHostRFUtgtGname(0, 0, 0); + SetHostRfuGameData(ACTIVITY_NONE, 0, FALSE); SetWirelessCommType1(); OpenLink(); InitializeRfuLinkManager_JoinGroup(); - data->field_4 = AllocZeroed(4 * sizeof(struct UnkStruct_x1C)); - data->field_0 = AllocZeroed(16 * sizeof(struct UnkStruct_x20)); + data->incomingPlayerList = AllocZeroed(RFU_CHILD_MAX * sizeof(struct RfuIncomingPlayer)); + data->playerList = AllocZeroed(MAX_RFU_PLAYER_LIST_SIZE * sizeof(struct RfuPlayer)); data->state = 1; break; case 1: @@ -2245,13 +2271,13 @@ static void Task_CardOrNewsOverWireless(u8 taskId) data->state = 2; break; case 2: - 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); + ClearIncomingPlayerList(data->incomingPlayerList, RFU_CHILD_MAX); + ClearRfuPlayerList(data->playerList->players, MAX_RFU_PLAYER_LIST_SIZE); + data->listenTaskId = CreateTask_ListenForWonderDistributor(data->incomingPlayerList, data->isWonderNews + LINK_GROUP_WONDER_CARD); - if (data->field_13 != 0) + if (data->showListMenu) { - winTemplate = gUnknown_082F0174; + winTemplate = sWindowTemplate_GroupList; winTemplate.baseBlock = GetMysteryGiftBaseBlock(); data->listWindowId = AddWindow(&winTemplate); @@ -2273,23 +2299,23 @@ static void Task_CardOrNewsOverWireless(u8 taskId) case 1: PlaySE(SE_PC_LOGIN); default: - if (data->field_13 != 0) + if (data->showListMenu) RedrawListMenu(data->listTaskId); break; case 0: - if (data->field_13 != 0) + if (data->showListMenu) id = ListMenu_ProcessInput(data->listTaskId); if (data->refreshTimer > 120) { - if (data->field_0->arr[0].groupScheduledAnim == UNION_ROOM_SPAWN_IN && !data->field_0->arr[0].gname_uname.gname.started) + if (data->playerList->players[0].groupScheduledAnim == UNION_ROOM_SPAWN_IN && !data->playerList->players[0].rfu.data.startedActivity) { - if (HasWonderCardOrNewsByLinkGroup(&data->field_0->arr[0].gname_uname.gname, data->isWonderNews + LINK_GROUP_WONDER_CARD)) + if (HasWonderCardOrNewsByLinkGroup(&data->playerList->players[0].rfu.data, data->isWonderNews + LINK_GROUP_WONDER_CARD)) { data->leaderId = 0; data->refreshTimer = 0; LoadWirelessStatusIndicatorSpriteGfx(); CreateWirelessStatusIndicatorSprite(0, 0); - CreateTask_RfuReconnectWithParent(data->field_0->arr[0].gname_uname.playerName, ReadAsU16(data->field_0->arr[0].gname_uname.gname.unk_00.playerTrainerId)); + CreateTask_RfuReconnectWithParent(data->playerList->players[0].rfu.name, ReadAsU16(data->playerList->players[0].rfu.data.compatibility.playerTrainerId)); PlaySE(SE_POKENAV_ON); data->state = 4; } @@ -2311,13 +2337,13 @@ static void Task_CardOrNewsOverWireless(u8 taskId) break; case 4: AddTextPrinterToWindow1(sText_AwaitingResponseFromWirelessSystem); - IntlConvPartnerUname7(gStringVar1, &data->field_0->arr[data->leaderId]); + CopyAndTranslatePlayerName(gStringVar1, &data->playerList->players[data->leaderId]); data->state = 5; break; case 5: if (gReceivedRemoteLinkPlayers) { - gPlayerCurrActivity = data->field_0->arr[data->leaderId].gname_uname.gname.activity; + gPlayerCurrActivity = data->playerList->players[data->leaderId].rfu.data.activity; data->state = 12; } @@ -2338,15 +2364,15 @@ static void Task_CardOrNewsOverWireless(u8 taskId) case 8: case 10: case 12: - if (data->field_13 != 0) + if (data->showListMenu) { DestroyListMenuTask(data->listTaskId, 0, 0); CopyBgTilemapBufferToVram(0); RemoveWindow(data->listWindowId); } DestroyTask(data->listenTaskId); - Free(data->field_0); - Free(data->field_4); + Free(data->playerList); + Free(data->incomingPlayerList); data->state++; break; case 9: @@ -2391,7 +2417,7 @@ void RunUnionRoom(void) { struct WirelessLink_URoom *uroom; - ClearAndInitHostRFUtgtGname(); + ResetHostRfuGameData(); CreateTask(Task_RunUnionRoom, 10); // dumb line needed to match @@ -2434,14 +2460,18 @@ static void ScheduleFieldMessageAndExit(const u8 *src) StringExpandPlaceholders(gStringVar4, src); } -static void sub_80156B0(struct WirelessLink_URoom *uroom) +static void CopyPlayerListToBuffer(struct WirelessLink_URoom *uroom) { - memcpy(&gDecompressionBuffer[0x3F00], uroom->field_0, 0x100); + memcpy(&gDecompressionBuffer[sizeof(gDecompressionBuffer) - (MAX_UNION_ROOM_LEADERS * sizeof(struct RfuPlayer))], + uroom->playerList, + MAX_UNION_ROOM_LEADERS * sizeof(struct RfuPlayer)); } -static void sub_80156C8(struct WirelessLink_URoom *uroom) +static void CopyPlayerListFromBuffer(struct WirelessLink_URoom *uroom) { - memcpy(uroom->field_0, &gDecompressionBuffer[0x3F00], 0x100); + memcpy(uroom->playerList, + &gDecompressionBuffer[sizeof(gDecompressionBuffer) - (MAX_UNION_ROOM_LEADERS * sizeof(struct RfuPlayer))], + MAX_UNION_ROOM_LEADERS * sizeof(struct RfuPlayer)); } static void Task_RunUnionRoom(u8 taskId) @@ -2455,31 +2485,31 @@ static void Task_RunUnionRoom(u8 taskId) switch (uroom->state) { case UR_STATE_INIT: - uroom->field_4 = AllocZeroed(RFU_CHILD_MAX * sizeof(struct UnkStruct_x1C)); - uroom->field_C = AllocZeroed(RFU_CHILD_MAX * sizeof(struct UnkStruct_x1C)); - uroom->field_0 = AllocZeroed(8 * sizeof(struct UnkStruct_x20)); - uroom->field_8 = AllocZeroed(sizeof(struct UnkStruct_x20)); - ClearUnkStruct_x20Array(uroom->field_0->arr, ARRAY_COUNT(uroom->field_0->arr)); + uroom->incomingChildList = AllocZeroed(RFU_CHILD_MAX * sizeof(struct RfuIncomingPlayer)); + uroom->incomingParentList = AllocZeroed(RFU_CHILD_MAX * sizeof(struct RfuIncomingPlayer)); + uroom->playerList = AllocZeroed(MAX_UNION_ROOM_LEADERS * sizeof(struct RfuPlayer)); + uroom->spawnPlayer = AllocZeroed(sizeof(struct RfuPlayer)); + ClearRfuPlayerList(uroom->playerList->players, MAX_UNION_ROOM_LEADERS); gPlayerCurrActivity = IN_UNION_ROOM; - uroom->searchTaskId = CreateTask_SearchForChildOrParent(uroom->field_C, uroom->field_4, LINK_GROUP_UNION_ROOM_RESUME); + uroom->searchTaskId = CreateTask_SearchForChildOrParent(uroom->incomingParentList, uroom->incomingChildList, LINK_GROUP_UNION_ROOM_RESUME); InitUnionRoomPlayerObjects(uroom->objects); SetTilesAroundUnionRoomPlayersPassable(); uroom->state = UR_STATE_INIT_OBJECTS; break; case UR_STATE_INIT_OBJECTS: - CreateGroupMemberSpritesInvisible(uroom->spriteIds, taskData[0]); + CreateUnionRoomPlayerSprites(uroom->spriteIds, taskData[0]); if (++taskData[0] == 8) uroom->state = UR_STATE_INIT_LINK; break; case UR_STATE_INIT_LINK: - SetHostRFUtgtGname(IN_UNION_ROOM, 0, 0); + SetHostRfuGameData(IN_UNION_ROOM, 0, FALSE); SetTradeBoardRegisteredMonInfo(sUnionRoomTrade.type, sUnionRoomTrade.playerSpecies, sUnionRoomTrade.playerLevel); SetWirelessCommType1(); OpenLink(); InitializeRfuLinkManager_EnterUnionRoom(); - ClearUnkStruct_x20Array(&uroom->field_8->arr[0], 1); - ClearUnkStruct_x1CArray(uroom->field_4, 4); - ClearUnkStruct_x1CArray(uroom->field_C, 4); + ClearRfuPlayerList(&uroom->spawnPlayer->players[0], 1); + ClearIncomingPlayerList(uroom->incomingChildList, RFU_CHILD_MAX); + ClearIncomingPlayerList(uroom->incomingParentList, RFU_CHILD_MAX); gSpecialVar_Result = 0; uroom->state = UR_STATE_CHECK_SELECTING_MON; break; @@ -2509,7 +2539,7 @@ static void Task_RunUnionRoom(u8 taskId) } break; case URTRADE_STATE_OFFERING: - sub_80156C8(uroom); + CopyPlayerListFromBuffer(uroom); taskData[1] = sUnionRoomTrade.offerPlayerId; if (id >= PARTY_SIZE) { @@ -2560,10 +2590,10 @@ static void Task_RunUnionRoom(u8 taskId) { if (JOY_NEW(A_BUTTON)) { - if (TryInteractWithUnionRoomMember(uroom->field_0, &taskData[0], &taskData[1], uroom->spriteIds)) + if (TryInteractWithUnionRoomMember(uroom->playerList, &taskData[0], &taskData[1], uroom->spriteIds)) { PlaySE(SE_SELECT); - UR_EnableScriptContext2AndFreezeObjectEvents(); + StartScriptInteraction(); uroom->state = UR_STATE_INTERACT_WITH_PLAYER; break; } @@ -2571,7 +2601,7 @@ static void Task_RunUnionRoom(u8 taskId) { UpdateGameData_SetActivity(ACTIVITY_PLYRTALK | IN_UNION_ROOM, 0, TRUE); PlaySE(SE_PC_LOGIN); - UR_EnableScriptContext2AndFreezeObjectEvents(); + StartScriptInteraction(); StringCopy(gStringVar1, gSaveBlock2Ptr->playerName); uroom->state = UR_STATE_CHECK_TRADING_BOARD; break; @@ -2580,16 +2610,16 @@ static void Task_RunUnionRoom(u8 taskId) switch (HandlePlayerListUpdate()) { - case 1: + case PLIST_1: PlaySE(SE_PC_LOGIN); - case 2: + case PLIST_2: ScheduleUnionRoomPlayerRefresh(uroom); break; - case 4: + case PLIST_4: uroom->state = UR_STATE_PLAYER_CONTACTED_YOU; - UR_EnableScriptContext2AndFreezeObjectEvents(); + StartScriptInteraction(); SetTradeBoardRegisteredMonInfo(TYPE_NORMAL, SPECIES_NONE, 0); - UpdateGameData_SetActivity(ACTIVITY_NPCTALK | IN_UNION_ROOM, GetActivePartnerSpriteGenderParam(uroom), FALSE); + UpdateGameData_SetActivity(ACTIVITY_NPCTALK | IN_UNION_ROOM, GetActivePartnersInfo(uroom), FALSE); break; } HandleUnionRoomPlayerRefresh(uroom); @@ -2603,16 +2633,16 @@ static void Task_RunUnionRoom(u8 taskId) } break; case UR_STATE_INTERACT_WITH_PLAYER: - UR_RunTextPrinters_CheckPrinter0Active(); - playerGender = GetUnionRoomPlayerGender(taskData[1], uroom->field_0); + UR_RunTextPrinters(); + playerGender = GetUnionRoomPlayerGender(taskData[1], uroom->playerList); UpdateGameData_SetActivity(ACTIVITY_PLYRTALK | IN_UNION_ROOM, 0, TRUE); - switch (UnionRoomGetPlayerInteractionResponse(uroom->field_0, taskData[0], taskData[1], playerGender)) + switch (UnionRoomGetPlayerInteractionResponse(uroom->playerList, taskData[0], taskData[1], playerGender)) { case 0: // Player is or was just doing an activity uroom->state = UR_STATE_PRINT_AND_EXIT; break; case 1: // Link communicating - sub_8012188(uroom->field_0->arr[taskData[1]].gname_uname.playerName, &uroom->field_0->arr[taskData[1]].gname_uname.gname, gPlayerCurrActivity); + TryConnectToUnionRoomParent(uroom->playerList->players[taskData[1]].rfu.name, &uroom->playerList->players[taskData[1]].rfu.data, gPlayerCurrActivity); uroom->field_12 = id; // Should be just 0, but won't match any other way. uroom->state = UR_STATE_TRY_COMMUNICATING; break; @@ -2622,7 +2652,7 @@ static void Task_RunUnionRoom(u8 taskId) } break; case UR_STATE_TRY_COMMUNICATING: - UR_RunTextPrinters_CheckPrinter0Active(); + UR_RunTextPrinters(); switch (RfuGetStatus()) { case RFU_STATUS_NEW_CHILD_DETECTED: @@ -2660,13 +2690,13 @@ static void Task_RunUnionRoom(u8 taskId) if (!gReceivedRemoteLinkPlayers) { HandleCancelActivity(FALSE); - UpdateUnionRoomMemberFacing(taskData[0], taskData[1], uroom->field_0); + UpdateUnionRoomMemberFacing(taskData[0], taskData[1], uroom->playerList); uroom->state = UR_STATE_INIT_LINK; } break; case UR_STATE_DO_SOMETHING_PROMPT: - id = ConvPartnerUnameAndGetWhetherMetAlready(&uroom->field_0->arr[taskData[1]]); - playerGender = GetUnionRoomPlayerGender(taskData[1], uroom->field_0); + id = ConvPartnerUnameAndGetWhetherMetAlready(&uroom->playerList->players[taskData[1]]); + playerGender = GetUnionRoomPlayerGender(taskData[1], uroom->playerList); ScheduleFieldMessageWithFollowupState(UR_STATE_HANDLE_DO_SOMETHING_PROMPT_INPUT, sHiDoSomethingTexts[id][playerGender]); break; case UR_STATE_HANDLE_DO_SOMETHING_PROMPT_INPUT: @@ -2684,7 +2714,7 @@ static void Task_RunUnionRoom(u8 taskId) else { uroom->partnerYesNoResponse = 0; - playerGender = GetUnionRoomPlayerGender(taskData[1], uroom->field_0); + playerGender = GetUnionRoomPlayerGender(taskData[1], uroom->playerList); if (input == -2 || input == IN_UNION_ROOM) { uroom->playerSendBuffer[0] = IN_UNION_ROOM; @@ -2695,7 +2725,7 @@ static void Task_RunUnionRoom(u8 taskId) else { gPlayerCurrActivity = input; - sPlayerActivityGroupSize = (u32)(input) >> 8; + sPlayerActivityGroupSize = (u32)input >> 8; // Extract capacity from sInviteToActivityMenuItems if (gPlayerCurrActivity == (ACTIVITY_BATTLE_SINGLE | IN_UNION_ROOM) && !HasAtLeastTwoMonsOfLevel30OrLower()) { ScheduleFieldMessageWithFollowupState(UR_STATE_DO_SOMETHING_PROMPT, sText_NeedTwoMonsOfLevel30OrLower1); @@ -2716,7 +2746,7 @@ static void Task_RunUnionRoom(u8 taskId) break; case UR_STATE_SEND_ACTIVITY_REQUEST: PollPartnerYesNoResponse(uroom); - playerGender = GetUnionRoomPlayerGender(taskData[1], uroom->field_0); + playerGender = GetUnionRoomPlayerGender(taskData[1], uroom->playerList); id = GetResponseIdx_InviteToURoomActivity(uroom->playerSendBuffer[0] & 0x3F); if (PrintOnTextbox(&uroom->textState, sText_WaitOrShowCardTexts[playerGender][id])) { @@ -2766,8 +2796,8 @@ static void Task_RunUnionRoom(u8 taskId) break; case UR_STATE_DO_SOMETHING_PROMPT_2: // Identical to UR_STATE_DO_SOMETHING_PROMPT - id = ConvPartnerUnameAndGetWhetherMetAlready(&uroom->field_0->arr[taskData[1]]); - playerGender = GetUnionRoomPlayerGender(taskData[1], uroom->field_0); + id = ConvPartnerUnameAndGetWhetherMetAlready(&uroom->playerList->players[taskData[1]]); + playerGender = GetUnionRoomPlayerGender(taskData[1], uroom->playerList); ScheduleFieldMessageWithFollowupState(UR_STATE_HANDLE_DO_SOMETHING_PROMPT_INPUT, sHiDoSomethingTexts[id][playerGender]); break; case UR_STATE_PRINT_CARD_INFO: @@ -2802,14 +2832,14 @@ static void Task_RunUnionRoom(u8 taskId) CopyBgTilemapBufferToVram(0); gPlayerCurrActivity = ACTIVITY_CHAT | IN_UNION_ROOM; UpdateGameData_SetActivity(ACTIVITY_CHAT | IN_UNION_ROOM, 0, TRUE); - sub_8012188(uroom->field_0->arr[taskData[1]].gname_uname.playerName, &uroom->field_0->arr[taskData[1]].gname_uname.gname, gPlayerCurrActivity); + TryConnectToUnionRoomParent(uroom->playerList->players[taskData[1]].rfu.name, &uroom->playerList->players[taskData[1]].rfu.data, gPlayerCurrActivity); uroom->field_12 = taskData[1]; uroom->state = UR_STATE_TRY_ACCEPT_CHAT_REQUEST_DELAY; taskData[3] = 0; break; case 1: // NO - case -1: - playerGender = GetUnionRoomPlayerGender(taskData[1], uroom->field_0); + case MENU_B_PRESSED: + playerGender = GetUnionRoomPlayerGender(taskData[1], uroom->playerList); ScheduleFieldMessageAndExit(sDeclineChatTexts[playerGender]); break; } @@ -2830,7 +2860,7 @@ static void Task_RunUnionRoom(u8 taskId) break; case RFU_STATUS_FATAL_ERROR: case RFU_STATUS_CONNECTION_ERROR: - playerGender = GetUnionRoomPlayerGender(taskData[1], uroom->field_0); + playerGender = GetUnionRoomPlayerGender(taskData[1], uroom->playerList); UpdateGameData_SetActivity(ACTIVITY_PLYRTALK | IN_UNION_ROOM, 0, TRUE); if (IsUnionRoomListenTaskActive() == TRUE) ScheduleFieldMessageAndExit(sChatDeclinedTexts[playerGender]); @@ -2846,7 +2876,7 @@ static void Task_RunUnionRoom(u8 taskId) case UR_STATE_ACCEPT_CHAT_REQUEST: if (RfuHasErrored()) { - playerGender = GetUnionRoomPlayerGender(taskData[1], uroom->field_0); + playerGender = GetUnionRoomPlayerGender(taskData[1], uroom->playerList); UpdateGameData_SetActivity(ACTIVITY_PLYRTALK | IN_UNION_ROOM, 0, TRUE); if (IsUnionRoomListenTaskActive() == TRUE) ScheduleFieldMessageAndExit(sChatDeclinedTexts[playerGender]); @@ -2892,7 +2922,7 @@ static void Task_RunUnionRoom(u8 taskId) break; case UR_STATE_HANDLE_CONTACT_DATA: ReceiveUnionRoomActivityPacket(uroom); - if (UnionRoom_HandleContactFromOtherPlayer(uroom) && JOY_NEW(B_BUTTON)) + if (HandleContactFromOtherPlayer(uroom) && JOY_NEW(B_BUTTON)) { Rfu_DisconnectPlayerById(1); StringCopy(gStringVar4, sText_ChatEnded); @@ -2912,7 +2942,7 @@ static void Task_RunUnionRoom(u8 taskId) else UpdateGameData_SetActivity(gPlayerCurrActivity | IN_UNION_ROOM, GetLinkPlayerInfoFlags(1), TRUE); - uroom->field_8->arr[0].field_1B = 0; + uroom->spawnPlayer->players[0].field_1B = 0; taskData[3] = 0; if (gPlayerCurrActivity == (ACTIVITY_BATTLE_SINGLE | IN_UNION_ROOM)) { @@ -2942,7 +2972,7 @@ static void Task_RunUnionRoom(u8 taskId) } break; case 1: // DECLINE - case -1: + case MENU_B_PRESSED: uroom->playerSendBuffer[0] = ACTIVITY_DECLINE | IN_UNION_ROOM; Rfu_SendPacket(uroom->playerSendBuffer); uroom->state = UR_STATE_DECLINE_ACTIVITY_REQUEST; @@ -2981,16 +3011,16 @@ static void Task_RunUnionRoom(u8 taskId) uroom->state = UR_STATE_START_ACTIVITY_FREE_UROOM; break; case UR_STATE_START_ACTIVITY_FREE_UROOM: - Free(uroom->field_8); - Free(uroom->field_0); - Free(uroom->field_C); - Free(uroom->field_4); + Free(uroom->spawnPlayer); + Free(uroom->playerList); + Free(uroom->incomingParentList); + Free(uroom->incomingChildList); DestroyTask(uroom->searchTaskId); - DestroyGroupMemberSprites(uroom->spriteIds); + DestroyUnionRoomPlayerSprites(uroom->spriteIds); uroom->state = UR_STATE_START_ACTIVITY_FADE; break; case UR_STATE_START_ACTIVITY_FADE: - BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 0x10, RGB_BLACK); + BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); uroom->state = UR_STATE_START_ACTIVITY; break; case UR_STATE_START_ACTIVITY: @@ -3003,20 +3033,20 @@ static void Task_RunUnionRoom(u8 taskId) } break; case UR_STATE_INTERACT_WITH_ATTENDANT: - if (GetHostRFUtgtGname()->species == SPECIES_NONE) + if (GetHostRfuGameData()->tradeSpecies == SPECIES_NONE) { uroom->state = UR_STATE_REGISTER_PROMPT; } else { - if (GetHostRFUtgtGname()->species == SPECIES_EGG) + if (GetHostRfuGameData()->tradeSpecies == SPECIES_EGG) { StringCopy(gStringVar4, sText_CancelRegistrationOfEgg); } else { - StringCopy(gStringVar1, gSpeciesNames[GetHostRFUtgtGname()->species]); - ConvertIntToDecimalStringN(gStringVar2, GetHostRFUtgtGname()->level, STR_CONV_MODE_LEFT_ALIGN, 3); + StringCopy(gStringVar1, gSpeciesNames[GetHostRfuGameData()->tradeSpecies]); + ConvertIntToDecimalStringN(gStringVar2, GetHostRfuGameData()->tradeLevel, STR_CONV_MODE_LEFT_ALIGN, 3); StringExpandPlaceholders(gStringVar4, sText_CancelRegistrationOfMon); } ScheduleFieldMessageWithFollowupState(UR_STATE_CANCEL_REGISTRATION_PROMPT, gStringVar4); @@ -3028,8 +3058,8 @@ static void Task_RunUnionRoom(u8 taskId) break; case UR_STATE_REGISTER_PROMPT_HANDLE_INPUT: input = ListMenuHandler_AllItemsAvailable(&uroom->textState, - &uroom->tradeBoardSelectWindowId, - &uroom->tradeBoardDetailsWindowId, + &uroom->tradeBoardMainWindowId, + &uroom->tradeBoardHeaderWindowId, &sWindowTemplate_RegisterForTrade, &sListMenuTemplate_RegisterForTrade); if (input != -1) @@ -3067,9 +3097,9 @@ static void Task_RunUnionRoom(u8 taskId) break; case UR_STATE_REGISTER_REQUEST_TYPE: input = ListMenuHandler_AllItemsAvailable(&uroom->textState, - &uroom->tradeBoardSelectWindowId, - &uroom->tradeBoardDetailsWindowId, - &gUnknown_082F0294, + &uroom->tradeBoardMainWindowId, + &uroom->tradeBoardHeaderWindowId, + &sWindowTemplate_TradingBoardRequestType, &sMenuTemplate_TradingBoardRequestType); if (input != -1) { @@ -3099,7 +3129,7 @@ static void Task_RunUnionRoom(u8 taskId) uroom->state = UR_STATE_CANCEL_REGISTRATION; break; case 1: // NO - case -1: + case MENU_B_PRESSED: HandleCancelActivity(TRUE); uroom->state = UR_STATE_MAIN; break; @@ -3123,7 +3153,13 @@ static void Task_RunUnionRoom(u8 taskId) uroom->state = UR_STATE_TRADING_BOARD_HANDLE_INPUT; break; case UR_STATE_TRADING_BOARD_HANDLE_INPUT: - input = TradeBoardMenuHandler(&uroom->textState, &uroom->tradeBoardSelectWindowId, &uroom->tradeBoardListMenuId, &uroom->tradeBoardDetailsWindowId, &gUnknown_082F034C, &sTradeBoardListMenuTemplate, uroom->field_0); + input = TradeBoardMenuHandler(&uroom->textState, + &uroom->tradeBoardMainWindowId, + &uroom->tradeBoardListMenuId, + &uroom->tradeBoardHeaderWindowId, + &sWindowTemplate_TradingBoardMain, + &sTradeBoardListMenuTemplate, + uroom->playerList); if (input != -1) { switch (input) @@ -3135,21 +3171,21 @@ static void Task_RunUnionRoom(u8 taskId) break; default: UR_ClearBg0(); - switch (IsRequestedTypeOrEggInPlayerParty(uroom->field_0->arr[input].gname_uname.gname.type, uroom->field_0->arr[input].gname_uname.gname.species)) + switch (IsRequestedTypeOrEggInPlayerParty(uroom->playerList->players[input].rfu.data.tradeType, uroom->playerList->players[input].rfu.data.tradeSpecies)) { case UR_TRADE_MATCH: - IntlConvPartnerUname7(gStringVar1, &uroom->field_0->arr[input]); + CopyAndTranslatePlayerName(gStringVar1, &uroom->playerList->players[input]); ScheduleFieldMessageWithFollowupState(UR_STATE_TRADE_PROMPT, sText_AskTrainerToMakeTrade); taskData[1] = input; break; case UR_TRADE_NOTYPE: - IntlConvPartnerUname7(gStringVar1, &uroom->field_0->arr[input]); - StringCopy(gStringVar2, gTypeNames[uroom->field_0->arr[input].gname_uname.gname.type]); + CopyAndTranslatePlayerName(gStringVar1, &uroom->playerList->players[input]); + StringCopy(gStringVar2, gTypeNames[uroom->playerList->players[input].rfu.data.tradeType]); ScheduleFieldMessageWithFollowupState(UR_STATE_TRADING_BOARD_LOAD, sText_DontHaveTypeTrainerWants); break; case UR_TRADE_NOEGG: - IntlConvPartnerUname7(gStringVar1, &uroom->field_0->arr[input]); - StringCopy(gStringVar2, gTypeNames[uroom->field_0->arr[input].gname_uname.gname.type]); + CopyAndTranslatePlayerName(gStringVar1, &uroom->playerList->players[input]); + StringCopy(gStringVar2, gTypeNames[uroom->playerList->players[input].rfu.data.tradeType]); ScheduleFieldMessageWithFollowupState(UR_STATE_TRADING_BOARD_LOAD, sText_DontHaveEggTrainerWants); break; } @@ -3163,8 +3199,8 @@ static void Task_RunUnionRoom(u8 taskId) case 0: // YES uroom->state = UR_STATE_TRADE_SELECT_MON; break; - case -1: // NO - case 1: + case MENU_B_PRESSED: + case 1: // NO HandleCancelActivity(TRUE); uroom->state = UR_STATE_MAIN; break; @@ -3174,19 +3210,19 @@ static void Task_RunUnionRoom(u8 taskId) if (PrintOnTextbox(&uroom->textState, sText_WhichMonWillYouOffer)) { sUnionRoomTrade.state = URTRADE_STATE_OFFERING; - memcpy(&gPartnerTgtGnameSub, &uroom->field_0->arr[taskData[1]].gname_uname.gname.unk_00, sizeof(gPartnerTgtGnameSub)); - gUnionRoomRequestedMonType = uroom->field_0->arr[taskData[1]].gname_uname.gname.type; - gUnionRoomOfferedSpecies = uroom->field_0->arr[taskData[1]].gname_uname.gname.species; + memcpy(&gRfuPartnerCompatibilityData, &uroom->playerList->players[taskData[1]].rfu.data.compatibility, sizeof(gRfuPartnerCompatibilityData)); + gUnionRoomRequestedMonType = uroom->playerList->players[taskData[1]].rfu.data.tradeType; + gUnionRoomOfferedSpecies = uroom->playerList->players[taskData[1]].rfu.data.tradeSpecies; gFieldCallback = FieldCB_ContinueScriptUnionRoom; ChooseMonForTradingBoard(PARTY_MENU_TYPE_UNION_ROOM_TRADE, CB2_ReturnToField); - sub_80156B0(uroom); + CopyPlayerListToBuffer(uroom); sUnionRoomTrade.offerPlayerId = taskData[1]; } break; case UR_STATE_TRADE_OFFER_MON: gPlayerCurrActivity = ACTIVITY_TRADE | IN_UNION_ROOM; - sub_8012188(uroom->field_0->arr[taskData[1]].gname_uname.playerName, &uroom->field_0->arr[taskData[1]].gname_uname.gname, gPlayerCurrActivity); - IntlConvPartnerUname7(gStringVar1, &uroom->field_0->arr[taskData[1]]); + TryConnectToUnionRoomParent(uroom->playerList->players[taskData[1]].rfu.name, &uroom->playerList->players[taskData[1]].rfu.data, gPlayerCurrActivity); + CopyAndTranslatePlayerName(gStringVar1, &uroom->playerList->players[taskData[1]]); UR_PrintFieldMessage(sCommunicatingWaitTexts[2]); uroom->state = UR_STATE_TRY_COMMUNICATING; break; @@ -3194,7 +3230,7 @@ static void Task_RunUnionRoom(u8 taskId) if (PrintOnTextbox(&uroom->textState, gStringVar4)) { HandleCancelActivity(TRUE); - UpdateUnionRoomMemberFacing(taskData[0], taskData[1], uroom->field_0); + UpdateUnionRoomMemberFacing(taskData[0], taskData[1], uroom->playerList); uroom->state = UR_STATE_MAIN; } break; @@ -3224,7 +3260,7 @@ static void ReceiveUnionRoomActivityPacket(struct WirelessLink_URoom *data) } } -static bool32 UnionRoom_HandleContactFromOtherPlayer(struct WirelessLink_URoom *uroom) +static bool32 HandleContactFromOtherPlayer(struct WirelessLink_URoom *uroom) { if (uroom->recvActivityRequest[0] != 0) { @@ -3278,7 +3314,7 @@ static void Task_InitUnionRoom(u8 taskId) data->state = 1; break; case 1: - SetHostRFUtgtGname(ACTIVITY_SEARCH, 0, 0); + SetHostRfuGameData(ACTIVITY_SEARCH, 0, FALSE); SetWirelessCommType1(); OpenLink(); InitializeRfuLinkManager_EnterUnionRoom(); @@ -3286,30 +3322,30 @@ static void Task_InitUnionRoom(u8 taskId) data->state = 2; break; case 2: - 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->searchTaskId = CreateTask_SearchForChildOrParent(data->field_C, data->field_4, 10); + data->incomingChildList = AllocZeroed(RFU_CHILD_MAX * sizeof(struct RfuIncomingPlayer)); + ClearIncomingPlayerList(data->incomingChildList, RFU_CHILD_MAX); + data->incomingParentList = AllocZeroed(RFU_CHILD_MAX * sizeof(struct RfuIncomingPlayer)); + ClearIncomingPlayerList(data->incomingParentList, RFU_CHILD_MAX); + data->playerList = AllocZeroed(MAX_UNION_ROOM_LEADERS * sizeof(struct RfuPlayer)); + ClearRfuPlayerList(data->playerList->players, MAX_UNION_ROOM_LEADERS); + data->spawnPlayer = AllocZeroed(sizeof(struct RfuPlayer)); + ClearRfuPlayerList(&data->spawnPlayer->players[0], 1); + data->searchTaskId = CreateTask_SearchForChildOrParent(data->incomingParentList, data->incomingChildList, LINK_GROUP_UNION_ROOM_INIT); data->state = 3; break; case 3: switch (HandlePlayerListUpdate()) { - case 1: - case 2: + case PLIST_1: + case PLIST_2: if (sUnionRoomPlayerName[0] == EOS) { - for (i = 0; i < PLAYER_NAME_LENGTH + 1; i++) + for (i = 0; i < MAX_UNION_ROOM_LEADERS; i++) { - if (data->field_0->arr[i].groupScheduledAnim == UNION_ROOM_SPAWN_IN) + if (data->playerList->players[i].groupScheduledAnim == UNION_ROOM_SPAWN_IN) { - IntlConvPartnerUname7(text, &data->field_0->arr[i]); - if (PlayerHasMetTrainerBefore(ReadAsU16(data->field_0->arr[i].gname_uname.gname.unk_00.playerTrainerId), text)) + CopyAndTranslatePlayerName(text, &data->playerList->players[i]); + if (PlayerHasMetTrainerBefore(ReadAsU16(data->playerList->players[i].rfu.data.compatibility.playerTrainerId), text)) { StringCopy(sUnionRoomPlayerName, text); break; @@ -3318,15 +3354,15 @@ static void Task_InitUnionRoom(u8 taskId) } } break; - case 3: + case PLIST_3: break; } break; case 4: - free(data->field_8); - free(data->field_0); - free(data->field_C); - free(data->field_4); + free(data->spawnPlayer); + free(data->playerList); + free(data->incomingParentList); + free(data->incomingChildList); DestroyTask(data->searchTaskId); free(sWirelessLinkMain.uRoom); LinkRfu_Shutdown(); @@ -3354,160 +3390,150 @@ static u8 HandlePlayerListUpdate(void) s32 i; u8 j; struct WirelessLink_URoom *data = sWirelessLinkMain.uRoom; - s32 r7 = 0; + s32 retVal = PLIST_0; for (i = 0; i < RFU_CHILD_MAX; i++) { - if (AreGnameUnameDifferent(&data->field_C->arr[i].gname_uname, &sWirelessGnameUnamePair_Dummy) == TRUE) + if (ArePlayersDifferent(&data->incomingParentList->players[i].rfu, &sUnionRoomPlayer_DummyRfu) == TRUE) { - data->field_8->arr[0].gname_uname = data->field_C->arr[i].gname_uname; - data->field_8->arr[0].timeoutCounter = 0; - data->field_8->arr[0].groupScheduledAnim = UNION_ROOM_SPAWN_IN; - data->field_8->arr[0].field_1B = 1; - return 4; + data->spawnPlayer->players[0].rfu = data->incomingParentList->players[i].rfu; + data->spawnPlayer->players[0].timeoutCounter = 0; + data->spawnPlayer->players[0].groupScheduledAnim = UNION_ROOM_SPAWN_IN; + data->spawnPlayer->players[0].field_1B = 1; + return PLIST_4; } } - for (j = 0; j < ARRAY_COUNT(data->field_0->arr); j++) + for (j = 0; j < MAX_UNION_ROOM_LEADERS; j++) { - if (data->field_0->arr[j].groupScheduledAnim != UNION_ROOM_SPAWN_NONE) + if (data->playerList->players[j].groupScheduledAnim != UNION_ROOM_SPAWN_NONE) { - i = Findx20Inx1CArray(&data->field_0->arr[j], &data->field_4->arr[0]); + i = GetNewIncomingPlayerId(&data->playerList->players[j], &data->incomingChildList->players[0]); if (i != 0xFF) { - if (data->field_0->arr[j].groupScheduledAnim == UNION_ROOM_SPAWN_IN) + if (data->playerList->players[j].groupScheduledAnim == UNION_ROOM_SPAWN_IN) { - if (AreUnionRoomPlayerGnamesDifferent(&data->field_0->arr[j].gname_uname, &data->field_4->arr[i].gname_uname)) + if (ArePlayerDataDifferent(&data->playerList->players[j].rfu, &data->incomingChildList->players[i].rfu)) { - data->field_0->arr[j].gname_uname = data->field_4->arr[i].gname_uname; - data->field_0->arr[j].field_1B = 64; - r7 = 1; + data->playerList->players[j].rfu = data->incomingChildList->players[i].rfu; + data->playerList->players[j].field_1B = 64; + retVal = PLIST_1; } - else if (data->field_0->arr[j].field_1B != 0) + else if (data->playerList->players[j].field_1B != 0) { - data->field_0->arr[j].field_1B--; - if (data->field_0->arr[j].field_1B == 0) - r7 = 2; + data->playerList->players[j].field_1B--; + if (data->playerList->players[j].field_1B == 0) + retVal = PLIST_2; } } else { - data->field_0->arr[j].groupScheduledAnim = UNION_ROOM_SPAWN_IN; - data->field_0->arr[j].field_1B = 0; - r7 = 2; + data->playerList->players[j].groupScheduledAnim = UNION_ROOM_SPAWN_IN; + data->playerList->players[j].field_1B = 0; + retVal = PLIST_2; } - data->field_0->arr[j].timeoutCounter = 0; + data->playerList->players[j].timeoutCounter = 0; } - else if (data->field_0->arr[j].groupScheduledAnim != UNION_ROOM_SPAWN_OUT) + else if (data->playerList->players[j].groupScheduledAnim != UNION_ROOM_SPAWN_OUT) { - data->field_0->arr[j].timeoutCounter++; - if (data->field_0->arr[j].timeoutCounter >= 600) + data->playerList->players[j].timeoutCounter++; + if (data->playerList->players[j].timeoutCounter >= 600) { - data->field_0->arr[j].groupScheduledAnim = UNION_ROOM_SPAWN_OUT; - r7 = 2; + data->playerList->players[j].groupScheduledAnim = UNION_ROOM_SPAWN_OUT; + retVal = PLIST_2; } } - else if (data->field_0->arr[j].groupScheduledAnim == UNION_ROOM_SPAWN_OUT) + else if (data->playerList->players[j].groupScheduledAnim == UNION_ROOM_SPAWN_OUT) { - data->field_0->arr[j].timeoutCounter++; - if (data->field_0->arr[j].timeoutCounter >= 900) - { - ClearUnkStruct_x20Array(&data->field_0->arr[j], 1); - } + data->playerList->players[j].timeoutCounter++; + if (data->playerList->players[j].timeoutCounter >= 900) + ClearRfuPlayerList(&data->playerList->players[j], 1); } } } for (i = 0; i < RFU_CHILD_MAX; i++) - { - if (Appendx1Ctox20(&data->field_0->arr[0], &data->field_4->arr[i], MAX_UNION_ROOM_PLAYERS) != 0xFF) - r7 = 1; - } + if (TryAddIncomingPlayerToList(&data->playerList->players[0], &data->incomingChildList->players[i], MAX_UNION_ROOM_LEADERS) != 0xFF) + retVal = PLIST_1; - return r7; + return retVal; } static void Task_SearchForChildOrParent(u8 taskId) { s32 i, j; - struct WirelessGnameUnamePair gname_uname; - struct UnkStruct_Main4 **ptr = (void*) gTasks[taskId].data; + struct RfuPlayerData rfu; + struct RfuIncomingPlayerList **list = (void*) gTasks[taskId].data; bool8 isParent; for (i = 0; i < RFU_CHILD_MAX; i++) { - isParent = LinkRfu_GetNameIfCompatible(&gname_uname.gname, gname_uname.playerName, i); - if (!IsPartnerActivityAcceptable(gname_uname.gname.activity, gTasks[taskId].data[4])) - { - gname_uname = sWirelessGnameUnamePair_Dummy; - } - if (gname_uname.gname.unk_00.language == LANGUAGE_JAPANESE) - { - gname_uname = sWirelessGnameUnamePair_Dummy; - } + isParent = Rfu_GetCompatiblePlayerData(&rfu.data, rfu.name, i); + + if (!IsPartnerActivityAcceptable(rfu.data.activity, gTasks[taskId].data[4])) + rfu = sUnionRoomPlayer_DummyRfu; + if (rfu.data.compatibility.language == LANGUAGE_JAPANESE) + rfu = sUnionRoomPlayer_DummyRfu; + if (!isParent) { for (j = 0; j < i; j++) { - if (!AreGnameUnameDifferent(&ptr[1]->arr[j].gname_uname, &gname_uname)) - { - gname_uname = sWirelessGnameUnamePair_Dummy; - } + if (!ArePlayersDifferent(&list[1]->players[j].rfu, &rfu)) + rfu = sUnionRoomPlayer_DummyRfu; } - ptr[1]->arr[i].gname_uname = gname_uname; - ptr[1]->arr[i].active = AreGnameUnameDifferent(&ptr[1]->arr[i].gname_uname, &sWirelessGnameUnamePair_Dummy); + list[1]->players[i].rfu = rfu; + list[1]->players[i].active = ArePlayersDifferent(&list[1]->players[i].rfu, &sUnionRoomPlayer_DummyRfu); } else { - ptr[0]->arr[i].gname_uname = gname_uname; - ptr[0]->arr[i].active = AreGnameUnameDifferent(&ptr[0]->arr[i].gname_uname, &sWirelessGnameUnamePair_Dummy); + list[0]->players[i].rfu = rfu; + list[0]->players[i].active = ArePlayersDifferent(&list[0]->players[i].rfu, &sUnionRoomPlayer_DummyRfu); } } } -static u8 CreateTask_SearchForChildOrParent(struct UnkStruct_Main4 * main4_parent, struct UnkStruct_Main4 * main4_child, u32 linkGroup) +static u8 CreateTask_SearchForChildOrParent(struct RfuIncomingPlayerList * parentList, struct RfuIncomingPlayerList * childList, u32 linkGroup) { u8 taskId = CreateTask(Task_SearchForChildOrParent, 0); - struct UnkStruct_Main4 ** data = (void *)gTasks[taskId].data; - data[0] = main4_parent; - data[1] = main4_child; + struct RfuIncomingPlayerList ** data = (void *)gTasks[taskId].data; + data[0] = parentList; + data[1] = childList; gTasks[taskId].data[4] = linkGroup; return taskId; } -static void Task_ListenForPartnersWithCompatibleSerialNos(u8 taskId) +static void Task_ListenForCompatiblePartners(u8 taskId) { s32 i, j; - struct UnkStruct_Main4 **ptr = (void*) gTasks[taskId].data; + struct RfuIncomingPlayerList **list = (void*) gTasks[taskId].data; for (i = 0; i < RFU_CHILD_MAX; i++) { - 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])) + Rfu_GetCompatiblePlayerData(&list[0]->players[i].rfu.data, list[0]->players[i].rfu.name, i); + if (!IsPartnerActivityAcceptable(list[0]->players[i].rfu.data.activity, gTasks[taskId].data[2])) { - ptr[0]->arr[i].gname_uname = sWirelessGnameUnamePair_Dummy; + list[0]->players[i].rfu = sUnionRoomPlayer_DummyRfu; } for (j = 0; j < i; j++) { - if (!AreGnameUnameDifferent(&ptr[0]->arr[j].gname_uname, &ptr[0]->arr[i].gname_uname)) - { - ptr[0]->arr[i].gname_uname = sWirelessGnameUnamePair_Dummy; - } + if (!ArePlayersDifferent(&list[0]->players[j].rfu, &list[0]->players[i].rfu)) + list[0]->players[i].rfu = sUnionRoomPlayer_DummyRfu; } - ptr[0]->arr[i].active = AreGnameUnameDifferent(&ptr[0]->arr[i].gname_uname, &sWirelessGnameUnamePair_Dummy); + list[0]->players[i].active = ArePlayersDifferent(&list[0]->players[i].rfu, &sUnionRoomPlayer_DummyRfu); } } -static bool32 HasWonderCardOrNewsByLinkGroup(struct GFtgtGname *gname, s16 linkGroup) +static bool32 HasWonderCardOrNewsByLinkGroup(struct RfuGameData *data, s16 linkGroup) { if (linkGroup == LINK_GROUP_WONDER_CARD) { - if (!gname->unk_00.hasCard) + if (!data->compatibility.hasCard) return FALSE; else return TRUE; } else if (linkGroup == LINK_GROUP_WONDER_NEWS) { - if (!gname->unk_00.hasNews) + if (!data->compatibility.hasNews) return FALSE; else return TRUE; @@ -3518,35 +3544,34 @@ static bool32 HasWonderCardOrNewsByLinkGroup(struct GFtgtGname *gname, s16 linkG } } -static void Task_ListenForPartnersWithSerial7F7D(u8 taskId) +static void Task_ListenForWonderDistributor(u8 taskId) { s32 i; - struct UnkStruct_Main4 **ptr = (void*) gTasks[taskId].data; + struct RfuIncomingPlayerList **list = (void*) gTasks[taskId].data; for (i = 0; i < RFU_CHILD_MAX; i++) { - if (LinkRfu_GetNameIfSerial7F7D(&ptr[0]->arr[i].gname_uname.gname, ptr[0]->arr[i].gname_uname.playerName, i)) - { - HasWonderCardOrNewsByLinkGroup(&ptr[0]->arr[i].gname_uname.gname, gTasks[taskId].data[2]); - } - ptr[0]->arr[i].active = AreGnameUnameDifferent(&ptr[0]->arr[i].gname_uname, &sWirelessGnameUnamePair_Dummy); + if (Rfu_GetWonderDistributorPlayerData(&list[0]->players[i].rfu.data, list[0]->players[i].rfu.name, i)) + HasWonderCardOrNewsByLinkGroup(&list[0]->players[i].rfu.data, gTasks[taskId].data[2]); + + list[0]->players[i].active = ArePlayersDifferent(&list[0]->players[i].rfu, &sUnionRoomPlayer_DummyRfu); } } -static u8 CreateTask_ListenForPartnersWithCompatibleSerialNos(struct UnkStruct_Main4 * main4, u32 linkGroup) +static u8 CreateTask_ListenForCompatiblePartners(struct RfuIncomingPlayerList * list, u32 linkGroup) { - u8 taskId = CreateTask(Task_ListenForPartnersWithCompatibleSerialNos, 0); - struct UnkStruct_Main4 **ptr = (void*) gTasks[taskId].data; - ptr[0] = main4; + u8 taskId = CreateTask(Task_ListenForCompatiblePartners, 0); + struct RfuIncomingPlayerList **oldList = (void*) gTasks[taskId].data; + oldList[0] = list; gTasks[taskId].data[2] = linkGroup; return taskId; } -static u8 CreateTask_ListenForPartnersWithSerial7F7D(struct UnkStruct_Main4 * main4, u32 linkGroup) +static u8 CreateTask_ListenForWonderDistributor(struct RfuIncomingPlayerList * list, u32 linkGroup) { - u8 taskId = CreateTask(Task_ListenForPartnersWithSerial7F7D, 0); - struct UnkStruct_Main4 **ptr = (void*) gTasks[taskId].data; - ptr[0] = main4; + u8 taskId = CreateTask(Task_ListenForWonderDistributor, 0); + struct RfuIncomingPlayerList **oldList = (void*) gTasks[taskId].data; + oldList[0] = list; gTasks[taskId].data[2] = linkGroup; return taskId; } @@ -3560,7 +3585,7 @@ static bool32 UR_PrintFieldMessage(const u8 *src) return FALSE; } -static bool32 UR_RunTextPrinters_CheckPrinter0Active(void) +static bool32 UR_RunTextPrinters(void) { if (!RunTextPrintersAndIsPrinter0Active()) return TRUE; @@ -3598,9 +3623,7 @@ static s8 UnionRoomHandleYesNo(u8 *state, bool32 noDraw) { case 0: if (noDraw) - { return -3; - } DisplayYesNoMenuDefaultYes(); (*state)++; break; @@ -3612,14 +3635,14 @@ static s8 UnionRoomHandleYesNo(u8 *state, bool32 noDraw) return -3; } input = Menu_ProcessInputNoWrapClearOnChoose(); - if (input == -1 || input == 0 || input == 1) + if (input == MENU_B_PRESSED || input == 0 || input == 1) { *state = 0; return input; } break; } - return -2; + return MENU_NOTHING_CHOSEN; } static u8 CreateTradeBoardWindow(const struct WindowTemplate * template) @@ -3627,7 +3650,7 @@ static u8 CreateTradeBoardWindow(const struct WindowTemplate * template) u8 windowId = AddWindow(template); DrawStdWindowFrame(windowId, FALSE); FillWindowPixelBuffer(windowId, PIXEL_FILL(15)); - UR_AddTextPrinterParameterized(windowId, 1, sText_NameWantedOfferLv, 8, 1, 6); + PrintUnionRoomText(windowId, 1, sText_NameWantedOfferLv, 8, 1, UR_COLOR_TRADE_BOARD_OTHER); CopyWindowToVram(windowId, 2); PutWindowTilemap(windowId); return windowId; @@ -3649,13 +3672,11 @@ static s32 ListMenuHandler_AllItemsAvailable(u8 *state, u8 *windowId, u8 *listMe winTemplateCopy = *winTemplate; maxWidth = Intl_GetListMenuWidth(menuTemplate); if (winTemplateCopy.width > maxWidth) - { winTemplateCopy.width = maxWidth; - } + if (winTemplateCopy.tilemapLeft + winTemplateCopy.width > 29) - { winTemplateCopy.tilemapLeft = max(29 - winTemplateCopy.width, 0); - } + *windowId = AddWindow(&winTemplateCopy); DrawStdWindowFrame(*windowId, FALSE); gMultiuseListMenuTemplate = *menuTemplate; @@ -3688,7 +3709,10 @@ static s32 ListMenuHandler_AllItemsAvailable(u8 *state, u8 *windowId, u8 *listMe return -1; } -static s32 TradeBoardMenuHandler(u8 *state, u8 *windowId, u8 *listMenuId, u8 *tradeBoardWindowId, const struct WindowTemplate *winTemplate, const struct ListMenuTemplate *menuTemplate, struct UnkStruct_Main0 *traders) +static s32 TradeBoardMenuHandler(u8 *state, u8 *mainWindowId, u8 *listMenuId, u8 *headerWindowId, + const struct WindowTemplate *winTemplate, + const struct ListMenuTemplate *menuTemplate, + struct RfuPlayerList *list) { s32 input; s32 idx; @@ -3696,16 +3720,16 @@ static s32 TradeBoardMenuHandler(u8 *state, u8 *windowId, u8 *listMenuId, u8 *tr switch (*state) { case 0: - *tradeBoardWindowId = CreateTradeBoardWindow(&sWindowTemplate_TradingBoard); - *windowId = AddWindow(winTemplate); - DrawStdWindowFrame(*windowId, FALSE); + *headerWindowId = CreateTradeBoardWindow(&sWindowTemplate_TradingBoardHeader); + *mainWindowId = AddWindow(winTemplate); + DrawStdWindowFrame(*mainWindowId, FALSE); gMultiuseListMenuTemplate = *menuTemplate; - gMultiuseListMenuTemplate.windowId = *windowId; + gMultiuseListMenuTemplate.windowId = *mainWindowId; *listMenuId = ListMenuInit(&gMultiuseListMenuTemplate, 0, 1); (*state)++; break; case 1: - CopyWindowToVram(*windowId, TRUE); + CopyWindowToVram(*mainWindowId, TRUE); (*state)++; break; case 2: @@ -3715,19 +3739,19 @@ static s32 TradeBoardMenuHandler(u8 *state, u8 *windowId, u8 *listMenuId, u8 *tr if (input == 8 || JOY_NEW(B_BUTTON)) { DestroyListMenuTask(*listMenuId, NULL, NULL); - RemoveWindow(*windowId); - DeleteTradeBoardWindow(*tradeBoardWindowId); + RemoveWindow(*mainWindowId); + DeleteTradeBoardWindow(*headerWindowId); *state = 0; return -2; } else { - idx = GetIndexOfNthTradeBoardOffer(traders->arr, input); + idx = GetIndexOfNthTradeBoardOffer(list->players, input); if (idx >= 0) { DestroyListMenuTask(*listMenuId, NULL, NULL); - RemoveWindow(*windowId); - DeleteTradeBoardWindow(*tradeBoardWindowId); + RemoveWindow(*mainWindowId); + DeleteTradeBoardWindow(*headerWindowId); *state = 0; return idx; } @@ -3754,7 +3778,7 @@ static void JoinGroup_EnableScriptContexts(void) EnableBothScriptContexts(); } -static void UR_AddTextPrinterParameterized(u8 windowId, u8 fontId, const u8 *str, u8 x, u8 y, u8 colorIdx) +static void PrintUnionRoomText(u8 windowId, u8 fontId, const u8 *str, u8 x, u8 y, u8 colorIdx) { struct TextPrinterTemplate printerTemplate; @@ -3770,49 +3794,49 @@ static void UR_AddTextPrinterParameterized(u8 windowId, u8 fontId, const u8 *str gTextFlags.useAlternateDownArrow = FALSE; switch (colorIdx) { - case UR_COLOR_DKE_WHT_LTE: + case UR_COLOR_DEFAULT: printerTemplate.letterSpacing = 0; printerTemplate.lineSpacing = 0; printerTemplate.fgColor = TEXT_COLOR_DARK_GRAY; printerTemplate.bgColor = TEXT_COLOR_WHITE; printerTemplate.shadowColor = TEXT_COLOR_LIGHT_GRAY; break; - case UR_COLOR_RED_WHT_LTR: + case UR_COLOR_RED: printerTemplate.letterSpacing = 0; printerTemplate.lineSpacing = 0; printerTemplate.fgColor = TEXT_COLOR_RED; printerTemplate.bgColor = TEXT_COLOR_WHITE; printerTemplate.shadowColor = TEXT_COLOR_LIGHT_RED; break; - case UR_COLOR_GRN_WHT_LTG: + case UR_COLOR_GREEN: printerTemplate.letterSpacing = 0; printerTemplate.lineSpacing = 0; printerTemplate.fgColor = TEXT_COLOR_GREEN; printerTemplate.bgColor = TEXT_COLOR_WHITE; printerTemplate.shadowColor = TEXT_COLOR_LIGHT_GREEN; break; - case UR_COLOR_WHT_WHT_LTE: + case UR_COLOR_WHITE: printerTemplate.letterSpacing = 0; printerTemplate.lineSpacing = 0; printerTemplate.fgColor = TEXT_COLOR_WHITE; printerTemplate.bgColor = TEXT_COLOR_WHITE; printerTemplate.shadowColor = TEXT_COLOR_LIGHT_GRAY; break; - case UR_COLOR_WHT_DKE_LTE: + case UR_COLOR_CANCEL: printerTemplate.letterSpacing = 0; printerTemplate.lineSpacing = 0; printerTemplate.fgColor = TEXT_COLOR_WHITE; printerTemplate.bgColor = TEXT_COLOR_DARK_GRAY; printerTemplate.shadowColor = TEXT_COLOR_LIGHT_GRAY; break; - case UR_COLOR_GRN_DN6_LTB: + case UR_COLOR_TRADE_BOARD_SELF: printerTemplate.letterSpacing = 0; printerTemplate.lineSpacing = 0; printerTemplate.fgColor = TEXT_COLOR_LIGHT_GREEN; printerTemplate.bgColor = TEXT_DYNAMIC_COLOR_6; printerTemplate.shadowColor = TEXT_COLOR_LIGHT_BLUE; break; - case UR_COLOR_DN5_DN6_LTB: + case UR_COLOR_TRADE_BOARD_OTHER: printerTemplate.letterSpacing = 0; printerTemplate.lineSpacing = 0; printerTemplate.fgColor = TEXT_DYNAMIC_COLOR_5; @@ -3821,114 +3845,111 @@ static void UR_AddTextPrinterParameterized(u8 windowId, u8 fontId, const u8 *str break; } - AddTextPrinter(&printerTemplate, 0xFF, NULL); + AddTextPrinter(&printerTemplate, TEXT_SPEED_FF, NULL); } -static void ClearUnkStruct_x20Array(struct UnkStruct_x20 *arr, u8 count) +static void ClearRfuPlayerList(struct RfuPlayer *players, u8 count) { s32 i; for (i = 0; i < count; i++) { - arr[i].gname_uname = sWirelessGnameUnamePair_Dummy; - arr[i].timeoutCounter = 255; - arr[i].groupScheduledAnim = UNION_ROOM_SPAWN_NONE; - arr[i].useRedText = FALSE; - arr[i].field_1B = 0; + players[i].rfu = sUnionRoomPlayer_DummyRfu; + players[i].timeoutCounter = 255; + players[i].groupScheduledAnim = UNION_ROOM_SPAWN_NONE; + players[i].useRedText = FALSE; + players[i].field_1B = 0; } } -static void ClearUnkStruct_x1CArray(struct UnkStruct_Main4 *main4, u8 count) +static void ClearIncomingPlayerList(struct RfuIncomingPlayerList *list, u8 count) { s32 i; for (i = 0; i < RFU_CHILD_MAX; i++) { - main4->arr[i].gname_uname = sWirelessGnameUnamePair_Dummy; - main4->arr[i].active = FALSE; + list->players[i].rfu = sUnionRoomPlayer_DummyRfu; + list->players[i].active = FALSE; } } -static bool8 AreGnameUnameDifferent(struct WirelessGnameUnamePair* pair1, const struct WirelessGnameUnamePair* pair2) +// Checks player name and trainer id, returns TRUE if they are not the same +static bool8 ArePlayersDifferent(struct RfuPlayerData* player1, const struct RfuPlayerData* player2) { s32 i; for (i = 0; i < 2; i++) { - if (pair1->gname.unk_00.playerTrainerId[i] != pair2->gname.unk_00.playerTrainerId[i]) - { + if (player1->data.compatibility.playerTrainerId[i] != player2->data.compatibility.playerTrainerId[i]) return TRUE; - } } for (i = 0; i < PLAYER_NAME_LENGTH + 1; i++) { - if (pair1->playerName[i] != pair2->playerName[i]) - { + if (player1->name[i] != player2->name[i]) return TRUE; - } } return FALSE; } -static bool32 AreUnionRoomPlayerGnamesDifferent(struct WirelessGnameUnamePair *pair1, struct WirelessGnameUnamePair *pair2) +static bool32 ArePlayerDataDifferent(struct RfuPlayerData *player1, struct RfuPlayerData *player2) { s32 i; - if (pair1->gname.activity != pair2->gname.activity) + if (player1->data.activity != player2->data.activity) return TRUE; - if (pair1->gname.started != pair2->gname.started) + if (player1->data.startedActivity != player2->data.startedActivity) return TRUE; for (i = 0; i < RFU_CHILD_MAX; i++) { - if (pair1->gname.child_sprite_gender[i] != pair2->gname.child_sprite_gender[i]) + if (player1->data.partnerInfo[i] != player2->data.partnerInfo[i]) return TRUE; } - if (pair1->gname.species != pair2->gname.species) + if (player1->data.tradeSpecies != player2->data.tradeSpecies) return TRUE; - if (pair1->gname.type != pair2->gname.type) + if (player1->data.tradeType != player2->data.tradeType) return TRUE; return FALSE; } -static u32 Findx20Inx1CArray(struct UnkStruct_x20 *arg0, struct UnkStruct_x1C *arg1) +static u32 GetNewIncomingPlayerId(struct RfuPlayer *player, struct RfuIncomingPlayer *incomingPlayer) { - u8 result = 0xFF; + u8 result = 0xFF; // None s32 i; for (i = 0; i < RFU_CHILD_MAX; i++) { - if (arg1[i].active && !AreGnameUnameDifferent(&arg0->gname_uname, &arg1[i].gname_uname)) + if (incomingPlayer[i].active && !ArePlayersDifferent(&player->rfu, &incomingPlayer[i].rfu)) { result = i; - arg1[i].active = FALSE; + incomingPlayer[i].active = FALSE; } } return result; } -static u8 Appendx1Ctox20(struct UnkStruct_x20 *arg0, struct UnkStruct_x1C *arg1, u8 max) +static u8 TryAddIncomingPlayerToList(struct RfuPlayer *players, struct RfuIncomingPlayer *incomingPlayer, u8 max) { s32 i; - if (arg1->active) + if (incomingPlayer->active) { for (i = 0; i < max; i++) { - if (arg0[i].groupScheduledAnim == UNION_ROOM_SPAWN_NONE) + if (players[i].groupScheduledAnim == UNION_ROOM_SPAWN_NONE) { - arg0[i].gname_uname = arg1->gname_uname; - arg0[i].timeoutCounter = 0; - arg0[i].groupScheduledAnim = UNION_ROOM_SPAWN_IN; - arg0[i].field_1B = 64; - arg1->active = FALSE; + players[i].rfu = incomingPlayer->rfu; + players[i].timeoutCounter = 0; + players[i].groupScheduledAnim = UNION_ROOM_SPAWN_IN; + players[i].field_1B = 64; + incomingPlayer->active = FALSE; return i; } } @@ -3937,39 +3958,39 @@ static u8 Appendx1Ctox20(struct UnkStruct_x20 *arg0, struct UnkStruct_x1C *arg1, return 0xFF; } -static void PrintUnionRoomGroupOnWindow(u8 windowId, u8 x, u8 y, struct UnkStruct_x20 *group, u8 colorIdx, u8 id) +static void PrintGroupMemberOnWindow(u8 windowId, u8 x, u8 y, struct RfuPlayer *player, u8 colorIdx, u8 id) { u8 activity; u8 trainerId[6]; ConvertIntToDecimalStringN(gStringVar4, id + 1, STR_CONV_MODE_LEADING_ZEROS, 2); StringAppend(gStringVar4, sText_Colon); - UR_AddTextPrinterParameterized(windowId, 1, gStringVar4, x, y, 0); + PrintUnionRoomText(windowId, 1, gStringVar4, x, y, UR_COLOR_DEFAULT); x += 18; - activity = group->gname_uname.gname.activity; - if (group->groupScheduledAnim == UNION_ROOM_SPAWN_IN && !(activity & IN_UNION_ROOM)) + activity = player->rfu.data.activity; + if (player->groupScheduledAnim == UNION_ROOM_SPAWN_IN && !(activity & IN_UNION_ROOM)) { - 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); + CopyAndTranslatePlayerName(gStringVar4, player); + PrintUnionRoomText(windowId, 1, gStringVar4, x, y, colorIdx); + ConvertIntToDecimalStringN(trainerId, player->rfu.data.compatibility.playerTrainerId[0] | (player->rfu.data.compatibility.playerTrainerId[1] << 8), STR_CONV_MODE_LEADING_ZEROS, 5); StringCopy(gStringVar4, sText_ID); StringAppend(gStringVar4, trainerId); - UR_AddTextPrinterParameterized(windowId, 1, gStringVar4, GetStringRightAlignXOffset(1, gStringVar4, 0x88), y, colorIdx); + PrintUnionRoomText(windowId, 1, gStringVar4, GetStringRightAlignXOffset(1, gStringVar4, 0x88), y, colorIdx); } } -static void PrintGroupMemberCandidateOnWindowWithColor(u8 windowId, u8 x, u8 y, struct UnkStruct_x20 *group, u8 colorIdx, u8 id) +static void PrintGroupCandidateOnWindow(u8 windowId, u8 x, u8 y, struct RfuPlayer *player, u8 colorIdx, u8 id) { u8 trainerId[6]; - if (group->groupScheduledAnim == UNION_ROOM_SPAWN_IN) + if (player->groupScheduledAnim == UNION_ROOM_SPAWN_IN) { - 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); + CopyAndTranslatePlayerName(gStringVar4, player); + PrintUnionRoomText(windowId, 1, gStringVar4, x, y, colorIdx); + ConvertIntToDecimalStringN(trainerId, player->rfu.data.compatibility.playerTrainerId[0] | (player->rfu.data.compatibility.playerTrainerId[1] << 8), STR_CONV_MODE_LEADING_ZEROS, 5); StringCopy(gStringVar4, sText_ID); StringAppend(gStringVar4, trainerId); - UR_AddTextPrinterParameterized(windowId, 1, gStringVar4, GetStringRightAlignXOffset(1, gStringVar4, 0x68), y, colorIdx); + PrintUnionRoomText(windowId, 1, gStringVar4, GetStringRightAlignXOffset(1, gStringVar4, 0x68), y, colorIdx); } } @@ -4006,24 +4027,24 @@ static u32 GetResponseIdx_InviteToURoomActivity(s32 activity) } } -static u32 ConvPartnerUnameAndGetWhetherMetAlready(struct UnkStruct_x20 *arg0) +static u32 ConvPartnerUnameAndGetWhetherMetAlready(struct RfuPlayer *player) { u8 name[30]; - IntlConvPartnerUname7(name, arg0); - return PlayerHasMetTrainerBefore(ReadAsU16(arg0->gname_uname.gname.unk_00.playerTrainerId), name); + CopyAndTranslatePlayerName(name, player); + return PlayerHasMetTrainerBefore(ReadAsU16(player->rfu.data.compatibility.playerTrainerId), name); } -static s32 UnionRoomGetPlayerInteractionResponse(struct UnkStruct_Main0 *main0, bool8 overrideGender, u8 playerIdx, u32 playerGender) +static s32 UnionRoomGetPlayerInteractionResponse(struct RfuPlayerList *list, bool8 overrideGender, u8 playerIdx, u32 playerGender) { bool32 metBefore; - struct UnkStruct_x20 * r5 = &main0->arr[playerIdx]; + struct RfuPlayer * player = &list->players[playerIdx]; - if (!r5->gname_uname.gname.started && !overrideGender) + if (!player->rfu.data.startedActivity && !overrideGender) { - 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)) + CopyAndTranslatePlayerName(gStringVar1, player); + metBefore = PlayerHasMetTrainerBefore(ReadAsU16(player->rfu.data.compatibility.playerTrainerId), gStringVar1); + if (player->rfu.data.activity == (ACTIVITY_CHAT | IN_UNION_ROOM)) { StringExpandPlaceholders(gStringVar4, sJoinChatTexts[metBefore][playerGender]); return 2; @@ -4036,12 +4057,12 @@ static s32 UnionRoomGetPlayerInteractionResponse(struct UnkStruct_Main0 *main0, } else { - IntlConvPartnerUname7(gStringVar1, r5); + CopyAndTranslatePlayerName(gStringVar1, player); if (overrideGender) { - playerGender = (r5->gname_uname.gname.unk_00.playerTrainerId[overrideGender + 1] >> 3) & 1; + playerGender = (player->rfu.data.compatibility.playerTrainerId[overrideGender + 1] >> 3) & 1; } - switch (r5->gname_uname.gname.activity & 0x3F) + switch (player->rfu.data.activity & 0x3F) { case ACTIVITY_BATTLE_SINGLE: StringExpandPlaceholders(gStringVar4, sBattleReactionTexts[playerGender][Random() % ARRAY_COUNT(sBattleReactionTexts[0])]); @@ -4067,84 +4088,78 @@ void ItemPrintFunc_EmptyList(u8 windowId, u32 itemId, u8 y) { } -static void TradeBoardPrintItemInfo(u8 windowId, u8 y, struct GFtgtGname * gname, const u8 * uname, u8 colorIdx) +static void TradeBoardPrintItemInfo(u8 windowId, u8 y, struct RfuGameData * data, const u8 * playerName, u8 colorIdx) { u8 levelStr[4]; - u16 species = gname->species; - u8 type = gname->type; - u8 level = gname->level; + u16 species = data->tradeSpecies; + u8 type = data->tradeType; + u8 level = data->tradeLevel; - UR_AddTextPrinterParameterized(windowId, 1, uname, 8, y, colorIdx); + PrintUnionRoomText(windowId, 1, playerName, 8, y, colorIdx); if (species == SPECIES_EGG) { - UR_AddTextPrinterParameterized(windowId, 1, sText_EggTrade, 68, y, colorIdx); + PrintUnionRoomText(windowId, 1, sText_EggTrade, 68, y, colorIdx); } else { BlitMenuInfoIcon(windowId, type + 1, 68, y); - UR_AddTextPrinterParameterized(windowId, 1, gSpeciesNames[species], 118, y, colorIdx); + PrintUnionRoomText(windowId, 1, gSpeciesNames[species], 118, y, colorIdx); ConvertIntToDecimalStringN(levelStr, level, STR_CONV_MODE_RIGHT_ALIGN, 3); - UR_AddTextPrinterParameterized(windowId, 1, levelStr, 198, y, colorIdx); + PrintUnionRoomText(windowId, 1, levelStr, 198, y, colorIdx); } } static void TradeBoardListMenuItemPrintFunc(u8 windowId, u32 itemId, u8 y) { - struct WirelessLink_Leader *data = sWirelessLinkMain.leader; - struct GFtgtGname *rfu; + struct WirelessLink_Leader *leader = sWirelessLinkMain.leader; + struct RfuGameData *gameData; s32 i, j; u8 playerName[11]; - if (itemId == -3 && y == sTradeBoardListMenuTemplate.upText_Y) + if (itemId == LIST_HEADER && y == sTradeBoardListMenuTemplate.upText_Y) { - rfu = GetHostRFUtgtGname(); - if (rfu->species != SPECIES_NONE) - { - TradeBoardPrintItemInfo(windowId, y, rfu, gSaveBlock2Ptr->playerName, 5); - } + gameData = GetHostRfuGameData(); + if (gameData->tradeSpecies != SPECIES_NONE) + TradeBoardPrintItemInfo(windowId, y, gameData, gSaveBlock2Ptr->playerName, UR_COLOR_TRADE_BOARD_SELF); } else { j = 0; - for (i = 0; i < (int)ARRAY_COUNT(data->field_0->arr); i++) + for (i = 0; i < MAX_UNION_ROOM_LEADERS; i++) { - if (data->field_0->arr[i].groupScheduledAnim == UNION_ROOM_SPAWN_IN && data->field_0->arr[i].gname_uname.gname.species != SPECIES_NONE) - { + if (leader->playerList->players[i].groupScheduledAnim == UNION_ROOM_SPAWN_IN && leader->playerList->players[i].rfu.data.tradeSpecies != SPECIES_NONE) j++; - } + if (j == itemId + 1) { - IntlConvPartnerUname7(playerName, &data->field_0->arr[i]); - TradeBoardPrintItemInfo(windowId, y, &data->field_0->arr[i].gname_uname.gname, playerName, 6); + CopyAndTranslatePlayerName(playerName, &leader->playerList->players[i]); + TradeBoardPrintItemInfo(windowId, y, &leader->playerList->players[i].rfu.data, playerName, UR_COLOR_TRADE_BOARD_OTHER); break; } } } } -static s32 GetIndexOfNthTradeBoardOffer(struct UnkStruct_x20 * arg, s32 n) +static s32 GetIndexOfNthTradeBoardOffer(struct RfuPlayer * players, s32 n) { s32 i; s32 j = 0; - for (i = 0; i < 8; i++) + for (i = 0; i < MAX_UNION_ROOM_LEADERS; i++) { - if (arg[i].groupScheduledAnim == UNION_ROOM_SPAWN_IN && arg[i].gname_uname.gname.species != SPECIES_NONE) - { + if (players[i].groupScheduledAnim == UNION_ROOM_SPAWN_IN && players[i].rfu.data.tradeSpecies != SPECIES_NONE) j++; - } + if (j == n + 1) - { return i; - } } return -1; } -static s32 GetUnionRoomPlayerGender(s32 playerIdx, struct UnkStruct_Main0 *main0) +static s32 GetUnionRoomPlayerGender(s32 playerIdx, struct RfuPlayerList *list) { - return main0->arr[playerIdx].gname_uname.gname.playerGender; + return list->players[playerIdx].rfu.data.playerGender; } static s32 IsRequestedTypeOrEggInPlayerParty(u32 type, u32 species) @@ -4157,9 +4172,7 @@ static s32 IsRequestedTypeOrEggInPlayerParty(u32 type, u32 species) { species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2); if (species == SPECIES_EGG) - { return UR_TRADE_MATCH; - } } return UR_TRADE_NOEGG; } @@ -4169,9 +4182,7 @@ static s32 IsRequestedTypeOrEggInPlayerParty(u32 type, u32 species) { species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2); if (gBaseStats[species].type1 == type || gBaseStats[species].type2 == type) - { return UR_TRADE_MATCH; - } } return UR_TRADE_NOTYPE; } @@ -4236,7 +4247,7 @@ static s32 GetChatLeaderActionRequestMessage(u8 *dst, u32 gender, u16 *activityD StringCopy(uroom->activityRequestStrbufs[1], gSpeciesNames[sUnionRoomTrade.playerSpecies]); for (i = 0; i < RFU_CHILD_MAX; i++) { - if (gRfuLinkStatus->partner[i].serialNo == RFU_SERIAL_A) + if (gRfuLinkStatus->partner[i].serialNo == RFU_SERIAL_GAME) { ConvertIntToDecimalStringN(uroom->activityRequestStrbufs[2], activityData[2], STR_CONV_MODE_LEFT_ALIGN, 3); StringCopy(uroom->activityRequestStrbufs[3], gSpeciesNames[activityData[1]]); @@ -4251,9 +4262,7 @@ static s32 GetChatLeaderActionRequestMessage(u8 *dst, u32 gender, u16 *activityD else { for (i = 0; i < RFU_CHILD_MAX; i++) - { DynamicPlaceholderTextUtil_SetPlaceholderPtr(i, uroom->activityRequestStrbufs[i]); - } DynamicPlaceholderTextUtil_ExpandPlaceholders(dst, sText_OfferToTradeMon); } result = 1; @@ -4291,9 +4300,9 @@ static bool32 PollPartnerYesNoResponse(struct WirelessLink_URoom *data) bool32 InUnionRoom(void) { - return gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(UNION_ROOM) - && gSaveBlock1Ptr->location.mapNum == MAP_NUM(UNION_ROOM) - ? TRUE : FALSE; + return gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(UNION_ROOM) + && gSaveBlock1Ptr->location.mapNum == MAP_NUM(UNION_ROOM) + ? TRUE : FALSE; } static bool32 HasAtLeastTwoMonsOfLevel30OrLower(void) @@ -4304,10 +4313,8 @@ static bool32 HasAtLeastTwoMonsOfLevel30OrLower(void) for (i = 0; i < gPlayerPartyCount; i++) { if (GetMonData(&gPlayerParty[i], MON_DATA_LEVEL) <= 30 - && GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2) != SPECIES_EGG) - { + && GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2) != SPECIES_EGG) count++; - } } if (count > 1) @@ -4316,16 +4323,16 @@ static bool32 HasAtLeastTwoMonsOfLevel30OrLower(void) return FALSE; } -static void ResetUnionRoomTrade(struct UnionRoomTrade *uroomTrade) +static void ResetUnionRoomTrade(struct UnionRoomTrade *trade) { - uroomTrade->state = URTRADE_STATE_NONE; - uroomTrade->type = 0; - uroomTrade->playerPersonality = 0; - uroomTrade->playerSpecies = 0; - uroomTrade->playerLevel = 0; - uroomTrade->species = 0; - uroomTrade->level = 0; - uroomTrade->personality = 0; + trade->state = URTRADE_STATE_NONE; + trade->type = 0; + trade->playerPersonality = 0; + trade->playerSpecies = SPECIES_NONE; + trade->playerLevel = 0; + trade->species = SPECIES_NONE; + trade->level = 0; + trade->personality = 0; } void Script_ResetUnionRoomTrade(void) @@ -4360,31 +4367,26 @@ static u32 GetPartyPositionOfRegisteredMon(struct UnionRoomTrade *trade, u8 mult u16 cur_species; s32 i; - // player if (multiplayerId == 0) { species = trade->playerSpecies; personality = trade->playerPersonality; } - // partner else { species = trade->species; personality = trade->personality; } + // Find party position by comparing to personality and species for (i = 0; i < gPlayerPartyCount; i++) { cur_personality = GetMonData(&gPlayerParty[i], MON_DATA_PERSONALITY); if (cur_personality != personality) - { continue; - } cur_species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2); if (cur_species != species) - { continue; - } response = i; break; } @@ -4405,23 +4407,23 @@ static void HandleCancelActivity(bool32 setData) } } -static void UR_EnableScriptContext2AndFreezeObjectEvents(void) +static void StartScriptInteraction(void) { ScriptContext2_Enable(); FreezeObjects_WaitForPlayer(); } -static u8 GetActivePartnerSpriteGenderParam(struct WirelessLink_URoom *data) +static u8 GetActivePartnersInfo(struct WirelessLink_URoom *data) { - u8 retVal = 0x80; + u8 retVal = PINFO_ACTIVE_FLAG; u8 i; for (i = 0; i < RFU_CHILD_MAX; i++) { - if (data->field_C->arr[i].active) + if (data->incomingParentList->players[i].active) { - 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; + retVal |= data->incomingParentList->players[i].rfu.data.playerGender << PINFO_GENDER_SHIFT; + retVal |= data->incomingParentList->players[i].rfu.data.compatibility.playerTrainerId[0] & PINFO_TID_MASK; break; } } @@ -4458,17 +4460,13 @@ static void ViewURoomPartnerTrainerCard(u8 *unused, struct WirelessLink_URoom *d n = trainerCard->linkBattleWins; if (n > 9999) - { n = 9999; - } ConvertIntToDecimalStringN(data->trainerCardStrBuffer[0], n, STR_CONV_MODE_LEFT_ALIGN, 4); DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, data->trainerCardStrBuffer[0]); n = trainerCard->linkBattleLosses; if (n > 9999) - { n = 9999; - } ConvertIntToDecimalStringN(data->trainerCardStrBuffer[1], n, STR_CONV_MODE_LEFT_ALIGN, 4); DynamicPlaceholderTextUtil_SetPlaceholderPtr(2, data->trainerCardStrBuffer[1]); @@ -4496,8 +4494,8 @@ static void ViewURoomPartnerTrainerCard(u8 *unused, struct WirelessLink_URoom *d } } -static void IntlConvPartnerUname7(u8 *dest, struct UnkStruct_x20 *arg1) +static void CopyAndTranslatePlayerName(u8 *dest, struct RfuPlayer *player) { - StringCopy7(dest, arg1->gname_uname.playerName); - ConvertInternationalString(dest, arg1->gname_uname.gname.unk_00.language); + StringCopy7(dest, player->rfu.name); + ConvertInternationalString(dest, player->rfu.data.compatibility.language); } diff --git a/src/union_room_player_avatar.c b/src/union_room_player_avatar.c index 671290e21..9a0f1a883 100644 --- a/src/union_room_player_avatar.c +++ b/src/union_room_player_avatar.c @@ -9,8 +9,12 @@ #include "constants/event_objects.h" #include "constants/event_object_movement.h" -#define UR_SPRITE_START_ID (MAX_SPRITES - MAX_UNION_ROOM_PLAYERS) -#define UR_PLAYER_SPRITE_ID(playerIdx, facingDir)(5 * playerIdx + facingDir) +#define UR_SPRITE_START_ID (MAX_SPRITES - MAX_UNION_ROOM_LEADERS) + +// Each parent player can lead a group of up to MAX_RFU_PLAYERS (including themselves). +// Multiply the leader's id by MAX_RFU_PLAYERS and add the member's id (0 if the leader) to +// get the sprite index of that player. +#define UR_PLAYER_SPRITE_ID(leaderId, memberId)(MAX_RFU_PLAYERS * leaderId + memberId) static EWRAM_DATA struct UnionRoomObject * sUnionObjWork = NULL; static EWRAM_DATA u32 sUnionObjRefreshTimer = 0; @@ -19,7 +23,8 @@ static u8 CreateTask_AnimateUnionRoomPlayers(void); static u32 IsUnionRoomPlayerInvisible(u32, u32); static void SetUnionRoomObjectFacingDirection(s32, s32, u8); -static const u8 sUnionRoomObjGfxIds[GENDER_COUNT][MAX_UNION_ROOM_PLAYERS + 2] = { +// + 2 is just to match, those elements are empty and never read +static const u8 sUnionRoomObjGfxIds[GENDER_COUNT][MAX_UNION_ROOM_LEADERS + 2] = { [MALE] = { OBJ_EVENT_GFX_MAN_3, OBJ_EVENT_GFX_BLACK_BELT, @@ -42,7 +47,7 @@ static const u8 sUnionRoomObjGfxIds[GENDER_COUNT][MAX_UNION_ROOM_PLAYERS + 2] = } }; -static const s16 sUnionRoomPlayerCoords[MAX_UNION_ROOM_PLAYERS][2] = { +static const s16 sUnionRoomPlayerCoords[MAX_UNION_ROOM_LEADERS][2] = { { 4, 6}, {13, 8}, {10, 6}, @@ -53,12 +58,16 @@ static const s16 sUnionRoomPlayerCoords[MAX_UNION_ROOM_PLAYERS][2] = { { 7, 8} }; -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} +// If there's a group of players interacting in the Union Room, the group +// leader will be at one of the positions above and each member in the group +// will be at one of the offsets from that position below. The leader will +// be at the first offset (0,0), as they're at the center. +static const s8 sUnionRoomGroupOffsets[MAX_RFU_PLAYERS][2] = { + { 0, 0}, // Center + { 1, 0}, // Left + { 0, -1}, // Top + {-1, 0}, // Right + { 0, 1} // Bottom }; static const u8 sOppositeFacingDirection[] = { @@ -69,12 +78,14 @@ static const u8 sOppositeFacingDirection[] = { [DIR_EAST] = DIR_WEST }; -static const u8 sNextFacingDirection[] = { - [DIR_NONE] = DIR_SOUTH, - [DIR_SOUTH] = DIR_WEST, - [DIR_NORTH] = DIR_SOUTH, - [DIR_WEST] = DIR_EAST, - [DIR_EAST] = DIR_NORTH +// Compare to sUnionRoomGroupOffsets, the direction each group member +// needs to be facing in order to face the group leader in the center. +static const u8 sMemberFacingDirections[MAX_RFU_PLAYERS] = { + DIR_SOUTH, // Leader, but never read + DIR_WEST, + DIR_SOUTH, + DIR_EAST, + DIR_NORTH }; static const u8 sUnionRoomLocalIds[] = { @@ -118,21 +129,22 @@ static bool32 IsPlayerStandingStill(void) return FALSE; } +// Gender and trainer id are used to determine which sprite a player appears as static u8 GetUnionRoomPlayerGraphicsId(u32 gender, u32 id) { - return sUnionRoomObjGfxIds[gender][id % MAX_UNION_ROOM_PLAYERS]; + return sUnionRoomObjGfxIds[gender][id % MAX_UNION_ROOM_LEADERS]; } -static void GetUnionRoomPlayerFacingCoords(u32 playerIdx, u32 direction, s32 * x, s32 * y) +static void GetUnionRoomPlayerCoords(u32 leaderId, u32 memberId, s32 * x, s32 * y) { - *x = sUnionRoomPlayerCoords[playerIdx][0] + sFacingDirectionOffsets[direction][0] + 7; - *y = sUnionRoomPlayerCoords[playerIdx][1] + sFacingDirectionOffsets[direction][1] + 7; + *x = sUnionRoomPlayerCoords[leaderId][0] + sUnionRoomGroupOffsets[memberId][0] + 7; + *y = sUnionRoomPlayerCoords[leaderId][1] + sUnionRoomGroupOffsets[memberId][1] + 7; } -static bool32 IsUnionRoomPlayerFacingTileAt(u32 playerIdx, u32 direction, s32 x, s32 y) +static bool32 IsUnionRoomPlayerAt(u32 leaderId, u32 memberId, s32 x, s32 y) { - if ((sUnionRoomPlayerCoords[playerIdx][0] + sFacingDirectionOffsets[direction][0] + 7 == x) - && (sUnionRoomPlayerCoords[playerIdx][1] + sFacingDirectionOffsets[direction][1] + 7 == y)) + if ((sUnionRoomPlayerCoords[leaderId][0] + sUnionRoomGroupOffsets[memberId][0] + 7 == x) + && (sUnionRoomPlayerCoords[leaderId][1] + sUnionRoomGroupOffsets[memberId][1] + 7 == y)) return TRUE; else return FALSE; @@ -153,62 +165,50 @@ static void ShowUnionRoomPlayer(u32 player_idx) FlagClear(FLAG_HIDE_UNION_ROOM_PLAYER_1 + player_idx); } -static void SetUnionRoomPlayerGfx(u32 playerIdx, u32 gfxId) +static void SetUnionRoomPlayerGfx(u32 leaderId, u32 gfxId) { - VarSet(VAR_OBJ_GFX_ID_0 + playerIdx, gfxId); + VarSet(VAR_OBJ_GFX_ID_0 + leaderId, gfxId); } -static void CreateUnionRoomPlayerObjectEvent(u32 playerIdx) +static void CreateUnionRoomPlayerObjectEvent(u32 leaderId) { - TrySpawnObjectEvent(sUnionRoomLocalIds[playerIdx], gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup); + TrySpawnObjectEvent(sUnionRoomLocalIds[leaderId], gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup); } -static void RemoveUnionRoomPlayerObjectEvent(u32 playerIdx) +static void RemoveUnionRoomPlayerObjectEvent(u32 leaderId) { - RemoveObjectEventByLocalIdAndMap(sUnionRoomLocalIds[playerIdx], gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup); + RemoveObjectEventByLocalIdAndMap(sUnionRoomLocalIds[leaderId], gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup); } -static bool32 SetUnionRoomPlayerEnterExitMovement(u32 playerIdx, const u8 * movement) +static bool32 SetUnionRoomPlayerEnterExitMovement(u32 leaderId, const u8 * movement) { u8 objectId; struct ObjectEvent * object; - if (TryGetObjectEventIdByLocalIdAndMap(sUnionRoomLocalIds[playerIdx], gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, &objectId)) - { + if (TryGetObjectEventIdByLocalIdAndMap(sUnionRoomLocalIds[leaderId], gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, &objectId)) return FALSE; - } object = &gObjectEvents[objectId]; if (ObjectEventIsMovementOverridden(object)) - { return FALSE; - } if (ObjectEventSetHeldMovement(object, *movement)) - { return FALSE; - } return TRUE; } -static bool32 TryReleaseUnionRoomPlayerObjectEvent(u32 playerIdx) +static bool32 TryReleaseUnionRoomPlayerObjectEvent(u32 leaderId) { u8 objectId; struct ObjectEvent * object; - if (TryGetObjectEventIdByLocalIdAndMap(sUnionRoomLocalIds[playerIdx], gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, &objectId)) - { + if (TryGetObjectEventIdByLocalIdAndMap(sUnionRoomLocalIds[leaderId], gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, &objectId)) return TRUE; - } + object = &gObjectEvents[objectId]; if (!ObjectEventClearHeldMovementIfFinished(object)) - { return FALSE; - } + if (!ScriptContext2_IsEnabled()) - { UnfreezeObjectEvent(object); - } else - { FreezeObjectEvent(object); - } return TRUE; } @@ -218,7 +218,7 @@ u8 InitUnionRoomPlayerObjects(struct UnionRoomObject * players) sUnionObjRefreshTimer = 0; sUnionObjWork = players; - for (i = 0; i < MAX_UNION_ROOM_PLAYERS; i++) + for (i = 0; i < MAX_UNION_ROOM_LEADERS; i++) { players[i].state = 0; players[i].gfxId = 0; @@ -228,22 +228,22 @@ u8 InitUnionRoomPlayerObjects(struct UnionRoomObject * players) return CreateTask_AnimateUnionRoomPlayers(); } -static bool32 AnimateUnionRoomPlayerDespawn(s8 * state, u32 playerIdx, struct UnionRoomObject * ptr) +static bool32 AnimateUnionRoomPlayerDespawn(s8 * state, u32 leaderId, struct UnionRoomObject * object) { switch (*state) { case 0: - if (SetUnionRoomPlayerEnterExitMovement(playerIdx, sMovement_UnionPlayerExit) == TRUE) + if (SetUnionRoomPlayerEnterExitMovement(leaderId, sMovement_UnionPlayerExit) == TRUE) { - HideUnionRoomPlayer(playerIdx); + HideUnionRoomPlayer(leaderId); (*state)++; } break; case 1: - if (TryReleaseUnionRoomPlayerObjectEvent(playerIdx)) + if (TryReleaseUnionRoomPlayerObjectEvent(leaderId)) { - RemoveUnionRoomPlayerObjectEvent(playerIdx); - HideUnionRoomPlayer(playerIdx); + RemoveUnionRoomPlayerObjectEvent(leaderId); + HideUnionRoomPlayer(leaderId); *state = 0; return TRUE; } @@ -252,7 +252,7 @@ static bool32 AnimateUnionRoomPlayerDespawn(s8 * state, u32 playerIdx, struct Un return FALSE; } -static bool32 AnimateUnionRoomPlayerSpawn(s8 * state, u32 playerIdx, struct UnionRoomObject * ptr) +static bool32 AnimateUnionRoomPlayerSpawn(s8 * state, u32 leaderId, struct UnionRoomObject * object) { s16 x, y; @@ -260,32 +260,24 @@ static bool32 AnimateUnionRoomPlayerSpawn(s8 * state, u32 playerIdx, struct Unio { case 0: if (!IsPlayerStandingStill()) - { break; - } PlayerGetDestCoords(&x, &y); - if (IsUnionRoomPlayerFacingTileAt(playerIdx, 0, x, y) == TRUE) - { + if (IsUnionRoomPlayerAt(leaderId, 0, x, y) == TRUE) break; - } player_get_pos_including_state_based_drift(&x, &y); - if (IsUnionRoomPlayerFacingTileAt(playerIdx, 0, x, y) == TRUE) - { + if (IsUnionRoomPlayerAt(leaderId, 0, x, y) == TRUE) break; - } - SetUnionRoomPlayerGfx(playerIdx, ptr->gfxId); - CreateUnionRoomPlayerObjectEvent(playerIdx); - ShowUnionRoomPlayer(playerIdx); + SetUnionRoomPlayerGfx(leaderId, object->gfxId); + CreateUnionRoomPlayerObjectEvent(leaderId); + ShowUnionRoomPlayer(leaderId); (*state)++; // fallthrough case 3: // incorrect? - if (SetUnionRoomPlayerEnterExitMovement(playerIdx, sMovement_UnionPlayerEnter) == TRUE) - { + if (SetUnionRoomPlayerEnterExitMovement(leaderId, sMovement_UnionPlayerEnter) == TRUE) (*state)++; - } break; case 2: - if (TryReleaseUnionRoomPlayerObjectEvent(playerIdx)) + if (TryReleaseUnionRoomPlayerObjectEvent(leaderId)) { *state = 0; return TRUE; @@ -295,38 +287,38 @@ static bool32 AnimateUnionRoomPlayerSpawn(s8 * state, u32 playerIdx, struct Unio return FALSE; } -static bool32 SpawnGroupLeader(u32 playerIdx, u32 gender, u32 id) +static bool32 SpawnGroupLeader(u32 leaderId, u32 gender, u32 id) { - struct UnionRoomObject * ptr = &sUnionObjWork[playerIdx]; - ptr->schedAnim = UNION_ROOM_SPAWN_IN; - ptr->gfxId = GetUnionRoomPlayerGraphicsId(gender, id); + struct UnionRoomObject * object = &sUnionObjWork[leaderId]; + object->schedAnim = UNION_ROOM_SPAWN_IN; + object->gfxId = GetUnionRoomPlayerGraphicsId(gender, id); - if (ptr->state == 0) + if (object->state == 0) return TRUE; else return FALSE; } -static bool32 DespawnGroupLeader(u32 playerIdx) +static bool32 DespawnGroupLeader(u32 leaderId) { - struct UnionRoomObject * ptr = &sUnionObjWork[playerIdx]; - ptr->schedAnim = UNION_ROOM_SPAWN_OUT; + struct UnionRoomObject * object = &sUnionObjWork[leaderId]; + object->schedAnim = UNION_ROOM_SPAWN_OUT; - if (ptr->state == 1) + if (object->state == 1) return TRUE; else return FALSE; } -static void AnimateUnionRoomPlayer(u32 playerIdx, struct UnionRoomObject * ptr) +static void AnimateUnionRoomPlayer(u32 leaderId, struct UnionRoomObject * object) { - switch (ptr->state) + switch (object->state) { case 0: - if (ptr->schedAnim == UNION_ROOM_SPAWN_IN) + if (object->schedAnim == UNION_ROOM_SPAWN_IN) { - ptr->state = 2; - ptr->animState = 0; + object->state = 2; + object->animState = 0; } else { @@ -334,23 +326,23 @@ static void AnimateUnionRoomPlayer(u32 playerIdx, struct UnionRoomObject * ptr) } // fallthrough case 2: - if (!IsUnionRoomPlayerInvisible(playerIdx, 0) && ptr->schedAnim == UNION_ROOM_SPAWN_OUT) + if (!IsUnionRoomPlayerInvisible(leaderId, 0) && object->schedAnim == UNION_ROOM_SPAWN_OUT) { - ptr->state = 0; - ptr->animState = 0; - RemoveUnionRoomPlayerObjectEvent(playerIdx); - HideUnionRoomPlayer(playerIdx); + object->state = 0; + object->animState = 0; + RemoveUnionRoomPlayerObjectEvent(leaderId); + HideUnionRoomPlayer(leaderId); } - else if (AnimateUnionRoomPlayerSpawn(&ptr->animState, playerIdx, ptr) == TRUE) + else if (AnimateUnionRoomPlayerSpawn(&object->animState, leaderId, object) == TRUE) { - ptr->state = 1; + object->state = 1; } break; case 1: - if (ptr->schedAnim == UNION_ROOM_SPAWN_OUT) + if (object->schedAnim == UNION_ROOM_SPAWN_OUT) { - ptr->state = 3; - ptr->animState = 0; + object->state = 3; + object->animState = 0; } else { @@ -358,19 +350,17 @@ static void AnimateUnionRoomPlayer(u32 playerIdx, struct UnionRoomObject * ptr) } // fallthrough case 3: - if (AnimateUnionRoomPlayerDespawn(&ptr->animState, playerIdx, ptr) == 1) - { - ptr->state = 0; - } + if (AnimateUnionRoomPlayerDespawn(&object->animState, leaderId, object) == 1) + object->state = 0; break; } - ptr->schedAnim = UNION_ROOM_SPAWN_NONE; + object->schedAnim = UNION_ROOM_SPAWN_NONE; } static void Task_AnimateUnionRoomPlayers(u8 taskId) { s32 i; - for (i = 0; i < MAX_UNION_ROOM_PLAYERS; i++) + for (i = 0; i < MAX_UNION_ROOM_LEADERS; i++) AnimateUnionRoomPlayer(i, &sUnionObjWork[i]); } @@ -386,15 +376,13 @@ static void DestroyTask_AnimateUnionRoomPlayers(void) { u8 taskId = FindTaskIdByFunc(Task_AnimateUnionRoomPlayers); if (taskId < NUM_TASKS) - { DestroyTask(taskId); - } } void DestroyUnionRoomPlayerObjects(void) { s32 i; - for (i = 0; i < MAX_UNION_ROOM_PLAYERS; i++) + for (i = 0; i < MAX_UNION_ROOM_LEADERS; i++) { if (!IsUnionRoomPlayerHidden(i)) { @@ -406,120 +394,119 @@ void DestroyUnionRoomPlayerObjects(void) DestroyTask_AnimateUnionRoomPlayers(); } -void CreateGroupMemberSpritesInvisible(u8 * spriteIds, s32 playerIdx) +void CreateUnionRoomPlayerSprites(u8 * spriteIds, s32 leaderId) { - s32 direction; - - for (direction = DIR_NONE; direction <= DIR_EAST; direction++) + s32 memberId; + for (memberId = 0; memberId < MAX_RFU_PLAYERS; memberId++) { - s32 id = UR_PLAYER_SPRITE_ID(playerIdx, direction); + s32 id = UR_PLAYER_SPRITE_ID(leaderId, memberId); spriteIds[id] = CreateObjectSprite(OBJ_EVENT_GFX_MAN_4, id - UR_SPRITE_START_ID, - sUnionRoomPlayerCoords[playerIdx][0] + sFacingDirectionOffsets[direction][0], - sUnionRoomPlayerCoords[playerIdx][1] + sFacingDirectionOffsets[direction][1], + sUnionRoomPlayerCoords[leaderId][0] + sUnionRoomGroupOffsets[memberId][0], + sUnionRoomPlayerCoords[leaderId][1] + sUnionRoomGroupOffsets[memberId][1], 3, 1); SetObjectEventSpriteInvisibility(id - UR_SPRITE_START_ID, TRUE); } } -void DestroyGroupMemberSprites(u8 * spriteIds) +void DestroyUnionRoomPlayerSprites(u8 * spriteIds) { s32 i; - for (i = 0; i < UR_PLAYER_SPRITE_ID(MAX_UNION_ROOM_PLAYERS, 0); i++) + for (i = 0; i < NUM_UNION_ROOM_SPRITES; i++) DestroySprite(&gSprites[spriteIds[i]]); } +// Clear the impassable metatiles around the group leaders that get set +// to prevent the player from walking through the group member sprites. void SetTilesAroundUnionRoomPlayersPassable(void) { - s32 i, direction, x, y; - for (i = 0; i < MAX_UNION_ROOM_PLAYERS; i++) + s32 i, memberId, x, y; + for (i = 0; i < MAX_UNION_ROOM_LEADERS; i++) { - for (direction = DIR_NONE; direction <= DIR_EAST; direction++) + for (memberId = 0; memberId < MAX_RFU_PLAYERS; memberId++) { - GetUnionRoomPlayerFacingCoords(i, direction, &x, &y); + GetUnionRoomPlayerCoords(i, memberId, &x, &y); MapGridSetMetatileImpassabilityAt(x, y, FALSE); } } } -static u8 GetNewFacingDirectionForUnionRoomPlayer(u32 direction, u32 playerIdx, struct GFtgtGname * gname) +static u8 GetNewFacingDirectionForUnionRoomPlayer(u32 memberId, u32 leaderId, struct RfuGameData * gameData) { - if (direction != DIR_NONE) - return sNextFacingDirection[direction]; - else if (gname->activity == (ACTIVITY_CHAT | IN_UNION_ROOM)) + if (memberId) // If not leader + return sMemberFacingDirections[memberId]; + else if (gameData->activity == (ACTIVITY_CHAT | IN_UNION_ROOM)) return DIR_SOUTH; else return DIR_EAST; } -static bool32 IsUnionRoomPlayerInvisible(u32 playerIdx, u32 direction) +static bool32 IsUnionRoomPlayerInvisible(u32 leaderId, u32 memberId) { - return IsObjectEventSpriteInvisible(UR_PLAYER_SPRITE_ID(playerIdx, direction) - UR_SPRITE_START_ID); + return IsObjectEventSpriteInvisible(UR_PLAYER_SPRITE_ID(leaderId, memberId) - UR_SPRITE_START_ID); } -static void SpawnGroupMember(u32 playerIdx, u32 direction, u8 graphicsId, struct GFtgtGname * gname) +static void SpawnGroupMember(u32 leaderId, u32 memberId, u8 graphicsId, struct RfuGameData * gameData) { s32 x, y; - s32 id = UR_PLAYER_SPRITE_ID(playerIdx, direction); - if (IsUnionRoomPlayerInvisible(playerIdx, direction) == TRUE) + s32 id = UR_PLAYER_SPRITE_ID(leaderId, memberId); + if (IsUnionRoomPlayerInvisible(leaderId, memberId) == TRUE) { SetObjectEventSpriteInvisibility(id - UR_SPRITE_START_ID, FALSE); SetObjectEventSpriteAnim(id - UR_SPRITE_START_ID, UNION_ROOM_SPAWN_IN); } SetObjectEventSpriteGraphics(id - UR_SPRITE_START_ID, graphicsId); - SetUnionRoomObjectFacingDirection(direction, playerIdx, GetNewFacingDirectionForUnionRoomPlayer(direction, playerIdx, gname)); - GetUnionRoomPlayerFacingCoords(playerIdx, direction, &x, &y); + SetUnionRoomObjectFacingDirection(memberId, leaderId, GetNewFacingDirectionForUnionRoomPlayer(memberId, leaderId, gameData)); + GetUnionRoomPlayerCoords(leaderId, memberId, &x, &y); MapGridSetMetatileImpassabilityAt(x, y, TRUE); } -static void DespawnGroupMember(u32 playerIdx, u32 direction) +static void DespawnGroupMember(u32 leaderId, u32 memberId) { s32 x, y; - SetObjectEventSpriteAnim(UR_PLAYER_SPRITE_ID(playerIdx, direction) - UR_SPRITE_START_ID, UNION_ROOM_SPAWN_OUT); - GetUnionRoomPlayerFacingCoords(playerIdx, direction, &x, &y); + SetObjectEventSpriteAnim(UR_PLAYER_SPRITE_ID(leaderId, memberId) - UR_SPRITE_START_ID, UNION_ROOM_SPAWN_OUT); + GetUnionRoomPlayerCoords(leaderId, memberId, &x, &y); MapGridSetMetatileImpassabilityAt(x, y, FALSE); } -static void AssembleGroup(u32 playerIdx, struct GFtgtGname * gname) +static void AssembleGroup(u32 leaderId, struct RfuGameData * gameData) { s16 x, y, x2, y2; s32 i; PlayerGetDestCoords(&x, &y); player_get_pos_including_state_based_drift(&x2, &y2); - if (IsObjectEventSpriteInvisible(UR_PLAYER_SPRITE_ID(playerIdx, 0) - UR_SPRITE_START_ID) == TRUE) + if (IsObjectEventSpriteInvisible(UR_PLAYER_SPRITE_ID(leaderId, 0) - UR_SPRITE_START_ID) == TRUE) { - if (IsUnionRoomPlayerFacingTileAt(playerIdx, 0, x, y) == TRUE || IsUnionRoomPlayerFacingTileAt(playerIdx, 0, x2, y2) == TRUE) - { + if (IsUnionRoomPlayerAt(leaderId, 0, x, y) == TRUE || IsUnionRoomPlayerAt(leaderId, 0, x2, y2) == TRUE) return; - } - SpawnGroupMember(playerIdx, 0, GetUnionRoomPlayerGraphicsId(gname->playerGender, gname->unk_00.playerTrainerId[0]), gname); + SpawnGroupMember(leaderId, 0, GetUnionRoomPlayerGraphicsId(gameData->playerGender, gameData->compatibility.playerTrainerId[0]), gameData); } - for (i = 1; i < 5; i++) + for (i = 1; i < MAX_RFU_PLAYERS; i++) { - if (gname->child_sprite_gender[i - 1] == 0) + if (gameData->partnerInfo[i - 1] == 0) { - DespawnGroupMember(playerIdx, i); + DespawnGroupMember(leaderId, i); } - else if (IsUnionRoomPlayerFacingTileAt(playerIdx, i, x, y) == FALSE && IsUnionRoomPlayerFacingTileAt(playerIdx, i, x2, y2) == FALSE) + else if (IsUnionRoomPlayerAt(leaderId, i, x, y) == FALSE && IsUnionRoomPlayerAt(leaderId, i, x2, y2) == FALSE) { - SpawnGroupMember(playerIdx, i, GetUnionRoomPlayerGraphicsId((gname->child_sprite_gender[i - 1] >> 3) & 1, gname->child_sprite_gender[i - 1] & 7), gname); + SpawnGroupMember(leaderId, i, GetUnionRoomPlayerGraphicsId((gameData->partnerInfo[i - 1] >> PINFO_GENDER_SHIFT) & 1, + gameData->partnerInfo[i - 1] & PINFO_TID_MASK), + gameData); } } } -static void SpawnGroupLeaderAndMembers(u32 playerIdx, struct GFtgtGname * gname) +static void SpawnGroupLeaderAndMembers(u32 leaderId, struct RfuGameData * gameData) { u32 i; - switch (gname->activity) + switch (gameData->activity) { case ACTIVITY_NONE | IN_UNION_ROOM: case ACTIVITY_PLYRTALK | IN_UNION_ROOM: - SpawnGroupLeader(playerIdx, gname->playerGender, gname->unk_00.playerTrainerId[0]); - for (i = 0; i < 5; i++) - { - DespawnGroupMember(playerIdx, i); - } + SpawnGroupLeader(leaderId, gameData->playerGender, gameData->compatibility.playerTrainerId[0]); + for (i = 0; i < MAX_RFU_PLAYERS; i++) + DespawnGroupMember(leaderId, i); break; case ACTIVITY_BATTLE_SINGLE | IN_UNION_ROOM: case ACTIVITY_TRADE | IN_UNION_ROOM: @@ -528,37 +515,31 @@ static void SpawnGroupLeaderAndMembers(u32 playerIdx, struct GFtgtGname * gname) case ACTIVITY_ACCEPT | IN_UNION_ROOM: case ACTIVITY_DECLINE | IN_UNION_ROOM: case ACTIVITY_NPCTALK | IN_UNION_ROOM: - DespawnGroupLeader(playerIdx); - AssembleGroup(playerIdx, gname); + DespawnGroupLeader(leaderId); + AssembleGroup(leaderId, gameData); break; } } -static void DespawnGroupLeaderAndMembers(u32 r5, struct GFtgtGname *gname) +static void DespawnGroupLeaderAndMembers(u32 leaderId, struct RfuGameData *gameData) { s32 i; - DespawnGroupLeader(r5); - for (i = 0; i < 5; i++) - { - DespawnGroupMember(r5, i); - } + DespawnGroupLeader(leaderId); + for (i = 0; i < MAX_RFU_PLAYERS; i++) + DespawnGroupMember(leaderId, i); } static void UpdateUnionRoomPlayerSprites(struct WirelessLink_URoom *uroom) { s32 i; - struct UnkStruct_x20 * r4; + struct RfuPlayer * leaders; sUnionObjRefreshTimer = 0; - for (i = 0, r4 = uroom->field_0->arr; i < MAX_UNION_ROOM_PLAYERS; i++) + for (i = 0, leaders = uroom->playerList->players; i < MAX_UNION_ROOM_LEADERS; i++) { - if (r4[i].groupScheduledAnim == UNION_ROOM_SPAWN_IN) - { - SpawnGroupLeaderAndMembers(i, &r4[i].gname_uname.gname); - } - else if (r4[i].groupScheduledAnim == UNION_ROOM_SPAWN_OUT) - { - DespawnGroupLeaderAndMembers(i, &r4[i].gname_uname.gname); - } + if (leaders[i].groupScheduledAnim == UNION_ROOM_SPAWN_IN) + SpawnGroupLeaderAndMembers(i, &leaders[i].rfu.data); + else if (leaders[i].groupScheduledAnim == UNION_ROOM_SPAWN_OUT) + DespawnGroupLeaderAndMembers(i, &leaders[i].rfu.data); } } @@ -570,64 +551,56 @@ void ScheduleUnionRoomPlayerRefresh(struct WirelessLink_URoom *uroom) void HandleUnionRoomPlayerRefresh(struct WirelessLink_URoom *uroom) { if (++sUnionObjRefreshTimer > 300) - { UpdateUnionRoomPlayerSprites(uroom); - } } -bool32 TryInteractWithUnionRoomMember(struct UnkStruct_Main0 *main0, s16 *directionPtr, s16 *playerIdxPtr, u8 *spriteIds) +bool32 TryInteractWithUnionRoomMember(struct RfuPlayerList *list, s16 *memberIdPtr, s16 *leaderIdPtr, u8 *spriteIds) { s16 x, y; - s32 i, direction; - struct UnkStruct_x20 * r4; + s32 i, memberId; + struct RfuPlayer * leaders; if (!IsPlayerStandingStill()) - { return FALSE; - } + GetXYCoordsOneStepInFrontOfPlayer(&x, &y); - for (i = 0, r4 = main0->arr; i < MAX_UNION_ROOM_PLAYERS; i++) + for (i = 0, leaders = list->players; i < MAX_UNION_ROOM_LEADERS; i++) { - for (direction = DIR_NONE; direction <= DIR_EAST; direction++) + for (memberId = 0; memberId < MAX_RFU_PLAYERS; memberId++) { - s32 id = UR_PLAYER_SPRITE_ID(i, direction); - if (x != sUnionRoomPlayerCoords[i][0] + sFacingDirectionOffsets[direction][0] + 7) - { + s32 id = UR_PLAYER_SPRITE_ID(i, memberId); + + // Is the player in front of a group member position? + if (x != sUnionRoomPlayerCoords[i][0] + sUnionRoomGroupOffsets[memberId][0] + 7) continue; - } - if (y != sUnionRoomPlayerCoords[i][1] + sFacingDirectionOffsets[direction][1] + 7) - { + if (y != sUnionRoomPlayerCoords[i][1] + sUnionRoomGroupOffsets[memberId][1] + 7) continue; - } + + // Has a group member spawned at this position? if (IsObjectEventSpriteInvisible(id - UR_SPRITE_START_ID)) - { continue; - } if (IsObjectEventSpriteAnimating(id - UR_SPRITE_START_ID)) - { continue; - } - if (r4[i].groupScheduledAnim != UNION_ROOM_SPAWN_IN) - { + if (leaders[i].groupScheduledAnim != UNION_ROOM_SPAWN_IN) continue; - } - // Face player - SetUnionRoomObjectFacingDirection(direction, i, sOppositeFacingDirection[GetPlayerFacingDirection()]); - *directionPtr = direction; - *playerIdxPtr = i; + + // Interaction attempt successful, face player + SetUnionRoomObjectFacingDirection(memberId, i, sOppositeFacingDirection[GetPlayerFacingDirection()]); + *memberIdPtr = memberId; + *leaderIdPtr = i; return TRUE; } } return FALSE; } -static void SetUnionRoomObjectFacingDirection(s32 currDirection, s32 playerIdx, u8 newDirection) +static void SetUnionRoomObjectFacingDirection(s32 memberId, s32 leaderId, u8 newDirection) { - TurnObjectEventSprite(5 * playerIdx - UR_SPRITE_START_ID + currDirection, newDirection); + TurnObjectEventSprite(MAX_RFU_PLAYERS * leaderId - UR_SPRITE_START_ID + memberId, newDirection); // should be line below, but order is swapped here - // TurnObjectEventSprite(UR_PLAYER_SPRITE_ID(playerIdx, currDirection) - UR_SPRITE_START_ID, newDirection); + // TurnObjectEventSprite(UR_PLAYER_SPRITE_ID(leaderId, memberId) - UR_SPRITE_START_ID, newDirection); } -void UpdateUnionRoomMemberFacing(u32 currDirection, u32 playerIdx, struct UnkStruct_Main0 *main0) +void UpdateUnionRoomMemberFacing(u32 memberId, u32 leaderId, struct RfuPlayerList *list) { - return SetUnionRoomObjectFacingDirection(currDirection, playerIdx, GetNewFacingDirectionForUnionRoomPlayer(currDirection, playerIdx, &main0->arr[playerIdx].gname_uname.gname)); + return SetUnionRoomObjectFacingDirection(memberId, leaderId, GetNewFacingDirectionForUnionRoomPlayer(memberId, leaderId, &list->players[leaderId].rfu.data)); } diff --git a/src/wireless_communication_status_screen.c b/src/wireless_communication_status_screen.c index dbc71d634..1d15df32f 100644 --- a/src/wireless_communication_status_screen.c +++ b/src/wireless_communication_status_screen.c @@ -114,8 +114,8 @@ static const u8 sActivityGroupInfo[][3] = { {ACTIVITY_BATTLE_DOUBLE, GROUPTYPE_BATTLE, 2}, {ACTIVITY_BATTLE_MULTI, GROUPTYPE_BATTLE, 4}, {ACTIVITY_TRADE, GROUPTYPE_TRADE, 2}, - {ACTIVITY_WONDER_CARD, GROUPTYPE_TOTAL, 2}, - {ACTIVITY_WONDER_NEWS, GROUPTYPE_TOTAL, 2}, + {ACTIVITY_WONDER_CARD_DUP, GROUPTYPE_TOTAL, 2}, + {ACTIVITY_WONDER_NEWS_DUP, GROUPTYPE_TOTAL, 2}, {ACTIVITY_POKEMON_JUMP, GROUPTYPE_TOTAL, 0}, {ACTIVITY_BERRY_CRUSH, GROUPTYPE_TOTAL, 0}, {ACTIVITY_BERRY_PICK, GROUPTYPE_TOTAL, 0}, @@ -132,8 +132,8 @@ static const u8 sActivityGroupInfo[][3] = { {ACTIVITY_NPCTALK | IN_UNION_ROOM, GROUPTYPE_UNION, 2}, {ACTIVITY_ACCEPT | IN_UNION_ROOM, GROUPTYPE_UNION, 1}, {ACTIVITY_DECLINE | IN_UNION_ROOM, GROUPTYPE_UNION, 1}, - {ACTIVITY_WONDER_CARD2, GROUPTYPE_TOTAL, 2}, - {ACTIVITY_WONDER_NEWS2, GROUPTYPE_TOTAL, 2}, + {ACTIVITY_WONDER_CARD, GROUPTYPE_TOTAL, 2}, + {ACTIVITY_WONDER_NEWS, GROUPTYPE_TOTAL, 2}, {ACTIVITY_CONTEST_COOL, GROUPTYPE_TOTAL, 0}, {ACTIVITY_CONTEST_BEAUTY, GROUPTYPE_TOTAL, 0}, {ACTIVITY_CONTEST_CUTE, GROUPTYPE_TOTAL, 0}, @@ -347,10 +347,10 @@ static void WCSS_AddTextPrinterParameterized(u8 windowId, u8 fontId, const u8 * AddTextPrinterParameterized4(windowId, fontId, x, y, 0, 0, color, -1, str); } -static u32 CountPlayersInGroupAndGetActivity(struct UnkStruct_x20 * unk20, u32 * groupCounts) +static u32 CountPlayersInGroupAndGetActivity(struct RfuPlayer * player, u32 * groupCounts) { int i, j, k; - u32 activity = unk20->gname_uname.gname.activity; + u32 activity = player->rfu.data.activity; #define group_activity(i) (sActivityGroupInfo[(i)][0]) #define group_type(i) (sActivityGroupInfo[(i)][1]) @@ -358,15 +358,13 @@ static u32 CountPlayersInGroupAndGetActivity(struct UnkStruct_x20 * unk20, u32 * for (i = 0; i < ARRAY_COUNT(sActivityGroupInfo); i++) { - if (activity == group_activity(i) && unk20->groupScheduledAnim == UNION_ROOM_SPAWN_IN) + if (activity == group_activity(i) && player->groupScheduledAnim == UNION_ROOM_SPAWN_IN) { if (group_players(i) == 0) { k = 0; for (j = 0; j < RFU_CHILD_MAX; j++) - { - if (unk20->gname_uname.gname.child_sprite_gender[j] != 0) k++; - } + if (player->rfu.data.partnerInfo[j] != 0) k++; k++; groupCounts[group_type(i)] += k; } @@ -398,12 +396,12 @@ static bool32 UpdateCommunicationCounts(u32 * groupCounts, u32 * prevGroupCounts { bool32 activitiesChanged = FALSE; u32 groupCountBuffer[NUM_GROUPTYPES] = {0, 0, 0, 0}; - struct UnkStruct_x20 ** data = (void *)gTasks[taskId].data; + struct RfuPlayer ** players = (void *)gTasks[taskId].data; s32 i; for (i = 0; i < NUM_TASK_DATA; i++) { - u32 activity = CountPlayersInGroupAndGetActivity(&(*data)[i], groupCountBuffer); + u32 activity = CountPlayersInGroupAndGetActivity(&(*players)[i], groupCountBuffer); if (activity != activities[i]) { activities[i] = activity;