From 04af378904dc5e7ded00bb8e50c8e6b554c3571b Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 18 Apr 2021 20:12:12 -0400 Subject: [PATCH 01/11] Document trade sequence animation, some trade cleanup --- ...p_map.bin => crossing_highlight_cable.bin} | Bin ...A0.bin => crossing_highlight_wireless.bin} | Bin .../trade/{unknown_DDB444.pal => cursor.pal} | 0 graphics/trade/{buttons.png => cursor.png} | Bin graphics/trade/{misc.pal => link_mon.pal} | 0 .../trade/{glow1.png => link_mon_glow.png} | Bin ...unknown_338EA4.pal => link_mon_shadow.pal} | 0 .../trade/{glow2.png => link_mon_shadow.png} | Bin .../trade/{shadow_map.bin => platform.bin} | Bin .../trade/{unknown_3308C0.pal => unused1.pal} | 0 graphics/trade/{shadow.pal => unused2.pal} | 0 .../{black.pal => wireless_signal_none.pal} | 0 include/graphics.h | 4 +- src/data/trade.h | 502 +++---- src/egg_hatch.c | 4 +- src/graphics.c | 4 +- src/trade.c | 1248 +++++++++-------- 17 files changed, 930 insertions(+), 832 deletions(-) rename graphics/trade/{cable_closeup_map.bin => crossing_highlight_cable.bin} (100%) rename graphics/trade/{unknown_3379A0.bin => crossing_highlight_wireless.bin} (100%) rename graphics/trade/{unknown_DDB444.pal => cursor.pal} (100%) rename graphics/trade/{buttons.png => cursor.png} (100%) rename graphics/trade/{misc.pal => link_mon.pal} (100%) rename graphics/trade/{glow1.png => link_mon_glow.png} (100%) rename graphics/trade/{unknown_338EA4.pal => link_mon_shadow.pal} (100%) rename graphics/trade/{glow2.png => link_mon_shadow.png} (100%) rename graphics/trade/{shadow_map.bin => platform.bin} (100%) rename graphics/trade/{unknown_3308C0.pal => unused1.pal} (100%) rename graphics/trade/{shadow.pal => unused2.pal} (100%) rename graphics/trade/{black.pal => wireless_signal_none.pal} (100%) 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 From a2a9f226129317c2557b908883903df47701324c Mon Sep 17 00:00:00 2001 From: GriffinR Date: Tue, 20 Apr 2021 21:16:47 -0400 Subject: [PATCH 02/11] Clean up contest_util --- .../bg.bin} | 0 .../interface.bin} | Bin .../results_screen/text_window.pal} | 0 .../results_screen/text_window.png} | Bin .../tiles.pal} | 0 .../tiles.png} | Bin .../title.bin} | Bin .../title_beauty.bin} | 0 .../title_cool.bin} | Bin .../title_cute.bin} | 0 .../title_hyper.bin} | Bin .../title_link.bin} | Bin .../title_master.bin} | Bin .../title_normal.bin} | Bin .../title_smart.bin} | 0 .../title_super.bin} | Bin .../title_tough.bin} | 0 .../winner_banner.bin} | Bin include/graphics.h | 28 +-- src/contest_util.c | 180 ++++++++++-------- src/graphics.c | 32 ++-- 21 files changed, 131 insertions(+), 109 deletions(-) rename graphics/contest/{misc_2_tilemap_3.bin => results_screen/bg.bin} (100%) rename graphics/contest/{misc_2_tilemap_2.bin => results_screen/interface.bin} (100%) rename graphics/{unknown/unknown_58D6B0.pal => contest/results_screen/text_window.pal} (100%) rename graphics/{unknown/unknown_58D6D0.png => contest/results_screen/text_window.png} (100%) rename graphics/contest/{results_screen.pal => results_screen/tiles.pal} (100%) rename graphics/contest/{results_screen.png => results_screen/tiles.png} (100%) rename graphics/contest/{results_screen.bin => results_screen/title.bin} (100%) rename graphics/contest/{results_screen_beauty.bin => results_screen/title_beauty.bin} (100%) rename graphics/contest/{results_screen_cool.bin => results_screen/title_cool.bin} (100%) rename graphics/contest/{results_screen_cute.bin => results_screen/title_cute.bin} (100%) rename graphics/contest/{results_screen_hyper.bin => results_screen/title_hyper.bin} (100%) rename graphics/contest/{results_screen_link.bin => results_screen/title_link.bin} (100%) rename graphics/contest/{results_screen_master.bin => results_screen/title_master.bin} (100%) rename graphics/contest/{results_screen_normal.bin => results_screen/title_normal.bin} (100%) rename graphics/contest/{results_screen_smart.bin => results_screen/title_smart.bin} (100%) rename graphics/contest/{results_screen_super.bin => results_screen/title_super.bin} (100%) rename graphics/contest/{results_screen_tough.bin => results_screen/title_tough.bin} (100%) rename graphics/contest/{misc_2_tilemap_1.bin => results_screen/winner_banner.bin} (100%) diff --git a/graphics/contest/misc_2_tilemap_3.bin b/graphics/contest/results_screen/bg.bin similarity index 100% rename from graphics/contest/misc_2_tilemap_3.bin rename to graphics/contest/results_screen/bg.bin diff --git a/graphics/contest/misc_2_tilemap_2.bin b/graphics/contest/results_screen/interface.bin similarity index 100% rename from graphics/contest/misc_2_tilemap_2.bin rename to graphics/contest/results_screen/interface.bin diff --git a/graphics/unknown/unknown_58D6B0.pal b/graphics/contest/results_screen/text_window.pal similarity index 100% rename from graphics/unknown/unknown_58D6B0.pal rename to graphics/contest/results_screen/text_window.pal diff --git a/graphics/unknown/unknown_58D6D0.png b/graphics/contest/results_screen/text_window.png similarity index 100% rename from graphics/unknown/unknown_58D6D0.png rename to graphics/contest/results_screen/text_window.png diff --git a/graphics/contest/results_screen.pal b/graphics/contest/results_screen/tiles.pal similarity index 100% rename from graphics/contest/results_screen.pal rename to graphics/contest/results_screen/tiles.pal diff --git a/graphics/contest/results_screen.png b/graphics/contest/results_screen/tiles.png similarity index 100% rename from graphics/contest/results_screen.png rename to graphics/contest/results_screen/tiles.png diff --git a/graphics/contest/results_screen.bin b/graphics/contest/results_screen/title.bin similarity index 100% rename from graphics/contest/results_screen.bin rename to graphics/contest/results_screen/title.bin diff --git a/graphics/contest/results_screen_beauty.bin b/graphics/contest/results_screen/title_beauty.bin similarity index 100% rename from graphics/contest/results_screen_beauty.bin rename to graphics/contest/results_screen/title_beauty.bin diff --git a/graphics/contest/results_screen_cool.bin b/graphics/contest/results_screen/title_cool.bin similarity index 100% rename from graphics/contest/results_screen_cool.bin rename to graphics/contest/results_screen/title_cool.bin diff --git a/graphics/contest/results_screen_cute.bin b/graphics/contest/results_screen/title_cute.bin similarity index 100% rename from graphics/contest/results_screen_cute.bin rename to graphics/contest/results_screen/title_cute.bin diff --git a/graphics/contest/results_screen_hyper.bin b/graphics/contest/results_screen/title_hyper.bin similarity index 100% rename from graphics/contest/results_screen_hyper.bin rename to graphics/contest/results_screen/title_hyper.bin diff --git a/graphics/contest/results_screen_link.bin b/graphics/contest/results_screen/title_link.bin similarity index 100% rename from graphics/contest/results_screen_link.bin rename to graphics/contest/results_screen/title_link.bin diff --git a/graphics/contest/results_screen_master.bin b/graphics/contest/results_screen/title_master.bin similarity index 100% rename from graphics/contest/results_screen_master.bin rename to graphics/contest/results_screen/title_master.bin diff --git a/graphics/contest/results_screen_normal.bin b/graphics/contest/results_screen/title_normal.bin similarity index 100% rename from graphics/contest/results_screen_normal.bin rename to graphics/contest/results_screen/title_normal.bin diff --git a/graphics/contest/results_screen_smart.bin b/graphics/contest/results_screen/title_smart.bin similarity index 100% rename from graphics/contest/results_screen_smart.bin rename to graphics/contest/results_screen/title_smart.bin diff --git a/graphics/contest/results_screen_super.bin b/graphics/contest/results_screen/title_super.bin similarity index 100% rename from graphics/contest/results_screen_super.bin rename to graphics/contest/results_screen/title_super.bin diff --git a/graphics/contest/results_screen_tough.bin b/graphics/contest/results_screen/title_tough.bin similarity index 100% rename from graphics/contest/results_screen_tough.bin rename to graphics/contest/results_screen/title_tough.bin diff --git a/graphics/contest/misc_2_tilemap_1.bin b/graphics/contest/results_screen/winner_banner.bin similarity index 100% rename from graphics/contest/misc_2_tilemap_1.bin rename to graphics/contest/results_screen/winner_banner.bin diff --git a/include/graphics.h b/include/graphics.h index cea8bbab1..6262d8862 100644 --- a/include/graphics.h +++ b/include/graphics.h @@ -4924,21 +4924,21 @@ extern const u32 gRouletteMultiplier_Gfx[]; // Contest util extern const u32 gContestResults_Gfx[]; -extern const u32 gUnknown_08C19EEC[]; -extern const u32 gUnknown_08C1A000[]; -extern const u32 gUnknown_08C1A12C[]; +extern const u32 gContestResults_WinnerBanner_Tilemap[]; +extern const u32 gContestResults_Interface_Tilemap[]; +extern const u32 gContestResults_Bg_Tilemap[]; extern const u32 gContestResults_Pal[]; -extern const u16 gLinkContestResults_Tilemap[]; -extern const u16 gNormalContestResults_Tilemap[]; -extern const u16 gSuperContestResults_Tilemap[]; -extern const u16 gHyperContestResults_Tilemap[]; -extern const u16 gMasterContestResults_Tilemap[]; -extern const u16 gCoolContestResults_Tilemap[]; -extern const u16 gBeautyContestResults_Tilemap[]; -extern const u16 gCuteContestResults_Tilemap[]; -extern const u16 gSmartContestResults_Tilemap[]; -extern const u16 gToughContestResults_Tilemap[]; -extern const u16 gContestResults_Tilemap[]; +extern const u16 gContestResultsTitle_Link_Tilemap[]; +extern const u16 gContestResultsTitle_Normal_Tilemap[]; +extern const u16 gContestResultsTitle_Super_Tilemap[]; +extern const u16 gContestResultsTitle_Hyper_Tilemap[]; +extern const u16 gContestResultsTitle_Master_Tilemap[]; +extern const u16 gContestResultsTitle_Cool_Tilemap[]; +extern const u16 gContestResultsTitle_Beauty_Tilemap[]; +extern const u16 gContestResultsTitle_Cute_Tilemap[]; +extern const u16 gContestResultsTitle_Smart_Tilemap[]; +extern const u16 gContestResultsTitle_Tough_Tilemap[]; +extern const u16 gContestResultsTitle_Tilemap[]; // Trainer Card. extern const u16 gHoennTrainerCard0Star_Pal[]; diff --git a/src/contest_util.c b/src/contest_util.c index 98854c4c6..700e44606 100644 --- a/src/contest_util.c +++ b/src/contest_util.c @@ -61,10 +61,29 @@ enum { #define GET_CONTEST_WINNER_ID(i) { for ((i) = 0; (i) < CONTESTANT_COUNT && gContestFinalStandings[(i)] != 0; (i)++); } +// Gfx/pal tags for the text window sprites on the contest results screen. +// Both types of text windows are made up of 4 individual sprites +// These tags are used by the spritesheets, and implicitly in the loop in CreateResultsTextWindowSprites +#define TAG_TEXT_WINDOW_BASE 3009 +enum { + TAG_RESULTS_TEXT_WINDOW_LEFT = TAG_TEXT_WINDOW_BASE, + TAG_RESULTS_TEXT_WINDOW_MIDLEFT, + TAG_RESULTS_TEXT_WINDOW_MIDRIGHT, + TAG_RESULTS_TEXT_WINDOW_RIGHT, + TAG_LINK_TEXT_WINDOW_LEFT, + TAG_LINK_TEXT_WINDOW_MIDLEFT, + TAG_LINK_TEXT_WINDOW_MIDRIGHT, + TAG_LINK_TEXT_WINDOW_RIGHT, // 3016 +}; #define TAG_CONFETTI 3017 +#define TAG_WIRELESS_INDICATOR_WINDOW 22222 #define MAX_BAR_LENGTH 87 +// Starting x/y for the sliding results screen text box +#define TEXT_BOX_X (DISPLAY_WIDTH + 32) +#define TEXT_BOX_Y (DISPLAY_HEIGHT - 16) + struct ContestResultsInternal { u8 slidingTextBoxSpriteId; @@ -105,14 +124,14 @@ struct ContestResults static EWRAM_DATA struct ContestResults *sContestResults = NULL; static void LoadAllContestMonIconPalettes(void); -static void LoadContestResultsTilemaps(void); +static void LoadContestResultsTitleBarTilemaps(void); static u8 GetNumPreliminaryPoints(u8, bool8); static s8 GetNumRound2Points(u8, bool8); static void AddContestTextPrinter(int, u8 *, int); static void AllocContestResults(void); static void FreeContestResults(void); static void LoadAllContestMonIcons(u8, u8); -static void LoadContestResultSprites(void); +static void CreateResultsTextWindowSprites(void); static void TryCreateWirelessSprites(void); static void Task_StartShowContestResults(u8 taskId); static void CB2_StartShowContestResults(void); @@ -166,11 +185,11 @@ static void SpriteCB_Confetti(struct Sprite *sprite); static void Task_ShowContestEntryMonPic(u8 taskId); static void Task_LinkContestWaitForConnection(u8 taskId); -static const u16 sUnknown_0858D6B0[] = INCBIN_U16("graphics/unknown/unknown_58D6B0.gbapal"); -static const u8 sUnknown_0858D6D0[] = INCBIN_U8("graphics/unknown/unknown_58D6D0.4bpp"); +static const u16 sResultsTextWindow_Pal[] = INCBIN_U16("graphics/contest/results_screen/text_window.gbapal"); +static const u8 sResultsTextWindow_Gfx[] = INCBIN_U8("graphics/contest/results_screen/text_window.4bpp"); static const u16 sMiscBlank_Pal[] = INCBIN_U16("graphics/interface/blank.gbapal"); -static const struct OamData sOamData_858D7F0 = +static const struct OamData sOamData_ResultsTextWindow = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -187,33 +206,33 @@ static const struct OamData sOamData_858D7F0 = .affineParam = 0, }; -static const struct SpriteTemplate sSpriteTemplate_858D7F8 = +static const struct SpriteTemplate sSpriteTemplate_ResultsTextWindow = { - .tileTag = 3009, - .paletteTag = 3009, - .oam = &sOamData_858D7F0, + .tileTag = TAG_TEXT_WINDOW_BASE, + .paletteTag = TAG_TEXT_WINDOW_BASE, + .oam = &sOamData_ResultsTextWindow, .anims = gDummySpriteAnimTable, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy }; -static const struct SpriteSheet sUnknown_0858D810[] = +static const struct SpriteSheet sSpriteSheets_ResultsTextWindow[] = { - { .data = gMiscBlank_Gfx, .size = 0x400, .tag = 3009 }, - { .data = gMiscBlank_Gfx, .size = 0x400, .tag = 3010 }, - { .data = gMiscBlank_Gfx, .size = 0x400, .tag = 3011 }, - { .data = gMiscBlank_Gfx, .size = 0x400, .tag = 3012 }, - { .data = gMiscBlank_Gfx, .size = 0x400, .tag = 3013 }, - { .data = gMiscBlank_Gfx, .size = 0x400, .tag = 3014 }, - { .data = gMiscBlank_Gfx, .size = 0x400, .tag = 3015 }, - { .data = gMiscBlank_Gfx, .size = 0x400, .tag = 3016 }, + { .data = gMiscBlank_Gfx, .size = 0x400, .tag = TAG_RESULTS_TEXT_WINDOW_LEFT }, + { .data = gMiscBlank_Gfx, .size = 0x400, .tag = TAG_RESULTS_TEXT_WINDOW_MIDLEFT }, + { .data = gMiscBlank_Gfx, .size = 0x400, .tag = TAG_RESULTS_TEXT_WINDOW_MIDRIGHT }, + { .data = gMiscBlank_Gfx, .size = 0x400, .tag = TAG_RESULTS_TEXT_WINDOW_RIGHT }, + { .data = gMiscBlank_Gfx, .size = 0x400, .tag = TAG_LINK_TEXT_WINDOW_LEFT }, + { .data = gMiscBlank_Gfx, .size = 0x400, .tag = TAG_LINK_TEXT_WINDOW_MIDLEFT }, + { .data = gMiscBlank_Gfx, .size = 0x400, .tag = TAG_LINK_TEXT_WINDOW_MIDRIGHT }, + { .data = gMiscBlank_Gfx, .size = 0x400, .tag = TAG_LINK_TEXT_WINDOW_RIGHT }, }; -static const struct SpritePalette sUnknown_0858D850 = +static const struct SpritePalette sSpritePalette_ResultsTextWindow = { .data = sMiscBlank_Pal, - .tag = 3009, + .tag = TAG_TEXT_WINDOW_BASE, }; static const struct OamData sOamData_Confetti = @@ -339,7 +358,7 @@ static const struct WindowTemplate sWindowTemplates[] = DUMMY_WIN_TEMPLATE, }; -static const struct OamData sUnknown_0858D8C0 = +static const struct OamData sOamData_WirelessIndicatorWindow = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -357,22 +376,22 @@ static const struct OamData sUnknown_0858D8C0 = }; -static const struct SpriteTemplate sSpriteTemplate_858D8C8 = +static const struct SpriteTemplate sSpriteTemplate_WirelessIndicatorWindow = { - .tileTag = 22222, + .tileTag = TAG_WIRELESS_INDICATOR_WINDOW, .paletteTag = 0, - .oam = &sUnknown_0858D8C0, + .oam = &sOamData_WirelessIndicatorWindow, .anims = gDummySpriteAnimTable, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy }; -static const struct SpriteSheet sUnknown_0858D8E0 = +static const struct SpriteSheet sSpriteSheet_WirelessIndicatorWindow = { .data = gMiscBlank_Gfx, .size = 0x200, - .tag = 22222 + .tag = TAG_WIRELESS_INDICATOR_WINDOW }; static const u8 sContestLinkTextColors[4] = {TEXT_COLOR_WHITE, TEXT_DYNAMIC_COLOR_6, TEXT_DYNAMIC_COLOR_5}; @@ -430,12 +449,12 @@ static void LoadContestResultsBgGfx(void) u16 tile1, tile2; LZDecompressVram(gContestResults_Gfx, (void *)BG_CHAR_ADDR(0)); - CopyToBgTilemapBuffer(3, gUnknown_08C1A12C, 0, 0); - CopyToBgTilemapBuffer(2, gUnknown_08C1A000, 0, 0); - CopyToBgTilemapBuffer(0, gUnknown_08C19EEC, 0, 0); - LoadContestResultsTilemaps(); + CopyToBgTilemapBuffer(3, gContestResults_Bg_Tilemap, 0, 0); + CopyToBgTilemapBuffer(2, gContestResults_Interface_Tilemap, 0, 0); + CopyToBgTilemapBuffer(0, gContestResults_WinnerBanner_Tilemap, 0, 0); + LoadContestResultsTitleBarTilemaps(); LoadCompressedPalette(gContestResults_Pal, 0, 0x200); - LoadPalette(sUnknown_0858D6B0, 0xF0, 0x20); + LoadPalette(sResultsTextWindow_Pal, 0xF0, sizeof(sResultsTextWindow_Pal)); for (i = 0; i < CONTESTANT_COUNT; i++) { @@ -515,14 +534,14 @@ static void CB2_StartShowContestResults(void) LoadAllContestMonNames(); memset(sContestResults->data, 0, sizeof(*sContestResults->data)); memset(sContestResults->monResults, 0, sizeof(*sContestResults->monResults)); - LoadContestResultSprites(); + CreateResultsTextWindowSprites(); TryCreateWirelessSprites(); BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK); gPaletteFade.bufferTransferDisabled = FALSE; sContestResults->data->showResultsTaskId = CreateTask(Task_ShowContestResults, 5); SetMainCallback2(CB2_ShowContestResults); gBattle_WIN1H = WIN_RANGE(0, DISPLAY_WIDTH); - gBattle_WIN1V = WIN_RANGE(128, DISPLAY_HEIGHT); + gBattle_WIN1V = WIN_RANGE(DISPLAY_HEIGHT - 32, DISPLAY_HEIGHT); CreateTask(Task_SlideContestResultsBg, 20); CalculateContestantsResultData(); if (gLinkContestFlags & LINK_CONTEST_FLAG_IS_WIRELESS) @@ -679,7 +698,7 @@ static void Task_AnnouncePreliminaryResults(u8 taskId) { CreateTask(Task_FlashStarsAndHearts, 20); x = DrawResultsTextWindow(gText_AnnouncingResults, sContestResults->data->slidingTextBoxSpriteId); - StartTextBoxSlideIn(x, DISPLAY_HEIGHT - 16, 120, 1088); + StartTextBoxSlideIn(x, TEXT_BOX_Y, 120, 1088); gTasks[taskId].tState++; } else if (gTasks[taskId].tState == 1) @@ -702,7 +721,7 @@ static void Task_AnnouncePreliminaryResults(u8 taskId) else if (gTasks[taskId].tState == 3) { x = DrawResultsTextWindow(gText_PreliminaryResults, sContestResults->data->slidingTextBoxSpriteId); - StartTextBoxSlideIn(x, DISPLAY_HEIGHT - 16, -1, 1088); + StartTextBoxSlideIn(x, TEXT_BOX_Y, -1, 1088); gTasks[taskId].tState++; } else if (gTasks[taskId].tState == 4) @@ -752,7 +771,7 @@ static void Task_AnnounceRound2Results(u8 taskId) { gTasks[taskId].tTimer = 0; x = DrawResultsTextWindow(gText_Round2Results, sContestResults->data->slidingTextBoxSpriteId); - StartTextBoxSlideIn(x, DISPLAY_HEIGHT - 16, -1, 1088); + StartTextBoxSlideIn(x, TEXT_BOX_Y, -1, 1088); } } else if (sContestResults->data->slidingTextBoxState == SLIDING_TEXT_ARRIVED) @@ -841,7 +860,7 @@ static void Task_AnnounceWinner(u8 taskId) StringCopy(gStringVar2, gContestMons[i].nickname); StringExpandPlaceholders(winnerTextBuffer, gText_ContestantsMonWon); x = DrawResultsTextWindow(winnerTextBuffer, sContestResults->data->slidingTextBoxSpriteId); - StartTextBoxSlideIn(x, DISPLAY_HEIGHT - 16, -1, 1088); + StartTextBoxSlideIn(x, TEXT_BOX_Y, -1, 1088); gTasks[taskId].tState++; } break; @@ -892,7 +911,7 @@ static void Task_ShowWinnerMonBanner(u8 taskId) LoadCompressedSpritePalette(pokePal); SetMultiuseSpriteTemplateToPokemon(species, B_POSITION_OPPONENT_LEFT); gMultiuseSpriteTemplate.paletteTag = pokePal->tag; - spriteId = CreateSprite(&gMultiuseSpriteTemplate, DISPLAY_WIDTH + 32, 80, 10); + spriteId = CreateSprite(&gMultiuseSpriteTemplate, DISPLAY_WIDTH + 32, DISPLAY_HEIGHT / 2, 10); gSprites[spriteId].data[1] = species; gSprites[spriteId].oam.priority = 0; gSprites[spriteId].callback = SpriteCB_WinnerMonSlideIn; @@ -1136,9 +1155,9 @@ static void TryCreateWirelessSprites(void) LoadWirelessStatusIndicatorSpriteGfx(); CreateWirelessStatusIndicatorSprite(8, 8); gSprites[gWirelessStatusIndicatorSpriteId].subpriority = 1; - sheet = LoadSpriteSheet(&sUnknown_0858D8E0); + sheet = LoadSpriteSheet(&sSpriteSheet_WirelessIndicatorWindow); RequestDma3Fill(0xFFFFFFFF, (void *)BG_CHAR_ADDR(4) + sheet * 0x20, 0x80, 1); - spriteId = CreateSprite(&sSpriteTemplate_858D8C8, 8, 8, 0); + spriteId = CreateSprite(&sSpriteTemplate_WirelessIndicatorWindow, 8, 8, 0); gSprites[spriteId].oam.objMode = ST_OAM_OBJ_WINDOW; } } @@ -1150,14 +1169,13 @@ static s32 DrawResultsTextWindow(const u8 *text, u8 spriteId) int strWidth; u8 *spriteTilePtrs[4]; u8 *dst; - { - struct WindowTemplate windowTemplate; - memset(&windowTemplate, 0, sizeof(windowTemplate)); - windowTemplate.width = 30; - windowTemplate.height = 2; - windowId = AddWindow(&windowTemplate); - FillWindowPixelBuffer(windowId, PIXEL_FILL(1)); - } + + struct WindowTemplate windowTemplate; + memset(&windowTemplate, 0, sizeof(windowTemplate)); + windowTemplate.width = 30; + windowTemplate.height = 2; + windowId = AddWindow(&windowTemplate); + FillWindowPixelBuffer(windowId, PIXEL_FILL(1)); origWidth = GetStringWidth(1, text, 0); strWidth = (origWidth + 9) / 8; @@ -1169,16 +1187,16 @@ static s32 DrawResultsTextWindow(const u8 *text, u8 spriteId) s32 i; struct Sprite *sprite; const u8 *src, *windowTilesPtr; - windowTilesPtr = (u8 *)(GetWindowAttribute(windowId, WINDOW_TILE_DATA)); - src = (u8 *)(sUnknown_0858D6D0); + windowTilesPtr = (u8 *)GetWindowAttribute(windowId, WINDOW_TILE_DATA); + src = (u8 *)sResultsTextWindow_Gfx; sprite = &gSprites[spriteId]; spriteTilePtrs[0] = (u8 *)(sprite->oam.tileNum * 32 + OBJ_VRAM0); - for (i = 1; i < 4; i++) + for (i = 1; i < (int)ARRAY_COUNT(spriteTilePtrs); i++) spriteTilePtrs[i] = (void*)(gSprites[sprite->data[i - 1]].oam.tileNum * 32 + OBJ_VRAM0); - for (i = 0; i < 4; i++) + for (i = 0; i < (int)ARRAY_COUNT(spriteTilePtrs); i++) CpuFill32(0, spriteTilePtrs[i], 0x400); dst = spriteTilePtrs[0]; @@ -1208,27 +1226,31 @@ static s32 DrawResultsTextWindow(const u8 *text, u8 spriteId) return (DISPLAY_WIDTH - (strWidth + 2) * 8) / 2; } -static void LoadContestResultSprites(void) +static void CreateResultsTextWindowSprites(void) { int i; struct SpriteTemplate template; - u8 spriteIds[ARRAY_COUNT(sUnknown_0858D810)]; + u8 spriteIds[ARRAY_COUNT(sSpriteSheets_ResultsTextWindow)]; - template = sSpriteTemplate_858D7F8; - for (i = 0; i < (int)ARRAY_COUNT(sUnknown_0858D810); i++) - LoadSpriteSheet(&sUnknown_0858D810[i]); + template = sSpriteTemplate_ResultsTextWindow; + for (i = 0; i < (int)ARRAY_COUNT(sSpriteSheets_ResultsTextWindow); i++) + LoadSpriteSheet(&sSpriteSheets_ResultsTextWindow[i]); - LoadSpritePalette(&sUnknown_0858D850); - for (i = 0; i < (int)ARRAY_COUNT(sUnknown_0858D810); i++) + LoadSpritePalette(&sSpritePalette_ResultsTextWindow); + + // Create sprites for the two window types, each made up of 4 sprites + for (i = 0; i < (int)ARRAY_COUNT(sSpriteSheets_ResultsTextWindow); i++) { - spriteIds[i] = CreateSprite(&template, DISPLAY_WIDTH + 32, DISPLAY_HEIGHT - 16, 10); + spriteIds[i] = CreateSprite(&template, TEXT_BOX_X, TEXT_BOX_Y, 10); template.tileTag++; } + // Save sprite ids of the sliding text box onto its leftmost sprite gSprites[spriteIds[0]].data[0] = spriteIds[1]; gSprites[spriteIds[0]].data[1] = spriteIds[2]; gSprites[spriteIds[0]].data[2] = spriteIds[3]; + // Save sprite ids of the link text box onto its leftmost sprite gSprites[spriteIds[4]].data[0] = spriteIds[5]; gSprites[spriteIds[4]].data[1] = spriteIds[6]; gSprites[spriteIds[4]].data[2] = spriteIds[7]; @@ -1248,7 +1270,7 @@ static void LoadContestResultSprites(void) static void StartTextBoxSlideIn(s16 x, u16 y, u16 slideOutTimer, u16 slideIncrement) { struct Sprite *sprite = &gSprites[sContestResults->data->slidingTextBoxSpriteId]; - sprite->pos1.x = DISPLAY_WIDTH + 32; + sprite->pos1.x = TEXT_BOX_X; sprite->pos1.y = y; sprite->pos2.x = 0; sprite->pos2.y = 0; @@ -1275,8 +1297,8 @@ static void StartTextBoxSlideOut(u16 slideIncrement) static void EndTextBoxSlideOut(struct Sprite *sprite) { - sprite->pos1.x = DISPLAY_WIDTH + 32; - sprite->pos1.y = DISPLAY_HEIGHT - 16; + sprite->pos1.x = TEXT_BOX_X; + sprite->pos1.y = TEXT_BOX_Y; sprite->pos2.y = 0; sprite->pos2.x = 0; sprite->callback = SpriteCallbackDummy; @@ -1377,7 +1399,7 @@ static void HideLinkResultsTextBox(void) | WININ_WIN1_BG_ALL | WININ_WIN1_OBJ | WININ_WIN1_CLR); } -static void LoadContestResultsTilemaps(void) +static void LoadContestResultsTitleBarTilemaps(void) { u8 palette; int x, y; @@ -1386,58 +1408,58 @@ static void LoadContestResultsTilemaps(void) y = 1; if (gLinkContestFlags & LINK_CONTEST_FLAG_IS_LINK) { - CopyToBgTilemapBufferRect(2, gLinkContestResults_Tilemap, 5, 1, 5, 2); + CopyToBgTilemapBufferRect(2, gContestResultsTitle_Link_Tilemap, 5, 1, 5, 2); x = 10; } else if (gSpecialVar_ContestRank == CONTEST_RANK_NORMAL) { - CopyToBgTilemapBufferRect(2, gNormalContestResults_Tilemap, 5, 1, 10, 2); + CopyToBgTilemapBufferRect(2, gContestResultsTitle_Normal_Tilemap, 5, 1, 10, 2); x = 15; } else if (gSpecialVar_ContestRank == CONTEST_RANK_SUPER) { - CopyToBgTilemapBufferRect(2, gSuperContestResults_Tilemap, 5, 1, 10, 2); + CopyToBgTilemapBufferRect(2, gContestResultsTitle_Super_Tilemap, 5, 1, 10, 2); x = 15; } else if (gSpecialVar_ContestRank == CONTEST_RANK_HYPER) { - CopyToBgTilemapBufferRect(2, gHyperContestResults_Tilemap, 5, 1, 10, 2); + CopyToBgTilemapBufferRect(2, gContestResultsTitle_Hyper_Tilemap, 5, 1, 10, 2); x = 15; } else // CONTEST_RANK_MASTER { - CopyToBgTilemapBufferRect(2, gMasterContestResults_Tilemap, 5, 1, 10, 2); + CopyToBgTilemapBufferRect(2, gContestResultsTitle_Master_Tilemap, 5, 1, 10, 2); x = 15; } if (gSpecialVar_ContestCategory == CONTEST_CATEGORY_COOL) { palette = 0; - CopyToBgTilemapBufferRect(2, gCoolContestResults_Tilemap, x, y, 5, 2); + CopyToBgTilemapBufferRect(2, gContestResultsTitle_Cool_Tilemap, x, y, 5, 2); } else if (gSpecialVar_ContestCategory == CONTEST_CATEGORY_BEAUTY) { palette = 1; - CopyToBgTilemapBufferRect(2, gBeautyContestResults_Tilemap, x, y, 5, 2); + CopyToBgTilemapBufferRect(2, gContestResultsTitle_Beauty_Tilemap, x, y, 5, 2); } else if (gSpecialVar_ContestCategory == CONTEST_CATEGORY_CUTE) { palette = 2; - CopyToBgTilemapBufferRect(2, gCuteContestResults_Tilemap, x, y, 5, 2); + CopyToBgTilemapBufferRect(2, gContestResultsTitle_Cute_Tilemap, x, y, 5, 2); } else if (gSpecialVar_ContestCategory == CONTEST_CATEGORY_SMART) { palette = 3; - CopyToBgTilemapBufferRect(2, gSmartContestResults_Tilemap, x, y, 5, 2); + CopyToBgTilemapBufferRect(2, gContestResultsTitle_Smart_Tilemap, x, y, 5, 2); } else // CONTEST_CATEGORY_TOUGH { palette = 4; - CopyToBgTilemapBufferRect(2, gToughContestResults_Tilemap, x, y, 5, 2); + CopyToBgTilemapBufferRect(2, gContestResultsTitle_Tough_Tilemap, x, y, 5, 2); } x += 5; - CopyToBgTilemapBufferRect(2, gContestResults_Tilemap, x, y, 6, 2); + CopyToBgTilemapBufferRect(2, gContestResultsTitle_Tilemap, x, y, 6, 2); CopyToBgTilemapBufferRect_ChangePalette(2, sContestResults->tilemapBuffers[2], 0, 0, 32, 4, palette); } @@ -1567,10 +1589,10 @@ static void SpriteCB_WinnerMonSlideIn(struct Sprite *sprite) sprite->pos1.x -= delta >> 8; sprite->data[1] += 0x600; sprite->data[1] &= 0xFF; - if (sprite->pos1.x < 120) - sprite->pos1.x = 120; + if (sprite->pos1.x < DISPLAY_WIDTH / 2) + sprite->pos1.x = DISPLAY_WIDTH / 2; - if (sprite->pos1.x == 120) + if (sprite->pos1.x == DISPLAY_WIDTH / 2) { sprite->callback = SpriteCallbackDummy; sprite->data[1] = 0; @@ -1628,7 +1650,7 @@ static void SpriteCB_Confetti(struct Sprite *sprite) if (sContestResults->data->destroyConfetti) sprite->invisible = TRUE; - if (sprite->pos1.x > 248 || sprite->pos1.y > 116) + if (sprite->pos1.x > DISPLAY_WIDTH + 8 || sprite->pos1.y > 116) { DestroySprite(sprite); sContestResults->data->confettiCount--; diff --git a/src/graphics.c b/src/graphics.c index 09779eab7..d8991c535 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -471,11 +471,11 @@ const u8 gContestSliderHeart_Gfx[] = INCBIN_U8("graphics/contest/slider_heart.4b const u32 gUnknownGfx_C19470[] = INCBIN_U32("graphics/unknown/unknown_C19470.4bpp.lz"); const u32 gUnknownPal_C19470[] = INCBIN_U32("graphics/unknown/unknown_C19470.gbapal.lz"); -const u32 gContestResults_Gfx[] = INCBIN_U32("graphics/contest/results_screen.4bpp.lz"); -const u32 gUnknown_08C19EEC[] = INCBIN_U32("graphics/contest/misc_2_tilemap_1.bin.lz"); -const u32 gUnknown_08C1A000[] = INCBIN_U32("graphics/contest/misc_2_tilemap_2.bin.lz"); -const u32 gUnknown_08C1A12C[] = INCBIN_U32("graphics/contest/misc_2_tilemap_3.bin.lz"); -const u32 gContestResults_Pal[] = INCBIN_U32("graphics/contest/results_screen.gbapal.lz"); +const u32 gContestResults_Gfx[] = INCBIN_U32("graphics/contest/results_screen/tiles.4bpp.lz"); +const u32 gContestResults_WinnerBanner_Tilemap[] = INCBIN_U32("graphics/contest/results_screen/winner_banner.bin.lz"); +const u32 gContestResults_Interface_Tilemap[] = INCBIN_U32("graphics/contest/results_screen/interface.bin.lz"); +const u32 gContestResults_Bg_Tilemap[] = INCBIN_U32("graphics/contest/results_screen/bg.bin.lz"); +const u32 gContestResults_Pal[] = INCBIN_U32("graphics/contest/results_screen/tiles.gbapal.lz"); const u32 gBattleAnimSpriteGfx_Impact[] = INCBIN_U32("graphics/battle_anims/sprites/impact.4bpp.lz"); const u32 gBattleAnimSpritePal_Impact[] = INCBIN_U32("graphics/battle_anims/sprites/impact.gbapal.lz"); @@ -1296,17 +1296,17 @@ const u8 gBagMenuHMIcon_Gfx[] = INCBIN_U8("graphics/interface/hm.4bpp"); // contest results screen -const u16 gNormalContestResults_Tilemap[] = INCBIN_U16("graphics/contest/results_screen_normal.bin"); -const u16 gSuperContestResults_Tilemap[] = INCBIN_U16("graphics/contest/results_screen_super.bin"); -const u16 gHyperContestResults_Tilemap[] = INCBIN_U16("graphics/contest/results_screen_hyper.bin"); -const u16 gMasterContestResults_Tilemap[] = INCBIN_U16("graphics/contest/results_screen_master.bin"); -const u16 gLinkContestResults_Tilemap[] = INCBIN_U16("graphics/contest/results_screen_link.bin"); -const u16 gCoolContestResults_Tilemap[] = INCBIN_U16("graphics/contest/results_screen_cool.bin"); -const u16 gBeautyContestResults_Tilemap[] = INCBIN_U16("graphics/contest/results_screen_beauty.bin"); -const u16 gCuteContestResults_Tilemap[] = INCBIN_U16("graphics/contest/results_screen_cute.bin"); -const u16 gSmartContestResults_Tilemap[] = INCBIN_U16("graphics/contest/results_screen_smart.bin"); -const u16 gToughContestResults_Tilemap[] = INCBIN_U16("graphics/contest/results_screen_tough.bin"); -const u16 gContestResults_Tilemap[] = INCBIN_U16("graphics/contest/results_screen.bin"); +const u16 gContestResultsTitle_Normal_Tilemap[] = INCBIN_U16("graphics/contest/results_screen/title_normal.bin"); +const u16 gContestResultsTitle_Super_Tilemap[] = INCBIN_U16("graphics/contest/results_screen/title_super.bin"); +const u16 gContestResultsTitle_Hyper_Tilemap[] = INCBIN_U16("graphics/contest/results_screen/title_hyper.bin"); +const u16 gContestResultsTitle_Master_Tilemap[] = INCBIN_U16("graphics/contest/results_screen/title_master.bin"); +const u16 gContestResultsTitle_Link_Tilemap[] = INCBIN_U16("graphics/contest/results_screen/title_link.bin"); +const u16 gContestResultsTitle_Cool_Tilemap[] = INCBIN_U16("graphics/contest/results_screen/title_cool.bin"); +const u16 gContestResultsTitle_Beauty_Tilemap[] = INCBIN_U16("graphics/contest/results_screen/title_beauty.bin"); +const u16 gContestResultsTitle_Cute_Tilemap[] = INCBIN_U16("graphics/contest/results_screen/title_cute.bin"); +const u16 gContestResultsTitle_Smart_Tilemap[] = INCBIN_U16("graphics/contest/results_screen/title_smart.bin"); +const u16 gContestResultsTitle_Tough_Tilemap[] = INCBIN_U16("graphics/contest/results_screen/title_tough.bin"); +const u16 gContestResultsTitle_Tilemap[] = INCBIN_U16("graphics/contest/results_screen/title.bin"); // pokenav From dbe24f0baa560aaa30f3084f1dfb21fb3cfb04db Mon Sep 17 00:00:00 2001 From: GriffinR Date: Wed, 21 Apr 2021 20:04:12 -0400 Subject: [PATCH 03/11] Clean up contest_painting --- asm/macros/event.inc | 6 +- .../LilycoveCity_ContestLobby/scripts.inc | 16 +- .../scripts.inc | 10 +- data/script_cmd_table.inc | 2 +- data/specials.inc | 2 +- data/text/contest_painting.inc | 2 +- .../picture_frame/{frame1.png => beauty.png} | Bin .../{frame1_map.bin => beauty_map.bin} | Bin .../picture_frame/{frame0.png => cool.png} | Bin .../{frame0_map.bin => cool_map.bin} | Bin .../picture_frame/{frame2.png => cute.png} | Bin .../{frame2_map.bin => cute_map.bin} | Bin .../picture_frame/{frame5.png => lobby.png} | Bin .../{frame5_map.bin => lobby_map.bin} | Bin .../picture_frame/{frame3.png => smart.png} | Bin .../{frame3_map.bin => smart_map.bin} | Bin .../picture_frame/{frame4.png => tough.png} | Bin .../{frame4_map.bin => tough_map.bin} | Bin graphics_file_rules.mk | 2 +- include/constants/contest.h | 16 +- include/contest.h | 8 +- include/contest_util.h | 2 +- src/contest.c | 60 +++-- src/contest_painting.c | 252 +++++++++--------- src/contest_util.c | 24 +- src/data/contest_opponents.h | 16 +- src/scrcmd.c | 6 +- 27 files changed, 226 insertions(+), 198 deletions(-) rename graphics/picture_frame/{frame1.png => beauty.png} (100%) rename graphics/picture_frame/{frame1_map.bin => beauty_map.bin} (100%) rename graphics/picture_frame/{frame0.png => cool.png} (100%) rename graphics/picture_frame/{frame0_map.bin => cool_map.bin} (100%) rename graphics/picture_frame/{frame2.png => cute.png} (100%) rename graphics/picture_frame/{frame2_map.bin => cute_map.bin} (100%) rename graphics/picture_frame/{frame5.png => lobby.png} (100%) rename graphics/picture_frame/{frame5_map.bin => lobby_map.bin} (100%) rename graphics/picture_frame/{frame3.png => smart.png} (100%) rename graphics/picture_frame/{frame3_map.bin => smart_map.bin} (100%) rename graphics/picture_frame/{frame4.png => tough.png} (100%) rename graphics/picture_frame/{frame4_map.bin => tough_map.bin} (100%) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index 84fdd592a..f3f17c5d8 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -918,10 +918,10 @@ .byte 0x76 .endm - @ Draws an image of the winner of the contest. In FireRed, this command is a nop. (The argument is discarded.) - .macro showcontestwinner a:req + @ Draws an image of the winner of the contest. winnerId is any CONTEST_WINNER_* constant. + .macro showcontestpainting winnerId:req .byte 0x77 - .byte \a + .byte \winnerId .endm @ Displays the string at pointer as braille text in a standard message box. The string must be formatted to use braille diff --git a/data/maps/LilycoveCity_ContestLobby/scripts.inc b/data/maps/LilycoveCity_ContestLobby/scripts.inc index 300d4dfab..3642bc1d1 100644 --- a/data/maps/LilycoveCity_ContestLobby/scripts.inc +++ b/data/maps/LilycoveCity_ContestLobby/scripts.inc @@ -49,7 +49,7 @@ LilycoveCity_ContestLobby_EventScript_ContestArtist:: @ 821A264 msgbox LilycoveCity_ContestLobby_Text_YourPokemonSpurredMeToPaint, MSGBOX_DEFAULT lockall fadescreen FADE_TO_BLACK - showcontestwinner CONTEST_WINNER_ARTIST + showcontestpainting CONTEST_WINNER_ARTIST lockall msgbox LilycoveCity_ContestLobby_Text_ShouldITakePaintingToMuseum, MSGBOX_YESNO compare VAR_RESULT, YES @@ -223,7 +223,7 @@ LilycoveCity_ContestLobby_EventScript_LinkContestArtist:: @ 821A436 msgbox LilycoveCity_ContestLobby_Text_YourPokemonSpurredMeToPaint, MSGBOX_DEFAULT lockall fadescreen FADE_TO_BLACK - showcontestwinner CONTEST_WINNER_ARTIST + showcontestpainting CONTEST_WINNER_ARTIST msgbox LilycoveCity_ContestLobby_Text_ShouldITakePaintingToMuseum, MSGBOX_YESNO compare VAR_RESULT, YES goto_if_eq LilycoveCity_ContestLobby_EventScript_TakePaintingToMuseumLink @@ -511,42 +511,42 @@ LilycoveCity_ContestLobby_EventScript_NinjaBoy:: @ 821A735 LilycoveCity_ContestLobby_EventScript_ContestWinner1:: @ 821A73E lockall fadescreen FADE_TO_BLACK - showcontestwinner CONTEST_WINNER_HALL_1 + showcontestpainting CONTEST_WINNER_HALL_1 releaseall end LilycoveCity_ContestLobby_EventScript_ContestWinner2:: @ 821A745 lockall fadescreen FADE_TO_BLACK - showcontestwinner CONTEST_WINNER_HALL_2 + showcontestpainting CONTEST_WINNER_HALL_2 releaseall end LilycoveCity_ContestLobby_EventScript_ContestWinner3:: @ 821A74C lockall fadescreen FADE_TO_BLACK - showcontestwinner CONTEST_WINNER_HALL_3 + showcontestpainting CONTEST_WINNER_HALL_3 releaseall end LilycoveCity_ContestLobby_EventScript_ContestWinner4:: @ 821A753 lockall fadescreen FADE_TO_BLACK - showcontestwinner CONTEST_WINNER_HALL_4 + showcontestpainting CONTEST_WINNER_HALL_4 releaseall end LilycoveCity_ContestLobby_EventScript_ContestWinner5:: @ 821A75A lockall fadescreen FADE_TO_BLACK - showcontestwinner CONTEST_WINNER_HALL_5 + showcontestpainting CONTEST_WINNER_HALL_5 releaseall end LilycoveCity_ContestLobby_EventScript_ContestWinner6:: @ 821A761 lockall fadescreen FADE_TO_BLACK - showcontestwinner CONTEST_WINNER_HALL_6 + showcontestpainting CONTEST_WINNER_HALL_6 releaseall end diff --git a/data/maps/LilycoveCity_LilycoveMuseum_2F/scripts.inc b/data/maps/LilycoveCity_LilycoveMuseum_2F/scripts.inc index 4cebebd82..c769f4b55 100644 --- a/data/maps/LilycoveCity_LilycoveMuseum_2F/scripts.inc +++ b/data/maps/LilycoveCity_LilycoveMuseum_2F/scripts.inc @@ -185,35 +185,35 @@ LilycoveCity_LilycoveMuseum_2F_EventScript_RichBoy:: @ 821999C LilycoveCity_LilycoveMuseum_2F_EventScript_ShowCoolPainting:: @ 82199A5 msgbox LilycoveCity_LilycoveMuseum_2F_Text_ItsPaintingOfPokemon, MSGBOX_SIGN fadescreen FADE_TO_BLACK - showcontestwinner CONTEST_WINNER_MUSEUM_COOL + showcontestpainting CONTEST_WINNER_MUSEUM_COOL releaseall end LilycoveCity_LilycoveMuseum_2F_EventScript_ShowBeautyPainting:: @ 82199B3 msgbox LilycoveCity_LilycoveMuseum_2F_Text_ItsPaintingOfPokemon, MSGBOX_SIGN fadescreen FADE_TO_BLACK - showcontestwinner CONTEST_WINNER_MUSEUM_BEAUTY + showcontestpainting CONTEST_WINNER_MUSEUM_BEAUTY releaseall end LilycoveCity_LilycoveMuseum_2F_EventScript_ShowCutePainting:: @ 82199C1 msgbox LilycoveCity_LilycoveMuseum_2F_Text_ItsPaintingOfPokemon, MSGBOX_SIGN fadescreen FADE_TO_BLACK - showcontestwinner CONTEST_WINNER_MUSEUM_CUTE + showcontestpainting CONTEST_WINNER_MUSEUM_CUTE releaseall end LilycoveCity_LilycoveMuseum_2F_EventScript_ShowSmartPainting:: @ 82199CF msgbox LilycoveCity_LilycoveMuseum_2F_Text_ItsPaintingOfPokemon, MSGBOX_SIGN fadescreen FADE_TO_BLACK - showcontestwinner CONTEST_WINNER_MUSEUM_SMART + showcontestpainting CONTEST_WINNER_MUSEUM_SMART releaseall end LilycoveCity_LilycoveMuseum_2F_EventScript_ShowToughPainting:: @ 82199DD msgbox LilycoveCity_LilycoveMuseum_2F_Text_ItsPaintingOfPokemon, MSGBOX_SIGN fadescreen FADE_TO_BLACK - showcontestwinner CONTEST_WINNER_MUSEUM_TOUGH + showcontestpainting CONTEST_WINNER_MUSEUM_TOUGH releaseall end diff --git a/data/script_cmd_table.inc b/data/script_cmd_table.inc index a26ce6bf2..9e54ad52b 100644 --- a/data/script_cmd_table.inc +++ b/data/script_cmd_table.inc @@ -119,7 +119,7 @@ gScriptCmdTable:: @ 81DB67C .4byte ScrCmd_drawboxtext @ 0x74 .4byte ScrCmd_showmonpic @ 0x75 .4byte ScrCmd_hidemonpic @ 0x76 - .4byte ScrCmd_showcontestwinner @ 0x77 + .4byte ScrCmd_showcontestpainting @ 0x77 .4byte ScrCmd_braillemessage @ 0x78 .4byte ScrCmd_givemon @ 0x79 .4byte ScrCmd_giveegg @ 0x7a diff --git a/data/specials.inc b/data/specials.inc index f672a7b87..4c2a6dc73 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -149,7 +149,7 @@ gSpecials:: @ 81DBA64 def_special SaveMuseumContestPainting def_special DoesContestCategoryHaveWinner def_special CountPlayerContestPaintings - def_special ShowContestWinnerPainting + def_special ShowContestPainting @ Unused, redundant with showcontestpainting command def_special MauvilleGymSetDefaultBarriers def_special MauvilleGymPressSwitch def_special ShowFieldMessageStringVar4 diff --git a/data/text/contest_painting.inc b/data/text/contest_painting.inc index 78ae80153..b423fbb27 100644 --- a/data/text/contest_painting.inc +++ b/data/text/contest_painting.inc @@ -1,4 +1,4 @@ -gContestPaintingCaption:: @ 827EA0C +gContestHallPaintingCaption:: @ 827EA0C .string "{STR_VAR_1}\n" .string "{STR_VAR_2}'s {STR_VAR_3}$" diff --git a/graphics/picture_frame/frame1.png b/graphics/picture_frame/beauty.png similarity index 100% rename from graphics/picture_frame/frame1.png rename to graphics/picture_frame/beauty.png diff --git a/graphics/picture_frame/frame1_map.bin b/graphics/picture_frame/beauty_map.bin similarity index 100% rename from graphics/picture_frame/frame1_map.bin rename to graphics/picture_frame/beauty_map.bin diff --git a/graphics/picture_frame/frame0.png b/graphics/picture_frame/cool.png similarity index 100% rename from graphics/picture_frame/frame0.png rename to graphics/picture_frame/cool.png diff --git a/graphics/picture_frame/frame0_map.bin b/graphics/picture_frame/cool_map.bin similarity index 100% rename from graphics/picture_frame/frame0_map.bin rename to graphics/picture_frame/cool_map.bin diff --git a/graphics/picture_frame/frame2.png b/graphics/picture_frame/cute.png similarity index 100% rename from graphics/picture_frame/frame2.png rename to graphics/picture_frame/cute.png diff --git a/graphics/picture_frame/frame2_map.bin b/graphics/picture_frame/cute_map.bin similarity index 100% rename from graphics/picture_frame/frame2_map.bin rename to graphics/picture_frame/cute_map.bin diff --git a/graphics/picture_frame/frame5.png b/graphics/picture_frame/lobby.png similarity index 100% rename from graphics/picture_frame/frame5.png rename to graphics/picture_frame/lobby.png diff --git a/graphics/picture_frame/frame5_map.bin b/graphics/picture_frame/lobby_map.bin similarity index 100% rename from graphics/picture_frame/frame5_map.bin rename to graphics/picture_frame/lobby_map.bin diff --git a/graphics/picture_frame/frame3.png b/graphics/picture_frame/smart.png similarity index 100% rename from graphics/picture_frame/frame3.png rename to graphics/picture_frame/smart.png diff --git a/graphics/picture_frame/frame3_map.bin b/graphics/picture_frame/smart_map.bin similarity index 100% rename from graphics/picture_frame/frame3_map.bin rename to graphics/picture_frame/smart_map.bin diff --git a/graphics/picture_frame/frame4.png b/graphics/picture_frame/tough.png similarity index 100% rename from graphics/picture_frame/frame4.png rename to graphics/picture_frame/tough.png diff --git a/graphics/picture_frame/frame4_map.bin b/graphics/picture_frame/tough_map.bin similarity index 100% rename from graphics/picture_frame/frame4_map.bin rename to graphics/picture_frame/tough_map.bin diff --git a/graphics_file_rules.mk b/graphics_file_rules.mk index 6a3bf4006..a369d973e 100644 --- a/graphics_file_rules.mk +++ b/graphics_file_rules.mk @@ -476,7 +476,7 @@ $(RAYQUAZAGFXDIR)/scene_4/streaks.4bpp: %.4bpp: %.png $(RAYQUAZAGFXDIR)/scene_4/rayquaza.4bpp: %.4bpp: %.png $(GFX) $< $@ -num_tiles 155 -graphics/picture_frame/frame5.4bpp: %.4bpp: %.png +graphics/picture_frame/lobby.4bpp: %.4bpp: %.png $(GFX) $< $@ -num_tiles 86 $(ROULETTEGFXDIR)/roulette_tilt.4bpp: $(ROULETTEGFXDIR)/shroomish.4bpp \ diff --git a/include/constants/contest.h b/include/constants/contest.h index 9eb6b26e4..c18af0817 100644 --- a/include/constants/contest.h +++ b/include/constants/contest.h @@ -22,7 +22,9 @@ #define CONTEST_TYPE_NPC_MASTER (CONTEST_RANK_MASTER + 1) #define CONTEST_TYPE_LINK (CONTEST_RANK_LINK + 1) -#define CONTEST_WINNER_ARTIST 0 // Winner shown by the artist, painting not necessarily saved +// IDs below - 1 are indexes into gSaveBlock1Ptr->contestWinners[] +// CONTEST_WINNER_ARTIST is for the winner of the most recent contest, and is not saved. +#define CONTEST_WINNER_ARTIST 0 #define CONTEST_WINNER_HALL_1 1 #define CONTEST_WINNER_HALL_2 2 #define CONTEST_WINNER_HALL_3 3 @@ -30,8 +32,8 @@ #define CONTEST_WINNER_HALL_5 5 #define CONTEST_WINNER_HALL_6 6 #define NUM_CONTEST_HALL_WINNERS 6 -#define CONTEST_WINNER_7 7 -#define CONTEST_WINNER_8 8 +#define CONTEST_WINNER_HALL_UNUSED 7 +#define CONTEST_WINNER_MUSEUM_UNUSED 8 #define CONTEST_WINNER_MUSEUM_COOL 9 #define CONTEST_WINNER_MUSEUM_BEAUTY 10 #define CONTEST_WINNER_MUSEUM_CUTE 11 @@ -39,6 +41,14 @@ #define CONTEST_WINNER_MUSEUM_TOUGH 13 // NUM_CONTEST_WINNERS in constants/global.h +#define MUSEUM_CONTEST_WINNERS_START CONTEST_WINNER_MUSEUM_UNUSED + +// The number of possible captions for a Contest painting, per category +#define NUM_PAINTING_CAPTIONS 3 + +#define CONTEST_SAVE_FOR_MUSEUM ((u8)-1) +#define CONTEST_SAVE_FOR_ARTIST ((u8)-2) + #define CANT_ENTER_CONTEST 0 #define CAN_ENTER_CONTEST_EQUAL_RANK 1 #define CAN_ENTER_CONTEST_HIGH_RANK 2 diff --git a/include/contest.h b/include/contest.h index 1dd4340bd..6469bf628 100644 --- a/include/contest.h +++ b/include/contest.h @@ -326,8 +326,8 @@ extern u8 gHighestRibbonRank; extern struct ContestResources *gContestResources; extern u8 sContestBgCopyFlags; extern struct ContestWinner gCurContestWinner; -extern u8 gUnknown_02039F5C; -extern u8 gUnknown_02039F5D; +extern u8 gCurContestWinnerIsForArtist; +extern u8 gCurContestWinnerSaveIdx; extern u32 gContestRngValue; // contest.c @@ -351,8 +351,8 @@ s8 Contest_GetMoveExcitement(u16 move); bool8 IsContestantAllowedToCombo(u8 contestant); void Contest_PrintTextToBg0WindowAt(u32 windowId, u8 *currChar, s32 x, s32 y, s32 fontId); void ResetContestLinkResults(void); -bool8 sub_80DEDA8(u8 a); -u8 sub_80DEFA8(u8 a, u8 b); +bool8 SaveContestWinner(u8 rank); +u8 GetContestWinnerSaveIdx(u8 rank, bool8 shift); void ClearContestWinnerPicsInContestHall(void); void StripPlayerAndMonNamesForLinkContest(struct ContestPokemon *mon, s32 language); diff --git a/include/contest_util.h b/include/contest_util.h index 76f9ae522..5b0c5559a 100644 --- a/include/contest_util.h +++ b/include/contest_util.h @@ -7,7 +7,7 @@ void StartContest(void); void BufferContestantMonSpecies(void); void ShowContestResults(void); void ContestLinkTransfer(u8); -void ShowContestWinnerPainting(void); +void ShowContestPainting(void); u16 GetContestRand(void); u8 CountPlayerContestPaintings(void); diff --git a/src/contest.c b/src/contest.c index 246fc1e50..59f50fcfc 100644 --- a/src/contest.c +++ b/src/contest.c @@ -350,8 +350,8 @@ EWRAM_DATA u8 gHighestRibbonRank = 0; EWRAM_DATA struct ContestResources *gContestResources = NULL; EWRAM_DATA u8 sContestBgCopyFlags = 0; EWRAM_DATA struct ContestWinner gCurContestWinner = {0}; -EWRAM_DATA bool8 gUnknown_02039F5C = 0; -EWRAM_DATA u8 gUnknown_02039F5D = 0; +EWRAM_DATA bool8 gCurContestWinnerIsForArtist = 0; +EWRAM_DATA u8 gCurContestWinnerSaveIdx = 0; // IWRAM common vars. u32 gContestRngValue; @@ -5516,40 +5516,47 @@ void ResetContestLinkResults(void) gSaveBlock2Ptr->contestLinkResults[i][j] = 0; } -bool8 sub_80DEDA8(u8 rank) +bool8 SaveContestWinner(u8 rank) { s32 i; - u8 r7 = Random() % 3; + u8 captionId = Random() % NUM_PAINTING_CAPTIONS; + // Get the index of the winner among the contestants for (i = 0; i < CONTESTANT_COUNT - 1; i++) - { if (gContestFinalStandings[i] == 0) break; - } - if (rank == 0xFF && i != gContestPlayerMonIndex) + + // Exit if attempting to save a Pokémon other than the player's to the museum + if (rank == CONTEST_SAVE_FOR_MUSEUM && i != gContestPlayerMonIndex) return FALSE; + + + // Adjust the random painting caption depending on the category switch (gSpecialVar_ContestCategory) { case CONTEST_CATEGORY_COOL: - r7 += 0; + captionId += NUM_PAINTING_CAPTIONS * CONTEST_CATEGORY_COOL; break; case CONTEST_CATEGORY_BEAUTY: - r7 += 3; + captionId += NUM_PAINTING_CAPTIONS * CONTEST_CATEGORY_BEAUTY; break; case CONTEST_CATEGORY_CUTE: - r7 += 6; + captionId += NUM_PAINTING_CAPTIONS * CONTEST_CATEGORY_CUTE; break; case CONTEST_CATEGORY_SMART: - r7 += 9; + captionId += NUM_PAINTING_CAPTIONS * CONTEST_CATEGORY_SMART; break; case CONTEST_CATEGORY_TOUGH: - r7 += 12; + captionId += NUM_PAINTING_CAPTIONS * CONTEST_CATEGORY_TOUGH; break; } - if (rank != 0xFE) - { - u8 id = sub_80DEFA8(rank, 1); + if (rank != CONTEST_SAVE_FOR_ARTIST) + { + // Save winner in the saveblock + // Used to save any winner for the Contest Hall or the Museum + // but excludes the temporary save used by the artist + u8 id = GetContestWinnerSaveIdx(rank, TRUE); gSaveBlock1Ptr->contestWinners[id].personality = gContestMons[i].personality; gSaveBlock1Ptr->contestWinners[id].species = gContestMons[i].species; gSaveBlock1Ptr->contestWinners[id].trainerId = gContestMons[i].otId; @@ -5560,24 +5567,29 @@ bool8 sub_80DEDA8(u8 rank) else gSaveBlock1Ptr->contestWinners[id].contestRank = gSpecialVar_ContestRank; - if (rank != 0xFF) + if (rank != CONTEST_SAVE_FOR_MUSEUM) gSaveBlock1Ptr->contestWinners[id].contestCategory = gSpecialVar_ContestCategory; else - gSaveBlock1Ptr->contestWinners[id].contestCategory = r7; + gSaveBlock1Ptr->contestWinners[id].contestCategory = captionId; } else { + // Set the most recent winner so the artist can show the player their painting gCurContestWinner.personality = gContestMons[i].personality; gCurContestWinner.trainerId = gContestMons[i].otId; gCurContestWinner.species = gContestMons[i].species; StringCopy(gCurContestWinner.monName, gContestMons[i].nickname); StringCopy(gCurContestWinner.trainerName, gContestMons[i].trainerName); - gCurContestWinner.contestCategory = r7; + gCurContestWinner.contestCategory = captionId; } return TRUE; } -u8 sub_80DEFA8(u8 rank, u8 b) +// Rank is either a regular contest rank (for saving winners to show in the Contest Hall) +// Or one of two special IDs listed below (for saving winners to show in Museum, or from the artist) +// If just retrieving the index where the winner *would* go, shift is FALSE +// If actually preparing to insert the winner into the saveblock, shift is TRUE +u8 GetContestWinnerSaveIdx(u8 rank, bool8 shift) { s32 i; @@ -5587,13 +5599,15 @@ u8 sub_80DEFA8(u8 rank, u8 b) case CONTEST_RANK_SUPER: case CONTEST_RANK_HYPER: case CONTEST_RANK_MASTER: - if (b != 0) + if (shift) { - for (i = NUM_CONTEST_HALL_WINNERS - 1; i >= 1; i--) + for (i = NUM_CONTEST_HALL_WINNERS - 1; i > 0; i--) memcpy(&gSaveBlock1Ptr->contestWinners[i], &gSaveBlock1Ptr->contestWinners[i - 1], sizeof(struct ContestWinner)); } - return 0; + return CONTEST_WINNER_HALL_1 - 1; default: +// case CONTEST_SAVE_FOR_MUSEUM: +// case CONTEST_SAVE_FOR_ARTIST: switch (gSpecialVar_ContestCategory) { case CONTEST_CATEGORY_COOL: @@ -5615,7 +5629,7 @@ void ClearContestWinnerPicsInContestHall(void) { s32 i; - for (i = 0; i < 8; i++) + for (i = 0; i < MUSEUM_CONTEST_WINNERS_START; i++) gSaveBlock1Ptr->contestWinners[i] = gDefaultContestWinners[i]; } diff --git a/src/contest_painting.c b/src/contest_painting.c index 4f0bf9245..ca5d8c0a9 100644 --- a/src/contest_painting.c +++ b/src/contest_painting.c @@ -21,18 +21,16 @@ #include "window.h" #include "constants/rgb.h" -// IWRAM common u16 (*gContestMonPixels)[][32]; struct ImageProcessingContext gImageProcessingContext; struct ContestWinner *gContestPaintingWinner; u16 *gContestPaintingMonPalette; -// IWRAM bss -static u8 gContestPaintingState; -static u16 gContestPaintingMosaicVal; -static u16 gContestPaintingFadeCounter; -static bool8 gUnknown_030011F6; -static u8 gContestPaintingWindowId; +static u8 sHoldState; +static u16 sMosaicVal; +static u16 sFadeCounter; +static bool8 sVarsInitialized; +static u8 sWindowId; static void ShowContestPainting(void); static void HoldContestPainting(void); @@ -44,7 +42,7 @@ static void PrintContestPaintingCaption(u8, u8); static void VBlankCB_ContestPainting(void); static void _InitContestMonPixels(u8 *spriteGfx, u16 *palette, u16 (*destPixels)[64][64]); -extern const u8 gContestPaintingCaption[]; +extern const u8 gContestHallPaintingCaption[]; extern const u8 gContestCoolness[]; extern const u8 gContestBeauty[]; extern const u8 gContestCuteness[]; @@ -71,39 +69,39 @@ extern const u8 gContestPaintingTough1[]; extern const u8 gContestPaintingTough2[]; extern const u8 gContestPaintingTough3[]; -const u16 gPictureFramePalettes[] = INCBIN_U16("graphics/picture_frame/bg.gbapal"); -const u8 gPictureFrameTiles_0[] = INCBIN_U8("graphics/picture_frame/frame0.4bpp.rl"); -const u8 gPictureFrameTiles_1[] = INCBIN_U8("graphics/picture_frame/frame1.4bpp.rl"); -const u8 gPictureFrameTiles_2[] = INCBIN_U8("graphics/picture_frame/frame2.4bpp.rl"); -const u8 gPictureFrameTiles_3[] = INCBIN_U8("graphics/picture_frame/frame3.4bpp.rl"); -const u8 gPictureFrameTiles_4[] = INCBIN_U8("graphics/picture_frame/frame4.4bpp.rl"); -const u8 gPictureFrameTiles_5[] = INCBIN_U8("graphics/picture_frame/frame5.4bpp.rl"); -const u8 gPictureFrameTilemap_0[] = INCBIN_U8("graphics/picture_frame/frame0_map.bin.rl"); -const u8 gPictureFrameTilemap_1[] = INCBIN_U8("graphics/picture_frame/frame1_map.bin.rl"); -const u8 gPictureFrameTilemap_2[] = INCBIN_U8("graphics/picture_frame/frame2_map.bin.rl"); -const u8 gPictureFrameTilemap_3[] = INCBIN_U8("graphics/picture_frame/frame3_map.bin.rl"); -const u8 gPictureFrameTilemap_4[] = INCBIN_U8("graphics/picture_frame/frame4_map.bin.rl"); -const u8 gPictureFrameTilemap_5[] = INCBIN_U8("graphics/picture_frame/frame5_map.bin.rl"); +static const u16 sPictureFramePalettes[] = INCBIN_U16("graphics/picture_frame/bg.gbapal"); +static const u8 sPictureFrameTiles_Cool[] = INCBIN_U8("graphics/picture_frame/cool.4bpp.rl"); +static const u8 sPictureFrameTiles_Beauty[] = INCBIN_U8("graphics/picture_frame/beauty.4bpp.rl"); +static const u8 sPictureFrameTiles_Cute[] = INCBIN_U8("graphics/picture_frame/cute.4bpp.rl"); +static const u8 sPictureFrameTiles_Smart[] = INCBIN_U8("graphics/picture_frame/smart.4bpp.rl"); +static const u8 sPictureFrameTiles_Tough[] = INCBIN_U8("graphics/picture_frame/tough.4bpp.rl"); +static const u8 sPictureFrameTiles_HallLobby[] = INCBIN_U8("graphics/picture_frame/lobby.4bpp.rl"); +static const u8 sPictureFrameTilemap_Cool[] = INCBIN_U8("graphics/picture_frame/cool_map.bin.rl"); +static const u8 sPictureFrameTilemap_Beauty[] = INCBIN_U8("graphics/picture_frame/beauty_map.bin.rl"); +static const u8 sPictureFrameTilemap_Cute[] = INCBIN_U8("graphics/picture_frame/cute_map.bin.rl"); +static const u8 sPictureFrameTilemap_Smart[] = INCBIN_U8("graphics/picture_frame/smart_map.bin.rl"); +static const u8 sPictureFrameTilemap_Tough[] = INCBIN_U8("graphics/picture_frame/tough_map.bin.rl"); +static const u8 sPictureFrameTilemap_HallLobby[] = INCBIN_U8("graphics/picture_frame/lobby_map.bin.rl"); static const u8 *const sContestCategoryNames_Unused[] = { - gContestCoolness, - gContestBeauty, - gContestCuteness, - gContestSmartness, - gContestToughness, + [CONTEST_CATEGORY_COOL] = gContestCoolness, + [CONTEST_CATEGORY_BEAUTY] = gContestBeauty, + [CONTEST_CATEGORY_CUTE] = gContestCuteness, + [CONTEST_CATEGORY_SMART] = gContestSmartness, + [CONTEST_CATEGORY_TOUGH] = gContestToughness, }; static const u8 *const sContestRankNames[] = { - gContestRankNormal, - gContestRankSuper, - gContestRankHyper, - gContestRankMaster, - gContestLink, + [CONTEST_RANK_NORMAL] = gContestRankNormal, + [CONTEST_RANK_SUPER] = gContestRankSuper, + [CONTEST_RANK_HYPER] = gContestRankHyper, + [CONTEST_RANK_MASTER] = gContestRankMaster, + [CONTEST_RANK_LINK] = gContestLink, }; -static const struct BgTemplate sContestPaintingBgTemplates[] = +static const struct BgTemplate sBgTemplates[] = { { .bg = 1, @@ -116,7 +114,7 @@ static const struct BgTemplate sContestPaintingBgTemplates[] = }, }; -static const struct WindowTemplate sContestPaintingWindowTemplate = +static const struct WindowTemplate sWindowTemplate = { .bg = 1, .tilemapLeft = 2, @@ -127,23 +125,23 @@ static const struct WindowTemplate sContestPaintingWindowTemplate = .baseBlock = 1, }; -static const u8 *const sContestPaintingDescriptionPointers[] = +static const u8 *const sMuseumCaptions[NUM_PAINTING_CAPTIONS * CONTEST_CATEGORIES_COUNT] = { - gContestPaintingCool1, - gContestPaintingCool2, - gContestPaintingCool3, - gContestPaintingBeauty1, - gContestPaintingBeauty2, - gContestPaintingBeauty3, - gContestPaintingCute1, - gContestPaintingCute2, - gContestPaintingCute3, - gContestPaintingSmart1, - gContestPaintingSmart2, - gContestPaintingSmart3, - gContestPaintingTough1, - gContestPaintingTough2, - gContestPaintingTough3, + [0 + NUM_PAINTING_CAPTIONS * CONTEST_CATEGORY_COOL] = gContestPaintingCool1, + [1 + NUM_PAINTING_CAPTIONS * CONTEST_CATEGORY_COOL] = gContestPaintingCool2, + [2 + NUM_PAINTING_CAPTIONS * CONTEST_CATEGORY_COOL] = gContestPaintingCool3, + [0 + NUM_PAINTING_CAPTIONS * CONTEST_CATEGORY_BEAUTY] = gContestPaintingBeauty1, + [1 + NUM_PAINTING_CAPTIONS * CONTEST_CATEGORY_BEAUTY] = gContestPaintingBeauty2, + [2 + NUM_PAINTING_CAPTIONS * CONTEST_CATEGORY_BEAUTY] = gContestPaintingBeauty3, + [0 + NUM_PAINTING_CAPTIONS * CONTEST_CATEGORY_CUTE] = gContestPaintingCute1, + [1 + NUM_PAINTING_CAPTIONS * CONTEST_CATEGORY_CUTE] = gContestPaintingCute2, + [2 + NUM_PAINTING_CAPTIONS * CONTEST_CATEGORY_CUTE] = gContestPaintingCute3, + [0 + NUM_PAINTING_CAPTIONS * CONTEST_CATEGORY_SMART] = gContestPaintingSmart1, + [1 + NUM_PAINTING_CAPTIONS * CONTEST_CATEGORY_SMART] = gContestPaintingSmart2, + [2 + NUM_PAINTING_CAPTIONS * CONTEST_CATEGORY_SMART] = gContestPaintingSmart3, + [0 + NUM_PAINTING_CAPTIONS * CONTEST_CATEGORY_TOUGH] = gContestPaintingTough1, + [1 + NUM_PAINTING_CAPTIONS * CONTEST_CATEGORY_TOUGH] = gContestPaintingTough2, + [2 + NUM_PAINTING_CAPTIONS * CONTEST_CATEGORY_TOUGH] = gContestPaintingTough3, }; static const struct OamData sContestPaintingMonOamData = @@ -161,15 +159,15 @@ static const struct OamData sContestPaintingMonOamData = .paletteNum = 0, }; -const u16 gUnknown_085B0838[] = {RGB(0, 0, 0), RGB(0, 0, 0)}; +static const u16 sBg_Palette[] = {RGB_BLACK, RGB_BLACK}; void SetContestWinnerForPainting(int contestWinnerId) { - u8 *ptr1 = &gUnknown_02039F5D; - u8 *ptr2 = &gUnknown_02039F5C; + u8 *saveIdx = &gCurContestWinnerSaveIdx; + u8 *isForArtist = &gCurContestWinnerIsForArtist; gCurContestWinner = gSaveBlock1Ptr->contestWinners[contestWinnerId - 1]; - *ptr1 = contestWinnerId - 1; - *ptr2 = FALSE; + *saveIdx = contestWinnerId - 1; + *isForArtist = FALSE; } void CB2_ContestPainting(void) @@ -189,7 +187,7 @@ static void CB2_QuitContestPainting(void) SetMainCallback2(gMain.savedCallback); FREE_AND_SET_NULL(gContestPaintingMonPalette); FREE_AND_SET_NULL(gContestMonPixels); - RemoveWindow(gContestPaintingWindowId); + RemoveWindow(sWindowId); Free(GetBgTilemapBuffer(1)); FreeMonSpritesGfx(); } @@ -203,13 +201,13 @@ static void ShowContestPainting(void) SetVBlankCallback(NULL); AllocateMonSpritesGfx(); gContestPaintingWinner = &gCurContestWinner; - InitContestPaintingVars(1); + InitContestPaintingVars(TRUE); InitContestPaintingBg(); gMain.state++; break; case 1: ResetPaletteFade(); - DmaFillLarge32(3, 0, (void *)BG_VRAM, 0x18000, 0x1000); + DmaFillLarge32(3, 0, (void *)VRAM, VRAM_SIZE, 0x1000); ResetSpriteData(); gMain.state++; break; @@ -220,16 +218,16 @@ static void ShowContestPainting(void) gMain.state++; break; case 3: - CreateContestPaintingPicture(gUnknown_02039F5D, gUnknown_02039F5C); + CreateContestPaintingPicture(gCurContestWinnerSaveIdx, gCurContestWinnerIsForArtist); gMain.state++; break; case 4: - PrintContestPaintingCaption(gUnknown_02039F5D, gUnknown_02039F5C); - LoadPalette(gUnknown_085B0838, 0, 1 * 2); + PrintContestPaintingCaption(gCurContestWinnerSaveIdx, gCurContestWinnerIsForArtist); + LoadPalette(sBg_Palette, 0, 1 * 2); DmaClear32(3, PLTT, PLTT_SIZE); BeginFastPaletteFade(2); SetVBlankCallback(VBlankCB_ContestPainting); - gContestPaintingState = 0; + sHoldState = 0; SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG0_ON | DISPCNT_BG1_ON | DISPCNT_OBJ_ON); SetMainCallback2(CB2_HoldContestPainting); break; @@ -238,29 +236,29 @@ static void ShowContestPainting(void) static void HoldContestPainting(void) { - switch (gContestPaintingState) + switch (sHoldState) { case 0: if (!gPaletteFade.active) - gContestPaintingState = 1; - if (gUnknown_030011F6 && gContestPaintingFadeCounter) - gContestPaintingFadeCounter--; + sHoldState = 1; + if (sVarsInitialized && sFadeCounter) + sFadeCounter--; break; case 1: if ((JOY_NEW(A_BUTTON)) || (JOY_NEW(B_BUTTON))) { - gContestPaintingState++; + sHoldState++; BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB(0, 0, 0)); } - if (gUnknown_030011F6) - gContestPaintingFadeCounter = 0; + if (sVarsInitialized) + sFadeCounter = 0; break; case 2: if (!gPaletteFade.active) SetMainCallback2(CB2_QuitContestPainting); - if (gUnknown_030011F6 && gContestPaintingFadeCounter < 30) - gContestPaintingFadeCounter++; + if (sVarsInitialized && sFadeCounter < 30) + sFadeCounter++; break; } } @@ -268,45 +266,47 @@ static void HoldContestPainting(void) static void InitContestPaintingWindow(void) { ResetBgsAndClearDma3BusyFlags(0); - InitBgsFromTemplates(0, sContestPaintingBgTemplates, ARRAY_COUNT(sContestPaintingBgTemplates)); + InitBgsFromTemplates(0, sBgTemplates, ARRAY_COUNT(sBgTemplates)); ChangeBgX(1, 0, 0); ChangeBgY(1, 0, 0); SetBgTilemapBuffer(1, AllocZeroed(BG_SCREEN_SIZE)); - gContestPaintingWindowId = AddWindow(&sContestPaintingWindowTemplate); + sWindowId = AddWindow(&sWindowTemplate); DeactivateAllTextPrinters(); - FillWindowPixelBuffer(gContestPaintingWindowId, PIXEL_FILL(0)); - PutWindowTilemap(gContestPaintingWindowId); - CopyWindowToVram(gContestPaintingWindowId, 3); + FillWindowPixelBuffer(sWindowId, PIXEL_FILL(0)); + PutWindowTilemap(sWindowId); + CopyWindowToVram(sWindowId, 3); ShowBg(1); } -static void PrintContestPaintingCaption(u8 contestType, bool8 arg1) +static void PrintContestPaintingCaption(u8 contestType, bool8 noCaption) { int x; u8 category; - if (arg1 == TRUE) + if (noCaption == TRUE) return; category = gContestPaintingWinner->contestCategory; - if (contestType < 8) + if (contestType < MUSEUM_CONTEST_WINNERS_START) { + // Contest Hall caption BufferContestName(gStringVar1, category); StringAppend(gStringVar1, gText_Space); StringAppend(gStringVar1, sContestRankNames[gContestPaintingWinner->contestRank]); StringCopy(gStringVar2, gContestPaintingWinner->trainerName); sub_81DB5AC(gStringVar2); StringCopy(gStringVar3, gContestPaintingWinner->monName); - StringExpandPlaceholders(gStringVar4, gContestPaintingCaption); + StringExpandPlaceholders(gStringVar4, gContestHallPaintingCaption); } else { + // Museum caption StringCopy(gStringVar1, gContestPaintingWinner->monName); - StringExpandPlaceholders(gStringVar4, sContestPaintingDescriptionPointers[category]); + StringExpandPlaceholders(gStringVar4, sMuseumCaptions[category]); } x = GetStringCenterAlignXOffset(1, gStringVar4, 208); - AddTextPrinterParameterized(gContestPaintingWindowId, 1, gStringVar4, x, 1, 0, 0); + AddTextPrinterParameterized(sWindowId, 1, gStringVar4, x, 1, 0, 0); CopyBgTilemapBufferToVram(1); } @@ -321,33 +321,34 @@ static void InitContestPaintingBg(void) SetGpuReg(REG_OFFSET_BLDY, 0); } -static void InitContestPaintingVars(bool8 arg0) +static void InitContestPaintingVars(bool8 reset) { - if (arg0 == FALSE) + if (reset == FALSE) { - gUnknown_030011F6 = FALSE; - gContestPaintingMosaicVal = 0; - gContestPaintingFadeCounter = 0; + // Never reached + sVarsInitialized = FALSE; + sMosaicVal = 0; + sFadeCounter = 0; } else { - gUnknown_030011F6 = TRUE; - gContestPaintingMosaicVal = 15; - gContestPaintingFadeCounter = 30; + sVarsInitialized = TRUE; + sMosaicVal = 15; + sFadeCounter = 30; } } static void UpdateContestPaintingMosaicEffect(void) { - if (!gUnknown_030011F6) + if (!sVarsInitialized) { SetGpuReg(REG_OFFSET_MOSAIC, 0); } else { SetGpuReg(REG_OFFSET_BG1CNT, BGCNT_PRIORITY(1) | BGCNT_CHARBASE(1) | BGCNT_SCREENBASE(10) | BGCNT_MOSAIC | BGCNT_16COLOR | BGCNT_TXT256x256); - gContestPaintingMosaicVal = gContestPaintingFadeCounter / 2; - SetGpuReg(REG_OFFSET_MOSAIC, (gContestPaintingMosaicVal << 12) | (gContestPaintingMosaicVal << 8) | (gContestPaintingMosaicVal << 4) | (gContestPaintingMosaicVal << 0)); + sMosaicVal = sFadeCounter / 2; + SetGpuReg(REG_OFFSET_MOSAIC, (sMosaicVal << 12) | (sMosaicVal << 8) | (sMosaicVal << 4) | (sMosaicVal << 0)); } } @@ -414,34 +415,35 @@ static void _InitContestMonPixels(u8 *spriteGfx, u16 *palette, u16 (*destPixels) #define VRAM_PICTURE_DATA(x, y) (((u16 *)(BG_SCREEN_ADDR(12)))[(y) * 32 + (x)]) -static void LoadContestPaintingFrame(u8 contestWinnerId, bool8 arg1) +static void LoadContestPaintingFrame(u8 contestWinnerId, bool8 isForArtist) { u8 x, y; - LoadPalette(gPictureFramePalettes, 0, 0x100); - if (arg1 == TRUE) + LoadPalette(sPictureFramePalettes, 0, 0x100); + if (isForArtist == TRUE) { - switch (gContestPaintingWinner->contestCategory / 3) + // Load Artist's frame + switch (gContestPaintingWinner->contestCategory / NUM_PAINTING_CAPTIONS) { case CONTEST_CATEGORY_COOL: - RLUnCompVram(gPictureFrameTiles_0, (void *)VRAM); - RLUnCompWram(gPictureFrameTilemap_0, gContestMonPixels); + RLUnCompVram(sPictureFrameTiles_Cool, (void *)VRAM); + RLUnCompWram(sPictureFrameTilemap_Cool, gContestMonPixels); break; case CONTEST_CATEGORY_BEAUTY: - RLUnCompVram(gPictureFrameTiles_1, (void *)VRAM); - RLUnCompWram(gPictureFrameTilemap_1, gContestMonPixels); + RLUnCompVram(sPictureFrameTiles_Beauty, (void *)VRAM); + RLUnCompWram(sPictureFrameTilemap_Beauty, gContestMonPixels); break; case CONTEST_CATEGORY_CUTE: - RLUnCompVram(gPictureFrameTiles_2, (void *)VRAM); - RLUnCompWram(gPictureFrameTilemap_2, gContestMonPixels); + RLUnCompVram(sPictureFrameTiles_Cute, (void *)VRAM); + RLUnCompWram(sPictureFrameTilemap_Cute, gContestMonPixels); break; case CONTEST_CATEGORY_SMART: - RLUnCompVram(gPictureFrameTiles_3, (void *)VRAM); - RLUnCompWram(gPictureFrameTilemap_3, gContestMonPixels); + RLUnCompVram(sPictureFrameTiles_Smart, (void *)VRAM); + RLUnCompWram(sPictureFrameTilemap_Smart, gContestMonPixels); break; case CONTEST_CATEGORY_TOUGH: - RLUnCompVram(gPictureFrameTiles_4, (void *)VRAM); - RLUnCompWram(gPictureFrameTilemap_4, gContestMonPixels); + RLUnCompVram(sPictureFrameTiles_Tough, (void *)VRAM); + RLUnCompWram(sPictureFrameTilemap_Tough, gContestMonPixels); break; } @@ -463,34 +465,36 @@ static void LoadContestPaintingFrame(u8 contestWinnerId, bool8 arg1) for (x = 0; x < 16; x++) VRAM_PICTURE_DATA(x + 7, 2) = (*gContestMonPixels)[2][7]; } - else if (contestWinnerId < 8) + else if (contestWinnerId < MUSEUM_CONTEST_WINNERS_START) { - RLUnCompVram(gPictureFrameTiles_5, (void *)VRAM); - RLUnCompVram(gPictureFrameTilemap_5, (void *)(BG_SCREEN_ADDR(12))); + // Load Contest Hall lobby frame + RLUnCompVram(sPictureFrameTiles_HallLobby, (void *)VRAM); + RLUnCompVram(sPictureFrameTilemap_HallLobby, (void *)(BG_SCREEN_ADDR(12))); } else { - switch (gContestPaintingWinner->contestCategory / 3) + // Load Museum frame + switch (gContestPaintingWinner->contestCategory / NUM_PAINTING_CAPTIONS) { case CONTEST_CATEGORY_COOL: - RLUnCompVram(gPictureFrameTiles_0, (void *)VRAM); - RLUnCompVram(gPictureFrameTilemap_0, (void *)(BG_SCREEN_ADDR(12))); + RLUnCompVram(sPictureFrameTiles_Cool, (void *)VRAM); + RLUnCompVram(sPictureFrameTilemap_Cool, (void *)(BG_SCREEN_ADDR(12))); break; case CONTEST_CATEGORY_BEAUTY: - RLUnCompVram(gPictureFrameTiles_1, (void *)VRAM); - RLUnCompVram(gPictureFrameTilemap_1, (void *)(BG_SCREEN_ADDR(12))); + RLUnCompVram(sPictureFrameTiles_Beauty, (void *)VRAM); + RLUnCompVram(sPictureFrameTilemap_Beauty, (void *)(BG_SCREEN_ADDR(12))); break; case CONTEST_CATEGORY_CUTE: - RLUnCompVram(gPictureFrameTiles_2, (void *)VRAM); - RLUnCompVram(gPictureFrameTilemap_2, (void *)(BG_SCREEN_ADDR(12))); + RLUnCompVram(sPictureFrameTiles_Cute, (void *)VRAM); + RLUnCompVram(sPictureFrameTilemap_Cute, (void *)(BG_SCREEN_ADDR(12))); break; case CONTEST_CATEGORY_SMART: - RLUnCompVram(gPictureFrameTiles_3, (void *)VRAM); - RLUnCompVram(gPictureFrameTilemap_3, (void *)(BG_SCREEN_ADDR(12))); + RLUnCompVram(sPictureFrameTiles_Smart, (void *)VRAM); + RLUnCompVram(sPictureFrameTilemap_Smart, (void *)(BG_SCREEN_ADDR(12))); break; case CONTEST_CATEGORY_TOUGH: - RLUnCompVram(gPictureFrameTiles_4, (void *)VRAM); - RLUnCompVram(gPictureFrameTilemap_4, (void *)(BG_SCREEN_ADDR(12))); + RLUnCompVram(sPictureFrameTiles_Tough, (void *)VRAM); + RLUnCompVram(sPictureFrameTilemap_Tough, (void *)(BG_SCREEN_ADDR(12))); break; } } @@ -519,10 +523,10 @@ static u8 GetImageEffectForContestWinner(u8 contestWinnerId) { u8 contestCategory; - if (contestWinnerId < 8) + if (contestWinnerId < MUSEUM_CONTEST_WINNERS_START) contestCategory = gContestPaintingWinner->contestCategory; else - contestCategory = gContestPaintingWinner->contestCategory / 3; + contestCategory = gContestPaintingWinner->contestCategory / NUM_PAINTING_CAPTIONS; switch (contestCategory) { @@ -584,12 +588,12 @@ static void DoContestPaintingImageProcessing(u8 imageEffect) LoadPalette(gContestPaintingMonPalette, 0x100, 0x200); } -static void CreateContestPaintingPicture(u8 contestWinnerId, bool8 arg1) +static void CreateContestPaintingPicture(u8 contestWinnerId, bool8 isForArtist) { AllocPaintingResources(); InitContestMonPixels(gContestPaintingWinner->species, 0); DoContestPaintingImageProcessing(GetImageEffectForContestWinner(contestWinnerId)); InitPaintingMonOamData(contestWinnerId); - LoadContestPaintingFrame(contestWinnerId, arg1); + LoadContestPaintingFrame(contestWinnerId, isForArtist); } diff --git a/src/contest_util.c b/src/contest_util.c index 700e44606..c490a2f0e 100644 --- a/src/contest_util.c +++ b/src/contest_util.c @@ -606,10 +606,10 @@ static void Task_ShowContestResults(u8 taskId) } TryGainNewFanFromCounter(FANCOUNTER_FINISHED_CONTEST); - sub_80DEDA8(gSpecialVar_ContestRank); - sub_80DEDA8(0xFE); - gUnknown_02039F5C = TRUE; - gUnknown_02039F5D = sub_80DEFA8(0xFE, 0); + SaveContestWinner(gSpecialVar_ContestRank); // Save for lobby painting + SaveContestWinner(CONTEST_SAVE_FOR_ARTIST); + gCurContestWinnerIsForArtist = TRUE; + gCurContestWinnerSaveIdx = GetContestWinnerSaveIdx(CONTEST_SAVE_FOR_ARTIST, FALSE); var = VarGet(VAR_CONTEST_HALL_STATE); VarSet(VAR_CONTEST_HALL_STATE, 0); SetContinueGameWarpStatusToDynamicWarp(); @@ -656,10 +656,10 @@ static void Task_ShowContestResults(u8 taskId) if (gContestFinalStandings[gContestPlayerMonIndex] == 0) IncrementGameStat(GAME_STAT_WON_CONTEST); - sub_80DEDA8(gSpecialVar_ContestRank); - sub_80DEDA8(0xFE); - gUnknown_02039F5C = TRUE; - gUnknown_02039F5D = sub_80DEFA8(0xFE, 0); + SaveContestWinner(gSpecialVar_ContestRank); // Save for lobby painting + SaveContestWinner(CONTEST_SAVE_FOR_ARTIST); + gCurContestWinnerIsForArtist = TRUE; + gCurContestWinnerSaveIdx = GetContestWinnerSaveIdx(CONTEST_SAVE_FOR_ARTIST, FALSE); TryGainNewFanFromCounter(FANCOUNTER_FINISHED_CONTEST); gTasks[taskId].func = Task_AnnouncePreliminaryResults; } @@ -2349,7 +2349,7 @@ void DoesContestCategoryHaveWinner(void) void SaveMuseumContestPainting(void) { - sub_80DEDA8(0xFF); + SaveContestWinner(CONTEST_SAVE_FOR_MUSEUM); } void ShouldReadyContestArtist(void) @@ -2449,15 +2449,15 @@ void sub_80F8970(void) gSpecialVar_0x8006 = r7 + 4; } -static void ExitContestWinnerPainting(void) +static void ExitContestPainting(void) { SetMainCallback2(CB2_ReturnToFieldContinueScriptPlayMapMusic); } -void ShowContestWinnerPainting(void) +void ShowContestPainting(void) { SetMainCallback2(CB2_ContestPainting); - gMain.savedCallback = ExitContestWinnerPainting; + gMain.savedCallback = ExitContestPainting; } void SetLinkContestPlayerGfx(void) diff --git a/src/data/contest_opponents.h b/src/data/contest_opponents.h index 127457bbe..a3d19c36c 100644 --- a/src/data/contest_opponents.h +++ b/src/data/contest_opponents.h @@ -138,7 +138,7 @@ const struct ContestWinner gDefaultContestWinners[] = { - { + [CONTEST_WINNER_HALL_1 - 1] = { .personality = 0, .trainerId = 0xFFFF, .species = SPECIES_ELECTRIKE, @@ -147,7 +147,7 @@ const struct ContestWinner gDefaultContestWinners[] = .trainerName = _("EZRA"), .contestRank = CONTEST_RANK_NORMAL }, - { + [CONTEST_WINNER_HALL_2 - 1] = { .personality = 0, .trainerId = 0xFFFF, .species = SPECIES_TROPIUS, @@ -156,7 +156,7 @@ const struct ContestWinner gDefaultContestWinners[] = .trainerName = _("ALLAN"), .contestRank = CONTEST_RANK_HYPER }, - { + [CONTEST_WINNER_HALL_3 - 1] = { .personality = 0, .trainerId = 0xFFFF, .species = SPECIES_XATU, @@ -165,7 +165,7 @@ const struct ContestWinner gDefaultContestWinners[] = .trainerName = _("JULIET"), .contestRank = CONTEST_RANK_NORMAL }, - { + [CONTEST_WINNER_HALL_4 - 1] = { .personality = 0, .trainerId = 0xFFFF, .species = SPECIES_PLUSLE, @@ -174,7 +174,7 @@ const struct ContestWinner gDefaultContestWinners[] = .trainerName = _("BAILY"), .contestRank = CONTEST_RANK_MASTER }, - { + [CONTEST_WINNER_HALL_5 - 1] = { .personality = 0, .trainerId = 0xFFFF, .species = SPECIES_SHUPPET, @@ -183,7 +183,7 @@ const struct ContestWinner gDefaultContestWinners[] = .trainerName = _("MELANY"), .contestRank = CONTEST_RANK_SUPER }, - { + [CONTEST_WINNER_HALL_6 - 1] = { .personality = 0, .trainerId = 0xFFFF, .species = SPECIES_ZANGOOSE, @@ -192,7 +192,7 @@ const struct ContestWinner gDefaultContestWinners[] = .trainerName = _("HANA"), .contestRank = CONTEST_RANK_HYPER }, - { + [CONTEST_WINNER_HALL_UNUSED - 1] = { .personality = 0, .trainerId = 0xFFFF, .species = SPECIES_LOUDRED, @@ -201,7 +201,7 @@ const struct ContestWinner gDefaultContestWinners[] = .trainerName = _("BRYANT"), .contestRank = CONTEST_RANK_HYPER }, - { + [CONTEST_WINNER_MUSEUM_UNUSED - 1] = { .personality = 0, .trainerId = 0xFFFF, .species = SPECIES_DELCATTY, diff --git a/src/scrcmd.c b/src/scrcmd.c index 7dc02b6a8..0ee20d1c6 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -1466,15 +1466,15 @@ bool8 ScrCmd_hidemonpic(struct ScriptContext *ctx) return TRUE; } -bool8 ScrCmd_showcontestwinner(struct ScriptContext *ctx) +bool8 ScrCmd_showcontestpainting(struct ScriptContext *ctx) { u8 contestWinnerId = ScriptReadByte(ctx); - // Don't save artist's painting yet + // Artist's painting is temporary and already has its data loaded if (contestWinnerId != CONTEST_WINNER_ARTIST) SetContestWinnerForPainting(contestWinnerId); - ShowContestWinnerPainting(); + ShowContestPainting(); ScriptContext1_Stop(); return TRUE; } From bc9fc382547aadfb321c7c55571786d20c5e9663 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 22 Apr 2021 14:30:45 -0400 Subject: [PATCH 04/11] Misc contest cleanup --- data/maps/LilycoveCity/scripts.inc | 2 +- .../LilycoveCity_ContestLobby/scripts.inc | 2 +- .../scripts.inc | 2 +- data/specials.inc | 8 +- include/constants/contest.h | 12 +-- include/contest.h | 8 +- include/contest_util.h | 2 +- include/international_string_util.h | 2 +- src/contest.c | 17 ++-- src/contest_painting.c | 11 ++- src/contest_util.c | 95 +++++++++++-------- src/data/contest_opponents.h | 4 +- src/international_string_util.c | 2 +- src/new_game.c | 8 +- src/trainer_card.c | 4 +- 15 files changed, 95 insertions(+), 84 deletions(-) diff --git a/data/maps/LilycoveCity/scripts.inc b/data/maps/LilycoveCity/scripts.inc index 0c94bce62..d54942386 100644 --- a/data/maps/LilycoveCity/scripts.inc +++ b/data/maps/LilycoveCity/scripts.inc @@ -160,7 +160,7 @@ LilycoveCity_EventScript_MotelSign:: @ 81E2D11 LilycoveCity_EventScript_MuseumSign:: @ 81E2D1A lockall - specialvar VAR_0x8004, CountPlayerContestPaintings + specialvar VAR_0x8004, CountPlayerMuseumPaintings switch VAR_0x8004 case 0, LilycoveCity_EventScript_MuseumSignNoPaintings msgbox LilycoveCity_Text_MuseumSignPlayersExhibit, MSGBOX_DEFAULT diff --git a/data/maps/LilycoveCity_ContestLobby/scripts.inc b/data/maps/LilycoveCity_ContestLobby/scripts.inc index 3642bc1d1..458585ea4 100644 --- a/data/maps/LilycoveCity_ContestLobby/scripts.inc +++ b/data/maps/LilycoveCity_ContestLobby/scripts.inc @@ -108,7 +108,7 @@ LilycoveCity_ContestLobby_EventScript_ReceivedArtistRibbon:: @ 821A314 return LilycoveCity_ContestLobby_EventScript_UpdateMuseumPatrons:: @ 821A360 - specialvar VAR_0x8004, CountPlayerContestPaintings + specialvar VAR_0x8004, CountPlayerMuseumPaintings switch VAR_0x8004 case 1, LilycoveCity_ContestLobby_EventScript_ShowPatron1 case 2, LilycoveCity_ContestLobby_EventScript_ShowPatron2 diff --git a/data/maps/LilycoveCity_LilycoveMuseum_2F/scripts.inc b/data/maps/LilycoveCity_LilycoveMuseum_2F/scripts.inc index c769f4b55..6f51d1cac 100644 --- a/data/maps/LilycoveCity_LilycoveMuseum_2F/scripts.inc +++ b/data/maps/LilycoveCity_LilycoveMuseum_2F/scripts.inc @@ -94,7 +94,7 @@ LilycoveCity_LilycoveMuseum_2F_Movement_FaceExhibitHall: @ 8219863 LilycoveCity_LilycoveMuseum_2F_EventScript_Curator:: @ 8219866 lockall goto_if_set FLAG_RECEIVED_GLASS_ORNAMENT, LilycoveCity_LilycoveMuseum_2F_EventScript_ReceivedGlassOrnament - specialvar VAR_0x8004, CountPlayerContestPaintings + specialvar VAR_0x8004, CountPlayerMuseumPaintings switch VAR_0x8004 case 1, LilycoveCity_LilycoveMuseum_2F_EventScript_AddedPainting case 2, LilycoveCity_LilycoveMuseum_2F_EventScript_AddedPainting diff --git a/data/specials.inc b/data/specials.inc index 4c2a6dc73..34db6f8b9 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -89,14 +89,14 @@ gSpecials:: @ 81DBA64 def_special ResetTVShowState def_special GetContestWinnerId def_special GetContestPlayerId - def_special sub_80F8814 + def_special GetNpcContestantLocalId def_special BufferContestWinnerTrainerName def_special BufferContestWinnerMonName def_special BufferContestTrainerAndMonNames def_special GetContestMonConditionRanking def_special SetContestTrainerGfxIds def_special TryEnterContestMon - def_special sub_80F8970 + def_special GetContestantNamesAtRank def_special SetLinkContestPlayerGfx def_special GetContestMonCondition def_special HasMonWonThisContestBefore @@ -147,8 +147,8 @@ gSpecials:: @ 81DBA64 def_special CountPartyAliveNonEggMons_IgnoreVar0x8004Slot def_special ShouldReadyContestArtist def_special SaveMuseumContestPainting - def_special DoesContestCategoryHaveWinner - def_special CountPlayerContestPaintings + def_special DoesContestCategoryHaveMuseumPainting + def_special CountPlayerMuseumPaintings def_special ShowContestPainting @ Unused, redundant with showcontestpainting command def_special MauvilleGymSetDefaultBarriers def_special MauvilleGymPressSwitch diff --git a/include/constants/contest.h b/include/constants/contest.h index c18af0817..28b02e9c0 100644 --- a/include/constants/contest.h +++ b/include/constants/contest.h @@ -32,8 +32,8 @@ #define CONTEST_WINNER_HALL_5 5 #define CONTEST_WINNER_HALL_6 6 #define NUM_CONTEST_HALL_WINNERS 6 -#define CONTEST_WINNER_HALL_UNUSED 7 -#define CONTEST_WINNER_MUSEUM_UNUSED 8 +#define CONTEST_WINNER_HALL_UNUSED_1 7 // These two have data for gDefaultContestWinners +#define CONTEST_WINNER_HALL_UNUSED_2 8 // but there are only 6 paintings in the Contest Hall #define CONTEST_WINNER_MUSEUM_COOL 9 #define CONTEST_WINNER_MUSEUM_BEAUTY 10 #define CONTEST_WINNER_MUSEUM_CUTE 11 @@ -41,14 +41,14 @@ #define CONTEST_WINNER_MUSEUM_TOUGH 13 // NUM_CONTEST_WINNERS in constants/global.h -#define MUSEUM_CONTEST_WINNERS_START CONTEST_WINNER_MUSEUM_UNUSED - -// The number of possible captions for a Contest painting, per category -#define NUM_PAINTING_CAPTIONS 3 +#define MUSEUM_CONTEST_WINNERS_START (CONTEST_WINNER_MUSEUM_COOL - 1) #define CONTEST_SAVE_FOR_MUSEUM ((u8)-1) #define CONTEST_SAVE_FOR_ARTIST ((u8)-2) +// The number of possible captions for a Contest painting, per category +#define NUM_PAINTING_CAPTIONS 3 + #define CANT_ENTER_CONTEST 0 #define CAN_ENTER_CONTEST_EQUAL_RANK 1 #define CAN_ENTER_CONTEST_HIGH_RANK 2 diff --git a/include/contest.h b/include/contest.h index 6469bf628..9bac63eda 100644 --- a/include/contest.h +++ b/include/contest.h @@ -111,11 +111,11 @@ struct ContestPokemon u32 otId; }; -struct Shared1A004 +struct ContestTempSave { u16 cachedWindowPalettes[16][16]; // Saved palette data before a move happens? - u16 unk18204[PLTT_BUFFER_SIZE]; // Saved copy of gPlttBufferUnfaded - u16 unk18604[PLTT_BUFFER_SIZE]; // Saved copy of gPlttBufferFaded + u16 cachedPlttBufferUnfaded[PLTT_BUFFER_SIZE]; + u16 cachedPlttBufferFaded[PLTT_BUFFER_SIZE]; u8 savedJunk[0x800]; }; @@ -306,7 +306,7 @@ struct ContestResources #define eUnzippedContestAudience_Gfx (gHeap + 0x18000) #define eContestAudienceFrame2_Gfx (gHeap + 0x19000) #define eContestDebugMode (gHeap[0x1a000]) -#define eUnknownHeap1A004 (*(struct Shared1A004 *)(gHeap + 0x1a004)) +#define eContestTempSave (*(struct ContestTempSave *)(gHeap + 0x1a004)) extern struct ContestPokemon gContestMons[CONTESTANT_COUNT]; extern s16 gContestMonRound1Points[CONTESTANT_COUNT]; diff --git a/include/contest_util.h b/include/contest_util.h index 5b0c5559a..1e97d91d3 100644 --- a/include/contest_util.h +++ b/include/contest_util.h @@ -9,6 +9,6 @@ void ShowContestResults(void); void ContestLinkTransfer(u8); void ShowContestPainting(void); u16 GetContestRand(void); -u8 CountPlayerContestPaintings(void); +u8 CountPlayerMuseumPaintings(void); #endif // GUARD_CONTEST_UTIL_H diff --git a/include/international_string_util.h b/include/international_string_util.h index f76fc5be1..fe7e85b41 100644 --- a/include/international_string_util.h +++ b/include/international_string_util.h @@ -17,7 +17,7 @@ void CopyMonCategoryText(int dexNum, u8 *dest); u8 *sub_81DB494(u8 *str, int fontId, const u8 *str2, int totalStringWidth); void PadNameString(u8 *dest, u8 padChar); void ConvertInternationalPlayerNameStripChar(u8 *, u8); -void sub_81DB5AC(u8 *); +void ConvertInternationalContestantName(u8 *); int sub_81DB604(u8 *); void sub_81DB620(int windowId, int columnStart, int rowStart, int numFillTiles, int numRows); diff --git a/src/contest.c b/src/contest.c index 59f50fcfc..7dd420c20 100644 --- a/src/contest.c +++ b/src/contest.c @@ -1034,7 +1034,7 @@ void LoadContestBgAfterMoveAnim(void) { u32 contestantWindowId = 5 + i; - LoadPalette(eUnknownHeap1A004.cachedWindowPalettes[contestantWindowId], 16 * (5 + gContestantTurnOrder[i]), sizeof((eUnknownHeap1A004.cachedWindowPalettes[contestantWindowId]))); + LoadPalette(eContestTempSave.cachedWindowPalettes[contestantWindowId], 16 * (5 + gContestantTurnOrder[i]), sizeof((eContestTempSave.cachedWindowPalettes[contestantWindowId]))); } } @@ -1320,7 +1320,7 @@ static bool8 SetupContestGraphics(u8 *stateVar) CopyToBgTilemapBuffer(2, gUnknown_08C17170, 0, 0); CopyBgTilemapBufferToVram(2); // This is a bug, and copies random junk. savedJunk is never read. - DmaCopy32Defvars(3, gContestResources->contestBgTilemaps[2], eUnknownHeap1A004.savedJunk, sizeof(eUnknownHeap1A004.savedJunk)); + DmaCopy32Defvars(3, gContestResources->contestBgTilemaps[2], eContestTempSave.savedJunk, sizeof(eContestTempSave.savedJunk)); break; case 5: LoadCompressedPalette(gOldContestPalette, 0, 0x200); @@ -1328,7 +1328,7 @@ static bool8 SetupContestGraphics(u8 *stateVar) CpuCopy32(gPlttBufferUnfaded + (5 + gContestPlayerMonIndex) * 16, tempPalette2, 16 * sizeof(u16)); CpuCopy32(tempPalette2, gPlttBufferUnfaded + 128, 16 * sizeof(u16)); CpuCopy32(tempPalette1, gPlttBufferUnfaded + (5 + gContestPlayerMonIndex) * 16, 16 * sizeof(u16)); - DmaCopy32Defvars(3, gPlttBufferUnfaded, eUnknownHeap1A004.cachedWindowPalettes, sizeof(eUnknownHeap1A004.cachedWindowPalettes)); + DmaCopy32Defvars(3, gPlttBufferUnfaded, eContestTempSave.cachedWindowPalettes, sizeof(eContestTempSave.cachedWindowPalettes)); LoadContestPalettes(); break; case 6: @@ -1468,7 +1468,7 @@ static void Task_DisplayAppealNumberText(u8 taskId) gBattle_BG0_Y = 0; gBattle_BG2_Y = 0; ContestDebugDoPrint(); - DmaCopy32Defvars(3, gPlttBufferUnfaded, eUnknownHeap1A004.unk18204, PLTT_BUFFER_SIZE * 2); + DmaCopy32Defvars(3, gPlttBufferUnfaded, eContestTempSave.cachedPlttBufferUnfaded, PLTT_BUFFER_SIZE * 2); ConvertIntToDecimalStringN(gStringVar1, eContest.appealNumber + 1, STR_CONV_MODE_LEFT_ALIGN, 1); if (!Contest_IsMonsTurnDisabled(gContestPlayerMonIndex)) StringCopy(gDisplayedStringBattle, gText_AppealNumWhichMoveWillBePlayed); @@ -1667,8 +1667,8 @@ static void Task_HideMoveSelectScreen(u8 taskId) } Contest_SetBgCopyFlags(0); // This seems to be a bug; it should have just copied PLTT_BUFFER_SIZE. - DmaCopy32Defvars(3, gPlttBufferFaded, eUnknownHeap1A004.unk18604, PLTT_BUFFER_SIZE * 2); - LoadPalette(eUnknownHeap1A004.unk18204, 0, PLTT_BUFFER_SIZE * 2); + DmaCopy32Defvars(3, gPlttBufferFaded, eContestTempSave.cachedPlttBufferFaded, PLTT_BUFFER_SIZE * 2); + LoadPalette(eContestTempSave.cachedPlttBufferUnfaded, 0, PLTT_BUFFER_SIZE * 2); gTasks[taskId].data[0] = 0; gTasks[taskId].data[1] = 0; gTasks[taskId].func = Task_HideApplauseMeterForAppealStart; @@ -2554,7 +2554,7 @@ static void Task_WaitForHeartSliders(u8 taskId) static void sub_80DA348(u8 taskId) { - DmaCopy32Defvars(3, eUnknownHeap1A004.unk18204, gPlttBufferUnfaded, PLTT_BUFFER_SIZE * 2); + DmaCopy32Defvars(3, eContestTempSave.cachedPlttBufferUnfaded, gPlttBufferUnfaded, PLTT_BUFFER_SIZE * 2); gTasks[taskId].data[0] = 0; gTasks[taskId].data[1] = 2; gTasks[taskId].func = Task_WaitPrintRoundResult; @@ -4412,7 +4412,7 @@ static void DrawContestantWindows(void) for (i = 0; i < CONTESTANT_COUNT; i++) { s32 windowId = i + 5; - LoadPalette(eUnknownHeap1A004.cachedWindowPalettes[windowId], (gContestantTurnOrder[i] + 5) * 16, sizeof(eUnknownHeap1A004.cachedWindowPalettes[0])); + LoadPalette(eContestTempSave.cachedWindowPalettes[windowId], (gContestantTurnOrder[i] + 5) * 16, sizeof(eContestTempSave.cachedWindowPalettes[0])); } DrawContestantWindowText(); } @@ -5530,7 +5530,6 @@ bool8 SaveContestWinner(u8 rank) if (rank == CONTEST_SAVE_FOR_MUSEUM && i != gContestPlayerMonIndex) return FALSE; - // Adjust the random painting caption depending on the category switch (gSpecialVar_ContestCategory) { diff --git a/src/contest_painting.c b/src/contest_painting.c index ca5d8c0a9..d4bc8ca04 100644 --- a/src/contest_painting.c +++ b/src/contest_painting.c @@ -159,7 +159,7 @@ static const struct OamData sContestPaintingMonOamData = .paletteNum = 0, }; -static const u16 sBg_Palette[] = {RGB_BLACK, RGB_BLACK}; +static const u16 sBgPalette[] = {RGB_BLACK, RGB_BLACK}; void SetContestWinnerForPainting(int contestWinnerId) { @@ -223,7 +223,7 @@ static void ShowContestPainting(void) break; case 4: PrintContestPaintingCaption(gCurContestWinnerSaveIdx, gCurContestWinnerIsForArtist); - LoadPalette(sBg_Palette, 0, 1 * 2); + LoadPalette(sBgPalette, 0, 1 * 2); DmaClear32(3, PLTT, PLTT_SIZE); BeginFastPaletteFade(2); SetVBlankCallback(VBlankCB_ContestPainting); @@ -278,12 +278,13 @@ static void InitContestPaintingWindow(void) ShowBg(1); } -static void PrintContestPaintingCaption(u8 contestType, bool8 noCaption) +static void PrintContestPaintingCaption(u8 contestType, bool8 isForArtist) { int x; u8 category; - if (noCaption == TRUE) + // Artist's painting has no caption + if (isForArtist == TRUE) return; category = gContestPaintingWinner->contestCategory; @@ -294,7 +295,7 @@ static void PrintContestPaintingCaption(u8 contestType, bool8 noCaption) StringAppend(gStringVar1, gText_Space); StringAppend(gStringVar1, sContestRankNames[gContestPaintingWinner->contestRank]); StringCopy(gStringVar2, gContestPaintingWinner->trainerName); - sub_81DB5AC(gStringVar2); + ConvertInternationalContestantName(gStringVar2); StringCopy(gStringVar3, gContestPaintingWinner->monName); StringExpandPlaceholders(gStringVar4, gContestHallPaintingCaption); } diff --git a/src/contest_util.c b/src/contest_util.c index c490a2f0e..167f49876 100644 --- a/src/contest_util.c +++ b/src/contest_util.c @@ -856,7 +856,7 @@ static void Task_AnnounceWinner(u8 taskId) gTasks[taskId].tTimer = 0; GET_CONTEST_WINNER_ID(i); StringCopy(gStringVar1, gContestMons[i].trainerName); - sub_81DB5AC(gStringVar1); + ConvertInternationalContestantName(gStringVar1); StringCopy(gStringVar2, gContestMons[i].nickname); StringExpandPlaceholders(winnerTextBuffer, gText_ContestantsMonWon); x = DrawResultsTextWindow(winnerTextBuffer, sContestResults->data->slidingTextBoxSpriteId); @@ -2057,7 +2057,7 @@ void GiveMonContestRibbon(void) void BufferContestantTrainerName(void) { StringCopy(gStringVar1, gContestMons[gSpecialVar_0x8006].trainerName); - sub_81DB5AC(gStringVar1); + ConvertInternationalContestantName(gStringVar1); } void BufferContestantMonNickname(void) @@ -2096,7 +2096,7 @@ void BufferContestWinnerTrainerName(void) u8 i; GET_CONTEST_WINNER_ID(i); StringCopy(gStringVar3, gContestMons[i].trainerName); - sub_81DB5AC(gStringVar3); + ConvertInternationalContestantName(gStringVar3); } void BufferContestWinnerMonName(void) @@ -2279,6 +2279,10 @@ static void Task_LinkContest_WaitDisconnect(u8 taskId) } } +/* + A section of contest script functions starts here +*/ + void SetContestTrainerGfxIds(void) { gSaveBlock1Ptr->vars[VAR_OBJ_GFX_ID_0 - VARS_START] = gContestMons[0].trainerGfxId; @@ -2287,27 +2291,27 @@ void SetContestTrainerGfxIds(void) } // Unused -void sub_80F8814(void) +void GetNpcContestantLocalId(void) { - u16 var1; - u8 var0 = gSpecialVar_0x8005; - switch (var0) + u16 localId; + u8 contestant = gSpecialVar_0x8005; + switch (contestant) { case 0: - var1 = 3; + localId = 3; break; case 1: - var1 = 4; + localId = 4; break; case 2: - var1 = 5; + localId = 5; break; - default: - var1 = 100; + default: // Invalid + localId = 100; break; } - gSpecialVar_0x8004 = var1; + gSpecialVar_0x8004 = localId; } void BufferContestTrainerAndMonNames(void) @@ -2318,26 +2322,26 @@ void BufferContestTrainerAndMonNames(void) } // Unused -void DoesContestCategoryHaveWinner(void) +void DoesContestCategoryHaveMuseumPainting(void) { int contestWinner; switch (gSpecialVar_ContestCategory) { case CONTEST_CATEGORY_COOL: - contestWinner = 8; + contestWinner = CONTEST_WINNER_MUSEUM_COOL - 1; break; case CONTEST_CATEGORY_BEAUTY: - contestWinner = 9; + contestWinner = CONTEST_WINNER_MUSEUM_BEAUTY - 1; break; case CONTEST_CATEGORY_CUTE: - contestWinner = 10; + contestWinner = CONTEST_WINNER_MUSEUM_CUTE - 1; break; case CONTEST_CATEGORY_SMART: - contestWinner = 11; + contestWinner = CONTEST_WINNER_MUSEUM_SMART - 1; break; case CONTEST_CATEGORY_TOUGH: default: - contestWinner = 12; + contestWinner = CONTEST_WINNER_MUSEUM_TOUGH - 1; break; } @@ -2366,14 +2370,14 @@ void ShouldReadyContestArtist(void) } } -u8 CountPlayerContestPaintings(void) +u8 CountPlayerMuseumPaintings(void) { int i; u8 count = 0; - for (i = 0; i < 5; i++) + for (i = 0; i < NUM_CONTEST_WINNERS - MUSEUM_CONTEST_WINNERS_START; i++) { - if (gSaveBlock1Ptr->contestWinners[8 + i].species) + if (gSaveBlock1Ptr->contestWinners[MUSEUM_CONTEST_WINNERS_START + i].species) count++; } @@ -2381,19 +2385,21 @@ u8 CountPlayerContestPaintings(void) } // Unused -void sub_80F8970(void) +void GetContestantNamesAtRank(void) { s16 conditions[CONTESTANT_COUNT]; int i, j; s16 condition; - s8 var0; - u8 var2; - u8 r8; - u8 r7; + s8 numAtCondition; + u8 contestantOffset; + u8 tieRank; + u8 rank; + // Get round 1 points for (i = 0; i < CONTESTANT_COUNT; i++) conditions[i] = gContestMonRound1Points[i]; + // Sort round 1 points for (i = 0; i < CONTESTANT_COUNT - 1; i++) { for (j = CONTESTANT_COUNT - 1; j > i; j--) @@ -2406,47 +2412,54 @@ void sub_80F8970(void) } } + // Get round 1 points at specified rank condition = conditions[gSpecialVar_0x8006]; - var0 = 0; - r8 = 0; + + // Count number of contestants with the same number of points + numAtCondition = 0; + tieRank = 0; for (i = 0; i < CONTESTANT_COUNT; i++) { if (conditions[i] == condition) { - var0++; + numAtCondition++; if (i == gSpecialVar_0x8006) - r8 = var0; + tieRank = numAtCondition; } } + // Get rank of first contestant with the same number of points for (i = 0; i < CONTESTANT_COUNT; i++) { if (conditions[i] == condition) break; } + rank = i; - r7 = i; - var2 = r8; + // Get contestant id of player at rank (taking ties into account) + contestantOffset = tieRank; for (i = 0; i < CONTESTANT_COUNT; i++) { if (condition == gContestMonRound1Points[i]) { - if (var2 == 1) + if (contestantOffset == 1) break; - var2--; + contestantOffset--; } } + // Use contestant id to get names StringCopy(gStringVar1, gContestMons[i].nickname); StringCopy(gStringVar2, gContestMons[i].trainerName); - sub_81DB5AC(gStringVar2); + ConvertInternationalContestantName(gStringVar2); - if (var0 == 1) - gSpecialVar_0x8006 = r7; - else if (r8 == var0) - gSpecialVar_0x8006 = r7; + // Return adjusted rank + if (numAtCondition == 1) + gSpecialVar_0x8006 = rank; + else if (tieRank == numAtCondition) + gSpecialVar_0x8006 = rank; else - gSpecialVar_0x8006 = r7 + 4; + gSpecialVar_0x8006 = rank + CONTESTANT_COUNT; } static void ExitContestPainting(void) diff --git a/src/data/contest_opponents.h b/src/data/contest_opponents.h index a3d19c36c..b5466904b 100644 --- a/src/data/contest_opponents.h +++ b/src/data/contest_opponents.h @@ -192,7 +192,7 @@ const struct ContestWinner gDefaultContestWinners[] = .trainerName = _("HANA"), .contestRank = CONTEST_RANK_HYPER }, - [CONTEST_WINNER_HALL_UNUSED - 1] = { + [CONTEST_WINNER_HALL_UNUSED_1 - 1] = { .personality = 0, .trainerId = 0xFFFF, .species = SPECIES_LOUDRED, @@ -201,7 +201,7 @@ const struct ContestWinner gDefaultContestWinners[] = .trainerName = _("BRYANT"), .contestRank = CONTEST_RANK_HYPER }, - [CONTEST_WINNER_MUSEUM_UNUSED - 1] = { + [CONTEST_WINNER_HALL_UNUSED_2 - 1] = { .personality = 0, .trainerId = 0xFFFF, .species = SPECIES_DELCATTY, diff --git a/src/international_string_util.c b/src/international_string_util.c index ed1e17816..ab812de89 100644 --- a/src/international_string_util.c +++ b/src/international_string_util.c @@ -185,7 +185,7 @@ void ConvertInternationalPlayerNameStripChar(u8 *str, u8 removeChar) } } -void sub_81DB5AC(u8 *str) +void ConvertInternationalContestantName(u8 *str) { if (*str++ == EXT_CTRL_CODE_BEGIN && *str++ == EXT_CTRL_CODE_JPN) { diff --git a/src/new_game.c b/src/new_game.c index 05d86aa8c..2a950efbc 100644 --- a/src/new_game.c +++ b/src/new_game.c @@ -48,23 +48,19 @@ extern const u8 EventScript_ResetAllMapFlags[]; -// this file's functions static void ClearFrontierRecord(void); static void WarpToTruck(void); static void ResetMiniGamesRecords(void); -// EWRAM vars EWRAM_DATA bool8 gDifferentSaveFile = FALSE; EWRAM_DATA bool8 gEnableContestDebugging = FALSE; -// const rom data static const struct ContestWinner sContestWinnerPicDummy = { .monName = _(""), .trainerName = _("") }; -// code void SetTrainerId(u32 trainerId, u8 *dst) { dst[0] = trainerId; @@ -114,7 +110,9 @@ void ClearAllContestWinnerPics(void) s32 i; ClearContestWinnerPicsInContestHall(); - for (i = 8; i < 13; i++) + + // Clear Museum paintings + for (i = MUSEUM_CONTEST_WINNERS_START; i < NUM_CONTEST_WINNERS; i++) gSaveBlock1Ptr->contestWinners[i] = sContestWinnerPicDummy; } diff --git a/src/trainer_card.c b/src/trainer_card.c index 03a7b9219..1ec519c90 100755 --- a/src/trainer_card.c +++ b/src/trainer_card.c @@ -661,7 +661,7 @@ u32 CountPlayerTrainerStars(void) stars++; if (HasAllHoennMons()) stars++; - if (CountPlayerContestPaintings() > 4) + if (CountPlayerMuseumPaintings() >= CONTEST_CATEGORIES_COUNT) stars++; if (HasAllFrontierSymbols()) stars++; @@ -735,7 +735,7 @@ static void SetPlayerCardData(struct TrainerCard *trainerCard, u8 cardType) case CARD_TYPE_FRLG: trainerCard->contestsWithFriends = GetCappedGameStat(GAME_STAT_WON_LINK_CONTEST, 999); trainerCard->pokeblocksWithFriends = GetCappedGameStat(GAME_STAT_POKEBLOCKS_WITH_FRIENDS, 0xFFFF); - if (CountPlayerContestPaintings() > 4) + if (CountPlayerMuseumPaintings() >= CONTEST_CATEGORIES_COUNT) trainerCard->hasAllPaintings = TRUE; trainerCard->stars = GetRubyTrainerStars(trainerCard); break; From 8c820878bfa91e7a00953e02a5e93847c5428468 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 22 Apr 2021 18:49:54 -0400 Subject: [PATCH 05/11] Document Battle Pyramid Bag --- include/battle_pyramid_bag.h | 54 +- include/menu.h | 4 +- include/menu_helpers.h | 2 +- include/strings.h | 3 +- src/battle_pyramid_bag.c | 978 ++++++++++++++++++----------------- src/item.c | 2 +- src/item_menu.c | 15 +- src/item_use.c | 18 +- src/menu.c | 19 +- src/menu_helpers.c | 2 +- src/party_menu.c | 4 +- src/script_menu.c | 2 +- src/strings.c | 13 +- 13 files changed, 595 insertions(+), 521 deletions(-) diff --git a/include/battle_pyramid_bag.h b/include/battle_pyramid_bag.h index df111b939..de571714c 100644 --- a/include/battle_pyramid_bag.h +++ b/include/battle_pyramid_bag.h @@ -3,48 +3,72 @@ #include "list_menu.h" -struct PyramidBagResources +enum { + PYRAMIDBAG_LOC_FIELD, + PYRAMIDBAG_LOC_BATTLE, + PYRAMIDBAG_LOC_PARTY, + PYRAMIDBAG_LOC_CHOOSE_TOSS, + PYRAMIDBAG_LOC_PREV, +}; + +enum { + PBAG_SPRITE_BAG, + PBAG_SPRITE_ITEM_ICON, + PBAG_SPRITE_ITEM_ICON_ALT, + PBAG_SPRITE_SWAP_LINE_START, // Swap line consists of 8 sprites + PBAG_SPRITE_SWAP_LINE_2, + PBAG_SPRITE_SWAP_LINE_3, + PBAG_SPRITE_SWAP_LINE_4, + PBAG_SPRITE_SWAP_LINE_5, + PBAG_SPRITE_SWAP_LINE_6, + PBAG_SPRITE_SWAP_LINE_7, + PBAG_SPRITE_SWAP_LINE_END, + PBAG_SPRITE_COUNT +}; +#define NUM_SWAP_LINE_SPRITES (1 + PBAG_SPRITE_SWAP_LINE_END - PBAG_SPRITE_SWAP_LINE_START) + +struct PyramidBagMenu { - void (*callback2)(void); - u8 tilemapBuffer[0x800]; - u8 itemsSpriteIds[PYRAMID_BAG_ITEMS_COUNT + 1]; + void (*exitCallback)(void); + u8 tilemapBuffer[BG_SCREEN_SIZE]; + u8 spriteIds[PBAG_SPRITE_COUNT]; u8 windowIds[5]; - u8 unk814; - u8 unk815; + u8 toSwapPos; + bool8 isAltIcon; // Two item icons loaded at a time. Tracks which to show next u8 scrollIndicatorsTaskId; const u8 *menuActionIds; - u8 filler81C[0x820 - 0x81C]; + u8 unused1[4]; u8 menuActionsCount; u8 listMenuCount; u8 listMenuMaxShown; struct ListMenuItem bagListItems[PYRAMID_BAG_ITEMS_COUNT + 1]; u8 itemStrings[PYRAMID_BAG_ITEMS_COUNT + 1][ITEM_NAME_LENGTH + 10]; s16 state; - u8 filler986[0x98C - 0x986]; + u8 unused2[4]; }; -struct PyramidBagCursorData +struct PyramidBagMenuState { void (*callback)(void); - u8 unk4; + u8 location; u16 cursorPosition; u16 scrollPosition; }; -extern struct PyramidBagResources *gPyramidBagResources; -extern struct PyramidBagCursorData gPyramidBagCursorData; +extern struct PyramidBagMenu *gPyramidBagMenu; +extern struct PyramidBagMenuState gPyramidBagMenuState; void InitBattlePyramidBagCursorPosition(void); void CB2_PyramidBagMenuFromStartMenu(void); void CB2_ReturnToPyramidBagMenu(void); -void sub_81C5924(void); -void sub_81C59BC(void); +void UpdatePyramidBagList(void); +void UpdatePyramidBagCursorPos(void); void sub_81C4EFC(void); void GoToBattlePyramidBagMenu(u8 a0, void (*callback)(void)); void Task_CloseBattlePyramidBagMessage(u8 taskId); void TryStoreHeldItemsInPyramidBag(void); void ChooseItemsToTossFromPyramidBag(void); -void CloseBattlePyramidBagAndSetCallback(u8 taskId); +void CloseBattlePyramidBag(u8 taskId); void DisplayItemMessageInBattlePyramid(u8 taskId, const u8 *str, void (*callback)(u8 taskId)); #endif // GUARD_BATTLE_PYRAMID_BAG_H diff --git a/include/menu.h b/include/menu.h index c9d8e374d..07e00eb73 100644 --- a/include/menu.h +++ b/include/menu.h @@ -90,8 +90,8 @@ void *malloc_and_decompress(const void *src, u32 *sizeOut); u16 copy_decompressed_tile_data_to_vram(u8 bgId, const void *src, u16 size, u16 offset, u8 mode); void AddTextPrinterForMessage(bool8 allowSkippingDelayWithButtonPress); void AddItemMenuActionTextPrinters(u8 windowId, u8 fontId, u8 left, u8 top, u8 letterSpacing, u8 lineHeight, u8 itemCount, const struct MenuAction *strs, const u8 *a8); -void sub_8198DBC(u8 windowId, u8 fontId, u8 left, u8 top, u8 a4, u8 itemCount, u8 itemCount2, const struct MenuAction *strs, const u8 *a8); -u8 sub_8199944(u8 windowId, u8 optionWidth, u8 columns, u8 rows, u8 initialCursorPos); +void PrintMenuActionGrid(u8 windowId, u8 fontId, u8 left, u8 top, u8 a4, u8 itemCount, u8 itemCount2, const struct MenuAction *strs, const u8 *a8); +u8 InitMenuActionGrid(u8 windowId, u8 optionWidth, u8 columns, u8 rows, u8 initialCursorPos); u8 ChangeListMenuCursorPosition(s8 deltaX, s8 deltaY); u8 GetStartMenuWindowId(void); void ListMenuLoadStdPalAt(u8, u8); diff --git a/include/menu_helpers.h b/include/menu_helpers.h index c4401354b..9909437a2 100644 --- a/include/menu_helpers.h +++ b/include/menu_helpers.h @@ -29,7 +29,7 @@ bool8 AdjustQuantityAccordingToDPadInput(s16 *arg0, u16 arg1); u8 GetLRKeysPressed(void); u8 GetLRKeysPressedAndHeld(void); bool8 sub_8122148(u16 itemId); -bool8 itemid_80BF6D8_mail_related(u16 itemId); +bool8 IsWritingMailAllowed(u16 itemId); bool8 MenuHelpers_LinkSomething(void); bool8 MenuHelpers_CallLinkSomething(void); void sub_812220C(struct ItemSlot *slots, u8 count, u8 *arg2, u8 *usedSlotsCount, u8 maxUsedSlotsCount); diff --git a/include/strings.h b/include/strings.h index 8880f3a5c..04283db0e 100644 --- a/include/strings.h +++ b/include/strings.h @@ -982,7 +982,8 @@ extern const u8 gText_RibbonsVar1[]; extern const u8 gText_OneDash[]; extern const u8 gText_TwoDashes[]; -extern const u8 *const gReturnToXStringsTable2[]; +extern const u8 *const gBagMenu_ReturnToStrings[]; +extern const u8 *const gPyramidBagMenu_ReturnToStrings[]; extern const u8 gText_NumPlayerLink[]; extern const u8 gText_ConfirmLinkWhenPlayersReady[]; diff --git a/src/battle_pyramid_bag.c b/src/battle_pyramid_bag.c index 23f2f9653..0b13512ec 100644 --- a/src/battle_pyramid_bag.c +++ b/src/battle_pyramid_bag.c @@ -34,71 +34,83 @@ #include "constants/rgb.h" #include "constants/songs.h" -EWRAM_DATA struct PyramidBagResources *gPyramidBagResources = NULL; -EWRAM_DATA struct PyramidBagCursorData gPyramidBagCursorData = {0}; +#define TAG_SCROLL_ARROW 2910 +#define TAG_PYRAMID_BAG 4132 +#define TAG_ITEM_ICON 4133 +#define TAG_ITEM_ICON_ALT 4134 -// This file's functions. -static void Task_HandlePyramidBagInput(u8 taskId); -static void Task_ChooseItemsToTossFromPyramidBag(u8 taskId); -static void sub_81C5B4C(u8 taskId); -static void Task_BeginItemSwap(u8 taskId); -static void sub_81C5D20(u8 taskId); -static void sub_81C674C(u8 taskId); -static void HandleMenuActionInput(u8 taskId); -static void HandleFewMenuActionsInput(u8 taskId); -static void sub_81C66EC(u8 taskId); -static void SetTaskToMainPyramidBagInputHandler(u8 taskId); -static void sub_81C6350(u8 taskId); -static void sub_81C64B4(u8 taskId); -static void sub_81C65CC(u8 taskId); -static void sub_81C66AC(u8 taskId); -static void PerformItemSwap(u8 taskId); -static void Task_ItemSwapHandleInput(u8 taskId); -static void sub_81C6A14(u8 taskId); +#define POS_NONE ((u8)-1) + +enum { + WIN_LIST, + WIN_INFO, + WIN_MSG, + WIN_TOSS_NUM, +}; + +EWRAM_DATA struct PyramidBagMenu *gPyramidBagMenu = NULL; +EWRAM_DATA struct PyramidBagMenuState gPyramidBagMenuState = {0}; + +static void Task_HandlePyramidBagInput(u8); +static void Task_ChooseItemsToTossFromPyramidBag(u8); +static void Task_ClosePyramidBag(u8); +static void Task_BeginItemSwap(u8); +static void OpenContextMenu(u8); +static void TryCloseBagToGiveItem(u8); +static void HandleMenuActionInput_2x2(u8); +static void HandleMenuActionInput_SingleRow(u8); +static void Task_WaitCloseErrorMessage(u8); +static void SetTaskToMainPyramidBagInputHandler(u8); +static void AskConfirmToss(u8); +static void Task_ChooseHowManyToToss(u8); +static void Task_TossItem(u8); +static void ShowCantHoldMessage(u8); +static void PerformItemSwap(u8); +static void Task_ItemSwapHandleInput(u8); +static void CancelItemSwap(u8); static void SetBagItemsListTemplate(void); -static void sub_81C504C(void); -static void sub_81C51DC(void); -static void AddScrollArrow(void); -static void sub_81C56F8(void); -static void sub_81C5A20(void); -static void sub_81C6BD8(void); -static void sub_81C6EF4(void); +static void CB2_LoadPyramidBagMenu(void); +static void InitPyramidBagBgs(void); +static void AddScrollArrows(void); +static void CreatePyramidBagInputTask(void); +static void InitPyramidBagScroll(void); +static void InitPyramidBagWindows(void); +static void CreatePyramidBagSprite(void); static void CreateSwapLine(void); -static void sub_81C6E98(void); -static void sub_81C6F20(void); -static void sub_81C6404(void); +static void LoadPyramidBagPalette(void); +static void ShakePyramidBag(void); +static void ShowNumToToss(void); static void CloseBattlePyramidBagTextWindow(void); -static bool8 sub_81C5238(void); -static bool8 sub_81C5078(void); -static void ShowItemImage(u16 itemId, u8 itemSpriteArrayId); -static void PyramidBag_CopyItemName(u8 *dst, u16 itemId); -static void sub_81C6FF8(u8 arg0); -static void PrintItemDescription(s32 listMenuId); -static void sub_81C5AB8(u8 y, u8 arg1); -static void PrintOnWindow_Font1(u8 windowId, const u8 *src, u8 x, u8 y, u8 letterSpacing, u8 lineSpacing, u8 speed, u8 colorTableId); -static void PrintOnWindow_Font7(u8 windowId, const u8 *src, u8 x, u8 y, u8 letterSpacing, u8 lineSpacing, u8 speed, u8 colorTableId); -static u8 sub_81C6D24(u8 windowArrayId); -static void sub_81C6D6C(u8 windowArrayId); -static void sub_81C5EAC(u8 windowId); -static void sub_81C5F08(u8 windowId, u8 horizontalCount, u8 verticalCount); -static bool8 IsValidMenuAction(s8 arg0); -static void sub_81C6DAC(u8 taskId, const struct YesNoFuncTable *yesNoTable); -static void sub_81C6CEC(u8 windowId); -static void UpdateSwapLinePos(u8 y); -static void SetSwapLineInvisibility(bool8 invisible); -static void sub_81C6F68(struct Sprite *sprite); -static void BagAction_UseOnField(u8 taskId); -static void BagAction_Toss(u8 taskId); -static void BagAction_Give(u8 taskId); -static void BagAction_Cancel(u8 taskId); -static void BagAction_UseInBattle(u8 taskId); -static void PyramidBagMoveCursorFunc(s32 itemIndex, bool8 onInit, struct ListMenu *list); -static void PrintItemQuantity(u8 windowId, s32 itemIndex, u8 y); -static void TossItem(u8 taskId); -static void DontTossItem(u8 taskId); +static bool8 LoadPyramidBagGfx(void); +static bool8 LoadPyramidBagMenu(void); +static void ShowItemIcon(u16, u8); +static void CopyBagItemName(u8 *, u16); +static void FreeItemIconSpriteByAltId(u8); +static void PrintItemDescription(s32); +static void PrintSelectorArrowAtPos(u8, u8); +static void PrintOnWindow_Font1(u8, const u8 *, u8, u8, u8, u8, u8, u8); +static void PrintOnWindow_Font7(u8, const u8 *, u8, u8, u8, u8, u8, u8); +static u8 OpenMenuActionWindowById(u8); +static void CloseMenuActionWindowById(u8); +static void PrintMenuActionText_SingleRow(u8); +static void PrintMenuActionText_MultiRow(u8, u8, u8); +static bool8 IsValidMenuAction(s8); +static void CreatePyramidBagYesNo(u8, const struct YesNoFuncTable *); +static void DrawTossNumberWindow(u8); +static void UpdateSwapLinePos(u8); +static void SetSwapLineInvisibility(bool8); +static void SpriteCB_BagWaitForShake(struct Sprite *); +static void BagAction_UseOnField(u8); +static void BagAction_Toss(u8); +static void BagAction_Give(u8); +static void BagAction_Cancel(u8); +static void BagAction_UseInBattle(u8); +static void BagCursorMoved(s32, bool8, struct ListMenu *); +static void PrintItemQuantity(u8, s32, u8); +static void TossItem(u8); +static void DontTossItem(u8); -// Const rom data. -static const struct BgTemplate gUnknown_0861F2B4[] = +static const struct BgTemplate sBgTemplates[] = { { .bg = 0, @@ -129,14 +141,14 @@ static const struct BgTemplate gUnknown_0861F2B4[] = }, }; -static const struct ListMenuTemplate gUnknown_0861F2C0 = +static const struct ListMenuTemplate sListMenuTemplate = { .items = NULL, - .moveCursorFunc = PyramidBagMoveCursorFunc, + .moveCursorFunc = BagCursorMoved, .itemPrintFunc = PrintItemQuantity, .totalItems = 0, .maxShowed = 0, - .windowId = 0, + .windowId = WIN_LIST, .header_X = 0, .item_X = 8, .cursor_X = 0, @@ -151,12 +163,14 @@ static const struct ListMenuTemplate gUnknown_0861F2C0 = .cursorKind = 0 }; -#define ACTION_USE_FIELD 0 -#define ACTION_TOSS 1 -#define ACTION_GIVE 2 -#define ACTION_CANCEL 3 -#define ACTION_USE_BATTLE 4 -#define ACTION_DUMMY 5 +enum { + ACTION_USE_FIELD, + ACTION_TOSS, + ACTION_GIVE, + ACTION_CANCEL, + ACTION_USE_BATTLE, + ACTION_DUMMY, +}; static const struct MenuAction sMenuActions[] = { @@ -168,26 +182,33 @@ static const struct MenuAction sMenuActions[] = [ACTION_DUMMY] = { gText_EmptyString2, NULL }, }; -static const u8 sFieldMenuActionIds[] = {ACTION_USE_FIELD, ACTION_GIVE, ACTION_TOSS, ACTION_CANCEL}; -static const u8 gUnknown_0861F30C[] = {ACTION_TOSS, ACTION_CANCEL}; -static const u8 sBattleMenuActionIds[] = {ACTION_USE_BATTLE, ACTION_CANCEL}; -static const u8 gUnknown_0861F310[] = {ACTION_CANCEL}; +static const u8 sMenuActionIds_Field[] = {ACTION_USE_FIELD, ACTION_GIVE, ACTION_TOSS, ACTION_CANCEL}; +static const u8 sMenuActionIds_ChooseToss[] = {ACTION_TOSS, ACTION_CANCEL}; +static const u8 sMenuActionIds_Battle[] = {ACTION_USE_BATTLE, ACTION_CANCEL}; +static const u8 sMenuActionIds_BattleCannotUse[] = {ACTION_CANCEL}; static const struct YesNoFuncTable sYesNoTossFuncions = { TossItem, DontTossItem }; -static const u8 sColorTable[][3] = -{ - {0, 2, 3}, - {0, 3, 1}, - {1, 2, 3}, +enum { + COLORID_DARK_GRAY, + COLORID_LIGHT_GRAY, + COLORID_WHITE_BG, + COLORID_NONE = 0xFF }; -static const struct WindowTemplate gUnknown_0861F328[] = +static const u8 sTextColors[][3] = { - { + [COLORID_DARK_GRAY] = {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_DARK_GRAY, TEXT_COLOR_LIGHT_GRAY}, + [COLORID_LIGHT_GRAY] = {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_LIGHT_GRAY, TEXT_COLOR_WHITE}, + [COLORID_WHITE_BG] = {TEXT_COLOR_WHITE, TEXT_COLOR_DARK_GRAY, TEXT_COLOR_LIGHT_GRAY}, // Unused +}; + +static const struct WindowTemplate sWindowTemplates[] = +{ + [WIN_LIST] = { .bg = 0, .tilemapLeft = 14, .tilemapTop = 2, @@ -196,7 +217,7 @@ static const struct WindowTemplate gUnknown_0861F328[] = .paletteNum = 15, .baseBlock = 30 }, - { + [WIN_INFO] = { .bg = 0, .tilemapLeft = 0, .tilemapTop = 13, @@ -205,7 +226,7 @@ static const struct WindowTemplate gUnknown_0861F328[] = .paletteNum = 15, .baseBlock = 270 }, - { + [WIN_MSG] = { .bg = 1, .tilemapLeft = 2, .tilemapTop = 15, @@ -214,7 +235,7 @@ static const struct WindowTemplate gUnknown_0861F328[] = .paletteNum = 15, .baseBlock = 354 }, - { + [WIN_TOSS_NUM] = { .bg = 1, .tilemapLeft = 24, .tilemapTop = 17, @@ -226,9 +247,17 @@ static const struct WindowTemplate gUnknown_0861F328[] = DUMMY_WIN_TEMPLATE, }; -static const struct WindowTemplate gUnknown_0861F350[] = +enum { + MENU_WIN_1x1, + MENU_WIN_1x2, + MENU_WIN_2x2, + MENU_WIN_2x3, + MENU_WIN_YESNO, +}; + +static const struct WindowTemplate sWindowTemplates_MenuActions[] = { - { + [MENU_WIN_1x1] = { .bg = 1, .tilemapLeft = 22, .tilemapTop = 17, @@ -237,7 +266,7 @@ static const struct WindowTemplate gUnknown_0861F350[] = .paletteNum = 15, .baseBlock = 472 }, - { + [MENU_WIN_1x2] = { .bg = 1, .tilemapLeft = 22, .tilemapTop = 15, @@ -246,7 +275,7 @@ static const struct WindowTemplate gUnknown_0861F350[] = .paletteNum = 15, .baseBlock = 472 }, - { + [MENU_WIN_2x2] = { .bg = 1, .tilemapLeft = 15, .tilemapTop = 15, @@ -255,7 +284,7 @@ static const struct WindowTemplate gUnknown_0861F350[] = .paletteNum = 15, .baseBlock = 472 }, - { + [MENU_WIN_2x3] = { // Unused .bg = 1, .tilemapLeft = 15, .tilemapTop = 13, @@ -264,7 +293,7 @@ static const struct WindowTemplate gUnknown_0861F350[] = .paletteNum = 15, .baseBlock = 472 }, - { + [MENU_WIN_YESNO] = { .bg = 1, .tilemapLeft = 24, .tilemapTop = 15, @@ -275,7 +304,7 @@ static const struct WindowTemplate gUnknown_0861F350[] = }, }; -static const struct OamData gOamData_861F378 = +static const struct OamData sOamData_PyramidBag = { .y = 0, .affineMode = ST_OAM_AFFINE_NORMAL, @@ -292,24 +321,24 @@ static const struct OamData gOamData_861F378 = .affineParam = 0, }; -static const union AnimCmd gSpriteAnim_861F380[] = +static const union AnimCmd sAnim_PyramidBag[] = { ANIMCMD_FRAME(0, 4), ANIMCMD_END, }; -static const union AnimCmd * const gSpriteAnimTable_861F388[] = +static const union AnimCmd * const sAnims_PyramidBag[] = { - gSpriteAnim_861F380, + sAnim_PyramidBag, }; -static const union AffineAnimCmd gSpriteAffineAnim_861F38C[] = +static const union AffineAnimCmd sAffineAnim_PyramidBag_Still[] = { AFFINEANIMCMD_FRAME(256, 256, 0, 0), AFFINEANIMCMD_END, }; -static const union AffineAnimCmd gSpriteAffineAnim_861F39C[] = +static const union AffineAnimCmd sAffineAnim_PyramidBag_Shake[] = { AFFINEANIMCMD_FRAME(0, 0, 254, 2), AFFINEANIMCMD_FRAME(0, 0, 2, 4), @@ -318,42 +347,50 @@ static const union AffineAnimCmd gSpriteAffineAnim_861F39C[] = AFFINEANIMCMD_END, }; -static const union AffineAnimCmd * const gSpriteAffineAnimTable_861F3C4[] = -{ - gSpriteAffineAnim_861F38C, - gSpriteAffineAnim_861F39C, +enum { + ANIM_BAG_STILL, + ANIM_BAG_SHAKE, }; -static const struct CompressedSpriteSheet gPyramidBagSpriteSheet = {gBattleFrontierGfx_PyramidBag, 0x0800, 0x1024}; - -static const struct SpriteTemplate gUnknown_0861F3D4 = +static const union AffineAnimCmd * const sAffineAnims_PyramidBag[] = { - .tileTag = 0x1024, - .paletteTag = 0x1024, - .oam = &gOamData_861F378, - .anims = gSpriteAnimTable_861F388, + [ANIM_BAG_STILL] = sAffineAnim_PyramidBag_Still, + [ANIM_BAG_SHAKE] = sAffineAnim_PyramidBag_Shake, +}; + +static const struct CompressedSpriteSheet sSpriteSheet_PyramidBag = {gBattleFrontierGfx_PyramidBag, 0x0800, TAG_PYRAMID_BAG}; + +static const struct SpriteTemplate sSpriteTemplate_PyramidBag = +{ + .tileTag = TAG_PYRAMID_BAG, + .paletteTag = TAG_PYRAMID_BAG, + .oam = &sOamData_PyramidBag, + .anims = sAnims_PyramidBag, .images = NULL, - .affineAnims = gSpriteAffineAnimTable_861F3C4, + .affineAnims = sAffineAnims_PyramidBag, .callback = SpriteCallbackDummy }; -// code void InitBattlePyramidBagCursorPosition(void) { - gPyramidBagCursorData.cursorPosition = 0; - gPyramidBagCursorData.scrollPosition = 0; + gPyramidBagMenuState.cursorPosition = 0; + gPyramidBagMenuState.scrollPosition = 0; } void CB2_PyramidBagMenuFromStartMenu(void) { - GoToBattlePyramidBagMenu(0, CB2_ReturnToFieldWithOpenMenu); + GoToBattlePyramidBagMenu(PYRAMIDBAG_LOC_FIELD, CB2_ReturnToFieldWithOpenMenu); } -static void sub_81C4F10(void) +// Unused, CB2_BagMenuFromBattle is used instead +static void OpenBattlePyramidBagInBattle(void) { - GoToBattlePyramidBagMenu(1, CB2_SetUpReshowBattleScreenAfterMenu2); + GoToBattlePyramidBagMenu(PYRAMIDBAG_LOC_BATTLE, CB2_SetUpReshowBattleScreenAfterMenu2); } +// If the player finishes a round at the Battle Pyramid with insufficient space in their +// Pyramid Bag to store the party's held items, they may choose items to toss in order to +// make room. void ChooseItemsToTossFromPyramidBag(void) { ScriptContext2_Enable(); @@ -367,37 +404,37 @@ static void Task_ChooseItemsToTossFromPyramidBag(u8 taskId) { CleanupOverworldWindowsAndTilemaps(); gFieldCallback2 = CB2_FadeFromPartyMenu; - GoToBattlePyramidBagMenu(3, CB2_ReturnToField); + GoToBattlePyramidBagMenu(PYRAMIDBAG_LOC_CHOOSE_TOSS, CB2_ReturnToField); DestroyTask(taskId); } } void CB2_ReturnToPyramidBagMenu(void) { - GoToBattlePyramidBagMenu(4, gPyramidBagCursorData.callback); + GoToBattlePyramidBagMenu(PYRAMIDBAG_LOC_PREV, gPyramidBagMenuState.callback); } -void GoToBattlePyramidBagMenu(u8 a0, void (*callback)(void)) +void GoToBattlePyramidBagMenu(u8 location, void (*callback)(void)) { - gPyramidBagResources = AllocZeroed(sizeof(*gPyramidBagResources)); + gPyramidBagMenu = AllocZeroed(sizeof(*gPyramidBagMenu)); - if (a0 != 4) - gPyramidBagCursorData.unk4 = a0; + if (location != PYRAMIDBAG_LOC_PREV) + gPyramidBagMenuState.location = location; if (callback != NULL) - gPyramidBagCursorData.callback = callback; + gPyramidBagMenuState.callback = callback; - gPyramidBagResources->callback2 = NULL; - gPyramidBagResources->unk814 = 0xFF; - gPyramidBagResources->scrollIndicatorsTaskId = TASK_NONE; + gPyramidBagMenu->exitCallback = NULL; + gPyramidBagMenu->toSwapPos = POS_NONE; + gPyramidBagMenu->scrollIndicatorsTaskId = TASK_NONE; - memset(gPyramidBagResources->itemsSpriteIds, 0xFF, sizeof(gPyramidBagResources->itemsSpriteIds)); - memset(gPyramidBagResources->windowIds, WINDOW_NONE, sizeof(gPyramidBagResources->windowIds)); + memset(gPyramidBagMenu->spriteIds, SPRITE_NONE, sizeof(gPyramidBagMenu->spriteIds)); + memset(gPyramidBagMenu->windowIds, WINDOW_NONE, sizeof(gPyramidBagMenu->windowIds)); - SetMainCallback2(sub_81C504C); + SetMainCallback2(CB2_LoadPyramidBagMenu); } -static void sub_81C501C(void) +static void CB2_PyramidBag(void) { RunTasks(); AnimateSprites(); @@ -406,19 +443,21 @@ static void sub_81C501C(void) UpdatePaletteFade(); } -static void sub_81C5038(void) +static void VBlankCB_PyramidBag(void) { LoadOam(); ProcessSpriteCopyRequests(); TransferPlttBuffer(); } -static void sub_81C504C(void) +static void CB2_LoadPyramidBagMenu(void) { - while (MenuHelpers_CallLinkSomething() != TRUE && sub_81C5078() != TRUE && MenuHelpers_LinkSomething() != TRUE); + while (MenuHelpers_CallLinkSomething() != TRUE + && LoadPyramidBagMenu() != TRUE + && MenuHelpers_LinkSomething() != TRUE); } -static bool8 sub_81C5078(void) +static bool8 LoadPyramidBagMenu(void) { switch (gMain.state) { @@ -446,30 +485,26 @@ static bool8 sub_81C5078(void) break; case 5: if (!MenuHelpers_LinkSomething()) - { ResetTasks(); - } gMain.state++; break; case 6: - sub_81C51DC(); - gPyramidBagResources->state = 0; + InitPyramidBagBgs(); + gPyramidBagMenu->state = 0; gMain.state++; break; case 7: - if (sub_81C5238()) - { + if (LoadPyramidBagGfx()) gMain.state++; - } break; case 8: - sub_81C6BD8(); + InitPyramidBagWindows(); gMain.state++; break; case 9: - sub_81C5924(); - sub_81C59BC(); - sub_81C5A20(); + UpdatePyramidBagList(); + UpdatePyramidBagCursorPos(); + InitPyramidBagScroll(); gMain.state++; break; case 10: @@ -477,15 +512,15 @@ static bool8 sub_81C5078(void) gMain.state++; break; case 11: - sub_81C56F8(); + CreatePyramidBagInputTask(); gMain.state++; break; case 12: - sub_81C6EF4(); + CreatePyramidBagSprite(); gMain.state++; break; case 13: - AddScrollArrow(); + AddScrollArrows(); gMain.state++; break; case 14: @@ -493,28 +528,28 @@ static bool8 sub_81C5078(void) gMain.state++; break; case 15: - BlendPalettes(PALETTES_ALL, 0x10, 0); + BlendPalettes(PALETTES_ALL, 16, 0); gMain.state++; break; case 16: - BeginNormalPaletteFade(PALETTES_ALL, 0, 0x10, 0, RGB_BLACK); + BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK); gPaletteFade.bufferTransferDisabled = FALSE; gMain.state++; break; default: - SetVBlankCallback(sub_81C5038); - SetMainCallback2(sub_81C501C); + SetVBlankCallback(VBlankCB_PyramidBag); + SetMainCallback2(CB2_PyramidBag); return TRUE; } return FALSE; } -static void sub_81C51DC(void) +static void InitPyramidBagBgs(void) { ResetVramOamAndBgCntRegs(); ResetBgsAndClearDma3BusyFlags(0); - InitBgsFromTemplates(0, gUnknown_0861F2B4, ARRAY_COUNT(gUnknown_0861F2B4)); - SetBgTilemapBuffer(2, gPyramidBagResources->tilemapBuffer); + InitBgsFromTemplates(0, sBgTemplates, ARRAY_COUNT(sBgTemplates)); + SetBgTilemapBuffer(2, gPyramidBagMenu->tilemapBuffer); ResetAllBgsCoordinates(); ScheduleBgCopyTilemapToVram(2); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 | @@ -526,37 +561,37 @@ static void sub_81C51DC(void) SetGpuReg(REG_OFFSET_BLDCNT, 0); } -static bool8 sub_81C5238(void) +static bool8 LoadPyramidBagGfx(void) { - switch (gPyramidBagResources->state) + switch (gPyramidBagMenu->state) { case 0: ResetTempTileDataBuffers(); DecompressAndCopyTileDataToVram(2, gBagScreen_Gfx, 0, 0, 0); - gPyramidBagResources->state++; + gPyramidBagMenu->state++; break; case 1: if (FreeTempTileDataBuffersIfPossible() != TRUE) { - LZDecompressWram(gBattleFrontierGfx_PyramidBagTileMap, gPyramidBagResources->tilemapBuffer); - gPyramidBagResources->state++; + LZDecompressWram(gBattleFrontierGfx_PyramidBagTileMap, gPyramidBagMenu->tilemapBuffer); + gPyramidBagMenu->state++; } break; case 2: - LoadCompressedPalette(gUnknown_08D9AF44, 0, 0x20); - gPyramidBagResources->state++; + LoadCompressedPalette(gUnknown_08D9AF44, 0, 32); + gPyramidBagMenu->state++; break; case 3: - LoadCompressedSpriteSheet(&gPyramidBagSpriteSheet); - gPyramidBagResources->state++; + LoadCompressedSpriteSheet(&sSpriteSheet_PyramidBag); + gPyramidBagMenu->state++; break; case 4: - sub_81C6E98(); - gPyramidBagResources->state++; + LoadPyramidBagPalette(); + gPyramidBagMenu->state++; break; default: LoadListMenuSwapLineGfx(); - gPyramidBagResources->state = 0; + gPyramidBagMenu->state = 0; return TRUE; } @@ -566,24 +601,24 @@ static bool8 sub_81C5238(void) static void SetBagItemsListTemplate(void) { u16 i; - u16 *pyramidItems = gSaveBlock2Ptr->frontier.pyramidBag.itemId[gSaveBlock2Ptr->frontier.lvlMode]; + u16 *itemIds = gSaveBlock2Ptr->frontier.pyramidBag.itemId[gSaveBlock2Ptr->frontier.lvlMode]; - for (i = 0; i < gPyramidBagResources->listMenuCount - 1; i++) + for (i = 0; i < gPyramidBagMenu->listMenuCount - 1; i++) { - PyramidBag_CopyItemName(gPyramidBagResources->itemStrings[i], pyramidItems[i]); - gPyramidBagResources->bagListItems[i].name = gPyramidBagResources->itemStrings[i]; - gPyramidBagResources->bagListItems[i].id = i; + CopyBagItemName(gPyramidBagMenu->itemStrings[i], itemIds[i]); + gPyramidBagMenu->bagListItems[i].name = gPyramidBagMenu->itemStrings[i]; + gPyramidBagMenu->bagListItems[i].id = i; } - StringCopy(gPyramidBagResources->itemStrings[i], gText_CloseBag); - gPyramidBagResources->bagListItems[i].name = gPyramidBagResources->itemStrings[i]; - gPyramidBagResources->bagListItems[i].id = LIST_CANCEL; - gMultiuseListMenuTemplate = gUnknown_0861F2C0; - gMultiuseListMenuTemplate.totalItems = gPyramidBagResources->listMenuCount; - gMultiuseListMenuTemplate.items = gPyramidBagResources->bagListItems; - gMultiuseListMenuTemplate.maxShowed = gPyramidBagResources->listMenuMaxShown; + StringCopy(gPyramidBagMenu->itemStrings[i], gText_CloseBag); + gPyramidBagMenu->bagListItems[i].name = gPyramidBagMenu->itemStrings[i]; + gPyramidBagMenu->bagListItems[i].id = LIST_CANCEL; + gMultiuseListMenuTemplate = sListMenuTemplate; + gMultiuseListMenuTemplate.totalItems = gPyramidBagMenu->listMenuCount; + gMultiuseListMenuTemplate.items = gPyramidBagMenu->bagListItems; + gMultiuseListMenuTemplate.maxShowed = gPyramidBagMenu->listMenuMaxShown; } -static void PyramidBag_CopyItemName(u8 *dst, u16 itemId) +static void CopyBagItemName(u8 *dst, u16 itemId) { if (ItemId_GetPocket(itemId) == POCKET_BERRIES) { @@ -597,21 +632,21 @@ static void PyramidBag_CopyItemName(u8 *dst, u16 itemId) } } -static void PyramidBagMoveCursorFunc(s32 itemIndex, bool8 onInit, struct ListMenu *list) +static void BagCursorMoved(s32 itemIndex, bool8 onInit, struct ListMenu *list) { if (onInit != TRUE) { PlaySE(SE_SELECT); - sub_81C6F20(); + ShakePyramidBag(); } - if (gPyramidBagResources->unk814 == 0xFF) + if (gPyramidBagMenu->toSwapPos == POS_NONE) { - sub_81C6FF8(gPyramidBagResources->unk815 ^ 1); + FreeItemIconSpriteByAltId(gPyramidBagMenu->isAltIcon ^ 1); if (itemIndex != LIST_CANCEL) - ShowItemImage(gSaveBlock2Ptr->frontier.pyramidBag.itemId[gSaveBlock2Ptr->frontier.lvlMode][itemIndex], gPyramidBagResources->unk815); + ShowItemIcon(gSaveBlock2Ptr->frontier.pyramidBag.itemId[gSaveBlock2Ptr->frontier.lvlMode][itemIndex], gPyramidBagMenu->isAltIcon); else - ShowItemImage(0xFFFF, gPyramidBagResources->unk815); - gPyramidBagResources->unk815 ^= 1; + ShowItemIcon(0xFFFF, gPyramidBagMenu->isAltIcon); // Show exit arrow if on Cancel + gPyramidBagMenu->isAltIcon ^= 1; PrintItemDescription(itemIndex); } } @@ -622,20 +657,23 @@ static void PrintItemQuantity(u8 windowId, s32 itemIndex, u8 y) if (itemIndex == LIST_CANCEL) return; - if (gPyramidBagResources->unk814 != 0xFF) + if (gPyramidBagMenu->toSwapPos != POS_NONE) { - if (gPyramidBagResources->unk814 == (u8)(itemIndex)) - sub_81C5AB8(y, 1); + // Performing a swap. Keep a gray selector arrow on the position to swap to + // and erase the selector arrow anywhere else + if (gPyramidBagMenu->toSwapPos == (u8)(itemIndex)) + PrintSelectorArrowAtPos(y, COLORID_LIGHT_GRAY); else - sub_81C5AB8(y, 0xFF); + PrintSelectorArrowAtPos(y, COLORID_NONE); } + ConvertIntToDecimalStringN(gStringVar1, gSaveBlock2Ptr->frontier.pyramidBag.quantity[gSaveBlock2Ptr->frontier.lvlMode][itemIndex], STR_CONV_MODE_RIGHT_ALIGN, 2); StringExpandPlaceholders(gStringVar4, gText_xVar1); - xAlign = GetStringRightAlignXOffset(7, gStringVar4, 0x77); - PrintOnWindow_Font7(windowId, gStringVar4, xAlign, y, 0, 0, TEXT_SPEED_FF, 0); + xAlign = GetStringRightAlignXOffset(7, gStringVar4, 119); + PrintOnWindow_Font7(windowId, gStringVar4, xAlign, y, 0, 0, TEXT_SPEED_FF, COLORID_DARK_GRAY); } static void PrintItemDescription(s32 listMenuId) @@ -647,34 +685,42 @@ static void PrintItemDescription(s32 listMenuId) } else { - StringCopy(gStringVar1, gReturnToXStringsTable2[gPyramidBagCursorData.unk4]); + StringCopy(gStringVar1, gPyramidBagMenu_ReturnToStrings[gPyramidBagMenuState.location]); StringExpandPlaceholders(gStringVar4, gText_ReturnToVar1); desc = gStringVar4; } - FillWindowPixelBuffer(1, PIXEL_FILL(0)); - PrintOnWindow_Font1(1, desc, 3, 0, 0, 1, 0, 0); + FillWindowPixelBuffer(WIN_INFO, PIXEL_FILL(0)); + PrintOnWindow_Font1(WIN_INFO, desc, 3, 0, 0, 1, 0, COLORID_DARK_GRAY); } -static void AddScrollArrow(void) +static void AddScrollArrows(void) { - if (gPyramidBagResources->scrollIndicatorsTaskId == TASK_NONE) - gPyramidBagResources->scrollIndicatorsTaskId = AddScrollIndicatorArrowPairParameterized(2, 172, 12, 148, gPyramidBagResources->listMenuCount - gPyramidBagResources->listMenuMaxShown, 0xB5E, 0xB5E, &gPyramidBagCursorData.scrollPosition); + if (gPyramidBagMenu->scrollIndicatorsTaskId == TASK_NONE) + gPyramidBagMenu->scrollIndicatorsTaskId = AddScrollIndicatorArrowPairParameterized(SCROLL_ARROW_UP, 172, 12, 148, + gPyramidBagMenu->listMenuCount - gPyramidBagMenu->listMenuMaxShown, + TAG_SCROLL_ARROW, TAG_SCROLL_ARROW, + &gPyramidBagMenuState.scrollPosition); } static void RemoveScrollArrow(void) { - if (gPyramidBagResources->scrollIndicatorsTaskId != TASK_NONE) + if (gPyramidBagMenu->scrollIndicatorsTaskId != TASK_NONE) { - RemoveScrollIndicatorArrowPair(gPyramidBagResources->scrollIndicatorsTaskId); - gPyramidBagResources->scrollIndicatorsTaskId = TASK_NONE; + RemoveScrollIndicatorArrowPair(gPyramidBagMenu->scrollIndicatorsTaskId); + gPyramidBagMenu->scrollIndicatorsTaskId = TASK_NONE; } } -static void sub_81C56F8(void) +#define tListTaskId data[0] +#define tListPos data[1] +#define tQuantity data[2] +#define tNumToToss data[8] + +static void CreatePyramidBagInputTask(void) { u8 taskId = CreateTask(Task_HandlePyramidBagInput, 0); s16 *data = gTasks[taskId].data; - data[0] = ListMenuInit(&gMultiuseListMenuTemplate, gPyramidBagCursorData.scrollPosition, gPyramidBagCursorData.cursorPosition); + tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, gPyramidBagMenuState.scrollPosition, gPyramidBagMenuState.cursorPosition); } static void SwapItems(u8 id1, u8 id2) @@ -728,9 +774,9 @@ static void CompactItems(void) for (i = 0; i < PYRAMID_BAG_ITEMS_COUNT; i++) { - if (itemIds[i] == 0 || quantities[i] == 0) + if (itemIds[i] == ITEM_NONE || quantities[i] == 0) { - itemIds[i] = 0; + itemIds[i] = ITEM_NONE; quantities[i] = 0; } } @@ -738,98 +784,97 @@ static void CompactItems(void) { for (j = i + 1; j < PYRAMID_BAG_ITEMS_COUNT; j++) { - if (itemIds[i] == 0 || quantities[i] == 0) + if (itemIds[i] == ITEM_NONE || quantities[i] == 0) SwapItems(i, j); } } } -void sub_81C5924(void) +void UpdatePyramidBagList(void) { u16 i; u16 *itemIds = gSaveBlock2Ptr->frontier.pyramidBag.itemId[gSaveBlock2Ptr->frontier.lvlMode]; CompactItems(); - gPyramidBagResources->listMenuCount = 0; + gPyramidBagMenu->listMenuCount = 0; for (i = 0; i < PYRAMID_BAG_ITEMS_COUNT; i++) { - if (itemIds[i] != 0) - gPyramidBagResources->listMenuCount++; + if (itemIds[i] != ITEM_NONE) + gPyramidBagMenu->listMenuCount++; } - gPyramidBagResources->listMenuCount++; - if (gPyramidBagResources->listMenuCount > 8) - gPyramidBagResources->listMenuMaxShown = 8; + gPyramidBagMenu->listMenuCount++; + if (gPyramidBagMenu->listMenuCount > 8) + gPyramidBagMenu->listMenuMaxShown = 8; else - gPyramidBagResources->listMenuMaxShown = gPyramidBagResources->listMenuCount; + gPyramidBagMenu->listMenuMaxShown = gPyramidBagMenu->listMenuCount; } -void sub_81C59BC(void) +void UpdatePyramidBagCursorPos(void) { - if (gPyramidBagCursorData.scrollPosition != 0 && gPyramidBagCursorData.scrollPosition + gPyramidBagResources->listMenuMaxShown > gPyramidBagResources->listMenuCount) - gPyramidBagCursorData.scrollPosition = gPyramidBagResources->listMenuCount - gPyramidBagResources->listMenuMaxShown; - if (gPyramidBagCursorData.scrollPosition + gPyramidBagCursorData.cursorPosition >= gPyramidBagResources->listMenuCount) + if (gPyramidBagMenuState.scrollPosition != 0 && gPyramidBagMenuState.scrollPosition + gPyramidBagMenu->listMenuMaxShown > gPyramidBagMenu->listMenuCount) + gPyramidBagMenuState.scrollPosition = gPyramidBagMenu->listMenuCount - gPyramidBagMenu->listMenuMaxShown; + + if (gPyramidBagMenuState.scrollPosition + gPyramidBagMenuState.cursorPosition >= gPyramidBagMenu->listMenuCount) { - if (gPyramidBagResources->listMenuCount == 0) - gPyramidBagCursorData.cursorPosition = 0; + if (gPyramidBagMenu->listMenuCount == 0) + gPyramidBagMenuState.cursorPosition = 0; else - gPyramidBagCursorData.cursorPosition = gPyramidBagResources->listMenuCount - 1; + gPyramidBagMenuState.cursorPosition = gPyramidBagMenu->listMenuCount - 1; } } -static void sub_81C5A20(void) +static void InitPyramidBagScroll(void) { u8 i; - if (gPyramidBagCursorData.cursorPosition > 4) + if (gPyramidBagMenuState.cursorPosition > 4) { - for (i = 0; i <= gPyramidBagCursorData.cursorPosition - 4; i++) + for (i = 0; i <= gPyramidBagMenuState.cursorPosition - 4; i++) { - if (gPyramidBagCursorData.scrollPosition + gPyramidBagResources->listMenuMaxShown == gPyramidBagResources->listMenuCount) - { - // daycare.c sends its regards. + if (gPyramidBagMenuState.scrollPosition + gPyramidBagMenu->listMenuMaxShown == gPyramidBagMenu->listMenuCount) break; - } - gPyramidBagCursorData.cursorPosition--; - gPyramidBagCursorData.scrollPosition++; + + gPyramidBagMenuState.cursorPosition--; + gPyramidBagMenuState.scrollPosition++; } } } -static void sub_81C5A98(u8 listMenuTaskId, u8 arg1) +static void PrintSelectorArrow(u8 listMenuTaskId, u8 colorId) { u8 y = ListMenuGetYCoordForPrintingArrowCursor(listMenuTaskId); - sub_81C5AB8(y, arg1); + PrintSelectorArrowAtPos(y, colorId); } -static void sub_81C5AB8(u8 y, u8 arg1) +static void PrintSelectorArrowAtPos(u8 y, u8 colorId) { - if (arg1 == 0xFF) - FillWindowPixelRect(0, PIXEL_FILL(0), 0, y, GetMenuCursorDimensionByFont(1, 0), GetMenuCursorDimensionByFont(1, 1)); + if (colorId == COLORID_NONE) // If 'no color', erase arrow + FillWindowPixelRect(WIN_LIST, PIXEL_FILL(0), 0, y, GetMenuCursorDimensionByFont(1, 0), GetMenuCursorDimensionByFont(1, 1)); else - PrintOnWindow_Font1(0, gText_SelectorArrow2, 0, y, 0, 0, 0, arg1); + PrintOnWindow_Font1(WIN_LIST, gText_SelectorArrow2, 0, y, 0, 0, 0, colorId); } -void CloseBattlePyramidBagAndSetCallback(u8 taskId) +void CloseBattlePyramidBag(u8 taskId) { - BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 0x10, RGB_BLACK); - gTasks[taskId].func = sub_81C5B4C; + BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); + gTasks[taskId].func = Task_ClosePyramidBag; } -static void sub_81C5B4C(u8 taskId) +static void Task_ClosePyramidBag(u8 taskId) { s16 *data = gTasks[taskId].data; if (!gPaletteFade.active) { - DestroyListMenuTask(data[0], &gPyramidBagCursorData.scrollPosition, &gPyramidBagCursorData.cursorPosition); - if (gPyramidBagResources->callback2 != NULL) - SetMainCallback2(gPyramidBagResources->callback2); + DestroyListMenuTask(tListTaskId, &gPyramidBagMenuState.scrollPosition, &gPyramidBagMenuState.cursorPosition); + if (gPyramidBagMenu->exitCallback != NULL) + SetMainCallback2(gPyramidBagMenu->exitCallback); else - SetMainCallback2(gPyramidBagCursorData.callback); + SetMainCallback2(gPyramidBagMenuState.callback); RemoveScrollArrow(); ResetSpriteData(); FreeAllSpritePalettes(); FreeAllWindowBuffers(); - Free(gPyramidBagResources); + Free(gPyramidBagMenu); DestroyTask(taskId); } } @@ -837,108 +882,110 @@ static void sub_81C5B4C(u8 taskId) static void Task_HandlePyramidBagInput(u8 taskId) { s16 *data = gTasks[taskId].data; - if (MenuHelpers_CallLinkSomething() != TRUE && !gPaletteFade.active) + if (MenuHelpers_CallLinkSomething() == TRUE || gPaletteFade.active) + return; + + if (JOY_NEW(SELECT_BUTTON)) { - if (JOY_NEW(SELECT_BUTTON)) + if (gPyramidBagMenuState.location != PYRAMIDBAG_LOC_PARTY) { - if (gPyramidBagCursorData.unk4 != 2) + ListMenuGetScrollAndRow(tListTaskId, &gPyramidBagMenuState.scrollPosition, &gPyramidBagMenuState.cursorPosition); + if (gPyramidBagMenuState.scrollPosition + gPyramidBagMenuState.cursorPosition != gPyramidBagMenu->listMenuCount - 1) { - ListMenuGetScrollAndRow(data[0], &gPyramidBagCursorData.scrollPosition, &gPyramidBagCursorData.cursorPosition); - if (gPyramidBagCursorData.scrollPosition + gPyramidBagCursorData.cursorPosition != gPyramidBagResources->listMenuCount - 1) - { - PlaySE(SE_SELECT); - Task_BeginItemSwap(taskId); - } + PlaySE(SE_SELECT); + Task_BeginItemSwap(taskId); } } - else + } + else + { + s32 listId = ListMenu_ProcessInput(tListTaskId); + ListMenuGetScrollAndRow(tListTaskId, &gPyramidBagMenuState.scrollPosition, &gPyramidBagMenuState.cursorPosition); + switch (listId) { - s32 listId = ListMenu_ProcessInput(data[0]); - ListMenuGetScrollAndRow(data[0], &gPyramidBagCursorData.scrollPosition, &gPyramidBagCursorData.cursorPosition); - switch (listId) - { - case LIST_NOTHING_CHOSEN: - break; - case LIST_CANCEL: - PlaySE(SE_SELECT); - gSpecialVar_ItemId = 0; - CloseBattlePyramidBagAndSetCallback(taskId); - break; - default: - PlaySE(SE_SELECT); - gSpecialVar_ItemId = gSaveBlock2Ptr->frontier.pyramidBag.itemId[gSaveBlock2Ptr->frontier.lvlMode][listId]; - data[1] = listId; - data[2] = gSaveBlock2Ptr->frontier.pyramidBag.quantity[gSaveBlock2Ptr->frontier.lvlMode][listId]; - if (gPyramidBagCursorData.unk4 == 2) - sub_81C674C(taskId); - else - sub_81C5D20(taskId); - break; - } + case LIST_NOTHING_CHOSEN: + break; + case LIST_CANCEL: + PlaySE(SE_SELECT); + gSpecialVar_ItemId = ITEM_NONE; + CloseBattlePyramidBag(taskId); + break; + default: + PlaySE(SE_SELECT); + gSpecialVar_ItemId = gSaveBlock2Ptr->frontier.pyramidBag.itemId[gSaveBlock2Ptr->frontier.lvlMode][listId]; + tListPos = listId; + tQuantity = gSaveBlock2Ptr->frontier.pyramidBag.quantity[gSaveBlock2Ptr->frontier.lvlMode][listId]; + if (gPyramidBagMenuState.location == PYRAMIDBAG_LOC_PARTY) + TryCloseBagToGiveItem(taskId); + else + OpenContextMenu(taskId); + break; } } } -static void sub_81C5D20(u8 taskId) +static void OpenContextMenu(u8 taskId) { s16 *data = gTasks[taskId].data; RemoveScrollArrow(); - sub_81C5A98(data[0], 1); - switch (gPyramidBagCursorData.unk4) + PrintSelectorArrow(tListTaskId, COLORID_LIGHT_GRAY); + switch (gPyramidBagMenuState.location) { default: - gPyramidBagResources->menuActionIds = sFieldMenuActionIds; - gPyramidBagResources->menuActionsCount = ARRAY_COUNT(sFieldMenuActionIds); +// case PYRAMIDBAG_LOC_FIELD: +// case PYRAMIDBAG_LOC_PARTY: + gPyramidBagMenu->menuActionIds = sMenuActionIds_Field; + gPyramidBagMenu->menuActionsCount = ARRAY_COUNT(sMenuActionIds_Field); break; - case 1: + case PYRAMIDBAG_LOC_BATTLE: if (ItemId_GetBattleUsage(gSpecialVar_ItemId)) { - gPyramidBagResources->menuActionIds = sBattleMenuActionIds; - gPyramidBagResources->menuActionsCount = ARRAY_COUNT(sBattleMenuActionIds); + gPyramidBagMenu->menuActionIds = sMenuActionIds_Battle; + gPyramidBagMenu->menuActionsCount = ARRAY_COUNT(sMenuActionIds_Battle); } else { - gPyramidBagResources->menuActionIds = gUnknown_0861F310; - gPyramidBagResources->menuActionsCount = ARRAY_COUNT(gUnknown_0861F310); + gPyramidBagMenu->menuActionIds = sMenuActionIds_BattleCannotUse; + gPyramidBagMenu->menuActionsCount = ARRAY_COUNT(sMenuActionIds_BattleCannotUse); } break; - case 3: - gPyramidBagResources->menuActionIds = gUnknown_0861F30C; - gPyramidBagResources->menuActionsCount = ARRAY_COUNT(gUnknown_0861F30C); + case PYRAMIDBAG_LOC_CHOOSE_TOSS: + gPyramidBagMenu->menuActionIds = sMenuActionIds_ChooseToss; + gPyramidBagMenu->menuActionsCount = ARRAY_COUNT(sMenuActionIds_ChooseToss); break; } CopyItemName(gSpecialVar_ItemId, gStringVar1); StringExpandPlaceholders(gStringVar4, gText_Var1IsSelected); - FillWindowPixelBuffer(1, PIXEL_FILL(0)); - PrintOnWindow_Font1(1, gStringVar4, 3, 0, 0, 1, 0, 0); - if (gPyramidBagResources->menuActionsCount == 1) - sub_81C5EAC(sub_81C6D24(0)); - else if (gPyramidBagResources->menuActionsCount == 2) - sub_81C5EAC(sub_81C6D24(1)); + FillWindowPixelBuffer(WIN_INFO, PIXEL_FILL(0)); + PrintOnWindow_Font1(WIN_INFO, gStringVar4, 3, 0, 0, 1, 0, COLORID_DARK_GRAY); + if (gPyramidBagMenu->menuActionsCount == 1) + PrintMenuActionText_SingleRow(OpenMenuActionWindowById(MENU_WIN_1x1)); + else if (gPyramidBagMenu->menuActionsCount == 2) + PrintMenuActionText_SingleRow(OpenMenuActionWindowById(MENU_WIN_1x2)); else - sub_81C5F08(sub_81C6D24(2), 2, 2); + PrintMenuActionText_MultiRow(OpenMenuActionWindowById(MENU_WIN_2x2), 2, 2); - if (gPyramidBagResources->menuActionsCount == 4) - gTasks[taskId].func = HandleMenuActionInput; + if (gPyramidBagMenu->menuActionsCount == 2 * 2) // Assumes any non 2x2 menu is single-row + gTasks[taskId].func = HandleMenuActionInput_2x2; else - gTasks[taskId].func = HandleFewMenuActionsInput; + gTasks[taskId].func = HandleMenuActionInput_SingleRow; } -static void sub_81C5EAC(u8 windowId) +static void PrintMenuActionText_SingleRow(u8 windowId) { - AddItemMenuActionTextPrinters(windowId, 7, 8, 1, 0, 0x10, gPyramidBagResources->menuActionsCount, sMenuActions, gPyramidBagResources->menuActionIds); - InitMenuInUpperLeftCornerPlaySoundWhenAPressed(windowId, gPyramidBagResources->menuActionsCount, 0); + AddItemMenuActionTextPrinters(windowId, 7, 8, 1, 0, 0x10, gPyramidBagMenu->menuActionsCount, sMenuActions, gPyramidBagMenu->menuActionIds); + InitMenuInUpperLeftCornerPlaySoundWhenAPressed(windowId, gPyramidBagMenu->menuActionsCount, 0); } -static void sub_81C5F08(u8 windowId, u8 horizontalCount, u8 verticalCount) +static void PrintMenuActionText_MultiRow(u8 windowId, u8 horizontalCount, u8 verticalCount) { - sub_8198DBC(windowId, 7, 8, 1, 0x38, horizontalCount, verticalCount, sMenuActions, gPyramidBagResources->menuActionIds); - sub_8199944(windowId, 0x38, horizontalCount, verticalCount, 0); + PrintMenuActionGrid(windowId, 7, 8, 1, 56, horizontalCount, verticalCount, sMenuActions, gPyramidBagMenu->menuActionIds); + InitMenuActionGrid(windowId, 56, horizontalCount, verticalCount, 0); } -static void HandleFewMenuActionsInput(u8 taskId) +static void HandleMenuActionInput_SingleRow(u8 taskId) { if (MenuHelpers_CallLinkSomething() != TRUE) { @@ -953,14 +1000,14 @@ static void HandleFewMenuActionsInput(u8 taskId) break; default: PlaySE(SE_SELECT); - if (sMenuActions[gPyramidBagResources->menuActionIds[id]].func.void_u8 != NULL) - sMenuActions[gPyramidBagResources->menuActionIds[id]].func.void_u8(taskId); + if (sMenuActions[gPyramidBagMenu->menuActionIds[id]].func.void_u8 != NULL) + sMenuActions[gPyramidBagMenu->menuActionIds[id]].func.void_u8(taskId); break; } } } -static void HandleMenuActionInput(u8 taskId) +static void HandleMenuActionInput_2x2(u8 taskId) { if (MenuHelpers_CallLinkSomething() != TRUE) { @@ -975,7 +1022,7 @@ static void HandleMenuActionInput(u8 taskId) } else if (JOY_NEW(DPAD_DOWN)) { - if (id < gPyramidBagResources->menuActionsCount - 2 && IsValidMenuAction(id + 2)) + if (id < gPyramidBagMenu->menuActionsCount - 2 && IsValidMenuAction(id + 2)) { PlaySE(SE_SELECT); ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_NONE, MENU_CURSOR_DELTA_DOWN); @@ -1000,8 +1047,8 @@ static void HandleMenuActionInput(u8 taskId) else if (JOY_NEW(A_BUTTON)) { PlaySE(SE_SELECT); - if (sMenuActions[gPyramidBagResources->menuActionIds[id]].func.void_u8 != NULL) - sMenuActions[gPyramidBagResources->menuActionIds[id]].func.void_u8(taskId); + if (sMenuActions[gPyramidBagMenu->menuActionIds[id]].func.void_u8 != NULL) + sMenuActions[gPyramidBagMenu->menuActionIds[id]].func.void_u8(taskId); } else if (JOY_NEW(B_BUTTON)) { @@ -1015,22 +1062,22 @@ static bool8 IsValidMenuAction(s8 actionTableId) { if (actionTableId < 0) return FALSE; - else if (actionTableId > gPyramidBagResources->menuActionsCount) + else if (actionTableId > gPyramidBagMenu->menuActionsCount) return FALSE; - else if (gPyramidBagResources->menuActionIds[actionTableId] == ACTION_DUMMY) + else if (gPyramidBagMenu->menuActionIds[actionTableId] == ACTION_DUMMY) return FALSE; else return TRUE; } -static void sub_81C61A8(void) +static void CloseMenuActionWindow(void) { - if (gPyramidBagResources->menuActionsCount == 1) - sub_81C6D6C(0); - else if (gPyramidBagResources->menuActionsCount == 2) - sub_81C6D6C(1); + if (gPyramidBagMenu->menuActionsCount == 1) + CloseMenuActionWindowById(MENU_WIN_1x1); + else if (gPyramidBagMenu->menuActionsCount == 2) + CloseMenuActionWindowById(MENU_WIN_1x2); else - sub_81C6D6C(2); + CloseMenuActionWindowById(MENU_WIN_2x2); } static void BagAction_UseOnField(u8 taskId) @@ -1042,13 +1089,13 @@ static void BagAction_UseOnField(u8 taskId) || pocketId == POCKET_TM_HM || ItemIsMail(gSpecialVar_ItemId) == TRUE) { - sub_81C61A8(); + CloseMenuActionWindow(); DisplayItemMessageInBattlePyramid(taskId, gText_DadsAdvice, Task_CloseBattlePyramidBagMessage); } else if (ItemId_GetFieldFunc(gSpecialVar_ItemId) != NULL) { - sub_81C61A8(); - FillWindowPixelBuffer(1, PIXEL_FILL(0)); + CloseMenuActionWindow(); + FillWindowPixelBuffer(WIN_INFO, PIXEL_FILL(0)); ScheduleBgCopyTilemapToVram(0); ItemId_GetFieldFunc(gSpecialVar_ItemId)(taskId); } @@ -1058,17 +1105,17 @@ static void BagAction_Cancel(u8 taskId) { s16 *data = gTasks[taskId].data; - sub_81C61A8(); - PrintItemDescription(data[1]); + CloseMenuActionWindow(); + PrintItemDescription(tListPos); ScheduleBgCopyTilemapToVram(0); ScheduleBgCopyTilemapToVram(1); - sub_81C5A98(data[0], 0); + PrintSelectorArrow(tListTaskId, COLORID_DARK_GRAY); SetTaskToMainPyramidBagInputHandler(taskId); } static void SetTaskToMainPyramidBagInputHandler(u8 taskId) { - AddScrollArrow(); + AddScrollArrows(); gTasks[taskId].func = Task_HandlePyramidBagInput; } @@ -1076,86 +1123,86 @@ static void BagAction_Toss(u8 taskId) { s16 *data = gTasks[taskId].data; - sub_81C61A8(); - data[8] = 1; - if (data[2] == 1) + CloseMenuActionWindow(); + tNumToToss = 1; + if (tQuantity == 1) { - sub_81C6350(taskId); + AskConfirmToss(taskId); } else { CopyItemName(gSpecialVar_ItemId, gStringVar1); StringExpandPlaceholders(gStringVar4, gText_TossHowManyVar1s); - FillWindowPixelBuffer(1, PIXEL_FILL(0)); - PrintOnWindow_Font1(1, gStringVar4, 3, 0, 0, 1, 0, 0); - sub_81C6404(); - gTasks[taskId].func = sub_81C64B4; + FillWindowPixelBuffer(WIN_INFO, PIXEL_FILL(0)); + PrintOnWindow_Font1(WIN_INFO, gStringVar4, 3, 0, 0, 1, 0, COLORID_DARK_GRAY); + ShowNumToToss(); + gTasks[taskId].func = Task_ChooseHowManyToToss; } } -static void sub_81C6350(u8 taskId) +static void AskConfirmToss(u8 taskId) { s16 *data = gTasks[taskId].data; CopyItemName(gSpecialVar_ItemId, gStringVar1); - ConvertIntToDecimalStringN(gStringVar2, data[8], STR_CONV_MODE_LEFT_ALIGN, 2); + ConvertIntToDecimalStringN(gStringVar2, tNumToToss, STR_CONV_MODE_LEFT_ALIGN, 2); StringExpandPlaceholders(gStringVar4, gText_ConfirmTossItems); - FillWindowPixelBuffer(1, PIXEL_FILL(0)); - PrintOnWindow_Font1(1, gStringVar4, 3, 0, 0, 1, 0, 0); - sub_81C6DAC(taskId, &sYesNoTossFuncions); + FillWindowPixelBuffer(WIN_INFO, PIXEL_FILL(0)); + PrintOnWindow_Font1(WIN_INFO, gStringVar4, 3, 0, 0, 1, 0, COLORID_DARK_GRAY); + CreatePyramidBagYesNo(taskId, &sYesNoTossFuncions); } static void DontTossItem(u8 taskId) { s16 *data = gTasks[taskId].data; - PrintItemDescription(data[1]); - sub_81C5A98(data[0], 0); + PrintItemDescription(tListPos); + PrintSelectorArrow(tListTaskId, COLORID_DARK_GRAY); SetTaskToMainPyramidBagInputHandler(taskId); } -static void sub_81C6404(void) +static void ShowNumToToss(void) { s32 x; - ConvertIntToDecimalStringN(gStringVar1, 1, STR_CONV_MODE_LEADING_ZEROS, 2); StringExpandPlaceholders(gStringVar4, gText_xVar1); - sub_81C6CEC(3); + DrawTossNumberWindow(WIN_TOSS_NUM); x = GetStringCenterAlignXOffset(1, gStringVar4, 0x28); - AddTextPrinterParameterized(3, 1, gStringVar4, x, 2, 0, NULL); + AddTextPrinterParameterized(WIN_TOSS_NUM, 1, gStringVar4, x, 2, 0, NULL); } -static void sub_81C645C(s16 value) +static void UpdateNumToToss(s16 num) { s32 x; - - ConvertIntToDecimalStringN(gStringVar1, value, STR_CONV_MODE_LEADING_ZEROS, 2); + ConvertIntToDecimalStringN(gStringVar1, num, STR_CONV_MODE_LEADING_ZEROS, 2); StringExpandPlaceholders(gStringVar4, gText_xVar1); x = GetStringCenterAlignXOffset(1, gStringVar4, 0x28); - AddTextPrinterParameterized(3, 1, gStringVar4, x, 2, 0, NULL); + AddTextPrinterParameterized(WIN_TOSS_NUM, 1, gStringVar4, x, 2, 0, NULL); } -static void sub_81C64B4(u8 taskId) +static void Task_ChooseHowManyToToss(u8 taskId) { s16 *data = gTasks[taskId].data; - if (AdjustQuantityAccordingToDPadInput(&data[8], data[2]) == TRUE) + if (AdjustQuantityAccordingToDPadInput(&tNumToToss, tQuantity) == TRUE) { - sub_81C645C(data[8]); + UpdateNumToToss(tNumToToss); } else if (JOY_NEW(A_BUTTON)) { + // Toss PlaySE(SE_SELECT); - ClearStdWindowAndFrameToTransparent(3, 0); - ClearWindowTilemap(3); + ClearStdWindowAndFrameToTransparent(WIN_TOSS_NUM, 0); + ClearWindowTilemap(WIN_TOSS_NUM); ScheduleBgCopyTilemapToVram(1); - sub_81C6350(taskId); + AskConfirmToss(taskId); } else if (JOY_NEW(B_BUTTON)) { + // Cancel tossing PlaySE(SE_SELECT); - ClearStdWindowAndFrameToTransparent(3, 0); - ClearWindowTilemap(3); + ClearStdWindowAndFrameToTransparent(WIN_TOSS_NUM, 0); + ClearWindowTilemap(WIN_TOSS_NUM); ScheduleBgCopyTilemapToVram(1); DontTossItem(taskId); } @@ -1166,28 +1213,28 @@ static void TossItem(u8 taskId) s16 *data = gTasks[taskId].data; CopyItemName(gSpecialVar_ItemId, gStringVar1); - ConvertIntToDecimalStringN(gStringVar2, data[8], STR_CONV_MODE_LEFT_ALIGN, 2); + ConvertIntToDecimalStringN(gStringVar2, tNumToToss, STR_CONV_MODE_LEFT_ALIGN, 2); StringExpandPlaceholders(gStringVar4, gText_ThrewAwayVar2Var1s); - FillWindowPixelBuffer(1, PIXEL_FILL(0)); - PrintOnWindow_Font1(1, gStringVar4, 3, 0, 0, 1, 0, 0); - gTasks[taskId].func = sub_81C65CC; + FillWindowPixelBuffer(WIN_INFO, PIXEL_FILL(0)); + PrintOnWindow_Font1(WIN_INFO, gStringVar4, 3, 0, 0, 1, 0, COLORID_DARK_GRAY); + gTasks[taskId].func = Task_TossItem; } -static void sub_81C65CC(u8 taskId) +static void Task_TossItem(u8 taskId) { s16 *data = gTasks[taskId].data; - u16 *scrollOffset = &gPyramidBagCursorData.scrollPosition; - u16 *selectedRow = &gPyramidBagCursorData.cursorPosition; + u16 *scrollOffset = &gPyramidBagMenuState.scrollPosition; + u16 *selectedRow = &gPyramidBagMenuState.cursorPosition; if (JOY_NEW(A_BUTTON | B_BUTTON)) { PlaySE(SE_SELECT); - RemovePyramidBagItem(gSpecialVar_ItemId, data[8]); - DestroyListMenuTask(data[0], scrollOffset, selectedRow); - sub_81C5924(); - sub_81C59BC(); + RemovePyramidBagItem(gSpecialVar_ItemId, tNumToToss); + DestroyListMenuTask(tListTaskId, scrollOffset, selectedRow); + UpdatePyramidBagList(); + UpdatePyramidBagCursorPos(); SetBagItemsListTemplate(); - data[0] = ListMenuInit(&gMultiuseListMenuTemplate, *scrollOffset, *selectedRow); + tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, *scrollOffset, *selectedRow); ScheduleBgCopyTilemapToVram(0); SetTaskToMainPyramidBagInputHandler(taskId); } @@ -1195,30 +1242,30 @@ static void sub_81C65CC(u8 taskId) static void BagAction_Give(u8 taskId) { - sub_81C61A8(); + CloseMenuActionWindow(); if (ItemIsMail(gSpecialVar_ItemId) == TRUE) { - DisplayItemMessageInBattlePyramid(taskId, gText_CantWriteMail, sub_81C66EC); + DisplayItemMessageInBattlePyramid(taskId, gText_CantWriteMail, Task_WaitCloseErrorMessage); } else if (!ItemId_GetImportance(gSpecialVar_ItemId)) { - gPyramidBagResources->callback2 = CB2_ChooseMonToGiveItem; - CloseBattlePyramidBagAndSetCallback(taskId); + gPyramidBagMenu->exitCallback = CB2_ChooseMonToGiveItem; + CloseBattlePyramidBag(taskId); } else { - sub_81C66AC(taskId); + ShowCantHoldMessage(taskId); } } -static void sub_81C66AC(u8 taskId) +static void ShowCantHoldMessage(u8 taskId) { CopyItemName(gSpecialVar_ItemId, gStringVar1); StringExpandPlaceholders(gStringVar4, gText_Var1CantBeHeld); - DisplayItemMessageInBattlePyramid(taskId, gStringVar4, sub_81C66EC); + DisplayItemMessageInBattlePyramid(taskId, gStringVar4, Task_WaitCloseErrorMessage); } -static void sub_81C66EC(u8 taskId) +static void Task_WaitCloseErrorMessage(u8 taskId) { if (JOY_NEW(A_BUTTON)) { @@ -1232,26 +1279,26 @@ void Task_CloseBattlePyramidBagMessage(u8 taskId) s16 *data = gTasks[taskId].data; CloseBattlePyramidBagTextWindow(); - PrintItemDescription(data[1]); - sub_81C5A98(data[0], 0); + PrintItemDescription(tListPos); + PrintSelectorArrow(tListTaskId, COLORID_DARK_GRAY); SetTaskToMainPyramidBagInputHandler(taskId); } -static void sub_81C674C(u8 taskId) +static void TryCloseBagToGiveItem(u8 taskId) { - if (!itemid_80BF6D8_mail_related(gSpecialVar_ItemId)) - DisplayItemMessageInBattlePyramid(taskId, gText_CantWriteMail, sub_81C66EC); + if (!IsWritingMailAllowed(gSpecialVar_ItemId)) + DisplayItemMessageInBattlePyramid(taskId, gText_CantWriteMail, Task_WaitCloseErrorMessage); else if (!ItemId_GetImportance(gSpecialVar_ItemId)) - CloseBattlePyramidBagAndSetCallback(taskId); + CloseBattlePyramidBag(taskId); else - sub_81C66AC(taskId); + ShowCantHoldMessage(taskId); } static void BagAction_UseInBattle(u8 taskId) { if (ItemId_GetBattleFunc(gSpecialVar_ItemId) != NULL) { - sub_81C61A8(); + CloseMenuActionWindow(); ItemId_GetBattleFunc(gSpecialVar_ItemId)(taskId); } } @@ -1260,15 +1307,15 @@ static void Task_BeginItemSwap(u8 taskId) { s16 *data = gTasks[taskId].data; - data[1] = gPyramidBagCursorData.scrollPosition + gPyramidBagCursorData.cursorPosition; - gPyramidBagResources->unk814 = data[1]; - ListMenuSetUnkIndicatorsStructField(data[0], 0x10, 1); - CopyItemName(gSaveBlock2Ptr->frontier.pyramidBag.itemId[gSaveBlock2Ptr->frontier.lvlMode][data[1]], gStringVar1); + tListPos = gPyramidBagMenuState.scrollPosition + gPyramidBagMenuState.cursorPosition; + gPyramidBagMenu->toSwapPos = tListPos; + ListMenuSetUnkIndicatorsStructField(tListTaskId, 0x10, 1); + CopyItemName(gSaveBlock2Ptr->frontier.pyramidBag.itemId[gSaveBlock2Ptr->frontier.lvlMode][tListPos], gStringVar1); StringExpandPlaceholders(gStringVar4, gText_MoveVar1Where); - FillWindowPixelBuffer(1, PIXEL_FILL(0)); - PrintOnWindow_Font1(1, gStringVar4, 3, 0, 0, 1, 0, 0); - sub_81C5A98(data[0], 1); - UpdateSwapLinePos(data[1]); + FillWindowPixelBuffer(WIN_INFO, PIXEL_FILL(0)); + PrintOnWindow_Font1(WIN_INFO, gStringVar4, 3, 0, 0, 1, 0, COLORID_DARK_GRAY); + PrintSelectorArrow(tListTaskId, COLORID_LIGHT_GRAY); + UpdateSwapLinePos(tListPos); gTasks[taskId].func = Task_ItemSwapHandleInput; } @@ -1280,15 +1327,15 @@ static void Task_ItemSwapHandleInput(u8 taskId) if (JOY_NEW(SELECT_BUTTON)) { PlaySE(SE_SELECT); - ListMenuGetScrollAndRow(data[0], &gPyramidBagCursorData.scrollPosition, &gPyramidBagCursorData.cursorPosition); + ListMenuGetScrollAndRow(tListTaskId, &gPyramidBagMenuState.scrollPosition, &gPyramidBagMenuState.cursorPosition); PerformItemSwap(taskId); } else { - s32 id = ListMenu_ProcessInput(data[0]); - ListMenuGetScrollAndRow(data[0], &gPyramidBagCursorData.scrollPosition, &gPyramidBagCursorData.cursorPosition); + s32 id = ListMenu_ProcessInput(tListTaskId); + ListMenuGetScrollAndRow(tListTaskId, &gPyramidBagMenuState.scrollPosition, &gPyramidBagMenuState.cursorPosition); SetSwapLineInvisibility(FALSE); - UpdateSwapLinePos(gPyramidBagCursorData.cursorPosition); + UpdateSwapLinePos(gPyramidBagMenuState.cursorPosition); switch (id) { case LIST_NOTHING_CHOSEN: @@ -1298,7 +1345,7 @@ static void Task_ItemSwapHandleInput(u8 taskId) if (JOY_NEW(A_BUTTON)) PerformItemSwap(taskId); else - sub_81C6A14(taskId); + CancelItemSwap(taskId); break; default: PlaySE(SE_SELECT); @@ -1312,41 +1359,41 @@ static void Task_ItemSwapHandleInput(u8 taskId) static void PerformItemSwap(u8 taskId) { s16 *data = gTasks[taskId].data; - u16 *scrollOffset = &gPyramidBagCursorData.scrollPosition; - u16 *selectedRow = &gPyramidBagCursorData.cursorPosition; - u16 var = *scrollOffset + *selectedRow; + u16 *scrollOffset = &gPyramidBagMenuState.scrollPosition; + u16 *selectedRow = &gPyramidBagMenuState.cursorPosition; + u16 swapPos = *scrollOffset + *selectedRow; - if (data[1] == var || data[1] == var - 1) + if (tListPos == swapPos || tListPos == swapPos - 1) { - sub_81C6A14(taskId); + CancelItemSwap(taskId); } else { - MovePyramidBagItemSlotInList(data[1], var); - gPyramidBagResources->unk814 = 0xFF; + MovePyramidBagItemSlotInList(tListPos, swapPos); + gPyramidBagMenu->toSwapPos = POS_NONE; SetSwapLineInvisibility(TRUE); - DestroyListMenuTask(data[0], scrollOffset, selectedRow); - if (data[1] < var) - gPyramidBagCursorData.cursorPosition--; + DestroyListMenuTask(tListTaskId, scrollOffset, selectedRow); + if (tListPos < swapPos) + gPyramidBagMenuState.cursorPosition--; SetBagItemsListTemplate(); - data[0] = ListMenuInit(&gMultiuseListMenuTemplate, *scrollOffset, *selectedRow); + tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, *scrollOffset, *selectedRow); SetTaskToMainPyramidBagInputHandler(taskId); } } -static void sub_81C6A14(u8 taskId) +static void CancelItemSwap(u8 taskId) { s16 *data = gTasks[taskId].data; - u16 *scrollOffset = &gPyramidBagCursorData.scrollPosition; - u16 *selectedRow = &gPyramidBagCursorData.cursorPosition; + u16 *scrollOffset = &gPyramidBagMenuState.scrollPosition; + u16 *selectedRow = &gPyramidBagMenuState.cursorPosition; - gPyramidBagResources->unk814 = 0xFF; + gPyramidBagMenu->toSwapPos = POS_NONE; SetSwapLineInvisibility(TRUE); - DestroyListMenuTask(data[0], scrollOffset, selectedRow); - if (data[1] < *scrollOffset + *selectedRow) - gPyramidBagCursorData.cursorPosition--; + DestroyListMenuTask(tListTaskId, scrollOffset, selectedRow); + if (tListPos < *scrollOffset + *selectedRow) + gPyramidBagMenuState.cursorPosition--; SetBagItemsListTemplate(); - data[0] = ListMenuInit(&gMultiuseListMenuTemplate, *scrollOffset, *selectedRow); + tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, *scrollOffset, *selectedRow); SetTaskToMainPyramidBagInputHandler(taskId); } @@ -1385,61 +1432,62 @@ void TryStoreHeldItemsInPyramidBag(void) Free(newQuantities); } -static void sub_81C6BD8(void) +static void InitPyramidBagWindows(void) { u8 i; - InitWindows(gUnknown_0861F328); + InitWindows(sWindowTemplates); DeactivateAllTextPrinters(); LoadUserWindowBorderGfx(0, 0x1, 0xE0); LoadMessageBoxGfx(0, 0xA, 0xD0); LoadPalette(gUnknown_0860F074, 0xF0, 0x20); - for (i = 0; i < 5; i++) + for (i = 0; i < ARRAY_COUNT(sWindowTemplates); i++) FillWindowPixelBuffer(i, PIXEL_FILL(0)); - PutWindowTilemap(0); - PutWindowTilemap(1); + PutWindowTilemap(WIN_LIST); + PutWindowTilemap(WIN_INFO); ScheduleBgCopyTilemapToVram(0); ScheduleBgCopyTilemapToVram(1); } static void PrintOnWindow_Font1(u8 windowId, const u8 *src, u8 x, u8 y, u8 letterSpacing, u8 lineSpacing, u8 speed, u8 colorTableId) { - AddTextPrinterParameterized4(windowId, 1, x, y, letterSpacing, lineSpacing, sColorTable[colorTableId], speed, src); + AddTextPrinterParameterized4(windowId, 1, x, y, letterSpacing, lineSpacing, sTextColors[colorTableId], speed, src); } static void PrintOnWindow_Font7(u8 windowId, const u8 *src, u8 x, u8 y, u8 letterSpacing, u8 lineSpacing, u8 speed, u8 colorTableId) { - AddTextPrinterParameterized4(windowId, 7, x, y, letterSpacing, lineSpacing, sColorTable[colorTableId], speed, src); + AddTextPrinterParameterized4(windowId, 7, x, y, letterSpacing, lineSpacing, sTextColors[colorTableId], speed, src); } -static void sub_81C6CEC(u8 windowId) +static void DrawTossNumberWindow(u8 windowId) { DrawStdFrameWithCustomTileAndPalette(windowId, 0, 1, 0xE); ScheduleBgCopyTilemapToVram(1); } -static u8 sub_81C6D08(u8 windowArrayId) +// Unused +static u8 GetMenuActionWindowId(u8 windowArrayId) { - return gPyramidBagResources->windowIds[windowArrayId]; + return gPyramidBagMenu->windowIds[windowArrayId]; } -static u8 sub_81C6D24(u8 windowArrayId) +static u8 OpenMenuActionWindowById(u8 windowArrayId) { - u8 *windowId = &gPyramidBagResources->windowIds[windowArrayId]; + u8 *windowId = &gPyramidBagMenu->windowIds[windowArrayId]; if (*windowId == WINDOW_NONE) { - *windowId = AddWindow(&gUnknown_0861F350[windowArrayId]); + *windowId = AddWindow(&sWindowTemplates_MenuActions[windowArrayId]); DrawStdFrameWithCustomTileAndPalette(*windowId, FALSE, 1, 0xE); ScheduleBgCopyTilemapToVram(1); } return *windowId; } -static void sub_81C6D6C(u8 windowArrayId) +static void CloseMenuActionWindowById(u8 windowArrayId) { - u8 *windowId = &gPyramidBagResources->windowIds[windowArrayId]; + u8 *windowId = &gPyramidBagMenu->windowIds[windowArrayId]; if (*windowId != WINDOW_NONE) { ClearStdWindowAndFrameToTransparent(*windowId, FALSE); @@ -1450,87 +1498,87 @@ static void sub_81C6D6C(u8 windowArrayId) } } -static void sub_81C6DAC(u8 taskId, const struct YesNoFuncTable *yesNoTable) +static void CreatePyramidBagYesNo(u8 taskId, const struct YesNoFuncTable *yesNoTable) { - CreateYesNoMenuWithCallbacks(taskId, &gUnknown_0861F350[4], 1, 0, 2, 1, 0xE, yesNoTable); + CreateYesNoMenuWithCallbacks(taskId, &sWindowTemplates_MenuActions[MENU_WIN_YESNO], 1, 0, 2, 1, 0xE, yesNoTable); } void DisplayItemMessageInBattlePyramid(u8 taskId, const u8 *str, void (*callback)(u8 taskId)) { - FillWindowPixelBuffer(2, PIXEL_FILL(1)); - DisplayMessageAndContinueTask(taskId, 2, 0xA, 0xD, 1, GetPlayerTextSpeedDelay(), str, callback); + FillWindowPixelBuffer(WIN_MSG, PIXEL_FILL(1)); + DisplayMessageAndContinueTask(taskId, WIN_MSG, 0xA, 0xD, 1, GetPlayerTextSpeedDelay(), str, callback); ScheduleBgCopyTilemapToVram(1); } static void CloseBattlePyramidBagTextWindow(void) { - ClearDialogWindowAndFrameToTransparent(2, FALSE); + ClearDialogWindowAndFrameToTransparent(WIN_MSG, FALSE); // This ClearWindowTilemap call is redundant, since ClearDialogWindowAndFrameToTransparent already calls it. - ClearWindowTilemap(2); + ClearWindowTilemap(WIN_MSG); ScheduleBgCopyTilemapToVram(1); } -#define ITEM_IMAGE_TAG 0x1024 - -static void sub_81C6E38(u8 itemSpriteArrayId) +static void FreeItemIconSprite(u8 spriteArrId) { - u8 *spriteId = &gPyramidBagResources->itemsSpriteIds[itemSpriteArrayId]; + u8 *spriteId = &gPyramidBagMenu->spriteIds[spriteArrId]; if (*spriteId != SPRITE_NONE) { - FreeSpriteTilesByTag(ITEM_IMAGE_TAG + itemSpriteArrayId); - FreeSpritePaletteByTag(ITEM_IMAGE_TAG + itemSpriteArrayId); + // spriteArrId is PBAG_SPRITE_ITEM_ICON / PBAG_SPRITE_ITEM_ICON_ALT here (1-2) + // so tag will be TAG_ITEM_ICON / TAG_ITEM_ICON_ALT + FreeSpriteTilesByTag(TAG_ITEM_ICON - 1 + spriteArrId); + FreeSpritePaletteByTag(TAG_ITEM_ICON - 1 + spriteArrId); FreeSpriteOamMatrix(&gSprites[*spriteId]); DestroySprite(&gSprites[*spriteId]); *spriteId = SPRITE_NONE; } } -static void sub_81C6E98(void) +static void LoadPyramidBagPalette(void) { struct SpritePalette spritePalette; u16 *palPtr = Alloc(0x40); LZDecompressWram(gBattleFrontierGfx_PyramidBag_Pal, palPtr); spritePalette.data = palPtr + (gSaveBlock2Ptr->frontier.lvlMode * 16); - spritePalette.tag = ITEM_IMAGE_TAG; + spritePalette.tag = TAG_PYRAMID_BAG; LoadSpritePalette(&spritePalette); Free(palPtr); } -static void sub_81C6EF4(void) +static void CreatePyramidBagSprite(void) { - u8 *spriteId = &gPyramidBagResources->itemsSpriteIds[0]; - *spriteId = CreateSprite(&gUnknown_0861F3D4, 0x44, 0x38, 0); + u8 *spriteId = &gPyramidBagMenu->spriteIds[PBAG_SPRITE_BAG]; + *spriteId = CreateSprite(&sSpriteTemplate_PyramidBag, 68, 56, 0); } -static void sub_81C6F20(void) +static void ShakePyramidBag(void) { - struct Sprite *sprite = &gSprites[gPyramidBagResources->itemsSpriteIds[0]]; + struct Sprite *sprite = &gSprites[gPyramidBagMenu->spriteIds[PBAG_SPRITE_BAG]]; if (sprite->affineAnimEnded) { - StartSpriteAffineAnim(sprite, 1); - sprite->callback = sub_81C6F68; + StartSpriteAffineAnim(sprite, ANIM_BAG_SHAKE); + sprite->callback = SpriteCB_BagWaitForShake; } } -static void sub_81C6F68(struct Sprite *sprite) +static void SpriteCB_BagWaitForShake(struct Sprite *sprite) { if (sprite->affineAnimEnded) { - StartSpriteAffineAnim(sprite, 0); + StartSpriteAffineAnim(sprite, ANIM_BAG_STILL); sprite->callback = SpriteCallbackDummy; } } -static void ShowItemImage(u16 itemId, u8 itemSpriteArrayId) +static void ShowItemIcon(u16 itemId, bool8 isAlt) { u8 itemSpriteId; - u8 *spriteId = &gPyramidBagResources->itemsSpriteIds[itemSpriteArrayId + 1]; + u8 *spriteId = &gPyramidBagMenu->spriteIds[isAlt + PBAG_SPRITE_ITEM_ICON]; if (*spriteId == SPRITE_NONE) { - FreeSpriteTilesByTag(ITEM_IMAGE_TAG + 1 + itemSpriteArrayId); - FreeSpritePaletteByTag(ITEM_IMAGE_TAG + 1 + itemSpriteArrayId); - itemSpriteId = AddItemIconSprite(ITEM_IMAGE_TAG + 1 + itemSpriteArrayId, ITEM_IMAGE_TAG + 1 + itemSpriteArrayId, itemId); + FreeSpriteTilesByTag(TAG_ITEM_ICON + isAlt); + FreeSpritePaletteByTag(TAG_ITEM_ICON + isAlt); + itemSpriteId = AddItemIconSprite(TAG_ITEM_ICON + isAlt, TAG_ITEM_ICON + isAlt, itemId); if (itemSpriteId != MAX_SPRITES) { *spriteId = itemSpriteId; @@ -1540,22 +1588,22 @@ static void ShowItemImage(u16 itemId, u8 itemSpriteArrayId) } } -static void sub_81C6FF8(u8 itemSpriteArrayId) +static void FreeItemIconSpriteByAltId(bool8 isAlt) { - sub_81C6E38(itemSpriteArrayId + 1); + FreeItemIconSprite(isAlt + PBAG_SPRITE_ITEM_ICON); } static void CreateSwapLine(void) { - CreateSwapLineSprites(&gPyramidBagResources->itemsSpriteIds[3], 8); + CreateSwapLineSprites(&gPyramidBagMenu->spriteIds[PBAG_SPRITE_SWAP_LINE_START], NUM_SWAP_LINE_SPRITES); } static void SetSwapLineInvisibility(bool8 invisible) { - SetSwapLineSpritesInvisibility(&gPyramidBagResources->itemsSpriteIds[3], 8, invisible); + SetSwapLineSpritesInvisibility(&gPyramidBagMenu->spriteIds[PBAG_SPRITE_SWAP_LINE_START], NUM_SWAP_LINE_SPRITES, invisible); } static void UpdateSwapLinePos(u8 y) { - UpdateSwapLineSpritesPos(&gPyramidBagResources->itemsSpriteIds[3], 8 | 0x80, 120, (y + 1) * 16); + UpdateSwapLineSpritesPos(&gPyramidBagMenu->spriteIds[PBAG_SPRITE_SWAP_LINE_START], NUM_SWAP_LINE_SPRITES | 0x80, 120, (y + 1) * 16); } diff --git a/src/item.c b/src/item.c index 892092184..b5f9e0dd6 100644 --- a/src/item.c +++ b/src/item.c @@ -820,7 +820,7 @@ bool8 RemovePyramidBagItem(u16 itemId, u16 count) u16 *items = gSaveBlock2Ptr->frontier.pyramidBag.itemId[gSaveBlock2Ptr->frontier.lvlMode]; u8 *quantities = gSaveBlock2Ptr->frontier.pyramidBag.quantity[gSaveBlock2Ptr->frontier.lvlMode]; - i = gPyramidBagCursorData.cursorPosition + gPyramidBagCursorData.scrollPosition; + i = gPyramidBagMenuState.cursorPosition + gPyramidBagMenuState.scrollPosition; if (items[i] == itemId && quantities[i] >= count) { quantities[i] -= count; diff --git a/src/item_menu.c b/src/item_menu.c index 865f8d8d1..de4d82e9b 100755 --- a/src/item_menu.c +++ b/src/item_menu.c @@ -509,7 +509,6 @@ EWRAM_DATA u16 gSpecialVar_ItemId = 0; static EWRAM_DATA struct TempWallyStruct *sTempWallyBag = 0; extern u8 *const gPocketNamesStringsTable[]; -extern u8* gReturnToXStringsTable[]; extern const u8 EventScript_SelectWithoutRegisteredItem[]; extern const u16 gUnknown_0860F074[]; @@ -530,7 +529,7 @@ void CB2_BagMenuFromBattle(void) if (!InBattlePyramid()) GoToBagMenu(ITEMMENULOCATION_BATTLE, POCKETS_COUNT, CB2_SetUpReshowBattleScreenAfterMenu2); else - GoToBattlePyramidBagMenu(1, CB2_SetUpReshowBattleScreenAfterMenu2); + GoToBattlePyramidBagMenu(PYRAMIDBAG_LOC_BATTLE, CB2_SetUpReshowBattleScreenAfterMenu2); } // Choosing berry to plant @@ -947,7 +946,7 @@ void BagMenu_PrintDescription(int itemIndex) } else { - StringCopy(gStringVar1, gReturnToXStringsTable[gBagPositionStruct.location]); + StringCopy(gStringVar1, gBagMenu_ReturnToStrings[gBagPositionStruct.location]); StringExpandPlaceholders(gStringVar4, gText_ReturnToVar1); str = gStringVar4; } @@ -1458,7 +1457,7 @@ void sub_81AC590(u8 taskId) gTasks[taskId].func = Task_BagMenu_HandleInput; } -void OpenContextMenu(u8 unused) +static void OpenContextMenu(u8 unused) { switch (gBagPositionStruct.location) { @@ -1604,8 +1603,8 @@ void sub_81ACAF8(u8 a) void sub_81ACB54(u8 a, u8 b, u8 c) { - sub_8198DBC(a, 7, 8, 1, 0x38, b, c, sItemMenuActions, gBagMenu->contextMenuItemsPtr); - sub_8199944(a, 0x38, b, c, 0); + PrintMenuActionGrid(a, 7, 8, 1, 0x38, b, c, sItemMenuActions, gBagMenu->contextMenuItemsPtr); + InitMenuActionGrid(a, 0x38, b, c, 0); } void Task_ItemContext_FieldOrBattle(u8 taskId) @@ -1850,7 +1849,7 @@ void ItemMenu_Register(u8 taskId) void ItemMenu_Give(u8 taskId) { BagMenu_RemoveSomeWindow(); - if (!itemid_80BF6D8_mail_related(gSpecialVar_ItemId)) + if (!IsWritingMailAllowed(gSpecialVar_ItemId)) { DisplayItemMessage(taskId, 1, gText_CantWriteMail, sub_81AD350); } @@ -1925,7 +1924,7 @@ void CB2_ReturnToBagMenuPocket(void) void Task_ItemContext_FieldGive(u8 taskId) { - if (!itemid_80BF6D8_mail_related(gSpecialVar_ItemId)) + if (!IsWritingMailAllowed(gSpecialVar_ItemId)) { DisplayItemMessage(taskId, 1, gText_CantWriteMail, sub_81AD350); } diff --git a/src/item_use.c b/src/item_use.c index af0ca9ee5..19f50549e 100755 --- a/src/item_use.c +++ b/src/item_use.c @@ -109,8 +109,8 @@ static void SetUpItemUseCallback(u8 taskId) } else { - gPyramidBagResources->callback2 = sItemUseCallbacks[type]; - CloseBattlePyramidBagAndSetCallback(taskId); + gPyramidBagMenu->exitCallback = sItemUseCallbacks[type]; + CloseBattlePyramidBag(taskId); } } @@ -822,8 +822,8 @@ static void RemoveUsedItem(void) } else { - sub_81C5924(); - sub_81C59BC(); + UpdatePyramidBagList(); + UpdatePyramidBagCursorPos(); } } @@ -943,7 +943,7 @@ void ItemUseInBattle_PokeBall(u8 taskId) if (!InBattlePyramid()) Task_FadeAndCloseBagMenu(taskId); else - CloseBattlePyramidBagAndSetCallback(taskId); + CloseBattlePyramidBag(taskId); } else if (!InBattlePyramid()) { @@ -960,7 +960,7 @@ static void Task_CloseStatIncreaseMessage(u8 taskId) if (!InBattlePyramid()) Task_FadeAndCloseBagMenu(taskId); else - CloseBattlePyramidBagAndSetCallback(taskId); + CloseBattlePyramidBag(taskId); } } @@ -1005,8 +1005,8 @@ static void ItemUseInBattle_ShowPartyMenu(u8 taskId) } else { - gPyramidBagResources->callback2 = ChooseMonForInBattleItem; - CloseBattlePyramidBagAndSetCallback(taskId); + gPyramidBagMenu->exitCallback = ChooseMonForInBattleItem; + CloseBattlePyramidBag(taskId); } } @@ -1039,7 +1039,7 @@ void ItemUseInBattle_Escape(u8 taskId) if (!InBattlePyramid()) DisplayItemMessage(taskId, 1, gStringVar4, Task_FadeAndCloseBagMenu); else - DisplayItemMessageInBattlePyramid(taskId, gStringVar4, CloseBattlePyramidBagAndSetCallback); + DisplayItemMessageInBattlePyramid(taskId, gStringVar4, CloseBattlePyramidBag); } else { diff --git a/src/menu.c b/src/menu.c index 44b39d762..154f88187 100644 --- a/src/menu.c +++ b/src/menu.c @@ -1241,7 +1241,7 @@ void sub_8198D54(u8 windowId, u8 fontId, u8 a2, u8 a3, u8 a4, u8 a5, const struc sub_8198C94(windowId, fontId, GetFontAttribute(fontId, 0), 0, a2, a3, a4, a5, strs); } -void sub_8198DBC(u8 windowId, u8 fontId, u8 left, u8 top, u8 a4, u8 itemCount, u8 itemCount2, const struct MenuAction *strs, const u8 *a8) +void PrintMenuActionGrid(u8 windowId, u8 fontId, u8 left, u8 top, u8 optionWidth, u8 horizontalCount, u8 verticalCount, const struct MenuAction *strs, const u8 *strIds) { u8 i; u8 j; @@ -1256,13 +1256,13 @@ void sub_8198DBC(u8 windowId, u8 fontId, u8 left, u8 top, u8 a4, u8 itemCount, u printer.letterSpacing = GetFontAttribute(fontId, FONTATTR_LETTER_SPACING); printer.lineSpacing = GetFontAttribute(fontId, FONTATTR_LINE_SPACING); - for (i = 0; i < itemCount2; i++) + for (i = 0; i < verticalCount; i++) { - for (j = 0; j < itemCount; j++) + for (j = 0; j < horizontalCount; j++) { - printer.currentChar = strs[a8[(itemCount * i) + j]].text; - printer.x = (a4 * j) + left; - printer.y = (GetFontAttribute(fontId, 1) * i) + top; + printer.currentChar = strs[strIds[(horizontalCount * i) + j]].text; + printer.x = (optionWidth * j) + left; + printer.y = (GetFontAttribute(fontId, FONTATTR_MAX_LETTER_HEIGHT) * i) + top; printer.currentX = printer.x; printer.currentY = printer.y; AddTextPrinter(&printer, 0xFF, NULL); @@ -1272,9 +1272,10 @@ void sub_8198DBC(u8 windowId, u8 fontId, u8 left, u8 top, u8 a4, u8 itemCount, u CopyWindowToVram(windowId, 2); } -void sub_8198EF8(u8 windowId, u8 fontId, u8 a2, u8 a3, u8 a4, u8 a5, const struct MenuAction *strs, const u8 *a8) +// Unused +static void PrintMenuActionGrid_TopLeft(u8 windowId, u8 fontId, u8 optionWidth, u8 unused, u8 horizontalCount, u8 verticalCount, const struct MenuAction *strs, const u8 *strIds) { - sub_8198DBC(windowId, fontId, GetFontAttribute(fontId, 0), 0, a2, a4, a5, strs, a8); + PrintMenuActionGrid(windowId, fontId, GetFontAttribute(fontId, FONTATTR_MAX_LETTER_WIDTH), 0, optionWidth, horizontalCount, verticalCount, strs, strIds); } u8 sub_8198F58(u8 windowId, u8 fontId, u8 left, u8 top, u8 a4, u8 cursorHeight, u8 a6, u8 a7, u8 numChoices, u8 a9) @@ -1701,7 +1702,7 @@ void sub_819983C(u8 windowId, u8 a4, u8 itemCount, u8 itemCount2, const struct M CopyWindowToVram(windowId, 2); } -u8 sub_8199944(u8 windowId, u8 optionWidth, u8 columns, u8 rows, u8 initialCursorPos) +u8 InitMenuActionGrid(u8 windowId, u8 optionWidth, u8 columns, u8 rows, u8 initialCursorPos) { s32 pos; diff --git a/src/menu_helpers.c b/src/menu_helpers.c index 5a6ac8394..151de0bd4 100644 --- a/src/menu_helpers.c +++ b/src/menu_helpers.c @@ -287,7 +287,7 @@ bool8 sub_8122148(u16 itemId) return FALSE; } -bool8 itemid_80BF6D8_mail_related(u16 itemId) +bool8 IsWritingMailAllowed(u16 itemId) { if (IsUpdateLinkStateCBActive() != TRUE && InUnionRoom() != TRUE) return TRUE; diff --git a/src/party_menu.c b/src/party_menu.c index 81c39949b..681dc5f93 100755 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -3020,7 +3020,7 @@ static void CB2_SelectBagItemToGive(void) if (InBattlePyramid() == FALSE) GoToBagMenu(ITEMMENULOCATION_PARTY, POCKETS_COUNT, CB2_GiveHoldItem); else - GoToBattlePyramidBagMenu(2, CB2_GiveHoldItem); + GoToBattlePyramidBagMenu(PYRAMIDBAG_LOC_PARTY, CB2_GiveHoldItem); } static void CB2_GiveHoldItem(void) @@ -4203,7 +4203,7 @@ static void CB2_ReturnToBagMenu(void) if (InBattlePyramid() == FALSE) GoToBagMenu(ITEMMENULOCATION_LAST, POCKETS_COUNT, NULL); else - GoToBattlePyramidBagMenu(4, gPyramidBagCursorData.callback); + GoToBattlePyramidBagMenu(PYRAMIDBAG_LOC_PREV, gPyramidBagMenuState.callback); } static void Task_SetSacredAshCB(u8 taskId) diff --git a/src/script_menu.c b/src/script_menu.c index 51c37b5b6..f3317773a 100644 --- a/src/script_menu.c +++ b/src/script_menu.c @@ -279,7 +279,7 @@ bool8 ScriptMenu_MultichoiceGrid(u8 left, u8 top, u8 multichoiceId, bool8 ignore gTasks[taskId].tWindowId = CreateWindowFromRect(left, top, columnCount * newWidth, rowCount * 2); SetStandardWindowBorderStyle(gTasks[taskId].tWindowId, 0); PrintMenuGridTable(gTasks[taskId].tWindowId, newWidth * 8, columnCount, rowCount, sMultichoiceLists[multichoiceId].list); - sub_8199944(gTasks[taskId].tWindowId, newWidth * 8, columnCount, rowCount, 0); + InitMenuActionGrid(gTasks[taskId].tWindowId, newWidth * 8, columnCount, rowCount, 0); CopyWindowToVram(gTasks[taskId].tWindowId, 3); return TRUE; } diff --git a/src/strings.c b/src/strings.c index 5c9b09c83..18cf31fb7 100644 --- a/src/strings.c +++ b/src/strings.c @@ -1,5 +1,6 @@ #include "global.h" #include "strings.h" +#include "battle_pyramid_bag.h" ALIGNED(4) const u8 gText_ExpandedPlaceholder_Empty[] = _(""); @@ -252,7 +253,7 @@ const u8 gText_ThePokemonList[] = _("the POKéMON LIST"); const u8 gText_TheShop[] = _("the shop"); const u8 gText_ThePC[] = _("the PC"); -const u8 *const gReturnToXStringsTable[] = +const u8 *const gBagMenu_ReturnToStrings[] = { gText_TheField, gText_TheBattle, @@ -268,12 +269,12 @@ const u8 *const gReturnToXStringsTable[] = gText_ThePC }; -const u8 *const gReturnToXStringsTable2[] = +const u8 *const gPyramidBagMenu_ReturnToStrings[] = { - gText_TheField, - gText_TheBattle, - gText_ThePokemonList, - gText_TheField + [PYRAMIDBAG_LOC_FIELD] = gText_TheField, + [PYRAMIDBAG_LOC_BATTLE] = gText_TheBattle, + [PYRAMIDBAG_LOC_PARTY] = gText_ThePokemonList, + [PYRAMIDBAG_LOC_CHOOSE_TOSS] = gText_TheField }; const u8 gText_ReturnToVar1[] = _("Return to\n{STR_VAR_1}."); From 004c37bf022f9ab8a4307306f84cb20ac1dc9518 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 23 Apr 2021 17:04:44 -0400 Subject: [PATCH 06/11] Sync ereader_helpers with pokefirered --- include/ereader_helpers.h | 8 +- include/link.h | 2 +- src/ereader_helpers.c | 413 ++++++++++++++++++++------------------ src/ereader_screen.c | 8 +- 4 files changed, 227 insertions(+), 204 deletions(-) diff --git a/include/ereader_helpers.h b/include/ereader_helpers.h index 8dc3b907a..7cced65cb 100755 --- a/include/ereader_helpers.h +++ b/include/ereader_helpers.h @@ -24,11 +24,11 @@ struct EReaderTrainerHillSet bool8 EReader_IsReceivedDataValid(struct EReaderTrainerHillSet *buffer); bool32 TryWriteTrainerHill(struct EReaderTrainerHillSet *arg0); bool32 ReadTrainerHillAndValidate(void); -int EReaderHandleTransfer(u8, u32, u32*, u32*); -void sub_81D3F9C(void); -void sub_81D3FAC(void); +int EReaderHandleTransfer(u8, size_t, const void *, void *); +void EReaderHelper_Timer3Callback(void); +void EReaderHelper_SerialCallback(void); void EReaderHelper_SaveRegsState(void); void EReaderHelper_RestoreRegsState(void); -void sub_81D4238(void); +void EReaderHelper_ClearSendRecvMgr(void); #endif // GUARD_EREADER_HELPERS_H diff --git a/include/link.h b/include/link.h index 3b621e6c1..407dbabb9 100644 --- a/include/link.h +++ b/include/link.h @@ -323,7 +323,7 @@ extern bool8 gSavedLinkPlayerCount; extern u8 gSavedMultiplayerId; extern struct LinkTestBGInfo gLinkTestBGInfo; extern void (*gLinkCallback)(void); -extern bool8 gShouldAdvanceLinkState; +extern u8 gShouldAdvanceLinkState; extern u16 gLinkTestBlockChecksums[MAX_LINK_PLAYERS]; extern u8 gBlockRequestType; extern u8 gLastSendQueueCount; diff --git a/src/ereader_helpers.c b/src/ereader_helpers.c index 5edfc120c..4db62c847 100755 --- a/src/ereader_helpers.c +++ b/src/ereader_helpers.c @@ -15,33 +15,62 @@ #include "constants/moves.h" #include "constants/items.h" -struct Unknown030012C8 -{ - u8 unk0[8]; - u32 *unk8; - int unkC; - int unk10; - int unk14; +enum { + EREADER_XFR_STATE_INIT = 0, + EREADER_XFR_STATE_HANDSHAKE, + EREADER_XFR_STATE_START, + EREADER_XFR_STATE_TRANSFER, + EREADER_XFR_STATE_TRANSFER_DONE, + EREADER_XFR_STATE_CHECKSUM, + EREADER_XFR_STATE_DONE }; -static void sub_81D4170(void); -static u16 sub_81D3EE8(u8); -static void sub_81D413C(void); -static void sub_81D414C(void); -static void sub_81D3F1C(u32, u32*, u32*); -static void sub_81D3F68(void); +#define EREADER_XFER_EXE 1 +#define EREADER_XFER_CHK 2 +#define EREADER_XFER_SHIFT 0 +#define EREADER_XFER_MASK 3 -static struct Unknown030012C8 gUnknown_030012C8; -static u16 gUnknown_030012E0; -static u16 gUnknown_030012E2; -static u16 gUnknown_030012E4; -static u16 gUnknown_030012E6; -static u32 gUnknown_030012E8; -static u16 gUnknown_030012EC; -static u16 gUnknown_030012EE; -static u16 gUnknown_030012F0; -static u16 gUnknown_030012F2; -static u16 gUnknown_030012F4; +#define EREADER_CANCEL_TIMEOUT 1 +#define EREADER_CANCEL_KEY 2 +#define EREADER_CANCEL_MASK 0xC +#define EREADER_CANCEL_SHIFT 2 + +#define EREADER_CHECKSUM_OK 1 +#define EREADER_CHECKSUM_ERR 2 +#define EREADER_CHECKSUM_MASK 0x30 +#define EREADER_CHECKSUM_SHIFT 4 + +struct SendRecvMgr +{ + bool8 isParent; + u8 state; // EREADER_XFR_STATE_* + u8 xferState; // EREADER_XFER_* + u8 checksumResult; // EREADER_CHECKSUM_* + u8 cancellationReason; // EREADER_CANCEL_* + u32 *data; // Payload source or destination + int cursor; // Index of the next word + int size; // Last word index + int checksum; +}; + +static void GetKeyInput(void); +static u16 DetermineSendRecvState(u8); +static void EnableSio(void); +static void DisableTm3(void); +static void SetUpTransferManager(size_t, const void *, void *); +static void StartTm3(void); + +static struct SendRecvMgr sSendRecvMgr; +static u16 sJoyNewOrRepeated; +static u16 sJoyNew; +static u16 sSendRecvStatus; +static u16 sCounter1; +static u32 sCounter2; +static u16 sSavedIme; +static u16 sSavedIe; +static u16 sSavedTm3Cnt; +static u16 sSavedSioCnt; +static u16 sSavedRCnt; static const struct TrainerHillTrainer sTrainerHillTrainerTemplates_JP[] = { [0] = { @@ -514,93 +543,89 @@ bool32 ReadTrainerHillAndValidate(void) return result; } -int EReader_Send(int arg0, u32 *arg1) +int EReader_Send(int size, const void * src) { int result; - u16 var0; - int var1; + int sendStatus; EReaderHelper_SaveRegsState(); while (1) { - sub_81D4170(); - if (gUnknown_030012E2 & 2) + GetKeyInput(); + if (sJoyNew & B_BUTTON) gShouldAdvanceLinkState = 2; - var1 = EReaderHandleTransfer(1, arg0, arg1, NULL); - gUnknown_030012E4 = var1; - if ((gUnknown_030012E4 & 0x13) == 0x10) + sendStatus = EReaderHandleTransfer(1, size, src, NULL); + sSendRecvStatus = sendStatus; + if ((sSendRecvStatus & 0x13) == 0x10) { result = 0; break; } - - if (gUnknown_030012E4 & 0x8) + else if (sSendRecvStatus & 0x8) { result = 1; break; } - - var0 = gUnknown_030012E4 & 0x4; - if (var0) + else if (sSendRecvStatus & 0x4) { result = 2; break; } - - gShouldAdvanceLinkState = var0; - VBlankIntrWait(); + else + { + gShouldAdvanceLinkState = 0; + VBlankIntrWait(); + } } - CpuFill32(0, &gUnknown_030012C8, sizeof(struct Unknown030012C8)); + CpuFill32(0, &sSendRecvMgr, sizeof(sSendRecvMgr)); EReaderHelper_RestoreRegsState(); return result; } -int EReader_Recv(u32 *arg0) +int EReader_Recv(void * dest) { int result; - u16 var0; - int var1; + int recvStatus; EReaderHelper_SaveRegsState(); while (1) { - sub_81D4170(); - if (gUnknown_030012E2 & 2) + GetKeyInput(); + if (sJoyNew & B_BUTTON) gShouldAdvanceLinkState = 2; - var1 = EReaderHandleTransfer(0, 0, NULL, arg0); - gUnknown_030012E4 = var1; - if ((gUnknown_030012E4 & 0x13) == 0x10) + recvStatus = EReaderHandleTransfer(0, 0, NULL, dest); + sSendRecvStatus = recvStatus; + if ((sSendRecvStatus & 0x13) == 0x10) { result = 0; break; } - - if (gUnknown_030012E4 & 0x8) + else if (sSendRecvStatus & 0x8) { result = 1; break; } - - var0 = gUnknown_030012E4 & 0x4; - if (var0) + else if (sSendRecvStatus & 0x4) { result = 2; break; } - - gShouldAdvanceLinkState = var0; - VBlankIntrWait(); + else + { + gShouldAdvanceLinkState = 0; + VBlankIntrWait(); + } } - CpuFill32(0, &gUnknown_030012C8, sizeof(struct Unknown030012C8)); + CpuFill32(0, &sSendRecvMgr, sizeof(sSendRecvMgr)); EReaderHelper_RestoreRegsState(); return result; } -static void sub_81D3C7C(void) +static void CloseSerial(void) { REG_IME = 0; REG_IE &= ~(INTR_FLAG_TIMER3 | INTR_FLAG_SERIAL); @@ -610,7 +635,7 @@ static void sub_81D3C7C(void) REG_IF = INTR_FLAG_TIMER3 | INTR_FLAG_SERIAL; } -static void sub_81D3CBC(void) +static void OpenSerialMulti(void) { REG_IME = 0; REG_IE &= ~(INTR_FLAG_TIMER3 | INTR_FLAG_SERIAL); @@ -622,273 +647,271 @@ static void sub_81D3CBC(void) REG_IE |= INTR_FLAG_SERIAL; REG_IME = 1; - if (!gUnknown_030012C8.unk0[1]) - CpuFill32(0, &gUnknown_030012C8, sizeof(struct Unknown030012C8)); + if (sSendRecvMgr.state == 0) + CpuFill32(0, &sSendRecvMgr, sizeof(sSendRecvMgr)); } -static void sub_81D3D34(void) +static void OpenSerial32(void) { REG_RCNT = 0; REG_SIOCNT = SIO_32BIT_MODE | SIO_INTR_ENABLE; REG_SIOCNT |= SIO_MULTI_SD; gShouldAdvanceLinkState = 0; - gUnknown_030012E6 = 0; - gUnknown_030012E8 = 0; + sCounter1 = 0; + sCounter2 = 0; } -int EReaderHandleTransfer(u8 arg0, u32 arg1, u32 *arg2, u32 *arg3) +int EReaderHandleTransfer(u8 mode, size_t size, const void * data, void * recvBuffer) { - switch (gUnknown_030012C8.unk0[1]) + switch (sSendRecvMgr.state) { - case 0: - sub_81D3CBC(); - gUnknown_030012C8.unk0[2] = 1; - gUnknown_030012C8.unk0[1] = 1; + case EREADER_XFR_STATE_INIT: + OpenSerialMulti(); + sSendRecvMgr.xferState = EREADER_XFER_EXE; + sSendRecvMgr.state = EREADER_XFR_STATE_HANDSHAKE; break; - case 1: - if (sub_81D3EE8(arg0)) - sub_81D413C(); + case EREADER_XFR_STATE_HANDSHAKE: + if (DetermineSendRecvState(mode)) + EnableSio(); if (gShouldAdvanceLinkState == 2) { - gUnknown_030012C8.unk0[4] = 2; - gUnknown_030012C8.unk0[1] = 6; + sSendRecvMgr.cancellationReason = EREADER_CANCEL_KEY; + sSendRecvMgr.state = EREADER_XFR_STATE_DONE; } break; - case 2: - sub_81D3D34(); - sub_81D3F1C(arg1, arg2, arg3); - gUnknown_030012C8.unk0[1] = 3; + case EREADER_XFR_STATE_START: + OpenSerial32(); + SetUpTransferManager(size, data, recvBuffer); + sSendRecvMgr.state = EREADER_XFR_STATE_TRANSFER; // fall through - case 3: + case EREADER_XFR_STATE_TRANSFER: if (gShouldAdvanceLinkState == 2) { - gUnknown_030012C8.unk0[4] = 2; - gUnknown_030012C8.unk0[1] = 6; + sSendRecvMgr.cancellationReason = EREADER_CANCEL_KEY; + sSendRecvMgr.state = EREADER_XFR_STATE_DONE; } else { - gUnknown_030012E6++; - gUnknown_030012E8++; - if (!gUnknown_030012C8.unk0[0] && gUnknown_030012E8 > 60) + sCounter1++; + sCounter2++; + if (!sSendRecvMgr.isParent && sCounter2 > 60) { - gUnknown_030012C8.unk0[4] = 1; - gUnknown_030012C8.unk0[1] = 6; + sSendRecvMgr.cancellationReason = EREADER_CANCEL_TIMEOUT; + sSendRecvMgr.state = EREADER_XFR_STATE_DONE; } - if (gUnknown_030012C8.unk0[2] != 2) + if (sSendRecvMgr.xferState != EREADER_XFER_CHK) { - if (gUnknown_030012C8.unk0[0] && gUnknown_030012E6 > 2) + if (sSendRecvMgr.isParent && sCounter1 > 2) { - sub_81D413C(); - gUnknown_030012C8.unk0[2] = 2; + EnableSio(); + sSendRecvMgr.xferState = EREADER_XFER_CHK; } else { - sub_81D413C(); - gUnknown_030012C8.unk0[2] = 2; + EnableSio(); + sSendRecvMgr.xferState = EREADER_XFER_CHK; } } } break; - case 4: - sub_81D3CBC(); - gUnknown_030012C8.unk0[1] = 5; + case EREADER_XFR_STATE_TRANSFER_DONE: + OpenSerialMulti(); + sSendRecvMgr.state = EREADER_XFR_STATE_CHECKSUM; break; - case 5: - if (gUnknown_030012C8.unk0[0] == 1 && gUnknown_030012E6 > 2) - sub_81D413C(); + case EREADER_XFR_STATE_CHECKSUM: + if (sSendRecvMgr.isParent == TRUE && sCounter1 > 2) + EnableSio(); - if (++gUnknown_030012E6 > 60) + if (++sCounter1 > 60) { - gUnknown_030012C8.unk0[4] = 1; - gUnknown_030012C8.unk0[1] = 6; + sSendRecvMgr.cancellationReason = EREADER_CANCEL_TIMEOUT; + sSendRecvMgr.state = EREADER_XFR_STATE_DONE; } break; - case 6: - if (gUnknown_030012C8.unk0[2]) + case EREADER_XFR_STATE_DONE: + if (sSendRecvMgr.xferState) { - sub_81D3C7C(); - gUnknown_030012C8.unk0[2] = 0; + CloseSerial(); + sSendRecvMgr.xferState = 0; } break; } - return gUnknown_030012C8.unk0[2] | (gUnknown_030012C8.unk0[4] << 2) | (gUnknown_030012C8.unk0[3] << 4); + return (sSendRecvMgr.xferState << EREADER_XFER_SHIFT) + | (sSendRecvMgr.cancellationReason << EREADER_CANCEL_SHIFT) + | (sSendRecvMgr.checksumResult << EREADER_CHECKSUM_SHIFT); } -static u16 sub_81D3EE8(u8 arg0) +static u16 DetermineSendRecvState(u8 mode) { - u16 terminal = (*(vu32 *)REG_ADDR_SIOCNT) & (SIO_MULTI_SI | SIO_MULTI_SD); - if (terminal == SIO_MULTI_SD && arg0) - { - gUnknown_030012C8.unk0[0] = 1; - return 1; - } + bool16 resp; + if ((*(vu32 *)REG_ADDR_SIOCNT & (SIO_MULTI_SI | SIO_MULTI_SD)) == SIO_MULTI_SD && mode) + resp = sSendRecvMgr.isParent = TRUE; else - { - gUnknown_030012C8.unk0[0] = 0; - return 0; - } + resp = sSendRecvMgr.isParent = FALSE; + return resp; } -static void sub_81D3F1C(u32 arg0, u32 *arg1, u32 *arg2) +static void SetUpTransferManager(size_t size, const void * data, void * recvBuffer) { - if (gUnknown_030012C8.unk0[0]) + if (sSendRecvMgr.isParent) { REG_SIOCNT |= SIO_38400_BPS; - gUnknown_030012C8.unk8 = arg1; - REG_SIODATA32 = arg0; - gUnknown_030012C8.unk10 = arg0 / 4 + 1; - sub_81D3F68(); + sSendRecvMgr.data = (void *)data; + REG_SIODATA32 = size; + sSendRecvMgr.size = size / 4 + 1; + StartTm3(); } else { REG_SIOCNT = REG_SIOCNT; - gUnknown_030012C8.unk8 = arg2; + sSendRecvMgr.data = recvBuffer; } } -static void sub_81D3F68(void) +static void StartTm3(void) { - REG_TM3CNT_L = 0xFDA7; + REG_TM3CNT_L = -601; REG_TM3CNT_H = TIMER_INTR_ENABLE; REG_IME = 0; REG_IE |= INTR_FLAG_TIMER3; REG_IME = 1; } -void sub_81D3F9C(void) +void EReaderHelper_Timer3Callback(void) { - sub_81D414C(); - sub_81D413C(); + DisableTm3(); + EnableSio(); } -void sub_81D3FAC(void) +void EReaderHelper_SerialCallback(void) { - u16 i, playerCount, k; - u32 value; - u16 var0; - u16 recvBuffer[4]; + u16 i, cnt1, cnt2; + u32 recv32; + u16 recv[4]; - switch (gUnknown_030012C8.unk0[1]) + switch (sSendRecvMgr.state) { - case 1: + case EREADER_XFR_STATE_HANDSHAKE: REG_SIOMLT_SEND = 0xCCD0; // Handshake id - *(u64 *)recvBuffer = REG_SIOMLT_RECV; - for (i = 0, playerCount = 0, k = 0; i < 4; i++) + *(u64 *)recv = REG_SIOMLT_RECV; + for (i = 0, cnt1 = 0, cnt2 = 0; i < 4; i++) { - if (recvBuffer[i] == 0xCCD0) - playerCount++; - else if (recvBuffer[i] != 0xFFFF) - k++; + if (recv[i] == 0xCCD0) + cnt1++; + else if (recv[i] != 0xFFFF) + cnt2++; } - if (playerCount == 2 && k == 0) - gUnknown_030012C8.unk0[1] = 2; + if (cnt1 == 2 && cnt2 == 0) + sSendRecvMgr.state = 2; break; - case 3: - value = REG_SIODATA32; - if (!gUnknown_030012C8.unkC && !gUnknown_030012C8.unk0[0]) - gUnknown_030012C8.unk10 = value / 4 + 1; + case EREADER_XFR_STATE_TRANSFER: + recv32 = REG_SIODATA32; + // The first value sent by the EReader is the payload size + if (!sSendRecvMgr.cursor && !sSendRecvMgr.isParent) + sSendRecvMgr.size = recv32 / 4 + 1; - if (gUnknown_030012C8.unk0[0] == 1) + if (sSendRecvMgr.isParent == TRUE) { - if (gUnknown_030012C8.unkC < gUnknown_030012C8.unk10) + // Send mode + if (sSendRecvMgr.cursor < sSendRecvMgr.size) { - REG_SIODATA32 = gUnknown_030012C8.unk8[gUnknown_030012C8.unkC]; - gUnknown_030012C8.unk14 += gUnknown_030012C8.unk8[gUnknown_030012C8.unkC]; + REG_SIODATA32 = sSendRecvMgr.data[sSendRecvMgr.cursor]; + sSendRecvMgr.checksum += sSendRecvMgr.data[sSendRecvMgr.cursor]; } else { - REG_SIODATA32 = gUnknown_030012C8.unk14; + REG_SIODATA32 = sSendRecvMgr.checksum; } } else { - if (gUnknown_030012C8.unkC > 0 && gUnknown_030012C8.unkC < gUnknown_030012C8.unk10 + 1) + // Receive mode + if (sSendRecvMgr.cursor > 0 && sSendRecvMgr.cursor < sSendRecvMgr.size + 1) { - gUnknown_030012C8.unk8[gUnknown_030012C8.unkC - 1] = value; - gUnknown_030012C8.unk14 += value; + sSendRecvMgr.data[sSendRecvMgr.cursor - 1] = recv32; + sSendRecvMgr.checksum += recv32; } - else if (gUnknown_030012C8.unkC) + else if (sSendRecvMgr.cursor) { - if (gUnknown_030012C8.unk14 == value) - gUnknown_030012C8.unk0[3] = 1; + if (sSendRecvMgr.checksum == recv32) + sSendRecvMgr.checksumResult = EREADER_CHECKSUM_OK; else - gUnknown_030012C8.unk0[3] = 2; + sSendRecvMgr.checksumResult = EREADER_CHECKSUM_ERR; } - gUnknown_030012E8 = 0; + sCounter2 = 0; } - if (++gUnknown_030012C8.unkC < gUnknown_030012C8.unk10 + 2) + if (++sSendRecvMgr.cursor < sSendRecvMgr.size + 2) { - if (gUnknown_030012C8.unk0[0]) + if (sSendRecvMgr.isParent) REG_TM3CNT_H |= TIMER_ENABLE; else - sub_81D413C(); + EnableSio(); } else { - gUnknown_030012C8.unk0[1] = 4; - gUnknown_030012E6 = 0; + sSendRecvMgr.state = EREADER_XFR_STATE_TRANSFER_DONE; + sCounter1 = 0; } break; - case 5: - if (!gUnknown_030012C8.unk0[0]) - REG_SIOMLT_SEND = gUnknown_030012C8.unk0[3]; + case EREADER_XFR_STATE_CHECKSUM: + if (!sSendRecvMgr.isParent) + REG_SIOMLT_SEND = sSendRecvMgr.checksumResult; - *(u64 *)recvBuffer = REG_SIOMLT_RECV; - var0 = recvBuffer[1] - 1; - if (var0 < 2) + *(vu64 *)recv = REG_SIOMLT_RECV; + if (recv[1] == EREADER_CHECKSUM_OK || recv[1] == EREADER_CHECKSUM_ERR) { - if (gUnknown_030012C8.unk0[0] == 1) - gUnknown_030012C8.unk0[3] = recvBuffer[1]; + if (sSendRecvMgr.isParent == TRUE) + sSendRecvMgr.checksumResult = recv[1]; // EReader has (in)validated the payload - gUnknown_030012C8.unk0[1] = 6; + sSendRecvMgr.state = EREADER_XFR_STATE_DONE; } break; } } -static void sub_81D413C(void) +static void EnableSio(void) { REG_SIOCNT |= SIO_ENABLE; } -static void sub_81D414C(void) +static void DisableTm3(void) { REG_TM3CNT_H &= ~TIMER_ENABLE; REG_TM3CNT_L = 0xFDA7; } -static void sub_81D4170(void) +static void GetKeyInput(void) { - int keysMask = REG_KEYINPUT ^ KEYS_MASK; - gUnknown_030012E2 = keysMask & ~gUnknown_030012E0; - gUnknown_030012E0 = keysMask; + int rawKeys = REG_KEYINPUT ^ KEYS_MASK; + sJoyNew = rawKeys & ~sJoyNewOrRepeated; + sJoyNewOrRepeated = rawKeys; } void EReaderHelper_SaveRegsState(void) { - gUnknown_030012EC = REG_IME; - gUnknown_030012EE = REG_IE; - gUnknown_030012F0 = REG_TM3CNT_H; - gUnknown_030012F2 = REG_SIOCNT; - gUnknown_030012F4 = REG_RCNT; + sSavedIme = REG_IME; + sSavedIe = REG_IE; + sSavedTm3Cnt = REG_TM3CNT_H; + sSavedSioCnt = REG_SIOCNT; + sSavedRCnt = REG_RCNT; } void EReaderHelper_RestoreRegsState(void) { - REG_IME = gUnknown_030012EC; - REG_IE = gUnknown_030012EE; - REG_TM3CNT_H = gUnknown_030012F0; - REG_SIOCNT = gUnknown_030012F2; - REG_RCNT = gUnknown_030012F4; + REG_IME = sSavedIme; + REG_IE = sSavedIe; + REG_TM3CNT_H = sSavedTm3Cnt; + REG_SIOCNT = sSavedSioCnt; + REG_RCNT = sSavedRCnt; } -void sub_81D4238(void) +void EReaderHelper_ClearSendRecvMgr(void) { - CpuFill32(0, &gUnknown_030012C8, sizeof(struct Unknown030012C8)); + CpuFill32(0, &sSendRecvMgr, sizeof(sSendRecvMgr)); } diff --git a/src/ereader_screen.c b/src/ereader_screen.c index d27605c1d..d79b23b93 100755 --- a/src/ereader_screen.c +++ b/src/ereader_screen.c @@ -47,10 +47,10 @@ static void sub_81D4D50(struct Unk03006370 *arg0, int arg1, u32 *arg2) { volatile u16 backupIME = REG_IME; REG_IME = 0; - gIntrTable[1] = sub_81D3FAC; - gIntrTable[2] = sub_81D3F9C; + gIntrTable[1] = EReaderHelper_SerialCallback; + gIntrTable[2] = EReaderHelper_Timer3Callback; EReaderHelper_SaveRegsState(); - sub_81D4238(); + EReaderHelper_ClearSendRecvMgr(); REG_IE |= INTR_FLAG_VCOUNT; REG_IME = backupIME; arg0->unk0 = 0; @@ -62,7 +62,7 @@ static void sub_81D4DB8(struct Unk03006370 *arg0) { volatile u16 backupIME = REG_IME; REG_IME = 0; - sub_81D4238(); + EReaderHelper_ClearSendRecvMgr(); EReaderHelper_RestoreRegsState(); RestoreSerialTimer3IntrHandlers(); REG_IME = backupIME; From 86475c5ded028032a5b02c2700af77de2ab140c6 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sat, 24 Apr 2021 18:04:27 -0400 Subject: [PATCH 07/11] Document trainer hill ereader --- include/constants/trainer_hill.h | 5 +- include/ereader_helpers.h | 15 +++-- src/ereader_helpers.c | 97 +++++++++++++++++--------------- src/ereader_screen.c | 2 +- 4 files changed, 62 insertions(+), 57 deletions(-) diff --git a/include/constants/trainer_hill.h b/include/constants/trainer_hill.h index 27357e99c..0e802bba8 100644 --- a/include/constants/trainer_hill.h +++ b/include/constants/trainer_hill.h @@ -37,8 +37,9 @@ #define TRAINER_HILL_TEXT_PLAYER_WON 4 #define TRAINER_HILL_TEXT_AFTER 5 -#define NUM_TRAINER_HILL_TRAINERS (NUM_TRAINER_HILL_FLOORS * 2) -#define NUM_TRAINER_HILL_TRAINERS_JP (NUM_TRAINER_HILL_FLOORS_JP * 2) +#define TRAINER_HILL_TRAINERS_PER_FLOOR 2 +#define NUM_TRAINER_HILL_TRAINERS (NUM_TRAINER_HILL_FLOORS * TRAINER_HILL_TRAINERS_PER_FLOOR) +#define NUM_TRAINER_HILL_TRAINERS_JP (NUM_TRAINER_HILL_FLOORS_JP * TRAINER_HILL_TRAINERS_PER_FLOOR) // Values returned by TrainerHillGetChallengeStatus #define TRAINER_HILL_PLAYER_STATUS_LOST 0 diff --git a/include/ereader_helpers.h b/include/ereader_helpers.h index 7cced65cb..937cfaca1 100755 --- a/include/ereader_helpers.h +++ b/include/ereader_helpers.h @@ -5,24 +5,23 @@ struct EReaderTrainerHillTrainer { - u8 unk0; - struct TrainerHillTrainer unk4; - struct TrHillDisplay unk14C; + u8 trainerNum; + struct TrainerHillTrainer trainer; + struct TrHillDisplay display; u32 checksum; }; // size=0x274 struct EReaderTrainerHillSet { - u8 count; + u8 numTrainers; u8 id; - u16 dummy; u32 checksum; - struct EReaderTrainerHillTrainer unk_8[6]; + struct EReaderTrainerHillTrainer trainers[6]; u8 unk_ec0[40]; }; // size = 0xf00 -bool8 EReader_IsReceivedDataValid(struct EReaderTrainerHillSet *buffer); -bool32 TryWriteTrainerHill(struct EReaderTrainerHillSet *arg0); +bool8 ValidateTrainerHillData(struct EReaderTrainerHillSet *); +bool32 TryWriteTrainerHill(struct EReaderTrainerHillSet *); bool32 ReadTrainerHillAndValidate(void); int EReaderHandleTransfer(u8, size_t, const void *, void *); void EReaderHelper_Timer3Callback(void); diff --git a/src/ereader_helpers.c b/src/ereader_helpers.c index 4db62c847..eef2a15d8 100755 --- a/src/ereader_helpers.c +++ b/src/ereader_helpers.c @@ -14,6 +14,7 @@ #include "constants/trainers.h" #include "constants/moves.h" #include "constants/items.h" +#include "constants/trainer_hill.h" enum { EREADER_XFR_STATE_INIT = 0, @@ -419,127 +420,131 @@ static const struct TrainerHillTrainer sTrainerHillTrainerTemplates_JP[] = { }, }; -static u8 sub_81D38D4(void) +static u8 GetTrainerHillUnkVal(void) { return (gSaveBlock1Ptr->trainerHill.unused + 1) % 256; } -static bool32 Struct_EReaderTrainerHillTrainer_ValidateChecksum(struct EReaderTrainerHillTrainer *arg0) +static bool32 ValidateTrainerChecksum(struct EReaderTrainerHillTrainer * hillTrainer) { - int checksum = CalcByteArraySum((u8 *)arg0, 0x270); - if (checksum != arg0->checksum) + int checksum = CalcByteArraySum((u8 *)hillTrainer, offsetof(typeof(*hillTrainer), checksum)); + if (checksum != hillTrainer->checksum) return FALSE; return TRUE; } -bool8 EReader_IsReceivedDataValid(struct EReaderTrainerHillSet *buffer) +bool8 ValidateTrainerHillData(struct EReaderTrainerHillSet * hillSet) { u32 i; u32 checksum; - int var0 = buffer->count; - if (var0 < 1 || var0 > 8) + int numTrainers = hillSet->numTrainers; + + // Validate number of trainers + if (numTrainers < 1 || numTrainers > NUM_TRAINER_HILL_TRAINERS) return FALSE; - for (i = 0; i < var0; i++) + // Validate trainers + for (i = 0; i < numTrainers; i++) { - if (!Struct_EReaderTrainerHillTrainer_ValidateChecksum(&buffer->unk_8[i])) + if (!ValidateTrainerChecksum(&hillSet->trainers[i])) return FALSE; } - checksum = CalcByteArraySum((u8 *)buffer->unk_8, var0 * sizeof(struct EReaderTrainerHillTrainer)); - if (checksum != buffer->checksum) + // Validate checksum + checksum = CalcByteArraySum((u8 *)hillSet->trainers, numTrainers * sizeof(struct EReaderTrainerHillTrainer)); + if (checksum != hillSet->checksum) return FALSE; return TRUE; } -static bool32 TrainerHill_VerifyChecksum(struct EReaderTrainerHillSet *buffer) +static bool32 ValidateTrainerHillChecksum(struct EReaderTrainerHillSet *hillSet) { u32 checksum; - int var0 = buffer->count; - if (var0 < 1 || var0 > 8) + int numTrainers = hillSet->numTrainers; + if (numTrainers < 1 || numTrainers > NUM_TRAINER_HILL_TRAINERS) return FALSE; - checksum = CalcByteArraySum((u8 *)buffer->unk_8, sizeof(struct EReaderTrainerHillSet) - offsetof(struct EReaderTrainerHillSet, unk_8)); - if (checksum != buffer->checksum) + checksum = CalcByteArraySum((u8 *)hillSet->trainers, sizeof(struct EReaderTrainerHillSet) - offsetof(struct EReaderTrainerHillSet, trainers)); + if (checksum != hillSet->checksum) return FALSE; return TRUE; } -static bool32 TryWriteTrainerHill_r(struct EReaderTrainerHillSet *ttdata, struct TrHillTag *buffer2) +static bool32 TryWriteTrainerHill_Internal(struct EReaderTrainerHillSet * hillSet, struct TrHillTag * hillTag) { int i; - AGB_ASSERT_EX(ttdata->dummy == 0, "cereader_tool.c", 450); - AGB_ASSERT_EX(ttdata->id == 0, "cereader_tool.c", 452); + AGB_ASSERT_EX(hillSet->dummy == 0, "cereader_tool.c", 450); + AGB_ASSERT_EX(hillSet->id == 0, "cereader_tool.c", 452); - memset(buffer2, 0, 0x1000); - buffer2->numTrainers = ttdata->count; - buffer2->unused1 = sub_81D38D4(); - buffer2->numFloors = (ttdata->count + 1) / 2; + memset(hillTag, 0, SECTOR_SIZE); + hillTag->numTrainers = hillSet->numTrainers; + hillTag->unused1 = GetTrainerHillUnkVal(); + hillTag->numFloors = (hillSet->numTrainers + 1) / TRAINER_HILL_TRAINERS_PER_FLOOR; - for (i = 0; i < ttdata->count; i++) + for (i = 0; i < hillSet->numTrainers; i++) { if (!(i & 1)) { - buffer2->floors[i / 2].trainerNum1 = ttdata->unk_8[i].unk0; - buffer2->floors[i / 2].display = ttdata->unk_8[i].unk14C; - buffer2->floors[i / 2].trainers[0] = ttdata->unk_8[i].unk4; + hillTag->floors[i / TRAINER_HILL_TRAINERS_PER_FLOOR].trainerNum1 = hillSet->trainers[i].trainerNum; + hillTag->floors[i / TRAINER_HILL_TRAINERS_PER_FLOOR].display = hillSet->trainers[i].display; + hillTag->floors[i / TRAINER_HILL_TRAINERS_PER_FLOOR].trainers[0] = hillSet->trainers[i].trainer; } else { - buffer2->floors[i / 2].trainerNum2 = ttdata->unk_8[i].unk0; - buffer2->floors[i / 2].trainers[1] = ttdata->unk_8[i].unk4; + hillTag->floors[i / TRAINER_HILL_TRAINERS_PER_FLOOR].trainerNum2 = hillSet->trainers[i].trainerNum; + hillTag->floors[i / TRAINER_HILL_TRAINERS_PER_FLOOR].trainers[1] = hillSet->trainers[i].trainer; } } if (i & 1) { - buffer2->floors[i / 2].trainers[1] = sTrainerHillTrainerTemplates_JP[i / 2]; + hillTag->floors[i / TRAINER_HILL_TRAINERS_PER_FLOOR].trainers[1] = sTrainerHillTrainerTemplates_JP[i / TRAINER_HILL_TRAINERS_PER_FLOOR]; } - buffer2->checksum = CalcByteArraySum((u8 *)buffer2->floors, 4 * sizeof(struct TrHillFloor)); - if (TryWriteSpecialSaveSection(SECTOR_ID_TRAINER_HILL, (u8 *)buffer2) != SAVE_STATUS_OK) + hillTag->checksum = CalcByteArraySum((u8 *)hillTag->floors, NUM_TRAINER_HILL_FLOORS * sizeof(struct TrHillFloor)); + if (TryWriteSpecialSaveSection(SECTOR_ID_TRAINER_HILL, (u8 *)hillTag) != SAVE_STATUS_OK) return FALSE; return TRUE; } -bool32 TryWriteTrainerHill(struct EReaderTrainerHillSet *arg0) +bool32 TryWriteTrainerHill(struct EReaderTrainerHillSet * hillSet) { - void *var0 = AllocZeroed(0x1000); - bool32 result = TryWriteTrainerHill_r(arg0, var0); - Free(var0); + void *buffer = AllocZeroed(SECTOR_SIZE); + bool32 result = TryWriteTrainerHill_Internal(hillSet, buffer); + Free(buffer); return result; } -static bool32 TryReadTrainerHill_r(struct EReaderTrainerHillSet *dst, u8 *buffer) +static bool32 TryReadTrainerHill_Internal(struct EReaderTrainerHillSet * dest, u8 * buffer) { if (TryReadSpecialSaveSection(SECTOR_ID_TRAINER_HILL, buffer) != SAVE_STATUS_OK) return FALSE; - memcpy(dst, buffer, sizeof(struct EReaderTrainerHillSet)); - if (!TrainerHill_VerifyChecksum(dst)) + memcpy(dest, buffer, sizeof(struct EReaderTrainerHillSet)); + if (!ValidateTrainerHillChecksum(dest)) return FALSE; return TRUE; } -static bool32 TryReadTrainerHill(struct EReaderTrainerHillSet *arg0) +static bool32 TryReadTrainerHill(struct EReaderTrainerHillSet * hillSet) { - u8 *var0 = AllocZeroed(0x1000); - bool32 result = TryReadTrainerHill_r(arg0, var0); - Free(var0); + u8 *buffer = AllocZeroed(SECTOR_SIZE); + bool32 result = TryReadTrainerHill_Internal(hillSet, buffer); + Free(buffer); return result; } bool32 ReadTrainerHillAndValidate(void) { - struct EReaderTrainerHillSet *var0 = AllocZeroed(0x1000); - bool32 result = TryReadTrainerHill(var0); - Free(var0); + struct EReaderTrainerHillSet *hillSet = AllocZeroed(SECTOR_SIZE); + bool32 result = TryReadTrainerHill(hillSet); + Free(hillSet); return result; } diff --git a/src/ereader_screen.c b/src/ereader_screen.c index d79b23b93..438c4bec9 100755 --- a/src/ereader_screen.c +++ b/src/ereader_screen.c @@ -401,7 +401,7 @@ static void sub_81D5084(u8 taskId) } break; case 15: - data->unkE = EReader_IsReceivedDataValid((struct EReaderTrainerHillSet *)gDecompressionBuffer); + data->unkE = ValidateTrainerHillData((struct EReaderTrainerHillSet *)gDecompressionBuffer); SetCloseLinkCallbackAndType(data->unkE); data->unk8 = 16; break; From e065c0c28576509f1873d76168618e4e57692f86 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sat, 24 Apr 2021 18:26:25 -0400 Subject: [PATCH 08/11] Label more unused battle anims --- include/battle_anim.h | 4 +-- src/battle_anim_mons.c | 4 +-- src/battle_anim_status_effects.c | 62 ++++++++++++++++---------------- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/include/battle_anim.h b/include/battle_anim.h index 34bd774fe..476480489 100644 --- a/include/battle_anim.h +++ b/include/battle_anim.h @@ -75,8 +75,8 @@ int GetAnimBgAttribute(u8 bgId, u8 attributeId); // battle_anim_mons.c void TranslateSpriteInEllipseOverDuration(struct Sprite *sprite); -void AnimUnused_80A8AEC(struct Sprite *sprite); -void AnimUnused_80A8A6C(struct Sprite *sprite); +void AnimTranslateLinearAndFlicker(struct Sprite *sprite); +void AnimTranslateLinearAndFlicker_Flipped(struct Sprite *sprite); void AnimWeatherBallUp(struct Sprite *sprite); void AnimWeatherBallDown(struct Sprite *sprite); void AnimSpinningSparkle(struct Sprite *sprite); diff --git a/src/battle_anim_mons.c b/src/battle_anim_mons.c index 6fd8cd621..3be8ed23d 100644 --- a/src/battle_anim_mons.c +++ b/src/battle_anim_mons.c @@ -2273,7 +2273,7 @@ u8 CreateInvisibleSpriteCopy(int battlerId, u8 spriteId, int species) return newSpriteId; } -void AnimUnused_80A8A6C(struct Sprite *sprite) +void AnimTranslateLinearAndFlicker_Flipped(struct Sprite *sprite) { SetSpriteCoordsToAnimAttackerCoords(sprite); if (GetBattlerSide(gBattleAnimAttacker)) @@ -2296,7 +2296,7 @@ void AnimUnused_80A8A6C(struct Sprite *sprite) } // Used by three different unused battle anim sprite templates. -void AnimUnused_80A8AEC(struct Sprite *sprite) +void AnimTranslateLinearAndFlicker(struct Sprite *sprite) { if (GetBattlerSide(gBattleAnimAttacker) != B_SIDE_PLAYER) { diff --git a/src/battle_anim_status_effects.c b/src/battle_anim_status_effects.c index e7ef05673..e859bed62 100644 --- a/src/battle_anim_status_effects.c +++ b/src/battle_anim_status_effects.c @@ -26,7 +26,7 @@ static void Task_DoStatusAnimation(u8 taskId); static void AnimFlashingCircleImpact(struct Sprite *sprite); static void AnimFlashingCircleImpact_Step(struct Sprite *sprite); -static const union AnimCmd sAnim_Unused_853EDE4[] = +static const union AnimCmd sAnim_FlickeringOrb[] = { ANIMCMD_FRAME(0, 3), ANIMCMD_FRAME(4, 3), @@ -35,33 +35,33 @@ static const union AnimCmd sAnim_Unused_853EDE4[] = ANIMCMD_JUMP(0) }; -static const union AnimCmd *const sAnims_Unused_853EDF8[] = +static const union AnimCmd *const sAnims_FlickeringOrb[] = { - sAnim_Unused_853EDE4 + sAnim_FlickeringOrb }; // Unused -const struct SpriteTemplate gUnusedSpriteTemplate_0853EDFC = +static const struct SpriteTemplate sFlickeringOrbSpriteTemplate = { .tileTag = ANIM_TAG_ORB, .paletteTag = ANIM_TAG_ORB, .oam = &gOamData_AffineOff_ObjNormal_16x16, - .anims = sAnims_Unused_853EDF8, + .anims = sAnims_FlickeringOrb, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = AnimUnused_80A8AEC, + .callback = AnimTranslateLinearAndFlicker, }; // Unused -const struct SpriteTemplate gUnusedSpriteTemplate_0853EE14 = +static const struct SpriteTemplate sFlickeringOrbFlippedSpriteTemplate = { .tileTag = ANIM_TAG_ORB, .paletteTag = ANIM_TAG_ORB, .oam = &gOamData_AffineOff_ObjNormal_16x16, - .anims = sAnims_Unused_853EDF8, + .anims = sAnims_FlickeringOrb, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = AnimUnused_80A8A6C, + .callback = AnimTranslateLinearAndFlicker_Flipped, }; static const union AnimCmd sAnim_WeatherBallNormal[] = @@ -124,7 +124,7 @@ const struct SpriteTemplate gSpinningSparkleSpriteTemplate = }; // Unused -const struct SpriteTemplate gUnusedSpriteTemplate_0853EE9C = +static const struct SpriteTemplate sFlickeringFootSpriteTemplate = { .tileTag = ANIM_TAG_MONSTER_FOOT, .paletteTag = ANIM_TAG_MONSTER_FOOT, @@ -132,79 +132,79 @@ const struct SpriteTemplate gUnusedSpriteTemplate_0853EE9C = .anims = gDummySpriteAnimTable, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = AnimUnused_80A8AEC, + .callback = AnimTranslateLinearAndFlicker, }; -static const union AnimCmd sAnim_Unused_853EEB4[] = +static const union AnimCmd sAnim_FlickeringImpact_0[] = { ANIMCMD_FRAME(0, 5), ANIMCMD_JUMP(0) }; -static const union AnimCmd sAnim_Unused_853EEBC[] = +static const union AnimCmd sAnim_FlickeringImpact_1[] = { ANIMCMD_FRAME(0, 5), ANIMCMD_JUMP(0) }; -static const union AnimCmd sAnim_Unused_853EEC4[] = +static const union AnimCmd sAnim_FlickeringImpact_2[] = { ANIMCMD_FRAME(0, 5), ANIMCMD_JUMP(0) }; -static const union AnimCmd *const sAnims_Unused_853EECC[] = +static const union AnimCmd *const sAnims_FlickeringImpact[] = { - sAnim_Unused_853EEB4, - sAnim_Unused_853EEBC, - sAnim_Unused_853EEC4, + sAnim_FlickeringImpact_0, + sAnim_FlickeringImpact_1, + sAnim_FlickeringImpact_2, }; // Unused -const struct SpriteTemplate gUnusedSpriteTemplate_0853EED8 = +static const struct SpriteTemplate sFlickeringImpactSpriteTemplate = { .tileTag = ANIM_TAG_IMPACT, .paletteTag = ANIM_TAG_IMPACT, .oam = &gOamData_AffineOff_ObjNormal_32x32, - .anims = sAnims_Unused_853EECC, + .anims = sAnims_FlickeringImpact, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = AnimUnused_80A8AEC, + .callback = AnimTranslateLinearAndFlicker, }; -static const union AnimCmd sAnim_Unused_853EEF0[] = +static const union AnimCmd sAnim_FlickeringShrinkOrb[] = { ANIMCMD_FRAME(0, 15), ANIMCMD_JUMP(0) }; -static const union AnimCmd *const sAnims_Unused_853EEF8[] = +static const union AnimCmd *const sAnims_FlickeringShrinkOrb[] = { - sAnim_Unused_853EEF0 + sAnim_FlickeringShrinkOrb }; -static const union AffineAnimCmd sAffineAnim_Unused_853EEFC[] = +static const union AffineAnimCmd sAffineAnim_FlickeringShrinkOrb[] = { AFFINEANIMCMD_FRAME(96, 96, 0, 0), AFFINEANIMCMD_FRAME(2, 2, 0, 1), AFFINEANIMCMD_JUMP(1) }; -static const union AffineAnimCmd *const sAffineAnims_Unused_853EEF8[] = +static const union AffineAnimCmd *const sAffineAnims_FlickeringShrinkOrb[] = { - sAffineAnim_Unused_853EEFC + sAffineAnim_FlickeringShrinkOrb }; // Unused -const struct SpriteTemplate gUnusedSpriteTemplate_0853EF18 = +static const struct SpriteTemplate sFlickeringShrinkOrbSpriteTemplate = { .tileTag = ANIM_TAG_ORB, .paletteTag = ANIM_TAG_ORB, .oam = &gOamData_AffineDouble_ObjNormal_16x16, - .anims = sAnims_Unused_853EEF8, + .anims = sAnims_FlickeringShrinkOrb, .images = NULL, - .affineAnims = sAffineAnims_Unused_853EEF8, - .callback = AnimUnused_80A8A6C, + .affineAnims = sAffineAnims_FlickeringShrinkOrb, + .callback = AnimTranslateLinearAndFlicker_Flipped, }; static const struct Subsprite sFrozenIceCubeSubsprites[] = From bee60f4c64e6cdf2bfa3777b59067ff63450e4e3 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sat, 24 Apr 2021 23:29:49 -0400 Subject: [PATCH 09/11] Document battler sprite affine anims, default pokeball throw --- include/data.h | 10 ++- src/battle_anim_effects_3.c | 8 +- src/battle_anim_mons.c | 4 +- src/battle_anim_throw.c | 5 +- src/contest.c | 4 +- src/data.c | 162 ++++++++++++++++++---------------- src/egg_hatch.c | 2 +- src/pokeball.c | 100 +++++++++++---------- src/pokemon.c | 4 +- src/trainer_pokemon_sprites.c | 2 +- 10 files changed, 158 insertions(+), 143 deletions(-) diff --git a/include/data.h b/include/data.h index 2f8c44746..f94f55a8f 100644 --- a/include/data.h +++ b/include/data.h @@ -5,6 +5,12 @@ #define SPECIES_SHINY_TAG 500 +enum { + BATTLER_AFFINE_NORMAL, + BATTLER_AFFINE_EMERGE, + BATTLER_AFFINE_RETURN, +}; + struct MonCoords { // This would use a bitfield, but some function @@ -87,9 +93,9 @@ extern const struct SpriteFrameImage gTrainerBackPicTable_Steven[]; extern const union AffineAnimCmd *const gAffineAnims_BattleSpritePlayerSide[]; extern const union AffineAnimCmd *const gAffineAnims_BattleSpriteOpponentSide[]; -extern const union AffineAnimCmd *const gUnknown_082FF6C0[]; +extern const union AffineAnimCmd *const gAffineAnims_BattleSpriteContest[]; -extern const union AnimCmd *const gUnknown_082FF70C[]; +extern const union AnimCmd *const gAnims_MonPic[]; extern const struct MonCoords gMonFrontPicCoords[]; extern const struct CompressedSpriteSheet gMonStillFrontPicTable[]; extern const struct MonCoords gMonBackPicCoords[]; diff --git a/src/battle_anim_effects_3.c b/src/battle_anim_effects_3.c index 800431c6a..5aaf45f19 100755 --- a/src/battle_anim_effects_3.c +++ b/src/battle_anim_effects_3.c @@ -2319,11 +2319,11 @@ void AnimTask_TransformMon(u8 taskId) } if (IsSpeciesNotUnown(gContestResources->moveAnim->targetSpecies)) - gSprites[gBattlerSpriteIds[gBattleAnimAttacker]].affineAnims = gUnknown_082FF6C0; + gSprites[gBattlerSpriteIds[gBattleAnimAttacker]].affineAnims = gAffineAnims_BattleSpriteContest; else gSprites[gBattlerSpriteIds[gBattleAnimAttacker]].affineAnims = gAffineAnims_BattleSpriteOpponentSide; - StartSpriteAffineAnim(&gSprites[gBattlerSpriteIds[gBattleAnimAttacker]], 0); + StartSpriteAffineAnim(&gSprites[gBattlerSpriteIds[gBattleAnimAttacker]], BATTLER_AFFINE_NORMAL); } gTasks[taskId].data[0]++; @@ -4733,8 +4733,8 @@ void AnimTask_MonToSubstitute(u8 taskId) LoadBattleMonGfxAndAnimate(gBattleAnimAttacker, 0, spriteId); if (IsContest()) { - gSprites[gBattlerSpriteIds[gBattleAnimAttacker]].affineAnims = gUnknown_082FF6C0; - StartSpriteAffineAnim(&gSprites[gBattlerSpriteIds[gBattleAnimAttacker]], 0); + gSprites[gBattlerSpriteIds[gBattleAnimAttacker]].affineAnims = gAffineAnims_BattleSpriteContest; + StartSpriteAffineAnim(&gSprites[gBattlerSpriteIds[gBattleAnimAttacker]], BATTLER_AFFINE_NORMAL); } for (i = 0; i < NUM_TASK_DATA; i++) diff --git a/src/battle_anim_mons.c b/src/battle_anim_mons.c index 6fd8cd621..6dc0a0271 100644 --- a/src/battle_anim_mons.c +++ b/src/battle_anim_mons.c @@ -2078,8 +2078,8 @@ u8 CreateAdditionalMonSpriteForMoveAnim(u16 species, bool8 isBackpic, u8 id, s16 if (IsContest()) { - gSprites[spriteId].affineAnims = gUnknown_082FF6C0; - StartSpriteAffineAnim(&gSprites[spriteId], 0); + gSprites[spriteId].affineAnims = gAffineAnims_BattleSpriteContest; + StartSpriteAffineAnim(&gSprites[spriteId], BATTLER_AFFINE_NORMAL); } return spriteId; } diff --git a/src/battle_anim_throw.c b/src/battle_anim_throw.c index f6a48cf69..83768b476 100755 --- a/src/battle_anim_throw.c +++ b/src/battle_anim_throw.c @@ -16,6 +16,7 @@ #include "task.h" #include "trig.h" #include "util.h" +#include "data.h" #include "constants/items.h" #include "constants/moves.h" #include "constants/songs.h" @@ -1471,7 +1472,7 @@ static void SpriteCB_Ball_Release_Step(struct Sprite *sprite) // Animate Pokémon emerging from Poké Ball gSprites[gBattlerSpriteIds[gBattleAnimTarget]].invisible = FALSE; - StartSpriteAffineAnim(&gSprites[gBattlerSpriteIds[gBattleAnimTarget]], 1); + StartSpriteAffineAnim(&gSprites[gBattlerSpriteIds[gBattleAnimTarget]], BATTLER_AFFINE_EMERGE); AnimateSprite(&gSprites[gBattlerSpriteIds[gBattleAnimTarget]]); gSprites[gBattlerSpriteIds[gBattleAnimTarget]].sOffsetY = 4096; } @@ -1485,7 +1486,7 @@ static void SpriteCB_Ball_Release_Wait(struct Sprite *sprite) if (gSprites[gBattlerSpriteIds[gBattleAnimTarget]].affineAnimEnded) { - StartSpriteAffineAnim(&gSprites[gBattlerSpriteIds[gBattleAnimTarget]], 0); + StartSpriteAffineAnim(&gSprites[gBattlerSpriteIds[gBattleAnimTarget]], BATTLER_AFFINE_NORMAL); released = TRUE; } else diff --git a/src/contest.c b/src/contest.c index 246fc1e50..0d2d66a66 100644 --- a/src/contest.c +++ b/src/contest.c @@ -3133,10 +3133,10 @@ static u8 CreateContestantSprite(u16 species, u32 otId, u32 personality, u32 ind gSprites[spriteId].data[0] = gSprites[spriteId].oam.paletteNum; gSprites[spriteId].data[2] = species; if (IsSpeciesNotUnown(species)) - gSprites[spriteId].affineAnims = gUnknown_082FF6C0; + gSprites[spriteId].affineAnims = gAffineAnims_BattleSpriteContest; else gSprites[spriteId].affineAnims = gAffineAnims_BattleSpriteOpponentSide; - StartSpriteAffineAnim(gSprites + spriteId, 0); + StartSpriteAffineAnim(&gSprites[spriteId], BATTLER_AFFINE_NORMAL); return spriteId; } diff --git a/src/data.c b/src/data.c index 30672f7c4..d300d4f63 100644 --- a/src/data.c +++ b/src/data.c @@ -124,172 +124,178 @@ static const union AnimCmd sAnim_GeneralFrame3[] = ANIMCMD_END, }; -static const union AffineAnimCmd gUnknown_082FF548[] = +// Many of these affine anims seem to go unused, and +// instead SetSpriteRotScale is used to manipulate +// the battler sprites directly (for instance, in AnimTask_SwitchOutShrinkMon). +// Those with explicit indexes are referenced elsewhere. + +static const union AffineAnimCmd sAffineAnim_Battler_Normal[] = { - AFFINEANIMCMD_FRAME(0x0100, 0x0100, 0x00, 0x00), + AFFINEANIMCMD_FRAME(0x100, 0x100, 0, 0), AFFINEANIMCMD_END, }; -static const union AffineAnimCmd gUnknown_082FF558[] = +static const union AffineAnimCmd sAffineAnim_Battler_Flipped[] = { - AFFINEANIMCMD_FRAME(0xff00, 0x0100, 0x00, 0x00), + AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0), AFFINEANIMCMD_END, }; -static const union AffineAnimCmd gUnknown_082FF568[] = +static const union AffineAnimCmd sAffineAnim_Battler_Emerge[] = { - AFFINEANIMCMD_FRAME(0x0028, 0x0028, 0x00, 0x00), - AFFINEANIMCMD_FRAME(0x0012, 0x0012, 0x00, 0x0c), + AFFINEANIMCMD_FRAME(0x28, 0x28, 0, 0), + AFFINEANIMCMD_FRAME(0x12, 0x12, 0, 12), AFFINEANIMCMD_END, }; -static const union AffineAnimCmd gUnknown_082FF580[] = +static const union AffineAnimCmd sAffineAnim_Battler_Return[] = { - AFFINEANIMCMD_FRAME(0xfffe, 0xfffe, 0x00, 0x12), - AFFINEANIMCMD_FRAME(0xfff0, 0xfff0, 0x00, 0x0f), + AFFINEANIMCMD_FRAME( -0x2, -0x2, 0, 18), + AFFINEANIMCMD_FRAME(-0x10, -0x10, 0, 15), AFFINEANIMCMD_END, }; -static const union AffineAnimCmd gUnknown_082FF598[] = +static const union AffineAnimCmd sAffineAnim_Battler_HorizontalSquishLoop[] = { - AFFINEANIMCMD_FRAME(0x00a0, 0x0100, 0x00, 0x00), - AFFINEANIMCMD_FRAME(0x0004, 0x0000, 0x00, 0x08), - AFFINEANIMCMD_FRAME(0xfffc, 0x0000, 0x00, 0x08), + AFFINEANIMCMD_FRAME(0xA0, 0x100, 0, 0), + AFFINEANIMCMD_FRAME( 0x4, 0x0, 0, 8), + AFFINEANIMCMD_FRAME(-0x4, 0x0, 0, 8), AFFINEANIMCMD_JUMP(1), }; -static const union AffineAnimCmd gUnknown_082FF5B8[] = +static const union AffineAnimCmd sAffineAnim_Battler_Grow[] = { - AFFINEANIMCMD_FRAME(0x0002, 0x0002, 0x00, 0x14), + AFFINEANIMCMD_FRAME(0x2, 0x2, 0, 20), AFFINEANIMCMD_END, }; -static const union AffineAnimCmd gUnknown_082FF5C8[] = +static const union AffineAnimCmd sAffineAnim_Battler_Shrink[] = { - AFFINEANIMCMD_FRAME(0xfffe, 0xfffe, 0x00, 0x14), + AFFINEANIMCMD_FRAME(-0x2, -0x2, 0, 20), AFFINEANIMCMD_END, }; -static const union AffineAnimCmd gUnknown_082FF5D8[] = +static const union AffineAnimCmd sAffineAnim_Battler_BigToSmall[] = { - AFFINEANIMCMD_FRAME(0x0100, 0x0100, 0x00, 0000), - AFFINEANIMCMD_FRAME(0xfff0, 0xfff0, 0x00, 0x09), + AFFINEANIMCMD_FRAME(0x100, 0x100, 0, 0), + AFFINEANIMCMD_FRAME(-0x10, -0x10, 0, 9), AFFINEANIMCMD_END, }; -static const union AffineAnimCmd gUnknown_082FF5F0[] = +static const union AffineAnimCmd sAffineAnim_Battler_GrowLarge[] = { - AFFINEANIMCMD_FRAME(0x0004, 0x0004, 0x00, 0x3f), + AFFINEANIMCMD_FRAME(0x4, 0x4, 0, 63), AFFINEANIMCMD_END, }; -static const union AffineAnimCmd gUnknown_082FF600[] = +static const union AffineAnimCmd sAffineAnim_Battler_TipRight[] = { - AFFINEANIMCMD_FRAME(0x0000, 0x0000, 0xfd, 0x05), - AFFINEANIMCMD_FRAME(0x0000, 0x0000, 0x03, 0x05), + AFFINEANIMCMD_FRAME(0x0, 0x0, -3, 5), + AFFINEANIMCMD_FRAME(0x0, 0x0, 3, 5), AFFINEANIMCMD_END, }; const union AffineAnimCmd *const gAffineAnims_BattleSpritePlayerSide[] = { - gUnknown_082FF548, - gUnknown_082FF568, - gUnknown_082FF580, - gUnknown_082FF598, - gUnknown_082FF5B8, - gUnknown_082FF5C8, - gUnknown_082FF5F0, - gUnknown_082FF600, - gUnknown_082FF5D8, + [BATTLER_AFFINE_NORMAL] = sAffineAnim_Battler_Normal, + [BATTLER_AFFINE_EMERGE] = sAffineAnim_Battler_Emerge, + [BATTLER_AFFINE_RETURN] = sAffineAnim_Battler_Return, + sAffineAnim_Battler_HorizontalSquishLoop, + sAffineAnim_Battler_Grow, + sAffineAnim_Battler_Shrink, + sAffineAnim_Battler_GrowLarge, + sAffineAnim_Battler_TipRight, + sAffineAnim_Battler_BigToSmall, }; -static const union AffineAnimCmd gUnknown_082FF63C[] = +static const union AffineAnimCmd sAffineAnim_Battler_SpinShrink[] = { - AFFINEANIMCMD_FRAME(0xfffc, 0xfffc, 0x04, 0x3f), + AFFINEANIMCMD_FRAME(-0x4, -0x4, 4, 63), AFFINEANIMCMD_END, }; -static const union AffineAnimCmd gUnknown_082FF64C[] = +static const union AffineAnimCmd sAffineAnim_Battler_TipLeft[] = { - AFFINEANIMCMD_FRAME(0x0000, 0x0000, 0x03, 0x05), - AFFINEANIMCMD_FRAME(0x0000, 0x0000, 0xfd, 0x05), + AFFINEANIMCMD_FRAME(0x0, 0x0, 3, 5), + AFFINEANIMCMD_FRAME(0x0, 0x0, -3, 5), AFFINEANIMCMD_END, }; -static const union AffineAnimCmd gUnknown_082FF664[] = +static const union AffineAnimCmd sAffineAnim_Battler_RotateUpAndBack[] = { - AFFINEANIMCMD_FRAME(0x0000, 0x0000, 0xfb, 0x14), - AFFINEANIMCMD_FRAME(0x0000, 0x0000, 0x00, 0x14), - AFFINEANIMCMD_FRAME(0x0000, 0x0000, 0x05, 0x14), + AFFINEANIMCMD_FRAME(0x0, 0x0, -5, 20), + AFFINEANIMCMD_FRAME(0x0, 0x0, 0, 20), + AFFINEANIMCMD_FRAME(0x0, 0x0, 5, 20), AFFINEANIMCMD_END, }; -static const union AffineAnimCmd gUnknown_082FF684[] = +static const union AffineAnimCmd sAffineAnim_Battler_Spin[] = { - AFFINEANIMCMD_FRAME(0x0000, 0x0000, 0x09, 0x6e), + AFFINEANIMCMD_FRAME(0x0, 0x0, 9, 110), AFFINEANIMCMD_END, }; const union AffineAnimCmd *const gAffineAnims_BattleSpriteOpponentSide[] = { - gUnknown_082FF548, - gUnknown_082FF568, - gUnknown_082FF580, - gUnknown_082FF598, - gUnknown_082FF5B8, - gUnknown_082FF5C8, - gUnknown_082FF63C, - gUnknown_082FF64C, - gUnknown_082FF664, - gUnknown_082FF5D8, - gUnknown_082FF684, + [BATTLER_AFFINE_NORMAL] = sAffineAnim_Battler_Normal, + [BATTLER_AFFINE_EMERGE] = sAffineAnim_Battler_Emerge, + [BATTLER_AFFINE_RETURN] = sAffineAnim_Battler_Return, + sAffineAnim_Battler_HorizontalSquishLoop, + sAffineAnim_Battler_Grow, + sAffineAnim_Battler_Shrink, + sAffineAnim_Battler_SpinShrink, + sAffineAnim_Battler_TipLeft, + sAffineAnim_Battler_RotateUpAndBack, + sAffineAnim_Battler_BigToSmall, + sAffineAnim_Battler_Spin, }; -const union AffineAnimCmd *const gUnknown_082FF6C0[] = +const union AffineAnimCmd *const gAffineAnims_BattleSpriteContest[] = { - gUnknown_082FF558, - gUnknown_082FF568, - gUnknown_082FF580, - gUnknown_082FF598, - gUnknown_082FF5B8, - gUnknown_082FF5C8, - gUnknown_082FF63C, - gUnknown_082FF64C, - gUnknown_082FF664, - gUnknown_082FF5D8, - gUnknown_082FF684, + [BATTLER_AFFINE_NORMAL] = sAffineAnim_Battler_Flipped, + [BATTLER_AFFINE_EMERGE] = sAffineAnim_Battler_Emerge, + [BATTLER_AFFINE_RETURN] = sAffineAnim_Battler_Return, + sAffineAnim_Battler_HorizontalSquishLoop, + sAffineAnim_Battler_Grow, + sAffineAnim_Battler_Shrink, + sAffineAnim_Battler_SpinShrink, + sAffineAnim_Battler_TipLeft, + sAffineAnim_Battler_RotateUpAndBack, + sAffineAnim_Battler_BigToSmall, + sAffineAnim_Battler_Spin, }; -static const union AnimCmd gUnknown_082FF6EC[] = + +static const union AnimCmd sAnim_MonPic_0[] = { ANIMCMD_FRAME(0, 0), ANIMCMD_END, }; -static const union AnimCmd gUnknown_082FF6F4[] = +static const union AnimCmd sAnim_MonPic_1[] = { ANIMCMD_FRAME(1, 0), ANIMCMD_END, }; -static const union AnimCmd gUnknown_082FF6FC[] = +static const union AnimCmd sAnim_MonPic_2[] = { ANIMCMD_FRAME(2, 0), ANIMCMD_END, }; -static const union AnimCmd gUnknown_082FF704[] = +static const union AnimCmd sAnim_MonPic_3[] = { ANIMCMD_FRAME(3, 0), ANIMCMD_END, }; -const union AnimCmd *const gUnknown_082FF70C[] = +const union AnimCmd *const gAnims_MonPic[] = { - gUnknown_082FF6EC, - gUnknown_082FF6F4, - gUnknown_082FF6FC, - gUnknown_082FF704, + sAnim_MonPic_0, + sAnim_MonPic_1, + sAnim_MonPic_2, + sAnim_MonPic_3, }; #define SPECIES_SPRITE(species, sprite) [SPECIES_##species] = {sprite, MON_PIC_SIZE, SPECIES_##species} diff --git a/src/egg_hatch.c b/src/egg_hatch.c index 0ae0e1323..f2d28e916 100644 --- a/src/egg_hatch.c +++ b/src/egg_hatch.c @@ -811,7 +811,7 @@ static void SpriteCB_Egg_5(struct Sprite* sprite) if (sprite->data[0] == 0) { gSprites[sEggHatchData->pokeSpriteID].invisible = FALSE; - StartSpriteAffineAnim(&gSprites[sEggHatchData->pokeSpriteID], 1); + StartSpriteAffineAnim(&gSprites[sEggHatchData->pokeSpriteID], BATTLER_AFFINE_EMERGE); } if (sprite->data[0] == 8) BeginNormalPaletteFade(PALETTES_ALL, -1, 0x10, 0, RGB_WHITEALPHA); diff --git a/src/pokeball.c b/src/pokeball.c index 77d2b119c..3671e6a35 100644 --- a/src/pokeball.c +++ b/src/pokeball.c @@ -12,28 +12,29 @@ #include "task.h" #include "trig.h" #include "util.h" +#include "data.h" #include "constants/songs.h" extern struct MusicPlayerInfo gMPlayInfo_BGM; // this file's functions static void Task_DoPokeballSendOutAnim(u8 taskId); -static void SpriteCB_TestBallThrow(struct Sprite *sprite); static void SpriteCB_PlayerMonSendOut_1(struct Sprite *sprite); static void SpriteCB_PlayerMonSendOut_2(struct Sprite *sprite); static void SpriteCB_OpponentMonSendOut(struct Sprite *sprite); -static void sub_80756D4(struct Sprite *sprite); -static void sub_80756E0(struct Sprite *sprite); -static void sub_807574C(struct Sprite *sprite); -static void sub_80757E4(struct Sprite *sprite); -static void sub_8075838(struct Sprite *sprite); -static void sub_8075930(struct Sprite *sprite); +static void SpriteCB_BallThrow(struct Sprite *sprite); +static void SpriteCB_BallThrow_ReachMon(struct Sprite *sprite); +static void SpriteCB_BallThrow_StartShrinkMon(struct Sprite *sprite); +static void SpriteCB_BallThrow_ShrinkMon(struct Sprite *sprite); +static void SpriteCB_BallThrow_Close(struct Sprite *sprite); +static void SpriteCB_BallThrow_FallToGround(struct Sprite *sprite); +static void SpriteCB_BallThrow_StartShakes(struct Sprite *sprite); +static void SpriteCB_BallThrow_Shake(struct Sprite *sprite); +static void SpriteCB_BallThrow_StartCaptureMon(struct Sprite *sprite); +static void SpriteCB_BallThrow_CaptureMon(struct Sprite *sprite); static void SpriteCB_ReleaseMonFromBall(struct Sprite *sprite); static void SpriteCB_ReleaseMon2FromBall(struct Sprite *sprite); -static void sub_8075970(struct Sprite *sprite); static void HandleBallAnimEnd(struct Sprite *sprite); -static void sub_8075FB4(struct Sprite *sprite); -static void sub_80760F8(struct Sprite *sprite); static void SpriteCB_PokeballReleaseMon(struct Sprite *sprite); static void SpriteCB_ReleasedMonFlyOut(struct Sprite *sprite); static void SpriteCB_TradePokeball(struct Sprite *sprite); @@ -213,7 +214,7 @@ const struct SpriteTemplate gBallSpriteTemplates[POKEBALL_COUNT] = .anims = sBallAnimSequences, .images = NULL, .affineAnims = sAffineAnim_BallRotate, - .callback = SpriteCB_TestBallThrow, + .callback = SpriteCB_BallThrow, }, { .tileTag = GFX_TAG_GREATBALL, @@ -222,7 +223,7 @@ const struct SpriteTemplate gBallSpriteTemplates[POKEBALL_COUNT] = .anims = sBallAnimSequences, .images = NULL, .affineAnims = sAffineAnim_BallRotate, - .callback = SpriteCB_TestBallThrow, + .callback = SpriteCB_BallThrow, }, { .tileTag = GFX_TAG_SAFARIBALL, @@ -231,7 +232,7 @@ const struct SpriteTemplate gBallSpriteTemplates[POKEBALL_COUNT] = .anims = sBallAnimSequences, .images = NULL, .affineAnims = sAffineAnim_BallRotate, - .callback = SpriteCB_TestBallThrow, + .callback = SpriteCB_BallThrow, }, { .tileTag = GFX_TAG_ULTRABALL, @@ -240,7 +241,7 @@ const struct SpriteTemplate gBallSpriteTemplates[POKEBALL_COUNT] = .anims = sBallAnimSequences, .images = NULL, .affineAnims = sAffineAnim_BallRotate, - .callback = SpriteCB_TestBallThrow, + .callback = SpriteCB_BallThrow, }, { .tileTag = GFX_TAG_MASTERBALL, @@ -249,7 +250,7 @@ const struct SpriteTemplate gBallSpriteTemplates[POKEBALL_COUNT] = .anims = sBallAnimSequences, .images = NULL, .affineAnims = sAffineAnim_BallRotate, - .callback = SpriteCB_TestBallThrow, + .callback = SpriteCB_BallThrow, }, { .tileTag = GFX_TAG_NETBALL, @@ -258,7 +259,7 @@ const struct SpriteTemplate gBallSpriteTemplates[POKEBALL_COUNT] = .anims = sBallAnimSequences, .images = NULL, .affineAnims = sAffineAnim_BallRotate, - .callback = SpriteCB_TestBallThrow, + .callback = SpriteCB_BallThrow, }, { .tileTag = GFX_TAG_DIVEBALL, @@ -267,7 +268,7 @@ const struct SpriteTemplate gBallSpriteTemplates[POKEBALL_COUNT] = .anims = sBallAnimSequences, .images = NULL, .affineAnims = sAffineAnim_BallRotate, - .callback = SpriteCB_TestBallThrow, + .callback = SpriteCB_BallThrow, }, { .tileTag = GFX_TAG_NESTBALL, @@ -276,7 +277,7 @@ const struct SpriteTemplate gBallSpriteTemplates[POKEBALL_COUNT] = .anims = sBallAnimSequences, .images = NULL, .affineAnims = sAffineAnim_BallRotate, - .callback = SpriteCB_TestBallThrow, + .callback = SpriteCB_BallThrow, }, { .tileTag = GFX_TAG_REPEATBALL, @@ -285,7 +286,7 @@ const struct SpriteTemplate gBallSpriteTemplates[POKEBALL_COUNT] = .anims = sBallAnimSequences, .images = NULL, .affineAnims = sAffineAnim_BallRotate, - .callback = SpriteCB_TestBallThrow, + .callback = SpriteCB_BallThrow, }, { .tileTag = GFX_TAG_TIMERBALL, @@ -294,7 +295,7 @@ const struct SpriteTemplate gBallSpriteTemplates[POKEBALL_COUNT] = .anims = sBallAnimSequences, .images = NULL, .affineAnims = sAffineAnim_BallRotate, - .callback = SpriteCB_TestBallThrow, + .callback = SpriteCB_BallThrow, }, { .tileTag = GFX_TAG_LUXURYBALL, @@ -303,7 +304,7 @@ const struct SpriteTemplate gBallSpriteTemplates[POKEBALL_COUNT] = .anims = sBallAnimSequences, .images = NULL, .affineAnims = sAffineAnim_BallRotate, - .callback = SpriteCB_TestBallThrow, + .callback = SpriteCB_BallThrow, }, { .tileTag = GFX_TAG_PREMIERBALL, @@ -312,7 +313,7 @@ const struct SpriteTemplate gBallSpriteTemplates[POKEBALL_COUNT] = .anims = sBallAnimSequences, .images = NULL, .affineAnims = sAffineAnim_BallRotate, - .callback = SpriteCB_TestBallThrow, + .callback = SpriteCB_BallThrow, }, }; @@ -408,7 +409,10 @@ static void Task_DoPokeballSendOutAnim(u8 taskId) PlaySE(SE_BALL_THROW); } -static void SpriteCB_TestBallThrow(struct Sprite *sprite) +// This sequence of functions is very similar to those that get run when +// a Pokéball gets thrown at a wild Pokémon, starting at SpriteCB_Ball_Arc. +// These do not seem to get run. +static void SpriteCB_BallThrow(struct Sprite *sprite) { if (TranslateAnimHorizontalArc(sprite)) { @@ -430,7 +434,7 @@ static void SpriteCB_TestBallThrow(struct Sprite *sprite) sprite->sBattler = opponentBattler; sprite->data[7] = noOfShakes; DestroyTask(taskId); - sprite->callback = sub_80756D4; + sprite->callback = SpriteCB_BallThrow_ReachMon; } } @@ -440,26 +444,24 @@ static void SpriteCB_TestBallThrow(struct Sprite *sprite) #undef tBattler #undef tOpponentBattler -static void sub_80756D4(struct Sprite *sprite) +static void SpriteCB_BallThrow_ReachMon(struct Sprite *sprite) { - sprite->callback = sub_80756E0; + sprite->callback = SpriteCB_BallThrow_StartShrinkMon; } -// Start something for battler -static void sub_80756E0(struct Sprite *sprite) +static void SpriteCB_BallThrow_StartShrinkMon(struct Sprite *sprite) { if (++sprite->data[5] == 10) { sprite->data[5] = 0; - sprite->callback = sub_807574C; - StartSpriteAffineAnim(&gSprites[gBattlerSpriteIds[sprite->sBattler]], 2); + sprite->callback = SpriteCB_BallThrow_ShrinkMon; + StartSpriteAffineAnim(&gSprites[gBattlerSpriteIds[sprite->sBattler]], BATTLER_AFFINE_RETURN); AnimateSprite(&gSprites[gBattlerSpriteIds[sprite->sBattler]]); gSprites[gBattlerSpriteIds[sprite->sBattler]].data[1] = 0; } } -// Shrink player -static void sub_807574C(struct Sprite *sprite) +static void SpriteCB_BallThrow_ShrinkMon(struct Sprite *sprite) { sprite->data[5]++; if (sprite->data[5] == 11) @@ -469,7 +471,7 @@ static void sub_807574C(struct Sprite *sprite) StartSpriteAnim(sprite, 2); gSprites[gBattlerSpriteIds[sprite->sBattler]].invisible = TRUE; sprite->data[5] = 0; - sprite->callback = sub_80757E4; + sprite->callback = SpriteCB_BallThrow_Close; } else { @@ -478,7 +480,7 @@ static void sub_807574C(struct Sprite *sprite) } } -static void sub_80757E4(struct Sprite *sprite) +static void SpriteCB_BallThrow_Close(struct Sprite *sprite) { if (sprite->animEnded) { @@ -490,12 +492,12 @@ static void sub_80757E4(struct Sprite *sprite) sprite->data[5] = 0; sprite->pos1.y += Cos(0, 32); sprite->pos2.y = -Cos(0, sprite->data[4]); - sprite->callback = sub_8075838; + sprite->callback = SpriteCB_BallThrow_FallToGround; } } } -static void sub_8075838(struct Sprite *sprite) +static void SpriteCB_BallThrow_FallToGround(struct Sprite *sprite) { bool8 r5 = FALSE; @@ -548,14 +550,14 @@ static void sub_8075838(struct Sprite *sprite) } else { - sprite->callback = sub_8075930; + sprite->callback = SpriteCB_BallThrow_StartShakes; sprite->data[4] = 1; sprite->data[5] = 0; } } } -static void sub_8075930(struct Sprite *sprite) +static void SpriteCB_BallThrow_StartShakes(struct Sprite *sprite) { sprite->data[3]++; if (sprite->data[3] == 31) @@ -563,12 +565,12 @@ static void sub_8075930(struct Sprite *sprite) sprite->data[3] = 0; sprite->affineAnimPaused = TRUE; StartSpriteAffineAnim(sprite, 1); - sprite->callback = sub_8075970; + sprite->callback = SpriteCB_BallThrow_Shake; PlaySE(SE_BALL); } } -static void sub_8075970(struct Sprite *sprite) +static void SpriteCB_BallThrow_Shake(struct Sprite *sprite) { switch (sprite->data[3] & 0xFF) { @@ -611,7 +613,7 @@ static void sub_8075970(struct Sprite *sprite) { if (sprite->data[7] == 4 && sprite->data[3] >> 8 == 3) { - sprite->callback = sub_8075FB4; + sprite->callback = SpriteCB_BallThrow_StartCaptureMon; sprite->affineAnimPaused = TRUE; } else @@ -796,7 +798,7 @@ static void SpriteCB_ReleaseMonFromBall(struct Sprite *sprite) gTasks[taskId].tCryTaskState = 0; } - StartSpriteAffineAnim(&gSprites[gBattlerSpriteIds[sprite->sBattler]], 1); + StartSpriteAffineAnim(&gSprites[gBattlerSpriteIds[sprite->sBattler]], BATTLER_AFFINE_EMERGE); if (GetBattlerSide(sprite->sBattler) == B_SIDE_OPPONENT) gSprites[gBattlerSpriteIds[sprite->sBattler]].callback = SpriteCb_OpponentMonFromBall; @@ -817,10 +819,10 @@ static void SpriteCB_ReleaseMonFromBall(struct Sprite *sprite) #undef tCryTaskFrames #undef tCryTaskState -static void sub_8075FB4(struct Sprite *sprite) +static void SpriteCB_BallThrow_StartCaptureMon(struct Sprite *sprite) { sprite->animPaused = TRUE; - sprite->callback = sub_80760F8; + sprite->callback = SpriteCB_BallThrow_CaptureMon; sprite->data[3] = 0; sprite->data[4] = 0; sprite->data[5] = 0; @@ -836,7 +838,7 @@ static void HandleBallAnimEnd(struct Sprite *sprite) sprite->invisible = TRUE; if (gSprites[gBattlerSpriteIds[battlerId]].affineAnimEnded) { - StartSpriteAffineAnim(&gSprites[gBattlerSpriteIds[battlerId]], 0); + StartSpriteAffineAnim(&gSprites[gBattlerSpriteIds[battlerId]], BATTLER_AFFINE_NORMAL); affineAnimEnded = TRUE; } else @@ -867,7 +869,7 @@ static void HandleBallAnimEnd(struct Sprite *sprite) } } -static void sub_80760F8(struct Sprite *sprite) +static void SpriteCB_BallThrow_CaptureMon(struct Sprite *sprite) { u8 battlerId = sprite->sBattler; @@ -1042,7 +1044,7 @@ static void SpriteCB_PokeballReleaseMon(struct Sprite *sprite) sprite->data[1] = LaunchBallFadeMonTaskForPokeball(1, battlerId, r4); sprite->callback = SpriteCB_ReleasedMonFlyOut; gSprites[r7].invisible = FALSE; - StartSpriteAffineAnim(&gSprites[r7], 1); + StartSpriteAffineAnim(&gSprites[r7], BATTLER_AFFINE_EMERGE); AnimateSprite(&gSprites[r7]); gSprites[r7].data[1] = 0x1000; sprite->data[7] = 0; @@ -1065,7 +1067,7 @@ static void SpriteCB_ReleasedMonFlyOut(struct Sprite *sprite) sprite->invisible = TRUE; if (gSprites[monSpriteId].affineAnimEnded) { - StartSpriteAffineAnim(&gSprites[monSpriteId], 0); + StartSpriteAffineAnim(&gSprites[monSpriteId], BATTLER_AFFINE_NORMAL); r12 = TRUE; } var1 = (sprite->data[5] - sprite->pos1.x) * sprite->data[7] / 128 + sprite->pos1.x; @@ -1139,7 +1141,7 @@ static void SpriteCB_TradePokeball(struct Sprite *sprite) // play the shrink anim properly due to being paused. Works together with the fix to `sub_817F77C`. gSprites[monSpriteId].affineAnimPaused = FALSE; #endif // BUGFIX - StartSpriteAffineAnim(&gSprites[monSpriteId], 2); + StartSpriteAffineAnim(&gSprites[monSpriteId], BATTLER_AFFINE_RETURN); AnimateSprite(&gSprites[monSpriteId]); gSprites[monSpriteId].data[1] = 0; } diff --git a/src/pokemon.c b/src/pokemon.c index 1d736be74..b4eb6f01a 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -3433,7 +3433,7 @@ void SetMultiuseSpriteTemplateToPokemon(u16 speciesTag, u8 battlerPosition) gMultiuseSpriteTemplate.paletteTag = speciesTag; if (battlerPosition == B_POSITION_PLAYER_LEFT || battlerPosition == B_POSITION_PLAYER_RIGHT) - gMultiuseSpriteTemplate.anims = gUnknown_082FF70C; + gMultiuseSpriteTemplate.anims = gAnims_MonPic; else if (speciesTag > SPECIES_SHINY_TAG) gMultiuseSpriteTemplate.anims = gMonFrontAnimsPtrTable[speciesTag - SPECIES_SHINY_TAG]; else @@ -6826,7 +6826,7 @@ static void sub_806F1FC(struct Unknown_806F160_Struct* structPtr) structPtr->frameImages[i * structPtr->field_0_0 + j].data = &structPtr->byteArrays[i][j * 0x800]; } structPtr->templates[i].images = &structPtr->frameImages[i * structPtr->field_0_0]; - structPtr->templates[i].anims = gUnknown_082FF70C; + structPtr->templates[i].anims = gAnims_MonPic; structPtr->templates[i].paletteTag = i; } } diff --git a/src/trainer_pokemon_sprites.c b/src/trainer_pokemon_sprites.c index aab4142db..477c11faf 100644 --- a/src/trainer_pokemon_sprites.c +++ b/src/trainer_pokemon_sprites.c @@ -137,7 +137,7 @@ static void LoadPicPaletteBySlot(u16 species, u32 otId, u32 personality, u8 pale static void AssignSpriteAnimsTable(bool8 isTrainer) { if (!isTrainer) - sCreatingSpriteTemplate.anims = gUnknown_082FF70C; + sCreatingSpriteTemplate.anims = gAnims_MonPic; else sCreatingSpriteTemplate.anims = gTrainerFrontAnimsPtrTable[0]; } From e40f89b175189bcfca33285ee5a98de1b7ff74a6 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 25 Apr 2021 02:19:01 -0400 Subject: [PATCH 10/11] Move unknown data table, reference with species --- src/data.c | 115 +----- src/data/pokemon_graphics/unknown_table.h | 444 ++++++++++++++++++++++ 2 files changed, 445 insertions(+), 114 deletions(-) create mode 100644 src/data/pokemon_graphics/unknown_table.h diff --git a/src/data.c b/src/data.c index d300d4f63..5856d17b8 100644 --- a/src/data.c +++ b/src/data.c @@ -319,120 +319,7 @@ const union AnimCmd *const gAnims_MonPic[] = #include "data/pokemon_graphics/enemy_mon_elevation.h" #include "data/pokemon_graphics/front_pic_anims.h" #include "data/pokemon_graphics/front_pic_table.h" - -static const u32 sUnused[] = -{ - 0x00000888, 0x00000888, 0x00000888, 0x00000888, - 0x00000088, 0x00000888, 0x00000888, 0x00000886, - 0x00000888, 0x00000886, 0x00000888, 0x00000888, - 0x00000888, 0x00000888, 0x00000888, 0x00000888, - 0x00000886, 0x00000888, 0x00000888, 0x00000888, - 0x00000888, 0x00000888, 0x00000886, 0x00000886, - 0x00000888, 0x00000088, 0x00000088, 0x00000088, - 0x00000088, 0x00000888, 0x00000886, 0x00000888, - 0x00000888, 0x00000888, 0x00000886, 0x00000886, - 0x00000888, 0x00000088, 0x00000088, 0x00000088, - 0x00000088, 0x00000886, 0x00000886, 0x00000088, - 0x00000886, 0x00000886, 0x00000888, 0x00000888, - 0x00000888, 0x00000888, 0x00000888, 0x00000888, - 0x00000886, 0x00000888, 0x00000088, 0x00000088, - 0x00000888, 0x00000888, 0x00000888, 0x00000886, - 0x00000888, 0x00000888, 0x00000888, 0x00000886, - 0x00000886, 0x00000886, 0x00000886, 0x00000886, - 0x00000886, 0x00000886, 0x00000888, 0x00000888, - 0x00000886, 0x00000886, 0x00000886, 0x00000886, - 0x00000886, 0x00000888, 0x00000888, 0x00000888, - 0x00000888, 0x00000886, 0x00000886, 0x00000888, - 0x00000886, 0x00000886, 0x00000888, 0x00000888, - 0x00000088, 0x00000088, 0x00000888, 0x00000888, - 0x00000888, 0x00000888, 0x00000888, 0x00000888, - 0x00000888, 0x00000888, 0x00000888, 0x00000888, - 0x00000886, 0x00000886, 0x00000888, 0x00000888, - 0x00000888, 0x00000888, 0x00000088, 0x00000886, - 0x00000888, 0x00000088, 0x00000088, 0x00000088, - 0x00000088, 0x00000888, 0x00000886, 0x00000888, - 0x00000088, 0x00000088, 0x00000886, 0x00000886, - 0x00000088, 0x00000088, 0x00000888, 0x00000886, - 0x00000886, 0x00000888, 0x00000888, 0x00000088, - 0x00000888, 0x00000886, 0x00000886, 0x00000888, - 0x00000886, 0x00000888, 0x00000888, 0x00000886, - 0x00000888, 0x00000888, 0x00000888, 0x00000888, - 0x00000888, 0x00000888, 0x00000888, 0x00000888, - 0x00000888, 0x00000888, 0x00000888, 0x00000888, - 0x00000888, 0x00000888, 0x00000088, 0x00000888, - 0x00000888, 0x00000888, 0x00000888, 0x00000888, - 0x00000088, 0x00000888, 0x00000888, 0x00000886, - 0x00000886, 0x00000888, 0x00000888, 0x00000888, - 0x00000888, 0x00000888, 0x00000888, 0x00000886, - 0x00000888, 0x00000886, 0x00000088, 0x00000088, - 0x00000088, 0x00000888, 0x00000088, 0x00000888, - 0x00000888, 0x00000088, 0x00000088, 0x00000888, - 0x00000886, 0x00000888, 0x00000886, 0x00000886, - 0x00000886, 0x00000888, 0x00000888, 0x00000888, - 0x00000088, 0x00000888, 0x00000888, 0x00000888, - 0x00000088, 0x00000888, 0x00000888, 0x00000888, - 0x00000888, 0x00000888, 0x00000888, 0x00000888, - 0x00000888, 0x00000888, 0x00000088, 0x00000088, - 0x00000886, 0x00000888, 0x00000888, 0x00000888, - 0x00000888, 0x00000888, 0x00000888, 0x00000888, - 0x00000888, 0x00000888, 0x00000088, 0x00000888, - 0x00000886, 0x00000888, 0x00000088, 0x00000088, - 0x00000888, 0x00000888, 0x00000088, 0x00000888, - 0x00000888, 0x00000888, 0x00000888, 0x00000088, - 0x00000888, 0x00000888, 0x00000088, 0x00000088, - 0x00000088, 0x00000888, 0x00000088, 0x00000888, - 0x00000888, 0x00000888, 0x00000888, 0x00000888, - 0x00000888, 0x00000888, 0x00000888, 0x00000888, - 0x00000888, 0x00000888, 0x00000888, 0x00000888, - 0x00000888, 0x00000886, 0x00000888, 0x00000888, - 0x00000888, 0x00000888, 0x00000888, 0x00000888, - 0x00000888, 0x00000888, 0x00000888, 0x00000888, - 0x00000888, 0x00000888, 0x00000888, 0x00000888, - 0x00000888, 0x00000888, 0x00000888, 0x00000888, - 0x00000888, 0x00000888, 0x00000888, 0x00000888, - 0x00000888, 0x00000888, 0x00000888, 0x00000888, - 0x00000888, 0x00000886, 0x00000886, 0x00000886, - 0x00000088, 0x00000088, 0x00000088, 0x00000886, - 0x00000088, 0x00000886, 0x00000886, 0x00000886, - 0x00000088, 0x00000886, 0x00000088, 0x00000088, - 0x00000088, 0x00000088, 0x00000088, 0x00000886, - 0x00000886, 0x00000886, 0x00000888, 0x00000888, - 0x00000886, 0x00000886, 0x00000886, 0x00000886, - 0x00000088, 0x00000088, 0x00000886, 0x00000886, - 0x00001882, 0x00000088, 0x00000088, 0x00000088, - 0x00000088, 0x00000886, 0x00000886, 0x00000886, - 0x00000088, 0x00000088, 0x00000088, 0x00000088, - 0x00000886, 0x00000088, 0x00000886, 0x00000088, - 0x00000088, 0x00000088, 0x00000088, 0x00000088, - 0x00000088, 0x00000088, 0x00000886, 0x00000886, - 0x00000088, 0x00000088, 0x00000088, 0x00000886, - 0x00000886, 0x00000088, 0x00000088, 0x00000088, - 0x00000088, 0x00000088, 0x00000088, 0x00000088, - 0x00000088, 0x00000088, 0x00000088, 0x00000088, - 0x00000088, 0x00000088, 0x00000886, 0x00000088, - 0x00000088, 0x00000886, 0x00000886, 0x00000886, - 0x00000886, 0x00000886, 0x00000088, 0x00000088, - 0x00000088, 0x00000088, 0x00000088, 0x00000886, - 0x00000886, 0x00000886, 0x00000886, 0x00000088, - 0x00000886, 0x00000088, 0x00000886, 0x00000886, - 0x00000886, 0x00000088, 0x00000088, 0x00000088, - 0x00000088, 0x00000088, 0x00000088, 0x00000088, - 0x00000088, 0x00000088, 0x00000886, 0x00000886, - 0x00000886, 0x00000888, 0x00000886, 0x00000886, - 0x00000088, 0x00000088, 0x00000088, 0x00000088, - 0x00000886, 0x00000886, 0x00000088, 0x00000088, - 0x00000088, 0x00000088, 0x00000088, 0x00000088, - 0x00000088, 0x00000088, 0x00000088, 0x00000088, - 0x00000088, 0x00000088, 0x00000088, 0x00000088, - 0x00000088, 0x00000088, 0x00000088, 0x00000088, - 0x00000088, 0x00000888, 0x00000888, 0x00000888, - 0x00000888, 0x00000888, 0x00000888, 0x00000888, - 0x00000888, 0x00000888, 0x00000888, 0x00000888, - 0x00000888, 0x00000888, 0x00000888, 0x00000888, - 0x00000888, 0x00000888, 0x00000888, 0x00000888, - 0x00000888, 0x00000888, 0x00000888, 0x00000888, - 0x00000888, 0x00000888, 0x00000888, 0x00000888, -}; +#include "data/pokemon_graphics/unknown_table.h" #include "data/trainer_parties.h" #include "data/text/trainer_class_names.h" diff --git a/src/data/pokemon_graphics/unknown_table.h b/src/data/pokemon_graphics/unknown_table.h new file mode 100644 index 000000000..737b79c1b --- /dev/null +++ b/src/data/pokemon_graphics/unknown_table.h @@ -0,0 +1,444 @@ +// Unknown and unused +static const u32 sUnused[] = +{ + [SPECIES_NONE] = 0x888, + [SPECIES_BULBASAUR] = 0x888, + [SPECIES_IVYSAUR] = 0x888, + [SPECIES_VENUSAUR] = 0x888, + [SPECIES_CHARMANDER] = 0x88, + [SPECIES_CHARMELEON] = 0x888, + [SPECIES_CHARIZARD] = 0x888, + [SPECIES_SQUIRTLE] = 0x886, + [SPECIES_WARTORTLE] = 0x888, + [SPECIES_BLASTOISE] = 0x886, + [SPECIES_CATERPIE] = 0x888, + [SPECIES_METAPOD] = 0x888, + [SPECIES_BUTTERFREE] = 0x888, + [SPECIES_WEEDLE] = 0x888, + [SPECIES_KAKUNA] = 0x888, + [SPECIES_BEEDRILL] = 0x888, + [SPECIES_PIDGEY] = 0x886, + [SPECIES_PIDGEOTTO] = 0x888, + [SPECIES_PIDGEOT] = 0x888, + [SPECIES_RATTATA] = 0x888, + [SPECIES_RATICATE] = 0x888, + [SPECIES_SPEAROW] = 0x888, + [SPECIES_FEAROW] = 0x886, + [SPECIES_EKANS] = 0x886, + [SPECIES_ARBOK] = 0x888, + [SPECIES_PIKACHU] = 0x88, + [SPECIES_RAICHU] = 0x88, + [SPECIES_SANDSHREW] = 0x88, + [SPECIES_SANDSLASH] = 0x88, + [SPECIES_NIDORAN_F] = 0x888, + [SPECIES_NIDORINA] = 0x886, + [SPECIES_NIDOQUEEN] = 0x888, + [SPECIES_NIDORAN_M] = 0x888, + [SPECIES_NIDORINO] = 0x888, + [SPECIES_NIDOKING] = 0x886, + [SPECIES_CLEFAIRY] = 0x886, + [SPECIES_CLEFABLE] = 0x888, + [SPECIES_VULPIX] = 0x88, + [SPECIES_NINETALES] = 0x88, + [SPECIES_JIGGLYPUFF] = 0x88, + [SPECIES_WIGGLYTUFF] = 0x88, + [SPECIES_ZUBAT] = 0x886, + [SPECIES_GOLBAT] = 0x886, + [SPECIES_ODDISH] = 0x88, + [SPECIES_GLOOM] = 0x886, + [SPECIES_VILEPLUME] = 0x886, + [SPECIES_PARAS] = 0x888, + [SPECIES_PARASECT] = 0x888, + [SPECIES_VENONAT] = 0x888, + [SPECIES_VENOMOTH] = 0x888, + [SPECIES_DIGLETT] = 0x888, + [SPECIES_DUGTRIO] = 0x888, + [SPECIES_MEOWTH] = 0x886, + [SPECIES_PERSIAN] = 0x888, + [SPECIES_PSYDUCK] = 0x88, + [SPECIES_GOLDUCK] = 0x88, + [SPECIES_MANKEY] = 0x888, + [SPECIES_PRIMEAPE] = 0x888, + [SPECIES_GROWLITHE] = 0x888, + [SPECIES_ARCANINE] = 0x886, + [SPECIES_POLIWAG] = 0x888, + [SPECIES_POLIWHIRL] = 0x888, + [SPECIES_POLIWRATH] = 0x888, + [SPECIES_ABRA] = 0x886, + [SPECIES_KADABRA] = 0x886, + [SPECIES_ALAKAZAM] = 0x886, + [SPECIES_MACHOP] = 0x886, + [SPECIES_MACHOKE] = 0x886, + [SPECIES_MACHAMP] = 0x886, + [SPECIES_BELLSPROUT] = 0x886, + [SPECIES_WEEPINBELL] = 0x888, + [SPECIES_VICTREEBEL] = 0x888, + [SPECIES_TENTACOOL] = 0x886, + [SPECIES_TENTACRUEL] = 0x886, + [SPECIES_GEODUDE] = 0x886, + [SPECIES_GRAVELER] = 0x886, + [SPECIES_GOLEM] = 0x886, + [SPECIES_PONYTA] = 0x888, + [SPECIES_RAPIDASH] = 0x888, + [SPECIES_SLOWPOKE] = 0x888, + [SPECIES_SLOWBRO] = 0x888, + [SPECIES_MAGNEMITE] = 0x886, + [SPECIES_MAGNETON] = 0x886, + [SPECIES_FARFETCHD] = 0x888, + [SPECIES_DODUO] = 0x886, + [SPECIES_DODRIO] = 0x886, + [SPECIES_SEEL] = 0x888, + [SPECIES_DEWGONG] = 0x888, + [SPECIES_GRIMER] = 0x88, + [SPECIES_MUK] = 0x88, + [SPECIES_SHELLDER] = 0x888, + [SPECIES_CLOYSTER] = 0x888, + [SPECIES_GASTLY] = 0x888, + [SPECIES_HAUNTER] = 0x888, + [SPECIES_GENGAR] = 0x888, + [SPECIES_ONIX] = 0x888, + [SPECIES_DROWZEE] = 0x888, + [SPECIES_HYPNO] = 0x888, + [SPECIES_KRABBY] = 0x888, + [SPECIES_KINGLER] = 0x888, + [SPECIES_VOLTORB] = 0x886, + [SPECIES_ELECTRODE] = 0x886, + [SPECIES_EXEGGCUTE] = 0x888, + [SPECIES_EXEGGUTOR] = 0x888, + [SPECIES_CUBONE] = 0x888, + [SPECIES_MAROWAK] = 0x888, + [SPECIES_HITMONLEE] = 0x88, + [SPECIES_HITMONCHAN] = 0x886, + [SPECIES_LICKITUNG] = 0x888, + [SPECIES_KOFFING] = 0x88, + [SPECIES_WEEZING] = 0x88, + [SPECIES_RHYHORN] = 0x88, + [SPECIES_RHYDON] = 0x88, + [SPECIES_CHANSEY] = 0x888, + [SPECIES_TANGELA] = 0x886, + [SPECIES_KANGASKHAN] = 0x888, + [SPECIES_HORSEA] = 0x88, + [SPECIES_SEADRA] = 0x88, + [SPECIES_GOLDEEN] = 0x886, + [SPECIES_SEAKING] = 0x886, + [SPECIES_STARYU] = 0x88, + [SPECIES_STARMIE] = 0x88, + [SPECIES_MR_MIME] = 0x888, + [SPECIES_SCYTHER] = 0x886, + [SPECIES_JYNX] = 0x886, + [SPECIES_ELECTABUZZ] = 0x888, + [SPECIES_MAGMAR] = 0x888, + [SPECIES_PINSIR] = 0x88, + [SPECIES_TAUROS] = 0x888, + [SPECIES_MAGIKARP] = 0x886, + [SPECIES_GYARADOS] = 0x886, + [SPECIES_LAPRAS] = 0x888, + [SPECIES_DITTO] = 0x886, + [SPECIES_EEVEE] = 0x888, + [SPECIES_VAPOREON] = 0x888, + [SPECIES_JOLTEON] = 0x886, + [SPECIES_FLAREON] = 0x888, + [SPECIES_PORYGON] = 0x888, + [SPECIES_OMANYTE] = 0x888, + [SPECIES_OMASTAR] = 0x888, + [SPECIES_KABUTO] = 0x888, + [SPECIES_KABUTOPS] = 0x888, + [SPECIES_AERODACTYL] = 0x888, + [SPECIES_SNORLAX] = 0x888, + [SPECIES_ARTICUNO] = 0x888, + [SPECIES_ZAPDOS] = 0x888, + [SPECIES_MOLTRES] = 0x888, + [SPECIES_DRATINI] = 0x888, + [SPECIES_DRAGONAIR] = 0x888, + [SPECIES_DRAGONITE] = 0x888, + [SPECIES_MEWTWO] = 0x88, + [SPECIES_MEW] = 0x888, + [SPECIES_CHIKORITA] = 0x888, + [SPECIES_BAYLEEF] = 0x888, + [SPECIES_MEGANIUM] = 0x888, + [SPECIES_CYNDAQUIL] = 0x888, + [SPECIES_QUILAVA] = 0x88, + [SPECIES_TYPHLOSION] = 0x888, + [SPECIES_TOTODILE] = 0x888, + [SPECIES_CROCONAW] = 0x886, + [SPECIES_FERALIGATR] = 0x886, + [SPECIES_SENTRET] = 0x888, + [SPECIES_FURRET] = 0x888, + [SPECIES_HOOTHOOT] = 0x888, + [SPECIES_NOCTOWL] = 0x888, + [SPECIES_LEDYBA] = 0x888, + [SPECIES_LEDIAN] = 0x888, + [SPECIES_SPINARAK] = 0x886, + [SPECIES_ARIADOS] = 0x888, + [SPECIES_CROBAT] = 0x886, + [SPECIES_CHINCHOU] = 0x88, + [SPECIES_LANTURN] = 0x88, + [SPECIES_PICHU] = 0x88, + [SPECIES_CLEFFA] = 0x888, + [SPECIES_IGGLYBUFF] = 0x88, + [SPECIES_TOGEPI] = 0x888, + [SPECIES_TOGETIC] = 0x888, + [SPECIES_NATU] = 0x88, + [SPECIES_XATU] = 0x88, + [SPECIES_MAREEP] = 0x888, + [SPECIES_FLAAFFY] = 0x886, + [SPECIES_AMPHAROS] = 0x888, + [SPECIES_BELLOSSOM] = 0x886, + [SPECIES_MARILL] = 0x886, + [SPECIES_AZUMARILL] = 0x886, + [SPECIES_SUDOWOODO] = 0x888, + [SPECIES_POLITOED] = 0x888, + [SPECIES_HOPPIP] = 0x888, + [SPECIES_SKIPLOOM] = 0x88, + [SPECIES_JUMPLUFF] = 0x888, + [SPECIES_AIPOM] = 0x888, + [SPECIES_SUNKERN] = 0x888, + [SPECIES_SUNFLORA] = 0x88, + [SPECIES_YANMA] = 0x888, + [SPECIES_WOOPER] = 0x888, + [SPECIES_QUAGSIRE] = 0x888, + [SPECIES_ESPEON] = 0x888, + [SPECIES_UMBREON] = 0x888, + [SPECIES_MURKROW] = 0x888, + [SPECIES_SLOWKING] = 0x888, + [SPECIES_MISDREAVUS] = 0x888, + [SPECIES_UNOWN] = 0x888, + [SPECIES_WOBBUFFET] = 0x88, + [SPECIES_GIRAFARIG] = 0x88, + [SPECIES_PINECO] = 0x886, + [SPECIES_FORRETRESS] = 0x888, + [SPECIES_DUNSPARCE] = 0x888, + [SPECIES_GLIGAR] = 0x888, + [SPECIES_STEELIX] = 0x888, + [SPECIES_SNUBBULL] = 0x888, + [SPECIES_GRANBULL] = 0x888, + [SPECIES_QWILFISH] = 0x888, + [SPECIES_SCIZOR] = 0x888, + [SPECIES_SHUCKLE] = 0x888, + [SPECIES_HERACROSS] = 0x88, + [SPECIES_SNEASEL] = 0x888, + [SPECIES_TEDDIURSA] = 0x886, + [SPECIES_URSARING] = 0x888, + [SPECIES_SLUGMA] = 0x88, + [SPECIES_MAGCARGO] = 0x88, + [SPECIES_SWINUB] = 0x888, + [SPECIES_PILOSWINE] = 0x888, + [SPECIES_CORSOLA] = 0x88, + [SPECIES_REMORAID] = 0x888, + [SPECIES_OCTILLERY] = 0x888, + [SPECIES_DELIBIRD] = 0x888, + [SPECIES_MANTINE] = 0x888, + [SPECIES_SKARMORY] = 0x88, + [SPECIES_HOUNDOUR] = 0x888, + [SPECIES_HOUNDOOM] = 0x888, + [SPECIES_KINGDRA] = 0x88, + [SPECIES_PHANPY] = 0x88, + [SPECIES_DONPHAN] = 0x88, + [SPECIES_PORYGON2] = 0x888, + [SPECIES_STANTLER] = 0x88, + [SPECIES_SMEARGLE] = 0x888, + [SPECIES_TYROGUE] = 0x888, + [SPECIES_HITMONTOP] = 0x888, + [SPECIES_SMOOCHUM] = 0x888, + [SPECIES_ELEKID] = 0x888, + [SPECIES_MAGBY] = 0x888, + [SPECIES_MILTANK] = 0x888, + [SPECIES_BLISSEY] = 0x888, + [SPECIES_RAIKOU] = 0x888, + [SPECIES_ENTEI] = 0x888, + [SPECIES_SUICUNE] = 0x888, + [SPECIES_LARVITAR] = 0x888, + [SPECIES_PUPITAR] = 0x888, + [SPECIES_TYRANITAR] = 0x888, + [SPECIES_LUGIA] = 0x886, + [SPECIES_HO_OH] = 0x888, + [SPECIES_CELEBI] = 0x888, + [SPECIES_OLD_UNOWN_B] = 0x888, + [SPECIES_OLD_UNOWN_C] = 0x888, + [SPECIES_OLD_UNOWN_D] = 0x888, + [SPECIES_OLD_UNOWN_E] = 0x888, + [SPECIES_OLD_UNOWN_F] = 0x888, + [SPECIES_OLD_UNOWN_G] = 0x888, + [SPECIES_OLD_UNOWN_H] = 0x888, + [SPECIES_OLD_UNOWN_I] = 0x888, + [SPECIES_OLD_UNOWN_J] = 0x888, + [SPECIES_OLD_UNOWN_K] = 0x888, + [SPECIES_OLD_UNOWN_L] = 0x888, + [SPECIES_OLD_UNOWN_M] = 0x888, + [SPECIES_OLD_UNOWN_N] = 0x888, + [SPECIES_OLD_UNOWN_O] = 0x888, + [SPECIES_OLD_UNOWN_P] = 0x888, + [SPECIES_OLD_UNOWN_Q] = 0x888, + [SPECIES_OLD_UNOWN_R] = 0x888, + [SPECIES_OLD_UNOWN_S] = 0x888, + [SPECIES_OLD_UNOWN_T] = 0x888, + [SPECIES_OLD_UNOWN_U] = 0x888, + [SPECIES_OLD_UNOWN_V] = 0x888, + [SPECIES_OLD_UNOWN_W] = 0x888, + [SPECIES_OLD_UNOWN_X] = 0x888, + [SPECIES_OLD_UNOWN_Y] = 0x888, + [SPECIES_OLD_UNOWN_Z] = 0x888, + [SPECIES_TREECKO] = 0x886, + [SPECIES_GROVYLE] = 0x886, + [SPECIES_SCEPTILE] = 0x886, + [SPECIES_TORCHIC] = 0x88, + [SPECIES_COMBUSKEN] = 0x88, + [SPECIES_BLAZIKEN] = 0x88, + [SPECIES_MUDKIP] = 0x886, + [SPECIES_MARSHTOMP] = 0x88, + [SPECIES_SWAMPERT] = 0x886, + [SPECIES_POOCHYENA] = 0x886, + [SPECIES_MIGHTYENA] = 0x886, + [SPECIES_ZIGZAGOON] = 0x88, + [SPECIES_LINOONE] = 0x886, + [SPECIES_WURMPLE] = 0x88, + [SPECIES_SILCOON] = 0x88, + [SPECIES_BEAUTIFLY] = 0x88, + [SPECIES_CASCOON] = 0x88, + [SPECIES_DUSTOX] = 0x88, + [SPECIES_LOTAD] = 0x886, + [SPECIES_LOMBRE] = 0x886, + [SPECIES_LUDICOLO] = 0x886, + [SPECIES_SEEDOT] = 0x888, + [SPECIES_NUZLEAF] = 0x888, + [SPECIES_SHIFTRY] = 0x886, + [SPECIES_NINCADA] = 0x886, + [SPECIES_NINJASK] = 0x886, + [SPECIES_SHEDINJA] = 0x886, + [SPECIES_TAILLOW] = 0x88, + [SPECIES_SWELLOW] = 0x88, + [SPECIES_SHROOMISH] = 0x886, + [SPECIES_BRELOOM] = 0x886, + [SPECIES_SPINDA] = 0x1882, + [SPECIES_WINGULL] = 0x88, + [SPECIES_PELIPPER] = 0x88, + [SPECIES_SURSKIT] = 0x88, + [SPECIES_MASQUERAIN] = 0x88, + [SPECIES_WAILMER] = 0x886, + [SPECIES_WAILORD] = 0x886, + [SPECIES_SKITTY] = 0x886, + [SPECIES_DELCATTY] = 0x88, + [SPECIES_KECLEON] = 0x88, + [SPECIES_BALTOY] = 0x88, + [SPECIES_CLAYDOL] = 0x88, + [SPECIES_NOSEPASS] = 0x886, + [SPECIES_TORKOAL] = 0x88, + [SPECIES_SABLEYE] = 0x886, + [SPECIES_BARBOACH] = 0x88, + [SPECIES_WHISCASH] = 0x88, + [SPECIES_LUVDISC] = 0x88, + [SPECIES_CORPHISH] = 0x88, + [SPECIES_CRAWDAUNT] = 0x88, + [SPECIES_FEEBAS] = 0x88, + [SPECIES_MILOTIC] = 0x88, + [SPECIES_CARVANHA] = 0x886, + [SPECIES_SHARPEDO] = 0x886, + [SPECIES_TRAPINCH] = 0x88, + [SPECIES_VIBRAVA] = 0x88, + [SPECIES_FLYGON] = 0x88, + [SPECIES_MAKUHITA] = 0x886, + [SPECIES_HARIYAMA] = 0x886, + [SPECIES_ELECTRIKE] = 0x88, + [SPECIES_MANECTRIC] = 0x88, + [SPECIES_NUMEL] = 0x88, + [SPECIES_CAMERUPT] = 0x88, + [SPECIES_SPHEAL] = 0x88, + [SPECIES_SEALEO] = 0x88, + [SPECIES_WALREIN] = 0x88, + [SPECIES_CACNEA] = 0x88, + [SPECIES_CACTURNE] = 0x88, + [SPECIES_SNORUNT] = 0x88, + [SPECIES_GLALIE] = 0x88, + [SPECIES_LUNATONE] = 0x88, + [SPECIES_SOLROCK] = 0x88, + [SPECIES_AZURILL] = 0x886, + [SPECIES_SPOINK] = 0x88, + [SPECIES_GRUMPIG] = 0x88, + [SPECIES_PLUSLE] = 0x886, + [SPECIES_MINUN] = 0x886, + [SPECIES_MAWILE] = 0x886, + [SPECIES_MEDITITE] = 0x886, + [SPECIES_MEDICHAM] = 0x886, + [SPECIES_SWABLU] = 0x88, + [SPECIES_ALTARIA] = 0x88, + [SPECIES_WYNAUT] = 0x88, + [SPECIES_DUSKULL] = 0x88, + [SPECIES_DUSCLOPS] = 0x88, + [SPECIES_ROSELIA] = 0x886, + [SPECIES_SLAKOTH] = 0x886, + [SPECIES_VIGOROTH] = 0x886, + [SPECIES_SLAKING] = 0x886, + [SPECIES_GULPIN] = 0x88, + [SPECIES_SWALOT] = 0x886, + [SPECIES_TROPIUS] = 0x88, + [SPECIES_WHISMUR] = 0x886, + [SPECIES_LOUDRED] = 0x886, + [SPECIES_EXPLOUD] = 0x886, + [SPECIES_CLAMPERL] = 0x88, + [SPECIES_HUNTAIL] = 0x88, + [SPECIES_GOREBYSS] = 0x88, + [SPECIES_ABSOL] = 0x88, + [SPECIES_SHUPPET] = 0x88, + [SPECIES_BANETTE] = 0x88, + [SPECIES_SEVIPER] = 0x88, + [SPECIES_ZANGOOSE] = 0x88, + [SPECIES_RELICANTH] = 0x88, + [SPECIES_ARON] = 0x886, + [SPECIES_LAIRON] = 0x886, + [SPECIES_AGGRON] = 0x886, + [SPECIES_CASTFORM] = 0x888, + [SPECIES_VOLBEAT] = 0x886, + [SPECIES_ILLUMISE] = 0x886, + [SPECIES_LILEEP] = 0x88, + [SPECIES_CRADILY] = 0x88, + [SPECIES_ANORITH] = 0x88, + [SPECIES_ARMALDO] = 0x88, + [SPECIES_RALTS] = 0x886, + [SPECIES_KIRLIA] = 0x886, + [SPECIES_GARDEVOIR] = 0x88, + [SPECIES_BAGON] = 0x88, + [SPECIES_SHELGON] = 0x88, + [SPECIES_SALAMENCE] = 0x88, + [SPECIES_BELDUM] = 0x88, + [SPECIES_METANG] = 0x88, + [SPECIES_METAGROSS] = 0x88, + [SPECIES_REGIROCK] = 0x88, + [SPECIES_REGICE] = 0x88, + [SPECIES_REGISTEEL] = 0x88, + [SPECIES_KYOGRE] = 0x88, + [SPECIES_GROUDON] = 0x88, + [SPECIES_RAYQUAZA] = 0x88, + [SPECIES_LATIAS] = 0x88, + [SPECIES_LATIOS] = 0x88, + [SPECIES_JIRACHI] = 0x88, + [SPECIES_DEOXYS] = 0x88, + [SPECIES_CHIMECHO] = 0x88, + [SPECIES_EGG] = 0x88, + [SPECIES_UNOWN_B] = 0x888, + [SPECIES_UNOWN_C] = 0x888, + [SPECIES_UNOWN_D] = 0x888, + [SPECIES_UNOWN_E] = 0x888, + [SPECIES_UNOWN_F] = 0x888, + [SPECIES_UNOWN_G] = 0x888, + [SPECIES_UNOWN_H] = 0x888, + [SPECIES_UNOWN_I] = 0x888, + [SPECIES_UNOWN_J] = 0x888, + [SPECIES_UNOWN_K] = 0x888, + [SPECIES_UNOWN_L] = 0x888, + [SPECIES_UNOWN_M] = 0x888, + [SPECIES_UNOWN_N] = 0x888, + [SPECIES_UNOWN_O] = 0x888, + [SPECIES_UNOWN_P] = 0x888, + [SPECIES_UNOWN_Q] = 0x888, + [SPECIES_UNOWN_R] = 0x888, + [SPECIES_UNOWN_S] = 0x888, + [SPECIES_UNOWN_T] = 0x888, + [SPECIES_UNOWN_U] = 0x888, + [SPECIES_UNOWN_V] = 0x888, + [SPECIES_UNOWN_W] = 0x888, + [SPECIES_UNOWN_X] = 0x888, + [SPECIES_UNOWN_Y] = 0x888, + [SPECIES_UNOWN_Z] = 0x888, + [SPECIES_UNOWN_EMARK] = 0x888, + [SPECIES_UNOWN_QMARK] = 0x888, +}; From aad090e154d4cb1397468f3b19071ddad688a7bc Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 25 Apr 2021 17:22:45 -0400 Subject: [PATCH 11/11] Document TV --- .../scripts.inc | 2 +- data/scripts/gabby_and_ty.inc | 6 +- data/scripts/tv.inc | 8 +- data/specials.inc | 10 +- include/constants/battle_frontier.h | 15 + include/constants/easy_chat.h | 2 +- include/constants/metatile_labels.h | 2 + include/constants/tv.h | 38 +- include/daycare.h | 2 +- include/global.h | 8 +- include/global.tv.h | 22 +- include/mauville_old_man.h | 2 +- include/tv.h | 30 +- src/battle_main.c | 4 +- src/battle_tower.c | 1 - src/contest.c | 1 - src/contest_util.c | 1 - src/daycare.c | 12 +- src/decoration.c | 4 +- src/easy_chat.c | 4 +- src/field_specials.c | 3 +- src/fldeff_misc.c | 1 - src/frontier_util.c | 26 +- src/item.c | 1 - src/mauville_old_man.c | 52 +- src/menu.c | 6 +- src/post_battle_event_funcs.c | 1 - src/record_mixing.c | 106 +- src/roulette.c | 2 +- src/safari_zone.c | 2 +- src/script_pokemon_util.c | 1 - src/secret_base.c | 1 - src/shop.c | 5 +- src/slot_machine.c | 2 +- src/tv.c | 6062 ++++++++--------- 35 files changed, 3028 insertions(+), 3417 deletions(-) diff --git a/data/maps/LilycoveCity_PokemonTrainerFanClub/scripts.inc b/data/maps/LilycoveCity_PokemonTrainerFanClub/scripts.inc index 6ff869db3..86544d3e9 100644 --- a/data/maps/LilycoveCity_PokemonTrainerFanClub/scripts.inc +++ b/data/maps/LilycoveCity_PokemonTrainerFanClub/scripts.inc @@ -173,7 +173,7 @@ LilycoveCity_PokemonTrainerFanClub_EventScript_CountNotPlayersFan:: @ 821C9AE return LilycoveCity_PokemonTrainerFanClub_EventScript_TrySetUpTVShow:: @ 821C9B4 - special TrySetUpTrainerFanClubSpecial + special TryPutTrainerFanClubOnAir return LilycoveCity_PokemonTrainerFanClub_EventScript_MoveMember1ToFarTable:: @ 821C9B8 diff --git a/data/scripts/gabby_and_ty.inc b/data/scripts/gabby_and_ty.inc index c7f576aba..60854a801 100644 --- a/data/scripts/gabby_and_ty.inc +++ b/data/scripts/gabby_and_ty.inc @@ -1,6 +1,6 @@ @ Gabby and Ty always move to the same spots for the first 5 battles @ From the 6th battle onwards, they move randomly between locations 6-8 -@ Note: The local IDs of Gabby and Ty are hard-coded in GabbyAndTySetScriptVarsToObjectEventLocalIds +@ Note: The local IDs of Gabby and Ty are hard-coded in GetGabbyAndTyLocalIds GabbyAndTy_EventScript_UpdateLocation:: @ 828CCC7 cleartrainerflag TRAINER_GABBY_AND_TY_6 specialvar VAR_RESULT, GabbyAndTyGetBattleNum @@ -198,7 +198,7 @@ GabbyAndTy_EventScript_TyBattle6:: @ 828CF36 GabbyAndTy_EventScript_FirstInterview:: @ 828CF56 special GabbyAndTyBeforeInterview - special GabbyAndTySetScriptVarsToObjectEventLocalIds + special GetGabbyAndTyLocalIds compare VAR_FACING, DIR_NORTH call_if_eq GabbyAndTy_EventScript_FacePlayerNorth compare VAR_FACING, DIR_SOUTH @@ -229,7 +229,7 @@ GabbyAndTy_EventScript_FacePlayerEast:: @ 828CFB1 GabbyAndTy_EventScript_RequestInterview:: @ 828CFC3 special GabbyAndTyBeforeInterview - special GabbyAndTySetScriptVarsToObjectEventLocalIds + special GetGabbyAndTyLocalIds compare VAR_FACING, DIR_NORTH call_if_eq GabbyAndTy_EventScript_FacePlayerNorth compare VAR_FACING, DIR_SOUTH diff --git a/data/scripts/tv.inc b/data/scripts/tv.inc index a2d5473b1..1dfc1884b 100644 --- a/data/scripts/tv.inc +++ b/data/scripts/tv.inc @@ -2,14 +2,14 @@ EventScript_TV:: @ 827EE0B lockall incrementgamestat GAME_STAT_WATCHED_TV special ResetTVShowState - specialvar VAR_RESULT, CheckForBigMovieOrEmergencyNewsOnTV - compare VAR_RESULT, 2 + specialvar VAR_RESULT, CheckForPlayersHouseNews + compare VAR_RESULT, PLAYERS_HOUSE_TV_MOVIE goto_if_eq EventScript_PlayersHouseMovie - compare VAR_RESULT, 1 + compare VAR_RESULT, PLAYERS_HOUSE_TV_LATI goto_if_eq EventScript_PlayersHouseLatiNewsFlash goto_if_unset FLAG_SYS_TV_START, EventScript_MomDadMightLikeThis1 goto_if_set FLAG_SYS_TV_WATCH, EventScript_MomDadMightLikeThis1 - specialvar VAR_RESULT, IsTVShowInSearchOfTrainersAiring + specialvar VAR_RESULT, IsGabbyAndTyShowOnTheAir compare VAR_RESULT, TRUE goto_if_eq EventScript_DoInSearchOfTrainers goto EventScript_TryDoPokeNews diff --git a/data/specials.inc b/data/specials.inc index f672a7b87..e8315c013 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -83,8 +83,8 @@ gSpecials:: @ 81DBA64 def_special IsLeadMonNicknamedOrNotEnglish def_special SetContestCategoryStringVarForInterview def_special GetNextActiveShowIfMassOutbreak - def_special TV_IsScriptShowKindAlreadyInQueue - def_special CheckForBigMovieOrEmergencyNewsOnTV + def_special IsTVShowAlreadyInQueue + def_special CheckForPlayersHouseNews def_special GetMomOrDadStringForTVMessage def_special ResetTVShowState def_special GetContestWinnerId @@ -187,10 +187,10 @@ gSpecials:: @ 81DBA64 def_special GabbyAndTyAfterInterview def_special GabbyAndTyBeforeInterview def_special DoTVShowInSearchOfTrainers - def_special IsTVShowInSearchOfTrainersAiring + def_special IsGabbyAndTyShowOnTheAir def_special GabbyAndTyGetLastQuote def_special GabbyAndTyGetLastBattleTrivia - def_special GabbyAndTySetScriptVarsToObjectEventLocalIds + def_special GetGabbyAndTyLocalIds def_special GetBattleOutcome def_special GetDaycareMonNicknames def_special GetDaycareState @@ -354,7 +354,7 @@ gSpecials:: @ 81DBA64 def_special SetChampionSaveWarp def_special TryPutTreasureInvestigatorsOnAir def_special TryPutLotteryWinnerReportOnAir - def_special TrySetUpTrainerFanClubSpecial + def_special TryPutTrainerFanClubOnAir def_special ShouldHideFanClubInterviewer def_special ShowGlassWorkshopMenu def_special PutFanClubSpecialOnTheAir diff --git a/include/constants/battle_frontier.h b/include/constants/battle_frontier.h index bbe6db81c..68c5a42ef 100644 --- a/include/constants/battle_frontier.h +++ b/include/constants/battle_frontier.h @@ -78,6 +78,21 @@ #define FRONTIER_MANIAC_MESSAGE_COUNT 3 +// Frontier TV Show +#define FRONTIER_SHOW_TOWER_SINGLES 1 +#define FRONTIER_SHOW_TOWER_DOUBLES 2 +#define FRONTIER_SHOW_TOWER_MULTIS 3 +#define FRONTIER_SHOW_TOWER_LINK_MULTIS 4 +#define FRONTIER_SHOW_DOME_SINGLES 5 +#define FRONTIER_SHOW_DOME_DOUBLES 6 +#define FRONTIER_SHOW_FACTORY_SINGLES 7 +#define FRONTIER_SHOW_FACTORY_DOUBLES 8 +#define FRONTIER_SHOW_PIKE 9 +#define FRONTIER_SHOW_ARENA 10 +#define FRONTIER_SHOW_PALACE_SINGLES 11 +#define FRONTIER_SHOW_PALACE_DOUBLES 12 +#define FRONTIER_SHOW_PYRAMID 13 + // Frontier Gambler #define FRONTIER_GAMBLER_WAITING 0 #define FRONTIER_GAMBLER_PLACED_BET 1 diff --git a/include/constants/easy_chat.h b/include/constants/easy_chat.h index 069f17fcb..f98cedbb7 100644 --- a/include/constants/easy_chat.h +++ b/include/constants/easy_chat.h @@ -9,7 +9,7 @@ #define EASY_CHAT_TYPE_INTERVIEW 5 #define EASY_CHAT_TYPE_BARD_SONG 6 #define EASY_CHAT_TYPE_FAN_CLUB 7 -#define EASY_CHAT_TYPE_UNK_8 8 +#define EASY_CHAT_TYPE_DUMMY_SHOW 8 #define EASY_CHAT_TYPE_TRENDY_PHRASE 9 #define EASY_CHAT_TYPE_GABBY_AND_TY 10 #define EASY_CHAT_TYPE_CONTEST_INTERVIEW 11 diff --git a/include/constants/metatile_labels.h b/include/constants/metatile_labels.h index 836ab6ef2..b5ef69046 100644 --- a/include/constants/metatile_labels.h +++ b/include/constants/metatile_labels.h @@ -42,6 +42,8 @@ #define METATILE_General_BlueCaveOpen 0x1B1 // gTileset_Building +#define METATILE_Building_TV_Off 0x002 +#define METATILE_Building_TV_On 0x003 #define METATILE_Building_PC_Off 0x004 #define METATILE_Building_PC_On 0x005 diff --git a/include/constants/tv.h b/include/constants/tv.h index f7b091f49..1b28f6e6e 100644 --- a/include/constants/tv.h +++ b/include/constants/tv.h @@ -6,12 +6,22 @@ #define POKENEWS_GAME_CORNER 2 #define POKENEWS_LILYCOVE 3 #define POKENEWS_BLENDMASTER 4 +#define NUM_POKENEWS_TYPES 4 // Excludes NONE + +// TV shows are categorized as being in one of 3 groups +// - TVGROUP_NORMAL, TV shows that can appear without Record Mixing +// - TVGROUP_RECORD_MIX, TV shows that can only appear via Record Mixing +// - TVGROUP_OUTBREAK, just contains TVSHOW_MASS_OUTBREAK +// Each group was allotted 20 spaces arbitrarily, though none use all 20 #define TVSHOW_OFF_AIR 0 + +// TVGROUP_NORMAL +#define TVGROUP_NORMAL_START 1 #define TVSHOW_FAN_CLUB_LETTER 1 #define TVSHOW_RECENT_HAPPENINGS 2 #define TVSHOW_PKMN_FAN_CLUB_OPINIONS 3 -#define TVSHOW_UNKN_SHOWTYPE_04 4 +#define TVSHOW_DUMMY 4 #define TVSHOW_NAME_RATER_SHOW 5 #define TVSHOW_BRAVO_TRAINER_POKEMON_PROFILE 6 #define TVSHOW_BRAVO_TRAINER_BATTLE_TOWER_PROFILE 7 @@ -20,7 +30,11 @@ #define TVSHOW_BATTLE_UPDATE 10 #define TVSHOW_FAN_CLUB_SPECIAL 11 #define TVSHOW_LILYCOVE_CONTEST_LADY 12 -// // +// +#define TVGROUP_NORMAL_END 20 + +// TVGROUP_RECORD_MIX +#define TVGROUP_RECORD_MIX_START 21 #define TVSHOW_POKEMON_TODAY_CAUGHT 21 #define TVSHOW_SMART_SHOPPER 22 #define TVSHOW_POKEMON_TODAY_FAILED 23 @@ -40,8 +54,22 @@ #define TVSHOW_NUMBER_ONE 37 #define TVSHOW_SECRET_BASE_SECRETS 38 #define TVSHOW_SAFARI_FAN_CLUB 39 -// // -#define TVSHOW_MASS_OUTBREAK 41 +#define TVGROUP_RECORD_MIX_END 40 + +// TVGROUP_OUTBREAK +#define TVGROUP_OUTBREAK_START 41 +#define TVSHOW_MASS_OUTBREAK 41 +// +#define TVGROUP_OUTBREAK_END 60 + +// The first 5 elements of gSaveBlock1Ptr->tvShows are reserved +// for TV shows from TVGROUP_NORMAL. The remainder are for TV +// shows from TVGROUP_RECORD_MIX. +#define NUM_NORMAL_TVSHOW_SLOTS 5 + +#define PLAYERS_HOUSE_TV_NONE 0 +#define PLAYERS_HOUSE_TV_LATI 1 +#define PLAYERS_HOUSE_TV_MOVIE 2 // Number of ribbons to put Spot the Cuties on air #define NUM_CUTIES_RIBBONS 4 @@ -221,4 +249,6 @@ #define CONTESTLADYLIVE_STATE_LOST 2 #define CONTESTLADYLIVE_STATE_LOST_BADLY 3 +#define SMARTSHOPPER_NUM_ITEMS 3 + #endif //GUARD_CONSTANTS_TV_H diff --git a/include/daycare.h b/include/daycare.h index 7d6f2fb19..d6c0d4201 100644 --- a/include/daycare.h +++ b/include/daycare.h @@ -6,7 +6,7 @@ u8 *GetMonNickname2(struct Pokemon *mon, u8 *dest); u8 *GetBoxMonNickname(struct BoxPokemon *mon, u8 *dest); u8 CountPokemonInDaycare(struct DayCare *daycare); -void InitDaycareMailRecordMixing(struct DayCare *daycare, struct RecordMixingDayCareMail *daycareMail); +void InitDaycareMailRecordMixing(struct DayCare *daycare, struct RecordMixingDaycareMail *daycareMail); void StoreSelectedPokemonInDaycare(void); u16 TakePokemonFromDaycare(void); void GetDaycareCost(void); diff --git a/include/global.h b/include/global.h index 19605ca57..e4c11f9ef 100644 --- a/include/global.h +++ b/include/global.h @@ -727,7 +727,7 @@ struct ContestWinner u8 contestRank; }; -struct DayCareMail +struct DaycareMail { struct MailStruct message; u8 OT_name[PLAYER_NAME_LENGTH + 1]; @@ -739,7 +739,7 @@ struct DayCareMail struct DaycareMon { struct BoxPokemon mon; - struct DayCareMail mail; + struct DaycareMail mail; u32 steps; }; @@ -750,9 +750,9 @@ struct DayCare u8 stepCounter; }; -struct RecordMixingDayCareMail +struct RecordMixingDaycareMail { - struct DayCareMail mail[DAYCARE_MON_COUNT]; + struct DaycareMail mail[DAYCARE_MON_COUNT]; u32 numDaycareMons; bool16 holdsItem[DAYCARE_MON_COUNT]; }; diff --git a/include/global.tv.h b/include/global.tv.h index 64e6a984e..2bc7dda99 100644 --- a/include/global.tv.h +++ b/include/global.tv.h @@ -1,13 +1,15 @@ #ifndef GUARD_GLOBAL_TV_H #define GUARD_GLOBAL_TV_H +#include "constants/tv.h" + typedef union // size = 0x24 { // Common struct { /*0x00*/ u8 kind; /*0x01*/ bool8 active; - /*0x02*/ u8 pad02[26]; + /*0x02*/ u8 data[26]; /*0x1C*/ u8 srcTrainerId3Lo; /*0x1D*/ u8 srcTrainerId3Hi; /*0x1E*/ u8 srcTrainerId2Lo; @@ -22,7 +24,7 @@ typedef union // size = 0x24 struct { /*0x00*/ u8 kind; /*0x01*/ bool8 active; - /*0x02*/ u8 pad02[34]; + /*0x02*/ u8 data[34]; } commonInit; // Local shows @@ -40,7 +42,7 @@ typedef union // size = 0x24 struct { /*0x00*/ u8 kind; /*0x01*/ bool8 active; - /*0x02*/ u16 var02; + /*0x02*/ u16 species; /*0x04*/ u16 words[6]; /*0x10*/ u8 playerName[PLAYER_NAME_LENGTH + 1]; /*0x18*/ u8 language; @@ -62,16 +64,16 @@ typedef union // size = 0x24 /*0x1C*/ u16 words[4]; } fanclubOpinions; - // TVSHOW_UNKN_SHOWTYPE_04 (dummied out) + // TVSHOW_DUMMY struct { /*0x00*/ u8 kind; /*0x01*/ bool8 active; /*0x02*/ u16 words[2]; - /*0x06*/ u16 var06; + /*0x06*/ u16 species; /*0x08*/ u8 pad_08[3]; - /*0x0b*/ u8 string_0b[12]; + /*0x0b*/ u8 name[12]; /*0x17*/ u8 language; - } unkShow04; + } dummy; // TVSHOW_NAME_RATER_SHOW struct { @@ -212,8 +214,8 @@ typedef union // size = 0x24 /*0x02*/ u8 priceReduced; /*0x03*/ u8 language; /*0x04*/ u8 pad04[2]; - /*0x06*/ u16 itemIds[3]; - /*0x0C*/ u16 itemAmounts[3]; + /*0x06*/ u16 itemIds[SMARTSHOPPER_NUM_ITEMS]; + /*0x0C*/ u16 itemAmounts[SMARTSHOPPER_NUM_ITEMS]; /*0x12*/ u8 shopLocation; /*0x13*/ u8 playerName[PLAYER_NAME_LENGTH + 1]; } smartshopperShow; @@ -401,7 +403,7 @@ typedef union // size = 0x24 /*0x08*/ u16 species3; /*0x0a*/ u16 species4; /*0x0c*/ u8 language; - /*0x0d*/ u8 facility; + /*0x0d*/ u8 facilityAndMode; /*0x0e*/ u8 filler_0e[5]; /*0x13*/ u8 playerName[PLAYER_NAME_LENGTH + 1]; } frontier; diff --git a/include/mauville_old_man.h b/include/mauville_old_man.h index 29c66a992..603d585da 100644 --- a/include/mauville_old_man.h +++ b/include/mauville_old_man.h @@ -7,7 +7,7 @@ void SetMauvilleOldMan(void); u8 GetCurrentMauvilleOldMan(void); void ScrSpecial_SetMauvilleOldManObjEventGfx(void); u8 sub_81201C8(void); -void sub_8120B70(OldMan *dest); +void SanitizeMauvilleOldManForRuby(OldMan *dest); void sub_8120670(void); void SanitizeReceivedRubyOldMan(union OldMan * oldMan, u32 r1, u32 r6); void SanitizeReceivedEmeraldOldMan(union OldMan * oldMan, u32 unused, u32 a2); diff --git a/include/tv.h b/include/tv.h index f94c5b7e5..30cd13326 100644 --- a/include/tv.h +++ b/include/tv.h @@ -1,13 +1,10 @@ #ifndef GUARD_TV_H #define GUARD_TV_H -#define SLOT_MACHINE 0 -#define ROULETTE 1 - extern u8 *const gTVStringVarPtrs[3]; void ClearTVShowData(void); -void sub_80EE184(void); +void TryPutBreakingNewsOnAir(void); void TryPutBattleSeminarOnAir(u16 foeSpecies, u16 species, u8 moveIdx, const u16 *movePtr, u16 betterMove); void TryPutFrontierTVShowOnAir(u16 winStreak, u8 facility); void DoTVShow(void); @@ -23,41 +20,37 @@ void ReceiveTvShowsData(void *src, u32 size, u8 masterIdx); void TryPutSpotTheCutiesOnAir(struct Pokemon *pokemon, u8 ribbonMonDataIdx); u32 GetPlayerIDAsU32(void); bool8 GetPriceReduction(u8 newsKind); -void sub_80F14F8(TVShow *shows); +void SanitizeTVShowLocationsForRuby(TVShow *shows); size_t CountDigits(int value); u8 GetRibbonCount(struct Pokemon *pokemon); void AlertTVThatPlayerPlayedSlotMachine(u16 nCoinsSpent); void AlertTVThatPlayerPlayedRoulette(u16 nCoinsSpent); -void AlertTVOfNewCoinTotal(u16 nCoinsPaidOut); +void TryPutFindThatGamerOnAir(u16 nCoinsPaidOut); void TryPutSecretBaseSecretsOnAir(void); void TryPutTodaysRivalTrainerOnAir(void); void TryPutTrendWatcherOnAir(const u16 *words); -void sub_80EDA80(void); void ReceivePokeNewsData(void *src, u32 size, u8 masterIdx); -void sub_80F0BB8(void); +void DeactivateAllNormalTVShows(void); void RecordFishingAttemptForTV(bool8 caughtFish); void IncrementDailySlotsUses(void); void IncrementDailyRouletteUses(void); void IncrementDailyWildBattles(void); void IncrementDailyBerryBlender(void); -void sub_80F1208(TVShow *shows); -void sub_80EE44C(u8 nMonsCaught, u8 nPkblkUsed); -void sub_80F14F8(TVShow *shows); -size_t sub_80EF370(int value); +void SanitizeTVShowsForRuby(TVShow *shows); +void TryPutSafariFanClubOnAir(u8 nMonsCaught, u8 nPkblkUsed); bool8 Put3CheersForPokeblocksOnTheAir(const u8 *partnersName, u8 flavor, u8 unused, u8 sheen, u8 language); void SetPokemonAnglerSpecies(u16 species); void UpdateTVShowsPerDay(u16 days); -void PutPokemonTodayCaughtOnAir(void); -void TV_PutSecretBaseVisitOnTheAir(void); +void TryPutPokemonTodayOnAir(void); +void TryPutSecretBaseVisitOnAir(void); void PutBattleUpdateOnTheAir(u8 opponentLinkPlayerId, u16 move, u16 speciesPlayer, u16 speciesOpponent); void BravoTrainerPokemonProfile_BeforeInterview1(u16 move); void InterviewBefore(void); void InterviewAfter(void); void UpdateTVScreensOnMap(int, int); -void TV_PrintIntToStringVar(u8 varIdx, int value); -void SaveRecordedItemPurchasesForTVShow(void); +void ConvertIntToDecimalString(u8 varIdx, int value); +void TryPutSmartShopperOnAir(void); bool8 ShouldAirFrontierTVShow(void); -void sub_80EE8C8(u16 winStreak, u8 facilityAndMode); void BravoTrainerPokemonProfile_BeforeInterview2(u8 contestStandingPlace); void ContestLiveUpdates_Init(u8 round1Placing); void ContestLiveUpdates_SetRound2Placing(u8 round2Placing); @@ -65,5 +58,8 @@ void ContestLiveUpdates_SetWinnerAppealFlag(u8 flag); void ContestLiveUpdates_SetWinnerMoveUsed(u16 move); void ContestLiveUpdates_SetLoserData(u8 flag, u8 loser); void ResetGabbyAndTy(void); +u8 CheckForPlayersHouseNews(void); +bool8 IsGabbyAndTyShowOnTheAir(void); +void TryPutTrainerFanClubOnAir(void); #endif //GUARD_TV_H diff --git a/src/battle_main.c b/src/battle_main.c index 741461b0b..c74de896e 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -5039,7 +5039,7 @@ static void HandleEndTurn_FinishBattle(void) } } } - PutPokemonTodayCaughtOnAir(); + TryPutPokemonTodayOnAir(); } if (!(gBattleTypeFlags & (BATTLE_TYPE_LINK @@ -5052,7 +5052,7 @@ static void HandleEndTurn_FinishBattle(void) | BATTLE_TYPE_WALLY_TUTORIAL)) && gBattleResults.shinyWildMon) { - sub_80EE184(); + TryPutBreakingNewsOnAir(); } sub_8186444(); diff --git a/src/battle_tower.c b/src/battle_tower.c index b1e5d7817..082ea6822 100644 --- a/src/battle_tower.c +++ b/src/battle_tower.c @@ -36,7 +36,6 @@ #include "constants/event_objects.h" #include "constants/moves.h" #include "constants/easy_chat.h" -#include "constants/tv.h" extern const u8 MossdeepCity_SpaceCenter_2F_EventScript_MaxieTrainer[]; extern const u8 MossdeepCity_SpaceCenter_2F_EventScript_TabithaTrainer[]; diff --git a/src/contest.c b/src/contest.c index 246fc1e50..1549544df 100644 --- a/src/contest.c +++ b/src/contest.c @@ -42,7 +42,6 @@ #include "constants/moves.h" #include "constants/rgb.h" #include "constants/songs.h" -#include "constants/tv.h" // This file's functions. static void LoadContestPalettes(void); diff --git a/src/contest_util.c b/src/contest_util.c index 98854c4c6..40c964bac 100644 --- a/src/contest_util.c +++ b/src/contest_util.c @@ -44,7 +44,6 @@ #include "constants/game_stat.h" #include "constants/rgb.h" #include "constants/songs.h" -#include "constants/tv.h" #include "contest.h" enum { diff --git a/src/daycare.c b/src/daycare.c index 14cf57806..34b864981 100644 --- a/src/daycare.c +++ b/src/daycare.c @@ -24,7 +24,7 @@ #include "constants/region_map_sections.h" // this file's functions -static void ClearDaycareMonMail(struct DayCareMail *mail); +static void ClearDaycareMonMail(struct DaycareMail *mail); static void SetInitialEggData(struct Pokemon *mon, u16 species, struct DayCare *daycare); static u8 GetDaycareCompatibilityScore(struct DayCare *daycare); static void DaycarePrintMonInfo(u8 windowId, s32 daycareSlotId, u8 y); @@ -120,7 +120,7 @@ u8 CountPokemonInDaycare(struct DayCare *daycare) return count; } -void InitDaycareMailRecordMixing(struct DayCare *daycare, struct RecordMixingDayCareMail *daycareMail) +void InitDaycareMailRecordMixing(struct DayCare *daycare, struct RecordMixingDaycareMail *daycareMail) { u8 i; u8 numDaycareMons = 0; @@ -131,13 +131,9 @@ void InitDaycareMailRecordMixing(struct DayCare *daycare, struct RecordMixingDay { numDaycareMons++; if (GetBoxMonData(&daycare->mons[i].mon, MON_DATA_HELD_ITEM) == ITEM_NONE) - { daycareMail->holdsItem[i] = FALSE; - } else - { daycareMail->holdsItem[i] = TRUE; - } } else { @@ -154,7 +150,7 @@ static s8 Daycare_FindEmptySpot(struct DayCare *daycare) for (i = 0; i < DAYCARE_MON_COUNT; i++) { - if (GetBoxMonData(&daycare->mons[i].mon, MON_DATA_SPECIES) == 0) + if (GetBoxMonData(&daycare->mons[i].mon, MON_DATA_SPECIES) == SPECIES_NONE) return i; } @@ -349,7 +345,7 @@ u8 GetNumLevelsGainedFromDaycare(void) return 0; } -static void ClearDaycareMonMail(struct DayCareMail *mail) +static void ClearDaycareMonMail(struct DaycareMail *mail) { s32 i; diff --git a/src/decoration.c b/src/decoration.c index b9a243708..6b6cf21e8 100644 --- a/src/decoration.c +++ b/src/decoration.c @@ -1652,7 +1652,7 @@ static void PlaceDecoration(u8 taskId) gSprites[sDecor_CameraSpriteObjectIdx1].pos1.y += 2; if (gMapHeader.regionMapSectionId == MAPSEC_SECRET_BASE) - TV_PutSecretBaseVisitOnTheAir(); + TryPutSecretBaseVisitOnAir(); CancelDecorating_(taskId); } @@ -2260,7 +2260,7 @@ static void Task_PutAwayDecoration(u8 taskId) StringExpandPlaceholders(gStringVar4, gText_DecorationReturnedToPC); DisplayItemMessageOnField(taskId, gStringVar4, ContinuePuttingAwayDecorationsPrompt); if (gMapHeader.regionMapSectionId == MAPSEC_SECRET_BASE) - TV_PutSecretBaseVisitOnTheAir(); + TryPutSecretBaseVisitOnAir(); } break; } diff --git a/src/easy_chat.c b/src/easy_chat.c index 96d680840..753c2df76 100644 --- a/src/easy_chat.c +++ b/src/easy_chat.c @@ -1474,8 +1474,8 @@ void ShowEasyChatScreen(void) words = &gSaveBlock1Ptr->tvShows[gSpecialVar_0x8005].fanclubOpinions.words[gSpecialVar_0x8006]; displayedPersonType = EASY_CHAT_PERSON_REPORTER_FEMALE; break; - case EASY_CHAT_TYPE_UNK_8: - words = gSaveBlock1Ptr->tvShows[gSpecialVar_0x8005].unkShow04.words; + case EASY_CHAT_TYPE_DUMMY_SHOW: + words = gSaveBlock1Ptr->tvShows[gSpecialVar_0x8005].dummy.words; displayedPersonType = EASY_CHAT_PERSON_REPORTER_MALE; break; case EASY_CHAT_TYPE_TRENDY_PHRASE: diff --git a/src/field_specials.c b/src/field_specials.c index df16583ed..13fad83b1 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -57,7 +57,6 @@ #include "constants/map_types.h" #include "constants/maps.h" #include "constants/mevent.h" -#include "constants/tv.h" #include "constants/script_menu.h" #include "constants/slot_machine.h" #include "constants/songs.h" @@ -1622,7 +1621,7 @@ void BufferLottoTicketNumber(void) { if (gSpecialVar_Result >= 10000) { - TV_PrintIntToStringVar(0, gSpecialVar_Result); + ConvertIntToDecimalString(0, gSpecialVar_Result); } else if (gSpecialVar_Result >= 1000) { diff --git a/src/fldeff_misc.c b/src/fldeff_misc.c index 914ba2880..3d3b83fef 100644 --- a/src/fldeff_misc.c +++ b/src/fldeff_misc.c @@ -22,7 +22,6 @@ #include "constants/metatile_behaviors.h" #include "constants/metatile_labels.h" #include "constants/songs.h" -#include "constants/tv.h" EWRAM_DATA struct MapPosition gPlayerFacingPosition = {0}; diff --git a/src/frontier_util.c b/src/frontier_util.c index 491aef936..4aec27944 100644 --- a/src/frontier_util.c +++ b/src/frontier_util.c @@ -1552,16 +1552,16 @@ static void CheckPutFrontierTVShowOnAir(void) switch (battleMode) { case FRONTIER_MODE_SINGLES: - TryPutFrontierTVShowOnAir(gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode], 1); + TryPutFrontierTVShowOnAir(gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode], FRONTIER_SHOW_TOWER_SINGLES); break; case FRONTIER_MODE_DOUBLES: - TryPutFrontierTVShowOnAir(gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode], 2); + TryPutFrontierTVShowOnAir(gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode], FRONTIER_SHOW_TOWER_DOUBLES); break; case FRONTIER_MODE_MULTIS: - TryPutFrontierTVShowOnAir(gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode], 3); + TryPutFrontierTVShowOnAir(gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode], FRONTIER_SHOW_TOWER_MULTIS); break; case FRONTIER_MODE_LINK_MULTIS: - TryPutFrontierTVShowOnAir(gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode], 4); + TryPutFrontierTVShowOnAir(gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode], FRONTIER_SHOW_TOWER_LINK_MULTIS); break; } } @@ -1575,9 +1575,9 @@ static void CheckPutFrontierTVShowOnAir(void) && ShouldAirFrontierTVShow()) { if (battleMode == FRONTIER_MODE_SINGLES) - TryPutFrontierTVShowOnAir(gSaveBlock2Ptr->frontier.domeWinStreaks[battleMode][lvlMode], 5); + TryPutFrontierTVShowOnAir(gSaveBlock2Ptr->frontier.domeWinStreaks[battleMode][lvlMode], FRONTIER_SHOW_DOME_SINGLES); else - TryPutFrontierTVShowOnAir(gSaveBlock2Ptr->frontier.domeWinStreaks[battleMode][lvlMode], 6); + TryPutFrontierTVShowOnAir(gSaveBlock2Ptr->frontier.domeWinStreaks[battleMode][lvlMode], FRONTIER_SHOW_DOME_DOUBLES); } } break; @@ -1589,9 +1589,9 @@ static void CheckPutFrontierTVShowOnAir(void) && ShouldAirFrontierTVShow()) { if (battleMode == FRONTIER_MODE_SINGLES) - TryPutFrontierTVShowOnAir(gSaveBlock2Ptr->frontier.palaceWinStreaks[battleMode][lvlMode], 11); + TryPutFrontierTVShowOnAir(gSaveBlock2Ptr->frontier.palaceWinStreaks[battleMode][lvlMode], FRONTIER_SHOW_PALACE_SINGLES); else - TryPutFrontierTVShowOnAir(gSaveBlock2Ptr->frontier.palaceWinStreaks[battleMode][lvlMode], 12); + TryPutFrontierTVShowOnAir(gSaveBlock2Ptr->frontier.palaceWinStreaks[battleMode][lvlMode], FRONTIER_SHOW_PALACE_DOUBLES); } } break; @@ -1602,7 +1602,7 @@ static void CheckPutFrontierTVShowOnAir(void) if (gSaveBlock2Ptr->frontier.arenaWinStreaks[lvlMode] > 1 && ShouldAirFrontierTVShow()) { - TryPutFrontierTVShowOnAir(gSaveBlock2Ptr->frontier.arenaWinStreaks[lvlMode], 10); + TryPutFrontierTVShowOnAir(gSaveBlock2Ptr->frontier.arenaWinStreaks[lvlMode], FRONTIER_SHOW_ARENA); } } break; @@ -1615,9 +1615,9 @@ static void CheckPutFrontierTVShowOnAir(void) && ShouldAirFrontierTVShow()) { if (battleMode == FRONTIER_MODE_SINGLES) - TryPutFrontierTVShowOnAir(gSaveBlock2Ptr->frontier.factoryWinStreaks[battleMode][lvlMode], 7); + TryPutFrontierTVShowOnAir(gSaveBlock2Ptr->frontier.factoryWinStreaks[battleMode][lvlMode], FRONTIER_SHOW_FACTORY_SINGLES); else - TryPutFrontierTVShowOnAir(gSaveBlock2Ptr->frontier.factoryWinStreaks[battleMode][lvlMode], 8); + TryPutFrontierTVShowOnAir(gSaveBlock2Ptr->frontier.factoryWinStreaks[battleMode][lvlMode], FRONTIER_SHOW_FACTORY_DOUBLES); } } break; @@ -1628,7 +1628,7 @@ static void CheckPutFrontierTVShowOnAir(void) if (gSaveBlock2Ptr->frontier.pikeWinStreaks[lvlMode] > 1 && ShouldAirFrontierTVShow()) { - TryPutFrontierTVShowOnAir(gSaveBlock2Ptr->frontier.pikeWinStreaks[lvlMode], 9); + TryPutFrontierTVShowOnAir(gSaveBlock2Ptr->frontier.pikeWinStreaks[lvlMode], FRONTIER_SHOW_PIKE); } } break; @@ -1639,7 +1639,7 @@ static void CheckPutFrontierTVShowOnAir(void) if (gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] > 1 && ShouldAirFrontierTVShow()) { - TryPutFrontierTVShowOnAir(gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode], 13); + TryPutFrontierTVShowOnAir(gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode], FRONTIER_SHOW_PYRAMID); } } break; diff --git a/src/item.c b/src/item.c index 892092184..8259d1cd5 100644 --- a/src/item.c +++ b/src/item.c @@ -14,7 +14,6 @@ #include "battle_pyramid_bag.h" #include "constants/items.h" #include "constants/hold_effects.h" -#include "constants/tv.h" extern u16 gUnknown_0203CF30[]; diff --git a/src/mauville_old_man.c b/src/mauville_old_man.c index 228415628..239639e0b 100644 --- a/src/mauville_old_man.c +++ b/src/mauville_old_man.c @@ -680,45 +680,43 @@ void ScrSpecial_SetMauvilleOldManObjEventGfx(void) // Language fixers? -void sub_8120B70(union OldMan * oldMan) +void SanitizeMauvilleOldManForRuby(union OldMan * oldMan) { s32 i; u8 playerName[PLAYER_NAME_LENGTH + 1]; switch (oldMan->common.id) { - case MAUVILLE_MAN_TRADER: + case MAUVILLE_MAN_TRADER: + { + struct MauvilleOldManTrader * trader = &oldMan->trader; + for (i = 0; i < NUM_TRADER_ITEMS; i++) { - struct MauvilleOldManTrader * trader = &oldMan->trader; - for (i = 0; i < NUM_TRADER_ITEMS; i++) + if (trader->language[i] == LANGUAGE_JAPANESE) + ConvertInternationalString(trader->playerNames[i], LANGUAGE_JAPANESE); + } + break; + } + case MAUVILLE_MAN_STORYTELLER: + { + struct MauvilleManStoryteller * storyteller = &oldMan->storyteller; + for (i = 0; i < NUM_STORYTELLER_TALES; i++) + { + if (storyteller->gameStatIDs[i] != 0) { - if (trader->language[i] == LANGUAGE_JAPANESE) + memcpy(playerName, storyteller->trainerNames[i], PLAYER_NAME_LENGTH); + playerName[PLAYER_NAME_LENGTH] = EOS; + if (IsStringJapanese(playerName)) { - ConvertInternationalString(trader->playerNames[i], LANGUAGE_JAPANESE); + memset(playerName, CHAR_SPACE, PLAYER_NAME_LENGTH + 1); + StringCopy(playerName, gText_Friend); + memcpy(storyteller->trainerNames[i], playerName, PLAYER_NAME_LENGTH); + storyteller->language[i] = GAME_LANGUAGE; } } } - break; - case MAUVILLE_MAN_STORYTELLER: - { - struct MauvilleManStoryteller * storyteller = &oldMan->storyteller; - for (i = 0; i < NUM_STORYTELLER_TALES; i++) - { - if (storyteller->gameStatIDs[i] != 0) - { - memcpy(playerName, storyteller->trainerNames[i], PLAYER_NAME_LENGTH); - playerName[PLAYER_NAME_LENGTH] = EOS; - if (IsStringJapanese(playerName)) - { - memset(playerName, CHAR_SPACE, PLAYER_NAME_LENGTH + 1); - StringCopy(playerName, gText_Friend); - memcpy(storyteller->trainerNames[i], playerName, PLAYER_NAME_LENGTH); - storyteller->language[i] = GAME_LANGUAGE; - } - } - } - } - break; + break; + } } } diff --git a/src/menu.c b/src/menu.c index 44b39d762..c01a69b12 100644 --- a/src/menu.c +++ b/src/menu.c @@ -509,12 +509,14 @@ void RemoveStartMenuWindow(void) } } -u16 sub_8197A30(void) +// Unused +static u16 GetDialogFrameBaseTileNum(void) { return DLG_WINDOW_BASE_TILE_NUM; } -u16 sub_8197A38(void) +// Unused +static u16 GetStandardFrameBaseTileNum(void) { return STD_WINDOW_BASE_TILE_NUM; } diff --git a/src/post_battle_event_funcs.c b/src/post_battle_event_funcs.c index 78ebe02e4..081a40218 100644 --- a/src/post_battle_event_funcs.c +++ b/src/post_battle_event_funcs.c @@ -8,7 +8,6 @@ #include "script_pokemon_util.h" #include "tv.h" #include "constants/heal_locations.h" -#include "constants/tv.h" int GameClear(void) { diff --git a/src/record_mixing.c b/src/record_mixing.c index 7cc88a54c..aa6e4eef2 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -51,7 +51,7 @@ struct PlayerRecordsRS PokeNews pokeNews[POKE_NEWS_COUNT]; OldMan oldMan; struct DewfordTrend dewfordTrends[SAVED_TRENDS_COUNT]; - struct RecordMixingDayCareMail dayCareMail; + struct RecordMixingDaycareMail daycareMail; struct RSBattleTowerRecord battleTowerRecord; u16 giftItem; u16 filler11C8[0x32]; @@ -64,7 +64,7 @@ struct PlayerRecordsEmerald /* 0x1004 */ PokeNews pokeNews[POKE_NEWS_COUNT]; /* 0x1044 */ OldMan oldMan; /* 0x1084 */ struct DewfordTrend dewfordTrends[SAVED_TRENDS_COUNT]; - /* 0x10ac */ struct RecordMixingDayCareMail dayCareMail; + /* 0x10ac */ struct RecordMixingDaycareMail daycareMail; /* 0x1124 */ struct EmeraldBattleTowerRecord battleTowerRecord; /* 0x1210 */ u16 giftItem; /* 0x1214 */ LilycoveLady lilycoveLady; @@ -87,7 +87,7 @@ static TVShow *sTvShowsSave; static PokeNews *sPokeNewsSave; static OldMan *sOldManSave; static struct DewfordTrend *sDewfordTrendsSave; -static struct RecordMixingDayCareMail *gUnknown_03001148; +static struct RecordMixingDaycareMail *sDaycareMailSave; static void *sBattleTowerSave; static LilycoveLady *sLilycoveLadySave; static void *sApprenticesSave; @@ -96,7 +96,7 @@ static u32 sRecordStructSize; static u8 gUnknown_03001160; static struct PlayerHallRecords *gUnknown_03001168[3]; -static EWRAM_DATA struct RecordMixingDayCareMail gUnknown_02039F9C = {0}; +static EWRAM_DATA struct RecordMixingDaycareMail sDaycareMail = {0}; static EWRAM_DATA union PlayerRecords *sReceivedRecords = NULL; static EWRAM_DATA union PlayerRecords *sSentRecord = NULL; @@ -115,14 +115,14 @@ static void ReceiveOldManData(OldMan *, size_t, u8); static void ReceiveBattleTowerData(void *battleTowerRecord, size_t, u8); static void ReceiveLilycoveLadyData(LilycoveLady *, size_t, u8); static void sub_80E7B2C(const u8 *); -static void ReceiveDaycareMailData(struct RecordMixingDayCareMail *, size_t, u8, TVShow *); +static void ReceiveDaycareMailData(struct RecordMixingDaycareMail *, size_t, u8, TVShow *); static void ReceiveGiftItem(u16 *item, u8 which); static void Task_DoRecordMixing(u8 taskId); static void GetSavedApprentices(struct Apprentice *dst, struct Apprentice *src); static void ReceiveApprenticeData(struct Apprentice *mixApprentice, size_t recordSize, u32 multiplayerId); static void ReceiveRankingHallRecords(struct PlayerHallRecords *hallRecords, size_t arg1, u32 arg2); -static void sub_80E89F8(struct RecordMixingDayCareMail *dst); -static void SanitizeDayCareMailForRuby(struct RecordMixingDayCareMail *src); +static void GetRecordMixingDaycareMail(struct RecordMixingDaycareMail *dst); +static void SanitizeDaycareMailForRuby(struct RecordMixingDaycareMail *src); static void SanitizeEmeraldBattleTowerRecord(struct EmeraldBattleTowerRecord *arg0); static void SanitizeRubyBattleTowerRecord(struct RSBattleTowerRecord *src); @@ -180,7 +180,7 @@ static void SetSrcLookupPointers(void) sPokeNewsSave = gSaveBlock1Ptr->pokeNews; sOldManSave = &gSaveBlock1Ptr->oldMan; sDewfordTrendsSave = gSaveBlock1Ptr->dewfordTrends; - gUnknown_03001148 = &gUnknown_02039F9C; + sDaycareMailSave = &sDaycareMail; sBattleTowerSave = &gSaveBlock2Ptr->frontier.towerPlayer; sLilycoveLadySave = &gSaveBlock1Ptr->lilycoveLady; sApprenticesSave = gSaveBlock2Ptr->apprentices; @@ -191,11 +191,11 @@ static void PrepareUnknownExchangePacket(struct PlayerRecordsRS *dest) { memcpy(dest->secretBases, sSecretBasesSave, sizeof(dest->secretBases)); memcpy(dest->tvShows, sTvShowsSave, sizeof(dest->tvShows)); - sub_80F14F8(dest->tvShows); + SanitizeTVShowLocationsForRuby(dest->tvShows); memcpy(dest->pokeNews, sPokeNewsSave, sizeof(dest->pokeNews)); memcpy(&dest->oldMan, sOldManSave, sizeof(dest->oldMan)); memcpy(dest->dewfordTrends, sDewfordTrendsSave, sizeof(dest->dewfordTrends)); - sub_80E89F8(&dest->dayCareMail); + GetRecordMixingDaycareMail(&dest->daycareMail); EmeraldBattleTowerRecordToRuby(sBattleTowerSave, &dest->battleTowerRecord); if (GetMultiplayerId() == 0) @@ -207,13 +207,13 @@ static void PrepareExchangePacketForRubySapphire(struct PlayerRecordsRS *dest) memcpy(dest->secretBases, sSecretBasesSave, sizeof(dest->secretBases)); ClearJapaneseSecretBases(dest->secretBases); memcpy(dest->tvShows, sTvShowsSave, sizeof(dest->tvShows)); - sub_80F1208(dest->tvShows); + SanitizeTVShowsForRuby(dest->tvShows); memcpy(dest->pokeNews, sPokeNewsSave, sizeof(dest->pokeNews)); memcpy(&dest->oldMan, sOldManSave, sizeof(dest->oldMan)); - sub_8120B70(&dest->oldMan); + SanitizeMauvilleOldManForRuby(&dest->oldMan); memcpy(dest->dewfordTrends, sDewfordTrendsSave, sizeof(dest->dewfordTrends)); - sub_80E89F8(&dest->dayCareMail); - SanitizeDayCareMailForRuby(&dest->dayCareMail); + GetRecordMixingDaycareMail(&dest->daycareMail); + SanitizeDaycareMailForRuby(&dest->daycareMail); EmeraldBattleTowerRecordToRuby(sBattleTowerSave, &dest->battleTowerRecord); SanitizeRubyBattleTowerRecord(&dest->battleTowerRecord); @@ -224,7 +224,7 @@ static void PrepareExchangePacketForRubySapphire(struct PlayerRecordsRS *dest) static void PrepareExchangePacket(void) { SetPlayerSecretBaseParty(); - sub_80F0BB8(); + DeactivateAllNormalTVShows(); SetSrcLookupPointers(); if (Link_AnyPartnersPlayingRubyOrSapphire()) @@ -242,7 +242,7 @@ static void PrepareExchangePacket(void) memcpy(&sSentRecord->emerald.oldMan, sOldManSave, sizeof(sSentRecord->emerald.oldMan)); memcpy(&sSentRecord->emerald.lilycoveLady, sLilycoveLadySave, sizeof(sSentRecord->emerald.lilycoveLady)); memcpy(sSentRecord->emerald.dewfordTrends, sDewfordTrendsSave, sizeof(sSentRecord->emerald.dewfordTrends)); - sub_80E89F8(&sSentRecord->emerald.dayCareMail); + GetRecordMixingDaycareMail(&sSentRecord->emerald.daycareMail); memcpy(&sSentRecord->emerald.battleTowerRecord, sBattleTowerSave, sizeof(sSentRecord->emerald.battleTowerRecord)); SanitizeEmeraldBattleTowerRecord(&sSentRecord->emerald.battleTowerRecord); @@ -261,7 +261,7 @@ static void ReceiveExchangePacket(u32 which) // Ruby/Sapphire sub_80E7B2C((void *)sReceivedRecords->ruby.tvShows); ReceiveSecretBasesData(sReceivedRecords->ruby.secretBases, sizeof(struct PlayerRecordsRS), which); - ReceiveDaycareMailData(&sReceivedRecords->ruby.dayCareMail, sizeof(struct PlayerRecordsRS), which, sReceivedRecords->ruby.tvShows); + ReceiveDaycareMailData(&sReceivedRecords->ruby.daycareMail, sizeof(struct PlayerRecordsRS), which, sReceivedRecords->ruby.tvShows); ReceiveBattleTowerData(&sReceivedRecords->ruby.battleTowerRecord, sizeof(struct PlayerRecordsRS), which); ReceiveTvShowsData(sReceivedRecords->ruby.tvShows, sizeof(struct PlayerRecordsRS), which); ReceivePokeNewsData(sReceivedRecords->ruby.pokeNews, sizeof(struct PlayerRecordsRS), which); @@ -278,7 +278,7 @@ static void ReceiveExchangePacket(u32 which) ReceivePokeNewsData(sReceivedRecords->emerald.pokeNews, sizeof(struct PlayerRecordsEmerald), which); ReceiveOldManData(&sReceivedRecords->emerald.oldMan, sizeof(struct PlayerRecordsEmerald), which); ReceiveDewfordTrendData(sReceivedRecords->emerald.dewfordTrends, sizeof(struct PlayerRecordsEmerald), which); - ReceiveDaycareMailData(&sReceivedRecords->emerald.dayCareMail, sizeof(struct PlayerRecordsEmerald), which, sReceivedRecords->emerald.tvShows); + ReceiveDaycareMailData(&sReceivedRecords->emerald.daycareMail, sizeof(struct PlayerRecordsEmerald), which, sReceivedRecords->emerald.tvShows); ReceiveBattleTowerData(&sReceivedRecords->emerald.battleTowerRecord, sizeof(struct PlayerRecordsEmerald), which); ReceiveGiftItem(&sReceivedRecords->emerald.giftItem, which); ReceiveLilycoveLadyData(&sReceivedRecords->emerald.lilycoveLady, sizeof(struct PlayerRecordsEmerald), which); @@ -319,7 +319,7 @@ static void Task_RecordMixing_Main(u8 taskId) { case 0: // init sSentRecord = malloc(sizeof(union PlayerRecords)); - sReceivedRecords = malloc(sizeof(union PlayerRecords) * 4); + sReceivedRecords = malloc(sizeof(union PlayerRecords) * MAX_LINK_PLAYERS); SetLocalLinkPlayerId(gSpecialVar_0x8005); VarSet(VAR_TEMP_0, 1); gUnknown_03001130 = FALSE; @@ -665,7 +665,7 @@ static void ReceiveBattleTowerData(void *battleTowerRecord, size_t recordSize, u { memcpy((void *)battleTowerRecord + recordSize * which, (void *)battleTowerRecord + recordSize * mixIndices[which], sizeof(struct EmeraldBattleTowerRecord)); dest = (void *)battleTowerRecord + recordSize * which; - for (i = 0; i < 4; i ++) + for (i = 0; i < MAX_FRONTIER_PARTY_SIZE; i++) { btPokemon = &dest->party[i]; if (btPokemon->species != SPECIES_NONE && IsStringJapanese(btPokemon->nickname)) @@ -706,22 +706,22 @@ static void ReceiveLilycoveLadyData(LilycoveLady *lilycoveLady, size_t recordSiz } } -static u8 sub_80E7A9C(struct DayCareMail *rmMail) +static u8 sub_80E7A9C(struct DaycareMail *rmMail) { return rmMail->message.itemId; } -static void sub_80E7AA4(struct RecordMixingDayCareMail *src, size_t recordSize, u8 (*idxs)[2], u8 which0, u8 which1) +static void sub_80E7AA4(struct RecordMixingDaycareMail *src, size_t recordSize, u8 (*idxs)[2], u8 which0, u8 which1) { - struct DayCareMail buffer; - struct RecordMixingDayCareMail *mail1; - struct RecordMixingDayCareMail *mail2; + struct DaycareMail buffer; + struct RecordMixingDaycareMail *mail1; + struct RecordMixingDaycareMail *mail2; mail1 = (void *)src + recordSize * idxs[which0][0]; - memcpy(&buffer, &mail1->mail[idxs[which0][1]], sizeof(struct DayCareMail)); + memcpy(&buffer, &mail1->mail[idxs[which0][1]], sizeof(struct DaycareMail)); mail2 = (void *)src + recordSize * idxs[which1][0]; - memcpy(&mail1->mail[idxs[which0][1]], &mail2->mail[idxs[which1][1]], sizeof(struct DayCareMail)); - memcpy(&mail2->mail[idxs[which1][1]], &buffer, sizeof(struct DayCareMail)); + memcpy(&mail1->mail[idxs[which0][1]], &mail2->mail[idxs[which1][1]], sizeof(struct DaycareMail)); + memcpy(&mail2->mail[idxs[which1][1]], &buffer, sizeof(struct DaycareMail)); } static void sub_80E7B2C(const u8 *src) @@ -730,7 +730,7 @@ static void sub_80E7B2C(const u8 *src) s32 i; sum = 0; - for (i = 0; i < 256; i ++) + for (i = 0; i < 256; i++) sum += src[i]; gUnknown_03001160 = sum; @@ -741,17 +741,17 @@ static u8 sub_80E7B54(void) return gUnknown_03001160; } -static void ReceiveDaycareMailData(struct RecordMixingDayCareMail *src, size_t recordSize, u8 which, TVShow *shows) +static void ReceiveDaycareMailData(struct RecordMixingDaycareMail *src, size_t recordSize, u8 which, TVShow *shows) { u16 i, j; u8 linkPlayerCount; u8 tableId; - struct RecordMixingDayCareMail *_src; + struct RecordMixingDaycareMail *_src; u8 which0, which1; void *ptr; u8 sp04[4]; u8 sp08[4]; - struct RecordMixingDayCareMail *sp0c[4]; + struct RecordMixingDaycareMail *sp0c[4]; u8 sp1c[4][2]; u8 sp24[4][2]; u8 sp34; @@ -777,10 +777,10 @@ static void ReceiveDaycareMailData(struct RecordMixingDayCareMail *src, size_t r _src = (void *)src + i * recordSize; language = gLinkPlayers[i].language; version = gLinkPlayers[i].version & 0xFF; - for (j = 0; j < _src->numDaycareMons; j ++) + for (j = 0; j < _src->numDaycareMons; j++) { u16 otNameLanguage, nicknameLanguage; - struct DayCareMail *recordMixingMail = &_src->mail[j]; + struct DaycareMail *recordMixingMail = &_src->mail[j]; if (!recordMixingMail->message.itemId) continue; @@ -835,7 +835,7 @@ static void ReceiveDaycareMailData(struct RecordMixingDayCareMail *src, size_t r if (_src->numDaycareMons == 0) continue; - for (j = 0; j < _src->numDaycareMons; j ++) + for (j = 0; j < _src->numDaycareMons; j++) { if (!_src->holdsItem[j]) sp1c[i][j] = 1; @@ -913,8 +913,8 @@ static void ReceiveDaycareMailData(struct RecordMixingDayCareMail *src, size_t r } _src = (void *)src + which * recordSize; - memcpy(&gSaveBlock1Ptr->daycare.mons[0].mail, &_src->mail[0], sizeof(struct DayCareMail)); - memcpy(&gSaveBlock1Ptr->daycare.mons[1].mail, &_src->mail[1], sizeof(struct DayCareMail)); + memcpy(&gSaveBlock1Ptr->daycare.mons[0].mail, &_src->mail[0], sizeof(struct DaycareMail)); + memcpy(&gSaveBlock1Ptr->daycare.mons[1].mail, &_src->mail[1], sizeof(struct DaycareMail)); SeedRng(oldSeed); } @@ -957,7 +957,7 @@ static void Task_DoRecordMixing(u8 taskId) case 2: SetContinueGameWarpStatusToDynamicWarp(); FullSaveGame(); - task->data[0] ++; + task->data[0]++; break; case 3: if (CheckSaveFile()) @@ -971,7 +971,7 @@ static void Task_DoRecordMixing(u8 taskId) if (++task->data[1] > 10) { SetCloseLinkCallback(); - task->data[0] ++; + task->data[0]++; } break; case 5: @@ -984,7 +984,7 @@ static void Task_DoRecordMixing(u8 taskId) if (!sub_801048C(FALSE)) { CreateTask(Task_LinkSave, 5); - task->data[0] ++; + task->data[0]++; } break; case 7: // wait for Task_LinkSave to finish. @@ -1003,7 +1003,7 @@ static void Task_DoRecordMixing(u8 taskId) break; case 8: SetLinkStandbyCallback(); - task->data[0] ++; + task->data[0]++; break; case 9: if (IsLinkTaskFinished()) @@ -1061,13 +1061,9 @@ static void GetSavedApprentices(struct Apprentice *dst, struct Apprentice *src) break; case 2: if (Random2() > 0x3333) - { dst[1] = src[gSaveBlock2Ptr->playerApprentice.saveId + 1]; - } else - { dst[1] = src[((gSaveBlock2Ptr->playerApprentice.saveId + 1) % (APPRENTICE_COUNT - 1) + 1)]; - } break; } } @@ -1221,7 +1217,7 @@ static void sub_80E8578(struct RecordMixingHallRecords *dst, void *hallRecords, for (l = 0; l < 3; l++) { if (GetTrainerId(dst->hallRecords2P[j][l].id1) == GetTrainerId(gUnknown_03001168[k]->twoPlayers[j].id1) - && GetTrainerId(dst->hallRecords2P[j][l].id2) == GetTrainerId(gUnknown_03001168[k]->twoPlayers[j].id2)) + && GetTrainerId(dst->hallRecords2P[j][l].id2) == GetTrainerId(gUnknown_03001168[k]->twoPlayers[j].id2)) { var_68++; if (dst->hallRecords2P[j][l].winStreak < gUnknown_03001168[k]->twoPlayers[j].winStreak) @@ -1308,21 +1304,21 @@ static void ReceiveRankingHallRecords(struct PlayerHallRecords *hallRecords, siz Free(largeStructPtr); } -static void sub_80E89F8(struct RecordMixingDayCareMail *dst) +static void GetRecordMixingDaycareMail(struct RecordMixingDaycareMail *dst) { - gUnknown_02039F9C.mail[0] = gSaveBlock1Ptr->daycare.mons[0].mail; - gUnknown_02039F9C.mail[1] = gSaveBlock1Ptr->daycare.mons[1].mail; - InitDaycareMailRecordMixing(&gSaveBlock1Ptr->daycare, &gUnknown_02039F9C); - *dst = *gUnknown_03001148; + sDaycareMail.mail[0] = gSaveBlock1Ptr->daycare.mons[0].mail; + sDaycareMail.mail[1] = gSaveBlock1Ptr->daycare.mons[1].mail; + InitDaycareMailRecordMixing(&gSaveBlock1Ptr->daycare, &sDaycareMail); + *dst = *sDaycareMailSave; } -static void SanitizeDayCareMailForRuby(struct RecordMixingDayCareMail *src) +static void SanitizeDaycareMailForRuby(struct RecordMixingDaycareMail *src) { s32 i; for (i = 0; i < src->numDaycareMons; i++) { - struct DayCareMail *mail = &src->mail[i]; + struct DaycareMail *mail = &src->mail[i]; if (mail->message.itemId != 0) { if (mail->gameLanguage != LANGUAGE_JAPANESE) @@ -1342,10 +1338,10 @@ static void SanitizeEmeraldBattleTowerRecord(struct EmeraldBattleTowerRecord *ds { s32 i; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_FRONTIER_PARTY_SIZE; i++) { struct BattleTowerPokemon *towerMon = &dst->party[i]; - if (towerMon->species != 0) + if (towerMon->species != SPECIES_NONE) StripExtCtrlCodes(towerMon->nickname); } diff --git a/src/roulette.c b/src/roulette.c index f0b484fe8..cf27fdf9b 100644 --- a/src/roulette.c +++ b/src/roulette.c @@ -1968,7 +1968,7 @@ static void ExitRoulette(u8 taskId) gSpecialVar_0x8004 = TRUE; else gSpecialVar_0x8004 = FALSE; - AlertTVOfNewCoinTotal(GetCoins()); + TryPutFindThatGamerOnAir(GetCoins()); BeginHardwarePaletteFade(0xFF, 0, 0, 16, 0); gTasks[taskId].func = Task_ExitRoulette; } diff --git a/src/safari_zone.c b/src/safari_zone.c index 3b86bc464..1f1397656 100644 --- a/src/safari_zone.c +++ b/src/safari_zone.c @@ -65,7 +65,7 @@ void EnterSafariMode(void) void ExitSafariMode(void) { - sub_80EE44C(sSafariZoneCaughtMons, sSafariZonePkblkUses); + TryPutSafariFanClubOnAir(sSafariZoneCaughtMons, sSafariZonePkblkUses); ResetSafariZoneFlag(); ClearAllPokeblockFeeders(); gNumSafariBalls = 0; diff --git a/src/script_pokemon_util.c b/src/script_pokemon_util.c index ad1a55230..93a747772 100755 --- a/src/script_pokemon_util.c +++ b/src/script_pokemon_util.c @@ -22,7 +22,6 @@ #include "string_util.h" #include "tv.h" #include "constants/items.h" -#include "constants/tv.h" #include "constants/battle_frontier.h" static void CB2_ReturnFromChooseHalfParty(void); diff --git a/src/secret_base.c b/src/secret_base.c index ddc051dca..e1c62e2f2 100644 --- a/src/secret_base.c +++ b/src/secret_base.c @@ -47,7 +47,6 @@ #include "constants/secret_bases.h" #include "constants/songs.h" #include "constants/trainers.h" -#include "constants/tv.h" // Values for registryStatus enum { diff --git a/src/shop.c b/src/shop.c index dac43c96d..55b421928 100755 --- a/src/shop.c +++ b/src/shop.c @@ -38,7 +38,6 @@ #include "constants/metatile_behaviors.h" #include "constants/rgb.h" #include "constants/songs.h" -#include "constants/tv.h" #define TAG_SCROLL_ARROW 2100 #define TAG_ITEM_ICON_BASE 2110 @@ -48,7 +47,7 @@ static EWRAM_DATA struct ShopData *sShopData = NULL; static EWRAM_DATA struct ListMenuItem *sListMenuItems = NULL; static EWRAM_DATA u8 (*sItemNames)[16] = {0}; static EWRAM_DATA u8 sPurchaseHistoryId = 0; -EWRAM_DATA struct ItemSlot gMartPurchaseHistory[3] = {0}; +EWRAM_DATA struct ItemSlot gMartPurchaseHistory[SMARTSHOPPER_NUM_ITEMS] = {0}; static void Task_ShopMenu(u8 taskId); static void Task_HandleShopMenuQuit(u8 taskId); @@ -373,7 +372,7 @@ static void Task_HandleShopMenuQuit(u8 taskId) { ClearStdWindowAndFrameToTransparent(sMartInfo.windowId, 2); RemoveWindow(sMartInfo.windowId); - SaveRecordedItemPurchasesForTVShow(); + TryPutSmartShopperOnAir(); ScriptContext2_Disable(); DestroyTask(taskId); diff --git a/src/slot_machine.c b/src/slot_machine.c index aa32d5d95..9a3a9ee06 100644 --- a/src/slot_machine.c +++ b/src/slot_machine.c @@ -1592,7 +1592,7 @@ static bool8 SlotAction_WaitMsg_NoMoreCoins(struct Task *task) static bool8 SlotAction_EndGame(struct Task *task) { SetCoins(sSlotMachine->coins); - AlertTVOfNewCoinTotal(GetCoins()); + TryPutFindThatGamerOnAir(GetCoins()); BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB(0, 0, 0)); sSlotMachine->state++; // SLOT_ACTION_FREE return FALSE; diff --git a/src/tv.c b/src/tv.c index 0466ee713..50adde3f4 100644 --- a/src/tv.c +++ b/src/tv.c @@ -41,18 +41,27 @@ #include "constants/lilycove_lady.h" #include "constants/maps.h" #include "constants/metatile_behaviors.h" +#include "constants/metatile_labels.h" #include "constants/moves.h" #include "constants/region_map_sections.h" #include "constants/script_menu.h" -#include "constants/tv.h" - -// Static type declarations #define LAST_TVSHOW_IDX (TV_SHOWS_COUNT - 1) -#define rbernoulli(num, den) TV_BernoulliTrial(0xFFFF * (num) / (den)) +#define rbernoulli(num, den) BernoulliTrial(0xFFFF * (num) / (den)) -// Static RAM declarations +enum { + TVGROUP_NONE, + TVGROUP_UNUSED, + TVGROUP_NORMAL, + TVGROUP_RECORD_MIX, + TVGROUP_OUTBREAK, +}; + +enum { + SLOT_MACHINE, + ROULETTE, +}; s8 sCurTVShowSlot; u16 sTV_SecretBaseVisitMovesTemp[8]; @@ -67,79 +76,77 @@ static u8 sTVShowMixingNumPlayers; static u8 sTVShowNewsMixingNumPlayers; static s8 sTVShowMixingCurSlot; -EWRAM_DATA u16 sPokemonAnglerSpecies = 0; -EWRAM_DATA u16 sPokemonAnglerAttemptCounters = 0; -EWRAM_DATA u16 sFindThatGamerCoinsSpent = 0; -EWRAM_DATA u8 sFindThatGamerWhichGame = SLOT_MACHINE; -EWRAM_DATA ALIGNED(4) u8 sRecordMixingPartnersWithoutShowsToShare = 0; -EWRAM_DATA ALIGNED(4) u8 sTVShowState = 0; -EWRAM_DATA u8 sTVSecretBaseSecretsRandomValues[3] = {}; +static EWRAM_DATA u16 sPokemonAnglerSpecies = 0; +static EWRAM_DATA u16 sPokemonAnglerAttemptCounters = 0; +static EWRAM_DATA u16 sFindThatGamerCoinsSpent = 0; +static EWRAM_DATA u8 sFindThatGamerWhichGame = SLOT_MACHINE; +static EWRAM_DATA ALIGNED(4) u8 sRecordMixingPartnersWithoutShowsToShare = 0; +static EWRAM_DATA ALIGNED(4) u8 sTVShowState = 0; +static EWRAM_DATA u8 sTVSecretBaseSecretsRandomValues[3] = {}; -// Static ROM declarations -void ClearPokemonNews(void); -u8 GetTVChannelByShowType(u8 kind); -u8 FindFirstActiveTVShowThatIsNotAMassOutbreak(void); -u8 CheckForBigMovieOrEmergencyNewsOnTV(void); -void SetTVMetatilesOnMap(int width, int height, u16 tileId); -u8 FindAnyTVNewsOnTheAir(void); -bool8 IsTVShowInSearchOfTrainersAiring(void); -void TakeTVShowInSearchOfTrainersOffTheAir(void); -bool8 TV_BernoulliTrial(u16 ratio); -s8 FindEmptyTVSlotBeyondFirstFiveShowsOfArray(TVShow *shows); -bool8 HasMixableShowAlreadyBeenSpawnedWithPlayerID(u8 kind, bool8 flag); -void tv_store_id_3x(TVShow *show); -void DeleteTVShowInArrayByIdx(TVShow *shows, u8 idx); -s8 FindEmptyTVSlotWithinFirstFiveShowsOfArray(TVShow *shows); -void FindActiveBroadcastByShowType_SetScriptResult(u8 kind); +static void ClearPokeNews(void); +static u8 GetTVGroupByShowId(u8); +static u8 FindFirstActiveTVShowThatIsNotAMassOutbreak(void); +static void SetTVMetatilesOnMap(int, int, u16); +static u8 FindAnyPokeNewsOnTheAir(void); +static void TakeGabbyAndTyOffTheAir(void); +static bool8 BernoulliTrial(u16 ratio); +static s8 FindFirstEmptyRecordMixTVShowSlot(TVShow *); +static bool8 IsRecordMixShowAlreadySpawned(u8, bool8); +static void StorePlayerIdInRecordMixShow(TVShow *); +static void DeleteTVShowInArrayByIdx(TVShow *, u8); +static s8 FindFirstEmptyNormalTVShowSlot(TVShow *); +static void TryReplaceOldTVShowOfKind(u8); static void InterviewBefore_BravoTrainerPkmnProfile(void); static void InterviewBefore_NameRater(void); -u16 TV_GetSomeOtherSpeciesAlreadySeenByPlayer(u16 passedSpecies); -static void sub_80EFA88(void); -static void sub_80EF93C(TVShow *shows); -s8 sub_80EEE30(PokeNews *pokeNews); -bool8 sub_80EF0E4(u8 newsKind); -void ClearPokemonNewsI(u8 i); -static void sub_80F1254(TVShow *shows); -static void sub_80F12A4(TVShow *shows); -static void sub_80F0358(TVShow *player1, TVShow *player2, TVShow *player3, TVShow *player4); -static void sub_80F0C04(void); -static void sub_80F0708(void); -static void sub_80F0B64(void); -static s8 sub_80F06D0(TVShow *tvShows); -static bool8 sub_80F049C(TVShow *dest[], TVShow *src[], u8 idx); -static bool8 sub_80F0580(TVShow *tv1, TVShow *tv2, u8 idx); -static bool8 sub_80F05E8(TVShow *tv1, TVShow *tv2, u8 idx); -static bool8 sub_80F0668(TVShow *tv1, TVShow *tv2, u8 idx); -void SetTvShowInactive(u8 showIdx); -static void sub_80F0B24(u16 species, u8 showIdx); -static void sub_80F0D60(PokeNews *player1, PokeNews *player2, PokeNews *player3, PokeNews *player4); -static void sub_80F0EEC(void); -static void sub_80F0F24(void); -static s8 sub_80F0ECC(PokeNews *pokeNews, u8 idx); -static void sub_80F0E58(PokeNews *dest[], PokeNews *src[]); -static bool8 sub_80F0E84(PokeNews *dest, PokeNews *src, s8 slot); -void TVShowDone(void); +static u16 GetRandomDifferentSpeciesSeenByPlayer(u16); +static void Script_FindFirstEmptyNormalTVShowSlot(void); +static void CompactTVShowArray(TVShow *); +static s8 GetFirstEmptyPokeNewsSlot(PokeNews *); +static bool8 IsAddingPokeNewsDisallowed(u8); +static void ClearPokeNewsBySlot(u8); +static void TranslateRubyShows(TVShow *); +static void TranslateJapaneseEmeraldShows(TVShow *); +static void SetMixedTVShows(TVShow *, TVShow *, TVShow *, TVShow *); +static void DeleteExcessMixedShows(void); +static void DeactivateShowsWithUnseenSpecies(void); +static void DeactivateGameCompleteShowsIfNotUnlocked(void); +static s8 FindInactiveShowInArray(TVShow *); +static bool8 TryMixTVShow(TVShow *[], TVShow *[], u8); +static bool8 TryMixNormalTVShow(TVShow *, TVShow *, u8); +static bool8 TryMixRecordMixTVShow(TVShow *, TVShow *, u8); +static bool8 TryMixOutbreakTVShow(TVShow *, TVShow *, u8); +static void DeactivateShow(u8 showIdx); +static void DeactivateShowIfNotSeenSpecies(u16, u8); +static void SetMixedPokeNews(PokeNews *, PokeNews *, PokeNews *, PokeNews *); +static void ClearInvalidPokeNews(void); +static void ClearPokeNewsIfGameNotComplete(void); +static s8 GetPokeNewsSlotIfActive(PokeNews *, u8); +static void InitTryMixPokeNewsShow(PokeNews *[], PokeNews *[]); +static bool8 TryMixPokeNewsShow(PokeNews *, PokeNews *, s8); +static void TVShowDone(void); static void InterviewAfter_FanClubLetter(void); static void InterviewAfter_RecentHappenings(void); static void InterviewAfter_PkmnFanClubOpinions(void); -static void InterviewAfter_DummyShow4(void); +static void InterviewAfter_Dummy(void); static void InterviewAfter_BravoTrainerPokemonProfile(void); static void InterviewAfter_BravoTrainerBattleTowerProfile(void); static void InterviewAfter_ContestLiveUpdates(void); -void UpdateWorldOfMastersAndPutItOnTheAir(void); -void PutPokemonTodayFailedOnTheAir(void); -static void sub_80ED718(void); -static void sub_80EED88(void); -void TV_SortPurchasesByQuantity(void); -static void UpdateMassOutbreakTimeLeft(u16 days); -static void TryEndMassOutbreak(u16 days); -static void sub_80EF120(u16 days); -static void sub_80EDA48(u16 days); -static void sub_80EEB98(u16 days); -void PutFishingAdviceShowOnTheAir(void); -static u8 MonDataIdxToRibbon(u8 monDataIdx); -static void sub_80EEBF4(u8 actionIdx); -bool8 IsPriceDiscounted(u8 newsKind); +static void InitWorldOfMastersShowAttempt(void); +static void TryPutPokemonTodayFailedOnTheAir(void); +static void TryStartRandomMassOutbreak(void); +static void TryPutRandomPokeNewsOnAir(void); +static void SortPurchasesByQuantity(void); +static void UpdateMassOutbreakTimeLeft(u16); +static void TryEndMassOutbreak(u16); +static void UpdatePokeNewsTimeLeft(u16); +static void ResolveWorldOfMastersShow(u16); +static void ResolveNumberOneShow(u16); +static void TryPutFishingAdviceOnAir(void); +static u8 MonDataIdxToRibbon(u8); +static void TryPutNumberOneOnAir(u8); +static bool8 IsPriceDiscounted(u8); +static void TryPutWorldOfMastersOnAir(void); static void InterviewBefore_FanClubLetter(void); static void InterviewBefore_RecentHappenings(void); static void InterviewBefore_PkmnFanClubOpinions(void); @@ -148,7 +155,7 @@ static void InterviewBefore_BravoTrainerBTProfile(void); static void InterviewBefore_ContestLiveUpdates(void); static void InterviewBefore_3CheersForPokeblocks(void); static void InterviewBefore_FanClubSpecial(void); -void ChangeBoxPokemonNickname_CB(void); +static void ChangeBoxPokemonNickname_CB(void); static void DoTVShowPokemonFanClubLetter(void); static void DoTVShowRecentHappenings(void); static void DoTVShowPokemonFanClubOpinions(void); @@ -182,8 +189,6 @@ static void DoTVShowSecretBaseSecrets(void); static void DoTVShowSafariFanClub(void); static void DoTVShowLilycoveContestLady(void); -// .rodata - static const struct { u16 species; u16 moves[MAX_MON_MOVES]; @@ -753,23 +758,18 @@ const u8 sTVSecretBaseSecretsActions[NUM_SECRET_BASE_FLAGS] = SBSECRETS_NUM_STATES // SECRET_BASE_UNUSED_FLAG. Odd that this is included, if it were used it would overflow sTVSecretBaseSecretsTextGroup }; -// .text - void ClearTVShowData(void) { - u8 i; - u8 j; + u8 i, j; - for (i = 0; i < ARRAY_COUNT(gSaveBlock1Ptr->tvShows); i ++) + for (i = 0; i < ARRAY_COUNT(gSaveBlock1Ptr->tvShows); i++) { gSaveBlock1Ptr->tvShows[i].commonInit.kind = 0; gSaveBlock1Ptr->tvShows[i].commonInit.active = 0; - for (j = 0; j < ARRAY_COUNT(gSaveBlock1Ptr->tvShows[i].commonInit.pad02); j ++) - { - gSaveBlock1Ptr->tvShows[i].commonInit.pad02[j] = 0; - } + for (j = 0; j < ARRAY_COUNT(gSaveBlock1Ptr->tvShows[i].commonInit.data); j++) + gSaveBlock1Ptr->tvShows[i].commonInit.data[j] = 0; } - ClearPokemonNews(); + ClearPokeNews(); } u8 GetRandomActiveShowIdx(void) @@ -779,7 +779,8 @@ u8 GetRandomActiveShowIdx(void) u8 selIdx; TVShow *show; - for (i = 5; i < ARRAY_COUNT(gSaveBlock1Ptr->tvShows) - 1; i ++) + // Include all normal TV shows, and up through any present Record Mix shows + for (i = NUM_NORMAL_TVSHOW_SLOTS; i < LAST_TVSHOW_IDX; i++) { if (gSaveBlock1Ptr->tvShows[i].common.kind == TVSHOW_OFF_AIR) break; @@ -788,7 +789,7 @@ u8 GetRandomActiveShowIdx(void) selIdx = j; do { - if (GetTVChannelByShowType(gSaveBlock1Ptr->tvShows[j].common.kind) != 4) + if (GetTVGroupByShowId(gSaveBlock1Ptr->tvShows[j].common.kind) != TVGROUP_OUTBREAK) { if (gSaveBlock1Ptr->tvShows[j].common.active == TRUE) return j; @@ -803,7 +804,7 @@ u8 GetRandomActiveShowIdx(void) if (j == 0) j = ARRAY_COUNT(gSaveBlock1Ptr->tvShows) - 2; else - j --; + j--; } while (j != selIdx); return 0xFF; @@ -811,88 +812,88 @@ u8 GetRandomActiveShowIdx(void) u8 FindAnyTVShowOnTheAir(void) { - u8 show; - - show = GetRandomActiveShowIdx(); - if (show == 0xFF) - { + u8 slot = GetRandomActiveShowIdx(); + if (slot == 0xFF) return 0xFF; - } - if (gSaveBlock1Ptr->outbreakPokemonSpecies != SPECIES_NONE && gSaveBlock1Ptr->tvShows[show].common.kind == TVSHOW_MASS_OUTBREAK) - { + + if (gSaveBlock1Ptr->outbreakPokemonSpecies != SPECIES_NONE + && gSaveBlock1Ptr->tvShows[slot].common.kind == TVSHOW_MASS_OUTBREAK) return FindFirstActiveTVShowThatIsNotAMassOutbreak(); - } - return show; + + return slot; } void UpdateTVScreensOnMap(int width, int height) { FlagSet(FLAG_SYS_TV_WATCH); - switch (CheckForBigMovieOrEmergencyNewsOnTV()) + switch (CheckForPlayersHouseNews()) { - case 1: - SetTVMetatilesOnMap(width, height, 0x3); - break; - case 2: - break; - default: - if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(LILYCOVE_CITY_COVE_LILY_MOTEL_1F) && gSaveBlock1Ptr->location.mapNum == MAP_NUM(LILYCOVE_CITY_COVE_LILY_MOTEL_1F)) - { - SetTVMetatilesOnMap(width, height, 0x3); - } - else if (FlagGet(FLAG_SYS_TV_START) && (FindAnyTVShowOnTheAir() != 0xFF || FindAnyTVNewsOnTheAir() != 0xFF || IsTVShowInSearchOfTrainersAiring())) - { - FlagClear(FLAG_SYS_TV_WATCH); - SetTVMetatilesOnMap(width, height, 0x3); - } - break; + case PLAYERS_HOUSE_TV_LATI: + SetTVMetatilesOnMap(width, height, METATILE_Building_TV_On); + break; + case PLAYERS_HOUSE_TV_MOVIE: + // Don't flash TV for movie text in player's house + break; +// case PLAYERS_HOUSE_TV_NONE: + default: + if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(LILYCOVE_CITY_COVE_LILY_MOTEL_1F) + && gSaveBlock1Ptr->location.mapNum == MAP_NUM(LILYCOVE_CITY_COVE_LILY_MOTEL_1F)) + { + // NPC in Lilycove Hotel is always watching TV + SetTVMetatilesOnMap(width, height, METATILE_Building_TV_On); + } + else if (FlagGet(FLAG_SYS_TV_START) && (FindAnyTVShowOnTheAir() != 0xFF || FindAnyPokeNewsOnTheAir() != 0xFF || IsGabbyAndTyShowOnTheAir())) + { + FlagClear(FLAG_SYS_TV_WATCH); + SetTVMetatilesOnMap(width, height, METATILE_Building_TV_On); + } + break; } } -void SetTVMetatilesOnMap(int width, int height, u16 tileId) +static void SetTVMetatilesOnMap(int width, int height, u16 tileId) { int x; int y; - for (y = 0; y < height; y ++) + for (y = 0; y < height; y++) { - for (x = 0; x < width; x ++) + for (x = 0; x < width; x++) { if (MapGridGetMetatileBehaviorAt(x, y) == MB_TELEVISION) - { MapGridSetMetatileIdAt(x, y, tileId | METATILE_COLLISION_MASK); - } } } } void TurnOffTVScreen(void) { - SetTVMetatilesOnMap(gBackupMapLayout.width, gBackupMapLayout.height, 0x0002); + SetTVMetatilesOnMap(gBackupMapLayout.width, gBackupMapLayout.height, METATILE_Building_TV_Off); DrawWholeMapView(); } void TurnOnTVScreen(void) { - SetTVMetatilesOnMap(gBackupMapLayout.width, gBackupMapLayout.height, 0x0003); + SetTVMetatilesOnMap(gBackupMapLayout.width, gBackupMapLayout.height, METATILE_Building_TV_On); DrawWholeMapView(); } +// gSpecialVar_0x8004 here is set from GetRandomActiveShowIdx in EventScript_TryDoTVShow u8 GetSelectedTVShow(void) { return gSaveBlock1Ptr->tvShows[gSpecialVar_0x8004].common.kind; } -u8 FindFirstActiveTVShowThatIsNotAMassOutbreak(void) +static u8 FindFirstActiveTVShowThatIsNotAMassOutbreak(void) { u8 i; - for (i = 0; i < ARRAY_COUNT(gSaveBlock1Ptr->tvShows) - 1; i ++) + for (i = 0; i < ARRAY_COUNT(gSaveBlock1Ptr->tvShows) - 1; i++) { - if (gSaveBlock1Ptr->tvShows[i].common.kind != TVSHOW_OFF_AIR && gSaveBlock1Ptr->tvShows[i].common.kind != TVSHOW_MASS_OUTBREAK && gSaveBlock1Ptr->tvShows[i].common.active == TRUE) - { + if (gSaveBlock1Ptr->tvShows[i].common.kind != TVSHOW_OFF_AIR + && gSaveBlock1Ptr->tvShows[i].common.kind != TVSHOW_MASS_OUTBREAK + && gSaveBlock1Ptr->tvShows[i].common.active == TRUE) return i; - } } return 0xFF; } @@ -903,9 +904,8 @@ u8 GetNextActiveShowIfMassOutbreak(void) tvShow = &gSaveBlock1Ptr->tvShows[gSpecialVar_0x8004]; if (tvShow->common.kind == TVSHOW_MASS_OUTBREAK && gSaveBlock1Ptr->outbreakPokemonSpecies != SPECIES_NONE) - { return FindFirstActiveTVShowThatIsNotAMassOutbreak(); - } + return gSpecialVar_0x8004; } @@ -941,28 +941,23 @@ void GabbyAndTyBeforeInterview(void) gSaveBlock1Ptr->gabbyAndTyData.lastMove = gBattleResults.lastUsedMovePlayer; if (gSaveBlock1Ptr->gabbyAndTyData.battleNum != 0xFF) { - gSaveBlock1Ptr->gabbyAndTyData.battleNum ++; + gSaveBlock1Ptr->gabbyAndTyData.battleNum++; } gSaveBlock1Ptr->gabbyAndTyData.battleTookMoreThanOneTurn = gBattleResults.playerMonWasDamaged; + if (gBattleResults.playerFaintCounter != 0) - { gSaveBlock1Ptr->gabbyAndTyData.playerLostAMon = TRUE; - } else - { gSaveBlock1Ptr->gabbyAndTyData.playerLostAMon = FALSE; - } + if (gBattleResults.numHealingItemsUsed != 0) - { gSaveBlock1Ptr->gabbyAndTyData.playerUsedHealingItem = TRUE; - } else - { gSaveBlock1Ptr->gabbyAndTyData.playerUsedHealingItem = FALSE; - } + if (!gBattleResults.usedMasterBall) { - for (i = 0; i < POKEBALL_COUNT - 1; i ++) + for (i = 0; i < POKEBALL_COUNT - 1; i++) { if (gBattleResults.catchAttempts[i]) { @@ -973,9 +968,11 @@ void GabbyAndTyBeforeInterview(void) } else { + // Player threw a Master Ball at Gabby and Ty gSaveBlock1Ptr->gabbyAndTyData.playerThrewABall = TRUE; } - TakeTVShowInSearchOfTrainersOffTheAir(); + + TakeGabbyAndTyOffTheAir(); if (gSaveBlock1Ptr->gabbyAndTyData.lastMove == MOVE_NONE) { FlagSet(FLAG_TEMP_1); @@ -993,7 +990,7 @@ void GabbyAndTyAfterInterview(void) IncrementGameStat(GAME_STAT_GOT_INTERVIEWED); } -void TakeTVShowInSearchOfTrainersOffTheAir(void) +static void TakeGabbyAndTyOffTheAir(void) { gSaveBlock1Ptr->gabbyAndTyData.onAir = FALSE; } @@ -1001,13 +998,12 @@ void TakeTVShowInSearchOfTrainersOffTheAir(void) u8 GabbyAndTyGetBattleNum(void) { if (gSaveBlock1Ptr->gabbyAndTyData.battleNum > 5) - { return (gSaveBlock1Ptr->gabbyAndTyData.battleNum % 3) + 6; - } + return gSaveBlock1Ptr->gabbyAndTyData.battleNum; } -bool8 IsTVShowInSearchOfTrainersAiring(void) +bool8 IsGabbyAndTyShowOnTheAir(void) { return gSaveBlock1Ptr->gabbyAndTyData.onAir; } @@ -1026,60 +1022,56 @@ bool8 GabbyAndTyGetLastQuote(void) u8 GabbyAndTyGetLastBattleTrivia(void) { if (!gSaveBlock1Ptr->gabbyAndTyData.battleTookMoreThanOneTurn2) - { return 1; - } + if (gSaveBlock1Ptr->gabbyAndTyData.playerThrewABall2) - { return 2; - } + if (gSaveBlock1Ptr->gabbyAndTyData.playerUsedHealingItem2) - { return 3; - } + if (gSaveBlock1Ptr->gabbyAndTyData.playerLostAMon2) - { return 4; - } + return 0; } -void GabbyAndTySetScriptVarsToObjectEventLocalIds(void) +void GetGabbyAndTyLocalIds(void) { switch (GabbyAndTyGetBattleNum()) { - case 1: - gSpecialVar_0x8004 = 14; - gSpecialVar_0x8005 = 13; - break; - case 2: - gSpecialVar_0x8004 = 5; - gSpecialVar_0x8005 = 6; - break; - case 3: - gSpecialVar_0x8004 = 18; - gSpecialVar_0x8005 = 17; - break; - case 4: - gSpecialVar_0x8004 = 21; - gSpecialVar_0x8005 = 22; - break; - case 5: - gSpecialVar_0x8004 = 8; - gSpecialVar_0x8005 = 9; - break; - case 6: - gSpecialVar_0x8004 = 19; - gSpecialVar_0x8005 = 20; - break; - case 7: - gSpecialVar_0x8004 = 23; - gSpecialVar_0x8005 = 24; - break; - case 8: - gSpecialVar_0x8004 = 10; - gSpecialVar_0x8005 = 11; - break; + case 1: + gSpecialVar_0x8004 = 14; + gSpecialVar_0x8005 = 13; + break; + case 2: + gSpecialVar_0x8004 = 5; + gSpecialVar_0x8005 = 6; + break; + case 3: + gSpecialVar_0x8004 = 18; + gSpecialVar_0x8005 = 17; + break; + case 4: + gSpecialVar_0x8004 = 21; + gSpecialVar_0x8005 = 22; + break; + case 5: + gSpecialVar_0x8004 = 8; + gSpecialVar_0x8005 = 9; + break; + case 6: + gSpecialVar_0x8004 = 19; + gSpecialVar_0x8005 = 20; + break; + case 7: + gSpecialVar_0x8004 = 23; + gSpecialVar_0x8005 = 24; + break; + case 8: + gSpecialVar_0x8004 = 10; + gSpecialVar_0x8005 = 11; + break; } } @@ -1087,88 +1079,85 @@ void InterviewAfter(void) { switch (gSpecialVar_0x8005) { - case TVSHOW_FAN_CLUB_LETTER: - InterviewAfter_FanClubLetter(); - break; - case TVSHOW_RECENT_HAPPENINGS: - InterviewAfter_RecentHappenings(); - break; - case TVSHOW_PKMN_FAN_CLUB_OPINIONS: - InterviewAfter_PkmnFanClubOpinions(); - break; - case TVSHOW_UNKN_SHOWTYPE_04: - InterviewAfter_DummyShow4(); - break; - case TVSHOW_BRAVO_TRAINER_POKEMON_PROFILE: - InterviewAfter_BravoTrainerPokemonProfile(); - break; - case TVSHOW_BRAVO_TRAINER_BATTLE_TOWER_PROFILE: - InterviewAfter_BravoTrainerBattleTowerProfile(); - break; - case TVSHOW_CONTEST_LIVE_UPDATES: - InterviewAfter_ContestLiveUpdates(); - break; + case TVSHOW_FAN_CLUB_LETTER: + InterviewAfter_FanClubLetter(); + break; + case TVSHOW_RECENT_HAPPENINGS: + InterviewAfter_RecentHappenings(); + break; + case TVSHOW_PKMN_FAN_CLUB_OPINIONS: + InterviewAfter_PkmnFanClubOpinions(); + break; + case TVSHOW_DUMMY: + InterviewAfter_Dummy(); + break; + case TVSHOW_BRAVO_TRAINER_POKEMON_PROFILE: + InterviewAfter_BravoTrainerPokemonProfile(); + break; + case TVSHOW_BRAVO_TRAINER_BATTLE_TOWER_PROFILE: + InterviewAfter_BravoTrainerBattleTowerProfile(); + break; + case TVSHOW_CONTEST_LIVE_UPDATES: + InterviewAfter_ContestLiveUpdates(); + break; } } -void PutPokemonTodayCaughtOnAir(void) +void TryPutPokemonTodayOnAir(void) { u8 i; - u16 ct; + u16 ballsUsed; TVShow *show; u32 language2; u16 itemLastUsed; - ct = 0; - sub_80EED88(); - sub_80ED718(); + ballsUsed = 0; + TryPutRandomPokeNewsOnAir(); + TryStartRandomMassOutbreak(); + + // Try either the Failed or Caught version of the show if (gBattleResults.caughtMonSpecies == SPECIES_NONE) { - PutPokemonTodayFailedOnTheAir(); + TryPutPokemonTodayFailedOnTheAir(); } else { - UpdateWorldOfMastersAndPutItOnTheAir(); + InitWorldOfMastersShowAttempt(); if (!rbernoulli(1, 1) && StringCompare(gSpeciesNames[gBattleResults.caughtMonSpecies], gBattleResults.caughtMonNick)) { - sCurTVShowSlot = FindEmptyTVSlotBeyondFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); - if (sCurTVShowSlot != -1 && HasMixableShowAlreadyBeenSpawnedWithPlayerID(TVSHOW_POKEMON_TODAY_CAUGHT, FALSE) != TRUE) + sCurTVShowSlot = FindFirstEmptyRecordMixTVShowSlot(gSaveBlock1Ptr->tvShows); + if (sCurTVShowSlot != -1 && IsRecordMixShowAlreadySpawned(TVSHOW_POKEMON_TODAY_CAUGHT, FALSE) != TRUE) { - for (i = 0; i < POKEBALL_COUNT - 1; i ++) + for (i = 0; i < POKEBALL_COUNT - 1; i++) + ballsUsed += gBattleResults.catchAttempts[i]; + + if (ballsUsed != 0 || gBattleResults.usedMasterBall) { - ct += gBattleResults.catchAttempts[i]; - } - if (ct != 0 || gBattleResults.usedMasterBall) - { - ct = 0; + ballsUsed = 0; show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; show->pokemonToday.kind = TVSHOW_POKEMON_TODAY_CAUGHT; - show->pokemonToday.active = FALSE; + show->pokemonToday.active = FALSE; // NOTE: Show is not active until passed via Record Mix. if (gBattleResults.usedMasterBall) { - ct = 1; + ballsUsed = 1; itemLastUsed = ITEM_MASTER_BALL; } else { - for (i = 0; i < POKEBALL_COUNT - 1; i ++) - { - ct += gBattleResults.catchAttempts[i]; - } - if (ct > 0xFF) - { - ct = 0xFF; - } + for (i = 0; i < POKEBALL_COUNT - 1; i++) + ballsUsed += gBattleResults.catchAttempts[i]; + if (ballsUsed > 255) + ballsUsed = 255; itemLastUsed = gLastUsedItem; } - show->pokemonToday.nBallsUsed = ct; + show->pokemonToday.nBallsUsed = ballsUsed; show->pokemonToday.ball = itemLastUsed; StringCopy(show->pokemonToday.playerName, gSaveBlock2Ptr->playerName); StringCopy(show->pokemonToday.nickname, gBattleResults.caughtMonNick); language2 = sub_81DB604(show->pokemonToday.nickname); StripExtCtrlCodes(show->pokemonToday.nickname); show->pokemonToday.species = gBattleResults.caughtMonSpecies; - tv_store_id_3x(show); + StorePlayerIdInRecordMixShow(show); show->pokemonToday.language = gGameLanguage; show->pokemonToday.language2 = language2; } @@ -1177,65 +1166,60 @@ void PutPokemonTodayCaughtOnAir(void) } } -void UpdateWorldOfMastersAndPutItOnTheAir(void) +// Show is initialized in last slot and updated there until it's +// either triggered or deleted at the end of the day by ResolveWorldOfMastersShow +static void InitWorldOfMastersShowAttempt(void) { - TVShow *show; - - show = &gSaveBlock1Ptr->tvShows[LAST_TVSHOW_IDX]; - if (show->worldOfMasters.kind != TVSHOW_WORLD_OF_MASTERS) + TVShow *show = &gSaveBlock1Ptr->tvShows[LAST_TVSHOW_IDX]; + if (show->common.kind != TVSHOW_WORLD_OF_MASTERS) { DeleteTVShowInArrayByIdx(gSaveBlock1Ptr->tvShows, LAST_TVSHOW_IDX); show->worldOfMasters.steps = GetGameStat(GAME_STAT_STEPS); show->worldOfMasters.kind = TVSHOW_WORLD_OF_MASTERS; } - show->worldOfMasters.numPokeCaught ++; + show->worldOfMasters.numPokeCaught++; show->worldOfMasters.caughtPoke = gBattleResults.caughtMonSpecies; show->worldOfMasters.species = gBattleResults.playerMon1Species; show->worldOfMasters.location = gMapHeader.regionMapSectionId; } -void PutPokemonTodayFailedOnTheAir(void) +static void TryPutPokemonTodayFailedOnTheAir(void) { - u16 ct; + u16 ballsUsed; u8 i; TVShow *show; if (!rbernoulli(1, 1)) { - for (i = 0, ct = 0; i < POKEBALL_COUNT - 1; i ++) + for (i = 0, ballsUsed = 0; i < POKEBALL_COUNT - 1; i++) + ballsUsed += gBattleResults.catchAttempts[i]; + if (ballsUsed > 255) + ballsUsed = 255; + + if (ballsUsed > 2 && (gBattleOutcome == B_OUTCOME_MON_FLED || gBattleOutcome == B_OUTCOME_WON)) { - ct += gBattleResults.catchAttempts[i]; - } - if (ct > 0xFF) - { - ct = 0xFF; - } - if (ct > 2 && (gBattleOutcome == B_OUTCOME_MON_FLED || gBattleOutcome == B_OUTCOME_WON)) - { - sCurTVShowSlot = FindEmptyTVSlotBeyondFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); - if (sCurTVShowSlot != -1 && HasMixableShowAlreadyBeenSpawnedWithPlayerID(TVSHOW_POKEMON_TODAY_FAILED, FALSE) != TRUE) + sCurTVShowSlot = FindFirstEmptyRecordMixTVShowSlot(gSaveBlock1Ptr->tvShows); + if (sCurTVShowSlot != -1 && IsRecordMixShowAlreadySpawned(TVSHOW_POKEMON_TODAY_FAILED, FALSE) != TRUE) { show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; show->pokemonTodayFailed.kind = TVSHOW_POKEMON_TODAY_FAILED; - show->pokemonTodayFailed.active = FALSE; + show->pokemonTodayFailed.active = FALSE; // NOTE: Show is not active until passed via Record Mix. show->pokemonTodayFailed.species = gBattleResults.playerMon1Species; show->pokemonTodayFailed.species2 = gBattleResults.lastOpponentSpecies; - show->pokemonTodayFailed.nBallsUsed = ct; + show->pokemonTodayFailed.nBallsUsed = ballsUsed; show->pokemonTodayFailed.outcome = gBattleOutcome; show->pokemonTodayFailed.location = gMapHeader.regionMapSectionId; StringCopy(show->pokemonTodayFailed.playerName, gSaveBlock2Ptr->playerName); - tv_store_id_3x(show); + StorePlayerIdInRecordMixShow(show); show->pokemonTodayFailed.language = gGameLanguage; } } } } -void tv_store_id_3x(TVShow *show) +static void StorePlayerIdInRecordMixShow(TVShow *show) { - u32 id; - - id = GetPlayerIDAsU32(); + u32 id = GetPlayerIDAsU32(); show->common.srcTrainerId2Lo = id; show->common.srcTrainerId2Hi = id >> 8; show->common.srcTrainerIdLo = id; @@ -1244,11 +1228,9 @@ void tv_store_id_3x(TVShow *show) show->common.trainerIdHi = id >> 8; } -void tv_store_id_2x(TVShow *show) +static void StorePlayerIdInNormalShow(TVShow *show) { - u32 id; - - id = GetPlayerIDAsU32(); + u32 id = GetPlayerIDAsU32(); show->common.srcTrainerIdLo = id; show->common.srcTrainerIdHi = id >> 8; show->common.trainerIdLo = id; @@ -1276,7 +1258,7 @@ static void InterviewAfter_ContestLiveUpdates(void) show2->contestLiveUpdates.move = show->contestLiveUpdates.move; show2->contestLiveUpdates.winnerAppealFlag = show->contestLiveUpdates.winnerAppealFlag; StringCopy(show2->contestLiveUpdates.losingTrainerName, show->contestLiveUpdates.losingTrainerName); - tv_store_id_2x(show2); + StorePlayerIdInNormalShow(show2); show2->contestLiveUpdates.winningTrainerLanguage = gGameLanguage; show2->contestLiveUpdates.losingTrainerLanguage = show->contestLiveUpdates.losingTrainerLanguage; DeleteTVShowInArrayByIdx(gSaveBlock1Ptr->tvShows, LAST_TVSHOW_IDX); @@ -1288,44 +1270,36 @@ void PutBattleUpdateOnTheAir(u8 opponentLinkPlayerId, u16 move, u16 speciesPlaye TVShow *show; u8 name[32]; - sCurTVShowSlot = FindEmptyTVSlotWithinFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); + sCurTVShowSlot = FindFirstEmptyNormalTVShowSlot(gSaveBlock1Ptr->tvShows); if (sCurTVShowSlot != -1) { - FindActiveBroadcastByShowType_SetScriptResult(TVSHOW_BATTLE_UPDATE); - if (gSpecialVar_Result != 1) + TryReplaceOldTVShowOfKind(TVSHOW_BATTLE_UPDATE); + if (gSpecialVar_Result != TRUE) { show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; show->battleUpdate.kind = TVSHOW_BATTLE_UPDATE; show->battleUpdate.active = TRUE; StringCopy(show->battleUpdate.playerName, gSaveBlock2Ptr->playerName); + if (gBattleTypeFlags & BATTLE_TYPE_MULTI) - { show->battleUpdate.battleType = 2; - } else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) - { show->battleUpdate.battleType = 1; - } else - { show->battleUpdate.battleType = 0; - } + show->battleUpdate.move = move; show->battleUpdate.speciesPlayer = speciesPlayer; show->battleUpdate.speciesOpponent = speciesOpponent; StringCopy(name, gLinkPlayers[opponentLinkPlayerId].name); StripExtCtrlCodes(name); StringCopy(show->battleUpdate.linkOpponentName, name); - tv_store_id_2x(show); + StorePlayerIdInNormalShow(show); show->battleUpdate.language = gGameLanguage; if (show->battleUpdate.language == LANGUAGE_JAPANESE || gLinkPlayers[opponentLinkPlayerId].language == LANGUAGE_JAPANESE) - { show->battleUpdate.linkOpponentLanguage = LANGUAGE_JAPANESE; - } else - { show->battleUpdate.linkOpponentLanguage = gLinkPlayers[opponentLinkPlayerId].language; - } } } } @@ -1335,16 +1309,14 @@ bool8 Put3CheersForPokeblocksOnTheAir(const u8 *partnersName, u8 flavor, u8 colo TVShow *show; u8 name[32]; - sCurTVShowSlot = FindEmptyTVSlotWithinFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); + sCurTVShowSlot = FindFirstEmptyNormalTVShowSlot(gSaveBlock1Ptr->tvShows); if (sCurTVShowSlot == -1) - { return FALSE; - } - FindActiveBroadcastByShowType_SetScriptResult(TVSHOW_3_CHEERS_FOR_POKEBLOCKS); - if (gSpecialVar_Result == 1) - { - return FALSE; - } + + TryReplaceOldTVShowOfKind(TVSHOW_3_CHEERS_FOR_POKEBLOCKS); + if (gSpecialVar_Result == TRUE) + return FALSE; // Old show is still active + show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; show->threeCheers.kind = TVSHOW_3_CHEERS_FOR_POKEBLOCKS; show->threeCheers.active = TRUE; @@ -1355,16 +1327,12 @@ bool8 Put3CheersForPokeblocksOnTheAir(const u8 *partnersName, u8 flavor, u8 colo show->threeCheers.flavor = flavor; show->threeCheers.color = color; show->threeCheers.sheen = sheen; - tv_store_id_2x(show); + StorePlayerIdInNormalShow(show); show->threeCheers.language = gGameLanguage; if (show->threeCheers.language == LANGUAGE_JAPANESE || language == LANGUAGE_JAPANESE) - { show->threeCheers.worstBlenderLanguage = LANGUAGE_JAPANESE; - } else - { show->threeCheers.worstBlenderLanguage = language; - } return TRUE; } @@ -1385,16 +1353,12 @@ void PutFanClubSpecialOnTheAir(void) StringCopy(name, gStringVar1); StripExtCtrlCodes(name); StringCopy(show->fanClubSpecial.idolName, name); - tv_store_id_2x(show); + StorePlayerIdInNormalShow(show); show->fanClubSpecial.language = gGameLanguage; if (show->fanClubSpecial.language == LANGUAGE_JAPANESE || gSaveBlock1Ptr->linkBattleRecords.languages[0] == LANGUAGE_JAPANESE) - { show->fanClubSpecial.idolNameLanguage = LANGUAGE_JAPANESE; - } else - { show->fanClubSpecial.idolNameLanguage = gSaveBlock1Ptr->linkBattleRecords.languages[0]; - } } void ContestLiveUpdates_Init(u8 round1Placing) @@ -1402,7 +1366,7 @@ void ContestLiveUpdates_Init(u8 round1Placing) TVShow *show; DeleteTVShowInArrayByIdx(gSaveBlock1Ptr->tvShows, LAST_TVSHOW_IDX); - sCurTVShowSlot = FindEmptyTVSlotWithinFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); + sCurTVShowSlot = FindFirstEmptyNormalTVShowSlot(gSaveBlock1Ptr->tvShows); if (sCurTVShowSlot != -1) { show = &gSaveBlock1Ptr->tvShows[LAST_TVSHOW_IDX]; @@ -1413,64 +1377,45 @@ void ContestLiveUpdates_Init(u8 round1Placing) void ContestLiveUpdates_SetRound2Placing(u8 round2Placing) { - TVShow *show; - - show = &gSaveBlock1Ptr->tvShows[LAST_TVSHOW_IDX]; - sCurTVShowSlot = FindEmptyTVSlotWithinFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); + TVShow *show = &gSaveBlock1Ptr->tvShows[LAST_TVSHOW_IDX]; + sCurTVShowSlot = FindFirstEmptyNormalTVShowSlot(gSaveBlock1Ptr->tvShows); if (sCurTVShowSlot != -1) - { show->contestLiveUpdates.round2Placing = round2Placing; - } } void ContestLiveUpdates_SetWinnerAppealFlag(u8 flag) { - TVShow *show; - - show = &gSaveBlock1Ptr->tvShows[LAST_TVSHOW_IDX]; - sCurTVShowSlot = FindEmptyTVSlotWithinFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); + TVShow *show = &gSaveBlock1Ptr->tvShows[LAST_TVSHOW_IDX]; + sCurTVShowSlot = FindFirstEmptyNormalTVShowSlot(gSaveBlock1Ptr->tvShows); if (sCurTVShowSlot != -1) - { show->contestLiveUpdates.winnerAppealFlag = flag; - } } void ContestLiveUpdates_SetWinnerMoveUsed(u16 move) { - TVShow *show; - - show = &gSaveBlock1Ptr->tvShows[LAST_TVSHOW_IDX]; - sCurTVShowSlot = FindEmptyTVSlotWithinFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); + TVShow *show = &gSaveBlock1Ptr->tvShows[LAST_TVSHOW_IDX]; + sCurTVShowSlot = FindFirstEmptyNormalTVShowSlot(gSaveBlock1Ptr->tvShows); if (sCurTVShowSlot != -1) - { show->contestLiveUpdates.move = move; - } } void ContestLiveUpdates_SetLoserData(u8 flag, u8 loser) { - TVShow *show; - - show = &gSaveBlock1Ptr->tvShows[LAST_TVSHOW_IDX]; - sCurTVShowSlot = FindEmptyTVSlotWithinFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); + TVShow *show = &gSaveBlock1Ptr->tvShows[LAST_TVSHOW_IDX]; + sCurTVShowSlot = FindFirstEmptyNormalTVShowSlot(gSaveBlock1Ptr->tvShows); if (sCurTVShowSlot != -1) { show->contestLiveUpdates.losingSpecies = gContestMons[loser].species; StringCopy(show->contestLiveUpdates.losingTrainerName, gContestMons[loser].trainerName); StripExtCtrlCodes(show->contestLiveUpdates.losingTrainerName); show->contestLiveUpdates.loserAppealFlag = flag; + if (loser + 1 > gNumLinkContestPlayers) - { show->contestLiveUpdates.losingTrainerLanguage = gLinkPlayers[0].language; - } else if (gGameLanguage == LANGUAGE_JAPANESE || gLinkPlayers[loser].language == LANGUAGE_JAPANESE) - { show->contestLiveUpdates.losingTrainerLanguage = LANGUAGE_JAPANESE; - } else - { show->contestLiveUpdates.losingTrainerLanguage = gLinkPlayers[loser].language; - } } } @@ -1493,27 +1438,21 @@ static void InterviewAfter_BravoTrainerPokemonProfile(void) show2->bravoTrainer.move = show->bravoTrainer.move; show2->bravoTrainer.contestResult = show->bravoTrainer.contestResult; show2->bravoTrainer.contestCategory = show->bravoTrainer.contestCategory; - tv_store_id_2x(show2); + StorePlayerIdInNormalShow(show2); show2->bravoTrainer.language = gGameLanguage; if (show2->bravoTrainer.language == LANGUAGE_JAPANESE || show->bravoTrainer.pokemonNameLanguage == LANGUAGE_JAPANESE) - { show2->bravoTrainer.pokemonNameLanguage = LANGUAGE_JAPANESE; - } else - { show2->bravoTrainer.pokemonNameLanguage = show->bravoTrainer.pokemonNameLanguage; - } DeleteTVShowInArrayByIdx(gSaveBlock1Ptr->tvShows, LAST_TVSHOW_IDX); } } void BravoTrainerPokemonProfile_BeforeInterview1(u16 a0) { - TVShow *show; - - show = &gSaveBlock1Ptr->tvShows[LAST_TVSHOW_IDX]; + TVShow *show = &gSaveBlock1Ptr->tvShows[LAST_TVSHOW_IDX]; InterviewBefore_BravoTrainerPkmnProfile(); - sCurTVShowSlot = FindEmptyTVSlotWithinFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); + sCurTVShowSlot = FindFirstEmptyNormalTVShowSlot(gSaveBlock1Ptr->tvShows); if (sCurTVShowSlot != -1) { DeleteTVShowInArrayByIdx(gSaveBlock1Ptr->tvShows, LAST_TVSHOW_IDX); @@ -1524,10 +1463,8 @@ void BravoTrainerPokemonProfile_BeforeInterview1(u16 a0) void BravoTrainerPokemonProfile_BeforeInterview2(u8 contestStandingPlace) { - TVShow *show; - - show = &gSaveBlock1Ptr->tvShows[LAST_TVSHOW_IDX]; - sCurTVShowSlot = FindEmptyTVSlotWithinFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); + TVShow *show = &gSaveBlock1Ptr->tvShows[LAST_TVSHOW_IDX]; + sCurTVShowSlot = FindFirstEmptyNormalTVShowSlot(gSaveBlock1Ptr->tvShows); if (sCurTVShowSlot != -1) { show->bravoTrainer.contestResult = contestStandingPlace; @@ -1542,9 +1479,7 @@ void BravoTrainerPokemonProfile_BeforeInterview2(u8 contestStandingPlace) static void InterviewAfter_BravoTrainerBattleTowerProfile(void) { - TVShow *show; - - show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; + TVShow *show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; show->bravoTrainerTower.kind = TVSHOW_BRAVO_TRAINER_BATTLE_TOWER_PROFILE; show->bravoTrainerTower.active = TRUE; StringCopy(show->bravoTrainerTower.trainerName, gSaveBlock2Ptr->playerName); @@ -1554,27 +1489,19 @@ static void InterviewAfter_BravoTrainerBattleTowerProfile(void) show->bravoTrainerTower.numFights = GetCurrentBattleTowerWinStreak(gSaveBlock2Ptr->frontier.towerLvlMode, 0); show->bravoTrainerTower.wonTheChallenge = gSaveBlock2Ptr->frontier.towerBattleOutcome; if (gSaveBlock2Ptr->frontier.towerLvlMode == FRONTIER_LVL_50) - { show->bravoTrainerTower.btLevel = 50; - } else - { show->bravoTrainerTower.btLevel = 100; - } show->bravoTrainerTower.interviewResponse = gSpecialVar_0x8004; - tv_store_id_2x(show); + StorePlayerIdInNormalShow(show); show->bravoTrainerTower.language = gGameLanguage; if (show->bravoTrainerTower.language == LANGUAGE_JAPANESE || gSaveBlock2Ptr->frontier.towerInterview.opponentLanguage == LANGUAGE_JAPANESE) - { show->bravoTrainerTower.pokemonNameLanguage = LANGUAGE_JAPANESE; - } else - { show->bravoTrainerTower.pokemonNameLanguage = gSaveBlock2Ptr->frontier.towerInterview.opponentLanguage; - } } -void SaveRecordedItemPurchasesForTVShow(void) +void TryPutSmartShopperOnAir(void) { TVShow *show; u8 i; @@ -1583,24 +1510,24 @@ void SaveRecordedItemPurchasesForTVShow(void) && !(gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(BATTLE_FRONTIER_MART) && gSaveBlock1Ptr->location.mapNum == MAP_NUM(BATTLE_FRONTIER_MART)) && !rbernoulli(1, 3)) { - sCurTVShowSlot = FindEmptyTVSlotBeyondFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); - if (sCurTVShowSlot != -1 && HasMixableShowAlreadyBeenSpawnedWithPlayerID(TVSHOW_SMART_SHOPPER, FALSE) != TRUE) + sCurTVShowSlot = FindFirstEmptyRecordMixTVShowSlot(gSaveBlock1Ptr->tvShows); + if (sCurTVShowSlot != -1 && IsRecordMixShowAlreadySpawned(TVSHOW_SMART_SHOPPER, FALSE) != TRUE) { - TV_SortPurchasesByQuantity(); + SortPurchasesByQuantity(); if (gMartPurchaseHistory[0].quantity >= 20) { show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; show->smartshopperShow.kind = TVSHOW_SMART_SHOPPER; - show->smartshopperShow.active = FALSE; + show->smartshopperShow.active = FALSE; // NOTE: Show is not active until passed via Record Mix. show->smartshopperShow.shopLocation = gMapHeader.regionMapSectionId; - for (i = 0; i < 3; i ++) + for (i = 0; i < SMARTSHOPPER_NUM_ITEMS; i++) { show->smartshopperShow.itemIds[i] = gMartPurchaseHistory[i].itemId; show->smartshopperShow.itemAmounts[i] = gMartPurchaseHistory[i].quantity; } show->smartshopperShow.priceReduced = GetPriceReduction(POKENEWS_SLATEPORT); StringCopy(show->smartshopperShow.playerName, gSaveBlock2Ptr->playerName); - tv_store_id_3x(show); + StorePlayerIdInRecordMixShow(show); show->smartshopperShow.language = gGameLanguage; } } @@ -1623,11 +1550,11 @@ void PutNameRaterShowOnTheAir(void) show->nameRaterShow.species = GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_SPECIES, NULL); show->nameRaterShow.random = Random() % 3; show->nameRaterShow.random2 = Random() % 2; - show->nameRaterShow.randomSpecies = TV_GetSomeOtherSpeciesAlreadySeenByPlayer(show->nameRaterShow.species); + show->nameRaterShow.randomSpecies = GetRandomDifferentSpeciesSeenByPlayer(show->nameRaterShow.species); StringCopy(show->nameRaterShow.trainerName, gSaveBlock2Ptr->playerName); GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_NICKNAME, show->nameRaterShow.pokemonName); StripExtCtrlCodes(show->nameRaterShow.pokemonName); - tv_store_id_2x(show); + StorePlayerIdInNormalShow(show); show->nameRaterShow.language = gGameLanguage; show->nameRaterShow.pokemonNameLanguage = GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_LANGUAGE); } @@ -1636,9 +1563,7 @@ void PutNameRaterShowOnTheAir(void) void StartMassOutbreak(void) { - TVShow *show; - - show = &gSaveBlock1Ptr->tvShows[gSpecialVar_0x8004]; + TVShow *show = &gSaveBlock1Ptr->tvShows[gSpecialVar_0x8004]; gSaveBlock1Ptr->outbreakPokemonSpecies = show->massOutbreak.species; gSaveBlock1Ptr->outbreakLocationMapNum = show->massOutbreak.locationMapNum; gSaveBlock1Ptr->outbreakLocationMapGroup = show->massOutbreak.locationMapGroup; @@ -1658,7 +1583,7 @@ void PutLilycoveContestLadyShowOnTheAir(void) { TVShow *show; - sub_80EFA88(); + Script_FindFirstEmptyNormalTVShowSlot(); if (gSpecialVar_Result != TRUE) { show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; @@ -1669,41 +1594,35 @@ void PutLilycoveContestLadyShowOnTheAir(void) BufferContestLadyPlayerName(show->contestLady.playerName); BufferContestLadyMonName(&show->contestLady.contestCategory, show->contestLady.nickname); show->contestLady.pokeblockState = GetContestLadyPokeblockState(); - tv_store_id_2x(show); + StorePlayerIdInNormalShow(show); } } static void InterviewAfter_FanClubLetter(void) { - TVShow *show; - - show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; + TVShow *show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; show->fanclubLetter.kind = TVSHOW_FAN_CLUB_LETTER; show->fanclubLetter.active = TRUE; StringCopy(show->fanclubLetter.playerName, gSaveBlock2Ptr->playerName); show->fanclubLetter.species = GetMonData(&gPlayerParty[GetLeadMonIndex()], MON_DATA_SPECIES, NULL); - tv_store_id_2x(show); + StorePlayerIdInNormalShow(show); show->fanclubLetter.language = gGameLanguage; } static void InterviewAfter_RecentHappenings(void) { - TVShow *show; - - show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; + TVShow *show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; show->recentHappenings.kind = TVSHOW_RECENT_HAPPENINGS; show->recentHappenings.active = TRUE; StringCopy(show->recentHappenings.playerName, gSaveBlock2Ptr->playerName); - show->recentHappenings.var02 = 0; - tv_store_id_2x(show); + show->recentHappenings.species = SPECIES_NONE; + StorePlayerIdInNormalShow(show); show->recentHappenings.language = gGameLanguage; } static void InterviewAfter_PkmnFanClubOpinions(void) { - TVShow *show; - - show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; + TVShow *show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; show->fanclubOpinions.kind = TVSHOW_PKMN_FAN_CLUB_OPINIONS; show->fanclubOpinions.active = TRUE; show->fanclubOpinions.friendshipHighNybble = GetMonData(&gPlayerParty[GetLeadMonIndex()], MON_DATA_FRIENDSHIP, NULL) >> 4; @@ -1712,26 +1631,20 @@ static void InterviewAfter_PkmnFanClubOpinions(void) GetMonData(&gPlayerParty[GetLeadMonIndex()], MON_DATA_NICKNAME, show->fanclubOpinions.nickname); StripExtCtrlCodes(show->fanclubOpinions.nickname); show->fanclubOpinions.species = GetMonData(&gPlayerParty[GetLeadMonIndex()], MON_DATA_SPECIES, NULL); - tv_store_id_2x(show); + StorePlayerIdInNormalShow(show); show->fanclubOpinions.language = gGameLanguage; if (gGameLanguage == LANGUAGE_JAPANESE || GetMonData(&gPlayerParty[GetLeadMonIndex()], MON_DATA_LANGUAGE) == LANGUAGE_JAPANESE) - { show->fanclubOpinions.pokemonNameLanguage = LANGUAGE_JAPANESE; - } else - { show->fanclubOpinions.pokemonNameLanguage = GetMonData(&gPlayerParty[GetLeadMonIndex()], MON_DATA_LANGUAGE); - } } -static void InterviewAfter_DummyShow4(void) +static void InterviewAfter_Dummy(void) { - TVShow *show; - - show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; + TVShow *show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; } -static void sub_80ED718(void) +static void TryStartRandomMassOutbreak(void) { u8 i; u16 outbreakIdx; @@ -1739,16 +1652,14 @@ static void sub_80ED718(void) if (FlagGet(FLAG_SYS_GAME_CLEAR)) { - for (i = 0; i < LAST_TVSHOW_IDX; i ++) + for (i = 0; i < LAST_TVSHOW_IDX; i++) { if (gSaveBlock1Ptr->tvShows[i].common.kind == TVSHOW_MASS_OUTBREAK) - { return; - } } if (!rbernoulli(1, 200)) { - sCurTVShowSlot = FindEmptyTVSlotWithinFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); + sCurTVShowSlot = FindFirstEmptyNormalTVShowSlot(gSaveBlock1Ptr->tvShows); if (sCurTVShowSlot != -1) { outbreakIdx = Random() % ARRAY_COUNT(sPokeOutbreakSpeciesList); @@ -1770,7 +1681,7 @@ static void sub_80ED718(void) show->massOutbreak.probability = 50; show->massOutbreak.var15 = 0; show->massOutbreak.daysLeft = 1; - tv_store_id_2x(show); + StorePlayerIdInNormalShow(show); show->massOutbreak.language = gGameLanguage; } } @@ -1798,9 +1709,9 @@ void UpdateTVShowsPerDay(u16 days) { UpdateMassOutbreakTimeLeft(days); TryEndMassOutbreak(days); - sub_80EF120(days); - sub_80EDA48(days); - sub_80EEB98(days); + UpdatePokeNewsTimeLeft(days); + ResolveWorldOfMastersShow(days); + ResolveNumberOneShow(days); } static void UpdateMassOutbreakTimeLeft(u16 days) @@ -1810,7 +1721,7 @@ static void UpdateMassOutbreakTimeLeft(u16 days) if (gSaveBlock1Ptr->outbreakPokemonSpecies == SPECIES_NONE) { - for (i = 0; i < LAST_TVSHOW_IDX; i ++) + for (i = 0; i < LAST_TVSHOW_IDX; i++) { if (gSaveBlock1Ptr->tvShows[i].massOutbreak.kind == TVSHOW_MASS_OUTBREAK && gSaveBlock1Ptr->tvShows[i].massOutbreak.active == TRUE) { @@ -1839,7 +1750,7 @@ void RecordFishingAttemptForTV(bool8 caughtFish) if (caughtFish) { if (sPokemonAnglerAttemptCounters >> 8 > 4) - PutFishingAdviceShowOnTheAir(); + TryPutFishingAdviceOnAir(); sPokemonAnglerAttemptCounters &= 0xFF; if (sPokemonAnglerAttemptCounters != 0xFF) @@ -1848,7 +1759,7 @@ void RecordFishingAttemptForTV(bool8 caughtFish) else { if ((u8)sPokemonAnglerAttemptCounters > 4) - PutFishingAdviceShowOnTheAir(); + TryPutFishingAdviceOnAir(); sPokemonAnglerAttemptCounters &= 0xFF00; if (sPokemonAnglerAttemptCounters >> 8 != 0xFF) @@ -1856,21 +1767,21 @@ void RecordFishingAttemptForTV(bool8 caughtFish) } } -void PutFishingAdviceShowOnTheAir(void) +static void TryPutFishingAdviceOnAir(void) { TVShow *show; - sCurTVShowSlot = FindEmptyTVSlotBeyondFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); - if (sCurTVShowSlot != -1 && HasMixableShowAlreadyBeenSpawnedWithPlayerID(TVSHOW_FISHING_ADVICE, FALSE) != TRUE) + sCurTVShowSlot = FindFirstEmptyRecordMixTVShowSlot(gSaveBlock1Ptr->tvShows); + if (sCurTVShowSlot != -1 && IsRecordMixShowAlreadySpawned(TVSHOW_FISHING_ADVICE, FALSE) != TRUE) { show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; show->pokemonAngler.kind = TVSHOW_FISHING_ADVICE; - show->pokemonAngler.active = FALSE; + show->pokemonAngler.active = FALSE; // NOTE: Show is not active until passed via Record Mix. show->pokemonAngler.nBites = sPokemonAnglerAttemptCounters; show->pokemonAngler.nFails = sPokemonAnglerAttemptCounters >> 8; show->pokemonAngler.species = sPokemonAnglerSpecies; StringCopy(show->pokemonAngler.playerName, gSaveBlock2Ptr->playerName); - tv_store_id_3x(show); + StorePlayerIdInRecordMixShow(show); show->pokemonAngler.language = gGameLanguage; } } @@ -1880,7 +1791,11 @@ void SetPokemonAnglerSpecies(u16 species) sPokemonAnglerSpecies = species; } -static void sub_80EDA48(u16 days) +// World of Masters is initialized in the last slot by InitWorldOfMastersShowAttempt +// If enough Pokémon were caught during the day the show can be put on air (and will +// be moved out of the last slot). +// Either way the temporary version of the show in the last slot is deleted. +static void ResolveWorldOfMastersShow(u16 days) { TVShow *show; @@ -1888,14 +1803,13 @@ static void sub_80EDA48(u16 days) if (show->worldOfMasters.kind == TVSHOW_WORLD_OF_MASTERS) { if (show->worldOfMasters.numPokeCaught >= 20) - { - sub_80EDA80(); - } + TryPutWorldOfMastersOnAir(); + DeleteTVShowInArrayByIdx(gSaveBlock1Ptr->tvShows, LAST_TVSHOW_IDX); } } -void sub_80EDA80(void) +static void TryPutWorldOfMastersOnAir(void) { TVShow *show; TVShow *show2; @@ -1903,19 +1817,19 @@ void sub_80EDA80(void) show = &gSaveBlock1Ptr->tvShows[LAST_TVSHOW_IDX]; if (!rbernoulli(1, 1)) { - sCurTVShowSlot = FindEmptyTVSlotBeyondFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); - if (sCurTVShowSlot != -1 && HasMixableShowAlreadyBeenSpawnedWithPlayerID(TVSHOW_WORLD_OF_MASTERS, FALSE) != TRUE) + sCurTVShowSlot = FindFirstEmptyRecordMixTVShowSlot(gSaveBlock1Ptr->tvShows); + if (sCurTVShowSlot != -1 && IsRecordMixShowAlreadySpawned(TVSHOW_WORLD_OF_MASTERS, FALSE) != TRUE) { show2 = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; show2->worldOfMasters.kind = TVSHOW_WORLD_OF_MASTERS; - show2->worldOfMasters.active = FALSE; + show2->worldOfMasters.active = FALSE; // NOTE: Show is not active until passed via Record Mix. show2->worldOfMasters.numPokeCaught = show->worldOfMasters.numPokeCaught; show2->worldOfMasters.steps = GetGameStat(GAME_STAT_STEPS) - show->worldOfMasters.steps; show2->worldOfMasters.caughtPoke = show->worldOfMasters.caughtPoke; show2->worldOfMasters.species = show->worldOfMasters.species; show2->worldOfMasters.location = show->worldOfMasters.location; StringCopy(show2->worldOfMasters.playerName, gSaveBlock2Ptr->playerName); - tv_store_id_3x(show2); + StorePlayerIdInRecordMixShow(show2); show2->worldOfMasters.language = gGameLanguage; DeleteTVShowInArrayByIdx(gSaveBlock1Ptr->tvShows, LAST_TVSHOW_IDX); } @@ -1928,47 +1842,38 @@ void TryPutTodaysRivalTrainerOnAir(void) u32 i; u8 nBadges; - HasMixableShowAlreadyBeenSpawnedWithPlayerID(TVSHOW_TODAYS_RIVAL_TRAINER, TRUE); - sCurTVShowSlot = FindEmptyTVSlotBeyondFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); + IsRecordMixShowAlreadySpawned(TVSHOW_TODAYS_RIVAL_TRAINER, TRUE); // Delete old version of show + sCurTVShowSlot = FindFirstEmptyRecordMixTVShowSlot(gSaveBlock1Ptr->tvShows); if (sCurTVShowSlot != -1) { show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; show->rivalTrainer.kind = TVSHOW_TODAYS_RIVAL_TRAINER; - show->rivalTrainer.active = FALSE; - for (i = FLAG_BADGE01_GET, nBadges = 0; i < FLAG_BADGE01_GET + NUM_BADGES; i ++) + show->rivalTrainer.active = FALSE; // NOTE: Show is not active until passed via Record Mix. + for (i = FLAG_BADGE01_GET, nBadges = 0; i < FLAG_BADGE01_GET + NUM_BADGES; i++) { if (FlagGet(i)) - { - nBadges ++; - } + nBadges++; } show->rivalTrainer.badgeCount = nBadges; if (IsNationalPokedexEnabled()) - { show->rivalTrainer.dexCount = GetNationalPokedexCount(FLAG_GET_CAUGHT); - } else - { show->rivalTrainer.dexCount = GetHoennPokedexCount(FLAG_GET_CAUGHT); - } show->rivalTrainer.location = gMapHeader.regionMapSectionId; show->rivalTrainer.mapLayoutId = gMapHeader.mapLayoutId; show->rivalTrainer.nSilverSymbols = 0; show->rivalTrainer.nGoldSymbols = 0; - for (i = 0; i < 7; i ++) + for (i = 0; i < 7; i++) { if (FlagGet(sSilverSymbolFlags[i]) == TRUE) - { - show->rivalTrainer.nSilverSymbols ++; - } + show->rivalTrainer.nSilverSymbols++; + if (FlagGet(sGoldSymbolFlags[i]) == TRUE) - { - show->rivalTrainer.nGoldSymbols ++; - } + show->rivalTrainer.nGoldSymbols++; } show->rivalTrainer.battlePoints = gSaveBlock2Ptr->frontier.battlePoints; StringCopy(show->rivalTrainer.playerName, gSaveBlock2Ptr->playerName); - tv_store_id_3x(show); + StorePlayerIdInRecordMixShow(show); show->rivalTrainer.language = gGameLanguage; } } @@ -1977,17 +1882,17 @@ void TryPutTrendWatcherOnAir(const u16 *words) { TVShow *show; - sCurTVShowSlot = FindEmptyTVSlotBeyondFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); - if (sCurTVShowSlot != -1 && HasMixableShowAlreadyBeenSpawnedWithPlayerID(TVSHOW_TREND_WATCHER, FALSE) != TRUE) + sCurTVShowSlot = FindFirstEmptyRecordMixTVShowSlot(gSaveBlock1Ptr->tvShows); + if (sCurTVShowSlot != -1 && IsRecordMixShowAlreadySpawned(TVSHOW_TREND_WATCHER, FALSE) != TRUE) { show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; show->trendWatcher.kind = TVSHOW_TREND_WATCHER; - show->trendWatcher.active = FALSE; + show->trendWatcher.active = FALSE; // NOTE: Show is not active until passed via Record Mix. show->trendWatcher.gender = gSaveBlock2Ptr->playerGender; show->trendWatcher.words[0] = words[0]; show->trendWatcher.words[1] = words[1]; StringCopy(show->trendWatcher.playerName, gSaveBlock2Ptr->playerName); - tv_store_id_3x(show); + StorePlayerIdInRecordMixShow(show); show->trendWatcher.language = gGameLanguage; } } @@ -1996,70 +1901,70 @@ void TryPutTreasureInvestigatorsOnAir(void) { TVShow *show; - sCurTVShowSlot = FindEmptyTVSlotBeyondFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); - if (sCurTVShowSlot != -1 && HasMixableShowAlreadyBeenSpawnedWithPlayerID(TVSHOW_TREASURE_INVESTIGATORS, FALSE) != TRUE) + sCurTVShowSlot = FindFirstEmptyRecordMixTVShowSlot(gSaveBlock1Ptr->tvShows); + if (sCurTVShowSlot != -1 && IsRecordMixShowAlreadySpawned(TVSHOW_TREASURE_INVESTIGATORS, FALSE) != TRUE) { show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; show->treasureInvestigators.kind = TVSHOW_TREASURE_INVESTIGATORS; - show->treasureInvestigators.active = FALSE; + show->treasureInvestigators.active = FALSE; // NOTE: Show is not active until passed via Record Mix. show->treasureInvestigators.item = gSpecialVar_0x8005; show->treasureInvestigators.location = gMapHeader.regionMapSectionId; show->treasureInvestigators.mapLayoutId = gMapHeader.mapLayoutId; StringCopy(show->treasureInvestigators.playerName, gSaveBlock2Ptr->playerName); - tv_store_id_3x(show); + StorePlayerIdInRecordMixShow(show); show->treasureInvestigators.language = gGameLanguage; } } -void AlertTVOfNewCoinTotal(u16 nCoinsPaidOut) +void TryPutFindThatGamerOnAir(u16 nCoinsPaidOut) { TVShow *show; bool8 flag; u16 nCoinsWon; - sCurTVShowSlot = FindEmptyTVSlotBeyondFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); - if (sCurTVShowSlot != -1 && HasMixableShowAlreadyBeenSpawnedWithPlayerID(TVSHOW_FIND_THAT_GAMER, FALSE) != TRUE) + sCurTVShowSlot = FindFirstEmptyRecordMixTVShowSlot(gSaveBlock1Ptr->tvShows); + if (sCurTVShowSlot != -1 && IsRecordMixShowAlreadySpawned(TVSHOW_FIND_THAT_GAMER, FALSE) != TRUE) { flag = FALSE; switch (sFindThatGamerWhichGame) { - case SLOT_MACHINE: - if (nCoinsPaidOut >= sFindThatGamerCoinsSpent + 200) - { - flag = TRUE; - nCoinsWon = nCoinsPaidOut - sFindThatGamerCoinsSpent; - break; - } - if (sFindThatGamerCoinsSpent >= 100 && nCoinsPaidOut <= sFindThatGamerCoinsSpent - 100) - { - nCoinsWon = sFindThatGamerCoinsSpent - nCoinsPaidOut; - break; - } - return; - case ROULETTE: - if (nCoinsPaidOut >= sFindThatGamerCoinsSpent + 50) - { - flag = TRUE; - nCoinsWon = nCoinsPaidOut - sFindThatGamerCoinsSpent; - break; - } - if (sFindThatGamerCoinsSpent >= 50 && nCoinsPaidOut <= sFindThatGamerCoinsSpent - 50) - { - nCoinsWon = sFindThatGamerCoinsSpent - nCoinsPaidOut; - break; - } - return; - default: - return; + case SLOT_MACHINE: + if (nCoinsPaidOut >= sFindThatGamerCoinsSpent + 200) + { + flag = TRUE; + nCoinsWon = nCoinsPaidOut - sFindThatGamerCoinsSpent; + break; + } + if (sFindThatGamerCoinsSpent >= 100 && nCoinsPaidOut <= sFindThatGamerCoinsSpent - 100) + { + nCoinsWon = sFindThatGamerCoinsSpent - nCoinsPaidOut; + break; + } + return; + case ROULETTE: + if (nCoinsPaidOut >= sFindThatGamerCoinsSpent + 50) + { + flag = TRUE; + nCoinsWon = nCoinsPaidOut - sFindThatGamerCoinsSpent; + break; + } + if (sFindThatGamerCoinsSpent >= 50 && nCoinsPaidOut <= sFindThatGamerCoinsSpent - 50) + { + nCoinsWon = sFindThatGamerCoinsSpent - nCoinsPaidOut; + break; + } + return; + default: + return; } show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; show->findThatGamer.kind = TVSHOW_FIND_THAT_GAMER; - show->findThatGamer.active = FALSE; + show->findThatGamer.active = FALSE; // NOTE: Show is not active until passed via Record Mix. show->findThatGamer.nCoins = nCoinsWon; show->findThatGamer.whichGame = sFindThatGamerWhichGame; show->findThatGamer.won = flag; StringCopy(show->findThatGamer.playerName, gSaveBlock2Ptr->playerName); - tv_store_id_3x(show); + StorePlayerIdInRecordMixShow(show); show->findThatGamer.language = gGameLanguage; } } @@ -2076,71 +1981,64 @@ void AlertTVThatPlayerPlayedRoulette(u16 nCoinsSpent) sFindThatGamerCoinsSpent = nCoinsSpent; } -static void sub_80EDE98(TVShow *show) +static void SecretBaseVisit_CalculateDecorationData(TVShow *show) { - u8 i; - u8 j; + u8 i, j; u16 k; u8 n; - u8 deco; + u8 decoration; - for (i = 0; i < DECOR_MAX_SECRET_BASE; i ++) - { + for (i = 0; i < DECOR_MAX_SECRET_BASE; i++) sTV_DecorationsBuffer[i] = 0; - } - for (i = 0, n = 0; i < DECOR_MAX_SECRET_BASE; i ++) + + for (i = 0, n = 0; i < DECOR_MAX_SECRET_BASE; i++) { - deco = gSaveBlock1Ptr->secretBases[0].decorations[i]; - if (deco) + decoration = gSaveBlock1Ptr->secretBases[0].decorations[i]; + if (decoration) { - for (j = 0; j < DECOR_MAX_SECRET_BASE; j ++) + for (j = 0; j < DECOR_MAX_SECRET_BASE; j++) { if (sTV_DecorationsBuffer[j] == 0) { - sTV_DecorationsBuffer[j] = deco; - n ++; + sTV_DecorationsBuffer[j] = decoration; + n++; break; } - if (sTV_DecorationsBuffer[j] == deco) - { + if (sTV_DecorationsBuffer[j] == decoration) break; - } } } } + if (n > 4) - { show->secretBaseVisit.nDecorations = 4; - } else - { show->secretBaseVisit.nDecorations = n; - } + switch (show->secretBaseVisit.nDecorations) { - case 0: - break; - case 1: - show->secretBaseVisit.decorations[0] = sTV_DecorationsBuffer[0]; - break; - default: - for (k = 0; k < n * n; k ++) - { - deco = Random() % n; - j = Random() % n; - i = sTV_DecorationsBuffer[deco]; - sTV_DecorationsBuffer[deco] = sTV_DecorationsBuffer[j]; - sTV_DecorationsBuffer[j] = i; - } - for (i = 0; i < show->secretBaseVisit.nDecorations; i ++) - { - show->secretBaseVisit.decorations[i] = sTV_DecorationsBuffer[i]; - } - break; + case 0: + break; + case 1: + show->secretBaseVisit.decorations[0] = sTV_DecorationsBuffer[0]; + break; + default: + for (k = 0; k < n * n; k++) + { + decoration = Random() % n; + j = Random() % n; + i = sTV_DecorationsBuffer[decoration]; + sTV_DecorationsBuffer[decoration] = sTV_DecorationsBuffer[j]; + sTV_DecorationsBuffer[j] = i; + } + + for (i = 0; i < show->secretBaseVisit.nDecorations; i++) + show->secretBaseVisit.decorations[i] = sTV_DecorationsBuffer[i]; + break; } } -static void sub_80EDFB4(TVShow *show) +static void SecretBaseVisit_CalculatePartyData(TVShow *show) { u8 i; u16 move; @@ -2149,7 +2047,7 @@ static void sub_80EDFB4(TVShow *show) u8 nPokemon; u16 sum; - for (i = 0, nPokemon = 0; i < PARTY_SIZE; i ++) + for (i = 0, nPokemon = 0; i < PARTY_SIZE; i++) { if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES) != SPECIES_NONE && !GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG)) { @@ -2160,128 +2058,119 @@ static void sub_80EDFB4(TVShow *show) if (move != MOVE_NONE) { sTV_SecretBaseVisitMovesTemp[nMoves] = move; - nMoves ++; + nMoves++; } move = GetMonData(&gPlayerParty[i], MON_DATA_MOVE2); if (move != MOVE_NONE) { sTV_SecretBaseVisitMovesTemp[nMoves] = move; - nMoves ++; + nMoves++; } move = GetMonData(&gPlayerParty[i], MON_DATA_MOVE3); if (move != MOVE_NONE) { sTV_SecretBaseVisitMovesTemp[nMoves] = move; - nMoves ++; + nMoves++; } move = GetMonData(&gPlayerParty[i], MON_DATA_MOVE4); if (move != MOVE_NONE) { sTV_SecretBaseVisitMovesTemp[nMoves] = move; - nMoves ++; + nMoves++; } sTV_SecretBaseVisitMonsTemp[nPokemon].move = sTV_SecretBaseVisitMovesTemp[Random() % nMoves]; - nPokemon ++; + nPokemon++; } } - for (i = 0, sum = 0; i < nPokemon; i ++) - { + for (i = 0, sum = 0; i < nPokemon; i++) sum += sTV_SecretBaseVisitMonsTemp[i].level; - } + show->secretBaseVisit.avgLevel = sum / nPokemon; j = Random() % nPokemon; show->secretBaseVisit.species = sTV_SecretBaseVisitMonsTemp[j].species; show->secretBaseVisit.move = sTV_SecretBaseVisitMonsTemp[j].move; } -void TV_PutSecretBaseVisitOnTheAir(void) +void TryPutSecretBaseVisitOnAir(void) { TVShow *show; - HasMixableShowAlreadyBeenSpawnedWithPlayerID(TVSHOW_SECRET_BASE_VISIT, TRUE); - sCurTVShowSlot = FindEmptyTVSlotBeyondFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); + IsRecordMixShowAlreadySpawned(TVSHOW_SECRET_BASE_VISIT, TRUE); // Delete old version of show + sCurTVShowSlot = FindFirstEmptyRecordMixTVShowSlot(gSaveBlock1Ptr->tvShows); if (sCurTVShowSlot != -1) { show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; show->secretBaseVisit.kind = TVSHOW_SECRET_BASE_VISIT; - show->secretBaseVisit.active = FALSE; + show->secretBaseVisit.active = FALSE; // NOTE: Show is not active until passed via Record Mix. StringCopy(show->secretBaseVisit.playerName, gSaveBlock2Ptr->playerName); - sub_80EDE98(show); - sub_80EDFB4(show); - tv_store_id_3x(show); + SecretBaseVisit_CalculateDecorationData(show); + SecretBaseVisit_CalculatePartyData(show); + StorePlayerIdInRecordMixShow(show); show->secretBaseVisit.language = gGameLanguage; } } -void sub_80EE184(void) +void TryPutBreakingNewsOnAir(void) { TVShow *show; u8 i; u16 balls; - sCurTVShowSlot = FindEmptyTVSlotBeyondFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); - if (sCurTVShowSlot != -1 && HasMixableShowAlreadyBeenSpawnedWithPlayerID(TVSHOW_BREAKING_NEWS, FALSE) != TRUE) + sCurTVShowSlot = FindFirstEmptyRecordMixTVShowSlot(gSaveBlock1Ptr->tvShows); + if (sCurTVShowSlot != -1 && IsRecordMixShowAlreadySpawned(TVSHOW_BREAKING_NEWS, FALSE) != TRUE) { show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; show->breakingNews.kind = TVSHOW_BREAKING_NEWS; - show->breakingNews.active = FALSE; + show->breakingNews.active = FALSE; // NOTE: Show is not active until passed via Record Mix. balls = 0; - for (i = 0; i < POKEBALL_COUNT - 1; i ++) - { + for (i = 0; i < POKEBALL_COUNT - 1; i++) balls += gBattleResults.catchAttempts[i]; - } + if (gBattleResults.usedMasterBall) - { - balls ++; - } + balls++; show->breakingNews.location = gMapHeader.regionMapSectionId; StringCopy(show->breakingNews.playerName, gSaveBlock2Ptr->playerName); show->breakingNews.poke1Species = gBattleResults.playerMon1Species; switch (gBattleOutcome) { - case B_OUTCOME_LOST: - case B_OUTCOME_DREW: - show->breakingNews.kind = TVSHOW_OFF_AIR; - return; - case B_OUTCOME_CAUGHT: - show->breakingNews.outcome = 0; - break; - case B_OUTCOME_WON: - show->breakingNews.outcome = 1; - break; - case B_OUTCOME_RAN: - case B_OUTCOME_PLAYER_TELEPORTED: - case B_OUTCOME_NO_SAFARI_BALLS: - show->breakingNews.outcome = 2; - break; - case B_OUTCOME_MON_FLED: - case B_OUTCOME_MON_TELEPORTED: - show->breakingNews.outcome = 3; - break; + case B_OUTCOME_LOST: + case B_OUTCOME_DREW: + show->breakingNews.kind = TVSHOW_OFF_AIR; + return; + case B_OUTCOME_CAUGHT: + show->breakingNews.outcome = 0; + break; + case B_OUTCOME_WON: + show->breakingNews.outcome = 1; + break; + case B_OUTCOME_RAN: + case B_OUTCOME_PLAYER_TELEPORTED: + case B_OUTCOME_NO_SAFARI_BALLS: + show->breakingNews.outcome = 2; + break; + case B_OUTCOME_MON_FLED: + case B_OUTCOME_MON_TELEPORTED: + show->breakingNews.outcome = 3; + break; } show->breakingNews.lastOpponentSpecies = gBattleResults.lastOpponentSpecies; switch (show->breakingNews.outcome) { - case 0: - if (gBattleResults.usedMasterBall) - { - show->breakingNews.caughtMonBall = ITEM_MASTER_BALL; - } - else - { - show->breakingNews.caughtMonBall = gBattleResults.caughtMonBall; - } - show->breakingNews.balls = balls; - break; - case 1: - show->breakingNews.lastUsedMove = gBattleResults.lastUsedMovePlayer; - break; - case 2: - break; - case 3: - break; + case 0: + if (gBattleResults.usedMasterBall) + show->breakingNews.caughtMonBall = ITEM_MASTER_BALL; + else + show->breakingNews.caughtMonBall = gBattleResults.caughtMonBall; + show->breakingNews.balls = balls; + break; + case 1: + show->breakingNews.lastUsedMove = gBattleResults.lastUsedMovePlayer; + break; + case 2: + case 3: + break; } - tv_store_id_3x(show); + StorePlayerIdInRecordMixShow(show); show->breakingNews.language = gGameLanguage; } } @@ -2290,16 +2179,16 @@ void TryPutLotteryWinnerReportOnAir(void) { TVShow *show; - sCurTVShowSlot = FindEmptyTVSlotBeyondFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); - if (sCurTVShowSlot != -1 && HasMixableShowAlreadyBeenSpawnedWithPlayerID(TVSHOW_LOTTO_WINNER, FALSE) != TRUE) + sCurTVShowSlot = FindFirstEmptyRecordMixTVShowSlot(gSaveBlock1Ptr->tvShows); + if (sCurTVShowSlot != -1 && IsRecordMixShowAlreadySpawned(TVSHOW_LOTTO_WINNER, FALSE) != TRUE) { show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; show->lottoWinner.kind = TVSHOW_LOTTO_WINNER; - show->lottoWinner.active = FALSE; + show->lottoWinner.active = FALSE; // NOTE: Show is not active until passed via Record Mix. StringCopy(show->lottoWinner.playerName, gSaveBlock2Ptr->playerName); show->lottoWinner.whichPrize = 4 - gSpecialVar_0x8004; show->lottoWinner.item = gSpecialVar_0x8005; - tv_store_id_3x(show); + StorePlayerIdInRecordMixShow(show); show->lottoWinner.language = gGameLanguage; } } @@ -2310,45 +2199,45 @@ void TryPutBattleSeminarOnAir(u16 foeSpecies, u16 species, u8 moveIdx, const u16 u8 i; u8 j; - sCurTVShowSlot = FindEmptyTVSlotBeyondFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); - if (sCurTVShowSlot != -1 && HasMixableShowAlreadyBeenSpawnedWithPlayerID(TVSHOW_BATTLE_SEMINAR, FALSE) != TRUE) + sCurTVShowSlot = FindFirstEmptyRecordMixTVShowSlot(gSaveBlock1Ptr->tvShows); + if (sCurTVShowSlot != -1 && IsRecordMixShowAlreadySpawned(TVSHOW_BATTLE_SEMINAR, FALSE) != TRUE) { show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; show->battleSeminar.kind = TVSHOW_BATTLE_SEMINAR; - show->battleSeminar.active = FALSE; + show->battleSeminar.active = FALSE; // NOTE: Show is not active until passed via Record Mix. StringCopy(show->battleSeminar.playerName, gSaveBlock2Ptr->playerName); show->battleSeminar.foeSpecies = foeSpecies; show->battleSeminar.species = species; show->battleSeminar.move = movePtr[moveIdx]; - for (i = 0, j = 0; i < MAX_MON_MOVES; i ++) + for (i = 0, j = 0; i < MAX_MON_MOVES; i++) { if (i != moveIdx && movePtr[i]) { show->battleSeminar.otherMoves[j] = movePtr[i]; - j ++; + j++; } } show->battleSeminar.nOtherMoves = j; show->battleSeminar.betterMove = betterMove; - tv_store_id_3x(show); + StorePlayerIdInRecordMixShow(show); show->battleSeminar.language = gGameLanguage; } } -void sub_80EE44C(u8 nMonsCaught, u8 nPkblkUsed) +void TryPutSafariFanClubOnAir(u8 nMonsCaught, u8 nPkblkUsed) { TVShow *show; - sCurTVShowSlot = FindEmptyTVSlotBeyondFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); - if (sCurTVShowSlot != -1 && HasMixableShowAlreadyBeenSpawnedWithPlayerID(TVSHOW_SAFARI_FAN_CLUB, FALSE) != TRUE) + sCurTVShowSlot = FindFirstEmptyRecordMixTVShowSlot(gSaveBlock1Ptr->tvShows); + if (sCurTVShowSlot != -1 && IsRecordMixShowAlreadySpawned(TVSHOW_SAFARI_FAN_CLUB, FALSE) != TRUE) { show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; show->safariFanClub.kind = TVSHOW_SAFARI_FAN_CLUB; - show->safariFanClub.active = FALSE; + show->safariFanClub.active = FALSE; // NOTE: Show is not active until passed via Record Mix. StringCopy(show->safariFanClub.playerName, gSaveBlock2Ptr->playerName); show->safariFanClub.nMonsCaught = nMonsCaught; show->safariFanClub.nPkblkUsed = nPkblkUsed; - tv_store_id_3x(show); + StorePlayerIdInRecordMixShow(show); show->safariFanClub.language = gGameLanguage; } } @@ -2357,27 +2246,23 @@ void TryPutSpotTheCutiesOnAir(struct Pokemon *pokemon, u8 ribbonMonDataIdx) { TVShow *show; - sCurTVShowSlot = FindEmptyTVSlotBeyondFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); - if (sCurTVShowSlot != -1 && HasMixableShowAlreadyBeenSpawnedWithPlayerID(TVSHOW_CUTIES, FALSE) != TRUE) + sCurTVShowSlot = FindFirstEmptyRecordMixTVShowSlot(gSaveBlock1Ptr->tvShows); + if (sCurTVShowSlot != -1 && IsRecordMixShowAlreadySpawned(TVSHOW_CUTIES, FALSE) != TRUE) { show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; show->cuties.kind = TVSHOW_CUTIES; - show->cuties.active = FALSE; + show->cuties.active = FALSE; // NOTE: Show is not active until passed via Record Mix. StringCopy(show->cuties.playerName, gSaveBlock2Ptr->playerName); GetMonData(pokemon, MON_DATA_NICKNAME, show->cuties.nickname); StripExtCtrlCodes(show->cuties.nickname); show->cuties.nRibbons = GetRibbonCount(pokemon); show->cuties.selectedRibbon = MonDataIdxToRibbon(ribbonMonDataIdx); - tv_store_id_3x(show); + StorePlayerIdInRecordMixShow(show); show->cuties.language = gGameLanguage; if (show->cuties.language == LANGUAGE_JAPANESE || GetMonData(pokemon, MON_DATA_LANGUAGE) == LANGUAGE_JAPANESE) - { show->cuties.pokemonNameLanguage = LANGUAGE_JAPANESE; - } else - { show->cuties.pokemonNameLanguage = GetMonData(pokemon, MON_DATA_LANGUAGE); - } } } @@ -2428,31 +2313,31 @@ static u8 MonDataIdxToRibbon(u8 monDataIdx) return CHAMPION_RIBBON; } -void TrySetUpTrainerFanClubSpecial(void) +void TryPutTrainerFanClubOnAir(void) { TVShow *show; - sCurTVShowSlot = FindEmptyTVSlotBeyondFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); - if (sCurTVShowSlot != -1 && HasMixableShowAlreadyBeenSpawnedWithPlayerID(TVSHOW_TRAINER_FAN_CLUB, FALSE) != TRUE) + sCurTVShowSlot = FindFirstEmptyRecordMixTVShowSlot(gSaveBlock1Ptr->tvShows); + if (sCurTVShowSlot != -1 && IsRecordMixShowAlreadySpawned(TVSHOW_TRAINER_FAN_CLUB, FALSE) != TRUE) { show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; show->trainerFanClub.kind = TVSHOW_TRAINER_FAN_CLUB; - show->trainerFanClub.active = FALSE; + show->trainerFanClub.active = FALSE; // NOTE: Show is not active until passed via Record Mix. StringCopy(show->trainerFanClub.playerName, gSaveBlock2Ptr->playerName); show->trainerFanClub.words[0] = gSaveBlock1Ptr->easyChatProfile[0]; show->trainerFanClub.words[1] = gSaveBlock1Ptr->easyChatProfile[1]; - tv_store_id_3x(show); + StorePlayerIdInRecordMixShow(show); show->trainerFanClub.language = gGameLanguage; } } bool8 ShouldHideFanClubInterviewer(void) { - sCurTVShowSlot = FindEmptyTVSlotWithinFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); + sCurTVShowSlot = FindFirstEmptyNormalTVShowSlot(gSaveBlock1Ptr->tvShows); if (sCurTVShowSlot == -1) return TRUE; - FindActiveBroadcastByShowType_SetScriptResult(TVSHOW_FAN_CLUB_SPECIAL); + TryReplaceOldTVShowOfKind(TVSHOW_FAN_CLUB_SPECIAL); if (gSpecialVar_Result == TRUE) return TRUE; @@ -2468,25 +2353,24 @@ bool8 ShouldAirFrontierTVShow(void) u8 showIdx; TVShow *shows; - if (HasMixableShowAlreadyBeenSpawnedWithPlayerID(TVSHOW_FRONTIER, FALSE) == TRUE) + if (IsRecordMixShowAlreadySpawned(TVSHOW_FRONTIER, FALSE) == TRUE) { shows = gSaveBlock1Ptr->tvShows; playerId = GetPlayerIDAsU32(); - for (showIdx = 5; showIdx < LAST_TVSHOW_IDX; showIdx ++) + for (showIdx = NUM_NORMAL_TVSHOW_SLOTS; showIdx < LAST_TVSHOW_IDX; showIdx++) { if (shows[showIdx].common.kind == TVSHOW_FRONTIER && (playerId & 0xFF) == shows[showIdx].common.trainerIdLo && ((playerId >> 8) & 0xFF) == shows[showIdx].common.trainerIdHi) { DeleteTVShowInArrayByIdx(gSaveBlock1Ptr->tvShows, showIdx); - sub_80EF93C(gSaveBlock1Ptr->tvShows); + CompactTVShowArray(gSaveBlock1Ptr->tvShows); return TRUE; } } } - sCurTVShowSlot = FindEmptyTVSlotBeyondFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); + sCurTVShowSlot = FindFirstEmptyRecordMixTVShowSlot(gSaveBlock1Ptr->tvShows); if (sCurTVShowSlot == -1) - { return FALSE; - } + return TRUE; } @@ -2494,47 +2378,47 @@ void TryPutFrontierTVShowOnAir(u16 winStreak, u8 facilityAndMode) { TVShow *show; - sCurTVShowSlot = FindEmptyTVSlotBeyondFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); + sCurTVShowSlot = FindFirstEmptyRecordMixTVShowSlot(gSaveBlock1Ptr->tvShows); if (sCurTVShowSlot != -1) { show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; show->frontier.kind = TVSHOW_FRONTIER; - show->frontier.active = FALSE; + show->frontier.active = FALSE; // NOTE: Show is not active until passed via Record Mix. StringCopy(show->frontier.playerName, gSaveBlock2Ptr->playerName); show->frontier.winStreak = winStreak; - show->frontier.facility = facilityAndMode; + show->frontier.facilityAndMode = facilityAndMode; switch (facilityAndMode) { - case 1: - case 5: - case 6: - case 7: - case 8: - case 9: - case 10: - case 11: - case 12: - case 13: - show->frontier.species1 = GetMonData(&gPlayerParty[0], MON_DATA_SPECIES, NULL); - show->frontier.species2 = GetMonData(&gPlayerParty[1], MON_DATA_SPECIES, NULL); - show->frontier.species3 = GetMonData(&gPlayerParty[2], MON_DATA_SPECIES, NULL); - break; - case 2: - show->frontier.species1 = GetMonData(&gPlayerParty[0], MON_DATA_SPECIES, NULL); - show->frontier.species2 = GetMonData(&gPlayerParty[1], MON_DATA_SPECIES, NULL); - show->frontier.species3 = GetMonData(&gPlayerParty[2], MON_DATA_SPECIES, NULL); - show->frontier.species4 = GetMonData(&gPlayerParty[3], MON_DATA_SPECIES, NULL); - break; - case 3: - show->frontier.species1 = GetMonData(&gPlayerParty[0], MON_DATA_SPECIES, NULL); - show->frontier.species2 = GetMonData(&gPlayerParty[1], MON_DATA_SPECIES, NULL); - break; - case 4: - show->frontier.species1 = GetMonData(&gSaveBlock1Ptr->playerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[0] - 1], MON_DATA_SPECIES, NULL); - show->frontier.species2 = GetMonData(&gSaveBlock1Ptr->playerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[1] - 1], MON_DATA_SPECIES, NULL); - break; + case FRONTIER_SHOW_TOWER_SINGLES: + case FRONTIER_SHOW_DOME_SINGLES: + case FRONTIER_SHOW_DOME_DOUBLES: + case FRONTIER_SHOW_FACTORY_SINGLES: + case FRONTIER_SHOW_FACTORY_DOUBLES: + case FRONTIER_SHOW_PIKE: + case FRONTIER_SHOW_ARENA: + case FRONTIER_SHOW_PALACE_SINGLES: + case FRONTIER_SHOW_PALACE_DOUBLES: + case FRONTIER_SHOW_PYRAMID: + show->frontier.species1 = GetMonData(&gPlayerParty[0], MON_DATA_SPECIES, NULL); + show->frontier.species2 = GetMonData(&gPlayerParty[1], MON_DATA_SPECIES, NULL); + show->frontier.species3 = GetMonData(&gPlayerParty[2], MON_DATA_SPECIES, NULL); + break; + case FRONTIER_SHOW_TOWER_DOUBLES: + show->frontier.species1 = GetMonData(&gPlayerParty[0], MON_DATA_SPECIES, NULL); + show->frontier.species2 = GetMonData(&gPlayerParty[1], MON_DATA_SPECIES, NULL); + show->frontier.species3 = GetMonData(&gPlayerParty[2], MON_DATA_SPECIES, NULL); + show->frontier.species4 = GetMonData(&gPlayerParty[3], MON_DATA_SPECIES, NULL); + break; + case FRONTIER_SHOW_TOWER_MULTIS: + show->frontier.species1 = GetMonData(&gPlayerParty[0], MON_DATA_SPECIES, NULL); + show->frontier.species2 = GetMonData(&gPlayerParty[1], MON_DATA_SPECIES, NULL); + break; + case FRONTIER_SHOW_TOWER_LINK_MULTIS: + show->frontier.species1 = GetMonData(&gSaveBlock1Ptr->playerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[0] - 1], MON_DATA_SPECIES, NULL); + show->frontier.species2 = GetMonData(&gSaveBlock1Ptr->playerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[1] - 1], MON_DATA_SPECIES, NULL); + break; } - tv_store_id_3x(show); + StorePlayerIdInRecordMixShow(show); show->frontier.language = gGameLanguage; } } @@ -2544,14 +2428,14 @@ void TryPutSecretBaseSecretsOnAir(void) TVShow *show; u8 strbuf[32]; - if (HasMixableShowAlreadyBeenSpawnedWithPlayerID(TVSHOW_SECRET_BASE_SECRETS, FALSE) != TRUE) + if (IsRecordMixShowAlreadySpawned(TVSHOW_SECRET_BASE_SECRETS, FALSE) != TRUE) { - sCurTVShowSlot = FindEmptyTVSlotBeyondFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); + sCurTVShowSlot = FindFirstEmptyRecordMixTVShowSlot(gSaveBlock1Ptr->tvShows); if (sCurTVShowSlot != -1) { show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; show->secretBaseSecrets.kind = TVSHOW_SECRET_BASE_SECRETS; - show->secretBaseSecrets.active = FALSE; + show->secretBaseSecrets.active = FALSE; // NOTE: Show is not active until passed via Record Mix. StringCopy(show->secretBaseSecrets.playerName, gSaveBlock2Ptr->playerName); show->secretBaseSecrets.stepsInBase = VarGet(VAR_SECRET_BASE_STEP_COUNTER); CopyCurSecretBaseOwnerName_StrVar1(); @@ -2560,53 +2444,50 @@ void TryPutSecretBaseSecretsOnAir(void) StringCopy(show->secretBaseSecrets.baseOwnersName, strbuf); show->secretBaseSecrets.item = VarGet(VAR_SECRET_BASE_LAST_ITEM_USED); show->secretBaseSecrets.flags = VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) + (VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) << 16); - tv_store_id_3x(show); + StorePlayerIdInRecordMixShow(show); show->secretBaseSecrets.language = gGameLanguage; if (show->secretBaseSecrets.language == LANGUAGE_JAPANESE || gSaveBlock1Ptr->secretBases[VarGet(VAR_CURRENT_SECRET_BASE)].language == LANGUAGE_JAPANESE) - { show->secretBaseSecrets.baseOwnersNameLanguage = LANGUAGE_JAPANESE; - } else - { show->secretBaseSecrets.baseOwnersNameLanguage = gSaveBlock1Ptr->secretBases[VarGet(VAR_CURRENT_SECRET_BASE)].language; - } } } } -static void sub_80EEB98(u16 days) +// Check var thresholds required to trigger the Number One show +// The vars are reset afterwards regardless +static void ResolveNumberOneShow(u16 days) { u8 i; - for (i = 0; i < ARRAY_COUNT(sNumberOneVarsAndThresholds); i ++) + for (i = 0; i < ARRAY_COUNT(sNumberOneVarsAndThresholds); i++) { if (VarGet(sNumberOneVarsAndThresholds[i][0]) >= sNumberOneVarsAndThresholds[i][1]) { - sub_80EEBF4(i); + TryPutNumberOneOnAir(i); break; } } - for (i = 0; i < ARRAY_COUNT(sNumberOneVarsAndThresholds); i ++) - { + + for (i = 0; i < ARRAY_COUNT(sNumberOneVarsAndThresholds); i++) VarSet(sNumberOneVarsAndThresholds[i][0], 0); - } } -static void sub_80EEBF4(u8 actionIdx) +static void TryPutNumberOneOnAir(u8 actionIdx) { TVShow *show; - HasMixableShowAlreadyBeenSpawnedWithPlayerID(TVSHOW_NUMBER_ONE, TRUE); - sCurTVShowSlot = FindEmptyTVSlotBeyondFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); + IsRecordMixShowAlreadySpawned(TVSHOW_NUMBER_ONE, TRUE); // Delete old version of show + sCurTVShowSlot = FindFirstEmptyRecordMixTVShowSlot(gSaveBlock1Ptr->tvShows); if (sCurTVShowSlot != -1) { show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; show->numberOne.kind = TVSHOW_NUMBER_ONE; - show->numberOne.active = FALSE; + show->numberOne.active = FALSE; // NOTE: Show is not active until passed via Record Mix. StringCopy(show->numberOne.playerName, gSaveBlock2Ptr->playerName); show->numberOne.actionIdx = actionIdx; show->numberOne.count = VarGet(sNumberOneVarsAndThresholds[actionIdx][0]); - tv_store_id_3x(show); + StorePlayerIdInRecordMixShow(show); show->numberOne.language = gGameLanguage; } } @@ -2648,72 +2529,66 @@ void IncrementDailyBattlePoints(u16 delta) // PokeNews -static void sub_80EED88(void) +static void TryPutRandomPokeNewsOnAir(void) { - u8 newsKind; - if (FlagGet(FLAG_SYS_GAME_CLEAR)) { - sCurTVShowSlot = sub_80EEE30(gSaveBlock1Ptr->pokeNews); + sCurTVShowSlot = GetFirstEmptyPokeNewsSlot(gSaveBlock1Ptr->pokeNews); if (sCurTVShowSlot != -1 && rbernoulli(1, 100) != TRUE) { - newsKind = (Random() % 4) + POKENEWS_SLATEPORT; - if (sub_80EF0E4(newsKind) != TRUE) + u8 newsKind = (Random() % NUM_POKENEWS_TYPES) + POKENEWS_SLATEPORT; + if (IsAddingPokeNewsDisallowed(newsKind) != TRUE) { gSaveBlock1Ptr->pokeNews[sCurTVShowSlot].kind = newsKind; gSaveBlock1Ptr->pokeNews[sCurTVShowSlot].days = 4; - gSaveBlock1Ptr->pokeNews[sCurTVShowSlot].state = TRUE; + gSaveBlock1Ptr->pokeNews[sCurTVShowSlot].state = 1; } } } } -s8 sub_80EEE30(PokeNews *pokeNews) +static s8 GetFirstEmptyPokeNewsSlot(PokeNews *pokeNews) { s8 i; - for (i = 0; i < POKE_NEWS_COUNT; i ++) + for (i = 0; i < POKE_NEWS_COUNT; i++) { - if (pokeNews[i].kind == 0) - { + if (pokeNews[i].kind == POKENEWS_NONE) return i; - } } return -1; } -void ClearPokemonNews(void) +static void ClearPokeNews(void) { u8 i; - for (i = 0; i < POKE_NEWS_COUNT; i ++) - { - ClearPokemonNewsI(i); - } + for (i = 0; i < POKE_NEWS_COUNT; i++) + ClearPokeNewsBySlot(i); } -void ClearPokemonNewsI(u8 i) +static void ClearPokeNewsBySlot(u8 i) { gSaveBlock1Ptr->pokeNews[i].kind = POKENEWS_NONE; gSaveBlock1Ptr->pokeNews[i].state = FALSE; gSaveBlock1Ptr->pokeNews[i].days = 0; } -static void sub_80EEEB8(void) +static void CompactPokeNews(void) { u8 i; u8 j; - for (i = 0; i < POKE_NEWS_COUNT - 1; i ++) + for (i = 0; i < POKE_NEWS_COUNT - 1; i++) { if (gSaveBlock1Ptr->pokeNews[i].kind == POKENEWS_NONE) { - for (j = i + 1; j < POKE_NEWS_COUNT; j ++) + for (j = i + 1; j < POKE_NEWS_COUNT; j++) { if (gSaveBlock1Ptr->pokeNews[j].kind != POKENEWS_NONE) { gSaveBlock1Ptr->pokeNews[i] = gSaveBlock1Ptr->pokeNews[j]; - ClearPokemonNewsI(j); + ClearPokeNewsBySlot(j); break; } } @@ -2721,16 +2596,16 @@ static void sub_80EEEB8(void) } } -u8 FindAnyTVNewsOnTheAir(void) +static u8 FindAnyPokeNewsOnTheAir(void) { u8 i; - for (i = 0; i < POKE_NEWS_COUNT; i ++) + for (i = 0; i < POKE_NEWS_COUNT; i++) { - if (gSaveBlock1Ptr->pokeNews[i].kind != POKENEWS_NONE && gSaveBlock1Ptr->pokeNews[i].state == TRUE && gSaveBlock1Ptr->pokeNews[i].days < 3) - { + if (gSaveBlock1Ptr->pokeNews[i].kind != POKENEWS_NONE + && gSaveBlock1Ptr->pokeNews[i].state == 1 + && gSaveBlock1Ptr->pokeNews[i].days < 3) return i; - } } return 0xFF; } @@ -2740,7 +2615,7 @@ void DoPokeNews(void) u8 i; u16 n; - i = FindAnyTVNewsOnTheAir(); + i = FindAnyPokeNewsOnTheAir(); if (i == 0xFF) { gSpecialVar_Result = FALSE; @@ -2751,13 +2626,9 @@ void DoPokeNews(void) { gSaveBlock1Ptr->pokeNews[i].state = 2; if (gLocalTime.hours < 20) - { ShowFieldMessage(sPokeNewsTextGroup_Ongoing[gSaveBlock1Ptr->pokeNews[i].kind]); - } else - { ShowFieldMessage(sPokeNewsTextGroup_Ending[gSaveBlock1Ptr->pokeNews[i].kind]); - } } else { @@ -2775,101 +2646,92 @@ bool8 GetPriceReduction(u8 newsKind) u8 i; if (newsKind == POKENEWS_NONE) - { return FALSE; - } - for (i = 0; i < POKE_NEWS_COUNT; i ++) + + for (i = 0; i < POKE_NEWS_COUNT; i++) { if (gSaveBlock1Ptr->pokeNews[i].kind == newsKind) { if (gSaveBlock1Ptr->pokeNews[i].state == 2 && IsPriceDiscounted(newsKind)) - { return TRUE; - } + return FALSE; } } return FALSE; } -bool8 IsPriceDiscounted(u8 newsKind) +static bool8 IsPriceDiscounted(u8 newsKind) { switch (newsKind) { - case POKENEWS_SLATEPORT: - if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(SLATEPORT_CITY) && gSaveBlock1Ptr->location.mapNum == MAP_NUM(SLATEPORT_CITY) && gSpecialVar_LastTalked == 25) - { - return TRUE; - } - return FALSE; - case POKENEWS_LILYCOVE: - if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(LILYCOVE_CITY_DEPARTMENT_STORE_ROOFTOP) && gSaveBlock1Ptr->location.mapNum == MAP_NUM(LILYCOVE_CITY_DEPARTMENT_STORE_ROOFTOP)) - { - return TRUE; - } - return FALSE; + case POKENEWS_SLATEPORT: + if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(SLATEPORT_CITY) && gSaveBlock1Ptr->location.mapNum == MAP_NUM(SLATEPORT_CITY) && gSpecialVar_LastTalked == 25) + return TRUE; + return FALSE; + case POKENEWS_LILYCOVE: + if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(LILYCOVE_CITY_DEPARTMENT_STORE_ROOFTOP) && gSaveBlock1Ptr->location.mapNum == MAP_NUM(LILYCOVE_CITY_DEPARTMENT_STORE_ROOFTOP)) + return TRUE; + return FALSE; } return TRUE; } -bool8 sub_80EF0E4(u8 newsKind) +static bool8 IsAddingPokeNewsDisallowed(u8 newsKind) { u8 i; if (newsKind == POKENEWS_NONE) - { return TRUE; - } - for (i = 0; i < POKE_NEWS_COUNT; i ++) + + // Check if this type of news is already active + for (i = 0; i < POKE_NEWS_COUNT; i++) { if (gSaveBlock1Ptr->pokeNews[i].kind == newsKind) - { return TRUE; - } } return FALSE; } -static void sub_80EF120(u16 days) +static void UpdatePokeNewsTimeLeft(u16 days) { u8 i; - for (i = 0; i < POKE_NEWS_COUNT; i ++) + for (i = 0; i < POKE_NEWS_COUNT; i++) { if (gSaveBlock1Ptr->pokeNews[i].kind != POKENEWS_NONE) { if (gSaveBlock1Ptr->pokeNews[i].days < days) { - ClearPokemonNewsI(i); + ClearPokeNewsBySlot(i); } else { if (gSaveBlock1Ptr->pokeNews[i].state == 0 && FlagGet(FLAG_SYS_GAME_CLEAR) == TRUE) - { gSaveBlock1Ptr->pokeNews[i].state = 1; - } + gSaveBlock1Ptr->pokeNews[i].days -= days; } } } - sub_80EEEB8(); + CompactPokeNews(); } void CopyContestRankToStringVar(u8 varIdx, u8 rank) { switch (rank) { - case CONTEST_RANK_NORMAL: - StringCopy(gTVStringVarPtrs[varIdx], gStdStrings[STDSTRING_NORMAL]); - break; - case CONTEST_RANK_SUPER: - StringCopy(gTVStringVarPtrs[varIdx], gStdStrings[STDSTRING_SUPER]); - break; - case CONTEST_RANK_HYPER: - StringCopy(gTVStringVarPtrs[varIdx], gStdStrings[STDSTRING_HYPER]); - break; - case CONTEST_RANK_MASTER: - StringCopy(gTVStringVarPtrs[varIdx], gStdStrings[STDSTRING_MASTER]); - break; + case CONTEST_RANK_NORMAL: + StringCopy(gTVStringVarPtrs[varIdx], gStdStrings[STDSTRING_NORMAL]); + break; + case CONTEST_RANK_SUPER: + StringCopy(gTVStringVarPtrs[varIdx], gStdStrings[STDSTRING_SUPER]); + break; + case CONTEST_RANK_HYPER: + StringCopy(gTVStringVarPtrs[varIdx], gStdStrings[STDSTRING_HYPER]); + break; + case CONTEST_RANK_MASTER: + StringCopy(gTVStringVarPtrs[varIdx], gStdStrings[STDSTRING_MASTER]); + break; } } @@ -2877,21 +2739,21 @@ void CopyContestCategoryToStringVar(u8 varIdx, u8 category) { switch (category) { - case CONTEST_CATEGORY_COOL: - StringCopy(gTVStringVarPtrs[varIdx], gStdStrings[STDSTRING_COOL]); - break; - case CONTEST_CATEGORY_BEAUTY: - StringCopy(gTVStringVarPtrs[varIdx], gStdStrings[STDSTRING_BEAUTY]); - break; - case CONTEST_CATEGORY_CUTE: - StringCopy(gTVStringVarPtrs[varIdx], gStdStrings[STDSTRING_CUTE]); - break; - case CONTEST_CATEGORY_SMART: - StringCopy(gTVStringVarPtrs[varIdx], gStdStrings[STDSTRING_SMART]); - break; - case CONTEST_CATEGORY_TOUGH: - StringCopy(gTVStringVarPtrs[varIdx], gStdStrings[STDSTRING_TOUGH]); - break; + case CONTEST_CATEGORY_COOL: + StringCopy(gTVStringVarPtrs[varIdx], gStdStrings[STDSTRING_COOL]); + break; + case CONTEST_CATEGORY_BEAUTY: + StringCopy(gTVStringVarPtrs[varIdx], gStdStrings[STDSTRING_BEAUTY]); + break; + case CONTEST_CATEGORY_CUTE: + StringCopy(gTVStringVarPtrs[varIdx], gStdStrings[STDSTRING_CUTE]); + break; + case CONTEST_CATEGORY_SMART: + StringCopy(gTVStringVarPtrs[varIdx], gStdStrings[STDSTRING_SMART]); + break; + case CONTEST_CATEGORY_TOUGH: + StringCopy(gTVStringVarPtrs[varIdx], gStdStrings[STDSTRING_TOUGH]); + break; } } @@ -2903,11 +2765,9 @@ void SetContestCategoryStringVarForInterview(void) CopyContestCategoryToStringVar(1, show->bravoTrainer.contestCategory); } -void TV_PrintIntToStringVar(u8 varIdx, int value) +void ConvertIntToDecimalString(u8 varIdx, int value) { - int nDigits; - - nDigits = CountDigits(value); + int nDigits = CountDigits(value); ConvertIntToDecimalStringN(gTVStringVarPtrs[varIdx], value, STR_CONV_MODE_LEFT_ALIGN, nDigits); } @@ -2931,24 +2791,19 @@ static void sub_80EF40C(u8 varIdx, TVShow *show) int price; price = 0; - for (i = 0; i < 3; i ++) + for (i = 0; i < SMARTSHOPPER_NUM_ITEMS; i++) { if (show->smartshopperShow.itemIds[i] != ITEM_NONE) - { price += ItemId_GetPrice(show->smartshopperShow.itemIds[i]) * show->smartshopperShow.itemAmounts[i]; - } } + if (show->smartshopperShow.priceReduced == TRUE) - { - TV_PrintIntToStringVar(varIdx, price >> 1); - } + ConvertIntToDecimalString(varIdx, price >> 1); else - { - TV_PrintIntToStringVar(varIdx, price); - } + ConvertIntToDecimalString(varIdx, price); } -bool8 HasMixableShowAlreadyBeenSpawnedWithPlayerID(u8 kind, bool8 flag) +static bool8 IsRecordMixShowAlreadySpawned(u8 kind, bool8 delete) { u32 playerId; TVShow *shows; @@ -2956,14 +2811,16 @@ bool8 HasMixableShowAlreadyBeenSpawnedWithPlayerID(u8 kind, bool8 flag) shows = gSaveBlock1Ptr->tvShows; playerId = GetPlayerIDAsU32(); - for (i = 5; i < LAST_TVSHOW_IDX; i ++) + for (i = NUM_NORMAL_TVSHOW_SLOTS; i < LAST_TVSHOW_IDX; i++) { - if (shows[i].common.kind == kind && (playerId & 0xFF) == shows[i].common.trainerIdLo && ((playerId >> 8) & 0xFF) == shows[i].common.trainerIdHi) + if (shows[i].common.kind == kind + && (playerId & 0xFF) == shows[i].common.trainerIdLo + && ((playerId >> 8) & 0xFF) == shows[i].common.trainerIdHi) { - if (flag == TRUE) + if (delete == TRUE) { DeleteTVShowInArrayByIdx(gSaveBlock1Ptr->tvShows, i); - sub_80EF93C(gSaveBlock1Ptr->tvShows); + CompactTVShowArray(gSaveBlock1Ptr->tvShows); } return TRUE; } @@ -2971,16 +2828,15 @@ bool8 HasMixableShowAlreadyBeenSpawnedWithPlayerID(u8 kind, bool8 flag) return FALSE; } -void TV_SortPurchasesByQuantity(void) +static void SortPurchasesByQuantity(void) { - u8 i; - u8 j; + u8 i, j; u16 tmpId; u16 tmpQn; - for (i = 0; i < 2; i ++) + for (i = 0; i < SMARTSHOPPER_NUM_ITEMS - 1; i++) { - for (j = i + 1; j < 3; j ++) + for (j = i + 1; j < SMARTSHOPPER_NUM_ITEMS; j++) { if (gMartPurchaseHistory[i].quantity < gMartPurchaseHistory[j].quantity) { @@ -2995,27 +2851,31 @@ void TV_SortPurchasesByQuantity(void) } } -void FindActiveBroadcastByShowType_SetScriptResult(u8 kind) +static void TryReplaceOldTVShowOfKind(u8 kind) { u8 i; - for (i = 0; i < 5; i ++) + for (i = 0; i < NUM_NORMAL_TVSHOW_SLOTS; i++) { if (gSaveBlock1Ptr->tvShows[i].common.kind == kind) { if (gSaveBlock1Ptr->tvShows[i].common.active == TRUE) { + // Old TV show is still active, don't replace gSpecialVar_Result = TRUE; } else { + // Old TV show is inactive, replace it and get new slot DeleteTVShowInArrayByIdx(gSaveBlock1Ptr->tvShows, i); - sub_80EF93C(gSaveBlock1Ptr->tvShows); - sub_80EFA88(); + CompactTVShowArray(gSaveBlock1Ptr->tvShows); + Script_FindFirstEmptyNormalTVShowSlot(); } return; } } - sub_80EFA88(); + + // Old TV show doesn't exist, just get new slot + Script_FindFirstEmptyNormalTVShowSlot(); } void InterviewBefore(void) @@ -3023,42 +2883,42 @@ void InterviewBefore(void) gSpecialVar_Result = FALSE; switch (gSpecialVar_0x8005) { - case TVSHOW_FAN_CLUB_LETTER: - InterviewBefore_FanClubLetter(); - break; - case TVSHOW_RECENT_HAPPENINGS: - InterviewBefore_RecentHappenings(); - break; - case TVSHOW_PKMN_FAN_CLUB_OPINIONS: - InterviewBefore_PkmnFanClubOpinions(); - break; - case TVSHOW_UNKN_SHOWTYPE_04: - InterviewBefore_Dummy(); - break; - case TVSHOW_NAME_RATER_SHOW: - InterviewBefore_NameRater(); - break; - case TVSHOW_BRAVO_TRAINER_POKEMON_PROFILE: - InterviewBefore_BravoTrainerPkmnProfile(); - break; - case TVSHOW_BRAVO_TRAINER_BATTLE_TOWER_PROFILE: - InterviewBefore_BravoTrainerBTProfile(); - break; - case TVSHOW_CONTEST_LIVE_UPDATES: - InterviewBefore_ContestLiveUpdates(); - break; - case TVSHOW_3_CHEERS_FOR_POKEBLOCKS: - InterviewBefore_3CheersForPokeblocks(); - break; - case TVSHOW_FAN_CLUB_SPECIAL: - InterviewBefore_FanClubSpecial(); - break; + case TVSHOW_FAN_CLUB_LETTER: + InterviewBefore_FanClubLetter(); + break; + case TVSHOW_RECENT_HAPPENINGS: + InterviewBefore_RecentHappenings(); + break; + case TVSHOW_PKMN_FAN_CLUB_OPINIONS: + InterviewBefore_PkmnFanClubOpinions(); + break; + case TVSHOW_DUMMY: + InterviewBefore_Dummy(); + break; + case TVSHOW_NAME_RATER_SHOW: + InterviewBefore_NameRater(); + break; + case TVSHOW_BRAVO_TRAINER_POKEMON_PROFILE: + InterviewBefore_BravoTrainerPkmnProfile(); + break; + case TVSHOW_BRAVO_TRAINER_BATTLE_TOWER_PROFILE: + InterviewBefore_BravoTrainerBTProfile(); + break; + case TVSHOW_CONTEST_LIVE_UPDATES: + InterviewBefore_ContestLiveUpdates(); + break; + case TVSHOW_3_CHEERS_FOR_POKEBLOCKS: + InterviewBefore_3CheersForPokeblocks(); + break; + case TVSHOW_FAN_CLUB_SPECIAL: + InterviewBefore_FanClubSpecial(); + break; } } static void InterviewBefore_FanClubLetter(void) { - FindActiveBroadcastByShowType_SetScriptResult(TVSHOW_FAN_CLUB_LETTER); + TryReplaceOldTVShowOfKind(TVSHOW_FAN_CLUB_LETTER); if (!gSpecialVar_Result) { StringCopy(gStringVar1, gSpeciesNames[GetMonData(&gPlayerParty[GetLeadMonIndex()], MON_DATA_SPECIES, NULL)]); @@ -3068,7 +2928,7 @@ static void InterviewBefore_FanClubLetter(void) static void InterviewBefore_RecentHappenings(void) { - FindActiveBroadcastByShowType_SetScriptResult(TVSHOW_RECENT_HAPPENINGS); + TryReplaceOldTVShowOfKind(TVSHOW_RECENT_HAPPENINGS); if (!gSpecialVar_Result) { InitializeEasyChatWordArray(gSaveBlock1Ptr->tvShows[sCurTVShowSlot].recentHappenings.words, 6); @@ -3077,7 +2937,7 @@ static void InterviewBefore_RecentHappenings(void) static void InterviewBefore_PkmnFanClubOpinions(void) { - FindActiveBroadcastByShowType_SetScriptResult(TVSHOW_PKMN_FAN_CLUB_OPINIONS); + TryReplaceOldTVShowOfKind(TVSHOW_PKMN_FAN_CLUB_OPINIONS); if (!gSpecialVar_Result) { StringCopy(gStringVar1, gSpeciesNames[GetMonData(&gPlayerParty[GetLeadMonIndex()], MON_DATA_SPECIES, NULL)]); @@ -3094,44 +2954,38 @@ static void InterviewBefore_Dummy(void) static void InterviewBefore_NameRater(void) { - FindActiveBroadcastByShowType_SetScriptResult(TVSHOW_NAME_RATER_SHOW); + TryReplaceOldTVShowOfKind(TVSHOW_NAME_RATER_SHOW); } static void InterviewBefore_BravoTrainerPkmnProfile(void) { - FindActiveBroadcastByShowType_SetScriptResult(TVSHOW_BRAVO_TRAINER_POKEMON_PROFILE); + TryReplaceOldTVShowOfKind(TVSHOW_BRAVO_TRAINER_POKEMON_PROFILE); if (!gSpecialVar_Result) - { InitializeEasyChatWordArray(gSaveBlock1Ptr->tvShows[sCurTVShowSlot].bravoTrainer.words, 2); - } } static void InterviewBefore_ContestLiveUpdates(void) { - FindActiveBroadcastByShowType_SetScriptResult(TVSHOW_CONTEST_LIVE_UPDATES); + TryReplaceOldTVShowOfKind(TVSHOW_CONTEST_LIVE_UPDATES); } static void InterviewBefore_3CheersForPokeblocks(void) { - FindActiveBroadcastByShowType_SetScriptResult(TVSHOW_3_CHEERS_FOR_POKEBLOCKS); + TryReplaceOldTVShowOfKind(TVSHOW_3_CHEERS_FOR_POKEBLOCKS); } static void InterviewBefore_BravoTrainerBTProfile(void) { - FindActiveBroadcastByShowType_SetScriptResult(TVSHOW_BRAVO_TRAINER_BATTLE_TOWER_PROFILE); + TryReplaceOldTVShowOfKind(TVSHOW_BRAVO_TRAINER_BATTLE_TOWER_PROFILE); if (!gSpecialVar_Result) - { InitializeEasyChatWordArray(gSaveBlock1Ptr->tvShows[sCurTVShowSlot].bravoTrainerTower.words, 1); - } } static void InterviewBefore_FanClubSpecial(void) { - FindActiveBroadcastByShowType_SetScriptResult(TVSHOW_FAN_CLUB_SPECIAL); + TryReplaceOldTVShowOfKind(TVSHOW_FAN_CLUB_SPECIAL); if (!gSpecialVar_Result) - { InitializeEasyChatWordArray(gSaveBlock1Ptr->tvShows[sCurTVShowSlot].fanClubSpecial.words, 1); - } } static bool8 IsPartyMonNicknamedOrNotEnglish(u8 monIdx) @@ -3143,9 +2997,8 @@ static bool8 IsPartyMonNicknamedOrNotEnglish(u8 monIdx) GetMonData(pokemon, MON_DATA_NICKNAME, gStringVar1); language = GetMonData(pokemon, MON_DATA_LANGUAGE, &language); if (language == GAME_LANGUAGE && !StringCompare(gSpeciesNames[GetMonData(pokemon, MON_DATA_SPECIES, NULL)], gStringVar1)) - { return FALSE; - } + return TRUE; } @@ -3154,28 +3007,27 @@ bool8 IsLeadMonNicknamedOrNotEnglish(void) return IsPartyMonNicknamedOrNotEnglish(GetLeadMonIndex()); } -void DeleteTVShowInArrayByIdx(TVShow *shows, u8 idx) +static void DeleteTVShowInArrayByIdx(TVShow *shows, u8 idx) { u8 i; shows[idx].commonInit.kind = TVSHOW_OFF_AIR; shows[idx].commonInit.active = FALSE; - for (i = 0; i < ARRAY_COUNT(shows[idx].commonInit.pad02); i++) - { - shows[idx].commonInit.pad02[i] = 0; - } + for (i = 0; i < ARRAY_COUNT(shows[idx].commonInit.data); i++) + shows[idx].commonInit.data[i] = 0; } -static void sub_80EF93C(TVShow *shows) +static void CompactTVShowArray(TVShow *shows) { u8 i; u8 j; - for (i = 0; i < 4; i ++) + // Compact normal TV shows + for (i = 0; i < NUM_NORMAL_TVSHOW_SLOTS - 1; i++) { if (shows[i].common.kind == TVSHOW_OFF_AIR) { - for (j = i + 1; j < 5; j ++) + for (j = i + 1; j < NUM_NORMAL_TVSHOW_SLOTS; j++) { if (shows[j].common.kind != TVSHOW_OFF_AIR) { @@ -3186,11 +3038,13 @@ static void sub_80EF93C(TVShow *shows) } } } - for (i = 5; i < LAST_TVSHOW_IDX; i ++) + + // Compact Record Mix TV shows + for (i = NUM_NORMAL_TVSHOW_SLOTS; i < LAST_TVSHOW_IDX; i++) { if (shows[i].common.kind == TVSHOW_OFF_AIR) { - for (j = i + 1; j < LAST_TVSHOW_IDX; j ++) + for (j = i + 1; j < LAST_TVSHOW_IDX; j++) { if (shows[j].common.kind != TVSHOW_OFF_AIR) { @@ -3203,16 +3057,16 @@ static void sub_80EF93C(TVShow *shows) } } -u16 TV_GetSomeOtherSpeciesAlreadySeenByPlayer_AndPrintName(u8 varIdx, u16 passedSpecies) +static u16 GetRandomDifferentSpeciesAndNameSeenByPlayer(u8 varIdx, u16 passedSpecies) { u16 species; - species = TV_GetSomeOtherSpeciesAlreadySeenByPlayer(passedSpecies); + species = GetRandomDifferentSpeciesSeenByPlayer(passedSpecies); StringCopy(gTVStringVarPtrs[varIdx], gSpeciesNames[species]); return species; } -u16 TV_GetSomeOtherSpeciesAlreadySeenByPlayer(u16 passedSpecies) +static u16 GetRandomDifferentSpeciesSeenByPlayer(u16 passedSpecies) { u16 species; u16 initSpecies; @@ -3222,13 +3076,10 @@ u16 TV_GetSomeOtherSpeciesAlreadySeenByPlayer(u16 passedSpecies) while (GetSetPokedexFlag(SpeciesToNationalPokedexNum(species), FLAG_GET_SEEN) != TRUE || species == passedSpecies) { if (species == SPECIES_NONE + 1) - { species = NUM_SPECIES - 1; - } else - { - species --; - } + species--; + if (species == initSpecies) { species = passedSpecies; @@ -3238,65 +3089,60 @@ u16 TV_GetSomeOtherSpeciesAlreadySeenByPlayer(u16 passedSpecies) return species; } -static void sub_80EFA88(void) +static void Script_FindFirstEmptyNormalTVShowSlot(void) { - sCurTVShowSlot = FindEmptyTVSlotWithinFirstFiveShowsOfArray(gSaveBlock1Ptr->tvShows); + sCurTVShowSlot = FindFirstEmptyNormalTVShowSlot(gSaveBlock1Ptr->tvShows); gSpecialVar_0x8006 = sCurTVShowSlot; if (sCurTVShowSlot == -1) - { - gSpecialVar_Result = TRUE; - } + gSpecialVar_Result = TRUE; // Failed to find empty slot else - { - gSpecialVar_Result = FALSE; - } + gSpecialVar_Result = FALSE; // Found empty slot } -s8 FindEmptyTVSlotWithinFirstFiveShowsOfArray(TVShow *shows) +static s8 FindFirstEmptyNormalTVShowSlot(TVShow *shows) { u8 i; - for (i = 0; i < 5; i ++) + for (i = 0; i < NUM_NORMAL_TVSHOW_SLOTS; i++) { if (shows[i].common.kind == TVSHOW_OFF_AIR) - { return i; - } } return -1; } -s8 FindEmptyTVSlotBeyondFirstFiveShowsOfArray(TVShow *shows) +static s8 FindFirstEmptyRecordMixTVShowSlot(TVShow *shows) { s8 i; - for (i = 5; i < LAST_TVSHOW_IDX; i ++) + for (i = NUM_NORMAL_TVSHOW_SLOTS; i < LAST_TVSHOW_IDX; i++) { if (shows[i].common.kind == TVSHOW_OFF_AIR) - { return i; - } } return -1; } -bool8 TV_BernoulliTrial(u16 ratio) +static bool8 BernoulliTrial(u16 ratio) { if (Random() <= ratio) - { return FALSE; - } + return TRUE; } -void TV_FanClubLetter_RandomWordToStringVar3(TVShow *show) +// For TVSHOW_FAN_CLUB_LETTER / TVSHOW_RECENT_HAPPENINGS +// Both are assumed to have the same struct layout +static void GetRandomWordFromShow(TVShow *show) { u8 i; - i = Random() % 6; + i = Random() % ARRAY_COUNT(show->fanclubLetter.words); + + // From random point, get first non-empty word while (TRUE) { - if (i == 6) + if (i == ARRAY_COUNT(show->fanclubLetter.words)) i = 0; if (show->fanclubLetter.words[i] != EC_EMPTY_WORD) @@ -3306,33 +3152,31 @@ void TV_FanClubLetter_RandomWordToStringVar3(TVShow *show) CopyEasyChatWord(gStringVar3, show->fanclubLetter.words[i]); } -u8 TV_GetNicknameSumMod8(TVShow *show) +static u8 GetRandomNameRaterStateFromName(TVShow *show) { u8 i; - u16 ct; + u16 nameSum; - ct = 0; - for (i = 0; i < 11; i ++) + nameSum = 0; + for (i = 0; i < POKEMON_NAME_LENGTH + 1; i++) { if (show->nameRaterShow.pokemonName[i] == EOS) - { break; - } - ct += show->nameRaterShow.pokemonName[i]; + + nameSum += show->nameRaterShow.pokemonName[i]; } - return ct & 7; + return nameSum & 7; } -void TV_GetNicknameSubstring(u8 varIdx, u8 whichPosition, u8 charParam, u16 whichString, u16 species, TVShow *show) +static void GetNicknameSubstring(u8 varIdx, u8 whichPosition, u8 charParam, u16 whichString, u16 species, TVShow *show) { u8 buff[16]; u8 i; u16 strlen; - for (i = 0; i < 3; i ++) - { + for (i = 0; i < 3; i++) buff[i] = EOS; - } + if (whichString == 0) { strlen = StringLength(show->nameRaterShow.trainerName); @@ -3404,16 +3248,15 @@ void TV_GetNicknameSubstring(u8 varIdx, u8 whichPosition, u8 charParam, u16 whic StringCopy(gTVStringVarPtrs[varIdx], buff); } -bool8 TV_IsScriptShowKindAlreadyInQueue(void) +// Unused script special +bool8 IsTVShowAlreadyInQueue(void) { u8 i; - for (i = 0; i < 5; i ++) + for (i = 0; i < NUM_NORMAL_TVSHOW_SLOTS; i++) { if (gSaveBlock1Ptr->tvShows[i].common.kind == gSpecialVar_0x8004) - { return TRUE; - } } return FALSE; } @@ -3455,7 +3298,7 @@ void ChangeBoxPokemonNickname(void) DoNamingScreen(NAMING_SCREEN_NICKNAME, gStringVar2, GetBoxMonData(boxMon, MON_DATA_SPECIES, NULL), GetBoxMonGender(boxMon), GetBoxMonData(boxMon, MON_DATA_PERSONALITY, NULL), ChangeBoxPokemonNickname_CB); } -void ChangeBoxPokemonNickname_CB(void) +static void ChangeBoxPokemonNickname_CB(void) { SetBoxMonNickAt(gSpecialVar_MonBoxId, gSpecialVar_MonBoxPos, gStringVar2); CB2_ReturnToFieldContinueScriptPlayMapMusic(); @@ -3475,25 +3318,21 @@ void IsMonOTIDNotPlayers(void) gSpecialVar_Result = TRUE; } -u8 GetTVChannelByShowType(u8 kind) +static u8 GetTVGroupByShowId(u8 kind) { if (kind == TVSHOW_OFF_AIR) - { - return 0; - } - if (kind >= TVSHOW_FAN_CLUB_LETTER && kind < TVSHOW_POKEMON_TODAY_CAUGHT) - { - return 2; - } - if (kind >= TVSHOW_POKEMON_TODAY_CAUGHT && kind < TVSHOW_MASS_OUTBREAK) - { - return 3; - } - if (kind >= TVSHOW_MASS_OUTBREAK && kind < 61) - { - return 4; - } - return 0; + return TVGROUP_NONE; + + if (kind >= TVGROUP_NORMAL_START && kind <= TVGROUP_NORMAL_END) + return TVGROUP_NORMAL; + + if (kind >= TVGROUP_RECORD_MIX_START && kind <= TVGROUP_RECORD_MIX_END) + return TVGROUP_RECORD_MIX; + + if (kind >= TVGROUP_OUTBREAK_START && kind <= TVGROUP_OUTBREAK_END) + return TVGROUP_OUTBREAK; + + return TVGROUP_NONE; } u32 GetPlayerIDAsU32(void) @@ -3501,35 +3340,31 @@ u32 GetPlayerIDAsU32(void) return (gSaveBlock2Ptr->playerTrainerId[3] << 24) | (gSaveBlock2Ptr->playerTrainerId[2] << 16) | (gSaveBlock2Ptr->playerTrainerId[1] << 8) | gSaveBlock2Ptr->playerTrainerId[0]; } -u8 CheckForBigMovieOrEmergencyNewsOnTV(void) +u8 CheckForPlayersHouseNews(void) { + // Check if not in Littleroot house map group if (gSaveBlock1Ptr->location.mapGroup != MAP_GROUP(LITTLEROOT_TOWN_BRENDANS_HOUSE_1F)) - { - return 0; - } + return PLAYERS_HOUSE_TV_NONE; + + // Check if not in player's house (dependent on gender) if (gSaveBlock2Ptr->playerGender == MALE) { if (gSaveBlock1Ptr->location.mapNum != MAP_NUM(LITTLEROOT_TOWN_BRENDANS_HOUSE_1F)) - { - return 0; - } + return PLAYERS_HOUSE_TV_NONE; } else { if (gSaveBlock1Ptr->location.mapNum != MAP_NUM(LITTLEROOT_TOWN_MAYS_HOUSE_1F)) - { - return 0; - } + return PLAYERS_HOUSE_TV_NONE; } + if (FlagGet(FLAG_SYS_TV_LATIAS_LATIOS) == TRUE) - { - return 1; - } + return PLAYERS_HOUSE_TV_LATI; + if (FlagGet(FLAG_SYS_TV_HOME) == TRUE) - { - return 2; - } - return 1; + return PLAYERS_HOUSE_TV_MOVIE; + + return PLAYERS_HOUSE_TV_LATI; } void GetMomOrDadStringForTVMessage(void) @@ -3590,129 +3425,120 @@ void HideBattleTowerReporter(void) FlagSet(FLAG_HIDE_BATTLE_TOWER_REPORTER); } -void ReceiveTvShowsData(void *src, u32 size, u8 masterIdx) +void ReceiveTvShowsData(void *src, u32 size, u8 playersLinkId) { u8 i; u16 version; - TVShow (*rmBuffer2)[4][25]; - TVShow (*rmBuffer)[4][25]; + TVShow (*rmBuffer2)[MAX_LINK_PLAYERS][TV_SHOWS_COUNT]; + TVShow (*rmBuffer)[MAX_LINK_PLAYERS][TV_SHOWS_COUNT]; - rmBuffer2 = malloc(4 * 25 * sizeof(TVShow)); + rmBuffer2 = malloc(MAX_LINK_PLAYERS * TV_SHOWS_COUNT * sizeof(TVShow)); if (rmBuffer2 != NULL) { - for (i = 0; i < 4; i ++) - { + for (i = 0; i < MAX_LINK_PLAYERS; i++) memcpy((*rmBuffer2)[i], src + i * size, sizeof((*rmBuffer2)[i])); - } + rmBuffer = rmBuffer2; - for (i = 0; i < GetLinkPlayerCount(); i ++) + for (i = 0; i < GetLinkPlayerCount(); i++) { version = (u8)gLinkPlayers[i].version; if (version == VERSION_RUBY || version == VERSION_SAPPHIRE) - { - sub_80F1254((*rmBuffer)[i]); - } + TranslateRubyShows((*rmBuffer)[i]); else if (version == VERSION_EMERALD && gLinkPlayers[i].language == LANGUAGE_JAPANESE) - { - sub_80F12A4((*rmBuffer)[i]); - } + TranslateJapaneseEmeraldShows((*rmBuffer)[i]); } - switch (masterIdx) + + // Position player's TV shows in argument list depending on link id + switch (playersLinkId) { - case 0: - sub_80F0358(gSaveBlock1Ptr->tvShows, (*rmBuffer)[1], (*rmBuffer)[2], (*rmBuffer)[3]); - break; - case 1: - sub_80F0358((*rmBuffer)[0], gSaveBlock1Ptr->tvShows, (*rmBuffer)[2], (*rmBuffer)[3]); - break; - case 2: - sub_80F0358((*rmBuffer)[0], (*rmBuffer)[1], gSaveBlock1Ptr->tvShows, (*rmBuffer)[3]); - break; - case 3: - sub_80F0358((*rmBuffer)[0], (*rmBuffer)[1], (*rmBuffer)[2], gSaveBlock1Ptr->tvShows); - break; + case 0: + SetMixedTVShows(gSaveBlock1Ptr->tvShows, (*rmBuffer)[1], (*rmBuffer)[2], (*rmBuffer)[3]); + break; + case 1: + SetMixedTVShows((*rmBuffer)[0], gSaveBlock1Ptr->tvShows, (*rmBuffer)[2], (*rmBuffer)[3]); + break; + case 2: + SetMixedTVShows((*rmBuffer)[0], (*rmBuffer)[1], gSaveBlock1Ptr->tvShows, (*rmBuffer)[3]); + break; + case 3: + SetMixedTVShows((*rmBuffer)[0], (*rmBuffer)[1], (*rmBuffer)[2], gSaveBlock1Ptr->tvShows); + break; } - sub_80EF93C(gSaveBlock1Ptr->tvShows); - sub_80F0C04(); - sub_80EF93C(gSaveBlock1Ptr->tvShows); - sub_80F0708(); - sub_80F0B64(); + + CompactTVShowArray(gSaveBlock1Ptr->tvShows); + DeleteExcessMixedShows(); + CompactTVShowArray(gSaveBlock1Ptr->tvShows); + DeactivateShowsWithUnseenSpecies(); + DeactivateGameCompleteShowsIfNotUnlocked(); free(rmBuffer2); } } -static void sub_80F0358(TVShow player1[25], TVShow player2[25], TVShow player3[25], TVShow player4[25]) +static void SetMixedTVShows(TVShow player1[TV_SHOWS_COUNT], TVShow player2[TV_SHOWS_COUNT], TVShow player3[TV_SHOWS_COUNT], TVShow player4[TV_SHOWS_COUNT]) { u8 i; u8 j; - TVShow **argslist[4]; + TVShow **tvShows[MAX_LINK_PLAYERS]; - argslist[0] = &player1; - argslist[1] = &player2; - argslist[2] = &player3; - argslist[3] = &player4; + tvShows[0] = &player1; + tvShows[1] = &player2; + tvShows[2] = &player3; + tvShows[3] = &player4; sTVShowMixingNumPlayers = GetLinkPlayerCount(); while (1) { - for (i = 0; i < sTVShowMixingNumPlayers; i ++) + for (i = 0; i < sTVShowMixingNumPlayers; i++) { if (i == 0) - { - sRecordMixingPartnersWithoutShowsToShare = i; - } - sTVShowMixingCurSlot = sub_80F06D0(argslist[i][0]); + sRecordMixingPartnersWithoutShowsToShare = 0; + + sTVShowMixingCurSlot = FindInactiveShowInArray(tvShows[i][0]); if (sTVShowMixingCurSlot == -1) { - sRecordMixingPartnersWithoutShowsToShare ++; + sRecordMixingPartnersWithoutShowsToShare++; if (sRecordMixingPartnersWithoutShowsToShare == sTVShowMixingNumPlayers) - { return; - } } else { - for (j = 0; j < sTVShowMixingNumPlayers - 1; j ++) + for (j = 0; j < sTVShowMixingNumPlayers - 1; j++) { - sCurTVShowSlot = FindEmptyTVSlotBeyondFirstFiveShowsOfArray(argslist[(i + j + 1) % sTVShowMixingNumPlayers][0]); + sCurTVShowSlot = FindFirstEmptyRecordMixTVShowSlot(tvShows[(i + j + 1) % sTVShowMixingNumPlayers][0]); if (sCurTVShowSlot != -1 - && sub_80F049C(&argslist[(i + j + 1) % sTVShowMixingNumPlayers][0], &argslist[i][0], (i + j + 1) % sTVShowMixingNumPlayers) == 1) - { + && TryMixTVShow(&tvShows[(i + j + 1) % sTVShowMixingNumPlayers][0], &tvShows[i][0], (i + j + 1) % sTVShowMixingNumPlayers) == 1) break; - } } if (j == sTVShowMixingNumPlayers - 1) - { - DeleteTVShowInArrayByIdx(argslist[i][0], sTVShowMixingCurSlot); - } + DeleteTVShowInArrayByIdx(tvShows[i][0], sTVShowMixingCurSlot); } } } } -static bool8 sub_80F049C(TVShow *dest[25], TVShow *src[25], u8 idx) +static bool8 TryMixTVShow(TVShow *dest[TV_SHOWS_COUNT], TVShow *src[TV_SHOWS_COUNT], u8 idx) { - u8 value; - u8 switchval; - TVShow *tv1; - TVShow *tv2; + bool8 success; + u8 type; + TVShow *tv1 = *dest; + TVShow *tv2 = *src; - tv1 = *dest; - tv2 = *src; - value = FALSE; - switchval = GetTVChannelByShowType(tv2[sTVShowMixingCurSlot].common.kind); - switch (switchval) + success = FALSE; + type = GetTVGroupByShowId(tv2[sTVShowMixingCurSlot].common.kind); + switch (type) { - case 2: - value = sub_80F0580(&tv1[sCurTVShowSlot], &tv2[sTVShowMixingCurSlot], idx); - break; - case 3: - value = sub_80F05E8(&tv1[sCurTVShowSlot], &tv2[sTVShowMixingCurSlot], idx); - break; - case 4: - value = sub_80F0668(&tv1[sCurTVShowSlot], &tv2[sTVShowMixingCurSlot], idx); - break; + case TVGROUP_NORMAL: + success = TryMixNormalTVShow(&tv1[sCurTVShowSlot], &tv2[sTVShowMixingCurSlot], idx); + break; + case TVGROUP_RECORD_MIX: + success = TryMixRecordMixTVShow(&tv1[sCurTVShowSlot], &tv2[sTVShowMixingCurSlot], idx); + break; + case TVGROUP_OUTBREAK: + success = TryMixOutbreakTVShow(&tv1[sCurTVShowSlot], &tv2[sTVShowMixingCurSlot], idx); + break; } - if (value == TRUE) + + // Show was mixed, delete from array + if (success == TRUE) { DeleteTVShowInArrayByIdx(tv2, sTVShowMixingCurSlot); return TRUE; @@ -3720,385 +3546,354 @@ static bool8 sub_80F049C(TVShow *dest[25], TVShow *src[25], u8 idx) return FALSE; } -static bool8 sub_80F0580(TVShow *tv1, TVShow *tv2, u8 idx) +static bool8 TryMixNormalTVShow(TVShow *dest, TVShow *src, u8 idx) { u32 linkTrainerId = GetLinkPlayerTrainerId(idx); - if ((linkTrainerId & 0xFF) == tv2->common.trainerIdLo && ((linkTrainerId >> 8) & 0xFF) == tv2->common.trainerIdHi) - { + if ((linkTrainerId & 0xFF) == src->common.trainerIdLo + && ((linkTrainerId >> 8) & 0xFF) == src->common.trainerIdHi) return FALSE; - } - tv2->common.trainerIdLo = tv2->common.srcTrainerIdLo; - tv2->common.trainerIdHi = tv2->common.srcTrainerIdHi; - tv2->common.srcTrainerIdLo = linkTrainerId & 0xFF; - tv2->common.srcTrainerIdHi = linkTrainerId >> 8; - *tv1 = *tv2; - tv1->common.active = TRUE; + + src->common.trainerIdLo = src->common.srcTrainerIdLo; + src->common.trainerIdHi = src->common.srcTrainerIdHi; + src->common.srcTrainerIdLo = linkTrainerId & 0xFF; + src->common.srcTrainerIdHi = linkTrainerId >> 8; + *dest = *src; + dest->common.active = TRUE; return TRUE; } -static bool8 sub_80F05E8(TVShow *tv1, TVShow *tv2, u8 idx) +static bool8 TryMixRecordMixTVShow(TVShow *dest, TVShow *src, u8 idx) { u32 linkTrainerId = GetLinkPlayerTrainerId(idx); - if ((linkTrainerId & 0xFF) == tv2->common.srcTrainerIdLo && ((linkTrainerId >> 8) & 0xFF) == tv2->common.srcTrainerIdHi) - { + + if ((linkTrainerId & 0xFF) == src->common.srcTrainerIdLo + && ((linkTrainerId >> 8) & 0xFF) == src->common.srcTrainerIdHi) return FALSE; - } - if ((linkTrainerId & 0xFF) == tv2->common.trainerIdLo && ((linkTrainerId >> 8) & 0xFF) == tv2->common.trainerIdHi) - { + + if ((linkTrainerId & 0xFF) == src->common.trainerIdLo + && ((linkTrainerId >> 8) & 0xFF) == src->common.trainerIdHi) return FALSE; - } - tv2->common.srcTrainerIdLo = tv2->common.srcTrainerId2Lo; - tv2->common.srcTrainerIdHi = tv2->common.srcTrainerId2Hi; - tv2->common.srcTrainerId2Lo = linkTrainerId & 0xFF; - tv2->common.srcTrainerId2Hi = linkTrainerId >> 8; - *tv1 = *tv2; - tv1->common.active = TRUE; + + src->common.srcTrainerIdLo = src->common.srcTrainerId2Lo; + src->common.srcTrainerIdHi = src->common.srcTrainerId2Hi; + src->common.srcTrainerId2Lo = linkTrainerId & 0xFF; + src->common.srcTrainerId2Hi = linkTrainerId >> 8; + *dest = *src; + dest->common.active = TRUE; return TRUE; } -static bool8 sub_80F0668(TVShow *tv1, TVShow *tv2, u8 idx) +static bool8 TryMixOutbreakTVShow(TVShow *dest, TVShow *src, u8 idx) { u32 linkTrainerId = GetLinkPlayerTrainerId(idx); - if ((linkTrainerId & 0xFF) == tv2->common.trainerIdLo && ((linkTrainerId >> 8) & 0xFF) == tv2->common.trainerIdHi) - { + + if ((linkTrainerId & 0xFF) == src->common.trainerIdLo + && ((linkTrainerId >> 8) & 0xFF) == src->common.trainerIdHi) return FALSE; - } - tv2->common.trainerIdLo = tv2->common.srcTrainerIdLo; - tv2->common.trainerIdHi = tv2->common.srcTrainerIdHi; - tv2->common.srcTrainerIdLo = linkTrainerId & 0xFF; - tv2->common.srcTrainerIdHi = linkTrainerId >> 8; - *tv1 = *tv2; - tv1->common.active = TRUE; - tv1->massOutbreak.daysLeft = 1; + + src->common.trainerIdLo = src->common.srcTrainerIdLo; + src->common.trainerIdHi = src->common.srcTrainerIdHi; + src->common.srcTrainerIdLo = linkTrainerId & 0xFF; + src->common.srcTrainerIdHi = linkTrainerId >> 8; + *dest = *src; + dest->common.active = TRUE; + dest->massOutbreak.daysLeft = 1; return TRUE; } -static s8 sub_80F06D0(TVShow *tvShows) +static s8 FindInactiveShowInArray(TVShow *tvShows) { u8 i; - for (i = 0; i < LAST_TVSHOW_IDX; i ++) + for (i = 0; i < LAST_TVSHOW_IDX; i++) { - if (tvShows[i].common.active == FALSE && (u8)(tvShows[i].common.kind - 1) < 60) - { + // Second check is to make sure its a valid show (not too high, not TVSHOW_OFF_AIR) + if (tvShows[i].common.active == FALSE && (u8)(tvShows[i].common.kind - 1) < TVGROUP_OUTBREAK_END) return i; - } } return -1; } -static void sub_80F0708(void) // FIXME: register allocation shenanigans +static void DeactivateShowsWithUnseenSpecies(void) { u16 i; - u16 j; + u16 species; - for (i = 0; i < LAST_TVSHOW_IDX; i ++) + for (i = 0; i < LAST_TVSHOW_IDX; i++) { switch (gSaveBlock1Ptr->tvShows[i].common.kind) { - case TVSHOW_CONTEST_LIVE_UPDATES: - j = (&gSaveBlock1Ptr->tvShows[i])->contestLiveUpdates.winningSpecies; - sub_80F0B24(j, i); - j = (&gSaveBlock1Ptr->tvShows[i])->contestLiveUpdates.losingSpecies; - sub_80F0B24(j, i); + case TVSHOW_CONTEST_LIVE_UPDATES: + species = (&gSaveBlock1Ptr->tvShows[i])->contestLiveUpdates.winningSpecies; + DeactivateShowIfNotSeenSpecies(species, i); + species = (&gSaveBlock1Ptr->tvShows[i])->contestLiveUpdates.losingSpecies; + DeactivateShowIfNotSeenSpecies(species, i); + break; + case TVSHOW_BATTLE_UPDATE: + species = (&gSaveBlock1Ptr->tvShows[i])->battleUpdate.speciesPlayer; + DeactivateShowIfNotSeenSpecies(species, i); + species = (&gSaveBlock1Ptr->tvShows[i])->battleUpdate.speciesOpponent; + DeactivateShowIfNotSeenSpecies(species, i); + break; + case TVSHOW_FAN_CLUB_LETTER: + species = (&gSaveBlock1Ptr->tvShows[i])->fanclubLetter.species; + DeactivateShowIfNotSeenSpecies(species, i); + break; + case TVSHOW_PKMN_FAN_CLUB_OPINIONS: + species = (&gSaveBlock1Ptr->tvShows[i])->fanclubOpinions.species; + DeactivateShowIfNotSeenSpecies(species, i); + break; + case TVSHOW_DUMMY: + species = (&gSaveBlock1Ptr->tvShows[i])->dummy.species; + DeactivateShowIfNotSeenSpecies(species, i); + break; + case TVSHOW_NAME_RATER_SHOW: + species = (&gSaveBlock1Ptr->tvShows[i])->nameRaterShow.species; + DeactivateShowIfNotSeenSpecies(species, i); + species = (&gSaveBlock1Ptr->tvShows[i])->nameRaterShow.randomSpecies; + DeactivateShowIfNotSeenSpecies(species, i); + break; + case TVSHOW_BRAVO_TRAINER_POKEMON_PROFILE: + species = (&gSaveBlock1Ptr->tvShows[i])->bravoTrainer.species; + DeactivateShowIfNotSeenSpecies(species, i); + break; + case TVSHOW_BRAVO_TRAINER_BATTLE_TOWER_PROFILE: + species = (&gSaveBlock1Ptr->tvShows[i])->bravoTrainerTower.species; + DeactivateShowIfNotSeenSpecies(species, i); + species = (&gSaveBlock1Ptr->tvShows[i])->bravoTrainerTower.defeatedSpecies; + DeactivateShowIfNotSeenSpecies(species, i); + break; + case TVSHOW_POKEMON_TODAY_CAUGHT: + species = (&gSaveBlock1Ptr->tvShows[i])->pokemonToday.species; + DeactivateShowIfNotSeenSpecies(species, i); + break; + case TVSHOW_POKEMON_TODAY_FAILED: + species = (&gSaveBlock1Ptr->tvShows[i])->pokemonTodayFailed.species; + DeactivateShowIfNotSeenSpecies(species, i); + species = (&gSaveBlock1Ptr->tvShows[i])->pokemonTodayFailed.species2; + DeactivateShowIfNotSeenSpecies(species, i); + break; + case TVSHOW_FISHING_ADVICE: + species = (&gSaveBlock1Ptr->tvShows[i])->pokemonAngler.species; + DeactivateShowIfNotSeenSpecies(species, i); + break; + case TVSHOW_WORLD_OF_MASTERS: + species = (&gSaveBlock1Ptr->tvShows[i])->worldOfMasters.species; + DeactivateShowIfNotSeenSpecies(species, i); + species = (&gSaveBlock1Ptr->tvShows[i])->worldOfMasters.caughtPoke; + DeactivateShowIfNotSeenSpecies(species, i); + break; + case TVSHOW_BREAKING_NEWS: + species = (&gSaveBlock1Ptr->tvShows[i])->breakingNews.lastOpponentSpecies; + DeactivateShowIfNotSeenSpecies(species, i); + species = (&gSaveBlock1Ptr->tvShows[i])->breakingNews.poke1Species; + DeactivateShowIfNotSeenSpecies(species, i); + break; + case TVSHOW_SECRET_BASE_VISIT: + species = (&gSaveBlock1Ptr->tvShows[i])->secretBaseVisit.species; + DeactivateShowIfNotSeenSpecies(species, i); + break; + case TVSHOW_BATTLE_SEMINAR: + species = (&gSaveBlock1Ptr->tvShows[i])->battleSeminar.species; + DeactivateShowIfNotSeenSpecies(species, i); + species = (&gSaveBlock1Ptr->tvShows[i])->battleSeminar.foeSpecies; + DeactivateShowIfNotSeenSpecies(species, i); + break; + case TVSHOW_FRONTIER: + species = (&gSaveBlock1Ptr->tvShows[i])->frontier.species1; + DeactivateShowIfNotSeenSpecies(species, i); + species = (&gSaveBlock1Ptr->tvShows[i])->frontier.species2; + DeactivateShowIfNotSeenSpecies(species, i); + // Species var re-used here + species = (&gSaveBlock1Ptr->tvShows[i])->frontier.facilityAndMode; + switch (species) + { + case FRONTIER_SHOW_TOWER_MULTIS: + case FRONTIER_SHOW_TOWER_LINK_MULTIS: break; - case TVSHOW_3_CHEERS_FOR_POKEBLOCKS: + case FRONTIER_SHOW_TOWER_SINGLES: + case FRONTIER_SHOW_DOME_SINGLES: + case FRONTIER_SHOW_DOME_DOUBLES: + case FRONTIER_SHOW_FACTORY_SINGLES: + case FRONTIER_SHOW_FACTORY_DOUBLES: + case FRONTIER_SHOW_PIKE: + case FRONTIER_SHOW_ARENA: + case FRONTIER_SHOW_PALACE_SINGLES: + case FRONTIER_SHOW_PALACE_DOUBLES: + case FRONTIER_SHOW_PYRAMID: + species = (&gSaveBlock1Ptr->tvShows[i])->frontier.species3; + DeactivateShowIfNotSeenSpecies(species, i); break; - case TVSHOW_BATTLE_UPDATE: - j = (&gSaveBlock1Ptr->tvShows[i])->battleUpdate.speciesPlayer; - sub_80F0B24(j, i); - j = (&gSaveBlock1Ptr->tvShows[i])->battleUpdate.speciesOpponent; - sub_80F0B24(j, i); - break; - case TVSHOW_FAN_CLUB_SPECIAL: - break; - case TVSHOW_LILYCOVE_CONTEST_LADY: - break; - case TVSHOW_OFF_AIR: - break; - case TVSHOW_FAN_CLUB_LETTER: - j = (&gSaveBlock1Ptr->tvShows[i])->fanclubLetter.species; - sub_80F0B24(j, i); - break; - case TVSHOW_RECENT_HAPPENINGS: - break; - case TVSHOW_PKMN_FAN_CLUB_OPINIONS: - j = (&gSaveBlock1Ptr->tvShows[i])->fanclubOpinions.species; - sub_80F0B24(j, i); - break; - case TVSHOW_UNKN_SHOWTYPE_04: - j = (&gSaveBlock1Ptr->tvShows[i])->unkShow04.var06; - sub_80F0B24(j, i); - break; - case TVSHOW_NAME_RATER_SHOW: - j = (&gSaveBlock1Ptr->tvShows[i])->nameRaterShow.species; - sub_80F0B24(j, i); - j = (&gSaveBlock1Ptr->tvShows[i])->nameRaterShow.randomSpecies; - sub_80F0B24(j, i); - break; - case TVSHOW_BRAVO_TRAINER_POKEMON_PROFILE: - j = (&gSaveBlock1Ptr->tvShows[i])->bravoTrainer.species; - sub_80F0B24(j, i); - break; - case TVSHOW_BRAVO_TRAINER_BATTLE_TOWER_PROFILE: - j = (&gSaveBlock1Ptr->tvShows[i])->bravoTrainerTower.species; - sub_80F0B24(j, i); - j = (&gSaveBlock1Ptr->tvShows[i])->bravoTrainerTower.defeatedSpecies; - sub_80F0B24(j, i); - break; - - case TVSHOW_POKEMON_TODAY_CAUGHT: - j = (&gSaveBlock1Ptr->tvShows[i])->pokemonToday.species; - sub_80F0B24(j, i); - break; - case TVSHOW_SMART_SHOPPER: - break; - case TVSHOW_POKEMON_TODAY_FAILED: - j = (&gSaveBlock1Ptr->tvShows[i])->pokemonTodayFailed.species; - sub_80F0B24(j, i); - j = (&gSaveBlock1Ptr->tvShows[i])->pokemonTodayFailed.species2; - sub_80F0B24(j, i); - break; - case TVSHOW_FISHING_ADVICE: - j = (&gSaveBlock1Ptr->tvShows[i])->pokemonAngler.species; - sub_80F0B24(j, i); - break; - case TVSHOW_WORLD_OF_MASTERS: - j = (&gSaveBlock1Ptr->tvShows[i])->worldOfMasters.species; - sub_80F0B24(j, i); - j = (&gSaveBlock1Ptr->tvShows[i])->worldOfMasters.caughtPoke; - sub_80F0B24(j, i); - break; - - case TVSHOW_TODAYS_RIVAL_TRAINER: - break; - case TVSHOW_TREND_WATCHER: - break; - case TVSHOW_TREASURE_INVESTIGATORS: - break; - case TVSHOW_FIND_THAT_GAMER: - break; - case TVSHOW_BREAKING_NEWS: - j = (&gSaveBlock1Ptr->tvShows[i])->breakingNews.lastOpponentSpecies; - sub_80F0B24(j, i); - j = (&gSaveBlock1Ptr->tvShows[i])->breakingNews.poke1Species; - sub_80F0B24(j, i); - break; - case TVSHOW_SECRET_BASE_VISIT: - j = (&gSaveBlock1Ptr->tvShows[i])->secretBaseVisit.species; - sub_80F0B24(j, i); - break; - case TVSHOW_LOTTO_WINNER: - break; - case TVSHOW_BATTLE_SEMINAR: - j = (&gSaveBlock1Ptr->tvShows[i])->battleSeminar.species; - sub_80F0B24(j, i); - j = (&gSaveBlock1Ptr->tvShows[i])->battleSeminar.foeSpecies; - sub_80F0B24(j, i); - break; - case TVSHOW_TRAINER_FAN_CLUB: - break; - case TVSHOW_CUTIES: - break; - case TVSHOW_FRONTIER: - j = (&gSaveBlock1Ptr->tvShows[i])->frontier.species1; - sub_80F0B24(j, i); - j = (&gSaveBlock1Ptr->tvShows[i])->frontier.species2; - sub_80F0B24(j, i); - j = (&gSaveBlock1Ptr->tvShows[i])->frontier.facility; - switch (j) - { - case 3: - case 4: - break; - case 1: - case 5 ... 13: - j = (&gSaveBlock1Ptr->tvShows[i])->frontier.species3; - sub_80F0B24(j, i); - break; - case 2: - j = (&gSaveBlock1Ptr->tvShows[i])->frontier.species3; - sub_80F0B24(j, i); - j = (&gSaveBlock1Ptr->tvShows[i])->frontier.species4; - sub_80F0B24(j, i); - break; - } - break; - case TVSHOW_NUMBER_ONE: - break; - case TVSHOW_SECRET_BASE_SECRETS: - break; - case TVSHOW_SAFARI_FAN_CLUB: - break; - - case TVSHOW_MASS_OUTBREAK: - break; - - default: - SetTvShowInactive(i); + case FRONTIER_SHOW_TOWER_DOUBLES: + species = (&gSaveBlock1Ptr->tvShows[i])->frontier.species3; + DeactivateShowIfNotSeenSpecies(species, i); + species = (&gSaveBlock1Ptr->tvShows[i])->frontier.species4; + DeactivateShowIfNotSeenSpecies(species, i); break; + } + break; + // Shows with no species + case TVSHOW_OFF_AIR: + case TVSHOW_RECENT_HAPPENINGS: + case TVSHOW_3_CHEERS_FOR_POKEBLOCKS: + case TVSHOW_TODAYS_RIVAL_TRAINER: + case TVSHOW_TREND_WATCHER: + case TVSHOW_TREASURE_INVESTIGATORS: + case TVSHOW_FIND_THAT_GAMER: + case TVSHOW_TRAINER_FAN_CLUB: + case TVSHOW_CUTIES: + case TVSHOW_SMART_SHOPPER: + case TVSHOW_FAN_CLUB_SPECIAL: + case TVSHOW_LILYCOVE_CONTEST_LADY: + case TVSHOW_LOTTO_WINNER: + case TVSHOW_NUMBER_ONE: + case TVSHOW_SECRET_BASE_SECRETS: + case TVSHOW_SAFARI_FAN_CLUB: + case TVSHOW_MASS_OUTBREAK: + break; + default: + DeactivateShow(i); + break; } } } -void SetTvShowInactive(u8 showIdx) +static void DeactivateShow(u8 showIdx) { gSaveBlock1Ptr->tvShows[showIdx].common.active = FALSE; } -static void sub_80F0B24(u16 species, u8 showIdx) +static void DeactivateShowIfNotSeenSpecies(u16 species, u8 showIdx) { if (!GetSetPokedexFlag(SpeciesToNationalPokedexNum(species), FLAG_GET_SEEN)) - { gSaveBlock1Ptr->tvShows[showIdx].common.active = FALSE; - } } -static void sub_80F0B64(void) +static void DeactivateGameCompleteShowsIfNotUnlocked(void) { u16 i; if (FlagGet(FLAG_SYS_GAME_CLEAR) != TRUE) { - for (i = 0; i < LAST_TVSHOW_IDX; i ++) + for (i = 0; i < LAST_TVSHOW_IDX; i++) { if (gSaveBlock1Ptr->tvShows[i].common.kind == TVSHOW_BRAVO_TRAINER_BATTLE_TOWER_PROFILE) - { gSaveBlock1Ptr->tvShows[i].common.active = FALSE; - } else if (gSaveBlock1Ptr->tvShows[i].common.kind == TVSHOW_MASS_OUTBREAK) - { gSaveBlock1Ptr->tvShows[i].common.active = FALSE; - } } } } -void sub_80F0BB8(void) +void DeactivateAllNormalTVShows(void) { u8 i; - for (i = 0; i < 5; i ++) + for (i = 0; i < NUM_NORMAL_TVSHOW_SLOTS; i++) { - if (GetTVChannelByShowType(gSaveBlock1Ptr->tvShows[i].common.kind) == 2) - { + if (GetTVGroupByShowId(gSaveBlock1Ptr->tvShows[i].common.kind) == TVGROUP_NORMAL) gSaveBlock1Ptr->tvShows[i].common.active = FALSE; - } } } -static void sub_80F0C04(void) +// Ensures a minimum of 5 empty mixed show slots +static void DeleteExcessMixedShows(void) { s8 i; - s8 ct; - - ct = 0; - for (i = 5; i < LAST_TVSHOW_IDX; i ++) + s8 numEmptyMixSlots = 0; + for (i = NUM_NORMAL_TVSHOW_SLOTS; i < LAST_TVSHOW_IDX; i++) { if (gSaveBlock1Ptr->tvShows[i].common.kind == TVSHOW_OFF_AIR) - { - ct ++; - } - } - for (i = 0; i < 5 - ct; i ++) - { - DeleteTVShowInArrayByIdx(gSaveBlock1Ptr->tvShows, i + 5); + numEmptyMixSlots++; } + for (i = 0; i < NUM_NORMAL_TVSHOW_SLOTS - numEmptyMixSlots; i++) + DeleteTVShowInArrayByIdx(gSaveBlock1Ptr->tvShows, i + NUM_NORMAL_TVSHOW_SLOTS); } -void ReceivePokeNewsData(void *src, u32 size, u8 masterIdx) +void ReceivePokeNewsData(void *src, u32 size, u8 playersLinkId) { u8 i; - PokeNews (*rmBuffer2)[4][16]; - PokeNews (*rmBuffer)[4][16]; + PokeNews (*rmBuffer2)[MAX_LINK_PLAYERS][POKE_NEWS_COUNT]; + PokeNews (*rmBuffer)[MAX_LINK_PLAYERS][POKE_NEWS_COUNT]; - rmBuffer2 = malloc(4 * 16 * sizeof(PokeNews)); + rmBuffer2 = malloc(MAX_LINK_PLAYERS * POKE_NEWS_COUNT * sizeof(PokeNews)); if (rmBuffer2 != NULL) { - for (i = 0; i < 4; i ++) - { + for (i = 0; i < MAX_LINK_PLAYERS; i++) memcpy((*rmBuffer2)[i], src + i * size, sizeof((*rmBuffer2)[i])); - } + rmBuffer = rmBuffer2; - switch (masterIdx) + + // Position player's PokeNews in argument list depending on link id + switch (playersLinkId) { - case 0: - sub_80F0D60(gSaveBlock1Ptr->pokeNews, (*rmBuffer)[1], (*rmBuffer)[2], (*rmBuffer)[3]); - break; - case 1: - sub_80F0D60((*rmBuffer)[0], gSaveBlock1Ptr->pokeNews, (*rmBuffer)[2], (*rmBuffer)[3]); - break; - case 2: - sub_80F0D60((*rmBuffer)[0], (*rmBuffer)[1], gSaveBlock1Ptr->pokeNews, (*rmBuffer)[3]); - break; - case 3: - sub_80F0D60((*rmBuffer)[0], (*rmBuffer)[1], (*rmBuffer)[2], gSaveBlock1Ptr->pokeNews); - break; + case 0: + SetMixedPokeNews(gSaveBlock1Ptr->pokeNews, (*rmBuffer)[1], (*rmBuffer)[2], (*rmBuffer)[3]); + break; + case 1: + SetMixedPokeNews((*rmBuffer)[0], gSaveBlock1Ptr->pokeNews, (*rmBuffer)[2], (*rmBuffer)[3]); + break; + case 2: + SetMixedPokeNews((*rmBuffer)[0], (*rmBuffer)[1], gSaveBlock1Ptr->pokeNews, (*rmBuffer)[3]); + break; + case 3: + SetMixedPokeNews((*rmBuffer)[0], (*rmBuffer)[1], (*rmBuffer)[2], gSaveBlock1Ptr->pokeNews); + break; } - sub_80F0EEC(); - sub_80F0F24(); + ClearInvalidPokeNews(); + ClearPokeNewsIfGameNotComplete(); free(rmBuffer2); } } -static void sub_80F0D60(PokeNews player1[16], PokeNews player2[16], PokeNews player3[16], PokeNews player4[16]) +static void SetMixedPokeNews(PokeNews player1[POKE_NEWS_COUNT], PokeNews player2[POKE_NEWS_COUNT], PokeNews player3[POKE_NEWS_COUNT], PokeNews player4[POKE_NEWS_COUNT]) { - u8 i; - u8 j; - u8 k; - PokeNews **argslist[4]; + u8 i, j, k; + PokeNews **pokeNews[MAX_LINK_PLAYERS]; - argslist[0] = &player1; - argslist[1] = &player2; - argslist[2] = &player3; - argslist[3] = &player4; + pokeNews[0] = &player1; + pokeNews[1] = &player2; + pokeNews[2] = &player3; + pokeNews[3] = &player4; sTVShowNewsMixingNumPlayers = GetLinkPlayerCount(); - for (i = 0; i < POKE_NEWS_COUNT; i ++) + for (i = 0; i < POKE_NEWS_COUNT; i++) { - for (j = 0; j < sTVShowNewsMixingNumPlayers; j ++) + for (j = 0; j < sTVShowNewsMixingNumPlayers; j++) { - sTVShowMixingCurSlot = sub_80F0ECC(*argslist[j], i); + sTVShowMixingCurSlot = GetPokeNewsSlotIfActive(*pokeNews[j], i); if (sTVShowMixingCurSlot != -1) { for (k = 0; k < sTVShowNewsMixingNumPlayers - 1; k++) { - sCurTVShowSlot = sub_80EEE30(*argslist[(j + k + 1) % sTVShowNewsMixingNumPlayers]); + sCurTVShowSlot = GetFirstEmptyPokeNewsSlot(*pokeNews[(j + k + 1) % sTVShowNewsMixingNumPlayers]); if (sCurTVShowSlot != -1) - { - sub_80F0E58(argslist[(j + k + 1) % sTVShowNewsMixingNumPlayers], argslist[j]); - } + InitTryMixPokeNewsShow(pokeNews[(j + k + 1) % sTVShowNewsMixingNumPlayers], pokeNews[j]); } } } } } -static void sub_80F0E58(PokeNews *dest[16], PokeNews *src[16]) +static void InitTryMixPokeNewsShow(PokeNews *dest[POKE_NEWS_COUNT], PokeNews *src[POKE_NEWS_COUNT]) { - PokeNews *ptr1; - PokeNews *ptr2; - - ptr1 = *dest; - ptr2 = *src; + PokeNews *ptr1 = *dest; + PokeNews *ptr2 = *src; ptr2 += sTVShowMixingCurSlot; - sub_80F0E84(ptr1, ptr2, sCurTVShowSlot); + TryMixPokeNewsShow(ptr1, ptr2, sCurTVShowSlot); } -static bool8 sub_80F0E84(PokeNews *dest, PokeNews *src, s8 slot) +static bool8 TryMixPokeNewsShow(PokeNews *dest, PokeNews *src, s8 slot) { u8 i; if (src->kind == POKENEWS_NONE) - { return FALSE; - } - for (i = 0; i < POKE_NEWS_COUNT; i ++) + + for (i = 0; i < POKE_NEWS_COUNT; i++) { if (dest[i].kind == src->kind) - { return FALSE; - } } dest[slot].kind = src->kind; dest[slot].state = 1; @@ -4106,43 +3901,38 @@ static bool8 sub_80F0E84(PokeNews *dest, PokeNews *src, s8 slot) return TRUE; } -static s8 sub_80F0ECC(PokeNews *pokeNews, u8 idx) +static s8 GetPokeNewsSlotIfActive(PokeNews *pokeNews, u8 idx) { if (pokeNews[idx].kind == POKENEWS_NONE) - { return -1; - } + return idx; } -static void sub_80F0EEC(void) +static void ClearInvalidPokeNews(void) { u8 i; - for (i = 0; i < POKE_NEWS_COUNT; i ++) + for (i = 0; i < POKE_NEWS_COUNT; i++) { if (gSaveBlock1Ptr->pokeNews[i].kind > POKENEWS_BLENDMASTER) - { - ClearPokemonNewsI(i); - } + ClearPokeNewsBySlot(i); } - sub_80EEEB8(); + CompactPokeNews(); } -static void sub_80F0F24(void) +static void ClearPokeNewsIfGameNotComplete(void) { u8 i; if (FlagGet(FLAG_SYS_GAME_CLEAR) != TRUE) { - for (i = 0; i < POKE_NEWS_COUNT; i ++) - { + for (i = 0; i < POKE_NEWS_COUNT; i++) gSaveBlock1Ptr->pokeNews[i].state = 0; - } } } -#define tvlangfix(strptr, langptr, langfix) \ +#define SetStrLanguage(strptr, langptr, langfix) \ if (IsStringJapanese(strptr)) \ { \ (langptr) = LANGUAGE_JAPANESE; \ @@ -4152,348 +3942,341 @@ else \ (langptr) = langfix; \ } -static void sub_80F0F64(TVShow *show, u32 language) +// Unused +static void TranslateShowNames(TVShow *show, u32 language) { int i; - TVShow **r4; + TVShow **shows; - r4 = calloc(11, sizeof(TVShow *)); - for (i = 0; i < LAST_TVSHOW_IDX; i ++) + shows = calloc(11, sizeof(TVShow *)); + for (i = 0; i < LAST_TVSHOW_IDX; i++) { switch (show[i].common.kind) { - case TVSHOW_FAN_CLUB_LETTER: - case TVSHOW_RECENT_HAPPENINGS: - r4[0] = &show[i]; - tvlangfix(r4[0]->fanclubLetter.playerName, r4[0]->fanclubLetter.language, language); - break; - case TVSHOW_PKMN_FAN_CLUB_OPINIONS: - r4[1] = &show[i]; - tvlangfix(r4[1]->fanclubOpinions.playerName, r4[1]->fanclubOpinions.language, language); - tvlangfix(r4[1]->fanclubOpinions.nickname, r4[1]->fanclubOpinions.pokemonNameLanguage, language); - break; - case TVSHOW_POKEMON_TODAY_CAUGHT: - r4[6] = &show[i]; - tvlangfix(r4[6]->pokemonToday.playerName, r4[6]->pokemonToday.language, language); - tvlangfix(r4[6]->pokemonToday.nickname, r4[6]->pokemonToday.language2, language); - break; - case TVSHOW_SMART_SHOPPER: - r4[7] = &show[i]; - tvlangfix(r4[7]->smartshopperShow.playerName, r4[7]->smartshopperShow.language, language); - break; - case TVSHOW_BRAVO_TRAINER_BATTLE_TOWER_PROFILE: - r4[5] = &show[i]; - tvlangfix(r4[5]->bravoTrainerTower.trainerName, r4[5]->bravoTrainerTower.language, language); - tvlangfix(r4[5]->bravoTrainerTower.pokemonName, r4[5]->bravoTrainerTower.pokemonNameLanguage, language); - break; - case TVSHOW_BRAVO_TRAINER_POKEMON_PROFILE: - r4[4] = &show[i]; - tvlangfix(r4[4]->bravoTrainer.playerName, r4[4]->bravoTrainer.language, language); - tvlangfix(r4[4]->bravoTrainer.pokemonNickname, r4[4]->bravoTrainer.pokemonNameLanguage, language); - break; - case TVSHOW_NAME_RATER_SHOW: - r4[3] = &show[i]; - tvlangfix(r4[3]->nameRaterShow.trainerName, r4[3]->nameRaterShow.language, language); - tvlangfix(r4[3]->nameRaterShow.pokemonName, r4[3]->nameRaterShow.pokemonNameLanguage, language); - break; - case TVSHOW_POKEMON_TODAY_FAILED: - r4[2] = &show[i]; - tvlangfix(r4[2]->pokemonTodayFailed.playerName, r4[2]->pokemonTodayFailed.language, language); - break; - case TVSHOW_FISHING_ADVICE: - r4[8] = &show[i]; - tvlangfix(r4[8]->pokemonAngler.playerName, r4[8]->pokemonAngler.language, language); - break; - case TVSHOW_WORLD_OF_MASTERS: - r4[9] = &show[i]; - tvlangfix(r4[9]->worldOfMasters.playerName, r4[9]->worldOfMasters.language, language); - break; - case TVSHOW_MASS_OUTBREAK: - r4[10] = &show[i]; - r4[10]->massOutbreak.language = language; - break; + case TVSHOW_FAN_CLUB_LETTER: + case TVSHOW_RECENT_HAPPENINGS: // NOTE: These two shows are assumed to have the same struct layout + shows[0] = &show[i]; + SetStrLanguage(shows[0]->fanclubLetter.playerName, shows[0]->fanclubLetter.language, language); + break; + case TVSHOW_PKMN_FAN_CLUB_OPINIONS: + shows[1] = &show[i]; + SetStrLanguage(shows[1]->fanclubOpinions.playerName, shows[1]->fanclubOpinions.language, language); + SetStrLanguage(shows[1]->fanclubOpinions.nickname, shows[1]->fanclubOpinions.pokemonNameLanguage, language); + break; + case TVSHOW_POKEMON_TODAY_CAUGHT: + shows[6] = &show[i]; + SetStrLanguage(shows[6]->pokemonToday.playerName, shows[6]->pokemonToday.language, language); + SetStrLanguage(shows[6]->pokemonToday.nickname, shows[6]->pokemonToday.language2, language); + break; + case TVSHOW_SMART_SHOPPER: + shows[7] = &show[i]; + SetStrLanguage(shows[7]->smartshopperShow.playerName, shows[7]->smartshopperShow.language, language); + break; + case TVSHOW_BRAVO_TRAINER_BATTLE_TOWER_PROFILE: + shows[5] = &show[i]; + SetStrLanguage(shows[5]->bravoTrainerTower.trainerName, shows[5]->bravoTrainerTower.language, language); + SetStrLanguage(shows[5]->bravoTrainerTower.pokemonName, shows[5]->bravoTrainerTower.pokemonNameLanguage, language); + break; + case TVSHOW_BRAVO_TRAINER_POKEMON_PROFILE: + shows[4] = &show[i]; + SetStrLanguage(shows[4]->bravoTrainer.playerName, shows[4]->bravoTrainer.language, language); + SetStrLanguage(shows[4]->bravoTrainer.pokemonNickname, shows[4]->bravoTrainer.pokemonNameLanguage, language); + break; + case TVSHOW_NAME_RATER_SHOW: + shows[3] = &show[i]; + SetStrLanguage(shows[3]->nameRaterShow.trainerName, shows[3]->nameRaterShow.language, language); + SetStrLanguage(shows[3]->nameRaterShow.pokemonName, shows[3]->nameRaterShow.pokemonNameLanguage, language); + break; + case TVSHOW_POKEMON_TODAY_FAILED: + shows[2] = &show[i]; + SetStrLanguage(shows[2]->pokemonTodayFailed.playerName, shows[2]->pokemonTodayFailed.language, language); + break; + case TVSHOW_FISHING_ADVICE: + shows[8] = &show[i]; + SetStrLanguage(shows[8]->pokemonAngler.playerName, shows[8]->pokemonAngler.language, language); + break; + case TVSHOW_WORLD_OF_MASTERS: + shows[9] = &show[i]; + SetStrLanguage(shows[9]->worldOfMasters.playerName, shows[9]->worldOfMasters.language, language); + break; + case TVSHOW_MASS_OUTBREAK: + shows[10] = &show[i]; + shows[10]->massOutbreak.language = language; + break; } } - free(r4); + free(shows); } -void sub_80F1208(TVShow *shows) +void SanitizeTVShowsForRuby(TVShow *shows) { TVShow *curShow; - sub_80F14F8(shows); - for (curShow = shows; curShow < shows + LAST_TVSHOW_IDX; curShow ++) + SanitizeTVShowLocationsForRuby(shows); + for (curShow = shows; curShow < shows + LAST_TVSHOW_IDX; curShow++) { if (curShow->bravoTrainerTower.kind == TVSHOW_BRAVO_TRAINER_BATTLE_TOWER_PROFILE) { - if ((curShow->bravoTrainerTower.language == LANGUAGE_JAPANESE && curShow->bravoTrainerTower.pokemonNameLanguage != LANGUAGE_JAPANESE) || (curShow->bravoTrainerTower.language != LANGUAGE_JAPANESE && curShow->bravoTrainerTower.pokemonNameLanguage == LANGUAGE_JAPANESE)) - { + if ((curShow->bravoTrainerTower.language == LANGUAGE_JAPANESE && curShow->bravoTrainerTower.pokemonNameLanguage != LANGUAGE_JAPANESE) + || (curShow->bravoTrainerTower.language != LANGUAGE_JAPANESE && curShow->bravoTrainerTower.pokemonNameLanguage == LANGUAGE_JAPANESE)) memset(curShow, 0, sizeof(TVShow)); - } } } } -static void sub_80F1254(TVShow *shows) +static void TranslateRubyShows(TVShow *shows) { TVShow *curShow; - for (curShow = shows; curShow < shows + LAST_TVSHOW_IDX; curShow ++) + for (curShow = shows; curShow < shows + LAST_TVSHOW_IDX; curShow++) { if (curShow->bravoTrainerTower.kind == TVSHOW_BRAVO_TRAINER_BATTLE_TOWER_PROFILE) { if (IsStringJapanese(curShow->bravoTrainerTower.pokemonName)) - { curShow->bravoTrainerTower.pokemonNameLanguage = LANGUAGE_JAPANESE; - } else - { curShow->bravoTrainerTower.pokemonNameLanguage = GAME_LANGUAGE; - } } } } -u8 TV_GetStringLanguage(u8 *str) +static u8 GetStringLanguage(u8 *str) { return IsStringJapanese(str) ? LANGUAGE_JAPANESE : GAME_LANGUAGE; } -static void sub_80F12A4(TVShow *shows) +static void TranslateJapaneseEmeraldShows(TVShow *shows) { TVShow *curShow; - for (curShow = shows; curShow < shows + LAST_TVSHOW_IDX; curShow ++) + for (curShow = shows; curShow < shows + LAST_TVSHOW_IDX; curShow++) { switch(curShow->common.kind) { - case TVSHOW_FAN_CLUB_LETTER: - curShow->fanclubLetter.language = TV_GetStringLanguage(curShow->fanclubLetter.playerName); - break; - case TVSHOW_RECENT_HAPPENINGS: - curShow->recentHappenings.language = TV_GetStringLanguage(curShow->recentHappenings.playerName); - break; - case TVSHOW_PKMN_FAN_CLUB_OPINIONS: - curShow->fanclubOpinions.language = TV_GetStringLanguage(curShow->fanclubOpinions.playerName); - curShow->fanclubOpinions.pokemonNameLanguage = TV_GetStringLanguage(curShow->fanclubOpinions.nickname); - break; - case TVSHOW_UNKN_SHOWTYPE_04: - curShow->unkShow04.language = TV_GetStringLanguage(curShow->unkShow04.string_0b); - break; - case TVSHOW_NAME_RATER_SHOW: - curShow->nameRaterShow.language = TV_GetStringLanguage(curShow->nameRaterShow.trainerName); - curShow->nameRaterShow.pokemonNameLanguage = TV_GetStringLanguage(curShow->nameRaterShow.pokemonName); - break; - case TVSHOW_BRAVO_TRAINER_POKEMON_PROFILE: - curShow->bravoTrainer.language = TV_GetStringLanguage(curShow->bravoTrainer.playerName); - curShow->bravoTrainer.pokemonNameLanguage = TV_GetStringLanguage(curShow->bravoTrainer.pokemonNickname); - break; - case TVSHOW_BRAVO_TRAINER_BATTLE_TOWER_PROFILE: - curShow->bravoTrainerTower.language = TV_GetStringLanguage(curShow->bravoTrainerTower.trainerName); - curShow->bravoTrainerTower.pokemonNameLanguage = TV_GetStringLanguage(curShow->bravoTrainerTower.pokemonName); - break; - case TVSHOW_CONTEST_LIVE_UPDATES: - curShow->contestLiveUpdates.winningTrainerLanguage = TV_GetStringLanguage(curShow->contestLiveUpdates.winningTrainerName); - curShow->contestLiveUpdates.losingTrainerLanguage = TV_GetStringLanguage(curShow->contestLiveUpdates.losingTrainerName); - break; - case TVSHOW_3_CHEERS_FOR_POKEBLOCKS: - curShow->threeCheers.language = TV_GetStringLanguage(curShow->threeCheers.playerName); - curShow->threeCheers.worstBlenderLanguage = TV_GetStringLanguage(curShow->threeCheers.worstBlenderName); - break; - case TVSHOW_BATTLE_UPDATE: - curShow->battleUpdate.language = TV_GetStringLanguage(curShow->battleUpdate.playerName); - curShow->battleUpdate.linkOpponentLanguage = TV_GetStringLanguage(curShow->battleUpdate.linkOpponentName); - break; - case TVSHOW_FAN_CLUB_SPECIAL: - curShow->fanClubSpecial.language = TV_GetStringLanguage(curShow->fanClubSpecial.playerName); - curShow->fanClubSpecial.idolNameLanguage = TV_GetStringLanguage(curShow->fanClubSpecial.idolName); - break; - case TVSHOW_LILYCOVE_CONTEST_LADY: - curShow->contestLady.language = TV_GetStringLanguage(curShow->contestLady.playerName); - curShow->contestLady.pokemonNameLanguage = TV_GetStringLanguage(curShow->contestLady.nickname); - break; - case TVSHOW_POKEMON_TODAY_CAUGHT: - curShow->pokemonToday.language = TV_GetStringLanguage(curShow->pokemonToday.playerName); - curShow->pokemonToday.language2 = TV_GetStringLanguage(curShow->pokemonToday.nickname); - break; - case TVSHOW_SMART_SHOPPER: - curShow->smartshopperShow.language = TV_GetStringLanguage(curShow->smartshopperShow.playerName); - break; - case TVSHOW_POKEMON_TODAY_FAILED: - curShow->pokemonTodayFailed.language = TV_GetStringLanguage(curShow->pokemonTodayFailed.playerName); - break; - case TVSHOW_FISHING_ADVICE: - curShow->pokemonAngler.language = TV_GetStringLanguage(curShow->pokemonAngler.playerName); - break; - case TVSHOW_WORLD_OF_MASTERS: - curShow->worldOfMasters.language = TV_GetStringLanguage(curShow->worldOfMasters.playerName); - break; - case TVSHOW_TREND_WATCHER: - curShow->trendWatcher.language = TV_GetStringLanguage(curShow->trendWatcher.playerName); - break; - case TVSHOW_BREAKING_NEWS: - curShow->breakingNews.language = TV_GetStringLanguage(curShow->breakingNews.playerName); - break; - case TVSHOW_BATTLE_SEMINAR: - curShow->battleSeminar.language = TV_GetStringLanguage(curShow->battleSeminar.playerName); - break; - case TVSHOW_FIND_THAT_GAMER: - case TVSHOW_TRAINER_FAN_CLUB: - curShow->trainerFanClub.language = TV_GetStringLanguage(curShow->trainerFanClub.playerName); - break; - case TVSHOW_CUTIES: - curShow->cuties.language = TV_GetStringLanguage(curShow->cuties.playerName); - curShow->cuties.pokemonNameLanguage = TV_GetStringLanguage(curShow->cuties.nickname); - break; - case TVSHOW_TODAYS_RIVAL_TRAINER: - case TVSHOW_SECRET_BASE_VISIT: - case TVSHOW_FRONTIER: - curShow->rivalTrainer.language = TV_GetStringLanguage(curShow->rivalTrainer.playerName); - break; - case TVSHOW_TREASURE_INVESTIGATORS: - case TVSHOW_LOTTO_WINNER: - case TVSHOW_NUMBER_ONE: - curShow->treasureInvestigators.language = TV_GetStringLanguage(curShow->treasureInvestigators.playerName); - break; - case TVSHOW_SECRET_BASE_SECRETS: - curShow->secretBaseSecrets.language = TV_GetStringLanguage(curShow->secretBaseSecrets.playerName); - curShow->secretBaseSecrets.baseOwnersNameLanguage = TV_GetStringLanguage(curShow->secretBaseSecrets.baseOwnersName); - break; - case TVSHOW_SAFARI_FAN_CLUB: - curShow->safariFanClub.language = TV_GetStringLanguage(curShow->safariFanClub.playerName); - break; - case TVSHOW_MASS_OUTBREAK: - break; + case TVSHOW_FAN_CLUB_LETTER: + curShow->fanclubLetter.language = GetStringLanguage(curShow->fanclubLetter.playerName); + break; + case TVSHOW_RECENT_HAPPENINGS: + curShow->recentHappenings.language = GetStringLanguage(curShow->recentHappenings.playerName); + break; + case TVSHOW_PKMN_FAN_CLUB_OPINIONS: + curShow->fanclubOpinions.language = GetStringLanguage(curShow->fanclubOpinions.playerName); + curShow->fanclubOpinions.pokemonNameLanguage = GetStringLanguage(curShow->fanclubOpinions.nickname); + break; + case TVSHOW_DUMMY: + curShow->dummy.language = GetStringLanguage(curShow->dummy.name); + break; + case TVSHOW_NAME_RATER_SHOW: + curShow->nameRaterShow.language = GetStringLanguage(curShow->nameRaterShow.trainerName); + curShow->nameRaterShow.pokemonNameLanguage = GetStringLanguage(curShow->nameRaterShow.pokemonName); + break; + case TVSHOW_BRAVO_TRAINER_POKEMON_PROFILE: + curShow->bravoTrainer.language = GetStringLanguage(curShow->bravoTrainer.playerName); + curShow->bravoTrainer.pokemonNameLanguage = GetStringLanguage(curShow->bravoTrainer.pokemonNickname); + break; + case TVSHOW_BRAVO_TRAINER_BATTLE_TOWER_PROFILE: + curShow->bravoTrainerTower.language = GetStringLanguage(curShow->bravoTrainerTower.trainerName); + curShow->bravoTrainerTower.pokemonNameLanguage = GetStringLanguage(curShow->bravoTrainerTower.pokemonName); + break; + case TVSHOW_CONTEST_LIVE_UPDATES: + curShow->contestLiveUpdates.winningTrainerLanguage = GetStringLanguage(curShow->contestLiveUpdates.winningTrainerName); + curShow->contestLiveUpdates.losingTrainerLanguage = GetStringLanguage(curShow->contestLiveUpdates.losingTrainerName); + break; + case TVSHOW_3_CHEERS_FOR_POKEBLOCKS: + curShow->threeCheers.language = GetStringLanguage(curShow->threeCheers.playerName); + curShow->threeCheers.worstBlenderLanguage = GetStringLanguage(curShow->threeCheers.worstBlenderName); + break; + case TVSHOW_BATTLE_UPDATE: + curShow->battleUpdate.language = GetStringLanguage(curShow->battleUpdate.playerName); + curShow->battleUpdate.linkOpponentLanguage = GetStringLanguage(curShow->battleUpdate.linkOpponentName); + break; + case TVSHOW_FAN_CLUB_SPECIAL: + curShow->fanClubSpecial.language = GetStringLanguage(curShow->fanClubSpecial.playerName); + curShow->fanClubSpecial.idolNameLanguage = GetStringLanguage(curShow->fanClubSpecial.idolName); + break; + case TVSHOW_LILYCOVE_CONTEST_LADY: + curShow->contestLady.language = GetStringLanguage(curShow->contestLady.playerName); + curShow->contestLady.pokemonNameLanguage = GetStringLanguage(curShow->contestLady.nickname); + break; + case TVSHOW_POKEMON_TODAY_CAUGHT: + curShow->pokemonToday.language = GetStringLanguage(curShow->pokemonToday.playerName); + curShow->pokemonToday.language2 = GetStringLanguage(curShow->pokemonToday.nickname); + break; + case TVSHOW_SMART_SHOPPER: + curShow->smartshopperShow.language = GetStringLanguage(curShow->smartshopperShow.playerName); + break; + case TVSHOW_POKEMON_TODAY_FAILED: + curShow->pokemonTodayFailed.language = GetStringLanguage(curShow->pokemonTodayFailed.playerName); + break; + case TVSHOW_FISHING_ADVICE: + curShow->pokemonAngler.language = GetStringLanguage(curShow->pokemonAngler.playerName); + break; + case TVSHOW_WORLD_OF_MASTERS: + curShow->worldOfMasters.language = GetStringLanguage(curShow->worldOfMasters.playerName); + break; + case TVSHOW_TREND_WATCHER: + curShow->trendWatcher.language = GetStringLanguage(curShow->trendWatcher.playerName); + break; + case TVSHOW_BREAKING_NEWS: + curShow->breakingNews.language = GetStringLanguage(curShow->breakingNews.playerName); + break; + case TVSHOW_BATTLE_SEMINAR: + curShow->battleSeminar.language = GetStringLanguage(curShow->battleSeminar.playerName); + break; + case TVSHOW_FIND_THAT_GAMER: + case TVSHOW_TRAINER_FAN_CLUB: + curShow->trainerFanClub.language = GetStringLanguage(curShow->trainerFanClub.playerName); + break; + case TVSHOW_CUTIES: + curShow->cuties.language = GetStringLanguage(curShow->cuties.playerName); + curShow->cuties.pokemonNameLanguage = GetStringLanguage(curShow->cuties.nickname); + break; + case TVSHOW_TODAYS_RIVAL_TRAINER: + case TVSHOW_SECRET_BASE_VISIT: + case TVSHOW_FRONTIER: + curShow->rivalTrainer.language = GetStringLanguage(curShow->rivalTrainer.playerName); + break; + case TVSHOW_TREASURE_INVESTIGATORS: + case TVSHOW_LOTTO_WINNER: + case TVSHOW_NUMBER_ONE: + curShow->treasureInvestigators.language = GetStringLanguage(curShow->treasureInvestigators.playerName); + break; + case TVSHOW_SECRET_BASE_SECRETS: + curShow->secretBaseSecrets.language = GetStringLanguage(curShow->secretBaseSecrets.playerName); + curShow->secretBaseSecrets.baseOwnersNameLanguage = GetStringLanguage(curShow->secretBaseSecrets.baseOwnersName); + break; + case TVSHOW_SAFARI_FAN_CLUB: + curShow->safariFanClub.language = GetStringLanguage(curShow->safariFanClub.playerName); + break; + case TVSHOW_MASS_OUTBREAK: + break; } } } -void sub_80F14F8(TVShow *shows) +void SanitizeTVShowLocationsForRuby(TVShow *shows) { int i; - for (i = 0; i < LAST_TVSHOW_IDX; i ++) + for (i = 0; i < LAST_TVSHOW_IDX; i++) { switch (shows[i].common.kind) { - case TVSHOW_WORLD_OF_MASTERS: - if (shows[i].worldOfMasters.location > KANTO_MAPSEC_START) - { - memset(&shows[i], 0, sizeof(TVShow)); - } - break; - case TVSHOW_POKEMON_TODAY_FAILED: - if (shows[i].pokemonTodayFailed.location > KANTO_MAPSEC_START) - { - memset(&shows[i], 0, sizeof(TVShow)); - } - break; + case TVSHOW_WORLD_OF_MASTERS: + if (shows[i].worldOfMasters.location > KANTO_MAPSEC_START) + memset(&shows[i], 0, sizeof(TVShow)); + break; + case TVSHOW_POKEMON_TODAY_FAILED: + if (shows[i].pokemonTodayFailed.location > KANTO_MAPSEC_START) + memset(&shows[i], 0, sizeof(TVShow)); + break; } } } +// gSpecialVar_0x8004 here is set from GetRandomActiveShowIdx in EventScript_TryDoTVShow void DoTVShow(void) { if (gSaveBlock1Ptr->tvShows[gSpecialVar_0x8004].common.active) { switch (gSaveBlock1Ptr->tvShows[gSpecialVar_0x8004].common.kind) { - case TVSHOW_FAN_CLUB_LETTER: - DoTVShowPokemonFanClubLetter(); - break; - case TVSHOW_RECENT_HAPPENINGS: - DoTVShowRecentHappenings(); - break; - case TVSHOW_PKMN_FAN_CLUB_OPINIONS: - DoTVShowPokemonFanClubOpinions(); - break; - case TVSHOW_UNKN_SHOWTYPE_04: - DoTVShowDummiedOut(); - break; - case TVSHOW_MASS_OUTBREAK: - DoTVShowPokemonNewsMassOutbreak(); - break; - case TVSHOW_BRAVO_TRAINER_POKEMON_PROFILE: - DoTVShowBravoTrainerPokemonProfile(); - break; - case TVSHOW_BRAVO_TRAINER_BATTLE_TOWER_PROFILE: - DoTVShowBravoTrainerBattleTower(); - break; - case TVSHOW_POKEMON_TODAY_CAUGHT: - DoTVShowPokemonTodaySuccessfulCapture(); - break; - case TVSHOW_SMART_SHOPPER: - DoTVShowTodaysSmartShopper(); - break; - case TVSHOW_NAME_RATER_SHOW: - DoTVShowTheNameRaterShow(); - break; - case TVSHOW_CONTEST_LIVE_UPDATES: - DoTVShowPokemonContestLiveUpdates(); - break; - case TVSHOW_BATTLE_UPDATE: - DoTVShowPokemonBattleUpdate(); - break; - case TVSHOW_3_CHEERS_FOR_POKEBLOCKS: - DoTVShow3CheersForPokeblocks(); - break; - case TVSHOW_POKEMON_TODAY_FAILED: - DoTVShowPokemonTodayFailedCapture(); - break; - case TVSHOW_FISHING_ADVICE: - DoTVShowPokemonAngler(); - break; - case TVSHOW_WORLD_OF_MASTERS: - DoTVShowTheWorldOfMasters(); - break; - case TVSHOW_TODAYS_RIVAL_TRAINER: - DoTVShowTodaysRivalTrainer(); - break; - case TVSHOW_TREND_WATCHER: - DoTVShowDewfordTrendWatcherNetwork(); - break; - case TVSHOW_TREASURE_INVESTIGATORS: - DoTVShowHoennTreasureInvestigators(); - break; - case TVSHOW_FIND_THAT_GAMER: - DoTVShowFindThatGamer(); - break; - case TVSHOW_BREAKING_NEWS: - DoTVShowBreakingNewsTV(); - break; - case TVSHOW_SECRET_BASE_VISIT: - DoTVShowSecretBaseVisit(); - break; - case TVSHOW_LOTTO_WINNER: - DoTVShowPokemonLotteryWinnerFlashReport(); - break; - case TVSHOW_BATTLE_SEMINAR: - DoTVShowThePokemonBattleSeminar(); - break; - case TVSHOW_FAN_CLUB_SPECIAL: - DoTVShowTrainerFanClubSpecial(); - break; - case TVSHOW_TRAINER_FAN_CLUB: - DoTVShowTrainerFanClub(); - break; - case TVSHOW_CUTIES: - DoTVShowSpotTheCuties(); - break; - case TVSHOW_FRONTIER: - DoTVShowPokemonNewsBattleFrontier(); - break; - case TVSHOW_NUMBER_ONE: - DoTVShowWhatsNo1InHoennToday(); - break; - case TVSHOW_SECRET_BASE_SECRETS: - DoTVShowSecretBaseSecrets(); - break; - case TVSHOW_SAFARI_FAN_CLUB: - DoTVShowSafariFanClub(); - break; - case TVSHOW_LILYCOVE_CONTEST_LADY: - DoTVShowLilycoveContestLady(); - break; + case TVSHOW_FAN_CLUB_LETTER: + DoTVShowPokemonFanClubLetter(); + break; + case TVSHOW_RECENT_HAPPENINGS: + DoTVShowRecentHappenings(); + break; + case TVSHOW_PKMN_FAN_CLUB_OPINIONS: + DoTVShowPokemonFanClubOpinions(); + break; + case TVSHOW_DUMMY: + DoTVShowDummiedOut(); + break; + case TVSHOW_MASS_OUTBREAK: + DoTVShowPokemonNewsMassOutbreak(); + break; + case TVSHOW_BRAVO_TRAINER_POKEMON_PROFILE: + DoTVShowBravoTrainerPokemonProfile(); + break; + case TVSHOW_BRAVO_TRAINER_BATTLE_TOWER_PROFILE: + DoTVShowBravoTrainerBattleTower(); + break; + case TVSHOW_POKEMON_TODAY_CAUGHT: + DoTVShowPokemonTodaySuccessfulCapture(); + break; + case TVSHOW_SMART_SHOPPER: + DoTVShowTodaysSmartShopper(); + break; + case TVSHOW_NAME_RATER_SHOW: + DoTVShowTheNameRaterShow(); + break; + case TVSHOW_CONTEST_LIVE_UPDATES: + DoTVShowPokemonContestLiveUpdates(); + break; + case TVSHOW_BATTLE_UPDATE: + DoTVShowPokemonBattleUpdate(); + break; + case TVSHOW_3_CHEERS_FOR_POKEBLOCKS: + DoTVShow3CheersForPokeblocks(); + break; + case TVSHOW_POKEMON_TODAY_FAILED: + DoTVShowPokemonTodayFailedCapture(); + break; + case TVSHOW_FISHING_ADVICE: + DoTVShowPokemonAngler(); + break; + case TVSHOW_WORLD_OF_MASTERS: + DoTVShowTheWorldOfMasters(); + break; + case TVSHOW_TODAYS_RIVAL_TRAINER: + DoTVShowTodaysRivalTrainer(); + break; + case TVSHOW_TREND_WATCHER: + DoTVShowDewfordTrendWatcherNetwork(); + break; + case TVSHOW_TREASURE_INVESTIGATORS: + DoTVShowHoennTreasureInvestigators(); + break; + case TVSHOW_FIND_THAT_GAMER: + DoTVShowFindThatGamer(); + break; + case TVSHOW_BREAKING_NEWS: + DoTVShowBreakingNewsTV(); + break; + case TVSHOW_SECRET_BASE_VISIT: + DoTVShowSecretBaseVisit(); + break; + case TVSHOW_LOTTO_WINNER: + DoTVShowPokemonLotteryWinnerFlashReport(); + break; + case TVSHOW_BATTLE_SEMINAR: + DoTVShowThePokemonBattleSeminar(); + break; + case TVSHOW_FAN_CLUB_SPECIAL: + DoTVShowTrainerFanClubSpecial(); + break; + case TVSHOW_TRAINER_FAN_CLUB: + DoTVShowTrainerFanClub(); + break; + case TVSHOW_CUTIES: + DoTVShowSpotTheCuties(); + break; + case TVSHOW_FRONTIER: + DoTVShowPokemonNewsBattleFrontier(); + break; + case TVSHOW_NUMBER_ONE: + DoTVShowWhatsNo1InHoennToday(); + break; + case TVSHOW_SECRET_BASE_SECRETS: + DoTVShowSecretBaseSecrets(); + break; + case TVSHOW_SAFARI_FAN_CLUB: + DoTVShowSafariFanClub(); + break; + case TVSHOW_LILYCOVE_CONTEST_LADY: + DoTVShowLilycoveContestLady(); + break; } } } @@ -4508,64 +4291,64 @@ static void DoTVShowBravoTrainerPokemonProfile(void) state = sTVShowState; switch (state) { - case 0: - TVShowConvertInternationalString(gStringVar1, show->bravoTrainer.playerName, show->bravoTrainer.language); - CopyContestCategoryToStringVar(1, show->bravoTrainer.contestCategory); - CopyContestRankToStringVar(2, show->bravoTrainer.contestRank); - if (!StringCompare(gSpeciesNames[show->bravoTrainer.species], show->bravoTrainer.pokemonNickname)) - sTVShowState = 8; - else - sTVShowState = 1; - break; - case 1: - StringCopy(gStringVar1, gSpeciesNames[show->bravoTrainer.species]); - TVShowConvertInternationalString(gStringVar2, show->bravoTrainer.pokemonNickname, show->bravoTrainer.pokemonNameLanguage); - CopyContestCategoryToStringVar(2, show->bravoTrainer.contestCategory); - sTVShowState = 2; - break; - case 2: - TVShowConvertInternationalString(gStringVar1, show->bravoTrainer.playerName, show->bravoTrainer.language); - if (show->bravoTrainer.contestResult == 0) // placed first - sTVShowState = 3; - else - sTVShowState = 4; - break; - case 3: - TVShowConvertInternationalString(gStringVar1, show->bravoTrainer.playerName, show->bravoTrainer.language); - CopyEasyChatWord(gStringVar2, show->bravoTrainer.words[0]); - TV_PrintIntToStringVar(2, show->bravoTrainer.contestResult + 1); - sTVShowState = 5; - break; - case 4: - TVShowConvertInternationalString(gStringVar1, show->bravoTrainer.playerName, show->bravoTrainer.language); - CopyEasyChatWord(gStringVar2, show->bravoTrainer.words[0]); - TV_PrintIntToStringVar(2, show->bravoTrainer.contestResult + 1); - sTVShowState = 5; - break; - case 5: - TVShowConvertInternationalString(gStringVar1, show->bravoTrainer.playerName, show->bravoTrainer.language); - CopyContestCategoryToStringVar(1, show->bravoTrainer.contestCategory); - CopyEasyChatWord(gStringVar3, show->bravoTrainer.words[1]); - if (show->bravoTrainer.move) - sTVShowState = 6; - else - sTVShowState = 7; - break; - case 6: - StringCopy(gStringVar1, gSpeciesNames[show->bravoTrainer.species]); - StringCopy(gStringVar2, gMoveNames[show->bravoTrainer.move]); - CopyEasyChatWord(gStringVar3, show->bravoTrainer.words[1]); + case 0: + TVShowConvertInternationalString(gStringVar1, show->bravoTrainer.playerName, show->bravoTrainer.language); + CopyContestCategoryToStringVar(1, show->bravoTrainer.contestCategory); + CopyContestRankToStringVar(2, show->bravoTrainer.contestRank); + if (!StringCompare(gSpeciesNames[show->bravoTrainer.species], show->bravoTrainer.pokemonNickname)) + sTVShowState = 8; + else + sTVShowState = 1; + break; + case 1: + StringCopy(gStringVar1, gSpeciesNames[show->bravoTrainer.species]); + TVShowConvertInternationalString(gStringVar2, show->bravoTrainer.pokemonNickname, show->bravoTrainer.pokemonNameLanguage); + CopyContestCategoryToStringVar(2, show->bravoTrainer.contestCategory); + sTVShowState = 2; + break; + case 2: + TVShowConvertInternationalString(gStringVar1, show->bravoTrainer.playerName, show->bravoTrainer.language); + if (show->bravoTrainer.contestResult == 0) // placed first + sTVShowState = 3; + else + sTVShowState = 4; + break; + case 3: + TVShowConvertInternationalString(gStringVar1, show->bravoTrainer.playerName, show->bravoTrainer.language); + CopyEasyChatWord(gStringVar2, show->bravoTrainer.words[0]); + ConvertIntToDecimalString(2, show->bravoTrainer.contestResult + 1); + sTVShowState = 5; + break; + case 4: + TVShowConvertInternationalString(gStringVar1, show->bravoTrainer.playerName, show->bravoTrainer.language); + CopyEasyChatWord(gStringVar2, show->bravoTrainer.words[0]); + ConvertIntToDecimalString(2, show->bravoTrainer.contestResult + 1); + sTVShowState = 5; + break; + case 5: + TVShowConvertInternationalString(gStringVar1, show->bravoTrainer.playerName, show->bravoTrainer.language); + CopyContestCategoryToStringVar(1, show->bravoTrainer.contestCategory); + CopyEasyChatWord(gStringVar3, show->bravoTrainer.words[1]); + if (show->bravoTrainer.move) + sTVShowState = 6; + else sTVShowState = 7; - break; - case 7: - TVShowConvertInternationalString(gStringVar1, show->bravoTrainer.playerName, show->bravoTrainer.language); - StringCopy(gStringVar2, gSpeciesNames[show->bravoTrainer.species]); - TVShowDone(); - break; - case 8: - StringCopy(gStringVar1, gSpeciesNames[show->bravoTrainer.species]); - sTVShowState = 2; - break; + break; + case 6: + StringCopy(gStringVar1, gSpeciesNames[show->bravoTrainer.species]); + StringCopy(gStringVar2, gMoveNames[show->bravoTrainer.move]); + CopyEasyChatWord(gStringVar3, show->bravoTrainer.words[1]); + sTVShowState = 7; + break; + case 7: + TVShowConvertInternationalString(gStringVar1, show->bravoTrainer.playerName, show->bravoTrainer.language); + StringCopy(gStringVar2, gSpeciesNames[show->bravoTrainer.species]); + TVShowDone(); + break; + case 8: + StringCopy(gStringVar1, gSpeciesNames[show->bravoTrainer.species]); + sTVShowState = 2; + break; } ShowFieldMessage(sTVBravoTrainerTextGroup[state]); } @@ -4580,89 +4363,89 @@ static void DoTVShowBravoTrainerBattleTower(void) state = sTVShowState; switch(state) { - case 0: - TVShowConvertInternationalString(gStringVar1, show->bravoTrainerTower.trainerName, show->bravoTrainerTower.language); - StringCopy(gStringVar2, gSpeciesNames[show->bravoTrainerTower.species]); - if (show->bravoTrainerTower.numFights >= 7) - sTVShowState = 1; - else - sTVShowState = 2; - break; - case 1: - if (show->bravoTrainerTower.btLevel == 50) - { - StringCopy(gStringVar1, gText_Lv50); - } - else - { - StringCopy(gStringVar1, gText_OpenLevel); - } - TV_PrintIntToStringVar(1, show->bravoTrainerTower.numFights); - if (show->bravoTrainerTower.wonTheChallenge == TRUE) - sTVShowState = 3; - else - sTVShowState = 4; - break; - case 2: - TVShowConvertInternationalString(gStringVar1, show->bravoTrainerTower.pokemonName, show->bravoTrainerTower.pokemonNameLanguage); - TV_PrintIntToStringVar(1, show->bravoTrainerTower.numFights + 1); - if (show->bravoTrainerTower.interviewResponse == 0) - sTVShowState = 5; - else - sTVShowState = 6; - break; - case 3: - TVShowConvertInternationalString(gStringVar1, show->bravoTrainerTower.pokemonName, show->bravoTrainerTower.pokemonNameLanguage); - StringCopy(gStringVar2, gSpeciesNames[show->bravoTrainerTower.defeatedSpecies]); - if (show->bravoTrainerTower.interviewResponse == 0) - sTVShowState = 5; - else - sTVShowState = 6; - break; - case 4: - TVShowConvertInternationalString(gStringVar1, show->bravoTrainerTower.pokemonName, show->bravoTrainerTower.pokemonNameLanguage); - StringCopy(gStringVar2, gSpeciesNames[show->bravoTrainerTower.defeatedSpecies]); - if (show->bravoTrainerTower.interviewResponse == 0) - sTVShowState = 5; - else - sTVShowState = 6; - break; - case 5: - TVShowConvertInternationalString(gStringVar1, show->bravoTrainerTower.pokemonName, show->bravoTrainerTower.pokemonNameLanguage); - sTVShowState = 11; - break; - case 6: - TVShowConvertInternationalString(gStringVar1, show->bravoTrainerTower.pokemonName, show->bravoTrainerTower.pokemonNameLanguage); - sTVShowState = 11; - break; - case 7: - sTVShowState = 11; - break; - case 8: - case 9: - case 10: - TVShowConvertInternationalString(gStringVar1, show->bravoTrainerTower.trainerName, show->bravoTrainerTower.language); - sTVShowState = 11; - break; - case 11: - CopyEasyChatWord(gStringVar1, show->bravoTrainerTower.words[0]); - if (show->bravoTrainerTower.interviewResponse == 0) - sTVShowState = 12; - else - sTVShowState = 13; - break; - case 12: - case 13: - CopyEasyChatWord(gStringVar1, show->bravoTrainerTower.words[0]); - TVShowConvertInternationalString(gStringVar2, show->bravoTrainerTower.trainerName, show->bravoTrainerTower.language); - TVShowConvertInternationalString(gStringVar3, show->bravoTrainerTower.pokemonName, show->bravoTrainerTower.pokemonNameLanguage); - sTVShowState = 14; - break; - case 14: - TVShowConvertInternationalString(gStringVar1, show->bravoTrainerTower.trainerName, show->bravoTrainerTower.language); - StringCopy(gStringVar2, gSpeciesNames[show->bravoTrainerTower.species]); - TVShowDone(); - break; + case 0: + TVShowConvertInternationalString(gStringVar1, show->bravoTrainerTower.trainerName, show->bravoTrainerTower.language); + StringCopy(gStringVar2, gSpeciesNames[show->bravoTrainerTower.species]); + if (show->bravoTrainerTower.numFights >= 7) + sTVShowState = 1; + else + sTVShowState = 2; + break; + case 1: + if (show->bravoTrainerTower.btLevel == 50) + { + StringCopy(gStringVar1, gText_Lv50); + } + else + { + StringCopy(gStringVar1, gText_OpenLevel); + } + ConvertIntToDecimalString(1, show->bravoTrainerTower.numFights); + if (show->bravoTrainerTower.wonTheChallenge == TRUE) + sTVShowState = 3; + else + sTVShowState = 4; + break; + case 2: + TVShowConvertInternationalString(gStringVar1, show->bravoTrainerTower.pokemonName, show->bravoTrainerTower.pokemonNameLanguage); + ConvertIntToDecimalString(1, show->bravoTrainerTower.numFights + 1); + if (show->bravoTrainerTower.interviewResponse == 0) + sTVShowState = 5; + else + sTVShowState = 6; + break; + case 3: + TVShowConvertInternationalString(gStringVar1, show->bravoTrainerTower.pokemonName, show->bravoTrainerTower.pokemonNameLanguage); + StringCopy(gStringVar2, gSpeciesNames[show->bravoTrainerTower.defeatedSpecies]); + if (show->bravoTrainerTower.interviewResponse == 0) + sTVShowState = 5; + else + sTVShowState = 6; + break; + case 4: + TVShowConvertInternationalString(gStringVar1, show->bravoTrainerTower.pokemonName, show->bravoTrainerTower.pokemonNameLanguage); + StringCopy(gStringVar2, gSpeciesNames[show->bravoTrainerTower.defeatedSpecies]); + if (show->bravoTrainerTower.interviewResponse == 0) + sTVShowState = 5; + else + sTVShowState = 6; + break; + case 5: + TVShowConvertInternationalString(gStringVar1, show->bravoTrainerTower.pokemonName, show->bravoTrainerTower.pokemonNameLanguage); + sTVShowState = 11; + break; + case 6: + TVShowConvertInternationalString(gStringVar1, show->bravoTrainerTower.pokemonName, show->bravoTrainerTower.pokemonNameLanguage); + sTVShowState = 11; + break; + case 7: + sTVShowState = 11; + break; + case 8: + case 9: + case 10: + TVShowConvertInternationalString(gStringVar1, show->bravoTrainerTower.trainerName, show->bravoTrainerTower.language); + sTVShowState = 11; + break; + case 11: + CopyEasyChatWord(gStringVar1, show->bravoTrainerTower.words[0]); + if (show->bravoTrainerTower.interviewResponse == 0) + sTVShowState = 12; + else + sTVShowState = 13; + break; + case 12: + case 13: + CopyEasyChatWord(gStringVar1, show->bravoTrainerTower.words[0]); + TVShowConvertInternationalString(gStringVar2, show->bravoTrainerTower.trainerName, show->bravoTrainerTower.language); + TVShowConvertInternationalString(gStringVar3, show->bravoTrainerTower.pokemonName, show->bravoTrainerTower.pokemonNameLanguage); + sTVShowState = 14; + break; + case 14: + TVShowConvertInternationalString(gStringVar1, show->bravoTrainerTower.trainerName, show->bravoTrainerTower.language); + StringCopy(gStringVar2, gSpeciesNames[show->bravoTrainerTower.species]); + TVShowDone(); + break; } ShowFieldMessage(sTVBravoTrainerBattleTowerTextGroup[state]); } @@ -4677,115 +4460,81 @@ static void DoTVShowTodaysSmartShopper(void) state = sTVShowState; switch(state) { - case 0: - TVShowConvertInternationalString(gStringVar1, show->smartshopperShow.playerName, show->smartshopperShow.language); - GetMapName(gStringVar2, show->smartshopperShow.shopLocation, 0); - if (show->smartshopperShow.itemAmounts[0] >= 255) - { - sTVShowState = 11; - } - else - { - sTVShowState = 1; - } - break; - case 1: - TVShowConvertInternationalString(gStringVar1, show->smartshopperShow.playerName, show->smartshopperShow.language); - StringCopy(gStringVar2, ItemId_GetName(show->smartshopperShow.itemIds[0])); - TV_PrintIntToStringVar(2, show->smartshopperShow.itemAmounts[0]); - sTVShowState += 1 + (Random() % 4); - break; - case 2: - case 4: - case 5: - if (show->smartshopperShow.itemIds[1] != ITEM_NONE) - { - sTVShowState = 6; - } - else - { - sTVShowState = 10; - } - break; - case 3: - TV_PrintIntToStringVar(2, show->smartshopperShow.itemAmounts[0] + 1); - if (show->smartshopperShow.itemIds[1] != ITEM_NONE) - { - sTVShowState = 6; - } - else - { - sTVShowState = 10; - } - break; - case 6: - StringCopy(gStringVar2, ItemId_GetName(show->smartshopperShow.itemIds[1])); - TV_PrintIntToStringVar(2, show->smartshopperShow.itemAmounts[1]); - if (show->smartshopperShow.itemIds[2] != ITEM_NONE) - { - sTVShowState = 7; - } - else if (show->smartshopperShow.priceReduced == TRUE) - { - sTVShowState = 8; - } - else - { - sTVShowState = 9; - } - break; - case 7: - StringCopy(gStringVar2, ItemId_GetName(show->smartshopperShow.itemIds[2])); - TV_PrintIntToStringVar(2, show->smartshopperShow.itemAmounts[2]); - if (show->smartshopperShow.priceReduced == TRUE) - { - sTVShowState = 8; - } - else - { - sTVShowState = 9; - } - break; - case 8: - if (show->smartshopperShow.itemAmounts[0] >= 255) - { - sTVShowState = 12; - } - else - { - sTVShowState = 9; - } - break; - case 9: - sub_80EF40C(1, show); - TVShowDone(); - break; - case 10: - if (show->smartshopperShow.priceReduced == TRUE) - { - sTVShowState = 8; - } - else - { - sTVShowState = 9; - } - break; - case 11: - TVShowConvertInternationalString(gStringVar1, show->smartshopperShow.playerName, show->smartshopperShow.language); - StringCopy(gStringVar2, ItemId_GetName(show->smartshopperShow.itemIds[0])); - if (show->smartshopperShow.priceReduced == TRUE) - { - sTVShowState = 8; - } - else - { - sTVShowState = 12; - } - break; - case 12: - TVShowConvertInternationalString(gStringVar1, show->smartshopperShow.playerName, show->smartshopperShow.language); - TVShowDone(); - break; + case 0: + TVShowConvertInternationalString(gStringVar1, show->smartshopperShow.playerName, show->smartshopperShow.language); + GetMapName(gStringVar2, show->smartshopperShow.shopLocation, 0); + if (show->smartshopperShow.itemAmounts[0] >= 255) + sTVShowState = 11; + else + sTVShowState = 1; + break; + case 1: + TVShowConvertInternationalString(gStringVar1, show->smartshopperShow.playerName, show->smartshopperShow.language); + StringCopy(gStringVar2, ItemId_GetName(show->smartshopperShow.itemIds[0])); + ConvertIntToDecimalString(2, show->smartshopperShow.itemAmounts[0]); + sTVShowState += 1 + (Random() % 4); + break; + case 2: + case 4: + case 5: + if (show->smartshopperShow.itemIds[1] != ITEM_NONE) + sTVShowState = 6; + else + sTVShowState = 10; + break; + case 3: + ConvertIntToDecimalString(2, show->smartshopperShow.itemAmounts[0] + 1); + if (show->smartshopperShow.itemIds[1] != ITEM_NONE) + sTVShowState = 6; + else + sTVShowState = 10; + break; + case 6: + StringCopy(gStringVar2, ItemId_GetName(show->smartshopperShow.itemIds[1])); + ConvertIntToDecimalString(2, show->smartshopperShow.itemAmounts[1]); + if (show->smartshopperShow.itemIds[2] != ITEM_NONE) + sTVShowState = 7; + else if (show->smartshopperShow.priceReduced == TRUE) + sTVShowState = 8; + else + sTVShowState = 9; + break; + case 7: + StringCopy(gStringVar2, ItemId_GetName(show->smartshopperShow.itemIds[2])); + ConvertIntToDecimalString(2, show->smartshopperShow.itemAmounts[2]); + if (show->smartshopperShow.priceReduced == TRUE) + sTVShowState = 8; + else + sTVShowState = 9; + break; + case 8: + if (show->smartshopperShow.itemAmounts[0] >= 255) + sTVShowState = 12; + else + sTVShowState = 9; + break; + case 9: + sub_80EF40C(1, show); + TVShowDone(); + break; + case 10: + if (show->smartshopperShow.priceReduced == TRUE) + sTVShowState = 8; + else + sTVShowState = 9; + break; + case 11: + TVShowConvertInternationalString(gStringVar1, show->smartshopperShow.playerName, show->smartshopperShow.language); + StringCopy(gStringVar2, ItemId_GetName(show->smartshopperShow.itemIds[0])); + if (show->smartshopperShow.priceReduced == TRUE) + sTVShowState = 8; + else + sTVShowState = 12; + break; + case 12: + TVShowConvertInternationalString(gStringVar1, show->smartshopperShow.playerName, show->smartshopperShow.language); + TVShowDone(); + break; } ShowFieldMessage(sTVTodaysSmartShopperTextGroup[state]); } @@ -4800,90 +4549,78 @@ static void DoTVShowTheNameRaterShow(void) state = sTVShowState; switch (state) { - case 0: - TVShowConvertInternationalString(gStringVar1, show->nameRaterShow.trainerName, show->nameRaterShow.language); - StringCopy(gStringVar2, gSpeciesNames[show->nameRaterShow.species]); - TVShowConvertInternationalString(gStringVar3, show->nameRaterShow.pokemonName, show->nameRaterShow.pokemonNameLanguage); - sTVShowState = TV_GetNicknameSumMod8(show) + 1; - break; - case 1: - case 3: - case 4: - case 5: - case 6: - case 7: - case 8: - if (show->nameRaterShow.random == 0) - { - sTVShowState = 9; - } - else if (show->nameRaterShow.random == 1) - { - sTVShowState = 10; - } - else if (show->nameRaterShow.random == 2) - { - sTVShowState = 11; - } - break; - case 2: - TVShowConvertInternationalString(gStringVar1, show->nameRaterShow.trainerName, show->nameRaterShow.language); - if (show->nameRaterShow.random == 0) - { - sTVShowState = 9; - } - else if (show->nameRaterShow.random == 1) - { - sTVShowState = 10; - } - else if (show->nameRaterShow.random == 2) - { - sTVShowState = 11; - } - break; - case 9: - case 10: - case 11: - TVShowConvertInternationalString(gStringVar1, show->nameRaterShow.pokemonName, show->nameRaterShow.pokemonNameLanguage); - TV_GetNicknameSubstring(1, 0, 0, 1, 0, show); - TV_GetNicknameSubstring(2, 1, 0, 1, 0, show); - sTVShowState = 12; - break; - case 13: - TVShowConvertInternationalString(gStringVar1, show->nameRaterShow.trainerName, show->nameRaterShow.language); - TV_GetNicknameSubstring(1, 0, 2, 0, 0, show); - TV_GetNicknameSubstring(2, 0, 3, 1, 0, show); - sTVShowState = 14; - break; - case 14: - TV_GetNicknameSubstring(1, 0, 2, 1, 0, show); - TV_GetNicknameSubstring(2, 0, 3, 0, 0, show); - sTVShowState = 18; - break; - case 15: - TV_GetNicknameSubstring(0, 0, 2, 1, 0, show); - StringCopy(gStringVar2, gSpeciesNames[show->nameRaterShow.species]); - TV_GetNicknameSubstring(2, 0, 3, 2, show->nameRaterShow.species, show); - sTVShowState = 16; - break; - case 16: - TV_GetNicknameSubstring(0, 0, 2, 2, show->nameRaterShow.species, show); - TV_GetNicknameSubstring(2, 0, 3, 1, 0, show); - sTVShowState = 17; - break; - case 17: - TV_GetNicknameSubstring(0, 0, 2, 1, 0, show); - StringCopy(gStringVar2, gSpeciesNames[show->nameRaterShow.randomSpecies]); - TV_GetNicknameSubstring(2, 0, 3, 2, show->nameRaterShow.randomSpecies, show); - sTVShowState = 18; - break; - case 12: - state = 18; - sTVShowState = 18; - case 18: - TVShowConvertInternationalString(gStringVar1, show->nameRaterShow.pokemonName, show->nameRaterShow.pokemonNameLanguage); - TVShowDone(); - break; + case 0: + TVShowConvertInternationalString(gStringVar1, show->nameRaterShow.trainerName, show->nameRaterShow.language); + StringCopy(gStringVar2, gSpeciesNames[show->nameRaterShow.species]); + TVShowConvertInternationalString(gStringVar3, show->nameRaterShow.pokemonName, show->nameRaterShow.pokemonNameLanguage); + sTVShowState = GetRandomNameRaterStateFromName(show) + 1; + break; + case 1: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + if (show->nameRaterShow.random == 0) + sTVShowState = 9; + else if (show->nameRaterShow.random == 1) + sTVShowState = 10; + else if (show->nameRaterShow.random == 2) + sTVShowState = 11; + break; + case 2: + TVShowConvertInternationalString(gStringVar1, show->nameRaterShow.trainerName, show->nameRaterShow.language); + if (show->nameRaterShow.random == 0) + sTVShowState = 9; + else if (show->nameRaterShow.random == 1) + sTVShowState = 10; + else if (show->nameRaterShow.random == 2) + sTVShowState = 11; + break; + case 9: + case 10: + case 11: + TVShowConvertInternationalString(gStringVar1, show->nameRaterShow.pokemonName, show->nameRaterShow.pokemonNameLanguage); + GetNicknameSubstring(1, 0, 0, 1, 0, show); + GetNicknameSubstring(2, 1, 0, 1, 0, show); + sTVShowState = 12; + break; + case 13: + TVShowConvertInternationalString(gStringVar1, show->nameRaterShow.trainerName, show->nameRaterShow.language); + GetNicknameSubstring(1, 0, 2, 0, 0, show); + GetNicknameSubstring(2, 0, 3, 1, 0, show); + sTVShowState = 14; + break; + case 14: + GetNicknameSubstring(1, 0, 2, 1, 0, show); + GetNicknameSubstring(2, 0, 3, 0, 0, show); + sTVShowState = 18; + break; + case 15: + GetNicknameSubstring(0, 0, 2, 1, 0, show); + StringCopy(gStringVar2, gSpeciesNames[show->nameRaterShow.species]); + GetNicknameSubstring(2, 0, 3, 2, show->nameRaterShow.species, show); + sTVShowState = 16; + break; + case 16: + GetNicknameSubstring(0, 0, 2, 2, show->nameRaterShow.species, show); + GetNicknameSubstring(2, 0, 3, 1, 0, show); + sTVShowState = 17; + break; + case 17: + GetNicknameSubstring(0, 0, 2, 1, 0, show); + StringCopy(gStringVar2, gSpeciesNames[show->nameRaterShow.randomSpecies]); + GetNicknameSubstring(2, 0, 3, 2, show->nameRaterShow.randomSpecies, show); + sTVShowState = 18; + break; + case 12: + state = 18; + sTVShowState = 18; + case 18: + TVShowConvertInternationalString(gStringVar1, show->nameRaterShow.pokemonName, show->nameRaterShow.pokemonNameLanguage); + TVShowDone(); + break; } ShowFieldMessage(sTVNameRaterTextGroup[state]); } @@ -4898,70 +4635,62 @@ static void DoTVShowPokemonTodaySuccessfulCapture(void) state = sTVShowState; switch (state) { - case 0: - TVShowConvertInternationalString(gStringVar1, show->pokemonToday.playerName, show->pokemonToday.language); - StringCopy(gStringVar2, gSpeciesNames[show->pokemonToday.species]); - TVShowConvertInternationalString(gStringVar3, show->pokemonToday.nickname, show->pokemonToday.language2); - if (show->pokemonToday.ball == ITEM_MASTER_BALL) - { - sTVShowState = 5; - } - else - { - sTVShowState = 1; - } - break; - case 1: - sTVShowState = 2; - break; - case 2: - StringCopy(gStringVar2, ItemId_GetName(show->pokemonToday.ball)); - TV_PrintIntToStringVar(2, show->pokemonToday.nBallsUsed); - if (show->pokemonToday.nBallsUsed < 4) - { - sTVShowState = 3; - } - else - { - sTVShowState = 4; - } - break; - case 3: - TVShowConvertInternationalString(gStringVar1, show->pokemonToday.playerName, show->pokemonToday.language); - StringCopy(gStringVar2, gSpeciesNames[show->pokemonToday.species]); - TVShowConvertInternationalString(gStringVar3, show->pokemonToday.nickname, show->pokemonToday.language2); - sTVShowState = 6; - break; - case 4: - sTVShowState = 6; - break; - case 5: - TVShowConvertInternationalString(gStringVar1, show->pokemonToday.playerName, show->pokemonToday.language); - StringCopy(gStringVar2, gSpeciesNames[show->pokemonToday.species]); - sTVShowState = 6; - break; - case 6: - TVShowConvertInternationalString(gStringVar1, show->pokemonToday.playerName, show->pokemonToday.language); - StringCopy(gStringVar2, gSpeciesNames[show->pokemonToday.species]); - TVShowConvertInternationalString(gStringVar3, show->pokemonToday.nickname, show->pokemonToday.language2); - sTVShowState += 1 + (Random() % 4); - break; - case 7: - case 8: - StringCopy(gStringVar1, gSpeciesNames[show->pokemonToday.species]); - TVShowConvertInternationalString(gStringVar2, show->pokemonToday.nickname, show->pokemonToday.language2); - TV_GetSomeOtherSpeciesAlreadySeenByPlayer_AndPrintName(2, show->pokemonToday.species); - sTVShowState = 11; - break; - case 9: - case 10: - StringCopy(gStringVar1, gSpeciesNames[show->pokemonToday.species]); - TVShowConvertInternationalString(gStringVar2, show->pokemonToday.nickname, show->pokemonToday.language2); - sTVShowState = 11; - break; - case 11: - TVShowDone(); - break; + case 0: + TVShowConvertInternationalString(gStringVar1, show->pokemonToday.playerName, show->pokemonToday.language); + StringCopy(gStringVar2, gSpeciesNames[show->pokemonToday.species]); + TVShowConvertInternationalString(gStringVar3, show->pokemonToday.nickname, show->pokemonToday.language2); + if (show->pokemonToday.ball == ITEM_MASTER_BALL) + sTVShowState = 5; + else + sTVShowState = 1; + break; + case 1: + sTVShowState = 2; + break; + case 2: + StringCopy(gStringVar2, ItemId_GetName(show->pokemonToday.ball)); + ConvertIntToDecimalString(2, show->pokemonToday.nBallsUsed); + if (show->pokemonToday.nBallsUsed < 4) + sTVShowState = 3; + else + sTVShowState = 4; + break; + case 3: + TVShowConvertInternationalString(gStringVar1, show->pokemonToday.playerName, show->pokemonToday.language); + StringCopy(gStringVar2, gSpeciesNames[show->pokemonToday.species]); + TVShowConvertInternationalString(gStringVar3, show->pokemonToday.nickname, show->pokemonToday.language2); + sTVShowState = 6; + break; + case 4: + sTVShowState = 6; + break; + case 5: + TVShowConvertInternationalString(gStringVar1, show->pokemonToday.playerName, show->pokemonToday.language); + StringCopy(gStringVar2, gSpeciesNames[show->pokemonToday.species]); + sTVShowState = 6; + break; + case 6: + TVShowConvertInternationalString(gStringVar1, show->pokemonToday.playerName, show->pokemonToday.language); + StringCopy(gStringVar2, gSpeciesNames[show->pokemonToday.species]); + TVShowConvertInternationalString(gStringVar3, show->pokemonToday.nickname, show->pokemonToday.language2); + sTVShowState += 1 + (Random() % 4); + break; + case 7: + case 8: + StringCopy(gStringVar1, gSpeciesNames[show->pokemonToday.species]); + TVShowConvertInternationalString(gStringVar2, show->pokemonToday.nickname, show->pokemonToday.language2); + GetRandomDifferentSpeciesAndNameSeenByPlayer(2, show->pokemonToday.species); + sTVShowState = 11; + break; + case 9: + case 10: + StringCopy(gStringVar1, gSpeciesNames[show->pokemonToday.species]); + TVShowConvertInternationalString(gStringVar2, show->pokemonToday.nickname, show->pokemonToday.language2); + sTVShowState = 11; + break; + case 11: + TVShowDone(); + break; } ShowFieldMessage(sTVPokemonTodaySuccessfulTextGroup[state]); } @@ -4976,45 +4705,37 @@ static void DoTVShowPokemonTodayFailedCapture(void) state = sTVShowState; switch (state) { - case 0: - TVShowConvertInternationalString(gStringVar1, show->pokemonTodayFailed.playerName, show->pokemonTodayFailed.language); - StringCopy(gStringVar2, gSpeciesNames[show->pokemonTodayFailed.species]); - sTVShowState = 1; - break; - case 1: - TVShowConvertInternationalString(gStringVar1, show->pokemonTodayFailed.playerName, show->pokemonTodayFailed.language); - GetMapName(gStringVar2, show->pokemonTodayFailed.location, 0); - StringCopy(gStringVar3, gSpeciesNames[show->pokemonTodayFailed.species2]); - if (show->pokemonTodayFailed.outcome == 1) - { - sTVShowState = 3; - } - else - { - sTVShowState = 2; - } - break; - case 2: - case 3: - TVShowConvertInternationalString(gStringVar1, show->pokemonTodayFailed.playerName, show->pokemonTodayFailed.language); - TV_PrintIntToStringVar(1, show->pokemonTodayFailed.nBallsUsed); - if (Random() % 3 == 0) - { - sTVShowState = 5; - } - else - { - sTVShowState = 4; - } - break; - case 4: - case 5: - TVShowConvertInternationalString(gStringVar1, show->pokemonTodayFailed.playerName, show->pokemonTodayFailed.language); - sTVShowState = 6; - break; - case 6: - TVShowDone(); - break; + case 0: + TVShowConvertInternationalString(gStringVar1, show->pokemonTodayFailed.playerName, show->pokemonTodayFailed.language); + StringCopy(gStringVar2, gSpeciesNames[show->pokemonTodayFailed.species]); + sTVShowState = 1; + break; + case 1: + TVShowConvertInternationalString(gStringVar1, show->pokemonTodayFailed.playerName, show->pokemonTodayFailed.language); + GetMapName(gStringVar2, show->pokemonTodayFailed.location, 0); + StringCopy(gStringVar3, gSpeciesNames[show->pokemonTodayFailed.species2]); + if (show->pokemonTodayFailed.outcome == 1) + sTVShowState = 3; + else + sTVShowState = 2; + break; + case 2: + case 3: + TVShowConvertInternationalString(gStringVar1, show->pokemonTodayFailed.playerName, show->pokemonTodayFailed.language); + ConvertIntToDecimalString(1, show->pokemonTodayFailed.nBallsUsed); + if (Random() % 3 == 0) + sTVShowState = 5; + else + sTVShowState = 4; + break; + case 4: + case 5: + TVShowConvertInternationalString(gStringVar1, show->pokemonTodayFailed.playerName, show->pokemonTodayFailed.language); + sTVShowState = 6; + break; + case 6: + TVShowDone(); + break; } ShowFieldMessage(sTVPokemonTodayFailedTextGroup[state]); } @@ -5030,45 +4751,45 @@ static void DoTVShowPokemonFanClubLetter(void) state = sTVShowState; switch (state) { - case 0: - TVShowConvertInternationalString(gStringVar1, show->fanclubLetter.playerName, show->fanclubLetter.language); - StringCopy(gStringVar2, gSpeciesNames[show->fanclubLetter.species]); - sTVShowState = 50; - break; - case 1: - rval = (Random() % 4) + 1; - if (rval == 1) - sTVShowState = 2; - else - sTVShowState = rval + 2; - break; - case 2: - sTVShowState = 51; - break; - case 3: - sTVShowState += (Random() % 3) + 1; - break; - case 4: - case 5: - case 6: - TV_FanClubLetter_RandomWordToStringVar3(show); - sTVShowState = 7; - break; - case 7: - rval = (Random() % 0x1f) + 0x46; - TV_PrintIntToStringVar(2, rval); - TVShowDone(); - break; - case 50: - ConvertEasyChatWordsToString(gStringVar4, show->fanclubLetter.words, 2, 2); - ShowFieldMessage(gStringVar4); - sTVShowState = 1; - return; - case 51: - ConvertEasyChatWordsToString(gStringVar4, show->fanclubLetter.words, 2, 2); - ShowFieldMessage(gStringVar4); - sTVShowState = 3; - return; + case 0: + TVShowConvertInternationalString(gStringVar1, show->fanclubLetter.playerName, show->fanclubLetter.language); + StringCopy(gStringVar2, gSpeciesNames[show->fanclubLetter.species]); + sTVShowState = 50; + break; + case 1: + rval = (Random() % 4) + 1; + if (rval == 1) + sTVShowState = 2; + else + sTVShowState = rval + 2; + break; + case 2: + sTVShowState = 51; + break; + case 3: + sTVShowState += (Random() % 3) + 1; + break; + case 4: + case 5: + case 6: + GetRandomWordFromShow(show); + sTVShowState = 7; + break; + case 7: + rval = (Random() % 0x1f) + 0x46; + ConvertIntToDecimalString(2, rval); + TVShowDone(); + break; + case 50: + ConvertEasyChatWordsToString(gStringVar4, show->fanclubLetter.words, 2, 2); + ShowFieldMessage(gStringVar4); + sTVShowState = 1; + return; + case 51: + ConvertEasyChatWordsToString(gStringVar4, show->fanclubLetter.words, 2, 2); + ShowFieldMessage(gStringVar4); + sTVShowState = 3; + return; } ShowFieldMessage(sTVFanClubTextGroup[state]); } @@ -5083,27 +4804,27 @@ static void DoTVShowRecentHappenings(void) state = sTVShowState; switch (state) { - case 0: - TVShowConvertInternationalString(gStringVar1, show->recentHappenings.playerName, show->recentHappenings.language); - TV_FanClubLetter_RandomWordToStringVar3(show); - sTVShowState = 50; - break; - case 1: - sTVShowState += 1 + (Random() % 3); - break; - case 2: - case 3: - case 4: - sTVShowState = 5; - break; - case 5: - TVShowDone(); - break; - case 50: - ConvertEasyChatWordsToString(gStringVar4, show->recentHappenings.words, 2, 2); - ShowFieldMessage(gStringVar4); - sTVShowState = 1; - return; + case 0: + TVShowConvertInternationalString(gStringVar1, show->recentHappenings.playerName, show->recentHappenings.language); + GetRandomWordFromShow(show); + sTVShowState = 50; + break; + case 1: + sTVShowState += 1 + (Random() % 3); + break; + case 2: + case 3: + case 4: + sTVShowState = 5; + break; + case 5: + TVShowDone(); + break; + case 50: + ConvertEasyChatWordsToString(gStringVar4, show->recentHappenings.words, 2, 2); + ShowFieldMessage(gStringVar4); + sTVShowState = 1; + return; } ShowFieldMessage(sTVRecentHappeninssTextGroup[state]); } @@ -5118,25 +4839,25 @@ static void DoTVShowPokemonFanClubOpinions(void) state = sTVShowState; switch (state) { - case 0: - TVShowConvertInternationalString(gStringVar1, show->fanclubOpinions.playerName, show->fanclubOpinions.language); - StringCopy(gStringVar2, gSpeciesNames[show->fanclubOpinions.species]); - TVShowConvertInternationalString(gStringVar3, show->fanclubOpinions.nickname, show->fanclubOpinions.pokemonNameLanguage); - sTVShowState = show->fanclubOpinions.questionAsked + 1; - break; - case 1: - case 2: - case 3: - TVShowConvertInternationalString(gStringVar1, show->fanclubOpinions.playerName, show->fanclubOpinions.language); - StringCopy(gStringVar2, gSpeciesNames[show->fanclubOpinions.species]); - CopyEasyChatWord(gStringVar3, show->fanclubOpinions.words[0]); - sTVShowState = 4; - break; - case 4: - TVShowConvertInternationalString(gStringVar1, show->fanclubOpinions.playerName, show->fanclubOpinions.language); - CopyEasyChatWord(gStringVar3, show->fanclubOpinions.words[1]); - TVShowDone(); - break; + case 0: + TVShowConvertInternationalString(gStringVar1, show->fanclubOpinions.playerName, show->fanclubOpinions.language); + StringCopy(gStringVar2, gSpeciesNames[show->fanclubOpinions.species]); + TVShowConvertInternationalString(gStringVar3, show->fanclubOpinions.nickname, show->fanclubOpinions.pokemonNameLanguage); + sTVShowState = show->fanclubOpinions.questionAsked + 1; + break; + case 1: + case 2: + case 3: + TVShowConvertInternationalString(gStringVar1, show->fanclubOpinions.playerName, show->fanclubOpinions.language); + StringCopy(gStringVar2, gSpeciesNames[show->fanclubOpinions.species]); + CopyEasyChatWord(gStringVar3, show->fanclubOpinions.words[0]); + sTVShowState = 4; + break; + case 4: + TVShowConvertInternationalString(gStringVar1, show->fanclubOpinions.playerName, show->fanclubOpinions.language); + CopyEasyChatWord(gStringVar3, show->fanclubOpinions.words[1]); + TVShowDone(); + break; } ShowFieldMessage(sTVFanClubOpinionsTextGroup[state]); } @@ -5181,13 +4902,9 @@ static void DoTVShowPokemonContestLiveUpdates(void) if (show->contestLiveUpdates.round1Placing == show->contestLiveUpdates.round2Placing) { if (show->contestLiveUpdates.round1Placing == 0) - { sTVShowState = CONTESTLIVE_STATE_WON_BOTH_ROUNDS; - } else - { sTVShowState = CONTESTLIVE_STATE_EQUAL_ROUNDS; - } } else if (show->contestLiveUpdates.round1Placing > show->contestLiveUpdates.round2Placing) { @@ -5520,64 +5237,64 @@ static void DoTVShowPokemonBattleUpdate(void) state = sTVShowState; switch (state) { + case 0: + switch (show->battleUpdate.battleType) + { case 0: - switch (show->battleUpdate.battleType) - { - case 0: - case 1: - sTVShowState = 1; - break; - case 2: - sTVShowState = 5; - break; - } - break; case 1: - TVShowConvertInternationalString(gStringVar1, show->battleUpdate.playerName, show->battleUpdate.language); - TVShowConvertInternationalString(gStringVar2, show->battleUpdate.linkOpponentName, show->battleUpdate.linkOpponentLanguage); - if (show->battleUpdate.battleType == 0) - { - StringCopy(gStringVar3, gText_Single); - } - else - { - StringCopy(gStringVar3, gText_Double); - } - sTVShowState = 2; + sTVShowState = 1; break; case 2: - TVShowConvertInternationalString(gStringVar1, show->battleUpdate.playerName, show->battleUpdate.language); - StringCopy(gStringVar2, gSpeciesNames[show->battleUpdate.speciesPlayer]); - StringCopy(gStringVar3, gMoveNames[show->battleUpdate.move]); - sTVShowState = 3; - break; - case 3: - TVShowConvertInternationalString(gStringVar1, show->battleUpdate.linkOpponentName, show->battleUpdate.linkOpponentLanguage); - StringCopy(gStringVar2, gSpeciesNames[show->battleUpdate.speciesOpponent]); - sTVShowState = 4; - break; - case 4: - TVShowConvertInternationalString(gStringVar1, show->battleUpdate.playerName, show->battleUpdate.language); - TVShowConvertInternationalString(gStringVar2, show->battleUpdate.linkOpponentName, show->battleUpdate.linkOpponentLanguage); - TVShowDone(); - break; - case 5: - TVShowConvertInternationalString(gStringVar1, show->battleUpdate.playerName, show->battleUpdate.language); - TVShowConvertInternationalString(gStringVar2, show->battleUpdate.linkOpponentName, show->battleUpdate.linkOpponentLanguage); - sTVShowState = 6; - break; - case 6: - TVShowConvertInternationalString(gStringVar1, show->battleUpdate.playerName, show->battleUpdate.language); - StringCopy(gStringVar2, gSpeciesNames[show->battleUpdate.speciesPlayer]); - StringCopy(gStringVar3, gMoveNames[show->battleUpdate.move]); - sTVShowState = 7; - break; - case 7: - TVShowConvertInternationalString(gStringVar1, show->battleUpdate.playerName, show->battleUpdate.language); - TVShowConvertInternationalString(gStringVar2, show->battleUpdate.linkOpponentName, show->battleUpdate.linkOpponentLanguage); - StringCopy(gStringVar3, gSpeciesNames[show->battleUpdate.speciesOpponent]); - TVShowDone(); + sTVShowState = 5; break; + } + break; + case 1: + TVShowConvertInternationalString(gStringVar1, show->battleUpdate.playerName, show->battleUpdate.language); + TVShowConvertInternationalString(gStringVar2, show->battleUpdate.linkOpponentName, show->battleUpdate.linkOpponentLanguage); + if (show->battleUpdate.battleType == 0) + { + StringCopy(gStringVar3, gText_Single); + } + else + { + StringCopy(gStringVar3, gText_Double); + } + sTVShowState = 2; + break; + case 2: + TVShowConvertInternationalString(gStringVar1, show->battleUpdate.playerName, show->battleUpdate.language); + StringCopy(gStringVar2, gSpeciesNames[show->battleUpdate.speciesPlayer]); + StringCopy(gStringVar3, gMoveNames[show->battleUpdate.move]); + sTVShowState = 3; + break; + case 3: + TVShowConvertInternationalString(gStringVar1, show->battleUpdate.linkOpponentName, show->battleUpdate.linkOpponentLanguage); + StringCopy(gStringVar2, gSpeciesNames[show->battleUpdate.speciesOpponent]); + sTVShowState = 4; + break; + case 4: + TVShowConvertInternationalString(gStringVar1, show->battleUpdate.playerName, show->battleUpdate.language); + TVShowConvertInternationalString(gStringVar2, show->battleUpdate.linkOpponentName, show->battleUpdate.linkOpponentLanguage); + TVShowDone(); + break; + case 5: + TVShowConvertInternationalString(gStringVar1, show->battleUpdate.playerName, show->battleUpdate.language); + TVShowConvertInternationalString(gStringVar2, show->battleUpdate.linkOpponentName, show->battleUpdate.linkOpponentLanguage); + sTVShowState = 6; + break; + case 6: + TVShowConvertInternationalString(gStringVar1, show->battleUpdate.playerName, show->battleUpdate.language); + StringCopy(gStringVar2, gSpeciesNames[show->battleUpdate.speciesPlayer]); + StringCopy(gStringVar3, gMoveNames[show->battleUpdate.move]); + sTVShowState = 7; + break; + case 7: + TVShowConvertInternationalString(gStringVar1, show->battleUpdate.playerName, show->battleUpdate.language); + TVShowConvertInternationalString(gStringVar2, show->battleUpdate.linkOpponentName, show->battleUpdate.linkOpponentLanguage); + StringCopy(gStringVar3, gSpeciesNames[show->battleUpdate.speciesOpponent]); + TVShowDone(); + break; } ShowFieldMessage(sTVPokemonBattleUpdateTextGroup[state]); } @@ -5592,95 +5309,88 @@ static void DoTVShow3CheersForPokeblocks(void) state = sTVShowState; switch (state) { + case 0: + TVShowConvertInternationalString(gStringVar1, show->threeCheers.playerName, show->threeCheers.language); + if (show->threeCheers.sheen > 20) + sTVShowState = 1; + else + sTVShowState = 3; + break; + case 1: + switch (show->threeCheers.flavor) + { case 0: - TVShowConvertInternationalString(gStringVar1, show->threeCheers.playerName, show->threeCheers.language); - if (show->threeCheers.sheen > 20) - { - sTVShowState = 1; - } - else - { - sTVShowState = 3; - } + StringCopy(gStringVar1, gText_Spicy2); break; case 1: - switch (show->threeCheers.flavor) - { - case 0: - StringCopy(gStringVar1, gText_Spicy2); - break; - case 1: - StringCopy(gStringVar1, gText_Dry2); - break; - case 2: - StringCopy(gStringVar1, gText_Sweet2); - break; - case 3: - StringCopy(gStringVar1, gText_Bitter2); - break; - case 4: - StringCopy(gStringVar1, gText_Sour2); - break; - } - if (show->threeCheers.sheen > 24) - { - StringCopy(gStringVar2, gText_Excellent); - } else if (show->threeCheers.sheen > 22) - { - StringCopy(gStringVar2, gText_VeryGood); - } - else - { - StringCopy(gStringVar2, gText_Good); - } - TVShowConvertInternationalString(gStringVar3, show->threeCheers.playerName, show->threeCheers.language); - sTVShowState = 2; + StringCopy(gStringVar1, gText_Dry2); break; case 2: - TVShowConvertInternationalString(gStringVar1, show->threeCheers.worstBlenderName, show->threeCheers.worstBlenderLanguage); - sTVShowState = 5; + StringCopy(gStringVar1, gText_Sweet2); break; case 3: - switch (show->threeCheers.flavor) - { - case 0: - StringCopy(gStringVar1, gText_Spicy2); - break; - case 1: - StringCopy(gStringVar1, gText_Dry2); - break; - case 2: - StringCopy(gStringVar1, gText_Sweet2); - break; - case 3: - StringCopy(gStringVar1, gText_Bitter2); - break; - case 4: - StringCopy(gStringVar1, gText_Sour2); - break; - } - if (show->threeCheers.sheen > 16) - { - StringCopy(gStringVar2, gText_SoSo); - } else if (show->threeCheers.sheen > 13) - { - StringCopy(gStringVar2, gText_Bad); - } - else - { - StringCopy(gStringVar2, gText_TheWorst); - } - TVShowConvertInternationalString(gStringVar3, show->threeCheers.playerName, show->threeCheers.language); - sTVShowState = 4; + StringCopy(gStringVar1, gText_Bitter2); break; case 4: - TVShowConvertInternationalString(gStringVar1, show->threeCheers.worstBlenderName, show->threeCheers.worstBlenderLanguage); - TVShowConvertInternationalString(gStringVar2, show->threeCheers.playerName, show->threeCheers.language); - sTVShowState = 5; + StringCopy(gStringVar1, gText_Sour2); break; - case 5: - TVShowDone(); + } + if (show->threeCheers.sheen > 24) + { + StringCopy(gStringVar2, gText_Excellent); + } else if (show->threeCheers.sheen > 22) + { + StringCopy(gStringVar2, gText_VeryGood); + } + else + { + StringCopy(gStringVar2, gText_Good); + } + TVShowConvertInternationalString(gStringVar3, show->threeCheers.playerName, show->threeCheers.language); + sTVShowState = 2; + break; + case 2: + TVShowConvertInternationalString(gStringVar1, show->threeCheers.worstBlenderName, show->threeCheers.worstBlenderLanguage); + sTVShowState = 5; + break; + case 3: + switch (show->threeCheers.flavor) + { + case 0: + StringCopy(gStringVar1, gText_Spicy2); break; + case 1: + StringCopy(gStringVar1, gText_Dry2); + break; + case 2: + StringCopy(gStringVar1, gText_Sweet2); + break; + case 3: + StringCopy(gStringVar1, gText_Bitter2); + break; + case 4: + StringCopy(gStringVar1, gText_Sour2); + break; + } + + if (show->threeCheers.sheen > 16) + StringCopy(gStringVar2, gText_SoSo); + else if (show->threeCheers.sheen > 13) + StringCopy(gStringVar2, gText_Bad); + else + StringCopy(gStringVar2, gText_TheWorst); + + TVShowConvertInternationalString(gStringVar3, show->threeCheers.playerName, show->threeCheers.language); + sTVShowState = 4; + break; + case 4: + TVShowConvertInternationalString(gStringVar1, show->threeCheers.worstBlenderName, show->threeCheers.worstBlenderLanguage); + TVShowConvertInternationalString(gStringVar2, show->threeCheers.playerName, show->threeCheers.language); + sTVShowState = 5; + break; + case 5: + TVShowDone(); + break; } ShowFieldMessage(sTV3CheersForPokeblocksTextGroup[state]); } @@ -5693,62 +5403,48 @@ void DoTVShowInSearchOfTrainers(void) state = sTVShowState; switch (state) { - case 0: - GetMapName(gStringVar1, gSaveBlock1Ptr->gabbyAndTyData.mapnum, 0); - if (gSaveBlock1Ptr->gabbyAndTyData.battleNum > 1) - { - sTVShowState = 1; - } - else - { - sTVShowState = 2; - } - break; - case 1: + case 0: + GetMapName(gStringVar1, gSaveBlock1Ptr->gabbyAndTyData.mapnum, 0); + if (gSaveBlock1Ptr->gabbyAndTyData.battleNum > 1) + sTVShowState = 1; + else sTVShowState = 2; - break; - case 2: - if (!gSaveBlock1Ptr->gabbyAndTyData.battleTookMoreThanOneTurn) - { - sTVShowState = 4; - } - else if (gSaveBlock1Ptr->gabbyAndTyData.playerThrewABall) - { - sTVShowState = 5; - } - else if (gSaveBlock1Ptr->gabbyAndTyData.playerUsedHealingItem) - { - sTVShowState = 6; - } - else if (gSaveBlock1Ptr->gabbyAndTyData.playerLostAMon) - { - sTVShowState = 7; - } - else - { - sTVShowState = 3; - } - break; - case 3: - StringCopy(gStringVar1, gSpeciesNames[gSaveBlock1Ptr->gabbyAndTyData.mon1]); - StringCopy(gStringVar2, gMoveNames[gSaveBlock1Ptr->gabbyAndTyData.lastMove]); - StringCopy(gStringVar3, gSpeciesNames[gSaveBlock1Ptr->gabbyAndTyData.mon2]); - sTVShowState = 8; - break; - case 4: - case 5: - case 6: - case 7: - sTVShowState = 8; - break; - case 8: - CopyEasyChatWord(gStringVar1, gSaveBlock1Ptr->gabbyAndTyData.quote[0]); - StringCopy(gStringVar2, gSpeciesNames[gSaveBlock1Ptr->gabbyAndTyData.mon1]); - StringCopy(gStringVar3, gSpeciesNames[gSaveBlock1Ptr->gabbyAndTyData.mon2]); - gSpecialVar_Result = TRUE; - sTVShowState = 0; - TakeTVShowInSearchOfTrainersOffTheAir(); - break; + break; + case 1: + sTVShowState = 2; + break; + case 2: + if (!gSaveBlock1Ptr->gabbyAndTyData.battleTookMoreThanOneTurn) + sTVShowState = 4; + else if (gSaveBlock1Ptr->gabbyAndTyData.playerThrewABall) + sTVShowState = 5; + else if (gSaveBlock1Ptr->gabbyAndTyData.playerUsedHealingItem) + sTVShowState = 6; + else if (gSaveBlock1Ptr->gabbyAndTyData.playerLostAMon) + sTVShowState = 7; + else + sTVShowState = 3; + break; + case 3: + StringCopy(gStringVar1, gSpeciesNames[gSaveBlock1Ptr->gabbyAndTyData.mon1]); + StringCopy(gStringVar2, gMoveNames[gSaveBlock1Ptr->gabbyAndTyData.lastMove]); + StringCopy(gStringVar3, gSpeciesNames[gSaveBlock1Ptr->gabbyAndTyData.mon2]); + sTVShowState = 8; + break; + case 4: + case 5: + case 6: + case 7: + sTVShowState = 8; + break; + case 8: + CopyEasyChatWord(gStringVar1, gSaveBlock1Ptr->gabbyAndTyData.quote[0]); + StringCopy(gStringVar2, gSpeciesNames[gSaveBlock1Ptr->gabbyAndTyData.mon1]); + StringCopy(gStringVar3, gSpeciesNames[gSaveBlock1Ptr->gabbyAndTyData.mon2]); + gSpecialVar_Result = TRUE; + sTVShowState = 0; + TakeGabbyAndTyOffTheAir(); + break; } ShowFieldMessage(sTVInSearchOfTrainersTextGroup[state]); } @@ -5761,28 +5457,24 @@ static void DoTVShowPokemonAngler(void) show = &gSaveBlock1Ptr->tvShows[gSpecialVar_0x8004]; gSpecialVar_Result = FALSE; if (show->pokemonAngler.nBites < show->pokemonAngler.nFails) - { sTVShowState = 0; - } else - { sTVShowState = 1; - } state = sTVShowState; switch (state) { - case 0: - TVShowConvertInternationalString(gStringVar1, show->pokemonAngler.playerName, show->pokemonAngler.language); - StringCopy(gStringVar2, gSpeciesNames[show->pokemonAngler.species]); - TV_PrintIntToStringVar(2, show->pokemonAngler.nFails); - TVShowDone(); - break; - case 1: - TVShowConvertInternationalString(gStringVar1, show->pokemonAngler.playerName, show->pokemonAngler.language); - StringCopy(gStringVar2, gSpeciesNames[show->pokemonAngler.species]); - TV_PrintIntToStringVar(2, show->pokemonAngler.nBites); - TVShowDone(); - break; + case 0: + TVShowConvertInternationalString(gStringVar1, show->pokemonAngler.playerName, show->pokemonAngler.language); + StringCopy(gStringVar2, gSpeciesNames[show->pokemonAngler.species]); + ConvertIntToDecimalString(2, show->pokemonAngler.nFails); + TVShowDone(); + break; + case 1: + TVShowConvertInternationalString(gStringVar1, show->pokemonAngler.playerName, show->pokemonAngler.language); + StringCopy(gStringVar2, gSpeciesNames[show->pokemonAngler.species]); + ConvertIntToDecimalString(2, show->pokemonAngler.nBites); + TVShowDone(); + break; } ShowFieldMessage(sTVPokemonAnslerTextGroup[state]); } @@ -5797,22 +5489,22 @@ static void DoTVShowTheWorldOfMasters(void) state = sTVShowState; switch (state) { - case 0: - TVShowConvertInternationalString(gStringVar1, show->worldOfMasters.playerName, show->worldOfMasters.language); - TV_PrintIntToStringVar(1, show->worldOfMasters.steps); - TV_PrintIntToStringVar(2, show->worldOfMasters.numPokeCaught); - sTVShowState = 1; - break; - case 1: - StringCopy(gStringVar1, gSpeciesNames[show->worldOfMasters.species]); - sTVShowState = 2; - break; - case 2: - TVShowConvertInternationalString(gStringVar1, show->worldOfMasters.playerName, show->worldOfMasters.language); - GetMapName(gStringVar2, show->worldOfMasters.location, 0); - StringCopy(gStringVar3, gSpeciesNames[show->worldOfMasters.caughtPoke]); - TVShowDone(); - break; + case 0: + TVShowConvertInternationalString(gStringVar1, show->worldOfMasters.playerName, show->worldOfMasters.language); + ConvertIntToDecimalString(1, show->worldOfMasters.steps); + ConvertIntToDecimalString(2, show->worldOfMasters.numPokeCaught); + sTVShowState = 1; + break; + case 1: + StringCopy(gStringVar1, gSpeciesNames[show->worldOfMasters.species]); + sTVShowState = 2; + break; + case 2: + TVShowConvertInternationalString(gStringVar1, show->worldOfMasters.playerName, show->worldOfMasters.language); + GetMapName(gStringVar2, show->worldOfMasters.location, 0); + StringCopy(gStringVar3, gSpeciesNames[show->worldOfMasters.caughtPoke]); + TVShowDone(); + break; } ShowFieldMessage(sTVWorldOfMastersTextGroup[state]); } @@ -5827,143 +5519,111 @@ static void DoTVShowTodaysRivalTrainer(void) state = sTVShowState; switch (state) { - case 0: - switch (show->rivalTrainer.location) + case 0: + switch (show->rivalTrainer.location) + { + default: + sTVShowState = 7; + break; + case MAPSEC_SECRET_BASE: + sTVShowState = 8; + break; + case MAPSEC_DYNAMIC: + switch (show->rivalTrainer.mapLayoutId) { - default: - sTVShowState = 7; - break; - case MAPSEC_SECRET_BASE: - sTVShowState = 8; - break; - case MAPSEC_DYNAMIC: - switch (show->rivalTrainer.mapLayoutId) - { - case LAYOUT_SS_TIDAL_CORRIDOR: - case LAYOUT_SS_TIDAL_LOWER_DECK: - case LAYOUT_SS_TIDAL_ROOMS: - sTVShowState = 10; - break; - default: - sTVShowState = 9; - break; - } - break; + case LAYOUT_SS_TIDAL_CORRIDOR: + case LAYOUT_SS_TIDAL_LOWER_DECK: + case LAYOUT_SS_TIDAL_ROOMS: + sTVShowState = 10; + break; + default: + sTVShowState = 9; + break; } break; - case 7: - TVShowConvertInternationalString(gStringVar1, show->rivalTrainer.playerName, show->rivalTrainer.language); - TV_PrintIntToStringVar(1, show->rivalTrainer.dexCount); - GetMapName(gStringVar3, show->rivalTrainer.location, 0); - if (show->rivalTrainer.badgeCount != 0) - { - sTVShowState = 1; - } + } + break; + case 7: + TVShowConvertInternationalString(gStringVar1, show->rivalTrainer.playerName, show->rivalTrainer.language); + ConvertIntToDecimalString(1, show->rivalTrainer.dexCount); + GetMapName(gStringVar3, show->rivalTrainer.location, 0); + if (show->rivalTrainer.badgeCount != 0) + sTVShowState = 1; + else + sTVShowState = 2; + break; + case 8: + TVShowConvertInternationalString(gStringVar1, show->rivalTrainer.playerName, show->rivalTrainer.language); + ConvertIntToDecimalString(1, show->rivalTrainer.dexCount); + if (show->rivalTrainer.badgeCount != 0) + sTVShowState = 1; + else + sTVShowState = 2; + break; + case 9: + TVShowConvertInternationalString(gStringVar1, show->rivalTrainer.playerName, show->rivalTrainer.language); + ConvertIntToDecimalString(1, show->rivalTrainer.dexCount); + if (show->rivalTrainer.badgeCount != 0) + sTVShowState = 1; + else + sTVShowState = 2; + break; + case 10: + TVShowConvertInternationalString(gStringVar1, show->rivalTrainer.playerName, show->rivalTrainer.language); + ConvertIntToDecimalString(1, show->rivalTrainer.dexCount); + if (show->rivalTrainer.badgeCount != 0) + sTVShowState = 1; + else + sTVShowState = 2; + break; + case 1: + ConvertIntToDecimalString(0, show->rivalTrainer.badgeCount); + if (FlagGet(FLAG_LANDMARK_BATTLE_FRONTIER)) + { + if (show->rivalTrainer.nSilverSymbols || show->rivalTrainer.nGoldSymbols) + sTVShowState = 4; else - { - sTVShowState = 2; - } - break; - case 8: - TVShowConvertInternationalString(gStringVar1, show->rivalTrainer.playerName, show->rivalTrainer.language); - TV_PrintIntToStringVar(1, show->rivalTrainer.dexCount); - if (show->rivalTrainer.badgeCount != 0) - { - sTVShowState = 1; - } - else - { - sTVShowState = 2; - } - break; - case 9: - TVShowConvertInternationalString(gStringVar1, show->rivalTrainer.playerName, show->rivalTrainer.language); - TV_PrintIntToStringVar(1, show->rivalTrainer.dexCount); - if (show->rivalTrainer.badgeCount != 0) - { - sTVShowState = 1; - } - else - { - sTVShowState = 2; - } - break; - case 10: - TVShowConvertInternationalString(gStringVar1, show->rivalTrainer.playerName, show->rivalTrainer.language); - TV_PrintIntToStringVar(1, show->rivalTrainer.dexCount); - if (show->rivalTrainer.badgeCount != 0) - { - sTVShowState = 1; - } - else - { - sTVShowState = 2; - } - break; - case 1: - TV_PrintIntToStringVar(0, show->rivalTrainer.badgeCount); - if (FlagGet(FLAG_LANDMARK_BATTLE_FRONTIER)) - { - if (show->rivalTrainer.nSilverSymbols || show->rivalTrainer.nGoldSymbols) - { - sTVShowState = 4; - } - else - { - sTVShowState = 3; - } - } - else - { - sTVShowState = 6; - } - break; - case 2: - if (FlagGet(FLAG_LANDMARK_BATTLE_FRONTIER)) - { - if (show->rivalTrainer.nSilverSymbols || show->rivalTrainer.nGoldSymbols) - { - sTVShowState = 4; - } - else - { - sTVShowState = 3; - } - } - else - { - sTVShowState = 6; - } - break; - case 3: - if (show->rivalTrainer.battlePoints == 0) - { - sTVShowState = 6; - } - else - { - sTVShowState = 5; - } - break; - case 4: - TV_PrintIntToStringVar(0, show->rivalTrainer.nGoldSymbols); - TV_PrintIntToStringVar(1, show->rivalTrainer.nSilverSymbols); - if (show->rivalTrainer.battlePoints == 0) - { - sTVShowState = 6; - } - else - { - sTVShowState = 5; - } - break; - case 5: - TV_PrintIntToStringVar(0, show->rivalTrainer.battlePoints); + sTVShowState = 3; + } + else + { sTVShowState = 6; - break; - case 6: - TVShowConvertInternationalString(gStringVar1, show->rivalTrainer.playerName, show->rivalTrainer.language); - TVShowDone(); + } + break; + case 2: + if (FlagGet(FLAG_LANDMARK_BATTLE_FRONTIER)) + { + if (show->rivalTrainer.nSilverSymbols || show->rivalTrainer.nGoldSymbols) + sTVShowState = 4; + else + sTVShowState = 3; + } + else + { + sTVShowState = 6; + } + break; + case 3: + if (show->rivalTrainer.battlePoints == 0) + sTVShowState = 6; + else + sTVShowState = 5; + break; + case 4: + ConvertIntToDecimalString(0, show->rivalTrainer.nGoldSymbols); + ConvertIntToDecimalString(1, show->rivalTrainer.nSilverSymbols); + if (show->rivalTrainer.battlePoints == 0) + sTVShowState = 6; + else + sTVShowState = 5; + break; + case 5: + ConvertIntToDecimalString(0, show->rivalTrainer.battlePoints); + sTVShowState = 6; + break; + case 6: + TVShowConvertInternationalString(gStringVar1, show->rivalTrainer.playerName, show->rivalTrainer.language); + TVShowDone(); } ShowFieldMessage(sTVTodaysRivalTrainerTextGroup[state]); } @@ -6026,38 +5686,38 @@ static void DoTVShowHoennTreasureInvestigators(void) state = sTVShowState; switch (state) { - case 0: - StringCopy(gStringVar1, ItemId_GetName(show->treasureInvestigators.item)); - if (show->treasureInvestigators.location == MAPSEC_DYNAMIC) - { - switch (show->treasureInvestigators.mapLayoutId) - { - case LAYOUT_SS_TIDAL_CORRIDOR: - case LAYOUT_SS_TIDAL_LOWER_DECK: - case LAYOUT_SS_TIDAL_ROOMS: - sTVShowState = 2; - break; - default: - sTVShowState = 1; - break; - } - } - else + case 0: + StringCopy(gStringVar1, ItemId_GetName(show->treasureInvestigators.item)); + if (show->treasureInvestigators.location == MAPSEC_DYNAMIC) + { + switch (show->treasureInvestigators.mapLayoutId) { + case LAYOUT_SS_TIDAL_CORRIDOR: + case LAYOUT_SS_TIDAL_LOWER_DECK: + case LAYOUT_SS_TIDAL_ROOMS: + sTVShowState = 2; + break; + default: sTVShowState = 1; + break; } - break; - case 1: - StringCopy(gStringVar1, ItemId_GetName(show->treasureInvestigators.item)); - TVShowConvertInternationalString(gStringVar2, show->treasureInvestigators.playerName, show->treasureInvestigators.language); - GetMapName(gStringVar3, show->treasureInvestigators.location, 0); - TVShowDone(); - break; - case 2: - StringCopy(gStringVar1, ItemId_GetName(show->treasureInvestigators.item)); - TVShowConvertInternationalString(gStringVar2, show->treasureInvestigators.playerName, show->treasureInvestigators.language); - TVShowDone(); - break; + } + else + { + sTVShowState = 1; + } + break; + case 1: + StringCopy(gStringVar1, ItemId_GetName(show->treasureInvestigators.item)); + TVShowConvertInternationalString(gStringVar2, show->treasureInvestigators.playerName, show->treasureInvestigators.language); + GetMapName(gStringVar3, show->treasureInvestigators.location, 0); + TVShowDone(); + break; + case 2: + StringCopy(gStringVar1, ItemId_GetName(show->treasureInvestigators.item)); + TVShowConvertInternationalString(gStringVar2, show->treasureInvestigators.playerName, show->treasureInvestigators.language); + TVShowDone(); + break; } ShowFieldMessage(sTVHoennTreasureInvestisatorsTextGroup[state]); } @@ -6072,66 +5732,62 @@ static void DoTVShowFindThatGamer(void) state = sTVShowState; switch (state) { + case 0: + TVShowConvertInternationalString(gStringVar1, show->findThatGamer.playerName, show->findThatGamer.language); + switch (show->findThatGamer.whichGame) + { case 0: - TVShowConvertInternationalString(gStringVar1, show->findThatGamer.playerName, show->findThatGamer.language); - switch (show->findThatGamer.whichGame) - { - case 0: - StringCopy(gStringVar2, gText_Slots); - break; - case 1: - StringCopy(gStringVar2, gText_Roulette); - break; - } - if (show->findThatGamer.won == TRUE) - { - sTVShowState = 1; - } - else - { - sTVShowState = 2; - } + StringCopy(gStringVar2, gText_Slots); break; case 1: - TVShowConvertInternationalString(gStringVar1, show->findThatGamer.playerName, show->findThatGamer.language); - switch (show->findThatGamer.whichGame) - { - case 0: - StringCopy(gStringVar2, gText_Slots); - break; - case 1: - StringCopy(gStringVar2, gText_Roulette); - break; - } - TV_PrintIntToStringVar(2, show->findThatGamer.nCoins); - TVShowDone(); break; - case 2: - TVShowConvertInternationalString(gStringVar1, show->findThatGamer.playerName, show->findThatGamer.language); - switch (show->findThatGamer.whichGame) - { - case 0: - StringCopy(gStringVar2, gText_Slots); - break; - case 1: - StringCopy(gStringVar2, gText_Roulette); - break; - } - TV_PrintIntToStringVar(2, show->findThatGamer.nCoins); - sTVShowState = 3; + StringCopy(gStringVar2, gText_Roulette); break; - case 3: - TVShowConvertInternationalString(gStringVar1, show->findThatGamer.playerName, show->findThatGamer.language); - switch (show->findThatGamer.whichGame) - { - case 0: - StringCopy(gStringVar2, gText_Roulette); - break; - case 1: - StringCopy(gStringVar2, gText_Slots); - break; - } - TVShowDone(); + } + if (show->findThatGamer.won == TRUE) + sTVShowState = 1; + else + sTVShowState = 2; + break; + case 1: + TVShowConvertInternationalString(gStringVar1, show->findThatGamer.playerName, show->findThatGamer.language); + switch (show->findThatGamer.whichGame) + { + case 0: + StringCopy(gStringVar2, gText_Slots); break; + case 1: + StringCopy(gStringVar2, gText_Roulette); + break; + } + ConvertIntToDecimalString(2, show->findThatGamer.nCoins); + TVShowDone(); break; + case 2: + TVShowConvertInternationalString(gStringVar1, show->findThatGamer.playerName, show->findThatGamer.language); + switch (show->findThatGamer.whichGame) + { + case 0: + StringCopy(gStringVar2, gText_Slots); + break; + case 1: + StringCopy(gStringVar2, gText_Roulette); + break; + } + ConvertIntToDecimalString(2, show->findThatGamer.nCoins); + sTVShowState = 3; + break; + case 3: + TVShowConvertInternationalString(gStringVar1, show->findThatGamer.playerName, show->findThatGamer.language); + switch (show->findThatGamer.whichGame) + { + case 0: + StringCopy(gStringVar2, gText_Roulette); + break; + case 1: + StringCopy(gStringVar2, gText_Slots); + break; + } + TVShowDone(); + break; } ShowFieldMessage(sTVFindThatGamerTextGroup[state]); } @@ -6146,95 +5802,87 @@ static void DoTVShowBreakingNewsTV(void) state = sTVShowState; switch (state) { - case 0: - if (show->breakingNews.outcome == 0) - { - sTVShowState = 1; - } - else - { - sTVShowState = 5; - } - break; + case 0: + if (show->breakingNews.outcome == 0) + sTVShowState = 1; + else + sTVShowState = 5; + break; + case 1: + TVShowConvertInternationalString(gStringVar1, show->breakingNews.playerName, show->breakingNews.language); + StringCopy(gStringVar2, gSpeciesNames[show->breakingNews.lastOpponentSpecies]); + GetMapName(gStringVar3, show->breakingNews.location, 0); + sTVShowState = 2; + break; + case 2: + TVShowConvertInternationalString(gStringVar1, show->breakingNews.playerName, show->breakingNews.language); + StringCopy(gStringVar2, gSpeciesNames[show->breakingNews.lastOpponentSpecies]); + StringCopy(gStringVar3, gSpeciesNames[show->breakingNews.poke1Species]); + sTVShowState = 3; + break; + case 3: + ConvertIntToDecimalString(0, show->breakingNews.balls); + StringCopy(gStringVar2, ItemId_GetName(show->breakingNews.caughtMonBall)); + sTVShowState = 4; + break; + case 4: + TVShowConvertInternationalString(gStringVar1, show->breakingNews.playerName, show->breakingNews.language); + GetMapName(gStringVar2, show->breakingNews.location, 0); + TVShowDone(); + break; + case 5: + TVShowConvertInternationalString(gStringVar1, show->breakingNews.playerName, show->breakingNews.language); + StringCopy(gStringVar2, gSpeciesNames[show->breakingNews.lastOpponentSpecies]); + GetMapName(gStringVar3, show->breakingNews.location, 0); + sTVShowState = 6; + break; + case 6: + TVShowConvertInternationalString(gStringVar1, show->breakingNews.playerName, show->breakingNews.language); + StringCopy(gStringVar2, gSpeciesNames[show->breakingNews.lastOpponentSpecies]); + StringCopy(gStringVar3, gSpeciesNames[show->breakingNews.poke1Species]); + switch (show->breakingNews.outcome) + { case 1: - TVShowConvertInternationalString(gStringVar1, show->breakingNews.playerName, show->breakingNews.language); - StringCopy(gStringVar2, gSpeciesNames[show->breakingNews.lastOpponentSpecies]); - GetMapName(gStringVar3, show->breakingNews.location, 0); - sTVShowState = 2; + if (show->breakingNews.lastUsedMove == MOVE_NONE) + sTVShowState = 12; + else + sTVShowState = 7; break; case 2: - TVShowConvertInternationalString(gStringVar1, show->breakingNews.playerName, show->breakingNews.language); - StringCopy(gStringVar2, gSpeciesNames[show->breakingNews.lastOpponentSpecies]); - StringCopy(gStringVar3, gSpeciesNames[show->breakingNews.poke1Species]); - sTVShowState = 3; + sTVShowState = 9; break; case 3: - TV_PrintIntToStringVar(0, show->breakingNews.balls); - StringCopy(gStringVar2, ItemId_GetName(show->breakingNews.caughtMonBall)); - sTVShowState = 4; - break; - case 4: - TVShowConvertInternationalString(gStringVar1, show->breakingNews.playerName, show->breakingNews.language); - GetMapName(gStringVar2, show->breakingNews.location, 0); - TVShowDone(); - break; - case 5: - TVShowConvertInternationalString(gStringVar1, show->breakingNews.playerName, show->breakingNews.language); - StringCopy(gStringVar2, gSpeciesNames[show->breakingNews.lastOpponentSpecies]); - GetMapName(gStringVar3, show->breakingNews.location, 0); - sTVShowState = 6; - break; - case 6: - TVShowConvertInternationalString(gStringVar1, show->breakingNews.playerName, show->breakingNews.language); - StringCopy(gStringVar2, gSpeciesNames[show->breakingNews.lastOpponentSpecies]); - StringCopy(gStringVar3, gSpeciesNames[show->breakingNews.poke1Species]); - switch (show->breakingNews.outcome) - { - case 1: - if (show->breakingNews.lastUsedMove == MOVE_NONE) - { - sTVShowState = 12; - } - else - { - sTVShowState = 7; - } - break; - case 2: - sTVShowState = 9; - break; - case 3: - sTVShowState = 10; - break; - } - break; - case 7: - StringCopy(gStringVar1, gMoveNames[show->breakingNews.lastUsedMove]); - StringCopy(gStringVar2, gSpeciesNames[show->breakingNews.poke1Species]); - sTVShowState = 8; - break; - case 12: - TVShowConvertInternationalString(gStringVar1, show->breakingNews.playerName, show->breakingNews.language); - StringCopy(gStringVar2, gSpeciesNames[show->breakingNews.lastOpponentSpecies]); - StringCopy(gStringVar3, gSpeciesNames[show->breakingNews.poke1Species]); - sTVShowState = 8; - break; - case 8: - TVShowConvertInternationalString(gStringVar1, show->breakingNews.playerName, show->breakingNews.language); - GetMapName(gStringVar2, show->breakingNews.location, 0); - sTVShowState = 11; - break; - case 9: - case 10: - TVShowConvertInternationalString(gStringVar1, show->breakingNews.playerName, show->breakingNews.language); - StringCopy(gStringVar2, gSpeciesNames[show->breakingNews.lastOpponentSpecies]); - GetMapName(gStringVar3, show->breakingNews.location, 0); - sTVShowState = 11; - break; - case 11: - TVShowConvertInternationalString(gStringVar1, show->breakingNews.playerName, show->breakingNews.language); - TVShowDone(); + sTVShowState = 10; break; + } + break; + case 7: + StringCopy(gStringVar1, gMoveNames[show->breakingNews.lastUsedMove]); + StringCopy(gStringVar2, gSpeciesNames[show->breakingNews.poke1Species]); + sTVShowState = 8; + break; + case 12: + TVShowConvertInternationalString(gStringVar1, show->breakingNews.playerName, show->breakingNews.language); + StringCopy(gStringVar2, gSpeciesNames[show->breakingNews.lastOpponentSpecies]); + StringCopy(gStringVar3, gSpeciesNames[show->breakingNews.poke1Species]); + sTVShowState = 8; + break; + case 8: + TVShowConvertInternationalString(gStringVar1, show->breakingNews.playerName, show->breakingNews.language); + GetMapName(gStringVar2, show->breakingNews.location, 0); + sTVShowState = 11; + break; + case 9: + case 10: + TVShowConvertInternationalString(gStringVar1, show->breakingNews.playerName, show->breakingNews.language); + StringCopy(gStringVar2, gSpeciesNames[show->breakingNews.lastOpponentSpecies]); + GetMapName(gStringVar3, show->breakingNews.location, 0); + sTVShowState = 11; + break; + case 11: + TVShowConvertInternationalString(gStringVar1, show->breakingNews.playerName, show->breakingNews.language); + TVShowDone(); + break; } ShowFieldMessage(sTVBreakingNewsTextGroup[state]); } @@ -6249,88 +5897,72 @@ static void DoTVShowSecretBaseVisit(void) state = sTVShowState; switch (state) { - case 0: - TVShowConvertInternationalString(gStringVar1, show->secretBaseVisit.playerName, show->secretBaseVisit.language); - if (show->secretBaseVisit.nDecorations == 0) - { - sTVShowState = 2; - } - else - { - sTVShowState = 1; - } - break; - case 1: - StringCopy(gStringVar2, gDecorations[show->secretBaseVisit.decorations[0]].name); - if (show->secretBaseVisit.nDecorations == 1) - { - sTVShowState = 4; - } - else - { - sTVShowState = 3; - } + case 0: + TVShowConvertInternationalString(gStringVar1, show->secretBaseVisit.playerName, show->secretBaseVisit.language); + if (show->secretBaseVisit.nDecorations == 0) + sTVShowState = 2; + else + sTVShowState = 1; + break; + case 1: + StringCopy(gStringVar2, gDecorations[show->secretBaseVisit.decorations[0]].name); + if (show->secretBaseVisit.nDecorations == 1) + sTVShowState = 4; + else + sTVShowState = 3; + break; + case 3: + StringCopy(gStringVar2, gDecorations[show->secretBaseVisit.decorations[1]].name); + switch (show->secretBaseVisit.nDecorations) + { + case 2: + sTVShowState = 7; break; case 3: - StringCopy(gStringVar2, gDecorations[show->secretBaseVisit.decorations[1]].name); - switch (show->secretBaseVisit.nDecorations) - { - case 2: - sTVShowState = 7; - break; - case 3: - sTVShowState = 6; - break; - case 4: - sTVShowState = 5; - break; - } + sTVShowState = 6; break; - case 5: - StringCopy(gStringVar2, gDecorations[show->secretBaseVisit.decorations[2]].name); - StringCopy(gStringVar3, gDecorations[show->secretBaseVisit.decorations[3]].name); - sTVShowState = 8; - break; - case 6: - StringCopy(gStringVar2, gDecorations[show->secretBaseVisit.decorations[2]].name); - sTVShowState = 8; - break; - case 2: case 4: - case 7: - sTVShowState = 8; - break; - case 8: - TVShowConvertInternationalString(gStringVar1, show->secretBaseVisit.playerName, show->secretBaseVisit.language); - if (show->secretBaseVisit.avgLevel < 25) - { - sTVShowState = 12; - } - else if (show->secretBaseVisit.avgLevel < 50) - { - sTVShowState = 11; - } - else if (show->secretBaseVisit.avgLevel < 70) - { - sTVShowState = 10; - } - else - { - sTVShowState = 9; - } - break; - case 9: - case 10: - case 11: - case 12: - TVShowConvertInternationalString(gStringVar1, show->secretBaseVisit.playerName, show->secretBaseVisit.language); - StringCopy(gStringVar2, gSpeciesNames[show->secretBaseVisit.species]); - StringCopy(gStringVar3, gMoveNames[show->secretBaseVisit.move]); - sTVShowState = 13; - break; - case 13: - TVShowDone(); + sTVShowState = 5; break; + } + break; + case 5: + StringCopy(gStringVar2, gDecorations[show->secretBaseVisit.decorations[2]].name); + StringCopy(gStringVar3, gDecorations[show->secretBaseVisit.decorations[3]].name); + sTVShowState = 8; + break; + case 6: + StringCopy(gStringVar2, gDecorations[show->secretBaseVisit.decorations[2]].name); + sTVShowState = 8; + break; + case 2: + case 4: + case 7: + sTVShowState = 8; + break; + case 8: + TVShowConvertInternationalString(gStringVar1, show->secretBaseVisit.playerName, show->secretBaseVisit.language); + if (show->secretBaseVisit.avgLevel < 25) + sTVShowState = 12; + else if (show->secretBaseVisit.avgLevel < 50) + sTVShowState = 11; + else if (show->secretBaseVisit.avgLevel < 70) + sTVShowState = 10; + else + sTVShowState = 9; + break; + case 9: + case 10: + case 11: + case 12: + TVShowConvertInternationalString(gStringVar1, show->secretBaseVisit.playerName, show->secretBaseVisit.language); + StringCopy(gStringVar2, gSpeciesNames[show->secretBaseVisit.species]); + StringCopy(gStringVar3, gMoveNames[show->secretBaseVisit.move]); + sTVShowState = 13; + break; + case 13: + TVShowDone(); + break; } ShowFieldMessage(sTVSecretBaseVisitTextGroup[state]); } @@ -6375,56 +6007,56 @@ static void DoTVShowThePokemonBattleSeminar(void) state = sTVShowState; switch (state) { - case 0: - TVShowConvertInternationalString(gStringVar1, show->battleSeminar.playerName, show->battleSeminar.language); - StringCopy(gStringVar2, gSpeciesNames[show->battleSeminar.species]); - StringCopy(gStringVar3, gSpeciesNames[show->battleSeminar.foeSpecies]); - sTVShowState = 1; - break; + case 0: + TVShowConvertInternationalString(gStringVar1, show->battleSeminar.playerName, show->battleSeminar.language); + StringCopy(gStringVar2, gSpeciesNames[show->battleSeminar.species]); + StringCopy(gStringVar3, gSpeciesNames[show->battleSeminar.foeSpecies]); + sTVShowState = 1; + break; + case 1: + TVShowConvertInternationalString(gStringVar1, show->battleSeminar.playerName, show->battleSeminar.language); + StringCopy(gStringVar2, gSpeciesNames[show->battleSeminar.foeSpecies]); + StringCopy(gStringVar3, gMoveNames[show->battleSeminar.move]); + sTVShowState = 2; + break; + case 2: + StringCopy(gStringVar1, gSpeciesNames[show->battleSeminar.species]); + switch (show->battleSeminar.nOtherMoves) + { case 1: - TVShowConvertInternationalString(gStringVar1, show->battleSeminar.playerName, show->battleSeminar.language); - StringCopy(gStringVar2, gSpeciesNames[show->battleSeminar.foeSpecies]); - StringCopy(gStringVar3, gMoveNames[show->battleSeminar.move]); - sTVShowState = 2; + sTVShowState = 5; break; case 2: - StringCopy(gStringVar1, gSpeciesNames[show->battleSeminar.species]); - switch (show->battleSeminar.nOtherMoves) - { - case 1: - sTVShowState = 5; - break; - case 2: - sTVShowState = 4; - break; - case 3: - sTVShowState = 3; - break; - default: - sTVShowState = 6; - break; - } + sTVShowState = 4; break; case 3: - StringCopy(gStringVar1, gMoveNames[show->battleSeminar.otherMoves[0]]); - StringCopy(gStringVar2, gMoveNames[show->battleSeminar.otherMoves[1]]); - StringCopy(gStringVar3, gMoveNames[show->battleSeminar.otherMoves[2]]); + sTVShowState = 3; + break; + default: sTVShowState = 6; break; - case 4: - StringCopy(gStringVar1, gMoveNames[show->battleSeminar.otherMoves[0]]); - StringCopy(gStringVar2, gMoveNames[show->battleSeminar.otherMoves[1]]); - sTVShowState = 6; - break; - case 5: - StringCopy(gStringVar2, gMoveNames[show->battleSeminar.otherMoves[0]]); - sTVShowState = 6; - break; - case 6: - StringCopy(gStringVar1, gMoveNames[show->battleSeminar.betterMove]); - StringCopy(gStringVar2, gMoveNames[show->battleSeminar.move]); - TVShowDone(); - break; + } + break; + case 3: + StringCopy(gStringVar1, gMoveNames[show->battleSeminar.otherMoves[0]]); + StringCopy(gStringVar2, gMoveNames[show->battleSeminar.otherMoves[1]]); + StringCopy(gStringVar3, gMoveNames[show->battleSeminar.otherMoves[2]]); + sTVShowState = 6; + break; + case 4: + StringCopy(gStringVar1, gMoveNames[show->battleSeminar.otherMoves[0]]); + StringCopy(gStringVar2, gMoveNames[show->battleSeminar.otherMoves[1]]); + sTVShowState = 6; + break; + case 5: + StringCopy(gStringVar2, gMoveNames[show->battleSeminar.otherMoves[0]]); + sTVShowState = 6; + break; + case 6: + StringCopy(gStringVar1, gMoveNames[show->battleSeminar.betterMove]); + StringCopy(gStringVar2, gMoveNames[show->battleSeminar.move]); + TVShowDone(); + break; } ShowFieldMessage(sTVThePokemonBattleSeminarTextGroup[state]); } @@ -6439,57 +6071,49 @@ static void DoTVShowTrainerFanClubSpecial(void) state = sTVShowState; switch (state) { - case 0: - TVShowConvertInternationalString(gStringVar1, show->fanClubSpecial.idolName, show->fanClubSpecial.idolNameLanguage); - TVShowConvertInternationalString(gStringVar2, show->fanClubSpecial.playerName, show->fanClubSpecial.language); - CopyEasyChatWord(gStringVar3, show->fanClubSpecial.words[0]); - if (show->fanClubSpecial.score >= 90) - { - sTVShowState = 1; - } - else if (show->fanClubSpecial.score >= 70) - { - sTVShowState = 2; - } - else if (show->fanClubSpecial.score >= 30) - { - sTVShowState = 3; - } - else - { - sTVShowState = 4; - } - break; - case 1: - TVShowConvertInternationalString(gStringVar1, show->fanClubSpecial.idolName, show->fanClubSpecial.idolNameLanguage); - TVShowConvertInternationalString(gStringVar2, show->fanClubSpecial.playerName, show->fanClubSpecial.language); - TV_PrintIntToStringVar(2, show->fanClubSpecial.score); - sTVShowState = 5; - break; - case 2: - TVShowConvertInternationalString(gStringVar1, show->fanClubSpecial.idolName, show->fanClubSpecial.idolNameLanguage); - TVShowConvertInternationalString(gStringVar2, show->fanClubSpecial.playerName, show->fanClubSpecial.language); - TV_PrintIntToStringVar(2, show->fanClubSpecial.score); - sTVShowState = 5; - break; - case 3: - TVShowConvertInternationalString(gStringVar1, show->fanClubSpecial.idolName, show->fanClubSpecial.idolNameLanguage); - TVShowConvertInternationalString(gStringVar2, show->fanClubSpecial.playerName, show->fanClubSpecial.language); - TV_PrintIntToStringVar(2, show->fanClubSpecial.score); - sTVShowState = 5; - break; - case 4: - TVShowConvertInternationalString(gStringVar1, show->fanClubSpecial.idolName, show->fanClubSpecial.idolNameLanguage); - TVShowConvertInternationalString(gStringVar2, show->fanClubSpecial.playerName, show->fanClubSpecial.language); - TV_PrintIntToStringVar(2, show->fanClubSpecial.score); - sTVShowState = 5; - break; - case 5: - TVShowConvertInternationalString(gStringVar1, show->fanClubSpecial.idolName, show->fanClubSpecial.idolNameLanguage); - TVShowConvertInternationalString(gStringVar2, show->fanClubSpecial.playerName, show->fanClubSpecial.language); - CopyEasyChatWord(gStringVar3, show->fanClubSpecial.words[0]); - TVShowDone(); - break; + case 0: + TVShowConvertInternationalString(gStringVar1, show->fanClubSpecial.idolName, show->fanClubSpecial.idolNameLanguage); + TVShowConvertInternationalString(gStringVar2, show->fanClubSpecial.playerName, show->fanClubSpecial.language); + CopyEasyChatWord(gStringVar3, show->fanClubSpecial.words[0]); + if (show->fanClubSpecial.score >= 90) + sTVShowState = 1; + else if (show->fanClubSpecial.score >= 70) + sTVShowState = 2; + else if (show->fanClubSpecial.score >= 30) + sTVShowState = 3; + else + sTVShowState = 4; + break; + case 1: + TVShowConvertInternationalString(gStringVar1, show->fanClubSpecial.idolName, show->fanClubSpecial.idolNameLanguage); + TVShowConvertInternationalString(gStringVar2, show->fanClubSpecial.playerName, show->fanClubSpecial.language); + ConvertIntToDecimalString(2, show->fanClubSpecial.score); + sTVShowState = 5; + break; + case 2: + TVShowConvertInternationalString(gStringVar1, show->fanClubSpecial.idolName, show->fanClubSpecial.idolNameLanguage); + TVShowConvertInternationalString(gStringVar2, show->fanClubSpecial.playerName, show->fanClubSpecial.language); + ConvertIntToDecimalString(2, show->fanClubSpecial.score); + sTVShowState = 5; + break; + case 3: + TVShowConvertInternationalString(gStringVar1, show->fanClubSpecial.idolName, show->fanClubSpecial.idolNameLanguage); + TVShowConvertInternationalString(gStringVar2, show->fanClubSpecial.playerName, show->fanClubSpecial.language); + ConvertIntToDecimalString(2, show->fanClubSpecial.score); + sTVShowState = 5; + break; + case 4: + TVShowConvertInternationalString(gStringVar1, show->fanClubSpecial.idolName, show->fanClubSpecial.idolNameLanguage); + TVShowConvertInternationalString(gStringVar2, show->fanClubSpecial.playerName, show->fanClubSpecial.language); + ConvertIntToDecimalString(2, show->fanClubSpecial.score); + sTVShowState = 5; + break; + case 5: + TVShowConvertInternationalString(gStringVar1, show->fanClubSpecial.idolName, show->fanClubSpecial.idolNameLanguage); + TVShowConvertInternationalString(gStringVar2, show->fanClubSpecial.playerName, show->fanClubSpecial.language); + CopyEasyChatWord(gStringVar3, show->fanClubSpecial.words[0]); + TVShowDone(); + break; } ShowFieldMessage(sTVTrainerFanClubSpecialTextGroup[state]); } @@ -6505,78 +6129,79 @@ static void DoTVShowTrainerFanClub(void) state = sTVShowState; switch (state) { + case 0: + TVShowConvertInternationalString(gStringVar1, show->trainerFanClub.playerName, show->trainerFanClub.language); + playerId = ((show->common.trainerIdHi << 8) + show->common.trainerIdLo); + switch (playerId % 10) + { case 0: - TVShowConvertInternationalString(gStringVar1, show->trainerFanClub.playerName, show->trainerFanClub.language); - playerId = ((show->common.trainerIdHi << 8) + show->common.trainerIdLo); - switch (playerId % 10) - { - case 0: - sTVShowState = 1; - break; - case 1: - sTVShowState = 2; - break; - case 2: - sTVShowState = 3; - break; - case 3: - sTVShowState = 4; - break; - case 4: - sTVShowState = 5; - break; - case 5: - sTVShowState = 6; - break; - case 6: - sTVShowState = 7; - break; - case 7: - sTVShowState = 8; - break; - case 8: - sTVShowState = 9; - break; - case 9: - sTVShowState = 10; - break; - } + sTVShowState = 1; break; case 1: - sTVShowState = 11; + sTVShowState = 2; break; case 2: - sTVShowState = 11; + sTVShowState = 3; break; case 3: - sTVShowState = 11; + sTVShowState = 4; break; case 4: - sTVShowState = 11; + sTVShowState = 5; break; case 5: - sTVShowState = 11; + sTVShowState = 6; break; case 6: - sTVShowState = 11; + sTVShowState = 7; break; case 7: - sTVShowState = 11; + sTVShowState = 8; break; case 8: - sTVShowState = 11; + sTVShowState = 9; break; case 9: - sTVShowState = 11; + sTVShowState = 10; break; - case 10: - sTVShowState = 11; - break; - case 11: - TVShowConvertInternationalString(gStringVar1, show->trainerFanClub.playerName, show->trainerFanClub.language); - CopyEasyChatWord(gStringVar2, show->trainerFanClub.words[0]); - CopyEasyChatWord(gStringVar3, show->trainerFanClub.words[1]); - TVShowDone(); + } + break; + case 1: + sTVShowState = 11; + break; + case 2: + sTVShowState = 11; + break; + case 3: + sTVShowState = 11; + break; + case 4: + sTVShowState = 11; + break; + case 5: + sTVShowState = 11; + break; + case 6: + sTVShowState = 11; + break; + case 7: + sTVShowState = 11; + break; + case 8: + sTVShowState = 11; + break; + case 9: + sTVShowState = 11; + break; + case 10: + sTVShowState = 11; + break; + case 11: + TVShowConvertInternationalString(gStringVar1, show->trainerFanClub.playerName, show->trainerFanClub.language); + CopyEasyChatWord(gStringVar2, show->trainerFanClub.words[0]); + CopyEasyChatWord(gStringVar3, show->trainerFanClub.words[1]); + TVShowDone(); + break; } ShowFieldMessage(sTVTrainerFanClubTextGroup[state]); } @@ -6594,95 +6219,95 @@ static void DoTVShowSpotTheCuties(void) state = sTVShowState; switch (state) { - case SPOTCUTIES_STATE_INTRO: - TVShowConvertInternationalString(gStringVar1, show->cuties.playerName, show->cuties.language); - TVShowConvertInternationalString(gStringVar2, show->cuties.nickname, show->cuties.pokemonNameLanguage); + case SPOTCUTIES_STATE_INTRO: + TVShowConvertInternationalString(gStringVar1, show->cuties.playerName, show->cuties.language); + TVShowConvertInternationalString(gStringVar2, show->cuties.nickname, show->cuties.pokemonNameLanguage); - // Comments following the intro depend on how many ribbons the pokemon has - if (show->cuties.nRibbons < 10) - sTVShowState = SPOTCUTIES_STATE_RIBBONS_LOW; - else if (show->cuties.nRibbons < 20) - sTVShowState = SPOTCUTIES_STATE_RIBBONS_MID; - else - sTVShowState = SPOTCUTIES_STATE_RIBBONS_HIGH; + // Comments following the intro depend on how many ribbons the pokemon has + if (show->cuties.nRibbons < 10) + sTVShowState = SPOTCUTIES_STATE_RIBBONS_LOW; + else if (show->cuties.nRibbons < 20) + sTVShowState = SPOTCUTIES_STATE_RIBBONS_MID; + else + sTVShowState = SPOTCUTIES_STATE_RIBBONS_HIGH; + break; + case SPOTCUTIES_STATE_RIBBONS_LOW: + case SPOTCUTIES_STATE_RIBBONS_MID: + case SPOTCUTIES_STATE_RIBBONS_HIGH: + TVShowConvertInternationalString(gStringVar1, show->cuties.playerName, show->cuties.language); + TVShowConvertInternationalString(gStringVar2, show->cuties.nickname, show->cuties.pokemonNameLanguage); + ConvertIntToDecimalString(2, show->cuties.nRibbons); + sTVShowState = SPOTCUTIES_STATE_RIBBON_INTRO; + break; + case SPOTCUTIES_STATE_RIBBON_INTRO: + TVShowConvertInternationalString(gStringVar2, show->cuties.nickname, show->cuties.pokemonNameLanguage); + switch (show->cuties.selectedRibbon) + { + case CHAMPION_RIBBON: + sTVShowState = SPOTCUTIES_STATE_RIBBON_CHAMPION; break; - case SPOTCUTIES_STATE_RIBBONS_LOW: - case SPOTCUTIES_STATE_RIBBONS_MID: - case SPOTCUTIES_STATE_RIBBONS_HIGH: - TVShowConvertInternationalString(gStringVar1, show->cuties.playerName, show->cuties.language); - TVShowConvertInternationalString(gStringVar2, show->cuties.nickname, show->cuties.pokemonNameLanguage); - TV_PrintIntToStringVar(2, show->cuties.nRibbons); - sTVShowState = SPOTCUTIES_STATE_RIBBON_INTRO; + case COOL_RIBBON_NORMAL: + case COOL_RIBBON_SUPER: + case COOL_RIBBON_HYPER: + case COOL_RIBBON_MASTER: + sTVShowState = SPOTCUTIES_STATE_RIBBON_COOL; break; - case SPOTCUTIES_STATE_RIBBON_INTRO: - TVShowConvertInternationalString(gStringVar2, show->cuties.nickname, show->cuties.pokemonNameLanguage); - switch (show->cuties.selectedRibbon) - { - case CHAMPION_RIBBON: - sTVShowState = SPOTCUTIES_STATE_RIBBON_CHAMPION; - break; - case COOL_RIBBON_NORMAL: - case COOL_RIBBON_SUPER: - case COOL_RIBBON_HYPER: - case COOL_RIBBON_MASTER: - sTVShowState = SPOTCUTIES_STATE_RIBBON_COOL; - break; - case BEAUTY_RIBBON_NORMAL: - case BEAUTY_RIBBON_SUPER: - case BEAUTY_RIBBON_HYPER: - case BEAUTY_RIBBON_MASTER: - sTVShowState = SPOTCUTIES_STATE_RIBBON_BEAUTY; - break; - case CUTE_RIBBON_NORMAL: - case CUTE_RIBBON_SUPER: - case CUTE_RIBBON_HYPER: - case CUTE_RIBBON_MASTER: - sTVShowState = SPOTCUTIES_STATE_RIBBON_CUTE; - break; - case SMART_RIBBON_NORMAL: - case SMART_RIBBON_SUPER: - case SMART_RIBBON_HYPER: - case SMART_RIBBON_MASTER: - sTVShowState = SPOTCUTIES_STATE_RIBBON_SMART; - break; - case TOUGH_RIBBON_NORMAL: - case TOUGH_RIBBON_SUPER: - case TOUGH_RIBBON_HYPER: - case TOUGH_RIBBON_MASTER: - sTVShowState = SPOTCUTIES_STATE_RIBBON_TOUGH; - break; - case WINNING_RIBBON: - sTVShowState = SPOTCUTIES_STATE_RIBBON_WINNING; - break; - case VICTORY_RIBBON: - sTVShowState = SPOTCUTIES_STATE_RIBBON_VICTORY; - break; - case ARTIST_RIBBON: - sTVShowState = SPOTCUTIES_STATE_RIBBON_ARTIST; - break; - case EFFORT_RIBBON: - sTVShowState = SPOTCUTIES_STATE_RIBBON_EFFORT; - break; - // No comment is made for any of the gift ribbons. - // If the show is created for a gift ribbon - // then this state will repeat indefinitely - } + case BEAUTY_RIBBON_NORMAL: + case BEAUTY_RIBBON_SUPER: + case BEAUTY_RIBBON_HYPER: + case BEAUTY_RIBBON_MASTER: + sTVShowState = SPOTCUTIES_STATE_RIBBON_BEAUTY; break; - case SPOTCUTIES_STATE_RIBBON_CHAMPION: - case SPOTCUTIES_STATE_RIBBON_COOL: - case SPOTCUTIES_STATE_RIBBON_BEAUTY: - case SPOTCUTIES_STATE_RIBBON_CUTE: - case SPOTCUTIES_STATE_RIBBON_SMART: - case SPOTCUTIES_STATE_RIBBON_TOUGH: - case SPOTCUTIES_STATE_RIBBON_WINNING: - case SPOTCUTIES_STATE_RIBBON_VICTORY: - case SPOTCUTIES_STATE_RIBBON_ARTIST: - case SPOTCUTIES_STATE_RIBBON_EFFORT: - TVShowConvertInternationalString(gStringVar2, show->cuties.nickname, show->cuties.pokemonNameLanguage); - sTVShowState = SPOTCUTIES_STATE_OUTRO; + case CUTE_RIBBON_NORMAL: + case CUTE_RIBBON_SUPER: + case CUTE_RIBBON_HYPER: + case CUTE_RIBBON_MASTER: + sTVShowState = SPOTCUTIES_STATE_RIBBON_CUTE; break; - case SPOTCUTIES_STATE_OUTRO: - TVShowDone(); + case SMART_RIBBON_NORMAL: + case SMART_RIBBON_SUPER: + case SMART_RIBBON_HYPER: + case SMART_RIBBON_MASTER: + sTVShowState = SPOTCUTIES_STATE_RIBBON_SMART; + break; + case TOUGH_RIBBON_NORMAL: + case TOUGH_RIBBON_SUPER: + case TOUGH_RIBBON_HYPER: + case TOUGH_RIBBON_MASTER: + sTVShowState = SPOTCUTIES_STATE_RIBBON_TOUGH; + break; + case WINNING_RIBBON: + sTVShowState = SPOTCUTIES_STATE_RIBBON_WINNING; + break; + case VICTORY_RIBBON: + sTVShowState = SPOTCUTIES_STATE_RIBBON_VICTORY; + break; + case ARTIST_RIBBON: + sTVShowState = SPOTCUTIES_STATE_RIBBON_ARTIST; + break; + case EFFORT_RIBBON: + sTVShowState = SPOTCUTIES_STATE_RIBBON_EFFORT; + break; + // No comment is made for any of the gift ribbons. + // If the show is created for a gift ribbon + // then this state will repeat indefinitely + } + break; + case SPOTCUTIES_STATE_RIBBON_CHAMPION: + case SPOTCUTIES_STATE_RIBBON_COOL: + case SPOTCUTIES_STATE_RIBBON_BEAUTY: + case SPOTCUTIES_STATE_RIBBON_CUTE: + case SPOTCUTIES_STATE_RIBBON_SMART: + case SPOTCUTIES_STATE_RIBBON_TOUGH: + case SPOTCUTIES_STATE_RIBBON_WINNING: + case SPOTCUTIES_STATE_RIBBON_VICTORY: + case SPOTCUTIES_STATE_RIBBON_ARTIST: + case SPOTCUTIES_STATE_RIBBON_EFFORT: + TVShowConvertInternationalString(gStringVar2, show->cuties.nickname, show->cuties.pokemonNameLanguage); + sTVShowState = SPOTCUTIES_STATE_OUTRO; + break; + case SPOTCUTIES_STATE_OUTRO: + TVShowDone(); } ShowFieldMessage(sTVCutiesTextGroup[state]); } @@ -6697,140 +6322,140 @@ static void DoTVShowPokemonNewsBattleFrontier(void) state = sTVShowState; switch (state) { - case 0: - switch (show->frontier.facility) - { - case 1: - sTVShowState = 1; - break; - case 2: - sTVShowState = 2; - break; - case 3: - sTVShowState = 3; - break; - case 4: - sTVShowState = 4; - break; - case 5: - sTVShowState = 5; - break; - case 6: - sTVShowState = 6; - break; - case 7: - sTVShowState = 7; - break; - case 8: - sTVShowState = 8; - break; - case 9: - sTVShowState = 9; - break; - case 10: - sTVShowState = 10; - break; - case 11: - sTVShowState = 11; - break; - case 12: - sTVShowState = 12; - break; - case 13: - sTVShowState = 13; - break; - } - break; + case 0: + switch (show->frontier.facilityAndMode) + { case 1: - TVShowConvertInternationalString(gStringVar1, show->frontier.playerName, show->frontier.language); - TV_PrintIntToStringVar(1, show->frontier.winStreak); - sTVShowState = 14; + sTVShowState = 1; break; case 2: - TVShowConvertInternationalString(gStringVar1, show->frontier.playerName, show->frontier.language); - TV_PrintIntToStringVar(1, show->frontier.winStreak); - sTVShowState = 16; + sTVShowState = 2; break; case 3: - TVShowConvertInternationalString(gStringVar1, show->frontier.playerName, show->frontier.language); - TV_PrintIntToStringVar(1, show->frontier.winStreak); - sTVShowState = 15; + sTVShowState = 3; break; case 4: - TVShowConvertInternationalString(gStringVar1, show->frontier.playerName, show->frontier.language); - TV_PrintIntToStringVar(1, show->frontier.winStreak); - sTVShowState = 15; + sTVShowState = 4; break; case 5: - TVShowConvertInternationalString(gStringVar1, show->frontier.playerName, show->frontier.language); - TV_PrintIntToStringVar(1, show->frontier.winStreak); - sTVShowState = 14; + sTVShowState = 5; break; case 6: - TVShowConvertInternationalString(gStringVar1, show->frontier.playerName, show->frontier.language); - TV_PrintIntToStringVar(1, show->frontier.winStreak); - sTVShowState = 14; + sTVShowState = 6; break; case 7: - TVShowConvertInternationalString(gStringVar1, show->frontier.playerName, show->frontier.language); - TV_PrintIntToStringVar(1, show->frontier.winStreak); - sTVShowState = 14; + sTVShowState = 7; break; case 8: - TVShowConvertInternationalString(gStringVar1, show->frontier.playerName, show->frontier.language); - TV_PrintIntToStringVar(1, show->frontier.winStreak); - sTVShowState = 14; + sTVShowState = 8; break; case 9: - TVShowConvertInternationalString(gStringVar1, show->frontier.playerName, show->frontier.language); - TV_PrintIntToStringVar(1, show->frontier.winStreak); - sTVShowState = 14; + sTVShowState = 9; break; case 10: - TVShowConvertInternationalString(gStringVar1, show->frontier.playerName, show->frontier.language); - TV_PrintIntToStringVar(1, show->frontier.winStreak); - sTVShowState = 14; + sTVShowState = 10; break; case 11: - TVShowConvertInternationalString(gStringVar1, show->frontier.playerName, show->frontier.language); - TV_PrintIntToStringVar(1, show->frontier.winStreak); - sTVShowState = 14; + sTVShowState = 11; break; case 12: - TVShowConvertInternationalString(gStringVar1, show->frontier.playerName, show->frontier.language); - TV_PrintIntToStringVar(1, show->frontier.winStreak); - sTVShowState = 14; + sTVShowState = 12; break; case 13: - TVShowConvertInternationalString(gStringVar1, show->frontier.playerName, show->frontier.language); - TV_PrintIntToStringVar(1, show->frontier.winStreak); - sTVShowState = 14; - break; - case 14: - StringCopy(gStringVar1, gSpeciesNames[show->frontier.species1]); - StringCopy(gStringVar2, gSpeciesNames[show->frontier.species2]); - StringCopy(gStringVar3, gSpeciesNames[show->frontier.species3]); - sTVShowState = 18; - break; - case 15: - StringCopy(gStringVar1, gSpeciesNames[show->frontier.species1]); - StringCopy(gStringVar2, gSpeciesNames[show->frontier.species2]); - sTVShowState = 18; - break; - case 16: - StringCopy(gStringVar1, gSpeciesNames[show->frontier.species1]); - StringCopy(gStringVar2, gSpeciesNames[show->frontier.species2]); - StringCopy(gStringVar3, gSpeciesNames[show->frontier.species3]); - sTVShowState = 17; - break; - case 17: - StringCopy(gStringVar1, gSpeciesNames[show->frontier.species4]); - sTVShowState = 18; - break; - case 18: - TVShowConvertInternationalString(gStringVar1, show->frontier.playerName, show->frontier.language); - TVShowDone(); + sTVShowState = 13; break; + } + break; + case 1: + TVShowConvertInternationalString(gStringVar1, show->frontier.playerName, show->frontier.language); + ConvertIntToDecimalString(1, show->frontier.winStreak); + sTVShowState = 14; + break; + case 2: + TVShowConvertInternationalString(gStringVar1, show->frontier.playerName, show->frontier.language); + ConvertIntToDecimalString(1, show->frontier.winStreak); + sTVShowState = 16; + break; + case 3: + TVShowConvertInternationalString(gStringVar1, show->frontier.playerName, show->frontier.language); + ConvertIntToDecimalString(1, show->frontier.winStreak); + sTVShowState = 15; + break; + case 4: + TVShowConvertInternationalString(gStringVar1, show->frontier.playerName, show->frontier.language); + ConvertIntToDecimalString(1, show->frontier.winStreak); + sTVShowState = 15; + break; + case 5: + TVShowConvertInternationalString(gStringVar1, show->frontier.playerName, show->frontier.language); + ConvertIntToDecimalString(1, show->frontier.winStreak); + sTVShowState = 14; + break; + case 6: + TVShowConvertInternationalString(gStringVar1, show->frontier.playerName, show->frontier.language); + ConvertIntToDecimalString(1, show->frontier.winStreak); + sTVShowState = 14; + break; + case 7: + TVShowConvertInternationalString(gStringVar1, show->frontier.playerName, show->frontier.language); + ConvertIntToDecimalString(1, show->frontier.winStreak); + sTVShowState = 14; + break; + case 8: + TVShowConvertInternationalString(gStringVar1, show->frontier.playerName, show->frontier.language); + ConvertIntToDecimalString(1, show->frontier.winStreak); + sTVShowState = 14; + break; + case 9: + TVShowConvertInternationalString(gStringVar1, show->frontier.playerName, show->frontier.language); + ConvertIntToDecimalString(1, show->frontier.winStreak); + sTVShowState = 14; + break; + case 10: + TVShowConvertInternationalString(gStringVar1, show->frontier.playerName, show->frontier.language); + ConvertIntToDecimalString(1, show->frontier.winStreak); + sTVShowState = 14; + break; + case 11: + TVShowConvertInternationalString(gStringVar1, show->frontier.playerName, show->frontier.language); + ConvertIntToDecimalString(1, show->frontier.winStreak); + sTVShowState = 14; + break; + case 12: + TVShowConvertInternationalString(gStringVar1, show->frontier.playerName, show->frontier.language); + ConvertIntToDecimalString(1, show->frontier.winStreak); + sTVShowState = 14; + break; + case 13: + TVShowConvertInternationalString(gStringVar1, show->frontier.playerName, show->frontier.language); + ConvertIntToDecimalString(1, show->frontier.winStreak); + sTVShowState = 14; + break; + case 14: + StringCopy(gStringVar1, gSpeciesNames[show->frontier.species1]); + StringCopy(gStringVar2, gSpeciesNames[show->frontier.species2]); + StringCopy(gStringVar3, gSpeciesNames[show->frontier.species3]); + sTVShowState = 18; + break; + case 15: + StringCopy(gStringVar1, gSpeciesNames[show->frontier.species1]); + StringCopy(gStringVar2, gSpeciesNames[show->frontier.species2]); + sTVShowState = 18; + break; + case 16: + StringCopy(gStringVar1, gSpeciesNames[show->frontier.species1]); + StringCopy(gStringVar2, gSpeciesNames[show->frontier.species2]); + StringCopy(gStringVar3, gSpeciesNames[show->frontier.species3]); + sTVShowState = 17; + break; + case 17: + StringCopy(gStringVar1, gSpeciesNames[show->frontier.species4]); + sTVShowState = 18; + break; + case 18: + TVShowConvertInternationalString(gStringVar1, show->frontier.playerName, show->frontier.language); + TVShowDone(); + break; } ShowFieldMessage(sTVPokemonNewsBattleFrontierTextGroup[state]); } @@ -6845,72 +6470,72 @@ static void DoTVShowWhatsNo1InHoennToday(void) state = sTVShowState; switch (state) { + case 0: + TVShowConvertInternationalString(gStringVar1, show->numberOne.playerName, show->numberOne.language); + switch (show->numberOne.actionIdx) + { case 0: - TVShowConvertInternationalString(gStringVar1, show->numberOne.playerName, show->numberOne.language); - switch (show->numberOne.actionIdx) - { - case 0: - sTVShowState = 1; - break; - case 1: - sTVShowState = 2; - break; - case 2: - sTVShowState = 3; - break; - case 3: - sTVShowState = 4; - break; - case 4: - sTVShowState = 5; - break; - case 5: - sTVShowState = 6; - break; - case 6: - sTVShowState = 7; - break; - } + sTVShowState = 1; break; case 1: - TVShowConvertInternationalString(gStringVar1, show->numberOne.playerName, show->numberOne.language); - TV_PrintIntToStringVar(1, show->numberOne.count); - sTVShowState = 8; + sTVShowState = 2; break; case 2: - TVShowConvertInternationalString(gStringVar1, show->numberOne.playerName, show->numberOne.language); - TV_PrintIntToStringVar(1, show->numberOne.count); - sTVShowState = 8; + sTVShowState = 3; break; case 3: - TVShowConvertInternationalString(gStringVar1, show->numberOne.playerName, show->numberOne.language); - TV_PrintIntToStringVar(1, show->numberOne.count); - sTVShowState = 8; + sTVShowState = 4; break; case 4: - TVShowConvertInternationalString(gStringVar1, show->numberOne.playerName, show->numberOne.language); - TV_PrintIntToStringVar(1, show->numberOne.count); - sTVShowState = 8; + sTVShowState = 5; break; case 5: - TVShowConvertInternationalString(gStringVar1, show->numberOne.playerName, show->numberOne.language); - TV_PrintIntToStringVar(1, show->numberOne.count); - sTVShowState = 8; + sTVShowState = 6; break; case 6: - TVShowConvertInternationalString(gStringVar1, show->numberOne.playerName, show->numberOne.language); - TV_PrintIntToStringVar(1, show->numberOne.count); - sTVShowState = 8; - break; - case 7: - TVShowConvertInternationalString(gStringVar1, show->numberOne.playerName, show->numberOne.language); - TV_PrintIntToStringVar(1, show->numberOne.count); - sTVShowState = 8; - break; - case 8: - TVShowConvertInternationalString(gStringVar1, show->numberOne.playerName, show->numberOne.language); - TVShowDone(); + sTVShowState = 7; break; + } + break; + case 1: + TVShowConvertInternationalString(gStringVar1, show->numberOne.playerName, show->numberOne.language); + ConvertIntToDecimalString(1, show->numberOne.count); + sTVShowState = 8; + break; + case 2: + TVShowConvertInternationalString(gStringVar1, show->numberOne.playerName, show->numberOne.language); + ConvertIntToDecimalString(1, show->numberOne.count); + sTVShowState = 8; + break; + case 3: + TVShowConvertInternationalString(gStringVar1, show->numberOne.playerName, show->numberOne.language); + ConvertIntToDecimalString(1, show->numberOne.count); + sTVShowState = 8; + break; + case 4: + TVShowConvertInternationalString(gStringVar1, show->numberOne.playerName, show->numberOne.language); + ConvertIntToDecimalString(1, show->numberOne.count); + sTVShowState = 8; + break; + case 5: + TVShowConvertInternationalString(gStringVar1, show->numberOne.playerName, show->numberOne.language); + ConvertIntToDecimalString(1, show->numberOne.count); + sTVShowState = 8; + break; + case 6: + TVShowConvertInternationalString(gStringVar1, show->numberOne.playerName, show->numberOne.language); + ConvertIntToDecimalString(1, show->numberOne.count); + sTVShowState = 8; + break; + case 7: + TVShowConvertInternationalString(gStringVar1, show->numberOne.playerName, show->numberOne.language); + ConvertIntToDecimalString(1, show->numberOne.count); + sTVShowState = 8; + break; + case 8: + TVShowConvertInternationalString(gStringVar1, show->numberOne.playerName, show->numberOne.language); + TVShowDone(); + break; } ShowFieldMessage(sTVWhatsNo1InHoennTodayTextGroup[state]); } @@ -6920,7 +6545,7 @@ u8 SecretBaseSecrets_GetNumActionsTaken(TVShow *show) u8 i; u8 flagsSet; - for (i = 0, flagsSet = 0; i < NUM_SECRET_BASE_FLAGS; i ++) + for (i = 0, flagsSet = 0; i < NUM_SECRET_BASE_FLAGS; i++) { if ((show->secretBaseSecrets.flags >> i) & 1) flagsSet++; @@ -6933,7 +6558,7 @@ static u8 SecretBaseSecrets_GetStateByFlagNumber(TVShow *show, u8 flagId) u8 i; u8 flagsSet; - for (i = 0, flagsSet = 0; i < NUM_SECRET_BASE_FLAGS; i ++) + for (i = 0, flagsSet = 0; i < NUM_SECRET_BASE_FLAGS; i++) { if ((show->secretBaseSecrets.flags >> i) & 1) { @@ -6958,130 +6583,112 @@ static void DoTVShowSecretBaseSecrets(void) state = sTVShowState; switch (state) { - case SBSECRETS_STATE_INTRO: - TVShowConvertInternationalString(gStringVar1, show->secretBaseSecrets.baseOwnersName, show->secretBaseSecrets.baseOwnersNameLanguage); - TVShowConvertInternationalString(gStringVar2, show->secretBaseSecrets.playerName, show->secretBaseSecrets.language); - numActions = SecretBaseSecrets_GetNumActionsTaken(show); - if (numActions == 0) - { - sTVShowState = SBSECRETS_STATE_NOTHING_USED1; - } - else - { - show->secretBaseSecrets.savedState = SBSECRETS_STATE_DO_NEXT1; - sTVSecretBaseSecretsRandomValues[0] = Random() % numActions; - sTVShowState = SecretBaseSecrets_GetStateByFlagNumber(show, sTVSecretBaseSecretsRandomValues[0]); - } + case SBSECRETS_STATE_INTRO: + TVShowConvertInternationalString(gStringVar1, show->secretBaseSecrets.baseOwnersName, show->secretBaseSecrets.baseOwnersNameLanguage); + TVShowConvertInternationalString(gStringVar2, show->secretBaseSecrets.playerName, show->secretBaseSecrets.language); + numActions = SecretBaseSecrets_GetNumActionsTaken(show); + if (numActions == 0) + { + sTVShowState = SBSECRETS_STATE_NOTHING_USED1; + } + else + { + show->secretBaseSecrets.savedState = SBSECRETS_STATE_DO_NEXT1; + sTVSecretBaseSecretsRandomValues[0] = Random() % numActions; + sTVShowState = SecretBaseSecrets_GetStateByFlagNumber(show, sTVSecretBaseSecretsRandomValues[0]); + } + break; + case SBSECRETS_STATE_DO_NEXT1: + TVShowConvertInternationalString(gStringVar2, show->secretBaseSecrets.playerName, show->secretBaseSecrets.language); + numActions = SecretBaseSecrets_GetNumActionsTaken(show); + switch (numActions) + { + case 1: + sTVShowState = SBSECRETS_STATE_NOTHING_USED2; break; - case SBSECRETS_STATE_DO_NEXT1: - TVShowConvertInternationalString(gStringVar2, show->secretBaseSecrets.playerName, show->secretBaseSecrets.language); - numActions = SecretBaseSecrets_GetNumActionsTaken(show); - switch (numActions) + case 2: + show->secretBaseSecrets.savedState = SBSECRETS_STATE_DO_NEXT2; + if (sTVSecretBaseSecretsRandomValues[0] == 0) + sTVShowState = SecretBaseSecrets_GetStateByFlagNumber(show, 1); + else + sTVShowState = SecretBaseSecrets_GetStateByFlagNumber(show, 0); + break; + default: + for (i = 0; i < 0xFFFF; i++) { - case 1: - sTVShowState = SBSECRETS_STATE_NOTHING_USED2; - break; - case 2: - show->secretBaseSecrets.savedState = SBSECRETS_STATE_DO_NEXT2; - if (sTVSecretBaseSecretsRandomValues[0] == 0) - { - sTVShowState = SecretBaseSecrets_GetStateByFlagNumber(show, 1); - } - else - { - sTVShowState = SecretBaseSecrets_GetStateByFlagNumber(show, 0); - } - break; - default: - for (i = 0; i < 0xFFFF; i ++) - { - sTVSecretBaseSecretsRandomValues[1] = Random() % numActions; - if (sTVSecretBaseSecretsRandomValues[1] != sTVSecretBaseSecretsRandomValues[0]) - { - break; - } - } - show->secretBaseSecrets.savedState = SBSECRETS_STATE_DO_NEXT2; - sTVShowState = SecretBaseSecrets_GetStateByFlagNumber(show, sTVSecretBaseSecretsRandomValues[1]); + sTVSecretBaseSecretsRandomValues[1] = Random() % numActions; + if (sTVSecretBaseSecretsRandomValues[1] != sTVSecretBaseSecretsRandomValues[0]) break; } + show->secretBaseSecrets.savedState = SBSECRETS_STATE_DO_NEXT2; + sTVShowState = SecretBaseSecrets_GetStateByFlagNumber(show, sTVSecretBaseSecretsRandomValues[1]); break; - case SBSECRETS_STATE_DO_NEXT2: - TVShowConvertInternationalString(gStringVar2, show->secretBaseSecrets.playerName, show->secretBaseSecrets.language); - numActions = SecretBaseSecrets_GetNumActionsTaken(show); - if (numActions == 2) + } + break; + case SBSECRETS_STATE_DO_NEXT2: + TVShowConvertInternationalString(gStringVar2, show->secretBaseSecrets.playerName, show->secretBaseSecrets.language); + numActions = SecretBaseSecrets_GetNumActionsTaken(show); + if (numActions == 2) + { + sTVShowState = SBSECRETS_STATE_NOTHING_USED2; + } + else + { + for (i = 0; i < 0xFFFF; i++) { - sTVShowState = SBSECRETS_STATE_NOTHING_USED2; + sTVSecretBaseSecretsRandomValues[2] = Random() % numActions; + if (sTVSecretBaseSecretsRandomValues[2] != sTVSecretBaseSecretsRandomValues[0] && sTVSecretBaseSecretsRandomValues[2] != sTVSecretBaseSecretsRandomValues[1]) + break; } - else - { - for (i = 0; i < 0xFFFF; i ++) - { - sTVSecretBaseSecretsRandomValues[2] = Random() % numActions; - if (sTVSecretBaseSecretsRandomValues[2] != sTVSecretBaseSecretsRandomValues[0] && sTVSecretBaseSecretsRandomValues[2] != sTVSecretBaseSecretsRandomValues[1]) - { - break; - } - } - show->secretBaseSecrets.savedState = SBSECRETS_STATE_TOOK_X_STEPS; - sTVShowState = SecretBaseSecrets_GetStateByFlagNumber(show, sTVSecretBaseSecretsRandomValues[2]); - } - break; - case SBSECRETS_STATE_TOOK_X_STEPS: - TVShowConvertInternationalString(gStringVar1, show->secretBaseSecrets.baseOwnersName, show->secretBaseSecrets.baseOwnersNameLanguage); - TVShowConvertInternationalString(gStringVar2, show->secretBaseSecrets.playerName, show->secretBaseSecrets.language); - TV_PrintIntToStringVar(2, show->secretBaseSecrets.stepsInBase); - if (show->secretBaseSecrets.stepsInBase <= 30) - { - sTVShowState = SBSECRETS_STATE_BASE_INTEREST_LOW; - } - else if (show->secretBaseSecrets.stepsInBase <= 100) - { - sTVShowState = SBSECRETS_STATE_BASE_INTEREST_MED; - } - else - { - sTVShowState = SBSECRETS_STATE_BASE_INTEREST_HIGH; - } - break; - case SBSECRETS_STATE_BASE_INTEREST_LOW ... SBSECRETS_STATE_BASE_INTEREST_HIGH: - TVShowConvertInternationalString(gStringVar1, show->secretBaseSecrets.baseOwnersName, show->secretBaseSecrets.baseOwnersNameLanguage); - TVShowConvertInternationalString(gStringVar2, show->secretBaseSecrets.playerName, show->secretBaseSecrets.language); - sTVShowState = SBSECRETS_STATE_OUTRO; - break; - case SBSECRETS_STATE_OUTRO: - TVShowConvertInternationalString(gStringVar1, show->secretBaseSecrets.baseOwnersName, show->secretBaseSecrets.baseOwnersNameLanguage); - TVShowConvertInternationalString(gStringVar2, show->secretBaseSecrets.playerName, show->secretBaseSecrets.language); - TVShowDone(); - break; - // All below states are descriptions of what the player interacted with while in the secret base - case SBSECRETS_STATE_NOTHING_USED1: - sTVShowState = SBSECRETS_STATE_TOOK_X_STEPS; - break; - case SBSECRETS_STATE_NOTHING_USED2: - sTVShowState = SBSECRETS_STATE_TOOK_X_STEPS; - break; - case SBSECRETS_STATE_USED_CHAIR ... SBSECRETS_STATE_USED_MUD_BALL: - sTVShowState = show->secretBaseSecrets.savedState; - break; - case SBSECRETS_STATE_USED_BAG: - StringCopy(gStringVar2, ItemId_GetName(show->secretBaseSecrets.item)); - sTVShowState = show->secretBaseSecrets.savedState; - break; - case SBSECRETS_STATE_USED_CUSHION: - // Randomly decide based on trainer ID if the player hugged or hit the cushion - if (show->common.trainerIdLo & 1) - { - sTVShowState = SBSECRETS_STATE_HUGGED_CUSHION; - } - else - { - sTVShowState = SBSECRETS_STATE_HIT_CUSHION; - } - break; - case SBSECRETS_STATE_HIT_CUSHION ... SBSECRETS_NUM_STATES: - sTVShowState = show->secretBaseSecrets.savedState; - break; + show->secretBaseSecrets.savedState = SBSECRETS_STATE_TOOK_X_STEPS; + sTVShowState = SecretBaseSecrets_GetStateByFlagNumber(show, sTVSecretBaseSecretsRandomValues[2]); + } + break; + case SBSECRETS_STATE_TOOK_X_STEPS: + TVShowConvertInternationalString(gStringVar1, show->secretBaseSecrets.baseOwnersName, show->secretBaseSecrets.baseOwnersNameLanguage); + TVShowConvertInternationalString(gStringVar2, show->secretBaseSecrets.playerName, show->secretBaseSecrets.language); + ConvertIntToDecimalString(2, show->secretBaseSecrets.stepsInBase); + if (show->secretBaseSecrets.stepsInBase <= 30) + sTVShowState = SBSECRETS_STATE_BASE_INTEREST_LOW; + else if (show->secretBaseSecrets.stepsInBase <= 100) + sTVShowState = SBSECRETS_STATE_BASE_INTEREST_MED; + else + sTVShowState = SBSECRETS_STATE_BASE_INTEREST_HIGH; + break; + case SBSECRETS_STATE_BASE_INTEREST_LOW ... SBSECRETS_STATE_BASE_INTEREST_HIGH: + TVShowConvertInternationalString(gStringVar1, show->secretBaseSecrets.baseOwnersName, show->secretBaseSecrets.baseOwnersNameLanguage); + TVShowConvertInternationalString(gStringVar2, show->secretBaseSecrets.playerName, show->secretBaseSecrets.language); + sTVShowState = SBSECRETS_STATE_OUTRO; + break; + case SBSECRETS_STATE_OUTRO: + TVShowConvertInternationalString(gStringVar1, show->secretBaseSecrets.baseOwnersName, show->secretBaseSecrets.baseOwnersNameLanguage); + TVShowConvertInternationalString(gStringVar2, show->secretBaseSecrets.playerName, show->secretBaseSecrets.language); + TVShowDone(); + break; + // All below states are descriptions of what the player interacted with while in the secret base + case SBSECRETS_STATE_NOTHING_USED1: + sTVShowState = SBSECRETS_STATE_TOOK_X_STEPS; + break; + case SBSECRETS_STATE_NOTHING_USED2: + sTVShowState = SBSECRETS_STATE_TOOK_X_STEPS; + break; + case SBSECRETS_STATE_USED_CHAIR ... SBSECRETS_STATE_USED_MUD_BALL: + sTVShowState = show->secretBaseSecrets.savedState; + break; + case SBSECRETS_STATE_USED_BAG: + StringCopy(gStringVar2, ItemId_GetName(show->secretBaseSecrets.item)); + sTVShowState = show->secretBaseSecrets.savedState; + break; + case SBSECRETS_STATE_USED_CUSHION: + // Randomly decide based on trainer ID if the player hugged or hit the cushion + if (show->common.trainerIdLo & 1) + sTVShowState = SBSECRETS_STATE_HUGGED_CUSHION; + else + sTVShowState = SBSECRETS_STATE_HIT_CUSHION; + break; + case SBSECRETS_STATE_HIT_CUSHION ... SBSECRETS_NUM_STATES: + sTVShowState = show->secretBaseSecrets.savedState; + break; } ShowFieldMessage(sTVSecretBaseSecretsTextGroup[state]); } @@ -7096,79 +6703,62 @@ static void DoTVShowSafariFanClub(void) state = sTVShowState; switch (state) { - case 0: - if (show->safariFanClub.nMonsCaught == 0) - { - sTVShowState = 6; - } - else if (show->safariFanClub.nMonsCaught < 4) - { - sTVShowState = 5; - } - else - { - sTVShowState = 1; - } - break; - case 1: - TVShowConvertInternationalString(gStringVar1, show->safariFanClub.playerName, show->safariFanClub.language); - TV_PrintIntToStringVar(1, show->safariFanClub.nMonsCaught); - if (show->safariFanClub.nPkblkUsed == 0) - { - sTVShowState = 3; - } - else - { - sTVShowState = 2; - } - break; - case 2: - TV_PrintIntToStringVar(1, show->safariFanClub.nPkblkUsed); - sTVShowState = 4; - break; - case 3: - sTVShowState = 4; - break; - case 4: - TVShowConvertInternationalString(gStringVar1, show->safariFanClub.playerName, show->safariFanClub.language); - sTVShowState = 10; - break; - case 5: - TVShowConvertInternationalString(gStringVar1, show->safariFanClub.playerName, show->safariFanClub.language); - TV_PrintIntToStringVar(1, show->safariFanClub.nMonsCaught); - if (show->safariFanClub.nPkblkUsed == 0) - { - sTVShowState = 8; - } - else - { - sTVShowState = 7; - } - break; - case 6: - TVShowConvertInternationalString(gStringVar1, show->safariFanClub.playerName, show->safariFanClub.language); - if (show->safariFanClub.nPkblkUsed == 0) - { - sTVShowState = 8; - } - else - { - sTVShowState = 7; - } - break; - case 7: - TV_PrintIntToStringVar(1, show->safariFanClub.nPkblkUsed); - sTVShowState = 9; - break; - case 8: - sTVShowState = 9; - break; - case 9: - TVShowConvertInternationalString(gStringVar1, show->safariFanClub.playerName, show->safariFanClub.language); - sTVShowState = 10; - break; - case 10: - TVShowDone(); + case 0: + if (show->safariFanClub.nMonsCaught == 0) + sTVShowState = 6; + else if (show->safariFanClub.nMonsCaught < 4) + sTVShowState = 5; + else + sTVShowState = 1; + break; + case 1: + TVShowConvertInternationalString(gStringVar1, show->safariFanClub.playerName, show->safariFanClub.language); + ConvertIntToDecimalString(1, show->safariFanClub.nMonsCaught); + if (show->safariFanClub.nPkblkUsed == 0) + sTVShowState = 3; + else + sTVShowState = 2; + break; + case 2: + ConvertIntToDecimalString(1, show->safariFanClub.nPkblkUsed); + sTVShowState = 4; + break; + case 3: + sTVShowState = 4; + break; + case 4: + TVShowConvertInternationalString(gStringVar1, show->safariFanClub.playerName, show->safariFanClub.language); + sTVShowState = 10; + break; + case 5: + TVShowConvertInternationalString(gStringVar1, show->safariFanClub.playerName, show->safariFanClub.language); + ConvertIntToDecimalString(1, show->safariFanClub.nMonsCaught); + if (show->safariFanClub.nPkblkUsed == 0) + sTVShowState = 8; + else + sTVShowState = 7; + break; + case 6: + TVShowConvertInternationalString(gStringVar1, show->safariFanClub.playerName, show->safariFanClub.language); + if (show->safariFanClub.nPkblkUsed == 0) + sTVShowState = 8; + else + sTVShowState = 7; + break; + case 7: + ConvertIntToDecimalString(1, show->safariFanClub.nPkblkUsed); + sTVShowState = 9; + break; + case 8: + sTVShowState = 9; + break; + case 9: + TVShowConvertInternationalString(gStringVar1, show->safariFanClub.playerName, show->safariFanClub.language); + sTVShowState = 10; + break; + case 10: + TVShowDone(); + break; } ShowFieldMessage(sTVSafariFanClubTextGroup[state]); } @@ -7187,17 +6777,11 @@ static void DoTVShowLilycoveContestLady(void) case CONTESTLADYLIVE_STATE_INTRO: BufferContestName(gStringVar1, show->contestLady.contestCategory); if (show->contestLady.pokeblockState == CONTEST_LADY_GOOD) - { sTVShowState = CONTESTLADYLIVE_STATE_WON; - } else if (show->contestLady.pokeblockState == CONTEST_LADY_NORMAL) - { sTVShowState = CONTESTLADYLIVE_STATE_LOST; - } else // CONTEST_LADY_BAD - { sTVShowState = CONTESTLADYLIVE_STATE_LOST_BADLY; - } break; case CONTESTLADYLIVE_STATE_WON: case CONTESTLADYLIVE_STATE_LOST: @@ -7210,7 +6794,7 @@ static void DoTVShowLilycoveContestLady(void) ShowFieldMessage(sTVLilycoveContestLadyTextGroup[state]); } -void TVShowDone(void) +static void TVShowDone(void) { gSpecialVar_Result = TRUE; sTVShowState = 0;