2017-11-11 06:39:02 +01:00
|
|
|
#include "global.h"
|
2019-09-09 03:07:54 +02:00
|
|
|
#include "malloc.h"
|
2019-08-02 00:41:55 +02:00
|
|
|
#include "battle.h"
|
|
|
|
#include "berry_crush.h"
|
2018-06-01 23:08:25 +02:00
|
|
|
#include "bg.h"
|
2019-08-02 00:41:55 +02:00
|
|
|
#include "cable_club.h"
|
|
|
|
#include "data.h"
|
|
|
|
#include "decompress.h"
|
|
|
|
#include "dodrio_berry_picking.h"
|
|
|
|
#include "dynamic_placeholder_text_util.h"
|
|
|
|
#include "easy_chat.h"
|
2018-06-01 23:08:25 +02:00
|
|
|
#include "event_data.h"
|
2019-12-06 08:55:30 +01:00
|
|
|
#include "event_object_lock.h"
|
2019-08-02 00:41:55 +02:00
|
|
|
#include "field_control_avatar.h"
|
|
|
|
#include "field_player_avatar.h"
|
|
|
|
#include "field_screen_effect.h"
|
|
|
|
#include "field_weather.h"
|
|
|
|
#include "international_string_util.h"
|
|
|
|
#include "librfu.h"
|
2018-06-01 23:08:25 +02:00
|
|
|
#include "link.h"
|
|
|
|
#include "link_rfu.h"
|
|
|
|
#include "list_menu.h"
|
2019-08-02 00:41:55 +02:00
|
|
|
#include "load_save.h"
|
|
|
|
#include "menu.h"
|
2018-06-01 23:08:25 +02:00
|
|
|
#include "menu_helpers.h"
|
2019-08-02 00:41:55 +02:00
|
|
|
#include "mevent.h"
|
|
|
|
#include "mystery_gift.h"
|
2018-06-03 22:39:10 +02:00
|
|
|
#include "overworld.h"
|
2018-06-04 12:07:32 +02:00
|
|
|
#include "palette.h"
|
2019-08-02 00:41:55 +02:00
|
|
|
#include "party_menu.h"
|
|
|
|
#include "pokemon_jump.h"
|
|
|
|
#include "random.h"
|
2019-11-07 19:26:53 +01:00
|
|
|
#include "save_location.h"
|
2019-08-02 00:41:55 +02:00
|
|
|
#include "script.h"
|
2020-08-13 23:42:12 +02:00
|
|
|
#include "script_pokemon_util.h"
|
2019-08-02 00:41:55 +02:00
|
|
|
#include "sound.h"
|
|
|
|
#include "start_menu.h"
|
|
|
|
#include "string_util.h"
|
2019-03-29 16:57:03 +01:00
|
|
|
#include "strings.h"
|
2019-08-02 00:41:55 +02:00
|
|
|
#include "task.h"
|
|
|
|
#include "trade.h"
|
|
|
|
#include "trainer_card.h"
|
2019-03-30 19:36:52 +01:00
|
|
|
#include "union_room.h"
|
2020-05-30 10:09:21 +02:00
|
|
|
#include "union_room_battle.h"
|
2019-03-27 01:03:46 +01:00
|
|
|
#include "union_room_chat.h"
|
2019-04-01 20:20:34 +02:00
|
|
|
#include "union_room_player_avatar.h"
|
2019-08-02 00:41:55 +02:00
|
|
|
#include "window.h"
|
|
|
|
#include "constants/battle_frontier.h"
|
2019-10-11 10:14:09 +02:00
|
|
|
#include "constants/cable_club.h"
|
2019-08-02 00:41:55 +02:00
|
|
|
#include "constants/game_stat.h"
|
|
|
|
#include "constants/maps.h"
|
2019-10-18 01:22:03 +02:00
|
|
|
#include "constants/party_menu.h"
|
2019-08-02 00:41:55 +02:00
|
|
|
#include "constants/rgb.h"
|
|
|
|
#include "constants/songs.h"
|
2019-03-29 20:50:04 +01:00
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
// States for Task_RunUnionRoom
|
|
|
|
enum {
|
|
|
|
UR_STATE_INIT,
|
|
|
|
UR_STATE_INIT_OBJECTS,
|
|
|
|
UR_STATE_INIT_LINK,
|
|
|
|
UR_STATE_CHECK_SELECTING_MON,
|
|
|
|
UR_STATE_MAIN,
|
|
|
|
UR_STATE_DO_SOMETHING_PROMPT,
|
2021-08-25 00:59:32 +02:00
|
|
|
UR_STATE_HANDLE_DO_SOMETHING_PROMPT_INPUT,
|
2020-06-09 00:16:57 +02:00
|
|
|
UR_STATE_DO_SOMETHING_PROMPT_2,
|
|
|
|
UR_STATE_PRINT_MSG,
|
|
|
|
UR_STATE_HANDLE_ACTIVITY_REQUEST,
|
2021-08-25 00:59:32 +02:00
|
|
|
UR_STATE_DECLINE_ACTIVITY_REQUEST,
|
2020-06-09 00:16:57 +02:00
|
|
|
UR_STATE_PLAYER_CONTACTED_YOU,
|
2021-08-25 00:59:32 +02:00
|
|
|
UR_STATE_RECV_CONTACT_DATA,
|
2020-06-09 00:16:57 +02:00
|
|
|
UR_STATE_PRINT_START_ACTIVITY_MSG,
|
|
|
|
UR_STATE_START_ACTIVITY_LINK,
|
|
|
|
UR_STATE_START_ACTIVITY_WAIT_FOR_LINK,
|
|
|
|
UR_STATE_START_ACTIVITY_FREE_UROOM,
|
|
|
|
UR_STATE_START_ACTIVITY_FADE,
|
|
|
|
UR_STATE_START_ACTIVITY,
|
|
|
|
UR_STATE_RECV_JOIN_CHAT_REQUEST,
|
|
|
|
UR_STATE_TRY_ACCEPT_CHAT_REQUEST_DELAY,
|
|
|
|
UR_STATE_TRY_ACCEPT_CHAT_REQUEST,
|
|
|
|
UR_STATE_ACCEPT_CHAT_REQUEST,
|
|
|
|
UR_STATE_WAIT_FOR_START_MENU,
|
|
|
|
UR_STATE_INTERACT_WITH_PLAYER,
|
2021-08-25 00:59:32 +02:00
|
|
|
UR_STATE_TRY_COMMUNICATING,
|
2020-06-09 00:16:57 +02:00
|
|
|
UR_STATE_PRINT_AND_EXIT,
|
|
|
|
UR_STATE_SEND_ACTIVITY_REQUEST,
|
|
|
|
UR_STATE_TRAINER_APPEARS_BUSY,
|
|
|
|
UR_STATE_WAIT_FOR_RESPONSE_TO_REQUEST,
|
|
|
|
UR_STATE_CANCEL_ACTIVITY_LINK_ERROR,
|
|
|
|
UR_STATE_SEND_TRADE_REQUST,
|
|
|
|
UR_STATE_REQUEST_DECLINED,
|
|
|
|
UR_STATE_PRINT_CONTACT_MSG,
|
|
|
|
UR_STATE_HANDLE_CONTACT_DATA,
|
|
|
|
UR_STATE_RECV_ACTIVITY_REQUEST,
|
|
|
|
UR_STATE_CANCEL_REQUEST_PRINT_MSG,
|
|
|
|
UR_STATE_CANCEL_REQUEST_RESTART_LINK,
|
|
|
|
UR_STATE_COMMUNICATING_WAIT_FOR_DATA,
|
2021-08-25 00:59:32 +02:00
|
|
|
UR_STATE_WAIT_FOR_CONTACT_DATA,
|
2020-06-09 00:16:57 +02:00
|
|
|
UR_STATE_PRINT_CARD_INFO,
|
|
|
|
UR_STATE_WAIT_FINISH_READING_CARD,
|
|
|
|
UR_STATE_INTERACT_WITH_ATTENDANT,
|
2021-08-25 00:59:32 +02:00
|
|
|
UR_STATE_REGISTER_PROMPT,
|
2020-06-09 00:16:57 +02:00
|
|
|
UR_STATE_CANCEL_REGISTRATION_PROMPT,
|
|
|
|
UR_STATE_CHECK_TRADING_BOARD,
|
|
|
|
UR_STATE_TRADING_BOARD_LOAD,
|
2021-08-25 00:59:32 +02:00
|
|
|
UR_STATE_REGISTER_PROMPT_HANDLE_INPUT,
|
2020-06-09 00:16:57 +02:00
|
|
|
UR_STATE_TRADING_BOARD_HANDLE_INPUT,
|
|
|
|
UR_STATE_TRADE_PROMPT,
|
|
|
|
UR_STATE_TRADE_SELECT_MON,
|
|
|
|
UR_STATE_TRADE_OFFER_MON,
|
|
|
|
UR_STATE_REGISTER_REQUEST_TYPE,
|
|
|
|
UR_STATE_REGISTER_SELECT_MON_FADE,
|
|
|
|
UR_STATE_REGISTER_SELECT_MON,
|
2021-08-25 00:59:32 +02:00
|
|
|
UR_STATE_REGISTER_COMPLETE,
|
2020-06-09 00:16:57 +02:00
|
|
|
UR_STATE_CANCEL_REGISTRATION,
|
|
|
|
};
|
|
|
|
|
|
|
|
// States for sUnionRoomTrade.state
|
|
|
|
enum {
|
|
|
|
URTRADE_STATE_NONE,
|
|
|
|
URTRADE_STATE_REGISTERING,
|
|
|
|
URTRADE_STATE_OFFERING,
|
|
|
|
};
|
|
|
|
|
|
|
|
// States for Task_TryBecomeLinkLeader
|
|
|
|
enum {
|
|
|
|
LL_STATE_INIT,
|
|
|
|
LL_STATE_INIT2 = 3,
|
|
|
|
LL_STATE_GET_AWAITING_PLAYERS_TEXT,
|
|
|
|
LL_STATE_PRINT_AWAITING_PLAYERS,
|
|
|
|
LL_STATE_AWAIT_PLAYERS,
|
|
|
|
LL_STATE_ACCEPT_NEW_MEMBER_PROMPT,
|
2021-07-12 02:42:05 +02:00
|
|
|
LL_STATE_WAIT_DISCONNECT_CHILD = 9,
|
2020-06-09 00:16:57 +02:00
|
|
|
LL_STATE_MEMBER_LEFT,
|
|
|
|
LL_STATE_ACCEPT_NEW_MEMBER_PROMPT_HANDLE_INPUT,
|
|
|
|
LL_STATE_UPDATE_AFTER_JOIN_REQUEST,
|
|
|
|
LL_STATE_ACCEPTED_FINAL_MEMBER,
|
|
|
|
LL_STATE_WAIT_AND_CONFIRM_MEMBERS,
|
|
|
|
LL_STATE_MEMBERS_OK_PROMPT,
|
|
|
|
LL_STATE_MEMBERS_OK_PROMPT_HANDLE_INPUT,
|
|
|
|
LL_STATE_CONFIRMED_MEMBERS,
|
|
|
|
LL_STATE_FINAL_MEMBER_CHECK,
|
|
|
|
LL_STATE_CANCEL_PROMPT,
|
|
|
|
LL_STATE_CANCEL_PROMPT_HANDLE_INPUT,
|
|
|
|
LL_STATE_SHUTDOWN_AND_RETRY,
|
|
|
|
LL_STATE_RETRY,
|
|
|
|
LL_STATE_SHUTDOWN_AND_FAIL,
|
|
|
|
LL_STATE_FAILED,
|
|
|
|
LL_STATE_TRY_START_ACTIVITY = 26,
|
|
|
|
LL_STATE_MEMBER_DISCONNECTED = 29,
|
|
|
|
LL_STATE_CANCEL_WITH_MSG
|
|
|
|
};
|
|
|
|
|
|
|
|
// States for Task_TryJoinLinkGroup
|
|
|
|
enum {
|
|
|
|
LG_STATE_INIT,
|
|
|
|
LG_STATE_CHOOSE_LEADER_MSG,
|
|
|
|
LG_STATE_INIT_WINDOWS,
|
|
|
|
LG_STATE_CHOOSE_LEADER_HANDLE_INPUT,
|
|
|
|
LG_STATE_ASK_JOIN_GROUP = 5,
|
|
|
|
LG_STATE_MAIN,
|
|
|
|
LG_STATE_ASK_LEAVE_GROUP,
|
|
|
|
LG_STATE_ASK_LEAVE_GROUP_HANDLE_INPUT,
|
|
|
|
LG_STATE_WAIT_LEAVE_GROUP,
|
|
|
|
LG_STATE_CANCEL_CHOOSE_LEADER,
|
|
|
|
LG_STATE_CANCELED,
|
|
|
|
LG_STATE_RFU_ERROR,
|
|
|
|
LG_STATE_RFU_ERROR_SHUTDOWN,
|
|
|
|
LG_STATE_DISCONNECTED,
|
|
|
|
LG_STATE_RETRY_CONNECTION,
|
|
|
|
LG_STATE_TRADE_NOT_READY = 18,
|
|
|
|
LG_STATE_TRADE_NOT_READY_RETRY,
|
|
|
|
LG_STATE_READY_START_ACTIVITY,
|
|
|
|
LG_STATE_START_ACTIVITY,
|
|
|
|
LG_STATE_SHUTDOWN = 23,
|
|
|
|
};
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
// 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 {
|
2021-10-07 21:32:51 +02:00
|
|
|
PLIST_NONE,
|
|
|
|
PLIST_NEW_PLAYER,
|
|
|
|
PLIST_RECENT_UPDATE,
|
|
|
|
PLIST_UNUSED,
|
|
|
|
PLIST_CONTACTED,
|
2021-10-06 05:38:36 +02:00
|
|
|
};
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static EWRAM_DATA u8 sUnionRoomPlayerName[12] = {};
|
|
|
|
EWRAM_DATA u8 gPlayerCurrActivity = 0;
|
|
|
|
static EWRAM_DATA u8 sPlayerActivityGroupSize = 0;
|
2021-10-06 05:38:36 +02:00
|
|
|
static EWRAM_DATA union
|
|
|
|
{
|
|
|
|
struct WirelessLink_Leader *leader;
|
|
|
|
struct WirelessLink_Group *group;
|
|
|
|
struct WirelessLink_URoom *uRoom;
|
|
|
|
} sWirelessLinkMain = {};
|
2020-05-30 10:09:21 +02:00
|
|
|
static EWRAM_DATA u32 sUnused = 0;
|
2021-10-06 05:38:36 +02:00
|
|
|
EWRAM_DATA struct RfuGameCompatibilityData gRfuPartnerCompatibilityData = {};
|
2019-10-04 23:24:03 +02:00
|
|
|
EWRAM_DATA u16 gUnionRoomOfferedSpecies = 0;
|
|
|
|
EWRAM_DATA u8 gUnionRoomRequestedMonType = 0;
|
2019-10-05 05:31:25 +02:00
|
|
|
static EWRAM_DATA struct UnionRoomTrade sUnionRoomTrade = {};
|
2018-06-03 22:39:10 +02:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static struct WirelessLink_Leader *sLeader;
|
|
|
|
static struct WirelessLink_Group *sGroup;
|
|
|
|
static struct WirelessLink_URoom *sURoom;
|
2017-11-11 06:39:02 +01:00
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static void PrintUnionRoomText(u8, u8, const u8 *, u8, u8, u8);
|
2020-06-09 00:16:57 +02:00
|
|
|
static u16 ReadAsU16(const u8 *);
|
|
|
|
static void Task_TryBecomeLinkLeader(u8);
|
|
|
|
static void Task_TryJoinLinkGroup(u8);
|
|
|
|
static void Task_ListenToWireless(u8);
|
|
|
|
static void Task_MEvent_Leader(u8);
|
|
|
|
static void Task_CardOrNewsWithFriend(u8);
|
|
|
|
static void Task_CardOrNewsOverWireless(u8);
|
|
|
|
static void Task_RunUnionRoom(u8);
|
2021-10-06 05:38:36 +02:00
|
|
|
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 );
|
2020-06-09 00:16:57 +02:00
|
|
|
static bool8 PrintOnTextbox(u8 *, const u8 *);
|
|
|
|
static bool8 Leader_SetStateIfMemberListChanged(struct WirelessLink_Leader *, u32, u32);
|
2021-10-06 05:38:36 +02:00
|
|
|
static u8 LeaderPrunePlayerList(struct RfuPlayerList *);
|
2020-06-09 00:16:57 +02:00
|
|
|
static s8 UnionRoomHandleYesNo(u8 *, bool32);
|
2021-10-06 05:38:36 +02:00
|
|
|
static void CopyAndTranslatePlayerName(u8 *, struct RfuPlayer *);
|
2020-06-09 00:16:57 +02:00
|
|
|
static void Leader_DestroyResources(struct WirelessLink_Leader *);
|
2020-05-30 10:09:21 +02:00
|
|
|
static void CreateTask_RunScriptAndFadeToActivity(void);
|
2021-10-06 05:38:36 +02:00
|
|
|
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);
|
2020-05-30 10:09:21 +02:00
|
|
|
static u8 GetNewLeaderCandidate(void);
|
2020-06-09 00:16:57 +02:00
|
|
|
static u32 IsTryingToTradeAcrossVersionTooSoon(struct WirelessLink_Group *, s32);
|
|
|
|
static void AskToJoinRfuGroup(struct WirelessLink_Group *, s32);
|
2020-05-30 10:09:21 +02:00
|
|
|
static void JoinGroup_EnableScriptContexts(void);
|
2021-10-06 05:38:36 +02:00
|
|
|
static void PrintGroupMemberOnWindow(u8, u8, u8, struct RfuPlayer *, u8, u8);
|
|
|
|
static bool32 ArePlayerDataDifferent(struct RfuPlayerData *, struct RfuPlayerData *);
|
2020-06-09 00:16:57 +02:00
|
|
|
static u32 GetPartyPositionOfRegisteredMon(struct UnionRoomTrade *, u8);
|
|
|
|
static void ResetUnionRoomTrade(struct UnionRoomTrade *);
|
2020-05-30 10:09:21 +02:00
|
|
|
static void CreateTask_StartActivity(void);
|
2021-10-06 05:38:36 +02:00
|
|
|
static bool32 HasWonderCardOrNewsByLinkGroup(struct RfuGameData *, s16);
|
|
|
|
static u8 CreateTask_SearchForChildOrParent(struct RfuIncomingPlayerList *, struct RfuIncomingPlayerList *, u32);
|
2020-06-09 00:16:57 +02:00
|
|
|
static bool32 RegisterTradeMonAndGetIsEgg(u32, struct UnionRoomTrade *);
|
|
|
|
static void RegisterTradeMon(u32, struct UnionRoomTrade *);
|
2021-10-06 05:38:36 +02:00
|
|
|
static void StartScriptInteraction(void);
|
2020-06-09 00:16:57 +02:00
|
|
|
static bool32 IsPlayerFacingTradingBoard(void);
|
2020-05-30 10:09:21 +02:00
|
|
|
static u8 HandlePlayerListUpdate(void);
|
2020-06-09 00:16:57 +02:00
|
|
|
static bool32 PollPartnerYesNoResponse(struct WirelessLink_URoom *);
|
|
|
|
static void ReceiveUnionRoomActivityPacket(struct WirelessLink_URoom *);
|
2021-10-06 05:38:36 +02:00
|
|
|
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);
|
2020-06-09 00:16:57 +02:00
|
|
|
static void HandleCancelActivity(bool32);
|
|
|
|
static s32 ListMenuHandler_AllItemsAvailable(u8 *, u8 *, u8 *, const struct WindowTemplate *, const struct ListMenuTemplate *);
|
2021-10-06 05:38:36 +02:00
|
|
|
static s32 TradeBoardMenuHandler(u8 *, u8 *, u8 *, u8 *, const struct WindowTemplate *, const struct ListMenuTemplate *, struct RfuPlayerList *);
|
|
|
|
static s32 GetIndexOfNthTradeBoardOffer(struct RfuPlayer *, s32);
|
2020-05-30 10:09:21 +02:00
|
|
|
static bool32 HasAtLeastTwoMonsOfLevel30OrLower(void);
|
2020-06-09 00:16:57 +02:00
|
|
|
static u32 GetResponseIdx_InviteToURoomActivity(s32);
|
|
|
|
static void ViewURoomPartnerTrainerCard(u8 *, struct WirelessLink_URoom *, bool8);
|
|
|
|
static void GetURoomActivityRejectMsg(u8 *, s32, u32);
|
2021-10-06 05:38:36 +02:00
|
|
|
static u32 ConvPartnerUnameAndGetWhetherMetAlready(struct RfuPlayer *);
|
2020-06-09 00:16:57 +02:00
|
|
|
static void GetURoomActivityStartMsg(u8 *, u8);
|
2020-05-30 10:09:21 +02:00
|
|
|
static void UR_ClearBg0(void);
|
2020-06-09 00:16:57 +02:00
|
|
|
static s32 IsRequestedTypeOrEggInPlayerParty(u32, u32);
|
|
|
|
static bool32 UR_PrintFieldMessage(const u8 *);
|
|
|
|
static s32 GetChatLeaderActionRequestMessage(u8 *, u32, u16 *, struct WirelessLink_URoom *);
|
2020-05-30 10:09:21 +02:00
|
|
|
static void Task_InitUnionRoom(u8 taskId);
|
2021-10-06 05:38:36 +02:00
|
|
|
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);
|
2018-06-01 23:08:25 +02:00
|
|
|
|
2019-10-04 23:24:03 +02:00
|
|
|
#include "data/union_room.h"
|
2019-03-28 16:24:50 +01:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void PrintNumPlayersWaitingForMsg(u8 windowId, u8 capacityCode, u8 stringId)
|
2018-06-01 23:08:25 +02:00
|
|
|
{
|
2019-03-02 23:25:39 +01:00
|
|
|
FillWindowPixelBuffer(windowId, PIXEL_FILL(1));
|
2020-05-30 10:09:21 +02:00
|
|
|
switch (capacityCode << 8)
|
2018-06-01 23:08:25 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
case LINK_GROUP_CAPACITY(0, 2):
|
2021-10-06 05:38:36 +02:00
|
|
|
PrintUnionRoomText(windowId, 1, sPlayersNeededOrModeTexts[0][stringId - 1], 0, 1, UR_COLOR_DEFAULT);
|
2018-06-01 23:08:25 +02:00
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case LINK_GROUP_CAPACITY(0, 4):
|
2021-10-06 05:38:36 +02:00
|
|
|
PrintUnionRoomText(windowId, 1, sPlayersNeededOrModeTexts[1][stringId - 1], 0, 1, UR_COLOR_DEFAULT);
|
2018-06-01 23:08:25 +02:00
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case LINK_GROUP_CAPACITY(2, 5):
|
2021-10-06 05:38:36 +02:00
|
|
|
PrintUnionRoomText(windowId, 1, sPlayersNeededOrModeTexts[2][stringId - 1], 0, 1, UR_COLOR_DEFAULT);
|
2018-06-01 23:08:25 +02:00
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case LINK_GROUP_CAPACITY(3, 5):
|
2021-10-06 05:38:36 +02:00
|
|
|
PrintUnionRoomText(windowId, 1, sPlayersNeededOrModeTexts[3][stringId - 1], 0, 1, UR_COLOR_DEFAULT);
|
2018-06-01 23:08:25 +02:00
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case LINK_GROUP_CAPACITY(2, 4):
|
2021-10-06 05:38:36 +02:00
|
|
|
PrintUnionRoomText(windowId, 1, sPlayersNeededOrModeTexts[4][stringId - 1], 0, 1, UR_COLOR_DEFAULT);
|
2018-06-01 23:08:25 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
CopyWindowToVram(windowId, 2);
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void PrintPlayerNameAndIdOnWindow(u8 windowId)
|
2018-06-01 23:08:25 +02:00
|
|
|
{
|
|
|
|
u8 text[30];
|
|
|
|
u8 *txtPtr;
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
PrintUnionRoomText(windowId, 1, gSaveBlock2Ptr->playerName, 0, 1, UR_COLOR_DEFAULT);
|
2019-12-10 19:48:20 +01:00
|
|
|
txtPtr = StringCopy(text, sText_ID);
|
2018-06-01 23:08:25 +02:00
|
|
|
ConvertIntToDecimalStringN(txtPtr, ReadAsU16(gSaveBlock2Ptr->playerTrainerId), STR_CONV_MODE_LEADING_ZEROS, 5);
|
2021-10-06 05:38:36 +02:00
|
|
|
PrintUnionRoomText(windowId, 1, text, 0, 17, UR_COLOR_DEFAULT);
|
2018-06-01 23:08:25 +02:00
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static void GetAwaitingCommunicationText(u8 *dst, u8 caseId)
|
2018-06-01 23:08:25 +02:00
|
|
|
{
|
|
|
|
switch (caseId)
|
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_BATTLE_SINGLE:
|
|
|
|
case ACTIVITY_BATTLE_DOUBLE:
|
|
|
|
case ACTIVITY_BATTLE_MULTI:
|
|
|
|
case ACTIVITY_TRADE:
|
|
|
|
case ACTIVITY_POKEMON_JUMP:
|
|
|
|
case ACTIVITY_BERRY_CRUSH:
|
|
|
|
case ACTIVITY_BERRY_PICK:
|
|
|
|
case ACTIVITY_BATTLE_TOWER:
|
|
|
|
case ACTIVITY_BATTLE_TOWER_OPEN:
|
|
|
|
case ACTIVITY_RECORD_CORNER:
|
|
|
|
case ACTIVITY_BERRY_BLENDER:
|
2021-10-06 05:38:36 +02:00
|
|
|
case ACTIVITY_WONDER_CARD:
|
|
|
|
case ACTIVITY_WONDER_NEWS:
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_CONTEST_COOL:
|
|
|
|
case ACTIVITY_CONTEST_BEAUTY:
|
|
|
|
case ACTIVITY_CONTEST_CUTE:
|
|
|
|
case ACTIVITY_CONTEST_SMART:
|
|
|
|
case ACTIVITY_CONTEST_TOUGH:
|
2021-05-15 22:56:17 +02:00
|
|
|
// BUG: argument *dst isn't used, instead it always prints to gStringVar4
|
|
|
|
// not an issue in practice since Gamefreak never used any other arguments here besides gStringVar4
|
|
|
|
#ifndef BUGFIX
|
2019-12-10 19:48:20 +01:00
|
|
|
StringExpandPlaceholders(gStringVar4, sText_AwaitingCommunication);
|
2021-05-15 22:56:17 +02:00
|
|
|
#else
|
|
|
|
StringExpandPlaceholders(dst, sText_AwaitingCommunication);
|
|
|
|
#endif
|
2018-06-01 23:08:25 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static bool32 IsActivityWithVariableGroupSize(u32 caseId)
|
2018-06-01 23:08:25 +02:00
|
|
|
{
|
|
|
|
switch (caseId)
|
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_POKEMON_JUMP:
|
|
|
|
case ACTIVITY_BERRY_CRUSH:
|
|
|
|
case ACTIVITY_BERRY_PICK:
|
|
|
|
case ACTIVITY_RECORD_CORNER:
|
|
|
|
case ACTIVITY_BERRY_BLENDER:
|
|
|
|
case ACTIVITY_CONTEST_COOL:
|
|
|
|
case ACTIVITY_CONTEST_BEAUTY:
|
|
|
|
case ACTIVITY_CONTEST_CUTE:
|
|
|
|
case ACTIVITY_CONTEST_SMART:
|
|
|
|
case ACTIVITY_CONTEST_TOUGH:
|
2018-06-01 23:08:25 +02:00
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-11 10:14:09 +02:00
|
|
|
void TryBecomeLinkLeader(void)
|
2018-06-01 23:08:25 +02:00
|
|
|
{
|
|
|
|
u8 taskId;
|
2020-05-30 10:09:21 +02:00
|
|
|
struct WirelessLink_Leader *data;
|
2018-06-01 23:08:25 +02:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
taskId = CreateTask(Task_TryBecomeLinkLeader, 0);
|
|
|
|
sWirelessLinkMain.leader = data = (void*)(gTasks[taskId].data);
|
|
|
|
sLeader = data;
|
2018-06-01 23:08:25 +02:00
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LL_STATE_INIT;
|
2020-05-30 10:09:21 +02:00
|
|
|
data->textState = 0;
|
2020-06-09 00:16:57 +02:00
|
|
|
gSpecialVar_Result = LINKUP_ONGOING;
|
2018-06-01 23:08:25 +02:00
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void Task_TryBecomeLinkLeader(u8 taskId)
|
2018-06-01 23:08:25 +02:00
|
|
|
{
|
2018-06-03 09:37:01 +02:00
|
|
|
u32 id, val;
|
2020-05-30 10:09:21 +02:00
|
|
|
struct WirelessLink_Leader *data = sWirelessLinkMain.leader;
|
2018-06-01 23:08:25 +02:00
|
|
|
|
2018-06-03 09:37:01 +02:00
|
|
|
switch (data->state)
|
2018-06-01 23:08:25 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
case LL_STATE_INIT:
|
2019-11-11 03:54:00 +01:00
|
|
|
if (gSpecialVar_0x8004 == LINK_GROUP_BATTLE_TOWER && gSaveBlock2Ptr->frontier.lvlMode == FRONTIER_LVL_OPEN)
|
2018-06-01 23:08:25 +02:00
|
|
|
gSpecialVar_0x8004++;
|
2020-05-30 10:09:21 +02:00
|
|
|
gPlayerCurrActivity = sLinkGroupToActivityAndCapacity[gSpecialVar_0x8004];
|
|
|
|
sPlayerActivityGroupSize = sLinkGroupToActivityAndCapacity[gSpecialVar_0x8004] >> 8;
|
2021-10-06 05:38:36 +02:00
|
|
|
SetHostRfuGameData(gPlayerCurrActivity, 0, FALSE);
|
2020-05-30 10:09:21 +02:00
|
|
|
SetWirelessCommType1();
|
2018-06-01 23:08:25 +02:00
|
|
|
OpenLink();
|
2020-06-09 00:16:57 +02:00
|
|
|
InitializeRfuLinkManager_LinkLeader(GROUP_MAX(sPlayerActivityGroupSize));
|
|
|
|
data->state = LL_STATE_INIT2;
|
2018-06-01 23:08:25 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LL_STATE_INIT2:
|
2021-10-06 05:38:36 +02:00
|
|
|
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;
|
2021-10-07 21:32:51 +02:00
|
|
|
data->playerList->players[0].newPlayerCountdown = 0;
|
2021-10-06 05:38:36 +02:00
|
|
|
data->listenTaskId = CreateTask_ListenForCompatiblePartners(data->incomingPlayerList, 0xFF);
|
2020-05-30 10:09:21 +02:00
|
|
|
data->bButtonCancelWindowId = AddWindow(&sWindowTemplate_BButtonCancel);
|
2020-06-09 00:16:57 +02:00
|
|
|
switch (GROUP_MAX(sPlayerActivityGroupSize))
|
2018-06-01 23:08:25 +02:00
|
|
|
{
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
case 4:
|
2020-06-09 00:16:57 +02:00
|
|
|
data->listWindowId = AddWindow(&sWindowTemplate_PlayerList);
|
2018-06-01 23:08:25 +02:00
|
|
|
break;
|
|
|
|
case 5:
|
2020-06-09 00:16:57 +02:00
|
|
|
data->listWindowId = AddWindow(&sWindowTemplate_5PlayerList);
|
2018-06-01 23:08:25 +02:00
|
|
|
break;
|
|
|
|
}
|
2020-05-30 10:09:21 +02:00
|
|
|
data->nPlayerModeWindowId = AddWindow(&sWindowTemplate_NumPlayerMode);
|
2018-06-01 23:08:25 +02:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
FillWindowPixelBuffer(data->bButtonCancelWindowId, PIXEL_FILL(2));
|
2021-10-06 05:38:36 +02:00
|
|
|
PrintUnionRoomText(data->bButtonCancelWindowId, 0, sText_BButtonCancel, 8, 1, UR_COLOR_CANCEL);
|
2020-05-30 10:09:21 +02:00
|
|
|
PutWindowTilemap(data->bButtonCancelWindowId);
|
|
|
|
CopyWindowToVram(data->bButtonCancelWindowId, 2);
|
2018-06-01 23:08:25 +02:00
|
|
|
|
2019-02-22 07:40:11 +01:00
|
|
|
DrawStdWindowFrame(data->listWindowId, FALSE);
|
2020-05-30 10:09:21 +02:00
|
|
|
gMultiuseListMenuTemplate = sListMenuTemplate_PossibleGroupMembers;
|
2018-06-04 12:07:32 +02:00
|
|
|
gMultiuseListMenuTemplate.windowId = data->listWindowId;
|
2018-06-03 09:37:01 +02:00
|
|
|
data->listTaskId = ListMenuInit(&gMultiuseListMenuTemplate, 0, 0);
|
2018-06-01 23:08:25 +02:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
DrawStdWindowFrame(data->nPlayerModeWindowId, FALSE);
|
|
|
|
PutWindowTilemap(data->nPlayerModeWindowId);
|
|
|
|
CopyWindowToVram(data->nPlayerModeWindowId, 2);
|
2017-11-11 06:39:02 +01:00
|
|
|
|
2018-06-01 23:08:25 +02:00
|
|
|
CopyBgTilemapBufferToVram(0);
|
2020-05-30 10:09:21 +02:00
|
|
|
data->playerCount = 1;
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LL_STATE_GET_AWAITING_PLAYERS_TEXT;
|
2018-06-01 23:08:25 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LL_STATE_GET_AWAITING_PLAYERS_TEXT:
|
|
|
|
StringCopy(gStringVar1, sLinkGroupActivityNameTexts[gPlayerCurrActivity]);
|
|
|
|
if (GROUP_MIN(sPlayerActivityGroupSize) != 0)
|
2018-06-01 23:08:25 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
if (data->playerCount > GROUP_MIN(sPlayerActivityGroupSize) - 1 && GROUP_MAX(sPlayerActivityGroupSize) != 0)
|
2019-12-10 19:48:20 +01:00
|
|
|
StringExpandPlaceholders(gStringVar4, sText_AwaitingLinkPressStart);
|
2018-06-01 23:08:25 +02:00
|
|
|
else
|
2019-12-10 19:48:20 +01:00
|
|
|
StringExpandPlaceholders(gStringVar4, sText_AwaitingCommunication);
|
2018-06-01 23:08:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
GetAwaitingCommunicationText(gStringVar4, gPlayerCurrActivity);
|
2018-06-01 23:08:25 +02:00
|
|
|
}
|
2017-11-11 06:39:02 +01:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
PrintNumPlayersWaitingForMsg(data->nPlayerModeWindowId, sPlayerActivityGroupSize, data->playerCount);
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LL_STATE_PRINT_AWAITING_PLAYERS;
|
2018-06-01 23:08:25 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LL_STATE_PRINT_AWAITING_PLAYERS:
|
2018-06-03 09:37:01 +02:00
|
|
|
if (PrintOnTextbox(&data->textState, gStringVar4))
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LL_STATE_AWAIT_PLAYERS;
|
2018-06-01 23:08:25 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LL_STATE_AWAIT_PLAYERS:
|
|
|
|
Leader_SetStateIfMemberListChanged(data, LL_STATE_ACCEPT_NEW_MEMBER_PROMPT, LL_STATE_MEMBER_LEFT);
|
2020-09-05 03:11:55 +02:00
|
|
|
if (JOY_NEW(B_BUTTON))
|
2018-06-01 23:08:25 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
if (data->playerCount == 1)
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LL_STATE_SHUTDOWN_AND_FAIL;
|
|
|
|
else if (GROUP_MIN2(sPlayerActivityGroupSize) != 0)
|
|
|
|
data->state = LL_STATE_CANCEL_WITH_MSG;
|
2018-06-03 09:37:01 +02:00
|
|
|
else
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LL_STATE_CANCEL_PROMPT;
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
2020-06-09 00:16:57 +02:00
|
|
|
if (GROUP_MIN(sPlayerActivityGroupSize) != 0
|
|
|
|
&& data->playerCount > GROUP_MIN(sPlayerActivityGroupSize) - 1
|
|
|
|
&& GROUP_MAX(sPlayerActivityGroupSize) != 0
|
2021-07-12 02:42:05 +02:00
|
|
|
&& IsRfuCommunicatingWithAllChildren()
|
2020-09-05 03:11:55 +02:00
|
|
|
&& JOY_NEW(START_BUTTON))
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LL_STATE_MEMBERS_OK_PROMPT;
|
2020-05-30 10:09:21 +02:00
|
|
|
LinkRfu_StopManagerAndFinalizeSlots();
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
2021-07-12 02:42:05 +02:00
|
|
|
if (data->state == LL_STATE_AWAIT_PLAYERS && RfuTryDisconnectLeavingChildren())
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2021-07-12 02:42:05 +02:00
|
|
|
// At least 1 group member has left or is trying to leave
|
|
|
|
data->state = LL_STATE_WAIT_DISCONNECT_CHILD;
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
|
|
|
break;
|
2021-07-12 02:42:05 +02:00
|
|
|
case LL_STATE_WAIT_DISCONNECT_CHILD:
|
|
|
|
// Resume after ensuring all members trying to leave have left
|
|
|
|
if (!RfuTryDisconnectLeavingChildren())
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LL_STATE_AWAIT_PLAYERS;
|
2021-10-06 05:38:36 +02:00
|
|
|
data->playerCount = LeaderPrunePlayerList(data->playerList);
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LL_STATE_MEMBER_LEFT:
|
|
|
|
// BUG: sPlayerActivityGroupSize was meant below, not gPlayerCurrActivity
|
|
|
|
// This will be false for all but ACTIVITY_BATTLE_DOUBLE and ACTIVITY_DECLINE
|
|
|
|
// All this changes is which of two texts gets printed
|
2020-12-13 05:28:01 +01:00
|
|
|
#ifdef BUGFIX
|
|
|
|
id = (GROUP_MAX(sPlayerActivityGroupSize) == 2) ? 0 : 1;
|
|
|
|
#else
|
2020-06-09 00:16:57 +02:00
|
|
|
id = (GROUP_MAX(gPlayerCurrActivity) == 2) ? 1 : 0;
|
2020-12-13 05:28:01 +01:00
|
|
|
#endif
|
2019-12-10 19:48:20 +01:00
|
|
|
if (PrintOnTextbox(&data->textState, sPlayerUnavailableTexts[id]))
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
data->playerCount = LeaderPrunePlayerList(data->playerList);
|
2018-07-22 13:14:58 +02:00
|
|
|
RedrawListMenu(data->listTaskId);
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LL_STATE_GET_AWAITING_PLAYERS_TEXT;
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LL_STATE_MEMBER_DISCONNECTED:
|
|
|
|
id = (GROUP_MAX(sPlayerActivityGroupSize) == 2) ? 0 : 1;
|
2019-12-10 19:48:20 +01:00
|
|
|
if (PrintOnTextbox(&data->textState, sPlayerUnavailableTexts[id]))
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LL_STATE_SHUTDOWN_AND_RETRY;
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LL_STATE_ACCEPT_NEW_MEMBER_PROMPT:
|
2018-06-03 09:37:01 +02:00
|
|
|
if (PrintOnTextbox(&data->textState, gStringVar4))
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LL_STATE_ACCEPT_NEW_MEMBER_PROMPT_HANDLE_INPUT;
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LL_STATE_ACCEPT_NEW_MEMBER_PROMPT_HANDLE_INPUT:
|
2021-10-06 05:38:36 +02:00
|
|
|
switch (UnionRoomHandleYesNo(&data->textState, HasTrainerLeftPartnersList(ReadAsU16(data->playerList->players[data->playerCount].rfu.data.compatibility.playerTrainerId), data->playerList->players[data->playerCount].rfu.name)))
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
case 0: // YES
|
2019-04-04 23:05:46 +02:00
|
|
|
LoadWirelessStatusIndicatorSpriteGfx();
|
2018-06-03 09:37:01 +02:00
|
|
|
CreateWirelessStatusIndicatorSprite(0, 0);
|
2020-06-09 00:16:57 +02:00
|
|
|
data->joinRequestAnswer = RFU_STATUS_JOIN_GROUP_OK;
|
2021-10-06 05:38:36 +02:00
|
|
|
SendRfuStatusToPartner(data->joinRequestAnswer, ReadAsU16(data->playerList->players[data->playerCount].rfu.data.compatibility.playerTrainerId), data->playerList->players[data->playerCount].rfu.name);
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LL_STATE_UPDATE_AFTER_JOIN_REQUEST;
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case 1: // NO
|
2021-10-06 05:38:36 +02:00
|
|
|
case MENU_B_PRESSED:
|
2020-06-09 00:16:57 +02:00
|
|
|
data->joinRequestAnswer = RFU_STATUS_JOIN_GROUP_NO;
|
2021-10-06 05:38:36 +02:00
|
|
|
SendRfuStatusToPartner(data->joinRequestAnswer, ReadAsU16(data->playerList->players[data->playerCount].rfu.data.compatibility.playerTrainerId), data->playerList->players[data->playerCount].rfu.name);
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LL_STATE_UPDATE_AFTER_JOIN_REQUEST;
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
|
|
|
case -3:
|
2021-07-12 02:42:05 +02:00
|
|
|
data->state = LL_STATE_WAIT_DISCONNECT_CHILD;
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LL_STATE_UPDATE_AFTER_JOIN_REQUEST:
|
2021-10-06 05:38:36 +02:00
|
|
|
val = WaitSendRfuStatusToPartner(ReadAsU16(data->playerList->players[data->playerCount].rfu.data.compatibility.playerTrainerId), data->playerList->players[data->playerCount].rfu.name);
|
2020-06-09 00:16:57 +02:00
|
|
|
if (val == 1) // Send complete
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
if (data->joinRequestAnswer == RFU_STATUS_JOIN_GROUP_OK)
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2021-10-07 21:32:51 +02:00
|
|
|
data->playerList->players[data->playerCount].newPlayerCountdown = 0;
|
2018-07-22 13:14:58 +02:00
|
|
|
RedrawListMenu(data->listTaskId);
|
2020-05-30 10:09:21 +02:00
|
|
|
data->playerCount++;
|
2020-06-09 00:16:57 +02:00
|
|
|
if (data->playerCount == GROUP_MAX(sPlayerActivityGroupSize))
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (GROUP_MIN2(sPlayerActivityGroupSize) != 0 || data->playerCount == RFU_CHILD_MAX)
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LL_STATE_MEMBERS_OK_PROMPT;
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
CopyAndTranslatePlayerName(gStringVar1, &data->playerList->players[data->playerCount - 1]);
|
2019-12-10 19:48:20 +01:00
|
|
|
StringExpandPlaceholders(gStringVar4, sText_AnOKWasSentToPlayer);
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LL_STATE_ACCEPTED_FINAL_MEMBER;
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
LinkRfu_StopManagerAndFinalizeSlots();
|
|
|
|
PrintNumPlayersWaitingForMsg(data->nPlayerModeWindowId, sPlayerActivityGroupSize, data->playerCount);
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LL_STATE_GET_AWAITING_PLAYERS_TEXT;
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
|
|
|
}
|
2020-06-09 00:16:57 +02:00
|
|
|
else // Member disconnected
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
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);
|
2018-07-22 13:14:58 +02:00
|
|
|
RedrawListMenu(data->listTaskId);
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LL_STATE_GET_AWAITING_PLAYERS_TEXT;
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
data->joinRequestAnswer = 0;
|
2018-06-01 23:08:25 +02:00
|
|
|
}
|
2018-06-03 09:37:01 +02:00
|
|
|
else if (val == 2)
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(RFU_STATUS_OK, 0);
|
|
|
|
data->state = LL_STATE_GET_AWAITING_PLAYERS_TEXT;
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LL_STATE_ACCEPTED_FINAL_MEMBER:
|
2018-06-03 09:37:01 +02:00
|
|
|
if (PrintOnTextbox(&data->textState, gStringVar4))
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LL_STATE_WAIT_AND_CONFIRM_MEMBERS;
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LL_STATE_WAIT_AND_CONFIRM_MEMBERS:
|
2020-05-30 10:09:21 +02:00
|
|
|
if (++data->delayTimerAfterOk > 120)
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LL_STATE_CONFIRMED_MEMBERS;
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LL_STATE_MEMBERS_OK_PROMPT:
|
2019-12-10 19:48:20 +01:00
|
|
|
if (PrintOnTextbox(&data->textState, sText_AreTheseMembersOK))
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LL_STATE_MEMBERS_OK_PROMPT_HANDLE_INPUT;
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LL_STATE_MEMBERS_OK_PROMPT_HANDLE_INPUT:
|
2020-05-30 10:09:21 +02:00
|
|
|
switch (UnionRoomHandleYesNo(&data->textState, FALSE))
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
case 0: // YES
|
|
|
|
data->state = LL_STATE_CONFIRMED_MEMBERS;
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case 1: // NO
|
2021-10-06 05:38:36 +02:00
|
|
|
case MENU_B_PRESSED:
|
2020-06-09 00:16:57 +02:00
|
|
|
if (GROUP_MIN2(sPlayerActivityGroupSize) != 0)
|
|
|
|
data->state = LL_STATE_CANCEL_WITH_MSG;
|
2018-06-03 09:37:01 +02:00
|
|
|
else
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LL_STATE_CANCEL_PROMPT;
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LL_STATE_CANCEL_PROMPT:
|
2019-12-10 19:48:20 +01:00
|
|
|
if (PrintOnTextbox(&data->textState, sText_CancelModeWithTheseMembers))
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LL_STATE_CANCEL_PROMPT_HANDLE_INPUT;
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LL_STATE_CANCEL_PROMPT_HANDLE_INPUT:
|
2020-05-30 10:09:21 +02:00
|
|
|
switch (UnionRoomHandleYesNo(&data->textState, FALSE))
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
case 0: // YES
|
|
|
|
data->state = LL_STATE_SHUTDOWN_AND_FAIL;
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case 1: // NO
|
2021-10-06 05:38:36 +02:00
|
|
|
case MENU_B_PRESSED:
|
2020-06-09 00:16:57 +02:00
|
|
|
if (GROUP_MIN2(sPlayerActivityGroupSize) != 0)
|
|
|
|
data->state = LL_STATE_MEMBERS_OK_PROMPT;
|
|
|
|
else if (data->playerCount == GROUP_MAX(sPlayerActivityGroupSize))
|
|
|
|
data->state = LL_STATE_MEMBERS_OK_PROMPT;
|
2018-06-03 09:37:01 +02:00
|
|
|
else
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LL_STATE_GET_AWAITING_PLAYERS_TEXT;
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LL_STATE_CONFIRMED_MEMBERS:
|
|
|
|
if (!Leader_SetStateIfMemberListChanged(data, LL_STATE_ACCEPT_NEW_MEMBER_PROMPT, LL_STATE_MEMBER_DISCONNECTED))
|
|
|
|
data->state = LL_STATE_FINAL_MEMBER_CHECK;
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LL_STATE_FINAL_MEMBER_CHECK:
|
2020-05-30 10:09:21 +02:00
|
|
|
if (LmanAcceptSlotFlagIsNotZero())
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
if (WaitRfuState(FALSE))
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LL_STATE_TRY_START_ACTIVITY;
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
if (++data->memberConfirmTimeout > 300)
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LL_STATE_MEMBER_DISCONNECTED;
|
2018-06-03 09:37:01 +02:00
|
|
|
data->textState = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LL_STATE_MEMBER_DISCONNECTED;
|
2018-06-03 09:37:01 +02:00
|
|
|
data->textState = 0;
|
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LL_STATE_CANCEL_WITH_MSG:
|
2019-12-10 19:48:20 +01:00
|
|
|
if (PrintOnTextbox(&data->textState, sText_ModeWithTheseMembersWillBeCanceled))
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LL_STATE_SHUTDOWN_AND_FAIL;
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LL_STATE_SHUTDOWN_AND_RETRY:
|
|
|
|
case LL_STATE_SHUTDOWN_AND_FAIL:
|
2019-04-01 00:59:52 +02:00
|
|
|
DestroyWirelessStatusIndicatorSprite();
|
2020-05-30 10:09:21 +02:00
|
|
|
LinkRfu_Shutdown();
|
|
|
|
Leader_DestroyResources(data);
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state++; // LL_STATE_RETRY or LL_STATE_FAILED
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LL_STATE_FAILED:
|
2018-06-03 09:37:01 +02:00
|
|
|
EnableBothScriptContexts();
|
|
|
|
DestroyTask(taskId);
|
2020-06-09 00:16:57 +02:00
|
|
|
gSpecialVar_Result = LINKUP_FAILED;
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LL_STATE_RETRY:
|
2018-06-03 09:37:01 +02:00
|
|
|
EnableBothScriptContexts();
|
|
|
|
DestroyTask(taskId);
|
2020-06-09 00:16:57 +02:00
|
|
|
gSpecialVar_Result = LINKUP_RETRY_ROLE_ASSIGN;
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LL_STATE_TRY_START_ACTIVITY:
|
|
|
|
if (RfuHasErrored())
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LL_STATE_MEMBER_DISCONNECTED;
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (gReceivedRemoteLinkPlayers != 0)
|
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
if (IsActivityWithVariableGroupSize(gPlayerCurrActivity))
|
2021-08-16 00:26:09 +02:00
|
|
|
GetOtherPlayersInfoFlags();
|
2020-05-30 10:09:21 +02:00
|
|
|
UpdateGameData_GroupLockedIn(TRUE);
|
|
|
|
CreateTask_RunScriptAndFadeToActivity();
|
|
|
|
Leader_DestroyResources(data);
|
2018-06-03 09:37:01 +02:00
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void Leader_DestroyResources(struct WirelessLink_Leader *data)
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
ClearWindowTilemap(data->nPlayerModeWindowId);
|
|
|
|
ClearStdWindowAndFrame(data->nPlayerModeWindowId, FALSE);
|
2018-06-03 09:37:01 +02:00
|
|
|
DestroyListMenuTask(data->listTaskId, 0, 0);
|
2020-05-30 10:09:21 +02:00
|
|
|
ClearWindowTilemap(data->bButtonCancelWindowId);
|
2019-02-22 07:40:11 +01:00
|
|
|
ClearStdWindowAndFrame(data->listWindowId, FALSE);
|
2018-06-03 09:37:01 +02:00
|
|
|
CopyBgTilemapBufferToVram(0);
|
2020-05-30 10:09:21 +02:00
|
|
|
RemoveWindow(data->nPlayerModeWindowId);
|
2018-06-04 12:07:32 +02:00
|
|
|
RemoveWindow(data->listWindowId);
|
2020-05-30 10:09:21 +02:00
|
|
|
RemoveWindow(data->bButtonCancelWindowId);
|
|
|
|
DestroyTask(data->listenTaskId);
|
2018-06-03 09:37:01 +02:00
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
Free(data->playerListBackup);
|
|
|
|
Free(data->playerList);
|
|
|
|
Free(data->incomingPlayerList);
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void Leader_GetAcceptNewMemberPrompt(u8 *dst, u8 caseId)
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
|
|
|
switch (caseId)
|
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_BATTLE_SINGLE:
|
|
|
|
case ACTIVITY_BATTLE_DOUBLE:
|
|
|
|
case ACTIVITY_TRADE:
|
|
|
|
case ACTIVITY_BATTLE_TOWER_OPEN:
|
|
|
|
case ACTIVITY_BATTLE_TOWER:
|
2019-12-10 19:48:20 +01:00
|
|
|
StringExpandPlaceholders(dst, sText_PlayerContactedYouForXAccept);
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
2021-10-06 05:38:36 +02:00
|
|
|
case ACTIVITY_WONDER_CARD:
|
|
|
|
case ACTIVITY_WONDER_NEWS:
|
2019-12-10 19:48:20 +01:00
|
|
|
StringExpandPlaceholders(dst, sText_PlayerContactedYouShareX);
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_BATTLE_MULTI:
|
|
|
|
case ACTIVITY_POKEMON_JUMP:
|
|
|
|
case ACTIVITY_BERRY_CRUSH:
|
|
|
|
case ACTIVITY_BERRY_PICK:
|
|
|
|
case ACTIVITY_RECORD_CORNER:
|
|
|
|
case ACTIVITY_BERRY_BLENDER:
|
|
|
|
case ACTIVITY_CONTEST_COOL:
|
|
|
|
case ACTIVITY_CONTEST_BEAUTY:
|
|
|
|
case ACTIVITY_CONTEST_CUTE:
|
|
|
|
case ACTIVITY_CONTEST_SMART:
|
|
|
|
case ACTIVITY_CONTEST_TOUGH:
|
2019-12-10 19:48:20 +01:00
|
|
|
StringExpandPlaceholders(dst, sText_PlayerContactedYouAddToMembers);
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void GetYouDeclinedTheOfferMessage(u8 *dst, u8 caseId)
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
|
|
|
switch (caseId)
|
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_BATTLE_SINGLE | IN_UNION_ROOM:
|
|
|
|
case ACTIVITY_TRADE | IN_UNION_ROOM:
|
2019-10-05 05:31:25 +02:00
|
|
|
StringExpandPlaceholders(dst, sText_OfferDeclined1);
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_CHAT | IN_UNION_ROOM:
|
|
|
|
case ACTIVITY_CARD | IN_UNION_ROOM:
|
2019-10-05 05:31:25 +02:00
|
|
|
StringExpandPlaceholders(dst, sText_OfferDeclined2);
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void GetYouAskedToJoinGroupPleaseWaitMessage(u8 *dst, u8 caseId)
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
|
|
|
switch (caseId)
|
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_BATTLE_SINGLE:
|
|
|
|
case ACTIVITY_BATTLE_DOUBLE:
|
|
|
|
case ACTIVITY_TRADE:
|
|
|
|
case ACTIVITY_BATTLE_TOWER:
|
|
|
|
case ACTIVITY_BATTLE_TOWER_OPEN:
|
2021-10-06 05:38:36 +02:00
|
|
|
case ACTIVITY_WONDER_CARD:
|
|
|
|
case ACTIVITY_WONDER_NEWS:
|
2019-12-10 19:48:20 +01:00
|
|
|
StringExpandPlaceholders(dst, sText_AwaitingPlayersResponse);
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_BATTLE_MULTI:
|
|
|
|
case ACTIVITY_POKEMON_JUMP:
|
|
|
|
case ACTIVITY_BERRY_CRUSH:
|
|
|
|
case ACTIVITY_BERRY_PICK:
|
|
|
|
case ACTIVITY_RECORD_CORNER:
|
|
|
|
case ACTIVITY_BERRY_BLENDER:
|
|
|
|
case ACTIVITY_CONTEST_COOL:
|
|
|
|
case ACTIVITY_CONTEST_BEAUTY:
|
|
|
|
case ACTIVITY_CONTEST_CUTE:
|
|
|
|
case ACTIVITY_CONTEST_SMART:
|
|
|
|
case ACTIVITY_CONTEST_TOUGH:
|
2019-12-10 19:48:20 +01:00
|
|
|
StringExpandPlaceholders(dst, sText_PlayerHasBeenAskedToRegisterYouPleaseWait);
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void GetGroupLeaderSentAnOKMessage(u8 *dst, u8 caseId)
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
|
|
|
switch (caseId)
|
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_BATTLE_SINGLE:
|
|
|
|
case ACTIVITY_BATTLE_DOUBLE:
|
|
|
|
case ACTIVITY_TRADE:
|
|
|
|
case ACTIVITY_BATTLE_TOWER:
|
|
|
|
case ACTIVITY_BATTLE_TOWER_OPEN:
|
2021-10-06 05:38:36 +02:00
|
|
|
case ACTIVITY_WONDER_CARD:
|
|
|
|
case ACTIVITY_WONDER_NEWS:
|
2019-12-10 19:48:20 +01:00
|
|
|
StringExpandPlaceholders(dst, sText_PlayerSentBackOK);
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_BATTLE_MULTI:
|
|
|
|
case ACTIVITY_POKEMON_JUMP:
|
|
|
|
case ACTIVITY_BERRY_CRUSH:
|
|
|
|
case ACTIVITY_BERRY_PICK:
|
|
|
|
case ACTIVITY_RECORD_CORNER:
|
|
|
|
case ACTIVITY_BERRY_BLENDER:
|
|
|
|
case ACTIVITY_CONTEST_COOL:
|
|
|
|
case ACTIVITY_CONTEST_BEAUTY:
|
|
|
|
case ACTIVITY_CONTEST_CUTE:
|
|
|
|
case ACTIVITY_CONTEST_SMART:
|
|
|
|
case ACTIVITY_CONTEST_TOUGH:
|
2019-12-10 19:48:20 +01:00
|
|
|
StringExpandPlaceholders(dst, sText_PlayerOKdRegistration);
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
static bool8 Leader_SetStateIfMemberListChanged(struct WirelessLink_Leader *data, u32 joinedState, u32 droppedState)
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
switch (LeaderUpdateGroupMembership(data->playerList))
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
case UNION_ROOM_SPAWN_IN:
|
2018-06-03 09:37:01 +02:00
|
|
|
PlaySE(SE_PC_LOGIN);
|
2018-07-22 13:14:58 +02:00
|
|
|
RedrawListMenu(data->listTaskId);
|
2021-10-06 05:38:36 +02:00
|
|
|
CopyAndTranslatePlayerName(gStringVar2, &data->playerList->players[data->playerCount]);
|
2020-05-30 10:09:21 +02:00
|
|
|
Leader_GetAcceptNewMemberPrompt(gStringVar4, gPlayerCurrActivity);
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = joinedState;
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case UNION_ROOM_SPAWN_OUT:
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(RFU_STATUS_OK, 0);
|
2018-07-22 13:14:58 +02:00
|
|
|
RedrawListMenu(data->listTaskId);
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = droppedState;
|
2018-06-03 09:37:01 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-06-18 06:15:45 +02:00
|
|
|
static void ItemPrintFunc_PossibleGroupMembers(u8 windowId, u32 id, u8 y)
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
struct WirelessLink_Leader *data = sWirelessLinkMain.leader;
|
2021-10-06 05:38:36 +02:00
|
|
|
u8 colorIdx = UR_COLOR_DEFAULT;
|
2018-06-03 09:37:01 +02:00
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
switch (data->playerList->players[id].groupScheduledAnim)
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
case UNION_ROOM_SPAWN_IN:
|
2021-10-07 21:32:51 +02:00
|
|
|
if (data->playerList->players[id].newPlayerCountdown != 0)
|
2021-10-06 05:38:36 +02:00
|
|
|
colorIdx = UR_COLOR_GREEN;
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case UNION_ROOM_SPAWN_OUT:
|
2021-10-06 05:38:36 +02:00
|
|
|
colorIdx = UR_COLOR_RED;
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
PrintGroupCandidateOnWindow(windowId, 0, y, &data->playerList->players[id], colorIdx, id);
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static u8 LeaderUpdateGroupMembership(struct RfuPlayerList *list)
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
struct WirelessLink_Leader *data = sWirelessLinkMain.leader;
|
|
|
|
u8 ret = UNION_ROOM_SPAWN_NONE;
|
2018-06-03 09:37:01 +02:00
|
|
|
u8 i;
|
|
|
|
s32 id;
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
for (i = 1; i < MAX_RFU_PLAYERS; i++)
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
u16 var = data->playerList->players[i].groupScheduledAnim;
|
2020-05-30 10:09:21 +02:00
|
|
|
if (var == UNION_ROOM_SPAWN_IN)
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
id = GetNewIncomingPlayerId(&data->playerList->players[i], data->incomingPlayerList->players);
|
2018-06-03 09:37:01 +02:00
|
|
|
if (id != 0xFF)
|
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
// New incoming player
|
|
|
|
data->playerList->players[i].rfu = data->incomingPlayerList->players[id].rfu;
|
|
|
|
data->playerList->players[i].timeoutCounter = 1;
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
// No new incoming player
|
|
|
|
data->playerList->players[i].groupScheduledAnim = UNION_ROOM_SPAWN_OUT;
|
2020-05-30 10:09:21 +02:00
|
|
|
ret = UNION_ROOM_SPAWN_OUT;
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
for (id = 0; id < RFU_CHILD_MAX; id++)
|
2021-10-06 05:38:36 +02:00
|
|
|
TryAddIncomingPlayerToList(data->playerList->players, &data->incomingPlayerList->players[id], MAX_RFU_PLAYERS);
|
2018-06-03 09:37:01 +02:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
if (ret != UNION_ROOM_SPAWN_OUT)
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
for (id = 0; id < MAX_RFU_PLAYERS; id++)
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2021-10-07 21:32:51 +02:00
|
|
|
if (data->playerList->players[id].newPlayerCountdown != 0)
|
2020-05-30 10:09:21 +02:00
|
|
|
ret = UNION_ROOM_SPAWN_IN;
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static u8 LeaderPrunePlayerList(struct RfuPlayerList *list)
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
struct WirelessLink_Leader *data = sWirelessLinkMain.leader;
|
2018-06-03 09:37:01 +02:00
|
|
|
u8 copiedCount;
|
|
|
|
s32 i;
|
2020-06-09 00:16:57 +02:00
|
|
|
u8 playerCount;
|
2018-06-03 09:37:01 +02:00
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
for (i = 0; i < MAX_RFU_PLAYERS; i++)
|
2021-10-06 05:38:36 +02:00
|
|
|
data->playerListBackup->players[i] = data->playerList->players[i];
|
2018-06-03 09:37:01 +02:00
|
|
|
|
|
|
|
copiedCount = 0;
|
2020-06-09 00:16:57 +02:00
|
|
|
for (i = 0; i < MAX_RFU_PLAYERS; i++)
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (data->playerListBackup->players[i].groupScheduledAnim == UNION_ROOM_SPAWN_IN)
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
data->playerList->players[copiedCount] = data->playerListBackup->players[i];
|
2018-06-03 09:37:01 +02:00
|
|
|
copiedCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
playerCount = copiedCount;
|
|
|
|
for (; copiedCount < MAX_RFU_PLAYERS; copiedCount++)
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
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;
|
2021-10-07 21:32:51 +02:00
|
|
|
data->playerList->players[copiedCount].newPlayerCountdown = 0;
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
for (i = 0; i < MAX_RFU_PLAYERS; i++)
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (data->playerList->players[i].groupScheduledAnim != UNION_ROOM_SPAWN_IN)
|
2018-06-03 09:37:01 +02:00
|
|
|
continue;
|
2021-10-07 21:32:51 +02:00
|
|
|
if (data->playerList->players[i].newPlayerCountdown != 64)
|
2018-06-03 09:37:01 +02:00
|
|
|
continue;
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
playerCount = i;
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
return playerCount;
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
|
|
|
|
2019-10-11 10:14:09 +02:00
|
|
|
void TryJoinLinkGroup(void)
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
|
|
|
u8 taskId;
|
2020-05-30 10:09:21 +02:00
|
|
|
struct WirelessLink_Group *data;
|
2018-06-03 09:37:01 +02:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
taskId = CreateTask(Task_TryJoinLinkGroup, 0);
|
|
|
|
sWirelessLinkMain.group = data = (void*)(gTasks[taskId].data);
|
|
|
|
sGroup = data;
|
2018-06-03 09:37:01 +02:00
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LG_STATE_INIT;
|
2020-05-30 10:09:21 +02:00
|
|
|
data->textState = 0;
|
2020-06-09 00:16:57 +02:00
|
|
|
gSpecialVar_Result = LINKUP_ONGOING;
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void Task_TryJoinLinkGroup(u8 taskId)
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
|
|
|
s32 id;
|
2020-05-30 10:09:21 +02:00
|
|
|
struct WirelessLink_Group *data = sWirelessLinkMain.group;
|
2018-06-03 09:37:01 +02:00
|
|
|
|
|
|
|
switch (data->state)
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
case LG_STATE_INIT:
|
2019-11-11 03:54:00 +01:00
|
|
|
if (gSpecialVar_0x8004 == LINK_GROUP_BATTLE_TOWER && gSaveBlock2Ptr->frontier.lvlMode == FRONTIER_LVL_OPEN)
|
2018-06-03 09:37:01 +02:00
|
|
|
gSpecialVar_0x8004++;
|
2020-05-30 10:09:21 +02:00
|
|
|
gPlayerCurrActivity = sLinkGroupToURoomActivity[gSpecialVar_0x8004];
|
2021-10-06 05:38:36 +02:00
|
|
|
SetHostRfuGameData(gPlayerCurrActivity, 0, FALSE);
|
2020-05-30 10:09:21 +02:00
|
|
|
SetWirelessCommType1();
|
2018-06-03 09:37:01 +02:00
|
|
|
OpenLink();
|
2020-05-30 10:09:21 +02:00
|
|
|
InitializeRfuLinkManager_JoinGroup();
|
2021-10-06 05:38:36 +02:00
|
|
|
data->incomingPlayerList = AllocZeroed(RFU_CHILD_MAX * sizeof(struct RfuIncomingPlayer));
|
|
|
|
data->playerList = AllocZeroed(MAX_RFU_PLAYER_LIST_SIZE * sizeof(struct RfuPlayer));
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LG_STATE_CHOOSE_LEADER_MSG;
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LG_STATE_CHOOSE_LEADER_MSG:
|
2019-11-11 03:54:00 +01:00
|
|
|
if (PrintOnTextbox(&data->textState, sChooseTrainerTexts[gSpecialVar_0x8004]))
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LG_STATE_INIT_WINDOWS;
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LG_STATE_INIT_WINDOWS:
|
2021-10-06 05:38:36 +02:00
|
|
|
ClearIncomingPlayerList(data->incomingPlayerList, RFU_CHILD_MAX);
|
|
|
|
ClearRfuPlayerList(data->playerList->players, MAX_RFU_PLAYER_LIST_SIZE);
|
|
|
|
data->listenTaskId = CreateTask_ListenForCompatiblePartners(data->incomingPlayerList, gSpecialVar_0x8004);
|
2020-05-30 10:09:21 +02:00
|
|
|
data->bButtonCancelWindowId = AddWindow(&sWindowTemplate_BButtonCancel);
|
2021-10-06 05:38:36 +02:00
|
|
|
data->listWindowId = AddWindow(&sWindowTemplate_GroupList);
|
|
|
|
data->playerNameAndIdWindowId = AddWindow(&sWindowTemplate_PlayerNameAndId);
|
2018-06-03 09:37:01 +02:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
FillWindowPixelBuffer(data->bButtonCancelWindowId, PIXEL_FILL(2));
|
2021-10-06 05:38:36 +02:00
|
|
|
PrintUnionRoomText(data->bButtonCancelWindowId, 0, sText_ChooseJoinCancel, 8, 1, UR_COLOR_CANCEL);
|
2020-05-30 10:09:21 +02:00
|
|
|
PutWindowTilemap(data->bButtonCancelWindowId);
|
|
|
|
CopyWindowToVram(data->bButtonCancelWindowId, 2);
|
2018-06-03 09:37:01 +02:00
|
|
|
|
2019-02-22 07:40:11 +01:00
|
|
|
DrawStdWindowFrame(data->listWindowId, FALSE);
|
2020-05-30 10:09:21 +02:00
|
|
|
gMultiuseListMenuTemplate = sListMenuTemplate_UnionRoomGroups;
|
2018-06-04 23:32:28 +02:00
|
|
|
gMultiuseListMenuTemplate.windowId = data->listWindowId;
|
2018-06-03 09:37:01 +02:00
|
|
|
data->listTaskId = ListMenuInit(&gMultiuseListMenuTemplate, 0, 0);
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
DrawStdWindowFrame(data->playerNameAndIdWindowId, FALSE);
|
|
|
|
PutWindowTilemap(data->playerNameAndIdWindowId);
|
|
|
|
PrintPlayerNameAndIdOnWindow(data->playerNameAndIdWindowId);
|
|
|
|
CopyWindowToVram(data->playerNameAndIdWindowId, 2);
|
2018-06-03 09:37:01 +02:00
|
|
|
|
|
|
|
CopyBgTilemapBufferToVram(0);
|
2020-05-30 10:09:21 +02:00
|
|
|
data->leaderId = 0;
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LG_STATE_CHOOSE_LEADER_HANDLE_INPUT;
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LG_STATE_CHOOSE_LEADER_HANDLE_INPUT:
|
2020-05-30 10:09:21 +02:00
|
|
|
id = GetNewLeaderCandidate();
|
2018-06-03 09:37:01 +02:00
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
PlaySE(SE_PC_LOGIN);
|
2018-07-22 13:14:58 +02:00
|
|
|
RedrawListMenu(data->listTaskId);
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
|
|
|
case 0:
|
2019-02-02 11:04:38 +01:00
|
|
|
id = ListMenu_ProcessInput(data->listTaskId);
|
2021-10-06 05:38:36 +02:00
|
|
|
if (JOY_NEW(A_BUTTON) && id != MENU_B_PRESSED)
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2018-06-03 22:39:10 +02:00
|
|
|
// this unused variable along with the assignment is needed to match
|
2021-10-06 05:38:36 +02:00
|
|
|
u32 activity = data->playerList->players[id].rfu.data.activity;
|
2018-06-03 09:37:01 +02:00
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
if (data->playerList->players[id].groupScheduledAnim == UNION_ROOM_SPAWN_IN && !data->playerList->players[id].rfu.data.startedActivity)
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
u32 readyStatus = IsTryingToTradeAcrossVersionTooSoon(data, id);
|
|
|
|
if (readyStatus == UR_TRADE_READY)
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
// Trading is allowed, or not trading at all
|
2020-05-30 10:09:21 +02:00
|
|
|
AskToJoinRfuGroup(data, id);
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LG_STATE_ASK_JOIN_GROUP;
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_POKENAV_ON);
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
StringCopy(gStringVar4, sCantTransmitToTrainerTexts[readyStatus - 1]);
|
|
|
|
data->state = LG_STATE_TRADE_NOT_READY;
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_POKENAV_ON);
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PlaySE(SE_WALL_HIT);
|
|
|
|
}
|
|
|
|
}
|
2020-09-05 03:11:55 +02:00
|
|
|
else if (JOY_NEW(B_BUTTON))
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LG_STATE_CANCEL_CHOOSE_LEADER;
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2018-07-22 13:14:58 +02:00
|
|
|
RedrawListMenu(data->listTaskId);
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LG_STATE_ASK_JOIN_GROUP:
|
2020-05-30 10:09:21 +02:00
|
|
|
GetYouAskedToJoinGroupPleaseWaitMessage(gStringVar4, gPlayerCurrActivity);
|
2018-06-03 09:37:01 +02:00
|
|
|
if (PrintOnTextbox(&data->textState, gStringVar4))
|
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
CopyAndTranslatePlayerName(gStringVar1, &data->playerList->players[data->leaderId]);
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LG_STATE_MAIN;
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LG_STATE_MAIN:
|
2020-05-30 10:09:21 +02:00
|
|
|
if (gReceivedRemoteLinkPlayers)
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
gPlayerCurrActivity = data->playerList->players[data->leaderId].rfu.data.activity;
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(RFU_STATUS_OK, 0);
|
2020-05-30 10:09:21 +02:00
|
|
|
switch (gPlayerCurrActivity)
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_BATTLE_SINGLE:
|
|
|
|
case ACTIVITY_BATTLE_DOUBLE:
|
|
|
|
case ACTIVITY_BATTLE_MULTI:
|
|
|
|
case ACTIVITY_TRADE:
|
|
|
|
case ACTIVITY_CHAT:
|
|
|
|
case ACTIVITY_POKEMON_JUMP:
|
|
|
|
case ACTIVITY_BERRY_CRUSH:
|
|
|
|
case ACTIVITY_BERRY_PICK:
|
|
|
|
case ACTIVITY_SPIN_TRADE:
|
|
|
|
case ACTIVITY_BATTLE_TOWER:
|
|
|
|
case ACTIVITY_BATTLE_TOWER_OPEN:
|
|
|
|
case ACTIVITY_RECORD_CORNER:
|
|
|
|
case ACTIVITY_BERRY_BLENDER:
|
2021-10-06 05:38:36 +02:00
|
|
|
case ACTIVITY_WONDER_CARD:
|
|
|
|
case ACTIVITY_WONDER_NEWS:
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_CONTEST_COOL:
|
|
|
|
case ACTIVITY_CONTEST_BEAUTY:
|
|
|
|
case ACTIVITY_CONTEST_CUTE:
|
|
|
|
case ACTIVITY_CONTEST_SMART:
|
|
|
|
case ACTIVITY_CONTEST_TOUGH:
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LG_STATE_READY_START_ACTIVITY;
|
2018-06-03 09:37:01 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
switch (RfuGetStatus())
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
case RFU_STATUS_FATAL_ERROR:
|
|
|
|
data->state = LG_STATE_RFU_ERROR;
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case RFU_STATUS_CONNECTION_ERROR:
|
|
|
|
case RFU_STATUS_JOIN_GROUP_NO:
|
|
|
|
case RFU_STATUS_LEAVE_GROUP:
|
|
|
|
data->state = LG_STATE_DISCONNECTED;
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case RFU_STATUS_JOIN_GROUP_OK:
|
2020-05-30 10:09:21 +02:00
|
|
|
GetGroupLeaderSentAnOKMessage(gStringVar4, gPlayerCurrActivity);
|
2018-06-03 09:37:01 +02:00
|
|
|
if (PrintOnTextbox(&data->textState, gStringVar4))
|
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
if (gPlayerCurrActivity == ACTIVITY_BATTLE_TOWER || gPlayerCurrActivity == ACTIVITY_BATTLE_TOWER_OPEN)
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(RFU_STATUS_ACK_JOIN_GROUP, 0);
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(RFU_STATUS_WAIT_ACK_JOIN_GROUP, 0);
|
|
|
|
StringCopy(gStringVar1, sLinkGroupActivityNameTexts[gPlayerCurrActivity]);
|
2019-12-10 19:48:20 +01:00
|
|
|
StringExpandPlaceholders(gStringVar4, sText_AwaitingOtherMembers);
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case RFU_STATUS_WAIT_ACK_JOIN_GROUP:
|
2020-05-30 10:09:21 +02:00
|
|
|
if (data->delayBeforePrint > 240)
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
|
|
|
if (PrintOnTextbox(&data->textState, gStringVar4))
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(RFU_STATUS_ACK_JOIN_GROUP, 0);
|
2020-05-30 10:09:21 +02:00
|
|
|
data->delayBeforePrint = 0;
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
switch (gPlayerCurrActivity)
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_BATTLE_SINGLE:
|
|
|
|
case ACTIVITY_BATTLE_DOUBLE:
|
|
|
|
case ACTIVITY_TRADE:
|
|
|
|
case ACTIVITY_BATTLE_TOWER:
|
|
|
|
case ACTIVITY_BATTLE_TOWER_OPEN:
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
|
|
|
default:
|
2020-05-30 10:09:21 +02:00
|
|
|
data->delayBeforePrint++;
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-09-05 03:11:55 +02:00
|
|
|
if (RfuGetStatus() == RFU_STATUS_OK && JOY_NEW(B_BUTTON))
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LG_STATE_ASK_LEAVE_GROUP;
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LG_STATE_ASK_LEAVE_GROUP:
|
2019-12-10 19:48:20 +01:00
|
|
|
if (PrintOnTextbox(&data->textState, sText_QuitBeingMember))
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LG_STATE_ASK_LEAVE_GROUP_HANDLE_INPUT;
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LG_STATE_ASK_LEAVE_GROUP_HANDLE_INPUT:
|
|
|
|
switch (UnionRoomHandleYesNo(&data->textState, RfuGetStatus()))
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
case 0: // YES
|
|
|
|
SendLeaveGroupNotice();
|
|
|
|
data->state = LG_STATE_WAIT_LEAVE_GROUP;
|
2018-07-22 13:14:58 +02:00
|
|
|
RedrawListMenu(data->listTaskId);
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case 1: // NO
|
2021-10-06 05:38:36 +02:00
|
|
|
case MENU_B_PRESSED:
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LG_STATE_ASK_JOIN_GROUP;
|
2018-07-22 13:14:58 +02:00
|
|
|
RedrawListMenu(data->listTaskId);
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
|
|
|
case -3:
|
2020-06-09 00:16:57 +02:00
|
|
|
data->state = LG_STATE_MAIN;
|
2018-07-22 13:14:58 +02:00
|
|
|
RedrawListMenu(data->listTaskId);
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LG_STATE_WAIT_LEAVE_GROUP:
|
|
|
|
if (RfuGetStatus())
|
|
|
|
data->state = LG_STATE_MAIN;
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LG_STATE_CANCEL_CHOOSE_LEADER: // next: LG_STATE_CANCELED
|
|
|
|
case LG_STATE_RFU_ERROR: // next: LG_STATE_RFU_ERROR_SHUTDOWN
|
|
|
|
case LG_STATE_DISCONNECTED: // next: LG_STATE_RETRY_CONNECTION
|
|
|
|
case LG_STATE_TRADE_NOT_READY: // next: LG_STATE_TRADE_NOT_READY_RETRY
|
|
|
|
case LG_STATE_READY_START_ACTIVITY: // next: LG_STATE_START_ACTIVITY
|
2020-05-30 10:09:21 +02:00
|
|
|
ClearWindowTilemap(data->playerNameAndIdWindowId);
|
|
|
|
ClearStdWindowAndFrame(data->playerNameAndIdWindowId, FALSE);
|
2018-06-03 09:37:01 +02:00
|
|
|
DestroyListMenuTask(data->listTaskId, 0, 0);
|
2020-05-30 10:09:21 +02:00
|
|
|
ClearWindowTilemap(data->bButtonCancelWindowId);
|
2019-02-22 07:40:11 +01:00
|
|
|
ClearStdWindowAndFrame(data->listWindowId, FALSE);
|
2018-06-03 09:37:01 +02:00
|
|
|
CopyBgTilemapBufferToVram(0);
|
2020-05-30 10:09:21 +02:00
|
|
|
RemoveWindow(data->playerNameAndIdWindowId);
|
2018-06-04 23:32:28 +02:00
|
|
|
RemoveWindow(data->listWindowId);
|
2020-05-30 10:09:21 +02:00
|
|
|
RemoveWindow(data->bButtonCancelWindowId);
|
|
|
|
DestroyTask(data->listenTaskId);
|
2021-10-06 05:38:36 +02:00
|
|
|
Free(data->playerList);
|
|
|
|
Free(data->incomingPlayerList);
|
2018-06-03 09:37:01 +02:00
|
|
|
data->state++;
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LG_STATE_RFU_ERROR_SHUTDOWN:
|
2019-04-01 00:59:52 +02:00
|
|
|
DestroyWirelessStatusIndicatorSprite();
|
2020-06-09 00:16:57 +02:00
|
|
|
if (PrintOnTextbox(&data->textState, sPlayerDisconnectedTexts[RfuGetStatus()]))
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
gSpecialVar_Result = LINKUP_CONNECTION_ERROR;
|
|
|
|
data->state = LG_STATE_SHUTDOWN;
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LG_STATE_CANCELED:
|
2019-04-01 00:59:52 +02:00
|
|
|
DestroyWirelessStatusIndicatorSprite();
|
2020-06-09 00:16:57 +02:00
|
|
|
gSpecialVar_Result = LINKUP_FAILED;
|
|
|
|
data->state = LG_STATE_SHUTDOWN;
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LG_STATE_RETRY_CONNECTION:
|
|
|
|
// Failure from disconnection
|
|
|
|
// Happens if player or required member(s) leave group
|
|
|
|
// or if player is rejected from joining group
|
2019-04-01 00:59:52 +02:00
|
|
|
DestroyWirelessStatusIndicatorSprite();
|
2020-06-09 00:16:57 +02:00
|
|
|
if (PrintOnTextbox(&data->textState, sPlayerDisconnectedTexts[RfuGetStatus()]))
|
2018-06-03 09:37:01 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
gSpecialVar_Result = LINKUP_RETRY_ROLE_ASSIGN;
|
|
|
|
data->state = LG_STATE_SHUTDOWN;
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LG_STATE_TRADE_NOT_READY_RETRY:
|
2018-06-03 09:37:01 +02:00
|
|
|
if (PrintOnTextbox(&data->textState, gStringVar4))
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
gSpecialVar_Result = LINKUP_RETRY_ROLE_ASSIGN;
|
|
|
|
data->state = LG_STATE_SHUTDOWN;
|
2018-06-03 09:37:01 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LG_STATE_SHUTDOWN:
|
2018-06-03 09:37:01 +02:00
|
|
|
DestroyTask(taskId);
|
2020-05-30 10:09:21 +02:00
|
|
|
JoinGroup_EnableScriptContexts();
|
|
|
|
LinkRfu_Shutdown();
|
2018-06-03 09:37:01 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case LG_STATE_START_ACTIVITY:
|
2020-05-30 10:09:21 +02:00
|
|
|
CreateTask_RunScriptAndFadeToActivity();
|
2018-06-03 09:37:01 +02:00
|
|
|
DestroyTask(taskId);
|
2018-06-01 23:08:25 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-06-03 22:39:10 +02:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static u32 IsTryingToTradeAcrossVersionTooSoon(struct WirelessLink_Group *data, s32 id)
|
2018-06-03 22:39:10 +02:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
struct RfuPlayer *partner = &data->playerList->players[id];
|
2018-06-03 22:39:10 +02:00
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
if (gPlayerCurrActivity == ACTIVITY_TRADE && partner->rfu.data.compatibility.version != VERSION_EMERALD)
|
2018-06-03 22:39:10 +02:00
|
|
|
{
|
2019-11-07 19:26:53 +01:00
|
|
|
if (!(gSaveBlock2Ptr->specialSaveWarpFlags & CHAMPION_SAVEWARP))
|
2020-06-09 00:16:57 +02:00
|
|
|
return UR_TRADE_PLAYER_NOT_READY;
|
2021-10-06 05:38:36 +02:00
|
|
|
else if (partner->rfu.data.compatibility.isChampion)
|
2020-06-09 00:16:57 +02:00
|
|
|
return UR_TRADE_READY;
|
2018-06-03 22:39:10 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
return UR_TRADE_READY;
|
2018-06-03 22:39:10 +02:00
|
|
|
}
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
return UR_TRADE_PARTNER_NOT_READY;
|
2018-06-03 22:39:10 +02:00
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void AskToJoinRfuGroup(struct WirelessLink_Group *data, s32 id)
|
2018-06-03 22:39:10 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
data->leaderId = id;
|
2019-04-04 23:05:46 +02:00
|
|
|
LoadWirelessStatusIndicatorSpriteGfx();
|
2018-06-03 22:39:10 +02:00
|
|
|
CreateWirelessStatusIndicatorSprite(0, 0);
|
2018-07-22 13:14:58 +02:00
|
|
|
RedrawListMenu(data->listTaskId);
|
2021-10-06 05:38:36 +02:00
|
|
|
CopyAndTranslatePlayerName(gStringVar1, &data->playerList->players[data->leaderId]);
|
2020-06-09 00:16:57 +02:00
|
|
|
UpdateGameData_SetActivity(sLinkGroupToURoomActivity[gSpecialVar_0x8004], 0, TRUE);
|
2021-10-06 05:38:36 +02:00
|
|
|
CreateTask_RfuReconnectWithParent(data->playerList->players[data->leaderId].rfu.name, ReadAsU16(data->playerList->players[data->leaderId].rfu.data.compatibility.playerTrainerId));
|
2018-06-03 22:39:10 +02:00
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
u8 CreateTask_ListenToWireless(void)
|
2018-06-03 22:39:10 +02:00
|
|
|
{
|
|
|
|
u8 taskId;
|
2020-05-30 10:09:21 +02:00
|
|
|
struct WirelessLink_Group *data;
|
2018-06-03 22:39:10 +02:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
taskId = CreateTask(Task_ListenToWireless, 0);
|
|
|
|
sWirelessLinkMain.group = data = (void*)(gTasks[taskId].data);
|
2018-06-03 22:39:10 +02:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
data->state = 0;
|
|
|
|
data->textState = 0;
|
2018-06-03 22:39:10 +02:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
sGroup = data;
|
2018-06-03 22:39:10 +02:00
|
|
|
|
|
|
|
return taskId;
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void Task_ListenToWireless(u8 taskId)
|
2018-06-03 22:39:10 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
struct WirelessLink_Group *data = sWirelessLinkMain.group;
|
2018-06-03 22:39:10 +02:00
|
|
|
|
|
|
|
switch (data->state)
|
|
|
|
{
|
|
|
|
case 0:
|
2021-10-06 05:38:36 +02:00
|
|
|
SetHostRfuGameData(ACTIVITY_NONE, 0, FALSE);
|
2020-05-30 10:09:21 +02:00
|
|
|
SetWirelessCommType1();
|
2018-06-03 22:39:10 +02:00
|
|
|
OpenLink();
|
2020-05-30 10:09:21 +02:00
|
|
|
InitializeRfuLinkManager_JoinGroup();
|
2021-08-16 00:26:09 +02:00
|
|
|
RfuSetIgnoreError(TRUE);
|
2021-10-06 05:38:36 +02:00
|
|
|
data->incomingPlayerList = AllocZeroed(RFU_CHILD_MAX * sizeof(struct RfuIncomingPlayer));
|
|
|
|
data->playerList = AllocZeroed(MAX_RFU_PLAYER_LIST_SIZE * sizeof(struct RfuPlayer));
|
2018-06-03 22:39:10 +02:00
|
|
|
data->state = 2;
|
|
|
|
break;
|
|
|
|
case 2:
|
2021-10-06 05:38:36 +02:00
|
|
|
ClearIncomingPlayerList(data->incomingPlayerList, RFU_CHILD_MAX);
|
|
|
|
ClearRfuPlayerList(data->playerList->players, MAX_RFU_PLAYER_LIST_SIZE);
|
|
|
|
data->listenTaskId = CreateTask_ListenForCompatiblePartners(data->incomingPlayerList, 0xFF);
|
2020-05-30 10:09:21 +02:00
|
|
|
data->leaderId = 0;
|
2018-06-03 22:39:10 +02:00
|
|
|
data->state = 3;
|
|
|
|
break;
|
|
|
|
case 3:
|
2020-05-30 10:09:21 +02:00
|
|
|
if (GetNewLeaderCandidate() == 1)
|
2018-06-03 22:39:10 +02:00
|
|
|
PlaySE(SE_PC_LOGIN);
|
|
|
|
if (gTasks[taskId].data[15] == 0xFF)
|
|
|
|
data->state = 10;
|
|
|
|
break;
|
|
|
|
case 10:
|
2020-05-30 10:09:21 +02:00
|
|
|
DestroyTask(data->listenTaskId);
|
2021-10-06 05:38:36 +02:00
|
|
|
Free(data->playerList);
|
|
|
|
Free(data->incomingPlayerList);
|
2020-05-30 10:09:21 +02:00
|
|
|
LinkRfu_Shutdown();
|
2018-06-03 22:39:10 +02:00
|
|
|
data->state++;
|
|
|
|
break;
|
|
|
|
case 11:
|
2020-05-30 10:09:21 +02:00
|
|
|
LinkRfu_Shutdown();
|
2018-06-03 22:39:10 +02:00
|
|
|
DestroyTask(taskId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-01 16:23:12 +02:00
|
|
|
static bool32 IsPartnerActivityAcceptable(u32 activity, u32 linkGroup)
|
2018-06-03 22:39:10 +02:00
|
|
|
{
|
2020-06-01 16:23:12 +02:00
|
|
|
if (linkGroup == 0xFF)
|
2018-06-03 22:39:10 +02:00
|
|
|
return TRUE;
|
|
|
|
|
2020-12-13 05:28:01 +01:00
|
|
|
#ifdef UBFIX
|
|
|
|
if (linkGroup < ARRAY_COUNT(sAcceptedActivityIds))
|
|
|
|
#else
|
|
|
|
if (linkGroup <= ARRAY_COUNT(sAcceptedActivityIds))
|
|
|
|
#endif
|
2018-06-03 22:39:10 +02:00
|
|
|
{
|
2020-06-01 16:23:12 +02:00
|
|
|
const u8 *bytes = sAcceptedActivityIds[linkGroup];
|
2018-06-03 22:39:10 +02:00
|
|
|
|
|
|
|
while ((*(bytes) != 0xFF))
|
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
if ((*bytes) == activity)
|
2018-06-03 22:39:10 +02:00
|
|
|
return TRUE;
|
|
|
|
bytes++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static u8 GetGroupListTextColor(struct WirelessLink_Group *data, u32 id)
|
2018-06-03 22:39:10 +02:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (data->playerList->players[id].groupScheduledAnim == UNION_ROOM_SPAWN_IN)
|
2018-06-03 22:39:10 +02:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (data->playerList->players[id].rfu.data.startedActivity)
|
|
|
|
return UR_COLOR_WHITE;
|
|
|
|
else if (data->playerList->players[id].useRedText)
|
|
|
|
return UR_COLOR_RED;
|
2021-10-07 21:32:51 +02:00
|
|
|
else if (data->playerList->players[id].newPlayerCountdown != 0)
|
2021-10-06 05:38:36 +02:00
|
|
|
return UR_COLOR_GREEN;
|
2018-06-03 22:39:10 +02:00
|
|
|
}
|
2021-10-06 05:38:36 +02:00
|
|
|
return UR_COLOR_DEFAULT;
|
2018-06-03 22:39:10 +02:00
|
|
|
}
|
|
|
|
|
2021-06-18 06:15:45 +02:00
|
|
|
static void ListMenuItemPrintFunc_UnionRoomGroups(u8 windowId, u32 id, u8 y)
|
2018-06-03 22:39:10 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
struct WirelessLink_Group *data = sWirelessLinkMain.group;
|
2021-10-06 05:38:36 +02:00
|
|
|
u8 colorId = GetGroupListTextColor(data, id);
|
2018-06-03 22:39:10 +02:00
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
PrintGroupMemberOnWindow(windowId, 8, y, &data->playerList->players[id], colorId, id);
|
2018-06-03 22:39:10 +02:00
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static u8 GetNewLeaderCandidate(void)
|
2018-06-03 22:39:10 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
struct WirelessLink_Group *data = sWirelessLinkMain.group;
|
2018-06-03 22:39:10 +02:00
|
|
|
u8 ret = 0;
|
|
|
|
u8 i;
|
|
|
|
s32 id;
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
for (i = 0; i < MAX_RFU_PLAYER_LIST_SIZE; i++)
|
2018-06-03 22:39:10 +02:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (data->playerList->players[i].groupScheduledAnim != UNION_ROOM_SPAWN_NONE)
|
2018-06-03 22:39:10 +02:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
id = GetNewIncomingPlayerId(&data->playerList->players[i], data->incomingPlayerList->players);
|
2018-06-03 22:39:10 +02:00
|
|
|
if (id != 0xFF)
|
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (data->playerList->players[i].groupScheduledAnim == UNION_ROOM_SPAWN_IN)
|
2018-06-03 22:39:10 +02:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (ArePlayerDataDifferent(&data->playerList->players[i].rfu, &data->incomingPlayerList->players[id].rfu))
|
2018-06-03 22:39:10 +02:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
data->playerList->players[i].rfu = data->incomingPlayerList->players[id].rfu;
|
2021-10-07 21:32:51 +02:00
|
|
|
data->playerList->players[i].newPlayerCountdown = 64;
|
2018-06-03 22:39:10 +02:00
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-07 21:32:51 +02:00
|
|
|
if (data->playerList->players[i].newPlayerCountdown != 0)
|
2018-06-03 22:39:10 +02:00
|
|
|
{
|
2021-10-07 21:32:51 +02:00
|
|
|
data->playerList->players[i].newPlayerCountdown--;
|
|
|
|
if (data->playerList->players[i].newPlayerCountdown == 0)
|
2018-06-03 22:39:10 +02:00
|
|
|
ret = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
data->playerList->players[i].groupScheduledAnim = UNION_ROOM_SPAWN_IN;
|
2021-10-07 21:32:51 +02:00
|
|
|
data->playerList->players[i].newPlayerCountdown = 64;
|
2018-06-03 22:39:10 +02:00
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
data->playerList->players[i].timeoutCounter = 0;
|
2018-06-03 22:39:10 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (data->playerList->players[i].groupScheduledAnim != UNION_ROOM_SPAWN_OUT)
|
2018-06-03 22:39:10 +02:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
data->playerList->players[i].timeoutCounter++;
|
|
|
|
if (data->playerList->players[i].timeoutCounter >= 300)
|
2018-06-03 22:39:10 +02:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
data->playerList->players[i].groupScheduledAnim = UNION_ROOM_SPAWN_OUT;
|
2018-06-03 22:39:10 +02:00
|
|
|
ret = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
for (id = 0; id < RFU_CHILD_MAX; id++)
|
2018-06-03 22:39:10 +02:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (TryAddIncomingPlayerToList(data->playerList->players, &data->incomingPlayerList->players[id], MAX_RFU_PLAYER_LIST_SIZE) != 0xFF)
|
2018-06-03 22:39:10 +02:00
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-06-04 00:00:53 +02:00
|
|
|
static void Task_CreateTradeMenu(u8 taskId)
|
2018-06-03 22:39:10 +02:00
|
|
|
{
|
2019-10-09 11:56:44 +02:00
|
|
|
CB2_StartCreateTradeMenu();
|
2018-06-03 22:39:10 +02:00
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
|
2020-06-04 00:00:53 +02:00
|
|
|
u8 CreateTask_CreateTradeMenu(void)
|
2018-06-03 22:39:10 +02:00
|
|
|
{
|
2020-06-04 00:00:53 +02:00
|
|
|
u8 taskId = CreateTask(Task_CreateTradeMenu, 0);
|
2018-06-03 22:39:10 +02:00
|
|
|
|
|
|
|
return taskId;
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void Task_StartUnionRoomTrade(u8 taskId)
|
2018-06-03 22:39:10 +02:00
|
|
|
{
|
2019-10-05 05:31:25 +02:00
|
|
|
u32 monId = GetPartyPositionOfRegisteredMon(&sUnionRoomTrade, GetMultiplayerId());
|
2018-06-03 22:39:10 +02:00
|
|
|
|
|
|
|
switch (gTasks[taskId].data[0])
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
gTasks[taskId].data[0]++;
|
|
|
|
SendBlock(0, &gPlayerParty[monId], sizeof(struct Pokemon));
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (GetBlockReceivedStatus() == 3)
|
|
|
|
{
|
|
|
|
gEnemyParty[0] = *(struct Pokemon*)(gBlockRecvBuffer[GetMultiplayerId() ^ 1]);
|
2019-04-02 04:30:30 +02:00
|
|
|
IncrementGameStat(GAME_STAT_NUM_UNION_ROOM_BATTLES);
|
2018-06-03 22:39:10 +02:00
|
|
|
ResetBlockReceivedFlags();
|
|
|
|
gTasks[taskId].data[0]++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
memcpy(gBlockSendBuffer, gSaveBlock1Ptr->mail, sizeof(struct MailStruct) * PARTY_SIZE + 4);
|
|
|
|
if (SendBlock(0, gBlockSendBuffer, sizeof(struct MailStruct) * PARTY_SIZE + 4))
|
|
|
|
gTasks[taskId].data[0]++;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (GetBlockReceivedStatus() == 3)
|
|
|
|
{
|
2019-10-04 13:42:45 +02:00
|
|
|
memcpy(gTradeMail, gBlockRecvBuffer[GetMultiplayerId() ^ 1], sizeof(struct MailStruct) * PARTY_SIZE);
|
2018-06-03 22:39:10 +02:00
|
|
|
ResetBlockReceivedFlags();
|
2019-10-04 01:39:37 +02:00
|
|
|
gSelectedTradeMonPositions[TRADE_PLAYER] = monId;
|
|
|
|
gSelectedTradeMonPositions[TRADE_PARTNER] = PARTY_SIZE;
|
2018-06-03 22:39:10 +02:00
|
|
|
gMain.savedCallback = CB2_ReturnToField;
|
2019-10-05 16:41:37 +02:00
|
|
|
SetMainCallback2(CB2_LinkTrade);
|
2019-10-05 05:31:25 +02:00
|
|
|
ResetUnionRoomTrade(&sUnionRoomTrade);
|
2018-06-03 22:39:10 +02:00
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void Task_ExchangeCards(u8 taskId)
|
2018-06-03 22:39:10 +02:00
|
|
|
{
|
|
|
|
switch (gTasks[taskId].data[0])
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
if (GetMultiplayerId() == 0)
|
2021-08-15 22:11:30 +02:00
|
|
|
SendBlockRequest(BLOCK_REQ_SIZE_100);
|
2018-06-03 22:39:10 +02:00
|
|
|
gTasks[taskId].data[0]++;
|
|
|
|
break;
|
|
|
|
case 1:
|
2020-06-08 06:45:06 +02:00
|
|
|
if (GetBlockReceivedStatus() == GetLinkPlayerCountAsBitFlags())
|
2018-06-03 22:39:10 +02:00
|
|
|
{
|
|
|
|
s32 i;
|
|
|
|
u16 *recvBuff;
|
|
|
|
|
|
|
|
for (i = 0; i < GetLinkPlayerCount(); i++)
|
|
|
|
{
|
|
|
|
recvBuff = gBlockRecvBuffer[i];
|
2019-01-20 18:24:35 +01:00
|
|
|
CopyTrainerCardData(&gTrainerCards[i], recvBuff, gLinkPlayers[i].version);
|
2018-06-03 22:39:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (GetLinkPlayerCount() == 2)
|
|
|
|
{
|
|
|
|
recvBuff = gBlockRecvBuffer[GetMultiplayerId() ^ 1];
|
2020-05-30 10:09:21 +02:00
|
|
|
MEventHandleReceivedWonderCard(recvBuff[48]);
|
2018-06-03 22:39:10 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
ResetReceivedWonderCardFlag();
|
2018-06-03 22:39:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ResetBlockReceivedFlags();
|
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void CB2_ShowCard(void)
|
2018-06-03 22:39:10 +02:00
|
|
|
{
|
|
|
|
switch (gMain.state)
|
|
|
|
{
|
|
|
|
case 0:
|
2020-05-30 10:09:21 +02:00
|
|
|
CreateTask(Task_ExchangeCards, 5);
|
2018-06-03 22:39:10 +02:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 1:
|
2020-05-30 10:09:21 +02:00
|
|
|
if (!FuncIsActiveTask(Task_ExchangeCards))
|
2019-01-20 18:24:35 +01:00
|
|
|
ShowTrainerCardInLink(GetMultiplayerId() ^ 1, CB2_ReturnToField);
|
2018-06-03 22:39:10 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
RunTasks();
|
|
|
|
RunTextPrinters();
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
void StartUnionRoomBattle(u16 battleFlags)
|
2018-06-03 22:39:10 +02:00
|
|
|
{
|
|
|
|
HealPlayerParty();
|
|
|
|
SavePlayerParty();
|
|
|
|
LoadPlayerBag();
|
2019-10-11 10:14:09 +02:00
|
|
|
gLinkPlayers[0].linkType = LINKTYPE_BATTLE;
|
2018-06-04 12:07:32 +02:00
|
|
|
gLinkPlayers[GetMultiplayerId()].id = GetMultiplayerId();
|
|
|
|
gLinkPlayers[GetMultiplayerId() ^ 1].id = GetMultiplayerId() ^ 1;
|
2020-05-30 10:09:21 +02:00
|
|
|
gMain.savedCallback = CB2_ReturnFromCableClubBattle;
|
2018-06-03 22:39:10 +02:00
|
|
|
gBattleTypeFlags = battleFlags;
|
|
|
|
PlayBattleBGM();
|
|
|
|
}
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
static void WarpForWirelessMinigame(u16 linkService, u16 x, u16 y)
|
2018-06-03 22:39:10 +02:00
|
|
|
{
|
2019-10-11 10:14:09 +02:00
|
|
|
VarSet(VAR_CABLE_CLUB_STATE, linkService);
|
2018-12-27 23:30:47 +01:00
|
|
|
SetWarpDestination(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1, x, y);
|
|
|
|
SetDynamicWarpWithCoords(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1, x, y);
|
2018-09-05 00:31:37 +02:00
|
|
|
WarpIntoMap();
|
2018-06-03 22:39:10 +02:00
|
|
|
}
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
static void WarpForCableClubActivity(s8 mapGroup, s8 mapNum, s32 x, s32 y, u16 linkService)
|
2018-06-03 22:39:10 +02:00
|
|
|
{
|
2019-10-11 10:14:09 +02:00
|
|
|
gSpecialVar_0x8004 = linkService;
|
|
|
|
VarSet(VAR_CABLE_CLUB_STATE, linkService);
|
2018-06-03 22:39:10 +02:00
|
|
|
gFieldLinkPlayerCount = GetLinkPlayerCount();
|
2019-02-27 04:04:44 +01:00
|
|
|
gLocalLinkPlayerId = GetMultiplayerId();
|
2018-10-17 04:47:08 +02:00
|
|
|
SetCableClubWarp();
|
2018-12-27 23:30:47 +01:00
|
|
|
SetWarpDestination(mapGroup, mapNum, -1, x, y);
|
2018-09-05 00:31:37 +02:00
|
|
|
WarpIntoMap();
|
2018-06-03 22:39:10 +02:00
|
|
|
}
|
2018-06-04 12:07:32 +02:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void CB2_TransitionToCableClub(void)
|
2018-06-04 12:07:32 +02:00
|
|
|
{
|
|
|
|
switch (gMain.state)
|
|
|
|
{
|
|
|
|
case 0:
|
2020-05-30 10:09:21 +02:00
|
|
|
CreateTask(Task_ExchangeCards, 5);
|
2018-06-04 12:07:32 +02:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 1:
|
2020-05-30 10:09:21 +02:00
|
|
|
if (!FuncIsActiveTask(Task_ExchangeCards))
|
2019-12-17 09:24:44 +01:00
|
|
|
SetMainCallback2(CB2_ReturnToFieldCableClub);
|
2018-06-04 12:07:32 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
RunTasks();
|
|
|
|
RunTextPrinters();
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void CreateTrainerCardInBuffer(void *dest, bool32 setWonderCard)
|
2018-06-04 12:07:32 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
u16 *argAsU16Ptr = dest;
|
2018-06-04 12:07:32 +02:00
|
|
|
|
2018-10-13 19:41:10 +02:00
|
|
|
TrainerCard_GenerateCardForPlayer((struct TrainerCard *)argAsU16Ptr);
|
2020-05-30 10:09:21 +02:00
|
|
|
if (setWonderCard)
|
2019-04-01 00:59:52 +02:00
|
|
|
argAsU16Ptr[48] = GetWonderCardFlagID();
|
2018-06-04 12:07:32 +02:00
|
|
|
else
|
|
|
|
argAsU16Ptr[48] = 0;
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void Task_StartActivity(u8 taskId)
|
2018-06-04 12:07:32 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
ResetReceivedWonderCardFlag();
|
|
|
|
switch (gPlayerCurrActivity)
|
2018-06-04 12:07:32 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_BATTLE_SINGLE:
|
|
|
|
case ACTIVITY_BATTLE_DOUBLE:
|
|
|
|
case ACTIVITY_BATTLE_MULTI:
|
|
|
|
case ACTIVITY_TRADE:
|
|
|
|
case ACTIVITY_POKEMON_JUMP:
|
|
|
|
case ACTIVITY_BERRY_CRUSH:
|
|
|
|
case ACTIVITY_BERRY_PICK:
|
|
|
|
case ACTIVITY_SPIN_TRADE:
|
|
|
|
case ACTIVITY_RECORD_CORNER:
|
2019-02-15 09:40:57 +01:00
|
|
|
RecordMixTrainerNames();
|
2018-06-04 12:07:32 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
switch (gPlayerCurrActivity)
|
2018-06-04 12:07:32 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_BATTLE_SINGLE | IN_UNION_ROOM:
|
|
|
|
case ACTIVITY_ACCEPT | IN_UNION_ROOM:
|
2018-12-27 23:30:47 +01:00
|
|
|
CleanupOverworldWindowsAndTilemaps();
|
2020-05-30 10:09:21 +02:00
|
|
|
gMain.savedCallback = CB2_UnionRoomBattle;
|
2019-02-11 02:42:50 +01:00
|
|
|
InitChooseHalfPartyForBattle(3);
|
2018-06-04 12:07:32 +02:00
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_BATTLE_SINGLE:
|
2018-12-27 23:30:47 +01:00
|
|
|
CleanupOverworldWindowsAndTilemaps();
|
2020-05-30 10:09:21 +02:00
|
|
|
CreateTrainerCardInBuffer(gBlockSendBuffer, TRUE);
|
2018-06-04 12:07:32 +02:00
|
|
|
HealPlayerParty();
|
|
|
|
SavePlayerParty();
|
|
|
|
LoadPlayerBag();
|
2020-06-09 00:16:57 +02:00
|
|
|
WarpForCableClubActivity(MAP_GROUP(BATTLE_COLOSSEUM_2P), MAP_NUM(BATTLE_COLOSSEUM_2P), 6, 8, USING_SINGLE_BATTLE);
|
2020-05-30 10:09:21 +02:00
|
|
|
SetMainCallback2(CB2_TransitionToCableClub);
|
2018-06-04 12:07:32 +02:00
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_BATTLE_DOUBLE:
|
2018-12-27 23:30:47 +01:00
|
|
|
CleanupOverworldWindowsAndTilemaps();
|
2018-06-04 12:07:32 +02:00
|
|
|
HealPlayerParty();
|
|
|
|
SavePlayerParty();
|
|
|
|
LoadPlayerBag();
|
2020-05-30 10:09:21 +02:00
|
|
|
CreateTrainerCardInBuffer(gBlockSendBuffer, TRUE);
|
2020-06-09 00:16:57 +02:00
|
|
|
WarpForCableClubActivity(MAP_GROUP(BATTLE_COLOSSEUM_2P), MAP_NUM(BATTLE_COLOSSEUM_2P), 6, 8, USING_DOUBLE_BATTLE);
|
2020-05-30 10:09:21 +02:00
|
|
|
SetMainCallback2(CB2_TransitionToCableClub);
|
2018-06-04 12:07:32 +02:00
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_BATTLE_MULTI:
|
2018-12-27 23:30:47 +01:00
|
|
|
CleanupOverworldWindowsAndTilemaps();
|
2018-06-04 12:07:32 +02:00
|
|
|
HealPlayerParty();
|
|
|
|
SavePlayerParty();
|
|
|
|
LoadPlayerBag();
|
2020-05-30 10:09:21 +02:00
|
|
|
CreateTrainerCardInBuffer(gBlockSendBuffer, TRUE);
|
2020-06-09 00:16:57 +02:00
|
|
|
WarpForCableClubActivity(MAP_GROUP(BATTLE_COLOSSEUM_4P), MAP_NUM(BATTLE_COLOSSEUM_4P), 5, 8, USING_MULTI_BATTLE);
|
2020-05-30 10:09:21 +02:00
|
|
|
SetMainCallback2(CB2_TransitionToCableClub);
|
2018-06-04 12:07:32 +02:00
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_TRADE:
|
|
|
|
CreateTrainerCardInBuffer(gBlockSendBuffer, TRUE);
|
2018-12-27 23:30:47 +01:00
|
|
|
CleanupOverworldWindowsAndTilemaps();
|
2020-06-09 00:16:57 +02:00
|
|
|
WarpForCableClubActivity(MAP_GROUP(TRADE_CENTER), MAP_NUM(TRADE_CENTER), 5, 8, USING_TRADE_CENTER);
|
2020-05-30 10:09:21 +02:00
|
|
|
SetMainCallback2(CB2_TransitionToCableClub);
|
2018-06-04 12:07:32 +02:00
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_RECORD_CORNER:
|
|
|
|
CreateTrainerCardInBuffer(gBlockSendBuffer, TRUE);
|
2018-12-27 23:30:47 +01:00
|
|
|
CleanupOverworldWindowsAndTilemaps();
|
2020-06-09 00:16:57 +02:00
|
|
|
WarpForCableClubActivity(MAP_GROUP(RECORD_CORNER), MAP_NUM(RECORD_CORNER), 8, 9, USING_RECORD_CORNER);
|
2020-05-30 10:09:21 +02:00
|
|
|
SetMainCallback2(CB2_TransitionToCableClub);
|
2018-06-04 12:07:32 +02:00
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_TRADE | IN_UNION_ROOM:
|
2018-12-27 23:30:47 +01:00
|
|
|
CleanupOverworldWindowsAndTilemaps();
|
2020-05-30 10:09:21 +02:00
|
|
|
CreateTask(Task_StartUnionRoomTrade, 0);
|
2018-06-04 12:07:32 +02:00
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_CHAT:
|
|
|
|
case ACTIVITY_CHAT | IN_UNION_ROOM:
|
2018-06-04 12:07:32 +02:00
|
|
|
if (GetMultiplayerId() == 0)
|
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
LinkRfu_CreateConnectionAsParent();
|
2018-06-04 12:07:32 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
LinkRfu_StopManagerBeforeEnteringChat();
|
2021-10-06 05:38:36 +02:00
|
|
|
SetHostRfuGameData(ACTIVITY_CHAT | IN_UNION_ROOM, 0, TRUE);
|
2018-06-04 12:07:32 +02:00
|
|
|
}
|
2020-05-30 10:09:21 +02:00
|
|
|
EnterUnionRoomChat();
|
2018-06-04 12:07:32 +02:00
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_CARD:
|
|
|
|
case ACTIVITY_CARD | IN_UNION_ROOM:
|
|
|
|
CreateTrainerCardInBuffer(gBlockSendBuffer, FALSE);
|
|
|
|
SetMainCallback2(CB2_ShowCard);
|
2018-06-04 12:07:32 +02:00
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_POKEMON_JUMP:
|
2020-06-09 00:16:57 +02:00
|
|
|
WarpForWirelessMinigame(USING_MINIGAME, 5, 1);
|
2020-05-30 10:09:21 +02:00
|
|
|
StartPokemonJump(GetCursorSelectionMonId(), CB2_LoadMap);
|
2018-06-04 12:07:32 +02:00
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_BERRY_CRUSH:
|
2020-06-09 00:16:57 +02:00
|
|
|
WarpForWirelessMinigame(USING_BERRY_CRUSH, 9, 1);
|
2020-05-30 10:09:21 +02:00
|
|
|
StartBerryCrush(CB2_LoadMap);
|
2018-06-04 12:07:32 +02:00
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_BERRY_PICK:
|
2020-06-09 00:16:57 +02:00
|
|
|
WarpForWirelessMinigame(USING_MINIGAME, 5, 1);
|
2020-05-30 10:09:21 +02:00
|
|
|
StartDodrioBerryPicking(GetCursorSelectionMonId(), CB2_LoadMap);
|
2018-06-04 12:07:32 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
DestroyTask(taskId);
|
2020-06-09 00:16:57 +02:00
|
|
|
gSpecialVar_Result = LINKUP_SUCCESS;
|
2020-05-30 10:09:21 +02:00
|
|
|
if (gPlayerCurrActivity != (ACTIVITY_TRADE | IN_UNION_ROOM))
|
2018-06-04 12:07:32 +02:00
|
|
|
ScriptContext2_Disable();
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void Task_RunScriptAndFadeToActivity(u8 taskId)
|
2018-06-04 12:07:32 +02:00
|
|
|
{
|
|
|
|
s16 *data = gTasks[taskId].data;
|
|
|
|
u16 *sendBuff = (u16*)(gBlockSendBuffer);
|
|
|
|
|
|
|
|
switch (data[0])
|
|
|
|
{
|
|
|
|
case 0:
|
2020-06-04 00:00:53 +02:00
|
|
|
gSpecialVar_Result = LINKUP_SUCCESS;
|
2020-05-30 10:09:21 +02:00
|
|
|
switch (gPlayerCurrActivity)
|
2018-06-04 12:07:32 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_BATTLE_TOWER:
|
|
|
|
case ACTIVITY_BATTLE_TOWER_OPEN:
|
2019-10-11 10:14:09 +02:00
|
|
|
gLinkPlayers[0].linkType = LINKTYPE_BATTLE;
|
2018-06-04 12:07:32 +02:00
|
|
|
gLinkPlayers[0].id = 0;
|
|
|
|
gLinkPlayers[1].id = 2;
|
2018-11-25 22:50:54 +01:00
|
|
|
sendBuff[0] = GetMonData(&gPlayerParty[gSelectedOrderFromParty[0] - 1], MON_DATA_SPECIES);
|
|
|
|
sendBuff[1] = GetMonData(&gPlayerParty[gSelectedOrderFromParty[1] - 1], MON_DATA_SPECIES, NULL);
|
2018-06-04 12:07:32 +02:00
|
|
|
gMain.savedCallback = NULL;
|
|
|
|
data[0] = 4;
|
2019-02-15 09:40:57 +01:00
|
|
|
RecordMixTrainerNames();
|
2018-06-04 12:07:32 +02:00
|
|
|
ResetBlockReceivedFlags();
|
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_BERRY_BLENDER:
|
|
|
|
case ACTIVITY_CONTEST_COOL:
|
|
|
|
case ACTIVITY_CONTEST_BEAUTY:
|
|
|
|
case ACTIVITY_CONTEST_CUTE:
|
|
|
|
case ACTIVITY_CONTEST_SMART:
|
|
|
|
case ACTIVITY_CONTEST_TOUGH:
|
2019-02-15 09:40:57 +01:00
|
|
|
RecordMixTrainerNames();
|
2018-06-04 12:07:32 +02:00
|
|
|
DestroyTask(taskId);
|
|
|
|
default:
|
|
|
|
EnableBothScriptContexts();
|
|
|
|
data[0] = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (!ScriptContext1_IsScriptSetUp())
|
|
|
|
{
|
2019-12-15 17:42:50 +01:00
|
|
|
FadeScreen(FADE_TO_BLACK, 0);
|
2018-06-04 12:07:32 +02:00
|
|
|
data[0] = 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
if (gPlayerCurrActivity == ACTIVITY_29)
|
2018-06-04 12:07:32 +02:00
|
|
|
{
|
|
|
|
DestroyTask(taskId);
|
2019-10-09 11:56:44 +02:00
|
|
|
SetMainCallback2(CB2_StartCreateTradeMenu);
|
2018-06-04 12:07:32 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-13 09:09:47 +02:00
|
|
|
SetLinkStandbyCallback();
|
2018-06-04 12:07:32 +02:00
|
|
|
data[0] = 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
2018-12-31 09:22:21 +01:00
|
|
|
if (IsLinkTaskFinished())
|
2018-06-04 12:07:32 +02:00
|
|
|
{
|
|
|
|
DestroyTask(taskId);
|
2020-05-30 10:09:21 +02:00
|
|
|
CreateTask_StartActivity();
|
2018-06-04 12:07:32 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
if (SendBlock(0, gBlockSendBuffer, 0xE))
|
|
|
|
data[0] = 5;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
if (GetBlockReceivedStatus() == 3)
|
|
|
|
{
|
|
|
|
ResetBlockReceivedFlags();
|
2020-06-04 00:00:53 +02:00
|
|
|
if (AreBattleTowerLinkSpeciesSame(gBlockRecvBuffer[0], gBlockRecvBuffer[1]))
|
2018-06-04 12:07:32 +02:00
|
|
|
{
|
2020-06-04 00:00:53 +02:00
|
|
|
gSpecialVar_Result = LINKUP_FAILED_BATTLE_TOWER;
|
2018-06-04 12:07:32 +02:00
|
|
|
data[0] = 7;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data[0] = 6;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
EnableBothScriptContexts();
|
|
|
|
DestroyTask(taskId);
|
|
|
|
break;
|
|
|
|
case 7:
|
2020-08-13 09:09:47 +02:00
|
|
|
SetCloseLinkCallback();
|
2018-06-04 12:07:32 +02:00
|
|
|
data[0] = 8;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
if (gReceivedRemoteLinkPlayers == 0)
|
|
|
|
{
|
2019-04-01 00:59:52 +02:00
|
|
|
DestroyWirelessStatusIndicatorSprite();
|
2018-06-04 12:07:32 +02:00
|
|
|
EnableBothScriptContexts();
|
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void CreateTask_RunScriptAndFadeToActivity(void)
|
2018-06-04 12:07:32 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
CreateTask(Task_RunScriptAndFadeToActivity, 0);
|
2018-06-04 12:07:32 +02:00
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void CreateTask_StartActivity(void)
|
2018-06-04 12:07:32 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
u8 taskId = CreateTask(Task_StartActivity, 0);
|
2018-06-04 12:07:32 +02:00
|
|
|
gTasks[taskId].data[0] = 0;
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
void MEvent_CreateTask_Leader(u32 activity)
|
2018-06-04 12:07:32 +02:00
|
|
|
{
|
|
|
|
u8 taskId;
|
2020-05-30 10:09:21 +02:00
|
|
|
struct WirelessLink_Leader *data;
|
2018-06-04 12:07:32 +02:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
taskId = CreateTask(Task_MEvent_Leader, 0);
|
|
|
|
sWirelessLinkMain.leader = data = (void*)(gTasks[taskId].data);
|
2018-06-04 12:07:32 +02:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
data->state = 0;
|
|
|
|
data->textState = 0;
|
|
|
|
data->activity = activity;
|
2020-06-09 00:16:57 +02:00
|
|
|
gSpecialVar_Result = LINKUP_ONGOING;
|
2018-06-04 12:07:32 +02:00
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void Task_MEvent_Leader(u8 taskId)
|
2018-06-04 12:07:32 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
struct WirelessLink_Leader *data = sWirelessLinkMain.leader;
|
2018-06-04 12:07:32 +02:00
|
|
|
struct WindowTemplate winTemplate;
|
|
|
|
s32 val;
|
|
|
|
|
|
|
|
switch (data->state)
|
|
|
|
{
|
|
|
|
case 0:
|
2020-05-30 10:09:21 +02:00
|
|
|
gPlayerCurrActivity = data->activity;
|
|
|
|
sPlayerActivityGroupSize = 2;
|
2021-10-06 05:38:36 +02:00
|
|
|
SetHostRfuGameData(data->activity, 0, FALSE);
|
|
|
|
SetHostRfuWonderFlags(FALSE, FALSE);
|
2020-05-30 10:09:21 +02:00
|
|
|
SetWirelessCommType1();
|
2018-06-04 12:07:32 +02:00
|
|
|
OpenLink();
|
2020-05-30 10:09:21 +02:00
|
|
|
InitializeRfuLinkManager_LinkLeader(2);
|
2018-06-04 12:07:32 +02:00
|
|
|
data->state = 1;
|
|
|
|
break;
|
|
|
|
case 1:
|
2021-10-06 05:38:36 +02:00
|
|
|
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;
|
2021-10-07 21:32:51 +02:00
|
|
|
data->playerList->players[0].newPlayerCountdown = 0;
|
2021-10-06 05:38:36 +02:00
|
|
|
data->listenTaskId = CreateTask_ListenForCompatiblePartners(data->incomingPlayerList, 0xFF);
|
2018-06-04 12:07:32 +02:00
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
winTemplate = sWindowTemplate_PlayerList;
|
2019-04-01 00:59:52 +02:00
|
|
|
winTemplate.baseBlock = GetMysteryGiftBaseBlock();
|
2021-10-06 05:38:36 +02:00
|
|
|
winTemplate.paletteNum = 12;
|
2018-06-04 12:07:32 +02:00
|
|
|
data->listWindowId = AddWindow(&winTemplate);
|
2019-04-01 00:59:52 +02:00
|
|
|
MG_DrawTextBorder(data->listWindowId);
|
2020-05-30 10:09:21 +02:00
|
|
|
gMultiuseListMenuTemplate = sListMenuTemplate_PossibleGroupMembers;
|
2018-06-04 12:07:32 +02:00
|
|
|
gMultiuseListMenuTemplate.windowId = data->listWindowId;
|
|
|
|
data->listTaskId = ListMenuInit(&gMultiuseListMenuTemplate, 0, 0);
|
|
|
|
|
|
|
|
CopyBgTilemapBufferToVram(0);
|
2020-05-30 10:09:21 +02:00
|
|
|
data->playerCount = 1;
|
2018-06-04 12:07:32 +02:00
|
|
|
data->state = 2;
|
|
|
|
break;
|
|
|
|
case 2:
|
2020-06-09 00:16:57 +02:00
|
|
|
StringCopy(gStringVar1, sLinkGroupActivityNameTexts[gPlayerCurrActivity]);
|
2021-10-06 05:38:36 +02:00
|
|
|
GetAwaitingCommunicationText(gStringVar4, gPlayerCurrActivity);
|
2018-06-04 12:07:32 +02:00
|
|
|
data->state = 3;
|
|
|
|
break;
|
|
|
|
case 3:
|
2019-04-01 00:59:52 +02:00
|
|
|
AddTextPrinterToWindow1(gStringVar4);
|
2018-06-04 12:07:32 +02:00
|
|
|
data->state = 4;
|
|
|
|
break;
|
|
|
|
case 4:
|
2020-05-30 10:09:21 +02:00
|
|
|
Leader_SetStateIfMemberListChanged(data, 5, 6);
|
2020-09-05 03:11:55 +02:00
|
|
|
if (JOY_NEW(B_BUTTON))
|
2018-06-04 12:07:32 +02:00
|
|
|
{
|
|
|
|
data->state = 13;
|
2019-04-01 00:59:52 +02:00
|
|
|
DestroyWirelessStatusIndicatorSprite();
|
2018-06-04 12:07:32 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 6:
|
2019-12-10 19:48:20 +01:00
|
|
|
if (MG_PrintTextOnWindow1AndWaitButton(&data->textState, sText_LinkWithFriendDropped))
|
2018-06-04 12:07:32 +02:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
data->playerCount = LeaderPrunePlayerList(data->playerList);
|
2018-07-22 13:14:58 +02:00
|
|
|
RedrawListMenu(data->listTaskId);
|
2018-06-04 12:07:32 +02:00
|
|
|
data->state = 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
data->state = 7;
|
|
|
|
break;
|
|
|
|
case 7:
|
2021-10-06 05:38:36 +02:00
|
|
|
switch (mevent_message_print_and_prompt_yes_no(&data->textState, &data->yesNoWindowId, 0, gStringVar4))
|
2018-06-04 12:07:32 +02:00
|
|
|
{
|
|
|
|
case 0:
|
2019-04-04 23:05:46 +02:00
|
|
|
LoadWirelessStatusIndicatorSpriteGfx();
|
2018-06-04 12:07:32 +02:00
|
|
|
CreateWirelessStatusIndicatorSprite(0, 0);
|
2021-10-07 21:32:51 +02:00
|
|
|
data->playerList->players[data->playerCount].newPlayerCountdown = 0;
|
2018-07-22 13:14:58 +02:00
|
|
|
RedrawListMenu(data->listTaskId);
|
2020-06-09 00:16:57 +02:00
|
|
|
data->joinRequestAnswer = RFU_STATUS_JOIN_GROUP_OK;
|
2021-10-06 05:38:36 +02:00
|
|
|
SendRfuStatusToPartner(data->joinRequestAnswer, ReadAsU16(data->playerList->players[data->playerCount].rfu.data.compatibility.playerTrainerId), data->playerList->players[data->playerCount].rfu.name);
|
2018-06-04 12:07:32 +02:00
|
|
|
data->state = 8;
|
|
|
|
break;
|
|
|
|
case 1:
|
2021-10-06 05:38:36 +02:00
|
|
|
case MENU_B_PRESSED:
|
2020-06-09 00:16:57 +02:00
|
|
|
data->joinRequestAnswer = RFU_STATUS_JOIN_GROUP_NO;
|
2021-10-06 05:38:36 +02:00
|
|
|
SendRfuStatusToPartner(data->joinRequestAnswer, ReadAsU16(data->playerList->players[data->playerCount].rfu.data.compatibility.playerTrainerId), data->playerList->players[data->playerCount].rfu.name);
|
2018-06-04 12:07:32 +02:00
|
|
|
data->state = 8;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 8:
|
2021-10-06 05:38:36 +02:00
|
|
|
val = WaitSendRfuStatusToPartner(ReadAsU16(data->playerList->players[data->playerCount].rfu.data.compatibility.playerTrainerId), data->playerList->players[data->playerCount].rfu.name);
|
2020-06-09 00:16:57 +02:00
|
|
|
if (val == 1) // Send complete
|
2018-06-04 12:07:32 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
if (data->joinRequestAnswer == RFU_STATUS_JOIN_GROUP_OK)
|
2018-06-04 12:07:32 +02:00
|
|
|
{
|
2021-10-07 21:32:51 +02:00
|
|
|
data->playerList->players[data->playerCount].newPlayerCountdown = 0;
|
2018-07-22 13:14:58 +02:00
|
|
|
RedrawListMenu(data->listTaskId);
|
2020-05-30 10:09:21 +02:00
|
|
|
data->playerCount++;
|
2021-10-06 05:38:36 +02:00
|
|
|
CopyAndTranslatePlayerName(gStringVar1, &data->playerList->players[data->playerCount - 1]);
|
2019-12-10 19:48:20 +01:00
|
|
|
StringExpandPlaceholders(gStringVar4, sText_AnOKWasSentToPlayer);
|
2018-06-04 12:07:32 +02:00
|
|
|
data->state = 9;
|
2020-05-30 10:09:21 +02:00
|
|
|
LinkRfu_StopManagerAndFinalizeSlots();
|
2018-06-04 12:07:32 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
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);
|
2018-07-22 13:14:58 +02:00
|
|
|
RedrawListMenu(data->listTaskId);
|
2018-06-04 12:07:32 +02:00
|
|
|
data->state = 2;
|
|
|
|
}
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
data->joinRequestAnswer = 0;
|
2018-06-04 12:07:32 +02:00
|
|
|
}
|
2020-06-09 00:16:57 +02:00
|
|
|
else if (val == 2) // Member disconnected
|
2018-06-04 12:07:32 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(RFU_STATUS_OK, 0);
|
2018-06-04 12:07:32 +02:00
|
|
|
data->state = 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 9:
|
2019-04-01 00:59:52 +02:00
|
|
|
AddTextPrinterToWindow1(gStringVar4);
|
2018-06-04 12:07:32 +02:00
|
|
|
data->state = 10;
|
|
|
|
break;
|
|
|
|
case 10:
|
2020-05-30 10:09:21 +02:00
|
|
|
if (++data->delayTimerAfterOk > 120)
|
2018-06-04 12:07:32 +02:00
|
|
|
data->state = 11;
|
|
|
|
break;
|
|
|
|
case 11:
|
2020-05-30 10:09:21 +02:00
|
|
|
if (!Leader_SetStateIfMemberListChanged(data, 5, 6))
|
2018-06-04 12:07:32 +02:00
|
|
|
data->state = 12;
|
|
|
|
break;
|
|
|
|
case 12:
|
2020-05-30 10:09:21 +02:00
|
|
|
if (LmanAcceptSlotFlagIsNotZero())
|
2018-06-04 12:07:32 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
WaitRfuState(FALSE);
|
2018-06-04 12:07:32 +02:00
|
|
|
data->state = 15;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data->state = 6;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 13:
|
2019-04-01 00:59:52 +02:00
|
|
|
DestroyWirelessStatusIndicatorSprite();
|
2020-05-30 10:09:21 +02:00
|
|
|
LinkRfu_Shutdown();
|
2018-06-04 12:07:32 +02:00
|
|
|
DestroyListMenuTask(data->listTaskId, 0, 0);
|
|
|
|
CopyBgTilemapBufferToVram(0);
|
|
|
|
RemoveWindow(data->listWindowId);
|
2020-05-30 10:09:21 +02:00
|
|
|
DestroyTask(data->listenTaskId);
|
2021-10-06 05:38:36 +02:00
|
|
|
Free(data->playerListBackup);
|
|
|
|
Free(data->playerList);
|
|
|
|
Free(data->incomingPlayerList);
|
2018-06-04 12:07:32 +02:00
|
|
|
data->state++;
|
|
|
|
break;
|
|
|
|
case 14:
|
2019-12-10 19:48:20 +01:00
|
|
|
if (MG_PrintTextOnWindow1AndWaitButton(&data->textState, sText_PleaseStartOver))
|
2018-06-04 12:07:32 +02:00
|
|
|
{
|
|
|
|
DestroyTask(taskId);
|
2020-06-09 00:16:57 +02:00
|
|
|
gSpecialVar_Result = LINKUP_FAILED;
|
2018-06-04 12:07:32 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 15:
|
2020-06-09 00:16:57 +02:00
|
|
|
if (RfuGetStatus() == RFU_STATUS_FATAL_ERROR || RfuGetStatus() == RFU_STATUS_CONNECTION_ERROR)
|
2018-06-04 12:07:32 +02:00
|
|
|
{
|
|
|
|
data->state = 13;
|
|
|
|
}
|
|
|
|
else if (gReceivedRemoteLinkPlayers != 0)
|
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
UpdateGameData_GroupLockedIn(TRUE);
|
2018-06-04 12:07:32 +02:00
|
|
|
data->state++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
DestroyListMenuTask(data->listTaskId, 0, 0);
|
|
|
|
CopyBgTilemapBufferToVram(0);
|
|
|
|
RemoveWindow(data->listWindowId);
|
2020-05-30 10:09:21 +02:00
|
|
|
DestroyTask(data->listenTaskId);
|
2021-10-06 05:38:36 +02:00
|
|
|
Free(data->playerListBackup);
|
|
|
|
Free(data->playerList);
|
|
|
|
Free(data->incomingPlayerList);
|
2020-08-13 09:09:47 +02:00
|
|
|
SetLinkStandbyCallback();
|
2018-06-04 12:07:32 +02:00
|
|
|
data->state++;
|
|
|
|
break;
|
|
|
|
case 17:
|
2018-12-31 09:22:21 +01:00
|
|
|
if (IsLinkTaskFinished())
|
2018-06-04 12:07:32 +02:00
|
|
|
DestroyTask(taskId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
void MEvent_CreateTask_CardOrNewsWithFriend(u32 activity)
|
2018-06-04 12:07:32 +02:00
|
|
|
{
|
|
|
|
u8 taskId;
|
2020-05-30 10:09:21 +02:00
|
|
|
struct WirelessLink_Group *data;
|
2018-06-04 12:07:32 +02:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
taskId = CreateTask(Task_CardOrNewsWithFriend, 0);
|
|
|
|
sWirelessLinkMain.group = data = (void*)(gTasks[taskId].data);
|
|
|
|
sGroup = data;
|
2018-06-04 12:07:32 +02:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
data->state = 0;
|
|
|
|
data->textState = 0;
|
2021-10-06 05:38:36 +02:00
|
|
|
data->isWonderNews = activity - ACTIVITY_WONDER_CARD;
|
2020-06-09 00:16:57 +02:00
|
|
|
gSpecialVar_Result = LINKUP_ONGOING;
|
2018-06-04 12:07:32 +02:00
|
|
|
}
|
2018-06-04 23:32:28 +02:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void Task_CardOrNewsWithFriend(u8 taskId)
|
2018-06-04 23:32:28 +02:00
|
|
|
{
|
|
|
|
s32 id;
|
2021-10-06 05:38:36 +02:00
|
|
|
struct WindowTemplate listWinTemplate, playerNameWinTemplate;
|
2020-05-30 10:09:21 +02:00
|
|
|
struct WirelessLink_Group *data = sWirelessLinkMain.group;
|
2018-06-04 23:32:28 +02:00
|
|
|
|
|
|
|
switch (data->state)
|
|
|
|
{
|
|
|
|
case 0:
|
2021-10-06 05:38:36 +02:00
|
|
|
SetHostRfuGameData(data->isWonderNews + ACTIVITY_WONDER_CARD, 0, FALSE);
|
2020-05-30 10:09:21 +02:00
|
|
|
SetWirelessCommType1();
|
2018-06-04 23:32:28 +02:00
|
|
|
OpenLink();
|
2020-05-30 10:09:21 +02:00
|
|
|
InitializeRfuLinkManager_JoinGroup();
|
2021-10-06 05:38:36 +02:00
|
|
|
data->incomingPlayerList = AllocZeroed(RFU_CHILD_MAX * sizeof(struct RfuIncomingPlayer));
|
|
|
|
data->playerList = AllocZeroed(MAX_RFU_PLAYER_LIST_SIZE * sizeof(struct RfuPlayer));
|
2018-06-04 23:32:28 +02:00
|
|
|
data->state = 1;
|
|
|
|
break;
|
|
|
|
case 1:
|
2019-11-11 03:54:00 +01:00
|
|
|
AddTextPrinterToWindow1(sText_ChooseTrainer);
|
2018-06-04 23:32:28 +02:00
|
|
|
data->state = 2;
|
|
|
|
break;
|
|
|
|
case 2:
|
2021-10-06 05:38:36 +02:00
|
|
|
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);
|
2018-06-04 23:32:28 +02:00
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
listWinTemplate = sWindowTemplate_GroupList;
|
|
|
|
listWinTemplate.baseBlock = GetMysteryGiftBaseBlock();
|
|
|
|
listWinTemplate.paletteNum = 12;
|
|
|
|
data->listWindowId = AddWindow(&listWinTemplate);
|
2018-06-04 23:32:28 +02:00
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
playerNameWinTemplate = sWindowTemplate_PlayerNameAndId;
|
|
|
|
playerNameWinTemplate.paletteNum = 12;
|
|
|
|
data->playerNameAndIdWindowId = AddWindow(&playerNameWinTemplate);
|
2018-06-04 23:32:28 +02:00
|
|
|
|
2019-04-01 00:59:52 +02:00
|
|
|
MG_DrawTextBorder(data->listWindowId);
|
2020-05-30 10:09:21 +02:00
|
|
|
gMultiuseListMenuTemplate = sListMenuTemplate_UnionRoomGroups;
|
2018-06-04 23:32:28 +02:00
|
|
|
gMultiuseListMenuTemplate.windowId = data->listWindowId;
|
|
|
|
data->listTaskId = ListMenuInit(&gMultiuseListMenuTemplate, 0, 0);
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
MG_DrawTextBorder(data->playerNameAndIdWindowId);
|
|
|
|
FillWindowPixelBuffer(data->playerNameAndIdWindowId, PIXEL_FILL(1));
|
|
|
|
PutWindowTilemap(data->playerNameAndIdWindowId);
|
|
|
|
PrintPlayerNameAndIdOnWindow(data->playerNameAndIdWindowId);
|
|
|
|
CopyWindowToVram(data->playerNameAndIdWindowId, 2);
|
2018-06-04 23:32:28 +02:00
|
|
|
|
|
|
|
CopyBgTilemapBufferToVram(0);
|
2020-05-30 10:09:21 +02:00
|
|
|
data->leaderId = 0;
|
2018-06-04 23:32:28 +02:00
|
|
|
data->state = 3;
|
|
|
|
break;
|
|
|
|
case 3:
|
2020-05-30 10:09:21 +02:00
|
|
|
id = GetNewLeaderCandidate();
|
2018-06-04 23:32:28 +02:00
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
PlaySE(SE_PC_LOGIN);
|
|
|
|
default:
|
2018-07-22 13:14:58 +02:00
|
|
|
RedrawListMenu(data->listTaskId);
|
2018-06-04 23:32:28 +02:00
|
|
|
break;
|
|
|
|
case 0:
|
2019-02-02 11:04:38 +01:00
|
|
|
id = ListMenu_ProcessInput(data->listTaskId);
|
2020-09-05 03:11:55 +02:00
|
|
|
if (JOY_NEW(A_BUTTON) && id != -1)
|
2018-06-04 23:32:28 +02:00
|
|
|
{
|
|
|
|
// this unused variable along with the assignment is needed to match
|
|
|
|
u32 unusedVar;
|
2021-10-06 05:38:36 +02:00
|
|
|
unusedVar = data->playerList->players[id].rfu.data.activity;
|
2018-06-04 23:32:28 +02:00
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
if (data->playerList->players[id].groupScheduledAnim == UNION_ROOM_SPAWN_IN && !data->playerList->players[id].rfu.data.startedActivity)
|
2018-06-04 23:32:28 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
data->leaderId = id;
|
2019-04-04 23:05:46 +02:00
|
|
|
LoadWirelessStatusIndicatorSpriteGfx();
|
2018-06-04 23:32:28 +02:00
|
|
|
CreateWirelessStatusIndicatorSprite(0, 0);
|
2018-07-22 13:14:58 +02:00
|
|
|
RedrawListMenu(data->listTaskId);
|
2021-10-06 05:38:36 +02:00
|
|
|
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));
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_POKENAV_ON);
|
2018-06-04 23:32:28 +02:00
|
|
|
data->state = 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PlaySE(SE_WALL_HIT);
|
|
|
|
}
|
|
|
|
}
|
2020-09-05 03:11:55 +02:00
|
|
|
else if (JOY_NEW(B_BUTTON))
|
2018-06-04 23:32:28 +02:00
|
|
|
{
|
|
|
|
data->state = 6;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
2019-12-10 19:48:20 +01:00
|
|
|
AddTextPrinterToWindow1(sText_AwaitingPlayersResponse);
|
2021-10-06 05:38:36 +02:00
|
|
|
CopyAndTranslatePlayerName(gStringVar1, &data->playerList->players[data->leaderId]);
|
2018-06-04 23:32:28 +02:00
|
|
|
data->state = 5;
|
|
|
|
break;
|
|
|
|
case 5:
|
2020-05-30 10:09:21 +02:00
|
|
|
if (gReceivedRemoteLinkPlayers)
|
2018-06-04 23:32:28 +02:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
gPlayerCurrActivity = data->playerList->players[data->leaderId].rfu.data.activity;
|
2018-06-04 23:32:28 +02:00
|
|
|
data->state = 10;
|
|
|
|
}
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
switch (RfuGetStatus())
|
2018-06-04 23:32:28 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
case RFU_STATUS_FATAL_ERROR:
|
|
|
|
case RFU_STATUS_CONNECTION_ERROR:
|
|
|
|
case RFU_STATUS_JOIN_GROUP_NO:
|
2018-06-04 23:32:28 +02:00
|
|
|
data->state = 8;
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case RFU_STATUS_JOIN_GROUP_OK:
|
2019-12-10 19:48:20 +01:00
|
|
|
AddTextPrinterToWindow1(sText_PlayerSentBackOK);
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(RFU_STATUS_OK, 0);
|
2018-06-04 23:32:28 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
case 8:
|
|
|
|
case 10:
|
|
|
|
DestroyListMenuTask(data->listTaskId, 0, 0);
|
|
|
|
CopyBgTilemapBufferToVram(0);
|
2020-05-30 10:09:21 +02:00
|
|
|
RemoveWindow(data->playerNameAndIdWindowId);
|
2018-06-04 23:32:28 +02:00
|
|
|
RemoveWindow(data->listWindowId);
|
2020-05-30 10:09:21 +02:00
|
|
|
DestroyTask(data->listenTaskId);
|
2021-10-06 05:38:36 +02:00
|
|
|
Free(data->playerList);
|
|
|
|
Free(data->incomingPlayerList);
|
2018-06-04 23:32:28 +02:00
|
|
|
data->state++;
|
|
|
|
break;
|
|
|
|
case 9:
|
2020-06-09 00:16:57 +02:00
|
|
|
if (MG_PrintTextOnWindow1AndWaitButton(&data->textState, sLinkDroppedTexts[RfuGetStatus()]))
|
2018-06-04 23:32:28 +02:00
|
|
|
{
|
2019-04-01 00:59:52 +02:00
|
|
|
DestroyWirelessStatusIndicatorSprite();
|
2018-06-04 23:32:28 +02:00
|
|
|
DestroyTask(taskId);
|
2020-05-30 10:09:21 +02:00
|
|
|
LinkRfu_Shutdown();
|
2020-06-09 00:16:57 +02:00
|
|
|
gSpecialVar_Result = LINKUP_FAILED;
|
2018-06-04 23:32:28 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 7:
|
2019-04-01 00:59:52 +02:00
|
|
|
DestroyWirelessStatusIndicatorSprite();
|
2019-12-10 19:48:20 +01:00
|
|
|
AddTextPrinterToWindow1(sText_PleaseStartOver);
|
2018-06-04 23:32:28 +02:00
|
|
|
DestroyTask(taskId);
|
2020-05-30 10:09:21 +02:00
|
|
|
LinkRfu_Shutdown();
|
2020-06-09 00:16:57 +02:00
|
|
|
gSpecialVar_Result = LINKUP_FAILED;
|
2018-06-04 23:32:28 +02:00
|
|
|
break;
|
|
|
|
case 11:
|
|
|
|
data->state++;
|
2020-08-13 09:09:47 +02:00
|
|
|
SetLinkStandbyCallback();
|
2018-06-04 23:32:28 +02:00
|
|
|
break;
|
|
|
|
case 12:
|
2018-12-31 09:22:21 +01:00
|
|
|
if (IsLinkTaskFinished())
|
2018-06-04 23:32:28 +02:00
|
|
|
DestroyTask(taskId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
void MEvent_CreateTask_CardOrNewsOverWireless(u32 activity)
|
2018-06-04 23:32:28 +02:00
|
|
|
{
|
|
|
|
u8 taskId;
|
2020-05-30 10:09:21 +02:00
|
|
|
struct WirelessLink_Group *data;
|
2018-06-04 23:32:28 +02:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
taskId = CreateTask(Task_CardOrNewsOverWireless, 0);
|
|
|
|
sWirelessLinkMain.group = data = (void*)(gTasks[taskId].data);
|
|
|
|
sGroup = data;
|
2018-06-04 23:32:28 +02:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
data->state = 0;
|
|
|
|
data->textState = 0;
|
2021-10-06 05:38:36 +02:00
|
|
|
data->isWonderNews = activity - ACTIVITY_WONDER_CARD;
|
2020-06-09 00:16:57 +02:00
|
|
|
gSpecialVar_Result = LINKUP_ONGOING;
|
2018-06-04 23:32:28 +02:00
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void Task_CardOrNewsOverWireless(u8 taskId)
|
2018-06-04 23:32:28 +02:00
|
|
|
{
|
|
|
|
s32 id;
|
|
|
|
struct WindowTemplate winTemplate;
|
2020-05-30 10:09:21 +02:00
|
|
|
struct WirelessLink_Group *data = sWirelessLinkMain.group;
|
2018-06-04 23:32:28 +02:00
|
|
|
|
|
|
|
switch (data->state)
|
|
|
|
{
|
|
|
|
case 0:
|
2021-10-06 05:38:36 +02:00
|
|
|
SetHostRfuGameData(ACTIVITY_NONE, 0, FALSE);
|
2020-05-30 10:09:21 +02:00
|
|
|
SetWirelessCommType1();
|
2018-06-04 23:32:28 +02:00
|
|
|
OpenLink();
|
2020-05-30 10:09:21 +02:00
|
|
|
InitializeRfuLinkManager_JoinGroup();
|
2021-10-06 05:38:36 +02:00
|
|
|
data->incomingPlayerList = AllocZeroed(RFU_CHILD_MAX * sizeof(struct RfuIncomingPlayer));
|
|
|
|
data->playerList = AllocZeroed(MAX_RFU_PLAYER_LIST_SIZE * sizeof(struct RfuPlayer));
|
2018-06-04 23:32:28 +02:00
|
|
|
data->state = 1;
|
|
|
|
break;
|
|
|
|
case 1:
|
2019-12-10 19:48:20 +01:00
|
|
|
AddTextPrinterToWindow1(sText_SearchingForWirelessSystemWait);
|
2018-06-04 23:32:28 +02:00
|
|
|
data->state = 2;
|
|
|
|
break;
|
|
|
|
case 2:
|
2021-10-06 05:38:36 +02:00
|
|
|
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);
|
2018-06-04 23:32:28 +02:00
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
if (data->showListMenu)
|
2018-06-04 23:32:28 +02:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
winTemplate = sWindowTemplate_GroupList;
|
2019-04-01 00:59:52 +02:00
|
|
|
winTemplate.baseBlock = GetMysteryGiftBaseBlock();
|
2018-06-04 23:32:28 +02:00
|
|
|
data->listWindowId = AddWindow(&winTemplate);
|
|
|
|
|
2019-04-01 00:59:52 +02:00
|
|
|
MG_DrawTextBorder(data->listWindowId);
|
2020-05-30 10:09:21 +02:00
|
|
|
gMultiuseListMenuTemplate = sListMenuTemplate_UnionRoomGroups;
|
2018-06-04 23:32:28 +02:00
|
|
|
gMultiuseListMenuTemplate.windowId = data->listWindowId;
|
|
|
|
data->listTaskId = ListMenuInit(&gMultiuseListMenuTemplate, 0, 0);
|
|
|
|
|
|
|
|
CopyBgTilemapBufferToVram(0);
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
data->leaderId = 0;
|
2018-06-04 23:32:28 +02:00
|
|
|
data->state = 3;
|
|
|
|
break;
|
|
|
|
case 3:
|
2020-05-30 10:09:21 +02:00
|
|
|
id = GetNewLeaderCandidate();
|
2018-06-04 23:32:28 +02:00
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
PlaySE(SE_PC_LOGIN);
|
|
|
|
default:
|
2021-10-06 05:38:36 +02:00
|
|
|
if (data->showListMenu)
|
2018-07-22 13:14:58 +02:00
|
|
|
RedrawListMenu(data->listTaskId);
|
2018-06-04 23:32:28 +02:00
|
|
|
break;
|
|
|
|
case 0:
|
2021-10-06 05:38:36 +02:00
|
|
|
if (data->showListMenu)
|
2019-02-02 11:04:38 +01:00
|
|
|
id = ListMenu_ProcessInput(data->listTaskId);
|
2020-05-30 10:09:21 +02:00
|
|
|
if (data->refreshTimer > 120)
|
2018-06-04 23:32:28 +02:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (data->playerList->players[0].groupScheduledAnim == UNION_ROOM_SPAWN_IN && !data->playerList->players[0].rfu.data.startedActivity)
|
2018-06-04 23:32:28 +02:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (HasWonderCardOrNewsByLinkGroup(&data->playerList->players[0].rfu.data, data->isWonderNews + LINK_GROUP_WONDER_CARD))
|
2018-06-04 23:32:28 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
data->leaderId = 0;
|
|
|
|
data->refreshTimer = 0;
|
2019-04-04 23:05:46 +02:00
|
|
|
LoadWirelessStatusIndicatorSpriteGfx();
|
2018-06-04 23:32:28 +02:00
|
|
|
CreateWirelessStatusIndicatorSprite(0, 0);
|
2021-10-06 05:38:36 +02:00
|
|
|
CreateTask_RfuReconnectWithParent(data->playerList->players[0].rfu.name, ReadAsU16(data->playerList->players[0].rfu.data.compatibility.playerTrainerId));
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_POKENAV_ON);
|
2018-06-04 23:32:28 +02:00
|
|
|
data->state = 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PlaySE(SE_BOO);
|
|
|
|
data->state = 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-05 03:11:55 +02:00
|
|
|
else if (JOY_NEW(B_BUTTON))
|
2018-06-04 23:32:28 +02:00
|
|
|
{
|
|
|
|
data->state = 6;
|
2020-05-30 10:09:21 +02:00
|
|
|
data->refreshTimer = 0;
|
2018-06-04 23:32:28 +02:00
|
|
|
}
|
2020-05-30 10:09:21 +02:00
|
|
|
data->refreshTimer++;
|
2018-06-04 23:32:28 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
2019-12-10 19:48:20 +01:00
|
|
|
AddTextPrinterToWindow1(sText_AwaitingResponseFromWirelessSystem);
|
2021-10-06 05:38:36 +02:00
|
|
|
CopyAndTranslatePlayerName(gStringVar1, &data->playerList->players[data->leaderId]);
|
2018-06-04 23:32:28 +02:00
|
|
|
data->state = 5;
|
|
|
|
break;
|
|
|
|
case 5:
|
2020-05-30 10:09:21 +02:00
|
|
|
if (gReceivedRemoteLinkPlayers)
|
2018-06-04 23:32:28 +02:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
gPlayerCurrActivity = data->playerList->players[data->leaderId].rfu.data.activity;
|
2018-06-04 23:32:28 +02:00
|
|
|
data->state = 12;
|
|
|
|
}
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
switch (RfuGetStatus())
|
2018-06-04 23:32:28 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
case RFU_STATUS_FATAL_ERROR:
|
|
|
|
case RFU_STATUS_CONNECTION_ERROR:
|
|
|
|
case RFU_STATUS_JOIN_GROUP_NO:
|
2018-06-04 23:32:28 +02:00
|
|
|
data->state = 8;
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case RFU_STATUS_JOIN_GROUP_OK:
|
2019-12-10 19:48:20 +01:00
|
|
|
AddTextPrinterToWindow1(sText_WirelessLinkEstablished);
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(RFU_STATUS_OK, 0);
|
2018-06-04 23:32:28 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
case 8:
|
|
|
|
case 10:
|
|
|
|
case 12:
|
2021-10-06 05:38:36 +02:00
|
|
|
if (data->showListMenu)
|
2018-06-04 23:32:28 +02:00
|
|
|
{
|
|
|
|
DestroyListMenuTask(data->listTaskId, 0, 0);
|
|
|
|
CopyBgTilemapBufferToVram(0);
|
|
|
|
RemoveWindow(data->listWindowId);
|
|
|
|
}
|
2020-05-30 10:09:21 +02:00
|
|
|
DestroyTask(data->listenTaskId);
|
2021-10-06 05:38:36 +02:00
|
|
|
Free(data->playerList);
|
|
|
|
Free(data->incomingPlayerList);
|
2018-06-04 23:32:28 +02:00
|
|
|
data->state++;
|
|
|
|
break;
|
|
|
|
case 9:
|
2019-12-10 19:48:20 +01:00
|
|
|
if (MG_PrintTextOnWindow1AndWaitButton(&data->textState, sText_WirelessLinkDropped))
|
2018-06-04 23:32:28 +02:00
|
|
|
{
|
2019-04-01 00:59:52 +02:00
|
|
|
DestroyWirelessStatusIndicatorSprite();
|
2018-06-04 23:32:28 +02:00
|
|
|
DestroyTask(taskId);
|
2020-05-30 10:09:21 +02:00
|
|
|
LinkRfu_Shutdown();
|
2020-06-09 00:16:57 +02:00
|
|
|
gSpecialVar_Result = LINKUP_FAILED;
|
2018-06-04 23:32:28 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 7:
|
2019-12-10 19:48:20 +01:00
|
|
|
if (MG_PrintTextOnWindow1AndWaitButton(&data->textState, sText_WirelessSearchCanceled))
|
2018-06-04 23:32:28 +02:00
|
|
|
{
|
2019-04-01 00:59:52 +02:00
|
|
|
DestroyWirelessStatusIndicatorSprite();
|
2018-06-04 23:32:28 +02:00
|
|
|
DestroyTask(taskId);
|
2020-05-30 10:09:21 +02:00
|
|
|
LinkRfu_Shutdown();
|
2020-06-09 00:16:57 +02:00
|
|
|
gSpecialVar_Result = LINKUP_FAILED;
|
2018-06-04 23:32:28 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 11:
|
2020-05-30 10:09:21 +02:00
|
|
|
if (MG_PrintTextOnWindow1AndWaitButton(&data->textState, sNoWonderSharedTexts[data->isWonderNews]))
|
2018-06-04 23:32:28 +02:00
|
|
|
{
|
2019-04-01 00:59:52 +02:00
|
|
|
DestroyWirelessStatusIndicatorSprite();
|
2018-06-04 23:32:28 +02:00
|
|
|
DestroyTask(taskId);
|
2020-05-30 10:09:21 +02:00
|
|
|
LinkRfu_Shutdown();
|
2020-06-09 00:16:57 +02:00
|
|
|
gSpecialVar_Result = LINKUP_FAILED;
|
2018-06-04 23:32:28 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 13:
|
|
|
|
data->state++;
|
2020-08-13 09:09:47 +02:00
|
|
|
SetLinkStandbyCallback();
|
2018-06-04 23:32:28 +02:00
|
|
|
break;
|
|
|
|
case 14:
|
2018-12-31 09:22:21 +01:00
|
|
|
if (IsLinkTaskFinished())
|
2018-06-04 23:32:28 +02:00
|
|
|
DestroyTask(taskId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
void RunUnionRoom(void)
|
2018-06-04 23:32:28 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
struct WirelessLink_URoom *uroom;
|
2018-06-04 23:32:28 +02:00
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
ResetHostRfuGameData();
|
2020-05-30 10:09:21 +02:00
|
|
|
CreateTask(Task_RunUnionRoom, 10);
|
2018-06-04 23:32:28 +02:00
|
|
|
|
|
|
|
// dumb line needed to match
|
2020-05-30 10:09:21 +02:00
|
|
|
sWirelessLinkMain.uRoom = sWirelessLinkMain.uRoom;
|
2018-06-04 23:32:28 +02:00
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom = AllocZeroed(sizeof(*sWirelessLinkMain.uRoom));
|
|
|
|
sWirelessLinkMain.uRoom = uroom;
|
|
|
|
sURoom = uroom;
|
2018-06-04 23:32:28 +02:00
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_INIT;
|
|
|
|
uroom->textState = 0;
|
|
|
|
uroom->unknown = 0;
|
2021-10-07 21:32:51 +02:00
|
|
|
uroom->unreadPlayerId = 0;
|
2018-06-04 23:32:28 +02:00
|
|
|
|
|
|
|
gSpecialVar_Result = 0;
|
2020-05-30 10:09:21 +02:00
|
|
|
ListMenuLoadStdPalAt(0xD0, 1);
|
2018-06-04 23:32:28 +02:00
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static u16 ReadAsU16(const u8 *ptr)
|
2018-06-04 23:32:28 +02:00
|
|
|
{
|
|
|
|
return (ptr[1] << 8) | (ptr[0]);
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void ScheduleFieldMessageWithFollowupState(u32 nextState, const u8 *src)
|
2018-06-04 23:32:28 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
struct WirelessLink_URoom *uroom = sWirelessLinkMain.uRoom;
|
2018-06-04 23:32:28 +02:00
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_PRINT_MSG;
|
|
|
|
uroom->stateAfterPrint = nextState;
|
2018-06-04 23:32:28 +02:00
|
|
|
if (src != gStringVar4)
|
|
|
|
StringExpandPlaceholders(gStringVar4, src);
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void ScheduleFieldMessageAndExit(const u8 *src)
|
2018-06-04 23:32:28 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
struct WirelessLink_URoom *uroom = sWirelessLinkMain.uRoom;
|
2018-06-04 23:32:28 +02:00
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_PRINT_AND_EXIT;
|
2018-06-04 23:32:28 +02:00
|
|
|
if (src != gStringVar4)
|
|
|
|
StringExpandPlaceholders(gStringVar4, src);
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static void CopyPlayerListToBuffer(struct WirelessLink_URoom *uroom)
|
2018-06-04 23:32:28 +02:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
memcpy(&gDecompressionBuffer[sizeof(gDecompressionBuffer) - (MAX_UNION_ROOM_LEADERS * sizeof(struct RfuPlayer))],
|
|
|
|
uroom->playerList,
|
|
|
|
MAX_UNION_ROOM_LEADERS * sizeof(struct RfuPlayer));
|
2018-06-04 23:32:28 +02:00
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static void CopyPlayerListFromBuffer(struct WirelessLink_URoom *uroom)
|
2018-06-04 23:32:28 +02:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
memcpy(uroom->playerList,
|
|
|
|
&gDecompressionBuffer[sizeof(gDecompressionBuffer) - (MAX_UNION_ROOM_LEADERS * sizeof(struct RfuPlayer))],
|
|
|
|
MAX_UNION_ROOM_LEADERS * sizeof(struct RfuPlayer));
|
2018-06-04 23:32:28 +02:00
|
|
|
}
|
2018-06-09 22:14:52 +02:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void Task_RunUnionRoom(u8 taskId)
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2018-06-10 18:28:37 +02:00
|
|
|
u32 id = 0;
|
2020-06-09 00:16:57 +02:00
|
|
|
s32 input = 0;
|
2020-05-30 10:09:21 +02:00
|
|
|
s32 playerGender = MALE;
|
2020-06-09 00:16:57 +02:00
|
|
|
struct WirelessLink_URoom *uroom = sWirelessLinkMain.uRoom;
|
2018-06-09 22:14:52 +02:00
|
|
|
s16 *taskData = gTasks[taskId].data;
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
switch (uroom->state)
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_INIT:
|
2021-10-06 05:38:36 +02:00
|
|
|
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);
|
2020-05-30 10:09:21 +02:00
|
|
|
gPlayerCurrActivity = IN_UNION_ROOM;
|
2021-10-06 05:38:36 +02:00
|
|
|
uroom->searchTaskId = CreateTask_SearchForChildOrParent(uroom->incomingParentList, uroom->incomingChildList, LINK_GROUP_UNION_ROOM_RESUME);
|
2020-06-09 00:16:57 +02:00
|
|
|
InitUnionRoomPlayerObjects(uroom->objects);
|
2020-06-01 16:23:12 +02:00
|
|
|
SetTilesAroundUnionRoomPlayersPassable();
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_INIT_OBJECTS;
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_INIT_OBJECTS:
|
2021-10-06 05:38:36 +02:00
|
|
|
CreateUnionRoomPlayerSprites(uroom->spriteIds, taskData[0]);
|
2018-06-10 18:28:37 +02:00
|
|
|
if (++taskData[0] == 8)
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_INIT_LINK;
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_INIT_LINK:
|
2021-10-06 05:38:36 +02:00
|
|
|
SetHostRfuGameData(IN_UNION_ROOM, 0, FALSE);
|
2020-06-06 22:46:19 +02:00
|
|
|
SetTradeBoardRegisteredMonInfo(sUnionRoomTrade.type, sUnionRoomTrade.playerSpecies, sUnionRoomTrade.playerLevel);
|
2020-05-30 10:09:21 +02:00
|
|
|
SetWirelessCommType1();
|
2018-06-09 22:14:52 +02:00
|
|
|
OpenLink();
|
2020-05-30 10:09:21 +02:00
|
|
|
InitializeRfuLinkManager_EnterUnionRoom();
|
2021-10-06 05:38:36 +02:00
|
|
|
ClearRfuPlayerList(&uroom->spawnPlayer->players[0], 1);
|
|
|
|
ClearIncomingPlayerList(uroom->incomingChildList, RFU_CHILD_MAX);
|
|
|
|
ClearIncomingPlayerList(uroom->incomingParentList, RFU_CHILD_MAX);
|
2018-06-09 22:14:52 +02:00
|
|
|
gSpecialVar_Result = 0;
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_CHECK_SELECTING_MON;
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_CHECK_SELECTING_MON:
|
2021-08-25 00:59:32 +02:00
|
|
|
if ((GetPartyMenuType() == PARTY_MENU_TYPE_UNION_ROOM_REGISTER
|
|
|
|
|| GetPartyMenuType() == PARTY_MENU_TYPE_UNION_ROOM_TRADE)
|
2020-06-09 00:16:57 +02:00
|
|
|
&& sUnionRoomTrade.state != URTRADE_STATE_NONE)
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2018-06-10 18:28:37 +02:00
|
|
|
id = GetCursorSelectionMonId();
|
2020-06-09 00:16:57 +02:00
|
|
|
switch (sUnionRoomTrade.state)
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
case URTRADE_STATE_REGISTERING:
|
|
|
|
UpdateGameData_SetActivity(ACTIVITY_PLYRTALK | IN_UNION_ROOM, 0, TRUE);
|
2018-06-10 18:28:37 +02:00
|
|
|
if (id >= PARTY_SIZE)
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2019-10-05 05:31:25 +02:00
|
|
|
ResetUnionRoomTrade(&sUnionRoomTrade);
|
2020-06-06 22:46:19 +02:00
|
|
|
SetTradeBoardRegisteredMonInfo(TYPE_NORMAL, SPECIES_NONE, 0);
|
2020-05-30 10:09:21 +02:00
|
|
|
ScheduleFieldMessageAndExit(sText_RegistrationCanceled);
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
2019-10-05 05:31:25 +02:00
|
|
|
else if (!RegisterTradeMonAndGetIsEgg(GetCursorSelectionMonId(), &sUnionRoomTrade))
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
ScheduleFieldMessageWithFollowupState(UR_STATE_REGISTER_REQUEST_TYPE, sText_ChooseRequestedMonType);
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_REGISTER_COMPLETE;
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case URTRADE_STATE_OFFERING:
|
2021-10-06 05:38:36 +02:00
|
|
|
CopyPlayerListFromBuffer(uroom);
|
2020-06-09 00:16:57 +02:00
|
|
|
taskData[1] = sUnionRoomTrade.offerPlayerId;
|
2018-06-10 18:28:37 +02:00
|
|
|
if (id >= PARTY_SIZE)
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
ScheduleFieldMessageAndExit(sText_TradeCanceled);
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
UpdateGameData_SetActivity(ACTIVITY_PLYRTALK | IN_UNION_ROOM, 0, TRUE);
|
2020-05-30 10:09:21 +02:00
|
|
|
gPlayerCurrActivity = ACTIVITY_TRADE | IN_UNION_ROOM;
|
2019-10-05 05:31:25 +02:00
|
|
|
RegisterTradeMon(GetCursorSelectionMonId(), &sUnionRoomTrade);
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_TRADE_OFFER_MON;
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2020-06-09 00:16:57 +02:00
|
|
|
sUnionRoomTrade.state = URTRADE_STATE_NONE;
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_MAIN;
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_MAIN:
|
2018-06-09 22:14:52 +02:00
|
|
|
if (gSpecialVar_Result != 0)
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
if (gSpecialVar_Result == UR_INTERACT_ATTENDANT)
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
UpdateGameData_SetActivity(ACTIVITY_PLYRTALK | IN_UNION_ROOM, 0, TRUE);
|
2018-06-09 22:14:52 +02:00
|
|
|
PlaySE(SE_PC_LOGIN);
|
|
|
|
StringCopy(gStringVar1, gSaveBlock2Ptr->playerName);
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_INTERACT_WITH_ATTENDANT;
|
2018-06-09 22:14:52 +02:00
|
|
|
gSpecialVar_Result = 0;
|
|
|
|
}
|
2020-06-09 00:16:57 +02:00
|
|
|
else if (gSpecialVar_Result == UR_INTERACT_START_MENU)
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
UpdateGameData_SetActivity(ACTIVITY_PLYRTALK | IN_UNION_ROOM, 0, TRUE);
|
|
|
|
uroom->state = UR_STATE_WAIT_FOR_START_MENU;
|
2018-06-09 22:14:52 +02:00
|
|
|
gSpecialVar_Result = 0;
|
|
|
|
}
|
2020-06-09 00:16:57 +02:00
|
|
|
else // UR_INTERACT_PLAYER_# (1-8)
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
|
|
|
taskData[0] = 0;
|
|
|
|
taskData[1] = gSpecialVar_Result - 1;
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_INTERACT_WITH_PLAYER;
|
2018-06-09 22:14:52 +02:00
|
|
|
gSpecialVar_Result = 0;
|
|
|
|
}
|
|
|
|
}
|
2018-06-10 18:28:37 +02:00
|
|
|
else if (ScriptContext2_IsEnabled() != TRUE)
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-09-05 03:11:55 +02:00
|
|
|
if (JOY_NEW(A_BUTTON))
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (TryInteractWithUnionRoomMember(uroom->playerList, &taskData[0], &taskData[1], uroom->spriteIds))
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
|
|
|
PlaySE(SE_SELECT);
|
2021-10-06 05:38:36 +02:00
|
|
|
StartScriptInteraction();
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_INTERACT_WITH_PLAYER;
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
|
|
|
}
|
2020-06-09 00:16:57 +02:00
|
|
|
else if (IsPlayerFacingTradingBoard())
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
UpdateGameData_SetActivity(ACTIVITY_PLYRTALK | IN_UNION_ROOM, 0, TRUE);
|
2018-06-09 22:14:52 +02:00
|
|
|
PlaySE(SE_PC_LOGIN);
|
2021-10-06 05:38:36 +02:00
|
|
|
StartScriptInteraction();
|
2018-06-09 22:14:52 +02:00
|
|
|
StringCopy(gStringVar1, gSaveBlock2Ptr->playerName);
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_CHECK_TRADING_BOARD;
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
switch (HandlePlayerListUpdate())
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2021-10-07 21:32:51 +02:00
|
|
|
case PLIST_NEW_PLAYER:
|
2018-06-09 22:14:52 +02:00
|
|
|
PlaySE(SE_PC_LOGIN);
|
2021-10-07 21:32:51 +02:00
|
|
|
case PLIST_RECENT_UPDATE:
|
2020-06-09 00:16:57 +02:00
|
|
|
ScheduleUnionRoomPlayerRefresh(uroom);
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
2021-10-07 21:32:51 +02:00
|
|
|
case PLIST_CONTACTED:
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_PLAYER_CONTACTED_YOU;
|
2021-10-06 05:38:36 +02:00
|
|
|
StartScriptInteraction();
|
2020-06-06 22:46:19 +02:00
|
|
|
SetTradeBoardRegisteredMonInfo(TYPE_NORMAL, SPECIES_NONE, 0);
|
2021-10-06 05:38:36 +02:00
|
|
|
UpdateGameData_SetActivity(ACTIVITY_NPCTALK | IN_UNION_ROOM, GetActivePartnersInfo(uroom), FALSE);
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
|
|
|
}
|
2020-06-09 00:16:57 +02:00
|
|
|
HandleUnionRoomPlayerRefresh(uroom);
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_WAIT_FOR_START_MENU:
|
2019-12-11 09:28:55 +01:00
|
|
|
if (!FuncIsActiveTask(Task_ShowStartMenu))
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
UpdateGameData_SetActivity(ACTIVITY_NONE | IN_UNION_ROOM, 0, FALSE);
|
|
|
|
uroom->state = UR_STATE_MAIN;
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_INTERACT_WITH_PLAYER:
|
2021-10-06 05:38:36 +02:00
|
|
|
UR_RunTextPrinters();
|
|
|
|
playerGender = GetUnionRoomPlayerGender(taskData[1], uroom->playerList);
|
2020-06-09 00:16:57 +02:00
|
|
|
UpdateGameData_SetActivity(ACTIVITY_PLYRTALK | IN_UNION_ROOM, 0, TRUE);
|
2021-10-06 05:38:36 +02:00
|
|
|
switch (UnionRoomGetPlayerInteractionResponse(uroom->playerList, taskData[0], taskData[1], playerGender))
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
case 0: // Player is or was just doing an activity
|
|
|
|
uroom->state = UR_STATE_PRINT_AND_EXIT;
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case 1: // Link communicating
|
2021-10-06 05:38:36 +02:00
|
|
|
TryConnectToUnionRoomParent(uroom->playerList->players[taskData[1]].rfu.name, &uroom->playerList->players[taskData[1]].rfu.data, gPlayerCurrActivity);
|
2021-10-07 21:32:51 +02:00
|
|
|
uroom->unreadPlayerId = id; // Should be just 0, but won't match any other way.
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_TRY_COMMUNICATING;
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case 2: // Ask to join chat
|
|
|
|
ScheduleFieldMessageWithFollowupState(UR_STATE_RECV_JOIN_CHAT_REQUEST, gStringVar4);
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_TRY_COMMUNICATING:
|
2021-10-06 05:38:36 +02:00
|
|
|
UR_RunTextPrinters();
|
2020-06-09 00:16:57 +02:00
|
|
|
switch (RfuGetStatus())
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
case RFU_STATUS_NEW_CHILD_DETECTED:
|
|
|
|
HandleCancelActivity(TRUE);
|
|
|
|
uroom->state = UR_STATE_MAIN;
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case RFU_STATUS_FATAL_ERROR:
|
|
|
|
case RFU_STATUS_CONNECTION_ERROR:
|
2020-05-30 10:09:21 +02:00
|
|
|
if (IsUnionRoomListenTaskActive() == TRUE)
|
|
|
|
ScheduleFieldMessageAndExit(sText_TrainerAppearsBusy);
|
2018-06-09 22:14:52 +02:00
|
|
|
else
|
2020-06-09 00:16:57 +02:00
|
|
|
ScheduleFieldMessageWithFollowupState(UR_STATE_CANCEL_ACTIVITY_LINK_ERROR, sText_TrainerAppearsBusy);
|
2018-06-09 22:14:52 +02:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
gPlayerCurrActivity = IN_UNION_ROOM;
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
if (gReceivedRemoteLinkPlayers)
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
CreateTrainerCardInBuffer(gBlockSendBuffer, TRUE);
|
|
|
|
CreateTask(Task_ExchangeCards, 5);
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_COMMUNICATING_WAIT_FOR_DATA;
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_COMMUNICATING_WAIT_FOR_DATA:
|
2020-05-30 10:09:21 +02:00
|
|
|
if (!FuncIsActiveTask(Task_ExchangeCards))
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
if (gPlayerCurrActivity == (ACTIVITY_TRADE | IN_UNION_ROOM))
|
2020-06-09 00:16:57 +02:00
|
|
|
ScheduleFieldMessageWithFollowupState(UR_STATE_SEND_TRADE_REQUST, sText_AwaitingPlayersResponseAboutTrade);
|
2018-06-09 22:14:52 +02:00
|
|
|
else
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_DO_SOMETHING_PROMPT;
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_CANCEL_ACTIVITY_LINK_ERROR:
|
2020-05-30 10:09:21 +02:00
|
|
|
if (!gReceivedRemoteLinkPlayers)
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
HandleCancelActivity(FALSE);
|
2021-10-06 05:38:36 +02:00
|
|
|
UpdateUnionRoomMemberFacing(taskData[0], taskData[1], uroom->playerList);
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_INIT_LINK;
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_DO_SOMETHING_PROMPT:
|
2021-10-06 05:38:36 +02:00
|
|
|
id = ConvPartnerUnameAndGetWhetherMetAlready(&uroom->playerList->players[taskData[1]]);
|
|
|
|
playerGender = GetUnionRoomPlayerGender(taskData[1], uroom->playerList);
|
2020-06-09 00:16:57 +02:00
|
|
|
ScheduleFieldMessageWithFollowupState(UR_STATE_HANDLE_DO_SOMETHING_PROMPT_INPUT, sHiDoSomethingTexts[id][playerGender]);
|
2018-12-02 11:58:50 +01:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_HANDLE_DO_SOMETHING_PROMPT_INPUT:
|
2021-08-25 00:59:32 +02:00
|
|
|
input = ListMenuHandler_AllItemsAvailable(&uroom->textState,
|
|
|
|
&uroom->topListMenuWindowId,
|
|
|
|
&uroom->topListMenuId,
|
|
|
|
&sWindowTemplate_InviteToActivity,
|
2020-06-09 00:16:57 +02:00
|
|
|
&sListMenuTemplate_InviteToActivity);
|
|
|
|
if (input != -1)
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
if (!gReceivedRemoteLinkPlayers)
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_TRAINER_APPEARS_BUSY;
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->partnerYesNoResponse = 0;
|
2021-10-06 05:38:36 +02:00
|
|
|
playerGender = GetUnionRoomPlayerGender(taskData[1], uroom->playerList);
|
2020-06-09 00:16:57 +02:00
|
|
|
if (input == -2 || input == IN_UNION_ROOM)
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->playerSendBuffer[0] = IN_UNION_ROOM;
|
2020-08-24 20:52:33 +02:00
|
|
|
Rfu_SendPacket(uroom->playerSendBuffer);
|
2019-12-10 19:48:20 +01:00
|
|
|
StringCopy(gStringVar4, sIfYouWantToDoSomethingTexts[gLinkPlayers[0].gender]);
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_REQUEST_DECLINED;
|
2018-12-02 11:58:50 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
gPlayerCurrActivity = input;
|
2021-10-06 05:38:36 +02:00
|
|
|
sPlayerActivityGroupSize = (u32)input >> 8; // Extract capacity from sInviteToActivityMenuItems
|
2020-05-30 10:09:21 +02:00
|
|
|
if (gPlayerCurrActivity == (ACTIVITY_BATTLE_SINGLE | IN_UNION_ROOM) && !HasAtLeastTwoMonsOfLevel30OrLower())
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
ScheduleFieldMessageWithFollowupState(UR_STATE_DO_SOMETHING_PROMPT, sText_NeedTwoMonsOfLevel30OrLower1);
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->playerSendBuffer[0] = gPlayerCurrActivity | IN_UNION_ROOM;
|
2020-08-24 20:52:33 +02:00
|
|
|
Rfu_SendPacket(uroom->playerSendBuffer);
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_SEND_ACTIVITY_REQUEST;
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_TRAINER_APPEARS_BUSY:
|
2019-10-05 05:31:25 +02:00
|
|
|
StringCopy(gStringVar4, sText_TrainerBattleBusy);
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_CANCEL_REQUEST_PRINT_MSG;
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_SEND_ACTIVITY_REQUEST:
|
|
|
|
PollPartnerYesNoResponse(uroom);
|
2021-10-06 05:38:36 +02:00
|
|
|
playerGender = GetUnionRoomPlayerGender(taskData[1], uroom->playerList);
|
2020-06-09 00:16:57 +02:00
|
|
|
id = GetResponseIdx_InviteToURoomActivity(uroom->playerSendBuffer[0] & 0x3F);
|
|
|
|
if (PrintOnTextbox(&uroom->textState, sText_WaitOrShowCardTexts[playerGender][id]))
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
|
|
|
taskData[3] = 0;
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_WAIT_FOR_RESPONSE_TO_REQUEST;
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_REQUEST_DECLINED:
|
2020-08-13 09:09:47 +02:00
|
|
|
SetCloseLinkCallback();
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_CANCEL_REQUEST_PRINT_MSG;
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_SEND_TRADE_REQUST:
|
|
|
|
uroom->playerSendBuffer[0] = ACTIVITY_TRADE | IN_UNION_ROOM;
|
|
|
|
uroom->playerSendBuffer[1] = sUnionRoomTrade.species;
|
|
|
|
uroom->playerSendBuffer[2] = sUnionRoomTrade.level;
|
2020-08-24 20:52:33 +02:00
|
|
|
Rfu_SendPacket(uroom->playerSendBuffer);
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_WAIT_FOR_RESPONSE_TO_REQUEST;
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_WAIT_FOR_RESPONSE_TO_REQUEST:
|
2020-05-30 10:09:21 +02:00
|
|
|
if (!gReceivedRemoteLinkPlayers)
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
StringCopy(gStringVar4, sText_TrainerBattleBusy); // Redundant, will be copied again in next state
|
|
|
|
uroom->state = UR_STATE_TRAINER_APPEARS_BUSY;
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
PollPartnerYesNoResponse(uroom);
|
|
|
|
if (uroom->partnerYesNoResponse == (ACTIVITY_ACCEPT | IN_UNION_ROOM))
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
if (gPlayerCurrActivity == ACTIVITY_CARD)
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
ViewURoomPartnerTrainerCard(gStringVar4, uroom, FALSE);
|
|
|
|
uroom->state = UR_STATE_PRINT_CARD_INFO;
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_PRINT_START_ACTIVITY_MSG;
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
}
|
2020-06-09 00:16:57 +02:00
|
|
|
else if (uroom->partnerYesNoResponse == (ACTIVITY_DECLINE | IN_UNION_ROOM))
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_REQUEST_DECLINED;
|
2020-05-30 10:09:21 +02:00
|
|
|
GetURoomActivityRejectMsg(gStringVar4, gPlayerCurrActivity | IN_UNION_ROOM, gLinkPlayers[0].gender);
|
|
|
|
gPlayerCurrActivity = ACTIVITY_NONE;
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2018-12-02 11:58:50 +01:00
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_DO_SOMETHING_PROMPT_2: // Identical to UR_STATE_DO_SOMETHING_PROMPT
|
2021-10-06 05:38:36 +02:00
|
|
|
id = ConvPartnerUnameAndGetWhetherMetAlready(&uroom->playerList->players[taskData[1]]);
|
|
|
|
playerGender = GetUnionRoomPlayerGender(taskData[1], uroom->playerList);
|
2020-06-09 00:16:57 +02:00
|
|
|
ScheduleFieldMessageWithFollowupState(UR_STATE_HANDLE_DO_SOMETHING_PROMPT_INPUT, sHiDoSomethingTexts[id][playerGender]);
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_PRINT_CARD_INFO:
|
|
|
|
if (PrintOnTextbox(&uroom->textState, gStringVar4))
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_WAIT_FINISH_READING_CARD;
|
2020-08-13 09:09:47 +02:00
|
|
|
SetLinkStandbyCallback();
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->partnerYesNoResponse = 0;
|
|
|
|
uroom->recvActivityRequest[0] = 0;
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_WAIT_FINISH_READING_CARD:
|
2018-12-31 09:22:21 +01:00
|
|
|
if (IsLinkTaskFinished())
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
|
|
|
if (GetMultiplayerId() == 0)
|
|
|
|
{
|
|
|
|
StringCopy(gStringVar1, gLinkPlayers[GetMultiplayerId() ^ 1].name);
|
2020-05-30 10:09:21 +02:00
|
|
|
id = PlayerHasMetTrainerBefore(gLinkPlayers[1].trainerId, gLinkPlayers[1].name);
|
2019-12-10 19:48:20 +01:00
|
|
|
StringExpandPlaceholders(gStringVar4, sAwaitingResponseTexts[id]);
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_PRINT_CONTACT_MSG;
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_DO_SOMETHING_PROMPT_2;
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_RECV_JOIN_CHAT_REQUEST:
|
|
|
|
switch (UnionRoomHandleYesNo(&uroom->textState, FALSE))
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
case 0: // YES
|
2018-06-09 22:14:52 +02:00
|
|
|
CopyBgTilemapBufferToVram(0);
|
2020-05-30 10:09:21 +02:00
|
|
|
gPlayerCurrActivity = ACTIVITY_CHAT | IN_UNION_ROOM;
|
2020-06-09 00:16:57 +02:00
|
|
|
UpdateGameData_SetActivity(ACTIVITY_CHAT | IN_UNION_ROOM, 0, TRUE);
|
2021-10-06 05:38:36 +02:00
|
|
|
TryConnectToUnionRoomParent(uroom->playerList->players[taskData[1]].rfu.name, &uroom->playerList->players[taskData[1]].rfu.data, gPlayerCurrActivity);
|
2021-10-07 21:32:51 +02:00
|
|
|
uroom->unreadPlayerId = taskData[1];
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_TRY_ACCEPT_CHAT_REQUEST_DELAY;
|
2018-06-09 22:14:52 +02:00
|
|
|
taskData[3] = 0;
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case 1: // NO
|
2021-10-06 05:38:36 +02:00
|
|
|
case MENU_B_PRESSED:
|
|
|
|
playerGender = GetUnionRoomPlayerGender(taskData[1], uroom->playerList);
|
2020-06-09 00:16:57 +02:00
|
|
|
ScheduleFieldMessageAndExit(sDeclineChatTexts[playerGender]);
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_TRY_ACCEPT_CHAT_REQUEST_DELAY:
|
2018-06-10 18:28:37 +02:00
|
|
|
if (++taskData[2] > 60)
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_TRY_ACCEPT_CHAT_REQUEST;
|
2018-06-09 22:14:52 +02:00
|
|
|
taskData[2] = 0;
|
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_TRY_ACCEPT_CHAT_REQUEST:
|
|
|
|
switch (RfuGetStatus())
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
case RFU_STATUS_NEW_CHILD_DETECTED:
|
|
|
|
HandleCancelActivity(TRUE);
|
|
|
|
uroom->state = UR_STATE_MAIN;
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case RFU_STATUS_FATAL_ERROR:
|
|
|
|
case RFU_STATUS_CONNECTION_ERROR:
|
2021-10-06 05:38:36 +02:00
|
|
|
playerGender = GetUnionRoomPlayerGender(taskData[1], uroom->playerList);
|
2020-06-09 00:16:57 +02:00
|
|
|
UpdateGameData_SetActivity(ACTIVITY_PLYRTALK | IN_UNION_ROOM, 0, TRUE);
|
2020-05-30 10:09:21 +02:00
|
|
|
if (IsUnionRoomListenTaskActive() == TRUE)
|
|
|
|
ScheduleFieldMessageAndExit(sChatDeclinedTexts[playerGender]);
|
2018-06-09 22:14:52 +02:00
|
|
|
else
|
2020-06-09 00:16:57 +02:00
|
|
|
ScheduleFieldMessageWithFollowupState(UR_STATE_CANCEL_ACTIVITY_LINK_ERROR, sChatDeclinedTexts[playerGender]);
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case RFU_STATUS_CHILD_SEND_COMPLETE:
|
|
|
|
uroom->state = UR_STATE_ACCEPT_CHAT_REQUEST;
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
taskData[3]++;
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_ACCEPT_CHAT_REQUEST:
|
|
|
|
if (RfuHasErrored())
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
playerGender = GetUnionRoomPlayerGender(taskData[1], uroom->playerList);
|
2020-06-09 00:16:57 +02:00
|
|
|
UpdateGameData_SetActivity(ACTIVITY_PLYRTALK | IN_UNION_ROOM, 0, TRUE);
|
2020-05-30 10:09:21 +02:00
|
|
|
if (IsUnionRoomListenTaskActive() == TRUE)
|
|
|
|
ScheduleFieldMessageAndExit(sChatDeclinedTexts[playerGender]);
|
2018-06-09 22:14:52 +02:00
|
|
|
else
|
2020-06-09 00:16:57 +02:00
|
|
|
ScheduleFieldMessageWithFollowupState(UR_STATE_CANCEL_ACTIVITY_LINK_ERROR, sChatDeclinedTexts[playerGender]);
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
2020-05-30 10:09:21 +02:00
|
|
|
if (gReceivedRemoteLinkPlayers)
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_START_ACTIVITY_FREE_UROOM;
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_PLAYER_CONTACTED_YOU:
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_DING_DONG);
|
2021-10-07 20:55:15 +02:00
|
|
|
StopUnionRoomLinkManager();
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_RECV_CONTACT_DATA;
|
|
|
|
uroom->recvActivityRequest[0] = 0;
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_RECV_CONTACT_DATA:
|
|
|
|
if (RfuHasErrored())
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
HandleCancelActivity(FALSE);
|
|
|
|
uroom->state = UR_STATE_INIT_LINK;
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
2020-05-30 10:09:21 +02:00
|
|
|
else if (gReceivedRemoteLinkPlayers)
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
CreateTrainerCardInBuffer(gBlockSendBuffer, TRUE);
|
|
|
|
CreateTask(Task_ExchangeCards, 5);
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_WAIT_FOR_CONTACT_DATA;
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_WAIT_FOR_CONTACT_DATA:
|
|
|
|
ReceiveUnionRoomActivityPacket(uroom);
|
2020-05-30 10:09:21 +02:00
|
|
|
if (!FuncIsActiveTask(Task_ExchangeCards))
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_PRINT_CONTACT_MSG;
|
2018-06-09 22:14:52 +02:00
|
|
|
StringCopy(gStringVar1, gLinkPlayers[1].name);
|
2020-05-30 10:09:21 +02:00
|
|
|
id = PlayerHasMetTrainerBefore(gLinkPlayers[1].trainerId, gLinkPlayers[1].name);
|
2019-12-10 19:48:20 +01:00
|
|
|
StringExpandPlaceholders(gStringVar4, sPlayerContactedYouTexts[id]);
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_PRINT_CONTACT_MSG:
|
|
|
|
ReceiveUnionRoomActivityPacket(uroom);
|
|
|
|
if (PrintOnTextbox(&uroom->textState, gStringVar4))
|
|
|
|
uroom->state = UR_STATE_HANDLE_CONTACT_DATA;
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_HANDLE_CONTACT_DATA:
|
|
|
|
ReceiveUnionRoomActivityPacket(uroom);
|
2021-10-06 05:38:36 +02:00
|
|
|
if (HandleContactFromOtherPlayer(uroom) && JOY_NEW(B_BUTTON))
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2021-08-16 00:26:09 +02:00
|
|
|
Rfu_DisconnectPlayerById(1);
|
2019-10-05 05:31:25 +02:00
|
|
|
StringCopy(gStringVar4, sText_ChatEnded);
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_CANCEL_REQUEST_PRINT_MSG;
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_RECV_ACTIVITY_REQUEST:
|
|
|
|
ScheduleFieldMessageWithFollowupState(UR_STATE_HANDLE_ACTIVITY_REQUEST, gStringVar4);
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_HANDLE_ACTIVITY_REQUEST:
|
|
|
|
switch (UnionRoomHandleYesNo(&uroom->textState, FALSE))
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
case 0: // ACCEPT
|
|
|
|
uroom->playerSendBuffer[0] = ACTIVITY_ACCEPT | IN_UNION_ROOM;
|
2020-05-30 10:09:21 +02:00
|
|
|
if (gPlayerCurrActivity == (ACTIVITY_CHAT | IN_UNION_ROOM))
|
2021-08-16 00:26:09 +02:00
|
|
|
UpdateGameData_SetActivity(gPlayerCurrActivity | IN_UNION_ROOM, GetLinkPlayerInfoFlags(1), FALSE);
|
2018-06-09 22:14:52 +02:00
|
|
|
else
|
2021-08-16 00:26:09 +02:00
|
|
|
UpdateGameData_SetActivity(gPlayerCurrActivity | IN_UNION_ROOM, GetLinkPlayerInfoFlags(1), TRUE);
|
2018-06-09 22:14:52 +02:00
|
|
|
|
2021-10-07 21:32:51 +02:00
|
|
|
uroom->spawnPlayer->players[0].newPlayerCountdown = 0;
|
2018-06-09 22:14:52 +02:00
|
|
|
taskData[3] = 0;
|
2020-05-30 10:09:21 +02:00
|
|
|
if (gPlayerCurrActivity == (ACTIVITY_BATTLE_SINGLE | IN_UNION_ROOM))
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2019-10-05 05:31:25 +02:00
|
|
|
if (!HasAtLeastTwoMonsOfLevel30OrLower())
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->playerSendBuffer[0] = ACTIVITY_DECLINE | IN_UNION_ROOM;
|
2020-08-24 20:52:33 +02:00
|
|
|
Rfu_SendPacket(uroom->playerSendBuffer);
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_DECLINE_ACTIVITY_REQUEST;
|
2019-10-05 05:31:25 +02:00
|
|
|
StringCopy(gStringVar4, sText_NeedTwoMonsOfLevel30OrLower2);
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-24 20:52:33 +02:00
|
|
|
Rfu_SendPacket(uroom->playerSendBuffer);
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_PRINT_START_ACTIVITY_MSG;
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
}
|
2020-05-30 10:09:21 +02:00
|
|
|
else if (gPlayerCurrActivity == (ACTIVITY_CARD | IN_UNION_ROOM))
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-08-24 20:52:33 +02:00
|
|
|
Rfu_SendPacket(uroom->playerSendBuffer);
|
2020-06-09 00:16:57 +02:00
|
|
|
ViewURoomPartnerTrainerCard(gStringVar4, uroom, TRUE);
|
|
|
|
uroom->state = UR_STATE_PRINT_CARD_INFO;
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-24 20:52:33 +02:00
|
|
|
Rfu_SendPacket(uroom->playerSendBuffer);
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_PRINT_START_ACTIVITY_MSG;
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case 1: // DECLINE
|
2021-10-06 05:38:36 +02:00
|
|
|
case MENU_B_PRESSED:
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->playerSendBuffer[0] = ACTIVITY_DECLINE | IN_UNION_ROOM;
|
2020-08-24 20:52:33 +02:00
|
|
|
Rfu_SendPacket(uroom->playerSendBuffer);
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_DECLINE_ACTIVITY_REQUEST;
|
2020-05-30 10:09:21 +02:00
|
|
|
GetYouDeclinedTheOfferMessage(gStringVar4, gPlayerCurrActivity);
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_DECLINE_ACTIVITY_REQUEST:
|
2020-08-13 09:09:47 +02:00
|
|
|
SetCloseLinkCallback();
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_CANCEL_REQUEST_PRINT_MSG;
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_CANCEL_REQUEST_PRINT_MSG:
|
2020-05-30 10:09:21 +02:00
|
|
|
if (!gReceivedRemoteLinkPlayers)
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
gPlayerCurrActivity = IN_UNION_ROOM;
|
2020-06-09 00:16:57 +02:00
|
|
|
ScheduleFieldMessageWithFollowupState(UR_STATE_CANCEL_REQUEST_RESTART_LINK, gStringVar4);
|
|
|
|
memset(uroom->playerSendBuffer, 0, sizeof(uroom->playerSendBuffer));
|
|
|
|
uroom->recvActivityRequest[0] = 0;
|
|
|
|
uroom->partnerYesNoResponse = 0;
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_CANCEL_REQUEST_RESTART_LINK:
|
|
|
|
uroom->state = UR_STATE_INIT_LINK;
|
|
|
|
HandleCancelActivity(FALSE);
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_PRINT_START_ACTIVITY_MSG:
|
2020-05-30 10:09:21 +02:00
|
|
|
GetURoomActivityStartMsg(gStringVar4, gPlayerCurrActivity | IN_UNION_ROOM);
|
2020-06-09 00:16:57 +02:00
|
|
|
ScheduleFieldMessageWithFollowupState(UR_STATE_START_ACTIVITY_LINK, gStringVar4);
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_START_ACTIVITY_LINK:
|
2020-08-13 09:09:47 +02:00
|
|
|
SetLinkStandbyCallback();
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_START_ACTIVITY_WAIT_FOR_LINK;
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_START_ACTIVITY_WAIT_FOR_LINK:
|
2018-12-31 09:22:21 +01:00
|
|
|
if (IsLinkTaskFinished())
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_START_ACTIVITY_FREE_UROOM;
|
|
|
|
break;
|
|
|
|
case UR_STATE_START_ACTIVITY_FREE_UROOM:
|
2021-10-06 05:38:36 +02:00
|
|
|
Free(uroom->spawnPlayer);
|
|
|
|
Free(uroom->playerList);
|
|
|
|
Free(uroom->incomingParentList);
|
|
|
|
Free(uroom->incomingChildList);
|
2020-06-09 00:16:57 +02:00
|
|
|
DestroyTask(uroom->searchTaskId);
|
2021-10-06 05:38:36 +02:00
|
|
|
DestroyUnionRoomPlayerSprites(uroom->spriteIds);
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_START_ACTIVITY_FADE;
|
|
|
|
break;
|
|
|
|
case UR_STATE_START_ACTIVITY_FADE:
|
2021-10-06 05:38:36 +02:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK);
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_START_ACTIVITY;
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_START_ACTIVITY:
|
2018-06-09 22:14:52 +02:00
|
|
|
if (!UpdatePaletteFade())
|
|
|
|
{
|
2020-06-01 16:23:12 +02:00
|
|
|
DestroyUnionRoomPlayerObjects();
|
2018-06-09 22:14:52 +02:00
|
|
|
DestroyTask(taskId);
|
2020-05-30 10:09:21 +02:00
|
|
|
Free(sWirelessLinkMain.uRoom);
|
|
|
|
CreateTask_StartActivity();
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_INTERACT_WITH_ATTENDANT:
|
2021-10-06 05:38:36 +02:00
|
|
|
if (GetHostRfuGameData()->tradeSpecies == SPECIES_NONE)
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_REGISTER_PROMPT;
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (GetHostRfuGameData()->tradeSpecies == SPECIES_EGG)
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2019-10-05 05:31:25 +02:00
|
|
|
StringCopy(gStringVar4, sText_CancelRegistrationOfEgg);
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
StringCopy(gStringVar1, gSpeciesNames[GetHostRfuGameData()->tradeSpecies]);
|
|
|
|
ConvertIntToDecimalStringN(gStringVar2, GetHostRfuGameData()->tradeLevel, STR_CONV_MODE_LEFT_ALIGN, 3);
|
2019-10-05 05:31:25 +02:00
|
|
|
StringExpandPlaceholders(gStringVar4, sText_CancelRegistrationOfMon);
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
2020-06-09 00:16:57 +02:00
|
|
|
ScheduleFieldMessageWithFollowupState(UR_STATE_CANCEL_REGISTRATION_PROMPT, gStringVar4);
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_REGISTER_PROMPT:
|
|
|
|
if (PrintOnTextbox(&uroom->textState, sText_RegisterMonAtTradingBoard))
|
|
|
|
uroom->state = UR_STATE_REGISTER_PROMPT_HANDLE_INPUT;
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_REGISTER_PROMPT_HANDLE_INPUT:
|
2021-08-25 00:59:32 +02:00
|
|
|
input = ListMenuHandler_AllItemsAvailable(&uroom->textState,
|
2021-10-07 22:10:35 +02:00
|
|
|
&uroom->tradeBoardMainWindowId,
|
|
|
|
&uroom->tradeBoardHeaderWindowId,
|
2021-08-25 00:59:32 +02:00
|
|
|
&sWindowTemplate_RegisterForTrade,
|
2020-06-09 00:16:57 +02:00
|
|
|
&sListMenuTemplate_RegisterForTrade);
|
|
|
|
if (input != -1)
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
if (input == -2 || input == 3)
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_MAIN;
|
|
|
|
HandleCancelActivity(TRUE);
|
2018-06-10 18:28:37 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
switch (input)
|
2018-06-10 18:28:37 +02:00
|
|
|
{
|
2019-10-05 05:31:25 +02:00
|
|
|
case 1: // REGISTER
|
2020-06-09 00:16:57 +02:00
|
|
|
ScheduleFieldMessageWithFollowupState(UR_STATE_REGISTER_SELECT_MON_FADE, sText_WhichMonWillYouOffer);
|
2018-06-10 18:28:37 +02:00
|
|
|
break;
|
2019-10-05 05:31:25 +02:00
|
|
|
case 2: // INFO
|
2020-06-09 00:16:57 +02:00
|
|
|
ScheduleFieldMessageWithFollowupState(UR_STATE_REGISTER_PROMPT_HANDLE_INPUT, sText_TradingBoardInfo);
|
2018-06-10 18:28:37 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_REGISTER_SELECT_MON_FADE:
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 0x10, RGB_BLACK);
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_REGISTER_SELECT_MON;
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_REGISTER_SELECT_MON:
|
2018-06-09 22:14:52 +02:00
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
sUnionRoomTrade.state = URTRADE_STATE_REGISTERING;
|
2019-12-17 09:24:44 +01:00
|
|
|
gFieldCallback = FieldCB_ContinueScriptUnionRoom;
|
2019-10-18 01:22:03 +02:00
|
|
|
ChooseMonForTradingBoard(PARTY_MENU_TYPE_UNION_ROOM_REGISTER, CB2_ReturnToField);
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_REGISTER_REQUEST_TYPE:
|
2021-08-25 00:59:32 +02:00
|
|
|
input = ListMenuHandler_AllItemsAvailable(&uroom->textState,
|
2021-10-07 22:10:35 +02:00
|
|
|
&uroom->tradeBoardMainWindowId,
|
|
|
|
&uroom->tradeBoardHeaderWindowId,
|
|
|
|
&sWindowTemplate_TradingBoardRequestType,
|
2020-06-09 00:16:57 +02:00
|
|
|
&sMenuTemplate_TradingBoardRequestType);
|
|
|
|
if (input != -1)
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
switch (input)
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
|
|
|
case -2:
|
2020-06-09 00:16:57 +02:00
|
|
|
case NUMBER_OF_MON_TYPES: // Exit
|
2019-10-05 05:31:25 +02:00
|
|
|
ResetUnionRoomTrade(&sUnionRoomTrade);
|
2020-06-06 22:46:19 +02:00
|
|
|
SetTradeBoardRegisteredMonInfo(TYPE_NORMAL, SPECIES_NONE, 0);
|
2020-05-30 10:09:21 +02:00
|
|
|
ScheduleFieldMessageAndExit(sText_RegistrationCanceled);
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
|
|
|
default:
|
2020-06-09 00:16:57 +02:00
|
|
|
sUnionRoomTrade.type = input;
|
|
|
|
uroom->state = UR_STATE_REGISTER_COMPLETE;
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_REGISTER_COMPLETE:
|
2020-06-06 22:46:19 +02:00
|
|
|
SetTradeBoardRegisteredMonInfo(sUnionRoomTrade.type, sUnionRoomTrade.playerSpecies, sUnionRoomTrade.playerLevel);
|
2020-05-30 10:09:21 +02:00
|
|
|
ScheduleFieldMessageAndExit(sText_RegistraionCompleted);
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_CANCEL_REGISTRATION_PROMPT:
|
|
|
|
switch (UnionRoomHandleYesNo(&uroom->textState, FALSE))
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
case 0: // YES
|
|
|
|
uroom->state = UR_STATE_CANCEL_REGISTRATION;
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case 1: // NO
|
2021-10-06 05:38:36 +02:00
|
|
|
case MENU_B_PRESSED:
|
2020-06-09 00:16:57 +02:00
|
|
|
HandleCancelActivity(TRUE);
|
|
|
|
uroom->state = UR_STATE_MAIN;
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_CANCEL_REGISTRATION:
|
|
|
|
if (PrintOnTextbox(&uroom->textState, sText_RegistrationCanceled2))
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
SetTradeBoardRegisteredMonInfo(TYPE_NORMAL, SPECIES_NONE, 0);
|
2019-10-05 05:31:25 +02:00
|
|
|
ResetUnionRoomTrade(&sUnionRoomTrade);
|
2020-06-09 00:16:57 +02:00
|
|
|
HandleCancelActivity(TRUE);
|
|
|
|
uroom->state = UR_STATE_MAIN;
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_CHECK_TRADING_BOARD:
|
|
|
|
if (PrintOnTextbox(&uroom->textState, sText_XCheckedTradingBoard))
|
|
|
|
uroom->state = UR_STATE_TRADING_BOARD_LOAD;
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_TRADING_BOARD_LOAD:
|
2020-05-30 10:09:21 +02:00
|
|
|
UR_ClearBg0();
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_TRADING_BOARD_HANDLE_INPUT;
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_TRADING_BOARD_HANDLE_INPUT:
|
2021-10-06 05:38:36 +02:00
|
|
|
input = TradeBoardMenuHandler(&uroom->textState,
|
|
|
|
&uroom->tradeBoardMainWindowId,
|
|
|
|
&uroom->tradeBoardListMenuId,
|
|
|
|
&uroom->tradeBoardHeaderWindowId,
|
|
|
|
&sWindowTemplate_TradingBoardMain,
|
|
|
|
&sTradeBoardListMenuTemplate,
|
|
|
|
uroom->playerList);
|
2020-06-09 00:16:57 +02:00
|
|
|
if (input != -1)
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
switch (input)
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
|
|
|
case -2:
|
2020-06-09 00:16:57 +02:00
|
|
|
case 8: // EXIT
|
|
|
|
HandleCancelActivity(TRUE);
|
|
|
|
uroom->state = UR_STATE_MAIN;
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
|
|
|
default:
|
2020-05-30 10:09:21 +02:00
|
|
|
UR_ClearBg0();
|
2021-10-06 05:38:36 +02:00
|
|
|
switch (IsRequestedTypeOrEggInPlayerParty(uroom->playerList->players[input].rfu.data.tradeType, uroom->playerList->players[input].rfu.data.tradeSpecies))
|
2018-06-09 22:14:52 +02:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
case UR_TRADE_MATCH:
|
2021-10-06 05:38:36 +02:00
|
|
|
CopyAndTranslatePlayerName(gStringVar1, &uroom->playerList->players[input]);
|
2020-06-09 00:16:57 +02:00
|
|
|
ScheduleFieldMessageWithFollowupState(UR_STATE_TRADE_PROMPT, sText_AskTrainerToMakeTrade);
|
|
|
|
taskData[1] = input;
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case UR_TRADE_NOTYPE:
|
2021-10-06 05:38:36 +02:00
|
|
|
CopyAndTranslatePlayerName(gStringVar1, &uroom->playerList->players[input]);
|
|
|
|
StringCopy(gStringVar2, gTypeNames[uroom->playerList->players[input].rfu.data.tradeType]);
|
2020-06-09 00:16:57 +02:00
|
|
|
ScheduleFieldMessageWithFollowupState(UR_STATE_TRADING_BOARD_LOAD, sText_DontHaveTypeTrainerWants);
|
2018-06-10 18:28:37 +02:00
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case UR_TRADE_NOEGG:
|
2021-10-06 05:38:36 +02:00
|
|
|
CopyAndTranslatePlayerName(gStringVar1, &uroom->playerList->players[input]);
|
|
|
|
StringCopy(gStringVar2, gTypeNames[uroom->playerList->players[input].rfu.data.tradeType]);
|
2020-06-09 00:16:57 +02:00
|
|
|
ScheduleFieldMessageWithFollowupState(UR_STATE_TRADING_BOARD_LOAD, sText_DontHaveEggTrainerWants);
|
2018-06-09 22:14:52 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_TRADE_PROMPT:
|
|
|
|
switch (UnionRoomHandleYesNo(&uroom->textState, FALSE))
|
2018-06-10 18:28:37 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
case 0: // YES
|
|
|
|
uroom->state = UR_STATE_TRADE_SELECT_MON;
|
2018-06-10 18:28:37 +02:00
|
|
|
break;
|
2021-10-06 05:38:36 +02:00
|
|
|
case MENU_B_PRESSED:
|
|
|
|
case 1: // NO
|
2020-06-09 00:16:57 +02:00
|
|
|
HandleCancelActivity(TRUE);
|
|
|
|
uroom->state = UR_STATE_MAIN;
|
2018-06-10 18:28:37 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_TRADE_SELECT_MON:
|
|
|
|
if (PrintOnTextbox(&uroom->textState, sText_WhichMonWillYouOffer))
|
2018-06-10 18:28:37 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
sUnionRoomTrade.state = URTRADE_STATE_OFFERING;
|
2021-10-06 05:38:36 +02:00
|
|
|
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;
|
2019-12-17 09:24:44 +01:00
|
|
|
gFieldCallback = FieldCB_ContinueScriptUnionRoom;
|
2019-10-18 01:22:03 +02:00
|
|
|
ChooseMonForTradingBoard(PARTY_MENU_TYPE_UNION_ROOM_TRADE, CB2_ReturnToField);
|
2021-10-06 05:38:36 +02:00
|
|
|
CopyPlayerListToBuffer(uroom);
|
2020-06-09 00:16:57 +02:00
|
|
|
sUnionRoomTrade.offerPlayerId = taskData[1];
|
2018-06-10 18:28:37 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_TRADE_OFFER_MON:
|
2020-05-30 10:09:21 +02:00
|
|
|
gPlayerCurrActivity = ACTIVITY_TRADE | IN_UNION_ROOM;
|
2021-10-06 05:38:36 +02:00
|
|
|
TryConnectToUnionRoomParent(uroom->playerList->players[taskData[1]].rfu.name, &uroom->playerList->players[taskData[1]].rfu.data, gPlayerCurrActivity);
|
|
|
|
CopyAndTranslatePlayerName(gStringVar1, &uroom->playerList->players[taskData[1]]);
|
2020-05-30 10:09:21 +02:00
|
|
|
UR_PrintFieldMessage(sCommunicatingWaitTexts[2]);
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_TRY_COMMUNICATING;
|
2018-06-10 18:28:37 +02:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_PRINT_AND_EXIT:
|
|
|
|
if (PrintOnTextbox(&uroom->textState, gStringVar4))
|
2018-06-10 18:28:37 +02:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
HandleCancelActivity(TRUE);
|
2021-10-06 05:38:36 +02:00
|
|
|
UpdateUnionRoomMemberFacing(taskData[0], taskData[1], uroom->playerList);
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_MAIN;
|
2018-06-10 18:28:37 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case UR_STATE_PRINT_MSG:
|
|
|
|
if (PrintOnTextbox(&uroom->textState, gStringVar4))
|
|
|
|
uroom->state = uroom->stateAfterPrint;
|
2018-06-10 18:28:37 +02:00
|
|
|
break;
|
2018-06-09 22:14:52 +02:00
|
|
|
}
|
|
|
|
}
|
2018-06-10 18:28:37 +02:00
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
void SetUsingUnionRoomStartMenu(void)
|
2018-06-10 18:28:37 +02:00
|
|
|
{
|
|
|
|
if (InUnionRoom() == TRUE)
|
2020-06-09 00:16:57 +02:00
|
|
|
gSpecialVar_Result = UR_INTERACT_START_MENU;
|
2018-06-10 18:28:37 +02:00
|
|
|
}
|
2018-12-02 13:59:55 +01:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void ReceiveUnionRoomActivityPacket(struct WirelessLink_URoom *data)
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
2021-08-16 00:26:09 +02:00
|
|
|
if (gRecvCmds[1][1] != 0 && (gRecvCmds[1][0] & RFUCMD_MASK) == RFUCMD_SEND_PACKET)
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
data->recvActivityRequest[0] = gRecvCmds[1][1];
|
|
|
|
if (gRecvCmds[1][1] == (ACTIVITY_TRADE | IN_UNION_ROOM))
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
data->recvActivityRequest[1] = gRecvCmds[1][2];
|
|
|
|
data->recvActivityRequest[2] = gRecvCmds[1][3];
|
2018-12-02 13:59:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static bool32 HandleContactFromOtherPlayer(struct WirelessLink_URoom *uroom)
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
if (uroom->recvActivityRequest[0] != 0)
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
s32 id = GetChatLeaderActionRequestMessage(gStringVar4, gLinkPlayers[1].gender, &uroom->recvActivityRequest[0], uroom);
|
|
|
|
if (id == 0) // Error
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
2020-06-09 00:16:57 +02:00
|
|
|
else if (id == 1) // Recieve activity request
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_RECV_ACTIVITY_REQUEST;
|
|
|
|
gPlayerCurrActivity = uroom->recvActivityRequest[0];
|
2018-12-02 13:59:55 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2020-06-09 00:16:57 +02:00
|
|
|
else if (id == 2) // No activity
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
uroom->state = UR_STATE_CANCEL_REQUEST_PRINT_MSG;
|
2020-08-13 09:09:47 +02:00
|
|
|
SetCloseLinkCallback();
|
2018-12-02 13:59:55 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-10-11 10:14:09 +02:00
|
|
|
void InitUnionRoom(void)
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
struct WirelessLink_URoom *data;
|
2018-12-02 13:59:55 +01:00
|
|
|
|
2019-08-15 05:38:42 +02:00
|
|
|
sUnionRoomPlayerName[0] = EOS;
|
2020-05-30 10:09:21 +02:00
|
|
|
CreateTask(Task_InitUnionRoom, 0);
|
|
|
|
sWirelessLinkMain.uRoom = sWirelessLinkMain.uRoom; // Needed to match.
|
|
|
|
sWirelessLinkMain.uRoom = data = AllocZeroed(sizeof(struct WirelessLink_URoom));
|
|
|
|
sURoom = sWirelessLinkMain.uRoom;
|
|
|
|
data->state = 0;
|
|
|
|
data->textState = 0;
|
2020-06-09 00:16:57 +02:00
|
|
|
data->unknown = 0;
|
2021-10-07 21:32:51 +02:00
|
|
|
data->unreadPlayerId = 0;
|
2019-08-15 05:38:42 +02:00
|
|
|
sUnionRoomPlayerName[0] = EOS;
|
2018-12-02 13:59:55 +01:00
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void Task_InitUnionRoom(u8 taskId)
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
|
|
|
s32 i;
|
|
|
|
u8 text[32];
|
2020-05-30 10:09:21 +02:00
|
|
|
struct WirelessLink_URoom *data = sWirelessLinkMain.uRoom;
|
2018-12-02 13:59:55 +01:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
switch (data->state)
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
|
|
|
case 0:
|
2020-05-30 10:09:21 +02:00
|
|
|
data->state = 1;
|
2018-12-02 13:59:55 +01:00
|
|
|
break;
|
|
|
|
case 1:
|
2021-10-06 05:38:36 +02:00
|
|
|
SetHostRfuGameData(ACTIVITY_SEARCH, 0, FALSE);
|
2020-05-30 10:09:21 +02:00
|
|
|
SetWirelessCommType1();
|
2018-12-02 13:59:55 +01:00
|
|
|
OpenLink();
|
2020-05-30 10:09:21 +02:00
|
|
|
InitializeRfuLinkManager_EnterUnionRoom();
|
2021-08-16 00:26:09 +02:00
|
|
|
RfuSetIgnoreError(TRUE);
|
2020-05-30 10:09:21 +02:00
|
|
|
data->state = 2;
|
2018-12-02 13:59:55 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
2021-10-06 05:38:36 +02:00
|
|
|
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);
|
2020-05-30 10:09:21 +02:00
|
|
|
data->state = 3;
|
2018-12-02 13:59:55 +01:00
|
|
|
break;
|
|
|
|
case 3:
|
2020-05-30 10:09:21 +02:00
|
|
|
switch (HandlePlayerListUpdate())
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
2021-10-07 21:32:51 +02:00
|
|
|
case PLIST_NEW_PLAYER:
|
|
|
|
case PLIST_RECENT_UPDATE:
|
2019-08-15 05:38:42 +02:00
|
|
|
if (sUnionRoomPlayerName[0] == EOS)
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
for (i = 0; i < MAX_UNION_ROOM_LEADERS; i++)
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (data->playerList->players[i].groupScheduledAnim == UNION_ROOM_SPAWN_IN)
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
CopyAndTranslatePlayerName(text, &data->playerList->players[i]);
|
|
|
|
if (PlayerHasMetTrainerBefore(ReadAsU16(data->playerList->players[i].rfu.data.compatibility.playerTrainerId), text))
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
2019-08-15 05:38:42 +02:00
|
|
|
StringCopy(sUnionRoomPlayerName, text);
|
2018-12-02 13:59:55 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2021-10-07 21:32:51 +02:00
|
|
|
case PLIST_UNUSED:
|
2018-12-02 13:59:55 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
2021-10-06 05:38:36 +02:00
|
|
|
free(data->spawnPlayer);
|
|
|
|
free(data->playerList);
|
|
|
|
free(data->incomingParentList);
|
|
|
|
free(data->incomingChildList);
|
2020-06-09 00:16:57 +02:00
|
|
|
DestroyTask(data->searchTaskId);
|
2020-05-30 10:09:21 +02:00
|
|
|
free(sWirelessLinkMain.uRoom);
|
|
|
|
LinkRfu_Shutdown();
|
2018-12-02 13:59:55 +01:00
|
|
|
DestroyTask(taskId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-15 05:38:42 +02:00
|
|
|
bool16 BufferUnionRoomPlayerName(void)
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
2019-08-15 05:38:42 +02:00
|
|
|
if (sUnionRoomPlayerName[0] != EOS)
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
2019-08-15 05:38:42 +02:00
|
|
|
StringCopy(gStringVar1, sUnionRoomPlayerName);
|
|
|
|
sUnionRoomPlayerName[0] = EOS;
|
2018-12-02 13:59:55 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static u8 HandlePlayerListUpdate(void)
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
|
|
|
s32 i;
|
|
|
|
u8 j;
|
2020-05-30 10:09:21 +02:00
|
|
|
struct WirelessLink_URoom *data = sWirelessLinkMain.uRoom;
|
2021-10-07 21:32:51 +02:00
|
|
|
s32 retVal = PLIST_NONE;
|
2018-12-02 13:59:55 +01:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (ArePlayersDifferent(&data->incomingParentList->players[i].rfu, &sUnionRoomPlayer_DummyRfu) == TRUE)
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
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;
|
2021-10-07 21:32:51 +02:00
|
|
|
data->spawnPlayer->players[0].newPlayerCountdown = 1;
|
|
|
|
return PLIST_CONTACTED;
|
2018-12-02 13:59:55 +01:00
|
|
|
}
|
|
|
|
}
|
2021-10-06 05:38:36 +02:00
|
|
|
for (j = 0; j < MAX_UNION_ROOM_LEADERS; j++)
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (data->playerList->players[j].groupScheduledAnim != UNION_ROOM_SPAWN_NONE)
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
i = GetNewIncomingPlayerId(&data->playerList->players[j], &data->incomingChildList->players[0]);
|
2018-12-02 13:59:55 +01:00
|
|
|
if (i != 0xFF)
|
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (data->playerList->players[j].groupScheduledAnim == UNION_ROOM_SPAWN_IN)
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (ArePlayerDataDifferent(&data->playerList->players[j].rfu, &data->incomingChildList->players[i].rfu))
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
data->playerList->players[j].rfu = data->incomingChildList->players[i].rfu;
|
2021-10-07 21:32:51 +02:00
|
|
|
data->playerList->players[j].newPlayerCountdown = 64;
|
|
|
|
retVal = PLIST_NEW_PLAYER;
|
2018-12-02 13:59:55 +01:00
|
|
|
}
|
2021-10-07 21:32:51 +02:00
|
|
|
else if (data->playerList->players[j].newPlayerCountdown != 0)
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
2021-10-07 21:32:51 +02:00
|
|
|
data->playerList->players[j].newPlayerCountdown--;
|
|
|
|
if (data->playerList->players[j].newPlayerCountdown == 0)
|
|
|
|
retVal = PLIST_RECENT_UPDATE;
|
2018-12-02 13:59:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
data->playerList->players[j].groupScheduledAnim = UNION_ROOM_SPAWN_IN;
|
2021-10-07 21:32:51 +02:00
|
|
|
data->playerList->players[j].newPlayerCountdown = 0;
|
|
|
|
retVal = PLIST_RECENT_UPDATE;
|
2018-12-02 13:59:55 +01:00
|
|
|
}
|
2021-10-06 05:38:36 +02:00
|
|
|
data->playerList->players[j].timeoutCounter = 0;
|
2018-12-02 13:59:55 +01:00
|
|
|
}
|
2021-10-06 05:38:36 +02:00
|
|
|
else if (data->playerList->players[j].groupScheduledAnim != UNION_ROOM_SPAWN_OUT)
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
data->playerList->players[j].timeoutCounter++;
|
|
|
|
if (data->playerList->players[j].timeoutCounter >= 600)
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
data->playerList->players[j].groupScheduledAnim = UNION_ROOM_SPAWN_OUT;
|
2021-10-07 21:32:51 +02:00
|
|
|
retVal = PLIST_RECENT_UPDATE;
|
2018-12-02 13:59:55 +01:00
|
|
|
}
|
|
|
|
}
|
2021-10-06 05:38:36 +02:00
|
|
|
else if (data->playerList->players[j].groupScheduledAnim == UNION_ROOM_SPAWN_OUT)
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
data->playerList->players[j].timeoutCounter++;
|
|
|
|
if (data->playerList->players[j].timeoutCounter >= 900)
|
|
|
|
ClearRfuPlayerList(&data->playerList->players[j], 1);
|
2018-12-02 13:59:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-30 10:09:21 +02:00
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
2021-10-06 05:38:36 +02:00
|
|
|
if (TryAddIncomingPlayerToList(&data->playerList->players[0], &data->incomingChildList->players[i], MAX_UNION_ROOM_LEADERS) != 0xFF)
|
2021-10-07 21:32:51 +02:00
|
|
|
retVal = PLIST_NEW_PLAYER;
|
2018-12-02 13:59:55 +01:00
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
return retVal;
|
2018-12-02 13:59:55 +01:00
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void Task_SearchForChildOrParent(u8 taskId)
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
|
|
|
s32 i, j;
|
2021-10-06 05:38:36 +02:00
|
|
|
struct RfuPlayerData rfu;
|
|
|
|
struct RfuIncomingPlayerList **list = (void*) gTasks[taskId].data;
|
2020-05-30 10:09:21 +02:00
|
|
|
bool8 isParent;
|
2018-12-02 13:59:55 +01:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
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;
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
if (!isParent)
|
2018-12-02 13:59:55 +01:00
|
|
|
{
|
|
|
|
for (j = 0; j < i; j++)
|
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (!ArePlayersDifferent(&list[1]->players[j].rfu, &rfu))
|
|
|
|
rfu = sUnionRoomPlayer_DummyRfu;
|
2018-12-02 13:59:55 +01:00
|
|
|
}
|
2021-10-06 05:38:36 +02:00
|
|
|
list[1]->players[i].rfu = rfu;
|
|
|
|
list[1]->players[i].active = ArePlayersDifferent(&list[1]->players[i].rfu, &sUnionRoomPlayer_DummyRfu);
|
2018-12-02 13:59:55 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
list[0]->players[i].rfu = rfu;
|
|
|
|
list[0]->players[i].active = ArePlayersDifferent(&list[0]->players[i].rfu, &sUnionRoomPlayer_DummyRfu);
|
2018-12-02 13:59:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-27 15:44:49 +01:00
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static u8 CreateTask_SearchForChildOrParent(struct RfuIncomingPlayerList * parentList, struct RfuIncomingPlayerList * childList, u32 linkGroup)
|
2019-03-27 15:44:49 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
u8 taskId = CreateTask(Task_SearchForChildOrParent, 0);
|
2021-10-06 05:38:36 +02:00
|
|
|
struct RfuIncomingPlayerList ** data = (void *)gTasks[taskId].data;
|
|
|
|
data[0] = parentList;
|
|
|
|
data[1] = childList;
|
2020-05-30 10:09:21 +02:00
|
|
|
gTasks[taskId].data[4] = linkGroup;
|
2019-03-27 15:44:49 +01:00
|
|
|
return taskId;
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static void Task_ListenForCompatiblePartners(u8 taskId)
|
2019-03-27 15:44:49 +01:00
|
|
|
{
|
|
|
|
s32 i, j;
|
2021-10-06 05:38:36 +02:00
|
|
|
struct RfuIncomingPlayerList **list = (void*) gTasks[taskId].data;
|
2019-03-27 15:44:49 +01:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
2019-03-27 15:44:49 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
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]))
|
2019-03-27 15:44:49 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
list[0]->players[i].rfu = sUnionRoomPlayer_DummyRfu;
|
2019-03-27 15:44:49 +01:00
|
|
|
}
|
|
|
|
for (j = 0; j < i; j++)
|
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (!ArePlayersDifferent(&list[0]->players[j].rfu, &list[0]->players[i].rfu))
|
|
|
|
list[0]->players[i].rfu = sUnionRoomPlayer_DummyRfu;
|
2019-03-27 15:44:49 +01:00
|
|
|
}
|
2021-10-06 05:38:36 +02:00
|
|
|
list[0]->players[i].active = ArePlayersDifferent(&list[0]->players[i].rfu, &sUnionRoomPlayer_DummyRfu);
|
2019-03-27 15:44:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static bool32 HasWonderCardOrNewsByLinkGroup(struct RfuGameData *data, s16 linkGroup)
|
2019-03-27 15:44:49 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
if (linkGroup == LINK_GROUP_WONDER_CARD)
|
2019-03-27 15:44:49 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (!data->compatibility.hasCard)
|
2019-03-27 15:44:49 +01:00
|
|
|
return FALSE;
|
|
|
|
else
|
|
|
|
return TRUE;
|
|
|
|
}
|
2020-05-30 10:09:21 +02:00
|
|
|
else if (linkGroup == LINK_GROUP_WONDER_NEWS)
|
2019-03-27 15:44:49 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (!data->compatibility.hasNews)
|
2019-03-27 15:44:49 +01:00
|
|
|
return FALSE;
|
|
|
|
else
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static void Task_ListenForWonderDistributor(u8 taskId)
|
2019-03-27 15:44:49 +01:00
|
|
|
{
|
|
|
|
s32 i;
|
2021-10-06 05:38:36 +02:00
|
|
|
struct RfuIncomingPlayerList **list = (void*) gTasks[taskId].data;
|
2019-03-27 15:44:49 +01:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
2019-03-27 15:44:49 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
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);
|
2019-03-27 15:44:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static u8 CreateTask_ListenForCompatiblePartners(struct RfuIncomingPlayerList * list, u32 linkGroup)
|
2019-03-27 15:44:49 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
u8 taskId = CreateTask(Task_ListenForCompatiblePartners, 0);
|
|
|
|
struct RfuIncomingPlayerList **oldList = (void*) gTasks[taskId].data;
|
|
|
|
oldList[0] = list;
|
2020-05-30 10:09:21 +02:00
|
|
|
gTasks[taskId].data[2] = linkGroup;
|
2019-03-27 15:44:49 +01:00
|
|
|
return taskId;
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static u8 CreateTask_ListenForWonderDistributor(struct RfuIncomingPlayerList * list, u32 linkGroup)
|
2019-03-27 15:44:49 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
u8 taskId = CreateTask(Task_ListenForWonderDistributor, 0);
|
|
|
|
struct RfuIncomingPlayerList **oldList = (void*) gTasks[taskId].data;
|
|
|
|
oldList[0] = list;
|
2020-05-30 10:09:21 +02:00
|
|
|
gTasks[taskId].data[2] = linkGroup;
|
2019-03-27 15:44:49 +01:00
|
|
|
return taskId;
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static bool32 UR_PrintFieldMessage(const u8 *src)
|
2019-03-27 15:44:49 +01:00
|
|
|
{
|
2020-02-07 18:48:47 +01:00
|
|
|
LoadMessageBoxAndBorderGfx();
|
2019-03-27 15:44:49 +01:00
|
|
|
DrawDialogueFrame(0, 1);
|
|
|
|
StringExpandPlaceholders(gStringVar4, src);
|
|
|
|
AddTextPrinterWithCustomSpeedForMessage(FALSE, 1);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static bool32 UR_RunTextPrinters(void)
|
2019-03-27 15:44:49 +01:00
|
|
|
{
|
|
|
|
if (!RunTextPrintersAndIsPrinter0Active())
|
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
2019-03-27 18:16:10 +01:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static bool8 PrintOnTextbox(u8 *textState, const u8 *str)
|
2019-03-27 18:16:10 +01:00
|
|
|
{
|
|
|
|
switch (*textState)
|
|
|
|
{
|
|
|
|
case 0:
|
2020-02-07 18:48:47 +01:00
|
|
|
LoadMessageBoxAndBorderGfx();
|
2019-03-27 18:16:10 +01:00
|
|
|
DrawDialogueFrame(0, 1);
|
|
|
|
StringExpandPlaceholders(gStringVar4, str);
|
|
|
|
AddTextPrinterForMessage_2(TRUE);
|
|
|
|
(*textState)++;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (!RunTextPrintersAndIsPrinter0Active())
|
|
|
|
{
|
|
|
|
*textState = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static s8 UnionRoomHandleYesNo(u8 *state, bool32 noDraw)
|
2019-03-27 18:16:10 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
s8 input;
|
2019-03-27 18:16:10 +01:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
switch (*state)
|
2019-03-27 18:16:10 +01:00
|
|
|
{
|
|
|
|
case 0:
|
2020-05-30 10:09:21 +02:00
|
|
|
if (noDraw)
|
2019-03-27 18:16:10 +01:00
|
|
|
return -3;
|
|
|
|
DisplayYesNoMenuDefaultYes();
|
2020-05-30 10:09:21 +02:00
|
|
|
(*state)++;
|
2019-03-27 18:16:10 +01:00
|
|
|
break;
|
|
|
|
case 1:
|
2020-05-30 10:09:21 +02:00
|
|
|
if (noDraw)
|
2019-03-27 18:16:10 +01:00
|
|
|
{
|
|
|
|
sub_8198C78();
|
2020-05-30 10:09:21 +02:00
|
|
|
*state = 0;
|
2019-03-27 18:16:10 +01:00
|
|
|
return -3;
|
|
|
|
}
|
2020-06-09 00:16:57 +02:00
|
|
|
input = Menu_ProcessInputNoWrapClearOnChoose();
|
2021-10-06 05:38:36 +02:00
|
|
|
if (input == MENU_B_PRESSED || input == 0 || input == 1)
|
2019-03-27 18:16:10 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
*state = 0;
|
2020-06-09 00:16:57 +02:00
|
|
|
return input;
|
2019-03-27 18:16:10 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2021-10-06 05:38:36 +02:00
|
|
|
return MENU_NOTHING_CHOSEN;
|
2019-03-27 18:16:10 +01:00
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static u8 CreateTradeBoardWindow(const struct WindowTemplate * template)
|
2019-03-27 18:16:10 +01:00
|
|
|
{
|
|
|
|
u8 windowId = AddWindow(template);
|
|
|
|
DrawStdWindowFrame(windowId, FALSE);
|
2020-05-30 10:09:21 +02:00
|
|
|
FillWindowPixelBuffer(windowId, PIXEL_FILL(15));
|
2021-10-06 05:38:36 +02:00
|
|
|
PrintUnionRoomText(windowId, 1, sText_NameWantedOfferLv, 8, 1, UR_COLOR_TRADE_BOARD_OTHER);
|
2019-03-27 18:16:10 +01:00
|
|
|
CopyWindowToVram(windowId, 2);
|
|
|
|
PutWindowTilemap(windowId);
|
|
|
|
return windowId;
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void DeleteTradeBoardWindow(u8 windowId)
|
2019-03-27 18:16:10 +01:00
|
|
|
{
|
|
|
|
RemoveWindow(windowId);
|
|
|
|
}
|
2019-03-27 21:57:34 +01:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static s32 ListMenuHandler_AllItemsAvailable(u8 *state, u8 *windowId, u8 *listMenuId, const struct WindowTemplate *winTemplate, const struct ListMenuTemplate *menuTemplate)
|
2019-03-27 21:57:34 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
s32 maxWidth, input;
|
2019-03-27 21:57:34 +01:00
|
|
|
struct WindowTemplate winTemplateCopy;
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
switch (*state)
|
2019-03-27 21:57:34 +01:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
winTemplateCopy = *winTemplate;
|
2020-05-30 10:09:21 +02:00
|
|
|
maxWidth = Intl_GetListMenuWidth(menuTemplate);
|
|
|
|
if (winTemplateCopy.width > maxWidth)
|
|
|
|
winTemplateCopy.width = maxWidth;
|
2021-10-06 05:38:36 +02:00
|
|
|
|
2019-03-27 21:57:34 +01:00
|
|
|
if (winTemplateCopy.tilemapLeft + winTemplateCopy.width > 29)
|
|
|
|
winTemplateCopy.tilemapLeft = max(29 - winTemplateCopy.width, 0);
|
2021-10-06 05:38:36 +02:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
*windowId = AddWindow(&winTemplateCopy);
|
|
|
|
DrawStdWindowFrame(*windowId, FALSE);
|
2019-03-27 21:57:34 +01:00
|
|
|
gMultiuseListMenuTemplate = *menuTemplate;
|
2020-05-30 10:09:21 +02:00
|
|
|
gMultiuseListMenuTemplate.windowId = *windowId;
|
|
|
|
*listMenuId = ListMenuInit(&gMultiuseListMenuTemplate, 0, 0);
|
|
|
|
CopyWindowToVram(*windowId, TRUE);
|
|
|
|
(*state)++;
|
2019-03-27 21:57:34 +01:00
|
|
|
break;
|
|
|
|
case 1:
|
2020-05-30 10:09:21 +02:00
|
|
|
input = ListMenu_ProcessInput(*listMenuId);
|
2020-06-09 00:16:57 +02:00
|
|
|
if (JOY_NEW(A_BUTTON))
|
2019-03-27 21:57:34 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
DestroyListMenuTask(*listMenuId, NULL, NULL);
|
|
|
|
ClearStdWindowAndFrame(*windowId, TRUE);
|
|
|
|
RemoveWindow(*windowId);
|
|
|
|
*state = 0;
|
|
|
|
return input;
|
2019-03-27 21:57:34 +01:00
|
|
|
}
|
2020-06-09 00:16:57 +02:00
|
|
|
else if (JOY_NEW(B_BUTTON))
|
2019-03-27 21:57:34 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
DestroyListMenuTask(*listMenuId, NULL, NULL);
|
|
|
|
ClearStdWindowAndFrame(*windowId, TRUE);
|
|
|
|
RemoveWindow(*windowId);
|
|
|
|
*state = 0;
|
2019-03-27 21:57:34 +01:00
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static s32 TradeBoardMenuHandler(u8 *state, u8 *mainWindowId, u8 *listMenuId, u8 *headerWindowId,
|
|
|
|
const struct WindowTemplate *winTemplate,
|
|
|
|
const struct ListMenuTemplate *menuTemplate,
|
|
|
|
struct RfuPlayerList *list)
|
2019-03-27 21:57:34 +01:00
|
|
|
{
|
|
|
|
s32 input;
|
2020-05-30 10:09:21 +02:00
|
|
|
s32 idx;
|
2019-03-27 21:57:34 +01:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
switch (*state)
|
2019-03-27 21:57:34 +01:00
|
|
|
{
|
|
|
|
case 0:
|
2021-10-06 05:38:36 +02:00
|
|
|
*headerWindowId = CreateTradeBoardWindow(&sWindowTemplate_TradingBoardHeader);
|
|
|
|
*mainWindowId = AddWindow(winTemplate);
|
|
|
|
DrawStdWindowFrame(*mainWindowId, FALSE);
|
2019-03-27 21:57:34 +01:00
|
|
|
gMultiuseListMenuTemplate = *menuTemplate;
|
2021-10-06 05:38:36 +02:00
|
|
|
gMultiuseListMenuTemplate.windowId = *mainWindowId;
|
2020-05-30 10:09:21 +02:00
|
|
|
*listMenuId = ListMenuInit(&gMultiuseListMenuTemplate, 0, 1);
|
|
|
|
(*state)++;
|
2019-03-27 21:57:34 +01:00
|
|
|
break;
|
|
|
|
case 1:
|
2021-10-06 05:38:36 +02:00
|
|
|
CopyWindowToVram(*mainWindowId, TRUE);
|
2020-05-30 10:09:21 +02:00
|
|
|
(*state)++;
|
2019-03-27 21:57:34 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
2020-05-30 10:09:21 +02:00
|
|
|
input = ListMenu_ProcessInput(*listMenuId);
|
2020-06-09 00:16:57 +02:00
|
|
|
if (JOY_NEW(A_BUTTON | B_BUTTON))
|
2019-03-27 21:57:34 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
if (input == 8 || JOY_NEW(B_BUTTON))
|
2019-03-27 21:57:34 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
DestroyListMenuTask(*listMenuId, NULL, NULL);
|
2021-10-06 05:38:36 +02:00
|
|
|
RemoveWindow(*mainWindowId);
|
|
|
|
DeleteTradeBoardWindow(*headerWindowId);
|
2020-05-30 10:09:21 +02:00
|
|
|
*state = 0;
|
2019-03-27 21:57:34 +01:00
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
idx = GetIndexOfNthTradeBoardOffer(list->players, input);
|
2020-05-30 10:09:21 +02:00
|
|
|
if (idx >= 0)
|
2019-03-27 21:57:34 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
DestroyListMenuTask(*listMenuId, NULL, NULL);
|
2021-10-06 05:38:36 +02:00
|
|
|
RemoveWindow(*mainWindowId);
|
|
|
|
DeleteTradeBoardWindow(*headerWindowId);
|
2020-05-30 10:09:21 +02:00
|
|
|
*state = 0;
|
|
|
|
return idx;
|
2019-03-27 21:57:34 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PlaySE(SE_WALL_HIT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2020-05-30 10:09:21 +02:00
|
|
|
|
|
|
|
static void UR_ClearBg0(void)
|
2019-03-28 13:42:35 +01:00
|
|
|
{
|
|
|
|
FillBgTilemapBufferRect(0, 0, 0, 0, 32, 32, 0);
|
|
|
|
CopyBgTilemapBufferToVram(0);
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void JoinGroup_EnableScriptContexts(void)
|
2019-03-28 13:42:35 +01:00
|
|
|
{
|
|
|
|
EnableBothScriptContexts();
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static void PrintUnionRoomText(u8 windowId, u8 fontId, const u8 *str, u8 x, u8 y, u8 colorIdx)
|
2019-03-28 13:42:35 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
struct TextPrinterTemplate printerTemplate;
|
2019-03-28 13:42:35 +01:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
printerTemplate.currentChar = str;
|
|
|
|
printerTemplate.windowId = windowId;
|
|
|
|
printerTemplate.fontId = fontId;
|
|
|
|
printerTemplate.x = x;
|
|
|
|
printerTemplate.y = y;
|
|
|
|
printerTemplate.currentX = x;
|
|
|
|
printerTemplate.currentY = y;
|
Undo PokeCodec's PRs
This commit undoes most of PokeCodec's PRs after the debate in chat. Some
harmless or completely superseded PRs have been left alone, as there is not
much benefit in attempting to undo them.
Reverts #1104, #1108, #1115, #1118, #1119, #1124, #1126, #1127, #1132, #1136,
#1137, #1139, #1140, #1144, #1148, #1149, #1150, #1153, #1155, #1177, #1179,
#1180, #1181, #1182 and #1183.
2020-09-13 09:22:50 +02:00
|
|
|
printerTemplate.unk = 0;
|
2019-03-28 14:59:08 +01:00
|
|
|
|
|
|
|
gTextFlags.useAlternateDownArrow = FALSE;
|
2020-05-30 10:09:21 +02:00
|
|
|
switch (colorIdx)
|
2019-03-28 14:59:08 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
case UR_COLOR_DEFAULT:
|
2020-05-30 10:09:21 +02:00
|
|
|
printerTemplate.letterSpacing = 0;
|
|
|
|
printerTemplate.lineSpacing = 0;
|
2021-04-10 04:39:34 +02:00
|
|
|
printerTemplate.fgColor = TEXT_COLOR_DARK_GRAY;
|
2020-05-30 10:09:21 +02:00
|
|
|
printerTemplate.bgColor = TEXT_COLOR_WHITE;
|
2021-04-10 04:39:34 +02:00
|
|
|
printerTemplate.shadowColor = TEXT_COLOR_LIGHT_GRAY;
|
2020-05-30 10:09:21 +02:00
|
|
|
break;
|
2021-10-06 05:38:36 +02:00
|
|
|
case UR_COLOR_RED:
|
2020-05-30 10:09:21 +02:00
|
|
|
printerTemplate.letterSpacing = 0;
|
|
|
|
printerTemplate.lineSpacing = 0;
|
|
|
|
printerTemplate.fgColor = TEXT_COLOR_RED;
|
|
|
|
printerTemplate.bgColor = TEXT_COLOR_WHITE;
|
|
|
|
printerTemplate.shadowColor = TEXT_COLOR_LIGHT_RED;
|
|
|
|
break;
|
2021-10-06 05:38:36 +02:00
|
|
|
case UR_COLOR_GREEN:
|
2020-05-30 10:09:21 +02:00
|
|
|
printerTemplate.letterSpacing = 0;
|
|
|
|
printerTemplate.lineSpacing = 0;
|
|
|
|
printerTemplate.fgColor = TEXT_COLOR_GREEN;
|
|
|
|
printerTemplate.bgColor = TEXT_COLOR_WHITE;
|
|
|
|
printerTemplate.shadowColor = TEXT_COLOR_LIGHT_GREEN;
|
|
|
|
break;
|
2021-10-06 05:38:36 +02:00
|
|
|
case UR_COLOR_WHITE:
|
2020-05-30 10:09:21 +02:00
|
|
|
printerTemplate.letterSpacing = 0;
|
|
|
|
printerTemplate.lineSpacing = 0;
|
|
|
|
printerTemplate.fgColor = TEXT_COLOR_WHITE;
|
|
|
|
printerTemplate.bgColor = TEXT_COLOR_WHITE;
|
2021-04-10 04:39:34 +02:00
|
|
|
printerTemplate.shadowColor = TEXT_COLOR_LIGHT_GRAY;
|
2020-05-30 10:09:21 +02:00
|
|
|
break;
|
2021-10-06 05:38:36 +02:00
|
|
|
case UR_COLOR_CANCEL:
|
2020-05-30 10:09:21 +02:00
|
|
|
printerTemplate.letterSpacing = 0;
|
|
|
|
printerTemplate.lineSpacing = 0;
|
|
|
|
printerTemplate.fgColor = TEXT_COLOR_WHITE;
|
2021-04-10 04:39:34 +02:00
|
|
|
printerTemplate.bgColor = TEXT_COLOR_DARK_GRAY;
|
|
|
|
printerTemplate.shadowColor = TEXT_COLOR_LIGHT_GRAY;
|
2020-05-30 10:09:21 +02:00
|
|
|
break;
|
2021-10-06 05:38:36 +02:00
|
|
|
case UR_COLOR_TRADE_BOARD_SELF:
|
2020-05-30 10:09:21 +02:00
|
|
|
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;
|
2021-10-06 05:38:36 +02:00
|
|
|
case UR_COLOR_TRADE_BOARD_OTHER:
|
2020-05-30 10:09:21 +02:00
|
|
|
printerTemplate.letterSpacing = 0;
|
|
|
|
printerTemplate.lineSpacing = 0;
|
|
|
|
printerTemplate.fgColor = TEXT_DYNAMIC_COLOR_5;
|
|
|
|
printerTemplate.bgColor = TEXT_DYNAMIC_COLOR_6;
|
|
|
|
printerTemplate.shadowColor = TEXT_COLOR_LIGHT_BLUE;
|
2019-03-28 14:59:08 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
AddTextPrinter(&printerTemplate, TEXT_SPEED_FF, NULL);
|
2019-03-28 13:42:35 +01:00
|
|
|
}
|
2019-03-28 15:24:31 +01:00
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static void ClearRfuPlayerList(struct RfuPlayer *players, u8 count)
|
2019-03-28 15:24:31 +01:00
|
|
|
{
|
|
|
|
s32 i;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
players[i].rfu = sUnionRoomPlayer_DummyRfu;
|
|
|
|
players[i].timeoutCounter = 255;
|
|
|
|
players[i].groupScheduledAnim = UNION_ROOM_SPAWN_NONE;
|
|
|
|
players[i].useRedText = FALSE;
|
2021-10-07 21:32:51 +02:00
|
|
|
players[i].newPlayerCountdown = 0;
|
2019-03-28 15:24:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static void ClearIncomingPlayerList(struct RfuIncomingPlayerList *list, u8 count)
|
2019-03-28 15:24:31 +01:00
|
|
|
{
|
|
|
|
s32 i;
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
2019-03-28 15:24:31 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
list->players[i].rfu = sUnionRoomPlayer_DummyRfu;
|
|
|
|
list->players[i].active = FALSE;
|
2019-03-28 15:24:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
// Checks player name and trainer id, returns TRUE if they are not the same
|
|
|
|
static bool8 ArePlayersDifferent(struct RfuPlayerData* player1, const struct RfuPlayerData* player2)
|
2019-03-28 15:24:31 +01:00
|
|
|
{
|
|
|
|
s32 i;
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (player1->data.compatibility.playerTrainerId[i] != player2->data.compatibility.playerTrainerId[i])
|
2019-03-28 15:24:31 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
for (i = 0; i < PLAYER_NAME_LENGTH + 1; i++)
|
2019-03-28 15:24:31 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (player1->name[i] != player2->name[i])
|
2019-03-28 15:24:31 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static bool32 ArePlayerDataDifferent(struct RfuPlayerData *player1, struct RfuPlayerData *player2)
|
2019-03-28 15:24:31 +01:00
|
|
|
{
|
|
|
|
s32 i;
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
if (player1->data.activity != player2->data.activity)
|
2019-03-28 15:24:31 +01:00
|
|
|
return TRUE;
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
if (player1->data.startedActivity != player2->data.startedActivity)
|
2019-03-28 15:24:31 +01:00
|
|
|
return TRUE;
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
2019-03-28 15:24:31 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (player1->data.partnerInfo[i] != player2->data.partnerInfo[i])
|
2019-03-28 15:24:31 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
if (player1->data.tradeSpecies != player2->data.tradeSpecies)
|
2019-03-28 15:24:31 +01:00
|
|
|
return TRUE;
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
if (player1->data.tradeType != player2->data.tradeType)
|
2019-03-28 15:24:31 +01:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static u32 GetNewIncomingPlayerId(struct RfuPlayer *player, struct RfuIncomingPlayer *incomingPlayer)
|
2019-03-28 15:24:31 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
u8 result = 0xFF; // None
|
2019-03-28 15:24:31 +01:00
|
|
|
s32 i;
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
2019-03-28 15:24:31 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (incomingPlayer[i].active && !ArePlayersDifferent(&player->rfu, &incomingPlayer[i].rfu))
|
2019-03-28 15:24:31 +01:00
|
|
|
{
|
|
|
|
result = i;
|
2021-10-06 05:38:36 +02:00
|
|
|
incomingPlayer[i].active = FALSE;
|
2019-03-28 15:24:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2019-03-28 16:24:50 +01:00
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static u8 TryAddIncomingPlayerToList(struct RfuPlayer *players, struct RfuIncomingPlayer *incomingPlayer, u8 max)
|
2019-03-28 16:24:50 +01:00
|
|
|
{
|
|
|
|
s32 i;
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
if (incomingPlayer->active)
|
2019-03-28 16:24:50 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
for (i = 0; i < max; i++)
|
2019-03-28 16:24:50 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (players[i].groupScheduledAnim == UNION_ROOM_SPAWN_NONE)
|
2019-03-28 16:24:50 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
players[i].rfu = incomingPlayer->rfu;
|
|
|
|
players[i].timeoutCounter = 0;
|
|
|
|
players[i].groupScheduledAnim = UNION_ROOM_SPAWN_IN;
|
2021-10-07 21:32:51 +02:00
|
|
|
players[i].newPlayerCountdown = 64;
|
2021-10-06 05:38:36 +02:00
|
|
|
incomingPlayer->active = FALSE;
|
2019-03-28 16:24:50 +01:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0xFF;
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static void PrintGroupMemberOnWindow(u8 windowId, u8 x, u8 y, struct RfuPlayer *player, u8 colorIdx, u8 id)
|
2019-03-28 16:24:50 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
u8 activity;
|
|
|
|
u8 trainerId[6];
|
2019-03-28 16:24:50 +01:00
|
|
|
|
|
|
|
ConvertIntToDecimalStringN(gStringVar4, id + 1, STR_CONV_MODE_LEADING_ZEROS, 2);
|
2019-12-10 19:48:20 +01:00
|
|
|
StringAppend(gStringVar4, sText_Colon);
|
2021-10-06 05:38:36 +02:00
|
|
|
PrintUnionRoomText(windowId, 1, gStringVar4, x, y, UR_COLOR_DEFAULT);
|
2020-05-30 10:09:21 +02:00
|
|
|
x += 18;
|
2021-10-06 05:38:36 +02:00
|
|
|
activity = player->rfu.data.activity;
|
|
|
|
if (player->groupScheduledAnim == UNION_ROOM_SPAWN_IN && !(activity & IN_UNION_ROOM))
|
2019-03-28 16:24:50 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
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);
|
2019-12-10 19:48:20 +01:00
|
|
|
StringCopy(gStringVar4, sText_ID);
|
2020-05-30 10:09:21 +02:00
|
|
|
StringAppend(gStringVar4, trainerId);
|
2021-10-06 05:38:36 +02:00
|
|
|
PrintUnionRoomText(windowId, 1, gStringVar4, GetStringRightAlignXOffset(1, gStringVar4, 0x88), y, colorIdx);
|
2019-03-28 16:24:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static void PrintGroupCandidateOnWindow(u8 windowId, u8 x, u8 y, struct RfuPlayer *player, u8 colorIdx, u8 id)
|
2019-03-28 16:24:50 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
u8 trainerId[6];
|
2019-03-28 16:24:50 +01:00
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
if (player->groupScheduledAnim == UNION_ROOM_SPAWN_IN)
|
2019-03-28 16:24:50 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
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);
|
2019-12-10 19:48:20 +01:00
|
|
|
StringCopy(gStringVar4, sText_ID);
|
2020-05-30 10:09:21 +02:00
|
|
|
StringAppend(gStringVar4, trainerId);
|
2021-10-06 05:38:36 +02:00
|
|
|
PrintUnionRoomText(windowId, 1, gStringVar4, GetStringRightAlignXOffset(1, gStringVar4, 0x68), y, colorIdx);
|
2019-03-28 16:24:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
static bool32 IsPlayerFacingTradingBoard(void)
|
2019-03-28 16:24:50 +01:00
|
|
|
{
|
|
|
|
s16 x, y;
|
|
|
|
GetXYCoordsOneStepInFrontOfPlayer(&x, &y);
|
2020-05-30 10:09:21 +02:00
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
if (x != 2 + 7)
|
2019-03-28 16:24:50 +01:00
|
|
|
return FALSE;
|
2020-05-30 10:09:21 +02:00
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
if (y != 1 + 7)
|
2019-03-28 16:24:50 +01:00
|
|
|
return FALSE;
|
2020-05-30 10:09:21 +02:00
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
if (gPlayerAvatar.tileTransitionState == T_TILE_CENTER || gPlayerAvatar.tileTransitionState == T_NOT_MOVING)
|
2019-03-28 16:24:50 +01:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static u32 GetResponseIdx_InviteToURoomActivity(s32 activity)
|
2019-03-28 16:24:50 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
switch (activity)
|
2019-03-28 16:24:50 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_CHAT:
|
2019-03-28 16:24:50 +01:00
|
|
|
return 1;
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_TRADE:
|
2019-03-28 16:24:50 +01:00
|
|
|
return 2;
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_CARD:
|
2019-03-28 16:24:50 +01:00
|
|
|
return 3;
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_BATTLE_MULTI:
|
2019-03-28 16:24:50 +01:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static u32 ConvPartnerUnameAndGetWhetherMetAlready(struct RfuPlayer *player)
|
2019-03-28 16:24:50 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
u8 name[30];
|
2021-10-06 05:38:36 +02:00
|
|
|
CopyAndTranslatePlayerName(name, player);
|
|
|
|
return PlayerHasMetTrainerBefore(ReadAsU16(player->rfu.data.compatibility.playerTrainerId), name);
|
2019-03-28 16:24:50 +01:00
|
|
|
}
|
2019-03-29 16:57:03 +01:00
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static s32 UnionRoomGetPlayerInteractionResponse(struct RfuPlayerList *list, bool8 overrideGender, u8 playerIdx, u32 playerGender)
|
2019-03-29 16:57:03 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
bool32 metBefore;
|
2019-03-29 16:57:03 +01:00
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
struct RfuPlayer * player = &list->players[playerIdx];
|
2019-03-29 16:57:03 +01:00
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
if (!player->rfu.data.startedActivity && !overrideGender)
|
2019-03-29 16:57:03 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
CopyAndTranslatePlayerName(gStringVar1, player);
|
|
|
|
metBefore = PlayerHasMetTrainerBefore(ReadAsU16(player->rfu.data.compatibility.playerTrainerId), gStringVar1);
|
|
|
|
if (player->rfu.data.activity == (ACTIVITY_CHAT | IN_UNION_ROOM))
|
2019-03-29 16:57:03 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
StringExpandPlaceholders(gStringVar4, sJoinChatTexts[metBefore][playerGender]);
|
2019-03-29 16:57:03 +01:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
UR_PrintFieldMessage(sCommunicatingWaitTexts[metBefore]);
|
2019-03-29 16:57:03 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
CopyAndTranslatePlayerName(gStringVar1, player);
|
2020-05-30 10:09:21 +02:00
|
|
|
if (overrideGender)
|
2019-03-29 16:57:03 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
playerGender = (player->rfu.data.compatibility.playerTrainerId[overrideGender + 1] >> 3) & 1;
|
2019-03-29 16:57:03 +01:00
|
|
|
}
|
2021-10-06 05:38:36 +02:00
|
|
|
switch (player->rfu.data.activity & 0x3F)
|
2019-03-29 16:57:03 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_BATTLE_SINGLE:
|
|
|
|
StringExpandPlaceholders(gStringVar4, sBattleReactionTexts[playerGender][Random() % ARRAY_COUNT(sBattleReactionTexts[0])]);
|
2019-03-29 16:57:03 +01:00
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_TRADE:
|
2019-12-10 19:48:20 +01:00
|
|
|
StringExpandPlaceholders(gStringVar4, sTradeReactionTexts[playerGender][Random() % 2]);
|
2019-03-29 16:57:03 +01:00
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_CHAT:
|
|
|
|
StringExpandPlaceholders(gStringVar4, sChatReactionTexts[playerGender][Random() % ARRAY_COUNT(sChatReactionTexts[0])]);
|
2019-03-29 16:57:03 +01:00
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_CARD:
|
|
|
|
StringExpandPlaceholders(gStringVar4, sTrainerCardReactionTexts[playerGender][Random() % ARRAY_COUNT(sTrainerCardReactionTexts[0])]);
|
2019-03-29 16:57:03 +01:00
|
|
|
break;
|
|
|
|
default:
|
2019-10-05 05:31:25 +02:00
|
|
|
StringExpandPlaceholders(gStringVar4, sText_TrainerAppearsBusy);
|
2019-03-29 16:57:03 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2019-03-29 20:50:04 +01:00
|
|
|
|
2021-07-12 02:42:05 +02:00
|
|
|
void ItemPrintFunc_EmptyList(u8 windowId, u32 itemId, u8 y)
|
2019-03-29 20:50:04 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static void TradeBoardPrintItemInfo(u8 windowId, u8 y, struct RfuGameData * data, const u8 * playerName, u8 colorIdx)
|
2019-03-29 20:50:04 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
u8 levelStr[4];
|
2021-10-06 05:38:36 +02:00
|
|
|
u16 species = data->tradeSpecies;
|
|
|
|
u8 type = data->tradeType;
|
|
|
|
u8 level = data->tradeLevel;
|
2019-03-29 20:50:04 +01:00
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
PrintUnionRoomText(windowId, 1, playerName, 8, y, colorIdx);
|
2020-05-30 10:09:21 +02:00
|
|
|
if (species == SPECIES_EGG)
|
2019-03-29 20:50:04 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
PrintUnionRoomText(windowId, 1, sText_EggTrade, 68, y, colorIdx);
|
2019-03-29 20:50:04 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-29 21:34:33 +01:00
|
|
|
BlitMenuInfoIcon(windowId, type + 1, 68, y);
|
2021-10-06 05:38:36 +02:00
|
|
|
PrintUnionRoomText(windowId, 1, gSpeciesNames[species], 118, y, colorIdx);
|
2020-05-30 10:09:21 +02:00
|
|
|
ConvertIntToDecimalStringN(levelStr, level, STR_CONV_MODE_RIGHT_ALIGN, 3);
|
2021-10-06 05:38:36 +02:00
|
|
|
PrintUnionRoomText(windowId, 1, levelStr, 198, y, colorIdx);
|
2019-03-29 20:50:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-18 06:15:45 +02:00
|
|
|
static void TradeBoardListMenuItemPrintFunc(u8 windowId, u32 itemId, u8 y)
|
2019-03-29 20:50:04 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
struct WirelessLink_Leader *leader = sWirelessLinkMain.leader;
|
|
|
|
struct RfuGameData *gameData;
|
2019-03-29 20:50:04 +01:00
|
|
|
s32 i, j;
|
2020-05-30 10:09:21 +02:00
|
|
|
u8 playerName[11];
|
2019-03-29 20:50:04 +01:00
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
if (itemId == LIST_HEADER && y == sTradeBoardListMenuTemplate.upText_Y)
|
2019-03-29 20:50:04 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
gameData = GetHostRfuGameData();
|
|
|
|
if (gameData->tradeSpecies != SPECIES_NONE)
|
|
|
|
TradeBoardPrintItemInfo(windowId, y, gameData, gSaveBlock2Ptr->playerName, UR_COLOR_TRADE_BOARD_SELF);
|
2019-03-29 20:50:04 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
j = 0;
|
2021-10-06 05:38:36 +02:00
|
|
|
for (i = 0; i < MAX_UNION_ROOM_LEADERS; i++)
|
2019-03-29 20:50:04 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (leader->playerList->players[i].groupScheduledAnim == UNION_ROOM_SPAWN_IN && leader->playerList->players[i].rfu.data.tradeSpecies != SPECIES_NONE)
|
2019-03-29 20:50:04 +01:00
|
|
|
j++;
|
2021-10-06 05:38:36 +02:00
|
|
|
|
2019-03-29 20:50:04 +01:00
|
|
|
if (j == itemId + 1)
|
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
CopyAndTranslatePlayerName(playerName, &leader->playerList->players[i]);
|
|
|
|
TradeBoardPrintItemInfo(windowId, y, &leader->playerList->players[i].rfu.data, playerName, UR_COLOR_TRADE_BOARD_OTHER);
|
2019-03-29 20:50:04 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static s32 GetIndexOfNthTradeBoardOffer(struct RfuPlayer * players, s32 n)
|
2019-03-29 20:50:04 +01:00
|
|
|
{
|
|
|
|
s32 i;
|
|
|
|
s32 j = 0;
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
for (i = 0; i < MAX_UNION_ROOM_LEADERS; i++)
|
2019-03-29 20:50:04 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (players[i].groupScheduledAnim == UNION_ROOM_SPAWN_IN && players[i].rfu.data.tradeSpecies != SPECIES_NONE)
|
2019-03-29 20:50:04 +01:00
|
|
|
j++;
|
2021-10-06 05:38:36 +02:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
if (j == n + 1)
|
2019-03-29 20:50:04 +01:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2019-03-29 21:24:48 +01:00
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static s32 GetUnionRoomPlayerGender(s32 playerIdx, struct RfuPlayerList *list)
|
2019-03-29 21:24:48 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
return list->players[playerIdx].rfu.data.playerGender;
|
2019-03-29 21:24:48 +01:00
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static s32 IsRequestedTypeOrEggInPlayerParty(u32 type, u32 species)
|
2019-03-29 21:24:48 +01:00
|
|
|
{
|
|
|
|
s32 i;
|
|
|
|
|
|
|
|
if (species == SPECIES_EGG)
|
|
|
|
{
|
|
|
|
for (i = 0; i < gPlayerPartyCount; i++)
|
|
|
|
{
|
|
|
|
species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2);
|
|
|
|
if (species == SPECIES_EGG)
|
2020-05-30 10:09:21 +02:00
|
|
|
return UR_TRADE_MATCH;
|
2019-03-29 21:24:48 +01:00
|
|
|
}
|
2020-05-30 10:09:21 +02:00
|
|
|
return UR_TRADE_NOEGG;
|
2019-03-29 21:24:48 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < gPlayerPartyCount; i++)
|
|
|
|
{
|
|
|
|
species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2);
|
|
|
|
if (gBaseStats[species].type1 == type || gBaseStats[species].type2 == type)
|
2020-05-30 10:09:21 +02:00
|
|
|
return UR_TRADE_MATCH;
|
2019-03-29 21:24:48 +01:00
|
|
|
}
|
2020-05-30 10:09:21 +02:00
|
|
|
return UR_TRADE_NOTYPE;
|
2019-03-29 21:24:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void GetURoomActivityRejectMsg(u8 *dst, s32 acitivty, u32 playerGender)
|
2019-03-29 21:24:48 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
switch (acitivty)
|
2019-03-29 21:24:48 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_BATTLE_SINGLE | IN_UNION_ROOM:
|
2019-12-10 19:48:20 +01:00
|
|
|
StringExpandPlaceholders(dst, sBattleDeclinedTexts[playerGender]);
|
2019-03-29 21:24:48 +01:00
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_CHAT | IN_UNION_ROOM:
|
2019-12-10 19:48:20 +01:00
|
|
|
StringExpandPlaceholders(dst, sChatDeclinedTexts[playerGender]);
|
2019-03-29 21:24:48 +01:00
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_TRADE | IN_UNION_ROOM:
|
2019-10-05 05:31:25 +02:00
|
|
|
StringExpandPlaceholders(dst, sText_TradeOfferRejected);
|
2019-03-29 21:24:48 +01:00
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_CARD | IN_UNION_ROOM:
|
2019-12-10 19:48:20 +01:00
|
|
|
StringExpandPlaceholders(dst, sShowTrainerCardDeclinedTexts[playerGender]);
|
2019-03-29 21:24:48 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void GetURoomActivityStartMsg(u8 *dst, u8 acitivty)
|
2019-03-29 21:24:48 +01:00
|
|
|
{
|
|
|
|
u8 mpId = GetMultiplayerId();
|
|
|
|
u8 gender = gLinkPlayers[mpId ^ 1].gender;
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
switch (acitivty)
|
2019-03-29 21:24:48 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_BATTLE_SINGLE | IN_UNION_ROOM:
|
2019-12-10 19:48:20 +01:00
|
|
|
StringCopy(dst, sStartActivityTexts[mpId][gender][0]);
|
2019-03-29 21:24:48 +01:00
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_TRADE | IN_UNION_ROOM:
|
2019-12-10 19:48:20 +01:00
|
|
|
StringCopy(dst, sStartActivityTexts[mpId][gender][2]);
|
2019-03-29 21:24:48 +01:00
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_CHAT | IN_UNION_ROOM:
|
2019-12-10 19:48:20 +01:00
|
|
|
StringCopy(dst, sStartActivityTexts[mpId][gender][1]);
|
2019-03-29 21:24:48 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-03-29 22:19:29 +01:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static s32 GetChatLeaderActionRequestMessage(u8 *dst, u32 gender, u16 *activityData, struct WirelessLink_URoom *uroom)
|
2019-03-29 22:19:29 +01:00
|
|
|
{
|
|
|
|
s32 result = 0;
|
|
|
|
u16 species = SPECIES_NONE;
|
|
|
|
s32 i;
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
switch (activityData[0])
|
2019-03-29 22:19:29 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_BATTLE_SINGLE | IN_UNION_ROOM:
|
2019-10-05 05:31:25 +02:00
|
|
|
StringExpandPlaceholders(dst, sText_BattleChallenge);
|
2019-03-29 22:19:29 +01:00
|
|
|
result = 1;
|
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_CHAT | IN_UNION_ROOM:
|
2019-10-05 05:31:25 +02:00
|
|
|
StringExpandPlaceholders(dst, sText_ChatInvitation);
|
2019-03-29 22:19:29 +01:00
|
|
|
result = 1;
|
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_TRADE | IN_UNION_ROOM:
|
|
|
|
ConvertIntToDecimalStringN(uroom->activityRequestStrbufs[0], sUnionRoomTrade.playerLevel, STR_CONV_MODE_LEFT_ALIGN, 3);
|
|
|
|
StringCopy(uroom->activityRequestStrbufs[1], gSpeciesNames[sUnionRoomTrade.playerSpecies]);
|
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
2019-03-29 22:19:29 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (gRfuLinkStatus->partner[i].serialNo == RFU_SERIAL_GAME)
|
2019-03-29 22:19:29 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
ConvertIntToDecimalStringN(uroom->activityRequestStrbufs[2], activityData[2], STR_CONV_MODE_LEFT_ALIGN, 3);
|
|
|
|
StringCopy(uroom->activityRequestStrbufs[3], gSpeciesNames[activityData[1]]);
|
|
|
|
species = activityData[1];
|
2019-03-29 22:19:29 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (species == SPECIES_EGG)
|
|
|
|
{
|
2019-10-05 05:31:25 +02:00
|
|
|
StringCopy(dst, sText_OfferToTradeEgg);
|
2019-03-29 22:19:29 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
|
|
|
DynamicPlaceholderTextUtil_SetPlaceholderPtr(i, uroom->activityRequestStrbufs[i]);
|
2019-10-05 05:31:25 +02:00
|
|
|
DynamicPlaceholderTextUtil_ExpandPlaceholders(dst, sText_OfferToTradeMon);
|
2019-03-29 22:19:29 +01:00
|
|
|
}
|
|
|
|
result = 1;
|
|
|
|
break;
|
2020-05-30 10:09:21 +02:00
|
|
|
case ACTIVITY_CARD | IN_UNION_ROOM:
|
2019-10-05 05:31:25 +02:00
|
|
|
StringExpandPlaceholders(dst, sText_ShowTrainerCard);
|
2019-03-29 22:19:29 +01:00
|
|
|
result = 1;
|
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case ACTIVITY_NONE | IN_UNION_ROOM:
|
2019-10-05 05:31:25 +02:00
|
|
|
StringExpandPlaceholders(dst, sText_ChatDropped);
|
2019-03-29 22:19:29 +01:00
|
|
|
result = 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2019-03-30 00:41:32 +01:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static bool32 PollPartnerYesNoResponse(struct WirelessLink_URoom *data)
|
2019-03-30 00:41:32 +01:00
|
|
|
{
|
|
|
|
if (gRecvCmds[0][1] != 0)
|
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
if (gRecvCmds[0][1] == (ACTIVITY_ACCEPT | IN_UNION_ROOM))
|
2019-03-30 00:41:32 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
data->partnerYesNoResponse = ACTIVITY_ACCEPT | IN_UNION_ROOM;
|
2019-03-30 00:41:32 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
2020-05-30 10:09:21 +02:00
|
|
|
else if (gRecvCmds[0][1] == (ACTIVITY_DECLINE | IN_UNION_ROOM))
|
2019-03-30 00:41:32 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
data->partnerYesNoResponse = ACTIVITY_DECLINE | IN_UNION_ROOM;
|
2019-03-30 00:41:32 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool32 InUnionRoom(void)
|
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
return gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(UNION_ROOM)
|
|
|
|
&& gSaveBlock1Ptr->location.mapNum == MAP_NUM(UNION_ROOM)
|
|
|
|
? TRUE : FALSE;
|
2019-03-30 00:41:32 +01:00
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static bool32 HasAtLeastTwoMonsOfLevel30OrLower(void)
|
2019-03-30 00:41:32 +01:00
|
|
|
{
|
|
|
|
s32 i;
|
|
|
|
s32 count = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < gPlayerPartyCount; i++)
|
|
|
|
{
|
2019-10-05 05:31:25 +02:00
|
|
|
if (GetMonData(&gPlayerParty[i], MON_DATA_LEVEL) <= 30
|
2021-10-06 05:38:36 +02:00
|
|
|
&& GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2) != SPECIES_EGG)
|
2019-03-30 00:41:32 +01:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count > 1)
|
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static void ResetUnionRoomTrade(struct UnionRoomTrade *trade)
|
2019-03-30 00:41:32 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
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;
|
2019-03-30 00:41:32 +01:00
|
|
|
}
|
|
|
|
|
2019-10-05 05:31:25 +02:00
|
|
|
void Script_ResetUnionRoomTrade(void)
|
2019-03-30 00:41:32 +01:00
|
|
|
{
|
2019-10-05 05:31:25 +02:00
|
|
|
ResetUnionRoomTrade(&sUnionRoomTrade);
|
2019-03-30 00:41:32 +01:00
|
|
|
}
|
|
|
|
|
2019-10-05 05:31:25 +02:00
|
|
|
static bool32 RegisterTradeMonAndGetIsEgg(u32 monId, struct UnionRoomTrade *trade)
|
2019-03-30 00:41:32 +01:00
|
|
|
{
|
2019-10-05 05:31:25 +02:00
|
|
|
trade->playerSpecies = GetMonData(&gPlayerParty[monId], MON_DATA_SPECIES2);
|
|
|
|
trade->playerLevel = GetMonData(&gPlayerParty[monId], MON_DATA_LEVEL);
|
|
|
|
trade->playerPersonality = GetMonData(&gPlayerParty[monId], MON_DATA_PERSONALITY);
|
|
|
|
if (trade->playerSpecies == SPECIES_EGG)
|
2019-03-30 00:41:32 +01:00
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-10-05 05:31:25 +02:00
|
|
|
static void RegisterTradeMon(u32 monId, struct UnionRoomTrade *trade)
|
2019-03-30 00:41:32 +01:00
|
|
|
{
|
2019-10-05 05:31:25 +02:00
|
|
|
trade->species = GetMonData(&gPlayerParty[monId], MON_DATA_SPECIES2);
|
|
|
|
trade->level = GetMonData(&gPlayerParty[monId], MON_DATA_LEVEL);
|
|
|
|
trade->personality = GetMonData(&gPlayerParty[monId], MON_DATA_PERSONALITY);
|
2019-03-30 00:41:32 +01:00
|
|
|
}
|
2019-03-30 03:22:26 +01:00
|
|
|
|
2019-10-05 05:31:25 +02:00
|
|
|
static u32 GetPartyPositionOfRegisteredMon(struct UnionRoomTrade *trade, u8 multiplayerId)
|
2019-03-30 03:22:26 +01:00
|
|
|
{
|
|
|
|
u16 response = 0;
|
|
|
|
u16 species;
|
|
|
|
u32 personality;
|
|
|
|
u32 cur_personality;
|
|
|
|
u16 cur_species;
|
|
|
|
s32 i;
|
|
|
|
|
|
|
|
if (multiplayerId == 0)
|
|
|
|
{
|
2019-10-05 05:31:25 +02:00
|
|
|
species = trade->playerSpecies;
|
|
|
|
personality = trade->playerPersonality;
|
2019-03-30 03:22:26 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-05 05:31:25 +02:00
|
|
|
species = trade->species;
|
|
|
|
personality = trade->personality;
|
2019-03-30 03:22:26 +01:00
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
// Find party position by comparing to personality and species
|
2019-03-30 03:22:26 +01:00
|
|
|
for (i = 0; i < gPlayerPartyCount; i++)
|
|
|
|
{
|
|
|
|
cur_personality = GetMonData(&gPlayerParty[i], MON_DATA_PERSONALITY);
|
|
|
|
if (cur_personality != personality)
|
|
|
|
continue;
|
|
|
|
cur_species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2);
|
|
|
|
if (cur_species != species)
|
|
|
|
continue;
|
|
|
|
response = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
static void HandleCancelActivity(bool32 setData)
|
2019-03-30 03:22:26 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
UR_ClearBg0();
|
2019-03-30 03:22:26 +01:00
|
|
|
ScriptContext2_Disable();
|
2020-05-30 10:09:21 +02:00
|
|
|
UnionRoom_UnlockPlayerAndChatPartner();
|
2020-06-09 00:16:57 +02:00
|
|
|
gPlayerCurrActivity = ACTIVITY_NONE;
|
|
|
|
if (setData)
|
2019-03-30 03:22:26 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
SetTradeBoardRegisteredMonInfo(sUnionRoomTrade.type, sUnionRoomTrade.playerSpecies, sUnionRoomTrade.playerLevel);
|
2020-06-09 00:16:57 +02:00
|
|
|
UpdateGameData_SetActivity(ACTIVITY_NONE | IN_UNION_ROOM, 0, FALSE);
|
2019-03-30 03:22:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static void StartScriptInteraction(void)
|
2019-03-30 03:22:26 +01:00
|
|
|
{
|
|
|
|
ScriptContext2_Enable();
|
2021-05-04 07:21:50 +02:00
|
|
|
FreezeObjects_WaitForPlayer();
|
2019-03-30 03:22:26 +01:00
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static u8 GetActivePartnersInfo(struct WirelessLink_URoom *data)
|
2019-03-30 03:22:26 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
u8 retVal = PINFO_ACTIVE_FLAG;
|
2019-03-30 03:22:26 +01:00
|
|
|
u8 i;
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
2019-03-30 03:22:26 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (data->incomingParentList->players[i].active)
|
2019-03-30 03:22:26 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
retVal |= data->incomingParentList->players[i].rfu.data.playerGender << PINFO_GENDER_SHIFT;
|
|
|
|
retVal |= data->incomingParentList->players[i].rfu.data.compatibility.playerTrainerId[0] & PINFO_TID_MASK;
|
2019-03-30 03:22:26 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
2019-03-30 14:18:58 +01:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
static void ViewURoomPartnerTrainerCard(u8 *unused, struct WirelessLink_URoom *data, bool8 isParent)
|
2019-03-30 14:18:58 +01:00
|
|
|
{
|
|
|
|
struct TrainerCard *trainerCard = &gTrainerCards[GetMultiplayerId() ^ 1];
|
|
|
|
s32 i;
|
|
|
|
s32 n;
|
|
|
|
|
|
|
|
DynamicPlaceholderTextUtil_Reset();
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
StringCopy(data->trainerCardStrBuffer[0], gTrainerClassNames[GetUnionRoomTrainerClass()]);
|
|
|
|
DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, data->trainerCardStrBuffer[0]);
|
2019-03-30 14:18:58 +01:00
|
|
|
|
|
|
|
DynamicPlaceholderTextUtil_SetPlaceholderPtr(1, trainerCard->playerName);
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
StringCopy(data->trainerCardColorStrBuffer, sCardColorTexts[trainerCard->stars]);
|
|
|
|
DynamicPlaceholderTextUtil_SetPlaceholderPtr(2, data->trainerCardColorStrBuffer);
|
2019-03-30 14:18:58 +01:00
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
ConvertIntToDecimalStringN(data->trainerCardStrBuffer[2], trainerCard->caughtMonsCount, STR_CONV_MODE_LEFT_ALIGN, 3);
|
|
|
|
DynamicPlaceholderTextUtil_SetPlaceholderPtr(3, data->trainerCardStrBuffer[2]);
|
2019-03-30 14:18:58 +01:00
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
ConvertIntToDecimalStringN(data->trainerCardStrBuffer[3], trainerCard->playTimeHours, STR_CONV_MODE_LEFT_ALIGN, 3);
|
|
|
|
ConvertIntToDecimalStringN(data->trainerCardStrBuffer[4], trainerCard->playTimeMinutes, STR_CONV_MODE_LEADING_ZEROS, 2);
|
|
|
|
DynamicPlaceholderTextUtil_SetPlaceholderPtr(4, data->trainerCardStrBuffer[3]);
|
|
|
|
DynamicPlaceholderTextUtil_SetPlaceholderPtr(5, data->trainerCardStrBuffer[4]);
|
2019-03-30 14:18:58 +01:00
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
DynamicPlaceholderTextUtil_ExpandPlaceholders(data->trainerCardMsgStrBuffer, sText_TrainerCardInfoPage1);
|
|
|
|
StringCopy(gStringVar4, data->trainerCardMsgStrBuffer);
|
2019-03-30 14:18:58 +01:00
|
|
|
|
|
|
|
n = trainerCard->linkBattleWins;
|
|
|
|
if (n > 9999)
|
|
|
|
n = 9999;
|
2020-06-09 00:16:57 +02:00
|
|
|
ConvertIntToDecimalStringN(data->trainerCardStrBuffer[0], n, STR_CONV_MODE_LEFT_ALIGN, 4);
|
|
|
|
DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, data->trainerCardStrBuffer[0]);
|
2019-03-30 14:18:58 +01:00
|
|
|
|
|
|
|
n = trainerCard->linkBattleLosses;
|
|
|
|
if (n > 9999)
|
|
|
|
n = 9999;
|
2020-06-09 00:16:57 +02:00
|
|
|
ConvertIntToDecimalStringN(data->trainerCardStrBuffer[1], n, STR_CONV_MODE_LEFT_ALIGN, 4);
|
|
|
|
DynamicPlaceholderTextUtil_SetPlaceholderPtr(2, data->trainerCardStrBuffer[1]);
|
2019-03-30 14:18:58 +01:00
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
ConvertIntToDecimalStringN(data->trainerCardStrBuffer[2], trainerCard->pokemonTrades, STR_CONV_MODE_LEFT_ALIGN, 5);
|
|
|
|
DynamicPlaceholderTextUtil_SetPlaceholderPtr(3, data->trainerCardStrBuffer[2]);
|
2019-03-30 14:18:58 +01:00
|
|
|
|
2020-02-07 18:48:47 +01:00
|
|
|
for (i = 0; i < TRAINER_CARD_PROFILE_LENGTH; i++)
|
2019-03-30 14:18:58 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
CopyEasyChatWord(data->trainerCardStrBuffer[i + 3], trainerCard->easyChatProfile[i]);
|
|
|
|
DynamicPlaceholderTextUtil_SetPlaceholderPtr(i + 4, data->trainerCardStrBuffer[i + 3]);
|
2019-03-30 14:18:58 +01:00
|
|
|
}
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
DynamicPlaceholderTextUtil_ExpandPlaceholders(data->trainerCardMsgStrBuffer, sText_TrainerCardInfoPage2);
|
|
|
|
StringAppend(gStringVar4, data->trainerCardMsgStrBuffer);
|
2019-03-30 14:18:58 +01:00
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
if (isParent == TRUE)
|
2019-03-30 14:18:58 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
DynamicPlaceholderTextUtil_ExpandPlaceholders(data->trainerCardMsgStrBuffer, sText_FinishedCheckingPlayersTrainerCard);
|
|
|
|
StringAppend(gStringVar4, data->trainerCardMsgStrBuffer);
|
2019-03-30 14:18:58 +01:00
|
|
|
}
|
2020-05-30 10:09:21 +02:00
|
|
|
else if (isParent == FALSE)
|
2019-03-30 14:18:58 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
DynamicPlaceholderTextUtil_ExpandPlaceholders(data->trainerCardMsgStrBuffer, sGladToMeetYouTexts[trainerCard->gender]);
|
|
|
|
StringAppend(gStringVar4, data->trainerCardMsgStrBuffer);
|
2019-03-30 14:18:58 +01:00
|
|
|
}
|
|
|
|
}
|
2019-03-30 14:23:47 +01:00
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
static void CopyAndTranslatePlayerName(u8 *dest, struct RfuPlayer *player)
|
2019-03-30 14:23:47 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
StringCopy7(dest, player->rfu.name);
|
|
|
|
ConvertInternationalString(dest, player->rfu.data.compatibility.language);
|
2019-03-30 14:23:47 +01:00
|
|
|
}
|