diff --git a/graphics/trade/cable_closeup_map.bin b/graphics/trade/crossing_highlight_cable.bin similarity index 100% rename from graphics/trade/cable_closeup_map.bin rename to graphics/trade/crossing_highlight_cable.bin diff --git a/graphics/trade/unknown_3379A0.bin b/graphics/trade/crossing_highlight_wireless.bin similarity index 100% rename from graphics/trade/unknown_3379A0.bin rename to graphics/trade/crossing_highlight_wireless.bin diff --git a/graphics/trade/unknown_DDB444.pal b/graphics/trade/cursor.pal similarity index 100% rename from graphics/trade/unknown_DDB444.pal rename to graphics/trade/cursor.pal diff --git a/graphics/trade/buttons.png b/graphics/trade/cursor.png similarity index 100% rename from graphics/trade/buttons.png rename to graphics/trade/cursor.png diff --git a/graphics/trade/misc.pal b/graphics/trade/link_mon.pal similarity index 100% rename from graphics/trade/misc.pal rename to graphics/trade/link_mon.pal diff --git a/graphics/trade/glow1.png b/graphics/trade/link_mon_glow.png similarity index 100% rename from graphics/trade/glow1.png rename to graphics/trade/link_mon_glow.png diff --git a/graphics/trade/unknown_338EA4.pal b/graphics/trade/link_mon_shadow.pal similarity index 100% rename from graphics/trade/unknown_338EA4.pal rename to graphics/trade/link_mon_shadow.pal diff --git a/graphics/trade/glow2.png b/graphics/trade/link_mon_shadow.png similarity index 100% rename from graphics/trade/glow2.png rename to graphics/trade/link_mon_shadow.png diff --git a/graphics/trade/shadow_map.bin b/graphics/trade/platform.bin similarity index 100% rename from graphics/trade/shadow_map.bin rename to graphics/trade/platform.bin diff --git a/graphics/trade/unknown_3308C0.pal b/graphics/trade/unused1.pal similarity index 100% rename from graphics/trade/unknown_3308C0.pal rename to graphics/trade/unused1.pal diff --git a/graphics/trade/shadow.pal b/graphics/trade/unused2.pal similarity index 100% rename from graphics/trade/shadow.pal rename to graphics/trade/unused2.pal diff --git a/graphics/trade/black.pal b/graphics/trade/wireless_signal_none.pal similarity index 100% rename from graphics/trade/black.pal rename to graphics/trade/wireless_signal_none.pal diff --git a/include/graphics.h b/include/graphics.h index cea8bbab1..786420472 100644 --- a/include/graphics.h +++ b/include/graphics.h @@ -4903,8 +4903,8 @@ extern const u16 gUnknown_08DDCF04[]; extern const u16 gTradeGba2_Pal[]; extern const u8 gTradeGba_Gfx[]; extern const u16 gTradeMenuMonBox_Tilemap[]; -extern const u8 gTradeButtons_Gfx[]; -extern const u16 gUnknown_08DDB444[]; +extern const u8 gTradeCursor_Gfx[]; +extern const u16 gTradeCursor_Pal[]; // Party menu extern const u32 gPartyMenuPokeball_Gfx[]; diff --git a/src/data/trade.h b/src/data/trade.h index b29e7c3d1..752971c11 100644 --- a/src/data/trade.h +++ b/src/data/trade.h @@ -1,3 +1,17 @@ +#define GFXTAG_MENU_TEXT 200 // Used as a base tag in CB2_CreateTradeMenu and CB2_ReturnToTradeMenu +#define GFXTAG_CURSOR 300 +#define GFXTAG_LINK_MON_GLOW 5550 +#define GFXTAG_LINK_MON_SHADOW 5552 +#define GFXTAG_CABLE_END 5554 +#define GFXTAG_GBA_SCREEN 5556 +#define GFXTAG_POKEBALL 5557 + +#define PALTAG_CURSOR 2345 +#define PALTAG_MENU_TEXT 4925 +#define PALTAG_LINK_MON 5551 +#define PALTAG_GBA 5555 +#define PALTAG_POKEBALL 5558 + // Exists unused in RS as well static const u32 sUnusedStructSizes[] = { @@ -25,7 +39,7 @@ static const u8 sText_Slash[] = _("/"); static const u8 sText_Lv[] = _("Lv. "); static const u8 sText_ThreeDashes[] = _("---"); static const u8 sText_FourQuestionMarks[] = _("????"); -static const u8 sText_832DAE4[] = _(""); +static const u8 sText_UnusedEmpty[] = _(""); static const u8 sText_IsThisTradeOkay[] = _("Is this trade okay?"); static const u8 sText_Cancel[] = _("CANCEL"); static const u8 sText_ChooseAPkmn[] = _("Choose a POKéMON."); @@ -48,107 +62,113 @@ static const struct OamData sTradeOamData_32x16 = .priority = 1 }; -static const struct OamData sTradeOamData_64x32 = +static const struct OamData sOamData_Cursor = { .shape = SPRITE_SHAPE(64x32), .size = SPRITE_SIZE(64x32), .priority = 1 }; -static const union AnimCmd gSpriteAnim_832DC24[] = +static const union AnimCmd sAnim_Cursor_Normal[] = { ANIMCMD_FRAME(0, 5), ANIMCMD_END }; -static const union AnimCmd gSpriteAnim_832DC2C[] = +static const union AnimCmd sAnim_Cursor_OnCancel[] = { ANIMCMD_FRAME(32, 5), ANIMCMD_END }; -static const union AnimCmd *const gSpriteAnimTable_832DC34[] = -{ - gSpriteAnim_832DC24, - gSpriteAnim_832DC2C +enum { + CURSOR_ANIM_NORMAL, + CURSOR_ANIM_ON_CANCEL, }; -static const struct SpriteSheet sTradeButtonsSpriteSheet = +static const union AnimCmd *const sAnims_Cursor[] = { - .data = gTradeButtons_Gfx, + [CURSOR_ANIM_NORMAL] = sAnim_Cursor_Normal, + [CURSOR_ANIM_ON_CANCEL] = sAnim_Cursor_OnCancel +}; + +static const struct SpriteSheet sCursor_SpriteSheet = +{ + .data = gTradeCursor_Gfx, .size = 0x800, - .tag = 300 + .tag = GFXTAG_CURSOR }; -static const struct SpritePalette gUnknown_0832DC44 = +static const struct SpritePalette sCursor_SpritePalette = { - .data = gUnknown_08DDB444, - .tag = 2345 + .data = gTradeCursor_Pal, + .tag = PALTAG_CURSOR }; -static const union AnimCmd gSpriteAnim_832DC4C[] = +static const union AnimCmd sAnim_MenuText_0[] = { ANIMCMD_FRAME(0, 5), ANIMCMD_END }; -static const union AnimCmd gSpriteAnim_832DC54[] = +static const union AnimCmd sAnim_MenuText_1[] = { ANIMCMD_FRAME(8, 5), ANIMCMD_END }; -static const union AnimCmd gSpriteAnim_832DC5C[] = +static const union AnimCmd sAnim_MenuText_2[] = { ANIMCMD_FRAME(16, 5), ANIMCMD_END }; -static const union AnimCmd gSpriteAnim_832DC64[] = +static const union AnimCmd sAnim_MenuText_3[] = { ANIMCMD_FRAME(24, 5), ANIMCMD_END }; -static const union AnimCmd gSpriteAnim_832DC6C[] = +static const union AnimCmd sAnim_MenuText_4[] = { ANIMCMD_FRAME(32, 5), ANIMCMD_END }; -static const union AnimCmd gSpriteAnim_832DC74[] = +static const union AnimCmd sAnim_MenuText_5[] = { ANIMCMD_FRAME(40, 5), ANIMCMD_END }; -static const union AnimCmd *const gSpriteAnimTable_832DC7C[] = +// These anims are not used +static const union AnimCmd *const sAnims_MenuText[] = { - gSpriteAnim_832DC4C, - gSpriteAnim_832DC54, - gSpriteAnim_832DC5C, - gSpriteAnim_832DC64, - gSpriteAnim_832DC6C, - gSpriteAnim_832DC74 + sAnim_MenuText_0, + sAnim_MenuText_1, + sAnim_MenuText_2, + sAnim_MenuText_3, + sAnim_MenuText_4, + sAnim_MenuText_5 }; -static const struct SpriteTemplate gSpriteTemplate_832DC94 = +static const struct SpriteTemplate sSpriteTemplate_Cursor = { - .tileTag = 300, - .paletteTag = 2345, - .oam = &sTradeOamData_64x32, - .anims = gSpriteAnimTable_832DC34, + .tileTag = GFXTAG_CURSOR, + .paletteTag = PALTAG_CURSOR, + .oam = &sOamData_Cursor, + .anims = sAnims_Cursor, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy, }; -static const struct SpriteTemplate gSpriteTemplate_832DCAC = +static const struct SpriteTemplate sSpriteTemplate_MenuText = { - .tileTag = 200, - .paletteTag = 4925, + .tileTag = GFXTAG_MENU_TEXT, + .paletteTag = PALTAG_MENU_TEXT, .oam = &sTradeOamData_32x16, - .anims = gSpriteAnimTable_832DC7C, + .anims = sAnims_MenuText, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy, @@ -158,7 +178,7 @@ static const u16 TradeScreenTextPalette[] = INCBIN_U16("graphics/trade/text.gbap static const struct SpritePalette gSpritePalette_TradeScreenText = { .data = TradeScreenTextPalette, - .tag = 4925 + .tag = PALTAG_MENU_TEXT }; // This is used to determine the next mon to select when the D-Pad is @@ -337,26 +357,26 @@ static const u8 sTradeMonBoxCoords[][2][2] = }, }; -static const u8 sUnref_0832DE6E[] = +static const u8 sUnusedCoords[][2] = { - 0x00, 0x0e, - 0x0f, 0x1d, - 0x03, 0x05, - 0x03, 0x07, - 0x12, 0x05, - 0x12, 0x07, - 0x08, 0x07, - 0x16, 0x0c, - 0x08, 0x07, - 0x16, 0x0c, - 0x06, 0x07, - 0x18, 0x0c, - 0x06, 0x07, - 0x18, 0x0c, - 0x08, 0x07, - 0x16, 0x0c, - 0x07, 0x07, - 0x17, 0x0c + { 0, 14}, + {15, 29}, + { 3, 5}, + { 3, 7}, + {18, 5}, + {18, 7}, + { 8, 7}, + {22, 12}, + { 8, 7}, + {22, 12}, + { 6, 7}, + {24, 12}, + { 6, 7}, + {24, 12}, + { 8, 7}, + {22, 12}, + { 7, 7}, + {23, 12} }; static const u8 *const sTradeActionTexts[] = @@ -620,42 +640,42 @@ static const u8 sTradeMenuPartyMonBoxDimensions[3][2] = [TRADE_PARTNER] = {19, 3} }; -static const u16 sTradePal_PokeBall[] = INCBIN_U16("graphics/trade/pokeball.gbapal"); -static const u8 sTradeGfx_PokeBall[] = INCBIN_U8("graphics/trade/pokeball.4bpp"); -static const u8 sTradeGfx_PokeBallSymbol[] = INCBIN_U8("graphics/trade/pokeball_symbol.8bpp"); // unused? -static const u16 sTradeTilemap_Cable[] = INCBIN_U16("graphics/trade/cable_closeup_map.bin"); +static const u16 sPokeball_Pal[] = INCBIN_U16("graphics/trade/pokeball.gbapal"); +static const u8 sPokeball_Gfx[] = INCBIN_U8("graphics/trade/pokeball.4bpp"); +static const u8 sPokeballSymbol_Gfx[] = INCBIN_U8("graphics/trade/pokeball_symbol.8bpp"); // unused +static const u16 sCrossingHighlightCable_Tilemap[] = INCBIN_U16("graphics/trade/crossing_highlight_cable.bin"); static const u16 sTradeTilemap_PokeBallSymbol[] = INCBIN_U16("graphics/trade/pokeball_symbol_map.bin"); // unused? -static const u16 sUnref_083308C0[] = INCBIN_U16("graphics/trade/unknown_3308C0.gbapal"); -static const u16 sTradePal_Gba[] = INCBIN_U16("graphics/trade/gba.gbapal"); -static const u16 sTradePal_ShadowUnused[] = INCBIN_U16("graphics/trade/shadow.gbapal"); -static const u16 sTradePal_BlackUnused[] = INCBIN_U16("graphics/trade/black.gbapal"); -static const u16 sTradePal_Misc[] = INCBIN_U16("graphics/trade/misc.gbapal"); -static const u8 sTradeGfx_Glow1[] = INCBIN_U8("graphics/trade/glow1.4bpp"); -static const u8 sTradeGfx_Glow2[] = INCBIN_U8("graphics/trade/glow2.4bpp"); -static const u8 sTradeGfx_CableEnd[] = INCBIN_U8("graphics/trade/cable_end.4bpp"); -static const u8 sTradeGfx_GbaScreen[] = INCBIN_U8("graphics/trade/gba_screen.4bpp"); -const u16 gUnknown_08331F60[] = INCBIN_U16("graphics/trade/shadow_map.bin"); -static const u8 sTradeAffine_Gba[] = INCBIN_U8("graphics/trade/gba_affine.8bpp"); -static const u8 sFiller_08335760[64] = {}; -static const u8 sTradeAffineMap_GbaCable[] = INCBIN_U8("graphics/trade/gba_affine_map_cable.bin"); -static const u8 sTradeAffineMap_GbaWireless[] = INCBIN_U8("graphics/trade/gba_affine_map_wireless.bin"); -static const u16 sTradeTilemap_GbaWireless[] = INCBIN_U16("graphics/trade/gba_map_wireless.bin"); -static const u16 sTradeTilemap_GbaCable[] = INCBIN_U16("graphics/trade/gba_map_cable.bin"); -static const u32 gUnknown_083379A0[] = INCBIN_U32("graphics/trade/unknown_3379A0.bin.lz"); //some wireless tilemap -static const u16 sTradePal_WirelessSignalSend[] = INCBIN_U16("graphics/trade/wireless_signal_send.gbapal"); -static const u16 sTradePal_WirelessSignalReceive[] = INCBIN_U16("graphics/trade/wireless_signal_receive.gbapal"); -static const u16 sTradePal_Black[] = INCBIN_U16("graphics/trade/black.gbapal"); -static const u32 sTradeGfx_WirelessSignal[] = INCBIN_U32("graphics/trade/wireless_signal.4bpp.lz"); -static const u32 sTradeTilemap_WirelessSignal[] = INCBIN_U32("graphics/trade/wireless_signal.bin.lz"); +static const u16 sUnusedPal1[] = INCBIN_U16("graphics/trade/unused1.gbapal"); +static const u16 sGba_Pal[] = INCBIN_U16("graphics/trade/gba.gbapal"); +static const u16 sUnusedPal2[] = INCBIN_U16("graphics/trade/unused2.gbapal"); +static const u16 sWirelessSignalNone_Pal_Unused[] = INCBIN_U16("graphics/trade/wireless_signal_none.gbapal"); +static const u16 sLinkMon_Pal[] = INCBIN_U16("graphics/trade/link_mon.gbapal"); +static const u8 sLinkMonGlow_Gfx[] = INCBIN_U8("graphics/trade/link_mon_glow.4bpp"); +static const u8 sLinkMonShadow_Gfx[] = INCBIN_U8("graphics/trade/link_mon_shadow.4bpp"); +static const u8 sCableEnd_Gfx[] = INCBIN_U8("graphics/trade/cable_end.4bpp"); +static const u8 sGbaScreen_Gfx[] = INCBIN_U8("graphics/trade/gba_screen.4bpp"); +const u16 gTradePlatform_Tilemap[] = INCBIN_U16("graphics/trade/platform.bin"); +static const u8 sGbaAffine_Gfx[] = INCBIN_U8("graphics/trade/gba_affine.8bpp"); // Only the gfx for when the GBA is zooming in/out +static const u8 sEmptyGfx[64] = {}; +static const u8 sGbaCable_AffineTilemap[] = INCBIN_U8("graphics/trade/gba_affine_map_cable.bin"); +static const u8 sGbaWireless_AffineTilemap[] = INCBIN_U8("graphics/trade/gba_affine_map_wireless.bin"); +static const u16 sGbaWireless_Tilemap[] = INCBIN_U16("graphics/trade/gba_map_wireless.bin"); +static const u16 sGbaCable_Tilemap[] = INCBIN_U16("graphics/trade/gba_map_cable.bin"); +static const u32 sCrossingHighlightWireless_Tilemap[] = INCBIN_U32("graphics/trade/crossing_highlight_wireless.bin.lz"); +static const u16 sWirelessSignalSend_Pal[] = INCBIN_U16("graphics/trade/wireless_signal_send.gbapal"); +static const u16 sWirelessSignalRecv_Pal[] = INCBIN_U16("graphics/trade/wireless_signal_receive.gbapal"); +static const u16 sWirelessSignalNone_Pal[] = INCBIN_U16("graphics/trade/wireless_signal_none.gbapal"); +static const u32 sWirelessSignal_Gfx[] = INCBIN_U32("graphics/trade/wireless_signal.4bpp.lz"); +static const u32 sWirelessSignal_Tilemap[] = INCBIN_U32("graphics/trade/wireless_signal.bin.lz"); -static const struct OamData sTradeOamData_16x16 = +static const struct OamData sOamData_Pokeball = { .affineMode = ST_OAM_AFFINE_NORMAL, .shape = SPRITE_SHAPE(16x16), .size = SPRITE_SIZE(16x16) }; -static const union AnimCmd gSpriteAnim_8338C4C[] = +static const union AnimCmd sAnim_Pokeball_SpinOnce[] = { ANIMCMD_FRAME( 0, 3), ANIMCMD_FRAME( 4, 3), @@ -674,7 +694,7 @@ static const union AnimCmd gSpriteAnim_8338C4C[] = ANIMCMD_END }; -static const union AnimCmd gSpriteAnim_8338C88[] = +static const union AnimCmd sAnim_Pokeball_SpinTwice[] = { ANIMCMD_FRAME( 0, 3), ANIMCMD_FRAME( 4, 3), @@ -693,25 +713,25 @@ static const union AnimCmd gSpriteAnim_8338C88[] = ANIMCMD_END }; -static const union AnimCmd *const gSpriteAnimTable_8338C88[] = +static const union AnimCmd *const sAnims_Pokeball[] = { - gSpriteAnim_8338C4C, - gSpriteAnim_8338C88 + sAnim_Pokeball_SpinOnce, + sAnim_Pokeball_SpinTwice }; -static const union AffineAnimCmd gSpriteAffineAnim_8338CCC[] = +static const union AffineAnimCmd sAffineAnim_Pokeball_Normal[] = { AFFINEANIMCMD_FRAME(0, 0, 0, 1), AFFINEANIMCMD_END }; -static const union AffineAnimCmd gSpriteAffineAnim_8338CDC[] = +static const union AffineAnimCmd sAffineAnim_Pokeball_Squish[] = { AFFINEANIMCMD_FRAME(-8, 0, 0, 20), AFFINEANIMCMD_END }; -static const union AffineAnimCmd gSpriteAffineAnim_8338CEC[] = +static const union AffineAnimCmd sAffineAnim_Pokeball_Unsquish[] = { AFFINEANIMCMD_FRAME(0x60, 0x100, 0, 0), AFFINEANIMCMD_FRAME( 0, 0, 0, 5), @@ -719,38 +739,38 @@ static const union AffineAnimCmd gSpriteAffineAnim_8338CEC[] = AFFINEANIMCMD_END }; -static const union AffineAnimCmd *const gSpriteAffineAnimTable_8338D0C[] = +static const union AffineAnimCmd *const sAffineAnims_Pokeball[] = { - gSpriteAffineAnim_8338CCC, - gSpriteAffineAnim_8338CDC, - gSpriteAffineAnim_8338CEC + sAffineAnim_Pokeball_Normal, + sAffineAnim_Pokeball_Squish, + sAffineAnim_Pokeball_Unsquish }; static const struct SpriteSheet sPokeBallSpriteSheet = { - .data = sTradeGfx_PokeBall, + .data = sPokeball_Gfx, .size = 0x600, - .tag = 5557 + .tag = GFXTAG_POKEBALL }; static const struct SpritePalette sPokeBallSpritePalette = { - .data = sTradePal_PokeBall, - .tag = 5558 + .data = sPokeball_Pal, + .tag = PALTAG_POKEBALL }; -static const struct SpriteTemplate gSpriteTemplate_8338D28 = +static const struct SpriteTemplate sSpriteTemplate_Pokeball = { - .tileTag = 5557, - .paletteTag = 5558, - .oam = &sTradeOamData_16x16, - .anims = gSpriteAnimTable_8338C88, + .tileTag = GFXTAG_POKEBALL, + .paletteTag = PALTAG_POKEBALL, + .oam = &sOamData_Pokeball, + .anims = sAnims_Pokeball, .images = NULL, - .affineAnims = gSpriteAffineAnimTable_8338D0C, - .callback = sub_807E55C + .affineAnims = sAffineAnims_Pokeball, + .callback = SpriteCB_BouncingPokeball }; -static const struct OamData sTradeOamData_32x32 = +static const struct OamData sOamData_LinkMonGlow = { .affineMode = ST_OAM_AFFINE_NORMAL, .objMode = ST_OAM_OBJ_BLEND, @@ -759,146 +779,151 @@ static const struct OamData sTradeOamData_32x32 = .priority = 1 }; -static const union AnimCmd gSpriteAnim_8338D48[] = +static const union AnimCmd sAnim_LinkMonGlow[] = { - ANIMCMD_FRAME(0, 5, .hFlip = TRUE, .vFlip = TRUE), + ANIMCMD_FRAME(0, 5, .hFlip = TRUE, .vFlip = TRUE), // ? The graphic is a perfect circle, no need to flip ANIMCMD_END }; -static const union AnimCmd *const gSpriteAnimTable_8338D50[] = +static const union AnimCmd *const sAnims_LinkMonGlow[] = { - gSpriteAnim_8338D48 + sAnim_LinkMonGlow }; -static const union AffineAnimCmd gSpriteAffineAnim_8338D54[] = +static const union AffineAnimCmd sAffineAnim_LinkMonGlow[] = { AFFINEANIMCMD_FRAME(-10, -10, 0, 5), AFFINEANIMCMD_FRAME(10, 10, 0, 5), AFFINEANIMCMD_JUMP(0) }; -static const union AffineAnimCmd *const gSpriteAffineAnimTable_8338D6C[] = +static const union AffineAnimCmd *const sAffineAnims_LinkMonGlow[] = { - gSpriteAffineAnim_8338D54 + sAffineAnim_LinkMonGlow }; -static const struct SpriteSheet sGlow1SpriteSheet = +static const struct SpriteSheet sSpriteSheet_LinkMonGlow = { - .data = sTradeGfx_Glow1, + .data = sLinkMonGlow_Gfx, .size = 0x200, - .tag = 5550 + .tag = GFXTAG_LINK_MON_GLOW }; -static const struct SpritePalette sMiscTradeSpritePalette = +static const struct SpritePalette sSpritePalette_LinkMon = { - .data = sTradePal_Misc, - .tag = 5551 + .data = sLinkMon_Pal, + .tag = PALTAG_LINK_MON }; -static const struct SpritePalette sGbaSpritePalette = +static const struct SpritePalette sSpritePalette_Gba = { - .data = sTradePal_Gba, - .tag = 5555 + .data = sGba_Pal, + .tag = PALTAG_GBA }; -static const struct SpriteTemplate gUnknown_08338D88 = +static const struct SpriteTemplate sSpriteTemplate_LinkMonGlow = { - .tileTag = 5550, - .paletteTag = 5551, - .oam = &sTradeOamData_32x32, - .anims = gSpriteAnimTable_8338D50, + .tileTag = GFXTAG_LINK_MON_GLOW, + .paletteTag = PALTAG_LINK_MON, + .oam = &sOamData_LinkMonGlow, + .anims = sAnims_LinkMonGlow, .images = NULL, - .affineAnims = gSpriteAffineAnimTable_8338D6C, - .callback = sub_807AA28 + .affineAnims = sAffineAnims_LinkMonGlow, + .callback = SpriteCB_LinkMonGlow }; -static const struct OamData sTradeOamData_16x32 = +static const struct OamData sOamData_LinkMonShadow = { .shape = SPRITE_SHAPE(16x32), .size = SPRITE_SIZE(16x32), .priority = 1 }; -static const union AnimCmd gSpriteAnim_8338DA8[] = +static const union AnimCmd sAnim_LinkMonShadow_Big[] = { ANIMCMD_FRAME(0, 5, .vFlip = TRUE, .hFlip = TRUE), ANIMCMD_END }; -static const union AnimCmd gSpriteAnim_8338DB0[] = +static const union AnimCmd sAnim_LinkMonShadow_Small[] = { ANIMCMD_FRAME(8, 5, .vFlip = TRUE, .hFlip = TRUE), ANIMCMD_END }; -static const union AnimCmd *const gSpriteAnimTable_8338DB8[] = -{ - gSpriteAnim_8338DA8, - gSpriteAnim_8338DB0 +enum { + ANIM_LINKMON_BIG, + ANIM_LINKMON_SMALL, }; -static const struct SpriteSheet sGlow2SpriteSheet = +static const union AnimCmd *const sAnims_LinkMonShadow[] = { - .data = sTradeGfx_Glow2, + [ANIM_LINKMON_BIG] = sAnim_LinkMonShadow_Big, + [ANIM_LINKMON_SMALL] = sAnim_LinkMonShadow_Small +}; + +static const struct SpriteSheet sSpriteSheet_LinkMonShadow = +{ + .data = sLinkMonShadow_Gfx, .size = 0x300, - .tag = 5552 + .tag = GFXTAG_LINK_MON_SHADOW }; -static const struct SpriteTemplate sGlowBallSpriteTemplate = +static const struct SpriteTemplate sSpriteTemplate_LinkMonShadow = { - .tileTag = 5552, - .paletteTag = 5551, - .oam = &sTradeOamData_16x32, - .anims = gSpriteAnimTable_8338DB8, + .tileTag = GFXTAG_LINK_MON_SHADOW, + .paletteTag = PALTAG_LINK_MON, + .oam = &sOamData_LinkMonShadow, + .anims = sAnims_LinkMonShadow, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = sub_807AA7C + .callback = SpriteCB_LinkMonShadow }; -static const struct OamData sTradeOamData_16x32_2 = +static const struct OamData sOamData_CableEnd = { .shape = SPRITE_SHAPE(16x32), .size = SPRITE_SIZE(16x32), .priority = 1 }; -static const union AnimCmd gSpriteAnim_8338DE8[] = +static const union AnimCmd sAnim_CableEnd[] = { ANIMCMD_FRAME(0, 10), ANIMCMD_END }; -static const union AnimCmd *const gSpriteAnimTable_8338DF0[] = +static const union AnimCmd *const sAnims_CableEnd[] = { - gSpriteAnim_8338DE8 + sAnim_CableEnd }; -static const struct SpriteSheet sCableEndSpriteSheet = +static const struct SpriteSheet sSpriteSheet_CableEnd = { - .data = sTradeGfx_CableEnd, + .data = sCableEnd_Gfx, .size = 0x100, - .tag = 5554 + .tag = GFXTAG_CABLE_END }; -static const struct SpriteTemplate gSpriteTemplate_8338DFC = +static const struct SpriteTemplate sSpriteTemplate_CableEnd = { - .tileTag = 5554, - .paletteTag = 5555, - .oam = &sTradeOamData_16x32_2, - .anims = gSpriteAnimTable_8338DF0, + .tileTag = GFXTAG_CABLE_END, + .paletteTag = PALTAG_GBA, + .oam = &sOamData_CableEnd, + .anims = sAnims_CableEnd, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = sub_807AABC + .callback = SpriteCB_CableEndSending }; -static const struct OamData sTradeOamData_64x32_2 = +static const struct OamData sOamData_GbaScreen = { .shape = SPRITE_SHAPE(64x32), .size = SPRITE_SIZE(64x32), .priority = 1 }; -static const union AnimCmd gSpriteAnim_8338E1C[] = +static const union AnimCmd sAnim_GbaScreen_Long[] = { ANIMCMD_FRAME( 0, 2, .vFlip = TRUE, .hFlip = TRUE), ANIMCMD_FRAME(32, 2, .vFlip = TRUE, .hFlip = TRUE), @@ -911,7 +936,7 @@ static const union AnimCmd gSpriteAnim_8338E1C[] = ANIMCMD_END }; -static const union AnimCmd gSpriteAnim_8338E40[] = +static const union AnimCmd sAnim_GbaScreen_Short[] = { ANIMCMD_FRAME( 0, 2, .vFlip = TRUE, .hFlip = TRUE), ANIMCMD_FRAME(32, 2, .vFlip = TRUE, .hFlip = TRUE), @@ -924,56 +949,56 @@ static const union AnimCmd gSpriteAnim_8338E40[] = ANIMCMD_END }; -static const union AnimCmd *const gSpriteAnimTable_8338E64[] = +static const union AnimCmd *const sAnims_GbaScreen_Long[] = { - gSpriteAnim_8338E1C + sAnim_GbaScreen_Long }; -static const union AnimCmd *const gSpriteAnimTable_8338E68[] = +static const union AnimCmd *const sAnims_GbaScreen_Short[] = { - gSpriteAnim_8338E40 + sAnim_GbaScreen_Short }; -static const struct SpriteSheet sGbaScreenSpriteSheet = +static const struct SpriteSheet sSpriteSheet_GbaScreen = { - .data = sTradeGfx_GbaScreen, + .data = sGbaScreen_Gfx, .size = 0x1000, - .tag = 5556 + .tag = GFXTAG_GBA_SCREEN }; -static const struct SpriteTemplate gSpriteTemplate_8338E74 = +static const struct SpriteTemplate sSpriteTemplate_GbaScreenFlash_Long = { - .tileTag = 5556, - .paletteTag = 5555, - .oam = &sTradeOamData_64x32_2, - .anims = gSpriteAnimTable_8338E64, + .tileTag = GFXTAG_GBA_SCREEN, + .paletteTag = PALTAG_GBA, + .oam = &sOamData_GbaScreen, + .anims = sAnims_GbaScreen_Long, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = sub_807AB04 + .callback = SpriteCB_GbaScreen }; -static const struct SpriteTemplate gSpriteTemplate_8338E8C = +static const struct SpriteTemplate sSpriteTemplate_GbaScreenFlash_Short = { - .tileTag = 5556, - .paletteTag = 5555, - .oam = &sTradeOamData_64x32_2, - .anims = gSpriteAnimTable_8338E68, + .tileTag = GFXTAG_GBA_SCREEN, + .paletteTag = PALTAG_GBA, + .oam = &sOamData_GbaScreen, + .anims = sAnims_GbaScreen_Short, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = sub_807AB04 + .callback = SpriteCB_GbaScreen }; -static const u16 gUnknown_08338EA4[] = INCBIN_U16("graphics/trade/unknown_338EA4.gbapal"); +static const u16 sLinkMonShadow_Pal[] = INCBIN_U16("graphics/trade/link_mon_shadow.gbapal"); -static const union AffineAnimCmd gSpriteAffineAnim_8338EBC[] = +static const union AffineAnimCmd sAffineAnim_CrossingMonPic[] = { AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0), AFFINEANIMCMD_JUMP(0) }; -static const union AffineAnimCmd *const gSpriteAffineAnimTable_8338ECC[] = +static const union AffineAnimCmd *const sAffineAnims_CrossingMonPics[] = { - gSpriteAffineAnim_8338EBC + sAffineAnim_CrossingMonPic }; static const struct InGameTrade sIngameTrades[] = @@ -1146,69 +1171,54 @@ static const struct BgTemplate sTradeSequenceBgTemplates[] = static const s8 sTradeBallVerticalVelocityTable[] = { - 0, 0, 1, 0, - 1, 0, 1, 1, - 1, 1, 2, 2, - 2, 2, 3, 3, - 3, 3, 4, 4, - 4, 4, -4, -4, - -4, -3, -3, -3, - -3, -2, -2, -2, - -2, -1, -1, -1, - -1, 0, -1, 0, - -1, 0, 0, 0, - 0, 0, 1, 0, - 1, 0, 1, 1, - 1, 1, 2, 2, - 2, 2, 3, 3, - 3, 3, 4, 4, - 4, 4, -4, -3, - -3, -2, -2, -1, - -1, -1, 0, -1, - 0, 0, 0, 0, - 0, 0, 1, 0, - 1, 1, 1, 2, - 2, 3, 3, 4, - -4, -3, -2, -1, - -1, -1, 0, 0, - 0, 0, 1, 0, - 1, 1, 2, 3 + 0, 0, 1, 0, 1, 0, 1, 1, 1, + 1, 2, 2, 2, 2, 3, 3, 3, 3, + 4, 4, 4, 4, -4, -4, -4, -3, -3, + -3, -3, -2, -2, -2, -2, -1, -1, -1, + -1, 0, -1, 0, -1, 0, 0, 0, 0, + 0, 1, 0, 1, 0, 1, 1, 1, 1, + 2, 2, 2, 2, 3, 3, 3, 3, 4, + 4, 4, 4, -4, -3, -3, -2, -2, -1, + -1, -1, 0, -1, 0, 0, 0, 0, 0, + 0, 1, 0, 1, 1, 1, 2, 2, 3, + 3, 4, -4, -3, -2, -1, -1, -1, 0, + 0, 0, 0, 1, 0, 1, 1, 2, 3 }; static const u8 sWirelessSignalTiming[][2] = { - {0, 1}, - {1, 1}, - {2, 1}, - {3, 1}, - {4, 1}, - {5, 2}, - {6, 2}, - {7, 2}, - {8, 2}, - {9, 2}, - {10, 3}, - {11, 3}, - {12, 3}, - {13, 4}, - {14, 5}, - {15, 2}, - {0, 1}, - {1, 1}, - {2, 1}, - {3, 1}, - {4, 1}, - {5, 2}, - {6, 2}, - {7, 2}, - {8, 2}, - {9, 2}, - {10, 3}, - {11, 3}, - {12, 3}, - {13, 4}, - {14, 5}, - {16, 1}, - {16, 255}, - {0, 0} + { 0, 1}, + { 1, 1}, + { 2, 1}, + { 3, 1}, + { 4, 1}, + { 5, 2}, + { 6, 2}, + { 7, 2}, + { 8, 2}, + { 9, 2}, + {10, 3}, + {11, 3}, + {12, 3}, + {13, 4}, + {14, 5}, + {15, 2}, + { 0, 1}, + { 1, 1}, + { 2, 1}, + { 3, 1}, + { 4, 1}, + { 5, 2}, + { 6, 2}, + { 7, 2}, + { 8, 2}, + { 9, 2}, + {10, 3}, + {11, 3}, + {12, 3}, + {13, 4}, + {14, 5}, + {16, 1}, + {16, -1}, + {} }; diff --git a/src/egg_hatch.c b/src/egg_hatch.c index 0ae0e1323..042173a4e 100644 --- a/src/egg_hatch.c +++ b/src/egg_hatch.c @@ -54,7 +54,7 @@ struct EggHatchData u8 textColor[3]; }; -extern const u32 gUnknown_08331F60[]; // tilemap gameboy circle +extern const u32 gTradePlatform_Tilemap[]; extern const u8 gText_HatchedFromEgg[]; extern const u8 gText_NicknameHatchPrompt[]; @@ -546,7 +546,7 @@ static void CB2_EggHatch_0(void) SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); LoadPalette(gTradeGba2_Pal, 0x10, 0xA0); LoadBgTiles(1, gTradeGba_Gfx, 0x1420, 0); - CopyToBgTilemapBuffer(1, gUnknown_08331F60, 0x1000, 0); + CopyToBgTilemapBuffer(1, gTradePlatform_Tilemap, 0x1000, 0); CopyBgTilemapBufferToVram(1); gMain.state++; break; diff --git a/src/graphics.c b/src/graphics.c index 09779eab7..6e54a8192 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -1474,9 +1474,9 @@ static const u16 sEmptyPal[16] = {0}; // Trade const u16 gTradeMenu_Pal[] = INCBIN_U16("graphics/trade/menu.gbapal"); -const u16 gUnknown_08DDB444[] = INCBIN_U16("graphics/trade/unknown_DDB444.gbapal"); +const u16 gTradeCursor_Pal[] = INCBIN_U16("graphics/trade/cursor.gbapal"); const u8 gTradeMenu_Gfx[] = INCBIN_U8("graphics/trade/menu.4bpp"); -const u8 gTradeButtons_Gfx[] = INCBIN_U8("graphics/trade/buttons.4bpp"); +const u8 gTradeCursor_Gfx[] = INCBIN_U8("graphics/trade/cursor.4bpp"); const u16 gUnused_DDCEE4[] = INCBIN_U16("graphics/unused/unused_DDCEE4.bin"); const u16 gUnknown_08DDCF04[] = INCBIN_U16("graphics/trade/unknown_DDCF04.bin"); const u16 gTradeMenuMonBox_Tilemap[] = INCBIN_U16("graphics/trade/menu_mon_box.bin"); diff --git a/src/trade.c b/src/trade.c index cb3db3c18..3c3915294 100644 --- a/src/trade.c +++ b/src/trade.c @@ -52,7 +52,29 @@ #include "constants/songs.h" #include "constants/union_room.h" -#define Trade_SendData(ptr) (SendBlock(bitmask_all_link_players_but_self(), ptr->linkData, 20)) +// The following tags are offsets from GFXTAG_MENU_TEXT +// They're looped over in CB2_CreateTradeMenu and CB2_ReturnToTradeMenu +// and used as indexes into sMenuTextTileBuffers +enum { + GFXTAG_PLAYER_NAME_L, + GFXTAG_PLAYER_NAME_M, + GFXTAG_PLAYER_NAME_R, + GFXTAG_PARTNER_NAME_L, + GFXTAG_PARTNER_NAME_M, + GFXTAG_PARTNER_NAME_R, + GFXTAG_CANCEL_L, + GFXTAG_CANCEL_R, + GFXTAG_CHOOSE_PKMN_L, + GFXTAG_CHOOSE_PKMN_M, + GFXTAG_CHOOSE_PKMN_R, + GFXTAG_CHOOSE_PKMN_EMPTY_1, // 6 sprites to cover the full bottom bar, but only first 3 are needed + GFXTAG_CHOOSE_PKMN_EMPTY_2, + GFXTAG_CHOOSE_PKMN_EMPTY_3, + GFXTAG_MENU_TEXT_COUNT +}; +#define GFXTAG_PLAYER_NAME (1 + GFXTAG_PLAYER_NAME_R - GFXTAG_PLAYER_NAME_L) +#define GFXTAG_PARTNER_NAME (1 + GFXTAG_PARTNER_NAME_R - GFXTAG_PARTNER_NAME_L) +#define GFXTAG_CHOOSE_PKMN (1 + GFXTAG_CHOOSE_PKMN_EMPTY_3 - GFXTAG_CHOOSE_PKMN_L) struct InGameTrade { /*0x00*/ u8 nickname[POKEMON_NAME_LENGTH + 1]; @@ -70,22 +92,23 @@ struct InGameTrade { /*0x38*/ u16 requestedSpecies; }; -static EWRAM_DATA u8 *sMessageBoxAllocBuffer = NULL; +static EWRAM_DATA u8 *sMenuTextAllocBuffer = 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}; +// Bytes 0-2 are used for the player's name text +// Bytes 3-5 are used for the partner's name text +// Bytes 6-7 are used for the Cancel text +// Bytes 8-13 are used for the Choose a Pokemon text +// See the corresponding GFXTAGs in src/data/trade.h +static EWRAM_DATA u8 *sMenuTextTileBuffers[GFXTAG_MENU_TEXT_COUNT] = {NULL}; EWRAM_DATA struct MailStruct gTradeMail[PARTY_SIZE] = {0}; EWRAM_DATA u8 gSelectedTradeMonPositions[2] = {0}; static EWRAM_DATA struct { /*0x0000*/ u8 bg2hofs; /*0x0001*/ u8 bg3hofs; - /*0x0002*/ u8 filler_2[0x28 - 2]; + /*0x0002*/ u8 filler_2[38]; /*0x0028*/ u8 partySpriteIds[2][PARTY_SIZE]; - /*0x0034*/ u8 cursorSpriteIdx; + /*0x0034*/ u8 cursorSpriteId; /*0x0035*/ u8 cursorPosition; /*0x0036*/ u8 partyCounts[2]; /*0x0038*/ bool8 monPresent[PARTY_SIZE * 2]; @@ -94,7 +117,7 @@ static EWRAM_DATA struct { /*0x0051*/ bool8 isEgg[2][PARTY_SIZE]; /*0x005D*/ u8 hpBarLevels[2][PARTY_SIZE]; /*0x0069*/ u8 bufferPartyState; - /*0x006A*/ u8 filler_6A[0x6F - 0x6A]; + /*0x006A*/ u8 filler_6A[5]; /*0x006F*/ u8 tradeMenuFunc; /*0x0070*/ u8 neverRead_70; /*0x0071*/ u8 filler_71; @@ -105,13 +128,13 @@ static EWRAM_DATA struct { /*0x0079*/ u8 partnerLinkFlagChoseAction; /*0x007A*/ u8 playerLinkFlagStatus; /*0x007B*/ u8 partnerLinkFlagStatus; - /*0x007C*/ u8 filler_7C[0x7E - 0x7C]; + /*0x007C*/ u8 filler_7C[2]; /*0x007E*/ u8 partnerCursorPosition; /*0x007F*/ u8 unused_7F; /*0x0080*/ u16 linkData[20]; /*0x00A8*/ u8 timer; /*0x00A9*/ u8 giftRibbons[GIFT_RIBBONS_COUNT]; - /*0x00B4*/ u8 filler_B4[0x8D0-0xB4]; + /*0x00B4*/ u8 filler_B4[0x81C]; /*0x08D0*/ struct { bool8 queued; u16 queueDelay; @@ -119,6 +142,7 @@ static EWRAM_DATA struct { } queuedActions[4]; /*0x08F0*/ u16 tilemapBuffer[0x400]; } *sTradeMenuData = {NULL}; + static EWRAM_DATA struct { /*0x00*/ struct Pokemon mon; /*0x64*/ u32 timer; @@ -127,19 +151,19 @@ static EWRAM_DATA struct { /*0x72*/ u8 playerLinkFlagFinishTrade; /*0x73*/ u8 partnerLinkFlagFinishTrade; /*0x74*/ u16 linkData[10]; - /*0x88*/ u8 alwaysZero_88; - /*0x89*/ u8 alwaysZero_89; + /*0x88*/ u8 linkTimeoutZero1; + /*0x89*/ u8 linkTimeoutZero2; /*0x8A*/ u16 linkTimeoutCounter; /*0x8C*/ u16 neverRead_8C; - /*0x8E*/ u8 pokePicSpriteIdxs[2]; - /*0x90*/ u8 unk_90; //sprite id - /*0x91*/ u8 unk_91; //sprite id - /*0x92*/ u8 unk_92; //sprite id + /*0x8E*/ u8 monSpriteIds[2]; + /*0x90*/ u8 connectionSpriteId1; // Multi-purpose sprite ids used during the transfer sequence + /*0x91*/ u8 connectionSpriteId2; + /*0x92*/ u8 cableEndSpriteId; /*0x93*/ u8 sendTradeFinishState; /*0x94*/ u16 state; /*0x96*/ u8 filler_96[0xD2 - 0x96]; - /*0xD2*/ u8 pokeballSpriteId; - /*0xD3*/ u8 unk_D3; //sprite id + /*0xD2*/ u8 releasePokeballSpriteId; + /*0xD3*/ u8 bouncingPokeballSpriteId; /*0xD4*/ u16 texX; /*0xD6*/ u16 texY; /*0xD8*/ u16 neverRead_D8; @@ -151,7 +175,7 @@ static EWRAM_DATA struct { /*0xE4*/ s16 bg2vofs; /*0xE6*/ s16 bg2hofs; /*0xE8*/ u16 sXY; - /*0xEA*/ u16 unk_EA; //sXY divisor + /*0xEA*/ u16 gbaScale; /*0xEC*/ u16 alpha; /*0xEE*/ bool8 isLinkTrade; /*0xF0*/ u16 monSpecies[2]; @@ -183,24 +207,24 @@ static void DrawTradeMenuPartyMonInfo(u8, u8, u8, u8, u8, u8); static void DrawTradeMenuPartyInfo(u8); static void PrintNicknamesForTradeMenu(void); static void RedrawTradeMenuParty(u8); -static void Task_DrawSelectionSummary(u8 taskId); -static void Task_DrawSelectionTrade(u8 taskId); +static void Task_DrawSelectionSummary(u8); +static void Task_DrawSelectionTrade(u8); static void QueueAction(u16, u8); static u32 GetNumQueuedActions(void); static void DoQueuedActions(void); static void PrintTradeMessage(u8); static bool8 LoadTradeMenuSpriteSheetsAndPalettes(void); -static void DrawTextWindowAndBuffer6Bytes(const u8 *, u8 *, u8); +static void DrawBottomRowText(const u8 *, u8 *, u8); static void SetTradePartyLiveStatuses(u8); static void GetTradePartyHPBarLevels(u8); static void SetTradePartyHPBarSprites(void); static void SaveTradeGiftRibbons(void); static u32 CanTradeSelectedMon(struct Pokemon *, int, int); -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); +static void SpriteCB_LinkMonGlow(struct Sprite *); +static void SpriteCB_LinkMonShadow(struct Sprite *); +static void SpriteCB_CableEndSending(struct Sprite *); +static void SpriteCB_CableEndReceiving(struct Sprite *); +static void SpriteCB_GbaScreen(struct Sprite *); static void InitTradeBgInternal(void); static void CB2_UpdateInGameTrade(void); static void SetTradeSequenceBgGpuRegs(u8); @@ -209,12 +233,12 @@ static void BufferTradeSceneStrings(void); static bool8 AnimateTradeSequence(void); static bool8 AnimateTradeSequenceCable(void); static bool8 AnimateTradeSequenceWireless(void); -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); +static void SpriteCB_BouncingPokeball(struct Sprite *); +static void SpriteCB_BouncingPokeballDepart(struct Sprite *); +static void SpriteCB_BouncingPokeballDepartEnd(struct Sprite *); +static void SpriteCB_BouncingPokeballArrive(struct Sprite *); static void BufferInGameTradeMonName(void); -static void SetInGameTradeMail(struct MailStruct *mail, const struct InGameTrade *trade); +static void SetInGameTradeMail(struct MailStruct *, const struct InGameTrade *); static void CB2_UpdateLinkTrade(void); static void CB2_TryFinishTrade(void); static void CB2_SaveAndEndTrade(void); @@ -222,8 +246,8 @@ static void CB2_FreeTradeData(void); static void Task_InGameTrade(u8); static void CheckPartnersMonForRibbons(void); static void Task_AnimateWirelessSignal(u8); -static void c3_0805465C(u8); -static void sub_807F39C(u8); +static void Task_NarrowWindowForCrossing_Wireless(u8); +static void Task_NarrowWindowForCrossing_Cable(u8); static void CB2_SaveAndEndWirelessTrade(void); #include "data/trade.h" @@ -246,7 +270,7 @@ static void RequestLinkData(u8 type) SendBlockRequest(type); } -static bool32 sub_80771BC(void) +static bool32 IsLinkTradeTaskFinished(void) { if (gPlayerCurrActivity == ACTIVITY_29) { @@ -362,12 +386,10 @@ static void CB2_CreateTradeMenu(void) case 0: sTradeMenuData = AllocZeroed(sizeof(*sTradeMenuData)); InitTradeMenu(); - sMessageBoxAllocBuffer = AllocZeroed(ARRAY_COUNT(sMessageBoxTileBuffers) * 256); + sMenuTextAllocBuffer = AllocZeroed(GFXTAG_MENU_TEXT_COUNT * 256); - for (i = 0; i < (int)ARRAY_COUNT(sMessageBoxTileBuffers); i++) - { - sMessageBoxTileBuffers[i] = &sMessageBoxAllocBuffer[i * 256]; - } + for (i = 0; i < GFXTAG_MENU_TEXT_COUNT; i++) + sMenuTextTileBuffers[i] = &sMenuTextAllocBuffer[i * 256]; gMain.state++; break; @@ -375,9 +397,7 @@ static void CB2_CreateTradeMenu(void) gPaletteFade.bufferTransferDisabled = FALSE; for (i = 0; i < PARTY_SIZE; i++) - { CreateMon(&gEnemyParty[i], SPECIES_NONE, 0, USE_RANDOM_IVS, FALSE, 0, OT_ID_PLAYER_ID, 0); - } PrintTradeMessage(TRADE_MSG_STANDBY); ShowBg(0); @@ -508,11 +528,11 @@ static void CB2_CreateTradeMenu(void) gMain.state++; break; case 10: - DrawTextWindowAndBufferTiles(gSaveBlock2Ptr->playerName, sMessageBoxTileBuffers[0], 0, 0, 3); + DrawTextWindowAndBufferTiles(gSaveBlock2Ptr->playerName, sMenuTextTileBuffers[GFXTAG_PLAYER_NAME_L], 0, 0, 3); id = GetMultiplayerId(); - DrawTextWindowAndBufferTiles(gLinkPlayers[id ^ 1].name, sMessageBoxTileBuffers[3], 0, 0, 3); - DrawTextWindowAndBufferTiles(sTradeActionTexts[TRADE_TEXT_CANCEL], sMessageBoxTileBuffers[6], 0, 0, 2); - DrawTextWindowAndBuffer6Bytes(sTradeActionTexts[TRADE_TEXT_CHOOSE_MON], sMessageBoxTileBuffers[8], 24); + DrawTextWindowAndBufferTiles(gLinkPlayers[id ^ 1].name, sMenuTextTileBuffers[GFXTAG_PARTNER_NAME_L], 0, 0, 3); + DrawTextWindowAndBufferTiles(sTradeActionTexts[TRADE_TEXT_CANCEL], sMenuTextTileBuffers[GFXTAG_CANCEL_L], 0, 0, 2); + DrawBottomRowText(sTradeActionTexts[TRADE_TEXT_CHOOSE_MON], sMenuTextTileBuffers[GFXTAG_CHOOSE_PKMN_L], 24); gMain.state++; sTradeMenuData->timer = 0; break; @@ -521,39 +541,43 @@ static void CB2_CreateTradeMenu(void) gMain.state++; break; case 12: + // Create player's name text sprites xPos = GetStringCenterAlignXOffset(1, gSaveBlock2Ptr->playerName, 120); - for (i = 0; i < 3; i++) + for (i = 0; i < GFXTAG_PLAYER_NAME; i++) { - temp = gSpriteTemplate_832DCAC; - temp.tileTag += i; + temp = sSpriteTemplate_MenuText; + temp.tileTag += i + GFXTAG_PLAYER_NAME_L; CreateSprite(&temp, xPos + (i * 32) + 16, 10, 1); } + // Create partner's name text sprites xPos = GetStringCenterAlignXOffset(1, gLinkPlayers[GetMultiplayerId() ^ 1].name, 120); - for (i = 0; i < 3; i++) + for (i = 0; i < GFXTAG_PARTNER_NAME; i++) { - temp = gSpriteTemplate_832DCAC; - temp.tileTag += i + 3; + temp = sSpriteTemplate_MenuText; + temp.tileTag += i + GFXTAG_PARTNER_NAME_L; CreateSprite(&temp, xPos + (i * 32) + 136, 10, 1); } gMain.state++; break; case 13: - temp = gSpriteTemplate_832DCAC; - temp.tileTag += 6; + // Create Cancel text sprites + temp = sSpriteTemplate_MenuText; + temp.tileTag += GFXTAG_CANCEL_L; CreateSprite(&temp, 215, 152, 1); - temp = gSpriteTemplate_832DCAC; - temp.tileTag += 7; + temp = sSpriteTemplate_MenuText; + temp.tileTag += GFXTAG_CANCEL_R; CreateSprite(&temp, 247, 152, 1); - for (i = 0; i < PARTY_SIZE; i++) + // Create Choose a Pokémon text sprites (only 3 are needed, other 3 are empty) + for (i = 0; i < GFXTAG_CHOOSE_PKMN; i++) { - temp = gSpriteTemplate_832DCAC; - temp.tileTag += i + 8; + temp = sSpriteTemplate_MenuText; + temp.tileTag += i + GFXTAG_CHOOSE_PKMN_L; CreateSprite(&temp, (i * 32) + 24, 150, 1); } - sTradeMenuData->cursorSpriteIdx = CreateSprite(&gSpriteTemplate_832DC94, sTradeMonSpriteCoords[0][0] * 8 + 32, sTradeMonSpriteCoords[0][1] * 8, 2); + sTradeMenuData->cursorSpriteId = CreateSprite(&sSpriteTemplate_Cursor, sTradeMonSpriteCoords[0][0] * 8 + 32, sTradeMonSpriteCoords[0][1] * 8, 2); sTradeMenuData->cursorPosition = 0; gMain.state++; rbox_fill_rectangle(0); @@ -695,11 +719,11 @@ static void CB2_ReturnToTradeMenu(void) gMain.state++; break; case 10: - DrawTextWindowAndBufferTiles(gSaveBlock2Ptr->playerName, sMessageBoxTileBuffers[0], 0, 0, 3); + DrawTextWindowAndBufferTiles(gSaveBlock2Ptr->playerName, sMenuTextTileBuffers[GFXTAG_PLAYER_NAME_L], 0, 0, 3); id = GetMultiplayerId(); - DrawTextWindowAndBufferTiles(gLinkPlayers[id ^ 1].name, sMessageBoxTileBuffers[3], 0, 0, 3); - DrawTextWindowAndBufferTiles(sTradeActionTexts[TRADE_TEXT_CANCEL], sMessageBoxTileBuffers[6], 0, 0, 2); - DrawTextWindowAndBuffer6Bytes(sTradeActionTexts[TRADE_TEXT_CHOOSE_MON], sMessageBoxTileBuffers[8], 24); + DrawTextWindowAndBufferTiles(gLinkPlayers[id ^ 1].name, sMenuTextTileBuffers[GFXTAG_PARTNER_NAME_L], 0, 0, 3); + DrawTextWindowAndBufferTiles(sTradeActionTexts[TRADE_TEXT_CANCEL], sMenuTextTileBuffers[GFXTAG_CANCEL_L], 0, 0, 2); + DrawBottomRowText(sTradeActionTexts[TRADE_TEXT_CHOOSE_MON], sMenuTextTileBuffers[GFXTAG_CHOOSE_PKMN_L], 24); gMain.state++; sTradeMenuData->timer = 0; break; @@ -708,35 +732,39 @@ static void CB2_ReturnToTradeMenu(void) gMain.state++; break; case 12: + // Create player's name text sprites xPos = GetStringCenterAlignXOffset(1, gSaveBlock2Ptr->playerName, 120); - for (i = 0; i < 3; i++) + for (i = 0; i < GFXTAG_PLAYER_NAME; i++) { - temp = gSpriteTemplate_832DCAC; - temp.tileTag += i; + temp = sSpriteTemplate_MenuText; + temp.tileTag += i + GFXTAG_PLAYER_NAME_L; CreateSprite(&temp, xPos + (i * 32) + 16, 10, 1); } + // Create partner's name text sprites xPos = GetStringCenterAlignXOffset(1, gLinkPlayers[GetMultiplayerId() ^ 1].name, 120); - for (i = 0; i < 3; i++) + for (i = 0; i < GFXTAG_PARTNER_NAME; i++) { - temp = gSpriteTemplate_832DCAC; - temp.tileTag += i + 3; + temp = sSpriteTemplate_MenuText; + temp.tileTag += i + GFXTAG_PARTNER_NAME_L; CreateSprite(&temp, xPos + (i * 32) + 136, 10, 1); } gMain.state++; break; case 13: - temp = gSpriteTemplate_832DCAC; - temp.tileTag += 6; + // Create Cancel text sprites + temp = sSpriteTemplate_MenuText; + temp.tileTag += GFXTAG_CANCEL_L; CreateSprite(&temp, 215, 152, 1); - temp = gSpriteTemplate_832DCAC; - temp.tileTag += 7; + temp = sSpriteTemplate_MenuText; + temp.tileTag += GFXTAG_CANCEL_R; CreateSprite(&temp, 247, 152, 1); - for (i = 0; i < PARTY_SIZE; i++) + // Create Choose a Pokémon text sprites + for (i = 0; i < GFXTAG_CHOOSE_PKMN; i++) { - temp = gSpriteTemplate_832DCAC; - temp.tileTag += i + 8; + temp = sSpriteTemplate_MenuText; + temp.tileTag += i + GFXTAG_CHOOSE_PKMN_L; CreateSprite(&temp, (i * 32) + 24, 150, 1); } @@ -745,7 +773,9 @@ static void CB2_ReturnToTradeMenu(void) else sTradeMenuData->cursorPosition = gLastViewedMonIndex + PARTY_SIZE; - sTradeMenuData->cursorSpriteIdx = CreateSprite(&gSpriteTemplate_832DC94, sTradeMonSpriteCoords[sTradeMenuData->cursorPosition][0] * 8 + 32, sTradeMonSpriteCoords[sTradeMenuData->cursorPosition][1] * 8, 2); + sTradeMenuData->cursorSpriteId = CreateSprite(&sSpriteTemplate_Cursor, + sTradeMonSpriteCoords[sTradeMenuData->cursorPosition][0] * 8 + 32, + sTradeMonSpriteCoords[sTradeMenuData->cursorPosition][1] * 8, 2); gMain.state = 16; break; case 16: @@ -835,7 +865,7 @@ static void SetLinkTradeCallbacks(void) { if (IsLinkRfuTaskFinished()) { - Free(sMessageBoxAllocBuffer); + Free(sMenuTextAllocBuffer); FreeAllWindowBuffers(); Free(sTradeMenuData); gMain.callback1 = NULL; @@ -848,7 +878,7 @@ static void SetLinkTradeCallbacks(void) { if (!gReceivedRemoteLinkPlayers) { - Free(sMessageBoxAllocBuffer); + Free(sMenuTextAllocBuffer); FreeAllWindowBuffers(); Free(sTradeMenuData); gMain.callback1 = NULL; @@ -957,12 +987,13 @@ static bool8 BufferTradeParties(void) switch (sTradeMenuData->bufferPartyState) { case 0: + // The parties are sent in pairs rather than all at once Trade_Memcpy(gBlockSendBuffer, &gPlayerParty[0], 2 * sizeof(struct Pokemon)); sTradeMenuData->bufferPartyState++; sTradeMenuData->timer = 0; break; case 1: - if (sub_80771BC()) + if (IsLinkTradeTaskFinished()) { if (_GetBlockReceivedStatus() == 0) { @@ -1004,13 +1035,13 @@ static bool8 BufferTradeParties(void) case 8: if (_GetBlockReceivedStatus() == 3) { - Trade_Memcpy(&gEnemyParty[2], gBlockRecvBuffer[id ^ 1], 200); + Trade_Memcpy(&gEnemyParty[2], gBlockRecvBuffer[id ^ 1], 2 * sizeof(struct Pokemon)); TradeResetReceivedFlags(); sTradeMenuData->bufferPartyState++; } break; case 9: - Trade_Memcpy(gBlockSendBuffer, &gPlayerParty[4], 200); + Trade_Memcpy(gBlockSendBuffer, &gPlayerParty[4], 2 * sizeof(struct Pokemon)); sTradeMenuData->bufferPartyState++; break; case 11: @@ -1023,13 +1054,13 @@ static bool8 BufferTradeParties(void) case 12: if (_GetBlockReceivedStatus() == 3) { - Trade_Memcpy(&gEnemyParty[4], gBlockRecvBuffer[id ^ 1], 200); + Trade_Memcpy(&gEnemyParty[4], gBlockRecvBuffer[id ^ 1], 2 * sizeof(struct Pokemon)); TradeResetReceivedFlags(); sTradeMenuData->bufferPartyState++; } break; case 13: - Trade_Memcpy(gBlockSendBuffer, gSaveBlock1Ptr->mail, 220); + Trade_Memcpy(gBlockSendBuffer, gSaveBlock1Ptr->mail, PARTY_SIZE * sizeof(struct MailStruct) + 4); sTradeMenuData->bufferPartyState++; break; case 15: @@ -1042,13 +1073,13 @@ static bool8 BufferTradeParties(void) case 16: if (_GetBlockReceivedStatus() == 3) { - Trade_Memcpy(gTradeMail, gBlockRecvBuffer[id ^ 1], 216); + Trade_Memcpy(gTradeMail, gBlockRecvBuffer[id ^ 1], PARTY_SIZE * sizeof(struct MailStruct)); TradeResetReceivedFlags(); sTradeMenuData->bufferPartyState++; } break; case 17: - Trade_Memcpy(gBlockSendBuffer, gSaveBlock1Ptr->giftRibbons, ARRAY_COUNT(sTradeMenuData->giftRibbons)); + Trade_Memcpy(gBlockSendBuffer, gSaveBlock1Ptr->giftRibbons, sizeof(sTradeMenuData->giftRibbons)); sTradeMenuData->bufferPartyState++; break; case 19: @@ -1061,7 +1092,7 @@ static bool8 BufferTradeParties(void) case 20: if (_GetBlockReceivedStatus() == 3) { - Trade_Memcpy(sTradeMenuData->giftRibbons, gBlockRecvBuffer[id ^ 1], ARRAY_COUNT(sTradeMenuData->giftRibbons)); + Trade_Memcpy(sTradeMenuData->giftRibbons, gBlockRecvBuffer[id ^ 1], sizeof(sTradeMenuData->giftRibbons)); TradeResetReceivedFlags(); sTradeMenuData->bufferPartyState++; } @@ -1103,9 +1134,9 @@ static bool8 BufferTradeParties(void) return FALSE; } -static void PrintAndBufferIsThisTradeOkay(void) +static void DrawIsThisTradeOkay(void) { - DrawTextWindowAndBuffer6Bytes(sText_IsThisTradeOkay, (void *)(OBJ_VRAM0 + (sTradeMenuData->bottomTextTileStart * 32)), 24); + DrawBottomRowText(sText_IsThisTradeOkay, (void *)(OBJ_VRAM0 + (sTradeMenuData->bottomTextTileStart * 32)), 24); } // mpId is unused @@ -1317,15 +1348,15 @@ static void TradeMenuMoveCursor(u8 *cursorPosition, u8 direction) if (newPosition == (PARTY_SIZE * 2)) // CANCEL { - StartSpriteAnim(&gSprites[sTradeMenuData->cursorSpriteIdx], 1); - gSprites[sTradeMenuData->cursorSpriteIdx].pos1.x = DISPLAY_WIDTH - 16; - gSprites[sTradeMenuData->cursorSpriteIdx].pos1.y = DISPLAY_HEIGHT; + StartSpriteAnim(&gSprites[sTradeMenuData->cursorSpriteId], CURSOR_ANIM_ON_CANCEL); + gSprites[sTradeMenuData->cursorSpriteId].pos1.x = DISPLAY_WIDTH - 16; + gSprites[sTradeMenuData->cursorSpriteId].pos1.y = DISPLAY_HEIGHT; } else { - StartSpriteAnim(&gSprites[sTradeMenuData->cursorSpriteIdx], 0); - gSprites[sTradeMenuData->cursorSpriteIdx].pos1.x = sTradeMonSpriteCoords[newPosition][0] * 8 + 32; - gSprites[sTradeMenuData->cursorSpriteIdx].pos1.y = sTradeMonSpriteCoords[newPosition][1] * 8; + StartSpriteAnim(&gSprites[sTradeMenuData->cursorSpriteId], CURSOR_ANIM_NORMAL); + gSprites[sTradeMenuData->cursorSpriteId].pos1.x = sTradeMonSpriteCoords[newPosition][0] * 8 + 32; + gSprites[sTradeMenuData->cursorSpriteId].pos1.y = sTradeMonSpriteCoords[newPosition][1] * 8; } if (*cursorPosition != newPosition) @@ -1392,7 +1423,7 @@ static void TradeMenuProcessInput(void) { CreateYesNoMenu(&sTradeYesNoWindowTemplate, 1, 14, 0); sTradeMenuData->tradeMenuFunc = TRADEMENUFUNC_CANCEL_TRADE_PROMPT; - DrawTextWindowAndBuffer6Bytes(sTradeActionTexts[TRADE_TEXT_CANCEL_TRADE], (void *)(OBJ_VRAM0 + sTradeMenuData->bottomTextTileStart * 32), 24); + DrawBottomRowText(sTradeActionTexts[TRADE_TEXT_CANCEL_TRADE], (void *)(OBJ_VRAM0 + sTradeMenuData->bottomTextTileStart * 32), 24); } } } @@ -1401,8 +1432,8 @@ static void TradeMenuChooseMon(void) { PrintNicknamesForTradeMenu(); sTradeMenuData->tradeMenuFunc = TRADEMENUFUNC_MAIN_MENU; - gSprites[sTradeMenuData->cursorSpriteIdx].invisible = FALSE; - DrawTextWindowAndBuffer6Bytes(sTradeActionTexts[TRADE_TEXT_CHOOSE_MON], (void *)(OBJ_VRAM0 + sTradeMenuData->bottomTextTileStart * 32), 24); + gSprites[sTradeMenuData->cursorSpriteId].invisible = FALSE; + DrawBottomRowText(sTradeActionTexts[TRADE_TEXT_CHOOSE_MON], (void *)(OBJ_VRAM0 + sTradeMenuData->bottomTextTileStart * 32), 24); } static void TradeMenuProcessInput_SelectedMon(void) @@ -1424,7 +1455,7 @@ static void TradeMenuProcessInput_SelectedMon(void) { case CAN_TRADE_MON: SetReadyToTrade(); - gSprites[sTradeMenuData->cursorSpriteIdx].invisible = TRUE; + gSprites[sTradeMenuData->cursorSpriteId].invisible = TRUE; break; case CANT_TRADE_LAST_MON: QueueAction(QUEUE_DELAY_MSG, QUEUE_ONLY_MON2); @@ -1514,7 +1545,9 @@ static bool32 CheckMonsBeforeTrade(void) aliveMons[i] = sTradeMenuData->isLiveMon[TRADE_PLAYER][i]; } - switch (CheckValidityOfTradeMons(aliveMons, sTradeMenuData->partyCounts[TRADE_PLAYER], sTradeMenuData->cursorPosition, sTradeMenuData->partnerCursorPosition)) + switch (CheckValidityOfTradeMons(aliveMons, sTradeMenuData->partyCounts[TRADE_PLAYER], + sTradeMenuData->cursorPosition, + sTradeMenuData->partnerCursorPosition)) { case PLAYER_MON_INVALID: QueueAction(QUEUE_DELAY_MSG, QUEUE_ONLY_MON2); @@ -1547,7 +1580,7 @@ static void ConfirmOrCancelTrade(void) case 1: // Cancel Trade case MENU_B_PRESSED: QueueAction(QUEUE_DELAY_MSG, QUEUE_STANDBY); - if (sub_80771BC()) + if (IsLinkTradeTaskFinished()) SetLinkData(LINKCMD_READY_CANCEL_TRADE, 0); sTradeMenuData->tradeMenuFunc = TRADEMENUFUNC_STANDBY; PutWindowTilemap(17); @@ -1555,7 +1588,8 @@ static void ConfirmOrCancelTrade(void) } } -static void sub_807929C(void) +// Only when choosing Yes to cancel, when No is chosen all are redrawn anyway +static void RestoreNicknamesCoveredByYesNo(void) { int i; @@ -1573,9 +1607,9 @@ static void CancelTradeYesNo(void) case 0: // YES, Cancel PrintTradeMessage(TRADE_MSG_WAITING_FOR_FRIEND); SetLinkData(LINKCMD_REQUEST_CANCEL, 0); - gSprites[sTradeMenuData->cursorSpriteIdx].invisible = TRUE; + gSprites[sTradeMenuData->cursorSpriteId].invisible = TRUE; sTradeMenuData->tradeMenuFunc = TRADEMENUFUNC_STANDBY; - sub_807929C(); + RestoreNicknamesCoveredByYesNo(); break; case 1: // NO, Continue case MENU_B_PRESSED: @@ -1601,7 +1635,7 @@ static void ConfirmTradePrompt(void) if (sTradeMenuData->drawPartyState[TRADE_PLAYER] == DRAW_PARTY_FINISH && sTradeMenuData->drawPartyState[TRADE_PARTNER] == DRAW_PARTY_FINISH) { - PrintAndBufferIsThisTradeOkay(); + DrawIsThisTradeOkay(); sTradeMenuData->tradeMenuFunc = TRADEMENUFUNC_DELAY_TRADE_CONFIRM; } } @@ -1637,7 +1671,7 @@ static void RedrawTradeMenuAfterPressA(void) RedrawTradeMenuParty(TRADE_PLAYER); RedrawTradeMenuParty(TRADE_PARTNER); sTradeMenuData->tradeMenuFunc = TRADEMENUFUNC_MAIN_MENU; - gSprites[sTradeMenuData->cursorSpriteIdx].invisible = FALSE; + gSprites[sTradeMenuData->cursorSpriteId].invisible = FALSE; } } @@ -1662,9 +1696,9 @@ static void CancelTrade_2(void) { if (gWirelessCommType) { - if (sub_80771BC() && GetNumQueuedActions() == 0) + if (IsLinkTradeTaskFinished() && GetNumQueuedActions() == 0) { - Free(sMessageBoxAllocBuffer); + Free(sMenuTextAllocBuffer); Free(sTradeMenuData); FreeAllWindowBuffers(); DestroyWirelessStatusIndicatorSprite(); @@ -1675,7 +1709,7 @@ static void CancelTrade_2(void) { if (!gReceivedRemoteLinkPlayers) { - Free(sMessageBoxAllocBuffer); + Free(sMenuTextAllocBuffer); Free(sTradeMenuData); FreeAllWindowBuffers(); SetMainCallback2(CB2_ReturnToFieldFromMultiplayer); @@ -1803,7 +1837,8 @@ static void DrawTradeMenuParty(u8 whichParty) gSprites[sTradeMenuData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]].invisible = FALSE; gSprites[sTradeMenuData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]].data[0] = 20; - gSprites[sTradeMenuData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]].data[2] = (sTradeMonSpriteCoords[selectedMonParty * PARTY_SIZE][0] + sTradeMonSpriteCoords[selectedMonParty * PARTY_SIZE + 1][0]) / 2 * 8 + 14; + gSprites[sTradeMenuData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]].data[2] = (sTradeMonSpriteCoords[selectedMonParty * PARTY_SIZE][0] + + sTradeMonSpriteCoords[selectedMonParty * PARTY_SIZE + 1][0]) / 2 * 8 + 14; gSprites[sTradeMenuData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]].data[4] = (sTradeMonSpriteCoords[selectedMonParty * PARTY_SIZE][1] * 8) - 12; StoreSpriteCallbackInData6(&gSprites[sTradeMenuData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]], SpriteCB_MonIcon); sTradeMenuData->drawPartyState[whichParty]++; @@ -1822,7 +1857,8 @@ static void DrawTradeMenuParty(u8 whichParty) case 3: CopyToBgTilemapBufferRect_ChangePalette(1, sTradeMovesBoxTilemap, selectedMonParty * 15, 0, 15, 17, 0); CopyBgTilemapBufferToVram(1); - gSprites[sTradeMenuData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]].pos1.x = (sTradeMonSpriteCoords[selectedMonParty * PARTY_SIZE][0] + sTradeMonSpriteCoords[selectedMonParty * PARTY_SIZE + 1][0]) / 2 * 8 + 14; + gSprites[sTradeMenuData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]].pos1.x = (sTradeMonSpriteCoords[selectedMonParty * PARTY_SIZE][0] + + sTradeMonSpriteCoords[selectedMonParty * PARTY_SIZE + 1][0]) / 2 * 8 + 14; gSprites[sTradeMenuData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]].pos1.y = (sTradeMonSpriteCoords[selectedMonParty * PARTY_SIZE][1] * 8) - 12; gSprites[sTradeMenuData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]].pos2.x = 0; gSprites[sTradeMenuData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]].pos2.y = 0; @@ -2035,7 +2071,7 @@ static void RedrawTradeMenuParty(u8 whichParty) DrawTradeMenuPartyInfo(whichParty); PrintPartyNicknamesForTradeMenu(whichParty); ResetTradeMenuPartyPositions(whichParty); - DrawTextWindowAndBuffer6Bytes(sTradeActionTexts[TRADE_TEXT_CHOOSE_MON], (void *)(OBJ_VRAM0 + (sTradeMenuData->bottomTextTileStart * 32)), 24); + DrawBottomRowText(sTradeActionTexts[TRADE_TEXT_CHOOSE_MON], (void *)(OBJ_VRAM0 + (sTradeMenuData->bottomTextTileStart * 32)), 24); sTradeMenuData->drawPartyState[whichParty] = 0; } @@ -2139,40 +2175,51 @@ static bool8 LoadTradeMenuSpriteSheetsAndPalettes(void) { struct SpriteSheet sheet; - if (sTradeMenuData->timer < (int)ARRAY_COUNT(sMessageBoxTileBuffers)) + if (sTradeMenuData->timer < GFXTAG_MENU_TEXT_COUNT) { - sheet.data = sMessageBoxTileBuffers[sTradeMenuData->timer]; + sheet.data = sMenuTextTileBuffers[sTradeMenuData->timer]; sheet.size = 0x100; - sheet.tag = 200 + sTradeMenuData->timer; + sheet.tag = GFXTAG_MENU_TEXT + sTradeMenuData->timer; } switch (sTradeMenuData->timer) { - case 0 ... 7: + case GFXTAG_PLAYER_NAME_L: + case GFXTAG_PLAYER_NAME_M: + case GFXTAG_PLAYER_NAME_R: + case GFXTAG_PARTNER_NAME_L: + case GFXTAG_PARTNER_NAME_M: + case GFXTAG_PARTNER_NAME_R: + case GFXTAG_CANCEL_L: + case GFXTAG_CANCEL_R: LoadSpriteSheet(&sheet); sTradeMenuData->timer++; break; - case 8: + case GFXTAG_CHOOSE_PKMN_L: sTradeMenuData->bottomTextTileStart = LoadSpriteSheet(&sheet); sTradeMenuData->timer++; break; - case 9 ... 13: + case GFXTAG_CHOOSE_PKMN_M: + case GFXTAG_CHOOSE_PKMN_R: + case GFXTAG_CHOOSE_PKMN_EMPTY_1: + case GFXTAG_CHOOSE_PKMN_EMPTY_2: + case GFXTAG_CHOOSE_PKMN_EMPTY_3: LoadSpriteSheet(&sheet); sTradeMenuData->timer++; break; - case 14: + case GFXTAG_MENU_TEXT_COUNT: LoadSpritePalette(&gSpritePalette_TradeScreenText); sTradeMenuData->timer++; break; - case 15: - LoadSpritePalette(&gUnknown_0832DC44); + case GFXTAG_MENU_TEXT_COUNT + 1: + LoadSpritePalette(&sCursor_SpritePalette); sTradeMenuData->timer++; break; - case 16: - LoadSpriteSheet(&sTradeButtonsSpriteSheet); + case GFXTAG_MENU_TEXT_COUNT + 2: + LoadSpriteSheet(&sCursor_SpriteSheet); sTradeMenuData->timer++; break; - case 17: + case GFXTAG_MENU_TEXT_COUNT + 3: sTradeMenuData->timer = 0; return TRUE; } @@ -2180,7 +2227,7 @@ static bool8 LoadTradeMenuSpriteSheetsAndPalettes(void) return FALSE; } -static void DrawTextWindowAndBuffer6Bytes(const u8 *str, u8 *dest, u8 unused) +static void DrawBottomRowText(const u8 *str, u8 *dest, u8 unused) { DrawTextWindowAndBufferTiles(str, dest, 0, 0, 6); } @@ -2564,7 +2611,7 @@ int CanSpinTradeMon(struct Pokemon *mon, u16 monIdx) return CAN_TRADE_MON; } -static void sub_807AA28(struct Sprite *sprite) +static void SpriteCB_LinkMonGlow(struct Sprite *sprite) { if (++sprite->data[0] == 10) { @@ -2573,7 +2620,7 @@ static void sub_807AA28(struct Sprite *sprite) } } -static void sub_807AA4C(struct Sprite *sprite) +static void SpriteCB_LinkMonGlowWireless(struct Sprite *sprite) { if (!sprite->invisible && ++sprite->data[0] == 10) { @@ -2582,18 +2629,19 @@ static void sub_807AA4C(struct Sprite *sprite) } } -static void sub_807AA7C(struct Sprite *sprite) +static void SpriteCB_LinkMonShadow(struct Sprite *sprite) { 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); + LoadPalette(&sLinkMonShadow_Pal[sprite->data[0]], (sprite->oam.paletteNum + 16) * 16 + 4, 2); } } -static void sub_807AABC(struct Sprite *sprite) +// Move cable down offscreen +static void SpriteCB_CableEndSending(struct Sprite *sprite) { sprite->data[0]++; sprite->pos2.y++; @@ -2602,7 +2650,8 @@ static void sub_807AABC(struct Sprite *sprite) DestroySprite(sprite); } -static void sub_807AAE0(struct Sprite *sprite) +// Move cable up onscreen +static void SpriteCB_CableEndReceiving(struct Sprite *sprite) { sprite->data[0]++; sprite->pos2.y--; @@ -2611,7 +2660,7 @@ static void sub_807AAE0(struct Sprite *sprite) DestroySprite(sprite); } -static void sub_807AB04(struct Sprite *sprite) +static void SpriteCB_GbaScreen(struct Sprite *sprite) { if (++sprite->data[0] == 15) { @@ -2665,13 +2714,13 @@ static void VBlankCB_Trade(void) static void ClearLinkTimeoutCounter(void) { sTradeData->linkTimeoutCounter = 0; - sTradeData->alwaysZero_88 = 0; - sTradeData->alwaysZero_89 = 0; + sTradeData->linkTimeoutZero1 = 0; + sTradeData->linkTimeoutZero2 = 0; } static void CheckForLinkTimeout(void) { - if (sTradeData->alwaysZero_88 == sTradeData->alwaysZero_89) + if (sTradeData->linkTimeoutZero1 == sTradeData->linkTimeoutZero2) sTradeData->linkTimeoutCounter++; else sTradeData->linkTimeoutCounter = 0; @@ -2681,11 +2730,11 @@ static void CheckForLinkTimeout(void) CloseLink(); SetMainCallback2(CB2_LinkError); sTradeData->linkTimeoutCounter = 0; - sTradeData->alwaysZero_89 = 0; - sTradeData->alwaysZero_88 = 0; + sTradeData->linkTimeoutZero2 = 0; + sTradeData->linkTimeoutZero1 = 0; } - sTradeData->alwaysZero_89 = sTradeData->alwaysZero_88; + sTradeData->linkTimeoutZero2 = sTradeData->linkTimeoutZero1; } static u32 TradeGetMultiplayerId(void) @@ -2731,9 +2780,9 @@ static void LoadTradeMonPic(u8 whichParty, u8 state) break; case 1: SetMultiuseSpriteTemplateToPokemon(GetMonSpritePalStruct(mon)->tag, pos); - sTradeData->pokePicSpriteIdxs[whichParty] = CreateSprite(&gMultiuseSpriteTemplate, 120, 60, 6); - gSprites[sTradeData->pokePicSpriteIdxs[whichParty]].invisible = TRUE; - gSprites[sTradeData->pokePicSpriteIdxs[whichParty]].callback = SpriteCallbackDummy; + sTradeData->monSpriteIds[whichParty] = CreateSprite(&gMultiuseSpriteTemplate, 120, 60, 6); + gSprites[sTradeData->monSpriteIds[whichParty]].invisible = TRUE; + gSprites[sTradeData->monSpriteIds[whichParty]].callback = SpriteCallbackDummy; break; } } @@ -3047,7 +3096,7 @@ static void TrySendTradeFinishData(void) case 1: if (IsLinkTaskFinished()) { - Trade_SendData(sTradeData); + SendBlock(bitmask_all_link_players_but_self(), sTradeData->linkData, sizeof(sTradeData->linkData)); sTradeData->sendTradeFinishState++; } // fallthrough @@ -3086,7 +3135,7 @@ static void SetTradeSequenceBgGpuRegs(u8 state) BGCNT_TXT512x256); LoadPalette(gTradeGba2_Pal, 16, 0x60); DmaCopyLarge16(3, gTradeGba_Gfx, (void *) BG_CHAR_ADDR(1), 0x1420, 0x1000); - DmaCopy16Defvars(3, gUnknown_08331F60, (void *) BG_SCREEN_ADDR(18), 0x1000); + DmaCopy16Defvars(3, gTradePlatform_Tilemap, (void *) BG_SCREEN_ADDR(18), 0x1000); break; case 1: sTradeData->bg1hofs = 0; @@ -3105,11 +3154,11 @@ static void SetTradeSequenceBgGpuRegs(u8 state) if (sTradeData->isCableTrade) { - DmaCopy16Defvars(3, sTradeTilemap_GbaCable, (void *) BG_SCREEN_ADDR(5), 0x1000); + DmaCopy16Defvars(3, sGbaCable_Tilemap, (void *) BG_SCREEN_ADDR(5), 0x1000); } else { - DmaCopy16Defvars(3, sTradeTilemap_GbaWireless, (void *) BG_SCREEN_ADDR(5), 0x1000); + DmaCopy16Defvars(3, sGbaWireless_Tilemap, (void *) BG_SCREEN_ADDR(5), 0x1000); } DmaCopyLarge16(3, gTradeGba_Gfx, (void *) BG_CHAR_ADDR(0), 0x1420, 0x1000); @@ -3127,7 +3176,7 @@ static void SetTradeSequenceBgGpuRegs(u8 state) DISPCNT_OBJ_1D_MAP | DISPCNT_BG1_ON | DISPCNT_OBJ_ON); - LZ77UnCompVram(gUnknown_083379A0, (void *) BG_SCREEN_ADDR(5)); + LZ77UnCompVram(sCrossingHighlightWireless_Tilemap, (void *) BG_SCREEN_ADDR(5)); BlendPalettes(0x8, 16, RGB_BLACK); } else @@ -3136,14 +3185,14 @@ static void SetTradeSequenceBgGpuRegs(u8 state) DISPCNT_OBJ_1D_MAP | DISPCNT_BG1_ON | DISPCNT_OBJ_ON); - DmaCopy16Defvars(3, sTradeTilemap_Cable, (void *) BG_SCREEN_ADDR(5), 0x800); + DmaCopy16Defvars(3, sCrossingHighlightCable_Tilemap, (void *) BG_SCREEN_ADDR(5), 0x800); BlendPalettes(0x1, 16, RGB_BLACK); } break; case 3: - LoadPalette(sTradePal_Black, 48, 0x20); - LZ77UnCompVram(sTradeGfx_WirelessSignal, (void *) BG_CHAR_ADDR(1)); - LZ77UnCompVram(sTradeTilemap_WirelessSignal, (void *) BG_SCREEN_ADDR(18)); + LoadPalette(sWirelessSignalNone_Pal, 48, 0x20); + LZ77UnCompVram(sWirelessSignal_Gfx, (void *) BG_CHAR_ADDR(1)); + LZ77UnCompVram(sWirelessSignal_Tilemap, (void *) BG_SCREEN_ADDR(18)); sTradeData->bg2vofs = 80; SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 | DISPCNT_OBJ_1D_MAP | @@ -3164,18 +3213,18 @@ static void SetTradeSequenceBgGpuRegs(u8 state) sTradeData->texX = 64; sTradeData->texY = 92; sTradeData->sXY = 32; - sTradeData->unk_EA = 1024; + sTradeData->gbaScale = 1024; sTradeData->alpha = 0; - DmaCopyLarge16(3, sTradeAffine_Gba, (void *) BG_CHAR_ADDR(1), 0x2840, 0x1000); + DmaCopyLarge16(3, sGbaAffine_Gfx, (void *) BG_CHAR_ADDR(1), 0x2840, 0x1000); if (sTradeData->isCableTrade) { - DmaCopy16Defvars(3, sTradeAffineMap_GbaCable, (void *) BG_SCREEN_ADDR(18), 0x100); + DmaCopy16Defvars(3, sGbaCable_AffineTilemap, (void *) BG_SCREEN_ADDR(18), 0x100); } else { - DmaCopy16Defvars(3, sTradeAffineMap_GbaWireless, (void *) BG_SCREEN_ADDR(18), 0x100); + DmaCopy16Defvars(3, sGbaWireless_AffineTilemap, (void *) BG_SCREEN_ADDR(18), 0x100); } break; case 5: @@ -3195,20 +3244,20 @@ static void SetTradeSequenceBgGpuRegs(u8 state) sTradeData->texX = 64; sTradeData->texY = 92; sTradeData->sXY = 256; - sTradeData->unk_EA = 128; + sTradeData->gbaScale = 128; sTradeData->scrX = 120; sTradeData->scrY = 80; sTradeData->alpha = 0; - DmaCopyLarge16(3, sTradeAffine_Gba, (void *) BG_CHAR_ADDR(1), 0x2840, 0x1000); + DmaCopyLarge16(3, sGbaAffine_Gfx, (void *) BG_CHAR_ADDR(1), 0x2840, 0x1000); if (sTradeData->isCableTrade) { - DmaCopy16Defvars(3, sTradeAffineMap_GbaCable, (void *) BG_SCREEN_ADDR(18), 0x100); + DmaCopy16Defvars(3, sGbaCable_AffineTilemap, (void *) BG_SCREEN_ADDR(18), 0x100); } else { - DmaCopy16Defvars(3, sTradeAffineMap_GbaWireless, (void *) BG_SCREEN_ADDR(18), 0x100); + DmaCopy16Defvars(3, sGbaWireless_AffineTilemap, (void *) BG_SCREEN_ADDR(18), 0x100); } break; case 7: @@ -3222,19 +3271,19 @@ static void SetTradeSequenceBgGpuRegs(u8 state) BGCNT_TXT512x256); LoadPalette(gTradeGba2_Pal, 16, 0x60); DmaCopyLarge16(3, gTradeGba_Gfx, (void *) BG_CHAR_ADDR(1), 0x1420, 0x1000); - DmaCopy16Defvars(3, gUnknown_08331F60, (void *) BG_SCREEN_ADDR(18), 0x1000); + DmaCopy16Defvars(3, gTradePlatform_Tilemap, (void *) BG_SCREEN_ADDR(18), 0x1000); break; } } static void LoadTradeSequenceSpriteSheetsAndPalettes(void) { - LoadSpriteSheet(&sGlow1SpriteSheet); - LoadSpriteSheet(&sGlow2SpriteSheet); - LoadSpriteSheet(&sCableEndSpriteSheet); - LoadSpriteSheet(&sGbaScreenSpriteSheet); - LoadSpritePalette(&sMiscTradeSpritePalette); - LoadSpritePalette(&sGbaSpritePalette); + LoadSpriteSheet(&sSpriteSheet_LinkMonGlow); + LoadSpriteSheet(&sSpriteSheet_LinkMonShadow); + LoadSpriteSheet(&sSpriteSheet_CableEnd); + LoadSpriteSheet(&sSpriteSheet_GbaScreen); + LoadSpritePalette(&sSpritePalette_LinkMon); + LoadSpritePalette(&sSpritePalette_Gba); } // Buffers "[Pokemon] will be sent to [Trainer]" strings @@ -3263,7 +3312,7 @@ static void BufferTradeSceneStrings(void) } } -// returns TRUE if it was a link trade, FALSE if it was an in-game trade +// returns TRUE if it finished a link trade, FALSE if it finished an in-game trade or if sequence is still going static bool8 AnimateTradeSequence(void) { if (sTradeData->isCableTrade) @@ -3272,71 +3321,146 @@ static bool8 AnimateTradeSequence(void) return AnimateTradeSequenceWireless(); } +// Below are the states for the main switch in AnimateTradeSequenceCable and AnimateTradeSequenceWireless +// When AnimateTradeSequenceWireless has a unique version of a +// state used by AnimateTradeSequenceCable, it adds the below modifier +#define TS_WIRELESS_STATE 100 +enum { + TS_STATE_START, + TS_STATE_MON_SLIDE_IN, + // 2-9 unused + TS_STATE_SEND_MSG = 10, + TS_STATE_BYE_BYE, + TS_STATE_POKEBALL_DEPART, + TS_STATE_POKEBALL_DEPART_WAIT, + TS_STATE_FADE_OUT_TO_GBA_SEND, + // 15-19 unused + TS_STATE_WAIT_FADE_OUT_TO_GBA_SEND = 20, + TS_STATE_FADE_IN_TO_GBA_SEND, + TS_STATE_WAIT_FADE_IN_TO_GBA_SEND, + TS_STATE_GBA_ZOOM_OUT, + TS_STATE_GBA_FLASH_SEND, + TS_STATE_GBA_STOP_FLASH_SEND, + TS_STATE_PAN_AWAY_GBA, + TS_STATE_CREATE_LINK_MON_LEAVING, + TS_STATE_LINK_MON_TRAVEL_OUT, + TS_STATE_FADE_OUT_TO_CROSSING, + TS_STATE_WAIT_FADE_OUT_TO_CROSSING, + TS_STATE_FADE_IN_TO_CROSSING, + TS_STATE_WAIT_FADE_IN_TO_CROSSING, + TS_STATE_CROSSING_LINK_MONS_ENTER, + TS_STATE_CROSSING_BLEND_WHITE_1, + TS_STATE_CROSSING_BLEND_WHITE_2, + TS_STATE_CROSSING_BLEND_WHITE_3, + TS_STATE_CROSSING_CREATE_MON_PICS, + TS_STATE_CROSSING_MON_PICS_MOVE, + TS_STATE_CROSSING_LINK_MONS_EXIT, + TS_STATE_CREATE_LINK_MON_ARRIVING, + TS_STATE_FADE_OUT_TO_GBA_RECV, + TS_STATE_WAIT_FADE_OUT_TO_GBA_RECV, + TS_STATE_LINK_MON_TRAVEL_IN, + TS_STATE_PAN_TO_GBA, + TS_STATE_DESTROY_LINK_MON, + TS_STATE_LINK_MON_ARRIVED_DELAY, + TS_STATE_MOVE_GBA_TO_CENTER, + TS_STATE_GBA_FLASH_RECV, + TS_STATE_UNUSED, + TS_STATE_GBA_STOP_FLASH_RECV, + TS_STATE_GBA_ZOOM_IN, + TS_STATE_FADE_OUT_TO_NEW_MON, + // 53-59 unused + TS_STATE_WAIT_FADE_OUT_TO_NEW_MON = 60, + TS_STATE_FADE_IN_TO_NEW_MON, + TS_STATE_WAIT_FADE_IN_TO_NEW_MON, + TS_STATE_POKEBALL_ARRIVE, + TS_STATE_FADE_POKEBALL_TO_NORMAL, + TS_STATE_POKEBALL_ARRIVE_WAIT, + TS_STATE_SHOW_NEW_MON, + TS_STATE_NEW_MON_MSG, + TS_STATE_TAKE_CARE_OF_MON, + TS_STATE_AFTER_NEW_MON_DELAY, + TS_STATE_CHECK_RIBBONS, + TS_STATE_END_LINK_TRADE, + TS_STATE_TRY_EVOLUTION, + TS_STATE_FADE_OUT_END, + TS_STATE_WAIT_FADE_OUT_END, + // Special states + TS_STATE_GBA_FLASH_SEND_WIRELESS = TS_STATE_GBA_FLASH_SEND + TS_WIRELESS_STATE, + TS_STATE_GBA_STOP_FLASH_SEND_WIRELESS, + TS_STATE_WAIT_WIRELESS_SIGNAL_SEND, + TS_STATE_PAN_TO_GBA_WIRELESS = TS_STATE_PAN_TO_GBA + TS_WIRELESS_STATE, + TS_STATE_DESTROY_LINK_MON_WIRELESS, + TS_STATE_WAIT_WIRELESS_SIGNAL_RECV, + TS_STATE_DELAY_FOR_MON_ANIM = 167, + TS_STATE_LINK_MON_TRAVEL_OFFSCREEN = 200, + TS_STATE_WAIT_FOR_MON_CRY = 267, +}; + static bool8 AnimateTradeSequenceCable(void) { u16 evoTarget; switch (sTradeData->state) { - case 0: - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]].invisible = FALSE; - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.x = -180; - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.y = gMonFrontPicCoords[sTradeData->monSpecies[TRADE_PLAYER]].y_offset; + case TS_STATE_START: + gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]].invisible = FALSE; + gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]].pos2.x = -180; + gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]].pos2.y = gMonFrontPicCoords[sTradeData->monSpecies[TRADE_PLAYER]].y_offset; sTradeData->state++; sTradeData->cachedMapMusic = GetCurrentMapMusic(); PlayNewMapMusic(MUS_EVOLUTION); break; - case 1: + case TS_STATE_MON_SLIDE_IN: if (sTradeData->bg2hofs > 0) { - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.x += 3; + // Sliding + gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]].pos2.x += 3; sTradeData->bg2hofs -= 3; } else { - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.x = 0; + // Pokémon has arrived onscreen + gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]].pos2.x = 0; sTradeData->bg2hofs = 0; - sTradeData->state = 10; + sTradeData->state = TS_STATE_SEND_MSG; } break; - case 10: + case TS_STATE_SEND_MSG: StringExpandPlaceholders(gStringVar4, gText_XWillBeSentToY); DrawTextOnTradeWindow(0, gStringVar4, 0); if (sTradeData->monSpecies[TRADE_PLAYER] != SPECIES_EGG) - { PlayCry1(sTradeData->monSpecies[TRADE_PLAYER], 0); - } - sTradeData->state = 11; + sTradeData->state = TS_STATE_BYE_BYE; sTradeData->timer = 0; break; - case 11: + case TS_STATE_BYE_BYE: if (++sTradeData->timer == 80) { - sTradeData->pokeballSpriteId = CreateTradePokeballSprite(sTradeData->pokePicSpriteIdxs[0], gSprites[sTradeData->pokePicSpriteIdxs[0]].oam.paletteNum, 120, 32, 2, 1, 0x14, 0xfffff); + sTradeData->releasePokeballSpriteId = CreateTradePokeballSprite(sTradeData->monSpriteIds[0], gSprites[sTradeData->monSpriteIds[0]].oam.paletteNum, 120, 32, 2, 1, 0x14, 0xfffff); sTradeData->state++; StringExpandPlaceholders(gStringVar4, gText_ByeByeVar1); DrawTextOnTradeWindow(0, gStringVar4, 0); } break; - case 12: - if (gSprites[sTradeData->pokeballSpriteId].callback == SpriteCallbackDummy) + case TS_STATE_POKEBALL_DEPART: + if (gSprites[sTradeData->releasePokeballSpriteId].callback == SpriteCallbackDummy) { - sTradeData->unk_D3 = CreateSprite(&gSpriteTemplate_8338D28, 120, 32, 0); - gSprites[sTradeData->unk_D3].callback = sub_807E5D8; - DestroySprite(&gSprites[sTradeData->pokeballSpriteId]); + sTradeData->bouncingPokeballSpriteId = CreateSprite(&sSpriteTemplate_Pokeball, 120, 32, 0); + gSprites[sTradeData->bouncingPokeballSpriteId].callback = SpriteCB_BouncingPokeballDepart; + DestroySprite(&gSprites[sTradeData->releasePokeballSpriteId]); sTradeData->state++; } break; - case 13: + case TS_STATE_POKEBALL_DEPART_WAIT: // The game waits here for the sprite to finish its animation sequence. break; - case 14: + case TS_STATE_FADE_OUT_TO_GBA_SEND: BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); - sTradeData->state = 20; + sTradeData->state = TS_STATE_WAIT_FADE_OUT_TO_GBA_SEND; break; - case 20: + case TS_STATE_WAIT_FADE_OUT_TO_GBA_SEND: if (!gPaletteFade.active) { SetTradeSequenceBgGpuRegs(4); @@ -3345,42 +3469,40 @@ static bool8 AnimateTradeSequenceCable(void) sTradeData->state++; } break; - case 21: + case TS_STATE_FADE_IN_TO_GBA_SEND: BeginNormalPaletteFade(PALETTES_ALL, -1, 16, 0, RGB_BLACK); sTradeData->state++; break; - case 22: + case TS_STATE_WAIT_FADE_IN_TO_GBA_SEND: if (!gPaletteFade.active) - { - sTradeData->state = 23; - } + sTradeData->state = TS_STATE_GBA_ZOOM_OUT; break; - case 23: - if (sTradeData->unk_EA > 0x100) + case TS_STATE_GBA_ZOOM_OUT: + if (sTradeData->gbaScale > 0x100) { - sTradeData->unk_EA -= 0x34; + sTradeData->gbaScale -= 0x34; } else { SetTradeSequenceBgGpuRegs(1); - sTradeData->unk_EA = 0x80; + sTradeData->gbaScale = 0x80; sTradeData->state++; sTradeData->timer = 0; } - sTradeData->sXY = 0x8000 / sTradeData->unk_EA; + sTradeData->sXY = 0x8000 / sTradeData->gbaScale; break; - case 24: + case TS_STATE_GBA_FLASH_SEND: if (++sTradeData->timer > 20) { SetTradeBGAffine(); - sTradeData->unk_91 = CreateSprite(&gSpriteTemplate_8338E74, 120, 80, 0); + sTradeData->connectionSpriteId2 = CreateSprite(&sSpriteTemplate_GbaScreenFlash_Long, 120, 80, 0); sTradeData->state++; } break; - case 25: - if (gSprites[sTradeData->unk_91].animEnded) + case TS_STATE_GBA_STOP_FLASH_SEND: + if (gSprites[sTradeData->connectionSpriteId2].animEnded) { - DestroySprite(&gSprites[sTradeData->unk_91]); + DestroySprite(&gSprites[sTradeData->connectionSpriteId2]); SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_BG1 | BLDCNT_TGT2_BG2); @@ -3388,193 +3510,183 @@ static bool8 AnimateTradeSequenceCable(void) sTradeData->state++; } break; - case 26: + case TS_STATE_PAN_AWAY_GBA: if (--sTradeData->bg1vofs == 316) - { sTradeData->state++; - } + if (sTradeData->bg1vofs == 328) - { - sTradeData->unk_92 = CreateSprite(&gSpriteTemplate_8338DFC, 128, 65, 0); - } + sTradeData->cableEndSpriteId = CreateSprite(&sSpriteTemplate_CableEnd, 128, 65, 0); break; - case 27: - sTradeData->unk_90 = CreateSprite(&gUnknown_08338D88, 128, 80, 3); - sTradeData->unk_91 = CreateSprite(&sGlowBallSpriteTemplate, 128, 80, 0); - StartSpriteAnim(&gSprites[sTradeData->unk_91], 1); + case TS_STATE_CREATE_LINK_MON_LEAVING: + sTradeData->connectionSpriteId1 = CreateSprite(&sSpriteTemplate_LinkMonGlow, 128, 80, 3); + sTradeData->connectionSpriteId2 = CreateSprite(&sSpriteTemplate_LinkMonShadow, 128, 80, 0); + StartSpriteAnim(&gSprites[sTradeData->connectionSpriteId2], ANIM_LINKMON_SMALL); sTradeData->state++; break; - case 28: + case TS_STATE_LINK_MON_TRAVEL_OUT: if ((sTradeData->bg1vofs -= 2) == 166) - { - sTradeData->state = 200; - } + sTradeData->state = TS_STATE_LINK_MON_TRAVEL_OFFSCREEN; + SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_1 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG1_ON | DISPCNT_OBJ_ON); break; - case 200: - gSprites[sTradeData->unk_90].pos1.y -= 2; - gSprites[sTradeData->unk_91].pos1.y -= 2; - if (gSprites[sTradeData->unk_90].pos1.y < -8) - { - sTradeData->state = 29; - } + case TS_STATE_LINK_MON_TRAVEL_OFFSCREEN: + gSprites[sTradeData->connectionSpriteId1].pos1.y -= 2; + gSprites[sTradeData->connectionSpriteId2].pos1.y -= 2; + if (gSprites[sTradeData->connectionSpriteId1].pos1.y < -8) + sTradeData->state = TS_STATE_FADE_OUT_TO_CROSSING; break; - case 29: + case TS_STATE_FADE_OUT_TO_CROSSING: BeginNormalPaletteFade(PALETTES_ALL, -1, 0, 16, RGB_BLACK); - sTradeData->state = 30; + sTradeData->state = TS_STATE_WAIT_FADE_OUT_TO_CROSSING; break; - case 30: + case TS_STATE_WAIT_FADE_OUT_TO_CROSSING: if (!gPaletteFade.active) { - DestroySprite(&gSprites[sTradeData->unk_90]); - DestroySprite(&gSprites[sTradeData->unk_91]); + DestroySprite(&gSprites[sTradeData->connectionSpriteId1]); + DestroySprite(&gSprites[sTradeData->connectionSpriteId2]); SetTradeSequenceBgGpuRegs(2); sTradeData->state++; } break; - case 31: + case TS_STATE_FADE_IN_TO_CROSSING: BeginNormalPaletteFade(PALETTES_ALL, -1, 16, 0, RGB_BLACK); - sTradeData->unk_90 = CreateSprite(&sGlowBallSpriteTemplate, 111, 170, 0); - sTradeData->unk_91 = CreateSprite(&sGlowBallSpriteTemplate, 129, -10, 0); + sTradeData->connectionSpriteId1 = CreateSprite(&sSpriteTemplate_LinkMonShadow, 111, 170, 0); + sTradeData->connectionSpriteId2 = CreateSprite(&sSpriteTemplate_LinkMonShadow, 129, -10, 0); sTradeData->state++; break; - case 32: + case TS_STATE_WAIT_FADE_IN_TO_CROSSING: if (!gPaletteFade.active) { PlaySE(SE_WARP_OUT); sTradeData->state++; } - gSprites[sTradeData->unk_90].pos2.y -= 3; - gSprites[sTradeData->unk_91].pos2.y += 3; + gSprites[sTradeData->connectionSpriteId1].pos2.y -= 3; + gSprites[sTradeData->connectionSpriteId2].pos2.y += 3; break; - case 33: - gSprites[sTradeData->unk_90].pos2.y -= 3; - gSprites[sTradeData->unk_91].pos2.y += 3; - if (gSprites[sTradeData->unk_90].pos2.y <= -90) + case TS_STATE_CROSSING_LINK_MONS_ENTER: + gSprites[sTradeData->connectionSpriteId1].pos2.y -= 3; + gSprites[sTradeData->connectionSpriteId2].pos2.y += 3; + if (gSprites[sTradeData->connectionSpriteId1].pos2.y <= -90) { - gSprites[sTradeData->unk_90].data[1] = 1; - gSprites[sTradeData->unk_91].data[1] = 1; + gSprites[sTradeData->connectionSpriteId1].data[1] = 1; + gSprites[sTradeData->connectionSpriteId2].data[1] = 1; sTradeData->state++; } break; - case 34: + case TS_STATE_CROSSING_BLEND_WHITE_1: BlendPalettes(0x1, 16, RGB_WHITEALPHA); sTradeData->state++; break; - case 35: + case TS_STATE_CROSSING_BLEND_WHITE_2: BlendPalettes(0x1, 0, RGB_WHITEALPHA); sTradeData->state++; break; - case 36: + case TS_STATE_CROSSING_BLEND_WHITE_3: BlendPalettes(0x1, 16, RGB_WHITEALPHA); sTradeData->state++; break; - case 37: + case TS_STATE_CROSSING_CREATE_MON_PICS: if (!IsMonSpriteNotFlipped(sTradeData->monSpecies[TRADE_PLAYER])) { - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]].affineAnims = gSpriteAffineAnimTable_8338ECC; - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]].oam.affineMode = ST_OAM_AFFINE_DOUBLE; - CalcCenterToCornerVec(&gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]], SPRITE_SHAPE(64x64), SPRITE_SIZE(64x64), ST_OAM_AFFINE_DOUBLE); - StartSpriteAffineAnim(&gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]], 0); + gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]].affineAnims = sAffineAnims_CrossingMonPics; + gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]].oam.affineMode = ST_OAM_AFFINE_DOUBLE; + CalcCenterToCornerVec(&gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]], SPRITE_SHAPE(64x64), SPRITE_SIZE(64x64), ST_OAM_AFFINE_DOUBLE); + StartSpriteAffineAnim(&gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]], 0); } else { - StartSpriteAffineAnim(&gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]], 0); + StartSpriteAffineAnim(&gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]], 0); } - StartSpriteAffineAnim(&gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PARTNER]], 0); - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]].pos1.x = 60; - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PARTNER]].pos1.x = 180; - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]].pos1.y = 192; - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PARTNER]].pos1.y = -32; - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]].invisible = FALSE; - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PARTNER]].invisible = FALSE; + StartSpriteAffineAnim(&gSprites[sTradeData->monSpriteIds[TRADE_PARTNER]], 0); + gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]].pos1.x = 60; + gSprites[sTradeData->monSpriteIds[TRADE_PARTNER]].pos1.x = 180; + gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]].pos1.y = 192; + gSprites[sTradeData->monSpriteIds[TRADE_PARTNER]].pos1.y = -32; + gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]].invisible = FALSE; + gSprites[sTradeData->monSpriteIds[TRADE_PARTNER]].invisible = FALSE; sTradeData->state++; break; - case 38: - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.y -= 3; - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PARTNER]].pos2.y += 3; - if (gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.y < -DISPLAY_HEIGHT - && gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.y >= -DISPLAY_HEIGHT - 3) + case TS_STATE_CROSSING_MON_PICS_MOVE: + gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]].pos2.y -= 3; + gSprites[sTradeData->monSpriteIds[TRADE_PARTNER]].pos2.y += 3; + if (gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]].pos2.y < -DISPLAY_HEIGHT + && gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]].pos2.y >= -DISPLAY_HEIGHT - 3) { PlaySE(SE_WARP_IN); } - if (gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.y < -222) + if (gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]].pos2.y < -222) { - gSprites[sTradeData->unk_90].data[1] = 0; - gSprites[sTradeData->unk_91].data[1] = 0; + gSprites[sTradeData->connectionSpriteId1].data[1] = 0; + gSprites[sTradeData->connectionSpriteId2].data[1] = 0; sTradeData->state++; - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]].invisible = TRUE; - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PARTNER]].invisible = TRUE; + gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]].invisible = TRUE; + gSprites[sTradeData->monSpriteIds[TRADE_PARTNER]].invisible = TRUE; BlendPalettes(0x1, 0, RGB_WHITEALPHA); } break; - case 39: - gSprites[sTradeData->unk_90].pos2.y -= 3; - gSprites[sTradeData->unk_91].pos2.y += 3; - if (gSprites[sTradeData->unk_90].pos2.y <= -222) + case TS_STATE_CROSSING_LINK_MONS_EXIT: + gSprites[sTradeData->connectionSpriteId1].pos2.y -= 3; + gSprites[sTradeData->connectionSpriteId2].pos2.y += 3; + if (gSprites[sTradeData->connectionSpriteId1].pos2.y <= -222) { BeginNormalPaletteFade(PALETTES_ALL, -1, 0, 16, RGB_BLACK); sTradeData->state++; - DestroySprite(&gSprites[sTradeData->unk_90]); - DestroySprite(&gSprites[sTradeData->unk_91]); + DestroySprite(&gSprites[sTradeData->connectionSpriteId1]); + DestroySprite(&gSprites[sTradeData->connectionSpriteId2]); } break; - case 40: + case TS_STATE_CREATE_LINK_MON_ARRIVING: if (!gPaletteFade.active) { sTradeData->state++; SetTradeSequenceBgGpuRegs(1); sTradeData->bg1vofs = 166; - sTradeData->unk_90 = CreateSprite(&gUnknown_08338D88, 128, -20, 3); - sTradeData->unk_91 = CreateSprite(&sGlowBallSpriteTemplate, 128, -20, 0); - StartSpriteAnim(&gSprites[sTradeData->unk_91], 1); + sTradeData->connectionSpriteId1 = CreateSprite(&sSpriteTemplate_LinkMonGlow, 128, -20, 3); + sTradeData->connectionSpriteId2 = CreateSprite(&sSpriteTemplate_LinkMonShadow, 128, -20, 0); + StartSpriteAnim(&gSprites[sTradeData->connectionSpriteId2], ANIM_LINKMON_SMALL); } break; - case 41: + case TS_STATE_FADE_OUT_TO_GBA_RECV: BeginNormalPaletteFade(PALETTES_ALL, -1, 16, 0, RGB_BLACK); sTradeData->state++; break; - case 42: + case TS_STATE_WAIT_FADE_OUT_TO_GBA_RECV: SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG1_ON | DISPCNT_OBJ_ON); if (!gPaletteFade.active) + sTradeData->state++; + break; + case TS_STATE_LINK_MON_TRAVEL_IN: + gSprites[sTradeData->connectionSpriteId1].pos2.y += 3; + gSprites[sTradeData->connectionSpriteId2].pos2.y += 3; + if (gSprites[sTradeData->connectionSpriteId1].pos2.y + gSprites[sTradeData->connectionSpriteId1].pos1.y == 64) { sTradeData->state++; } break; - case 43: - gSprites[sTradeData->unk_90].pos2.y += 3; - gSprites[sTradeData->unk_91].pos2.y += 3; - if (gSprites[sTradeData->unk_90].pos2.y + gSprites[sTradeData->unk_90].pos1.y == 64) - { - sTradeData->state++; - } - break; - case 44: + case TS_STATE_PAN_TO_GBA: if ((sTradeData->bg1vofs += 2) > 316) { sTradeData->bg1vofs = 316; sTradeData->state++; } break; - case 45: - DestroySprite(&gSprites[sTradeData->unk_90]); - DestroySprite(&gSprites[sTradeData->unk_91]); + case TS_STATE_DESTROY_LINK_MON: + DestroySprite(&gSprites[sTradeData->connectionSpriteId1]); + DestroySprite(&gSprites[sTradeData->connectionSpriteId2]); sTradeData->state++; sTradeData->timer = 0; break; - case 46: + case TS_STATE_LINK_MON_ARRIVED_DELAY: if (++sTradeData->timer == 10) - { sTradeData->state++; - } break; - case 47: + case TS_STATE_MOVE_GBA_TO_CENTER: if (++sTradeData->bg1vofs > 348) { sTradeData->bg1vofs = 348; @@ -3582,41 +3694,41 @@ static bool8 AnimateTradeSequenceCable(void) } if (sTradeData->bg1vofs == 328 && sTradeData->isCableTrade) { - sTradeData->unk_92 = CreateSprite(&gSpriteTemplate_8338DFC, 128, 65, 0); - gSprites[sTradeData->unk_92].callback = sub_807AAE0; + sTradeData->cableEndSpriteId = CreateSprite(&sSpriteTemplate_CableEnd, 128, 65, 0); + gSprites[sTradeData->cableEndSpriteId].callback = SpriteCB_CableEndReceiving; } break; - case 48: - sTradeData->unk_91 = CreateSprite(&gSpriteTemplate_8338E74, 120, 80, 0); - sTradeData->state = 50; + case TS_STATE_GBA_FLASH_RECV: + sTradeData->connectionSpriteId2 = CreateSprite(&sSpriteTemplate_GbaScreenFlash_Long, 120, 80, 0); + sTradeData->state = TS_STATE_GBA_STOP_FLASH_RECV; break; - case 50: - if (gSprites[sTradeData->unk_91].animEnded) + case TS_STATE_GBA_STOP_FLASH_RECV: + if (gSprites[sTradeData->connectionSpriteId2].animEnded) { - DestroySprite(&gSprites[sTradeData->unk_91]); + DestroySprite(&gSprites[sTradeData->connectionSpriteId2]); SetTradeSequenceBgGpuRegs(6); sTradeData->state++; PlaySE(SE_M_SAND_ATTACK); } break; - case 51: - if (sTradeData->unk_EA < 0x400) + case TS_STATE_GBA_ZOOM_IN: + if (sTradeData->gbaScale < 0x400) { - sTradeData->unk_EA += 0x34; + sTradeData->gbaScale += 0x34; } else { - sTradeData->unk_EA = 0x400; + sTradeData->gbaScale = 0x400; sTradeData->state++; } - sTradeData->sXY = 0x8000 / sTradeData->unk_EA; + sTradeData->sXY = 0x8000 / sTradeData->gbaScale; break; - case 52: + case TS_STATE_FADE_OUT_TO_NEW_MON: BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); - sTradeData->state = 60; + sTradeData->state = TS_STATE_WAIT_FADE_OUT_TO_NEW_MON; break; - case 60: + case TS_STATE_WAIT_FADE_OUT_TO_NEW_MON: if (!gPaletteFade.active) { SetTradeSequenceBgGpuRegs(5); @@ -3625,54 +3737,52 @@ static bool8 AnimateTradeSequenceCable(void) sTradeData->state++; } break; - case 61: + case TS_STATE_FADE_IN_TO_NEW_MON: gPaletteFade.bufferTransferDisabled = FALSE; BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK); sTradeData->state++; break; - case 62: + case TS_STATE_WAIT_FADE_IN_TO_NEW_MON: SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG2_ON | DISPCNT_OBJ_ON); if (!gPaletteFade.active) - { sTradeData->state++; - } break; - case 63: - sTradeData->unk_D3 = CreateSprite(&gSpriteTemplate_8338D28, 120, -8, 0); - gSprites[sTradeData->unk_D3].data[3] = 74; - gSprites[sTradeData->unk_D3].callback = sub_807E6AC; - StartSpriteAnim(&gSprites[sTradeData->unk_D3], 1); - StartSpriteAffineAnim(&gSprites[sTradeData->unk_D3], 2); - BlendPalettes(1 << (16 + gSprites[sTradeData->unk_D3].oam.paletteNum), 16, RGB_WHITEALPHA); + case TS_STATE_POKEBALL_ARRIVE: + sTradeData->bouncingPokeballSpriteId = CreateSprite(&sSpriteTemplate_Pokeball, 120, -8, 0); + gSprites[sTradeData->bouncingPokeballSpriteId].data[3] = 74; + gSprites[sTradeData->bouncingPokeballSpriteId].callback = SpriteCB_BouncingPokeballArrive; + StartSpriteAnim(&gSprites[sTradeData->bouncingPokeballSpriteId], 1); + StartSpriteAffineAnim(&gSprites[sTradeData->bouncingPokeballSpriteId], 2); + BlendPalettes(1 << (16 + gSprites[sTradeData->bouncingPokeballSpriteId].oam.paletteNum), 16, RGB_WHITEALPHA); sTradeData->state++; sTradeData->timer = 0; break; - case 64: - BeginNormalPaletteFade(1 << (16 + gSprites[sTradeData->unk_D3].oam.paletteNum), 1, 16, 0, RGB_WHITEALPHA); + case TS_STATE_FADE_POKEBALL_TO_NORMAL: + BeginNormalPaletteFade(1 << (16 + gSprites[sTradeData->bouncingPokeballSpriteId].oam.paletteNum), 1, 16, 0, RGB_WHITEALPHA); sTradeData->state++; break; - case 65: - if (gSprites[sTradeData->unk_D3].callback == SpriteCallbackDummy) + case TS_STATE_POKEBALL_ARRIVE_WAIT: + if (gSprites[sTradeData->bouncingPokeballSpriteId].callback == SpriteCallbackDummy) { HandleLoadSpecialPokePic_2(&gMonFrontPicTable[sTradeData->monSpecies[TRADE_PARTNER]], gMonSpritesGfxPtr->sprites.ptr[3], sTradeData->monSpecies[TRADE_PARTNER], sTradeData->monPersonalities[TRADE_PARTNER]); sTradeData->state++; } break; - case 66: - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PARTNER]].pos1.x = 120; - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PARTNER]].pos1.y = gMonFrontPicCoords[sTradeData->monSpecies[TRADE_PARTNER]].y_offset + 60; - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PARTNER]].pos2.x = 0; - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PARTNER]].pos2.y = 0; - StartSpriteAnim(&gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PARTNER]], 0); - CreatePokeballSpriteToReleaseMon(sTradeData->pokePicSpriteIdxs[TRADE_PARTNER], gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PARTNER]].oam.paletteNum, 120, 84, 2, 1, 20, 0xFFFFF, sTradeData->monSpecies[TRADE_PARTNER]); - FreeSpriteOamMatrix(&gSprites[sTradeData->unk_D3]); - DestroySprite(&gSprites[sTradeData->unk_D3]); + case TS_STATE_SHOW_NEW_MON: + gSprites[sTradeData->monSpriteIds[TRADE_PARTNER]].pos1.x = 120; + gSprites[sTradeData->monSpriteIds[TRADE_PARTNER]].pos1.y = gMonFrontPicCoords[sTradeData->monSpecies[TRADE_PARTNER]].y_offset + 60; + gSprites[sTradeData->monSpriteIds[TRADE_PARTNER]].pos2.x = 0; + gSprites[sTradeData->monSpriteIds[TRADE_PARTNER]].pos2.y = 0; + StartSpriteAnim(&gSprites[sTradeData->monSpriteIds[TRADE_PARTNER]], 0); + CreatePokeballSpriteToReleaseMon(sTradeData->monSpriteIds[TRADE_PARTNER], gSprites[sTradeData->monSpriteIds[TRADE_PARTNER]].oam.paletteNum, 120, 84, 2, 1, 20, 0xFFFFF, sTradeData->monSpecies[TRADE_PARTNER]); + FreeSpriteOamMatrix(&gSprites[sTradeData->bouncingPokeballSpriteId]); + DestroySprite(&gSprites[sTradeData->bouncingPokeballSpriteId]); sTradeData->state++; break; - case 67: + case TS_STATE_NEW_MON_MSG: SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG0_ON | @@ -3680,28 +3790,24 @@ static bool8 AnimateTradeSequenceCable(void) DISPCNT_OBJ_ON); StringExpandPlaceholders(gStringVar4, gText_XSentOverY); DrawTextOnTradeWindow(0, gStringVar4, 0); - sTradeData->state = 167; + sTradeData->state = TS_STATE_DELAY_FOR_MON_ANIM; sTradeData->timer = 0; break; - // 167 and 267 are extra cases added in for animations - case 167: + case TS_STATE_DELAY_FOR_MON_ANIM: if (++sTradeData->timer > 60) { - sTradeData->state = 267; + sTradeData->state = TS_STATE_WAIT_FOR_MON_CRY; sTradeData->timer = 0; } break; - case 267: + case TS_STATE_WAIT_FOR_MON_CRY: if (IsCryFinished()) - { - sTradeData->state = 68; - } + sTradeData->state = TS_STATE_TAKE_CARE_OF_MON; break; - case 68: + case TS_STATE_TAKE_CARE_OF_MON: if (++sTradeData->timer == 10) - { PlayFanfare(MUS_EVOLVED); - } + if (sTradeData->timer == 250) { sTradeData->state++; @@ -3710,17 +3816,15 @@ static bool8 AnimateTradeSequenceCable(void) sTradeData->timer = 0; } break; - case 69: + case TS_STATE_AFTER_NEW_MON_DELAY: if (++sTradeData->timer == 60) - { sTradeData->state++; - } break; - case 70: + case TS_STATE_CHECK_RIBBONS: CheckPartnersMonForRibbons(); sTradeData->state++; break; - case 71: + case TS_STATE_END_LINK_TRADE: if (sTradeData->isLinkTrade) { return TRUE; @@ -3730,21 +3834,21 @@ static bool8 AnimateTradeSequenceCable(void) sTradeData->state++; } break; - case 72: // Only if in-game trade + case TS_STATE_TRY_EVOLUTION: // Only if in-game trade, link trades use CB2_TryLinkTradeEvolution TradeMons(gSpecialVar_0x8005, 0); gCB2_AfterEvolution = CB2_UpdateInGameTrade; evoTarget = GetEvolutionTargetSpecies(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], EVO_MODE_TRADE, ITEM_NONE); if (evoTarget != SPECIES_NONE) { - TradeEvolutionScene(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], evoTarget, sTradeData->pokePicSpriteIdxs[TRADE_PARTNER], gSelectedTradeMonPositions[TRADE_PLAYER]); + TradeEvolutionScene(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], evoTarget, sTradeData->monSpriteIds[TRADE_PARTNER], gSelectedTradeMonPositions[TRADE_PLAYER]); } sTradeData->state++; break; - case 73: + case TS_STATE_FADE_OUT_END: BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); sTradeData->state++; break; - case 74: + case TS_STATE_WAIT_FADE_OUT_END: if (!gPaletteFade.active) { PlayNewMapMusic(sTradeData->cachedMapMusic); @@ -3771,65 +3875,63 @@ static bool8 AnimateTradeSequenceWireless(void) switch (sTradeData->state) { - case 0: - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]].invisible = FALSE; - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.x = -180; - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.y = gMonFrontPicCoords[sTradeData->monSpecies[TRADE_PLAYER]].y_offset; + case TS_STATE_START: + gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]].invisible = FALSE; + gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]].pos2.x = -180; + gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]].pos2.y = gMonFrontPicCoords[sTradeData->monSpecies[TRADE_PLAYER]].y_offset; sTradeData->state++; sTradeData->cachedMapMusic = GetCurrentMapMusic(); PlayNewMapMusic(MUS_EVOLUTION); break; - case 1: + case TS_STATE_MON_SLIDE_IN: if (sTradeData->bg2hofs > 0) { - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.x += 3; + gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]].pos2.x += 3; sTradeData->bg2hofs -= 3; } else { - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.x = 0; + gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]].pos2.x = 0; sTradeData->bg2hofs = 0; - sTradeData->state = 10; + sTradeData->state = TS_STATE_SEND_MSG; } break; - case 10: + case TS_STATE_SEND_MSG: StringExpandPlaceholders(gStringVar4, gText_XWillBeSentToY); DrawTextOnTradeWindow(0, gStringVar4, 0); if (sTradeData->monSpecies[TRADE_PLAYER] != SPECIES_EGG) - { PlayCry1(sTradeData->monSpecies[TRADE_PLAYER], 0); - } - sTradeData->state = 11; + sTradeData->state = TS_STATE_BYE_BYE; sTradeData->timer = 0; break; - case 11: + case TS_STATE_BYE_BYE: if (++sTradeData->timer == 80) { - sTradeData->pokeballSpriteId = CreateTradePokeballSprite(sTradeData->pokePicSpriteIdxs[0], gSprites[sTradeData->pokePicSpriteIdxs[0]].oam.paletteNum, 120, 32, 2, 1, 0x14, 0xfffff); + sTradeData->releasePokeballSpriteId = CreateTradePokeballSprite(sTradeData->monSpriteIds[0], gSprites[sTradeData->monSpriteIds[0]].oam.paletteNum, 120, 32, 2, 1, 0x14, 0xfffff); sTradeData->state++; StringExpandPlaceholders(gStringVar4, gText_ByeByeVar1); DrawTextOnTradeWindow(0, gStringVar4, 0); } break; - case 12: - if (gSprites[sTradeData->pokeballSpriteId].callback == SpriteCallbackDummy) + case TS_STATE_POKEBALL_DEPART: + if (gSprites[sTradeData->releasePokeballSpriteId].callback == SpriteCallbackDummy) { - sTradeData->unk_D3 = CreateSprite(&gSpriteTemplate_8338D28, 120, 32, 0); - gSprites[sTradeData->unk_D3].callback = sub_807E5D8; - DestroySprite(&gSprites[sTradeData->pokeballSpriteId]); + sTradeData->bouncingPokeballSpriteId = CreateSprite(&sSpriteTemplate_Pokeball, 120, 32, 0); + gSprites[sTradeData->bouncingPokeballSpriteId].callback = SpriteCB_BouncingPokeballDepart; + DestroySprite(&gSprites[sTradeData->releasePokeballSpriteId]); sTradeData->state++; } break; - case 13: + case TS_STATE_POKEBALL_DEPART_WAIT: // The game waits here for the sprite to finish its animation sequence. break; - case 14: + case TS_STATE_FADE_OUT_TO_GBA_SEND: BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); - sTradeData->state = 20; + sTradeData->state = TS_STATE_WAIT_FADE_OUT_TO_GBA_SEND; break; - case 20: + case TS_STATE_WAIT_FADE_OUT_TO_GBA_SEND: if (!gPaletteFade.active) { SetTradeSequenceBgGpuRegs(4); @@ -3838,190 +3940,185 @@ static bool8 AnimateTradeSequenceWireless(void) sTradeData->state++; } break; - case 21: + case TS_STATE_FADE_IN_TO_GBA_SEND: BeginNormalPaletteFade(PALETTES_ALL, -1, 16, 0, RGB_BLACK); sTradeData->state++; break; - case 22: + case TS_STATE_WAIT_FADE_IN_TO_GBA_SEND: if (!gPaletteFade.active) - { - sTradeData->state = 23; - } + sTradeData->state = TS_STATE_GBA_ZOOM_OUT; break; - case 23: - if (sTradeData->unk_EA > 0x100) + case TS_STATE_GBA_ZOOM_OUT: + if (sTradeData->gbaScale > 0x100) { - sTradeData->unk_EA -= 0x34; + sTradeData->gbaScale -= 0x34; } else { SetTradeSequenceBgGpuRegs(1); - sTradeData->unk_EA = 0x80; - sTradeData->state = 124; + sTradeData->gbaScale = 0x80; + sTradeData->state = TS_STATE_GBA_FLASH_SEND_WIRELESS; sTradeData->timer = 0; } - sTradeData->sXY = 0x8000 / sTradeData->unk_EA; + sTradeData->sXY = 0x8000 / sTradeData->gbaScale; break; - case 124: + case TS_STATE_GBA_FLASH_SEND_WIRELESS: if (++sTradeData->timer > 20) { SetTradeSequenceBgGpuRegs(3); - sTradeData->unk_91 = CreateSprite(&gSpriteTemplate_8338E8C, 120, 80, 0); + sTradeData->connectionSpriteId2 = CreateSprite(&sSpriteTemplate_GbaScreenFlash_Short, 120, 80, 0); sTradeData->state++; } break; - case 125: - if (gSprites[sTradeData->unk_91].animEnded) + case TS_STATE_GBA_STOP_FLASH_SEND_WIRELESS: + if (gSprites[sTradeData->connectionSpriteId2].animEnded) { - DestroySprite(&gSprites[sTradeData->unk_91]); + DestroySprite(&gSprites[sTradeData->connectionSpriteId2]); SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG1 | BLDCNT_TGT1_OBJ | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_BG2); SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(16, 4)); + + // Start wireless signal effect CreateTask(Task_AnimateWirelessSignal, 5); sTradeData->state++; } break; - case 126: + case TS_STATE_WAIT_WIRELESS_SIGNAL_SEND: if (!FuncIsActiveTask(Task_AnimateWirelessSignal)) - { - sTradeData->state = 26; - } + sTradeData->state = TS_STATE_PAN_AWAY_GBA; break; - case 26: + case TS_STATE_PAN_AWAY_GBA: if (--sTradeData->bg1vofs == 316) - { sTradeData->state++; - } break; - case 27: - sTradeData->unk_90 = CreateSprite(&gUnknown_08338D88, 120, 80, 3); - gSprites[sTradeData->unk_90].callback = sub_807AA4C; - sTradeData->unk_91 = CreateSprite(&sGlowBallSpriteTemplate, 120, 80, 0); - StartSpriteAnim(&gSprites[sTradeData->unk_91], 1); + case TS_STATE_CREATE_LINK_MON_LEAVING: + sTradeData->connectionSpriteId1 = CreateSprite(&sSpriteTemplate_LinkMonGlow, 120, 80, 3); + gSprites[sTradeData->connectionSpriteId1].callback = SpriteCB_LinkMonGlowWireless; + sTradeData->connectionSpriteId2 = CreateSprite(&sSpriteTemplate_LinkMonShadow, 120, 80, 0); + StartSpriteAnim(&gSprites[sTradeData->connectionSpriteId2], ANIM_LINKMON_SMALL); sTradeData->state++; break; - case 28: + case TS_STATE_LINK_MON_TRAVEL_OUT: if ((sTradeData->bg1vofs -= 3) == 166) - { - sTradeData->state = 200; - } + sTradeData->state = TS_STATE_LINK_MON_TRAVEL_OFFSCREEN; + SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_1 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG1_ON | DISPCNT_OBJ_ON); break; - case 200: - gSprites[sTradeData->unk_90].pos1.y -= 2; - gSprites[sTradeData->unk_91].pos1.y -= 2; - if (gSprites[sTradeData->unk_90].pos1.y < -8) + case TS_STATE_LINK_MON_TRAVEL_OFFSCREEN: + gSprites[sTradeData->connectionSpriteId1].pos1.y -= 2; + gSprites[sTradeData->connectionSpriteId2].pos1.y -= 2; + if (gSprites[sTradeData->connectionSpriteId1].pos1.y < -8) { - sTradeData->state = 29; + sTradeData->state = TS_STATE_FADE_OUT_TO_CROSSING; } break; - case 29: + case TS_STATE_FADE_OUT_TO_CROSSING: BeginNormalPaletteFade(PALETTES_ALL, -1, 0, 16, RGB_BLACK); - sTradeData->state = 30; + sTradeData->state = TS_STATE_WAIT_FADE_OUT_TO_CROSSING; break; - case 30: + case TS_STATE_WAIT_FADE_OUT_TO_CROSSING: if (!gPaletteFade.active) { - DestroySprite(&gSprites[sTradeData->unk_90]); - DestroySprite(&gSprites[sTradeData->unk_91]); + DestroySprite(&gSprites[sTradeData->connectionSpriteId1]); + DestroySprite(&gSprites[sTradeData->connectionSpriteId2]); SetTradeSequenceBgGpuRegs(2); sTradeData->state++; } break; - case 31: + case TS_STATE_FADE_IN_TO_CROSSING: BeginNormalPaletteFade(PALETTES_ALL, -1, 16, 0, RGB_BLACK); - sTradeData->unk_90 = CreateSprite(&sGlowBallSpriteTemplate, 111, 170, 0); - sTradeData->unk_91 = CreateSprite(&sGlowBallSpriteTemplate, 129, -10, 0); + sTradeData->connectionSpriteId1 = CreateSprite(&sSpriteTemplate_LinkMonShadow, 111, 170, 0); + sTradeData->connectionSpriteId2 = CreateSprite(&sSpriteTemplate_LinkMonShadow, 129, -10, 0); sTradeData->state++; break; - case 32: + case TS_STATE_WAIT_FADE_IN_TO_CROSSING: if (!gPaletteFade.active) { PlaySE(SE_WARP_OUT); sTradeData->state++; } - gSprites[sTradeData->unk_90].pos2.y -= 3; - gSprites[sTradeData->unk_91].pos2.y += 3; + gSprites[sTradeData->connectionSpriteId1].pos2.y -= 3; + gSprites[sTradeData->connectionSpriteId2].pos2.y += 3; break; - case 33: - gSprites[sTradeData->unk_90].pos2.y -= 3; - gSprites[sTradeData->unk_91].pos2.y += 3; - if (gSprites[sTradeData->unk_90].pos2.y <= -90) + case TS_STATE_CROSSING_LINK_MONS_ENTER: + gSprites[sTradeData->connectionSpriteId1].pos2.y -= 3; + gSprites[sTradeData->connectionSpriteId2].pos2.y += 3; + if (gSprites[sTradeData->connectionSpriteId1].pos2.y <= -90) { - gSprites[sTradeData->unk_90].data[1] = 1; - gSprites[sTradeData->unk_91].data[1] = 1; + gSprites[sTradeData->connectionSpriteId1].data[1] = 1; + gSprites[sTradeData->connectionSpriteId2].data[1] = 1; sTradeData->state++; - CreateTask(c3_0805465C, 5); + CreateTask(Task_NarrowWindowForCrossing_Wireless, 5); } break; - case 34: + case TS_STATE_CROSSING_BLEND_WHITE_1: BlendPalettes(0x8, 16, RGB_WHITEALPHA); sTradeData->state++; break; - case 35: + case TS_STATE_CROSSING_BLEND_WHITE_2: BlendPalettes(0x8, 16, RGB_WHITEALPHA); sTradeData->state++; break; - case 36: + case TS_STATE_CROSSING_BLEND_WHITE_3: BlendPalettes(0x8, 16, RGB_WHITEALPHA); sTradeData->state++; break; - case 37: + case TS_STATE_CROSSING_CREATE_MON_PICS: if (!IsMonSpriteNotFlipped(sTradeData->monSpecies[TRADE_PLAYER])) { - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]].affineAnims = gSpriteAffineAnimTable_8338ECC; - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]].oam.affineMode = ST_OAM_AFFINE_DOUBLE; - CalcCenterToCornerVec(&gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]], SPRITE_SHAPE(64x64), SPRITE_SIZE(64x64), ST_OAM_AFFINE_DOUBLE); - StartSpriteAffineAnim(&gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]], 0); + gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]].affineAnims = sAffineAnims_CrossingMonPics; + gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]].oam.affineMode = ST_OAM_AFFINE_DOUBLE; + CalcCenterToCornerVec(&gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]], SPRITE_SHAPE(64x64), SPRITE_SIZE(64x64), ST_OAM_AFFINE_DOUBLE); + StartSpriteAffineAnim(&gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]], 0); } else { - StartSpriteAffineAnim(&gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]], 0); + StartSpriteAffineAnim(&gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]], 0); } - StartSpriteAffineAnim(&gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PARTNER]], 0); - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]].pos1.x = 40; - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PARTNER]].pos1.x = 200; - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]].pos1.y = 192; - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PARTNER]].pos1.y = -32; - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]].invisible = FALSE; - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PARTNER]].invisible = FALSE; + StartSpriteAffineAnim(&gSprites[sTradeData->monSpriteIds[TRADE_PARTNER]], 0); + gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]].pos1.x = 40; + gSprites[sTradeData->monSpriteIds[TRADE_PARTNER]].pos1.x = 200; + gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]].pos1.y = 192; + gSprites[sTradeData->monSpriteIds[TRADE_PARTNER]].pos1.y = -32; + gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]].invisible = FALSE; + gSprites[sTradeData->monSpriteIds[TRADE_PARTNER]].invisible = FALSE; sTradeData->state++; break; - case 38: - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.y -= 3; - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PARTNER]].pos2.y += 3; - if (gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.y < -DISPLAY_HEIGHT - && gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.y >= -DISPLAY_HEIGHT - 3) + case TS_STATE_CROSSING_MON_PICS_MOVE: + gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]].pos2.y -= 3; + gSprites[sTradeData->monSpriteIds[TRADE_PARTNER]].pos2.y += 3; + if (gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]].pos2.y < -DISPLAY_HEIGHT + && gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]].pos2.y >= -DISPLAY_HEIGHT - 3) { PlaySE(SE_WARP_IN); } - if (gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]].pos2.y < -222) + if (gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]].pos2.y < -222) { - gSprites[sTradeData->unk_90].data[1] = 0; - gSprites[sTradeData->unk_91].data[1] = 0; + gSprites[sTradeData->connectionSpriteId1].data[1] = 0; + gSprites[sTradeData->connectionSpriteId2].data[1] = 0; sTradeData->state++; - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]].invisible = TRUE; - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PARTNER]].invisible = TRUE; - CreateTask(sub_807F39C, 5); + gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]].invisible = TRUE; + gSprites[sTradeData->monSpriteIds[TRADE_PARTNER]].invisible = TRUE; + CreateTask(Task_NarrowWindowForCrossing_Cable, 5); } break; - case 39: - gSprites[sTradeData->unk_90].pos2.y -= 3; - gSprites[sTradeData->unk_91].pos2.y += 3; - if (gSprites[sTradeData->unk_90].pos2.y <= -222) + case TS_STATE_CROSSING_LINK_MONS_EXIT: + gSprites[sTradeData->connectionSpriteId1].pos2.y -= 3; + gSprites[sTradeData->connectionSpriteId2].pos2.y += 3; + if (gSprites[sTradeData->connectionSpriteId1].pos2.y <= -222) { BeginNormalPaletteFade(PALETTES_ALL, -1, 0, 16, RGB_BLACK); sTradeData->state++; - DestroySprite(&gSprites[sTradeData->unk_90]); - DestroySprite(&gSprites[sTradeData->unk_91]); + DestroySprite(&gSprites[sTradeData->connectionSpriteId1]); + DestroySprite(&gSprites[sTradeData->connectionSpriteId2]); } break; - case 40: + case TS_STATE_CREATE_LINK_MON_ARRIVING: if (!gPaletteFade.active) { sTradeData->state++; @@ -4029,36 +4126,34 @@ static bool8 AnimateTradeSequenceWireless(void) sTradeData->bg1vofs = 166; SetTradeSequenceBgGpuRegs(3); sTradeData->bg2vofs = 412; - sTradeData->unk_90 = CreateSprite(&gUnknown_08338D88, 120, -20, 3); - gSprites[sTradeData->unk_90].callback = sub_807AA4C; - sTradeData->unk_91 = CreateSprite(&sGlowBallSpriteTemplate, 120, -20, 0); - StartSpriteAnim(&gSprites[sTradeData->unk_91], 1); + sTradeData->connectionSpriteId1 = CreateSprite(&sSpriteTemplate_LinkMonGlow, 120, -20, 3); + gSprites[sTradeData->connectionSpriteId1].callback = SpriteCB_LinkMonGlowWireless; + sTradeData->connectionSpriteId2 = CreateSprite(&sSpriteTemplate_LinkMonShadow, 120, -20, 0); + StartSpriteAnim(&gSprites[sTradeData->connectionSpriteId2], ANIM_LINKMON_SMALL); } break; - case 41: + case TS_STATE_FADE_OUT_TO_GBA_RECV: BeginNormalPaletteFade(PALETTES_ALL, -1, 16, 0, RGB_BLACK); sTradeData->state++; break; - case 42: + case TS_STATE_WAIT_FADE_OUT_TO_GBA_RECV: SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG1_ON | DISPCNT_OBJ_ON); if (!gPaletteFade.active) - { sTradeData->state++; - } break; - case 43: - gSprites[sTradeData->unk_90].pos2.y += 4; - gSprites[sTradeData->unk_91].pos2.y += 4; - if (gSprites[sTradeData->unk_90].pos2.y + gSprites[sTradeData->unk_90].pos1.y == 64) + case TS_STATE_LINK_MON_TRAVEL_IN: + gSprites[sTradeData->connectionSpriteId1].pos2.y += 4; + gSprites[sTradeData->connectionSpriteId2].pos2.y += 4; + if (gSprites[sTradeData->connectionSpriteId1].pos2.y + gSprites[sTradeData->connectionSpriteId1].pos1.y == 64) { - sTradeData->state = 144; + sTradeData->state = TS_STATE_PAN_TO_GBA_WIRELESS; sTradeData->timer = 0; } break; - case 144: + case TS_STATE_PAN_TO_GBA_WIRELESS: SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG1_ON | @@ -4077,62 +4172,60 @@ static bool8 AnimateTradeSequenceWireless(void) sTradeData->state++; } break; - case 145: - DestroySprite(&gSprites[sTradeData->unk_90]); - DestroySprite(&gSprites[sTradeData->unk_91]); + case TS_STATE_DESTROY_LINK_MON_WIRELESS: + DestroySprite(&gSprites[sTradeData->connectionSpriteId1]); + DestroySprite(&gSprites[sTradeData->connectionSpriteId2]); sTradeData->state++; sTradeData->timer = 0; break; - case 146: + case TS_STATE_WAIT_WIRELESS_SIGNAL_RECV: if (!FuncIsActiveTask(Task_AnimateWirelessSignal)) { - sTradeData->state = 46; + sTradeData->state = TS_STATE_LINK_MON_ARRIVED_DELAY; sTradeData->timer = 0; } break; - case 46: + case TS_STATE_LINK_MON_ARRIVED_DELAY: if (++sTradeData->timer == 10) - { sTradeData->state++; - } break; - case 47: + case TS_STATE_MOVE_GBA_TO_CENTER: if (++sTradeData->bg1vofs > 348) { sTradeData->bg1vofs = 348; sTradeData->state++; } break; - case 48: - sTradeData->unk_91 = CreateSprite(&gSpriteTemplate_8338E74, 120, 80, 0); - sTradeData->state = 50; + case TS_STATE_GBA_FLASH_RECV: + sTradeData->connectionSpriteId2 = CreateSprite(&sSpriteTemplate_GbaScreenFlash_Long, 120, 80, 0); + sTradeData->state = TS_STATE_GBA_STOP_FLASH_RECV; break; - case 50: - if (gSprites[sTradeData->unk_91].animEnded) + case TS_STATE_GBA_STOP_FLASH_RECV: + if (gSprites[sTradeData->connectionSpriteId2].animEnded) { - DestroySprite(&gSprites[sTradeData->unk_91]); + DestroySprite(&gSprites[sTradeData->connectionSpriteId2]); SetTradeSequenceBgGpuRegs(6); sTradeData->state++; PlaySE(SE_M_SAND_ATTACK); } break; - case 51: - if (sTradeData->unk_EA < 0x400) + case TS_STATE_GBA_ZOOM_IN: + if (sTradeData->gbaScale < 0x400) { - sTradeData->unk_EA += 0x34; + sTradeData->gbaScale += 0x34; } else { - sTradeData->unk_EA = 0x400; + sTradeData->gbaScale = 0x400; sTradeData->state++; } - sTradeData->sXY = 0x8000 / sTradeData->unk_EA; + sTradeData->sXY = 0x8000 / sTradeData->gbaScale; break; - case 52: + case TS_STATE_FADE_OUT_TO_NEW_MON: BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); - sTradeData->state = 60; + sTradeData->state = TS_STATE_WAIT_FADE_OUT_TO_NEW_MON; break; - case 60: + case TS_STATE_WAIT_FADE_OUT_TO_NEW_MON: if (!gPaletteFade.active) { SetTradeSequenceBgGpuRegs(5); @@ -4141,54 +4234,55 @@ static bool8 AnimateTradeSequenceWireless(void) sTradeData->state++; } break; - case 61: + case TS_STATE_FADE_IN_TO_NEW_MON: gPaletteFade.bufferTransferDisabled = FALSE; BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK); sTradeData->state++; break; - case 62: + case TS_STATE_WAIT_FADE_IN_TO_NEW_MON: SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG2_ON | DISPCNT_OBJ_ON); if (!gPaletteFade.active) - { sTradeData->state++; - } break; - case 63: - sTradeData->unk_D3 = CreateSprite(&gSpriteTemplate_8338D28, 120, -8, 0); - gSprites[sTradeData->unk_D3].data[3] = 74; - gSprites[sTradeData->unk_D3].callback = sub_807E6AC; - StartSpriteAnim(&gSprites[sTradeData->unk_D3], 1); - StartSpriteAffineAnim(&gSprites[sTradeData->unk_D3], 2); - BlendPalettes(1 << (16 + gSprites[sTradeData->unk_D3].oam.paletteNum), 16, RGB_WHITEALPHA); + case TS_STATE_POKEBALL_ARRIVE: + sTradeData->bouncingPokeballSpriteId = CreateSprite(&sSpriteTemplate_Pokeball, 120, -8, 0); + gSprites[sTradeData->bouncingPokeballSpriteId].data[3] = 74; + gSprites[sTradeData->bouncingPokeballSpriteId].callback = SpriteCB_BouncingPokeballArrive; + StartSpriteAnim(&gSprites[sTradeData->bouncingPokeballSpriteId], 1); + StartSpriteAffineAnim(&gSprites[sTradeData->bouncingPokeballSpriteId], 2); + BlendPalettes(1 << (16 + gSprites[sTradeData->bouncingPokeballSpriteId].oam.paletteNum), 16, RGB_WHITEALPHA); sTradeData->state++; sTradeData->timer = 0; break; - case 64: - BeginNormalPaletteFade(1 << (16 + gSprites[sTradeData->unk_D3].oam.paletteNum), 1, 16, 0, RGB_WHITEALPHA); + case TS_STATE_FADE_POKEBALL_TO_NORMAL: + BeginNormalPaletteFade(1 << (16 + gSprites[sTradeData->bouncingPokeballSpriteId].oam.paletteNum), 1, 16, 0, RGB_WHITEALPHA); sTradeData->state++; break; - case 65: - if (gSprites[sTradeData->unk_D3].callback == SpriteCallbackDummy) + case TS_STATE_POKEBALL_ARRIVE_WAIT: + if (gSprites[sTradeData->bouncingPokeballSpriteId].callback == SpriteCallbackDummy) { - HandleLoadSpecialPokePic_2(&gMonFrontPicTable[sTradeData->monSpecies[TRADE_PARTNER]], gMonSpritesGfxPtr->sprites.ptr[3], sTradeData->monSpecies[TRADE_PARTNER], sTradeData->monPersonalities[TRADE_PARTNER]); + HandleLoadSpecialPokePic_2(&gMonFrontPicTable[sTradeData->monSpecies[TRADE_PARTNER]], + gMonSpritesGfxPtr->sprites.ptr[3], + sTradeData->monSpecies[TRADE_PARTNER], + sTradeData->monPersonalities[TRADE_PARTNER]); sTradeData->state++; } break; - case 66: - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PARTNER]].pos1.x = 120; - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PARTNER]].pos1.y = gMonFrontPicCoords[sTradeData->monSpecies[TRADE_PARTNER]].y_offset + 60; - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PARTNER]].pos2.x = 0; - gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PARTNER]].pos2.y = 0; - StartSpriteAnim(&gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PARTNER]], 0); - CreatePokeballSpriteToReleaseMon(sTradeData->pokePicSpriteIdxs[TRADE_PARTNER], gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PARTNER]].oam.paletteNum, 120, 84, 2, 1, 20, 0xFFFFF, sTradeData->monSpecies[TRADE_PARTNER]); - FreeSpriteOamMatrix(&gSprites[sTradeData->unk_D3]); - DestroySprite(&gSprites[sTradeData->unk_D3]); + case TS_STATE_SHOW_NEW_MON: + gSprites[sTradeData->monSpriteIds[TRADE_PARTNER]].pos1.x = 120; + gSprites[sTradeData->monSpriteIds[TRADE_PARTNER]].pos1.y = gMonFrontPicCoords[sTradeData->monSpecies[TRADE_PARTNER]].y_offset + 60; + gSprites[sTradeData->monSpriteIds[TRADE_PARTNER]].pos2.x = 0; + gSprites[sTradeData->monSpriteIds[TRADE_PARTNER]].pos2.y = 0; + StartSpriteAnim(&gSprites[sTradeData->monSpriteIds[TRADE_PARTNER]], 0); + CreatePokeballSpriteToReleaseMon(sTradeData->monSpriteIds[TRADE_PARTNER], gSprites[sTradeData->monSpriteIds[TRADE_PARTNER]].oam.paletteNum, 120, 84, 2, 1, 20, 0xFFFFF, sTradeData->monSpecies[TRADE_PARTNER]); + FreeSpriteOamMatrix(&gSprites[sTradeData->bouncingPokeballSpriteId]); + DestroySprite(&gSprites[sTradeData->bouncingPokeballSpriteId]); sTradeData->state++; break; - case 67: + case TS_STATE_NEW_MON_MSG: SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG0_ON | @@ -4196,28 +4290,24 @@ static bool8 AnimateTradeSequenceWireless(void) DISPCNT_OBJ_ON); StringExpandPlaceholders(gStringVar4, gText_XSentOverY); DrawTextOnTradeWindow(0, gStringVar4, 0); - sTradeData->state = 167; + sTradeData->state = TS_STATE_DELAY_FOR_MON_ANIM; sTradeData->timer = 0; break; - // 167 and 267 are extra cases added in for animations - case 167: + case TS_STATE_DELAY_FOR_MON_ANIM: if (++sTradeData->timer > 60) { - sTradeData->state = 267; + sTradeData->state = TS_STATE_WAIT_FOR_MON_CRY; sTradeData->timer = 0; } break; - case 267: + case TS_STATE_WAIT_FOR_MON_CRY: if (IsCryFinished()) - { - sTradeData->state = 68; - } + sTradeData->state = TS_STATE_TAKE_CARE_OF_MON; break; - case 68: + case TS_STATE_TAKE_CARE_OF_MON: if (++sTradeData->timer == 10) - { PlayFanfare(MUS_EVOLVED); - } + if (sTradeData->timer == 250) { sTradeData->state++; @@ -4226,17 +4316,15 @@ static bool8 AnimateTradeSequenceWireless(void) sTradeData->timer = 0; } break; - case 69: + case TS_STATE_AFTER_NEW_MON_DELAY: if (++sTradeData->timer == 60) - { sTradeData->state++; - } break; - case 70: + case TS_STATE_CHECK_RIBBONS: CheckPartnersMonForRibbons(); sTradeData->state++; break; - case 71: + case TS_STATE_END_LINK_TRADE: if (sTradeData->isLinkTrade) { return TRUE; @@ -4246,21 +4334,21 @@ static bool8 AnimateTradeSequenceWireless(void) sTradeData->state++; } break; - case 72: // Only if in-game trade + case TS_STATE_TRY_EVOLUTION: // Only if in-game trade, link trades use CB2_TryLinkTradeEvolution TradeMons(gSpecialVar_0x8005, 0); gCB2_AfterEvolution = CB2_UpdateInGameTrade; evoTarget = GetEvolutionTargetSpecies(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], EVO_MODE_TRADE, ITEM_NONE); if (evoTarget != SPECIES_NONE) { - TradeEvolutionScene(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], evoTarget, sTradeData->pokePicSpriteIdxs[TRADE_PARTNER], gSelectedTradeMonPositions[TRADE_PLAYER]); + TradeEvolutionScene(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], evoTarget, sTradeData->monSpriteIds[TRADE_PARTNER], gSelectedTradeMonPositions[TRADE_PLAYER]); } sTradeData->state++; break; - case 73: + case TS_STATE_FADE_OUT_END: BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); sTradeData->state++; break; - case 74: + case TS_STATE_WAIT_FADE_OUT_END: if (!gPaletteFade.active) { PlayNewMapMusic(sTradeData->cachedMapMusic); @@ -4281,7 +4369,9 @@ static bool8 AnimateTradeSequenceWireless(void) return FALSE; } -static void CB2_TryTradeEvolution(void) +// Try to evolve a Pokémon received in a link trade +// In-game trades resolve evolution during the trade sequence, in TS_STATE_TRY_EVOLUTION +static void CB2_TryLinkTradeEvolution(void) { u16 evoTarget; switch (gMain.state) @@ -4294,7 +4384,7 @@ static void CB2_TryTradeEvolution(void) gCB2_AfterEvolution = CB2_SaveAndEndTrade; evoTarget = GetEvolutionTargetSpecies(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], EVO_MODE_TRADE, ITEM_NONE); if (evoTarget != SPECIES_NONE) - TradeEvolutionScene(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], evoTarget, sTradeData->pokePicSpriteIdxs[TRADE_PARTNER], gSelectedTradeMonPositions[TRADE_PLAYER]); + TradeEvolutionScene(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], evoTarget, sTradeData->monSpriteIds[TRADE_PARTNER], gSelectedTradeMonPositions[TRADE_PLAYER]); else if (IsWirelessTrade()) SetMainCallback2(CB2_SaveAndEndWirelessTrade); else @@ -4317,7 +4407,7 @@ static void UpdateTradeFinishFlags(void) if (blockReceivedStatus & 0x01) { if (gBlockRecvBuffer[0][0] == LINKCMD_CONFIRM_FINISH_TRADE) - SetMainCallback2(CB2_TryTradeEvolution); + SetMainCallback2(CB2_TryLinkTradeEvolution); if (gBlockRecvBuffer[0][0] == LINKCMD_READY_FINISH_TRADE) sTradeData->playerLinkFlagFinishTrade = READY_FINISH_TRADE; @@ -4333,7 +4423,7 @@ static void UpdateTradeFinishFlags(void) } } -static void sub_807E55C(struct Sprite *sprite) +static void SpriteCB_BouncingPokeball(struct Sprite *sprite) { sprite->pos1.y += sprite->data[0] / 10; sprite->data[5] += sprite->data[1]; @@ -4354,7 +4444,7 @@ static void sub_807E55C(struct Sprite *sprite) } } -static void sub_807E5D8(struct Sprite *sprite) +static void SpriteCB_BouncingPokeballDepart(struct Sprite *sprite) { sprite->pos2.y += sTradeBallVerticalVelocityTable[sprite->data[0]]; if (sprite->data[0] == 22) @@ -4362,13 +4452,13 @@ static void sub_807E5D8(struct Sprite *sprite) if (++ sprite->data[0] == 44) { PlaySE(SE_M_MEGA_KICK); - sprite->callback = sub_807E64C; + sprite->callback = SpriteCB_BouncingPokeballDepartEnd; sprite->data[0] = 0; BeginNormalPaletteFade(1 << (16 + sprite->oam.paletteNum), -1, 0, 16, RGB_WHITEALPHA); } } -static void sub_807E64C(struct Sprite *sprite) +static void SpriteCB_BouncingPokeballDepartEnd(struct Sprite *sprite) { if (sprite->data[1] == 20) StartSpriteAffineAnim(sprite, 1); @@ -4378,12 +4468,12 @@ static void sub_807E64C(struct Sprite *sprite) if (++ sprite->data[0] == 23) { DestroySprite(sprite); - sTradeData->state = 14; // Resume the master trade animation + sTradeData->state = TS_STATE_FADE_OUT_TO_GBA_SEND; // Resume the master trade animation } } } -static void sub_807E6AC(struct Sprite *sprite) +static void SpriteCB_BouncingPokeballArrive(struct Sprite *sprite) { if (sprite->data[2] == 0) { @@ -4508,8 +4598,8 @@ static void CB2_UpdateLinkTrade(void) { if (AnimateTradeSequence() == TRUE) { - DestroySprite(&gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PLAYER]]); - FreeSpriteOamMatrix(&gSprites[sTradeData->pokePicSpriteIdxs[TRADE_PARTNER]]); + DestroySprite(&gSprites[sTradeData->monSpriteIds[TRADE_PLAYER]]); + FreeSpriteOamMatrix(&gSprites[sTradeData->monSpriteIds[TRADE_PARTNER]]); TradeMons(gSelectedTradeMonPositions[TRADE_PLAYER], gSelectedTradeMonPositions[TRADE_PARTNER] % PARTY_SIZE); if (!IsWirelessTrade()) { @@ -4532,7 +4622,7 @@ static void CB2_TryFinishTrade(void) u8 mpId = TradeGetMultiplayerId(); if (IsWirelessTrade()) { - SetMainCallback2(CB2_TryTradeEvolution); + SetMainCallback2(CB2_TryLinkTradeEvolution); } else { @@ -4542,7 +4632,7 @@ static void CB2_TryFinishTrade(void) && sTradeData->partnerLinkFlagFinishTrade == READY_FINISH_TRADE) { sTradeData->linkData[0] = LINKCMD_CONFIRM_FINISH_TRADE; - Trade_SendData(sTradeData); + SendBlock(bitmask_all_link_players_but_self(), sTradeData->linkData, sizeof(sTradeData->linkData)); sTradeData->playerLinkFlagFinishTrade = FINISH_TRADE; sTradeData->partnerLinkFlagFinishTrade = FINISH_TRADE; } @@ -4793,16 +4883,16 @@ static void Task_AnimateWirelessSignal(u8 taskId) if (!signalComingBack) { if (paletteIdx == 256) - LoadPalette(sTradePal_Black, 0x30, 32); + LoadPalette(sWirelessSignalNone_Pal, 0x30, 32); else - LoadPalette(&sTradePal_WirelessSignalSend[paletteIdx], 0x30, 32); + LoadPalette(&sWirelessSignalSend_Pal[paletteIdx], 0x30, 32); } else { if (paletteIdx == 256) - LoadPalette(sTradePal_Black, 0x30, 32); + LoadPalette(sWirelessSignalNone_Pal, 0x30, 32); else - LoadPalette(&sTradePal_WirelessSignalReceive[paletteIdx], 0x30, 32); + LoadPalette(&sWirelessSignalRecv_Pal[paletteIdx], 0x30, 32); } if (sWirelessSignalTiming[idx][0] == 0 && counter == 0) @@ -4827,13 +4917,13 @@ static void Task_AnimateWirelessSignal(u8 taskId) #undef counter #undef signalComingBack -static void c3_0805465C(u8 taskId) +static void Task_NarrowWindowForCrossing_Wireless(u8 taskId) { s16 *data = gTasks[taskId].data; if (data[0] == 0) { - sTradeData->wirelessWinLeft = sTradeData->wirelessWinRight = 120; + sTradeData->wirelessWinLeft = sTradeData->wirelessWinRight = DISPLAY_WIDTH / 2; sTradeData->wirelessWinTop = 0; sTradeData->wirelessWinBottom = DISPLAY_HEIGHT; SetGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON); @@ -4851,19 +4941,17 @@ static void c3_0805465C(u8 taskId) sTradeData->wirelessWinRight += 5; if (sTradeData->wirelessWinLeft < 80) - { DestroyTask(taskId); - } } -static void sub_807F39C(u8 taskId) +static void Task_NarrowWindowForCrossing_Cable(u8 taskId) { s16 *data = gTasks[taskId].data; if (data[0] == 0) { sTradeData->wirelessWinLeft = 80; - sTradeData->wirelessWinRight = 160; + sTradeData->wirelessWinRight = DISPLAY_WIDTH - 80; SetGpuReg(REG_OFFSET_WINOUT, WINOUT_WIN01_OBJ); SetGpuReg(REG_OFFSET_WININ, WININ_WIN0_BG0 | WININ_WIN0_BG1 | @@ -4873,13 +4961,13 @@ static void sub_807F39C(u8 taskId) SetGpuReg(REG_OFFSET_WIN0H, WIN_RANGE2(sTradeData->wirelessWinLeft, sTradeData->wirelessWinRight)); SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE2(sTradeData->wirelessWinTop, sTradeData->wirelessWinBottom)); - if (sTradeData->wirelessWinLeft != 120) + if (sTradeData->wirelessWinLeft != DISPLAY_WIDTH / 2) { data[0]++; sTradeData->wirelessWinLeft += 5; sTradeData->wirelessWinRight -= 5; - if (sTradeData->wirelessWinLeft >= 116) + if (sTradeData->wirelessWinLeft > DISPLAY_WIDTH / 2 - 5) BlendPalettes(0x8, 0, RGB_WHITEALPHA); } else