2018-12-19 02:29:41 +01:00
|
|
|
#include "global.h"
|
2019-09-09 03:07:54 +02:00
|
|
|
#include "malloc.h"
|
2018-12-21 19:20:28 +01:00
|
|
|
#include "battle_anim.h"
|
2018-12-24 10:03:02 +01:00
|
|
|
#include "battle_interface.h"
|
2018-12-19 02:29:41 +01:00
|
|
|
#include "bg.h"
|
|
|
|
#include "cable_club.h"
|
2019-04-04 23:53:06 +02:00
|
|
|
#include "data.h"
|
2018-12-23 08:26:38 +01:00
|
|
|
#include "daycare.h"
|
2018-12-27 09:05:09 +01:00
|
|
|
#include "decompress.h"
|
2018-12-21 19:20:28 +01:00
|
|
|
#include "event_data.h"
|
2018-12-28 09:11:41 +01:00
|
|
|
#include "evolution_scene.h"
|
2018-12-29 19:46:15 +01:00
|
|
|
#include "field_screen_effect.h"
|
2018-12-19 02:29:41 +01:00
|
|
|
#include "gpu_regs.h"
|
|
|
|
#include "graphics.h"
|
|
|
|
#include "international_string_util.h"
|
|
|
|
#include "librfu.h"
|
|
|
|
#include "link.h"
|
|
|
|
#include "link_rfu.h"
|
2018-12-29 19:46:15 +01:00
|
|
|
#include "load_save.h"
|
2018-12-27 09:05:09 +01:00
|
|
|
#include "mail.h"
|
2018-12-19 02:29:41 +01:00
|
|
|
#include "main.h"
|
2019-03-30 19:36:52 +01:00
|
|
|
#include "mystery_gift.h"
|
2021-10-17 09:00:48 +02:00
|
|
|
#include "mystery_gift_menu.h"
|
2018-12-21 19:20:28 +01:00
|
|
|
#include "overworld.h"
|
2018-12-19 02:29:41 +01:00
|
|
|
#include "palette.h"
|
|
|
|
#include "party_menu.h"
|
2018-12-28 09:11:41 +01:00
|
|
|
#include "pokeball.h"
|
2018-12-27 09:05:09 +01:00
|
|
|
#include "pokedex.h"
|
2018-12-19 02:29:41 +01:00
|
|
|
#include "pokemon_icon.h"
|
2018-12-21 19:20:28 +01:00
|
|
|
#include "pokemon_summary_screen.h"
|
2019-01-26 20:56:06 +01:00
|
|
|
#include "pokemon_storage_system.h"
|
2018-12-29 19:46:15 +01:00
|
|
|
#include "random.h"
|
|
|
|
#include "save.h"
|
|
|
|
#include "script.h"
|
2018-12-19 02:29:41 +01:00
|
|
|
#include "sound.h"
|
|
|
|
#include "string_util.h"
|
2018-12-28 09:11:41 +01:00
|
|
|
#include "strings.h"
|
2018-12-19 02:29:41 +01:00
|
|
|
#include "task.h"
|
|
|
|
#include "text.h"
|
|
|
|
#include "text_window.h"
|
|
|
|
#include "trainer_card.h"
|
|
|
|
#include "trade.h"
|
2019-03-30 19:36:52 +01:00
|
|
|
#include "union_room.h"
|
2018-12-27 09:05:09 +01:00
|
|
|
#include "util.h"
|
2018-12-19 02:29:41 +01:00
|
|
|
#include "window.h"
|
2019-10-03 07:16:22 +02:00
|
|
|
#include "constants/contest.h"
|
2018-12-28 09:11:41 +01:00
|
|
|
#include "constants/items.h"
|
2018-12-22 08:26:53 +01:00
|
|
|
#include "constants/moves.h"
|
2019-10-03 07:16:22 +02:00
|
|
|
#include "constants/region_map_sections.h"
|
|
|
|
#include "constants/rgb.h"
|
2018-12-19 02:29:41 +01:00
|
|
|
#include "constants/songs.h"
|
2020-05-30 10:09:21 +02:00
|
|
|
#include "constants/union_room.h"
|
2018-12-19 02:29:41 +01:00
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
// IDs for RunTradeMenuCallback
|
|
|
|
enum {
|
|
|
|
CB_MAIN_MENU,
|
|
|
|
CB_SELECTED_MON,
|
|
|
|
CB_SHOW_MON_SUMMARY,
|
|
|
|
CB_CONFIRM_TRADE_PROMPT,
|
|
|
|
CB_CANCEL_TRADE_PROMPT,
|
|
|
|
CB_READY_WAIT, // Unused in Emerald, equivalent to CB_IDLE
|
|
|
|
CB_SET_SELECTED_MONS,
|
|
|
|
CB_PRINT_IS_THIS_OKAY,
|
|
|
|
CB_HANDLE_TRADE_CANCELED,
|
|
|
|
CB_FADE_TO_START_TRADE,
|
|
|
|
CB_WAIT_TO_START_TRADE,
|
|
|
|
CB_INIT_EXIT_CANCELED_TRADE,
|
|
|
|
CB_EXIT_CANCELED_TRADE,
|
|
|
|
CB_START_LINK_TRADE,
|
|
|
|
CB_INIT_CONFIRM_TRADE_PROMPT,
|
|
|
|
CB_UNUSED_CLOSE_MSG,
|
|
|
|
CB_WAIT_TO_START_RFU_TRADE,
|
|
|
|
CB_PARTNER_MON_INVALID,
|
|
|
|
CB_IDLE = 100,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Indexes for sActionTexts
|
|
|
|
enum {
|
|
|
|
TEXT_CANCEL,
|
|
|
|
TEXT_CHOOSE_MON,
|
|
|
|
TEXT_SUMMARY,
|
|
|
|
TEXT_TRADE,
|
|
|
|
TEXT_CANCEL_TRADE,
|
|
|
|
TEXT_JP_QUIT,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Indexes for sMessages
|
|
|
|
enum {
|
|
|
|
MSG_STANDBY,
|
|
|
|
MSG_CANCELED,
|
|
|
|
MSG_ONLY_MON1,
|
|
|
|
MSG_ONLY_MON2,
|
|
|
|
MSG_WAITING_FOR_FRIEND,
|
|
|
|
MSG_FRIEND_WANTS_TO_TRADE,
|
|
|
|
MSG_MON_CANT_BE_TRADED,
|
|
|
|
MSG_EGG_CANT_BE_TRADED,
|
|
|
|
MSG_FRIENDS_MON_CANT_BE_TRADED,
|
|
|
|
};
|
|
|
|
|
|
|
|
// IDs for QueueAction
|
|
|
|
enum {
|
|
|
|
QUEUE_SEND_DATA,
|
|
|
|
QUEUE_STANDBY,
|
|
|
|
QUEUE_ONLY_MON1,
|
|
|
|
QUEUE_ONLY_MON2,
|
|
|
|
QUEUE_UNUSED1, // Presumably intended for MSG_WAITING_FOR_FRIEND
|
|
|
|
QUEUE_UNUSED2, // Presumably intended for MSG_FRIEND_WANTS_TO_TRADE
|
|
|
|
QUEUE_MON_CANT_BE_TRADED,
|
|
|
|
QUEUE_EGG_CANT_BE_TRADED,
|
|
|
|
QUEUE_FRIENDS_MON_CANT_BE_TRADED,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define QUEUE_DELAY_MSG 3
|
|
|
|
#define QUEUE_DELAY_DATA 5
|
|
|
|
|
2021-04-19 02:12:12 +02:00
|
|
|
// The following tags are offsets from GFXTAG_MENU_TEXT
|
|
|
|
// They're looped over in CB2_CreateTradeMenu and CB2_ReturnToTradeMenu
|
|
|
|
// and used as indexes into sMenuTextTileBuffers
|
|
|
|
enum {
|
|
|
|
GFXTAG_PLAYER_NAME_L,
|
|
|
|
GFXTAG_PLAYER_NAME_M,
|
|
|
|
GFXTAG_PLAYER_NAME_R,
|
|
|
|
GFXTAG_PARTNER_NAME_L,
|
|
|
|
GFXTAG_PARTNER_NAME_M,
|
|
|
|
GFXTAG_PARTNER_NAME_R,
|
|
|
|
GFXTAG_CANCEL_L,
|
|
|
|
GFXTAG_CANCEL_R,
|
|
|
|
GFXTAG_CHOOSE_PKMN_L,
|
|
|
|
GFXTAG_CHOOSE_PKMN_M,
|
|
|
|
GFXTAG_CHOOSE_PKMN_R,
|
|
|
|
GFXTAG_CHOOSE_PKMN_EMPTY_1, // 6 sprites to cover the full bottom bar, but only first 3 are needed
|
|
|
|
GFXTAG_CHOOSE_PKMN_EMPTY_2,
|
|
|
|
GFXTAG_CHOOSE_PKMN_EMPTY_3,
|
2022-12-09 18:34:55 +01:00
|
|
|
NUM_MENU_TEXT_SPRITES
|
2021-04-19 02:12:12 +02:00
|
|
|
};
|
2022-12-09 18:34:55 +01:00
|
|
|
#define NUM_PLAYER_NAME_SPRITES (1 + GFXTAG_PLAYER_NAME_R - GFXTAG_PLAYER_NAME_L)
|
|
|
|
#define NUM_PARTNER_NAME_SPRITES (1 + GFXTAG_PARTNER_NAME_R - GFXTAG_PARTNER_NAME_L)
|
|
|
|
#define NUM_CHOOSE_PKMN_SPRITES (1 + GFXTAG_CHOOSE_PKMN_EMPTY_3 - GFXTAG_CHOOSE_PKMN_L)
|
|
|
|
|
|
|
|
// Values for signaling to/from the link partner
|
|
|
|
enum {
|
|
|
|
STATUS_NONE,
|
|
|
|
STATUS_READY,
|
|
|
|
STATUS_CANCEL,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Checked to confirm DrawSelectedMonScreen has reached final state
|
|
|
|
#define DRAW_SELECTED_FINISH 5
|
2018-12-29 19:46:15 +01:00
|
|
|
|
2018-12-28 09:11:41 +01:00
|
|
|
struct InGameTrade {
|
2022-12-15 22:00:53 +01:00
|
|
|
u8 nickname[POKEMON_NAME_LENGTH + 1];
|
|
|
|
u16 species;
|
|
|
|
u8 ivs[NUM_STATS];
|
|
|
|
u8 abilityNum;
|
|
|
|
u32 otId;
|
|
|
|
u8 conditions[CONTEST_CATEGORIES_COUNT];
|
|
|
|
u32 personality;
|
|
|
|
u16 heldItem;
|
|
|
|
u8 mailNum;
|
|
|
|
u8 otName[11];
|
|
|
|
u8 otGender;
|
|
|
|
u8 sheen;
|
|
|
|
u16 requestedSpecies;
|
2018-12-28 09:11:41 +01:00
|
|
|
};
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static EWRAM_DATA u8 *sMenuTextTileBuffer = NULL;
|
2019-10-05 16:41:37 +02:00
|
|
|
|
2021-04-19 02:12:12 +02:00
|
|
|
// Bytes 0-2 are used for the player's name text
|
|
|
|
// Bytes 3-5 are used for the partner's name text
|
|
|
|
// Bytes 6-7 are used for the Cancel text
|
|
|
|
// Bytes 8-13 are used for the Choose a Pokemon text
|
|
|
|
// See the corresponding GFXTAGs in src/data/trade.h
|
2022-12-09 18:34:55 +01:00
|
|
|
static EWRAM_DATA u8 *sMenuTextTileBuffers[NUM_MENU_TEXT_SPRITES] = {NULL};
|
2019-10-05 16:41:37 +02:00
|
|
|
|
2021-10-23 16:55:46 +02:00
|
|
|
EWRAM_DATA struct Mail gTradeMail[PARTY_SIZE] = {0};
|
2019-10-04 01:39:37 +02:00
|
|
|
EWRAM_DATA u8 gSelectedTradeMonPositions[2] = {0};
|
2018-12-31 08:23:27 +01:00
|
|
|
static EWRAM_DATA struct {
|
2022-12-09 18:34:55 +01:00
|
|
|
u8 bg2hofs;
|
|
|
|
u8 bg3hofs;
|
|
|
|
u8 filler_2[38];
|
|
|
|
u8 partySpriteIds[2][PARTY_SIZE];
|
|
|
|
u8 cursorSpriteId;
|
|
|
|
u8 cursorPosition;
|
|
|
|
u8 partyCounts[2];
|
|
|
|
bool8 optionsActive[PARTY_SIZE * 2 + 1];
|
|
|
|
bool8 isLiveMon[2][PARTY_SIZE];
|
|
|
|
bool8 isEgg[2][PARTY_SIZE];
|
|
|
|
u8 hpBarLevels[2][PARTY_SIZE];
|
|
|
|
u8 bufferPartyState;
|
|
|
|
u8 filler_6A[5];
|
|
|
|
u8 callbackId;
|
|
|
|
u8 neverRead_70;
|
|
|
|
u16 bottomTextTileStart;
|
|
|
|
u8 drawSelectedMonState[2];
|
|
|
|
u8 selectedMonIdx[2];
|
|
|
|
u8 playerSelectStatus;
|
|
|
|
u8 partnerSelectStatus;
|
|
|
|
u8 playerConfirmStatus;
|
|
|
|
u8 partnerConfirmStatus;
|
|
|
|
u8 filler_7C[2];
|
|
|
|
u8 partnerCursorPosition;
|
|
|
|
u16 linkData[20];
|
|
|
|
u8 timer;
|
|
|
|
u8 giftRibbons[GIFT_RIBBONS_COUNT];
|
|
|
|
u8 filler_B4[0x81C];
|
|
|
|
struct {
|
|
|
|
bool8 active;
|
|
|
|
u16 delay;
|
2019-10-07 04:58:25 +02:00
|
|
|
u8 actionId;
|
|
|
|
} queuedActions[4];
|
2022-12-09 18:34:55 +01:00
|
|
|
u16 tilemapBuffer[BG_SCREEN_SIZE / 2];
|
|
|
|
} *sTradeMenu = NULL;
|
2021-04-19 02:12:12 +02:00
|
|
|
|
2018-12-31 08:23:27 +01:00
|
|
|
static EWRAM_DATA struct {
|
2022-12-15 22:00:53 +01:00
|
|
|
struct Pokemon tempMon; // Used as a temp variable when swapping Pokémon
|
|
|
|
u32 timer;
|
|
|
|
u32 monPersonalities[2];
|
|
|
|
u8 filler_70[2];
|
|
|
|
u8 playerFinishStatus;
|
|
|
|
u8 partnerFinishStatus;
|
|
|
|
u16 linkData[10];
|
|
|
|
u8 linkTimeoutZero1;
|
|
|
|
u8 linkTimeoutZero2;
|
|
|
|
u16 linkTimeoutTimer;
|
|
|
|
u16 neverRead_8C;
|
|
|
|
u8 monSpriteIds[2];
|
|
|
|
u8 connectionSpriteId1; // Multi-purpose sprite ids used during the transfer sequence
|
|
|
|
u8 connectionSpriteId2;
|
|
|
|
u8 cableEndSpriteId;
|
|
|
|
u8 scheduleLinkTransfer;
|
|
|
|
u16 state;
|
|
|
|
u8 filler_96[0x3C];
|
|
|
|
u8 releasePokeballSpriteId;
|
|
|
|
u8 bouncingPokeballSpriteId;
|
|
|
|
u16 texX;
|
|
|
|
u16 texY;
|
|
|
|
u16 neverRead_D8;
|
|
|
|
u16 neverRead_DA;
|
|
|
|
u16 scrX;
|
|
|
|
u16 scrY;
|
|
|
|
s16 bg1vofs;
|
|
|
|
s16 bg1hofs;
|
|
|
|
s16 bg2vofs;
|
|
|
|
s16 bg2hofs;
|
|
|
|
u16 sXY;
|
|
|
|
u16 gbaScale;
|
|
|
|
u16 alpha;
|
|
|
|
bool8 isLinkTrade;
|
|
|
|
u16 monSpecies[2];
|
|
|
|
u16 cachedMapMusic;
|
|
|
|
u8 textColors[3];
|
|
|
|
u8 filler_F9;
|
|
|
|
bool8 isCableTrade;
|
|
|
|
u8 wirelessWinLeft;
|
|
|
|
u8 wirelessWinTop;
|
|
|
|
u8 wirelessWinRight;
|
|
|
|
u8 wirelessWinBottom;
|
|
|
|
} *sTradeAnim = NULL;
|
2018-12-31 08:23:27 +01:00
|
|
|
|
2019-10-04 13:42:45 +02:00
|
|
|
static bool32 IsWirelessTrade(void);
|
2019-10-09 11:56:44 +02:00
|
|
|
static void CB2_CreateTradeMenu(void);
|
|
|
|
static void VBlankCB_TradeMenu(void);
|
2019-10-07 04:58:25 +02:00
|
|
|
static void CB2_TradeMenu(void);
|
2019-10-09 11:56:44 +02:00
|
|
|
static void LoadTradeBgGfx(u8);
|
2022-12-09 18:34:55 +01:00
|
|
|
static void SetActiveMenuOptions(void);
|
2019-10-09 15:55:06 +02:00
|
|
|
static bool8 BufferTradeParties(void);
|
2022-12-09 18:34:55 +01:00
|
|
|
static void CB1_UpdateLink(void);
|
|
|
|
static void RunTradeMenuCallback(void);
|
2019-10-04 01:39:37 +02:00
|
|
|
static void SetSelectedMon(u8);
|
2022-12-09 18:34:55 +01:00
|
|
|
static void DrawSelectedMonScreen(u8);
|
2019-10-07 04:58:25 +02:00
|
|
|
static u8 GetMonNicknameWidth(u8 *, u8, u8);
|
2022-12-09 18:34:55 +01:00
|
|
|
static void BufferMovesString(u8 *, u8, u8);
|
|
|
|
static void PrintPartyNicknames(u8);
|
|
|
|
static void PrintLevelAndGender(u8, u8, u8, u8, u8, u8);
|
|
|
|
static void PrintPartyLevelsAndGenders(u8);
|
|
|
|
static void PrintTradePartnerPartyNicknames(void);
|
|
|
|
static void RedrawPartyWindow(u8);
|
2021-04-19 02:12:12 +02:00
|
|
|
static void Task_DrawSelectionSummary(u8);
|
|
|
|
static void Task_DrawSelectionTrade(u8);
|
2019-10-07 04:58:25 +02:00
|
|
|
static void QueueAction(u16, u8);
|
|
|
|
static u32 GetNumQueuedActions(void);
|
|
|
|
static void DoQueuedActions(void);
|
2019-10-04 01:39:37 +02:00
|
|
|
static void PrintTradeMessage(u8);
|
2022-12-09 18:34:55 +01:00
|
|
|
static bool8 LoadUISpriteGfx(void);
|
2021-04-19 02:12:12 +02:00
|
|
|
static void DrawBottomRowText(const u8 *, u8 *, u8);
|
2022-12-09 18:34:55 +01:00
|
|
|
static void ComputePartyTradeableFlags(u8);
|
|
|
|
static void ComputePartyHPBarLevels(u8);
|
2019-10-04 01:39:37 +02:00
|
|
|
static void SetTradePartyHPBarSprites(void);
|
2019-10-09 11:56:44 +02:00
|
|
|
static void SaveTradeGiftRibbons(void);
|
2019-10-07 04:58:25 +02:00
|
|
|
static u32 CanTradeSelectedMon(struct Pokemon *, int, int);
|
2021-04-19 02:12:12 +02:00
|
|
|
static void SpriteCB_LinkMonGlow(struct Sprite *);
|
|
|
|
static void SpriteCB_LinkMonShadow(struct Sprite *);
|
|
|
|
static void SpriteCB_CableEndSending(struct Sprite *);
|
|
|
|
static void SpriteCB_CableEndReceiving(struct Sprite *);
|
|
|
|
static void SpriteCB_GbaScreen(struct Sprite *);
|
2022-12-15 22:00:53 +01:00
|
|
|
static void TradeAnimInit_LoadGfx(void);
|
|
|
|
static void CB2_InGameTrade(void);
|
2019-10-09 15:55:06 +02:00
|
|
|
static void SetTradeSequenceBgGpuRegs(u8);
|
2019-10-05 16:41:37 +02:00
|
|
|
static void LoadTradeSequenceSpriteSheetsAndPalettes(void);
|
2019-10-09 15:55:06 +02:00
|
|
|
static void BufferTradeSceneStrings(void);
|
2022-12-15 22:00:53 +01:00
|
|
|
static bool8 DoTradeAnim(void);
|
|
|
|
static bool8 DoTradeAnim_Cable(void);
|
|
|
|
static bool8 DoTradeAnim_Wireless(void);
|
2021-04-19 02:12:12 +02:00
|
|
|
static void SpriteCB_BouncingPokeball(struct Sprite *);
|
|
|
|
static void SpriteCB_BouncingPokeballDepart(struct Sprite *);
|
|
|
|
static void SpriteCB_BouncingPokeballDepartEnd(struct Sprite *);
|
|
|
|
static void SpriteCB_BouncingPokeballArrive(struct Sprite *);
|
2020-01-08 19:19:41 +01:00
|
|
|
static void BufferInGameTradeMonName(void);
|
2022-12-15 22:00:53 +01:00
|
|
|
static void GetInGameTradeMail(struct Mail *, const struct InGameTrade *);
|
2019-10-09 15:55:06 +02:00
|
|
|
static void CB2_UpdateLinkTrade(void);
|
2022-12-15 22:00:53 +01:00
|
|
|
static void CB2_WaitTradeComplete(void);
|
2019-10-09 15:55:06 +02:00
|
|
|
static void CB2_SaveAndEndTrade(void);
|
2022-12-15 22:00:53 +01:00
|
|
|
static void CB2_FreeTradeAnim(void);
|
2019-10-04 13:42:45 +02:00
|
|
|
static void Task_InGameTrade(u8);
|
2019-10-04 01:39:37 +02:00
|
|
|
static void CheckPartnersMonForRibbons(void);
|
2019-10-09 15:55:06 +02:00
|
|
|
static void Task_AnimateWirelessSignal(u8);
|
2022-12-15 22:00:53 +01:00
|
|
|
static void Task_OpenCenterWhiteColumn(u8);
|
|
|
|
static void Task_CloseCenterWhiteColumn(u8);
|
2019-10-09 15:55:06 +02:00
|
|
|
static void CB2_SaveAndEndWirelessTrade(void);
|
2018-12-31 08:23:27 +01:00
|
|
|
|
2019-10-03 07:16:22 +02:00
|
|
|
#include "data/trade.h"
|
2018-12-28 09:11:41 +01:00
|
|
|
|
2019-10-04 01:39:37 +02:00
|
|
|
static bool8 SendLinkData(const void *linkData, u32 size)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
if (gPlayerCurrActivity == ACTIVITY_29)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2020-02-16 19:49:36 +01:00
|
|
|
rfu_NI_setSendData(lman.acceptSlot_flag, 84, linkData, size);
|
2018-12-19 02:29:41 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-04 01:39:37 +02:00
|
|
|
return SendBlock(0, linkData, size);
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-13 09:09:47 +02:00
|
|
|
static void RequestLinkData(u8 type)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2020-08-13 09:09:47 +02:00
|
|
|
SendBlockRequest(type);
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
|
|
|
|
2021-04-19 02:12:12 +02:00
|
|
|
static bool32 IsLinkTradeTaskFinished(void)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
if (gPlayerCurrActivity == ACTIVITY_29)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
if (gRfuSlotStatusNI[Rfu_GetIndexOfNewestChild(lman.acceptSlot_flag)]->send.state == 0)
|
2018-12-19 02:29:41 +01:00
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-31 09:22:21 +01:00
|
|
|
return IsLinkTaskFinished();
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 09:22:21 +01:00
|
|
|
static u32 _GetBlockReceivedStatus(void)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
|
|
|
return GetBlockReceivedStatus();
|
|
|
|
}
|
|
|
|
|
2019-10-04 13:42:45 +02:00
|
|
|
static void TradeResetReceivedFlags(void)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2019-10-04 13:42:45 +02:00
|
|
|
if (IsWirelessTrade())
|
2020-02-16 19:49:36 +01:00
|
|
|
rfu_clearSlot(12, lman.acceptSlot_flag);
|
2018-12-19 02:29:41 +01:00
|
|
|
else
|
|
|
|
ResetBlockReceivedFlags();
|
|
|
|
}
|
|
|
|
|
2019-10-04 13:42:45 +02:00
|
|
|
static void TradeResetReceivedFlag(u32 who)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2019-10-04 13:42:45 +02:00
|
|
|
if (IsWirelessTrade())
|
2020-02-16 19:49:36 +01:00
|
|
|
rfu_clearSlot(12, lman.acceptSlot_flag);
|
2018-12-19 02:29:41 +01:00
|
|
|
else
|
2019-10-04 13:42:45 +02:00
|
|
|
ResetBlockReceivedFlag(who);
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
|
|
|
|
2019-10-04 13:42:45 +02:00
|
|
|
static bool32 IsWirelessTrade(void)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
if (gWirelessCommType && gPlayerCurrActivity == ACTIVITY_29)
|
2018-12-19 02:29:41 +01:00
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-08-13 09:09:47 +02:00
|
|
|
static void SetTradeLinkStandbyCallback(u8 unused)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2020-08-13 09:09:47 +02:00
|
|
|
SetLinkStandbyCallback();
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
|
|
|
|
2018-12-31 09:22:21 +01:00
|
|
|
static bool32 _IsLinkTaskFinished(void)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2018-12-31 09:22:21 +01:00
|
|
|
return IsLinkTaskFinished();
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
|
|
|
|
2019-10-04 13:42:45 +02:00
|
|
|
static void InitTradeMenu(void)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
|
|
|
ResetSpriteData();
|
|
|
|
FreeAllSpritePalettes();
|
|
|
|
ResetTasks();
|
|
|
|
ResetPaletteFade();
|
|
|
|
|
|
|
|
gPaletteFade.bufferTransferDisabled = TRUE;
|
|
|
|
|
2019-10-09 11:56:44 +02:00
|
|
|
SetVBlankCallback(VBlankCB_TradeMenu);
|
2022-08-19 17:32:00 +02:00
|
|
|
LoadPalette(gStandardMenuPalette, BG_PLTT_ID(15), PLTT_SIZEOF(10));
|
|
|
|
LoadPalette(gStandardMenuPalette, BG_PLTT_ID(13), PLTT_SIZEOF(10));
|
2018-12-19 02:29:41 +01:00
|
|
|
ResetBgsAndClearDma3BusyFlags(0);
|
2022-12-09 18:34:55 +01:00
|
|
|
InitBgsFromTemplates(0, sBgTemplates, ARRAY_COUNT(sBgTemplates));
|
|
|
|
SetBgTilemapBuffer(1, sTradeMenu->tilemapBuffer);
|
2018-12-19 02:29:41 +01:00
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
if (InitWindows(sWindowTemplates))
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
|
|
|
u32 i;
|
|
|
|
|
|
|
|
DeactivateAllTextPrinters();
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
for (i = 0; i < ARRAY_COUNT(sWindowTemplates) - 1; i++)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
|
|
|
ClearWindowTilemap(i);
|
2019-03-02 23:25:39 +01:00
|
|
|
FillWindowPixelBuffer(i, PIXEL_FILL(0));
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
|
|
|
|
2022-09-26 18:22:27 +02:00
|
|
|
FillBgTilemapBufferRect(0, 0, 0, 0, DISPLAY_TILE_WIDTH, DISPLAY_TILE_HEIGHT, 15);
|
2022-08-19 17:32:00 +02:00
|
|
|
LoadUserWindowBorderGfx_(0, 20, BG_PLTT_ID(12));
|
|
|
|
LoadUserWindowBorderGfx(2, 1, BG_PLTT_ID(14));
|
2018-12-19 02:29:41 +01:00
|
|
|
LoadMonIconPalettes();
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->bufferPartyState = 0;
|
|
|
|
sTradeMenu->callbackId = CB_MAIN_MENU;
|
|
|
|
sTradeMenu->neverRead_70 = 0;
|
|
|
|
sTradeMenu->drawSelectedMonState[TRADE_PLAYER] = 0;
|
|
|
|
sTradeMenu->drawSelectedMonState[TRADE_PARTNER] = 0;
|
|
|
|
sTradeMenu->playerConfirmStatus = STATUS_NONE;
|
|
|
|
sTradeMenu->partnerConfirmStatus = STATUS_NONE;
|
|
|
|
sTradeMenu->timer = 0;
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-09 11:56:44 +02:00
|
|
|
void CB2_StartCreateTradeMenu(void)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2019-10-09 11:56:44 +02:00
|
|
|
SetMainCallback2(CB2_CreateTradeMenu);
|
2018-12-19 02:29:41 +01:00
|
|
|
gMain.callback1 = NULL;
|
|
|
|
gEnemyPartyCount = 0;
|
|
|
|
}
|
|
|
|
|
2019-10-09 11:56:44 +02:00
|
|
|
static void CB2_CreateTradeMenu(void)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct SpriteTemplate temp;
|
|
|
|
u8 id;
|
|
|
|
u32 xPos;
|
|
|
|
|
|
|
|
switch (gMain.state)
|
|
|
|
{
|
|
|
|
case 0:
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu = AllocZeroed(sizeof(*sTradeMenu));
|
2019-10-04 13:42:45 +02:00
|
|
|
InitTradeMenu();
|
2022-12-09 18:34:55 +01:00
|
|
|
sMenuTextTileBuffer = AllocZeroed(NUM_MENU_TEXT_SPRITES * 256);
|
2018-12-25 15:14:15 +01:00
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
for (i = 0; i < NUM_MENU_TEXT_SPRITES; i++)
|
|
|
|
sMenuTextTileBuffers[i] = &sMenuTextTileBuffer[i * 256];
|
2018-12-19 02:29:41 +01:00
|
|
|
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
gPaletteFade.bufferTransferDisabled = FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i < PARTY_SIZE; i++)
|
2021-01-07 23:13:14 +01:00
|
|
|
CreateMon(&gEnemyParty[i], SPECIES_NONE, 0, USE_RANDOM_IVS, FALSE, 0, OT_ID_PLAYER_ID, 0);
|
2018-12-19 02:29:41 +01:00
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
PrintTradeMessage(MSG_STANDBY);
|
2018-12-19 02:29:41 +01:00
|
|
|
ShowBg(0);
|
|
|
|
|
2018-12-31 09:22:21 +01:00
|
|
|
if (!gReceivedRemoteLinkPlayers)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2020-06-04 00:00:53 +02:00
|
|
|
gLinkType = LINKTYPE_TRADE_CONNECTING;
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->timer = 0;
|
2018-12-19 02:29:41 +01:00
|
|
|
|
2018-12-31 09:22:21 +01:00
|
|
|
if (gWirelessCommType)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
SetWirelessCommType1();
|
2018-12-19 02:29:41 +01:00
|
|
|
OpenLink();
|
2020-06-06 22:46:19 +02:00
|
|
|
CreateTask_RfuIdle();
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OpenLink();
|
|
|
|
gMain.state++;
|
2020-06-04 00:00:53 +02:00
|
|
|
CreateTask(Task_WaitForLinkPlayerConnection, 1);
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gMain.state = 4;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->timer++;
|
|
|
|
if (sTradeMenu->timer > 11)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->timer = 0;
|
2018-12-19 02:29:41 +01:00
|
|
|
gMain.state++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
2019-02-11 02:42:50 +01:00
|
|
|
if (GetLinkPlayerCount_2() >= GetSavedPlayerCount())
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
|
|
|
if (IsLinkMaster())
|
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
if (++sTradeMenu->timer > 30)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2019-02-11 02:42:50 +01:00
|
|
|
CheckShouldAdvanceLinkState();
|
2018-12-19 02:29:41 +01:00
|
|
|
gMain.state++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gMain.state++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
2018-12-31 09:22:21 +01:00
|
|
|
if (gReceivedRemoteLinkPlayers == TRUE && IsLinkPlayerDataExchangeComplete() == TRUE)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
DestroyTask_RfuIdle();
|
2018-12-19 02:29:41 +01:00
|
|
|
CalculatePlayerPartyCount();
|
|
|
|
gMain.state++;
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->timer = 0;
|
2018-12-31 09:22:21 +01:00
|
|
|
if (gWirelessCommType)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2021-08-16 00:26:09 +02:00
|
|
|
Rfu_SetLinkRecovery(TRUE);
|
2020-08-13 09:09:47 +02:00
|
|
|
SetLinkStandbyCallback();
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 5:
|
2018-12-31 09:22:21 +01:00
|
|
|
if (gWirelessCommType)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2019-10-09 11:56:44 +02:00
|
|
|
if (IsLinkRfuTaskFinished())
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
|
|
|
gMain.state++;
|
2019-04-04 23:05:46 +02:00
|
|
|
LoadWirelessStatusIndicatorSpriteGfx();
|
2018-12-19 02:29:41 +01:00
|
|
|
CreateWirelessStatusIndicatorSprite(0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gMain.state++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 6:
|
2019-10-09 15:55:06 +02:00
|
|
|
if (BufferTradeParties())
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2019-10-09 11:56:44 +02:00
|
|
|
SaveTradeGiftRibbons();
|
2018-12-19 02:29:41 +01:00
|
|
|
gMain.state++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
CalculateEnemyPartyCount();
|
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, 0);
|
|
|
|
SetGpuReg(REG_OFFSET_BLDCNT, 0);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->partyCounts[TRADE_PLAYER] = gPlayerPartyCount;
|
|
|
|
sTradeMenu->partyCounts[TRADE_PARTNER] = gEnemyPartyCount;
|
2018-12-19 02:29:41 +01:00
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
for (i = 0; i < sTradeMenu->partyCounts[TRADE_PLAYER]; i++)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
|
|
|
struct Pokemon *mon = &gPlayerParty[i];
|
2023-02-24 11:53:02 +01:00
|
|
|
sTradeMenu->partySpriteIds[TRADE_PLAYER][i] = CreateMonIcon(GetMonData(mon, MON_DATA_SPECIES_OR_EGG),
|
2019-10-31 19:11:55 +01:00
|
|
|
SpriteCB_MonIcon,
|
2019-10-11 00:46:42 +02:00
|
|
|
(sTradeMonSpriteCoords[i][0] * 8) + 14,
|
|
|
|
(sTradeMonSpriteCoords[i][1] * 8) - 12,
|
2018-12-19 02:29:41 +01:00
|
|
|
1,
|
|
|
|
GetMonData(mon, MON_DATA_PERSONALITY),
|
|
|
|
TRUE);
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
for (i = 0; i < sTradeMenu->partyCounts[TRADE_PARTNER]; i++)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
|
|
|
struct Pokemon *mon = &gEnemyParty[i];
|
2023-02-24 11:53:02 +01:00
|
|
|
sTradeMenu->partySpriteIds[TRADE_PARTNER][i] = CreateMonIcon(GetMonData(mon, MON_DATA_SPECIES_OR_EGG, NULL),
|
2019-10-31 19:11:55 +01:00
|
|
|
SpriteCB_MonIcon,
|
2019-10-11 00:46:42 +02:00
|
|
|
(sTradeMonSpriteCoords[i + PARTY_SIZE][0] * 8) + 14,
|
|
|
|
(sTradeMonSpriteCoords[i + PARTY_SIZE][1] * 8) - 12,
|
2018-12-19 02:29:41 +01:00
|
|
|
1,
|
|
|
|
GetMonData(mon, MON_DATA_PERSONALITY),
|
|
|
|
FALSE);
|
|
|
|
}
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 8:
|
2018-12-25 22:03:13 +01:00
|
|
|
LoadHeldItemIcons();
|
2022-12-09 18:34:55 +01:00
|
|
|
DrawHeldItemIconsForTrade(&sTradeMenu->partyCounts[0], sTradeMenu->partySpriteIds[0], TRADE_PLAYER);
|
2018-12-19 02:29:41 +01:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 9:
|
2022-12-09 18:34:55 +01:00
|
|
|
DrawHeldItemIconsForTrade(&sTradeMenu->partyCounts[0], sTradeMenu->partySpriteIds[0], TRADE_PARTNER);
|
2018-12-19 02:29:41 +01:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 10:
|
2021-04-19 02:12:12 +02:00
|
|
|
DrawTextWindowAndBufferTiles(gSaveBlock2Ptr->playerName, sMenuTextTileBuffers[GFXTAG_PLAYER_NAME_L], 0, 0, 3);
|
2018-12-19 02:29:41 +01:00
|
|
|
id = GetMultiplayerId();
|
2021-04-19 02:12:12 +02:00
|
|
|
DrawTextWindowAndBufferTiles(gLinkPlayers[id ^ 1].name, sMenuTextTileBuffers[GFXTAG_PARTNER_NAME_L], 0, 0, 3);
|
2022-12-09 18:34:55 +01:00
|
|
|
DrawTextWindowAndBufferTiles(sActionTexts[TEXT_CANCEL], sMenuTextTileBuffers[GFXTAG_CANCEL_L], 0, 0, 2);
|
|
|
|
DrawBottomRowText(sActionTexts[TEXT_CHOOSE_MON], sMenuTextTileBuffers[GFXTAG_CHOOSE_PKMN_L], 24);
|
2018-12-19 02:29:41 +01:00
|
|
|
gMain.state++;
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->timer = 0;
|
2018-12-19 02:29:41 +01:00
|
|
|
break;
|
|
|
|
case 11:
|
2022-12-09 18:34:55 +01:00
|
|
|
if (LoadUISpriteGfx())
|
2018-12-19 02:29:41 +01:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 12:
|
2021-04-19 02:12:12 +02:00
|
|
|
// Create player's name text sprites
|
2021-10-30 22:47:37 +02:00
|
|
|
xPos = GetStringCenterAlignXOffset(FONT_NORMAL, gSaveBlock2Ptr->playerName, 120);
|
2022-12-09 18:34:55 +01:00
|
|
|
for (i = 0; i < NUM_PLAYER_NAME_SPRITES; i++)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2021-04-19 02:12:12 +02:00
|
|
|
temp = sSpriteTemplate_MenuText;
|
|
|
|
temp.tileTag += i + GFXTAG_PLAYER_NAME_L;
|
2018-12-19 02:29:41 +01:00
|
|
|
CreateSprite(&temp, xPos + (i * 32) + 16, 10, 1);
|
|
|
|
}
|
|
|
|
|
2021-04-19 02:12:12 +02:00
|
|
|
// Create partner's name text sprites
|
2021-10-30 22:47:37 +02:00
|
|
|
xPos = GetStringCenterAlignXOffset(FONT_NORMAL, gLinkPlayers[GetMultiplayerId() ^ 1].name, 120);
|
2022-12-09 18:34:55 +01:00
|
|
|
for (i = 0; i < NUM_PARTNER_NAME_SPRITES; i++)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2021-04-19 02:12:12 +02:00
|
|
|
temp = sSpriteTemplate_MenuText;
|
|
|
|
temp.tileTag += i + GFXTAG_PARTNER_NAME_L;
|
2018-12-19 02:29:41 +01:00
|
|
|
CreateSprite(&temp, xPos + (i * 32) + 136, 10, 1);
|
|
|
|
}
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 13:
|
2021-04-19 02:12:12 +02:00
|
|
|
// Create Cancel text sprites
|
|
|
|
temp = sSpriteTemplate_MenuText;
|
|
|
|
temp.tileTag += GFXTAG_CANCEL_L;
|
2018-12-19 02:29:41 +01:00
|
|
|
CreateSprite(&temp, 215, 152, 1);
|
2021-04-19 02:12:12 +02:00
|
|
|
temp = sSpriteTemplate_MenuText;
|
|
|
|
temp.tileTag += GFXTAG_CANCEL_R;
|
2022-12-09 18:34:55 +01:00
|
|
|
CreateSprite(&temp, 215 + 32, 152, 1);
|
2018-12-19 02:29:41 +01:00
|
|
|
|
2021-04-19 02:12:12 +02:00
|
|
|
// Create Choose a Pokémon text sprites (only 3 are needed, other 3 are empty)
|
2022-12-09 18:34:55 +01:00
|
|
|
for (i = 0; i < NUM_CHOOSE_PKMN_SPRITES; i++)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2021-04-19 02:12:12 +02:00
|
|
|
temp = sSpriteTemplate_MenuText;
|
|
|
|
temp.tileTag += i + GFXTAG_CHOOSE_PKMN_L;
|
2018-12-19 02:29:41 +01:00
|
|
|
CreateSprite(&temp, (i * 32) + 24, 150, 1);
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->cursorSpriteId = CreateSprite(&sSpriteTemplate_Cursor, sTradeMonSpriteCoords[0][0] * 8 + 32, sTradeMonSpriteCoords[0][1] * 8, 2);
|
|
|
|
sTradeMenu->cursorPosition = 0;
|
2018-12-19 02:29:41 +01:00
|
|
|
gMain.state++;
|
|
|
|
rbox_fill_rectangle(0);
|
|
|
|
break;
|
|
|
|
case 14:
|
2022-12-09 18:34:55 +01:00
|
|
|
ComputePartyTradeableFlags(TRADE_PLAYER);
|
|
|
|
PrintPartyNicknames(TRADE_PLAYER);
|
|
|
|
sTradeMenu->bg2hofs = 0;
|
|
|
|
sTradeMenu->bg3hofs = 0;
|
|
|
|
SetActiveMenuOptions();
|
2018-12-19 02:29:41 +01:00
|
|
|
gMain.state++;
|
2020-08-21 00:02:00 +02:00
|
|
|
PlayBGM(MUS_SCHOOL);
|
2018-12-19 02:29:41 +01:00
|
|
|
break;
|
|
|
|
case 15:
|
2022-12-09 18:34:55 +01:00
|
|
|
ComputePartyTradeableFlags(TRADE_PARTNER);
|
|
|
|
PrintPartyNicknames(TRADE_PARTNER);
|
2018-12-19 02:29:41 +01:00
|
|
|
gMain.state++;
|
2018-12-31 08:23:27 +01:00
|
|
|
// fallthrough
|
|
|
|
case 16:
|
2019-10-09 11:56:44 +02:00
|
|
|
LoadTradeBgGfx(0);
|
2018-12-19 02:29:41 +01:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 17:
|
2019-10-09 11:56:44 +02:00
|
|
|
LoadTradeBgGfx(1);
|
2018-12-19 02:29:41 +01:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 18:
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK);
|
2018-12-19 02:29:41 +01:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 19:
|
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_1D_MAP | DISPCNT_OBJ_ON);
|
2019-10-09 11:56:44 +02:00
|
|
|
LoadTradeBgGfx(2);
|
2018-12-19 02:29:41 +01:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 20:
|
2022-12-09 18:34:55 +01:00
|
|
|
ComputePartyHPBarLevels(TRADE_PLAYER);
|
2018-12-19 02:29:41 +01:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 21:
|
2022-12-09 18:34:55 +01:00
|
|
|
ComputePartyHPBarLevels(TRADE_PARTNER);
|
2019-10-04 01:39:37 +02:00
|
|
|
SetTradePartyHPBarSprites();
|
2018-12-19 02:29:41 +01:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 22:
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
gMain.callback1 = CB1_UpdateLink;
|
2019-10-07 04:58:25 +02:00
|
|
|
SetMainCallback2(CB2_TradeMenu);
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
RunTextPrinters();
|
|
|
|
RunTasks();
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
|
|
|
UpdatePaletteFade();
|
|
|
|
}
|
|
|
|
|
2019-10-09 11:56:44 +02:00
|
|
|
static void CB2_ReturnToTradeMenu(void)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct SpriteTemplate temp;
|
|
|
|
u8 id;
|
|
|
|
u32 xPos;
|
|
|
|
|
|
|
|
switch (gMain.state)
|
|
|
|
{
|
|
|
|
case 0:
|
2019-10-04 13:42:45 +02:00
|
|
|
InitTradeMenu();
|
2018-12-19 02:29:41 +01:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
gMain.state++;
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->timer = 0;
|
2018-12-19 02:29:41 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
CalculatePlayerPartyCount();
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 5:
|
2018-12-31 09:22:21 +01:00
|
|
|
if (gWirelessCommType)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2019-04-04 23:05:46 +02:00
|
|
|
LoadWirelessStatusIndicatorSpriteGfx();
|
2018-12-19 02:29:41 +01:00
|
|
|
CreateWirelessStatusIndicatorSprite(0, 0);
|
|
|
|
}
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
CalculateEnemyPartyCount();
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->partyCounts[TRADE_PLAYER] = gPlayerPartyCount;
|
|
|
|
sTradeMenu->partyCounts[TRADE_PARTNER] = gEnemyPartyCount;
|
2018-12-19 02:29:41 +01:00
|
|
|
ClearWindowTilemap(0);
|
2022-12-09 18:34:55 +01:00
|
|
|
PrintPartyNicknames(TRADE_PLAYER);
|
|
|
|
PrintPartyNicknames(TRADE_PARTNER);
|
2018-12-19 02:29:41 +01:00
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
for (i = 0; i < sTradeMenu->partyCounts[TRADE_PLAYER]; i++)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
|
|
|
struct Pokemon *mon = &gPlayerParty[i];
|
2023-02-24 11:53:02 +01:00
|
|
|
sTradeMenu->partySpriteIds[TRADE_PLAYER][i] = CreateMonIcon(GetMonData(mon, MON_DATA_SPECIES_OR_EGG, NULL),
|
2019-10-31 19:11:55 +01:00
|
|
|
SpriteCB_MonIcon,
|
2019-10-11 00:46:42 +02:00
|
|
|
(sTradeMonSpriteCoords[i][0] * 8) + 14,
|
|
|
|
(sTradeMonSpriteCoords[i][1] * 8) - 12,
|
2018-12-19 02:29:41 +01:00
|
|
|
1,
|
|
|
|
GetMonData(mon, MON_DATA_PERSONALITY),
|
|
|
|
TRUE);
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
for (i = 0; i < sTradeMenu->partyCounts[TRADE_PARTNER]; i++)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
|
|
|
struct Pokemon *mon = &gEnemyParty[i];
|
2023-02-24 11:53:02 +01:00
|
|
|
sTradeMenu->partySpriteIds[TRADE_PARTNER][i] = CreateMonIcon(GetMonData(mon, MON_DATA_SPECIES_OR_EGG, NULL),
|
2019-10-31 19:11:55 +01:00
|
|
|
SpriteCB_MonIcon,
|
2019-10-11 00:46:42 +02:00
|
|
|
(sTradeMonSpriteCoords[i + PARTY_SIZE][0] * 8) + 14,
|
|
|
|
(sTradeMonSpriteCoords[i + PARTY_SIZE][1] * 8) - 12,
|
2018-12-19 02:29:41 +01:00
|
|
|
1,
|
|
|
|
GetMonData(mon, MON_DATA_PERSONALITY),
|
|
|
|
FALSE);
|
|
|
|
}
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 8:
|
2018-12-25 22:03:13 +01:00
|
|
|
LoadHeldItemIcons();
|
2022-12-09 18:34:55 +01:00
|
|
|
DrawHeldItemIconsForTrade(&sTradeMenu->partyCounts[0], sTradeMenu->partySpriteIds[0], TRADE_PLAYER);
|
2018-12-19 02:29:41 +01:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 9:
|
2022-12-09 18:34:55 +01:00
|
|
|
DrawHeldItemIconsForTrade(&sTradeMenu->partyCounts[0], sTradeMenu->partySpriteIds[0], TRADE_PARTNER);
|
2018-12-19 02:29:41 +01:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 10:
|
2021-04-19 02:12:12 +02:00
|
|
|
DrawTextWindowAndBufferTiles(gSaveBlock2Ptr->playerName, sMenuTextTileBuffers[GFXTAG_PLAYER_NAME_L], 0, 0, 3);
|
2018-12-19 02:29:41 +01:00
|
|
|
id = GetMultiplayerId();
|
2021-04-19 02:12:12 +02:00
|
|
|
DrawTextWindowAndBufferTiles(gLinkPlayers[id ^ 1].name, sMenuTextTileBuffers[GFXTAG_PARTNER_NAME_L], 0, 0, 3);
|
2022-12-09 18:34:55 +01:00
|
|
|
DrawTextWindowAndBufferTiles(sActionTexts[TEXT_CANCEL], sMenuTextTileBuffers[GFXTAG_CANCEL_L], 0, 0, 2);
|
|
|
|
DrawBottomRowText(sActionTexts[TEXT_CHOOSE_MON], sMenuTextTileBuffers[GFXTAG_CHOOSE_PKMN_L], 24);
|
2018-12-19 02:29:41 +01:00
|
|
|
gMain.state++;
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->timer = 0;
|
2018-12-19 02:29:41 +01:00
|
|
|
break;
|
|
|
|
case 11:
|
2022-12-09 18:34:55 +01:00
|
|
|
if (LoadUISpriteGfx())
|
2018-12-19 02:29:41 +01:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 12:
|
2021-04-19 02:12:12 +02:00
|
|
|
// Create player's name text sprites
|
2021-10-30 22:47:37 +02:00
|
|
|
xPos = GetStringCenterAlignXOffset(FONT_NORMAL, gSaveBlock2Ptr->playerName, 120);
|
2022-12-09 18:34:55 +01:00
|
|
|
for (i = 0; i < NUM_PLAYER_NAME_SPRITES; i++)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2021-04-19 02:12:12 +02:00
|
|
|
temp = sSpriteTemplate_MenuText;
|
|
|
|
temp.tileTag += i + GFXTAG_PLAYER_NAME_L;
|
2018-12-19 02:29:41 +01:00
|
|
|
CreateSprite(&temp, xPos + (i * 32) + 16, 10, 1);
|
|
|
|
}
|
|
|
|
|
2021-04-19 02:12:12 +02:00
|
|
|
// Create partner's name text sprites
|
2021-10-30 22:47:37 +02:00
|
|
|
xPos = GetStringCenterAlignXOffset(FONT_NORMAL, gLinkPlayers[GetMultiplayerId() ^ 1].name, 120);
|
2022-12-09 18:34:55 +01:00
|
|
|
for (i = 0; i < NUM_PARTNER_NAME_SPRITES; i++)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2021-04-19 02:12:12 +02:00
|
|
|
temp = sSpriteTemplate_MenuText;
|
|
|
|
temp.tileTag += i + GFXTAG_PARTNER_NAME_L;
|
2018-12-19 02:29:41 +01:00
|
|
|
CreateSprite(&temp, xPos + (i * 32) + 136, 10, 1);
|
|
|
|
}
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 13:
|
2021-04-19 02:12:12 +02:00
|
|
|
// Create Cancel text sprites
|
|
|
|
temp = sSpriteTemplate_MenuText;
|
|
|
|
temp.tileTag += GFXTAG_CANCEL_L;
|
2018-12-19 02:29:41 +01:00
|
|
|
CreateSprite(&temp, 215, 152, 1);
|
2021-04-19 02:12:12 +02:00
|
|
|
temp = sSpriteTemplate_MenuText;
|
|
|
|
temp.tileTag += GFXTAG_CANCEL_R;
|
2022-12-09 18:34:55 +01:00
|
|
|
CreateSprite(&temp, 215 + 32, 152, 1);
|
2018-12-19 02:29:41 +01:00
|
|
|
|
2021-04-19 02:12:12 +02:00
|
|
|
// Create Choose a Pokémon text sprites
|
2022-12-09 18:34:55 +01:00
|
|
|
for (i = 0; i < NUM_CHOOSE_PKMN_SPRITES; i++)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2021-04-19 02:12:12 +02:00
|
|
|
temp = sSpriteTemplate_MenuText;
|
|
|
|
temp.tileTag += i + GFXTAG_CHOOSE_PKMN_L;
|
2018-12-19 02:29:41 +01:00
|
|
|
CreateSprite(&temp, (i * 32) + 24, 150, 1);
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
if (sTradeMenu->cursorPosition < PARTY_SIZE)
|
|
|
|
sTradeMenu->cursorPosition = gLastViewedMonIndex;
|
2018-12-19 02:29:41 +01:00
|
|
|
else
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->cursorPosition = gLastViewedMonIndex + PARTY_SIZE;
|
2018-12-19 02:29:41 +01:00
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->cursorSpriteId = CreateSprite(&sSpriteTemplate_Cursor,
|
|
|
|
sTradeMonSpriteCoords[sTradeMenu->cursorPosition][0] * 8 + 32,
|
|
|
|
sTradeMonSpriteCoords[sTradeMenu->cursorPosition][1] * 8, 2);
|
2018-12-19 02:29:41 +01:00
|
|
|
gMain.state = 16;
|
|
|
|
break;
|
|
|
|
case 16:
|
2019-10-09 11:56:44 +02:00
|
|
|
LoadTradeBgGfx(0);
|
2018-12-19 02:29:41 +01:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 17:
|
2019-10-09 11:56:44 +02:00
|
|
|
LoadTradeBgGfx(1);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->bg2hofs = 0;
|
|
|
|
sTradeMenu->bg3hofs = 0;
|
|
|
|
SetActiveMenuOptions();
|
2018-12-19 02:29:41 +01:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 18:
|
|
|
|
gPaletteFade.bufferTransferDisabled = FALSE;
|
2021-02-24 17:01:02 +01:00
|
|
|
BlendPalettes(PALETTES_ALL, 16, RGB_BLACK);
|
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK);
|
2018-12-19 02:29:41 +01:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 19:
|
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_1D_MAP | DISPCNT_OBJ_ON);
|
2019-10-09 11:56:44 +02:00
|
|
|
LoadTradeBgGfx(2);
|
2018-12-19 02:29:41 +01:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 20:
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 21:
|
2019-10-04 01:39:37 +02:00
|
|
|
SetTradePartyHPBarSprites();
|
2018-12-19 02:29:41 +01:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 22:
|
|
|
|
if (!gPaletteFade.active)
|
2019-10-07 04:58:25 +02:00
|
|
|
SetMainCallback2(CB2_TradeMenu);
|
2018-12-19 02:29:41 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
RunTasks();
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
|
|
|
UpdatePaletteFade();
|
|
|
|
}
|
|
|
|
|
2019-10-09 11:56:44 +02:00
|
|
|
static void VBlankCB_TradeMenu(void)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
|
|
|
LoadOam();
|
|
|
|
ProcessSpriteCopyRequests();
|
|
|
|
TransferPlttBuffer();
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void CB_FadeToStartTrade(void)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
if (++sTradeMenu->timer > 15)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->callbackId = CB_WAIT_TO_START_TRADE;
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void CB_WaitToStartTrade(void)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
gSelectedTradeMonPositions[TRADE_PLAYER] = sTradeMenu->cursorPosition;
|
|
|
|
gSelectedTradeMonPositions[TRADE_PARTNER] = sTradeMenu->partnerCursorPosition;
|
2018-12-19 02:29:41 +01:00
|
|
|
|
2018-12-31 09:22:21 +01:00
|
|
|
if (gWirelessCommType)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->callbackId = CB_WAIT_TO_START_RFU_TRADE;
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-13 09:09:47 +02:00
|
|
|
SetCloseLinkCallbackAndType(32);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->callbackId = CB_START_LINK_TRADE;
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void CB_StartLinkTrade(void)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2019-10-09 11:56:44 +02:00
|
|
|
gMain.savedCallback = CB2_StartCreateTradeMenu;
|
2018-12-19 02:29:41 +01:00
|
|
|
|
2018-12-31 09:22:21 +01:00
|
|
|
if (gWirelessCommType)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
// Wireless Link Trade
|
2019-10-09 11:56:44 +02:00
|
|
|
if (IsLinkRfuTaskFinished())
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
Free(sMenuTextTileBuffer);
|
2018-12-19 02:29:41 +01:00
|
|
|
FreeAllWindowBuffers();
|
2022-12-09 18:34:55 +01:00
|
|
|
Free(sTradeMenu);
|
2018-12-19 02:29:41 +01:00
|
|
|
gMain.callback1 = NULL;
|
2019-04-01 00:59:52 +02:00
|
|
|
DestroyWirelessStatusIndicatorSprite();
|
2019-10-05 16:41:37 +02:00
|
|
|
SetMainCallback2(CB2_LinkTrade);
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
// Cable Link Trade
|
2018-12-31 09:22:21 +01:00
|
|
|
if (!gReceivedRemoteLinkPlayers)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
Free(sMenuTextTileBuffer);
|
2018-12-19 02:29:41 +01:00
|
|
|
FreeAllWindowBuffers();
|
2022-12-09 18:34:55 +01:00
|
|
|
Free(sTradeMenu);
|
2018-12-19 02:29:41 +01:00
|
|
|
gMain.callback1 = NULL;
|
2019-10-05 16:41:37 +02:00
|
|
|
SetMainCallback2(CB2_LinkTrade);
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-07 04:58:25 +02:00
|
|
|
static void CB2_TradeMenu(void)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
RunTradeMenuCallback();
|
2019-10-07 04:58:25 +02:00
|
|
|
DoQueuedActions();
|
2018-12-25 15:14:15 +01:00
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
// As long as drawSelectedMonState is 0, these do nothing
|
|
|
|
DrawSelectedMonScreen(TRADE_PLAYER);
|
|
|
|
DrawSelectedMonScreen(TRADE_PARTNER);
|
|
|
|
|
|
|
|
SetGpuReg(REG_OFFSET_BG2HOFS, sTradeMenu->bg2hofs++);
|
|
|
|
SetGpuReg(REG_OFFSET_BG3HOFS, sTradeMenu->bg3hofs--);
|
2018-12-19 02:29:41 +01:00
|
|
|
|
|
|
|
RunTextPrintersAndIsPrinter0Active();
|
|
|
|
RunTasks();
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
|
|
|
UpdatePaletteFade();
|
|
|
|
}
|
|
|
|
|
2019-10-09 11:56:44 +02:00
|
|
|
static void LoadTradeBgGfx(u8 state)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2019-10-07 04:58:25 +02:00
|
|
|
switch (state)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
|
|
|
case 0:
|
2022-08-19 17:32:00 +02:00
|
|
|
LoadPalette(gTradeMenu_Pal, BG_PLTT_ID(0), 3 * PLTT_SIZE_4BPP);
|
2019-10-03 07:16:22 +02:00
|
|
|
LoadBgTiles(1, gTradeMenu_Gfx, 0x1280, 0);
|
2021-10-26 22:52:23 +02:00
|
|
|
CopyToBgTilemapBufferRect_ChangePalette(1, gTradeMenu_Tilemap, 0, 0, 32, 20, 0);
|
2019-10-10 09:50:51 +02:00
|
|
|
LoadBgTilemap(2, sTradeStripesBG2Tilemap, 0x800, 0);
|
2018-12-19 02:29:41 +01:00
|
|
|
break;
|
|
|
|
case 1:
|
2019-10-10 09:50:51 +02:00
|
|
|
LoadBgTilemap(3, sTradeStripesBG3Tilemap, 0x800, 0);
|
2022-12-09 18:34:55 +01:00
|
|
|
PrintPartyLevelsAndGenders(TRADE_PLAYER);
|
|
|
|
PrintPartyLevelsAndGenders(TRADE_PARTNER);
|
2018-12-19 02:29:41 +01:00
|
|
|
CopyBgTilemapBufferToVram(1);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
SetGpuReg(REG_OFFSET_BG0HOFS + (i * 2), 0);
|
|
|
|
ShowBg(0);
|
|
|
|
ShowBg(1);
|
|
|
|
ShowBg(2);
|
|
|
|
ShowBg(3);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
// Determine (based on party counts) where the main menu cursor can go
|
|
|
|
static void SetActiveMenuOptions(void)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2018-12-21 19:20:28 +01:00
|
|
|
for (i = 0; i < PARTY_SIZE; i++)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
if (i < sTradeMenu->partyCounts[TRADE_PLAYER])
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
// Present player pokemon
|
|
|
|
gSprites[sTradeMenu->partySpriteIds[TRADE_PLAYER][i]].invisible = FALSE;
|
|
|
|
sTradeMenu->optionsActive[i] = TRUE;
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
// Absent player pokemon
|
|
|
|
sTradeMenu->optionsActive[i] = FALSE;
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
2018-12-25 15:14:15 +01:00
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
if (i < sTradeMenu->partyCounts[TRADE_PARTNER])
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
// Present partner pokemon
|
|
|
|
gSprites[sTradeMenu->partySpriteIds[TRADE_PARTNER][i]].invisible = FALSE;
|
|
|
|
sTradeMenu->optionsActive[i + PARTY_SIZE] = TRUE;
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
// Absent partner pokemon
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->optionsActive[i + PARTY_SIZE] = FALSE;
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
// Cancel is always active
|
|
|
|
sTradeMenu->optionsActive[PARTY_SIZE * 2] = TRUE;
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
|
|
|
|
2018-12-31 09:22:21 +01:00
|
|
|
// why not just use memcpy?
|
2022-12-09 18:34:55 +01:00
|
|
|
static void Trade_Memcpy(void *dest, const void *src, u32 size)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
u8 *_dest = dest;
|
|
|
|
const u8 *_src = src;
|
2018-12-19 02:29:41 +01:00
|
|
|
u32 i;
|
2022-12-09 18:34:55 +01:00
|
|
|
for (i = 0; i < size; i++)
|
|
|
|
_dest[i] = _src[i];
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
|
|
|
|
2019-10-09 15:55:06 +02:00
|
|
|
static bool8 BufferTradeParties(void)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
|
|
|
u8 id = GetMultiplayerId();
|
|
|
|
int i;
|
|
|
|
struct Pokemon *mon;
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
switch (sTradeMenu->bufferPartyState)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
|
|
|
case 0:
|
2021-04-19 02:12:12 +02:00
|
|
|
// The parties are sent in pairs rather than all at once
|
2018-12-31 09:22:21 +01:00
|
|
|
Trade_Memcpy(gBlockSendBuffer, &gPlayerParty[0], 2 * sizeof(struct Pokemon));
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->bufferPartyState++;
|
|
|
|
sTradeMenu->timer = 0;
|
2018-12-19 02:29:41 +01:00
|
|
|
break;
|
|
|
|
case 1:
|
2021-04-19 02:12:12 +02:00
|
|
|
if (IsLinkTradeTaskFinished())
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2018-12-31 09:22:21 +01:00
|
|
|
if (_GetBlockReceivedStatus() == 0)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->bufferPartyState++;
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-04 13:42:45 +02:00
|
|
|
TradeResetReceivedFlags();
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->bufferPartyState++;
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (id == 0)
|
2021-08-15 22:11:30 +02:00
|
|
|
RequestLinkData(BLOCK_REQ_SIZE_200);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->bufferPartyState++;
|
2018-12-19 02:29:41 +01:00
|
|
|
break;
|
|
|
|
case 4:
|
2018-12-31 09:22:21 +01:00
|
|
|
if (_GetBlockReceivedStatus() == 3)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2018-12-31 09:22:21 +01:00
|
|
|
Trade_Memcpy(&gEnemyParty[0], gBlockRecvBuffer[id ^ 1], 2 * sizeof(struct Pokemon));
|
2019-10-04 13:42:45 +02:00
|
|
|
TradeResetReceivedFlags();
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->bufferPartyState++;
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 5:
|
2018-12-31 09:22:21 +01:00
|
|
|
Trade_Memcpy(gBlockSendBuffer, &gPlayerParty[2], 2 * sizeof(struct Pokemon));
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->bufferPartyState++;
|
2018-12-19 02:29:41 +01:00
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
if (id == 0)
|
2021-08-15 22:11:30 +02:00
|
|
|
RequestLinkData(BLOCK_REQ_SIZE_200);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->bufferPartyState++;
|
2018-12-19 02:29:41 +01:00
|
|
|
break;
|
|
|
|
case 8:
|
2018-12-31 09:22:21 +01:00
|
|
|
if (_GetBlockReceivedStatus() == 3)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2021-04-19 02:12:12 +02:00
|
|
|
Trade_Memcpy(&gEnemyParty[2], gBlockRecvBuffer[id ^ 1], 2 * sizeof(struct Pokemon));
|
2019-10-04 13:42:45 +02:00
|
|
|
TradeResetReceivedFlags();
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->bufferPartyState++;
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 9:
|
2021-04-19 02:12:12 +02:00
|
|
|
Trade_Memcpy(gBlockSendBuffer, &gPlayerParty[4], 2 * sizeof(struct Pokemon));
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->bufferPartyState++;
|
2018-12-19 02:29:41 +01:00
|
|
|
break;
|
|
|
|
case 11:
|
|
|
|
if (id == 0)
|
2021-08-15 22:11:30 +02:00
|
|
|
RequestLinkData(BLOCK_REQ_SIZE_200);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->bufferPartyState++;
|
2018-12-19 02:29:41 +01:00
|
|
|
break;
|
|
|
|
case 12:
|
2018-12-31 09:22:21 +01:00
|
|
|
if (_GetBlockReceivedStatus() == 3)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2021-04-19 02:12:12 +02:00
|
|
|
Trade_Memcpy(&gEnemyParty[4], gBlockRecvBuffer[id ^ 1], 2 * sizeof(struct Pokemon));
|
2019-10-04 13:42:45 +02:00
|
|
|
TradeResetReceivedFlags();
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->bufferPartyState++;
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 13:
|
2021-10-23 16:55:46 +02:00
|
|
|
Trade_Memcpy(gBlockSendBuffer, gSaveBlock1Ptr->mail, PARTY_SIZE * sizeof(struct Mail) + 4);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->bufferPartyState++;
|
2018-12-19 02:29:41 +01:00
|
|
|
break;
|
|
|
|
case 15:
|
|
|
|
if (id == 0)
|
2021-08-15 22:11:30 +02:00
|
|
|
RequestLinkData(BLOCK_REQ_SIZE_220);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->bufferPartyState++;
|
2018-12-19 02:29:41 +01:00
|
|
|
break;
|
|
|
|
case 16:
|
2018-12-31 09:22:21 +01:00
|
|
|
if (_GetBlockReceivedStatus() == 3)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2021-10-23 16:55:46 +02:00
|
|
|
Trade_Memcpy(gTradeMail, gBlockRecvBuffer[id ^ 1], PARTY_SIZE * sizeof(struct Mail));
|
2019-10-04 13:42:45 +02:00
|
|
|
TradeResetReceivedFlags();
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->bufferPartyState++;
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 17:
|
2022-12-09 18:34:55 +01:00
|
|
|
Trade_Memcpy(gBlockSendBuffer, gSaveBlock1Ptr->giftRibbons, sizeof(sTradeMenu->giftRibbons));
|
|
|
|
sTradeMenu->bufferPartyState++;
|
2018-12-19 02:29:41 +01:00
|
|
|
break;
|
|
|
|
case 19:
|
|
|
|
if (id == 0)
|
2021-08-15 22:11:30 +02:00
|
|
|
RequestLinkData(BLOCK_REQ_SIZE_40);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->bufferPartyState++;
|
2018-12-19 02:29:41 +01:00
|
|
|
break;
|
|
|
|
case 20:
|
2018-12-31 09:22:21 +01:00
|
|
|
if (_GetBlockReceivedStatus() == 3)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
Trade_Memcpy(sTradeMenu->giftRibbons, gBlockRecvBuffer[id ^ 1], sizeof(sTradeMenu->giftRibbons));
|
2019-10-04 13:42:45 +02:00
|
|
|
TradeResetReceivedFlags();
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->bufferPartyState++;
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 21:
|
2018-12-21 19:20:28 +01:00
|
|
|
for (i = 0, mon = gEnemyParty; i < PARTY_SIZE; mon++, i++)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
|
|
|
u8 name[POKEMON_NAME_LENGTH + 1];
|
|
|
|
u16 species = GetMonData(mon, MON_DATA_SPECIES);
|
|
|
|
|
|
|
|
if (species != SPECIES_NONE)
|
|
|
|
{
|
|
|
|
if (species == SPECIES_SHEDINJA && GetMonData(mon, MON_DATA_LANGUAGE) != LANGUAGE_JAPANESE)
|
|
|
|
{
|
|
|
|
GetMonData(mon, MON_DATA_NICKNAME, name);
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
if (!StringCompareWithoutExtCtrlCodes(name, sText_ShedinjaJP))
|
2018-12-19 02:29:41 +01:00
|
|
|
SetMonData(mon, MON_DATA_NICKNAME, gSpeciesNames[SPECIES_SHEDINJA]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
2019-10-11 00:46:42 +02:00
|
|
|
// Delay until next state
|
2018-12-19 02:29:41 +01:00
|
|
|
case 2:
|
|
|
|
case 6:
|
|
|
|
case 10:
|
|
|
|
case 14:
|
|
|
|
case 18:
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->timer++;
|
|
|
|
if (sTradeMenu->timer > 10)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->timer = 0;
|
|
|
|
sTradeMenu->bufferPartyState++;
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void PrintIsThisTradeOkay(void)
|
2018-12-19 02:29:41 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
DrawBottomRowText(sText_IsThisTradeOkay, (void *)(OBJ_VRAM0 + (sTradeMenu->bottomTextTileStart * 32)), 24);
|
2018-12-19 02:29:41 +01:00
|
|
|
}
|
2018-12-21 19:20:28 +01:00
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void Leader_ReadLinkBuffer(u8 mpId, u8 status)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2019-10-09 15:55:06 +02:00
|
|
|
if (status & 1)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
|
|
|
switch (gBlockRecvBuffer[0][0])
|
|
|
|
{
|
2019-10-09 11:56:44 +02:00
|
|
|
case LINKCMD_REQUEST_CANCEL:
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->playerSelectStatus = STATUS_CANCEL;
|
2018-12-21 19:20:28 +01:00
|
|
|
break;
|
2019-10-09 11:56:44 +02:00
|
|
|
case LINKCMD_READY_TO_TRADE:
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->playerSelectStatus = STATUS_READY;
|
2018-12-21 19:20:28 +01:00
|
|
|
break;
|
2019-10-09 11:56:44 +02:00
|
|
|
case LINKCMD_INIT_BLOCK:
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->playerConfirmStatus = STATUS_READY;
|
2018-12-21 19:20:28 +01:00
|
|
|
break;
|
2019-10-11 00:46:42 +02:00
|
|
|
case LINKCMD_READY_CANCEL_TRADE:
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->playerConfirmStatus = STATUS_CANCEL;
|
2018-12-21 19:20:28 +01:00
|
|
|
break;
|
|
|
|
}
|
2019-10-09 11:56:44 +02:00
|
|
|
TradeResetReceivedFlag(0);
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
|
2019-10-09 15:55:06 +02:00
|
|
|
if (status & 2)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
|
|
|
switch (gBlockRecvBuffer[1][0])
|
|
|
|
{
|
2019-10-09 11:56:44 +02:00
|
|
|
case LINKCMD_REQUEST_CANCEL:
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->partnerSelectStatus = STATUS_CANCEL;
|
2018-12-21 19:20:28 +01:00
|
|
|
break;
|
2019-10-09 11:56:44 +02:00
|
|
|
case LINKCMD_READY_TO_TRADE:
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->partnerCursorPosition = gBlockRecvBuffer[1][1] + PARTY_SIZE;
|
|
|
|
sTradeMenu->partnerSelectStatus = STATUS_READY;
|
2018-12-21 19:20:28 +01:00
|
|
|
break;
|
2019-10-09 11:56:44 +02:00
|
|
|
case LINKCMD_INIT_BLOCK:
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->partnerConfirmStatus = STATUS_READY;
|
2018-12-21 19:20:28 +01:00
|
|
|
break;
|
2019-10-11 00:46:42 +02:00
|
|
|
case LINKCMD_READY_CANCEL_TRADE:
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->partnerConfirmStatus = STATUS_CANCEL;
|
2018-12-21 19:20:28 +01:00
|
|
|
break;
|
|
|
|
}
|
2019-10-09 11:56:44 +02:00
|
|
|
TradeResetReceivedFlag(1);
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void Follower_ReadLinkBuffer(u8 mpId, u8 status)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2019-10-09 15:55:06 +02:00
|
|
|
if (status & 1)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
|
|
|
switch (gBlockRecvBuffer[0][0])
|
|
|
|
{
|
2021-03-19 19:10:13 +01:00
|
|
|
case LINKCMD_BOTH_CANCEL_TRADE:
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK);
|
2022-12-09 18:34:55 +01:00
|
|
|
PrintTradeMessage(MSG_WAITING_FOR_FRIEND);
|
|
|
|
sTradeMenu->callbackId = CB_INIT_EXIT_CANCELED_TRADE;
|
2018-12-21 19:20:28 +01:00
|
|
|
break;
|
2021-03-19 19:10:13 +01:00
|
|
|
case LINKCMD_PARTNER_CANCEL_TRADE:
|
2022-12-09 18:34:55 +01:00
|
|
|
PrintTradeMessage(MSG_FRIEND_WANTS_TO_TRADE);
|
|
|
|
sTradeMenu->callbackId = CB_HANDLE_TRADE_CANCELED;
|
2018-12-21 19:20:28 +01:00
|
|
|
break;
|
2019-10-09 11:56:44 +02:00
|
|
|
case LINKCMD_SET_MONS_TO_TRADE:
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->partnerCursorPosition = gBlockRecvBuffer[0][1] + PARTY_SIZE;
|
2018-12-21 19:20:28 +01:00
|
|
|
rbox_fill_rectangle(0);
|
2022-12-09 18:34:55 +01:00
|
|
|
SetSelectedMon(sTradeMenu->cursorPosition);
|
|
|
|
SetSelectedMon(sTradeMenu->partnerCursorPosition);
|
|
|
|
sTradeMenu->callbackId = CB_PRINT_IS_THIS_OKAY;
|
2018-12-21 19:20:28 +01:00
|
|
|
break;
|
2019-10-09 11:56:44 +02:00
|
|
|
case LINKCMD_START_TRADE:
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->callbackId = CB_WAIT_TO_START_TRADE;
|
2018-12-21 19:20:28 +01:00
|
|
|
break;
|
2021-03-19 19:10:13 +01:00
|
|
|
case LINKCMD_PLAYER_CANCEL_TRADE:
|
2022-12-09 18:34:55 +01:00
|
|
|
PrintTradeMessage(MSG_CANCELED);
|
|
|
|
sTradeMenu->callbackId = CB_HANDLE_TRADE_CANCELED;
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
2019-10-09 11:56:44 +02:00
|
|
|
TradeResetReceivedFlag(0);
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
|
2019-10-09 15:55:06 +02:00
|
|
|
if (status & 2)
|
2019-10-09 11:56:44 +02:00
|
|
|
TradeResetReceivedFlag(1);
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void Leader_HandleCommunication(void)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
if (sTradeMenu->playerSelectStatus != STATUS_NONE
|
|
|
|
&& sTradeMenu->partnerSelectStatus != STATUS_NONE)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
if (sTradeMenu->playerSelectStatus == STATUS_READY
|
|
|
|
&& sTradeMenu->partnerSelectStatus == STATUS_READY)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
// Both players have selected a pokemon to trade
|
|
|
|
sTradeMenu->callbackId = CB_SET_SELECTED_MONS;
|
|
|
|
sTradeMenu->linkData[0] = LINKCMD_SET_MONS_TO_TRADE;
|
|
|
|
sTradeMenu->linkData[1] = sTradeMenu->cursorPosition;
|
2019-10-07 04:58:25 +02:00
|
|
|
QueueAction(QUEUE_DELAY_DATA, QUEUE_SEND_DATA);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->playerSelectStatus = sTradeMenu->partnerSelectStatus = STATUS_NONE;
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
2022-12-09 18:34:55 +01:00
|
|
|
else if (sTradeMenu->playerSelectStatus == STATUS_READY
|
|
|
|
&& sTradeMenu->partnerSelectStatus == STATUS_CANCEL)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
// The player has selected a pokemon to trade,
|
|
|
|
// but the partner has selected Cancel
|
|
|
|
PrintTradeMessage(MSG_CANCELED);
|
|
|
|
sTradeMenu->linkData[0] = LINKCMD_PARTNER_CANCEL_TRADE;
|
|
|
|
sTradeMenu->linkData[1] = 0;
|
2019-10-07 04:58:25 +02:00
|
|
|
QueueAction(QUEUE_DELAY_DATA, QUEUE_SEND_DATA);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->playerConfirmStatus = sTradeMenu->partnerConfirmStatus = STATUS_NONE;
|
|
|
|
sTradeMenu->playerSelectStatus = sTradeMenu->partnerSelectStatus = STATUS_NONE;
|
|
|
|
sTradeMenu->callbackId = CB_HANDLE_TRADE_CANCELED;
|
|
|
|
}
|
|
|
|
else if (sTradeMenu->playerSelectStatus == STATUS_CANCEL
|
|
|
|
&& sTradeMenu->partnerSelectStatus == STATUS_READY)
|
|
|
|
{
|
|
|
|
// The partner has selected a pokemon to trade,
|
|
|
|
// but the player has selected cancel
|
|
|
|
PrintTradeMessage(MSG_FRIEND_WANTS_TO_TRADE);
|
|
|
|
sTradeMenu->linkData[0] = LINKCMD_PLAYER_CANCEL_TRADE;
|
|
|
|
sTradeMenu->linkData[1] = 0;
|
2019-10-07 04:58:25 +02:00
|
|
|
QueueAction(QUEUE_DELAY_DATA, QUEUE_SEND_DATA);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->playerConfirmStatus = sTradeMenu->partnerConfirmStatus = STATUS_NONE;
|
|
|
|
sTradeMenu->playerSelectStatus = sTradeMenu->partnerSelectStatus = STATUS_NONE;
|
|
|
|
sTradeMenu->callbackId = CB_HANDLE_TRADE_CANCELED;
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
2022-12-09 18:34:55 +01:00
|
|
|
else if (sTradeMenu->playerSelectStatus == STATUS_CANCEL
|
|
|
|
&& sTradeMenu->partnerSelectStatus == STATUS_CANCEL)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
// Both players have selected Cancel
|
|
|
|
sTradeMenu->linkData[0] = LINKCMD_BOTH_CANCEL_TRADE;
|
|
|
|
sTradeMenu->linkData[1] = 0;
|
2019-10-07 04:58:25 +02:00
|
|
|
QueueAction(QUEUE_DELAY_DATA, QUEUE_SEND_DATA);
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->playerSelectStatus = sTradeMenu->partnerSelectStatus = STATUS_NONE;
|
|
|
|
sTradeMenu->callbackId = CB_INIT_EXIT_CANCELED_TRADE;
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
if (sTradeMenu->playerConfirmStatus != STATUS_NONE
|
|
|
|
&& sTradeMenu->partnerConfirmStatus != STATUS_NONE)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
if (sTradeMenu->playerConfirmStatus == STATUS_READY
|
|
|
|
&& sTradeMenu->partnerConfirmStatus == STATUS_READY)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
// Both players have confirmed trade
|
|
|
|
sTradeMenu->linkData[0] = LINKCMD_START_TRADE;
|
|
|
|
sTradeMenu->linkData[1] = 0;
|
2019-10-07 04:58:25 +02:00
|
|
|
QueueAction(QUEUE_DELAY_DATA, QUEUE_SEND_DATA);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->playerConfirmStatus = STATUS_NONE;
|
|
|
|
sTradeMenu->partnerConfirmStatus = STATUS_NONE;
|
|
|
|
sTradeMenu->callbackId = CB_FADE_TO_START_TRADE;
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
if (sTradeMenu->playerConfirmStatus == STATUS_CANCEL
|
|
|
|
|| sTradeMenu->partnerConfirmStatus == STATUS_CANCEL)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
// One of the players has decided not to confirm the trade,
|
|
|
|
// or the trade was not allowed.
|
|
|
|
PrintTradeMessage(MSG_CANCELED);
|
|
|
|
sTradeMenu->linkData[0] = LINKCMD_PLAYER_CANCEL_TRADE;
|
|
|
|
sTradeMenu->linkData[1] = 0;
|
2019-10-07 04:58:25 +02:00
|
|
|
QueueAction(QUEUE_DELAY_DATA, QUEUE_SEND_DATA);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->playerConfirmStatus = STATUS_NONE;
|
|
|
|
sTradeMenu->partnerConfirmStatus = STATUS_NONE;
|
|
|
|
sTradeMenu->callbackId = CB_HANDLE_TRADE_CANCELED;
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-07 04:58:25 +02:00
|
|
|
static void _SetLinkData(u16 *linkData, u16 linkCmd, u16 cursorPosition)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2019-10-07 04:58:25 +02:00
|
|
|
linkData[0] = linkCmd;
|
2019-10-04 01:39:37 +02:00
|
|
|
linkData[1] = cursorPosition;
|
2019-10-07 04:58:25 +02:00
|
|
|
QueueAction(QUEUE_DELAY_DATA, QUEUE_SEND_DATA);
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
|
2019-10-07 04:58:25 +02:00
|
|
|
static void SetLinkData(u16 linkCmd, u16 cursorPosition)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
_SetLinkData(sTradeMenu->linkData, linkCmd, cursorPosition);
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void CB1_UpdateLink(void)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2018-12-31 09:22:21 +01:00
|
|
|
u8 mpId = GetMultiplayerId();
|
|
|
|
u8 status;
|
2018-12-21 19:20:28 +01:00
|
|
|
|
2018-12-31 09:22:21 +01:00
|
|
|
if ((status = _GetBlockReceivedStatus()))
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2018-12-31 09:22:21 +01:00
|
|
|
if (mpId == 0)
|
2022-12-09 18:34:55 +01:00
|
|
|
Leader_ReadLinkBuffer(mpId, status);
|
2018-12-21 19:20:28 +01:00
|
|
|
else
|
2022-12-09 18:34:55 +01:00
|
|
|
Follower_ReadLinkBuffer(mpId, status);
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
|
2018-12-31 09:22:21 +01:00
|
|
|
if (mpId == 0)
|
2022-12-09 18:34:55 +01:00
|
|
|
Leader_HandleCommunication();
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static u8 GetNewCursorPosition(u8 oldPosition, u8 direction)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
|
|
|
int i;
|
2018-12-31 09:22:21 +01:00
|
|
|
u8 newPosition = 0;
|
2018-12-21 19:20:28 +01:00
|
|
|
|
|
|
|
for (i = 0; i < PARTY_SIZE; i++)
|
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
if (sTradeMenu->optionsActive[sCursorMoveDestinations[oldPosition][direction][i]] == TRUE)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
newPosition = sCursorMoveDestinations[oldPosition][direction][i];
|
2018-12-21 19:20:28 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 09:22:21 +01:00
|
|
|
return newPosition;
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
|
2019-10-04 01:39:37 +02:00
|
|
|
static void TradeMenuMoveCursor(u8 *cursorPosition, u8 direction)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
u8 newPosition = GetNewCursorPosition(*cursorPosition, direction);
|
2018-12-21 19:20:28 +01:00
|
|
|
|
2019-10-05 16:41:37 +02:00
|
|
|
if (newPosition == (PARTY_SIZE * 2)) // CANCEL
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
StartSpriteAnim(&gSprites[sTradeMenu->cursorSpriteId], CURSOR_ANIM_ON_CANCEL);
|
|
|
|
gSprites[sTradeMenu->cursorSpriteId].x = DISPLAY_WIDTH - 16;
|
|
|
|
gSprites[sTradeMenu->cursorSpriteId].y = DISPLAY_HEIGHT;
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
StartSpriteAnim(&gSprites[sTradeMenu->cursorSpriteId], CURSOR_ANIM_NORMAL);
|
|
|
|
gSprites[sTradeMenu->cursorSpriteId].x = sTradeMonSpriteCoords[newPosition][0] * 8 + 32;
|
|
|
|
gSprites[sTradeMenu->cursorSpriteId].y = sTradeMonSpriteCoords[newPosition][1] * 8;
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
|
2019-10-04 01:39:37 +02:00
|
|
|
if (*cursorPosition != newPosition)
|
2018-12-21 19:20:28 +01:00
|
|
|
PlaySE(SE_SELECT);
|
|
|
|
|
2019-10-04 01:39:37 +02:00
|
|
|
*cursorPosition = newPosition;
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
|
2019-10-09 11:56:44 +02:00
|
|
|
static void SetReadyToTrade(void)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
PrintTradeMessage(MSG_STANDBY);
|
|
|
|
sTradeMenu->callbackId = CB_IDLE;
|
2018-12-21 19:20:28 +01:00
|
|
|
|
|
|
|
if (GetMultiplayerId() == 1)
|
2022-12-09 18:34:55 +01:00
|
|
|
{
|
|
|
|
// Communicate to the link leader that we're ready to trade
|
|
|
|
SetLinkData(LINKCMD_READY_TO_TRADE, sTradeMenu->cursorPosition);
|
|
|
|
}
|
2018-12-21 19:20:28 +01:00
|
|
|
else
|
2022-12-09 18:34:55 +01:00
|
|
|
{
|
|
|
|
// We are the link leader, no communication necessary
|
|
|
|
sTradeMenu->playerSelectStatus = STATUS_READY;
|
|
|
|
}
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void CB_ProcessMenuInput(void)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2020-09-05 03:11:55 +02:00
|
|
|
if (JOY_REPEAT(DPAD_UP))
|
2022-12-09 18:34:55 +01:00
|
|
|
TradeMenuMoveCursor(&sTradeMenu->cursorPosition, 0);
|
2020-09-05 03:11:55 +02:00
|
|
|
else if (JOY_REPEAT(DPAD_DOWN))
|
2022-12-09 18:34:55 +01:00
|
|
|
TradeMenuMoveCursor(&sTradeMenu->cursorPosition, 1);
|
2020-09-05 03:11:55 +02:00
|
|
|
else if (JOY_REPEAT(DPAD_LEFT))
|
2022-12-09 18:34:55 +01:00
|
|
|
TradeMenuMoveCursor(&sTradeMenu->cursorPosition, 2);
|
2020-09-05 03:11:55 +02:00
|
|
|
else if (JOY_REPEAT(DPAD_RIGHT))
|
2022-12-09 18:34:55 +01:00
|
|
|
TradeMenuMoveCursor(&sTradeMenu->cursorPosition, 3);
|
2018-12-21 19:20:28 +01:00
|
|
|
|
2020-09-05 03:11:55 +02:00
|
|
|
if (JOY_NEW(A_BUTTON))
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
|
|
|
PlaySE(SE_SELECT);
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
if (sTradeMenu->cursorPosition < PARTY_SIZE)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
// Selected pokemon in player's party
|
2019-04-01 00:59:52 +02:00
|
|
|
DrawTextBorderOuter(1, 1, 14);
|
2019-03-02 23:25:39 +01:00
|
|
|
FillWindowPixelBuffer(1, PIXEL_FILL(1));
|
2019-10-04 01:39:37 +02:00
|
|
|
PrintMenuTable(1, ARRAY_COUNT(sSelectTradeMonActions), sSelectTradeMonActions);
|
2022-02-27 19:47:50 +01:00
|
|
|
InitMenuInUpperLeftCornerNormal(1, ARRAY_COUNT(sSelectTradeMonActions), 0);
|
2018-12-21 19:20:28 +01:00
|
|
|
PutWindowTilemap(1);
|
2021-11-03 20:29:18 +01:00
|
|
|
CopyWindowToVram(1, COPYWIN_FULL);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->callbackId = CB_SELECTED_MON;
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
2022-12-09 18:34:55 +01:00
|
|
|
else if (sTradeMenu->cursorPosition < PARTY_SIZE * 2)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
// Selected pokemon in partner's party
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->callbackId = CB_SHOW_MON_SUMMARY;
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
2022-12-09 18:34:55 +01:00
|
|
|
else if (sTradeMenu->cursorPosition == PARTY_SIZE * 2)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
// Selected Cancel
|
2019-10-04 01:39:37 +02:00
|
|
|
CreateYesNoMenu(&sTradeYesNoWindowTemplate, 1, 14, 0);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->callbackId = CB_CANCEL_TRADE_PROMPT;
|
|
|
|
DrawBottomRowText(sActionTexts[TEXT_CANCEL_TRADE], (void *)(OBJ_VRAM0 + sTradeMenu->bottomTextTileStart * 32), 24);
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void RedrawChooseAPokemonWindow(void)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
PrintTradePartnerPartyNicknames();
|
|
|
|
sTradeMenu->callbackId = CB_MAIN_MENU;
|
|
|
|
gSprites[sTradeMenu->cursorSpriteId].invisible = FALSE;
|
|
|
|
DrawBottomRowText(sActionTexts[TEXT_CHOOSE_MON], (void *)(OBJ_VRAM0 + sTradeMenu->bottomTextTileStart * 32), 24);
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void CB_ProcessSelectedMonInput(void)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
|
|
|
switch (Menu_ProcessInputNoWrap())
|
|
|
|
{
|
2019-10-09 15:55:06 +02:00
|
|
|
case MENU_B_PRESSED:
|
|
|
|
PlaySE(SE_SELECT);
|
2022-12-09 18:34:55 +01:00
|
|
|
RedrawChooseAPokemonWindow();
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
|
|
|
case MENU_NOTHING_CHOSEN:
|
|
|
|
break;
|
2019-10-10 09:50:51 +02:00
|
|
|
case 0: // Summary
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->callbackId = CB_SHOW_MON_SUMMARY;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2019-10-10 09:50:51 +02:00
|
|
|
case 1: // Trade
|
2022-12-09 18:34:55 +01:00
|
|
|
switch (CanTradeSelectedMon(gPlayerParty, gPlayerPartyCount, sTradeMenu->cursorPosition))
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
|
|
|
case CAN_TRADE_MON:
|
|
|
|
SetReadyToTrade();
|
2022-12-09 18:34:55 +01:00
|
|
|
gSprites[sTradeMenu->cursorSpriteId].invisible = TRUE;
|
2018-12-21 19:20:28 +01:00
|
|
|
break;
|
2019-10-09 15:55:06 +02:00
|
|
|
case CANT_TRADE_LAST_MON:
|
|
|
|
QueueAction(QUEUE_DELAY_MSG, QUEUE_ONLY_MON2);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->callbackId = CB_HANDLE_TRADE_CANCELED;
|
2018-12-21 19:20:28 +01:00
|
|
|
break;
|
2019-10-09 15:55:06 +02:00
|
|
|
case CANT_TRADE_NATIONAL:
|
|
|
|
case CANT_TRADE_INVALID_MON:
|
|
|
|
QueueAction(QUEUE_DELAY_MSG, QUEUE_MON_CANT_BE_TRADED);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->callbackId = CB_HANDLE_TRADE_CANCELED;
|
2018-12-21 19:20:28 +01:00
|
|
|
break;
|
2019-10-18 01:22:03 +02:00
|
|
|
case CANT_TRADE_EGG_YET:
|
2022-12-09 18:34:55 +01:00
|
|
|
case CANT_TRADE_PARTNER_EGG_YET:
|
2019-10-09 15:55:06 +02:00
|
|
|
QueueAction(QUEUE_DELAY_MSG, QUEUE_EGG_CANT_BE_TRADED);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->callbackId = CB_HANDLE_TRADE_CANCELED;
|
2018-12-21 19:20:28 +01:00
|
|
|
break;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void CB_ChooseMonAfterButtonPress(void)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
if (JOY_NEW(A_BUTTON) || JOY_NEW(B_BUTTON))
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
|
|
|
PlaySE(SE_SELECT);
|
2022-12-09 18:34:55 +01:00
|
|
|
RedrawChooseAPokemonWindow();
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void CB_ShowTradeMonSummaryScreen(void)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
if (sTradeMenu->cursorPosition < PARTY_SIZE)
|
|
|
|
ShowPokemonSummaryScreen(SUMMARY_MODE_LOCK_MOVES, gPlayerParty, sTradeMenu->cursorPosition, sTradeMenu->partyCounts[TRADE_PLAYER] - 1, CB2_ReturnToTradeMenu);
|
2018-12-21 19:20:28 +01:00
|
|
|
else
|
2022-12-09 18:34:55 +01:00
|
|
|
ShowPokemonSummaryScreen(SUMMARY_MODE_LOCK_MOVES, gEnemyParty, sTradeMenu->cursorPosition - PARTY_SIZE, sTradeMenu->partyCounts[TRADE_PARTNER] - 1, CB2_ReturnToTradeMenu);
|
2018-12-21 19:20:28 +01:00
|
|
|
FreeAllWindowBuffers();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-04 01:39:37 +02:00
|
|
|
static u8 CheckValidityOfTradeMons(u8 *aliveMons, u8 playerPartyCount, u8 playerMonIdx, u8 partnerMonIdx)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
|
|
|
int i;
|
2019-10-11 00:46:42 +02:00
|
|
|
u16 partnerSpecies;
|
2019-10-04 01:39:37 +02:00
|
|
|
u8 hasLiveMon = 0;
|
2018-12-21 19:20:28 +01:00
|
|
|
|
2019-10-04 01:39:37 +02:00
|
|
|
// Make sure mon to be traded isn't player's last alive mon
|
|
|
|
for (i = 0; i < playerPartyCount; i++)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2019-10-04 01:39:37 +02:00
|
|
|
if (playerMonIdx != i)
|
|
|
|
hasLiveMon += aliveMons[i];
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
2019-10-04 01:39:37 +02:00
|
|
|
partnerMonIdx %= PARTY_SIZE;
|
2019-10-11 00:46:42 +02:00
|
|
|
partnerSpecies = GetMonData(&gEnemyParty[partnerMonIdx], MON_DATA_SPECIES);
|
2018-12-21 19:20:28 +01:00
|
|
|
|
2019-10-04 01:39:37 +02:00
|
|
|
// Partner cant trade illegitimate Deoxys or Mew
|
2019-10-11 00:46:42 +02:00
|
|
|
if (partnerSpecies == SPECIES_DEOXYS || partnerSpecies == SPECIES_MEW)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2023-02-15 17:56:11 +01:00
|
|
|
if (!GetMonData(&gEnemyParty[partnerMonIdx], MON_DATA_MODERN_FATEFUL_ENCOUNTER))
|
2019-10-04 01:39:37 +02:00
|
|
|
return PARTNER_MON_INVALID;
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
|
2019-10-04 01:39:37 +02:00
|
|
|
// Partner cant trade Egg or non-Hoenn mon if player doesn't have National Dex
|
2018-12-21 19:20:28 +01:00
|
|
|
if (!IsNationalPokedexEnabled())
|
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
if (sTradeMenu->isEgg[TRADE_PARTNER][partnerMonIdx] || !IsSpeciesInHoennDex(partnerSpecies))
|
2019-10-04 01:39:37 +02:00
|
|
|
return PARTNER_MON_INVALID;
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
2018-12-25 15:14:15 +01:00
|
|
|
|
2019-10-04 01:39:37 +02:00
|
|
|
if (hasLiveMon)
|
2019-10-10 09:50:51 +02:00
|
|
|
hasLiveMon = BOTH_MONS_VALID;
|
2018-12-21 19:20:28 +01:00
|
|
|
|
2020-05-18 14:03:01 +02:00
|
|
|
return hasLiveMon; //PLAYER_MON_INVALID or BOTH_MONS_VALID
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
|
2019-10-09 11:56:44 +02:00
|
|
|
// Returns TRUE if the partner's selected mon is invalid, FALSE otherwise
|
2019-10-11 00:46:42 +02:00
|
|
|
static bool32 CheckMonsBeforeTrade(void)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
|
|
|
int i;
|
2019-10-04 01:39:37 +02:00
|
|
|
u8 aliveMons[PARTY_SIZE * 2];
|
2018-12-21 19:20:28 +01:00
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
for (i = 0; i < sTradeMenu->partyCounts[TRADE_PLAYER]; i++)
|
|
|
|
aliveMons[i] = sTradeMenu->isLiveMon[TRADE_PLAYER][i];
|
2018-12-21 19:20:28 +01:00
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
switch (CheckValidityOfTradeMons(aliveMons, sTradeMenu->partyCounts[TRADE_PLAYER],
|
|
|
|
sTradeMenu->cursorPosition,
|
|
|
|
sTradeMenu->partnerCursorPosition))
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2019-10-09 15:55:06 +02:00
|
|
|
case PLAYER_MON_INVALID:
|
|
|
|
QueueAction(QUEUE_DELAY_MSG, QUEUE_ONLY_MON2);
|
2019-10-11 00:46:42 +02:00
|
|
|
SetLinkData(LINKCMD_READY_CANCEL_TRADE, 0);
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2019-10-10 09:50:51 +02:00
|
|
|
case BOTH_MONS_VALID:
|
2019-10-09 15:55:06 +02:00
|
|
|
QueueAction(QUEUE_DELAY_MSG, QUEUE_STANDBY);
|
|
|
|
SetLinkData(LINKCMD_INIT_BLOCK, 0);
|
|
|
|
break;
|
|
|
|
case PARTNER_MON_INVALID:
|
|
|
|
QueueAction(QUEUE_DELAY_MSG, QUEUE_FRIENDS_MON_CANT_BE_TRADED);
|
|
|
|
return TRUE;
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void CB_ProcessConfirmTradeInput(void)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
|
|
|
switch (Menu_ProcessInputNoWrapClearOnChoose())
|
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
case 0: // YES, Confirm selection
|
2019-10-11 00:46:42 +02:00
|
|
|
if (!CheckMonsBeforeTrade())
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->callbackId = CB_IDLE;
|
2019-10-09 15:55:06 +02:00
|
|
|
else
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->callbackId = CB_PARTNER_MON_INVALID;
|
2019-10-11 00:46:42 +02:00
|
|
|
|
2019-10-09 15:55:06 +02:00
|
|
|
PutWindowTilemap(17);
|
|
|
|
break;
|
2022-12-09 18:34:55 +01:00
|
|
|
case 1: // NO, Cancel Trade
|
2019-10-09 15:55:06 +02:00
|
|
|
case MENU_B_PRESSED:
|
|
|
|
QueueAction(QUEUE_DELAY_MSG, QUEUE_STANDBY);
|
2021-04-19 02:12:12 +02:00
|
|
|
if (IsLinkTradeTaskFinished())
|
2019-10-11 00:46:42 +02:00
|
|
|
SetLinkData(LINKCMD_READY_CANCEL_TRADE, 0);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->callbackId = CB_IDLE;
|
2019-10-09 15:55:06 +02:00
|
|
|
PutWindowTilemap(17);
|
|
|
|
break;
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-25 00:59:32 +02:00
|
|
|
// Only when choosing Yes to cancel, when No is chosen all are redrawn anyway
|
2021-04-19 02:12:12 +02:00
|
|
|
static void RestoreNicknamesCoveredByYesNo(void)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
for (i = 0; i < sTradeMenu->partyCounts[1] - 4; i++)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
PutWindowTilemap(i + PARTY_SIZE * 2);
|
|
|
|
CopyWindowToVram(i + PARTY_SIZE * 2, COPYWIN_MAP);
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void CB_ProcessCancelTradeInput(void)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
|
|
|
switch (Menu_ProcessInputNoWrapClearOnChoose())
|
|
|
|
{
|
2019-10-09 15:55:06 +02:00
|
|
|
case 0: // YES, Cancel
|
2022-12-09 18:34:55 +01:00
|
|
|
PrintTradeMessage(MSG_WAITING_FOR_FRIEND);
|
2019-10-09 15:55:06 +02:00
|
|
|
SetLinkData(LINKCMD_REQUEST_CANCEL, 0);
|
2022-12-09 18:34:55 +01:00
|
|
|
gSprites[sTradeMenu->cursorSpriteId].invisible = TRUE;
|
|
|
|
sTradeMenu->callbackId = CB_IDLE;
|
2021-04-19 02:12:12 +02:00
|
|
|
RestoreNicknamesCoveredByYesNo();
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
|
|
|
case 1: // NO, Continue
|
|
|
|
case MENU_B_PRESSED:
|
|
|
|
PlaySE(SE_SELECT);
|
2022-12-09 18:34:55 +01:00
|
|
|
RedrawChooseAPokemonWindow();
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void CB_SetSelectedMons(void)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
|
|
|
if (GetMultiplayerId() == 0)
|
|
|
|
{
|
|
|
|
rbox_fill_rectangle(0);
|
2022-12-09 18:34:55 +01:00
|
|
|
SetSelectedMon(sTradeMenu->cursorPosition);
|
|
|
|
SetSelectedMon(sTradeMenu->partnerCursorPosition);
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->callbackId = CB_PRINT_IS_THIS_OKAY;
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void CB_PrintIsThisTradeOkay(void)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
if (sTradeMenu->drawSelectedMonState[TRADE_PLAYER] == DRAW_SELECTED_FINISH
|
|
|
|
&& sTradeMenu->drawSelectedMonState[TRADE_PARTNER] == DRAW_SELECTED_FINISH)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
PrintIsThisTradeOkay();
|
|
|
|
sTradeMenu->callbackId = CB_INIT_CONFIRM_TRADE_PROMPT;
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void CB_InitConfirmTradePrompt(void)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->timer++;
|
|
|
|
if (sTradeMenu->timer > 120)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2019-10-04 01:39:37 +02:00
|
|
|
CreateYesNoMenu(&sTradeYesNoWindowTemplate, 1, 14, 0);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->timer = 0;
|
|
|
|
sTradeMenu->callbackId = CB_CONFIRM_TRADE_PROMPT;
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void CB_HandleTradeCanceled(void)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2020-09-05 03:11:55 +02:00
|
|
|
if (JOY_NEW(A_BUTTON))
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
|
|
|
PlaySE(SE_SELECT);
|
|
|
|
rbox_fill_rectangle(0);
|
|
|
|
rbox_fill_rectangle(1);
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
2019-03-02 23:25:39 +01:00
|
|
|
FillWindowPixelBuffer(i + 14, PIXEL_FILL(0));
|
2018-12-21 19:20:28 +01:00
|
|
|
rbox_fill_rectangle(i + 14);
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
RedrawPartyWindow(TRADE_PLAYER);
|
|
|
|
RedrawPartyWindow(TRADE_PARTNER);
|
|
|
|
sTradeMenu->callbackId = CB_MAIN_MENU;
|
|
|
|
gSprites[sTradeMenu->cursorSpriteId].invisible = FALSE;
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void CB_InitExitCanceledTrade(void)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
|
|
|
if (gWirelessCommType)
|
2020-08-13 09:09:47 +02:00
|
|
|
SetLinkStandbyCallback();
|
2018-12-21 19:20:28 +01:00
|
|
|
else
|
2020-08-13 09:09:47 +02:00
|
|
|
SetCloseLinkCallbackAndType(12);
|
2018-12-21 19:20:28 +01:00
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->callbackId = CB_EXIT_CANCELED_TRADE;
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void CB_ExitCanceledTrade(void)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
|
|
|
if (gWirelessCommType)
|
|
|
|
{
|
2021-04-19 02:12:12 +02:00
|
|
|
if (IsLinkTradeTaskFinished() && GetNumQueuedActions() == 0)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
Free(sMenuTextTileBuffer);
|
|
|
|
Free(sTradeMenu);
|
2018-12-21 19:20:28 +01:00
|
|
|
FreeAllWindowBuffers();
|
2019-04-01 00:59:52 +02:00
|
|
|
DestroyWirelessStatusIndicatorSprite();
|
2019-02-10 09:54:50 +01:00
|
|
|
SetMainCallback2(CB2_ReturnToFieldFromMultiplayer);
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-31 09:22:21 +01:00
|
|
|
if (!gReceivedRemoteLinkPlayers)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
Free(sMenuTextTileBuffer);
|
|
|
|
Free(sTradeMenu);
|
2018-12-21 19:20:28 +01:00
|
|
|
FreeAllWindowBuffers();
|
2019-02-10 09:54:50 +01:00
|
|
|
SetMainCallback2(CB2_ReturnToFieldFromMultiplayer);
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void CB_WaitToStartRfuTrade(void)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2021-08-16 00:26:09 +02:00
|
|
|
if (!Rfu_SetLinkRecovery(FALSE) && GetNumQueuedActions() == 0)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2020-08-13 09:09:47 +02:00
|
|
|
SetLinkStandbyCallback();
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->callbackId = CB_START_LINK_TRADE;
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void CB_PartnersMonWasInvalid(void)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2020-09-05 03:11:55 +02:00
|
|
|
if (JOY_NEW(A_BUTTON))
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2019-10-11 00:46:42 +02:00
|
|
|
SetLinkData(LINKCMD_READY_CANCEL_TRADE, 0);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->callbackId = CB_IDLE;
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void RunTradeMenuCallback(void)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
switch (sTradeMenu->callbackId)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
case CB_MAIN_MENU:
|
|
|
|
CB_ProcessMenuInput();
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-09 18:34:55 +01:00
|
|
|
case CB_SELECTED_MON:
|
|
|
|
CB_ProcessSelectedMonInput();
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-09 18:34:55 +01:00
|
|
|
case CB_SHOW_MON_SUMMARY:
|
|
|
|
CB_ShowTradeMonSummaryScreen();
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-09 18:34:55 +01:00
|
|
|
case CB_CONFIRM_TRADE_PROMPT:
|
|
|
|
CB_ProcessConfirmTradeInput();
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-09 18:34:55 +01:00
|
|
|
case CB_CANCEL_TRADE_PROMPT:
|
|
|
|
CB_ProcessCancelTradeInput();
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-09 18:34:55 +01:00
|
|
|
case CB_SET_SELECTED_MONS:
|
|
|
|
CB_SetSelectedMons();
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-09 18:34:55 +01:00
|
|
|
case CB_PRINT_IS_THIS_OKAY:
|
|
|
|
CB_PrintIsThisTradeOkay();
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-09 18:34:55 +01:00
|
|
|
case CB_HANDLE_TRADE_CANCELED:
|
|
|
|
CB_HandleTradeCanceled();
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-09 18:34:55 +01:00
|
|
|
case CB_FADE_TO_START_TRADE:
|
|
|
|
CB_FadeToStartTrade();
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-09 18:34:55 +01:00
|
|
|
case CB_WAIT_TO_START_TRADE:
|
|
|
|
CB_WaitToStartTrade();
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-09 18:34:55 +01:00
|
|
|
case CB_INIT_EXIT_CANCELED_TRADE:
|
|
|
|
CB_InitExitCanceledTrade();
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-09 18:34:55 +01:00
|
|
|
case CB_EXIT_CANCELED_TRADE:
|
|
|
|
CB_ExitCanceledTrade();
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-09 18:34:55 +01:00
|
|
|
case CB_START_LINK_TRADE:
|
|
|
|
CB_StartLinkTrade();
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-09 18:34:55 +01:00
|
|
|
case CB_INIT_CONFIRM_TRADE_PROMPT:
|
|
|
|
CB_InitConfirmTradePrompt();
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-09 18:34:55 +01:00
|
|
|
case CB_UNUSED_CLOSE_MSG:
|
|
|
|
CB_ChooseMonAfterButtonPress();
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-09 18:34:55 +01:00
|
|
|
case CB_WAIT_TO_START_RFU_TRADE:
|
|
|
|
CB_WaitToStartRfuTrade();
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-09 18:34:55 +01:00
|
|
|
case CB_PARTNER_MON_INVALID:
|
|
|
|
CB_PartnersMonWasInvalid();
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-09 18:34:55 +01:00
|
|
|
//case CB_IDLE: is nop
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-04 01:39:37 +02:00
|
|
|
static void SetSelectedMon(u8 cursorPosition)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2019-10-04 01:39:37 +02:00
|
|
|
//cursorPosition 0-5 are the player's mons, 6-11 are the partner's
|
|
|
|
u8 whichParty = cursorPosition / PARTY_SIZE;
|
2018-12-21 19:20:28 +01:00
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
if (sTradeMenu->drawSelectedMonState[whichParty] == 0)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
// Start the animation to display just the selected
|
|
|
|
// pokemon in the middle of the screen
|
|
|
|
sTradeMenu->drawSelectedMonState[whichParty] = 1;
|
|
|
|
sTradeMenu->selectedMonIdx[whichParty] = cursorPosition;
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void DrawSelectedMonScreen(u8 whichParty)
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2018-12-31 09:22:21 +01:00
|
|
|
s8 nameStringWidth;
|
|
|
|
u8 nickname[20];
|
|
|
|
u8 movesString[56];
|
2018-12-21 19:20:28 +01:00
|
|
|
u8 i;
|
2018-12-31 09:22:21 +01:00
|
|
|
u8 partyIdx;
|
2019-10-04 13:42:45 +02:00
|
|
|
u8 selectedMonParty;
|
2022-12-09 18:34:55 +01:00
|
|
|
u8 selectedMonIdx = sTradeMenu->selectedMonIdx[whichParty];
|
2018-12-25 15:14:15 +01:00
|
|
|
|
2019-10-04 13:42:45 +02:00
|
|
|
selectedMonParty = TRADE_PARTNER;
|
2022-12-09 18:34:55 +01:00
|
|
|
if (sTradeMenu->selectedMonIdx[whichParty] < PARTY_SIZE)
|
2019-10-04 13:42:45 +02:00
|
|
|
selectedMonParty = TRADE_PLAYER;
|
2019-10-04 01:39:37 +02:00
|
|
|
partyIdx = selectedMonIdx % PARTY_SIZE;
|
2018-12-31 09:22:21 +01:00
|
|
|
nameStringWidth = 0;
|
2018-12-25 15:14:15 +01:00
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
switch (sTradeMenu->drawSelectedMonState[whichParty])
|
2018-12-21 19:20:28 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
default:
|
|
|
|
// Idle while state is 0, and once it reaches the final state (DRAW_SELECTED_FINISH)
|
|
|
|
break;
|
2019-10-10 09:50:51 +02:00
|
|
|
case 1:
|
2022-12-09 18:34:55 +01:00
|
|
|
// Erase the rest of the party
|
|
|
|
for (i = 0; i < sTradeMenu->partyCounts[whichParty]; i++)
|
|
|
|
gSprites[sTradeMenu->partySpriteIds[selectedMonParty][i]].invisible = TRUE;
|
|
|
|
for (i = 0; i < PARTY_SIZE; i++)
|
2019-10-04 13:42:45 +02:00
|
|
|
ClearWindowTilemap(i + (whichParty * PARTY_SIZE + 2));
|
2018-12-25 15:14:15 +01:00
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
// Re-display the selected pokemon
|
|
|
|
gSprites[sTradeMenu->partySpriteIds[selectedMonParty][partyIdx]].invisible = FALSE;
|
|
|
|
|
|
|
|
// Move the selected pokemon to the center
|
|
|
|
gSprites[sTradeMenu->partySpriteIds[selectedMonParty][partyIdx]].data[0] = 20;
|
|
|
|
gSprites[sTradeMenu->partySpriteIds[selectedMonParty][partyIdx]].data[2] = (sTradeMonSpriteCoords[selectedMonParty * PARTY_SIZE][0]
|
|
|
|
+ sTradeMonSpriteCoords[selectedMonParty * PARTY_SIZE + 1][0]) / 2 * 8 + 14;
|
|
|
|
gSprites[sTradeMenu->partySpriteIds[selectedMonParty][partyIdx]].data[4] = (sTradeMonSpriteCoords[selectedMonParty * PARTY_SIZE][1] * 8) - 12;
|
|
|
|
StoreSpriteCallbackInData6(&gSprites[sTradeMenu->partySpriteIds[selectedMonParty][partyIdx]], SpriteCB_MonIcon);
|
|
|
|
sTradeMenu->drawSelectedMonState[whichParty]++;
|
|
|
|
Trade_MoveSelectedMonToTarget(&gSprites[sTradeMenu->partySpriteIds[selectedMonParty][partyIdx]]);
|
|
|
|
|
2019-10-10 09:50:51 +02:00
|
|
|
CopyToBgTilemapBufferRect_ChangePalette(1, sTradePartyBoxTilemap, whichParty * 15, 0, 15, 17, 0);
|
2018-12-25 15:14:15 +01:00
|
|
|
CopyBgTilemapBufferToVram(1);
|
|
|
|
CopyBgTilemapBufferToVram(0);
|
|
|
|
|
2019-10-04 13:42:45 +02:00
|
|
|
if (selectedMonParty == TRADE_PLAYER)
|
2022-12-09 18:34:55 +01:00
|
|
|
PrintTradePartnerPartyNicknames();
|
2018-12-25 15:14:15 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
2022-12-09 18:34:55 +01:00
|
|
|
// Wait for the selected pokemon's sprite to move to the correct position
|
|
|
|
if (gSprites[sTradeMenu->partySpriteIds[selectedMonParty][partyIdx]].callback == SpriteCB_MonIcon)
|
|
|
|
sTradeMenu->drawSelectedMonState[whichParty] = 3;
|
2018-12-25 15:14:15 +01:00
|
|
|
break;
|
|
|
|
case 3:
|
2022-12-09 18:34:55 +01:00
|
|
|
// Redisplay the bg box
|
2019-10-10 09:50:51 +02:00
|
|
|
CopyToBgTilemapBufferRect_ChangePalette(1, sTradeMovesBoxTilemap, selectedMonParty * 15, 0, 15, 17, 0);
|
2018-12-25 15:14:15 +01:00
|
|
|
CopyBgTilemapBufferToVram(1);
|
2022-12-09 18:34:55 +01:00
|
|
|
|
|
|
|
// Finalize the selected pokemon's position
|
|
|
|
gSprites[sTradeMenu->partySpriteIds[selectedMonParty][partyIdx]].x = (sTradeMonSpriteCoords[selectedMonParty * PARTY_SIZE][0]
|
|
|
|
+ sTradeMonSpriteCoords[selectedMonParty * PARTY_SIZE + 1][0]) / 2 * 8 + 14;
|
|
|
|
gSprites[sTradeMenu->partySpriteIds[selectedMonParty][partyIdx]].y = (sTradeMonSpriteCoords[selectedMonParty * PARTY_SIZE][1] * 8) - 12;
|
|
|
|
gSprites[sTradeMenu->partySpriteIds[selectedMonParty][partyIdx]].x2 = 0;
|
|
|
|
gSprites[sTradeMenu->partySpriteIds[selectedMonParty][partyIdx]].y2 = 0;
|
|
|
|
|
|
|
|
// Print selected pokemon's name and moves
|
2019-10-07 04:58:25 +02:00
|
|
|
nameStringWidth = GetMonNicknameWidth(nickname, selectedMonParty, partyIdx);
|
2021-10-30 22:47:37 +02:00
|
|
|
AddTextPrinterParameterized3((whichParty * 2) + 14, FONT_SMALL, (80 - nameStringWidth) / 2, 4, sTradeTextColors, 0, nickname);
|
2022-12-09 18:34:55 +01:00
|
|
|
BufferMovesString(movesString, selectedMonParty, partyIdx);
|
2021-10-30 22:47:37 +02:00
|
|
|
AddTextPrinterParameterized4((whichParty * 2) + 15, FONT_NORMAL, 0, 0, 0, 0, sTradeTextColors, 0, movesString);
|
2019-10-04 13:42:45 +02:00
|
|
|
PutWindowTilemap((whichParty * 2) + 14);
|
2021-11-03 20:29:18 +01:00
|
|
|
CopyWindowToVram((whichParty * 2) + 14, COPYWIN_FULL);
|
2019-10-04 13:42:45 +02:00
|
|
|
PutWindowTilemap((whichParty * 2) + 15);
|
2021-11-03 20:29:18 +01:00
|
|
|
CopyWindowToVram((whichParty * 2) + 15, COPYWIN_FULL);
|
2022-12-09 18:34:55 +01:00
|
|
|
|
|
|
|
sTradeMenu->drawSelectedMonState[whichParty]++;
|
2018-12-25 15:14:15 +01:00
|
|
|
break;
|
|
|
|
case 4:
|
2022-12-09 18:34:55 +01:00
|
|
|
PrintLevelAndGender(whichParty, partyIdx,
|
|
|
|
sSelectedMonLevelGenderCoords[whichParty][0] + 4,
|
|
|
|
sSelectedMonLevelGenderCoords[whichParty][1] + 1,
|
|
|
|
sSelectedMonLevelGenderCoords[whichParty][0],
|
|
|
|
sSelectedMonLevelGenderCoords[whichParty][1]);
|
|
|
|
sTradeMenu->drawSelectedMonState[whichParty]++;
|
2018-12-25 15:14:15 +01:00
|
|
|
break;
|
2018-12-21 19:20:28 +01:00
|
|
|
}
|
|
|
|
}
|
2018-12-22 08:26:53 +01:00
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static u8 GetMonNicknameWidth(u8 *str, u8 whichParty, u8 partyIdx)
|
2018-12-22 08:26:53 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
u8 nickname[POKEMON_NAME_LENGTH];
|
2018-12-22 08:26:53 +01:00
|
|
|
|
2019-10-07 04:58:25 +02:00
|
|
|
if (whichParty == TRADE_PLAYER)
|
2022-12-09 18:34:55 +01:00
|
|
|
GetMonData(&gPlayerParty[partyIdx], MON_DATA_NICKNAME, nickname);
|
2018-12-22 08:26:53 +01:00
|
|
|
else
|
2022-12-09 18:34:55 +01:00
|
|
|
GetMonData(&gEnemyParty[partyIdx], MON_DATA_NICKNAME, nickname);
|
2018-12-22 08:26:53 +01:00
|
|
|
|
2021-11-18 04:11:03 +01:00
|
|
|
StringCopy_Nickname(str, nickname);
|
2021-10-30 22:47:37 +02:00
|
|
|
return GetStringWidth(FONT_SMALL, str, GetFontAttribute(FONT_SMALL, FONTATTR_LETTER_SPACING));
|
2018-12-22 08:26:53 +01:00
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void BufferMovesString(u8 *str, u8 whichParty, u8 partyIdx)
|
2018-12-22 08:26:53 +01:00
|
|
|
{
|
2019-09-08 17:53:48 +02:00
|
|
|
u16 moves[MAX_MON_MOVES];
|
2018-12-22 08:26:53 +01:00
|
|
|
u16 i;
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
if (!sTradeMenu->isEgg[whichParty][partyIdx])
|
2018-12-22 08:26:53 +01:00
|
|
|
{
|
|
|
|
for (i = 0; i < MAX_MON_MOVES; i++)
|
|
|
|
{
|
2019-10-03 07:16:22 +02:00
|
|
|
if (whichParty == TRADE_PLAYER)
|
|
|
|
moves[i] = GetMonData(&gPlayerParty[partyIdx], i + MON_DATA_MOVE1, NULL);
|
2018-12-22 08:26:53 +01:00
|
|
|
else
|
2019-10-03 07:16:22 +02:00
|
|
|
moves[i] = GetMonData(&gEnemyParty[partyIdx], i + MON_DATA_MOVE1, NULL);
|
2018-12-22 08:26:53 +01:00
|
|
|
}
|
|
|
|
|
2019-10-11 00:46:42 +02:00
|
|
|
StringCopy(str, sText_EmptyString);
|
2018-12-22 08:26:53 +01:00
|
|
|
|
|
|
|
for (i = 0; i < MAX_MON_MOVES; i++)
|
|
|
|
{
|
2019-09-08 17:53:48 +02:00
|
|
|
if (moves[i] != MOVE_NONE)
|
2019-10-03 07:16:22 +02:00
|
|
|
StringAppend(str, gMoveNames[moves[i]]);
|
2018-12-22 08:26:53 +01:00
|
|
|
|
2019-10-10 09:50:51 +02:00
|
|
|
StringAppend(str, sText_NewLine);
|
2018-12-22 08:26:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-11 00:46:42 +02:00
|
|
|
StringCopy(str, sText_EmptyString);
|
2019-10-10 09:50:51 +02:00
|
|
|
StringAppend(str, sText_FourQuestionMarks);
|
2018-12-22 08:26:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void PrintPartyMonNickname(u8 whichParty, u8 windowId, u8 *nickname)
|
2018-12-22 08:26:53 +01:00
|
|
|
{
|
|
|
|
u8 xPos;
|
2018-12-31 09:22:21 +01:00
|
|
|
windowId += (whichParty * PARTY_SIZE) + 2;
|
2021-10-30 22:47:37 +02:00
|
|
|
xPos = GetStringCenterAlignXOffset(FONT_SMALL, nickname, 64);
|
|
|
|
AddTextPrinterParameterized3(windowId, FONT_SMALL, xPos, 4, sTradeTextColors, 0, nickname);
|
2018-12-31 09:22:21 +01:00
|
|
|
PutWindowTilemap(windowId);
|
2021-11-03 20:29:18 +01:00
|
|
|
CopyWindowToVram(windowId, COPYWIN_FULL);
|
2018-12-22 08:26:53 +01:00
|
|
|
}
|
2018-12-23 08:26:38 +01:00
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void PrintPartyNicknames(u8 whichParty)
|
2018-12-23 08:26:38 +01:00
|
|
|
{
|
|
|
|
u8 i;
|
2019-10-04 01:39:37 +02:00
|
|
|
u8 nickname[20];
|
|
|
|
u8 str[32];
|
|
|
|
struct Pokemon *party = (whichParty == TRADE_PLAYER) ? gPlayerParty : gEnemyParty;
|
2018-12-23 08:26:38 +01:00
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
for (i = 0; i < sTradeMenu->partyCounts[whichParty]; i++)
|
2018-12-23 08:26:38 +01:00
|
|
|
{
|
2019-10-04 01:39:37 +02:00
|
|
|
GetMonData(&party[i], MON_DATA_NICKNAME, nickname);
|
2021-11-18 04:11:03 +01:00
|
|
|
StringCopy_Nickname(str, nickname);
|
2022-12-09 18:34:55 +01:00
|
|
|
PrintPartyMonNickname(whichParty, i, str);
|
2018-12-23 08:26:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void PrintLevelAndGender(u8 whichParty, u8 monIdx, u8 x, u8 y, u8 width, u8 height)
|
2018-12-23 08:26:38 +01:00
|
|
|
{
|
2018-12-31 09:22:21 +01:00
|
|
|
u8 level;
|
2019-10-07 04:58:25 +02:00
|
|
|
u32 symbolTile;
|
2018-12-23 08:26:38 +01:00
|
|
|
u8 gender;
|
2022-12-09 18:34:55 +01:00
|
|
|
u8 nickname[POKEMON_NAME_LENGTH];
|
2018-12-23 08:26:38 +01:00
|
|
|
|
2019-10-09 11:56:44 +02:00
|
|
|
CopyToBgTilemapBufferRect_ChangePalette(1, gTradeMenuMonBox_Tilemap, width, height, 6, 3, 0);
|
2018-12-23 08:26:38 +01:00
|
|
|
CopyBgTilemapBufferToVram(1);
|
|
|
|
|
2019-10-03 07:16:22 +02:00
|
|
|
if (whichParty == TRADE_PLAYER)
|
2018-12-31 09:22:21 +01:00
|
|
|
level = GetMonData(&gPlayerParty[monIdx], MON_DATA_LEVEL, NULL);
|
2018-12-23 08:26:38 +01:00
|
|
|
else
|
2018-12-31 09:22:21 +01:00
|
|
|
level = GetMonData(&gEnemyParty[monIdx], MON_DATA_LEVEL, NULL);
|
2018-12-23 08:26:38 +01:00
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
if (!sTradeMenu->isEgg[whichParty][monIdx])
|
2018-12-23 08:26:38 +01:00
|
|
|
{
|
2018-12-31 09:22:21 +01:00
|
|
|
if (level / 10 != 0)
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->tilemapBuffer[x + (y * 32)] = (level / 10) + 0x60;
|
2018-12-31 09:22:21 +01:00
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->tilemapBuffer[x + (y * 32) + 1] = (level % 10) + 0x70;
|
2018-12-23 08:26:38 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->tilemapBuffer[x + (y * 32) - 32] = sTradeMenu->tilemapBuffer[x + (y * 32) - 33];
|
|
|
|
sTradeMenu->tilemapBuffer[x + (y * 32) - 31] = sTradeMenu->tilemapBuffer[x + (y * 32) - 36] | 0x400;
|
2018-12-23 08:26:38 +01:00
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
if (sTradeMenu->isEgg[whichParty][monIdx])
|
2018-12-23 08:26:38 +01:00
|
|
|
{
|
2019-10-07 04:58:25 +02:00
|
|
|
symbolTile = 0x480;
|
2018-12-23 08:26:38 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-03 07:16:22 +02:00
|
|
|
if (whichParty == TRADE_PLAYER)
|
2018-12-23 08:26:38 +01:00
|
|
|
{
|
2018-12-31 09:22:21 +01:00
|
|
|
gender = GetMonGender(&gPlayerParty[monIdx]);
|
|
|
|
GetMonData(&gPlayerParty[monIdx], MON_DATA_NICKNAME, nickname);
|
2018-12-23 08:26:38 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-31 09:22:21 +01:00
|
|
|
gender = GetMonGender(&gEnemyParty[monIdx]);
|
|
|
|
GetMonData(&gEnemyParty[monIdx], MON_DATA_NICKNAME, nickname);
|
2018-12-23 08:26:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (gender)
|
|
|
|
{
|
2019-10-09 15:55:06 +02:00
|
|
|
case MON_MALE:
|
|
|
|
symbolTile = !NameHasGenderSymbol(nickname, MON_MALE) ? 0x84 : 0x83;
|
|
|
|
break;
|
|
|
|
case MON_FEMALE:
|
|
|
|
symbolTile = !NameHasGenderSymbol(nickname, MON_FEMALE) ? 0x85 : 0x83;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
symbolTile = 0x83;
|
|
|
|
break;
|
2018-12-23 08:26:38 +01:00
|
|
|
}
|
|
|
|
}
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->tilemapBuffer[(y - 1) * 32 + x + 1] = symbolTile;
|
2018-12-23 08:26:38 +01:00
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void PrintPartyLevelsAndGenders(u8 whichParty)
|
2018-12-23 08:26:38 +01:00
|
|
|
{
|
2019-12-20 23:09:59 +01:00
|
|
|
s32 i;
|
2022-12-09 18:34:55 +01:00
|
|
|
for (i = 0; i < sTradeMenu->partyCounts[whichParty]; i++)
|
2018-12-23 08:26:38 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
s32 j = i + PARTY_SIZE * whichParty;
|
|
|
|
PrintLevelAndGender(
|
2019-12-20 23:09:59 +01:00
|
|
|
whichParty,
|
|
|
|
i,
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMonLevelCoords[j][0],
|
|
|
|
sTradeMonLevelCoords[j][1],
|
|
|
|
sTradeMonBoxCoords[j][0],
|
|
|
|
sTradeMonBoxCoords[j][1]
|
2019-12-20 23:09:59 +01:00
|
|
|
);
|
2018-12-23 08:26:38 +01:00
|
|
|
}
|
|
|
|
}
|
2018-12-24 10:03:02 +01:00
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void ShowTradePartyMonIcons(u8 whichParty)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
for (i = 0; i < sTradeMenu->partyCounts[whichParty]; i++)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
gSprites[sTradeMenu->partySpriteIds[whichParty][i]].invisible = FALSE;
|
|
|
|
gSprites[sTradeMenu->partySpriteIds[whichParty][i]].x = sTradeMonSpriteCoords[(whichParty * PARTY_SIZE) + i][0] * 8 + 14;
|
|
|
|
gSprites[sTradeMenu->partySpriteIds[whichParty][i]].y = sTradeMonSpriteCoords[(whichParty * PARTY_SIZE) + i][1] * 8 - 12;
|
|
|
|
gSprites[sTradeMenu->partySpriteIds[whichParty][i]].x2 = 0;
|
|
|
|
gSprites[sTradeMenu->partySpriteIds[whichParty][i]].y2 = 0;
|
2018-12-24 10:03:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void PrintTradePartnerPartyNicknames(void)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
|
|
|
rbox_fill_rectangle(1);
|
2022-12-09 18:34:55 +01:00
|
|
|
//PrintPartyNicknames(TRADE_PLAYER); ?
|
|
|
|
PrintPartyNicknames(TRADE_PARTNER);
|
2018-12-24 10:03:02 +01:00
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
// Returning to the party selection screen from the "is this trade ok?" screen
|
|
|
|
static void RedrawPartyWindow(u8 whichParty)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
2019-10-10 09:50:51 +02:00
|
|
|
CopyToBgTilemapBufferRect_ChangePalette(1, sTradePartyBoxTilemap, whichParty * 15, 0, 15, 17, 0);
|
2018-12-24 10:03:02 +01:00
|
|
|
CopyBgTilemapBufferToVram(1);
|
2022-12-09 18:34:55 +01:00
|
|
|
PrintPartyLevelsAndGenders(whichParty);
|
|
|
|
PrintPartyNicknames(whichParty);
|
|
|
|
ShowTradePartyMonIcons(whichParty);
|
|
|
|
DrawBottomRowText(sActionTexts[TEXT_CHOOSE_MON], (void *)(OBJ_VRAM0 + (sTradeMenu->bottomTextTileStart * 32)), 24);
|
|
|
|
sTradeMenu->drawSelectedMonState[whichParty] = 0;
|
2018-12-24 10:03:02 +01:00
|
|
|
}
|
|
|
|
|
2019-10-10 09:50:51 +02:00
|
|
|
static void Task_DrawSelectionSummary(u8 taskId)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
2022-09-26 18:22:27 +02:00
|
|
|
FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, DISPLAY_TILE_WIDTH, DISPLAY_TILE_HEIGHT);
|
2018-12-24 10:03:02 +01:00
|
|
|
CopyBgTilemapBufferToVram(0);
|
|
|
|
}
|
|
|
|
|
2019-10-10 09:50:51 +02:00
|
|
|
static void Task_DrawSelectionTrade(u8 taskId)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
2022-09-26 18:22:27 +02:00
|
|
|
FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, DISPLAY_TILE_WIDTH, DISPLAY_TILE_HEIGHT);
|
2018-12-24 10:03:02 +01:00
|
|
|
CopyBgTilemapBufferToVram(0);
|
|
|
|
}
|
|
|
|
|
2019-10-07 04:58:25 +02:00
|
|
|
static void QueueAction(u16 delay, u8 actionId)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
for (i = 0; i < (int)ARRAY_COUNT(sTradeMenu->queuedActions); i++)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
// Find first available spot
|
|
|
|
if (!sTradeMenu->queuedActions[i].active)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->queuedActions[i].delay = delay;
|
|
|
|
sTradeMenu->queuedActions[i].actionId = actionId;
|
|
|
|
sTradeMenu->queuedActions[i].active = TRUE;
|
2018-12-24 10:03:02 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-07 04:58:25 +02:00
|
|
|
static u32 GetNumQueuedActions(void)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
2019-10-07 04:58:25 +02:00
|
|
|
u32 numActions = 0;
|
2018-12-24 10:03:02 +01:00
|
|
|
int i;
|
2018-12-25 15:14:15 +01:00
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
for (i = 0; i < (int)ARRAY_COUNT(sTradeMenu->queuedActions); i++)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
numActions += sTradeMenu->queuedActions[i].active;
|
2018-12-24 10:03:02 +01:00
|
|
|
}
|
|
|
|
|
2019-10-07 04:58:25 +02:00
|
|
|
return numActions;
|
2018-12-24 10:03:02 +01:00
|
|
|
}
|
|
|
|
|
2019-10-07 04:58:25 +02:00
|
|
|
static void DoQueuedActions(void)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
for (i = 0; i < (int)ARRAY_COUNT(sTradeMenu->queuedActions); i++)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
if (sTradeMenu->queuedActions[i].active)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
if (sTradeMenu->queuedActions[i].delay != 0)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->queuedActions[i].delay--;
|
2018-12-24 10:03:02 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
switch (sTradeMenu->queuedActions[i].actionId)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
2019-10-09 15:55:06 +02:00
|
|
|
case QUEUE_SEND_DATA:
|
2022-12-09 18:34:55 +01:00
|
|
|
SendLinkData(sTradeMenu->linkData, 20);
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
|
|
|
case QUEUE_STANDBY:
|
2022-12-09 18:34:55 +01:00
|
|
|
PrintTradeMessage(MSG_STANDBY);
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
|
|
|
case QUEUE_ONLY_MON1:
|
2022-12-09 18:34:55 +01:00
|
|
|
PrintTradeMessage(MSG_ONLY_MON1);
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
|
|
|
case QUEUE_ONLY_MON2:
|
|
|
|
case QUEUE_UNUSED1:
|
|
|
|
case QUEUE_UNUSED2:
|
2022-12-09 18:34:55 +01:00
|
|
|
PrintTradeMessage(MSG_ONLY_MON2);
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
|
|
|
case QUEUE_MON_CANT_BE_TRADED:
|
2022-12-09 18:34:55 +01:00
|
|
|
PrintTradeMessage(MSG_MON_CANT_BE_TRADED);
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
|
|
|
case QUEUE_EGG_CANT_BE_TRADED:
|
2022-12-09 18:34:55 +01:00
|
|
|
PrintTradeMessage(MSG_EGG_CANT_BE_TRADED);
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
|
|
|
case QUEUE_FRIENDS_MON_CANT_BE_TRADED:
|
2022-12-09 18:34:55 +01:00
|
|
|
PrintTradeMessage(MSG_FRIENDS_MON_CANT_BE_TRADED);
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2018-12-24 10:03:02 +01:00
|
|
|
}
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->queuedActions[i].active = FALSE;
|
2018-12-24 10:03:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-04 01:39:37 +02:00
|
|
|
static void PrintTradeMessage(u8 messageId)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
2019-03-02 23:25:39 +01:00
|
|
|
FillWindowPixelBuffer(0, PIXEL_FILL(1));
|
2022-12-09 18:34:55 +01:00
|
|
|
AddTextPrinterParameterized(0, FONT_NORMAL, sMessages[messageId], 0, 1, TEXT_SKIP_DRAW, NULL);
|
2019-04-01 00:59:52 +02:00
|
|
|
DrawTextBorderOuter(0, 20, 12);
|
2018-12-24 10:03:02 +01:00
|
|
|
PutWindowTilemap(0);
|
2021-11-03 20:29:18 +01:00
|
|
|
CopyWindowToVram(0, COPYWIN_FULL);
|
2018-12-24 10:03:02 +01:00
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static bool8 LoadUISpriteGfx(void)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
|
|
|
struct SpriteSheet sheet;
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
if (sTradeMenu->timer < NUM_MENU_TEXT_SPRITES)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
sheet.data = sMenuTextTileBuffers[sTradeMenu->timer];
|
2018-12-24 10:03:02 +01:00
|
|
|
sheet.size = 0x100;
|
2022-12-09 18:34:55 +01:00
|
|
|
sheet.tag = GFXTAG_MENU_TEXT + sTradeMenu->timer;
|
2018-12-24 10:03:02 +01:00
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
switch (sTradeMenu->timer)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
2021-04-19 02:12:12 +02:00
|
|
|
case GFXTAG_PLAYER_NAME_L:
|
|
|
|
case GFXTAG_PLAYER_NAME_M:
|
|
|
|
case GFXTAG_PLAYER_NAME_R:
|
|
|
|
case GFXTAG_PARTNER_NAME_L:
|
|
|
|
case GFXTAG_PARTNER_NAME_M:
|
|
|
|
case GFXTAG_PARTNER_NAME_R:
|
|
|
|
case GFXTAG_CANCEL_L:
|
|
|
|
case GFXTAG_CANCEL_R:
|
2019-10-09 15:55:06 +02:00
|
|
|
LoadSpriteSheet(&sheet);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->timer++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2021-04-19 02:12:12 +02:00
|
|
|
case GFXTAG_CHOOSE_PKMN_L:
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->bottomTextTileStart = LoadSpriteSheet(&sheet);
|
|
|
|
sTradeMenu->timer++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2021-04-19 02:12:12 +02:00
|
|
|
case GFXTAG_CHOOSE_PKMN_M:
|
|
|
|
case GFXTAG_CHOOSE_PKMN_R:
|
|
|
|
case GFXTAG_CHOOSE_PKMN_EMPTY_1:
|
|
|
|
case GFXTAG_CHOOSE_PKMN_EMPTY_2:
|
|
|
|
case GFXTAG_CHOOSE_PKMN_EMPTY_3:
|
2019-10-09 15:55:06 +02:00
|
|
|
LoadSpriteSheet(&sheet);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->timer++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-09 18:34:55 +01:00
|
|
|
case NUM_MENU_TEXT_SPRITES:
|
|
|
|
LoadSpritePalette(&sSpritePalette_MenuText);
|
|
|
|
sTradeMenu->timer++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-09 18:34:55 +01:00
|
|
|
case NUM_MENU_TEXT_SPRITES + 1:
|
2021-04-19 02:12:12 +02:00
|
|
|
LoadSpritePalette(&sCursor_SpritePalette);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->timer++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-09 18:34:55 +01:00
|
|
|
case NUM_MENU_TEXT_SPRITES + 2:
|
2021-04-19 02:12:12 +02:00
|
|
|
LoadSpriteSheet(&sCursor_SpriteSheet);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->timer++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-09 18:34:55 +01:00
|
|
|
case NUM_MENU_TEXT_SPRITES + 3:
|
|
|
|
sTradeMenu->timer = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
return TRUE;
|
2018-12-24 10:03:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-04-19 02:12:12 +02:00
|
|
|
static void DrawBottomRowText(const u8 *str, u8 *dest, u8 unused)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
2019-10-07 04:58:25 +02:00
|
|
|
DrawTextWindowAndBufferTiles(str, dest, 0, 0, 6);
|
2018-12-24 10:03:02 +01:00
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void ComputePartyTradeableFlags(u8 whichParty)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2019-10-03 07:16:22 +02:00
|
|
|
switch (whichParty)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
2019-10-03 07:16:22 +02:00
|
|
|
case TRADE_PLAYER:
|
2022-12-09 18:34:55 +01:00
|
|
|
for (i = 0; i < sTradeMenu->partyCounts[whichParty]; i++)
|
2019-10-03 07:16:22 +02:00
|
|
|
{
|
|
|
|
if (GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG) == TRUE)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->isLiveMon[whichParty][i] = FALSE;
|
|
|
|
sTradeMenu->isEgg[whichParty][i] = TRUE;
|
2018-12-24 10:03:02 +01:00
|
|
|
}
|
2019-10-03 07:16:22 +02:00
|
|
|
else if (GetMonData(&gPlayerParty[i], MON_DATA_HP) == 0)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->isLiveMon[whichParty][i] = FALSE;
|
|
|
|
sTradeMenu->isEgg[whichParty][i] = FALSE;
|
2018-12-24 10:03:02 +01:00
|
|
|
}
|
2019-10-03 07:16:22 +02:00
|
|
|
else
|
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->isLiveMon[whichParty][i] = TRUE;
|
|
|
|
sTradeMenu->isEgg[whichParty][i] = FALSE;
|
2019-10-03 07:16:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TRADE_PARTNER:
|
2022-12-09 18:34:55 +01:00
|
|
|
for (i = 0; i < sTradeMenu->partyCounts[whichParty]; i++)
|
2019-10-03 07:16:22 +02:00
|
|
|
{
|
|
|
|
if (GetMonData(&gEnemyParty[i], MON_DATA_IS_EGG) == TRUE)
|
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->isLiveMon[whichParty][i] = FALSE;
|
|
|
|
sTradeMenu->isEgg[whichParty][i] = TRUE;
|
2019-10-03 07:16:22 +02:00
|
|
|
}
|
|
|
|
else if (GetMonData(&gEnemyParty[i], MON_DATA_HP) == 0)
|
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->isLiveMon[whichParty][i] = FALSE;
|
|
|
|
sTradeMenu->isEgg[whichParty][i] = FALSE;
|
2019-10-03 07:16:22 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->isLiveMon[whichParty][i] = TRUE;
|
|
|
|
sTradeMenu->isEgg[whichParty][i] = FALSE;
|
2019-10-03 07:16:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2018-12-24 10:03:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
static void ComputePartyHPBarLevels(u8 whichParty)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
2018-12-28 09:11:41 +01:00
|
|
|
u16 i, curHp, maxHp;
|
2018-12-24 10:03:02 +01:00
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
switch (whichParty)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
2019-10-09 15:55:06 +02:00
|
|
|
case TRADE_PLAYER:
|
2022-12-09 18:34:55 +01:00
|
|
|
for (i = 0; i < sTradeMenu->partyCounts[TRADE_PLAYER]; i++)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
|
|
|
curHp = GetMonData(&gPlayerParty[i], MON_DATA_HP);
|
|
|
|
maxHp = GetMonData(&gPlayerParty[i], MON_DATA_MAX_HP);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->hpBarLevels[TRADE_PLAYER][i] = GetHPBarLevel(curHp, maxHp);
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TRADE_PARTNER:
|
2022-12-09 18:34:55 +01:00
|
|
|
for (i = 0; i < sTradeMenu->partyCounts[TRADE_PARTNER]; i++)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
|
|
|
curHp = GetMonData(&gEnemyParty[i], MON_DATA_HP);
|
|
|
|
maxHp = GetMonData(&gEnemyParty[i], MON_DATA_MAX_HP);
|
2022-12-09 18:34:55 +01:00
|
|
|
sTradeMenu->hpBarLevels[TRADE_PARTNER][i] = GetHPBarLevel(curHp, maxHp);
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2018-12-24 10:03:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-04 01:39:37 +02:00
|
|
|
static void SetTradePartyHPBarSprites(void)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
|
|
|
int i, j;
|
2018-12-25 15:14:15 +01:00
|
|
|
|
2019-10-04 01:39:37 +02:00
|
|
|
for (i = 0; i < 2; i++)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
for (j = 0; j < sTradeMenu->partyCounts[i]; j++)
|
|
|
|
SetPartyHPBarSprite(&gSprites[sTradeMenu->partySpriteIds[i][j]], 4 - sTradeMenu->hpBarLevels[i][j]);
|
2018-12-24 10:03:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-09 11:56:44 +02:00
|
|
|
static void SaveTradeGiftRibbons(void)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
for (i = 0; i < (int)ARRAY_COUNT(sTradeMenu->giftRibbons); i++)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
if (gSaveBlock1Ptr->giftRibbons[i] == 0 && sTradeMenu->giftRibbons[i] != 0)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
2023-02-12 03:16:24 +01:00
|
|
|
if (sTradeMenu->giftRibbons[i] < MAX_GIFT_RIBBON)
|
2022-12-09 18:34:55 +01:00
|
|
|
gSaveBlock1Ptr->giftRibbons[i] = sTradeMenu->giftRibbons[i];
|
2018-12-24 10:03:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-07 04:58:25 +02:00
|
|
|
static u32 CanTradeSelectedMon(struct Pokemon *playerParty, int partyCount, int monIdx)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
2019-10-10 09:50:51 +02:00
|
|
|
int i, numMonsLeft;
|
2022-12-09 18:34:55 +01:00
|
|
|
struct LinkPlayer *partner;
|
2019-10-04 01:39:37 +02:00
|
|
|
u32 species[PARTY_SIZE];
|
|
|
|
u32 species2[PARTY_SIZE];
|
2018-12-24 10:03:02 +01:00
|
|
|
|
2019-10-04 01:39:37 +02:00
|
|
|
for (i = 0; i < partyCount; i++)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
2023-02-24 11:53:02 +01:00
|
|
|
species2[i] = GetMonData(&playerParty[i], MON_DATA_SPECIES_OR_EGG);
|
2019-10-04 01:39:37 +02:00
|
|
|
species[i] = GetMonData(&playerParty[i], MON_DATA_SPECIES);
|
2018-12-24 10:03:02 +01:00
|
|
|
}
|
|
|
|
|
2019-10-07 04:58:25 +02:00
|
|
|
// Cant trade Eggs or non-Hoenn mons if player doesn't have National Dex
|
2018-12-24 10:03:02 +01:00
|
|
|
if (!IsNationalPokedexEnabled())
|
|
|
|
{
|
2018-12-31 09:22:21 +01:00
|
|
|
if (species2[monIdx] == SPECIES_EGG)
|
2019-10-18 01:22:03 +02:00
|
|
|
return CANT_TRADE_EGG_YET;
|
2018-12-24 10:03:02 +01:00
|
|
|
|
2018-12-31 09:22:21 +01:00
|
|
|
if (!IsSpeciesInHoennDex(species2[monIdx]))
|
2019-10-07 04:58:25 +02:00
|
|
|
return CANT_TRADE_NATIONAL;
|
2018-12-24 10:03:02 +01:00
|
|
|
}
|
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
partner = &gLinkPlayers[GetMultiplayerId() ^ 1];
|
|
|
|
if ((partner->version & 0xFF) != VERSION_RUBY &&
|
|
|
|
(partner->version & 0xFF) != VERSION_SAPPHIRE)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
2019-10-10 09:50:51 +02:00
|
|
|
// Does partner not have National Dex
|
2022-12-09 18:34:55 +01:00
|
|
|
if (!(partner->progressFlagsCopy & 0xF))
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
2018-12-31 09:22:21 +01:00
|
|
|
if (species2[monIdx] == SPECIES_EGG)
|
2022-12-09 18:34:55 +01:00
|
|
|
return CANT_TRADE_PARTNER_EGG_YET;
|
2018-12-25 15:14:15 +01:00
|
|
|
|
2018-12-31 09:22:21 +01:00
|
|
|
if (!IsSpeciesInHoennDex(species2[monIdx]))
|
2019-10-07 04:58:25 +02:00
|
|
|
return CANT_TRADE_INVALID_MON;
|
2018-12-24 10:03:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 09:22:21 +01:00
|
|
|
if (species[monIdx] == SPECIES_DEOXYS || species[monIdx] == SPECIES_MEW)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
2023-02-15 17:56:11 +01:00
|
|
|
if (!GetMonData(&playerParty[monIdx], MON_DATA_MODERN_FATEFUL_ENCOUNTER))
|
2019-10-07 04:58:25 +02:00
|
|
|
return CANT_TRADE_INVALID_MON;
|
2018-12-24 10:03:02 +01:00
|
|
|
}
|
|
|
|
|
2019-10-10 09:50:51 +02:00
|
|
|
// Make Eggs not count for numMonsLeft
|
2019-10-04 01:39:37 +02:00
|
|
|
for (i = 0; i < partyCount; i++)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
|
|
|
if (species2[i] == SPECIES_EGG)
|
|
|
|
species2[i] = SPECIES_NONE;
|
|
|
|
}
|
|
|
|
|
2019-10-07 04:58:25 +02:00
|
|
|
// Count alive mons in party, excluding selected trade mon
|
2019-10-10 09:50:51 +02:00
|
|
|
for (numMonsLeft = 0, i = 0; i < partyCount; i++)
|
2018-12-24 10:03:02 +01:00
|
|
|
{
|
2018-12-31 09:22:21 +01:00
|
|
|
if (i != monIdx)
|
2019-10-10 09:50:51 +02:00
|
|
|
numMonsLeft += species2[i];
|
2018-12-24 10:03:02 +01:00
|
|
|
}
|
|
|
|
|
2019-10-10 09:50:51 +02:00
|
|
|
if (numMonsLeft != 0)
|
2019-10-07 04:58:25 +02:00
|
|
|
return CAN_TRADE_MON;
|
2018-12-24 10:03:02 +01:00
|
|
|
else
|
2019-10-07 04:58:25 +02:00
|
|
|
return CANT_TRADE_LAST_MON;
|
2018-12-24 10:03:02 +01:00
|
|
|
}
|
2018-12-24 21:39:05 +01:00
|
|
|
|
2019-10-10 09:50:51 +02:00
|
|
|
s32 GetGameProgressForLinkTrade(void)
|
2018-12-24 21:39:05 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
// The usage of this value is a little unusual given it's treated as a bool,
|
|
|
|
// but it's the result of its usage in FRLG, where 0 is FRLG, 1 is RS, and 2 is Emerald.
|
|
|
|
s32 versionId; // 0: RSE, 2: FRLG
|
2018-12-25 15:14:15 +01:00
|
|
|
u16 version;
|
|
|
|
|
2022-09-05 02:24:12 +02:00
|
|
|
if (gReceivedRemoteLinkPlayers)
|
2018-12-24 21:39:05 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
versionId = 0;
|
2018-12-24 21:39:05 +01:00
|
|
|
version = (gLinkPlayers[GetMultiplayerId() ^ 1].version & 0xFF);
|
2018-12-25 15:14:15 +01:00
|
|
|
|
|
|
|
if (version == VERSION_RUBY || version == VERSION_SAPPHIRE || version == VERSION_EMERALD)
|
2022-12-09 18:34:55 +01:00
|
|
|
versionId = 0;
|
2018-12-25 15:14:15 +01:00
|
|
|
else if (version == VERSION_FIRE_RED || version == VERSION_LEAF_GREEN)
|
2022-12-09 18:34:55 +01:00
|
|
|
versionId = 2;
|
2018-12-24 21:39:05 +01:00
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
// If trading with FRLG, both players must have progessed the story enough
|
|
|
|
if (versionId > 0)
|
2018-12-24 21:39:05 +01:00
|
|
|
{
|
2019-10-10 09:50:51 +02:00
|
|
|
// Is player champion
|
2019-10-09 15:55:06 +02:00
|
|
|
if (gLinkPlayers[GetMultiplayerId()].progressFlagsCopy & 0xF0)
|
2018-12-24 21:39:05 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
if (versionId == 2) // Check is only relevant in FRLG, this will always be true
|
2018-12-24 21:39:05 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
// Has FRLG partner finished the Sevii Islands
|
2019-10-09 11:56:44 +02:00
|
|
|
if (gLinkPlayers[GetMultiplayerId() ^ 1].progressFlagsCopy & 0xF0)
|
2019-10-10 09:50:51 +02:00
|
|
|
return TRADE_BOTH_PLAYERS_READY;
|
2018-12-24 21:39:05 +01:00
|
|
|
else
|
2019-10-10 09:50:51 +02:00
|
|
|
return TRADE_PARTNER_NOT_READY;
|
2018-12-24 21:39:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-10 09:50:51 +02:00
|
|
|
return TRADE_PLAYER_NOT_READY;
|
2018-12-24 21:39:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-10-10 09:50:51 +02:00
|
|
|
return TRADE_BOTH_PLAYERS_READY;
|
2018-12-24 21:39:05 +01:00
|
|
|
}
|
2018-12-25 03:18:06 +01:00
|
|
|
|
2023-02-12 02:36:42 +01:00
|
|
|
static bool32 IsDeoxysOrMewUntradable(u16 species, bool8 isModernFatefulEncounter)
|
2018-12-25 03:18:06 +01:00
|
|
|
{
|
2018-12-31 09:22:21 +01:00
|
|
|
if (species == SPECIES_DEOXYS || species == SPECIES_MEW)
|
2018-12-25 03:18:06 +01:00
|
|
|
{
|
2023-02-12 02:36:42 +01:00
|
|
|
if (!isModernFatefulEncounter)
|
2018-12-25 03:18:06 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2023-02-12 02:36:42 +01:00
|
|
|
int GetUnionRoomTradeMessageId(struct RfuGameCompatibilityData player, struct RfuGameCompatibilityData partner, u16 playerSpecies2, u16 partnerSpecies, u8 requestedType, u16 playerSpecies, bool8 isModernFatefulEncounter)
|
2018-12-25 03:18:06 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
bool8 playerHasNationalDex = player.hasNationalDex;
|
2022-12-09 18:34:55 +01:00
|
|
|
bool8 playerCanLinkNationally = player.canLinkNationally;
|
2021-10-06 05:38:36 +02:00
|
|
|
bool8 partnerHasNationalDex = partner.hasNationalDex;
|
2022-12-09 18:34:55 +01:00
|
|
|
bool8 partnerCanLinkNationally = partner.canLinkNationally;
|
2021-10-06 05:38:36 +02:00
|
|
|
u8 partnerVersion = partner.version;
|
2018-12-25 03:18:06 +01:00
|
|
|
|
2022-12-09 18:34:55 +01:00
|
|
|
// If partner is not using Emerald, both players must have progressed the story
|
|
|
|
// to a certain point (becoming champion in RSE, finishing the Sevii islands in FRLG)
|
2021-10-06 05:38:36 +02:00
|
|
|
if (partnerVersion != VERSION_EMERALD)
|
2018-12-25 03:18:06 +01:00
|
|
|
{
|
2022-12-09 18:34:55 +01:00
|
|
|
if (!playerCanLinkNationally)
|
2019-10-04 23:24:03 +02:00
|
|
|
return UR_TRADE_MSG_CANT_TRADE_WITH_PARTNER_1;
|
2022-12-09 18:34:55 +01:00
|
|
|
else if (!partnerCanLinkNationally)
|
2019-10-04 23:24:03 +02:00
|
|
|
return UR_TRADE_MSG_CANT_TRADE_WITH_PARTNER_2;
|
2018-12-25 03:18:06 +01:00
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
// Cannot trade illegitimate Deoxys/Mew
|
2023-02-12 02:36:42 +01:00
|
|
|
if (IsDeoxysOrMewUntradable(playerSpecies, isModernFatefulEncounter))
|
2019-10-04 23:24:03 +02:00
|
|
|
return UR_TRADE_MSG_MON_CANT_BE_TRADED_2;
|
2018-12-25 03:18:06 +01:00
|
|
|
|
2019-10-04 23:24:03 +02:00
|
|
|
if (partnerSpecies == SPECIES_EGG)
|
2018-12-25 03:18:06 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
// If partner is trading an Egg then the player must also be trading an Egg
|
2019-10-04 23:24:03 +02:00
|
|
|
if (playerSpecies2 != partnerSpecies)
|
|
|
|
return UR_TRADE_MSG_NOT_EGG;
|
2018-12-25 03:18:06 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
// Player's Pokémon must be of the type the partner requested
|
2022-11-22 21:05:25 +01:00
|
|
|
if (gSpeciesInfo[playerSpecies2].types[0] != requestedType
|
|
|
|
&& gSpeciesInfo[playerSpecies2].types[1] != requestedType)
|
2019-10-04 23:24:03 +02:00
|
|
|
return UR_TRADE_MSG_NOT_MON_PARTNER_WANTS;
|
2018-12-25 03:18:06 +01:00
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
// If the player is trading an Egg then the partner must also be trading an Egg
|
|
|
|
// Odd that this wasn't checked earlier, as by this point we know either the partner doesn't have an Egg or that both do.
|
2019-10-04 23:24:03 +02:00
|
|
|
if (playerSpecies2 == SPECIES_EGG && playerSpecies2 != partnerSpecies)
|
|
|
|
return UR_TRADE_MSG_MON_CANT_BE_TRADED_1;
|
2018-12-25 03:18:06 +01:00
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
// If the player doesn't have the National Dex then Eggs and non-Hoenn Pokémon can't be traded
|
2019-10-04 23:24:03 +02:00
|
|
|
if (!playerHasNationalDex)
|
2018-12-25 03:18:06 +01:00
|
|
|
{
|
2019-10-04 23:24:03 +02:00
|
|
|
if (playerSpecies2 == SPECIES_EGG)
|
|
|
|
return UR_TRADE_MSG_EGG_CANT_BE_TRADED;
|
2019-01-05 19:25:46 +01:00
|
|
|
|
2019-10-04 23:24:03 +02:00
|
|
|
if (!IsSpeciesInHoennDex(playerSpecies2))
|
|
|
|
return UR_TRADE_MSG_MON_CANT_BE_TRADED_2;
|
2018-12-25 03:18:06 +01:00
|
|
|
|
2019-10-04 23:24:03 +02:00
|
|
|
if (!IsSpeciesInHoennDex(partnerSpecies))
|
|
|
|
return UR_TRADE_MSG_PARTNERS_MON_CANT_BE_TRADED;
|
2018-12-25 03:18:06 +01:00
|
|
|
}
|
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
// If the partner doesn't have the National Dex then the player's offer has to be a Hoenn Pokémon
|
2019-10-04 23:24:03 +02:00
|
|
|
if (!partnerHasNationalDex && !IsSpeciesInHoennDex(playerSpecies2))
|
|
|
|
return UR_TRADE_MSG_PARTNER_CANT_ACCEPT_MON;
|
2018-12-25 03:18:06 +01:00
|
|
|
|
2021-10-06 05:38:36 +02:00
|
|
|
// Trade is allowed
|
2019-10-04 23:24:03 +02:00
|
|
|
return UR_TRADE_MSG_NONE;
|
2018-12-25 03:18:06 +01:00
|
|
|
}
|
2018-12-27 09:05:09 +01:00
|
|
|
|
2023-02-12 02:36:42 +01:00
|
|
|
int CanRegisterMonForTradingBoard(struct RfuGameCompatibilityData player, u16 species2, u16 species, bool8 isModernFatefulEncounter)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
2021-10-06 05:38:36 +02:00
|
|
|
bool8 hasNationalDex = player.hasNationalDex;
|
2018-12-27 09:05:09 +01:00
|
|
|
|
2023-02-12 02:36:42 +01:00
|
|
|
if (IsDeoxysOrMewUntradable(species, isModernFatefulEncounter))
|
2019-10-05 05:31:25 +02:00
|
|
|
return CANT_REGISTER_MON;
|
2018-12-27 09:05:09 +01:00
|
|
|
|
2019-10-05 05:31:25 +02:00
|
|
|
if (hasNationalDex)
|
|
|
|
return CAN_REGISTER_MON;
|
2018-12-27 09:05:09 +01:00
|
|
|
|
2019-10-05 05:31:25 +02:00
|
|
|
// Eggs can only be traded if the player has the National Dex
|
2019-10-04 13:42:45 +02:00
|
|
|
if (species2 == SPECIES_EGG)
|
2019-10-05 05:31:25 +02:00
|
|
|
return CANT_REGISTER_EGG;
|
2018-12-27 09:05:09 +01:00
|
|
|
|
2019-10-04 13:42:45 +02:00
|
|
|
if (IsSpeciesInHoennDex(species2))
|
2019-10-05 05:31:25 +02:00
|
|
|
return CAN_REGISTER_MON;
|
2018-12-27 09:05:09 +01:00
|
|
|
|
2019-10-05 05:31:25 +02:00
|
|
|
return CANT_REGISTER_MON;
|
2018-12-27 09:05:09 +01:00
|
|
|
}
|
|
|
|
|
2019-10-18 01:22:03 +02:00
|
|
|
// Spin Trade wasnt fully implemented, but this checks if a mon would be valid to Spin Trade
|
|
|
|
// Unlike later generations, this version of Spin Trade isnt only for Eggs
|
|
|
|
int CanSpinTradeMon(struct Pokemon *mon, u16 monIdx)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
2019-10-11 00:46:42 +02:00
|
|
|
int i, version, versions, canTradeAnyMon, numMonsLeft;
|
2018-12-31 09:22:21 +01:00
|
|
|
int speciesArray[PARTY_SIZE];
|
2018-12-27 09:05:09 +01:00
|
|
|
|
2019-10-10 09:50:51 +02:00
|
|
|
// Make Eggs not count for numMonsLeft
|
2018-12-27 09:05:09 +01:00
|
|
|
for (i = 0; i < gPlayerPartyCount; i++)
|
|
|
|
{
|
2023-02-24 11:53:02 +01:00
|
|
|
speciesArray[i] = GetMonData(&mon[i], MON_DATA_SPECIES_OR_EGG);
|
2018-12-31 09:22:21 +01:00
|
|
|
if (speciesArray[i] == SPECIES_EGG)
|
2019-10-10 09:50:51 +02:00
|
|
|
speciesArray[i] = SPECIES_NONE;
|
2018-12-27 09:05:09 +01:00
|
|
|
}
|
|
|
|
|
2019-10-10 09:50:51 +02:00
|
|
|
versions = 0;
|
2019-12-20 23:15:41 +01:00
|
|
|
canTradeAnyMon = TRUE;
|
2018-12-27 09:05:09 +01:00
|
|
|
for (i = 0; i < GetLinkPlayerCount(); i++)
|
|
|
|
{
|
|
|
|
version = gLinkPlayers[i].version & 0xFF;
|
|
|
|
if (version == VERSION_FIRE_RED ||
|
|
|
|
version == VERSION_LEAF_GREEN)
|
|
|
|
versions = 0;
|
|
|
|
else
|
|
|
|
versions |= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < GetLinkPlayerCount(); i++)
|
|
|
|
{
|
|
|
|
struct LinkPlayer *player = &gLinkPlayers[i];
|
2019-10-09 11:56:44 +02:00
|
|
|
|
2019-10-10 09:50:51 +02:00
|
|
|
// Does player not have National Dex
|
2019-12-20 23:15:41 +01:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if (!(player->progressFlags & 0xF))
|
|
|
|
canTradeAnyMon = FALSE;
|
2019-01-05 19:25:46 +01:00
|
|
|
|
2019-12-20 23:15:41 +01:00
|
|
|
if (versions && (player->progressFlags / 16))
|
|
|
|
canTradeAnyMon = FALSE;
|
|
|
|
} while (0);
|
2018-12-27 09:05:09 +01:00
|
|
|
}
|
|
|
|
|
2019-10-11 00:46:42 +02:00
|
|
|
if (canTradeAnyMon == FALSE)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
2018-12-31 09:22:21 +01:00
|
|
|
if (!IsSpeciesInHoennDex(speciesArray[monIdx]))
|
2019-10-10 09:50:51 +02:00
|
|
|
return CANT_TRADE_NATIONAL;
|
2019-01-05 19:25:46 +01:00
|
|
|
|
2018-12-31 09:22:21 +01:00
|
|
|
if (speciesArray[monIdx] == SPECIES_NONE)
|
2019-10-18 01:22:03 +02:00
|
|
|
return CANT_TRADE_EGG_YET;
|
2018-12-27 09:05:09 +01:00
|
|
|
}
|
|
|
|
|
2019-10-10 09:50:51 +02:00
|
|
|
numMonsLeft = 0;
|
2018-12-27 09:05:09 +01:00
|
|
|
for (i = 0; i < gPlayerPartyCount; i++)
|
|
|
|
{
|
2018-12-31 09:22:21 +01:00
|
|
|
if (monIdx != i)
|
2019-10-10 09:50:51 +02:00
|
|
|
numMonsLeft += speciesArray[i];
|
2018-12-27 09:05:09 +01:00
|
|
|
}
|
|
|
|
|
2019-10-10 09:50:51 +02:00
|
|
|
if (!numMonsLeft)
|
|
|
|
return CANT_TRADE_LAST_MON;
|
2018-12-27 09:05:09 +01:00
|
|
|
else
|
2019-10-10 09:50:51 +02:00
|
|
|
return CAN_TRADE_MON;
|
2018-12-27 09:05:09 +01:00
|
|
|
}
|
|
|
|
|
2021-04-19 02:12:12 +02:00
|
|
|
static void SpriteCB_LinkMonGlow(struct Sprite *sprite)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
|
|
|
if (++sprite->data[0] == 10)
|
|
|
|
{
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_BALL);
|
2018-12-27 09:05:09 +01:00
|
|
|
sprite->data[0] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-19 02:12:12 +02:00
|
|
|
static void SpriteCB_LinkMonGlowWireless(struct Sprite *sprite)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
|
|
|
if (!sprite->invisible && ++sprite->data[0] == 10)
|
|
|
|
{
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_M_SWAGGER2);
|
2018-12-27 09:05:09 +01:00
|
|
|
sprite->data[0] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
// Palette flash for trade glow core
|
2021-04-19 02:12:12 +02:00
|
|
|
static void SpriteCB_LinkMonShadow(struct Sprite *sprite)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
|
|
|
if (!sprite->data[1])
|
|
|
|
{
|
|
|
|
if (++sprite->data[0] == 12)
|
|
|
|
sprite->data[0] = 0;
|
|
|
|
|
2022-08-19 16:29:35 +02:00
|
|
|
LoadPalette(&sLinkMonShadow_Pal[sprite->data[0]], OBJ_PLTT_ID2(sprite->oam.paletteNum) + 4, PLTT_SIZEOF(1));
|
2018-12-27 09:05:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-19 02:12:12 +02:00
|
|
|
// Move cable down offscreen
|
|
|
|
static void SpriteCB_CableEndSending(struct Sprite *sprite)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
|
|
|
sprite->data[0]++;
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->y2++;
|
2018-12-27 09:05:09 +01:00
|
|
|
|
|
|
|
if (sprite->data[0] == 10)
|
|
|
|
DestroySprite(sprite);
|
|
|
|
}
|
|
|
|
|
2021-04-19 02:12:12 +02:00
|
|
|
// Move cable up onscreen
|
|
|
|
static void SpriteCB_CableEndReceiving(struct Sprite *sprite)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
|
|
|
sprite->data[0]++;
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->y2--;
|
2018-12-27 09:05:09 +01:00
|
|
|
|
|
|
|
if (sprite->data[0] == 10)
|
|
|
|
DestroySprite(sprite);
|
|
|
|
}
|
|
|
|
|
2021-04-19 02:12:12 +02:00
|
|
|
static void SpriteCB_GbaScreen(struct Sprite *sprite)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
|
|
|
if (++sprite->data[0] == 15)
|
|
|
|
{
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_M_MINIMIZE);
|
2018-12-27 09:05:09 +01:00
|
|
|
sprite->data[0] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-05 16:41:37 +02:00
|
|
|
static void SetTradeBGAffine(void)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
|
|
|
struct BgAffineDstData affine;
|
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
DoBgAffineSet(&affine, sTradeAnim->texX * 0x100, sTradeAnim->texY * 0x100, sTradeAnim->scrX, sTradeAnim->scrY, sTradeAnim->sXY, sTradeAnim->sXY, sTradeAnim->alpha);
|
2018-12-27 09:05:09 +01:00
|
|
|
SetGpuReg(REG_OFFSET_BG2PA, affine.pa);
|
|
|
|
SetGpuReg(REG_OFFSET_BG2PB, affine.pb);
|
|
|
|
SetGpuReg(REG_OFFSET_BG2PC, affine.pc);
|
|
|
|
SetGpuReg(REG_OFFSET_BG2PD, affine.pd);
|
|
|
|
SetGpuReg(REG_OFFSET_BG2X_L, affine.dx);
|
|
|
|
SetGpuReg(REG_OFFSET_BG2X_H, affine.dx >> 16);
|
|
|
|
SetGpuReg(REG_OFFSET_BG2Y_L, affine.dy);
|
|
|
|
SetGpuReg(REG_OFFSET_BG2Y_H, affine.dy >> 16);
|
|
|
|
}
|
|
|
|
|
2019-10-05 16:41:37 +02:00
|
|
|
static void SetTradeGpuRegs(void)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
|
|
|
u16 dispcnt;
|
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
SetGpuReg(REG_OFFSET_BG1VOFS, sTradeAnim->bg1vofs);
|
|
|
|
SetGpuReg(REG_OFFSET_BG1HOFS, sTradeAnim->bg1hofs);
|
2018-12-27 09:05:09 +01:00
|
|
|
|
|
|
|
dispcnt = GetGpuReg(REG_OFFSET_DISPCNT);
|
2018-12-31 09:22:21 +01:00
|
|
|
if ((dispcnt & 7) == DISPCNT_MODE_0)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
SetGpuReg(REG_OFFSET_BG2VOFS, sTradeAnim->bg2vofs);
|
|
|
|
SetGpuReg(REG_OFFSET_BG2HOFS, sTradeAnim->bg2hofs);
|
2018-12-27 09:05:09 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-05 16:41:37 +02:00
|
|
|
SetTradeBGAffine();
|
2018-12-27 09:05:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
static void VBlankCB_TradeAnim(void)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
2019-10-05 16:41:37 +02:00
|
|
|
SetTradeGpuRegs();
|
2018-12-27 09:05:09 +01:00
|
|
|
LoadOam();
|
|
|
|
ProcessSpriteCopyRequests();
|
|
|
|
TransferPlttBuffer();
|
|
|
|
}
|
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
static void ClearLinkTimeoutTimer(void)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->linkTimeoutTimer = 0;
|
|
|
|
sTradeAnim->linkTimeoutZero1 = 0;
|
|
|
|
sTradeAnim->linkTimeoutZero2 = 0;
|
2018-12-27 09:05:09 +01:00
|
|
|
}
|
|
|
|
|
2019-10-05 16:41:37 +02:00
|
|
|
static void CheckForLinkTimeout(void)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
if (sTradeAnim->linkTimeoutZero1 == sTradeAnim->linkTimeoutZero2)
|
|
|
|
sTradeAnim->linkTimeoutTimer++;
|
2018-12-27 09:05:09 +01:00
|
|
|
else
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->linkTimeoutTimer = 0;
|
2018-12-27 09:05:09 +01:00
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
if (sTradeAnim->linkTimeoutTimer > 300)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
|
|
|
CloseLink();
|
|
|
|
SetMainCallback2(CB2_LinkError);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->linkTimeoutTimer = 0;
|
|
|
|
sTradeAnim->linkTimeoutZero2 = 0;
|
|
|
|
sTradeAnim->linkTimeoutZero1 = 0;
|
2018-12-27 09:05:09 +01:00
|
|
|
}
|
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->linkTimeoutZero2 = sTradeAnim->linkTimeoutZero1;
|
2018-12-27 09:05:09 +01:00
|
|
|
}
|
|
|
|
|
2019-10-04 13:42:45 +02:00
|
|
|
static u32 TradeGetMultiplayerId(void)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
2018-12-31 09:22:21 +01:00
|
|
|
if (gReceivedRemoteLinkPlayers)
|
2018-12-27 09:05:09 +01:00
|
|
|
return GetMultiplayerId();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-10-09 15:55:06 +02:00
|
|
|
static void LoadTradeMonPic(u8 whichParty, u8 state)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
2018-12-31 09:22:21 +01:00
|
|
|
int pos = 0;
|
2018-12-27 09:05:09 +01:00
|
|
|
struct Pokemon *mon = NULL;
|
|
|
|
u16 species;
|
|
|
|
u32 personality;
|
|
|
|
|
2019-10-03 07:16:22 +02:00
|
|
|
if (whichParty == TRADE_PLAYER)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
2019-10-04 01:39:37 +02:00
|
|
|
mon = &gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]];
|
2019-10-09 15:55:06 +02:00
|
|
|
pos = B_POSITION_OPPONENT_LEFT;
|
2018-12-27 09:05:09 +01:00
|
|
|
}
|
|
|
|
|
2019-10-03 07:16:22 +02:00
|
|
|
if (whichParty == TRADE_PARTNER)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
2019-10-04 01:39:37 +02:00
|
|
|
mon = &gEnemyParty[gSelectedTradeMonPositions[TRADE_PARTNER] % PARTY_SIZE];
|
2019-10-09 15:55:06 +02:00
|
|
|
pos = B_POSITION_OPPONENT_RIGHT;
|
2018-12-27 09:05:09 +01:00
|
|
|
}
|
|
|
|
|
2019-10-09 15:55:06 +02:00
|
|
|
switch (state)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
2019-10-09 15:55:06 +02:00
|
|
|
case 0:
|
2023-02-24 11:53:02 +01:00
|
|
|
species = GetMonData(mon, MON_DATA_SPECIES_OR_EGG);
|
2019-10-09 15:55:06 +02:00
|
|
|
personality = GetMonData(mon, MON_DATA_PERSONALITY);
|
2018-12-27 09:05:09 +01:00
|
|
|
|
2019-10-09 15:55:06 +02:00
|
|
|
if (whichParty == TRADE_PLAYER)
|
2021-10-03 05:47:59 +02:00
|
|
|
HandleLoadSpecialPokePic_2(&gMonFrontPicTable[species], gMonSpritesGfxPtr->sprites.ptr[B_POSITION_OPPONENT_LEFT], species, personality);
|
2019-10-09 15:55:06 +02:00
|
|
|
else
|
2021-10-03 05:47:59 +02:00
|
|
|
HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[species], gMonSpritesGfxPtr->sprites.ptr[whichParty * 2 + B_POSITION_OPPONENT_LEFT], species, personality);
|
2018-12-28 09:11:41 +01:00
|
|
|
|
2019-10-09 15:55:06 +02:00
|
|
|
LoadCompressedSpritePalette(GetMonSpritePalStruct(mon));
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->monSpecies[whichParty] = species;
|
|
|
|
sTradeAnim->monPersonalities[whichParty] = personality;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
SetMultiuseSpriteTemplateToPokemon(GetMonSpritePalStruct(mon)->tag, pos);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->monSpriteIds[whichParty] = CreateSprite(&gMultiuseSpriteTemplate, 120, 60, 6);
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[whichParty]].invisible = TRUE;
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[whichParty]].callback = SpriteCallbackDummy;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2018-12-27 09:05:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-05 16:41:37 +02:00
|
|
|
void CB2_LinkTrade(void)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
|
|
|
switch (gMain.state)
|
|
|
|
{
|
2019-10-09 15:55:06 +02:00
|
|
|
case 0:
|
|
|
|
if (!gReceivedRemoteLinkPlayers)
|
|
|
|
{
|
2020-06-04 00:00:53 +02:00
|
|
|
gLinkType = LINKTYPE_TRADE_DISCONNECTED;
|
2019-10-09 15:55:06 +02:00
|
|
|
CloseLink();
|
|
|
|
}
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim = AllocZeroed(sizeof(*sTradeAnim));
|
2019-10-09 15:55:06 +02:00
|
|
|
AllocateMonSpritesGfx();
|
|
|
|
ResetTasks();
|
|
|
|
ResetSpriteData();
|
|
|
|
FreeAllSpritePalettes();
|
2022-12-15 22:00:53 +01:00
|
|
|
SetVBlankCallback(VBlankCB_TradeAnim);
|
|
|
|
TradeAnimInit_LoadGfx();
|
|
|
|
ClearLinkTimeoutTimer();
|
2019-10-09 15:55:06 +02:00
|
|
|
gMain.state++;
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->neverRead_8C = 0;
|
|
|
|
sTradeAnim->state = 0;
|
|
|
|
sTradeAnim->isLinkTrade = TRUE;
|
|
|
|
sTradeAnim->texX = 64;
|
|
|
|
sTradeAnim->texY = 64;
|
|
|
|
sTradeAnim->neverRead_D8 = 0;
|
|
|
|
sTradeAnim->neverRead_DA = 0;
|
|
|
|
sTradeAnim->scrX = DISPLAY_WIDTH / 2;
|
|
|
|
sTradeAnim->scrY = DISPLAY_HEIGHT / 2;
|
|
|
|
sTradeAnim->sXY = 256;
|
|
|
|
sTradeAnim->alpha = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (!gReceivedRemoteLinkPlayers)
|
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->isCableTrade = TRUE;
|
2019-10-09 15:55:06 +02:00
|
|
|
OpenLink();
|
2018-12-27 09:05:09 +01:00
|
|
|
gMain.state++;
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->timer = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gMain.state = 4;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
2022-12-15 22:00:53 +01:00
|
|
|
if (++sTradeAnim->timer > 60)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->timer = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
gMain.state++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (IsLinkMaster())
|
|
|
|
{
|
|
|
|
if (GetLinkPlayerCount_2() >= GetSavedPlayerCount())
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
if (++sTradeAnim->timer > 30)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
2019-10-09 15:55:06 +02:00
|
|
|
CheckShouldAdvanceLinkState();
|
|
|
|
gMain.state++;
|
2018-12-27 09:05:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-09 15:55:06 +02:00
|
|
|
CheckForLinkTimeout();
|
2018-12-27 09:05:09 +01:00
|
|
|
}
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-27 09:05:09 +01:00
|
|
|
gMain.state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
CheckForLinkTimeout();
|
|
|
|
if (gReceivedRemoteLinkPlayers == TRUE && IsLinkPlayerDataExchangeComplete() == TRUE)
|
2018-12-27 09:05:09 +01:00
|
|
|
gMain.state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
|
|
|
case 5:
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->playerFinishStatus = 0;
|
|
|
|
sTradeAnim->partnerFinishStatus = 0;
|
|
|
|
sTradeAnim->scheduleLinkTransfer = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
LoadTradeMonPic(TRADE_PLAYER, 0);
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
LoadTradeMonPic(TRADE_PLAYER, 1);
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
LoadTradeMonPic(TRADE_PARTNER, 0);
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
LoadTradeMonPic(TRADE_PARTNER, 1);
|
2019-10-10 09:50:51 +02:00
|
|
|
LinkTradeDrawWindow();
|
2019-10-09 15:55:06 +02:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
LoadTradeSequenceSpriteSheetsAndPalettes();
|
|
|
|
LoadSpriteSheet(&sPokeBallSpriteSheet);
|
|
|
|
LoadSpritePalette(&sPokeBallSpritePalette);
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 10:
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK);
|
2019-10-09 15:55:06 +02:00
|
|
|
ShowBg(0);
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 11:
|
2019-10-10 09:50:51 +02:00
|
|
|
InitTradeSequenceBgGpuRegs();
|
2019-10-09 15:55:06 +02:00
|
|
|
BufferTradeSceneStrings();
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 12:
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
|
|
|
if (gWirelessCommType)
|
|
|
|
{
|
|
|
|
LoadWirelessStatusIndicatorSpriteGfx();
|
|
|
|
CreateWirelessStatusIndicatorSprite(0, 0);
|
|
|
|
}
|
|
|
|
SetMainCallback2(CB2_UpdateLinkTrade);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
RunTasks();
|
|
|
|
RunTextPrinters();
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
|
|
|
UpdatePaletteFade();
|
|
|
|
}
|
|
|
|
|
2019-10-10 09:50:51 +02:00
|
|
|
void InitTradeSequenceBgGpuRegs(void)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
|
|
|
SetTradeSequenceBgGpuRegs(5);
|
|
|
|
SetTradeSequenceBgGpuRegs(0);
|
|
|
|
}
|
|
|
|
|
2019-10-10 09:50:51 +02:00
|
|
|
void LinkTradeDrawWindow(void)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
|
|
|
FillWindowPixelBuffer(0, PIXEL_FILL(15));
|
|
|
|
PutWindowTilemap(0);
|
2021-11-03 20:29:18 +01:00
|
|
|
CopyWindowToVram(0, COPYWIN_FULL);
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
static void TradeAnimInit_LoadGfx(void)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, 0);
|
|
|
|
ResetBgsAndClearDma3BusyFlags(0);
|
2019-10-07 04:58:25 +02:00
|
|
|
InitBgsFromTemplates(0, sTradeSequenceBgTemplates, ARRAY_COUNT(sTradeSequenceBgTemplates));
|
2021-11-04 04:02:06 +01:00
|
|
|
ChangeBgX(0, 0, BG_COORD_SET);
|
|
|
|
ChangeBgY(0, 0, BG_COORD_SET);
|
2021-03-29 15:38:19 +02:00
|
|
|
SetBgTilemapBuffer(0, Alloc(BG_SCREEN_SIZE));
|
|
|
|
SetBgTilemapBuffer(1, Alloc(BG_SCREEN_SIZE));
|
|
|
|
SetBgTilemapBuffer(3, Alloc(BG_SCREEN_SIZE));
|
2018-12-27 09:05:09 +01:00
|
|
|
DeactivateAllTextPrinters();
|
2022-12-15 22:00:53 +01:00
|
|
|
// Doing the graphics load...
|
2018-12-27 09:05:09 +01:00
|
|
|
DecompressAndLoadBgGfxUsingHeap(0, gBattleTextboxTiles, 0, 0, 0);
|
|
|
|
LZDecompressWram(gBattleTextboxTilemap, gDecompressionBuffer);
|
2022-12-15 22:00:53 +01:00
|
|
|
CopyToBgTilemapBuffer(0, gDecompressionBuffer, BG_SCREEN_SIZE, 0);
|
2022-08-19 17:32:00 +02:00
|
|
|
LoadCompressedPalette(gBattleTextboxPalette, BG_PLTT_ID(0), PLTT_SIZE_4BPP);
|
2019-10-07 04:58:25 +02:00
|
|
|
InitWindows(sTradeSequenceWindowTemplates);
|
2022-12-15 22:00:53 +01:00
|
|
|
// ... and doing the same load again
|
2018-12-27 09:05:09 +01:00
|
|
|
DecompressAndLoadBgGfxUsingHeap(0, gBattleTextboxTiles, 0, 0, 0);
|
|
|
|
LZDecompressWram(gBattleTextboxTilemap, gDecompressionBuffer);
|
2022-12-15 22:00:53 +01:00
|
|
|
CopyToBgTilemapBuffer(0, gDecompressionBuffer, BG_SCREEN_SIZE, 0);
|
2022-08-19 17:32:00 +02:00
|
|
|
LoadCompressedPalette(gBattleTextboxPalette, BG_PLTT_ID(0), PLTT_SIZE_4BPP);
|
2018-12-27 09:05:09 +01:00
|
|
|
}
|
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
static void CB2_InitInGameTrade(void)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
2018-12-31 09:22:21 +01:00
|
|
|
u8 otName[11];
|
2018-12-27 09:05:09 +01:00
|
|
|
|
|
|
|
switch (gMain.state)
|
|
|
|
{
|
2019-10-09 15:55:06 +02:00
|
|
|
case 0:
|
|
|
|
gSelectedTradeMonPositions[TRADE_PLAYER] = gSpecialVar_0x8005;
|
|
|
|
gSelectedTradeMonPositions[TRADE_PARTNER] = PARTY_SIZE;
|
|
|
|
StringCopy(gLinkPlayers[0].name, gSaveBlock2Ptr->playerName);
|
|
|
|
GetMonData(&gEnemyParty[0], MON_DATA_OT_NAME, otName);
|
|
|
|
StringCopy(gLinkPlayers[1].name, otName);
|
2021-02-05 18:08:49 +01:00
|
|
|
gLinkPlayers[0].language = GAME_LANGUAGE;
|
2019-10-09 15:55:06 +02:00
|
|
|
gLinkPlayers[1].language = GetMonData(&gEnemyParty[0], MON_DATA_LANGUAGE);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim = AllocZeroed(sizeof(*sTradeAnim));
|
2019-10-09 15:55:06 +02:00
|
|
|
AllocateMonSpritesGfx();
|
|
|
|
ResetTasks();
|
|
|
|
ResetSpriteData();
|
|
|
|
FreeAllSpritePalettes();
|
2022-12-15 22:00:53 +01:00
|
|
|
SetVBlankCallback(VBlankCB_TradeAnim);
|
|
|
|
TradeAnimInit_LoadGfx();
|
|
|
|
sTradeAnim->isLinkTrade = FALSE;
|
|
|
|
sTradeAnim->neverRead_8C = 0;
|
|
|
|
sTradeAnim->state = 0;
|
|
|
|
sTradeAnim->texX = 64;
|
|
|
|
sTradeAnim->texY = 64;
|
|
|
|
sTradeAnim->neverRead_D8 = 0;
|
|
|
|
sTradeAnim->neverRead_DA = 0;
|
|
|
|
sTradeAnim->scrX = DISPLAY_WIDTH / 2;
|
|
|
|
sTradeAnim->scrY = DISPLAY_HEIGHT / 2;
|
|
|
|
sTradeAnim->sXY = 256;
|
|
|
|
sTradeAnim->alpha = 0;
|
|
|
|
sTradeAnim->timer = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
gMain.state = 5;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
LoadTradeMonPic(TRADE_PLAYER, 0);
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
LoadTradeMonPic(TRADE_PLAYER, 1);
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
LoadTradeMonPic(TRADE_PARTNER, 0);
|
|
|
|
ShowBg(0);
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
LoadTradeMonPic(TRADE_PARTNER, 1);
|
|
|
|
FillWindowPixelBuffer(0, PIXEL_FILL(15));
|
|
|
|
PutWindowTilemap(0);
|
2021-11-03 20:29:18 +01:00
|
|
|
CopyWindowToVram(0, COPYWIN_FULL);
|
2019-10-09 15:55:06 +02:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
LoadTradeSequenceSpriteSheetsAndPalettes();
|
|
|
|
LoadSpriteSheet(&sPokeBallSpriteSheet);
|
|
|
|
LoadSpritePalette(&sPokeBallSpritePalette);
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
ShowBg(0);
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 11:
|
|
|
|
SetTradeSequenceBgGpuRegs(5);
|
|
|
|
SetTradeSequenceBgGpuRegs(0);
|
|
|
|
BufferTradeSceneStrings();
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 12:
|
2022-12-15 22:00:53 +01:00
|
|
|
SetMainCallback2(CB2_InGameTrade);
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2018-12-27 09:05:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
RunTasks();
|
|
|
|
RunTextPrinters();
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
|
|
|
UpdatePaletteFade();
|
|
|
|
}
|
|
|
|
|
2019-10-04 13:42:45 +02:00
|
|
|
static void UpdatePokedexForReceivedMon(u8 partyIdx)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
2018-12-31 09:22:21 +01:00
|
|
|
struct Pokemon *mon = &gPlayerParty[partyIdx];
|
2018-12-28 09:11:41 +01:00
|
|
|
|
2018-12-27 09:05:09 +01:00
|
|
|
if (!GetMonData(mon, MON_DATA_IS_EGG))
|
|
|
|
{
|
2018-12-28 09:11:41 +01:00
|
|
|
u16 species = GetMonData(mon, MON_DATA_SPECIES, NULL);
|
|
|
|
u32 personality = GetMonData(mon, MON_DATA_PERSONALITY, NULL);
|
2018-12-27 09:05:09 +01:00
|
|
|
species = SpeciesToNationalPokedexNum(species);
|
|
|
|
GetSetPokedexFlag(species, FLAG_SET_SEEN);
|
|
|
|
HandleSetPokedexFlag(species, FLAG_SET_CAUGHT, personality);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-04 13:42:45 +02:00
|
|
|
// Functionally nop after commented code
|
2019-10-09 15:55:06 +02:00
|
|
|
static void TryEnableNationalDexFromLinkPartner(void)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
2018-12-28 09:11:41 +01:00
|
|
|
u8 mpId = GetMultiplayerId();
|
|
|
|
// Originally in Ruby but commented out
|
|
|
|
/*if (gLinkPlayers[mpId ^ 1].lp_field_2 == 0x8000)
|
|
|
|
EnableNationalPokedex();*/
|
2018-12-27 09:05:09 +01:00
|
|
|
}
|
|
|
|
|
2019-10-04 13:42:45 +02:00
|
|
|
static void TradeMons(u8 playerPartyIdx, u8 partnerPartyIdx)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
|
|
|
u8 friendship;
|
|
|
|
|
2019-10-04 13:42:45 +02:00
|
|
|
struct Pokemon *playerMon = &gPlayerParty[playerPartyIdx];
|
2018-12-31 09:22:21 +01:00
|
|
|
u16 playerMail = GetMonData(playerMon, MON_DATA_MAIL);
|
2018-12-27 09:05:09 +01:00
|
|
|
|
2019-10-04 13:42:45 +02:00
|
|
|
struct Pokemon *partnerMon = &gEnemyParty[partnerPartyIdx];
|
2018-12-31 09:22:21 +01:00
|
|
|
u16 partnerMail = GetMonData(partnerMon, MON_DATA_MAIL);
|
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
// The mail attached to the sent Pokemon no longer exists in your file.
|
2021-02-20 21:15:38 +01:00
|
|
|
if (playerMail != MAIL_NONE)
|
2021-10-23 16:55:46 +02:00
|
|
|
ClearMail(&gSaveBlock1Ptr->mail[playerMail]);
|
2018-12-27 09:05:09 +01:00
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
SWAP(*playerMon, *partnerMon, sTradeAnim->tempMon);
|
2018-12-27 09:05:09 +01:00
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
// By default, a Pokemon received from a trade will have 70 Friendship.
|
|
|
|
// Eggs use Friendship to track egg cycles, so don't set this on Eggs.
|
2018-12-27 09:05:09 +01:00
|
|
|
friendship = 70;
|
2018-12-31 09:22:21 +01:00
|
|
|
if (!GetMonData(playerMon, MON_DATA_IS_EGG))
|
|
|
|
SetMonData(playerMon, MON_DATA_FRIENDSHIP, &friendship);
|
2018-12-27 09:05:09 +01:00
|
|
|
|
2021-02-20 21:15:38 +01:00
|
|
|
if (partnerMail != MAIL_NONE)
|
2021-10-23 16:55:46 +02:00
|
|
|
GiveMailToMon(playerMon, &gTradeMail[partnerMail]);
|
2018-12-27 09:05:09 +01:00
|
|
|
|
2019-10-04 13:42:45 +02:00
|
|
|
UpdatePokedexForReceivedMon(playerPartyIdx);
|
2018-12-31 09:22:21 +01:00
|
|
|
if (gReceivedRemoteLinkPlayers)
|
2019-10-09 15:55:06 +02:00
|
|
|
TryEnableNationalDexFromLinkPartner();
|
2018-12-27 09:05:09 +01:00
|
|
|
}
|
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
static void HandleLinkDataSend(void)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
switch (sTradeAnim->scheduleLinkTransfer)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
2019-10-09 15:55:06 +02:00
|
|
|
case 1:
|
|
|
|
if (IsLinkTaskFinished())
|
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
SendBlock(BitmaskAllOtherLinkPlayers(), sTradeAnim->linkData, sizeof(sTradeAnim->linkData));
|
|
|
|
sTradeAnim->scheduleLinkTransfer++;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
// fallthrough
|
|
|
|
case 2:
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->scheduleLinkTransfer = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2018-12-27 09:05:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
static void CB2_InGameTrade(void)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
DoTradeAnim();
|
2018-12-27 09:05:09 +01:00
|
|
|
RunTasks();
|
|
|
|
RunTextPrinters();
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
|
|
|
UpdatePaletteFade();
|
|
|
|
}
|
|
|
|
|
2019-10-09 15:55:06 +02:00
|
|
|
static void SetTradeSequenceBgGpuRegs(u8 state)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
2019-10-09 15:55:06 +02:00
|
|
|
switch (state)
|
2018-12-27 09:05:09 +01:00
|
|
|
{
|
2019-10-09 15:55:06 +02:00
|
|
|
case 0:
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->bg2vofs = 0;
|
|
|
|
sTradeAnim->bg2hofs = 180;
|
2019-10-09 15:55:06 +02:00
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 |
|
|
|
|
DISPCNT_OBJ_1D_MAP |
|
|
|
|
DISPCNT_BG0_ON |
|
|
|
|
DISPCNT_BG2_ON |
|
|
|
|
DISPCNT_OBJ_ON);
|
|
|
|
SetGpuReg(REG_OFFSET_BG2CNT, BGCNT_PRIORITY(2) |
|
|
|
|
BGCNT_CHARBASE(1) |
|
|
|
|
BGCNT_16COLOR |
|
|
|
|
BGCNT_SCREENBASE(18) |
|
|
|
|
BGCNT_TXT512x256);
|
2022-08-19 17:32:00 +02:00
|
|
|
LoadPalette(gTradeGba2_Pal, BG_PLTT_ID(1), 3 * PLTT_SIZE_4BPP);
|
2019-10-09 15:55:06 +02:00
|
|
|
DmaCopyLarge16(3, gTradeGba_Gfx, (void *) BG_CHAR_ADDR(1), 0x1420, 0x1000);
|
2021-04-19 02:12:12 +02:00
|
|
|
DmaCopy16Defvars(3, gTradePlatform_Tilemap, (void *) BG_SCREEN_ADDR(18), 0x1000);
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
|
|
|
case 1:
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->bg1hofs = 0;
|
|
|
|
sTradeAnim->bg1vofs = 348;
|
2019-10-09 15:55:06 +02:00
|
|
|
SetGpuReg(REG_OFFSET_BG1VOFS, 348);
|
|
|
|
SetGpuReg(REG_OFFSET_BG1CNT, BGCNT_PRIORITY(2) |
|
|
|
|
BGCNT_CHARBASE(0) |
|
|
|
|
BGCNT_16COLOR |
|
|
|
|
BGCNT_SCREENBASE(5) |
|
|
|
|
BGCNT_TXT256x512);
|
|
|
|
SetGpuReg(REG_OFFSET_BG2CNT, BGCNT_PRIORITY(2) |
|
|
|
|
BGCNT_CHARBASE(1) |
|
|
|
|
BGCNT_16COLOR |
|
|
|
|
BGCNT_SCREENBASE(18) |
|
|
|
|
BGCNT_TXT256x512);
|
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
if (sTradeAnim->isCableTrade)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
DmaCopy16Defvars(3, sGbaMapCable, (void *) BG_SCREEN_ADDR(5), 0x1000);
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
DmaCopy16Defvars(3, sGbaMapWireless, (void *) BG_SCREEN_ADDR(5), 0x1000);
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
2018-12-27 09:05:09 +01:00
|
|
|
|
2019-10-09 15:55:06 +02:00
|
|
|
DmaCopyLarge16(3, gTradeGba_Gfx, (void *) BG_CHAR_ADDR(0), 0x1420, 0x1000);
|
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 |
|
|
|
|
DISPCNT_OBJ_1D_MAP |
|
|
|
|
DISPCNT_BG1_ON |
|
|
|
|
DISPCNT_OBJ_ON);
|
|
|
|
break;
|
|
|
|
case 2:
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->bg1vofs = 0;
|
|
|
|
sTradeAnim->bg1hofs = 0;
|
|
|
|
if (!sTradeAnim->isCableTrade)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2018-12-27 09:05:09 +01:00
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_1 |
|
|
|
|
DISPCNT_OBJ_1D_MAP |
|
2019-10-09 15:55:06 +02:00
|
|
|
DISPCNT_BG1_ON |
|
2018-12-27 09:05:09 +01:00
|
|
|
DISPCNT_OBJ_ON);
|
2022-12-15 22:00:53 +01:00
|
|
|
LZ77UnCompVram(sWirelessCloseup_Map, (void *) BG_SCREEN_ADDR(5));
|
2019-10-09 15:55:06 +02:00
|
|
|
BlendPalettes(0x8, 16, RGB_BLACK);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-27 09:05:09 +01:00
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_1 |
|
|
|
|
DISPCNT_OBJ_1D_MAP |
|
2019-10-09 15:55:06 +02:00
|
|
|
DISPCNT_BG1_ON |
|
2018-12-27 09:05:09 +01:00
|
|
|
DISPCNT_OBJ_ON);
|
2022-12-15 22:00:53 +01:00
|
|
|
DmaCopy16Defvars(3, sCableCloseup_Map, (void *) BG_SCREEN_ADDR(5), 0x800);
|
2019-10-09 15:55:06 +02:00
|
|
|
BlendPalettes(0x1, 16, RGB_BLACK);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
2022-08-19 17:32:00 +02:00
|
|
|
LoadPalette(sWirelessSignalNone_Pal, BG_PLTT_ID(3), PLTT_SIZE_4BPP);
|
2021-04-19 02:12:12 +02:00
|
|
|
LZ77UnCompVram(sWirelessSignal_Gfx, (void *) BG_CHAR_ADDR(1));
|
|
|
|
LZ77UnCompVram(sWirelessSignal_Tilemap, (void *) BG_SCREEN_ADDR(18));
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->bg2vofs = 80;
|
2019-10-09 15:55:06 +02:00
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 |
|
|
|
|
DISPCNT_OBJ_1D_MAP |
|
|
|
|
DISPCNT_BG1_ON |
|
|
|
|
DISPCNT_BG2_ON |
|
|
|
|
DISPCNT_OBJ_ON);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_1 |
|
|
|
|
DISPCNT_OBJ_1D_MAP |
|
|
|
|
DISPCNT_BG2_ON |
|
|
|
|
DISPCNT_OBJ_ON);
|
|
|
|
SetGpuReg(REG_OFFSET_BG2CNT, BGCNT_PRIORITY(3) |
|
|
|
|
BGCNT_CHARBASE(1) |
|
|
|
|
BGCNT_256COLOR |
|
|
|
|
BGCNT_SCREENBASE(18) |
|
|
|
|
BGCNT_AFF128x128);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->texX = 64;
|
|
|
|
sTradeAnim->texY = 92;
|
|
|
|
sTradeAnim->sXY = 32;
|
|
|
|
sTradeAnim->gbaScale = 1024;
|
|
|
|
sTradeAnim->alpha = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
|
2021-04-19 02:12:12 +02:00
|
|
|
DmaCopyLarge16(3, sGbaAffine_Gfx, (void *) BG_CHAR_ADDR(1), 0x2840, 0x1000);
|
2019-10-09 15:55:06 +02:00
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
if (sTradeAnim->isCableTrade)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
DmaCopy16Defvars(3, sGbaAffineMapCable, (void *) BG_SCREEN_ADDR(18), 0x100);
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
DmaCopy16Defvars(3, sGbaAffineMapWireless, (void *) BG_SCREEN_ADDR(18), 0x100);
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 5:
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->bg1vofs = 0;
|
|
|
|
sTradeAnim->bg1hofs = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_1 |
|
|
|
|
DISPCNT_OBJ_1D_MAP |
|
|
|
|
DISPCNT_BG2_ON |
|
|
|
|
DISPCNT_OBJ_ON);
|
|
|
|
SetGpuReg(REG_OFFSET_BG2CNT, BGCNT_PRIORITY(3) |
|
|
|
|
BGCNT_CHARBASE(1) |
|
|
|
|
BGCNT_256COLOR |
|
|
|
|
BGCNT_SCREENBASE(18) |
|
|
|
|
BGCNT_AFF128x128);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->texX = 64;
|
|
|
|
sTradeAnim->texY = 92;
|
|
|
|
sTradeAnim->sXY = 256;
|
|
|
|
sTradeAnim->gbaScale = 128;
|
|
|
|
sTradeAnim->scrX = 120;
|
|
|
|
sTradeAnim->scrY = 80;
|
|
|
|
sTradeAnim->alpha = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
|
2021-04-19 02:12:12 +02:00
|
|
|
DmaCopyLarge16(3, sGbaAffine_Gfx, (void *) BG_CHAR_ADDR(1), 0x2840, 0x1000);
|
2019-10-09 15:55:06 +02:00
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
if (sTradeAnim->isCableTrade)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
DmaCopy16Defvars(3, sGbaAffineMapCable, (void *) BG_SCREEN_ADDR(18), 0x100);
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
DmaCopy16Defvars(3, sGbaAffineMapWireless, (void *) BG_SCREEN_ADDR(18), 0x100);
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 7:
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->bg2vofs = 0;
|
|
|
|
sTradeAnim->bg2hofs = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
SetGpuReg(REG_OFFSET_BLDCNT, 0);
|
|
|
|
SetGpuReg(REG_OFFSET_BG2CNT, BGCNT_PRIORITY(2) |
|
|
|
|
BGCNT_CHARBASE(1) |
|
|
|
|
BGCNT_16COLOR |
|
|
|
|
BGCNT_SCREENBASE(18) |
|
|
|
|
BGCNT_TXT512x256);
|
2022-08-19 17:32:00 +02:00
|
|
|
LoadPalette(gTradeGba2_Pal, BG_PLTT_ID(1), 3 * PLTT_SIZE_4BPP);
|
2019-10-09 15:55:06 +02:00
|
|
|
DmaCopyLarge16(3, gTradeGba_Gfx, (void *) BG_CHAR_ADDR(1), 0x1420, 0x1000);
|
2021-04-19 02:12:12 +02:00
|
|
|
DmaCopy16Defvars(3, gTradePlatform_Tilemap, (void *) BG_SCREEN_ADDR(18), 0x1000);
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2018-12-27 09:05:09 +01:00
|
|
|
}
|
|
|
|
}
|
2018-12-28 09:11:41 +01:00
|
|
|
|
2019-10-05 16:41:37 +02:00
|
|
|
static void LoadTradeSequenceSpriteSheetsAndPalettes(void)
|
2018-12-28 09:11:41 +01:00
|
|
|
{
|
2021-04-19 02:12:12 +02:00
|
|
|
LoadSpriteSheet(&sSpriteSheet_LinkMonGlow);
|
|
|
|
LoadSpriteSheet(&sSpriteSheet_LinkMonShadow);
|
|
|
|
LoadSpriteSheet(&sSpriteSheet_CableEnd);
|
|
|
|
LoadSpriteSheet(&sSpriteSheet_GbaScreen);
|
|
|
|
LoadSpritePalette(&sSpritePalette_LinkMon);
|
|
|
|
LoadSpritePalette(&sSpritePalette_Gba);
|
2018-12-28 09:11:41 +01:00
|
|
|
}
|
|
|
|
|
2019-10-09 15:55:06 +02:00
|
|
|
// Buffers "[Pokemon] will be sent to [Trainer]" strings
|
|
|
|
static void BufferTradeSceneStrings(void)
|
2018-12-28 09:11:41 +01:00
|
|
|
{
|
|
|
|
u8 mpId;
|
|
|
|
u8 name[20];
|
|
|
|
const struct InGameTrade *ingameTrade;
|
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
if (sTradeAnim->isLinkTrade)
|
2018-12-28 09:11:41 +01:00
|
|
|
{
|
|
|
|
mpId = GetMultiplayerId();
|
|
|
|
StringCopy(gStringVar1, gLinkPlayers[mpId ^ 1].name);
|
2019-10-04 01:39:37 +02:00
|
|
|
GetMonData(&gEnemyParty[gSelectedTradeMonPositions[TRADE_PARTNER] % PARTY_SIZE], MON_DATA_NICKNAME, name);
|
2021-11-18 04:11:03 +01:00
|
|
|
StringCopy_Nickname(gStringVar3, name);
|
2019-10-04 01:39:37 +02:00
|
|
|
GetMonData(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], MON_DATA_NICKNAME, name);
|
2021-11-18 04:11:03 +01:00
|
|
|
StringCopy_Nickname(gStringVar2, name);
|
2018-12-28 09:11:41 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-03 07:16:22 +02:00
|
|
|
ingameTrade = &sIngameTrades[gSpecialVar_0x8004];
|
2018-12-28 09:11:41 +01:00
|
|
|
StringCopy(gStringVar1, ingameTrade->otName);
|
2021-11-18 04:11:03 +01:00
|
|
|
StringCopy_Nickname(gStringVar3, ingameTrade->nickname);
|
2018-12-28 09:11:41 +01:00
|
|
|
GetMonData(&gPlayerParty[gSpecialVar_0x8005], MON_DATA_NICKNAME, name);
|
2021-11-18 04:11:03 +01:00
|
|
|
StringCopy_Nickname(gStringVar2, name);
|
2018-12-28 09:11:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-19 02:12:12 +02:00
|
|
|
// returns TRUE if it finished a link trade, FALSE if it finished an in-game trade or if sequence is still going
|
2022-12-15 22:00:53 +01:00
|
|
|
static bool8 DoTradeAnim(void)
|
2018-12-28 09:11:41 +01:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
if (sTradeAnim->isCableTrade)
|
|
|
|
return DoTradeAnim_Cable();
|
2018-12-28 09:11:41 +01:00
|
|
|
else
|
2022-12-15 22:00:53 +01:00
|
|
|
return DoTradeAnim_Wireless();
|
2018-12-28 09:11:41 +01:00
|
|
|
}
|
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
// Below are the states for the main switch in DoTradeAnim_Cable and DoTradeAnim_Wireless
|
|
|
|
// When DoTradeAnim_Wireless has a unique version of a state used by DoTradeAnim_Cable, it adds the below modifier
|
|
|
|
#define STATE_WIRELESS 100
|
2021-04-19 02:12:12 +02:00
|
|
|
enum {
|
2022-12-15 22:00:53 +01:00
|
|
|
STATE_START,
|
|
|
|
STATE_MON_SLIDE_IN,
|
2021-04-19 02:12:12 +02:00
|
|
|
// 2-9 unused
|
2022-12-15 22:00:53 +01:00
|
|
|
STATE_SEND_MSG = 10,
|
|
|
|
STATE_BYE_BYE,
|
|
|
|
STATE_POKEBALL_DEPART,
|
|
|
|
STATE_POKEBALL_DEPART_WAIT,
|
|
|
|
STATE_FADE_OUT_TO_GBA_SEND,
|
2021-04-19 02:12:12 +02:00
|
|
|
// 15-19 unused
|
2022-12-15 22:00:53 +01:00
|
|
|
STATE_WAIT_FADE_OUT_TO_GBA_SEND = 20,
|
|
|
|
STATE_FADE_IN_TO_GBA_SEND,
|
|
|
|
STATE_WAIT_FADE_IN_TO_GBA_SEND,
|
|
|
|
STATE_GBA_ZOOM_OUT,
|
|
|
|
STATE_GBA_FLASH_SEND,
|
|
|
|
STATE_GBA_STOP_FLASH_SEND,
|
|
|
|
STATE_PAN_AWAY_GBA,
|
|
|
|
STATE_CREATE_LINK_MON_LEAVING,
|
|
|
|
STATE_LINK_MON_TRAVEL_OUT,
|
|
|
|
STATE_FADE_OUT_TO_CROSSING,
|
|
|
|
STATE_WAIT_FADE_OUT_TO_CROSSING,
|
|
|
|
STATE_FADE_IN_TO_CROSSING,
|
|
|
|
STATE_WAIT_FADE_IN_TO_CROSSING,
|
|
|
|
STATE_CROSSING_LINK_MONS_ENTER,
|
|
|
|
STATE_CROSSING_BLEND_WHITE_1,
|
|
|
|
STATE_CROSSING_BLEND_WHITE_2,
|
|
|
|
STATE_CROSSING_BLEND_WHITE_3,
|
|
|
|
STATE_CROSSING_CREATE_MON_PICS,
|
|
|
|
STATE_CROSSING_MON_PICS_MOVE,
|
|
|
|
STATE_CROSSING_LINK_MONS_EXIT,
|
|
|
|
STATE_CREATE_LINK_MON_ARRIVING,
|
|
|
|
STATE_FADE_OUT_TO_GBA_RECV,
|
|
|
|
STATE_WAIT_FADE_OUT_TO_GBA_RECV,
|
|
|
|
STATE_LINK_MON_TRAVEL_IN,
|
|
|
|
STATE_PAN_TO_GBA,
|
|
|
|
STATE_DESTROY_LINK_MON,
|
|
|
|
STATE_LINK_MON_ARRIVED_DELAY,
|
|
|
|
STATE_MOVE_GBA_TO_CENTER,
|
|
|
|
STATE_GBA_FLASH_RECV,
|
|
|
|
STATE_UNUSED,
|
|
|
|
STATE_GBA_STOP_FLASH_RECV,
|
|
|
|
STATE_GBA_ZOOM_IN,
|
|
|
|
STATE_FADE_OUT_TO_NEW_MON,
|
2021-04-19 02:12:12 +02:00
|
|
|
// 53-59 unused
|
2022-12-15 22:00:53 +01:00
|
|
|
STATE_WAIT_FADE_OUT_TO_NEW_MON = 60,
|
|
|
|
STATE_FADE_IN_TO_NEW_MON,
|
|
|
|
STATE_WAIT_FADE_IN_TO_NEW_MON,
|
|
|
|
STATE_POKEBALL_ARRIVE,
|
|
|
|
STATE_FADE_POKEBALL_TO_NORMAL,
|
|
|
|
STATE_POKEBALL_ARRIVE_WAIT,
|
|
|
|
STATE_SHOW_NEW_MON,
|
|
|
|
STATE_NEW_MON_MSG,
|
|
|
|
STATE_TAKE_CARE_OF_MON,
|
|
|
|
STATE_AFTER_NEW_MON_DELAY,
|
|
|
|
STATE_CHECK_RIBBONS,
|
|
|
|
STATE_END_LINK_TRADE,
|
|
|
|
STATE_TRY_EVOLUTION,
|
|
|
|
STATE_FADE_OUT_END,
|
|
|
|
STATE_WAIT_FADE_OUT_END,
|
2021-04-19 02:12:12 +02:00
|
|
|
// Special states
|
2022-12-15 22:00:53 +01:00
|
|
|
STATE_GBA_FLASH_SEND_WIRELESS = STATE_GBA_FLASH_SEND + STATE_WIRELESS,
|
|
|
|
STATE_GBA_STOP_FLASH_SEND_WIRELESS,
|
|
|
|
STATE_WAIT_WIRELESS_SIGNAL_SEND,
|
|
|
|
STATE_PAN_TO_GBA_WIRELESS = STATE_PAN_TO_GBA + STATE_WIRELESS,
|
|
|
|
STATE_DESTROY_LINK_MON_WIRELESS,
|
|
|
|
STATE_WAIT_WIRELESS_SIGNAL_RECV,
|
|
|
|
STATE_DELAY_FOR_MON_ANIM = 167,
|
|
|
|
STATE_LINK_MON_TRAVEL_OFFSCREEN = 200,
|
|
|
|
STATE_WAIT_FOR_MON_CRY = 267,
|
2021-04-19 02:12:12 +02:00
|
|
|
};
|
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
static bool8 DoTradeAnim_Cable(void)
|
2018-12-28 09:11:41 +01:00
|
|
|
{
|
|
|
|
u16 evoTarget;
|
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
switch (sTradeAnim->state)
|
2018-12-28 09:11:41 +01:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_START:
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].invisible = FALSE;
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].x2 = -180;
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].y2 = gMonFrontPicCoords[sTradeAnim->monSpecies[TRADE_PLAYER]].y_offset;
|
|
|
|
sTradeAnim->state++;
|
|
|
|
sTradeAnim->cachedMapMusic = GetCurrentMapMusic();
|
2020-08-21 00:02:00 +02:00
|
|
|
PlayNewMapMusic(MUS_EVOLUTION);
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_MON_SLIDE_IN:
|
|
|
|
if (sTradeAnim->bg2hofs > 0)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2021-04-19 02:12:12 +02:00
|
|
|
// Sliding
|
2022-12-15 22:00:53 +01:00
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].x2 += 3;
|
|
|
|
sTradeAnim->bg2hofs -= 3;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-04-19 02:12:12 +02:00
|
|
|
// Pokémon has arrived onscreen
|
2022-12-15 22:00:53 +01:00
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].x2 = 0;
|
|
|
|
sTradeAnim->bg2hofs = 0;
|
|
|
|
sTradeAnim->state = STATE_SEND_MSG;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_SEND_MSG:
|
2019-10-09 15:55:06 +02:00
|
|
|
StringExpandPlaceholders(gStringVar4, gText_XWillBeSentToY);
|
|
|
|
DrawTextOnTradeWindow(0, gStringVar4, 0);
|
2018-12-28 09:11:41 +01:00
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
if (sTradeAnim->monSpecies[TRADE_PLAYER] != SPECIES_EGG)
|
|
|
|
PlayCry_Normal(sTradeAnim->monSpecies[TRADE_PLAYER], 0);
|
2018-12-28 09:11:41 +01:00
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state = STATE_BYE_BYE;
|
|
|
|
sTradeAnim->timer = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_BYE_BYE:
|
|
|
|
if (++sTradeAnim->timer == 80)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->releasePokeballSpriteId = CreateTradePokeballSprite(sTradeAnim->monSpriteIds[TRADE_PLAYER], gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].oam.paletteNum, 120, 32, 2, 1, 0x14, 0xfffff);
|
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
StringExpandPlaceholders(gStringVar4, gText_ByeByeVar1);
|
|
|
|
DrawTextOnTradeWindow(0, gStringVar4, 0);
|
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_POKEBALL_DEPART:
|
|
|
|
if (gSprites[sTradeAnim->releasePokeballSpriteId].callback == SpriteCallbackDummy)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->bouncingPokeballSpriteId = CreateSprite(&sSpriteTemplate_Pokeball, 120, 32, 0);
|
|
|
|
gSprites[sTradeAnim->bouncingPokeballSpriteId].callback = SpriteCB_BouncingPokeballDepart;
|
|
|
|
DestroySprite(&gSprites[sTradeAnim->releasePokeballSpriteId]);
|
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_POKEBALL_DEPART_WAIT:
|
2019-10-09 15:55:06 +02:00
|
|
|
// The game waits here for the sprite to finish its animation sequence.
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_FADE_OUT_TO_GBA_SEND:
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state = STATE_WAIT_FADE_OUT_TO_GBA_SEND;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_WAIT_FADE_OUT_TO_GBA_SEND:
|
2019-10-09 15:55:06 +02:00
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
|
|
|
SetTradeSequenceBgGpuRegs(4);
|
|
|
|
FillWindowPixelBuffer(0, PIXEL_FILL(15));
|
2021-11-03 20:29:18 +01:00
|
|
|
CopyWindowToVram(0, COPYWIN_FULL);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_FADE_IN_TO_GBA_SEND:
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, -1, 16, 0, RGB_BLACK);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_WAIT_FADE_IN_TO_GBA_SEND:
|
2019-10-09 15:55:06 +02:00
|
|
|
if (!gPaletteFade.active)
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state = STATE_GBA_ZOOM_OUT;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_GBA_ZOOM_OUT:
|
|
|
|
if (sTradeAnim->gbaScale > 0x100)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->gbaScale -= 0x34;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetTradeSequenceBgGpuRegs(1);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->gbaScale = 0x80;
|
|
|
|
sTradeAnim->state++;
|
|
|
|
sTradeAnim->timer = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->sXY = 0x8000 / sTradeAnim->gbaScale;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_GBA_FLASH_SEND:
|
|
|
|
if (++sTradeAnim->timer > 20)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
|
|
|
SetTradeBGAffine();
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->connectionSpriteId2 = CreateSprite(&sSpriteTemplate_GbaScreenFlash_Long, 120, 80, 0);
|
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_GBA_STOP_FLASH_SEND:
|
|
|
|
if (gSprites[sTradeAnim->connectionSpriteId2].animEnded)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
DestroySprite(&gSprites[sTradeAnim->connectionSpriteId2]);
|
2019-10-09 15:55:06 +02:00
|
|
|
SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_EFFECT_BLEND |
|
|
|
|
BLDCNT_TGT2_BG1 |
|
|
|
|
BLDCNT_TGT2_BG2);
|
|
|
|
SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(12, 4));
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_PAN_AWAY_GBA:
|
|
|
|
if (--sTradeAnim->bg1vofs == 316)
|
|
|
|
sTradeAnim->state++;
|
2021-04-19 02:12:12 +02:00
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
if (sTradeAnim->bg1vofs == 328)
|
|
|
|
sTradeAnim->cableEndSpriteId = CreateSprite(&sSpriteTemplate_CableEnd, 128, 65, 0);
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_CREATE_LINK_MON_LEAVING:
|
|
|
|
sTradeAnim->connectionSpriteId1 = CreateSprite(&sSpriteTemplate_LinkMonGlow, 128, 80, 3);
|
|
|
|
sTradeAnim->connectionSpriteId2 = CreateSprite(&sSpriteTemplate_LinkMonShadow, 128, 80, 0);
|
|
|
|
StartSpriteAnim(&gSprites[sTradeAnim->connectionSpriteId2], ANIM_LINKMON_SMALL);
|
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_LINK_MON_TRAVEL_OUT:
|
|
|
|
if ((sTradeAnim->bg1vofs -= 2) == 166)
|
|
|
|
sTradeAnim->state = STATE_LINK_MON_TRAVEL_OFFSCREEN;
|
2021-04-19 02:12:12 +02:00
|
|
|
|
2019-10-09 15:55:06 +02:00
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_1 |
|
|
|
|
DISPCNT_OBJ_1D_MAP |
|
|
|
|
DISPCNT_BG1_ON |
|
|
|
|
DISPCNT_OBJ_ON);
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_LINK_MON_TRAVEL_OFFSCREEN:
|
|
|
|
gSprites[sTradeAnim->connectionSpriteId1].y -= 2;
|
|
|
|
gSprites[sTradeAnim->connectionSpriteId2].y -= 2;
|
|
|
|
if (gSprites[sTradeAnim->connectionSpriteId1].y < -8)
|
|
|
|
sTradeAnim->state = STATE_FADE_OUT_TO_CROSSING;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_FADE_OUT_TO_CROSSING:
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, -1, 0, 16, RGB_BLACK);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state = STATE_WAIT_FADE_OUT_TO_CROSSING;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_WAIT_FADE_OUT_TO_CROSSING:
|
2019-10-09 15:55:06 +02:00
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
DestroySprite(&gSprites[sTradeAnim->connectionSpriteId1]);
|
|
|
|
DestroySprite(&gSprites[sTradeAnim->connectionSpriteId2]);
|
2019-10-09 15:55:06 +02:00
|
|
|
SetTradeSequenceBgGpuRegs(2);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_FADE_IN_TO_CROSSING:
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, -1, 16, 0, RGB_BLACK);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->connectionSpriteId1 = CreateSprite(&sSpriteTemplate_LinkMonShadow, 111, 170, 0);
|
|
|
|
sTradeAnim->connectionSpriteId2 = CreateSprite(&sSpriteTemplate_LinkMonShadow, 129, -10, 0);
|
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_WAIT_FADE_IN_TO_CROSSING:
|
2019-10-09 15:55:06 +02:00
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_WARP_OUT);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
2022-12-15 22:00:53 +01:00
|
|
|
gSprites[sTradeAnim->connectionSpriteId1].y2 -= 3;
|
|
|
|
gSprites[sTradeAnim->connectionSpriteId2].y2 += 3;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_CROSSING_LINK_MONS_ENTER:
|
|
|
|
gSprites[sTradeAnim->connectionSpriteId1].y2 -= 3;
|
|
|
|
gSprites[sTradeAnim->connectionSpriteId2].y2 += 3;
|
|
|
|
if (gSprites[sTradeAnim->connectionSpriteId1].y2 <= -90)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
gSprites[sTradeAnim->connectionSpriteId1].data[1] = 1;
|
|
|
|
gSprites[sTradeAnim->connectionSpriteId2].data[1] = 1;
|
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_CROSSING_BLEND_WHITE_1:
|
2019-10-09 15:55:06 +02:00
|
|
|
BlendPalettes(0x1, 16, RGB_WHITEALPHA);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_CROSSING_BLEND_WHITE_2:
|
2019-10-09 15:55:06 +02:00
|
|
|
BlendPalettes(0x1, 0, RGB_WHITEALPHA);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_CROSSING_BLEND_WHITE_3:
|
2019-10-09 15:55:06 +02:00
|
|
|
BlendPalettes(0x1, 16, RGB_WHITEALPHA);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_CROSSING_CREATE_MON_PICS:
|
|
|
|
if (!IsMonSpriteNotFlipped(sTradeAnim->monSpecies[TRADE_PLAYER]))
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].affineAnims = sAffineAnims_CrossingMonPics;
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].oam.affineMode = ST_OAM_AFFINE_DOUBLE;
|
|
|
|
CalcCenterToCornerVec(&gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]], SPRITE_SHAPE(64x64), SPRITE_SIZE(64x64), ST_OAM_AFFINE_DOUBLE);
|
|
|
|
StartSpriteAffineAnim(&gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]], 0);
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
StartSpriteAffineAnim(&gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]], 0);
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
2022-12-15 22:00:53 +01:00
|
|
|
StartSpriteAffineAnim(&gSprites[sTradeAnim->monSpriteIds[TRADE_PARTNER]], 0);
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].x = 60;
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PARTNER]].x = 180;
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].y = 192;
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PARTNER]].y = -32;
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].invisible = FALSE;
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PARTNER]].invisible = FALSE;
|
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_CROSSING_MON_PICS_MOVE:
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].y2 -= 3;
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PARTNER]].y2 += 3;
|
|
|
|
if (gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].y2 < -DISPLAY_HEIGHT
|
|
|
|
&& gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].y2 >= -DISPLAY_HEIGHT - 3)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_WARP_IN);
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
2022-12-15 22:00:53 +01:00
|
|
|
if (gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].y2 < -222)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
gSprites[sTradeAnim->connectionSpriteId1].data[1] = 0;
|
|
|
|
gSprites[sTradeAnim->connectionSpriteId2].data[1] = 0;
|
|
|
|
sTradeAnim->state++;
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].invisible = TRUE;
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PARTNER]].invisible = TRUE;
|
2019-10-09 15:55:06 +02:00
|
|
|
BlendPalettes(0x1, 0, RGB_WHITEALPHA);
|
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_CROSSING_LINK_MONS_EXIT:
|
|
|
|
gSprites[sTradeAnim->connectionSpriteId1].y2 -= 3;
|
|
|
|
gSprites[sTradeAnim->connectionSpriteId2].y2 += 3;
|
|
|
|
if (gSprites[sTradeAnim->connectionSpriteId1].y2 <= -222)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, -1, 0, 16, RGB_BLACK);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
|
|
|
DestroySprite(&gSprites[sTradeAnim->connectionSpriteId1]);
|
|
|
|
DestroySprite(&gSprites[sTradeAnim->connectionSpriteId2]);
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_CREATE_LINK_MON_ARRIVING:
|
2019-10-09 15:55:06 +02:00
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
SetTradeSequenceBgGpuRegs(1);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->bg1vofs = 166;
|
|
|
|
sTradeAnim->connectionSpriteId1 = CreateSprite(&sSpriteTemplate_LinkMonGlow, 128, -20, 3);
|
|
|
|
sTradeAnim->connectionSpriteId2 = CreateSprite(&sSpriteTemplate_LinkMonShadow, 128, -20, 0);
|
|
|
|
StartSpriteAnim(&gSprites[sTradeAnim->connectionSpriteId2], ANIM_LINKMON_SMALL);
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_FADE_OUT_TO_GBA_RECV:
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, -1, 16, 0, RGB_BLACK);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_WAIT_FADE_OUT_TO_GBA_RECV:
|
2019-10-09 15:55:06 +02:00
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 |
|
|
|
|
DISPCNT_OBJ_1D_MAP |
|
|
|
|
DISPCNT_BG1_ON |
|
|
|
|
DISPCNT_OBJ_ON);
|
|
|
|
if (!gPaletteFade.active)
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_LINK_MON_TRAVEL_IN:
|
|
|
|
gSprites[sTradeAnim->connectionSpriteId1].y2 += 3;
|
|
|
|
gSprites[sTradeAnim->connectionSpriteId2].y2 += 3;
|
|
|
|
if (gSprites[sTradeAnim->connectionSpriteId1].y2 + gSprites[sTradeAnim->connectionSpriteId1].y == 64)
|
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_PAN_TO_GBA:
|
|
|
|
if ((sTradeAnim->bg1vofs += 2) > 316)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->bg1vofs = 316;
|
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_DESTROY_LINK_MON:
|
|
|
|
DestroySprite(&gSprites[sTradeAnim->connectionSpriteId1]);
|
|
|
|
DestroySprite(&gSprites[sTradeAnim->connectionSpriteId2]);
|
|
|
|
sTradeAnim->state++;
|
|
|
|
sTradeAnim->timer = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_LINK_MON_ARRIVED_DELAY:
|
|
|
|
if (++sTradeAnim->timer == 10)
|
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_MOVE_GBA_TO_CENTER:
|
|
|
|
if (++sTradeAnim->bg1vofs > 348)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->bg1vofs = 348;
|
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
2022-12-15 22:00:53 +01:00
|
|
|
if (sTradeAnim->bg1vofs == 328 && sTradeAnim->isCableTrade)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->cableEndSpriteId = CreateSprite(&sSpriteTemplate_CableEnd, 128, 65, 0);
|
|
|
|
gSprites[sTradeAnim->cableEndSpriteId].callback = SpriteCB_CableEndReceiving;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_GBA_FLASH_RECV:
|
|
|
|
sTradeAnim->connectionSpriteId2 = CreateSprite(&sSpriteTemplate_GbaScreenFlash_Long, 120, 80, 0);
|
|
|
|
sTradeAnim->state = STATE_GBA_STOP_FLASH_RECV;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_GBA_STOP_FLASH_RECV:
|
|
|
|
if (gSprites[sTradeAnim->connectionSpriteId2].animEnded)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
DestroySprite(&gSprites[sTradeAnim->connectionSpriteId2]);
|
2019-10-09 15:55:06 +02:00
|
|
|
SetTradeSequenceBgGpuRegs(6);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_M_SAND_ATTACK);
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_GBA_ZOOM_IN:
|
|
|
|
if (sTradeAnim->gbaScale < 0x400)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->gbaScale += 0x34;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->gbaScale = 0x400;
|
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->sXY = 0x8000 / sTradeAnim->gbaScale;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_FADE_OUT_TO_NEW_MON:
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state = STATE_WAIT_FADE_OUT_TO_NEW_MON;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2018-12-28 09:11:41 +01:00
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_WAIT_FADE_OUT_TO_NEW_MON:
|
2019-10-09 15:55:06 +02:00
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
|
|
|
SetTradeSequenceBgGpuRegs(5);
|
|
|
|
SetTradeSequenceBgGpuRegs(7);
|
|
|
|
gPaletteFade.bufferTransferDisabled = TRUE;
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_FADE_IN_TO_NEW_MON:
|
2019-10-09 15:55:06 +02:00
|
|
|
gPaletteFade.bufferTransferDisabled = FALSE;
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_WAIT_FADE_IN_TO_NEW_MON:
|
2019-10-09 15:55:06 +02:00
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 |
|
|
|
|
DISPCNT_OBJ_1D_MAP |
|
|
|
|
DISPCNT_BG2_ON |
|
|
|
|
DISPCNT_OBJ_ON);
|
|
|
|
if (!gPaletteFade.active)
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
|
|
|
break;
|
|
|
|
case STATE_POKEBALL_ARRIVE:
|
|
|
|
sTradeAnim->bouncingPokeballSpriteId = CreateSprite(&sSpriteTemplate_Pokeball, 120, -8, 0);
|
|
|
|
gSprites[sTradeAnim->bouncingPokeballSpriteId].data[3] = 74;
|
|
|
|
gSprites[sTradeAnim->bouncingPokeballSpriteId].callback = SpriteCB_BouncingPokeballArrive;
|
|
|
|
StartSpriteAnim(&gSprites[sTradeAnim->bouncingPokeballSpriteId], 1);
|
|
|
|
StartSpriteAffineAnim(&gSprites[sTradeAnim->bouncingPokeballSpriteId], 2);
|
|
|
|
BlendPalettes(1 << (16 + gSprites[sTradeAnim->bouncingPokeballSpriteId].oam.paletteNum), 16, RGB_WHITEALPHA);
|
|
|
|
sTradeAnim->state++;
|
|
|
|
sTradeAnim->timer = 0;
|
|
|
|
break;
|
|
|
|
case STATE_FADE_POKEBALL_TO_NORMAL:
|
|
|
|
BeginNormalPaletteFade(1 << (16 + gSprites[sTradeAnim->bouncingPokeballSpriteId].oam.paletteNum), 1, 16, 0, RGB_WHITEALPHA);
|
|
|
|
sTradeAnim->state++;
|
|
|
|
break;
|
|
|
|
case STATE_POKEBALL_ARRIVE_WAIT:
|
|
|
|
if (gSprites[sTradeAnim->bouncingPokeballSpriteId].callback == SpriteCallbackDummy)
|
|
|
|
{
|
|
|
|
HandleLoadSpecialPokePic_2(&gMonFrontPicTable[sTradeAnim->monSpecies[TRADE_PARTNER]],
|
|
|
|
gMonSpritesGfxPtr->sprites.ptr[B_POSITION_OPPONENT_RIGHT],
|
|
|
|
sTradeAnim->monSpecies[TRADE_PARTNER],
|
|
|
|
sTradeAnim->monPersonalities[TRADE_PARTNER]);
|
|
|
|
sTradeAnim->state++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case STATE_SHOW_NEW_MON:
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PARTNER]].x = 120;
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PARTNER]].y = gMonFrontPicCoords[sTradeAnim->monSpecies[TRADE_PARTNER]].y_offset + 60;
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PARTNER]].x2 = 0;
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PARTNER]].y2 = 0;
|
|
|
|
StartSpriteAnim(&gSprites[sTradeAnim->monSpriteIds[TRADE_PARTNER]], 0);
|
|
|
|
CreatePokeballSpriteToReleaseMon(sTradeAnim->monSpriteIds[TRADE_PARTNER], gSprites[sTradeAnim->monSpriteIds[TRADE_PARTNER]].oam.paletteNum, 120, 84, 2, 1, 20, PALETTES_BG | (0xF << 16), sTradeAnim->monSpecies[TRADE_PARTNER]);
|
|
|
|
FreeSpriteOamMatrix(&gSprites[sTradeAnim->bouncingPokeballSpriteId]);
|
|
|
|
DestroySprite(&gSprites[sTradeAnim->bouncingPokeballSpriteId]);
|
|
|
|
sTradeAnim->state++;
|
|
|
|
break;
|
|
|
|
case STATE_NEW_MON_MSG:
|
2019-10-09 15:55:06 +02:00
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 |
|
|
|
|
DISPCNT_OBJ_1D_MAP |
|
|
|
|
DISPCNT_BG0_ON |
|
|
|
|
DISPCNT_BG2_ON |
|
|
|
|
DISPCNT_OBJ_ON);
|
|
|
|
StringExpandPlaceholders(gStringVar4, gText_XSentOverY);
|
|
|
|
DrawTextOnTradeWindow(0, gStringVar4, 0);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state = STATE_DELAY_FOR_MON_ANIM;
|
|
|
|
sTradeAnim->timer = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_DELAY_FOR_MON_ANIM:
|
|
|
|
if (++sTradeAnim->timer > 60)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state = STATE_WAIT_FOR_MON_CRY;
|
|
|
|
sTradeAnim->timer = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_WAIT_FOR_MON_CRY:
|
2019-10-09 15:55:06 +02:00
|
|
|
if (IsCryFinished())
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state = STATE_TAKE_CARE_OF_MON;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_TAKE_CARE_OF_MON:
|
|
|
|
if (++sTradeAnim->timer == 10)
|
2020-08-21 00:02:00 +02:00
|
|
|
PlayFanfare(MUS_EVOLVED);
|
2021-04-19 02:12:12 +02:00
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
if (sTradeAnim->timer == 250)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
StringExpandPlaceholders(gStringVar4, gText_TakeGoodCareOfX);
|
2019-10-04 01:39:37 +02:00
|
|
|
DrawTextOnTradeWindow(0, gStringVar4, 0);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->timer = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_AFTER_NEW_MON_DELAY:
|
|
|
|
if (++sTradeAnim->timer == 60)
|
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_CHECK_RIBBONS:
|
2019-10-09 15:55:06 +02:00
|
|
|
CheckPartnersMonForRibbons();
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_END_LINK_TRADE:
|
|
|
|
if (sTradeAnim->isLinkTrade)
|
2019-10-09 15:55:06 +02:00
|
|
|
return TRUE;
|
2020-09-05 03:11:55 +02:00
|
|
|
else if (JOY_NEW(A_BUTTON))
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_TRY_EVOLUTION: // Only if in-game trade, link trades use CB2_TryLinkTradeEvolution
|
2019-10-09 15:55:06 +02:00
|
|
|
TradeMons(gSpecialVar_0x8005, 0);
|
2022-12-15 22:00:53 +01:00
|
|
|
gCB2_AfterEvolution = CB2_InGameTrade;
|
2021-02-12 20:54:11 +01:00
|
|
|
evoTarget = GetEvolutionTargetSpecies(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], EVO_MODE_TRADE, ITEM_NONE);
|
2019-10-09 15:55:06 +02:00
|
|
|
if (evoTarget != SPECIES_NONE)
|
2022-12-15 22:00:53 +01:00
|
|
|
TradeEvolutionScene(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], evoTarget, sTradeAnim->monSpriteIds[TRADE_PARTNER], gSelectedTradeMonPositions[TRADE_PLAYER]);
|
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_FADE_OUT_END:
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_WAIT_FADE_OUT_END:
|
2019-10-09 15:55:06 +02:00
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
PlayNewMapMusic(sTradeAnim->cachedMapMusic);
|
|
|
|
if (sTradeAnim)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
|
|
|
FreeAllWindowBuffers();
|
|
|
|
Free(GetBgTilemapBuffer(3));
|
|
|
|
Free(GetBgTilemapBuffer(1));
|
|
|
|
Free(GetBgTilemapBuffer(0));
|
|
|
|
FreeMonSpritesGfx();
|
2022-12-15 22:00:53 +01:00
|
|
|
FREE_AND_SET_NULL(sTradeAnim);
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
SetMainCallback2(CB2_ReturnToField);
|
2020-01-08 19:19:41 +01:00
|
|
|
BufferInGameTradeMonName();
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2018-12-28 20:42:34 +01:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
// Task data for Task_AnimateWirelessSignal
|
|
|
|
#define tIdx data[0]
|
|
|
|
#define tCounter data[1]
|
|
|
|
#define tSignalComingBack data[2]
|
|
|
|
|
|
|
|
static bool8 DoTradeAnim_Wireless(void)
|
2018-12-28 20:42:34 +01:00
|
|
|
{
|
|
|
|
u16 evoTarget;
|
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
switch (sTradeAnim->state)
|
2018-12-28 20:42:34 +01:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_START:
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].invisible = FALSE;
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].x2 = -180;
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].y2 = gMonFrontPicCoords[sTradeAnim->monSpecies[TRADE_PLAYER]].y_offset;
|
|
|
|
sTradeAnim->state++;
|
|
|
|
sTradeAnim->cachedMapMusic = GetCurrentMapMusic();
|
2020-08-21 00:02:00 +02:00
|
|
|
PlayNewMapMusic(MUS_EVOLUTION);
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_MON_SLIDE_IN:
|
|
|
|
if (sTradeAnim->bg2hofs > 0)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].x2 += 3;
|
|
|
|
sTradeAnim->bg2hofs -= 3;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].x2 = 0;
|
|
|
|
sTradeAnim->bg2hofs = 0;
|
|
|
|
sTradeAnim->state = STATE_SEND_MSG;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_SEND_MSG:
|
2019-10-09 15:55:06 +02:00
|
|
|
StringExpandPlaceholders(gStringVar4, gText_XWillBeSentToY);
|
|
|
|
DrawTextOnTradeWindow(0, gStringVar4, 0);
|
2018-12-28 20:42:34 +01:00
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
if (sTradeAnim->monSpecies[TRADE_PLAYER] != SPECIES_EGG)
|
|
|
|
PlayCry_Normal(sTradeAnim->monSpecies[TRADE_PLAYER], 0);
|
2018-12-28 20:42:34 +01:00
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state = STATE_BYE_BYE;
|
|
|
|
sTradeAnim->timer = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_BYE_BYE:
|
|
|
|
if (++sTradeAnim->timer == 80)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->releasePokeballSpriteId = CreateTradePokeballSprite(sTradeAnim->monSpriteIds[TRADE_PLAYER], gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].oam.paletteNum, 120, 32, 2, 1, 0x14, 0xfffff);
|
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
StringExpandPlaceholders(gStringVar4, gText_ByeByeVar1);
|
|
|
|
DrawTextOnTradeWindow(0, gStringVar4, 0);
|
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_POKEBALL_DEPART:
|
|
|
|
if (gSprites[sTradeAnim->releasePokeballSpriteId].callback == SpriteCallbackDummy)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->bouncingPokeballSpriteId = CreateSprite(&sSpriteTemplate_Pokeball, 120, 32, 0);
|
|
|
|
gSprites[sTradeAnim->bouncingPokeballSpriteId].callback = SpriteCB_BouncingPokeballDepart;
|
|
|
|
DestroySprite(&gSprites[sTradeAnim->releasePokeballSpriteId]);
|
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_POKEBALL_DEPART_WAIT:
|
2019-10-09 15:55:06 +02:00
|
|
|
// The game waits here for the sprite to finish its animation sequence.
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_FADE_OUT_TO_GBA_SEND:
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state = STATE_WAIT_FADE_OUT_TO_GBA_SEND;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_WAIT_FADE_OUT_TO_GBA_SEND:
|
2019-10-09 15:55:06 +02:00
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
|
|
|
SetTradeSequenceBgGpuRegs(4);
|
|
|
|
FillWindowPixelBuffer(0, PIXEL_FILL(15));
|
2021-11-03 20:29:18 +01:00
|
|
|
CopyWindowToVram(0, COPYWIN_FULL);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_FADE_IN_TO_GBA_SEND:
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, -1, 16, 0, RGB_BLACK);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_WAIT_FADE_IN_TO_GBA_SEND:
|
2019-10-09 15:55:06 +02:00
|
|
|
if (!gPaletteFade.active)
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state = STATE_GBA_ZOOM_OUT;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_GBA_ZOOM_OUT:
|
|
|
|
if (sTradeAnim->gbaScale > 0x100)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->gbaScale -= 0x34;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetTradeSequenceBgGpuRegs(1);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->gbaScale = 0x80;
|
|
|
|
sTradeAnim->state = STATE_GBA_FLASH_SEND_WIRELESS;
|
|
|
|
sTradeAnim->timer = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->sXY = 0x8000 / sTradeAnim->gbaScale;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_GBA_FLASH_SEND_WIRELESS:
|
|
|
|
if (++sTradeAnim->timer > 20)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
|
|
|
SetTradeSequenceBgGpuRegs(3);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->connectionSpriteId2 = CreateSprite(&sSpriteTemplate_GbaScreenFlash_Short, 120, 80, 0);
|
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_GBA_STOP_FLASH_SEND_WIRELESS:
|
|
|
|
if (gSprites[sTradeAnim->connectionSpriteId2].animEnded)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
DestroySprite(&gSprites[sTradeAnim->connectionSpriteId2]);
|
2019-10-09 15:55:06 +02:00
|
|
|
SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG1 |
|
|
|
|
BLDCNT_TGT1_OBJ |
|
|
|
|
BLDCNT_EFFECT_BLEND |
|
|
|
|
BLDCNT_TGT2_BG2);
|
|
|
|
SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(16, 4));
|
2021-08-25 00:59:32 +02:00
|
|
|
|
2021-04-19 02:12:12 +02:00
|
|
|
// Start wireless signal effect
|
2019-10-09 15:55:06 +02:00
|
|
|
CreateTask(Task_AnimateWirelessSignal, 5);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_WAIT_WIRELESS_SIGNAL_SEND:
|
2019-10-09 15:55:06 +02:00
|
|
|
if (!FuncIsActiveTask(Task_AnimateWirelessSignal))
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state = STATE_PAN_AWAY_GBA;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_PAN_AWAY_GBA:
|
|
|
|
if (--sTradeAnim->bg1vofs == 316)
|
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_CREATE_LINK_MON_LEAVING:
|
|
|
|
sTradeAnim->connectionSpriteId1 = CreateSprite(&sSpriteTemplate_LinkMonGlow, 120, 80, 3);
|
|
|
|
gSprites[sTradeAnim->connectionSpriteId1].callback = SpriteCB_LinkMonGlowWireless;
|
|
|
|
sTradeAnim->connectionSpriteId2 = CreateSprite(&sSpriteTemplate_LinkMonShadow, 120, 80, 0);
|
|
|
|
StartSpriteAnim(&gSprites[sTradeAnim->connectionSpriteId2], ANIM_LINKMON_SMALL);
|
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_LINK_MON_TRAVEL_OUT:
|
|
|
|
if ((sTradeAnim->bg1vofs -= 3) == 166)
|
|
|
|
sTradeAnim->state = STATE_LINK_MON_TRAVEL_OFFSCREEN;
|
2021-04-19 02:12:12 +02:00
|
|
|
|
2019-10-09 15:55:06 +02:00
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_1 |
|
|
|
|
DISPCNT_OBJ_1D_MAP |
|
|
|
|
DISPCNT_BG1_ON |
|
|
|
|
DISPCNT_OBJ_ON);
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_LINK_MON_TRAVEL_OFFSCREEN:
|
|
|
|
gSprites[sTradeAnim->connectionSpriteId1].y -= 2;
|
|
|
|
gSprites[sTradeAnim->connectionSpriteId2].y -= 2;
|
|
|
|
if (gSprites[sTradeAnim->connectionSpriteId1].y < -8)
|
|
|
|
sTradeAnim->state = STATE_FADE_OUT_TO_CROSSING;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_FADE_OUT_TO_CROSSING:
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, -1, 0, 16, RGB_BLACK);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state = STATE_WAIT_FADE_OUT_TO_CROSSING;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_WAIT_FADE_OUT_TO_CROSSING:
|
2019-10-09 15:55:06 +02:00
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
DestroySprite(&gSprites[sTradeAnim->connectionSpriteId1]);
|
|
|
|
DestroySprite(&gSprites[sTradeAnim->connectionSpriteId2]);
|
2019-10-09 15:55:06 +02:00
|
|
|
SetTradeSequenceBgGpuRegs(2);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_FADE_IN_TO_CROSSING:
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, -1, 16, 0, RGB_BLACK);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->connectionSpriteId1 = CreateSprite(&sSpriteTemplate_LinkMonShadow, 111, 170, 0);
|
|
|
|
sTradeAnim->connectionSpriteId2 = CreateSprite(&sSpriteTemplate_LinkMonShadow, 129, -10, 0);
|
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_WAIT_FADE_IN_TO_CROSSING:
|
2019-10-09 15:55:06 +02:00
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_WARP_OUT);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
2022-12-15 22:00:53 +01:00
|
|
|
gSprites[sTradeAnim->connectionSpriteId1].y2 -= 3;
|
|
|
|
gSprites[sTradeAnim->connectionSpriteId2].y2 += 3;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_CROSSING_LINK_MONS_ENTER:
|
|
|
|
gSprites[sTradeAnim->connectionSpriteId1].y2 -= 3;
|
|
|
|
gSprites[sTradeAnim->connectionSpriteId2].y2 += 3;
|
|
|
|
if (gSprites[sTradeAnim->connectionSpriteId1].y2 <= -90)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
gSprites[sTradeAnim->connectionSpriteId1].data[1] = 1;
|
|
|
|
gSprites[sTradeAnim->connectionSpriteId2].data[1] = 1;
|
|
|
|
sTradeAnim->state++;
|
|
|
|
CreateTask(Task_OpenCenterWhiteColumn, 5);
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_CROSSING_BLEND_WHITE_1:
|
2019-10-09 15:55:06 +02:00
|
|
|
BlendPalettes(0x8, 16, RGB_WHITEALPHA);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_CROSSING_BLEND_WHITE_2:
|
2019-10-09 15:55:06 +02:00
|
|
|
BlendPalettes(0x8, 16, RGB_WHITEALPHA);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_CROSSING_BLEND_WHITE_3:
|
2019-10-09 15:55:06 +02:00
|
|
|
BlendPalettes(0x8, 16, RGB_WHITEALPHA);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_CROSSING_CREATE_MON_PICS:
|
|
|
|
if (!IsMonSpriteNotFlipped(sTradeAnim->monSpecies[TRADE_PLAYER]))
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].affineAnims = sAffineAnims_CrossingMonPics;
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].oam.affineMode = ST_OAM_AFFINE_DOUBLE;
|
|
|
|
CalcCenterToCornerVec(&gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]], SPRITE_SHAPE(64x64), SPRITE_SIZE(64x64), ST_OAM_AFFINE_DOUBLE);
|
|
|
|
StartSpriteAffineAnim(&gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]], 0);
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
StartSpriteAffineAnim(&gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]], 0);
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
2022-12-15 22:00:53 +01:00
|
|
|
StartSpriteAffineAnim(&gSprites[sTradeAnim->monSpriteIds[TRADE_PARTNER]], 0);
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].x = 40;
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PARTNER]].x = 200;
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].y = 192;
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PARTNER]].y = -32;
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].invisible = FALSE;
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PARTNER]].invisible = FALSE;
|
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_CROSSING_MON_PICS_MOVE:
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].y2 -= 3;
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PARTNER]].y2 += 3;
|
|
|
|
if (gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].y2 < -DISPLAY_HEIGHT
|
|
|
|
&& gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].y2 >= -DISPLAY_HEIGHT - 3)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_WARP_IN);
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
2022-12-15 22:00:53 +01:00
|
|
|
if (gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].y2 < -222)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
gSprites[sTradeAnim->connectionSpriteId1].data[1] = 0;
|
|
|
|
gSprites[sTradeAnim->connectionSpriteId2].data[1] = 0;
|
|
|
|
sTradeAnim->state++;
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]].invisible = TRUE;
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PARTNER]].invisible = TRUE;
|
|
|
|
CreateTask(Task_CloseCenterWhiteColumn, 5);
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_CROSSING_LINK_MONS_EXIT:
|
|
|
|
gSprites[sTradeAnim->connectionSpriteId1].y2 -= 3;
|
|
|
|
gSprites[sTradeAnim->connectionSpriteId2].y2 += 3;
|
|
|
|
if (gSprites[sTradeAnim->connectionSpriteId1].y2 <= -222)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, -1, 0, 16, RGB_BLACK);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
|
|
|
DestroySprite(&gSprites[sTradeAnim->connectionSpriteId1]);
|
|
|
|
DestroySprite(&gSprites[sTradeAnim->connectionSpriteId2]);
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_CREATE_LINK_MON_ARRIVING:
|
2019-10-09 15:55:06 +02:00
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
SetTradeSequenceBgGpuRegs(1);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->bg1vofs = 166;
|
2019-10-09 15:55:06 +02:00
|
|
|
SetTradeSequenceBgGpuRegs(3);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->bg2vofs = 412;
|
|
|
|
sTradeAnim->connectionSpriteId1 = CreateSprite(&sSpriteTemplate_LinkMonGlow, 120, -20, 3);
|
|
|
|
gSprites[sTradeAnim->connectionSpriteId1].callback = SpriteCB_LinkMonGlowWireless;
|
|
|
|
sTradeAnim->connectionSpriteId2 = CreateSprite(&sSpriteTemplate_LinkMonShadow, 120, -20, 0);
|
|
|
|
StartSpriteAnim(&gSprites[sTradeAnim->connectionSpriteId2], ANIM_LINKMON_SMALL);
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_FADE_OUT_TO_GBA_RECV:
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, -1, 16, 0, RGB_BLACK);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_WAIT_FADE_OUT_TO_GBA_RECV:
|
2019-10-09 15:55:06 +02:00
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 |
|
|
|
|
DISPCNT_OBJ_1D_MAP |
|
|
|
|
DISPCNT_BG1_ON |
|
|
|
|
DISPCNT_OBJ_ON);
|
|
|
|
if (!gPaletteFade.active)
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_LINK_MON_TRAVEL_IN:
|
|
|
|
gSprites[sTradeAnim->connectionSpriteId1].y2 += 4;
|
|
|
|
gSprites[sTradeAnim->connectionSpriteId2].y2 += 4;
|
|
|
|
if (gSprites[sTradeAnim->connectionSpriteId1].y2 + gSprites[sTradeAnim->connectionSpriteId1].y == 64)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state = STATE_PAN_TO_GBA_WIRELESS;
|
|
|
|
sTradeAnim->timer = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_PAN_TO_GBA_WIRELESS:
|
2019-10-09 15:55:06 +02:00
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 |
|
|
|
|
DISPCNT_OBJ_1D_MAP |
|
|
|
|
DISPCNT_BG1_ON |
|
|
|
|
DISPCNT_BG2_ON |
|
|
|
|
DISPCNT_OBJ_ON);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->bg1vofs += 3;
|
|
|
|
sTradeAnim->bg2vofs += 3;
|
|
|
|
if (++sTradeAnim->timer == 10)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
|
|
|
u8 taskId = CreateTask(Task_AnimateWirelessSignal, 5);
|
2022-12-15 22:00:53 +01:00
|
|
|
gTasks[taskId].tSignalComingBack = TRUE;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
2022-12-15 22:00:53 +01:00
|
|
|
if (sTradeAnim->bg1vofs > 316)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->bg1vofs = 316;
|
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_DESTROY_LINK_MON_WIRELESS:
|
|
|
|
DestroySprite(&gSprites[sTradeAnim->connectionSpriteId1]);
|
|
|
|
DestroySprite(&gSprites[sTradeAnim->connectionSpriteId2]);
|
|
|
|
sTradeAnim->state++;
|
|
|
|
sTradeAnim->timer = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_WAIT_WIRELESS_SIGNAL_RECV:
|
2019-10-09 15:55:06 +02:00
|
|
|
if (!FuncIsActiveTask(Task_AnimateWirelessSignal))
|
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state = STATE_LINK_MON_ARRIVED_DELAY;
|
|
|
|
sTradeAnim->timer = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_LINK_MON_ARRIVED_DELAY:
|
|
|
|
if (++sTradeAnim->timer == 10)
|
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_MOVE_GBA_TO_CENTER:
|
|
|
|
if (++sTradeAnim->bg1vofs > 348)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->bg1vofs = 348;
|
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_GBA_FLASH_RECV:
|
|
|
|
sTradeAnim->connectionSpriteId2 = CreateSprite(&sSpriteTemplate_GbaScreenFlash_Long, 120, 80, 0);
|
|
|
|
sTradeAnim->state = STATE_GBA_STOP_FLASH_RECV;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_GBA_STOP_FLASH_RECV:
|
|
|
|
if (gSprites[sTradeAnim->connectionSpriteId2].animEnded)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
DestroySprite(&gSprites[sTradeAnim->connectionSpriteId2]);
|
2019-10-09 15:55:06 +02:00
|
|
|
SetTradeSequenceBgGpuRegs(6);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_M_SAND_ATTACK);
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_GBA_ZOOM_IN:
|
|
|
|
if (sTradeAnim->gbaScale < 0x400)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->gbaScale += 0x34;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->gbaScale = 0x400;
|
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->sXY = 0x8000 / sTradeAnim->gbaScale;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_FADE_OUT_TO_NEW_MON:
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state = STATE_WAIT_FADE_OUT_TO_NEW_MON;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_WAIT_FADE_OUT_TO_NEW_MON:
|
2019-10-09 15:55:06 +02:00
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
|
|
|
SetTradeSequenceBgGpuRegs(5);
|
|
|
|
SetTradeSequenceBgGpuRegs(7);
|
|
|
|
gPaletteFade.bufferTransferDisabled = TRUE;
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_FADE_IN_TO_NEW_MON:
|
2019-10-09 15:55:06 +02:00
|
|
|
gPaletteFade.bufferTransferDisabled = FALSE;
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_WAIT_FADE_IN_TO_NEW_MON:
|
2019-10-09 15:55:06 +02:00
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 |
|
|
|
|
DISPCNT_OBJ_1D_MAP |
|
|
|
|
DISPCNT_BG2_ON |
|
|
|
|
DISPCNT_OBJ_ON);
|
|
|
|
if (!gPaletteFade.active)
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
|
|
|
break;
|
|
|
|
case STATE_POKEBALL_ARRIVE:
|
|
|
|
sTradeAnim->bouncingPokeballSpriteId = CreateSprite(&sSpriteTemplate_Pokeball, 120, -8, 0);
|
|
|
|
gSprites[sTradeAnim->bouncingPokeballSpriteId].data[3] = 74;
|
|
|
|
gSprites[sTradeAnim->bouncingPokeballSpriteId].callback = SpriteCB_BouncingPokeballArrive;
|
|
|
|
StartSpriteAnim(&gSprites[sTradeAnim->bouncingPokeballSpriteId], 1);
|
|
|
|
StartSpriteAffineAnim(&gSprites[sTradeAnim->bouncingPokeballSpriteId], 2);
|
|
|
|
BlendPalettes(1 << (16 + gSprites[sTradeAnim->bouncingPokeballSpriteId].oam.paletteNum), 16, RGB_WHITEALPHA);
|
|
|
|
sTradeAnim->state++;
|
|
|
|
sTradeAnim->timer = 0;
|
|
|
|
break;
|
|
|
|
case STATE_FADE_POKEBALL_TO_NORMAL:
|
|
|
|
BeginNormalPaletteFade(1 << (16 + gSprites[sTradeAnim->bouncingPokeballSpriteId].oam.paletteNum), 1, 16, 0, RGB_WHITEALPHA);
|
|
|
|
sTradeAnim->state++;
|
|
|
|
break;
|
|
|
|
case STATE_POKEBALL_ARRIVE_WAIT:
|
|
|
|
if (gSprites[sTradeAnim->bouncingPokeballSpriteId].callback == SpriteCallbackDummy)
|
|
|
|
{
|
|
|
|
HandleLoadSpecialPokePic_2(&gMonFrontPicTable[sTradeAnim->monSpecies[TRADE_PARTNER]],
|
2021-10-03 05:47:59 +02:00
|
|
|
gMonSpritesGfxPtr->sprites.ptr[B_POSITION_OPPONENT_RIGHT],
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->monSpecies[TRADE_PARTNER],
|
|
|
|
sTradeAnim->monPersonalities[TRADE_PARTNER]);
|
|
|
|
sTradeAnim->state++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case STATE_SHOW_NEW_MON:
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PARTNER]].x = 120;
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PARTNER]].y = gMonFrontPicCoords[sTradeAnim->monSpecies[TRADE_PARTNER]].y_offset + 60;
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PARTNER]].x2 = 0;
|
|
|
|
gSprites[sTradeAnim->monSpriteIds[TRADE_PARTNER]].y2 = 0;
|
|
|
|
StartSpriteAnim(&gSprites[sTradeAnim->monSpriteIds[TRADE_PARTNER]], 0);
|
|
|
|
CreatePokeballSpriteToReleaseMon(sTradeAnim->monSpriteIds[TRADE_PARTNER], gSprites[sTradeAnim->monSpriteIds[TRADE_PARTNER]].oam.paletteNum, 120, 84, 2, 1, 20, PALETTES_BG | (0xF << 16), sTradeAnim->monSpecies[TRADE_PARTNER]);
|
|
|
|
FreeSpriteOamMatrix(&gSprites[sTradeAnim->bouncingPokeballSpriteId]);
|
|
|
|
DestroySprite(&gSprites[sTradeAnim->bouncingPokeballSpriteId]);
|
|
|
|
sTradeAnim->state++;
|
|
|
|
break;
|
|
|
|
case STATE_NEW_MON_MSG:
|
2019-10-09 15:55:06 +02:00
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 |
|
|
|
|
DISPCNT_OBJ_1D_MAP |
|
|
|
|
DISPCNT_BG0_ON |
|
|
|
|
DISPCNT_BG2_ON |
|
|
|
|
DISPCNT_OBJ_ON);
|
|
|
|
StringExpandPlaceholders(gStringVar4, gText_XSentOverY);
|
|
|
|
DrawTextOnTradeWindow(0, gStringVar4, 0);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state = STATE_DELAY_FOR_MON_ANIM;
|
|
|
|
sTradeAnim->timer = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_DELAY_FOR_MON_ANIM:
|
|
|
|
if (++sTradeAnim->timer > 60)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state = STATE_WAIT_FOR_MON_CRY;
|
|
|
|
sTradeAnim->timer = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_WAIT_FOR_MON_CRY:
|
2019-10-09 15:55:06 +02:00
|
|
|
if (IsCryFinished())
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state = STATE_TAKE_CARE_OF_MON;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_TAKE_CARE_OF_MON:
|
|
|
|
if (++sTradeAnim->timer == 10)
|
2020-08-21 00:02:00 +02:00
|
|
|
PlayFanfare(MUS_EVOLVED);
|
2021-04-19 02:12:12 +02:00
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
if (sTradeAnim->timer == 250)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
StringExpandPlaceholders(gStringVar4, gText_TakeGoodCareOfX);
|
|
|
|
DrawTextOnTradeWindow(0, gStringVar4, 0);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->timer = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_AFTER_NEW_MON_DELAY:
|
|
|
|
if (++sTradeAnim->timer == 60)
|
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_CHECK_RIBBONS:
|
2019-10-09 15:55:06 +02:00
|
|
|
CheckPartnersMonForRibbons();
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_END_LINK_TRADE:
|
|
|
|
if (sTradeAnim->isLinkTrade)
|
2019-10-09 15:55:06 +02:00
|
|
|
return TRUE;
|
2020-09-05 03:11:55 +02:00
|
|
|
else if (JOY_NEW(A_BUTTON))
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_TRY_EVOLUTION: // Only if in-game trade, link trades use CB2_TryLinkTradeEvolution
|
2019-10-09 15:55:06 +02:00
|
|
|
TradeMons(gSpecialVar_0x8005, 0);
|
2022-12-15 22:00:53 +01:00
|
|
|
gCB2_AfterEvolution = CB2_InGameTrade;
|
2021-02-12 20:54:11 +01:00
|
|
|
evoTarget = GetEvolutionTargetSpecies(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], EVO_MODE_TRADE, ITEM_NONE);
|
2019-10-09 15:55:06 +02:00
|
|
|
if (evoTarget != SPECIES_NONE)
|
2022-12-15 22:00:53 +01:00
|
|
|
TradeEvolutionScene(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], evoTarget, sTradeAnim->monSpriteIds[TRADE_PARTNER], gSelectedTradeMonPositions[TRADE_PLAYER]);
|
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_FADE_OUT_END:
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
2022-12-15 22:00:53 +01:00
|
|
|
case STATE_WAIT_FADE_OUT_END:
|
2019-10-09 15:55:06 +02:00
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
PlayNewMapMusic(sTradeAnim->cachedMapMusic);
|
|
|
|
if (sTradeAnim)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
|
|
|
FreeAllWindowBuffers();
|
|
|
|
Free(GetBgTilemapBuffer(3));
|
|
|
|
Free(GetBgTilemapBuffer(1));
|
|
|
|
Free(GetBgTilemapBuffer(0));
|
|
|
|
FreeMonSpritesGfx();
|
2022-12-15 22:00:53 +01:00
|
|
|
FREE_AND_SET_NULL(sTradeAnim);
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
SetMainCallback2(CB2_ReturnToField);
|
2020-01-08 19:19:41 +01:00
|
|
|
BufferInGameTradeMonName();
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2018-12-28 09:11:41 +01:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
2018-12-29 19:46:15 +01:00
|
|
|
|
2021-04-19 02:12:12 +02:00
|
|
|
// Try to evolve a Pokémon received in a link trade
|
2022-12-15 22:00:53 +01:00
|
|
|
// In-game trades resolve evolution during the trade sequence, in STATE_TRY_EVOLUTION
|
2021-04-19 02:12:12 +02:00
|
|
|
static void CB2_TryLinkTradeEvolution(void)
|
2018-12-29 19:46:15 +01:00
|
|
|
{
|
|
|
|
u16 evoTarget;
|
|
|
|
switch (gMain.state)
|
|
|
|
{
|
2019-10-09 15:55:06 +02:00
|
|
|
case 0:
|
|
|
|
gMain.state = 4;
|
|
|
|
gSoftResetDisabled = TRUE;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
gCB2_AfterEvolution = CB2_SaveAndEndTrade;
|
2021-02-12 20:54:11 +01:00
|
|
|
evoTarget = GetEvolutionTargetSpecies(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], EVO_MODE_TRADE, ITEM_NONE);
|
2019-10-09 15:55:06 +02:00
|
|
|
if (evoTarget != SPECIES_NONE)
|
2022-12-15 22:00:53 +01:00
|
|
|
TradeEvolutionScene(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], evoTarget, sTradeAnim->monSpriteIds[TRADE_PARTNER], gSelectedTradeMonPositions[TRADE_PLAYER]);
|
2019-10-09 15:55:06 +02:00
|
|
|
else if (IsWirelessTrade())
|
|
|
|
SetMainCallback2(CB2_SaveAndEndWirelessTrade);
|
|
|
|
else
|
|
|
|
SetMainCallback2(CB2_SaveAndEndTrade);
|
|
|
|
gSelectedTradeMonPositions[TRADE_PLAYER] = 255;
|
|
|
|
break;
|
2018-12-29 19:46:15 +01:00
|
|
|
}
|
|
|
|
if (!HasLinkErrorOccurred())
|
|
|
|
RunTasks();
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
|
|
|
UpdatePaletteFade();
|
|
|
|
}
|
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
static void HandleLinkDataReceive(void)
|
2018-12-29 19:46:15 +01:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
u8 recvStatus;
|
2019-10-04 13:42:45 +02:00
|
|
|
TradeGetMultiplayerId(); // no effect call, ret val ignored
|
2022-12-15 22:00:53 +01:00
|
|
|
recvStatus = GetBlockReceivedStatus();
|
|
|
|
if (recvStatus & (1 << 0))
|
2018-12-29 19:46:15 +01:00
|
|
|
{
|
2019-10-09 15:55:06 +02:00
|
|
|
if (gBlockRecvBuffer[0][0] == LINKCMD_CONFIRM_FINISH_TRADE)
|
2021-04-19 02:12:12 +02:00
|
|
|
SetMainCallback2(CB2_TryLinkTradeEvolution);
|
2019-10-09 15:55:06 +02:00
|
|
|
|
|
|
|
if (gBlockRecvBuffer[0][0] == LINKCMD_READY_FINISH_TRADE)
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->playerFinishStatus = STATUS_READY;
|
2019-10-09 15:55:06 +02:00
|
|
|
|
2018-12-29 19:46:15 +01:00
|
|
|
ResetBlockReceivedFlag(0);
|
|
|
|
}
|
2022-12-15 22:00:53 +01:00
|
|
|
if (recvStatus & (1 << 1))
|
2018-12-29 19:46:15 +01:00
|
|
|
{
|
2019-10-09 15:55:06 +02:00
|
|
|
if (gBlockRecvBuffer[1][0] == LINKCMD_READY_FINISH_TRADE)
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->partnerFinishStatus = STATUS_READY;
|
2019-10-09 15:55:06 +02:00
|
|
|
|
2018-12-29 19:46:15 +01:00
|
|
|
ResetBlockReceivedFlag(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-19 02:12:12 +02:00
|
|
|
static void SpriteCB_BouncingPokeball(struct Sprite *sprite)
|
2018-12-29 19:46:15 +01:00
|
|
|
{
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->y += sprite->data[0] / 10;
|
2018-12-29 19:46:15 +01:00
|
|
|
sprite->data[5] += sprite->data[1];
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->x = sprite->data[5] / 10;
|
|
|
|
if (sprite->y > 0x4c)
|
2018-12-29 19:46:15 +01:00
|
|
|
{
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->y = 0x4c;
|
2018-12-29 19:46:15 +01:00
|
|
|
sprite->data[0] = -(sprite->data[0] * sprite->data[2]) / 100;
|
|
|
|
sprite->data[3] ++;
|
|
|
|
}
|
2021-07-07 15:11:52 +02:00
|
|
|
if (sprite->x == 0x78)
|
2018-12-29 19:46:15 +01:00
|
|
|
sprite->data[1] = 0;
|
|
|
|
sprite->data[0] += sprite->data[4];
|
|
|
|
if (sprite->data[3] == 4)
|
|
|
|
{
|
|
|
|
sprite->data[7] = 1;
|
|
|
|
sprite->callback = SpriteCallbackDummy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-19 02:12:12 +02:00
|
|
|
static void SpriteCB_BouncingPokeballDepart(struct Sprite *sprite)
|
2018-12-29 19:46:15 +01:00
|
|
|
{
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->y2 += sTradeBallVerticalVelocityTable[sprite->data[0]];
|
2018-12-29 19:46:15 +01:00
|
|
|
if (sprite->data[0] == 22)
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_BALL_BOUNCE_1);
|
2018-12-29 19:46:15 +01:00
|
|
|
if (++ sprite->data[0] == 44)
|
|
|
|
{
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_M_MEGA_KICK);
|
2021-04-19 02:12:12 +02:00
|
|
|
sprite->callback = SpriteCB_BouncingPokeballDepartEnd;
|
2018-12-29 19:46:15 +01:00
|
|
|
sprite->data[0] = 0;
|
|
|
|
BeginNormalPaletteFade(1 << (16 + sprite->oam.paletteNum), -1, 0, 16, RGB_WHITEALPHA);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-19 02:12:12 +02:00
|
|
|
static void SpriteCB_BouncingPokeballDepartEnd(struct Sprite *sprite)
|
2018-12-29 19:46:15 +01:00
|
|
|
{
|
|
|
|
if (sprite->data[1] == 20)
|
|
|
|
StartSpriteAffineAnim(sprite, 1);
|
|
|
|
if (++ sprite->data[1] > 20)
|
|
|
|
{
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->y2 -= sTradeBallVerticalVelocityTable[sprite->data[0]];
|
2018-12-29 19:46:15 +01:00
|
|
|
if (++ sprite->data[0] == 23)
|
|
|
|
{
|
|
|
|
DestroySprite(sprite);
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->state = STATE_FADE_OUT_TO_GBA_SEND; // Resume the master trade animation
|
2018-12-29 19:46:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-19 02:12:12 +02:00
|
|
|
static void SpriteCB_BouncingPokeballArrive(struct Sprite *sprite)
|
2018-12-29 19:46:15 +01:00
|
|
|
{
|
|
|
|
if (sprite->data[2] == 0)
|
|
|
|
{
|
2021-07-07 15:11:52 +02:00
|
|
|
if ((sprite->y += 4) > sprite->data[3])
|
2018-12-29 19:46:15 +01:00
|
|
|
{
|
|
|
|
sprite->data[2] ++;
|
|
|
|
sprite->data[0] = 0x16;
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_BALL_BOUNCE_1);
|
2018-12-29 19:46:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (sprite->data[0] == 0x42)
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_BALL_BOUNCE_2);
|
2018-12-29 19:46:15 +01:00
|
|
|
if (sprite->data[0] == 0x5c)
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_BALL_BOUNCE_3);
|
2018-12-29 19:46:15 +01:00
|
|
|
if (sprite->data[0] == 0x6b)
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_BALL_BOUNCE_4);
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->y2 += sTradeBallVerticalVelocityTable[sprite->data[0]];
|
2018-12-29 19:46:15 +01:00
|
|
|
if (++sprite->data[0] == 0x6c)
|
|
|
|
sprite->callback = SpriteCallbackDummy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u16 GetInGameTradeSpeciesInfo(void)
|
|
|
|
{
|
2019-10-03 07:16:22 +02:00
|
|
|
const struct InGameTrade *inGameTrade = &sIngameTrades[gSpecialVar_0x8004];
|
|
|
|
StringCopy(gStringVar1, gSpeciesNames[inGameTrade->requestedSpecies]);
|
2018-12-29 19:46:15 +01:00
|
|
|
StringCopy(gStringVar2, gSpeciesNames[inGameTrade->species]);
|
2019-10-03 07:16:22 +02:00
|
|
|
return inGameTrade->requestedSpecies;
|
2018-12-29 19:46:15 +01:00
|
|
|
}
|
|
|
|
|
2020-01-08 19:19:41 +01:00
|
|
|
static void BufferInGameTradeMonName(void)
|
2018-12-29 19:46:15 +01:00
|
|
|
{
|
|
|
|
u8 nickname[32];
|
2019-10-03 07:16:22 +02:00
|
|
|
const struct InGameTrade *inGameTrade = &sIngameTrades[gSpecialVar_0x8004];
|
2018-12-29 19:46:15 +01:00
|
|
|
GetMonData(&gPlayerParty[gSpecialVar_0x8005], MON_DATA_NICKNAME, nickname);
|
2021-11-18 04:11:03 +01:00
|
|
|
StringCopy_Nickname(gStringVar1, nickname);
|
2018-12-29 19:46:15 +01:00
|
|
|
StringCopy(gStringVar2, gSpeciesNames[inGameTrade->species]);
|
|
|
|
}
|
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
static void CreateInGameTradePokemonInternal(u8 whichPlayerMon, u8 whichInGameTrade)
|
2018-12-29 19:46:15 +01:00
|
|
|
{
|
2019-10-03 07:16:22 +02:00
|
|
|
const struct InGameTrade *inGameTrade = &sIngameTrades[whichInGameTrade];
|
2018-12-29 19:46:15 +01:00
|
|
|
u8 level = GetMonData(&gPlayerParty[whichPlayerMon], MON_DATA_LEVEL);
|
|
|
|
|
2021-10-23 16:55:46 +02:00
|
|
|
struct Mail mail;
|
2019-10-03 07:16:22 +02:00
|
|
|
u8 metLocation = METLOC_IN_GAME_TRADE;
|
2022-12-15 22:00:53 +01:00
|
|
|
u8 mailNum;
|
2018-12-29 19:46:15 +01:00
|
|
|
struct Pokemon *pokemon = &gEnemyParty[0];
|
|
|
|
|
2021-01-07 23:13:14 +01:00
|
|
|
CreateMon(pokemon, inGameTrade->species, level, USE_RANDOM_IVS, TRUE, inGameTrade->personality, OT_ID_PRESET, inGameTrade->otId);
|
2018-12-29 19:46:15 +01:00
|
|
|
|
|
|
|
SetMonData(pokemon, MON_DATA_HP_IV, &inGameTrade->ivs[0]);
|
|
|
|
SetMonData(pokemon, MON_DATA_ATK_IV, &inGameTrade->ivs[1]);
|
|
|
|
SetMonData(pokemon, MON_DATA_DEF_IV, &inGameTrade->ivs[2]);
|
|
|
|
SetMonData(pokemon, MON_DATA_SPEED_IV, &inGameTrade->ivs[3]);
|
|
|
|
SetMonData(pokemon, MON_DATA_SPATK_IV, &inGameTrade->ivs[4]);
|
|
|
|
SetMonData(pokemon, MON_DATA_SPDEF_IV, &inGameTrade->ivs[5]);
|
2019-10-03 07:16:22 +02:00
|
|
|
SetMonData(pokemon, MON_DATA_NICKNAME, inGameTrade->nickname);
|
2018-12-29 19:46:15 +01:00
|
|
|
SetMonData(pokemon, MON_DATA_OT_NAME, inGameTrade->otName);
|
|
|
|
SetMonData(pokemon, MON_DATA_OT_GENDER, &inGameTrade->otGender);
|
2019-10-03 07:16:22 +02:00
|
|
|
SetMonData(pokemon, MON_DATA_ABILITY_NUM, &inGameTrade->abilityNum);
|
|
|
|
SetMonData(pokemon, MON_DATA_BEAUTY, &inGameTrade->conditions[1]);
|
|
|
|
SetMonData(pokemon, MON_DATA_CUTE, &inGameTrade->conditions[2]);
|
|
|
|
SetMonData(pokemon, MON_DATA_COOL, &inGameTrade->conditions[0]);
|
|
|
|
SetMonData(pokemon, MON_DATA_SMART, &inGameTrade->conditions[3]);
|
|
|
|
SetMonData(pokemon, MON_DATA_TOUGH, &inGameTrade->conditions[4]);
|
2018-12-29 19:46:15 +01:00
|
|
|
SetMonData(pokemon, MON_DATA_SHEEN, &inGameTrade->sheen);
|
|
|
|
SetMonData(pokemon, MON_DATA_MET_LOCATION, &metLocation);
|
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
mailNum = 0;
|
2018-12-29 19:46:15 +01:00
|
|
|
if (inGameTrade->heldItem != ITEM_NONE)
|
|
|
|
{
|
|
|
|
if (ItemIsMail(inGameTrade->heldItem))
|
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
GetInGameTradeMail(&mail, inGameTrade);
|
2019-10-04 13:42:45 +02:00
|
|
|
gTradeMail[0] = mail;
|
2022-12-15 22:00:53 +01:00
|
|
|
SetMonData(pokemon, MON_DATA_MAIL, &mailNum);
|
2018-12-29 19:46:15 +01:00
|
|
|
SetMonData(pokemon, MON_DATA_HELD_ITEM, &inGameTrade->heldItem);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetMonData(pokemon, MON_DATA_HELD_ITEM, &inGameTrade->heldItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CalculateMonStats(&gEnemyParty[0]);
|
|
|
|
}
|
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
static void GetInGameTradeMail(struct Mail *mail, const struct InGameTrade *trade)
|
2021-12-14 18:47:04 +01:00
|
|
|
{
|
2018-12-29 19:46:15 +01:00
|
|
|
s32 i;
|
|
|
|
|
2019-10-05 16:41:37 +02:00
|
|
|
for (i = 0; i < MAIL_WORDS_COUNT; i++)
|
2019-10-04 01:39:37 +02:00
|
|
|
mail->words[i] = sIngameTradeMail[trade->mailNum][i];
|
2018-12-29 19:46:15 +01:00
|
|
|
|
|
|
|
StringCopy(mail->playerName, trade->otName);
|
|
|
|
PadNameString(mail->playerName, CHAR_SPACE);
|
|
|
|
|
|
|
|
mail->trainerId[0] = trade->otId >> 24;
|
|
|
|
mail->trainerId[1] = trade->otId >> 16;
|
|
|
|
mail->trainerId[2] = trade->otId >> 8;
|
|
|
|
mail->trainerId[3] = trade->otId;
|
|
|
|
mail->species = trade->species;
|
|
|
|
mail->itemId = trade->heldItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
u16 GetTradeSpecies(void)
|
|
|
|
{
|
|
|
|
if (GetMonData(&gPlayerParty[gSpecialVar_0x8005], MON_DATA_IS_EGG))
|
|
|
|
return SPECIES_NONE;
|
|
|
|
return GetMonData(&gPlayerParty[gSpecialVar_0x8005], MON_DATA_SPECIES);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CreateInGameTradePokemon(void)
|
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
CreateInGameTradePokemonInternal(gSpecialVar_0x8005, gSpecialVar_0x8004);
|
2018-12-29 19:46:15 +01:00
|
|
|
}
|
|
|
|
|
2019-10-09 15:55:06 +02:00
|
|
|
static void CB2_UpdateLinkTrade(void)
|
2018-12-29 19:46:15 +01:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
if (DoTradeAnim() == TRUE)
|
2018-12-29 19:46:15 +01:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
DestroySprite(&gSprites[sTradeAnim->monSpriteIds[TRADE_PLAYER]]);
|
|
|
|
FreeSpriteOamMatrix(&gSprites[sTradeAnim->monSpriteIds[TRADE_PARTNER]]);
|
2019-10-04 13:42:45 +02:00
|
|
|
TradeMons(gSelectedTradeMonPositions[TRADE_PLAYER], gSelectedTradeMonPositions[TRADE_PARTNER] % PARTY_SIZE);
|
|
|
|
if (!IsWirelessTrade())
|
2018-12-29 19:46:15 +01:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->linkData[0] = LINKCMD_READY_FINISH_TRADE;
|
|
|
|
sTradeAnim->scheduleLinkTransfer = 1;
|
2018-12-29 19:46:15 +01:00
|
|
|
}
|
2022-12-15 22:00:53 +01:00
|
|
|
SetMainCallback2(CB2_WaitTradeComplete);
|
2018-12-29 19:46:15 +01:00
|
|
|
}
|
2022-12-15 22:00:53 +01:00
|
|
|
HandleLinkDataSend();
|
|
|
|
HandleLinkDataReceive();
|
2018-12-29 19:46:15 +01:00
|
|
|
RunTasks();
|
|
|
|
RunTextPrinters();
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
|
|
|
UpdatePaletteFade();
|
|
|
|
}
|
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
static void CB2_WaitTradeComplete(void)
|
2018-12-29 19:46:15 +01:00
|
|
|
{
|
2019-10-04 13:42:45 +02:00
|
|
|
u8 mpId = TradeGetMultiplayerId();
|
|
|
|
if (IsWirelessTrade())
|
2018-12-29 19:46:15 +01:00
|
|
|
{
|
2021-04-19 02:12:12 +02:00
|
|
|
SetMainCallback2(CB2_TryLinkTradeEvolution);
|
2018-12-29 19:46:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
HandleLinkDataReceive();
|
2020-05-18 14:03:01 +02:00
|
|
|
if (mpId == 0
|
2022-12-15 22:00:53 +01:00
|
|
|
&& sTradeAnim->playerFinishStatus == STATUS_READY
|
|
|
|
&& sTradeAnim->partnerFinishStatus == STATUS_READY)
|
2018-12-29 19:46:15 +01:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->linkData[0] = LINKCMD_CONFIRM_FINISH_TRADE;
|
|
|
|
SendBlock(BitmaskAllOtherLinkPlayers(), sTradeAnim->linkData, sizeof(sTradeAnim->linkData));
|
|
|
|
sTradeAnim->playerFinishStatus = STATUS_CANCEL;
|
|
|
|
sTradeAnim->partnerFinishStatus = STATUS_CANCEL;
|
2018-12-29 19:46:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
RunTasks();
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
|
|
|
UpdatePaletteFade();
|
|
|
|
}
|
|
|
|
|
2019-10-09 15:55:06 +02:00
|
|
|
static void CB2_SaveAndEndTrade(void)
|
2018-12-29 19:46:15 +01:00
|
|
|
{
|
|
|
|
switch (gMain.state)
|
|
|
|
{
|
2019-10-09 15:55:06 +02:00
|
|
|
case 0:
|
|
|
|
gMain.state++;
|
|
|
|
StringExpandPlaceholders(gStringVar4, gText_CommunicationStandby5);
|
|
|
|
DrawTextOnTradeWindow(0, gStringVar4, 0);
|
|
|
|
break;
|
|
|
|
case 1:
|
2020-08-13 09:09:47 +02:00
|
|
|
SetTradeLinkStandbyCallback(0);
|
2019-10-09 15:55:06 +02:00
|
|
|
gMain.state = 100;
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->timer = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
|
|
|
case 100:
|
2022-12-15 22:00:53 +01:00
|
|
|
if (++sTradeAnim->timer > 180)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
|
|
|
gMain.state = 101;
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->timer = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
if (_IsLinkTaskFinished())
|
|
|
|
gMain.state = 2;
|
|
|
|
break;
|
|
|
|
case 101:
|
|
|
|
if (_IsLinkTaskFinished())
|
|
|
|
gMain.state = 2;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
gMain.state = 50;
|
|
|
|
StringExpandPlaceholders(gStringVar4, gText_SavingDontTurnOffPower);
|
|
|
|
DrawTextOnTradeWindow(0, gStringVar4, 0);
|
|
|
|
break;
|
|
|
|
case 50:
|
|
|
|
if (!InUnionRoom())
|
|
|
|
IncrementGameStat(GAME_STAT_POKEMON_TRADES);
|
|
|
|
if (gWirelessCommType)
|
2021-10-17 07:35:26 +02:00
|
|
|
MysteryGift_TryIncrementStat(CARD_STAT_NUM_TRADES, gLinkPlayers[GetMultiplayerId() ^ 1].trainerId);
|
2021-10-15 18:56:14 +02:00
|
|
|
|
2019-10-09 15:55:06 +02:00
|
|
|
SetContinueGameWarpStatusToDynamicWarp();
|
2021-10-29 04:54:41 +02:00
|
|
|
LinkFullSave_Init();
|
2019-10-09 15:55:06 +02:00
|
|
|
gMain.state++;
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->timer = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
|
|
|
case 51:
|
2022-12-15 22:00:53 +01:00
|
|
|
if (++sTradeAnim->timer == 5)
|
2018-12-29 19:46:15 +01:00
|
|
|
gMain.state++;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
|
|
|
case 52:
|
2021-10-29 04:54:41 +02:00
|
|
|
if (LinkFullSave_WriteSector())
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
|
|
|
ClearContinueGameWarpStatus2();
|
|
|
|
gMain.state = 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-29 04:54:41 +02:00
|
|
|
// Save isn't finished, delay again
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->timer = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
gMain.state = 51;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
2021-10-29 04:54:41 +02:00
|
|
|
LinkFullSave_ReplaceLastSector();
|
2019-10-09 15:55:06 +02:00
|
|
|
gMain.state = 40;
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->timer = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
|
|
|
case 40:
|
2022-12-15 22:00:53 +01:00
|
|
|
if (++sTradeAnim->timer > 50)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
|
|
|
if (GetMultiplayerId() == 0)
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->timer = Random() % 30;
|
2018-12-29 19:46:15 +01:00
|
|
|
else
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->timer = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
gMain.state = 41;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 41:
|
2022-12-15 22:00:53 +01:00
|
|
|
if (sTradeAnim->timer == 0)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2020-08-13 09:09:47 +02:00
|
|
|
SetTradeLinkStandbyCallback(1);
|
2019-10-09 15:55:06 +02:00
|
|
|
gMain.state = 42;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->timer--;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 42:
|
|
|
|
if (_IsLinkTaskFinished())
|
|
|
|
{
|
2022-08-05 16:31:50 +02:00
|
|
|
LinkFullSave_SetLastSectorSignature();
|
2019-10-09 15:55:06 +02:00
|
|
|
gMain.state = 5;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 5:
|
2022-12-15 22:00:53 +01:00
|
|
|
if (++sTradeAnim->timer > 60)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
|
|
|
gMain.state++;
|
2020-08-13 09:09:47 +02:00
|
|
|
SetTradeLinkStandbyCallback(2);
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
if (_IsLinkTaskFinished())
|
|
|
|
{
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK);
|
2019-10-09 15:55:06 +02:00
|
|
|
gMain.state ++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
|
|
|
FadeOutBGM(3);
|
|
|
|
gMain.state++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
if (IsBGMStopped() == TRUE)
|
|
|
|
{
|
|
|
|
if (gWirelessCommType && gMain.savedCallback == CB2_StartCreateTradeMenu)
|
2020-08-13 09:09:47 +02:00
|
|
|
SetTradeLinkStandbyCallback(3);
|
2018-12-29 19:46:15 +01:00
|
|
|
else
|
2020-08-13 09:09:47 +02:00
|
|
|
SetCloseLinkCallback();
|
2019-10-09 15:55:06 +02:00
|
|
|
gMain.state++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
if (gWirelessCommType && gMain.savedCallback == CB2_StartCreateTradeMenu)
|
|
|
|
{
|
2018-12-31 09:22:21 +01:00
|
|
|
if (_IsLinkTaskFinished())
|
2018-12-29 19:46:15 +01:00
|
|
|
{
|
|
|
|
gSoftResetDisabled = FALSE;
|
2022-12-15 22:00:53 +01:00
|
|
|
SetMainCallback2(CB2_FreeTradeAnim);
|
2018-12-29 19:46:15 +01:00
|
|
|
}
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
else if (!gReceivedRemoteLinkPlayers)
|
|
|
|
{
|
|
|
|
gSoftResetDisabled = FALSE;
|
2022-12-15 22:00:53 +01:00
|
|
|
SetMainCallback2(CB2_FreeTradeAnim);
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2018-12-29 19:46:15 +01:00
|
|
|
}
|
|
|
|
if (!HasLinkErrorOccurred())
|
|
|
|
{
|
|
|
|
RunTasks();
|
|
|
|
}
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
|
|
|
UpdatePaletteFade();
|
|
|
|
}
|
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
static void CB2_FreeTradeAnim(void)
|
2018-12-29 19:46:15 +01:00
|
|
|
{
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
|
|
|
FreeAllWindowBuffers();
|
|
|
|
Free(GetBgTilemapBuffer(3));
|
|
|
|
Free(GetBgTilemapBuffer(1));
|
|
|
|
Free(GetBgTilemapBuffer(0));
|
|
|
|
FreeMonSpritesGfx();
|
2022-12-15 22:00:53 +01:00
|
|
|
FREE_AND_SET_NULL(sTradeAnim);
|
2018-12-29 19:46:15 +01:00
|
|
|
if (gWirelessCommType)
|
2019-04-01 00:59:52 +02:00
|
|
|
DestroyWirelessStatusIndicatorSprite();
|
2018-12-29 19:46:15 +01:00
|
|
|
SetMainCallback2(gMain.savedCallback);
|
|
|
|
}
|
|
|
|
RunTasks();
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
|
|
|
UpdatePaletteFade();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoInGameTradeScene(void)
|
|
|
|
{
|
2022-08-15 21:18:12 +02:00
|
|
|
LockPlayerFieldControls();
|
2019-10-04 13:42:45 +02:00
|
|
|
CreateTask(Task_InGameTrade, 10);
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK);
|
2018-12-29 19:46:15 +01:00
|
|
|
}
|
|
|
|
|
2019-10-04 13:42:45 +02:00
|
|
|
static void Task_InGameTrade(u8 taskId)
|
2018-12-29 19:46:15 +01:00
|
|
|
{
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
SetMainCallback2(CB2_InitInGameTrade);
|
2019-12-17 09:24:44 +01:00
|
|
|
gFieldCallback = FieldCB_ContinueScriptHandleMusic;
|
2018-12-29 19:46:15 +01:00
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-04 01:39:37 +02:00
|
|
|
static void CheckPartnersMonForRibbons(void)
|
2018-12-29 19:46:15 +01:00
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
u8 numRibbons = 0;
|
2022-12-15 22:00:53 +01:00
|
|
|
for (i = 0; i < (MON_DATA_UNUSED_RIBBONS - MON_DATA_CHAMPION_RIBBON); i++)
|
2019-10-04 01:39:37 +02:00
|
|
|
numRibbons += GetMonData(&gEnemyParty[gSelectedTradeMonPositions[TRADE_PARTNER] % PARTY_SIZE], MON_DATA_CHAMPION_RIBBON + i);
|
2022-12-15 22:00:53 +01:00
|
|
|
|
2018-12-29 19:46:15 +01:00
|
|
|
if (numRibbons != 0)
|
|
|
|
FlagSet(FLAG_SYS_RIBBON_GET);
|
|
|
|
}
|
|
|
|
|
2022-07-29 23:00:07 +02:00
|
|
|
void LoadTradeAnimGfx(void)
|
2018-12-29 19:46:15 +01:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
TradeAnimInit_LoadGfx();
|
2018-12-29 19:46:15 +01:00
|
|
|
}
|
|
|
|
|
2019-10-04 01:39:37 +02:00
|
|
|
void DrawTextOnTradeWindow(u8 windowId, const u8 *str, u8 speed)
|
2018-12-29 19:46:15 +01:00
|
|
|
{
|
2019-03-02 23:25:39 +01:00
|
|
|
FillWindowPixelBuffer(windowId, PIXEL_FILL(15));
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->textColors[0] = TEXT_DYNAMIC_COLOR_6;
|
|
|
|
sTradeAnim->textColors[1] = TEXT_COLOR_WHITE;
|
|
|
|
sTradeAnim->textColors[2] = TEXT_COLOR_GREEN;
|
|
|
|
AddTextPrinterParameterized4(windowId, FONT_NORMAL, 0, 2, 0, 0, sTradeAnim->textColors, speed, str);
|
2021-11-03 20:29:18 +01:00
|
|
|
CopyWindowToVram(windowId, COPYWIN_FULL);
|
2018-12-29 19:46:15 +01:00
|
|
|
}
|
|
|
|
|
2019-10-09 15:55:06 +02:00
|
|
|
static void Task_AnimateWirelessSignal(u8 taskId)
|
2018-12-29 19:46:15 +01:00
|
|
|
{
|
|
|
|
s16 *data = gTasks[taskId].data;
|
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
u16 paletteIdx = sWirelessSignalAnimParams[tIdx][0] * 16;
|
2018-12-29 19:46:15 +01:00
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
if (!tSignalComingBack)
|
2018-12-29 19:46:15 +01:00
|
|
|
{
|
2019-10-09 15:55:06 +02:00
|
|
|
if (paletteIdx == 256)
|
2022-08-19 17:32:00 +02:00
|
|
|
LoadPalette(sWirelessSignalNone_Pal, BG_PLTT_ID(3), PLTT_SIZE_4BPP);
|
2018-12-29 19:46:15 +01:00
|
|
|
else
|
2022-08-19 17:32:00 +02:00
|
|
|
LoadPalette(&sWirelessSignalSend_Pal[paletteIdx], BG_PLTT_ID(3), PLTT_SIZE_4BPP);
|
2018-12-29 19:46:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-09 15:55:06 +02:00
|
|
|
if (paletteIdx == 256)
|
2022-08-19 17:32:00 +02:00
|
|
|
LoadPalette(sWirelessSignalNone_Pal, BG_PLTT_ID(3), PLTT_SIZE_4BPP);
|
2018-12-29 19:46:15 +01:00
|
|
|
else
|
2022-08-19 17:32:00 +02:00
|
|
|
LoadPalette(&sWirelessSignalRecv_Pal[paletteIdx], BG_PLTT_ID(3), PLTT_SIZE_4BPP);
|
2018-12-29 19:46:15 +01:00
|
|
|
}
|
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
if (sWirelessSignalAnimParams[tIdx][0] == 0 && tCounter == 0)
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_M_HEAL_BELL);
|
2018-12-29 19:46:15 +01:00
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
if (tCounter == sWirelessSignalAnimParams[tIdx][1])
|
2018-12-29 19:46:15 +01:00
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
tIdx++;
|
|
|
|
tCounter = 0;
|
|
|
|
if (sWirelessSignalAnimParams[tIdx][1] == 0xFF)
|
2018-12-29 19:46:15 +01:00
|
|
|
{
|
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
tCounter++;
|
2018-12-29 19:46:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
#undef tIdx
|
|
|
|
#undef tCounter
|
|
|
|
#undef tSignalComingBack
|
2019-10-09 11:56:44 +02:00
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
static void Task_OpenCenterWhiteColumn(u8 taskId)
|
2018-12-29 19:46:15 +01:00
|
|
|
{
|
|
|
|
s16 *data = gTasks[taskId].data;
|
|
|
|
|
|
|
|
if (data[0] == 0)
|
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->wirelessWinLeft = sTradeAnim->wirelessWinRight = DISPLAY_WIDTH / 2;
|
|
|
|
sTradeAnim->wirelessWinTop = 0;
|
|
|
|
sTradeAnim->wirelessWinBottom = DISPLAY_HEIGHT;
|
2018-12-29 19:46:15 +01:00
|
|
|
SetGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON);
|
|
|
|
SetGpuReg(REG_OFFSET_WINOUT, WINOUT_WIN01_OBJ);
|
|
|
|
SetGpuReg(REG_OFFSET_WININ, WININ_WIN0_BG0 |
|
|
|
|
WININ_WIN0_BG1 |
|
|
|
|
WININ_WIN0_OBJ);
|
|
|
|
}
|
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
SetGpuReg(REG_OFFSET_WIN0H, WIN_RANGE2(sTradeAnim->wirelessWinLeft, sTradeAnim->wirelessWinRight));
|
|
|
|
SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE2(sTradeAnim->wirelessWinTop, sTradeAnim->wirelessWinBottom));
|
2019-01-05 19:25:46 +01:00
|
|
|
|
2018-12-29 19:46:15 +01:00
|
|
|
data[0]++;
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->wirelessWinLeft -= 5;
|
|
|
|
sTradeAnim->wirelessWinRight += 5;
|
2018-12-29 19:46:15 +01:00
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
if (sTradeAnim->wirelessWinLeft < 80)
|
2018-12-29 19:46:15 +01:00
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
2018-12-29 20:50:24 +01:00
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
static void Task_CloseCenterWhiteColumn(u8 taskId)
|
2018-12-29 20:50:24 +01:00
|
|
|
{
|
|
|
|
s16 *data = gTasks[taskId].data;
|
|
|
|
|
|
|
|
if (data[0] == 0)
|
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->wirelessWinLeft = 80;
|
|
|
|
sTradeAnim->wirelessWinRight = DISPLAY_WIDTH - 80;
|
2018-12-29 20:50:24 +01:00
|
|
|
SetGpuReg(REG_OFFSET_WINOUT, WINOUT_WIN01_OBJ);
|
|
|
|
SetGpuReg(REG_OFFSET_WININ, WININ_WIN0_BG0 |
|
|
|
|
WININ_WIN0_BG1 |
|
|
|
|
WININ_WIN0_OBJ);
|
|
|
|
}
|
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
SetGpuReg(REG_OFFSET_WIN0H, WIN_RANGE2(sTradeAnim->wirelessWinLeft, sTradeAnim->wirelessWinRight));
|
|
|
|
SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE2(sTradeAnim->wirelessWinTop, sTradeAnim->wirelessWinBottom));
|
2019-01-05 19:25:46 +01:00
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
if (sTradeAnim->wirelessWinLeft != DISPLAY_WIDTH / 2)
|
2018-12-29 20:50:24 +01:00
|
|
|
{
|
|
|
|
data[0]++;
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->wirelessWinLeft += 5;
|
|
|
|
sTradeAnim->wirelessWinRight -= 5;
|
2018-12-29 20:50:24 +01:00
|
|
|
|
2022-12-15 22:00:53 +01:00
|
|
|
if (sTradeAnim->wirelessWinLeft > DISPLAY_WIDTH / 2 - 5)
|
2018-12-29 20:50:24 +01:00
|
|
|
BlendPalettes(0x8, 0, RGB_WHITEALPHA);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ClearGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON);
|
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-09 15:55:06 +02:00
|
|
|
static void CB2_SaveAndEndWirelessTrade(void)
|
2018-12-29 20:50:24 +01:00
|
|
|
{
|
|
|
|
switch (gMain.state)
|
|
|
|
{
|
2019-10-09 15:55:06 +02:00
|
|
|
case 0:
|
|
|
|
gMain.state = 1;
|
|
|
|
StringExpandPlaceholders(gStringVar4, gText_CommunicationStandby5);
|
|
|
|
DrawTextOnTradeWindow(0, gStringVar4, 0);
|
|
|
|
break;
|
|
|
|
case 1:
|
2020-08-13 09:09:47 +02:00
|
|
|
SetTradeLinkStandbyCallback(0);
|
2019-10-09 15:55:06 +02:00
|
|
|
gMain.state = 2;
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->timer = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (_IsLinkTaskFinished())
|
|
|
|
{
|
|
|
|
gMain.state = 3;
|
|
|
|
StringExpandPlaceholders(gStringVar4, gText_SavingDontTurnOffPower);
|
2019-10-04 01:39:37 +02:00
|
|
|
DrawTextOnTradeWindow(0, gStringVar4, 0);
|
2019-10-09 15:55:06 +02:00
|
|
|
IncrementGameStat(GAME_STAT_POKEMON_TRADES);
|
2021-10-29 04:54:41 +02:00
|
|
|
LinkFullSave_Init();
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->timer = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
2022-12-15 22:00:53 +01:00
|
|
|
if (++sTradeAnim->timer == 5)
|
2019-10-09 15:55:06 +02:00
|
|
|
gMain.state = 4;
|
|
|
|
break;
|
|
|
|
case 4:
|
2021-10-29 04:54:41 +02:00
|
|
|
if (LinkFullSave_WriteSector())
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
|
|
|
gMain.state = 5;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->timer = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
gMain.state = 3;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 5:
|
2021-10-29 04:54:41 +02:00
|
|
|
LinkFullSave_ReplaceLastSector();
|
2019-10-09 15:55:06 +02:00
|
|
|
gMain.state = 6;
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->timer = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
break;
|
|
|
|
case 6:
|
2022-12-15 22:00:53 +01:00
|
|
|
if (++sTradeAnim->timer > 10)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
|
|
|
if (GetMultiplayerId() == 0)
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->timer = Random() % 30;
|
2018-12-29 20:50:24 +01:00
|
|
|
else
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->timer = 0;
|
2019-10-09 15:55:06 +02:00
|
|
|
gMain.state = 7;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 7:
|
2022-12-15 22:00:53 +01:00
|
|
|
if (sTradeAnim->timer == 0)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
2020-08-13 09:09:47 +02:00
|
|
|
SetTradeLinkStandbyCallback(1);
|
2019-10-09 15:55:06 +02:00
|
|
|
gMain.state = 8;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-15 22:00:53 +01:00
|
|
|
sTradeAnim->timer--;
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
if (_IsLinkTaskFinished())
|
|
|
|
{
|
2022-08-05 16:31:50 +02:00
|
|
|
LinkFullSave_SetLastSectorSignature();
|
2019-10-09 15:55:06 +02:00
|
|
|
gMain.state = 9;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 9:
|
2022-12-15 22:00:53 +01:00
|
|
|
if (++sTradeAnim->timer > 60)
|
2019-10-09 15:55:06 +02:00
|
|
|
{
|
|
|
|
gMain.state++;
|
2020-08-13 09:09:47 +02:00
|
|
|
SetTradeLinkStandbyCallback(2);
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
if (_IsLinkTaskFinished())
|
|
|
|
{
|
|
|
|
FadeOutBGM(3);
|
2021-02-24 17:01:02 +01:00
|
|
|
BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK);
|
2019-10-09 15:55:06 +02:00
|
|
|
gMain.state = 11;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 11:
|
|
|
|
if (!gPaletteFade.active && IsBGMStopped() == TRUE)
|
|
|
|
{
|
2020-08-13 09:09:47 +02:00
|
|
|
SetTradeLinkStandbyCallback(3);
|
2019-10-09 15:55:06 +02:00
|
|
|
gMain.state = 12;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 12:
|
|
|
|
if (_IsLinkTaskFinished())
|
|
|
|
{
|
|
|
|
gSoftResetDisabled = FALSE;
|
2022-12-15 22:00:53 +01:00
|
|
|
SetMainCallback2(CB2_FreeTradeAnim);
|
2019-10-09 15:55:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2018-12-29 20:50:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!HasLinkErrorOccurred())
|
|
|
|
RunTasks();
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
|
|
|
UpdatePaletteFade();
|
|
|
|
}
|