diff options
Diffstat (limited to 'src/battle_factory.c')
-rw-r--r-- | src/battle_factory.c | 888 |
1 files changed, 598 insertions, 290 deletions
diff --git a/src/battle_factory.c b/src/battle_factory.c index 9cb773ea3..f7568055c 100644 --- a/src/battle_factory.c +++ b/src/battle_factory.c @@ -19,10 +19,14 @@ #include "pokemon_summary_screen.h" #include "sound.h" #include "pokedex.h" +#include "blend_palette.h" #include "trainer_pokemon_sprites.h" #include "constants/battle_frontier.h" #include "constants/songs.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. + #define MENU_SUMMARY 0 #define MENU_RENT 1 #define MENU_DESELECT 1 @@ -57,23 +61,19 @@ struct FactorySelectMonsStruct u8 selectingMonsState; bool8 fromSummaryScreen; u8 yesNoCursorPos; - u8 unk8; - u8 unk9; + u8 unused8; struct FactorySelecteableMon mons[SELECTABLE_MONS_COUNT]; - u32 unk294; - struct UnkFactoryStruct unk298; - u32 unk29C; + struct UnkFactoryStruct unk294[3]; u8 unk2A0; - u8 unk2A1; - u8 unk2A2; - u8 unk2A3; + u8 palBlendTaskId; + bool8 unk2A2; u16 unk2A4; - u16 unk2A6; - u16 unk2A8; - u16 unk2AA; + bool8 unk2A6; + u8 unk2A7; + u8 unk2A8; + u8 unk2A9; }; -extern struct FactorySelectMonsStruct *gUnknown_0300127C; extern u8 (*gUnknown_030062E8)(void); extern u8 gUnknown_0203CF20; @@ -81,42 +81,46 @@ extern const u16 gBattleFrontierHeldItems[]; extern const struct FacilityMon gBattleFrontierMons[]; extern const struct FacilityMon gSlateportBattleTentMons[]; extern const struct BattleFrontierTrainer gBattleFrontierTrainers[]; +extern const u8 gUnknown_085B18AC[]; extern void SetMonMoveAvoidReturn(struct Pokemon *mon, u16 move, u8 moveSlot); // This file's functions. -void sub_819A514(void); -void sub_819C5D0(u16 mWin0H, u16 nWin0H, u16 mWin0V, u16 nWin0V); -void sub_819A9AC(void); -void sub_819AA18(void); -void sub_819BE34(void); -void PrintSelectMonString(void); -void PrintMonSpecies(void); -void PrintMonCategory(void); -void sub_819B9E8(void); -void PrintRentalPkmnString(void); -void CopySelectedMonsToPlayerParty(void); -void sub_819C4B4(void); -void sub_819B8D4(void); -void sub_819C568(void); -void sub_819B844(void); -void PrintSelectableMenuOptions(void); -void PrintSelectableYesNo(void); -void sub_819C69C(u8 taskId); -void Task_HandleSelectionScreenChooseMons(u8 taskId); -void Task_HandleSelectionScreenMenu(u8 taskId); -void CreateFrontierFactorySelectableMons(u8 firstMonId); -void CreateTentFactorySelectableMons(u8 firstMonId); -void SetBallSpritePaletteNum(u8 id); +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_ShowCheckedMonSprite(void); +static void Select_PrintSelectMonString(void); +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_ShowYesNoOptions(void); +static void sub_819C568(void); +static void Select_ShowMenuOptions(void); +static void Select_PrintMenuOptions(void); +static void Select_PrintYesNoOptions(void); +static void Task_SelectBlendPalette(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); void sub_819F444(struct UnkFactoryStruct arg0, u8 *arg1); -void sub_819B958(u8 windowId); +static void sub_819B958(u8 windowId); void sub_819F2B4(u8 *arg0, u8 *arg1, u8 arg2); void sub_819F3F8(struct UnkFactoryStruct arg0, u8 *arg1, u8 arg2); -u8 sub_819BC04(void); -u8 sub_819BC9C(void); +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); u8 sub_81A6F70(u8 battleMode, u8 lvlMode); u8 sub_81A6CA8(u8 arg0, u8 arg1); -bool32 sub_819C634(u16 monSetId); +static bool32 Select_AreSpeciesValid(u16 monSetId); // Ewram variables EWRAM_DATA u8 *gUnknown_0203CE2C = NULL; @@ -125,17 +129,68 @@ EWRAM_DATA u8 *gUnknown_0203CE34 = NULL; EWRAM_DATA u8 *gUnknown_0203CE38 = NULL; static EWRAM_DATA struct Pokemon *sFactorySelectMons = NULL; +// IWRAM bss +static IWRAM_DATA struct FactorySelectMonsStruct *sFactorySelectScreen; + // Const rom data. +const u16 gUnknown_0860F13C[] = INCBIN_U16("graphics/unknown/unknown_60F13C.gbapal"); +const u16 gUnknown_0860F15C[] = INCBIN_U16("graphics/unknown/unknown_60F15C.gbapal"); +const u16 gUnknown_0860F17C[] = INCBIN_U16("graphics/unknown/unknown_60F17C.gbapal"); +const u8 gUnknown_0860F1BC[] = INCBIN_U8("graphics/unknown/unknown_60F1BC.4bpp"); +const u8 gUnknown_0860F3BC[] = INCBIN_U8("graphics/unknown/unknown_60F3BC.4bpp"); +const u8 gUnknown_0860F43C[] = INCBIN_U8("graphics/unknown/unknown_60F43C.4bpp"); +const u8 gUnknown_0860F53C[] = INCBIN_U8("graphics/unknown/unknown_60F53C.4bpp"); +const u8 gUnknown_0860F63C[] = INCBIN_U8("graphics/unknown/unknown_60F63C.4bpp"); +const u8 gUnknown_0860F6BC[] = INCBIN_U8("graphics/unknown/unknown_60F6BC.4bpp"); +const u8 gUnknown_0860F7BC[] = INCBIN_U8("graphics/unknown/unknown_60F7BC.4bpp"); +const u8 gUnknown_0860F83C[] = INCBIN_U8("graphics/unknown/unknown_60F83C.4bpp"); +const u8 gUnknown_0860F93C[] = INCBIN_U8("graphics/unknown/unknown_60F93C.4bpp"); +const u8 gUnknown_0860FA3C[] = INCBIN_U8("graphics/unknown/unknown_60FA3C.4bpp"); +const u8 gUnknown_0861023C[] = INCBIN_U8("graphics/unknown/unknown_61023C.bin"); +const u8 gUnknown_0861033C[] = INCBIN_U8("graphics/unknown/unknown_61033C.4bpp"); +const u16 gUnknown_0861039C[] = INCBIN_U16("graphics/unknown/unknown_61039C.gbapal"); + +const struct SpriteSheet gUnknown_086103BC[] = +{ + {gUnknown_0860F3BC, sizeof(gUnknown_0860F3BC), 0x65}, + {gUnknown_0860F43C, sizeof(gUnknown_0860F43C), 0x66}, + {gUnknown_0860F53C, sizeof(gUnknown_0860F53C), 0x67}, + {gUnknown_0860FA3C, sizeof(gUnknown_0860FA3C), 0x6D}, + {}, +}; + +const struct CompressedSpriteSheet gUnknown_086103E4[] = +{ + {gUnknown_085B18AC, 0x800, 0x64}, + {}, +}; + +const struct SpritePalette gUnknown_086103F4[] = +{ + {gUnknown_0860F13C, 0x64}, + {gUnknown_0860F15C, 0x65}, + {gUnknown_0860F17C, 0x66}, + {gUnknown_0861039C, 0x67}, + {}, +}; + +u8 (* const sSelect_MenuOptionFuncs[])(void) = +{ + [MENU_SUMMARY] = Select_OptionSummary, + [MENU_RENT] /*Or Deselect*/ = Select_OptionRentDeselect, + [MENU_OTHERS] = Select_OptionOthers +}; + extern const struct BgTemplate gUnknown_08610428[3]; extern const struct WindowTemplate gUnknown_08610434[]; -extern const u8 gUnknown_0861033C[]; -extern const u8 gUnknown_0861023C[]; extern const u16 gUnknown_0861046C[]; -extern const u16 gUnknown_0861039C[]; -extern const struct SpritePalette gUnknown_086103F4[]; -extern const struct SpriteSheet gUnknown_086103BC[]; -extern const struct CompressedSpriteSheet gUnknown_086103E4[]; extern const struct SpriteTemplate gUnknown_086105D8; +extern const struct SpriteTemplate gUnknown_086105F0; +extern const struct SpriteTemplate gUnknown_08610608; +extern const struct SpriteTemplate gUnknown_08610620; +extern const struct SpriteTemplate gUnknown_08610638; +extern const u8 gUnknown_08610479[]; +extern const u8 gUnknown_08610476[]; // gfx extern const u8 gFrontierFactorySelectMenu_Gfx[]; @@ -188,7 +243,7 @@ void sub_819A44C(struct Sprite *sprite) } } -void sub_819A4C8(void) +static void Select_CB2(void) { AnimateSprites(); BuildOamBuffer(); @@ -197,7 +252,7 @@ void sub_819A4C8(void) RunTasks(); } -void sub_819A4E4(void) +static void Select_VblankCb(void) { LoadOam(); ProcessSpriteCopyRequests(); @@ -206,11 +261,11 @@ void sub_819A4E4(void) void sub_819A4F8(void) { - gUnknown_0300127C = NULL; - SetMainCallback2(sub_819A514); + sFactorySelectScreen = NULL; + SetMainCallback2(CB2_InitSelectScreen); } -void sub_819A514(void) +static void CB2_InitSelectScreen(void) { u8 taskId; @@ -265,8 +320,8 @@ void sub_819A514(void) LoadPalette(gFrontierFactorySelectMenu_Pal, 0, 0x40); LoadPalette(gUnknown_0861046C, 0xF0, 8); LoadPalette(gUnknown_0861046C, 0xE0, 10); - if (gUnknown_0300127C->fromSummaryScreen == TRUE) - gPlttBufferUnfaded[228] = gUnknown_0300127C->unk2A4; + if (sFactorySelectScreen->fromSummaryScreen == TRUE) + gPlttBufferUnfaded[228] = sFactorySelectScreen->unk2A4; LoadPalette(gUnknown_0861039C, 0x20, 4); gMain.state++; break; @@ -284,12 +339,12 @@ void sub_819A514(void) LoadCompressedObjectPic(gUnknown_086103E4); ShowBg(0); ShowBg(1); - SetVBlankCallback(sub_819A4E4); + SetVBlankCallback(Select_VblankCb); BeginNormalPaletteFade(0xFFFFFFFF, 0, 0x10, 0, 0); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_BG0_ON | DISPCNT_BG1_ON | DISPCNT_OBJ_1D_MAP); - if (gUnknown_0300127C->fromSummaryScreen == TRUE) + if (sFactorySelectScreen->fromSummaryScreen == TRUE) { - sub_819C5D0(88, 152, 32, 96); + Select_SetWinRegs(88, 152, 32, 96); 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)); @@ -301,67 +356,67 @@ void sub_819A514(void) gMain.state++; break; case 5: - if (gUnknown_0300127C->fromSummaryScreen == TRUE) - gUnknown_0300127C->cursorPos = gUnknown_0203CF20; - sub_819A9AC(); - sub_819AA18(); - if (gUnknown_0300127C->fromSummaryScreen == TRUE) - sub_819BE34(); + if (sFactorySelectScreen->fromSummaryScreen == TRUE) + sFactorySelectScreen->cursorPos = gUnknown_0203CF20; + Select_InitMonsData(); + Select_InitAllSprites(); + if (sFactorySelectScreen->fromSummaryScreen == TRUE) + Select_ShowCheckedMonSprite(); gMain.state++; break; case 6: - PrintSelectMonString(); + Select_PrintSelectMonString(); PutWindowTilemap(2); gMain.state++; break; case 7: - PrintMonCategory(); + Select_PrintMonCategory(); PutWindowTilemap(5); gMain.state++; break; case 8: - PrintMonSpecies(); + Select_PrintMonSpecies(); PutWindowTilemap(1); gMain.state++; break; case 9: - PrintRentalPkmnString(); + Select_PrintRentalPkmnString(); PutWindowTilemap(0); gMain.state++; break; case 10: - gUnknown_0300127C->unk2A1 = CreateTask(sub_819C69C, 0); - if (!gUnknown_0300127C->fromSummaryScreen) + sFactorySelectScreen->palBlendTaskId = CreateTask(Task_SelectBlendPalette, 0); + if (!sFactorySelectScreen->fromSummaryScreen) { - gTasks[gUnknown_0300127C->unk2A1].data[0] = 0; + gTasks[sFactorySelectScreen->palBlendTaskId].data[0] = 0; taskId = CreateTask(Task_HandleSelectionScreenChooseMons, 0); gTasks[taskId].data[0] = 0; } else { - gTasks[gUnknown_0300127C->unk2A1].data[0] = 1; - gUnknown_0300127C->unk2A2 = 0; + gTasks[sFactorySelectScreen->palBlendTaskId].data[0] = 1; + sFactorySelectScreen->unk2A2 = FALSE; taskId = CreateTask(Task_HandleSelectionScreenMenu, 0); gTasks[taskId].data[0] = 13; } - SetMainCallback2(sub_819A4C8); + SetMainCallback2(Select_CB2); break; } } -void sub_819A9AC(void) +static void Select_InitMonsData(void) { u8 i; - if (gUnknown_0300127C != NULL) + if (sFactorySelectScreen != NULL) return; - gUnknown_0300127C = AllocZeroed(sizeof(*gUnknown_0300127C)); - gUnknown_0300127C->cursorPos = 0; - gUnknown_0300127C->selectingMonsState = 1; - gUnknown_0300127C->fromSummaryScreen = FALSE; + sFactorySelectScreen = AllocZeroed(sizeof(*sFactorySelectScreen)); + sFactorySelectScreen->cursorPos = 0; + sFactorySelectScreen->selectingMonsState = 1; + sFactorySelectScreen->fromSummaryScreen = FALSE; for (i = 0; i < SELECTABLE_MONS_COUNT; i++) - gUnknown_0300127C->mons[i].selectedId = 0; + sFactorySelectScreen->mons[i].selectedId = 0; if (gSaveBlock2Ptr->frontier.lvlMode != FRONTIER_LVL_TENT) CreateFrontierFactorySelectableMons(0); @@ -369,157 +424,153 @@ void sub_819A9AC(void) CreateTentFactorySelectableMons(0); } -extern const struct SpriteTemplate gUnknown_086105F0; -extern const struct SpriteTemplate gUnknown_08610608; -extern const struct SpriteTemplate gUnknown_08610620; - -void sub_819AA18(void) +static void Select_InitAllSprites(void) { u8 i, cursorPos; s16 x; for (i = 0; i < SELECTABLE_MONS_COUNT; i++) { - gUnknown_0300127C->mons[i].spriteId = CreateSprite(&gUnknown_086105D8, (35 * i) + 32, 64, 1); - gSprites[gUnknown_0300127C->mons[i].spriteId].data[0] = 0; - SetBallSpritePaletteNum(i); + sFactorySelectScreen->mons[i].spriteId = CreateSprite(&gUnknown_086105D8, (35 * i) + 32, 64, 1); + gSprites[sFactorySelectScreen->mons[i].spriteId].data[0] = 0; + Select_SetBallSpritePaletteNum(i); } - cursorPos = gUnknown_0300127C->cursorPos; - x = gSprites[gUnknown_0300127C->mons[cursorPos].spriteId].pos1.x; - gUnknown_0300127C->cursorSpriteId = CreateSprite(&gUnknown_086105F0, x, 88, 0); - gUnknown_0300127C->menuCursor1SpriteId = CreateSprite(&gUnknown_08610608, 176, 112, 0); - gUnknown_0300127C->menuCursor2SpriteId = CreateSprite(&gUnknown_08610620, 176, 144, 0); - - gSprites[gUnknown_0300127C->menuCursor1SpriteId].invisible = 1; - gSprites[gUnknown_0300127C->menuCursor2SpriteId].invisible = 1; - - gSprites[gUnknown_0300127C->menuCursor1SpriteId].centerToCornerVecX = 0; - gSprites[gUnknown_0300127C->menuCursor1SpriteId].centerToCornerVecY = 0; - gSprites[gUnknown_0300127C->menuCursor2SpriteId].centerToCornerVecX = 0; - gSprites[gUnknown_0300127C->menuCursor2SpriteId].centerToCornerVecY = 0; + 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); + + gSprites[sFactorySelectScreen->menuCursor1SpriteId].invisible = 1; + gSprites[sFactorySelectScreen->menuCursor2SpriteId].invisible = 1; + + gSprites[sFactorySelectScreen->menuCursor1SpriteId].centerToCornerVecX = 0; + gSprites[sFactorySelectScreen->menuCursor1SpriteId].centerToCornerVecY = 0; + gSprites[sFactorySelectScreen->menuCursor2SpriteId].centerToCornerVecX = 0; + gSprites[sFactorySelectScreen->menuCursor2SpriteId].centerToCornerVecY = 0; } -void sub_819AB40(void) +static void Select_DestroyAllSprites(void) { u8 i; for (i = 0; i < SELECTABLE_MONS_COUNT; i++) - DestroySprite(&gSprites[gUnknown_0300127C->mons[i].spriteId]); + DestroySprite(&gSprites[sFactorySelectScreen->mons[i].spriteId]); - DestroySprite(&gSprites[gUnknown_0300127C->cursorSpriteId]); - DestroySprite(&gSprites[gUnknown_0300127C->menuCursor1SpriteId]); - DestroySprite(&gSprites[gUnknown_0300127C->menuCursor2SpriteId]); + DestroySprite(&gSprites[sFactorySelectScreen->cursorSpriteId]); + DestroySprite(&gSprites[sFactorySelectScreen->menuCursor1SpriteId]); + DestroySprite(&gSprites[sFactorySelectScreen->menuCursor2SpriteId]); } -void UpdateBallCursorPosition(s8 direction) +static void Select_UpdateBallCursorPosition(s8 direction) { u8 cursorPos; if (direction > 0) // Move cursor right. { - if (gUnknown_0300127C->cursorPos != SELECTABLE_MONS_COUNT - 1) - gUnknown_0300127C->cursorPos++; + if (sFactorySelectScreen->cursorPos != SELECTABLE_MONS_COUNT - 1) + sFactorySelectScreen->cursorPos++; else - gUnknown_0300127C->cursorPos = 0; + sFactorySelectScreen->cursorPos = 0; } else // Move cursor left. { - if (gUnknown_0300127C->cursorPos != 0) - gUnknown_0300127C->cursorPos--; + if (sFactorySelectScreen->cursorPos != 0) + sFactorySelectScreen->cursorPos--; else - gUnknown_0300127C->cursorPos = SELECTABLE_MONS_COUNT - 1; + sFactorySelectScreen->cursorPos = SELECTABLE_MONS_COUNT - 1; } - cursorPos = gUnknown_0300127C->cursorPos; - gSprites[gUnknown_0300127C->cursorSpriteId].pos1.x = gSprites[gUnknown_0300127C->mons[cursorPos].spriteId].pos1.x; + cursorPos = sFactorySelectScreen->cursorPos; + gSprites[sFactorySelectScreen->cursorSpriteId].pos1.x = gSprites[sFactorySelectScreen->mons[cursorPos].spriteId].pos1.x; } -void UpdateMenuCursorPosition(s8 direction) +static void Select_UpdateMenuCursorPosition(s8 direction) { if (direction > 0) // Move cursor down. { - if (gUnknown_0300127C->menuCursorPos != MENU_OPTIONS_COUNT - 1) - gUnknown_0300127C->menuCursorPos++; + if (sFactorySelectScreen->menuCursorPos != MENU_OPTIONS_COUNT - 1) + sFactorySelectScreen->menuCursorPos++; else - gUnknown_0300127C->menuCursorPos = 0; + sFactorySelectScreen->menuCursorPos = 0; } else // Move cursor up. { - if (gUnknown_0300127C->menuCursorPos != 0) - gUnknown_0300127C->menuCursorPos--; + if (sFactorySelectScreen->menuCursorPos != 0) + sFactorySelectScreen->menuCursorPos--; else - gUnknown_0300127C->menuCursorPos = MENU_OPTIONS_COUNT - 1; + sFactorySelectScreen->menuCursorPos = MENU_OPTIONS_COUNT - 1; } - gSprites[gUnknown_0300127C->menuCursor1SpriteId].pos1.y = (gUnknown_0300127C->menuCursorPos * 16) + 112; - gSprites[gUnknown_0300127C->menuCursor2SpriteId].pos1.y = (gUnknown_0300127C->menuCursorPos * 16) + 112; + gSprites[sFactorySelectScreen->menuCursor1SpriteId].pos1.y = (sFactorySelectScreen->menuCursorPos * 16) + 112; + gSprites[sFactorySelectScreen->menuCursor2SpriteId].pos1.y = (sFactorySelectScreen->menuCursorPos * 16) + 112; } -void UpdateYesNoCursorPosition(s8 direction) +static void Select_UpdateYesNoCursorPosition(s8 direction) { if (direction > 0) // Move cursor down. { - if (gUnknown_0300127C->yesNoCursorPos != 1) - gUnknown_0300127C->yesNoCursorPos++; + if (sFactorySelectScreen->yesNoCursorPos != 1) + sFactorySelectScreen->yesNoCursorPos++; else - gUnknown_0300127C->yesNoCursorPos = 0; + sFactorySelectScreen->yesNoCursorPos = 0; } else // Move cursor up. { - if (gUnknown_0300127C->yesNoCursorPos != 0) - gUnknown_0300127C->yesNoCursorPos--; + if (sFactorySelectScreen->yesNoCursorPos != 0) + sFactorySelectScreen->yesNoCursorPos--; else - gUnknown_0300127C->yesNoCursorPos = 1; + sFactorySelectScreen->yesNoCursorPos = 1; } - gSprites[gUnknown_0300127C->menuCursor1SpriteId].pos1.y = (gUnknown_0300127C->yesNoCursorPos * 16) + 112; - gSprites[gUnknown_0300127C->menuCursor2SpriteId].pos1.y = (gUnknown_0300127C->yesNoCursorPos * 16) + 112; + gSprites[sFactorySelectScreen->menuCursor1SpriteId].pos1.y = (sFactorySelectScreen->yesNoCursorPos * 16) + 112; + gSprites[sFactorySelectScreen->menuCursor2SpriteId].pos1.y = (sFactorySelectScreen->yesNoCursorPos * 16) + 112; } -void HandleMonSelectionChange(void) +static void Select_HandleMonSelectionChange(void) { u8 i, paletteNum; - u8 cursorPos = gUnknown_0300127C->cursorPos; - if (gUnknown_0300127C->mons[cursorPos].selectedId) // Deselect a mon. + u8 cursorPos = sFactorySelectScreen->cursorPos; + if (sFactorySelectScreen->mons[cursorPos].selectedId) // Deselect a mon. { paletteNum = IndexOfSpritePaletteTag(TAG_PAL_BALL_GREY); - if (gUnknown_0300127C->selectingMonsState == 3 && gUnknown_0300127C->mons[cursorPos].selectedId == 1) + if (sFactorySelectScreen->selectingMonsState == 3 && sFactorySelectScreen->mons[cursorPos].selectedId == 1) { for (i = 0; i < SELECTABLE_MONS_COUNT; i++) { - if (gUnknown_0300127C->mons[i].selectedId == 2) + if (sFactorySelectScreen->mons[i].selectedId == 2) break; } if (i == SELECTABLE_MONS_COUNT) return; else - gUnknown_0300127C->mons[i].selectedId = 1; + sFactorySelectScreen->mons[i].selectedId = 1; } - gUnknown_0300127C->mons[cursorPos].selectedId = 0; - gUnknown_0300127C->selectingMonsState--; + sFactorySelectScreen->mons[cursorPos].selectedId = 0; + sFactorySelectScreen->selectingMonsState--; } else // Select a mon. { paletteNum = IndexOfSpritePaletteTag(TAG_PAL_BALL_SELECTED); - gUnknown_0300127C->mons[cursorPos].selectedId = gUnknown_0300127C->selectingMonsState; - gUnknown_0300127C->selectingMonsState++; + sFactorySelectScreen->mons[cursorPos].selectedId = sFactorySelectScreen->selectingMonsState; + sFactorySelectScreen->selectingMonsState++; } - gSprites[gUnknown_0300127C->mons[cursorPos].spriteId].oam.paletteNum = paletteNum; + gSprites[sFactorySelectScreen->mons[cursorPos].spriteId].oam.paletteNum = paletteNum; } -void SetBallSpritePaletteNum(u8 id) +static void Select_SetBallSpritePaletteNum(u8 id) { u8 palNum; - if (gUnknown_0300127C->mons[id].selectedId) + if (sFactorySelectScreen->mons[id].selectedId) palNum = IndexOfSpritePaletteTag(TAG_PAL_BALL_SELECTED); else palNum = IndexOfSpritePaletteTag(TAG_PAL_BALL_GREY); - gSprites[gUnknown_0300127C->mons[id].spriteId].oam.paletteNum = palNum; + gSprites[sFactorySelectScreen->mons[id].spriteId].oam.paletteNum = palNum; } -void Task_FromSelectScreenToSummaryScreen(u8 taskId) +static void Task_FromSelectScreenToSummaryScreen(u8 taskId) { u8 i; u8 currMonId; @@ -534,9 +585,9 @@ void Task_FromSelectScreenToSummaryScreen(u8 taskId) case 7: if (!gPaletteFade.active) { - DestroyTask(gUnknown_0300127C->unk2A1); - sub_819F444(gUnknown_0300127C->unk298, &gUnknown_0300127C->unk2A0); - sub_819AB40(); + DestroyTask(sFactorySelectScreen->palBlendTaskId); + sub_819F444(sFactorySelectScreen->unk294[1], &sFactorySelectScreen->unk2A0); + Select_DestroyAllSprites(); FREE_AND_SET_NULL(gUnknown_0203CE2C); FREE_AND_SET_NULL(gUnknown_0203CE30); FREE_AND_SET_NULL(gUnknown_0203CE34); @@ -546,21 +597,21 @@ void Task_FromSelectScreenToSummaryScreen(u8 taskId) } break; case 8: - gUnknown_0300127C->unk2A4 = gPlttBufferUnfaded[228]; + sFactorySelectScreen->unk2A4 = gPlttBufferUnfaded[228]; DestroyTask(taskId); - gUnknown_0300127C->fromSummaryScreen = TRUE; - currMonId = gUnknown_0300127C->cursorPos; + sFactorySelectScreen->fromSummaryScreen = TRUE; + currMonId = sFactorySelectScreen->cursorPos; sFactorySelectMons = AllocZeroed(sizeof(struct Pokemon) * SELECTABLE_MONS_COUNT); for (i = 0; i < SELECTABLE_MONS_COUNT; i++) - sFactorySelectMons[i] = gUnknown_0300127C->mons[i].monData; - ShowPokemonSummaryScreen(1, sFactorySelectMons, currMonId, SELECTABLE_MONS_COUNT - 1, sub_819A514); + sFactorySelectMons[i] = sFactorySelectScreen->mons[i].monData; + ShowPokemonSummaryScreen(1, sFactorySelectMons, currMonId, SELECTABLE_MONS_COUNT - 1, CB2_InitSelectScreen); break; } } -void Task_CloseSelectionScreen(u8 taskId) +static void Task_CloseSelectionScreen(u8 taskId) { - if (gUnknown_0300127C->unk2A0 != 1) + if (sFactorySelectScreen->unk2A0 != 1) { switch (gTasks[taskId].data[0]) { @@ -571,13 +622,13 @@ void Task_CloseSelectionScreen(u8 taskId) case 1: if (!UpdatePaletteFade()) { - CopySelectedMonsToPlayerParty(); - DestroyTask(gUnknown_0300127C->unk2A1); - sub_819AB40(); + Select_CopyMonsToPlayerParty(); + DestroyTask(sFactorySelectScreen->palBlendTaskId); + Select_DestroyAllSprites(); FREE_AND_SET_NULL(gUnknown_0203CE2C); FREE_AND_SET_NULL(gUnknown_0203CE34); FREE_AND_SET_NULL(gUnknown_0203CE38); - FREE_AND_SET_NULL(gUnknown_0300127C); + FREE_AND_SET_NULL(sFactorySelectScreen); FreeAllWindowBuffers(); SetMainCallback2(CB2_ReturnToFieldContinueScript); DestroyTask(taskId); @@ -587,9 +638,9 @@ void Task_CloseSelectionScreen(u8 taskId) } } -void Task_HandleSelectionScreenYesNo(u8 taskId) +static void Task_HandleSelectionScreenYesNo(u8 taskId) { - if (gUnknown_0300127C->unk2A0 != 1) + if (sFactorySelectScreen->unk2A0 != 1) { switch (gTasks[taskId].data[0]) { @@ -598,14 +649,14 @@ void Task_HandleSelectionScreenYesNo(u8 taskId) gTasks[taskId].data[0] = 4; break; case 4: - sub_819B8D4(); + Select_ShowYesNoOptions(); gTasks[taskId].data[0] = 5; break; case 5: if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); - if (gUnknown_0300127C->yesNoCursorPos == 0) + if (sFactorySelectScreen->yesNoCursorPos == 0) { sub_819C568(); gTasks[taskId].data[0] = 0; @@ -615,7 +666,7 @@ void Task_HandleSelectionScreenYesNo(u8 taskId) { sub_819B958(4); sub_819BC9C(); - gUnknown_0300127C->unk2A2 = 1; + sFactorySelectScreen->unk2A2 = TRUE; gTasks[taskId].data[0] = 1; gTasks[taskId].func = Task_HandleSelectionScreenChooseMons; } @@ -625,39 +676,39 @@ void Task_HandleSelectionScreenYesNo(u8 taskId) PlaySE(SE_SELECT); sub_819B958(4); sub_819BC9C(); - gUnknown_0300127C->unk2A2 = 1; + sFactorySelectScreen->unk2A2 = TRUE; gTasks[taskId].data[0] = 1; gTasks[taskId].func = Task_HandleSelectionScreenChooseMons; } else if (gMain.newAndRepeatedKeys & DPAD_UP) { PlaySE(SE_SELECT); - UpdateYesNoCursorPosition(-1); + Select_UpdateYesNoCursorPosition(-1); } else if (gMain.newAndRepeatedKeys & DPAD_DOWN) { PlaySE(SE_SELECT); - UpdateYesNoCursorPosition(1); + Select_UpdateYesNoCursorPosition(1); } break; } } } -void Task_HandleSelectionScreenMenu(u8 taskId) +static void Task_HandleSelectionScreenMenu(u8 taskId) { switch (gTasks[taskId].data[0]) { case 2: - if (!gUnknown_0300127C->fromSummaryScreen) - sub_819F2B4(&gUnknown_0300127C->unk298.field1, &gUnknown_0300127C->unk2A0, 0); + if (!sFactorySelectScreen->fromSummaryScreen) + sub_819F2B4(&sFactorySelectScreen->unk294[1].field1, &sFactorySelectScreen->unk2A0, 0); gTasks[taskId].data[0] = 9; break; case 9: - if (gUnknown_0300127C->unk2A0 != 1) + if (sFactorySelectScreen->unk2A0 != 1) { - sub_819B844(); - gUnknown_0300127C->fromSummaryScreen = FALSE; + Select_ShowMenuOptions(); + sFactorySelectScreen->fromSummaryScreen = FALSE; gTasks[taskId].data[0] = 3; } break; @@ -666,10 +717,10 @@ void Task_HandleSelectionScreenMenu(u8 taskId) { u8 retVal; PlaySE(SE_SELECT); - retVal = sub_819BC04(); + retVal = Select_RunMenuOptionFunc(); if (retVal == 1) { - gUnknown_0300127C->unk2A2 = 1; + sFactorySelectScreen->unk2A2 = TRUE; gTasks[taskId].data[0] = 1; gTasks[taskId].func = Task_HandleSelectionScreenChooseMons; } @@ -692,45 +743,45 @@ void Task_HandleSelectionScreenMenu(u8 taskId) else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); - sub_819F3F8(gUnknown_0300127C->unk298, &gUnknown_0300127C->unk2A0, 0); + sub_819F3F8(sFactorySelectScreen->unk294[1], &sFactorySelectScreen->unk2A0, 0); sub_819B958(3); - gUnknown_0300127C->unk2A2 = 1; + sFactorySelectScreen->unk2A2 = TRUE; gTasks[taskId].data[0] = 1; gTasks[taskId].func = Task_HandleSelectionScreenChooseMons; } else if (gMain.newAndRepeatedKeys & DPAD_UP) { PlaySE(SE_SELECT); - UpdateMenuCursorPosition(-1); + Select_UpdateMenuCursorPosition(-1); } else if (gMain.newAndRepeatedKeys & DPAD_DOWN) { PlaySE(SE_SELECT); - UpdateMenuCursorPosition(1); + Select_UpdateMenuCursorPosition(1); } break; case 12: if (!gPaletteFade.active) { - if (gUnknown_0300127C->fromSummaryScreen == TRUE) + if (sFactorySelectScreen->fromSummaryScreen == TRUE) { - gPlttBufferFaded[228] = gUnknown_0300127C->unk2A4; + gPlttBufferFaded[228] = sFactorySelectScreen->unk2A4; gPlttBufferUnfaded[228] = gPlttBufferUnfaded[244]; } - gUnknown_0300127C->fromSummaryScreen = FALSE; + sFactorySelectScreen->fromSummaryScreen = FALSE; gTasks[taskId].data[0] = 3; } break; case 13: - sub_819B844(); + Select_ShowMenuOptions(); gTasks[taskId].data[0] = 12; break; } } -void Task_HandleSelectionScreenChooseMons(u8 taskId) +static void Task_HandleSelectionScreenChooseMons(u8 taskId) { - if (gUnknown_0300127C->unk2A0 != 1) + if (sFactorySelectScreen->unk2A0 != 1) { switch (gTasks[taskId].data[0]) { @@ -738,39 +789,39 @@ void Task_HandleSelectionScreenChooseMons(u8 taskId) if (!gPaletteFade.active) { gTasks[taskId].data[0] = 1; - gUnknown_0300127C->unk2A2 = 1; + sFactorySelectScreen->unk2A2 = TRUE; } break; case 1: if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); - gUnknown_0300127C->unk2A2 = 0; + sFactorySelectScreen->unk2A2 = FALSE; gTasks[taskId].data[0] = 2; gTasks[taskId].func = Task_HandleSelectionScreenMenu; } else if (gMain.newAndRepeatedKeys & DPAD_LEFT) { PlaySE(SE_SELECT); - UpdateBallCursorPosition(-1); - PrintMonCategory(); - PrintMonSpecies(); + Select_UpdateBallCursorPosition(-1); + Select_PrintMonCategory(); + Select_PrintMonSpecies(); } else if (gMain.newAndRepeatedKeys & DPAD_RIGHT) { PlaySE(SE_SELECT); - UpdateBallCursorPosition(1); - PrintMonCategory(); - PrintMonSpecies(); + Select_UpdateBallCursorPosition(1); + Select_PrintMonCategory(); + Select_PrintMonSpecies(); } break; case 11: if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); - sub_819F3F8(gUnknown_0300127C->unk298, &gUnknown_0300127C->unk2A0, 0); - PrintSelectMonString(); - gUnknown_0300127C->unk2A2 = 1; + sub_819F3F8(sFactorySelectScreen->unk294[1], &sFactorySelectScreen->unk2A0, 0); + Select_PrintSelectMonString(); + sFactorySelectScreen->unk2A2 = TRUE; gTasks[taskId].data[0] = 1; } break; @@ -778,7 +829,7 @@ void Task_HandleSelectionScreenChooseMons(u8 taskId) } } -void CreateFrontierFactorySelectableMons(u8 firstMonId) +static void CreateFrontierFactorySelectableMons(u8 firstMonId) { u8 i, j = 0; u8 ivs = 0; @@ -802,12 +853,12 @@ void CreateFrontierFactorySelectableMons(u8 firstMonId) for (i = 0; i < SELECTABLE_MONS_COUNT; i++) { u16 monSetId = gSaveBlock2Ptr->frontier.field_E70[i].monId; - gUnknown_0300127C->mons[i + firstMonId].monSetId = monSetId; + sFactorySelectScreen->mons[i + firstMonId].monSetId = monSetId; if (i < var_28) ivs = sub_81A6CA8(var_2C + 1, 0); else ivs = sub_81A6CA8(var_2C, 0); - CreateMonWithEVSpreadPersonalityOTID(&gUnknown_0300127C->mons[i + firstMonId].monData, + CreateMonWithEVSpreadPersonalityOTID(&sFactorySelectScreen->mons[i + firstMonId].monData, gFacilityTrainerMons[monSetId].species, level, gFacilityTrainerMons[monSetId].nature, @@ -816,13 +867,13 @@ void CreateFrontierFactorySelectableMons(u8 firstMonId) otId); happiness = 0; for (j = 0; j < 4; j++) - SetMonMoveAvoidReturn(&gUnknown_0300127C->mons[i + firstMonId].monData, gFacilityTrainerMons[monSetId].moves[j], j); - SetMonData(&gUnknown_0300127C->mons[i + firstMonId].monData, MON_DATA_FRIENDSHIP, &happiness); - SetMonData(&gUnknown_0300127C->mons[i + firstMonId].monData, MON_DATA_HELD_ITEM, &gBattleFrontierHeldItems[gFacilityTrainerMons[monSetId].itemTableId]); + SetMonMoveAvoidReturn(&sFactorySelectScreen->mons[i + firstMonId].monData, gFacilityTrainerMons[monSetId].moves[j], j); + SetMonData(&sFactorySelectScreen->mons[i + firstMonId].monData, MON_DATA_FRIENDSHIP, &happiness); + SetMonData(&sFactorySelectScreen->mons[i + firstMonId].monData, MON_DATA_HELD_ITEM, &gBattleFrontierHeldItems[gFacilityTrainerMons[monSetId].itemTableId]); } } -void CreateTentFactorySelectableMons(u8 firstMonId) +static void CreateTentFactorySelectableMons(u8 firstMonId) { u8 i, j; u8 ivs = 0; @@ -836,8 +887,8 @@ void CreateTentFactorySelectableMons(u8 firstMonId) for (i = 0; i < SELECTABLE_MONS_COUNT; i++) { u16 monSetId = gSaveBlock2Ptr->frontier.field_E70[i].monId; - gUnknown_0300127C->mons[i + firstMonId].monSetId = monSetId; - CreateMonWithEVSpreadPersonalityOTID(&gUnknown_0300127C->mons[i + firstMonId].monData, + sFactorySelectScreen->mons[i + firstMonId].monSetId = monSetId; + CreateMonWithEVSpreadPersonalityOTID(&sFactorySelectScreen->mons[i + firstMonId].monData, gFacilityTrainerMons[monSetId].species, level, gFacilityTrainerMons[monSetId].nature, @@ -846,13 +897,13 @@ void CreateTentFactorySelectableMons(u8 firstMonId) otId); happiness = 0; for (j = 0; j < 4; j++) - SetMonMoveAvoidReturn(&gUnknown_0300127C->mons[i + firstMonId].monData, gFacilityTrainerMons[monSetId].moves[j], j); - SetMonData(&gUnknown_0300127C->mons[i + firstMonId].monData, MON_DATA_FRIENDSHIP, &happiness); - SetMonData(&gUnknown_0300127C->mons[i + firstMonId].monData, MON_DATA_HELD_ITEM, &gBattleFrontierHeldItems[gFacilityTrainerMons[monSetId].itemTableId]); + SetMonMoveAvoidReturn(&sFactorySelectScreen->mons[i + firstMonId].monData, gFacilityTrainerMons[monSetId].moves[j], j); + SetMonData(&sFactorySelectScreen->mons[i + firstMonId].monData, MON_DATA_FRIENDSHIP, &happiness); + SetMonData(&sFactorySelectScreen->mons[i + firstMonId].monData, MON_DATA_HELD_ITEM, &gBattleFrontierHeldItems[gFacilityTrainerMons[monSetId].itemTableId]); } } -void CopySelectedMonsToPlayerParty(void) +static void Select_CopyMonsToPlayerParty(void) { u8 i, j; @@ -860,10 +911,10 @@ void CopySelectedMonsToPlayerParty(void) { for (j = 0; j < SELECTABLE_MONS_COUNT; j++) { - if (gUnknown_0300127C->mons[j].selectedId == i + 1) + if (sFactorySelectScreen->mons[j].selectedId == i + 1) { - gPlayerParty[i] = gUnknown_0300127C->mons[j].monData; - gSaveBlock2Ptr->frontier.field_E70[i].monId = gUnknown_0300127C->mons[j].monSetId; + gPlayerParty[i] = sFactorySelectScreen->mons[j].monData; + gSaveBlock2Ptr->frontier.field_E70[i].monId = sFactorySelectScreen->mons[j].monSetId; gSaveBlock2Ptr->frontier.field_E70[i].personality = GetMonData(&gPlayerParty[i].box, MON_DATA_PERSONALITY, NULL); gSaveBlock2Ptr->frontier.field_E70[i].abilityBit = GetBoxMonData(&gPlayerParty[i].box, MON_DATA_ALT_ABILITY, NULL); gSaveBlock2Ptr->frontier.field_E70[i].ivs = GetBoxMonData(&gPlayerParty[i].box, MON_DATA_ATK_IV, NULL); @@ -874,80 +925,77 @@ void CopySelectedMonsToPlayerParty(void) CalculatePlayerPartyCount(); } -void sub_819B844(void) +static void Select_ShowMenuOptions(void) { - if (!gUnknown_0300127C->fromSummaryScreen) - gUnknown_0300127C->menuCursorPos = 0; + if (!sFactorySelectScreen->fromSummaryScreen) + sFactorySelectScreen->menuCursorPos = 0; - gSprites[gUnknown_0300127C->menuCursor1SpriteId].pos1.x = 176; - gSprites[gUnknown_0300127C->menuCursor1SpriteId].pos1.y = (gUnknown_0300127C->menuCursorPos * 16) + 112; - gSprites[gUnknown_0300127C->menuCursor2SpriteId].pos1.x = 208; - gSprites[gUnknown_0300127C->menuCursor2SpriteId].pos1.y = (gUnknown_0300127C->menuCursorPos * 16) + 112; + gSprites[sFactorySelectScreen->menuCursor1SpriteId].pos1.x = 176; + gSprites[sFactorySelectScreen->menuCursor1SpriteId].pos1.y = (sFactorySelectScreen->menuCursorPos * 16) + 112; + gSprites[sFactorySelectScreen->menuCursor2SpriteId].pos1.x = 208; + gSprites[sFactorySelectScreen->menuCursor2SpriteId].pos1.y = (sFactorySelectScreen->menuCursorPos * 16) + 112; - gSprites[gUnknown_0300127C->menuCursor1SpriteId].invisible = 0; - gSprites[gUnknown_0300127C->menuCursor2SpriteId].invisible = 0; + gSprites[sFactorySelectScreen->menuCursor1SpriteId].invisible = 0; + gSprites[sFactorySelectScreen->menuCursor2SpriteId].invisible = 0; - PrintSelectableMenuOptions(); + Select_PrintMenuOptions(); } -void sub_819B8D4(void) +static void Select_ShowYesNoOptions(void) { - gUnknown_0300127C->yesNoCursorPos = 0; + sFactorySelectScreen->yesNoCursorPos = 0; - gSprites[gUnknown_0300127C->menuCursor1SpriteId].pos1.x = 176; - gSprites[gUnknown_0300127C->menuCursor1SpriteId].pos1.y = 112; - gSprites[gUnknown_0300127C->menuCursor2SpriteId].pos1.x = 208; - gSprites[gUnknown_0300127C->menuCursor2SpriteId].pos1.y = 112; + gSprites[sFactorySelectScreen->menuCursor1SpriteId].pos1.x = 176; + gSprites[sFactorySelectScreen->menuCursor1SpriteId].pos1.y = 112; + gSprites[sFactorySelectScreen->menuCursor2SpriteId].pos1.x = 208; + gSprites[sFactorySelectScreen->menuCursor2SpriteId].pos1.y = 112; - gSprites[gUnknown_0300127C->menuCursor1SpriteId].invisible = 0; - gSprites[gUnknown_0300127C->menuCursor2SpriteId].invisible = 0; + gSprites[sFactorySelectScreen->menuCursor1SpriteId].invisible = 0; + gSprites[sFactorySelectScreen->menuCursor2SpriteId].invisible = 0; - PrintSelectableYesNo(); + Select_PrintYesNoOptions(); } -void sub_819B958(u8 windowId) +static void sub_819B958(u8 windowId) { - gSprites[gUnknown_0300127C->menuCursor1SpriteId].invisible = 1; - gSprites[gUnknown_0300127C->menuCursor2SpriteId].invisible = 1; + gSprites[sFactorySelectScreen->menuCursor1SpriteId].invisible = 1; + gSprites[sFactorySelectScreen->menuCursor2SpriteId].invisible = 1; FillWindowPixelBuffer(windowId, 0); CopyWindowToVram(windowId, 2); ClearWindowTilemap(windowId); } -void PrintRentalPkmnString(void) +static void Select_PrintRentalPkmnString(void) { FillWindowPixelBuffer(0, 0); PrintTextOnWindow(0, 1, gText_RentalPkmn2, 2, 1, 0, NULL); CopyWindowToVram(0, 3); } -extern const u8 gUnknown_08610479[]; -extern const u8 gUnknown_08610476[]; - -void PrintMonSpecies(void) +static void Select_PrintMonSpecies(void) { u16 species; u8 x; - u8 monId = gUnknown_0300127C->cursorPos; + u8 monId = sFactorySelectScreen->cursorPos; FillWindowPixelBuffer(1, 0); - species = GetMonData(&gUnknown_0300127C->mons[monId].monData, MON_DATA_SPECIES, NULL); + species = GetMonData(&sFactorySelectScreen->mons[monId].monData, MON_DATA_SPECIES, NULL); StringCopy(gStringVar4, gSpeciesNames[species]); x = GetStringRightAlignXOffset(1, gStringVar4, 86); AddTextPrinterParameterized3(1, 1, x, 1, gUnknown_08610479, 0, gStringVar4); CopyWindowToVram(1, 2); } -void PrintSelectMonString(void) +static void Select_PrintSelectMonString(void) { const u8 *str = NULL; FillWindowPixelBuffer(2, 0); - if (gUnknown_0300127C->selectingMonsState == 1) + if (sFactorySelectScreen->selectingMonsState == 1) str = gText_SelectFirstPkmn; - else if (gUnknown_0300127C->selectingMonsState == 2) + else if (sFactorySelectScreen->selectingMonsState == 2) str = gText_SelectSecondPkmn; - else if (gUnknown_0300127C->selectingMonsState == 3) + else if (sFactorySelectScreen->selectingMonsState == 3) str = gText_SelectThirdPkmn; else str = gText_TheseThreePkmnOkay; @@ -956,16 +1004,16 @@ void PrintSelectMonString(void) CopyWindowToVram(2, 2); } -void PrintCantSelectSameMon(void) +static void Select_PrintCantSelectSameMon(void) { FillWindowPixelBuffer(2, 0); PrintTextOnWindow(2, 1, gText_CantSelectSamePkmn, 2, 5, 0, NULL); CopyWindowToVram(2, 2); } -void PrintSelectableMenuOptions(void) +static void Select_PrintMenuOptions(void) { - u8 selectedId = gUnknown_0300127C->mons[gUnknown_0300127C->cursorPos].selectedId; + u8 selectedId = sFactorySelectScreen->mons[sFactorySelectScreen->cursorPos].selectedId; PutWindowTilemap(3); FillWindowPixelBuffer(3, 0); @@ -979,7 +1027,7 @@ void PrintSelectableMenuOptions(void) CopyWindowToVram(3, 3); } -void PrintSelectableYesNo(void) +static void Select_PrintYesNoOptions(void) { PutWindowTilemap(4); FillWindowPixelBuffer(4, 0); @@ -988,72 +1036,70 @@ void PrintSelectableYesNo(void) CopyWindowToVram(4, 3); } -extern u8 (* const gUnknown_0861041C[])(void); - -u8 sub_819BC04(void) +static u8 Select_RunMenuOptionFunc(void) { - gUnknown_030062E8 = gUnknown_0861041C[gUnknown_0300127C->menuCursorPos]; + gUnknown_030062E8 = sSelect_MenuOptionFuncs[sFactorySelectScreen->menuCursorPos]; return gUnknown_030062E8(); } -u8 sub_819BC30(void) +static u8 Select_OptionRentDeselect(void) { - u8 selectedId = gUnknown_0300127C->mons[gUnknown_0300127C->cursorPos].selectedId; - u16 monSetId = gUnknown_0300127C->mons[gUnknown_0300127C->cursorPos].monSetId; - if (selectedId == 0 && !sub_819C634(monSetId)) + u8 selectedId = sFactorySelectScreen->mons[sFactorySelectScreen->cursorPos].selectedId; + u16 monSetId = sFactorySelectScreen->mons[sFactorySelectScreen->cursorPos].monSetId; + if (selectedId == 0 && !Select_AreSpeciesValid(monSetId)) { - PrintCantSelectSameMon(); + Select_PrintCantSelectSameMon(); sub_819B958(3); return 3; } else { - sub_819F3F8(gUnknown_0300127C->unk298, &gUnknown_0300127C->unk2A0, 0); - HandleMonSelectionChange(); - PrintSelectMonString(); + sub_819F3F8(sFactorySelectScreen->unk294[1], &sFactorySelectScreen->unk2A0, 0); + Select_HandleMonSelectionChange(); + Select_PrintSelectMonString(); sub_819B958(3); - if (gUnknown_0300127C->selectingMonsState > 3) + if (sFactorySelectScreen->selectingMonsState > 3) return 2; else return 1; } } -u8 sub_819BC9C(void) +static u8 sub_819BC9C(void) { sub_819C568(); - HandleMonSelectionChange(); - PrintSelectMonString(); + Select_HandleMonSelectionChange(); + Select_PrintSelectMonString(); sub_819B958(3); - if (gUnknown_0300127C->selectingMonsState > 3) + if (sFactorySelectScreen->selectingMonsState > 3) return 2; else return 1; } -u8 sub_819BCCC(void) +static u8 Select_OptionSummary(void) { return 0; } -u8 sub_819BCD0(void) +static u8 Select_OptionOthers(void) { - sub_819F3F8(gUnknown_0300127C->unk298, &gUnknown_0300127C->unk2A0, 0); + sub_819F3F8(sFactorySelectScreen->unk294[1], &sFactorySelectScreen->unk2A0, 0); sub_819B958(3); return 1; } -void PrintMonCategory(void) +static void Select_PrintMonCategory(void) { u16 species; u8 text[30]; u8 x; - u8 monId = gUnknown_0300127C->cursorPos; + u8 monId = sFactorySelectScreen->cursorPos; if (monId < SELECTABLE_MONS_COUNT) { PutWindowTilemap(5); FillWindowPixelBuffer(5, 0); - species = GetMonData(&gUnknown_0300127C->mons[monId].monData, MON_DATA_SPECIES, NULL); + species = GetMonData(&sFactorySelectScreen->mons[monId].monData, MON_DATA_SPECIES, NULL); CopyMonCategoryText(SpeciesToNationalPokedexNum(species), text); x = GetStringRightAlignXOffset(1, text, 0x76); PrintTextOnWindow(5, 1, text, x, 1, 0, NULL); @@ -1063,43 +1109,305 @@ void PrintMonCategory(void) void sub_819BD70(void) { - u8 monId = gUnknown_0300127C->cursorPos; - struct Pokemon *mon = &gUnknown_0300127C->mons[monId].monData; + u8 monId = sFactorySelectScreen->cursorPos; + struct Pokemon *mon = &sFactorySelectScreen->mons[monId].monData; u16 species = GetMonData(mon, MON_DATA_SPECIES, NULL); u32 personality = GetMonData(mon, MON_DATA_PERSONALITY, NULL); u32 otId = GetMonData(mon, MON_DATA_OT_ID, NULL); - gUnknown_0300127C->unk298.field0 = CreateMonPicSprite_HandleDeoxys(species, otId, personality, TRUE, 88, 32, 15, 0xFFFF); - gSprites[gUnknown_0300127C->unk298.field0].centerToCornerVecX = 0; - gSprites[gUnknown_0300127C->unk298.field0].centerToCornerVecY = 0; + 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; - gUnknown_0300127C->unk2A0 = 0; + sFactorySelectScreen->unk2A0 = 0; } -extern const struct SpriteTemplate gUnknown_08610638; - void sub_819BE20(u8 arg0) { - gUnknown_0300127C->unk2A0 = arg0; + sFactorySelectScreen->unk2A0 = arg0; } -void sub_819BE34(void) +static void Select_ShowCheckedMonSprite(void) { struct Pokemon *mon; u16 species; u32 personality, otId; - gUnknown_0300127C->unk298.field1 = CreateSprite(&gUnknown_08610638, 120, 64, 1); - StartSpriteAffineAnim(&gSprites[gUnknown_0300127C->unk298.field1], 2); + sFactorySelectScreen->unk294[1].field1 = CreateSprite(&gUnknown_08610638, 120, 64, 1); + StartSpriteAffineAnim(&gSprites[sFactorySelectScreen->unk294[1].field1], 2); - mon = &gUnknown_0300127C->mons[gUnknown_0300127C->cursorPos].monData; + 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); - gUnknown_0300127C->unk298.field0 = CreateMonPicSprite_HandleDeoxys(species, otId, personality, TRUE, 88, 32, 15, 0xFFFF); - gSprites[gUnknown_0300127C->unk298.field0].centerToCornerVecX = 0; - gSprites[gUnknown_0300127C->unk298.field0].centerToCornerVecY = 0; + 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; + + gSprites[sFactorySelectScreen->unk294[1].field1].invisible = 1; +} + +static void Select_ShowChosenMonsSprites(void) +{ + u8 i, j; + + for (i = 0; i < 3; i++) + { + for (j = 0; j < SELECTABLE_MONS_COUNT; j++) + { + if (sFactorySelectScreen->mons[j].selectedId == i + 1) + { + struct Pokemon *mon = &sFactorySelectScreen->mons[j].monData; + u16 species = GetMonData(mon, MON_DATA_SPECIES, NULL); + 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; + break; + } + } + } + sFactorySelectScreen->unk2A0 = 0; +} + +static void sub_819C040(struct Sprite *sprite) +{ + u8 taskId; + + if (sprite->affineAnimEnded + && gSprites[sFactorySelectScreen->unk294[0].field1].affineAnimEnded + && gSprites[sFactorySelectScreen->unk294[2].field1].affineAnimEnded) + { + sprite->invisible = 1; + gSprites[sFactorySelectScreen->unk294[0].field1].invisible = 1; + gSprites[sFactorySelectScreen->unk294[2].field1].invisible = 1; + + taskId = CreateTask(sub_819C1D0, 1); + gTasks[taskId].func(taskId); + + sprite->callback = SpriteCallbackDummy; + } +} + +static void sub_819C100(struct Sprite *sprite) +{ + if (sprite->affineAnimEnded + && gSprites[sFactorySelectScreen->unk294[0].field1].affineAnimEnded + && gSprites[sFactorySelectScreen->unk294[2].field1].affineAnimEnded) + { + FreeOamMatrix(sprite->oam.matrixNum); + FreeOamMatrix(gSprites[sFactorySelectScreen->unk294[0].field1].oam.matrixNum); + FreeOamMatrix(gSprites[sFactorySelectScreen->unk294[2].field1].oam.matrixNum); + + sFactorySelectScreen->unk2A0 = 0; + + DestroySprite(&gSprites[sFactorySelectScreen->unk294[0].field1]); + DestroySprite(&gSprites[sFactorySelectScreen->unk294[2].field1]); + DestroySprite(sprite); + } +} + +static void sub_819C1D0(u8 taskId) +{ + struct Task *task = &gTasks[taskId]; + switch (task->data[0]) + { + 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; + SetGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON); + SetGpuReg(REG_OFFSET_WIN0H, WINHV_COORDS(task->data[3], task->data[24])); + SetGpuReg(REG_OFFSET_WIN0V, WINHV_COORDS(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); + break; + case 1: + 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: + task->data[5] -= 4; + task->data[8] += 4; + if (task->data[5] <= 32 || task->data[8] >= 96) + { + task->data[5] = 32; + task->data[8] = 96; + ClearGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON); + } + SetGpuReg(REG_OFFSET_WIN0V, WINHV_COORDS(task->data[5], task->data[8])); + if (task->data[5] != 32) + return; + break; + default: + DestroyTask(taskId); + Select_ShowChosenMonsSprites(); + return; + } + task->data[0]++; +} + +static void sub_819C2D4(u8 taskId) +{ + struct Task *task = &gTasks[taskId]; + switch (task->data[0]) + { + default: + HideBg(3); + gSprites[sFactorySelectScreen->unk294[1].field1].invisible = 0; + gSprites[sFactorySelectScreen->unk294[1].field1].callback = sub_819C100; + gSprites[sFactorySelectScreen->unk294[0].field1].invisible = 0; + gSprites[sFactorySelectScreen->unk294[0].field1].callback = SpriteCallbackDummy; + gSprites[sFactorySelectScreen->unk294[2].field1].invisible = 0; + 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); + 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; + SetGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON); + SetGpuReg(REG_OFFSET_WIN0H, WINHV_COORDS(task->data[3], task->data[24])); + SetGpuReg(REG_OFFSET_WIN0V, WINHV_COORDS(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); + task->data[0]++; + break; + case 1: + task->data[5] += 4; + task->data[8] -= 4; + if (task->data[5] >= 64 || task->data[8] <= 65) + { + task->data[5] = 64; + task->data[8] = 65; + } + SetGpuReg(REG_OFFSET_WIN0V, WINHV_COORDS(task->data[5], task->data[8])); + if (task->data[5] == 64) + task->data[0]++; + break; + } +} + +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); + + gSprites[sFactorySelectScreen->unk294[1].field1].callback = sub_819C040; + gSprites[sFactorySelectScreen->unk294[0].field1].callback = SpriteCallbackDummy; + gSprites[sFactorySelectScreen->unk294[2].field1].callback = SpriteCallbackDummy; + + sFactorySelectScreen->unk2A0 = 1; +} + +static void sub_819C568(void) +{ + u8 taskId; + + FreeAndDestroyMonPicSprite(sFactorySelectScreen->unk294[0].field0); + FreeAndDestroyMonPicSprite(sFactorySelectScreen->unk294[1].field0); + FreeAndDestroyMonPicSprite(sFactorySelectScreen->unk294[2].field0); + + taskId = CreateTask(sub_819C2D4, 1); + gTasks[taskId].func(taskId); + + sFactorySelectScreen->unk2A0 = 1; +} + +static void Select_SetWinRegs(s16 mWin0H, s16 nWin0H, s16 mWin0V, s16 nWin0V) +{ + SetGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON); + SetGpuReg(REG_OFFSET_WIN0H, WINHV_COORDS(mWin0H, nWin0H)); + SetGpuReg(REG_OFFSET_WIN0V, WINHV_COORDS(mWin0V, nWin0V)); + 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); +} + +static bool32 Select_AreSpeciesValid(u16 monSetId) +{ + u8 i, j; + u32 species = gFacilityTrainerMons[monSetId].species; + u8 selectState = sFactorySelectScreen->selectingMonsState; + + for (i = 1; i < selectState; i++) + { + for (j = 0; j < SELECTABLE_MONS_COUNT; j++) + { + if (sFactorySelectScreen->mons[j].selectedId == i) + { + if (gFacilityTrainerMons[sFactorySelectScreen->mons[j].monSetId].species == species) + return FALSE; - gSprites[gUnknown_0300127C->unk298.field1].invisible = 1; + break; + } + } + } + + return TRUE; +} + +static void Task_SelectBlendPalette(u8 taskId) +{ + switch (gTasks[taskId].data[0]) + { + case 0: + sFactorySelectScreen->unk2A7 = 0; + sFactorySelectScreen->unk2A8 = 0; + sFactorySelectScreen->unk2A6 = TRUE; + gTasks[taskId].data[0] = 1; + break; + case 1: + if (sFactorySelectScreen->unk2A2) + { + if (sFactorySelectScreen->unk2A9) + { + gTasks[taskId].data[0] = 2; + } + else + { + sFactorySelectScreen->unk2A7++; + if (sFactorySelectScreen->unk2A7 > 6) + { + sFactorySelectScreen->unk2A7 = 0; + if (!sFactorySelectScreen->unk2A6) + sFactorySelectScreen->unk2A8--; + else + sFactorySelectScreen->unk2A8++; + } + BlendPalettes(0x4000, sFactorySelectScreen->unk2A8, 0); + if (sFactorySelectScreen->unk2A8 > 5) + { + sFactorySelectScreen->unk2A6 = FALSE; + } + else if (sFactorySelectScreen->unk2A8 == 0) + { + gTasks[taskId].data[0] = 2; + sFactorySelectScreen->unk2A6 = TRUE; + } + } + } + break; + case 2: + if (sFactorySelectScreen->unk2A9 > 14) + { + sFactorySelectScreen->unk2A9 = 0; + gTasks[taskId].data[0] = 1; + } + else + { + sFactorySelectScreen->unk2A9++; + } + break; + } } |