From bf61de01a75c67e2003405c3a07f948ba4799751 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 31 Aug 2020 13:36:48 -0400 Subject: [PATCH 1/6] Start documenting battle factory screen --- common_syms/battle_factory_screen.txt | 2 +- .../scripts.inc | 2 +- .../factory_screen/action_box_left.png | Bin 0 -> 156 bytes .../factory_screen/action_box_right.png | Bin 0 -> 134 bytes .../factory_screen/action_highlight_left.png | Bin 0 -> 165 bytes .../action_highlight_middle.png | Bin 0 -> 139 bytes .../factory_screen/action_highlight_right.png | Bin 0 -> 139 bytes .../battle_frontier/factory_screen/arrow.png | Bin 0 -> 167 bytes .../factory_screen/interface.pal} | 0 .../factory_screen/menu_highlight_left.png | Bin 0 -> 135 bytes .../factory_screen/menu_highlight_right.png | Bin 0 -> 132 bytes .../factory_screen/mon_pic_bg.bin} | Bin .../factory_screen/mon_pic_bg.png | Bin 0 -> 138 bytes .../factory_screen/mon_pic_bg_anim.png | Bin 0 -> 158 bytes .../factory_screen/pokeball.png | Bin 0 -> 263 bytes .../factory_screen/pokeball_gray.pal} | 0 .../factory_screen/pokeball_selected.pal} | 0 .../factory_screen/text.pal} | 0 graphics/unknown/unknown_60F1BC.png | Bin 211 -> 0 bytes graphics/unknown/unknown_60F3BC.png | Bin 115 -> 0 bytes graphics/unknown/unknown_60F43C.png | Bin 75 -> 0 bytes graphics/unknown/unknown_60F53C.png | Bin 72 -> 0 bytes graphics/unknown/unknown_60F63C.png | Bin 99 -> 0 bytes graphics/unknown/unknown_60F6BC.png | Bin 77 -> 0 bytes graphics/unknown/unknown_60F7BC.png | Bin 110 -> 0 bytes graphics/unknown/unknown_60F83C.png | Bin 82 -> 0 bytes graphics/unknown/unknown_60F93C.png | Bin 82 -> 0 bytes graphics/unknown/unknown_60FA3C.png | Bin 98 -> 0 bytes graphics/unknown/unknown_61033C.png | Bin 78 -> 0 bytes graphics/unknown/unknown_61039C.pal | 19 - src/battle_factory.c | 42 +- src/battle_factory_screen.c | 674 +++++++++--------- 32 files changed, 367 insertions(+), 372 deletions(-) create mode 100644 graphics/battle_frontier/factory_screen/action_box_left.png create mode 100644 graphics/battle_frontier/factory_screen/action_box_right.png create mode 100644 graphics/battle_frontier/factory_screen/action_highlight_left.png create mode 100644 graphics/battle_frontier/factory_screen/action_highlight_middle.png create mode 100644 graphics/battle_frontier/factory_screen/action_highlight_right.png create mode 100644 graphics/battle_frontier/factory_screen/arrow.png rename graphics/{unknown/unknown_60F17C.pal => battle_frontier/factory_screen/interface.pal} (100%) create mode 100644 graphics/battle_frontier/factory_screen/menu_highlight_left.png create mode 100644 graphics/battle_frontier/factory_screen/menu_highlight_right.png rename graphics/{unknown/unknown_61023C.bin => battle_frontier/factory_screen/mon_pic_bg.bin} (100%) create mode 100644 graphics/battle_frontier/factory_screen/mon_pic_bg.png create mode 100644 graphics/battle_frontier/factory_screen/mon_pic_bg_anim.png create mode 100644 graphics/battle_frontier/factory_screen/pokeball.png rename graphics/{unknown/unknown_60F13C.pal => battle_frontier/factory_screen/pokeball_gray.pal} (100%) rename graphics/{unknown/unknown_60F15C.pal => battle_frontier/factory_screen/pokeball_selected.pal} (100%) rename graphics/{unknown/unknown_61046C.pal => battle_frontier/factory_screen/text.pal} (100%) delete mode 100644 graphics/unknown/unknown_60F1BC.png delete mode 100644 graphics/unknown/unknown_60F3BC.png delete mode 100644 graphics/unknown/unknown_60F43C.png delete mode 100644 graphics/unknown/unknown_60F53C.png delete mode 100644 graphics/unknown/unknown_60F63C.png delete mode 100644 graphics/unknown/unknown_60F6BC.png delete mode 100644 graphics/unknown/unknown_60F7BC.png delete mode 100644 graphics/unknown/unknown_60F83C.png delete mode 100644 graphics/unknown/unknown_60F93C.png delete mode 100644 graphics/unknown/unknown_60FA3C.png delete mode 100644 graphics/unknown/unknown_61033C.png delete mode 100644 graphics/unknown/unknown_61039C.pal diff --git a/common_syms/battle_factory_screen.txt b/common_syms/battle_factory_screen.txt index 9f6868139..3ddeb6d3b 100644 --- a/common_syms/battle_factory_screen.txt +++ b/common_syms/battle_factory_screen.txt @@ -1 +1 @@ -gUnknown_030062E8 +gFactorySelect_CurrentOptionFunc diff --git a/data/maps/BattleFrontier_BattleFactoryPreBattleRoom/scripts.inc b/data/maps/BattleFrontier_BattleFactoryPreBattleRoom/scripts.inc index 48d2bcc3a..e85697146 100644 --- a/data/maps/BattleFrontier_BattleFactoryPreBattleRoom/scripts.inc +++ b/data/maps/BattleFrontier_BattleFactoryPreBattleRoom/scripts.inc @@ -168,7 +168,7 @@ BattleFrontier_BattleFactoryPreBattleRoom_EventScript_SwapMons:: @ 8259DF2 fadescreen FADE_TO_BLACK factory_swapmons waitstate - compare VAR_RESULT, 1 + compare VAR_RESULT, TRUE @ Did player keep current pokemon goto_if_eq BattleFrontier_BattleFactoryPreBattleRoom_EventScript_EnterBattleRoom factory_setswapped msgbox BattleFrontier_BattleFactoryPreBattleRoom_Text_YourSwapIsComplete, MSGBOX_DEFAULT diff --git a/graphics/battle_frontier/factory_screen/action_box_left.png b/graphics/battle_frontier/factory_screen/action_box_left.png new file mode 100644 index 0000000000000000000000000000000000000000..c4c943a15a9ef5ab494b26ac28e4aa64aabce955 GIT binary patch literal 156 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!73?$#)eFPFP2=EDU1=2w9pMhaX@wa#H-T_I7 z2rhE%C%+#+IdxAL#}JO0wZ}H{GAJ+{-r!-``M*9{QTAiXx#rfRhmsOEZitA`sTW_L V&ciO{Wnm67&ePS;Wt~$(699B alfIa(b0#*S8$&w`uq758|jS^e|j1vTeTNVPjnJ$b4 dnm%lK3=F|c>_6){SZhEgd%F6$taD0e0swIgCCUH* literal 0 HcmV?d00001 diff --git a/graphics/unknown/unknown_60F17C.pal b/graphics/battle_frontier/factory_screen/interface.pal similarity index 100% rename from graphics/unknown/unknown_60F17C.pal rename to graphics/battle_frontier/factory_screen/interface.pal diff --git a/graphics/battle_frontier/factory_screen/menu_highlight_left.png b/graphics/battle_frontier/factory_screen/menu_highlight_left.png new file mode 100644 index 0000000000000000000000000000000000000000..1c39f725010c1fb35d64e5f64fb047c3551b1ef4 GIT binary patch literal 135 zcmeAS@N?(olHy`uVBq!ia0vp^3P3Et!VDx^^%AmxltF+`h%1l=g8vK*ONzg}d-o1V zLPT(pYd`t@0Llq@x;TbNOifNmNC=Nu7_a~U literal 0 HcmV?d00001 diff --git a/graphics/unknown/unknown_61023C.bin b/graphics/battle_frontier/factory_screen/mon_pic_bg.bin similarity index 100% rename from graphics/unknown/unknown_61023C.bin rename to graphics/battle_frontier/factory_screen/mon_pic_bg.bin diff --git a/graphics/battle_frontier/factory_screen/mon_pic_bg.png b/graphics/battle_frontier/factory_screen/mon_pic_bg.png new file mode 100644 index 0000000000000000000000000000000000000000..b72da6f44b535b91f10381a76541bac282e22ad4 GIT binary patch literal 138 zcmeAS@N?(olHy`uVBq!ia0vp^57?|7~IT$udvSc1&WH`5j#js03Aq=R1!PC{xWt~$(699q#JVyWk literal 0 HcmV?d00001 diff --git a/graphics/battle_frontier/factory_screen/mon_pic_bg_anim.png b/graphics/battle_frontier/factory_screen/mon_pic_bg_anim.png new file mode 100644 index 0000000000000000000000000000000000000000..324063d0deb5d012b29d1f8260ffc970749a24cb GIT binary patch literal 158 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0J3?w7mbKU|eg8-ipS0H`$|2yK*%vYCGfqFDO zT^vI^I+Gt%w~N~(9MJ#&?(T}FK-R@vZlXO}5}^jG5_V`lIIRDlfq`EuuP;*8%>k&1 N!PC{xWt~$(696H8Ng)6L literal 0 HcmV?d00001 diff --git a/graphics/battle_frontier/factory_screen/pokeball.png b/graphics/battle_frontier/factory_screen/pokeball.png new file mode 100644 index 0000000000000000000000000000000000000000..b3426fc727e3fd1da1747093956d381bff9dbc52 GIT binary patch literal 263 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnF3?v&v(vJfvg8-ipS0FuQ%97&Z<|R>4j*dZB zuU7BfdlVva_3AyKNOkp^IdjeemHq$!-_gnRS2XoOTmXx%lO4%cUsil8N!!iZ*PXE7_AK+NGt4t1s~NXw`R^Ex;A- z!2jUdL)-Ta?;G|t{P|+qbi$*h`S%B#z@v%HZ(i~9U%hNvn&2XHVFVdQ&MBb@ E08Q|1UjP6A literal 0 HcmV?d00001 diff --git a/graphics/unknown/unknown_60F13C.pal b/graphics/battle_frontier/factory_screen/pokeball_gray.pal similarity index 100% rename from graphics/unknown/unknown_60F13C.pal rename to graphics/battle_frontier/factory_screen/pokeball_gray.pal diff --git a/graphics/unknown/unknown_60F15C.pal b/graphics/battle_frontier/factory_screen/pokeball_selected.pal similarity index 100% rename from graphics/unknown/unknown_60F15C.pal rename to graphics/battle_frontier/factory_screen/pokeball_selected.pal diff --git a/graphics/unknown/unknown_61046C.pal b/graphics/battle_frontier/factory_screen/text.pal similarity index 100% rename from graphics/unknown/unknown_61046C.pal rename to graphics/battle_frontier/factory_screen/text.pal diff --git a/graphics/unknown/unknown_60F1BC.png b/graphics/unknown/unknown_60F1BC.png deleted file mode 100644 index 185b93d57c58335da10ec86bc3c7457b8b9ea933..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 211 zcmeAS@N?(olHy`uVBq!ia0vp^3Lwk^Bp4pd2o=l-?H!QE1>tCIo{ptXROhgcK_t!|V zM$Z~1AEsZ|9)?SJaqUU56`U^P#bvlc>50Z;+0+|0?lbFt%HGS6+j+)tcR~WlwVtki JF6*2UngDXdPj~V|9@=C0fSAf Y41YQvCtm*kd^t#!r>mdKI;Vst0Iy6JN&o-= diff --git a/graphics/unknown/unknown_60F53C.png b/graphics/unknown/unknown_60F53C.png deleted file mode 100644 index 65450c7b33878b2eb300b83f301e5e5b870ea32d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 72 zcmeAS@N?(olHy`uVBq!ia0vp^3P3Et0wfrw&pzJ*r1(8u9780gChzEGlW^O{z>xp? UE@P2j(;bi!Pgg&ebxsLQ00v(XeEp+6kfg4*I3_Bg-r+hoeJo`vVwR!3%kO2&yu6{1- HoD!MAs(H{KQubTPZ&R#E-oSy uYOpFHZ diff --git a/graphics/unknown/unknown_61039C.pal b/graphics/unknown/unknown_61039C.pal deleted file mode 100644 index 89f527ce4..000000000 --- a/graphics/unknown/unknown_61039C.pal +++ /dev/null @@ -1,19 +0,0 @@ -JASC-PAL -0100 -16 -0 0 0 -213 255 238 -213 255 238 -213 255 238 -213 255 238 -213 255 238 -213 255 238 -213 255 238 -213 255 238 -213 255 238 -213 255 238 -213 255 238 -213 255 238 -213 255 238 -213 255 238 -213 255 238 diff --git a/src/battle_factory.c b/src/battle_factory.c index 940e71f7d..8a94dff0c 100644 --- a/src/battle_factory.c +++ b/src/battle_factory.c @@ -26,8 +26,8 @@ static void InitFactoryChallenge(void); static void GetBattleFactoryData(void); static void SetBattleFactoryData(void); static void SaveFactoryChallenge(void); -static void nullsub_75(void); -static void nullsub_123(void); +static void FactoryDummy1(void); +static void FactoryDummy2(void); static void SelectInitialRentalMons(void); static void SwapRentalMons(void); static void SetPerformedRentalSwap(void); @@ -42,8 +42,16 @@ static void RestorePlayerPartyHeldItems(void); static u16 GetFactoryMonId(u8 lvlMode, u8 challengeNum, bool8 arg2); static u8 GetMoveBattleStyle(u16 move); -// Const rom data. -static const u8 sRequiredMoveCounts[] = {3, 3, 3, 2, 2, 2, 2}; +// Number of moves needed on the team to be considered using a certain battle style +static const u8 sRequiredMoveCounts[FACTORY_NUM_STYLES - 1] = { + [FACTORY_STYLE_PREPARATION - 1] = 3, + [FACTORY_STYLE_SLOW_STEADY - 1] = 3, + [FACTORY_STYLE_ENDURANCE - 1] = 3, + [FACTORY_STYLE_HIGH_RISK - 1] = 2, + [FACTORY_STYLE_WEAKENING - 1] = 2, + [FACTORY_STYLE_UNPREDICTABLE - 1] = 2, + [FACTORY_STYLE_WEATHER - 1] = 2 +}; static const u16 sMoves_TotalPreparation[] = { @@ -120,8 +128,8 @@ static void (* const sBattleFactoryFunctions[])(void) = [BATTLE_FACTORY_FUNC_GET_DATA] = GetBattleFactoryData, [BATTLE_FACTORY_FUNC_SET_DATA] = SetBattleFactoryData, [BATTLE_FACTORY_FUNC_SAVE] = SaveFactoryChallenge, - [BATTLE_FACTORY_FUNC_NULL] = nullsub_75, - [BATTLE_FACTORY_FUNC_NULL2] = nullsub_123, + [BATTLE_FACTORY_FUNC_NULL] = FactoryDummy1, + [BATTLE_FACTORY_FUNC_NULL2] = FactoryDummy2, [BATTLE_FACTORY_FUNC_SELECT_RENT_MONS] = SelectInitialRentalMons, [BATTLE_FACTORY_FUNC_SWAP_RENT_MONS] = SwapRentalMons, [BATTLE_FACTORY_FUNC_SET_SWAPPED] = SetPerformedRentalSwap, @@ -267,12 +275,12 @@ static void SaveFactoryChallenge(void) SaveGameFrontier(); } -static void nullsub_75(void) +static void FactoryDummy1(void) { } -static void nullsub_123(void) +static void FactoryDummy2(void) { } @@ -377,10 +385,10 @@ static void SetRentalsToOpponentParty(void) for (i = 0; i < FRONTIER_PARTY_SIZE; i++) { - gSaveBlock2Ptr->frontier.rentalMons[i + 3].monId = gUnknown_03006298[i]; - gSaveBlock2Ptr->frontier.rentalMons[i + 3].ivs = GetBoxMonData(&gEnemyParty[i].box, MON_DATA_ATK_IV, NULL); - gSaveBlock2Ptr->frontier.rentalMons[i + 3].personality = GetMonData(&gEnemyParty[i], MON_DATA_PERSONALITY, NULL); - gSaveBlock2Ptr->frontier.rentalMons[i + 3].abilityNum = GetBoxMonData(&gEnemyParty[i].box, MON_DATA_ABILITY_NUM, NULL); + gSaveBlock2Ptr->frontier.rentalMons[i + FRONTIER_PARTY_SIZE].monId = gUnknown_03006298[i]; + gSaveBlock2Ptr->frontier.rentalMons[i + FRONTIER_PARTY_SIZE].ivs = GetBoxMonData(&gEnemyParty[i].box, MON_DATA_ATK_IV, NULL); + gSaveBlock2Ptr->frontier.rentalMons[i + FRONTIER_PARTY_SIZE].personality = GetMonData(&gEnemyParty[i], MON_DATA_PERSONALITY, NULL); + gSaveBlock2Ptr->frontier.rentalMons[i + FRONTIER_PARTY_SIZE].abilityNum = GetBoxMonData(&gEnemyParty[i].box, MON_DATA_ABILITY_NUM, NULL); SetMonData(&gEnemyParty[i], MON_DATA_HELD_ITEM, &gBattleFrontierHeldItems[gFacilityTrainerMons[gUnknown_03006298[i]].itemTableId]); } } @@ -456,13 +464,13 @@ static void SetPlayerAndOpponentParties(void) case 2: for (i = 0; i < FRONTIER_PARTY_SIZE; i++) { - monId = gSaveBlock2Ptr->frontier.rentalMons[i + 3].monId; - ivs = gSaveBlock2Ptr->frontier.rentalMons[i + 3].ivs; + monId = gSaveBlock2Ptr->frontier.rentalMons[i + FRONTIER_PARTY_SIZE].monId; + ivs = gSaveBlock2Ptr->frontier.rentalMons[i + FRONTIER_PARTY_SIZE].ivs; CreateMon(&gEnemyParty[i], gFacilityTrainerMons[monId].species, monLevel, ivs, - TRUE, gSaveBlock2Ptr->frontier.rentalMons[i + 3].personality, + TRUE, gSaveBlock2Ptr->frontier.rentalMons[i + FRONTIER_PARTY_SIZE].personality, OT_ID_PLAYER_ID, 0); count = 0; @@ -485,7 +493,7 @@ static void SetPlayerAndOpponentParties(void) for (k = 0; k < MAX_MON_MOVES; k++) SetMonMoveAvoidReturn(&gEnemyParty[i], gFacilityTrainerMons[monId].moves[k], k); SetMonData(&gEnemyParty[i], MON_DATA_HELD_ITEM, &gBattleFrontierHeldItems[gFacilityTrainerMons[monId].itemTableId]); - SetMonData(&gEnemyParty[i], MON_DATA_ABILITY_NUM, &gSaveBlock2Ptr->frontier.rentalMons[i + 3].abilityNum); + SetMonData(&gEnemyParty[i], MON_DATA_ABILITY_NUM, &gSaveBlock2Ptr->frontier.rentalMons[i + FRONTIER_PARTY_SIZE].abilityNum); } break; } @@ -640,7 +648,7 @@ static void GetOpponentBattleStyle(void) } } - gSpecialVar_Result = 0; + gSpecialVar_Result = FACTORY_STYLE_NONE; for (i = 1; i < FACTORY_NUM_STYLES; i++) { if (stylePoints[i] >= sRequiredMoveCounts[i - 1]) diff --git a/src/battle_factory_screen.c b/src/battle_factory_screen.c index 388881a1c..379c03613 100644 --- a/src/battle_factory_screen.c +++ b/src/battle_factory_screen.c @@ -30,33 +30,41 @@ #include "constants/rgb.h" // Select_ refers to the first Pokemon selection screen where you choose 3 Pokemon. -// Swap_ refers to the consecutive selection screen where you can keep your Pokemon or swap one with beaten trainer's. +// Swap_ refers to the subsequent selection screens where you can swap a Pokemon with one from the beaten trainer -#define MENU_SUMMARY 0 -#define MENU_RENT 1 -#define MENU_DESELECT 1 -#define MENU_OTHERS 2 -#define MENU_OPTIONS_COUNT 3 +// 'Action' refers to the 3 Selectable mons, Cancel, Pknm for swap windows. +#define ACTIONS_PLAYER_SCREEN 0 +#define ACTIONS_ENEMY_SCREEN 1 + +#define SELECTMENU_SUMMARY 0 +#define SELECTMENU_RENT 1 +#define SELECTMENU_OTHERS 2 +#define SELECTMENU_OPTIONS_COUNT 3 + +#define SWAPMENU_SUMMARY 0 +#define SWAPMENU_SWAP 1 +#define SWAPMENU_RECHOOSE 2 +#define SWAPMENU_OPTIONS_COUNT 3 #define SELECTABLE_MONS_COUNT 6 -#define TAG_PAL_BALL_GREY 0x64 -#define TAG_PAL_BALL_SELECTED 0x65 -#define TAG_PAL_66 0x66 -#define TAG_PAL_67 0x67 +#define PALTAG_BALL_GRAY 0x64 +#define PALTAG_BALL_SELECTED 0x65 +#define PALTAG_INTERFACE 0x66 +#define PALTAG_MON_PIC_BG 0x67 -#define TAG_TILE_64 0x64 -#define TAG_TILE_65 0x65 -#define TAG_TILE_66 0x66 -#define TAG_TILE_67 0x67 -#define TAG_TILE_68 0x68 -#define TAG_TILE_69 0x69 -#define TAG_TILE_6A 0x6A -#define TAG_TILE_6B 0x6B -#define TAG_TILE_6C 0x6C -#define TAG_TILE_6D 0x6D +#define GFXTAG_BALL 0x64 +#define GFXTAG_ARROW 0x65 +#define GFXTAG_MENU_HIGHLIGHT_LEFT 0x66 +#define GFXTAG_MENU_HIGHLIGHT_RIGHT 0x67 +#define GFXTAG_ACTION_BOX_LEFT 0x68 +#define GFXTAG_ACTION_BOX_RIGHT 0x69 +#define GFXTAG_ACTION_HIGHLIGHT_LEFT 0x6A +#define GFXTAG_ACTION_HIGHLIGHT_MIDDLE 0x6B +#define GFXTAG_ACTION_HIGHLIGHT_RIGHT 0x6C +#define GFXTAG_MON_PIC_BG_ANIM 0x6D -struct FactorySelecteableMon +struct FactorySelectableMon { u16 monId; u16 spriteId; @@ -70,7 +78,7 @@ struct UnkFactoryStruct u8 field1; }; -struct FactorySelectMonsStruct +struct FactorySelectScreen { u8 menuCursorPos; u8 menuCursor1SpriteId; @@ -81,36 +89,32 @@ struct FactorySelectMonsStruct bool8 fromSummaryScreen; u8 yesNoCursorPos; u8 unused8; - struct FactorySelecteableMon mons[SELECTABLE_MONS_COUNT]; - struct UnkFactoryStruct unk294[3]; + struct FactorySelectableMon mons[SELECTABLE_MONS_COUNT]; + struct UnkFactoryStruct unk294[FRONTIER_PARTY_SIZE]; bool8 unk2A0; u8 fadeSpeciesNameTaskId; bool8 unk2A2; - u16 unk2A4; + u16 speciesNameColorBackup; bool8 unk2A6; u8 unk2A7; u8 unk2A8; u8 unk2A9; }; -// 'Action' refers to the 3 Selectable mons, Cancel, Pknm for swap windows. -#define ACTIONS_PLAYER_SCREEN 0 -#define ACTIONS_ENEMY_SCREEN 1 - -struct SwapActionIdAndFunc +struct SwapScreenAction { u8 id; void (*func)(u8 taskId); }; -struct FactorySwapMonsStruct +struct FactorySwapScreen { u8 menuCursorPos; u8 menuCursor1SpriteId; u8 menuCursor2SpriteId; u8 cursorPos; u8 cursorSpriteId; - u8 ballSpriteIds[3]; + u8 ballSpriteIds[FRONTIER_PARTY_SIZE]; u8 unk8[2][3]; u8 unkE[2][2]; u8 playerMonId; @@ -119,7 +123,7 @@ struct FactorySwapMonsStruct bool8 fromSummaryScreen; u8 yesNoCursorPos; u8 actionsCount; - const struct SwapActionIdAndFunc *actionsData; + const struct SwapScreenAction *actionsData; u8 unused1C[4]; bool8 monSwapped; u8 fadeSpeciesNameTaskId; @@ -134,12 +138,12 @@ struct FactorySwapMonsStruct }; // This file's functions. -static void sub_819A44C(struct Sprite *sprite); +static void SpriteCB_Pokeball(struct Sprite *sprite); static void CB2_InitSelectScreen(void); static void Select_SetWinRegs(s16 mWin0H, s16 nWin0H, s16 mWin0V, s16 nWin0V); static void Select_InitMonsData(void); static void Select_InitAllSprites(void); -static void Select_ShowSummaryMonSprite(void); +static void Select_ReshowMonSprite(void); static void Select_PrintSelectMonString(void); static void Select_PrintMonSpecies(void); static void Select_PrintMonCategory(void); @@ -196,9 +200,9 @@ static void Swap_ShowSummaryMonSprite(void); static void Swap_UpdateActionCursorPosition(s8 direction); static void Swap_UpdateBallCursorPosition(s8 direction); static void Swap_RunMenuOptionFunc(u8 taskId); -static void sub_819F0CC(u8 taskId); -static void sub_819F114(u8 taskId); -static void sub_819F134(u8 taskId); +static void Swap_OptionSwap(u8 taskId); +static void Swap_OptionSummary(u8 taskId); +static void Swap_OptionRechoose(u8 taskId); static void Swap_RunActionFunc(u8 taskId); static void sub_819F69C(u8 taskId); static void Task_SwapCantHaveSameMons(u8 taskId); @@ -216,70 +220,67 @@ static void Swap_ActionPkmnForSwap(u8 taskId); // Ewram variables static EWRAM_DATA u8 *sSelectMenuTilesetBuffer = NULL; -static EWRAM_DATA u8 *sSelectMonCardBgTilesetBuffer = NULL; +static EWRAM_DATA u8 *sSelectMonPicBgTilesetBuffer = NULL; static EWRAM_DATA u8 *sSelectMenuTilemapBuffer = NULL; -static EWRAM_DATA u8 *sSelectMonCardBgTilemapBuffer = NULL; +static EWRAM_DATA u8 *sSelectMonPicBgTilemapBuffer = NULL; static EWRAM_DATA struct Pokemon *sFactorySelectMons = NULL; static EWRAM_DATA u8 *sSwapMenuTilesetBuffer = NULL; -static EWRAM_DATA u8 *sSwapMonCardBgTilesetBuffer = NULL; +static EWRAM_DATA u8 *sSwapMonPicBgTilesetBuffer = NULL; static EWRAM_DATA u8 *sSwapMenuTilemapBuffer = NULL; -static EWRAM_DATA u8 *sSwapMonCardBgTilemapBuffer = NULL; +static EWRAM_DATA u8 *sSwapMonPicBgTilemapBuffer = NULL; -// IWRAM bss -static struct FactorySelectMonsStruct *sFactorySelectScreen; -static void (*sSwap_CurrentTableFunc)(u8 taskId); -static struct FactorySwapMonsStruct *sFactorySwapScreen; +static struct FactorySelectScreen *sFactorySelectScreen; +static void (*sSwap_CurrentOptionFunc)(u8 taskId); +static struct FactorySwapScreen *sFactorySwapScreen; -// IWRAM common -u8 (*gUnknown_030062E8)(void); +u8 (*gFactorySelect_CurrentOptionFunc)(void); -// Const rom data. -static const u16 gUnknown_0860F13C[] = INCBIN_U16("graphics/unknown/unknown_60F13C.gbapal"); -static const u16 gUnknown_0860F15C[] = INCBIN_U16("graphics/unknown/unknown_60F15C.gbapal"); -static const u16 gUnknown_0860F17C[] = INCBIN_U16("graphics/unknown/unknown_60F17C.gbapal"); -static const u8 gUnknown_0860F1BC[] = INCBIN_U8("graphics/unknown/unknown_60F1BC.4bpp"); -static const u8 gUnknown_0860F3BC[] = INCBIN_U8("graphics/unknown/unknown_60F3BC.4bpp"); -static const u8 gUnknown_0860F43C[] = INCBIN_U8("graphics/unknown/unknown_60F43C.4bpp"); -static const u8 gUnknown_0860F53C[] = INCBIN_U8("graphics/unknown/unknown_60F53C.4bpp"); -static const u8 gUnknown_0860F63C[] = INCBIN_U8("graphics/unknown/unknown_60F63C.4bpp"); -static const u8 gUnknown_0860F6BC[] = INCBIN_U8("graphics/unknown/unknown_60F6BC.4bpp"); -static const u8 gUnknown_0860F7BC[] = INCBIN_U8("graphics/unknown/unknown_60F7BC.4bpp"); -static const u8 gUnknown_0860F83C[] = INCBIN_U8("graphics/unknown/unknown_60F83C.4bpp"); -static const u8 gUnknown_0860F93C[] = INCBIN_U8("graphics/unknown/unknown_60F93C.4bpp"); -static const u8 gUnknown_0860FA3C[] = INCBIN_U8("graphics/unknown/unknown_60FA3C.4bpp"); -static const u8 gUnknown_0861023C[] = INCBIN_U8("graphics/unknown/unknown_61023C.bin"); -static const u8 gUnknown_0861033C[] = INCBIN_U8("graphics/unknown/unknown_61033C.4bpp"); -static const u16 gUnknown_0861039C[] = INCBIN_U16("graphics/unknown/unknown_61039C.gbapal"); +static const u16 sPokeballGray_Pal[] = INCBIN_U16("graphics/battle_frontier/factory_screen/pokeball_gray.gbapal"); +static const u16 sPokeballSelected_Pal[] = INCBIN_U16("graphics/battle_frontier/factory_screen/pokeball_selected.gbapal"); +static const u16 sInterface_Pal[] = INCBIN_U16("graphics/battle_frontier/factory_screen/interface.gbapal"); // Arrow, menu/action highlights, action box, etc +static const u8 sPokeball_Gfx[] = INCBIN_U8( "graphics/battle_frontier/factory_screen/pokeball.4bpp"); // Unused, gPokeballSelection_Gfx used instead +static const u8 sArrow_Gfx[] = INCBIN_U8( "graphics/battle_frontier/factory_screen/arrow.4bpp"); +static const u8 sMenuHighlightLeft_Gfx[] = INCBIN_U8( "graphics/battle_frontier/factory_screen/menu_highlight_left.4bpp"); +static const u8 sMenuHighlightRight_Gfx[] = INCBIN_U8( "graphics/battle_frontier/factory_screen/menu_highlight_right.4bpp"); +static const u8 sActionBoxLeft_Gfx[] = INCBIN_U8( "graphics/battle_frontier/factory_screen/action_box_left.4bpp"); +static const u8 sActionBoxRight_Gfx[] = INCBIN_U8( "graphics/battle_frontier/factory_screen/action_box_right.4bpp"); +static const u8 sActionHighlightLeft_Gfx[] = INCBIN_U8( "graphics/battle_frontier/factory_screen/action_highlight_left.4bpp"); +static const u8 sActionHighlightMiddle_Gfx[] = INCBIN_U8( "graphics/battle_frontier/factory_screen/action_highlight_middle.4bpp"); +static const u8 sActionHighlightRight_Gfx[] = INCBIN_U8( "graphics/battle_frontier/factory_screen/action_highlight_right.4bpp"); +static const u8 sMonPicBgAnim_Gfx[] = INCBIN_U8( "graphics/battle_frontier/factory_screen/mon_pic_bg_anim.4bpp"); +static const u8 sMonPicBg_Tilemap[] = INCBIN_U8( "graphics/battle_frontier/factory_screen/mon_pic_bg.bin"); +static const u8 sMonPicBg_Gfx[] = INCBIN_U8( "graphics/battle_frontier/factory_screen/mon_pic_bg.4bpp"); +static const u16 sMonPicBg_Pal[] = INCBIN_U16("graphics/battle_frontier/factory_screen/mon_pic_bg.gbapal"); -static const struct SpriteSheet gUnknown_086103BC[] = +static const struct SpriteSheet sSelect_SpriteSheets[] = { - {gUnknown_0860F3BC, sizeof(gUnknown_0860F3BC), TAG_TILE_65}, - {gUnknown_0860F43C, sizeof(gUnknown_0860F43C), TAG_TILE_66}, - {gUnknown_0860F53C, sizeof(gUnknown_0860F53C), TAG_TILE_67}, - {gUnknown_0860FA3C, sizeof(gUnknown_0860FA3C), TAG_TILE_6D}, + {sArrow_Gfx, sizeof(sArrow_Gfx), GFXTAG_ARROW}, + {sMenuHighlightLeft_Gfx, sizeof(sMenuHighlightLeft_Gfx), GFXTAG_MENU_HIGHLIGHT_LEFT}, + {sMenuHighlightRight_Gfx, sizeof(sMenuHighlightRight_Gfx), GFXTAG_MENU_HIGHLIGHT_RIGHT}, + {sMonPicBgAnim_Gfx, sizeof(sMonPicBgAnim_Gfx), GFXTAG_MON_PIC_BG_ANIM}, {}, }; -static const struct CompressedSpriteSheet gUnknown_086103E4[] = +static const struct CompressedSpriteSheet sSelect_BallGfx[] = { - {gPokeballSelection_Gfx, 0x800, TAG_TILE_64}, + {gPokeballSelection_Gfx, 0x800, GFXTAG_BALL}, {}, }; -static const struct SpritePalette gUnknown_086103F4[] = +static const struct SpritePalette sSelect_SpritePalettes[] = { - {gUnknown_0860F13C, TAG_PAL_BALL_GREY}, - {gUnknown_0860F15C, TAG_PAL_BALL_SELECTED}, - {gUnknown_0860F17C, TAG_PAL_66}, - {gUnknown_0861039C, TAG_PAL_67}, + {sPokeballGray_Pal, PALTAG_BALL_GRAY}, + {sPokeballSelected_Pal, PALTAG_BALL_SELECTED}, + {sInterface_Pal, PALTAG_INTERFACE}, + {sMonPicBg_Pal, PALTAG_MON_PIC_BG}, {}, }; -u8 static (* const sSelect_MenuOptionFuncs[])(void) = +u8 static (* const sSelect_MenuOptionFuncs[SELECTMENU_OPTIONS_COUNT])(void) = { - [MENU_SUMMARY] = Select_OptionSummary, - [MENU_RENT] /*Or Deselect*/ = Select_OptionRentDeselect, - [MENU_OTHERS] = Select_OptionOthers + Select_OptionSummary, + Select_OptionRentDeselect, + Select_OptionOthers }; static const struct BgTemplate sSelect_BgTemplates[] = @@ -372,12 +373,11 @@ static const struct WindowTemplate sSelect_WindowTemplates[] = DUMMY_WIN_TEMPLATE, }; -static const u16 gUnknown_0861046C[] = INCBIN_U16("graphics/unknown/unknown_61046C.gbapal"); - +static const u16 sSelectText_Pal[] = INCBIN_U16("graphics/battle_frontier/factory_screen/text.gbapal"); static const u8 sMenuOptionTextColors[] = {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_DARK_GREY, TEXT_COLOR_TRANSPARENT}; static const u8 sSpeciesNameTextColors[] = {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_RED, TEXT_COLOR_TRANSPARENT}; -static const struct OamData gUnknown_0861047C = +static const struct OamData sOam_Select_Pokeball = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -394,7 +394,7 @@ static const struct OamData gUnknown_0861047C = .affineParam = 0, }; -static const struct OamData gUnknown_08610484 = +static const struct OamData sOam_Select_Arrow = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -411,7 +411,7 @@ static const struct OamData gUnknown_08610484 = .affineParam = 0, }; -static const struct OamData gUnknown_0861048C = +static const struct OamData sOam_Select_MenuHighlight = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -428,7 +428,7 @@ static const struct OamData gUnknown_0861048C = .affineParam = 0, }; -static const struct OamData gUnknown_08610494 = +static const struct OamData sOam_Select_MonPicBgAnim = { .y = 0, .affineMode = ST_OAM_AFFINE_DOUBLE, @@ -445,25 +445,25 @@ static const struct OamData gUnknown_08610494 = .affineParam = 1, }; -static const union AnimCmd gUnknown_0861049C[] = +static const union AnimCmd sAnim_Select_Interface[] = { ANIMCMD_FRAME(0, 1), ANIMCMD_END, }; -static const union AnimCmd gUnknown_086104A4[] = +static const union AnimCmd sAnim_Select_MonPicBgAnim[] = { ANIMCMD_FRAME(0, 1), ANIMCMD_END, }; -static const union AnimCmd gUnknown_086104AC[] = +static const union AnimCmd sAnim_Select_Pokeball_Still[] = { ANIMCMD_FRAME(0, 30), ANIMCMD_END, }; -static const union AnimCmd gUnknown_086104B4[] = +static const union AnimCmd sAnim_Select_Pokeball_Moving[] = { ANIMCMD_FRAME(16, 4), ANIMCMD_FRAME(0, 4), @@ -485,20 +485,20 @@ static const union AnimCmd gUnknown_086104B4[] = ANIMCMD_END, }; -static const union AnimCmd * const gUnknown_086104FC[] = +static const union AnimCmd * const sAnims_Select_Interface[] = { - gUnknown_0861049C, + sAnim_Select_Interface, }; -static const union AnimCmd * const gUnknown_08610500[] = +static const union AnimCmd * const sAnims_Select_MonPicBgAnim[] = { - gUnknown_086104A4, + sAnim_Select_MonPicBgAnim, }; -static const union AnimCmd * const gUnknown_08610504[] = +static const union AnimCmd * const sAnims_Select_Pokeball[] = { - gUnknown_086104AC, - gUnknown_086104B4, + sAnim_Select_Pokeball_Still, + sAnim_Select_Pokeball_Moving, }; static const union AffineAnimCmd gUnknown_0861050C[] = @@ -537,98 +537,98 @@ static const union AffineAnimCmd gUnknown_086105BC[] = AFFINEANIMCMD_END, }; -static const union AffineAnimCmd * const gUnknown_086105CC[] = +static const union AffineAnimCmd * const sAffineAnims_Select_MonPicBgAnim[] = { gUnknown_0861050C, gUnknown_0861056C, gUnknown_086105BC, }; -static const struct SpriteTemplate gUnknown_086105D8 = +static const struct SpriteTemplate sSpriteTemplate_Select_Pokeball = { - .tileTag = TAG_TILE_64, - .paletteTag = TAG_PAL_BALL_GREY, - .oam = &gUnknown_0861047C, - .anims = gUnknown_08610504, + .tileTag = GFXTAG_BALL, + .paletteTag = PALTAG_BALL_GRAY, + .oam = &sOam_Select_Pokeball, + .anims = sAnims_Select_Pokeball, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = sub_819A44C + .callback = SpriteCB_Pokeball }; -static const struct SpriteTemplate gUnknown_086105F0 = +static const struct SpriteTemplate sSpriteTemplate_Select_Arrow = { - .tileTag = TAG_TILE_65, - .paletteTag = TAG_PAL_66, - .oam = &gUnknown_08610484, - .anims = gUnknown_086104FC, + .tileTag = GFXTAG_ARROW, + .paletteTag = PALTAG_INTERFACE, + .oam = &sOam_Select_Arrow, + .anims = sAnims_Select_Interface, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy }; -static const struct SpriteTemplate gUnknown_08610608 = +static const struct SpriteTemplate sSpriteTemplate_Select_MenuHighlightLeft = { - .tileTag = TAG_TILE_66, - .paletteTag = TAG_PAL_66, - .oam = &gUnknown_0861048C, - .anims = gUnknown_086104FC, + .tileTag = GFXTAG_MENU_HIGHLIGHT_LEFT, + .paletteTag = PALTAG_INTERFACE, + .oam = &sOam_Select_MenuHighlight, + .anims = sAnims_Select_Interface, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy }; -static const struct SpriteTemplate gUnknown_08610620 = +static const struct SpriteTemplate sSpriteTemplate_Select_MenuHighlightRight = { - .tileTag = TAG_TILE_67, - .paletteTag = TAG_PAL_66, - .oam = &gUnknown_0861048C, - .anims = gUnknown_086104FC, + .tileTag = GFXTAG_MENU_HIGHLIGHT_RIGHT, + .paletteTag = PALTAG_INTERFACE, + .oam = &sOam_Select_MenuHighlight, + .anims = sAnims_Select_Interface, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy }; -static const struct SpriteTemplate gUnknown_08610638 = +static const struct SpriteTemplate sSpriteTemplate_Select_MonPicBgAnim = { - .tileTag = TAG_TILE_6D, - .paletteTag = TAG_PAL_67, - .oam = &gUnknown_08610494, - .anims = gUnknown_08610500, + .tileTag = GFXTAG_MON_PIC_BG_ANIM, + .paletteTag = PALTAG_MON_PIC_BG, + .oam = &sOam_Select_MonPicBgAnim, + .anims = sAnims_Select_MonPicBgAnim, .images = NULL, - .affineAnims = gUnknown_086105CC, + .affineAnims = sAffineAnims_Select_MonPicBgAnim, .callback = SpriteCallbackDummy }; -static const struct SpriteSheet gUnknown_08610650[] = +static const struct SpriteSheet sSwap_SpriteSheets[] = { - {gUnknown_0860F3BC, sizeof(gUnknown_0860F3BC), TAG_TILE_65}, - {gUnknown_0860F43C, sizeof(gUnknown_0860F43C), TAG_TILE_66}, - {gUnknown_0860F53C, sizeof(gUnknown_0860F53C), TAG_TILE_67}, - {gUnknown_0860F63C, sizeof(gUnknown_0860F63C), TAG_TILE_68}, - {gUnknown_0860F6BC, sizeof(gUnknown_0860F6BC), TAG_TILE_69}, - {gUnknown_0860F7BC, 0x100, TAG_TILE_6A}, - {gUnknown_0860F83C, sizeof(gUnknown_0860F83C), TAG_TILE_6B}, - {gUnknown_0860F93C, sizeof(gUnknown_0860F93C), TAG_TILE_6C}, - {gUnknown_0860FA3C, sizeof(gUnknown_0860FA3C), TAG_TILE_6D}, + {sArrow_Gfx, sizeof(sArrow_Gfx), GFXTAG_ARROW}, + {sMenuHighlightLeft_Gfx, sizeof(sMenuHighlightLeft_Gfx), GFXTAG_MENU_HIGHLIGHT_LEFT}, + {sMenuHighlightRight_Gfx, sizeof(sMenuHighlightRight_Gfx), GFXTAG_MENU_HIGHLIGHT_RIGHT}, + {sActionBoxLeft_Gfx, sizeof(sActionBoxLeft_Gfx), GFXTAG_ACTION_BOX_LEFT}, + {sActionBoxRight_Gfx, sizeof(sActionBoxRight_Gfx), GFXTAG_ACTION_BOX_RIGHT}, + {sActionHighlightLeft_Gfx, 0x100, GFXTAG_ACTION_HIGHLIGHT_LEFT}, + {sActionHighlightMiddle_Gfx, sizeof(sActionHighlightMiddle_Gfx), GFXTAG_ACTION_HIGHLIGHT_MIDDLE}, + {sActionHighlightRight_Gfx, sizeof(sActionHighlightRight_Gfx), GFXTAG_ACTION_HIGHLIGHT_RIGHT}, + {sMonPicBgAnim_Gfx, sizeof(sMonPicBgAnim_Gfx), GFXTAG_MON_PIC_BG_ANIM}, {}, }; -static const struct CompressedSpriteSheet gUnknown_086106A0[] = +static const struct CompressedSpriteSheet sSwap_BallGfx[] = { - {gPokeballSelection_Gfx, 0x800, TAG_TILE_64}, + {gPokeballSelection_Gfx, 0x800, GFXTAG_BALL}, {}, }; -static const struct SpritePalette gUnknown_086106B0[] = +static const struct SpritePalette sSwap_SpritePalettes[] = { - {gUnknown_0860F13C, TAG_PAL_BALL_GREY}, - {gUnknown_0860F15C, TAG_PAL_BALL_SELECTED}, - {gUnknown_0860F17C, TAG_PAL_66}, - {gUnknown_0861039C, TAG_PAL_67}, + {sPokeballGray_Pal, PALTAG_BALL_GRAY}, + {sPokeballSelected_Pal, PALTAG_BALL_SELECTED}, + {sInterface_Pal, PALTAG_INTERFACE}, + {sMonPicBg_Pal, PALTAG_MON_PIC_BG}, {}, }; -static const struct OamData gUnknown_086106D8 = +static const struct OamData sOam_Swap_Pokeball = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -645,7 +645,7 @@ static const struct OamData gUnknown_086106D8 = .affineParam = 0, }; -static const struct OamData gUnknown_086106E0 = +static const struct OamData sOam_Swap_Arrow = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -662,7 +662,7 @@ static const struct OamData gUnknown_086106E0 = .affineParam = 0, }; -static const struct OamData gUnknown_086106E8 = +static const struct OamData sOam_Swap_MenuHighlight = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -696,7 +696,7 @@ static const struct OamData gUnknown_086106F0 = .affineParam = 1, }; -static const union AnimCmd gUnknown_086106F8[] = +static const union AnimCmd sAnim_Swap_Interface[] = { ANIMCMD_FRAME(0, 1), ANIMCMD_END, @@ -708,13 +708,13 @@ static const union AnimCmd gUnknown_08610700[] = ANIMCMD_END, }; -static const union AnimCmd gUnknown_08610708[] = +static const union AnimCmd sAnim_Swap_Pokeball_Still[] = { ANIMCMD_FRAME(0, 30), ANIMCMD_END, }; -static const union AnimCmd gUnknown_08610710[] = +static const union AnimCmd sAnim_Swap_Pokeball_Moving[] = { ANIMCMD_FRAME(16, 4), ANIMCMD_FRAME(0, 4), @@ -736,9 +736,9 @@ static const union AnimCmd gUnknown_08610710[] = ANIMCMD_END, }; -static const union AnimCmd * const gUnknown_08610758[] = +static const union AnimCmd * const sAnims_Swap_Interface[] = { - gUnknown_086106F8, + sAnim_Swap_Interface, }; static const union AnimCmd * const gUnknown_0861075C[] = @@ -746,10 +746,10 @@ static const union AnimCmd * const gUnknown_0861075C[] = gUnknown_08610700, }; -static const union AnimCmd * const gUnknown_08610760[] = +static const union AnimCmd * const sAnims_Swap_Pokeball[] = { - gUnknown_08610708, - gUnknown_08610710, + sAnim_Swap_Pokeball_Still, + sAnim_Swap_Pokeball_Moving, }; static const union AffineAnimCmd gUnknown_08610768[] = @@ -795,54 +795,54 @@ static const union AffineAnimCmd * const gUnknown_08610828[] = gUnknown_08610818, }; -static const struct SpriteTemplate gUnknown_08610834 = +static const struct SpriteTemplate sSpriteTemplate_Swap_Pokeball = { - .tileTag = TAG_TILE_64, - .paletteTag = TAG_PAL_BALL_GREY, - .oam = &gUnknown_086106D8, - .anims = gUnknown_08610760, + .tileTag = GFXTAG_BALL, + .paletteTag = PALTAG_BALL_GRAY, + .oam = &sOam_Swap_Pokeball, + .anims = sAnims_Swap_Pokeball, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = sub_819A44C + .callback = SpriteCB_Pokeball }; -static const struct SpriteTemplate gUnknown_0861084C = +static const struct SpriteTemplate sSpriteTemplate_Swap_Arrow = { - .tileTag = TAG_TILE_65, - .paletteTag = TAG_PAL_66, - .oam = &gUnknown_086106E0, - .anims = gUnknown_08610758, + .tileTag = GFXTAG_ARROW, + .paletteTag = PALTAG_INTERFACE, + .oam = &sOam_Swap_Arrow, + .anims = sAnims_Swap_Interface, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy }; -static const struct SpriteTemplate gUnknown_08610864 = +static const struct SpriteTemplate sSpriteTemplate_Swap_MenuHighlightLeft = { - .tileTag = TAG_TILE_66, - .paletteTag = TAG_PAL_66, - .oam = &gUnknown_086106E8, - .anims = gUnknown_08610758, + .tileTag = GFXTAG_MENU_HIGHLIGHT_LEFT, + .paletteTag = PALTAG_INTERFACE, + .oam = &sOam_Swap_MenuHighlight, + .anims = sAnims_Swap_Interface, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy }; -static const struct SpriteTemplate gUnknown_0861087C = +static const struct SpriteTemplate sSpriteTemplate_Swap_MenuHighlightRight = { - .tileTag = TAG_TILE_67, - .paletteTag = TAG_PAL_66, - .oam = &gUnknown_086106E8, - .anims = gUnknown_08610758, + .tileTag = GFXTAG_MENU_HIGHLIGHT_RIGHT, + .paletteTag = PALTAG_INTERFACE, + .oam = &sOam_Swap_MenuHighlight, + .anims = sAnims_Swap_Interface, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy }; -static const struct SpriteTemplate gUnknown_08610894 = +static const struct SpriteTemplate sSpriteTemplate_Swap_MonPicBgAnim = { - .tileTag = TAG_TILE_6D, - .paletteTag = TAG_PAL_67, + .tileTag = GFXTAG_MON_PIC_BG_ANIM, + .paletteTag = PALTAG_MON_PIC_BG, .oam = &gUnknown_086106F0, .anims = gUnknown_0861075C, .images = NULL, @@ -850,11 +850,11 @@ static const struct SpriteTemplate gUnknown_08610894 = .callback = SpriteCallbackDummy }; -void static (* const sSwap_MenuOptionFuncs[])(u8 taskId) = +void static (* const sSwap_MenuOptionFuncs[SWAPMENU_OPTIONS_COUNT])(u8 taskId) = { - sub_819F114, - sub_819F0CC, - sub_819F134, + Swap_OptionSummary, + Swap_OptionSwap, + Swap_OptionRechoose, }; static const struct BgTemplate sSwap_BgTemplates[4] = @@ -983,25 +983,25 @@ static const struct WindowTemplate sSwap_WindowTemplates[] = DUMMY_WIN_TEMPLATE, }; -static const u16 gUnknown_08610918[] = {RGB_BLACK, RGB_BLACK, RGB_WHITE, RGB_BLACK, RGB_RED}; // Palette. +static const u16 sSwapText_Pal[] = INCBIN_U16("graphics/battle_frontier/factory_screen/text.gbapal"); // Identical to sSelectText_Pal static const u8 sSwapMenuOptionsTextColors[] = {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_DARK_GREY, TEXT_COLOR_TRANSPARENT}; static const u8 sSwapSpeciesNameTextColors[] = {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_RED, TEXT_COLOR_TRANSPARENT}; -static const struct SwapActionIdAndFunc sSwap_PlayerScreenActions[] = +static const struct SwapScreenAction sSwap_PlayerScreenActions[] = { - {1, Swap_ActionMon}, - {1, Swap_ActionMon}, - {1, Swap_ActionMon}, - {3, Swap_ActionCancel}, + {.id = 1, .func = Swap_ActionMon}, + {.id = 1, .func = Swap_ActionMon}, + {.id = 1, .func = Swap_ActionMon}, + {.id = 3, .func = Swap_ActionCancel}, }; -static const struct SwapActionIdAndFunc sSwap_EnemyScreenActions[] = +static const struct SwapScreenAction sSwap_EnemyScreenActions[] = { - {1, Swap_ActionMon}, - {1, Swap_ActionMon}, - {1, Swap_ActionMon}, - {2, Swap_ActionPkmnForSwap}, - {3, Swap_ActionCancel}, + {.id = 1, .func = Swap_ActionMon}, + {.id = 1, .func = Swap_ActionMon}, + {.id = 1, .func = Swap_ActionMon}, + {.id = 2, .func = Swap_ActionPkmnForSwap}, + {.id = 3, .func = Swap_ActionCancel}, }; // gfx @@ -1036,11 +1036,11 @@ extern const u8 gText_PkmnForSwap[]; extern const u8 gText_SamePkmnInPartyAlready[]; extern const u8 gText_Cancel3[]; -// code -static void sub_819A44C(struct Sprite *sprite) +static void SpriteCB_Pokeball(struct Sprite *sprite) { - if (sprite->oam.paletteNum == IndexOfSpritePaletteTag(TAG_PAL_BALL_SELECTED)) + if (sprite->oam.paletteNum == IndexOfSpritePaletteTag(PALTAG_BALL_SELECTED)) { + // Pokeball selected, do rocking animation if (sprite->animEnded) { if (sprite->data[0] != 0) @@ -1064,11 +1064,12 @@ static void sub_819A44C(struct Sprite *sprite) } else { + // Pokeball not selected, remain still StartSpriteAnimIfDifferent(sprite, 0); } } -static void Select_CB2(void) +static void CB2_SelectScreen(void) { AnimateSprites(); BuildOamBuffer(); @@ -1077,7 +1078,7 @@ static void Select_CB2(void) RunTasks(); } -static void Select_VblankCb(void) +static void VBlankCB_SelectScreen(void) { LoadOam(); ProcessSpriteCopyRequests(); @@ -1110,9 +1111,9 @@ static void CB2_InitSelectScreen(void) break; case 1: sSelectMenuTilesetBuffer = Alloc(0x440); - sSelectMonCardBgTilesetBuffer = AllocZeroed(0x440); - sSelectMenuTilemapBuffer = Alloc(0x800); - sSelectMonCardBgTilemapBuffer = AllocZeroed(0x800); + sSelectMonPicBgTilesetBuffer = AllocZeroed(0x440); + sSelectMenuTilemapBuffer = Alloc(BG_SCREEN_SIZE); + sSelectMonPicBgTilemapBuffer = AllocZeroed(BG_SCREEN_SIZE); ChangeBgX(0, 0, 0); ChangeBgY(0, 0, 0); ChangeBgX(1, 0, 0); @@ -1137,34 +1138,34 @@ static void CB2_InitSelectScreen(void) ResetTasks(); FreeAllSpritePalettes(); CpuCopy16(gFrontierFactorySelectMenu_Gfx, sSelectMenuTilesetBuffer, 0x440); - CpuCopy16(gUnknown_0861033C, sSelectMonCardBgTilesetBuffer, 0x60); + CpuCopy16(sMonPicBg_Gfx, sSelectMonPicBgTilesetBuffer, 0x60); LoadBgTiles(1, sSelectMenuTilesetBuffer, 0x440, 0); - LoadBgTiles(3, sSelectMonCardBgTilesetBuffer, 0x60, 0); - CpuCopy16(gFrontierFactorySelectMenu_Tilemap, sSelectMenuTilemapBuffer, 0x800); - LoadBgTilemap(1, sSelectMenuTilemapBuffer, 0x800, 0); + LoadBgTiles(3, sSelectMonPicBgTilesetBuffer, 0x60, 0); + CpuCopy16(gFrontierFactorySelectMenu_Tilemap, sSelectMenuTilemapBuffer, BG_SCREEN_SIZE); + LoadBgTilemap(1, sSelectMenuTilemapBuffer, BG_SCREEN_SIZE, 0); LoadPalette(gFrontierFactorySelectMenu_Pal, 0, 0x40); - LoadPalette(gUnknown_0861046C, 0xF0, 8); - LoadPalette(gUnknown_0861046C, 0xE0, 10); + LoadPalette(sSelectText_Pal, 0xF0, 8); + LoadPalette(sSelectText_Pal, 0xE0, 10); if (sFactorySelectScreen->fromSummaryScreen == TRUE) - gPlttBufferUnfaded[228] = sFactorySelectScreen->unk2A4; - LoadPalette(gUnknown_0861039C, 0x20, 4); + gPlttBufferUnfaded[228] = sFactorySelectScreen->speciesNameColorBackup; + LoadPalette(sMonPicBg_Pal, 0x20, 4); gMain.state++; break; case 3: - SetBgTilemapBuffer(3, sSelectMonCardBgTilemapBuffer); - CopyToBgTilemapBufferRect(3, gUnknown_0861023C, 11, 4, 8, 8); - CopyToBgTilemapBufferRect(3, gUnknown_0861023C, 2, 4, 8, 8); - CopyToBgTilemapBufferRect(3, gUnknown_0861023C, 20, 4, 8, 8); + SetBgTilemapBuffer(3, sSelectMonPicBgTilemapBuffer); + CopyToBgTilemapBufferRect(3, sMonPicBg_Tilemap, 11, 4, 8, 8); + CopyToBgTilemapBufferRect(3, sMonPicBg_Tilemap, 2, 4, 8, 8); + CopyToBgTilemapBufferRect(3, sMonPicBg_Tilemap, 20, 4, 8, 8); CopyBgTilemapBufferToVram(3); gMain.state++; break; case 4: - LoadSpritePalettes(gUnknown_086103F4); - LoadSpriteSheets(gUnknown_086103BC); - LoadCompressedSpriteSheet(gUnknown_086103E4); + LoadSpritePalettes(sSelect_SpritePalettes); + LoadSpriteSheets(sSelect_SpriteSheets); + LoadCompressedSpriteSheet(sSelect_BallGfx); ShowBg(0); ShowBg(1); - SetVBlankCallback(Select_VblankCb); + SetVBlankCallback(VBlankCB_SelectScreen); BeginNormalPaletteFade(0xFFFFFFFF, 0, 0x10, 0, RGB_BLACK); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_BG0_ON | DISPCNT_BG1_ON | DISPCNT_OBJ_1D_MAP); if (sFactorySelectScreen->fromSummaryScreen == TRUE) @@ -1186,7 +1187,7 @@ static void CB2_InitSelectScreen(void) Select_InitMonsData(); Select_InitAllSprites(); if (sFactorySelectScreen->fromSummaryScreen == TRUE) - Select_ShowSummaryMonSprite(); + Select_ReshowMonSprite(); gMain.state++; break; case 6: @@ -1224,7 +1225,7 @@ static void CB2_InitSelectScreen(void) taskId = CreateTask(Task_HandleSelectionScreenMenu, 0); gTasks[taskId].data[0] = 13; } - SetMainCallback2(Select_CB2); + SetMainCallback2(CB2_SelectScreen); break; } } @@ -1256,15 +1257,15 @@ static void Select_InitAllSprites(void) for (i = 0; i < SELECTABLE_MONS_COUNT; i++) { - sFactorySelectScreen->mons[i].spriteId = CreateSprite(&gUnknown_086105D8, (35 * i) + 32, 64, 1); + sFactorySelectScreen->mons[i].spriteId = CreateSprite(&sSpriteTemplate_Select_Pokeball, (35 * i) + 32, 64, 1); gSprites[sFactorySelectScreen->mons[i].spriteId].data[0] = 0; Select_SetBallSpritePaletteNum(i); } cursorPos = sFactorySelectScreen->cursorPos; x = gSprites[sFactorySelectScreen->mons[cursorPos].spriteId].pos1.x; - sFactorySelectScreen->cursorSpriteId = CreateSprite(&gUnknown_086105F0, x, 88, 0); - sFactorySelectScreen->menuCursor1SpriteId = CreateSprite(&gUnknown_08610608, 176, 112, 0); - sFactorySelectScreen->menuCursor2SpriteId = CreateSprite(&gUnknown_08610620, 176, 144, 0); + sFactorySelectScreen->cursorSpriteId = CreateSprite(&sSpriteTemplate_Select_Arrow, x, 88, 0); + sFactorySelectScreen->menuCursor1SpriteId = CreateSprite(&sSpriteTemplate_Select_MenuHighlightLeft, 176, 112, 0); + sFactorySelectScreen->menuCursor2SpriteId = CreateSprite(&sSpriteTemplate_Select_MenuHighlightRight, 176, 144, 0); gSprites[sFactorySelectScreen->menuCursor1SpriteId].invisible = TRUE; gSprites[sFactorySelectScreen->menuCursor2SpriteId].invisible = TRUE; @@ -1313,7 +1314,7 @@ static void Select_UpdateMenuCursorPosition(s8 direction) { if (direction > 0) // Move cursor down. { - if (sFactorySelectScreen->menuCursorPos != MENU_OPTIONS_COUNT - 1) + if (sFactorySelectScreen->menuCursorPos != SELECTMENU_OPTIONS_COUNT - 1) sFactorySelectScreen->menuCursorPos++; else sFactorySelectScreen->menuCursorPos = 0; @@ -1323,7 +1324,7 @@ static void Select_UpdateMenuCursorPosition(s8 direction) if (sFactorySelectScreen->menuCursorPos != 0) sFactorySelectScreen->menuCursorPos--; else - sFactorySelectScreen->menuCursorPos = MENU_OPTIONS_COUNT - 1; + sFactorySelectScreen->menuCursorPos = SELECTMENU_OPTIONS_COUNT - 1; } gSprites[sFactorySelectScreen->menuCursor1SpriteId].pos1.y = (sFactorySelectScreen->menuCursorPos * 16) + 112; @@ -1357,7 +1358,7 @@ static void Select_HandleMonSelectionChange(void) u8 cursorPos = sFactorySelectScreen->cursorPos; if (sFactorySelectScreen->mons[cursorPos].selectedId) // Deselect a mon. { - paletteNum = IndexOfSpritePaletteTag(TAG_PAL_BALL_GREY); + paletteNum = IndexOfSpritePaletteTag(PALTAG_BALL_GRAY); if (sFactorySelectScreen->selectingMonsState == 3 && sFactorySelectScreen->mons[cursorPos].selectedId == 1) { for (i = 0; i < SELECTABLE_MONS_COUNT; i++) @@ -1375,7 +1376,7 @@ static void Select_HandleMonSelectionChange(void) } else // Select a mon. { - paletteNum = IndexOfSpritePaletteTag(TAG_PAL_BALL_SELECTED); + paletteNum = IndexOfSpritePaletteTag(PALTAG_BALL_SELECTED); sFactorySelectScreen->mons[cursorPos].selectedId = sFactorySelectScreen->selectingMonsState; sFactorySelectScreen->selectingMonsState++; } @@ -1388,9 +1389,9 @@ static void Select_SetBallSpritePaletteNum(u8 id) u8 palNum; if (sFactorySelectScreen->mons[id].selectedId) - palNum = IndexOfSpritePaletteTag(TAG_PAL_BALL_SELECTED); + palNum = IndexOfSpritePaletteTag(PALTAG_BALL_SELECTED); else - palNum = IndexOfSpritePaletteTag(TAG_PAL_BALL_GREY); + palNum = IndexOfSpritePaletteTag(PALTAG_BALL_GRAY); gSprites[sFactorySelectScreen->mons[id].spriteId].oam.paletteNum = palNum; } @@ -1414,22 +1415,22 @@ static void Task_FromSelectScreenToSummaryScreen(u8 taskId) sub_819F444(sFactorySelectScreen->unk294[1], &sFactorySelectScreen->unk2A0); Select_DestroyAllSprites(); FREE_AND_SET_NULL(sSelectMenuTilesetBuffer); - FREE_AND_SET_NULL(sSelectMonCardBgTilesetBuffer); + FREE_AND_SET_NULL(sSelectMonPicBgTilesetBuffer); FREE_AND_SET_NULL(sSelectMenuTilemapBuffer); - FREE_AND_SET_NULL(sSelectMonCardBgTilemapBuffer); + FREE_AND_SET_NULL(sSelectMonPicBgTilemapBuffer); FreeAllWindowBuffers(); gTasks[taskId].data[0] = 8; } break; case 8: - sFactorySelectScreen->unk2A4 = gPlttBufferUnfaded[228]; + sFactorySelectScreen->speciesNameColorBackup = gPlttBufferUnfaded[228]; DestroyTask(taskId); sFactorySelectScreen->fromSummaryScreen = TRUE; currMonId = sFactorySelectScreen->cursorPos; sFactorySelectMons = AllocZeroed(sizeof(struct Pokemon) * SELECTABLE_MONS_COUNT); for (i = 0; i < SELECTABLE_MONS_COUNT; i++) sFactorySelectMons[i] = sFactorySelectScreen->mons[i].monData; - ShowPokemonSummaryScreen(1, sFactorySelectMons, currMonId, SELECTABLE_MONS_COUNT - 1, CB2_InitSelectScreen); + ShowPokemonSummaryScreen(PSS_MODE_LOCK_MOVES, sFactorySelectMons, currMonId, SELECTABLE_MONS_COUNT - 1, CB2_InitSelectScreen); break; } } @@ -1452,7 +1453,7 @@ static void Task_CloseSelectionScreen(u8 taskId) Select_DestroyAllSprites(); FREE_AND_SET_NULL(sSelectMenuTilesetBuffer); FREE_AND_SET_NULL(sSelectMenuTilemapBuffer); - FREE_AND_SET_NULL(sSelectMonCardBgTilemapBuffer); + FREE_AND_SET_NULL(sSelectMonPicBgTilemapBuffer); FREE_AND_SET_NULL(sFactorySelectScreen); FreeAllWindowBuffers(); SetMainCallback2(CB2_ReturnToFieldContinueScript); @@ -1590,7 +1591,7 @@ static void Task_HandleSelectionScreenMenu(u8 taskId) { if (sFactorySelectScreen->fromSummaryScreen == TRUE) { - gPlttBufferFaded[228] = sFactorySelectScreen->unk2A4; + gPlttBufferFaded[228] = sFactorySelectScreen->speciesNameColorBackup; gPlttBufferUnfaded[228] = gPlttBufferUnfaded[244]; } sFactorySelectScreen->fromSummaryScreen = FALSE; @@ -1659,7 +1660,7 @@ static void CreateFrontierFactorySelectableMons(u8 firstMonId) u8 i, j = 0; u8 ivs = 0; u8 level = 0; - u8 happiness = 0; + u8 friendship = 0; u32 otId = 0; u8 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); u8 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; @@ -1690,10 +1691,10 @@ static void CreateFrontierFactorySelectableMons(u8 firstMonId) ivs, gFacilityTrainerMons[monId].evSpread, otId); - happiness = 0; + friendship = 0; for (j = 0; j < MAX_MON_MOVES; j++) SetMonMoveAvoidReturn(&sFactorySelectScreen->mons[i + firstMonId].monData, gFacilityTrainerMons[monId].moves[j], j); - SetMonData(&sFactorySelectScreen->mons[i + firstMonId].monData, MON_DATA_FRIENDSHIP, &happiness); + SetMonData(&sFactorySelectScreen->mons[i + firstMonId].monData, MON_DATA_FRIENDSHIP, &friendship); SetMonData(&sFactorySelectScreen->mons[i + firstMonId].monData, MON_DATA_HELD_ITEM, &gBattleFrontierHeldItems[gFacilityTrainerMons[monId].itemTableId]); } } @@ -1703,7 +1704,7 @@ static void CreateTentFactorySelectableMons(u8 firstMonId) u8 i, j; u8 ivs = 0; u8 level = 30; - u8 happiness = 0; + u8 friendship = 0; u32 otId = 0; gFacilityTrainerMons = gSlateportBattleTentMons; @@ -1720,10 +1721,10 @@ static void CreateTentFactorySelectableMons(u8 firstMonId) ivs, gFacilityTrainerMons[monId].evSpread, otId); - happiness = 0; + friendship = 0; for (j = 0; j < MAX_MON_MOVES; j++) SetMonMoveAvoidReturn(&sFactorySelectScreen->mons[i + firstMonId].monData, gFacilityTrainerMons[monId].moves[j], j); - SetMonData(&sFactorySelectScreen->mons[i + firstMonId].monData, MON_DATA_FRIENDSHIP, &happiness); + SetMonData(&sFactorySelectScreen->mons[i + firstMonId].monData, MON_DATA_FRIENDSHIP, &friendship); SetMonData(&sFactorySelectScreen->mons[i + firstMonId].monData, MON_DATA_HELD_ITEM, &gBattleFrontierHeldItems[gFacilityTrainerMons[monId].itemTableId]); } } @@ -1732,7 +1733,7 @@ static void Select_CopyMonsToPlayerParty(void) { u8 i, j; - for (i = 0; i < 3; i++) + for (i = 0; i < FRONTIER_PARTY_SIZE; i++) { for (j = 0; j < SELECTABLE_MONS_COUNT; j++) { @@ -1863,8 +1864,8 @@ static void Select_PrintYesNoOptions(void) static u8 Select_RunMenuOptionFunc(void) { - gUnknown_030062E8 = sSelect_MenuOptionFuncs[sFactorySelectScreen->menuCursorPos]; - return gUnknown_030062E8(); + gFactorySelect_CurrentOptionFunc = sSelect_MenuOptionFuncs[sFactorySelectScreen->menuCursorPos]; + return gFactorySelect_CurrentOptionFunc(); } static u8 Select_OptionRentDeselect(void) @@ -1952,13 +1953,13 @@ static void sub_819BE20(bool8 arg0) sFactorySelectScreen->unk2A0 = arg0; } -static void Select_ShowSummaryMonSprite(void) +static void Select_ReshowMonSprite(void) { struct Pokemon *mon; u16 species; u32 personality, otId; - sFactorySelectScreen->unk294[1].field1 = CreateSprite(&gUnknown_08610638, 120, 64, 1); + sFactorySelectScreen->unk294[1].field1 = CreateSprite(&sSpriteTemplate_Select_MonPicBgAnim, 120, 64, 1); StartSpriteAffineAnim(&gSprites[sFactorySelectScreen->unk294[1].field1], 2); mon = &sFactorySelectScreen->mons[sFactorySelectScreen->cursorPos].monData; @@ -1977,7 +1978,7 @@ static void Select_ShowChosenMonsSprites(void) { u8 i, j; - for (i = 0; i < 3; i++) + for (i = 0; i < FRONTIER_PARTY_SIZE; i++) { for (j = 0; j < SELECTABLE_MONS_COUNT; j++) { @@ -2125,9 +2126,9 @@ static void sub_819C2D4(u8 taskId) static void sub_819C4B4(void) { - sFactorySelectScreen->unk294[1].field1 = CreateSprite(&gUnknown_08610638, 120, 64, 1); - sFactorySelectScreen->unk294[0].field1 = CreateSprite(&gUnknown_08610638, 44, 64, 1); - sFactorySelectScreen->unk294[2].field1 = CreateSprite(&gUnknown_08610638, 196, 64, 1); + sFactorySelectScreen->unk294[1].field1 = CreateSprite(&sSpriteTemplate_Select_MonPicBgAnim, 120, 64, 1); + sFactorySelectScreen->unk294[0].field1 = CreateSprite(&sSpriteTemplate_Select_MonPicBgAnim, 44, 64, 1); + sFactorySelectScreen->unk294[2].field1 = CreateSprite(&sSpriteTemplate_Select_MonPicBgAnim, 196, 64, 1); gSprites[sFactorySelectScreen->unk294[1].field1].callback = sub_819C040; gSprites[sFactorySelectScreen->unk294[0].field1].callback = SpriteCallbackDummy; @@ -2257,13 +2258,13 @@ static void Swap_VblankCb(void) static void CopySwappedMonData(void) { - u8 happiness; + u8 friendship; gPlayerParty[sFactorySwapScreen->playerMonId] = gEnemyParty[sFactorySwapScreen->enemyMonId]; - happiness = 0; - SetMonData(&gPlayerParty[sFactorySwapScreen->playerMonId], MON_DATA_FRIENDSHIP, &happiness); - gSaveBlock2Ptr->frontier.rentalMons[sFactorySwapScreen->playerMonId].monId = gSaveBlock2Ptr->frontier.rentalMons[sFactorySwapScreen->enemyMonId + 3].monId; - gSaveBlock2Ptr->frontier.rentalMons[sFactorySwapScreen->playerMonId].ivs = gSaveBlock2Ptr->frontier.rentalMons[sFactorySwapScreen->enemyMonId + 3].ivs; + friendship = 0; + SetMonData(&gPlayerParty[sFactorySwapScreen->playerMonId], MON_DATA_FRIENDSHIP, &friendship); + gSaveBlock2Ptr->frontier.rentalMons[sFactorySwapScreen->playerMonId].monId = gSaveBlock2Ptr->frontier.rentalMons[sFactorySwapScreen->enemyMonId + FRONTIER_PARTY_SIZE].monId; + gSaveBlock2Ptr->frontier.rentalMons[sFactorySwapScreen->playerMonId].ivs = gSaveBlock2Ptr->frontier.rentalMons[sFactorySwapScreen->enemyMonId + FRONTIER_PARTY_SIZE].ivs; gSaveBlock2Ptr->frontier.rentalMons[sFactorySwapScreen->playerMonId].personality = GetMonData(&gEnemyParty[sFactorySwapScreen->enemyMonId], MON_DATA_PERSONALITY, NULL); gSaveBlock2Ptr->frontier.rentalMons[sFactorySwapScreen->playerMonId].abilityNum = GetBoxMonData(&gEnemyParty[sFactorySwapScreen->enemyMonId].box, MON_DATA_ABILITY_NUM, NULL); } @@ -2283,9 +2284,9 @@ static void Task_FromSwapScreenToSummaryScreen(u8 taskId) sub_819F444(sFactorySwapScreen->unk2C, &sFactorySwapScreen->unk30); Swap_DestroyAllSprites(); FREE_AND_SET_NULL(sSwapMenuTilesetBuffer); - FREE_AND_SET_NULL(sSwapMonCardBgTilesetBuffer); + FREE_AND_SET_NULL(sSwapMonPicBgTilesetBuffer); FREE_AND_SET_NULL(sSwapMenuTilemapBuffer); - FREE_AND_SET_NULL(sSwapMonCardBgTilemapBuffer); + FREE_AND_SET_NULL(sSwapMonPicBgTilemapBuffer); FreeAllWindowBuffers(); gTasks[taskId].data[0] = 8; } @@ -2294,7 +2295,7 @@ static void Task_FromSwapScreenToSummaryScreen(u8 taskId) DestroyTask(taskId); sFactorySwapScreen->fromSummaryScreen = TRUE; sFactorySwapScreen->unk24 = gPlttBufferUnfaded[244]; - ShowPokemonSummaryScreen(0, gPlayerParty, sFactorySwapScreen->cursorPos, 3 - 1, CB2_InitSwapScreen); + ShowPokemonSummaryScreen(PSS_MODE_NORMAL, gPlayerParty, sFactorySwapScreen->cursorPos, FRONTIER_PARTY_SIZE - 1, CB2_InitSwapScreen); break; } } @@ -2306,15 +2307,17 @@ static void Task_CloseSwapScreen(u8 taskId) switch (gTasks[taskId].data[0]) { case 0: + // Set return value for script + // TRUE if player kept their current pokemon if (sFactorySwapScreen->monSwapped == TRUE) { gTasks[taskId].data[0]++; - gSpecialVar_Result = 0; + gSpecialVar_Result = FALSE; } else { gTasks[taskId].data[0] = 2; - gSpecialVar_Result = 1; + gSpecialVar_Result = TRUE; } break; case 1: @@ -2335,9 +2338,9 @@ static void Task_CloseSwapScreen(u8 taskId) DestroyTask(sFactorySwapScreen->fadeSpeciesNameTaskId); Swap_DestroyAllSprites(); FREE_AND_SET_NULL(sSwapMenuTilesetBuffer); - FREE_AND_SET_NULL(sSwapMonCardBgTilesetBuffer); + FREE_AND_SET_NULL(sSwapMonPicBgTilesetBuffer); FREE_AND_SET_NULL(sSwapMenuTilemapBuffer); - FREE_AND_SET_NULL(sSwapMonCardBgTilemapBuffer); + FREE_AND_SET_NULL(sSwapMonPicBgTilemapBuffer); FREE_AND_SET_NULL(sFactorySwapScreen); FreeAllWindowBuffers(); SetMainCallback2(CB2_ReturnToFieldContinueScript); @@ -2676,9 +2679,9 @@ static void sub_819D12C(u8 taskId) break; case 1: var_2C = 0; - for (i = 2; i >= 0; i--) + for (i = FRONTIER_PARTY_SIZE - 1; i >= 0; i--) { - if (i != 2) + if (i != FRONTIER_PARTY_SIZE - 1) { u8 posX = var_2C - gSprites[sFactorySwapScreen->ballSpriteIds[i]].pos1.x; if (posX == 16 || gTasks[taskId].data[i + 2] == 1) @@ -2723,9 +2726,9 @@ static void sub_819D12C(u8 taskId) var_2C = gSprites[sFactorySwapScreen->ballSpriteIds[i]].pos1.x; gSprites[sFactorySwapScreen->ballSpriteIds[i]].pos1.x = -16; if (sFactorySwapScreen->inEnemyScreen == TRUE) - gSprites[sFactorySwapScreen->ballSpriteIds[i]].oam.paletteNum = IndexOfSpritePaletteTag(TAG_PAL_BALL_SELECTED); + gSprites[sFactorySwapScreen->ballSpriteIds[i]].oam.paletteNum = IndexOfSpritePaletteTag(PALTAG_BALL_SELECTED); else - gSprites[sFactorySwapScreen->ballSpriteIds[i]].oam.paletteNum = IndexOfSpritePaletteTag(TAG_PAL_BALL_GREY); + gSprites[sFactorySwapScreen->ballSpriteIds[i]].oam.paletteNum = IndexOfSpritePaletteTag(PALTAG_BALL_GRAY); gTasks[taskId].data[i + 1] = 1; } @@ -2856,7 +2859,7 @@ static void sub_819D588(u8 taskId) switch (gTasks[taskId].data[0]) { case 0: - LoadPalette(gUnknown_08610918, 0xE0, sizeof(gUnknown_08610918)); + LoadPalette(sSwapText_Pal, 0xE0, sizeof(sSwapText_Pal)); Swap_PrintActionStrings(); PutWindowTilemap(5); gTasks[taskId].data[0]++; @@ -2866,7 +2869,7 @@ static void sub_819D588(u8 taskId) gTasks[taskId].data[0]++; break; case 2: - BeginNormalPaletteFade(0x4000, 0, 0, 0x10, gUnknown_0860F13C[37]); + BeginNormalPaletteFade(0x4000, 0, 0, 0x10, sPokeballGray_Pal[37]); gTasks[taskId].data[0]++; break; case 3: @@ -2978,14 +2981,14 @@ static void sub_819D770(u8 taskId) case 2: if (gTasks[taskId].data[3] == 1 && gTasks[taskId].data[4] == 1) { - gPlttBufferFaded[226] = gUnknown_0860F13C[37]; + gPlttBufferFaded[226] = sPokeballGray_Pal[37]; Swap_PrintActionStrings(); PutWindowTilemap(5); gTasks[taskId].data[0]++; } break; case 3: - BeginNormalPaletteFade(0x4000, 0, 0x10, 0, gUnknown_0860F13C[37]); + BeginNormalPaletteFade(0x4000, 0, 0x10, 0, sPokeballGray_Pal[37]); gTasks[taskId].data[0]++; break; case 4: @@ -3010,7 +3013,7 @@ static void sub_819D770(u8 taskId) Swap_PrintOnInfoWindow(gText_SelectPkmnToSwap); else Swap_PrintOnInfoWindow(gText_SelectPkmnToAccept); - if (sFactorySwapScreen->cursorPos < 3) + if (sFactorySwapScreen->cursorPos < FRONTIER_PARTY_SIZE) gSprites[sFactorySwapScreen->cursorSpriteId].invisible = FALSE; Swap_PrintMonCategory(); gTasks[taskId].data[0]++; @@ -3117,9 +3120,9 @@ static void CB2_InitSwapScreen(void) break; case 1: sSwapMenuTilesetBuffer = Alloc(0x440); - sSwapMonCardBgTilesetBuffer = AllocZeroed(0x440); - sSwapMenuTilemapBuffer = Alloc(0x800); - sSwapMonCardBgTilemapBuffer = AllocZeroed(0x800); + sSwapMonPicBgTilesetBuffer = AllocZeroed(0x440); + sSwapMenuTilemapBuffer = Alloc(BG_SCREEN_SIZE); + sSwapMonPicBgTilemapBuffer = AllocZeroed(BG_SCREEN_SIZE); ChangeBgX(0, 0, 0); ChangeBgY(0, 0, 0); ChangeBgX(1, 0, 0); @@ -3145,27 +3148,27 @@ static void CB2_InitSwapScreen(void) FreeAllSpritePalettes(); ResetAllPicSprites(); CpuCopy16(gFrontierFactorySelectMenu_Gfx, sSwapMenuTilesetBuffer, 0x440); - CpuCopy16(gUnknown_0861033C, sSwapMonCardBgTilesetBuffer, 0x60); + CpuCopy16(sMonPicBg_Gfx, sSwapMonPicBgTilesetBuffer, 0x60); LoadBgTiles(1, sSwapMenuTilesetBuffer, 0x440, 0); - LoadBgTiles(3, sSwapMonCardBgTilesetBuffer, 0x60, 0); - CpuCopy16(gFrontierFactorySelectMenu_Tilemap, sSwapMenuTilemapBuffer, 0x800); - LoadBgTilemap(1, sSwapMenuTilemapBuffer, 0x800, 0); + LoadBgTiles(3, sSwapMonPicBgTilesetBuffer, 0x60, 0); + CpuCopy16(gFrontierFactorySelectMenu_Tilemap, sSwapMenuTilemapBuffer, BG_SCREEN_SIZE); + LoadBgTilemap(1, sSwapMenuTilemapBuffer, BG_SCREEN_SIZE, 0); LoadPalette(gFrontierFactorySelectMenu_Pal, 0, 0x40); - LoadPalette(gUnknown_08610918, 0xF0, sizeof(gUnknown_08610918)); - LoadPalette(gUnknown_08610918, 0xE0, sizeof(gUnknown_08610918)); - LoadPalette(gUnknown_0861039C, 0x20, 4); + LoadPalette(sSwapText_Pal, 0xF0, sizeof(sSwapText_Pal)); + LoadPalette(sSwapText_Pal, 0xE0, sizeof(sSwapText_Pal)); + LoadPalette(sMonPicBg_Pal, 0x20, 4); gMain.state++; break; case 3: - SetBgTilemapBuffer(3, sSwapMonCardBgTilemapBuffer); - CopyToBgTilemapBufferRect(3, gUnknown_0861023C, 11, 4, 8, 8); + SetBgTilemapBuffer(3, sSwapMonPicBgTilemapBuffer); + CopyToBgTilemapBufferRect(3, sMonPicBg_Tilemap, 11, 4, 8, 8); CopyBgTilemapBufferToVram(3); gMain.state++; break; case 4: - LoadSpritePalettes(gUnknown_086106B0); - LoadSpriteSheets(gUnknown_08610650); - LoadCompressedSpriteSheet(gUnknown_086106A0); + LoadSpritePalettes(sSwap_SpritePalettes); + LoadSpriteSheets(sSwap_SpriteSheets); + LoadCompressedSpriteSheet(sSwap_BallGfx); SetVBlankCallback(Swap_VblankCb); gMain.state++; break; @@ -3261,17 +3264,17 @@ static void Swap_InitAllSprites(void) u8 x; struct SpriteTemplate spriteTemplate; - spriteTemplate = gUnknown_08610834; - spriteTemplate.paletteTag = TAG_PAL_BALL_SELECTED; + spriteTemplate = sSpriteTemplate_Swap_Pokeball; + spriteTemplate.paletteTag = PALTAG_BALL_SELECTED; - for (i = 0; i < 3; i++) + for (i = 0; i < FRONTIER_PARTY_SIZE; i++) { sFactorySwapScreen->ballSpriteIds[i] = CreateSprite(&spriteTemplate, (48 * i) + 72, 64, 1); gSprites[sFactorySwapScreen->ballSpriteIds[i]].data[0] = 0; } - sFactorySwapScreen->cursorSpriteId = CreateSprite(&gUnknown_0861084C, gSprites[sFactorySwapScreen->ballSpriteIds[sFactorySwapScreen->cursorPos]].pos1.x, 88, 0); - sFactorySwapScreen->menuCursor1SpriteId = CreateSprite(&gUnknown_08610864, 176, 112, 0); - sFactorySwapScreen->menuCursor2SpriteId = CreateSprite(&gUnknown_0861087C, 176, 144, 0); + sFactorySwapScreen->cursorSpriteId = CreateSprite(&sSpriteTemplate_Swap_Arrow, gSprites[sFactorySwapScreen->ballSpriteIds[sFactorySwapScreen->cursorPos]].pos1.x, 88, 0); + sFactorySwapScreen->menuCursor1SpriteId = CreateSprite(&sSpriteTemplate_Swap_MenuHighlightLeft, 176, 112, 0); + sFactorySwapScreen->menuCursor2SpriteId = CreateSprite(&sSpriteTemplate_Swap_MenuHighlightRight, 176, 144, 0); gSprites[sFactorySwapScreen->menuCursor1SpriteId].invisible = TRUE; gSprites[sFactorySwapScreen->menuCursor2SpriteId].invisible = TRUE; gSprites[sFactorySwapScreen->menuCursor1SpriteId].centerToCornerVecX = 0; @@ -3284,39 +3287,42 @@ static void Swap_InitAllSprites(void) else x = 192; - spriteTemplate = gUnknown_0861084C; - spriteTemplate.tileTag = TAG_TILE_68; + // Unusual way to create sprites + // The sprite template for the selector arrow is re-used + // with the tiles swapped out + spriteTemplate = sSpriteTemplate_Swap_Arrow; + spriteTemplate.tileTag = GFXTAG_ACTION_BOX_LEFT; sFactorySwapScreen->unk8[0][0] = CreateSprite(&spriteTemplate, 240, 120, 10); - spriteTemplate = gUnknown_08610864; - spriteTemplate.tileTag = TAG_TILE_69; + spriteTemplate = sSpriteTemplate_Swap_MenuHighlightLeft; + spriteTemplate.tileTag = GFXTAG_ACTION_BOX_RIGHT; sFactorySwapScreen->unk8[0][1] = CreateSprite(&spriteTemplate, 256, 120, 10); sFactorySwapScreen->unk8[0][2] = CreateSprite(&spriteTemplate, 288, 120, 10); - spriteTemplate = gUnknown_0861084C; - spriteTemplate.tileTag = TAG_TILE_6A; + spriteTemplate = sSpriteTemplate_Swap_Arrow; + spriteTemplate.tileTag = GFXTAG_ACTION_HIGHLIGHT_LEFT; sFactorySwapScreen->unk8[1][0] = CreateSprite(&spriteTemplate, 240, 120, 1); - spriteTemplate = gUnknown_08610864; - spriteTemplate.tileTag = TAG_TILE_6B; + spriteTemplate = sSpriteTemplate_Swap_MenuHighlightLeft; + spriteTemplate.tileTag = GFXTAG_ACTION_HIGHLIGHT_MIDDLE; sFactorySwapScreen->unk8[1][1] = CreateSprite(&spriteTemplate, 256, 120, 1); - spriteTemplate.tileTag = TAG_TILE_6C; + spriteTemplate.tileTag = GFXTAG_ACTION_HIGHLIGHT_RIGHT; sFactorySwapScreen->unk8[1][2] = CreateSprite(&spriteTemplate, 288, 120, 1); - spriteTemplate = gUnknown_0861084C; - spriteTemplate.tileTag = TAG_TILE_68; + spriteTemplate = sSpriteTemplate_Swap_Arrow; + spriteTemplate.tileTag = GFXTAG_ACTION_BOX_LEFT; sFactorySwapScreen->unkE[0][0] = CreateSprite(&spriteTemplate, x, 144, 10); - spriteTemplate = gUnknown_08610864; - spriteTemplate.tileTag = TAG_TILE_69; + spriteTemplate = sSpriteTemplate_Swap_MenuHighlightLeft; + spriteTemplate.tileTag = GFXTAG_ACTION_BOX_RIGHT; sFactorySwapScreen->unkE[0][1] = CreateSprite(&spriteTemplate, x + 16, 144, 10); - spriteTemplate = gUnknown_0861084C; - spriteTemplate.tileTag = TAG_TILE_6A; + spriteTemplate = sSpriteTemplate_Swap_Arrow; + spriteTemplate.tileTag = GFXTAG_ACTION_HIGHLIGHT_LEFT; sFactorySwapScreen->unkE[1][0] = CreateSprite(&spriteTemplate, x, 144, 1); - spriteTemplate = gUnknown_08610864; - spriteTemplate.tileTag = TAG_TILE_6C; + spriteTemplate = sSpriteTemplate_Swap_MenuHighlightLeft; + spriteTemplate.tileTag = GFXTAG_ACTION_HIGHLIGHT_RIGHT; sFactorySwapScreen->unkE[1][1] = CreateSprite(&spriteTemplate, x + 16, 144, 1); for (i = 0; i < 2; i++) @@ -3350,7 +3356,7 @@ static void Swap_DestroyAllSprites(void) { u8 i, j; - for (i = 0; i < 3; i++) + for (i = 0; i < FRONTIER_PARTY_SIZE; i++) DestroySprite(&gSprites[sFactorySwapScreen->ballSpriteIds[i]]); DestroySprite(&gSprites[sFactorySwapScreen->cursorSpriteId]); DestroySprite(&gSprites[sFactorySwapScreen->menuCursor1SpriteId]); @@ -3369,7 +3375,7 @@ static void Swap_DestroyAllSprites(void) static void Swap_HandleActionCursorChange(u8 cursorId) { - if (cursorId < 3) + if (cursorId < FRONTIER_PARTY_SIZE) { gSprites[sFactorySwapScreen->cursorSpriteId].invisible = FALSE; sub_819E8EC(); @@ -3411,8 +3417,8 @@ static void Swap_UpdateActionCursorPosition(s8 direction) PlaySE(SE_SELECT); if (direction > 0) // Move cursor down. { - if (sFactorySwapScreen->cursorPos < 3) - sFactorySwapScreen->cursorPos = 3; + if (sFactorySwapScreen->cursorPos < FRONTIER_PARTY_SIZE) + sFactorySwapScreen->cursorPos = FRONTIER_PARTY_SIZE; else if (sFactorySwapScreen->cursorPos + 1 != sFactorySwapScreen->actionsCount) sFactorySwapScreen->cursorPos++; else @@ -3420,7 +3426,7 @@ static void Swap_UpdateActionCursorPosition(s8 direction) } else // Move cursor up. { - if (sFactorySwapScreen->cursorPos < 3) + if (sFactorySwapScreen->cursorPos < FRONTIER_PARTY_SIZE) sFactorySwapScreen->cursorPos = sFactorySwapScreen->actionsCount - 1; else if (sFactorySwapScreen->cursorPos != 0) sFactorySwapScreen->cursorPos--; @@ -3458,7 +3464,7 @@ static void Swap_UpdateMenuCursorPosition(s8 direction) PlaySE(SE_SELECT); if (direction > 0) // Move cursor down. { - if (sFactorySwapScreen->menuCursorPos != MENU_OPTIONS_COUNT - 1) + if (sFactorySwapScreen->menuCursorPos != SWAPMENU_OPTIONS_COUNT - 1) sFactorySwapScreen->menuCursorPos++; else sFactorySwapScreen->menuCursorPos = 0; @@ -3468,7 +3474,7 @@ static void Swap_UpdateMenuCursorPosition(s8 direction) if (sFactorySwapScreen->menuCursorPos != 0) sFactorySwapScreen->menuCursorPos--; else - sFactorySwapScreen->menuCursorPos = MENU_OPTIONS_COUNT - 1; + sFactorySwapScreen->menuCursorPos = SWAPMENU_OPTIONS_COUNT - 1; } gSprites[sFactorySwapScreen->menuCursor1SpriteId].pos1.y = (sFactorySwapScreen->menuCursorPos * 16) + 112; @@ -3585,7 +3591,7 @@ static void Swap_PrintMonSpecies(void) u8 x; FillWindowPixelBuffer(1, PIXEL_FILL(0)); - if (sFactorySwapScreen->cursorPos > 2) + if (sFactorySwapScreen->cursorPos >= FRONTIER_PARTY_SIZE) { CopyWindowToVram(1, 2); } @@ -3684,16 +3690,16 @@ static void Swap_PrintMonSpecies2(void) u8 x; u16 pal[5]; - CpuCopy16(gUnknown_08610918, pal, 8); + CpuCopy16(sSwapText_Pal, pal, 8); if (!sFactorySwapScreen->fromSummaryScreen) pal[4] = gPlttBufferFaded[228]; else pal[4] = sFactorySwapScreen->unk24; - LoadPalette(pal, 0xF0, 0xA); + LoadPalette(pal, 0xF0, sizeof(sSwapText_Pal)); PutWindowTilemap(7); FillWindowPixelBuffer(7, PIXEL_FILL(0)); - if (sFactorySwapScreen->cursorPos > 2) + if (sFactorySwapScreen->cursorPos >= FRONTIER_PARTY_SIZE) { CopyWindowToVram(7, 3); } @@ -3716,10 +3722,10 @@ static void Swap_PrintMonSpecies3(void) u16 species; u8 x; - LoadPalette(gUnknown_08610918, 0xE0, sizeof(gUnknown_08610918)); + LoadPalette(sSwapText_Pal, 0xE0, sizeof(sSwapText_Pal)); CpuCopy16(gPlttBufferUnfaded + 240, gPlttBufferFaded + 224, 10); - if (sFactorySwapScreen->cursorPos > 2) + if (sFactorySwapScreen->cursorPos >= FRONTIER_PARTY_SIZE) { CopyWindowToVram(1, 2); } @@ -3745,7 +3751,7 @@ static void Swap_PrintMonCategory(void) u8 monId = sFactorySwapScreen->cursorPos; FillWindowPixelBuffer(8, PIXEL_FILL(0)); - if (monId > 2) + if (monId >= FRONTIER_PARTY_SIZE) { CopyWindowToVram(8, 2); } @@ -3787,11 +3793,11 @@ static void Swap_InitActions(u8 id) static void Swap_RunMenuOptionFunc(u8 taskId) { - sSwap_CurrentTableFunc = sSwap_MenuOptionFuncs[sFactorySwapScreen->menuCursorPos]; - sSwap_CurrentTableFunc(taskId); + sSwap_CurrentOptionFunc = sSwap_MenuOptionFuncs[sFactorySwapScreen->menuCursorPos]; + sSwap_CurrentOptionFunc(taskId); } -static void sub_819F0CC(u8 taskId) +static void Swap_OptionSwap(u8 taskId) { sub_819F3F8(sFactorySwapScreen->unk2C, &sFactorySwapScreen->unk30, TRUE); sFactorySwapScreen->playerMonId = sFactorySwapScreen->cursorPos; @@ -3800,13 +3806,13 @@ static void sub_819F0CC(u8 taskId) gTasks[taskId].func = sub_819D9EC; } -static void sub_819F114(u8 taskId) +static void Swap_OptionSummary(u8 taskId) { gTasks[taskId].data[0] = 6; gTasks[taskId].func = Task_FromSwapScreenToSummaryScreen; } -static void sub_819F134(u8 taskId) +static void Swap_OptionRechoose(u8 taskId) { sub_819F3F8(sFactorySwapScreen->unk2C, &sFactorySwapScreen->unk30, TRUE); sub_819EA64(3); @@ -3819,8 +3825,8 @@ static void sub_819F134(u8 taskId) static void Swap_RunActionFunc(u8 taskId) { - sSwap_CurrentTableFunc = sFactorySwapScreen->actionsData[sFactorySwapScreen->cursorPos].func; - sSwap_CurrentTableFunc(taskId); + sSwap_CurrentOptionFunc = sFactorySwapScreen->actionsData[sFactorySwapScreen->cursorPos].func; + sSwap_CurrentOptionFunc(taskId); } static void Swap_ActionCancel(u8 taskId) @@ -3869,7 +3875,7 @@ static void Swap_ActionMon(u8 taskId) static void sub_819F2B4(u8 *arg0, bool8 *arg1, bool8 swapScreen) { - *arg0 = CreateSprite(&gUnknown_08610894, 120, 64, 1); + *arg0 = CreateSprite(&sSpriteTemplate_Swap_MonPicBgAnim, 120, 64, 1); gSprites[*arg0].callback = sub_819F600; gSprites[*arg0].data[7] = swapScreen; *arg1 = TRUE; @@ -3881,7 +3887,7 @@ static void Swap_ShowSummaryMonSprite(void) u16 species; u32 personality, otId; - sFactorySwapScreen->unk2C.field1 = CreateSprite(&gUnknown_08610894, 120, 64, 1); + sFactorySwapScreen->unk2C.field1 = CreateSprite(&sSpriteTemplate_Swap_MonPicBgAnim, 120, 64, 1); StartSpriteAffineAnim(&gSprites[sFactorySwapScreen->unk2C.field1], 2); mon = &gPlayerParty[sFactorySwapScreen->cursorPos]; @@ -3963,7 +3969,7 @@ static bool8 Swap_AlreadyHasSameSpecies(u8 monId) u8 i; u16 species = GetMonData(&gEnemyParty[monId], MON_DATA_SPECIES, NULL); - for (i = 0; i < 3; i++) + for (i = 0; i < FRONTIER_PARTY_SIZE; i++) { if (i != sFactorySwapScreen->playerMonId && (u16)(GetMonData(&gPlayerParty[i], MON_DATA_SPECIES, NULL)) == species) return TRUE; From adcffd3f0e8e9fd5192bc257ac44cd94e40afb1c Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 3 Sep 2020 01:19:08 -0400 Subject: [PATCH 2/6] WIP More factory screen doc --- src/battle_factory_screen.c | 79 ++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 36 deletions(-) diff --git a/src/battle_factory_screen.c b/src/battle_factory_screen.c index 379c03613..46e2fa28c 100644 --- a/src/battle_factory_screen.c +++ b/src/battle_factory_screen.c @@ -165,7 +165,7 @@ static void Select_SetBallSpritePaletteNum(u8 id); static void sub_819F444(struct UnkFactoryStruct arg0, bool8 *arg1); static void sub_819B958(u8 windowId); static void sub_819F2B4(u8 *arg0, bool8 *arg1, bool8 swapScreen); -static void sub_819F3F8(struct UnkFactoryStruct arg0, bool8 *arg1, bool8 swapScreen); +static void CloseMonPic(struct UnkFactoryStruct arg0, bool8 *arg1, bool8 swapScreen); static u8 Select_RunMenuOptionFunc(void); static u8 sub_819BC9C(void); static u8 Select_OptionSummary(void); @@ -182,7 +182,7 @@ static void sub_819EA64(u8 windowId); static void sub_819D770(u8 taskId); static void Task_HandleSwapScreenChooseMons(u8 taskId); static void sub_819D588(u8 taskId); -static void sub_819F7B4(u8 taskId); +static void Task_CloseMonPic(u8 taskId); static void Swap_PrintOnInfoWindow(const u8 *str); static void Swap_ShowMenuOptions(void); static void Swap_PrintMenuOptions(void); @@ -204,16 +204,16 @@ static void Swap_OptionSwap(u8 taskId); static void Swap_OptionSummary(u8 taskId); static void Swap_OptionRechoose(u8 taskId); static void Swap_RunActionFunc(u8 taskId); -static void sub_819F69C(u8 taskId); +static void Task_OpenMonPic(u8 taskId); static void Task_SwapCantHaveSameMons(u8 taskId); -static void Swap_ShowMonSprite(void); +static void Swap_CreateMonSprite(void); static void Swap_PrintActionStrings(void); static void Swap_PrintActionStrings2(void); static void Swap_PrintOneActionString(u8 which); static void Swap_InitActions(u8 id); static void sub_819E838(u8 arg0); static bool8 Swap_AlreadyHasSameSpecies(u8 monId); -static void sub_819F600(struct Sprite *sprite); +static void SpriteCB_OpenMonPic(struct Sprite *sprite); static void Swap_ActionMon(u8 taskId); static void Swap_ActionCancel(u8 taskId); static void Swap_ActionPkmnForSwap(u8 taskId); @@ -1569,7 +1569,7 @@ static void Task_HandleSelectionScreenMenu(u8 taskId) else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); - sub_819F3F8(sFactorySelectScreen->unk294[1], &sFactorySelectScreen->unk2A0, FALSE); + CloseMonPic(sFactorySelectScreen->unk294[1], &sFactorySelectScreen->unk2A0, FALSE); sub_819B958(3); sFactorySelectScreen->unk2A2 = TRUE; gTasks[taskId].data[0] = 1; @@ -1645,7 +1645,7 @@ static void Task_HandleSelectionScreenChooseMons(u8 taskId) if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); - sub_819F3F8(sFactorySelectScreen->unk294[1], &sFactorySelectScreen->unk2A0, FALSE); + CloseMonPic(sFactorySelectScreen->unk294[1], &sFactorySelectScreen->unk2A0, FALSE); Select_PrintSelectMonString(); sFactorySelectScreen->unk2A2 = TRUE; gTasks[taskId].data[0] = 1; @@ -1880,7 +1880,7 @@ static u8 Select_OptionRentDeselect(void) } else { - sub_819F3F8(sFactorySelectScreen->unk294[1], &sFactorySelectScreen->unk2A0, FALSE); + CloseMonPic(sFactorySelectScreen->unk294[1], &sFactorySelectScreen->unk2A0, FALSE); Select_HandleMonSelectionChange(); Select_PrintSelectMonString(); sub_819B958(3); @@ -1910,7 +1910,7 @@ static u8 Select_OptionSummary(void) static u8 Select_OptionOthers(void) { - sub_819F3F8(sFactorySelectScreen->unk294[1], &sFactorySelectScreen->unk2A0, FALSE); + CloseMonPic(sFactorySelectScreen->unk294[1], &sFactorySelectScreen->unk2A0, FALSE); sub_819B958(3); return 1; } @@ -1933,7 +1933,7 @@ static void Select_PrintMonCategory(void) } } -static void Summary_ShowMonSprite(void) +static void Summary_CreateMonSprite(void) { u8 monId = sFactorySelectScreen->cursorPos; struct Pokemon *mon = &sFactorySelectScreen->mons[monId].monData; @@ -2439,7 +2439,7 @@ static void sub_819CC24(u8 taskId) static void sub_819CC74(u8 taskId) { - sub_819F3F8(sFactorySwapScreen->unk2C, &sFactorySwapScreen->unk30, TRUE); + CloseMonPic(sFactorySwapScreen->unk2C, &sFactorySwapScreen->unk30, TRUE); if (gTasks[taskId].data[1] == 1) { gTasks[taskId].data[0] = 0; @@ -2496,7 +2496,7 @@ static void Task_HandleSwapScreenMenu(u8 taskId) else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); - sub_819F3F8(sFactorySwapScreen->unk2C, &sFactorySwapScreen->unk30, TRUE); + CloseMonPic(sFactorySwapScreen->unk2C, &sFactorySwapScreen->unk30, TRUE); sub_819EA64(3); gTasks[taskId].data[0] = 0; gTasks[taskId].data[6] = (u32)(Task_HandleSwapScreenChooseMons) >> 16; @@ -3799,7 +3799,7 @@ static void Swap_RunMenuOptionFunc(u8 taskId) static void Swap_OptionSwap(u8 taskId) { - sub_819F3F8(sFactorySwapScreen->unk2C, &sFactorySwapScreen->unk30, TRUE); + CloseMonPic(sFactorySwapScreen->unk2C, &sFactorySwapScreen->unk30, TRUE); sFactorySwapScreen->playerMonId = sFactorySwapScreen->cursorPos; sub_819EA64(3); gTasks[taskId].data[0] = 0; @@ -3814,7 +3814,7 @@ static void Swap_OptionSummary(u8 taskId) static void Swap_OptionRechoose(u8 taskId) { - sub_819F3F8(sFactorySwapScreen->unk2C, &sFactorySwapScreen->unk30, TRUE); + CloseMonPic(sFactorySwapScreen->unk2C, &sFactorySwapScreen->unk30, TRUE); sub_819EA64(3); gTasks[taskId].data[0] = 0; gTasks[taskId].data[6] = (u32)(Task_HandleSwapScreenChooseMons) >> 0x10; @@ -3876,7 +3876,7 @@ static void Swap_ActionMon(u8 taskId) static void sub_819F2B4(u8 *arg0, bool8 *arg1, bool8 swapScreen) { *arg0 = CreateSprite(&sSpriteTemplate_Swap_MonPicBgAnim, 120, 64, 1); - gSprites[*arg0].callback = sub_819F600; + gSprites[*arg0].callback = SpriteCB_OpenMonPic; gSprites[*arg0].data[7] = swapScreen; *arg1 = TRUE; } @@ -3902,13 +3902,20 @@ static void Swap_ShowSummaryMonSprite(void) gSprites[sFactorySwapScreen->unk2C.field1].invisible = TRUE; } -static void sub_819F3F8(struct UnkFactoryStruct arg0, bool8 *arg1, bool8 swapScreen) +#define tState data[0] +#define tWinLeft data[3] +#define tWinRight data[24] // UB: Copied typo? Should be data[4], 24 is out of bounds +#define tWinTop data[5] +#define tWinBottom data[8] +#define tIsSwapScreen data[7] + +static void CloseMonPic(struct UnkFactoryStruct arg0, bool8 *arg1, bool8 swapScreen) { u8 taskId; FreeAndDestroyMonPicSprite(arg0.field0); - taskId = CreateTask(sub_819F7B4, 1); - gTasks[taskId].data[7] = swapScreen; + taskId = CreateTask(Task_CloseMonPic, 1); + gTasks[taskId].tIsSwapScreen = swapScreen; gTasks[taskId].data[6] = arg0.field1; gTasks[taskId].func(taskId); *arg1 = TRUE; @@ -3938,7 +3945,7 @@ static void Task_SwapCantHaveSameMons(u8 taskId) if (gMain.newKeys & A_BUTTON || gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); - sub_819F3F8(sFactorySwapScreen->unk2C, &sFactorySwapScreen->unk30, TRUE); + CloseMonPic(sFactorySwapScreen->unk2C, &sFactorySwapScreen->unk30, TRUE); gTasks[taskId].data[0]++; } break; @@ -3977,15 +3984,15 @@ static bool8 Swap_AlreadyHasSameSpecies(u8 monId) return FALSE; } -static void sub_819F600(struct Sprite *sprite) +static void SpriteCB_OpenMonPic(struct Sprite *sprite) { u8 taskId; if (sprite->affineAnimEnded) { sprite->invisible = TRUE; - taskId = CreateTask(sub_819F69C, 1); - gTasks[taskId].data[7] = sprite->data[7]; + taskId = CreateTask(Task_OpenMonPic, 1); + gTasks[taskId].tIsSwapScreen = sprite->data[7]; gTasks[taskId].func(taskId); sprite->callback = SpriteCallbackDummy; } @@ -4004,18 +4011,18 @@ static void sub_819F654(struct Sprite *sprite) } } -static void sub_819F69C(u8 taskId) +static void Task_OpenMonPic(u8 taskId) { struct Task *task = &gTasks[taskId]; switch (task->data[0]) { case 0: - task->data[3] = 88; - task->data[24] = 152; // BUG: writing outside the array's bounds. + task->tWinLeft = 88; + task->tWinRight = 152; // BUG: writing outside the array's bounds. task->data[5] = 64; task->data[8] = 65; SetGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON); - SetGpuReg(REG_OFFSET_WIN0H, WIN_RANGE(task->data[3], task->data[24])); + SetGpuReg(REG_OFFSET_WIN0H, WIN_RANGE(task->tWinLeft, task->tWinRight)); SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(task->data[5], task->data[8])); SetGpuReg(REG_OFFSET_WININ, WININ_WIN0_BG_ALL | WININ_WIN0_CLR | WININ_WIN0_OBJ); SetGpuReg(REG_OFFSET_WINOUT, WINOUT_WIN01_BG0 | WINOUT_WIN01_BG1 | WINOUT_WIN01_BG2 | WINOUT_WIN01_CLR | WINOUT_WIN01_OBJ); @@ -4040,23 +4047,23 @@ static void sub_819F69C(u8 taskId) default: DestroyTask(taskId); // UB: Should not use the task after it has been deleted. - if (gTasks[taskId].data[7] == TRUE) - Swap_ShowMonSprite(); + if (gTasks[taskId].tIsSwapScreen == TRUE) + Swap_CreateMonSprite(); else - Summary_ShowMonSprite(); + Summary_CreateMonSprite(); return; } task->data[0]++; } -static void sub_819F7B4(u8 taskId) +static void Task_CloseMonPic(u8 taskId) { struct Task *task = &gTasks[taskId]; - switch (task->data[0]) + switch (task->tState) { default: HideBg(3); - gSprites[task->data[6]].data[7] = task->data[7]; + gSprites[task->data[6]].data[7] = task->tIsSwapScreen; gSprites[task->data[6]].invisible = FALSE; gSprites[task->data[6]].callback = sub_819F654; StartSpriteAffineAnim(&gSprites[task->data[6]], 1); @@ -4064,12 +4071,12 @@ static void sub_819F7B4(u8 taskId) DestroyTask(taskId); break; case 0: - task->data[3] = 88; - task->data[24] = 152; // BUG: writing outside the array's bounds. + task->tWinLeft = 88; + task->tWinRight = 152; task->data[5] = 32; task->data[8] = 96; SetGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON); - SetGpuReg(REG_OFFSET_WIN0H, WIN_RANGE(task->data[3], task->data[24])); + SetGpuReg(REG_OFFSET_WIN0H, WIN_RANGE(task->tWinLeft, task->tWinRight)); SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(task->data[5], task->data[8])); SetGpuReg(REG_OFFSET_WININ, WININ_WIN0_BG_ALL | WININ_WIN0_CLR | WININ_WIN0_OBJ); SetGpuReg(REG_OFFSET_WINOUT, WINOUT_WIN01_BG0 | WINOUT_WIN01_BG1 | WINOUT_WIN01_BG2 | WINOUT_WIN01_CLR | WINOUT_WIN01_OBJ); @@ -4090,7 +4097,7 @@ static void sub_819F7B4(u8 taskId) } } -static void Swap_ShowMonSprite(void) +static void Swap_CreateMonSprite(void) { struct Pokemon *mon; u16 species; From 0bf49198f62484284994f6f54c68597608013eb2 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 28 Dec 2020 17:32:08 -0500 Subject: [PATCH 3/6] Resume factory screen doc --- include/graphics.h | 5 + include/strings.h | 27 + src/battle_factory_screen.c | 1995 ++++++++++++++++++----------------- 3 files changed, 1046 insertions(+), 981 deletions(-) diff --git a/include/graphics.h b/include/graphics.h index d9189622a..b5e9396d0 100644 --- a/include/graphics.h +++ b/include/graphics.h @@ -5013,4 +5013,9 @@ extern const u16 gPokenavMessageBox_Pal[]; extern const u32 gPokenavOptions_Gfx[]; extern const u16 gPokenavOptions_Pal[]; +// Battle Factory Screen +extern const u8 gFrontierFactorySelectMenu_Gfx[]; +extern const u8 gFrontierFactorySelectMenu_Tilemap[]; +extern const u16 gFrontierFactorySelectMenu_Pal[]; + #endif //GUARD_GRAPHICS_H diff --git a/include/strings.h b/include/strings.h index 7018f9e0d..294ab8aa6 100644 --- a/include/strings.h +++ b/include/strings.h @@ -2988,4 +2988,31 @@ extern const u8 gText_SavingDontTurnOff2[]; extern const u8 gText_BlenderMaxSpeedRecord[]; extern const u8 gText_234Players[]; +// Battle Factory Screen +extern const u8 gText_RentalPkmn2[]; +extern const u8 gText_SelectFirstPkmn[]; +extern const u8 gText_SelectSecondPkmn[]; +extern const u8 gText_SelectThirdPkmn[]; +extern const u8 gText_TheseThreePkmnOkay[]; +extern const u8 gText_CantSelectSamePkmn[]; +extern const u8 gText_Summary[]; +extern const u8 gText_Rechoose[]; +extern const u8 gText_Deselect[]; +extern const u8 gText_Rent[]; +extern const u8 gText_Others2[]; +extern const u8 gText_Yes2[]; +extern const u8 gText_Yes3[]; +extern const u8 gText_No2[]; +extern const u8 gText_No3[]; +extern const u8 gText_QuitSwapping[]; +extern const u8 gText_AcceptThisPkmn[]; +extern const u8 gText_SelectPkmnToAccept[]; +extern const u8 gText_SelectPkmnToSwap[]; +extern const u8 gText_PkmnSwap[]; +extern const u8 gText_Swap[]; +extern const u8 gText_Summary2[]; +extern const u8 gText_PkmnForSwap[]; +extern const u8 gText_SamePkmnInPartyAlready[]; +extern const u8 gText_Cancel3[]; + #endif // GUARD_STRINGS_H diff --git a/src/battle_factory_screen.c b/src/battle_factory_screen.c index 46e2fa28c..13edf6fef 100644 --- a/src/battle_factory_screen.c +++ b/src/battle_factory_screen.c @@ -25,26 +25,21 @@ #include "util.h" #include "trainer_pokemon_sprites.h" #include "starter_choose.h" +#include "strings.h" +#include "graphics.h" #include "constants/battle_frontier.h" #include "constants/songs.h" #include "constants/rgb.h" -// Select_ refers to the first Pokemon selection screen where you choose 3 Pokemon. +// Select_ refers to the first Pokemon selection screen where you choose your initial 3 rental Pokemon. // Swap_ refers to the subsequent selection screens where you can swap a Pokemon with one from the beaten trainer -// 'Action' refers to the 3 Selectable mons, Cancel, Pknm for swap windows. -#define ACTIONS_PLAYER_SCREEN 0 -#define ACTIONS_ENEMY_SCREEN 1 +// Note that, generally, "Action" will refer to the immediate actions that can be taken on each screen, +// i.e. selecting a pokemon or selecting the Cancel button +// The "Options menu" will refer to the popup menu that shows when some actions have been selected -#define SELECTMENU_SUMMARY 0 -#define SELECTMENU_RENT 1 -#define SELECTMENU_OTHERS 2 -#define SELECTMENU_OPTIONS_COUNT 3 - -#define SWAPMENU_SUMMARY 0 -#define SWAPMENU_SWAP 1 -#define SWAPMENU_RECHOOSE 2 -#define SWAPMENU_OPTIONS_COUNT 3 +#define SWAP_PLAYER_SCREEN 0 // The screen where the player selects which of their pokemon to swap away +#define SWAP_ENEMY_SCREEN 1 // The screen where the player selects which new pokemon from the defeated party to swap for #define SELECTABLE_MONS_COUNT 6 @@ -64,18 +59,28 @@ #define GFXTAG_ACTION_HIGHLIGHT_RIGHT 0x6C #define GFXTAG_MON_PIC_BG_ANIM 0x6D +// Tasks in this file universally use data[0] as a state for switches +#define tState data[0] + +// States for both Select/Swap versions of Task_FadeSpeciesName +enum { + FADESTATE_INIT, + FADESTATE_RUN, + FADESTATE_DELAY +}; + struct FactorySelectableMon { u16 monId; - u16 spriteId; + u16 ballSpriteId; u8 selectedId; // 0 - not selected, 1 - first pokemon, 2 - second pokemon, 3 - third pokemon struct Pokemon monData; }; -struct UnkFactoryStruct +struct FactoryMonPic { - u8 field0; - u8 field1; + u8 monSpriteId; + u8 bgSpriteId; }; struct FactorySelectScreen @@ -88,17 +93,17 @@ struct FactorySelectScreen u8 selectingMonsState; bool8 fromSummaryScreen; u8 yesNoCursorPos; - u8 unused8; + u8 unused; struct FactorySelectableMon mons[SELECTABLE_MONS_COUNT]; - struct UnkFactoryStruct unk294[FRONTIER_PARTY_SIZE]; - bool8 unk2A0; + struct FactoryMonPic monPics[FRONTIER_PARTY_SIZE]; // Array so all chosen mons can be shown at once + bool8 monPicAnimating; u8 fadeSpeciesNameTaskId; - bool8 unk2A2; + bool8 fadeSpeciesNameActive; u16 speciesNameColorBackup; - bool8 unk2A6; - u8 unk2A7; - u8 unk2A8; - u8 unk2A9; + bool8 fadeSpeciesNameFadeOut; + u8 fadeSpeciesNameCoeffDelay; + u8 fadeSpeciesNameCoeff; + u8 faceSpeciesNameDelay; }; struct SwapScreenAction @@ -115,8 +120,8 @@ struct FactorySwapScreen u8 cursorPos; u8 cursorSpriteId; u8 ballSpriteIds[FRONTIER_PARTY_SIZE]; - u8 unk8[2][3]; - u8 unkE[2][2]; + u8 pkmnForSwapButtonSpriteIds[2][3]; // For this and sprite ID array below, [0][i] is the button background, [1][i] is the button highlight + u8 cancelButtonSpriteIds[2][2]; u8 playerMonId; u8 enemyMonId; bool8 inEnemyScreen; @@ -127,20 +132,27 @@ struct FactorySwapScreen u8 unused1C[4]; bool8 monSwapped; u8 fadeSpeciesNameTaskId; - bool8 unk22; - u16 unk24; - bool8 unk26; - u8 unk27; - u8 unk28; - u8 unk29; - struct UnkFactoryStruct unk2C; - bool8 unk30; + bool8 fadeSpeciesNameActive; + u16 speciesNameColorBackup; + bool8 fadeSpeciesNameFadeOut; + u8 fadeSpeciesNameCoeffDelay; + u8 fadeSpeciesNameCoeff; + u8 faceSpeciesNameDelay; + struct FactoryMonPic monPic; + bool8 monPicAnimating; }; -// This file's functions. -static void SpriteCB_Pokeball(struct Sprite *sprite); +static void SpriteCB_Pokeball(struct Sprite *); +static void SpriteCB_OpenMonPic(struct Sprite *); +static void OpenMonPic(u8 *, bool8 *, bool8); +static void HideMonPic(struct FactoryMonPic, bool8 *); +static void CloseMonPic(struct FactoryMonPic, bool8 *, bool8); +static void Task_OpenMonPic(u8); +static void Task_CloseMonPic(u8); + +// Select screen static void CB2_InitSelectScreen(void); -static void Select_SetWinRegs(s16 mWin0H, s16 nWin0H, s16 mWin0V, s16 nWin0V); +static void Select_SetWinRegs(s16, s16, s16, s16); static void Select_InitMonsData(void); static void Select_InitAllSprites(void); static void Select_ReshowMonSprite(void); @@ -155,35 +167,34 @@ static void sub_819C568(void); static void Select_ShowMenuOptions(void); static void Select_PrintMenuOptions(void); static void Select_PrintYesNoOptions(void); -static void Task_SelectFadeSpeciesName(u8 taskId); -static void sub_819C1D0(u8 taskId); -static void Task_HandleSelectionScreenChooseMons(u8 taskId); -static void Task_HandleSelectionScreenMenu(u8 taskId); -static void CreateFrontierFactorySelectableMons(u8 firstMonId); -static void CreateTentFactorySelectableMons(u8 firstMonId); -static void Select_SetBallSpritePaletteNum(u8 id); -static void sub_819F444(struct UnkFactoryStruct arg0, bool8 *arg1); -static void sub_819B958(u8 windowId); -static void sub_819F2B4(u8 *arg0, bool8 *arg1, bool8 swapScreen); -static void CloseMonPic(struct UnkFactoryStruct arg0, bool8 *arg1, bool8 swapScreen); +static void Select_Task_FadeSpeciesName(u8); +static void sub_819C1D0(u8); +static void Select_Task_HandleChooseMons(u8); +static void Select_Task_HandleMenu(u8); +static void CreateFrontierFactorySelectableMons(u8); +static void CreateSlateportTentSelectableMons(u8); +static void Select_SetBallSpritePaletteNum(u8); +static void sub_819B958(u8); static u8 Select_RunMenuOptionFunc(void); static u8 sub_819BC9C(void); static u8 Select_OptionSummary(void); static u8 Select_OptionOthers(void); static u8 Select_OptionRentDeselect(void); -static bool32 Select_AreSpeciesValid(u16 monId); +static bool32 Select_AreSpeciesValid(u16); + +// Swap screen +static void CB2_InitSwapScreen(void); static void Swap_DestroyAllSprites(void); static void Swap_ShowYesNoOptions(void); -static void sub_819E8EC(void); +static void Swap_HideActionButtonHighlights(void); static void sub_819EAC0(void); -static void Swap_UpdateYesNoCursorPosition(s8 direction); -static void Swap_UpdateMenuCursorPosition(s8 direction); -static void sub_819EA64(u8 windowId); -static void sub_819D770(u8 taskId); -static void Task_HandleSwapScreenChooseMons(u8 taskId); -static void sub_819D588(u8 taskId); -static void Task_CloseMonPic(u8 taskId); -static void Swap_PrintOnInfoWindow(const u8 *str); +static void Swap_UpdateYesNoCursorPosition(s8); +static void Swap_UpdateMenuCursorPosition(s8); +static void Swap_ErasePopupMenu(u8); +static void sub_819D770(u8); +static void Swap_Task_HandleChooseMons(u8); +static void sub_819D588(u8); +static void Swap_PrintOnInfoWindow(const u8 *); static void Swap_ShowMenuOptions(void); static void Swap_PrintMenuOptions(void); static void Swap_PrintYesNoOptions(void); @@ -195,28 +206,25 @@ static void Swap_InitAllSprites(void); static void Swap_PrintPkmnSwap(void); static void sub_819EADC(void); static void sub_819EAF8(void); -static void CB2_InitSwapScreen(void); static void Swap_ShowSummaryMonSprite(void); -static void Swap_UpdateActionCursorPosition(s8 direction); -static void Swap_UpdateBallCursorPosition(s8 direction); -static void Swap_RunMenuOptionFunc(u8 taskId); -static void Swap_OptionSwap(u8 taskId); -static void Swap_OptionSummary(u8 taskId); -static void Swap_OptionRechoose(u8 taskId); -static void Swap_RunActionFunc(u8 taskId); -static void Task_OpenMonPic(u8 taskId); -static void Task_SwapCantHaveSameMons(u8 taskId); +static void Swap_UpdateActionCursorPosition(s8); +static void Swap_UpdateBallCursorPosition(s8); +static void Swap_RunMenuOptionFunc(u8); +static void Swap_OptionSwap(u8); +static void Swap_OptionSummary(u8); +static void Swap_OptionRechoose(u8); +static void Swap_RunActionFunc(u8); +static void Swap_TaskCantHaveSameMons(u8); static void Swap_CreateMonSprite(void); static void Swap_PrintActionStrings(void); static void Swap_PrintActionStrings2(void); -static void Swap_PrintOneActionString(u8 which); -static void Swap_InitActions(u8 id); -static void sub_819E838(u8 arg0); -static bool8 Swap_AlreadyHasSameSpecies(u8 monId); -static void SpriteCB_OpenMonPic(struct Sprite *sprite); -static void Swap_ActionMon(u8 taskId); -static void Swap_ActionCancel(u8 taskId); -static void Swap_ActionPkmnForSwap(u8 taskId); +static void Swap_PrintOneActionString(u8); +static void Swap_InitActions(u8); +static void Swap_HighlightActionButton(u8); +static bool8 Swap_AlreadyHasSameSpecies(u8); +static void Swap_ActionMon(u8); +static void Swap_ActionCancel(u8); +static void Swap_ActionPkmnForSwap(u8); // Ewram variables static EWRAM_DATA u8 *sSelectMenuTilesetBuffer = NULL; @@ -276,7 +284,7 @@ static const struct SpritePalette sSelect_SpritePalettes[] = {}, }; -u8 static (* const sSelect_MenuOptionFuncs[SELECTMENU_OPTIONS_COUNT])(void) = +u8 static (* const sSelect_MenuOptionFuncs[])(void) = { Select_OptionSummary, Select_OptionRentDeselect, @@ -314,9 +322,18 @@ static const struct BgTemplate sSelect_BgTemplates[] = }, }; +enum { + SELECT_WIN_TITLE, + SELECT_WIN_SPECIES, + SELECT_WIN_INFO, + SELECT_WIN_OPTIONS, + SELECT_WIN_YES_NO, + SELECT_WIN_MON_CATEGORY, +}; + static const struct WindowTemplate sSelect_WindowTemplates[] = { - { + [SELECT_WIN_TITLE] = { .bg = 0, .tilemapLeft = 0, .tilemapTop = 2, @@ -325,7 +342,7 @@ static const struct WindowTemplate sSelect_WindowTemplates[] = .paletteNum = 15, .baseBlock = 0x0001, }, - { + [SELECT_WIN_SPECIES] = { .bg = 0, .tilemapLeft = 19, .tilemapTop = 2, @@ -334,7 +351,7 @@ static const struct WindowTemplate sSelect_WindowTemplates[] = .paletteNum = 14, .baseBlock = 0x0019, }, - { + [SELECT_WIN_INFO] = { .bg = 0, .tilemapLeft = 0, .tilemapTop = 15, @@ -343,7 +360,7 @@ static const struct WindowTemplate sSelect_WindowTemplates[] = .paletteNum = 15, .baseBlock = 0x002f, }, - { + [SELECT_WIN_OPTIONS] = { .bg = 0, .tilemapLeft = 22, .tilemapTop = 14, @@ -352,7 +369,7 @@ static const struct WindowTemplate sSelect_WindowTemplates[] = .paletteNum = 15, .baseBlock = 0x006b, }, - { + [SELECT_WIN_YES_NO] = { .bg = 0, .tilemapLeft = 22, .tilemapTop = 14, @@ -361,7 +378,7 @@ static const struct WindowTemplate sSelect_WindowTemplates[] = .paletteNum = 15, .baseBlock = 0x009b, }, - { + [SELECT_WIN_MON_CATEGORY] = { .bg = 0, .tilemapLeft = 15, .tilemapTop = 0, @@ -679,7 +696,7 @@ static const struct OamData sOam_Swap_MenuHighlight = .affineParam = 0, }; -static const struct OamData gUnknown_086106F0 = +static const struct OamData sOam_Swap_MonPicBgAnim = { .y = 0, .affineMode = ST_OAM_AFFINE_DOUBLE, @@ -702,7 +719,7 @@ static const union AnimCmd sAnim_Swap_Interface[] = ANIMCMD_END, }; -static const union AnimCmd gUnknown_08610700[] = +static const union AnimCmd sAnim_Swap_MonPicBgAnim[] = { ANIMCMD_FRAME(0, 1), ANIMCMD_END, @@ -741,9 +758,9 @@ static const union AnimCmd * const sAnims_Swap_Interface[] = sAnim_Swap_Interface, }; -static const union AnimCmd * const gUnknown_0861075C[] = +static const union AnimCmd * const sAnims_Swap_MonPicBgAnim[] = { - gUnknown_08610700, + sAnim_Swap_MonPicBgAnim, }; static const union AnimCmd * const sAnims_Swap_Pokeball[] = @@ -788,7 +805,7 @@ static const union AffineAnimCmd gUnknown_08610818[] = AFFINEANIMCMD_END, }; -static const union AffineAnimCmd * const gUnknown_08610828[] = +static const union AffineAnimCmd * const sAffineAnims_Swap_MonPicBgAnim[] = { gUnknown_08610768, gUnknown_086107C8, @@ -843,14 +860,14 @@ static const struct SpriteTemplate sSpriteTemplate_Swap_MonPicBgAnim = { .tileTag = GFXTAG_MON_PIC_BG_ANIM, .paletteTag = PALTAG_MON_PIC_BG, - .oam = &gUnknown_086106F0, - .anims = gUnknown_0861075C, + .oam = &sOam_Swap_MonPicBgAnim, + .anims = sAnims_Swap_MonPicBgAnim, .images = NULL, - .affineAnims = gUnknown_08610828, + .affineAnims = sAffineAnims_Swap_MonPicBgAnim, .callback = SpriteCallbackDummy }; -void static (* const sSwap_MenuOptionFuncs[SWAPMENU_OPTIONS_COUNT])(u8 taskId) = +void static (* const sSwap_MenuOptionFuncs[])(u8 taskId) = { Swap_OptionSummary, Swap_OptionSwap, @@ -897,9 +914,21 @@ static const struct BgTemplate sSwap_BgTemplates[4] = }, }; +enum { + SWAP_WIN_TITLE, + SWAP_WIN_SPECIES, + SWAP_WIN_INFO, + SWAP_WIN_OPTIONS, + SWAP_WIN_YES_NO, + SWAP_WIN_5, + SWAP_WIN_6, + SWAP_WIN_7, + SWAP_WIN_MON_CATEGORY, +}; + static const struct WindowTemplate sSwap_WindowTemplates[] = { - { + [SWAP_WIN_TITLE] = { .bg = 0, .tilemapLeft = 0, .tilemapTop = 2, @@ -908,7 +937,7 @@ static const struct WindowTemplate sSwap_WindowTemplates[] = .paletteNum = 15, .baseBlock = 0x0001, }, - { + [SWAP_WIN_SPECIES] = { .bg = 2, .tilemapLeft = 19, .tilemapTop = 2, @@ -917,7 +946,7 @@ static const struct WindowTemplate sSwap_WindowTemplates[] = .paletteNum = 14, .baseBlock = 0x0019, }, - { + [SWAP_WIN_INFO] = { .bg = 0, .tilemapLeft = 0, .tilemapTop = 15, @@ -926,7 +955,7 @@ static const struct WindowTemplate sSwap_WindowTemplates[] = .paletteNum = 15, .baseBlock = 0x002f, }, - { + [SWAP_WIN_OPTIONS] = { .bg = 0, .tilemapLeft = 21, .tilemapTop = 14, @@ -935,7 +964,7 @@ static const struct WindowTemplate sSwap_WindowTemplates[] = .paletteNum = 15, .baseBlock = 0x006b, }, - { + [SWAP_WIN_YES_NO] = { .bg = 0, .tilemapLeft = 22, .tilemapTop = 14, @@ -944,7 +973,7 @@ static const struct WindowTemplate sSwap_WindowTemplates[] = .paletteNum = 15, .baseBlock = 0x00a1, }, - { + [SWAP_WIN_5] = { .bg = 2, .tilemapLeft = 21, .tilemapTop = 15, @@ -953,7 +982,7 @@ static const struct WindowTemplate sSwap_WindowTemplates[] = .paletteNum = 14, .baseBlock = 0x006b, }, - { + [SWAP_WIN_6] = { .bg = 2, .tilemapLeft = 10, .tilemapTop = 2, @@ -962,7 +991,7 @@ static const struct WindowTemplate sSwap_WindowTemplates[] = .paletteNum = 14, .baseBlock = 0x00c1, }, - { + [SWAP_WIN_7] = { .bg = 0, .tilemapLeft = 19, .tilemapTop = 2, @@ -971,7 +1000,7 @@ static const struct WindowTemplate sSwap_WindowTemplates[] = .paletteNum = 15, .baseBlock = 0x00c9, }, - { + [SWAP_WIN_MON_CATEGORY] = { .bg = 0, .tilemapLeft = 15, .tilemapTop = 0, @@ -987,55 +1016,27 @@ static const u16 sSwapText_Pal[] = INCBIN_U16("graphics/battle_frontier/factory_ static const u8 sSwapMenuOptionsTextColors[] = {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_DARK_GREY, TEXT_COLOR_TRANSPARENT}; static const u8 sSwapSpeciesNameTextColors[] = {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_RED, TEXT_COLOR_TRANSPARENT}; +#define SWAPACTION_MON 1 +#define SWAPACTION_PKMN_FOR_SWAP 2 +#define SWAPACTION_CANCEL 3 + static const struct SwapScreenAction sSwap_PlayerScreenActions[] = { - {.id = 1, .func = Swap_ActionMon}, - {.id = 1, .func = Swap_ActionMon}, - {.id = 1, .func = Swap_ActionMon}, - {.id = 3, .func = Swap_ActionCancel}, + {.id = SWAPACTION_MON, .func = Swap_ActionMon}, + {.id = SWAPACTION_MON, .func = Swap_ActionMon}, + {.id = SWAPACTION_MON, .func = Swap_ActionMon}, + {.id = SWAPACTION_CANCEL, .func = Swap_ActionCancel}, }; static const struct SwapScreenAction sSwap_EnemyScreenActions[] = { - {.id = 1, .func = Swap_ActionMon}, - {.id = 1, .func = Swap_ActionMon}, - {.id = 1, .func = Swap_ActionMon}, - {.id = 2, .func = Swap_ActionPkmnForSwap}, - {.id = 3, .func = Swap_ActionCancel}, + {.id = SWAPACTION_MON, .func = Swap_ActionMon}, + {.id = SWAPACTION_MON, .func = Swap_ActionMon}, + {.id = SWAPACTION_MON, .func = Swap_ActionMon}, + {.id = SWAPACTION_PKMN_FOR_SWAP, .func = Swap_ActionPkmnForSwap}, + {.id = SWAPACTION_CANCEL, .func = Swap_ActionCancel}, }; -// gfx -extern const u8 gFrontierFactorySelectMenu_Gfx[]; -extern const u8 gFrontierFactorySelectMenu_Tilemap[]; -extern const u16 gFrontierFactorySelectMenu_Pal[]; - -// text -extern const u8 gText_RentalPkmn2[]; -extern const u8 gText_SelectFirstPkmn[]; -extern const u8 gText_SelectSecondPkmn[]; -extern const u8 gText_SelectThirdPkmn[]; -extern const u8 gText_TheseThreePkmnOkay[]; -extern const u8 gText_CantSelectSamePkmn[]; -extern const u8 gText_Summary[]; -extern const u8 gText_Rechoose[]; -extern const u8 gText_Deselect[]; -extern const u8 gText_Rent[]; -extern const u8 gText_Others2[]; -extern const u8 gText_Yes2[]; -extern const u8 gText_Yes3[]; -extern const u8 gText_No2[]; -extern const u8 gText_No3[]; -extern const u8 gText_QuitSwapping[]; -extern const u8 gText_AcceptThisPkmn[]; -extern const u8 gText_SelectPkmnToAccept[]; -extern const u8 gText_SelectPkmnToSwap[]; -extern const u8 gText_PkmnSwap[]; -extern const u8 gText_Swap[]; -extern const u8 gText_Summary2[]; -extern const u8 gText_PkmnForSwap[]; -extern const u8 gText_SamePkmnInPartyAlready[]; -extern const u8 gText_Cancel3[]; - static void SpriteCB_Pokeball(struct Sprite *sprite) { if (sprite->oam.paletteNum == IndexOfSpritePaletteTag(PALTAG_BALL_SELECTED)) @@ -1166,7 +1167,7 @@ static void CB2_InitSelectScreen(void) ShowBg(0); ShowBg(1); SetVBlankCallback(VBlankCB_SelectScreen); - BeginNormalPaletteFade(0xFFFFFFFF, 0, 0x10, 0, RGB_BLACK); + BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, RGB_BLACK); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_BG0_ON | DISPCNT_BG1_ON | DISPCNT_OBJ_1D_MAP); if (sFactorySelectScreen->fromSummaryScreen == TRUE) { @@ -1192,38 +1193,38 @@ static void CB2_InitSelectScreen(void) break; case 6: Select_PrintSelectMonString(); - PutWindowTilemap(2); + PutWindowTilemap(SELECT_WIN_INFO); gMain.state++; break; case 7: Select_PrintMonCategory(); - PutWindowTilemap(5); + PutWindowTilemap(SELECT_WIN_MON_CATEGORY); gMain.state++; break; case 8: Select_PrintMonSpecies(); - PutWindowTilemap(1); + PutWindowTilemap(SELECT_WIN_SPECIES); gMain.state++; break; case 9: Select_PrintRentalPkmnString(); - PutWindowTilemap(0); + PutWindowTilemap(SELECT_WIN_TITLE); gMain.state++; break; case 10: - sFactorySelectScreen->fadeSpeciesNameTaskId = CreateTask(Task_SelectFadeSpeciesName, 0); + sFactorySelectScreen->fadeSpeciesNameTaskId = CreateTask(Select_Task_FadeSpeciesName, 0); if (!sFactorySelectScreen->fromSummaryScreen) { - gTasks[sFactorySelectScreen->fadeSpeciesNameTaskId].data[0] = 0; - taskId = CreateTask(Task_HandleSelectionScreenChooseMons, 0); - gTasks[taskId].data[0] = 0; + gTasks[sFactorySelectScreen->fadeSpeciesNameTaskId].tState = 0; + taskId = CreateTask(Select_Task_HandleChooseMons, 0); + gTasks[taskId].tState = 0; } else { - gTasks[sFactorySelectScreen->fadeSpeciesNameTaskId].data[0] = 1; - sFactorySelectScreen->unk2A2 = FALSE; - taskId = CreateTask(Task_HandleSelectionScreenMenu, 0); - gTasks[taskId].data[0] = 13; + gTasks[sFactorySelectScreen->fadeSpeciesNameTaskId].tState = 1; + sFactorySelectScreen->fadeSpeciesNameActive = FALSE; + taskId = CreateTask(Select_Task_HandleMenu, 0); + gTasks[taskId].tState = 13; } SetMainCallback2(CB2_SelectScreen); break; @@ -1247,7 +1248,7 @@ static void Select_InitMonsData(void) if (gSaveBlock2Ptr->frontier.lvlMode != FRONTIER_LVL_TENT) CreateFrontierFactorySelectableMons(0); else - CreateTentFactorySelectableMons(0); + CreateSlateportTentSelectableMons(0); } static void Select_InitAllSprites(void) @@ -1257,12 +1258,12 @@ static void Select_InitAllSprites(void) for (i = 0; i < SELECTABLE_MONS_COUNT; i++) { - sFactorySelectScreen->mons[i].spriteId = CreateSprite(&sSpriteTemplate_Select_Pokeball, (35 * i) + 32, 64, 1); - gSprites[sFactorySelectScreen->mons[i].spriteId].data[0] = 0; + sFactorySelectScreen->mons[i].ballSpriteId = CreateSprite(&sSpriteTemplate_Select_Pokeball, (35 * i) + 32, 64, 1); + gSprites[sFactorySelectScreen->mons[i].ballSpriteId].data[0] = 0; Select_SetBallSpritePaletteNum(i); } cursorPos = sFactorySelectScreen->cursorPos; - x = gSprites[sFactorySelectScreen->mons[cursorPos].spriteId].pos1.x; + x = gSprites[sFactorySelectScreen->mons[cursorPos].ballSpriteId].pos1.x; sFactorySelectScreen->cursorSpriteId = CreateSprite(&sSpriteTemplate_Select_Arrow, x, 88, 0); sFactorySelectScreen->menuCursor1SpriteId = CreateSprite(&sSpriteTemplate_Select_MenuHighlightLeft, 176, 112, 0); sFactorySelectScreen->menuCursor2SpriteId = CreateSprite(&sSpriteTemplate_Select_MenuHighlightRight, 176, 144, 0); @@ -1281,7 +1282,7 @@ static void Select_DestroyAllSprites(void) u8 i; for (i = 0; i < SELECTABLE_MONS_COUNT; i++) - DestroySprite(&gSprites[sFactorySelectScreen->mons[i].spriteId]); + DestroySprite(&gSprites[sFactorySelectScreen->mons[i].ballSpriteId]); DestroySprite(&gSprites[sFactorySelectScreen->cursorSpriteId]); DestroySprite(&gSprites[sFactorySelectScreen->menuCursor1SpriteId]); @@ -1307,14 +1308,14 @@ static void Select_UpdateBallCursorPosition(s8 direction) } cursorPos = sFactorySelectScreen->cursorPos; - gSprites[sFactorySelectScreen->cursorSpriteId].pos1.x = gSprites[sFactorySelectScreen->mons[cursorPos].spriteId].pos1.x; + gSprites[sFactorySelectScreen->cursorSpriteId].pos1.x = gSprites[sFactorySelectScreen->mons[cursorPos].ballSpriteId].pos1.x; } static void Select_UpdateMenuCursorPosition(s8 direction) { if (direction > 0) // Move cursor down. { - if (sFactorySelectScreen->menuCursorPos != SELECTMENU_OPTIONS_COUNT - 1) + if (sFactorySelectScreen->menuCursorPos != ARRAY_COUNT(sSelect_MenuOptionFuncs) - 1) sFactorySelectScreen->menuCursorPos++; else sFactorySelectScreen->menuCursorPos = 0; @@ -1324,7 +1325,7 @@ static void Select_UpdateMenuCursorPosition(s8 direction) if (sFactorySelectScreen->menuCursorPos != 0) sFactorySelectScreen->menuCursorPos--; else - sFactorySelectScreen->menuCursorPos = SELECTMENU_OPTIONS_COUNT - 1; + sFactorySelectScreen->menuCursorPos = ARRAY_COUNT(sSelect_MenuOptionFuncs) - 1; } gSprites[sFactorySelectScreen->menuCursor1SpriteId].pos1.y = (sFactorySelectScreen->menuCursorPos * 16) + 112; @@ -1381,7 +1382,7 @@ static void Select_HandleMonSelectionChange(void) sFactorySelectScreen->selectingMonsState++; } - gSprites[sFactorySelectScreen->mons[cursorPos].spriteId].oam.paletteNum = paletteNum; + gSprites[sFactorySelectScreen->mons[cursorPos].ballSpriteId].oam.paletteNum = paletteNum; } static void Select_SetBallSpritePaletteNum(u8 id) @@ -1393,33 +1394,33 @@ static void Select_SetBallSpritePaletteNum(u8 id) else palNum = IndexOfSpritePaletteTag(PALTAG_BALL_GRAY); - gSprites[sFactorySelectScreen->mons[id].spriteId].oam.paletteNum = palNum; + gSprites[sFactorySelectScreen->mons[id].ballSpriteId].oam.paletteNum = palNum; } -static void Task_FromSelectScreenToSummaryScreen(u8 taskId) +static void Select_Task_OpenSummaryScreen(u8 taskId) { u8 i; u8 currMonId; - switch (gTasks[taskId].data[0]) + switch (gTasks[taskId].tState) { case 6: gPlttBufferUnfaded[228] = gPlttBufferFaded[228]; - BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); - gTasks[taskId].data[0] = 7; + BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); + gTasks[taskId].tState = 7; break; case 7: if (!gPaletteFade.active) { DestroyTask(sFactorySelectScreen->fadeSpeciesNameTaskId); - sub_819F444(sFactorySelectScreen->unk294[1], &sFactorySelectScreen->unk2A0); + HideMonPic(sFactorySelectScreen->monPics[1], &sFactorySelectScreen->monPicAnimating); Select_DestroyAllSprites(); FREE_AND_SET_NULL(sSelectMenuTilesetBuffer); FREE_AND_SET_NULL(sSelectMonPicBgTilesetBuffer); FREE_AND_SET_NULL(sSelectMenuTilemapBuffer); FREE_AND_SET_NULL(sSelectMonPicBgTilemapBuffer); FreeAllWindowBuffers(); - gTasks[taskId].data[0] = 8; + gTasks[taskId].tState = 8; } break; case 8: @@ -1435,152 +1436,154 @@ static void Task_FromSelectScreenToSummaryScreen(u8 taskId) } } -static void Task_CloseSelectionScreen(u8 taskId) +static void Select_Task_Exit(u8 taskId) { - if (sFactorySelectScreen->unk2A0 != TRUE) + if (sFactorySelectScreen->monPicAnimating == TRUE) + return; + + switch (gTasks[taskId].tState) { - switch (gTasks[taskId].data[0]) + case 0: + BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); + gTasks[taskId].tState++; + break; + case 1: + if (!UpdatePaletteFade()) { - case 0: - BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); - gTasks[taskId].data[0]++; - break; - case 1: - if (!UpdatePaletteFade()) - { - Select_CopyMonsToPlayerParty(); - DestroyTask(sFactorySelectScreen->fadeSpeciesNameTaskId); - Select_DestroyAllSprites(); - FREE_AND_SET_NULL(sSelectMenuTilesetBuffer); - FREE_AND_SET_NULL(sSelectMenuTilemapBuffer); - FREE_AND_SET_NULL(sSelectMonPicBgTilemapBuffer); - FREE_AND_SET_NULL(sFactorySelectScreen); - FreeAllWindowBuffers(); - SetMainCallback2(CB2_ReturnToFieldContinueScript); - DestroyTask(taskId); - } - break; + Select_CopyMonsToPlayerParty(); + DestroyTask(sFactorySelectScreen->fadeSpeciesNameTaskId); + Select_DestroyAllSprites(); + FREE_AND_SET_NULL(sSelectMenuTilesetBuffer); + FREE_AND_SET_NULL(sSelectMenuTilemapBuffer); + FREE_AND_SET_NULL(sSelectMonPicBgTilemapBuffer); + FREE_AND_SET_NULL(sFactorySelectScreen); + FreeAllWindowBuffers(); + SetMainCallback2(CB2_ReturnToFieldContinueScript); + DestroyTask(taskId); } + break; } } -static void Task_HandleSelectionScreenYesNo(u8 taskId) +static void Select_Task_HandleYesNo(u8 taskId) { - if (sFactorySelectScreen->unk2A0 != TRUE) + if (sFactorySelectScreen->monPicAnimating == TRUE) + return; + + switch (gTasks[taskId].tState) { - switch (gTasks[taskId].data[0]) + case 10: + sub_819C4B4(); + gTasks[taskId].tState = 4; + break; + case 4: + Select_ShowYesNoOptions(); + gTasks[taskId].tState = 5; + break; + case 5: + if (JOY_NEW(A_BUTTON)) { - case 10: - sub_819C4B4(); - gTasks[taskId].data[0] = 4; - break; - case 4: - Select_ShowYesNoOptions(); - gTasks[taskId].data[0] = 5; - break; - case 5: - if (gMain.newKeys & A_BUTTON) + PlaySE(SE_SELECT); + if (sFactorySelectScreen->yesNoCursorPos == 0) { - PlaySE(SE_SELECT); - if (sFactorySelectScreen->yesNoCursorPos == 0) - { - sub_819C568(); - gTasks[taskId].data[0] = 0; - gTasks[taskId].func = Task_CloseSelectionScreen; - } - else - { - sub_819B958(4); - sub_819BC9C(); - sFactorySelectScreen->unk2A2 = TRUE; - gTasks[taskId].data[0] = 1; - gTasks[taskId].func = Task_HandleSelectionScreenChooseMons; - } + // Selected Yes + sub_819C568(); + gTasks[taskId].tState = 0; + gTasks[taskId].func = Select_Task_Exit; } - else if (gMain.newKeys & B_BUTTON) + else { - PlaySE(SE_SELECT); - sub_819B958(4); + // Selected No + sub_819B958(SELECT_WIN_YES_NO); sub_819BC9C(); - sFactorySelectScreen->unk2A2 = TRUE; - gTasks[taskId].data[0] = 1; - gTasks[taskId].func = Task_HandleSelectionScreenChooseMons; + sFactorySelectScreen->fadeSpeciesNameActive = TRUE; + gTasks[taskId].tState = 1; + gTasks[taskId].func = Select_Task_HandleChooseMons; } - else if (gMain.newAndRepeatedKeys & DPAD_UP) - { - PlaySE(SE_SELECT); - Select_UpdateYesNoCursorPosition(-1); - } - else if (gMain.newAndRepeatedKeys & DPAD_DOWN) - { - PlaySE(SE_SELECT); - Select_UpdateYesNoCursorPosition(1); - } - break; } + else if (JOY_NEW(B_BUTTON)) + { + PlaySE(SE_SELECT); + sub_819B958(SELECT_WIN_YES_NO); + sub_819BC9C(); + sFactorySelectScreen->fadeSpeciesNameActive = TRUE; + gTasks[taskId].tState = 1; + gTasks[taskId].func = Select_Task_HandleChooseMons; + } + else if (JOY_REPEAT(DPAD_UP)) + { + PlaySE(SE_SELECT); + Select_UpdateYesNoCursorPosition(-1); + } + else if (JOY_REPEAT(DPAD_DOWN)) + { + PlaySE(SE_SELECT); + Select_UpdateYesNoCursorPosition(1); + } + break; } } -static void Task_HandleSelectionScreenMenu(u8 taskId) +static void Select_Task_HandleMenu(u8 taskId) { - switch (gTasks[taskId].data[0]) + switch (gTasks[taskId].tState) { case 2: if (!sFactorySelectScreen->fromSummaryScreen) - sub_819F2B4(&sFactorySelectScreen->unk294[1].field1, &sFactorySelectScreen->unk2A0, FALSE); - gTasks[taskId].data[0] = 9; + OpenMonPic(&sFactorySelectScreen->monPics[1].bgSpriteId, &sFactorySelectScreen->monPicAnimating, FALSE); + gTasks[taskId].tState = 9; break; case 9: - if (sFactorySelectScreen->unk2A0 != TRUE) + if (sFactorySelectScreen->monPicAnimating != TRUE) { Select_ShowMenuOptions(); sFactorySelectScreen->fromSummaryScreen = FALSE; - gTasks[taskId].data[0] = 3; + gTasks[taskId].tState = 3; } break; case 3: - if (gMain.newKeys & A_BUTTON) + if (JOY_NEW(A_BUTTON)) { u8 retVal; PlaySE(SE_SELECT); retVal = Select_RunMenuOptionFunc(); if (retVal == 1) { - sFactorySelectScreen->unk2A2 = TRUE; - gTasks[taskId].data[0] = 1; - gTasks[taskId].func = Task_HandleSelectionScreenChooseMons; + sFactorySelectScreen->fadeSpeciesNameActive = TRUE; + gTasks[taskId].tState = 1; + gTasks[taskId].func = Select_Task_HandleChooseMons; } else if (retVal == 2) { - gTasks[taskId].data[0] = 10; - gTasks[taskId].func = Task_HandleSelectionScreenYesNo; + gTasks[taskId].tState = 10; + gTasks[taskId].func = Select_Task_HandleYesNo; } else if (retVal == 3) { - gTasks[taskId].data[0] = 11; - gTasks[taskId].func = Task_HandleSelectionScreenChooseMons; + gTasks[taskId].tState = 11; + gTasks[taskId].func = Select_Task_HandleChooseMons; } else { - gTasks[taskId].data[0] = 6; - gTasks[taskId].func = Task_FromSelectScreenToSummaryScreen; + gTasks[taskId].tState = 6; + gTasks[taskId].func = Select_Task_OpenSummaryScreen; } } - else if (gMain.newKeys & B_BUTTON) + else if (JOY_NEW(B_BUTTON)) { PlaySE(SE_SELECT); - CloseMonPic(sFactorySelectScreen->unk294[1], &sFactorySelectScreen->unk2A0, FALSE); - sub_819B958(3); - sFactorySelectScreen->unk2A2 = TRUE; - gTasks[taskId].data[0] = 1; - gTasks[taskId].func = Task_HandleSelectionScreenChooseMons; + CloseMonPic(sFactorySelectScreen->monPics[1], &sFactorySelectScreen->monPicAnimating, FALSE); + sub_819B958(SELECT_WIN_OPTIONS); + sFactorySelectScreen->fadeSpeciesNameActive = TRUE; + gTasks[taskId].tState = 1; + gTasks[taskId].func = Select_Task_HandleChooseMons; } - else if (gMain.newAndRepeatedKeys & DPAD_UP) + else if (JOY_REPEAT(DPAD_UP)) { PlaySE(SE_SELECT); Select_UpdateMenuCursorPosition(-1); } - else if (gMain.newAndRepeatedKeys & DPAD_DOWN) + else if (JOY_REPEAT(DPAD_DOWN)) { PlaySE(SE_SELECT); Select_UpdateMenuCursorPosition(1); @@ -1595,63 +1598,63 @@ static void Task_HandleSelectionScreenMenu(u8 taskId) gPlttBufferUnfaded[228] = gPlttBufferUnfaded[244]; } sFactorySelectScreen->fromSummaryScreen = FALSE; - gTasks[taskId].data[0] = 3; + gTasks[taskId].tState = 3; } break; case 13: Select_ShowMenuOptions(); - gTasks[taskId].data[0] = 12; + gTasks[taskId].tState = 12; break; } } -static void Task_HandleSelectionScreenChooseMons(u8 taskId) +static void Select_Task_HandleChooseMons(u8 taskId) { - if (sFactorySelectScreen->unk2A0 != TRUE) + if (sFactorySelectScreen->monPicAnimating == TRUE) + return; + + switch (gTasks[taskId].tState) { - switch (gTasks[taskId].data[0]) + case 0: + if (!gPaletteFade.active) { - case 0: - if (!gPaletteFade.active) - { - gTasks[taskId].data[0] = 1; - sFactorySelectScreen->unk2A2 = TRUE; - } - break; - case 1: - if (gMain.newKeys & A_BUTTON) - { - PlaySE(SE_SELECT); - sFactorySelectScreen->unk2A2 = FALSE; - gTasks[taskId].data[0] = 2; - gTasks[taskId].func = Task_HandleSelectionScreenMenu; - } - else if (gMain.newAndRepeatedKeys & DPAD_LEFT) - { - PlaySE(SE_SELECT); - Select_UpdateBallCursorPosition(-1); - Select_PrintMonCategory(); - Select_PrintMonSpecies(); - } - else if (gMain.newAndRepeatedKeys & DPAD_RIGHT) - { - PlaySE(SE_SELECT); - Select_UpdateBallCursorPosition(1); - Select_PrintMonCategory(); - Select_PrintMonSpecies(); - } - break; - case 11: - if (gMain.newKeys & A_BUTTON) - { - PlaySE(SE_SELECT); - CloseMonPic(sFactorySelectScreen->unk294[1], &sFactorySelectScreen->unk2A0, FALSE); - Select_PrintSelectMonString(); - sFactorySelectScreen->unk2A2 = TRUE; - gTasks[taskId].data[0] = 1; - } - break; + gTasks[taskId].tState = 1; + sFactorySelectScreen->fadeSpeciesNameActive = TRUE; } + break; + case 1: + if (JOY_NEW(A_BUTTON)) + { + PlaySE(SE_SELECT); + sFactorySelectScreen->fadeSpeciesNameActive = FALSE; + gTasks[taskId].tState = 2; + gTasks[taskId].func = Select_Task_HandleMenu; + } + else if (JOY_REPEAT(DPAD_LEFT)) + { + PlaySE(SE_SELECT); + Select_UpdateBallCursorPosition(-1); + Select_PrintMonCategory(); + Select_PrintMonSpecies(); + } + else if (JOY_REPEAT(DPAD_RIGHT)) + { + PlaySE(SE_SELECT); + Select_UpdateBallCursorPosition(1); + Select_PrintMonCategory(); + Select_PrintMonSpecies(); + } + break; + case 11: + if (JOY_NEW(A_BUTTON)) + { + PlaySE(SE_SELECT); + CloseMonPic(sFactorySelectScreen->monPics[1], &sFactorySelectScreen->monPicAnimating, FALSE); + Select_PrintSelectMonString(); + sFactorySelectScreen->fadeSpeciesNameActive = TRUE; + gTasks[taskId].tState = 1; + } + break; } } @@ -1699,7 +1702,7 @@ static void CreateFrontierFactorySelectableMons(u8 firstMonId) } } -static void CreateTentFactorySelectableMons(u8 firstMonId) +static void CreateSlateportTentSelectableMons(u8 firstMonId) { u8 i, j; u8 ivs = 0; @@ -1793,9 +1796,9 @@ static void sub_819B958(u8 windowId) static void Select_PrintRentalPkmnString(void) { - FillWindowPixelBuffer(0, PIXEL_FILL(0)); - AddTextPrinterParameterized(0, 1, gText_RentalPkmn2, 2, 1, 0, NULL); - CopyWindowToVram(0, 3); + FillWindowPixelBuffer(SELECT_WIN_TITLE, PIXEL_FILL(0)); + AddTextPrinterParameterized(SELECT_WIN_TITLE, 1, gText_RentalPkmn2, 2, 1, 0, NULL); + CopyWindowToVram(SELECT_WIN_TITLE, 3); } static void Select_PrintMonSpecies(void) @@ -1804,19 +1807,19 @@ static void Select_PrintMonSpecies(void) u8 x; u8 monId = sFactorySelectScreen->cursorPos; - FillWindowPixelBuffer(1, PIXEL_FILL(0)); + FillWindowPixelBuffer(SELECT_WIN_SPECIES, PIXEL_FILL(0)); species = GetMonData(&sFactorySelectScreen->mons[monId].monData, MON_DATA_SPECIES, NULL); StringCopy(gStringVar4, gSpeciesNames[species]); x = GetStringRightAlignXOffset(1, gStringVar4, 86); - AddTextPrinterParameterized3(1, 1, x, 1, sSpeciesNameTextColors, 0, gStringVar4); - CopyWindowToVram(1, 2); + AddTextPrinterParameterized3(SELECT_WIN_SPECIES, 1, x, 1, sSpeciesNameTextColors, 0, gStringVar4); + CopyWindowToVram(SELECT_WIN_SPECIES, 2); } static void Select_PrintSelectMonString(void) { const u8 *str = NULL; - FillWindowPixelBuffer(2, PIXEL_FILL(0)); + FillWindowPixelBuffer(SELECT_WIN_INFO, PIXEL_FILL(0)); if (sFactorySelectScreen->selectingMonsState == 1) str = gText_SelectFirstPkmn; else if (sFactorySelectScreen->selectingMonsState == 2) @@ -1826,40 +1829,40 @@ static void Select_PrintSelectMonString(void) else str = gText_TheseThreePkmnOkay; - AddTextPrinterParameterized(2, 1, str, 2, 5, 0, NULL); - CopyWindowToVram(2, 2); + AddTextPrinterParameterized(SELECT_WIN_INFO, 1, str, 2, 5, 0, NULL); + CopyWindowToVram(SELECT_WIN_INFO, 2); } static void Select_PrintCantSelectSameMon(void) { - FillWindowPixelBuffer(2, PIXEL_FILL(0)); - AddTextPrinterParameterized(2, 1, gText_CantSelectSamePkmn, 2, 5, 0, NULL); - CopyWindowToVram(2, 2); + FillWindowPixelBuffer(SELECT_WIN_INFO, PIXEL_FILL(0)); + AddTextPrinterParameterized(SELECT_WIN_INFO, 1, gText_CantSelectSamePkmn, 2, 5, 0, NULL); + CopyWindowToVram(SELECT_WIN_INFO, 2); } static void Select_PrintMenuOptions(void) { u8 selectedId = sFactorySelectScreen->mons[sFactorySelectScreen->cursorPos].selectedId; - PutWindowTilemap(3); - FillWindowPixelBuffer(3, PIXEL_FILL(0)); - AddTextPrinterParameterized3(3, 1, 7, 1, sMenuOptionTextColors, 0, gText_Summary); + PutWindowTilemap(SELECT_WIN_OPTIONS); + FillWindowPixelBuffer(SELECT_WIN_OPTIONS, PIXEL_FILL(0)); + AddTextPrinterParameterized3(SELECT_WIN_OPTIONS, 1, 7, 1, sMenuOptionTextColors, 0, gText_Summary); if (selectedId != 0) - AddTextPrinterParameterized3(3, 1, 7, 17, sMenuOptionTextColors, 0, gText_Deselect); + AddTextPrinterParameterized3(SELECT_WIN_OPTIONS, 1, 7, 17, sMenuOptionTextColors, 0, gText_Deselect); else - AddTextPrinterParameterized3(3, 1, 7, 17, sMenuOptionTextColors, 0, gText_Rent); + AddTextPrinterParameterized3(SELECT_WIN_OPTIONS, 1, 7, 17, sMenuOptionTextColors, 0, gText_Rent); - AddTextPrinterParameterized3(3, 1, 7, 33, sMenuOptionTextColors, 0, gText_Others2); - CopyWindowToVram(3, 3); + AddTextPrinterParameterized3(SELECT_WIN_OPTIONS, 1, 7, 33, sMenuOptionTextColors, 0, gText_Others2); + CopyWindowToVram(SELECT_WIN_OPTIONS, 3); } static void Select_PrintYesNoOptions(void) { - PutWindowTilemap(4); - FillWindowPixelBuffer(4, PIXEL_FILL(0)); - AddTextPrinterParameterized3(4, 1, 7, 1, sMenuOptionTextColors, 0, gText_Yes2); - AddTextPrinterParameterized3(4, 1, 7, 17, sMenuOptionTextColors, 0, gText_No2); - CopyWindowToVram(4, 3); + PutWindowTilemap(SELECT_WIN_YES_NO); + FillWindowPixelBuffer(SELECT_WIN_YES_NO, PIXEL_FILL(0)); + AddTextPrinterParameterized3(SELECT_WIN_YES_NO, 1, 7, 1, sMenuOptionTextColors, 0, gText_Yes2); + AddTextPrinterParameterized3(SELECT_WIN_YES_NO, 1, 7, 17, sMenuOptionTextColors, 0, gText_No2); + CopyWindowToVram(SELECT_WIN_YES_NO, 3); } static u8 Select_RunMenuOptionFunc(void) @@ -1875,15 +1878,15 @@ static u8 Select_OptionRentDeselect(void) if (selectedId == 0 && !Select_AreSpeciesValid(monId)) { Select_PrintCantSelectSameMon(); - sub_819B958(3); + sub_819B958(SELECT_WIN_OPTIONS); return 3; } else { - CloseMonPic(sFactorySelectScreen->unk294[1], &sFactorySelectScreen->unk2A0, FALSE); + CloseMonPic(sFactorySelectScreen->monPics[1], &sFactorySelectScreen->monPicAnimating, FALSE); Select_HandleMonSelectionChange(); Select_PrintSelectMonString(); - sub_819B958(3); + sub_819B958(SELECT_WIN_OPTIONS); if (sFactorySelectScreen->selectingMonsState > 3) return 2; else @@ -1896,7 +1899,7 @@ static u8 sub_819BC9C(void) sub_819C568(); Select_HandleMonSelectionChange(); Select_PrintSelectMonString(); - sub_819B958(3); + sub_819B958(SELECT_WIN_OPTIONS); if (sFactorySelectScreen->selectingMonsState > 3) return 2; else @@ -1910,8 +1913,8 @@ static u8 Select_OptionSummary(void) static u8 Select_OptionOthers(void) { - CloseMonPic(sFactorySelectScreen->unk294[1], &sFactorySelectScreen->unk2A0, FALSE); - sub_819B958(3); + CloseMonPic(sFactorySelectScreen->monPics[1], &sFactorySelectScreen->monPicAnimating, FALSE); + sub_819B958(SELECT_WIN_OPTIONS); return 1; } @@ -1923,17 +1926,17 @@ static void Select_PrintMonCategory(void) u8 monId = sFactorySelectScreen->cursorPos; if (monId < SELECTABLE_MONS_COUNT) { - PutWindowTilemap(5); - FillWindowPixelBuffer(5, PIXEL_FILL(0)); + PutWindowTilemap(SELECT_WIN_MON_CATEGORY); + FillWindowPixelBuffer(SELECT_WIN_MON_CATEGORY, PIXEL_FILL(0)); species = GetMonData(&sFactorySelectScreen->mons[monId].monData, MON_DATA_SPECIES, NULL); CopyMonCategoryText(SpeciesToNationalPokedexNum(species), text); x = GetStringRightAlignXOffset(1, text, 0x76); - AddTextPrinterParameterized(5, 1, text, x, 1, 0, NULL); - CopyWindowToVram(5, 2); + AddTextPrinterParameterized(SELECT_WIN_MON_CATEGORY, 1, text, x, 1, 0, NULL); + CopyWindowToVram(SELECT_WIN_MON_CATEGORY, 2); } } -static void Summary_CreateMonSprite(void) +static void Select_CreateMonSprite(void) { u8 monId = sFactorySelectScreen->cursorPos; struct Pokemon *mon = &sFactorySelectScreen->mons[monId].monData; @@ -1941,16 +1944,16 @@ static void Summary_CreateMonSprite(void) u32 personality = GetMonData(mon, MON_DATA_PERSONALITY, NULL); u32 otId = GetMonData(mon, MON_DATA_OT_ID, NULL); - sFactorySelectScreen->unk294[1].field0 = CreateMonPicSprite_HandleDeoxys(species, otId, personality, TRUE, 88, 32, 15, 0xFFFF); - gSprites[sFactorySelectScreen->unk294[1].field0].centerToCornerVecX = 0; - gSprites[sFactorySelectScreen->unk294[1].field0].centerToCornerVecY = 0; + sFactorySelectScreen->monPics[1].monSpriteId = CreateMonPicSprite_HandleDeoxys(species, otId, personality, TRUE, 88, 32, 15, 0xFFFF); + gSprites[sFactorySelectScreen->monPics[1].monSpriteId].centerToCornerVecX = 0; + gSprites[sFactorySelectScreen->monPics[1].monSpriteId].centerToCornerVecY = 0; - sFactorySelectScreen->unk2A0 = FALSE; + sFactorySelectScreen->monPicAnimating = FALSE; } -static void sub_819BE20(bool8 arg0) +static void Select_SetMonPicAnimating(bool8 animating) { - sFactorySelectScreen->unk2A0 = arg0; + sFactorySelectScreen->monPicAnimating = animating; } static void Select_ReshowMonSprite(void) @@ -1959,19 +1962,19 @@ static void Select_ReshowMonSprite(void) u16 species; u32 personality, otId; - sFactorySelectScreen->unk294[1].field1 = CreateSprite(&sSpriteTemplate_Select_MonPicBgAnim, 120, 64, 1); - StartSpriteAffineAnim(&gSprites[sFactorySelectScreen->unk294[1].field1], 2); + sFactorySelectScreen->monPics[1].bgSpriteId = CreateSprite(&sSpriteTemplate_Select_MonPicBgAnim, 120, 64, 1); + StartSpriteAffineAnim(&gSprites[sFactorySelectScreen->monPics[1].bgSpriteId], 2); mon = &sFactorySelectScreen->mons[sFactorySelectScreen->cursorPos].monData; species = GetMonData(mon, MON_DATA_SPECIES, NULL); personality = GetMonData(mon, MON_DATA_PERSONALITY, NULL); otId = GetMonData(mon, MON_DATA_OT_ID, NULL); - sFactorySelectScreen->unk294[1].field0 = CreateMonPicSprite_HandleDeoxys(species, otId, personality, TRUE, 88, 32, 15, 0xFFFF); - gSprites[sFactorySelectScreen->unk294[1].field0].centerToCornerVecX = 0; - gSprites[sFactorySelectScreen->unk294[1].field0].centerToCornerVecY = 0; + sFactorySelectScreen->monPics[1].monSpriteId = CreateMonPicSprite_HandleDeoxys(species, otId, personality, TRUE, 88, 32, 15, 0xFFFF); + gSprites[sFactorySelectScreen->monPics[1].monSpriteId].centerToCornerVecX = 0; + gSprites[sFactorySelectScreen->monPics[1].monSpriteId].centerToCornerVecY = 0; - gSprites[sFactorySelectScreen->unk294[1].field1].invisible = TRUE; + gSprites[sFactorySelectScreen->monPics[1].bgSpriteId].invisible = TRUE; } static void Select_ShowChosenMonsSprites(void) @@ -1989,14 +1992,14 @@ static void Select_ShowChosenMonsSprites(void) u32 personality = GetMonData(mon, MON_DATA_PERSONALITY, NULL); u32 otId = GetMonData(mon, MON_DATA_OT_ID, NULL); - sFactorySelectScreen->unk294[i].field0 = CreateMonPicSprite_HandleDeoxys(species, otId, personality, TRUE, (i * 72) + 16, 32, i + 13, 0xFFFF); - gSprites[sFactorySelectScreen->unk294[i].field0].centerToCornerVecX = 0; - gSprites[sFactorySelectScreen->unk294[i].field0].centerToCornerVecY = 0; + sFactorySelectScreen->monPics[i].monSpriteId = CreateMonPicSprite_HandleDeoxys(species, otId, personality, TRUE, (i * 72) + 16, 32, i + 13, 0xFFFF); + gSprites[sFactorySelectScreen->monPics[i].monSpriteId].centerToCornerVecX = 0; + gSprites[sFactorySelectScreen->monPics[i].monSpriteId].centerToCornerVecY = 0; break; } } } - sFactorySelectScreen->unk2A0 = FALSE; + sFactorySelectScreen->monPicAnimating = FALSE; } static void sub_819C040(struct Sprite *sprite) @@ -2004,12 +2007,12 @@ static void sub_819C040(struct Sprite *sprite) u8 taskId; if (sprite->affineAnimEnded - && gSprites[sFactorySelectScreen->unk294[0].field1].affineAnimEnded - && gSprites[sFactorySelectScreen->unk294[2].field1].affineAnimEnded) + && gSprites[sFactorySelectScreen->monPics[0].bgSpriteId].affineAnimEnded + && gSprites[sFactorySelectScreen->monPics[2].bgSpriteId].affineAnimEnded) { sprite->invisible = TRUE; - gSprites[sFactorySelectScreen->unk294[0].field1].invisible = TRUE; - gSprites[sFactorySelectScreen->unk294[2].field1].invisible = TRUE; + gSprites[sFactorySelectScreen->monPics[0].bgSpriteId].invisible = TRUE; + gSprites[sFactorySelectScreen->monPics[2].bgSpriteId].invisible = TRUE; taskId = CreateTask(sub_819C1D0, 1); gTasks[taskId].func(taskId); @@ -2021,34 +2024,46 @@ static void sub_819C040(struct Sprite *sprite) static void sub_819C100(struct Sprite *sprite) { if (sprite->affineAnimEnded - && gSprites[sFactorySelectScreen->unk294[0].field1].affineAnimEnded - && gSprites[sFactorySelectScreen->unk294[2].field1].affineAnimEnded) + && gSprites[sFactorySelectScreen->monPics[0].bgSpriteId].affineAnimEnded + && gSprites[sFactorySelectScreen->monPics[2].bgSpriteId].affineAnimEnded) { FreeOamMatrix(sprite->oam.matrixNum); - FreeOamMatrix(gSprites[sFactorySelectScreen->unk294[0].field1].oam.matrixNum); - FreeOamMatrix(gSprites[sFactorySelectScreen->unk294[2].field1].oam.matrixNum); + FreeOamMatrix(gSprites[sFactorySelectScreen->monPics[0].bgSpriteId].oam.matrixNum); + FreeOamMatrix(gSprites[sFactorySelectScreen->monPics[2].bgSpriteId].oam.matrixNum); - sFactorySelectScreen->unk2A0 = FALSE; + sFactorySelectScreen->monPicAnimating = FALSE; - DestroySprite(&gSprites[sFactorySelectScreen->unk294[0].field1]); - DestroySprite(&gSprites[sFactorySelectScreen->unk294[2].field1]); + DestroySprite(&gSprites[sFactorySelectScreen->monPics[0].bgSpriteId]); + DestroySprite(&gSprites[sFactorySelectScreen->monPics[2].bgSpriteId]); DestroySprite(sprite); } } +// Task data for sub_819C1D0, sub_819C2D4, Task_CloseMonPic, and Task_OpenMonPic +#define tWinLeft data[3] +#ifndef UBFIX +#define tWinRight data[24] // UB: Typo? Likely meant data[4], 24 is out of bounds +#else +#define tWinRight data[4] +#endif +#define tWinTop data[5] +#define tWinBottom data[8] +#define tSpriteId data[6] // TODO: Clarify, what sprite +#define tIsSwapScreen data[7] + static void sub_819C1D0(u8 taskId) { struct Task *task = &gTasks[taskId]; - switch (task->data[0]) + switch (task->tState) { case 0: - task->data[3] = 16; - task->data[24] = 224; // BUG: writing outside the array's bounds. - task->data[5] = 64; - task->data[8] = 65; + task->tWinLeft = 16; + task->tWinRight = DISPLAY_WIDTH - 16; + task->tWinTop = 64; + task->tWinBottom = 65; SetGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON); - SetGpuReg(REG_OFFSET_WIN0H, WIN_RANGE(task->data[3], task->data[24])); - SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(task->data[5], task->data[8])); + SetGpuReg(REG_OFFSET_WIN0H, WIN_RANGE(task->tWinLeft, task->tWinRight)); + SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(task->tWinTop, task->tWinBottom)); SetGpuReg(REG_OFFSET_WININ, WININ_WIN0_BG_ALL | WININ_WIN0_CLR | WININ_WIN0_OBJ); SetGpuReg(REG_OFFSET_WINOUT, WINOUT_WIN01_BG0 | WINOUT_WIN01_BG1 | WINOUT_WIN01_BG2 | WINOUT_WIN01_CLR | WINOUT_WIN01_OBJ); break; @@ -2058,16 +2073,16 @@ static void sub_819C1D0(u8 taskId) SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(11, 4)); break; case 2: - task->data[5] -= 4; - task->data[8] += 4; - if (task->data[5] <= 32 || task->data[8] >= 96) + task->tWinTop -= 4; + task->tWinBottom += 4; + if (task->tWinTop <= 32 || task->tWinBottom >= 96) { - task->data[5] = 32; - task->data[8] = 96; + task->tWinTop = 32; + task->tWinBottom = 96; ClearGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON); } - SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(task->data[5], task->data[8])); - if (task->data[5] != 32) + SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(task->tWinTop, task->tWinBottom)); + if (task->tWinTop != 32) return; break; default: @@ -2075,80 +2090,80 @@ static void sub_819C1D0(u8 taskId) Select_ShowChosenMonsSprites(); return; } - task->data[0]++; + task->tState++; } static void sub_819C2D4(u8 taskId) { struct Task *task = &gTasks[taskId]; - switch (task->data[0]) + switch (task->tState) { default: HideBg(3); - gSprites[sFactorySelectScreen->unk294[1].field1].invisible = FALSE; - gSprites[sFactorySelectScreen->unk294[1].field1].callback = sub_819C100; - gSprites[sFactorySelectScreen->unk294[0].field1].invisible = FALSE; - gSprites[sFactorySelectScreen->unk294[0].field1].callback = SpriteCallbackDummy; - gSprites[sFactorySelectScreen->unk294[2].field1].invisible = FALSE; - gSprites[sFactorySelectScreen->unk294[2].field1].callback = SpriteCallbackDummy; - StartSpriteAffineAnim(&gSprites[sFactorySelectScreen->unk294[1].field1], 1); - StartSpriteAffineAnim(&gSprites[sFactorySelectScreen->unk294[0].field1], 1); - StartSpriteAffineAnim(&gSprites[sFactorySelectScreen->unk294[2].field1], 1); + gSprites[sFactorySelectScreen->monPics[1].bgSpriteId].invisible = FALSE; + gSprites[sFactorySelectScreen->monPics[1].bgSpriteId].callback = sub_819C100; + gSprites[sFactorySelectScreen->monPics[0].bgSpriteId].invisible = FALSE; + gSprites[sFactorySelectScreen->monPics[0].bgSpriteId].callback = SpriteCallbackDummy; + gSprites[sFactorySelectScreen->monPics[2].bgSpriteId].invisible = FALSE; + gSprites[sFactorySelectScreen->monPics[2].bgSpriteId].callback = SpriteCallbackDummy; + StartSpriteAffineAnim(&gSprites[sFactorySelectScreen->monPics[1].bgSpriteId], 1); + StartSpriteAffineAnim(&gSprites[sFactorySelectScreen->monPics[0].bgSpriteId], 1); + StartSpriteAffineAnim(&gSprites[sFactorySelectScreen->monPics[2].bgSpriteId], 1); ClearGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON); DestroyTask(taskId); break; case 0: - task->data[3] = 16; - task->data[24] = 224; // BUG: writing outside the array's bounds. - task->data[5] = 32; - task->data[8] = 96; + task->tWinLeft = 16; + task->tWinRight = DISPLAY_WIDTH - 16; + task->tWinTop = 32; + task->tWinBottom = 96; SetGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON); - SetGpuReg(REG_OFFSET_WIN0H, WIN_RANGE(task->data[3], task->data[24])); - SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(task->data[5], task->data[8])); + SetGpuReg(REG_OFFSET_WIN0H, WIN_RANGE(task->tWinLeft, task->tWinRight)); + SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(task->tWinTop, task->tWinBottom)); SetGpuReg(REG_OFFSET_WININ, WININ_WIN0_BG_ALL | WININ_WIN0_CLR | WININ_WIN0_OBJ); SetGpuReg(REG_OFFSET_WINOUT, WINOUT_WIN01_BG0 | WINOUT_WIN01_BG1 | WINOUT_WIN01_BG2 | WINOUT_WIN01_CLR | WINOUT_WIN01_OBJ); - task->data[0]++; + task->tState++; break; case 1: - task->data[5] += 4; - task->data[8] -= 4; - if (task->data[5] >= 64 || task->data[8] <= 65) + task->tWinTop += 4; + task->tWinBottom -= 4; + if (task->tWinTop >= 64 || task->tWinBottom <= 65) { - task->data[5] = 64; - task->data[8] = 65; + task->tWinTop = 64; + task->tWinBottom = 65; } - SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(task->data[5], task->data[8])); - if (task->data[5] == 64) - task->data[0]++; + SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(task->tWinTop, task->tWinBottom)); + if (task->tWinTop == 64) + task->tState++; break; } } static void sub_819C4B4(void) { - sFactorySelectScreen->unk294[1].field1 = CreateSprite(&sSpriteTemplate_Select_MonPicBgAnim, 120, 64, 1); - sFactorySelectScreen->unk294[0].field1 = CreateSprite(&sSpriteTemplate_Select_MonPicBgAnim, 44, 64, 1); - sFactorySelectScreen->unk294[2].field1 = CreateSprite(&sSpriteTemplate_Select_MonPicBgAnim, 196, 64, 1); + sFactorySelectScreen->monPics[1].bgSpriteId = CreateSprite(&sSpriteTemplate_Select_MonPicBgAnim, 120, 64, 1); + sFactorySelectScreen->monPics[0].bgSpriteId = CreateSprite(&sSpriteTemplate_Select_MonPicBgAnim, 44, 64, 1); + sFactorySelectScreen->monPics[2].bgSpriteId = CreateSprite(&sSpriteTemplate_Select_MonPicBgAnim, 196, 64, 1); - gSprites[sFactorySelectScreen->unk294[1].field1].callback = sub_819C040; - gSprites[sFactorySelectScreen->unk294[0].field1].callback = SpriteCallbackDummy; - gSprites[sFactorySelectScreen->unk294[2].field1].callback = SpriteCallbackDummy; + gSprites[sFactorySelectScreen->monPics[1].bgSpriteId].callback = sub_819C040; + gSprites[sFactorySelectScreen->monPics[0].bgSpriteId].callback = SpriteCallbackDummy; + gSprites[sFactorySelectScreen->monPics[2].bgSpriteId].callback = SpriteCallbackDummy; - sFactorySelectScreen->unk2A0 = TRUE; + sFactorySelectScreen->monPicAnimating = TRUE; } static void sub_819C568(void) { u8 taskId; - FreeAndDestroyMonPicSprite(sFactorySelectScreen->unk294[0].field0); - FreeAndDestroyMonPicSprite(sFactorySelectScreen->unk294[1].field0); - FreeAndDestroyMonPicSprite(sFactorySelectScreen->unk294[2].field0); + FreeAndDestroyMonPicSprite(sFactorySelectScreen->monPics[0].monSpriteId); + FreeAndDestroyMonPicSprite(sFactorySelectScreen->monPics[1].monSpriteId); + FreeAndDestroyMonPicSprite(sFactorySelectScreen->monPics[2].monSpriteId); taskId = CreateTask(sub_819C2D4, 1); gTasks[taskId].func(taskId); - sFactorySelectScreen->unk2A0 = TRUE; + sFactorySelectScreen->monPicAnimating = TRUE; } static void Select_SetWinRegs(s16 mWin0H, s16 nWin0H, s16 mWin0V, s16 nWin0V) @@ -2183,56 +2198,56 @@ static bool32 Select_AreSpeciesValid(u16 monId) return TRUE; } -static void Task_SelectFadeSpeciesName(u8 taskId) +static void Select_Task_FadeSpeciesName(u8 taskId) { - switch (gTasks[taskId].data[0]) + switch (gTasks[taskId].tState) { - case 0: - sFactorySelectScreen->unk2A7 = 0; - sFactorySelectScreen->unk2A8 = 0; - sFactorySelectScreen->unk2A6 = TRUE; - gTasks[taskId].data[0] = 1; + case FADESTATE_INIT: + sFactorySelectScreen->fadeSpeciesNameCoeffDelay = 0; + sFactorySelectScreen->fadeSpeciesNameCoeff = 0; + sFactorySelectScreen->fadeSpeciesNameFadeOut = TRUE; + gTasks[taskId].tState = FADESTATE_RUN; break; - case 1: - if (sFactorySelectScreen->unk2A2) + case FADESTATE_RUN: + if (sFactorySelectScreen->fadeSpeciesNameActive) { - if (sFactorySelectScreen->unk2A9) + if (sFactorySelectScreen->faceSpeciesNameDelay) { - gTasks[taskId].data[0] = 2; + gTasks[taskId].tState = FADESTATE_DELAY; } else { - sFactorySelectScreen->unk2A7++; - if (sFactorySelectScreen->unk2A7 > 6) + sFactorySelectScreen->fadeSpeciesNameCoeffDelay++; + if (sFactorySelectScreen->fadeSpeciesNameCoeffDelay > 6) { - sFactorySelectScreen->unk2A7 = 0; - if (!sFactorySelectScreen->unk2A6) - sFactorySelectScreen->unk2A8--; + sFactorySelectScreen->fadeSpeciesNameCoeffDelay = 0; + if (!sFactorySelectScreen->fadeSpeciesNameFadeOut) + sFactorySelectScreen->fadeSpeciesNameCoeff--; else - sFactorySelectScreen->unk2A8++; + sFactorySelectScreen->fadeSpeciesNameCoeff++; } - BlendPalettes(0x4000, sFactorySelectScreen->unk2A8, 0); - if (sFactorySelectScreen->unk2A8 > 5) + BlendPalettes(0x4000, sFactorySelectScreen->fadeSpeciesNameCoeff, 0); + if (sFactorySelectScreen->fadeSpeciesNameCoeff > 5) { - sFactorySelectScreen->unk2A6 = FALSE; + sFactorySelectScreen->fadeSpeciesNameFadeOut = FALSE; } - else if (sFactorySelectScreen->unk2A8 == 0) + else if (sFactorySelectScreen->fadeSpeciesNameCoeff == 0) { - gTasks[taskId].data[0] = 2; - sFactorySelectScreen->unk2A6 = TRUE; + gTasks[taskId].tState = FADESTATE_DELAY; + sFactorySelectScreen->fadeSpeciesNameFadeOut = TRUE; } } } break; - case 2: - if (sFactorySelectScreen->unk2A9 > 14) + case FADESTATE_DELAY: + if (sFactorySelectScreen->faceSpeciesNameDelay > 14) { - sFactorySelectScreen->unk2A9 = 0; - gTasks[taskId].data[0] = 1; + sFactorySelectScreen->faceSpeciesNameDelay = 0; + gTasks[taskId].tState = FADESTATE_RUN; } else { - sFactorySelectScreen->unk2A9++; + sFactorySelectScreen->faceSpeciesNameDelay++; } break; } @@ -2269,246 +2284,256 @@ static void CopySwappedMonData(void) gSaveBlock2Ptr->frontier.rentalMons[sFactorySwapScreen->playerMonId].abilityNum = GetBoxMonData(&gEnemyParty[sFactorySwapScreen->enemyMonId].box, MON_DATA_ABILITY_NUM, NULL); } -static void Task_FromSwapScreenToSummaryScreen(u8 taskId) +static void Swap_Task_OpenSummaryScreen(u8 taskId) { - switch (gTasks[taskId].data[0]) + switch (gTasks[taskId].tState) { case 6: - BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); - gTasks[taskId].data[0] = 7; + BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); + gTasks[taskId].tState = 7; break; case 7: if (!gPaletteFade.active) { DestroyTask(sFactorySwapScreen->fadeSpeciesNameTaskId); - sub_819F444(sFactorySwapScreen->unk2C, &sFactorySwapScreen->unk30); + HideMonPic(sFactorySwapScreen->monPic, &sFactorySwapScreen->monPicAnimating); Swap_DestroyAllSprites(); FREE_AND_SET_NULL(sSwapMenuTilesetBuffer); FREE_AND_SET_NULL(sSwapMonPicBgTilesetBuffer); FREE_AND_SET_NULL(sSwapMenuTilemapBuffer); FREE_AND_SET_NULL(sSwapMonPicBgTilemapBuffer); FreeAllWindowBuffers(); - gTasks[taskId].data[0] = 8; + gTasks[taskId].tState = 8; } break; case 8: DestroyTask(taskId); sFactorySwapScreen->fromSummaryScreen = TRUE; - sFactorySwapScreen->unk24 = gPlttBufferUnfaded[244]; + sFactorySwapScreen->speciesNameColorBackup = gPlttBufferUnfaded[244]; ShowPokemonSummaryScreen(PSS_MODE_NORMAL, gPlayerParty, sFactorySwapScreen->cursorPos, FRONTIER_PARTY_SIZE - 1, CB2_InitSwapScreen); break; } } -static void Task_CloseSwapScreen(u8 taskId) +static void Swap_Task_Exit(u8 taskId) { - if (sFactorySwapScreen->unk30 != TRUE) + if (sFactorySwapScreen->monPicAnimating == TRUE) + return; + + switch (gTasks[taskId].tState) { - switch (gTasks[taskId].data[0]) + case 0: + // Set return value for script + // TRUE if player kept their current pokemon + if (sFactorySwapScreen->monSwapped == TRUE) { - case 0: - // Set return value for script - // TRUE if player kept their current pokemon - if (sFactorySwapScreen->monSwapped == TRUE) - { - gTasks[taskId].data[0]++; - gSpecialVar_Result = FALSE; - } - else - { - gTasks[taskId].data[0] = 2; - gSpecialVar_Result = TRUE; - } - break; - case 1: - if (sFactorySwapScreen->monSwapped == TRUE) - { - sFactorySwapScreen->enemyMonId = sFactorySwapScreen->cursorPos; - CopySwappedMonData(); - } - gTasks[taskId].data[0]++; - break; - case 2: - BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); - gTasks[taskId].data[0]++; - break; - case 3: - if (!UpdatePaletteFade()) - { - DestroyTask(sFactorySwapScreen->fadeSpeciesNameTaskId); - Swap_DestroyAllSprites(); - FREE_AND_SET_NULL(sSwapMenuTilesetBuffer); - FREE_AND_SET_NULL(sSwapMonPicBgTilesetBuffer); - FREE_AND_SET_NULL(sSwapMenuTilemapBuffer); - FREE_AND_SET_NULL(sSwapMonPicBgTilemapBuffer); - FREE_AND_SET_NULL(sFactorySwapScreen); - FreeAllWindowBuffers(); - SetMainCallback2(CB2_ReturnToFieldContinueScript); - DestroyTask(taskId); - } - break; + gTasks[taskId].tState++; + gSpecialVar_Result = FALSE; } + else + { + gTasks[taskId].tState = 2; + gSpecialVar_Result = TRUE; + } + break; + case 1: + if (sFactorySwapScreen->monSwapped == TRUE) + { + sFactorySwapScreen->enemyMonId = sFactorySwapScreen->cursorPos; + CopySwappedMonData(); + } + gTasks[taskId].tState++; + break; + case 2: + BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); + gTasks[taskId].tState++; + break; + case 3: + if (!UpdatePaletteFade()) + { + DestroyTask(sFactorySwapScreen->fadeSpeciesNameTaskId); + Swap_DestroyAllSprites(); + FREE_AND_SET_NULL(sSwapMenuTilesetBuffer); + FREE_AND_SET_NULL(sSwapMonPicBgTilesetBuffer); + FREE_AND_SET_NULL(sSwapMenuTilemapBuffer); + FREE_AND_SET_NULL(sSwapMonPicBgTilemapBuffer); + FREE_AND_SET_NULL(sFactorySwapScreen); + FreeAllWindowBuffers(); + SetMainCallback2(CB2_ReturnToFieldContinueScript); + DestroyTask(taskId); + } + break; } } -static void Task_HandleSwapScreenYesNo(u8 taskId) +#define STATE_SHOW_YES_NO 4 +#define STATE_HANDLE_INPUT 5 + +#define tSaidYes data[1] +#define tFollowUpTaskState data[5] +#define tFollowUpTaskPtrHi data[6] +#define tFollowUpTaskPtrLo data[7] + +static void Swap_Task_HandleYesNo(u8 taskId) { u16 loPtr, hiPtr; - if (sFactorySwapScreen->unk30 != TRUE) + if (sFactorySwapScreen->monPicAnimating == TRUE) + return; + + switch (gTasks[taskId].tState) { - switch (gTasks[taskId].data[0]) + case STATE_SHOW_YES_NO: + Swap_ShowYesNoOptions(); + gTasks[taskId].tState = STATE_HANDLE_INPUT; + break; + case STATE_HANDLE_INPUT: + if (JOY_NEW(A_BUTTON)) { - case 4: - Swap_ShowYesNoOptions(); - gTasks[taskId].data[0] = 5; - break; - case 5: - if (gMain.newKeys & A_BUTTON) + PlaySE(SE_SELECT); + if (sFactorySwapScreen->yesNoCursorPos == 0) { - PlaySE(SE_SELECT); - if (sFactorySwapScreen->yesNoCursorPos == 0) - { - gTasks[taskId].data[1] = 1; - hiPtr = gTasks[taskId].data[6]; - loPtr = gTasks[taskId].data[7]; - gTasks[taskId].func = (void*)((hiPtr << 16) | loPtr); - } - else - { - gTasks[taskId].data[1] = 0; - sub_819EA64(4); - hiPtr = gTasks[taskId].data[6]; - loPtr = gTasks[taskId].data[7]; - gTasks[taskId].func = (void*)((hiPtr << 16) | loPtr); - } - } - else if (gMain.newKeys & B_BUTTON) - { - PlaySE(SE_SELECT); - gTasks[taskId].data[1] = 0; - sub_819EA64(4); - hiPtr = gTasks[taskId].data[6]; - loPtr = gTasks[taskId].data[7]; + // Selected Yes + gTasks[taskId].tSaidYes = TRUE; + hiPtr = gTasks[taskId].tFollowUpTaskPtrHi; + loPtr = gTasks[taskId].tFollowUpTaskPtrLo; gTasks[taskId].func = (void*)((hiPtr << 16) | loPtr); } - else if (gMain.newAndRepeatedKeys & DPAD_UP) + else { - PlaySE(SE_SELECT); - Swap_UpdateYesNoCursorPosition(-1); + // Selected No + gTasks[taskId].tSaidYes = FALSE; + Swap_ErasePopupMenu(SWAP_WIN_YES_NO); + hiPtr = gTasks[taskId].tFollowUpTaskPtrHi; + loPtr = gTasks[taskId].tFollowUpTaskPtrLo; + gTasks[taskId].func = (void*)((hiPtr << 16) | loPtr); } - else if (gMain.newAndRepeatedKeys & DPAD_DOWN) - { - PlaySE(SE_SELECT); - Swap_UpdateYesNoCursorPosition(1); - } - break; } + else if (JOY_NEW(B_BUTTON)) + { + PlaySE(SE_SELECT); + gTasks[taskId].tSaidYes = FALSE; + Swap_ErasePopupMenu(SWAP_WIN_YES_NO); + hiPtr = gTasks[taskId].tFollowUpTaskPtrHi; + loPtr = gTasks[taskId].tFollowUpTaskPtrLo; + gTasks[taskId].func = (void*)((hiPtr << 16) | loPtr); + } + else if (JOY_REPEAT(DPAD_UP)) + { + PlaySE(SE_SELECT); + Swap_UpdateYesNoCursorPosition(-1); + } + else if (JOY_REPEAT(DPAD_DOWN)) + { + PlaySE(SE_SELECT); + Swap_UpdateYesNoCursorPosition(1); + } + break; } } -static void sub_819CBDC(u8 taskId) +static void Swap_HandleQuitSwappingResposne(u8 taskId) { - if (gTasks[taskId].data[1] == 1) + if (gTasks[taskId].tSaidYes == TRUE) { - gTasks[taskId].data[0] = 0; - gTasks[taskId].func = Task_CloseSwapScreen; + gTasks[taskId].tState = 0; + gTasks[taskId].func = Swap_Task_Exit; } else { - gTasks[taskId].data[0] = 0; - gTasks[taskId].data[6] = (u32)(Task_HandleSwapScreenChooseMons) >> 16; - gTasks[taskId].data[7] = (u32)(Task_HandleSwapScreenChooseMons); - gTasks[taskId].data[5] = 1; + gTasks[taskId].tState = 0; + gTasks[taskId].tFollowUpTaskPtrHi = (u32)(Swap_Task_HandleChooseMons) >> 16; + gTasks[taskId].tFollowUpTaskPtrLo = (u32)(Swap_Task_HandleChooseMons); + gTasks[taskId].tFollowUpTaskState = 1; gTasks[taskId].func = sub_819D770; } } -static void sub_819CC24(u8 taskId) +static void Swap_AskQuitSwapping(u8 taskId) { - if (gTasks[taskId].data[0] == 0) + if (gTasks[taskId].tState == 0) { Swap_PrintOnInfoWindow(gText_QuitSwapping); sFactorySwapScreen->monSwapped = FALSE; - gTasks[taskId].data[0] = 4; - gTasks[taskId].data[6] = (u32)(sub_819CBDC) >> 16; - gTasks[taskId].data[7] = (u32)(sub_819CBDC); - gTasks[taskId].func = Task_HandleSwapScreenYesNo; + gTasks[taskId].tState = STATE_SHOW_YES_NO; + gTasks[taskId].tFollowUpTaskPtrHi = (u32)(Swap_HandleQuitSwappingResposne) >> 16; + gTasks[taskId].tFollowUpTaskPtrLo = (u32)(Swap_HandleQuitSwappingResposne); + gTasks[taskId].func = Swap_Task_HandleYesNo; } } -static void sub_819CC74(u8 taskId) +static void Swap_HandleAcceptMonResponse(u8 taskId) { - CloseMonPic(sFactorySwapScreen->unk2C, &sFactorySwapScreen->unk30, TRUE); - if (gTasks[taskId].data[1] == 1) + CloseMonPic(sFactorySwapScreen->monPic, &sFactorySwapScreen->monPicAnimating, TRUE); + if (gTasks[taskId].tSaidYes == TRUE) { - gTasks[taskId].data[0] = 0; - gTasks[taskId].func = Task_CloseSwapScreen; + gTasks[taskId].tState = 0; + gTasks[taskId].func = Swap_Task_Exit; } else { - gTasks[taskId].data[0] = 0; - gTasks[taskId].data[6] = (u32)(Task_HandleSwapScreenChooseMons) >> 16; - gTasks[taskId].data[7] = (u32)(Task_HandleSwapScreenChooseMons); - gTasks[taskId].data[5] = 1; + gTasks[taskId].tState = 0; + gTasks[taskId].tFollowUpTaskPtrHi = (u32)(Swap_Task_HandleChooseMons) >> 16; + gTasks[taskId].tFollowUpTaskPtrLo = (u32)(Swap_Task_HandleChooseMons); + gTasks[taskId].tFollowUpTaskState = 1; gTasks[taskId].func = sub_819D770; } } -static void sub_819CCD4(u8 taskId) +static void Swap_AskAcceptMon(u8 taskId) { - if (gTasks[taskId].data[0] == 0) + if (gTasks[taskId].tState == 0) { - sub_819F2B4(&sFactorySwapScreen->unk2C.field1, &sFactorySwapScreen->unk30, TRUE); + OpenMonPic(&sFactorySwapScreen->monPic.bgSpriteId, &sFactorySwapScreen->monPicAnimating, TRUE); Swap_PrintOnInfoWindow(gText_AcceptThisPkmn); sFactorySwapScreen->monSwapped = TRUE; - gTasks[taskId].data[0] = 4; - gTasks[taskId].data[6] = (u32)(sub_819CC74) >> 16; - gTasks[taskId].data[7] = (u32)(sub_819CC74); - gTasks[taskId].func = Task_HandleSwapScreenYesNo; + gTasks[taskId].tState = STATE_SHOW_YES_NO; + gTasks[taskId].tFollowUpTaskPtrHi = (u32)(Swap_HandleAcceptMonResponse) >> 16; + gTasks[taskId].tFollowUpTaskPtrLo = (u32)(Swap_HandleAcceptMonResponse); + gTasks[taskId].func = Swap_Task_HandleYesNo; } } -static void Task_HandleSwapScreenMenu(u8 taskId) +static void Swap_Task_HandleMenu(u8 taskId) { - switch (gTasks[taskId].data[0]) + switch (gTasks[taskId].tState) { case 2: if (!sFactorySwapScreen->fromSummaryScreen) - sub_819F2B4(&sFactorySwapScreen->unk2C.field1, &sFactorySwapScreen->unk30, TRUE); - gTasks[taskId].data[0] = 9; + OpenMonPic(&sFactorySwapScreen->monPic.bgSpriteId, &sFactorySwapScreen->monPicAnimating, TRUE); + gTasks[taskId].tState = 9; break; case 9: - if (sFactorySwapScreen->unk30 != TRUE) + if (sFactorySwapScreen->monPicAnimating != TRUE) { Swap_ShowMenuOptions(); - gTasks[taskId].data[0] = 3; + gTasks[taskId].tState = 3; } break; case 3: - if (sFactorySwapScreen->unk30 != TRUE) + if (sFactorySwapScreen->monPicAnimating != TRUE) { - if (gMain.newKeys & A_BUTTON) + if (JOY_NEW(A_BUTTON)) { PlaySE(SE_SELECT); Swap_RunMenuOptionFunc(taskId); } - else if (gMain.newKeys & B_BUTTON) + else if (JOY_NEW(B_BUTTON)) { PlaySE(SE_SELECT); - CloseMonPic(sFactorySwapScreen->unk2C, &sFactorySwapScreen->unk30, TRUE); - sub_819EA64(3); - gTasks[taskId].data[0] = 0; - gTasks[taskId].data[6] = (u32)(Task_HandleSwapScreenChooseMons) >> 16; - gTasks[taskId].data[7] = (u32)(Task_HandleSwapScreenChooseMons); - gTasks[taskId].data[5] = 1; + CloseMonPic(sFactorySwapScreen->monPic, &sFactorySwapScreen->monPicAnimating, TRUE); + Swap_ErasePopupMenu(SWAP_WIN_OPTIONS); + gTasks[taskId].tState = 0; + gTasks[taskId].tFollowUpTaskPtrHi = (u32)(Swap_Task_HandleChooseMons) >> 16; + gTasks[taskId].tFollowUpTaskPtrLo = (u32)(Swap_Task_HandleChooseMons); + gTasks[taskId].tFollowUpTaskState = 1; gTasks[taskId].func = sub_819D770; } - else if (gMain.newAndRepeatedKeys & DPAD_UP) + else if (JOY_REPEAT(DPAD_UP)) { Swap_UpdateMenuCursorPosition(-1); } - else if (gMain.newAndRepeatedKeys & DPAD_DOWN) + else if (JOY_REPEAT(DPAD_DOWN)) { Swap_UpdateMenuCursorPosition(1); } @@ -2517,57 +2542,57 @@ static void Task_HandleSwapScreenMenu(u8 taskId) } } -static void Task_HandleSwapScreenChooseMons(u8 taskId) +static void Swap_Task_HandleChooseMons(u8 taskId) { - switch (gTasks[taskId].data[0]) + switch (gTasks[taskId].tState) { case 0: if (!gPaletteFade.active) { - sFactorySwapScreen->unk22 = TRUE; - gTasks[taskId].data[0] = 1; + sFactorySwapScreen->fadeSpeciesNameActive = TRUE; + gTasks[taskId].tState = 1; } break; case 1: - if (gMain.newKeys & A_BUTTON) + if (JOY_NEW(A_BUTTON)) { PlaySE(SE_SELECT); - sFactorySwapScreen->unk22 = FALSE; + sFactorySwapScreen->fadeSpeciesNameActive = FALSE; Swap_PrintMonSpecies2(); sub_819EAC0(); Swap_RunActionFunc(taskId); } - else if (gMain.newKeys & B_BUTTON) + else if (JOY_NEW(B_BUTTON)) { PlaySE(SE_SELECT); - sFactorySwapScreen->unk22 = FALSE; + sFactorySwapScreen->fadeSpeciesNameActive = FALSE; Swap_PrintMonSpecies2(); sub_819EAC0(); - gTasks[taskId].data[6] = (u32)(sub_819CC24) >> 16; - gTasks[taskId].data[7] = (u32)(sub_819CC24); - gTasks[taskId].data[0] = 0; - gTasks[taskId].data[5] = 0; + gTasks[taskId].tFollowUpTaskPtrHi = (u32)(Swap_AskQuitSwapping) >> 16; + gTasks[taskId].tFollowUpTaskPtrLo = (u32)(Swap_AskQuitSwapping); + gTasks[taskId].tState = 0; + gTasks[taskId].tFollowUpTaskState = 0; gTasks[taskId].func = sub_819D588; } - else if (gMain.newAndRepeatedKeys & DPAD_LEFT) + else if (JOY_REPEAT(DPAD_LEFT)) { Swap_UpdateBallCursorPosition(-1); Swap_PrintMonCategory(); Swap_PrintMonSpecies(); } - else if (gMain.newAndRepeatedKeys & DPAD_RIGHT) + else if (JOY_REPEAT(DPAD_RIGHT)) { Swap_UpdateBallCursorPosition(1); Swap_PrintMonCategory(); Swap_PrintMonSpecies(); } - else if (gMain.newAndRepeatedKeys & DPAD_DOWN) + else if (JOY_REPEAT(DPAD_DOWN)) { Swap_UpdateActionCursorPosition(1); Swap_PrintMonCategory(); Swap_PrintMonSpecies(); } - else if (gMain.newAndRepeatedKeys & DPAD_UP) + else if (JOY_REPEAT(DPAD_UP)) { Swap_UpdateActionCursorPosition(-1); Swap_PrintMonCategory(); @@ -2577,88 +2602,88 @@ static void Task_HandleSwapScreenChooseMons(u8 taskId) } } -static void Task_SwapFadeSpeciesName(u8 taskId) +static void Swap_Task_FadeSpeciesName(u8 taskId) { - switch (gTasks[taskId].data[0]) + switch (gTasks[taskId].tState) { - case 0: - sFactorySwapScreen->unk27 = 0; - sFactorySwapScreen->unk28 = 0; - sFactorySwapScreen->unk26 = TRUE; - gTasks[taskId].data[0] = 1; + case FADESTATE_INIT: + sFactorySwapScreen->fadeSpeciesNameCoeffDelay = 0; + sFactorySwapScreen->fadeSpeciesNameCoeff = 0; + sFactorySwapScreen->fadeSpeciesNameFadeOut = TRUE; + gTasks[taskId].tState = FADESTATE_RUN; break; - case 1: - if (sFactorySwapScreen->unk22) + case FADESTATE_RUN: + if (sFactorySwapScreen->fadeSpeciesNameActive) { - if (sFactorySwapScreen->unk29) + if (sFactorySwapScreen->faceSpeciesNameDelay) { - gTasks[taskId].data[0] = 2; + gTasks[taskId].tState = FADESTATE_DELAY; } else { - sFactorySwapScreen->unk27++; - if (sFactorySwapScreen->unk27 > 6) + sFactorySwapScreen->fadeSpeciesNameCoeffDelay++; + if (sFactorySwapScreen->fadeSpeciesNameCoeffDelay > 6) { - sFactorySwapScreen->unk27 = 0; - if (!sFactorySwapScreen->unk26) - sFactorySwapScreen->unk28--; + sFactorySwapScreen->fadeSpeciesNameCoeffDelay = 0; + if (!sFactorySwapScreen->fadeSpeciesNameFadeOut) + sFactorySwapScreen->fadeSpeciesNameCoeff--; else - sFactorySwapScreen->unk28++; + sFactorySwapScreen->fadeSpeciesNameCoeff++; } - BlendPalettes(0x4000, sFactorySwapScreen->unk28, 0); - if (sFactorySwapScreen->unk28 > 5) + BlendPalettes(0x4000, sFactorySwapScreen->fadeSpeciesNameCoeff, 0); + if (sFactorySwapScreen->fadeSpeciesNameCoeff > 5) { - sFactorySwapScreen->unk26 = FALSE; + sFactorySwapScreen->fadeSpeciesNameFadeOut = FALSE; } - else if (sFactorySwapScreen->unk28 == 0) + else if (sFactorySwapScreen->fadeSpeciesNameCoeff == 0) { - gTasks[taskId].data[0] = 2; - sFactorySwapScreen->unk26 = TRUE; + gTasks[taskId].tState = FADESTATE_DELAY; + sFactorySwapScreen->fadeSpeciesNameFadeOut = TRUE; } } } break; - case 2: - if (sFactorySwapScreen->unk29 > 14) + case FADESTATE_DELAY: + if (sFactorySwapScreen->faceSpeciesNameDelay > 14) { - sFactorySwapScreen->unk29 = 0; - gTasks[taskId].data[0] = 1; + sFactorySwapScreen->faceSpeciesNameDelay = 0; + gTasks[taskId].tState = FADESTATE_RUN; } else { - sFactorySwapScreen->unk29++; + sFactorySwapScreen->faceSpeciesNameDelay++; } break; } } -static void Task_SwapFadeSpeciesName2(u8 taskId) +static void Swap_Task_FadeSpeciesName2(u8 taskId) { - switch (gTasks[taskId].data[0]) + switch (gTasks[taskId].tState) { case 0: - sFactorySwapScreen->unk27 = 0; + sFactorySwapScreen->fadeSpeciesNameCoeffDelay = 0; gTasks[taskId].data[4] = 0; - gTasks[taskId].data[0]++; + gTasks[taskId].tState++; break; case 1: LoadPalette(&gPlttBufferUnfaded[0xF0], 0xE0, 0xA); - gTasks[taskId].data[0]++; + gTasks[taskId].tState++; break; case 2: - if (sFactorySwapScreen->unk28 > 15) + if (sFactorySwapScreen->fadeSpeciesNameCoeff > 15) { gTasks[taskId].data[4] = 1; - gTasks[taskId].data[0]++; + gTasks[taskId].tState++; } - sFactorySwapScreen->unk27++; - if (sFactorySwapScreen->unk27 > 3) + sFactorySwapScreen->fadeSpeciesNameCoeffDelay++; + if (sFactorySwapScreen->fadeSpeciesNameCoeffDelay > 3) { - sFactorySwapScreen->unk27 = 0; + sFactorySwapScreen->fadeSpeciesNameCoeffDelay = 0; gPlttBufferUnfaded[244] = gPlttBufferFaded[228]; - sFactorySwapScreen->unk28++; + sFactorySwapScreen->fadeSpeciesNameCoeff++; } - BlendPalettes(0x4000, sFactorySwapScreen->unk28, 0); + BlendPalettes(0x4000, sFactorySwapScreen->fadeSpeciesNameCoeff, 0); break; } } @@ -2669,13 +2694,13 @@ static void sub_819D12C(u8 taskId) u8 var_2C; bool8 destroyTask; - switch (gTasks[taskId].data[0]) + switch (gTasks[taskId].tState) { case 0: gTasks[taskId].data[1] = 0; gTasks[taskId].data[2] = 0; gTasks[taskId].data[3] = 0; - gTasks[taskId].data[0] = 1; + gTasks[taskId].tState = 1; break; case 1: var_2C = 0; @@ -2721,7 +2746,7 @@ static void sub_819D12C(u8 taskId) destroyTask = FALSE; } - if (gSprites[sFactorySwapScreen->ballSpriteIds[i]].pos1.x - 16 > 240) + if (gSprites[sFactorySwapScreen->ballSpriteIds[i]].pos1.x - 16 > DISPLAY_WIDTH) { var_2C = gSprites[sFactorySwapScreen->ballSpriteIds[i]].pos1.x; gSprites[sFactorySwapScreen->ballSpriteIds[i]].pos1.x = -16; @@ -2751,50 +2776,50 @@ static void sub_819D324(u8 taskId) if (gTasks[taskId].data[2] == 1) r4 *= -1; - switch (gTasks[taskId].data[0]) + switch (gTasks[taskId].tState) { case 0: - currPosX = gSprites[sFactorySwapScreen->unk8[0][0]].pos1.x; + currPosX = gSprites[sFactorySwapScreen->pkmnForSwapButtonSpriteIds[0][0]].pos1.x; if (!gTasks[taskId].data[2]) { - if (currPosX + r4 < 240) + if (currPosX + r4 < DISPLAY_WIDTH) { r1 = TRUE; } else { r1 = FALSE; - posX = 240; + posX = DISPLAY_WIDTH; } } else { - if (currPosX + r4 > 160) + if (currPosX + r4 > DISPLAY_HEIGHT) { r1 = TRUE; } else { r1 = FALSE; - posX = 160; + posX = DISPLAY_HEIGHT; } } if (r1 == TRUE) { - for (i = 0; i < 3; i++) + for (i = 0; i < ARRAY_COUNT(sFactorySwapScreen->pkmnForSwapButtonSpriteIds[0]); i++) { - for (j = 0; j < 2; j++) - gSprites[sFactorySwapScreen->unk8[j][i]].pos1.x += r4; + for (j = 0; j < ARRAY_COUNT(sFactorySwapScreen->pkmnForSwapButtonSpriteIds); j++) + gSprites[sFactorySwapScreen->pkmnForSwapButtonSpriteIds[j][i]].pos1.x += r4; } } else { - for (j = 0; j < 2; j++) + for (j = 0; j < ARRAY_COUNT(sFactorySwapScreen->pkmnForSwapButtonSpriteIds); j++) { - gSprites[sFactorySwapScreen->unk8[j][0]].pos1.x = posX; - gSprites[sFactorySwapScreen->unk8[j][1]].pos1.x = posX + 16; - gSprites[sFactorySwapScreen->unk8[j][2]].pos1.x = posX + 48; + gSprites[sFactorySwapScreen->pkmnForSwapButtonSpriteIds[j][0]].pos1.x = posX; + gSprites[sFactorySwapScreen->pkmnForSwapButtonSpriteIds[j][1]].pos1.x = posX + 16; + gSprites[sFactorySwapScreen->pkmnForSwapButtonSpriteIds[j][2]].pos1.x = posX + 48; } taskId2 = gTasks[taskId].data[1]; gTasks[taskId2].data[3] = 1; @@ -2802,46 +2827,46 @@ static void sub_819D324(u8 taskId) } break; case 1: - currPosX = gSprites[sFactorySwapScreen->unkE[0][0]].pos1.x; + currPosX = gSprites[sFactorySwapScreen->cancelButtonSpriteIds[0][0]].pos1.x; if (!gTasks[taskId].data[2]) { - if (currPosX + r4 < 240) + if (currPosX + r4 < DISPLAY_WIDTH) { r1 = TRUE; } else { r1 = FALSE; - posX = 240; + posX = DISPLAY_WIDTH; } } else { - if (currPosX + r4 > 192) + if (currPosX + r4 > DISPLAY_HEIGHT + 32) { r1 = TRUE; } else { r1 = FALSE; - posX = 192; + posX = DISPLAY_HEIGHT + 32; } } if (r1 == TRUE) { - for (i = 0; i < 2; i++) + for (i = 0; i < ARRAY_COUNT(sFactorySwapScreen->cancelButtonSpriteIds); i++) { - for (j = 0; j < 2; j++) - gSprites[sFactorySwapScreen->unkE[j][i]].pos1.x += r4; + for (j = 0; j < ARRAY_COUNT(sFactorySwapScreen->cancelButtonSpriteIds[0]); j++) + gSprites[sFactorySwapScreen->cancelButtonSpriteIds[j][i]].pos1.x += r4; } } else { - for (j = 0; j < 2; j++) + for (j = 0; j < ARRAY_COUNT(sFactorySwapScreen->cancelButtonSpriteIds); j++) { - gSprites[sFactorySwapScreen->unkE[j][0]].pos1.x = posX; - gSprites[sFactorySwapScreen->unkE[j][1]].pos1.x = posX + 16; + gSprites[sFactorySwapScreen->cancelButtonSpriteIds[j][0]].pos1.x = posX; + gSprites[sFactorySwapScreen->cancelButtonSpriteIds[j][1]].pos1.x = posX + 16; } taskId2 = gTasks[taskId].data[1]; gTasks[taskId2].data[4] = 1; @@ -2854,39 +2879,39 @@ static void sub_819D324(u8 taskId) static void sub_819D588(u8 taskId) { u8 anotherTaskId; - u16 loPtr, hiPtr; + u16 hiPtr, loPtr; - switch (gTasks[taskId].data[0]) + switch (gTasks[taskId].tState) { case 0: LoadPalette(sSwapText_Pal, 0xE0, sizeof(sSwapText_Pal)); Swap_PrintActionStrings(); - PutWindowTilemap(5); - gTasks[taskId].data[0]++; + PutWindowTilemap(SWAP_WIN_5); + gTasks[taskId].tState++; break; case 1: - sub_819EA64(3); - gTasks[taskId].data[0]++; + Swap_ErasePopupMenu(SWAP_WIN_OPTIONS); + gTasks[taskId].tState++; break; case 2: - BeginNormalPaletteFade(0x4000, 0, 0, 0x10, sPokeballGray_Pal[37]); - gTasks[taskId].data[0]++; + BeginNormalPaletteFade(0x4000, 0, 0, 16, sPokeballGray_Pal[37]); + gTasks[taskId].tState++; break; case 3: if (!gPaletteFade.active) { - FillWindowPixelBuffer(5, PIXEL_FILL(0)); - CopyWindowToVram(5, 2); + FillWindowPixelBuffer(SWAP_WIN_5, PIXEL_FILL(0)); + CopyWindowToVram(SWAP_WIN_5, 2); if (sFactorySwapScreen->inEnemyScreen == TRUE) { anotherTaskId = CreateTask(sub_819D324, 0); gTasks[taskId].data[3] = 0; gTasks[anotherTaskId].data[1] = taskId; - gTasks[anotherTaskId].data[0] = 0; + gTasks[anotherTaskId].tState = 0; gTasks[anotherTaskId].data[2] = 0; gTasks[anotherTaskId].data[3] = 6; gTasks[taskId].data[2] = 5; - gTasks[taskId].data[0]++; + gTasks[taskId].tState++; } else { @@ -2894,10 +2919,10 @@ static void sub_819D588(u8 taskId) gTasks[taskId].data[3] = 1; gTasks[taskId].data[4] = 0; gTasks[anotherTaskId].data[1] = taskId; - gTasks[anotherTaskId].data[0] = 1; + gTasks[anotherTaskId].tState = 1; gTasks[anotherTaskId].data[2] = 0; gTasks[anotherTaskId].data[3] = 6; - gTasks[taskId].data[0] += 2; + gTasks[taskId].tState += 2; } } break; @@ -2907,10 +2932,10 @@ static void sub_819D588(u8 taskId) anotherTaskId = CreateTask(sub_819D324, 0); gTasks[taskId].data[4] = 0; gTasks[anotherTaskId].data[1] = taskId; - gTasks[anotherTaskId].data[0] = 1; + gTasks[anotherTaskId].tState = 1; gTasks[anotherTaskId].data[2] = 0; gTasks[anotherTaskId].data[3] = 6; - gTasks[taskId].data[0]++; + gTasks[taskId].tState++; } else { @@ -2920,10 +2945,10 @@ static void sub_819D588(u8 taskId) case 5: if (gTasks[taskId].data[3] == 1 && gTasks[taskId].data[4] == 1) { - gTasks[taskId].data[0] = gTasks[taskId].data[5]; - loPtr = gTasks[taskId].data[6]; - hiPtr = gTasks[taskId].data[7]; - gTasks[taskId].func = (void *)((loPtr << 0x10) | (hiPtr)); + gTasks[taskId].tState = gTasks[taskId].tFollowUpTaskState; + hiPtr = gTasks[taskId].tFollowUpTaskPtrHi; + loPtr = gTasks[taskId].tFollowUpTaskPtrLo; + gTasks[taskId].func = (void *)((hiPtr << 16) | (loPtr)); } break; } @@ -2932,11 +2957,11 @@ static void sub_819D588(u8 taskId) static void sub_819D770(u8 taskId) { u8 anotherTaskId; - u16 loPtr, hiPtr; - if (sFactorySwapScreen->unk30 == TRUE) + u16 hiPtr, loPtr; + if (sFactorySwapScreen->monPicAnimating == TRUE) return; - switch (gTasks[taskId].data[0]) + switch (gTasks[taskId].tState) { case 0: if (sFactorySwapScreen->inEnemyScreen == TRUE) @@ -2944,11 +2969,11 @@ static void sub_819D770(u8 taskId) anotherTaskId = CreateTask(sub_819D324, 0); gTasks[taskId].data[3] = 0; gTasks[anotherTaskId].data[1] = taskId; - gTasks[anotherTaskId].data[0] = 0; + gTasks[anotherTaskId].tState = 0; gTasks[anotherTaskId].data[2] = 1; gTasks[anotherTaskId].data[3] = 6; gTasks[taskId].data[2] = 10; - gTasks[taskId].data[0]++; + gTasks[taskId].tState++; } else { @@ -2956,10 +2981,10 @@ static void sub_819D770(u8 taskId) gTasks[taskId].data[3] = 1; gTasks[taskId].data[4] = 0; gTasks[anotherTaskId].data[1] = taskId; - gTasks[anotherTaskId].data[0] = 1; + gTasks[anotherTaskId].tState = 1; gTasks[anotherTaskId].data[2] = 1; gTasks[anotherTaskId].data[3] = 6; - gTasks[taskId].data[0] += 2; + gTasks[taskId].tState += 2; } break; case 1: @@ -2968,10 +2993,10 @@ static void sub_819D770(u8 taskId) anotherTaskId = CreateTask(sub_819D324, 0); gTasks[taskId].data[4] = 0; gTasks[anotherTaskId].data[1] = taskId; - gTasks[anotherTaskId].data[0] = 1; + gTasks[anotherTaskId].tState = 1; gTasks[anotherTaskId].data[2] = 1; gTasks[anotherTaskId].data[3] = 6; - gTasks[taskId].data[0]++; + gTasks[taskId].tState++; } else { @@ -2983,30 +3008,30 @@ static void sub_819D770(u8 taskId) { gPlttBufferFaded[226] = sPokeballGray_Pal[37]; Swap_PrintActionStrings(); - PutWindowTilemap(5); - gTasks[taskId].data[0]++; + PutWindowTilemap(SWAP_WIN_5); + gTasks[taskId].tState++; } break; case 3: - BeginNormalPaletteFade(0x4000, 0, 0x10, 0, sPokeballGray_Pal[37]); - gTasks[taskId].data[0]++; + BeginNormalPaletteFade(0x4000, 0, 16, 0, sPokeballGray_Pal[37]); + gTasks[taskId].tState++; break; case 4: if (!gPaletteFade.active) { Swap_PrintOneActionString(0); - gTasks[taskId].data[0]++; + gTasks[taskId].tState++; } break; case 5: Swap_PrintOneActionString(1); - PutWindowTilemap(3); - gTasks[taskId].data[0]++; + PutWindowTilemap(SWAP_WIN_OPTIONS); + gTasks[taskId].tState++; break; case 6: - FillWindowPixelBuffer(5, PIXEL_FILL(0)); - CopyWindowToVram(5, 2); - gTasks[taskId].data[0]++; + FillWindowPixelBuffer(SWAP_WIN_5, PIXEL_FILL(0)); + CopyWindowToVram(SWAP_WIN_5, 2); + gTasks[taskId].tState++; break; case 7: if (!sFactorySwapScreen->inEnemyScreen) @@ -3016,16 +3041,16 @@ static void sub_819D770(u8 taskId) if (sFactorySwapScreen->cursorPos < FRONTIER_PARTY_SIZE) gSprites[sFactorySwapScreen->cursorSpriteId].invisible = FALSE; Swap_PrintMonCategory(); - gTasks[taskId].data[0]++; + gTasks[taskId].tState++; break; case 8: Swap_PrintMonSpecies3(); sub_819EADC(); - sFactorySwapScreen->unk22 = TRUE; - gTasks[taskId].data[0] = gTasks[taskId].data[5]; - loPtr = gTasks[taskId].data[6]; - hiPtr = gTasks[taskId].data[7]; - gTasks[taskId].func = (void *)((loPtr << 0x10) | (hiPtr)); + sFactorySwapScreen->fadeSpeciesNameActive = TRUE; + gTasks[taskId].tState = gTasks[taskId].tFollowUpTaskState; + hiPtr = gTasks[taskId].tFollowUpTaskPtrHi; + loPtr = gTasks[taskId].tFollowUpTaskPtrLo; + gTasks[taskId].func = (void *)((hiPtr << 16) | (loPtr)); break; } } @@ -3033,24 +3058,24 @@ static void sub_819D770(u8 taskId) static void sub_819D9EC(u8 taskId) { u8 i; - if (sFactorySwapScreen->unk30 == TRUE) + if (sFactorySwapScreen->monPicAnimating == TRUE) return; - switch (gTasks[taskId].data[0]) + switch (gTasks[taskId].tState) { case 0: Swap_PrintMonSpecies3(); - gTasks[taskId].data[0]++; + gTasks[taskId].tState++; break; case 1: sub_819EADC(); gSprites[sFactorySwapScreen->cursorSpriteId].invisible = TRUE; - gTasks[taskId].data[0]++; + gTasks[taskId].tState++; break; case 2: CreateTask(sub_819D12C, 0); - gTasks[sFactorySwapScreen->fadeSpeciesNameTaskId].func = Task_SwapFadeSpeciesName2; - gTasks[taskId].data[0]++; + gTasks[sFactorySwapScreen->fadeSpeciesNameTaskId].func = Swap_Task_FadeSpeciesName2; + gTasks[taskId].tState++; break; case 3: if (!FuncIsActiveTask(sub_819D12C) && gTasks[sFactorySwapScreen->fadeSpeciesNameTaskId].data[4] == 1) @@ -3058,28 +3083,30 @@ static void sub_819D9EC(u8 taskId) sub_819EAC0(); if (!sFactorySwapScreen->inEnemyScreen) { - Swap_InitActions(ACTIONS_ENEMY_SCREEN); + Swap_InitActions(SWAP_ENEMY_SCREEN); } else { - Swap_InitActions(ACTIONS_PLAYER_SCREEN); - for (i = 0; i < 3; i++) - gSprites[sFactorySwapScreen->unk8[1][i]].invisible = TRUE; + Swap_InitActions(SWAP_PLAYER_SCREEN); + + // Hide "Pkmn for Swap" button + for (i = 0; i < ARRAY_COUNT(sFactorySwapScreen->pkmnForSwapButtonSpriteIds[0]); i++) + gSprites[sFactorySwapScreen->pkmnForSwapButtonSpriteIds[1][i]].invisible = TRUE; } gSprites[sFactorySwapScreen->cursorSpriteId].pos1.x = gSprites[sFactorySwapScreen->ballSpriteIds[sFactorySwapScreen->cursorPos]].pos1.x; - gTasks[sFactorySwapScreen->fadeSpeciesNameTaskId].func = Task_SwapFadeSpeciesName; - sFactorySwapScreen->unk27 = 0; - sFactorySwapScreen->unk28 = 6; - sFactorySwapScreen->unk26 = FALSE; - gTasks[sFactorySwapScreen->fadeSpeciesNameTaskId].data[0] = 1; - gTasks[taskId].data[0]++; + gTasks[sFactorySwapScreen->fadeSpeciesNameTaskId].func = Swap_Task_FadeSpeciesName; + sFactorySwapScreen->fadeSpeciesNameCoeffDelay = 0; + sFactorySwapScreen->fadeSpeciesNameCoeff = 6; + sFactorySwapScreen->fadeSpeciesNameFadeOut = FALSE; + gTasks[sFactorySwapScreen->fadeSpeciesNameTaskId].tState = 1; + gTasks[taskId].tState++; } break; case 4: - gTasks[taskId].data[0] = 0; - gTasks[taskId].data[6] = (u32)(Task_HandleSwapScreenChooseMons) >> 0x10; - gTasks[taskId].data[7] = (u32)(Task_HandleSwapScreenChooseMons); - gTasks[taskId].data[5] = 1; + gTasks[taskId].tState = 0; + gTasks[taskId].tFollowUpTaskPtrHi = (u32)(Swap_Task_HandleChooseMons) >> 16; + gTasks[taskId].tFollowUpTaskPtrLo = (u32)(Swap_Task_HandleChooseMons); + gTasks[taskId].tFollowUpTaskState = 1; gTasks[taskId].func = sub_819D770; break; } @@ -3091,7 +3118,7 @@ static void Swap_InitStruct(void) { sFactorySwapScreen = AllocZeroed(sizeof(*sFactorySwapScreen)); sFactorySwapScreen->cursorPos = 0; - sFactorySwapScreen->unk30 = FALSE; + sFactorySwapScreen->monPicAnimating = FALSE; sFactorySwapScreen->fromSummaryScreen = FALSE; } } @@ -3182,28 +3209,28 @@ static void CB2_InitSwapScreen(void) Swap_InitAllSprites(); if (sFactorySwapScreen->fromSummaryScreen == TRUE) Swap_ShowSummaryMonSprite(); - Swap_InitActions(ACTIONS_PLAYER_SCREEN); + Swap_InitActions(SWAP_PLAYER_SCREEN); gMain.state++; break; case 7: Swap_PrintOnInfoWindow(gText_SelectPkmnToSwap); - PutWindowTilemap(2); + PutWindowTilemap(SWAP_WIN_INFO); gMain.state++; break; case 8: Swap_PrintMonCategory(); - PutWindowTilemap(8); + PutWindowTilemap(SWAP_WIN_MON_CATEGORY); gMain.state++; break; case 9: if (!sFactorySwapScreen->fromSummaryScreen) Swap_PrintMonSpecies(); - PutWindowTilemap(1); + PutWindowTilemap(SWAP_WIN_SPECIES); gMain.state++; break; case 10: Swap_PrintPkmnSwap(); - PutWindowTilemap(0); + PutWindowTilemap(SWAP_WIN_TITLE); gMain.state++; break; case 11: @@ -3216,11 +3243,11 @@ static void CB2_InitSwapScreen(void) break; case 13: Swap_PrintActionStrings2(); - PutWindowTilemap(3); + PutWindowTilemap(SWAP_WIN_OPTIONS); gMain.state++; break; case 14: - BeginNormalPaletteFade(0xFFFFFFFF, 0, 0x10, 0, RGB_BLACK); + BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, RGB_BLACK); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); ShowBg(0); ShowBg(1); @@ -3238,20 +3265,20 @@ static void CB2_InitSwapScreen(void) gMain.state++; break; case 15: - sFactorySwapScreen->fadeSpeciesNameTaskId = CreateTask(Task_SwapFadeSpeciesName, 0); + sFactorySwapScreen->fadeSpeciesNameTaskId = CreateTask(Swap_Task_FadeSpeciesName, 0); if (!sFactorySwapScreen->fromSummaryScreen) { - gTasks[sFactorySwapScreen->fadeSpeciesNameTaskId].data[0] = 0; - taskId = CreateTask(Task_HandleSwapScreenChooseMons, 0); - gTasks[taskId].data[0] = 0; + gTasks[sFactorySwapScreen->fadeSpeciesNameTaskId].tState = 0; + taskId = CreateTask(Swap_Task_HandleChooseMons, 0); + gTasks[taskId].tState = 0; } else { sub_819EAF8(); - gTasks[sFactorySwapScreen->fadeSpeciesNameTaskId].data[0] = 1; - sFactorySwapScreen->unk22 = FALSE; - taskId = CreateTask(Task_HandleSwapScreenMenu, 0); - gTasks[taskId].data[0] = 2; + gTasks[sFactorySwapScreen->fadeSpeciesNameTaskId].tState = 1; + sFactorySwapScreen->fadeSpeciesNameActive = FALSE; + taskId = CreateTask(Swap_Task_HandleMenu, 0); + gTasks[taskId].tState = 2; } SetMainCallback2(Swap_CB2); break; @@ -3283,73 +3310,73 @@ static void Swap_InitAllSprites(void) gSprites[sFactorySwapScreen->menuCursor2SpriteId].centerToCornerVecY = 0; if (sFactorySwapScreen->fromSummaryScreen == TRUE) - x = 240; + x = DISPLAY_WIDTH; else - x = 192; + x = DISPLAY_WIDTH - 48; // Unusual way to create sprites // The sprite template for the selector arrow is re-used // with the tiles swapped out spriteTemplate = sSpriteTemplate_Swap_Arrow; spriteTemplate.tileTag = GFXTAG_ACTION_BOX_LEFT; - sFactorySwapScreen->unk8[0][0] = CreateSprite(&spriteTemplate, 240, 120, 10); + sFactorySwapScreen->pkmnForSwapButtonSpriteIds[0][0] = CreateSprite(&spriteTemplate, DISPLAY_WIDTH, 120, 10); spriteTemplate = sSpriteTemplate_Swap_MenuHighlightLeft; spriteTemplate.tileTag = GFXTAG_ACTION_BOX_RIGHT; - sFactorySwapScreen->unk8[0][1] = CreateSprite(&spriteTemplate, 256, 120, 10); - sFactorySwapScreen->unk8[0][2] = CreateSprite(&spriteTemplate, 288, 120, 10); + sFactorySwapScreen->pkmnForSwapButtonSpriteIds[0][1] = CreateSprite(&spriteTemplate, DISPLAY_WIDTH + 16, 120, 10); + sFactorySwapScreen->pkmnForSwapButtonSpriteIds[0][2] = CreateSprite(&spriteTemplate, DISPLAY_WIDTH + 48, 120, 10); spriteTemplate = sSpriteTemplate_Swap_Arrow; spriteTemplate.tileTag = GFXTAG_ACTION_HIGHLIGHT_LEFT; - sFactorySwapScreen->unk8[1][0] = CreateSprite(&spriteTemplate, 240, 120, 1); + sFactorySwapScreen->pkmnForSwapButtonSpriteIds[1][0] = CreateSprite(&spriteTemplate, DISPLAY_WIDTH, 120, 1); spriteTemplate = sSpriteTemplate_Swap_MenuHighlightLeft; spriteTemplate.tileTag = GFXTAG_ACTION_HIGHLIGHT_MIDDLE; - sFactorySwapScreen->unk8[1][1] = CreateSprite(&spriteTemplate, 256, 120, 1); + sFactorySwapScreen->pkmnForSwapButtonSpriteIds[1][1] = CreateSprite(&spriteTemplate, DISPLAY_WIDTH + 16, 120, 1); spriteTemplate.tileTag = GFXTAG_ACTION_HIGHLIGHT_RIGHT; - sFactorySwapScreen->unk8[1][2] = CreateSprite(&spriteTemplate, 288, 120, 1); + sFactorySwapScreen->pkmnForSwapButtonSpriteIds[1][2] = CreateSprite(&spriteTemplate, DISPLAY_WIDTH + 48, 120, 1); spriteTemplate = sSpriteTemplate_Swap_Arrow; spriteTemplate.tileTag = GFXTAG_ACTION_BOX_LEFT; - sFactorySwapScreen->unkE[0][0] = CreateSprite(&spriteTemplate, x, 144, 10); + sFactorySwapScreen->cancelButtonSpriteIds[0][0] = CreateSprite(&spriteTemplate, x, 144, 10); spriteTemplate = sSpriteTemplate_Swap_MenuHighlightLeft; spriteTemplate.tileTag = GFXTAG_ACTION_BOX_RIGHT; - sFactorySwapScreen->unkE[0][1] = CreateSprite(&spriteTemplate, x + 16, 144, 10); + sFactorySwapScreen->cancelButtonSpriteIds[0][1] = CreateSprite(&spriteTemplate, x + 16, 144, 10); spriteTemplate = sSpriteTemplate_Swap_Arrow; spriteTemplate.tileTag = GFXTAG_ACTION_HIGHLIGHT_LEFT; - sFactorySwapScreen->unkE[1][0] = CreateSprite(&spriteTemplate, x, 144, 1); + sFactorySwapScreen->cancelButtonSpriteIds[1][0] = CreateSprite(&spriteTemplate, x, 144, 1); spriteTemplate = sSpriteTemplate_Swap_MenuHighlightLeft; spriteTemplate.tileTag = GFXTAG_ACTION_HIGHLIGHT_RIGHT; - sFactorySwapScreen->unkE[1][1] = CreateSprite(&spriteTemplate, x + 16, 144, 1); + sFactorySwapScreen->cancelButtonSpriteIds[1][1] = CreateSprite(&spriteTemplate, x + 16, 144, 1); for (i = 0; i < 2; i++) { - gSprites[sFactorySwapScreen->unk8[i][0]].centerToCornerVecX = 0; - gSprites[sFactorySwapScreen->unk8[i][0]].centerToCornerVecY = 0; - gSprites[sFactorySwapScreen->unk8[i][1]].centerToCornerVecX = 0; - gSprites[sFactorySwapScreen->unk8[i][1]].centerToCornerVecY = 0; - gSprites[sFactorySwapScreen->unk8[i][2]].centerToCornerVecX = 0; - gSprites[sFactorySwapScreen->unk8[i][2]].centerToCornerVecY = 0; - gSprites[sFactorySwapScreen->unkE[i][0]].centerToCornerVecX = 0; - gSprites[sFactorySwapScreen->unkE[i][0]].centerToCornerVecY = 0; - gSprites[sFactorySwapScreen->unkE[i][1]].centerToCornerVecX = 0; - gSprites[sFactorySwapScreen->unkE[i][1]].centerToCornerVecY = 0; + gSprites[sFactorySwapScreen->pkmnForSwapButtonSpriteIds[i][0]].centerToCornerVecX = 0; + gSprites[sFactorySwapScreen->pkmnForSwapButtonSpriteIds[i][0]].centerToCornerVecY = 0; + gSprites[sFactorySwapScreen->pkmnForSwapButtonSpriteIds[i][1]].centerToCornerVecX = 0; + gSprites[sFactorySwapScreen->pkmnForSwapButtonSpriteIds[i][1]].centerToCornerVecY = 0; + gSprites[sFactorySwapScreen->pkmnForSwapButtonSpriteIds[i][2]].centerToCornerVecX = 0; + gSprites[sFactorySwapScreen->pkmnForSwapButtonSpriteIds[i][2]].centerToCornerVecY = 0; + gSprites[sFactorySwapScreen->cancelButtonSpriteIds[i][0]].centerToCornerVecX = 0; + gSprites[sFactorySwapScreen->cancelButtonSpriteIds[i][0]].centerToCornerVecY = 0; + gSprites[sFactorySwapScreen->cancelButtonSpriteIds[i][1]].centerToCornerVecX = 0; + gSprites[sFactorySwapScreen->cancelButtonSpriteIds[i][1]].centerToCornerVecY = 0; - gSprites[sFactorySwapScreen->unk8[i][0]].invisible = TRUE; - gSprites[sFactorySwapScreen->unk8[i][1]].invisible = TRUE; - gSprites[sFactorySwapScreen->unk8[i][2]].invisible = TRUE; - gSprites[sFactorySwapScreen->unkE[i][0]].invisible = TRUE; - gSprites[sFactorySwapScreen->unkE[i][1]].invisible = TRUE; + gSprites[sFactorySwapScreen->pkmnForSwapButtonSpriteIds[i][0]].invisible = TRUE; + gSprites[sFactorySwapScreen->pkmnForSwapButtonSpriteIds[i][1]].invisible = TRUE; + gSprites[sFactorySwapScreen->pkmnForSwapButtonSpriteIds[i][2]].invisible = TRUE; + gSprites[sFactorySwapScreen->cancelButtonSpriteIds[i][0]].invisible = TRUE; + gSprites[sFactorySwapScreen->cancelButtonSpriteIds[i][1]].invisible = TRUE; } - gSprites[sFactorySwapScreen->unkE[0][0]].invisible = FALSE; - gSprites[sFactorySwapScreen->unkE[0][1]].invisible = FALSE; - gSprites[sFactorySwapScreen->unk8[0][0]].invisible = FALSE; - gSprites[sFactorySwapScreen->unk8[0][1]].invisible = FALSE; - gSprites[sFactorySwapScreen->unk8[0][2]].invisible = FALSE; + gSprites[sFactorySwapScreen->cancelButtonSpriteIds[0][0]].invisible = FALSE; + gSprites[sFactorySwapScreen->cancelButtonSpriteIds[0][1]].invisible = FALSE; + gSprites[sFactorySwapScreen->pkmnForSwapButtonSpriteIds[0][0]].invisible = FALSE; + gSprites[sFactorySwapScreen->pkmnForSwapButtonSpriteIds[0][1]].invisible = FALSE; + gSprites[sFactorySwapScreen->pkmnForSwapButtonSpriteIds[0][2]].invisible = FALSE; } static void Swap_DestroyAllSprites(void) @@ -3361,15 +3388,15 @@ static void Swap_DestroyAllSprites(void) DestroySprite(&gSprites[sFactorySwapScreen->cursorSpriteId]); DestroySprite(&gSprites[sFactorySwapScreen->menuCursor1SpriteId]); DestroySprite(&gSprites[sFactorySwapScreen->menuCursor2SpriteId]); - for (i = 0; i < 2; i++) + for (i = 0; i < ARRAY_COUNT(sFactorySwapScreen->pkmnForSwapButtonSpriteIds); i++) { - for (j = 0; j < 3; j++) - DestroySprite(&gSprites[sFactorySwapScreen->unk8[i][j]]); + for (j = 0; j < ARRAY_COUNT(sFactorySwapScreen->pkmnForSwapButtonSpriteIds[0]); j++) + DestroySprite(&gSprites[sFactorySwapScreen->pkmnForSwapButtonSpriteIds[i][j]]); } - for (i = 0; i < 2; i++) + for (i = 0; i < ARRAY_COUNT(sFactorySwapScreen->cancelButtonSpriteIds); i++) { - for (j = 0; j < 2; j++) - DestroySprite(&gSprites[sFactorySwapScreen->unkE[i][j]]); + for (j = 0; j < ARRAY_COUNT(sFactorySwapScreen->cancelButtonSpriteIds[0]); j++) + DestroySprite(&gSprites[sFactorySwapScreen->cancelButtonSpriteIds[i][j]]); } } @@ -3377,14 +3404,16 @@ static void Swap_HandleActionCursorChange(u8 cursorId) { if (cursorId < FRONTIER_PARTY_SIZE) { + // Cursor is on one of the pokemon gSprites[sFactorySwapScreen->cursorSpriteId].invisible = FALSE; - sub_819E8EC(); + Swap_HideActionButtonHighlights(); gSprites[sFactorySwapScreen->cursorSpriteId].pos1.x = gSprites[sFactorySwapScreen->ballSpriteIds[cursorId]].pos1.x; } else { + // Cursor is on an action button gSprites[sFactorySwapScreen->cursorSpriteId].invisible = TRUE; - sub_819E838(sFactorySwapScreen->actionsData[cursorId].id); + Swap_HighlightActionButton(sFactorySwapScreen->actionsData[cursorId].id); } } @@ -3464,7 +3493,7 @@ static void Swap_UpdateMenuCursorPosition(s8 direction) PlaySE(SE_SELECT); if (direction > 0) // Move cursor down. { - if (sFactorySwapScreen->menuCursorPos != SWAPMENU_OPTIONS_COUNT - 1) + if (sFactorySwapScreen->menuCursorPos != ARRAY_COUNT(sSwap_MenuOptionFuncs) - 1) sFactorySwapScreen->menuCursorPos++; else sFactorySwapScreen->menuCursorPos = 0; @@ -3474,43 +3503,52 @@ static void Swap_UpdateMenuCursorPosition(s8 direction) if (sFactorySwapScreen->menuCursorPos != 0) sFactorySwapScreen->menuCursorPos--; else - sFactorySwapScreen->menuCursorPos = SWAPMENU_OPTIONS_COUNT - 1; + sFactorySwapScreen->menuCursorPos = ARRAY_COUNT(sSwap_MenuOptionFuncs) - 1; } gSprites[sFactorySwapScreen->menuCursor1SpriteId].pos1.y = (sFactorySwapScreen->menuCursorPos * 16) + 112; gSprites[sFactorySwapScreen->menuCursor2SpriteId].pos1.y = (sFactorySwapScreen->menuCursorPos * 16) + 112; } -static void sub_819E838(u8 arg0) +static void Swap_HighlightActionButton(u8 actionId) { u8 i; - for (i = 0; i < 3; i++) + for (i = 0; i < ARRAY_COUNT(sFactorySwapScreen->pkmnForSwapButtonSpriteIds[0]); i++) { - if (arg0 == 2) + if (actionId == SWAPACTION_PKMN_FOR_SWAP) { - gSprites[sFactorySwapScreen->unk8[1][i]].invisible = FALSE; - if (i < 2) - gSprites[sFactorySwapScreen->unkE[1][i]].invisible = TRUE; + // Show button highlight on "Pkmn for Swap" + gSprites[sFactorySwapScreen->pkmnForSwapButtonSpriteIds[1][i]].invisible = FALSE; + + // Hide button highlight on Cancel + if (i < ARRAY_COUNT(sFactorySwapScreen->cancelButtonSpriteIds[0])) + gSprites[sFactorySwapScreen->cancelButtonSpriteIds[1][i]].invisible = TRUE; } - else if (arg0 == 3) + else if (actionId == SWAPACTION_CANCEL) { - if (i < 2) - gSprites[sFactorySwapScreen->unkE[1][i]].invisible = FALSE; - gSprites[sFactorySwapScreen->unk8[1][i]].invisible = TRUE; + // Show button highlight on Cancel + if (i < ARRAY_COUNT(sFactorySwapScreen->cancelButtonSpriteIds[0])) + gSprites[sFactorySwapScreen->cancelButtonSpriteIds[1][i]].invisible = FALSE; + + // Hide button highlight on "Pkmn for Swap" + gSprites[sFactorySwapScreen->pkmnForSwapButtonSpriteIds[1][i]].invisible = TRUE; } } } -static void sub_819E8EC(void) +static void Swap_HideActionButtonHighlights(void) { u8 i; - for (i = 0; i < 3; i++) + for (i = 0; i < ARRAY_COUNT(sFactorySwapScreen->pkmnForSwapButtonSpriteIds[0]); i++) { - gSprites[sFactorySwapScreen->unk8[1][i]].invisible = TRUE; - if (i < 2) - gSprites[sFactorySwapScreen->unkE[1][i]].invisible = TRUE; + // Hide button highlight on "Pkmn for Swap" + gSprites[sFactorySwapScreen->pkmnForSwapButtonSpriteIds[1][i]].invisible = TRUE; + + // Hide button highlight on Cancel + if (i < ARRAY_COUNT(sFactorySwapScreen->cancelButtonSpriteIds[0])) + gSprites[sFactorySwapScreen->cancelButtonSpriteIds[1][i]].invisible = TRUE; } } @@ -3547,7 +3585,7 @@ static void Swap_ShowYesNoOptions(void) Swap_PrintYesNoOptions(); } -static void sub_819EA64(u8 windowId) +static void Swap_ErasePopupMenu(u8 windowId) { gSprites[sFactorySwapScreen->menuCursor1SpriteId].invisible = TRUE; gSprites[sFactorySwapScreen->menuCursor2SpriteId].invisible = TRUE; @@ -3558,31 +3596,31 @@ static void sub_819EA64(u8 windowId) static void sub_819EAC0(void) { - PutWindowTilemap(1); - FillWindowPixelBuffer(1, PIXEL_FILL(0)); - CopyWindowToVram(1, 2); + PutWindowTilemap(SWAP_WIN_SPECIES); + FillWindowPixelBuffer(SWAP_WIN_SPECIES, PIXEL_FILL(0)); + CopyWindowToVram(SWAP_WIN_SPECIES, 2); } static void sub_819EADC(void) { - PutWindowTilemap(7); - FillWindowPixelBuffer(7, PIXEL_FILL(0)); - CopyWindowToVram(7, 2); + PutWindowTilemap(SWAP_WIN_7); + FillWindowPixelBuffer(SWAP_WIN_7, PIXEL_FILL(0)); + CopyWindowToVram(SWAP_WIN_7, 2); } static void sub_819EAF8(void) { sub_819EAC0(); - PutWindowTilemap(5); - FillWindowPixelBuffer(5, PIXEL_FILL(0)); - CopyWindowToVram(5, 2); + PutWindowTilemap(SWAP_WIN_5); + FillWindowPixelBuffer(SWAP_WIN_5, PIXEL_FILL(0)); + CopyWindowToVram(SWAP_WIN_5, 2); } static void Swap_PrintPkmnSwap(void) { - FillWindowPixelBuffer(0, PIXEL_FILL(1)); - AddTextPrinterParameterized(0, 1, gText_PkmnSwap, 2, 1, 0, NULL); - CopyWindowToVram(0, 3); + FillWindowPixelBuffer(SWAP_WIN_TITLE, PIXEL_FILL(1)); + AddTextPrinterParameterized(SWAP_WIN_TITLE, 1, gText_PkmnSwap, 2, 1, 0, NULL); + CopyWindowToVram(SWAP_WIN_TITLE, 3); } static void Swap_PrintMonSpecies(void) @@ -3590,10 +3628,10 @@ static void Swap_PrintMonSpecies(void) u16 species; u8 x; - FillWindowPixelBuffer(1, PIXEL_FILL(0)); + FillWindowPixelBuffer(SWAP_WIN_SPECIES, PIXEL_FILL(0)); if (sFactorySwapScreen->cursorPos >= FRONTIER_PARTY_SIZE) { - CopyWindowToVram(1, 2); + CopyWindowToVram(SWAP_WIN_SPECIES, 2); } else { @@ -3604,35 +3642,35 @@ static void Swap_PrintMonSpecies(void) species = GetMonData(&gEnemyParty[monId], MON_DATA_SPECIES, NULL); StringCopy(gStringVar4, gSpeciesNames[species]); x = GetStringRightAlignXOffset(1, gStringVar4, 86); - AddTextPrinterParameterized3(1, 1, x, 1, sSwapSpeciesNameTextColors, 0, gStringVar4); - CopyWindowToVram(1, 3); + AddTextPrinterParameterized3(SWAP_WIN_SPECIES, 1, x, 1, sSwapSpeciesNameTextColors, 0, gStringVar4); + CopyWindowToVram(SWAP_WIN_SPECIES, 3); } } static void Swap_PrintOnInfoWindow(const u8 *str) { - FillWindowPixelBuffer(2, PIXEL_FILL(0)); - AddTextPrinterParameterized(2, 1, str, 2, 5, 0, NULL); - CopyWindowToVram(2, 2); + FillWindowPixelBuffer(SWAP_WIN_INFO, PIXEL_FILL(0)); + AddTextPrinterParameterized(SWAP_WIN_INFO, 1, str, 2, 5, 0, NULL); + CopyWindowToVram(SWAP_WIN_INFO, 2); } static void Swap_PrintMenuOptions(void) { - PutWindowTilemap(3); - FillWindowPixelBuffer(3, PIXEL_FILL(0)); - AddTextPrinterParameterized3(3, 1, 15, 1, sSwapMenuOptionsTextColors, 0, gText_Summary2); - AddTextPrinterParameterized3(3, 1, 15, 17, sSwapMenuOptionsTextColors, 0, gText_Swap); - AddTextPrinterParameterized3(3, 1, 15, 33, sSwapMenuOptionsTextColors, 0, gText_Rechoose); - CopyWindowToVram(3, 3); + PutWindowTilemap(SWAP_WIN_OPTIONS); + FillWindowPixelBuffer(SWAP_WIN_OPTIONS, PIXEL_FILL(0)); + AddTextPrinterParameterized3(SWAP_WIN_OPTIONS, 1, 15, 1, sSwapMenuOptionsTextColors, 0, gText_Summary2); + AddTextPrinterParameterized3(SWAP_WIN_OPTIONS, 1, 15, 17, sSwapMenuOptionsTextColors, 0, gText_Swap); + AddTextPrinterParameterized3(SWAP_WIN_OPTIONS, 1, 15, 33, sSwapMenuOptionsTextColors, 0, gText_Rechoose); + CopyWindowToVram(SWAP_WIN_OPTIONS, 3); } static void Swap_PrintYesNoOptions(void) { - PutWindowTilemap(4); - FillWindowPixelBuffer(4, PIXEL_FILL(0)); - AddTextPrinterParameterized3(4, 1, 7, 1, sSwapMenuOptionsTextColors, 0, gText_Yes3); - AddTextPrinterParameterized3(4, 1, 7, 17, sSwapMenuOptionsTextColors, 0, gText_No3); - CopyWindowToVram(4, 3); + PutWindowTilemap(SWAP_WIN_YES_NO); + FillWindowPixelBuffer(SWAP_WIN_YES_NO, PIXEL_FILL(0)); + AddTextPrinterParameterized3(SWAP_WIN_YES_NO, 1, 7, 1, sSwapMenuOptionsTextColors, 0, gText_Yes3); + AddTextPrinterParameterized3(SWAP_WIN_YES_NO, 1, 7, 17, sSwapMenuOptionsTextColors, 0, gText_No3); + CopyWindowToVram(SWAP_WIN_YES_NO, 3); } static void Swap_PrintActionString(const u8 *str, u32 y, u32 windowId) @@ -3643,30 +3681,30 @@ static void Swap_PrintActionString(const u8 *str, u32 y, u32 windowId) static void Swap_PrintActionStrings(void) { - FillWindowPixelBuffer(5, PIXEL_FILL(0)); + FillWindowPixelBuffer(SWAP_WIN_5, PIXEL_FILL(0)); switch (sFactorySwapScreen->inEnemyScreen) { case TRUE: - Swap_PrintActionString(gText_PkmnForSwap, 0, 5); + Swap_PrintActionString(gText_PkmnForSwap, 0, SWAP_WIN_5); case FALSE: - Swap_PrintActionString(gText_Cancel3, 24, 5); + Swap_PrintActionString(gText_Cancel3, 24, SWAP_WIN_5); break; } - CopyWindowToVram(5, 3); + CopyWindowToVram(SWAP_WIN_5, 3); } static void Swap_PrintActionStrings2(void) { - FillWindowPixelBuffer(3, PIXEL_FILL(0)); + FillWindowPixelBuffer(SWAP_WIN_OPTIONS, PIXEL_FILL(0)); switch (sFactorySwapScreen->inEnemyScreen) { case TRUE: - Swap_PrintActionString(gText_PkmnForSwap, 8, 3); + Swap_PrintActionString(gText_PkmnForSwap, 8, SWAP_WIN_OPTIONS); case FALSE: - Swap_PrintActionString(gText_Cancel3, 32, 3); + Swap_PrintActionString(gText_Cancel3, 32, SWAP_WIN_OPTIONS); break; } - CopyWindowToVram(3, 3); + CopyWindowToVram(SWAP_WIN_OPTIONS, 3); } static void Swap_PrintOneActionString(u8 which) @@ -3675,13 +3713,13 @@ static void Swap_PrintOneActionString(u8 which) { case 0: if (sFactorySwapScreen->inEnemyScreen == TRUE) - Swap_PrintActionString(gText_PkmnForSwap, 8, 3); + Swap_PrintActionString(gText_PkmnForSwap, 8, SWAP_WIN_OPTIONS); break; case 1: - Swap_PrintActionString(gText_Cancel3, 32, 3); + Swap_PrintActionString(gText_Cancel3, 32, SWAP_WIN_OPTIONS); break; } - CopyWindowToVram(3, 3); + CopyWindowToVram(SWAP_WIN_OPTIONS, 3); } static void Swap_PrintMonSpecies2(void) @@ -3694,14 +3732,14 @@ static void Swap_PrintMonSpecies2(void) if (!sFactorySwapScreen->fromSummaryScreen) pal[4] = gPlttBufferFaded[228]; else - pal[4] = sFactorySwapScreen->unk24; + pal[4] = sFactorySwapScreen->speciesNameColorBackup; LoadPalette(pal, 0xF0, sizeof(sSwapText_Pal)); - PutWindowTilemap(7); - FillWindowPixelBuffer(7, PIXEL_FILL(0)); + PutWindowTilemap(SWAP_WIN_7); + FillWindowPixelBuffer(SWAP_WIN_7, PIXEL_FILL(0)); if (sFactorySwapScreen->cursorPos >= FRONTIER_PARTY_SIZE) { - CopyWindowToVram(7, 3); + CopyWindowToVram(SWAP_WIN_7, 3); } else { @@ -3712,8 +3750,8 @@ static void Swap_PrintMonSpecies2(void) species = GetMonData(&gEnemyParty[monId], MON_DATA_SPECIES, NULL); StringCopy(gStringVar4, gSpeciesNames[species]); x = GetStringRightAlignXOffset(1, gStringVar4, 86); - AddTextPrinterParameterized3(7, 1, x, 1, sSwapSpeciesNameTextColors, 0, gStringVar4); - CopyWindowToVram(7, 3); + AddTextPrinterParameterized3(SWAP_WIN_7, 1, x, 1, sSwapSpeciesNameTextColors, 0, gStringVar4); + CopyWindowToVram(SWAP_WIN_7, 3); } } @@ -3723,11 +3761,11 @@ static void Swap_PrintMonSpecies3(void) u8 x; LoadPalette(sSwapText_Pal, 0xE0, sizeof(sSwapText_Pal)); - CpuCopy16(gPlttBufferUnfaded + 240, gPlttBufferFaded + 224, 10); + CpuCopy16(&gPlttBufferUnfaded[240], &gPlttBufferFaded[224], 10); if (sFactorySwapScreen->cursorPos >= FRONTIER_PARTY_SIZE) { - CopyWindowToVram(1, 2); + CopyWindowToVram(SWAP_WIN_SPECIES, 2); } else { @@ -3738,8 +3776,8 @@ static void Swap_PrintMonSpecies3(void) species = GetMonData(&gEnemyParty[monId], MON_DATA_SPECIES, NULL); StringCopy(gStringVar4, gSpeciesNames[species]); x = GetStringRightAlignXOffset(1, gStringVar4, 86); - AddTextPrinterParameterized3(1, 1, x, 1, sSwapSpeciesNameTextColors, 0, gStringVar4); - CopyWindowToVram(1, 3); + AddTextPrinterParameterized3(SWAP_WIN_SPECIES, 1, x, 1, sSwapSpeciesNameTextColors, 0, gStringVar4); + CopyWindowToVram(SWAP_WIN_SPECIES, 3); } } @@ -3750,22 +3788,22 @@ static void Swap_PrintMonCategory(void) u8 x; u8 monId = sFactorySwapScreen->cursorPos; - FillWindowPixelBuffer(8, PIXEL_FILL(0)); + FillWindowPixelBuffer(SWAP_WIN_MON_CATEGORY, PIXEL_FILL(0)); if (monId >= FRONTIER_PARTY_SIZE) { - CopyWindowToVram(8, 2); + CopyWindowToVram(SWAP_WIN_MON_CATEGORY, 2); } else { - PutWindowTilemap(8); + PutWindowTilemap(SWAP_WIN_MON_CATEGORY); if (!sFactorySwapScreen->inEnemyScreen) species = GetMonData(&gPlayerParty[monId], MON_DATA_SPECIES, NULL); else species = GetMonData(&gEnemyParty[monId], MON_DATA_SPECIES, NULL); CopyMonCategoryText(SpeciesToNationalPokedexNum(species), text); x = GetStringRightAlignXOffset(1, text, 0x76); - AddTextPrinterParameterized(8, 1, text, x, 1, 0, NULL); - CopyWindowToVram(8, 2); + AddTextPrinterParameterized(SWAP_WIN_MON_CATEGORY, 1, text, x, 1, 0, NULL); + CopyWindowToVram(SWAP_WIN_MON_CATEGORY, 2); } } @@ -3775,13 +3813,13 @@ static void Swap_InitActions(u8 id) { switch (id) { - case ACTIONS_PLAYER_SCREEN: + case SWAP_PLAYER_SCREEN: sFactorySwapScreen->inEnemyScreen = FALSE; sFactorySwapScreen->cursorPos = 0; sFactorySwapScreen->actionsCount = ARRAY_COUNT(sSwap_PlayerScreenActions); sFactorySwapScreen->actionsData = sSwap_PlayerScreenActions; break; - case ACTIONS_ENEMY_SCREEN: + case SWAP_ENEMY_SCREEN: sFactorySwapScreen->inEnemyScreen = TRUE; sFactorySwapScreen->cursorPos = 0; sFactorySwapScreen->actionsCount = ARRAY_COUNT(sSwap_EnemyScreenActions); @@ -3799,27 +3837,27 @@ static void Swap_RunMenuOptionFunc(u8 taskId) static void Swap_OptionSwap(u8 taskId) { - CloseMonPic(sFactorySwapScreen->unk2C, &sFactorySwapScreen->unk30, TRUE); + CloseMonPic(sFactorySwapScreen->monPic, &sFactorySwapScreen->monPicAnimating, TRUE); sFactorySwapScreen->playerMonId = sFactorySwapScreen->cursorPos; - sub_819EA64(3); - gTasks[taskId].data[0] = 0; + Swap_ErasePopupMenu(SWAP_WIN_OPTIONS); + gTasks[taskId].tState = 0; gTasks[taskId].func = sub_819D9EC; } static void Swap_OptionSummary(u8 taskId) { - gTasks[taskId].data[0] = 6; - gTasks[taskId].func = Task_FromSwapScreenToSummaryScreen; + gTasks[taskId].tState = 6; + gTasks[taskId].func = Swap_Task_OpenSummaryScreen; } static void Swap_OptionRechoose(u8 taskId) { - CloseMonPic(sFactorySwapScreen->unk2C, &sFactorySwapScreen->unk30, TRUE); - sub_819EA64(3); - gTasks[taskId].data[0] = 0; - gTasks[taskId].data[6] = (u32)(Task_HandleSwapScreenChooseMons) >> 0x10; - gTasks[taskId].data[7] = (u32)(Task_HandleSwapScreenChooseMons); - gTasks[taskId].data[5] = 1; + CloseMonPic(sFactorySwapScreen->monPic, &sFactorySwapScreen->monPicAnimating, TRUE); + Swap_ErasePopupMenu(SWAP_WIN_OPTIONS); + gTasks[taskId].tState = 0; + gTasks[taskId].tFollowUpTaskPtrHi = (u32)(Swap_Task_HandleChooseMons) >> 16; + gTasks[taskId].tFollowUpTaskPtrLo = (u32)(Swap_Task_HandleChooseMons); + gTasks[taskId].tFollowUpTaskState = 1; gTasks[taskId].func = sub_819D770; } @@ -3831,19 +3869,19 @@ static void Swap_RunActionFunc(u8 taskId) static void Swap_ActionCancel(u8 taskId) { - gTasks[taskId].data[6] = (u32)(sub_819CC24) >> 0x10; - gTasks[taskId].data[7] = (u32)(sub_819CC24); - gTasks[taskId].data[0] = 0; - gTasks[taskId].data[5] = 0; + gTasks[taskId].tFollowUpTaskPtrHi = (u32)(Swap_AskQuitSwapping) >> 16; + gTasks[taskId].tFollowUpTaskPtrLo = (u32)(Swap_AskQuitSwapping); + gTasks[taskId].tState = 0; + gTasks[taskId].tFollowUpTaskState = 0; gTasks[taskId].func = sub_819D588; } static void Swap_ActionPkmnForSwap(u8 taskId) { - gTasks[taskId].data[6] = (u32)(sub_819D9EC) >> 0x10; - gTasks[taskId].data[7] = (u32)(sub_819D9EC); - gTasks[taskId].data[5] = 0; - gTasks[taskId].data[0] = 0; + gTasks[taskId].tFollowUpTaskPtrHi = (u32)(sub_819D9EC) >> 16; + gTasks[taskId].tFollowUpTaskPtrLo = (u32)(sub_819D9EC); + gTasks[taskId].tFollowUpTaskState = 0; + gTasks[taskId].tState = 0; gTasks[taskId].func = sub_819D588; } @@ -3851,34 +3889,36 @@ static void Swap_ActionMon(u8 taskId) { if (!sFactorySwapScreen->inEnemyScreen) { - gTasks[taskId].data[6] = (u32)(Task_HandleSwapScreenMenu) >> 0x10; - gTasks[taskId].data[7] = (u32)(Task_HandleSwapScreenMenu); - gTasks[taskId].data[5] = 2; + gTasks[taskId].tFollowUpTaskPtrHi = (u32)(Swap_Task_HandleMenu) >> 16; + gTasks[taskId].tFollowUpTaskPtrLo = (u32)(Swap_Task_HandleMenu); + gTasks[taskId].tFollowUpTaskState = 2; } else if (Swap_AlreadyHasSameSpecies(sFactorySwapScreen->cursorPos) == TRUE) { - sub_819F2B4(&sFactorySwapScreen->unk2C.field1, &sFactorySwapScreen->unk30, TRUE); - gTasks[taskId].data[0] = 0; - gTasks[taskId].data[5] = 1; - gTasks[taskId].func = Task_SwapCantHaveSameMons; + OpenMonPic(&sFactorySwapScreen->monPic.bgSpriteId, &sFactorySwapScreen->monPicAnimating, TRUE); + gTasks[taskId].tState = 0; + gTasks[taskId].tFollowUpTaskState = 1; + gTasks[taskId].func = Swap_TaskCantHaveSameMons; return; } else { - gTasks[taskId].data[6] = (u32)(sub_819CCD4) >> 0x10; - gTasks[taskId].data[7] = (u32)(sub_819CCD4); - gTasks[taskId].data[5] = 0; + gTasks[taskId].tFollowUpTaskPtrHi = (u32)(Swap_AskAcceptMon) >> 16; + gTasks[taskId].tFollowUpTaskPtrLo = (u32)(Swap_AskAcceptMon); + gTasks[taskId].tFollowUpTaskState = 0; } - gTasks[taskId].data[0] = 0; + gTasks[taskId].tState = 0; gTasks[taskId].func = sub_819D588; } -static void sub_819F2B4(u8 *arg0, bool8 *arg1, bool8 swapScreen) +#define sIsSwapScreen data[7] + +static void OpenMonPic(u8 *spriteId, bool8 *animating, bool8 swapScreen) { - *arg0 = CreateSprite(&sSpriteTemplate_Swap_MonPicBgAnim, 120, 64, 1); - gSprites[*arg0].callback = SpriteCB_OpenMonPic; - gSprites[*arg0].data[7] = swapScreen; - *arg1 = TRUE; + *spriteId = CreateSprite(&sSpriteTemplate_Swap_MonPicBgAnim, 120, 64, 1); + gSprites[*spriteId].callback = SpriteCB_OpenMonPic; + gSprites[*spriteId].sIsSwapScreen = swapScreen; + *animating = TRUE; } static void Swap_ShowSummaryMonSprite(void) @@ -3887,86 +3927,79 @@ static void Swap_ShowSummaryMonSprite(void) u16 species; u32 personality, otId; - sFactorySwapScreen->unk2C.field1 = CreateSprite(&sSpriteTemplate_Swap_MonPicBgAnim, 120, 64, 1); - StartSpriteAffineAnim(&gSprites[sFactorySwapScreen->unk2C.field1], 2); + sFactorySwapScreen->monPic.bgSpriteId = CreateSprite(&sSpriteTemplate_Swap_MonPicBgAnim, 120, 64, 1); + StartSpriteAffineAnim(&gSprites[sFactorySwapScreen->monPic.bgSpriteId], 2); mon = &gPlayerParty[sFactorySwapScreen->cursorPos]; species = GetMonData(mon, MON_DATA_SPECIES, NULL); personality = GetMonData(mon, MON_DATA_PERSONALITY, NULL); otId = GetMonData(mon, MON_DATA_OT_ID, NULL); - sFactorySwapScreen->unk2C.field0 = CreateMonPicSprite_HandleDeoxys(species, personality, otId, TRUE, 88, 32, 15, 0xFFFF); // BUG: otId and personality should be switched. - gSprites[sFactorySwapScreen->unk2C.field0].centerToCornerVecX = 0; - gSprites[sFactorySwapScreen->unk2C.field0].centerToCornerVecY = 0; + sFactorySwapScreen->monPic.monSpriteId = CreateMonPicSprite_HandleDeoxys(species, personality, otId, TRUE, 88, 32, 15, 0xFFFF); // BUG: otId and personality should be switched. + gSprites[sFactorySwapScreen->monPic.monSpriteId].centerToCornerVecX = 0; + gSprites[sFactorySwapScreen->monPic.monSpriteId].centerToCornerVecY = 0; - gSprites[sFactorySwapScreen->unk2C.field1].invisible = TRUE; + gSprites[sFactorySwapScreen->monPic.bgSpriteId].invisible = TRUE; } -#define tState data[0] -#define tWinLeft data[3] -#define tWinRight data[24] // UB: Copied typo? Should be data[4], 24 is out of bounds -#define tWinTop data[5] -#define tWinBottom data[8] -#define tIsSwapScreen data[7] - -static void CloseMonPic(struct UnkFactoryStruct arg0, bool8 *arg1, bool8 swapScreen) +static void CloseMonPic(struct FactoryMonPic pic, bool8 *animating, bool8 swapScreen) { u8 taskId; - FreeAndDestroyMonPicSprite(arg0.field0); + FreeAndDestroyMonPicSprite(pic.monSpriteId); taskId = CreateTask(Task_CloseMonPic, 1); gTasks[taskId].tIsSwapScreen = swapScreen; - gTasks[taskId].data[6] = arg0.field1; + gTasks[taskId].tSpriteId = pic.bgSpriteId; gTasks[taskId].func(taskId); - *arg1 = TRUE; + *animating = TRUE; } -static void sub_819F444(struct UnkFactoryStruct arg0, bool8 *arg1) +static void HideMonPic(struct FactoryMonPic pic, bool8 *animating) { - FreeAndDestroyMonPicSprite(arg0.field0); - FreeOamMatrix(gSprites[arg0.field1].oam.matrixNum); - DestroySprite(&gSprites[arg0.field1]); - *arg1 = FALSE; + FreeAndDestroyMonPicSprite(pic.monSpriteId); + FreeOamMatrix(gSprites[pic.bgSpriteId].oam.matrixNum); + DestroySprite(&gSprites[pic.bgSpriteId]); + *animating = FALSE; } -static void Task_SwapCantHaveSameMons(u8 taskId) +static void Swap_TaskCantHaveSameMons(u8 taskId) { - if (sFactorySwapScreen->unk30 == TRUE) + if (sFactorySwapScreen->monPicAnimating == TRUE) return; - switch (gTasks[taskId].data[0]) + switch (gTasks[taskId].tState) { case 0: Swap_PrintOnInfoWindow(gText_SamePkmnInPartyAlready); sFactorySwapScreen->monSwapped = FALSE; - gTasks[taskId].data[0]++; + gTasks[taskId].tState++; break; case 1: - if (gMain.newKeys & A_BUTTON || gMain.newKeys & B_BUTTON) + if (JOY_NEW(A_BUTTON) || JOY_NEW(B_BUTTON)) { PlaySE(SE_SELECT); - CloseMonPic(sFactorySwapScreen->unk2C, &sFactorySwapScreen->unk30, TRUE); - gTasks[taskId].data[0]++; + CloseMonPic(sFactorySwapScreen->monPic, &sFactorySwapScreen->monPicAnimating, TRUE); + gTasks[taskId].tState++; } break; case 2: - if (sFactorySwapScreen->unk30 != TRUE) + if (sFactorySwapScreen->monPicAnimating != TRUE) { - FillWindowPixelBuffer(5, PIXEL_FILL(0)); - CopyWindowToVram(5, 2); - gTasks[taskId].data[0]++; + FillWindowPixelBuffer(SWAP_WIN_5, PIXEL_FILL(0)); + CopyWindowToVram(SWAP_WIN_5, 2); + gTasks[taskId].tState++; } break; case 3: Swap_PrintOnInfoWindow(gText_SelectPkmnToAccept); - gTasks[taskId].data[0]++; + gTasks[taskId].tState++; break; case 4: Swap_PrintMonSpecies3(); sub_819EADC(); - sFactorySwapScreen->unk22 = TRUE; - gTasks[taskId].data[0] = gTasks[taskId].data[5]; - gTasks[taskId].func = Task_HandleSwapScreenChooseMons; + sFactorySwapScreen->fadeSpeciesNameActive = TRUE; + gTasks[taskId].tState = gTasks[taskId].tFollowUpTaskState; + gTasks[taskId].func = Swap_Task_HandleChooseMons; break; } } @@ -3992,7 +4025,7 @@ static void SpriteCB_OpenMonPic(struct Sprite *sprite) { sprite->invisible = TRUE; taskId = CreateTask(Task_OpenMonPic, 1); - gTasks[taskId].tIsSwapScreen = sprite->data[7]; + gTasks[taskId].tIsSwapScreen = sprite->sIsSwapScreen; gTasks[taskId].func(taskId); sprite->callback = SpriteCallbackDummy; } @@ -4003,10 +4036,10 @@ static void sub_819F654(struct Sprite *sprite) if (sprite->affineAnimEnded) { FreeOamMatrix(sprite->oam.matrixNum); - if (sprite->data[7] == TRUE) - sFactorySwapScreen->unk30 = FALSE; + if (sprite->sIsSwapScreen == TRUE) + sFactorySwapScreen->monPicAnimating = FALSE; else - sub_819BE20(FALSE); + Select_SetMonPicAnimating(FALSE); DestroySprite(sprite); } } @@ -4014,16 +4047,16 @@ static void sub_819F654(struct Sprite *sprite) static void Task_OpenMonPic(u8 taskId) { struct Task *task = &gTasks[taskId]; - switch (task->data[0]) + switch (task->tState) { case 0: task->tWinLeft = 88; - task->tWinRight = 152; // BUG: writing outside the array's bounds. - task->data[5] = 64; - task->data[8] = 65; + task->tWinRight = DISPLAY_WIDTH - 88; + task->tWinTop = 64; + task->tWinBottom = 65; SetGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON); SetGpuReg(REG_OFFSET_WIN0H, WIN_RANGE(task->tWinLeft, task->tWinRight)); - SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(task->data[5], task->data[8])); + SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(task->tWinTop, task->tWinBottom)); SetGpuReg(REG_OFFSET_WININ, WININ_WIN0_BG_ALL | WININ_WIN0_CLR | WININ_WIN0_OBJ); SetGpuReg(REG_OFFSET_WINOUT, WINOUT_WIN01_BG0 | WINOUT_WIN01_BG1 | WINOUT_WIN01_BG2 | WINOUT_WIN01_CLR | WINOUT_WIN01_OBJ); break; @@ -4033,15 +4066,15 @@ static void Task_OpenMonPic(u8 taskId) SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(11, 4)); break; case 2: - task->data[5] -= 4; - task->data[8] += 4; - if (task->data[5] <= 32 || task->data[8] >= 96) + task->tWinTop -= 4; + task->tWinBottom += 4; + if (task->tWinTop <= 32 || task->tWinBottom >= 96) { - task->data[5] = 32; - task->data[8] = 96; + task->tWinTop = 32; + task->tWinBottom = 96; } - SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(task->data[5], task->data[8])); - if (task->data[5] != 32) + SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(task->tWinTop, task->tWinBottom)); + if (task->tWinTop != 32) return; break; default: @@ -4050,10 +4083,10 @@ static void Task_OpenMonPic(u8 taskId) if (gTasks[taskId].tIsSwapScreen == TRUE) Swap_CreateMonSprite(); else - Summary_CreateMonSprite(); + Select_CreateMonSprite(); return; } - task->data[0]++; + task->tState++; } static void Task_CloseMonPic(u8 taskId) @@ -4063,36 +4096,36 @@ static void Task_CloseMonPic(u8 taskId) { default: HideBg(3); - gSprites[task->data[6]].data[7] = task->tIsSwapScreen; - gSprites[task->data[6]].invisible = FALSE; - gSprites[task->data[6]].callback = sub_819F654; - StartSpriteAffineAnim(&gSprites[task->data[6]], 1); + gSprites[task->tSpriteId].sIsSwapScreen = task->tIsSwapScreen; + gSprites[task->tSpriteId].invisible = FALSE; + gSprites[task->tSpriteId].callback = sub_819F654; + StartSpriteAffineAnim(&gSprites[task->tSpriteId], 1); ClearGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON); DestroyTask(taskId); break; case 0: task->tWinLeft = 88; - task->tWinRight = 152; - task->data[5] = 32; - task->data[8] = 96; + task->tWinRight = DISPLAY_WIDTH - 88; + task->tWinTop = 32; + task->tWinBottom = 96; SetGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON); SetGpuReg(REG_OFFSET_WIN0H, WIN_RANGE(task->tWinLeft, task->tWinRight)); - SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(task->data[5], task->data[8])); + SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(task->tWinTop, task->tWinBottom)); SetGpuReg(REG_OFFSET_WININ, WININ_WIN0_BG_ALL | WININ_WIN0_CLR | WININ_WIN0_OBJ); SetGpuReg(REG_OFFSET_WINOUT, WINOUT_WIN01_BG0 | WINOUT_WIN01_BG1 | WINOUT_WIN01_BG2 | WINOUT_WIN01_CLR | WINOUT_WIN01_OBJ); - task->data[0]++; + task->tState++; break; case 1: - task->data[5] += 4; - task->data[8] -= 4; - if (task->data[5] >= 64 || task->data[8] <= 65) + task->tWinTop += 4; + task->tWinBottom -= 4; + if (task->tWinTop >= 64 || task->tWinBottom <= 65) { - task->data[5] = 64; - task->data[8] = 65; + task->tWinTop = 64; + task->tWinBottom = 65; } - SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(task->data[5], task->data[8])); - if (task->data[5] == 64) - task->data[0]++; + SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(task->tWinTop, task->tWinBottom)); + if (task->tWinTop == 64) + task->tState++; break; } } @@ -4112,9 +4145,9 @@ static void Swap_CreateMonSprite(void) personality = GetMonData(mon, MON_DATA_PERSONALITY, NULL); otId = GetMonData(mon, MON_DATA_OT_ID, NULL); - sFactorySwapScreen->unk2C.field0 = CreateMonPicSprite_HandleDeoxys(species, otId, personality, TRUE, 88, 32, 15, 0xFFFF); - gSprites[sFactorySwapScreen->unk2C.field0].centerToCornerVecX = 0; - gSprites[sFactorySwapScreen->unk2C.field0].centerToCornerVecY = 0; + sFactorySwapScreen->monPic.monSpriteId = CreateMonPicSprite_HandleDeoxys(species, otId, personality, TRUE, 88, 32, 15, 0xFFFF); + gSprites[sFactorySwapScreen->monPic.monSpriteId].centerToCornerVecX = 0; + gSprites[sFactorySwapScreen->monPic.monSpriteId].centerToCornerVecY = 0; - sFactorySwapScreen->unk30 = FALSE; + sFactorySwapScreen->monPicAnimating = FALSE; } From 7ae78dc7738168bebb74c1ac43f600d1fb3688ea Mon Sep 17 00:00:00 2001 From: GriffinR Date: Wed, 30 Dec 2020 17:35:33 -0500 Subject: [PATCH 4/6] Finish factory select screen doc --- src/battle_factory_screen.c | 289 +++++++++++++++++++++--------------- 1 file changed, 168 insertions(+), 121 deletions(-) diff --git a/src/battle_factory_screen.c b/src/battle_factory_screen.c index 13edf6fef..0fc578b3f 100644 --- a/src/battle_factory_screen.c +++ b/src/battle_factory_screen.c @@ -43,21 +43,25 @@ #define SELECTABLE_MONS_COUNT 6 -#define PALTAG_BALL_GRAY 0x64 -#define PALTAG_BALL_SELECTED 0x65 -#define PALTAG_INTERFACE 0x66 -#define PALTAG_MON_PIC_BG 0x67 +enum { + PALTAG_BALL_GRAY = 100, + PALTAG_BALL_SELECTED, + PALTAG_INTERFACE, + PALTAG_MON_PIC_BG, +}; -#define GFXTAG_BALL 0x64 -#define GFXTAG_ARROW 0x65 -#define GFXTAG_MENU_HIGHLIGHT_LEFT 0x66 -#define GFXTAG_MENU_HIGHLIGHT_RIGHT 0x67 -#define GFXTAG_ACTION_BOX_LEFT 0x68 -#define GFXTAG_ACTION_BOX_RIGHT 0x69 -#define GFXTAG_ACTION_HIGHLIGHT_LEFT 0x6A -#define GFXTAG_ACTION_HIGHLIGHT_MIDDLE 0x6B -#define GFXTAG_ACTION_HIGHLIGHT_RIGHT 0x6C -#define GFXTAG_MON_PIC_BG_ANIM 0x6D +enum { + GFXTAG_BALL = 100, + GFXTAG_ARROW, + GFXTAG_MENU_HIGHLIGHT_LEFT, + GFXTAG_MENU_HIGHLIGHT_RIGHT, + GFXTAG_ACTION_BOX_LEFT, + GFXTAG_ACTION_BOX_RIGHT, + GFXTAG_ACTION_HIGHLIGHT_LEFT, + GFXTAG_ACTION_HIGHLIGHT_MIDDLE, + GFXTAG_ACTION_HIGHLIGHT_RIGHT, + GFXTAG_MON_PIC_BG_ANIM, +}; // Tasks in this file universally use data[0] as a state for switches #define tState data[0] @@ -69,6 +73,14 @@ enum { FADESTATE_DELAY }; +// Return states for the Select Actions +enum { + SELECT_SUMMARY, + SELECT_CONTINUE_CHOOSING, + SELECT_CONFIRM_MONS, + SELECT_INVALID_MON, +}; + struct FactorySelectableMon { u16 monId; @@ -129,7 +141,7 @@ struct FactorySwapScreen u8 yesNoCursorPos; u8 actionsCount; const struct SwapScreenAction *actionsData; - u8 unused1C[4]; + u8 unused[4]; bool8 monSwapped; u8 fadeSpeciesNameTaskId; bool8 fadeSpeciesNameActive; @@ -161,22 +173,22 @@ static void Select_PrintMonSpecies(void); static void Select_PrintMonCategory(void); static void Select_PrintRentalPkmnString(void); static void Select_CopyMonsToPlayerParty(void); -static void sub_819C4B4(void); +static void Select_ShowChosenMons(void); static void Select_ShowYesNoOptions(void); -static void sub_819C568(void); +static void Select_HideChosenMons(void); static void Select_ShowMenuOptions(void); static void Select_PrintMenuOptions(void); static void Select_PrintYesNoOptions(void); static void Select_Task_FadeSpeciesName(u8); -static void sub_819C1D0(u8); +static void Select_Task_OpenChosenMonPics(u8); static void Select_Task_HandleChooseMons(u8); static void Select_Task_HandleMenu(u8); static void CreateFrontierFactorySelectableMons(u8); static void CreateSlateportTentSelectableMons(u8); static void Select_SetBallSpritePaletteNum(u8); -static void sub_819B958(u8); +static void Select_ErasePopupMenu(u8); static u8 Select_RunMenuOptionFunc(void); -static u8 sub_819BC9C(void); +static u8 Select_DeclineChosenMons(void); static u8 Select_OptionSummary(void); static u8 Select_OptionOthers(void); static u8 Select_OptionRentDeselect(void); @@ -226,7 +238,6 @@ static void Swap_ActionMon(u8); static void Swap_ActionCancel(u8); static void Swap_ActionPkmnForSwap(u8); -// Ewram variables static EWRAM_DATA u8 *sSelectMenuTilesetBuffer = NULL; static EWRAM_DATA u8 *sSelectMonPicBgTilesetBuffer = NULL; static EWRAM_DATA u8 *sSelectMenuTilemapBuffer = NULL; @@ -1092,6 +1103,26 @@ void DoBattleFactorySelectScreen(void) SetMainCallback2(CB2_InitSelectScreen); } +// States for the main tasks of the Select_ functions after initialization, including: +// Select_Task_OpenSummaryScreen, Select_Task_HandleYesNo, Select_Task_HandleMenu, and Select_Task_HandleChooseMons +// Unnecessarily complicated, could easily have just kept states numbered in each task always starting at 0 +// There's only one instance (Select_Task_HandleChooseMons) where a non-initial case is used +// Select_Task_Exit has its own straightforward states +#define STATE_CHOOSE_MONS_INIT 0 +#define STATE_CHOOSE_MONS_HANDLE_INPUT 1 +#define STATE_MENU_INIT 2 +#define STATE_MENU_HANDLE_INPUT 3 +#define STATE_YESNO_SHOW_OPTIONS 4 +#define STATE_YESNO_HANDLE_INPUT 5 +#define STATE_SUMMARY_FADE 6 +#define STATE_SUMMARY_CLEAN 7 +#define STATE_SUMMARY_SHOW 8 +#define STATE_MENU_SHOW_OPTIONS 9 +#define STATE_YESNO_SHOW_MONS 10 +#define STATE_CHOOSE_MONS_INVALID 11 +#define STATE_MENU_REINIT 12 +#define STATE_MENU_RESHOW 13 + static void CB2_InitSelectScreen(void) { u8 taskId; @@ -1217,14 +1248,14 @@ static void CB2_InitSelectScreen(void) { gTasks[sFactorySelectScreen->fadeSpeciesNameTaskId].tState = 0; taskId = CreateTask(Select_Task_HandleChooseMons, 0); - gTasks[taskId].tState = 0; + gTasks[taskId].tState = STATE_CHOOSE_MONS_INIT; } else { gTasks[sFactorySelectScreen->fadeSpeciesNameTaskId].tState = 1; sFactorySelectScreen->fadeSpeciesNameActive = FALSE; taskId = CreateTask(Select_Task_HandleMenu, 0); - gTasks[taskId].tState = 13; + gTasks[taskId].tState = STATE_MENU_RESHOW; } SetMainCallback2(CB2_SelectScreen); break; @@ -1360,11 +1391,12 @@ static void Select_HandleMonSelectionChange(void) if (sFactorySelectScreen->mons[cursorPos].selectedId) // Deselect a mon. { paletteNum = IndexOfSpritePaletteTag(PALTAG_BALL_GRAY); - if (sFactorySelectScreen->selectingMonsState == 3 && sFactorySelectScreen->mons[cursorPos].selectedId == 1) + if (sFactorySelectScreen->selectingMonsState == FRONTIER_PARTY_SIZE + && sFactorySelectScreen->mons[cursorPos].selectedId == 1) { for (i = 0; i < SELECTABLE_MONS_COUNT; i++) { - if (sFactorySelectScreen->mons[i].selectedId == 2) + if (sFactorySelectScreen->mons[i].selectedId == FRONTIER_PARTY_SIZE - 1) break; } if (i == SELECTABLE_MONS_COUNT) @@ -1404,12 +1436,12 @@ static void Select_Task_OpenSummaryScreen(u8 taskId) switch (gTasks[taskId].tState) { - case 6: + case STATE_SUMMARY_FADE: gPlttBufferUnfaded[228] = gPlttBufferFaded[228]; BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); - gTasks[taskId].tState = 7; + gTasks[taskId].tState = STATE_SUMMARY_CLEAN; break; - case 7: + case STATE_SUMMARY_CLEAN: if (!gPaletteFade.active) { DestroyTask(sFactorySelectScreen->fadeSpeciesNameTaskId); @@ -1420,10 +1452,10 @@ static void Select_Task_OpenSummaryScreen(u8 taskId) FREE_AND_SET_NULL(sSelectMenuTilemapBuffer); FREE_AND_SET_NULL(sSelectMonPicBgTilemapBuffer); FreeAllWindowBuffers(); - gTasks[taskId].tState = 8; + gTasks[taskId].tState = STATE_SUMMARY_SHOW; } break; - case 8: + case STATE_SUMMARY_SHOW: sFactorySelectScreen->speciesNameColorBackup = gPlttBufferUnfaded[228]; DestroyTask(taskId); sFactorySelectScreen->fromSummaryScreen = TRUE; @@ -1465,6 +1497,7 @@ static void Select_Task_Exit(u8 taskId) } } +// Handles the Yes/No prompt when confirming the 3 selected rental pokemon static void Select_Task_HandleYesNo(u8 taskId) { if (sFactorySelectScreen->monPicAnimating == TRUE) @@ -1472,42 +1505,43 @@ static void Select_Task_HandleYesNo(u8 taskId) switch (gTasks[taskId].tState) { - case 10: - sub_819C4B4(); - gTasks[taskId].tState = 4; + case STATE_YESNO_SHOW_MONS: + Select_ShowChosenMons(); + gTasks[taskId].tState = STATE_YESNO_SHOW_OPTIONS; break; - case 4: + case STATE_YESNO_SHOW_OPTIONS: Select_ShowYesNoOptions(); - gTasks[taskId].tState = 5; + gTasks[taskId].tState = STATE_YESNO_HANDLE_INPUT; break; - case 5: + case STATE_YESNO_HANDLE_INPUT: if (JOY_NEW(A_BUTTON)) { PlaySE(SE_SELECT); if (sFactorySelectScreen->yesNoCursorPos == 0) { - // Selected Yes - sub_819C568(); + // Selected Yes, confirmed selected pokemon + Select_HideChosenMons(); gTasks[taskId].tState = 0; gTasks[taskId].func = Select_Task_Exit; } else { - // Selected No - sub_819B958(SELECT_WIN_YES_NO); - sub_819BC9C(); + // Selected No, continue choosing pokemon + Select_ErasePopupMenu(SELECT_WIN_YES_NO); + Select_DeclineChosenMons(); sFactorySelectScreen->fadeSpeciesNameActive = TRUE; - gTasks[taskId].tState = 1; + gTasks[taskId].tState = STATE_CHOOSE_MONS_HANDLE_INPUT; gTasks[taskId].func = Select_Task_HandleChooseMons; } } else if (JOY_NEW(B_BUTTON)) { + // Pressed B, Continue choosing pokemon PlaySE(SE_SELECT); - sub_819B958(SELECT_WIN_YES_NO); - sub_819BC9C(); + Select_ErasePopupMenu(SELECT_WIN_YES_NO); + Select_DeclineChosenMons(); sFactorySelectScreen->fadeSpeciesNameActive = TRUE; - gTasks[taskId].tState = 1; + gTasks[taskId].tState = STATE_CHOOSE_MONS_HANDLE_INPUT; gTasks[taskId].func = Select_Task_HandleChooseMons; } else if (JOY_REPEAT(DPAD_UP)) @@ -1524,48 +1558,49 @@ static void Select_Task_HandleYesNo(u8 taskId) } } +// Handles the popup menu that shows when a pokemon is selected static void Select_Task_HandleMenu(u8 taskId) { switch (gTasks[taskId].tState) { - case 2: + case STATE_MENU_INIT: if (!sFactorySelectScreen->fromSummaryScreen) OpenMonPic(&sFactorySelectScreen->monPics[1].bgSpriteId, &sFactorySelectScreen->monPicAnimating, FALSE); - gTasks[taskId].tState = 9; + gTasks[taskId].tState = STATE_MENU_SHOW_OPTIONS; break; - case 9: + case STATE_MENU_SHOW_OPTIONS: if (sFactorySelectScreen->monPicAnimating != TRUE) { Select_ShowMenuOptions(); sFactorySelectScreen->fromSummaryScreen = FALSE; - gTasks[taskId].tState = 3; + gTasks[taskId].tState = STATE_MENU_HANDLE_INPUT; } break; - case 3: + case STATE_MENU_HANDLE_INPUT: if (JOY_NEW(A_BUTTON)) { u8 retVal; PlaySE(SE_SELECT); retVal = Select_RunMenuOptionFunc(); - if (retVal == 1) + if (retVal == SELECT_CONTINUE_CHOOSING) { sFactorySelectScreen->fadeSpeciesNameActive = TRUE; - gTasks[taskId].tState = 1; + gTasks[taskId].tState = STATE_CHOOSE_MONS_HANDLE_INPUT; gTasks[taskId].func = Select_Task_HandleChooseMons; } - else if (retVal == 2) + else if (retVal == SELECT_CONFIRM_MONS) { - gTasks[taskId].tState = 10; + gTasks[taskId].tState = STATE_YESNO_SHOW_MONS; gTasks[taskId].func = Select_Task_HandleYesNo; } - else if (retVal == 3) + else if (retVal == SELECT_INVALID_MON) { - gTasks[taskId].tState = 11; + gTasks[taskId].tState = STATE_CHOOSE_MONS_INVALID; gTasks[taskId].func = Select_Task_HandleChooseMons; } - else + else // SELECT_SUMMARY { - gTasks[taskId].tState = 6; + gTasks[taskId].tState = STATE_SUMMARY_FADE; gTasks[taskId].func = Select_Task_OpenSummaryScreen; } } @@ -1573,9 +1608,9 @@ static void Select_Task_HandleMenu(u8 taskId) { PlaySE(SE_SELECT); CloseMonPic(sFactorySelectScreen->monPics[1], &sFactorySelectScreen->monPicAnimating, FALSE); - sub_819B958(SELECT_WIN_OPTIONS); + Select_ErasePopupMenu(SELECT_WIN_OPTIONS); sFactorySelectScreen->fadeSpeciesNameActive = TRUE; - gTasks[taskId].tState = 1; + gTasks[taskId].tState = STATE_CHOOSE_MONS_HANDLE_INPUT; gTasks[taskId].func = Select_Task_HandleChooseMons; } else if (JOY_REPEAT(DPAD_UP)) @@ -1589,7 +1624,7 @@ static void Select_Task_HandleMenu(u8 taskId) Select_UpdateMenuCursorPosition(1); } break; - case 12: + case STATE_MENU_REINIT: if (!gPaletteFade.active) { if (sFactorySelectScreen->fromSummaryScreen == TRUE) @@ -1598,16 +1633,17 @@ static void Select_Task_HandleMenu(u8 taskId) gPlttBufferUnfaded[228] = gPlttBufferUnfaded[244]; } sFactorySelectScreen->fromSummaryScreen = FALSE; - gTasks[taskId].tState = 3; + gTasks[taskId].tState = STATE_MENU_HANDLE_INPUT; } break; - case 13: + case STATE_MENU_RESHOW: Select_ShowMenuOptions(); - gTasks[taskId].tState = 12; + gTasks[taskId].tState = STATE_MENU_REINIT; break; } } +// Handles input on the main selection screen, when no popup menu is open static void Select_Task_HandleChooseMons(u8 taskId) { if (sFactorySelectScreen->monPicAnimating == TRUE) @@ -1615,19 +1651,19 @@ static void Select_Task_HandleChooseMons(u8 taskId) switch (gTasks[taskId].tState) { - case 0: + case STATE_CHOOSE_MONS_INIT: if (!gPaletteFade.active) { - gTasks[taskId].tState = 1; + gTasks[taskId].tState = STATE_CHOOSE_MONS_HANDLE_INPUT; sFactorySelectScreen->fadeSpeciesNameActive = TRUE; } break; - case 1: + case STATE_CHOOSE_MONS_HANDLE_INPUT: if (JOY_NEW(A_BUTTON)) { PlaySE(SE_SELECT); sFactorySelectScreen->fadeSpeciesNameActive = FALSE; - gTasks[taskId].tState = 2; + gTasks[taskId].tState = STATE_MENU_INIT; gTasks[taskId].func = Select_Task_HandleMenu; } else if (JOY_REPEAT(DPAD_LEFT)) @@ -1645,14 +1681,14 @@ static void Select_Task_HandleChooseMons(u8 taskId) Select_PrintMonSpecies(); } break; - case 11: + case STATE_CHOOSE_MONS_INVALID: if (JOY_NEW(A_BUTTON)) { PlaySE(SE_SELECT); CloseMonPic(sFactorySelectScreen->monPics[1], &sFactorySelectScreen->monPicAnimating, FALSE); Select_PrintSelectMonString(); sFactorySelectScreen->fadeSpeciesNameActive = TRUE; - gTasks[taskId].tState = 1; + gTasks[taskId].tState = STATE_CHOOSE_MONS_HANDLE_INPUT; } break; } @@ -1785,7 +1821,7 @@ static void Select_ShowYesNoOptions(void) Select_PrintYesNoOptions(); } -static void sub_819B958(u8 windowId) +static void Select_ErasePopupMenu(u8 windowId) { gSprites[sFactorySelectScreen->menuCursor1SpriteId].invisible = TRUE; gSprites[sFactorySelectScreen->menuCursor2SpriteId].invisible = TRUE; @@ -1878,29 +1914,29 @@ static u8 Select_OptionRentDeselect(void) if (selectedId == 0 && !Select_AreSpeciesValid(monId)) { Select_PrintCantSelectSameMon(); - sub_819B958(SELECT_WIN_OPTIONS); - return 3; + Select_ErasePopupMenu(SELECT_WIN_OPTIONS); + return SELECT_INVALID_MON; } else { CloseMonPic(sFactorySelectScreen->monPics[1], &sFactorySelectScreen->monPicAnimating, FALSE); Select_HandleMonSelectionChange(); Select_PrintSelectMonString(); - sub_819B958(SELECT_WIN_OPTIONS); - if (sFactorySelectScreen->selectingMonsState > 3) - return 2; + Select_ErasePopupMenu(SELECT_WIN_OPTIONS); + if (sFactorySelectScreen->selectingMonsState > FRONTIER_PARTY_SIZE) + return SELECT_CONFIRM_MONS; else - return 1; + return SELECT_CONTINUE_CHOOSING; } } -static u8 sub_819BC9C(void) +static u8 Select_DeclineChosenMons(void) { - sub_819C568(); + Select_HideChosenMons(); Select_HandleMonSelectionChange(); Select_PrintSelectMonString(); - sub_819B958(SELECT_WIN_OPTIONS); - if (sFactorySelectScreen->selectingMonsState > 3) + Select_ErasePopupMenu(SELECT_WIN_OPTIONS); + if (sFactorySelectScreen->selectingMonsState > FRONTIER_PARTY_SIZE) return 2; else return 1; @@ -1908,14 +1944,14 @@ static u8 sub_819BC9C(void) static u8 Select_OptionSummary(void) { - return 0; + return SELECT_SUMMARY; } static u8 Select_OptionOthers(void) { CloseMonPic(sFactorySelectScreen->monPics[1], &sFactorySelectScreen->monPicAnimating, FALSE); - sub_819B958(SELECT_WIN_OPTIONS); - return 1; + Select_ErasePopupMenu(SELECT_WIN_OPTIONS); + return SELECT_CONTINUE_CHOOSING; } static void Select_PrintMonCategory(void) @@ -1977,7 +2013,7 @@ static void Select_ReshowMonSprite(void) gSprites[sFactorySelectScreen->monPics[1].bgSpriteId].invisible = TRUE; } -static void Select_ShowChosenMonsSprites(void) +static void Select_CreateChosenMonsSprites(void) { u8 i, j; @@ -2002,10 +2038,11 @@ static void Select_ShowChosenMonsSprites(void) sFactorySelectScreen->monPicAnimating = FALSE; } -static void sub_819C040(struct Sprite *sprite) +static void SpriteCB_OpenChosenMonPics(struct Sprite *sprite) { u8 taskId; + // Current sprite is monPics[1] if (sprite->affineAnimEnded && gSprites[sFactorySelectScreen->monPics[0].bgSpriteId].affineAnimEnded && gSprites[sFactorySelectScreen->monPics[2].bgSpriteId].affineAnimEnded) @@ -2014,15 +2051,16 @@ static void sub_819C040(struct Sprite *sprite) gSprites[sFactorySelectScreen->monPics[0].bgSpriteId].invisible = TRUE; gSprites[sFactorySelectScreen->monPics[2].bgSpriteId].invisible = TRUE; - taskId = CreateTask(sub_819C1D0, 1); + taskId = CreateTask(Select_Task_OpenChosenMonPics, 1); gTasks[taskId].func(taskId); sprite->callback = SpriteCallbackDummy; } } -static void sub_819C100(struct Sprite *sprite) +static void SpriteCB_CloseChosenMonPics(struct Sprite *sprite) { + // Current sprite is monPics[1] if (sprite->affineAnimEnded && gSprites[sFactorySelectScreen->monPics[0].bgSpriteId].affineAnimEnded && gSprites[sFactorySelectScreen->monPics[2].bgSpriteId].affineAnimEnded) @@ -2039,7 +2077,7 @@ static void sub_819C100(struct Sprite *sprite) } } -// Task data for sub_819C1D0, sub_819C2D4, Task_CloseMonPic, and Task_OpenMonPic +// Task data for Select_Task_OpenChosenMonPics, Select_Task_CloseChosenMonPics, Task_CloseMonPic, and Task_OpenMonPic #define tWinLeft data[3] #ifndef UBFIX #define tWinRight data[24] // UB: Typo? Likely meant data[4], 24 is out of bounds @@ -2051,7 +2089,7 @@ static void sub_819C100(struct Sprite *sprite) #define tSpriteId data[6] // TODO: Clarify, what sprite #define tIsSwapScreen data[7] -static void sub_819C1D0(u8 taskId) +static void Select_Task_OpenChosenMonPics(u8 taskId) { struct Task *task = &gTasks[taskId]; switch (task->tState) @@ -2087,31 +2125,17 @@ static void sub_819C1D0(u8 taskId) break; default: DestroyTask(taskId); - Select_ShowChosenMonsSprites(); + Select_CreateChosenMonsSprites(); return; } task->tState++; } -static void sub_819C2D4(u8 taskId) +static void Select_Task_CloseChosenMonPics(u8 taskId) { struct Task *task = &gTasks[taskId]; switch (task->tState) { - default: - HideBg(3); - gSprites[sFactorySelectScreen->monPics[1].bgSpriteId].invisible = FALSE; - gSprites[sFactorySelectScreen->monPics[1].bgSpriteId].callback = sub_819C100; - gSprites[sFactorySelectScreen->monPics[0].bgSpriteId].invisible = FALSE; - gSprites[sFactorySelectScreen->monPics[0].bgSpriteId].callback = SpriteCallbackDummy; - gSprites[sFactorySelectScreen->monPics[2].bgSpriteId].invisible = FALSE; - gSprites[sFactorySelectScreen->monPics[2].bgSpriteId].callback = SpriteCallbackDummy; - StartSpriteAffineAnim(&gSprites[sFactorySelectScreen->monPics[1].bgSpriteId], 1); - StartSpriteAffineAnim(&gSprites[sFactorySelectScreen->monPics[0].bgSpriteId], 1); - StartSpriteAffineAnim(&gSprites[sFactorySelectScreen->monPics[2].bgSpriteId], 1); - ClearGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON); - DestroyTask(taskId); - break; case 0: task->tWinLeft = 16; task->tWinRight = DISPLAY_WIDTH - 16; @@ -2136,23 +2160,37 @@ static void sub_819C2D4(u8 taskId) if (task->tWinTop == 64) task->tState++; break; + default: + HideBg(3); + gSprites[sFactorySelectScreen->monPics[1].bgSpriteId].invisible = FALSE; + gSprites[sFactorySelectScreen->monPics[1].bgSpriteId].callback = SpriteCB_CloseChosenMonPics; + gSprites[sFactorySelectScreen->monPics[0].bgSpriteId].invisible = FALSE; + gSprites[sFactorySelectScreen->monPics[0].bgSpriteId].callback = SpriteCallbackDummy; + gSprites[sFactorySelectScreen->monPics[2].bgSpriteId].invisible = FALSE; + gSprites[sFactorySelectScreen->monPics[2].bgSpriteId].callback = SpriteCallbackDummy; + StartSpriteAffineAnim(&gSprites[sFactorySelectScreen->monPics[1].bgSpriteId], 1); + StartSpriteAffineAnim(&gSprites[sFactorySelectScreen->monPics[0].bgSpriteId], 1); + StartSpriteAffineAnim(&gSprites[sFactorySelectScreen->monPics[2].bgSpriteId], 1); + ClearGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON); + DestroyTask(taskId); + break; } } -static void sub_819C4B4(void) +static void Select_ShowChosenMons(void) { sFactorySelectScreen->monPics[1].bgSpriteId = CreateSprite(&sSpriteTemplate_Select_MonPicBgAnim, 120, 64, 1); sFactorySelectScreen->monPics[0].bgSpriteId = CreateSprite(&sSpriteTemplate_Select_MonPicBgAnim, 44, 64, 1); sFactorySelectScreen->monPics[2].bgSpriteId = CreateSprite(&sSpriteTemplate_Select_MonPicBgAnim, 196, 64, 1); - gSprites[sFactorySelectScreen->monPics[1].bgSpriteId].callback = sub_819C040; + gSprites[sFactorySelectScreen->monPics[1].bgSpriteId].callback = SpriteCB_OpenChosenMonPics; gSprites[sFactorySelectScreen->monPics[0].bgSpriteId].callback = SpriteCallbackDummy; gSprites[sFactorySelectScreen->monPics[2].bgSpriteId].callback = SpriteCallbackDummy; sFactorySelectScreen->monPicAnimating = TRUE; } -static void sub_819C568(void) +static void Select_HideChosenMons(void) { u8 taskId; @@ -2160,7 +2198,7 @@ static void sub_819C568(void) FreeAndDestroyMonPicSprite(sFactorySelectScreen->monPics[1].monSpriteId); FreeAndDestroyMonPicSprite(sFactorySelectScreen->monPics[2].monSpriteId); - taskId = CreateTask(sub_819C2D4, 1); + taskId = CreateTask(Select_Task_CloseChosenMonPics, 1); gTasks[taskId].func(taskId); sFactorySelectScreen->monPicAnimating = TRUE; @@ -2194,7 +2232,6 @@ static bool32 Select_AreSpeciesValid(u16 monId) } } } - return TRUE; } @@ -2494,6 +2531,9 @@ static void Swap_AskAcceptMon(u8 taskId) } } +#undef STATE_SHOW_YES_NO +#undef STATE_HANDLE_INPUT + static void Swap_Task_HandleMenu(u8 taskId) { switch (gTasks[taskId].tState) @@ -2688,6 +2728,7 @@ static void Swap_Task_FadeSpeciesName2(u8 taskId) } } +// TODO static void sub_819D12C(u8 taskId) { s8 i; @@ -4031,7 +4072,7 @@ static void SpriteCB_OpenMonPic(struct Sprite *sprite) } } -static void sub_819F654(struct Sprite *sprite) +static void SpriteCB_CloseMonPic(struct Sprite *sprite) { if (sprite->affineAnimEnded) { @@ -4050,6 +4091,7 @@ static void Task_OpenMonPic(u8 taskId) switch (task->tState) { case 0: + // Init task->tWinLeft = 88; task->tWinRight = DISPLAY_WIDTH - 88; task->tWinTop = 64; @@ -4061,11 +4103,13 @@ static void Task_OpenMonPic(u8 taskId) SetGpuReg(REG_OFFSET_WINOUT, WINOUT_WIN01_BG0 | WINOUT_WIN01_BG1 | WINOUT_WIN01_BG2 | WINOUT_WIN01_CLR | WINOUT_WIN01_OBJ); break; case 1: + // Show mon pic bg ShowBg(3); SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG3 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_BG1 | BLDCNT_TGT2_OBJ); SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(11, 4)); break; case 2: + // Animate mon pic bg task->tWinTop -= 4; task->tWinBottom += 4; if (task->tWinTop <= 32 || task->tWinBottom >= 96) @@ -4094,16 +4138,8 @@ static void Task_CloseMonPic(u8 taskId) struct Task *task = &gTasks[taskId]; switch (task->tState) { - default: - HideBg(3); - gSprites[task->tSpriteId].sIsSwapScreen = task->tIsSwapScreen; - gSprites[task->tSpriteId].invisible = FALSE; - gSprites[task->tSpriteId].callback = sub_819F654; - StartSpriteAffineAnim(&gSprites[task->tSpriteId], 1); - ClearGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON); - DestroyTask(taskId); - break; case 0: + // Init task->tWinLeft = 88; task->tWinRight = DISPLAY_WIDTH - 88; task->tWinTop = 32; @@ -4116,6 +4152,7 @@ static void Task_CloseMonPic(u8 taskId) task->tState++; break; case 1: + // Animate bg task->tWinTop += 4; task->tWinBottom -= 4; if (task->tWinTop >= 64 || task->tWinBottom <= 65) @@ -4127,6 +4164,16 @@ static void Task_CloseMonPic(u8 taskId) if (task->tWinTop == 64) task->tState++; break; + default: + // Hide bg + HideBg(3); + gSprites[task->tSpriteId].sIsSwapScreen = task->tIsSwapScreen; + gSprites[task->tSpriteId].invisible = FALSE; + gSprites[task->tSpriteId].callback = SpriteCB_CloseMonPic; + StartSpriteAffineAnim(&gSprites[task->tSpriteId], 1); + ClearGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON); + DestroyTask(taskId); + break; } } From 093610b46e99b517a416ccd5a572054dff09801b Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 31 Dec 2020 00:26:14 -0500 Subject: [PATCH 5/6] Finish factory swap screen doc --- src/battle_factory_screen.c | 511 +++++++++++++++++++++--------------- 1 file changed, 295 insertions(+), 216 deletions(-) diff --git a/src/battle_factory_screen.c b/src/battle_factory_screen.c index 0fc578b3f..9e0df2c77 100644 --- a/src/battle_factory_screen.c +++ b/src/battle_factory_screen.c @@ -199,25 +199,25 @@ static void CB2_InitSwapScreen(void); static void Swap_DestroyAllSprites(void); static void Swap_ShowYesNoOptions(void); static void Swap_HideActionButtonHighlights(void); -static void sub_819EAC0(void); +static void Swap_EraseSpeciesWindow(void); static void Swap_UpdateYesNoCursorPosition(s8); static void Swap_UpdateMenuCursorPosition(s8); static void Swap_ErasePopupMenu(u8); -static void sub_819D770(u8); +static void Swap_Task_ScreenInfoTransitionIn(u8); static void Swap_Task_HandleChooseMons(u8); -static void sub_819D588(u8); +static void Swap_Task_ScreenInfoTransitionOut(u8); static void Swap_PrintOnInfoWindow(const u8 *); static void Swap_ShowMenuOptions(void); static void Swap_PrintMenuOptions(void); static void Swap_PrintYesNoOptions(void); static void Swap_PrintMonSpecies(void); -static void Swap_PrintMonSpecies2(void); -static void Swap_PrintMonSpecies3(void); +static void Swap_PrintMonSpeciesAtFade(void); +static void Swap_PrintMonSpeciesForTransition(void); static void Swap_PrintMonCategory(void); static void Swap_InitAllSprites(void); static void Swap_PrintPkmnSwap(void); -static void sub_819EADC(void); -static void sub_819EAF8(void); +static void Swap_EraseSpeciesAtFadeWindow(void); +static void Swap_EraseActionFadeWindow(void); static void Swap_ShowSummaryMonSprite(void); static void Swap_UpdateActionCursorPosition(s8); static void Swap_UpdateBallCursorPosition(s8); @@ -931,9 +931,9 @@ enum { SWAP_WIN_INFO, SWAP_WIN_OPTIONS, SWAP_WIN_YES_NO, - SWAP_WIN_5, - SWAP_WIN_6, - SWAP_WIN_7, + SWAP_WIN_ACTION_FADE, // Used for action text fading out during screen transition + SWAP_WIN_UNUSED, + SWAP_WIN_SPECIES_AT_FADE, // Used to print species name stopped at current fade level SWAP_WIN_MON_CATEGORY, }; @@ -984,7 +984,7 @@ static const struct WindowTemplate sSwap_WindowTemplates[] = .paletteNum = 15, .baseBlock = 0x00a1, }, - [SWAP_WIN_5] = { + [SWAP_WIN_ACTION_FADE] = { .bg = 2, .tilemapLeft = 21, .tilemapTop = 15, @@ -993,7 +993,7 @@ static const struct WindowTemplate sSwap_WindowTemplates[] = .paletteNum = 14, .baseBlock = 0x006b, }, - [SWAP_WIN_6] = { + [SWAP_WIN_UNUSED] = { .bg = 2, .tilemapLeft = 10, .tilemapTop = 2, @@ -1002,7 +1002,7 @@ static const struct WindowTemplate sSwap_WindowTemplates[] = .paletteNum = 14, .baseBlock = 0x00c1, }, - [SWAP_WIN_7] = { + [SWAP_WIN_SPECIES_AT_FADE] = { .bg = 0, .tilemapLeft = 19, .tilemapTop = 2, @@ -1103,6 +1103,7 @@ void DoBattleFactorySelectScreen(void) SetMainCallback2(CB2_InitSelectScreen); } +// Main select states // States for the main tasks of the Select_ functions after initialization, including: // Select_Task_OpenSummaryScreen, Select_Task_HandleYesNo, Select_Task_HandleMenu, and Select_Task_HandleChooseMons // Unnecessarily complicated, could easily have just kept states numbered in each task always starting at 0 @@ -1246,13 +1247,13 @@ static void CB2_InitSelectScreen(void) sFactorySelectScreen->fadeSpeciesNameTaskId = CreateTask(Select_Task_FadeSpeciesName, 0); if (!sFactorySelectScreen->fromSummaryScreen) { - gTasks[sFactorySelectScreen->fadeSpeciesNameTaskId].tState = 0; + gTasks[sFactorySelectScreen->fadeSpeciesNameTaskId].tState = FADESTATE_INIT; taskId = CreateTask(Select_Task_HandleChooseMons, 0); gTasks[taskId].tState = STATE_CHOOSE_MONS_INIT; } else { - gTasks[sFactorySelectScreen->fadeSpeciesNameTaskId].tState = 1; + gTasks[sFactorySelectScreen->fadeSpeciesNameTaskId].tState = FADESTATE_RUN; sFactorySelectScreen->fadeSpeciesNameActive = FALSE; taskId = CreateTask(Select_Task_HandleMenu, 0); gTasks[taskId].tState = STATE_MENU_RESHOW; @@ -1694,6 +1695,21 @@ static void Select_Task_HandleChooseMons(u8 taskId) } } +#undef STATE_CHOOSE_MONS_INIT +#undef STATE_CHOOSE_MONS_HANDLE_INPUT +#undef STATE_MENU_INIT +#undef STATE_MENU_HANDLE_INPUT +#undef STATE_YESNO_SHOW_OPTIONS +#undef STATE_YESNO_HANDLE_INPUT +#undef STATE_SUMMARY_FADE +#undef STATE_SUMMARY_CLEAN +#undef STATE_SUMMARY_SHOW +#undef STATE_MENU_SHOW_OPTIONS +#undef STATE_YESNO_SHOW_MONS +#undef STATE_CHOOSE_MONS_INVALID +#undef STATE_MENU_REINIT +#undef STATE_MENU_RESHOW + static void CreateFrontierFactorySelectableMons(u8 firstMonId) { u8 i, j = 0; @@ -2321,15 +2337,30 @@ static void CopySwappedMonData(void) gSaveBlock2Ptr->frontier.rentalMons[sFactorySwapScreen->playerMonId].abilityNum = GetBoxMonData(&gEnemyParty[sFactorySwapScreen->enemyMonId].box, MON_DATA_ABILITY_NUM, NULL); } +// Main swap states +// States for the main tasks of the Swap_ functions after initialization, including: +// Swap_Task_OpenSummaryScreen, Swap_Task_HandleYesNo, Swap_Task_HandleMenu, and Swap_Task_HandleChooseMons +// Tasks sharing states was unnecessary, see "Main select states" +#define STATE_CHOOSE_MONS_INIT 0 +#define STATE_CHOOSE_MONS_HANDLE_INPUT 1 +#define STATE_MENU_INIT 2 +#define STATE_MENU_HANDLE_INPUT 3 +#define STATE_YESNO_SHOW 4 +#define STATE_YESNO_HANDLE_INPUT 5 +#define STATE_SUMMARY_FADE 6 +#define STATE_SUMMARY_CLEAN 7 +#define STATE_SUMMARY_SHOW 8 +#define STATE_MENU_SHOW_OPTIONS 9 + static void Swap_Task_OpenSummaryScreen(u8 taskId) { switch (gTasks[taskId].tState) { - case 6: + case STATE_SUMMARY_FADE: BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); - gTasks[taskId].tState = 7; + gTasks[taskId].tState = STATE_SUMMARY_CLEAN; break; - case 7: + case STATE_SUMMARY_CLEAN: if (!gPaletteFade.active) { DestroyTask(sFactorySwapScreen->fadeSpeciesNameTaskId); @@ -2340,10 +2371,10 @@ static void Swap_Task_OpenSummaryScreen(u8 taskId) FREE_AND_SET_NULL(sSwapMenuTilemapBuffer); FREE_AND_SET_NULL(sSwapMonPicBgTilemapBuffer); FreeAllWindowBuffers(); - gTasks[taskId].tState = 8; + gTasks[taskId].tState = STATE_SUMMARY_SHOW; } break; - case 8: + case STATE_SUMMARY_SHOW: DestroyTask(taskId); sFactorySwapScreen->fromSummaryScreen = TRUE; sFactorySwapScreen->speciesNameColorBackup = gPlttBufferUnfaded[244]; @@ -2403,10 +2434,7 @@ static void Swap_Task_Exit(u8 taskId) } } -#define STATE_SHOW_YES_NO 4 -#define STATE_HANDLE_INPUT 5 - -#define tSaidYes data[1] +#define tSaidYes data[1] #define tFollowUpTaskState data[5] #define tFollowUpTaskPtrHi data[6] #define tFollowUpTaskPtrLo data[7] @@ -2420,11 +2448,11 @@ static void Swap_Task_HandleYesNo(u8 taskId) switch (gTasks[taskId].tState) { - case STATE_SHOW_YES_NO: + case STATE_YESNO_SHOW: Swap_ShowYesNoOptions(); - gTasks[taskId].tState = STATE_HANDLE_INPUT; + gTasks[taskId].tState = STATE_YESNO_HANDLE_INPUT; break; - case STATE_HANDLE_INPUT: + case STATE_YESNO_HANDLE_INPUT: if (JOY_NEW(A_BUTTON)) { PlaySE(SE_SELECT); @@ -2481,8 +2509,8 @@ static void Swap_HandleQuitSwappingResposne(u8 taskId) gTasks[taskId].tState = 0; gTasks[taskId].tFollowUpTaskPtrHi = (u32)(Swap_Task_HandleChooseMons) >> 16; gTasks[taskId].tFollowUpTaskPtrLo = (u32)(Swap_Task_HandleChooseMons); - gTasks[taskId].tFollowUpTaskState = 1; - gTasks[taskId].func = sub_819D770; + gTasks[taskId].tFollowUpTaskState = STATE_CHOOSE_MONS_HANDLE_INPUT; + gTasks[taskId].func = Swap_Task_ScreenInfoTransitionIn; } } @@ -2492,7 +2520,7 @@ static void Swap_AskQuitSwapping(u8 taskId) { Swap_PrintOnInfoWindow(gText_QuitSwapping); sFactorySwapScreen->monSwapped = FALSE; - gTasks[taskId].tState = STATE_SHOW_YES_NO; + gTasks[taskId].tState = STATE_YESNO_SHOW; gTasks[taskId].tFollowUpTaskPtrHi = (u32)(Swap_HandleQuitSwappingResposne) >> 16; gTasks[taskId].tFollowUpTaskPtrLo = (u32)(Swap_HandleQuitSwappingResposne); gTasks[taskId].func = Swap_Task_HandleYesNo; @@ -2512,8 +2540,8 @@ static void Swap_HandleAcceptMonResponse(u8 taskId) gTasks[taskId].tState = 0; gTasks[taskId].tFollowUpTaskPtrHi = (u32)(Swap_Task_HandleChooseMons) >> 16; gTasks[taskId].tFollowUpTaskPtrLo = (u32)(Swap_Task_HandleChooseMons); - gTasks[taskId].tFollowUpTaskState = 1; - gTasks[taskId].func = sub_819D770; + gTasks[taskId].tFollowUpTaskState = STATE_CHOOSE_MONS_HANDLE_INPUT; + gTasks[taskId].func = Swap_Task_ScreenInfoTransitionIn; } } @@ -2524,33 +2552,30 @@ static void Swap_AskAcceptMon(u8 taskId) OpenMonPic(&sFactorySwapScreen->monPic.bgSpriteId, &sFactorySwapScreen->monPicAnimating, TRUE); Swap_PrintOnInfoWindow(gText_AcceptThisPkmn); sFactorySwapScreen->monSwapped = TRUE; - gTasks[taskId].tState = STATE_SHOW_YES_NO; + gTasks[taskId].tState = STATE_YESNO_SHOW; gTasks[taskId].tFollowUpTaskPtrHi = (u32)(Swap_HandleAcceptMonResponse) >> 16; gTasks[taskId].tFollowUpTaskPtrLo = (u32)(Swap_HandleAcceptMonResponse); gTasks[taskId].func = Swap_Task_HandleYesNo; } } -#undef STATE_SHOW_YES_NO -#undef STATE_HANDLE_INPUT - static void Swap_Task_HandleMenu(u8 taskId) { switch (gTasks[taskId].tState) { - case 2: + case STATE_MENU_INIT: if (!sFactorySwapScreen->fromSummaryScreen) OpenMonPic(&sFactorySwapScreen->monPic.bgSpriteId, &sFactorySwapScreen->monPicAnimating, TRUE); - gTasks[taskId].tState = 9; + gTasks[taskId].tState = STATE_MENU_SHOW_OPTIONS; break; - case 9: + case STATE_MENU_SHOW_OPTIONS: if (sFactorySwapScreen->monPicAnimating != TRUE) { Swap_ShowMenuOptions(); - gTasks[taskId].tState = 3; + gTasks[taskId].tState = STATE_MENU_HANDLE_INPUT; } break; - case 3: + case STATE_MENU_HANDLE_INPUT: if (sFactorySwapScreen->monPicAnimating != TRUE) { if (JOY_NEW(A_BUTTON)) @@ -2566,8 +2591,8 @@ static void Swap_Task_HandleMenu(u8 taskId) gTasks[taskId].tState = 0; gTasks[taskId].tFollowUpTaskPtrHi = (u32)(Swap_Task_HandleChooseMons) >> 16; gTasks[taskId].tFollowUpTaskPtrLo = (u32)(Swap_Task_HandleChooseMons); - gTasks[taskId].tFollowUpTaskState = 1; - gTasks[taskId].func = sub_819D770; + gTasks[taskId].tFollowUpTaskState = STATE_CHOOSE_MONS_HANDLE_INPUT; + gTasks[taskId].func = Swap_Task_ScreenInfoTransitionIn; } else if (JOY_REPEAT(DPAD_UP)) { @@ -2582,37 +2607,40 @@ static void Swap_Task_HandleMenu(u8 taskId) } } +// Handles input on the two main swap screens (choosing a current pokeon to get rid of, and choosing a new pokemon to receive) static void Swap_Task_HandleChooseMons(u8 taskId) { switch (gTasks[taskId].tState) { - case 0: + case STATE_CHOOSE_MONS_INIT: if (!gPaletteFade.active) { sFactorySwapScreen->fadeSpeciesNameActive = TRUE; - gTasks[taskId].tState = 1; + gTasks[taskId].tState = STATE_CHOOSE_MONS_HANDLE_INPUT; } break; - case 1: + case STATE_CHOOSE_MONS_HANDLE_INPUT: if (JOY_NEW(A_BUTTON)) { + // Run whatever action is currently selected (a pokeball, the Cancel button, etc.) PlaySE(SE_SELECT); sFactorySwapScreen->fadeSpeciesNameActive = FALSE; - Swap_PrintMonSpecies2(); - sub_819EAC0(); + Swap_PrintMonSpeciesAtFade(); + Swap_EraseSpeciesWindow(); Swap_RunActionFunc(taskId); } else if (JOY_NEW(B_BUTTON)) { + // Ask if player wants to quit swapping PlaySE(SE_SELECT); sFactorySwapScreen->fadeSpeciesNameActive = FALSE; - Swap_PrintMonSpecies2(); - sub_819EAC0(); + Swap_PrintMonSpeciesAtFade(); + Swap_EraseSpeciesWindow(); gTasks[taskId].tFollowUpTaskPtrHi = (u32)(Swap_AskQuitSwapping) >> 16; gTasks[taskId].tFollowUpTaskPtrLo = (u32)(Swap_AskQuitSwapping); gTasks[taskId].tState = 0; gTasks[taskId].tFollowUpTaskState = 0; - gTasks[taskId].func = sub_819D588; + gTasks[taskId].func = Swap_Task_ScreenInfoTransitionOut; } else if (JOY_REPEAT(DPAD_LEFT)) { @@ -2697,13 +2725,15 @@ static void Swap_Task_FadeSpeciesName(u8 taskId) } } -static void Swap_Task_FadeSpeciesName2(u8 taskId) +#define tFadeOutFinished data[4] + +static void Swap_Task_FadeOutSpeciesName(u8 taskId) { switch (gTasks[taskId].tState) { case 0: sFactorySwapScreen->fadeSpeciesNameCoeffDelay = 0; - gTasks[taskId].data[4] = 0; + gTasks[taskId].tFadeOutFinished = FALSE; gTasks[taskId].tState++; break; case 1: @@ -2713,7 +2743,7 @@ static void Swap_Task_FadeSpeciesName2(u8 taskId) case 2: if (sFactorySwapScreen->fadeSpeciesNameCoeff > 15) { - gTasks[taskId].data[4] = 1; + gTasks[taskId].tFadeOutFinished = TRUE; gTasks[taskId].tState++; } sFactorySwapScreen->fadeSpeciesNameCoeffDelay++; @@ -2728,31 +2758,33 @@ static void Swap_Task_FadeSpeciesName2(u8 taskId) } } -// TODO -static void sub_819D12C(u8 taskId) +// Slide current pokeballs offscreen to the right and new pokeballs onscreen from +// the left during transition between player's/enemy's party screens +#define tBallCycled(i) data[(i) + 1] +static void Swap_Task_SlideCycleBalls(u8 taskId) { s8 i; - u8 var_2C; - bool8 destroyTask; + u8 lastX; + bool8 finished; switch (gTasks[taskId].tState) { case 0: - gTasks[taskId].data[1] = 0; - gTasks[taskId].data[2] = 0; - gTasks[taskId].data[3] = 0; + gTasks[taskId].tBallCycled(0) = FALSE; + gTasks[taskId].tBallCycled(1) = FALSE; + gTasks[taskId].tBallCycled(2) = FALSE; gTasks[taskId].tState = 1; break; case 1: - var_2C = 0; + lastX = 0; for (i = FRONTIER_PARTY_SIZE - 1; i >= 0; i--) { if (i != FRONTIER_PARTY_SIZE - 1) { - u8 posX = var_2C - gSprites[sFactorySwapScreen->ballSpriteIds[i]].pos1.x; - if (posX == 16 || gTasks[taskId].data[i + 2] == 1) + u8 posX = lastX - gSprites[sFactorySwapScreen->ballSpriteIds[i]].pos1.x; + if (posX == 16 || gTasks[taskId].tBallCycled(i + 1) == TRUE) { - var_2C = gSprites[sFactorySwapScreen->ballSpriteIds[i]].pos1.x; + lastX = gSprites[sFactorySwapScreen->ballSpriteIds[i]].pos1.x; gSprites[sFactorySwapScreen->ballSpriteIds[i]].pos1.x += 10; } else if (posX > 16) @@ -2762,164 +2794,190 @@ static void sub_819D12C(u8 taskId) } else { - var_2C = gSprites[sFactorySwapScreen->ballSpriteIds[i]].pos1.x; + lastX = gSprites[sFactorySwapScreen->ballSpriteIds[i]].pos1.x; gSprites[sFactorySwapScreen->ballSpriteIds[i]].pos1.x += 10; } - if (gTasks[taskId].data[i + 1] == 1) + if (gTasks[taskId].tBallCycled(i) == TRUE) { + // New ball coming in from left, check if it has reached dest if (gSprites[sFactorySwapScreen->ballSpriteIds[i]].pos1.x > (i * 48) + 72) { + // Overshot dest, set x and finish gSprites[sFactorySwapScreen->ballSpriteIds[i]].pos1.x = (i * 48) + 72; - destroyTask = TRUE; + finished = TRUE; } else if (gSprites[sFactorySwapScreen->ballSpriteIds[i]].pos1.x == (i * 48) + 72) { - destroyTask = TRUE; + finished = TRUE; } else { - destroyTask = FALSE; + finished = FALSE; } } else { - destroyTask = FALSE; + finished = FALSE; } if (gSprites[sFactorySwapScreen->ballSpriteIds[i]].pos1.x - 16 > DISPLAY_WIDTH) { - var_2C = gSprites[sFactorySwapScreen->ballSpriteIds[i]].pos1.x; + // Ball is offscreen right, cycle its palette and move to left side of screen + lastX = gSprites[sFactorySwapScreen->ballSpriteIds[i]].pos1.x; gSprites[sFactorySwapScreen->ballSpriteIds[i]].pos1.x = -16; if (sFactorySwapScreen->inEnemyScreen == TRUE) gSprites[sFactorySwapScreen->ballSpriteIds[i]].oam.paletteNum = IndexOfSpritePaletteTag(PALTAG_BALL_SELECTED); else gSprites[sFactorySwapScreen->ballSpriteIds[i]].oam.paletteNum = IndexOfSpritePaletteTag(PALTAG_BALL_GRAY); - gTasks[taskId].data[i + 1] = 1; + gTasks[taskId].tBallCycled(i) = TRUE; } } - if (destroyTask == TRUE) + if (finished == TRUE) DestroyTask(taskId); break; } } -static void sub_819D324(u8 taskId) +// For sliding the action buttons (Cancel, Pkmn for Swap) on/off screen + +#define SLIDE_BUTTON_PKMN 0 +#define SLIDE_BUTTON_CANCEL 1 + +#define tTaskId data[1] +#define tSlidingOn data[2] +#define tXIncrement data[3] + +// Data to be used by the task that creates this task +#define tSecondSlideDelay data[2] +#define tSlideFinishedPkmn data[3] +#define tSlideFinishedCancel data[4] + +static void Swap_Task_SlideButtonOnOffScreen(u8 taskId) { u8 i, j; s32 posX = 0; - s8 r4 = gTasks[taskId].data[3]; - bool8 r1; + s8 deltaX = gTasks[taskId].tXIncrement; + bool8 sliding; s16 currPosX; - u8 taskId2; + u8 prevTaskId; - if (gTasks[taskId].data[2] == 1) - r4 *= -1; + if (gTasks[taskId].tSlidingOn == TRUE) + deltaX *= -1; switch (gTasks[taskId].tState) { - case 0: + case SLIDE_BUTTON_PKMN: currPosX = gSprites[sFactorySwapScreen->pkmnForSwapButtonSpriteIds[0][0]].pos1.x; - if (!gTasks[taskId].data[2]) + if (!gTasks[taskId].tSlidingOn) { - if (currPosX + r4 < DISPLAY_WIDTH) + // Sliding "Pkmn for Swap" offscreen + if (currPosX + deltaX < DISPLAY_WIDTH) { - r1 = TRUE; + sliding = TRUE; } else { - r1 = FALSE; + sliding = FALSE; posX = DISPLAY_WIDTH; } } else { - if (currPosX + r4 > DISPLAY_HEIGHT) + // Sliding "Pkmn for Swap" onscreen + if (currPosX + deltaX > 160) { - r1 = TRUE; + sliding = TRUE; } else { - r1 = FALSE; - posX = DISPLAY_HEIGHT; + sliding = FALSE; + posX = 160; } } - if (r1 == TRUE) + if (sliding == TRUE) { + // Do movement for (i = 0; i < ARRAY_COUNT(sFactorySwapScreen->pkmnForSwapButtonSpriteIds[0]); i++) { for (j = 0; j < ARRAY_COUNT(sFactorySwapScreen->pkmnForSwapButtonSpriteIds); j++) - gSprites[sFactorySwapScreen->pkmnForSwapButtonSpriteIds[j][i]].pos1.x += r4; + gSprites[sFactorySwapScreen->pkmnForSwapButtonSpriteIds[j][i]].pos1.x += deltaX; } } else { + // Set final position for (j = 0; j < ARRAY_COUNT(sFactorySwapScreen->pkmnForSwapButtonSpriteIds); j++) { gSprites[sFactorySwapScreen->pkmnForSwapButtonSpriteIds[j][0]].pos1.x = posX; gSprites[sFactorySwapScreen->pkmnForSwapButtonSpriteIds[j][1]].pos1.x = posX + 16; gSprites[sFactorySwapScreen->pkmnForSwapButtonSpriteIds[j][2]].pos1.x = posX + 48; } - taskId2 = gTasks[taskId].data[1]; - gTasks[taskId2].data[3] = 1; + prevTaskId = gTasks[taskId].tTaskId; + gTasks[prevTaskId].tSlideFinishedPkmn = TRUE; DestroyTask(taskId); } break; - case 1: + case SLIDE_BUTTON_CANCEL: currPosX = gSprites[sFactorySwapScreen->cancelButtonSpriteIds[0][0]].pos1.x; - if (!gTasks[taskId].data[2]) + if (!gTasks[taskId].tSlidingOn) { - if (currPosX + r4 < DISPLAY_WIDTH) + // Sliding "Cancel" offscreen + if (currPosX + deltaX < DISPLAY_WIDTH) { - r1 = TRUE; + sliding = TRUE; } else { - r1 = FALSE; + sliding = FALSE; posX = DISPLAY_WIDTH; } } else { - if (currPosX + r4 > DISPLAY_HEIGHT + 32) + // Sliding "Cancel" onscreen + if (currPosX + deltaX > 192) { - r1 = TRUE; + sliding = TRUE; } else { - r1 = FALSE; - posX = DISPLAY_HEIGHT + 32; + sliding = FALSE; + posX = 192; } } - if (r1 == TRUE) + if (sliding == TRUE) { + // Do movement for (i = 0; i < ARRAY_COUNT(sFactorySwapScreen->cancelButtonSpriteIds); i++) { for (j = 0; j < ARRAY_COUNT(sFactorySwapScreen->cancelButtonSpriteIds[0]); j++) - gSprites[sFactorySwapScreen->cancelButtonSpriteIds[j][i]].pos1.x += r4; + gSprites[sFactorySwapScreen->cancelButtonSpriteIds[j][i]].pos1.x += deltaX; } } else { + // Set final position for (j = 0; j < ARRAY_COUNT(sFactorySwapScreen->cancelButtonSpriteIds); j++) { gSprites[sFactorySwapScreen->cancelButtonSpriteIds[j][0]].pos1.x = posX; gSprites[sFactorySwapScreen->cancelButtonSpriteIds[j][1]].pos1.x = posX + 16; } - taskId2 = gTasks[taskId].data[1]; - gTasks[taskId2].data[4] = 1; + prevTaskId = gTasks[taskId].tTaskId; + gTasks[prevTaskId].tSlideFinishedCancel = TRUE; DestroyTask(taskId); } break; } } -static void sub_819D588(u8 taskId) +// Slide action buttons offscreen +static void Swap_Task_ScreenInfoTransitionOut(u8 taskId) { - u8 anotherTaskId; + u8 slideTaskId; u16 hiPtr, loPtr; switch (gTasks[taskId].tState) @@ -2927,7 +2985,7 @@ static void sub_819D588(u8 taskId) case 0: LoadPalette(sSwapText_Pal, 0xE0, sizeof(sSwapText_Pal)); Swap_PrintActionStrings(); - PutWindowTilemap(SWAP_WIN_5); + PutWindowTilemap(SWAP_WIN_ACTION_FADE); gTasks[taskId].tState++; break; case 1: @@ -2941,50 +2999,54 @@ static void sub_819D588(u8 taskId) case 3: if (!gPaletteFade.active) { - FillWindowPixelBuffer(SWAP_WIN_5, PIXEL_FILL(0)); - CopyWindowToVram(SWAP_WIN_5, 2); + FillWindowPixelBuffer(SWAP_WIN_ACTION_FADE, PIXEL_FILL(0)); + CopyWindowToVram(SWAP_WIN_ACTION_FADE, 2); if (sFactorySwapScreen->inEnemyScreen == TRUE) { - anotherTaskId = CreateTask(sub_819D324, 0); - gTasks[taskId].data[3] = 0; - gTasks[anotherTaskId].data[1] = taskId; - gTasks[anotherTaskId].tState = 0; - gTasks[anotherTaskId].data[2] = 0; - gTasks[anotherTaskId].data[3] = 6; - gTasks[taskId].data[2] = 5; + // Start "Pkmn for Swap" button slide offscreen + slideTaskId = CreateTask(Swap_Task_SlideButtonOnOffScreen, 0); + gTasks[taskId].tSlideFinishedPkmn = FALSE; + gTasks[slideTaskId].tTaskId = taskId; + gTasks[slideTaskId].tState = SLIDE_BUTTON_PKMN; + gTasks[slideTaskId].tSlidingOn = FALSE; + gTasks[slideTaskId].tXIncrement = 6; + gTasks[taskId].tSecondSlideDelay = 5; gTasks[taskId].tState++; } else { - anotherTaskId = CreateTask(sub_819D324, 0); - gTasks[taskId].data[3] = 1; - gTasks[taskId].data[4] = 0; - gTasks[anotherTaskId].data[1] = taskId; - gTasks[anotherTaskId].tState = 1; - gTasks[anotherTaskId].data[2] = 0; - gTasks[anotherTaskId].data[3] = 6; + // Start "Cancel" button slide offscreen + slideTaskId = CreateTask(Swap_Task_SlideButtonOnOffScreen, 0); + gTasks[taskId].tSlideFinishedPkmn = TRUE; + gTasks[taskId].tSlideFinishedCancel = FALSE; + gTasks[slideTaskId].tTaskId = taskId; + gTasks[slideTaskId].tState = SLIDE_BUTTON_CANCEL; + gTasks[slideTaskId].tSlidingOn = FALSE; + gTasks[slideTaskId].tXIncrement = 6; gTasks[taskId].tState += 2; } } break; case 4: - if (gTasks[taskId].data[2] == 0) + // Start "Cancel" button slide offscreen for screens with both buttons + if (gTasks[taskId].tSecondSlideDelay == 0) { - anotherTaskId = CreateTask(sub_819D324, 0); - gTasks[taskId].data[4] = 0; - gTasks[anotherTaskId].data[1] = taskId; - gTasks[anotherTaskId].tState = 1; - gTasks[anotherTaskId].data[2] = 0; - gTasks[anotherTaskId].data[3] = 6; + slideTaskId = CreateTask(Swap_Task_SlideButtonOnOffScreen, 0); + gTasks[taskId].tSlideFinishedCancel = FALSE; + gTasks[slideTaskId].tTaskId = taskId; + gTasks[slideTaskId].tState = SLIDE_BUTTON_CANCEL; + gTasks[slideTaskId].tSlidingOn = FALSE; + gTasks[slideTaskId].tXIncrement = 6; gTasks[taskId].tState++; } else { - gTasks[taskId].data[2]--; + gTasks[taskId].tSecondSlideDelay--; } break; case 5: - if (gTasks[taskId].data[3] == 1 && gTasks[taskId].data[4] == 1) + if (gTasks[taskId].tSlideFinishedPkmn == TRUE + && gTasks[taskId].tSlideFinishedCancel == TRUE) { gTasks[taskId].tState = gTasks[taskId].tFollowUpTaskState; hiPtr = gTasks[taskId].tFollowUpTaskPtrHi; @@ -2995,9 +3057,10 @@ static void sub_819D588(u8 taskId) } } -static void sub_819D770(u8 taskId) +// Slide action buttons onscreen, reprint swap dialogue and mon info +static void Swap_Task_ScreenInfoTransitionIn(u8 taskId) { - u8 anotherTaskId; + u8 slideTaskId; u16 hiPtr, loPtr; if (sFactorySwapScreen->monPicAnimating == TRUE) return; @@ -3007,49 +3070,53 @@ static void sub_819D770(u8 taskId) case 0: if (sFactorySwapScreen->inEnemyScreen == TRUE) { - anotherTaskId = CreateTask(sub_819D324, 0); - gTasks[taskId].data[3] = 0; - gTasks[anotherTaskId].data[1] = taskId; - gTasks[anotherTaskId].tState = 0; - gTasks[anotherTaskId].data[2] = 1; - gTasks[anotherTaskId].data[3] = 6; - gTasks[taskId].data[2] = 10; + // Start "Pkmn for Swap" button slide onscreen + slideTaskId = CreateTask(Swap_Task_SlideButtonOnOffScreen, 0); + gTasks[taskId].tSlideFinishedPkmn = FALSE; + gTasks[slideTaskId].tTaskId = taskId; + gTasks[slideTaskId].tState = SLIDE_BUTTON_PKMN; + gTasks[slideTaskId].tSlidingOn = TRUE; + gTasks[slideTaskId].tXIncrement = 6; + gTasks[taskId].tSecondSlideDelay = 10; gTasks[taskId].tState++; } else { - anotherTaskId = CreateTask(sub_819D324, 0); - gTasks[taskId].data[3] = 1; - gTasks[taskId].data[4] = 0; - gTasks[anotherTaskId].data[1] = taskId; - gTasks[anotherTaskId].tState = 1; - gTasks[anotherTaskId].data[2] = 1; - gTasks[anotherTaskId].data[3] = 6; + // Start "Cancel" button slide onscreen + slideTaskId = CreateTask(Swap_Task_SlideButtonOnOffScreen, 0); + gTasks[taskId].tSlideFinishedPkmn = TRUE; + gTasks[taskId].tSlideFinishedCancel = FALSE; + gTasks[slideTaskId].tTaskId = taskId; + gTasks[slideTaskId].tState = SLIDE_BUTTON_CANCEL; + gTasks[slideTaskId].tSlidingOn = TRUE; + gTasks[slideTaskId].tXIncrement = 6; gTasks[taskId].tState += 2; } break; case 1: - if (gTasks[taskId].data[2] == 0) + // Start "Cancel" button slide onscreen for screens with both buttons + if (gTasks[taskId].tSecondSlideDelay == 0) { - anotherTaskId = CreateTask(sub_819D324, 0); - gTasks[taskId].data[4] = 0; - gTasks[anotherTaskId].data[1] = taskId; - gTasks[anotherTaskId].tState = 1; - gTasks[anotherTaskId].data[2] = 1; - gTasks[anotherTaskId].data[3] = 6; + slideTaskId = CreateTask(Swap_Task_SlideButtonOnOffScreen, 0); + gTasks[taskId].tSlideFinishedCancel = FALSE; + gTasks[slideTaskId].tTaskId = taskId; + gTasks[slideTaskId].tState = SLIDE_BUTTON_CANCEL; + gTasks[slideTaskId].tSlidingOn = TRUE; + gTasks[slideTaskId].tXIncrement = 6; gTasks[taskId].tState++; } else { - gTasks[taskId].data[2]--; + gTasks[taskId].tSecondSlideDelay--; } break; case 2: - if (gTasks[taskId].data[3] == 1 && gTasks[taskId].data[4] == 1) + if (gTasks[taskId].tSlideFinishedPkmn == TRUE + && gTasks[taskId].tSlideFinishedCancel == TRUE) { gPlttBufferFaded[226] = sPokeballGray_Pal[37]; Swap_PrintActionStrings(); - PutWindowTilemap(SWAP_WIN_5); + PutWindowTilemap(SWAP_WIN_ACTION_FADE); gTasks[taskId].tState++; } break; @@ -3070,8 +3137,8 @@ static void sub_819D770(u8 taskId) gTasks[taskId].tState++; break; case 6: - FillWindowPixelBuffer(SWAP_WIN_5, PIXEL_FILL(0)); - CopyWindowToVram(SWAP_WIN_5, 2); + FillWindowPixelBuffer(SWAP_WIN_ACTION_FADE, PIXEL_FILL(0)); + CopyWindowToVram(SWAP_WIN_ACTION_FADE, 2); gTasks[taskId].tState++; break; case 7: @@ -3085,8 +3152,8 @@ static void sub_819D770(u8 taskId) gTasks[taskId].tState++; break; case 8: - Swap_PrintMonSpecies3(); - sub_819EADC(); + Swap_PrintMonSpeciesForTransition(); + Swap_EraseSpeciesAtFadeWindow(); sFactorySwapScreen->fadeSpeciesNameActive = TRUE; gTasks[taskId].tState = gTasks[taskId].tFollowUpTaskState; hiPtr = gTasks[taskId].tFollowUpTaskPtrHi; @@ -3096,7 +3163,14 @@ static void sub_819D770(u8 taskId) } } -static void sub_819D9EC(u8 taskId) +#undef tTaskId +#undef tSlidingOn +#undef tXIncrement +#undef tSlideFinishedPkmn +#undef tSlideFinishedCancel + +// For switching between the swap screens with the player's / enemy's parties +static void Swap_Task_SwitchPartyScreen(u8 taskId) { u8 i; if (sFactorySwapScreen->monPicAnimating == TRUE) @@ -3105,23 +3179,24 @@ static void sub_819D9EC(u8 taskId) switch (gTasks[taskId].tState) { case 0: - Swap_PrintMonSpecies3(); + Swap_PrintMonSpeciesForTransition(); gTasks[taskId].tState++; break; case 1: - sub_819EADC(); + Swap_EraseSpeciesAtFadeWindow(); gSprites[sFactorySwapScreen->cursorSpriteId].invisible = TRUE; gTasks[taskId].tState++; break; case 2: - CreateTask(sub_819D12C, 0); - gTasks[sFactorySwapScreen->fadeSpeciesNameTaskId].func = Swap_Task_FadeSpeciesName2; + CreateTask(Swap_Task_SlideCycleBalls, 0); + gTasks[sFactorySwapScreen->fadeSpeciesNameTaskId].func = Swap_Task_FadeOutSpeciesName; gTasks[taskId].tState++; break; case 3: - if (!FuncIsActiveTask(sub_819D12C) && gTasks[sFactorySwapScreen->fadeSpeciesNameTaskId].data[4] == 1) + if (!FuncIsActiveTask(Swap_Task_SlideCycleBalls) + && gTasks[sFactorySwapScreen->fadeSpeciesNameTaskId].tFadeOutFinished == TRUE) { - sub_819EAC0(); + Swap_EraseSpeciesWindow(); if (!sFactorySwapScreen->inEnemyScreen) { Swap_InitActions(SWAP_ENEMY_SCREEN); @@ -3139,7 +3214,7 @@ static void sub_819D9EC(u8 taskId) sFactorySwapScreen->fadeSpeciesNameCoeffDelay = 0; sFactorySwapScreen->fadeSpeciesNameCoeff = 6; sFactorySwapScreen->fadeSpeciesNameFadeOut = FALSE; - gTasks[sFactorySwapScreen->fadeSpeciesNameTaskId].tState = 1; + gTasks[sFactorySwapScreen->fadeSpeciesNameTaskId].tState = FADESTATE_RUN; gTasks[taskId].tState++; } break; @@ -3147,12 +3222,14 @@ static void sub_819D9EC(u8 taskId) gTasks[taskId].tState = 0; gTasks[taskId].tFollowUpTaskPtrHi = (u32)(Swap_Task_HandleChooseMons) >> 16; gTasks[taskId].tFollowUpTaskPtrLo = (u32)(Swap_Task_HandleChooseMons); - gTasks[taskId].tFollowUpTaskState = 1; - gTasks[taskId].func = sub_819D770; + gTasks[taskId].tFollowUpTaskState = STATE_CHOOSE_MONS_HANDLE_INPUT; + gTasks[taskId].func = Swap_Task_ScreenInfoTransitionIn; break; } } +#undef tFadeOutFinished + static void Swap_InitStruct(void) { if (sFactorySwapScreen == NULL) @@ -3279,7 +3356,7 @@ static void CB2_InitSwapScreen(void) break; case 12: if (sFactorySwapScreen->fromSummaryScreen) - Swap_PrintMonSpecies2(); + Swap_PrintMonSpeciesAtFade(); gMain.state++; break; case 13: @@ -3309,17 +3386,17 @@ static void CB2_InitSwapScreen(void) sFactorySwapScreen->fadeSpeciesNameTaskId = CreateTask(Swap_Task_FadeSpeciesName, 0); if (!sFactorySwapScreen->fromSummaryScreen) { - gTasks[sFactorySwapScreen->fadeSpeciesNameTaskId].tState = 0; + gTasks[sFactorySwapScreen->fadeSpeciesNameTaskId].tState = FADESTATE_INIT; taskId = CreateTask(Swap_Task_HandleChooseMons, 0); - gTasks[taskId].tState = 0; + gTasks[taskId].tState = STATE_CHOOSE_MONS_INIT; } else { - sub_819EAF8(); - gTasks[sFactorySwapScreen->fadeSpeciesNameTaskId].tState = 1; + Swap_EraseActionFadeWindow(); + gTasks[sFactorySwapScreen->fadeSpeciesNameTaskId].tState = FADESTATE_RUN; sFactorySwapScreen->fadeSpeciesNameActive = FALSE; taskId = CreateTask(Swap_Task_HandleMenu, 0); - gTasks[taskId].tState = 2; + gTasks[taskId].tState = STATE_MENU_INIT; } SetMainCallback2(Swap_CB2); break; @@ -3635,26 +3712,26 @@ static void Swap_ErasePopupMenu(u8 windowId) ClearWindowTilemap(windowId); } -static void sub_819EAC0(void) +static void Swap_EraseSpeciesWindow(void) { PutWindowTilemap(SWAP_WIN_SPECIES); FillWindowPixelBuffer(SWAP_WIN_SPECIES, PIXEL_FILL(0)); CopyWindowToVram(SWAP_WIN_SPECIES, 2); } -static void sub_819EADC(void) +static void Swap_EraseSpeciesAtFadeWindow(void) { - PutWindowTilemap(SWAP_WIN_7); - FillWindowPixelBuffer(SWAP_WIN_7, PIXEL_FILL(0)); - CopyWindowToVram(SWAP_WIN_7, 2); + PutWindowTilemap(SWAP_WIN_SPECIES_AT_FADE); + FillWindowPixelBuffer(SWAP_WIN_SPECIES_AT_FADE, PIXEL_FILL(0)); + CopyWindowToVram(SWAP_WIN_SPECIES_AT_FADE, 2); } -static void sub_819EAF8(void) +static void Swap_EraseActionFadeWindow(void) { - sub_819EAC0(); - PutWindowTilemap(SWAP_WIN_5); - FillWindowPixelBuffer(SWAP_WIN_5, PIXEL_FILL(0)); - CopyWindowToVram(SWAP_WIN_5, 2); + Swap_EraseSpeciesWindow(); + PutWindowTilemap(SWAP_WIN_ACTION_FADE); + FillWindowPixelBuffer(SWAP_WIN_ACTION_FADE, PIXEL_FILL(0)); + CopyWindowToVram(SWAP_WIN_ACTION_FADE, 2); } static void Swap_PrintPkmnSwap(void) @@ -3722,16 +3799,16 @@ static void Swap_PrintActionString(const u8 *str, u32 y, u32 windowId) static void Swap_PrintActionStrings(void) { - FillWindowPixelBuffer(SWAP_WIN_5, PIXEL_FILL(0)); + FillWindowPixelBuffer(SWAP_WIN_ACTION_FADE, PIXEL_FILL(0)); switch (sFactorySwapScreen->inEnemyScreen) { case TRUE: - Swap_PrintActionString(gText_PkmnForSwap, 0, SWAP_WIN_5); + Swap_PrintActionString(gText_PkmnForSwap, 0, SWAP_WIN_ACTION_FADE); case FALSE: - Swap_PrintActionString(gText_Cancel3, 24, SWAP_WIN_5); + Swap_PrintActionString(gText_Cancel3, 24, SWAP_WIN_ACTION_FADE); break; } - CopyWindowToVram(SWAP_WIN_5, 3); + CopyWindowToVram(SWAP_WIN_ACTION_FADE, 3); } static void Swap_PrintActionStrings2(void) @@ -3763,7 +3840,8 @@ static void Swap_PrintOneActionString(u8 which) CopyWindowToVram(SWAP_WIN_OPTIONS, 3); } -static void Swap_PrintMonSpecies2(void) +// For printing the species name once its selected. Keep the current fade but don't keep fading in and out +static void Swap_PrintMonSpeciesAtFade(void) { u16 species; u8 x; @@ -3776,11 +3854,11 @@ static void Swap_PrintMonSpecies2(void) pal[4] = sFactorySwapScreen->speciesNameColorBackup; LoadPalette(pal, 0xF0, sizeof(sSwapText_Pal)); - PutWindowTilemap(SWAP_WIN_7); - FillWindowPixelBuffer(SWAP_WIN_7, PIXEL_FILL(0)); + PutWindowTilemap(SWAP_WIN_SPECIES_AT_FADE); + FillWindowPixelBuffer(SWAP_WIN_SPECIES_AT_FADE, PIXEL_FILL(0)); if (sFactorySwapScreen->cursorPos >= FRONTIER_PARTY_SIZE) { - CopyWindowToVram(SWAP_WIN_7, 3); + CopyWindowToVram(SWAP_WIN_SPECIES_AT_FADE, 3); } else { @@ -3791,12 +3869,13 @@ static void Swap_PrintMonSpecies2(void) species = GetMonData(&gEnemyParty[monId], MON_DATA_SPECIES, NULL); StringCopy(gStringVar4, gSpeciesNames[species]); x = GetStringRightAlignXOffset(1, gStringVar4, 86); - AddTextPrinterParameterized3(SWAP_WIN_7, 1, x, 1, sSwapSpeciesNameTextColors, 0, gStringVar4); - CopyWindowToVram(SWAP_WIN_7, 3); + AddTextPrinterParameterized3(SWAP_WIN_SPECIES_AT_FADE, 1, x, 1, sSwapSpeciesNameTextColors, 0, gStringVar4); + CopyWindowToVram(SWAP_WIN_SPECIES_AT_FADE, 3); } } -static void Swap_PrintMonSpecies3(void) +// Reprints the species name over the faded one after a transition +static void Swap_PrintMonSpeciesForTransition(void) { u16 species; u8 x; @@ -3882,12 +3961,12 @@ static void Swap_OptionSwap(u8 taskId) sFactorySwapScreen->playerMonId = sFactorySwapScreen->cursorPos; Swap_ErasePopupMenu(SWAP_WIN_OPTIONS); gTasks[taskId].tState = 0; - gTasks[taskId].func = sub_819D9EC; + gTasks[taskId].func = Swap_Task_SwitchPartyScreen; } static void Swap_OptionSummary(u8 taskId) { - gTasks[taskId].tState = 6; + gTasks[taskId].tState = STATE_SUMMARY_FADE; gTasks[taskId].func = Swap_Task_OpenSummaryScreen; } @@ -3898,8 +3977,8 @@ static void Swap_OptionRechoose(u8 taskId) gTasks[taskId].tState = 0; gTasks[taskId].tFollowUpTaskPtrHi = (u32)(Swap_Task_HandleChooseMons) >> 16; gTasks[taskId].tFollowUpTaskPtrLo = (u32)(Swap_Task_HandleChooseMons); - gTasks[taskId].tFollowUpTaskState = 1; - gTasks[taskId].func = sub_819D770; + gTasks[taskId].tFollowUpTaskState = STATE_CHOOSE_MONS_HANDLE_INPUT; + gTasks[taskId].func = Swap_Task_ScreenInfoTransitionIn; } static void Swap_RunActionFunc(u8 taskId) @@ -3914,16 +3993,16 @@ static void Swap_ActionCancel(u8 taskId) gTasks[taskId].tFollowUpTaskPtrLo = (u32)(Swap_AskQuitSwapping); gTasks[taskId].tState = 0; gTasks[taskId].tFollowUpTaskState = 0; - gTasks[taskId].func = sub_819D588; + gTasks[taskId].func = Swap_Task_ScreenInfoTransitionOut; } static void Swap_ActionPkmnForSwap(u8 taskId) { - gTasks[taskId].tFollowUpTaskPtrHi = (u32)(sub_819D9EC) >> 16; - gTasks[taskId].tFollowUpTaskPtrLo = (u32)(sub_819D9EC); + gTasks[taskId].tFollowUpTaskPtrHi = (u32)(Swap_Task_SwitchPartyScreen) >> 16; + gTasks[taskId].tFollowUpTaskPtrLo = (u32)(Swap_Task_SwitchPartyScreen); gTasks[taskId].tFollowUpTaskState = 0; gTasks[taskId].tState = 0; - gTasks[taskId].func = sub_819D588; + gTasks[taskId].func = Swap_Task_ScreenInfoTransitionOut; } static void Swap_ActionMon(u8 taskId) @@ -3932,13 +4011,13 @@ static void Swap_ActionMon(u8 taskId) { gTasks[taskId].tFollowUpTaskPtrHi = (u32)(Swap_Task_HandleMenu) >> 16; gTasks[taskId].tFollowUpTaskPtrLo = (u32)(Swap_Task_HandleMenu); - gTasks[taskId].tFollowUpTaskState = 2; + gTasks[taskId].tFollowUpTaskState = STATE_MENU_INIT; } else if (Swap_AlreadyHasSameSpecies(sFactorySwapScreen->cursorPos) == TRUE) { OpenMonPic(&sFactorySwapScreen->monPic.bgSpriteId, &sFactorySwapScreen->monPicAnimating, TRUE); gTasks[taskId].tState = 0; - gTasks[taskId].tFollowUpTaskState = 1; + gTasks[taskId].tFollowUpTaskState = STATE_CHOOSE_MONS_HANDLE_INPUT; gTasks[taskId].func = Swap_TaskCantHaveSameMons; return; } @@ -3949,7 +4028,7 @@ static void Swap_ActionMon(u8 taskId) gTasks[taskId].tFollowUpTaskState = 0; } gTasks[taskId].tState = 0; - gTasks[taskId].func = sub_819D588; + gTasks[taskId].func = Swap_Task_ScreenInfoTransitionOut; } #define sIsSwapScreen data[7] @@ -4026,8 +4105,8 @@ static void Swap_TaskCantHaveSameMons(u8 taskId) case 2: if (sFactorySwapScreen->monPicAnimating != TRUE) { - FillWindowPixelBuffer(SWAP_WIN_5, PIXEL_FILL(0)); - CopyWindowToVram(SWAP_WIN_5, 2); + FillWindowPixelBuffer(SWAP_WIN_ACTION_FADE, PIXEL_FILL(0)); + CopyWindowToVram(SWAP_WIN_ACTION_FADE, 2); gTasks[taskId].tState++; } break; @@ -4036,8 +4115,8 @@ static void Swap_TaskCantHaveSameMons(u8 taskId) gTasks[taskId].tState++; break; case 4: - Swap_PrintMonSpecies3(); - sub_819EADC(); + Swap_PrintMonSpeciesForTransition(); + Swap_EraseSpeciesAtFadeWindow(); sFactorySwapScreen->fadeSpeciesNameActive = TRUE; gTasks[taskId].tState = gTasks[taskId].tFollowUpTaskState; gTasks[taskId].func = Swap_Task_HandleChooseMons; From 84fbcc9dd615e10f3f0c12c4bad8134872ea6c19 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 31 Dec 2020 00:44:43 -0500 Subject: [PATCH 6/6] Fix modern -> UBFIX macro change --- src/battle_factory_screen.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/battle_factory_screen.c b/src/battle_factory_screen.c index 1ceff5b98..86e3b0233 100644 --- a/src/battle_factory_screen.c +++ b/src/battle_factory_screen.c @@ -1179,7 +1179,7 @@ static void CB2_InitSelectScreen(void) LoadPalette(gFrontierFactorySelectMenu_Pal, 0, 0x40); LoadPalette(sSelectText_Pal, 0xF0, 8); LoadPalette(sSelectText_Pal, 0xE0, 10); -#if UBFIX +#ifdef UBFIX if (sFactorySelectScreen && sFactorySelectScreen->fromSummaryScreen) #else if (sFactorySelectScreen->fromSummaryScreen == TRUE) @@ -1205,7 +1205,7 @@ static void CB2_InitSelectScreen(void) SetVBlankCallback(VBlankCB_SelectScreen); BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, RGB_BLACK); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_BG0_ON | DISPCNT_BG1_ON | DISPCNT_OBJ_1D_MAP); -#if UBFIX +#ifdef UBFIX if (sFactorySelectScreen && sFactorySelectScreen->fromSummaryScreen) #else if (sFactorySelectScreen->fromSummaryScreen == TRUE) @@ -1223,7 +1223,7 @@ static void CB2_InitSelectScreen(void) gMain.state++; break; case 5: -#if UBFIX +#ifdef UBFIX if (sFactorySelectScreen && sFactorySelectScreen->fromSummaryScreen) #else if (sFactorySelectScreen->fromSummaryScreen == TRUE) @@ -3330,7 +3330,7 @@ static void CB2_InitSwapScreen(void) gMain.state++; break; case 5: -#if UBFIX +#ifdef UBFIX if (sFactorySwapScreen && sFactorySwapScreen->fromSummaryScreen) #else if (sFactorySwapScreen->fromSummaryScreen == TRUE)