2018-12-18 19:29:41 -06:00
|
|
|
#include "global.h"
|
2019-09-08 21:07:54 -04:00
|
|
|
#include "malloc.h"
|
2018-12-21 12:20:28 -06:00
|
|
|
#include "battle_anim.h"
|
2018-12-24 03:03:02 -06:00
|
|
|
#include "battle_interface.h"
|
2018-12-18 19:29:41 -06:00
|
|
|
#include "bg.h"
|
|
|
|
#include "cable_club.h"
|
2019-04-04 23:53:06 +02:00
|
|
|
#include "data.h"
|
2018-12-23 01:26:38 -06:00
|
|
|
#include "daycare.h"
|
2018-12-27 02:05:09 -06:00
|
|
|
#include "decompress.h"
|
2018-12-21 12:20:28 -06:00
|
|
|
#include "event_data.h"
|
2018-12-28 02:11:41 -06:00
|
|
|
#include "evolution_scene.h"
|
2018-12-29 12:46:15 -06:00
|
|
|
#include "field_screen_effect.h"
|
2018-12-18 19:29:41 -06: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 12:46:15 -06:00
|
|
|
#include "load_save.h"
|
2018-12-27 02:05:09 -06:00
|
|
|
#include "mail.h"
|
2018-12-18 19:29:41 -06:00
|
|
|
#include "main.h"
|
2019-03-30 14:36:52 -04:00
|
|
|
#include "mevent2.h"
|
|
|
|
#include "mystery_gift.h"
|
2018-12-21 12:20:28 -06:00
|
|
|
#include "overworld.h"
|
2018-12-18 19:29:41 -06:00
|
|
|
#include "palette.h"
|
|
|
|
#include "party_menu.h"
|
2018-12-28 02:11:41 -06:00
|
|
|
#include "pokeball.h"
|
2018-12-27 02:05:09 -06:00
|
|
|
#include "pokedex.h"
|
2018-12-18 19:29:41 -06:00
|
|
|
#include "pokemon_icon.h"
|
2018-12-21 12:20:28 -06:00
|
|
|
#include "pokemon_summary_screen.h"
|
2019-01-26 20:56:06 +01:00
|
|
|
#include "pokemon_storage_system.h"
|
2018-12-29 12:46:15 -06:00
|
|
|
#include "random.h"
|
|
|
|
#include "rom_8011DC0.h"
|
|
|
|
#include "save.h"
|
|
|
|
#include "script.h"
|
2018-12-18 19:29:41 -06:00
|
|
|
#include "sound.h"
|
|
|
|
#include "string_util.h"
|
2018-12-28 02:11:41 -06:00
|
|
|
#include "strings.h"
|
2018-12-18 19:29:41 -06:00
|
|
|
#include "task.h"
|
|
|
|
#include "text.h"
|
|
|
|
#include "text_window.h"
|
|
|
|
#include "trainer_card.h"
|
|
|
|
#include "trade.h"
|
2019-03-30 14:36:52 -04:00
|
|
|
#include "union_room.h"
|
2018-12-27 02:05:09 -06:00
|
|
|
#include "util.h"
|
2018-12-18 19:29:41 -06:00
|
|
|
#include "window.h"
|
2019-10-03 01:16:22 -04:00
|
|
|
#include "constants/contest.h"
|
2018-12-31 01:23:27 -06:00
|
|
|
#include "constants/easy_chat.h"
|
2018-12-28 02:11:41 -06:00
|
|
|
#include "constants/items.h"
|
2018-12-22 01:26:53 -06:00
|
|
|
#include "constants/moves.h"
|
2019-10-03 01:16:22 -04:00
|
|
|
#include "constants/region_map_sections.h"
|
|
|
|
#include "constants/rgb.h"
|
2018-12-18 19:29:41 -06:00
|
|
|
#include "constants/species.h"
|
|
|
|
#include "constants/songs.h"
|
|
|
|
|
2018-12-29 12:46:15 -06:00
|
|
|
#define Trade_SendData(ptr) (SendBlock(bitmask_all_link_players_but_self(), ptr->linkData, 20))
|
|
|
|
|
2018-12-28 02:11:41 -06:00
|
|
|
struct InGameTrade {
|
2019-10-03 01:16:22 -04:00
|
|
|
/*0x00*/ u8 nickname[POKEMON_NAME_LENGTH + 1];
|
2018-12-28 02:11:41 -06:00
|
|
|
/*0x0C*/ u16 species;
|
2019-10-03 01:16:22 -04:00
|
|
|
/*0x0E*/ u8 ivs[NUM_STATS];
|
|
|
|
/*0x14*/ u8 abilityNum;
|
2018-12-28 02:11:41 -06:00
|
|
|
/*0x18*/ u32 otId;
|
2019-10-03 01:16:22 -04:00
|
|
|
/*0x1C*/ u8 conditions[CONTEST_CATEGORIES_COUNT];
|
2018-12-28 02:11:41 -06:00
|
|
|
/*0x24*/ u32 personality;
|
|
|
|
/*0x28*/ u16 heldItem;
|
|
|
|
/*0x2A*/ u8 mailNum;
|
|
|
|
/*0x2B*/ u8 otName[11];
|
|
|
|
/*0x36*/ u8 otGender;
|
|
|
|
/*0x37*/ u8 sheen;
|
2019-10-03 01:16:22 -04:00
|
|
|
/*0x38*/ u16 requestedSpecies;
|
2018-12-28 02:11:41 -06:00
|
|
|
};
|
|
|
|
|
2019-10-05 10:41:37 -04:00
|
|
|
static EWRAM_DATA u8 *sMessageBoxAllocBuffer = NULL;
|
|
|
|
|
|
|
|
// Bytes 0-2 are used for the player's name box
|
|
|
|
// Bytes 3-5 are used for the partner's name box
|
|
|
|
// Bytes 6-7 are used for the Cancel box
|
|
|
|
// Bytes 8-13 are used for the Choose a Pokemon box
|
|
|
|
static EWRAM_DATA u8 *sMessageBoxTileBuffers[14] = {NULL};
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
EWRAM_DATA struct MailStruct gTradeMail[PARTY_SIZE] = {0};
|
2019-10-03 19:39:37 -04:00
|
|
|
EWRAM_DATA u8 gSelectedTradeMonPositions[2] = {0};
|
2018-12-31 01:23:27 -06:00
|
|
|
static EWRAM_DATA struct {
|
2019-10-03 19:39:37 -04:00
|
|
|
/*0x0000*/ u8 bg2hofs;
|
|
|
|
/*0x0001*/ u8 bg3hofs;
|
2018-12-28 02:11:41 -06:00
|
|
|
/*0x0002*/ u8 filler_2[0x28 - 2];
|
2019-10-06 22:58:25 -04:00
|
|
|
/*0x0028*/ u8 partySpriteIds[2][PARTY_SIZE];
|
2019-10-03 19:39:37 -04:00
|
|
|
/*0x0034*/ u8 cursorSpriteIdx;
|
|
|
|
/*0x0035*/ u8 cursorPosition;
|
|
|
|
/*0x0036*/ u8 partyCounts[2];
|
2019-10-04 07:42:45 -04:00
|
|
|
/*0x0038*/ bool8 monPresent[PARTY_SIZE * 2];
|
2019-10-03 01:16:22 -04:00
|
|
|
/*0x0044*/ u8 neverRead_44;
|
2019-10-03 19:39:37 -04:00
|
|
|
/*0x0045*/ bool8 isLiveMon[2][PARTY_SIZE];
|
|
|
|
/*0x0051*/ bool8 isEgg[2][PARTY_SIZE];
|
|
|
|
/*0x005D*/ u8 hpBarLevels[2][PARTY_SIZE];
|
2019-10-06 22:58:25 -04:00
|
|
|
/*0x0069*/ u8 unk_69; //state var for shedinja_maker_maybe
|
2018-12-28 02:11:41 -06:00
|
|
|
/*0x006A*/ u8 filler_6A[0x6F - 0x6A];
|
2019-10-06 22:58:25 -04:00
|
|
|
/*0x006F*/ u8 tradeMenuFunc; //switch var for sub_80795AC
|
2019-10-04 07:42:45 -04:00
|
|
|
/*0x0070*/ u8 neverRead_70;
|
2018-12-28 02:11:41 -06:00
|
|
|
/*0x0071*/ u8 filler_71;
|
2019-10-04 07:42:45 -04:00
|
|
|
/*0x0072*/ u16 unk_72; //sheet
|
|
|
|
/*0x0074*/ u8 drawPartyState[2];
|
2019-10-03 19:39:37 -04:00
|
|
|
/*0x0076*/ u8 selectedMonIdx[2];
|
2019-10-06 22:58:25 -04:00
|
|
|
/*0x0078*/ u8 playerLinkFlagChoseAction;
|
|
|
|
/*0x0079*/ u8 partnerLinkFlagChoseAction;
|
|
|
|
/*0x007A*/ u8 playerLinkFlagChoseMon;
|
|
|
|
/*0x007B*/ u8 partnerLinkFlagChoseMon;
|
2018-12-28 02:11:41 -06:00
|
|
|
/*0x007C*/ u8 filler_7C[0x7E - 0x7C];
|
2019-10-03 19:39:37 -04:00
|
|
|
/*0x007E*/ u8 partnerCursorPosition;
|
2019-10-04 07:42:45 -04:00
|
|
|
/*0x007F*/ u8 unused_7F;
|
2018-12-31 02:22:21 -06:00
|
|
|
/*0x0080*/ u16 linkData[20];
|
2019-10-06 22:58:25 -04:00
|
|
|
/*0x00A8*/ u8 timer;
|
|
|
|
/*0x00A9*/ u8 giftRibbons[11];
|
2018-12-28 02:11:41 -06:00
|
|
|
/*0x00B4*/ u8 filler_B4[0x8D0-0xB4];
|
|
|
|
/*0x08D0*/ struct {
|
2019-10-06 22:58:25 -04:00
|
|
|
bool8 queued;
|
|
|
|
u16 queueDelay;
|
|
|
|
u8 actionId;
|
|
|
|
} queuedActions[4];
|
2018-12-28 02:11:41 -06:00
|
|
|
/*0x08F0*/ u16 tilemapBuffer[0x400];
|
2019-10-04 07:42:45 -04:00
|
|
|
} *sTradeData = {NULL};
|
2018-12-31 01:23:27 -06:00
|
|
|
static EWRAM_DATA struct {
|
2018-12-28 02:11:41 -06:00
|
|
|
/*0x00*/ struct Pokemon mon;
|
2018-12-31 01:23:27 -06:00
|
|
|
/*0x64*/ u32 timer;
|
2019-10-04 07:42:45 -04:00
|
|
|
/*0x68*/ u32 monPersonalities[2];
|
2018-12-28 02:11:41 -06:00
|
|
|
/*0x70*/ u8 filler_70[2];
|
|
|
|
/*0x72*/ u8 unk_72;
|
|
|
|
/*0x73*/ u8 unk_73;
|
2018-12-29 12:46:15 -06:00
|
|
|
/*0x74*/ u16 linkData[10];
|
2019-10-05 10:41:37 -04:00
|
|
|
/*0x88*/ u8 alwaysZero_88;
|
|
|
|
/*0x89*/ u8 alwaysZero_89;
|
|
|
|
/*0x8A*/ u16 linkTimeoutCounter;
|
2019-10-04 07:42:45 -04:00
|
|
|
/*0x8C*/ u16 neverRead_8C;
|
2018-12-28 02:11:41 -06:00
|
|
|
/*0x8E*/ u8 pokePicSpriteIdxs[2];
|
2019-10-04 07:42:45 -04:00
|
|
|
/*0x90*/ u8 unk_90; //sprite id
|
|
|
|
/*0x91*/ u8 unk_91; //sprite id
|
|
|
|
/*0x92*/ u8 unk_92; //sprite id
|
2018-12-28 02:11:41 -06:00
|
|
|
/*0x93*/ u8 unk_93;
|
2018-12-31 01:23:27 -06:00
|
|
|
/*0x94*/ u16 state;
|
2018-12-28 02:11:41 -06:00
|
|
|
/*0x96*/ u8 filler_96[0xD2 - 0x96];
|
2019-10-04 07:42:45 -04:00
|
|
|
/*0xD2*/ u8 unk_D2; //sprite id
|
|
|
|
/*0xD3*/ u8 unk_D3; //sprite id
|
|
|
|
/*0xD4*/ u16 texX;
|
|
|
|
/*0xD6*/ u16 texY;
|
|
|
|
/*0xD8*/ u16 neverRead_D8;
|
|
|
|
/*0xDA*/ u16 neverRead_DA;
|
|
|
|
/*0xDC*/ u16 scrX;
|
|
|
|
/*0xDE*/ u16 scrY;
|
2018-12-28 02:11:41 -06:00
|
|
|
/*0xE0*/ s16 bg1vofs;
|
|
|
|
/*0xE2*/ s16 bg1hofs;
|
|
|
|
/*0xE4*/ s16 bg2vofs;
|
|
|
|
/*0xE6*/ s16 bg2hofs;
|
2019-10-04 07:42:45 -04:00
|
|
|
/*0xE8*/ u16 sXY;
|
|
|
|
/*0xEA*/ u16 unk_EA; //sXY divisor
|
|
|
|
/*0xEC*/ u16 alpha;
|
2018-12-28 02:11:41 -06:00
|
|
|
/*0xEE*/ bool8 isLinkTrade;
|
2019-10-04 07:42:45 -04:00
|
|
|
/*0xF0*/ u16 monSpecies[2];
|
2018-12-31 01:23:27 -06:00
|
|
|
/*0xF4*/ u16 cachedMapMusic;
|
2019-10-03 19:39:37 -04:00
|
|
|
/*0xF6*/ u8 textColors[3];
|
2018-12-29 12:46:15 -06:00
|
|
|
/*0xF9*/ u8 filler_F9;
|
2019-10-05 10:41:37 -04:00
|
|
|
/*0xFA*/ bool8 isCableTrade;
|
2018-12-29 12:46:15 -06:00
|
|
|
/*0xFB*/ u8 unk_FB;
|
|
|
|
/*0xFC*/ u8 unk_FC;
|
|
|
|
/*0xFD*/ u8 unk_FD;
|
|
|
|
/*0xFE*/ u8 unk_FE;
|
2019-10-04 07:42:45 -04:00
|
|
|
} *sTradeWindowData = {NULL};
|
2018-12-31 01:23:27 -06:00
|
|
|
|
2019-07-18 20:46:00 -04:00
|
|
|
#if !defined(NONMATCHING) && MODERN
|
|
|
|
#define static
|
|
|
|
#endif
|
2019-10-04 07:42:45 -04:00
|
|
|
static bool32 IsWirelessTrade(void);
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_80773D0(void);
|
|
|
|
static void sub_807811C(void);
|
2019-10-06 22:58:25 -04:00
|
|
|
static void CB2_TradeMenu(void);
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_80782B8(u8);
|
2019-10-06 22:58:25 -04:00
|
|
|
static void SetTradePartyMonsVisible(void);
|
2018-12-31 01:23:27 -06:00
|
|
|
static bool8 shedinja_maker_maybe(void);
|
|
|
|
static void sub_8078C34(void);
|
|
|
|
static void sub_80795AC(void);
|
2019-10-03 19:39:37 -04:00
|
|
|
static void SetSelectedMon(u8);
|
2019-10-04 07:42:45 -04:00
|
|
|
static void DrawTradeMenuParty(u8);
|
2019-10-06 22:58:25 -04:00
|
|
|
static u8 GetMonNicknameWidth(u8 *, u8, u8);
|
2019-10-03 01:16:22 -04:00
|
|
|
static void BufferTradeMonMoves(u8 *, u8, u8);
|
2019-10-03 19:39:37 -04:00
|
|
|
static void PrintPartyNicknamesForTradeMenu(u8);
|
2019-10-04 07:42:45 -04:00
|
|
|
static void DrawTradeMenuPartyMonInfo(u8, u8, u8, u8, u8, u8);
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_8079E44(u8);
|
|
|
|
static void sub_8079F74(void);
|
2019-10-06 22:58:25 -04:00
|
|
|
static void RedrawTradeMenuParty(u8);
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807A000(u8 taskId);
|
|
|
|
static void sub_807A024(u8 taskId);
|
2019-10-06 22:58:25 -04:00
|
|
|
static void QueueAction(u16, u8);
|
|
|
|
static u32 GetNumQueuedActions(void);
|
|
|
|
static void DoQueuedActions(void);
|
2019-10-03 19:39:37 -04:00
|
|
|
static void PrintTradeMessage(u8);
|
2019-10-06 22:58:25 -04:00
|
|
|
static bool8 LoadTradeMenuSpriteSheetsAndPalettes(void);
|
|
|
|
static void DrawTextWindowAndBuffer6Bytes(const u8 *, u8 *, u8);
|
|
|
|
static void SetTradePartyLiveStatuses(u8);
|
2019-10-03 19:39:37 -04:00
|
|
|
static void GetTradePartyHPBarLevels(u8);
|
|
|
|
static void SetTradePartyHPBarSprites(void);
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807A5B0(void);
|
2019-10-06 22:58:25 -04:00
|
|
|
static u32 CanTradeSelectedMon(struct Pokemon *, int, int);
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807AA28(struct Sprite *sprite);
|
|
|
|
static void sub_807AA7C(struct Sprite *sprite);
|
|
|
|
static void sub_807AABC(struct Sprite *sprite);
|
|
|
|
static void sub_807AAE0(struct Sprite *sprite);
|
|
|
|
static void sub_807AB04(struct Sprite *sprite);
|
2019-10-05 10:41:37 -04:00
|
|
|
static void InitTradeBgInternal(void);
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807B60C(void);
|
|
|
|
static void sub_807B62C(u8);
|
2019-10-05 10:41:37 -04:00
|
|
|
static void LoadTradeSequenceSpriteSheetsAndPalettes(void);
|
2018-12-31 02:22:21 -06:00
|
|
|
static void SetTradeSceneStrings(void);
|
2019-10-05 10:41:37 -04:00
|
|
|
static bool8 AnimateTradeSequence(void);
|
|
|
|
static bool8 AnimateTradeSequenceCable(void);
|
|
|
|
static bool8 AnimateTradeSequenceWireless(void);
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807E55C(struct Sprite *sprite);
|
|
|
|
static void sub_807E5D8(struct Sprite *sprite);
|
|
|
|
static void sub_807E64C(struct Sprite *sprite);
|
|
|
|
static void sub_807E6AC(struct Sprite *sprite);
|
2019-10-05 10:41:37 -04:00
|
|
|
static void BuffeInGameTradeMonName(void);
|
2019-10-03 19:39:37 -04:00
|
|
|
static void SetInGameTradeMail(struct MailStruct *mail, const struct InGameTrade *trade);
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807EA2C(void);
|
|
|
|
static void sub_807EACC(void);
|
|
|
|
static void sub_807EB50(void);
|
|
|
|
static void c2_080543C4(void);
|
2019-10-04 07:42:45 -04:00
|
|
|
static void Task_InGameTrade(u8);
|
2019-10-03 19:39:37 -04:00
|
|
|
static void CheckPartnersMonForRibbons(void);
|
2018-12-31 01:23:27 -06:00
|
|
|
static void c3_08054588(u8);
|
|
|
|
static void c3_0805465C(u8);
|
|
|
|
static void sub_807F39C(u8);
|
|
|
|
static void sub_807F464(void);
|
|
|
|
|
2019-10-03 01:16:22 -04:00
|
|
|
#include "data/trade.h"
|
2018-12-28 02:11:41 -06:00
|
|
|
|
2019-10-03 19:39:37 -04:00
|
|
|
static bool8 SendLinkData(const void *linkData, u32 size)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
|
|
|
if (gUnknown_02022C2C == 29)
|
|
|
|
{
|
2019-10-03 19:39:37 -04:00
|
|
|
rfu_NI_setSendData(gUnknown_03004140.unk_00, 84, linkData, size);
|
2018-12-18 19:29:41 -06:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-03 19:39:37 -04:00
|
|
|
return SendBlock(0, linkData, size);
|
2018-12-18 19:29:41 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_80771AC(u8 a0)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
|
|
|
sub_800A4D8(a0);
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static bool32 sub_80771BC(void)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
|
|
|
if (gUnknown_02022C2C == 29)
|
|
|
|
{
|
|
|
|
if (gUnknown_03007880[sub_800E87C(gUnknown_03004140.unk_00)]->unk_0 == 0)
|
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
return IsLinkTaskFinished();
|
2018-12-18 19:29:41 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 02:22:21 -06:00
|
|
|
static u32 _GetBlockReceivedStatus(void)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
|
|
|
return GetBlockReceivedStatus();
|
|
|
|
}
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
static void TradeResetReceivedFlags(void)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
if (IsWirelessTrade())
|
2018-12-18 19:29:41 -06:00
|
|
|
rfu_clearSlot(12, gUnknown_03004140.unk_00);
|
|
|
|
else
|
|
|
|
ResetBlockReceivedFlags();
|
|
|
|
}
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
static void TradeResetReceivedFlag(u32 who)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
if (IsWirelessTrade())
|
2018-12-18 19:29:41 -06:00
|
|
|
rfu_clearSlot(12, gUnknown_03004140.unk_00);
|
|
|
|
else
|
2019-10-04 07:42:45 -04:00
|
|
|
ResetBlockReceivedFlag(who);
|
2018-12-18 19:29:41 -06:00
|
|
|
}
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
static bool32 IsWirelessTrade(void)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
if (gWirelessCommType && gUnknown_02022C2C == 29)
|
2018-12-18 19:29:41 -06:00
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_8077288(u8 unused)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
|
|
|
sub_800ADF8();
|
|
|
|
}
|
|
|
|
|
2018-12-31 02:22:21 -06:00
|
|
|
static bool32 _IsLinkTaskFinished(void)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
return IsLinkTaskFinished();
|
2018-12-18 19:29:41 -06:00
|
|
|
}
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
static void InitTradeMenu(void)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
|
|
|
ResetSpriteData();
|
|
|
|
FreeAllSpritePalettes();
|
|
|
|
ResetTasks();
|
|
|
|
ResetPaletteFade();
|
|
|
|
|
|
|
|
gPaletteFade.bufferTransferDisabled = TRUE;
|
|
|
|
|
|
|
|
SetVBlankCallback(sub_807811C);
|
|
|
|
LoadPalette(gUnknown_0860F074, 0xF0, 20);
|
|
|
|
LoadPalette(gUnknown_0860F074, 0xD0, 20);
|
|
|
|
ResetBgsAndClearDma3BusyFlags(0);
|
2019-10-06 22:58:25 -04:00
|
|
|
InitBgsFromTemplates(0, sTradeMenuBgTemplates, ARRAY_COUNT(sTradeMenuBgTemplates));
|
2019-10-04 07:42:45 -04:00
|
|
|
SetBgTilemapBuffer(1, sTradeData->tilemapBuffer);
|
2018-12-18 19:29:41 -06:00
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
if (InitWindows(sTradeMenuWindowTemplates))
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
|
|
|
u32 i;
|
|
|
|
|
|
|
|
DeactivateAllTextPrinters();
|
|
|
|
|
|
|
|
for (i = 0; i < 18; i++)
|
|
|
|
{
|
|
|
|
ClearWindowTilemap(i);
|
2019-03-02 17:25:39 -05:00
|
|
|
FillWindowPixelBuffer(i, PIXEL_FILL(0));
|
2018-12-18 19:29:41 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
FillBgTilemapBufferRect(0, 0, 0, 0, 30, 20, 15);
|
|
|
|
LoadUserWindowBorderGfx_(0, 20, 0xC0);
|
|
|
|
LoadUserWindowBorderGfx(2, 1, 0xE0);
|
|
|
|
LoadMonIconPalettes();
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->unk_69 = 0;
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->tradeMenuFunc = 0;
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->neverRead_70 = 0;
|
|
|
|
sTradeData->drawPartyState[TRADE_PLAYER] = 0;
|
|
|
|
sTradeData->drawPartyState[TRADE_PARTNER] = 0;
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->playerLinkFlagChoseMon = 0;
|
|
|
|
sTradeData->partnerLinkFlagChoseMon = 0;
|
|
|
|
sTradeData->timer = 0;
|
2018-12-18 19:29:41 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void sub_80773AC(void)
|
|
|
|
{
|
|
|
|
SetMainCallback2(sub_80773D0);
|
|
|
|
gMain.callback1 = NULL;
|
|
|
|
gEnemyPartyCount = 0;
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_80773D0(void)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct SpriteTemplate temp;
|
|
|
|
u8 id;
|
|
|
|
u32 xPos;
|
|
|
|
|
|
|
|
switch (gMain.state)
|
|
|
|
{
|
|
|
|
case 0:
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData = AllocZeroed(sizeof(*sTradeData));
|
|
|
|
InitTradeMenu();
|
2019-10-05 10:41:37 -04:00
|
|
|
sMessageBoxAllocBuffer = AllocZeroed(14 * 256);
|
2018-12-25 15:14:15 +01:00
|
|
|
|
2019-10-05 10:41:37 -04:00
|
|
|
for (i = 0; i < (int)ARRAY_COUNT(sMessageBoxTileBuffers); i++)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
2019-10-05 10:41:37 -04:00
|
|
|
sMessageBoxTileBuffers[i] = &sMessageBoxAllocBuffer[i * 256];
|
2018-12-18 19:29:41 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
gPaletteFade.bufferTransferDisabled = FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i < PARTY_SIZE; i++)
|
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
CreateMon(&gEnemyParty[i], SPECIES_NONE, 0, 32, FALSE, 0, OT_ID_PLAYER_ID, 0);
|
2018-12-18 19:29:41 -06:00
|
|
|
}
|
|
|
|
|
2019-10-03 19:39:37 -04:00
|
|
|
PrintTradeMessage(TRADE_MSG_STANDBY);
|
2018-12-18 19:29:41 -06:00
|
|
|
ShowBg(0);
|
|
|
|
|
2018-12-31 02:22:21 -06:00
|
|
|
if (!gReceivedRemoteLinkPlayers)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
|
|
|
gLinkType = 0x1122;
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->timer = 0;
|
2018-12-18 19:29:41 -06:00
|
|
|
|
2018-12-31 02:22:21 -06:00
|
|
|
if (gWirelessCommType)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
|
|
|
sub_800B488();
|
|
|
|
OpenLink();
|
|
|
|
sub_8011BA4();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OpenLink();
|
|
|
|
gMain.state++;
|
|
|
|
CreateTask(task00_08081A90, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gMain.state = 4;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->timer++;
|
|
|
|
if (sTradeData->timer > 11)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->timer = 0;
|
2018-12-18 19:29:41 -06:00
|
|
|
gMain.state++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
2019-02-10 20:42:50 -05:00
|
|
|
if (GetLinkPlayerCount_2() >= GetSavedPlayerCount())
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
|
|
|
if (IsLinkMaster())
|
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
if (++sTradeData->timer > 30)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
2019-02-10 20:42:50 -05:00
|
|
|
CheckShouldAdvanceLinkState();
|
2018-12-18 19:29:41 -06:00
|
|
|
gMain.state++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gMain.state++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
2018-12-31 02:22:21 -06:00
|
|
|
if (gReceivedRemoteLinkPlayers == TRUE && IsLinkPlayerDataExchangeComplete() == TRUE)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
|
|
|
sub_8011BD0();
|
|
|
|
CalculatePlayerPartyCount();
|
|
|
|
gMain.state++;
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->timer = 0;
|
2018-12-31 02:22:21 -06:00
|
|
|
if (gWirelessCommType)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
|
|
|
sub_801048C(TRUE);
|
|
|
|
sub_800ADF8();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 5:
|
2018-12-31 02:22:21 -06:00
|
|
|
if (gWirelessCommType)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
|
|
|
if (sub_8010500())
|
|
|
|
{
|
|
|
|
gMain.state++;
|
2019-04-04 17:05:46 -04:00
|
|
|
LoadWirelessStatusIndicatorSpriteGfx();
|
2018-12-18 19:29:41 -06:00
|
|
|
CreateWirelessStatusIndicatorSprite(0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gMain.state++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
if (shedinja_maker_maybe())
|
|
|
|
{
|
|
|
|
sub_807A5B0();
|
|
|
|
gMain.state++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
CalculateEnemyPartyCount();
|
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, 0);
|
|
|
|
SetGpuReg(REG_OFFSET_BLDCNT, 0);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->partyCounts[TRADE_PLAYER] = gPlayerPartyCount;
|
|
|
|
sTradeData->partyCounts[TRADE_PARTNER] = gEnemyPartyCount;
|
2018-12-18 19:29:41 -06:00
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
for (i = 0; i < sTradeData->partyCounts[TRADE_PLAYER]; i++)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
|
|
|
struct Pokemon *mon = &gPlayerParty[i];
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->partySpriteIds[TRADE_PLAYER][i] = CreateMonIcon(GetMonData(mon, MON_DATA_SPECIES2),
|
2018-12-18 19:29:41 -06:00
|
|
|
sub_80D3014,
|
2018-12-31 01:23:27 -06:00
|
|
|
(gTradeMonSpriteCoords[i][0] * 8) + 14,
|
|
|
|
(gTradeMonSpriteCoords[i][1] * 8) - 12,
|
2018-12-18 19:29:41 -06:00
|
|
|
1,
|
|
|
|
GetMonData(mon, MON_DATA_PERSONALITY),
|
|
|
|
TRUE);
|
|
|
|
}
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
for (i = 0; i < sTradeData->partyCounts[TRADE_PARTNER]; i++)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
|
|
|
struct Pokemon *mon = &gEnemyParty[i];
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->partySpriteIds[TRADE_PARTNER][i] = CreateMonIcon(GetMonData(mon, MON_DATA_SPECIES2, NULL),
|
2018-12-18 19:29:41 -06:00
|
|
|
sub_80D3014,
|
2018-12-31 01:23:27 -06:00
|
|
|
(gTradeMonSpriteCoords[i + PARTY_SIZE][0] * 8) + 14,
|
|
|
|
(gTradeMonSpriteCoords[i + PARTY_SIZE][1] * 8) - 12,
|
2018-12-18 19:29:41 -06:00
|
|
|
1,
|
|
|
|
GetMonData(mon, MON_DATA_PERSONALITY),
|
|
|
|
FALSE);
|
|
|
|
}
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 8:
|
2018-12-25 15:03:13 -06:00
|
|
|
LoadHeldItemIcons();
|
2019-10-06 22:58:25 -04:00
|
|
|
DrawHeldItemIconsForTrade(&sTradeData->partyCounts[TRADE_PLAYER], sTradeData->partySpriteIds[TRADE_PLAYER], TRADE_PLAYER);
|
2018-12-18 19:29:41 -06:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 9:
|
2019-10-06 22:58:25 -04:00
|
|
|
DrawHeldItemIconsForTrade(&sTradeData->partyCounts[TRADE_PLAYER], sTradeData->partySpriteIds[TRADE_PLAYER], TRADE_PARTNER);
|
2018-12-18 19:29:41 -06:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 10:
|
2019-10-06 22:58:25 -04:00
|
|
|
DrawTextWindowAndBufferTiles(gSaveBlock2Ptr->playerName, sMessageBoxTileBuffers[0], 0, 0, 3);
|
2018-12-18 19:29:41 -06:00
|
|
|
id = GetMultiplayerId();
|
2019-10-06 22:58:25 -04:00
|
|
|
DrawTextWindowAndBufferTiles(gLinkPlayers[id ^ 1].name, sMessageBoxTileBuffers[3], 0, 0, 3);
|
|
|
|
DrawTextWindowAndBufferTiles(sTradeActionTexts[TRADE_ACTION_TEXT_CANCEL], sMessageBoxTileBuffers[6], 0, 0, 2);
|
|
|
|
DrawTextWindowAndBuffer6Bytes(sTradeActionTexts[TRADE_ACTION_TEXT_CHOOSE_MON], sMessageBoxTileBuffers[8], 24);
|
2018-12-18 19:29:41 -06:00
|
|
|
gMain.state++;
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->timer = 0;
|
2018-12-18 19:29:41 -06:00
|
|
|
break;
|
|
|
|
case 11:
|
2019-10-06 22:58:25 -04:00
|
|
|
if (LoadTradeMenuSpriteSheetsAndPalettes())
|
2018-12-18 19:29:41 -06:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 12:
|
|
|
|
xPos = GetStringCenterAlignXOffset(1, gSaveBlock2Ptr->playerName, 120);
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
temp = gSpriteTemplate_832DCAC;
|
|
|
|
temp.tileTag += i;
|
|
|
|
CreateSprite(&temp, xPos + (i * 32) + 16, 10, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
xPos = GetStringCenterAlignXOffset(1, gLinkPlayers[GetMultiplayerId() ^ 1].name, 120);
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
temp = gSpriteTemplate_832DCAC;
|
|
|
|
temp.tileTag += i + 3;
|
|
|
|
CreateSprite(&temp, xPos + (i * 32) + 136, 10, 1);
|
|
|
|
}
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 13:
|
|
|
|
temp = gSpriteTemplate_832DCAC;
|
|
|
|
temp.tileTag += 6;
|
|
|
|
CreateSprite(&temp, 215, 152, 1);
|
|
|
|
temp = gSpriteTemplate_832DCAC;
|
|
|
|
temp.tileTag += 7;
|
|
|
|
CreateSprite(&temp, 247, 152, 1);
|
|
|
|
|
2018-12-21 12:20:28 -06:00
|
|
|
for (i = 0; i < PARTY_SIZE; i++)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
|
|
|
temp = gSpriteTemplate_832DCAC;
|
|
|
|
temp.tileTag += i + 8;
|
|
|
|
CreateSprite(&temp, (i * 32) + 24, 150, 1);
|
|
|
|
}
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->cursorSpriteIdx = CreateSprite(&gSpriteTemplate_832DC94, gTradeMonSpriteCoords[0][0] * 8 + 32, gTradeMonSpriteCoords[0][1] * 8, 2);
|
|
|
|
sTradeData->cursorPosition = 0;
|
2018-12-18 19:29:41 -06:00
|
|
|
gMain.state++;
|
|
|
|
rbox_fill_rectangle(0);
|
|
|
|
break;
|
|
|
|
case 14:
|
2019-10-06 22:58:25 -04:00
|
|
|
SetTradePartyLiveStatuses(TRADE_PLAYER);
|
2019-10-03 19:39:37 -04:00
|
|
|
PrintPartyNicknamesForTradeMenu(TRADE_PLAYER);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->bg2hofs = 0;
|
|
|
|
sTradeData->bg3hofs = 0;
|
2019-10-06 22:58:25 -04:00
|
|
|
SetTradePartyMonsVisible();
|
2018-12-18 19:29:41 -06:00
|
|
|
gMain.state++;
|
|
|
|
PlayBGM(MUS_P_SCHOOL);
|
|
|
|
break;
|
|
|
|
case 15:
|
2019-10-06 22:58:25 -04:00
|
|
|
SetTradePartyLiveStatuses(TRADE_PARTNER);
|
2019-10-03 19:39:37 -04:00
|
|
|
PrintPartyNicknamesForTradeMenu(TRADE_PARTNER);
|
2018-12-18 19:29:41 -06:00
|
|
|
gMain.state++;
|
2018-12-31 01:23:27 -06:00
|
|
|
// fallthrough
|
|
|
|
case 16:
|
2018-12-18 19:29:41 -06:00
|
|
|
sub_80782B8(0);
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 17:
|
|
|
|
sub_80782B8(1);
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 18:
|
|
|
|
BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, RGB_BLACK);
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 19:
|
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_1D_MAP | DISPCNT_OBJ_ON);
|
|
|
|
sub_80782B8(2);
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 20:
|
2019-10-03 19:39:37 -04:00
|
|
|
GetTradePartyHPBarLevels(TRADE_PLAYER);
|
2018-12-18 19:29:41 -06:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 21:
|
2019-10-03 19:39:37 -04:00
|
|
|
GetTradePartyHPBarLevels(TRADE_PARTNER);
|
|
|
|
SetTradePartyHPBarSprites();
|
2018-12-18 19:29:41 -06:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 22:
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
|
|
|
gMain.callback1 = sub_8078C34;
|
2019-10-06 22:58:25 -04:00
|
|
|
SetMainCallback2(CB2_TradeMenu);
|
2018-12-18 19:29:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
RunTextPrinters();
|
|
|
|
RunTasks();
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
|
|
|
UpdatePaletteFade();
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_8077B74(void)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct SpriteTemplate temp;
|
|
|
|
u8 id;
|
|
|
|
u32 xPos;
|
|
|
|
|
|
|
|
switch (gMain.state)
|
|
|
|
{
|
|
|
|
case 0:
|
2019-10-04 07:42:45 -04:00
|
|
|
InitTradeMenu();
|
2018-12-18 19:29:41 -06:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
gMain.state++;
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->timer = 0;
|
2018-12-18 19:29:41 -06:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
CalculatePlayerPartyCount();
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 5:
|
2018-12-31 02:22:21 -06:00
|
|
|
if (gWirelessCommType)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
2019-04-04 17:05:46 -04:00
|
|
|
LoadWirelessStatusIndicatorSpriteGfx();
|
2018-12-18 19:29:41 -06:00
|
|
|
CreateWirelessStatusIndicatorSprite(0, 0);
|
|
|
|
}
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
CalculateEnemyPartyCount();
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->partyCounts[TRADE_PLAYER] = gPlayerPartyCount;
|
|
|
|
sTradeData->partyCounts[TRADE_PARTNER] = gEnemyPartyCount;
|
2018-12-18 19:29:41 -06:00
|
|
|
ClearWindowTilemap(0);
|
2019-10-03 19:39:37 -04:00
|
|
|
PrintPartyNicknamesForTradeMenu(TRADE_PLAYER);
|
|
|
|
PrintPartyNicknamesForTradeMenu(TRADE_PARTNER);
|
2018-12-18 19:29:41 -06:00
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
for (i = 0; i < sTradeData->partyCounts[TRADE_PLAYER]; i++)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
|
|
|
struct Pokemon *mon = &gPlayerParty[i];
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->partySpriteIds[TRADE_PLAYER][i] = CreateMonIcon(GetMonData(mon, MON_DATA_SPECIES2, NULL),
|
2018-12-18 19:29:41 -06:00
|
|
|
sub_80D3014,
|
2018-12-31 01:23:27 -06:00
|
|
|
(gTradeMonSpriteCoords[i][0] * 8) + 14,
|
|
|
|
(gTradeMonSpriteCoords[i][1] * 8) - 12,
|
2018-12-18 19:29:41 -06:00
|
|
|
1,
|
|
|
|
GetMonData(mon, MON_DATA_PERSONALITY),
|
|
|
|
TRUE);
|
|
|
|
}
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
for (i = 0; i < sTradeData->partyCounts[TRADE_PARTNER]; i++)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
|
|
|
struct Pokemon *mon = &gEnemyParty[i];
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->partySpriteIds[TRADE_PARTNER][i] = CreateMonIcon(GetMonData(mon, MON_DATA_SPECIES2, NULL),
|
2018-12-18 19:29:41 -06:00
|
|
|
sub_80D3014,
|
2018-12-31 01:23:27 -06:00
|
|
|
(gTradeMonSpriteCoords[i + PARTY_SIZE][0] * 8) + 14,
|
|
|
|
(gTradeMonSpriteCoords[i + PARTY_SIZE][1] * 8) - 12,
|
2018-12-18 19:29:41 -06:00
|
|
|
1,
|
|
|
|
GetMonData(mon, MON_DATA_PERSONALITY),
|
|
|
|
FALSE);
|
|
|
|
}
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 8:
|
2018-12-25 15:03:13 -06:00
|
|
|
LoadHeldItemIcons();
|
2019-10-06 22:58:25 -04:00
|
|
|
DrawHeldItemIconsForTrade(&sTradeData->partyCounts[TRADE_PLAYER], sTradeData->partySpriteIds[TRADE_PLAYER], TRADE_PLAYER);
|
2018-12-18 19:29:41 -06:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 9:
|
2019-10-06 22:58:25 -04:00
|
|
|
DrawHeldItemIconsForTrade(&sTradeData->partyCounts[TRADE_PLAYER], sTradeData->partySpriteIds[TRADE_PLAYER], TRADE_PARTNER);
|
2018-12-18 19:29:41 -06:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 10:
|
2019-10-06 22:58:25 -04:00
|
|
|
DrawTextWindowAndBufferTiles(gSaveBlock2Ptr->playerName, sMessageBoxTileBuffers[0], 0, 0, 3);
|
2018-12-18 19:29:41 -06:00
|
|
|
id = GetMultiplayerId();
|
2019-10-06 22:58:25 -04:00
|
|
|
DrawTextWindowAndBufferTiles(gLinkPlayers[id ^ 1].name, sMessageBoxTileBuffers[3], 0, 0, 3);
|
|
|
|
DrawTextWindowAndBufferTiles(sTradeActionTexts[TRADE_ACTION_TEXT_CANCEL], sMessageBoxTileBuffers[6], 0, 0, 2);
|
|
|
|
DrawTextWindowAndBuffer6Bytes(sTradeActionTexts[TRADE_ACTION_TEXT_CHOOSE_MON], sMessageBoxTileBuffers[8], 24);
|
2018-12-18 19:29:41 -06:00
|
|
|
gMain.state++;
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->timer = 0;
|
2018-12-18 19:29:41 -06:00
|
|
|
break;
|
|
|
|
case 11:
|
2019-10-06 22:58:25 -04:00
|
|
|
if (LoadTradeMenuSpriteSheetsAndPalettes())
|
2018-12-18 19:29:41 -06:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 12:
|
|
|
|
xPos = GetStringCenterAlignXOffset(1, gSaveBlock2Ptr->playerName, 120);
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
temp = gSpriteTemplate_832DCAC;
|
|
|
|
temp.tileTag += i;
|
|
|
|
CreateSprite(&temp, xPos + (i * 32) + 16, 10, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
xPos = GetStringCenterAlignXOffset(1, gLinkPlayers[GetMultiplayerId() ^ 1].name, 120);
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
temp = gSpriteTemplate_832DCAC;
|
|
|
|
temp.tileTag += i + 3;
|
|
|
|
CreateSprite(&temp, xPos + (i * 32) + 136, 10, 1);
|
|
|
|
}
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 13:
|
|
|
|
temp = gSpriteTemplate_832DCAC;
|
|
|
|
temp.tileTag += 6;
|
|
|
|
CreateSprite(&temp, 215, 152, 1);
|
|
|
|
temp = gSpriteTemplate_832DCAC;
|
|
|
|
temp.tileTag += 7;
|
|
|
|
CreateSprite(&temp, 247, 152, 1);
|
|
|
|
|
|
|
|
for (i = 0; i < PARTY_SIZE; i++)
|
|
|
|
{
|
|
|
|
temp = gSpriteTemplate_832DCAC;
|
|
|
|
temp.tileTag += i + 8;
|
|
|
|
CreateSprite(&temp, (i * 32) + 24, 150, 1);
|
|
|
|
}
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
if (sTradeData->cursorPosition < PARTY_SIZE)
|
|
|
|
sTradeData->cursorPosition = gLastViewedMonIndex;
|
2018-12-18 19:29:41 -06:00
|
|
|
else
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->cursorPosition = gLastViewedMonIndex + PARTY_SIZE;
|
2018-12-18 19:29:41 -06:00
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->cursorSpriteIdx = CreateSprite(&gSpriteTemplate_832DC94, gTradeMonSpriteCoords[sTradeData->cursorPosition][0] * 8 + 32, gTradeMonSpriteCoords[sTradeData->cursorPosition][1] * 8, 2);
|
2018-12-18 19:29:41 -06:00
|
|
|
gMain.state = 16;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
sub_80782B8(0);
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 17:
|
|
|
|
sub_80782B8(1);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->bg2hofs = 0;
|
|
|
|
sTradeData->bg3hofs = 0;
|
2019-10-06 22:58:25 -04:00
|
|
|
SetTradePartyMonsVisible();
|
2018-12-18 19:29:41 -06:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 18:
|
|
|
|
gPaletteFade.bufferTransferDisabled = FALSE;
|
|
|
|
BlendPalettes(0xFFFFFFFF, 16, RGB_BLACK);
|
|
|
|
BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, RGB_BLACK);
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 19:
|
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_1D_MAP | DISPCNT_OBJ_ON);
|
|
|
|
sub_80782B8(2);
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 20:
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 21:
|
2019-10-03 19:39:37 -04:00
|
|
|
SetTradePartyHPBarSprites();
|
2018-12-18 19:29:41 -06:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 22:
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
SetMainCallback2(CB2_TradeMenu);
|
2018-12-18 19:29:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
RunTasks();
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
|
|
|
UpdatePaletteFade();
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807811C(void)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
|
|
|
LoadOam();
|
|
|
|
ProcessSpriteCopyRequests();
|
|
|
|
TransferPlttBuffer();
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_8078130(void)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
if (++sTradeData->timer > 15)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
|
|
|
BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK);
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->tradeMenuFunc = 10;
|
2018-12-18 19:29:41 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807816C(void)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
gSelectedTradeMonPositions[TRADE_PLAYER] = sTradeData->cursorPosition;
|
|
|
|
gSelectedTradeMonPositions[TRADE_PARTNER] = sTradeData->partnerCursorPosition;
|
2018-12-18 19:29:41 -06:00
|
|
|
|
2018-12-31 02:22:21 -06:00
|
|
|
if (gWirelessCommType)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->tradeMenuFunc = 16;
|
2018-12-18 19:29:41 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sub_800ABF4(32);
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->tradeMenuFunc = 13;
|
2018-12-18 19:29:41 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_80781C8(void)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
|
|
|
gMain.savedCallback = sub_80773AC;
|
|
|
|
|
2019-10-05 10:41:37 -04:00
|
|
|
// Wireless Link Trade
|
2018-12-31 02:22:21 -06:00
|
|
|
if (gWirelessCommType)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
|
|
|
if (sub_8010500())
|
|
|
|
{
|
2019-10-05 10:41:37 -04:00
|
|
|
Free(sMessageBoxAllocBuffer);
|
2018-12-18 19:29:41 -06:00
|
|
|
FreeAllWindowBuffers();
|
2019-10-04 07:42:45 -04:00
|
|
|
Free(sTradeData);
|
2018-12-18 19:29:41 -06:00
|
|
|
gMain.callback1 = NULL;
|
2019-03-31 18:59:52 -04:00
|
|
|
DestroyWirelessStatusIndicatorSprite();
|
2019-10-05 10:41:37 -04:00
|
|
|
SetMainCallback2(CB2_LinkTrade);
|
2018-12-18 19:29:41 -06:00
|
|
|
}
|
|
|
|
}
|
2019-10-05 10:41:37 -04:00
|
|
|
// Cable Link Trade
|
2018-12-18 19:29:41 -06:00
|
|
|
else
|
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
if (!gReceivedRemoteLinkPlayers)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
2019-10-05 10:41:37 -04:00
|
|
|
Free(sMessageBoxAllocBuffer);
|
2018-12-18 19:29:41 -06:00
|
|
|
FreeAllWindowBuffers();
|
2019-10-04 07:42:45 -04:00
|
|
|
Free(sTradeData);
|
2018-12-18 19:29:41 -06:00
|
|
|
gMain.callback1 = NULL;
|
2019-10-05 10:41:37 -04:00
|
|
|
SetMainCallback2(CB2_LinkTrade);
|
2018-12-18 19:29:41 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
static void CB2_TradeMenu(void)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
sub_80795AC(); //func switch
|
|
|
|
DoQueuedActions();
|
2019-10-04 07:42:45 -04:00
|
|
|
DrawTradeMenuParty(TRADE_PLAYER);
|
|
|
|
DrawTradeMenuParty(TRADE_PARTNER);
|
2018-12-25 15:14:15 +01:00
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
SetGpuReg(REG_OFFSET_BG2HOFS, sTradeData->bg2hofs++);
|
|
|
|
SetGpuReg(REG_OFFSET_BG3HOFS, sTradeData->bg3hofs--);
|
2018-12-18 19:29:41 -06:00
|
|
|
|
|
|
|
RunTextPrintersAndIsPrinter0Active();
|
|
|
|
RunTasks();
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
|
|
|
UpdatePaletteFade();
|
|
|
|
}
|
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
static void sub_80782B8(u8 state)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
switch (state)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
|
|
|
case 0:
|
2019-10-03 01:16:22 -04:00
|
|
|
LoadPalette(gTradeMenu_Pal, 0, 0x60);
|
|
|
|
LoadBgTiles(1, gTradeMenu_Gfx, 0x1280, 0);
|
2018-12-18 19:29:41 -06:00
|
|
|
CopyToBgTilemapBufferRect_ChangePalette(1, gUnknown_08DDCF04, 0, 0, 32, 20, 0);
|
|
|
|
LoadBgTilemap(2, gTradeStripesBG2Tilemap, 0x800, 0);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
LoadBgTilemap(3, gTradeStripesBG3Tilemap, 0x800, 0);
|
2019-10-03 01:16:22 -04:00
|
|
|
sub_8079E44(TRADE_PLAYER);
|
|
|
|
sub_8079E44(TRADE_PARTNER);
|
2018-12-18 19:29:41 -06: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
static void SetTradePartyMonsVisible(void)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2018-12-21 12:20:28 -06:00
|
|
|
for (i = 0; i < PARTY_SIZE; i++)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
if (i < sTradeData->partyCounts[TRADE_PLAYER])
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
gSprites[sTradeData->partySpriteIds[TRADE_PLAYER][i]].invisible = FALSE;
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->monPresent[i] = TRUE;
|
2018-12-18 19:29:41 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->monPresent[i] = FALSE;
|
2018-12-18 19:29:41 -06:00
|
|
|
}
|
2018-12-25 15:14:15 +01:00
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
if (i < sTradeData->partyCounts[TRADE_PARTNER])
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
gSprites[sTradeData->partySpriteIds[TRADE_PARTNER][i]].invisible = FALSE;
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->monPresent[i + PARTY_SIZE] = TRUE;
|
2018-12-18 19:29:41 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->monPresent[i + PARTY_SIZE] = FALSE;
|
2018-12-18 19:29:41 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->neverRead_44 = 1;
|
2018-12-18 19:29:41 -06:00
|
|
|
}
|
|
|
|
|
2018-12-31 02:22:21 -06:00
|
|
|
// why not just use memcpy?
|
|
|
|
static void Trade_Memcpy(void *dataDest, const void *dataSrc, u32 count)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
u8 *dest = dataDest;
|
|
|
|
const u8 *src = dataSrc;
|
2018-12-18 19:29:41 -06:00
|
|
|
u32 i;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
dest[i] = src[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static bool8 shedinja_maker_maybe(void)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
|
|
|
u8 id = GetMultiplayerId();
|
|
|
|
int i;
|
|
|
|
struct Pokemon *mon;
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
switch (sTradeData->unk_69)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
|
|
|
case 0:
|
2018-12-31 02:22:21 -06:00
|
|
|
Trade_Memcpy(gBlockSendBuffer, &gPlayerParty[0], 2 * sizeof(struct Pokemon));
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->unk_69++;
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->timer = 0;
|
2018-12-18 19:29:41 -06:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (sub_80771BC())
|
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
if (_GetBlockReceivedStatus() == 0)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->unk_69++;
|
2018-12-18 19:29:41 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
TradeResetReceivedFlags();
|
|
|
|
sTradeData->unk_69++;
|
2018-12-18 19:29:41 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (id == 0)
|
|
|
|
{
|
|
|
|
sub_80771AC(1);
|
|
|
|
}
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->unk_69++;
|
2018-12-18 19:29:41 -06:00
|
|
|
break;
|
|
|
|
case 4:
|
2018-12-31 02:22:21 -06:00
|
|
|
if (_GetBlockReceivedStatus() == 3)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
Trade_Memcpy(&gEnemyParty[0], gBlockRecvBuffer[id ^ 1], 2 * sizeof(struct Pokemon));
|
2019-10-04 07:42:45 -04:00
|
|
|
TradeResetReceivedFlags();
|
|
|
|
sTradeData->unk_69++;
|
2018-12-18 19:29:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 5:
|
2018-12-31 02:22:21 -06:00
|
|
|
Trade_Memcpy(gBlockSendBuffer, &gPlayerParty[2], 2 * sizeof(struct Pokemon));
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->unk_69++;
|
2018-12-18 19:29:41 -06:00
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
if (id == 0)
|
|
|
|
{
|
|
|
|
sub_80771AC(1);
|
|
|
|
}
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->unk_69++;
|
2018-12-18 19:29:41 -06:00
|
|
|
break;
|
|
|
|
case 8:
|
2018-12-31 02:22:21 -06:00
|
|
|
if (_GetBlockReceivedStatus() == 3)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
Trade_Memcpy(&gEnemyParty[2], gBlockRecvBuffer[id ^ 1], 200);
|
2019-10-04 07:42:45 -04:00
|
|
|
TradeResetReceivedFlags();
|
|
|
|
sTradeData->unk_69++;
|
2018-12-18 19:29:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 9:
|
2018-12-31 02:22:21 -06:00
|
|
|
Trade_Memcpy(gBlockSendBuffer, &gPlayerParty[4], 200);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->unk_69++;
|
2018-12-18 19:29:41 -06:00
|
|
|
break;
|
|
|
|
case 11:
|
|
|
|
if (id == 0)
|
|
|
|
{
|
|
|
|
sub_80771AC(1);
|
|
|
|
}
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->unk_69++;
|
2018-12-18 19:29:41 -06:00
|
|
|
break;
|
|
|
|
case 12:
|
2018-12-31 02:22:21 -06:00
|
|
|
if (_GetBlockReceivedStatus() == 3)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
Trade_Memcpy(&gEnemyParty[4], gBlockRecvBuffer[id ^ 1], 200);
|
2019-10-04 07:42:45 -04:00
|
|
|
TradeResetReceivedFlags();
|
|
|
|
sTradeData->unk_69++;
|
2018-12-18 19:29:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 13:
|
2018-12-31 02:22:21 -06:00
|
|
|
Trade_Memcpy(gBlockSendBuffer, gSaveBlock1Ptr->mail, 220);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->unk_69++;
|
2018-12-18 19:29:41 -06:00
|
|
|
break;
|
|
|
|
case 15:
|
|
|
|
if (id == 0)
|
|
|
|
{
|
|
|
|
sub_80771AC(3);
|
|
|
|
}
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->unk_69++;
|
2018-12-18 19:29:41 -06:00
|
|
|
break;
|
|
|
|
case 16:
|
2018-12-31 02:22:21 -06:00
|
|
|
if (_GetBlockReceivedStatus() == 3)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
Trade_Memcpy(gTradeMail, gBlockRecvBuffer[id ^ 1], 216);
|
|
|
|
TradeResetReceivedFlags();
|
|
|
|
sTradeData->unk_69++;
|
2018-12-18 19:29:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 17:
|
2019-10-06 22:58:25 -04:00
|
|
|
Trade_Memcpy(gBlockSendBuffer, gSaveBlock1Ptr->giftRibbons, ARRAY_COUNT(sTradeData->giftRibbons));
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->unk_69++;
|
2018-12-18 19:29:41 -06:00
|
|
|
break;
|
|
|
|
case 19:
|
|
|
|
if (id == 0)
|
|
|
|
{
|
|
|
|
sub_80771AC(4);
|
|
|
|
}
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->unk_69++;
|
2018-12-18 19:29:41 -06:00
|
|
|
break;
|
|
|
|
case 20:
|
2018-12-31 02:22:21 -06:00
|
|
|
if (_GetBlockReceivedStatus() == 3)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
Trade_Memcpy(sTradeData->giftRibbons, gBlockRecvBuffer[id ^ 1], ARRAY_COUNT(sTradeData->giftRibbons));
|
2019-10-04 07:42:45 -04:00
|
|
|
TradeResetReceivedFlags();
|
|
|
|
sTradeData->unk_69++;
|
2018-12-18 19:29:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 21:
|
2018-12-21 12:20:28 -06:00
|
|
|
for (i = 0, mon = gEnemyParty; i < PARTY_SIZE; mon++, i++)
|
2018-12-18 19:29:41 -06: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);
|
|
|
|
|
2019-10-03 19:39:37 -04:00
|
|
|
if (!StringCompareWithoutExtCtrlCodes(name, sJPText_Shedinja))
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
|
|
|
SetMonData(mon, MON_DATA_NICKNAME, gSpeciesNames[SPECIES_SHEDINJA]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
case 2:
|
|
|
|
case 6:
|
|
|
|
case 10:
|
|
|
|
case 14:
|
|
|
|
case 18:
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->timer++;
|
|
|
|
if (sTradeData->timer > 10)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->timer = 0;
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->unk_69++;
|
2018-12-18 19:29:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
static void PrintAndBufferIsThisTradeOkay(void)
|
2018-12-18 19:29:41 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
DrawTextWindowAndBuffer6Bytes(gText_IsThisTradeOkay, (void *)(OBJ_VRAM0 + (sTradeData->unk_72 * 32)), 24);
|
2018-12-18 19:29:41 -06:00
|
|
|
}
|
2018-12-21 12:20:28 -06:00
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
static void UpdateLinkFlags(u8 a0, u8 a1)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
|
|
|
if (a1 & 1)
|
|
|
|
{
|
|
|
|
switch (gBlockRecvBuffer[0][0])
|
|
|
|
{
|
|
|
|
case 0xEEAA:
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->playerLinkFlagChoseAction = WANTS_TO_CANCEL;
|
2018-12-21 12:20:28 -06:00
|
|
|
break;
|
|
|
|
case 0xAABB:
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->playerLinkFlagChoseAction = WANTS_TO_TRADE;
|
2018-12-21 12:20:28 -06:00
|
|
|
break;
|
|
|
|
case 0xBBBB:
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->playerLinkFlagChoseMon = CHOSE_VALID_MON;
|
2018-12-21 12:20:28 -06:00
|
|
|
break;
|
|
|
|
case 0xBBCC:
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->playerLinkFlagChoseMon = CHOSE_INVALID_MON;
|
2018-12-21 12:20:28 -06:00
|
|
|
break;
|
|
|
|
}
|
2019-10-04 07:42:45 -04:00
|
|
|
TradeResetReceivedFlag(TRADE_PLAYER);
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (a1 & 2)
|
|
|
|
{
|
|
|
|
switch (gBlockRecvBuffer[1][0])
|
|
|
|
{
|
|
|
|
case 0xEEAA:
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->partnerLinkFlagChoseAction = WANTS_TO_CANCEL;
|
2018-12-21 12:20:28 -06:00
|
|
|
break;
|
|
|
|
case 0xAABB:
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->partnerCursorPosition = gBlockRecvBuffer[1][1] + 6;
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->partnerLinkFlagChoseAction = WANTS_TO_TRADE;
|
2018-12-21 12:20:28 -06:00
|
|
|
break;
|
|
|
|
case 0xBBBB:
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->partnerLinkFlagChoseMon = CHOSE_VALID_MON;
|
2018-12-21 12:20:28 -06:00
|
|
|
break;
|
|
|
|
case 0xBBCC:
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->partnerLinkFlagChoseMon = CHOSE_INVALID_MON;
|
2018-12-21 12:20:28 -06:00
|
|
|
break;
|
|
|
|
}
|
2019-10-04 07:42:45 -04:00
|
|
|
TradeResetReceivedFlag(TRADE_PARTNER);
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_8078900(u8 a0, u8 a1)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
|
|
|
if (a1 & 1)
|
|
|
|
{
|
|
|
|
switch (gBlockRecvBuffer[0][0])
|
|
|
|
{
|
|
|
|
case 0xEEBB:
|
|
|
|
BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK);
|
2019-10-03 19:39:37 -04:00
|
|
|
PrintTradeMessage(TRADE_MSG_WAITING_FOR_FRIEND);
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->tradeMenuFunc = 11;
|
2018-12-21 12:20:28 -06:00
|
|
|
break;
|
|
|
|
case 0xEECC:
|
2019-10-03 19:39:37 -04:00
|
|
|
PrintTradeMessage(TRADE_MSG_FRIEND_WANTS_TO_TRADE);
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->tradeMenuFunc = 8;
|
2018-12-21 12:20:28 -06:00
|
|
|
break;
|
|
|
|
case 0xDDDD:
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->partnerCursorPosition = gBlockRecvBuffer[0][1] + 6;
|
2018-12-21 12:20:28 -06:00
|
|
|
rbox_fill_rectangle(0);
|
2019-10-04 07:42:45 -04:00
|
|
|
SetSelectedMon(sTradeData->cursorPosition);
|
|
|
|
SetSelectedMon(sTradeData->partnerCursorPosition);
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->tradeMenuFunc = 7;
|
2018-12-21 12:20:28 -06:00
|
|
|
break;
|
|
|
|
case 0xCCDD:
|
|
|
|
BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK);
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->tradeMenuFunc = 10;
|
2018-12-21 12:20:28 -06:00
|
|
|
break;
|
|
|
|
case 0xDDEE:
|
2019-10-03 19:39:37 -04:00
|
|
|
PrintTradeMessage(TRADE_MSG_CANCELED);
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->tradeMenuFunc = 8;
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
2019-10-04 07:42:45 -04:00
|
|
|
TradeResetReceivedFlag(TRADE_PLAYER);
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (a1 & 2)
|
2019-10-04 07:42:45 -04:00
|
|
|
TradeResetReceivedFlag(TRADE_PARTNER);
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
// TODO: SetLinkData with additional steps
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_80789FC(void)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
if (sTradeData->playerLinkFlagChoseAction && sTradeData->partnerLinkFlagChoseAction)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
if (sTradeData->playerLinkFlagChoseAction == WANTS_TO_TRADE
|
|
|
|
&& sTradeData->partnerLinkFlagChoseAction == WANTS_TO_TRADE)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->tradeMenuFunc = 6;
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->linkData[0] = 0xDDDD;
|
|
|
|
sTradeData->linkData[1] = sTradeData->cursorPosition;
|
2019-10-06 22:58:25 -04:00
|
|
|
QueueAction(QUEUE_DELAY_DATA, QUEUE_SEND_DATA);
|
|
|
|
sTradeData->playerLinkFlagChoseAction = sTradeData->partnerLinkFlagChoseAction = 0;
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
2019-10-06 22:58:25 -04:00
|
|
|
else if (sTradeData->playerLinkFlagChoseAction == WANTS_TO_TRADE
|
|
|
|
&& sTradeData->partnerLinkFlagChoseAction == WANTS_TO_CANCEL)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-03 19:39:37 -04:00
|
|
|
PrintTradeMessage(TRADE_MSG_CANCELED);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->linkData[0] = 0xEECC;
|
|
|
|
sTradeData->linkData[1] = 0;
|
2019-10-06 22:58:25 -04:00
|
|
|
QueueAction(QUEUE_DELAY_DATA, QUEUE_SEND_DATA);
|
|
|
|
sTradeData->playerLinkFlagChoseMon = sTradeData->partnerLinkFlagChoseMon = 0;
|
|
|
|
sTradeData->playerLinkFlagChoseAction = sTradeData->partnerLinkFlagChoseAction = 0;
|
|
|
|
sTradeData->tradeMenuFunc = 8;
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
2019-10-06 22:58:25 -04:00
|
|
|
else if (sTradeData->playerLinkFlagChoseAction == WANTS_TO_CANCEL
|
|
|
|
&& sTradeData->partnerLinkFlagChoseAction == WANTS_TO_TRADE)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-03 19:39:37 -04:00
|
|
|
PrintTradeMessage(TRADE_MSG_FRIEND_WANTS_TO_TRADE);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->linkData[0] = 0xDDEE;
|
|
|
|
sTradeData->linkData[1] = 0;
|
2019-10-06 22:58:25 -04:00
|
|
|
QueueAction(QUEUE_DELAY_DATA, QUEUE_SEND_DATA);
|
|
|
|
sTradeData->playerLinkFlagChoseMon = sTradeData->partnerLinkFlagChoseMon = 0;
|
|
|
|
sTradeData->playerLinkFlagChoseAction = sTradeData->partnerLinkFlagChoseAction = 0;
|
|
|
|
sTradeData->tradeMenuFunc = 8;
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
2019-10-06 22:58:25 -04:00
|
|
|
else if (sTradeData->playerLinkFlagChoseAction == WANTS_TO_CANCEL
|
|
|
|
&& sTradeData->partnerLinkFlagChoseAction == WANTS_TO_CANCEL)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->linkData[0] = 0xEEBB;
|
|
|
|
sTradeData->linkData[1] = 0;
|
2019-10-06 22:58:25 -04:00
|
|
|
QueueAction(QUEUE_DELAY_DATA, QUEUE_SEND_DATA);
|
2018-12-21 12:20:28 -06:00
|
|
|
BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK);
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->playerLinkFlagChoseAction = sTradeData->partnerLinkFlagChoseAction = 0;
|
|
|
|
sTradeData->tradeMenuFunc = 11;
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
if (sTradeData->playerLinkFlagChoseMon && sTradeData->partnerLinkFlagChoseMon)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
if (sTradeData->playerLinkFlagChoseMon == CHOSE_VALID_MON
|
|
|
|
&& sTradeData->partnerLinkFlagChoseMon == CHOSE_VALID_MON)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->linkData[0] = 0xCCDD;
|
|
|
|
sTradeData->linkData[1] = 0;
|
2019-10-06 22:58:25 -04:00
|
|
|
QueueAction(QUEUE_DELAY_DATA, QUEUE_SEND_DATA);
|
|
|
|
sTradeData->playerLinkFlagChoseMon = 0;
|
|
|
|
sTradeData->partnerLinkFlagChoseMon = 0;
|
|
|
|
sTradeData->tradeMenuFunc = 9;
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
if (sTradeData->playerLinkFlagChoseMon == CHOSE_INVALID_MON
|
|
|
|
|| sTradeData->partnerLinkFlagChoseMon == CHOSE_INVALID_MON)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-03 19:39:37 -04:00
|
|
|
PrintTradeMessage(TRADE_MSG_CANCELED);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->linkData[0] = 0xDDEE;
|
|
|
|
sTradeData->linkData[1] = 0;
|
2019-10-06 22:58:25 -04:00
|
|
|
QueueAction(QUEUE_DELAY_DATA, QUEUE_SEND_DATA);
|
|
|
|
sTradeData->playerLinkFlagChoseMon = 0;
|
|
|
|
sTradeData->partnerLinkFlagChoseMon = 0;
|
|
|
|
sTradeData->tradeMenuFunc = 8;
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
static void _SetLinkData(u16 *linkData, u16 linkCmd, u16 cursorPosition)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
linkData[0] = linkCmd;
|
2019-10-03 19:39:37 -04:00
|
|
|
linkData[1] = cursorPosition;
|
2019-10-06 22:58:25 -04:00
|
|
|
QueueAction(QUEUE_DELAY_DATA, QUEUE_SEND_DATA);
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
static void SetLinkData(u16 linkCmd, u16 cursorPosition)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
_SetLinkData(sTradeData->linkData, linkCmd, cursorPosition);
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_8078C34(void)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
u8 mpId = GetMultiplayerId();
|
|
|
|
u8 status;
|
2018-12-21 12:20:28 -06:00
|
|
|
|
2018-12-31 02:22:21 -06:00
|
|
|
if ((status = _GetBlockReceivedStatus()))
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
if (mpId == 0)
|
2019-10-06 22:58:25 -04:00
|
|
|
UpdateLinkFlags(mpId, status);
|
2018-12-21 12:20:28 -06:00
|
|
|
else
|
2018-12-31 02:22:21 -06:00
|
|
|
sub_8078900(mpId, status);
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
|
2018-12-31 02:22:21 -06:00
|
|
|
if (mpId == 0)
|
2018-12-21 12:20:28 -06:00
|
|
|
sub_80789FC();
|
|
|
|
}
|
|
|
|
|
2019-10-05 10:41:37 -04:00
|
|
|
static u8 GetNewTradeMenuPosition(u8 oldPosition, u8 direction)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
|
|
|
int i;
|
2018-12-31 02:22:21 -06:00
|
|
|
u8 newPosition = 0;
|
2018-12-21 12:20:28 -06:00
|
|
|
|
|
|
|
for (i = 0; i < PARTY_SIZE; i++)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
if (sTradeData->monPresent[gTradeNextSelectedMonTable[oldPosition][direction][i]] == TRUE)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
newPosition = gTradeNextSelectedMonTable[oldPosition][direction][i];
|
2018-12-21 12:20:28 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 02:22:21 -06:00
|
|
|
return newPosition;
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
|
2019-10-03 19:39:37 -04:00
|
|
|
static void TradeMenuMoveCursor(u8 *cursorPosition, u8 direction)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-05 10:41:37 -04:00
|
|
|
u8 newPosition = GetNewTradeMenuPosition(*cursorPosition, direction);
|
2018-12-21 12:20:28 -06:00
|
|
|
|
2019-10-05 10:41:37 -04:00
|
|
|
if (newPosition == (PARTY_SIZE * 2)) // CANCEL
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
StartSpriteAnim(&gSprites[sTradeData->cursorSpriteIdx], 1);
|
|
|
|
gSprites[sTradeData->cursorSpriteIdx].pos1.x = 224;
|
|
|
|
gSprites[sTradeData->cursorSpriteIdx].pos1.y = 160;
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
StartSpriteAnim(&gSprites[sTradeData->cursorSpriteIdx], 0);
|
|
|
|
gSprites[sTradeData->cursorSpriteIdx].pos1.x = gTradeMonSpriteCoords[newPosition][0] * 8 + 32;
|
|
|
|
gSprites[sTradeData->cursorSpriteIdx].pos1.y = gTradeMonSpriteCoords[newPosition][1] * 8;
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
|
2019-10-03 19:39:37 -04:00
|
|
|
if (*cursorPosition != newPosition)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
|
|
|
PlaySE(SE_SELECT);
|
|
|
|
}
|
|
|
|
|
2019-10-03 19:39:37 -04:00
|
|
|
*cursorPosition = newPosition;
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_8078D78(void)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-03 19:39:37 -04:00
|
|
|
PrintTradeMessage(TRADE_MSG_STANDBY);
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->tradeMenuFunc = 100;
|
2018-12-21 12:20:28 -06:00
|
|
|
|
|
|
|
if (GetMultiplayerId() == 1)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
SetLinkData(0xAABB, sTradeData->cursorPosition);
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->playerLinkFlagChoseAction = WANTS_TO_TRADE;
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-05 10:41:37 -04:00
|
|
|
static void TradeMenuProcessInput(void)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
|
|
|
if (gMain.newAndRepeatedKeys & DPAD_UP)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
TradeMenuMoveCursor(&sTradeData->cursorPosition, 0);
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
else if (gMain.newAndRepeatedKeys & DPAD_DOWN)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
TradeMenuMoveCursor(&sTradeData->cursorPosition, 1);
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
else if (gMain.newAndRepeatedKeys & DPAD_LEFT)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
TradeMenuMoveCursor(&sTradeData->cursorPosition, 2);
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
else if (gMain.newAndRepeatedKeys & DPAD_RIGHT)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
TradeMenuMoveCursor(&sTradeData->cursorPosition, 3);
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (gMain.newKeys & A_BUTTON)
|
|
|
|
{
|
|
|
|
PlaySE(SE_SELECT);
|
|
|
|
|
2019-10-03 19:39:37 -04:00
|
|
|
// Cursor is in player's party
|
2019-10-04 07:42:45 -04:00
|
|
|
if (sTradeData->cursorPosition < PARTY_SIZE)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-03-31 18:59:52 -04:00
|
|
|
DrawTextBorderOuter(1, 1, 14);
|
2019-03-02 17:25:39 -05:00
|
|
|
FillWindowPixelBuffer(1, PIXEL_FILL(1));
|
2019-10-03 19:39:37 -04:00
|
|
|
PrintMenuTable(1, ARRAY_COUNT(sSelectTradeMonActions), sSelectTradeMonActions);
|
2018-12-21 12:20:28 -06:00
|
|
|
InitMenuInUpperLeftCornerPlaySoundWhenAPressed(1, 2, 0);
|
|
|
|
PutWindowTilemap(1);
|
|
|
|
CopyWindowToVram(1, 3);
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->tradeMenuFunc = 1;
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
2019-10-03 19:39:37 -04:00
|
|
|
// Cursor is in partner's party
|
2019-10-04 07:42:45 -04:00
|
|
|
else if (sTradeData->cursorPosition < PARTY_SIZE * 2)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
|
|
|
BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK);
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->tradeMenuFunc = 2;
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
2019-10-03 19:39:37 -04:00
|
|
|
// Cursor is on Cancel
|
2019-10-04 07:42:45 -04:00
|
|
|
else if (sTradeData->cursorPosition == PARTY_SIZE * 2)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-03 19:39:37 -04:00
|
|
|
CreateYesNoMenu(&sTradeYesNoWindowTemplate, 1, 14, 0);
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->tradeMenuFunc = 4;
|
|
|
|
DrawTextWindowAndBuffer6Bytes(sTradeActionTexts[TRADE_ACTION_TEXT_CANCEL_TRADE], (void *)(OBJ_VRAM0 + sTradeData->unk_72 * 32), 24);
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-05 10:41:37 -04:00
|
|
|
static void ReturnToTradeMenu(void)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
|
|
|
sub_8079F74();
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->tradeMenuFunc = 0;
|
2019-10-04 07:42:45 -04:00
|
|
|
gSprites[sTradeData->cursorSpriteIdx].invisible = FALSE;
|
2019-10-06 22:58:25 -04:00
|
|
|
DrawTextWindowAndBuffer6Bytes(sTradeActionTexts[TRADE_ACTION_TEXT_CHOOSE_MON], (void *)(OBJ_VRAM0 + sTradeData->unk_72 * 32), 24);
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
|
2019-10-03 19:39:37 -04:00
|
|
|
static void TradeMenuProcessInput_SelectedMon(void)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
|
|
|
switch (Menu_ProcessInputNoWrap())
|
|
|
|
{
|
|
|
|
case MENU_B_PRESSED:
|
|
|
|
PlaySE(SE_SELECT);
|
2019-10-05 10:41:37 -04:00
|
|
|
ReturnToTradeMenu();
|
2018-12-21 12:20:28 -06:00
|
|
|
break;
|
|
|
|
case MENU_NOTHING_CHOSEN:
|
|
|
|
break;
|
2019-10-03 19:39:37 -04:00
|
|
|
case MENU_ACTION_SUMMARY:
|
2018-12-21 12:20:28 -06:00
|
|
|
BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK);
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->tradeMenuFunc = 2;
|
2018-12-21 12:20:28 -06:00
|
|
|
break;
|
2019-10-03 19:39:37 -04:00
|
|
|
case MENU_ACTION_TRADE:
|
2019-10-06 22:58:25 -04:00
|
|
|
switch (CanTradeSelectedMon(gPlayerParty, gPlayerPartyCount, sTradeData->cursorPosition))
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
case CAN_TRADE_MON:
|
2018-12-21 12:20:28 -06:00
|
|
|
sub_8078D78();
|
2019-10-04 07:42:45 -04:00
|
|
|
gSprites[sTradeData->cursorSpriteIdx].invisible = TRUE;
|
2018-12-21 12:20:28 -06:00
|
|
|
break;
|
2019-10-06 22:58:25 -04:00
|
|
|
case CANT_TRADE_LAST_MON:
|
|
|
|
QueueAction(QUEUE_DELAY_MSG, QUEUE_ONLY_MON2);
|
|
|
|
sTradeData->tradeMenuFunc = 8;
|
2018-12-21 12:20:28 -06:00
|
|
|
break;
|
2019-10-06 22:58:25 -04:00
|
|
|
case CANT_TRADE_NATIONAL:
|
|
|
|
case CANT_TRADE_INVALID_MON:
|
|
|
|
QueueAction(QUEUE_DELAY_MSG, QUEUE_MON_CANT_BE_TRADED);
|
|
|
|
sTradeData->tradeMenuFunc = 8;
|
2018-12-21 12:20:28 -06:00
|
|
|
break;
|
2019-10-06 22:58:25 -04:00
|
|
|
case CANT_TRADE_EGG:
|
|
|
|
case CANT_TRADE_EGG2:
|
|
|
|
QueueAction(QUEUE_DELAY_MSG, QUEUE_EGG_CANT_BE_TRADED);
|
|
|
|
sTradeData->tradeMenuFunc = 8;
|
2018-12-21 12:20:28 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-05 10:41:37 -04:00
|
|
|
static void ReturnToTradeMenuAfterButtonPress(void)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
|
|
|
if ((gMain.newKeys & A_BUTTON) || (gMain.newKeys & B_BUTTON))
|
|
|
|
{
|
|
|
|
PlaySE(SE_SELECT);
|
2019-10-05 10:41:37 -04:00
|
|
|
ReturnToTradeMenu();
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
static void TradeMenuShowMonSummaryScreen(void)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
// Player's party
|
|
|
|
if (sTradeData->cursorPosition < PARTY_SIZE)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
ShowPokemonSummaryScreen(PSS_MODE_UNK1, gPlayerParty, sTradeData->cursorPosition, sTradeData->partyCounts[TRADE_PLAYER] - 1, sub_8077B74);
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
2019-10-04 07:42:45 -04:00
|
|
|
// Partner's party
|
2018-12-21 12:20:28 -06:00
|
|
|
else
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
ShowPokemonSummaryScreen(PSS_MODE_UNK1, gEnemyParty, sTradeData->cursorPosition - PARTY_SIZE, sTradeData->partyCounts[TRADE_PARTNER] - 1, sub_8077B74);
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
FreeAllWindowBuffers();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-03 19:39:37 -04:00
|
|
|
static u8 CheckValidityOfTradeMons(u8 *aliveMons, u8 playerPartyCount, u8 playerMonIdx, u8 partnerMonIdx)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
u16 species;
|
2019-10-03 19:39:37 -04:00
|
|
|
u8 hasLiveMon = 0;
|
2018-12-21 12:20:28 -06:00
|
|
|
|
2019-10-03 19:39:37 -04:00
|
|
|
// Make sure mon to be traded isn't player's last alive mon
|
|
|
|
for (i = 0; i < playerPartyCount; i++)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-03 19:39:37 -04:00
|
|
|
if (playerMonIdx != i)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-03 19:39:37 -04:00
|
|
|
hasLiveMon += aliveMons[i];
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
}
|
2019-10-03 19:39:37 -04:00
|
|
|
partnerMonIdx %= PARTY_SIZE;
|
|
|
|
species = GetMonData(&gEnemyParty[partnerMonIdx], MON_DATA_SPECIES);
|
2018-12-21 12:20:28 -06:00
|
|
|
|
2019-10-03 19:39:37 -04:00
|
|
|
// Partner cant trade illegitimate Deoxys or Mew
|
2018-12-21 12:20:28 -06:00
|
|
|
if (species == SPECIES_DEOXYS || species == SPECIES_MEW)
|
|
|
|
{
|
2019-10-03 19:39:37 -04:00
|
|
|
if (!GetMonData(&gEnemyParty[partnerMonIdx], MON_DATA_OBEDIENCE))
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-03 19:39:37 -04:00
|
|
|
return PARTNER_MON_INVALID;
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-03 19:39:37 -04:00
|
|
|
// Partner cant trade Egg or non-Hoenn mon if player doesn't have National Dex
|
2018-12-21 12:20:28 -06:00
|
|
|
if (!IsNationalPokedexEnabled())
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
if (sTradeData->isEgg[TRADE_PARTNER][partnerMonIdx] || !IsSpeciesInHoennDex(species))
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-03 19:39:37 -04:00
|
|
|
return PARTNER_MON_INVALID;
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
}
|
2018-12-25 15:14:15 +01:00
|
|
|
|
2019-10-03 19:39:37 -04:00
|
|
|
if (hasLiveMon)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-03 19:39:37 -04:00
|
|
|
hasLiveMon = PLAYER_MON_VALID;
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
|
2019-10-03 19:39:37 -04:00
|
|
|
return hasLiveMon; //PLAYER_MON_INVALID or PLAYER_MON_VALID
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static bool32 sub_8079174(void)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
|
|
|
int i;
|
2019-10-03 19:39:37 -04:00
|
|
|
u8 aliveMons[PARTY_SIZE * 2];
|
2018-12-21 12:20:28 -06:00
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
for (i = 0; i < sTradeData->partyCounts[TRADE_PLAYER]; i++)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
aliveMons[i] = sTradeData->isLiveMon[TRADE_PLAYER][i];
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
switch (CheckValidityOfTradeMons(aliveMons, sTradeData->partyCounts[TRADE_PLAYER], sTradeData->cursorPosition, sTradeData->partnerCursorPosition))
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-03 19:39:37 -04:00
|
|
|
case PLAYER_MON_INVALID:
|
2019-10-06 22:58:25 -04:00
|
|
|
QueueAction(QUEUE_DELAY_MSG, QUEUE_ONLY_MON2);
|
2019-10-03 19:39:37 -04:00
|
|
|
SetLinkData(0xBBCC, 0);
|
2018-12-21 12:20:28 -06:00
|
|
|
break;
|
2019-10-03 19:39:37 -04:00
|
|
|
case PLAYER_MON_VALID:
|
2019-10-06 22:58:25 -04:00
|
|
|
QueueAction(QUEUE_DELAY_MSG, QUEUE_STANDBY);
|
|
|
|
SetLinkData(LINKCMD_INIT_BLOCK, 0);
|
2018-12-21 12:20:28 -06:00
|
|
|
break;
|
2019-10-03 19:39:37 -04:00
|
|
|
case PARTNER_MON_INVALID:
|
2019-10-06 22:58:25 -04:00
|
|
|
QueueAction(QUEUE_DELAY_MSG, QUEUE_FRIENDS_MON_CANT_BE_TRADED);
|
2018-12-21 12:20:28 -06:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_8079218(void)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
|
|
|
switch (Menu_ProcessInputNoWrapClearOnChoose())
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
if (!sub_8079174())
|
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->tradeMenuFunc = 100;
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->tradeMenuFunc = 17;
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
PutWindowTilemap(17);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case MENU_B_PRESSED:
|
2019-10-06 22:58:25 -04:00
|
|
|
QueueAction(QUEUE_DELAY_MSG, QUEUE_STANDBY);
|
2018-12-21 12:20:28 -06:00
|
|
|
if (sub_80771BC())
|
2019-10-03 19:39:37 -04:00
|
|
|
SetLinkData(0xBBCC, 0);
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->tradeMenuFunc = 100;
|
2018-12-21 12:20:28 -06:00
|
|
|
PutWindowTilemap(17);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807929C(void)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2019-10-05 10:41:37 -04:00
|
|
|
for (i = 0; i < sTradeData->partyCounts[1] - 4; i++)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
|
|
|
PutWindowTilemap(i + 12);
|
|
|
|
CopyWindowToVram(i + 12, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_80792E4(void)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
|
|
|
switch (Menu_ProcessInputNoWrapClearOnChoose())
|
|
|
|
{
|
|
|
|
case 0:
|
2019-10-03 19:39:37 -04:00
|
|
|
PrintTradeMessage(TRADE_MSG_WAITING_FOR_FRIEND);
|
|
|
|
SetLinkData(0xEEAA, 0);
|
2019-10-04 07:42:45 -04:00
|
|
|
gSprites[sTradeData->cursorSpriteIdx].invisible = TRUE;
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->tradeMenuFunc = 100;
|
2018-12-21 12:20:28 -06:00
|
|
|
sub_807929C();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case MENU_B_PRESSED:
|
|
|
|
PlaySE(SE_SELECT);
|
2019-10-05 10:41:37 -04:00
|
|
|
ReturnToTradeMenu();
|
2018-12-21 12:20:28 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807935C(void)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
|
|
|
if (GetMultiplayerId() == 0)
|
|
|
|
{
|
|
|
|
rbox_fill_rectangle(0);
|
2019-10-04 07:42:45 -04:00
|
|
|
SetSelectedMon(sTradeData->cursorPosition);
|
|
|
|
SetSelectedMon(sTradeData->partnerCursorPosition);
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->tradeMenuFunc = 7;
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_8079398(void)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
if (sTradeData->drawPartyState[TRADE_PLAYER] == 5
|
|
|
|
&& sTradeData->drawPartyState[TRADE_PARTNER] == 5)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
PrintAndBufferIsThisTradeOkay();
|
|
|
|
sTradeData->tradeMenuFunc = 14;
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-18 20:46:00 -04:00
|
|
|
static void Wait2SecondsAndCreateYesNoMenu(void)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->timer++;
|
2018-12-25 15:14:15 +01:00
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
if (sTradeData->timer > 120)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-03 19:39:37 -04:00
|
|
|
CreateYesNoMenu(&sTradeYesNoWindowTemplate, 1, 14, 0);
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->timer = 0;
|
|
|
|
sTradeData->tradeMenuFunc = 3;
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
static void RedrawTradeMenuAfterPressA(void)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (gMain.newKeys & A_BUTTON)
|
|
|
|
{
|
|
|
|
PlaySE(SE_SELECT);
|
|
|
|
rbox_fill_rectangle(0);
|
|
|
|
rbox_fill_rectangle(1);
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
2019-03-02 17:25:39 -05:00
|
|
|
FillWindowPixelBuffer(i + 14, PIXEL_FILL(0));
|
2018-12-21 12:20:28 -06:00
|
|
|
rbox_fill_rectangle(i + 14);
|
|
|
|
}
|
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
RedrawTradeMenuParty(TRADE_PLAYER);
|
|
|
|
RedrawTradeMenuParty(TRADE_PARTNER);
|
|
|
|
sTradeData->tradeMenuFunc = 0;
|
2019-10-04 07:42:45 -04:00
|
|
|
gSprites[sTradeData->cursorSpriteIdx].invisible = FALSE;
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_8079490(void)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
|
|
|
if (gWirelessCommType)
|
|
|
|
{
|
|
|
|
sub_800ADF8();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sub_800ABF4(12);
|
|
|
|
}
|
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->tradeMenuFunc = 12;
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_80794CC(void)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
|
|
|
if (gWirelessCommType)
|
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
if (sub_80771BC() && GetNumQueuedActions() == 0)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-05 10:41:37 -04:00
|
|
|
Free(sMessageBoxAllocBuffer);
|
2019-10-04 07:42:45 -04:00
|
|
|
Free(sTradeData);
|
2018-12-21 12:20:28 -06:00
|
|
|
FreeAllWindowBuffers();
|
2019-03-31 18:59:52 -04:00
|
|
|
DestroyWirelessStatusIndicatorSprite();
|
2019-02-10 03:54:50 -05:00
|
|
|
SetMainCallback2(CB2_ReturnToFieldFromMultiplayer);
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
if (!gReceivedRemoteLinkPlayers)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-05 10:41:37 -04:00
|
|
|
Free(sMessageBoxAllocBuffer);
|
2019-10-04 07:42:45 -04:00
|
|
|
Free(sTradeData);
|
2018-12-21 12:20:28 -06:00
|
|
|
FreeAllWindowBuffers();
|
2019-02-10 03:54:50 -05:00
|
|
|
SetMainCallback2(CB2_ReturnToFieldFromMultiplayer);
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_8079550(void)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
if (!sub_801048C(FALSE) && GetNumQueuedActions() == 0)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
|
|
|
sub_800ADF8();
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->tradeMenuFunc = 13;
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807957C(void)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
|
|
|
if (gMain.newKeys & A_BUTTON)
|
|
|
|
{
|
2019-10-03 19:39:37 -04:00
|
|
|
SetLinkData(0xBBCC, 0);
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->tradeMenuFunc = 100;
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-03 19:39:37 -04:00
|
|
|
//TODO:
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_80795AC(void)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
switch (sTradeData->tradeMenuFunc)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
|
|
|
case 0:
|
2019-10-05 10:41:37 -04:00
|
|
|
TradeMenuProcessInput();
|
2018-12-21 12:20:28 -06:00
|
|
|
break;
|
|
|
|
case 1:
|
2019-10-03 19:39:37 -04:00
|
|
|
TradeMenuProcessInput_SelectedMon();
|
2018-12-21 12:20:28 -06:00
|
|
|
break;
|
|
|
|
case 2:
|
2019-10-04 07:42:45 -04:00
|
|
|
TradeMenuShowMonSummaryScreen();
|
2018-12-21 12:20:28 -06:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
sub_8079218();
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
sub_80792E4();
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
sub_807935C();
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
sub_8079398();
|
|
|
|
break;
|
|
|
|
case 8:
|
2019-10-06 22:58:25 -04:00
|
|
|
RedrawTradeMenuAfterPressA();
|
2018-12-21 12:20:28 -06:00
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
sub_8078130();
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
sub_807816C();
|
|
|
|
break;
|
|
|
|
case 11:
|
|
|
|
sub_8079490();
|
|
|
|
break;
|
|
|
|
case 12:
|
|
|
|
sub_80794CC();
|
|
|
|
break;
|
|
|
|
case 13:
|
|
|
|
sub_80781C8();
|
|
|
|
break;
|
|
|
|
case 14:
|
2019-07-18 20:46:00 -04:00
|
|
|
Wait2SecondsAndCreateYesNoMenu();
|
2018-12-21 12:20:28 -06:00
|
|
|
break;
|
|
|
|
case 15:
|
2019-10-05 10:41:37 -04:00
|
|
|
ReturnToTradeMenuAfterButtonPress();
|
2018-12-21 12:20:28 -06:00
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
sub_8079550();
|
|
|
|
break;
|
|
|
|
case 17:
|
|
|
|
sub_807957C();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-03 19:39:37 -04:00
|
|
|
static void SetSelectedMon(u8 cursorPosition)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-03 19:39:37 -04:00
|
|
|
//cursorPosition 0-5 are the player's mons, 6-11 are the partner's
|
|
|
|
u8 whichParty = cursorPosition / PARTY_SIZE;
|
2018-12-21 12:20:28 -06:00
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
if (sTradeData->drawPartyState[whichParty] == 0)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->drawPartyState[whichParty] = 1;
|
|
|
|
sTradeData->selectedMonIdx[whichParty] = cursorPosition;
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
static void DrawTradeMenuParty(u8 whichParty)
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
s8 nameStringWidth;
|
|
|
|
u8 nickname[20];
|
|
|
|
u8 movesString[56];
|
2018-12-21 12:20:28 -06:00
|
|
|
u8 i;
|
2018-12-31 02:22:21 -06:00
|
|
|
u8 partyIdx;
|
2019-10-04 07:42:45 -04:00
|
|
|
u8 selectedMonParty;
|
|
|
|
u8 selectedMonIdx = sTradeData->selectedMonIdx[whichParty];
|
2018-12-25 15:14:15 +01:00
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
selectedMonParty = TRADE_PARTNER;
|
|
|
|
if (sTradeData->selectedMonIdx[whichParty] < PARTY_SIZE)
|
|
|
|
selectedMonParty = TRADE_PLAYER;
|
2019-10-03 19:39:37 -04:00
|
|
|
partyIdx = selectedMonIdx % PARTY_SIZE;
|
2018-12-31 02:22:21 -06:00
|
|
|
nameStringWidth = 0;
|
2018-12-25 15:14:15 +01:00
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
switch (sTradeData->drawPartyState[whichParty])
|
2018-12-21 12:20:28 -06:00
|
|
|
{
|
2018-12-25 15:14:15 +01:00
|
|
|
case 1:
|
2019-10-04 07:42:45 -04:00
|
|
|
for (i = 0; i < sTradeData->partyCounts[whichParty]; i++)
|
2018-12-25 15:14:15 +01:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
gSprites[sTradeData->partySpriteIds[0][i + (selectedMonParty * PARTY_SIZE)]].invisible = TRUE;
|
2018-12-25 15:14:15 +01:00
|
|
|
}
|
2018-12-21 12:20:28 -06:00
|
|
|
|
2018-12-25 15:14:15 +01:00
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
ClearWindowTilemap(i + (whichParty * PARTY_SIZE + 2));
|
2018-12-25 15:14:15 +01:00
|
|
|
}
|
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
gSprites[sTradeData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]].invisible = FALSE;
|
|
|
|
gSprites[sTradeData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]].data[0] = 20;
|
|
|
|
gSprites[sTradeData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]].data[2] = (gTradeMonSpriteCoords[selectedMonParty * PARTY_SIZE][0] + gTradeMonSpriteCoords[selectedMonParty * PARTY_SIZE + 1][0]) / 2 * 8 + 14;
|
|
|
|
gSprites[sTradeData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]].data[4] = (gTradeMonSpriteCoords[selectedMonParty * PARTY_SIZE][1] * 8) - 12;
|
|
|
|
StoreSpriteCallbackInData6(&gSprites[sTradeData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]], sub_80D3014);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->drawPartyState[whichParty]++;
|
2019-10-06 22:58:25 -04:00
|
|
|
TradeMenuBouncePartySprites(&gSprites[sTradeData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]]);
|
2019-10-04 07:42:45 -04:00
|
|
|
CopyToBgTilemapBufferRect_ChangePalette(1, gTradePartyBoxTilemap, whichParty * 15, 0, 15, 17, 0);
|
2018-12-25 15:14:15 +01:00
|
|
|
CopyBgTilemapBufferToVram(1);
|
|
|
|
CopyBgTilemapBufferToVram(0);
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
if (selectedMonParty == TRADE_PLAYER)
|
2018-12-25 15:14:15 +01:00
|
|
|
sub_8079F74();
|
|
|
|
break;
|
|
|
|
case 2:
|
2019-10-06 22:58:25 -04:00
|
|
|
if (gSprites[sTradeData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]].callback == sub_80D3014)
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->drawPartyState[whichParty] = 3;
|
2018-12-25 15:14:15 +01:00
|
|
|
break;
|
|
|
|
case 3:
|
2019-10-04 07:42:45 -04:00
|
|
|
CopyToBgTilemapBufferRect_ChangePalette(1, gTradeMovesBoxTilemap, selectedMonParty * 15, 0, 15, 17, 0);
|
2018-12-25 15:14:15 +01:00
|
|
|
CopyBgTilemapBufferToVram(1);
|
2019-10-06 22:58:25 -04:00
|
|
|
gSprites[sTradeData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]].pos1.x = (gTradeMonSpriteCoords[selectedMonParty * PARTY_SIZE][0] + gTradeMonSpriteCoords[selectedMonParty * PARTY_SIZE + 1][0]) / 2 * 8 + 14;
|
|
|
|
gSprites[sTradeData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]].pos1.y = (gTradeMonSpriteCoords[selectedMonParty * PARTY_SIZE][1] * 8) - 12;
|
|
|
|
gSprites[sTradeData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]].pos2.x = 0;
|
|
|
|
gSprites[sTradeData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]].pos2.y = 0;
|
|
|
|
nameStringWidth = GetMonNicknameWidth(nickname, selectedMonParty, partyIdx);
|
2019-10-04 07:42:45 -04:00
|
|
|
AddTextPrinterParameterized3((whichParty * 2) + 14, 0, (80 - nameStringWidth) / 2, 4, sTradeTextColors, 0, nickname);
|
|
|
|
BufferTradeMonMoves(movesString, selectedMonParty, partyIdx);
|
|
|
|
AddTextPrinterParameterized4((whichParty * 2) + 15, 1, 0, 0, 0, 0, sTradeTextColors, 0, movesString);
|
|
|
|
PutWindowTilemap((whichParty * 2) + 14);
|
|
|
|
CopyWindowToVram((whichParty * 2) + 14, 3);
|
|
|
|
PutWindowTilemap((whichParty * 2) + 15);
|
|
|
|
CopyWindowToVram((whichParty * 2) + 15, 3);
|
|
|
|
sTradeData->drawPartyState[whichParty]++;
|
2018-12-25 15:14:15 +01:00
|
|
|
break;
|
|
|
|
case 4:
|
2019-10-04 07:42:45 -04:00
|
|
|
DrawTradeMenuPartyMonInfo(whichParty, partyIdx,
|
|
|
|
sTradeMenuPartyMonBoxDimensions[whichParty][0] + 4,
|
|
|
|
sTradeMenuPartyMonBoxDimensions[whichParty][1] + 1,
|
|
|
|
sTradeMenuPartyMonBoxDimensions[whichParty][0],
|
|
|
|
sTradeMenuPartyMonBoxDimensions[whichParty][1]);
|
|
|
|
sTradeData->drawPartyState[whichParty]++;
|
2018-12-25 15:14:15 +01:00
|
|
|
break;
|
2018-12-21 12:20:28 -06:00
|
|
|
}
|
|
|
|
}
|
2018-12-22 01:26:53 -06:00
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
static u8 GetMonNicknameWidth(u8 *str, u8 whichParty, u8 monIdx)
|
2018-12-22 01:26:53 -06:00
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
u8 nickname[12];
|
2018-12-22 01:26:53 -06:00
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
if (whichParty == TRADE_PLAYER)
|
2018-12-31 02:22:21 -06:00
|
|
|
GetMonData(&gPlayerParty[monIdx], MON_DATA_NICKNAME, nickname);
|
2018-12-22 01:26:53 -06:00
|
|
|
else
|
2018-12-31 02:22:21 -06:00
|
|
|
GetMonData(&gEnemyParty[monIdx], MON_DATA_NICKNAME, nickname);
|
2018-12-22 01:26:53 -06:00
|
|
|
|
2018-12-31 02:22:21 -06:00
|
|
|
StringCopy10(str, nickname);
|
|
|
|
return GetStringWidth(0, str, GetFontAttribute(0, FONTATTR_LETTER_SPACING));
|
2018-12-22 01:26:53 -06:00
|
|
|
}
|
|
|
|
|
2019-10-03 01:16:22 -04:00
|
|
|
static void BufferTradeMonMoves(u8 *str, u8 whichParty, u8 partyIdx)
|
2018-12-22 01:26:53 -06:00
|
|
|
{
|
2019-09-08 11:53:48 -04:00
|
|
|
u16 moves[MAX_MON_MOVES];
|
2018-12-22 01:26:53 -06:00
|
|
|
u16 i;
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
if (!sTradeData->isEgg[whichParty][partyIdx])
|
2018-12-22 01:26:53 -06:00
|
|
|
{
|
|
|
|
for (i = 0; i < MAX_MON_MOVES; i++)
|
|
|
|
{
|
2019-10-03 01:16:22 -04:00
|
|
|
if (whichParty == TRADE_PLAYER)
|
2018-12-22 01:26:53 -06:00
|
|
|
{
|
2019-10-03 01:16:22 -04:00
|
|
|
moves[i] = GetMonData(&gPlayerParty[partyIdx], i + MON_DATA_MOVE1, NULL);
|
2018-12-22 01:26:53 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-03 01:16:22 -04:00
|
|
|
moves[i] = GetMonData(&gEnemyParty[partyIdx], i + MON_DATA_MOVE1, NULL);
|
2018-12-22 01:26:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-03 01:16:22 -04:00
|
|
|
StringCopy(str, gText_EmptyString7);
|
2018-12-22 01:26:53 -06:00
|
|
|
|
|
|
|
for (i = 0; i < MAX_MON_MOVES; i++)
|
|
|
|
{
|
2019-09-08 11:53:48 -04:00
|
|
|
if (moves[i] != MOVE_NONE)
|
2018-12-22 01:26:53 -06:00
|
|
|
{
|
2019-10-03 01:16:22 -04:00
|
|
|
StringAppend(str, gMoveNames[moves[i]]);
|
2018-12-22 01:26:53 -06:00
|
|
|
}
|
|
|
|
|
2019-10-03 01:16:22 -04:00
|
|
|
StringAppend(str, gText_NewLine3);
|
2018-12-22 01:26:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-03 01:16:22 -04:00
|
|
|
StringCopy(str, gText_EmptyString7);
|
|
|
|
StringAppend(str, gText_FourQuestionMarks);
|
2018-12-22 01:26:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-03 19:39:37 -04:00
|
|
|
static void PrintMonNicknameForTradeMenu(u8 whichParty, u8 windowId, u8 *nickname)
|
2018-12-22 01:26:53 -06:00
|
|
|
{
|
|
|
|
u8 xPos;
|
2018-12-31 02:22:21 -06:00
|
|
|
windowId += (whichParty * PARTY_SIZE) + 2;
|
2019-10-03 19:39:37 -04:00
|
|
|
xPos = GetStringCenterAlignXOffset(0, nickname, 64);
|
|
|
|
AddTextPrinterParameterized3(windowId, 0, xPos, 4, sTradeTextColors, 0, nickname);
|
2018-12-31 02:22:21 -06:00
|
|
|
PutWindowTilemap(windowId);
|
|
|
|
CopyWindowToVram(windowId, 3);
|
2018-12-22 01:26:53 -06:00
|
|
|
}
|
2018-12-23 01:26:38 -06:00
|
|
|
|
2019-10-03 19:39:37 -04:00
|
|
|
static void PrintPartyNicknamesForTradeMenu(u8 whichParty)
|
2018-12-23 01:26:38 -06:00
|
|
|
{
|
|
|
|
u8 i;
|
2019-10-03 19:39:37 -04:00
|
|
|
u8 nickname[20];
|
|
|
|
u8 str[32];
|
|
|
|
struct Pokemon *party = (whichParty == TRADE_PLAYER) ? gPlayerParty : gEnemyParty;
|
2018-12-23 01:26:38 -06:00
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
for (i = 0; i < sTradeData->partyCounts[whichParty]; i++)
|
2018-12-23 01:26:38 -06:00
|
|
|
{
|
2019-10-03 19:39:37 -04:00
|
|
|
GetMonData(&party[i], MON_DATA_NICKNAME, nickname);
|
|
|
|
StringCopy10(str, nickname);
|
|
|
|
PrintMonNicknameForTradeMenu(whichParty, i, str);
|
2018-12-23 01:26:38 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
static void DrawTradeMenuPartyMonInfo(u8 whichParty, u8 monIdx, u8 x, u8 y, u8 width, u8 height)
|
2018-12-23 01:26:38 -06:00
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
u8 level;
|
2019-10-06 22:58:25 -04:00
|
|
|
u32 symbolTile;
|
2018-12-23 01:26:38 -06:00
|
|
|
u8 gender;
|
2018-12-31 02:22:21 -06:00
|
|
|
u8 nickname[12];
|
2018-12-23 01:26:38 -06:00
|
|
|
|
2019-10-03 19:39:37 -04:00
|
|
|
CopyToBgTilemapBufferRect_ChangePalette(1, gUnknown_08DDD704, width, height, 6, 3, 0);
|
2018-12-23 01:26:38 -06:00
|
|
|
CopyBgTilemapBufferToVram(1);
|
|
|
|
|
2019-10-03 01:16:22 -04:00
|
|
|
if (whichParty == TRADE_PLAYER)
|
2018-12-31 02:22:21 -06:00
|
|
|
level = GetMonData(&gPlayerParty[monIdx], MON_DATA_LEVEL, NULL);
|
2018-12-23 01:26:38 -06:00
|
|
|
else
|
2018-12-31 02:22:21 -06:00
|
|
|
level = GetMonData(&gEnemyParty[monIdx], MON_DATA_LEVEL, NULL);
|
2018-12-23 01:26:38 -06:00
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
if (!sTradeData->isEgg[whichParty][monIdx])
|
2018-12-23 01:26:38 -06:00
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
if (level / 10 != 0)
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->tilemapBuffer[x + (y * 32)] = (level / 10) + 0x60;
|
2018-12-31 02:22:21 -06:00
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->tilemapBuffer[x + (y * 32) + 1] = (level % 10) + 0x70;
|
2018-12-23 01:26:38 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->tilemapBuffer[x + (y * 32) - 32] = sTradeData->tilemapBuffer[x + (y * 32) - 33];
|
|
|
|
sTradeData->tilemapBuffer[x + (y * 32) - 31] = sTradeData->tilemapBuffer[x + (y * 32) - 36] | 0x400;
|
2018-12-23 01:26:38 -06:00
|
|
|
}
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
if (sTradeData->isEgg[whichParty][monIdx])
|
2018-12-23 01:26:38 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
symbolTile = 0x480;
|
2018-12-23 01:26:38 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-03 01:16:22 -04:00
|
|
|
if (whichParty == TRADE_PLAYER)
|
2018-12-23 01:26:38 -06:00
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
gender = GetMonGender(&gPlayerParty[monIdx]);
|
|
|
|
GetMonData(&gPlayerParty[monIdx], MON_DATA_NICKNAME, nickname);
|
2018-12-23 01:26:38 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
gender = GetMonGender(&gEnemyParty[monIdx]);
|
|
|
|
GetMonData(&gEnemyParty[monIdx], MON_DATA_NICKNAME, nickname);
|
2018-12-23 01:26:38 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (gender)
|
|
|
|
{
|
|
|
|
case MON_MALE:
|
2019-10-06 22:58:25 -04:00
|
|
|
symbolTile = !NameHasGenderSymbol(nickname, MON_MALE) ? 0x84 : 0x83;
|
2018-12-23 01:26:38 -06:00
|
|
|
break;
|
|
|
|
case MON_FEMALE:
|
2019-10-06 22:58:25 -04:00
|
|
|
symbolTile = !NameHasGenderSymbol(nickname, MON_FEMALE) ? 0x85 : 0x83;
|
2018-12-23 01:26:38 -06:00
|
|
|
break;
|
|
|
|
default:
|
2019-10-06 22:58:25 -04:00
|
|
|
symbolTile = 0x83;
|
2018-12-23 01:26:38 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->tilemapBuffer[(y - 1) * 32 + x + 1] = symbolTile;
|
2018-12-23 01:26:38 -06:00
|
|
|
}
|
|
|
|
|
2018-12-24 03:03:02 -06:00
|
|
|
// Very close but loop preamble not working.
|
|
|
|
#ifdef NONMATCHING
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_8079E44(u8 whichParty)
|
2018-12-23 01:26:38 -06:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
for (i = 0; i < sTradeData->partyCounts[whichParty]; i++)
|
2018-12-23 01:26:38 -06:00
|
|
|
{
|
2019-10-05 10:41:37 -04:00
|
|
|
DrawTradeMenuPartyMonInfo(whichParty, i,
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeMonCoords[whichParty][i][0] + 4,
|
|
|
|
sTradeMonCoords[whichParty][i][1] - 1,
|
|
|
|
sTradeMonBoxDimensions[whichParty][i][0],
|
|
|
|
sTradeMonBoxDimensions[whichParty][i][1]);
|
2018-12-23 01:26:38 -06:00
|
|
|
}
|
|
|
|
}
|
2018-12-24 03:03:02 -06:00
|
|
|
#else
|
|
|
|
NAKED
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_8079E44(u8 whichParty)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
|
|
|
asm_unified("push {r4-r7,lr}\n\
|
|
|
|
sub sp, 0x8\n\
|
|
|
|
lsls r0, 24\n\
|
|
|
|
lsrs r6, r0, 24\n\
|
|
|
|
movs r7, 0\n\
|
2019-10-04 07:42:45 -04:00
|
|
|
ldr r0, =sTradeData\n\
|
2018-12-24 03:03:02 -06:00
|
|
|
ldr r0, [r0]\n\
|
|
|
|
adds r0, 0x36\n\
|
|
|
|
adds r0, r6\n\
|
|
|
|
ldrb r0, [r0]\n\
|
|
|
|
cmp r7, r0\n\
|
|
|
|
bge _08079E94\n\
|
|
|
|
lsls r0, r6, 1\n\
|
|
|
|
adds r0, r6\n\
|
2019-10-06 22:58:25 -04:00
|
|
|
ldr r1, =sTradeMonCoords\n\
|
2018-12-24 03:03:02 -06:00
|
|
|
lsls r0, 2\n\
|
|
|
|
adds r5, r0, r1\n\
|
2019-10-06 22:58:25 -04:00
|
|
|
ldr r1, =sTradeMonBoxDimensions\n\
|
2018-12-24 03:03:02 -06:00
|
|
|
adds r4, r0, r1\n\
|
|
|
|
_08079E6A:\n\
|
|
|
|
lsls r1, r7, 24\n\
|
|
|
|
lsrs r1, 24\n\
|
|
|
|
ldrb r2, [r5]\n\
|
|
|
|
ldrb r3, [r5, 0x1]\n\
|
|
|
|
ldrb r0, [r4]\n\
|
|
|
|
str r0, [sp]\n\
|
|
|
|
ldrb r0, [r4, 0x1]\n\
|
|
|
|
str r0, [sp, 0x4]\n\
|
|
|
|
adds r0, r6, 0\n\
|
2019-10-04 07:42:45 -04:00
|
|
|
bl DrawTradeMenuPartyMonInfo\n\
|
2018-12-24 03:03:02 -06:00
|
|
|
adds r5, 0x2\n\
|
|
|
|
adds r4, 0x2\n\
|
|
|
|
adds r7, 0x1\n\
|
2019-10-04 07:42:45 -04:00
|
|
|
ldr r0, =sTradeData\n\
|
2018-12-24 03:03:02 -06:00
|
|
|
ldr r0, [r0]\n\
|
|
|
|
adds r0, 0x36\n\
|
|
|
|
adds r0, r6\n\
|
|
|
|
ldrb r0, [r0]\n\
|
|
|
|
cmp r7, r0\n\
|
|
|
|
blt _08079E6A\n\
|
|
|
|
_08079E94:\n\
|
|
|
|
add sp, 0x8\n\
|
|
|
|
pop {r4-r7}\n\
|
|
|
|
pop {r0}\n\
|
|
|
|
bx r0\n\
|
|
|
|
.pool");
|
|
|
|
}
|
|
|
|
#endif // NONMATCHING
|
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
static void ResetTradeMenuPartyPositions(u8 whichParty)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
for (i = 0; i < sTradeData->partyCounts[whichParty]; i++)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
gSprites[sTradeData->partySpriteIds[whichParty][i]].invisible = FALSE;
|
|
|
|
gSprites[sTradeData->partySpriteIds[whichParty][i]].pos1.x = gTradeMonSpriteCoords[(whichParty * PARTY_SIZE) + i][0] * 8 + 14;
|
|
|
|
gSprites[sTradeData->partySpriteIds[whichParty][i]].pos1.y = gTradeMonSpriteCoords[(whichParty * PARTY_SIZE) + i][1] * 8 - 12;
|
|
|
|
gSprites[sTradeData->partySpriteIds[whichParty][i]].pos2.x = 0;
|
|
|
|
gSprites[sTradeData->partySpriteIds[whichParty][i]].pos2.y = 0;
|
2018-12-24 03:03:02 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_8079F74(void)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
|
|
|
rbox_fill_rectangle(1);
|
2019-10-03 19:39:37 -04:00
|
|
|
PrintPartyNicknamesForTradeMenu(TRADE_PARTNER);
|
2018-12-24 03:03:02 -06:00
|
|
|
}
|
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
static void RedrawTradeMenuParty(u8 whichParty)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
2019-10-03 19:39:37 -04:00
|
|
|
CopyToBgTilemapBufferRect_ChangePalette(1, gTradePartyBoxTilemap, whichParty * 15, 0, 15, 17, 0);
|
2018-12-24 03:03:02 -06:00
|
|
|
CopyBgTilemapBufferToVram(1);
|
2019-10-03 19:39:37 -04:00
|
|
|
sub_8079E44(whichParty);
|
|
|
|
PrintPartyNicknamesForTradeMenu(whichParty);
|
2019-10-06 22:58:25 -04:00
|
|
|
ResetTradeMenuPartyPositions(whichParty);
|
|
|
|
DrawTextWindowAndBuffer6Bytes(sTradeActionTexts[TRADE_ACTION_TEXT_CHOOSE_MON], (void *)(OBJ_VRAM0 + (sTradeData->unk_72 * 32)), 24);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->drawPartyState[whichParty] = 0;
|
2018-12-24 03:03:02 -06:00
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807A000(u8 taskId)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
|
|
|
FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 30, 20);
|
|
|
|
CopyBgTilemapBufferToVram(0);
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807A024(u8 taskId)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
|
|
|
FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 30, 20);
|
|
|
|
CopyBgTilemapBufferToVram(0);
|
|
|
|
}
|
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
static void QueueAction(u16 delay, u8 actionId)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
for (i = 0; i < (int)ARRAY_COUNT(sTradeData->queuedActions); i++)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
if (!sTradeData->queuedActions[i].queued)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->queuedActions[i].queueDelay = delay;
|
|
|
|
sTradeData->queuedActions[i].actionId = actionId;
|
|
|
|
sTradeData->queuedActions[i].queued = TRUE;
|
2018-12-24 03:03:02 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
static u32 GetNumQueuedActions(void)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
u32 numActions = 0;
|
2018-12-24 03:03:02 -06:00
|
|
|
int i;
|
2018-12-25 15:14:15 +01:00
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
for (i = 0; i < (int)ARRAY_COUNT(sTradeData->queuedActions); i++)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
numActions += sTradeData->queuedActions[i].queued;
|
2018-12-24 03:03:02 -06:00
|
|
|
}
|
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
return numActions;
|
2018-12-24 03:03:02 -06:00
|
|
|
}
|
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
static void DoQueuedActions(void)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
for (i = 0; i < (int)ARRAY_COUNT(sTradeData->queuedActions); i++)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
if (sTradeData->queuedActions[i].queued)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
if (sTradeData->queuedActions[i].queueDelay)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->queuedActions[i].queueDelay--;
|
2018-12-24 03:03:02 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
switch (sTradeData->queuedActions[i].actionId)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
case QUEUE_SEND_DATA:
|
2019-10-04 07:42:45 -04:00
|
|
|
SendLinkData(sTradeData->linkData, 20);
|
2018-12-24 03:03:02 -06:00
|
|
|
break;
|
2019-10-06 22:58:25 -04:00
|
|
|
case QUEUE_STANDBY:
|
2019-10-03 19:39:37 -04:00
|
|
|
PrintTradeMessage(TRADE_MSG_STANDBY);
|
2018-12-24 03:03:02 -06:00
|
|
|
break;
|
2019-10-06 22:58:25 -04:00
|
|
|
case QUEUE_ONLY_MON1:
|
2019-10-03 19:39:37 -04:00
|
|
|
PrintTradeMessage(TRADE_MSG_ONLY_MON1);
|
2018-12-24 03:03:02 -06:00
|
|
|
break;
|
2019-10-06 22:58:25 -04:00
|
|
|
case QUEUE_ONLY_MON2:
|
|
|
|
case QUEUE_UNUSED1:
|
|
|
|
case QUEUE_UNUSED2:
|
2019-10-03 19:39:37 -04:00
|
|
|
PrintTradeMessage(TRADE_MSG_ONLY_MON2);
|
2018-12-24 03:03:02 -06:00
|
|
|
break;
|
2019-10-06 22:58:25 -04:00
|
|
|
case QUEUE_MON_CANT_BE_TRADED:
|
2019-10-03 19:39:37 -04:00
|
|
|
PrintTradeMessage(TRADE_MSG_MON_CANT_BE_TRADED);
|
2018-12-24 03:03:02 -06:00
|
|
|
break;
|
2019-10-06 22:58:25 -04:00
|
|
|
case QUEUE_EGG_CANT_BE_TRADED:
|
2019-10-03 19:39:37 -04:00
|
|
|
PrintTradeMessage(TRADE_MSG_EGG_CANT_BE_TRADED);
|
2018-12-24 03:03:02 -06:00
|
|
|
break;
|
2019-10-06 22:58:25 -04:00
|
|
|
case QUEUE_FRIENDS_MON_CANT_BE_TRADED:
|
2019-10-03 19:39:37 -04:00
|
|
|
PrintTradeMessage(TRADE_MSG_FRIENDS_MON_CANT_BE_TRADED);
|
2018-12-24 03:03:02 -06:00
|
|
|
break;
|
|
|
|
}
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->queuedActions[i].queued = FALSE;
|
2018-12-24 03:03:02 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-03 19:39:37 -04:00
|
|
|
static void PrintTradeMessage(u8 messageId)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
2019-03-02 17:25:39 -05:00
|
|
|
FillWindowPixelBuffer(0, PIXEL_FILL(1));
|
2019-10-04 17:24:03 -04:00
|
|
|
AddTextPrinterParameterized(0, 1, sTradeMessages[messageId], 0, 1, TEXT_SPEED_FF, NULL);
|
2019-03-31 18:59:52 -04:00
|
|
|
DrawTextBorderOuter(0, 20, 12);
|
2018-12-24 03:03:02 -06:00
|
|
|
PutWindowTilemap(0);
|
|
|
|
CopyWindowToVram(0, 3);
|
|
|
|
}
|
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
static bool8 LoadTradeMenuSpriteSheetsAndPalettes(void)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
|
|
|
struct SpriteSheet sheet;
|
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
if (sTradeData->timer < (int)ARRAY_COUNT(sMessageBoxTileBuffers))
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
sheet.data = sMessageBoxTileBuffers[sTradeData->timer];
|
2018-12-24 03:03:02 -06:00
|
|
|
sheet.size = 0x100;
|
2019-10-06 22:58:25 -04:00
|
|
|
sheet.tag = 200 + sTradeData->timer;
|
2018-12-24 03:03:02 -06:00
|
|
|
}
|
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
switch (sTradeData->timer)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
|
|
|
case 0 ... 7:
|
|
|
|
LoadSpriteSheet(&sheet);
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->timer++;
|
2018-12-24 03:03:02 -06:00
|
|
|
break;
|
|
|
|
case 8:
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->unk_72 = LoadSpriteSheet(&sheet);
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->timer++;
|
2018-12-24 03:03:02 -06:00
|
|
|
break;
|
|
|
|
case 9 ... 13:
|
|
|
|
LoadSpriteSheet(&sheet);
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->timer++;
|
2018-12-24 03:03:02 -06:00
|
|
|
break;
|
|
|
|
case 14:
|
|
|
|
LoadSpritePalette(&gSpritePalette_TradeScreenText);
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->timer++;
|
2018-12-24 03:03:02 -06:00
|
|
|
break;
|
|
|
|
case 15:
|
|
|
|
LoadSpritePalette(&gUnknown_0832DC44);
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->timer++;
|
2018-12-24 03:03:02 -06:00
|
|
|
break;
|
|
|
|
case 16:
|
2019-10-05 10:41:37 -04:00
|
|
|
LoadSpriteSheet(&sTradeButtonsSpriteSheet);
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->timer++;
|
2018-12-24 03:03:02 -06:00
|
|
|
break;
|
|
|
|
case 17:
|
2019-10-06 22:58:25 -04:00
|
|
|
sTradeData->timer = 0;
|
2018-12-24 03:03:02 -06:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
static void DrawTextWindowAndBuffer6Bytes(const u8 *str, u8 *dest, u8 unused)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
DrawTextWindowAndBufferTiles(str, dest, 0, 0, 6);
|
2018-12-24 03:03:02 -06:00
|
|
|
}
|
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
static void SetTradePartyLiveStatuses(u8 whichParty)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2019-10-03 01:16:22 -04:00
|
|
|
switch (whichParty)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
2019-10-03 01:16:22 -04:00
|
|
|
case TRADE_PLAYER:
|
2019-10-04 07:42:45 -04:00
|
|
|
for (i = 0; i < sTradeData->partyCounts[whichParty]; i++)
|
2019-10-03 01:16:22 -04:00
|
|
|
{
|
|
|
|
if (GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG) == TRUE)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->isLiveMon[whichParty][i] = FALSE;
|
|
|
|
sTradeData->isEgg[whichParty][i] = TRUE;
|
2018-12-24 03:03:02 -06:00
|
|
|
}
|
2019-10-03 01:16:22 -04:00
|
|
|
else if (GetMonData(&gPlayerParty[i], MON_DATA_HP) == 0)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->isLiveMon[whichParty][i] = FALSE;
|
|
|
|
sTradeData->isEgg[whichParty][i] = FALSE;
|
2018-12-24 03:03:02 -06:00
|
|
|
}
|
2019-10-03 01:16:22 -04:00
|
|
|
else
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->isLiveMon[whichParty][i] = TRUE;
|
|
|
|
sTradeData->isEgg[whichParty][i] = FALSE;
|
2019-10-03 01:16:22 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TRADE_PARTNER:
|
2019-10-04 07:42:45 -04:00
|
|
|
for (i = 0; i < sTradeData->partyCounts[whichParty]; i++)
|
2019-10-03 01:16:22 -04:00
|
|
|
{
|
|
|
|
if (GetMonData(&gEnemyParty[i], MON_DATA_IS_EGG) == TRUE)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->isLiveMon[whichParty][i] = FALSE;
|
|
|
|
sTradeData->isEgg[whichParty][i] = TRUE;
|
2019-10-03 01:16:22 -04:00
|
|
|
}
|
|
|
|
else if (GetMonData(&gEnemyParty[i], MON_DATA_HP) == 0)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->isLiveMon[whichParty][i] = FALSE;
|
|
|
|
sTradeData->isEgg[whichParty][i] = FALSE;
|
2019-10-03 01:16:22 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->isLiveMon[whichParty][i] = TRUE;
|
|
|
|
sTradeData->isEgg[whichParty][i] = FALSE;
|
2019-10-03 01:16:22 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2018-12-24 03:03:02 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-03 19:39:37 -04:00
|
|
|
static void GetTradePartyHPBarLevels(u8 who)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
2018-12-28 02:11:41 -06:00
|
|
|
u16 i, curHp, maxHp;
|
2018-12-24 03:03:02 -06:00
|
|
|
|
2018-12-28 02:11:41 -06:00
|
|
|
switch (who)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
2019-10-03 19:39:37 -04:00
|
|
|
case TRADE_PLAYER:
|
2019-10-04 07:42:45 -04:00
|
|
|
for (i = 0; i < sTradeData->partyCounts[TRADE_PLAYER]; i++)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
2018-12-28 02:11:41 -06:00
|
|
|
curHp = GetMonData(&gPlayerParty[i], MON_DATA_HP);
|
2018-12-24 03:03:02 -06:00
|
|
|
maxHp = GetMonData(&gPlayerParty[i], MON_DATA_MAX_HP);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->hpBarLevels[TRADE_PLAYER][i] = GetHPBarLevel(curHp, maxHp);
|
2018-12-24 03:03:02 -06:00
|
|
|
}
|
|
|
|
break;
|
2019-10-03 19:39:37 -04:00
|
|
|
case TRADE_PARTNER:
|
2019-10-04 07:42:45 -04:00
|
|
|
for (i = 0; i < sTradeData->partyCounts[TRADE_PARTNER]; i++)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
2018-12-28 02:11:41 -06:00
|
|
|
curHp = GetMonData(&gEnemyParty[i], MON_DATA_HP);
|
2018-12-24 03:03:02 -06:00
|
|
|
maxHp = GetMonData(&gEnemyParty[i], MON_DATA_MAX_HP);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeData->hpBarLevels[TRADE_PARTNER][i] = GetHPBarLevel(curHp, maxHp);
|
2018-12-24 03:03:02 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-03 19:39:37 -04:00
|
|
|
static void SetTradePartyHPBarSprites(void)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
|
|
|
int i, j;
|
2018-12-25 15:14:15 +01:00
|
|
|
|
2019-10-03 19:39:37 -04:00
|
|
|
for (i = 0; i < 2; i++)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
for (j = 0; j < sTradeData->partyCounts[i]; j++)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
SetPartyHPBarSprite(&gSprites[sTradeData->partySpriteIds[i][j]], 4 - sTradeData->hpBarLevels[i][j]);
|
2018-12-24 03:03:02 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807A5B0(void)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
for (i = 0; i < (int)ARRAY_COUNT(sTradeData->giftRibbons); i++)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
if (gSaveBlock1Ptr->giftRibbons[i] == 0 && sTradeData->giftRibbons[i] != 0)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
if (sTradeData->giftRibbons[i] < 64)
|
|
|
|
gSaveBlock1Ptr->giftRibbons[i] = sTradeData->giftRibbons[i];
|
2018-12-24 03:03:02 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-05 10:41:37 -04:00
|
|
|
//TODO:
|
2019-10-06 22:58:25 -04:00
|
|
|
static u32 CanTradeSelectedMon(struct Pokemon *playerParty, int partyCount, int monIdx)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
2019-10-06 22:58:25 -04:00
|
|
|
int i, numAliveMons;
|
2018-12-24 03:03:02 -06:00
|
|
|
struct LinkPlayer *player;
|
2019-10-03 19:39:37 -04:00
|
|
|
u32 species[PARTY_SIZE];
|
|
|
|
u32 species2[PARTY_SIZE];
|
2018-12-24 03:03:02 -06:00
|
|
|
|
2019-10-03 19:39:37 -04:00
|
|
|
for (i = 0; i < partyCount; i++)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
2019-10-03 19:39:37 -04:00
|
|
|
species2[i] = GetMonData(&playerParty[i], MON_DATA_SPECIES2);
|
|
|
|
species[i] = GetMonData(&playerParty[i], MON_DATA_SPECIES);
|
2018-12-24 03:03:02 -06:00
|
|
|
}
|
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
// Cant trade Eggs or non-Hoenn mons if player doesn't have National Dex
|
2018-12-24 03:03:02 -06:00
|
|
|
if (!IsNationalPokedexEnabled())
|
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
if (species2[monIdx] == SPECIES_EGG)
|
2019-10-06 22:58:25 -04:00
|
|
|
return CANT_TRADE_EGG;
|
2018-12-24 03:03:02 -06:00
|
|
|
|
2018-12-31 02:22:21 -06:00
|
|
|
if (!IsSpeciesInHoennDex(species2[monIdx]))
|
2019-10-06 22:58:25 -04:00
|
|
|
return CANT_TRADE_NATIONAL;
|
2018-12-24 03:03:02 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
player = &gLinkPlayers[GetMultiplayerId() ^ 1];
|
|
|
|
if ((player->version & 0xFF) != VERSION_RUBY &&
|
|
|
|
(player->version & 0xFF) != VERSION_SAPPHIRE)
|
|
|
|
{
|
|
|
|
if ((player->name[10] & 0xF) == 0)
|
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
if (species2[monIdx] == SPECIES_EGG)
|
2019-10-06 22:58:25 -04:00
|
|
|
return CANT_TRADE_EGG2;
|
2018-12-25 15:14:15 +01:00
|
|
|
|
2018-12-31 02:22:21 -06:00
|
|
|
if (!IsSpeciesInHoennDex(species2[monIdx]))
|
2019-10-06 22:58:25 -04:00
|
|
|
return CANT_TRADE_INVALID_MON;
|
2018-12-24 03:03:02 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 02:22:21 -06:00
|
|
|
if (species[monIdx] == SPECIES_DEOXYS || species[monIdx] == SPECIES_MEW)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
2019-10-03 19:39:37 -04:00
|
|
|
if (!GetMonData(&playerParty[monIdx], MON_DATA_OBEDIENCE))
|
2019-10-06 22:58:25 -04:00
|
|
|
return CANT_TRADE_INVALID_MON;
|
2018-12-24 03:03:02 -06:00
|
|
|
}
|
|
|
|
|
2019-10-03 19:39:37 -04:00
|
|
|
for (i = 0; i < partyCount; i++)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
|
|
|
if (species2[i] == SPECIES_EGG)
|
|
|
|
species2[i] = SPECIES_NONE;
|
|
|
|
}
|
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
// Count alive mons in party, excluding selected trade mon
|
|
|
|
for (numAliveMons = 0, i = 0; i < partyCount; i++)
|
2018-12-24 03:03:02 -06:00
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
if (i != monIdx)
|
2019-10-06 22:58:25 -04:00
|
|
|
numAliveMons += species2[i];
|
2018-12-24 03:03:02 -06:00
|
|
|
}
|
|
|
|
|
2019-10-06 22:58:25 -04:00
|
|
|
if (numAliveMons != 0)
|
|
|
|
return CAN_TRADE_MON;
|
2018-12-24 03:03:02 -06:00
|
|
|
else
|
2019-10-06 22:58:25 -04:00
|
|
|
return CANT_TRADE_LAST_MON;
|
2018-12-24 03:03:02 -06:00
|
|
|
}
|
2018-12-24 14:39:05 -06:00
|
|
|
|
2019-10-04 17:24:03 -04:00
|
|
|
// Return values are used to determine exchange status in GetLinkPlayerDataExchangeStatusTimed
|
|
|
|
// 0: EXCHANGE_COMPLETE
|
|
|
|
// 1: EXCHANGE_STAT_4
|
|
|
|
// 2: EXCHANGE_STAT_5
|
2018-12-24 14:39:05 -06:00
|
|
|
s32 sub_807A728(void)
|
|
|
|
{
|
2018-12-25 15:14:15 +01:00
|
|
|
s32 val;
|
|
|
|
u16 version;
|
|
|
|
|
2019-01-05 19:25:46 +01:00
|
|
|
if (gReceivedRemoteLinkPlayers != 0)
|
2018-12-24 14:39:05 -06:00
|
|
|
{
|
|
|
|
val = 0;
|
|
|
|
version = (gLinkPlayers[GetMultiplayerId() ^ 1].version & 0xFF);
|
2018-12-25 15:14:15 +01:00
|
|
|
|
|
|
|
if (version == VERSION_RUBY || version == VERSION_SAPPHIRE || version == VERSION_EMERALD)
|
2018-12-24 14:39:05 -06:00
|
|
|
{
|
|
|
|
// this value could actually be anything 0 or less
|
|
|
|
val = 0;
|
|
|
|
}
|
2018-12-25 15:14:15 +01:00
|
|
|
else if (version == VERSION_FIRE_RED || version == VERSION_LEAF_GREEN)
|
2018-12-24 14:39:05 -06:00
|
|
|
{
|
|
|
|
val = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (val > 0)
|
|
|
|
{
|
|
|
|
if (gLinkPlayers[GetMultiplayerId()].name[10] & 0xF0)
|
|
|
|
{
|
2019-10-04 17:24:03 -04:00
|
|
|
if (val == 2) //unnecessary check, val always 2 here
|
2018-12-24 14:39:05 -06:00
|
|
|
{
|
|
|
|
if (gLinkPlayers[GetMultiplayerId() ^ 1].name[10] & 0xF0)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2018-12-24 20:18:06 -06:00
|
|
|
|
2018-12-31 02:22:21 -06:00
|
|
|
static bool32 IsDeoxysOrMewUntradable(u16 species, bool8 isObedientBitSet)
|
2018-12-24 20:18:06 -06:00
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
if (species == SPECIES_DEOXYS || species == SPECIES_MEW)
|
2018-12-24 20:18:06 -06:00
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
if (!isObedientBitSet)
|
2018-12-24 20:18:06 -06:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-10-04 17:24:03 -04:00
|
|
|
int GetUnionRoomTradeMessageId(struct UnkLinkRfuStruct_02022B14Substruct a0, struct UnkLinkRfuStruct_02022B14Substruct a1, u16 playerSpecies2, u16 partnerSpecies, u8 requestedType, u16 playerSpecies, u8 isObedientBitSet)
|
2018-12-24 20:18:06 -06:00
|
|
|
{
|
2019-10-04 17:24:03 -04:00
|
|
|
bool8 playerHasNationalDex = a0.hasNationalDex;
|
|
|
|
bool8 playerIsChampion = a0.isChampion;
|
|
|
|
bool8 partnerHasNationalDex = a1.hasNationalDex;
|
|
|
|
bool8 partnerIsChampion = a1.isChampion;
|
2018-12-24 20:18:06 -06:00
|
|
|
u8 r1 = a1.unk_01_2;
|
|
|
|
|
|
|
|
if (r1 != 3)
|
|
|
|
{
|
2019-10-04 17:24:03 -04:00
|
|
|
if (!playerIsChampion)
|
2018-12-24 20:18:06 -06:00
|
|
|
{
|
2019-10-04 17:24:03 -04:00
|
|
|
return UR_TRADE_MSG_CANT_TRADE_WITH_PARTNER_1;
|
2018-12-24 20:18:06 -06:00
|
|
|
}
|
2019-10-04 17:24:03 -04:00
|
|
|
else if (!partnerIsChampion)
|
2018-12-24 20:18:06 -06:00
|
|
|
{
|
2019-10-04 17:24:03 -04:00
|
|
|
return UR_TRADE_MSG_CANT_TRADE_WITH_PARTNER_2;
|
2018-12-24 20:18:06 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-04 17:24:03 -04:00
|
|
|
if (IsDeoxysOrMewUntradable(playerSpecies, isObedientBitSet))
|
2018-12-24 20:18:06 -06:00
|
|
|
{
|
2019-10-04 17:24:03 -04:00
|
|
|
return UR_TRADE_MSG_MON_CANT_BE_TRADED_2;
|
2018-12-24 20:18:06 -06:00
|
|
|
}
|
|
|
|
|
2019-10-04 17:24:03 -04:00
|
|
|
if (partnerSpecies == SPECIES_EGG)
|
2018-12-24 20:18:06 -06:00
|
|
|
{
|
2019-10-04 17:24:03 -04:00
|
|
|
if (playerSpecies2 != partnerSpecies)
|
2018-12-24 20:18:06 -06:00
|
|
|
{
|
2019-10-04 17:24:03 -04:00
|
|
|
return UR_TRADE_MSG_NOT_EGG;
|
2018-12-24 20:18:06 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-04 17:24:03 -04:00
|
|
|
if (gBaseStats[playerSpecies2].type1 != requestedType && gBaseStats[playerSpecies2].type2 != requestedType)
|
2018-12-24 20:18:06 -06:00
|
|
|
{
|
2019-10-04 17:24:03 -04:00
|
|
|
return UR_TRADE_MSG_NOT_MON_PARTNER_WANTS;
|
2018-12-24 20:18:06 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-04 17:24:03 -04:00
|
|
|
if (playerSpecies2 == SPECIES_EGG && playerSpecies2 != partnerSpecies)
|
2018-12-24 20:18:06 -06:00
|
|
|
{
|
2019-10-04 17:24:03 -04:00
|
|
|
return UR_TRADE_MSG_MON_CANT_BE_TRADED_1;
|
2018-12-24 20:18:06 -06:00
|
|
|
}
|
|
|
|
|
2019-10-04 17:24:03 -04:00
|
|
|
if (!playerHasNationalDex)
|
2018-12-24 20:18:06 -06:00
|
|
|
{
|
2019-10-04 17:24:03 -04:00
|
|
|
if (playerSpecies2 == SPECIES_EGG)
|
2018-12-24 20:18:06 -06:00
|
|
|
{
|
2019-10-04 17:24:03 -04:00
|
|
|
return UR_TRADE_MSG_EGG_CANT_BE_TRADED;
|
2018-12-24 20:18:06 -06:00
|
|
|
}
|
2019-01-05 19:25:46 +01:00
|
|
|
|
2019-10-04 17:24:03 -04:00
|
|
|
if (!IsSpeciesInHoennDex(playerSpecies2))
|
2018-12-24 20:18:06 -06:00
|
|
|
{
|
2019-10-04 17:24:03 -04:00
|
|
|
return UR_TRADE_MSG_MON_CANT_BE_TRADED_2;
|
2018-12-24 20:18:06 -06:00
|
|
|
}
|
|
|
|
|
2019-10-04 17:24:03 -04:00
|
|
|
if (!IsSpeciesInHoennDex(partnerSpecies))
|
2018-12-24 20:18:06 -06:00
|
|
|
{
|
2019-10-04 17:24:03 -04:00
|
|
|
return UR_TRADE_MSG_PARTNERS_MON_CANT_BE_TRADED;
|
2018-12-24 20:18:06 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-04 17:24:03 -04:00
|
|
|
if (!partnerHasNationalDex && !IsSpeciesInHoennDex(playerSpecies2))
|
2018-12-24 20:18:06 -06:00
|
|
|
{
|
2019-10-04 17:24:03 -04:00
|
|
|
return UR_TRADE_MSG_PARTNER_CANT_ACCEPT_MON;
|
2018-12-24 20:18:06 -06:00
|
|
|
}
|
|
|
|
|
2019-10-04 17:24:03 -04:00
|
|
|
return UR_TRADE_MSG_NONE;
|
2018-12-24 20:18:06 -06:00
|
|
|
}
|
2018-12-27 02:05:09 -06:00
|
|
|
|
2019-10-04 23:31:25 -04:00
|
|
|
int CanRegisterMonForTradingBoard(struct UnkLinkRfuStruct_02022B14Substruct a0, u16 species2, u16 species, u8 isObedientBitSet)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
2019-10-04 23:31:25 -04:00
|
|
|
bool8 hasNationalDex = a0.hasNationalDex;
|
2018-12-27 02:05:09 -06:00
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
if (IsDeoxysOrMewUntradable(species, isObedientBitSet))
|
2019-10-04 23:31:25 -04:00
|
|
|
return CANT_REGISTER_MON;
|
2018-12-27 02:05:09 -06:00
|
|
|
|
2019-10-04 23:31:25 -04:00
|
|
|
if (hasNationalDex)
|
|
|
|
return CAN_REGISTER_MON;
|
2018-12-27 02:05:09 -06:00
|
|
|
|
2019-10-04 23:31:25 -04:00
|
|
|
// Eggs can only be traded if the player has the National Dex
|
2019-10-04 07:42:45 -04:00
|
|
|
if (species2 == SPECIES_EGG)
|
2019-10-04 23:31:25 -04:00
|
|
|
return CANT_REGISTER_EGG;
|
2018-12-27 02:05:09 -06:00
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
if (IsSpeciesInHoennDex(species2))
|
2019-10-04 23:31:25 -04:00
|
|
|
return CAN_REGISTER_MON;
|
2018-12-27 02:05:09 -06:00
|
|
|
|
2019-10-04 23:31:25 -04:00
|
|
|
return CANT_REGISTER_MON;
|
2018-12-27 02:05:09 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// r6/r7 flip. Ugh.
|
|
|
|
#ifdef NONMATCHING
|
2018-12-31 02:22:21 -06:00
|
|
|
int sub_807A918(struct Pokemon *mon, u16 monIdx)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
|
|
|
int i, version, versions, unk, unk2;
|
2018-12-31 02:22:21 -06:00
|
|
|
int speciesArray[PARTY_SIZE];
|
2018-12-27 02:05:09 -06:00
|
|
|
|
|
|
|
for (i = 0; i < gPlayerPartyCount; i++)
|
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
speciesArray[i] = GetMonData(&mon[i], MON_DATA_SPECIES2);
|
|
|
|
if (speciesArray[i] == SPECIES_EGG)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
speciesArray[i] = 0;
|
2018-12-27 02:05:09 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
versions = 0;
|
|
|
|
unk = 1;
|
|
|
|
for (i = 0; i < GetLinkPlayerCount(); i++)
|
|
|
|
{
|
|
|
|
version = gLinkPlayers[i].version & 0xFF;
|
|
|
|
if (version == VERSION_FIRE_RED ||
|
|
|
|
version == VERSION_LEAF_GREEN)
|
2019-01-05 19:25:46 +01:00
|
|
|
{
|
2018-12-27 02:05:09 -06:00
|
|
|
versions = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
versions |= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < GetLinkPlayerCount(); i++)
|
|
|
|
{
|
|
|
|
struct LinkPlayer *player = &gLinkPlayers[i];
|
|
|
|
if ((player->name[8] & 0xF) == 0)
|
|
|
|
{
|
|
|
|
unk = 0;
|
|
|
|
}
|
2019-01-05 19:25:46 +01:00
|
|
|
|
2018-12-27 02:05:09 -06:00
|
|
|
if (versions && (player->name[8] / 16))
|
|
|
|
{
|
|
|
|
unk = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unk == 0)
|
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
if (!IsSpeciesInHoennDex(speciesArray[monIdx]))
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
2019-01-05 19:25:46 +01:00
|
|
|
|
2018-12-31 02:22:21 -06:00
|
|
|
if (speciesArray[monIdx] == SPECIES_NONE)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unk2 = 0;
|
|
|
|
for (i = 0; i < gPlayerPartyCount; i++)
|
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
if (monIdx != i)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
unk2 += speciesArray[i];
|
2018-12-27 02:05:09 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!unk2)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
NAKED
|
2018-12-31 02:22:21 -06:00
|
|
|
int sub_807A918(struct Pokemon *mon, u16 a1)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
|
|
|
asm_unified("push {r4-r7,lr}\n\
|
|
|
|
mov r7, r8\n\
|
|
|
|
push {r7}\n\
|
|
|
|
sub sp, 0x18\n\
|
|
|
|
adds r6, r0, 0\n\
|
|
|
|
lsls r1, 16\n\
|
|
|
|
lsrs r1, 16\n\
|
|
|
|
mov r8, r1\n\
|
|
|
|
movs r5, 0\n\
|
|
|
|
ldr r0, =gPlayerPartyCount\n\
|
|
|
|
ldrb r0, [r0]\n\
|
|
|
|
cmp r5, r0\n\
|
|
|
|
bge _0807A95A\n\
|
|
|
|
mov r4, sp\n\
|
|
|
|
_0807A934:\n\
|
|
|
|
movs r0, 0x64\n\
|
|
|
|
muls r0, r5\n\
|
|
|
|
adds r0, r6, r0\n\
|
|
|
|
movs r1, 0x41\n\
|
|
|
|
bl GetMonData\n\
|
|
|
|
str r0, [r4]\n\
|
|
|
|
movs r1, 0xCE\n\
|
|
|
|
lsls r1, 1\n\
|
|
|
|
cmp r0, r1\n\
|
|
|
|
bne _0807A94E\n\
|
|
|
|
movs r0, 0\n\
|
|
|
|
str r0, [r4]\n\
|
|
|
|
_0807A94E:\n\
|
|
|
|
adds r4, 0x4\n\
|
|
|
|
adds r5, 0x1\n\
|
|
|
|
ldr r0, =gPlayerPartyCount\n\
|
|
|
|
ldrb r0, [r0]\n\
|
|
|
|
cmp r5, r0\n\
|
|
|
|
blt _0807A934\n\
|
|
|
|
_0807A95A:\n\
|
|
|
|
movs r7, 0\n\
|
|
|
|
movs r6, 0x1\n\
|
|
|
|
movs r5, 0\n\
|
|
|
|
ldr r4, =gLinkPlayers\n\
|
|
|
|
b _0807A980\n\
|
|
|
|
.pool\n\
|
|
|
|
_0807A96C:\n\
|
|
|
|
ldrb r0, [r4]\n\
|
|
|
|
subs r0, 0x4\n\
|
|
|
|
cmp r0, 0x1\n\
|
|
|
|
bhi _0807A978\n\
|
|
|
|
movs r7, 0\n\
|
|
|
|
b _0807A97C\n\
|
|
|
|
_0807A978:\n\
|
|
|
|
movs r0, 0x1\n\
|
|
|
|
orrs r7, r0\n\
|
|
|
|
_0807A97C:\n\
|
|
|
|
adds r4, 0x1C\n\
|
|
|
|
adds r5, 0x1\n\
|
|
|
|
_0807A980:\n\
|
|
|
|
bl GetLinkPlayerCount\n\
|
|
|
|
lsls r0, 24\n\
|
|
|
|
lsrs r0, 24\n\
|
|
|
|
cmp r5, r0\n\
|
|
|
|
blt _0807A96C\n\
|
|
|
|
movs r5, 0\n\
|
|
|
|
movs r4, 0\n\
|
|
|
|
b _0807A9B4\n\
|
|
|
|
_0807A992:\n\
|
|
|
|
ldr r0, =gLinkPlayers\n\
|
|
|
|
adds r2, r4, r0\n\
|
|
|
|
ldrb r1, [r2, 0x10]\n\
|
|
|
|
movs r0, 0xF\n\
|
|
|
|
ands r0, r1\n\
|
|
|
|
cmp r0, 0\n\
|
|
|
|
bne _0807A9A2\n\
|
|
|
|
movs r6, 0\n\
|
|
|
|
_0807A9A2:\n\
|
|
|
|
cmp r7, 0\n\
|
|
|
|
beq _0807A9B0\n\
|
|
|
|
ldrb r0, [r2, 0x10]\n\
|
|
|
|
lsrs r0, 4\n\
|
|
|
|
cmp r0, 0\n\
|
|
|
|
beq _0807A9B0\n\
|
|
|
|
movs r6, 0\n\
|
|
|
|
_0807A9B0:\n\
|
|
|
|
adds r4, 0x1C\n\
|
|
|
|
adds r5, 0x1\n\
|
|
|
|
_0807A9B4:\n\
|
|
|
|
bl GetLinkPlayerCount\n\
|
|
|
|
lsls r0, 24\n\
|
|
|
|
lsrs r0, 24\n\
|
|
|
|
cmp r5, r0\n\
|
|
|
|
blt _0807A992\n\
|
|
|
|
cmp r6, 0\n\
|
|
|
|
bne _0807A9EA\n\
|
|
|
|
mov r1, r8\n\
|
|
|
|
lsls r0, r1, 2\n\
|
|
|
|
mov r1, sp\n\
|
|
|
|
adds r4, r1, r0\n\
|
|
|
|
ldrh r0, [r4]\n\
|
|
|
|
bl IsSpeciesInHoennDex\n\
|
|
|
|
cmp r0, 0\n\
|
|
|
|
bne _0807A9E0\n\
|
|
|
|
movs r0, 0x2\n\
|
|
|
|
b _0807AA1A\n\
|
|
|
|
.pool\n\
|
|
|
|
_0807A9E0:\n\
|
|
|
|
ldr r0, [r4]\n\
|
|
|
|
cmp r0, 0\n\
|
|
|
|
bne _0807A9EA\n\
|
|
|
|
movs r0, 0x3\n\
|
|
|
|
b _0807AA1A\n\
|
|
|
|
_0807A9EA:\n\
|
|
|
|
movs r2, 0\n\
|
|
|
|
movs r5, 0\n\
|
|
|
|
ldr r0, =gPlayerPartyCount\n\
|
|
|
|
ldrb r0, [r0]\n\
|
|
|
|
cmp r2, r0\n\
|
|
|
|
bge _0807AA0A\n\
|
|
|
|
adds r3, r0, 0\n\
|
|
|
|
mov r1, sp\n\
|
|
|
|
_0807A9FA:\n\
|
|
|
|
cmp r8, r5\n\
|
|
|
|
beq _0807AA02\n\
|
|
|
|
ldr r0, [r1]\n\
|
|
|
|
adds r2, r0\n\
|
|
|
|
_0807AA02:\n\
|
|
|
|
adds r1, 0x4\n\
|
|
|
|
adds r5, 0x1\n\
|
|
|
|
cmp r5, r3\n\
|
|
|
|
blt _0807A9FA\n\
|
|
|
|
_0807AA0A:\n\
|
|
|
|
cmp r2, 0\n\
|
|
|
|
beq _0807AA18\n\
|
|
|
|
movs r0, 0\n\
|
|
|
|
b _0807AA1A\n\
|
|
|
|
.pool\n\
|
|
|
|
_0807AA18:\n\
|
|
|
|
movs r0, 0x1\n\
|
|
|
|
_0807AA1A:\n\
|
|
|
|
add sp, 0x18\n\
|
|
|
|
pop {r3}\n\
|
|
|
|
mov r8, r3\n\
|
|
|
|
pop {r4-r7}\n\
|
|
|
|
pop {r1}\n\
|
|
|
|
bx r1");
|
|
|
|
}
|
|
|
|
#endif // NONMATCHING
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807AA28(struct Sprite *sprite)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
|
|
|
if (++sprite->data[0] == 10)
|
|
|
|
{
|
|
|
|
PlaySE(SE_BOWA);
|
|
|
|
sprite->data[0] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807AA4C(struct Sprite *sprite)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
|
|
|
if (!sprite->invisible && ++sprite->data[0] == 10)
|
|
|
|
{
|
|
|
|
PlaySE(SE_W207B);
|
|
|
|
sprite->data[0] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807AA7C(struct Sprite *sprite)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
|
|
|
if (!sprite->data[1])
|
|
|
|
{
|
|
|
|
if (++sprite->data[0] == 12)
|
|
|
|
sprite->data[0] = 0;
|
|
|
|
|
|
|
|
LoadPalette(&gUnknown_08338EA4[sprite->data[0]], (sprite->oam.paletteNum + 16) * 16 + 4, 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807AABC(struct Sprite *sprite)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
|
|
|
sprite->data[0]++;
|
|
|
|
sprite->pos2.y++;
|
|
|
|
|
|
|
|
if (sprite->data[0] == 10)
|
|
|
|
DestroySprite(sprite);
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807AAE0(struct Sprite *sprite)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
|
|
|
sprite->data[0]++;
|
|
|
|
sprite->pos2.y--;
|
|
|
|
|
|
|
|
if (sprite->data[0] == 10)
|
|
|
|
DestroySprite(sprite);
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807AB04(struct Sprite *sprite)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
|
|
|
if (++sprite->data[0] == 15)
|
|
|
|
{
|
|
|
|
PlaySE(SE_W107);
|
|
|
|
sprite->data[0] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-05 10:41:37 -04:00
|
|
|
static void SetTradeBGAffine(void)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
|
|
|
struct BgAffineDstData affine;
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
DoBgAffineSet(&affine, sTradeWindowData->texX * 0x100, sTradeWindowData->texY * 0x100, sTradeWindowData->scrX, sTradeWindowData->scrY, sTradeWindowData->sXY, sTradeWindowData->sXY, sTradeWindowData->alpha);
|
2018-12-27 02:05:09 -06: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 10:41:37 -04:00
|
|
|
static void SetTradeGpuRegs(void)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
|
|
|
u16 dispcnt;
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
SetGpuReg(REG_OFFSET_BG1VOFS, sTradeWindowData->bg1vofs);
|
|
|
|
SetGpuReg(REG_OFFSET_BG1HOFS, sTradeWindowData->bg1hofs);
|
2018-12-27 02:05:09 -06:00
|
|
|
|
|
|
|
dispcnt = GetGpuReg(REG_OFFSET_DISPCNT);
|
2018-12-31 02:22:21 -06:00
|
|
|
if ((dispcnt & 7) == DISPCNT_MODE_0)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
SetGpuReg(REG_OFFSET_BG2VOFS, sTradeWindowData->bg2vofs);
|
|
|
|
SetGpuReg(REG_OFFSET_BG2HOFS, sTradeWindowData->bg2hofs);
|
2018-12-27 02:05:09 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-05 10:41:37 -04:00
|
|
|
SetTradeBGAffine();
|
2018-12-27 02:05:09 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-05 10:41:37 -04:00
|
|
|
static void VBlankCB_Trade(void)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
2019-10-05 10:41:37 -04:00
|
|
|
SetTradeGpuRegs();
|
2018-12-27 02:05:09 -06:00
|
|
|
LoadOam();
|
|
|
|
ProcessSpriteCopyRequests();
|
|
|
|
TransferPlttBuffer();
|
|
|
|
}
|
|
|
|
|
2019-10-05 10:41:37 -04:00
|
|
|
static void ClearLinkTimeoutCounter(void)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
2019-10-05 10:41:37 -04:00
|
|
|
sTradeWindowData->linkTimeoutCounter = 0;
|
|
|
|
sTradeWindowData->alwaysZero_88 = 0;
|
|
|
|
sTradeWindowData->alwaysZero_89 = 0;
|
2018-12-27 02:05:09 -06:00
|
|
|
}
|
|
|
|
|
2019-10-05 10:41:37 -04:00
|
|
|
static void CheckForLinkTimeout(void)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
2019-10-05 10:41:37 -04:00
|
|
|
if (sTradeWindowData->alwaysZero_88 == sTradeWindowData->alwaysZero_89)
|
|
|
|
sTradeWindowData->linkTimeoutCounter++;
|
2018-12-27 02:05:09 -06:00
|
|
|
else
|
2019-10-05 10:41:37 -04:00
|
|
|
sTradeWindowData->linkTimeoutCounter = 0;
|
2018-12-27 02:05:09 -06:00
|
|
|
|
2019-10-05 10:41:37 -04:00
|
|
|
if (sTradeWindowData->linkTimeoutCounter > LINK_TRADE_TIMEOUT)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
|
|
|
CloseLink();
|
|
|
|
SetMainCallback2(CB2_LinkError);
|
2019-10-05 10:41:37 -04:00
|
|
|
sTradeWindowData->linkTimeoutCounter = 0;
|
|
|
|
sTradeWindowData->alwaysZero_89 = 0;
|
|
|
|
sTradeWindowData->alwaysZero_88 = 0;
|
2018-12-27 02:05:09 -06:00
|
|
|
}
|
|
|
|
|
2019-10-05 10:41:37 -04:00
|
|
|
sTradeWindowData->alwaysZero_89 = sTradeWindowData->alwaysZero_88;
|
2018-12-27 02:05:09 -06:00
|
|
|
}
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
static u32 TradeGetMultiplayerId(void)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
if (gReceivedRemoteLinkPlayers)
|
2018-12-27 02:05:09 -06:00
|
|
|
return GetMultiplayerId();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-31 02:22:21 -06:00
|
|
|
static void sub_807ACFC(u8 whichParty, u8 a1)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
int pos = 0;
|
2018-12-27 02:05:09 -06:00
|
|
|
struct Pokemon *mon = NULL;
|
|
|
|
u16 species;
|
|
|
|
u32 personality;
|
|
|
|
|
2019-10-03 01:16:22 -04:00
|
|
|
if (whichParty == TRADE_PLAYER)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
2019-10-03 19:39:37 -04:00
|
|
|
mon = &gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]];
|
2018-12-31 02:22:21 -06:00
|
|
|
pos = 1;
|
2018-12-27 02:05:09 -06:00
|
|
|
}
|
|
|
|
|
2019-10-03 01:16:22 -04:00
|
|
|
if (whichParty == TRADE_PARTNER)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
2019-10-03 19:39:37 -04:00
|
|
|
mon = &gEnemyParty[gSelectedTradeMonPositions[TRADE_PARTNER] % PARTY_SIZE];
|
2018-12-31 02:22:21 -06:00
|
|
|
pos = 3;
|
2018-12-27 02:05:09 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (a1)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
species = GetMonData(mon, MON_DATA_SPECIES2);
|
|
|
|
personality = GetMonData(mon, MON_DATA_PERSONALITY);
|
|
|
|
|
2019-10-03 01:16:22 -04:00
|
|
|
if (whichParty == TRADE_PLAYER)
|
2018-12-27 02:05:09 -06:00
|
|
|
HandleLoadSpecialPokePic_2(&gMonFrontPicTable[species], gMonSpritesGfxPtr->sprites[1], species, personality);
|
|
|
|
else
|
2018-12-31 02:22:21 -06:00
|
|
|
HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[species], gMonSpritesGfxPtr->sprites[whichParty * 2 + 1], species, personality);
|
2018-12-28 02:11:41 -06:00
|
|
|
|
2018-12-27 02:05:09 -06:00
|
|
|
LoadCompressedSpritePalette(GetMonSpritePalStruct(mon));
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->monSpecies[whichParty] = species;
|
|
|
|
sTradeWindowData->monPersonalities[whichParty] = personality;
|
2018-12-27 02:05:09 -06:00
|
|
|
break;
|
|
|
|
case 1:
|
2018-12-31 02:22:21 -06:00
|
|
|
SetMultiuseSpriteTemplateToPokemon(GetMonSpritePalStruct(mon)->tag, pos);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->pokePicSpriteIdxs[whichParty] = CreateSprite(&gMultiuseSpriteTemplate, 120, 60, 6);
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[whichParty]].invisible = TRUE;
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[whichParty]].callback = SpriteCallbackDummy;
|
2018-12-27 02:05:09 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-05 10:41:37 -04:00
|
|
|
void CB2_LinkTrade(void)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
|
|
|
switch (gMain.state)
|
|
|
|
{
|
|
|
|
case 0:
|
2018-12-31 02:22:21 -06:00
|
|
|
if (!gReceivedRemoteLinkPlayers)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
|
|
|
gLinkType = 0x1144;
|
|
|
|
CloseLink();
|
|
|
|
}
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData = AllocZeroed(sizeof(*sTradeWindowData));
|
2018-12-27 02:05:09 -06:00
|
|
|
AllocateMonSpritesGfx();
|
|
|
|
ResetTasks();
|
|
|
|
ResetSpriteData();
|
|
|
|
FreeAllSpritePalettes();
|
2019-10-05 10:41:37 -04:00
|
|
|
SetVBlankCallback(VBlankCB_Trade);
|
|
|
|
InitTradeBgInternal();
|
|
|
|
ClearLinkTimeoutCounter();
|
2018-12-27 02:05:09 -06:00
|
|
|
gMain.state++;
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->neverRead_8C = 0;
|
|
|
|
sTradeWindowData->state = 0;
|
|
|
|
sTradeWindowData->isLinkTrade = TRUE;
|
|
|
|
sTradeWindowData->texX = 64;
|
|
|
|
sTradeWindowData->texY = 64;
|
|
|
|
sTradeWindowData->neverRead_D8 = 0;
|
|
|
|
sTradeWindowData->neverRead_DA = 0;
|
|
|
|
sTradeWindowData->scrX = 120;
|
|
|
|
sTradeWindowData->scrY = 80;
|
|
|
|
sTradeWindowData->sXY = 256;
|
|
|
|
sTradeWindowData->alpha = 0;
|
2018-12-27 02:05:09 -06:00
|
|
|
break;
|
|
|
|
case 1:
|
2018-12-31 02:22:21 -06:00
|
|
|
if (!gReceivedRemoteLinkPlayers)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
2019-10-05 10:41:37 -04:00
|
|
|
sTradeWindowData->isCableTrade = TRUE;
|
2018-12-27 02:05:09 -06:00
|
|
|
OpenLink();
|
|
|
|
gMain.state++;
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->timer = 0;
|
2018-12-27 02:05:09 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gMain.state = 4;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (++sTradeWindowData->timer > 60)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->timer = 0;
|
2018-12-27 02:05:09 -06:00
|
|
|
gMain.state++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (IsLinkMaster())
|
|
|
|
{
|
2019-02-10 20:42:50 -05:00
|
|
|
if (GetLinkPlayerCount_2() >= GetSavedPlayerCount())
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
if (++sTradeWindowData->timer > 30)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
2019-02-10 20:42:50 -05:00
|
|
|
CheckShouldAdvanceLinkState();
|
2018-12-27 02:05:09 -06:00
|
|
|
gMain.state++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-05 10:41:37 -04:00
|
|
|
CheckForLinkTimeout();
|
2018-12-27 02:05:09 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gMain.state++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
2019-10-05 10:41:37 -04:00
|
|
|
CheckForLinkTimeout();
|
2018-12-31 02:22:21 -06:00
|
|
|
if (gReceivedRemoteLinkPlayers == TRUE && IsLinkPlayerDataExchangeComplete() == TRUE)
|
2018-12-27 02:05:09 -06:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 5:
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_72 = 0;
|
|
|
|
sTradeWindowData->unk_73 = 0;
|
|
|
|
sTradeWindowData->unk_93 = 0;
|
2019-10-03 01:16:22 -04:00
|
|
|
sub_807ACFC(TRADE_PLAYER, 0);
|
2018-12-27 02:05:09 -06:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 6:
|
2019-10-03 01:16:22 -04:00
|
|
|
sub_807ACFC(TRADE_PLAYER, 1);
|
2018-12-27 02:05:09 -06:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 7:
|
2019-10-03 01:16:22 -04:00
|
|
|
sub_807ACFC(TRADE_PARTNER, 0);
|
2018-12-27 02:05:09 -06:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 8:
|
2019-10-03 01:16:22 -04:00
|
|
|
sub_807ACFC(TRADE_PARTNER, 1);
|
2018-12-27 02:05:09 -06:00
|
|
|
sub_807B154();
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 9:
|
2019-10-05 10:41:37 -04:00
|
|
|
LoadTradeSequenceSpriteSheetsAndPalettes();
|
|
|
|
LoadSpriteSheet(&sPokeBallSpriteSheet);
|
|
|
|
LoadSpritePalette(&sPokeBallSpritePalette);
|
2018-12-27 02:05:09 -06:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, RGB_BLACK);
|
|
|
|
ShowBg(0);
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 11:
|
|
|
|
sub_807B140();
|
2018-12-31 02:22:21 -06:00
|
|
|
SetTradeSceneStrings();
|
2018-12-27 02:05:09 -06:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 12:
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
|
|
|
if (gWirelessCommType)
|
|
|
|
{
|
2019-04-04 17:05:46 -04:00
|
|
|
LoadWirelessStatusIndicatorSpriteGfx();
|
2018-12-27 02:05:09 -06:00
|
|
|
CreateWirelessStatusIndicatorSprite(0, 0);
|
|
|
|
}
|
|
|
|
SetMainCallback2(sub_807EA2C);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
RunTasks();
|
|
|
|
RunTextPrinters();
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
|
|
|
UpdatePaletteFade();
|
|
|
|
}
|
|
|
|
|
|
|
|
void sub_807B140(void)
|
|
|
|
{
|
|
|
|
sub_807B62C(5);
|
|
|
|
sub_807B62C(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sub_807B154(void)
|
|
|
|
{
|
2019-03-02 17:25:39 -05:00
|
|
|
FillWindowPixelBuffer(0, PIXEL_FILL(15));
|
2018-12-27 02:05:09 -06:00
|
|
|
PutWindowTilemap(0);
|
|
|
|
CopyWindowToVram(0, 3);
|
|
|
|
}
|
|
|
|
|
2019-10-05 10:41:37 -04:00
|
|
|
static void InitTradeBgInternal(void)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, 0);
|
|
|
|
ResetBgsAndClearDma3BusyFlags(0);
|
2019-10-06 22:58:25 -04:00
|
|
|
InitBgsFromTemplates(0, sTradeSequenceBgTemplates, ARRAY_COUNT(sTradeSequenceBgTemplates));
|
2018-12-27 02:05:09 -06:00
|
|
|
ChangeBgX(0, 0, 0);
|
|
|
|
ChangeBgY(0, 0, 0);
|
|
|
|
SetBgTilemapBuffer(0, Alloc(0x800));
|
|
|
|
SetBgTilemapBuffer(1, Alloc(0x800));
|
|
|
|
SetBgTilemapBuffer(3, Alloc(0x800));
|
|
|
|
DeactivateAllTextPrinters();
|
|
|
|
DecompressAndLoadBgGfxUsingHeap(0, gBattleTextboxTiles, 0, 0, 0);
|
|
|
|
LZDecompressWram(gBattleTextboxTilemap, gDecompressionBuffer);
|
|
|
|
CopyToBgTilemapBuffer(0, gDecompressionBuffer, 0x800, 0);
|
|
|
|
LoadCompressedPalette(gBattleTextboxPalette, 0, 0x20);
|
2019-10-06 22:58:25 -04:00
|
|
|
InitWindows(sTradeSequenceWindowTemplates);
|
2018-12-27 02:05:09 -06:00
|
|
|
DecompressAndLoadBgGfxUsingHeap(0, gBattleTextboxTiles, 0, 0, 0);
|
|
|
|
LZDecompressWram(gBattleTextboxTilemap, gDecompressionBuffer);
|
|
|
|
CopyToBgTilemapBuffer(0, gDecompressionBuffer, 0x800, 0);
|
|
|
|
LoadCompressedPalette(gBattleTextboxPalette, 0, 0x20);
|
|
|
|
}
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
static void CB2_InGameTrade(void)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
u8 otName[11];
|
2018-12-27 02:05:09 -06:00
|
|
|
|
|
|
|
switch (gMain.state)
|
|
|
|
{
|
|
|
|
case 0:
|
2019-10-03 19:39:37 -04:00
|
|
|
gSelectedTradeMonPositions[TRADE_PLAYER] = gSpecialVar_0x8005;
|
|
|
|
gSelectedTradeMonPositions[TRADE_PARTNER] = PARTY_SIZE;
|
2018-12-27 02:05:09 -06:00
|
|
|
StringCopy(gLinkPlayers[0].name, gSaveBlock2Ptr->playerName);
|
2018-12-31 02:22:21 -06:00
|
|
|
GetMonData(&gEnemyParty[0], MON_DATA_OT_NAME, otName);
|
|
|
|
StringCopy(gLinkPlayers[1].name, otName);
|
2018-12-27 02:05:09 -06:00
|
|
|
gLinkPlayers[0].language = LANGUAGE_ENGLISH;
|
|
|
|
gLinkPlayers[1].language = GetMonData(&gEnemyParty[0], MON_DATA_LANGUAGE);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData = AllocZeroed(sizeof(*sTradeWindowData));
|
2018-12-27 02:05:09 -06:00
|
|
|
AllocateMonSpritesGfx();
|
|
|
|
ResetTasks();
|
|
|
|
ResetSpriteData();
|
|
|
|
FreeAllSpritePalettes();
|
2019-10-05 10:41:37 -04:00
|
|
|
SetVBlankCallback(VBlankCB_Trade);
|
|
|
|
InitTradeBgInternal();
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->isLinkTrade = FALSE;
|
|
|
|
sTradeWindowData->neverRead_8C = 0;
|
|
|
|
sTradeWindowData->state = 0;
|
|
|
|
sTradeWindowData->texX = 64;
|
|
|
|
sTradeWindowData->texY = 64;
|
|
|
|
sTradeWindowData->neverRead_D8 = 0;
|
|
|
|
sTradeWindowData->neverRead_DA = 0;
|
|
|
|
sTradeWindowData->scrX = 120;
|
|
|
|
sTradeWindowData->scrY = 80;
|
|
|
|
sTradeWindowData->sXY = 256;
|
|
|
|
sTradeWindowData->alpha = 0;
|
|
|
|
sTradeWindowData->timer = 0;
|
2018-12-27 02:05:09 -06:00
|
|
|
gMain.state = 5;
|
|
|
|
break;
|
|
|
|
case 5:
|
2019-10-03 01:16:22 -04:00
|
|
|
sub_807ACFC(TRADE_PLAYER, 0);
|
2018-12-27 02:05:09 -06:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 6:
|
2019-10-03 01:16:22 -04:00
|
|
|
sub_807ACFC(TRADE_PLAYER, 1);
|
2018-12-27 02:05:09 -06:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 7:
|
2019-10-03 01:16:22 -04:00
|
|
|
sub_807ACFC(TRADE_PARTNER, 0);
|
2018-12-27 02:05:09 -06:00
|
|
|
ShowBg(0);
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 8:
|
2019-10-03 01:16:22 -04:00
|
|
|
sub_807ACFC(TRADE_PARTNER, 1);
|
2019-03-02 17:25:39 -05:00
|
|
|
FillWindowPixelBuffer(0, PIXEL_FILL(15));
|
2018-12-27 02:05:09 -06:00
|
|
|
PutWindowTilemap(0);
|
|
|
|
CopyWindowToVram(0, 3);
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 9:
|
2019-10-05 10:41:37 -04:00
|
|
|
LoadTradeSequenceSpriteSheetsAndPalettes();
|
|
|
|
LoadSpriteSheet(&sPokeBallSpriteSheet);
|
|
|
|
LoadSpritePalette(&sPokeBallSpritePalette);
|
2018-12-27 02:05:09 -06:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
ShowBg(0);
|
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 11:
|
|
|
|
sub_807B62C(5);
|
|
|
|
sub_807B62C(0);
|
2018-12-31 02:22:21 -06:00
|
|
|
SetTradeSceneStrings();
|
2018-12-27 02:05:09 -06:00
|
|
|
gMain.state++;
|
|
|
|
break;
|
|
|
|
case 12:
|
|
|
|
SetMainCallback2(sub_807B60C);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
RunTasks();
|
|
|
|
RunTextPrinters();
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
|
|
|
UpdatePaletteFade();
|
|
|
|
}
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
static void UpdatePokedexForReceivedMon(u8 partyIdx)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
struct Pokemon *mon = &gPlayerParty[partyIdx];
|
2018-12-28 02:11:41 -06:00
|
|
|
|
2018-12-27 02:05:09 -06:00
|
|
|
if (!GetMonData(mon, MON_DATA_IS_EGG))
|
|
|
|
{
|
2018-12-28 02:11:41 -06:00
|
|
|
u16 species = GetMonData(mon, MON_DATA_SPECIES, NULL);
|
|
|
|
u32 personality = GetMonData(mon, MON_DATA_PERSONALITY, NULL);
|
2018-12-27 02:05:09 -06:00
|
|
|
species = SpeciesToNationalPokedexNum(species);
|
|
|
|
GetSetPokedexFlag(species, FLAG_SET_SEEN);
|
|
|
|
HandleSetPokedexFlag(species, FLAG_SET_CAUGHT, personality);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
// Functionally nop after commented code
|
|
|
|
static void EnableNationalDexFromLinkPlayer(void)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
2018-12-28 02:11:41 -06:00
|
|
|
u8 mpId = GetMultiplayerId();
|
|
|
|
// Originally in Ruby but commented out
|
|
|
|
/*if (gLinkPlayers[mpId ^ 1].lp_field_2 == 0x8000)
|
|
|
|
EnableNationalPokedex();*/
|
2018-12-27 02:05:09 -06:00
|
|
|
}
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
static void TradeMons(u8 playerPartyIdx, u8 partnerPartyIdx)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
|
|
|
u8 friendship;
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
struct Pokemon *playerMon = &gPlayerParty[playerPartyIdx];
|
2018-12-31 02:22:21 -06:00
|
|
|
u16 playerMail = GetMonData(playerMon, MON_DATA_MAIL);
|
2018-12-27 02:05:09 -06:00
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
struct Pokemon *partnerMon = &gEnemyParty[partnerPartyIdx];
|
2018-12-31 02:22:21 -06:00
|
|
|
u16 partnerMail = GetMonData(partnerMon, MON_DATA_MAIL);
|
|
|
|
|
|
|
|
if (playerMail != 0xFF)
|
|
|
|
ClearMailStruct(&gSaveBlock1Ptr->mail[playerMail]);
|
2018-12-27 02:05:09 -06:00
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->mon = *playerMon;
|
2018-12-31 02:22:21 -06:00
|
|
|
*playerMon = *partnerMon;
|
2019-10-04 07:42:45 -04:00
|
|
|
*partnerMon = sTradeWindowData->mon;
|
2018-12-27 02:05:09 -06:00
|
|
|
|
|
|
|
friendship = 70;
|
2018-12-31 02:22:21 -06:00
|
|
|
if (!GetMonData(playerMon, MON_DATA_IS_EGG))
|
|
|
|
SetMonData(playerMon, MON_DATA_FRIENDSHIP, &friendship);
|
2018-12-27 02:05:09 -06:00
|
|
|
|
2018-12-31 02:22:21 -06:00
|
|
|
if (partnerMail != 0xFF)
|
2019-10-04 07:42:45 -04:00
|
|
|
GiveMailToMon2(playerMon, &gTradeMail[partnerMail]);
|
2018-12-27 02:05:09 -06:00
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
UpdatePokedexForReceivedMon(playerPartyIdx);
|
2018-12-31 02:22:21 -06:00
|
|
|
if (gReceivedRemoteLinkPlayers)
|
2019-10-04 07:42:45 -04:00
|
|
|
EnableNationalDexFromLinkPlayer();
|
2018-12-27 02:05:09 -06:00
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807B5B8(void)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
switch (sTradeWindowData->unk_93)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
|
|
|
case 1:
|
2018-12-31 02:22:21 -06:00
|
|
|
if (IsLinkTaskFinished())
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
Trade_SendData(sTradeWindowData);
|
|
|
|
sTradeWindowData->unk_93++;
|
2018-12-27 02:05:09 -06:00
|
|
|
}
|
2018-12-31 02:22:21 -06:00
|
|
|
// fallthrough
|
2018-12-27 02:05:09 -06:00
|
|
|
case 2:
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_93 = 0;
|
2018-12-27 02:05:09 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807B60C(void)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
2019-10-05 10:41:37 -04:00
|
|
|
AnimateTradeSequence();
|
2018-12-27 02:05:09 -06:00
|
|
|
RunTasks();
|
|
|
|
RunTextPrinters();
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
|
|
|
UpdatePaletteFade();
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807B62C(u8 a0)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
|
|
|
switch (a0)
|
|
|
|
{
|
|
|
|
case 0:
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->bg2vofs = 0;
|
|
|
|
sTradeWindowData->bg2hofs = 180;
|
2018-12-27 02:05:09 -06: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);
|
|
|
|
LoadPalette(gTradeGba2_Pal, 16, 0x60);
|
|
|
|
DmaCopyLarge16(3, gTradeGba_Gfx, (void *) BG_CHAR_ADDR(1), 0x1420, 0x1000);
|
2018-12-28 02:11:41 -06:00
|
|
|
DmaCopy16Defvars(3, gUnknown_08331F60, (void *) BG_SCREEN_ADDR(18), 0x1000);
|
2018-12-27 02:05:09 -06:00
|
|
|
break;
|
|
|
|
case 1:
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->bg1hofs = 0;
|
|
|
|
sTradeWindowData->bg1vofs = 348;
|
2018-12-27 02:05:09 -06: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);
|
2019-01-05 19:25:46 +01:00
|
|
|
|
2019-10-05 10:41:37 -04:00
|
|
|
if (sTradeWindowData->isCableTrade)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
DmaCopy16Defvars(3, sTradeTilemap_GbaCable, (void *) BG_SCREEN_ADDR(5), 0x1000);
|
2018-12-27 02:05:09 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
DmaCopy16Defvars(3, sTradeTilemap_GbaWireless, (void *) BG_SCREEN_ADDR(5), 0x1000);
|
2018-12-27 02:05:09 -06: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:
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->bg1vofs = 0;
|
|
|
|
sTradeWindowData->bg1hofs = 0;
|
2019-10-05 10:41:37 -04:00
|
|
|
if (!sTradeWindowData->isCableTrade)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_1 |
|
|
|
|
DISPCNT_OBJ_1D_MAP |
|
|
|
|
DISPCNT_BG1_ON |
|
|
|
|
DISPCNT_OBJ_ON);
|
|
|
|
LZ77UnCompVram(gUnknown_083379A0, (void *) BG_SCREEN_ADDR(5));
|
|
|
|
BlendPalettes(0x8, 16, RGB_BLACK);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_1 |
|
|
|
|
DISPCNT_OBJ_1D_MAP |
|
|
|
|
DISPCNT_BG1_ON |
|
|
|
|
DISPCNT_OBJ_ON);
|
2019-10-03 19:39:37 -04:00
|
|
|
DmaCopy16Defvars(3, sTradeTilemap_Cable, (void *) BG_SCREEN_ADDR(5), 0x800);
|
2018-12-27 02:05:09 -06:00
|
|
|
BlendPalettes(0x1, 16, RGB_BLACK);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
2019-10-03 19:39:37 -04:00
|
|
|
LoadPalette(sTradePal_Black, 48, 0x20);
|
|
|
|
LZ77UnCompVram(sTradeGfx_WirelessSignal, (void *) BG_CHAR_ADDR(1));
|
|
|
|
LZ77UnCompVram(sTradeTilemap_WirelessSignal, (void *) BG_SCREEN_ADDR(18));
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->bg2vofs = 80;
|
2018-12-27 02:05:09 -06: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);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->texX = 64;
|
|
|
|
sTradeWindowData->texY = 92;
|
|
|
|
sTradeWindowData->sXY = 32;
|
|
|
|
sTradeWindowData->unk_EA = 1024;
|
|
|
|
sTradeWindowData->alpha = 0;
|
2018-12-27 02:05:09 -06:00
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
DmaCopyLarge16(3, sTradeAffine_Gba, (void *) BG_CHAR_ADDR(1), 0x2840, 0x1000);
|
2019-01-05 19:25:46 +01:00
|
|
|
|
2019-10-05 10:41:37 -04:00
|
|
|
if (sTradeWindowData->isCableTrade)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
DmaCopy16Defvars(3, sTradeAffineMap_GbaCable, (void *) BG_SCREEN_ADDR(18), 0x100);
|
2018-12-27 02:05:09 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
DmaCopy16Defvars(3, sTradeAffineMap_GbaWireless, (void *) BG_SCREEN_ADDR(18), 0x100);
|
2018-12-27 02:05:09 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 5:
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->bg1vofs = 0;
|
|
|
|
sTradeWindowData->bg1hofs = 0;
|
2018-12-27 02:05:09 -06: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);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->texX = 64;
|
|
|
|
sTradeWindowData->texY = 92;
|
|
|
|
sTradeWindowData->sXY = 256;
|
|
|
|
sTradeWindowData->unk_EA = 128;
|
|
|
|
sTradeWindowData->scrX = 120;
|
|
|
|
sTradeWindowData->scrY = 80;
|
|
|
|
sTradeWindowData->alpha = 0;
|
2018-12-27 02:05:09 -06:00
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
DmaCopyLarge16(3, sTradeAffine_Gba, (void *) BG_CHAR_ADDR(1), 0x2840, 0x1000);
|
2019-01-05 19:25:46 +01:00
|
|
|
|
2019-10-05 10:41:37 -04:00
|
|
|
if (sTradeWindowData->isCableTrade)
|
2018-12-27 02:05:09 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
DmaCopy16Defvars(3, sTradeAffineMap_GbaCable, (void *) BG_SCREEN_ADDR(18), 0x100);
|
2018-12-27 02:05:09 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
DmaCopy16Defvars(3, sTradeAffineMap_GbaWireless, (void *) BG_SCREEN_ADDR(18), 0x100);
|
2018-12-27 02:05:09 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 7:
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->bg2vofs = 0;
|
|
|
|
sTradeWindowData->bg2hofs = 0;
|
2018-12-27 02:05:09 -06:00
|
|
|
SetGpuReg(REG_OFFSET_BLDCNT, 0);
|
|
|
|
SetGpuReg(REG_OFFSET_BG2CNT, BGCNT_PRIORITY(2) |
|
|
|
|
BGCNT_CHARBASE(1) |
|
|
|
|
BGCNT_16COLOR |
|
|
|
|
BGCNT_SCREENBASE(18) |
|
|
|
|
BGCNT_TXT512x256);
|
|
|
|
LoadPalette(gTradeGba2_Pal, 16, 0x60);
|
|
|
|
DmaCopyLarge16(3, gTradeGba_Gfx, (void *) BG_CHAR_ADDR(1), 0x1420, 0x1000);
|
2018-12-28 02:11:41 -06:00
|
|
|
DmaCopy16Defvars(3, gUnknown_08331F60, (void *) BG_SCREEN_ADDR(18), 0x1000);
|
2018-12-27 02:05:09 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-12-28 02:11:41 -06:00
|
|
|
|
2019-10-05 10:41:37 -04:00
|
|
|
static void LoadTradeSequenceSpriteSheetsAndPalettes(void)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
2019-10-05 10:41:37 -04:00
|
|
|
LoadSpriteSheet(&sGlow1SpriteSheet);
|
|
|
|
LoadSpriteSheet(&sGlow2SpriteSheet);
|
|
|
|
LoadSpriteSheet(&sCableEndSpriteSheet);
|
|
|
|
LoadSpriteSheet(&sGbaScreenSpriteSheet);
|
|
|
|
LoadSpritePalette(&sMiscTradeSpritePalette);
|
|
|
|
LoadSpritePalette(&sGbaSpritePalette);
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
|
2019-10-03 01:16:22 -04:00
|
|
|
/// Buffers "[Pokemon] will be sent to [Trainer]" strings
|
2018-12-31 02:22:21 -06:00
|
|
|
static void SetTradeSceneStrings(void)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
|
|
|
u8 mpId;
|
|
|
|
u8 name[20];
|
|
|
|
const struct InGameTrade *ingameTrade;
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
if (sTradeWindowData->isLinkTrade)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
|
|
|
mpId = GetMultiplayerId();
|
|
|
|
StringCopy(gStringVar1, gLinkPlayers[mpId ^ 1].name);
|
2019-10-03 19:39:37 -04:00
|
|
|
GetMonData(&gEnemyParty[gSelectedTradeMonPositions[TRADE_PARTNER] % PARTY_SIZE], MON_DATA_NICKNAME, name);
|
2018-12-28 02:11:41 -06:00
|
|
|
StringCopy10(gStringVar3, name);
|
2019-10-03 19:39:37 -04:00
|
|
|
GetMonData(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], MON_DATA_NICKNAME, name);
|
2018-12-28 02:11:41 -06:00
|
|
|
StringCopy10(gStringVar2, name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-03 01:16:22 -04:00
|
|
|
ingameTrade = &sIngameTrades[gSpecialVar_0x8004];
|
2018-12-28 02:11:41 -06:00
|
|
|
StringCopy(gStringVar1, ingameTrade->otName);
|
2019-10-03 01:16:22 -04:00
|
|
|
StringCopy10(gStringVar3, ingameTrade->nickname);
|
2018-12-28 02:11:41 -06:00
|
|
|
GetMonData(&gPlayerParty[gSpecialVar_0x8005], MON_DATA_NICKNAME, name);
|
|
|
|
StringCopy10(gStringVar2, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-05 10:41:37 -04:00
|
|
|
// returns TRUE if it was a link trade, FALSE if it was an in-game trade
|
|
|
|
static bool8 AnimateTradeSequence(void)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
2019-10-05 10:41:37 -04:00
|
|
|
if (sTradeWindowData->isCableTrade)
|
|
|
|
return AnimateTradeSequenceCable();
|
2018-12-28 02:11:41 -06:00
|
|
|
else
|
2019-10-05 10:41:37 -04:00
|
|
|
return AnimateTradeSequenceWireless();
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
|
2019-10-05 10:41:37 -04:00
|
|
|
static bool8 AnimateTradeSequenceCable(void)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
|
|
|
u16 evoTarget;
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
switch (sTradeWindowData->state)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
|
|
|
case 0:
|
2019-10-04 07:42:45 -04:00
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].invisible = FALSE;
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.x = -180;
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.y = gMonFrontPicCoords[sTradeWindowData->monSpecies[TRADE_PLAYER]].y_offset;
|
|
|
|
sTradeWindowData->state++;
|
|
|
|
sTradeWindowData->cachedMapMusic = GetCurrentMapMusic();
|
2018-12-28 02:11:41 -06:00
|
|
|
PlayNewMapMusic(MUS_SHINKA);
|
|
|
|
break;
|
|
|
|
case 1:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (sTradeWindowData->bg2hofs > 0)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.x += 3;
|
|
|
|
sTradeWindowData->bg2hofs -= 3;
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.x = 0;
|
|
|
|
sTradeWindowData->bg2hofs = 0;
|
|
|
|
sTradeWindowData->state = 10;
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
StringExpandPlaceholders(gStringVar4, gText_XWillBeSentToY);
|
2019-10-03 19:39:37 -04:00
|
|
|
DrawTextOnTradeWindow(0, gStringVar4, 0);
|
2018-12-28 02:11:41 -06:00
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
if (sTradeWindowData->monSpecies[TRADE_PLAYER] != SPECIES_EGG)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
PlayCry1(sTradeWindowData->monSpecies[TRADE_PLAYER], 0);
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state = 11;
|
|
|
|
sTradeWindowData->timer = 0;
|
2018-12-28 02:11:41 -06:00
|
|
|
break;
|
|
|
|
case 11:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (++sTradeWindowData->timer == 80)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_D2 = sub_807671C(sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER], gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].oam.paletteNum, 120, 32, 2, 1, 0x14, 0xfffff);
|
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
StringExpandPlaceholders(gStringVar4, gText_ByeByeVar1);
|
2019-10-03 19:39:37 -04:00
|
|
|
DrawTextOnTradeWindow(0, gStringVar4, 0);
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 12:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (gSprites[sTradeWindowData->unk_D2].callback == SpriteCallbackDummy)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_D3 = CreateSprite(&gSpriteTemplate_8338D28, 120, 32, 0);
|
|
|
|
gSprites[sTradeWindowData->unk_D3].callback = sub_807E5D8;
|
|
|
|
DestroySprite(&gSprites[sTradeWindowData->unk_D2]);
|
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
break;
|
2018-12-28 13:42:34 -06:00
|
|
|
case 13:
|
2018-12-28 02:11:41 -06:00
|
|
|
// The game waits here for the sprite to finish its animation sequence.
|
2018-12-28 13:42:34 -06:00
|
|
|
break;
|
2018-12-28 02:11:41 -06:00
|
|
|
case 14:
|
|
|
|
BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state = 20;
|
2018-12-28 02:11:41 -06:00
|
|
|
break;
|
|
|
|
case 20:
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
|
|
|
sub_807B62C(4);
|
2019-03-02 17:25:39 -05:00
|
|
|
FillWindowPixelBuffer(0, PIXEL_FILL(15));
|
2018-12-28 02:11:41 -06:00
|
|
|
CopyWindowToVram(0, 3);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 21:
|
|
|
|
BeginNormalPaletteFade(0xFFFFFFFF, -1, 16, 0, RGB_BLACK);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
break;
|
|
|
|
case 22:
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state = 23;
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 23:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (sTradeWindowData->unk_EA > 0x100)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_EA -= 0x34;
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sub_807B62C(1);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_EA = 0x80;
|
|
|
|
sTradeWindowData->state++;
|
|
|
|
sTradeWindowData->timer = 0;
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->sXY = 0x8000 / sTradeWindowData->unk_EA;
|
2018-12-28 02:11:41 -06:00
|
|
|
break;
|
|
|
|
case 24:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (++sTradeWindowData->timer > 20)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
2019-10-05 10:41:37 -04:00
|
|
|
SetTradeBGAffine();
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_91 = CreateSprite(&gSpriteTemplate_8338E74, 120, 80, 0);
|
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 25:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (gSprites[sTradeWindowData->unk_91].animEnded)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
DestroySprite(&gSprites[sTradeWindowData->unk_91]);
|
2018-12-28 02:11:41 -06:00
|
|
|
SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_EFFECT_BLEND |
|
|
|
|
BLDCNT_TGT2_BG1 |
|
|
|
|
BLDCNT_TGT2_BG2);
|
|
|
|
SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(12, 4));
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 26:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (--sTradeWindowData->bg1vofs == 316)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
2019-10-04 07:42:45 -04:00
|
|
|
if (sTradeWindowData->bg1vofs == 328)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_92 = CreateSprite(&gSpriteTemplate_8338DFC, 128, 65, 0);
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 27:
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_90 = CreateSprite(&gUnknown_08338D88, 128, 80, 3);
|
|
|
|
sTradeWindowData->unk_91 = CreateSprite(&gSpriteTemplate_8338DC8, 128, 80, 0);
|
|
|
|
StartSpriteAnim(&gSprites[sTradeWindowData->unk_91], 1);
|
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
break;
|
|
|
|
case 28:
|
2019-10-04 07:42:45 -04:00
|
|
|
if ((sTradeWindowData->bg1vofs -= 2) == 166)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state = 200;
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_1 |
|
|
|
|
DISPCNT_OBJ_1D_MAP |
|
|
|
|
DISPCNT_BG1_ON |
|
|
|
|
DISPCNT_OBJ_ON);
|
|
|
|
break;
|
|
|
|
case 200:
|
2019-10-04 07:42:45 -04:00
|
|
|
gSprites[sTradeWindowData->unk_90].pos1.y -= 2;
|
|
|
|
gSprites[sTradeWindowData->unk_91].pos1.y -= 2;
|
|
|
|
if (gSprites[sTradeWindowData->unk_90].pos1.y < -8)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state = 29;
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 29:
|
|
|
|
BeginNormalPaletteFade(0xFFFFFFFF, -1, 0, 16, RGB_BLACK);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state = 30;
|
2018-12-28 02:11:41 -06:00
|
|
|
break;
|
|
|
|
case 30:
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
DestroySprite(&gSprites[sTradeWindowData->unk_90]);
|
|
|
|
DestroySprite(&gSprites[sTradeWindowData->unk_91]);
|
2018-12-28 02:11:41 -06:00
|
|
|
sub_807B62C(2);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 31:
|
|
|
|
BeginNormalPaletteFade(0xFFFFFFFF, -1, 16, 0, RGB_BLACK);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_90 = CreateSprite(&gSpriteTemplate_8338DC8, 111, 170, 0);
|
|
|
|
sTradeWindowData->unk_91 = CreateSprite(&gSpriteTemplate_8338DC8, 129, -10, 0);
|
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
break;
|
|
|
|
case 32:
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
|
|
|
PlaySE(SE_TK_WARPOUT);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
2019-10-04 07:42:45 -04:00
|
|
|
gSprites[sTradeWindowData->unk_90].pos2.y -= 3;
|
|
|
|
gSprites[sTradeWindowData->unk_91].pos2.y += 3;
|
2018-12-28 02:11:41 -06:00
|
|
|
break;
|
|
|
|
case 33:
|
2019-10-04 07:42:45 -04:00
|
|
|
gSprites[sTradeWindowData->unk_90].pos2.y -= 3;
|
|
|
|
gSprites[sTradeWindowData->unk_91].pos2.y += 3;
|
|
|
|
if (gSprites[sTradeWindowData->unk_90].pos2.y <= -90)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
gSprites[sTradeWindowData->unk_90].data[1] = 1;
|
|
|
|
gSprites[sTradeWindowData->unk_91].data[1] = 1;
|
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 34:
|
|
|
|
BlendPalettes(0x1, 16, RGB_WHITEALPHA);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
break;
|
|
|
|
case 35:
|
|
|
|
BlendPalettes(0x1, 0, RGB_WHITEALPHA);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
break;
|
|
|
|
case 36:
|
|
|
|
BlendPalettes(0x1, 16, RGB_WHITEALPHA);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
break;
|
|
|
|
case 37:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (!IsMonSpriteNotFlipped(sTradeWindowData->monSpecies[TRADE_PLAYER]))
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].affineAnims = gSpriteAffineAnimTable_8338ECC;
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].oam.affineMode = 3;
|
|
|
|
CalcCenterToCornerVec(&gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]], 0, 3, 3);
|
|
|
|
StartSpriteAffineAnim(&gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]], 0);
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
StartSpriteAffineAnim(&gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]], 0);
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
2019-10-04 07:42:45 -04:00
|
|
|
StartSpriteAffineAnim(&gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PARTNER]], 0);
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].pos1.x = 60;
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PARTNER]].pos1.x = 180;
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].pos1.y = 192;
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PARTNER]].pos1.y = -32;
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].invisible = FALSE;
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PARTNER]].invisible = FALSE;
|
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
break;
|
|
|
|
case 38:
|
2019-10-04 07:42:45 -04:00
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.y -= 3;
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PARTNER]].pos2.y += 3;
|
|
|
|
if (gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.y < -160 && gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.y >= -163)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
|
|
|
PlaySE(SE_TK_WARPIN);
|
|
|
|
}
|
2019-10-04 07:42:45 -04:00
|
|
|
if (gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.y < -222)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
gSprites[sTradeWindowData->unk_90].data[1] = 0;
|
|
|
|
gSprites[sTradeWindowData->unk_91].data[1] = 0;
|
|
|
|
sTradeWindowData->state++;
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].invisible = TRUE;
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PARTNER]].invisible = TRUE;
|
2018-12-28 02:11:41 -06:00
|
|
|
BlendPalettes(0x1, 0, RGB_WHITEALPHA);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 39:
|
2019-10-04 07:42:45 -04:00
|
|
|
gSprites[sTradeWindowData->unk_90].pos2.y -= 3;
|
|
|
|
gSprites[sTradeWindowData->unk_91].pos2.y += 3;
|
|
|
|
if (gSprites[sTradeWindowData->unk_90].pos2.y <= -222)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
|
|
|
BeginNormalPaletteFade(0xFFFFFFFF, -1, 0, 16, RGB_BLACK);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
|
|
|
DestroySprite(&gSprites[sTradeWindowData->unk_90]);
|
|
|
|
DestroySprite(&gSprites[sTradeWindowData->unk_91]);
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 40:
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
sub_807B62C(1);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->bg1vofs = 166;
|
|
|
|
sTradeWindowData->unk_90 = CreateSprite(&gUnknown_08338D88, 128, -20, 3);
|
|
|
|
sTradeWindowData->unk_91 = CreateSprite(&gSpriteTemplate_8338DC8, 128, -20, 0);
|
|
|
|
StartSpriteAnim(&gSprites[sTradeWindowData->unk_91], 1);
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 41:
|
|
|
|
BeginNormalPaletteFade(0xFFFFFFFF, -1, 16, 0, RGB_BLACK);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
break;
|
|
|
|
case 42:
|
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 |
|
|
|
|
DISPCNT_OBJ_1D_MAP |
|
|
|
|
DISPCNT_BG1_ON |
|
|
|
|
DISPCNT_OBJ_ON);
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 43:
|
2019-10-04 07:42:45 -04:00
|
|
|
gSprites[sTradeWindowData->unk_90].pos2.y += 3;
|
|
|
|
gSprites[sTradeWindowData->unk_91].pos2.y += 3;
|
|
|
|
if (gSprites[sTradeWindowData->unk_90].pos2.y + gSprites[sTradeWindowData->unk_90].pos1.y == 64)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 44:
|
2019-10-04 07:42:45 -04:00
|
|
|
if ((sTradeWindowData->bg1vofs += 2) > 316)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->bg1vofs = 316;
|
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 45:
|
2019-10-04 07:42:45 -04:00
|
|
|
DestroySprite(&gSprites[sTradeWindowData->unk_90]);
|
|
|
|
DestroySprite(&gSprites[sTradeWindowData->unk_91]);
|
|
|
|
sTradeWindowData->state++;
|
|
|
|
sTradeWindowData->timer = 0;
|
2018-12-28 02:11:41 -06:00
|
|
|
break;
|
|
|
|
case 46:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (++sTradeWindowData->timer == 10)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 47:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (++sTradeWindowData->bg1vofs > 348)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->bg1vofs = 348;
|
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
2019-10-05 10:41:37 -04:00
|
|
|
if (sTradeWindowData->bg1vofs == 328 && sTradeWindowData->isCableTrade)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_92 = CreateSprite(&gSpriteTemplate_8338DFC, 128, 65, 0);
|
|
|
|
gSprites[sTradeWindowData->unk_92].callback = sub_807AAE0;
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 48:
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_91 = CreateSprite(&gSpriteTemplate_8338E74, 120, 80, 0);
|
|
|
|
sTradeWindowData->state = 50;
|
2018-12-28 02:11:41 -06:00
|
|
|
break;
|
|
|
|
case 50:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (gSprites[sTradeWindowData->unk_91].animEnded)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
DestroySprite(&gSprites[sTradeWindowData->unk_91]);
|
2018-12-28 02:11:41 -06:00
|
|
|
sub_807B62C(6);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
PlaySE(SE_W028);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 51:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (sTradeWindowData->unk_EA < 0x400)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_EA += 0x34;
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_EA = 0x400;
|
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->sXY = 0x8000 / sTradeWindowData->unk_EA;
|
2018-12-28 02:11:41 -06:00
|
|
|
break;
|
|
|
|
case 52:
|
|
|
|
BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state = 60;
|
2018-12-28 02:11:41 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 60:
|
|
|
|
if (!gPaletteFade.active)
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
|
|
|
sub_807B62C(5);
|
|
|
|
sub_807B62C(7);
|
|
|
|
gPaletteFade.bufferTransferDisabled = TRUE;
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 61:
|
|
|
|
gPaletteFade.bufferTransferDisabled = FALSE;
|
|
|
|
BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, RGB_BLACK);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
break;
|
|
|
|
case 62:
|
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 |
|
|
|
|
DISPCNT_OBJ_1D_MAP |
|
|
|
|
DISPCNT_BG2_ON |
|
|
|
|
DISPCNT_OBJ_ON);
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 63:
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_D3 = CreateSprite(&gSpriteTemplate_8338D28, 120, -8, 0);
|
|
|
|
gSprites[sTradeWindowData->unk_D3].data[3] = 74;
|
|
|
|
gSprites[sTradeWindowData->unk_D3].callback = sub_807E6AC;
|
|
|
|
StartSpriteAnim(&gSprites[sTradeWindowData->unk_D3], 1);
|
|
|
|
StartSpriteAffineAnim(&gSprites[sTradeWindowData->unk_D3], 2);
|
|
|
|
BlendPalettes(1 << (16 + gSprites[sTradeWindowData->unk_D3].oam.paletteNum), 16, RGB_WHITEALPHA);
|
|
|
|
sTradeWindowData->state++;
|
|
|
|
sTradeWindowData->timer = 0;
|
2018-12-28 13:42:34 -06:00
|
|
|
break;
|
|
|
|
case 64:
|
2019-10-04 07:42:45 -04:00
|
|
|
BeginNormalPaletteFade(1 << (16 + gSprites[sTradeWindowData->unk_D3].oam.paletteNum), 1, 16, 0, RGB_WHITEALPHA);
|
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
break;
|
|
|
|
case 65:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (gSprites[sTradeWindowData->unk_D3].callback == SpriteCallbackDummy)
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
HandleLoadSpecialPokePic_2(&gMonFrontPicTable[sTradeWindowData->monSpecies[TRADE_PARTNER]], gMonSpritesGfxPtr->sprites[3], sTradeWindowData->monSpecies[TRADE_PARTNER], sTradeWindowData->monPersonalities[TRADE_PARTNER]);
|
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 66:
|
2019-10-04 07:42:45 -04:00
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PARTNER]].pos1.x = 120;
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PARTNER]].pos1.y = gMonFrontPicCoords[sTradeWindowData->monSpecies[TRADE_PARTNER]].y_offset + 60;
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PARTNER]].pos2.x = 0;
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PARTNER]].pos2.y = 0;
|
|
|
|
StartSpriteAnim(&gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PARTNER]], 0);
|
|
|
|
CreatePokeballSpriteToReleaseMon(sTradeWindowData->pokePicSpriteIdxs[TRADE_PARTNER], gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PARTNER]].oam.paletteNum, 120, 84, 2, 1, 20, 0xFFFFF, sTradeWindowData->monSpecies[TRADE_PARTNER]);
|
|
|
|
FreeSpriteOamMatrix(&gSprites[sTradeWindowData->unk_D3]);
|
|
|
|
DestroySprite(&gSprites[sTradeWindowData->unk_D3]);
|
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
break;
|
|
|
|
case 67:
|
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 |
|
|
|
|
DISPCNT_OBJ_1D_MAP |
|
|
|
|
DISPCNT_BG0_ON |
|
|
|
|
DISPCNT_BG2_ON |
|
|
|
|
DISPCNT_OBJ_ON);
|
|
|
|
StringExpandPlaceholders(gStringVar4, gText_XSentOverY);
|
2019-10-03 19:39:37 -04:00
|
|
|
DrawTextOnTradeWindow(0, gStringVar4, 0);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state = 167;
|
|
|
|
sTradeWindowData->timer = 0;
|
2018-12-28 13:42:34 -06:00
|
|
|
break;
|
|
|
|
// 167 and 267 are extra cases added in for animations
|
|
|
|
case 167:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (++sTradeWindowData->timer > 60)
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state = 267;
|
|
|
|
sTradeWindowData->timer = 0;
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 267:
|
|
|
|
if (IsCryFinished())
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state = 68;
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 68:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (++sTradeWindowData->timer == 10)
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
|
|
|
PlayFanfare(MUS_FANFA5);
|
|
|
|
}
|
2019-10-04 07:42:45 -04:00
|
|
|
if (sTradeWindowData->timer == 250)
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
StringExpandPlaceholders(gStringVar4, gText_TakeGoodCareOfX);
|
2019-10-03 19:39:37 -04:00
|
|
|
DrawTextOnTradeWindow(0, gStringVar4, 0);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->timer = 0;
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 69:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (++sTradeWindowData->timer == 60)
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 70:
|
2019-10-03 19:39:37 -04:00
|
|
|
CheckPartnersMonForRibbons();
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
break;
|
|
|
|
case 71:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (sTradeWindowData->isLinkTrade)
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else if (gMain.newKeys & A_BUTTON)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 72: // Only if in-game trade
|
2019-10-04 07:42:45 -04:00
|
|
|
TradeMons(gSpecialVar_0x8005, 0);
|
2018-12-28 13:42:34 -06:00
|
|
|
gCB2_AfterEvolution = sub_807B60C;
|
2019-10-03 19:39:37 -04:00
|
|
|
evoTarget = GetEvolutionTargetSpecies(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], TRUE, ITEM_NONE);
|
2018-12-28 13:42:34 -06:00
|
|
|
if (evoTarget != SPECIES_NONE)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
TradeEvolutionScene(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], evoTarget, sTradeWindowData->pokePicSpriteIdxs[TRADE_PARTNER], gSelectedTradeMonPositions[TRADE_PLAYER]);
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
break;
|
|
|
|
case 73:
|
|
|
|
BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
break;
|
|
|
|
case 74:
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
PlayNewMapMusic(sTradeWindowData->cachedMapMusic);
|
|
|
|
if (sTradeWindowData)
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
|
|
|
FreeAllWindowBuffers();
|
|
|
|
Free(GetBgTilemapBuffer(3));
|
|
|
|
Free(GetBgTilemapBuffer(1));
|
|
|
|
Free(GetBgTilemapBuffer(0));
|
|
|
|
FreeMonSpritesGfx();
|
2019-10-04 07:42:45 -04:00
|
|
|
FREE_AND_SET_NULL(sTradeWindowData);
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
SetMainCallback2(CB2_ReturnToField);
|
2019-10-05 10:41:37 -04:00
|
|
|
BuffeInGameTradeMonName();
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-10-05 10:41:37 -04:00
|
|
|
static bool8 AnimateTradeSequenceWireless(void)
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
|
|
|
u16 evoTarget;
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
switch (sTradeWindowData->state)
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
|
|
|
case 0:
|
2019-10-04 07:42:45 -04:00
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].invisible = FALSE;
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.x = -180;
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.y = gMonFrontPicCoords[sTradeWindowData->monSpecies[TRADE_PLAYER]].y_offset;
|
|
|
|
sTradeWindowData->state++;
|
|
|
|
sTradeWindowData->cachedMapMusic = GetCurrentMapMusic();
|
2018-12-28 13:42:34 -06:00
|
|
|
PlayNewMapMusic(MUS_SHINKA);
|
|
|
|
break;
|
|
|
|
case 1:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (sTradeWindowData->bg2hofs > 0)
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.x += 3;
|
|
|
|
sTradeWindowData->bg2hofs -= 3;
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.x = 0;
|
|
|
|
sTradeWindowData->bg2hofs = 0;
|
|
|
|
sTradeWindowData->state = 10;
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
StringExpandPlaceholders(gStringVar4, gText_XWillBeSentToY);
|
2019-10-03 19:39:37 -04:00
|
|
|
DrawTextOnTradeWindow(0, gStringVar4, 0);
|
2018-12-28 13:42:34 -06:00
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
if (sTradeWindowData->monSpecies[TRADE_PLAYER] != SPECIES_EGG)
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
PlayCry1(sTradeWindowData->monSpecies[TRADE_PLAYER], 0);
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state = 11;
|
|
|
|
sTradeWindowData->timer = 0;
|
2018-12-28 13:42:34 -06:00
|
|
|
break;
|
|
|
|
case 11:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (++sTradeWindowData->timer == 80)
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_D2 = sub_807671C(sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER], gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].oam.paletteNum, 120, 32, 2, 1, 0x14, 0xfffff);
|
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
StringExpandPlaceholders(gStringVar4, gText_ByeByeVar1);
|
2019-10-03 19:39:37 -04:00
|
|
|
DrawTextOnTradeWindow(0, gStringVar4, 0);
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 12:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (gSprites[sTradeWindowData->unk_D2].callback == SpriteCallbackDummy)
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_D3 = CreateSprite(&gSpriteTemplate_8338D28, 120, 32, 0);
|
|
|
|
gSprites[sTradeWindowData->unk_D3].callback = sub_807E5D8;
|
|
|
|
DestroySprite(&gSprites[sTradeWindowData->unk_D2]);
|
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 13:
|
|
|
|
// The game waits here for the sprite to finish its animation sequence.
|
|
|
|
break;
|
|
|
|
case 14:
|
|
|
|
BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state = 20;
|
2018-12-28 13:42:34 -06:00
|
|
|
break;
|
|
|
|
case 20:
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
|
|
|
sub_807B62C(4);
|
2019-03-02 17:25:39 -05:00
|
|
|
FillWindowPixelBuffer(0, PIXEL_FILL(15));
|
2018-12-28 13:42:34 -06:00
|
|
|
CopyWindowToVram(0, 3);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 21:
|
|
|
|
BeginNormalPaletteFade(0xFFFFFFFF, -1, 16, 0, RGB_BLACK);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
break;
|
|
|
|
case 22:
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state = 23;
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 23:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (sTradeWindowData->unk_EA > 0x100)
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_EA -= 0x34;
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sub_807B62C(1);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_EA = 0x80;
|
|
|
|
sTradeWindowData->state = 124;
|
|
|
|
sTradeWindowData->timer = 0;
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->sXY = 0x8000 / sTradeWindowData->unk_EA;
|
2018-12-28 13:42:34 -06:00
|
|
|
break;
|
|
|
|
case 124:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (++sTradeWindowData->timer > 20)
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
|
|
|
sub_807B62C(3);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_91 = CreateSprite(&gSpriteTemplate_8338E8C, 120, 80, 0);
|
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 125:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (gSprites[sTradeWindowData->unk_91].animEnded)
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
DestroySprite(&gSprites[sTradeWindowData->unk_91]);
|
2018-12-28 13:42:34 -06: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));
|
|
|
|
CreateTask(c3_08054588, 5);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 126:
|
|
|
|
if (!FuncIsActiveTask(c3_08054588))
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state = 26;
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 26:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (--sTradeWindowData->bg1vofs == 316)
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 27:
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_90 = CreateSprite(&gUnknown_08338D88, 120, 80, 3);
|
|
|
|
gSprites[sTradeWindowData->unk_90].callback = sub_807AA4C;
|
|
|
|
sTradeWindowData->unk_91 = CreateSprite(&gSpriteTemplate_8338DC8, 120, 80, 0);
|
|
|
|
StartSpriteAnim(&gSprites[sTradeWindowData->unk_91], 1);
|
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
break;
|
|
|
|
case 28:
|
2019-10-04 07:42:45 -04:00
|
|
|
if ((sTradeWindowData->bg1vofs -= 3) == 166)
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state = 200;
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_1 |
|
|
|
|
DISPCNT_OBJ_1D_MAP |
|
|
|
|
DISPCNT_BG1_ON |
|
|
|
|
DISPCNT_OBJ_ON);
|
|
|
|
break;
|
|
|
|
case 200:
|
2019-10-04 07:42:45 -04:00
|
|
|
gSprites[sTradeWindowData->unk_90].pos1.y -= 2;
|
|
|
|
gSprites[sTradeWindowData->unk_91].pos1.y -= 2;
|
|
|
|
if (gSprites[sTradeWindowData->unk_90].pos1.y < -8)
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state = 29;
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 29:
|
|
|
|
BeginNormalPaletteFade(0xFFFFFFFF, -1, 0, 16, RGB_BLACK);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state = 30;
|
2018-12-28 13:42:34 -06:00
|
|
|
break;
|
|
|
|
case 30:
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
DestroySprite(&gSprites[sTradeWindowData->unk_90]);
|
|
|
|
DestroySprite(&gSprites[sTradeWindowData->unk_91]);
|
2018-12-28 13:42:34 -06:00
|
|
|
sub_807B62C(2);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 31:
|
|
|
|
BeginNormalPaletteFade(0xFFFFFFFF, -1, 16, 0, RGB_BLACK);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_90 = CreateSprite(&gSpriteTemplate_8338DC8, 111, 170, 0);
|
|
|
|
sTradeWindowData->unk_91 = CreateSprite(&gSpriteTemplate_8338DC8, 129, -10, 0);
|
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
break;
|
|
|
|
case 32:
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
|
|
|
PlaySE(SE_TK_WARPOUT);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
2019-10-04 07:42:45 -04:00
|
|
|
gSprites[sTradeWindowData->unk_90].pos2.y -= 3;
|
|
|
|
gSprites[sTradeWindowData->unk_91].pos2.y += 3;
|
2018-12-28 13:42:34 -06:00
|
|
|
break;
|
|
|
|
case 33:
|
2019-10-04 07:42:45 -04:00
|
|
|
gSprites[sTradeWindowData->unk_90].pos2.y -= 3;
|
|
|
|
gSprites[sTradeWindowData->unk_91].pos2.y += 3;
|
|
|
|
if (gSprites[sTradeWindowData->unk_90].pos2.y <= -90)
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
gSprites[sTradeWindowData->unk_90].data[1] = 1;
|
|
|
|
gSprites[sTradeWindowData->unk_91].data[1] = 1;
|
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
CreateTask(c3_0805465C, 5);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 34:
|
|
|
|
BlendPalettes(0x8, 16, RGB_WHITEALPHA);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
break;
|
|
|
|
case 35:
|
|
|
|
BlendPalettes(0x8, 16, RGB_WHITEALPHA);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
break;
|
|
|
|
case 36:
|
|
|
|
BlendPalettes(0x8, 16, RGB_WHITEALPHA);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
break;
|
|
|
|
case 37:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (!IsMonSpriteNotFlipped(sTradeWindowData->monSpecies[TRADE_PLAYER]))
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].affineAnims = gSpriteAffineAnimTable_8338ECC;
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].oam.affineMode = 3;
|
|
|
|
CalcCenterToCornerVec(&gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]], 0, 3, 3);
|
|
|
|
StartSpriteAffineAnim(&gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]], 0);
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
StartSpriteAffineAnim(&gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]], 0);
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
2019-10-04 07:42:45 -04:00
|
|
|
StartSpriteAffineAnim(&gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PARTNER]], 0);
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].pos1.x = 40;
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PARTNER]].pos1.x = 200;
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].pos1.y = 192;
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PARTNER]].pos1.y = -32;
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].invisible = FALSE;
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PARTNER]].invisible = FALSE;
|
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
break;
|
|
|
|
case 38:
|
2019-10-04 07:42:45 -04:00
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.y -= 3;
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PARTNER]].pos2.y += 3;
|
|
|
|
if (gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.y < -160 && gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.y >= -163)
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
|
|
|
PlaySE(SE_TK_WARPIN);
|
|
|
|
}
|
2019-10-04 07:42:45 -04:00
|
|
|
if (gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.y < -222)
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
gSprites[sTradeWindowData->unk_90].data[1] = 0;
|
|
|
|
gSprites[sTradeWindowData->unk_91].data[1] = 0;
|
|
|
|
sTradeWindowData->state++;
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]].invisible = TRUE;
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PARTNER]].invisible = TRUE;
|
2018-12-28 13:42:34 -06:00
|
|
|
CreateTask(sub_807F39C, 5);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 39:
|
2019-10-04 07:42:45 -04:00
|
|
|
gSprites[sTradeWindowData->unk_90].pos2.y -= 3;
|
|
|
|
gSprites[sTradeWindowData->unk_91].pos2.y += 3;
|
|
|
|
if (gSprites[sTradeWindowData->unk_90].pos2.y <= -222)
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
|
|
|
BeginNormalPaletteFade(0xFFFFFFFF, -1, 0, 16, RGB_BLACK);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
|
|
|
DestroySprite(&gSprites[sTradeWindowData->unk_90]);
|
|
|
|
DestroySprite(&gSprites[sTradeWindowData->unk_91]);
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 40:
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
sub_807B62C(1);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->bg1vofs = 166;
|
2018-12-28 13:42:34 -06:00
|
|
|
sub_807B62C(3);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->bg2vofs = 412;
|
|
|
|
sTradeWindowData->unk_90 = CreateSprite(&gUnknown_08338D88, 120, -20, 3);
|
|
|
|
gSprites[sTradeWindowData->unk_90].callback = sub_807AA4C;
|
|
|
|
sTradeWindowData->unk_91 = CreateSprite(&gSpriteTemplate_8338DC8, 120, -20, 0);
|
|
|
|
StartSpriteAnim(&gSprites[sTradeWindowData->unk_91], 1);
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 41:
|
|
|
|
BeginNormalPaletteFade(0xFFFFFFFF, -1, 16, 0, RGB_BLACK);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
break;
|
|
|
|
case 42:
|
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 |
|
|
|
|
DISPCNT_OBJ_1D_MAP |
|
|
|
|
DISPCNT_BG1_ON |
|
|
|
|
DISPCNT_OBJ_ON);
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 43:
|
2019-10-04 07:42:45 -04:00
|
|
|
gSprites[sTradeWindowData->unk_90].pos2.y += 4;
|
|
|
|
gSprites[sTradeWindowData->unk_91].pos2.y += 4;
|
|
|
|
if (gSprites[sTradeWindowData->unk_90].pos2.y + gSprites[sTradeWindowData->unk_90].pos1.y == 64)
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state = 144;
|
|
|
|
sTradeWindowData->timer = 0;
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 144:
|
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 |
|
|
|
|
DISPCNT_OBJ_1D_MAP |
|
|
|
|
DISPCNT_BG1_ON |
|
|
|
|
DISPCNT_BG2_ON |
|
|
|
|
DISPCNT_OBJ_ON);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->bg1vofs += 3;
|
|
|
|
sTradeWindowData->bg2vofs += 3;
|
|
|
|
if (++sTradeWindowData->timer == 10)
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
|
|
|
u8 taskId = CreateTask(c3_08054588, 5);
|
|
|
|
gTasks[taskId].data[2] = 1;
|
|
|
|
}
|
2019-10-04 07:42:45 -04:00
|
|
|
if (sTradeWindowData->bg1vofs > 316)
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->bg1vofs = 316;
|
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 145:
|
2019-10-04 07:42:45 -04:00
|
|
|
DestroySprite(&gSprites[sTradeWindowData->unk_90]);
|
|
|
|
DestroySprite(&gSprites[sTradeWindowData->unk_91]);
|
|
|
|
sTradeWindowData->state++;
|
|
|
|
sTradeWindowData->timer = 0;
|
2018-12-28 13:42:34 -06:00
|
|
|
break;
|
|
|
|
case 146:
|
|
|
|
if (!FuncIsActiveTask(c3_08054588))
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state = 46;
|
|
|
|
sTradeWindowData->timer = 0;
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 46:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (++sTradeWindowData->timer == 10)
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 47:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (++sTradeWindowData->bg1vofs > 348)
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->bg1vofs = 348;
|
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 48:
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_91 = CreateSprite(&gSpriteTemplate_8338E74, 120, 80, 0);
|
|
|
|
sTradeWindowData->state = 50;
|
2018-12-28 13:42:34 -06:00
|
|
|
break;
|
|
|
|
case 50:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (gSprites[sTradeWindowData->unk_91].animEnded)
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
DestroySprite(&gSprites[sTradeWindowData->unk_91]);
|
2018-12-28 13:42:34 -06:00
|
|
|
sub_807B62C(6);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
PlaySE(SE_W028);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 51:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (sTradeWindowData->unk_EA < 0x400)
|
2018-12-28 13:42:34 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_EA += 0x34;
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_EA = 0x400;
|
|
|
|
sTradeWindowData->state++;
|
2018-12-28 13:42:34 -06:00
|
|
|
}
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->sXY = 0x8000 / sTradeWindowData->unk_EA;
|
2018-12-28 13:42:34 -06:00
|
|
|
break;
|
|
|
|
case 52:
|
|
|
|
BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state = 60;
|
2018-12-28 13:42:34 -06:00
|
|
|
break;
|
|
|
|
case 60:
|
|
|
|
if (!gPaletteFade.active)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
|
|
|
sub_807B62C(5);
|
|
|
|
sub_807B62C(7);
|
|
|
|
gPaletteFade.bufferTransferDisabled = TRUE;
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 61:
|
|
|
|
gPaletteFade.bufferTransferDisabled = FALSE;
|
|
|
|
BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, RGB_BLACK);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
break;
|
|
|
|
case 62:
|
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 |
|
|
|
|
DISPCNT_OBJ_1D_MAP |
|
|
|
|
DISPCNT_BG2_ON |
|
|
|
|
DISPCNT_OBJ_ON);
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 63:
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_D3 = CreateSprite(&gSpriteTemplate_8338D28, 120, -8, 0);
|
|
|
|
gSprites[sTradeWindowData->unk_D3].data[3] = 74;
|
|
|
|
gSprites[sTradeWindowData->unk_D3].callback = sub_807E6AC;
|
|
|
|
StartSpriteAnim(&gSprites[sTradeWindowData->unk_D3], 1);
|
|
|
|
StartSpriteAffineAnim(&gSprites[sTradeWindowData->unk_D3], 2);
|
|
|
|
BlendPalettes(1 << (16 + gSprites[sTradeWindowData->unk_D3].oam.paletteNum), 16, RGB_WHITEALPHA);
|
|
|
|
sTradeWindowData->state++;
|
|
|
|
sTradeWindowData->timer = 0;
|
2018-12-28 02:11:41 -06:00
|
|
|
break;
|
|
|
|
case 64:
|
2019-10-04 07:42:45 -04:00
|
|
|
BeginNormalPaletteFade(1 << (16 + gSprites[sTradeWindowData->unk_D3].oam.paletteNum), 1, 16, 0, RGB_WHITEALPHA);
|
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
break;
|
|
|
|
case 65:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (gSprites[sTradeWindowData->unk_D3].callback == SpriteCallbackDummy)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
HandleLoadSpecialPokePic_2(&gMonFrontPicTable[sTradeWindowData->monSpecies[TRADE_PARTNER]], gMonSpritesGfxPtr->sprites[3], sTradeWindowData->monSpecies[TRADE_PARTNER], sTradeWindowData->monPersonalities[TRADE_PARTNER]);
|
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 66:
|
2019-10-04 07:42:45 -04:00
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PARTNER]].pos1.x = 120;
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PARTNER]].pos1.y = gMonFrontPicCoords[sTradeWindowData->monSpecies[TRADE_PARTNER]].y_offset + 60;
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PARTNER]].pos2.x = 0;
|
|
|
|
gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PARTNER]].pos2.y = 0;
|
|
|
|
StartSpriteAnim(&gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PARTNER]], 0);
|
|
|
|
CreatePokeballSpriteToReleaseMon(sTradeWindowData->pokePicSpriteIdxs[TRADE_PARTNER], gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PARTNER]].oam.paletteNum, 120, 84, 2, 1, 20, 0xFFFFF, sTradeWindowData->monSpecies[TRADE_PARTNER]);
|
|
|
|
FreeSpriteOamMatrix(&gSprites[sTradeWindowData->unk_D3]);
|
|
|
|
DestroySprite(&gSprites[sTradeWindowData->unk_D3]);
|
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
break;
|
|
|
|
case 67:
|
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 |
|
|
|
|
DISPCNT_OBJ_1D_MAP |
|
|
|
|
DISPCNT_BG0_ON |
|
|
|
|
DISPCNT_BG2_ON |
|
|
|
|
DISPCNT_OBJ_ON);
|
|
|
|
StringExpandPlaceholders(gStringVar4, gText_XSentOverY);
|
2019-10-03 19:39:37 -04:00
|
|
|
DrawTextOnTradeWindow(0, gStringVar4, 0);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state = 167;
|
|
|
|
sTradeWindowData->timer = 0;
|
2018-12-28 02:11:41 -06:00
|
|
|
break;
|
|
|
|
// 167 and 267 are extra cases added in for animations
|
|
|
|
case 167:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (++sTradeWindowData->timer > 60)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state = 267;
|
|
|
|
sTradeWindowData->timer = 0;
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 267:
|
|
|
|
if (IsCryFinished())
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state = 68;
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 68:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (++sTradeWindowData->timer == 10)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
|
|
|
PlayFanfare(MUS_FANFA5);
|
|
|
|
}
|
2019-10-04 07:42:45 -04:00
|
|
|
if (sTradeWindowData->timer == 250)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
StringExpandPlaceholders(gStringVar4, gText_TakeGoodCareOfX);
|
2019-10-03 19:39:37 -04:00
|
|
|
DrawTextOnTradeWindow(0, gStringVar4, 0);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->timer = 0;
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 69:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (++sTradeWindowData->timer == 60)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 70:
|
2019-10-03 19:39:37 -04:00
|
|
|
CheckPartnersMonForRibbons();
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
break;
|
|
|
|
case 71:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (sTradeWindowData->isLinkTrade)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else if (gMain.newKeys & A_BUTTON)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 72: // Only if in-game trade
|
2019-10-04 07:42:45 -04:00
|
|
|
TradeMons(gSpecialVar_0x8005, 0);
|
2018-12-28 02:11:41 -06:00
|
|
|
gCB2_AfterEvolution = sub_807B60C;
|
2019-10-03 19:39:37 -04:00
|
|
|
evoTarget = GetEvolutionTargetSpecies(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], TRUE, ITEM_NONE);
|
2018-12-28 02:11:41 -06:00
|
|
|
if (evoTarget != SPECIES_NONE)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
TradeEvolutionScene(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], evoTarget, sTradeWindowData->pokePicSpriteIdxs[TRADE_PARTNER], gSelectedTradeMonPositions[TRADE_PLAYER]);
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
break;
|
|
|
|
case 73:
|
|
|
|
BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state++;
|
2018-12-28 02:11:41 -06:00
|
|
|
break;
|
|
|
|
case 74:
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
PlayNewMapMusic(sTradeWindowData->cachedMapMusic);
|
|
|
|
if (sTradeWindowData)
|
2018-12-28 02:11:41 -06:00
|
|
|
{
|
|
|
|
FreeAllWindowBuffers();
|
|
|
|
Free(GetBgTilemapBuffer(3));
|
|
|
|
Free(GetBgTilemapBuffer(1));
|
|
|
|
Free(GetBgTilemapBuffer(0));
|
|
|
|
FreeMonSpritesGfx();
|
2019-10-04 07:42:45 -04:00
|
|
|
FREE_AND_SET_NULL(sTradeWindowData);
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
SetMainCallback2(CB2_ReturnToField);
|
2019-10-05 10:41:37 -04:00
|
|
|
BuffeInGameTradeMonName();
|
2018-12-28 02:11:41 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
2018-12-29 12:46:15 -06:00
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void c2_08053788(void)
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
|
|
|
u16 evoTarget;
|
|
|
|
switch (gMain.state)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
gMain.state = 4;
|
|
|
|
gSoftResetDisabled = TRUE;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
gCB2_AfterEvolution = sub_807EB50;
|
2019-10-03 19:39:37 -04:00
|
|
|
evoTarget = GetEvolutionTargetSpecies(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], TRUE, ITEM_NONE);
|
2018-12-29 12:46:15 -06:00
|
|
|
if (evoTarget != SPECIES_NONE)
|
2019-10-04 07:42:45 -04:00
|
|
|
TradeEvolutionScene(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], evoTarget, sTradeWindowData->pokePicSpriteIdxs[TRADE_PARTNER], gSelectedTradeMonPositions[TRADE_PLAYER]);
|
|
|
|
else if (IsWirelessTrade())
|
2018-12-29 12:46:15 -06:00
|
|
|
SetMainCallback2(sub_807F464);
|
|
|
|
else
|
|
|
|
SetMainCallback2(sub_807EB50);
|
2019-10-03 19:39:37 -04:00
|
|
|
gSelectedTradeMonPositions[TRADE_PLAYER] = 255;
|
2018-12-29 12:46:15 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!HasLinkErrorOccurred())
|
|
|
|
RunTasks();
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
|
|
|
UpdatePaletteFade();
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807E4DC(void)
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
|
|
|
u8 blockReceivedStatus;
|
2019-10-04 07:42:45 -04:00
|
|
|
TradeGetMultiplayerId(); // no effect call, ret val ignored
|
2018-12-29 12:46:15 -06:00
|
|
|
blockReceivedStatus = GetBlockReceivedStatus();
|
|
|
|
if (blockReceivedStatus & 0x01)
|
|
|
|
{
|
|
|
|
if (gBlockRecvBuffer[0][0] == 0xDCBA)
|
|
|
|
{
|
|
|
|
SetMainCallback2(c2_08053788);
|
|
|
|
}
|
|
|
|
if (gBlockRecvBuffer[0][0] == 0xABCD)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_72 = 1;
|
2018-12-29 12:46:15 -06:00
|
|
|
}
|
|
|
|
ResetBlockReceivedFlag(0);
|
|
|
|
}
|
|
|
|
if (blockReceivedStatus & 0x02)
|
|
|
|
{
|
|
|
|
if (gBlockRecvBuffer[1][0] == 0xABCD)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_73 = 1;
|
2018-12-29 12:46:15 -06:00
|
|
|
}
|
|
|
|
ResetBlockReceivedFlag(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807E55C(struct Sprite *sprite)
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
|
|
|
sprite->pos1.y += sprite->data[0] / 10;
|
|
|
|
sprite->data[5] += sprite->data[1];
|
|
|
|
sprite->pos1.x = sprite->data[5] / 10;
|
|
|
|
if (sprite->pos1.y > 0x4c)
|
|
|
|
{
|
|
|
|
sprite->pos1.y = 0x4c;
|
|
|
|
sprite->data[0] = -(sprite->data[0] * sprite->data[2]) / 100;
|
|
|
|
sprite->data[3] ++;
|
|
|
|
}
|
|
|
|
if (sprite->pos1.x == 0x78)
|
|
|
|
sprite->data[1] = 0;
|
|
|
|
sprite->data[0] += sprite->data[4];
|
|
|
|
if (sprite->data[3] == 4)
|
|
|
|
{
|
|
|
|
sprite->data[7] = 1;
|
|
|
|
sprite->callback = SpriteCallbackDummy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807E5D8(struct Sprite *sprite)
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
2019-10-05 10:41:37 -04:00
|
|
|
sprite->pos2.y += sTradeBallVerticalVelocityTable[sprite->data[0]];
|
2018-12-29 12:46:15 -06:00
|
|
|
if (sprite->data[0] == 22)
|
|
|
|
PlaySE(SE_KON);
|
|
|
|
if (++ sprite->data[0] == 44)
|
|
|
|
{
|
|
|
|
PlaySE(SE_W025);
|
|
|
|
sprite->callback = sub_807E64C;
|
|
|
|
sprite->data[0] = 0;
|
|
|
|
BeginNormalPaletteFade(1 << (16 + sprite->oam.paletteNum), -1, 0, 16, RGB_WHITEALPHA);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807E64C(struct Sprite *sprite)
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
|
|
|
if (sprite->data[1] == 20)
|
|
|
|
StartSpriteAffineAnim(sprite, 1);
|
|
|
|
if (++ sprite->data[1] > 20)
|
|
|
|
{
|
2019-10-05 10:41:37 -04:00
|
|
|
sprite->pos2.y -= sTradeBallVerticalVelocityTable[sprite->data[0]];
|
2018-12-29 12:46:15 -06:00
|
|
|
if (++ sprite->data[0] == 23)
|
|
|
|
{
|
|
|
|
DestroySprite(sprite);
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->state = 14; // Resume the master trade animation
|
2018-12-29 12:46:15 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807E6AC(struct Sprite *sprite)
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
|
|
|
if (sprite->data[2] == 0)
|
|
|
|
{
|
|
|
|
if ((sprite->pos1.y += 4) > sprite->data[3])
|
|
|
|
{
|
|
|
|
sprite->data[2] ++;
|
|
|
|
sprite->data[0] = 0x16;
|
|
|
|
PlaySE(SE_KON);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (sprite->data[0] == 0x42)
|
|
|
|
PlaySE(SE_KON2);
|
|
|
|
if (sprite->data[0] == 0x5c)
|
|
|
|
PlaySE(SE_KON3);
|
|
|
|
if (sprite->data[0] == 0x6b)
|
|
|
|
PlaySE(SE_KON4);
|
2019-10-05 10:41:37 -04:00
|
|
|
sprite->pos2.y += sTradeBallVerticalVelocityTable[sprite->data[0]];
|
2018-12-29 12:46:15 -06:00
|
|
|
if (++sprite->data[0] == 0x6c)
|
|
|
|
sprite->callback = SpriteCallbackDummy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u16 GetInGameTradeSpeciesInfo(void)
|
|
|
|
{
|
2019-10-03 01:16:22 -04:00
|
|
|
const struct InGameTrade *inGameTrade = &sIngameTrades[gSpecialVar_0x8004];
|
|
|
|
StringCopy(gStringVar1, gSpeciesNames[inGameTrade->requestedSpecies]);
|
2018-12-29 12:46:15 -06:00
|
|
|
StringCopy(gStringVar2, gSpeciesNames[inGameTrade->species]);
|
2019-10-03 01:16:22 -04:00
|
|
|
return inGameTrade->requestedSpecies;
|
2018-12-29 12:46:15 -06:00
|
|
|
}
|
|
|
|
|
2019-10-05 10:41:37 -04:00
|
|
|
static void BuffeInGameTradeMonName(void)
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
|
|
|
u8 nickname[32];
|
2019-10-03 01:16:22 -04:00
|
|
|
const struct InGameTrade *inGameTrade = &sIngameTrades[gSpecialVar_0x8004];
|
2018-12-29 12:46:15 -06:00
|
|
|
GetMonData(&gPlayerParty[gSpecialVar_0x8005], MON_DATA_NICKNAME, nickname);
|
|
|
|
StringCopy10(gStringVar1, nickname);
|
|
|
|
StringCopy(gStringVar2, gSpeciesNames[inGameTrade->species]);
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void _CreateInGameTradePokemon(u8 whichPlayerMon, u8 whichInGameTrade)
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
2019-10-03 01:16:22 -04:00
|
|
|
const struct InGameTrade *inGameTrade = &sIngameTrades[whichInGameTrade];
|
2018-12-29 12:46:15 -06:00
|
|
|
u8 level = GetMonData(&gPlayerParty[whichPlayerMon], MON_DATA_LEVEL);
|
|
|
|
|
|
|
|
struct MailStruct mail;
|
2019-10-03 01:16:22 -04:00
|
|
|
u8 metLocation = METLOC_IN_GAME_TRADE;
|
2018-12-29 12:46:15 -06:00
|
|
|
u8 isMail;
|
|
|
|
struct Pokemon *pokemon = &gEnemyParty[0];
|
|
|
|
|
2019-08-30 23:06:43 -04:00
|
|
|
CreateMon(pokemon, inGameTrade->species, level, 32, TRUE, inGameTrade->personality, OT_ID_PRESET, inGameTrade->otId);
|
2018-12-29 12:46:15 -06: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 01:16:22 -04:00
|
|
|
SetMonData(pokemon, MON_DATA_NICKNAME, inGameTrade->nickname);
|
2018-12-29 12:46:15 -06:00
|
|
|
SetMonData(pokemon, MON_DATA_OT_NAME, inGameTrade->otName);
|
|
|
|
SetMonData(pokemon, MON_DATA_OT_GENDER, &inGameTrade->otGender);
|
2019-10-03 01:16:22 -04: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 12:46:15 -06:00
|
|
|
SetMonData(pokemon, MON_DATA_SHEEN, &inGameTrade->sheen);
|
|
|
|
SetMonData(pokemon, MON_DATA_MET_LOCATION, &metLocation);
|
|
|
|
|
|
|
|
isMail = FALSE;
|
|
|
|
if (inGameTrade->heldItem != ITEM_NONE)
|
|
|
|
{
|
|
|
|
if (ItemIsMail(inGameTrade->heldItem))
|
|
|
|
{
|
2019-10-03 19:39:37 -04:00
|
|
|
SetInGameTradeMail(&mail, inGameTrade);
|
2019-10-04 07:42:45 -04:00
|
|
|
gTradeMail[0] = mail;
|
2018-12-29 12:46:15 -06:00
|
|
|
SetMonData(pokemon, MON_DATA_MAIL, &isMail);
|
|
|
|
SetMonData(pokemon, MON_DATA_HELD_ITEM, &inGameTrade->heldItem);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetMonData(pokemon, MON_DATA_HELD_ITEM, &inGameTrade->heldItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CalculateMonStats(&gEnemyParty[0]);
|
|
|
|
}
|
|
|
|
|
2019-10-03 19:39:37 -04:00
|
|
|
static void SetInGameTradeMail(struct MailStruct *mail, const struct InGameTrade *trade) {
|
2018-12-29 12:46:15 -06:00
|
|
|
s32 i;
|
|
|
|
|
2019-10-05 10:41:37 -04:00
|
|
|
for (i = 0; i < MAIL_WORDS_COUNT; i++)
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
2019-10-03 19:39:37 -04:00
|
|
|
mail->words[i] = sIngameTradeMail[trade->mailNum][i];
|
2018-12-29 12:46:15 -06: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)
|
|
|
|
{
|
|
|
|
_CreateInGameTradePokemon(gSpecialVar_0x8005, gSpecialVar_0x8004);
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807EA2C(void)
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
2019-10-05 10:41:37 -04:00
|
|
|
if (AnimateTradeSequence() == TRUE)
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
DestroySprite(&gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PLAYER]]);
|
|
|
|
FreeSpriteOamMatrix(&gSprites[sTradeWindowData->pokePicSpriteIdxs[TRADE_PARTNER]]);
|
|
|
|
TradeMons(gSelectedTradeMonPositions[TRADE_PLAYER], gSelectedTradeMonPositions[TRADE_PARTNER] % PARTY_SIZE);
|
|
|
|
if (!IsWirelessTrade())
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->linkData[0] = 0xABCD;
|
|
|
|
sTradeWindowData->unk_93 = 1;
|
2018-12-29 12:46:15 -06:00
|
|
|
}
|
|
|
|
SetMainCallback2(sub_807EACC);
|
|
|
|
}
|
|
|
|
sub_807B5B8();
|
|
|
|
sub_807E4DC();
|
|
|
|
RunTasks();
|
|
|
|
RunTextPrinters();
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
|
|
|
UpdatePaletteFade();
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807EACC(void)
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
u8 mpId = TradeGetMultiplayerId();
|
|
|
|
if (IsWirelessTrade())
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
|
|
|
SetMainCallback2(c2_08053788);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sub_807E4DC();
|
2019-10-04 07:42:45 -04:00
|
|
|
if (mpId == 0 && sTradeWindowData->unk_72 == 1 && sTradeWindowData->unk_73 == 1)
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->linkData[0] = 0xDCBA;
|
|
|
|
Trade_SendData(sTradeWindowData);
|
|
|
|
sTradeWindowData->unk_72 = 2;
|
|
|
|
sTradeWindowData->unk_73 = 2;
|
2018-12-29 12:46:15 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
RunTasks();
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
|
|
|
UpdatePaletteFade();
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807EB50(void)
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
|
|
|
switch (gMain.state)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
gMain.state++;
|
|
|
|
StringExpandPlaceholders(gStringVar4, gText_CommunicationStandby5);
|
2019-10-03 19:39:37 -04:00
|
|
|
DrawTextOnTradeWindow(0, gStringVar4, 0);
|
2018-12-29 12:46:15 -06:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
sub_8077288(0);
|
|
|
|
gMain.state = 100;
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->timer = 0;
|
2018-12-29 12:46:15 -06:00
|
|
|
break;
|
|
|
|
case 100:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (++sTradeWindowData->timer > 180)
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
|
|
|
gMain.state = 101;
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->timer = 0;
|
2018-12-29 12:46:15 -06:00
|
|
|
}
|
2018-12-31 02:22:21 -06:00
|
|
|
if (_IsLinkTaskFinished())
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
|
|
|
gMain.state = 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 101:
|
2018-12-31 02:22:21 -06:00
|
|
|
if (_IsLinkTaskFinished())
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
|
|
|
gMain.state = 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
gMain.state = 50;
|
|
|
|
StringExpandPlaceholders(gStringVar4, gText_SavingDontTurnOffPower);
|
2019-10-03 19:39:37 -04:00
|
|
|
DrawTextOnTradeWindow(0, gStringVar4, 0);
|
2018-12-29 12:46:15 -06:00
|
|
|
break;
|
|
|
|
case 50:
|
|
|
|
if (!InUnionRoom())
|
|
|
|
IncrementGameStat(GAME_STAT_POKEMON_TRADES);
|
|
|
|
if (gWirelessCommType)
|
|
|
|
{
|
|
|
|
sub_801B990(2, gLinkPlayers[GetMultiplayerId() ^ 1].trainerId);
|
|
|
|
}
|
2018-12-31 02:30:30 -06:00
|
|
|
SetContinueGameWarpStatusToDynamicWarp();
|
2018-12-29 12:46:15 -06:00
|
|
|
sub_8153380();
|
|
|
|
gMain.state++;
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->timer = 0;
|
2018-12-29 12:46:15 -06:00
|
|
|
break;
|
|
|
|
case 51:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (++sTradeWindowData->timer == 5)
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
|
|
|
gMain.state++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 52:
|
|
|
|
if (sub_81533AC())
|
|
|
|
{
|
2018-12-31 02:30:30 -06:00
|
|
|
ClearContinueGameWarpStatus2();
|
2018-12-29 12:46:15 -06:00
|
|
|
gMain.state = 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->timer = 0;
|
2018-12-29 12:46:15 -06:00
|
|
|
gMain.state = 51;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
sub_81533E0();
|
|
|
|
gMain.state = 40;
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->timer = 0;
|
2018-12-29 12:46:15 -06:00
|
|
|
break;
|
|
|
|
case 40:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (++sTradeWindowData->timer > 50)
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
|
|
|
if (GetMultiplayerId() == 0)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->timer = Random() % 30;
|
2018-12-29 12:46:15 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->timer = 0;
|
2018-12-29 12:46:15 -06:00
|
|
|
}
|
|
|
|
gMain.state = 41;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 41:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (sTradeWindowData->timer == 0)
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
|
|
|
sub_8077288(1);
|
|
|
|
gMain.state = 42;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->timer--;
|
2018-12-29 12:46:15 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 42:
|
2018-12-31 02:22:21 -06:00
|
|
|
if (_IsLinkTaskFinished())
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
|
|
|
sub_8153408();
|
|
|
|
gMain.state = 5;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 5:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (++sTradeWindowData->timer > 60)
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
|
|
|
gMain.state++;
|
|
|
|
sub_8077288(2);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 6:
|
2018-12-31 02:22:21 -06:00
|
|
|
if (_IsLinkTaskFinished())
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
|
|
|
BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK);
|
|
|
|
gMain.state ++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
|
|
|
FadeOutBGM(3);
|
|
|
|
gMain.state++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
if (IsBGMStopped() == TRUE)
|
|
|
|
{
|
|
|
|
if (gWirelessCommType && gMain.savedCallback == sub_80773AC)
|
|
|
|
{
|
|
|
|
sub_8077288(3);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sub_800AC34();
|
|
|
|
}
|
|
|
|
gMain.state++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
if (gWirelessCommType && gMain.savedCallback == sub_80773AC)
|
|
|
|
{
|
2018-12-31 02:22:21 -06:00
|
|
|
if (_IsLinkTaskFinished())
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
|
|
|
gSoftResetDisabled = FALSE;
|
|
|
|
SetMainCallback2(c2_080543C4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!gReceivedRemoteLinkPlayers)
|
|
|
|
{
|
|
|
|
gSoftResetDisabled = FALSE;
|
|
|
|
SetMainCallback2(c2_080543C4);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!HasLinkErrorOccurred())
|
|
|
|
{
|
|
|
|
RunTasks();
|
|
|
|
}
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
|
|
|
UpdatePaletteFade();
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void c2_080543C4(void)
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
|
|
|
FreeAllWindowBuffers();
|
|
|
|
Free(GetBgTilemapBuffer(3));
|
|
|
|
Free(GetBgTilemapBuffer(1));
|
|
|
|
Free(GetBgTilemapBuffer(0));
|
|
|
|
FreeMonSpritesGfx();
|
2019-10-04 07:42:45 -04:00
|
|
|
FREE_AND_SET_NULL(sTradeWindowData);
|
2018-12-29 12:46:15 -06:00
|
|
|
if (gWirelessCommType)
|
2019-03-31 18:59:52 -04:00
|
|
|
DestroyWirelessStatusIndicatorSprite();
|
2018-12-29 12:46:15 -06:00
|
|
|
SetMainCallback2(gMain.savedCallback);
|
|
|
|
}
|
|
|
|
RunTasks();
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
|
|
|
UpdatePaletteFade();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoInGameTradeScene(void)
|
|
|
|
{
|
|
|
|
ScriptContext2_Enable();
|
2019-10-04 07:42:45 -04:00
|
|
|
CreateTask(Task_InGameTrade, 10);
|
2018-12-29 12:46:15 -06:00
|
|
|
BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK);
|
|
|
|
}
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
static void Task_InGameTrade(u8 taskId)
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
SetMainCallback2(CB2_InGameTrade);
|
2019-03-03 02:50:40 -05:00
|
|
|
gFieldCallback = FieldCallback_ReturnToEventScript2;
|
2018-12-29 12:46:15 -06:00
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-03 19:39:37 -04:00
|
|
|
static void CheckPartnersMonForRibbons(void)
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
u8 numRibbons = 0;
|
2019-10-06 22:58:25 -04:00
|
|
|
for (i = 0; i < 12; i ++)
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
2019-10-03 19:39:37 -04:00
|
|
|
numRibbons += GetMonData(&gEnemyParty[gSelectedTradeMonPositions[TRADE_PARTNER] % PARTY_SIZE], MON_DATA_CHAMPION_RIBBON + i);
|
2018-12-29 12:46:15 -06:00
|
|
|
}
|
|
|
|
if (numRibbons != 0)
|
|
|
|
FlagSet(FLAG_SYS_RIBBON_GET);
|
|
|
|
}
|
|
|
|
|
2019-10-05 10:41:37 -04:00
|
|
|
void InitTradeBg(void)
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
2019-10-05 10:41:37 -04:00
|
|
|
InitTradeBgInternal();
|
2018-12-29 12:46:15 -06:00
|
|
|
}
|
|
|
|
|
2019-10-03 19:39:37 -04:00
|
|
|
void DrawTextOnTradeWindow(u8 windowId, const u8 *str, u8 speed)
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
2019-03-02 17:25:39 -05:00
|
|
|
FillWindowPixelBuffer(windowId, PIXEL_FILL(15));
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->textColors[0] = TEXT_DYNAMIC_COLOR_6;
|
|
|
|
sTradeWindowData->textColors[1] = TEXT_COLOR_WHITE;
|
|
|
|
sTradeWindowData->textColors[2] = TEXT_COLOR_GREEN;
|
|
|
|
AddTextPrinterParameterized4(windowId, 1, 0, 2, 0, 0, sTradeWindowData->textColors, speed, str);
|
2018-12-29 12:46:15 -06:00
|
|
|
CopyWindowToVram(windowId, 3);
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void c3_08054588(u8 taskId)
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
|
|
|
s16 *data = gTasks[taskId].data;
|
|
|
|
|
|
|
|
u16 unk = gUnknown_08339090[data[0]][0] * 16;
|
|
|
|
|
|
|
|
if (!data[2])
|
|
|
|
{
|
|
|
|
if (unk == 0x100)
|
2019-10-03 19:39:37 -04:00
|
|
|
LoadPalette(sTradePal_Black, 0x30, 32);
|
2018-12-29 12:46:15 -06:00
|
|
|
else
|
2019-10-03 19:39:37 -04:00
|
|
|
LoadPalette(&sTradePal_WirelessSignalSend[unk], 0x30, 32);
|
2018-12-29 12:46:15 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (unk == 0x100)
|
2019-10-03 19:39:37 -04:00
|
|
|
LoadPalette(sTradePal_Black, 0x30, 32);
|
2018-12-29 12:46:15 -06:00
|
|
|
else
|
2019-10-03 19:39:37 -04:00
|
|
|
LoadPalette(&sTradePal_WirelessSignalReceive[unk], 0x30, 32);
|
2018-12-29 12:46:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (gUnknown_08339090[data[0]][0] == 0 && data[1] == 0)
|
|
|
|
PlaySE(SE_W215);
|
|
|
|
|
|
|
|
if (data[1] == gUnknown_08339090[data[0]][1])
|
|
|
|
{
|
|
|
|
data[0]++;
|
|
|
|
data[1] = 0;
|
|
|
|
if (gUnknown_08339090[data[0]][1] == 0xFF)
|
|
|
|
{
|
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data[1]++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void c3_0805465C(u8 taskId)
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
|
|
|
s16 *data = gTasks[taskId].data;
|
|
|
|
|
|
|
|
if (data[0] == 0)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_FB = sTradeWindowData->unk_FD = 120;
|
|
|
|
sTradeWindowData->unk_FC = 0;
|
|
|
|
sTradeWindowData->unk_FE = 160;
|
2018-12-29 12:46:15 -06: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);
|
|
|
|
}
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
SetGpuReg(REG_OFFSET_WIN0H, WIN_RANGE2(sTradeWindowData->unk_FB, sTradeWindowData->unk_FD));
|
|
|
|
SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE2(sTradeWindowData->unk_FC, sTradeWindowData->unk_FE));
|
2019-01-05 19:25:46 +01:00
|
|
|
|
2018-12-29 12:46:15 -06:00
|
|
|
data[0]++;
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_FB -= 5;
|
|
|
|
sTradeWindowData->unk_FD += 5;
|
2018-12-29 12:46:15 -06:00
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
if (sTradeWindowData->unk_FB < 80)
|
2018-12-29 12:46:15 -06:00
|
|
|
{
|
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
}
|
2018-12-29 13:50:24 -06:00
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807F39C(u8 taskId)
|
2018-12-29 13:50:24 -06:00
|
|
|
{
|
|
|
|
s16 *data = gTasks[taskId].data;
|
|
|
|
|
|
|
|
if (data[0] == 0)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_FB = 80;
|
|
|
|
sTradeWindowData->unk_FD = 160;
|
2018-12-29 13:50:24 -06:00
|
|
|
SetGpuReg(REG_OFFSET_WINOUT, WINOUT_WIN01_OBJ);
|
|
|
|
SetGpuReg(REG_OFFSET_WININ, WININ_WIN0_BG0 |
|
|
|
|
WININ_WIN0_BG1 |
|
|
|
|
WININ_WIN0_OBJ);
|
|
|
|
}
|
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
SetGpuReg(REG_OFFSET_WIN0H, WIN_RANGE2(sTradeWindowData->unk_FB, sTradeWindowData->unk_FD));
|
|
|
|
SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE2(sTradeWindowData->unk_FC, sTradeWindowData->unk_FE));
|
2019-01-05 19:25:46 +01:00
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
if (sTradeWindowData->unk_FB != 120)
|
2018-12-29 13:50:24 -06:00
|
|
|
{
|
|
|
|
data[0]++;
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->unk_FB += 5;
|
|
|
|
sTradeWindowData->unk_FD -= 5;
|
2018-12-29 13:50:24 -06:00
|
|
|
|
2019-10-04 07:42:45 -04:00
|
|
|
if (sTradeWindowData->unk_FB >= 116)
|
2018-12-29 13:50:24 -06:00
|
|
|
BlendPalettes(0x8, 0, RGB_WHITEALPHA);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ClearGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON);
|
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:23:27 -06:00
|
|
|
static void sub_807F464(void)
|
2018-12-29 13:50:24 -06:00
|
|
|
{
|
|
|
|
switch (gMain.state)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
gMain.state = 1;
|
|
|
|
StringExpandPlaceholders(gStringVar4, gText_CommunicationStandby5);
|
2019-10-03 19:39:37 -04:00
|
|
|
DrawTextOnTradeWindow(0, gStringVar4, 0);
|
2018-12-29 13:50:24 -06:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
sub_8077288(0);
|
|
|
|
gMain.state = 2;
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->timer = 0;
|
2018-12-29 13:50:24 -06:00
|
|
|
break;
|
|
|
|
case 2:
|
2018-12-31 02:22:21 -06:00
|
|
|
if (_IsLinkTaskFinished())
|
2018-12-29 13:50:24 -06:00
|
|
|
{
|
|
|
|
gMain.state = 3;
|
|
|
|
StringExpandPlaceholders(gStringVar4, gText_SavingDontTurnOffPower);
|
2019-10-03 19:39:37 -04:00
|
|
|
DrawTextOnTradeWindow(0, gStringVar4, 0);
|
2018-12-29 13:50:24 -06:00
|
|
|
IncrementGameStat(GAME_STAT_POKEMON_TRADES);
|
|
|
|
sub_8153380();
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->timer = 0;
|
2018-12-29 13:50:24 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (++sTradeWindowData->timer == 5)
|
2018-12-29 13:50:24 -06:00
|
|
|
{
|
|
|
|
gMain.state = 4;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
if (sub_81533AC())
|
|
|
|
{
|
|
|
|
gMain.state = 5;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->timer = 0;
|
2018-12-29 13:50:24 -06:00
|
|
|
gMain.state = 3;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
sub_81533E0();
|
|
|
|
gMain.state = 6;
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->timer = 0;
|
2018-12-29 13:50:24 -06:00
|
|
|
break;
|
|
|
|
case 6:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (++sTradeWindowData->timer > 10)
|
2018-12-29 13:50:24 -06:00
|
|
|
{
|
|
|
|
if (GetMultiplayerId() == 0)
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->timer = Random() % 30;
|
2018-12-29 13:50:24 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->timer = 0;
|
2018-12-29 13:50:24 -06:00
|
|
|
}
|
|
|
|
gMain.state = 7;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 7:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (sTradeWindowData->timer == 0)
|
2018-12-29 13:50:24 -06:00
|
|
|
{
|
|
|
|
sub_8077288(1);
|
|
|
|
gMain.state = 8;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-04 07:42:45 -04:00
|
|
|
sTradeWindowData->timer--;
|
2018-12-29 13:50:24 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 8:
|
2018-12-31 02:22:21 -06:00
|
|
|
if (_IsLinkTaskFinished())
|
2018-12-29 13:50:24 -06:00
|
|
|
{
|
|
|
|
sub_8153408();
|
|
|
|
gMain.state = 9;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 9:
|
2019-10-04 07:42:45 -04:00
|
|
|
if (++sTradeWindowData->timer > 60)
|
2018-12-29 13:50:24 -06:00
|
|
|
{
|
|
|
|
gMain.state++;
|
|
|
|
sub_8077288(2);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 10:
|
2018-12-31 02:22:21 -06:00
|
|
|
if (_IsLinkTaskFinished())
|
2018-12-29 13:50:24 -06:00
|
|
|
{
|
|
|
|
FadeOutBGM(3);
|
|
|
|
BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK);
|
|
|
|
gMain.state = 11;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 11:
|
|
|
|
if (!gPaletteFade.active && IsBGMStopped() == TRUE)
|
|
|
|
{
|
|
|
|
sub_8077288(3);
|
|
|
|
gMain.state = 12;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 12:
|
2018-12-31 02:22:21 -06:00
|
|
|
if (_IsLinkTaskFinished())
|
2018-12-29 13:50:24 -06:00
|
|
|
{
|
|
|
|
gSoftResetDisabled = FALSE;
|
|
|
|
SetMainCallback2(c2_080543C4);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!HasLinkErrorOccurred())
|
|
|
|
RunTasks();
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
|
|
|
UpdatePaletteFade();
|
|
|
|
}
|