diff --git a/asm/battle_frontier_1.s b/asm/battle_frontier_1.s index f1508c297..f18f5dbf6 100644 --- a/asm/battle_frontier_1.s +++ b/asm/battle_frontier_1.s @@ -101,7 +101,7 @@ _08192598: ldr r3, [sp, 0x24] cmp r3, r0 bne _081925AC - bl sub_8195910 + bl GetDomeBrainTrainerPicId b _081925B2 .pool _081925AC: @@ -316,7 +316,7 @@ _08192784: ldr r1, [sp, 0x24] cmp r1, r0 bne _08192798 - bl sub_8195924 + bl GetDomeBrainTrainerClass b _0819279E .pool _08192798: @@ -373,7 +373,7 @@ _08192800: bne _08192824 ldr r4, =gStringVar2 adds r0, r4, 0 - bl sub_8195938 + bl CopyDomeBrainTrainerName adds r0, r5, 0 adds r1, r4, 0 bl StringAppend @@ -383,7 +383,7 @@ _08192824: ldr r4, =gStringVar2 ldr r1, [sp, 0x24] adds r0, r4, 0 - bl sub_8195898 + bl CopyDomeOpponentName adds r0, r5, 0 adds r1, r4, 0 bl StringAppend @@ -1296,13 +1296,13 @@ _08192F9C: cmp r0, r9 bne _08192FB0 ldr r0, =gStringVar1 - bl sub_8195938 + bl CopyDomeBrainTrainerName b _08192FB8 .pool _08192FB0: lsrs r1, 22 ldr r0, =gStringVar1 - bl sub_8195898 + bl CopyDomeOpponentName _08192FB8: movs r2, 0x1 add r8, r2 @@ -1442,13 +1442,13 @@ _081930E0: cmp r1, r0 bne _081930F8 ldr r0, =gStringVar1 - bl sub_8195938 + bl CopyDomeBrainTrainerName b _08193100 .pool _081930F8: lsrs r1, 22 ldr r0, =gStringVar1 - bl sub_8195898 + bl CopyDomeOpponentName _08193100: mov r0, r8 cmp r0, 0x2 @@ -1683,7 +1683,7 @@ _081932D4: ldr r0, =0x000003fe cmp r1, r0 bne _081932E4 - bl sub_8195910 + bl GetDomeBrainTrainerPicId b _081932EC .pool _081932E4: @@ -1765,7 +1765,7 @@ _08193388: ldr r0, =0x000003fe cmp r1, r0 bne _081933A4 - bl sub_8195910 + bl GetDomeBrainTrainerPicId lsls r0, 24 lsrs r0, 24 ldr r2, [sp, 0x7C] @@ -2207,14 +2207,14 @@ _0819375C: cmp r1, r0 bne _08193774 ldr r0, =gStringVar1 - bl sub_8195938 + bl CopyDomeBrainTrainerName b _0819377E .pool _08193774: ldr r0, =gStringVar1 lsls r1, 16 lsrs r1, 16 - bl sub_8195898 + bl CopyDomeOpponentName _0819377E: add r0, sp, 0xC movs r4, 0x2 @@ -2262,14 +2262,14 @@ _081937E4: cmp r1, r0 bne _081937F8 adds r0, r5, 0 - bl sub_8195938 + bl CopyDomeBrainTrainerName b _08193802 .pool _081937F8: lsls r1, 16 lsrs r1, 16 adds r0, r5, 0 - bl sub_8195898 + bl CopyDomeOpponentName _08193802: ldr r0, =gStringVar1 str r0, [sp, 0xC] @@ -3800,7 +3800,7 @@ _0819456C: lsls r1, 22 lsrs r1, 22 ldr r0, =gDisplayedStringBattle - bl sub_8195898 + bl CopyDomeOpponentName mov r2, r10 cmp r2, 0x1 bne _081945C4 @@ -4342,7 +4342,7 @@ _08194A1C: lsls r1, 22 lsrs r1, 22 mov r0, r9 - bl sub_8195898 + bl CopyDomeOpponentName mov r0, r8 ldr r2, [r0] adds r0, r2, r5 @@ -4895,7 +4895,7 @@ _08194F2A: ldrh r1, [r1] lsls r1, 22 lsrs r1, 22 - bl sub_8195898 + bl CopyDomeOpponentName pop {r4} pop {r0} bx r0 @@ -6041,8 +6041,8 @@ _0819587E: .pool thumb_func_end sub_8195438 - thumb_func_start sub_8195898 -sub_8195898: @ 8195898 + thumb_func_start CopyDomeOpponentName +CopyDomeOpponentName: @ 8195898 push {r4-r6,lr} adds r6, r0, 0 lsls r1, 16 @@ -6053,7 +6053,7 @@ sub_8195898: @ 8195898 cmp r5, r0 bne _081958B8 adds r0, r6, 0 - bl sub_8195938 + bl CopyDomeBrainTrainerName b _08195902 .pool _081958B8: @@ -6099,30 +6099,30 @@ _08195902: pop {r0} bx r0 .pool - thumb_func_end sub_8195898 + thumb_func_end CopyDomeOpponentName - thumb_func_start sub_8195910 -sub_8195910: @ 8195910 + thumb_func_start GetDomeBrainTrainerPicId +GetDomeBrainTrainerPicId: @ 8195910 ldr r0, =gTrainers ldr r1, =0x00007df3 adds r0, r1 ldrb r0, [r0] bx lr .pool - thumb_func_end sub_8195910 + thumb_func_end GetDomeBrainTrainerPicId - thumb_func_start sub_8195924 -sub_8195924: @ 8195924 + thumb_func_start GetDomeBrainTrainerClass +GetDomeBrainTrainerClass: @ 8195924 ldr r0, =gTrainers ldr r1, =0x00007df1 adds r0, r1 ldrb r0, [r0] bx lr .pool - thumb_func_end sub_8195924 + thumb_func_end GetDomeBrainTrainerClass - thumb_func_start sub_8195938 -sub_8195938: @ 8195938 + thumb_func_start CopyDomeBrainTrainerName +CopyDomeBrainTrainerName: @ 8195938 push {r4,lr} adds r3, r0, 0 movs r2, 0 @@ -6142,7 +6142,7 @@ _08195940: pop {r0} bx r0 .pool - thumb_func_end sub_8195938 + thumb_func_end CopyDomeBrainTrainerName thumb_func_start sub_8195960 sub_8195960: @ 8195960 diff --git a/include/pokemon.h b/include/pokemon.h index a60ad66be..09496b5c3 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -456,6 +456,7 @@ extern const u8 gStatStageRatios[][2]; extern const u16 gUnknown_08329D54[]; extern const struct SpriteTemplate gUnknown_08329D98[]; extern const struct CompressedSpritePalette gMonPaletteTable[]; +extern const s8 gNatureStatTable[][5]; void ZeroBoxMonData(struct BoxPokemon *boxMon); void ZeroMonData(struct Pokemon *mon); diff --git a/src/battle_frontier_1.c b/src/battle_frontier_1.c index a1d8b2c31..692f942fc 100644 --- a/src/battle_frontier_1.c +++ b/src/battle_frontier_1.c @@ -20,6 +20,8 @@ #include "menu.h" #include "sound.h" #include "pokemon_icon.h" +#include "data2.h" +#include "international_string_util.h" #include "trainer_pokemon_sprites.h" #include "constants/species.h" #include "constants/moves.h" @@ -54,12 +56,16 @@ extern u32 sub_81A39C4(void); extern u16 sub_8162548(u8, u8); extern u16 RandomizeFacilityTrainerMonId(u16); extern u8 GetFrontierEnemyMonLevel(void); -extern void sub_8195898(u8 *dst, u16 trainerId); +extern void CopyDomeOpponentName(u8 *dst, u16 trainerId); extern u16 sub_81A5060(u8, u8); +extern u8 sub_81A50F0(u8, u8); +extern u8 sub_81A50B0(u8); extern void sub_8162614(u16, u8); extern void sub_81A4C30(void); extern bool8 sub_81A3610(void); extern u16 sub_81A4FF0(u8); +extern u8 GetFrontierTrainerFrontSpriteId(u16); +extern u8 GetFrontierOpponentClass(u16); extern u8 gUnknown_0203CEF8[]; extern u32 gUnknown_0203CD70; @@ -90,8 +96,17 @@ extern const u8 gUnknown_0860D080[]; extern const u8 gUnknown_0860D15C[]; extern const u8 gUnknown_0860D1A0[]; extern const u8 gUnknown_0860D19C[]; +extern const u8 gUnknown_0860D349[]; extern const u8 gUnknown_0860D1C0[]; +extern const u8 gUnknown_0860D343[]; +extern const u8 gUnknown_0860D340[]; +extern const u8 gUnknown_0860D346[]; +extern const u8 gUnknown_0860B358[][16]; +extern const u8 gUnknown_0860C988[31][16]; extern const u8 gUnknown_0860D3F1[][2]; +extern const u8 *const gBattleDomePotentialPointers[]; +extern const u8 *const gBattleDomeOpponentStylePointers[]; +extern const u8 *const gBattleDomeOpponentStatsPointers[]; // gfx extern const u8 gUnknown_08D83D50[]; @@ -102,6 +117,9 @@ extern const u8 gUnknown_08D85358[]; extern const u8 gUnknown_08D85600[]; extern const u8 gUnknown_08D854C8[]; +// text +extern const u8 gTrainerClassNames[][0xD]; + // This file's functions. u8 GetDomeTrainerMonIvs(u16 trainerId); void SwapDomeTrainers(s32 id1, s32 id2, u16 *statsArray); @@ -120,9 +138,13 @@ void sub_8194220(u8 taskId); void sub_8194B54(void); void sub_8194B70(void); void sub_819314C(u8, u8); -void sub_81924E0(u8, u8); +void sub_81924E0(u8, u8 trainerTournamentId); u8 sub_819221C(u8 taskId); s32 sub_8192F08(u8, u8*); +u8 GetDomeBrainTrainerPicId(void); +u8 GetDomeBrainTrainerClass(void); +void CopyDomeBrainTrainerName(u8 *dst); +void CopyDomeOpponentName(u8 *dst, u16 trainerId); // code void sub_818E9AC(void) @@ -549,7 +571,7 @@ void sub_818F9B0(void) void sub_818F9E0(void) { StringCopy(gStringVar1, gRoundsStringTable[gSaveBlock2Ptr->frontier.field_CB2]); - sub_8195898(gStringVar2, gTrainerBattleOpponent_A); + CopyDomeOpponentName(gStringVar2, gTrainerBattleOpponent_A); } void sub_818FA20(void) @@ -2444,9 +2466,363 @@ u8 sub_819221C(u8 taskId) return retVal; } -/* -void sub_81924E0(u8 arg0, u8 arg1) +void sub_81924E0(u8 arg0, u8 trainerTournamentId) { + s32 i, j, k; + s16 *allocatedArray; + struct TextSubPrinter textPrinter; + s32 trainerId; + s32 windowId; + s32 x, y; + u8 palSlot; + u8 nature; + j = 0; + windowId = 0; + x = 0; + y = 0; + palSlot = 0; + allocatedArray = AllocZeroed(sizeof(s16) * 18); + trainerId = gSaveBlock2Ptr->frontier.domeTrainers[trainerTournamentId].trainerId; + + if (arg0 & 1) + j = 8, windowId = 9, palSlot = 2; + if (arg0 & 2) + x = 256; + if (arg0 & 4) + y = 160; + if (arg0 & 8) + x = -256; + if (arg0 & 0x10) + y = -160; + + if (trainerId == TRAINER_PLAYER) + gUnknown_0203CD78->arr[j] = CreateTrainerPicSprite(PlayerGenderToFrontTrainerPicId(gSaveBlock2Ptr->playerGender), TRUE, x + 48, y + 64, palSlot + 12, 0xFFFF); + else if (trainerId == TRAINER_FRONTIER_BRAIN) + gUnknown_0203CD78->arr[j] = CreateTrainerPicSprite(GetDomeBrainTrainerPicId(), TRUE, x + 48, y + 64, palSlot + 12, 0xFFFF); + else + gUnknown_0203CD78->arr[j] = CreateTrainerPicSprite(GetFrontierTrainerFrontSpriteId(trainerId), TRUE, x + 48, y + 64, palSlot + 12, 0xFFFF); + + if (arg0 & 0x1E) + gSprites[gUnknown_0203CD78->arr[j]].invisible = 1; + + for (i = 0; i < 3; i++) + { + if (trainerId == TRAINER_PLAYER) + gUnknown_0203CD78->arr[i + 2 + j] = CreateMonIcon(gSaveBlock2Ptr->frontier.domeMonId[trainerTournamentId][i], + sub_8190938, + x | gUnknown_0860D340[i], + y + gUnknown_0860D343[i], + 0, 0, TRUE); + else if (trainerId == TRAINER_FRONTIER_BRAIN) + gUnknown_0203CD78->arr[i + 2 + j] = CreateMonIcon(gSaveBlock2Ptr->frontier.domeMonId[trainerTournamentId][i], + sub_8190938, + x | gUnknown_0860D340[i], + y + gUnknown_0860D343[i], + 0, 0, TRUE); + else + gUnknown_0203CD78->arr[i + 2 + j] = CreateMonIcon(gFacilityTrainerMons[gSaveBlock2Ptr->frontier.domeMonId[trainerTournamentId][i]].species, + sub_8190938, + x | gUnknown_0860D340[i], + y + gUnknown_0860D343[i], + 0, 0, TRUE); + gSprites[gUnknown_0203CD78->arr[i + 2 + j]].oam.priority = 0; + if (arg0 & 0x1E) + gSprites[gUnknown_0203CD78->arr[i + 2 + j]].invisible = 1; + } + textPrinter.fontId = 2; + textPrinter.x = 0; + textPrinter.y = 0; + textPrinter.currentX = 0; + textPrinter.currentY = 0; + textPrinter.letterSpacing = 2; + textPrinter.lineSpacing = 0; + textPrinter.fontColor_l = 0; + textPrinter.fgColor = 14; + textPrinter.bgColor = 0; + textPrinter.shadowColor = 13; + + i = 0; + if (trainerId == TRAINER_PLAYER) + j = gFacilityClassToTrainerClass[FACILITY_CLASS_PKMN_TRAINER_BRENDAN]; + else if (trainerId == TRAINER_FRONTIER_BRAIN) + j = GetDomeBrainTrainerClass(); + else + j = GetFrontierOpponentClass(trainerId); + + for (;gTrainerClassNames[j][i] != EOS; i++) + gStringVar1[i] = gTrainerClassNames[j][i]; + gStringVar1[i] = CHAR_SPACE; + gStringVar1[i + 1] = EOS; + + if (trainerId == TRAINER_PLAYER) + { + StringAppend(gStringVar1, gSaveBlock2Ptr->playerName); + } + else if (trainerId == TRAINER_FRONTIER_BRAIN) + { + CopyDomeBrainTrainerName(gStringVar2); + StringAppend(gStringVar1, gStringVar2); + } + else + { + CopyDomeOpponentName(gStringVar2, trainerId); + StringAppend(gStringVar1, gStringVar2); + } + + textPrinter.currentX = GetStringCenterAlignXOffsetWithLetterSpacing(textPrinter.fontId, gStringVar1, 0xD0, textPrinter.letterSpacing); + textPrinter.current_text_offset = gStringVar1; + textPrinter.windowId = windowId; + PutWindowTilemap(windowId); + CopyWindowToVram(windowId, 3); + AddTextPrinter(&textPrinter, 0, NULL); + textPrinter.letterSpacing = 0; + + for (i = 0; i < 3; i++) + { + textPrinter.currentY = gUnknown_0860D346[i]; + if (trainerId == TRAINER_PLAYER) + textPrinter.current_text_offset = gSpeciesNames[gSaveBlock2Ptr->frontier.domeMonId[trainerTournamentId][i]]; + else if (trainerId == TRAINER_FRONTIER_BRAIN) + textPrinter.current_text_offset = gSpeciesNames[gSaveBlock2Ptr->frontier.domeMonId[trainerTournamentId][i]]; + else + textPrinter.current_text_offset = gSpeciesNames[gFacilityTrainerMons[gSaveBlock2Ptr->frontier.domeMonId[trainerTournamentId][i]].species]; + + textPrinter.windowId = windowId + i + 1; + if (i == 1) + textPrinter.currentX = 7; + else + textPrinter.currentX = 0; + + j = i + 1; + PutWindowTilemap(windowId + j); + CopyWindowToVram(windowId + j, 3); + AddTextPrinter(&textPrinter, 0, NULL); + } + + PutWindowTilemap(windowId + 4); + CopyWindowToVram(windowId + 4, 3); + if (trainerId == TRAINER_FRONTIER_BRAIN) + textPrinter.current_text_offset = gBattleDomePotentialPointers[16]; + else + textPrinter.current_text_offset = gBattleDomePotentialPointers[trainerTournamentId]; + + textPrinter.fontId = 1; + textPrinter.windowId = windowId + 4; + textPrinter.currentX = 0; + textPrinter.y = 4; + textPrinter.currentY = 4; + AddTextPrinter(&textPrinter, 0, NULL); + + for (i = 0; i < 3; i++) + { + for (j = 0; j < 4; j++) + { + for (k = 0; k < DOME_TOURNAMENT_TRAINERS_COUNT; k++) + { + if (trainerId == TRAINER_FRONTIER_BRAIN) + allocatedArray[k] += gUnknown_0860B358[sub_81A5060(i, j)][k]; + else if (trainerId == TRAINER_PLAYER) + allocatedArray[k] += gUnknown_0860B358[gSaveBlock2Ptr->frontier.field_EFC[i].moves[j]][k]; + else + allocatedArray[k] += gUnknown_0860B358[gFacilityTrainerMons[gSaveBlock2Ptr->frontier.domeMonId[trainerTournamentId][i]].moves[j]][k]; + } + } + } + + for (i = 0; i < ARRAY_COUNT(gUnknown_0860C988); i++) + { + s32 r4 = 0; + + for (k = 0, j = 0; j < DOME_TOURNAMENT_TRAINERS_COUNT; j++) + { + if (gUnknown_0860C988[i][j] != 0) + { + r4++; + if (allocatedArray[j] != 0 && allocatedArray[j] >= gUnknown_0860C988[i][j]) + k++; + } + } + if (r4 == k) + break; + } + + textPrinter.current_text_offset = gBattleDomeOpponentStylePointers[i]; + textPrinter.y = 20; + textPrinter.currentY = 20; + AddTextPrinter(&textPrinter, 0, NULL); + + for (i = 0; i < 18; i++) + allocatedArray[i] = 0; + + if (trainerId == TRAINER_FRONTIER_BRAIN || trainerId == TRAINER_PLAYER) + { + for (i = 0; i < 3; i++) + { + for (j = 0; j < 6; j++) + { + if (trainerId == TRAINER_FRONTIER_BRAIN) + allocatedArray[j] = sub_81A50F0(i, j); + else + allocatedArray[j] = gSaveBlock2Ptr->frontier.field_EFC[i].evs[j]; + } + allocatedArray[6] += allocatedArray[0]; + for (j = 0; j < 5; j++) + { + if (trainerId == TRAINER_FRONTIER_BRAIN) + nature = sub_81A50B0(i); + else + nature = gSaveBlock2Ptr->frontier.field_EFC[i].nature; + + if (gNatureStatTable[nature][j] > 0) + { + allocatedArray[j + 7] += (allocatedArray[j + 1] * 110) / 100; + } + else if (gNatureStatTable[nature][j] < 0) + { + allocatedArray[j + 7] += (allocatedArray[j + 1] * 90) / 100; + allocatedArray[j + 13]++; + } + else + { + allocatedArray[j + 7] += allocatedArray[j + 1]; + } + } + } + for (j = 0, i = 0; i < 6; i++) + j += allocatedArray[6 + i]; + for (i = 0; i < 6; i++) + allocatedArray[i] = (allocatedArray[6 + i] * 100) / j; + } + else + { + for (i = 0; i < 3; i++) + { + s32 evBits = gFacilityTrainerMons[gSaveBlock2Ptr->frontier.domeMonId[trainerTournamentId][i]].evSpread; + for (k = 0, j = 0; j < 6; j++) + { + allocatedArray[j] = 0; + if (evBits & 1) + k++; + evBits >>= 1; + } + k = 510 / k; + evBits = gFacilityTrainerMons[gSaveBlock2Ptr->frontier.domeMonId[trainerTournamentId][i]].evSpread; + for (j = 0; j < 6; j++) + { + if (evBits & 1) + allocatedArray[j] = k; + evBits >>= 1; + } + + allocatedArray[6] += allocatedArray[0]; + for (j = 0; j < 5; j++) + { + nature = gFacilityTrainerMons[gSaveBlock2Ptr->frontier.domeMonId[trainerTournamentId][i]].nature; + if (gNatureStatTable[nature][j] > 0) + { + allocatedArray[j + 7] += (allocatedArray[j + 1] * 110) / 100; + } + else if (gNatureStatTable[nature][j] < 0) + { + allocatedArray[j + 7] += (allocatedArray[j + 1] * 90) / 100; + allocatedArray[j + 13]++; + } + else + { + allocatedArray[j + 7] += allocatedArray[j + 1]; + } + } + } + for (j = 0, i = 0; i < 6; i++) + j += allocatedArray[i + 6]; + for (i = 0; i < 6; i++) + allocatedArray[i] = (allocatedArray[6 + i] * 100) / j; + } + + for (i = 0, j = 0, k = 0; k < 6; k++) + { + if (allocatedArray[k] > 29) + { + if (i == 2) + { + if (allocatedArray[6] < allocatedArray[k]) + { + s16 var_24 = allocatedArray[7]; + if (allocatedArray[7] < allocatedArray[k]) + { + if (allocatedArray[6] < allocatedArray[7]) + { + allocatedArray[6] = var_24; + allocatedArray[7] = k; + } + else + { + allocatedArray[7] = k; + } + } + else + { + allocatedArray[6] = var_24; + allocatedArray[7] = k; + } + } + else + { + if (allocatedArray[7] < allocatedArray[k]) + allocatedArray[7] = k; + } + } + else + { + allocatedArray[i + 7] = k; + i++; + } + } + if (allocatedArray[k] == 0) + { + if (j == 2) + { + if (allocatedArray[k + 12] >= 2 + || ((allocatedArray[k + 12] == 1 && (allocatedArray[12 + allocatedArray[8]] != 0 || allocatedArray[12 + allocatedArray[9]] == 0)) + ) + ) + { + allocatedArray[8] = allocatedArray[9]; + allocatedArray[9] = k; + } + else if (allocatedArray[k + 12] == 1 && allocatedArray[12 + allocatedArray[8]] == 0) + { + allocatedArray[8] = allocatedArray[9]; + allocatedArray[9] = k; + } + else if (allocatedArray[k + 12] == 1 && allocatedArray[12 + allocatedArray[9]] == 0) + { + allocatedArray[9] = k; + } + } + else + { + allocatedArray[j + 8] = k; + j++; + } + } + } + + if (i == 2) + i = gUnknown_0860D349[allocatedArray[6]] + (allocatedArray[7] - (allocatedArray[6] + 1)); + else if (i == 1) + i = allocatedArray[6] + 15; + else if (j == 2) + i = gUnknown_0860D349[allocatedArray[8]] + (allocatedArray[9] - (allocatedArray[8] + 1)) + 21; + else if (j == 1) + i = allocatedArray[8] + 36; + else + i = 42; + + textPrinter.current_text_offset = gBattleDomeOpponentStatsPointers[i]; + textPrinter.y = 36; + textPrinter.currentY = 36; + AddTextPrinter(&textPrinter, 0, NULL); + Free(allocatedArray); } -*/