diff --git a/gflib/malloc.h b/gflib/malloc.h index f2dcf6d46..8d49e0be7 100644 --- a/gflib/malloc.h +++ b/gflib/malloc.h @@ -12,6 +12,8 @@ ptr = NULL; \ } +#define TRY_FREE_AND_SET_NULL(ptr) if (ptr != NULL) FREE_AND_SET_NULL(ptr) + extern u8 gHeap[]; void *Alloc(u32 size); diff --git a/graphics/frontier_pass/tiles.bin b/graphics/frontier_pass/bg.bin similarity index 100% rename from graphics/frontier_pass/tiles.bin rename to graphics/frontier_pass/bg.bin diff --git a/graphics/frontier_pass/tiles.pal b/graphics/frontier_pass/bg.pal similarity index 100% rename from graphics/frontier_pass/tiles.pal rename to graphics/frontier_pass/bg.pal diff --git a/graphics/frontier_pass/tiles.png b/graphics/frontier_pass/bg.png similarity index 100% rename from graphics/frontier_pass/tiles.png rename to graphics/frontier_pass/bg.png diff --git a/graphics/frontier_pass/tilemap1.bin b/graphics/frontier_pass/cancel.bin similarity index 100% rename from graphics/frontier_pass/tilemap1.bin rename to graphics/frontier_pass/cancel.bin diff --git a/graphics/frontier_pass/tilemap2.bin b/graphics/frontier_pass/cancel_highlighted.bin similarity index 100% rename from graphics/frontier_pass/tilemap2.bin rename to graphics/frontier_pass/cancel_highlighted.bin diff --git a/graphics/frontier_pass/tiles2.png b/graphics/frontier_pass/map_and_card.png similarity index 100% rename from graphics/frontier_pass/tiles2.png rename to graphics/frontier_pass/map_and_card.png diff --git a/graphics/frontier_pass/unknown_571298.bin b/graphics/frontier_pass/unused.bin similarity index 100% rename from graphics/frontier_pass/unknown_571298.bin rename to graphics/frontier_pass/unused.bin diff --git a/include/graphics.h b/include/graphics.h index 9be05f38e..f4ad5ed9e 100644 --- a/include/graphics.h +++ b/include/graphics.h @@ -4958,13 +4958,13 @@ extern const u32 gKantoTrainerCardFrontLink_Tilemap[]; extern const u32 gHoennTrainerCardBg_Tilemap[]; // Frontier Pass -extern const u32 gUnknown_08DE08C8[]; -extern const u32 gUnknown_08DE2084[]; -extern const u32 gUnknown_08DE3350[]; -extern const u32 gUnknown_08DE3374[]; -extern const u32 gUnknown_08DE3060[]; +extern const u32 gFrontierPassBg_Gfx[]; +extern const u32 gFrontierPassBg_Tilemap[]; +extern const u16 gFrontierPassBg_Pal[][16]; +extern const u32 gFrontierPassMapAndCard_Gfx[]; +extern const u32 gFrontierPassCancelButton_Tilemap[]; +extern const u32 gFrontierPassCancelButtonHighlighted_Tilemap[]; extern const u32 gFrontierPassMedals_Gfx[]; -extern const u16 gUnknown_08DE07C8[][16]; extern const u16 gFrontierPassCursor_Pal[]; extern const u16 gFrontierPassMedalsGold_Pal[]; extern const u16 gFrontierPassMedalsSilver_Pal[]; diff --git a/src/frontier_pass.c b/src/frontier_pass.c index 2de27c36b..3be374fbd 100644 --- a/src/frontier_pass.c +++ b/src/frontier_pass.c @@ -38,14 +38,14 @@ enum WINDOW_BATTLE_RECORD, WINDOW_BATTLE_POINTS, WINDOW_DESCRIPTION, - WINDOW_4, + WINDOW_DUMMY, WINDOW_COUNT }; // Windows displayed in the facilities map view. enum { - MAP_WINDOW_0, + MAP_WINDOW_UNUSED, // Overlaps the "Battle Frontier" title area of the map MAP_WINDOW_NAME, MAP_WINDOW_DESCRIPTION, MAP_WINDOW_COUNT @@ -59,9 +59,39 @@ enum CURSOR_AREA_RECORD, CURSOR_AREA_CANCEL, CURSOR_AREA_POINTS, - CURSOR_AREA_EARNED_SYMBOLS, // The window. - CURSOR_AREA_SYMBOL, // All 7 symbols. - CURSOR_AREA_COUNT = CURSOR_AREA_SYMBOL + NUM_FRONTIER_FACILITIES, + CURSOR_AREA_EARNED_SYMBOLS, // The window containing the symbols + CURSOR_AREA_SYMBOL_TOWER, + CURSOR_AREA_SYMBOL_DOME, + CURSOR_AREA_SYMBOL_PALACE, + CURSOR_AREA_SYMBOL_ARENA, + CURSOR_AREA_SYMBOL_FACTORY, + CURSOR_AREA_SYMBOL_PIKE, + CURSOR_AREA_SYMBOL_PYRAMID, + CURSOR_AREA_COUNT +}; + +// Start of symbol cursor areas +#define CURSOR_AREA_SYMBOL CURSOR_AREA_SYMBOL_TOWER + +enum { + MAP_INDICATOR_RECTANGLE, + MAP_INDICATOR_SQUARE, +}; + +enum { + TAG_CURSOR, + TAG_MAP_INDICATOR, + TAG_MEDAL_SILVER, + TAG_MEDAL_GOLD, + TAG_HEAD_MALE, + TAG_HEAD_FEMALE, +}; + +// Error return codes. Never read +enum { + SUCCESS, + ERR_ALREADY_DONE, + ERR_ALLOC_FAILED, }; struct FrontierPassData @@ -73,25 +103,26 @@ struct FrontierPassData s16 cursorY; u8 cursorArea; u8 previousCursorArea; - u8 hasBattleRecord:1; - u8 unkE:3; + bool8 hasBattleRecord:1; + u8 areaToShow:3; u8 trainerStars:4; - u8 facilitySymbols[NUM_FRONTIER_FACILITIES]; + u8 facilitySymbols[NUM_FRONTIER_FACILITIES]; // 0: no symbol, 1: silver, 2: gold }; struct FrontierPassGfx { struct Sprite *cursorSprite; struct Sprite *symbolSprites[NUM_FRONTIER_FACILITIES]; - u8 *unk20; - u8 *unk24; - u8 *unk28; - bool8 setAffine; - s16 unk2E; - s16 unk30; - u8 tilemapBuff1[0x1000]; - u8 tilemapBuff2[0x1000]; - u8 tilemapBuff3[0x400]; + // These 3 tilemaps are used to overwrite the respective area when highlighted + u8 *mapAndCardZoomTilemap; + u8 *mapAndCardTilemap; + u8 *battleRecordTilemap; + bool8 zooming; + s16 scaleX; + s16 scaleY; + u8 tilemapBuff1[BG_SCREEN_SIZE * 2]; + u8 tilemapBuff2[BG_SCREEN_SIZE * 2]; + u8 tilemapBuff3[BG_SCREEN_SIZE / 2]; }; struct FrontierPassSaved @@ -109,9 +140,9 @@ struct FrontierMapData struct Sprite *mapIndicatorSprite; u8 cursorPos; u8 unused; - u8 tilemapBuff0[0x1000]; - u8 tilemapBuff1[0x1000]; - u8 tilemapBuff2[0x1000]; + u8 tilemapBuff0[BG_SCREEN_SIZE * 2]; + u8 tilemapBuff1[BG_SCREEN_SIZE * 2]; + u8 tilemapBuff2[BG_SCREEN_SIZE * 2]; }; static EWRAM_DATA struct FrontierPassData *sPassData = NULL; @@ -119,37 +150,39 @@ static EWRAM_DATA struct FrontierPassGfx *sPassGfx = NULL; static EWRAM_DATA struct FrontierMapData *sMapData = NULL; static EWRAM_DATA struct FrontierPassSaved sSavedPassData = {0}; -// This file's functions. static u32 AllocateFrontierPassData(void (*callback)(void)); static void ShowFrontierMap(void (*callback)(void)); static void CB2_InitFrontierPass(void); -static void sub_80C629C(void); +static void DrawFrontierPassBg(void); static void FreeCursorAndSymbolSprites(void); static void LoadCursorAndSymbolSprites(void); static u32 FreeFrontierPassData(void); static bool32 InitFrontierPass(void); static bool32 HideFrontierPass(void); -static void Task_HandleFrontierPassInput(u8 taskId); -static void Task_DoFadeEffect(u8 taskId); -static void sub_80C6104(u8 cursorArea, u8 previousCursorArea); -static void PrintAreaDescription(u8 cursorArea); -static void sub_80C5F58(bool8 arg0, bool8 arg1); -static void SpriteCb_Dummy(struct Sprite *sprite); +static void Task_HandleFrontierPassInput(u8); +static void Task_PassAreaZoom(u8); +static void UpdateAreaHighlight(u8, u8); +static void PrintAreaDescription(u8); +static void ShowHideZoomingArea(bool8, bool8); +static void SpriteCB_PlayerHead(struct Sprite *); -// Const rom data. -static const u16 sMaleHeadPalette[] = INCBIN_U16("graphics/frontier_pass/map_heads.gbapal"); -static const u16 sFemaleHeadPalette[] = INCBIN_U16("graphics/frontier_pass/map_heads_female.gbapal"); -static const u32 gUnknown_0856FBBC[] = INCBIN_U32("graphics/frontier_pass/map_screen.4bpp.lz"); -static const u32 sCursorGfx[] = INCBIN_U32("graphics/frontier_pass/cursor.4bpp.lz"); -static const u32 sHeadsGfx[] = INCBIN_U32("graphics/frontier_pass/map_heads.4bpp.lz"); -static const u32 sMapCursorGfx[] = INCBIN_U32("graphics/frontier_pass/map_cursor.4bpp.lz"); -static const u32 gUnknown_08570E00[] = INCBIN_U32("graphics/frontier_pass/map_screen.bin.lz"); -static const u32 gUnknown_08571060[] = INCBIN_U32("graphics/frontier_pass/small_map_and_card.bin.lz"); -static const u32 gUnknown_08571298[] = INCBIN_U32("graphics/frontier_pass/unknown_571298.bin"); -static const u32 gUnknown_085712C0[] = INCBIN_U32("graphics/frontier_pass/record_frame.bin.lz"); -static const u32 gUnknown_085712F8[] = INCBIN_U32("graphics/frontier_pass/small_map_and_card_affine.bin.lz"); +static const u16 sMaleHead_Pal[] = INCBIN_U16("graphics/frontier_pass/map_heads.gbapal"); +static const u16 sFemaleHead_Pal[] = INCBIN_U16("graphics/frontier_pass/map_heads_female.gbapal"); +static const u32 sMapScreen_Gfx[] = INCBIN_U32("graphics/frontier_pass/map_screen.4bpp.lz"); +static const u32 sCursor_Gfx[] = INCBIN_U32("graphics/frontier_pass/cursor.4bpp.lz"); +static const u32 sHeads_Gfx[] = INCBIN_U32("graphics/frontier_pass/map_heads.4bpp.lz"); +static const u32 sMapCursor_Gfx[] = INCBIN_U32("graphics/frontier_pass/map_cursor.4bpp.lz"); +static const u32 sMapScreen_Tilemap[] = INCBIN_U32("graphics/frontier_pass/map_screen.bin.lz"); +static const u32 sMapAndCard_ZoomedOut_Tilemap[] = INCBIN_U32("graphics/frontier_pass/small_map_and_card.bin.lz"); +static const u32 sUnusedData[] = INCBIN_U32("graphics/frontier_pass/unused.bin"); +static const u32 sBattleRecord_Tilemap[] = INCBIN_U32("graphics/frontier_pass/record_frame.bin.lz"); +static const u32 sMapAndCard_Zooming_Tilemap[] = INCBIN_U32("graphics/frontier_pass/small_map_and_card_affine.bin.lz"); -static const s16 gUnknown_085713E0[][2] = {{216, 32}, {216, 128}}; +static const s16 sBgAffineCoords[][2] = +{ + [CURSOR_AREA_MAP - 1] = {216, 32}, + [CURSOR_AREA_CARD - 1] = {216, 128} +}; static const struct BgTemplate sPassBgTemplates[] = { @@ -213,9 +246,9 @@ static const struct BgTemplate sMapBgTemplates[] = }, }; -static const struct WindowTemplate sPassWindowTemplates[] = +static const struct WindowTemplate sPassWindowTemplates[WINDOW_COUNT] = { - { + [WINDOW_EARNED_SYMBOLS] = { .bg = 0, .tilemapLeft = 2, .tilemapTop = 3, @@ -224,7 +257,7 @@ static const struct WindowTemplate sPassWindowTemplates[] = .paletteNum = 15, .baseBlock = 0x1, }, - { + [WINDOW_BATTLE_RECORD] = { .bg = 0, .tilemapLeft = 2, .tilemapTop = 10, @@ -233,7 +266,7 @@ static const struct WindowTemplate sPassWindowTemplates[] = .paletteNum = 15, .baseBlock = 0x26, }, - { + [WINDOW_BATTLE_POINTS] = { .bg = 0, .tilemapLeft = 2, .tilemapTop = 13, @@ -242,7 +275,7 @@ static const struct WindowTemplate sPassWindowTemplates[] = .paletteNum = 15, .baseBlock = 0x4B, }, - { + [WINDOW_DESCRIPTION] = { .bg = 0, .tilemapLeft = 0, .tilemapTop = 18, @@ -256,7 +289,7 @@ static const struct WindowTemplate sPassWindowTemplates[] = static const struct WindowTemplate sMapWindowTemplates[] = { - { + [MAP_WINDOW_UNUSED] = { .bg = 0, .tilemapLeft = 0, .tilemapTop = 1, @@ -265,7 +298,7 @@ static const struct WindowTemplate sMapWindowTemplates[] = .paletteNum = 15, .baseBlock = 0x1, }, - { + [MAP_WINDOW_NAME] = { .bg = 0, .tilemapLeft = 20, .tilemapTop = 1, @@ -274,7 +307,7 @@ static const struct WindowTemplate sMapWindowTemplates[] = .paletteNum = 15, .baseBlock = 0x4D, }, - { + [MAP_WINDOW_DESCRIPTION] = { .bg = 0, .tilemapLeft = 2, .tilemapTop = 16, @@ -300,159 +333,162 @@ struct s16 xStart; s16 xEnd; } -static const sPassAreasLayout[] = +static const sPassAreasLayout[CURSOR_AREA_COUNT - 1] = { - {28, 76, 132, 220}, - {84, 132, 132, 220}, - {80, 102, 20, 108}, - {0, 16, 152, 240}, - {108, 134, 20, 108}, - {24, 48, 20, 108}, - {50, 66, 20, 36}, - {66, 82, 32, 48}, - {50, 66, 44, 60}, - {66, 82, 56, 72}, - {50, 66, 68, 84}, - {66, 82, 80, 96}, - {50, 66, 92, 108}, + [CURSOR_AREA_MAP - 1] = { 28, 76, 132, 220}, + [CURSOR_AREA_CARD - 1] = { 84, 132, 132, 220}, + [CURSOR_AREA_RECORD - 1] = { 80, 102, 20, 108}, + [CURSOR_AREA_CANCEL - 1] = { 0, 16, 152, 240}, + [CURSOR_AREA_POINTS - 1] = {108, 134, 20, 108}, + [CURSOR_AREA_EARNED_SYMBOLS - 1] = { 24, 48, 20, 108}, + [CURSOR_AREA_SYMBOL_TOWER - 1] = { 50, 66, 20, 36}, + [CURSOR_AREA_SYMBOL_DOME - 1] = { 66, 82, 32, 48}, + [CURSOR_AREA_SYMBOL_PALACE - 1] = { 50, 66, 44, 60}, + [CURSOR_AREA_SYMBOL_ARENA - 1] = { 66, 82, 56, 72}, + [CURSOR_AREA_SYMBOL_FACTORY - 1] = { 50, 66, 68, 84}, + [CURSOR_AREA_SYMBOL_PIKE - 1] = { 66, 82, 80, 96}, + [CURSOR_AREA_SYMBOL_PYRAMID - 1] = { 50, 66, 92, 108}, }; static const struct CompressedSpriteSheet sCursorSpriteSheets[] = { - {sCursorGfx, 0x100, 0}, - {sMapCursorGfx, 0x400, 1}, - {gFrontierPassMedals_Gfx, 0x380, 2}, + {sCursor_Gfx, 0x100, TAG_CURSOR}, + {sMapCursor_Gfx, 0x400, TAG_MAP_INDICATOR}, + {gFrontierPassMedals_Gfx, 0x380, TAG_MEDAL_SILVER}, }; static const struct CompressedSpriteSheet sHeadsSpriteSheet[] = { - {sHeadsGfx, 0x100, 4}, + {sHeads_Gfx, 0x100, TAG_HEAD_MALE}, {} }; static const struct SpritePalette sSpritePalettes[] = { - {gFrontierPassCursor_Pal, 0}, - {gFrontierPassMapCursor_Pal, 1}, - {gFrontierPassMedalsSilver_Pal, 2}, - {gFrontierPassMedalsGold_Pal, 3}, - {sMaleHeadPalette, 4}, - {sFemaleHeadPalette, 5}, + {gFrontierPassCursor_Pal, TAG_CURSOR}, + {gFrontierPassMapCursor_Pal, TAG_MAP_INDICATOR}, + {gFrontierPassMedalsSilver_Pal, TAG_MEDAL_SILVER}, + {gFrontierPassMedalsGold_Pal, TAG_MEDAL_GOLD}, + {sMaleHead_Pal, TAG_HEAD_MALE}, + {sFemaleHead_Pal, TAG_HEAD_FEMALE}, {} }; -static const union AnimCmd sSpriteAnim_857151C[] = +static const union AnimCmd sAnim_Frame1_Unused[] = { ANIMCMD_FRAME(0, 0), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_8571524[] = +static const union AnimCmd sAnim_Frame1[] = { ANIMCMD_FRAME(0, 0), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_857152C[] = +static const union AnimCmd sAnim_Frame2[] = { ANIMCMD_FRAME(4, 0), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_8571534[] = +static const union AnimCmd sAnim_Frame3[] = { ANIMCMD_FRAME(8, 0), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_857153C[] = +static const union AnimCmd sAnim_Frame4[] = { ANIMCMD_FRAME(12, 0), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_8571544[] = +static const union AnimCmd sAnim_Frame5[] = { ANIMCMD_FRAME(16, 0), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_857154C[] = +static const union AnimCmd sAnim_Frame6[] = { ANIMCMD_FRAME(20, 0), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_8571554[] = +static const union AnimCmd sAnim_Frame7[] = { ANIMCMD_FRAME(24, 0), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_857155C[] = +static const union AnimCmd sAnim_MapIndicatorCursor_Rectangle[] = { ANIMCMD_FRAME(0, 45), ANIMCMD_FRAME(8, 45), ANIMCMD_JUMP(0) }; -static const union AnimCmd sSpriteAnim_8571568[] = +static const union AnimCmd sAnim_MapIndicatorCursor_Square[] = { ANIMCMD_FRAME(16, 45), ANIMCMD_FRAME(24, 45), ANIMCMD_JUMP(0) }; -static const union AnimCmd *const sSpriteAnimTable_8571574[] = +// Used both by the cursor and the map head icons +static const union AnimCmd *const sAnims_TwoFrame[] = { - sSpriteAnim_8571524, - sSpriteAnim_857152C + sAnim_Frame1, + sAnim_Frame2 }; -static const union AnimCmd *const sSpriteAnimTable_857157C[] = +static const union AnimCmd *const sAnims_Medal[] = { - sSpriteAnim_8571524, - sSpriteAnim_857152C, - sSpriteAnim_8571534, - sSpriteAnim_857153C, - sSpriteAnim_8571544, - sSpriteAnim_857154C, - sSpriteAnim_8571554 + [CURSOR_AREA_SYMBOL_TOWER - CURSOR_AREA_SYMBOL] = sAnim_Frame1, + [CURSOR_AREA_SYMBOL_DOME - CURSOR_AREA_SYMBOL] = sAnim_Frame2, + [CURSOR_AREA_SYMBOL_PALACE - CURSOR_AREA_SYMBOL] = sAnim_Frame3, + [CURSOR_AREA_SYMBOL_ARENA - CURSOR_AREA_SYMBOL] = sAnim_Frame4, + [CURSOR_AREA_SYMBOL_FACTORY - CURSOR_AREA_SYMBOL] = sAnim_Frame5, + [CURSOR_AREA_SYMBOL_PIKE - CURSOR_AREA_SYMBOL] = sAnim_Frame6, + [CURSOR_AREA_SYMBOL_PYRAMID - CURSOR_AREA_SYMBOL] = sAnim_Frame7 }; -static const union AnimCmd *const sSpriteAnimTable_8571598[] = +static const union AnimCmd *const sAnims_MapIndicatorCursor[] = { - sSpriteAnim_857155C, - sSpriteAnim_8571568 + [MAP_INDICATOR_RECTANGLE] = sAnim_MapIndicatorCursor_Rectangle, + [MAP_INDICATOR_SQUARE] = sAnim_MapIndicatorCursor_Square }; -static const union AffineAnimCmd sSpriteAffineAnim_85715A0[] = +static const union AffineAnimCmd sAffineAnim_Unused[] = { AFFINEANIMCMD_FRAME(256, 256, 0, 0), AFFINEANIMCMD_END }; -static const union AffineAnimCmd *const sSpriteAffineAnimTable_85715B0[] = +static const union AffineAnimCmd *const sAffineAnims_Unused[] = { - sSpriteAffineAnim_85715A0 + sAffineAnim_Unused }; static const struct SpriteTemplate sSpriteTemplates_Cursors[] = { + // Triangular cursor { - .tileTag = 0, - .paletteTag = 0, + .tileTag = TAG_CURSOR, + .paletteTag = TAG_CURSOR, .oam = &gOamData_AffineOff_ObjNormal_16x16, - .anims = sSpriteAnimTable_8571574, + .anims = sAnims_TwoFrame, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy, }, + // Map indicator cursor { - .tileTag = 1, - .paletteTag = 1, + .tileTag = TAG_MAP_INDICATOR, + .paletteTag = TAG_MAP_INDICATOR, .oam = &gOamData_AffineOff_ObjNormal_32x16, - .anims = sSpriteAnimTable_8571598, + .anims = sAnims_MapIndicatorCursor, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy, @@ -461,43 +497,43 @@ static const struct SpriteTemplate sSpriteTemplates_Cursors[] = static const struct SpriteTemplate sSpriteTemplate_Medal = { - .tileTag = 2, - .paletteTag = 2, + .tileTag = TAG_MEDAL_SILVER, + .paletteTag = TAG_MEDAL_SILVER, .oam = &gOamData_AffineOff_ObjNormal_16x16, - .anims = sSpriteAnimTable_857157C, + .anims = sAnims_Medal, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy, }; -static const struct SpriteTemplate sSpriteTemplate_Head = +static const struct SpriteTemplate sSpriteTemplate_PlayerHead = { - .tileTag = 4, - .paletteTag = 4, + .tileTag = TAG_HEAD_MALE, + .paletteTag = TAG_HEAD_MALE, .oam = &gOamData_AffineOff_ObjNormal_16x16, - .anims = sSpriteAnimTable_8571574, + .anims = sAnims_TwoFrame, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = SpriteCb_Dummy, + .callback = SpriteCB_PlayerHead, }; -static const u8 *const sPassAreaDescriptions[] = +static const u8 *const sPassAreaDescriptions[CURSOR_AREA_COUNT + 1] = { - gText_ThereIsNoBattleRecord, - gText_CheckFrontierMap, - gText_CheckTrainerCard, - gText_ViewRecordedBattle, - gText_PutAwayFrontierPass, - gText_CurrentBattlePoints, - gText_CollectedSymbols, - gText_BattleTowerAbilitySymbol, - gText_BattleDomeTacticsSymbol, - gText_BattlePalaceSpiritsSymbol, - gText_BattleArenaGutsSymbol, - gText_BattleFactoryKnowledgeSymbol, - gText_BattlePikeLuckSymbol, - gText_BattlePyramidBraveSymbol, - gText_EmptyString7, + [CURSOR_AREA_NOTHING] = gText_ThereIsNoBattleRecord, // NOTHING is re-used for CURSOR_AREA_RECORD when no Record is present + [CURSOR_AREA_MAP] = gText_CheckFrontierMap, + [CURSOR_AREA_CARD] = gText_CheckTrainerCard, + [CURSOR_AREA_RECORD] = gText_ViewRecordedBattle, + [CURSOR_AREA_CANCEL] = gText_PutAwayFrontierPass, + [CURSOR_AREA_POINTS] = gText_CurrentBattlePoints, + [CURSOR_AREA_EARNED_SYMBOLS] = gText_CollectedSymbols, + [CURSOR_AREA_SYMBOL_TOWER] = gText_BattleTowerAbilitySymbol, + [CURSOR_AREA_SYMBOL_DOME] = gText_BattleDomeTacticsSymbol, + [CURSOR_AREA_SYMBOL_PALACE] = gText_BattlePalaceSpiritsSymbol, + [CURSOR_AREA_SYMBOL_ARENA] = gText_BattleArenaGutsSymbol, + [CURSOR_AREA_SYMBOL_FACTORY] = gText_BattleFactoryKnowledgeSymbol, + [CURSOR_AREA_SYMBOL_PIKE] = gText_BattlePikeLuckSymbol, + [CURSOR_AREA_SYMBOL_PYRAMID] = gText_BattlePyramidBraveSymbol, + [CURSOR_AREA_COUNT] = gText_EmptyString7, }; struct @@ -507,18 +543,17 @@ struct s16 x; s16 y; u8 animNum; -} static const sMapLandmarks[] = +} static const sMapLandmarks[NUM_FRONTIER_FACILITIES] = { - {gText_BattleTower3, gText_BattleTowerDesc, 0x59, 0x28, 1}, - {gText_BattleDome2, gText_BattleDomeDesc, 0x21, 0x2A, 1}, - {gText_BattlePalace2, gText_BattlePalaceDesc, 0x78, 0x56, 0}, - {gText_BattleArena2, gText_BattleArenaDesc, 0x72, 0x3B, 0}, - {gText_BattleFactory2, gText_BattleFactoryDesc, 0x19, 0x43, 0}, - {gText_BattlePike2, gText_BattlePikeDesc, 0x39, 0x39, 1}, - {gText_BattlePyramid2, gText_BattlePyramidDesc, 0x86, 0x29, 1}, + [FRONTIER_FACILITY_TOWER] = {gText_BattleTower3, gText_BattleTowerDesc, 89, 40, MAP_INDICATOR_SQUARE}, + [FRONTIER_FACILITY_DOME] = {gText_BattleDome2, gText_BattleDomeDesc, 33, 42, MAP_INDICATOR_SQUARE}, + [FRONTIER_FACILITY_PALACE] = {gText_BattlePalace2, gText_BattlePalaceDesc, 120, 86, MAP_INDICATOR_RECTANGLE}, + [FRONTIER_FACILITY_ARENA] = {gText_BattleArena2, gText_BattleArenaDesc, 114, 59, MAP_INDICATOR_RECTANGLE}, + [FRONTIER_FACILITY_FACTORY] = {gText_BattleFactory2, gText_BattleFactoryDesc, 25, 67, MAP_INDICATOR_RECTANGLE}, + [FRONTIER_FACILITY_PIKE] = {gText_BattlePike2, gText_BattlePikeDesc, 57, 57, MAP_INDICATOR_SQUARE}, + [FRONTIER_FACILITY_PYRAMID] = {gText_BattlePyramid2, gText_BattlePyramidDesc, 134, 41, MAP_INDICATOR_SQUARE}, }; -// code static void ResetGpuRegsAndBgs(void) { SetGpuReg(REG_OFFSET_DISPCNT, 0); @@ -564,30 +599,34 @@ static u32 AllocateFrontierPassData(void (*callback)(void)) u8 i; if (sPassData != NULL) - return 1; + return ERR_ALREADY_DONE; sPassData = AllocZeroed(sizeof(*sPassData)); if (sPassData == NULL) - return 2; + return ERR_ALLOC_FAILED; sPassData->callback = callback; i = GetCurrentRegionMapSectionId(); if (i != MAPSEC_BATTLE_FRONTIER && i != MAPSEC_ARTISAN_CAVE) { + // Player is not in the frontier, set + // cursor position to the Trainer Card sPassData->cursorX = 176; sPassData->cursorY = 104; } else { + // Player is in the frontier, set + // cursor position to the frontier map sPassData->cursorX = 176; sPassData->cursorY = 48; } sPassData->battlePoints = gSaveBlock2Ptr->frontier.battlePoints; sPassData->hasBattleRecord = CanCopyRecordedBattleSaveData(); - sPassData->unkE = 0; + sPassData->areaToShow = CURSOR_AREA_NOTHING; sPassData->trainerStars = CountPlayerTrainerStars(); - for (i = 0; i < 7; i++) + for (i = 0; i < NUM_FRONTIER_FACILITIES; i++) { if (FlagGet(FLAG_SYS_TOWER_SILVER + i * 2)) sPassData->facilitySymbols[i]++; @@ -595,60 +634,57 @@ static u32 AllocateFrontierPassData(void (*callback)(void)) sPassData->facilitySymbols[i]++; } - return 0; + return SUCCESS; } static u32 FreeFrontierPassData(void) { if (sPassData == NULL) - return 1; + return ERR_ALREADY_DONE; memset(sPassData, 0, sizeof(*sPassData)); // Why clear data, if it's going to be freed anyway? FREE_AND_SET_NULL(sPassData); - return 0; + return SUCCESS; } static u32 AllocateFrontierPassGfx(void) { if (sPassGfx != NULL) - return 1; + return ERR_ALREADY_DONE; sPassGfx = AllocZeroed(sizeof(*sPassGfx)); if (sPassGfx == NULL) - return 2; + return ERR_ALLOC_FAILED; - return 0; + return SUCCESS; } static u32 FreeFrontierPassGfx(void) { FreeAllWindowBuffers(); if (sPassGfx == NULL) - return 1; + return ERR_ALREADY_DONE; - if (sPassGfx->unk28 != NULL) - FREE_AND_SET_NULL(sPassGfx->unk28); - if (sPassGfx->unk24 != NULL) - FREE_AND_SET_NULL(sPassGfx->unk24); - if (sPassGfx->unk20 != NULL) - FREE_AND_SET_NULL(sPassGfx->unk20); + TRY_FREE_AND_SET_NULL(sPassGfx->battleRecordTilemap); + TRY_FREE_AND_SET_NULL(sPassGfx->mapAndCardTilemap); + TRY_FREE_AND_SET_NULL(sPassGfx->mapAndCardZoomTilemap); memset(sPassGfx, 0, sizeof(*sPassGfx)); // Why clear data, if it's going to be freed anyway? FREE_AND_SET_NULL(sPassGfx); - return 0; + return SUCCESS; } -static void VblankCb_FrontierPass(void) +static void VBlankCB_FrontierPass(void) { - if (sPassGfx->setAffine) + if (sPassGfx->zooming) { SetBgAffine(2, - gUnknown_085713E0[sPassData->unkE - 1][0] << 8, - gUnknown_085713E0[sPassData->unkE - 1][1] << 8, - gUnknown_085713E0[sPassData->unkE - 1][0], - gUnknown_085713E0[sPassData->unkE - 1][1], - sPassGfx->unk2E, - sPassGfx->unk30, + sBgAffineCoords[sPassData->areaToShow - 1][0] << 8, + sBgAffineCoords[sPassData->areaToShow - 1][1] << 8, + sBgAffineCoords[sPassData->areaToShow - 1][0], + sBgAffineCoords[sPassData->areaToShow - 1][1], + sPassGfx->scaleX, + sPassGfx->scaleY, 0); } LoadOam(); @@ -716,11 +752,11 @@ static bool32 InitFrontierPass(void) DeactivateAllTextPrinters(); break; case 6: - sPassGfx->unk20 = malloc_and_decompress(gUnknown_085712F8, &sizeOut); - sPassGfx->unk24 = malloc_and_decompress(gUnknown_08571060, &sizeOut); - sPassGfx->unk28 = malloc_and_decompress(gUnknown_085712C0, &sizeOut); - DecompressAndCopyTileDataToVram(1, gUnknown_08DE08C8, 0, 0, 0); - DecompressAndCopyTileDataToVram(2, gUnknown_08DE2084, 0, 0, 0); + sPassGfx->mapAndCardZoomTilemap = malloc_and_decompress(sMapAndCard_Zooming_Tilemap, &sizeOut); + sPassGfx->mapAndCardTilemap = malloc_and_decompress(sMapAndCard_ZoomedOut_Tilemap, &sizeOut); + sPassGfx->battleRecordTilemap = malloc_and_decompress(sBattleRecord_Tilemap, &sizeOut); + DecompressAndCopyTileDataToVram(1, gFrontierPassBg_Gfx, 0, 0, 0); + DecompressAndCopyTileDataToVram(2, gFrontierPassMapAndCard_Gfx, 0, 0, 0); break; case 7: if (FreeTempTileDataBuffersIfPossible()) @@ -733,12 +769,12 @@ static bool32 InitFrontierPass(void) CopyBgTilemapBufferToVram(2); break; case 8: - LoadPalette(gUnknown_08DE07C8[0], 0, 0x1A0); - LoadPalette(gUnknown_08DE07C8[1 + sPassData->trainerStars], 0x10, 0x20); + LoadPalette(gFrontierPassBg_Pal[0], 0, 0x1A0); + LoadPalette(gFrontierPassBg_Pal[1 + sPassData->trainerStars], 0x10, 0x20); LoadPalette(GetTextWindowPalette(0), 0xF0, 0x20); - sub_80C629C(); - sub_80C6104(sPassData->cursorArea, sPassData->previousCursorArea); - if (sPassData->unkE == 1 || sPassData->unkE == 2) + DrawFrontierPassBg(); + UpdateAreaHighlight(sPassData->cursorArea, sPassData->previousCursorArea); + if (sPassData->areaToShow == CURSOR_AREA_MAP || sPassData->areaToShow == CURSOR_AREA_CARD) { sPassData->state = 0; return TRUE; @@ -750,9 +786,9 @@ static bool32 InitFrontierPass(void) ShowBg(1); ShowBg(2); LoadCursorAndSymbolSprites(); - SetVBlankCallback(VblankCb_FrontierPass); - BlendPalettes(PALETTES_ALL, 0x10, RGB_BLACK); - BeginNormalPaletteFade(PALETTES_ALL, 0, 0x10, 0, RGB_BLACK); + SetVBlankCallback(VBlankCB_FrontierPass); + BlendPalettes(PALETTES_ALL, 16, RGB_BLACK); + BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK); break; case 10: AnimateSprites(); @@ -773,9 +809,9 @@ static bool32 HideFrontierPass(void) switch (sPassData->state) { case 0: - if (sPassData->unkE != 1 && sPassData->unkE != 2) + if (sPassData->areaToShow != CURSOR_AREA_MAP && sPassData->areaToShow != CURSOR_AREA_CARD) { - BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 0x10, RGB_BLACK); + BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); } else { @@ -822,11 +858,11 @@ static u8 GetCursorAreaFromCoords(s16 x, s16 y) { u8 i; - // Minus/Plus 1, because the table doesn't take into account the nothing field. + // Minus/Plus 1, because the table doesn't take CURSOR_AREA_NOTHING into account. for (i = 0; i < CURSOR_AREA_COUNT - 1; i++) { if (sPassAreasLayout[i].yStart <= y && sPassAreasLayout[i].yEnd >= y - && sPassAreasLayout[i].xStart <= x && sPassAreasLayout[i].xEnd >= x) + && sPassAreasLayout[i].xStart <= x && sPassAreasLayout[i].xEnd >= x) { if (i >= CURSOR_AREA_SYMBOL - 1 && sPassData->facilitySymbols[i - CURSOR_AREA_SYMBOL + 1] == 0) break; @@ -835,9 +871,12 @@ static u8 GetCursorAreaFromCoords(s16 x, s16 y) } } - return 0; + return CURSOR_AREA_NOTHING; } +// For Task_PassAreaZoom +#define tZoomOut data[0] + void CB2_ReshowFrontierPass(void) { u8 taskId; @@ -845,16 +884,16 @@ void CB2_ReshowFrontierPass(void) if (!InitFrontierPass()) return; - switch (sPassData->unkE) + switch (sPassData->areaToShow) { - case 1: - case 2: - taskId = CreateTask(Task_DoFadeEffect, 0); - gTasks[taskId].data[0] = TRUE; + case CURSOR_AREA_MAP: + case CURSOR_AREA_CARD: + taskId = CreateTask(Task_PassAreaZoom, 0); + gTasks[taskId].tZoomOut = TRUE; break; - case 3: + case CURSOR_AREA_RECORD: default: - sPassData->unkE = 0; + sPassData->areaToShow = CURSOR_AREA_NOTHING; taskId = CreateTask(Task_HandleFrontierPassInput, 0); break; } @@ -889,19 +928,19 @@ static void CB2_ShowFrontierPassFeature(void) if (!HideFrontierPass()) return; - switch (sPassData->unkE) + switch (sPassData->areaToShow) { - case 1: + case CURSOR_AREA_MAP: ShowFrontierMap(CB2_ReshowFrontierPass); break; - case 3: + case CURSOR_AREA_RECORD: sSavedPassData.callback = sPassData->callback; sSavedPassData.cursorX = sPassData->cursorX; sSavedPassData.cursorY = sPassData->cursorY; FreeFrontierPassData(); PlayRecordedBattle(CB2_ReturnFromRecord); break; - case 2: + case CURSOR_AREA_CARD: ShowPlayerTrainerCard(CB2_ReshowFrontierPass); break; } @@ -914,15 +953,15 @@ static bool32 TryCallPassAreaFunction(u8 taskId, u8 cursorArea) case CURSOR_AREA_RECORD: if (!sPassData->hasBattleRecord) return FALSE; - sPassData->unkE = 3; + sPassData->areaToShow = CURSOR_AREA_RECORD; DestroyTask(taskId); SetMainCallback2(CB2_ShowFrontierPassFeature); break; case CURSOR_AREA_MAP: case CURSOR_AREA_CARD: - sPassData->unkE = cursorArea; - gTasks[taskId].func = Task_DoFadeEffect; - gTasks[taskId].data[0] = FALSE; + sPassData->areaToShow = cursorArea; + gTasks[taskId].func = Task_PassAreaZoom; + gTasks[taskId].tZoomOut = FALSE; break; default: return FALSE; @@ -1004,77 +1043,92 @@ static void Task_HandleFrontierPassInput(u8 taskId) PrintAreaDescription(var); sPassData->previousCursorArea = sPassData->cursorArea; sPassData->cursorArea = var; - sub_80C6104(sPassData->cursorArea, sPassData->previousCursorArea); + UpdateAreaHighlight(sPassData->cursorArea, sPassData->previousCursorArea); } } } -static void Task_DoFadeEffect(u8 taskId) +#define tScaleX data[1] +#define tScaleY data[2] +#define tScaleSpeedX data[3] +#define tScaleSpeedY data[4] + +// Zoom in/out for the Frontier map or the trainer card +static void Task_PassAreaZoom(u8 taskId) { s16 *data = gTasks[taskId].data; switch (sPassData->state) { case 0: - if (!data[0]) + // Initialize the zoom, start fading in/out + if (!tZoomOut) { - sub_80C5F58(TRUE, FALSE); - data[1] = Q_8_8(1); - data[2] = Q_8_8(1); - data[3] = 0x15; - data[4] = 0x15; - BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 0x10, RGB_WHITE); + // Zooming in to map/card screen + ShowHideZoomingArea(TRUE, FALSE); + tScaleX = Q_8_8(1); + tScaleY = Q_8_8(1); + tScaleSpeedX = 0x15; + tScaleSpeedY = 0x15; + BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_WHITE); } else { - data[1] = Q_8_8(1.984375); // 1 and 63/64 - data[2] = Q_8_8(1.984375); - data[3] = -0x15; - data[4] = -0x15; + // Zooming out of map/card screen back to frontier pass + tScaleX = Q_8_8(1.984375); // 1 and 63/64 + tScaleY = Q_8_8(1.984375); + tScaleSpeedX = -0x15; + tScaleSpeedY = -0x15; SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); ShowBg(0); ShowBg(1); ShowBg(2); LoadCursorAndSymbolSprites(); - SetVBlankCallback(VblankCb_FrontierPass); - BlendPalettes(PALETTES_ALL, 0x10, RGB_WHITE); - BeginNormalPaletteFade(PALETTES_ALL, 0, 0x10, 0, RGB_WHITE); + SetVBlankCallback(VBlankCB_FrontierPass); + BlendPalettes(PALETTES_ALL, 16, RGB_WHITE); + BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_WHITE); } - sPassGfx->setAffine = TRUE; - sPassGfx->unk2E = MathUtil_Inv16(data[1]); - sPassGfx->unk30 = MathUtil_Inv16(data[2]); + sPassGfx->zooming = TRUE; + sPassGfx->scaleX = MathUtil_Inv16(tScaleX); + sPassGfx->scaleY = MathUtil_Inv16(tScaleY); break; case 1: + // Update the fade and zoom UpdatePaletteFade(); - data[1] += data[3]; - data[2] += data[4]; - sPassGfx->unk2E = MathUtil_Inv16(data[1]); - sPassGfx->unk30 = MathUtil_Inv16(data[2]); - if (!data[0]) + tScaleX += tScaleSpeedX; + tScaleY += tScaleSpeedY; + sPassGfx->scaleX = MathUtil_Inv16(tScaleX); + sPassGfx->scaleY = MathUtil_Inv16(tScaleY); + + // Check if zoom hasn't reached target + if (!tZoomOut) { - if (data[1] <= Q_8_8(1.984375)) + if (tScaleX <= Q_8_8(1.984375)) return; } else { - if (data[1] != Q_8_8(1)) + if (tScaleX != Q_8_8(1)) return; } break; case 2: - if (sPassGfx->setAffine) // Nonsensical check. - sPassGfx->setAffine = FALSE; + if (sPassGfx->zooming) + sPassGfx->zooming = FALSE; if (UpdatePaletteFade()) return; - if (!data[0]) + + if (!tZoomOut) { + // Zoomed in and faded out, switch to map or trainer card DestroyTask(taskId); SetMainCallback2(CB2_ShowFrontierPassFeature); } else { - sub_80C5F58(FALSE, FALSE); - sPassData->unkE = 0; + // Zoomed out and faded in, return to frontier pass + ShowHideZoomingArea(FALSE, FALSE); + sPassData->areaToShow = CURSOR_AREA_NOTHING; gTasks[taskId].func = Task_HandleFrontierPassInput; } SetBgAttribute(2, BG_ATTR_WRAPAROUND, 0); @@ -1120,8 +1174,9 @@ static void ShowAndPrintWindows(void) static void PrintAreaDescription(u8 cursorArea) { FillWindowPixelBuffer(WINDOW_DESCRIPTION, PIXEL_FILL(0)); + if (cursorArea == CURSOR_AREA_RECORD && !sPassData->hasBattleRecord) - AddTextPrinterParameterized3(WINDOW_DESCRIPTION, 1, 2, 0, sTextColors[1], 0, sPassAreaDescriptions[0]); + AddTextPrinterParameterized3(WINDOW_DESCRIPTION, 1, 2, 0, sTextColors[1], 0, sPassAreaDescriptions[CURSOR_AREA_NOTHING]); else if (cursorArea != CURSOR_AREA_NOTHING) AddTextPrinterParameterized3(WINDOW_DESCRIPTION, 1, 2, 0, sTextColors[1], 0, sPassAreaDescriptions[cursorArea]); @@ -1129,19 +1184,19 @@ static void PrintAreaDescription(u8 cursorArea) CopyBgTilemapBufferToVram(0); } -static void sub_80C5F58(bool8 arg0, bool8 arg1) +static void ShowHideZoomingArea(bool8 show, bool8 zoomedIn) { - switch (sPassData->unkE) + switch (sPassData->areaToShow) { - case 1: - if (arg0) - CopyToBgTilemapBufferRect_ChangePalette(2, sPassGfx->unk20, 16, 3, 12, 7, 16); + case CURSOR_AREA_MAP: + if (show) + CopyToBgTilemapBufferRect_ChangePalette(2, sPassGfx->mapAndCardZoomTilemap, 16, 3, 12, 7, 16); else FillBgTilemapBufferRect(2, 0, 16, 3, 12, 7, 16); break; - case 2: - if (arg0) - CopyToBgTilemapBufferRect_ChangePalette(2, sPassGfx->unk20 + 84, 16, 10, 12, 7, 16); + case CURSOR_AREA_CARD: + if (show) + CopyToBgTilemapBufferRect_ChangePalette(2, sPassGfx->mapAndCardZoomTilemap + 84, 16, 10, 12, 7, 16); else FillBgTilemapBufferRect(2, 0, 16, 10, 12, 7, 16); break; @@ -1150,13 +1205,13 @@ static void sub_80C5F58(bool8 arg0, bool8 arg1) } CopyBgTilemapBufferToVram(2); - if (arg1) + if (zoomedIn) { SetBgAffine(2, - gUnknown_085713E0[sPassData->unkE - 1][0] << 8, - gUnknown_085713E0[sPassData->unkE - 1][1] << 8, - gUnknown_085713E0[sPassData->unkE - 1][0], - gUnknown_085713E0[sPassData->unkE - 1][1], + sBgAffineCoords[sPassData->areaToShow - 1][0] << 8, + sBgAffineCoords[sPassData->areaToShow - 1][1] << 8, + sBgAffineCoords[sPassData->areaToShow - 1][0], + sBgAffineCoords[sPassData->areaToShow - 1][1], MathUtil_Inv16(Q_8_8(1.984375)), // 1 and 63/64 MathUtil_Inv16(Q_8_8(1.984375)), 0); @@ -1164,71 +1219,75 @@ static void sub_80C5F58(bool8 arg0, bool8 arg1) else { SetBgAffine(2, - gUnknown_085713E0[sPassData->unkE - 1][0] << 8, - gUnknown_085713E0[sPassData->unkE - 1][1] << 8, - gUnknown_085713E0[sPassData->unkE - 1][0], - gUnknown_085713E0[sPassData->unkE - 1][1], + sBgAffineCoords[sPassData->areaToShow - 1][0] << 8, + sBgAffineCoords[sPassData->areaToShow - 1][1] << 8, + sBgAffineCoords[sPassData->areaToShow - 1][0], + sBgAffineCoords[sPassData->areaToShow - 1][1], MathUtil_Inv16(Q_8_8(1)), MathUtil_Inv16(Q_8_8(1)), 0); } } -static void sub_80C6104(u8 cursorArea, u8 previousCursorArea) +static void UpdateAreaHighlight(u8 cursorArea, u8 previousCursorArea) { + #define NON_HIGHLIGHT_AREA(area)((area) == CURSOR_AREA_NOTHING || (area) > CURSOR_AREA_CANCEL) + + // If moving off highlightable area, unhighlight it switch (previousCursorArea) { case CURSOR_AREA_MAP: - CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->unk24, 16, 3, 12, 7, 17); + CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->mapAndCardTilemap, 16, 3, 12, 7, 17); break; case CURSOR_AREA_CARD: - CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->unk24 + 336, 16, 10, 12, 7, 17); + CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->mapAndCardTilemap + 336, 16, 10, 12, 7, 17); break; case CURSOR_AREA_RECORD: if (sPassData->hasBattleRecord) - CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->unk28, 2, 10, 12, 3, 17); - else if (cursorArea == CURSOR_AREA_NOTHING || cursorArea > CURSOR_AREA_CANCEL) + CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->battleRecordTilemap, 2, 10, 12, 3, 17); + else if (NON_HIGHLIGHT_AREA(cursorArea)) return; break; case CURSOR_AREA_CANCEL: - CopyToBgTilemapBufferRect_ChangePalette(1, gUnknown_08DE3350, 21, 0, 9, 2, 17); + CopyToBgTilemapBufferRect_ChangePalette(1, gFrontierPassCancelButton_Tilemap, 21, 0, 9, 2, 17); break; default: - if (cursorArea == CURSOR_AREA_NOTHING || cursorArea > CURSOR_AREA_CANCEL) + if (NON_HIGHLIGHT_AREA(cursorArea)) return; break; } + // If moving on to highlightable area, highlight it switch (cursorArea) { case CURSOR_AREA_MAP: - CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->unk24 + 168, 16, 3, 12, 7, 17); + CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->mapAndCardTilemap + 168, 16, 3, 12, 7, 17); break; case CURSOR_AREA_CARD: - CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->unk24 + 504, 16, 10, 12, 7, 17); + CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->mapAndCardTilemap + 504, 16, 10, 12, 7, 17); break; case CURSOR_AREA_RECORD: if (sPassData->hasBattleRecord) - CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->unk28 + 72, 2, 10, 12, 3, 17); + CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->battleRecordTilemap + 72, 2, 10, 12, 3, 17); else return; - break; //needed to match + break; case CURSOR_AREA_CANCEL: - CopyToBgTilemapBufferRect_ChangePalette(1, gUnknown_08DE3374, 21, 0, 9, 2, 17); + CopyToBgTilemapBufferRect_ChangePalette(1, gFrontierPassCancelButtonHighlighted_Tilemap, 21, 0, 9, 2, 17); break; default: - if (previousCursorArea == CURSOR_AREA_NOTHING || previousCursorArea > CURSOR_AREA_CANCEL) + if (NON_HIGHLIGHT_AREA(previousCursorArea)) return; } CopyBgTilemapBufferToVram(1); } -static void sub_80C629C(void) +static void DrawFrontierPassBg(void) { - CopyToBgTilemapBuffer(1, gUnknown_08DE3060, 0, 0); - sub_80C6104(sPassData->cursorArea, sPassData->previousCursorArea); - sub_80C5F58(TRUE, sPassData->unkE); + CopyToBgTilemapBuffer(1, gFrontierPassBg_Tilemap, 0, 0); + UpdateAreaHighlight(sPassData->cursorArea, sPassData->previousCursorArea); + ShowHideZoomingArea(TRUE, sPassData->areaToShow); // If returning to frontier pass from map/card (areaToShow will be != 0) ShowAndPrintWindows(); CopyBgTilemapBufferToVram(1); } @@ -1253,7 +1312,7 @@ static void LoadCursorAndSymbolSprites(void) { struct SpriteTemplate sprite = sSpriteTemplate_Medal; - sprite.paletteTag += sPassData->facilitySymbols[i] - 1; + sprite.paletteTag += sPassData->facilitySymbols[i] - 1; // Adds 1 if gold for TAG_MEDAL_GOLD spriteId = CreateSprite(&sprite, sPassAreasLayout[i + CURSOR_AREA_SYMBOL - 1].xStart + 8, sPassAreasLayout[i + CURSOR_AREA_SYMBOL - 1].yStart + 6, i + 1); sPassGfx->symbolSprites[i] = &gSprites[spriteId]; sPassGfx->symbolSprites[i]->oam.priority = 2; @@ -1277,11 +1336,11 @@ static void FreeCursorAndSymbolSprites(void) } } FreeAllSpritePalettes(); - FreeSpriteTilesByTag(2); - FreeSpriteTilesByTag(0); + FreeSpriteTilesByTag(TAG_MEDAL_SILVER); + FreeSpriteTilesByTag(TAG_CURSOR); } -static void SpriteCb_Dummy(struct Sprite *sprite) +static void SpriteCB_PlayerHead(struct Sprite *sprite) { } @@ -1349,14 +1408,14 @@ static bool32 InitFrontierMap(void) InitWindows(sMapWindowTemplates); DeactivateAllTextPrinters(); PrintOnFrontierMap(); - DecompressAndCopyTileDataToVram(1, gUnknown_0856FBBC, 0, 0, 0); + DecompressAndCopyTileDataToVram(1, sMapScreen_Gfx, 0, 0, 0); break; case 5: if (FreeTempTileDataBuffersIfPossible()) return FALSE; - LoadPalette(gUnknown_08DE07C8[0], 0, 0x1A0); + LoadPalette(gFrontierPassBg_Pal[0], 0, 0x1A0); LoadPalette(GetTextWindowPalette(0), 0xF0, 0x20); - CopyToBgTilemapBuffer(2, gUnknown_08570E00, 0, 0); + CopyToBgTilemapBuffer(2, sMapScreen_Tilemap, 0, 0); CopyBgTilemapBufferToVram(2); break; case 6: @@ -1365,9 +1424,9 @@ static bool32 InitFrontierMap(void) ShowBg(1); ShowBg(2); InitFrontierMapSprites(); - SetVBlankCallback(VblankCb_FrontierPass); - BlendPalettes(PALETTES_ALL, 0x10, RGB_WHITE); - BeginNormalPaletteFade(PALETTES_ALL, 0, 0x10, 0, RGB_WHITE); + SetVBlankCallback(VBlankCB_FrontierPass); + BlendPalettes(PALETTES_ALL, 16, RGB_WHITE); + BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_WHITE); break; case 7: if (UpdatePaletteFade()) @@ -1385,7 +1444,7 @@ static bool32 ExitFrontierMap(void) switch (sPassData->state) { case 0: - BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 0x10, RGB_WHITE); + BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_WHITE); break; case 1: if (UpdatePaletteFade()) @@ -1404,17 +1463,17 @@ static bool32 ExitFrontierMap(void) if (sMapData->cursorSprite != NULL) { DestroySprite(sMapData->cursorSprite); - FreeSpriteTilesByTag(0); + FreeSpriteTilesByTag(TAG_CURSOR); } if (sMapData->mapIndicatorSprite != NULL) { DestroySprite(sMapData->mapIndicatorSprite); - FreeSpriteTilesByTag(1); + FreeSpriteTilesByTag(TAG_MAP_INDICATOR); } if (sMapData->playerHeadSprite != NULL) { DestroySprite(sMapData->playerHeadSprite); - FreeSpriteTilesByTag(4); + FreeSpriteTilesByTag(TAG_HEAD_MALE); } FreeAllWindowBuffers(); break; @@ -1435,11 +1494,14 @@ static bool32 ExitFrontierMap(void) return FALSE; } +#define tState data[0] +#define tMoveSteps data[1] + static void Task_HandleFrontierMap(u8 taskId) { s16 *data = gTasks[taskId].data; - switch (data[0]) + switch (tState) { case 0: if (InitFrontierMap()) @@ -1449,47 +1511,47 @@ static void Task_HandleFrontierMap(u8 taskId) if (JOY_NEW(B_BUTTON)) { PlaySE(SE_PC_OFF); - data[0] = 4; + tState = 4; } else if (JOY_NEW(DPAD_DOWN)) { if (sMapData->cursorPos >= NUM_FRONTIER_FACILITIES - 1) HandleFrontierMapCursorMove(0); else - data[0] = 2; + tState = 2; } else if (JOY_NEW(DPAD_UP)) { if (sMapData->cursorPos == 0) HandleFrontierMapCursorMove(1); else - data[0] = 3; + tState = 3; } return; case 2: - if (data[1] > 3) + if (tMoveSteps > 3) { HandleFrontierMapCursorMove(0); - data[1] = 0; - data[0] = 1; + tMoveSteps = 0; + tState = 1; } else { sMapData->cursorSprite->pos1.y += 4; - data[1]++; + tMoveSteps++; } return; case 3: - if (data[1] > 3) + if (tMoveSteps > 3) { HandleFrontierMapCursorMove(1); - data[1] = 0; - data[0] = 1; + tMoveSteps = 0; + tState = 1; } else { sMapData->cursorSprite->pos1.y -= 4; - data[1]++; + tMoveSteps++; } return; case 4: @@ -1502,31 +1564,42 @@ static void Task_HandleFrontierMap(u8 taskId) return; } - data[0]++; + tState++; } static u8 MapNumToFrontierFacilityId(u16 mapNum) // id + 1, zero means not a frontier map number { + // In Battle Tower if ((mapNum >= MAP_NUM(BATTLE_FRONTIER_BATTLE_TOWER_LOBBY) && mapNum <= MAP_NUM(BATTLE_FRONTIER_BATTLE_TOWER_BATTLE_ROOM)) - || (mapNum >= MAP_NUM(BATTLE_FRONTIER_BATTLE_TOWER_MULTI_PARTNER_ROOM) && mapNum <= MAP_NUM(BATTLE_FRONTIER_BATTLE_TOWER_MULTI_BATTLE_ROOM))) + || (mapNum >= MAP_NUM(BATTLE_FRONTIER_BATTLE_TOWER_MULTI_PARTNER_ROOM) && mapNum <= MAP_NUM(BATTLE_FRONTIER_BATTLE_TOWER_MULTI_BATTLE_ROOM))) return FRONTIER_FACILITY_TOWER + 1; + + // In Battle Dome else if (mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_DOME_LOBBY) || mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_DOME_CORRIDOR) || mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_DOME_PRE_BATTLE_ROOM) || mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_DOME_BATTLE_ROOM)) return FRONTIER_FACILITY_DOME + 1; + + // In Battle Palace else if (mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_PALACE_LOBBY) || mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_PALACE_CORRIDOR) || mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_PALACE_BATTLE_ROOM)) return FRONTIER_FACILITY_PALACE + 1; + + // In Battle Arena else if (mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_ARENA_LOBBY) || mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_ARENA_CORRIDOR) || mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_ARENA_BATTLE_ROOM)) return FRONTIER_FACILITY_ARENA + 1; + + // In Battle Factory else if (mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_FACTORY_LOBBY) || mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_FACTORY_PRE_BATTLE_ROOM) || mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_FACTORY_BATTLE_ROOM)) return FRONTIER_FACILITY_FACTORY + 1; + + // In Battle Pike else if (mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_PIKE_LOBBY) || mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_PIKE_CORRIDOR) || mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_PIKE_THREE_PATH_ROOM) @@ -1534,10 +1607,13 @@ static u8 MapNumToFrontierFacilityId(u16 mapNum) // id + 1, zero means not a fro || mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_PIKE_ROOM_FINAL) || mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_PIKE_ROOM_WILD_MONS)) return FRONTIER_FACILITY_PIKE + 1; + + // In Battle Pyramid else if (mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_PYRAMID_LOBBY) || mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_PYRAMID_FLOOR) || mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_PYRAMID_TOP)) return FRONTIER_FACILITY_PYRAMID + 1; + else return 0; } @@ -1606,8 +1682,8 @@ static void InitFrontierMapSprites(void) } LoadCompressedSpriteSheet(sHeadsSpriteSheet); - sprite = sSpriteTemplate_Head; - sprite.paletteTag = gSaveBlock2Ptr->playerGender + 4; + sprite = sSpriteTemplate_PlayerHead; + sprite.paletteTag = gSaveBlock2Ptr->playerGender + TAG_HEAD_MALE; // TAG_HEAD_FEMALE if gender is FEMALE if (id != 0) { spriteId = CreateSprite(&sprite, x, y, 0); @@ -1678,7 +1754,7 @@ static void HandleFrontierMapCursorMove(u8 direction) FillWindowPixelBuffer(MAP_WINDOW_DESCRIPTION, PIXEL_FILL(0)); AddTextPrinterParameterized3(MAP_WINDOW_DESCRIPTION, 1, 4, 0, sTextColors[0], 0, sMapLandmarks[sMapData->cursorPos].description); - for (i = 0; i < 3; i++) + for (i = 0; i < MAP_WINDOW_COUNT; i++) CopyWindowToVram(i, 3); CopyBgTilemapBufferToVram(0); diff --git a/src/graphics.c b/src/graphics.c index 7a7a11b2b..39abf69d8 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -1533,14 +1533,12 @@ const u32 gTitleScreenPressStartGfx[] = INCBIN_U32("graphics/title_screen/press_ const u32 gUnknown_08DE0644[] = INCBIN_U32("graphics/title_screen/title_screen2.bin.lz"); -// more trainer card stuff - -const u16 gUnknown_08DE07C8[][16] = INCBIN_U16("graphics/frontier_pass/tiles.gbapal");// size in LoadPalette calls is reported as 0xD0 << 1, which is 0x1A0, but palette is only 0x100 bytes long so it loads garbage as well -const u32 gUnknown_08DE08C8[] = INCBIN_U32("graphics/frontier_pass/tiles.4bpp.lz"); -const u32 gUnknown_08DE2084[] = INCBIN_U32("graphics/frontier_pass/tiles2.8bpp.lz"); -const u32 gUnknown_08DE3060[] = INCBIN_U32("graphics/frontier_pass/tiles.bin.lz"); -const u16 gUnknown_08DE3350[] = INCBIN_U16("graphics/frontier_pass/tilemap1.bin"); -const u16 gUnknown_08DE3374[] = INCBIN_U16("graphics/frontier_pass/tilemap2.bin"); +const u16 gFrontierPassBg_Pal[][16] = INCBIN_U16("graphics/frontier_pass/bg.gbapal");// size in LoadPalette calls is reported as 0xD0 << 1, which is 0x1A0, but palette is only 0x100 bytes long so it loads garbage as well +const u32 gFrontierPassBg_Gfx[] = INCBIN_U32("graphics/frontier_pass/bg.4bpp.lz"); +const u32 gFrontierPassMapAndCard_Gfx[] = INCBIN_U32("graphics/frontier_pass/map_and_card.8bpp.lz"); +const u32 gFrontierPassBg_Tilemap[] = INCBIN_U32("graphics/frontier_pass/bg.bin.lz"); +const u16 gFrontierPassCancelButton_Tilemap[] = INCBIN_U16("graphics/frontier_pass/cancel.bin"); +const u16 gFrontierPassCancelButtonHighlighted_Tilemap[] = INCBIN_U16("graphics/frontier_pass/cancel_highlighted.bin"); // Berry Crush const u16 gBerryCrush_Crusher_Pal[] = INCBIN_U16("graphics/berry_crush/crusher.gbapal");