diff options
author | DizzyEggg <jajkodizzy@wp.pl> | 2018-05-01 15:33:13 +0200 |
---|---|---|
committer | DizzyEggg <jajkodizzy@wp.pl> | 2018-05-01 15:33:13 +0200 |
commit | ae7878672379cf8bc1e071c3cc392696785ac3e6 (patch) | |
tree | ab06e5b1d7de06f1b1292ee57792c4708360f92d /src/battle_records.c | |
parent | 95cf853762e4202dbfece323c5cf454984ca37c5 (diff) |
identify and name battle records things
Diffstat (limited to 'src/battle_records.c')
-rw-r--r-- | src/battle_records.c | 247 |
1 files changed, 226 insertions, 21 deletions
diff --git a/src/battle_records.c b/src/battle_records.c index 0a0e0bd42..efc9173a7 100644 --- a/src/battle_records.c +++ b/src/battle_records.c @@ -6,15 +6,34 @@ #include "battle.h" #include "overworld.h" #include "text.h" +#include "text_window.h" #include "strings.h" #include "string_util.h" #include "trainer_card.h" #include "menu.h" #include "menu_helpers.h" +#include "palette.h" +#include "main.h" +#include "scanline_effect.h" #include "international_string_util.h" +#include "sound.h" +#include "constants/songs.h" +#include "malloc.h" +#include "gpu_regs.h" #include "constants/game_stat.h" -extern u8 gResultsWindowId; +extern void PrintOnTrainerHillRecordsWindow(void); // pokenav.s + +// this file's functions +static void sub_813C5EC(u8 taskId); +static void sub_813C62C(u8 taskId); +static void sub_813C664(u8 taskId); +static void sub_813C6A8(u8 windowId); +static void sub_813C91C(void); + +// EWRAM variables +EWRAM_DATA u8 gRecordsWindowId = 0; +EWRAM_DATA static u8 *sUnknown_0203AB78 = NULL; // const rom data const u32 gUnknown_085B3484[] = INCBIN_U32("graphics/unknown/unknown_5B3484.4bpp"); @@ -192,7 +211,7 @@ void ClearPlayerLinkBattleRecords(void) ClearLinkBattleRecords(gSaveBlock1Ptr->linkBattleRecords.entries); } -static void IncTrainerCardWins(int battlerId) +static void IncTrainerCardWins(s32 battlerId) { u16 *wins = &gTrainerCards[battlerId].linkBattleWins; (*wins)++; @@ -200,7 +219,7 @@ static void IncTrainerCardWins(int battlerId) *wins = 9999; } -static void IncTrainerCardLosses(int battlerId) +static void IncTrainerCardLosses(s32 battlerId) { u16 *losses = &gTrainerCards[battlerId].linkBattleLosses; (*losses)++; @@ -208,7 +227,7 @@ static void IncTrainerCardLosses(int battlerId) *losses = 9999; } -static void UpdateTrainerCardWinsLosses(int battlerId) +static void UpdateTrainerCardWinsLosses(s32 battlerId) { switch (gBattleOutcome) { @@ -223,7 +242,7 @@ static void UpdateTrainerCardWinsLosses(int battlerId) } } -void UpdatePlayerLinkBattleRecords(int battlerId) +void UpdatePlayerLinkBattleRecords(s32 battlerId) { if (InUnionRoom() != TRUE) { @@ -247,7 +266,7 @@ static void PrintLinkBattleWinsLossesDraws(struct LinkBattleRecord *records) StringExpandPlaceholders(gStringVar4, gText_TotalRecordWLD); x = GetStringCenterAlignXOffset(1, gStringVar4, 0xD0); - PrintTextOnWindow(gResultsWindowId, 1, gStringVar4, x, 0x11, 0, NULL); + PrintTextOnWindow(gRecordsWindowId, 1, gStringVar4, x, 0x11, 0, NULL); } static void PrintLinkBattleRecord(struct LinkBattleRecord *record, u8 y, s32 language) @@ -255,10 +274,10 @@ static void PrintLinkBattleRecord(struct LinkBattleRecord *record, u8 y, s32 lan if (record->wins == 0 && record->losses == 0 && record->draws == 0) { // empty slot - PrintTextOnWindow(gResultsWindowId, 1, gUnknown_085B3D84, 8, (y * 8) + 1, 0, NULL); - PrintTextOnWindow(gResultsWindowId, 1, gUnknown_085B3D8C, 80, (y * 8) + 1, 0, NULL); - PrintTextOnWindow(gResultsWindowId, 1, gUnknown_085B3D8C, 128, (y * 8) + 1, 0, NULL); - PrintTextOnWindow(gResultsWindowId, 1, gUnknown_085B3D8C, 176, (y * 8) + 1, 0, NULL); + PrintTextOnWindow(gRecordsWindowId, 1, gUnknown_085B3D84, 8, (y * 8) + 1, 0, NULL); + PrintTextOnWindow(gRecordsWindowId, 1, gUnknown_085B3D8C, 80, (y * 8) + 1, 0, NULL); + PrintTextOnWindow(gRecordsWindowId, 1, gUnknown_085B3D8C, 128, (y * 8) + 1, 0, NULL); + PrintTextOnWindow(gRecordsWindowId, 1, gUnknown_085B3D8C, 176, (y * 8) + 1, 0, NULL); } else { @@ -266,16 +285,16 @@ static void PrintLinkBattleRecord(struct LinkBattleRecord *record, u8 y, s32 lan StringCopyN(gStringVar1, record->name, 7); ConvertInternationalString(gStringVar1, language); - PrintTextOnWindow(gResultsWindowId, 1, gStringVar1, 8, (y * 8) + 1, 0, NULL); + PrintTextOnWindow(gRecordsWindowId, 1, gStringVar1, 8, (y * 8) + 1, 0, NULL); ConvertIntToDecimalStringN(gStringVar1, record->wins, STR_CONV_MODE_RIGHT_ALIGN, 4); - PrintTextOnWindow(gResultsWindowId, 1, gStringVar1, 80, (y * 8) + 1, 0, NULL); + PrintTextOnWindow(gRecordsWindowId, 1, gStringVar1, 80, (y * 8) + 1, 0, NULL); ConvertIntToDecimalStringN(gStringVar1, record->losses, STR_CONV_MODE_RIGHT_ALIGN, 4); - PrintTextOnWindow(gResultsWindowId, 1, gStringVar1, 128, (y * 8) + 1, 0, NULL); + PrintTextOnWindow(gRecordsWindowId, 1, gStringVar1, 128, (y * 8) + 1, 0, NULL); ConvertIntToDecimalStringN(gStringVar1, record->draws, STR_CONV_MODE_RIGHT_ALIGN, 4); - PrintTextOnWindow(gResultsWindowId, 1, gStringVar1, 176, (y * 8) + 1, 0, NULL); + PrintTextOnWindow(gRecordsWindowId, 1, gStringVar1, 176, (y * 8) + 1, 0, NULL); } } @@ -283,23 +302,209 @@ void ShowLinkBattleRecords(void) { s32 i, x; - gResultsWindowId = AddWindow(&gUnknown_085B3D7C); - NewMenuHelpers_DrawStdWindowFrame(gResultsWindowId, FALSE); - FillWindowPixelBuffer(gResultsWindowId, 0x11); + gRecordsWindowId = AddWindow(&gUnknown_085B3D7C); + NewMenuHelpers_DrawStdWindowFrame(gRecordsWindowId, FALSE); + FillWindowPixelBuffer(gRecordsWindowId, 0x11); StringExpandPlaceholders(gStringVar4, gText_PlayersBattleResults); x = GetStringCenterAlignXOffset(1, gStringVar4, 208); - PrintTextOnWindow(gResultsWindowId, 1, gStringVar4, x, 1, 0, NULL); + PrintTextOnWindow(gRecordsWindowId, 1, gStringVar4, x, 1, 0, NULL); PrintLinkBattleWinsLossesDraws(gSaveBlock1Ptr->linkBattleRecords.entries); StringExpandPlaceholders(gStringVar4, gText_WinLoseDraw); - PrintTextOnWindow(gResultsWindowId, 1, gStringVar4, 0, 41, 0, NULL); + PrintTextOnWindow(gRecordsWindowId, 1, gStringVar4, 0, 41, 0, NULL); for (i = 0; i < LINK_B_RECORDS_COUNT; i++) { PrintLinkBattleRecord(&gSaveBlock1Ptr->linkBattleRecords.entries[i], 7 + (i * 2), gSaveBlock1Ptr->linkBattleRecords.languages[i]); } - PutWindowTilemap(gResultsWindowId); - CopyWindowToVram(gResultsWindowId, 3); + PutWindowTilemap(gRecordsWindowId); + CopyWindowToVram(gRecordsWindowId, 3); +} + +void RemoveRecordsWindow(void) +{ + sub_819746C(gRecordsWindowId, FALSE); + RemoveWindow(gRecordsWindowId); +} + +static void sub_813C5BC(u8 taskId) +{ + if (!gPaletteFade.active) + gTasks[taskId].func = sub_813C5EC; +} + +static void sub_813C5EC(u8 taskId) +{ + struct Task *task = &gTasks[taskId]; + + if (gMain.newKeys & A_BUTTON || gMain.newKeys & B_BUTTON) + { + PlaySE(SE_SELECT); + task->func = sub_813C62C; + } +} + +static void sub_813C62C(u8 taskId) +{ + BeginNormalPaletteFade(-1, 0, 0, 0x10, 0); + gTasks[taskId].func = sub_813C664; +} + +static void sub_813C664(u8 taskId) +{ + if (!gPaletteFade.active) + { + SetMainCallback2(CB2_ReturnToFieldContinueScript); + Free(sUnknown_0203AB78); + sub_813C6A8(0); + FreeAllWindowBuffers(); + DestroyTask(taskId); + } +} + +static void sub_813C6A8(u8 windowId) +{ + FillWindowPixelBuffer(windowId, 0); + ClearWindowTilemap(windowId); + CopyWindowToVram(windowId, 2); + RemoveWindow(windowId); +} + +static void sub_813C6D4(void) +{ + DmaClearLarge16(3, (void*)(VRAM), VRAM_SIZE, 0x1000); + DmaClear32(3, OAM, OAM_SIZE); + DmaClear16(3, PLTT, PLTT_SIZE); + + SetGpuReg(REG_OFFSET_DISPCNT, 0); + SetGpuReg(REG_OFFSET_BG0CNT, 0); + SetGpuReg(REG_OFFSET_BG0HOFS, 0); + SetGpuReg(REG_OFFSET_BG0VOFS, 0); + SetGpuReg(REG_OFFSET_BG1CNT, 0); + SetGpuReg(REG_OFFSET_BG1HOFS, 0); + SetGpuReg(REG_OFFSET_BG1VOFS, 0); + SetGpuReg(REG_OFFSET_BG2CNT, 0); + SetGpuReg(REG_OFFSET_BG2HOFS, 0); + SetGpuReg(REG_OFFSET_BG2VOFS, 0); + SetGpuReg(REG_OFFSET_BG3CNT, 0); + SetGpuReg(REG_OFFSET_BG3HOFS, 0); + SetGpuReg(REG_OFFSET_BG3VOFS, 0); + SetGpuReg(REG_OFFSET_WIN0H, 0); + SetGpuReg(REG_OFFSET_WIN0V, 0); + SetGpuReg(REG_OFFSET_WININ, 0); + SetGpuReg(REG_OFFSET_WINOUT, 0); + SetGpuReg(REG_OFFSET_BLDCNT, 0); + SetGpuReg(REG_OFFSET_BLDALPHA, 0); + SetGpuReg(REG_OFFSET_BLDY, 0); +} + +static void sub_813C80C(void) +{ + ScanlineEffect_Stop(); + ResetTasks(); + ResetSpriteData(); + ResetPaletteFade(); + FreeAllSpritePalettes(); +} + +static void ResetBgCoordinates(void) +{ + ChangeBgX(0, 0, 0); + ChangeBgY(0, 0, 0); + ChangeBgX(1, 0, 0); + ChangeBgY(1, 0, 0); + ChangeBgX(2, 0, 0); + ChangeBgY(2, 0, 0); + ChangeBgX(3, 0, 0); + ChangeBgY(3, 0, 0); +} + +static void sub_813C880(void) +{ + SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_BG0_ON | DISPCNT_BG3_ON | DISPCNT_OBJ_1D_MAP); +} + +static void sub_813C890(u8 bgId) +{ + LoadBgTiles(bgId, gUnknown_085B3484, sizeof(gUnknown_085B3484), 0); + CopyToBgTilemapBufferRect(bgId, gUnknown_085B3564, 0, 0, 0x20, 0x20); + LoadPalette(gUnknown_085B3544, 0, 0x20); +} + +static void sub_813C8D8(void) +{ + LoadOam(); + ProcessSpriteCopyRequests(); + TransferPlttBuffer(); +} + +static void sub_813C8EC(void) +{ + RunTasks(); + AnimateSprites(); + BuildOamBuffer(); + UpdatePaletteFade(); +} + +void ShowTrainerHillRecords(void) +{ + SetVBlankCallback(NULL); + SetMainCallback2(sub_813C91C); +} + +static void sub_813C91C(void) +{ + switch (gMain.state) + { + case 0: + SetVBlankCallback(NULL); + sub_813C6D4(); + gMain.state++; + break; + case 1: + sub_813C80C(); + gMain.state++; + break; + case 2: + sUnknown_0203AB78 = AllocZeroed(0x800); + ResetBgsAndClearDma3BusyFlags(0); + InitBgsFromTemplates(0, gUnknown_085B3D64, ARRAY_COUNT(gUnknown_085B3D64)); + SetBgTilemapBuffer(3, sUnknown_0203AB78); + ResetBgCoordinates(); + gMain.state++; + break; + case 3: + sub_813C890(3); + LoadPalette(stdpal_get(0), 0xF0, 0x20); + gMain.state++; + break; + case 4: + if (IsDma3ManagerBusyWithBgCopy() != TRUE) + { + ShowBg(0); + ShowBg(3); + CopyBgTilemapBufferToVram(3); + gMain.state++; + } + break; + case 5: + InitWindows(gUnknown_085B3D6C); + DeactivateAllTextPrinters(); + gMain.state++; + break; + case 6: + BeginNormalPaletteFade(-1, 0, 0x10, 0, 0); + gMain.state++; + break; + case 7: + sub_813C880(); + SetVBlankCallback(sub_813C8D8); + PrintOnTrainerHillRecordsWindow(); + CreateTask(sub_813C5BC, 8); + SetMainCallback2(sub_813C8EC); + gMain.state = 0; + break; + } } |