From c70ec9748ac92e4b9ecc2f110ae5702a46097f90 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 17 Oct 2021 15:11:36 -0400 Subject: [PATCH 01/10] Some union_room_chat clean up --- src/union_room_chat.c | 149 +++++++++++++++++++++++------------------- 1 file changed, 83 insertions(+), 66 deletions(-) diff --git a/src/union_room_chat.c b/src/union_room_chat.c index adf496fe6..7debe3cd4 100755 --- a/src/union_room_chat.c +++ b/src/union_room_chat.c @@ -105,6 +105,17 @@ enum { CHAT_EXIT_DISBANDED, }; +enum { + GFXTAG_KEYBOARD_CURSOR, + GFXTAG_TEXT_ENTRY_ARROW, + GFXTAG_TEXT_ENTRY_CURSOR, + GFXTAG_RBUTTON_ICON, + GFXTAG_RBUTTON_LABELS, +}; + +// Shared by all above +#define PALTAG_INTERFACE 0 + struct UnionRoomChat { u32 filler1; @@ -123,7 +134,7 @@ struct UnionRoomChat u8 lastBufferCursorPos; u8 bufferCursorPos; u8 receivedPlayerIndex; - u8 exitType; + u8 exitType; // CHAT_EXIT_* bool8 changedRegisteredTexts; u8 afterSaveTimer; u8 messageEntryBuffer[2 * MAX_MESSAGE_LENGTH + 1]; @@ -249,9 +260,9 @@ static void CreateRButtonSprites(void); static void ShowKeyboardSwapMenu(void); static void HideKeyboardSwapMenu(void); static void SetKeyboardCursorInvisibility(bool32); -static bool32 sub_8020320(void); +static bool32 SlideKeyboardPageOut(void); static void PrintCurrentKeyboardPage(void); -static bool32 sub_8020368(void); +static bool32 SlideKeyboardPageIn(void); static void MoveKeyboardCursor(void); static void UpdateRButtonLabel(void); static void AddStdMessageWindow(int, u16); @@ -266,8 +277,8 @@ static void SetRegisteredTextPalette(bool32); static void PrintChatMessage(u16, u8 *, u8); static void StartKeyboardCursorAnim(void); static bool32 TryKeyboardCursorReopen(void); -static void sub_80207C0(s16); -static void sub_8020818(s16); +static void UpdateSlidingKeyboard(s16); +static void FinishSlidingKeyboard(s16); static bool32 Display_Dummy(u8 *); static bool32 Display_LoadGfx(u8 *state); static bool32 Display_ShowKeyboardSwapMenu(u8 *state); @@ -550,36 +561,36 @@ static const struct BgTemplate sBgTemplates[] = { static const struct WindowTemplate sWinTemplates[] = { { - .bg = 0x03, - .tilemapLeft = 0x08, - .tilemapTop = 0x01, - .width = 0x15, - .height = 0x13, - .paletteNum = 0x0f, + .bg = 3, + .tilemapLeft = 8, + .tilemapTop = 1, + .width = 21, + .height = 19, + .paletteNum = 15, .baseBlock = 0x0001, }, { - .bg = 0x01, - .tilemapLeft = 0x09, - .tilemapTop = 0x12, - .width = 0x0f, - .height = 0x02, - .paletteNum = 0x0c, + .bg = 1, + .tilemapLeft = 9, + .tilemapTop = 18, + .width = 15, + .height = 2, + .paletteNum = 12, .baseBlock = 0x007a, }, { - .bg = 0x01, - .tilemapLeft = 0x00, - .tilemapTop = 0x02, - .width = 0x06, - .height = 0x0f, - .paletteNum = 0x07, + .bg = 1, + .tilemapLeft = 0, + .tilemapTop = 2, + .width = 6, + .height = 15, + .paletteNum = 7, .baseBlock = 0x0020, }, { - .bg = 0x00, - .tilemapLeft = 0x01, - .tilemapTop = 0x02, - .width = 0x07, - .height = 0x09, - .paletteNum = 0x0e, + .bg = 0, + .tilemapLeft = 1, + .tilemapTop = 2, + .width = 7, + .height = 9, + .paletteNum = 14, .baseBlock = 0x0013, }, DUMMY_WIN_TEMPLATE }; @@ -783,8 +794,8 @@ static const union AnimCmd *const sAnims_KeyboardCursor[] = { }; static const struct SpriteTemplate sSpriteTemplate_KeyboardCursor = { - .tileTag = 0x0000, - .paletteTag = 0x0000, + .tileTag = GFXTAG_KEYBOARD_CURSOR, + .paletteTag = PALTAG_INTERFACE, .oam = &sOam_KeyboardCursor, .anims = sAnims_KeyboardCursor, .images = NULL, @@ -799,8 +810,8 @@ static const struct OamData sOam_TextEntrySprite = { }; static const struct SpriteTemplate sSpriteTemplate_TextEntryCursor = { - .tileTag = 0x0002, - .paletteTag = 0x0000, + .tileTag = GFXTAG_TEXT_ENTRY_CURSOR, + .paletteTag = PALTAG_INTERFACE, .oam = &sOam_TextEntrySprite, .anims = gDummySpriteAnimTable, .images = NULL, @@ -809,8 +820,8 @@ static const struct SpriteTemplate sSpriteTemplate_TextEntryCursor = { }; static const struct SpriteTemplate sSpriteTemplate_TextEntryArrow = { - .tileTag = 0x0001, - .paletteTag = 0x0000, + .tileTag = GFXTAG_TEXT_ENTRY_ARROW, + .paletteTag = PALTAG_INTERFACE, .oam = &sOam_TextEntrySprite, .anims = gDummySpriteAnimTable, .images = NULL, @@ -858,8 +869,8 @@ static const union AnimCmd *const sAnims_RButtonLabels[] = { }; static const struct SpriteTemplate sSpriteTemplate_RButtonIcon = { - .tileTag = 0x0003, - .paletteTag = 0x0000, + .tileTag = GFXTAG_RBUTTON_ICON, + .paletteTag = PALTAG_INTERFACE, .oam = &sOam_RButtonIcon, .anims = gDummySpriteAnimTable, .images = NULL, @@ -868,8 +879,8 @@ static const struct SpriteTemplate sSpriteTemplate_RButtonIcon = { }; static const struct SpriteTemplate sSpriteTemplate_RButtonLabels = { - .tileTag = 0x0004, - .paletteTag = 0x0000, + .tileTag = GFXTAG_RBUTTON_LABELS, + .paletteTag = PALTAG_INTERFACE, .oam = &sOam_RButtonLabel, .anims = sAnims_RButtonLabels, .images = NULL, @@ -879,7 +890,7 @@ static const struct SpriteTemplate sSpriteTemplate_RButtonLabels = { void EnterUnionRoomChat(void) { - sChat = Alloc(sizeof(struct UnionRoomChat)); + sChat = Alloc(sizeof(*sChat)); InitUnionRoomChat(sChat); gKeyRepeatStartDelay = 20; SetVBlankCallback(NULL); @@ -890,7 +901,7 @@ static void InitUnionRoomChat(struct UnionRoomChat *chat) { int i; - chat->funcId = 0; + chat->funcId = CHAT_FUNC_JOIN; chat->funcState = 0; chat->currentPage = 0; chat->currentCol = 0; @@ -901,7 +912,7 @@ static void InitUnionRoomChat(struct UnionRoomChat *chat) chat->messageEntryBuffer[0] = EOS; chat->linkPlayerCount = GetLinkPlayerCount(); chat->multiplayerId = GetMultiplayerId(); - chat->exitType = 0; + chat->exitType = CHAT_EXIT_NONE; chat->changedRegisteredTexts = FALSE; PrepareSendBuffer_Null(chat->sendMessageBuffer); for (i = 0; i < UNION_ROOM_KB_ROW_COUNT; i++) @@ -969,6 +980,8 @@ static void CB2_UnionRoomChatMain(void) static void Task_HandlePlayerInput(u8 taskId) { + // If exitType is not CHAT_EXIT_NONE, begin exit function. + // Otherwise just call main function below. switch (sChat->exitType) { case CHAT_EXIT_ONLY_LEADER: @@ -1056,7 +1069,7 @@ static void Chat_HandleInput(void) } else { - SetChatFunction(5); + SetChatFunction(CHAT_FUNC_REGISTER); } } else if (HandleDPadInput()) @@ -2080,7 +2093,7 @@ static void Task_ReceiveChatMessage(u8 taskId) if (GetLinkPlayerCount() == 2) { Rfu_StopPartnerSearch(); - sChat->exitType = 1; + sChat->exitType = CHAT_EXIT_ONLY_LEADER; DestroyTask(taskId); return; } @@ -2091,12 +2104,12 @@ static void Task_ReceiveChatMessage(u8 taskId) break; case 5: if (sChat->multiplayerId) - sChat->exitType = 2; + sChat->exitType = CHAT_EXIT_DROPPED; DestroyTask(taskId); break; case 6: - sChat->exitType = 3; + sChat->exitType = CHAT_EXIT_DISBANDED; DestroyTask(taskId); break; case 2: @@ -2295,7 +2308,7 @@ static bool32 Display_SwitchPages(u8 *state) { case 0: SetKeyboardCursorInvisibility(TRUE); - if (sub_8020320()) + if (SlideKeyboardPageOut()) return TRUE; PrintCurrentKeyboardPage(); @@ -2306,7 +2319,7 @@ static bool32 Display_SwitchPages(u8 *state) return TRUE; break; case 2: - if (sub_8020368()) + if (SlideKeyboardPageIn()) return TRUE; MoveKeyboardCursor(); @@ -2928,26 +2941,29 @@ static void PrintCurrentKeyboardPage(void) } } -static bool32 sub_8020320(void) +#define KEYBOARD_HOFS_END 56 + +static bool32 SlideKeyboardPageOut(void) { - if (sDisplay->bg1hofs < 56) + if (sDisplay->bg1hofs < KEYBOARD_HOFS_END) { sDisplay->bg1hofs += 12; - if (sDisplay->bg1hofs >= 56) - sDisplay->bg1hofs = 56; + if (sDisplay->bg1hofs >= KEYBOARD_HOFS_END) + sDisplay->bg1hofs = KEYBOARD_HOFS_END; - if (sDisplay->bg1hofs < 56) + if (sDisplay->bg1hofs < KEYBOARD_HOFS_END) { - sub_80207C0(sDisplay->bg1hofs); + // Still sliding + UpdateSlidingKeyboard(sDisplay->bg1hofs); return TRUE; } } - sub_8020818(sDisplay->bg1hofs); + FinishSlidingKeyboard(sDisplay->bg1hofs); return FALSE; } -static bool32 sub_8020368(void) +static bool32 SlideKeyboardPageIn(void) { if (sDisplay->bg1hofs > 0) { @@ -2957,12 +2973,13 @@ static bool32 sub_8020368(void) if (sDisplay->bg1hofs > 0) { - sub_80207C0(sDisplay->bg1hofs); + // Still sliding + UpdateSlidingKeyboard(sDisplay->bg1hofs); return TRUE; } } - sub_8020818(sDisplay->bg1hofs); + FinishSlidingKeyboard(sDisplay->bg1hofs); return FALSE; } @@ -3049,8 +3066,8 @@ static void LoadChatWindowGfx(void) ptr = DecompressAndCopyTileDataToVram(2, gUnionRoomChat_Background_Gfx, 0, 0, 0); if (ptr) { - CpuFastCopy(&ptr[0x220], sDisplay->unk2128, 0x20); - CpuFastCopy(&ptr[0x420], sDisplay->unk2148, 0x20); + CpuFastCopy(&ptr[0x220], sDisplay->unk2128, sizeof(sDisplay->unk2128)); + CpuFastCopy(&ptr[0x420], sDisplay->unk2148, sizeof(sDisplay->unk2148)); } CopyToBgTilemapBuffer(2, gUnionRoomChat_Background_Tilemap, 0, 0); @@ -3059,13 +3076,13 @@ static void LoadChatWindowGfx(void) static void sub_8020680(void) { - LoadPalette(sUnk_Palette1, 0x80, 0x20); + LoadPalette(sUnk_Palette1, 0x80, sizeof(sUnk_Palette1)); RequestDma3Fill(0, (void *)BG_CHAR_ADDR(1) + 0x20, 0x20, 1); } static void LoadChatMessagesWindow(void) { - LoadPalette(sUnk_Palette2, 0xF0, 0x20); + LoadPalette(sUnk_Palette2, 0xF0, sizeof(sUnk_Palette2)); PutWindowTilemap(0); FillWindowPixelBuffer(0, PIXEL_FILL(1)); CopyWindowToVram(0, 3); @@ -3113,13 +3130,13 @@ static void InitScanlineEffect(void) ScanlineEffect_SetParams(params); } -static void sub_80207C0(s16 bg1hofs) +static void UpdateSlidingKeyboard(s16 bg1hofs) { CpuFill16(bg1hofs, gScanlineEffectRegBuffers[gScanlineEffect.srcBuffer], 0x120); CpuFill16(0, gScanlineEffectRegBuffers[gScanlineEffect.srcBuffer] + 0x90, 0x20); } -static void sub_8020818(s16 bg1hofs) +static void FinishSlidingKeyboard(s16 bg1hofs) { CpuFill16(bg1hofs, gScanlineEffectRegBuffers[0], 0x120); CpuFill16(0, gScanlineEffectRegBuffers[0] + 0x90, 0x20); @@ -3134,7 +3151,7 @@ static bool32 TryAllocSprites(void) LoadCompressedSpriteSheet(&sSpriteSheets[i]); LoadSpritePalette(&sSpritePalette); - sSprites = Alloc(sizeof(struct UnionRoomChatSprites)); + sSprites = Alloc(sizeof(*sSprites)); if (!sSprites) return FALSE; @@ -3180,7 +3197,7 @@ static void MoveKeyboardCursor(void) static void SetRegisteredTextPalette(bool32 registering) { const u16 *palette = &sUnionRoomChatInterfacePal[registering * 2 + 1]; - u8 index = IndexOfSpritePaletteTag(0); + u8 index = IndexOfSpritePaletteTag(PALTAG_INTERFACE); LoadPalette(palette, index * 16 + 0x101, 4); } From 371a13e9f9a44ba3959789361f3fc4a825fee9ab Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 17 Oct 2021 17:38:52 -0400 Subject: [PATCH 02/10] Clean up in save_location --- src/save_location.c | 54 +++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/src/save_location.c b/src/save_location.c index aa56d7b16..b201ca1c0 100644 --- a/src/save_location.c +++ b/src/save_location.c @@ -2,14 +2,16 @@ #include "save_location.h" #include "constants/maps.h" +#define LIST_END 0xFFFF + static bool32 IsCurMapInLocationList(const u16 *list) { s32 i; - u16 locSum = (gSaveBlock1Ptr->location.mapGroup << 8) + (gSaveBlock1Ptr->location.mapNum); + u16 map = (gSaveBlock1Ptr->location.mapGroup << 8) + gSaveBlock1Ptr->location.mapNum; - for (i = 0; list[i] != 0xFFFF; i++) + for (i = 0; list[i] != LIST_END; i++) { - if (list[i] == locSum) + if (list[i] == map) return TRUE; } @@ -56,7 +58,7 @@ static const u16 sSaveLocationPokeCenterList[] = MAP_TRADE_CENTER, MAP_RECORD_CORNER, MAP_BATTLE_COLOSSEUM_4P, - 0xFFFF, + LIST_END, }; static bool32 IsCurMapPokeCenter(void) @@ -67,7 +69,7 @@ static bool32 IsCurMapPokeCenter(void) static const u16 sSaveLocationReloadLocList[] = // There's only 1 location, and it's presumed its for the save reload feature for battle tower. { MAP_BATTLE_FRONTIER_BATTLE_TOWER_LOBBY, - 0xFFFF, + LIST_END, }; static bool32 IsCurMapReloadLocation(void) @@ -76,20 +78,20 @@ static bool32 IsCurMapReloadLocation(void) } // Nulled out list. Unknown what this would have been. -static const u16 sUnknown_0861440E[] = +static const u16 sEmptyMapList[] = { - 0xFFFF, + LIST_END, }; -static bool32 sub_81AFCEC(void) +static bool32 IsCurMapInEmptyList(void) { - return IsCurMapInLocationList(sUnknown_0861440E); + return IsCurMapInLocationList(sEmptyMapList); } static void TrySetPokeCenterWarpStatus(void) { - if (IsCurMapPokeCenter() == FALSE) - gSaveBlock2Ptr->specialSaveWarpFlags &= ~(POKECENTER_SAVEWARP); + if (!IsCurMapPokeCenter()) + gSaveBlock2Ptr->specialSaveWarpFlags &= ~POKECENTER_SAVEWARP; else gSaveBlock2Ptr->specialSaveWarpFlags |= POKECENTER_SAVEWARP; } @@ -97,16 +99,16 @@ static void TrySetPokeCenterWarpStatus(void) static void TrySetReloadWarpStatus(void) { if (!IsCurMapReloadLocation()) - gSaveBlock2Ptr->specialSaveWarpFlags &= ~(LOBBY_SAVEWARP); + gSaveBlock2Ptr->specialSaveWarpFlags &= ~LOBBY_SAVEWARP; else gSaveBlock2Ptr->specialSaveWarpFlags |= LOBBY_SAVEWARP; } -// this function definitely sets a warp status, but because the list is empty, it's unknown what this does yet. -static void sub_81AFD5C(void) +// Unknown save warp flag. Never set because map list is empty. +static void TrySetUnknownWarpStatus(void) { - if (!sub_81AFCEC()) - gSaveBlock2Ptr->specialSaveWarpFlags &= ~(UNK_SPECIAL_SAVE_WARP_FLAG_3); + if (!IsCurMapInEmptyList()) + gSaveBlock2Ptr->specialSaveWarpFlags &= ~UNK_SPECIAL_SAVE_WARP_FLAG_3; else gSaveBlock2Ptr->specialSaveWarpFlags |= UNK_SPECIAL_SAVE_WARP_FLAG_3; } @@ -115,21 +117,21 @@ void TrySetMapSaveWarpStatus(void) { TrySetPokeCenterWarpStatus(); TrySetReloadWarpStatus(); - sub_81AFD5C(); + TrySetUnknownWarpStatus(); } -// In FRLG, only 0x1, 0x10, and 0x20 are set when the pokedex is received -// 0x2, 0x4, 0x8, and 0x8000 are instead set by SetPostgameFlags +// In FRLG, only bits 0, 4, and 5 are set when the pokedex is received. +// Bits 1, 2, 3, and 15 are instead set by SetPostgameFlags. // These flags are read by Pokemon Colosseum/XD for linking. XD Additionally requires FLAG_SYS_GAME_CLEAR void SetUnlockedPokedexFlags(void) { - gSaveBlock2Ptr->gcnLinkFlags |= 0x8000; - gSaveBlock2Ptr->gcnLinkFlags |= 0x1; - gSaveBlock2Ptr->gcnLinkFlags |= 0x2; - gSaveBlock2Ptr->gcnLinkFlags |= 0x4; - gSaveBlock2Ptr->gcnLinkFlags |= 0x10; - gSaveBlock2Ptr->gcnLinkFlags |= 0x20; - gSaveBlock2Ptr->gcnLinkFlags |= 0x8; + gSaveBlock2Ptr->gcnLinkFlags |= (1 << 15); + gSaveBlock2Ptr->gcnLinkFlags |= (1 << 0); + gSaveBlock2Ptr->gcnLinkFlags |= (1 << 1); + gSaveBlock2Ptr->gcnLinkFlags |= (1 << 2); + gSaveBlock2Ptr->gcnLinkFlags |= (1 << 4); + gSaveBlock2Ptr->gcnLinkFlags |= (1 << 5); + gSaveBlock2Ptr->gcnLinkFlags |= (1 << 3); } void SetChampionSaveWarp(void) From f2e0c9ec9d6333813ca37edbb944ff333770679e Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 17 Oct 2021 17:51:35 -0400 Subject: [PATCH 03/10] Some pokedex clean up --- gflib/text.h | 2 +- src/battle_script_commands.c | 2 +- src/pokedex.c | 228 +++++++++++++++++++---------------- src/pokemon_storage_system.c | 2 +- src/pokenav_conditions_1.c | 2 +- 5 files changed, 126 insertions(+), 110 deletions(-) diff --git a/gflib/text.h b/gflib/text.h index f71cd557f..8871ba2f1 100644 --- a/gflib/text.h +++ b/gflib/text.h @@ -71,7 +71,7 @@ // #define CHAR_i_ACUTE 0x6F // -#define CHAR_GENDERLESS 0x77 // Empty space for lack of gender icon +#define CHAR_SPACER 0x77 // Empty space // #define CHAR_UP_ARROW 0x79 #define CHAR_DOWN_ARROW 0x7A diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 91f89137a..f71720295 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -6047,7 +6047,7 @@ static void PutLevelAndGenderOnLvlUpBox(void) var = (u32)(txtPtr); txtPtr = ConvertIntToDecimalStringN(txtPtr, monLevel, STR_CONV_MODE_LEFT_ALIGN, 3); var = (u32)(txtPtr) - var; - txtPtr = StringFill(txtPtr, CHAR_GENDERLESS, 4 - var); + txtPtr = StringFill(txtPtr, CHAR_SPACER, 4 - var); if (monGender != MON_GENDERLESS) { diff --git a/src/pokedex.c b/src/pokedex.c index fa64b155c..67e2d732e 100644 --- a/src/pokedex.c +++ b/src/pokedex.c @@ -104,13 +104,15 @@ enum #define POKEBALL_ROTATION_TOP 64 #define POKEBALL_ROTATION_BOTTOM (POKEBALL_ROTATION_TOP - 16) -// EWRAM +// Coordinates of the Pokémon sprite on its page (info/cry screens) +#define MON_PAGE_X 48 +#define MON_PAGE_Y 56 + static EWRAM_DATA struct PokedexView *sPokedexView = NULL; static EWRAM_DATA u16 sLastSelectedPokemon = 0; static EWRAM_DATA u8 sPokeBallRotation = 0; static EWRAM_DATA struct PokedexListItem *sPokedexListItem = NULL; -// IWRAM common // This is written to, but never read. u8 gUnusedPokedexU8; void (*gPokedexVBlankCB)(void); @@ -241,7 +243,7 @@ static void SpriteCB_DexListStartMenuCursor(struct Sprite *sprite); static void SpriteCB_PokedexListMonSprite(struct Sprite *sprite); static u8 LoadInfoScreen(struct PokedexListItem*, u8 monSpriteId); static bool8 IsInfoScreenScrolling(u8); -static u8 sub_80BE9F8(struct PokedexListItem*, u8); +static u8 StartInfoScreenScroll(struct PokedexListItem*, u8); static void Task_LoadInfoScreen(u8); static void Task_HandleInfoScreenInput(u8); static void Task_SwitchScreensFromInfoScreen(u8); @@ -270,7 +272,7 @@ static void PrintMonHeight(u16 height, u8 left, u8 top); static void PrintMonWeight(u16 weight, u8 left, u8 top); static void ResetOtherVideoRegisters(u16); static u8 PrintCryScreenSpeciesName(u8, u16, u8, u8); -static void PrintFootprint(u8 windowId, u16 dexNum); +static void DrawFootprint(u8 windowId, u16 dexNum); static u16 CreateSizeScreenTrainerPic(u16, s16, s16, s8); static u16 GetNextPosition(u8, u16, u16, u16); static u8 LoadSearchMenu(void); @@ -1657,7 +1659,7 @@ void Task_OpenPokedexMainPage(u8 taskId) gTasks[taskId].func = Task_HandlePokedexInput; } -#define tTaskId data[0] +#define tLoadScreenTaskId data[0] static void Task_HandlePokedexInput(u8 taskId) { @@ -1669,7 +1671,7 @@ static void Task_HandlePokedexInput(u8 taskId) } else { - if ((JOY_NEW(A_BUTTON)) && sPokedexView->pokedexList[sPokedexView->selectedPokemon].seen) + if (JOY_NEW(A_BUTTON) && sPokedexView->pokedexList[sPokedexView->selectedPokemon].seen) { UpdateSelectedMonSpriteId(); BeginNormalPaletteFade(~(1 << (gSprites[sPokedexView->selectedMonSpriteId].oam.paletteNum + 16)), 0, 0, 0x10, RGB_BLACK); @@ -1690,7 +1692,7 @@ static void Task_HandlePokedexInput(u8 taskId) { PlaySE(SE_SELECT); BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 0x10, RGB_BLACK); - gTasks[taskId].tTaskId = LoadSearchMenu(); + gTasks[taskId].tLoadScreenTaskId = LoadSearchMenu(); sPokedexView->screenSwitchState = 0; sPokedexView->pokeBallRotationBackup = sPokedexView->pokeBallRotation; sPokedexView->selectedPokemonBackup = sPokedexView->selectedPokemon; @@ -1770,12 +1772,12 @@ static void Task_HandlePokedexStartMenuInput(u8 taskId) gTasks[taskId].func = Task_HandlePokedexInput; PlaySE(SE_SELECT); } - else if ((JOY_REPEAT(DPAD_UP)) && sPokedexView->menuCursorPos != 0) + else if (JOY_REPEAT(DPAD_UP) && sPokedexView->menuCursorPos != 0) { sPokedexView->menuCursorPos--; PlaySE(SE_SELECT); } - else if ((JOY_REPEAT(DPAD_DOWN)) && sPokedexView->menuCursorPos < 3) + else if (JOY_REPEAT(DPAD_DOWN) && sPokedexView->menuCursorPos < 3) { sPokedexView->menuCursorPos++; PlaySE(SE_SELECT); @@ -1783,25 +1785,28 @@ static void Task_HandlePokedexStartMenuInput(u8 taskId) } } +// Opening the info screen from list view. Pokémon sprite is moving to its new position, wait for it to arrive static void Task_OpenInfoScreenAfterMonMovement(u8 taskId) { - if (gSprites[sPokedexView->selectedMonSpriteId].x == 48 && gSprites[sPokedexView->selectedMonSpriteId].y == 56) + if (gSprites[sPokedexView->selectedMonSpriteId].x == MON_PAGE_X && gSprites[sPokedexView->selectedMonSpriteId].y == MON_PAGE_Y) { sPokedexView->currentPageBackup = sPokedexView->currentPage; - gTasks[taskId].tTaskId = LoadInfoScreen(&sPokedexView->pokedexList[sPokedexView->selectedPokemon], sPokedexView->selectedMonSpriteId); + gTasks[taskId].tLoadScreenTaskId = LoadInfoScreen(&sPokedexView->pokedexList[sPokedexView->selectedPokemon], sPokedexView->selectedMonSpriteId); gTasks[taskId].func = Task_WaitForExitInfoScreen; } } static void Task_WaitForExitInfoScreen(u8 taskId) { - if (gTasks[gTasks[taskId].tTaskId].isActive) + if (gTasks[gTasks[taskId].tLoadScreenTaskId].isActive) { - if (sPokedexView->currentPage == PAGE_INFO && !IsInfoScreenScrolling(gTasks[taskId].tTaskId) && TryDoInfoScreenScroll()) - sub_80BE9F8(&sPokedexView->pokedexList[sPokedexView->selectedPokemon], gTasks[taskId].tTaskId); + // While active, handle scroll input + if (sPokedexView->currentPage == PAGE_INFO && !IsInfoScreenScrolling(gTasks[taskId].tLoadScreenTaskId) && TryDoInfoScreenScroll()) + StartInfoScreenScroll(&sPokedexView->pokedexList[sPokedexView->selectedPokemon], gTasks[taskId].tLoadScreenTaskId); } else { + // Exiting, back to list view sLastSelectedPokemon = sPokedexView->selectedPokemon; sPokeBallRotation = sPokedexView->pokeBallRotation; gTasks[taskId].func = Task_OpenPokedexMainPage; @@ -1810,7 +1815,7 @@ static void Task_WaitForExitInfoScreen(u8 taskId) static void Task_WaitForExitSearch(u8 taskId) { - if (!gTasks[gTasks[taskId].tTaskId].isActive) + if (!gTasks[gTasks[taskId].tLoadScreenTaskId].isActive) { ClearMonSprites(); @@ -1869,7 +1874,7 @@ static void Task_HandleSearchResultsInput(u8 taskId) } else { - if ((JOY_NEW(A_BUTTON)) && sPokedexView->pokedexList[sPokedexView->selectedPokemon].seen) + if (JOY_NEW(A_BUTTON) && sPokedexView->pokedexList[sPokedexView->selectedPokemon].seen) { u32 a; @@ -1892,7 +1897,7 @@ static void Task_HandleSearchResultsInput(u8 taskId) else if (JOY_NEW(SELECT_BUTTON)) { BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 0x10, RGB_BLACK); - gTasks[taskId].tTaskId = LoadSearchMenu(); + gTasks[taskId].tLoadScreenTaskId = LoadSearchMenu(); sPokedexView->screenSwitchState = 0; gTasks[taskId].func = Task_WaitForExitSearch; PlaySE(SE_PC_LOGIN); @@ -1972,12 +1977,12 @@ static void Task_HandleSearchResultsStartMenuInput(u8 taskId) gTasks[taskId].func = Task_HandleSearchResultsInput; PlaySE(SE_SELECT); } - else if ((JOY_REPEAT(DPAD_UP)) && sPokedexView->menuCursorPos) + else if (JOY_REPEAT(DPAD_UP) && sPokedexView->menuCursorPos) { sPokedexView->menuCursorPos--; PlaySE(SE_SELECT); } - else if ((JOY_REPEAT(DPAD_DOWN)) && sPokedexView->menuCursorPos < 4) + else if (JOY_REPEAT(DPAD_DOWN) && sPokedexView->menuCursorPos < 4) { sPokedexView->menuCursorPos++; PlaySE(SE_SELECT); @@ -1987,10 +1992,10 @@ static void Task_HandleSearchResultsStartMenuInput(u8 taskId) static void Task_OpenSearchResultsInfoScreenAfterMonMovement(u8 taskId) { - if (gSprites[sPokedexView->selectedMonSpriteId].x == 48 && gSprites[sPokedexView->selectedMonSpriteId].y == 56) + if (gSprites[sPokedexView->selectedMonSpriteId].x == MON_PAGE_X && gSprites[sPokedexView->selectedMonSpriteId].y == MON_PAGE_Y) { sPokedexView->currentPageBackup = sPokedexView->currentPage; - gTasks[taskId].tTaskId = LoadInfoScreen(&sPokedexView->pokedexList[sPokedexView->selectedPokemon], sPokedexView->selectedMonSpriteId); + gTasks[taskId].tLoadScreenTaskId = LoadInfoScreen(&sPokedexView->pokedexList[sPokedexView->selectedPokemon], sPokedexView->selectedMonSpriteId); sPokedexView->selectedMonSpriteId = -1; gTasks[taskId].func = Task_WaitForExitSearchResultsInfoScreen; } @@ -1998,13 +2003,15 @@ static void Task_OpenSearchResultsInfoScreenAfterMonMovement(u8 taskId) static void Task_WaitForExitSearchResultsInfoScreen(u8 taskId) { - if (gTasks[gTasks[taskId].tTaskId].isActive) + if (gTasks[gTasks[taskId].tLoadScreenTaskId].isActive) { - if (sPokedexView->currentPage == PAGE_INFO && !IsInfoScreenScrolling(gTasks[taskId].tTaskId) && TryDoInfoScreenScroll()) - sub_80BE9F8(&sPokedexView->pokedexList[sPokedexView->selectedPokemon], gTasks[taskId].tTaskId); + // While active, handle scroll input + if (sPokedexView->currentPage == PAGE_INFO && !IsInfoScreenScrolling(gTasks[taskId].tLoadScreenTaskId) && TryDoInfoScreenScroll()) + StartInfoScreenScroll(&sPokedexView->pokedexList[sPokedexView->selectedPokemon], gTasks[taskId].tLoadScreenTaskId); } else { + // Exiting, back to search results gTasks[taskId].func = Task_OpenSearchResults; } } @@ -2039,7 +2046,7 @@ static void Task_ClosePokedexFromSearchResultsStartMenu(u8 taskId) } } -#undef tTaskId +#undef tLoadScreenTaskId // For loading main pokedex page or pokedex search results static bool8 LoadPokedexListPage(u8 page) @@ -2586,7 +2593,7 @@ static u16 TryDoPokedexScroll(u16 selectedMon, u16 ignored) u16 startingPos; u8 scrollDir = 0; - if ((JOY_HELD(DPAD_UP)) && (selectedMon > 0)) + if (JOY_HELD(DPAD_UP) && (selectedMon > 0)) { scrollDir = 1; selectedMon = GetNextPosition(1, selectedMon, 0, sPokedexView->pokemonListCount - 1); @@ -2594,7 +2601,7 @@ static u16 TryDoPokedexScroll(u16 selectedMon, u16 ignored) CreateMonListEntry(1, selectedMon, ignored); PlaySE(SE_DEX_SCROLL); } - else if ((JOY_HELD(DPAD_DOWN)) && (selectedMon < sPokedexView->pokemonListCount - 1)) + else if (JOY_HELD(DPAD_DOWN) && (selectedMon < sPokedexView->pokemonListCount - 1)) { scrollDir = 2; selectedMon = GetNextPosition(0, selectedMon, 0, sPokedexView->pokemonListCount - 1); @@ -2602,7 +2609,7 @@ static u16 TryDoPokedexScroll(u16 selectedMon, u16 ignored) CreateMonListEntry(2, selectedMon, ignored); PlaySE(SE_DEX_SCROLL); } - else if ((JOY_NEW(DPAD_LEFT)) && (selectedMon > 0)) + else if (JOY_NEW(DPAD_LEFT) && (selectedMon > 0)) { startingPos = selectedMon; @@ -2613,7 +2620,7 @@ static u16 TryDoPokedexScroll(u16 selectedMon, u16 ignored) CreateMonSpritesAtPos(selectedMon, 0xE); PlaySE(SE_DEX_PAGE); } - else if ((JOY_NEW(DPAD_RIGHT)) && (selectedMon < sPokedexView->pokemonListCount - 1)) + else if (JOY_NEW(DPAD_RIGHT) && (selectedMon < sPokedexView->pokemonListCount - 1)) { startingPos = selectedMon; for (i = 0; i < 7; i++) @@ -2662,7 +2669,7 @@ static bool8 TryDoInfoScreenScroll(void) u16 nextPokemon; u16 selectedPokemon = sPokedexView->selectedPokemon; - if ((JOY_NEW(DPAD_UP)) && selectedPokemon) + if (JOY_NEW(DPAD_UP) && selectedPokemon) { nextPokemon = selectedPokemon; while (nextPokemon != 0) @@ -2685,7 +2692,7 @@ static bool8 TryDoInfoScreenScroll(void) return TRUE; } } - else if ((JOY_NEW(DPAD_DOWN)) && selectedPokemon < sPokedexView->pokemonListCount - 1) + else if (JOY_NEW(DPAD_DOWN) && selectedPokemon < sPokedexView->pokemonListCount - 1) { nextPokemon = selectedPokemon; while (nextPokemon < sPokedexView->pokemonListCount - 1) @@ -3002,16 +3009,16 @@ void SpriteCB_MoveMonForInfoScreen(struct Sprite *sprite) sprite->oam.affineMode = ST_OAM_AFFINE_OFF; sprite->x2 = 0; sprite->y2 = 0; - if (sprite->x != 48 || sprite->y != 56) + if (sprite->x != MON_PAGE_X || sprite->y != MON_PAGE_Y) { - if (sprite->x > 48) + if (sprite->x > MON_PAGE_X) sprite->x--; - if (sprite->x < 48) + if (sprite->x < MON_PAGE_X) sprite->x++; - if (sprite->y > 56) + if (sprite->y > MON_PAGE_Y) sprite->y--; - if (sprite->y < 56) + if (sprite->y < MON_PAGE_Y) sprite->y++; } else @@ -3165,7 +3172,12 @@ static void PrintInfoScreenText(const u8* str, u8 left, u8 top) AddTextPrinterParameterized4(0, 1, left, top, 0, 0, color, -1, str); } -#define tMonSpriteId data[4] +#define tScrolling data[0] +#define tMonSpriteDone data[1] +#define tBgLoaded data[2] +#define tSkipCry data[3] +#define tMonSpriteId data[4] +#define tTrainerSpriteId data[5] static u8 LoadInfoScreen(struct PokedexListItem* item, u8 monSpriteId) { @@ -3173,12 +3185,12 @@ static u8 LoadInfoScreen(struct PokedexListItem* item, u8 monSpriteId) sPokedexListItem = item; taskId = CreateTask(Task_LoadInfoScreen, 0); - gTasks[taskId].data[0] = 0; - gTasks[taskId].data[1] = 1; - gTasks[taskId].data[2] = 0; - gTasks[taskId].data[3] = 0; + gTasks[taskId].tScrolling = FALSE; + gTasks[taskId].tMonSpriteDone = TRUE; // Already has sprite from list view + gTasks[taskId].tBgLoaded = FALSE; + gTasks[taskId].tSkipCry = FALSE; gTasks[taskId].tMonSpriteId = monSpriteId; - gTasks[taskId].data[5] = 255; + gTasks[taskId].tTrainerSpriteId = SPRITE_NONE; ResetBgsAndClearDma3BusyFlags(0); InitBgsFromTemplates(0, sInfoScreen_BgTemplate, ARRAY_COUNT(sInfoScreen_BgTemplate)); SetBgTilemapBuffer(3, AllocZeroed(BG_SCREEN_SIZE)); @@ -3193,19 +3205,19 @@ static u8 LoadInfoScreen(struct PokedexListItem* item, u8 monSpriteId) static bool8 IsInfoScreenScrolling(u8 taskId) { - if (gTasks[taskId].data[0] == 0 && gTasks[taskId].func == Task_HandleInfoScreenInput) + if (!gTasks[taskId].tScrolling && gTasks[taskId].func == Task_HandleInfoScreenInput) return FALSE; else return TRUE; } -static u8 sub_80BE9F8(struct PokedexListItem *item, u8 taskId) +static u8 StartInfoScreenScroll(struct PokedexListItem *item, u8 taskId) { sPokedexListItem = item; - gTasks[taskId].data[0] = 1; - gTasks[taskId].data[1] = 0; - gTasks[taskId].data[2] = 0; - gTasks[taskId].data[3] = 0; + gTasks[taskId].tScrolling = TRUE; + gTasks[taskId].tMonSpriteDone = FALSE; + gTasks[taskId].tBgLoaded = FALSE; + gTasks[taskId].tSkipCry = FALSE; return taskId; } @@ -3223,9 +3235,9 @@ static void Task_LoadInfoScreen(u8 taskId) gPokedexVBlankCB = gMain.vblankCallback; SetVBlankCallback(NULL); r2 = 0; - if (gTasks[taskId].data[1] != 0) + if (gTasks[taskId].tMonSpriteDone) r2 += DISPCNT_OBJ_ON; - if (gTasks[taskId].data[2] != 0) + if (gTasks[taskId].tBgLoaded) r2 |= DISPCNT_BG1_ON; ResetOtherVideoRegisters(r2); gMain.state = 1; @@ -3237,7 +3249,7 @@ static void Task_LoadInfoScreen(u8 taskId) FillWindowPixelBuffer(WIN_INFO, PIXEL_FILL(0)); PutWindowTilemap(WIN_INFO); PutWindowTilemap(WIN_FOOTPRINT); - PrintFootprint(WIN_FOOTPRINT, sPokedexListItem->dexNum); + DrawFootprint(WIN_FOOTPRINT, sPokedexListItem->dexNum); CopyWindowToVram(WIN_FOOTPRINT, 2); gMain.state++; break; @@ -3261,9 +3273,9 @@ static void Task_LoadInfoScreen(u8 taskId) gMain.state++; break; case 5: - if (gTasks[taskId].data[1] == 0) + if (!gTasks[taskId].tMonSpriteDone) { - gTasks[taskId].tMonSpriteId = (u16)CreateMonSpriteFromNationalDexNumber(sPokedexListItem->dexNum, 48, 56, 0); + gTasks[taskId].tMonSpriteId = (u16)CreateMonSpriteFromNationalDexNumber(sPokedexListItem->dexNum, MON_PAGE_X, MON_PAGE_Y, 0); gSprites[gTasks[taskId].tMonSpriteId].oam.priority = 0; } gMain.state++; @@ -3272,9 +3284,9 @@ static void Task_LoadInfoScreen(u8 taskId) { u32 preservedPalettes = 0; - if (gTasks[taskId].data[2] != 0) + if (gTasks[taskId].tBgLoaded) preservedPalettes = 0x14; // each bit represents a palette index - if (gTasks[taskId].data[1] != 0) + if (gTasks[taskId].tMonSpriteDone) preservedPalettes |= (1 << (gSprites[gTasks[taskId].tMonSpriteId].oam.paletteNum + 16)); BeginNormalPaletteFade(~preservedPalettes, 0, 16, 0, RGB_BLACK); SetVBlankCallback(gPokedexVBlankCB); @@ -3296,10 +3308,10 @@ static void Task_LoadInfoScreen(u8 taskId) if (!gPaletteFade.active) { gMain.state++; - if (gTasks[taskId].data[3] == 0) + if (!gTasks[taskId].tSkipCry) { StopCryAndClearCrySongs(); - PlayCry2(NationalPokedexNumToSpecies(sPokedexListItem->dexNum), 0, 0x7D, 0xA); + PlayCry2(NationalPokedexNumToSpecies(sPokedexListItem->dexNum), 0, 125, 10); } else { @@ -3312,10 +3324,10 @@ static void Task_LoadInfoScreen(u8 taskId) gMain.state++; break; case 10: - gTasks[taskId].data[0] = 0; - gTasks[taskId].data[1] = 0; - gTasks[taskId].data[2] = 1; - gTasks[taskId].data[3] = 1; + gTasks[taskId].tScrolling = FALSE; + gTasks[taskId].tMonSpriteDone = FALSE; // Reload next time screen comes up + gTasks[taskId].tBgLoaded = TRUE; + gTasks[taskId].tSkipCry = TRUE; gTasks[taskId].func = Task_HandleInfoScreenInput; gMain.state = 0; break; @@ -3343,7 +3355,7 @@ static void FreeInfoScreenWindowAndBgBuffers(void) static void Task_HandleInfoScreenInput(u8 taskId) { - if (gTasks[taskId].data[0] != 0) + if (gTasks[taskId].tScrolling) { // Scroll up/down BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); @@ -3395,8 +3407,8 @@ static void Task_HandleInfoScreenInput(u8 taskId) } return; } - if (((JOY_NEW(DPAD_LEFT)) - || ((JOY_NEW(L_BUTTON)) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) + if ((JOY_NEW(DPAD_LEFT) + || (JOY_NEW(L_BUTTON) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) && sPokedexView->selectedScreen > 0) { sPokedexView->selectedScreen--; @@ -3404,8 +3416,8 @@ static void Task_HandleInfoScreenInput(u8 taskId) PlaySE(SE_DEX_PAGE); return; } - if (((JOY_NEW(DPAD_RIGHT)) - || ((JOY_NEW(R_BUTTON)) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) + if ((JOY_NEW(DPAD_RIGHT) + || (JOY_NEW(R_BUTTON) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) && sPokedexView->selectedScreen < CANCEL_SCREEN) { sPokedexView->selectedScreen++; @@ -3554,7 +3566,7 @@ static void Task_LoadCryScreen(u8 taskId) gMain.state++; break; case 5: - gTasks[taskId].tMonSpriteId = CreateMonSpriteFromNationalDexNumber(sPokedexListItem->dexNum, 48, 56, 0); + gTasks[taskId].tMonSpriteId = CreateMonSpriteFromNationalDexNumber(sPokedexListItem->dexNum, MON_PAGE_X, MON_PAGE_Y, 0); gSprites[gTasks[taskId].tMonSpriteId].oam.priority = 0; gDexCryScreenState = 0; gMain.state++; @@ -3642,8 +3654,8 @@ static void Task_HandleCryScreenInput(u8 taskId) PlaySE(SE_PC_OFF); return; } - if ((JOY_NEW(DPAD_LEFT)) - || ((JOY_NEW(L_BUTTON)) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) + if (JOY_NEW(DPAD_LEFT) + || (JOY_NEW(L_BUTTON) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) { BeginNormalPaletteFade(PALETTES_ALL & ~(0x14), 0, 0, 0x10, RGB_BLACK); m4aMPlayContinue(&gMPlayInfo_BGM); @@ -3652,8 +3664,8 @@ static void Task_HandleCryScreenInput(u8 taskId) PlaySE(SE_DEX_PAGE); return; } - if ((JOY_NEW(DPAD_RIGHT)) - || ((JOY_NEW(R_BUTTON)) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) + if (JOY_NEW(DPAD_RIGHT) + || (JOY_NEW(R_BUTTON) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) { if (!sPokedexListItem->owned) { @@ -3758,7 +3770,7 @@ static void Task_LoadSizeScreen(u8 taskId) gSprites[spriteId].y2 = gPokedexEntries[sPokedexListItem->dexNum].trainerOffset; SetOamMatrix(1, gPokedexEntries[sPokedexListItem->dexNum].trainerScale, 0, 0, gPokedexEntries[sPokedexListItem->dexNum].trainerScale); LoadPalette(sSizeScreenSilhouette_Pal, (gSprites[spriteId].oam.paletteNum + 16) * 16, 0x20); - gTasks[taskId].data[5] = spriteId; + gTasks[taskId].tTrainerSpriteId = spriteId; gMain.state++; break; case 6: @@ -3812,8 +3824,8 @@ static void Task_HandleSizeScreenInput(u8 taskId) gTasks[taskId].func = Task_SwitchScreensFromSizeScreen; PlaySE(SE_PC_OFF); } - else if ((JOY_NEW(DPAD_LEFT)) - || ((JOY_NEW(L_BUTTON)) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) + else if (JOY_NEW(DPAD_LEFT) + || (JOY_NEW(L_BUTTON) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) { BeginNormalPaletteFade(PALETTES_ALL & ~(0x14), 0, 0, 0x10, RGB_BLACK); sPokedexView->screenSwitchState = 2; @@ -3827,7 +3839,7 @@ static void Task_SwitchScreensFromSizeScreen(u8 taskId) if (!gPaletteFade.active) { FreeAndDestroyMonPicSprite(gTasks[taskId].tMonSpriteId); - FreeAndDestroyTrainerPicSprite(gTasks[taskId].data[5]); + FreeAndDestroyTrainerPicSprite(gTasks[taskId].tTrainerSpriteId); switch (sPokedexView->screenSwitchState) { default: @@ -3841,7 +3853,12 @@ static void Task_SwitchScreensFromSizeScreen(u8 taskId) } } +#undef tScrolling +#undef tMonSpriteDone +#undef tBgLoaded +#undef tSkipCry #undef tMonSpriteId +#undef tTrainerSpriteId static void LoadScreenSelectBarMain(u16 unused) { @@ -3959,7 +3976,7 @@ static void Task_DisplayCaughtMonDexPage(u8 taskId) FillWindowPixelBuffer(WIN_INFO, PIXEL_FILL(0)); PutWindowTilemap(WIN_INFO); PutWindowTilemap(WIN_FOOTPRINT); - PrintFootprint(WIN_FOOTPRINT, gTasks[taskId].tDexNum); + DrawFootprint(WIN_FOOTPRINT, gTasks[taskId].tDexNum); CopyWindowToVram(WIN_FOOTPRINT, 2); ResetPaletteFade(); LoadPokedexBgPalette(FALSE); @@ -3976,7 +3993,7 @@ static void Task_DisplayCaughtMonDexPage(u8 taskId) gTasks[taskId].tState++; break; case 4: - spriteId = CreateMonSpriteFromNationalDexNumber(dexNum, 48, 56, 0); + spriteId = CreateMonSpriteFromNationalDexNumber(dexNum, MON_PAGE_X, MON_PAGE_Y, 0); gSprites[spriteId].oam.priority = 0; BeginNormalPaletteFade(PALETTES_ALL, 0, 0x10, 0, RGB_BLACK); SetVBlankCallback(gPokedexVBlankCB); @@ -4174,7 +4191,7 @@ static void PrintMonWeight(u16 weight, u8 left, u8 top) if ((buffer[i] = (lbs / 100000) + CHAR_0) == CHAR_0 && !output) { - buffer[i++] = 0x77; + buffer[i++] = CHAR_SPACER; } else { @@ -4185,7 +4202,7 @@ static void PrintMonWeight(u16 weight, u8 left, u8 top) lbs %= 100000; if ((buffer[i] = (lbs / 10000) + CHAR_0) == CHAR_0 && !output) { - buffer[i++] = 0x77; + buffer[i++] = CHAR_SPACER; } else { @@ -4196,7 +4213,7 @@ static void PrintMonWeight(u16 weight, u8 left, u8 top) lbs %= 10000; if ((buffer[i] = (lbs / 1000) + CHAR_0) == CHAR_0 && !output) { - buffer[i++] = 0x77; + buffer[i++] = CHAR_SPACER; } else { @@ -4525,7 +4542,7 @@ static void UnusedPrintDecimalNum(u8 windowId, u16 b, u8 left, u8 top) result = b / 1000; if (result == 0) { - str[0] = 0x77; + str[0] = CHAR_SPACER; outputted = FALSE; } else @@ -4537,7 +4554,7 @@ static void UnusedPrintDecimalNum(u8 windowId, u16 b, u8 left, u8 top) result = (b % 1000) / 100; if (result == 0 && !outputted) { - str[1] = 0x77; + str[1] = CHAR_SPACER; outputted = FALSE; } else @@ -4553,36 +4570,35 @@ static void UnusedPrintDecimalNum(u8 windowId, u16 b, u8 left, u8 top) PrintInfoSubMenuText(windowId, str, left, top); } -static void PrintFootprint(u8 windowId, u16 dexNum) +static void DrawFootprint(u8 windowId, u16 dexNum) { - u8 image[32 * 4]; - const u8 * r12 = gMonFootprintTable[NationalPokedexNumToSpecies(dexNum)]; - u16 r5 = 0; - u16 i; - u16 j; + u8 footprint[32 * 4]; + const u8 * footprintGfx = gMonFootprintTable[NationalPokedexNumToSpecies(dexNum)]; + u16 tileIdx = 0; + u16 i, j; for (i = 0; i < 32; i++) { - u8 r3 = r12[i]; + u8 tile = footprintGfx[i]; for (j = 0; j < 4; j++) { - u8 value = ((r3 >> (2 * j)) & 1 ? 2 : 0); - if ((2 << (2 * j)) & r3) + u8 value = ((tile >> (2 * j)) & 1 ? 2 : 0); + if (tile & (2 << (2 * j))) value |= 0x20; - image[r5] = value; - r5++; + footprint[tileIdx] = value; + tileIdx++; } } - CopyToWindowPixelBuffer(windowId, image, sizeof(image), 0); + CopyToWindowPixelBuffer(windowId, footprint, sizeof(footprint), 0); } -// Unused -void sub_80C0DC0(u16 a, u16 b) +// Unused Ruby/Sapphire function. +static void RS_DrawFootprint(u16 offset, u16 tileNum) { - *(u16 *)(VRAM + a * 0x800 + 0x232) = 0xF000 + b + 0; - *(u16 *)(VRAM + a * 0x800 + 0x234) = 0xF000 + b + 1; - *(u16 *)(VRAM + a * 0x800 + 0x272) = 0xF000 + b + 2; - *(u16 *)(VRAM + a * 0x800 + 0x274) = 0xF000 + b + 3; + *(u16 *)(VRAM + offset * 0x800 + 0x232) = 0xF000 + tileNum + 0; + *(u16 *)(VRAM + offset * 0x800 + 0x234) = 0xF000 + tileNum + 1; + *(u16 *)(VRAM + offset * 0x800 + 0x272) = 0xF000 + tileNum + 2; + *(u16 *)(VRAM + offset * 0x800 + 0x274) = 0xF000 + tileNum + 3; } static u16 GetNextPosition(u8 direction, u16 position, u16 min, u16 max) @@ -4921,7 +4937,7 @@ static void Task_HandleSearchTopBarInput(u8 taskId) } return; } - if ((JOY_NEW(DPAD_LEFT)) && gTasks[taskId].tTopBarItem > SEARCH_TOPBAR_SEARCH) + if (JOY_NEW(DPAD_LEFT) && gTasks[taskId].tTopBarItem > SEARCH_TOPBAR_SEARCH) { PlaySE(SE_DEX_PAGE); gTasks[taskId].tTopBarItem--; @@ -4929,7 +4945,7 @@ static void Task_HandleSearchTopBarInput(u8 taskId) CopyWindowToVram(0, 2); CopyBgTilemapBufferToVram(3); } - if ((JOY_NEW(DPAD_RIGHT)) && gTasks[taskId].tTopBarItem < SEARCH_TOPBAR_CANCEL) + if (JOY_NEW(DPAD_RIGHT) && gTasks[taskId].tTopBarItem < SEARCH_TOPBAR_CANCEL) { PlaySE(SE_DEX_PAGE); gTasks[taskId].tTopBarItem++; @@ -5010,7 +5026,7 @@ static void Task_HandleSearchMenuInput(u8 taskId) return; } - if ((JOY_NEW(DPAD_LEFT)) && movementMap[gTasks[taskId].tMenuItem][0] != 0xFF) + if (JOY_NEW(DPAD_LEFT) && movementMap[gTasks[taskId].tMenuItem][0] != 0xFF) { PlaySE(SE_SELECT); gTasks[taskId].tMenuItem = movementMap[gTasks[taskId].tMenuItem][0]; @@ -5018,7 +5034,7 @@ static void Task_HandleSearchMenuInput(u8 taskId) CopyWindowToVram(0, 2); CopyBgTilemapBufferToVram(3); } - if ((JOY_NEW(DPAD_RIGHT)) && movementMap[gTasks[taskId].tMenuItem][1] != 0xFF) + if (JOY_NEW(DPAD_RIGHT) && movementMap[gTasks[taskId].tMenuItem][1] != 0xFF) { PlaySE(SE_SELECT); gTasks[taskId].tMenuItem = movementMap[gTasks[taskId].tMenuItem][1]; @@ -5026,7 +5042,7 @@ static void Task_HandleSearchMenuInput(u8 taskId) CopyWindowToVram(0, 2); CopyBgTilemapBufferToVram(3); } - if ((JOY_NEW(DPAD_UP)) && movementMap[gTasks[taskId].tMenuItem][2] != 0xFF) + if (JOY_NEW(DPAD_UP) && movementMap[gTasks[taskId].tMenuItem][2] != 0xFF) { PlaySE(SE_SELECT); gTasks[taskId].tMenuItem = movementMap[gTasks[taskId].tMenuItem][2]; @@ -5034,7 +5050,7 @@ static void Task_HandleSearchMenuInput(u8 taskId) CopyWindowToVram(0, 2); CopyBgTilemapBufferToVram(3); } - if ((JOY_NEW(DPAD_DOWN)) && movementMap[gTasks[taskId].tMenuItem][3] != 0xFF) + if (JOY_NEW(DPAD_DOWN) && movementMap[gTasks[taskId].tMenuItem][3] != 0xFF) { PlaySE(SE_SELECT); gTasks[taskId].tMenuItem = movementMap[gTasks[taskId].tMenuItem][3]; diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index bd0910658..3911f52f0 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -6980,7 +6980,7 @@ static void SetDisplayMonData(void *pokemon, u8 mode) *(txtPtr)++ = TEXT_COLOR_DARK_GRAY; *(txtPtr)++ = TEXT_COLOR_WHITE; *(txtPtr)++ = TEXT_COLOR_LIGHT_GRAY; - *(txtPtr)++ = CHAR_GENDERLESS; + *(txtPtr)++ = CHAR_SPACER; // Genderless break; } diff --git a/src/pokenav_conditions_1.c b/src/pokenav_conditions_1.c index d2424629a..a01b93a80 100644 --- a/src/pokenav_conditions_1.c +++ b/src/pokenav_conditions_1.c @@ -372,7 +372,7 @@ u8 *CopyMonConditionNameGender(u8 *str, u16 id, bool8 arg3) switch (gender) { default: - *(str_++) = CHAR_GENDERLESS; + *(str_++) = CHAR_SPACER; // Genderless break; case MON_MALE: *(str_++) = EXT_CTRL_CODE_BEGIN; From a950f9c7712ed8794e385bb7ed6b9eff360b4260 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 17 Oct 2021 21:51:11 -0400 Subject: [PATCH 04/10] Clean up international_string_util --- include/international_string_util.h | 8 ++--- src/international_string_util.c | 49 ++++++++++++++--------------- src/player_pc.c | 2 +- src/pokenav_conditions_3.c | 4 +-- src/pokenav_match_call_1.c | 6 ++-- src/pokenav_ribbons_1.c | 4 +-- src/tv.c | 2 +- 7 files changed, 36 insertions(+), 39 deletions(-) diff --git a/include/international_string_util.h b/include/international_string_util.h index fe7e85b41..54f4c008f 100644 --- a/include/international_string_util.h +++ b/include/international_string_util.h @@ -10,15 +10,15 @@ int GetStringCenterAlignXOffset(int fontId, const u8 *str, int totalWidth); int GetStringRightAlignXOffset(int fontId, const u8 *str, int totalWidth); int GetStringCenterAlignXOffsetWithLetterSpacing(int fontId, const u8 *str, int totalWidth, int letterSpacing); int GetStringWidthDifference(int fontId, const u8 *str, int totalWidth, int letterSpacing); -int GetMaxWidthInMenuTable(const struct MenuAction *str, int arg1); -int sub_81DB3D8(const struct MenuAction *str, const u8* arg1, int arg2); +int GetMaxWidthInMenuTable(const struct MenuAction *actions, int numActions); +int GetMaxWidthInSubsetOfMenuTable(const struct MenuAction *actions, const u8* actionIds, int numActions); int Intl_GetListMenuWidth(const struct ListMenuTemplate *listMenu); void CopyMonCategoryText(int dexNum, u8 *dest); -u8 *sub_81DB494(u8 *str, int fontId, const u8 *str2, int totalStringWidth); +u8 *GetStringClearToWidth(u8 *dest, int fontId, const u8 *str, int totalStringWidth); void PadNameString(u8 *dest, u8 padChar); void ConvertInternationalPlayerNameStripChar(u8 *, u8); void ConvertInternationalContestantName(u8 *); -int sub_81DB604(u8 *); +int GetNicknameLanguage(u8 *); void sub_81DB620(int windowId, int columnStart, int rowStart, int numFillTiles, int numRows); #endif // GUARD_INTERNATIONAL_STRING_UTIL_H diff --git a/src/international_string_util.c b/src/international_string_util.c index eb2ec16e7..b2ee9743e 100644 --- a/src/international_string_util.c +++ b/src/international_string_util.c @@ -34,32 +34,32 @@ int GetStringWidthDifference(int fontId, const u8 *str, int totalWidth, int lett return 0; } -int GetMaxWidthInMenuTable(const struct MenuAction *str, int numActions) +int GetMaxWidthInMenuTable(const struct MenuAction *actions, int numActions) { - int i, var; + int i, maxWidth; - for (var = 0, i = 0; i < numActions; i++) + for (maxWidth = 0, i = 0; i < numActions; i++) { - int stringWidth = GetStringWidth(1, str[i].text, 0); - if (stringWidth > var) - var = stringWidth; + int stringWidth = GetStringWidth(1, actions[i].text, 0); + if (stringWidth > maxWidth) + maxWidth = stringWidth; } - return ConvertPixelWidthToTileWidth(var); + return ConvertPixelWidthToTileWidth(maxWidth); } -int sub_81DB3D8(const struct MenuAction *str, const u8* arg1, int arg2) +int GetMaxWidthInSubsetOfMenuTable(const struct MenuAction *actions, const u8* actionIds, int numActions) { - int i, var; + int i, maxWidth; - for (var = 0, i = 0; i < arg2; i++) + for (maxWidth = 0, i = 0; i < numActions; i++) { - int stringWidth = GetStringWidth(1, str[arg1[i]].text, 0); - if (stringWidth > var) - var = stringWidth; + int stringWidth = GetStringWidth(1, actions[actionIds[i]].text, 0); + if (stringWidth > maxWidth) + maxWidth = stringWidth; } - return ConvertPixelWidthToTileWidth(var); + return ConvertPixelWidthToTileWidth(maxWidth); } int Intl_GetListMenuWidth(const struct ListMenuTemplate *listMenu) @@ -93,32 +93,29 @@ void CopyMonCategoryText(int dexNum, u8 *dest) StringCopy(str + 1, gText_Pokemon); } -u8 *sub_81DB494(u8 *str, int fontId, const u8 *str2, int totalStringWidth) +u8 *GetStringClearToWidth(u8 *dest, int fontId, const u8 *str, int totalStringWidth) { u8 *buffer; int width; int clearWidth; - if (str2) + if (str) { - buffer = StringCopy(str, str2); - width = GetStringWidth(fontId, str2, 0); + buffer = StringCopy(dest, str); + width = GetStringWidth(fontId, str, 0); } else { - buffer = str; + buffer = dest; width = 0; } clearWidth = totalStringWidth - width; if (clearWidth > 0) { - *buffer = EXT_CTRL_CODE_BEGIN; - buffer++; - *buffer = EXT_CTRL_CODE_CLEAR; - buffer++; - *buffer = clearWidth; - buffer++; + *(buffer++) = EXT_CTRL_CODE_BEGIN; + *(buffer++) = EXT_CTRL_CODE_CLEAR; + *(buffer++) = clearWidth; *buffer = EOS; } @@ -209,7 +206,7 @@ void TVShowConvertInternationalString(u8 *dest, const u8 *src, int language) ConvertInternationalString(dest, language); } -int sub_81DB604(u8 *str) +int GetNicknameLanguage(u8 *str) { if (str[0] == EXT_CTRL_CODE_BEGIN && str[1] == EXT_CTRL_CODE_JPN) return LANGUAGE_JAPANESE; diff --git a/src/player_pc.c b/src/player_pc.c index 507fc6558..cc9d33067 100644 --- a/src/player_pc.c +++ b/src/player_pc.c @@ -396,7 +396,7 @@ static void InitPlayerPCMenu(u8 taskId) else // Bedroom PC windowTemplate = sWindowTemplates_MainMenus[WIN_MAIN_MENU_BEDROOM]; - windowTemplate.width = sub_81DB3D8(sPlayerPCMenuActions, sTopMenuOptionOrder, sTopMenuNumOptions); + windowTemplate.width = GetMaxWidthInSubsetOfMenuTable(sPlayerPCMenuActions, sTopMenuOptionOrder, sTopMenuNumOptions); tWindowId = AddWindow(&windowTemplate); SetStandardWindowBorderStyle(tWindowId, 0); sub_81995E4(tWindowId, sTopMenuNumOptions, sPlayerPCMenuActions, sTopMenuOptionOrder); diff --git a/src/pokenav_conditions_3.c b/src/pokenav_conditions_3.c index 219bb5a07..53987d11d 100644 --- a/src/pokenav_conditions_3.c +++ b/src/pokenav_conditions_3.c @@ -705,7 +705,7 @@ static void PrintSearchMonListItem(struct PokenavMonList * item, u8 * dest) } StringGetEnd10(gStringVar3); - dest = sub_81DB494(dest, 1, gStringVar3, 60); + dest = GetStringClearToWidth(dest, 1, gStringVar3, 60); switch (gender) { default: @@ -723,5 +723,5 @@ static void PrintSearchMonListItem(struct PokenavMonList * item, u8 * dest) *s++ = CHAR_EXTRA_SYMBOL; *s++ = CHAR_LV_2; ConvertIntToDecimalStringN(s, level, STR_CONV_MODE_LEFT_ALIGN, 3); - sub_81DB494(dest, 1, gStringVar1, 40); + GetStringClearToWidth(dest, 1, gStringVar1, 40); } diff --git a/src/pokenav_match_call_1.c b/src/pokenav_match_call_1.c index e9d4c0b67..64957995d 100755 --- a/src/pokenav_match_call_1.c +++ b/src/pokenav_match_call_1.c @@ -413,12 +413,12 @@ void BufferMatchCallNameAndDesc(struct PokenavMatchCallEntries *matchCallEntry, if (className && trainerName) { - u8 *str2 = sub_81DB494(str, 7, className, 69); - sub_81DB494(str2, 7, trainerName, 51); + u8 *str2 = GetStringClearToWidth(str, 7, className, 69); + GetStringClearToWidth(str2, 7, trainerName, 51); } else { - sub_81DB494(str, 7, NULL, 120); + GetStringClearToWidth(str, 7, NULL, 120); } } diff --git a/src/pokenav_ribbons_1.c b/src/pokenav_ribbons_1.c index 69326ad23..a8aaafa35 100644 --- a/src/pokenav_ribbons_1.c +++ b/src/pokenav_ribbons_1.c @@ -722,7 +722,7 @@ static void BufferRibbonMonInfoText(struct PokenavMonList * item0, u8 * dest) } StringGetEnd10(gStringVar3); - dest = sub_81DB494(dest, 1, gStringVar3, 60); + dest = GetStringClearToWidth(dest, 1, gStringVar3, 60); switch (gender) { default: @@ -741,6 +741,6 @@ static void BufferRibbonMonInfoText(struct PokenavMonList * item0, u8 * dest) *s++ = CHAR_EXTRA_SYMBOL; *s++ = CHAR_LV_2; ConvertIntToDecimalStringN(s, level, STR_CONV_MODE_LEFT_ALIGN, 3); - dest = sub_81DB494(dest, 1, gStringVar1, 54); + dest = GetStringClearToWidth(dest, 1, gStringVar1, 54); ConvertIntToDecimalStringN(dest, item->data, STR_CONV_MODE_RIGHT_ALIGN, 2); } diff --git a/src/tv.c b/src/tv.c index 452923933..310163e94 100644 --- a/src/tv.c +++ b/src/tv.c @@ -1155,7 +1155,7 @@ void TryPutPokemonTodayOnAir(void) show->pokemonToday.ball = itemLastUsed; StringCopy(show->pokemonToday.playerName, gSaveBlock2Ptr->playerName); StringCopy(show->pokemonToday.nickname, gBattleResults.caughtMonNick); - language2 = sub_81DB604(show->pokemonToday.nickname); + language2 = GetNicknameLanguage(show->pokemonToday.nickname); StripExtCtrlCodes(show->pokemonToday.nickname); show->pokemonToday.species = gBattleResults.caughtMonSpecies; StorePlayerIdInRecordMixShow(show); From ed6fdd743f41185a1ebd030fb9d9ea36e37a3ced Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 17 Oct 2021 22:04:08 -0400 Subject: [PATCH 05/10] Some pokemon_icon clean up --- include/pokemon_icon.h | 3 +-- src/pokemon_icon.c | 44 +++++++++++++++++------------------- src/pokemon_storage_system.c | 2 +- 3 files changed, 23 insertions(+), 26 deletions(-) diff --git a/include/pokemon_icon.h b/include/pokemon_icon.h index c0f823bb1..4731da90e 100644 --- a/include/pokemon_icon.h +++ b/include/pokemon_icon.h @@ -4,7 +4,7 @@ extern const u8 gMonIconPaletteIndices[]; const u8 *GetMonIconTiles(u16 species, bool32); -void sub_80D304C(u16 offset); +void TryLoadAllMonIconPalettesAtOffset(u16 offset); u8 GetValidMonIconPalIndex(u16 species); const u8 *GetMonIconPtr(u16 speciesId, u32 personality, u32 frameNo); const u16 *GetValidMonIconPalettePtr(u16 speciesId); @@ -20,7 +20,6 @@ void FreeAndDestroyMonIconSprite(struct Sprite *sprite); u8 CreateMonIcon(u16 species, void (*callback)(struct Sprite *), s16 x, s16 y, u8 subpriority, u32 personality, bool32 handleDeoxys); u8 UpdateMonIconFrame(struct Sprite *sprite); void LoadMonIconPalette(u16 species); -void sub_80D328C(struct Sprite *sprite); void SpriteCB_MonIcon(struct Sprite *sprite); void SetPartyHPBarSprite(struct Sprite *sprite, u8 animNum); u8 GetMonIconPaletteIndexFromSpecies(u16 species); diff --git a/src/pokemon_icon.c b/src/pokemon_icon.c index 3cd80cf0d..58d0b3420 100644 --- a/src/pokemon_icon.c +++ b/src/pokemon_icon.c @@ -19,10 +19,8 @@ struct MonIconSpriteTemplate u16 paletteTag; }; -// static functions static u8 CreateMonIconSprite(struct MonIconSpriteTemplate *, s16, s16, u8); - -// .rodata +static void FreeAndDestroyMonIconSprite_(struct Sprite *sprite); const u8 *const gMonIconTable[] = { @@ -925,7 +923,7 @@ const struct SpritePalette gMonIconPaletteTable[] = { gMonIconPalettes[5], POKE_ICON_BASE_PAL_TAG + 5 }, }; -const struct OamData sMonIconOamData = +static const struct OamData sMonIconOamData = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -976,7 +974,7 @@ static const union AnimCmd sAnim_4[] = ANIMCMD_JUMP(0), }; -const union AnimCmd *const sMonIconAnims[] = +static const union AnimCmd *const sMonIconAnims[] = { sAnim_0, sAnim_1, @@ -997,34 +995,34 @@ static const union AffineAnimCmd sAffineAnim_1[] = AFFINEANIMCMD_END, }; -const union AffineAnimCmd *const sMonIconAffineAnims[] = +static const union AffineAnimCmd *const sMonIconAffineAnims[] = { sAffineAnim_0, sAffineAnim_1, }; -const u16 sSpriteImageSizes[3][4] = +static const u16 sSpriteImageSizes[3][4] = { [ST_OAM_SQUARE] = { - [SPRITE_SIZE(8x8)] = 0x20, - [SPRITE_SIZE(16x16)] = 0x80, - [SPRITE_SIZE(32x32)] = 0x200, - [SPRITE_SIZE(64x64)] = 0x800, + [SPRITE_SIZE(8x8)] = 8 * 8 / 2, + [SPRITE_SIZE(16x16)] = 16 * 16 / 2, + [SPRITE_SIZE(32x32)] = 32 * 32 / 2, + [SPRITE_SIZE(64x64)] = 64 * 64 / 2, }, [ST_OAM_H_RECTANGLE] = { - [SPRITE_SIZE(16x8)] = 0x40, - [SPRITE_SIZE(32x8)] = 0x80, - [SPRITE_SIZE(32x16)] = 0x100, - [SPRITE_SIZE(64x32)] = 0x400, + [SPRITE_SIZE(16x8)] = 16 * 8 / 2, + [SPRITE_SIZE(32x8)] = 32 * 8 / 2, + [SPRITE_SIZE(32x16)] = 32 * 16 / 2, + [SPRITE_SIZE(64x32)] = 64 * 32 / 2, }, [ST_OAM_V_RECTANGLE] = { - [SPRITE_SIZE(8x16)] = 0x40, - [SPRITE_SIZE(8x32)] = 0x80, - [SPRITE_SIZE(16x32)] = 0x100, - [SPRITE_SIZE(32x64)] = 0x400, + [SPRITE_SIZE(8x16)] = 8 * 16 / 2, + [SPRITE_SIZE(8x32)] = 8 * 32 / 2, + [SPRITE_SIZE(16x32)] = 16 * 32 / 2, + [SPRITE_SIZE(32x64)] = 32 * 64 / 2, }, }; @@ -1131,7 +1129,7 @@ const u8 *GetMonIconPtr(u16 species, u32 personality, bool32 handleDeoxys) void FreeAndDestroyMonIconSprite(struct Sprite *sprite) { - sub_80D328C(sprite); + FreeAndDestroyMonIconSprite_(sprite); } void LoadMonIconPalettes(void) @@ -1198,7 +1196,7 @@ const u8* GetMonIconTiles(u16 species, bool32 handleDeoxys) return iconSprite; } -void sub_80D304C(u16 offset) +void TryLoadAllMonIconPalettesAtOffset(u16 offset) { s32 i; const struct SpritePalette* monIconPalettePtr; @@ -1206,7 +1204,7 @@ void sub_80D304C(u16 offset) if (offset <= 0xA0) { monIconPalettePtr = gMonIconPaletteTable; - for(i = 5; i >= 0; i--) + for(i = ARRAY_COUNT(gMonIconPaletteTable) - 1; i >= 0; i--) { LoadPalette(monIconPalettePtr->data, offset, 0x20); offset += 0x10; @@ -1294,7 +1292,7 @@ static u8 CreateMonIconSprite(struct MonIconSpriteTemplate *iconTemplate, s16 x, return spriteId; } -void sub_80D328C(struct Sprite *sprite) +static void FreeAndDestroyMonIconSprite_(struct Sprite *sprite) { struct SpriteFrameImage image = { NULL, sSpriteImageSizes[sprite->oam.shape][sprite->oam.size] }; sprite->images = ℑ diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index 3911f52f0..e18a6db76 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -8177,7 +8177,7 @@ static bool8 MultiMove_Start(void) { case 0: HideBg(0); - sub_80D304C(0x80); + TryLoadAllMonIconPalettesAtOffset(0x80); sMultiMove->state++; break; case 1: From db8ce5d7f9429e4054267617896f66daa2f56633 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 18 Oct 2021 00:08:36 -0400 Subject: [PATCH 06/10] Clean up mauville_old_man, drop ScrSpecial prefix --- .../MauvilleCity_PokemonCenter_1F/scripts.inc | 2 +- data/scripts/mauville_man.inc | 53 +- data/specials.inc | 44 +- include/constants/global.h | 1 + include/global.h | 2 +- include/mauville_old_man.h | 2 +- include/wild_encounter.h | 1 - src/mauville_old_man.c | 821 +++++++++--------- src/trader.c | 12 +- 9 files changed, 457 insertions(+), 481 deletions(-) diff --git a/data/maps/MauvilleCity_PokemonCenter_1F/scripts.inc b/data/maps/MauvilleCity_PokemonCenter_1F/scripts.inc index 4347c4773..463d652b3 100644 --- a/data/maps/MauvilleCity_PokemonCenter_1F/scripts.inc +++ b/data/maps/MauvilleCity_PokemonCenter_1F/scripts.inc @@ -12,7 +12,7 @@ MauvilleCity_PokemonCenter_1F_OnTransition: end MauvilleCity_PokemonCenter_1F_EventScript_SetMauvilleOldManGfx:: - special ScrSpecial_SetMauvilleOldManObjEventGfx + special SetMauvilleOldManObjEventGfx end MauvilleCity_PokemonCenter_1F_EventScript_Nurse:: diff --git a/data/scripts/mauville_man.inc b/data/scripts/mauville_man.inc index a9c008e5e..b34f84e8e 100644 --- a/data/scripts/mauville_man.inc +++ b/data/scripts/mauville_man.inc @@ -1,5 +1,5 @@ MauvilleCity_PokemonCenter_1F_EventScript_MauvilleOldMan:: - special ScrSpecial_GetCurrentMauvilleMan + special Script_GetCurrentMauvilleMan switch VAR_RESULT case MAUVILLE_MAN_BARD, MauvilleCity_PokemonCenter_1F_EventScript_Bard case MAUVILLE_MAN_HIPSTER, MauvilleCity_PokemonCenter_1F_EventScript_Hipster @@ -21,9 +21,9 @@ MauvilleCity_PokemonCenter_1F_EventScript_Bard:: MauvilleCity_PokemonCenter_1F_EventScript_PlaySong:: setvar VAR_0x8004, 0 - special ScrSpecial_PlayBardSong + special PlayBardSong delay 60 - special ScrSpecial_HasBardSongBeenChanged + special HasBardSongBeenChanged compare VAR_RESULT, FALSE goto_if_eq MauvilleCity_PokemonCenter_1F_EventScript_AskToWriteLyrics msgbox MauvilleCity_PokemonCenter_1F_Text_WishICouldPlaySongForOthers, MSGBOX_DEFAULT @@ -52,12 +52,12 @@ MauvilleCity_PokemonCenter_1F_EventScript_WriteLyrics:: goto_if_eq MauvilleCity_PokemonCenter_1F_EventScript_DeclineWritingLyrics msgbox MauvilleCity_PokemonCenter_1F_Text_LetMeSingItForYou, MSGBOX_DEFAULT setvar VAR_0x8004, 1 - special ScrSpecial_PlayBardSong + special PlayBardSong delay 60 msgbox MauvilleCity_PokemonCenter_1F_Text_ThatHowYouWantedSongToGo, MSGBOX_YESNO compare VAR_RESULT, NO goto_if_eq MauvilleCity_PokemonCenter_1F_EventScript_WriteLyrics - special ScrSpecial_SaveBardSongLyrics + special SaveBardSongLyrics msgbox MauvilleCity_PokemonCenter_1F_Text_IllSingThisSongForAWhile, MSGBOX_DEFAULT release end @@ -73,7 +73,7 @@ MauvilleCity_PokemonCenter_1F_EventScript_Hipster:: faceplayer setflag FLAG_SYS_HIPSTER_MEET msgbox MauvilleCity_PokemonCenter_1F_Text_TeachWhatsHipAndHappening, MSGBOX_DEFAULT - special ScrSpecial_GetHipsterSpokenFlag + special GetHipsterSpokenFlag compare VAR_RESULT, FALSE goto_if_eq MauvilleCity_PokemonCenter_1F_EventScript_TryTeachWord msgbox MauvilleCity_PokemonCenter_1F_Text_IAlreadyTaughtYou, MSGBOX_DEFAULT @@ -81,7 +81,7 @@ MauvilleCity_PokemonCenter_1F_EventScript_Hipster:: end MauvilleCity_PokemonCenter_1F_EventScript_TryTeachWord:: - special ScrSpecial_HipsterTeachWord + special HipsterTryTeachWord compare VAR_RESULT, TRUE goto_if_eq MauvilleCity_PokemonCenter_1F_EventScript_TeachWord msgbox MauvilleCity_PokemonCenter_1F_Text_IveGotNothingNewToTeach, MSGBOX_DEFAULT @@ -90,7 +90,7 @@ MauvilleCity_PokemonCenter_1F_EventScript_TryTeachWord:: MauvilleCity_PokemonCenter_1F_EventScript_TeachWord:: msgbox MauvilleCity_PokemonCenter_1F_Text_HaveYouHeardOfPhrase, MSGBOX_DEFAULT - special ScrSpecial_SetHipsterSpokenFlag + special SetHipsterSpokenFlag release end @@ -160,7 +160,7 @@ MauvilleCity_PokemonCenter_1F_EventScript_Trader:: msgbox MauvilleCity_PokemonCenter_1F_Text_WantToTradeDecor, MSGBOX_YESNO compare VAR_RESULT, NO goto_if_eq MauvilleCity_PokemonCenter_1F_EventScript_DeclineTrade - special ScrSpecial_GetTraderTradedFlag + special GetTraderTradedFlag compare VAR_RESULT, TRUE goto_if_eq MauvilleCity_PokemonCenter_1F_EventScript_AlreadyTraded message MauvilleCity_PokemonCenter_1F_Text_PickADecorItem @@ -179,7 +179,7 @@ MauvilleCity_PokemonCenter_1F_EventScript_AlreadyTraded:: end MauvilleCity_PokemonCenter_1F_EventScript_PickDecorToReceive:: - special ScrSpecial_TraderMenuGetDecoration + special TraderMenuGetDecoration waitstate compare VAR_0x8004, 0 goto_if_eq MauvilleCity_PokemonCenter_1F_EventScript_CancelPickDecor @@ -188,7 +188,7 @@ MauvilleCity_PokemonCenter_1F_EventScript_PickDecorToReceive:: msgbox MauvilleCity_PokemonCenter_1F_Text_OnceBelongedToPlayerDoYouWantIt, MSGBOX_YESNO compare VAR_RESULT, NO goto_if_eq MauvilleCity_PokemonCenter_1F_EventScript_PickDifferentDecor - special ScrSpecial_DoesPlayerHaveNoDecorations + special DoesPlayerHaveNoDecorations compare VAR_RESULT, TRUE goto_if_eq MauvilleCity_PokemonCenter_1F_EventScript_DontHaveAnyDecor goto MauvilleCity_PokemonCenter_1F_EventScript_PickDecorToGive @@ -218,19 +218,19 @@ MauvilleCity_PokemonCenter_1F_EventScript_DontHaveAnyDecor:: MauvilleCity_PokemonCenter_1F_EventScript_PickDecorToGive:: msgbox MauvilleCity_PokemonCenter_1F_Text_PickTheDecorToTrade, MSGBOX_DEFAULT - special ScrSpecial_TraderMenuGiveDecoration + special TraderShowDecorationMenu waitstate compare VAR_0x8006, 0 goto_if_eq MauvilleCity_PokemonCenter_1F_EventScript_CancelGiveDecor compare VAR_0x8006, 0xFFFF goto_if_eq MauvilleCity_PokemonCenter_1F_EventScript_DecorInUse - special ScrSpecial_IsDecorationFull + special IsDecorationCategoryFull compare VAR_RESULT, TRUE goto_if_eq MauvilleCity_PokemonCenter_1F_EventScript_NoRoomForDecor msgbox MauvilleCity_PokemonCenter_1F_Text_SoWellTradeTheseDecor, MSGBOX_YESNO compare VAR_RESULT, NO goto_if_eq MauvilleCity_PokemonCenter_1F_EventScript_PickDecorToGive - special ScrSpecial_TraderDoDecorationTrade + special TraderDoDecorationTrade msgbox MauvilleCity_PokemonCenter_1F_Text_SendDecorToYourPC, MSGBOX_DEFAULT release end @@ -818,20 +818,20 @@ MauvilleCity_PokemonCenter_1F_EventScript_Storyteller:: msgbox MauvilleCity_PokemonCenter_1F_Text_WillYouHearMyTale, MSGBOX_YESNO compare VAR_RESULT, NO goto_if_eq MauvilleCity_PokemonCenter_1F_EventScript_DeclineStoryteller - specialvar VAR_RESULT, ScrSpecial_StorytellerGetFreeStorySlot + specialvar VAR_RESULT, StorytellerGetFreeStorySlot compare VAR_RESULT, 0 goto_if_eq MauvilleCity_PokemonCenter_1F_EventScript_KnowNoTales message MauvilleCity_PokemonCenter_1F_Text_WhichTaleToTell waitmessage - special ScrSpecial_StorytellerStoryListMenu + special StorytellerStoryListMenu waitstate compare VAR_RESULT, 0 goto_if_eq MauvilleCity_PokemonCenter_1F_EventScript_CancelStorySelection setvar VAR_0x8008, 1 - special ScrSpecial_StorytellerDisplayStory + special Script_StorytellerDisplayStory waitmessage waitbuttonpress - specialvar VAR_RESULT, ScrSpecial_StorytellerUpdateStat + specialvar VAR_RESULT, StorytellerUpdateStat compare VAR_RESULT, 0 goto_if_eq MauvilleCity_PokemonCenter_1F_EventScript_AreThereOtherTales goto MauvilleCity_PokemonCenter_1F_EventScript_TellPlayersTale @@ -842,7 +842,7 @@ MauvilleCity_PokemonCenter_1F_EventScript_CancelStorySelection:: MauvilleCity_PokemonCenter_1F_EventScript_AreThereOtherTales:: msgbox MauvilleCity_PokemonCenter_1F_Text_CouldThereBeOtherLegends, MSGBOX_DEFAULT - specialvar VAR_RESULT, ScrSpecial_HasStorytellerAlreadyRecorded + specialvar VAR_RESULT, HasStorytellerAlreadyRecorded compare VAR_RESULT, TRUE goto_if_eq MauvilleCity_PokemonCenter_1F_EventScript_StorytellerEnd goto MauvilleCity_PokemonCenter_1F_EventScript_DoYouHaveAnyTales @@ -853,7 +853,7 @@ MauvilleCity_PokemonCenter_1F_EventScript_DoYouHaveAnyTales:: msgbox MauvilleCity_PokemonCenter_1F_Text_HaveYouAnyLegendaryTales, MSGBOX_YESNO compare VAR_RESULT, NO goto_if_eq MauvilleCity_PokemonCenter_1F_EventScript_DeclineStoryteller - specialvar VAR_RESULT, ScrSpecial_StorytellerInitializeRandomStat + specialvar VAR_RESULT, Script_StorytellerInitializeRandomStat compare VAR_RESULT, 1 goto_if_eq MauvilleCity_PokemonCenter_1F_EventScript_TellPlayersTale msgbox MauvilleCity_PokemonCenter_1F_Text_NotWorthyOfLegend, MSGBOX_DEFAULT @@ -909,7 +909,7 @@ MauvilleCity_PokemonCenter_1F_EventScript_Giddy:: end MauvilleCity_PokemonCenter_1F_EventScript_TryTellTale:: - special ScrSpecial_GiddyShouldTellAnotherTale + special GiddyShouldTellAnotherTale compare VAR_RESULT, TRUE goto_if_eq MauvilleCity_PokemonCenter_1F_EventScript_GiddyTellTale compare VAR_RESULT, FALSE @@ -917,7 +917,7 @@ MauvilleCity_PokemonCenter_1F_EventScript_TryTellTale:: end MauvilleCity_PokemonCenter_1F_EventScript_TryTellNewTale:: - special ScrSpecial_GiddyShouldTellAnotherTale + special GiddyShouldTellAnotherTale compare VAR_RESULT, TRUE goto_if_eq MauvilleCity_PokemonCenter_1F_EventScript_GiddyStartNewTale compare VAR_RESULT, FALSE @@ -929,15 +929,16 @@ MauvilleCity_PokemonCenter_1F_EventScript_GiddyStartNewTale:: goto MauvilleCity_PokemonCenter_1F_EventScript_GiddyTellTale end -@ Regardless of whether yes or no is selected below, Giddy will continue to tell stories until he's told 10 +@ Giddy will continue to tell stories regardless of whether yes or no is selected below. +@ Each story there is a 10% chance it will be his last. Otherwise he will stop at 10 stories. MauvilleCity_PokemonCenter_1F_EventScript_GiddyTellTale:: - special ScrSpecial_GenerateGiddyLine + special GenerateGiddyLine special ShowFieldMessageStringVar4 waitmessage yesnobox 20, 8 - compare VAR_RESULT, 1 + compare VAR_RESULT, YES goto_if_eq MauvilleCity_PokemonCenter_1F_EventScript_TryTellNewTale - compare VAR_RESULT, 0 + compare VAR_RESULT, NO goto_if_eq MauvilleCity_PokemonCenter_1F_EventScript_TryTellNewTale end diff --git a/data/specials.inc b/data/specials.inc index 81b25c14d..0b053b774 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -108,28 +108,28 @@ gSpecials:: def_special DoWateringBerryTreeAnim def_special ShowEasyChatScreen def_special ShowEasyChatProfile - def_special ScrSpecial_GetCurrentMauvilleMan - def_special ScrSpecial_HasBardSongBeenChanged - def_special ScrSpecial_SaveBardSongLyrics - def_special ScrSpecial_GetHipsterSpokenFlag - def_special ScrSpecial_SetHipsterSpokenFlag - def_special ScrSpecial_HipsterTeachWord - def_special ScrSpecial_PlayBardSong - def_special ScrSpecial_SetMauvilleOldManObjEventGfx - def_special ScrSpecial_GenerateGiddyLine - def_special ScrSpecial_GiddyShouldTellAnotherTale - def_special ScrSpecial_StorytellerGetFreeStorySlot - def_special ScrSpecial_StorytellerDisplayStory - def_special ScrSpecial_StorytellerStoryListMenu - def_special ScrSpecial_StorytellerUpdateStat - def_special ScrSpecial_StorytellerInitializeRandomStat - def_special ScrSpecial_HasStorytellerAlreadyRecorded - def_special ScrSpecial_TraderMenuGetDecoration - def_special ScrSpecial_GetTraderTradedFlag - def_special ScrSpecial_DoesPlayerHaveNoDecorations - def_special ScrSpecial_IsDecorationFull - def_special ScrSpecial_TraderMenuGiveDecoration - def_special ScrSpecial_TraderDoDecorationTrade + def_special Script_GetCurrentMauvilleMan + def_special HasBardSongBeenChanged + def_special SaveBardSongLyrics + def_special GetHipsterSpokenFlag + def_special SetHipsterSpokenFlag + def_special HipsterTryTeachWord + def_special PlayBardSong + def_special SetMauvilleOldManObjEventGfx + def_special GenerateGiddyLine + def_special GiddyShouldTellAnotherTale + def_special StorytellerGetFreeStorySlot + def_special Script_StorytellerDisplayStory + def_special StorytellerStoryListMenu + def_special StorytellerUpdateStat + def_special Script_StorytellerInitializeRandomStat + def_special HasStorytellerAlreadyRecorded + def_special TraderMenuGetDecoration + def_special GetTraderTradedFlag + def_special DoesPlayerHaveNoDecorations + def_special IsDecorationCategoryFull + def_special TraderShowDecorationMenu + def_special TraderDoDecorationTrade def_special GetSeedotSizeRecordInfo def_special CompareSeedotSize def_special GetLotadSizeRecordInfo diff --git a/include/constants/global.h b/include/constants/global.h index 1cece7975..6d3fa936d 100644 --- a/include/constants/global.h +++ b/include/constants/global.h @@ -95,6 +95,7 @@ #define BARD_SONG_LENGTH 6 #define NUM_STORYTELLER_TALES 4 #define NUM_TRADER_ITEMS 4 +#define GIDDY_MAX_TALES 10 #define OPTIONS_BUTTON_MODE_NORMAL 0 #define OPTIONS_BUTTON_MODE_LR 1 diff --git a/include/global.h b/include/global.h index d14aa60f4..dcec2c4db 100644 --- a/include/global.h +++ b/include/global.h @@ -639,7 +639,7 @@ struct MauvilleManGiddy /*0x00*/ u8 id; /*0x01*/ u8 taleCounter; /*0x02*/ u8 questionNum; - /*0x04*/ u16 randomWords[10]; + /*0x04*/ u16 randomWords[GIDDY_MAX_TALES]; /*0x18*/ u8 questionList[8]; /*0x20*/ u8 language; }; /*size = 0x2C*/ diff --git a/include/mauville_old_man.h b/include/mauville_old_man.h index 603d585da..23a3cabfb 100644 --- a/include/mauville_old_man.h +++ b/include/mauville_old_man.h @@ -5,7 +5,7 @@ extern struct BardSong gBardSong; void SetMauvilleOldMan(void); u8 GetCurrentMauvilleOldMan(void); -void ScrSpecial_SetMauvilleOldManObjEventGfx(void); +void SetMauvilleOldManObjEventGfx(void); u8 sub_81201C8(void); void SanitizeMauvilleOldManForRuby(OldMan *dest); void sub_8120670(void); diff --git a/include/wild_encounter.h b/include/wild_encounter.h index 55bbaa7dd..09525beff 100644 --- a/include/wild_encounter.h +++ b/include/wild_encounter.h @@ -33,7 +33,6 @@ extern const struct WildPokemonHeader gWildMonHeaders[]; void DisableWildEncounters(bool8 disabled); bool8 StandardWildEncounter(u16 currMetaTileBehavior, u16 previousMetaTileBehavior); -void ScrSpecial_RockSmashWildEncounter(void); bool8 SweetScentWildEncounter(void); bool8 DoesCurrentMapHaveFishingMons(void); void FishingWildEncounter(u8 rod); diff --git a/src/mauville_old_man.c b/src/mauville_old_man.c index d3c41236c..d202bc638 100644 --- a/src/mauville_old_man.c +++ b/src/mauville_old_man.c @@ -21,12 +21,11 @@ #include "field_message_box.h" #include "script_menu.h" #include "trader.h" +#include "m4a.h" #include "constants/mauville_old_man.h" #define CHAR_SONG_WORD_SEPARATOR 0x37 -extern struct MusicPlayerInfo gMPlayInfo_SE2; - static void InitGiddyTaleList(void); static void StartBardSong(bool8 useTemporaryLyrics); static void Task_BardSong(u8 taskId); @@ -120,46 +119,41 @@ void SetMauvilleOldMan(void) // Determine man based on the last digit of the player's trainer ID. switch ((trainerId % 10) / 2) { - case MAUVILLE_MAN_BARD: - SetupBard(); - break; - case MAUVILLE_MAN_HIPSTER: - SetupHipster(); - break; - case MAUVILLE_MAN_TRADER: - SetupTrader(); - break; - case MAUVILLE_MAN_STORYTELLER: - SetupStoryteller(); - break; - case MAUVILLE_MAN_GIDDY: - SetupGiddy(); - break; + case MAUVILLE_MAN_BARD: + SetupBard(); + break; + case MAUVILLE_MAN_HIPSTER: + SetupHipster(); + break; + case MAUVILLE_MAN_TRADER: + SetupTrader(); + break; + case MAUVILLE_MAN_STORYTELLER: + SetupStoryteller(); + break; + case MAUVILLE_MAN_GIDDY: + SetupGiddy(); + break; } - ScrSpecial_SetMauvilleOldManObjEventGfx(); + SetMauvilleOldManObjEventGfx(); } u8 GetCurrentMauvilleOldMan(void) { - struct MauvilleManCommon *common = &gSaveBlock1Ptr->oldMan.common; - - return common->id; + return gSaveBlock1Ptr->oldMan.common.id; } -void ScrSpecial_GetCurrentMauvilleMan(void) +void Script_GetCurrentMauvilleMan(void) { gSpecialVar_Result = GetCurrentMauvilleOldMan(); } -void ScrSpecial_HasBardSongBeenChanged(void) +void HasBardSongBeenChanged(void) { - u16 *scriptResult = &gSpecialVar_Result; // why?? - struct MauvilleManBard *bard = &gSaveBlock1Ptr->oldMan.bard; - - *scriptResult = bard->hasChangedSong; + gSpecialVar_Result = (&gSaveBlock1Ptr->oldMan.bard)->hasChangedSong; } -void ScrSpecial_SaveBardSongLyrics(void) +void SaveBardSongLyrics(void) { u16 i; struct MauvilleManBard *bard = &gSaveBlock1Ptr->oldMan.bard; @@ -225,28 +219,23 @@ static void PrepareSongText(void) } } -void ScrSpecial_PlayBardSong(void) +void PlayBardSong(void) { StartBardSong(gSpecialVar_0x8004); ScriptContext1_Stop(); } -void ScrSpecial_GetHipsterSpokenFlag(void) +void GetHipsterSpokenFlag(void) { - u16 *scriptResult = &gSpecialVar_Result; // again?? - struct MauvilleManHipster *hipster = &gSaveBlock1Ptr->oldMan.hipster; - - *scriptResult = hipster->alreadySpoken; + gSpecialVar_Result = (&gSaveBlock1Ptr->oldMan.hipster)->alreadySpoken; } -void ScrSpecial_SetHipsterSpokenFlag(void) +void SetHipsterSpokenFlag(void) { - struct MauvilleManHipster *hipster = &gSaveBlock1Ptr->oldMan.hipster; - - hipster->alreadySpoken = TRUE; + (&gSaveBlock1Ptr->oldMan.hipster)->alreadySpoken = TRUE; } -void ScrSpecial_HipsterTeachWord(void) +void HipsterTryTeachWord(void) { u16 phrase = GetNewHipsterPhraseToTeach(); @@ -261,11 +250,11 @@ void ScrSpecial_HipsterTeachWord(void) } } -void ScrSpecial_GiddyShouldTellAnotherTale(void) +void GiddyShouldTellAnotherTale(void) { struct MauvilleManGiddy *giddy = &gSaveBlock1Ptr->oldMan.giddy; - if (giddy->taleCounter == 10) + if (giddy->taleCounter == GIDDY_MAX_TALES) { gSpecialVar_Result = FALSE; giddy->taleCounter = 0; @@ -276,7 +265,7 @@ void ScrSpecial_GiddyShouldTellAnotherTale(void) } } -void ScrSpecial_GenerateGiddyLine(void) +void GenerateGiddyLine(void) { struct MauvilleManGiddy *giddy = &gSaveBlock1Ptr->oldMan.giddy; @@ -300,7 +289,7 @@ void ScrSpecial_GenerateGiddyLine(void) } if (!(Random() % 10)) - giddy->taleCounter = 10; + giddy->taleCounter = GIDDY_MAX_TALES; else giddy->taleCounter++; @@ -310,7 +299,7 @@ void ScrSpecial_GenerateGiddyLine(void) static void InitGiddyTaleList(void) { struct MauvilleManGiddy *giddy = &gSaveBlock1Ptr->oldMan.giddy; - u16 arr[][2] = { + u16 wordGroupsAndCount[][2] = { {EC_GROUP_POKEMON, 0}, {EC_GROUP_LIFESTYLE, 0}, {EC_GROUP_HOBBIES, 0}, @@ -323,27 +312,25 @@ static void InitGiddyTaleList(void) u16 r7; u16 r1; + // Shuffle question list for (i = 0; i < 8; i++) giddy->questionList[i] = i; - for (i = 0; i < 8; i++) { r1 = Random() % (i + 1); - r7 = giddy->questionList[i]; - giddy->questionList[i] = giddy->questionList[r1]; - giddy->questionList[r1] = r7; + SWAP(giddy->questionList[i], giddy->questionList[r1], r7); } r10 = 0; for (i = 0; i < 6; i++) { - arr[i][1] = EasyChat_GetNumWordsInGroup(arr[i][0]); - r10 += arr[i][1]; + wordGroupsAndCount[i][1] = EasyChat_GetNumWordsInGroup(wordGroupsAndCount[i][0]); + r10 += wordGroupsAndCount[i][1]; } giddy->questionNum = 0; r7 = 0; - for (i = 0; i < 10; i++) + for (i = 0; i < GIDDY_MAX_TALES; i++) { r1 = Random() % 10; if (r1 < 3 && r7 < 8) @@ -355,26 +342,22 @@ static void InitGiddyTaleList(void) { s16 r2 = Random() % r10; for (r1 = 0; i < 6; r1++) - if ((r2 -= arr[r1][1]) <= 0) + if ((r2 -= wordGroupsAndCount[r1][1]) <= 0) break; if (r1 == 6) r1 = 0; - giddy->randomWords[i] = GetRandomEasyChatWordFromUnlockedGroup(arr[r1][0]); + giddy->randomWords[i] = GetRandomEasyChatWordFromUnlockedGroup(wordGroupsAndCount[r1][0]); } } } static void ResetBardFlag(void) { - struct MauvilleManBard *bard = &gSaveBlock1Ptr->oldMan.bard; - - bard->hasChangedSong = FALSE; + (&gSaveBlock1Ptr->oldMan.bard)->hasChangedSong = FALSE; } static void ResetHipsterFlag(void) { - struct MauvilleManHipster *hipster = &gSaveBlock1Ptr->oldMan.hipster; - - hipster->alreadySpoken = FALSE; + (&gSaveBlock1Ptr->oldMan.hipster)->alreadySpoken = FALSE; } static void ResetTraderFlag(void) @@ -391,22 +374,22 @@ void ResetMauvilleOldManFlag(void) { switch (GetCurrentMauvilleOldMan()) { - case MAUVILLE_MAN_BARD: - ResetBardFlag(); - break; - case MAUVILLE_MAN_HIPSTER: - ResetHipsterFlag(); - break; - case MAUVILLE_MAN_STORYTELLER: - ResetStorytellerFlag(); - break; - case MAUVILLE_MAN_TRADER: - ResetTraderFlag(); - break; - case MAUVILLE_MAN_GIDDY: - break; + case MAUVILLE_MAN_BARD: + ResetBardFlag(); + break; + case MAUVILLE_MAN_HIPSTER: + ResetHipsterFlag(); + break; + case MAUVILLE_MAN_STORYTELLER: + ResetStorytellerFlag(); + break; + case MAUVILLE_MAN_TRADER: + ResetTraderFlag(); + break; + case MAUVILLE_MAN_GIDDY: + break; } - ScrSpecial_SetMauvilleOldManObjEventGfx(); + SetMauvilleOldManObjEventGfx(); } @@ -430,15 +413,15 @@ static void EnableTextPrinters(void) gDisableTextPrinters = FALSE; } -static void BardSong_DisableTextPrinters(struct TextPrinterTemplate * printer, u16 a1) +static void DisableTextPrinters(struct TextPrinterTemplate * printer, u16 a1) { gDisableTextPrinters = TRUE; } -static void sub_8120708(const u8 * src) +static void sub_8120708(const u8 * str) { DrawDialogueFrame(0, 0); - AddTextPrinterParameterized(0, 1, src, 0, 1, 1, BardSong_DisableTextPrinters); + AddTextPrinterParameterized(0, 1, str, 0, 1, 1, DisableTextPrinters); gDisableTextPrinters = TRUE; CopyWindowToVram(0, 3); } @@ -447,233 +430,233 @@ static void BardSing(struct Task *task, struct BardSong *song) { switch (task->tState) { - case 0: // Initialize song - { - struct MauvilleManBard *bard = &gSaveBlock1Ptr->oldMan.bard; - u16 *lyrics; - s32 i; + case 0: // Initialize song + { + struct MauvilleManBard *bard = &gSaveBlock1Ptr->oldMan.bard; + u16 *lyrics; + s32 i; - // Copy lyrics - if (gSpecialVar_0x8004 == 0) - lyrics = bard->songLyrics; - else - lyrics = bard->temporaryLyrics; - for (i = 0; i < BARD_SONG_LENGTH; i++) - song->lyrics[i] = lyrics[i]; - song->currWord = 0; - } - break; - case 1: // Wait for BGM to end - break; - case 2: // Initialize word + // Copy lyrics + if (gSpecialVar_0x8004 == 0) + lyrics = bard->songLyrics; + else + lyrics = bard->temporaryLyrics; + for (i = 0; i < BARD_SONG_LENGTH; i++) + song->lyrics[i] = lyrics[i]; + song->currWord = 0; + } + break; + case 1: // Wait for BGM to end + break; + case 2: // Initialize word + { + u16 word = song->lyrics[song->currWord]; + song->sound = GetWordSounds(word); + GetWordPhonemes(song, MACRO1(word)); + song->currWord++; + if (song->sound->var00 != 0xFF) + song->state = 0; + else { - u16 word = song->lyrics[song->currWord]; - song->sound = GetWordSounds(word); - GetWordPhonemes(song, MACRO1(word)); - song->currWord++; - if (song->sound->var00 != 0xFF) - song->state = 0; - else + song->state = 3; + song->phonemeTimer = 2; + } + break; + } + case 3: + case 4: + { + const struct BardSound *sound = &song->sound[song->currPhoneme]; + + switch (song->state) + { + case 0: + song->phonemeTimer = song->phonemes[song->currPhoneme].length; + if (sound->var00 <= 50) { - song->state = 3; - song->phonemeTimer = 2; + u8 num = sound->var00 / 3; + m4aSongNumStart(PH_TRAP_HELD + 3 * num); + } + song->state = 2; + song->phonemeTimer--; + break; + case 2: + song->state = 1; + if (sound->var00 <= 50) + { + song->volume = 0x100 + sound->volume * 16; + m4aMPlayVolumeControl(&gMPlayInfo_SE2, TRACKS_ALL, song->volume); + song->pitch = 0x200 + song->phonemes[song->currPhoneme].pitch; + m4aMPlayPitchControl(&gMPlayInfo_SE2, TRACKS_ALL, song->pitch); + } + break; + case 1: + if (song->voiceInflection > 10) + song->volume -= 2; + if (song->voiceInflection & 1) + song->pitch += 64; + else + song->pitch -= 64; + m4aMPlayVolumeControl(&gMPlayInfo_SE2, TRACKS_ALL, song->volume); + m4aMPlayPitchControl(&gMPlayInfo_SE2, TRACKS_ALL, song->pitch); + song->voiceInflection++; + song->phonemeTimer--; + if (song->phonemeTimer == 0) + { + song->currPhoneme++; + if (song->currPhoneme != 6 && song->sound[song->currPhoneme].var00 != 0xFF) + song->state = 0; + else + { + song->state = 3; + song->phonemeTimer = 2; + } } break; - } case 3: - case 4: - { - const struct BardSound *sound = &song->sound[song->currPhoneme]; - - switch (song->state) + song->phonemeTimer--; + if (song->phonemeTimer == 0) { - case 0: - song->phonemeTimer = song->phonemes[song->currPhoneme].length; - if (sound->var00 <= 50) - { - u8 num = sound->var00 / 3; - m4aSongNumStart(PH_TRAP_HELD + 3 * num); - } - song->state = 2; - song->phonemeTimer--; - break; - case 2: - song->state = 1; - if (sound->var00 <= 50) - { - song->volume = 0x100 + sound->volume * 16; - m4aMPlayVolumeControl(&gMPlayInfo_SE2, TRACKS_ALL, song->volume); - song->pitch = 0x200 + song->phonemes[song->currPhoneme].pitch; - m4aMPlayPitchControl(&gMPlayInfo_SE2, TRACKS_ALL, song->pitch); - } - break; - case 1: - if (song->voiceInflection > 10) - song->volume -= 2; - if (song->voiceInflection & 1) - song->pitch += 64; - else - song->pitch -= 64; - m4aMPlayVolumeControl(&gMPlayInfo_SE2, TRACKS_ALL, song->volume); - m4aMPlayPitchControl(&gMPlayInfo_SE2, TRACKS_ALL, song->pitch); - song->voiceInflection++; - song->phonemeTimer--; - if (song->phonemeTimer == 0) - { - song->currPhoneme++; - if (song->currPhoneme != 6 && song->sound[song->currPhoneme].var00 != 0xFF) - song->state = 0; - else - { - song->state = 3; - song->phonemeTimer = 2; - } - } - break; - case 3: - song->phonemeTimer--; - if (song->phonemeTimer == 0) - { - m4aMPlayStop(&gMPlayInfo_SE2); - song->state = 4; - } - break; + m4aMPlayStop(&gMPlayInfo_SE2); + song->state = 4; } + break; } - break; - case 5: - break; + } + break; + case 5: + break; } } static void Task_BardSong(u8 taskId) { - struct Task *task = &gTasks[taskId]; // r5 + struct Task *task = &gTasks[taskId]; BardSing(task, &gBardSong); switch (task->tState) { - case 0: // Initialize song - PrepareSongText(); - sub_8120708(gStringVar4); - task->data[1] = 0; - task->data[2] = 0; - task->tCharIndex = 0; - task->tCurrWord = 0; - FadeOutBGMTemporarily(4); - task->tState = 1; - break; - case 1: // Wait for BGM to end - if (IsBGMPausedOrStopped()) - task->tState = 2; - break; - case 2: // Initialize word + case 0: // Initialize song + PrepareSongText(); + sub_8120708(gStringVar4); + task->data[1] = 0; + task->data[2] = 0; + task->tCharIndex = 0; + task->tCurrWord = 0; + FadeOutBGMTemporarily(4); + task->tState = 1; + break; + case 1: // Wait for BGM to end + if (IsBGMPausedOrStopped()) + task->tState = 2; + break; + case 2: // Initialize word + { + struct MauvilleManBard *bard = &gSaveBlock1Ptr->oldMan.bard; + u8 *str = gStringVar4 + task->tCharIndex; + u16 wordLen = 0; + + while (*str != CHAR_SPACE + && *str != CHAR_NEWLINE + && *str != EXT_CTRL_CODE_BEGIN + && *str != EOS) { - struct MauvilleManBard *bard = &gSaveBlock1Ptr->oldMan.bard; - u8 *str = gStringVar4 + task->tCharIndex; - u16 wordLen = 0; + str++; + wordLen++; + } + if (!task->tUseTemporaryLyrics) + sUnknownBardRelated = MACRO2(bard->songLyrics[task->tCurrWord]); + else + sUnknownBardRelated = MACRO2(bard->temporaryLyrics[task->tCurrWord]); - while (*str != CHAR_SPACE - && *str != CHAR_NEWLINE - && *str != EXT_CTRL_CODE_BEGIN - && *str != EOS) + gBardSong.length /= wordLen; + if (gBardSong.length <= 0) + gBardSong.length = 1; + task->tCurrWord++; + + if (task->data[2] == 0) + { + task->tState = 3; + task->data[1] = 0; + } + else + { + task->tState = 5; + task->data[1] = 0; + } + } + break; + case 5: + if (task->data[2] == 0) + task->tState = 3; + else + task->data[2]--; + break; + case 3: + if (gStringVar4[task->tCharIndex] == EOS) + { + FadeInBGM(6); + m4aMPlayFadeOutTemporarily(&gMPlayInfo_SE2, 2); + EnableBothScriptContexts(); + DestroyTask(taskId); + } + else if (gStringVar4[task->tCharIndex] == CHAR_SPACE) + { + + EnableTextPrinters(); + task->tCharIndex++; + task->tState = 2; + task->data[2] = 0; + } + else if (gStringVar4[task->tCharIndex] == CHAR_NEWLINE) + { + task->tCharIndex++; + task->tState = 2; + task->data[2] = 0; + } + else if (gStringVar4[task->tCharIndex] == EXT_CTRL_CODE_BEGIN) + { + task->tCharIndex += 2; // skip over control codes + task->tState = 2; + task->data[2] = 8; + } + else if (gStringVar4[task->tCharIndex] == CHAR_SONG_WORD_SEPARATOR) + { + gStringVar4[task->tCharIndex] = CHAR_SPACE; // restore it back to a space + EnableTextPrinters(); + task->tCharIndex++; + task->data[2] = 0; + } + else + { + switch (task->data[1]) { - str++; - wordLen++; - } - if (!task->tUseTemporaryLyrics) - sUnknownBardRelated = MACRO2(bard->songLyrics[task->tCurrWord]); - else - sUnknownBardRelated = MACRO2(bard->temporaryLyrics[task->tCurrWord]); - - gBardSong.length /= wordLen; - if (gBardSong.length <= 0) - gBardSong.length = 1; - task->tCurrWord++; - - if (task->data[2] == 0) - { - task->tState = 3; - task->data[1] = 0; - } - else - { - task->tState = 5; + case 0: + EnableTextPrinters(); + task->data[1]++; + break; + case 1: + task->data[1]++; + break; + case 2: + task->tCharIndex++; task->data[1] = 0; + task->data[2] = gBardSong.length; + task->tState = 4; + break; } } - break; - case 5: - if (task->data[2] == 0) - task->tState = 3; - else - task->data[2]--; - break; - case 3: - if (gStringVar4[task->tCharIndex] == EOS) - { - FadeInBGM(6); - m4aMPlayFadeOutTemporarily(&gMPlayInfo_SE2, 2); - EnableBothScriptContexts(); - DestroyTask(taskId); - } - else if (gStringVar4[task->tCharIndex] == CHAR_SPACE) - { - - EnableTextPrinters(); - task->tCharIndex++; - task->tState = 2; - task->data[2] = 0; - } - else if (gStringVar4[task->tCharIndex] == CHAR_NEWLINE) - { - task->tCharIndex++; - task->tState = 2; - task->data[2] = 0; - } - else if (gStringVar4[task->tCharIndex] == EXT_CTRL_CODE_BEGIN) - { - task->tCharIndex += 2; // skip over control codes - task->tState = 2; - task->data[2] = 8; - } - else if (gStringVar4[task->tCharIndex] == CHAR_SONG_WORD_SEPARATOR) - { - gStringVar4[task->tCharIndex] = CHAR_SPACE; // restore it back to a space - EnableTextPrinters(); - task->tCharIndex++; - task->data[2] = 0; - } - else - { - switch (task->data[1]) - { - case 0: - EnableTextPrinters(); - task->data[1]++; - break; - case 1: - task->data[1]++; - break; - case 2: - task->tCharIndex++; - task->data[1] = 0; - task->data[2] = gBardSong.length; - task->tState = 4; - break; - } - } - break; - case 4: - task->data[2]--; - if (task->data[2] == 0) - task->tState = 3; - break; + break; + case 4: + task->data[2]--; + if (task->data[2] == 0) + task->tState = 3; + break; } RunTextPrintersAndIsPrinter0Active(); } -void ScrSpecial_SetMauvilleOldManObjEventGfx(void) +void SetMauvilleOldManObjEventGfx(void) { VarSet(VAR_OBJ_GFX_ID_0, OBJ_EVENT_GFX_BARD); } @@ -720,76 +703,69 @@ void SanitizeMauvilleOldManForRuby(union OldMan * oldMan) } } -void sub_8120C0C(union OldMan * oldMan, u32 r8, u32 r7, u32 r3) +// Unused +static void SetMauvilleOldManLanguage(union OldMan * oldMan, u32 language1, u32 language2, u32 language3) { s32 i; switch (oldMan->common.id) { - case MAUVILLE_MAN_TRADER: - { - struct MauvilleOldManTrader * trader = &oldMan->trader; + case MAUVILLE_MAN_TRADER: + { + struct MauvilleOldManTrader * trader = &oldMan->trader; - for (i = 0; i < NUM_TRADER_ITEMS; i++) - { - if (IsStringJapanese(trader->playerNames[i])) - { - trader->language[i] = r8; - } - else - { - trader->language[i] = r7; - } - } - } - break; - case MAUVILLE_MAN_STORYTELLER: + for (i = 0; i < NUM_TRADER_ITEMS; i++) { - struct MauvilleManStoryteller * storyteller = &oldMan->storyteller; - - for (i = 0; i < NUM_STORYTELLER_TALES; i++) - { - if (IsStringJapanese(storyteller->trainerNames[i])) - { - storyteller->language[i] = r8; - } - else - { - storyteller->language[i] = r7; - } - } - } - break; - case MAUVILLE_MAN_BARD: - { - struct MauvilleManBard * bard = &oldMan->bard; - - if (r3 == LANGUAGE_JAPANESE) - bard->language = r8; + if (IsStringJapanese(trader->playerNames[i])) + trader->language[i] = language1; else - bard->language = r7; + trader->language[i] = language2; } - break; - case MAUVILLE_MAN_HIPSTER: - { - struct MauvilleManHipster * hipster = &oldMan->hipster; + } + break; + case MAUVILLE_MAN_STORYTELLER: + { + struct MauvilleManStoryteller * storyteller = &oldMan->storyteller; - if (r3 == LANGUAGE_JAPANESE) - hipster->language = r8; - else - hipster->language = r7; - } - break; - case MAUVILLE_MAN_GIDDY: + for (i = 0; i < NUM_STORYTELLER_TALES; i++) { - struct MauvilleManGiddy * giddy = &oldMan->giddy; - - if (r3 == LANGUAGE_JAPANESE) - giddy->language = r8; + if (IsStringJapanese(storyteller->trainerNames[i])) + storyteller->language[i] = language1; else - giddy->language = r7; + storyteller->language[i] = language2; } - break; + } + break; + case MAUVILLE_MAN_BARD: + { + struct MauvilleManBard * bard = &oldMan->bard; + + if (language3 == LANGUAGE_JAPANESE) + bard->language = language1; + else + bard->language = language2; + } + break; + case MAUVILLE_MAN_HIPSTER: + { + struct MauvilleManHipster * hipster = &oldMan->hipster; + + if (language3 == LANGUAGE_JAPANESE) + hipster->language = language1; + else + hipster->language = language2; + } + break; + case MAUVILLE_MAN_GIDDY: + { + struct MauvilleManGiddy * giddy = &oldMan->giddy; + + if (language3 == LANGUAGE_JAPANESE) + giddy->language = language1; + else + giddy->language = language2; + } + break; } } @@ -822,83 +798,83 @@ void SanitizeReceivedRubyOldMan(union OldMan * oldMan, u32 version, u32 language switch (oldMan->common.id) { - case MAUVILLE_MAN_TRADER: - { - struct MauvilleOldManTrader * trader = &oldMan->trader; - s32 i; + case MAUVILLE_MAN_TRADER: + { + struct MauvilleOldManTrader * trader = &oldMan->trader; + s32 i; - if (isRuby) + if (isRuby) + { + for (i = 0; i < NUM_TRADER_ITEMS; i++) { - for (i = 0; i < NUM_TRADER_ITEMS; i++) + u8 * str = trader->playerNames[i]; + if (str[0] == EXT_CTRL_CODE_BEGIN && str[1] == EXT_CTRL_CODE_JPN) { - u8 * str = trader->playerNames[i]; - if (str[0] == EXT_CTRL_CODE_BEGIN && str[1] == EXT_CTRL_CODE_JPN) - { - StripExtCtrlCodes(str); - trader->language[i] = LANGUAGE_JAPANESE; - } - else - trader->language[i] = language; + StripExtCtrlCodes(str); + trader->language[i] = LANGUAGE_JAPANESE; } + else + trader->language[i] = language; } - else + } + else + { + for (i = 0; i < NUM_TRADER_ITEMS; i++) { - for (i = 0; i < NUM_TRADER_ITEMS; i++) + if (trader->language[i] == LANGUAGE_JAPANESE) { - if (trader->language[i] == LANGUAGE_JAPANESE) - { - StripExtCtrlCodes(trader->playerNames[i]); - } + StripExtCtrlCodes(trader->playerNames[i]); } } } - break; - case MAUVILLE_MAN_STORYTELLER: + } + break; + case MAUVILLE_MAN_STORYTELLER: + { + + struct MauvilleManStoryteller * storyteller = &oldMan->storyteller; + s32 i; + + if (isRuby) { - - struct MauvilleManStoryteller * storyteller = &oldMan->storyteller; - s32 i; - - if (isRuby) + for (i = 0; i < NUM_STORYTELLER_TALES; i++) { - for (i = 0; i < NUM_STORYTELLER_TALES; i++) - { - if (storyteller->gameStatIDs[i] != 0) - storyteller->language[i] = language; - } + if (storyteller->gameStatIDs[i] != 0) + storyteller->language[i] = language; } } - break; - case MAUVILLE_MAN_BARD: - { - struct MauvilleManBard * bard = &oldMan->bard; + } + break; + case MAUVILLE_MAN_BARD: + { + struct MauvilleManBard * bard = &oldMan->bard; - if (isRuby) - { - bard->language = language; - } - } - break; - case MAUVILLE_MAN_HIPSTER: + if (isRuby) { - struct MauvilleManHipster * hipster = &oldMan->hipster; - - if (isRuby) - { - hipster->language = language; - } + bard->language = language; } - break; - case MAUVILLE_MAN_GIDDY: + } + break; + case MAUVILLE_MAN_HIPSTER: + { + struct MauvilleManHipster * hipster = &oldMan->hipster; + + if (isRuby) { - struct MauvilleManGiddy * giddy = &oldMan->giddy; - - if (isRuby) - { - giddy->language = language; - } + hipster->language = language; } - break; + } + break; + case MAUVILLE_MAN_GIDDY: + { + struct MauvilleManGiddy * giddy = &oldMan->giddy; + + if (isRuby) + { + giddy->language = language; + } + } + break; } } @@ -1260,9 +1236,8 @@ static void ScrambleStatList(u8 * arr, s32 count) { u32 a = Random() % count; u32 b = Random() % count; - u8 temp = arr[a]; - arr[a] = arr[b]; - arr[b] = temp; + u8 temp; + SWAP(arr[a], arr[b], temp); } } @@ -1354,63 +1329,63 @@ static void Task_StoryListMenu(u8 taskId) switch (task->data[0]) { - case 0: - PrintStoryList(); - task->data[0]++; - break; - case 1: - selection = Menu_ProcessInput(); - if (selection == MENU_NOTHING_CHOSEN) - break; - if (selection == MENU_B_PRESSED || selection == GetFreeStorySlot()) - { - gSpecialVar_Result = 0; - } - else - { - gSpecialVar_Result = 1; - sSelectedStory = selection; - } - ClearToTransparentAndRemoveWindow(sStorytellerWindowId); - DestroyTask(taskId); - EnableBothScriptContexts(); + case 0: + PrintStoryList(); + task->data[0]++; + break; + case 1: + selection = Menu_ProcessInput(); + if (selection == MENU_NOTHING_CHOSEN) break; + if (selection == MENU_B_PRESSED || selection == GetFreeStorySlot()) + { + gSpecialVar_Result = 0; + } + else + { + gSpecialVar_Result = 1; + sSelectedStory = selection; + } + ClearToTransparentAndRemoveWindow(sStorytellerWindowId); + DestroyTask(taskId); + EnableBothScriptContexts(); + break; } } // Sets gSpecialVar_Result to TRUE if player selected a story -void ScrSpecial_StorytellerStoryListMenu(void) +void StorytellerStoryListMenu(void) { CreateTask(Task_StoryListMenu, 80); } -void ScrSpecial_StorytellerDisplayStory(void) +void Script_StorytellerDisplayStory(void) { StorytellerDisplayStory(sSelectedStory); } -u8 ScrSpecial_StorytellerGetFreeStorySlot(void) +u8 StorytellerGetFreeStorySlot(void) { sStorytellerPtr = &gSaveBlock1Ptr->oldMan.storyteller; return GetFreeStorySlot(); } // Returns TRUE if stat has increased -bool8 ScrSpecial_StorytellerUpdateStat(void) +bool8 StorytellerUpdateStat(void) { - u8 r4; + u8 stat; sStorytellerPtr = &gSaveBlock1Ptr->oldMan.storyteller; - r4 = sStorytellerPtr->gameStatIDs[sSelectedStory]; + stat = sStorytellerPtr->gameStatIDs[sSelectedStory]; if (HasTrainerStatIncreased(sSelectedStory) == TRUE) { - StorytellerRecordNewStat(sSelectedStory, r4); + StorytellerRecordNewStat(sSelectedStory, stat); return TRUE; } return FALSE; } -bool8 ScrSpecial_HasStorytellerAlreadyRecorded(void) +bool8 HasStorytellerAlreadyRecorded(void) { sStorytellerPtr = &gSaveBlock1Ptr->oldMan.storyteller; @@ -1420,7 +1395,7 @@ bool8 ScrSpecial_HasStorytellerAlreadyRecorded(void) return TRUE; } -bool8 ScrSpecial_StorytellerInitializeRandomStat(void) +bool8 Script_StorytellerInitializeRandomStat(void) { sStorytellerPtr = &gSaveBlock1Ptr->oldMan.storyteller; return StorytellerInitializeRandomStat(); diff --git a/src/trader.c b/src/trader.c index f6d021dfe..98b4f464c 100644 --- a/src/trader.c +++ b/src/trader.c @@ -130,13 +130,13 @@ void Task_HandleGetDecorationMenuInput(u8 taskId) } } -void ScrSpecial_GetTraderTradedFlag(void) +void GetTraderTradedFlag(void) { struct MauvilleOldManTrader *trader = &gSaveBlock1Ptr->oldMan.trader; gSpecialVar_Result = trader->alreadyTraded; } -void ScrSpecial_DoesPlayerHaveNoDecorations(void) +void DoesPlayerHaveNoDecorations(void) { u8 i; @@ -151,7 +151,7 @@ void ScrSpecial_DoesPlayerHaveNoDecorations(void) gSpecialVar_Result = TRUE; } -void ScrSpecial_IsDecorationFull(void) +void IsDecorationCategoryFull(void) { gSpecialVar_Result = FALSE; if (gDecorations[gSpecialVar_0x8004].category != gDecorations[gSpecialVar_0x8006].category @@ -162,7 +162,7 @@ void ScrSpecial_IsDecorationFull(void) } } -void ScrSpecial_TraderMenuGiveDecoration(void) +void TraderShowDecorationMenu(void) { CreateTask(ShowDecorationCategoriesWindow, 0); } @@ -190,7 +190,7 @@ void ExitTraderMenu(u8 taskId) EnableBothScriptContexts(); } -void ScrSpecial_TraderDoDecorationTrade(void) +void TraderDoDecorationTrade(void) { struct MauvilleOldManTrader *trader = &gSaveBlock1Ptr->oldMan.trader; @@ -202,7 +202,7 @@ void ScrSpecial_TraderDoDecorationTrade(void) trader->alreadyTraded = TRUE; } -void ScrSpecial_TraderMenuGetDecoration(void) +void TraderMenuGetDecoration(void) { u8 taskId = CreateTask(Task_HandleGetDecorationMenuInput, 0); CreateAvailableDecorationsMenu(taskId); From 46dd10c87ba7abf8c10e5ab604a7c21e9beaebc3 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 18 Oct 2021 01:39:07 -0400 Subject: [PATCH 07/10] Clean up trainer_pokemon_sprites --- include/trainer_pokemon_sprites.h | 8 ++- src/hall_of_fame.c | 2 +- src/main_menu.c | 4 +- src/starter_choose.c | 2 +- src/trainer_pokemon_sprites.c | 96 +++++++++++-------------------- 5 files changed, 45 insertions(+), 67 deletions(-) diff --git a/include/trainer_pokemon_sprites.h b/include/trainer_pokemon_sprites.h index d4390608e..520268c47 100644 --- a/include/trainer_pokemon_sprites.h +++ b/include/trainer_pokemon_sprites.h @@ -1,8 +1,14 @@ #ifndef GUARD_TRAINER_POKEMON_SPRITES_H #define GUARD_TRAINER_POKEMON_SPRITES_H +// For the flags argument of CreateMonPicSprite_Affine +#define MON_PIC_AFFINE_BACK 0 +#define MON_PIC_AFFINE_FRONT 1 +#define MON_PIC_AFFINE_NONE 3 +#define F_MON_PIC_NO_AFFINE (1 << 7) + bool16 ResetAllPicSprites(void); -u16 CreatePicSprite2(u16 species, u32 otId, u32 personality, u8 flags, s16 x, s16 y, u8 paletteSlot, u16 paletteTag); +u16 CreateMonPicSprite_Affine(u16 species, u32 otId, u32 personality, u8 flags, s16 x, s16 y, u8 paletteSlot, u16 paletteTag); u16 CreateMonPicSprite_HandleDeoxys(u16 species, u32 otId, u32 personality, bool8 isFrontPic, s16 x, s16 y, u8 paletteSlot, u16 paletteTag); u16 FreeAndDestroyMonPicSprite(u16 spriteId); u16 CreateTrainerPicSprite(u16 species, bool8 isFrontPic, s16 x, s16 y, u8 paletteSlot, u16 paletteTag); diff --git a/src/hall_of_fame.c b/src/hall_of_fame.c index 3485f3ba3..571c55001 100644 --- a/src/hall_of_fame.c +++ b/src/hall_of_fame.c @@ -588,7 +588,7 @@ static void Task_Hof_DisplayMon(u8 taskId) if (currMon->species == SPECIES_EGG) destY += 10; - spriteId = CreatePicSprite2(currMon->species, currMon->tid, currMon->personality, 1, startX, startY, currMonId, TAG_NONE); + spriteId = CreateMonPicSprite_Affine(currMon->species, currMon->tid, currMon->personality, MON_PIC_AFFINE_FRONT, startX, startY, currMonId, TAG_NONE); gSprites[spriteId].tDestinationX = destX; gSprites[spriteId].tDestinationY = destY; gSprites[spriteId].data[0] = 0; diff --git a/src/main_menu.c b/src/main_menu.c index f6dff3d44..6553278e8 100644 --- a/src/main_menu.c +++ b/src/main_menu.c @@ -1871,9 +1871,9 @@ static void SpriteCB_MovePlayerDownWhileShrinking(struct Sprite *sprite) sprite->data[0] = y; } -static u8 NewGameBirchSpeech_CreateLotadSprite(u8 a, u8 b) +static u8 NewGameBirchSpeech_CreateLotadSprite(u8 x, u8 y) { - return CreatePicSprite2(SPECIES_LOTAD, SHINY_ODDS, 0, 1, a, b, 14, -1); + return CreateMonPicSprite_Affine(SPECIES_LOTAD, SHINY_ODDS, 0, MON_PIC_AFFINE_FRONT, x, y, 14, TAG_NONE); } static void AddBirchSpeechObjects(u8 taskId) diff --git a/src/starter_choose.c b/src/starter_choose.c index 37c334680..d14846130 100644 --- a/src/starter_choose.c +++ b/src/starter_choose.c @@ -635,7 +635,7 @@ static u8 CreatePokemonFrontSprite(u16 species, u8 x, u8 y) { u8 spriteId; - spriteId = CreatePicSprite2(species, SHINY_ODDS, 0, 1, x, y, 0xE, TAG_NONE); + spriteId = CreateMonPicSprite_Affine(species, SHINY_ODDS, 0, MON_PIC_AFFINE_FRONT, x, y, 14, TAG_NONE); gSprites[spriteId].oam.priority = 0; return spriteId; } diff --git a/src/trainer_pokemon_sprites.c b/src/trainer_pokemon_sprites.c index 9e30f636e..a7289677e 100644 --- a/src/trainer_pokemon_sprites.c +++ b/src/trainer_pokemon_sprites.c @@ -9,8 +9,6 @@ #include "pokemon.h" #include "constants/trainers.h" -// Static type declarations - struct PicData { u8 *frames; @@ -20,33 +18,26 @@ struct PicData u8 active; }; -// Static RAM declarations #define PICS_COUNT 8 static EWRAM_DATA struct SpriteTemplate sCreatingSpriteTemplate = {}; static EWRAM_DATA struct PicData sSpritePics[PICS_COUNT] = {}; -// Static ROM declarations - -// .rodata - static const struct PicData sDummyPicData = {}; -static const struct OamData gUnknown_0860B064 = +static const struct OamData sOamData_Normal = { .shape = SPRITE_SHAPE(64x64), .size = SPRITE_SIZE(64x64) }; -static const struct OamData gUnknown_0860B06C = +static const struct OamData sOamData_Affine = { .affineMode = ST_OAM_AFFINE_NORMAL, .shape = SPRITE_SHAPE(64x64), .size = SPRITE_SIZE(64x64) }; -// .text - static void DummyPicSpriteCallback(struct Sprite *sprite) { @@ -153,19 +144,15 @@ static u16 CreatePicSprite(u16 species, u32 otId, u32 personality, bool8 isFront for (i = 0; i < PICS_COUNT; i ++) { if (!sSpritePics[i].active) - { break; - } } if (i == PICS_COUNT) - { return 0xFFFF; - } + framePics = Alloc(4 * 0x800); if (!framePics) - { return 0xFFFF; - } + images = Alloc(4 * sizeof(struct SpriteFrameImage)); if (!images) { @@ -183,7 +170,7 @@ static u16 CreatePicSprite(u16 species, u32 otId, u32 personality, bool8 isFront images[j].size = 0x800; } sCreatingSpriteTemplate.tileTag = TAG_NONE; - sCreatingSpriteTemplate.oam = &gUnknown_0860B064; + sCreatingSpriteTemplate.oam = &sOamData_Normal; AssignSpriteAnimsTable(isTrainer); sCreatingSpriteTemplate.images = images; sCreatingSpriteTemplate.affineAnims = gDummySpriteAffineAnimTable; @@ -191,9 +178,7 @@ static u16 CreatePicSprite(u16 species, u32 otId, u32 personality, bool8 isFront LoadPicPaletteByTagOrSlot(species, otId, personality, paletteSlot, paletteTag, isTrainer); spriteId = CreateSprite(&sCreatingSpriteTemplate, x, y, 0); if (paletteTag == TAG_NONE) - { gSprites[spriteId].oam.paletteNum = paletteSlot; - } sSpritePics[i].frames = framePics; sSpritePics[i].images = images; sSpritePics[i].paletteTag = paletteTag; @@ -207,39 +192,35 @@ static u16 CreatePicSprite_HandleDeoxys(u16 species, u32 otId, u32 personality, return CreatePicSprite(species, otId, personality, isFrontPic, x, y, paletteSlot, paletteTag, isTrainer, FALSE); } -u16 CreatePicSprite2(u16 species, u32 otId, u32 personality, u8 flags, s16 x, s16 y, u8 paletteSlot, u16 paletteTag) +u16 CreateMonPicSprite_Affine(u16 species, u32 otId, u32 personality, u8 flags, s16 x, s16 y, u8 paletteSlot, u16 paletteTag) { u8 *framePics; struct SpriteFrameImage *images; int j; u8 i; u8 spriteId; - u8 flags2; + u8 type; - for (i = 0; i < PICS_COUNT; i ++) + for (i = 0; i < PICS_COUNT; i++) { if (!sSpritePics[i].active) - { break; - } } if (i == PICS_COUNT) - { return 0xFFFF; - } - framePics = Alloc(4 * 0x800); + + framePics = Alloc(4 * MON_PIC_SIZE); if (!framePics) - { return 0xFFFF; - } - if (flags & 0x80) + + if (flags & F_MON_PIC_NO_AFFINE) { - flags &= 0x7F; - flags2 = 3; + flags &= ~F_MON_PIC_NO_AFFINE; + type = MON_PIC_AFFINE_NONE; } else { - flags2 = flags; + type = flags; } images = Alloc(4 * sizeof(struct SpriteFrameImage)); if (!images) @@ -254,34 +235,32 @@ u16 CreatePicSprite2(u16 species, u32 otId, u32 personality, u8 flags, s16 x, s1 } for (j = 0; j < 4; j ++) { - images[j].data = framePics + 0x800 * j; - images[j].size = 0x800; + images[j].data = framePics + MON_PIC_SIZE * j; + images[j].size = MON_PIC_SIZE; } sCreatingSpriteTemplate.tileTag = TAG_NONE; sCreatingSpriteTemplate.anims = gMonFrontAnimsPtrTable[species]; sCreatingSpriteTemplate.images = images; - if (flags2 == 0x01) + if (type == MON_PIC_AFFINE_FRONT) { sCreatingSpriteTemplate.affineAnims = gAffineAnims_BattleSpriteOpponentSide; - sCreatingSpriteTemplate.oam = &gUnknown_0860B06C; + sCreatingSpriteTemplate.oam = &sOamData_Affine; } - else if (flags2 == 0x00) + else if (type == MON_PIC_AFFINE_BACK) { sCreatingSpriteTemplate.affineAnims = gAffineAnims_BattleSpritePlayerSide; - sCreatingSpriteTemplate.oam = &gUnknown_0860B06C; + sCreatingSpriteTemplate.oam = &sOamData_Affine; } - else + else // MON_PIC_AFFINE_NONE { - sCreatingSpriteTemplate.oam = &gUnknown_0860B064; + sCreatingSpriteTemplate.oam = &sOamData_Normal; sCreatingSpriteTemplate.affineAnims = gDummySpriteAffineAnimTable; } sCreatingSpriteTemplate.callback = DummyPicSpriteCallback; LoadPicPaletteByTagOrSlot(species, otId, personality, paletteSlot, paletteTag, FALSE); spriteId = CreateSprite(&sCreatingSpriteTemplate, x, y, 0); if (paletteTag == TAG_NONE) - { gSprites[spriteId].oam.paletteNum = paletteSlot; - } sSpritePics[i].frames = framePics; sSpritePics[i].images = images; sSpritePics[i].paletteTag = paletteTag; @@ -299,20 +278,15 @@ static u16 FreeAndDestroyPicSpriteInternal(u16 spriteId) for (i = 0; i < PICS_COUNT; i ++) { if (sSpritePics[i].spriteId == spriteId) - { break; - } } if (i == PICS_COUNT) - { return 0xFFFF; - } + framePics = sSpritePics[i].frames; images = sSpritePics[i].images; if (sSpritePics[i].paletteTag != TAG_NONE) - { FreeSpritePaletteByTag(GetSpritePaletteTagByPaletteNum(gSprites[spriteId].oam.paletteNum)); - } DestroySprite(&gSprites[spriteId]); Free(framePics); Free(images); @@ -320,12 +294,11 @@ static u16 FreeAndDestroyPicSpriteInternal(u16 spriteId) return 0; } -static u16 sub_818D65C(u16 species, u32 otId, u32 personality, bool8 isFrontPic, u8 paletteSlot, u8 windowId, bool8 isTrainer) +static u16 LoadPicSpriteInWindow(u16 species, u32 otId, u32 personality, bool8 isFrontPic, u8 paletteSlot, u8 windowId, bool8 isTrainer) { if (DecompressPic_HandleDeoxys(species, personality, isFrontPic, (u8 *)GetWindowAttribute(windowId, WINDOW_TILE_DATA), FALSE)) - { return 0xFFFF; - } + LoadPicPaletteBySlot(species, otId, personality, paletteSlot, isTrainer); return 0; } @@ -360,9 +333,10 @@ u16 FreeAndDestroyMonPicSprite(u16 spriteId) return FreeAndDestroyPicSpriteInternal(spriteId); } -u16 sub_818D834(u16 species, u32 otId, u32 personality, bool8 isFrontPic, u8 paletteSlot, u8 windowId) +// Unused +static u16 LoadMonPicInWindow(u16 species, u32 otId, u32 personality, bool8 isFrontPic, u8 paletteSlot, u8 windowId) { - return sub_818D65C(species, otId, personality, isFrontPic, paletteSlot, windowId, FALSE); + return LoadPicSpriteInWindow(species, otId, personality, isFrontPic, paletteSlot, windowId, FALSE); } // Unused, FRLG only @@ -381,9 +355,10 @@ u16 FreeAndDestroyTrainerPicSprite(u16 spriteId) return FreeAndDestroyPicSpriteInternal(spriteId); } -u16 sub_818D904(u16 species, bool8 isFrontPic, u8 paletteSlot, u8 windowId) +// Unused +static u16 LoadTrainerPicInWindow(u16 species, bool8 isFrontPic, u8 paletteSlot, u8 windowId) { - return sub_818D65C(species, 0, 0, isFrontPic, paletteSlot, windowId, TRUE); + return LoadPicSpriteInWindow(species, 0, 0, isFrontPic, paletteSlot, windowId, TRUE); } u16 CreateTrainerCardTrainerPicSprite(u16 species, bool8 isFrontPic, u16 destX, u16 destY, u8 paletteSlot, u8 windowId) @@ -395,13 +370,10 @@ u16 PlayerGenderToFrontTrainerPicId_Debug(u8 gender, bool8 getClass) { if (getClass == TRUE) { - switch (gender) - { - default: + if (gender != MALE) return gFacilityClassToPicIndex[FACILITY_CLASS_MAY]; - case MALE: + else return gFacilityClassToPicIndex[FACILITY_CLASS_BRENDAN]; - } } return gender; } From 7590bacec1362cd3d339aa422ced50bb57f6cca0 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 18 Oct 2021 02:14:29 -0400 Subject: [PATCH 08/10] Label remaining symbols in field_specials --- data/specials.inc | 6 ++-- src/field_specials.c | 67 +++++++++++++++----------------------------- 2 files changed, 26 insertions(+), 47 deletions(-) diff --git a/data/specials.inc b/data/specials.inc index 0b053b774..df6a6812e 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -455,7 +455,7 @@ gSpecials:: def_special ClearLinkContestFlags def_special TryContestEModeLinkup def_special ShowScrollableMultichoice - def_special sub_813A630 + def_special ScrollableMultichoice_TryReturnToList def_special BufferBattleTowerElevatorFloors def_special TryStoreHeldItemsInPyramidBag def_special ChooseItemsToTossFromPyramidBag @@ -484,10 +484,10 @@ gSpecials:: def_special CountPlayerTrainerStars def_special BufferBattleFrontierTutorMoveName def_special CloseBattleFrontierTutorWindow - def_special sub_813ADD4 + def_special ScrollableMultichoice_RedrawPersistentMenu def_special ChooseMonForMoveTutor def_special GetBattleFrontierTutorMoveIndex - def_special sub_813AF48 + def_special ScrollableMultichoice_ClosePersistentMenu def_special DoDeoxysRockInteraction def_special SetDeoxysRockPalette def_special CreateEventLegalEnemyMon diff --git a/src/field_specials.c b/src/field_specials.c index ab02f9938..44b9a0d5d 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -116,8 +116,8 @@ static void HideFrontierExchangeCornerItemIcon(u16 menu, u16 unused); static void ShowBattleFrontierTutorMoveDescription(u8 menu, u16 selection); static void CloseScrollableMultichoice(u8 taskId); static void ScrollableMultichoice_RemoveScrollArrows(u8 taskId); -static void sub_813A600(u8 taskId); -static void sub_813A664(u8 taskId); +static void Task_ScrollableMultichoice_WaitReturnToList(u8 taskId); +static void Task_ScrollableMultichoice_ReturnToList(u8 taskId); static void ShowFrontierExchangeCornerItemIcon(u16 item); static void Task_DeoxysRockInteraction(u8 taskId); static void ChangeDeoxysRockLevel(u8 a0); @@ -2702,10 +2702,10 @@ static void ScrollableMultichoice_ProcessInput(u8 taskId) { CloseScrollableMultichoice(taskId); } - else + else // Handle selection while keeping the menu open { ScrollableMultichoice_RemoveScrollArrows(taskId); - task->func = sub_813A600; + task->func = Task_ScrollableMultichoice_WaitReturnToList; EnableBothScriptContexts(); } break; @@ -2729,36 +2729,32 @@ static void CloseScrollableMultichoice(u8 taskId) EnableBothScriptContexts(); } -// Functionally unused; tKeepOpenAfterSelect is only != 0 in unused functions -static void sub_813A600(u8 taskId) +// Never run, tKeepOpenAfterSelect is FALSE for all scrollable multichoices. +static void Task_ScrollableMultichoice_WaitReturnToList(u8 taskId) { switch (gTasks[taskId].tKeepOpenAfterSelect) { - case 1: - default: - break; - case 2: - gTasks[taskId].tKeepOpenAfterSelect = 1; - gTasks[taskId].func = sub_813A664; - break; + case 1: + default: + break; + case 2: + gTasks[taskId].tKeepOpenAfterSelect = 1; + gTasks[taskId].func = Task_ScrollableMultichoice_ReturnToList; + break; } } // Never called -void sub_813A630(void) +void ScrollableMultichoice_TryReturnToList(void) { - u8 taskId = FindTaskIdByFunc(sub_813A600); + u8 taskId = FindTaskIdByFunc(Task_ScrollableMultichoice_WaitReturnToList); if (taskId == TASK_NONE) - { EnableBothScriptContexts(); - } else - { - gTasks[taskId].tKeepOpenAfterSelect++; - } + gTasks[taskId].tKeepOpenAfterSelect++; // Return to list } -static void sub_813A664(u8 taskId) +static void Task_ScrollableMultichoice_ReturnToList(u8 taskId) { ScriptContext2_Enable(); ScrollableMultichoice_UpdateScrollArrows(taskId); @@ -2807,23 +2803,7 @@ static void ScrollableMultichoice_RemoveScrollArrows(u8 taskId) // Removed for Emerald (replaced by ShowScrollableMultichoice) void ShowGlassWorkshopMenu(void) { - /* - u8 i; - ScriptContext2_Enable(); - Menu_DrawStdWindowFrame(0, 0, 10, 11); - InitMenu(0, 1, 1, 5, 0, 9); - gUnknown_0203925C = 0; - ClearVerticalScrollIndicatorPalettes(); - LoadScrollIndicatorPalette(); - sub_810F2B4(); - for (i = 0; i < 5; i++) - { - Menu_PrintText(gUnknown_083F83C0[i], 1, 2 * i + 1); - } - gUnknown_0203925B = 0; - gUnknown_0203925A = ARRAY_COUNT(gUnknown_083F83C0); - CreateTask(sub_810F118, 8); - */ + } void SetBattleTowerLinkPlayerGfx(void) @@ -3252,11 +3232,11 @@ void CloseBattleFrontierTutorWindow(void) } // Never called -void sub_813ADD4(void) +void ScrollableMultichoice_RedrawPersistentMenu(void) { u16 scrollOffset, selectedRow; u8 i; - u8 taskId = FindTaskIdByFunc(sub_813A600); + u8 taskId = FindTaskIdByFunc(Task_ScrollableMultichoice_WaitReturnToList); if (taskId != TASK_NONE) { struct Task *task = &gTasks[taskId]; @@ -3264,9 +3244,7 @@ void sub_813ADD4(void) SetStandardWindowBorderStyle(task->tWindowId, 0); for (i = 0; i < MAX_SCROLL_MULTI_ON_SCREEN; i++) - { AddTextPrinterParameterized5(task->tWindowId, 1, sScrollableMultichoiceOptions[gSpecialVar_0x8004][scrollOffset + i], 10, i * 16, TEXT_SPEED_FF, NULL, 0, 0); - } AddTextPrinterParameterized(task->tWindowId, 1, gText_SelectorArrow, 0, selectedRow * 16, TEXT_SPEED_FF, NULL); PutWindowTilemap(task->tWindowId); @@ -3313,9 +3291,10 @@ void GetBattleFrontierTutorMoveIndex(void) } // Never called -void sub_813AF48(void) +// Close a scrollable multichoice that stays open after selection +void ScrollableMultichoice_ClosePersistentMenu(void) { - u8 taskId = FindTaskIdByFunc(sub_813A600); + u8 taskId = FindTaskIdByFunc(Task_ScrollableMultichoice_WaitReturnToList); if (taskId != TASK_NONE) { struct Task *task = &gTasks[taskId]; From b31bddddca327bd15cc022717d19ace43b435ac2 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 18 Oct 2021 12:20:35 -0400 Subject: [PATCH 09/10] Clean up metatile_behavior --- include/constants/metatile_behaviors.h | 20 ++--- include/metatile_behavior.h | 14 +++- src/battle_setup.c | 6 +- src/field_control_avatar.c | 6 +- src/field_effect_helpers.c | 10 ++- src/item_use.c | 2 +- src/metatile_behavior.c | 107 ++++++++++++++++--------- src/wild_encounter.c | 2 +- 8 files changed, 106 insertions(+), 61 deletions(-) diff --git a/include/constants/metatile_behaviors.h b/include/constants/metatile_behaviors.h index 1d1557256..df2d28c7d 100755 --- a/include/constants/metatile_behaviors.h +++ b/include/constants/metatile_behaviors.h @@ -113,22 +113,22 @@ #define MB_WATER_SOUTH_ARROW_WARP 0x6D #define MB_DEEP_SOUTH_WARP 0x6E #define MB_UNUSED_6F 0x6F -#define MB_WARP_OR_BRIDGE 0x70 -#define MB_UNUSED_71 0x71 -#define MB_ROUTE120_NORTH_BRIDGE_1 0x72 -#define MB_ROUTE120_NORTH_BRIDGE_2 0x73 +#define MB_BRIDGE_OVER_OCEAN 0x70 +#define MB_BRIDGE_OVER_POND_LOW 0x71 +#define MB_BRIDGE_OVER_POND_MED 0x72 +#define MB_BRIDGE_OVER_POND_HIGH 0x73 #define MB_PACIFIDLOG_VERTICAL_LOG_1 0x74 #define MB_PACIFIDLOG_VERTICAL_LOG_2 0x75 #define MB_PACIFIDLOG_HORIZONTAL_LOG_1 0x76 #define MB_PACIFIDLOG_HORIZONTAL_LOG_2 0x77 #define MB_FORTREE_BRIDGE 0x78 #define MB_UNUSED_79 0x79 -#define MB_ROUTE120_SOUTH_BRIDGE_1 0x7A -#define MB_ROUTE120_SOUTH_BRIDGE_2 0x7B -#define MB_ROUTE120_NORTH_BRIDGE_3 0x7C -#define MB_ROUTE120_NORTH_BRIDGE_4 0x7D -#define MB_UNUSED_7E 0x7E -#define MB_ROUTE110_BRIDGE 0x7F +#define MB_BRIDGE_OVER_POND_MED_EDGE_1 0x7A +#define MB_BRIDGE_OVER_POND_MED_EDGE_2 0x7B +#define MB_BRIDGE_OVER_POND_HIGH_EDGE_1 0x7C +#define MB_BRIDGE_OVER_POND_HIGH_EDGE_2 0x7D +#define MB_UNUSED_BRIDGE_1 0x7E +#define MB_UNUSED_BRIDGE_2 0x7F #define MB_COUNTER 0x80 #define MB_UNUSED_81 0x81 #define MB_UNUSED_82 0x82 diff --git a/include/metatile_behavior.h b/include/metatile_behavior.h index 584b3e546..87a9ebcc5 100644 --- a/include/metatile_behavior.h +++ b/include/metatile_behavior.h @@ -1,6 +1,14 @@ #ifndef GUARD_METATILE_BEHAVIOR_H #define GUARD_METATILE_BEHAVIOR_H +// Return values for MetatileBehavior_GetBridgeType +enum { + BRIDGE_TYPE_OCEAN, // For log bridges over 'ocean' style water (Routes 110/119 use this). + BRIDGE_TYPE_POND_LOW, + BRIDGE_TYPE_POND_MED, + BRIDGE_TYPE_POND_HIGH, +}; + bool8 MetatileBehavior_IsATile(u8); bool8 MetatileBehavior_IsEncounterTile(u8); bool8 MetatileBehavior_IsJumpEast(u8); @@ -76,9 +84,9 @@ bool8 MetatileBehavior_IsLongGrass(u8); bool8 MetatileBehavior_IsBerryTreeSoil(u8); bool8 MetatileBehavior_IsAshGrass(u8); bool8 MetatileBehavior_IsFootprints(u8); -bool8 MetatileBehavior_IsBridge(u8); +bool8 MetatileBehavior_IsBridgeOverWater(u8); u8 MetatileBehavior_GetBridgeType(u8); -u8 MetatileBehavior_8089510(u8); +bool8 MetatileBehavior_IsBridgeOverWaterNoEdge(u8); bool8 MetatileBehavior_IsLandWildEncounter(u8); bool8 MetatileBehavior_IsWaterWildEncounter(u8); bool8 MetatileBehavior_IsIndoorEncounter(u8); @@ -115,7 +123,7 @@ bool8 MetatileBehavior_IsSecretBaseSpinMat(u8); bool8 MetatileBehavior_IsLavaridgeB1FWarp(u8); bool8 MetatileBehavior_IsLavaridge1FWarp(u8); bool8 MetatileBehavior_IsAquaHideoutWarp(u8); -bool8 MetatileBehavior_IsWarpOrBridge(u8); +bool8 MetatileBehavior_IsBridgeOverOcean(u8); bool8 MetatileBehavior_IsMossdeepGymWarp(u8); bool8 MetatileBehavior_IsSurfableFishableWater(u8); bool8 MetatileBehavior_IsMtPyreHole(u8); diff --git a/src/battle_setup.c b/src/battle_setup.c index 4337ec29c..28e80545f 100644 --- a/src/battle_setup.c +++ b/src/battle_setup.c @@ -674,9 +674,11 @@ u8 BattleSetup_GetTerrainId(void) return BATTLE_TERRAIN_MOUNTAIN; if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_SURFING)) { - if (MetatileBehavior_GetBridgeType(tileBehavior)) + // Is BRIDGE_TYPE_POND_*? + if (MetatileBehavior_GetBridgeType(tileBehavior) != BRIDGE_TYPE_OCEAN) return BATTLE_TERRAIN_POND; - if (MetatileBehavior_IsBridge(tileBehavior) == TRUE) + + if (MetatileBehavior_IsBridgeOverWater(tileBehavior) == TRUE) return BATTLE_TERRAIN_WATER; } if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(ROUTE113) && gSaveBlock1Ptr->location.mapNum == MAP_NUM(ROUTE113)) diff --git a/src/field_control_avatar.c b/src/field_control_avatar.c index 10f8d49bb..e58fb783b 100644 --- a/src/field_control_avatar.c +++ b/src/field_control_avatar.c @@ -729,9 +729,9 @@ static bool8 TryStartWarpEventScript(struct MapPosition *position, u16 metatileB DoTeleportTileWarp(); return TRUE; } - if (MetatileBehavior_IsWarpOrBridge(metatileBehavior) == TRUE) + if (MetatileBehavior_IsBridgeOverOcean(metatileBehavior) == TRUE) { - // Maybe unused? This MB is used by log bridges, but there's never a warp event on them + // Maybe unused? This MB is used by log bridges, but there's never a warp event on them. DoSpinExitWarp(); return TRUE; } @@ -762,7 +762,7 @@ static bool8 IsWarpMetatileBehavior(u16 metatileBehavior) && MetatileBehavior_IsAquaHideoutWarp(metatileBehavior) != TRUE && MetatileBehavior_IsMtPyreHole(metatileBehavior) != TRUE && MetatileBehavior_IsMossdeepGymWarp(metatileBehavior) != TRUE - && MetatileBehavior_IsWarpOrBridge(metatileBehavior) != TRUE) + && MetatileBehavior_IsBridgeOverOcean(metatileBehavior) != TRUE) return FALSE; return TRUE; } diff --git a/src/field_effect_helpers.c b/src/field_effect_helpers.c index 0a0e465a8..0acb15863 100755 --- a/src/field_effect_helpers.c +++ b/src/field_effect_helpers.c @@ -71,9 +71,15 @@ static s16 GetReflectionVerticalOffset(struct ObjectEvent *objectEvent) static void LoadObjectReflectionPalette(struct ObjectEvent *objectEvent, struct Sprite *reflectionSprite) { u8 bridgeType; - u16 bridgeReflectionVerticalOffsets[] = { 12, 28, 44 }; + u16 bridgeReflectionVerticalOffsets[] = { + [BRIDGE_TYPE_POND_LOW - 1] = 12, + [BRIDGE_TYPE_POND_MED - 1] = 28, + [BRIDGE_TYPE_POND_HIGH - 1] = 44 + }; reflectionSprite->sReflectionVerticalOffset = 0; - if (!GetObjectEventGraphicsInfo(objectEvent->graphicsId)->disableReflectionPaletteLoad && ((bridgeType = MetatileBehavior_GetBridgeType(objectEvent->previousMetatileBehavior)) || (bridgeType = MetatileBehavior_GetBridgeType(objectEvent->currentMetatileBehavior)))) + if (!GetObjectEventGraphicsInfo(objectEvent->graphicsId)->disableReflectionPaletteLoad + && ((bridgeType = MetatileBehavior_GetBridgeType(objectEvent->previousMetatileBehavior)) + || (bridgeType = MetatileBehavior_GetBridgeType(objectEvent->currentMetatileBehavior)))) { reflectionSprite->sReflectionVerticalOffset = bridgeReflectionVerticalOffsets[bridgeType - 1]; LoadObjectHighBridgeReflectionPalette(objectEvent, reflectionSprite->oam.paletteNum); diff --git a/src/item_use.c b/src/item_use.c index 0a3181608..665d27e7d 100755 --- a/src/item_use.c +++ b/src/item_use.c @@ -249,7 +249,7 @@ static bool32 CanFish(void) { if (MetatileBehavior_IsSurfableWaterOrUnderwater(tileBehavior) && !MapGridIsImpassableAt(x, y)) return TRUE; - if (MetatileBehavior_8089510(tileBehavior) == TRUE) + if (MetatileBehavior_IsBridgeOverWaterNoEdge(tileBehavior) == TRUE) return TRUE; } diff --git a/src/metatile_behavior.c b/src/metatile_behavior.c index 5c8b8ec51..3829523df 100644 --- a/src/metatile_behavior.c +++ b/src/metatile_behavior.c @@ -122,22 +122,22 @@ static const u8 sTileBitAttributes[] = [MB_WATER_SOUTH_ARROW_WARP] = TILE_ATTRIBUTES(TRUE, TRUE, FALSE), [MB_DEEP_SOUTH_WARP] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), [MB_UNUSED_6F] = TILE_ATTRIBUTES(TRUE, TRUE, FALSE), - [MB_WARP_OR_BRIDGE] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE), - [MB_UNUSED_71] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), - [MB_ROUTE120_NORTH_BRIDGE_1] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), - [MB_ROUTE120_NORTH_BRIDGE_2] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), + [MB_BRIDGE_OVER_OCEAN] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE), + [MB_BRIDGE_OVER_POND_LOW] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), + [MB_BRIDGE_OVER_POND_MED] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), + [MB_BRIDGE_OVER_POND_HIGH] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), [MB_PACIFIDLOG_VERTICAL_LOG_1] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), [MB_PACIFIDLOG_VERTICAL_LOG_2] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), [MB_PACIFIDLOG_HORIZONTAL_LOG_1] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), [MB_PACIFIDLOG_HORIZONTAL_LOG_2] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), [MB_FORTREE_BRIDGE] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), [MB_UNUSED_79] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE), - [MB_ROUTE120_SOUTH_BRIDGE_1] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), - [MB_ROUTE120_SOUTH_BRIDGE_2] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), - [MB_ROUTE120_NORTH_BRIDGE_3] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), - [MB_ROUTE120_NORTH_BRIDGE_4] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), - [MB_UNUSED_7E] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), - [MB_ROUTE110_BRIDGE] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), + [MB_BRIDGE_OVER_POND_MED_EDGE_1] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), + [MB_BRIDGE_OVER_POND_MED_EDGE_2] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), + [MB_BRIDGE_OVER_POND_HIGH_EDGE_1] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), + [MB_BRIDGE_OVER_POND_HIGH_EDGE_2] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), + [MB_UNUSED_BRIDGE_1] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), + [MB_UNUSED_BRIDGE_2] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), [MB_COUNTER] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE), [MB_UNUSED_81] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE), [MB_UNUSED_82] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE), @@ -833,7 +833,9 @@ bool8 MetatileBehavior_IsPlayerRoomPCOn(u8 metatileBehavior) bool8 MetatileBehavior_HasRipples(u8 metatileBehavior) { - if (metatileBehavior == MB_POND_WATER || metatileBehavior == MB_PUDDLE || metatileBehavior == MB_SOOTOPOLIS_DEEP_WATER) + if (metatileBehavior == MB_POND_WATER + || metatileBehavior == MB_PUDDLE + || metatileBehavior == MB_SOOTOPOLIS_DEEP_WATER) return TRUE; else return FALSE; @@ -888,10 +890,19 @@ bool8 MetatileBehavior_IsFootprints(u8 metatileBehavior) return FALSE; } -bool8 MetatileBehavior_IsBridge(u8 metatileBehavior) +// For the sections of log bridges that span water / water's edge. +// Note that the rest of the metatiles for these bridges use MB_NORMAL. +// This is used to allow encounters on the water below the bridge. +bool8 MetatileBehavior_IsBridgeOverWater(u8 metatileBehavior) { - if ((metatileBehavior == MB_WARP_OR_BRIDGE || metatileBehavior == MB_UNUSED_71 || metatileBehavior == MB_ROUTE120_NORTH_BRIDGE_1 || metatileBehavior == MB_ROUTE120_NORTH_BRIDGE_2) - || (metatileBehavior == MB_ROUTE120_NORTH_BRIDGE_3 || metatileBehavior == MB_ROUTE120_NORTH_BRIDGE_4 || metatileBehavior == MB_UNUSED_7E || metatileBehavior == MB_ROUTE110_BRIDGE)) + if ((metatileBehavior == MB_BRIDGE_OVER_OCEAN + || metatileBehavior == MB_BRIDGE_OVER_POND_LOW + || metatileBehavior == MB_BRIDGE_OVER_POND_MED + || metatileBehavior == MB_BRIDGE_OVER_POND_HIGH) + || (metatileBehavior == MB_BRIDGE_OVER_POND_HIGH_EDGE_1 + || metatileBehavior == MB_BRIDGE_OVER_POND_HIGH_EDGE_2 + || metatileBehavior == MB_UNUSED_BRIDGE_1 + || metatileBehavior == MB_UNUSED_BRIDGE_2)) return TRUE; else return FALSE; @@ -899,34 +910,39 @@ bool8 MetatileBehavior_IsBridge(u8 metatileBehavior) u8 MetatileBehavior_GetBridgeType(u8 metatileBehavior) { - u8 result = metatileBehavior - MB_WARP_OR_BRIDGE; - if (result < 4) - return result; + // MB_BRIDGE_OVER_OCEAN --> BRIDGE_TYPE_OCEAN (Routes 110/119) + // MB_BRIDGE_OVER_POND_LOW --> BRIDGE_TYPE_POND_LOW (Unused) + // MB_BRIDGE_OVER_POND_MED --> BRIDGE_TYPE_POND_MED (Route 120, south) + // MB_BRIDGE_OVER_POND_HIGH --> BRIDGE_TYPE_POND_HIGH (Route 120, north) + if (metatileBehavior >= MB_BRIDGE_OVER_OCEAN + && metatileBehavior <= MB_BRIDGE_OVER_POND_HIGH) + return metatileBehavior - MB_BRIDGE_OVER_OCEAN; - result = metatileBehavior - MB_ROUTE120_SOUTH_BRIDGE_1; - if (result < 2) - return 2; + if (metatileBehavior >= MB_BRIDGE_OVER_POND_MED_EDGE_1 + && metatileBehavior <= MB_BRIDGE_OVER_POND_MED_EDGE_2) + return BRIDGE_TYPE_POND_MED; - result = metatileBehavior - MB_ROUTE120_NORTH_BRIDGE_3; - if (result < 2) - return 3; + if (metatileBehavior >= MB_BRIDGE_OVER_POND_HIGH_EDGE_1 + && metatileBehavior <= MB_BRIDGE_OVER_POND_HIGH_EDGE_2) + return BRIDGE_TYPE_POND_HIGH; - return 0; + return BRIDGE_TYPE_OCEAN; } -u8 MetatileBehavior_8089510(u8 metatileBehavior) +// Used to allow fishing below the bridge metatiles. +bool8 MetatileBehavior_IsBridgeOverWaterNoEdge(u8 metatileBehavior) { - u8 result = metatileBehavior - MB_WARP_OR_BRIDGE; - - if (result < 4) - return 1; + if (metatileBehavior >= MB_BRIDGE_OVER_OCEAN + && metatileBehavior <= MB_BRIDGE_OVER_POND_HIGH) + return TRUE; else - return 0; + return FALSE; } bool8 MetatileBehavior_IsLandWildEncounter(u8 metatileBehavior) { - if (MetatileBehavior_IsSurfableWaterOrUnderwater(metatileBehavior) == FALSE && MetatileBehavior_IsEncounterTile(metatileBehavior) == TRUE) + if (MetatileBehavior_IsSurfableWaterOrUnderwater(metatileBehavior) == FALSE + && MetatileBehavior_IsEncounterTile(metatileBehavior) == TRUE) return TRUE; else return FALSE; @@ -934,7 +950,8 @@ bool8 MetatileBehavior_IsLandWildEncounter(u8 metatileBehavior) bool8 MetatileBehavior_IsWaterWildEncounter(u8 metatileBehavior) { - if (MetatileBehavior_IsSurfableWaterOrUnderwater(metatileBehavior) == TRUE && MetatileBehavior_IsEncounterTile(metatileBehavior) == TRUE) + if (MetatileBehavior_IsSurfableWaterOrUnderwater(metatileBehavior) == TRUE + && MetatileBehavior_IsEncounterTile(metatileBehavior) == TRUE) return TRUE; else return FALSE; @@ -1148,8 +1165,10 @@ bool8 MetatileBehavior_IsPacifidlogHorizontalLog2(u8 metatileBehavior) bool8 MetatileBehavior_IsPacifidlogLog(u8 metatileBehavior) { - if (metatileBehavior == MB_PACIFIDLOG_VERTICAL_LOG_1 || metatileBehavior == MB_PACIFIDLOG_VERTICAL_LOG_2 - || metatileBehavior == MB_PACIFIDLOG_HORIZONTAL_LOG_1 || metatileBehavior == MB_PACIFIDLOG_HORIZONTAL_LOG_2) + if (metatileBehavior == MB_PACIFIDLOG_VERTICAL_LOG_1 + || metatileBehavior == MB_PACIFIDLOG_VERTICAL_LOG_2 + || metatileBehavior == MB_PACIFIDLOG_HORIZONTAL_LOG_1 + || metatileBehavior == MB_PACIFIDLOG_HORIZONTAL_LOG_2) return TRUE; else return FALSE; @@ -1243,9 +1262,13 @@ bool8 MetatileBehavior_IsAquaHideoutWarp(u8 metatileBehavior) return FALSE; } -bool8 MetatileBehavior_IsWarpOrBridge(u8 metatileBehavior) +// Very odd, used to initiate a teleport-style warp. +// No warp events seem to be on a metatile of this kind, and it's +// used by log bridges over ocean-style water, which wouldn't make +// sense to have a warp like this. +bool8 MetatileBehavior_IsBridgeOverOcean(u8 metatileBehavior) { - if (metatileBehavior == MB_WARP_OR_BRIDGE) + if (metatileBehavior == MB_BRIDGE_OVER_OCEAN) return TRUE; else return FALSE; @@ -1262,9 +1285,15 @@ bool8 MetatileBehavior_IsMossdeepGymWarp(u8 metatileBehavior) bool8 MetatileBehavior_IsSurfableFishableWater(u8 metatileBehavior) { - if (metatileBehavior == MB_POND_WATER || metatileBehavior == MB_OCEAN_WATER || metatileBehavior == MB_SEMI_DEEP_WATER || metatileBehavior == MB_DEEP_WATER - || metatileBehavior == MB_SOOTOPOLIS_DEEP_WATER || (metatileBehavior == MB_EASTWARD_CURRENT || metatileBehavior == MB_WESTWARD_CURRENT - || metatileBehavior == MB_NORTHWARD_CURRENT || metatileBehavior == MB_SOUTHWARD_CURRENT)) + if (metatileBehavior == MB_POND_WATER + || metatileBehavior == MB_OCEAN_WATER + || metatileBehavior == MB_SEMI_DEEP_WATER + || metatileBehavior == MB_DEEP_WATER + || metatileBehavior == MB_SOOTOPOLIS_DEEP_WATER + || (metatileBehavior == MB_EASTWARD_CURRENT + || metatileBehavior == MB_WESTWARD_CURRENT + || metatileBehavior == MB_NORTHWARD_CURRENT + || metatileBehavior == MB_SOUTHWARD_CURRENT)) return TRUE; else return FALSE; diff --git a/src/wild_encounter.c b/src/wild_encounter.c index 5d7425762..458882853 100644 --- a/src/wild_encounter.c +++ b/src/wild_encounter.c @@ -613,7 +613,7 @@ bool8 StandardWildEncounter(u16 currMetaTileBehavior, u16 previousMetaTileBehavi } } else if (MetatileBehavior_IsWaterWildEncounter(currMetaTileBehavior) == TRUE - || (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_SURFING) && MetatileBehavior_IsBridge(currMetaTileBehavior) == TRUE)) + || (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_SURFING) && MetatileBehavior_IsBridgeOverWater(currMetaTileBehavior) == TRUE)) { if (AreLegendariesInSootopolisPreventingEncounters() == TRUE) return FALSE; From 24b4e898ada55c79a0575684722b9d42e63017e9 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 18 Oct 2021 14:40:04 -0400 Subject: [PATCH 10/10] More mauville_old_man clean up --- data/text/mauville_man.inc | 38 +++--- gflib/text.h | 2 +- include/constants/global.h | 1 + include/event_scripts.h | 40 +++--- include/global.h | 2 +- src/mauville_old_man.c | 256 ++++++++++++++++++++----------------- 6 files changed, 184 insertions(+), 155 deletions(-) diff --git a/data/text/mauville_man.inc b/data/text/mauville_man.inc index 5d9954d9b..5b7dfbb7b 100644 --- a/data/text/mauville_man.inc +++ b/data/text/mauville_man.inc @@ -1,63 +1,63 @@ -@ Only contains a portion of the mauville_man text. The rest is in scripts/mauville_man.inc -gText_SoPretty:: +@ Only contains the text for the Mauville Man named Giddy. The rest is in scripts/mauville_man.inc +GiddyText_SoPretty:: .string " so pretty!$" -gText_SoDarling:: +GiddyText_SoDarling:: .string " so darling!$" -gText_SoRelaxed:: +GiddyText_SoRelaxed:: .string " so relaxed!$" -gText_SoSunny:: +GiddyText_SoSunny:: .string " so sunny!$" -gText_SoDesirable:: +GiddyText_SoDesirable:: .string " so desirable!$" -gText_SoExciting:: +GiddyText_SoExciting:: .string " so exciting!$" -gText_SoAmusing:: +GiddyText_SoAmusing:: .string " so amusing!$" -gText_SoMagical:: +GiddyText_SoMagical:: .string " so magical!$" -gOtherText_Is:: +GiddyText_Is:: .string " is$" -gOtherText_DontYouAgree:: +GiddyText_DontYouAgree:: .string "\n" .string "Don't you agree?$" -gMauvilleManText_ISoWantToGoOnAVacation:: +GiddyText_ISoWantToGoOnAVacation:: .string "I so want to go on a vacation.\n" .string "Would you happen to know a nice place?$" -gMauvilleManText_IBoughtCrayonsWith120Colors:: +GiddyText_IBoughtCrayonsWith120Colors:: .string "I bought crayons with 120 colors!\n" .string "Don't you think that's nice?$" -gMauvilleManText_WouldntItBeNiceIfWeCouldFloat:: +GiddyText_WouldntItBeNiceIfWeCouldFloat:: .string "Wouldn't it be nice if we could float\n" .string "away on a cloud of bubbles?$" -gMauvilleManText_WhenYouWriteOnASandyBeach:: +GiddyText_WhenYouWriteOnASandyBeach:: .string "When you write on a sandy beach,\n" .string "they wash away. It makes me sad.$" -gMauvilleManText_WhatsTheBottomOfTheSeaLike:: +GiddyText_WhatsTheBottomOfTheSeaLike:: .string "What's the bottom of the sea like?\n" .string "Just once I would so love to go!$" -gMauvilleManText_WhenYouSeeTheSettingSunDoesIt:: +GiddyText_WhenYouSeeTheSettingSunDoesIt:: .string "When you see the setting sun, does it\n" .string "make you want to go home?$" -gMauvilleManText_LyingBackInTheGreenGrass:: +GiddyText_LyingBackInTheGreenGrass:: .string "Lying back in the green grass…\n" .string "Oh, it's so, so nice!$" -gMauvilleManText_SecretBasesAreSoWonderful:: +GiddyText_SecretBasesAreSoWonderful:: .string "SECRET BASES are so wonderful!\n" .string "Can't you feel the excitement?$" diff --git a/gflib/text.h b/gflib/text.h index 8871ba2f1..ee3dfa34c 100644 --- a/gflib/text.h +++ b/gflib/text.h @@ -52,7 +52,7 @@ #define CHAR_LV 0x34 #define CHAR_EQUALS 0x35 #define CHAR_SEMICOLON 0x36 -// +#define CHAR_BARD_WORD_DELIMIT 0x37 // Empty space to separate words in Bard's song #define CHAR_INV_QUESTION_MARK 0x51 #define CHAR_INV_EXCL_MARK 0x52 #define CHAR_PK 0x53 diff --git a/include/constants/global.h b/include/constants/global.h index 6d3fa936d..3d5da0078 100644 --- a/include/constants/global.h +++ b/include/constants/global.h @@ -96,6 +96,7 @@ #define NUM_STORYTELLER_TALES 4 #define NUM_TRADER_ITEMS 4 #define GIDDY_MAX_TALES 10 +#define GIDDY_MAX_QUESTIONS 8 #define OPTIONS_BUTTON_MODE_NORMAL 0 #define OPTIONS_BUTTON_MODE_LR 1 diff --git a/include/event_scripts.h b/include/event_scripts.h index 1a24aa59d..a19d4553a 100644 --- a/include/event_scripts.h +++ b/include/event_scripts.h @@ -382,27 +382,27 @@ extern const u8 EventScript_UseRockSmash[]; extern const u8 LittlerootTown_BrendansHouse_2F_EventScript_TurnOffPlayerPC[]; extern const u8 LittlerootTown_MaysHouse_2F_EventScript_TurnOffPlayerPC[]; -//mauville_old_man -extern const u8 gOtherText_Is[]; -extern const u8 gOtherText_DontYouAgree[]; -extern const u8 gText_SoPretty[]; -extern const u8 gText_SoDarling[]; -extern const u8 gText_SoRelaxed[]; -extern const u8 gText_SoSunny[]; -extern const u8 gText_SoDesirable[]; -extern const u8 gText_SoExciting[]; -extern const u8 gText_SoAmusing[]; -extern const u8 gText_SoMagical[]; -extern const u8 gMauvilleManText_ISoWantToGoOnAVacation[]; -extern const u8 gMauvilleManText_IBoughtCrayonsWith120Colors[]; -extern const u8 gMauvilleManText_WouldntItBeNiceIfWeCouldFloat[]; -extern const u8 gMauvilleManText_WhenYouWriteOnASandyBeach[]; -extern const u8 gMauvilleManText_WhatsTheBottomOfTheSeaLike[]; -extern const u8 gMauvilleManText_WhenYouSeeTheSettingSunDoesIt[]; -extern const u8 gMauvilleManText_LyingBackInTheGreenGrass[]; -extern const u8 gMauvilleManText_SecretBasesAreSoWonderful[]; +// Mauville Old Man (Giddy) +extern const u8 GiddyText_Is[]; +extern const u8 GiddyText_DontYouAgree[]; +extern const u8 GiddyText_SoPretty[]; +extern const u8 GiddyText_SoDarling[]; +extern const u8 GiddyText_SoRelaxed[]; +extern const u8 GiddyText_SoSunny[]; +extern const u8 GiddyText_SoDesirable[]; +extern const u8 GiddyText_SoExciting[]; +extern const u8 GiddyText_SoAmusing[]; +extern const u8 GiddyText_SoMagical[]; +extern const u8 GiddyText_ISoWantToGoOnAVacation[]; +extern const u8 GiddyText_IBoughtCrayonsWith120Colors[]; +extern const u8 GiddyText_WouldntItBeNiceIfWeCouldFloat[]; +extern const u8 GiddyText_WhenYouWriteOnASandyBeach[]; +extern const u8 GiddyText_WhatsTheBottomOfTheSeaLike[]; +extern const u8 GiddyText_WhenYouSeeTheSettingSunDoesIt[]; +extern const u8 GiddyText_LyingBackInTheGreenGrass[]; +extern const u8 GiddyText_SecretBasesAreSoWonderful[]; -// mauville old man storyteller +// Mauville Old Man (storyteller) extern const u8 MauvilleCity_PokemonCenter_1F_Text_SavedGameTitle[]; extern const u8 MauvilleCity_PokemonCenter_1F_Text_SavedGameAction[]; extern const u8 MauvilleCity_PokemonCenter_1F_Text_SavedGameStory[]; diff --git a/include/global.h b/include/global.h index dcec2c4db..8b2c2ae86 100644 --- a/include/global.h +++ b/include/global.h @@ -640,7 +640,7 @@ struct MauvilleManGiddy /*0x01*/ u8 taleCounter; /*0x02*/ u8 questionNum; /*0x04*/ u16 randomWords[GIDDY_MAX_TALES]; - /*0x18*/ u8 questionList[8]; + /*0x18*/ u8 questionList[GIDDY_MAX_QUESTIONS]; /*0x20*/ u8 language; }; /*size = 0x2C*/ diff --git a/src/mauville_old_man.c b/src/mauville_old_man.c index d202bc638..2fd0e6730 100644 --- a/src/mauville_old_man.c +++ b/src/mauville_old_man.c @@ -24,8 +24,6 @@ #include "m4a.h" #include "constants/mauville_old_man.h" -#define CHAR_SONG_WORD_SEPARATOR 0x37 - static void InitGiddyTaleList(void); static void StartBardSong(bool8 useTemporaryLyrics); static void Task_BardSong(u8 taskId); @@ -50,25 +48,28 @@ static const u16 sDefaultBardSongLyrics[BARD_SONG_LENGTH] = { }; static const u8 * const sGiddyAdjectives[] = { - gText_SoPretty, - gText_SoDarling, - gText_SoRelaxed, - gText_SoSunny, - gText_SoDesirable, - gText_SoExciting, - gText_SoAmusing, - gText_SoMagical + GiddyText_SoPretty, + GiddyText_SoDarling, + GiddyText_SoRelaxed, + GiddyText_SoSunny, + GiddyText_SoDesirable, + GiddyText_SoExciting, + GiddyText_SoAmusing, + GiddyText_SoMagical }; -static const u8 * const sGiddyQuestions[] = { - gMauvilleManText_ISoWantToGoOnAVacation, - gMauvilleManText_IBoughtCrayonsWith120Colors, - gMauvilleManText_WouldntItBeNiceIfWeCouldFloat, - gMauvilleManText_WhenYouWriteOnASandyBeach, - gMauvilleManText_WhatsTheBottomOfTheSeaLike, - gMauvilleManText_WhenYouSeeTheSettingSunDoesIt, - gMauvilleManText_LyingBackInTheGreenGrass, - gMauvilleManText_SecretBasesAreSoWonderful +// Non-random lines Giddy can say. Not all are strictly +// questions, but most are, and the player will receive +// a Yes/No prompt afterwards regardless. +static const u8 * const sGiddyQuestions[GIDDY_MAX_QUESTIONS] = { + GiddyText_ISoWantToGoOnAVacation, + GiddyText_IBoughtCrayonsWith120Colors, + GiddyText_WouldntItBeNiceIfWeCouldFloat, + GiddyText_WhenYouWriteOnASandyBeach, + GiddyText_WhatsTheBottomOfTheSeaLike, + GiddyText_WhenYouSeeTheSettingSunDoesIt, + GiddyText_LyingBackInTheGreenGrass, + GiddyText_SecretBasesAreSoWonderful }; static void SetupBard(void) @@ -185,7 +186,7 @@ static void PrepareSongText(void) while (wordEnd != str) { if (*str == CHAR_SPACE) - *str = CHAR_SONG_WORD_SEPARATOR; + *str = CHAR_BARD_WORD_DELIMIT; str++; } @@ -196,7 +197,7 @@ static void PrepareSongText(void) while (wordEnd != str) { if (*str == CHAR_SPACE) - *str = CHAR_SONG_WORD_SEPARATOR; + *str = CHAR_BARD_WORD_DELIMIT; str++; } @@ -207,7 +208,7 @@ static void PrepareSongText(void) while (wordEnd != str) { if (*str == CHAR_SPACE) - *str = CHAR_SONG_WORD_SEPARATOR; + *str = CHAR_BARD_WORD_DELIMIT; str++; } @@ -272,22 +273,26 @@ void GenerateGiddyLine(void) if (giddy->taleCounter == 0) InitGiddyTaleList(); + // A line from Giddy is either a line following this format: + // "{random word} is so {adjective}! Don't you agree?", + // or one of the texts in sGiddyQuestions. if (giddy->randomWords[giddy->taleCounter] != EC_EMPTY_WORD) { u8 *stringPtr; u32 adjective = Random(); + adjective %= ARRAY_COUNT(sGiddyAdjectives); - adjective %= 8; stringPtr = CopyEasyChatWord(gStringVar4, giddy->randomWords[giddy->taleCounter]); - stringPtr = StringCopy(stringPtr, gOtherText_Is); + stringPtr = StringCopy(stringPtr, GiddyText_Is); stringPtr = StringCopy(stringPtr, sGiddyAdjectives[adjective]); - StringCopy(stringPtr, gOtherText_DontYouAgree); + StringCopy(stringPtr, GiddyText_DontYouAgree); } else { StringCopy(gStringVar4, sGiddyQuestions[giddy->questionList[giddy->questionNum++]]); } + // 10% chance for Giddy to stop telling tales. if (!(Random() % 10)) giddy->taleCounter = GIDDY_MAX_TALES; else @@ -308,45 +313,53 @@ static void InitGiddyTaleList(void) {EC_GROUP_POKEMON_NATIONAL, 0} }; u16 i; - u16 r10; - u16 r7; - u16 r1; + u16 totalWords; + u16 temp; + u16 var; // re-used // Shuffle question list - for (i = 0; i < 8; i++) + for (i = 0; i < GIDDY_MAX_QUESTIONS; i++) giddy->questionList[i] = i; - for (i = 0; i < 8; i++) + for (i = 0; i < GIDDY_MAX_QUESTIONS; i++) { - r1 = Random() % (i + 1); - SWAP(giddy->questionList[i], giddy->questionList[r1], r7); + var = Random() % (i + 1); + SWAP(giddy->questionList[i], giddy->questionList[var], temp); } - r10 = 0; - for (i = 0; i < 6; i++) + // Count total number of words in above word groups + totalWords = 0; + for (i = 0; i < ARRAY_COUNT(wordGroupsAndCount); i++) { wordGroupsAndCount[i][1] = EasyChat_GetNumWordsInGroup(wordGroupsAndCount[i][0]); - r10 += wordGroupsAndCount[i][1]; + totalWords += wordGroupsAndCount[i][1]; } giddy->questionNum = 0; - r7 = 0; + temp = 0; for (i = 0; i < GIDDY_MAX_TALES; i++) { - r1 = Random() % 10; - if (r1 < 3 && r7 < 8) + var = Random() % 10; + if (var < 3 && temp < GIDDY_MAX_QUESTIONS) { + // 30% chance for word to be empty (in which case Giddy + // will say one of his non-random questions), unless + // the limit for questions has been reached already. giddy->randomWords[i] = EC_EMPTY_WORD; - r7++; + temp++; } else { - s16 r2 = Random() % r10; - for (r1 = 0; i < 6; r1++) - if ((r2 -= wordGroupsAndCount[r1][1]) <= 0) + // Pick a random word id, then advance through the word + // groups until the group where that id landed. + s16 randWord = Random() % totalWords; + for (var = 0; i < ARRAY_COUNT(wordGroupsAndCount); var++) + if ((randWord -= wordGroupsAndCount[var][1]) <= 0) break; - if (r1 == 6) - r1 = 0; - giddy->randomWords[i] = GetRandomEasyChatWordFromUnlockedGroup(wordGroupsAndCount[r1][0]); + if (var == ARRAY_COUNT(wordGroupsAndCount)) + var = 0; + + // Save the randomly selected word + giddy->randomWords[i] = GetRandomEasyChatWordFromUnlockedGroup(wordGroupsAndCount[var][0]); } } } @@ -392,10 +405,23 @@ void ResetMauvilleOldManFlag(void) SetMauvilleOldManObjEventGfx(); } +// States and task data for Task_BardSong. +// The function BardSing receives this task as an +// argument and reads its state as well. +enum { + BARD_STATE_INIT, + BARD_STATE_WAIT_BGM, + BARD_STATE_GET_WORD, + BARD_STATE_HANDLE_WORD, + BARD_STATE_WAIT_WORD, + BARD_STATE_PAUSE, +}; -#define tState data[0] -#define tCharIndex data[3] -#define tCurrWord data[4] +#define tState data[0] +#define tWordState data[1] +#define tDelay data[2] +#define tCharIndex data[3] +#define tCurrWord data[4] #define tUseTemporaryLyrics data[5] #define MACRO1(a) (((a) & 3) + (((a) / 8) & 1)) @@ -418,7 +444,7 @@ static void DisableTextPrinters(struct TextPrinterTemplate * printer, u16 a1) gDisableTextPrinters = TRUE; } -static void sub_8120708(const u8 * str) +static void DrawSongTextWindow(const u8 * str) { DrawDialogueFrame(0, 0); AddTextPrinterParameterized(0, 1, str, 0, 1, 1, DisableTextPrinters); @@ -430,7 +456,7 @@ static void BardSing(struct Task *task, struct BardSong *song) { switch (task->tState) { - case 0: // Initialize song + case BARD_STATE_INIT: { struct MauvilleManBard *bard = &gSaveBlock1Ptr->oldMan.bard; u16 *lyrics; @@ -446,9 +472,9 @@ static void BardSing(struct Task *task, struct BardSong *song) song->currWord = 0; } break; - case 1: // Wait for BGM to end + case BARD_STATE_WAIT_BGM: break; - case 2: // Initialize word + case BARD_STATE_GET_WORD: { u16 word = song->lyrics[song->currWord]; song->sound = GetWordSounds(word); @@ -463,8 +489,8 @@ static void BardSing(struct Task *task, struct BardSong *song) } break; } - case 3: - case 4: + case BARD_STATE_HANDLE_WORD: + case BARD_STATE_WAIT_WORD: { const struct BardSound *sound = &song->sound[song->currPhoneme]; @@ -524,7 +550,7 @@ static void BardSing(struct Task *task, struct BardSong *song) } } break; - case 5: + case BARD_STATE_PAUSE: break; } } @@ -534,28 +560,30 @@ static void Task_BardSong(u8 taskId) struct Task *task = &gTasks[taskId]; BardSing(task, &gBardSong); + switch (task->tState) { - case 0: // Initialize song + case BARD_STATE_INIT: PrepareSongText(); - sub_8120708(gStringVar4); - task->data[1] = 0; - task->data[2] = 0; + DrawSongTextWindow(gStringVar4); + task->tWordState = 0; + task->tDelay = 0; task->tCharIndex = 0; task->tCurrWord = 0; FadeOutBGMTemporarily(4); - task->tState = 1; + task->tState = BARD_STATE_WAIT_BGM; break; - case 1: // Wait for BGM to end + case BARD_STATE_WAIT_BGM: if (IsBGMPausedOrStopped()) - task->tState = 2; + task->tState = BARD_STATE_GET_WORD; break; - case 2: // Initialize word + case BARD_STATE_GET_WORD: { struct MauvilleManBard *bard = &gSaveBlock1Ptr->oldMan.bard; - u8 *str = gStringVar4 + task->tCharIndex; + u8 *str = &gStringVar4[task->tCharIndex]; u16 wordLen = 0; + // Read letters until delimiter while (*str != CHAR_SPACE && *str != CHAR_NEWLINE && *str != EXT_CTRL_CODE_BEGIN @@ -564,6 +592,7 @@ static void Task_BardSong(u8 taskId) str++; wordLen++; } + if (!task->tUseTemporaryLyrics) sUnknownBardRelated = MACRO2(bard->songLyrics[task->tCurrWord]); else @@ -574,27 +603,29 @@ static void Task_BardSong(u8 taskId) gBardSong.length = 1; task->tCurrWord++; - if (task->data[2] == 0) + if (task->tDelay == 0) { - task->tState = 3; - task->data[1] = 0; + task->tState = BARD_STATE_HANDLE_WORD; + task->tWordState = 0; } else { - task->tState = 5; - task->data[1] = 0; + task->tState = BARD_STATE_PAUSE; + task->tWordState = 0; } } break; - case 5: - if (task->data[2] == 0) - task->tState = 3; + case BARD_STATE_PAUSE: + // Wait before singing next word + if (task->tDelay == 0) + task->tState = BARD_STATE_HANDLE_WORD; else - task->data[2]--; + task->tDelay--; break; - case 3: + case BARD_STATE_HANDLE_WORD: if (gStringVar4[task->tCharIndex] == EOS) { + // End song FadeInBGM(6); m4aMPlayFadeOutTemporarily(&gMPlayInfo_SE2, 2); EnableBothScriptContexts(); @@ -602,55 +633,61 @@ static void Task_BardSong(u8 taskId) } else if (gStringVar4[task->tCharIndex] == CHAR_SPACE) { - + // Handle space EnableTextPrinters(); task->tCharIndex++; - task->tState = 2; - task->data[2] = 0; + task->tState = BARD_STATE_GET_WORD; + task->tDelay = 0; } else if (gStringVar4[task->tCharIndex] == CHAR_NEWLINE) { + // Handle newline task->tCharIndex++; - task->tState = 2; - task->data[2] = 0; + task->tState = BARD_STATE_GET_WORD; + task->tDelay = 0; } else if (gStringVar4[task->tCharIndex] == EXT_CTRL_CODE_BEGIN) { + // Handle ctrl code task->tCharIndex += 2; // skip over control codes - task->tState = 2; - task->data[2] = 8; + task->tState = BARD_STATE_GET_WORD; + task->tDelay = 8; } - else if (gStringVar4[task->tCharIndex] == CHAR_SONG_WORD_SEPARATOR) + else if (gStringVar4[task->tCharIndex] == CHAR_BARD_WORD_DELIMIT) { - gStringVar4[task->tCharIndex] = CHAR_SPACE; // restore it back to a space + // Handle word boundary + gStringVar4[task->tCharIndex] = CHAR_SPACE; // Replace with a real space EnableTextPrinters(); task->tCharIndex++; - task->data[2] = 0; + task->tDelay = 0; } else { - switch (task->data[1]) + // Handle regular word + switch (task->tWordState) { case 0: EnableTextPrinters(); - task->data[1]++; + task->tWordState++; break; case 1: - task->data[1]++; + task->tWordState++; break; case 2: task->tCharIndex++; - task->data[1] = 0; - task->data[2] = gBardSong.length; - task->tState = 4; + task->tWordState = 0; + task->tDelay = gBardSong.length; + task->tState = BARD_STATE_WAIT_WORD; break; } } break; - case 4: - task->data[2]--; - if (task->data[2] == 0) - task->tState = 3; + case BARD_STATE_WAIT_WORD: + // Wait for word to finish being sung. + // BardSing will continue to play it. + task->tDelay--; + if (task->tDelay == 0) + task->tState = BARD_STATE_HANDLE_WORD; break; } RunTextPrintersAndIsPrinter0Active(); @@ -1107,6 +1144,9 @@ static const struct Story sStorytellerStories[] = { } }; +static const s32 sNumStories = ARRAY_COUNT(sStorytellerStories); +static const u32 sUnused = 8; + static void StorytellerSetup(void) { s32 i; @@ -1140,12 +1180,12 @@ static const struct Story *GetStoryByStat(u32 stat) { s32 i; - for (i = 0; i < (int)ARRAY_COUNT(sStorytellerStories); i++) + for (i = 0; i < sNumStories; i++) { if (sStorytellerStories[i].stat == stat) return &sStorytellerStories[i]; } - return &sStorytellerStories[ARRAY_COUNT(sStorytellerStories) - 1]; + return &sStorytellerStories[sNumStories - 1]; } static const u8 *GetStoryTitleByStat(u32 stat) @@ -1241,28 +1281,16 @@ static void ScrambleStatList(u8 * arr, s32 count) } } -struct UnknownStruct_0859F288 -{ - s32 length; - u32 unused2; -}; - -static const struct UnknownStruct_0859F288 sStorytellerStuff = { - ARRAY_COUNT(sStorytellerStories), - sizeof(sStorytellerStuff) -}; - static bool8 StorytellerInitializeRandomStat(void) { - u8 arr[sStorytellerStuff.length]; - s32 i; - s32 j; + u8 storyIds[sNumStories]; + s32 i, j; - ScrambleStatList(arr, ARRAY_COUNT(sStorytellerStories)); - for (i = 0; i < (s32)ARRAY_COUNT(sStorytellerStories); i++) + ScrambleStatList(storyIds, sNumStories); + for (i = 0; i < sNumStories; i++) { - u8 stat = sStorytellerStories[arr[i]].stat; - u8 minVal = sStorytellerStories[arr[i]].minVal; + u8 stat = sStorytellerStories[storyIds[i]].stat; + u8 minVal = sStorytellerStories[storyIds[i]].minVal; for (j = 0; j < NUM_STORYTELLER_TALES; j++) {